@@ -78,68 +78,53 @@ struct intc_miwu_config {
78
78
uint8_t index ;
79
79
};
80
80
81
- /* Callback functions list for GPIO wake-up inputs */
82
- sys_slist_t cb_list_gpio ;
83
-
84
- /*
85
- * Callback functions list for the generic hardware modules wake-up inputs
86
- * such as timer, uart, i2c, host interface and so on.
87
- */
88
- sys_slist_t cb_list_generic ;
89
-
90
- BUILD_ASSERT (sizeof (struct miwu_io_callback ) == sizeof (struct gpio_callback ),
91
- "Size of struct miwu_io_callback must equal to struct gpio_callback" );
81
+ /* Driver data */
82
+ struct intc_miwu_data {
83
+ /* Callback functions list for each MIWU group */
84
+ sys_slist_t cb_list_grp [8 ];
85
+ };
92
86
93
87
BUILD_ASSERT (sizeof (struct miwu_io_params ) == sizeof (gpio_port_pins_t ),
94
88
"Size of struct miwu_io_params must equal to struct gpio_port_pins_t" );
95
89
90
+ BUILD_ASSERT (offsetof (struct miwu_callback , io_cb .params ) +
91
+ sizeof (struct miwu_io_params ) == sizeof (struct gpio_callback ),
92
+ "Failed in size check of miwu_callback and gpio_callback structures!" );
93
+
94
+ BUILD_ASSERT (offsetof (struct miwu_callback , io_cb .params .cb_type ) ==
95
+ offsetof(struct miwu_callback , dev_cb .params .cb_type ),
96
+ "Failed in offset check of cb_type field of miwu_callback structure" );
97
+
96
98
/* MIWU local functions */
97
- static void intc_miwu_dispatch_gpio_isr (uint8_t wui_table ,
98
- uint8_t wui_group , uint8_t wui_bit )
99
+ static void intc_miwu_dispatch_isr (sys_slist_t * cb_list , uint8_t mask )
99
100
{
100
- struct miwu_io_callback * cb , * tmp ;
101
-
102
- SYS_SLIST_FOR_EACH_CONTAINER_SAFE (& cb_list_gpio , cb , tmp , node ) {
103
- /* Pending bit, group and table match the wui item in list */
104
- if (cb -> params .wui .table == wui_table
105
- && cb -> params .wui .group == wui_group
106
- && cb -> params .wui .bit == wui_bit ) {
107
- __ASSERT (cb -> handler , "No GPIO callback handler!" );
108
- /*
109
- * Execute GPIO callback and the other callback might
110
- * match the same wui item.
111
- */
112
- cb -> handler (npcx_get_gpio_dev (cb -> params .gpio_port ),
101
+ struct miwu_callback * cb , * tmp ;
102
+
103
+ SYS_SLIST_FOR_EACH_CONTAINER_SAFE (cb_list , cb , tmp , node ) {
104
+
105
+ if (cb -> io_cb .params .cb_type == NPCX_MIWU_CALLBACK_GPIO ) {
106
+ if (BIT (cb -> io_cb .params .wui .bit ) & mask ) {
107
+ __ASSERT (cb -> io_cb .handler , "No GPIO callback handler!" );
108
+ cb -> io_cb .handler (
109
+ npcx_get_gpio_dev (cb -> io_cb .params .gpio_port ),
113
110
(struct gpio_callback * )cb ,
114
- cb -> params .pin_mask );
115
- }
116
- }
117
- }
111
+ cb -> io_cb .params .pin_mask );
112
+ }
113
+ } else {
114
+ if (BIT (cb -> dev_cb .params .wui .bit ) & mask ) {
115
+ __ASSERT (cb -> dev_cb .handler , "No device callback handler!" );
118
116
119
- static void intc_miwu_dispatch_generic_isr (uint8_t wui_table ,
120
- uint8_t wui_group , uint8_t wui_bit )
121
- {
122
- struct miwu_dev_callback * cb , * tmp ;
123
-
124
- SYS_SLIST_FOR_EACH_CONTAINER_SAFE (& cb_list_generic , cb , tmp , node ) {
125
- /* Pending bit, group and table match the wui item in list */
126
- if (cb -> wui .table == wui_table
127
- && cb -> wui .group == wui_group
128
- && cb -> wui .bit == wui_bit ) {
129
- __ASSERT (cb -> handler , "No Generic callback handler!" );
130
- /*
131
- * Execute generic callback and the other callback might
132
- * match the same wui item.
133
- */
134
- cb -> handler (cb -> source , & cb -> wui );
117
+ cb -> dev_cb .handler (cb -> dev_cb .params .source ,
118
+ & cb -> dev_cb .params .wui );
119
+ }
135
120
}
136
121
}
137
122
}
138
123
139
124
static void intc_miwu_isr_pri (int wui_table , int wui_group )
140
125
{
141
- int wui_bit ;
142
126
const struct intc_miwu_config * config = miwu_devs [wui_table ]-> config ;
127
+ struct intc_miwu_data * data = miwu_devs [wui_table ]-> data ;
143
128
const uint32_t base = config -> base ;
144
129
uint8_t mask = NPCX_WKPND (base , wui_group ) & NPCX_WKEN (base , wui_group );
145
130
@@ -148,17 +133,8 @@ static void intc_miwu_isr_pri(int wui_table, int wui_group)
148
133
NPCX_WKPCL (base , wui_group ) = mask ;
149
134
}
150
135
151
- for (wui_bit = 0 ; wui_bit < 8 ; wui_bit ++ ) {
152
- if (mask & BIT (wui_bit )) {
153
- LOG_DBG ("miwu_isr %d %d %d!\n" , wui_table ,
154
- wui_group , wui_bit );
155
- /* Dispatch registered gpio and generic isrs */
156
- intc_miwu_dispatch_gpio_isr (wui_table ,
157
- wui_group , wui_bit );
158
- intc_miwu_dispatch_generic_isr (wui_table ,
159
- wui_group , wui_bit );
160
- }
161
- }
136
+ /* Dispatch registered gpio isrs */
137
+ intc_miwu_dispatch_isr (& data -> cb_list_grp [wui_group ], mask );
162
138
}
163
139
164
140
/* Platform specific MIWU functions */
@@ -278,58 +254,55 @@ int npcx_miwu_interrupt_configure(const struct npcx_wui *wui,
278
254
return 0 ;
279
255
}
280
256
281
- void npcx_miwu_init_gpio_callback (struct miwu_io_callback * callback ,
257
+ void npcx_miwu_init_gpio_callback (struct miwu_callback * callback ,
282
258
const struct npcx_wui * io_wui , int port )
283
259
{
284
260
/* Initialize WUI and GPIO settings in unused bits field */
285
- callback -> params .wui .table = io_wui -> table ;
286
- callback -> params .wui .group = io_wui -> group ;
287
- callback -> params .wui .bit = io_wui -> bit ;
288
- callback -> params .gpio_port = port ;
261
+ callback -> io_cb .params .wui .table = io_wui -> table ;
262
+ callback -> io_cb .params .wui .bit = io_wui -> bit ;
263
+ callback -> io_cb .params .gpio_port = port ;
264
+ callback -> io_cb .params .cb_type = NPCX_MIWU_CALLBACK_GPIO ;
265
+ callback -> io_cb .params .wui .group = io_wui -> group ;
289
266
}
290
267
291
- void npcx_miwu_init_dev_callback (struct miwu_dev_callback * callback ,
268
+ void npcx_miwu_init_dev_callback (struct miwu_callback * callback ,
292
269
const struct npcx_wui * dev_wui ,
293
270
miwu_dev_callback_handler_t handler ,
294
271
const struct device * source )
295
272
{
296
273
/* Initialize WUI and input device settings */
297
- callback -> wui .table = dev_wui -> table ;
298
- callback -> wui .group = dev_wui -> group ;
299
- callback -> wui .bit = dev_wui -> bit ;
300
- callback -> handler = handler ;
301
- callback -> source = source ;
274
+ callback -> dev_cb .params .wui .table = dev_wui -> table ;
275
+ callback -> dev_cb .params .wui .group = dev_wui -> group ;
276
+ callback -> dev_cb .params .wui .bit = dev_wui -> bit ;
277
+ callback -> dev_cb .params .source = source ;
278
+ callback -> dev_cb .params .cb_type = NPCX_MIWU_CALLBACK_DEV ;
279
+ callback -> dev_cb .handler = handler ;
302
280
}
303
281
304
- int npcx_miwu_manage_gpio_callback (struct miwu_io_callback * cb , bool set )
282
+ int npcx_miwu_manage_callback (struct miwu_callback * cb , bool set )
305
283
{
306
- if (!sys_slist_is_empty (& cb_list_gpio )) {
307
- if (!sys_slist_find_and_remove (& cb_list_gpio , & cb -> node )) {
308
- if (!set ) {
309
- return - EINVAL ;
310
- }
311
- }
312
- }
284
+ struct npcx_wui * wui ;
285
+ struct intc_miwu_data * data ;
286
+ sys_slist_t * cb_list ;
313
287
314
- if (set ) {
315
- sys_slist_prepend (& cb_list_gpio , & cb -> node );
288
+ if (cb -> io_cb .params .cb_type == NPCX_MIWU_CALLBACK_GPIO ) {
289
+ wui = & cb -> io_cb .params .wui ;
290
+ } else {
291
+ wui = & cb -> dev_cb .params .wui ;
316
292
}
317
293
318
- return 0 ;
319
- }
320
-
321
- int npcx_miwu_manage_dev_callback (struct miwu_dev_callback * cb , bool set )
322
- {
323
- if (!sys_slist_is_empty (& cb_list_generic )) {
324
- if (!sys_slist_find_and_remove (& cb_list_generic , & cb -> node )) {
294
+ data = miwu_devs [wui -> table ]-> data ;
295
+ cb_list = & data -> cb_list_grp [wui -> group ];
296
+ if (!sys_slist_is_empty (cb_list )) {
297
+ if (!sys_slist_find_and_remove (cb_list , & cb -> node )) {
325
298
if (!set ) {
326
299
return - EINVAL ;
327
300
}
328
301
}
329
302
}
330
303
331
304
if (set ) {
332
- sys_slist_prepend (& cb_list_generic , & cb -> node );
305
+ sys_slist_prepend (cb_list , & cb -> node );
333
306
}
334
307
335
308
return 0 ;
@@ -385,11 +358,12 @@ int npcx_miwu_manage_dev_callback(struct miwu_dev_callback *cb, bool set)
385
358
.base = DT_REG_ADDR(DT_NODELABEL(miwu##inst)), \
386
359
.index = DT_PROP(DT_NODELABEL(miwu##inst), index), \
387
360
}; \
361
+ struct intc_miwu_data miwu_data_##inst; \
388
362
\
389
363
DEVICE_DT_INST_DEFINE(inst, \
390
364
NPCX_MIWU_INIT_FUNC(inst), \
391
365
NULL, \
392
- NULL , &miwu_config_##inst, \
366
+ &miwu_data_##inst , &miwu_config_##inst, \
393
367
PRE_KERNEL_1, \
394
368
CONFIG_INTC_INIT_PRIORITY, NULL); \
395
369
\
0 commit comments