31 #include <linux/export.h>
34 #include <linux/slab.h>
58 #define TWL4030_CORE_NR_IRQS 8
59 #define TWL4030_PWR_NR_IRQS 8
62 #define REG_PIH_ISR_P1 0x01
63 #define REG_PIH_ISR_P2 0x02
64 #define REG_PIH_SIR 0x03
91 static const struct sih *sih_modules;
92 static int nr_sih_modules;
94 #define SIH_INITIALIZER(modname, nbits) \
95 .module = TWL4030_MODULE_ ## modname, \
96 .control_offset = TWL4030_ ## modname ## _SIH_CTRL, \
98 .bytes_ixr = DIV_ROUND_UP(nbits, 8), \
99 .edr_offset = TWL4030_ ## modname ## _EDR, \
100 .bytes_edr = DIV_ROUND_UP((2*(nbits)), 8), \
103 .isr_offset = TWL4030_ ## modname ## _ISR1, \
104 .imr_offset = TWL4030_ ## modname ## _IMR1, \
107 .isr_offset = TWL4030_ ## modname ## _ISR2, \
108 .imr_offset = TWL4030_ ## modname ## _IMR2, \
112 #define TWL4030_INT_PWR_EDR TWL4030_INT_PWR_EDR1
113 #define TWL4030_MODULE_KEYPAD_KEYP TWL4030_MODULE_KEYPAD
114 #define TWL4030_MODULE_INT_PWR TWL4030_MODULE_INT
122 static const struct sih sih_modules_twl4030[6] = {
182 static const struct sih sih_modules_twl5031[8] = {
276 #undef TWL4030_MODULE_KEYPAD_KEYP
277 #undef TWL4030_MODULE_INT_PWR
278 #undef TWL4030_INT_PWR_EDR
282 static unsigned twl4030_irq_base;
301 pr_warning(
"twl4030: I2C error %d reading PIH ISR\n", ret);
306 unsigned long pending =
__ffs(pih_isr);
309 pih_isr &= ~
BIT(pending);
310 irq = pending + twl4030_irq_base;
328 static int twl4030_init_sih_modules(
unsigned line)
342 memset(buf, 0xff,
sizeof buf);
344 for (i = 0; i < nr_sih_modules; i++, sih++) {
356 pr_err(
"twl4030: err %d initializing %s %s\n",
357 status, sih->
name,
"IMR");
372 pr_err(
"twl4030: err %d initializing %s %s\n",
373 status, sih->
name,
"SIH_CTRL");
378 for (i = 0; i < nr_sih_modules; i++, sih++) {
396 for (j = 0; j < 2; j++) {
400 pr_err(
"twl4030: err %d initializing %s %s\n",
401 status, sih->
name,
"ISR");
405 sih->
mask[line].isr_offset,
417 static inline void activate_irq(
int irq)
427 irq_set_noprobe(irq);
457 struct sih_agent *agent = irq_data_get_irq_chip_data(data);
465 struct sih_agent *agent = irq_data_get_irq_chip_data(data);
473 struct sih_agent *agent = irq_data_get_irq_chip_data(data);
478 if (irqd_get_trigger_type(data) != trigger)
484 static void twl4030_sih_bus_lock(
struct irq_data *data)
486 struct sih_agent *agent = irq_data_get_irq_chip_data(data);
491 static void twl4030_sih_bus_sync_unlock(
struct irq_data *data)
493 struct sih_agent *agent = irq_data_get_irq_chip_data(data);
494 const struct sih *sih = agent->
sih;
509 sih->
mask[irq_line].imr_offset,
512 pr_err(
"twl4030: %s, %s --> %d\n", __func__,
532 pr_err(
"twl4030: %s, %s --> %d\n", __func__,
538 while (edge_change) {
539 int i = fls(edge_change) - 1;
541 int byte = 1 + (i >> 2);
542 int off = (i & 0x3) * 2;
547 bytes[
byte] &= ~(0x03 << off);
549 type = irqd_get_trigger_type(idata);
555 edge_change &= ~
BIT(i);
562 pr_err(
"twl4030: %s, %s --> %d\n", __func__,
569 static struct irq_chip twl4030_sih_irq_chip = {
571 .irq_mask = twl4030_sih_mask,
572 .irq_unmask = twl4030_sih_unmask,
573 .irq_set_type = twl4030_sih_set_type,
574 .irq_bus_lock = twl4030_sih_bus_lock,
575 .irq_bus_sync_unlock = twl4030_sih_bus_sync_unlock,
580 static inline int sih_read_isr(
const struct sih *sih)
601 static irqreturn_t handle_twl4030_sih(
int irq,
void *data)
603 struct sih_agent *agent = irq_get_handler_data(irq);
604 const struct sih *sih = agent->
sih;
608 isr = sih_read_isr(sih);
611 pr_err(
"twl4030: %s SIH, read ISR error %d\n",
625 pr_err(
"twl4030: %s SIH, invalid ISR bit %d\n",
635 const struct sih *sih =
NULL;
641 for (sih_mod = 0, sih = sih_modules; sih_mod < nr_sih_modules;
661 for (i = 0; i < sih->
bits; i++) {
665 irq_set_chip_and_handler(irq, &twl4030_sih_irq_chip,
667 irq_set_nested_thread(irq, 1);
672 irq = sih_mod + twl4030_irq_base;
679 dev_info(dev,
"%s (irq %d) chaining IRQs %d..%d\n", sih->
name,
680 irq, irq_base, irq_base + i - 1);
682 return status < 0 ? status :
irq_base;
690 #define twl_irq_line 0
694 static struct irq_chip twl4030_irq_chip;
696 int irq_base, irq_end,
nr_irqs;
706 irq_base = irq_alloc_descs(-1, 0, nr_irqs, 0);
708 dev_err(dev,
"Fail to allocate IRQ descs\n");
725 twl4030_irq_base = irq_base;
732 twl4030_irq_chip.
name =
"twl4030";
736 for (i = irq_base; i < irq_end; i++) {
737 irq_set_chip_and_handler(i, &twl4030_irq_chip,
739 irq_set_nested_thread(i, 1);
743 dev_info(dev,
"%s (irq %d) chaining IRQs %d..%d\n",
"PIH",
744 irq_num, irq_base, irq_end);
749 dev_err(dev,
"sih_setup PWR INT --> %d\n", status);
756 "TWL4030-PIH",
NULL);
758 dev_err(dev,
"could not claim irq%d: %d\n", irq_num, status);
761 enable_irq_wake(irq_num);
767 for (i = irq_base; i < irq_end; i++) {
768 irq_set_nested_thread(i, 0);
769 irq_set_chip_and_handler(i,
NULL,
NULL);
778 if (twl4030_irq_base) {
779 pr_err(
"twl4030: can't yet clean up IRQs?\n");
787 if (!
strcmp(chip,
"twl5031")) {
788 sih_modules = sih_modules_twl5031;
789 nr_sih_modules =
ARRAY_SIZE(sih_modules_twl5031);
791 sih_modules = sih_modules_twl4030;
792 nr_sih_modules =
ARRAY_SIZE(sih_modules_twl4030);