]> Git Repo - J-linux.git/blobdiff - drivers/pwm/pwm-berlin.c
Merge tag 'x86_urgent_for_v6.7_rc2' of git://git.kernel.org/pub/scm/linux/kernel...
[J-linux.git] / drivers / pwm / pwm-berlin.c
index 0971c666afd134f28e343b7218e4dbb2a947d88f..ba2d799917695fc4d767160049dfe45a4dca83d3 100644 (file)
@@ -39,6 +39,8 @@
 #define BERLIN_PWM_TCNT                        0xc
 #define  BERLIN_PWM_MAX_TCNT           65535
 
+#define BERLIN_PWM_NUMPWMS             4
+
 struct berlin_pwm_channel {
        u32 enable;
        u32 ctrl;
@@ -50,6 +52,7 @@ struct berlin_pwm_chip {
        struct pwm_chip chip;
        struct clk *clk;
        void __iomem *base;
+       struct berlin_pwm_channel channel[BERLIN_PWM_NUMPWMS];
 };
 
 static inline struct berlin_pwm_chip *to_berlin_pwm_chip(struct pwm_chip *chip)
@@ -70,24 +73,6 @@ static inline void berlin_pwm_writel(struct berlin_pwm_chip *bpc,
        writel_relaxed(value, bpc->base + channel * 0x10 + offset);
 }
 
-static int berlin_pwm_request(struct pwm_chip *chip, struct pwm_device *pwm)
-{
-       struct berlin_pwm_channel *channel;
-
-       channel = kzalloc(sizeof(*channel), GFP_KERNEL);
-       if (!channel)
-               return -ENOMEM;
-
-       return pwm_set_chip_data(pwm, channel);
-}
-
-static void berlin_pwm_free(struct pwm_chip *chip, struct pwm_device *pwm)
-{
-       struct berlin_pwm_channel *channel = pwm_get_chip_data(pwm);
-
-       kfree(channel);
-}
-
 static int berlin_pwm_config(struct pwm_chip *chip, struct pwm_device *pwm,
                             u64 duty_ns, u64 period_ns)
 {
@@ -202,10 +187,7 @@ static int berlin_pwm_apply(struct pwm_chip *chip, struct pwm_device *pwm,
 }
 
 static const struct pwm_ops berlin_pwm_ops = {
-       .request = berlin_pwm_request,
-       .free = berlin_pwm_free,
        .apply = berlin_pwm_apply,
-       .owner = THIS_MODULE,
 };
 
 static const struct of_device_id berlin_pwm_match[] = {
@@ -227,39 +209,23 @@ static int berlin_pwm_probe(struct platform_device *pdev)
        if (IS_ERR(bpc->base))
                return PTR_ERR(bpc->base);
 
-       bpc->clk = devm_clk_get(&pdev->dev, NULL);
+       bpc->clk = devm_clk_get_enabled(&pdev->dev, NULL);
        if (IS_ERR(bpc->clk))
                return PTR_ERR(bpc->clk);
 
-       ret = clk_prepare_enable(bpc->clk);
-       if (ret)
-               return ret;
-
        bpc->chip.dev = &pdev->dev;
        bpc->chip.ops = &berlin_pwm_ops;
-       bpc->chip.npwm = 4;
+       bpc->chip.npwm = BERLIN_PWM_NUMPWMS;
 
-       ret = pwmchip_add(&bpc->chip);
-       if (ret < 0) {
-               dev_err(&pdev->dev, "failed to add PWM chip: %d\n", ret);
-               clk_disable_unprepare(bpc->clk);
-               return ret;
-       }
+       ret = devm_pwmchip_add(&pdev->dev, &bpc->chip);
+       if (ret < 0)
+               return dev_err_probe(&pdev->dev, ret, "failed to add PWM chip\n");
 
        platform_set_drvdata(pdev, bpc);
 
        return 0;
 }
 
-static void berlin_pwm_remove(struct platform_device *pdev)
-{
-       struct berlin_pwm_chip *bpc = platform_get_drvdata(pdev);
-
-       pwmchip_remove(&bpc->chip);
-
-       clk_disable_unprepare(bpc->clk);
-}
-
 #ifdef CONFIG_PM_SLEEP
 static int berlin_pwm_suspend(struct device *dev)
 {
@@ -267,11 +233,7 @@ static int berlin_pwm_suspend(struct device *dev)
        unsigned int i;
 
        for (i = 0; i < bpc->chip.npwm; i++) {
-               struct berlin_pwm_channel *channel;
-
-               channel = pwm_get_chip_data(&bpc->chip.pwms[i]);
-               if (!channel)
-                       continue;
+               struct berlin_pwm_channel *channel = &bpc->channel[i];
 
                channel->enable = berlin_pwm_readl(bpc, i, BERLIN_PWM_ENABLE);
                channel->ctrl = berlin_pwm_readl(bpc, i, BERLIN_PWM_CONTROL);
@@ -295,11 +257,7 @@ static int berlin_pwm_resume(struct device *dev)
                return ret;
 
        for (i = 0; i < bpc->chip.npwm; i++) {
-               struct berlin_pwm_channel *channel;
-
-               channel = pwm_get_chip_data(&bpc->chip.pwms[i]);
-               if (!channel)
-                       continue;
+               struct berlin_pwm_channel *channel = &bpc->channel[i];
 
                berlin_pwm_writel(bpc, i, channel->ctrl, BERLIN_PWM_CONTROL);
                berlin_pwm_writel(bpc, i, channel->duty, BERLIN_PWM_DUTY);
@@ -316,7 +274,6 @@ static SIMPLE_DEV_PM_OPS(berlin_pwm_pm_ops, berlin_pwm_suspend,
 
 static struct platform_driver berlin_pwm_driver = {
        .probe = berlin_pwm_probe,
-       .remove_new = berlin_pwm_remove,
        .driver = {
                .name = "berlin-pwm",
                .of_match_table = berlin_pwm_match,
This page took 0.029704 seconds and 4 git commands to generate.