diff options
Diffstat (limited to 'drivers/iio/trigger/stm32-timer-trigger.c')
-rw-r--r-- | drivers/iio/trigger/stm32-timer-trigger.c | 55 |
1 files changed, 51 insertions, 4 deletions
diff --git a/drivers/iio/trigger/stm32-timer-trigger.c b/drivers/iio/trigger/stm32-timer-trigger.c index d22bc56dd9fc..33890f9ad11b 100644 --- a/drivers/iio/trigger/stm32-timer-trigger.c +++ b/drivers/iio/trigger/stm32-timer-trigger.c | |||
@@ -13,6 +13,7 @@ | |||
13 | #include <linux/mfd/stm32-timers.h> | 13 | #include <linux/mfd/stm32-timers.h> |
14 | #include <linux/module.h> | 14 | #include <linux/module.h> |
15 | #include <linux/platform_device.h> | 15 | #include <linux/platform_device.h> |
16 | #include <linux/of_device.h> | ||
16 | 17 | ||
17 | #define MAX_TRIGGERS 7 | 18 | #define MAX_TRIGGERS 7 |
18 | #define MAX_VALIDS 5 | 19 | #define MAX_VALIDS 5 |
@@ -31,6 +32,9 @@ static const void *triggers_table[][MAX_TRIGGERS] = { | |||
31 | { }, /* timer 10 */ | 32 | { }, /* timer 10 */ |
32 | { }, /* timer 11 */ | 33 | { }, /* timer 11 */ |
33 | { TIM12_TRGO, TIM12_CH1, TIM12_CH2,}, | 34 | { TIM12_TRGO, TIM12_CH1, TIM12_CH2,}, |
35 | { }, /* timer 13 */ | ||
36 | { }, /* timer 14 */ | ||
37 | { TIM15_TRGO,}, | ||
34 | }; | 38 | }; |
35 | 39 | ||
36 | /* List the triggers accepted by each timer */ | 40 | /* List the triggers accepted by each timer */ |
@@ -49,6 +53,24 @@ static const void *valids_table[][MAX_VALIDS] = { | |||
49 | { TIM4_TRGO, TIM5_TRGO,}, | 53 | { TIM4_TRGO, TIM5_TRGO,}, |
50 | }; | 54 | }; |
51 | 55 | ||
56 | static const void *stm32h7_valids_table[][MAX_VALIDS] = { | ||
57 | { TIM15_TRGO, TIM2_TRGO, TIM3_TRGO, TIM4_TRGO,}, | ||
58 | { TIM1_TRGO, TIM8_TRGO, TIM3_TRGO, TIM4_TRGO,}, | ||
59 | { TIM1_TRGO, TIM2_TRGO, TIM15_TRGO, TIM4_TRGO,}, | ||
60 | { TIM1_TRGO, TIM2_TRGO, TIM3_TRGO, TIM8_TRGO,}, | ||
61 | { TIM1_TRGO, TIM8_TRGO, TIM3_TRGO, TIM4_TRGO,}, | ||
62 | { }, /* timer 6 */ | ||
63 | { }, /* timer 7 */ | ||
64 | { TIM1_TRGO, TIM2_TRGO, TIM4_TRGO, TIM5_TRGO,}, | ||
65 | { }, /* timer 9 */ | ||
66 | { }, /* timer 10 */ | ||
67 | { }, /* timer 11 */ | ||
68 | { TIM4_TRGO, TIM5_TRGO,}, | ||
69 | { }, /* timer 13 */ | ||
70 | { }, /* timer 14 */ | ||
71 | { TIM1_TRGO, TIM3_TRGO,}, | ||
72 | }; | ||
73 | |||
52 | struct stm32_timer_trigger { | 74 | struct stm32_timer_trigger { |
53 | struct device *dev; | 75 | struct device *dev; |
54 | struct regmap *regmap; | 76 | struct regmap *regmap; |
@@ -59,6 +81,11 @@ struct stm32_timer_trigger { | |||
59 | bool has_trgo2; | 81 | bool has_trgo2; |
60 | }; | 82 | }; |
61 | 83 | ||
84 | struct stm32_timer_trigger_cfg { | ||
85 | const void *(*valids_table)[MAX_VALIDS]; | ||
86 | const unsigned int num_valids_table; | ||
87 | }; | ||
88 | |||
62 | static bool stm32_timer_is_trgo2_name(const char *name) | 89 | static bool stm32_timer_is_trgo2_name(const char *name) |
63 | { | 90 | { |
64 | return !!strstr(name, "trgo2"); | 91 | return !!strstr(name, "trgo2"); |
@@ -734,18 +761,22 @@ static int stm32_timer_trigger_probe(struct platform_device *pdev) | |||
734 | struct device *dev = &pdev->dev; | 761 | struct device *dev = &pdev->dev; |
735 | struct stm32_timer_trigger *priv; | 762 | struct stm32_timer_trigger *priv; |
736 | struct stm32_timers *ddata = dev_get_drvdata(pdev->dev.parent); | 763 | struct stm32_timers *ddata = dev_get_drvdata(pdev->dev.parent); |
764 | const struct stm32_timer_trigger_cfg *cfg; | ||
737 | unsigned int index; | 765 | unsigned int index; |
738 | int ret; | 766 | int ret; |
739 | 767 | ||
740 | if (of_property_read_u32(dev->of_node, "reg", &index)) | 768 | if (of_property_read_u32(dev->of_node, "reg", &index)) |
741 | return -EINVAL; | 769 | return -EINVAL; |
742 | 770 | ||
771 | cfg = (const struct stm32_timer_trigger_cfg *) | ||
772 | of_match_device(dev->driver->of_match_table, dev)->data; | ||
773 | |||
743 | if (index >= ARRAY_SIZE(triggers_table) || | 774 | if (index >= ARRAY_SIZE(triggers_table) || |
744 | index >= ARRAY_SIZE(valids_table)) | 775 | index >= cfg->num_valids_table) |
745 | return -EINVAL; | 776 | return -EINVAL; |
746 | 777 | ||
747 | /* Create an IIO device only if we have triggers to be validated */ | 778 | /* Create an IIO device only if we have triggers to be validated */ |
748 | if (*valids_table[index]) | 779 | if (*cfg->valids_table[index]) |
749 | priv = stm32_setup_counter_device(dev); | 780 | priv = stm32_setup_counter_device(dev); |
750 | else | 781 | else |
751 | priv = devm_kzalloc(dev, sizeof(*priv), GFP_KERNEL); | 782 | priv = devm_kzalloc(dev, sizeof(*priv), GFP_KERNEL); |
@@ -758,7 +789,7 @@ static int stm32_timer_trigger_probe(struct platform_device *pdev) | |||
758 | priv->clk = ddata->clk; | 789 | priv->clk = ddata->clk; |
759 | priv->max_arr = ddata->max_arr; | 790 | priv->max_arr = ddata->max_arr; |
760 | priv->triggers = triggers_table[index]; | 791 | priv->triggers = triggers_table[index]; |
761 | priv->valids = valids_table[index]; | 792 | priv->valids = cfg->valids_table[index]; |
762 | stm32_timer_detect_trgo2(priv); | 793 | stm32_timer_detect_trgo2(priv); |
763 | 794 | ||
764 | ret = stm32_setup_iio_triggers(priv); | 795 | ret = stm32_setup_iio_triggers(priv); |
@@ -770,8 +801,24 @@ static int stm32_timer_trigger_probe(struct platform_device *pdev) | |||
770 | return 0; | 801 | return 0; |
771 | } | 802 | } |
772 | 803 | ||
804 | static const struct stm32_timer_trigger_cfg stm32_timer_trg_cfg = { | ||
805 | .valids_table = valids_table, | ||
806 | .num_valids_table = ARRAY_SIZE(valids_table), | ||
807 | }; | ||
808 | |||
809 | static const struct stm32_timer_trigger_cfg stm32h7_timer_trg_cfg = { | ||
810 | .valids_table = stm32h7_valids_table, | ||
811 | .num_valids_table = ARRAY_SIZE(stm32h7_valids_table), | ||
812 | }; | ||
813 | |||
773 | static const struct of_device_id stm32_trig_of_match[] = { | 814 | static const struct of_device_id stm32_trig_of_match[] = { |
774 | { .compatible = "st,stm32-timer-trigger", }, | 815 | { |
816 | .compatible = "st,stm32-timer-trigger", | ||
817 | .data = (void *)&stm32_timer_trg_cfg, | ||
818 | }, { | ||
819 | .compatible = "st,stm32h7-timer-trigger", | ||
820 | .data = (void *)&stm32h7_timer_trg_cfg, | ||
821 | }, | ||
775 | { /* end node */ }, | 822 | { /* end node */ }, |
776 | }; | 823 | }; |
777 | MODULE_DEVICE_TABLE(of, stm32_trig_of_match); | 824 | MODULE_DEVICE_TABLE(of, stm32_trig_of_match); |