14 #define pr_fmt(fmt) "%s: " fmt, __func__
19 #include <linux/kernel.h>
23 #include <linux/slab.h>
27 #define SSBI_REG_ADDR_IRQ_BASE 0x1BB
29 #define SSBI_REG_ADDR_IRQ_ROOT (SSBI_REG_ADDR_IRQ_BASE + 0)
30 #define SSBI_REG_ADDR_IRQ_M_STATUS1 (SSBI_REG_ADDR_IRQ_BASE + 1)
31 #define SSBI_REG_ADDR_IRQ_M_STATUS2 (SSBI_REG_ADDR_IRQ_BASE + 2)
32 #define SSBI_REG_ADDR_IRQ_M_STATUS3 (SSBI_REG_ADDR_IRQ_BASE + 3)
33 #define SSBI_REG_ADDR_IRQ_M_STATUS4 (SSBI_REG_ADDR_IRQ_BASE + 4)
34 #define SSBI_REG_ADDR_IRQ_BLK_SEL (SSBI_REG_ADDR_IRQ_BASE + 5)
35 #define SSBI_REG_ADDR_IRQ_IT_STATUS (SSBI_REG_ADDR_IRQ_BASE + 6)
36 #define SSBI_REG_ADDR_IRQ_CONFIG (SSBI_REG_ADDR_IRQ_BASE + 7)
37 #define SSBI_REG_ADDR_IRQ_RT_STATUS (SSBI_REG_ADDR_IRQ_BASE + 8)
39 #define PM_IRQF_LVL_SEL 0x01
40 #define PM_IRQF_MASK_FE 0x02
41 #define PM_IRQF_MASK_RE 0x04
42 #define PM_IRQF_CLR 0x08
43 #define PM_IRQF_BITS_MASK 0x70
44 #define PM_IRQF_BITS_SHIFT 4
45 #define PM_IRQF_WRITE 0x80
47 #define PM_IRQF_MASK_ALL (PM_IRQF_MASK_FE | \
68 return pm8xxx_readb(chip->
dev,
79 pr_err(
"Failed Selecting Block %d rc=%d\n", bp, rc);
85 pr_err(
"Failed Reading Status rc=%d\n", rc);
98 pr_err(
"Failed Selecting Block %d rc=%d\n", bp, rc);
105 pr_err(
"Failed Configuring IRQ rc=%d\n", rc);
116 ret = pm8xxx_read_block_irq(chip, block, &bits);
118 pr_err(
"Failed reading %d block ret=%d", block, ret);
122 pr_err(
"block bit set in master but no irqs: %d", block);
127 for (i = 0; i < 8; i++) {
128 if (bits & (1 << i)) {
129 pmirq = block * 8 +
i;
137 static int pm8xxx_irq_master_handler(
struct pm_irq_chip *chip,
int master)
142 ret = pm8xxx_read_master_irq(chip, master, &blockbits);
144 pr_err(
"Failed to read master %d ret=%d\n", master, ret);
148 pr_err(
"master bit set in root but no blocks: %d", master);
152 for (i = 0; i < 8; i++)
153 if (blockbits & (1 << i)) {
154 block_number = master * 8 +
i;
155 ret |= pm8xxx_irq_block_handler(chip, block_number);
160 static void pm8xxx_irq_handler(
unsigned int irq,
struct irq_desc *
desc)
162 struct pm_irq_chip *chip = irq_desc_get_handler_data(desc);
165 int i,
ret, masters = 0;
167 ret = pm8xxx_read_root_irq(chip, &root);
169 pr_err(
"Can't read root status ret=%d\n", ret);
178 if (masters & (1 << i))
179 pm8xxx_irq_master_handler(chip, i);
184 static void pm8xxx_irq_mask_ack(
struct irq_data *
d)
186 struct pm_irq_chip *chip = irq_data_get_irq_chip_data(d);
196 pm8xxx_config_irq(chip, block, config);
199 static void pm8xxx_irq_unmask(
struct irq_data *
d)
201 struct pm_irq_chip *chip = irq_data_get_irq_chip_data(d);
210 config = chip->
config[pmirq];
211 pm8xxx_config_irq(chip, block, config);
214 static int pm8xxx_irq_set_type(
struct irq_data *
d,
unsigned int flow_type)
216 struct pm_irq_chip *chip = irq_data_get_irq_chip_data(d);
242 return pm8xxx_config_irq(chip, block, config);
245 static int pm8xxx_irq_set_wake(
struct irq_data *d,
unsigned int on)
250 static struct irq_chip pm8xxx_irq_chip = {
252 .irq_mask_ack = pm8xxx_irq_mask_ack,
253 .irq_unmask = pm8xxx_irq_unmask,
254 .irq_set_type = pm8xxx_irq_set_type,
255 .irq_set_wake = pm8xxx_irq_set_wake,
278 if (chip ==
NULL || irq < chip->irq_base ||
291 pr_err(
"Failed Selecting block irq=%d pmirq=%d blk=%d rc=%d\n",
292 irq, pmirq, block, rc);
298 pr_err(
"Failed Configuring irq=%d pmirq=%d blk=%d rc=%d\n",
299 irq, pmirq, block, rc);
303 rc = (bits & (1 <<
bit)) ? 1 : 0;
320 pr_err(
"No platform data\n");
326 pr_err(
"missing devirq\n");
334 pr_err(
"Cannot alloc pm_irq_chip struct\n");
346 for (pmirq = 0; pmirq < chip->
num_irqs; pmirq++) {
347 irq_set_chip_and_handler(chip->
irq_base + pmirq,
354 irq_set_noprobe(chip->
irq_base + pmirq);
360 irq_set_chained_handler(devirq, pm8xxx_irq_handler);
361 set_irq_wake(devirq, 1);