All of lore.kernel.org
 help / color / mirror / Atom feed
From: Kever Yang <kever.yang@rock-chips.com>
To: u-boot@lists.denx.de
Subject: [U-Boot] [PATCH 3/5] rk_pwm: use clock framework API to get module clock
Date: Fri, 12 Aug 2016 17:57:48 +0800	[thread overview]
Message-ID: <1470995868-2960-1-git-send-email-kever.yang@rock-chips.com> (raw)
In-Reply-To: <1470995239-2477-1-git-send-email-kever.yang@rock-chips.com>

This patch use clock API instead of hardcode for get pwm clock.

Signed-off-by: Kever Yang <kever.yang@rock-chips.com>
---

 drivers/pwm/rk_pwm.c | 17 ++++++++++++++---
 1 file changed, 14 insertions(+), 3 deletions(-)

diff --git a/drivers/pwm/rk_pwm.c b/drivers/pwm/rk_pwm.c
index 2d289a4..d69aab5 100644
--- a/drivers/pwm/rk_pwm.c
+++ b/drivers/pwm/rk_pwm.c
@@ -6,6 +6,7 @@
  */
 
 #include <common.h>
+#include <clk.h>
 #include <div64.h>
 #include <dm.h>
 #include <pwm.h>
@@ -13,9 +14,9 @@
 #include <syscon.h>
 #include <asm/io.h>
 #include <asm/arch/clock.h>
-#include <asm/arch/cru_rk3288.h>
 #include <asm/arch/grf_rk3288.h>
 #include <asm/arch/pwm.h>
+#include <asm/arch/hardware.h>
 #include <power/regulator.h>
 
 DECLARE_GLOBAL_DATA_PTR;
@@ -23,6 +24,7 @@ DECLARE_GLOBAL_DATA_PTR;
 struct rk_pwm_priv {
 	struct rk3288_pwm *regs;
 	struct rk3288_grf *grf;
+	ulong freq;
 };
 
 static int rk_pwm_set_config(struct udevice *dev, uint channel, uint period_ns,
@@ -38,8 +40,8 @@ static int rk_pwm_set_config(struct udevice *dev, uint channel, uint period_ns,
 		RK_PWM_DISABLE,
 		&regs->ctrl);
 
-	period = lldiv((uint64_t)(PD_BUS_PCLK_HZ / 1000) * period_ns, 1000000);
-	duty = lldiv((uint64_t)(PD_BUS_PCLK_HZ / 1000) * duty_ns, 1000000);
+	period = lldiv((uint64_t)(priv->freq / 1000) * period_ns, 1000000);
+	duty = lldiv((uint64_t)(priv->freq / 1000) * duty_ns, 1000000);
 
 	writel(period, &regs->period_hpr);
 	writel(duty, &regs->duty_lpr);
@@ -76,9 +78,18 @@ static int rk_pwm_ofdata_to_platdata(struct udevice *dev)
 static int rk_pwm_probe(struct udevice *dev)
 {
 	struct rk_pwm_priv *priv = dev_get_priv(dev);
+	struct clk clk;
+	int ret = 0;
 
 	rk_setreg(&priv->grf->soc_con2, 1 << 0);
 
+	ret = clk_get_by_index(dev, 0, &clk);
+	if (ret < 0) {
+		printf("%s get clock fail!\n", __func__);
+		return -EINVAL;
+	}
+	priv->freq = clk_get_rate(&clk);
+
 	return 0;
 }
 
-- 
1.9.1

  parent reply	other threads:[~2016-08-12  9:57 UTC|newest]

Thread overview: 16+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2016-08-12  9:47 [U-Boot] [PATCH 0/5] clean rkpwm driver Kever Yang
2016-08-12  9:47 ` [U-Boot] [PATCH 1/5] clk: rk3399: add pmucru controller support Kever Yang
2016-08-12 17:21   ` Simon Glass
2016-09-06  1:04     ` Simon Glass
2016-08-12  9:57 ` [U-Boot] [PATCH 2/5] clk: rk3288: add PWM clock get rate Kever Yang
2016-08-12 17:21   ` Simon Glass
2016-09-06  1:05     ` Simon Glass
2016-08-12  9:57 ` Kever Yang [this message]
2016-08-12 17:21   ` [U-Boot] [PATCH 3/5] rk_pwm: use clock framework API to get module clock Simon Glass
2016-08-27 16:06     ` Simon Glass
2016-08-12  9:58 ` [U-Boot] [PATCH 4/5] rk_pwm: remove grf setting code from driver Kever Yang
2016-08-12 17:21   ` Simon Glass
2016-08-27 16:06     ` Simon Glass
2016-08-12  9:58 ` [U-Boot] [PATCH 5/5] rk3288: add arch_cpu_init for rk3288 Kever Yang
2016-08-16  4:50   ` Simon Glass
2016-08-27 16:06     ` Simon Glass

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=1470995868-2960-1-git-send-email-kever.yang@rock-chips.com \
    --to=kever.yang@rock-chips.com \
    --cc=u-boot@lists.denx.de \
    /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.