[PATCH 05/27] pwm: pxa: get the clock from the clk API

Sascha Hauer <[email protected]>
Newsgroups org.infradead.lists.barebox
Message-ID <[email protected]>
The driver enabled and disabled its clock by poking CKEN and asked
pxa_get_pwmclk() for the rate. Use the clk api to handle the clocks.

A clk driver for PXA is not yet present in the tree, but PXA has
no board support currently, so we can safely break bisectability
here.

Assisted-by: Claude Opus 5
Signed-off-by: Sascha Hauer <[email protected]>
---
 drivers/pwm/Kconfig   |  7 +++----
 drivers/pwm/pxa_pwm.c | 38 ++++++++++----------------------------
 2 files changed, 13 insertions(+), 32 deletions(-)

diff --git a/drivers/pwm/Kconfig b/drivers/pwm/Kconfig
index 85cde63bf6..33e1da8aef 100644
--- a/drivers/pwm/Kconfig
+++ b/drivers/pwm/Kconfig
@@ -11,11 +11,10 @@ menuconfig PWM
 if PWM
 config PWM_PXA
 	bool "PXA PWM Support"
-	default y if ARCH_PXA2XX
-	depends on ARCH_PXA2XX
+	default y if ARCH_PXA
+	depends on ARCH_PXA
 	help
-	  This enables PWM support for Intel/Marvell PXA chips, such
-	  as the PXA25x, PXA27x.
+	  This enables PWM support for Intel/Marvell PXA chips.
 
 config PWM_ATMEL
 	bool "Atmel PWM Support"
diff --git a/drivers/pwm/pxa_pwm.c b/drivers/pwm/pxa_pwm.c
index 42ccb37b9a..a70661d164 100644
--- a/drivers/pwm/pxa_pwm.c
+++ b/drivers/pwm/pxa_pwm.c
@@ -14,11 +14,11 @@
 #include <pwm.h>
 
 #include <mach/pxa/hardware.h>
-#include <mach/pxa/clock.h>
 #include <mach/pxa/pxa-regs.h>
 #include <mach/pxa/regs-pwm.h>
 #include <linux/math64.h>
 #include <linux/compiler.h>
+#include <linux/clk.h>
 
 /* PWM registers and bits definitions */
 #define PWMCR		(0x00)
@@ -31,6 +31,7 @@
 struct pxa_pwm_chip {
 	struct pwm_chip chip;
 	void __iomem *iobase;
+	struct clk *clk;
 	int id;
 };
 
@@ -41,35 +42,12 @@ static struct pxa_pwm_chip *to_pxa_pwm_chip(struct pwm_chip *chip)
 
 static int pxa_pwm_enable(struct pxa_pwm_chip *pxa_pwm)
 {
-	switch (pxa_pwm->id) {
-	case 0:
-	case 2:
-		CKEN |= CKEN_PWM0;
-		break;
-	case 1:
-	case 3:
-		CKEN |= CKEN_PWM1;
-		break;
-	default:
-		return -EINVAL;
-	}
-	return 0;
+	return clk_enable(pxa_pwm->clk);
 }
 
 static void pxa_pwm_disable(struct pxa_pwm_chip *pxa_pwm)
 {
-	switch (pxa_pwm->id) {
-	case 0:
-	case 2:
-		CKEN &= ~CKEN_PWM0;
-		break;
-	case 1:
-	case 3:
-		CKEN &= ~CKEN_PWM1;
-		break;
-	default:
-		break;
-	}
+	clk_disable(pxa_pwm->clk);
 }
 
 /*
@@ -93,7 +71,7 @@ static int pxa_pwm_apply(struct pwm_chip *chip,
 		return 0;
 	}
 
-	c = pxa_get_pwmclk();
+	c = clk_get_rate(pxa_pwm->clk);
 	c = c * state->period;
 	do_div(c, 1000000000);
 	period_cycles = c;
@@ -142,6 +120,11 @@ static int pxa_pwm_probe(struct device *dev)
 	if (IS_ERR(iores))
 		return PTR_ERR(iores);
 	chip->iobase = IOMEM(iores->start);
+
+	chip->clk = clk_get(dev, NULL);
+	if (IS_ERR(chip->clk))
+		return PTR_ERR(chip->clk);
+
 	chip->id = dev->id;
 	chip->chip.dev = dev;
 	dev->priv = chip;
@@ -156,7 +139,6 @@ static struct driver pxa_pwm_driver = {
 
 static int __init pxa_pwm_init_driver(void)
 {
-	CKEN &= ~CKEN_PWM0 & ~CKEN_PWM1;
 	platform_driver_register(&pxa_pwm_driver);
 	return 0;
 }

-- 
2.47.3
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.