From patchwork Fri Aug 12 09:57:48 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Kever Yang X-Patchwork-Id: 658751 X-Patchwork-Delegate: sjg@chromium.org Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Received: from theia.denx.de (theia.denx.de [85.214.87.163]) by ozlabs.org (Postfix) with ESMTP id 3s9t7T2qdSz9sxR for ; Sat, 13 Aug 2016 04:04:21 +1000 (AEST) Received: from localhost (localhost [127.0.0.1]) by theia.denx.de (Postfix) with ESMTP id D0D044B656; Fri, 12 Aug 2016 20:04:19 +0200 (CEST) Received: from theia.denx.de ([127.0.0.1]) by localhost (theia.denx.de [127.0.0.1]) (amavisd-new, port 10024) with ESMTP id lHOHd1Rh6A-g; Fri, 12 Aug 2016 20:04:19 +0200 (CEST) Received: from theia.denx.de (localhost [127.0.0.1]) by theia.denx.de (Postfix) with ESMTP id 083BB4B99D; Fri, 12 Aug 2016 20:02:25 +0200 (CEST) Received: from localhost (localhost [127.0.0.1]) by theia.denx.de (Postfix) with ESMTP id 886214B660 for ; Fri, 12 Aug 2016 11:58:32 +0200 (CEST) Received: from theia.denx.de ([127.0.0.1]) by localhost (theia.denx.de [127.0.0.1]) (amavisd-new, port 10024) with ESMTP id i2iGCsQsNAGb for ; Fri, 12 Aug 2016 11:58:31 +0200 (CEST) X-policyd-weight: NOT_IN_SBL_XBL_SPAMHAUS=-1.5 NOT_IN_SPAMCOP=-1.5 NOT_IN_BL_NJABL=-1.5 (only DNSBL check requested) Received: from regular1.263xmail.com (regular1.263xmail.com [211.150.99.130]) by theia.denx.de (Postfix) with ESMTPS id 769004B656 for ; Fri, 12 Aug 2016 11:58:25 +0200 (CEST) Received: from kever.yang?rock-chips.com (unknown [192.168.165.141]) by regular1.263xmail.com (Postfix) with SMTP id AF4F7B0FB; Fri, 12 Aug 2016 17:58:19 +0800 (CST) X-263anti-spam: KSV:0; X-MAIL-GRAY: 0 X-MAIL-DELIVERY: 1 X-KSVirus-check: 0 X-ABS-CHECKED: 4 addr_info_check: 0 Received: from smtp.263.net (sg-smtp01.263.net [54.255.195.220]) by smtp.263.net (Postfix) with ESMTP id C85B64FD; Fri, 12 Aug 2016 17:58:16 +0800 (CST) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.263.net (Postfix) with ESMTP id 7A3ADDF370; Fri, 12 Aug 2016 17:57:54 +0800 (CST) X-RL-SENDER: kever.yang@rock-chips.com X-FST-TO: sjg@chromium.org X-SENDER-IP: 103.29.142.67 X-LOGIN-NAME: kever.yang@rock-chips.com X-UNIQUE-TAG: <1f906dafb5440c471f58082609572ab7> X-ATTACHMENT-NUM: 0 X-SENDER: yk@rock-chips.com X-DNS-TYPE: 0 Received: from localhost.localdomain (unknown [103.29.142.67]) by smtp.263.net (Postfix) whith ESMTP id 10385C7TG6D; Fri, 12 Aug 2016 17:57:55 +0800 (CST) From: Kever Yang To: sjg@chromium.org Date: Fri, 12 Aug 2016 17:57:48 +0800 Message-Id: <1470995868-2960-1-git-send-email-kever.yang@rock-chips.com> X-Mailer: git-send-email 1.9.1 In-Reply-To: <1470995239-2477-1-git-send-email-kever.yang@rock-chips.com> References: <1470995239-2477-1-git-send-email-kever.yang@rock-chips.com> Cc: elaine.zhang@rock-chips.com, u-boot@lists.denx.de Subject: [U-Boot] [PATCH 3/5] rk_pwm: use clock framework API to get module clock X-BeenThere: u-boot@lists.denx.de X-Mailman-Version: 2.1.15 Precedence: list List-Id: U-Boot discussion List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , MIME-Version: 1.0 Errors-To: u-boot-bounces@lists.denx.de Sender: "U-Boot" This patch use clock API instead of hardcode for get pwm clock. Signed-off-by: Kever Yang Acked-by: Simon Glass --- 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 +#include #include #include #include @@ -13,9 +14,9 @@ #include #include #include -#include #include #include +#include #include 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, ®s->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, ®s->period_hpr); writel(duty, ®s->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; }