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

gpio/mxc: add device tree probe support

The patch adds device tree probe support for gpio-mxc driver.

Signed-off-by: Shawn Guo <shawn.guo@linaro.org>
Signed-off-by: Grant Likely <grant.likely@secretlab.ca>

authored by

Shawn Guo and committed by
Grant Likely
8937cb60 14305e68

+50 -6
+22
Documentation/devicetree/bindings/gpio/fsl-imx-gpio.txt
··· 1 + * Freescale i.MX/MXC GPIO controller 2 + 3 + Required properties: 4 + - compatible : Should be "fsl,<soc>-gpio" 5 + - reg : Address and length of the register set for the device 6 + - interrupts : Should be the port interrupt shared by all 32 pins, if 7 + one number. If two numbers, the first one is the interrupt shared 8 + by low 16 pins and the second one is for high 16 pins. 9 + - gpio-controller : Marks the device node as a gpio controller. 10 + - #gpio-cells : Should be two. The first cell is the pin number and 11 + the second cell is used to specify optional parameters (currently 12 + unused). 13 + 14 + Example: 15 + 16 + gpio0: gpio@73f84000 { 17 + compatible = "fsl,imx51-gpio", "fsl,imx31-gpio"; 18 + reg = <0x73f84000 0x4000>; 19 + interrupts = <50 51>; 20 + gpio-controller; 21 + #gpio-cells = <2>; 22 + };
+28 -6
drivers/gpio/gpio-mxc.c
··· 27 27 #include <linux/platform_device.h> 28 28 #include <linux/slab.h> 29 29 #include <linux/basic_mmio_gpio.h> 30 + #include <linux/of.h> 31 + #include <linux/of_device.h> 30 32 #include <asm-generic/bug.h> 31 33 32 34 enum mxc_gpio_hwtype { ··· 120 118 }, { 121 119 /* sentinel */ 122 120 } 121 + }; 122 + 123 + static const struct of_device_id mxc_gpio_dt_ids[] = { 124 + { .compatible = "fsl,imx1-gpio", .data = &mxc_gpio_devtype[IMX1_GPIO], }, 125 + { .compatible = "fsl,imx21-gpio", .data = &mxc_gpio_devtype[IMX21_GPIO], }, 126 + { .compatible = "fsl,imx31-gpio", .data = &mxc_gpio_devtype[IMX31_GPIO], }, 127 + { /* sentinel */ } 123 128 }; 124 129 125 130 /* ··· 311 302 312 303 static void __devinit mxc_gpio_get_hw(struct platform_device *pdev) 313 304 { 314 - enum mxc_gpio_hwtype hwtype = pdev->id_entry->driver_data; 305 + const struct of_device_id *of_id = 306 + of_match_device(mxc_gpio_dt_ids, &pdev->dev); 307 + enum mxc_gpio_hwtype hwtype; 308 + 309 + if (of_id) 310 + pdev->id_entry = of_id->data; 311 + hwtype = pdev->id_entry->driver_data; 315 312 316 313 if (mxc_gpio_hwtype) { 317 314 /* ··· 339 324 340 325 static int __devinit mxc_gpio_probe(struct platform_device *pdev) 341 326 { 327 + struct device_node *np = pdev->dev.of_node; 342 328 struct mxc_gpio_port *port; 343 329 struct resource *iores; 344 330 int err; ··· 349 333 port = kzalloc(sizeof(struct mxc_gpio_port), GFP_KERNEL); 350 334 if (!port) 351 335 return -ENOMEM; 352 - 353 - port->virtual_irq_start = MXC_GPIO_IRQ_START + pdev->id * 32; 354 336 355 337 iores = platform_get_resource(pdev, IORESOURCE_MEM, 0); 356 338 if (!iores) { ··· 378 364 /* disable the interrupt and clear the status */ 379 365 writel(0, port->base + GPIO_IMR); 380 366 writel(~0, port->base + GPIO_ISR); 381 - 382 - /* gpio-mxc can be a generic irq chip */ 383 - mxc_gpio_init_gc(port); 384 367 385 368 if (mxc_gpio_hwtype == IMX21_GPIO) { 386 369 /* setup one handler for all GPIO interrupts */ ··· 411 400 if (err) 412 401 goto out_bgpio_remove; 413 402 403 + /* 404 + * In dt case, we use gpio number range dynamically 405 + * allocated by gpio core. 406 + */ 407 + port->virtual_irq_start = MXC_GPIO_IRQ_START + (np ? port->bgc.gc.base : 408 + pdev->id * 32); 409 + 410 + /* gpio-mxc can be a generic irq chip */ 411 + mxc_gpio_init_gc(port); 412 + 414 413 list_add_tail(&port->node, &mxc_gpio_ports); 415 414 416 415 return 0; ··· 441 420 .driver = { 442 421 .name = "gpio-mxc", 443 422 .owner = THIS_MODULE, 423 + .of_match_table = mxc_gpio_dt_ids, 444 424 }, 445 425 .probe = mxc_gpio_probe, 446 426 .id_table = mxc_gpio_devtype,