@@ -32,8 +32,13 @@ LOG_MODULE_REGISTER(mcux_lpi2c);
32
32
*/
33
33
#define SCAN_DELAY_US (baudrate ) (12 * USEC_PER_SEC / baudrate)
34
34
35
+ /* Required by DEVICE_MMIO_NAMED_* macros */
36
+ #define DEV_CFG (_dev ) \
37
+ ((const struct mcux_lpi2c_config *)(_dev)->config)
38
+ #define DEV_DATA (_dev ) ((struct mcux_lpi2c_data *)(_dev)->data)
39
+
35
40
struct mcux_lpi2c_config {
36
- LPI2C_Type * base ;
41
+ DEVICE_MMIO_NAMED_ROM ( reg_base ) ;
37
42
const struct device * clock_dev ;
38
43
clock_control_subsys_t clock_subsys ;
39
44
void (* irq_config_func )(const struct device * dev );
@@ -47,6 +52,7 @@ struct mcux_lpi2c_config {
47
52
};
48
53
49
54
struct mcux_lpi2c_data {
55
+ DEVICE_MMIO_NAMED_RAM (reg_base );
50
56
lpi2c_master_handle_t handle ;
51
57
struct k_sem lock ;
52
58
struct k_sem device_sync_sem ;
@@ -66,7 +72,7 @@ static int mcux_lpi2c_configure(const struct device *dev,
66
72
{
67
73
const struct mcux_lpi2c_config * config = dev -> config ;
68
74
struct mcux_lpi2c_data * data = dev -> data ;
69
- LPI2C_Type * base = config -> base ;
75
+ LPI2C_Type * base = ( LPI2C_Type * ) DEVICE_MMIO_NAMED_GET ( dev , reg_base ) ;
70
76
uint32_t clock_freq ;
71
77
uint32_t baudrate ;
72
78
int ret ;
@@ -138,11 +144,11 @@ static uint32_t mcux_lpi2c_convert_flags(int msg_flags)
138
144
}
139
145
140
146
static int mcux_lpi2c_transfer (const struct device * dev , struct i2c_msg * msgs ,
141
- uint8_t num_msgs , uint16_t addr )
147
+ uint8_t num_msgs , uint16_t addr )
142
148
{
143
149
const struct mcux_lpi2c_config * config = dev -> config ;
144
150
struct mcux_lpi2c_data * data = dev -> data ;
145
- LPI2C_Type * base = config -> base ;
151
+ LPI2C_Type * base = ( LPI2C_Type * ) DEVICE_MMIO_NAMED_GET ( dev , reg_base ) ;
146
152
lpi2c_master_transfer_t transfer ;
147
153
status_t status ;
148
154
int ret = 0 ;
@@ -306,6 +312,7 @@ static void mcux_lpi2c_slave_irq_handler(const struct device *dev)
306
312
{
307
313
const struct mcux_lpi2c_config * config = dev -> config ;
308
314
struct mcux_lpi2c_data * data = dev -> data ;
315
+ LPI2C_Type * base = (LPI2C_Type * )DEVICE_MMIO_NAMED_GET (dev , reg_base );
309
316
const struct i2c_target_callbacks * target_cb = data -> target_cfg -> callbacks ;
310
317
int ret ;
311
318
uint32_t flags ;
@@ -319,11 +326,11 @@ static void mcux_lpi2c_slave_irq_handler(const struct device *dev)
319
326
* every byte. For these reason, we handle the LPI2C IRQ
320
327
* directly.
321
328
*/
322
- flags = LPI2C_SlaveGetStatusFlags (config -> base );
329
+ flags = LPI2C_SlaveGetStatusFlags (base );
323
330
324
331
if (flags & kLPI2C_SlaveAddressValidFlag ) {
325
332
/* Read Slave address to clear flag */
326
- LPI2C_SlaveGetReceivedAddress (config -> base );
333
+ LPI2C_SlaveGetReceivedAddress (base );
327
334
data -> first_tx = true;
328
335
/* Reset to sending ACK, in case we NAK'ed before */
329
336
data -> send_ack = true;
@@ -384,26 +391,27 @@ static void mcux_lpi2c_slave_irq_handler(const struct device *dev)
384
391
}
385
392
386
393
if (flags & kLPI2C_SlaveStopDetectFlag ) {
387
- LPI2C_SlaveClearStatusFlags (config -> base , flags );
394
+ LPI2C_SlaveClearStatusFlags (base , flags );
388
395
if (target_cb -> stop ) {
389
396
target_cb -> stop (data -> target_cfg );
390
397
}
391
398
}
392
399
393
400
if (flags & kLPI2C_SlaveTransmitAckFlag ) {
394
- LPI2C_SlaveTransmitAck (config -> base , data -> send_ack );
401
+ LPI2C_SlaveTransmitAck (base , data -> send_ack );
395
402
}
396
403
}
397
404
398
405
static int mcux_lpi2c_target_register (const struct device * dev ,
399
- struct i2c_target_config * target_config )
406
+ struct i2c_target_config * target_config )
400
407
{
401
408
const struct mcux_lpi2c_config * config = dev -> config ;
402
409
struct mcux_lpi2c_data * data = dev -> data ;
410
+ LPI2C_Type * base = (LPI2C_Type * )DEVICE_MMIO_NAMED_GET (dev , reg_base );
403
411
lpi2c_slave_config_t slave_config ;
404
412
uint32_t clock_freq ;
405
413
406
- LPI2C_MasterDeinit (config -> base );
414
+ LPI2C_MasterDeinit (base );
407
415
408
416
/* Get the clock frequency */
409
417
if (clock_control_get_rate (config -> clock_dev , config -> clock_subsys ,
@@ -430,11 +438,11 @@ static int mcux_lpi2c_target_register(const struct device *dev,
430
438
* this behavior may cause issues with some I2C controllers.
431
439
*/
432
440
slave_config .sclStall .enableAck = true;
433
- LPI2C_SlaveInit (config -> base , & slave_config , clock_freq );
441
+ LPI2C_SlaveInit (base , & slave_config , clock_freq );
434
442
/* Clear all flags. */
435
- LPI2C_SlaveClearStatusFlags (config -> base , (uint32_t )kLPI2C_SlaveClearFlags );
443
+ LPI2C_SlaveClearStatusFlags (base , (uint32_t )kLPI2C_SlaveClearFlags );
436
444
/* Enable interrupt */
437
- LPI2C_SlaveEnableInterrupts (config -> base ,
445
+ LPI2C_SlaveEnableInterrupts (base ,
438
446
(kLPI2C_SlaveTxReadyFlag |
439
447
kLPI2C_SlaveRxReadyFlag |
440
448
kLPI2C_SlaveStopDetectFlag |
@@ -448,6 +456,7 @@ static int mcux_lpi2c_target_unregister(const struct device *dev,
448
456
{
449
457
const struct mcux_lpi2c_config * config = dev -> config ;
450
458
struct mcux_lpi2c_data * data = dev -> data ;
459
+ LPI2C_Type * base = (LPI2C_Type * )DEVICE_MMIO_NAMED_GET (dev , reg_base );
451
460
452
461
if (!data -> target_attached ) {
453
462
return - EINVAL ;
@@ -456,17 +465,16 @@ static int mcux_lpi2c_target_unregister(const struct device *dev,
456
465
data -> target_cfg = NULL ;
457
466
data -> target_attached = false;
458
467
459
- LPI2C_SlaveDeinit (config -> base );
468
+ LPI2C_SlaveDeinit (base );
460
469
461
470
return 0 ;
462
471
}
463
472
#endif /* CONFIG_I2C_TARGET */
464
473
465
474
static void mcux_lpi2c_isr (const struct device * dev )
466
475
{
467
- const struct mcux_lpi2c_config * config = dev -> config ;
468
476
struct mcux_lpi2c_data * data = dev -> data ;
469
- LPI2C_Type * base = config -> base ;
477
+ LPI2C_Type * base = ( LPI2C_Type * ) DEVICE_MMIO_NAMED_GET ( dev , reg_base ) ;
470
478
471
479
#ifdef CONFIG_I2C_TARGET
472
480
if (data -> target_attached ) {
@@ -481,11 +489,15 @@ static int mcux_lpi2c_init(const struct device *dev)
481
489
{
482
490
const struct mcux_lpi2c_config * config = dev -> config ;
483
491
struct mcux_lpi2c_data * data = dev -> data ;
484
- LPI2C_Type * base = config -> base ;
492
+ LPI2C_Type * base ;
485
493
uint32_t clock_freq , bitrate_cfg ;
486
494
lpi2c_master_config_t master_config ;
487
495
int error ;
488
496
497
+ DEVICE_MMIO_NAMED_MAP (dev , reg_base , K_MEM_CACHE_NONE | K_MEM_DIRECT_MAP );
498
+
499
+ base = (LPI2C_Type * )DEVICE_MMIO_NAMED_GET (dev , reg_base );
500
+
489
501
k_sem_init (& data -> lock , 1 , 1 );
490
502
k_sem_init (& data -> device_sync_sem , 0 , K_SEM_MAX_LIMIT );
491
503
@@ -549,7 +561,7 @@ static const struct i2c_driver_api mcux_lpi2c_driver_api = {
549
561
static void mcux_lpi2c_config_func_##n(const struct device *dev); \
550
562
\
551
563
static const struct mcux_lpi2c_config mcux_lpi2c_config_##n = { \
552
- .base = (LPI2C_Type *)DT_INST_REG_ADDR (n), \
564
+ DEVICE_MMIO_NAMED_ROM_INIT(reg_base, DT_DRV_INST (n)), \
553
565
.clock_dev = DEVICE_DT_GET(DT_INST_CLOCKS_CTLR(n)), \
554
566
.clock_subsys = \
555
567
(clock_control_subsys_t)DT_INST_CLOCKS_CELL(n, name),\
@@ -566,17 +578,17 @@ static const struct i2c_driver_api mcux_lpi2c_driver_api = {
566
578
static struct mcux_lpi2c_data mcux_lpi2c_data_##n; \
567
579
\
568
580
I2C_DEVICE_DT_INST_DEFINE(n, mcux_lpi2c_init, NULL, \
569
- &mcux_lpi2c_data_##n, \
570
- &mcux_lpi2c_config_##n, POST_KERNEL, \
571
- CONFIG_I2C_INIT_PRIORITY, \
572
- &mcux_lpi2c_driver_api); \
581
+ &mcux_lpi2c_data_##n, \
582
+ &mcux_lpi2c_config_##n, POST_KERNEL, \
583
+ CONFIG_I2C_INIT_PRIORITY, \
584
+ &mcux_lpi2c_driver_api); \
573
585
\
574
586
static void mcux_lpi2c_config_func_##n(const struct device *dev) \
575
587
{ \
576
588
IRQ_CONNECT(DT_INST_IRQN(n), \
577
- DT_INST_IRQ(n, priority), \
578
- mcux_lpi2c_isr, \
579
- DEVICE_DT_INST_GET(n), 0); \
589
+ DT_INST_IRQ(n, priority), \
590
+ mcux_lpi2c_isr, \
591
+ DEVICE_DT_INST_GET(n), 0); \
580
592
\
581
593
irq_enable(DT_INST_IRQN(n)); \
582
594
}
0 commit comments