x86/speculation/mds: Fix documentation typo
[linux/fpc-iii.git] / drivers / iio / trigger / stm32-lptimer-trigger.c
blob241eae6a4306abb013c67f274f36a618dd238705
1 /*
2 * STM32 Low-Power Timer Trigger driver
4 * Copyright (C) STMicroelectronics 2017
6 * Author: Fabrice Gasnier <fabrice.gasnier@st.com>.
8 * License terms: GNU General Public License (GPL), version 2
10 * Inspired by Benjamin Gaignard's stm32-timer-trigger driver
13 #include <linux/iio/timer/stm32-lptim-trigger.h>
14 #include <linux/mfd/stm32-lptimer.h>
15 #include <linux/module.h>
16 #include <linux/platform_device.h>
18 /* List Low-Power Timer triggers */
19 static const char * const stm32_lptim_triggers[] = {
20 LPTIM1_OUT,
21 LPTIM2_OUT,
22 LPTIM3_OUT,
25 struct stm32_lptim_trigger {
26 struct device *dev;
27 const char *trg;
30 static int stm32_lptim_validate_device(struct iio_trigger *trig,
31 struct iio_dev *indio_dev)
33 if (indio_dev->modes & INDIO_HARDWARE_TRIGGERED)
34 return 0;
36 return -EINVAL;
39 static const struct iio_trigger_ops stm32_lptim_trigger_ops = {
40 .owner = THIS_MODULE,
41 .validate_device = stm32_lptim_validate_device,
44 /**
45 * is_stm32_lptim_trigger
46 * @trig: trigger to be checked
48 * return true if the trigger is a valid STM32 IIO Low-Power Timer Trigger
49 * either return false
51 bool is_stm32_lptim_trigger(struct iio_trigger *trig)
53 return (trig->ops == &stm32_lptim_trigger_ops);
55 EXPORT_SYMBOL(is_stm32_lptim_trigger);
57 static int stm32_lptim_setup_trig(struct stm32_lptim_trigger *priv)
59 struct iio_trigger *trig;
61 trig = devm_iio_trigger_alloc(priv->dev, "%s", priv->trg);
62 if (!trig)
63 return -ENOMEM;
65 trig->dev.parent = priv->dev->parent;
66 trig->ops = &stm32_lptim_trigger_ops;
67 iio_trigger_set_drvdata(trig, priv);
69 return devm_iio_trigger_register(priv->dev, trig);
72 static int stm32_lptim_trigger_probe(struct platform_device *pdev)
74 struct stm32_lptim_trigger *priv;
75 u32 index;
76 int ret;
78 priv = devm_kzalloc(&pdev->dev, sizeof(*priv), GFP_KERNEL);
79 if (!priv)
80 return -ENOMEM;
82 if (of_property_read_u32(pdev->dev.of_node, "reg", &index))
83 return -EINVAL;
85 if (index >= ARRAY_SIZE(stm32_lptim_triggers))
86 return -EINVAL;
88 priv->dev = &pdev->dev;
89 priv->trg = stm32_lptim_triggers[index];
91 ret = stm32_lptim_setup_trig(priv);
92 if (ret)
93 return ret;
95 platform_set_drvdata(pdev, priv);
97 return 0;
100 static const struct of_device_id stm32_lptim_trig_of_match[] = {
101 { .compatible = "st,stm32-lptimer-trigger", },
104 MODULE_DEVICE_TABLE(of, stm32_lptim_trig_of_match);
106 static struct platform_driver stm32_lptim_trigger_driver = {
107 .probe = stm32_lptim_trigger_probe,
108 .driver = {
109 .name = "stm32-lptimer-trigger",
110 .of_match_table = stm32_lptim_trig_of_match,
113 module_platform_driver(stm32_lptim_trigger_driver);
115 MODULE_AUTHOR("Fabrice Gasnier <fabrice.gasnier@st.com>");
116 MODULE_ALIAS("platform:stm32-lptimer-trigger");
117 MODULE_DESCRIPTION("STMicroelectronics STM32 LPTIM trigger driver");
118 MODULE_LICENSE("GPL v2");