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

Merge branch 'ib-ingenic' into devel

+487 -470
-46
Documentation/devicetree/bindings/gpio/ingenic,gpio.txt
··· 1 - Ingenic jz47xx GPIO controller 2 - 3 - That the Ingenic GPIO driver node must be a sub-node of the Ingenic pinctrl 4 - driver node. 5 - 6 - Required properties: 7 - -------------------- 8 - 9 - - compatible: Must contain one of: 10 - - "ingenic,jz4740-gpio" 11 - - "ingenic,jz4770-gpio" 12 - - "ingenic,jz4780-gpio" 13 - - reg: The GPIO bank number. 14 - - interrupt-controller: Marks the device node as an interrupt controller. 15 - - interrupts: Interrupt specifier for the controllers interrupt. 16 - - #interrupt-cells: Should be 2. Refer to 17 - ../interrupt-controller/interrupts.txt for more details. 18 - - gpio-controller: Marks the device node as a GPIO controller. 19 - - #gpio-cells: Should be 2. The first cell is the GPIO number and the second 20 - cell specifies GPIO flags, as defined in <dt-bindings/gpio/gpio.h>. Only the 21 - GPIO_ACTIVE_HIGH and GPIO_ACTIVE_LOW flags are supported. 22 - - gpio-ranges: Range of pins managed by the GPIO controller. Refer to 23 - 'gpio.txt' in this directory for more details. 24 - 25 - Example: 26 - -------- 27 - 28 - &pinctrl { 29 - #address-cells = <1>; 30 - #size-cells = <0>; 31 - 32 - gpa: gpio@0 { 33 - compatible = "ingenic,jz4740-gpio"; 34 - reg = <0>; 35 - 36 - gpio-controller; 37 - gpio-ranges = <&pinctrl 0 0 32>; 38 - #gpio-cells = <2>; 39 - 40 - interrupt-controller; 41 - #interrupt-cells = <2>; 42 - 43 - interrupt-parent = <&intc>; 44 - interrupts = <28>; 45 - }; 46 - };
+35 -4
Documentation/devicetree/bindings/pinctrl/ingenic,pinctrl.txt
··· 20 20 21 21 - compatible: One of: 22 22 - "ingenic,jz4740-pinctrl" 23 + - "ingenic,jz4725b-pinctrl" 23 24 - "ingenic,jz4770-pinctrl" 24 25 - "ingenic,jz4780-pinctrl" 25 26 - reg: Address range of the pinctrl registers. 26 27 27 28 28 - GPIO sub-nodes 29 - -------------- 29 + Required properties for sub-nodes (GPIO chips): 30 + ----------------------------------------------- 30 31 31 - The pinctrl node can have optional sub-nodes for the Ingenic GPIO driver; 32 - please refer to ../gpio/ingenic,gpio.txt. 32 + - compatible: Must contain one of: 33 + - "ingenic,jz4740-gpio" 34 + - "ingenic,jz4770-gpio" 35 + - "ingenic,jz4780-gpio" 36 + - reg: The GPIO bank number. 37 + - interrupt-controller: Marks the device node as an interrupt controller. 38 + - interrupts: Interrupt specifier for the controllers interrupt. 39 + - #interrupt-cells: Should be 2. Refer to 40 + ../interrupt-controller/interrupts.txt for more details. 41 + - gpio-controller: Marks the device node as a GPIO controller. 42 + - #gpio-cells: Should be 2. The first cell is the GPIO number and the second 43 + cell specifies GPIO flags, as defined in <dt-bindings/gpio/gpio.h>. Only the 44 + GPIO_ACTIVE_HIGH and GPIO_ACTIVE_LOW flags are supported. 45 + - gpio-ranges: Range of pins managed by the GPIO controller. Refer to 46 + ../gpio/gpio.txt for more details. 33 47 34 48 35 49 Example: ··· 52 38 pinctrl: pin-controller@10010000 { 53 39 compatible = "ingenic,jz4740-pinctrl"; 54 40 reg = <0x10010000 0x400>; 41 + #address-cells = <1>; 42 + #size-cells = <0>; 43 + 44 + gpa: gpio@0 { 45 + compatible = "ingenic,jz4740-gpio"; 46 + reg = <0>; 47 + 48 + gpio-controller; 49 + gpio-ranges = <&pinctrl 0 0 32>; 50 + #gpio-cells = <2>; 51 + 52 + interrupt-controller; 53 + #interrupt-cells = <2>; 54 + 55 + interrupt-parent = <&intc>; 56 + interrupts = <28>; 57 + }; 55 58 };
-11
drivers/gpio/Kconfig
··· 267 267 268 268 If unsure, say N. 269 269 270 - config GPIO_INGENIC 271 - tristate "Ingenic JZ47xx SoCs GPIO support" 272 - depends on OF 273 - depends on MACH_INGENIC || COMPILE_TEST 274 - select GPIOLIB_IRQCHIP 275 - help 276 - Say yes here to support the GPIO functionality present on the 277 - JZ4740 and JZ4780 SoCs from Ingenic. 278 - 279 - If unsure, say N. 280 - 281 270 config GPIO_IOP 282 271 tristate "Intel IOP GPIO" 283 272 depends on ARCH_IOP32X || ARCH_IOP33X || COMPILE_TEST
-1
drivers/gpio/Makefile
··· 57 57 obj-$(CONFIG_GPIO_HLWD) += gpio-hlwd.o 58 58 obj-$(CONFIG_HTC_EGPIO) += gpio-htc-egpio.o 59 59 obj-$(CONFIG_GPIO_ICH) += gpio-ich.o 60 - obj-$(CONFIG_GPIO_INGENIC) += gpio-ingenic.o 61 60 obj-$(CONFIG_GPIO_IOP) += gpio-iop.o 62 61 obj-$(CONFIG_GPIO_IT87) += gpio-it87.o 63 62 obj-$(CONFIG_GPIO_JANZ_TTL) += gpio-janz-ttl.o
-392
drivers/gpio/gpio-ingenic.c
··· 1 - /* 2 - * Ingenic JZ47xx GPIO driver 3 - * 4 - * Copyright (c) 2017 Paul Cercueil <paul@crapouillou.net> 5 - * 6 - * License terms: GNU General Public License (GPL) version 2 7 - */ 8 - 9 - #include <linux/gpio/driver.h> 10 - #include <linux/interrupt.h> 11 - #include <linux/io.h> 12 - #include <linux/module.h> 13 - #include <linux/of_address.h> 14 - #include <linux/of_device.h> 15 - #include <linux/of_irq.h> 16 - #include <linux/pinctrl/consumer.h> 17 - #include <linux/regmap.h> 18 - 19 - #define GPIO_PIN 0x00 20 - #define GPIO_MSK 0x20 21 - 22 - #define JZ4740_GPIO_DATA 0x10 23 - #define JZ4740_GPIO_SELECT 0x50 24 - #define JZ4740_GPIO_DIR 0x60 25 - #define JZ4740_GPIO_TRIG 0x70 26 - #define JZ4740_GPIO_FLAG 0x80 27 - 28 - #define JZ4770_GPIO_INT 0x10 29 - #define JZ4770_GPIO_PAT1 0x30 30 - #define JZ4770_GPIO_PAT0 0x40 31 - #define JZ4770_GPIO_FLAG 0x50 32 - 33 - #define REG_SET(x) ((x) + 0x4) 34 - #define REG_CLEAR(x) ((x) + 0x8) 35 - 36 - enum jz_version { 37 - ID_JZ4740, 38 - ID_JZ4770, 39 - ID_JZ4780, 40 - }; 41 - 42 - struct ingenic_gpio_chip { 43 - struct regmap *map; 44 - struct gpio_chip gc; 45 - struct irq_chip irq_chip; 46 - unsigned int irq, reg_base; 47 - enum jz_version version; 48 - }; 49 - 50 - static u32 gpio_ingenic_read_reg(struct ingenic_gpio_chip *jzgc, u8 reg) 51 - { 52 - unsigned int val; 53 - 54 - regmap_read(jzgc->map, jzgc->reg_base + reg, &val); 55 - 56 - return (u32) val; 57 - } 58 - 59 - static void gpio_ingenic_set_bit(struct ingenic_gpio_chip *jzgc, 60 - u8 reg, u8 offset, bool set) 61 - { 62 - if (set) 63 - reg = REG_SET(reg); 64 - else 65 - reg = REG_CLEAR(reg); 66 - 67 - regmap_write(jzgc->map, jzgc->reg_base + reg, BIT(offset)); 68 - } 69 - 70 - static inline bool gpio_get_value(struct ingenic_gpio_chip *jzgc, u8 offset) 71 - { 72 - unsigned int val = gpio_ingenic_read_reg(jzgc, GPIO_PIN); 73 - 74 - return !!(val & BIT(offset)); 75 - } 76 - 77 - static void gpio_set_value(struct ingenic_gpio_chip *jzgc, u8 offset, int value) 78 - { 79 - if (jzgc->version >= ID_JZ4770) 80 - gpio_ingenic_set_bit(jzgc, JZ4770_GPIO_PAT0, offset, !!value); 81 - else 82 - gpio_ingenic_set_bit(jzgc, JZ4740_GPIO_DATA, offset, !!value); 83 - } 84 - 85 - static void irq_set_type(struct ingenic_gpio_chip *jzgc, 86 - u8 offset, unsigned int type) 87 - { 88 - u8 reg1, reg2; 89 - 90 - if (jzgc->version >= ID_JZ4770) { 91 - reg1 = JZ4770_GPIO_PAT1; 92 - reg2 = JZ4770_GPIO_PAT0; 93 - } else { 94 - reg1 = JZ4740_GPIO_TRIG; 95 - reg2 = JZ4740_GPIO_DIR; 96 - } 97 - 98 - switch (type) { 99 - case IRQ_TYPE_EDGE_RISING: 100 - gpio_ingenic_set_bit(jzgc, reg2, offset, true); 101 - gpio_ingenic_set_bit(jzgc, reg1, offset, true); 102 - break; 103 - case IRQ_TYPE_EDGE_FALLING: 104 - gpio_ingenic_set_bit(jzgc, reg2, offset, false); 105 - gpio_ingenic_set_bit(jzgc, reg1, offset, true); 106 - break; 107 - case IRQ_TYPE_LEVEL_HIGH: 108 - gpio_ingenic_set_bit(jzgc, reg2, offset, true); 109 - gpio_ingenic_set_bit(jzgc, reg1, offset, false); 110 - break; 111 - case IRQ_TYPE_LEVEL_LOW: 112 - default: 113 - gpio_ingenic_set_bit(jzgc, reg2, offset, false); 114 - gpio_ingenic_set_bit(jzgc, reg1, offset, false); 115 - break; 116 - } 117 - } 118 - 119 - static void ingenic_gpio_irq_mask(struct irq_data *irqd) 120 - { 121 - struct gpio_chip *gc = irq_data_get_irq_chip_data(irqd); 122 - struct ingenic_gpio_chip *jzgc = gpiochip_get_data(gc); 123 - 124 - gpio_ingenic_set_bit(jzgc, GPIO_MSK, irqd->hwirq, true); 125 - } 126 - 127 - static void ingenic_gpio_irq_unmask(struct irq_data *irqd) 128 - { 129 - struct gpio_chip *gc = irq_data_get_irq_chip_data(irqd); 130 - struct ingenic_gpio_chip *jzgc = gpiochip_get_data(gc); 131 - 132 - gpio_ingenic_set_bit(jzgc, GPIO_MSK, irqd->hwirq, false); 133 - } 134 - 135 - static void ingenic_gpio_irq_enable(struct irq_data *irqd) 136 - { 137 - struct gpio_chip *gc = irq_data_get_irq_chip_data(irqd); 138 - struct ingenic_gpio_chip *jzgc = gpiochip_get_data(gc); 139 - int irq = irqd->hwirq; 140 - 141 - if (jzgc->version >= ID_JZ4770) 142 - gpio_ingenic_set_bit(jzgc, JZ4770_GPIO_INT, irq, true); 143 - else 144 - gpio_ingenic_set_bit(jzgc, JZ4740_GPIO_SELECT, irq, true); 145 - 146 - ingenic_gpio_irq_unmask(irqd); 147 - } 148 - 149 - static void ingenic_gpio_irq_disable(struct irq_data *irqd) 150 - { 151 - struct gpio_chip *gc = irq_data_get_irq_chip_data(irqd); 152 - struct ingenic_gpio_chip *jzgc = gpiochip_get_data(gc); 153 - int irq = irqd->hwirq; 154 - 155 - ingenic_gpio_irq_mask(irqd); 156 - 157 - if (jzgc->version >= ID_JZ4770) 158 - gpio_ingenic_set_bit(jzgc, JZ4770_GPIO_INT, irq, false); 159 - else 160 - gpio_ingenic_set_bit(jzgc, JZ4740_GPIO_SELECT, irq, false); 161 - } 162 - 163 - static void ingenic_gpio_irq_ack(struct irq_data *irqd) 164 - { 165 - struct gpio_chip *gc = irq_data_get_irq_chip_data(irqd); 166 - struct ingenic_gpio_chip *jzgc = gpiochip_get_data(gc); 167 - int irq = irqd->hwirq; 168 - bool high; 169 - 170 - if (irqd_get_trigger_type(irqd) == IRQ_TYPE_EDGE_BOTH) { 171 - /* 172 - * Switch to an interrupt for the opposite edge to the one that 173 - * triggered the interrupt being ACKed. 174 - */ 175 - high = gpio_get_value(jzgc, irq); 176 - if (high) 177 - irq_set_type(jzgc, irq, IRQ_TYPE_EDGE_FALLING); 178 - else 179 - irq_set_type(jzgc, irq, IRQ_TYPE_EDGE_RISING); 180 - } 181 - 182 - if (jzgc->version >= ID_JZ4770) 183 - gpio_ingenic_set_bit(jzgc, JZ4770_GPIO_FLAG, irq, false); 184 - else 185 - gpio_ingenic_set_bit(jzgc, JZ4740_GPIO_DATA, irq, true); 186 - } 187 - 188 - static int ingenic_gpio_irq_set_type(struct irq_data *irqd, unsigned int type) 189 - { 190 - struct gpio_chip *gc = irq_data_get_irq_chip_data(irqd); 191 - struct ingenic_gpio_chip *jzgc = gpiochip_get_data(gc); 192 - 193 - switch (type) { 194 - case IRQ_TYPE_EDGE_BOTH: 195 - case IRQ_TYPE_EDGE_RISING: 196 - case IRQ_TYPE_EDGE_FALLING: 197 - irq_set_handler_locked(irqd, handle_edge_irq); 198 - break; 199 - case IRQ_TYPE_LEVEL_HIGH: 200 - case IRQ_TYPE_LEVEL_LOW: 201 - irq_set_handler_locked(irqd, handle_level_irq); 202 - break; 203 - default: 204 - irq_set_handler_locked(irqd, handle_bad_irq); 205 - } 206 - 207 - if (type == IRQ_TYPE_EDGE_BOTH) { 208 - /* 209 - * The hardware does not support interrupts on both edges. The 210 - * best we can do is to set up a single-edge interrupt and then 211 - * switch to the opposing edge when ACKing the interrupt. 212 - */ 213 - bool high = gpio_get_value(jzgc, irqd->hwirq); 214 - 215 - type = high ? IRQ_TYPE_EDGE_FALLING : IRQ_TYPE_EDGE_RISING; 216 - } 217 - 218 - irq_set_type(jzgc, irqd->hwirq, type); 219 - return 0; 220 - } 221 - 222 - static int ingenic_gpio_irq_set_wake(struct irq_data *irqd, unsigned int on) 223 - { 224 - struct gpio_chip *gc = irq_data_get_irq_chip_data(irqd); 225 - struct ingenic_gpio_chip *jzgc = gpiochip_get_data(gc); 226 - 227 - return irq_set_irq_wake(jzgc->irq, on); 228 - } 229 - 230 - static void ingenic_gpio_irq_handler(struct irq_desc *desc) 231 - { 232 - struct gpio_chip *gc = irq_desc_get_handler_data(desc); 233 - struct ingenic_gpio_chip *jzgc = gpiochip_get_data(gc); 234 - struct irq_chip *irq_chip = irq_data_get_irq_chip(&desc->irq_data); 235 - unsigned long flag, i; 236 - 237 - chained_irq_enter(irq_chip, desc); 238 - 239 - if (jzgc->version >= ID_JZ4770) 240 - flag = gpio_ingenic_read_reg(jzgc, JZ4770_GPIO_FLAG); 241 - else 242 - flag = gpio_ingenic_read_reg(jzgc, JZ4740_GPIO_FLAG); 243 - 244 - for_each_set_bit(i, &flag, 32) 245 - generic_handle_irq(irq_linear_revmap(gc->irq.domain, i)); 246 - chained_irq_exit(irq_chip, desc); 247 - } 248 - 249 - static void ingenic_gpio_set(struct gpio_chip *gc, 250 - unsigned int offset, int value) 251 - { 252 - struct ingenic_gpio_chip *jzgc = gpiochip_get_data(gc); 253 - 254 - gpio_set_value(jzgc, offset, value); 255 - } 256 - 257 - static int ingenic_gpio_get(struct gpio_chip *gc, unsigned int offset) 258 - { 259 - struct ingenic_gpio_chip *jzgc = gpiochip_get_data(gc); 260 - 261 - return (int) gpio_get_value(jzgc, offset); 262 - } 263 - 264 - static int ingenic_gpio_direction_input(struct gpio_chip *gc, 265 - unsigned int offset) 266 - { 267 - return pinctrl_gpio_direction_input(gc->base + offset); 268 - } 269 - 270 - static int ingenic_gpio_direction_output(struct gpio_chip *gc, 271 - unsigned int offset, int value) 272 - { 273 - ingenic_gpio_set(gc, offset, value); 274 - return pinctrl_gpio_direction_output(gc->base + offset); 275 - } 276 - 277 - static const struct of_device_id ingenic_gpio_of_match[] = { 278 - { .compatible = "ingenic,jz4740-gpio", .data = (void *)ID_JZ4740 }, 279 - { .compatible = "ingenic,jz4770-gpio", .data = (void *)ID_JZ4770 }, 280 - { .compatible = "ingenic,jz4780-gpio", .data = (void *)ID_JZ4780 }, 281 - {}, 282 - }; 283 - MODULE_DEVICE_TABLE(of, ingenic_gpio_of_match); 284 - 285 - static int ingenic_gpio_probe(struct platform_device *pdev) 286 - { 287 - struct device *dev = &pdev->dev; 288 - struct ingenic_gpio_chip *jzgc; 289 - u32 bank; 290 - int err; 291 - 292 - jzgc = devm_kzalloc(dev, sizeof(*jzgc), GFP_KERNEL); 293 - if (!jzgc) 294 - return -ENOMEM; 295 - 296 - jzgc->map = dev_get_drvdata(dev->parent); 297 - if (!jzgc->map) { 298 - dev_err(dev, "Cannot get parent regmap\n"); 299 - return -ENXIO; 300 - } 301 - 302 - err = of_property_read_u32(dev->of_node, "reg", &bank); 303 - if (err) { 304 - dev_err(dev, "Cannot read \"reg\" property: %i\n", err); 305 - return err; 306 - } 307 - 308 - jzgc->reg_base = bank * 0x100; 309 - 310 - jzgc->gc.label = devm_kasprintf(dev, GFP_KERNEL, "GPIO%c", 'A' + bank); 311 - if (!jzgc->gc.label) 312 - return -ENOMEM; 313 - 314 - /* DO NOT EXPAND THIS: FOR BACKWARD GPIO NUMBERSPACE COMPATIBIBILITY 315 - * ONLY: WORK TO TRANSITION CONSUMERS TO USE THE GPIO DESCRIPTOR API IN 316 - * <linux/gpio/consumer.h> INSTEAD. 317 - */ 318 - jzgc->gc.base = bank * 32; 319 - 320 - jzgc->gc.ngpio = 32; 321 - jzgc->gc.parent = dev; 322 - jzgc->gc.of_node = dev->of_node; 323 - jzgc->gc.owner = THIS_MODULE; 324 - jzgc->version = (enum jz_version)of_device_get_match_data(dev); 325 - 326 - jzgc->gc.set = ingenic_gpio_set; 327 - jzgc->gc.get = ingenic_gpio_get; 328 - jzgc->gc.direction_input = ingenic_gpio_direction_input; 329 - jzgc->gc.direction_output = ingenic_gpio_direction_output; 330 - 331 - if (of_property_read_bool(dev->of_node, "gpio-ranges")) { 332 - jzgc->gc.request = gpiochip_generic_request; 333 - jzgc->gc.free = gpiochip_generic_free; 334 - } 335 - 336 - err = devm_gpiochip_add_data(dev, &jzgc->gc, jzgc); 337 - if (err) 338 - return err; 339 - 340 - jzgc->irq = irq_of_parse_and_map(dev->of_node, 0); 341 - if (!jzgc->irq) 342 - return -EINVAL; 343 - 344 - jzgc->irq_chip.name = jzgc->gc.label; 345 - jzgc->irq_chip.irq_enable = ingenic_gpio_irq_enable; 346 - jzgc->irq_chip.irq_disable = ingenic_gpio_irq_disable; 347 - jzgc->irq_chip.irq_unmask = ingenic_gpio_irq_unmask; 348 - jzgc->irq_chip.irq_mask = ingenic_gpio_irq_mask; 349 - jzgc->irq_chip.irq_ack = ingenic_gpio_irq_ack; 350 - jzgc->irq_chip.irq_set_type = ingenic_gpio_irq_set_type; 351 - jzgc->irq_chip.irq_set_wake = ingenic_gpio_irq_set_wake; 352 - jzgc->irq_chip.flags = IRQCHIP_MASK_ON_SUSPEND; 353 - 354 - err = gpiochip_irqchip_add(&jzgc->gc, &jzgc->irq_chip, 0, 355 - handle_level_irq, IRQ_TYPE_NONE); 356 - if (err) 357 - return err; 358 - 359 - gpiochip_set_chained_irqchip(&jzgc->gc, &jzgc->irq_chip, 360 - jzgc->irq, ingenic_gpio_irq_handler); 361 - return 0; 362 - } 363 - 364 - static int ingenic_gpio_remove(struct platform_device *pdev) 365 - { 366 - return 0; 367 - } 368 - 369 - static struct platform_driver ingenic_gpio_driver = { 370 - .driver = { 371 - .name = "gpio-ingenic", 372 - .of_match_table = of_match_ptr(ingenic_gpio_of_match), 373 - }, 374 - .probe = ingenic_gpio_probe, 375 - .remove = ingenic_gpio_remove, 376 - }; 377 - 378 - static int __init ingenic_gpio_drv_register(void) 379 - { 380 - return platform_driver_register(&ingenic_gpio_driver); 381 - } 382 - subsys_initcall(ingenic_gpio_drv_register); 383 - 384 - static void __exit ingenic_gpio_drv_unregister(void) 385 - { 386 - platform_driver_unregister(&ingenic_gpio_driver); 387 - } 388 - module_exit(ingenic_gpio_drv_unregister); 389 - 390 - MODULE_AUTHOR("Paul Cercueil <paul@crapouillou.net>"); 391 - MODULE_DESCRIPTION("Ingenic JZ47xx GPIO driver"); 392 - MODULE_LICENSE("GPL");
+4 -2
drivers/pinctrl/Kconfig
··· 309 309 310 310 config PINCTRL_INGENIC 311 311 bool "Pinctrl driver for the Ingenic JZ47xx SoCs" 312 - default y 312 + default MACH_INGENIC 313 313 depends on OF 314 - depends on MACH_INGENIC || COMPILE_TEST 314 + depends on MIPS || COMPILE_TEST 315 315 select GENERIC_PINCONF 316 316 select GENERIC_PINCTRL_GROUPS 317 317 select GENERIC_PINMUX_FUNCTIONS 318 + select GPIOLIB 319 + select GPIOLIB_IRQCHIP 318 320 select REGMAP_MMIO 319 321 320 322 config PINCTRL_RK805
+448 -14
drivers/pinctrl/pinctrl-ingenic.c
··· 7 7 */ 8 8 9 9 #include <linux/compiler.h> 10 - #include <linux/gpio.h> 10 + #include <linux/gpio/driver.h> 11 11 #include <linux/interrupt.h> 12 12 #include <linux/io.h> 13 13 #include <linux/of_device.h> 14 + #include <linux/of_irq.h> 14 15 #include <linux/of_platform.h> 15 16 #include <linux/pinctrl/pinctrl.h> 16 17 #include <linux/pinctrl/pinmux.h> ··· 25 24 #include "pinconf.h" 26 25 #include "pinmux.h" 27 26 27 + #define GPIO_PIN 0x00 28 + #define GPIO_MSK 0x20 29 + 28 30 #define JZ4740_GPIO_DATA 0x10 29 31 #define JZ4740_GPIO_PULL_DIS 0x30 30 32 #define JZ4740_GPIO_FUNC 0x40 ··· 37 33 #define JZ4740_GPIO_FLAG 0x80 38 34 39 35 #define JZ4770_GPIO_INT 0x10 40 - #define JZ4770_GPIO_MSK 0x20 41 36 #define JZ4770_GPIO_PAT1 0x30 42 37 #define JZ4770_GPIO_PAT0 0x40 43 38 #define JZ4770_GPIO_FLAG 0x50 ··· 49 46 50 47 enum jz_version { 51 48 ID_JZ4740, 49 + ID_JZ4725B, 52 50 ID_JZ4770, 53 51 ID_JZ4780, 54 52 }; ··· 74 70 enum jz_version version; 75 71 76 72 const struct ingenic_chip_info *info; 73 + }; 74 + 75 + struct ingenic_gpio_chip { 76 + struct ingenic_pinctrl *jzpc; 77 + struct gpio_chip gc; 78 + struct irq_chip irq_chip; 79 + unsigned int irq, reg_base; 77 80 }; 78 81 79 82 static const u32 jz4740_pull_ups[4] = { ··· 212 201 .num_groups = ARRAY_SIZE(jz4740_groups), 213 202 .functions = jz4740_functions, 214 203 .num_functions = ARRAY_SIZE(jz4740_functions), 204 + .pull_ups = jz4740_pull_ups, 205 + .pull_downs = jz4740_pull_downs, 206 + }; 207 + 208 + static int jz4725b_mmc0_1bit_pins[] = { 0x48, 0x49, 0x5c, }; 209 + static int jz4725b_mmc0_4bit_pins[] = { 0x5d, 0x5b, 0x56, }; 210 + static int jz4725b_mmc1_1bit_pins[] = { 0x7a, 0x7b, 0x7c, }; 211 + static int jz4725b_mmc1_4bit_pins[] = { 0x7d, 0x7e, 0x7f, }; 212 + static int jz4725b_uart_data_pins[] = { 0x4c, 0x4d, }; 213 + static int jz4725b_nand_cs1_pins[] = { 0x55, }; 214 + static int jz4725b_nand_cs2_pins[] = { 0x56, }; 215 + static int jz4725b_nand_cs3_pins[] = { 0x57, }; 216 + static int jz4725b_nand_cs4_pins[] = { 0x58, }; 217 + static int jz4725b_nand_cle_ale_pins[] = { 0x48, 0x49 }; 218 + static int jz4725b_nand_fre_fwe_pins[] = { 0x5c, 0x5d }; 219 + static int jz4725b_pwm_pwm0_pins[] = { 0x4a, }; 220 + static int jz4725b_pwm_pwm1_pins[] = { 0x4b, }; 221 + static int jz4725b_pwm_pwm2_pins[] = { 0x4c, }; 222 + static int jz4725b_pwm_pwm3_pins[] = { 0x4d, }; 223 + static int jz4725b_pwm_pwm4_pins[] = { 0x4e, }; 224 + static int jz4725b_pwm_pwm5_pins[] = { 0x4f, }; 225 + 226 + static int jz4725b_mmc0_1bit_funcs[] = { 1, 1, 1, }; 227 + static int jz4725b_mmc0_4bit_funcs[] = { 1, 0, 1, }; 228 + static int jz4725b_mmc1_1bit_funcs[] = { 0, 0, 0, }; 229 + static int jz4725b_mmc1_4bit_funcs[] = { 0, 0, 0, }; 230 + static int jz4725b_uart_data_funcs[] = { 1, 1, }; 231 + static int jz4725b_nand_cs1_funcs[] = { 0, }; 232 + static int jz4725b_nand_cs2_funcs[] = { 0, }; 233 + static int jz4725b_nand_cs3_funcs[] = { 0, }; 234 + static int jz4725b_nand_cs4_funcs[] = { 0, }; 235 + static int jz4725b_nand_cle_ale_funcs[] = { 0, 0, }; 236 + static int jz4725b_nand_fre_fwe_funcs[] = { 0, 0, }; 237 + static int jz4725b_pwm_pwm0_funcs[] = { 0, }; 238 + static int jz4725b_pwm_pwm1_funcs[] = { 0, }; 239 + static int jz4725b_pwm_pwm2_funcs[] = { 0, }; 240 + static int jz4725b_pwm_pwm3_funcs[] = { 0, }; 241 + static int jz4725b_pwm_pwm4_funcs[] = { 0, }; 242 + static int jz4725b_pwm_pwm5_funcs[] = { 0, }; 243 + 244 + static const struct group_desc jz4725b_groups[] = { 245 + INGENIC_PIN_GROUP("mmc0-1bit", jz4725b_mmc0_1bit), 246 + INGENIC_PIN_GROUP("mmc0-4bit", jz4725b_mmc0_4bit), 247 + INGENIC_PIN_GROUP("mmc1-1bit", jz4725b_mmc1_1bit), 248 + INGENIC_PIN_GROUP("mmc1-4bit", jz4725b_mmc1_4bit), 249 + INGENIC_PIN_GROUP("uart-data", jz4725b_uart_data), 250 + INGENIC_PIN_GROUP("nand-cs1", jz4725b_nand_cs1), 251 + INGENIC_PIN_GROUP("nand-cs2", jz4725b_nand_cs2), 252 + INGENIC_PIN_GROUP("nand-cs3", jz4725b_nand_cs3), 253 + INGENIC_PIN_GROUP("nand-cs4", jz4725b_nand_cs4), 254 + INGENIC_PIN_GROUP("nand-cle-ale", jz4725b_nand_cle_ale), 255 + INGENIC_PIN_GROUP("nand-fre-fwe", jz4725b_nand_fre_fwe), 256 + INGENIC_PIN_GROUP("pwm0", jz4725b_pwm_pwm0), 257 + INGENIC_PIN_GROUP("pwm1", jz4725b_pwm_pwm1), 258 + INGENIC_PIN_GROUP("pwm2", jz4725b_pwm_pwm2), 259 + INGENIC_PIN_GROUP("pwm3", jz4725b_pwm_pwm3), 260 + INGENIC_PIN_GROUP("pwm4", jz4725b_pwm_pwm4), 261 + INGENIC_PIN_GROUP("pwm5", jz4725b_pwm_pwm5), 262 + }; 263 + 264 + static const char *jz4725b_mmc0_groups[] = { "mmc0-1bit", "mmc0-4bit", }; 265 + static const char *jz4725b_mmc1_groups[] = { "mmc1-1bit", "mmc1-4bit", }; 266 + static const char *jz4725b_uart_groups[] = { "uart-data", }; 267 + static const char *jz4725b_nand_groups[] = { 268 + "nand-cs1", "nand-cs2", "nand-cs3", "nand-cs4", 269 + "nand-cle-ale", "nand-fre-fwe", 270 + }; 271 + static const char *jz4725b_pwm0_groups[] = { "pwm0", }; 272 + static const char *jz4725b_pwm1_groups[] = { "pwm1", }; 273 + static const char *jz4725b_pwm2_groups[] = { "pwm2", }; 274 + static const char *jz4725b_pwm3_groups[] = { "pwm3", }; 275 + static const char *jz4725b_pwm4_groups[] = { "pwm4", }; 276 + static const char *jz4725b_pwm5_groups[] = { "pwm5", }; 277 + 278 + static const struct function_desc jz4725b_functions[] = { 279 + { "mmc0", jz4725b_mmc0_groups, ARRAY_SIZE(jz4725b_mmc0_groups), }, 280 + { "mmc1", jz4725b_mmc1_groups, ARRAY_SIZE(jz4725b_mmc1_groups), }, 281 + { "uart", jz4725b_uart_groups, ARRAY_SIZE(jz4725b_uart_groups), }, 282 + { "nand", jz4725b_nand_groups, ARRAY_SIZE(jz4725b_nand_groups), }, 283 + { "pwm0", jz4725b_pwm0_groups, ARRAY_SIZE(jz4725b_pwm0_groups), }, 284 + { "pwm1", jz4725b_pwm1_groups, ARRAY_SIZE(jz4725b_pwm1_groups), }, 285 + { "pwm2", jz4725b_pwm2_groups, ARRAY_SIZE(jz4725b_pwm2_groups), }, 286 + { "pwm3", jz4725b_pwm3_groups, ARRAY_SIZE(jz4725b_pwm3_groups), }, 287 + { "pwm4", jz4725b_pwm4_groups, ARRAY_SIZE(jz4725b_pwm4_groups), }, 288 + { "pwm5", jz4725b_pwm5_groups, ARRAY_SIZE(jz4725b_pwm5_groups), }, 289 + }; 290 + 291 + static const struct ingenic_chip_info jz4725b_chip_info = { 292 + .num_chips = 4, 293 + .groups = jz4725b_groups, 294 + .num_groups = ARRAY_SIZE(jz4725b_groups), 295 + .functions = jz4725b_functions, 296 + .num_functions = ARRAY_SIZE(jz4725b_functions), 215 297 .pull_ups = jz4740_pull_ups, 216 298 .pull_downs = jz4740_pull_downs, 217 299 }; ··· 542 438 .pull_downs = jz4770_pull_downs, 543 439 }; 544 440 441 + static u32 gpio_ingenic_read_reg(struct ingenic_gpio_chip *jzgc, u8 reg) 442 + { 443 + unsigned int val; 444 + 445 + regmap_read(jzgc->jzpc->map, jzgc->reg_base + reg, &val); 446 + 447 + return (u32) val; 448 + } 449 + 450 + static void gpio_ingenic_set_bit(struct ingenic_gpio_chip *jzgc, 451 + u8 reg, u8 offset, bool set) 452 + { 453 + if (set) 454 + reg = REG_SET(reg); 455 + else 456 + reg = REG_CLEAR(reg); 457 + 458 + regmap_write(jzgc->jzpc->map, jzgc->reg_base + reg, BIT(offset)); 459 + } 460 + 461 + static inline bool ingenic_gpio_get_value(struct ingenic_gpio_chip *jzgc, 462 + u8 offset) 463 + { 464 + unsigned int val = gpio_ingenic_read_reg(jzgc, GPIO_PIN); 465 + 466 + return !!(val & BIT(offset)); 467 + } 468 + 469 + static void ingenic_gpio_set_value(struct ingenic_gpio_chip *jzgc, 470 + u8 offset, int value) 471 + { 472 + if (jzgc->jzpc->version >= ID_JZ4770) 473 + gpio_ingenic_set_bit(jzgc, JZ4770_GPIO_PAT0, offset, !!value); 474 + else 475 + gpio_ingenic_set_bit(jzgc, JZ4740_GPIO_DATA, offset, !!value); 476 + } 477 + 478 + static void irq_set_type(struct ingenic_gpio_chip *jzgc, 479 + u8 offset, unsigned int type) 480 + { 481 + u8 reg1, reg2; 482 + 483 + if (jzgc->jzpc->version >= ID_JZ4770) { 484 + reg1 = JZ4770_GPIO_PAT1; 485 + reg2 = JZ4770_GPIO_PAT0; 486 + } else { 487 + reg1 = JZ4740_GPIO_TRIG; 488 + reg2 = JZ4740_GPIO_DIR; 489 + } 490 + 491 + switch (type) { 492 + case IRQ_TYPE_EDGE_RISING: 493 + gpio_ingenic_set_bit(jzgc, reg2, offset, true); 494 + gpio_ingenic_set_bit(jzgc, reg1, offset, true); 495 + break; 496 + case IRQ_TYPE_EDGE_FALLING: 497 + gpio_ingenic_set_bit(jzgc, reg2, offset, false); 498 + gpio_ingenic_set_bit(jzgc, reg1, offset, true); 499 + break; 500 + case IRQ_TYPE_LEVEL_HIGH: 501 + gpio_ingenic_set_bit(jzgc, reg2, offset, true); 502 + gpio_ingenic_set_bit(jzgc, reg1, offset, false); 503 + break; 504 + case IRQ_TYPE_LEVEL_LOW: 505 + default: 506 + gpio_ingenic_set_bit(jzgc, reg2, offset, false); 507 + gpio_ingenic_set_bit(jzgc, reg1, offset, false); 508 + break; 509 + } 510 + } 511 + 512 + static void ingenic_gpio_irq_mask(struct irq_data *irqd) 513 + { 514 + struct gpio_chip *gc = irq_data_get_irq_chip_data(irqd); 515 + struct ingenic_gpio_chip *jzgc = gpiochip_get_data(gc); 516 + 517 + gpio_ingenic_set_bit(jzgc, GPIO_MSK, irqd->hwirq, true); 518 + } 519 + 520 + static void ingenic_gpio_irq_unmask(struct irq_data *irqd) 521 + { 522 + struct gpio_chip *gc = irq_data_get_irq_chip_data(irqd); 523 + struct ingenic_gpio_chip *jzgc = gpiochip_get_data(gc); 524 + 525 + gpio_ingenic_set_bit(jzgc, GPIO_MSK, irqd->hwirq, false); 526 + } 527 + 528 + static void ingenic_gpio_irq_enable(struct irq_data *irqd) 529 + { 530 + struct gpio_chip *gc = irq_data_get_irq_chip_data(irqd); 531 + struct ingenic_gpio_chip *jzgc = gpiochip_get_data(gc); 532 + int irq = irqd->hwirq; 533 + 534 + if (jzgc->jzpc->version >= ID_JZ4770) 535 + gpio_ingenic_set_bit(jzgc, JZ4770_GPIO_INT, irq, true); 536 + else 537 + gpio_ingenic_set_bit(jzgc, JZ4740_GPIO_SELECT, irq, true); 538 + 539 + ingenic_gpio_irq_unmask(irqd); 540 + } 541 + 542 + static void ingenic_gpio_irq_disable(struct irq_data *irqd) 543 + { 544 + struct gpio_chip *gc = irq_data_get_irq_chip_data(irqd); 545 + struct ingenic_gpio_chip *jzgc = gpiochip_get_data(gc); 546 + int irq = irqd->hwirq; 547 + 548 + ingenic_gpio_irq_mask(irqd); 549 + 550 + if (jzgc->jzpc->version >= ID_JZ4770) 551 + gpio_ingenic_set_bit(jzgc, JZ4770_GPIO_INT, irq, false); 552 + else 553 + gpio_ingenic_set_bit(jzgc, JZ4740_GPIO_SELECT, irq, false); 554 + } 555 + 556 + static void ingenic_gpio_irq_ack(struct irq_data *irqd) 557 + { 558 + struct gpio_chip *gc = irq_data_get_irq_chip_data(irqd); 559 + struct ingenic_gpio_chip *jzgc = gpiochip_get_data(gc); 560 + int irq = irqd->hwirq; 561 + bool high; 562 + 563 + if (irqd_get_trigger_type(irqd) == IRQ_TYPE_EDGE_BOTH) { 564 + /* 565 + * Switch to an interrupt for the opposite edge to the one that 566 + * triggered the interrupt being ACKed. 567 + */ 568 + high = ingenic_gpio_get_value(jzgc, irq); 569 + if (high) 570 + irq_set_type(jzgc, irq, IRQ_TYPE_EDGE_FALLING); 571 + else 572 + irq_set_type(jzgc, irq, IRQ_TYPE_EDGE_RISING); 573 + } 574 + 575 + if (jzgc->jzpc->version >= ID_JZ4770) 576 + gpio_ingenic_set_bit(jzgc, JZ4770_GPIO_FLAG, irq, false); 577 + else 578 + gpio_ingenic_set_bit(jzgc, JZ4740_GPIO_DATA, irq, true); 579 + } 580 + 581 + static int ingenic_gpio_irq_set_type(struct irq_data *irqd, unsigned int type) 582 + { 583 + struct gpio_chip *gc = irq_data_get_irq_chip_data(irqd); 584 + struct ingenic_gpio_chip *jzgc = gpiochip_get_data(gc); 585 + 586 + switch (type) { 587 + case IRQ_TYPE_EDGE_BOTH: 588 + case IRQ_TYPE_EDGE_RISING: 589 + case IRQ_TYPE_EDGE_FALLING: 590 + irq_set_handler_locked(irqd, handle_edge_irq); 591 + break; 592 + case IRQ_TYPE_LEVEL_HIGH: 593 + case IRQ_TYPE_LEVEL_LOW: 594 + irq_set_handler_locked(irqd, handle_level_irq); 595 + break; 596 + default: 597 + irq_set_handler_locked(irqd, handle_bad_irq); 598 + } 599 + 600 + if (type == IRQ_TYPE_EDGE_BOTH) { 601 + /* 602 + * The hardware does not support interrupts on both edges. The 603 + * best we can do is to set up a single-edge interrupt and then 604 + * switch to the opposing edge when ACKing the interrupt. 605 + */ 606 + bool high = ingenic_gpio_get_value(jzgc, irqd->hwirq); 607 + 608 + type = high ? IRQ_TYPE_EDGE_FALLING : IRQ_TYPE_EDGE_RISING; 609 + } 610 + 611 + irq_set_type(jzgc, irqd->hwirq, type); 612 + return 0; 613 + } 614 + 615 + static int ingenic_gpio_irq_set_wake(struct irq_data *irqd, unsigned int on) 616 + { 617 + struct gpio_chip *gc = irq_data_get_irq_chip_data(irqd); 618 + struct ingenic_gpio_chip *jzgc = gpiochip_get_data(gc); 619 + 620 + return irq_set_irq_wake(jzgc->irq, on); 621 + } 622 + 623 + static void ingenic_gpio_irq_handler(struct irq_desc *desc) 624 + { 625 + struct gpio_chip *gc = irq_desc_get_handler_data(desc); 626 + struct ingenic_gpio_chip *jzgc = gpiochip_get_data(gc); 627 + struct irq_chip *irq_chip = irq_data_get_irq_chip(&desc->irq_data); 628 + unsigned long flag, i; 629 + 630 + chained_irq_enter(irq_chip, desc); 631 + 632 + if (jzgc->jzpc->version >= ID_JZ4770) 633 + flag = gpio_ingenic_read_reg(jzgc, JZ4770_GPIO_FLAG); 634 + else 635 + flag = gpio_ingenic_read_reg(jzgc, JZ4740_GPIO_FLAG); 636 + 637 + for_each_set_bit(i, &flag, 32) 638 + generic_handle_irq(irq_linear_revmap(gc->irq.domain, i)); 639 + chained_irq_exit(irq_chip, desc); 640 + } 641 + 642 + static void ingenic_gpio_set(struct gpio_chip *gc, 643 + unsigned int offset, int value) 644 + { 645 + struct ingenic_gpio_chip *jzgc = gpiochip_get_data(gc); 646 + 647 + ingenic_gpio_set_value(jzgc, offset, value); 648 + } 649 + 650 + static int ingenic_gpio_get(struct gpio_chip *gc, unsigned int offset) 651 + { 652 + struct ingenic_gpio_chip *jzgc = gpiochip_get_data(gc); 653 + 654 + return (int) ingenic_gpio_get_value(jzgc, offset); 655 + } 656 + 657 + static int ingenic_gpio_direction_input(struct gpio_chip *gc, 658 + unsigned int offset) 659 + { 660 + return pinctrl_gpio_direction_input(gc->base + offset); 661 + } 662 + 663 + static int ingenic_gpio_direction_output(struct gpio_chip *gc, 664 + unsigned int offset, int value) 665 + { 666 + ingenic_gpio_set(gc, offset, value); 667 + return pinctrl_gpio_direction_output(gc->base + offset); 668 + } 669 + 545 670 static inline void ingenic_config_pin(struct ingenic_pinctrl *jzpc, 546 671 unsigned int pin, u8 reg, bool set) 547 672 { ··· 793 460 return val & BIT(idx); 794 461 } 795 462 463 + static int ingenic_gpio_get_direction(struct gpio_chip *gc, unsigned int offset) 464 + { 465 + struct ingenic_gpio_chip *jzgc = gpiochip_get_data(gc); 466 + struct ingenic_pinctrl *jzpc = jzgc->jzpc; 467 + unsigned int pin = gc->base + offset; 468 + 469 + if (jzpc->version >= ID_JZ4770) 470 + return ingenic_get_pin_config(jzpc, pin, JZ4770_GPIO_PAT1); 471 + 472 + if (ingenic_get_pin_config(jzpc, pin, JZ4740_GPIO_SELECT)) 473 + return true; 474 + 475 + return !ingenic_get_pin_config(jzpc, pin, JZ4740_GPIO_DIR); 476 + } 477 + 796 478 static const struct pinctrl_ops ingenic_pctlops = { 797 479 .get_groups_count = pinctrl_generic_get_group_count, 798 480 .get_group_name = pinctrl_generic_get_group_name, ··· 827 479 828 480 if (jzpc->version >= ID_JZ4770) { 829 481 ingenic_config_pin(jzpc, pin, JZ4770_GPIO_INT, false); 830 - ingenic_config_pin(jzpc, pin, JZ4770_GPIO_MSK, false); 482 + ingenic_config_pin(jzpc, pin, GPIO_MSK, false); 831 483 ingenic_config_pin(jzpc, pin, JZ4770_GPIO_PAT1, func & 0x2); 832 484 ingenic_config_pin(jzpc, pin, JZ4770_GPIO_PAT0, func & 0x1); 833 485 } else { ··· 880 532 881 533 if (jzpc->version >= ID_JZ4770) { 882 534 ingenic_config_pin(jzpc, pin, JZ4770_GPIO_INT, false); 883 - ingenic_config_pin(jzpc, pin, JZ4770_GPIO_MSK, true); 535 + ingenic_config_pin(jzpc, pin, GPIO_MSK, true); 884 536 ingenic_config_pin(jzpc, pin, JZ4770_GPIO_PAT1, input); 885 537 } else { 886 538 ingenic_config_pin(jzpc, pin, JZ4740_GPIO_SELECT, false); ··· 1060 712 1061 713 static const struct of_device_id ingenic_pinctrl_of_match[] = { 1062 714 { .compatible = "ingenic,jz4740-pinctrl", .data = (void *) ID_JZ4740 }, 715 + { .compatible = "ingenic,jz4725b-pinctrl", .data = (void *)ID_JZ4725B }, 1063 716 { .compatible = "ingenic,jz4770-pinctrl", .data = (void *) ID_JZ4770 }, 1064 717 { .compatible = "ingenic,jz4780-pinctrl", .data = (void *) ID_JZ4780 }, 1065 718 {}, 1066 719 }; 1067 720 1068 - static int ingenic_pinctrl_probe(struct platform_device *pdev) 721 + static const struct of_device_id ingenic_gpio_of_match[] __initconst = { 722 + { .compatible = "ingenic,jz4740-gpio", }, 723 + { .compatible = "ingenic,jz4770-gpio", }, 724 + { .compatible = "ingenic,jz4780-gpio", }, 725 + {}, 726 + }; 727 + 728 + static int __init ingenic_gpio_probe(struct ingenic_pinctrl *jzpc, 729 + struct device_node *node) 730 + { 731 + struct ingenic_gpio_chip *jzgc; 732 + struct device *dev = jzpc->dev; 733 + unsigned int bank; 734 + int err; 735 + 736 + err = of_property_read_u32(node, "reg", &bank); 737 + if (err) { 738 + dev_err(dev, "Cannot read \"reg\" property: %i\n", err); 739 + return err; 740 + } 741 + 742 + jzgc = devm_kzalloc(dev, sizeof(*jzgc), GFP_KERNEL); 743 + if (!jzgc) 744 + return -ENOMEM; 745 + 746 + jzgc->jzpc = jzpc; 747 + jzgc->reg_base = bank * 0x100; 748 + 749 + jzgc->gc.label = devm_kasprintf(dev, GFP_KERNEL, "GPIO%c", 'A' + bank); 750 + if (!jzgc->gc.label) 751 + return -ENOMEM; 752 + 753 + /* DO NOT EXPAND THIS: FOR BACKWARD GPIO NUMBERSPACE COMPATIBIBILITY 754 + * ONLY: WORK TO TRANSITION CONSUMERS TO USE THE GPIO DESCRIPTOR API IN 755 + * <linux/gpio/consumer.h> INSTEAD. 756 + */ 757 + jzgc->gc.base = bank * 32; 758 + 759 + jzgc->gc.ngpio = 32; 760 + jzgc->gc.parent = dev; 761 + jzgc->gc.of_node = node; 762 + jzgc->gc.owner = THIS_MODULE; 763 + 764 + jzgc->gc.set = ingenic_gpio_set; 765 + jzgc->gc.get = ingenic_gpio_get; 766 + jzgc->gc.direction_input = ingenic_gpio_direction_input; 767 + jzgc->gc.direction_output = ingenic_gpio_direction_output; 768 + jzgc->gc.get_direction = ingenic_gpio_get_direction; 769 + 770 + if (of_property_read_bool(node, "gpio-ranges")) { 771 + jzgc->gc.request = gpiochip_generic_request; 772 + jzgc->gc.free = gpiochip_generic_free; 773 + } 774 + 775 + err = devm_gpiochip_add_data(dev, &jzgc->gc, jzgc); 776 + if (err) 777 + return err; 778 + 779 + jzgc->irq = irq_of_parse_and_map(node, 0); 780 + if (!jzgc->irq) 781 + return -EINVAL; 782 + 783 + jzgc->irq_chip.name = jzgc->gc.label; 784 + jzgc->irq_chip.irq_enable = ingenic_gpio_irq_enable; 785 + jzgc->irq_chip.irq_disable = ingenic_gpio_irq_disable; 786 + jzgc->irq_chip.irq_unmask = ingenic_gpio_irq_unmask; 787 + jzgc->irq_chip.irq_mask = ingenic_gpio_irq_mask; 788 + jzgc->irq_chip.irq_ack = ingenic_gpio_irq_ack; 789 + jzgc->irq_chip.irq_set_type = ingenic_gpio_irq_set_type; 790 + jzgc->irq_chip.irq_set_wake = ingenic_gpio_irq_set_wake; 791 + jzgc->irq_chip.flags = IRQCHIP_MASK_ON_SUSPEND; 792 + 793 + err = gpiochip_irqchip_add(&jzgc->gc, &jzgc->irq_chip, 0, 794 + handle_level_irq, IRQ_TYPE_NONE); 795 + if (err) 796 + return err; 797 + 798 + gpiochip_set_chained_irqchip(&jzgc->gc, &jzgc->irq_chip, 799 + jzgc->irq, ingenic_gpio_irq_handler); 800 + return 0; 801 + } 802 + 803 + static int __init ingenic_pinctrl_probe(struct platform_device *pdev) 1069 804 { 1070 805 struct device *dev = &pdev->dev; 1071 806 struct ingenic_pinctrl *jzpc; ··· 1158 727 const struct of_device_id *of_id = of_match_device( 1159 728 ingenic_pinctrl_of_match, dev); 1160 729 const struct ingenic_chip_info *chip_info; 730 + struct device_node *node; 1161 731 unsigned int i; 1162 732 int err; 1163 733 ··· 1187 755 1188 756 if (jzpc->version >= ID_JZ4770) 1189 757 chip_info = &jz4770_chip_info; 758 + else if (jzpc->version >= ID_JZ4725B) 759 + chip_info = &jz4725b_chip_info; 1190 760 else 1191 761 chip_info = &jz4740_chip_info; 1192 762 jzpc->info = chip_info; ··· 1249 815 1250 816 dev_set_drvdata(dev, jzpc->map); 1251 817 1252 - if (dev->of_node) { 1253 - err = of_platform_populate(dev->of_node, NULL, NULL, dev); 1254 - if (err) { 1255 - dev_err(dev, "Failed to probe GPIO devices\n"); 1256 - return err; 818 + for_each_child_of_node(dev->of_node, node) { 819 + if (of_match_node(ingenic_gpio_of_match, node)) { 820 + err = ingenic_gpio_probe(jzpc, node); 821 + if (err) 822 + return err; 1257 823 } 1258 824 } 1259 825 ··· 1262 828 1263 829 static const struct platform_device_id ingenic_pinctrl_ids[] = { 1264 830 { "jz4740-pinctrl", ID_JZ4740 }, 831 + { "jz4725b-pinctrl", ID_JZ4725B }, 1265 832 { "jz4770-pinctrl", ID_JZ4770 }, 1266 833 { "jz4780-pinctrl", ID_JZ4780 }, 1267 834 {}, ··· 1272 837 .driver = { 1273 838 .name = "pinctrl-ingenic", 1274 839 .of_match_table = of_match_ptr(ingenic_pinctrl_of_match), 1275 - .suppress_bind_attrs = true, 1276 840 }, 1277 - .probe = ingenic_pinctrl_probe, 1278 841 .id_table = ingenic_pinctrl_ids, 1279 842 }; 1280 843 1281 844 static int __init ingenic_pinctrl_drv_register(void) 1282 845 { 1283 - return platform_driver_register(&ingenic_pinctrl_driver); 846 + return platform_driver_probe(&ingenic_pinctrl_driver, 847 + ingenic_pinctrl_probe); 1284 848 } 1285 - postcore_initcall(ingenic_pinctrl_drv_register); 849 + subsys_initcall(ingenic_pinctrl_drv_register);