ramips: modernize pwm driver

Add more devm usage.

Signed-off-by: Rosen Penev <rosenp@gmail.com>
Link: https://github.com/openwrt/openwrt/pull/16649
Signed-off-by: Hauke Mehrtens <hauke@hauke-m.de>
This commit is contained in:
Rosen Penev 2024-10-09 13:44:56 -07:00 committed by Hauke Mehrtens
parent b5c7c67b8f
commit 0f5e5dee1d
1 changed files with 4 additions and 14 deletions

View File

@ -41,7 +41,7 @@ Signed-off-by: John Crispin <blogic@openwrt.org>
obj-$(CONFIG_PWM_MXS) += pwm-mxs.o
--- /dev/null
+++ b/drivers/pwm/pwm-mediatek-ramips.c
@@ -0,0 +1,197 @@
@@ -0,0 +1,187 @@
+/*
+ * Mediatek Pulse Width Modulator driver
+ *
@ -178,30 +178,23 @@ Signed-off-by: John Crispin <blogic@openwrt.org>
+static int mtk_pwm_probe(struct platform_device *pdev)
+{
+ struct mtk_pwm_chip *pc;
+ struct resource *r;
+ int ret;
+
+ pc = devm_kzalloc(&pdev->dev, sizeof(*pc), GFP_KERNEL);
+ if (!pc)
+ return -ENOMEM;
+
+ r = platform_get_resource(pdev, IORESOURCE_MEM, 0);
+ pc->mmio_base = devm_ioremap_resource(&pdev->dev, r);
+ pc->mmio_base = devm_platform_ioremap_resource(pdev, 0);
+ if (IS_ERR(pc->mmio_base))
+ return PTR_ERR(pc->mmio_base);
+
+ platform_set_drvdata(pdev, pc);
+
+ pc->chip.dev = &pdev->dev;
+ pc->chip.ops = &mtk_pwm_ops;
+ pc->chip.base = -1;
+ pc->chip.npwm = NUM_PWM;
+
+ ret = pwmchip_add(&pc->chip);
+ if (ret < 0)
+ dev_err(&pdev->dev, "pwmchip_add() failed: %d\n", ret);
+ platform_set_drvdata(pdev, pc);
+
+ return ret;
+ return devm_pwmchip_add(&pdev->dev, &pc->chip);
+}
+
+static int mtk_pwm_remove(struct platform_device *pdev)
@ -212,8 +205,6 @@ Signed-off-by: John Crispin <blogic@openwrt.org>
+ for (i = 0; i < NUM_PWM; i++)
+ pwm_disable(&pc->chip.pwms[i]);
+
+ pwmchip_remove(&pc->chip);
+
+ return 0;
+}
+
@ -227,7 +218,6 @@ Signed-off-by: John Crispin <blogic@openwrt.org>
+static struct platform_driver mtk_pwm_driver = {
+ .driver = {
+ .name = "mtk-pwm",
+ .owner = THIS_MODULE,
+ .of_match_table = mtk_pwm_of_match,
+ },
+ .probe = mtk_pwm_probe,