From 46cba77924e48f2f8ec8fb6a909dd1a24541d1f9 Mon Sep 17 00:00:00 2001 From: Cyril Fougeray Date: Tue, 10 Oct 2023 15:27:08 +0200 Subject: [PATCH] i2c: stm32: init priority per device instance allow redefinition of i2c device initialization priority per instance so that one bus can be initialized for a specific purpose before another --- drivers/i2c/i2c_ll_stm32.c | 19 ++++++++++++++++++- 1 file changed, 18 insertions(+), 1 deletion(-) diff --git a/drivers/i2c/i2c_ll_stm32.c b/drivers/i2c/i2c_ll_stm32.c index bbf255923772f2..05b918d7d7215c 100644 --- a/drivers/i2c/i2c_ll_stm32.c +++ b/drivers/i2c/i2c_ll_stm32.c @@ -543,6 +543,22 @@ static void i2c_stm32_irq_config_func_##index(const struct device *dev) \ #define USE_TIMINGS(index) #endif /* V2 */ +/* allow redefinition of init priority, per instance, + * at least for the 4 first instances + */ +#ifndef CONFIG_I2C_INIT_PRIO_INST_0 +#define CONFIG_I2C_INIT_PRIO_INST_0 CONFIG_I2C_INIT_PRIORITY +#endif +#ifndef CONFIG_I2C_INIT_PRIO_INST_1 +#define CONFIG_I2C_INIT_PRIO_INST_1 CONFIG_I2C_INIT_PRIORITY +#endif +#ifndef CONFIG_I2C_INIT_PRIO_INST_2 +#define CONFIG_I2C_INIT_PRIO_INST_2 CONFIG_I2C_INIT_PRIORITY +#endif +#ifndef CONFIG_I2C_INIT_PRIO_INST_3 +#define CONFIG_I2C_INIT_PRIO_INST_3 CONFIG_I2C_INIT_PRIORITY +#endif + #define STM32_I2C_INIT(index) \ STM32_I2C_IRQ_HANDLER_DECL(index); \ \ @@ -573,7 +589,8 @@ I2C_DEVICE_DT_INST_DEFINE(index, i2c_stm32_init, \ PM_DEVICE_DT_INST_GET(index), \ &i2c_stm32_dev_data_##index, \ &i2c_stm32_cfg_##index, \ - POST_KERNEL, CONFIG_I2C_INIT_PRIORITY, \ + POST_KERNEL, \ + _CONCAT(CONFIG_I2C_INIT_PRIO_INST_, index), \ &api_funcs); \ \ STM32_I2C_IRQ_HANDLER(index)