@@ -171,10 +171,9 @@ static int gpio_dw_pin_interrupt_configure(const struct device *port,
171
171
enum gpio_int_mode mode ,
172
172
enum gpio_int_trig trig )
173
173
{
174
- struct gpio_dw_runtime * context = port -> data ;
175
174
const struct gpio_dw_config * config = port -> config ;
176
- uint32_t base_addr = dw_base_to_block_base (context -> base_addr );
177
- uint32_t port_base_addr = context -> base_addr ;
175
+ uint32_t base_addr = dw_base_to_block_base (config -> base_addr );
176
+ uint32_t port_base_addr = config -> base_addr ;
178
177
uint32_t dir_port = dw_get_dir_port (port_base_addr );
179
178
uint32_t data_port = dw_get_data_port (port_base_addr );
180
179
uint32_t dir_reg ;
@@ -235,10 +234,9 @@ static int gpio_dw_pin_interrupt_configure(const struct device *port,
235
234
static inline void dw_pin_config (const struct device * port ,
236
235
uint32_t pin , int flags )
237
236
{
238
- struct gpio_dw_runtime * context = port -> data ;
239
237
const struct gpio_dw_config * config = port -> config ;
240
- uint32_t base_addr = dw_base_to_block_base (context -> base_addr );
241
- uint32_t port_base_addr = context -> base_addr ;
238
+ uint32_t base_addr = dw_base_to_block_base (config -> base_addr );
239
+ uint32_t port_base_addr = config -> base_addr ;
242
240
uint32_t dir_port = dw_get_dir_port (port_base_addr );
243
241
bool pin_is_output , need_debounce ;
244
242
@@ -303,9 +301,9 @@ static inline int gpio_dw_config(const struct device *port,
303
301
304
302
static int gpio_dw_port_get_raw (const struct device * port , uint32_t * value )
305
303
{
306
- struct gpio_dw_runtime * context = port -> data ;
307
- uint32_t base_addr = dw_base_to_block_base (context -> base_addr );
308
- uint32_t port_base_addr = context -> base_addr ;
304
+ const struct gpio_dw_config * config = port -> config ;
305
+ uint32_t base_addr = dw_base_to_block_base (config -> base_addr );
306
+ uint32_t port_base_addr = config -> base_addr ;
309
307
uint32_t ext_port = dw_get_ext_port (port_base_addr );
310
308
311
309
* value = dw_read (base_addr , ext_port );
@@ -316,9 +314,9 @@ static int gpio_dw_port_get_raw(const struct device *port, uint32_t *value)
316
314
static int gpio_dw_port_set_masked_raw (const struct device * port ,
317
315
uint32_t mask , uint32_t value )
318
316
{
319
- struct gpio_dw_runtime * context = port -> data ;
320
- uint32_t base_addr = dw_base_to_block_base (context -> base_addr );
321
- uint32_t port_base_addr = context -> base_addr ;
317
+ const struct gpio_dw_config * config = port -> config ;
318
+ uint32_t base_addr = dw_base_to_block_base (config -> base_addr );
319
+ uint32_t port_base_addr = config -> base_addr ;
322
320
uint32_t data_port = dw_get_data_port (port_base_addr );
323
321
uint32_t pins ;
324
322
@@ -331,9 +329,9 @@ static int gpio_dw_port_set_masked_raw(const struct device *port,
331
329
332
330
static int gpio_dw_port_set_bits_raw (const struct device * port , uint32_t mask )
333
331
{
334
- struct gpio_dw_runtime * context = port -> data ;
335
- uint32_t base_addr = dw_base_to_block_base (context -> base_addr );
336
- uint32_t port_base_addr = context -> base_addr ;
332
+ const struct gpio_dw_config * config = port -> config ;
333
+ uint32_t base_addr = dw_base_to_block_base (config -> base_addr );
334
+ uint32_t port_base_addr = config -> base_addr ;
337
335
uint32_t data_port = dw_get_data_port (port_base_addr );
338
336
uint32_t pins ;
339
337
@@ -347,9 +345,9 @@ static int gpio_dw_port_set_bits_raw(const struct device *port, uint32_t mask)
347
345
static int gpio_dw_port_clear_bits_raw (const struct device * port ,
348
346
uint32_t mask )
349
347
{
350
- struct gpio_dw_runtime * context = port -> data ;
351
- uint32_t base_addr = dw_base_to_block_base (context -> base_addr );
352
- uint32_t port_base_addr = context -> base_addr ;
348
+ const struct gpio_dw_config * config = port -> config ;
349
+ uint32_t base_addr = dw_base_to_block_base (config -> base_addr );
350
+ uint32_t port_base_addr = config -> base_addr ;
353
351
uint32_t data_port = dw_get_data_port (port_base_addr );
354
352
uint32_t pins ;
355
353
@@ -362,9 +360,9 @@ static int gpio_dw_port_clear_bits_raw(const struct device *port,
362
360
363
361
static int gpio_dw_port_toggle_bits (const struct device * port , uint32_t mask )
364
362
{
365
- struct gpio_dw_runtime * context = port -> data ;
366
- uint32_t base_addr = dw_base_to_block_base (context -> base_addr );
367
- uint32_t port_base_addr = context -> base_addr ;
363
+ const struct gpio_dw_config * config = port -> config ;
364
+ uint32_t base_addr = dw_base_to_block_base (config -> base_addr );
365
+ uint32_t port_base_addr = config -> base_addr ;
368
366
uint32_t data_port = dw_get_data_port (port_base_addr );
369
367
uint32_t pins ;
370
368
@@ -388,7 +386,8 @@ static inline int gpio_dw_manage_callback(const struct device *port,
388
386
static void gpio_dw_isr (const struct device * port )
389
387
{
390
388
struct gpio_dw_runtime * context = port -> data ;
391
- uint32_t base_addr = dw_base_to_block_base (context -> base_addr );
389
+ const struct gpio_dw_config * config = port -> config ;
390
+ uint32_t base_addr = dw_base_to_block_base (config -> base_addr );
392
391
uint32_t int_status ;
393
392
394
393
int_status = dw_read (base_addr , INTSTATUS );
@@ -401,14 +400,13 @@ static void gpio_dw_isr(const struct device *port)
401
400
402
401
int gpio_dw_set_hw_mode (const struct device * port , gpio_pin_t pin , bool hw_mode )
403
402
{
404
- struct gpio_dw_runtime * context = port -> data ;
405
- __unused const struct gpio_driver_config * const cfg =
406
- (const struct gpio_driver_config * )port -> config ;
407
- uint32_t base_addr = dw_base_to_block_base (context -> base_addr );
408
- uint32_t port_id = dw_derive_port_from_base (context -> base_addr );
403
+ const struct gpio_dw_config * config = port -> config ;
404
+ uint32_t base_addr = dw_base_to_block_base (config -> base_addr );
405
+ uint32_t port_id = dw_derive_port_from_base (config -> base_addr );
409
406
uint32_t ctl_port ;
410
407
411
- __ASSERT ((cfg -> port_pin_mask & (gpio_port_pins_t )BIT (pin )) != 0U , "Unsupported pin" );
408
+ __ASSERT ((config -> common .port_pin_mask & (gpio_port_pins_t )BIT (pin )) != 0U ,
409
+ "Unsupported pin" );
412
410
413
411
/* 4-port GPIO implementation translates from base address to port */
414
412
switch (port_id ) {
@@ -445,13 +443,12 @@ static DEVICE_API(gpio, api_funcs) = {
445
443
446
444
static int gpio_dw_initialize (const struct device * port )
447
445
{
448
- struct gpio_dw_runtime * context = port -> data ;
449
446
const struct gpio_dw_config * config = port -> config ;
450
447
uint32_t base_addr ;
451
448
452
449
if (dw_interrupt_support (config )) {
453
450
454
- base_addr = dw_base_to_block_base (context -> base_addr );
451
+ base_addr = dw_base_to_block_base (config -> base_addr );
455
452
456
453
/* interrupts in sync with system clock */
457
454
dw_set_bit (base_addr , INT_CLOCK_SYNC , LS_SYNC_POS , 1 );
@@ -488,14 +485,13 @@ static int gpio_dw_initialize(const struct device *port)
488
485
.common = { \
489
486
.port_pin_mask = GPIO_PORT_PIN_MASK_FROM_DT_INST(n), \
490
487
}, \
488
+ .base_addr = DT_INST_REG_ADDR(n), \
491
489
.irq_num = COND_CODE_1(DT_INST_IRQ_HAS_IDX(n, 0), (DT_INST_IRQN(n)), (0)), \
492
490
.ngpios = DT_INST_PROP(n, ngpios), \
493
491
.config_func = gpio_config_##n##_irq, \
494
492
}; \
495
493
\
496
- static struct gpio_dw_runtime gpio_##n##_runtime = { \
497
- .base_addr = DT_INST_REG_ADDR(n), \
498
- }; \
494
+ static struct gpio_dw_runtime gpio_##n##_runtime; \
499
495
\
500
496
DEVICE_DT_INST_DEFINE(n, gpio_dw_initialize, NULL, &gpio_##n##_runtime, \
501
497
&gpio_dw_config_##n, PRE_KERNEL_1, \
0 commit comments