[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Message-Id: <20220712100113.569042-6-ben.dooks@sifive.com>
Date: Tue, 12 Jul 2022 11:01:11 +0100
From: Ben Dooks <ben.dooks@...ive.com>
To: linux-pwm@...r.kernel.org
Cc: devicetree@...r.kernel.org, linux-kernel@...r.kernel.org,
Lee Jones <lee.jones@...aro.org>,
u.kleine-koenig@...gutronix.de,
Thierry Reding <thierry.reding@...il.com>,
Krzysztof Kozlowski <krzysztof.kozlowski+dt@...aro.org>,
Greentime Hu <greentime.hu@...ive.com>,
Jude Onyenegecha <jude.onyenegecha@...ive.com>,
Sudip Mukherjee <sudip.mukherjee@...ive.com>,
William Salmon <william.salmon@...ive.com>,
Adnan Chowdhury <adnan.chowdhury@...ive.com>,
Ben Dooks <ben.dooks@...ive.com>
Subject: [PATCH 5/7] pwm: dwc: add timer clock
Add a configurable clock base rate for the pwm as when
being built for non-PCI the block may be sourced from
an internal clock.
Signed-off-by: Ben Dooks <ben.dooks@...ive.com>
---
drivers/pwm/pwm-dwc.c | 17 +++++++++++++++++
1 file changed, 17 insertions(+)
diff --git a/drivers/pwm/pwm-dwc.c b/drivers/pwm/pwm-dwc.c
index 235cb730c888..aa0486b89bdd 100644
--- a/drivers/pwm/pwm-dwc.c
+++ b/drivers/pwm/pwm-dwc.c
@@ -18,6 +18,7 @@
#include <linux/kernel.h>
#include <linux/module.h>
#include <linux/pci.h>
+#include <linux/clk.h>
#include <linux/platform_device.h>
#include <linux/pm_runtime.h>
#include <linux/pwm.h>
@@ -35,7 +36,12 @@
#define DWC_TIMERS_COMP_VERSION 0xac
#define DWC_TIMERS_TOTAL 8
+
+#ifndef CONFIG_OF
#define DWC_CLK_PERIOD_NS 10
+#else
+#define DWC_CLK_PERIOD_NS dwc->clk_ns
+#endif
/* Timer Control Register */
#define DWC_TIM_CTRL_EN BIT(0)
@@ -54,6 +60,8 @@ struct dwc_pwm_ctx {
struct dwc_pwm {
struct pwm_chip chip;
void __iomem *base;
+ struct clk *clk;
+ unsigned int clk_ns;
struct dwc_pwm_ctx ctx[DWC_TIMERS_TOTAL];
};
#define to_dwc_pwm(p) (container_of((p), struct dwc_pwm, chip))
@@ -336,6 +344,14 @@ static int dwc_pwm_plat_probe(struct platform_device *pdev)
return dev_err_probe(dev, PTR_ERR(dwc->base),
"failed to map IO\n");
+ dwc->clk = devm_clk_get(dev, "timer");
+ if (IS_ERR(dwc->clk))
+ return dev_err_probe(dev, PTR_ERR(dwc->clk),
+ "failed to get timer clock\n");
+
+ clk_prepare_enable(dwc->clk);
+ dwc->clk_ns = 1000000000 /clk_get_rate(dwc->clk);
+
ret = pwmchip_add(&dwc->chip);
if (ret)
return ret;
@@ -347,6 +363,7 @@ static int dwc_pwm_plat_remove(struct platform_device *pdev)
{
struct dwc_pwm *dwc = platform_get_drvdata(pdev);
+ clk_disable_unprepare(dwc->clk);
pwmchip_remove(&dwc->chip);
return 0;
}
--
2.35.1
Powered by blists - more mailing lists