From: Xianwei Zhao via B4 Relay <devnull+xianwei.zhao.amlogic.com@kernel.org>
To: "Uwe Kleine-König" <ukleinek@kernel.org>,
"Rob Herring" <robh@kernel.org>,
"Krzysztof Kozlowski" <krzk+dt@kernel.org>,
"Conor Dooley" <conor+dt@kernel.org>,
"Heiner Kallweit" <hkallweit1@gmail.com>,
"Neil Armstrong" <neil.armstrong@linaro.org>,
"Kevin Hilman" <khilman@baylibre.com>,
"Jerome Brunet" <jbrunet@baylibre.com>,
"Martin Blumenstingl" <martin.blumenstingl@googlemail.com>
Cc: linux-pwm@vger.kernel.org, devicetree@vger.kernel.org,
linux-kernel@vger.kernel.org,
linux-arm-kernel@lists.infradead.org,
linux-amlogic@lists.infradead.org,
Xianwei Zhao <xianwei.zhao@amlogic.com>,
Alexandre Mergnat <amergnat@baylibre.com>
Subject: [PATCH v6 2/3] pwm: meson: add the PWM count driver data
Date: Tue, 01 Dec 2026 03:34:13 +0000 [thread overview]
Message-ID: <20261201-s6-s7-pwm-v6-2-703cc13d4da5@amlogic.com> (raw)
In-Reply-To: <20261201-s6-s7-pwm-v6-0-703cc13d4da5@amlogic.com>
From: Xianwei Zhao <xianwei.zhao@amlogic.com>
To prepare adding support for S6, S7 and S7D SoCs which don't have 2
but 1 PWM outputs, make the various loops iterate using chip->npwm
instead of the constant MESON_NUM_PWMS. Add npwm to struct
meson_pwm_data, and set .npwm = 2 for existing variants.
Reviewed-by: Alexandre Mergnat <amergnat@baylibre.com>
Signed-off-by: Xianwei Zhao <xianwei.zhao@amlogic.com>
---
drivers/pwm/pwm-meson.c | 20 +++++++++++++++++---
1 file changed, 17 insertions(+), 3 deletions(-)
diff --git a/drivers/pwm/pwm-meson.c b/drivers/pwm/pwm-meson.c
index 3a28c853089f..a4b5f3877607 100644
--- a/drivers/pwm/pwm-meson.c
+++ b/drivers/pwm/pwm-meson.c
@@ -108,6 +108,7 @@ struct meson_pwm_data {
int (*channels_init)(struct pwm_chip *chip);
bool has_constant;
bool has_polarity;
+ u8 npwm;
};
struct meson_pwm {
@@ -440,7 +441,7 @@ static int meson_pwm_init_clocks_meson8b(struct pwm_chip *chip,
char name[255];
int err;
- for (i = 0; i < MESON_NUM_PWMS; i++) {
+ for (i = 0; i < chip->npwm; i++) {
struct meson_pwm_channel *channel = &meson->channels[i];
struct clk_parent_data div_parent = {}, gate_parent = {};
struct clk_init_data init = {};
@@ -580,6 +581,7 @@ static int meson_pwm_init_channels_per_channel_clk(struct pwm_chip *chip)
static const struct meson_pwm_data pwm_meson8b_data = {
.parent_names = { "xtal", NULL, "fclk_div4", "fclk_div3" },
.channels_init = meson_pwm_init_channels_meson8b_legacy,
+ .npwm = 2,
};
/*
@@ -589,6 +591,7 @@ static const struct meson_pwm_data pwm_meson8b_data = {
static const struct meson_pwm_data pwm_gxbb_ao_data = {
.parent_names = { "xtal", "clk81", NULL, NULL },
.channels_init = meson_pwm_init_channels_meson8b_legacy,
+ .npwm = 2,
};
static const struct meson_pwm_data pwm_axg_ee_data = {
@@ -596,6 +599,7 @@ static const struct meson_pwm_data pwm_axg_ee_data = {
.channels_init = meson_pwm_init_channels_meson8b_legacy,
.has_constant = true,
.has_polarity = true,
+ .npwm = 2,
};
static const struct meson_pwm_data pwm_axg_ao_data = {
@@ -603,6 +607,7 @@ static const struct meson_pwm_data pwm_axg_ao_data = {
.channels_init = meson_pwm_init_channels_meson8b_legacy,
.has_constant = true,
.has_polarity = true,
+ .npwm = 2,
};
static const struct meson_pwm_data pwm_g12a_ee_data = {
@@ -610,6 +615,7 @@ static const struct meson_pwm_data pwm_g12a_ee_data = {
.channels_init = meson_pwm_init_channels_meson8b_legacy,
.has_constant = true,
.has_polarity = true,
+ .npwm = 2,
};
static const struct meson_pwm_data pwm_g12a_ao_ab_data = {
@@ -617,6 +623,7 @@ static const struct meson_pwm_data pwm_g12a_ao_ab_data = {
.channels_init = meson_pwm_init_channels_meson8b_legacy,
.has_constant = true,
.has_polarity = true,
+ .npwm = 2,
};
static const struct meson_pwm_data pwm_g12a_ao_cd_data = {
@@ -624,22 +631,26 @@ static const struct meson_pwm_data pwm_g12a_ao_cd_data = {
.channels_init = meson_pwm_init_channels_meson8b_legacy,
.has_constant = true,
.has_polarity = true,
+ .npwm = 2,
};
static const struct meson_pwm_data pwm_meson8_v2_data = {
.channels_init = meson_pwm_init_channels_meson8b_v2,
+ .npwm = 2,
};
static const struct meson_pwm_data pwm_meson_axg_v2_data = {
.channels_init = meson_pwm_init_channels_meson8b_v2,
.has_constant = true,
.has_polarity = true,
+ .npwm = 2,
};
static const struct meson_pwm_data pwm_s4_data = {
.channels_init = meson_pwm_init_channels_per_channel_clk,
.has_constant = true,
.has_polarity = true,
+ .npwm = 2,
};
static const struct of_device_id meson_pwm_matches[] = {
@@ -699,9 +710,12 @@ static int meson_pwm_probe(struct platform_device *pdev)
{
struct pwm_chip *chip;
struct meson_pwm *meson;
+ const struct meson_pwm_data *pdata = of_device_get_match_data(&pdev->dev);
int err;
- chip = devm_pwmchip_alloc(&pdev->dev, MESON_NUM_PWMS, sizeof(*meson));
+ if (pdata->npwm > 2)
+ return -EINVAL;
+ chip = devm_pwmchip_alloc(&pdev->dev, pdata->npwm, sizeof(*meson));
if (IS_ERR(chip))
return PTR_ERR(chip);
meson = to_meson_pwm(chip);
@@ -713,7 +727,7 @@ static int meson_pwm_probe(struct platform_device *pdev)
spin_lock_init(&meson->lock);
chip->ops = &meson_pwm_ops;
- meson->data = of_device_get_match_data(&pdev->dev);
+ meson->data = pdata;
err = meson->data->channels_init(chip);
if (err < 0)
--
2.52.0
_______________________________________________
linux-amlogic mailing list
linux-amlogic@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/linux-amlogic
next prev parent reply other threads:[~2026-12-01 3:34 UTC|newest]
Thread overview: 5+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-12-01 3:34 [PATCH v6 0/3] Add PWM support Amlogic S7 S7D S6 Xianwei Zhao via B4 Relay
2026-12-01 3:34 ` [PATCH v6 1/3] dt-bindings: pwm: amlogic: Add S6, S7 and S7D PWM Xianwei Zhao via B4 Relay
2026-12-01 3:34 ` Xianwei Zhao via B4 Relay [this message]
2026-12-01 3:38 ` [PATCH v6 2/3] pwm: meson: add the PWM count driver data sashiko-bot
2026-12-01 3:34 ` [PATCH v6 3/3] pwm: meson: Add support for Amlogic S7 Xianwei Zhao via B4 Relay
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=20261201-s6-s7-pwm-v6-2-703cc13d4da5@amlogic.com \
--to=devnull+xianwei.zhao.amlogic.com@kernel.org \
--cc=amergnat@baylibre.com \
--cc=conor+dt@kernel.org \
--cc=devicetree@vger.kernel.org \
--cc=hkallweit1@gmail.com \
--cc=jbrunet@baylibre.com \
--cc=khilman@baylibre.com \
--cc=krzk+dt@kernel.org \
--cc=linux-amlogic@lists.infradead.org \
--cc=linux-arm-kernel@lists.infradead.org \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-pwm@vger.kernel.org \
--cc=martin.blumenstingl@googlemail.com \
--cc=neil.armstrong@linaro.org \
--cc=robh@kernel.org \
--cc=ukleinek@kernel.org \
--cc=xianwei.zhao@amlogic.com \
/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
all inboxes | Powered by JetHome®