@@ -29,6 +29,7 @@ LOG_MODULE_REGISTER(i2c_nrfx_twim, CONFIG_I2C_LOG_LEVEL);
2929#endif
3030
3131struct i2c_nrfx_twim_data {
32+ nrfx_twim_t twim ;
3233 struct k_sem transfer_sync ;
3334 struct k_sem completion_sync ;
3435 volatile nrfx_err_t res ;
@@ -81,7 +82,7 @@ static int i2c_nrfx_twim_transfer(const struct device *dev,
8182 break ;
8283 }
8384
84- bool dma_accessible = nrf_dma_accessible_check (& dev_config -> twim , msgs [i ].buf );
85+ bool dma_accessible = nrf_dma_accessible_check (& dev_data -> twim , msgs [i ].buf );
8586
8687 /* This fragment needs to be merged with the next one if:
8788 * - it is not the last fragment
@@ -191,7 +192,7 @@ static int i2c_nrfx_twim_transfer(const struct device *dev,
191192 return ret ;
192193}
193194
194- static void event_handler (nrfx_twim_evt_t const * p_event , void * p_context )
195+ static void event_handler (nrfx_twim_event_t const * p_event , void * p_context )
195196{
196197 const struct device * dev = p_context ;
197198 struct i2c_nrfx_twim_data * dev_data = dev -> data ;
@@ -238,142 +239,73 @@ static DEVICE_API(i2c, i2c_nrfx_twim_driver_api) = {
238239 .recover_bus = i2c_nrfx_twim_recover_bus ,
239240};
240241
241- #define CONCAT_BUF_SIZE (idx ) \
242- COND_CODE_1(DT_NODE_HAS_PROP(I2C(idx), zephyr_concat_buf_size), \
243- (DT_PROP(I2C(idx), zephyr_concat_buf_size)), (0))
244- #define FLASH_BUF_MAX_SIZE (idx ) \
245- COND_CODE_1(DT_NODE_HAS_PROP(I2C(idx), zephyr_flash_buf_max_size), \
246- (DT_PROP(I2C(idx), zephyr_flash_buf_max_size)), (0))
242+ #if DT_HAS_COMPAT_STATUS_OKAY (nordic_nrf_twim )
243+ #define DT_DRV_COMPAT nordic_nrf_twim
244+ #endif
245+
246+ #define CONCAT_BUF_SIZE (idx ) \
247+ COND_CODE_1(DT_NODE_HAS_PROP(DT_DRV_INST(idx), zephyr_concat_buf_size), \
248+ (DT_INST_PROP(idx, zephyr_concat_buf_size)), (0))
249+ #define FLASH_BUF_MAX_SIZE (idx ) \
250+ COND_CODE_1(DT_NODE_HAS_PROP(DT_DRV_INST(idx), zephyr_flash_buf_max_size), \
251+ (DT_INST_PROP(idx, zephyr_flash_buf_max_size)), (0))
247252
248- #define USES_MSG_BUF (idx ) \
249- COND_CODE_0(CONCAT_BUF_SIZE(idx), \
250- (COND_CODE_0(FLASH_BUF_MAX_SIZE(idx), (0), (1))), \
253+ #define USES_MSG_BUF (idx ) \
254+ COND_CODE_0(CONCAT_BUF_SIZE(idx), \
255+ (COND_CODE_0(FLASH_BUF_MAX_SIZE(idx), (0), (1))), \
251256 (1))
252257#define MSG_BUF_SIZE (idx ) MAX(CONCAT_BUF_SIZE(idx), FLASH_BUF_MAX_SIZE(idx))
253258
254- #define I2C_NRFX_TWIM_DEVICE (idx ) \
255- NRF_DT_CHECK_NODE_HAS_PINCTRL_SLEEP(I2C(idx)); \
256- NRF_DT_CHECK_NODE_HAS_REQUIRED_MEMORY_REGIONS(I2C(idx)); \
257- BUILD_ASSERT(I2C_FREQUENCY(idx) != \
258- I2C_NRFX_TWIM_INVALID_FREQUENCY, \
259- "Wrong I2C " #idx " frequency setting in dts"); \
260- static void irq_connect##idx(void) \
261- { \
262- IRQ_CONNECT(DT_IRQN(I2C(idx)), DT_IRQ(I2C(idx), priority), \
263- nrfx_isr, nrfx_twim_##idx##_irq_handler, 0); \
264- } \
259+ #define I2C_NRFX_TWIM_DEVICE (idx ) \
260+ NRF_DT_CHECK_NODE_HAS_PINCTRL_SLEEP(DT_DRV_INST(idx)); \
261+ NRF_DT_CHECK_NODE_HAS_REQUIRED_MEMORY_REGIONS(DT_DRV_INST(idx)); \
262+ BUILD_ASSERT(I2C_FREQUENCY(DT_DRV_INST(idx)) != I2C_NRFX_TWIM_INVALID_FREQUENCY, \
263+ "Wrong I2C " #idx " frequency setting in dts"); \
264+ static struct i2c_nrfx_twim_data twim_##idx##_data; \
265+ static struct i2c_nrfx_twim_common_config twim_##idx##z_config; \
266+ static void pre_init##idx(void) \
267+ { \
268+ twim_##idx##z_config.twim = &twim_##idx##_data.twim; \
269+ twim_##idx##_data.twim.p_twim = (NRF_TWIM_Type *)DT_INST_REG_ADDR(idx); \
270+ IRQ_CONNECT(DT_INST_IRQN(idx), DT_INST_IRQ(idx, priority), nrfx_twim_irq_handler, \
271+ &twim_##idx##_data.twim, 0); \
272+ } \
265273 IF_ENABLED(USES_MSG_BUF(idx), \
266274 (static uint8_t twim_##idx##_msg_buf[MSG_BUF_SIZE(idx)] \
267- I2C_MEMORY_SECTION(idx);)) \
268- static struct i2c_nrfx_twim_data twim_##idx##_data; \
269- PINCTRL_DT_DEFINE(I2C(idx)); \
270- static const \
271- struct i2c_nrfx_twim_common_config twim_##idx##z_config = { \
272- .twim = NRFX_TWIM_INSTANCE(idx), \
273- .twim_config = { \
274- .skip_gpio_cfg = true, \
275- .skip_psel_cfg = true, \
276- .frequency = I2C_FREQUENCY(idx), \
277- }, \
278- .event_handler = event_handler, \
279- .msg_buf_size = MSG_BUF_SIZE(idx), \
280- .irq_connect = irq_connect##idx, \
281- .pcfg = PINCTRL_DT_DEV_CONFIG_GET(I2C(idx)), \
275+ I2C_MEMORY_SECTION(idx);)) \
276+ PINCTRL_DT_INST_DEFINE(idx); \
277+ static struct i2c_nrfx_twim_common_config twim_##idx##z_config = { \
278+ .twim_config = \
279+ { \
280+ .skip_gpio_cfg = true, \
281+ .skip_psel_cfg = true, \
282+ .frequency = I2C_FREQUENCY(DT_DRV_INST(idx)), \
283+ }, \
284+ .event_handler = event_handler, \
285+ .msg_buf_size = MSG_BUF_SIZE(idx), \
286+ .pre_init = pre_init##idx, \
287+ .pcfg = PINCTRL_DT_INST_DEV_CONFIG_GET(idx), \
282288 IF_ENABLED(USES_MSG_BUF(idx), \
283289 (.msg_buf = twim_##idx##_msg_buf,)) \
284290 .max_transfer_size = BIT_MASK( \
285- DT_PROP(I2C( idx) , easydma_maxcnt_bits)), \
291+ DT_INST_PROP( idx, easydma_maxcnt_bits)), \
286292 }; \
287- PM_DEVICE_DT_DEFINE(I2C( idx) , twim_nrfx_pm_action, \
293+ PM_DEVICE_DT_INST_DEFINE( idx, twim_nrfx_pm_action, \
288294 I2C_PM_ISR_SAFE(idx)); \
289- I2C_DEVICE_DT_DEINIT_DEFINE(I2C( idx) , \
295+ I2C_DEVICE_DT_INST_DEINIT_DEFINE( idx, \
290296 i2c_nrfx_twim_init, \
291297 i2c_nrfx_twim_deinit, \
292- PM_DEVICE_DT_GET(I2C( idx) ), \
298+ PM_DEVICE_DT_INST_GET( idx), \
293299 &twim_##idx##_data, \
294300 &twim_##idx##z_config, \
295301 POST_KERNEL, \
296302 CONFIG_I2C_INIT_PRIORITY, \
297303 &i2c_nrfx_twim_driver_api)
298304
299- #define I2C_MEMORY_SECTION (idx ) \
300- COND_CODE_1(I2C_HAS_PROP( idx, memory_regions), \
305+ #define I2C_MEMORY_SECTION (idx ) \
306+ COND_CODE_1(DT_NODE_HAS_PROP(DT_DRV_INST( idx), prop), \
301307 (__attribute__((__section__(LINKER_DT_NODE_REGION_NAME( \
302- DT_PHANDLE(I2C (idx), memory_regions)))))), \
308+ DT_PHANDLE(DT_DRV_INST (idx), memory_regions)))))), \
303309 ())
304310
305- #ifdef CONFIG_HAS_HW_NRF_TWIM0
306- I2C_NRFX_TWIM_DEVICE (0 );
307- #endif
308-
309- #ifdef CONFIG_HAS_HW_NRF_TWIM1
310- I2C_NRFX_TWIM_DEVICE (1 );
311- #endif
312-
313- #ifdef CONFIG_HAS_HW_NRF_TWIM2
314- I2C_NRFX_TWIM_DEVICE (2 );
315- #endif
316-
317- #ifdef CONFIG_HAS_HW_NRF_TWIM3
318- I2C_NRFX_TWIM_DEVICE (3 );
319- #endif
320-
321- #ifdef CONFIG_HAS_HW_NRF_TWIM20
322- I2C_NRFX_TWIM_DEVICE (20 );
323- #endif
324-
325- #ifdef CONFIG_HAS_HW_NRF_TWIM21
326- I2C_NRFX_TWIM_DEVICE (21 );
327- #endif
328-
329- #ifdef CONFIG_HAS_HW_NRF_TWIM22
330- I2C_NRFX_TWIM_DEVICE (22 );
331- #endif
332-
333- #ifdef CONFIG_HAS_HW_NRF_TWIM23
334- I2C_NRFX_TWIM_DEVICE (23 );
335- #endif
336-
337- #ifdef CONFIG_HAS_HW_NRF_TWIM24
338- I2C_NRFX_TWIM_DEVICE (24 );
339- #endif
340-
341- #ifdef CONFIG_HAS_HW_NRF_TWIM30
342- I2C_NRFX_TWIM_DEVICE (30 );
343- #endif
344-
345- #ifdef CONFIG_HAS_HW_NRF_TWIM120
346- I2C_NRFX_TWIM_DEVICE (120 );
347- #endif
348-
349- #ifdef CONFIG_HAS_HW_NRF_TWIM130
350- I2C_NRFX_TWIM_DEVICE (130 );
351- #endif
352-
353- #ifdef CONFIG_HAS_HW_NRF_TWIM131
354- I2C_NRFX_TWIM_DEVICE (131 );
355- #endif
356-
357- #ifdef CONFIG_HAS_HW_NRF_TWIM132
358- I2C_NRFX_TWIM_DEVICE (132 );
359- #endif
360-
361- #ifdef CONFIG_HAS_HW_NRF_TWIM133
362- I2C_NRFX_TWIM_DEVICE (133 );
363- #endif
364-
365- #ifdef CONFIG_HAS_HW_NRF_TWIM134
366- I2C_NRFX_TWIM_DEVICE (134 );
367- #endif
368-
369- #ifdef CONFIG_HAS_HW_NRF_TWIM135
370- I2C_NRFX_TWIM_DEVICE (135 );
371- #endif
372-
373- #ifdef CONFIG_HAS_HW_NRF_TWIM136
374- I2C_NRFX_TWIM_DEVICE (136 );
375- #endif
376-
377- #ifdef CONFIG_HAS_HW_NRF_TWIM137
378- I2C_NRFX_TWIM_DEVICE (137 );
379- #endif
311+ DT_INST_FOREACH_STATUS_OKAY (I2C_NRFX_TWIM_DEVICE )
0 commit comments