diff mbox

[U-Boot,1/9] gpio: bcm2835: add device tree support

Message ID 20160926122651.22132-2-fvogt@suse.com
State Accepted
Commit 4faf5f93c61632c18e435dc6a190b30893786a10
Delegated to: Tom Rini
Headers show

Commit Message

Fabian Vogt Sept. 26, 2016, 12:26 p.m. UTC
This patch adds device tree support for the bcm2835 GPIO driver.

Signed-off-by: Fabian Vogt <fvogt@suse.com>
---
 doc/device-tree-bindings/gpio/bcm2835-gpio.txt |  5 +++++
 drivers/gpio/bcm2835_gpio.c                    | 24 ++++++++++++++++++++++++
 2 files changed, 29 insertions(+)
 create mode 100644 doc/device-tree-bindings/gpio/bcm2835-gpio.txt

Comments

Simon Glass Sept. 27, 2016, 12:32 a.m. UTC | #1
On 26 September 2016 at 06:26, Fabian Vogt <fvogt@suse.com> wrote:
> This patch adds device tree support for the bcm2835 GPIO driver.
>
> Signed-off-by: Fabian Vogt <fvogt@suse.com>
> ---
>  doc/device-tree-bindings/gpio/bcm2835-gpio.txt |  5 +++++
>  drivers/gpio/bcm2835_gpio.c                    | 24 ++++++++++++++++++++++++
>  2 files changed, 29 insertions(+)
>  create mode 100644 doc/device-tree-bindings/gpio/bcm2835-gpio.txt

Reviewed-by: Simon Glass <sjg@chromium.org>
Tom Rini Nov. 29, 2016, 5:33 p.m. UTC | #2
On Mon, Sep 26, 2016 at 02:26:43PM +0200, Fabian Vogt wrote:

> This patch adds device tree support for the bcm2835 GPIO driver.
> 
> Signed-off-by: Fabian Vogt <fvogt@suse.com>
> Reviewed-by: Simon Glass <sjg@chromium.org>

Applied to u-boot/master, thanks!
diff mbox

Patch

diff --git a/doc/device-tree-bindings/gpio/bcm2835-gpio.txt b/doc/device-tree-bindings/gpio/bcm2835-gpio.txt
new file mode 100644
index 0000000..21e0610
--- /dev/null
+++ b/doc/device-tree-bindings/gpio/bcm2835-gpio.txt
@@ -0,0 +1,5 @@ 
+* Broadcom BCM283x GPIO controller
+
+Required properties:
+- compatible: must be "brcm,bcm2835-gpio"
+- reg: exactly one register range with length 0xb4
diff --git a/drivers/gpio/bcm2835_gpio.c b/drivers/gpio/bcm2835_gpio.c
index 8dd7a28..cd5480e 100644
--- a/drivers/gpio/bcm2835_gpio.c
+++ b/drivers/gpio/bcm2835_gpio.c
@@ -10,6 +10,7 @@ 
 #include <errno.h>
 #include <asm/gpio.h>
 #include <asm/io.h>
+#include <fdtdec.h>
 
 struct bcm2835_gpios {
 	struct bcm2835_gpio_regs *reg;
@@ -118,9 +119,32 @@  static int bcm2835_gpio_probe(struct udevice *dev)
 	return 0;
 }
 
+#if CONFIG_IS_ENABLED(OF_CONTROL)
+static const struct udevice_id bcm2835_gpio_id[] = {
+	{.compatible = "brcm,bcm2835-gpio"},
+	{}
+};
+
+static int bcm2835_gpio_ofdata_to_platdata(struct udevice *dev)
+{
+	struct bcm2835_gpio_platdata *plat = dev_get_platdata(dev);
+	fdt_addr_t addr;
+
+	addr = dev_get_addr(dev);
+	if (addr == FDT_ADDR_T_NONE)
+		return -EINVAL;
+
+	plat->base = addr;
+	return 0;
+}
+#endif
+
 U_BOOT_DRIVER(gpio_bcm2835) = {
 	.name	= "gpio_bcm2835",
 	.id	= UCLASS_GPIO,
+	.of_match = of_match_ptr(bcm2835_gpio_id),
+	.ofdata_to_platdata = of_match_ptr(bcm2835_gpio_ofdata_to_platdata),
+	.platdata_auto_alloc_size = sizeof(struct bcm2835_gpio_platdata),
 	.ops	= &gpio_bcm2835_ops,
 	.probe	= bcm2835_gpio_probe,
 	.flags	= DM_FLAG_PRE_RELOC,