Lines Matching +full:irq +full:- +full:can +full:- +full:wake
1 // SPDX-License-Identifier: GPL-2.0-or-later
3 * wm831x-irq.c -- Interrupt controller support for Wolfson WM831x PMICs
13 #include <linux/irq.h>
21 #include <linux/mfd/wm831x/irq.h>
321 return WM831X_INTERRUPT_STATUS_1 - 1 + irq_data->reg; in irq_data_to_status_reg()
325 int irq) in irq_to_wm831x_irq() argument
327 return &wm831x_irqs[irq]; in irq_to_wm831x_irq()
334 mutex_lock(&wm831x->irq_lock); in wm831x_irq_lock()
342 for (i = 0; i < ARRAY_SIZE(wm831x->gpio_update); i++) { in wm831x_irq_sync_unlock()
343 if (wm831x->gpio_update[i]) { in wm831x_irq_sync_unlock()
346 wm831x->gpio_update[i]); in wm831x_irq_sync_unlock()
347 wm831x->gpio_update[i] = 0; in wm831x_irq_sync_unlock()
351 for (i = 0; i < ARRAY_SIZE(wm831x->irq_masks_cur); i++) { in wm831x_irq_sync_unlock()
354 if (wm831x->irq_masks_cur[i] != wm831x->irq_masks_cache[i]) { in wm831x_irq_sync_unlock()
355 dev_dbg(wm831x->dev, "IRQ mask sync: %x = %x\n", in wm831x_irq_sync_unlock()
357 wm831x->irq_masks_cur[i]); in wm831x_irq_sync_unlock()
359 wm831x->irq_masks_cache[i] = wm831x->irq_masks_cur[i]; in wm831x_irq_sync_unlock()
362 wm831x->irq_masks_cur[i]); in wm831x_irq_sync_unlock()
366 mutex_unlock(&wm831x->irq_lock); in wm831x_irq_sync_unlock()
373 data->hwirq); in wm831x_irq_enable()
375 wm831x->irq_masks_cur[irq_data->reg - 1] &= ~irq_data->mask; in wm831x_irq_enable()
382 data->hwirq); in wm831x_irq_disable()
384 wm831x->irq_masks_cur[irq_data->reg - 1] |= irq_data->mask; in wm831x_irq_disable()
390 int irq; in wm831x_irq_set_type() local
392 irq = data->hwirq; in wm831x_irq_set_type()
394 if (irq < WM831X_IRQ_GPIO_1 || irq > WM831X_IRQ_GPIO_11) { in wm831x_irq_set_type()
395 /* Ignore internal-only IRQs */ in wm831x_irq_set_type()
396 if (irq >= 0 && irq < WM831X_NUM_IRQS) in wm831x_irq_set_type()
399 return -EINVAL; in wm831x_irq_set_type()
402 /* Rebase the IRQ into the GPIO range so we've got a sensible array in wm831x_irq_set_type()
405 irq -= WM831X_IRQ_GPIO_1; in wm831x_irq_set_type()
408 * do the update here as we can be called with the bus lock in wm831x_irq_set_type()
411 wm831x->gpio_level_low[irq] = false; in wm831x_irq_set_type()
412 wm831x->gpio_level_high[irq] = false; in wm831x_irq_set_type()
415 wm831x->gpio_update[irq] = 0x10000 | WM831X_GPN_INT_MODE; in wm831x_irq_set_type()
418 wm831x->gpio_update[irq] = 0x10000 | WM831X_GPN_POL; in wm831x_irq_set_type()
421 wm831x->gpio_update[irq] = 0x10000; in wm831x_irq_set_type()
424 wm831x->gpio_update[irq] = 0x10000 | WM831X_GPN_POL; in wm831x_irq_set_type()
425 wm831x->gpio_level_high[irq] = true; in wm831x_irq_set_type()
428 wm831x->gpio_update[irq] = 0x10000; in wm831x_irq_set_type()
429 wm831x->gpio_level_low[irq] = true; in wm831x_irq_set_type()
432 return -EINVAL; in wm831x_irq_set_type()
448 * we can interact with the device over I2C or SPI. */
449 static irqreturn_t wm831x_irq_thread(int irq, void *data) in wm831x_irq_thread() argument
460 dev_err(wm831x->dev, "Failed to read system interrupt: %d\n", in wm831x_irq_thread()
467 * main handling loop and so we can also skip iterating the in wm831x_irq_thread()
471 handle_nested_irq(irq_find_mapping(wm831x->irq_domain, in wm831x_irq_thread()
474 handle_nested_irq(irq_find_mapping(wm831x->irq_domain, in wm831x_irq_thread()
479 int offset = wm831x_irqs[i].reg - 1; in wm831x_irq_thread()
493 dev_err(wm831x->dev, in wm831x_irq_thread()
494 "Failed to read IRQ status: %d\n", in wm831x_irq_thread()
502 *status &= ~wm831x->irq_masks_cur[offset]; in wm831x_irq_thread()
511 handle_nested_irq(irq_find_mapping(wm831x->irq_domain, in wm831x_irq_thread()
514 /* Simulate an edge triggered IRQ by polling the input in wm831x_irq_thread()
518 wm831x->gpio_level_high[i - WM831X_IRQ_GPIO_1]) { in wm831x_irq_thread()
520 while (ret & 1 << (i - WM831X_IRQ_GPIO_1)) { in wm831x_irq_thread()
521 handle_nested_irq(irq_find_mapping(wm831x->irq_domain, in wm831x_irq_thread()
529 wm831x->gpio_level_low[i - WM831X_IRQ_GPIO_1]) { in wm831x_irq_thread()
531 while (!(ret & 1 << (i - WM831X_IRQ_GPIO_1))) { in wm831x_irq_thread()
532 handle_nested_irq(irq_find_mapping(wm831x->irq_domain, in wm831x_irq_thread()
547 irq_set_chip_data(virq, h->host_data); in wm831x_irq_map()
560 int wm831x_irq_init(struct wm831x *wm831x, int irq) in wm831x_irq_init() argument
562 struct wm831x_pdata *pdata = &wm831x->pdata; in wm831x_irq_init()
566 mutex_init(&wm831x->irq_lock); in wm831x_irq_init()
569 for (i = 0; i < ARRAY_SIZE(wm831x->irq_masks_cur); i++) { in wm831x_irq_init()
570 wm831x->irq_masks_cur[i] = 0xffff; in wm831x_irq_init()
571 wm831x->irq_masks_cache[i] = 0xffff; in wm831x_irq_init()
577 if (pdata->irq_base) { in wm831x_irq_init()
578 irq_base = irq_alloc_descs(pdata->irq_base, 0, in wm831x_irq_init()
581 dev_warn(wm831x->dev, "Failed to allocate IRQs: %d\n", in wm831x_irq_init()
590 domain = irq_domain_add_legacy(wm831x->dev->of_node, in wm831x_irq_init()
596 domain = irq_domain_add_linear(wm831x->dev->of_node, in wm831x_irq_init()
602 dev_warn(wm831x->dev, "Failed to allocate IRQ domain\n"); in wm831x_irq_init()
603 return -EINVAL; in wm831x_irq_init()
606 if (pdata->irq_cmos) in wm831x_irq_init()
614 wm831x->irq = irq; in wm831x_irq_init()
615 wm831x->irq_domain = domain; in wm831x_irq_init()
617 if (irq) { in wm831x_irq_init()
618 /* Try to flag /IRQ as a wake source; there are a number of in wm831x_irq_init()
619 * unconditional wake sources in the PMIC so this isn't in wm831x_irq_init()
623 ret = enable_irq_wake(irq); in wm831x_irq_init()
625 dev_warn(wm831x->dev, in wm831x_irq_init()
626 "Can't enable IRQ as wake source: %d\n", in wm831x_irq_init()
630 ret = request_threaded_irq(irq, NULL, wm831x_irq_thread, in wm831x_irq_init()
634 dev_err(wm831x->dev, "Failed to request IRQ %d: %d\n", in wm831x_irq_init()
635 irq, ret); in wm831x_irq_init()
639 dev_warn(wm831x->dev, in wm831x_irq_init()
640 "No interrupt specified - functionality limited\n"); in wm831x_irq_init()
651 if (wm831x->irq) in wm831x_irq_exit()
652 free_irq(wm831x->irq, wm831x); in wm831x_irq_exit()