All of lore.kernel.org
 help / color / mirror / Atom feed
* [U-Boot] [PATCH 0/21] dm: Support GPIO device tree bindings in the uclass
@ 2015-01-06  3:05 Simon Glass
  2015-01-06  3:05 ` [U-Boot] [PATCH 01/21] dm: gpio: Bring in GPIO device tree binding Simon Glass
                   ` (21 more replies)
  0 siblings, 22 replies; 49+ messages in thread
From: Simon Glass @ 2015-01-06  3:05 UTC (permalink / raw)
  To: u-boot

At present U-Boot sort-of supports the standard way of reading GPIOs from
device tree nodes, but the support is incomplete, a bit clunky and only
works for GPIO bindings where #gpio-cells is 2.

Also, this support can now be built into the uclass, rather than parked in
a separate file.

Add support for requesting GPIOs based on a list in a device tree node, by
looking up the phandles. Convert existing boards and remove the old code.

As a side-effect, we now no-longer need to include <asm/gpio.h> in fdtdec.h,
a problem reported by Masahiro and others.

This series is tested on boards as follows, with the objective being to cover
each code path:

seaboard
--------
LCD comes up, USB host shows partitions, NAND can read/write. Both internal
MMC and external SD card partition can be read. Ejecting external SD card is
detected

Tegra20 (SeaBoard) # gpio status
Bank B:
B2: output: 1 [x] panel.nvidia,lvds-shutdown-gpios

Bank C:
C6: output: 1 [x] panel.nvidia,panel-vdd-gpios

Bank D:
D0: output: 0 [x] usb at c5000000.nvidia,vbus-gpio
D4: output: 1 [x] panel.nvidia,backlight-enable-gpios

Bank H:
H1: input: 0 [x] sdhci at c8000400.wp-gpios
H3: output: 1 [x] nand-controller at 70008000.nvidia,wp-gpios

Bank I:
I5: input: 0 [x] sdhci at c8000400.cd-gpios
I6: output: 1 [x] sdhci at c8000400.power-gpios

Bank W:
W0: output: 1 [x] panel.nvidia,backlight-vdd-gpios

pit
---
LCD comes up, internal MMC and external uSD cards can show a partition list.
EC works and the interrupt line behaves as expected. USB stick can display
a partition list.

pi
--
EC works correctly.


Simon Glass (21):
  dm: gpio: Bring in GPIO device tree binding
  dm: exynos: Bring in GPIO device tree binding
  dm: tegra: Bring in GPIO device tree binding
  dm: fdt: Add a function to decode phandles with arguments
  dm: gpio: Add a native driver model API
  dm: gpio: Add a driver GPIO translation method
  dm: gpio: Add better functions to request GPIOs
  dm: gpio: Mark the old GPIO API deprecated
  dm: demo: Add a simple GPIO demonstration
  dm: cros_ec: Remove use of fdtdec GPIO support
  dm: tegra: Add a GPIO translation function
  dm: exynos: Add a GPIO translation function
  dm: tegra: video: Remove use of fdtdec GPIO support
  dm: tegra: nand: Remove use of fdtdec GPIO support
  dm: zynq: Remove inline gpio functions
  dm: mmc: Remove use of fdtdec GPIO support
  dm: usb: Remove use of fdtdec GPIO support
  dm: spi: Remove use of fdtdec GPIO support
  dm: tegra: dts: Use TEGRA_GPIO() macro for all GPIOs
  dm: exynos: dts: Use GPIO bank phandles for GPIOs
  dm: fdt: Remove the old GPIO functions

 arch/arm/dts/exynos4.dtsi                          |   7 -
 arch/arm/dts/exynos4210-origen.dts                 |   2 +-
 arch/arm/dts/exynos4210-trats.dts                  |   4 +-
 arch/arm/dts/exynos4210-universal_c210.dts         |  12 +-
 arch/arm/dts/exynos4412-odroid.dts                 |   2 +-
 arch/arm/dts/exynos4412-trats2.dts                 |   6 +-
 arch/arm/dts/exynos5.dtsi                          |   4 +-
 arch/arm/dts/exynos5250-smdk5250.dts               |   2 +-
 arch/arm/dts/exynos5250-snow.dts                   |  10 +-
 arch/arm/dts/exynos5420-peach-pit.dts              |   8 +-
 arch/arm/dts/exynos5422-odroidxu3.dts              |   2 +-
 arch/arm/dts/exynos5800-peach-pi.dts               |  10 +-
 arch/arm/dts/tegra114-dalmore.dts                  |   5 +-
 arch/arm/dts/tegra124-jetson-tk1.dts               |   9 +-
 arch/arm/dts/tegra124-venice2.dts                  |   9 +-
 arch/arm/dts/tegra20-colibri_t20_iris.dts          |  10 +-
 arch/arm/dts/tegra20-harmony.dts                   |  28 +-
 arch/arm/dts/tegra20-medcom-wide.dts               |   9 +-
 arch/arm/dts/tegra20-paz00.dts                     |  18 +-
 arch/arm/dts/tegra20-seaboard.dts                  |  22 +-
 arch/arm/dts/tegra20-tamonten.dtsi                 |   9 +-
 arch/arm/dts/tegra20-tec.dts                       |   9 +-
 arch/arm/dts/tegra20-trimslice.dts                 |   8 +-
 arch/arm/dts/tegra20-ventana.dts                   |  18 +-
 arch/arm/dts/tegra20-whistler.dts                  |   2 +-
 arch/arm/dts/tegra30-apalis.dts                    |  10 +-
 arch/arm/dts/tegra30-beaver.dts                    |  10 +-
 arch/arm/dts/tegra30-cardhu.dts                    |   8 +-
 arch/arm/dts/tegra30-colibri.dts                   |   6 +-
 arch/arm/dts/tegra30-tamonten.dtsi                 |   4 +-
 arch/arm/include/asm/arch-pantheon/gpio.h          |   0
 arch/arm/include/asm/arch-tegra/tegra_mmc.h        |   7 +-
 arch/arm/include/asm/arch-tegra20/display.h        |   9 +-
 arch/arm/include/asm/arch-zynq/gpio.h              |  15 -
 arch/sandbox/dts/sandbox.dts                       |  11 +-
 common/cmd_demo.c                                  |  29 +-
 doc/device-tree-bindings/gpio/gpio-samsung.txt     |  41 +++
 doc/device-tree-bindings/gpio/gpio.txt             | 211 +++++++++++
 .../gpio/nvidia,tegra20-gpio.txt                   |  40 +++
 drivers/demo/demo-shape.c                          |  71 ++++
 drivers/demo/demo-uclass.c                         |  20 ++
 drivers/gpio/gpio-uclass.c                         | 396 +++++++++++++++++----
 drivers/gpio/s5p_gpio.c                            |  13 +-
 drivers/gpio/sandbox.c                             |  20 ++
 drivers/gpio/tegra_gpio.c                          |  18 +
 drivers/misc/cros_ec.c                             |  24 +-
 drivers/mmc/s5p_sdhci.c                            |  20 +-
 drivers/mmc/tegra_mmc.c                            |  36 +-
 drivers/mtd/nand/tegra_nand.c                      |   9 +-
 drivers/spi/soft_spi.c                             |  62 ++--
 drivers/usb/host/ehci-exynos.c                     |  10 +-
 drivers/usb/host/ehci-tegra.c                      |  38 +-
 drivers/usb/host/xhci-exynos5.c                    |  10 +-
 drivers/video/tegra.c                              |  54 ++-
 include/asm-generic/gpio.h                         | 265 ++++++++++++++
 include/cros_ec.h                                  |   3 +-
 include/dm-demo.h                                  |   4 +
 include/fdtdec.h                                   | 116 +++---
 include/sdhci.h                                    |   6 +-
 lib/fdtdec.c                                       | 195 +++++-----
 test/dm/gpio.c                                     |  69 +++-
 test/dm/test.dts                                   |  11 +-
 62 files changed, 1561 insertions(+), 535 deletions(-)
 create mode 100644 arch/arm/include/asm/arch-pantheon/gpio.h
 create mode 100644 doc/device-tree-bindings/gpio/gpio-samsung.txt
 create mode 100644 doc/device-tree-bindings/gpio/gpio.txt
 create mode 100644 doc/device-tree-bindings/gpio/nvidia,tegra20-gpio.txt

-- 
2.2.0.rc0.207.ga3a616c

^ permalink raw reply	[flat|nested] 49+ messages in thread

* [U-Boot] [PATCH 01/21] dm: gpio: Bring in GPIO device tree binding
  2015-01-06  3:05 [U-Boot] [PATCH 0/21] dm: Support GPIO device tree bindings in the uclass Simon Glass
@ 2015-01-06  3:05 ` Simon Glass
  2015-01-15  4:38   ` Simon Glass
  2015-01-06  3:05 ` [U-Boot] [PATCH 02/21] dm: exynos: " Simon Glass
                   ` (20 subsequent siblings)
  21 siblings, 1 reply; 49+ messages in thread
From: Simon Glass @ 2015-01-06  3:05 UTC (permalink / raw)
  To: u-boot

Add the binding file that we are about to support.

Signed-off-by: Simon Glass <sjg@chromium.org>
---

 doc/device-tree-bindings/gpio/gpio.txt | 211 +++++++++++++++++++++++++++++++++
 1 file changed, 211 insertions(+)
 create mode 100644 doc/device-tree-bindings/gpio/gpio.txt

diff --git a/doc/device-tree-bindings/gpio/gpio.txt b/doc/device-tree-bindings/gpio/gpio.txt
new file mode 100644
index 0000000..b9bd1d6
--- /dev/null
+++ b/doc/device-tree-bindings/gpio/gpio.txt
@@ -0,0 +1,211 @@
+Specifying GPIO information for devices
+============================================
+
+1) gpios property
+-----------------
+
+Nodes that makes use of GPIOs should specify them using one or more
+properties, each containing a 'gpio-list':
+
+	gpio-list ::= <single-gpio> [gpio-list]
+	single-gpio ::= <gpio-phandle> <gpio-specifier>
+	gpio-phandle : phandle to gpio controller node
+	gpio-specifier : Array of #gpio-cells specifying specific gpio
+			 (controller specific)
+
+GPIO properties should be named "[<name>-]gpios", with <name> being the purpose
+of this GPIO for the device. While a non-existent <name> is considered valid
+for compatibility reasons (resolving to the "gpios" property), it is not allowed
+for new bindings.
+
+GPIO properties can contain one or more GPIO phandles, but only in exceptional
+cases should they contain more than one. If your device uses several GPIOs with
+distinct functions, reference each of them under its own property, giving it a
+meaningful name. The only case where an array of GPIOs is accepted is when
+several GPIOs serve the same function (e.g. a parallel data line).
+
+The exact purpose of each gpios property must be documented in the device tree
+binding of the device.
+
+The following example could be used to describe GPIO pins used as device enable
+and bit-banged data signals:
+
+	gpio1: gpio1 {
+		gpio-controller
+		 #gpio-cells = <2>;
+	};
+	gpio2: gpio2 {
+		gpio-controller
+		 #gpio-cells = <1>;
+	};
+	[...]
+
+	enable-gpios = <&gpio2 2>;
+	data-gpios = <&gpio1 12 0>,
+		     <&gpio1 13 0>,
+		     <&gpio1 14 0>,
+		     <&gpio1 15 0>;
+
+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. Use the macros
+defined in include/dt-bindings/gpio/gpio.h whenever possible:
+
+Example of a node using GPIOs:
+
+	node {
+		enable-gpios = <&qe_pio_e 18 GPIO_ACTIVE_HIGH>;
+	};
+
+GPIO_ACTIVE_HIGH is 0, so in this example gpio-specifier is "18 0" and encodes
+GPIO pin number, and GPIO flags as accepted by the "qe_pio_e" gpio-controller.
+
+1.1) GPIO specifier best practices
+----------------------------------
+
+A gpio-specifier should contain a flag indicating the GPIO polarity; active-
+high or active-low. If it does, the follow best practices should be followed:
+
+The gpio-specifier's polarity flag should represent the physical level at the
+GPIO controller that achieves (or represents, for inputs) a logically asserted
+value at the device. The exact definition of logically asserted should be
+defined by the binding for the device. If the board inverts the signal between
+the GPIO controller and the device, then the gpio-specifier will represent the
+opposite physical level than the signal at the device's pin.
+
+When the device's signal polarity is configurable, the binding for the
+device must either:
+
+a) Define a single static polarity for the signal, with the expectation that
+any software using that binding would statically program the device to use
+that signal polarity.
+
+The static choice of polarity may be either:
+
+a1) (Preferred) Dictated by a binding-specific DT property.
+
+or:
+
+a2) Defined statically by the DT binding itself.
+
+In particular, the polarity cannot be derived from the gpio-specifier, since
+that would prevent the DT from separately representing the two orthogonal
+concepts of configurable signal polarity in the device, and possible board-
+level signal inversion.
+
+or:
+
+b) Pick a single option for device signal polarity, and document this choice
+in the binding. The gpio-specifier should represent the polarity of the signal
+(at the GPIO controller) assuming that the device is configured for this
+particular signal polarity choice. If software chooses to program the device
+to generate or receive a signal of the opposite polarity, software will be
+responsible for correctly interpreting (inverting) the GPIO signal at the GPIO
+controller.
+
+2) gpio-controller nodes
+------------------------
+
+Every GPIO controller node must contain both an empty "gpio-controller"
+property, and a #gpio-cells integer property, which indicates the number of
+cells in a gpio-specifier.
+
+Example of two SOC GPIO banks defined as gpio-controller nodes:
+
+	qe_pio_a: gpio-controller at 1400 {
+		compatible = "fsl,qe-pario-bank-a", "fsl,qe-pario-bank";
+		reg = <0x1400 0x18>;
+		gpio-controller;
+		#gpio-cells = <2>;
+	};
+
+	qe_pio_e: gpio-controller at 1460 {
+		compatible = "fsl,qe-pario-bank-e", "fsl,qe-pario-bank";
+		reg = <0x1460 0x18>;
+		gpio-controller;
+		#gpio-cells = <2>;
+	};
+
+2.1) gpio- and pin-controller interaction
+-----------------------------------------
+
+Some or all of the GPIOs provided by a GPIO controller may be routed to pins
+on the package via a pin controller. This allows muxing those pins between
+GPIO and other functions.
+
+It is useful to represent which GPIOs correspond to which pins on which pin
+controllers. The gpio-ranges property described below represents this, and
+contains information structures as follows:
+
+	gpio-range-list ::= <single-gpio-range> [gpio-range-list]
+	single-gpio-range ::= <numeric-gpio-range> | <named-gpio-range>
+	numeric-gpio-range ::=
+			<pinctrl-phandle> <gpio-base> <pinctrl-base> <count>
+	named-gpio-range ::= <pinctrl-phandle> <gpio-base> '<0 0>'
+	gpio-phandle : phandle to pin controller node.
+	gpio-base : Base GPIO ID in the GPIO controller
+	pinctrl-base : Base pinctrl pin ID in the pin controller
+	count : The number of GPIOs/pins in this range
+
+The "pin controller node" mentioned above must conform to the bindings
+described in ../pinctrl/pinctrl-bindings.txt.
+
+In case named gpio ranges are used (ranges with both <pinctrl-base> and
+<count> set to 0), the property gpio-ranges-group-names contains one string
+for every single-gpio-range in gpio-ranges:
+	gpiorange-names-list ::= <gpiorange-name> [gpiorange-names-list]
+	gpiorange-name : Name of the pingroup associated to the GPIO range in
+			the respective pin controller.
+
+Elements of gpiorange-names-list corresponding to numeric ranges contain
+the empty string. Elements of gpiorange-names-list corresponding to named
+ranges contain the name of a pin group defined in the respective pin
+controller. The number of pins/GPIOs in the range is the number of pins in
+that pin group.
+
+Previous versions of this binding required all pin controller nodes that
+were referenced by any gpio-ranges property to contain a property named
+#gpio-range-cells with value <3>. This requirement is now deprecated.
+However, that property may still exist in older device trees for
+compatibility reasons, and would still be required even in new device
+trees that need to be compatible with older software.
+
+Example 1:
+
+	qe_pio_e: gpio-controller at 1460 {
+		#gpio-cells = <2>;
+		compatible = "fsl,qe-pario-bank-e", "fsl,qe-pario-bank";
+		reg = <0x1460 0x18>;
+		gpio-controller;
+		gpio-ranges = <&pinctrl1 0 20 10>, <&pinctrl2 10 50 20>;
+	};
+
+Here, a single GPIO controller has GPIOs 0..9 routed to pin controller
+pinctrl1's pins 20..29, and GPIOs 10..19 routed to pin controller pinctrl2's
+pins 50..59.
+
+Example 2:
+
+	gpio_pio_i: gpio-controller at 14B0 {
+		#gpio-cells = <2>;
+		compatible = "fsl,qe-pario-bank-e", "fsl,qe-pario-bank";
+		reg = <0x1480 0x18>;
+		gpio-controller;
+		gpio-ranges =			<&pinctrl1 0 20 10>,
+						<&pinctrl2 10 0 0>,
+						<&pinctrl1 15 0 10>,
+						<&pinctrl2 25 0 0>;
+		gpio-ranges-group-names =	"",
+						"foo",
+						"",
+						"bar";
+	};
+
+Here, three GPIO ranges are defined wrt. two pin controllers. pinctrl1 GPIO
+ranges are defined using pin numbers whereas the GPIO ranges wrt. pinctrl2
+are named "foo" and "bar".
-- 
2.2.0.rc0.207.ga3a616c

^ permalink raw reply related	[flat|nested] 49+ messages in thread

* [U-Boot] [PATCH 02/21] dm: exynos: Bring in GPIO device tree binding
  2015-01-06  3:05 [U-Boot] [PATCH 0/21] dm: Support GPIO device tree bindings in the uclass Simon Glass
  2015-01-06  3:05 ` [U-Boot] [PATCH 01/21] dm: gpio: Bring in GPIO device tree binding Simon Glass
@ 2015-01-06  3:05 ` Simon Glass
  2015-01-15  4:38   ` Simon Glass
  2015-01-06  3:05 ` [U-Boot] [PATCH 03/21] dm: tegra: " Simon Glass
                   ` (19 subsequent siblings)
  21 siblings, 1 reply; 49+ messages in thread
From: Simon Glass @ 2015-01-06  3:05 UTC (permalink / raw)
  To: u-boot

At present the exynos GPIO driver does not fully support the existing device
tree binding, but add the binding file to cover the existing partial support.

Signed-off-by: Simon Glass <sjg@chromium.org>
---

 doc/device-tree-bindings/gpio/gpio-samsung.txt | 41 ++++++++++++++++++++++++++
 1 file changed, 41 insertions(+)
 create mode 100644 doc/device-tree-bindings/gpio/gpio-samsung.txt

diff --git a/doc/device-tree-bindings/gpio/gpio-samsung.txt b/doc/device-tree-bindings/gpio/gpio-samsung.txt
new file mode 100644
index 0000000..5375625
--- /dev/null
+++ b/doc/device-tree-bindings/gpio/gpio-samsung.txt
@@ -0,0 +1,41 @@
+Samsung Exynos4 GPIO Controller
+
+Required properties:
+- compatible: Compatible property value should be "samsung,exynos4-gpio>".
+
+- reg: Physical base address of the controller and length of memory mapped
+  region.
+
+- #gpio-cells: Should be 4. The syntax of the gpio specifier used by client nodes
+  should be the following with values derived from the SoC user manual.
+     <[phandle of the gpio controller node]
+      [pin number within the gpio controller]
+      [mux function]
+      [flags and pull up/down]
+      [drive strength]>
+
+  Values for gpio specifier:
+  - Pin number: is a value between 0 to 7.
+  - Flags and Pull Up/Down: 0 - Pull Up/Down Disabled.
+                            1 - Pull Down Enabled.
+                            3 - Pull Up Enabled.
+          Bit 16 (0x00010000) - Input is active low.
+  - Drive Strength: 0 - 1x,
+                    1 - 3x,
+                    2 - 2x,
+                    3 - 4x
+
+- gpio-controller: Specifies that the node is a gpio controller.
+- #address-cells: should be 1.
+- #size-cells: should be 1.
+
+Example:
+
+	gpa0: gpio-controller at 11400000 {
+		#address-cells = <1>;
+		#size-cells = <1>;
+		compatible = "samsung,exynos4-gpio";
+		reg = <0x11400000 0x20>;
+		#gpio-cells = <4>;
+		gpio-controller;
+	};
-- 
2.2.0.rc0.207.ga3a616c

^ permalink raw reply related	[flat|nested] 49+ messages in thread

* [U-Boot] [PATCH 03/21] dm: tegra: Bring in GPIO device tree binding
  2015-01-06  3:05 [U-Boot] [PATCH 0/21] dm: Support GPIO device tree bindings in the uclass Simon Glass
  2015-01-06  3:05 ` [U-Boot] [PATCH 01/21] dm: gpio: Bring in GPIO device tree binding Simon Glass
  2015-01-06  3:05 ` [U-Boot] [PATCH 02/21] dm: exynos: " Simon Glass
@ 2015-01-06  3:05 ` Simon Glass
  2015-01-15  4:39   ` Simon Glass
  2015-01-06  3:05 ` [U-Boot] [PATCH 04/21] dm: fdt: Add a function to decode phandles with arguments Simon Glass
                   ` (18 subsequent siblings)
  21 siblings, 1 reply; 49+ messages in thread
From: Simon Glass @ 2015-01-06  3:05 UTC (permalink / raw)
  To: u-boot

At present the tegra GPIO driver does not fully support the existing device
tree binding, but add the binding file to cover the existing partial support.

Signed-off-by: Simon Glass <sjg@chromium.org>
---

 .../gpio/nvidia,tegra20-gpio.txt                   | 40 ++++++++++++++++++++++
 1 file changed, 40 insertions(+)
 create mode 100644 doc/device-tree-bindings/gpio/nvidia,tegra20-gpio.txt

diff --git a/doc/device-tree-bindings/gpio/nvidia,tegra20-gpio.txt b/doc/device-tree-bindings/gpio/nvidia,tegra20-gpio.txt
new file mode 100644
index 0000000..023c952
--- /dev/null
+++ b/doc/device-tree-bindings/gpio/nvidia,tegra20-gpio.txt
@@ -0,0 +1,40 @@
+NVIDIA Tegra GPIO controller
+
+Required properties:
+- compatible : "nvidia,tegra<chip>-gpio"
+- reg : Physical base address and length of the controller's registers.
+- interrupts : The interrupt outputs from the controller. For Tegra20,
+  there should be 7 interrupts specified, and for Tegra30, there should
+  be 8 interrupts specified.
+- #gpio-cells : Should be two. The first cell is the pin number and the
+  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.
+- #interrupt-cells : Should be 2.
+  The first cell is the GPIO number.
+  The second cell is used to specify flags:
+    bits[3:0] trigger type and level flags:
+      1 = low-to-high edge triggered.
+      2 = high-to-low edge triggered.
+      4 = active high level-sensitive.
+      8 = active low level-sensitive.
+      Valid combinations are 1, 2, 3, 4, 8.
+- interrupt-controller : Marks the device node as an interrupt controller.
+
+Example:
+
+gpio: gpio at 6000d000 {
+	compatible = "nvidia,tegra20-gpio";
+	reg = < 0x6000d000 0x1000 >;
+	interrupts = < 0 32 0x04
+		       0 33 0x04
+		       0 34 0x04
+		       0 35 0x04
+		       0 55 0x04
+		       0 87 0x04
+		       0 89 0x04 >;
+	#gpio-cells = <2>;
+	gpio-controller;
+	#interrupt-cells = <2>;
+	interrupt-controller;
+};
-- 
2.2.0.rc0.207.ga3a616c

^ permalink raw reply related	[flat|nested] 49+ messages in thread

* [U-Boot] [PATCH 04/21] dm: fdt: Add a function to decode phandles with arguments
  2015-01-06  3:05 [U-Boot] [PATCH 0/21] dm: Support GPIO device tree bindings in the uclass Simon Glass
                   ` (2 preceding siblings ...)
  2015-01-06  3:05 ` [U-Boot] [PATCH 03/21] dm: tegra: " Simon Glass
@ 2015-01-06  3:05 ` Simon Glass
  2015-01-15  4:39   ` Simon Glass
  2015-01-15  7:29   ` Masahiro Yamada
  2015-01-06  3:05 ` [U-Boot] [PATCH 05/21] dm: gpio: Add a native driver model API Simon Glass
                   ` (17 subsequent siblings)
  21 siblings, 2 replies; 49+ messages in thread
From: Simon Glass @ 2015-01-06  3:05 UTC (permalink / raw)
  To: u-boot

For GPIOs and other functions we want to look up a phandle and then decode
a list of arguments for that phandle. Each phandle can have a different
number of arguments, specified by a property in the target node. This is
the "#gpio-cells" property for GPIOs.

Add a function to provide this feature, taken modified from Linux 3.18.

Signed-off-by: Simon Glass <sjg@chromium.org>
---

 include/fdtdec.h |  53 ++++++++++++++++++++++++
 lib/fdtdec.c     | 124 +++++++++++++++++++++++++++++++++++++++++++++++++++++++
 2 files changed, 177 insertions(+)

diff --git a/include/fdtdec.h b/include/fdtdec.h
index 5effa24..629e072 100644
--- a/include/fdtdec.h
+++ b/include/fdtdec.h
@@ -133,6 +133,59 @@ enum fdt_compat_id {
 	COMPAT_COUNT,
 };
 
+#define MAX_PHANDLE_ARGS 16
+struct fdtdec_phandle_args {
+	int node;
+	int args_count;
+	uint32_t args[MAX_PHANDLE_ARGS];
+};
+
+/**
+ * fdtdec_parse_phandle_with_args() - Find a node pointed by phandle in a list
+ *
+ * This function is useful to parse lists of phandles and their arguments.
+ *
+ * Example:
+ *
+ * phandle1: node1 {
+ *	#list-cells = <2>;
+ * }
+ *
+ * phandle2: node2 {
+ *	#list-cells = <1>;
+ * }
+ *
+ * node3 {
+ *	list = <&phandle1 1 2 &phandle2 3>;
+ * }
+ *
+ * To get a device_node of the `node2' node you may call this:
+ * fdtdec_parse_phandle_with_args(blob, node3, "list", "#list-cells", 0, 1,
+ *				  &args);
+ *
+ * (This function is a modified version of of_parse_phandle_with_args() from
+ * Linux 3.18)
+ *
+ * @blob:	Pointer to device tree
+ * @src_node:	Offset of device tree node containing a list
+ * @list_name:	property name that contains a list
+ * @cells_name:	property name that specifies the phandles' arguments count,
+ *		or NULL to use @cells_count
+ * @cells_count: Cell count to use if @cells_name is NULL
+ * @index:	index of a phandle to parse out
+ * @out_args:	optional pointer to output arguments structure (will be filled)
+ * @return 0 on success (with @out_args filled out if not NULL), -ENOENT if
+ *	@list_name does not exist, a phandle was not found, @cells_name
+ *	could not be found, the arguments were truncated or there were too
+ *	many arguments.
+ *
+ */
+int fdtdec_parse_phandle_with_args(const void *blob, int src_node,
+				   const char *list_name,
+				   const char *cells_name,
+				   int cell_count, int index,
+				   struct fdtdec_phandle_args *out_args);
+
 /* GPIOs are numbered from 0 */
 enum {
 	FDT_GPIO_NONE = -1U,	/* an invalid GPIO used to end our list */
diff --git a/lib/fdtdec.c b/lib/fdtdec.c
index 745b390..d6bc783 100644
--- a/lib/fdtdec.c
+++ b/lib/fdtdec.c
@@ -521,6 +521,130 @@ int fdtdec_get_bool(const void *blob, int node, const char *prop_name)
 	return cell != NULL;
 }
 
+int fdtdec_parse_phandle_with_args(const void *blob, int src_node,
+				   const char *list_name,
+				   const char *cells_name,
+				   int cell_count, int index,
+				   struct fdtdec_phandle_args *out_args)
+{
+	const __be32 *list, *list_end;
+	int rc = 0, size, cur_index = 0;
+	uint32_t count = 0;
+	int node = -1;
+	int phandle;
+
+	/* Retrieve the phandle list property */
+	list = fdt_getprop(blob, src_node, list_name, &size);
+	if (!list)
+		return -ENOENT;
+	list_end = list + size / sizeof(*list);
+
+	/* Loop over the phandles until all the requested entry is found */
+	while (list < list_end) {
+		rc = -EINVAL;
+		count = 0;
+
+		/*
+		 * If phandle is 0, then it is an empty entry with no
+		 * arguments.  Skip forward to the next entry.
+		 */
+		phandle = be32_to_cpup(list++);
+		if (phandle) {
+			/*
+			 * Find the provider node and parse the #*-cells
+			 * property to determine the argument length.
+			 *
+			 * This is not needed if the cell count is hard-coded
+			 * (i.e. cells_name not set, but cell_count is set),
+			 * except when we're going to return the found node
+			 * below.
+			 */
+			if (cells_name || cur_index == index) {
+				node = fdt_node_offset_by_phandle(blob,
+								  phandle);
+				if (!node) {
+					debug("%s: could not find phandle\n",
+					      fdt_get_name(blob, src_node,
+							   NULL));
+					goto err;
+				}
+			}
+
+			if (cells_name) {
+				count = fdtdec_get_int(blob, node, cells_name,
+						       -1);
+				if (count == -1) {
+					debug("%s: could not get %s for %s\n",
+					      fdt_get_name(blob, src_node,
+							   NULL),
+					      cells_name,
+					      fdt_get_name(blob, node,
+							   NULL));
+					goto err;
+				}
+			} else {
+				count = cell_count;
+			}
+
+			/*
+			 * Make sure that the arguments actually fit in the
+			 * remaining property data length
+			 */
+			if (list + count > list_end) {
+				debug("%s: arguments longer than property\n",
+				      fdt_get_name(blob, src_node, NULL));
+				goto err;
+			}
+		}
+
+		/*
+		 * All of the error cases above bail out of the loop, so at
+		 * this point, the parsing is successful. If the requested
+		 * index matches, then fill the out_args structure and return,
+		 * or return -ENOENT for an empty entry.
+		 */
+		rc = -ENOENT;
+		if (cur_index == index) {
+			if (!phandle)
+				goto err;
+
+			if (out_args) {
+				int i;
+
+				if (count > MAX_PHANDLE_ARGS) {
+					debug("%s: too many arguments %d\n",
+					      fdt_get_name(blob, src_node,
+							   NULL), count);
+					count = MAX_PHANDLE_ARGS;
+				}
+				out_args->node = node;
+				out_args->args_count = count;
+				for (i = 0; i < count; i++) {
+					out_args->args[i] =
+							be32_to_cpup(list++);
+				}
+			}
+
+			/* Found it! return success */
+			return 0;
+		}
+
+		node = -1;
+		list += count;
+		cur_index++;
+	}
+
+	/*
+	 * Result will be one of:
+	 * -ENOENT : index is for empty phandle
+	 * -EINVAL : parsing error on data
+	 * [1..n]  : Number of phandle (count mode; when index = -1)
+	 */
+	rc = index < 0 ? cur_index : -ENOENT;
+ err:
+	return rc;
+}
+
 /**
  * Decode a list of GPIOs from an FDT. This creates a list of GPIOs with no
  * terminating item.
-- 
2.2.0.rc0.207.ga3a616c

^ permalink raw reply related	[flat|nested] 49+ messages in thread

* [U-Boot] [PATCH 05/21] dm: gpio: Add a native driver model API
  2015-01-06  3:05 [U-Boot] [PATCH 0/21] dm: Support GPIO device tree bindings in the uclass Simon Glass
                   ` (3 preceding siblings ...)
  2015-01-06  3:05 ` [U-Boot] [PATCH 04/21] dm: fdt: Add a function to decode phandles with arguments Simon Glass
@ 2015-01-06  3:05 ` Simon Glass
  2015-01-15  4:39   ` Simon Glass
  2015-01-06  3:05 ` [U-Boot] [PATCH 06/21] dm: gpio: Add a driver GPIO translation method Simon Glass
                   ` (16 subsequent siblings)
  21 siblings, 1 reply; 49+ messages in thread
From: Simon Glass @ 2015-01-06  3:05 UTC (permalink / raw)
  To: u-boot

So far driver model's GPIO uclass just implements the existing GPIO API.
This has some limitations:

- it requires manual device tree munging to support GPIOs in device tree
    (fdtdec_get_gpio() and friends)
- it does not understand polarity
- it is somewhat slower since we must scan for the GPIO device each time
- Global GPIO numbering can change if other GPIO drivers are probed
- it requires extra steps to set the GPIO direction and value

The new functions have a dm_ prefix where necessary to avoid name conflicts
but we can remove that when it is no-longer needed. The new struct gpio_desc
holds all required information about the GPIO. For now this is intended to
be stored by the client requesting the GPIO, but in future it might be
brought into the uclass in some way.

With these changes the old GPIO API still works, and uses the driver model
API underneath.

Signed-off-by: Simon Glass <sjg@chromium.org>
---

 drivers/gpio/gpio-uclass.c | 218 ++++++++++++++++++++++++++++++---------------
 include/asm-generic/gpio.h |  16 ++++
 2 files changed, 163 insertions(+), 71 deletions(-)

diff --git a/drivers/gpio/gpio-uclass.c b/drivers/gpio/gpio-uclass.c
index 255700a..2f3c36b 100644
--- a/drivers/gpio/gpio-uclass.c
+++ b/drivers/gpio/gpio-uclass.c
@@ -13,14 +13,16 @@
 
 /**
  * gpio_to_device() - Convert global GPIO number to device, number
- * gpio:	The numeric representation of the GPIO
  *
  * Convert the GPIO number to an entry in the list of GPIOs
  * or GPIO blocks registered with the GPIO controller. Returns
  * entry on success, NULL on error.
+ *
+ * @gpio:	The numeric representation of the GPIO
+ * @desc:	Returns description (desc->flags will always be 0)
+ * @return 0 if found, -ENOENT if not found
  */
-static int gpio_to_device(unsigned int gpio, struct udevice **devp,
-			  unsigned int *offset)
+static int gpio_to_device(unsigned int gpio, struct gpio_desc *desc)
 {
 	struct gpio_dev_priv *uc_priv;
 	struct udevice *dev;
@@ -32,14 +34,15 @@ static int gpio_to_device(unsigned int gpio, struct udevice **devp,
 		uc_priv = dev->uclass_priv;
 		if (gpio >= uc_priv->gpio_base &&
 		    gpio < uc_priv->gpio_base + uc_priv->gpio_count) {
-			*devp = dev;
-			*offset = gpio - uc_priv->gpio_base;
+			desc->dev = dev;
+			desc->offset = gpio - uc_priv->gpio_base;
+			desc->flags = 0;
 			return 0;
 		}
 	}
 
 	/* No such GPIO */
-	return ret ? ret : -EINVAL;
+	return ret ? ret : -ENOENT;
 }
 
 int gpio_lookup_name(const char *name, struct udevice **devp,
@@ -88,6 +91,31 @@ int gpio_lookup_name(const char *name, struct udevice **devp,
 	return 0;
 }
 
+static int dm_gpio_request(struct gpio_desc *desc, const char *label)
+{
+	struct udevice *dev = desc->dev;
+	struct gpio_dev_priv *uc_priv;
+	char *str;
+	int ret;
+
+	uc_priv = dev->uclass_priv;
+	if (uc_priv->name[desc->offset])
+		return -EBUSY;
+	str = strdup(label);
+	if (!str)
+		return -ENOMEM;
+	if (gpio_get_ops(dev)->request) {
+		ret = gpio_get_ops(dev)->request(dev, desc->offset, label);
+		if (ret) {
+			free(str);
+			return ret;
+		}
+	}
+	uc_priv->name[desc->offset] = str;
+
+	return 0;
+}
+
 /**
  * gpio_request() - [COMPAT] Request GPIO
  * gpio:	GPIO number
@@ -102,32 +130,14 @@ int gpio_lookup_name(const char *name, struct udevice **devp,
  */
 int gpio_request(unsigned gpio, const char *label)
 {
-	struct gpio_dev_priv *uc_priv;
-	unsigned int offset;
-	struct udevice *dev;
-	char *str;
+	struct gpio_desc desc;
 	int ret;
 
-	ret = gpio_to_device(gpio, &dev, &offset);
+	ret = gpio_to_device(gpio, &desc);
 	if (ret)
 		return ret;
 
-	uc_priv = dev->uclass_priv;
-	if (uc_priv->name[offset])
-		return -EBUSY;
-	str = strdup(label);
-	if (!str)
-		return -ENOMEM;
-	if (gpio_get_ops(dev)->request) {
-		ret = gpio_get_ops(dev)->request(dev, offset, label);
-		if (ret) {
-			free(str);
-			return ret;
-		}
-	}
-	uc_priv->name[offset] = str;
-
-	return 0;
+	return dm_gpio_request(&desc, label);
 }
 
 /**
@@ -151,25 +161,11 @@ int gpio_requestf(unsigned gpio, const char *fmt, ...)
 	return gpio_request(gpio, buf);
 }
 
-/**
- * gpio_free() - [COMPAT] Relinquish GPIO
- * gpio:	GPIO number
- *
- * This function implements the API that's compatible with current
- * GPIO API used in U-Boot. The request is forwarded to particular
- * GPIO driver. Returns 0 on success, negative value on error.
- */
-int gpio_free(unsigned gpio)
+int _dm_gpio_free(struct udevice *dev, uint offset)
 {
 	struct gpio_dev_priv *uc_priv;
-	unsigned int offset;
-	struct udevice *dev;
 	int ret;
 
-	ret = gpio_to_device(gpio, &dev, &offset);
-	if (ret)
-		return ret;
-
 	uc_priv = dev->uclass_priv;
 	if (!uc_priv->name[offset])
 		return -ENXIO;
@@ -185,15 +181,35 @@ int gpio_free(unsigned gpio)
 	return 0;
 }
 
-static int check_reserved(struct udevice *dev, unsigned offset,
-			  const char *func)
+/**
+ * gpio_free() - [COMPAT] Relinquish GPIO
+ * gpio:	GPIO number
+ *
+ * This function implements the API that's compatible with current
+ * GPIO API used in U-Boot. The request is forwarded to particular
+ * GPIO driver. Returns 0 on success, negative value on error.
+ */
+int gpio_free(unsigned gpio)
 {
-	struct gpio_dev_priv *uc_priv = dev->uclass_priv;
+	struct gpio_desc desc;
+	int ret;
+
+	ret = gpio_to_device(gpio, &desc);
+	if (ret)
+		return ret;
+
+	return _dm_gpio_free(desc.dev, desc.offset);
+}
 
-	if (!uc_priv->name[offset]) {
+static int check_reserved(struct gpio_desc *desc, const char *func)
+{
+	struct gpio_dev_priv *uc_priv = desc->dev->uclass_priv;
+
+	if (!uc_priv->name[desc->offset]) {
 		printf("%s: %s: error: gpio %s%d not reserved\n",
-		       dev->name, func,
-		       uc_priv->bank_name ? uc_priv->bank_name : "", offset);
+		       desc->dev->name, func,
+		       uc_priv->bank_name ? uc_priv->bank_name : "",
+		       desc->offset);
 		return -EBUSY;
 	}
 
@@ -210,16 +226,17 @@ static int check_reserved(struct udevice *dev, unsigned offset,
  */
 int gpio_direction_input(unsigned gpio)
 {
-	unsigned int offset;
-	struct udevice *dev;
+	struct gpio_desc desc;
 	int ret;
 
-	ret = gpio_to_device(gpio, &dev, &offset);
+	ret = gpio_to_device(gpio, &desc);
+	if (ret)
+		return ret;
+	ret = check_reserved(&desc, "dir_input");
 	if (ret)
 		return ret;
-	ret = check_reserved(dev, offset, "dir_input");
 
-	return ret ? ret : gpio_get_ops(dev)->direction_input(dev, offset);
+	return gpio_get_ops(desc.dev)->direction_input(desc.dev, desc.offset);
 }
 
 /**
@@ -233,17 +250,81 @@ int gpio_direction_input(unsigned gpio)
  */
 int gpio_direction_output(unsigned gpio, int value)
 {
-	unsigned int offset;
-	struct udevice *dev;
+	struct gpio_desc desc;
 	int ret;
 
-	ret = gpio_to_device(gpio, &dev, &offset);
+	ret = gpio_to_device(gpio, &desc);
+	if (ret)
+		return ret;
+	ret = check_reserved(&desc, "dir_output");
+	if (ret)
+		return ret;
+
+	return gpio_get_ops(desc.dev)->direction_output(desc.dev,
+							desc.offset, value);
+}
+
+int dm_gpio_get_value(struct gpio_desc *desc)
+{
+	int value;
+	int ret;
+
+	ret = check_reserved(desc, "get_value");
 	if (ret)
 		return ret;
-	ret = check_reserved(dev, offset, "dir_output");
 
-	return ret ? ret :
-		gpio_get_ops(dev)->direction_output(dev, offset, value);
+	value = gpio_get_ops(desc->dev)->get_value(desc->dev, desc->offset);
+
+	return desc->flags & GPIOD_ACTIVE_LOW ? !value : value;
+}
+
+int dm_gpio_set_value(struct gpio_desc *desc, int value)
+{
+	int ret;
+
+	ret = check_reserved(desc, "set_value");
+	if (ret)
+		return ret;
+
+	if (desc->flags & GPIOD_ACTIVE_LOW)
+		value = !value;
+	gpio_get_ops(desc->dev)->set_value(desc->dev, desc->offset, value);
+	return 0;
+}
+
+int dm_gpio_set_dir_flags(struct gpio_desc *desc, ulong flags)
+{
+	struct udevice *dev = desc->dev;
+	struct dm_gpio_ops *ops = gpio_get_ops(dev);
+	int ret;
+
+	ret = check_reserved(desc, "set_dir");
+	if (ret)
+		return ret;
+
+	if (flags & GPIOD_IS_OUT) {
+		int value = flags & GPIOD_IS_OUT_ACTIVE ? 1 : 0;
+
+		if (flags & GPIOD_ACTIVE_LOW)
+			value = !value;
+		ret = ops->direction_output(dev, desc->offset, value);
+	} else  if (flags & GPIOD_IS_IN) {
+		ret = ops->direction_input(dev, desc->offset);
+	}
+	if (ret)
+		return ret;
+	/*
+	 * Update desc->flags here, so that GPIO_ACTIVE_LOW is honoured in
+	 * futures
+	 */
+	desc->flags = flags;
+
+	return 0;
+}
+
+int dm_gpio_set_dir(struct gpio_desc *desc)
+{
+	return dm_gpio_set_dir_flags(desc, desc->flags);
 }
 
 /**
@@ -257,16 +338,14 @@ int gpio_direction_output(unsigned gpio, int value)
  */
 int gpio_get_value(unsigned gpio)
 {
-	unsigned int offset;
-	struct udevice *dev;
 	int ret;
 
-	ret = gpio_to_device(gpio, &dev, &offset);
+	struct gpio_desc desc;
+
+	ret = gpio_to_device(gpio, &desc);
 	if (ret)
 		return ret;
-	ret = check_reserved(dev, offset, "get_value");
-
-	return ret ? ret : gpio_get_ops(dev)->get_value(dev, offset);
+	return dm_gpio_get_value(&desc);
 }
 
 /**
@@ -280,16 +359,13 @@ int gpio_get_value(unsigned gpio)
  */
 int gpio_set_value(unsigned gpio, int value)
 {
-	unsigned int offset;
-	struct udevice *dev;
+	struct gpio_desc desc;
 	int ret;
 
-	ret = gpio_to_device(gpio, &dev, &offset);
+	ret = gpio_to_device(gpio, &desc);
 	if (ret)
 		return ret;
-	ret = check_reserved(dev, offset, "set_value");
-
-	return ret ? ret : gpio_get_ops(dev)->set_value(dev, offset, value);
+	return dm_gpio_set_value(&desc, value);
 }
 
 const char *gpio_get_bank_info(struct udevice *dev, int *bit_count)
diff --git a/include/asm-generic/gpio.h b/include/asm-generic/gpio.h
index 36a36c6..a827a56 100644
--- a/include/asm-generic/gpio.h
+++ b/include/asm-generic/gpio.h
@@ -95,6 +95,22 @@ enum gpio_func_t {
 
 struct udevice;
 
+struct gpio_desc {
+	struct udevice *dev;	/* Device, NULL for invalid GPIO */
+	unsigned long flags;
+#define GPIOD_REQUESTED		(1 << 0)	/* Requested/claimed */
+#define GPIOD_IS_OUT		(1 << 1)	/* GPIO is an output */
+#define GPIOD_IS_IN		(1 << 2)	/* GPIO is an output */
+#define GPIOD_ACTIVE_LOW	(1 << 3)	/* value has active low */
+#define GPIOD_IS_OUT_ACTIVE	(1 << 4)	/* set output active */
+
+	uint offset;		/* GPIO offset within the device */
+	/*
+	 * We could consider adding the GPIO label in here. Possibly we could
+	 * use this structure for internal GPIO information.
+	 */
+};
+
 /**
  * gpio_get_status() - get the current GPIO status as a string
  *
-- 
2.2.0.rc0.207.ga3a616c

^ permalink raw reply related	[flat|nested] 49+ messages in thread

* [U-Boot] [PATCH 06/21] dm: gpio: Add a driver GPIO translation method
  2015-01-06  3:05 [U-Boot] [PATCH 0/21] dm: Support GPIO device tree bindings in the uclass Simon Glass
                   ` (4 preceding siblings ...)
  2015-01-06  3:05 ` [U-Boot] [PATCH 05/21] dm: gpio: Add a native driver model API Simon Glass
@ 2015-01-06  3:05 ` Simon Glass
  2015-01-15  4:39   ` Simon Glass
  2015-01-06  3:05 ` [U-Boot] [PATCH 07/21] dm: gpio: Add better functions to request GPIOs Simon Glass
                   ` (15 subsequent siblings)
  21 siblings, 1 reply; 49+ messages in thread
From: Simon Glass @ 2015-01-06  3:05 UTC (permalink / raw)
  To: u-boot

Only the GPIO driver knows about the full GPIO device tree binding used by
a device. Add a method to allow the driver to provide this information to the
uclass, including the GPIO offset within the device and flags such as the
polarity.

Signed-off-by: Simon Glass <sjg@chromium.org>
---

 drivers/gpio/gpio-uclass.c | 16 ++++++++++++++++
 include/asm-generic/gpio.h | 29 +++++++++++++++++++++++++++++
 2 files changed, 45 insertions(+)

diff --git a/drivers/gpio/gpio-uclass.c b/drivers/gpio/gpio-uclass.c
index 2f3c36b..0a4d9e4 100644
--- a/drivers/gpio/gpio-uclass.c
+++ b/drivers/gpio/gpio-uclass.c
@@ -7,6 +7,7 @@
 #include <common.h>
 #include <dm.h>
 #include <errno.h>
+#include <fdtdec.h>
 #include <malloc.h>
 #include <asm/gpio.h>
 #include <linux/ctype.h>
@@ -91,6 +92,21 @@ int gpio_lookup_name(const char *name, struct udevice **devp,
 	return 0;
 }
 
+int gpio_find_and_xlate(struct gpio_desc *desc,
+			struct fdtdec_phandle_args *args)
+{
+	struct dm_gpio_ops *ops = gpio_get_ops(desc->dev);
+
+	/* Use the first argument as the offset by default */
+	if (args->args_count > 0)
+		desc->offset = args->args[0];
+	else
+		desc->offset = -1;
+	desc->flags = 0;
+
+	return ops->xlate ? ops->xlate(desc->dev, desc, args) : 0;
+}
+
 static int dm_gpio_request(struct gpio_desc *desc, const char *label)
 {
 	struct udevice *dev = desc->dev;
diff --git a/include/asm-generic/gpio.h b/include/asm-generic/gpio.h
index a827a56..c08c963 100644
--- a/include/asm-generic/gpio.h
+++ b/include/asm-generic/gpio.h
@@ -171,6 +171,8 @@ int gpio_get_raw_function(struct udevice *dev, int offset, const char **namep);
 int gpio_requestf(unsigned gpio, const char *fmt, ...)
 		__attribute__ ((format (__printf__, 2, 3)));
 
+struct fdtdec_phandle_args;
+
 /**
  * struct struct dm_gpio_ops - Driver model GPIO operations
  *
@@ -214,6 +216,33 @@ struct dm_gpio_ops {
 	 * @return current function - GPIOF_...
 	 */
 	int (*get_function)(struct udevice *dev, unsigned offset);
+
+	/**
+	 * xlate() - Translate phandle arguments into a GPIO description
+	 *
+	 * This function should set up the fields in desc according to the
+	 * information in the arguments. The uclass will have set up:
+	 *
+	 *   @desc->dev to @dev
+	 *   @desc->flags to 0
+	 *   @desc->offset to the value of the first argument in args, if any,
+	 *		otherwise -1 (which is invalid)
+	 *
+	 * This method is optional so if the above defaults suit it can be
+	 * omitted. Typical behaviour is to set up the GPIOD_ACTIVE_LOW flag
+	 * in desc->flags.
+	 *
+	 * Note that @dev is passed in as a parameter to follow driver model
+	 * uclass conventions, even though it is already available as
+	 * desc->dev.
+	 *
+	 * @dev:	GPIO device
+	 * @desc:	Place to put GPIO description
+	 * @args:	Arguments provided in descripion
+	 * @return 0 if OK, -ve on error
+	 */
+	int (*xlate)(struct udevice *dev, struct gpio_desc *desc,
+		     struct fdtdec_phandle_args *args);
 };
 
 /**
-- 
2.2.0.rc0.207.ga3a616c

^ permalink raw reply related	[flat|nested] 49+ messages in thread

* [U-Boot] [PATCH 07/21] dm: gpio: Add better functions to request GPIOs
  2015-01-06  3:05 [U-Boot] [PATCH 0/21] dm: Support GPIO device tree bindings in the uclass Simon Glass
                   ` (5 preceding siblings ...)
  2015-01-06  3:05 ` [U-Boot] [PATCH 06/21] dm: gpio: Add a driver GPIO translation method Simon Glass
@ 2015-01-06  3:05 ` Simon Glass
  2015-01-15  4:39   ` Simon Glass
  2015-01-06  3:05 ` [U-Boot] [PATCH 08/21] dm: gpio: Mark the old GPIO API deprecated Simon Glass
                   ` (14 subsequent siblings)
  21 siblings, 1 reply; 49+ messages in thread
From: Simon Glass @ 2015-01-06  3:05 UTC (permalink / raw)
  To: u-boot

At present U-Boot sort-of supports the standard way of reading GPIOs from
device tree nodes, but the support is incomplete, a bit clunky and only
works for GPIO bindings where #gpio-cells is 2.

Add new functions to request GPIOs, taking full account of the device
tree binding. These permit requesting a GPIO with a simple call like:

   gpio_request_by_name(dev, "cd-gpios", 0, &desc, GPIOD_IS_IN);

This will request the GPIO, looking at the device's node which might be
this, for example:

   cd-gpios = <&gpio TEGRA_GPIO(B, 3) GPIO_ACTIVE_LOW>;

The GPIO will be set to input mode in this case and polarity will be
honoured by the GPIO calls.

It is also possible to request and free a list of GPIOs.

Signed-off-by: Simon Glass <sjg@chromium.org>
---

 drivers/gpio/gpio-uclass.c | 166 ++++++++++++++++++++++++++++++++++++-
 drivers/gpio/sandbox.c     |  20 +++++
 include/asm-generic/gpio.h | 199 +++++++++++++++++++++++++++++++++++++++++++++
 test/dm/gpio.c             |  69 +++++++++++++++-
 test/dm/test.dts           |  11 ++-
 5 files changed, 461 insertions(+), 4 deletions(-)

diff --git a/drivers/gpio/gpio-uclass.c b/drivers/gpio/gpio-uclass.c
index 0a4d9e4..a69bbd2 100644
--- a/drivers/gpio/gpio-uclass.c
+++ b/drivers/gpio/gpio-uclass.c
@@ -12,6 +12,8 @@
 #include <asm/gpio.h>
 #include <linux/ctype.h>
 
+DECLARE_GLOBAL_DATA_PTR;
+
 /**
  * gpio_to_device() - Convert global GPIO number to device, number
  *
@@ -92,8 +94,8 @@ int gpio_lookup_name(const char *name, struct udevice **devp,
 	return 0;
 }
 
-int gpio_find_and_xlate(struct gpio_desc *desc,
-			struct fdtdec_phandle_args *args)
+static int gpio_find_and_xlate(struct gpio_desc *desc,
+			       struct fdtdec_phandle_args *args)
 {
 	struct dm_gpio_ops *ops = gpio_get_ops(desc->dev);
 
@@ -132,6 +134,17 @@ static int dm_gpio_request(struct gpio_desc *desc, const char *label)
 	return 0;
 }
 
+static int dm_gpio_requestf(struct gpio_desc *desc, const char *fmt, ...)
+{
+	va_list args;
+	char buf[40];
+
+	va_start(args, fmt);
+	vscnprintf(buf, sizeof(buf), fmt, args);
+	va_end(args);
+	return dm_gpio_request(desc, buf);
+}
+
 /**
  * gpio_request() - [COMPAT] Request GPIO
  * gpio:	GPIO number
@@ -501,6 +514,155 @@ unsigned gpio_get_values_as_int(const int *gpio_num_array)
 	return vector;
 }
 
+static int _gpio_request_by_name_nodev(const void *blob, int node,
+				       const char *list_name, int index,
+				       struct gpio_desc *desc, int flags,
+				       bool add_index)
+{
+	struct fdtdec_phandle_args args;
+	int ret;
+
+	desc->dev = NULL;
+	desc->offset = 0;
+	ret = fdtdec_parse_phandle_with_args(blob, node, list_name,
+					     "#gpio-cells", 0, index, &args);
+	if (ret) {
+		debug("%s: fdtdec_parse_phandle_with_args failed\n", __func__);
+		goto err;
+	}
+
+	ret = uclass_get_device_by_of_offset(UCLASS_GPIO, args.node,
+					     &desc->dev);
+	if (ret) {
+		debug("%s: uclass_get_device_by_of_offset failed\n", __func__);
+		goto err;
+	}
+	ret = gpio_find_and_xlate(desc, &args);
+	if (ret) {
+		debug("%s: gpio_find_and_xlate failed\n", __func__);
+		goto err;
+	}
+	ret = dm_gpio_requestf(desc, add_index ? "%s.%s%d" : "%s.%s",
+			       fdt_get_name(blob, node, NULL),
+			       list_name, index);
+	if (ret) {
+		debug("%s: dm_gpio_requestf failed\n", __func__);
+		goto err;
+	}
+	ret = dm_gpio_set_dir_flags(desc, flags | desc->flags);
+	if (ret) {
+		debug("%s: dm_gpio_set_dir failed\n", __func__);
+		goto err;
+	}
+
+	return 0;
+err:
+	debug("%s: Node '%s', property '%s', failed to request GPIO index %d: %d\n",
+	      __func__, fdt_get_name(blob, node, NULL), list_name, index, ret);
+	return ret;
+}
+
+int gpio_request_by_name_nodev(const void *blob, int node,
+			       const char *list_name, int index,
+			       struct gpio_desc *desc, int flags)
+{
+	return _gpio_request_by_name_nodev(blob, node, list_name, index, desc,
+					   flags, index > 0);
+}
+
+int gpio_request_by_name(struct udevice *dev,  const char *list_name, int index,
+			 struct gpio_desc *desc, int flags)
+{
+	/*
+	 * This isn't ideal since we don't use dev->name in the debug()
+	 * calls in gpio_request_by_name(), but we can do this until
+	 * gpio_request_by_name_nodev() can be dropped.
+	 */
+	return gpio_request_by_name_nodev(gd->fdt_blob, dev->of_offset,
+					  list_name, index, desc, flags);
+}
+
+int gpio_request_list_by_name_nodev(const void *blob, int node,
+				    const char *list_name,
+				    struct gpio_desc *desc, int max_count,
+				    int flags)
+{
+	int count;
+	int ret;
+
+	for (count = 0; ; count++) {
+		if (count >= max_count) {
+			ret = -ENOSPC;
+			goto err;
+		}
+		ret = _gpio_request_by_name_nodev(blob, node, list_name, count,
+						  &desc[count], flags, true);
+		if (ret == -ENOENT)
+			break;
+		else if (ret)
+			goto err;
+	}
+
+	/* We ran out of GPIOs in the list */
+	return count;
+
+err:
+	gpio_free_list_nodev(desc, count - 1);
+
+	return ret;
+}
+
+int gpio_request_list_by_name(struct udevice *dev, const char *list_name,
+			      struct gpio_desc *desc, int max_count,
+			      int flags)
+{
+	/*
+	 * This isn't ideal since we don't use dev->name in the debug()
+	 * calls in gpio_request_by_name(), but we can do this until
+	 * gpio_request_list_by_name_nodev() can be dropped.
+	 */
+	return gpio_request_list_by_name_nodev(gd->fdt_blob, dev->of_offset,
+					       list_name, desc, max_count,
+					       flags);
+}
+
+int gpio_get_list_count(struct udevice *dev, const char *list_name)
+{
+	int ret;
+
+	ret = fdtdec_parse_phandle_with_args(gd->fdt_blob, dev->of_offset,
+					     list_name, "#gpio-cells", 0, -1,
+					     NULL);
+	if (ret) {
+		debug("%s: Node '%s', property '%s', GPIO count failed: %d\n",
+		      __func__, dev->name, list_name, ret);
+	}
+
+	return ret;
+}
+
+int dm_gpio_free(struct udevice *dev, struct gpio_desc *desc)
+{
+	/* For now, we don't do any checking of dev */
+	return _dm_gpio_free(desc->dev, desc->offset);
+}
+
+int gpio_free_list(struct udevice *dev, struct gpio_desc *desc, int count)
+{
+	int i;
+
+	/* For now, we don't do any checking of dev */
+	for (i = 0; i < count; i++)
+		dm_gpio_free(dev, &desc[i]);
+
+	return 0;
+}
+
+int gpio_free_list_nodev(struct gpio_desc *desc, int count)
+{
+	return gpio_free_list(NULL, desc, count);
+}
+
 /* We need to renumber the GPIOs when any driver is probed/removed */
 static int gpio_renumber(struct udevice *removed_dev)
 {
diff --git a/drivers/gpio/sandbox.c b/drivers/gpio/sandbox.c
index 53c80d5..d564c25 100644
--- a/drivers/gpio/sandbox.c
+++ b/drivers/gpio/sandbox.c
@@ -8,6 +8,7 @@
 #include <fdtdec.h>
 #include <malloc.h>
 #include <asm/gpio.h>
+#include <dt-bindings/gpio/gpio.h>
 
 DECLARE_GLOBAL_DATA_PTR;
 
@@ -130,12 +131,31 @@ static int sb_gpio_get_function(struct udevice *dev, unsigned offset)
 	return GPIOF_INPUT;
 }
 
+static int sb_gpio_xlate(struct udevice *dev, struct gpio_desc *desc,
+			 struct fdtdec_phandle_args *args)
+{
+	desc->offset = args->args[0];
+	if (args->args_count < 2)
+		return 0;
+	if (args->args[1] & GPIO_ACTIVE_LOW)
+		desc->flags |= GPIOD_ACTIVE_LOW;
+	if (args->args[1] & 2)
+		desc->flags |= GPIOD_IS_IN;
+	if (args->args[1] & 4)
+		desc->flags |= GPIOD_IS_OUT;
+	if (args->args[1] & 8)
+		desc->flags |= GPIOD_IS_OUT_ACTIVE;
+
+	return 0;
+}
+
 static const struct dm_gpio_ops gpio_sandbox_ops = {
 	.direction_input	= sb_gpio_direction_input,
 	.direction_output	= sb_gpio_direction_output,
 	.get_value		= sb_gpio_get_value,
 	.set_value		= sb_gpio_set_value,
 	.get_function		= sb_gpio_get_function,
+	.xlate			= sb_gpio_xlate,
 };
 
 static int sandbox_gpio_ofdata_to_platdata(struct udevice *dev)
diff --git a/include/asm-generic/gpio.h b/include/asm-generic/gpio.h
index c08c963..2653415 100644
--- a/include/asm-generic/gpio.h
+++ b/include/asm-generic/gpio.h
@@ -112,6 +112,18 @@ struct gpio_desc {
 };
 
 /**
+ * dm_gpio_is_valid() - Check if a GPIO is gpio_is_valie
+ *
+ * @desc:	GPIO description containing device, offset and flags,
+ *		previously returned by gpio_request_by_name()
+ * @return true if valid, false if not
+ */
+static inline bool dm_gpio_is_valid(struct gpio_desc *desc)
+{
+	return desc->dev != NULL;
+}
+
+/**
  * gpio_get_status() - get the current GPIO status as a string
  *
  * Obtain the current GPIO status as a string which can be presented to the
@@ -313,4 +325,191 @@ int gpio_lookup_name(const char *name, struct udevice **devp,
  */
 unsigned gpio_get_values_as_int(const int *gpio_list);
 
+/**
+ * gpio_request_by_name() - Locate and request a GPIO by name
+ *
+ * This operates by looking up the given list name in the device (device
+ * tree property) and requesting the GPIO for use. The property must exist
+ * in @dev's node.
+ *
+ * Use @flags to specify whether the GPIO should be an input or output. In
+ * principle this can also come from the device tree binding but most
+ * bindings don't provide this information. Specifically, when the GPIO uclass
+ * calls the xlate() method, it can return default flags, which are then
+ * ORed with this @flags.
+ *
+ * If we find that requesting the GPIO is not always needed we could add a
+ * new function or a new GPIOD_NO_REQUEST flag.
+ *
+ * At present driver model has no reference counting so if one device
+ * requests a GPIO which subsequently is unbound, the @desc->dev pointer
+ * will be invalid. However this will only happen if the GPIO device is
+ * unbound, not if it is removed, so this seems like a reasonable limitation
+ * for now. There is no real use case for unbinding drivers in normal
+ * operation.
+ *
+ * The device tree binding is doc/device-tree-bindings/gpio/gpio.txt in
+ * generate terms and each specific device may add additional details in
+ * a binding file in the same directory.
+ *
+ * @dev:	Device requesting the GPIO
+ * @list_name:	Name of GPIO list (e.g. "board-id-gpios")
+ * @index:	Index number of the GPIO in that list use request (0=first)
+ * @desc:	Returns GPIO description information. If there is no such
+ *		GPIO, dev->dev will be NULL.
+ * @flags:	Indicates the GPIO input/output settings (GPIOD_...)
+ * @return 0 if OK, -ENOENT if the GPIO does not exist, -EINVAL if there is
+ * something wrong with the list, or other -ve for another error (e.g.
+ * -EBUSY if a GPIO was already requested)
+ */
+int gpio_request_by_name(struct udevice *dev, const char *list_name,
+			 int index, struct gpio_desc *desc, int flags);
+
+/**
+ * gpio_request_list_by_name() - Request a list of GPIOs
+ *
+ * Reads all the GPIOs from a list and requetss them. See
+ * gpio_request_by_name() for additional details. Lists should not be
+ * misused to hold unrelated or optional GPIOs. They should only be used
+ * for things like parallel data lines. A zero phandle terminates the list
+ * the list.
+ *
+ * This function will either succeed, and request all GPIOs in the list, or
+ * fail and request none (it will free already-requested GPIOs in case of
+ * an error part-way through).
+ *
+ * @dev:	Device requesting the GPIO
+ * @list_name:	Name of GPIO list (e.g. "board-id-gpios")
+ * @desc_list:	Returns a list of GPIO description information
+ * @max_count:	Maximum number of GPIOs to return (@desc_list must be at least
+ *		this big)
+ * @flags:	Indicates the GPIO input/output settings (GPIOD_...)
+ * @return number of GPIOs requested, or -ve on error
+ */
+int gpio_request_list_by_name(struct udevice *dev, const char *list_name,
+			      struct gpio_desc *desc_list, int max_count,
+			      int flags);
+
+/**
+ * gpio_get_list_count() - Returns the number of GPIOs in a list
+ *
+ * Counts the GPIOs in a list. See gpio_request_by_name() for additional
+ * details.
+ *
+ * @dev:	Device requesting the GPIO
+ * @list_name:	Name of GPIO list (e.g. "board-id-gpios")
+ * @return number of GPIOs (0 for an empty property) or -ENOENT if the list
+ * does not exist
+ */
+int gpio_get_list_count(struct udevice *dev, const char *list_name);
+
+/**
+ * gpio_request_by_name_nodev() - request GPIOs without a device
+ *
+ * This is a version of gpio_request_list_by_name() that does not use a
+ * device. Avoid it unless the caller is not yet using driver model
+ */
+int gpio_request_by_name_nodev(const void *blob, int node,
+			       const char *list_name,
+			       int index, struct gpio_desc *desc, int flags);
+
+/**
+ * gpio_request_list_by_name_nodev() - request GPIOs without a device
+ *
+ * This is a version of gpio_request_list_by_name() that does not use a
+ * device. Avoid it unless the caller is not yet using driver model
+ */
+int gpio_request_list_by_name_nodev(const void *blob, int node,
+				    const char *list_name,
+				    struct gpio_desc *desc_list, int max_count,
+				    int flags);
+
+/**
+ * dm_gpio_free() - Free a single GPIO
+ *
+ * This frees a single GPIOs previously returned from gpio_request_by_name().
+ *
+ * @dev:	Device which requested the GPIO
+ * @desc:	GPIO to free
+ * @return 0 if OK, -ve on error
+ */
+int dm_gpio_free(struct udevice *dev, struct gpio_desc *desc);
+
+/**
+ * gpio_free_list() - Free a list of GPIOs
+ *
+ * This frees a list of GPIOs previously returned from
+ * gpio_request_list_by_name().
+ *
+ * @dev:	Device which requested the GPIOs
+ * @desc:	List of GPIOs to free
+ * @count:	Number of GPIOs in the list
+ * @return 0 if OK, -ve on error
+ */
+int gpio_free_list(struct udevice *dev, struct gpio_desc *desc, int count);
+
+/**
+ * gpio_free_list_nodev() - free GPIOs without a device
+ *
+ * This is a version of gpio_free_list() that does not use a
+ * device. Avoid it unless the caller is not yet using driver model
+ */
+int gpio_free_list_nodev(struct gpio_desc *desc, int count);
+
+/**
+ * dm_gpio_get_value() - Get the value of a GPIO
+ *
+ * This is the driver model version of the existing gpio_get_value() function
+ * and should be used instead of that.
+ *
+ * For now, these functions have a dm_ prefix since they conflict with
+ * existing names.
+ *
+ * @desc:	GPIO description containing device, offset and flags,
+ *		previously returned by gpio_request_by_name()
+ * @return GPIO value (0 for inactive, 1 for active) or -ve on error
+ */
+int dm_gpio_get_value(struct gpio_desc *desc);
+
+int dm_gpio_set_value(struct gpio_desc *desc, int value);
+
+/**
+ * dm_gpio_set_dir() - Set the direction for a GPIO
+ *
+ * This sets up the direction according tot the provided flags. It will do
+ * nothing unless the direction is actually specified.
+ *
+ * @desc:	GPIO description containing device, offset and flags,
+ *		previously returned by gpio_request_by_name()
+ * @return 0 if OK, -ve on error
+ */
+int dm_gpio_set_dir(struct gpio_desc *desc);
+
+/**
+ * dm_gpio_set_dir_flags() - Set direction using specific flags
+ *
+ * This is like dm_gpio_set_dir() except that the flags value is provided
+ * instead of being used from desc->flags. This is needed because in many
+ * cases the GPIO description does not include direction information.
+ * Note that desc->flags is updated by this function.
+ *
+ * @desc:	GPIO description containing device, offset and flags,
+ *		previously returned by gpio_request_by_name()
+ * @flags:	New flags to use
+ * @return 0 if OK, -ve on error, in which case desc->flags is not updated
+ */
+int dm_gpio_set_dir_flags(struct gpio_desc *desc, ulong flags);
+
+/**
+ * gpio_get_number() - Get the global GPIO number of a GPIO
+ *
+ * This should only be used for debugging or interest. It returns the nummber
+ * that should be used for gpio_get_value() etc. to access this GPIO.
+ *
+ * @desc:	GPIO description containing device, offset and flags,
+ *		previously returned by gpio_request_by_name()
+ * @return GPIO number, or -ve if not found
+ */
+int gpio_get_number(struct gpio_desc *desc);
+
 #endif	/* _ASM_GENERIC_GPIO_H_ */
diff --git a/test/dm/gpio.c b/test/dm/gpio.c
index 94bd0d9..b29daf1 100644
--- a/test/dm/gpio.c
+++ b/test/dm/gpio.c
@@ -174,5 +174,72 @@ static int dm_test_gpio_leak(struct dm_test_state *dms)
 
 	return 0;
 }
-
 DM_TEST(dm_test_gpio_leak, DM_TESTF_SCAN_PDATA | DM_TESTF_SCAN_FDT);
+
+/* Test that we can find GPIOs using phandles */
+static int dm_test_gpio_phandles(struct dm_test_state *dms)
+{
+	struct gpio_desc desc, desc_list[8], desc_list2[8];
+	struct udevice *dev, *gpio_a, *gpio_b;
+
+	ut_assertok(uclass_get_device(UCLASS_TEST_FDT, 0, &dev));
+	ut_asserteq_str("a-test", dev->name);
+
+	ut_assertok(gpio_request_by_name(dev, "test-gpios", 1, &desc, 0));
+	ut_assertok(uclass_get_device(UCLASS_GPIO, 1, &gpio_a));
+	ut_assertok(uclass_get_device(UCLASS_GPIO, 2, &gpio_b));
+	ut_asserteq_str("base-gpios", gpio_a->name);
+	ut_asserteq(true, !!device_active(gpio_a));
+	ut_asserteq_ptr(gpio_a, desc.dev);
+	ut_asserteq(4, desc.offset);
+	/* GPIOF_INPUT is the sandbox GPIO driver default */
+	ut_asserteq(GPIOF_INPUT, gpio_get_function(gpio_a, 4, NULL));
+	ut_assertok(dm_gpio_free(dev, &desc));
+
+	ut_asserteq(-ENOENT, gpio_request_by_name(dev, "test-gpios", 3, &desc,
+						  0));
+	ut_asserteq_ptr(NULL, desc.dev);
+	ut_asserteq(desc.offset, 0);
+	ut_asserteq(-ENOENT, gpio_request_by_name(dev, "test-gpios", 5, &desc,
+						  0));
+
+	/* Last GPIO is ignord as it comes after <0> */
+	ut_asserteq(3, gpio_request_list_by_name(dev, "test-gpios", desc_list,
+						 ARRAY_SIZE(desc_list), 0));
+	ut_asserteq(-EBUSY, gpio_request_list_by_name(dev, "test-gpios",
+						      desc_list2,
+						      ARRAY_SIZE(desc_list2),
+						      0));
+	ut_assertok(gpio_free_list(dev, desc_list, 3));
+	ut_asserteq(3, gpio_request_list_by_name(dev,  "test-gpios", desc_list,
+						 ARRAY_SIZE(desc_list),
+						 GPIOD_IS_OUT |
+						 GPIOD_IS_OUT_ACTIVE));
+	ut_asserteq_ptr(gpio_a, desc_list[0].dev);
+	ut_asserteq(1, desc_list[0].offset);
+	ut_asserteq_ptr(gpio_a, desc_list[1].dev);
+	ut_asserteq(4, desc_list[1].offset);
+	ut_asserteq_ptr(gpio_b, desc_list[2].dev);
+	ut_asserteq(5, desc_list[2].offset);
+	ut_asserteq(1, dm_gpio_get_value(desc_list));
+	ut_assertok(gpio_free_list(dev, desc_list, 3));
+
+	ut_asserteq(6, gpio_request_list_by_name(dev, "test2-gpios", desc_list,
+						 ARRAY_SIZE(desc_list), 0));
+	/* This was set to output previously, so still will be */
+	ut_asserteq(GPIOF_OUTPUT, gpio_get_function(gpio_a, 1, NULL));
+
+	/* Active low should invert the input value */
+	ut_asserteq(GPIOF_INPUT, gpio_get_function(gpio_b, 6, NULL));
+	ut_asserteq(1, dm_gpio_get_value(&desc_list[2]));
+
+	ut_asserteq(GPIOF_INPUT, gpio_get_function(gpio_b, 7, NULL));
+	ut_asserteq(GPIOF_OUTPUT, gpio_get_function(gpio_b, 8, NULL));
+	ut_asserteq(0, dm_gpio_get_value(&desc_list[4]));
+	ut_asserteq(GPIOF_OUTPUT, gpio_get_function(gpio_b, 9, NULL));
+	ut_asserteq(1, dm_gpio_get_value(&desc_list[5]));
+
+
+	return 0;
+}
+DM_TEST(dm_test_gpio_phandles, DM_TESTF_SCAN_PDATA | DM_TESTF_SCAN_FDT);
diff --git a/test/dm/test.dts b/test/dm/test.dts
index fb0272a..33f2c00 100644
--- a/test/dm/test.dts
+++ b/test/dm/test.dts
@@ -22,6 +22,11 @@
 		ping-expect = <0>;
 		ping-add = <0>;
 		u-boot,dm-pre-reloc;
+		test-gpios = <&gpio_a 1>, <&gpio_a 4>, <&gpio_b 5 0 3 2 1>,
+			<0>, <&gpio_a 12>;
+		test2-gpios = <&gpio_a 1>, <&gpio_a 4>, <&gpio_b 6 1 3 2 1>,
+			<&gpio_b 7 2 3 2 1>, <&gpio_b 8 4 3 2 1>,
+			<&gpio_b 9 0xc 3 2 1>;
 	};
 
 	junk {
@@ -83,12 +88,16 @@
 
 	gpio_a: base-gpios {
 		compatible = "sandbox,gpio";
+		gpio-controller;
+		#gpio-cells = <1>;
 		gpio-bank-name = "a";
 		num-gpios = <20>;
 	};
 
-	extra-gpios {
+	gpio_b: extra-gpios {
 		compatible = "sandbox,gpio";
+		gpio-controller;
+		#gpio-cells = <5>;
 		gpio-bank-name = "b";
 		num-gpios = <10>;
 	};
-- 
2.2.0.rc0.207.ga3a616c

^ permalink raw reply related	[flat|nested] 49+ messages in thread

* [U-Boot] [PATCH 08/21] dm: gpio: Mark the old GPIO API deprecated
  2015-01-06  3:05 [U-Boot] [PATCH 0/21] dm: Support GPIO device tree bindings in the uclass Simon Glass
                   ` (6 preceding siblings ...)
  2015-01-06  3:05 ` [U-Boot] [PATCH 07/21] dm: gpio: Add better functions to request GPIOs Simon Glass
@ 2015-01-06  3:05 ` Simon Glass
  2015-01-15  4:39   ` Simon Glass
  2015-01-06  3:05 ` [U-Boot] [PATCH 09/21] dm: demo: Add a simple GPIO demonstration Simon Glass
                   ` (13 subsequent siblings)
  21 siblings, 1 reply; 49+ messages in thread
From: Simon Glass @ 2015-01-06  3:05 UTC (permalink / raw)
  To: u-boot

Add a deprecation notice to each function so that it is more obvious that we
are moving GPIOs to driver model.

Signed-off-by: Simon Glass <sjg@chromium.org>
---

 include/asm-generic/gpio.h | 21 +++++++++++++++++++++
 1 file changed, 21 insertions(+)

diff --git a/include/asm-generic/gpio.h b/include/asm-generic/gpio.h
index 2653415..3b96b82 100644
--- a/include/asm-generic/gpio.h
+++ b/include/asm-generic/gpio.h
@@ -10,6 +10,15 @@
 /*
  * Generic GPIO API for U-Boot
  *
+ * --
+ * NB: This is deprecated. Please use the driver model functions instead:
+ *
+ *    - gpio_request_by_name()
+ *    - dm_gpio_get_value() etc.
+ *
+ * For now we need a dm_ prefix on some functions to avoid name collision.
+ * --
+ *
  * GPIOs are numbered from 0 to GPIO_COUNT-1 which value is defined
  * by the SOC/architecture.
  *
@@ -26,6 +35,7 @@
  */
 
 /**
+ * @deprecated	Please use driver model instead
  * Request a GPIO. This should be called before any of the other functions
  * are used on this GPIO.
  *
@@ -39,6 +49,7 @@
 int gpio_request(unsigned gpio, const char *label);
 
 /**
+ * @deprecated	Please use driver model instead
  * Stop using the GPIO.  This function should not alter pin configuration.
  *
  * @param gpio	GPIO number
@@ -47,6 +58,7 @@ int gpio_request(unsigned gpio, const char *label);
 int gpio_free(unsigned gpio);
 
 /**
+ * @deprecated	Please use driver model instead
  * Make a GPIO an input.
  *
  * @param gpio	GPIO number
@@ -55,6 +67,7 @@ int gpio_free(unsigned gpio);
 int gpio_direction_input(unsigned gpio);
 
 /**
+ * @deprecated	Please use driver model instead
  * Make a GPIO an output, and set its value.
  *
  * @param gpio	GPIO number
@@ -64,6 +77,7 @@ int gpio_direction_input(unsigned gpio);
 int gpio_direction_output(unsigned gpio, int value);
 
 /**
+ * @deprecated	Please use driver model instead
  * Get a GPIO's value. This will work whether the GPIO is an input
  * or an output.
  *
@@ -73,6 +87,7 @@ int gpio_direction_output(unsigned gpio, int value);
 int gpio_get_value(unsigned gpio);
 
 /**
+ * @deprecated	Please use driver model instead
  * Set an output GPIO's value. The GPIO must already be an output or
  * this function may have no effect.
  *
@@ -134,6 +149,8 @@ static inline bool dm_gpio_is_valid(struct gpio_desc *desc)
  * which means this is GPIO bank b, offset 4, currently set to input, current
  * value 1, [x] means that it is requested and the owner is 'sdmmc_cd'
  *
+ * TODO(sjg at chromium.org): This should use struct gpio_desc
+ *
  * @dev:	Device to check
  * @offset:	Offset of device GPIO to check
  * @buf:	Place to put string
@@ -146,6 +163,8 @@ int gpio_get_status(struct udevice *dev, int offset, char *buf, int buffsize);
  *
  * Note this returns GPIOF_UNUSED if the GPIO is not requested.
  *
+ * TODO(sjg at chromium.org): This should use struct gpio_desc
+ *
  * @dev:	Device to check
  * @offset:	Offset of device GPIO to check
  * @namep:	If non-NULL, this is set to the nane given when the GPIO
@@ -163,6 +182,8 @@ int gpio_get_function(struct udevice *dev, int offset, const char **namep);
  * Note this does not return GPIOF_UNUSED - it will always return the GPIO
  * driver's view of a pin function, even if it is not correctly set up.
  *
+ * TODO(sjg at chromium.org): This should use struct gpio_desc
+ *
  * @dev:	Device to check
  * @offset:	Offset of device GPIO to check
  * @namep:	If non-NULL, this is set to the nane given when the GPIO
-- 
2.2.0.rc0.207.ga3a616c

^ permalink raw reply related	[flat|nested] 49+ messages in thread

* [U-Boot] [PATCH 09/21] dm: demo: Add a simple GPIO demonstration
  2015-01-06  3:05 [U-Boot] [PATCH 0/21] dm: Support GPIO device tree bindings in the uclass Simon Glass
                   ` (7 preceding siblings ...)
  2015-01-06  3:05 ` [U-Boot] [PATCH 08/21] dm: gpio: Mark the old GPIO API deprecated Simon Glass
@ 2015-01-06  3:05 ` Simon Glass
  2015-01-15  4:40   ` Simon Glass
  2015-01-06  3:05 ` [U-Boot] [PATCH 10/21] dm: cros_ec: Remove use of fdtdec GPIO support Simon Glass
                   ` (12 subsequent siblings)
  21 siblings, 1 reply; 49+ messages in thread
From: Simon Glass @ 2015-01-06  3:05 UTC (permalink / raw)
  To: u-boot

Add a new 'demo light' command which uses GPIOs to control imaginary lights.
Each light is assigned a bit number in the overall value. This provides an
example driver for using the new GPIO API.

Signed-off-by: Simon Glass <sjg@chromium.org>
---

 arch/sandbox/dts/sandbox.dts | 11 ++++++-
 common/cmd_demo.c            | 29 +++++++++++++++++-
 drivers/demo/demo-shape.c    | 71 ++++++++++++++++++++++++++++++++++++++++++++
 drivers/demo/demo-uclass.c   | 20 +++++++++++++
 include/dm-demo.h            |  4 +++
 5 files changed, 133 insertions(+), 2 deletions(-)

diff --git a/arch/sandbox/dts/sandbox.dts b/arch/sandbox/dts/sandbox.dts
index 11748ae..4c63e4f 100644
--- a/arch/sandbox/dts/sandbox.dts
+++ b/arch/sandbox/dts/sandbox.dts
@@ -19,6 +19,7 @@
 		colour = "cyan";
 		sides = <3>;
 		character = <83>;
+		light-gpios = <&gpio_a 2>, <&gpio_b 6 0>;
 	};
 	square {
 		compatible = "demo-shape";
@@ -126,7 +127,7 @@
 			0x070b0067 0x070c0069>;
 	};
 
-	gpio_a: gpios {
+	gpio_a: gpios at 0 {
 		gpio-controller;
 		compatible = "sandbox,gpio";
 		#gpio-cells = <1>;
@@ -134,6 +135,14 @@
 		num-gpios = <20>;
 	};
 
+	gpio_b: gpios at 1 {
+		gpio-controller;
+		compatible = "sandbox,gpio";
+		#gpio-cells = <2>;
+		gpio-bank-name = "b";
+		num-gpios = <10>;
+	};
+
 	i2c at 0 {
 		#address-cells = <1>;
 		#size-cells = <0>;
diff --git a/common/cmd_demo.c b/common/cmd_demo.c
index 652c61c..bcb34d9 100644
--- a/common/cmd_demo.c
+++ b/common/cmd_demo.c
@@ -39,6 +39,26 @@ static int do_demo_status(cmd_tbl_t *cmdtp, int flag, int argc,
 	return 0;
 }
 
+static int do_demo_light(cmd_tbl_t *cmdtp, int flag, int argc,
+			 char * const argv[])
+{
+	int light;
+	int ret;
+
+	if (argc) {
+		light = simple_strtoul(argv[0], NULL, 16);
+		ret = demo_set_light(demo_dev, light);
+	} else {
+		ret = demo_get_light(demo_dev);
+		if (ret >= 0) {
+			printf("Light: %x\n", ret);
+			ret = 0;
+		}
+	}
+
+	return ret;
+}
+
 int do_demo_list(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[])
 {
 	struct udevice *dev;
@@ -61,6 +81,7 @@ int do_demo_list(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[])
 static cmd_tbl_t demo_commands[] = {
 	U_BOOT_CMD_MKENT(list, 0, 1, do_demo_list, "", ""),
 	U_BOOT_CMD_MKENT(hello, 2, 1, do_demo_hello, "", ""),
+	U_BOOT_CMD_MKENT(light, 2, 1, do_demo_light, "", ""),
 	U_BOOT_CMD_MKENT(status, 1, 1, do_demo_status, "", ""),
 };
 
@@ -86,6 +107,10 @@ static int do_demo(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[])
 			return cmd_process_error(cmdtp, ret);
 		argc--;
 		argv++;
+	} else {
+		demo_dev = NULL;
+		if (demo_cmd->cmd != do_demo_list)
+			return CMD_RET_USAGE;
 	}
 
 	ret = demo_cmd->cmd(demo_cmd, flag, argc, argv);
@@ -98,5 +123,7 @@ U_BOOT_CMD(
 	"Driver model (dm) demo operations",
 	"list                     List available demo devices\n"
 	"demo hello <num> [<char>]     Say hello\n"
-	"demo status <num>             Get demo device status"
+	"demo light [<num>]            Set or get the lights\n"
+	"demo status <num>             Get demo device status\n"
+	"demo list                     List available demo devices"
 );
diff --git a/drivers/demo/demo-shape.c b/drivers/demo/demo-shape.c
index 3fa9c59..d908736 100644
--- a/drivers/demo/demo-shape.c
+++ b/drivers/demo/demo-shape.c
@@ -11,6 +11,7 @@
 #include <malloc.h>
 #include <dm-demo.h>
 #include <asm/io.h>
+#include <asm/gpio.h>
 
 DECLARE_GLOBAL_DATA_PTR;
 
@@ -20,6 +21,8 @@ DECLARE_GLOBAL_DATA_PTR;
 
 struct shape_data {
 	int num_chars;	/* Number of non-space characters output so far */
+	struct gpio_desc gpio_desc[8];
+	int gpio_count;
 };
 
 /* Crazy little function to draw shapes on the console */
@@ -89,9 +92,52 @@ static int shape_status(struct udevice *dev, int *status)
 	return 0;
 }
 
+static int set_light(struct udevice *dev, int light)
+{
+	struct shape_data *priv = dev_get_priv(dev);
+	struct gpio_desc *desc;
+	int ret;
+	int i;
+
+	desc = priv->gpio_desc;
+	for (i = 0; i < priv->gpio_count; i++, desc++) {
+		uint mask = 1 << i;
+
+		ret = dm_gpio_set_value(desc, light & mask);
+		if (ret < 0)
+			return ret;
+	}
+
+	return 0;
+}
+
+static int get_light(struct udevice *dev)
+{
+	struct shape_data *priv = dev_get_priv(dev);
+	struct gpio_desc *desc;
+	uint value = 0;
+	int ret;
+	int i;
+
+	desc = priv->gpio_desc;
+	for (i = 0; i < priv->gpio_count; i++, desc++) {
+		uint mask = 1 << i;
+
+		ret = dm_gpio_get_value(desc);
+		if (ret < 0)
+			return ret;
+		if (ret)
+			value |= mask;
+	}
+
+	return value;
+}
+
 static const struct demo_ops shape_ops = {
 	.hello = shape_hello,
 	.status = shape_status,
+	.get_light = get_light,
+	.set_light = set_light,
 };
 
 static int shape_ofdata_to_platdata(struct udevice *dev)
@@ -111,6 +157,29 @@ static int shape_ofdata_to_platdata(struct udevice *dev)
 	return 0;
 }
 
+static int dm_shape_probe(struct udevice *dev)
+{
+	struct shape_data *priv = dev_get_priv(dev);
+	int ret;
+
+	ret = gpio_request_list_by_name(dev, "light-gpios", priv->gpio_desc,
+					ARRAY_SIZE(priv->gpio_desc),
+					GPIOD_IS_OUT | GPIOD_IS_OUT_ACTIVE);
+	if (ret < 0)
+		return ret;
+	priv->gpio_count = ret;
+	debug("%s: %d GPIOs\n", __func__, priv->gpio_count);
+
+	return 0;
+}
+
+static int dm_shape_remove(struct udevice *dev)
+{
+	struct shape_data *priv = dev_get_priv(dev);
+
+	return gpio_free_list(dev, priv->gpio_desc, priv->gpio_count);
+}
+
 static const struct udevice_id demo_shape_id[] = {
 	{ "demo-shape", 0 },
 	{ },
@@ -122,6 +191,8 @@ U_BOOT_DRIVER(demo_shape_drv) = {
 	.id	= UCLASS_DEMO,
 	.ofdata_to_platdata = shape_ofdata_to_platdata,
 	.ops	= &shape_ops,
+	.probe = dm_shape_probe,
+	.remove = dm_shape_remove,
 	.priv_auto_alloc_size = sizeof(struct shape_data),
 	.platdata_auto_alloc_size = sizeof(struct dm_demo_pdata),
 };
diff --git a/drivers/demo/demo-uclass.c b/drivers/demo/demo-uclass.c
index f6510d6..725f068 100644
--- a/drivers/demo/demo-uclass.c
+++ b/drivers/demo/demo-uclass.c
@@ -43,6 +43,26 @@ int demo_status(struct udevice *dev, int *status)
 	return ops->status(dev, status);
 }
 
+int demo_get_light(struct udevice *dev)
+{
+	const struct demo_ops *ops = device_get_ops(dev);
+
+	if (!ops->get_light)
+		return -ENOSYS;
+
+	return ops->get_light(dev);
+}
+
+int demo_set_light(struct udevice *dev, int light)
+{
+	const struct demo_ops *ops = device_get_ops(dev);
+
+	if (!ops->set_light)
+		return -ENOSYS;
+
+	return ops->set_light(dev, light);
+}
+
 int demo_parse_dt(struct udevice *dev)
 {
 	struct dm_demo_pdata *pdata = dev_get_platdata(dev);
diff --git a/include/dm-demo.h b/include/dm-demo.h
index a24fec6..03722d0 100644
--- a/include/dm-demo.h
+++ b/include/dm-demo.h
@@ -25,10 +25,14 @@ struct dm_demo_pdata {
 struct demo_ops {
 	int (*hello)(struct udevice *dev, int ch);
 	int (*status)(struct udevice *dev, int *status);
+	int (*set_light)(struct udevice *dev, int light);
+	int (*get_light)(struct udevice *dev);
 };
 
 int demo_hello(struct udevice *dev, int ch);
 int demo_status(struct udevice *dev, int *status);
+int demo_set_light(struct udevice *dev, int light);
+int demo_get_light(struct udevice *dev);
 int demo_list(void);
 
 int demo_parse_dt(struct udevice *dev);
-- 
2.2.0.rc0.207.ga3a616c

^ permalink raw reply related	[flat|nested] 49+ messages in thread

* [U-Boot] [PATCH 10/21] dm: cros_ec: Remove use of fdtdec GPIO support
  2015-01-06  3:05 [U-Boot] [PATCH 0/21] dm: Support GPIO device tree bindings in the uclass Simon Glass
                   ` (8 preceding siblings ...)
  2015-01-06  3:05 ` [U-Boot] [PATCH 09/21] dm: demo: Add a simple GPIO demonstration Simon Glass
@ 2015-01-06  3:05 ` Simon Glass
  2015-01-15  4:40   ` Simon Glass
  2015-01-06  3:05 ` [U-Boot] [PATCH 11/21] dm: tegra: Add a GPIO translation function Simon Glass
                   ` (11 subsequent siblings)
  21 siblings, 1 reply; 49+ messages in thread
From: Simon Glass @ 2015-01-06  3:05 UTC (permalink / raw)
  To: u-boot

These functions are going away, so use the new uclass support instead.

Signed-off-by: Simon Glass <sjg@chromium.org>
---

 drivers/misc/cros_ec.c | 24 ++++++------------------
 include/cros_ec.h      |  3 ++-
 2 files changed, 8 insertions(+), 19 deletions(-)

diff --git a/drivers/misc/cros_ec.c b/drivers/misc/cros_ec.c
index 9b4effb..7b20ffc 100644
--- a/drivers/misc/cros_ec.c
+++ b/drivers/misc/cros_ec.c
@@ -606,10 +606,10 @@ int cros_ec_reboot(struct cros_ec_dev *dev, enum ec_reboot_cmd cmd,
 int cros_ec_interrupt_pending(struct cros_ec_dev *dev)
 {
 	/* no interrupt support : always poll */
-	if (!fdt_gpio_isvalid(&dev->ec_int))
+	if (!dm_gpio_is_valid(&dev->ec_int))
 		return -ENOENT;
 
-	return !gpio_get_value(dev->ec_int.gpio);
+	return dm_gpio_get_value(&dev->ec_int);
 }
 
 int cros_ec_info(struct cros_ec_dev *dev, struct ec_response_mkbp_info *info)
@@ -1072,7 +1072,8 @@ static int cros_ec_decode_fdt(const void *blob, int node,
 		return -1;
 	}
 
-	fdtdec_decode_gpio(blob, node, "ec-interrupt", &dev->ec_int);
+	gpio_request_by_name_nodev(blob, node, "ec-interrupt", 0, &dev->ec_int,
+				   GPIOD_IS_IN);
 	dev->optimise_flash_write = fdtdec_get_bool(blob, node,
 						    "optimise-flash-write");
 	*devp = dev;
@@ -1090,17 +1091,11 @@ int cros_ec_register(struct udevice *dev)
 	char id[MSG_BYTES];
 
 	cdev->dev = dev;
-	fdtdec_decode_gpio(blob, node, "ec-interrupt", &cdev->ec_int);
+	gpio_request_by_name(dev, "ec-interrupt", 0, &cdev->ec_int,
+			     GPIOD_IS_IN);
 	cdev->optimise_flash_write = fdtdec_get_bool(blob, node,
 						     "optimise-flash-write");
 
-	/* we will poll the EC interrupt line */
-	fdtdec_setup_gpio(&cdev->ec_int);
-	if (fdt_gpio_isvalid(&cdev->ec_int)) {
-		gpio_request(cdev->ec_int.gpio, "cros-ec-irq");
-		gpio_direction_input(cdev->ec_int.gpio);
-	}
-
 	if (cros_ec_check_version(cdev)) {
 		debug("%s: Could not detect CROS-EC version\n", __func__);
 		return -CROS_EC_ERR_CHECK_VERSION;
@@ -1184,13 +1179,6 @@ int cros_ec_init(const void *blob, struct cros_ec_dev **cros_ecp)
 	}
 #endif
 
-	/* we will poll the EC interrupt line */
-	fdtdec_setup_gpio(&dev->ec_int);
-	if (fdt_gpio_isvalid(&dev->ec_int)) {
-		gpio_request(dev->ec_int.gpio, "cros-ec-irq");
-		gpio_direction_input(dev->ec_int.gpio);
-	}
-
 	if (cros_ec_check_version(dev)) {
 		debug("%s: Could not detect CROS-EC version\n", __func__);
 		return -CROS_EC_ERR_CHECK_VERSION;
diff --git a/include/cros_ec.h b/include/cros_ec.h
index 9e13146..8457c80 100644
--- a/include/cros_ec.h
+++ b/include/cros_ec.h
@@ -13,6 +13,7 @@
 #include <ec_commands.h>
 #include <fdtdec.h>
 #include <cros_ec_message.h>
+#include <asm/gpio.h>
 
 #ifndef CONFIG_DM_CROS_EC
 /* Which interface is the device on? */
@@ -39,7 +40,7 @@ struct cros_ec_dev {
 	unsigned int bus_num;		/* Bus number (for I2C) */
 	unsigned int max_frequency;	/* Maximum interface frequency */
 #endif
-	struct fdt_gpio_state ec_int;	/* GPIO used as EC interrupt line */
+	struct gpio_desc ec_int;	/* GPIO used as EC interrupt line */
 	int protocol_version;           /* Protocol version to use */
 	int optimise_flash_write;	/* Don't write erased flash blocks */
 
-- 
2.2.0.rc0.207.ga3a616c

^ permalink raw reply related	[flat|nested] 49+ messages in thread

* [U-Boot] [PATCH 11/21] dm: tegra: Add a GPIO translation function
  2015-01-06  3:05 [U-Boot] [PATCH 0/21] dm: Support GPIO device tree bindings in the uclass Simon Glass
                   ` (9 preceding siblings ...)
  2015-01-06  3:05 ` [U-Boot] [PATCH 10/21] dm: cros_ec: Remove use of fdtdec GPIO support Simon Glass
@ 2015-01-06  3:05 ` Simon Glass
  2015-01-15  4:40   ` Simon Glass
  2015-01-06  3:05 ` [U-Boot] [PATCH 12/21] dm: exynos: " Simon Glass
                   ` (10 subsequent siblings)
  21 siblings, 1 reply; 49+ messages in thread
From: Simon Glass @ 2015-01-06  3:05 UTC (permalink / raw)
  To: u-boot

This deals with the polarity bit and selecting the correct bank device
given a GPIO number.

Signed-off-by: Simon Glass <sjg@chromium.org>
---

 drivers/gpio/tegra_gpio.c | 18 ++++++++++++++++++
 1 file changed, 18 insertions(+)

diff --git a/drivers/gpio/tegra_gpio.c b/drivers/gpio/tegra_gpio.c
index 88f7ef5..43928b8 100644
--- a/drivers/gpio/tegra_gpio.c
+++ b/drivers/gpio/tegra_gpio.c
@@ -21,6 +21,7 @@
 #include <asm/arch/tegra.h>
 #include <asm/gpio.h>
 #include <dm/device-internal.h>
+#include <dt-bindings/gpio/gpio.h>
 
 DECLARE_GLOBAL_DATA_PTR;
 
@@ -251,6 +252,22 @@ static int tegra_gpio_get_function(struct udevice *dev, unsigned offset)
 		return GPIOF_INPUT;
 }
 
+static int tegra_gpio_xlate(struct udevice *dev, struct gpio_desc *desc,
+			    struct fdtdec_phandle_args *args)
+{
+	int gpio, port, ret;
+
+	gpio = args->args[0];
+	port = gpio / TEGRA_GPIOS_PER_PORT;
+	ret = device_get_child(dev, port, &desc->dev);
+	if (ret)
+		return ret;
+	desc->offset = gpio % TEGRA_GPIOS_PER_PORT;
+	desc->flags = args->args[1] & GPIO_ACTIVE_LOW ? GPIOD_ACTIVE_LOW : 0;
+
+	return 0;
+}
+
 static const struct dm_gpio_ops gpio_tegra_ops = {
 	.request		= tegra_gpio_request,
 	.direction_input	= tegra_gpio_direction_input,
@@ -258,6 +275,7 @@ static const struct dm_gpio_ops gpio_tegra_ops = {
 	.get_value		= tegra_gpio_get_value,
 	.set_value		= tegra_gpio_set_value,
 	.get_function		= tegra_gpio_get_function,
+	.xlate			= tegra_gpio_xlate,
 };
 
 /**
-- 
2.2.0.rc0.207.ga3a616c

^ permalink raw reply related	[flat|nested] 49+ messages in thread

* [U-Boot] [PATCH 12/21] dm: exynos: Add a GPIO translation function
  2015-01-06  3:05 [U-Boot] [PATCH 0/21] dm: Support GPIO device tree bindings in the uclass Simon Glass
                   ` (10 preceding siblings ...)
  2015-01-06  3:05 ` [U-Boot] [PATCH 11/21] dm: tegra: Add a GPIO translation function Simon Glass
@ 2015-01-06  3:05 ` Simon Glass
  2015-01-15  4:40   ` Simon Glass
  2015-01-06  3:05 ` [U-Boot] [PATCH 13/21] dm: tegra: video: Remove use of fdtdec GPIO support Simon Glass
                   ` (9 subsequent siblings)
  21 siblings, 1 reply; 49+ messages in thread
From: Simon Glass @ 2015-01-06  3:05 UTC (permalink / raw)
  To: u-boot

This deals with the polarity bit. It also changes the GPIO devices so that
the correct device tree node is linked to each one. This allows us to use
the new uclass phandle functionality to implement a proper GPIO binding.

Signed-off-by: Simon Glass <sjg@chromium.org>
---

 drivers/gpio/s5p_gpio.c | 13 ++++++++++++-
 1 file changed, 12 insertions(+), 1 deletion(-)

diff --git a/drivers/gpio/s5p_gpio.c b/drivers/gpio/s5p_gpio.c
index 6c41a42..0a245ba 100644
--- a/drivers/gpio/s5p_gpio.c
+++ b/drivers/gpio/s5p_gpio.c
@@ -13,6 +13,7 @@
 #include <asm/io.h>
 #include <asm/gpio.h>
 #include <dm/device-internal.h>
+#include <dt-bindings/gpio/gpio.h>
 
 DECLARE_GLOBAL_DATA_PTR;
 
@@ -275,12 +276,22 @@ static int exynos_gpio_get_function(struct udevice *dev, unsigned offset)
 		return GPIOF_FUNC;
 }
 
+static int exynos_gpio_xlate(struct udevice *dev, struct gpio_desc *desc,
+			     struct fdtdec_phandle_args *args)
+{
+	desc->offset = args->args[0];
+	desc->flags = args->args[1] & GPIO_ACTIVE_LOW ? GPIOD_ACTIVE_LOW : 0;
+
+	return 0;
+}
+
 static const struct dm_gpio_ops gpio_exynos_ops = {
 	.direction_input	= exynos_gpio_direction_input,
 	.direction_output	= exynos_gpio_direction_output,
 	.get_value		= exynos_gpio_get_value,
 	.set_value		= exynos_gpio_set_value,
 	.get_function		= exynos_gpio_get_function,
+	.xlate			= exynos_gpio_xlate,
 };
 
 static int gpio_exynos_probe(struct udevice *dev)
@@ -342,7 +353,7 @@ static int gpio_exynos_bind(struct udevice *parent)
 					plat->bank_name, plat, -1, &dev);
 		if (ret)
 			return ret;
-		dev->of_offset = parent->of_offset;
+		dev->of_offset = node;
 	}
 
 	return 0;
-- 
2.2.0.rc0.207.ga3a616c

^ permalink raw reply related	[flat|nested] 49+ messages in thread

* [U-Boot] [PATCH 13/21] dm: tegra: video: Remove use of fdtdec GPIO support
  2015-01-06  3:05 [U-Boot] [PATCH 0/21] dm: Support GPIO device tree bindings in the uclass Simon Glass
                   ` (11 preceding siblings ...)
  2015-01-06  3:05 ` [U-Boot] [PATCH 12/21] dm: exynos: " Simon Glass
@ 2015-01-06  3:05 ` Simon Glass
  2015-01-15  4:40   ` Simon Glass
  2015-01-06  3:05 ` [U-Boot] [PATCH 14/21] dm: tegra: nand: " Simon Glass
                   ` (8 subsequent siblings)
  21 siblings, 1 reply; 49+ messages in thread
From: Simon Glass @ 2015-01-06  3:05 UTC (permalink / raw)
  To: u-boot

These functions are going away, so use the new uclass support instead.

Signed-off-by: Simon Glass <sjg@chromium.org>
---

 arch/arm/include/asm/arch-tegra20/display.h |  9 ++---
 drivers/video/tegra.c                       | 54 +++++++++++------------------
 2 files changed, 25 insertions(+), 38 deletions(-)

diff --git a/arch/arm/include/asm/arch-tegra20/display.h b/arch/arm/include/asm/arch-tegra20/display.h
index a04c84e..6feeda3 100644
--- a/arch/arm/include/asm/arch-tegra20/display.h
+++ b/arch/arm/include/asm/arch-tegra20/display.h
@@ -10,6 +10,7 @@
 
 #include <asm/arch/dc.h>
 #include <fdtdec.h>
+#include <asm/gpio.h>
 
 /* This holds information about a window which can be displayed */
 struct disp_ctl_win {
@@ -72,10 +73,10 @@ struct fdt_panel_config {
 	int pwm_channel;		/* PWM channel to use for backlight */
 	enum lcd_cache_t cache_type;
 
-	struct fdt_gpio_state backlight_en;	/* GPIO for backlight enable */
-	struct fdt_gpio_state lvds_shutdown;	/* GPIO for lvds shutdown */
-	struct fdt_gpio_state backlight_vdd;	/* GPIO for backlight vdd */
-	struct fdt_gpio_state panel_vdd;	/* GPIO for panel vdd */
+	struct gpio_desc backlight_en;	/* GPIO for backlight enable */
+	struct gpio_desc lvds_shutdown;	/* GPIO for lvds shutdown */
+	struct gpio_desc backlight_vdd;	/* GPIO for backlight vdd */
+	struct gpio_desc panel_vdd;	/* GPIO for panel vdd */
 	/*
 	 * Panel required timings
 	 * Timing 1: delay between panel_vdd-rise and data-rise
diff --git a/drivers/video/tegra.c b/drivers/video/tegra.c
index 57cb007..b8f3431 100644
--- a/drivers/video/tegra.c
+++ b/drivers/video/tegra.c
@@ -149,14 +149,18 @@ static int fdt_decode_lcd(const void *blob, struct fdt_panel_config *config)
 					    FDT_LCD_CACHE_WRITE_BACK_FLUSH);
 
 	/* These GPIOs are all optional */
-	fdtdec_decode_gpio(blob, display_node, "nvidia,backlight-enable-gpios",
-			    &config->backlight_en);
-	fdtdec_decode_gpio(blob, display_node, "nvidia,lvds-shutdown-gpios",
-			   &config->lvds_shutdown);
-	fdtdec_decode_gpio(blob, display_node, "nvidia,backlight-vdd-gpios",
-			   &config->backlight_vdd);
-	fdtdec_decode_gpio(blob, display_node, "nvidia,panel-vdd-gpios",
-			   &config->panel_vdd);
+	gpio_request_by_name_nodev(blob, display_node,
+				   "nvidia,backlight-enable-gpios", 0,
+				   &config->backlight_en, GPIOD_IS_OUT);
+	gpio_request_by_name_nodev(blob, display_node,
+				   "nvidia,lvds-shutdown-gpios", 0,
+				   &config->lvds_shutdown, GPIOD_IS_OUT);
+	gpio_request_by_name_nodev(blob, display_node,
+				   "nvidia,backlight-vdd-gpios", 0,
+				   &config->backlight_vdd, GPIOD_IS_OUT);
+	gpio_request_by_name_nodev(blob, display_node,
+				   "nvidia,panel-vdd-gpios", 0,
+				   &config->panel_vdd, GPIOD_IS_OUT);
 
 	return fdtdec_get_int_array(blob, display_node, "nvidia,panel-timings",
 			config->panel_timings, FDT_LCD_TIMINGS);
@@ -196,36 +200,18 @@ static int handle_stage(const void *blob)
 		 */
 
 		funcmux_select(PERIPH_ID_DISP1, FUNCMUX_DEFAULT);
-
-		fdtdec_setup_gpio(&config.panel_vdd);
-		fdtdec_setup_gpio(&config.lvds_shutdown);
-		fdtdec_setup_gpio(&config.backlight_vdd);
-		fdtdec_setup_gpio(&config.backlight_en);
-
-		/*
-		 * TODO: If fdt includes output flag we can omit this code
-		 * since fdtdec_setup_gpio will do it for us.
-		 */
-		if (fdt_gpio_isvalid(&config.panel_vdd))
-			gpio_direction_output(config.panel_vdd.gpio, 0);
-		if (fdt_gpio_isvalid(&config.lvds_shutdown))
-			gpio_direction_output(config.lvds_shutdown.gpio, 0);
-		if (fdt_gpio_isvalid(&config.backlight_vdd))
-			gpio_direction_output(config.backlight_vdd.gpio, 0);
-		if (fdt_gpio_isvalid(&config.backlight_en))
-			gpio_direction_output(config.backlight_en.gpio, 0);
 		break;
 	case STAGE_PANEL_VDD:
-		if (fdt_gpio_isvalid(&config.panel_vdd))
-			gpio_direction_output(config.panel_vdd.gpio, 1);
+		if (dm_gpio_is_valid(&config.panel_vdd))
+			dm_gpio_set_value(&config.panel_vdd, 1);
 		break;
 	case STAGE_LVDS:
-		if (fdt_gpio_isvalid(&config.lvds_shutdown))
-			gpio_set_value(config.lvds_shutdown.gpio, 1);
+		if (dm_gpio_is_valid(&config.lvds_shutdown))
+			dm_gpio_set_value(&config.lvds_shutdown, 1);
 		break;
 	case STAGE_BACKLIGHT_VDD:
-		if (fdt_gpio_isvalid(&config.backlight_vdd))
-			gpio_set_value(config.backlight_vdd.gpio, 1);
+		if (dm_gpio_is_valid(&config.backlight_vdd))
+			dm_gpio_set_value(&config.backlight_vdd, 1);
 		break;
 	case STAGE_PWM:
 		/* Enable PWM at 15/16 high, 32768 Hz with divider 1 */
@@ -235,8 +221,8 @@ static int handle_stage(const void *blob)
 		pwm_enable(config.pwm_channel, 32768, 0xdf, 1);
 		break;
 	case STAGE_BACKLIGHT_EN:
-		if (fdt_gpio_isvalid(&config.backlight_en))
-			gpio_set_value(config.backlight_en.gpio, 1);
+		if (dm_gpio_is_valid(&config.backlight_en))
+			dm_gpio_set_value(&config.backlight_en, 1);
 		break;
 	case STAGE_DONE:
 		break;
-- 
2.2.0.rc0.207.ga3a616c

^ permalink raw reply related	[flat|nested] 49+ messages in thread

* [U-Boot] [PATCH 14/21] dm: tegra: nand: Remove use of fdtdec GPIO support
  2015-01-06  3:05 [U-Boot] [PATCH 0/21] dm: Support GPIO device tree bindings in the uclass Simon Glass
                   ` (12 preceding siblings ...)
  2015-01-06  3:05 ` [U-Boot] [PATCH 13/21] dm: tegra: video: Remove use of fdtdec GPIO support Simon Glass
@ 2015-01-06  3:05 ` Simon Glass
  2015-01-15  4:40   ` Simon Glass
  2015-01-06  3:05 ` [U-Boot] [PATCH 15/21] dm: zynq: Remove inline gpio functions Simon Glass
                   ` (7 subsequent siblings)
  21 siblings, 1 reply; 49+ messages in thread
From: Simon Glass @ 2015-01-06  3:05 UTC (permalink / raw)
  To: u-boot

These functions are going away, so use the new uclass support instead.

Signed-off-by: Simon Glass <sjg@chromium.org>
---

 drivers/mtd/nand/tegra_nand.c | 9 ++++-----
 1 file changed, 4 insertions(+), 5 deletions(-)

diff --git a/drivers/mtd/nand/tegra_nand.c b/drivers/mtd/nand/tegra_nand.c
index 163cf29..b660f3b 100644
--- a/drivers/mtd/nand/tegra_nand.c
+++ b/drivers/mtd/nand/tegra_nand.c
@@ -79,7 +79,7 @@ enum {
 struct fdt_nand {
 	struct nand_ctlr *reg;
 	int enabled;		/* 1 to enable, 0 to disable */
-	struct fdt_gpio_state wp_gpio;	/* write-protect GPIO */
+	struct gpio_desc wp_gpio;	/* write-protect GPIO */
 	s32 width;		/* bit width, normally 8 */
 	u32 timing[FDT_NAND_TIMING_COUNT];
 };
@@ -945,8 +945,8 @@ static int fdt_decode_nand(const void *blob, int node, struct fdt_nand *config)
 	config->reg = (struct nand_ctlr *)fdtdec_get_addr(blob, node, "reg");
 	config->enabled = fdtdec_get_is_enabled(blob, node);
 	config->width = fdtdec_get_int(blob, node, "nvidia,nand-width", 8);
-	err = fdtdec_decode_gpio(blob, node, "nvidia,wp-gpios",
-				 &config->wp_gpio);
+	err = gpio_request_by_name_nodev(blob, node, "nvidia,wp-gpios", 0,
+				 &config->wp_gpio, GPIOD_IS_OUT);
 	if (err)
 		return err;
 	err = fdtdec_get_int_array(blob, node, "nvidia,timing",
@@ -1009,8 +1009,7 @@ int tegra_nand_init(struct nand_chip *nand, int devnum)
 	/* Adjust timing for NAND device */
 	setup_timing(config->timing, info->reg);
 
-	fdtdec_setup_gpio(&config->wp_gpio);
-	gpio_direction_output(config->wp_gpio.gpio, 1);
+	dm_gpio_set_value(&config->wp_gpio, 1);
 
 	our_mtd = &nand_info[devnum];
 	our_mtd->priv = nand;
-- 
2.2.0.rc0.207.ga3a616c

^ permalink raw reply related	[flat|nested] 49+ messages in thread

* [U-Boot] [PATCH 15/21] dm: zynq: Remove inline gpio functions
  2015-01-06  3:05 [U-Boot] [PATCH 0/21] dm: Support GPIO device tree bindings in the uclass Simon Glass
                   ` (13 preceding siblings ...)
  2015-01-06  3:05 ` [U-Boot] [PATCH 14/21] dm: tegra: nand: " Simon Glass
@ 2015-01-06  3:05 ` Simon Glass
  2015-01-15  4:40   ` Simon Glass
  2015-01-06  3:05 ` [U-Boot] [PATCH 16/21] dm: mmc: Remove use of fdtdec GPIO support Simon Glass
                   ` (6 subsequent siblings)
  21 siblings, 1 reply; 49+ messages in thread
From: Simon Glass @ 2015-01-06  3:05 UTC (permalink / raw)
  To: u-boot

These functions serve no useful purpose, and conflict with the generic API.
Drop them.

Signed-off-by: Simon Glass <sjg@chromium.org>
---

 arch/arm/include/asm/arch-zynq/gpio.h | 15 ---------------
 1 file changed, 15 deletions(-)

diff --git a/arch/arm/include/asm/arch-zynq/gpio.h b/arch/arm/include/asm/arch-zynq/gpio.h
index 2dbba75..a26ae87 100644
--- a/arch/arm/include/asm/arch-zynq/gpio.h
+++ b/arch/arm/include/asm/arch-zynq/gpio.h
@@ -7,19 +7,4 @@
 #ifndef _ZYNQ_GPIO_H
 #define _ZYNQ_GPIO_H
 
-inline int gpio_get_value(unsigned gpio)
-{
-	return 0;
-}
-
-inline int gpio_set_value(unsigned gpio, int val)
-{
-	return 0;
-}
-
-inline int gpio_request(unsigned gpio, const char *label)
-{
-	return 0;
-}
-
 #endif /* _ZYNQ_GPIO_H */
-- 
2.2.0.rc0.207.ga3a616c

^ permalink raw reply related	[flat|nested] 49+ messages in thread

* [U-Boot] [PATCH 16/21] dm: mmc: Remove use of fdtdec GPIO support
  2015-01-06  3:05 [U-Boot] [PATCH 0/21] dm: Support GPIO device tree bindings in the uclass Simon Glass
                   ` (14 preceding siblings ...)
  2015-01-06  3:05 ` [U-Boot] [PATCH 15/21] dm: zynq: Remove inline gpio functions Simon Glass
@ 2015-01-06  3:05 ` Simon Glass
  2015-01-15  4:40   ` Simon Glass
  2015-01-06  3:05 ` [U-Boot] [PATCH 17/21] dm: usb: " Simon Glass
                   ` (5 subsequent siblings)
  21 siblings, 1 reply; 49+ messages in thread
From: Simon Glass @ 2015-01-06  3:05 UTC (permalink / raw)
  To: u-boot

These functions are going away, so use the new uclass support instead.

Signed-off-by: Simon Glass <sjg@chromium.org>
---

 arch/arm/include/asm/arch-pantheon/gpio.h   |  0
 arch/arm/include/asm/arch-tegra/tegra_mmc.h |  7 +++---
 drivers/mmc/s5p_sdhci.c                     | 20 +++++++---------
 drivers/mmc/tegra_mmc.c                     | 36 +++++++++++------------------
 include/sdhci.h                             |  6 ++---
 5 files changed, 28 insertions(+), 41 deletions(-)
 create mode 100644 arch/arm/include/asm/arch-pantheon/gpio.h

diff --git a/arch/arm/include/asm/arch-pantheon/gpio.h b/arch/arm/include/asm/arch-pantheon/gpio.h
new file mode 100644
index 0000000..e69de29
diff --git a/arch/arm/include/asm/arch-tegra/tegra_mmc.h b/arch/arm/include/asm/arch-tegra/tegra_mmc.h
index 84e7b55..a20bdaa 100644
--- a/arch/arm/include/asm/arch-tegra/tegra_mmc.h
+++ b/arch/arm/include/asm/arch-tegra/tegra_mmc.h
@@ -10,6 +10,7 @@
 #define __TEGRA_MMC_H_
 
 #include <fdtdec.h>
+#include <asm/gpio.h>
 
 /* for mmc_config definition */
 #include <mmc.h>
@@ -134,9 +135,9 @@ struct mmc_host {
 	int enabled;		/* 1 to enable, 0 to disable */
 	int width;		/* Bus Width, 1, 4 or 8 */
 	enum periph_id mmc_id;	/* Peripheral ID: PERIPH_ID_... */
-	struct fdt_gpio_state cd_gpio;		/* Change Detect GPIO */
-	struct fdt_gpio_state pwr_gpio;		/* Power GPIO */
-	struct fdt_gpio_state wp_gpio;		/* Write Protect GPIO */
+	struct gpio_desc cd_gpio;	/* Change Detect GPIO */
+	struct gpio_desc pwr_gpio;	/* Power GPIO */
+	struct gpio_desc wp_gpio;	/* Write Protect GPIO */
 	unsigned int version;	/* SDHCI spec. version */
 	unsigned int clock;	/* Current clock (MHz) */
 	struct mmc_config cfg;	/* mmc configuration */
diff --git a/drivers/mmc/s5p_sdhci.c b/drivers/mmc/s5p_sdhci.c
index a5d3487..3899372 100644
--- a/drivers/mmc/s5p_sdhci.c
+++ b/drivers/mmc/s5p_sdhci.c
@@ -102,17 +102,14 @@ struct sdhci_host sdhci_host[SDHCI_MAX_HOSTS];
 
 static int do_sdhci_init(struct sdhci_host *host)
 {
-	char str[20];
 	int dev_id, flag;
 	int err = 0;
 
 	flag = host->bus_width == 8 ? PINMUX_FLAG_8BIT_MODE : PINMUX_FLAG_NONE;
 	dev_id = host->index + PERIPH_ID_SDMMC0;
 
-	if (fdt_gpio_isvalid(&host->pwr_gpio)) {
-		sprintf(str, "sdhci%d_power", host->index & 0xf);
-		gpio_request(host->pwr_gpio.gpio, str);
-		gpio_direction_output(host->pwr_gpio.gpio, 1);
+	if (dm_gpio_is_valid(&host->pwr_gpio)) {
+		dm_gpio_set_value(&host->pwr_gpio, 1);
 		err = exynos_pinmux_config(dev_id, flag);
 		if (err) {
 			debug("MMC not configured\n");
@@ -120,11 +117,8 @@ static int do_sdhci_init(struct sdhci_host *host)
 		}
 	}
 
-	if (fdt_gpio_isvalid(&host->cd_gpio)) {
-		sprintf(str, "sdhci%d_cd", host->index & 0xf);
-		gpio_request(host->cd_gpio.gpio, str);
-		gpio_direction_input(host->cd_gpio.gpio);
-		if (gpio_get_value(host->cd_gpio.gpio))
+	if (dm_gpio_is_valid(&host->cd_gpio)) {
+		if (dm_gpio_get_value(&host->cd_gpio))
 			return -ENODEV;
 
 		err = exynos_pinmux_config(dev_id, flag);
@@ -166,8 +160,10 @@ static int sdhci_get_config(const void *blob, int node, struct sdhci_host *host)
 	}
 	host->ioaddr = (void *)base;
 
-	fdtdec_decode_gpio(blob, node, "pwr-gpios", &host->pwr_gpio);
-	fdtdec_decode_gpio(blob, node, "cd-gpios", &host->cd_gpio);
+	gpio_request_by_name_nodev(blob, node, "pwr-gpios", 0, &host->pwr_gpio,
+				   GPIOD_IS_OUT);
+	gpio_request_by_name_nodev(blob, node, "cd-gpios", 0, &host->cd_gpio,
+				   GPIOD_IS_IN);
 
 	return 0;
 }
diff --git a/drivers/mmc/tegra_mmc.c b/drivers/mmc/tegra_mmc.c
index 2bd36b0..2cd8cf1 100644
--- a/drivers/mmc/tegra_mmc.c
+++ b/drivers/mmc/tegra_mmc.c
@@ -515,8 +515,8 @@ static int tegra_mmc_getcd(struct mmc *mmc)
 
 	debug("tegra_mmc_getcd called\n");
 
-	if (fdt_gpio_isvalid(&host->cd_gpio))
-		return fdtdec_get_gpio(&host->cd_gpio);
+	if (dm_gpio_is_valid(&host->cd_gpio))
+		return dm_gpio_get_value(&host->cd_gpio);
 
 	return 1;
 }
@@ -531,7 +531,6 @@ static const struct mmc_ops tegra_mmc_ops = {
 static int do_mmc_init(int dev_index)
 {
 	struct mmc_host *host;
-	char gpusage[12]; /* "SD/MMCn PWR" or "SD/MMCn CD" */
 	struct mmc *mmc;
 
 	/* DT should have been read & host config filled in */
@@ -539,27 +538,15 @@ static int do_mmc_init(int dev_index)
 	if (!host->enabled)
 		return -1;
 
-	debug(" do_mmc_init: index %d, bus width %d "
-		"pwr_gpio %d cd_gpio %d\n",
-		dev_index, host->width,
-		host->pwr_gpio.gpio, host->cd_gpio.gpio);
+	debug(" do_mmc_init: index %d, bus width %d pwr_gpio %d cd_gpio %d\n",
+	      dev_index, host->width, gpio_get_number(&host->pwr_gpio),
+	      gpio_get_number(&host->cd_gpio));
 
 	host->clock = 0;
 	clock_start_periph_pll(host->mmc_id, CLOCK_ID_PERIPH, 20000000);
 
-	if (fdt_gpio_isvalid(&host->pwr_gpio)) {
-		sprintf(gpusage, "SD/MMC%d PWR", dev_index);
-		gpio_request(host->pwr_gpio.gpio, gpusage);
-		gpio_direction_output(host->pwr_gpio.gpio, 1);
-		debug(" Power GPIO name = %s\n", host->pwr_gpio.name);
-	}
-
-	if (fdt_gpio_isvalid(&host->cd_gpio)) {
-		sprintf(gpusage, "SD/MMC%d CD", dev_index);
-		gpio_request(host->cd_gpio.gpio, gpusage);
-		gpio_direction_input(host->cd_gpio.gpio);
-		debug(" CD GPIO name = %s\n", host->cd_gpio.name);
-	}
+	if (dm_gpio_is_valid(&host->pwr_gpio))
+		dm_gpio_set_value(&host->pwr_gpio, 1);
 
 	memset(&host->cfg, 0, sizeof(host->cfg));
 
@@ -626,9 +613,12 @@ static int mmc_get_config(const void *blob, int node, struct mmc_host *host)
 		debug("%s: no sdmmc width found\n", __func__);
 
 	/* These GPIOs are optional */
-	fdtdec_decode_gpio(blob, node, "cd-gpios", &host->cd_gpio);
-	fdtdec_decode_gpio(blob, node, "wp-gpios", &host->wp_gpio);
-	fdtdec_decode_gpio(blob, node, "power-gpios", &host->pwr_gpio);
+	gpio_request_by_name_nodev(blob, node, "cd-gpios", 0, &host->cd_gpio,
+				   GPIOD_IS_IN);
+	gpio_request_by_name_nodev(blob, node, "wp-gpios", 0, &host->wp_gpio,
+				   GPIOD_IS_IN);
+	gpio_request_by_name_nodev(blob, node, "power-gpios", 0,
+				   &host->pwr_gpio, GPIOD_IS_OUT);
 
 	debug("%s: found controller at %p, width = %d, periph_id = %d\n",
 		__func__, host->reg, host->width, host->mmc_id);
diff --git a/include/sdhci.h b/include/sdhci.h
index aa4a0e9..23893b5 100644
--- a/include/sdhci.h
+++ b/include/sdhci.h
@@ -12,7 +12,7 @@
 
 #include <asm/io.h>
 #include <mmc.h>
-#include <fdtdec.h>
+#include <asm/gpio.h>
 
 /*
  * Controller registers
@@ -246,8 +246,8 @@ struct sdhci_host {
 	int index;
 
 	int bus_width;
-	struct fdt_gpio_state pwr_gpio;	/* Power GPIO */
-	struct fdt_gpio_state cd_gpio;		/* Card Detect GPIO */
+	struct gpio_desc pwr_gpio;	/* Power GPIO */
+	struct gpio_desc cd_gpio;		/* Card Detect GPIO */
 
 	void (*set_control_reg)(struct sdhci_host *host);
 	void (*set_clock)(int dev_index, unsigned int div);
-- 
2.2.0.rc0.207.ga3a616c

^ permalink raw reply related	[flat|nested] 49+ messages in thread

* [U-Boot] [PATCH 17/21] dm: usb: Remove use of fdtdec GPIO support
  2015-01-06  3:05 [U-Boot] [PATCH 0/21] dm: Support GPIO device tree bindings in the uclass Simon Glass
                   ` (15 preceding siblings ...)
  2015-01-06  3:05 ` [U-Boot] [PATCH 16/21] dm: mmc: Remove use of fdtdec GPIO support Simon Glass
@ 2015-01-06  3:05 ` Simon Glass
  2015-01-15  4:40   ` Simon Glass
  2015-01-06  3:05 ` [U-Boot] [PATCH 18/21] dm: spi: " Simon Glass
                   ` (4 subsequent siblings)
  21 siblings, 1 reply; 49+ messages in thread
From: Simon Glass @ 2015-01-06  3:05 UTC (permalink / raw)
  To: u-boot

These functions are going away, so use the new uclass support instead.

Signed-off-by: Simon Glass <sjg@chromium.org>
---

 drivers/usb/host/ehci-exynos.c  | 10 +++++-----
 drivers/usb/host/ehci-tegra.c   | 38 ++++++++++++++++++--------------------
 drivers/usb/host/xhci-exynos5.c | 10 +++++-----
 3 files changed, 28 insertions(+), 30 deletions(-)

diff --git a/drivers/usb/host/ehci-exynos.c b/drivers/usb/host/ehci-exynos.c
index 6fdbf57..f3c077d 100644
--- a/drivers/usb/host/ehci-exynos.c
+++ b/drivers/usb/host/ehci-exynos.c
@@ -31,7 +31,7 @@ DECLARE_GLOBAL_DATA_PTR;
 struct exynos_ehci {
 	struct exynos_usb_phy *usb;
 	struct ehci_hccr *hcd;
-	struct fdt_gpio_state vbus_gpio;
+	struct gpio_desc vbus_gpio;
 };
 
 static struct exynos_ehci exynos;
@@ -61,7 +61,8 @@ static int exynos_usb_parse_dt(const void *blob, struct exynos_ehci *exynos)
 	exynos->hcd = (struct ehci_hccr *)addr;
 
 	/* Vbus gpio */
-	fdtdec_decode_gpio(blob, node, "samsung,vbus-gpio", &exynos->vbus_gpio);
+	gpio_request_by_name_nodev(blob, node, "samsung,vbus-gpio", 0,
+				   &exynos->vbus_gpio, GPIOD_IS_OUT);
 
 	depth = 0;
 	node = fdtdec_next_compatible_subnode(blob, node,
@@ -236,9 +237,8 @@ int ehci_hcd_init(int index, enum usb_init_type init,
 
 #ifdef CONFIG_OF_CONTROL
 	/* setup the Vbus gpio here */
-	if (fdt_gpio_isvalid(&ctx->vbus_gpio) &&
-	    !fdtdec_setup_gpio(&ctx->vbus_gpio))
-		gpio_direction_output(ctx->vbus_gpio.gpio, 1);
+	if (dm_gpio_is_valid(&ctx->vbus_gpio))
+		dm_gpio_set_value(&ctx->vbus_gpio, 1);
 #endif
 
 	setup_usb_phy(ctx->usb);
diff --git a/drivers/usb/host/ehci-tegra.c b/drivers/usb/host/ehci-tegra.c
index 5f0a98e..b5ad1e3 100644
--- a/drivers/usb/host/ehci-tegra.c
+++ b/drivers/usb/host/ehci-tegra.c
@@ -72,8 +72,8 @@ struct fdt_usb {
 	enum usb_init_type init_type;
 	enum dr_mode dr_mode;	/* dual role mode */
 	enum periph_id periph_id;/* peripheral id */
-	struct fdt_gpio_state vbus_gpio;	/* GPIO for vbus enable */
-	struct fdt_gpio_state phy_reset_gpio; /* GPIO to reset ULPI phy */
+	struct gpio_desc vbus_gpio;	/* GPIO for vbus enable */
+	struct gpio_desc phy_reset_gpio; /* GPIO to reset ULPI phy */
 };
 
 static struct fdt_usb port[USB_PORTS_MAX];	/* List of valid USB ports */
@@ -252,17 +252,14 @@ static void set_up_vbus(struct fdt_usb *config, enum usb_init_type init)
 		return;
 	}
 
-	if (fdt_gpio_isvalid(&config->vbus_gpio)) {
+	if (dm_gpio_is_valid(&config->vbus_gpio)) {
 		int vbus_value;
 
-		fdtdec_setup_gpio(&config->vbus_gpio);
+		vbus_value = (init == USB_INIT_HOST);
+		dm_gpio_set_value(&config->vbus_gpio, vbus_value);
 
-		vbus_value = (init == USB_INIT_HOST) ^
-			     !!(config->vbus_gpio.flags & FDT_GPIO_ACTIVE_LOW);
-		gpio_direction_output(config->vbus_gpio.gpio, vbus_value);
-
-		debug("set_up_vbus: GPIO %d %d\n", config->vbus_gpio.gpio,
-		      vbus_value);
+		debug("set_up_vbus: GPIO %d %d\n",
+		      gpio_get_number(&config->vbus_gpio), vbus_value);
 	}
 }
 
@@ -360,7 +357,7 @@ static int init_utmi_usb_controller(struct fdt_usb *config,
 	 * mux must be switched to actually use a_sess_vld threshold.
 	 */
 	if (config->dr_mode == DR_MODE_OTG &&
-	    fdt_gpio_isvalid(&config->vbus_gpio))
+	    dm_gpio_is_valid(&config->vbus_gpio))
 		clrsetbits_le32(&usbctlr->usb1_legacy_ctrl,
 			VBUS_SENSE_CTL_MASK,
 			VBUS_SENSE_CTL_A_SESS_VLD << VBUS_SENSE_CTL_SHIFT);
@@ -569,11 +566,10 @@ static int init_ulpi_usb_controller(struct fdt_usb *config,
 	clock_set_pllout(CLOCK_ID_PERIPH, PLL_OUT4, CONFIG_ULPI_REF_CLK);
 
 	/* reset ULPI phy */
-	if (fdt_gpio_isvalid(&config->phy_reset_gpio)) {
-		fdtdec_setup_gpio(&config->phy_reset_gpio);
-		gpio_direction_output(config->phy_reset_gpio.gpio, 0);
+	if (dm_gpio_is_valid(&config->phy_reset_gpio)) {
+		dm_gpio_set_value(&config->phy_reset_gpio, 0);
 		mdelay(5);
-		gpio_set_value(config->phy_reset_gpio.gpio, 1);
+		dm_gpio_set_value(&config->phy_reset_gpio, 1);
 	}
 
 	/* Reset the usb controller */
@@ -685,14 +681,16 @@ static int fdt_decode_usb(const void *blob, int node, struct fdt_usb *config)
 		debug("%s: Missing/invalid peripheral ID\n", __func__);
 		return -FDT_ERR_NOTFOUND;
 	}
-	fdtdec_decode_gpio(blob, node, "nvidia,vbus-gpio", &config->vbus_gpio);
-	fdtdec_decode_gpio(blob, node, "nvidia,phy-reset-gpio",
-			&config->phy_reset_gpio);
+	gpio_request_by_name_nodev(blob, node, "nvidia,vbus-gpio", 0,
+				   &config->vbus_gpio, GPIOD_IS_OUT);
+	gpio_request_by_name_nodev(blob, node, "nvidia,phy-reset-gpio", 0,
+				   &config->phy_reset_gpio, GPIOD_IS_OUT);
 	debug("enabled=%d, legacy_mode=%d, utmi=%d, ulpi=%d, periph_id=%d, "
 		"vbus=%d, phy_reset=%d, dr_mode=%d\n",
 		config->enabled, config->has_legacy_mode, config->utmi,
-		config->ulpi, config->periph_id, config->vbus_gpio.gpio,
-		config->phy_reset_gpio.gpio, config->dr_mode);
+		config->ulpi, config->periph_id,
+		gpio_get_number(&config->vbus_gpio),
+		gpio_get_number(&config->phy_reset_gpio), config->dr_mode);
 
 	return 0;
 }
diff --git a/drivers/usb/host/xhci-exynos5.c b/drivers/usb/host/xhci-exynos5.c
index b4946a3..a77c8bc 100644
--- a/drivers/usb/host/xhci-exynos5.c
+++ b/drivers/usb/host/xhci-exynos5.c
@@ -40,7 +40,7 @@ struct exynos_xhci {
 	struct exynos_usb3_phy *usb3_phy;
 	struct xhci_hccr *hcd;
 	struct dwc3 *dwc3_reg;
-	struct fdt_gpio_state vbus_gpio;
+	struct gpio_desc vbus_gpio;
 };
 
 static struct exynos_xhci exynos;
@@ -69,7 +69,8 @@ static int exynos_usb3_parse_dt(const void *blob, struct exynos_xhci *exynos)
 	exynos->hcd = (struct xhci_hccr *)addr;
 
 	/* Vbus gpio */
-	fdtdec_decode_gpio(blob, node, "samsung,vbus-gpio", &exynos->vbus_gpio);
+	gpio_request_by_name_nodev(blob, node, "samsung,vbus-gpio", 0,
+				   &exynos->vbus_gpio, GPIOD_IS_OUT);
 
 	depth = 0;
 	node = fdtdec_next_compatible_subnode(blob, node,
@@ -298,9 +299,8 @@ int xhci_hcd_init(int index, struct xhci_hccr **hccr, struct xhci_hcor **hcor)
 
 #ifdef CONFIG_OF_CONTROL
 	/* setup the Vbus gpio here */
-	if (fdt_gpio_isvalid(&ctx->vbus_gpio) &&
-	    !fdtdec_setup_gpio(&ctx->vbus_gpio))
-		gpio_direction_output(ctx->vbus_gpio.gpio, 1);
+	if (dm_gpio_is_valid(&ctx->vbus_gpio))
+		dm_gpio_set_value(&ctx->vbus_gpio, 1);
 #endif
 
 	ret = exynos_xhci_core_init(ctx);
-- 
2.2.0.rc0.207.ga3a616c

^ permalink raw reply related	[flat|nested] 49+ messages in thread

* [U-Boot] [PATCH 18/21] dm: spi: Remove use of fdtdec GPIO support
  2015-01-06  3:05 [U-Boot] [PATCH 0/21] dm: Support GPIO device tree bindings in the uclass Simon Glass
                   ` (16 preceding siblings ...)
  2015-01-06  3:05 ` [U-Boot] [PATCH 17/21] dm: usb: " Simon Glass
@ 2015-01-06  3:05 ` Simon Glass
  2015-01-15  4:40   ` Simon Glass
  2015-01-06  3:05 ` [U-Boot] [PATCH 19/21] dm: tegra: dts: Use TEGRA_GPIO() macro for all GPIOs Simon Glass
                   ` (3 subsequent siblings)
  21 siblings, 1 reply; 49+ messages in thread
From: Simon Glass @ 2015-01-06  3:05 UTC (permalink / raw)
  To: u-boot

These functions are going away, so use the new uclass support instead.

Signed-off-by: Simon Glass <sjg@chromium.org>
---

 drivers/spi/soft_spi.c | 62 +++++++++++++++++++++++---------------------------
 1 file changed, 28 insertions(+), 34 deletions(-)

diff --git a/drivers/spi/soft_spi.c b/drivers/spi/soft_spi.c
index 5588036..423c98d 100644
--- a/drivers/spi/soft_spi.c
+++ b/drivers/spi/soft_spi.c
@@ -21,10 +21,10 @@
 DECLARE_GLOBAL_DATA_PTR;
 
 struct soft_spi_platdata {
-	struct fdt_gpio_state cs;
-	struct fdt_gpio_state sclk;
-	struct fdt_gpio_state mosi;
-	struct fdt_gpio_state miso;
+	struct gpio_desc cs;
+	struct gpio_desc sclk;
+	struct gpio_desc mosi;
+	struct gpio_desc miso;
 	int spi_delay_us;
 };
 
@@ -35,9 +35,8 @@ struct soft_spi_priv {
 static int soft_spi_scl(struct udevice *dev, int bit)
 {
 	struct soft_spi_platdata *plat = dev->platdata;
-	struct soft_spi_priv *priv = dev_get_priv(dev);
 
-	gpio_set_value(plat->sclk.gpio, priv->mode & SPI_CPOL ? bit : !bit);
+	dm_gpio_set_value(&plat->sclk, bit);
 
 	return 0;
 }
@@ -46,7 +45,7 @@ static int soft_spi_sda(struct udevice *dev, int bit)
 {
 	struct soft_spi_platdata *plat = dev->platdata;
 
-	gpio_set_value(plat->mosi.gpio, bit);
+	dm_gpio_set_value(&plat->mosi, bit);
 
 	return 0;
 }
@@ -54,11 +53,10 @@ static int soft_spi_sda(struct udevice *dev, int bit)
 static int soft_spi_cs_activate(struct udevice *dev)
 {
 	struct soft_spi_platdata *plat = dev->platdata;
-	struct soft_spi_priv *priv = dev_get_priv(dev);
 
-	gpio_set_value(plat->cs.gpio, !(priv->mode & SPI_CS_HIGH));
-	gpio_set_value(plat->sclk.gpio, priv->mode & SPI_CPOL);
-	gpio_set_value(plat->cs.gpio, priv->mode & SPI_CS_HIGH);
+	dm_gpio_set_value(&plat->cs, 0);
+	dm_gpio_set_value(&plat->sclk, 0);
+	dm_gpio_set_value(&plat->cs, 1);
 
 	return 0;
 }
@@ -66,9 +64,8 @@ static int soft_spi_cs_activate(struct udevice *dev)
 static int soft_spi_cs_deactivate(struct udevice *dev)
 {
 	struct soft_spi_platdata *plat = dev->platdata;
-	struct soft_spi_priv *priv = dev_get_priv(dev);
 
-	gpio_set_value(plat->cs.gpio, !(priv->mode & SPI_CS_HIGH));
+	dm_gpio_set_value(&plat->cs, 0);
 
 	return 0;
 }
@@ -109,7 +106,6 @@ static int soft_spi_xfer(struct udevice *dev, unsigned int bitlen,
 	uchar		tmpdout = 0;
 	const u8	*txd = dout;
 	u8		*rxd = din;
-	int		cpol = priv->mode & SPI_CPOL;
 	int		cpha = priv->mode & SPI_CPHA;
 	unsigned int	j;
 
@@ -137,19 +133,19 @@ static int soft_spi_xfer(struct udevice *dev, unsigned int bitlen,
 		}
 
 		if (!cpha)
-			soft_spi_scl(dev, !cpol);
+			soft_spi_scl(dev, 0);
 		soft_spi_sda(dev, tmpdout & 0x80);
 		udelay(plat->spi_delay_us);
 		if (cpha)
-			soft_spi_scl(dev, !cpol);
+			soft_spi_scl(dev, 0);
 		else
-			soft_spi_scl(dev, cpol);
+			soft_spi_scl(dev, 1);
 		tmpdin	<<= 1;
-		tmpdin	|= gpio_get_value(plat->miso.gpio);
+		tmpdin	|= dm_gpio_get_value(&plat->miso);
 		tmpdout	<<= 1;
 		udelay(plat->spi_delay_us);
 		if (cpha)
-			soft_spi_scl(dev, cpol);
+			soft_spi_scl(dev, 1);
 	}
 	/*
 	 * If the number of bits isn't a multiple of 8, shift the last
@@ -205,11 +201,6 @@ static int soft_spi_ofdata_to_platdata(struct udevice *dev)
 	const void *blob = gd->fdt_blob;
 	int node = dev->of_offset;
 
-	if (fdtdec_decode_gpio(blob, node, "cs-gpio", &plat->cs) ||
-	    fdtdec_decode_gpio(blob, node, "sclk-gpio", &plat->sclk) ||
-	    fdtdec_decode_gpio(blob, node, "mosi-gpio", &plat->mosi) ||
-	    fdtdec_decode_gpio(blob, node, "miso-gpio", &plat->miso))
-		return -EINVAL;
 	plat->spi_delay_us = fdtdec_get_int(blob, node, "spi-delay-us", 0);
 
 	return 0;
@@ -219,16 +210,19 @@ static int soft_spi_probe(struct udevice *dev)
 {
 	struct spi_slave *slave = dev_get_parentdata(dev);
 	struct soft_spi_platdata *plat = dev->platdata;
-
-	gpio_request(plat->cs.gpio, "soft_spi_cs");
-	gpio_request(plat->sclk.gpio, "soft_spi_sclk");
-	gpio_request(plat->mosi.gpio, "soft_spi_mosi");
-	gpio_request(plat->miso.gpio, "soft_spi_miso");
-
-	gpio_direction_output(plat->sclk.gpio, slave->mode & SPI_CPOL);
-	gpio_direction_output(plat->mosi.gpio, 1);
-	gpio_direction_input(plat->miso.gpio);
-	gpio_direction_output(plat->cs.gpio, !(slave->mode & SPI_CS_HIGH));
+	int cs_flags, clk_flags;
+
+	cs_flags = (slave->mode & SPI_CS_HIGH) ? 0 : GPIOD_ACTIVE_LOW;
+	clk_flags = (slave->mode & SPI_CPOL) ? GPIOD_ACTIVE_LOW : 0;
+	if (gpio_request_by_name(dev, "cs-gpio", 0, &plat->cs,
+				 GPIOD_IS_OUT | cs_flags) ||
+	    gpio_request_by_name(dev, "sclk-gpio", 0, &plat->sclk,
+				 GPIOD_IS_OUT | clk_flags) ||
+	    gpio_request_by_name(dev, "mosi-gpio", 0, &plat->mosi,
+				 GPIOD_IS_OUT | GPIOD_IS_OUT_ACTIVE) ||
+	    gpio_request_by_name(dev, "miso-gpio", 0, &plat->miso,
+				 GPIOD_IS_IN))
+		return -EINVAL;
 
 	return 0;
 }
-- 
2.2.0.rc0.207.ga3a616c

^ permalink raw reply related	[flat|nested] 49+ messages in thread

* [U-Boot] [PATCH 19/21] dm: tegra: dts: Use TEGRA_GPIO() macro for all GPIOs
  2015-01-06  3:05 [U-Boot] [PATCH 0/21] dm: Support GPIO device tree bindings in the uclass Simon Glass
                   ` (17 preceding siblings ...)
  2015-01-06  3:05 ` [U-Boot] [PATCH 18/21] dm: spi: " Simon Glass
@ 2015-01-06  3:05 ` Simon Glass
  2015-01-15  4:40   ` Simon Glass
  2015-01-06  3:05 ` [U-Boot] [PATCH 20/21] dm: exynos: dts: Use GPIO bank phandles for GPIOs Simon Glass
                   ` (2 subsequent siblings)
  21 siblings, 1 reply; 49+ messages in thread
From: Simon Glass @ 2015-01-06  3:05 UTC (permalink / raw)
  To: u-boot

This new method is much easier and matches the kernel.

Signed-off-by: Simon Glass <sjg@chromium.org>
---

 arch/arm/dts/tegra114-dalmore.dts         |  5 ++---
 arch/arm/dts/tegra124-jetson-tk1.dts      |  9 +++++----
 arch/arm/dts/tegra124-venice2.dts         |  9 +++++----
 arch/arm/dts/tegra20-colibri_t20_iris.dts | 10 +++++-----
 arch/arm/dts/tegra20-harmony.dts          | 28 ++++++++++++++++------------
 arch/arm/dts/tegra20-medcom-wide.dts      |  9 ++++++---
 arch/arm/dts/tegra20-paz00.dts            | 18 +++++++++++-------
 arch/arm/dts/tegra20-seaboard.dts         | 22 +++++++++++++---------
 arch/arm/dts/tegra20-tamonten.dtsi        |  9 +++++----
 arch/arm/dts/tegra20-tec.dts              |  9 ++++++---
 arch/arm/dts/tegra20-trimslice.dts        |  8 ++++----
 arch/arm/dts/tegra20-ventana.dts          | 18 +++++++++++-------
 arch/arm/dts/tegra20-whistler.dts         |  2 +-
 arch/arm/dts/tegra30-apalis.dts           | 10 +++++-----
 arch/arm/dts/tegra30-beaver.dts           | 10 +++++-----
 arch/arm/dts/tegra30-cardhu.dts           |  8 ++++----
 arch/arm/dts/tegra30-colibri.dts          |  6 +++---
 arch/arm/dts/tegra30-tamonten.dtsi        |  4 ++--
 18 files changed, 109 insertions(+), 85 deletions(-)

diff --git a/arch/arm/dts/tegra114-dalmore.dts b/arch/arm/dts/tegra114-dalmore.dts
index 81ad212..51ff266d 100644
--- a/arch/arm/dts/tegra114-dalmore.dts
+++ b/arch/arm/dts/tegra114-dalmore.dts
@@ -57,7 +57,7 @@
 	};
 
 	sdhci at 78000400 {
-		cd-gpios = <&gpio 170 1>; /* gpio PV2 */
+		cd-gpios = <&gpio TEGRA_GPIO(V, 2) GPIO_ACTIVE_LOW>;
 		bus-width = <4>;
 		status = "okay";
 	};
@@ -68,8 +68,7 @@
 	};
 
 	usb at 7d008000 {
-		/* SPDIF_IN: USB_VBUS_EN1 */
-		nvidia,vbus-gpio = <&gpio 86 0>;
+		nvidia,vbus-gpio = <&gpio TEGRA_GPIO(K, 6) GPIO_ACTIVE_HIGH>;
 		status = "okay";
 	};
 };
diff --git a/arch/arm/dts/tegra124-jetson-tk1.dts b/arch/arm/dts/tegra124-jetson-tk1.dts
index 51fef54..e7b66d8 100644
--- a/arch/arm/dts/tegra124-jetson-tk1.dts
+++ b/arch/arm/dts/tegra124-jetson-tk1.dts
@@ -303,8 +303,9 @@
 
 	sdhci at 700b0400 {
 		status = "okay";
-		cd-gpios = <&gpio 170 1>; /* gpio PV2 */
-		power-gpios = <&gpio 136 0>; /* gpio PR0 */
+		cd-gpios = <&gpio TEGRA_GPIO(V, 2) GPIO_ACTIVE_LOW>;
+		power-gpios = <&gpio TEGRA_GPIO(R, 0) GPIO_ACTIVE_HIGH>;
+		wp-gpios = <&gpio TEGRA_GPIO(Q, 4) GPIO_ACTIVE_HIGH>;
 		bus-width = <4>;
 	};
 
@@ -316,12 +317,12 @@
 	usb at 7d000000 {
 		status = "okay";
 		dr_mode = "otg";
-		nvidia,vbus-gpio = <&gpio 108 0>; /* gpio PN4, USB_VBUS_EN0 */
+		nvidia,vbus-gpio = <&gpio TEGRA_GPIO(N, 4) GPIO_ACTIVE_HIGH>;
 	};
 
 	usb at 7d008000 {
 		status = "okay";
-		nvidia,vbus-gpio = <&gpio 109 0>; /* gpio PN5, USB_VBUS_EN1 */
+		nvidia,vbus-gpio = <&gpio TEGRA_GPIO(N, 5) GPIO_ACTIVE_HIGH>;
 	};
 
 	regulators {
diff --git a/arch/arm/dts/tegra124-venice2.dts b/arch/arm/dts/tegra124-venice2.dts
index f7ccfc5..9e93cf9 100644
--- a/arch/arm/dts/tegra124-venice2.dts
+++ b/arch/arm/dts/tegra124-venice2.dts
@@ -72,8 +72,9 @@
 
 	sdhci at 700b0400 {
 		status = "okay";
-		cd-gpios = <&gpio 170 0>; /* gpio PV2 */
-		power-gpios = <&gpio 136 0>; /* gpio PR0 */
+		cd-gpios = <&gpio TEGRA_GPIO(V, 2) GPIO_ACTIVE_HIGH>;
+		power-gpios = <&gpio TEGRA_GPIO(R, 0) GPIO_ACTIVE_HIGH>;
+		wp-gpios = <&gpio TEGRA_GPIO(Q, 4) GPIO_ACTIVE_LOW>;
 		bus-width = <4>;
 	};
 
@@ -85,11 +86,11 @@
 	usb at 7d000000 {
 		status = "okay";
 		dr_mode = "otg";
-		nvidia,vbus-gpio = <&gpio 108 0>; /* gpio PN4, USB_VBUS_EN0 */
+		nvidia,vbus-gpio = <&gpio TEGRA_GPIO(N, 4) GPIO_ACTIVE_HIGH>;
 	};
 
 	usb at 7d008000 {
 		status = "okay";
-		nvidia,vbus-gpio = <&gpio 109 0>; /* gpio PN5, USB_VBUS_EN1 */
+		nvidia,vbus-gpio = <&gpio TEGRA_GPIO(N, 5) GPIO_ACTIVE_HIGH>;
 	};
 };
diff --git a/arch/arm/dts/tegra20-colibri_t20_iris.dts b/arch/arm/dts/tegra20-colibri_t20_iris.dts
index 7cf08f4..3131b92 100644
--- a/arch/arm/dts/tegra20-colibri_t20_iris.dts
+++ b/arch/arm/dts/tegra20-colibri_t20_iris.dts
@@ -22,16 +22,16 @@
 	};
 
 	usb at c5004000 {
-		nvidia,phy-reset-gpio = <&gpio 169 0>; /* PV1 */
-		nvidia,vbus-gpio = <&gpio 217 0>; /* PBB1 */
+		nvidia,phy-reset-gpio = <&gpio TEGRA_GPIO(V, 1) GPIO_ACTIVE_HIGH>;
+		nvidia,vbus-gpio = <&gpio TEGRA_GPIO(BB, 1) GPIO_ACTIVE_HIGH>;
 	};
 
 	usb at c5008000 {
-		nvidia,vbus-gpio = <&gpio 178 1>; /* PW2 low-active */
+		nvidia,vbus-gpio = <&gpio TEGRA_GPIO(W, 2) GPIO_ACTIVE_LOW>;
 	};
 
 	nand-controller at 70008000 {
-		nvidia,wp-gpios = <&gpio 144 0>; /* PS0 */
+		nvidia,wp-gpios = <&gpio TEGRA_GPIO(S, 0) GPIO_ACTIVE_HIGH>;
 		nvidia,width = <8>;
 		nvidia,timing = <15 100 25 80 25 10 15 10 100>;
 
@@ -43,7 +43,7 @@
 
 	sdhci at c8000600 {
 		status = "okay";
-		cd-gpios = <&gpio 23 1>; /* gpio PC7 */
+		cd-gpios = <&gpio TEGRA_GPIO(C, 7) GPIO_ACTIVE_LOW>;
 		bus-width = <4>;
 	};
 };
diff --git a/arch/arm/dts/tegra20-harmony.dts b/arch/arm/dts/tegra20-harmony.dts
index 982a14c..e6e4229 100644
--- a/arch/arm/dts/tegra20-harmony.dts
+++ b/arch/arm/dts/tegra20-harmony.dts
@@ -37,7 +37,7 @@
 	};
 
 	nand-controller at 70008000 {
-		nvidia,wp-gpios = <&gpio 23 0>;		/* PC7 */
+		nvidia,wp-gpios = <&gpio TEGRA_GPIO(C, 7) GPIO_ACTIVE_HIGH>;
 		nvidia,width = <8>;
 		nvidia,timing = <26 100 20 80 20 10 12 10 70>;
 		nand at 0 {
@@ -67,22 +67,22 @@
 	};
 
 	usb at c5004000 {
-		nvidia,phy-reset-gpio = <&gpio 169 0>; /* gpio PV1 */
+		nvidia,phy-reset-gpio = <&gpio TEGRA_GPIO(V, 1) 0>;
 	};
 
 	sdhci at c8000200 {
 		status = "okay";
-		cd-gpios = <&gpio 69 1>; /* gpio PI5 */
-		wp-gpios = <&gpio 57 0>; /* gpio PH1 */
-		power-gpios = <&gpio 155 0>; /* gpio PT3 */
+		cd-gpios = <&gpio TEGRA_GPIO(I, 5) GPIO_ACTIVE_LOW>;
+		wp-gpios = <&gpio TEGRA_GPIO(H, 1) GPIO_ACTIVE_HIGH>;
+		power-gpios = <&gpio TEGRA_GPIO(T, 3) GPIO_ACTIVE_HIGH>;
 		bus-width = <4>;
 	};
 
 	sdhci at c8000600 {
 		status = "okay";
-		cd-gpios = <&gpio 58 1>; /* gpio PH2 */
-		wp-gpios = <&gpio 59 0>; /* gpio PH3 */
-		power-gpios = <&gpio 70 0>; /* gpio PI6 */
+		cd-gpios = <&gpio TEGRA_GPIO(H, 2) GPIO_ACTIVE_LOW>;
+		wp-gpios = <&gpio TEGRA_GPIO(H, 3) GPIO_ACTIVE_HIGH>;
+		power-gpios = <&gpio TEGRA_GPIO(I, 6) GPIO_ACTIVE_HIGH>;
 		bus-width = <8>;
 	};
 
@@ -100,10 +100,14 @@
 		vsyncx-active-high;
 		nvidia,bits-per-pixel = <16>;
 		nvidia,pwm = <&pwm 0 0>;
-		nvidia,backlight-enable-gpios = <&gpio 13 0>;	/* PB5 */
-		nvidia,lvds-shutdown-gpios = <&gpio 10 0>;	/* PB2 */
-		nvidia,backlight-vdd-gpios = <&gpio 176 0>;	/* PW0 */
-		nvidia,panel-vdd-gpios = <&gpio 22 0>;		/* PC6 */
+		nvidia,backlight-enable-gpios = <&gpio TEGRA_GPIO(B, 5)
+							GPIO_ACTIVE_HIGH>;
+		nvidia,lvds-shutdown-gpios = <&gpio TEGRA_GPIO(B, 2)
+							GPIO_ACTIVE_HIGH>;
+		nvidia,backlight-vdd-gpios = <&gpio TEGRA_GPIO(W, 0)
+							GPIO_ACTIVE_HIGH>;
+		nvidia,panel-vdd-gpios = <&gpio TEGRA_GPIO(C, 6)
+							GPIO_ACTIVE_HIGH>;
 		nvidia,panel-timings = <0 0 200 0 0>;
 	};
 };
diff --git a/arch/arm/dts/tegra20-medcom-wide.dts b/arch/arm/dts/tegra20-medcom-wide.dts
index be2ed42..b6b57ab 100644
--- a/arch/arm/dts/tegra20-medcom-wide.dts
+++ b/arch/arm/dts/tegra20-medcom-wide.dts
@@ -73,9 +73,12 @@
 
 		nvidia,bits-per-pixel = <16>;
 		nvidia,pwm = <&pwm 0 500000>;
-		nvidia,backlight-enable-gpios = <&gpio 13 0>; /* PB5 */
-		nvidia,backlight-vdd-gpios = <&gpio 176 0>; /* PW0 */
-		nvidia,lvds-shutdown-gpios = <&gpio 10 0>; /* PB2 */
+		nvidia,backlight-enable-gpios = <&gpio TEGRA_GPIO(B, 5)
+							GPIO_ACTIVE_HIGH>;
+		nvidia,lvds-shutdown-gpios = <&gpio TEGRA_GPIO(B, 2)
+							GPIO_ACTIVE_HIGH>;
+		nvidia,backlight-vdd-gpios = <&gpio TEGRA_GPIO(W, 0)
+							GPIO_ACTIVE_HIGH>;
 		nvidia,panel-timings = <0 0 0 0>;
 	};
 };
diff --git a/arch/arm/dts/tegra20-paz00.dts b/arch/arm/dts/tegra20-paz00.dts
index 9d735b5..16381c3 100644
--- a/arch/arm/dts/tegra20-paz00.dts
+++ b/arch/arm/dts/tegra20-paz00.dts
@@ -61,9 +61,9 @@
 
 	sdhci at c8000000 {
 		status = "okay";
-		cd-gpios = <&gpio 173 1>; /* gpio PV5 */
-		wp-gpios = <&gpio 57 0>; /* gpio PH1 */
-		power-gpios = <&gpio 169 0>; /* gpio PV1 */
+		cd-gpios = <&gpio TEGRA_GPIO(V, 5) GPIO_ACTIVE_LOW>;
+		wp-gpios = <&gpio TEGRA_GPIO(H, 1) GPIO_ACTIVE_HIGH>;
+		power-gpios = <&gpio TEGRA_GPIO(V, 1) GPIO_ACTIVE_HIGH>;
 		bus-width = <4>;
 	};
 
@@ -86,10 +86,14 @@
 		hsync-active-high;
 		nvidia,bits-per-pixel = <16>;
 		nvidia,pwm = <&pwm 0 0>;
-		nvidia,backlight-enable-gpios = <&gpio 164 0>;	/* PU4 */
-		nvidia,lvds-shutdown-gpios = <&gpio 102 0>;	/* PM6 */
-		nvidia,backlight-vdd-gpios = <&gpio 176 0>;	/* PW0 */
-		nvidia,panel-vdd-gpios = <&gpio 4 0>;		/* PA4 */
+		nvidia,backlight-enable-gpios = <&gpio TEGRA_GPIO(U, 4)
+							GPIO_ACTIVE_HIGH>;
+		nvidia,lvds-shutdown-gpios = <&gpio TEGRA_GPIO(M, 6)
+							GPIO_ACTIVE_HIGH>;
+		nvidia,backlight-vdd-gpios = <&gpio TEGRA_GPIO(W, 0)
+							GPIO_ACTIVE_HIGH>;
+		nvidia,panel-vdd-gpios = <&gpio TEGRA_GPIO(A, 4)
+							GPIO_ACTIVE_HIGH>;
 		nvidia,panel-timings = <400 4 203 17 15>;
 	};
 };
diff --git a/arch/arm/dts/tegra20-seaboard.dts b/arch/arm/dts/tegra20-seaboard.dts
index 43b9911..10f3992 100644
--- a/arch/arm/dts/tegra20-seaboard.dts
+++ b/arch/arm/dts/tegra20-seaboard.dts
@@ -65,7 +65,7 @@
 	};
 
 	nand-controller at 70008000 {
-		nvidia,wp-gpios = <&gpio 59 0>;		/* PH3 */
+		nvidia,wp-gpios = <&gpio TEGRA_GPIO(H, 3) GPIO_ACTIVE_HIGH>;
 		nvidia,width = <8>;
 		nvidia,timing = <26 100 20 80 20 10 12 10 70>;
 		nand at 0 {
@@ -151,7 +151,7 @@
 	};
 
 	usb at c5000000 {
-		nvidia,vbus-gpio = <&gpio 24 0>; /* PD0 */
+		nvidia,vbus-gpio = <&gpio TEGRA_GPIO(D, 0) GPIO_ACTIVE_HIGH>;
 		dr_mode = "otg";
 	};
 
@@ -161,9 +161,9 @@
 
 	sdhci at c8000400 {
 		status = "okay";
-		cd-gpios = <&gpio 69 1>; /* gpio PI5 */
-		wp-gpios = <&gpio 57 0>; /* gpio PH1 */
-		power-gpios = <&gpio 70 0>; /* gpio PI6 */
+		cd-gpios = <&gpio TEGRA_GPIO(I, 5) GPIO_ACTIVE_LOW>;
+		wp-gpios = <&gpio TEGRA_GPIO(H, 1) GPIO_ACTIVE_HIGH>;
+		power-gpios = <&gpio TEGRA_GPIO(I, 6) GPIO_ACTIVE_HIGH>;
 		bus-width = <4>;
 	};
 
@@ -186,10 +186,14 @@
 		hsync-active-high;
 		nvidia,bits-per-pixel = <16>;
 		nvidia,pwm = <&pwm 2 0>;
-		nvidia,backlight-enable-gpios = <&gpio 28 0>;	/* PD4 */
-		nvidia,lvds-shutdown-gpios = <&gpio 10 0>;	/* PB2 */
-		nvidia,backlight-vdd-gpios = <&gpio 176 0>;	/* PW0 */
-		nvidia,panel-vdd-gpios = <&gpio 22 0>;		/* PC6 */
+		nvidia,backlight-enable-gpios = <&gpio TEGRA_GPIO(D, 4)
+							GPIO_ACTIVE_HIGH>;
+		nvidia,lvds-shutdown-gpios = <&gpio TEGRA_GPIO(B, 2)
+							GPIO_ACTIVE_HIGH>;
+		nvidia,backlight-vdd-gpios = <&gpio TEGRA_GPIO(W, 0)
+							GPIO_ACTIVE_HIGH>;
+		nvidia,panel-vdd-gpios = <&gpio TEGRA_GPIO(C, 6)
+							GPIO_ACTIVE_HIGH>;
 		nvidia,panel-timings = <400 4 203 17 15>;
 	};
 };
diff --git a/arch/arm/dts/tegra20-tamonten.dtsi b/arch/arm/dts/tegra20-tamonten.dtsi
index f379622..78449e6 100644
--- a/arch/arm/dts/tegra20-tamonten.dtsi
+++ b/arch/arm/dts/tegra20-tamonten.dtsi
@@ -14,7 +14,8 @@
 			pll-supply = <&hdmi_pll_reg>;
 
 			nvidia,ddc-i2c-bus = <&hdmi_ddc>;
-			nvidia,hpd-gpio = <&gpio 111 0>; /* PN7 */
+			nvidia,hpd-gpio = <&gpio TEGRA_GPIO(N, 7)
+				GPIO_ACTIVE_HIGH>;
 		};
 	};
 
@@ -280,7 +281,7 @@
 	};
 
 	nand-controller at 70008000 {
-		nvidia,wp-gpios = <&gpio 23 0>; /* PC7 */
+		nvidia,wp-gpios = <&gpio TEGRA_GPIO(C, 7) GPIO_ACTIVE_HIGH>;
 		nvidia,width = <8>;
 		nvidia,timing = <26 100 20 80 20 10 12 10 70>;
 
@@ -476,8 +477,8 @@
 	};
 
 	sdhci at c8000600 {
-		cd-gpios = <&gpio 58 1>; /* gpio PH2 */
-		wp-gpios = <&gpio 59 0>; /* gpio PH3 */
+		cd-gpios = <&gpio TEGRA_GPIO(H, 2) GPIO_ACTIVE_LOW>;
+		wp-gpios = <&gpio TEGRA_GPIO(H, 3) GPIO_ACTIVE_HIGH>;
 		bus-width = <4>;
 		status = "okay";
 	};
diff --git a/arch/arm/dts/tegra20-tec.dts b/arch/arm/dts/tegra20-tec.dts
index e99bd44..94ba6dc 100644
--- a/arch/arm/dts/tegra20-tec.dts
+++ b/arch/arm/dts/tegra20-tec.dts
@@ -73,9 +73,12 @@
 
 		nvidia,bits-per-pixel = <16>;
 		nvidia,pwm = <&pwm 0 500000>;
-		nvidia,backlight-enable-gpios = <&gpio 13 0>; /* PB5 */
-		nvidia,backlight-vdd-gpios = <&gpio 176 0>; /* PW0 */
-		nvidia,lvds-shutdown-gpios = <&gpio 10 0>; /* PB2 */
+		nvidia,backlight-enable-gpios = <&gpio TEGRA_GPIO(B, 5)
+							GPIO_ACTIVE_HIGH>;
+		nvidia,lvds-shutdown-gpios = <&gpio TEGRA_GPIO(B, 2)
+							GPIO_ACTIVE_HIGH>;
+		nvidia,backlight-vdd-gpios = <&gpio TEGRA_GPIO(W, 0)
+							GPIO_ACTIVE_HIGH>;
 		nvidia,panel-timings = <0 0 0 0>;
 	};
 };
diff --git a/arch/arm/dts/tegra20-trimslice.dts b/arch/arm/dts/tegra20-trimslice.dts
index 1637cbd..27b118f 100644
--- a/arch/arm/dts/tegra20-trimslice.dts
+++ b/arch/arm/dts/tegra20-trimslice.dts
@@ -62,7 +62,7 @@
 	};
 
 	usb at c5000000 {
-		nvidia,vbus-gpio = <&gpio 170 0>; /* PV2 */
+		nvidia,vbus-gpio = <&gpio TEGRA_GPIO(V, 2) GPIO_ACTIVE_HIGH>;
 	};
 
 	usb at c5004000 {
@@ -76,8 +76,8 @@
 
 	sdhci at c8000600 {
 		status = "okay";
-		cd-gpios = <&gpio 121 1>; /* gpio PP1 */
-		wp-gpios = <&gpio 122 0>; /* gpio PP2 */
+		cd-gpios = <&gpio TEGRA_GPIO(P, 1) GPIO_ACTIVE_LOW>;
+		wp-gpios = <&gpio TEGRA_GPIO(P, 2) GPIO_ACTIVE_HIGH>;
 		bus-width = <4>;
 	};
 
@@ -111,7 +111,7 @@
 			regulator-min-microvolt = <5000000>;
 			regulator-max-microvolt = <5000000>;
 			enable-active-high;
-			gpio = <&gpio TEGRA_GPIO(V, 2) 0>;
+			gpio = <&gpio TEGRA_GPIO(V, 2) GPIO_ACTIVE_HIGH>;
 			regulator-always-on;
 			regulator-boot-on;
 		};
diff --git a/arch/arm/dts/tegra20-ventana.dts b/arch/arm/dts/tegra20-ventana.dts
index 6812203..939e567 100644
--- a/arch/arm/dts/tegra20-ventana.dts
+++ b/arch/arm/dts/tegra20-ventana.dts
@@ -61,9 +61,9 @@
 
 	sdhci at c8000400 {
 		status = "okay";
-		cd-gpios = <&gpio 69 1>; /* gpio PI5 */
-		wp-gpios = <&gpio 57 0>; /* gpio PH1 */
-		power-gpios = <&gpio 70 0>; /* gpio PI6 */
+		cd-gpios = <&gpio TEGRA_GPIO(I, 5) GPIO_ACTIVE_LOW>;
+		wp-gpios = <&gpio TEGRA_GPIO(H, 1) GPIO_ACTIVE_HIGH>;
+		power-gpios = <&gpio TEGRA_GPIO(I, 6) GPIO_ACTIVE_HIGH>;
 		bus-width = <4>;
 	};
 
@@ -86,10 +86,14 @@
 		vsync-active-high;
 		nvidia,bits-per-pixel = <16>;
 		nvidia,pwm = <&pwm 2 0>;
-		nvidia,backlight-enable-gpios = <&gpio 28 0>;	/* PD4 */
-		nvidia,lvds-shutdown-gpios = <&gpio 10 0>;	/* PB2 */
-		nvidia,backlight-vdd-gpios = <&gpio 176 0>;	/* PW0 */
-		nvidia,panel-vdd-gpios = <&gpio 22 0>;		/* PC6 */
+		nvidia,backlight-enable-gpios = <&gpio TEGRA_GPIO(D, 4)
+							GPIO_ACTIVE_HIGH>;
+		nvidia,lvds-shutdown-gpios = <&gpio TEGRA_GPIO(B, 2)
+							GPIO_ACTIVE_HIGH>;
+		nvidia,backlight-vdd-gpios = <&gpio TEGRA_GPIO(W, 0)
+							GPIO_ACTIVE_HIGH>;
+		nvidia,panel-vdd-gpios = <&gpio TEGRA_GPIO(C, 6)
+							GPIO_ACTIVE_HIGH>;
 		nvidia,panel-timings = <0 0 200 0 0>;
 	};
 };
diff --git a/arch/arm/dts/tegra20-whistler.dts b/arch/arm/dts/tegra20-whistler.dts
index 4fd2496..c4a28eb 100644
--- a/arch/arm/dts/tegra20-whistler.dts
+++ b/arch/arm/dts/tegra20-whistler.dts
@@ -66,7 +66,7 @@
 
 	sdhci at c8000400 {
 		status = "okay";
-		wp-gpios = <&gpio 173 0>; /* gpio PV5 */
+		wp-gpios = <&gpio TEGRA_GPIO(V, 5) GPIO_ACTIVE_HIGH>;
 		bus-width = <8>;
 	};
 
diff --git a/arch/arm/dts/tegra30-apalis.dts b/arch/arm/dts/tegra30-apalis.dts
index 5bad3e7..15db0f2 100644
--- a/arch/arm/dts/tegra30-apalis.dts
+++ b/arch/arm/dts/tegra30-apalis.dts
@@ -243,13 +243,13 @@
 	sdhci at 78000000 {
 		status = "okay";
 		bus-width = <4>;
-		cd-gpios = <&gpio 229 1>; /* PCC5, SD1_CD# */
+		cd-gpios = <&gpio TEGRA_GPIO(CC, 5) GPIO_ACTIVE_HIGH>;
 	};
 
 	sdhci at 78000400 {
 		status = "okay";
 		bus-width = <8>;
-		cd-gpios = <&gpio 171 1>; /* PV3, MMC1_CD# */
+		cd-gpios = <&gpio TEGRA_GPIO(V, 3) GPIO_ACTIVE_HIGH>;
 	};
 
 	sdhci at 78000600 {
@@ -262,20 +262,20 @@
 	usb at 7d000000 {
 		status = "okay";
 		dr_mode = "peripheral";
-		nvidia,vbus-gpio = <&gpio 157 0>;	/* PT5, USBO1_EN */
+		nvidia,vbus-gpio = <&gpio TEGRA_GPIO(T, 5) GPIO_ACTIVE_HIGH>;
 	};
 
 	/* EHCI instance 1: USB2_DP/N -> USBH2_DP/N */
 	usb at 7d004000 {
 		status = "okay";
-		nvidia,vbus-gpio = <&gpio 233 0>;	/* PDD1, USBH_EN */
+		nvidia,vbus-gpio = <&gpio TEGRA_GPIO(DD, 1) GPIO_ACTIVE_HIGH>;
 		phy_type = "utmi";
 	};
 
 	/* EHCI instance 2: USB3_DP/N -> USBH3_DP/N */
 	usb at 7d008000 {
 		status = "okay";
-		nvidia,vbus-gpio = <&gpio 233 0>;	/* PDD1, USBH_EN */
+		nvidia,vbus-gpio = <&gpio TEGRA_GPIO(DD, 1) GPIO_ACTIVE_HIGH>;
 	};
 
 	regulators {
diff --git a/arch/arm/dts/tegra30-beaver.dts b/arch/arm/dts/tegra30-beaver.dts
index 5903af6..ae83636 100644
--- a/arch/arm/dts/tegra30-beaver.dts
+++ b/arch/arm/dts/tegra30-beaver.dts
@@ -196,9 +196,9 @@
 
 	sdhci at 78000000 {
 		status = "okay";
-		cd-gpios = <&gpio 69 1>; /* gpio PI5 */
-		wp-gpios = <&gpio 155 0>; /* gpio PT3 */
-		power-gpios = <&gpio 31 0>; /* gpio PD7 */
+		cd-gpios = <&gpio TEGRA_GPIO(I, 5) GPIO_ACTIVE_LOW>;
+		wp-gpios = <&gpio TEGRA_GPIO(T, 3) GPIO_ACTIVE_HIGH>;
+		power-gpios = <&gpio TEGRA_GPIO(D, 7) GPIO_ACTIVE_HIGH>;
 		bus-width = <4>;
 	};
 
@@ -210,11 +210,11 @@
 	usb at 7d000000 {
 		status = "okay";
 		dr_mode = "otg";
-		nvidia,vbus-gpio = <&gpio 238 0>; /* gpio DD6, PEX_L1_CLKREQ */
+		nvidia,vbus-gpio = <&gpio TEGRA_GPIO(DD, 6) GPIO_ACTIVE_HIGH>;
 	};
 
 	usb at 7d008000 {
-		nvidia,vbus-gpio = <&gpio 236 0>; /* PDD4 */
+		nvidia,vbus-gpio = <&gpio TEGRA_GPIO(DD, 4) GPIO_ACTIVE_HIGH>;
 		status = "okay";
 	};
 
diff --git a/arch/arm/dts/tegra30-cardhu.dts b/arch/arm/dts/tegra30-cardhu.dts
index e13d0fb..23ca141 100644
--- a/arch/arm/dts/tegra30-cardhu.dts
+++ b/arch/arm/dts/tegra30-cardhu.dts
@@ -185,9 +185,9 @@
 
 	sdhci at 78000000 {
 		status = "okay";
-		cd-gpios = <&gpio 69 1>; /* gpio PI5 */
-		wp-gpios = <&gpio 155 0>; /* gpio PT3 */
-		power-gpios = <&gpio 31 0>; /* gpio PD7 */
+		cd-gpios = <&gpio TEGRA_GPIO(I, 5) GPIO_ACTIVE_LOW>;
+		wp-gpios = <&gpio TEGRA_GPIO(T, 3) GPIO_ACTIVE_HIGH>;
+		power-gpios = <&gpio TEGRA_GPIO(D, 7) GPIO_ACTIVE_HIGH>;
 		bus-width = <4>;
 	};
 
@@ -197,7 +197,7 @@
 	};
 
 	usb at 7d008000 {
-		nvidia,vbus-gpio = <&gpio 236 0>;	/* PDD4 */
+		nvidia,vbus-gpio = <&gpio TEGRA_GPIO(DD, 4) GPIO_ACTIVE_HIGH>;
 		status = "okay";
 	};
 
diff --git a/arch/arm/dts/tegra30-colibri.dts b/arch/arm/dts/tegra30-colibri.dts
index 37b6abd..6cd1902 100644
--- a/arch/arm/dts/tegra30-colibri.dts
+++ b/arch/arm/dts/tegra30-colibri.dts
@@ -64,7 +64,7 @@
 	sdhci at 78000200 {
 		status = "okay";
 		bus-width = <4>;
-		cd-gpios = <&gpio 23 1>; /* PC7, MMCD */
+		cd-gpios = <&gpio TEGRA_GPIO(C, 7) GPIO_ACTIVE_LOW>;
 	};
 
 	sdhci at 78000600 {
@@ -83,12 +83,12 @@
 	usb at 7d004000 {
 		status = "okay";
 		phy_type = "utmi";
-		nvidia,vbus-gpio = <&gpio 234 0>;	/* PDD2, VBUS_LAN */
+		nvidia,vbus-gpio = <&gpio TEGRA_GPIO(DD, 2) GPIO_ACTIVE_HIGH>;
 	};
 
 	/* EHCI instance 2: USB3_DP/N -> USBH_P/N */
 	usb at 7d008000 {
 		status = "okay";
-		nvidia,vbus-gpio = <&gpio 178 1>;	/* PW2, USBH_PEN */
+		nvidia,vbus-gpio = <&gpio TEGRA_GPIO(W, 2) GPIO_ACTIVE_LOW>;
 	};
 };
diff --git a/arch/arm/dts/tegra30-tamonten.dtsi b/arch/arm/dts/tegra30-tamonten.dtsi
index c73afef..8eff627 100644
--- a/arch/arm/dts/tegra30-tamonten.dtsi
+++ b/arch/arm/dts/tegra30-tamonten.dtsi
@@ -55,8 +55,8 @@
 
 	/* SD slot on the base board */
 	sdhci at 78000400 {
-		cd-gpios = <&gpio 69 1>; /* gpio PI5 */
-		wp-gpios = <&gpio 67 0>; /* gpio PI3 */
+		cd-gpios = <&gpio TEGRA_GPIO(I, 5) GPIO_ACTIVE_LOW>;
+		wp-gpios = <&gpio TEGRA_GPIO(I, 3) GPIO_ACTIVE_HIGH>;
 		bus-width = <4>;
 	};
 
-- 
2.2.0.rc0.207.ga3a616c

^ permalink raw reply related	[flat|nested] 49+ messages in thread

* [U-Boot] [PATCH 20/21] dm: exynos: dts: Use GPIO bank phandles for GPIOs
  2015-01-06  3:05 [U-Boot] [PATCH 0/21] dm: Support GPIO device tree bindings in the uclass Simon Glass
                   ` (18 preceding siblings ...)
  2015-01-06  3:05 ` [U-Boot] [PATCH 19/21] dm: tegra: dts: Use TEGRA_GPIO() macro for all GPIOs Simon Glass
@ 2015-01-06  3:05 ` Simon Glass
  2015-01-07  2:44   ` Minkyu Kang
  2015-01-06  3:05 ` [U-Boot] [PATCH 21/21] dm: fdt: Remove the old GPIO functions Simon Glass
  2015-01-13  4:19 ` [U-Boot] [PATCH 0/21] dm: Support GPIO device tree bindings in the uclass Simon Glass
  21 siblings, 1 reply; 49+ messages in thread
From: Simon Glass @ 2015-01-06  3:05 UTC (permalink / raw)
  To: u-boot

U-Boot now supports using GPIOs using bank phandles instead of global
numbers. Update the exynos device tree files to use this.

Signed-off-by: Simon Glass <sjg@chromium.org>
---

 arch/arm/dts/exynos4.dtsi                  |  7 -------
 arch/arm/dts/exynos4210-origen.dts         |  2 +-
 arch/arm/dts/exynos4210-trats.dts          |  4 ++--
 arch/arm/dts/exynos4210-universal_c210.dts | 12 ++++++------
 arch/arm/dts/exynos4412-odroid.dts         |  2 +-
 arch/arm/dts/exynos4412-trats2.dts         |  6 +++---
 arch/arm/dts/exynos5.dtsi                  |  4 +---
 arch/arm/dts/exynos5250-smdk5250.dts       |  2 +-
 arch/arm/dts/exynos5250-snow.dts           | 10 +++++-----
 arch/arm/dts/exynos5420-peach-pit.dts      |  8 ++++----
 arch/arm/dts/exynos5422-odroidxu3.dts      |  2 +-
 arch/arm/dts/exynos5800-peach-pi.dts       | 10 +++++-----
 12 files changed, 30 insertions(+), 39 deletions(-)

diff --git a/arch/arm/dts/exynos4.dtsi b/arch/arm/dts/exynos4.dtsi
index 77fad48..3c983ed 100644
--- a/arch/arm/dts/exynos4.dtsi
+++ b/arch/arm/dts/exynos4.dtsi
@@ -143,11 +143,4 @@
 		interrupts = <0 131 0>;
 	};
 
-	gpio: gpio {
-		gpio-controller;
-		#gpio-cells = <2>;
-
-		interrupt-controller;
-		#interrupt-cells = <2>;
-	};
 };
diff --git a/arch/arm/dts/exynos4210-origen.dts b/arch/arm/dts/exynos4210-origen.dts
index dd2476c..3f87761 100644
--- a/arch/arm/dts/exynos4210-origen.dts
+++ b/arch/arm/dts/exynos4210-origen.dts
@@ -36,7 +36,7 @@
 	sdhci at 12530000 {
 		samsung,bus-width = <4>;
 		samsung,timing = <1 2 3>;
-		cd-gpios = <&gpio 0xA2 0>;
+		cd-gpios = <&gpk2 2 0>;
 	};
 
 	sdhci at 12540000 {
diff --git a/arch/arm/dts/exynos4210-trats.dts b/arch/arm/dts/exynos4210-trats.dts
index 8c7a2c3..36d02df 100644
--- a/arch/arm/dts/exynos4210-trats.dts
+++ b/arch/arm/dts/exynos4210-trats.dts
@@ -101,7 +101,7 @@
 	sdhci at 12510000 {
 		samsung,bus-width = <8>;
 		samsung,timing = <1 3 3>;
-		pwr-gpios = <&gpio 146 0>;
+		pwr-gpios = <&gpk0 2 0>;
 	};
 
 	sdhci at 12520000 {
@@ -111,7 +111,7 @@
 	sdhci at 12530000 {
 		samsung,bus-width = <4>;
 		samsung,timing = <1 2 3>;
-		cd-gpios = <&gpio 284 0>;
+		cd-gpios = <&gpx3 4 0>;
 	};
 
 	sdhci at 12540000 {
diff --git a/arch/arm/dts/exynos4210-universal_c210.dts b/arch/arm/dts/exynos4210-universal_c210.dts
index 808c3f7..16948c9 100644
--- a/arch/arm/dts/exynos4210-universal_c210.dts
+++ b/arch/arm/dts/exynos4210-universal_c210.dts
@@ -24,7 +24,7 @@
 	sdhci at 12510000 {
 		samsung,bus-width = <8>;
 		samsung,timing = <1 3 3>;
-		pwr-gpios = <&gpio 146 0>;
+		pwr-gpios = <&gpk0 2 0>;
 	};
 
 	sdhci at 12520000 {
@@ -34,7 +34,7 @@
 	sdhci at 12530000 {
 		samsung,bus-width = <4>;
 		samsung,timing = <1 2 3>;
-		cd-gpios = <&gpio 284 0>;
+		cd-gpios = <&gpx3 4 0>;
 	};
 
 	sdhci at 12540000 {
@@ -43,10 +43,10 @@
 
 	soft-spi {
 		compatible = "u-boot,soft-spi";
-		cs-gpio = <&gpio 235 0>;	/* Y43 */
-		sclk-gpio = <&gpio 225 0>;	/* Y31 */
-		mosi-gpio = <&gpio 227 0>;	/* Y33 */
-		miso-gpio = <&gpio 224 0>;	/* Y30 */
+		cs-gpio = <&gpy4 3 0>;
+		sclk-gpio = <&gpy3 1 0>;
+		mosi-gpio = <&gpy3 3 0>;
+		miso-gpio = <&gpy3 0 0>;
 		spi-delay-us = <1>;
 		#address-cells = <1>;
 		#size-cells = <0>;
diff --git a/arch/arm/dts/exynos4412-odroid.dts b/arch/arm/dts/exynos4412-odroid.dts
index c78efec..29ad6ab 100644
--- a/arch/arm/dts/exynos4412-odroid.dts
+++ b/arch/arm/dts/exynos4412-odroid.dts
@@ -51,7 +51,7 @@
 	sdhci at 12530000 {
 		samsung,bus-width = <4>;
 		samsung,timing = <1 2 3>;
-		cd-gpios = <&gpio 122 0>;
+		cd-gpios = <&gpk2 2 0>;
 	};
 
 	sdhci at 12540000 {
diff --git a/arch/arm/dts/exynos4412-trats2.dts b/arch/arm/dts/exynos4412-trats2.dts
index 60e4515..dd238df 100644
--- a/arch/arm/dts/exynos4412-trats2.dts
+++ b/arch/arm/dts/exynos4412-trats2.dts
@@ -416,7 +416,7 @@
 	sdhci at 12510000 {
 		samsung,bus-width = <8>;
 		samsung,timing = <1 3 3>;
-		pwr-gpios = <&gpio 0x6a 0>;
+		pwr-gpios = <&gpk0 4 0>;
 		status = "disabled";
 	};
 
@@ -427,7 +427,7 @@
 	sdhci at 12530000 {
 		samsung,bus-width = <4>;
 		samsung,timing = <1 2 3>;
-		cd-gpios = <&gpio 0x7a 0>;
+		cd-gpios = <&gpk2 2 0>;
 	};
 
 	sdhci at 12540000 {
@@ -437,7 +437,7 @@
 	dwmmc at 12550000 {
 		samsung,bus-width = <8>;
 		samsung,timing = <2 1 0>;
-		pwr-gpios = <&gpio 0x6a 0>;
+		pwr-gpios = <&gpk0 4 0>;
 		fifoth_val = <0x203f0040>;
 		bus_hz = <400000000>;
 		div = <0x3>;
diff --git a/arch/arm/dts/exynos5.dtsi b/arch/arm/dts/exynos5.dtsi
index e539068..238acb8 100644
--- a/arch/arm/dts/exynos5.dtsi
+++ b/arch/arm/dts/exynos5.dtsi
@@ -6,6 +6,7 @@
  */
 
 #include "skeleton.dtsi"
+#include <dt-bindings/gpio/gpio.h>
 
 / {
 	compatible = "samsung,exynos5";
@@ -247,7 +248,4 @@
 		u-boot,dm-pre-reloc;
 		id = <3>;
 	};
-
-	gpio: gpio {
-	};
 };
diff --git a/arch/arm/dts/exynos5250-smdk5250.dts b/arch/arm/dts/exynos5250-smdk5250.dts
index 8850409..9273562 100644
--- a/arch/arm/dts/exynos5250-smdk5250.dts
+++ b/arch/arm/dts/exynos5250-smdk5250.dts
@@ -146,6 +146,6 @@
 	};
 
 	ehci at 12110000 {
-		samsung,vbus-gpio = <&gpio 0x316 0>; /* X26 */
+		samsung,vbus-gpio = <&gpx2 6 GPIO_ACTIVE_HIGH>;
 	};
 };
diff --git a/arch/arm/dts/exynos5250-snow.dts b/arch/arm/dts/exynos5250-snow.dts
index 95af025..b1a05a1 100644
--- a/arch/arm/dts/exynos5250-snow.dts
+++ b/arch/arm/dts/exynos5250-snow.dts
@@ -44,7 +44,7 @@
 			reg = <0x1e>;
 			compatible = "google,cros-ec";
 			i2c-max-frequency = <100000>;
-			ec-interrupt = <&gpio 182 1>;
+			ec-interrupt = <&gpx1 6 GPIO_ACTIVE_LOW>;
 		};
 
 		power-regulator at 48 {
@@ -68,7 +68,7 @@
 			reg = <0>;
 			compatible = "google,cros-ec";
 			spi-max-frequency = <5000000>;
-			ec-interrupt = <&gpio 182 1>;
+			ec-interrupt = <&gpx1 6 GPIO_ACTIVE_LOW>;
 			optimise-flash-write;
 			status = "disabled";
 		};
@@ -76,7 +76,7 @@
 
 	sound at 3830000 {
 		samsung,codec-type = "max98095";
-		codec-enable-gpio = <&gpio 0xb7 0>;
+		codec-enable-gpio = <&gpx1 7 GPIO_ACTIVE_HIGH>;
 	};
 
 	sound at 12d60000 {
@@ -131,11 +131,11 @@
 	};
 
 	ehci at 12110000 {
-		samsung,vbus-gpio = <&gpio 0xb1 0>; /* X11 */
+		samsung,vbus-gpio = <&gpx1 1 GPIO_ACTIVE_HIGH>;
 	};
 
 	xhci at 12000000 {
-		samsung,vbus-gpio = <&gpio 0xbf 0>; /* X27 */
+		samsung,vbus-gpio = <&gpx2 7 GPIO_ACTIVE_HIGH>;
 	};
 
 	tmu at 10060000 {
diff --git a/arch/arm/dts/exynos5420-peach-pit.dts b/arch/arm/dts/exynos5420-peach-pit.dts
index fde863d..8bb651c 100644
--- a/arch/arm/dts/exynos5420-peach-pit.dts
+++ b/arch/arm/dts/exynos5420-peach-pit.dts
@@ -17,7 +17,7 @@
 		"google,peach", "samsung,exynos5420", "samsung,exynos5";
 
 	config {
-		google,bad-wake-gpios = <&gpio 0x56 0>; /* gpx0-6 */
+		google,bad-wake-gpios = <&gpx0 6 GPIO_ACTIVE_HIGH>;
 		hwid = "PIT TEST A-A 7848";
 		lazy-init = <1>;
 	};
@@ -163,7 +163,7 @@
 			spi-half-duplex;
 			spi-max-timeout-ms = <1100>;
 			spi-frame-header = <0xec>;
-			ec-interrupt = <&gpio 93 1>; /* GPX1_5 */
+			ec-interrupt = <&gpx1 5 GPIO_ACTIVE_LOW>;
 
 			/*
 			 * This describes the flash memory within the EC. Note
@@ -179,11 +179,11 @@
 	};
 
 	xhci at 12000000 {
-		samsung,vbus-gpio = <&gpio 0x40 0>; /* H00 */
+		samsung,vbus-gpio = <&gph0 0 GPIO_ACTIVE_HIGH>;
 	};
 
 	xhci at 12400000 {
-		samsung,vbus-gpio = <&gpio 0x41 0>; /* H01 */
+		samsung,vbus-gpio = <&gph0 1 GPIO_ACTIVE_HIGH>;
 	};
 
 	fimd at 14400000 {
diff --git a/arch/arm/dts/exynos5422-odroidxu3.dts b/arch/arm/dts/exynos5422-odroidxu3.dts
index 79a7acd..8f46637 100644
--- a/arch/arm/dts/exynos5422-odroidxu3.dts
+++ b/arch/arm/dts/exynos5422-odroidxu3.dts
@@ -32,7 +32,7 @@
 	};
 
 	ehci at 12110000 {
-		samsung,vbus-gpio = <&gpio 0x66 0>; /* X26 */
+		samsung,vbus-gpio = <&gpx2 6 GPIO_ACTIVE_HIGH>;
 	};
 
 	serial at 12C20000 {
diff --git a/arch/arm/dts/exynos5800-peach-pi.dts b/arch/arm/dts/exynos5800-peach-pi.dts
index 2f9d2db..81db8b6 100644
--- a/arch/arm/dts/exynos5800-peach-pi.dts
+++ b/arch/arm/dts/exynos5800-peach-pi.dts
@@ -17,7 +17,7 @@
 		"google,peach", "samsung,exynos5800", "samsung,exynos5";
 
 	config {
-		google,bad-wake-gpios = <&gpio 0x56 0>; /* gpx0-6 */
+		google,bad-wake-gpios = <&gpx0 6 GPIO_ACTIVE_HIGH>;
 		hwid = "PIT TEST A-A 7848";
 		lazy-init = <1>;
 	};
@@ -32,7 +32,7 @@
 		mem-manuf = "samsung";
 		mem-type = "ddr3";
 		clock-frequency = <800000000>;
-		arm-frequency = <1700000000>;
+		arm-frequency = <900000000>;
 	};
 
 	tmu at 10060000 {
@@ -102,7 +102,7 @@
 			spi-half-duplex;
 			spi-max-timeout-ms = <1100>;
 			spi-frame-header = <0xec>;
-			ec-interrupt = <&gpio 93 1>; /* GPX1_5 */
+			ec-interrupt = <&gpx1 5 GPIO_ACTIVE_LOW>;
 
 			/*
 			 * This describes the flash memory within the EC. Note
@@ -118,11 +118,11 @@
 	};
 
 	xhci at 12000000 {
-		samsung,vbus-gpio = <&gpio 0x40 0>; /* H00 */
+		samsung,vbus-gpio = <&gph0 0 GPIO_ACTIVE_HIGH>;
 	};
 
 	xhci at 12400000 {
-		samsung,vbus-gpio = <&gpio 0x41 0>; /* H01 */
+		samsung,vbus-gpio = <&gph0 1 GPIO_ACTIVE_HIGH>;
 	};
 
 	fimd at 14400000 {
-- 
2.2.0.rc0.207.ga3a616c

^ permalink raw reply related	[flat|nested] 49+ messages in thread

* [U-Boot] [PATCH 21/21] dm: fdt: Remove the old GPIO functions
  2015-01-06  3:05 [U-Boot] [PATCH 0/21] dm: Support GPIO device tree bindings in the uclass Simon Glass
                   ` (19 preceding siblings ...)
  2015-01-06  3:05 ` [U-Boot] [PATCH 20/21] dm: exynos: dts: Use GPIO bank phandles for GPIOs Simon Glass
@ 2015-01-06  3:05 ` Simon Glass
  2015-01-15  4:40   ` Simon Glass
  2015-01-15  7:28   ` Masahiro Yamada
  2015-01-13  4:19 ` [U-Boot] [PATCH 0/21] dm: Support GPIO device tree bindings in the uclass Simon Glass
  21 siblings, 2 replies; 49+ messages in thread
From: Simon Glass @ 2015-01-06  3:05 UTC (permalink / raw)
  To: u-boot

Now that we support device tree GPIO bindings directly in the driver model
GPIO uclass we can remove these functions.

Signed-off-by: Simon Glass <sjg@chromium.org>
---

 include/fdtdec.h | 77 ---------------------------------------------
 lib/fdtdec.c     | 95 --------------------------------------------------------
 2 files changed, 172 deletions(-)

diff --git a/include/fdtdec.h b/include/fdtdec.h
index 629e072..54b716e 100644
--- a/include/fdtdec.h
+++ b/include/fdtdec.h
@@ -186,39 +186,6 @@ int fdtdec_parse_phandle_with_args(const void *blob, int src_node,
 				   int cell_count, int index,
 				   struct fdtdec_phandle_args *out_args);
 
-/* GPIOs are numbered from 0 */
-enum {
-	FDT_GPIO_NONE = -1U,	/* an invalid GPIO used to end our list */
-
-	FDT_GPIO_ACTIVE_LOW = 1 << 0,	/* input is active low (else high) */
-};
-
-/* This is the state of a GPIO pin as defined by the fdt */
-struct fdt_gpio_state {
-	const char *name;	/* name of the fdt property defining this */
-	uint gpio;		/* GPIO number, or FDT_GPIO_NONE if none */
-	u8 flags;		/* FDT_GPIO_... flags */
-};
-
-/* This tells us whether a fdt_gpio_state record is valid or not */
-#define fdt_gpio_isvalid(x) ((x)->gpio != FDT_GPIO_NONE)
-
-/**
- * Read the GPIO taking into account the polarity of the pin.
- *
- * @param gpio		pointer to the decoded gpio
- * @return value of the gpio if successful, < 0 if unsuccessful
- */
-int fdtdec_get_gpio(struct fdt_gpio_state *gpio);
-
-/**
- * Write the GPIO taking into account the polarity of the pin.
- *
- * @param gpio		pointer to the decoded gpio
- * @return 0 if successful
- */
-int fdtdec_set_gpio(struct fdt_gpio_state *gpio, int val);
-
 /**
  * Find the next numbered alias for a peripheral. This is used to enumerate
  * all the peripherals of a certain type.
@@ -546,50 +513,6 @@ const u32 *fdtdec_locate_array(const void *blob, int node,
 int fdtdec_get_bool(const void *blob, int node, const char *prop_name);
 
 /**
- * Decode a single GPIOs from an FDT.
- *
- * If the property is not found, then the GPIO structure will still be
- * initialised, with gpio set to FDT_GPIO_NONE. This makes it easy to
- * provide optional GPIOs.
- *
- * @param blob		FDT blob to use
- * @param node		Node to look at
- * @param prop_name	Node property name
- * @param gpio		gpio elements to fill from FDT
- * @return 0 if ok, -FDT_ERR_NOTFOUND if the property is missing.
- */
-int fdtdec_decode_gpio(const void *blob, int node, const char *prop_name,
-		struct fdt_gpio_state *gpio);
-
-/**
- * Decode a list of GPIOs from an FDT. This creates a list of GPIOs with no
- * terminating item.
- *
- * @param blob         FDT blob to use
- * @param node         Node to look at
- * @param prop_name    Node property name
- * @param gpio         Array of gpio elements to fill from FDT. This will be
- *                     untouched if either 0 or an error is returned
- * @param max_count    Maximum number of elements allowed
- * @return number of GPIOs read if ok, -FDT_ERR_BADLAYOUT if max_count would
- * be exceeded, or -FDT_ERR_NOTFOUND if the property is missing.
- */
-int fdtdec_decode_gpios(const void *blob, int node, const char *prop_name,
-		struct fdt_gpio_state *gpio, int max_count);
-
-/**
- * Set up a GPIO pin according to the provided gpio information. At present this
- * just requests the GPIO.
- *
- * If the gpio is FDT_GPIO_NONE, no action is taken. This makes it easy to
- * deal with optional GPIOs.
- *
- * @param gpio		GPIO info to use for set up
- * @return 0 if all ok or gpio was FDT_GPIO_NONE; -1 on error
- */
-int fdtdec_setup_gpio(struct fdt_gpio_state *gpio);
-
-/**
  * Look in the FDT for a config item with the given name and return its value
  * as a 32-bit integer. The property must have@least 4 bytes of data. The
  * value of the first cell is returned.
diff --git a/lib/fdtdec.c b/lib/fdtdec.c
index d6bc783..71adc06 100644
--- a/lib/fdtdec.c
+++ b/lib/fdtdec.c
@@ -645,101 +645,6 @@ int fdtdec_parse_phandle_with_args(const void *blob, int src_node,
 	return rc;
 }
 
-/**
- * Decode a list of GPIOs from an FDT. This creates a list of GPIOs with no
- * terminating item.
- *
- * @param blob		FDT blob to use
- * @param node		Node to look at
- * @param prop_name	Node property name
- * @param gpio		Array of gpio elements to fill from FDT. This will be
- *			untouched if either 0 or an error is returned
- * @param max_count	Maximum number of elements allowed
- * @return number of GPIOs read if ok, -FDT_ERR_BADLAYOUT if max_count would
- * be exceeded, or -FDT_ERR_NOTFOUND if the property is missing.
- */
-int fdtdec_decode_gpios(const void *blob, int node, const char *prop_name,
-		struct fdt_gpio_state *gpio, int max_count)
-{
-	const struct fdt_property *prop;
-	const u32 *cell;
-	const char *name;
-	int len, i;
-
-	debug("%s: %s\n", __func__, prop_name);
-	assert(max_count > 0);
-	prop = fdt_get_property(blob, node, prop_name, &len);
-	if (!prop) {
-		debug("%s: property '%s' missing\n", __func__, prop_name);
-		return -FDT_ERR_NOTFOUND;
-	}
-
-	/* We will use the name to tag the GPIO */
-	name = fdt_string(blob, fdt32_to_cpu(prop->nameoff));
-	cell = (u32 *)prop->data;
-	len /= sizeof(u32) * 3;		/* 3 cells per GPIO record */
-	if (len > max_count) {
-		debug(" %s: too many GPIOs / cells for "
-			"property '%s'\n", __func__, prop_name);
-		return -FDT_ERR_BADLAYOUT;
-	}
-
-	/* Read out the GPIO data from the cells */
-	for (i = 0; i < len; i++, cell += 3) {
-		gpio[i].gpio = fdt32_to_cpu(cell[1]);
-		gpio[i].flags = fdt32_to_cpu(cell[2]);
-		gpio[i].name = name;
-	}
-
-	return len;
-}
-
-int fdtdec_decode_gpio(const void *blob, int node, const char *prop_name,
-		struct fdt_gpio_state *gpio)
-{
-	int err;
-
-	debug("%s: %s\n", __func__, prop_name);
-	gpio->gpio = FDT_GPIO_NONE;
-	gpio->name = NULL;
-	err = fdtdec_decode_gpios(blob, node, prop_name, gpio, 1);
-	return err == 1 ? 0 : err;
-}
-
-int fdtdec_get_gpio(struct fdt_gpio_state *gpio)
-{
-	int val;
-
-	if (!fdt_gpio_isvalid(gpio))
-		return -1;
-
-	val = gpio_get_value(gpio->gpio);
-	return gpio->flags & FDT_GPIO_ACTIVE_LOW ? val ^ 1 : val;
-}
-
-int fdtdec_set_gpio(struct fdt_gpio_state *gpio, int val)
-{
-	if (!fdt_gpio_isvalid(gpio))
-		return -1;
-
-	val = gpio->flags & FDT_GPIO_ACTIVE_LOW ? val ^ 1 : val;
-	return gpio_set_value(gpio->gpio, val);
-}
-
-int fdtdec_setup_gpio(struct fdt_gpio_state *gpio)
-{
-	/*
-	 * Return success if there is no GPIO defined. This is used for
-	 * optional GPIOs)
-	 */
-	if (!fdt_gpio_isvalid(gpio))
-		return 0;
-
-	if (gpio_request(gpio->gpio, gpio->name))
-		return -1;
-	return 0;
-}
-
 int fdtdec_get_byte_array(const void *blob, int node, const char *prop_name,
 		u8 *array, int count)
 {
-- 
2.2.0.rc0.207.ga3a616c

^ permalink raw reply related	[flat|nested] 49+ messages in thread

* [U-Boot] [PATCH 20/21] dm: exynos: dts: Use GPIO bank phandles for GPIOs
  2015-01-06  3:05 ` [U-Boot] [PATCH 20/21] dm: exynos: dts: Use GPIO bank phandles for GPIOs Simon Glass
@ 2015-01-07  2:44   ` Minkyu Kang
  2015-01-15  4:40     ` Simon Glass
  0 siblings, 1 reply; 49+ messages in thread
From: Minkyu Kang @ 2015-01-07  2:44 UTC (permalink / raw)
  To: u-boot

On 06/01/15 12:05, Simon Glass wrote:
> U-Boot now supports using GPIOs using bank phandles instead of global
> numbers. Update the exynos device tree files to use this.
> 
> Signed-off-by: Simon Glass <sjg@chromium.org>
> ---
> 
>  arch/arm/dts/exynos4.dtsi                  |  7 -------
>  arch/arm/dts/exynos4210-origen.dts         |  2 +-
>  arch/arm/dts/exynos4210-trats.dts          |  4 ++--
>  arch/arm/dts/exynos4210-universal_c210.dts | 12 ++++++------
>  arch/arm/dts/exynos4412-odroid.dts         |  2 +-
>  arch/arm/dts/exynos4412-trats2.dts         |  6 +++---
>  arch/arm/dts/exynos5.dtsi                  |  4 +---
>  arch/arm/dts/exynos5250-smdk5250.dts       |  2 +-
>  arch/arm/dts/exynos5250-snow.dts           | 10 +++++-----
>  arch/arm/dts/exynos5420-peach-pit.dts      |  8 ++++----
>  arch/arm/dts/exynos5422-odroidxu3.dts      |  2 +-
>  arch/arm/dts/exynos5800-peach-pi.dts       | 10 +++++-----
>  12 files changed, 30 insertions(+), 39 deletions(-)
> 

Acked-by: Minkyu Kang <mk7.kang@samsung.com>

Thanks,
Minkyu Kang.

^ permalink raw reply	[flat|nested] 49+ messages in thread

* [U-Boot] [PATCH 0/21] dm: Support GPIO device tree bindings in the uclass
  2015-01-06  3:05 [U-Boot] [PATCH 0/21] dm: Support GPIO device tree bindings in the uclass Simon Glass
                   ` (20 preceding siblings ...)
  2015-01-06  3:05 ` [U-Boot] [PATCH 21/21] dm: fdt: Remove the old GPIO functions Simon Glass
@ 2015-01-13  4:19 ` Simon Glass
  21 siblings, 0 replies; 49+ messages in thread
From: Simon Glass @ 2015-01-13  4:19 UTC (permalink / raw)
  To: u-boot

Hi Reviewers,

On 5 January 2015 at 19:05, Simon Glass <sjg@chromium.org> wrote:
> At present U-Boot sort-of supports the standard way of reading GPIOs from
> device tree nodes, but the support is incomplete, a bit clunky and only
> works for GPIO bindings where #gpio-cells is 2.
>
> Also, this support can now be built into the uclass, rather than parked in
> a separate file.
>
> Add support for requesting GPIOs based on a list in a device tree node, by
> looking up the phandles. Convert existing boards and remove the old code.
>
> As a side-effect, we now no-longer need to include <asm/gpio.h> in fdtdec.h,
> a problem reported by Masahiro and others.
>
> This series is tested on boards as follows, with the objective being to cover
> each code path:
>
> seaboard
> --------
> LCD comes up, USB host shows partitions, NAND can read/write. Both internal
> MMC and external SD card partition can be read. Ejecting external SD card is
> detected
>
> Tegra20 (SeaBoard) # gpio status
> Bank B:
> B2: output: 1 [x] panel.nvidia,lvds-shutdown-gpios
>
> Bank C:
> C6: output: 1 [x] panel.nvidia,panel-vdd-gpios
>
> Bank D:
> D0: output: 0 [x] usb at c5000000.nvidia,vbus-gpio
> D4: output: 1 [x] panel.nvidia,backlight-enable-gpios
>
> Bank H:
> H1: input: 0 [x] sdhci at c8000400.wp-gpios
> H3: output: 1 [x] nand-controller at 70008000.nvidia,wp-gpios
>
> Bank I:
> I5: input: 0 [x] sdhci at c8000400.cd-gpios
> I6: output: 1 [x] sdhci at c8000400.power-gpios
>
> Bank W:
> W0: output: 1 [x] panel.nvidia,backlight-vdd-gpios
>
> pit
> ---
> LCD comes up, internal MMC and external uSD cards can show a partition list.
> EC works and the interrupt line behaves as expected. USB stick can display
> a partition list.
>
>

Please take a look at this series if you have time. A bit of feedback
on the Exynos and Tegra side would be helpful.

> --
> EC works correctly.
>
>
> Simon Glass (21):
>   dm: gpio: Bring in GPIO device tree binding
>   dm: exynos: Bring in GPIO device tree binding
>   dm: tegra: Bring in GPIO device tree binding
>   dm: fdt: Add a function to decode phandles with arguments
>   dm: gpio: Add a native driver model API
>   dm: gpio: Add a driver GPIO translation method
>   dm: gpio: Add better functions to request GPIOs
>   dm: gpio: Mark the old GPIO API deprecated
>   dm: demo: Add a simple GPIO demonstration
>   dm: cros_ec: Remove use of fdtdec GPIO support
>   dm: tegra: Add a GPIO translation function
>   dm: exynos: Add a GPIO translation function
>   dm: tegra: video: Remove use of fdtdec GPIO support
>   dm: tegra: nand: Remove use of fdtdec GPIO support
>   dm: zynq: Remove inline gpio functions
>   dm: mmc: Remove use of fdtdec GPIO support
>   dm: usb: Remove use of fdtdec GPIO support
>   dm: spi: Remove use of fdtdec GPIO support
>   dm: tegra: dts: Use TEGRA_GPIO() macro for all GPIOs
>   dm: exynos: dts: Use GPIO bank phandles for GPIOs
>   dm: fdt: Remove the old GPIO functions
>
>  arch/arm/dts/exynos4.dtsi                          |   7 -
>  arch/arm/dts/exynos4210-origen.dts                 |   2 +-
>  arch/arm/dts/exynos4210-trats.dts                  |   4 +-
>  arch/arm/dts/exynos4210-universal_c210.dts         |  12 +-
>  arch/arm/dts/exynos4412-odroid.dts                 |   2 +-
>  arch/arm/dts/exynos4412-trats2.dts                 |   6 +-
>  arch/arm/dts/exynos5.dtsi                          |   4 +-
>  arch/arm/dts/exynos5250-smdk5250.dts               |   2 +-
>  arch/arm/dts/exynos5250-snow.dts                   |  10 +-
>  arch/arm/dts/exynos5420-peach-pit.dts              |   8 +-
>  arch/arm/dts/exynos5422-odroidxu3.dts              |   2 +-
>  arch/arm/dts/exynos5800-peach-pi.dts               |  10 +-
>  arch/arm/dts/tegra114-dalmore.dts                  |   5 +-
>  arch/arm/dts/tegra124-jetson-tk1.dts               |   9 +-
>  arch/arm/dts/tegra124-venice2.dts                  |   9 +-
>  arch/arm/dts/tegra20-colibri_t20_iris.dts          |  10 +-
>  arch/arm/dts/tegra20-harmony.dts                   |  28 +-
>  arch/arm/dts/tegra20-medcom-wide.dts               |   9 +-
>  arch/arm/dts/tegra20-paz00.dts                     |  18 +-
>  arch/arm/dts/tegra20-seaboard.dts                  |  22 +-
>  arch/arm/dts/tegra20-tamonten.dtsi                 |   9 +-
>  arch/arm/dts/tegra20-tec.dts                       |   9 +-
>  arch/arm/dts/tegra20-trimslice.dts                 |   8 +-
>  arch/arm/dts/tegra20-ventana.dts                   |  18 +-
>  arch/arm/dts/tegra20-whistler.dts                  |   2 +-
>  arch/arm/dts/tegra30-apalis.dts                    |  10 +-
>  arch/arm/dts/tegra30-beaver.dts                    |  10 +-
>  arch/arm/dts/tegra30-cardhu.dts                    |   8 +-
>  arch/arm/dts/tegra30-colibri.dts                   |   6 +-
>  arch/arm/dts/tegra30-tamonten.dtsi                 |   4 +-
>  arch/arm/include/asm/arch-pantheon/gpio.h          |   0
>  arch/arm/include/asm/arch-tegra/tegra_mmc.h        |   7 +-
>  arch/arm/include/asm/arch-tegra20/display.h        |   9 +-
>  arch/arm/include/asm/arch-zynq/gpio.h              |  15 -
>  arch/sandbox/dts/sandbox.dts                       |  11 +-
>  common/cmd_demo.c                                  |  29 +-
>  doc/device-tree-bindings/gpio/gpio-samsung.txt     |  41 +++
>  doc/device-tree-bindings/gpio/gpio.txt             | 211 +++++++++++
>  .../gpio/nvidia,tegra20-gpio.txt                   |  40 +++
>  drivers/demo/demo-shape.c                          |  71 ++++
>  drivers/demo/demo-uclass.c                         |  20 ++
>  drivers/gpio/gpio-uclass.c                         | 396 +++++++++++++++++----
>  drivers/gpio/s5p_gpio.c                            |  13 +-
>  drivers/gpio/sandbox.c                             |  20 ++
>  drivers/gpio/tegra_gpio.c                          |  18 +
>  drivers/misc/cros_ec.c                             |  24 +-
>  drivers/mmc/s5p_sdhci.c                            |  20 +-
>  drivers/mmc/tegra_mmc.c                            |  36 +-
>  drivers/mtd/nand/tegra_nand.c                      |   9 +-
>  drivers/spi/soft_spi.c                             |  62 ++--
>  drivers/usb/host/ehci-exynos.c                     |  10 +-
>  drivers/usb/host/ehci-tegra.c                      |  38 +-
>  drivers/usb/host/xhci-exynos5.c                    |  10 +-
>  drivers/video/tegra.c                              |  54 ++-
>  include/asm-generic/gpio.h                         | 265 ++++++++++++++
>  include/cros_ec.h                                  |   3 +-
>  include/dm-demo.h                                  |   4 +
>  include/fdtdec.h                                   | 116 +++---
>  include/sdhci.h                                    |   6 +-
>  lib/fdtdec.c                                       | 195 +++++-----
>  test/dm/gpio.c                                     |  69 +++-
>  test/dm/test.dts                                   |  11 +-
>  62 files changed, 1561 insertions(+), 535 deletions(-)
>  create mode 100644 arch/arm/include/asm/arch-pantheon/gpio.h
>  create mode 100644 doc/device-tree-bindings/gpio/gpio-samsung.txt
>  create mode 100644 doc/device-tree-bindings/gpio/gpio.txt
>  create mode 100644 doc/device-tree-bindings/gpio/nvidia,tegra20-gpio.txt
>
> --
> 2.2.0.rc0.207.ga3a616c
>

Regards,
Simon

^ permalink raw reply	[flat|nested] 49+ messages in thread

* [U-Boot] [PATCH 01/21] dm: gpio: Bring in GPIO device tree binding
  2015-01-06  3:05 ` [U-Boot] [PATCH 01/21] dm: gpio: Bring in GPIO device tree binding Simon Glass
@ 2015-01-15  4:38   ` Simon Glass
  0 siblings, 0 replies; 49+ messages in thread
From: Simon Glass @ 2015-01-15  4:38 UTC (permalink / raw)
  To: u-boot

On 5 January 2015 at 20:05, Simon Glass <sjg@chromium.org> wrote:
> Add the binding file that we are about to support.
>
> Signed-off-by: Simon Glass <sjg@chromium.org>
> ---
>
>  doc/device-tree-bindings/gpio/gpio.txt | 211 +++++++++++++++++++++++++++++++++
>  1 file changed, 211 insertions(+)
>  create mode 100644 doc/device-tree-bindings/gpio/gpio.txt

Applied to u-boot-dm.

^ permalink raw reply	[flat|nested] 49+ messages in thread

* [U-Boot] [PATCH 02/21] dm: exynos: Bring in GPIO device tree binding
  2015-01-06  3:05 ` [U-Boot] [PATCH 02/21] dm: exynos: " Simon Glass
@ 2015-01-15  4:38   ` Simon Glass
  0 siblings, 0 replies; 49+ messages in thread
From: Simon Glass @ 2015-01-15  4:38 UTC (permalink / raw)
  To: u-boot

On 5 January 2015 at 20:05, Simon Glass <sjg@chromium.org> wrote:
> At present the exynos GPIO driver does not fully support the existing device
> tree binding, but add the binding file to cover the existing partial support.
>
> Signed-off-by: Simon Glass <sjg@chromium.org>
> ---
>
>  doc/device-tree-bindings/gpio/gpio-samsung.txt | 41 ++++++++++++++++++++++++++
>  1 file changed, 41 insertions(+)
>  create mode 100644 doc/device-tree-bindings/gpio/gpio-samsung.txt

Applied to u-boot-dm.

^ permalink raw reply	[flat|nested] 49+ messages in thread

* [U-Boot] [PATCH 03/21] dm: tegra: Bring in GPIO device tree binding
  2015-01-06  3:05 ` [U-Boot] [PATCH 03/21] dm: tegra: " Simon Glass
@ 2015-01-15  4:39   ` Simon Glass
  0 siblings, 0 replies; 49+ messages in thread
From: Simon Glass @ 2015-01-15  4:39 UTC (permalink / raw)
  To: u-boot

On 5 January 2015 at 20:05, Simon Glass <sjg@chromium.org> wrote:
> At present the tegra GPIO driver does not fully support the existing device
> tree binding, but add the binding file to cover the existing partial support.
>
> Signed-off-by: Simon Glass <sjg@chromium.org>
> ---
>
>  .../gpio/nvidia,tegra20-gpio.txt                   | 40 ++++++++++++++++++++++
>  1 file changed, 40 insertions(+)
>  create mode 100644 doc/device-tree-bindings/gpio/nvidia,tegra20-gpio.txt
>

Applied to u-boot-dm.

^ permalink raw reply	[flat|nested] 49+ messages in thread

* [U-Boot] [PATCH 04/21] dm: fdt: Add a function to decode phandles with arguments
  2015-01-06  3:05 ` [U-Boot] [PATCH 04/21] dm: fdt: Add a function to decode phandles with arguments Simon Glass
@ 2015-01-15  4:39   ` Simon Glass
  2015-01-15  7:29   ` Masahiro Yamada
  1 sibling, 0 replies; 49+ messages in thread
From: Simon Glass @ 2015-01-15  4:39 UTC (permalink / raw)
  To: u-boot

On 5 January 2015 at 20:05, Simon Glass <sjg@chromium.org> wrote:
> For GPIOs and other functions we want to look up a phandle and then decode
> a list of arguments for that phandle. Each phandle can have a different
> number of arguments, specified by a property in the target node. This is
> the "#gpio-cells" property for GPIOs.
>
> Add a function to provide this feature, taken modified from Linux 3.18.
>
> Signed-off-by: Simon Glass <sjg@chromium.org>
> ---
>
>  include/fdtdec.h |  53 ++++++++++++++++++++++++
>  lib/fdtdec.c     | 124 +++++++++++++++++++++++++++++++++++++++++++++++++++++++
>  2 files changed, 177 insertions(+)

Applied to u-boot-dm.

^ permalink raw reply	[flat|nested] 49+ messages in thread

* [U-Boot] [PATCH 05/21] dm: gpio: Add a native driver model API
  2015-01-06  3:05 ` [U-Boot] [PATCH 05/21] dm: gpio: Add a native driver model API Simon Glass
@ 2015-01-15  4:39   ` Simon Glass
  0 siblings, 0 replies; 49+ messages in thread
From: Simon Glass @ 2015-01-15  4:39 UTC (permalink / raw)
  To: u-boot

On 5 January 2015 at 20:05, Simon Glass <sjg@chromium.org> wrote:
> So far driver model's GPIO uclass just implements the existing GPIO API.
> This has some limitations:
>
> - it requires manual device tree munging to support GPIOs in device tree
>     (fdtdec_get_gpio() and friends)
> - it does not understand polarity
> - it is somewhat slower since we must scan for the GPIO device each time
> - Global GPIO numbering can change if other GPIO drivers are probed
> - it requires extra steps to set the GPIO direction and value
>
> The new functions have a dm_ prefix where necessary to avoid name conflicts
> but we can remove that when it is no-longer needed. The new struct gpio_desc
> holds all required information about the GPIO. For now this is intended to
> be stored by the client requesting the GPIO, but in future it might be
> brought into the uclass in some way.
>
> With these changes the old GPIO API still works, and uses the driver model
> API underneath.
>
> Signed-off-by: Simon Glass <sjg@chromium.org>
> ---
>
>  drivers/gpio/gpio-uclass.c | 218 ++++++++++++++++++++++++++++++---------------
>  include/asm-generic/gpio.h |  16 ++++
>  2 files changed, 163 insertions(+), 71 deletions(-)

Applied to u-boot-dm.

^ permalink raw reply	[flat|nested] 49+ messages in thread

* [U-Boot] [PATCH 06/21] dm: gpio: Add a driver GPIO translation method
  2015-01-06  3:05 ` [U-Boot] [PATCH 06/21] dm: gpio: Add a driver GPIO translation method Simon Glass
@ 2015-01-15  4:39   ` Simon Glass
  0 siblings, 0 replies; 49+ messages in thread
From: Simon Glass @ 2015-01-15  4:39 UTC (permalink / raw)
  To: u-boot

On 5 January 2015 at 20:05, Simon Glass <sjg@chromium.org> wrote:
> Only the GPIO driver knows about the full GPIO device tree binding used by
> a device. Add a method to allow the driver to provide this information to the
> uclass, including the GPIO offset within the device and flags such as the
> polarity.
>
> Signed-off-by: Simon Glass <sjg@chromium.org>
> ---
>
>  drivers/gpio/gpio-uclass.c | 16 ++++++++++++++++
>  include/asm-generic/gpio.h | 29 +++++++++++++++++++++++++++++
>  2 files changed, 45 insertions(+)

Applied to u-boot-dm.

^ permalink raw reply	[flat|nested] 49+ messages in thread

* [U-Boot] [PATCH 07/21] dm: gpio: Add better functions to request GPIOs
  2015-01-06  3:05 ` [U-Boot] [PATCH 07/21] dm: gpio: Add better functions to request GPIOs Simon Glass
@ 2015-01-15  4:39   ` Simon Glass
  0 siblings, 0 replies; 49+ messages in thread
From: Simon Glass @ 2015-01-15  4:39 UTC (permalink / raw)
  To: u-boot

On 5 January 2015 at 20:05, Simon Glass <sjg@chromium.org> wrote:
> At present U-Boot sort-of supports the standard way of reading GPIOs from
> device tree nodes, but the support is incomplete, a bit clunky and only
> works for GPIO bindings where #gpio-cells is 2.
>
> Add new functions to request GPIOs, taking full account of the device
> tree binding. These permit requesting a GPIO with a simple call like:
>
>    gpio_request_by_name(dev, "cd-gpios", 0, &desc, GPIOD_IS_IN);
>
> This will request the GPIO, looking at the device's node which might be
> this, for example:
>
>    cd-gpios = <&gpio TEGRA_GPIO(B, 3) GPIO_ACTIVE_LOW>;
>
> The GPIO will be set to input mode in this case and polarity will be
> honoured by the GPIO calls.
>
> It is also possible to request and free a list of GPIOs.
>
> Signed-off-by: Simon Glass <sjg@chromium.org>
> ---
>
>  drivers/gpio/gpio-uclass.c | 166 ++++++++++++++++++++++++++++++++++++-
>  drivers/gpio/sandbox.c     |  20 +++++
>  include/asm-generic/gpio.h | 199 +++++++++++++++++++++++++++++++++++++++++++++
>  test/dm/gpio.c             |  69 +++++++++++++++-
>  test/dm/test.dts           |  11 ++-
>  5 files changed, 461 insertions(+), 4 deletions(-)

Applied to u-boot-dm.

^ permalink raw reply	[flat|nested] 49+ messages in thread

* [U-Boot] [PATCH 08/21] dm: gpio: Mark the old GPIO API deprecated
  2015-01-06  3:05 ` [U-Boot] [PATCH 08/21] dm: gpio: Mark the old GPIO API deprecated Simon Glass
@ 2015-01-15  4:39   ` Simon Glass
  0 siblings, 0 replies; 49+ messages in thread
From: Simon Glass @ 2015-01-15  4:39 UTC (permalink / raw)
  To: u-boot

On 5 January 2015 at 20:05, Simon Glass <sjg@chromium.org> wrote:
> Add a deprecation notice to each function so that it is more obvious that we
> are moving GPIOs to driver model.
>
> Signed-off-by: Simon Glass <sjg@chromium.org>
> ---
>
>  include/asm-generic/gpio.h | 21 +++++++++++++++++++++
>  1 file changed, 21 insertions(+)

Applied to u-boot-dm.

^ permalink raw reply	[flat|nested] 49+ messages in thread

* [U-Boot] [PATCH 09/21] dm: demo: Add a simple GPIO demonstration
  2015-01-06  3:05 ` [U-Boot] [PATCH 09/21] dm: demo: Add a simple GPIO demonstration Simon Glass
@ 2015-01-15  4:40   ` Simon Glass
  0 siblings, 0 replies; 49+ messages in thread
From: Simon Glass @ 2015-01-15  4:40 UTC (permalink / raw)
  To: u-boot

On 5 January 2015 at 20:05, Simon Glass <sjg@chromium.org> wrote:
> Add a new 'demo light' command which uses GPIOs to control imaginary lights.
> Each light is assigned a bit number in the overall value. This provides an
> example driver for using the new GPIO API.
>
> Signed-off-by: Simon Glass <sjg@chromium.org>
> ---
>
>  arch/sandbox/dts/sandbox.dts | 11 ++++++-
>  common/cmd_demo.c            | 29 +++++++++++++++++-
>  drivers/demo/demo-shape.c    | 71 ++++++++++++++++++++++++++++++++++++++++++++
>  drivers/demo/demo-uclass.c   | 20 +++++++++++++
>  include/dm-demo.h            |  4 +++
>  5 files changed, 133 insertions(+), 2 deletions(-)

Applied to u-boot-dm.

^ permalink raw reply	[flat|nested] 49+ messages in thread

* [U-Boot] [PATCH 10/21] dm: cros_ec: Remove use of fdtdec GPIO support
  2015-01-06  3:05 ` [U-Boot] [PATCH 10/21] dm: cros_ec: Remove use of fdtdec GPIO support Simon Glass
@ 2015-01-15  4:40   ` Simon Glass
  0 siblings, 0 replies; 49+ messages in thread
From: Simon Glass @ 2015-01-15  4:40 UTC (permalink / raw)
  To: u-boot

On 5 January 2015 at 20:05, Simon Glass <sjg@chromium.org> wrote:
> These functions are going away, so use the new uclass support instead.
>
> Signed-off-by: Simon Glass <sjg@chromium.org>
> ---
>
>  drivers/misc/cros_ec.c | 24 ++++++------------------
>  include/cros_ec.h      |  3 ++-
>  2 files changed, 8 insertions(+), 19 deletions(-)

Applied to u-boot-dm.

^ permalink raw reply	[flat|nested] 49+ messages in thread

* [U-Boot] [PATCH 11/21] dm: tegra: Add a GPIO translation function
  2015-01-06  3:05 ` [U-Boot] [PATCH 11/21] dm: tegra: Add a GPIO translation function Simon Glass
@ 2015-01-15  4:40   ` Simon Glass
  0 siblings, 0 replies; 49+ messages in thread
From: Simon Glass @ 2015-01-15  4:40 UTC (permalink / raw)
  To: u-boot

On 5 January 2015 at 20:05, Simon Glass <sjg@chromium.org> wrote:
> This deals with the polarity bit and selecting the correct bank device
> given a GPIO number.
>
> Signed-off-by: Simon Glass <sjg@chromium.org>
> ---
>
>  drivers/gpio/tegra_gpio.c | 18 ++++++++++++++++++
>  1 file changed, 18 insertions(+)

Applied to u-boot-dm.

^ permalink raw reply	[flat|nested] 49+ messages in thread

* [U-Boot] [PATCH 12/21] dm: exynos: Add a GPIO translation function
  2015-01-06  3:05 ` [U-Boot] [PATCH 12/21] dm: exynos: " Simon Glass
@ 2015-01-15  4:40   ` Simon Glass
  0 siblings, 0 replies; 49+ messages in thread
From: Simon Glass @ 2015-01-15  4:40 UTC (permalink / raw)
  To: u-boot

On 5 January 2015 at 20:05, Simon Glass <sjg@chromium.org> wrote:
> This deals with the polarity bit. It also changes the GPIO devices so that
> the correct device tree node is linked to each one. This allows us to use
> the new uclass phandle functionality to implement a proper GPIO binding.
>
> Signed-off-by: Simon Glass <sjg@chromium.org>
> ---
>
>  drivers/gpio/s5p_gpio.c | 13 ++++++++++++-
>  1 file changed, 12 insertions(+), 1 deletion(-)

Applied to u-boot-dm.

^ permalink raw reply	[flat|nested] 49+ messages in thread

* [U-Boot] [PATCH 13/21] dm: tegra: video: Remove use of fdtdec GPIO support
  2015-01-06  3:05 ` [U-Boot] [PATCH 13/21] dm: tegra: video: Remove use of fdtdec GPIO support Simon Glass
@ 2015-01-15  4:40   ` Simon Glass
  0 siblings, 0 replies; 49+ messages in thread
From: Simon Glass @ 2015-01-15  4:40 UTC (permalink / raw)
  To: u-boot

On 5 January 2015 at 20:05, Simon Glass <sjg@chromium.org> wrote:
> These functions are going away, so use the new uclass support instead.
>
> Signed-off-by: Simon Glass <sjg@chromium.org>
> ---
>
>  arch/arm/include/asm/arch-tegra20/display.h |  9 ++---
>  drivers/video/tegra.c                       | 54 +++++++++++------------------
>  2 files changed, 25 insertions(+), 38 deletions(-)

Applied to u-boot-dm.

^ permalink raw reply	[flat|nested] 49+ messages in thread

* [U-Boot] [PATCH 14/21] dm: tegra: nand: Remove use of fdtdec GPIO support
  2015-01-06  3:05 ` [U-Boot] [PATCH 14/21] dm: tegra: nand: " Simon Glass
@ 2015-01-15  4:40   ` Simon Glass
  0 siblings, 0 replies; 49+ messages in thread
From: Simon Glass @ 2015-01-15  4:40 UTC (permalink / raw)
  To: u-boot

On 5 January 2015 at 20:05, Simon Glass <sjg@chromium.org> wrote:
> These functions are going away, so use the new uclass support instead.
>
> Signed-off-by: Simon Glass <sjg@chromium.org>
> ---
>
>  drivers/mtd/nand/tegra_nand.c | 9 ++++-----
>  1 file changed, 4 insertions(+), 5 deletions(-)

Applied to u-boot-dm.

^ permalink raw reply	[flat|nested] 49+ messages in thread

* [U-Boot] [PATCH 15/21] dm: zynq: Remove inline gpio functions
  2015-01-06  3:05 ` [U-Boot] [PATCH 15/21] dm: zynq: Remove inline gpio functions Simon Glass
@ 2015-01-15  4:40   ` Simon Glass
  0 siblings, 0 replies; 49+ messages in thread
From: Simon Glass @ 2015-01-15  4:40 UTC (permalink / raw)
  To: u-boot

On 5 January 2015 at 20:05, Simon Glass <sjg@chromium.org> wrote:
> These functions serve no useful purpose, and conflict with the generic API.
> Drop them.
>
> Signed-off-by: Simon Glass <sjg@chromium.org>
> ---
>
>  arch/arm/include/asm/arch-zynq/gpio.h | 15 ---------------
>  1 file changed, 15 deletions(-)

Applied to u-boot-dm.

^ permalink raw reply	[flat|nested] 49+ messages in thread

* [U-Boot] [PATCH 16/21] dm: mmc: Remove use of fdtdec GPIO support
  2015-01-06  3:05 ` [U-Boot] [PATCH 16/21] dm: mmc: Remove use of fdtdec GPIO support Simon Glass
@ 2015-01-15  4:40   ` Simon Glass
  0 siblings, 0 replies; 49+ messages in thread
From: Simon Glass @ 2015-01-15  4:40 UTC (permalink / raw)
  To: u-boot

On 5 January 2015 at 20:05, Simon Glass <sjg@chromium.org> wrote:
> These functions are going away, so use the new uclass support instead.
>
> Signed-off-by: Simon Glass <sjg@chromium.org>
> ---
>
>  arch/arm/include/asm/arch-pantheon/gpio.h   |  0
>  arch/arm/include/asm/arch-tegra/tegra_mmc.h |  7 +++---
>  drivers/mmc/s5p_sdhci.c                     | 20 +++++++---------
>  drivers/mmc/tegra_mmc.c                     | 36 +++++++++++------------------
>  include/sdhci.h                             |  6 ++---
>  5 files changed, 28 insertions(+), 41 deletions(-)
>  create mode 100644 arch/arm/include/asm/arch-pantheon/gpio.h

Applied to u-boot-dm.

^ permalink raw reply	[flat|nested] 49+ messages in thread

* [U-Boot] [PATCH 17/21] dm: usb: Remove use of fdtdec GPIO support
  2015-01-06  3:05 ` [U-Boot] [PATCH 17/21] dm: usb: " Simon Glass
@ 2015-01-15  4:40   ` Simon Glass
  0 siblings, 0 replies; 49+ messages in thread
From: Simon Glass @ 2015-01-15  4:40 UTC (permalink / raw)
  To: u-boot

On 5 January 2015 at 20:05, Simon Glass <sjg@chromium.org> wrote:
> These functions are going away, so use the new uclass support instead.
>
> Signed-off-by: Simon Glass <sjg@chromium.org>
> ---
>
>  drivers/usb/host/ehci-exynos.c  | 10 +++++-----
>  drivers/usb/host/ehci-tegra.c   | 38 ++++++++++++++++++--------------------
>  drivers/usb/host/xhci-exynos5.c | 10 +++++-----
>  3 files changed, 28 insertions(+), 30 deletions(-)

Applied to u-boot-dm.

^ permalink raw reply	[flat|nested] 49+ messages in thread

* [U-Boot] [PATCH 18/21] dm: spi: Remove use of fdtdec GPIO support
  2015-01-06  3:05 ` [U-Boot] [PATCH 18/21] dm: spi: " Simon Glass
@ 2015-01-15  4:40   ` Simon Glass
  0 siblings, 0 replies; 49+ messages in thread
From: Simon Glass @ 2015-01-15  4:40 UTC (permalink / raw)
  To: u-boot

On 5 January 2015 at 20:05, Simon Glass <sjg@chromium.org> wrote:
> These functions are going away, so use the new uclass support instead.
>
> Signed-off-by: Simon Glass <sjg@chromium.org>
> ---
>
>  drivers/spi/soft_spi.c | 62 +++++++++++++++++++++++---------------------------
>  1 file changed, 28 insertions(+), 34 deletions(-)
>

Applied to u-boot-dm.

^ permalink raw reply	[flat|nested] 49+ messages in thread

* [U-Boot] [PATCH 19/21] dm: tegra: dts: Use TEGRA_GPIO() macro for all GPIOs
  2015-01-06  3:05 ` [U-Boot] [PATCH 19/21] dm: tegra: dts: Use TEGRA_GPIO() macro for all GPIOs Simon Glass
@ 2015-01-15  4:40   ` Simon Glass
  0 siblings, 0 replies; 49+ messages in thread
From: Simon Glass @ 2015-01-15  4:40 UTC (permalink / raw)
  To: u-boot

On 5 January 2015 at 20:05, Simon Glass <sjg@chromium.org> wrote:
> This new method is much easier and matches the kernel.
>
> Signed-off-by: Simon Glass <sjg@chromium.org>
> ---
>
>  arch/arm/dts/tegra114-dalmore.dts         |  5 ++---
>  arch/arm/dts/tegra124-jetson-tk1.dts      |  9 +++++----
>  arch/arm/dts/tegra124-venice2.dts         |  9 +++++----
>  arch/arm/dts/tegra20-colibri_t20_iris.dts | 10 +++++-----
>  arch/arm/dts/tegra20-harmony.dts          | 28 ++++++++++++++++------------
>  arch/arm/dts/tegra20-medcom-wide.dts      |  9 ++++++---
>  arch/arm/dts/tegra20-paz00.dts            | 18 +++++++++++-------
>  arch/arm/dts/tegra20-seaboard.dts         | 22 +++++++++++++---------
>  arch/arm/dts/tegra20-tamonten.dtsi        |  9 +++++----
>  arch/arm/dts/tegra20-tec.dts              |  9 ++++++---
>  arch/arm/dts/tegra20-trimslice.dts        |  8 ++++----
>  arch/arm/dts/tegra20-ventana.dts          | 18 +++++++++++-------
>  arch/arm/dts/tegra20-whistler.dts         |  2 +-
>  arch/arm/dts/tegra30-apalis.dts           | 10 +++++-----
>  arch/arm/dts/tegra30-beaver.dts           | 10 +++++-----
>  arch/arm/dts/tegra30-cardhu.dts           |  8 ++++----
>  arch/arm/dts/tegra30-colibri.dts          |  6 +++---
>  arch/arm/dts/tegra30-tamonten.dtsi        |  4 ++--
>  18 files changed, 109 insertions(+), 85 deletions(-)

Applied to u-boot-dm.

^ permalink raw reply	[flat|nested] 49+ messages in thread

* [U-Boot] [PATCH 20/21] dm: exynos: dts: Use GPIO bank phandles for GPIOs
  2015-01-07  2:44   ` Minkyu Kang
@ 2015-01-15  4:40     ` Simon Glass
  0 siblings, 0 replies; 49+ messages in thread
From: Simon Glass @ 2015-01-15  4:40 UTC (permalink / raw)
  To: u-boot

On 6 January 2015 at 19:44, Minkyu Kang <mk7.kang@samsung.com> wrote:
> On 06/01/15 12:05, Simon Glass wrote:
>> U-Boot now supports using GPIOs using bank phandles instead of global
>> numbers. Update the exynos device tree files to use this.
>>
>> Signed-off-by: Simon Glass <sjg@chromium.org>
>> ---
>>
>>  arch/arm/dts/exynos4.dtsi                  |  7 -------
>>  arch/arm/dts/exynos4210-origen.dts         |  2 +-
>>  arch/arm/dts/exynos4210-trats.dts          |  4 ++--
>>  arch/arm/dts/exynos4210-universal_c210.dts | 12 ++++++------
>>  arch/arm/dts/exynos4412-odroid.dts         |  2 +-
>>  arch/arm/dts/exynos4412-trats2.dts         |  6 +++---
>>  arch/arm/dts/exynos5.dtsi                  |  4 +---
>>  arch/arm/dts/exynos5250-smdk5250.dts       |  2 +-
>>  arch/arm/dts/exynos5250-snow.dts           | 10 +++++-----
>>  arch/arm/dts/exynos5420-peach-pit.dts      |  8 ++++----
>>  arch/arm/dts/exynos5422-odroidxu3.dts      |  2 +-
>>  arch/arm/dts/exynos5800-peach-pi.dts       | 10 +++++-----
>>  12 files changed, 30 insertions(+), 39 deletions(-)
>>
>
> Acked-by: Minkyu Kang <mk7.kang@samsung.com>

Applied to u-boot-dm.

^ permalink raw reply	[flat|nested] 49+ messages in thread

* [U-Boot] [PATCH 21/21] dm: fdt: Remove the old GPIO functions
  2015-01-06  3:05 ` [U-Boot] [PATCH 21/21] dm: fdt: Remove the old GPIO functions Simon Glass
@ 2015-01-15  4:40   ` Simon Glass
  2015-01-15  7:28   ` Masahiro Yamada
  1 sibling, 0 replies; 49+ messages in thread
From: Simon Glass @ 2015-01-15  4:40 UTC (permalink / raw)
  To: u-boot

On 5 January 2015 at 20:05, Simon Glass <sjg@chromium.org> wrote:
> Now that we support device tree GPIO bindings directly in the driver model
> GPIO uclass we can remove these functions.
>
> Signed-off-by: Simon Glass <sjg@chromium.org>
> ---
>
>  include/fdtdec.h | 77 ---------------------------------------------
>  lib/fdtdec.c     | 95 --------------------------------------------------------
>  2 files changed, 172 deletions(-)

Applied to u-boot-dm.

^ permalink raw reply	[flat|nested] 49+ messages in thread

* [U-Boot] [PATCH 21/21] dm: fdt: Remove the old GPIO functions
  2015-01-06  3:05 ` [U-Boot] [PATCH 21/21] dm: fdt: Remove the old GPIO functions Simon Glass
  2015-01-15  4:40   ` Simon Glass
@ 2015-01-15  7:28   ` Masahiro Yamada
  2015-01-15 14:56     ` Simon Glass
  1 sibling, 1 reply; 49+ messages in thread
From: Masahiro Yamada @ 2015-01-15  7:28 UTC (permalink / raw)
  To: u-boot

Hi Simon,


You have already applied this patch.

It might be too late, but...



You can remove  "#include <asm/gpio.h>"
from lib/fdtdec.c.



This is important for me to delete 
my dummy file arch/arm/include/asm/arch-uniphier/gpio.h





Best Regards
Masahiro Yamada






On Mon,  5 Jan 2015 20:05:43 -0700
Simon Glass <sjg@chromium.org> wrote:

> Now that we support device tree GPIO bindings directly in the driver model
> GPIO uclass we can remove these functions.
> 
> Signed-off-by: Simon Glass <sjg@chromium.org>
> ---
> 
>  include/fdtdec.h | 77 ---------------------------------------------
>  lib/fdtdec.c     | 95 --------------------------------------------------------
>  2 files changed, 172 deletions(-)
> 
> diff --git a/include/fdtdec.h b/include/fdtdec.h
> index 629e072..54b716e 100644
> --- a/include/fdtdec.h
> +++ b/include/fdtdec.h
> @@ -186,39 +186,6 @@ int fdtdec_parse_phandle_with_args(const void *blob, int src_node,
>  				   int cell_count, int index,
>  				   struct fdtdec_phandle_args *out_args);
>  
> -/* GPIOs are numbered from 0 */
> -enum {
> -	FDT_GPIO_NONE = -1U,	/* an invalid GPIO used to end our list */
> -
> -	FDT_GPIO_ACTIVE_LOW = 1 << 0,	/* input is active low (else high) */
> -};
> -
> -/* This is the state of a GPIO pin as defined by the fdt */
> -struct fdt_gpio_state {
> -	const char *name;	/* name of the fdt property defining this */
> -	uint gpio;		/* GPIO number, or FDT_GPIO_NONE if none */
> -	u8 flags;		/* FDT_GPIO_... flags */
> -};
> -
> -/* This tells us whether a fdt_gpio_state record is valid or not */
> -#define fdt_gpio_isvalid(x) ((x)->gpio != FDT_GPIO_NONE)
> -
> -/**
> - * Read the GPIO taking into account the polarity of the pin.
> - *
> - * @param gpio		pointer to the decoded gpio
> - * @return value of the gpio if successful, < 0 if unsuccessful
> - */
> -int fdtdec_get_gpio(struct fdt_gpio_state *gpio);
> -
> -/**
> - * Write the GPIO taking into account the polarity of the pin.
> - *
> - * @param gpio		pointer to the decoded gpio
> - * @return 0 if successful
> - */
> -int fdtdec_set_gpio(struct fdt_gpio_state *gpio, int val);
> -
>  /**
>   * Find the next numbered alias for a peripheral. This is used to enumerate
>   * all the peripherals of a certain type.
> @@ -546,50 +513,6 @@ const u32 *fdtdec_locate_array(const void *blob, int node,
>  int fdtdec_get_bool(const void *blob, int node, const char *prop_name);
>  
>  /**
> - * Decode a single GPIOs from an FDT.
> - *
> - * If the property is not found, then the GPIO structure will still be
> - * initialised, with gpio set to FDT_GPIO_NONE. This makes it easy to
> - * provide optional GPIOs.
> - *
> - * @param blob		FDT blob to use
> - * @param node		Node to look at
> - * @param prop_name	Node property name
> - * @param gpio		gpio elements to fill from FDT
> - * @return 0 if ok, -FDT_ERR_NOTFOUND if the property is missing.
> - */
> -int fdtdec_decode_gpio(const void *blob, int node, const char *prop_name,
> -		struct fdt_gpio_state *gpio);
> -
> -/**
> - * Decode a list of GPIOs from an FDT. This creates a list of GPIOs with no
> - * terminating item.
> - *
> - * @param blob         FDT blob to use
> - * @param node         Node to look at
> - * @param prop_name    Node property name
> - * @param gpio         Array of gpio elements to fill from FDT. This will be
> - *                     untouched if either 0 or an error is returned
> - * @param max_count    Maximum number of elements allowed
> - * @return number of GPIOs read if ok, -FDT_ERR_BADLAYOUT if max_count would
> - * be exceeded, or -FDT_ERR_NOTFOUND if the property is missing.
> - */
> -int fdtdec_decode_gpios(const void *blob, int node, const char *prop_name,
> -		struct fdt_gpio_state *gpio, int max_count);
> -
> -/**
> - * Set up a GPIO pin according to the provided gpio information. At present this
> - * just requests the GPIO.
> - *
> - * If the gpio is FDT_GPIO_NONE, no action is taken. This makes it easy to
> - * deal with optional GPIOs.
> - *
> - * @param gpio		GPIO info to use for set up
> - * @return 0 if all ok or gpio was FDT_GPIO_NONE; -1 on error
> - */
> -int fdtdec_setup_gpio(struct fdt_gpio_state *gpio);
> -
> -/**
>   * Look in the FDT for a config item with the given name and return its value
>   * as a 32-bit integer. The property must have at least 4 bytes of data. The
>   * value of the first cell is returned.
> diff --git a/lib/fdtdec.c b/lib/fdtdec.c
> index d6bc783..71adc06 100644
> --- a/lib/fdtdec.c
> +++ b/lib/fdtdec.c
> @@ -645,101 +645,6 @@ int fdtdec_parse_phandle_with_args(const void *blob, int src_node,
>  	return rc;
>  }
>  
> -/**
> - * Decode a list of GPIOs from an FDT. This creates a list of GPIOs with no
> - * terminating item.
> - *
> - * @param blob		FDT blob to use
> - * @param node		Node to look at
> - * @param prop_name	Node property name
> - * @param gpio		Array of gpio elements to fill from FDT. This will be
> - *			untouched if either 0 or an error is returned
> - * @param max_count	Maximum number of elements allowed
> - * @return number of GPIOs read if ok, -FDT_ERR_BADLAYOUT if max_count would
> - * be exceeded, or -FDT_ERR_NOTFOUND if the property is missing.
> - */
> -int fdtdec_decode_gpios(const void *blob, int node, const char *prop_name,
> -		struct fdt_gpio_state *gpio, int max_count)
> -{
> -	const struct fdt_property *prop;
> -	const u32 *cell;
> -	const char *name;
> -	int len, i;
> -
> -	debug("%s: %s\n", __func__, prop_name);
> -	assert(max_count > 0);
> -	prop = fdt_get_property(blob, node, prop_name, &len);
> -	if (!prop) {
> -		debug("%s: property '%s' missing\n", __func__, prop_name);
> -		return -FDT_ERR_NOTFOUND;
> -	}
> -
> -	/* We will use the name to tag the GPIO */
> -	name = fdt_string(blob, fdt32_to_cpu(prop->nameoff));
> -	cell = (u32 *)prop->data;
> -	len /= sizeof(u32) * 3;		/* 3 cells per GPIO record */
> -	if (len > max_count) {
> -		debug(" %s: too many GPIOs / cells for "
> -			"property '%s'\n", __func__, prop_name);
> -		return -FDT_ERR_BADLAYOUT;
> -	}
> -
> -	/* Read out the GPIO data from the cells */
> -	for (i = 0; i < len; i++, cell += 3) {
> -		gpio[i].gpio = fdt32_to_cpu(cell[1]);
> -		gpio[i].flags = fdt32_to_cpu(cell[2]);
> -		gpio[i].name = name;
> -	}
> -
> -	return len;
> -}
> -
> -int fdtdec_decode_gpio(const void *blob, int node, const char *prop_name,
> -		struct fdt_gpio_state *gpio)
> -{
> -	int err;
> -
> -	debug("%s: %s\n", __func__, prop_name);
> -	gpio->gpio = FDT_GPIO_NONE;
> -	gpio->name = NULL;
> -	err = fdtdec_decode_gpios(blob, node, prop_name, gpio, 1);
> -	return err == 1 ? 0 : err;
> -}
> -
> -int fdtdec_get_gpio(struct fdt_gpio_state *gpio)
> -{
> -	int val;
> -
> -	if (!fdt_gpio_isvalid(gpio))
> -		return -1;
> -
> -	val = gpio_get_value(gpio->gpio);
> -	return gpio->flags & FDT_GPIO_ACTIVE_LOW ? val ^ 1 : val;
> -}
> -
> -int fdtdec_set_gpio(struct fdt_gpio_state *gpio, int val)
> -{
> -	if (!fdt_gpio_isvalid(gpio))
> -		return -1;
> -
> -	val = gpio->flags & FDT_GPIO_ACTIVE_LOW ? val ^ 1 : val;
> -	return gpio_set_value(gpio->gpio, val);
> -}
> -
> -int fdtdec_setup_gpio(struct fdt_gpio_state *gpio)
> -{
> -	/*
> -	 * Return success if there is no GPIO defined. This is used for
> -	 * optional GPIOs)
> -	 */
> -	if (!fdt_gpio_isvalid(gpio))
> -		return 0;
> -
> -	if (gpio_request(gpio->gpio, gpio->name))
> -		return -1;
> -	return 0;
> -}
> -
>  int fdtdec_get_byte_array(const void *blob, int node, const char *prop_name,
>  		u8 *array, int count)
>  {
> -- 
> 2.2.0.rc0.207.ga3a616c

^ permalink raw reply	[flat|nested] 49+ messages in thread

* [U-Boot] [PATCH 04/21] dm: fdt: Add a function to decode phandles with arguments
  2015-01-06  3:05 ` [U-Boot] [PATCH 04/21] dm: fdt: Add a function to decode phandles with arguments Simon Glass
  2015-01-15  4:39   ` Simon Glass
@ 2015-01-15  7:29   ` Masahiro Yamada
  2015-01-15 14:55     ` Simon Glass
  1 sibling, 1 reply; 49+ messages in thread
From: Masahiro Yamada @ 2015-01-15  7:29 UTC (permalink / raw)
  To: u-boot

Hi Simon,


A nit


On Mon,  5 Jan 2015 20:05:26 -0700
Simon Glass <sjg@chromium.org> wrote:

> For GPIOs and other functions we want to look up a phandle and then decode
> a list of arguments for that phandle. Each phandle can have a different
> number of arguments, specified by a property in the target node. This is
> the "#gpio-cells" property for GPIOs.
> 
> Add a function to provide this feature, taken modified from Linux 3.18.
> 
> Signed-off-by: Simon Glass <sjg@chromium.org>
> ---
> 
>  include/fdtdec.h |  53 ++++++++++++++++++++++++
>  lib/fdtdec.c     | 124 +++++++++++++++++++++++++++++++++++++++++++++++++++++++
>  2 files changed, 177 insertions(+)
> 
> diff --git a/include/fdtdec.h b/include/fdtdec.h
> index 5effa24..629e072 100644
> --- a/include/fdtdec.h
> +++ b/include/fdtdec.h
> @@ -133,6 +133,59 @@ enum fdt_compat_id {
>  	COMPAT_COUNT,
>  };
>  
> +#define MAX_PHANDLE_ARGS 16
> +struct fdtdec_phandle_args {
> +	int node;
> +	int args_count;
> +	uint32_t args[MAX_PHANDLE_ARGS];
> +};
> +
> +/**
> + * fdtdec_parse_phandle_with_args() - Find a node pointed by phandle in a list
> + *
> + * This function is useful to parse lists of phandles and their arguments.
> + *
> + * Example:
> + *
> + * phandle1: node1 {
> + *	#list-cells = <2>;
> + * }
> + *
> + * phandle2: node2 {
> + *	#list-cells = <1>;
> + * }
> + *
> + * node3 {
> + *	list = <&phandle1 1 2 &phandle2 3>;
> + * }
> + *
> + * To get a device_node of the `node2' node you may call this:
> + * fdtdec_parse_phandle_with_args(blob, node3, "list", "#list-cells", 0, 1,
> + *				  &args);
> + *
> + * (This function is a modified version of of_parse_phandle_with_args() from
> + * Linux 3.18)

I think this is a modified version of __of_parse_phandle_with_args()


Best Regards
Masahiro Yamada

^ permalink raw reply	[flat|nested] 49+ messages in thread

* [U-Boot] [PATCH 04/21] dm: fdt: Add a function to decode phandles with arguments
  2015-01-15  7:29   ` Masahiro Yamada
@ 2015-01-15 14:55     ` Simon Glass
  0 siblings, 0 replies; 49+ messages in thread
From: Simon Glass @ 2015-01-15 14:55 UTC (permalink / raw)
  To: u-boot

Hi Masahiro,

On 15 January 2015 at 00:29, Masahiro Yamada <yamada.m@jp.panasonic.com> wrote:
> Hi Simon,
>
>
> A nit
>
>
> On Mon,  5 Jan 2015 20:05:26 -0700
> Simon Glass <sjg@chromium.org> wrote:
>
>> For GPIOs and other functions we want to look up a phandle and then decode
>> a list of arguments for that phandle. Each phandle can have a different
>> number of arguments, specified by a property in the target node. This is
>> the "#gpio-cells" property for GPIOs.
>>
>> Add a function to provide this feature, taken modified from Linux 3.18.
>>
>> Signed-off-by: Simon Glass <sjg@chromium.org>
>> ---
>>
>>  include/fdtdec.h |  53 ++++++++++++++++++++++++
>>  lib/fdtdec.c     | 124 +++++++++++++++++++++++++++++++++++++++++++++++++++++++
>>  2 files changed, 177 insertions(+)
>>
>> diff --git a/include/fdtdec.h b/include/fdtdec.h
>> index 5effa24..629e072 100644
>> --- a/include/fdtdec.h
>> +++ b/include/fdtdec.h
>> @@ -133,6 +133,59 @@ enum fdt_compat_id {
>>       COMPAT_COUNT,
>>  };
>>
>> +#define MAX_PHANDLE_ARGS 16
>> +struct fdtdec_phandle_args {
>> +     int node;
>> +     int args_count;
>> +     uint32_t args[MAX_PHANDLE_ARGS];
>> +};
>> +
>> +/**
>> + * fdtdec_parse_phandle_with_args() - Find a node pointed by phandle in a list
>> + *
>> + * This function is useful to parse lists of phandles and their arguments.
>> + *
>> + * Example:
>> + *
>> + * phandle1: node1 {
>> + *   #list-cells = <2>;
>> + * }
>> + *
>> + * phandle2: node2 {
>> + *   #list-cells = <1>;
>> + * }
>> + *
>> + * node3 {
>> + *   list = <&phandle1 1 2 &phandle2 3>;
>> + * }
>> + *
>> + * To get a device_node of the `node2' node you may call this:
>> + * fdtdec_parse_phandle_with_args(blob, node3, "list", "#list-cells", 0, 1,
>> + *                             &args);
>> + *
>> + * (This function is a modified version of of_parse_phandle_with_args() from
>> + * Linux 3.18)
>
> I think this is a modified version of __of_parse_phandle_with_args()

OK, I have fixed it.

Regards,
Simon

^ permalink raw reply	[flat|nested] 49+ messages in thread

* [U-Boot] [PATCH 21/21] dm: fdt: Remove the old GPIO functions
  2015-01-15  7:28   ` Masahiro Yamada
@ 2015-01-15 14:56     ` Simon Glass
  0 siblings, 0 replies; 49+ messages in thread
From: Simon Glass @ 2015-01-15 14:56 UTC (permalink / raw)
  To: u-boot

Hi Masahiro,

On 15 January 2015 at 00:28, Masahiro Yamada <yamada.m@jp.panasonic.com> wrote:
> Hi Simon,
>
>
> You have already applied this patch.
>
> It might be too late, but...
>
>
>
> You can remove  "#include <asm/gpio.h>"
> from lib/fdtdec.c.
>
>
>
> This is important for me to delete
> my dummy file arch/arm/include/asm/arch-uniphier/gpio.h

Good point, I'll test and send a new patch for this.

Regards,
Simon

^ permalink raw reply	[flat|nested] 49+ messages in thread

end of thread, other threads:[~2015-01-15 14:56 UTC | newest]

Thread overview: 49+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2015-01-06  3:05 [U-Boot] [PATCH 0/21] dm: Support GPIO device tree bindings in the uclass Simon Glass
2015-01-06  3:05 ` [U-Boot] [PATCH 01/21] dm: gpio: Bring in GPIO device tree binding Simon Glass
2015-01-15  4:38   ` Simon Glass
2015-01-06  3:05 ` [U-Boot] [PATCH 02/21] dm: exynos: " Simon Glass
2015-01-15  4:38   ` Simon Glass
2015-01-06  3:05 ` [U-Boot] [PATCH 03/21] dm: tegra: " Simon Glass
2015-01-15  4:39   ` Simon Glass
2015-01-06  3:05 ` [U-Boot] [PATCH 04/21] dm: fdt: Add a function to decode phandles with arguments Simon Glass
2015-01-15  4:39   ` Simon Glass
2015-01-15  7:29   ` Masahiro Yamada
2015-01-15 14:55     ` Simon Glass
2015-01-06  3:05 ` [U-Boot] [PATCH 05/21] dm: gpio: Add a native driver model API Simon Glass
2015-01-15  4:39   ` Simon Glass
2015-01-06  3:05 ` [U-Boot] [PATCH 06/21] dm: gpio: Add a driver GPIO translation method Simon Glass
2015-01-15  4:39   ` Simon Glass
2015-01-06  3:05 ` [U-Boot] [PATCH 07/21] dm: gpio: Add better functions to request GPIOs Simon Glass
2015-01-15  4:39   ` Simon Glass
2015-01-06  3:05 ` [U-Boot] [PATCH 08/21] dm: gpio: Mark the old GPIO API deprecated Simon Glass
2015-01-15  4:39   ` Simon Glass
2015-01-06  3:05 ` [U-Boot] [PATCH 09/21] dm: demo: Add a simple GPIO demonstration Simon Glass
2015-01-15  4:40   ` Simon Glass
2015-01-06  3:05 ` [U-Boot] [PATCH 10/21] dm: cros_ec: Remove use of fdtdec GPIO support Simon Glass
2015-01-15  4:40   ` Simon Glass
2015-01-06  3:05 ` [U-Boot] [PATCH 11/21] dm: tegra: Add a GPIO translation function Simon Glass
2015-01-15  4:40   ` Simon Glass
2015-01-06  3:05 ` [U-Boot] [PATCH 12/21] dm: exynos: " Simon Glass
2015-01-15  4:40   ` Simon Glass
2015-01-06  3:05 ` [U-Boot] [PATCH 13/21] dm: tegra: video: Remove use of fdtdec GPIO support Simon Glass
2015-01-15  4:40   ` Simon Glass
2015-01-06  3:05 ` [U-Boot] [PATCH 14/21] dm: tegra: nand: " Simon Glass
2015-01-15  4:40   ` Simon Glass
2015-01-06  3:05 ` [U-Boot] [PATCH 15/21] dm: zynq: Remove inline gpio functions Simon Glass
2015-01-15  4:40   ` Simon Glass
2015-01-06  3:05 ` [U-Boot] [PATCH 16/21] dm: mmc: Remove use of fdtdec GPIO support Simon Glass
2015-01-15  4:40   ` Simon Glass
2015-01-06  3:05 ` [U-Boot] [PATCH 17/21] dm: usb: " Simon Glass
2015-01-15  4:40   ` Simon Glass
2015-01-06  3:05 ` [U-Boot] [PATCH 18/21] dm: spi: " Simon Glass
2015-01-15  4:40   ` Simon Glass
2015-01-06  3:05 ` [U-Boot] [PATCH 19/21] dm: tegra: dts: Use TEGRA_GPIO() macro for all GPIOs Simon Glass
2015-01-15  4:40   ` Simon Glass
2015-01-06  3:05 ` [U-Boot] [PATCH 20/21] dm: exynos: dts: Use GPIO bank phandles for GPIOs Simon Glass
2015-01-07  2:44   ` Minkyu Kang
2015-01-15  4:40     ` Simon Glass
2015-01-06  3:05 ` [U-Boot] [PATCH 21/21] dm: fdt: Remove the old GPIO functions Simon Glass
2015-01-15  4:40   ` Simon Glass
2015-01-15  7:28   ` Masahiro Yamada
2015-01-15 14:56     ` Simon Glass
2015-01-13  4:19 ` [U-Boot] [PATCH 0/21] dm: Support GPIO device tree bindings in the uclass Simon Glass

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.