···11+* Freescale i.MX/MXC GPIO controller22+33+Required properties:44+- compatible : Should be "fsl,<soc>-gpio"55+- reg : Address and length of the register set for the device66+- interrupts : Should be the port interrupt shared by all 32 pins, if77+ one number. If two numbers, the first one is the interrupt shared88+ by low 16 pins and the second one is for high 16 pins.99+- gpio-controller : Marks the device node as a gpio controller.1010+- #gpio-cells : Should be two. The first cell is the pin number and1111+ the second cell is used to specify optional parameters (currently1212+ unused).1313+1414+Example:1515+1616+gpio0: gpio@73f84000 {1717+ compatible = "fsl,imx51-gpio", "fsl,imx31-gpio";1818+ reg = <0x73f84000 0x4000>;1919+ interrupts = <50 51>;2020+ gpio-controller;2121+ #gpio-cells = <2>;2222+};
+28-6
drivers/gpio/gpio-mxc.c
···2727#include <linux/platform_device.h>2828#include <linux/slab.h>2929#include <linux/basic_mmio_gpio.h>3030+#include <linux/of.h>3131+#include <linux/of_device.h>3032#include <asm-generic/bug.h>31333234enum mxc_gpio_hwtype {···120118 }, {121119 /* sentinel */122120 }121121+};122122+123123+static const struct of_device_id mxc_gpio_dt_ids[] = {124124+ { .compatible = "fsl,imx1-gpio", .data = &mxc_gpio_devtype[IMX1_GPIO], },125125+ { .compatible = "fsl,imx21-gpio", .data = &mxc_gpio_devtype[IMX21_GPIO], },126126+ { .compatible = "fsl,imx31-gpio", .data = &mxc_gpio_devtype[IMX31_GPIO], },127127+ { /* sentinel */ }123128};124129125130/*···311302312303static void __devinit mxc_gpio_get_hw(struct platform_device *pdev)313304{314314- enum mxc_gpio_hwtype hwtype = pdev->id_entry->driver_data;305305+ const struct of_device_id *of_id =306306+ of_match_device(mxc_gpio_dt_ids, &pdev->dev);307307+ enum mxc_gpio_hwtype hwtype;308308+309309+ if (of_id)310310+ pdev->id_entry = of_id->data;311311+ hwtype = pdev->id_entry->driver_data;315312316313 if (mxc_gpio_hwtype) {317314 /*···339324340325static int __devinit mxc_gpio_probe(struct platform_device *pdev)341326{327327+ struct device_node *np = pdev->dev.of_node;342328 struct mxc_gpio_port *port;343329 struct resource *iores;344330 int err;···349333 port = kzalloc(sizeof(struct mxc_gpio_port), GFP_KERNEL);350334 if (!port)351335 return -ENOMEM;352352-353353- port->virtual_irq_start = MXC_GPIO_IRQ_START + pdev->id * 32;354336355337 iores = platform_get_resource(pdev, IORESOURCE_MEM, 0);356338 if (!iores) {···378364 /* disable the interrupt and clear the status */379365 writel(0, port->base + GPIO_IMR);380366 writel(~0, port->base + GPIO_ISR);381381-382382- /* gpio-mxc can be a generic irq chip */383383- mxc_gpio_init_gc(port);384367385368 if (mxc_gpio_hwtype == IMX21_GPIO) {386369 /* setup one handler for all GPIO interrupts */···411400 if (err)412401 goto out_bgpio_remove;413402403403+ /*404404+ * In dt case, we use gpio number range dynamically405405+ * allocated by gpio core.406406+ */407407+ port->virtual_irq_start = MXC_GPIO_IRQ_START + (np ? port->bgc.gc.base :408408+ pdev->id * 32);409409+410410+ /* gpio-mxc can be a generic irq chip */411411+ mxc_gpio_init_gc(port);412412+414413 list_add_tail(&port->node, &mxc_gpio_ports);415414416415 return 0;···441420 .driver = {442421 .name = "gpio-mxc",443422 .owner = THIS_MODULE,423423+ .of_match_table = mxc_gpio_dt_ids,444424 },445425 .probe = mxc_gpio_probe,446426 .id_table = mxc_gpio_devtype,