@@ -177,8 +177,6 @@ static int gpio_npcx_pin_interrupt_configure(const struct device *dev,
177177 enum gpio_int_trig trig )
178178{
179179 const struct gpio_npcx_config * const config = DRV_CONFIG (dev );
180- enum miwu_int_mode miwu_mode = NPCX_MIWU_MODE_DISABLED ;
181- enum miwu_int_trig miwu_trig = NPCX_MIWU_TRIG_NONE ;
182180
183181 if (config -> wui_maps [pin ].table == NPCX_MIWU_TABLE_NONE ) {
184182 LOG_ERR ("Cannot configure GPIO(%x, %d)" , config -> port , pin );
@@ -190,28 +188,43 @@ static int gpio_npcx_pin_interrupt_configure(const struct device *dev,
190188 config -> wui_maps [pin ].group ,
191189 config -> wui_maps [pin ].bit );
192190
193- /* Determine interrupt is level or edge mode? */
194- if (mode == GPIO_INT_MODE_LEVEL )
195- miwu_mode = NPCX_MIWU_MODE_LEVEL ;
196- else if (mode == GPIO_INT_MODE_EDGE )
197- miwu_mode = NPCX_MIWU_MODE_EDGE ;
198-
199- /* Determine trigger mode is low, high or both? */
200- if (trig == GPIO_INT_TRIG_LOW )
201- miwu_trig = NPCX_MIWU_TRIG_LOW ;
202- else if (trig == GPIO_INT_TRIG_HIGH )
203- miwu_trig = NPCX_MIWU_TRIG_HIGH ;
204- else if (trig == GPIO_INT_TRIG_BOTH )
205- miwu_trig = NPCX_MIWU_TRIG_BOTH ;
206-
207- /* Call MIWU routine to setup interrupt configuration */
208- npcx_miwu_interrupt_configure (& config -> wui_maps [pin ],
209- miwu_mode , miwu_trig );
210-
211- /* Enable/Disable irq of wake-up input sources */
212- if (mode == GPIO_INT_MODE_DISABLED ) {
213- npcx_miwu_irq_disable (& config -> wui_maps [pin ]);
214- } else {
191+ /* Disable irq of wake-up input io-pads before configuring them */
192+ npcx_miwu_irq_disable (& config -> wui_maps [pin ]);
193+
194+ /* Configure and enable interrupt? */
195+ if (mode != GPIO_INT_MODE_DISABLED ) {
196+ enum miwu_int_mode miwu_mode ;
197+ enum miwu_int_trig miwu_trig ;
198+ int ret = 0 ;
199+
200+ /* Determine interrupt is level or edge mode? */
201+ if (mode == GPIO_INT_MODE_EDGE ) {
202+ miwu_mode = NPCX_MIWU_MODE_EDGE ;
203+ } else {
204+ miwu_mode = NPCX_MIWU_MODE_LEVEL ;
205+ }
206+
207+ /* Determine trigger mode is low, high or both? */
208+ if (trig == GPIO_INT_TRIG_LOW ) {
209+ miwu_trig = NPCX_MIWU_TRIG_LOW ;
210+ } else if (trig == GPIO_INT_TRIG_HIGH ) {
211+ miwu_trig = NPCX_MIWU_TRIG_HIGH ;
212+ } else if (trig == GPIO_INT_TRIG_BOTH ) {
213+ miwu_trig = NPCX_MIWU_TRIG_BOTH ;
214+ } else {
215+ LOG_ERR ("Invalid interrupt trigger type %d" , trig );
216+ return - EINVAL ;
217+ }
218+
219+ /* Call MIWU routine to setup interrupt configuration */
220+ ret = npcx_miwu_interrupt_configure (& config -> wui_maps [pin ],
221+ miwu_mode , miwu_trig );
222+ if (ret != 0 ) {
223+ LOG_ERR ("Configure MIWU interrupt failed" );
224+ return ret ;
225+ }
226+
227+ /* Enable it after configuration is completed */
215228 npcx_miwu_irq_enable (& config -> wui_maps [pin ]);
216229 }
217230
0 commit comments