diff --git a/drivers/spmi/spmi-apple-controller.c b/drivers/spmi/spmi-apple-controller.c index c5f8829cfeb45..9e6ba9b27477b 100644 --- a/drivers/spmi/spmi-apple-controller.c +++ b/drivers/spmi/spmi-apple-controller.c @@ -77,6 +77,9 @@ struct apple_spmi_hw { u32 rx_empty; bool legacy_irqs; u32 num_irqs; + /* Interrupt mask and acknowledge banks */ + u32 irq_mask; + u32 irq_ack; }; static const struct apple_spmi_hw apple_spmi_gen1 = { @@ -86,6 +89,8 @@ static const struct apple_spmi_hw apple_spmi_gen1 = { .rx_empty = SPMI_RX_FIFO_EMPTY, .legacy_irqs = true, .num_irqs = 256, + .irq_mask = SPMI_IRQ_MASK_BASE, + .irq_ack = SPMI_IRQ_ACK_BASE, }; /* M1 Pro, Max and Ultra: 192 peripheral interrupts, notification at 192 */ @@ -96,13 +101,22 @@ static const struct apple_spmi_hw apple_spmi_t6000 = { .rx_empty = SPMI_RX_FIFO_EMPTY, .legacy_irqs = true, .num_irqs = 192, + .irq_mask = SPMI_IRQ_MASK_BASE, + .irq_ack = SPMI_IRQ_ACK_BASE, }; +/* + * Generation 4: 256 peripheral interrupts, the notification at 256 and the controller's fault + * interrupt at 263, in 32-bit mask words from 0x400 and acknowledge words from 0x600. + */ static const struct apple_spmi_hw apple_spmi_gen4 = { .status = 0x200, .command = 0x210, .reply = 0x220, .rx_empty = BIT(30), + .num_irqs = SPMI_MAX_PERIPHERAL_IRQS, + .irq_mask = 0x400, + .irq_ack = SPMI_GEN4_IRQ_ACK_BASE, }; struct apple_spmi { @@ -125,21 +139,21 @@ struct apple_spmi { static void apple_spmi_irq_ack_raw(struct apple_spmi *spmi, u32 irq) { - u32 __iomem *reg = spmi->regs + SPMI_IRQ_ACK_BASE + (irq / 32) * 4; + u32 __iomem *reg = spmi->regs + spmi->hw->irq_ack + (irq / 32) * 4; writel(BIT(irq % 32), reg); } static void apple_spmi_irq_mask_raw(struct apple_spmi *spmi, u32 irq) { - u32 __iomem *reg = spmi->regs + SPMI_IRQ_MASK_BASE + (irq / 32) * 4; + u32 __iomem *reg = spmi->regs + spmi->hw->irq_mask + (irq / 32) * 4; writel(readl(reg) & ~BIT(irq % 32), reg); } static void apple_spmi_irq_unmask_raw(struct apple_spmi *spmi, u32 irq) { - u32 __iomem *reg = spmi->regs + SPMI_IRQ_MASK_BASE + (irq / 32) * 4; + u32 __iomem *reg = spmi->regs + spmi->hw->irq_mask + (irq / 32) * 4; writel(readl(reg) | BIT(irq % 32), reg); } @@ -504,6 +518,16 @@ static const struct irq_domain_ops apple_spmi_irq_domain_ops = { .free = apple_spmi_irq_domain_free, }; +/* Generation 4 has 32-bit interrupt banks; older controllers are read 64 bits at a time. */ +static u64 apple_spmi_irq_status(struct apple_spmi *spmi, unsigned long offset) +{ + void __iomem *reg = spmi->regs + spmi->hw->irq_ack + offset; + + if (!spmi->hw->legacy_irqs) + return readl(reg) | ((u64)readl(reg + 4) << 32); + return readq(reg); +} + static void apple_spmi_irq_handler(struct irq_desc *desc) { struct apple_spmi *spmi = irq_desc_get_handler_data(desc); @@ -513,7 +537,7 @@ static void apple_spmi_irq_handler(struct irq_desc *desc) unsigned long val, offset, bit; chained_irq_enter(chip, desc); - val = readl(spmi->regs + SPMI_IRQ_ACK_BASE + (notify / 32) * 4); + val = readl(spmi->regs + spmi->hw->irq_ack + (notify / 32) * 4); raw_pending |= !!val; if (val & BIT(notify % 32)) { apple_spmi_irq_ack_raw(spmi, notify); @@ -522,14 +546,14 @@ static void apple_spmi_irq_handler(struct irq_desc *desc) } /* Other queues' responses, such as the sleep's own commands at the debug link's cut. */ if (val & ~BIT(notify % 32)) { - writel(val & ~BIT(notify % 32), spmi->regs + SPMI_IRQ_ACK_BASE + (notify / 32) * 4); + writel(val & ~BIT(notify % 32), spmi->regs + spmi->hw->irq_ack + (notify / 32) * 4); handled = true; } for (offset = 0; offset < notify / 8; offset += sizeof(val)) { unsigned long stray; - val = readq(spmi->regs + SPMI_IRQ_ACK_BASE + offset); + val = apple_spmi_irq_status(spmi, offset); raw_pending |= !!val; /* * After a real sleep, sources no driver uses come up pending (on the Neo the @@ -540,8 +564,8 @@ static void apple_spmi_irq_handler(struct irq_desc *desc) */ stray = val & ~spmi->irq_used[offset / sizeof(val)]; if (stray) { - writel(lower_32_bits(stray), spmi->regs + SPMI_IRQ_ACK_BASE + offset); - writel(upper_32_bits(stray), spmi->regs + SPMI_IRQ_ACK_BASE + offset + 4); + writel(lower_32_bits(stray), spmi->regs + spmi->hw->irq_ack + offset); + writel(upper_32_bits(stray), spmi->regs + spmi->hw->irq_ack + offset + 4); handled = true; } if (val & spmi->irq_used[offset / sizeof(val)] & @@ -571,7 +595,7 @@ static void apple_spmi_irq_handler(struct irq_desc *desc) * unmasked, or it fires again for what was just cleared. */ if (handled) - readl(spmi->regs + SPMI_IRQ_ACK_BASE); + readl(spmi->regs + spmi->hw->irq_ack); chained_irq_exit(chip, desc); } @@ -580,7 +604,7 @@ static void apple_spmi_teardown_irq(void *data) struct apple_spmi *spmi = data; for (size_t offset = 0; offset < (spmi->hw->num_irqs + 32) / 8; offset += 4) - writel(0, spmi->regs + SPMI_IRQ_MASK_BASE + offset); + writel(0, spmi->regs + spmi->hw->irq_mask + offset); synchronize_irq(spmi->irq); irq_set_chained_handler_and_data(spmi->irq, NULL, NULL); @@ -600,8 +624,8 @@ static int apple_spmi_init_irq(struct platform_device *pdev, raw_spin_lock_init(&spmi->irq_mask_lock); for (size_t offset = 0; offset < (spmi->hw->num_irqs + 32) / 8; offset += 4) { - writel(0, spmi->regs + SPMI_IRQ_MASK_BASE + offset); - writel(U32_MAX, spmi->regs + SPMI_IRQ_ACK_BASE + offset); + writel(0, spmi->regs + spmi->hw->irq_mask + offset); + writel(U32_MAX, spmi->regs + spmi->hw->irq_ack + offset); } spmi->irqd = devm_irq_domain_instantiate(&pdev->dev, &info); @@ -662,7 +686,7 @@ static int apple_spmi_resume_noirq(struct device *dev) if (pm_resume_via_firmware()) { bitmap_to_arr32(words, spmi->irq_mask_cache, spmi->hw->num_irqs); for (i = 0; i < spmi->hw->num_irqs / 32; i++) - writel(words[i], spmi->regs + SPMI_IRQ_MASK_BASE + i * 4); + writel(words[i], spmi->regs + spmi->hw->irq_mask + i * 4); } apple_spmi_irq_ack_raw(spmi, spmi->hw->num_irqs); apple_spmi_irq_unmask_raw(spmi, spmi->hw->num_irqs); @@ -715,9 +739,6 @@ static int apple_spmi_probe(struct platform_device *pdev) if (spmi->irq < 0 && spmi->irq != -ENXIO) return spmi->irq; if (spmi->irq >= 0) { - if (!spmi->hw->legacy_irqs) - return dev_err_probe(&pdev->dev, -EOPNOTSUPP, - "Generation 4 interrupt layout is not supported\n"); ret = apple_spmi_init_irq(pdev, spmi, spmi->irq); if (ret) return ret;