linux-arm-kernel.lists.infradead.org archive mirror
 help / color / mirror / Atom feed
From: "Uwe Kleine-König" <u.kleine-koenig@pengutronix.de>
To: Thierry Reding <thierry.reding@gmail.com>
Cc: kernel@pengutronix.de, Chen-Yu Tsai <wens@csie.org>,
	Jernej Skrabec <jernej.skrabec@gmail.com>,
	Samuel Holland <samuel@sholland.org>,
	linux-pwm@vger.kernel.org, linux-arm-kernel@lists.infradead.org,
	linux-sunxi@lists.linux.dev
Subject: [PATCH v4 097/115] pwm: sun4i: Make use of devm_pwmchip_alloc() function
Date: Wed,  6 Dec 2023 12:44:51 +0100	[thread overview]
Message-ID: <c79e120b120df9eedddaaf70364d28e15df23d91.1701860672.git.u.kleine-koenig@pengutronix.de> (raw)
In-Reply-To: <cover.1701860672.git.u.kleine-koenig@pengutronix.de>

This prepares the pwm-sun4i driver to further changes of the pwm core
outlined in the commit introducing devm_pwmchip_alloc(). There is no
intended semantical change and the driver should behave as before.

Signed-off-by: Uwe Kleine-König <u.kleine-koenig@pengutronix.de>
---
 drivers/pwm/pwm-sun4i.c | 34 +++++++++++++++++++---------------
 1 file changed, 19 insertions(+), 15 deletions(-)

diff --git a/drivers/pwm/pwm-sun4i.c b/drivers/pwm/pwm-sun4i.c
index 44edf1ce5739..36a8dc65b19c 100644
--- a/drivers/pwm/pwm-sun4i.c
+++ b/drivers/pwm/pwm-sun4i.c
@@ -81,7 +81,6 @@ struct sun4i_pwm_data {
 };
 
 struct sun4i_pwm_chip {
-	struct pwm_chip chip;
 	struct clk *bus_clk;
 	struct clk *clk;
 	struct reset_control *rst;
@@ -92,7 +91,7 @@ struct sun4i_pwm_chip {
 
 static inline struct sun4i_pwm_chip *to_sun4i_pwm_chip(struct pwm_chip *chip)
 {
-	return container_of(chip, struct sun4i_pwm_chip, chip);
+	return pwmchip_get_drvdata(chip);
 }
 
 static inline u32 sun4i_pwm_readl(struct sun4i_pwm_chip *chip,
@@ -384,17 +383,22 @@ MODULE_DEVICE_TABLE(of, sun4i_pwm_dt_ids);
 
 static int sun4i_pwm_probe(struct platform_device *pdev)
 {
+	struct pwm_chip *chip;
 	struct sun4i_pwm_chip *sun4ichip;
+	const struct sun4i_pwm_data *data;
 	int ret;
 
-	sun4ichip = devm_kzalloc(&pdev->dev, sizeof(*sun4ichip), GFP_KERNEL);
-	if (!sun4ichip)
-		return -ENOMEM;
-
-	sun4ichip->data = of_device_get_match_data(&pdev->dev);
-	if (!sun4ichip->data)
+	data = of_device_get_match_data(&pdev->dev);
+	if (!data)
 		return -ENODEV;
 
+	chip = devm_pwmchip_alloc(&pdev->dev, data->npwm, sizeof(*sun4ichip));
+	if (IS_ERR(chip))
+		return PTR_ERR(chip);
+	sun4ichip = to_sun4i_pwm_chip(chip);
+
+	sun4ichip->data = data;
+
 	sun4ichip->base = devm_platform_ioremap_resource(pdev, 0);
 	if (IS_ERR(sun4ichip->base))
 		return PTR_ERR(sun4ichip->base);
@@ -451,19 +455,18 @@ static int sun4i_pwm_probe(struct platform_device *pdev)
 		goto err_bus;
 	}
 
-	sun4ichip->chip.dev = &pdev->dev;
-	sun4ichip->chip.ops = &sun4i_pwm_ops;
-	sun4ichip->chip.npwm = sun4ichip->data->npwm;
+	chip->ops = &sun4i_pwm_ops;
+	chip->npwm = sun4ichip->data->npwm;
 
 	spin_lock_init(&sun4ichip->ctrl_lock);
 
-	ret = pwmchip_add(&sun4ichip->chip);
+	ret = pwmchip_add(chip);
 	if (ret < 0) {
 		dev_err(&pdev->dev, "failed to add PWM chip: %d\n", ret);
 		goto err_pwm_add;
 	}
 
-	platform_set_drvdata(pdev, sun4ichip);
+	platform_set_drvdata(pdev, chip);
 
 	return 0;
 
@@ -477,9 +480,10 @@ static int sun4i_pwm_probe(struct platform_device *pdev)
 
 static void sun4i_pwm_remove(struct platform_device *pdev)
 {
-	struct sun4i_pwm_chip *sun4ichip = platform_get_drvdata(pdev);
+	struct pwm_chip *chip = platform_get_drvdata(pdev);
+	struct sun4i_pwm_chip *sun4ichip = to_sun4i_pwm_chip(chip);
 
-	pwmchip_remove(&sun4ichip->chip);
+	pwmchip_remove(chip);
 
 	clk_disable_unprepare(sun4ichip->bus_clk);
 	reset_control_assert(sun4ichip->rst);
-- 
2.42.0


_______________________________________________
linux-arm-kernel mailing list
linux-arm-kernel@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/linux-arm-kernel

  parent reply	other threads:[~2023-12-06 11:51 UTC|newest]

Thread overview: 49+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
     [not found] <cover.1701860672.git.u.kleine-koenig@pengutronix.de>
2023-12-06 11:43 ` [PATCH v4 009/115] pwm: atmel: Make use of pwmchip_parent() macro Uwe Kleine-König
2023-12-06 11:43 ` [PATCH v4 010/115] pwm: atmel-tcb: " Uwe Kleine-König
2023-12-06 11:43 ` [PATCH v4 018/115] pwm: imx27: " Uwe Kleine-König
2023-12-06 11:43 ` [PATCH v4 020/115] pwm: lpc18xx-sct: Make use of parent device pointer in driver data Uwe Kleine-König
2023-12-06 11:43 ` [PATCH v4 022/115] pwm: mediatek: Make use of pwmchip_parent() macro Uwe Kleine-König
2023-12-06 11:43 ` [PATCH v4 023/115] pwm: meson: " Uwe Kleine-König
2023-12-06 11:43 ` [PATCH v4 024/115] pwm: mtk-disp: " Uwe Kleine-König
2023-12-06 11:43 ` [PATCH v4 027/115] pwm: raspberrypi-poe: " Uwe Kleine-König
2023-12-06 11:43 ` [PATCH v4 030/115] pwm: samsung: " Uwe Kleine-König
2023-12-06 11:43 ` [PATCH v4 032/115] pwm: stm32-lp: " Uwe Kleine-König
2023-12-06 11:43 ` [PATCH v4 033/115] pwm: stm32: " Uwe Kleine-König
2023-12-06 11:43 ` [PATCH v4 034/115] pwm: stmpe: " Uwe Kleine-König
2023-12-06 11:43 ` [PATCH v4 035/115] pwm: sun4i: " Uwe Kleine-König
2023-12-06 11:43 ` [PATCH v4 040/115] pwm: vt8500: " Uwe Kleine-König
2023-12-06 11:43 ` [PATCH v4 045/115] pwm: apple: Make use of devm_pwmchip_alloc() function Uwe Kleine-König
2023-12-06 11:44 ` [PATCH v4 046/115] pwm: atmel-hlcdc: " Uwe Kleine-König
2023-12-06 11:44 ` [PATCH v4 047/115] pwm: atmel: " Uwe Kleine-König
2023-12-06 11:44 ` [PATCH v4 048/115] pwm: atmel-tcb: " Uwe Kleine-König
2023-12-06 11:44 ` [PATCH v4 049/115] pwm: bcm2835: " Uwe Kleine-König
2023-12-06 11:44 ` [PATCH v4 050/115] pwm: bcm-iproc: " Uwe Kleine-König
2023-12-06 11:44 ` [PATCH v4 053/115] pwm: brcmstb: " Uwe Kleine-König
2023-12-06 11:44 ` [PATCH v4 055/115] pwm: clps711x: " Uwe Kleine-König
2023-12-06 11:44 ` [PATCH v4 063/115] pwm: imx1: " Uwe Kleine-König
2023-12-06 11:44 ` [PATCH v4 064/115] pwm: imx27: " Uwe Kleine-König
2023-12-06 11:44 ` [PATCH v4 065/115] pwm: imx-tpm: " Uwe Kleine-König
2023-12-06 11:44 ` [PATCH v4 071/115] pwm: lpc18xx-sct: " Uwe Kleine-König
2023-12-06 11:44 ` [PATCH v4 072/115] pwm: lpc32xx: " Uwe Kleine-König
2023-12-06 11:44 ` [PATCH v4 074/115] pwm: mediatek: " Uwe Kleine-König
2023-12-06 11:44 ` [PATCH v4 075/115] pwm: meson: " Uwe Kleine-König
2023-12-06 11:44 ` [PATCH v4 077/115] pwm: mtk-disp: " Uwe Kleine-König
2023-12-06 11:44 ` [PATCH v4 078/115] pwm: mxs: " Uwe Kleine-König
2023-12-06 11:44 ` [PATCH v4 083/115] pwm: raspberrypi-poe: " Uwe Kleine-König
2023-12-06 11:44 ` [PATCH v4 086/115] pwm: rockchip: " Uwe Kleine-König
2023-12-06 13:06   ` Heiko Stübner
2023-12-06 11:44 ` [PATCH v4 088/115] pwm: samsung: " Uwe Kleine-König
2023-12-06 11:44 ` [PATCH v4 094/115] pwm: stm32-lp: " Uwe Kleine-König
2023-12-06 11:44 ` [PATCH v4 095/115] pwm: stm32: " Uwe Kleine-König
2023-12-06 11:44 ` [PATCH v4 096/115] pwm: stmpe: " Uwe Kleine-König
2023-12-06 11:44 ` Uwe Kleine-König [this message]
2023-12-06 17:11   ` [PATCH v4 097/115] pwm: sun4i: " Andre Przywara
2023-12-13 20:31   ` Jernej Škrabec
2023-12-06 11:44 ` [PATCH v4 103/115] pwm: visconti: " Uwe Kleine-König
2023-12-06 11:44 ` [PATCH v4 104/115] pwm: vt8500: " Uwe Kleine-König
2023-12-06 11:44 ` [PATCH v4 105/115] pwm: xilinx: " Uwe Kleine-König
2023-12-08 15:41 ` [PATCH v4 000/115] pwm: Fix lifetime issues for pwm_chips Thierry Reding
2023-12-08 18:50   ` Uwe Kleine-König
2023-12-11 11:33     ` Thierry Reding
2023-12-11 12:18       ` Uwe Kleine-König
2023-12-12 21:05       ` Uwe Kleine-König

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=c79e120b120df9eedddaaf70364d28e15df23d91.1701860672.git.u.kleine-koenig@pengutronix.de \
    --to=u.kleine-koenig@pengutronix.de \
    --cc=jernej.skrabec@gmail.com \
    --cc=kernel@pengutronix.de \
    --cc=linux-arm-kernel@lists.infradead.org \
    --cc=linux-pwm@vger.kernel.org \
    --cc=linux-sunxi@lists.linux.dev \
    --cc=samuel@sholland.org \
    --cc=thierry.reding@gmail.com \
    --cc=wens@csie.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).