From: Jonathan Cameron <jic23@kernel.org>
To: Fabrice Gasnier <fabrice.gasnier@foss.st.com>
Cc: <lee@kernel.org>, <ukleinek@kernel.org>,
<alexandre.torgue@foss.st.com>, <robh@kernel.org>,
<krzk+dt@kernel.org>, <conor+dt@kernel.org>, <wbg@kernel.org>,
<daniel.lezcano@linaro.org>, <tglx@linutronix.de>,
<catalin.marinas@arm.com>, <will@kernel.org>,
<devicetree@vger.kernel.org>,
<linux-stm32@st-md-mailman.stormreply.com>,
<linux-arm-kernel@lists.infradead.org>,
<linux-kernel@vger.kernel.org>, <linux-iio@vger.kernel.org>,
<linux-pwm@vger.kernel.org>, <olivier.moysan@foss.st.com>
Subject: Re: [PATCH 3/8] iio: trigger: stm32-lptimer: add support for stm32mp25
Date: Wed, 5 Mar 2025 14:38:24 +0000 [thread overview]
Message-ID: <20250305143824.138a2605@jic23-huawei> (raw)
In-Reply-To: <20250224180150.3689638-4-fabrice.gasnier@foss.st.com>
On Mon, 24 Feb 2025 19:01:45 +0100
Fabrice Gasnier <fabrice.gasnier@foss.st.com> wrote:
> From: Olivier Moysan <olivier.moysan@foss.st.com>
>
> Add support for STM32MP25 SoC. Use newly introduced compatible to handle
> this new HW variant. Add new trigger definitions that can be used by the
> stm32 analog-to-digital converter. Use compatible data to identify them.
>
> Signed-off-by: Olivier Moysan <olivier.moysan@foss.st.com>
> Signed-off-by: Fabrice Gasnier <fabrice.gasnier@foss.st.com>
Hi. I'm not really following why you can't use devm calls for the
trigger probe path and hence why you need the explicit remove.
Feels like a lot of infrastructure and I can't see why we need it.
Jonathan
> @@ -54,25 +82,49 @@ bool is_stm32_lptim_trigger(struct iio_trigger *trig)
> }
> EXPORT_SYMBOL(is_stm32_lptim_trigger);
>
> -static int stm32_lptim_setup_trig(struct stm32_lptim_trigger *priv)
> +static void stm32_lptim_unregister_triggers(struct stm32_lptim_trigger *priv)
> {
> - struct iio_trigger *trig;
> + struct iio_trigger *tr;
>
> - trig = devm_iio_trigger_alloc(priv->dev, "%s", priv->trg);
> - if (!trig)
> - return -ENOMEM;
> + list_for_each_entry(tr, &priv->tr_list, alloc_list)
> + iio_trigger_unregister(tr);
> +}
> +
> +static int stm32_lptim_register_triggers(struct stm32_lptim_trigger *priv)
> +{
> + const char * const *cur = priv->triggers;
> + int ret;
>
> - trig->dev.parent = priv->dev->parent;
> - trig->ops = &stm32_lptim_trigger_ops;
> - iio_trigger_set_drvdata(trig, priv);
> + INIT_LIST_HEAD(&priv->tr_list);
>
> - return devm_iio_trigger_register(priv->dev, trig);
> + while (cur && *cur) {
> + struct iio_trigger *trig;
> +
> + trig = devm_iio_trigger_alloc(priv->dev, "%s", *cur);
> + if (!trig)
> + return -ENOMEM;
> +
> + trig->dev.parent = priv->dev->parent;
> + trig->ops = &stm32_lptim_trigger_ops;
> + iio_trigger_set_drvdata(trig, priv);
> +
> + ret = iio_trigger_register(trig);
I'm not really following why you can't use devm_iio_trigger_register() here
and avoid your own tracking with the list below.
> + if (ret)
> + return ret;
> +
> + list_add_tail(&trig->alloc_list, &priv->tr_list);
> + cur++;
> + }
> +
> + return 0;
> }
>
> static int stm32_lptim_trigger_probe(struct platform_device *pdev)
> {
> struct stm32_lptim_trigger *priv;
> + struct stm32_lptim_cfg const *lptim_cfg;
> u32 index;
> + int ret;
>
> priv = devm_kzalloc(&pdev->dev, sizeof(*priv), GFP_KERNEL);
> if (!priv)
> @@ -81,23 +133,42 @@ static int stm32_lptim_trigger_probe(struct platform_device *pdev)
> if (device_property_read_u32(&pdev->dev, "reg", &index))
> return -EINVAL;
>
> - if (index >= ARRAY_SIZE(stm32_lptim_triggers))
> + lptim_cfg = device_get_match_data(&pdev->dev);
> +
> + if (index >= lptim_cfg->nb_triggers)
> return -EINVAL;
>
> priv->dev = &pdev->dev;
> - priv->trg = stm32_lptim_triggers[index];
> + priv->triggers = lptim_cfg->triggers[index];
> +
> + ret = stm32_lptim_register_triggers(priv);
> + if (ret) {
> + stm32_lptim_unregister_triggers(priv);
> + return ret;
> + }
> +
> + platform_set_drvdata(pdev, priv);
> +
> + return 0;
> +}
> +
> +static void stm32_lptim_trigger_remove(struct platform_device *pdev)
> +{
> + struct stm32_lptim_trigger *priv = platform_get_drvdata(pdev);
>
> - return stm32_lptim_setup_trig(priv);
> + stm32_lptim_unregister_triggers(priv);
Why not a devm_add_action_or_reset?
or for that matter a devm_iio_trigger_register() in the first place.
> }
>
> static const struct of_device_id stm32_lptim_trig_of_match[] = {
> - { .compatible = "st,stm32-lptimer-trigger", },
> + { .compatible = "st,stm32-lptimer-trigger", .data = (void *)&stm32mp15_lptim_cfg },
> + { .compatible = "st,stm32mp25-lptimer-trigger", .data = (void *)&stm32mp25_lptim_cfg},
Why cast away a const then pass it to a const void *?
That is I don't think the casts are needed.
> {},
> };
> MODULE_DEVICE_TABLE(of, stm32_lptim_trig_of_match);
>
> static struct platform_driver stm32_lptim_trigger_driver = {
> .probe = stm32_lptim_trigger_probe,
> + .remove = stm32_lptim_trigger_remove,
> .driver = {
> .name = "stm32-lptimer-trigger",
> .of_match_table = stm32_lptim_trig_of_match,
> diff --git a/include/linux/iio/timer/stm32-lptim-trigger.h b/include/linux/iio/timer/stm32-lptim-trigger.h
> index a34dcf6a6001..ce3cf0addb2e 100644
> --- a/include/linux/iio/timer/stm32-lptim-trigger.h
> +++ b/include/linux/iio/timer/stm32-lptim-trigger.h
> @@ -14,6 +14,15 @@
> #define LPTIM1_OUT "lptim1_out"
> #define LPTIM2_OUT "lptim2_out"
> #define LPTIM3_OUT "lptim3_out"
> +#define LPTIM4_OUT "lptim4_out"
> +#define LPTIM5_OUT "lptim5_out"
> +
> +#define LPTIM1_CH1 "lptim1_ch1"
> +#define LPTIM1_CH2 "lptim1_ch2"
> +#define LPTIM2_CH1 "lptim2_ch1"
> +#define LPTIM2_CH2 "lptim2_ch2"
> +#define LPTIM3_CH1 "lptim3_ch1"
> +#define LPTIM4_CH1 "lptim4_ch1"
>
> #if IS_REACHABLE(CONFIG_IIO_STM32_LPTIMER_TRIGGER)
> bool is_stm32_lptim_trigger(struct iio_trigger *trig);
next prev parent reply other threads:[~2025-03-05 14:38 UTC|newest]
Thread overview: 29+ messages / expand[flat|nested] mbox.gz Atom feed top
2025-02-24 18:01 [PATCH 0/8] Add STM32MP25 LPTIM support: MFD, PWM, IIO, counter, clocksource Fabrice Gasnier
2025-02-24 18:01 ` [PATCH 1/8] dt-bindings: mfd: stm32-lptimer: add support for stm32mp25 Fabrice Gasnier
2025-02-25 12:02 ` Krzysztof Kozlowski
2025-02-25 14:57 ` Fabrice Gasnier
2025-02-26 7:51 ` Krzysztof Kozlowski
2025-02-26 18:17 ` Fabrice Gasnier
2025-02-24 18:01 ` [PATCH 2/8] " Fabrice Gasnier
2025-02-24 18:01 ` [PATCH 3/8] iio: trigger: " Fabrice Gasnier
2025-03-05 14:38 ` Jonathan Cameron [this message]
2025-02-24 18:01 ` [PATCH 4/8] clocksource: stm32-lptimer: add stm32mp25 support Fabrice Gasnier
2025-02-25 12:02 ` Krzysztof Kozlowski
2025-02-25 14:57 ` Fabrice Gasnier
2025-02-26 18:14 ` Fabrice Gasnier
2025-02-24 18:01 ` [PATCH 5/8] pwm: stm32-lp: add support for stm32mp25 Fabrice Gasnier
2025-02-25 12:04 ` Krzysztof Kozlowski
2025-02-25 14:58 ` Fabrice Gasnier
2025-02-26 7:54 ` Krzysztof Kozlowski
2025-02-26 18:14 ` Fabrice Gasnier
2025-02-24 18:01 ` [PATCH 6/8] counter: stm32-lptimer-cnt: " Fabrice Gasnier
2025-02-25 12:02 ` Krzysztof Kozlowski
2025-02-25 14:58 ` Fabrice Gasnier
2025-02-26 7:49 ` Krzysztof Kozlowski
2025-02-26 18:16 ` Fabrice Gasnier
2025-02-24 18:01 ` [PATCH 7/8] arm64: defconfig: enable STM32 LP timers drivers Fabrice Gasnier
2025-02-25 7:48 ` Krzysztof Kozlowski
2025-02-25 8:43 ` Fabrice Gasnier
2025-02-25 12:00 ` Krzysztof Kozlowski
2025-02-24 18:01 ` [PATCH 8/8] arm64: dts: st: add low-power timer nodes on stm32mp251 Fabrice Gasnier
2025-02-25 20:12 ` [PATCH 0/8] Add STM32MP25 LPTIM support: MFD, PWM, IIO, counter, clocksource Rob Herring (Arm)
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=20250305143824.138a2605@jic23-huawei \
--to=jic23@kernel.org \
--cc=alexandre.torgue@foss.st.com \
--cc=catalin.marinas@arm.com \
--cc=conor+dt@kernel.org \
--cc=daniel.lezcano@linaro.org \
--cc=devicetree@vger.kernel.org \
--cc=fabrice.gasnier@foss.st.com \
--cc=krzk+dt@kernel.org \
--cc=lee@kernel.org \
--cc=linux-arm-kernel@lists.infradead.org \
--cc=linux-iio@vger.kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-pwm@vger.kernel.org \
--cc=linux-stm32@st-md-mailman.stormreply.com \
--cc=olivier.moysan@foss.st.com \
--cc=robh@kernel.org \
--cc=tglx@linutronix.de \
--cc=ukleinek@kernel.org \
--cc=wbg@kernel.org \
--cc=will@kernel.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