2020#include <errno.h>
2121#include <zephyr/drivers/i2c.h>
2222#include <zephyr/drivers/pinctrl.h>
23- #include "i2c_ll_stm32.h"
23+ #include <zephyr/irq.h>
2424
2525#ifdef CONFIG_I2C_STM32_BUS_RECOVERY
2626#include "i2c_bitbang.h"
2727#endif /* CONFIG_I2C_STM32_BUS_RECOVERY */
2828
2929#define LOG_LEVEL CONFIG_I2C_LOG_LEVEL
3030#include <zephyr/logging/log.h>
31- #include <zephyr/irq.h>
3231LOG_MODULE_REGISTER (i2c_ll_stm32 );
3332
33+ #include "i2c_ll_stm32.h"
3434#include "i2c-priv.h"
3535
3636#if DT_HAS_COMPAT_STATUS_OKAY (st_stm32_i2c_v2 )
@@ -42,9 +42,9 @@ LOG_MODULE_REGISTER(i2c_ll_stm32);
4242/* This symbol takes the value 1 if one of the device instances */
4343/* is configured in dts with a domain clock */
4444#if STM32_DT_INST_DEV_DOMAIN_CLOCK_SUPPORT
45- #define STM32_I2C_DOMAIN_CLOCK_SUPPORT 1
45+ #define I2C_STM32_DOMAIN_CLOCK_SUPPORT 1
4646#else
47- #define STM32_I2C_DOMAIN_CLOCK_SUPPORT 0
47+ #define I2C_STM32_DOMAIN_CLOCK_SUPPORT 0
4848#endif
4949
5050int i2c_stm32_get_config (const struct device * dev , uint32_t * config )
@@ -90,7 +90,7 @@ int i2c_stm32_runtime_configure(const struct device *dev, uint32_t config)
9090 uint32_t i2c_clock = 0U ;
9191 int ret ;
9292
93- if (IS_ENABLED (STM32_I2C_DOMAIN_CLOCK_SUPPORT ) && (cfg -> pclk_len > 1 )) {
93+ if (IS_ENABLED (I2C_STM32_DOMAIN_CLOCK_SUPPORT ) && (cfg -> pclk_len > 1 )) {
9494 if (clock_control_get_rate (clk , (clock_control_subsys_t )& cfg -> pclken [1 ],
9595 & i2c_clock ) < 0 ) {
9696 LOG_ERR ("Failed call clock_control_get_rate(pclken[1])" );
@@ -120,7 +120,7 @@ int i2c_stm32_runtime_configure(const struct device *dev, uint32_t config)
120120#if defined(I2C_CR1_SMBUS ) || defined(I2C_CR1_SMBDEN ) || defined(I2C_CR1_SMBHEN )
121121 i2c_stm32_set_smbus_mode (dev , data -> mode );
122122#endif
123- ret = stm32_i2c_configure_timing (dev , i2c_clock );
123+ ret = i2c_stm32_configure_timing (dev , i2c_clock );
124124
125125 if (data -> smbalert_active ) {
126126 LL_I2C_Enable (i2c );
@@ -210,7 +210,7 @@ static int i2c_stm32_transfer(const struct device *dev, struct i2c_msg *msg,
210210 next = current + 1 ;
211211 next_msg_flags = & (next -> flags );
212212 }
213- ret = stm32_i2c_transaction (dev , * current , next_msg_flags , slave );
213+ ret = i2c_stm32_transaction (dev , * current , next_msg_flags , slave );
214214 if (ret < 0 ) {
215215 break ;
216216 }
@@ -411,7 +411,7 @@ static int i2c_stm32_init(const struct device *dev)
411411
412412 i2c_stm32_activate (dev );
413413
414- if (IS_ENABLED (STM32_I2C_DOMAIN_CLOCK_SUPPORT ) && (cfg -> pclk_len > 1 )) {
414+ if (IS_ENABLED (I2C_STM32_DOMAIN_CLOCK_SUPPORT ) && (cfg -> pclk_len > 1 )) {
415415 /* Enable I2C clock source */
416416 ret = clock_control_configure (clk ,
417417 (clock_control_subsys_t ) & cfg -> pclken [1 ],
@@ -543,60 +543,60 @@ void i2c_stm32_smbalert_disable(const struct device *dev)
543543#ifdef CONFIG_I2C_STM32_INTERRUPT
544544
545545#ifdef CONFIG_I2C_STM32_COMBINED_INTERRUPT
546- #define STM32_I2C_IRQ_CONNECT_AND_ENABLE (index ) \
546+ #define I2C_STM32_IRQ_CONNECT_AND_ENABLE (index ) \
547547 do { \
548548 IRQ_CONNECT(DT_INST_IRQN(index), \
549549 DT_INST_IRQ(index, priority), \
550- stm32_i2c_combined_isr , \
550+ i2c_stm32_combined_isr , \
551551 DEVICE_DT_INST_GET(index), 0); \
552552 irq_enable(DT_INST_IRQN(index)); \
553553 } while (false)
554554#else
555- #define STM32_I2C_IRQ_CONNECT_AND_ENABLE (index ) \
555+ #define I2C_STM32_IRQ_CONNECT_AND_ENABLE (index ) \
556556 do { \
557557 IRQ_CONNECT(DT_INST_IRQ_BY_NAME(index, event, irq), \
558558 DT_INST_IRQ_BY_NAME(index, event, priority),\
559- stm32_i2c_event_isr , \
559+ i2c_stm32_event_isr , \
560560 DEVICE_DT_INST_GET(index), 0); \
561561 irq_enable(DT_INST_IRQ_BY_NAME(index, event, irq)); \
562562 \
563563 IRQ_CONNECT(DT_INST_IRQ_BY_NAME(index, error, irq), \
564564 DT_INST_IRQ_BY_NAME(index, error, priority),\
565- stm32_i2c_error_isr , \
565+ i2c_stm32_error_isr , \
566566 DEVICE_DT_INST_GET(index), 0); \
567567 irq_enable(DT_INST_IRQ_BY_NAME(index, error, irq)); \
568568 } while (false)
569569#endif /* CONFIG_I2C_STM32_COMBINED_INTERRUPT */
570570
571- #define STM32_I2C_IRQ_HANDLER_DECL (index ) \
571+ #define I2C_STM32_IRQ_HANDLER_DECL (index ) \
572572static void i2c_stm32_irq_config_func_##index(const struct device *dev)
573- #define STM32_I2C_IRQ_HANDLER_FUNCTION (index ) \
573+ #define I2C_STM32_IRQ_HANDLER_FUNCTION (index ) \
574574 .irq_config_func = i2c_stm32_irq_config_func_##index,
575- #define STM32_I2C_IRQ_HANDLER (index ) \
575+ #define I2C_STM32_IRQ_HANDLER (index ) \
576576static void i2c_stm32_irq_config_func_##index(const struct device *dev) \
577577{ \
578- STM32_I2C_IRQ_CONNECT_AND_ENABLE (index); \
578+ I2C_STM32_IRQ_CONNECT_AND_ENABLE (index); \
579579}
580580#else
581581
582- #define STM32_I2C_IRQ_HANDLER_DECL (index )
583- #define STM32_I2C_IRQ_HANDLER_FUNCTION (index )
584- #define STM32_I2C_IRQ_HANDLER (index )
582+ #define I2C_STM32_IRQ_HANDLER_DECL (index )
583+ #define I2C_STM32_IRQ_HANDLER_FUNCTION (index )
584+ #define I2C_STM32_IRQ_HANDLER (index )
585585
586586#endif /* CONFIG_I2C_STM32_INTERRUPT */
587587
588588#ifdef CONFIG_I2C_STM32_V2_DMA
589589
590- #define I2C_DMA_INIT (index , dir ) \
591- .dir##_dma = { \
592- .dev_dma = COND_CODE_1(DT_INST_DMAS_HAS_NAME(index, dir),\
593- (DEVICE_DT_GET(STM32_DMA_CTLR(index, dir))), (NULL)),\
594- .dma_channel = COND_CODE_1(DT_INST_DMAS_HAS_NAME(index, dir),\
595- (DT_INST_DMAS_CELL_BY_NAME(index, dir, channel)), (-1)),\
590+ #define I2C_DMA_INIT (index , dir ) \
591+ .dir##_dma = { \
592+ .dev_dma = COND_CODE_1(DT_INST_DMAS_HAS_NAME(index, dir), \
593+ (DEVICE_DT_GET(STM32_DMA_CTLR(index, dir))), (NULL)), \
594+ .dma_channel = COND_CODE_1(DT_INST_DMAS_HAS_NAME(index, dir), \
595+ (DT_INST_DMAS_CELL_BY_NAME(index, dir, channel)), (-1)), \
596596 },
597597
598598void i2c_stm32_dma_tx_cb (const struct device * dma_dev , void * user_data ,
599- uint32_t channel , int status )
599+ uint32_t channel , int status )
600600{
601601 ARG_UNUSED (dma_dev );
602602 ARG_UNUSED (user_data );
@@ -609,7 +609,7 @@ void i2c_stm32_dma_tx_cb(const struct device *dma_dev, void *user_data,
609609}
610610
611611void i2c_stm32_dma_rx_cb (const struct device * dma_dev , void * user_data ,
612- uint32_t channel , int status )
612+ uint32_t channel , int status )
613613{
614614 ARG_UNUSED (dma_dev );
615615 ARG_UNUSED (user_data );
@@ -621,23 +621,23 @@ void i2c_stm32_dma_rx_cb(const struct device *dma_dev, void *user_data,
621621 }
622622}
623623
624- #define I2C_DMA_DATA_INIT (index , dir , src , dest ) \
625- .dma_##dir##_cfg = { \
626- .dma_slot = STM32_DMA_SLOT(index, dir, slot), \
627- .channel_direction = STM32_DMA_CONFIG_DIRECTION( \
628- STM32_DMA_CHANNEL_CONFIG(index, dir)),\
629- .cyclic = STM32_DMA_CONFIG_CYCLIC( \
630- STM32_DMA_CHANNEL_CONFIG(index, dir)), \
631- .channel_priority = STM32_DMA_CONFIG_PRIORITY( \
632- STM32_DMA_CHANNEL_CONFIG(index, dir)), \
633- .source_data_size = STM32_DMA_CONFIG_##src##_DATA_SIZE( \
634- STM32_DMA_CHANNEL_CONFIG(index, dir)),\
635- .dest_data_size = STM32_DMA_CONFIG_##dest##_DATA_SIZE( \
636- STM32_DMA_CHANNEL_CONFIG(index, dir)), \
637- .source_burst_length = 1, \
638- .dest_burst_length = 1, \
639- .dma_callback = i2c_stm32_dma_##dir##_cb, \
640- }, \
624+ #define I2C_DMA_DATA_INIT (index , dir , src , dest ) \
625+ .dma_##dir##_cfg = { \
626+ .dma_slot = STM32_DMA_SLOT(index, dir, slot), \
627+ .channel_direction = STM32_DMA_CONFIG_DIRECTION( \
628+ STM32_DMA_CHANNEL_CONFIG(index, dir)), \
629+ .cyclic = STM32_DMA_CONFIG_CYCLIC( \
630+ STM32_DMA_CHANNEL_CONFIG(index, dir)), \
631+ .channel_priority = STM32_DMA_CONFIG_PRIORITY( \
632+ STM32_DMA_CHANNEL_CONFIG(index, dir)), \
633+ .source_data_size = STM32_DMA_CONFIG_##src##_DATA_SIZE( \
634+ STM32_DMA_CHANNEL_CONFIG(index, dir)), \
635+ .dest_data_size = STM32_DMA_CONFIG_##dest##_DATA_SIZE( \
636+ STM32_DMA_CHANNEL_CONFIG(index, dir)), \
637+ .source_burst_length = 1, \
638+ .dest_burst_length = 1, \
639+ .dma_callback = i2c_stm32_dma_##dir##_cb, \
640+ }, \
641641
642642#else
643643
@@ -646,49 +646,49 @@ void i2c_stm32_dma_rx_cb(const struct device *dma_dev, void *user_data,
646646
647647#endif /* CONFIG_I2C_STM32_V2_DMA */
648648
649- #define STM32_I2C_INIT (index ) \
650- STM32_I2C_IRQ_HANDLER_DECL (index); \
651- \
652- IF_ENABLED(DT_HAS_COMPAT_STATUS_OKAY(st_stm32_i2c_v2), \
653- (static const uint32_t i2c_timings_##index[] = \
654- DT_INST_PROP_OR(index, timings, {});)) \
655- \
656- PINCTRL_DT_INST_DEFINE(index); \
657- \
658- static const struct stm32_pclken pclken_##index[] = \
659- STM32_DT_INST_CLOCKS(index); \
660- \
661- static const struct i2c_stm32_config i2c_stm32_cfg_##index = { \
662- .i2c = (I2C_TypeDef *)DT_INST_REG_ADDR(index), \
663- .pclken = pclken_##index, \
664- .pclk_len = DT_INST_NUM_CLOCKS(index), \
665- STM32_I2C_IRQ_HANDLER_FUNCTION (index) \
666- .bitrate = DT_INST_PROP(index, clock_frequency), \
667- .pcfg = PINCTRL_DT_INST_DEV_CONFIG_GET(index), \
668- IF_ENABLED(CONFIG_I2C_STM32_BUS_RECOVERY, \
669- (.scl = GPIO_DT_SPEC_INST_GET_OR(index, scl_gpios, {0}),\
670- .sda = GPIO_DT_SPEC_INST_GET_OR(index, sda_gpios, {0}),))\
671- IF_ENABLED(DT_HAS_COMPAT_STATUS_OKAY(st_stm32_i2c_v2), \
672- (.timings = (const struct i2c_config_timing *) i2c_timings_##index,\
673- .n_timings = ARRAY_SIZE(i2c_timings_##index),)) \
674- I2C_DMA_INIT(index, tx) \
675- I2C_DMA_INIT(index, rx) \
676- }; \
677- \
678- static struct i2c_stm32_data i2c_stm32_dev_data_##index = { \
679- I2C_DMA_DATA_INIT(index, tx, MEMORY, PERIPHERAL) \
680- I2C_DMA_DATA_INIT(index, rx, PERIPHERAL, MEMORY) \
681- }; \
682- \
683- PM_DEVICE_DT_INST_DEFINE(index, i2c_stm32_pm_action); \
684- \
685- I2C_DEVICE_DT_INST_DEFINE(index, i2c_stm32_init, \
686- PM_DEVICE_DT_INST_GET(index), \
687- &i2c_stm32_dev_data_##index, \
688- &i2c_stm32_cfg_##index, \
689- POST_KERNEL, CONFIG_I2C_INIT_PRIORITY, \
690- &api_funcs); \
691- \
692- STM32_I2C_IRQ_HANDLER (index)
693-
694- DT_INST_FOREACH_STATUS_OKAY (STM32_I2C_INIT )
649+ #define I2C_STM32_INIT (index ) \
650+ I2C_STM32_IRQ_HANDLER_DECL (index); \
651+ \
652+ IF_ENABLED(DT_HAS_COMPAT_STATUS_OKAY(st_stm32_i2c_v2), \
653+ (static const uint32_t i2c_timings_##index[] = \
654+ DT_INST_PROP_OR(index, timings, {});)) \
655+ \
656+ PINCTRL_DT_INST_DEFINE(index); \
657+ \
658+ static const struct stm32_pclken pclken_##index[] = \
659+ STM32_DT_INST_CLOCKS(index); \
660+ \
661+ static const struct i2c_stm32_config i2c_stm32_cfg_##index = { \
662+ .i2c = (I2C_TypeDef *)DT_INST_REG_ADDR(index), \
663+ .pclken = pclken_##index, \
664+ .pclk_len = DT_INST_NUM_CLOCKS(index), \
665+ I2C_STM32_IRQ_HANDLER_FUNCTION (index) \
666+ .bitrate = DT_INST_PROP(index, clock_frequency), \
667+ .pcfg = PINCTRL_DT_INST_DEV_CONFIG_GET(index), \
668+ IF_ENABLED(CONFIG_I2C_STM32_BUS_RECOVERY, \
669+ (.scl = GPIO_DT_SPEC_INST_GET_OR(index, scl_gpios, {0}), \
670+ .sda = GPIO_DT_SPEC_INST_GET_OR(index, sda_gpios, {0}),)) \
671+ IF_ENABLED(DT_HAS_COMPAT_STATUS_OKAY(st_stm32_i2c_v2), \
672+ (.timings = (const struct i2c_config_timing *) i2c_timings_##index, \
673+ .n_timings = ARRAY_SIZE(i2c_timings_##index),)) \
674+ I2C_DMA_INIT(index, tx) \
675+ I2C_DMA_INIT(index, rx) \
676+ }; \
677+ \
678+ static struct i2c_stm32_data i2c_stm32_dev_data_##index = { \
679+ I2C_DMA_DATA_INIT(index, tx, MEMORY, PERIPHERAL) \
680+ I2C_DMA_DATA_INIT(index, rx, PERIPHERAL, MEMORY) \
681+ }; \
682+ \
683+ PM_DEVICE_DT_INST_DEFINE(index, i2c_stm32_pm_action); \
684+ \
685+ I2C_DEVICE_DT_INST_DEFINE(index, i2c_stm32_init, \
686+ PM_DEVICE_DT_INST_GET(index), \
687+ &i2c_stm32_dev_data_##index, \
688+ &i2c_stm32_cfg_##index, \
689+ POST_KERNEL, CONFIG_I2C_INIT_PRIORITY, \
690+ &api_funcs); \
691+ \
692+ I2C_STM32_IRQ_HANDLER (index)
693+
694+ DT_INST_FOREACH_STATUS_OKAY (I2C_STM32_INIT )
0 commit comments