Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

iio: trigger: stm32-timer: add support for STM32H7

Add support for STM32H7 timer triggers:
- Add new valids_table
- Introduce compatible, with configuration data
- Extend up to 15 timers, available on STM32H7

Signed-off-by: Fabrice Gasnier <fabrice.gasnier@st.com>
Signed-off-by: Jonathan Cameron <Jonathan.Cameron@huawei.com>

authored by

Fabrice Gasnier and committed by
Jonathan Cameron
45fff14b a6bb1bb8

+53 -4
+51 -4
drivers/iio/trigger/stm32-timer-trigger.c
··· 13 13 #include <linux/mfd/stm32-timers.h> 14 14 #include <linux/module.h> 15 15 #include <linux/platform_device.h> 16 + #include <linux/of_device.h> 16 17 17 18 #define MAX_TRIGGERS 7 18 19 #define MAX_VALIDS 5 ··· 32 31 { }, /* timer 10 */ 33 32 { }, /* timer 11 */ 34 33 { TIM12_TRGO, TIM12_CH1, TIM12_CH2,}, 34 + { }, /* timer 13 */ 35 + { }, /* timer 14 */ 36 + { TIM15_TRGO,}, 35 37 }; 36 38 37 39 /* List the triggers accepted by each timer */ ··· 53 49 { TIM4_TRGO, TIM5_TRGO,}, 54 50 }; 55 51 52 + static const void *stm32h7_valids_table[][MAX_VALIDS] = { 53 + { TIM15_TRGO, TIM2_TRGO, TIM3_TRGO, TIM4_TRGO,}, 54 + { TIM1_TRGO, TIM8_TRGO, TIM3_TRGO, TIM4_TRGO,}, 55 + { TIM1_TRGO, TIM2_TRGO, TIM15_TRGO, TIM4_TRGO,}, 56 + { TIM1_TRGO, TIM2_TRGO, TIM3_TRGO, TIM8_TRGO,}, 57 + { TIM1_TRGO, TIM8_TRGO, TIM3_TRGO, TIM4_TRGO,}, 58 + { }, /* timer 6 */ 59 + { }, /* timer 7 */ 60 + { TIM1_TRGO, TIM2_TRGO, TIM4_TRGO, TIM5_TRGO,}, 61 + { }, /* timer 9 */ 62 + { }, /* timer 10 */ 63 + { }, /* timer 11 */ 64 + { TIM4_TRGO, TIM5_TRGO,}, 65 + { }, /* timer 13 */ 66 + { }, /* timer 14 */ 67 + { TIM1_TRGO, TIM3_TRGO,}, 68 + }; 69 + 56 70 struct stm32_timer_trigger { 57 71 struct device *dev; 58 72 struct regmap *regmap; ··· 79 57 const void *triggers; 80 58 const void *valids; 81 59 bool has_trgo2; 60 + }; 61 + 62 + struct stm32_timer_trigger_cfg { 63 + const void *(*valids_table)[MAX_VALIDS]; 64 + const unsigned int num_valids_table; 82 65 }; 83 66 84 67 static bool stm32_timer_is_trgo2_name(const char *name) ··· 761 734 struct device *dev = &pdev->dev; 762 735 struct stm32_timer_trigger *priv; 763 736 struct stm32_timers *ddata = dev_get_drvdata(pdev->dev.parent); 737 + const struct stm32_timer_trigger_cfg *cfg; 764 738 unsigned int index; 765 739 int ret; 766 740 767 741 if (of_property_read_u32(dev->of_node, "reg", &index)) 768 742 return -EINVAL; 769 743 744 + cfg = (const struct stm32_timer_trigger_cfg *) 745 + of_match_device(dev->driver->of_match_table, dev)->data; 746 + 770 747 if (index >= ARRAY_SIZE(triggers_table) || 771 - index >= ARRAY_SIZE(valids_table)) 748 + index >= cfg->num_valids_table) 772 749 return -EINVAL; 773 750 774 751 /* Create an IIO device only if we have triggers to be validated */ 775 - if (*valids_table[index]) 752 + if (*cfg->valids_table[index]) 776 753 priv = stm32_setup_counter_device(dev); 777 754 else 778 755 priv = devm_kzalloc(dev, sizeof(*priv), GFP_KERNEL); ··· 789 758 priv->clk = ddata->clk; 790 759 priv->max_arr = ddata->max_arr; 791 760 priv->triggers = triggers_table[index]; 792 - priv->valids = valids_table[index]; 761 + priv->valids = cfg->valids_table[index]; 793 762 stm32_timer_detect_trgo2(priv); 794 763 795 764 ret = stm32_setup_iio_triggers(priv); ··· 801 770 return 0; 802 771 } 803 772 773 + static const struct stm32_timer_trigger_cfg stm32_timer_trg_cfg = { 774 + .valids_table = valids_table, 775 + .num_valids_table = ARRAY_SIZE(valids_table), 776 + }; 777 + 778 + static const struct stm32_timer_trigger_cfg stm32h7_timer_trg_cfg = { 779 + .valids_table = stm32h7_valids_table, 780 + .num_valids_table = ARRAY_SIZE(stm32h7_valids_table), 781 + }; 782 + 804 783 static const struct of_device_id stm32_trig_of_match[] = { 805 - { .compatible = "st,stm32-timer-trigger", }, 784 + { 785 + .compatible = "st,stm32-timer-trigger", 786 + .data = (void *)&stm32_timer_trg_cfg, 787 + }, { 788 + .compatible = "st,stm32h7-timer-trigger", 789 + .data = (void *)&stm32h7_timer_trg_cfg, 790 + }, 806 791 { /* end node */ }, 807 792 }; 808 793 MODULE_DEVICE_TABLE(of, stm32_trig_of_match);
+2
include/linux/iio/timer/stm32-timer-trigger.h
··· 59 59 #define TIM12_CH1 "tim12_ch1" 60 60 #define TIM12_CH2 "tim12_ch2" 61 61 62 + #define TIM15_TRGO "tim15_trgo" 63 + 62 64 bool is_stm32_timer_trigger(struct iio_trigger *trig); 63 65 64 66 #endif