1 // SPDX-License-Identifier: GPL-2.0
3 * STM32 Low-Power Timer Trigger driver
5 * Copyright (C) STMicroelectronics 2017
7 * Author: Fabrice Gasnier <fabrice.gasnier@st.com>.
9 * Inspired by Benjamin Gaignard's stm32-timer-trigger driver
12 #include <linux/iio/timer/stm32-lptim-trigger.h>
13 #include <linux/mfd/stm32-lptimer.h>
14 #include <linux/module.h>
15 #include <linux/platform_device.h>
17 /* List Low-Power Timer triggers */
18 static const char * const stm32_lptim_triggers
[] = {
24 struct stm32_lptim_trigger
{
29 static int stm32_lptim_validate_device(struct iio_trigger
*trig
,
30 struct iio_dev
*indio_dev
)
32 if (indio_dev
->modes
& INDIO_HARDWARE_TRIGGERED
)
38 static const struct iio_trigger_ops stm32_lptim_trigger_ops
= {
39 .validate_device
= stm32_lptim_validate_device
,
43 * is_stm32_lptim_trigger
44 * @trig: trigger to be checked
46 * return true if the trigger is a valid STM32 IIO Low-Power Timer Trigger
49 bool is_stm32_lptim_trigger(struct iio_trigger
*trig
)
51 return (trig
->ops
== &stm32_lptim_trigger_ops
);
53 EXPORT_SYMBOL(is_stm32_lptim_trigger
);
55 static int stm32_lptim_setup_trig(struct stm32_lptim_trigger
*priv
)
57 struct iio_trigger
*trig
;
59 trig
= devm_iio_trigger_alloc(priv
->dev
, "%s", priv
->trg
);
63 trig
->dev
.parent
= priv
->dev
->parent
;
64 trig
->ops
= &stm32_lptim_trigger_ops
;
65 iio_trigger_set_drvdata(trig
, priv
);
67 return devm_iio_trigger_register(priv
->dev
, trig
);
70 static int stm32_lptim_trigger_probe(struct platform_device
*pdev
)
72 struct stm32_lptim_trigger
*priv
;
76 priv
= devm_kzalloc(&pdev
->dev
, sizeof(*priv
), GFP_KERNEL
);
80 if (of_property_read_u32(pdev
->dev
.of_node
, "reg", &index
))
83 if (index
>= ARRAY_SIZE(stm32_lptim_triggers
))
86 priv
->dev
= &pdev
->dev
;
87 priv
->trg
= stm32_lptim_triggers
[index
];
89 ret
= stm32_lptim_setup_trig(priv
);
93 platform_set_drvdata(pdev
, priv
);
98 static const struct of_device_id stm32_lptim_trig_of_match
[] = {
99 { .compatible
= "st,stm32-lptimer-trigger", },
102 MODULE_DEVICE_TABLE(of
, stm32_lptim_trig_of_match
);
104 static struct platform_driver stm32_lptim_trigger_driver
= {
105 .probe
= stm32_lptim_trigger_probe
,
107 .name
= "stm32-lptimer-trigger",
108 .of_match_table
= stm32_lptim_trig_of_match
,
111 module_platform_driver(stm32_lptim_trigger_driver
);
113 MODULE_AUTHOR("Fabrice Gasnier <fabrice.gasnier@st.com>");
114 MODULE_ALIAS("platform:stm32-lptimer-trigger");
115 MODULE_DESCRIPTION("STMicroelectronics STM32 LPTIM trigger driver");
116 MODULE_LICENSE("GPL v2");