From: Hironori KIKUCHI <kikuchan98@gmail.com>
To: linux-kernel@vger.kernel.org
Cc: "Hironori KIKUCHI" <kikuchan98@gmail.com>,
"Uwe Kleine-König" <ukleinek@kernel.org>,
"Rob Herring" <robh@kernel.org>,
"Krzysztof Kozlowski" <krzk+dt@kernel.org>,
"Conor Dooley" <conor+dt@kernel.org>,
"Chen-Yu Tsai" <wens@csie.org>,
"Jernej Skrabec" <jernej.skrabec@gmail.com>,
"Samuel Holland" <samuel@sholland.org>,
"Aleksandr Shubin" <privatesub2@gmail.com>,
"Cheo Fusi" <fusibrandon13@gmail.com>,
linux-pwm@vger.kernel.org, devicetree@vger.kernel.org,
linux-arm-kernel@lists.infradead.org,
linux-sunxi@lists.linux.dev
Subject: [PATCH 1/5] pwm: sun20i: Use devm_pwmchip_alloc() helper
Date: Fri, 31 May 2024 23:11:33 +0900 [thread overview]
Message-ID: <20240531141152.327592-2-kikuchan98@gmail.com> (raw)
In-Reply-To: <20240531141152.327592-1-kikuchan98@gmail.com>
This patch fixes a compile error by using the devm_pwmchip_alloc() helper
function along the way.
Signed-off-by: Hironori KIKUCHI <kikuchan98@gmail.com>
---
drivers/pwm/pwm-sun20i.c | 45 ++++++++++++++++++++++------------------
1 file changed, 25 insertions(+), 20 deletions(-)
diff --git a/drivers/pwm/pwm-sun20i.c b/drivers/pwm/pwm-sun20i.c
index 3e3b5b138b3..93782023af6 100644
--- a/drivers/pwm/pwm-sun20i.c
+++ b/drivers/pwm/pwm-sun20i.c
@@ -102,7 +102,7 @@ struct sun20i_pwm_chip {
static inline struct sun20i_pwm_chip *to_sun20i_pwm_chip(struct pwm_chip *chip)
{
- return container_of(chip, struct sun20i_pwm_chip, chip);
+ return pwmchip_get_drvdata(chip);
}
static inline u32 sun20i_pwm_readl(struct sun20i_pwm_chip *chip,
@@ -308,12 +308,31 @@ static void sun20i_pwm_reset_ctrl_release(void *data)
static int sun20i_pwm_probe(struct platform_device *pdev)
{
+ struct pwm_chip *chip;
struct sun20i_pwm_chip *sun20i_chip;
+ const struct sun20i_pwm_data *data;
+ u32 npwm;
int ret;
- sun20i_chip = devm_kzalloc(&pdev->dev, sizeof(*sun20i_chip), GFP_KERNEL);
- if (!sun20i_chip)
- return -ENOMEM;
+ data = of_device_get_match_data(&pdev->dev);
+ if (!data)
+ return -ENODEV;
+
+ ret = of_property_read_u32(pdev->dev.of_node, "allwinner,pwm-channels", &npwm);
+ if (ret)
+ npwm = 8;
+
+ if (npwm > 16) {
+ dev_info(&pdev->dev, "Limiting number of PWM lines from %u to 16", npwm);
+ npwm = 16;
+ }
+
+ chip = devm_pwmchip_alloc(&pdev->dev, npwm, sizeof(*sun20i_chip));
+ if (IS_ERR(chip))
+ return PTR_ERR(chip);
+ sun20i_chip = to_sun20i_pwm_chip(chip);
+
+ sun20i_chip->data = data;
sun20i_chip->base = devm_platform_ioremap_resource(pdev, 0);
if (IS_ERR(sun20i_chip->base))
@@ -339,17 +358,6 @@ static int sun20i_pwm_probe(struct platform_device *pdev)
return dev_err_probe(&pdev->dev, PTR_ERR(sun20i_chip->rst),
"failed to get bus reset\n");
- ret = of_property_read_u32(pdev->dev.of_node, "allwinner,pwm-channels",
- &sun20i_chip->chip.npwm);
- if (ret)
- sun20i_chip->chip.npwm = 8;
-
- if (sun20i_chip->chip.npwm > 16) {
- dev_info(&pdev->dev, "Limiting number of PWM lines from %u to 16",
- sun20i_chip->chip.npwm);
- sun20i_chip->chip.npwm = 16;
- }
-
/* Deassert reset */
ret = reset_control_deassert(sun20i_chip->rst);
if (ret)
@@ -359,17 +367,14 @@ static int sun20i_pwm_probe(struct platform_device *pdev)
if (ret)
return ret;
- sun20i_chip->chip.dev = &pdev->dev;
- sun20i_chip->chip.ops = &sun20i_pwm_ops;
+ chip->ops = &sun20i_pwm_ops;
mutex_init(&sun20i_chip->mutex);
- ret = devm_pwmchip_add(&pdev->dev, &sun20i_chip->chip);
+ ret = devm_pwmchip_add(&pdev->dev, chip);
if (ret < 0)
return dev_err_probe(&pdev->dev, ret, "failed to add PWM chip\n");
- platform_set_drvdata(pdev, sun20i_chip);
-
return 0;
}
--
2.45.1
next prev parent reply other threads:[~2024-05-31 14:12 UTC|newest]
Thread overview: 17+ messages / expand[flat|nested] mbox.gz Atom feed top
2024-05-31 14:11 [PATCH 0/5] Add support for Allwinner H616 PWM Hironori KIKUCHI
2024-05-31 14:11 ` Hironori KIKUCHI [this message]
2024-05-31 14:11 ` [PATCH 2/5] pwm: sun20i: " Hironori KIKUCHI
2024-07-13 12:37 ` Uwe Kleine-König
2024-05-31 14:11 ` [PATCH 3/5] dt-bindings: pwm: sun20i: Add compatible string " Hironori KIKUCHI
2024-05-31 14:39 ` Krzysztof Kozlowski
2024-05-31 17:50 ` Hironori KIKUCHI
2024-05-31 14:11 ` [PATCH 4/5] pwm: sun20i: Delegating the clock source and DIV_M to the Device Tree Hironori KIKUCHI
2024-05-31 14:11 ` [PATCH 5/5] dt-bindings: pwm: sun20i: Add options to select a clock source and DIV_M Hironori KIKUCHI
2024-05-31 14:43 ` Krzysztof Kozlowski
2024-05-31 17:57 ` Hironori KIKUCHI
2024-06-01 15:17 ` Krzysztof Kozlowski
2024-06-02 6:15 ` Hironori KIKUCHI
2024-06-03 0:09 ` Andre Przywara
2024-06-03 8:42 ` Hironori KIKUCHI
2024-07-13 12:58 ` Uwe Kleine-König
2024-06-05 13:38 ` [PATCH 0/5] Add support for Allwinner H616 PWM 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=20240531141152.327592-2-kikuchan98@gmail.com \
--to=kikuchan98@gmail.com \
--cc=conor+dt@kernel.org \
--cc=devicetree@vger.kernel.org \
--cc=fusibrandon13@gmail.com \
--cc=jernej.skrabec@gmail.com \
--cc=krzk+dt@kernel.org \
--cc=linux-arm-kernel@lists.infradead.org \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-pwm@vger.kernel.org \
--cc=linux-sunxi@lists.linux.dev \
--cc=privatesub2@gmail.com \
--cc=robh@kernel.org \
--cc=samuel@sholland.org \
--cc=ukleinek@kernel.org \
--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