iio: trigger: stm32-lptimer: add support for stm32mp25
authorOlivier Moysan <olivier.moysan@foss.st.com>
Fri, 14 Mar 2025 17:14:46 +0000 (18:14 +0100)
committerJonathan Cameron <Jonathan.Cameron@huawei.com>
Tue, 22 Apr 2025 18:09:54 +0000 (19:09 +0100)
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>
Link: https://patch.msgid.link/20250314171451.3497789-4-fabrice.gasnier@foss.st.com
Signed-off-by: Jonathan Cameron <Jonathan.Cameron@huawei.com>
drivers/iio/trigger/stm32-lptimer-trigger.c
include/linux/iio/timer/stm32-lptim-trigger.h

index f1e1891..3dcc8d2 100644 (file)
 #include <linux/platform_device.h>
 #include <linux/property.h>
 
-/* List Low-Power Timer triggers */
-static const char * const stm32_lptim_triggers[] = {
-       LPTIM1_OUT,
-       LPTIM2_OUT,
-       LPTIM3_OUT,
+/* Maximum triggers + one trailing null entry to indicate the end of array */
+#define MAX_TRIGGERS 3
+
+struct stm32_lptim_cfg {
+       const char * const (*triggers)[MAX_TRIGGERS];
+       unsigned int nb_triggers;
+};
+
+/* List Low-Power Timer triggers for H7, MP13, MP15 */
+static const char * const stm32_lptim_triggers[][MAX_TRIGGERS] = {
+       { LPTIM1_OUT,},
+       { LPTIM2_OUT,},
+       { LPTIM3_OUT,},
+};
+
+/* List Low-Power Timer triggers for STM32MP25 */
+static const char * const stm32mp25_lptim_triggers[][MAX_TRIGGERS] = {
+       { LPTIM1_CH1, LPTIM1_CH2, },
+       { LPTIM2_CH1, LPTIM2_CH2, },
+       { LPTIM3_CH1,},
+       { LPTIM4_CH1,},
+       { LPTIM5_OUT,},
+};
+
+static const struct stm32_lptim_cfg stm32mp15_lptim_cfg = {
+       .triggers = stm32_lptim_triggers,
+       .nb_triggers = ARRAY_SIZE(stm32_lptim_triggers),
+};
+
+static const struct stm32_lptim_cfg stm32mp25_lptim_cfg = {
+       .triggers = stm32mp25_lptim_triggers,
+       .nb_triggers = ARRAY_SIZE(stm32mp25_lptim_triggers),
 };
 
 struct stm32_lptim_trigger {
        struct device *dev;
-       const char *trg;
+       const char * const *triggers;
 };
 
 static int stm32_lptim_validate_device(struct iio_trigger *trig,
@@ -56,22 +83,33 @@ EXPORT_SYMBOL(is_stm32_lptim_trigger);
 
 static int stm32_lptim_setup_trig(struct stm32_lptim_trigger *priv)
 {
-       struct iio_trigger *trig;
+       const char * const *cur = priv->triggers;
+       int ret;
 
-       trig = devm_iio_trigger_alloc(priv->dev, "%s", priv->trg);
-       if  (!trig)
-               return -ENOMEM;
+       while (cur && *cur) {
+               struct iio_trigger *trig;
 
-       trig->dev.parent = priv->dev->parent;
-       trig->ops = &stm32_lptim_trigger_ops;
-       iio_trigger_set_drvdata(trig, priv);
+               trig = devm_iio_trigger_alloc(priv->dev, "%s", *cur);
+               if  (!trig)
+                       return -ENOMEM;
 
-       return devm_iio_trigger_register(priv->dev, trig);
+               trig->dev.parent = priv->dev->parent;
+               trig->ops = &stm32_lptim_trigger_ops;
+               iio_trigger_set_drvdata(trig, priv);
+
+               ret = devm_iio_trigger_register(priv->dev, trig);
+               if (ret)
+                       return ret;
+               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;
 
        priv = devm_kzalloc(&pdev->dev, sizeof(*priv), GFP_KERNEL);
@@ -81,17 +119,20 @@ 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];
 
        return stm32_lptim_setup_trig(priv);
 }
 
 static const struct of_device_id stm32_lptim_trig_of_match[] = {
-       { .compatible = "st,stm32-lptimer-trigger", },
+       { .compatible = "st,stm32-lptimer-trigger", .data = &stm32mp15_lptim_cfg },
+       { .compatible = "st,stm32mp25-lptimer-trigger", .data = &stm32mp25_lptim_cfg},
        {},
 };
 MODULE_DEVICE_TABLE(of, stm32_lptim_trig_of_match);
index a34dcf6..ce3cf0a 100644 (file)
 #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);