1313#include <linux/mfd/stm32-timers.h>
1414#include <linux/module.h>
1515#include <linux/platform_device.h>
16+ #include <linux/of_device.h>
1617
1718#define MAX_TRIGGERS 7
1819#define MAX_VALIDS 5
@@ -31,6 +32,9 @@ static const void *triggers_table[][MAX_TRIGGERS] = {
3132 { }, /* timer 10 */
3233 { }, /* timer 11 */
3334 { TIM12_TRGO , TIM12_CH1 , TIM12_CH2 ,},
35+ { }, /* timer 13 */
36+ { }, /* timer 14 */
37+ { TIM15_TRGO ,},
3438};
3539
3640/* List the triggers accepted by each timer */
@@ -49,6 +53,24 @@ static const void *valids_table[][MAX_VALIDS] = {
4953 { TIM4_TRGO , TIM5_TRGO ,},
5054};
5155
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+
5274struct stm32_timer_trigger {
5375 struct device * dev ;
5476 struct regmap * regmap ;
@@ -59,6 +81,11 @@ struct stm32_timer_trigger {
5981 bool has_trgo2 ;
6082};
6183
84+ struct stm32_timer_trigger_cfg {
85+ const void * (* valids_table )[MAX_VALIDS ];
86+ const unsigned int num_valids_table ;
87+ };
88+
6289static bool stm32_timer_is_trgo2_name (const char * name )
6390{
6491 return !!strstr (name , "trgo2" );
@@ -734,18 +761,22 @@ static int stm32_timer_trigger_probe(struct platform_device *pdev)
734761 struct device * dev = & pdev -> dev ;
735762 struct stm32_timer_trigger * priv ;
736763 struct stm32_timers * ddata = dev_get_drvdata (pdev -> dev .parent );
764+ const struct stm32_timer_trigger_cfg * cfg ;
737765 unsigned int index ;
738766 int ret ;
739767
740768 if (of_property_read_u32 (dev -> of_node , "reg" , & index ))
741769 return - EINVAL ;
742770
771+ cfg = (const struct stm32_timer_trigger_cfg * )
772+ of_match_device (dev -> driver -> of_match_table , dev )-> data ;
773+
743774 if (index >= ARRAY_SIZE (triggers_table ) ||
744- index >= ARRAY_SIZE ( valids_table ) )
775+ index >= cfg -> num_valids_table )
745776 return - EINVAL ;
746777
747778 /* Create an IIO device only if we have triggers to be validated */
748- if (* valids_table [index ])
779+ if (* cfg -> valids_table [index ])
749780 priv = stm32_setup_counter_device (dev );
750781 else
751782 priv = devm_kzalloc (dev , sizeof (* priv ), GFP_KERNEL );
@@ -758,7 +789,7 @@ static int stm32_timer_trigger_probe(struct platform_device *pdev)
758789 priv -> clk = ddata -> clk ;
759790 priv -> max_arr = ddata -> max_arr ;
760791 priv -> triggers = triggers_table [index ];
761- priv -> valids = valids_table [index ];
792+ priv -> valids = cfg -> valids_table [index ];
762793 stm32_timer_detect_trgo2 (priv );
763794
764795 ret = stm32_setup_iio_triggers (priv );
@@ -770,8 +801,24 @@ static int stm32_timer_trigger_probe(struct platform_device *pdev)
770801 return 0 ;
771802}
772803
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+
773814static 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+ },
775822 { /* end node */ },
776823};
777824MODULE_DEVICE_TABLE (of , stm32_trig_of_match );
0 commit comments