drivers: counter: stm32: timer: fix counter for stm32 advanced timers

Counter driver was not functional with STM32 advanced timers (like
TIMER1/8) due to them having more than one interrupt line.
This commit defines the proper interrupts for the advanced timers so that
they can be used as counters.

Signed-off-by: Guillaume Gautier <guillaume.gautier-ext@st.com>
diff --git a/drivers/counter/counter_ll_stm32_timer.c b/drivers/counter/counter_ll_stm32_timer.c
index 72f7f26..3eb6555 100644
--- a/drivers/counter/counter_ll_stm32_timer.c
+++ b/drivers/counter/counter_ll_stm32_timer.c
@@ -524,7 +524,7 @@
 		}								\
 	} while (0)
 
-void counter_stm32_irq_handler(const struct device *dev)
+static void counter_stm32_irq_handler_cc(const struct device *dev)
 {
 	const struct counter_stm32_config *config = dev->config;
 	struct counter_stm32_data *data = dev->data;
@@ -543,7 +543,16 @@
 		__fallthrough;
 	case 1U:
 		TIM_IRQ_HANDLE_CC(timer, 1);
+		__fallthrough;
+	default:
+		break;
 	}
+}
+
+static void counter_stm32_irq_handler_up(const struct device *dev)
+{
+	const struct counter_stm32_config *config = dev->config;
+	TIM_TypeDef *timer = config->timer;
 
 	/* TIM Update event */
 	if (LL_TIM_IsActiveFlag_UPDATE(timer) && LL_TIM_IsEnabledIT_UPDATE(timer)) {
@@ -552,6 +561,17 @@
 	}
 }
 
+static void counter_stm32_irq_handler_brk_up_trg_com(const struct device *dev)
+{
+	counter_stm32_irq_handler_up(dev);
+}
+
+static void counter_stm32_irq_handler_global(const struct device *dev)
+{
+	counter_stm32_irq_handler_cc(dev);
+	counter_stm32_irq_handler_brk_up_trg_com(dev);
+}
+
 #define TIMER(idx)              DT_INST_PARENT(idx)
 
 /** TIMx instance from DT */
@@ -561,7 +581,7 @@
 {										\
 	IRQ_CONNECT(DT_IRQ_BY_NAME(TIMER(index), name, irq),			\
 		    DT_IRQ_BY_NAME(TIMER(index), name, priority),		\
-		    counter_stm32_irq_handler, DEVICE_DT_INST_GET(index), 0);	\
+		    counter_stm32_irq_handler_##name, DEVICE_DT_INST_GET(index), 0);	\
 	irq_enable(DT_IRQ_BY_NAME(TIMER(index), name, irq));			\
 }
 
@@ -576,6 +596,10 @@
 										  \
 	static void counter_##idx##_stm32_irq_config(const struct device *dev)	  \
 	{									  \
+		IF_ENABLED(DT_IRQ_HAS_NAME(TIMER(idx), up),			  \
+			(IRQ_CONNECT_AND_ENABLE_BY_NAME(idx, up)))		  \
+		IF_ENABLED(DT_IRQ_HAS_NAME(TIMER(idx), brk_up_trg_com),		  \
+			(IRQ_CONNECT_AND_ENABLE_BY_NAME(idx, brk_up_trg_com)))	  \
 		COND_CODE_1(DT_IRQ_HAS_NAME(TIMER(idx), cc),			  \
 			(IRQ_CONNECT_AND_ENABLE_BY_NAME(idx, cc)),		  \
 		(COND_CODE_1(DT_IRQ_HAS_NAME(TIMER(idx), global),		  \
@@ -600,7 +624,9 @@
 		.pclken = pclken_##idx,						  \
 		.pclk_len = DT_NUM_CLOCKS(TIMER(idx)),				  \
 		.irq_config_func = counter_##idx##_stm32_irq_config,		  \
-		.irqn = DT_IRQN(TIMER(idx)),					  \
+		.irqn = COND_CODE_1(DT_IRQ_HAS_NAME(TIMER(idx), cc),		  \
+				    (DT_IRQ_BY_NAME(TIMER(idx), cc, irq)),	  \
+				    (DT_IRQ_BY_NAME(TIMER(idx), global, irq))),	  \
 		.reset = RESET_DT_SPEC_GET(TIMER(idx)),				  \
 	};									  \
 										  \