Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

gpio: ep93xx: split device in multiple

Prepare ep93xx SOC gpio to convert into device tree driver:
- dropped banks and legacy defines
- split AB IRQ and make it shared

We are relying on IRQ number information A, B ports have single shared
IRQ, while F port have dedicated IRQ for each line.

Also we had to split single ep93xx platform_device into multiple, one
for each port, without this we can't do a full working transition from
legacy platform code into device tree capable. All GPIO_LOOKUP were
change to match new chip namings.

Signed-off-by: Nikita Shubin <nikita.shubin@maquefel.me>
Tested-by: Alexander Sverdlin <alexander.sverdlin@gmail.com>
Reviewed-by: Linus Walleij <linus.walleij@linaro.org>
Reviewed-by: Andy Shevchenko <andy@kernel.org>
Reviewed-by: Andy Shevchenko <andriy.shevchenko@linux.intel.com>
Reviewed-by: Krzysztof Kozlowski <krzysztof.kozlowski@linaro.org>
Reviewed-by: Guenter Roeck <linux@roeck-us.net>
Acked-by: Bartosz Golaszewski <bartosz.golaszewski@linaro.org>
Acked-by: Miquel Raynal <miquel.raynal@bootlin.com>
Acked-by: Vinod Koul <vkoul@kernel.org>
Signed-off-by: Arnd Bergmann <arnd@arndb.de>

authored by

Nikita Shubin and committed by
Arnd Bergmann
cbe8e464 a8c39443

+228 -220
+109 -12
arch/arm/mach-ep93xx/core.c
··· 35 35 #include <linux/reboot.h> 36 36 #include <linux/usb/ohci_pdriver.h> 37 37 #include <linux/random.h> 38 + #include <linux/ioport.h> 38 39 39 40 #include "hardware.h" 40 41 #include <linux/platform_data/video-ep93xx.h> ··· 140 139 /************************************************************************* 141 140 * EP93xx GPIO 142 141 *************************************************************************/ 143 - static struct resource ep93xx_gpio_resource[] = { 144 - DEFINE_RES_MEM(EP93XX_GPIO_PHYS_BASE, 0xcc), 142 + /* port A */ 143 + static struct resource ep93xx_a_gpio_resources[] = { 144 + DEFINE_RES_MEM_NAMED(EP93XX_GPIO_PHYS_BASE, 0x04, "data"), 145 + DEFINE_RES_MEM_NAMED(EP93XX_GPIO_PHYS_BASE + 0x10, 0x04, "dir"), 146 + DEFINE_RES_MEM_NAMED(EP93XX_GPIO_PHYS_BASE + 0x90, 0x1c, "intr"), 145 147 DEFINE_RES_IRQ(IRQ_EP93XX_GPIO_AB), 148 + }; 149 + 150 + static struct platform_device ep93xx_a_gpio = { 151 + .name = "gpio-ep93xx", 152 + .id = 0, 153 + .num_resources = ARRAY_SIZE(ep93xx_a_gpio_resources), 154 + .resource = ep93xx_a_gpio_resources, 155 + }; 156 + 157 + /* port B */ 158 + static struct resource ep93xx_b_gpio_resources[] = { 159 + DEFINE_RES_MEM_NAMED(EP93XX_GPIO_PHYS_BASE + 0x04, 0x04, "data"), 160 + DEFINE_RES_MEM_NAMED(EP93XX_GPIO_PHYS_BASE + 0x14, 0x04, "dir"), 161 + DEFINE_RES_MEM_NAMED(EP93XX_GPIO_PHYS_BASE + 0xac, 0x1c, "intr"), 162 + DEFINE_RES_IRQ(IRQ_EP93XX_GPIO_AB), 163 + }; 164 + 165 + static struct platform_device ep93xx_b_gpio = { 166 + .name = "gpio-ep93xx", 167 + .id = 1, 168 + .num_resources = ARRAY_SIZE(ep93xx_b_gpio_resources), 169 + .resource = ep93xx_b_gpio_resources, 170 + }; 171 + 172 + /* port C */ 173 + static struct resource ep93xx_c_gpio_resources[] = { 174 + DEFINE_RES_MEM_NAMED(EP93XX_GPIO_PHYS_BASE + 0x08, 0x04, "data"), 175 + DEFINE_RES_MEM_NAMED(EP93XX_GPIO_PHYS_BASE + 0x18, 0x04, "dir"), 176 + }; 177 + 178 + static struct platform_device ep93xx_c_gpio = { 179 + .name = "gpio-ep93xx", 180 + .id = 2, 181 + .num_resources = ARRAY_SIZE(ep93xx_c_gpio_resources), 182 + .resource = ep93xx_c_gpio_resources, 183 + }; 184 + 185 + /* port D */ 186 + static struct resource ep93xx_d_gpio_resources[] = { 187 + DEFINE_RES_MEM_NAMED(EP93XX_GPIO_PHYS_BASE + 0x0c, 0x04, "data"), 188 + DEFINE_RES_MEM_NAMED(EP93XX_GPIO_PHYS_BASE + 0x1c, 0x04, "dir"), 189 + }; 190 + 191 + static struct platform_device ep93xx_d_gpio = { 192 + .name = "gpio-ep93xx", 193 + .id = 3, 194 + .num_resources = ARRAY_SIZE(ep93xx_d_gpio_resources), 195 + .resource = ep93xx_d_gpio_resources, 196 + }; 197 + 198 + /* port E */ 199 + static struct resource ep93xx_e_gpio_resources[] = { 200 + DEFINE_RES_MEM_NAMED(EP93XX_GPIO_PHYS_BASE + 0x20, 0x04, "data"), 201 + DEFINE_RES_MEM_NAMED(EP93XX_GPIO_PHYS_BASE + 0x24, 0x04, "dir"), 202 + }; 203 + 204 + static struct platform_device ep93xx_e_gpio = { 205 + .name = "gpio-ep93xx", 206 + .id = 4, 207 + .num_resources = ARRAY_SIZE(ep93xx_e_gpio_resources), 208 + .resource = ep93xx_e_gpio_resources, 209 + }; 210 + 211 + /* port F */ 212 + static struct resource ep93xx_f_gpio_resources[] = { 213 + DEFINE_RES_MEM_NAMED(EP93XX_GPIO_PHYS_BASE + 0x30, 0x04, "data"), 214 + DEFINE_RES_MEM_NAMED(EP93XX_GPIO_PHYS_BASE + 0x34, 0x04, "dir"), 215 + DEFINE_RES_MEM_NAMED(EP93XX_GPIO_PHYS_BASE + 0x4c, 0x1c, "intr"), 146 216 DEFINE_RES_IRQ(IRQ_EP93XX_GPIO0MUX), 147 217 DEFINE_RES_IRQ(IRQ_EP93XX_GPIO1MUX), 148 218 DEFINE_RES_IRQ(IRQ_EP93XX_GPIO2MUX), ··· 224 152 DEFINE_RES_IRQ(IRQ_EP93XX_GPIO7MUX), 225 153 }; 226 154 227 - static struct platform_device ep93xx_gpio_device = { 228 - .name = "gpio-ep93xx", 229 - .id = -1, 230 - .num_resources = ARRAY_SIZE(ep93xx_gpio_resource), 231 - .resource = ep93xx_gpio_resource, 155 + static struct platform_device ep93xx_f_gpio = { 156 + .name = "gpio-ep93xx", 157 + .id = 5, 158 + .num_resources = ARRAY_SIZE(ep93xx_f_gpio_resources), 159 + .resource = ep93xx_f_gpio_resources, 160 + }; 161 + 162 + /* port G */ 163 + static struct resource ep93xx_g_gpio_resources[] = { 164 + DEFINE_RES_MEM_NAMED(EP93XX_GPIO_PHYS_BASE + 0x38, 0x04, "data"), 165 + DEFINE_RES_MEM_NAMED(EP93XX_GPIO_PHYS_BASE + 0x3c, 0x04, "dir"), 166 + }; 167 + 168 + static struct platform_device ep93xx_g_gpio = { 169 + .name = "gpio-ep93xx", 170 + .id = 6, 171 + .num_resources = ARRAY_SIZE(ep93xx_g_gpio_resources), 172 + .resource = ep93xx_g_gpio_resources, 173 + }; 174 + 175 + static struct platform_device *ep93xx_gpio_device[] __initdata = { 176 + &ep93xx_a_gpio, 177 + &ep93xx_b_gpio, 178 + &ep93xx_c_gpio, 179 + &ep93xx_d_gpio, 180 + &ep93xx_e_gpio, 181 + &ep93xx_f_gpio, 182 + &ep93xx_g_gpio, 232 183 }; 233 184 234 185 /************************************************************************* ··· 430 335 .dev_id = "i2c-gpio.0", 431 336 .table = { 432 337 /* Use local offsets on gpiochip/port "G" */ 433 - GPIO_LOOKUP_IDX("G", 1, NULL, 0, 338 + GPIO_LOOKUP_IDX("gpio-ep93xx.6", 1, NULL, 0, 434 339 GPIO_ACTIVE_HIGH | GPIO_OPEN_DRAIN), 435 - GPIO_LOOKUP_IDX("G", 0, NULL, 1, 340 + GPIO_LOOKUP_IDX("gpio-ep93xx.6", 0, NULL, 1, 436 341 GPIO_ACTIVE_HIGH | GPIO_OPEN_DRAIN), 437 342 { } 438 343 }, ··· 536 441 .dev_id = "leds-gpio", 537 442 .table = { 538 443 /* Use local offsets on gpiochip/port "E" */ 539 - GPIO_LOOKUP_IDX("E", 0, NULL, 0, GPIO_ACTIVE_HIGH), 540 - GPIO_LOOKUP_IDX("E", 1, NULL, 1, GPIO_ACTIVE_HIGH), 444 + GPIO_LOOKUP_IDX("gpio-ep93xx.4", 0, NULL, 0, GPIO_ACTIVE_HIGH), 445 + GPIO_LOOKUP_IDX("gpio-ep93xx.4", 1, NULL, 1, GPIO_ACTIVE_HIGH), 541 446 { } 542 447 }, 543 448 }; ··· 1070 975 struct device __init *ep93xx_init_devices(void) 1071 976 { 1072 977 struct device *parent; 978 + unsigned int i; 1073 979 1074 980 /* Disallow access to MaverickCrunch initially */ 1075 981 ep93xx_devcfg_clear_bits(EP93XX_SYSCON_DEVCFG_CPENA); ··· 1085 989 parent = ep93xx_init_soc(); 1086 990 1087 991 /* Get the GPIO working early, other devices need it */ 1088 - platform_device_register(&ep93xx_gpio_device); 992 + for (i = 0; i < ARRAY_SIZE(ep93xx_gpio_device); i++) 993 + platform_device_register(ep93xx_gpio_device[i]); 1089 994 1090 995 amba_device_register(&uart1_device, &iomem_resource); 1091 996 amba_device_register(&uart2_device, &iomem_resource);
+1 -1
arch/arm/mach-ep93xx/edb93xx.c
··· 105 105 static struct gpiod_lookup_table edb93xx_spi_cs_gpio_table = { 106 106 .dev_id = "spi0", 107 107 .table = { 108 - GPIO_LOOKUP("A", 6, "cs", GPIO_ACTIVE_LOW), 108 + GPIO_LOOKUP("gpio-ep93xx.0", 6, "cs", GPIO_ACTIVE_LOW), 109 109 { }, 110 110 }, 111 111 };
+2 -2
arch/arm/mach-ep93xx/ts72xx.c
··· 268 268 static struct gpiod_lookup_table bk3_spi_cs_gpio_table = { 269 269 .dev_id = "spi0", 270 270 .table = { 271 - GPIO_LOOKUP("F", 3, "cs", GPIO_ACTIVE_LOW), 271 + GPIO_LOOKUP("gpio-ep93xx.5", 3, "cs", GPIO_ACTIVE_LOW), 272 272 { }, 273 273 }, 274 274 }; ··· 318 318 .dev_id = "spi0", 319 319 .table = { 320 320 /* DIO_17 */ 321 - GPIO_LOOKUP("F", 2, "cs", GPIO_ACTIVE_LOW), 321 + GPIO_LOOKUP("gpio-ep93xx.5", 2, "cs", GPIO_ACTIVE_LOW), 322 322 { }, 323 323 }, 324 324 };
+5 -5
arch/arm/mach-ep93xx/vision_ep9307.c
··· 206 206 .dev_id = "mmc_spi.2", /* "mmc_spi @ CS2 */ 207 207 .table = { 208 208 /* Card detect */ 209 - GPIO_LOOKUP_IDX("B", 7, NULL, 0, GPIO_ACTIVE_LOW), 209 + GPIO_LOOKUP_IDX("gpio-ep93xx.1", 7, NULL, 0, GPIO_ACTIVE_LOW), 210 210 /* Write protect */ 211 - GPIO_LOOKUP_IDX("F", 0, NULL, 1, GPIO_ACTIVE_HIGH), 211 + GPIO_LOOKUP_IDX("gpio-ep93xx.5", 0, NULL, 1, GPIO_ACTIVE_HIGH), 212 212 { }, 213 213 }, 214 214 }; ··· 253 253 static struct gpiod_lookup_table vision_spi_cs_gpio_table = { 254 254 .dev_id = "spi0", 255 255 .table = { 256 - GPIO_LOOKUP_IDX("A", 6, "cs", 0, GPIO_ACTIVE_LOW), 257 - GPIO_LOOKUP_IDX("A", 7, "cs", 1, GPIO_ACTIVE_LOW), 258 - GPIO_LOOKUP_IDX("G", 2, "cs", 2, GPIO_ACTIVE_LOW), 256 + GPIO_LOOKUP_IDX("gpio-ep93xx.0", 6, "cs", 0, GPIO_ACTIVE_LOW), 257 + GPIO_LOOKUP_IDX("gpio-ep93xx.0", 7, "cs", 1, GPIO_ACTIVE_LOW), 258 + GPIO_LOOKUP_IDX("gpio-ep93xx.6", 2, "cs", 2, GPIO_ACTIVE_LOW), 259 259 { }, 260 260 }, 261 261 };
+111 -200
drivers/gpio/gpio-ep93xx.c
··· 18 18 #include <linux/gpio/driver.h> 19 19 #include <linux/bitops.h> 20 20 #include <linux/seq_file.h> 21 - 22 - #define EP93XX_GPIO_F_INT_STATUS 0x5c 23 - #define EP93XX_GPIO_A_INT_STATUS 0xa0 24 - #define EP93XX_GPIO_B_INT_STATUS 0xbc 25 - 26 - /* Maximum value for gpio line identifiers */ 27 - #define EP93XX_GPIO_LINE_MAX 63 28 - 29 - /* Number of GPIO chips in EP93XX */ 30 - #define EP93XX_GPIO_CHIP_NUM 8 31 - 32 - /* Maximum value for irq capable line identifiers */ 33 - #define EP93XX_GPIO_LINE_MAX_IRQ 23 34 - 35 - #define EP93XX_GPIO_A_IRQ_BASE 64 36 - #define EP93XX_GPIO_B_IRQ_BASE 72 37 - /* 38 - * Static mapping of GPIO bank F IRQS: 39 - * F0..F7 (16..24) to irq 80..87. 40 - */ 41 - #define EP93XX_GPIO_F_IRQ_BASE 80 21 + #include <linux/interrupt.h> 42 22 43 23 struct ep93xx_gpio_irq_chip { 44 - u8 irq_offset; 24 + void __iomem *base; 45 25 u8 int_unmasked; 46 26 u8 int_enabled; 47 27 u8 int_type1; ··· 30 50 }; 31 51 32 52 struct ep93xx_gpio_chip { 53 + void __iomem *base; 33 54 struct gpio_chip gc; 34 55 struct ep93xx_gpio_irq_chip *eic; 35 - }; 36 - 37 - struct ep93xx_gpio { 38 - void __iomem *base; 39 - struct ep93xx_gpio_chip gc[EP93XX_GPIO_CHIP_NUM]; 40 56 }; 41 57 42 58 #define to_ep93xx_gpio_chip(x) container_of(x, struct ep93xx_gpio_chip, gc) ··· 55 79 #define EP93XX_INT_RAW_STATUS_OFFSET 0x14 56 80 #define EP93XX_INT_DEBOUNCE_OFFSET 0x18 57 81 58 - static void ep93xx_gpio_update_int_params(struct ep93xx_gpio *epg, 59 - struct ep93xx_gpio_irq_chip *eic) 82 + static void ep93xx_gpio_update_int_params(struct ep93xx_gpio_irq_chip *eic) 60 83 { 61 - writeb_relaxed(0, epg->base + eic->irq_offset + EP93XX_INT_EN_OFFSET); 84 + writeb_relaxed(0, eic->base + EP93XX_INT_EN_OFFSET); 62 85 63 86 writeb_relaxed(eic->int_type2, 64 - epg->base + eic->irq_offset + EP93XX_INT_TYPE2_OFFSET); 87 + eic->base + EP93XX_INT_TYPE2_OFFSET); 65 88 66 89 writeb_relaxed(eic->int_type1, 67 - epg->base + eic->irq_offset + EP93XX_INT_TYPE1_OFFSET); 90 + eic->base + EP93XX_INT_TYPE1_OFFSET); 68 91 69 92 writeb_relaxed(eic->int_unmasked & eic->int_enabled, 70 - epg->base + eic->irq_offset + EP93XX_INT_EN_OFFSET); 93 + eic->base + EP93XX_INT_EN_OFFSET); 71 94 } 72 95 73 96 static void ep93xx_gpio_int_debounce(struct gpio_chip *gc, 74 97 unsigned int offset, bool enable) 75 98 { 76 - struct ep93xx_gpio *epg = gpiochip_get_data(gc); 77 99 struct ep93xx_gpio_irq_chip *eic = to_ep93xx_gpio_irq_chip(gc); 78 100 int port_mask = BIT(offset); 79 101 ··· 80 106 else 81 107 eic->int_debounce &= ~port_mask; 82 108 83 - writeb(eic->int_debounce, 84 - epg->base + eic->irq_offset + EP93XX_INT_DEBOUNCE_OFFSET); 109 + writeb(eic->int_debounce, eic->base + EP93XX_INT_DEBOUNCE_OFFSET); 85 110 } 86 111 87 - static void ep93xx_gpio_ab_irq_handler(struct irq_desc *desc) 112 + static u32 ep93xx_gpio_ab_irq_handler(struct gpio_chip *gc) 88 113 { 89 - struct gpio_chip *gc = irq_desc_get_handler_data(desc); 90 - struct ep93xx_gpio *epg = gpiochip_get_data(gc); 91 - struct irq_chip *irqchip = irq_desc_get_chip(desc); 114 + struct ep93xx_gpio_irq_chip *eic = to_ep93xx_gpio_irq_chip(gc); 92 115 unsigned long stat; 93 116 int offset; 94 117 95 - chained_irq_enter(irqchip, desc); 96 - 97 - /* 98 - * Dispatch the IRQs to the irqdomain of each A and B 99 - * gpiochip irqdomains depending on what has fired. 100 - * The tricky part is that the IRQ line is shared 101 - * between bank A and B and each has their own gpiochip. 102 - */ 103 - stat = readb(epg->base + EP93XX_GPIO_A_INT_STATUS); 118 + stat = readb(eic->base + EP93XX_INT_STATUS_OFFSET); 104 119 for_each_set_bit(offset, &stat, 8) 105 - generic_handle_domain_irq(epg->gc[0].gc.irq.domain, 106 - offset); 120 + generic_handle_domain_irq(gc->irq.domain, offset); 107 121 108 - stat = readb(epg->base + EP93XX_GPIO_B_INT_STATUS); 109 - for_each_set_bit(offset, &stat, 8) 110 - generic_handle_domain_irq(epg->gc[1].gc.irq.domain, 111 - offset); 122 + return stat; 123 + } 112 124 113 - chained_irq_exit(irqchip, desc); 125 + static irqreturn_t ep93xx_ab_irq_handler(int irq, void *dev_id) 126 + { 127 + return IRQ_RETVAL(ep93xx_gpio_ab_irq_handler(dev_id)); 114 128 } 115 129 116 130 static void ep93xx_gpio_f_irq_handler(struct irq_desc *desc) 117 131 { 118 - /* 119 - * map discontiguous hw irq range to continuous sw irq range: 120 - * 121 - * IRQ_EP93XX_GPIO{0..7}MUX -> EP93XX_GPIO_LINE_F{0..7} 122 - */ 123 132 struct irq_chip *irqchip = irq_desc_get_chip(desc); 124 - unsigned int irq = irq_desc_get_irq(desc); 125 - int port_f_idx = (irq & 7) ^ 4; /* {20..23,48..51} -> {0..7} */ 126 - int gpio_irq = EP93XX_GPIO_F_IRQ_BASE + port_f_idx; 133 + struct gpio_chip *gc = irq_desc_get_handler_data(desc); 134 + struct gpio_irq_chip *gic = &gc->irq; 135 + unsigned int parent = irq_desc_get_irq(desc); 136 + unsigned int i; 127 137 128 138 chained_irq_enter(irqchip, desc); 129 - generic_handle_irq(gpio_irq); 139 + for (i = 0; i < gic->num_parents; i++) 140 + if (gic->parents[i] == parent) 141 + break; 142 + 143 + if (i < gic->num_parents) 144 + generic_handle_domain_irq(gc->irq.domain, i); 145 + 130 146 chained_irq_exit(irqchip, desc); 131 147 } 132 148 ··· 124 160 { 125 161 struct gpio_chip *gc = irq_data_get_irq_chip_data(d); 126 162 struct ep93xx_gpio_irq_chip *eic = to_ep93xx_gpio_irq_chip(gc); 127 - struct ep93xx_gpio *epg = gpiochip_get_data(gc); 128 - int port_mask = BIT(d->irq & 7); 163 + int port_mask = BIT(irqd_to_hwirq(d)); 129 164 130 165 if (irqd_get_trigger_type(d) == IRQ_TYPE_EDGE_BOTH) { 131 166 eic->int_type2 ^= port_mask; /* switch edge direction */ 132 - ep93xx_gpio_update_int_params(epg, eic); 167 + ep93xx_gpio_update_int_params(eic); 133 168 } 134 169 135 - writeb(port_mask, epg->base + eic->irq_offset + EP93XX_INT_EOI_OFFSET); 170 + writeb(port_mask, eic->base + EP93XX_INT_EOI_OFFSET); 136 171 } 137 172 138 173 static void ep93xx_gpio_irq_mask_ack(struct irq_data *d) 139 174 { 140 175 struct gpio_chip *gc = irq_data_get_irq_chip_data(d); 141 176 struct ep93xx_gpio_irq_chip *eic = to_ep93xx_gpio_irq_chip(gc); 142 - struct ep93xx_gpio *epg = gpiochip_get_data(gc); 143 - int port_mask = BIT(d->irq & 7); 177 + int port_mask = BIT(irqd_to_hwirq(d)); 144 178 145 179 if (irqd_get_trigger_type(d) == IRQ_TYPE_EDGE_BOTH) 146 180 eic->int_type2 ^= port_mask; /* switch edge direction */ 147 181 148 182 eic->int_unmasked &= ~port_mask; 149 - ep93xx_gpio_update_int_params(epg, eic); 183 + ep93xx_gpio_update_int_params(eic); 150 184 151 - writeb(port_mask, epg->base + eic->irq_offset + EP93XX_INT_EOI_OFFSET); 185 + writeb(port_mask, eic->base + EP93XX_INT_EOI_OFFSET); 152 186 gpiochip_disable_irq(gc, irqd_to_hwirq(d)); 153 187 } 154 188 ··· 154 192 { 155 193 struct gpio_chip *gc = irq_data_get_irq_chip_data(d); 156 194 struct ep93xx_gpio_irq_chip *eic = to_ep93xx_gpio_irq_chip(gc); 157 - struct ep93xx_gpio *epg = gpiochip_get_data(gc); 158 195 159 - eic->int_unmasked &= ~BIT(d->irq & 7); 160 - ep93xx_gpio_update_int_params(epg, eic); 196 + eic->int_unmasked &= ~BIT(irqd_to_hwirq(d)); 197 + ep93xx_gpio_update_int_params(eic); 161 198 gpiochip_disable_irq(gc, irqd_to_hwirq(d)); 162 199 } 163 200 ··· 164 203 { 165 204 struct gpio_chip *gc = irq_data_get_irq_chip_data(d); 166 205 struct ep93xx_gpio_irq_chip *eic = to_ep93xx_gpio_irq_chip(gc); 167 - struct ep93xx_gpio *epg = gpiochip_get_data(gc); 168 206 169 207 gpiochip_enable_irq(gc, irqd_to_hwirq(d)); 170 - eic->int_unmasked |= BIT(d->irq & 7); 171 - ep93xx_gpio_update_int_params(epg, eic); 208 + eic->int_unmasked |= BIT(irqd_to_hwirq(d)); 209 + ep93xx_gpio_update_int_params(eic); 172 210 } 173 211 174 212 /* ··· 179 219 { 180 220 struct gpio_chip *gc = irq_data_get_irq_chip_data(d); 181 221 struct ep93xx_gpio_irq_chip *eic = to_ep93xx_gpio_irq_chip(gc); 182 - struct ep93xx_gpio *epg = gpiochip_get_data(gc); 183 - int offset = d->irq & 7; 222 + irq_hw_number_t offset = irqd_to_hwirq(d); 184 223 int port_mask = BIT(offset); 185 224 irq_flow_handler_t handler; 186 225 ··· 223 264 224 265 eic->int_enabled |= port_mask; 225 266 226 - ep93xx_gpio_update_int_params(epg, eic); 267 + ep93xx_gpio_update_int_params(eic); 227 268 228 269 return 0; 229 270 } 230 - 231 - /************************************************************************* 232 - * gpiolib interface for EP93xx on-chip GPIOs 233 - *************************************************************************/ 234 - struct ep93xx_gpio_bank { 235 - const char *label; 236 - int data; 237 - int dir; 238 - int irq; 239 - int base; 240 - bool has_irq; 241 - bool has_hierarchical_irq; 242 - unsigned int irq_base; 243 - }; 244 - 245 - #define EP93XX_GPIO_BANK(_label, _data, _dir, _irq, _base, _has_irq, _has_hier, _irq_base) \ 246 - { \ 247 - .label = _label, \ 248 - .data = _data, \ 249 - .dir = _dir, \ 250 - .irq = _irq, \ 251 - .base = _base, \ 252 - .has_irq = _has_irq, \ 253 - .has_hierarchical_irq = _has_hier, \ 254 - .irq_base = _irq_base, \ 255 - } 256 - 257 - static struct ep93xx_gpio_bank ep93xx_gpio_banks[] = { 258 - /* Bank A has 8 IRQs */ 259 - EP93XX_GPIO_BANK("A", 0x00, 0x10, 0x90, 0, true, false, EP93XX_GPIO_A_IRQ_BASE), 260 - /* Bank B has 8 IRQs */ 261 - EP93XX_GPIO_BANK("B", 0x04, 0x14, 0xac, 8, true, false, EP93XX_GPIO_B_IRQ_BASE), 262 - EP93XX_GPIO_BANK("C", 0x08, 0x18, 0x00, 40, false, false, 0), 263 - EP93XX_GPIO_BANK("D", 0x0c, 0x1c, 0x00, 24, false, false, 0), 264 - EP93XX_GPIO_BANK("E", 0x20, 0x24, 0x00, 32, false, false, 0), 265 - /* Bank F has 8 IRQs */ 266 - EP93XX_GPIO_BANK("F", 0x30, 0x34, 0x4c, 16, false, true, EP93XX_GPIO_F_IRQ_BASE), 267 - EP93XX_GPIO_BANK("G", 0x38, 0x3c, 0x00, 48, false, false, 0), 268 - EP93XX_GPIO_BANK("H", 0x40, 0x44, 0x00, 56, false, false, 0), 269 - }; 270 271 271 272 static int ep93xx_gpio_set_config(struct gpio_chip *gc, unsigned offset, 272 273 unsigned long config) ··· 261 342 GPIOCHIP_IRQ_RESOURCE_HELPERS, 262 343 }; 263 344 264 - static int ep93xx_gpio_add_bank(struct ep93xx_gpio_chip *egc, 265 - struct platform_device *pdev, 266 - struct ep93xx_gpio *epg, 267 - struct ep93xx_gpio_bank *bank) 345 + static int ep93xx_setup_irqs(struct platform_device *pdev, 346 + struct ep93xx_gpio_chip *egc) 268 347 { 269 - void __iomem *data = epg->base + bank->data; 270 - void __iomem *dir = epg->base + bank->dir; 271 348 struct gpio_chip *gc = &egc->gc; 272 349 struct device *dev = &pdev->dev; 273 - struct gpio_irq_chip *girq; 274 - int err; 350 + struct gpio_irq_chip *girq = &gc->irq; 351 + int ret, irq, i; 352 + void __iomem *intr; 275 353 276 - err = bgpio_init(gc, dev, 1, data, NULL, NULL, dir, NULL, 0); 277 - if (err) 278 - return err; 354 + intr = devm_platform_ioremap_resource_byname(pdev, "intr"); 355 + if (IS_ERR(intr)) 356 + return PTR_ERR(intr); 279 357 280 - gc->label = bank->label; 281 - gc->base = bank->base; 358 + gc->set_config = ep93xx_gpio_set_config; 359 + egc->eic = devm_kzalloc(dev, sizeof(*egc->eic), GFP_KERNEL); 360 + if (!egc->eic) 361 + return -ENOMEM; 282 362 283 - girq = &gc->irq; 284 - if (bank->has_irq || bank->has_hierarchical_irq) { 285 - gc->set_config = ep93xx_gpio_set_config; 286 - egc->eic = devm_kcalloc(dev, 1, 287 - sizeof(*egc->eic), 288 - GFP_KERNEL); 289 - if (!egc->eic) 290 - return -ENOMEM; 291 - egc->eic->irq_offset = bank->irq; 292 - gpio_irq_chip_set_chip(girq, &gpio_eic_irq_chip); 293 - } 363 + egc->eic->base = intr; 364 + gpio_irq_chip_set_chip(girq, &gpio_eic_irq_chip); 365 + girq->num_parents = platform_irq_count(pdev); 366 + if (girq->num_parents == 0) 367 + return -EINVAL; 294 368 295 - if (bank->has_irq) { 296 - int ab_parent_irq = platform_get_irq(pdev, 0); 369 + girq->parents = devm_kcalloc(dev, girq->num_parents, 370 + sizeof(*girq->parents), 371 + GFP_KERNEL); 372 + if (!girq->parents) 373 + return -ENOMEM; 297 374 298 - girq->parent_handler = ep93xx_gpio_ab_irq_handler; 299 - girq->num_parents = 1; 300 - girq->parents = devm_kcalloc(dev, girq->num_parents, 301 - sizeof(*girq->parents), 302 - GFP_KERNEL); 303 - if (!girq->parents) 304 - return -ENOMEM; 305 - girq->default_type = IRQ_TYPE_NONE; 306 - girq->handler = handle_level_irq; 307 - girq->parents[0] = ab_parent_irq; 308 - girq->first = bank->irq_base; 309 - } 375 + if (girq->num_parents == 1) { /* A/B irqchips */ 376 + irq = platform_get_irq(pdev, 0); 377 + if (irq < 0) 378 + return irq; 310 379 311 - /* Only bank F has especially funky IRQ handling */ 312 - if (bank->has_hierarchical_irq) { 313 - int gpio_irq; 314 - int i; 380 + ret = devm_request_irq(dev, irq, ep93xx_ab_irq_handler, 381 + IRQF_SHARED, gc->label, gc); 382 + if (ret) 383 + return dev_err_probe(dev, ret, "requesting IRQ: %d\n", irq); 315 384 316 - /* 317 - * FIXME: convert this to use hierarchical IRQ support! 318 - * this requires fixing the root irqchip to be hierarchical. 319 - */ 385 + girq->parents[0] = irq; 386 + } else { /* F irqchip */ 320 387 girq->parent_handler = ep93xx_gpio_f_irq_handler; 321 - girq->num_parents = 8; 322 - girq->parents = devm_kcalloc(dev, girq->num_parents, 323 - sizeof(*girq->parents), 324 - GFP_KERNEL); 325 - if (!girq->parents) 326 - return -ENOMEM; 327 - /* Pick resources 1..8 for these IRQs */ 388 + 328 389 for (i = 0; i < girq->num_parents; i++) { 329 - girq->parents[i] = platform_get_irq(pdev, i + 1); 330 - gpio_irq = bank->irq_base + i; 331 - irq_set_chip_data(gpio_irq, &epg->gc[5]); 332 - irq_set_chip_and_handler(gpio_irq, 333 - girq->chip, 334 - handle_level_irq); 335 - irq_clear_status_flags(gpio_irq, IRQ_NOREQUEST); 390 + irq = platform_get_irq(pdev, i); 391 + if (irq < 0) 392 + continue; 393 + 394 + girq->parents[i] = irq; 336 395 } 337 - girq->default_type = IRQ_TYPE_NONE; 338 - girq->handler = handle_level_irq; 339 - girq->first = bank->irq_base; 396 + 397 + girq->map = girq->parents; 340 398 } 341 399 342 - return devm_gpiochip_add_data(dev, gc, epg); 400 + girq->default_type = IRQ_TYPE_NONE; 401 + /* TODO: replace with handle_bad_irq() once we are fully hierarchical */ 402 + girq->handler = handle_simple_irq; 403 + 404 + return 0; 343 405 } 344 406 345 407 static int ep93xx_gpio_probe(struct platform_device *pdev) 346 408 { 347 - struct ep93xx_gpio *epg; 348 - int i; 409 + struct ep93xx_gpio_chip *egc; 410 + struct gpio_chip *gc; 411 + void __iomem *data; 412 + void __iomem *dir; 413 + int ret; 349 414 350 - epg = devm_kzalloc(&pdev->dev, sizeof(*epg), GFP_KERNEL); 351 - if (!epg) 415 + egc = devm_kzalloc(&pdev->dev, sizeof(*egc), GFP_KERNEL); 416 + if (!egc) 352 417 return -ENOMEM; 353 418 354 - epg->base = devm_platform_ioremap_resource(pdev, 0); 355 - if (IS_ERR(epg->base)) 356 - return PTR_ERR(epg->base); 419 + data = devm_platform_ioremap_resource_byname(pdev, "data"); 420 + if (IS_ERR(data)) 421 + return PTR_ERR(data); 357 422 358 - for (i = 0; i < ARRAY_SIZE(ep93xx_gpio_banks); i++) { 359 - struct ep93xx_gpio_chip *gc = &epg->gc[i]; 360 - struct ep93xx_gpio_bank *bank = &ep93xx_gpio_banks[i]; 423 + dir = devm_platform_ioremap_resource_byname(pdev, "dir"); 424 + if (IS_ERR(dir)) 425 + return PTR_ERR(dir); 361 426 362 - if (ep93xx_gpio_add_bank(gc, pdev, epg, bank)) 363 - dev_warn(&pdev->dev, "Unable to add gpio bank %s\n", 364 - bank->label); 427 + gc = &egc->gc; 428 + ret = bgpio_init(gc, &pdev->dev, 1, data, NULL, NULL, dir, NULL, 0); 429 + if (ret) 430 + return dev_err_probe(&pdev->dev, ret, "unable to init generic GPIO\n"); 431 + 432 + gc->label = dev_name(&pdev->dev); 433 + if (platform_irq_count(pdev) > 0) { 434 + dev_dbg(&pdev->dev, "setting up irqs for %s\n", dev_name(&pdev->dev)); 435 + ret = ep93xx_setup_irqs(pdev, egc); 436 + if (ret) 437 + dev_err_probe(&pdev->dev, ret, "setup irqs failed"); 365 438 } 366 439 367 - return 0; 440 + return devm_gpiochip_add_data(&pdev->dev, gc, egc); 368 441 } 369 442 370 443 static struct platform_driver ep93xx_gpio_driver = {