Thomas Gleixner | 2874c5f | 2019-05-27 08:55:01 +0200 | [diff] [blame] | 1 | // SPDX-License-Identifier: GPL-2.0-or-later |
Albert Herranz | 9c21025 | 2009-12-12 06:31:47 +0000 | [diff] [blame] | 2 | /* |
| 3 | * arch/powerpc/platforms/embedded6xx/hlwd-pic.c |
| 4 | * |
| 5 | * Nintendo Wii "Hollywood" interrupt controller support. |
| 6 | * Copyright (C) 2009 The GameCube Linux Team |
| 7 | * Copyright (C) 2009 Albert Herranz |
Albert Herranz | 9c21025 | 2009-12-12 06:31:47 +0000 | [diff] [blame] | 8 | */ |
| 9 | #define DRV_MODULE_NAME "hlwd-pic" |
| 10 | #define pr_fmt(fmt) DRV_MODULE_NAME ": " fmt |
| 11 | |
| 12 | #include <linux/kernel.h> |
Albert Herranz | 9c21025 | 2009-12-12 06:31:47 +0000 | [diff] [blame] | 13 | #include <linux/irq.h> |
| 14 | #include <linux/of.h> |
Rob Herring | 26a2056 | 2013-09-26 07:40:04 -0500 | [diff] [blame] | 15 | #include <linux/of_address.h> |
| 16 | #include <linux/of_irq.h> |
Albert Herranz | 9c21025 | 2009-12-12 06:31:47 +0000 | [diff] [blame] | 17 | #include <asm/io.h> |
| 18 | |
| 19 | #include "hlwd-pic.h" |
| 20 | |
| 21 | #define HLWD_NR_IRQS 32 |
| 22 | |
| 23 | /* |
| 24 | * Each interrupt has a corresponding bit in both |
| 25 | * the Interrupt Cause (ICR) and Interrupt Mask (IMR) registers. |
| 26 | * |
| 27 | * Enabling/disabling an interrupt line involves asserting/clearing |
| 28 | * the corresponding bit in IMR. ACK'ing a request simply involves |
| 29 | * asserting the corresponding bit in ICR. |
| 30 | */ |
| 31 | #define HW_BROADWAY_ICR 0x00 |
| 32 | #define HW_BROADWAY_IMR 0x04 |
Jonathan Neuschäfer | 9dcb3df | 2018-05-10 23:59:19 +0200 | [diff] [blame] | 33 | #define HW_STARLET_ICR 0x08 |
| 34 | #define HW_STARLET_IMR 0x0c |
Albert Herranz | 9c21025 | 2009-12-12 06:31:47 +0000 | [diff] [blame] | 35 | |
| 36 | |
| 37 | /* |
| 38 | * IRQ chip hooks. |
| 39 | * |
| 40 | */ |
| 41 | |
Lennert Buytenhek | 0bf8878 | 2011-03-08 22:26:53 +0000 | [diff] [blame] | 42 | static void hlwd_pic_mask_and_ack(struct irq_data *d) |
Albert Herranz | 9c21025 | 2009-12-12 06:31:47 +0000 | [diff] [blame] | 43 | { |
Grant Likely | 476eb49 | 2011-05-04 15:02:15 +1000 | [diff] [blame] | 44 | int irq = irqd_to_hwirq(d); |
Lennert Buytenhek | 0bf8878 | 2011-03-08 22:26:53 +0000 | [diff] [blame] | 45 | void __iomem *io_base = irq_data_get_irq_chip_data(d); |
Albert Herranz | 9c21025 | 2009-12-12 06:31:47 +0000 | [diff] [blame] | 46 | u32 mask = 1 << irq; |
| 47 | |
| 48 | clrbits32(io_base + HW_BROADWAY_IMR, mask); |
| 49 | out_be32(io_base + HW_BROADWAY_ICR, mask); |
| 50 | } |
| 51 | |
Lennert Buytenhek | 0bf8878 | 2011-03-08 22:26:53 +0000 | [diff] [blame] | 52 | static void hlwd_pic_ack(struct irq_data *d) |
Albert Herranz | 9c21025 | 2009-12-12 06:31:47 +0000 | [diff] [blame] | 53 | { |
Grant Likely | 476eb49 | 2011-05-04 15:02:15 +1000 | [diff] [blame] | 54 | int irq = irqd_to_hwirq(d); |
Lennert Buytenhek | 0bf8878 | 2011-03-08 22:26:53 +0000 | [diff] [blame] | 55 | void __iomem *io_base = irq_data_get_irq_chip_data(d); |
Albert Herranz | 9c21025 | 2009-12-12 06:31:47 +0000 | [diff] [blame] | 56 | |
| 57 | out_be32(io_base + HW_BROADWAY_ICR, 1 << irq); |
| 58 | } |
| 59 | |
Lennert Buytenhek | 0bf8878 | 2011-03-08 22:26:53 +0000 | [diff] [blame] | 60 | static void hlwd_pic_mask(struct irq_data *d) |
Albert Herranz | 9c21025 | 2009-12-12 06:31:47 +0000 | [diff] [blame] | 61 | { |
Grant Likely | 476eb49 | 2011-05-04 15:02:15 +1000 | [diff] [blame] | 62 | int irq = irqd_to_hwirq(d); |
Lennert Buytenhek | 0bf8878 | 2011-03-08 22:26:53 +0000 | [diff] [blame] | 63 | void __iomem *io_base = irq_data_get_irq_chip_data(d); |
Albert Herranz | 9c21025 | 2009-12-12 06:31:47 +0000 | [diff] [blame] | 64 | |
| 65 | clrbits32(io_base + HW_BROADWAY_IMR, 1 << irq); |
| 66 | } |
| 67 | |
Lennert Buytenhek | 0bf8878 | 2011-03-08 22:26:53 +0000 | [diff] [blame] | 68 | static void hlwd_pic_unmask(struct irq_data *d) |
Albert Herranz | 9c21025 | 2009-12-12 06:31:47 +0000 | [diff] [blame] | 69 | { |
Grant Likely | 476eb49 | 2011-05-04 15:02:15 +1000 | [diff] [blame] | 70 | int irq = irqd_to_hwirq(d); |
Lennert Buytenhek | 0bf8878 | 2011-03-08 22:26:53 +0000 | [diff] [blame] | 71 | void __iomem *io_base = irq_data_get_irq_chip_data(d); |
Albert Herranz | 9c21025 | 2009-12-12 06:31:47 +0000 | [diff] [blame] | 72 | |
| 73 | setbits32(io_base + HW_BROADWAY_IMR, 1 << irq); |
Jonathan Neuschäfer | 9dcb3df | 2018-05-10 23:59:19 +0200 | [diff] [blame] | 74 | |
| 75 | /* Make sure the ARM (aka. Starlet) doesn't handle this interrupt. */ |
| 76 | clrbits32(io_base + HW_STARLET_IMR, 1 << irq); |
Albert Herranz | 9c21025 | 2009-12-12 06:31:47 +0000 | [diff] [blame] | 77 | } |
| 78 | |
| 79 | |
| 80 | static struct irq_chip hlwd_pic = { |
| 81 | .name = "hlwd-pic", |
Lennert Buytenhek | 0bf8878 | 2011-03-08 22:26:53 +0000 | [diff] [blame] | 82 | .irq_ack = hlwd_pic_ack, |
| 83 | .irq_mask_ack = hlwd_pic_mask_and_ack, |
| 84 | .irq_mask = hlwd_pic_mask, |
| 85 | .irq_unmask = hlwd_pic_unmask, |
Albert Herranz | 9c21025 | 2009-12-12 06:31:47 +0000 | [diff] [blame] | 86 | }; |
| 87 | |
| 88 | /* |
| 89 | * IRQ host hooks. |
| 90 | * |
| 91 | */ |
| 92 | |
Grant Likely | bae1d8f | 2012-02-14 14:06:50 -0700 | [diff] [blame] | 93 | static struct irq_domain *hlwd_irq_host; |
Albert Herranz | 9c21025 | 2009-12-12 06:31:47 +0000 | [diff] [blame] | 94 | |
Grant Likely | bae1d8f | 2012-02-14 14:06:50 -0700 | [diff] [blame] | 95 | static int hlwd_pic_map(struct irq_domain *h, unsigned int virq, |
Albert Herranz | 9c21025 | 2009-12-12 06:31:47 +0000 | [diff] [blame] | 96 | irq_hw_number_t hwirq) |
| 97 | { |
Thomas Gleixner | ec775d0 | 2011-03-25 16:45:20 +0100 | [diff] [blame] | 98 | irq_set_chip_data(virq, h->host_data); |
Thomas Gleixner | 98488db | 2011-03-25 15:43:57 +0100 | [diff] [blame] | 99 | irq_set_status_flags(virq, IRQ_LEVEL); |
Thomas Gleixner | ec775d0 | 2011-03-25 16:45:20 +0100 | [diff] [blame] | 100 | irq_set_chip_and_handler(virq, &hlwd_pic, handle_level_irq); |
Albert Herranz | 9c21025 | 2009-12-12 06:31:47 +0000 | [diff] [blame] | 101 | return 0; |
| 102 | } |
| 103 | |
Grant Likely | 9f70b8e | 2012-01-26 12:24:34 -0700 | [diff] [blame] | 104 | static const struct irq_domain_ops hlwd_irq_domain_ops = { |
Albert Herranz | 9c21025 | 2009-12-12 06:31:47 +0000 | [diff] [blame] | 105 | .map = hlwd_pic_map, |
Albert Herranz | 9c21025 | 2009-12-12 06:31:47 +0000 | [diff] [blame] | 106 | }; |
| 107 | |
Grant Likely | bae1d8f | 2012-02-14 14:06:50 -0700 | [diff] [blame] | 108 | static unsigned int __hlwd_pic_get_irq(struct irq_domain *h) |
Albert Herranz | 9c21025 | 2009-12-12 06:31:47 +0000 | [diff] [blame] | 109 | { |
| 110 | void __iomem *io_base = h->host_data; |
Albert Herranz | 9c21025 | 2009-12-12 06:31:47 +0000 | [diff] [blame] | 111 | u32 irq_status; |
| 112 | |
| 113 | irq_status = in_be32(io_base + HW_BROADWAY_ICR) & |
| 114 | in_be32(io_base + HW_BROADWAY_IMR); |
| 115 | if (irq_status == 0) |
Michael Ellerman | ef24ba7 | 2016-09-06 21:53:24 +1000 | [diff] [blame] | 116 | return 0; /* no more IRQs pending */ |
Albert Herranz | 9c21025 | 2009-12-12 06:31:47 +0000 | [diff] [blame] | 117 | |
Marc Zyngier | 2c89965 | 2021-05-04 17:42:18 +0100 | [diff] [blame] | 118 | return __ffs(irq_status); |
Albert Herranz | 9c21025 | 2009-12-12 06:31:47 +0000 | [diff] [blame] | 119 | } |
| 120 | |
Thomas Gleixner | bd0b9ac | 2015-09-14 10:42:37 +0200 | [diff] [blame] | 121 | static void hlwd_pic_irq_cascade(struct irq_desc *desc) |
Albert Herranz | 9c21025 | 2009-12-12 06:31:47 +0000 | [diff] [blame] | 122 | { |
Thomas Gleixner | ec775d0 | 2011-03-25 16:45:20 +0100 | [diff] [blame] | 123 | struct irq_chip *chip = irq_desc_get_chip(desc); |
Jiang Liu | c1231a7 | 2015-05-20 17:59:52 +0800 | [diff] [blame] | 124 | struct irq_domain *irq_domain = irq_desc_get_handler_data(desc); |
Marc Zyngier | 2c89965 | 2021-05-04 17:42:18 +0100 | [diff] [blame] | 125 | unsigned int hwirq; |
Albert Herranz | 9c21025 | 2009-12-12 06:31:47 +0000 | [diff] [blame] | 126 | |
Albert Herranz | 7ccec3e | 2009-12-18 10:04:42 +0000 | [diff] [blame] | 127 | raw_spin_lock(&desc->lock); |
Lennert Buytenhek | 0bf8878 | 2011-03-08 22:26:53 +0000 | [diff] [blame] | 128 | chip->irq_mask(&desc->irq_data); /* IRQ_LEVEL */ |
Albert Herranz | 7ccec3e | 2009-12-18 10:04:42 +0000 | [diff] [blame] | 129 | raw_spin_unlock(&desc->lock); |
Albert Herranz | 9c21025 | 2009-12-12 06:31:47 +0000 | [diff] [blame] | 130 | |
Marc Zyngier | 2c89965 | 2021-05-04 17:42:18 +0100 | [diff] [blame] | 131 | hwirq = __hlwd_pic_get_irq(irq_domain); |
| 132 | if (hwirq) |
| 133 | generic_handle_domain_irq(irq_domain, hwirq); |
Albert Herranz | 9c21025 | 2009-12-12 06:31:47 +0000 | [diff] [blame] | 134 | else |
| 135 | pr_err("spurious interrupt!\n"); |
| 136 | |
Albert Herranz | 7ccec3e | 2009-12-18 10:04:42 +0000 | [diff] [blame] | 137 | raw_spin_lock(&desc->lock); |
Lennert Buytenhek | 0bf8878 | 2011-03-08 22:26:53 +0000 | [diff] [blame] | 138 | chip->irq_ack(&desc->irq_data); /* IRQ_LEVEL */ |
Thomas Gleixner | 98488db | 2011-03-25 15:43:57 +0100 | [diff] [blame] | 139 | if (!irqd_irq_disabled(&desc->irq_data) && chip->irq_unmask) |
Lennert Buytenhek | 0bf8878 | 2011-03-08 22:26:53 +0000 | [diff] [blame] | 140 | chip->irq_unmask(&desc->irq_data); |
Albert Herranz | 7ccec3e | 2009-12-18 10:04:42 +0000 | [diff] [blame] | 141 | raw_spin_unlock(&desc->lock); |
Albert Herranz | 9c21025 | 2009-12-12 06:31:47 +0000 | [diff] [blame] | 142 | } |
| 143 | |
| 144 | /* |
| 145 | * Platform hooks. |
| 146 | * |
| 147 | */ |
| 148 | |
| 149 | static void __hlwd_quiesce(void __iomem *io_base) |
| 150 | { |
| 151 | /* mask and ack all IRQs */ |
| 152 | out_be32(io_base + HW_BROADWAY_IMR, 0); |
| 153 | out_be32(io_base + HW_BROADWAY_ICR, 0xffffffff); |
| 154 | } |
| 155 | |
Mathieu Malaterre | eed6964 | 2018-04-23 21:45:32 +0200 | [diff] [blame] | 156 | static struct irq_domain *hlwd_pic_init(struct device_node *np) |
Albert Herranz | 9c21025 | 2009-12-12 06:31:47 +0000 | [diff] [blame] | 157 | { |
Grant Likely | bae1d8f | 2012-02-14 14:06:50 -0700 | [diff] [blame] | 158 | struct irq_domain *irq_domain; |
Albert Herranz | 9c21025 | 2009-12-12 06:31:47 +0000 | [diff] [blame] | 159 | struct resource res; |
| 160 | void __iomem *io_base; |
| 161 | int retval; |
| 162 | |
| 163 | retval = of_address_to_resource(np, 0, &res); |
| 164 | if (retval) { |
| 165 | pr_err("no io memory range found\n"); |
| 166 | return NULL; |
| 167 | } |
| 168 | io_base = ioremap(res.start, resource_size(&res)); |
| 169 | if (!io_base) { |
| 170 | pr_err("ioremap failed\n"); |
| 171 | return NULL; |
| 172 | } |
| 173 | |
| 174 | pr_info("controller at 0x%08x mapped to 0x%p\n", res.start, io_base); |
| 175 | |
| 176 | __hlwd_quiesce(io_base); |
| 177 | |
Grant Likely | a8db8cf | 2012-02-14 14:06:54 -0700 | [diff] [blame] | 178 | irq_domain = irq_domain_add_linear(np, HLWD_NR_IRQS, |
| 179 | &hlwd_irq_domain_ops, io_base); |
Grant Likely | bae1d8f | 2012-02-14 14:06:50 -0700 | [diff] [blame] | 180 | if (!irq_domain) { |
| 181 | pr_err("failed to allocate irq_domain\n"); |
Wei Yongjun | 8d7c0b5 | 2013-10-12 15:13:19 +0800 | [diff] [blame] | 182 | iounmap(io_base); |
Albert Herranz | 9c21025 | 2009-12-12 06:31:47 +0000 | [diff] [blame] | 183 | return NULL; |
| 184 | } |
Albert Herranz | 9c21025 | 2009-12-12 06:31:47 +0000 | [diff] [blame] | 185 | |
Grant Likely | bae1d8f | 2012-02-14 14:06:50 -0700 | [diff] [blame] | 186 | return irq_domain; |
Albert Herranz | 9c21025 | 2009-12-12 06:31:47 +0000 | [diff] [blame] | 187 | } |
| 188 | |
| 189 | unsigned int hlwd_pic_get_irq(void) |
| 190 | { |
Marc Zyngier | 2c89965 | 2021-05-04 17:42:18 +0100 | [diff] [blame] | 191 | unsigned int hwirq = __hlwd_pic_get_irq(hlwd_irq_host); |
| 192 | return hwirq ? irq_linear_revmap(hlwd_irq_host, hwirq) : 0; |
Albert Herranz | 9c21025 | 2009-12-12 06:31:47 +0000 | [diff] [blame] | 193 | } |
| 194 | |
| 195 | /* |
| 196 | * Probe function. |
| 197 | * |
| 198 | */ |
| 199 | |
| 200 | void hlwd_pic_probe(void) |
| 201 | { |
Grant Likely | bae1d8f | 2012-02-14 14:06:50 -0700 | [diff] [blame] | 202 | struct irq_domain *host; |
Albert Herranz | 9c21025 | 2009-12-12 06:31:47 +0000 | [diff] [blame] | 203 | struct device_node *np; |
| 204 | const u32 *interrupts; |
| 205 | int cascade_virq; |
| 206 | |
| 207 | for_each_compatible_node(np, NULL, "nintendo,hollywood-pic") { |
| 208 | interrupts = of_get_property(np, "interrupts", NULL); |
| 209 | if (interrupts) { |
| 210 | host = hlwd_pic_init(np); |
| 211 | BUG_ON(!host); |
| 212 | cascade_virq = irq_of_parse_and_map(np, 0); |
Thomas Gleixner | ec775d0 | 2011-03-25 16:45:20 +0100 | [diff] [blame] | 213 | irq_set_handler_data(cascade_virq, host); |
| 214 | irq_set_chained_handler(cascade_virq, |
Albert Herranz | 9c21025 | 2009-12-12 06:31:47 +0000 | [diff] [blame] | 215 | hlwd_pic_irq_cascade); |
Paul Gortmaker | 6d166fe | 2012-02-22 18:35:03 -0500 | [diff] [blame] | 216 | hlwd_irq_host = host; |
Albert Herranz | 9c21025 | 2009-12-12 06:31:47 +0000 | [diff] [blame] | 217 | break; |
| 218 | } |
| 219 | } |
| 220 | } |
| 221 | |
| 222 | /** |
| 223 | * hlwd_quiesce() - quiesce hollywood irq controller |
| 224 | * |
| 225 | * Mask and ack all interrupt sources. |
| 226 | * |
| 227 | */ |
| 228 | void hlwd_quiesce(void) |
| 229 | { |
Paul Gortmaker | 6d166fe | 2012-02-22 18:35:03 -0500 | [diff] [blame] | 230 | void __iomem *io_base = hlwd_irq_host->host_data; |
Albert Herranz | 9c21025 | 2009-12-12 06:31:47 +0000 | [diff] [blame] | 231 | |
| 232 | __hlwd_quiesce(io_base); |
| 233 | } |
| 234 | |