All of lore.kernel.org
 help / color / mirror / Atom feed
From: David Wu <david.wu-TNX95d0MmH7DzftRWevZcw@public.gmane.org>
To: sjg-F7+t8E8rja9g9hUCZPvPmw@public.gmane.org,
	philipp.tomsich-SN7IsUiht6C/RdPyistoZJqQE7yCjDx5@public.gmane.org
Cc: huangtao-TNX95d0MmH7DzftRWevZcw@public.gmane.org,
	heiko-4mtYJXux2i+zQB+pC5nmwQ@public.gmane.org,
	u-boot-0aAXYlwwYIKGBzrmiIFOJg@public.gmane.org,
	zhangqing-TNX95d0MmH7DzftRWevZcw@public.gmane.org,
	kever.yang-TNX95d0MmH7DzftRWevZcw@public.gmane.org,
	linux-rockchip-IAPFreCvJWM7uuMidbF8XUB+6BGkLq7r@public.gmane.org,
	p.marczak-Sze3O3UU22JBDgjK7y7TUQ@public.gmane.org,
	David Wu <david.wu-TNX95d0MmH7DzftRWevZcw@public.gmane.org>,
	andy.yan-TNX95d0MmH7DzftRWevZcw@public.gmane.org,
	chenjh-TNX95d0MmH7DzftRWevZcw@public.gmane.org
Subject: [PATCH 5/8] clk: rockchip: Add rk3328 Saradc clock support
Date: Wed, 13 Sep 2017 18:52:49 +0800	[thread overview]
Message-ID: <1505299969-13329-1-git-send-email-david.wu@rock-chips.com> (raw)
In-Reply-To: <1505297379-12638-1-git-send-email-david.wu-TNX95d0MmH7DzftRWevZcw@public.gmane.org>

The clk_saradc is dividing from the 24M, clk_saradc=24MHz/(saradc_div_con+1).
Saradc integer divider control register is 10-bits width.

Signed-off-by: David Wu <david.wu-TNX95d0MmH7DzftRWevZcw@public.gmane.org>
---
 drivers/clk/rockchip/clk_rk3328.c | 37 +++++++++++++++++++++++++++++++++++++
 1 file changed, 37 insertions(+)

diff --git a/drivers/clk/rockchip/clk_rk3328.c b/drivers/clk/rockchip/clk_rk3328.c
index c3a6650..e1ae7b2 100644
--- a/drivers/clk/rockchip/clk_rk3328.c
+++ b/drivers/clk/rockchip/clk_rk3328.c
@@ -115,6 +115,7 @@ enum {
 	/* CLKSEL_CON23 */
 	CLK_SARADC_DIV_CON_SHIFT	= 0,
 	CLK_SARADC_DIV_CON_MASK		= 0x3ff << CLK_SARADC_DIV_CON_SHIFT,
+	CLK_SARADC_DIV_CON_WIDTH	= 10,
 
 	/* CLKSEL_CON24 */
 	CLK_PWM_PLL_SEL_CPLL		= 0,
@@ -180,6 +181,11 @@ enum {
 #define PLL_DIV_MIN	16
 #define PLL_DIV_MAX	3200
 
+static inline u32 extract_bits(u32 val, unsigned width, unsigned shift)
+{
+	return (val >> shift) & ((1 << width) - 1);
+}
+
 /*
  * How to calculate the PLL(from TRM V0.3 Part 1 Page 63):
  * Formulas also embedded within the Fractional PLL Verilog model:
@@ -478,6 +484,31 @@ static ulong rk3328_pwm_set_clk(struct rk3328_cru *cru, uint hz)
 	return DIV_TO_RATE(GPLL_HZ, div);
 }
 
+static ulong rk3328_saradc_get_clk(struct rk3328_cru *cru)
+{
+	u32 div, val;
+
+	val = readl(&cru->clksel_con[23]);
+	div = extract_bits(val, CLK_SARADC_DIV_CON_WIDTH,
+			   CLK_SARADC_DIV_CON_SHIFT);
+
+	return DIV_TO_RATE(OSC_HZ, div);
+}
+
+static ulong rk3328_saradc_set_clk(struct rk3328_cru *cru, uint hz)
+{
+	int src_clk_div;
+
+	src_clk_div = DIV_ROUND_UP(OSC_HZ, hz) - 1;
+	assert(src_clk_div < 128);
+
+	rk_clrsetreg(&cru->clksel_con[23],
+		     CLK_SARADC_DIV_CON_MASK,
+		     src_clk_div << CLK_SARADC_DIV_CON_SHIFT);
+
+	return rk3328_saradc_get_clk(cru);
+}
+
 static ulong rk3328_clk_get_rate(struct clk *clk)
 {
 	struct rk3328_clk_priv *priv = dev_get_priv(clk->dev);
@@ -501,6 +532,9 @@ static ulong rk3328_clk_get_rate(struct clk *clk)
 	case SCLK_PWM:
 		rate = rk3328_pwm_get_clk(priv->cru);
 		break;
+	case SCLK_SARADC:
+		rate = rk3328_saradc_get_clk(priv->cru);
+		break;
 	default:
 		return -ENOENT;
 	}
@@ -531,6 +565,9 @@ static ulong rk3328_clk_set_rate(struct clk *clk, ulong rate)
 	case SCLK_PWM:
 		ret = rk3328_pwm_set_clk(priv->cru, rate);
 		break;
+	case SCLK_SARADC:
+		ret = rk3328_saradc_set_clk(priv->cru, rate);
+		break;
 	default:
 		return -ENOENT;
 	}
-- 
2.7.4

WARNING: multiple messages have this Message-ID (diff)
From: David Wu <david.wu@rock-chips.com>
To: u-boot@lists.denx.de
Subject: [U-Boot] [PATCH 5/8] clk: rockchip: Add rk3328 Saradc clock support
Date: Wed, 13 Sep 2017 18:52:49 +0800	[thread overview]
Message-ID: <1505299969-13329-1-git-send-email-david.wu@rock-chips.com> (raw)
In-Reply-To: <1505297379-12638-1-git-send-email-david.wu@rock-chips.com>

The clk_saradc is dividing from the 24M, clk_saradc=24MHz/(saradc_div_con+1).
Saradc integer divider control register is 10-bits width.

Signed-off-by: David Wu <david.wu@rock-chips.com>
---
 drivers/clk/rockchip/clk_rk3328.c | 37 +++++++++++++++++++++++++++++++++++++
 1 file changed, 37 insertions(+)

diff --git a/drivers/clk/rockchip/clk_rk3328.c b/drivers/clk/rockchip/clk_rk3328.c
index c3a6650..e1ae7b2 100644
--- a/drivers/clk/rockchip/clk_rk3328.c
+++ b/drivers/clk/rockchip/clk_rk3328.c
@@ -115,6 +115,7 @@ enum {
 	/* CLKSEL_CON23 */
 	CLK_SARADC_DIV_CON_SHIFT	= 0,
 	CLK_SARADC_DIV_CON_MASK		= 0x3ff << CLK_SARADC_DIV_CON_SHIFT,
+	CLK_SARADC_DIV_CON_WIDTH	= 10,
 
 	/* CLKSEL_CON24 */
 	CLK_PWM_PLL_SEL_CPLL		= 0,
@@ -180,6 +181,11 @@ enum {
 #define PLL_DIV_MIN	16
 #define PLL_DIV_MAX	3200
 
+static inline u32 extract_bits(u32 val, unsigned width, unsigned shift)
+{
+	return (val >> shift) & ((1 << width) - 1);
+}
+
 /*
  * How to calculate the PLL(from TRM V0.3 Part 1 Page 63):
  * Formulas also embedded within the Fractional PLL Verilog model:
@@ -478,6 +484,31 @@ static ulong rk3328_pwm_set_clk(struct rk3328_cru *cru, uint hz)
 	return DIV_TO_RATE(GPLL_HZ, div);
 }
 
+static ulong rk3328_saradc_get_clk(struct rk3328_cru *cru)
+{
+	u32 div, val;
+
+	val = readl(&cru->clksel_con[23]);
+	div = extract_bits(val, CLK_SARADC_DIV_CON_WIDTH,
+			   CLK_SARADC_DIV_CON_SHIFT);
+
+	return DIV_TO_RATE(OSC_HZ, div);
+}
+
+static ulong rk3328_saradc_set_clk(struct rk3328_cru *cru, uint hz)
+{
+	int src_clk_div;
+
+	src_clk_div = DIV_ROUND_UP(OSC_HZ, hz) - 1;
+	assert(src_clk_div < 128);
+
+	rk_clrsetreg(&cru->clksel_con[23],
+		     CLK_SARADC_DIV_CON_MASK,
+		     src_clk_div << CLK_SARADC_DIV_CON_SHIFT);
+
+	return rk3328_saradc_get_clk(cru);
+}
+
 static ulong rk3328_clk_get_rate(struct clk *clk)
 {
 	struct rk3328_clk_priv *priv = dev_get_priv(clk->dev);
@@ -501,6 +532,9 @@ static ulong rk3328_clk_get_rate(struct clk *clk)
 	case SCLK_PWM:
 		rate = rk3328_pwm_get_clk(priv->cru);
 		break;
+	case SCLK_SARADC:
+		rate = rk3328_saradc_get_clk(priv->cru);
+		break;
 	default:
 		return -ENOENT;
 	}
@@ -531,6 +565,9 @@ static ulong rk3328_clk_set_rate(struct clk *clk, ulong rate)
 	case SCLK_PWM:
 		ret = rk3328_pwm_set_clk(priv->cru, rate);
 		break;
+	case SCLK_SARADC:
+		ret = rk3328_saradc_set_clk(priv->cru, rate);
+		break;
 	default:
 		return -ENOENT;
 	}
-- 
2.7.4

  parent reply	other threads:[~2017-09-13 10:52 UTC|newest]

Thread overview: 44+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2017-09-13 10:09 [PATCH 0/8] Add rockchip Saradc support David Wu
2017-09-13 10:09 ` [U-Boot] " David Wu
     [not found] ` <1505297379-12638-1-git-send-email-david.wu-TNX95d0MmH7DzftRWevZcw@public.gmane.org>
2017-09-13 10:09   ` [PATCH 1/8] adc: Add driver for Rockchip Saradc David Wu
2017-09-13 10:09     ` [U-Boot] " David Wu
     [not found]     ` <1505297379-12638-2-git-send-email-david.wu-TNX95d0MmH7DzftRWevZcw@public.gmane.org>
2017-09-13 20:07       ` [U-Boot,1/8] " Philipp Tomsich
2017-09-13 20:07         ` [U-Boot] " Philipp Tomsich
2017-09-13 20:40     ` Philipp Tomsich
2017-09-13 20:40       ` [U-Boot] " Philipp Tomsich
2017-09-13 10:09   ` [PATCH 2/8] configs: rockchip: Enable the ROCKCHIP_SARADC config David Wu
2017-09-13 10:09     ` [U-Boot] " David Wu
2017-09-13 10:20     ` Dr. Philipp Tomsich
2017-09-13 10:20       ` [U-Boot] " Dr. Philipp Tomsich
2017-09-13 10:09   ` [PATCH 4/8] clk: rockchip: Add Saradc clock support for rk3288 David Wu
2017-09-13 10:09     ` [U-Boot] " David Wu
2017-09-13 10:24     ` Dr. Philipp Tomsich
2017-09-13 10:24       ` [U-Boot] " Dr. Philipp Tomsich
2017-09-13 10:26     ` Dr. Philipp Tomsich
2017-09-13 10:26       ` [U-Boot] " Dr. Philipp Tomsich
     [not found]     ` <1505297379-12638-5-git-send-email-david.wu-TNX95d0MmH7DzftRWevZcw@public.gmane.org>
2017-09-13 20:07       ` [U-Boot,4/8] " Philipp Tomsich
2017-09-13 20:07         ` [U-Boot] [U-Boot, 4/8] " Philipp Tomsich
2017-09-13 10:52   ` David Wu [this message]
2017-09-13 10:52     ` [U-Boot] [PATCH 5/8] clk: rockchip: Add rk3328 Saradc clock support David Wu
     [not found]     ` <1505299969-13329-1-git-send-email-david.wu-TNX95d0MmH7DzftRWevZcw@public.gmane.org>
2017-09-13 20:07       ` [U-Boot,5/8] " Philipp Tomsich
2017-09-13 20:07         ` [U-Boot] [U-Boot, 5/8] " Philipp Tomsich
2017-09-13 20:44     ` Philipp Tomsich
2017-09-13 20:44       ` [U-Boot] " Philipp Tomsich
2017-09-13 10:09 ` [PATCH 3/8] clk: rockchip: Add rv1108 " David Wu
2017-09-13 10:09   ` [U-Boot] " David Wu
     [not found]   ` <1505297379-12638-4-git-send-email-david.wu-TNX95d0MmH7DzftRWevZcw@public.gmane.org>
2017-09-13 20:07     ` [U-Boot,3/8] " Philipp Tomsich
2017-09-13 20:07       ` [U-Boot] [U-Boot, 3/8] " Philipp Tomsich
2017-09-13 20:45   ` Philipp Tomsich
2017-09-13 20:45     ` [U-Boot] " Philipp Tomsich
2017-09-13 11:32 ` [U-Boot] [PATCH 6/8] clk: rockchip: Add rk3368 " David Wu
2017-09-13 20:07   ` [U-Boot] [U-Boot, " Philipp Tomsich
2017-09-13 20:41   ` Philipp Tomsich
2017-09-13 20:44     ` Dr. Philipp Tomsich
2017-09-14 11:17     ` David.Wu
2017-09-14 14:55       ` Dr. Philipp Tomsich
2017-09-13 11:33 ` [U-Boot] [PATCH 7/8] clk: rockchip: Add rk3399 " David Wu
2017-09-13 20:07   ` [U-Boot] [U-Boot, " Philipp Tomsich
2017-09-13 20:42   ` Philipp Tomsich
2017-09-13 11:35 ` [U-Boot] [PATCH 8/8] arm: dts: rv1108: Add Saradc node at dtsi level David Wu
2017-09-13 20:07   ` [U-Boot] [U-Boot, " Philipp Tomsich
2017-09-13 20:08   ` Philipp Tomsich

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=1505299969-13329-1-git-send-email-david.wu@rock-chips.com \
    --to=david.wu-tnx95d0mmh7dzftrwevzcw@public.gmane.org \
    --cc=andy.yan-TNX95d0MmH7DzftRWevZcw@public.gmane.org \
    --cc=chenjh-TNX95d0MmH7DzftRWevZcw@public.gmane.org \
    --cc=heiko-4mtYJXux2i+zQB+pC5nmwQ@public.gmane.org \
    --cc=huangtao-TNX95d0MmH7DzftRWevZcw@public.gmane.org \
    --cc=kever.yang-TNX95d0MmH7DzftRWevZcw@public.gmane.org \
    --cc=linux-rockchip-IAPFreCvJWM7uuMidbF8XUB+6BGkLq7r@public.gmane.org \
    --cc=p.marczak-Sze3O3UU22JBDgjK7y7TUQ@public.gmane.org \
    --cc=philipp.tomsich-SN7IsUiht6C/RdPyistoZJqQE7yCjDx5@public.gmane.org \
    --cc=sjg-F7+t8E8rja9g9hUCZPvPmw@public.gmane.org \
    --cc=u-boot-0aAXYlwwYIKGBzrmiIFOJg@public.gmane.org \
    --cc=zhangqing-TNX95d0MmH7DzftRWevZcw@public.gmane.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.