pwm: imx: Rewrite v1 code to facilitate switch to atomic PWM
authorLukasz Majewski <l.majewski@majess.pl>
Sun, 29 Jan 2017 21:54:08 +0000 (22:54 +0100)
committerThierry Reding <thierry.reding@gmail.com>
Mon, 30 Jan 2017 08:12:42 +0000 (09:12 +0100)
The code has been rewritten to remove "generic" calls to
imx_pwm_{enable|disable|config}.

Such approach would facilitate switch to atomic PWM (a.k.a ->apply())
implementation.

Suggested-by: Stefan Agner <stefan@agner.ch>
Suggested-by: Boris Brezillon <boris.brezillon@free-electrons.com>
Reviewed-by: Stefan Agner <stefan@agner.ch>
Signed-off-by: Lukasz Majewski <l.majewski@majess.pl>
Reviewed-by: Boris Brezillon <boris.brezillon@free-electrons.com>
Signed-off-by: Thierry Reding <thierry.reding@gmail.com>
drivers/pwm/pwm-imx.c

index c405cb777808d4ffa6c1ad65f463278c9701f9b8..5c712104066a7538355e0e42604b30fc29ed0aca 100644 (file)
@@ -90,19 +90,33 @@ static int imx_pwm_config_v1(struct pwm_chip *chip,
        return 0;
 }
 
-static void imx_pwm_set_enable_v1(struct pwm_chip *chip, bool enable)
+static int imx_pwm_enable_v1(struct pwm_chip *chip, struct pwm_device *pwm)
 {
        struct imx_chip *imx = to_imx_chip(chip);
        u32 val;
+       int ret;
+
+       ret = clk_prepare_enable(imx->clk_per);
+       if (ret < 0)
+               return ret;
 
        val = readl(imx->mmio_base + MX1_PWMC);
+       val |= MX1_PWMC_EN;
+       writel(val, imx->mmio_base + MX1_PWMC);
 
-       if (enable)
-               val |= MX1_PWMC_EN;
-       else
-               val &= ~MX1_PWMC_EN;
+       return 0;
+}
+
+static void imx_pwm_disable_v1(struct pwm_chip *chip, struct pwm_device *pwm)
+{
+       struct imx_chip *imx = to_imx_chip(chip);
+       u32 val;
 
+       val = readl(imx->mmio_base + MX1_PWMC);
+       val &= ~MX1_PWMC_EN;
        writel(val, imx->mmio_base + MX1_PWMC);
+
+       clk_disable_unprepare(imx->clk_per);
 }
 
 static int imx_pwm_config_v2(struct pwm_chip *chip,
@@ -240,9 +254,9 @@ static void imx_pwm_disable(struct pwm_chip *chip, struct pwm_device *pwm)
 }
 
 static const struct pwm_ops imx_pwm_ops_v1 = {
-       .enable = imx_pwm_enable,
-       .disable = imx_pwm_disable,
-       .config = imx_pwm_config,
+       .enable = imx_pwm_enable_v1,
+       .disable = imx_pwm_disable_v1,
+       .config = imx_pwm_config_v1,
        .owner = THIS_MODULE,
 };
 
@@ -261,8 +275,6 @@ struct imx_pwm_data {
 };
 
 static struct imx_pwm_data imx_pwm_data_v1 = {
-       .config = imx_pwm_config_v1,
-       .set_enable = imx_pwm_set_enable_v1,
        .ops = &imx_pwm_ops_v1,
 };