From df2212270ce94f12e9caed6ca04c7077672d588e Mon Sep 17 00:00:00 2001 From: Grant Likely Date: Wed, 15 Jun 2011 14:54:14 -0600 Subject: gpio/tegra: add devicetree support Add support for decoding gpios from the device tree Signed-off-by: Grant Likely Acked-by: Olof Johansson --- Documentation/devicetree/bindings/gpio/gpio_nvidia.txt | 7 +++++++ 1 file changed, 7 insertions(+) create mode 100644 Documentation/devicetree/bindings/gpio/gpio_nvidia.txt (limited to 'Documentation') diff --git a/Documentation/devicetree/bindings/gpio/gpio_nvidia.txt b/Documentation/devicetree/bindings/gpio/gpio_nvidia.txt new file mode 100644 index 000000000000..afb3ff3134c8 --- /dev/null +++ b/Documentation/devicetree/bindings/gpio/gpio_nvidia.txt @@ -0,0 +1,7 @@ +NVIDIA Tegra 2 GPIO controller + +Required properties: +- compatible : "nvidia,tegra250-gpio" +- #gpio-cells : Should be two. The first cell is the pin number and the + second cell is used to specify optional parameters (currently unused). +- gpio-controller : Marks the device node as a GPIO controller. -- cgit v1.2.3 From bf859f84a19f8e562af4a990a287b5e3edabc572 Mon Sep 17 00:00:00 2001 From: Grant Likely Date: Fri, 3 Jun 2011 11:07:16 -0600 Subject: gpio/dt: Refine GPIO device tree binding Allow for multiple named gpio properties Signed-off-by: Grant Likely --- Documentation/devicetree/bindings/gpio/gpio.txt | 46 ++++++++++++++++++++----- 1 file changed, 37 insertions(+), 9 deletions(-) (limited to 'Documentation') diff --git a/Documentation/devicetree/bindings/gpio/gpio.txt b/Documentation/devicetree/bindings/gpio/gpio.txt index edaa84d288a1..4e16ba4feab0 100644 --- a/Documentation/devicetree/bindings/gpio/gpio.txt +++ b/Documentation/devicetree/bindings/gpio/gpio.txt @@ -4,17 +4,45 @@ Specifying GPIO information for devices 1) gpios property ----------------- -Nodes that makes use of GPIOs should define them using `gpios' property, -format of which is: <&gpio-controller1-phandle gpio1-specifier - &gpio-controller2-phandle gpio2-specifier - 0 /* holes are permitted, means no GPIO 3 */ - &gpio-controller4-phandle gpio4-specifier - ...>; +Nodes that makes use of GPIOs should specify them using one or more +properties, each containing a 'gpio-list': -Note that gpio-specifier length is controller dependent. + gpio-list ::= [gpio-list] + single-gpio ::= + gpio-phandle : phandle to gpio controller node + gpio-specifier : Array of #gpio-cells specifying specific gpio + (controller specific) + +GPIO properties should be named "[-]gpios". Exact +meaning of each gpios property must be documented in the device tree +binding for each device. + +For example, the following could be used to describe gpios pins to use +as chip select lines; with chip selects 0, 1 and 3 populated, and chip +select 2 left empty: + + gpio1: gpio1 { + gpio-controller + #gpio-cells = <2>; + }; + gpio2: gpio2 { + gpio-controller + #gpio-cells = <1>; + }; + [...] + chipsel-gpios = <&gpio1 12 0>, + <&gpio1 13 0>, + <0>, /* holes are permitted, means no GPIO 2 */ + <&gpio2 2>; + +Note that gpio-specifier length is controller dependent. In the +above example, &gpio1 uses 2 cells to specify a gpio, while &gpio2 +only uses one. gpio-specifier may encode: bank, pin position inside the bank, whether pin is open-drain and whether pin is logically inverted. +Exact meaning of each specifier cell is controller specific, and must +be documented in the device tree binding for the device. Example of the node using GPIOs: @@ -28,8 +56,8 @@ and empty GPIO flags as accepted by the "qe_pio_e" gpio-controller. 2) gpio-controller nodes ------------------------ -Every GPIO controller node must have #gpio-cells property defined, -this information will be used to translate gpio-specifiers. +Every GPIO controller node must both an empty "gpio-controller" +property, and have #gpio-cells contain the size of the gpio-specifier. Example of two SOC GPIO banks defined as gpio-controller nodes: -- cgit v1.2.3 From f7f678a06326ebafe9005203c0b2fa06885fd12c Mon Sep 17 00:00:00 2001 From: Stephen Warren Date: Tue, 5 Jul 2011 14:15:18 -0600 Subject: gpio/tegra: Use engineering names in DT compatible property Engineering names are more stable than marketing names. Hence, use them for Device Tree compatible properties instead. Signed-off-by: Stephen Warren Signed-off-by: Grant Likely --- Documentation/devicetree/bindings/gpio/gpio_nvidia.txt | 2 +- drivers/gpio/gpio-tegra.c | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) (limited to 'Documentation') diff --git a/Documentation/devicetree/bindings/gpio/gpio_nvidia.txt b/Documentation/devicetree/bindings/gpio/gpio_nvidia.txt index afb3ff3134c8..64aac39e6edc 100644 --- a/Documentation/devicetree/bindings/gpio/gpio_nvidia.txt +++ b/Documentation/devicetree/bindings/gpio/gpio_nvidia.txt @@ -1,7 +1,7 @@ NVIDIA Tegra 2 GPIO controller Required properties: -- compatible : "nvidia,tegra250-gpio" +- compatible : "nvidia,tegra20-gpio" - #gpio-cells : Should be two. The first cell is the pin number and the second cell is used to specify optional parameters (currently unused). - gpio-controller : Marks the device node as a GPIO controller. diff --git a/drivers/gpio/gpio-tegra.c b/drivers/gpio/gpio-tegra.c index 13afb881ffc3..747eb40e8afe 100644 --- a/drivers/gpio/gpio-tegra.c +++ b/drivers/gpio/gpio-tegra.c @@ -347,7 +347,7 @@ static int __init tegra_gpio_init(void) * driver is converted into a platform_device */ tegra_gpio_chip.of_node = of_find_compatible_node(NULL, NULL, - "nvidia,tegra250-gpio"); + "nvidia,tegra20-gpio"); #endif /* CONFIG_OF_GPIO */ gpiochip_add(&tegra_gpio_chip); -- cgit v1.2.3 From 8937cb602bea120248cef64961fc46836a394c8a Mon Sep 17 00:00:00 2001 From: Shawn Guo Date: Thu, 7 Jul 2011 00:37:43 +0800 Subject: gpio/mxc: add device tree probe support The patch adds device tree probe support for gpio-mxc driver. Signed-off-by: Shawn Guo Signed-off-by: Grant Likely --- .../devicetree/bindings/gpio/fsl-imx-gpio.txt | 22 ++++++++++++++ drivers/gpio/gpio-mxc.c | 34 ++++++++++++++++++---- 2 files changed, 50 insertions(+), 6 deletions(-) create mode 100644 Documentation/devicetree/bindings/gpio/fsl-imx-gpio.txt (limited to 'Documentation') diff --git a/Documentation/devicetree/bindings/gpio/fsl-imx-gpio.txt b/Documentation/devicetree/bindings/gpio/fsl-imx-gpio.txt new file mode 100644 index 000000000000..4363ae4b3c14 --- /dev/null +++ b/Documentation/devicetree/bindings/gpio/fsl-imx-gpio.txt @@ -0,0 +1,22 @@ +* Freescale i.MX/MXC GPIO controller + +Required properties: +- compatible : Should be "fsl,-gpio" +- reg : Address and length of the register set for the device +- interrupts : Should be the port interrupt shared by all 32 pins, if + one number. If two numbers, the first one is the interrupt shared + by low 16 pins and the second one is for high 16 pins. +- gpio-controller : Marks the device node as a gpio controller. +- #gpio-cells : Should be two. The first cell is the pin number and + the second cell is used to specify optional parameters (currently + unused). + +Example: + +gpio0: gpio@73f84000 { + compatible = "fsl,imx51-gpio", "fsl,imx31-gpio"; + reg = <0x73f84000 0x4000>; + interrupts = <50 51>; + gpio-controller; + #gpio-cells = <2>; +}; diff --git a/drivers/gpio/gpio-mxc.c b/drivers/gpio/gpio-mxc.c index 3775dccef4ad..89fda58db90d 100644 --- a/drivers/gpio/gpio-mxc.c +++ b/drivers/gpio/gpio-mxc.c @@ -27,6 +27,8 @@ #include #include #include +#include +#include #include enum mxc_gpio_hwtype { @@ -120,6 +122,13 @@ static struct platform_device_id mxc_gpio_devtype[] = { } }; +static const struct of_device_id mxc_gpio_dt_ids[] = { + { .compatible = "fsl,imx1-gpio", .data = &mxc_gpio_devtype[IMX1_GPIO], }, + { .compatible = "fsl,imx21-gpio", .data = &mxc_gpio_devtype[IMX21_GPIO], }, + { .compatible = "fsl,imx31-gpio", .data = &mxc_gpio_devtype[IMX31_GPIO], }, + { /* sentinel */ } +}; + /* * MX2 has one interrupt *for all* gpio ports. The list is used * to save the references to all ports, so that mx2_gpio_irq_handler @@ -302,7 +311,13 @@ static void __init mxc_gpio_init_gc(struct mxc_gpio_port *port) static void __devinit mxc_gpio_get_hw(struct platform_device *pdev) { - enum mxc_gpio_hwtype hwtype = pdev->id_entry->driver_data; + const struct of_device_id *of_id = + of_match_device(mxc_gpio_dt_ids, &pdev->dev); + enum mxc_gpio_hwtype hwtype; + + if (of_id) + pdev->id_entry = of_id->data; + hwtype = pdev->id_entry->driver_data; if (mxc_gpio_hwtype) { /* @@ -324,6 +339,7 @@ static void __devinit mxc_gpio_get_hw(struct platform_device *pdev) static int __devinit mxc_gpio_probe(struct platform_device *pdev) { + struct device_node *np = pdev->dev.of_node; struct mxc_gpio_port *port; struct resource *iores; int err; @@ -334,8 +350,6 @@ static int __devinit mxc_gpio_probe(struct platform_device *pdev) if (!port) return -ENOMEM; - port->virtual_irq_start = MXC_GPIO_IRQ_START + pdev->id * 32; - iores = platform_get_resource(pdev, IORESOURCE_MEM, 0); if (!iores) { err = -ENODEV; @@ -365,9 +379,6 @@ static int __devinit mxc_gpio_probe(struct platform_device *pdev) writel(0, port->base + GPIO_IMR); writel(~0, port->base + GPIO_ISR); - /* gpio-mxc can be a generic irq chip */ - mxc_gpio_init_gc(port); - if (mxc_gpio_hwtype == IMX21_GPIO) { /* setup one handler for all GPIO interrupts */ if (pdev->id == 0) @@ -400,6 +411,16 @@ static int __devinit mxc_gpio_probe(struct platform_device *pdev) if (err) goto out_bgpio_remove; + /* + * In dt case, we use gpio number range dynamically + * allocated by gpio core. + */ + port->virtual_irq_start = MXC_GPIO_IRQ_START + (np ? port->bgc.gc.base : + pdev->id * 32); + + /* gpio-mxc can be a generic irq chip */ + mxc_gpio_init_gc(port); + list_add_tail(&port->node, &mxc_gpio_ports); return 0; @@ -420,6 +441,7 @@ static struct platform_driver mxc_gpio_driver = { .driver = { .name = "gpio-mxc", .owner = THIS_MODULE, + .of_match_table = mxc_gpio_dt_ids, }, .probe = mxc_gpio_probe, .id_table = mxc_gpio_devtype, -- cgit v1.2.3 From eb5064db408eaffa332f93ddcc19c0b653849093 Mon Sep 17 00:00:00 2001 From: Olof Johansson Date: Thu, 14 Jul 2011 22:17:13 -0700 Subject: gpio/tegra: dt: add binding for gpio polarity Allocate one bit in the available extra cell to indicate if the gpio should be considered logically inverted. Signed-off-by: Olof Johansson Acked-by: Stephen Warren Signed-off-by: Grant Likely --- Documentation/devicetree/bindings/gpio/gpio_nvidia.txt | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) (limited to 'Documentation') diff --git a/Documentation/devicetree/bindings/gpio/gpio_nvidia.txt b/Documentation/devicetree/bindings/gpio/gpio_nvidia.txt index 64aac39e6edc..eb4b530d64e1 100644 --- a/Documentation/devicetree/bindings/gpio/gpio_nvidia.txt +++ b/Documentation/devicetree/bindings/gpio/gpio_nvidia.txt @@ -3,5 +3,6 @@ NVIDIA Tegra 2 GPIO controller Required properties: - compatible : "nvidia,tegra20-gpio" - #gpio-cells : Should be two. The first cell is the pin number and the - second cell is used to specify optional parameters (currently unused). + second cell is used to specify optional parameters: + - bit 0 specifies polarity (0 for normal, 1 for inverted) - gpio-controller : Marks the device node as a GPIO controller. -- cgit v1.2.3