Skip to contentSkip to conversation

gpio: Add DW APB GPIO driver

PATCH Superseded Marek Vasut 2 participants 15 messages Jul 27, 2015 – Aug 10, 2015 GPIO

v1 of 3 Superseded Latest is v3 →

lore
Share & tools
lore
#0 lore raw

PATCH 1/2 gpio: Add DW APB GPIO driver

Add driver for the DesignWare APB GPIO IP block.
This driver is DM capable and probes from DT.

---
 drivers/gpio/Makefile     |   1 +
 drivers/gpio/dwapb_gpio.c | 167 ++++++++++++++++++++++++++++++++++++++++++++++
 2 files changed, 168 insertions(+)
 create mode 100644 drivers/gpio/dwapb_gpio.c
drivers/gpio/Makefile +1 -0
index 67c6374..603c96b 100644
@@ -6,6 +6,7 @@
 #
 
 ifndef CONFIG_SPL_BUILD
+obj-$(CONFIG_DWAPB_GPIO)	+= dwapb_gpio.o
 obj-$(CONFIG_AXP_GPIO)		+= axp_gpio.o
 endif
 obj-$(CONFIG_DM_GPIO)		+= gpio-uclass.o
drivers/gpio/dwapb_gpio.c new file +167 -0

167 lines not on this page · raw message

Signature · 1 line
2.1.4
#1 lore raw

PATCH 2/2 arm: socfpga: Enable DWAPB GPIO driver

Enable the DWAPB GPIO driver for SoCFPGA Cyclone V and Arria V.

Cc Simon Glass <[email protected]>
Cc Dinh Nguyen <[email protected]>
---
 include/configs/socfpga_arria5.h   | 2 +-
 include/configs/socfpga_common.h   | 6 ++++++
 include/configs/socfpga_cyclone5.h | 2 +-
 3 files changed, 8 insertions(+), 2 deletions(-)
include/configs/socfpga_arria5.h +1 -1
index 7aee1ce..5a4417f 100644
@@ -26,6 +26,7 @@
 #define CONFIG_CMD_EXT4_WRITE
 #define CONFIG_CMD_FAT
 #define CONFIG_CMD_FS_GENERIC
+#define CONFIG_CMD_GPIO
 #define CONFIG_CMD_GREPENV
 #define CONFIG_CMD_MII
 #define CONFIG_CMD_MMC
@@ -33,7 +34,6 @@
 #define CONFIG_CMD_USB
 #define CONFIG_CMD_USB_MASS_STORAGE
 
-
 /* Memory configurations */
 #define PHYS_SDRAM_1_SIZE		0x40000000	/* 1GiB on SoCDK */
 
include/configs/socfpga_common.h +6 -0
index e8473b8..0298360 100644
@@ -114,6 +114,12 @@
 #endif
 
 /*
+ * GPIO Driver
+ */
+#define CONFIG_DM_GPIO
+#define CONFIG_DWAPB_GPIO
+
+/*
  * L4 OSC1 Timer 0
  */
 /* This timer uses eosc1, whose clock frequency is fixed at any condition. */
include/configs/socfpga_cyclone5.h +1 -1
index 33d04fd..9a9c85a 100644
@@ -26,6 +26,7 @@
 #define CONFIG_CMD_EXT4_WRITE
 #define CONFIG_CMD_FAT
 #define CONFIG_CMD_FS_GENERIC
+#define CONFIG_CMD_GPIO
 #define CONFIG_CMD_GREPENV
 #define CONFIG_CMD_MII
 #define CONFIG_CMD_MMC
@@ -33,7 +34,6 @@
 #define CONFIG_CMD_USB
 #define CONFIG_CMD_USB_MASS_STORAGE
 
-
 /* Memory configurations */
 #define PHYS_SDRAM_1_SIZE		0x40000000	/* 1GiB on SoCDK */
 
Signature · 1 line
2.1.4
#3 lore raw

PATCH 1/2 gpio: Add DW APB GPIO driver

In reply to Marek Vasut

Hi Marek,

Quoted 50 lines · Marek Vasut

Add driver for the DesignWare APB GPIO IP block.
This driver is DM capable and probes from DT.

---
 drivers/gpio/Makefile     |   1 +
 drivers/gpio/dwapb_gpio.c | 167 ++++++++++++++++++++++++++++++++++++++++++++++
 2 files changed, 168 insertions(+)
 create mode 100644 drivers/gpio/dwapb_gpio.c
drivers/gpio/Makefile +1 -0
index 67c6374..603c96b 100644
@@ -6,6 +6,7 @@
 #
 
 ifndef CONFIG_SPL_BUILD
+obj-$(CONFIG_DWAPB_GPIO)       += dwapb_gpio.o
 obj-$(CONFIG_AXP_GPIO)         += axp_gpio.o
 endif
 obj-$(CONFIG_DM_GPIO)          += gpio-uclass.o
drivers/gpio/dwapb_gpio.c new file +21 -0
new file mode 100644
index 0000000..cdb6e78
@@ -0,0 +1,167 @@
+/*
+ * (C) Copyright 2015 Marek Vasut <[email protected]>
+ *
+ * DesignWare APB GPIO driver
+ *
+ * SPDX-License-Identifier:    GPL-2.0+
+ */
+
+#include <common.h>
+#include <malloc.h>
+#include <asm/arch/gpio.h>
+#include <asm/gpio.h>
+#include <asm/io.h>
+#include <dm.h>
+#include <dm/device-internal.h>
+#include <dm/lists.h>
+#include <dm/root.h>
+#include <errno.h>
+
+DECLARE_GLOBAL_DATA_PTR;
+

drivers/gpio/dwapb_gpio.c line 31

Quoted 10 lines
drivers/gpio/dwapb_gpio.c new file +10 -0
+#define GPIO_SWPORTA_DR                0x00
+#define GPIO_SWPORTA_DDR       0x04
+#define GPIO_INTEN             0x30
+#define GPIO_INTMASK           0x34
+#define GPIO_INTTYPE_LEVEL     0x38
+#define GPIO_INT_POLARITY      0x3c
+#define GPIO_INTSTATUS         0x40
+#define GPIO_PORTA_DEBOUNCE    0x48
+#define GPIO_PORTA_EOI         0x4c
+#define GPIO_EXT_PORTA         0x50

Should use C structure, right?

drivers/gpio/dwapb_gpio.c line 42

Quoted 11 lines
drivers/gpio/dwapb_gpio.c new file +11 -0
+
+struct gpio_dwapb_platdata {
+       char            name[24];
+       int             bank;
+       int             pins;
+       fdt_addr_t      base;
+};
+
+static int dwapb_gpio_direction_input(struct udevice *dev, unsigned pin)
+{
+       struct gpio_dwapb_platdata *plat = dev_get_platdata(dev);

blank line after declarations

Quoted 33 lines
drivers/gpio/dwapb_gpio.c new file +33 -0
+       clrbits_le32(plat->base + GPIO_SWPORTA_DDR, 1 << pin);
+       return 0;
+}
+
+static int dwapb_gpio_direction_output(struct udevice *dev, unsigned pin,
+                                    int val)
+{
+       struct gpio_dwapb_platdata *plat = dev_get_platdata(dev);
+
+       setbits_le32(plat->base + GPIO_SWPORTA_DDR, 1 << pin);
+
+       if (val)
+               setbits_le32(plat->base + GPIO_SWPORTA_DR, 1 << pin);
+       else
+               clrbits_le32(plat->base + GPIO_SWPORTA_DR, 1 << pin);
+
+       return 0;
+}
+
+static int dwapb_gpio_get_value(struct udevice *dev, unsigned pin)
+{
+       struct gpio_dwapb_platdata *plat = dev_get_platdata(dev);
+       return !!(readl(plat->base + GPIO_EXT_PORTA) & (1 << pin));
+}
+
+
+static int dwapb_gpio_set_value(struct udevice *dev, unsigned pin, int val)
+{
+       struct gpio_dwapb_platdata *plat = dev_get_platdata(dev);
+
+       if (val)
+               setbits_le32(plat->base + GPIO_SWPORTA_DR, 1 << pin);
+       else

drivers/gpio/dwapb_gpio.c line 85

Quoted 10 lines
drivers/gpio/dwapb_gpio.c new file +10 -0
+               clrbits_le32(plat->base + GPIO_SWPORTA_DR, 1 << pin);
+
+       return 0;
+}
+
+static const struct dm_gpio_ops gpio_dwapb_ops = {
+       .direction_input        = dwapb_gpio_direction_input,
+       .direction_output       = dwapb_gpio_direction_output,
+       .get_value              = dwapb_gpio_get_value,
+       .set_value              = dwapb_gpio_set_value,

Do you want to implement .function?

Quoted 37 lines
drivers/gpio/dwapb_gpio.c new file +37 -0
+};
+
+static int gpio_dwapb_probe(struct udevice *dev)
+{
+       struct gpio_dev_priv *priv = dev_get_uclass_priv(dev);
+       struct gpio_dwapb_platdata *plat = dev->platdata;
+
+       if (!plat)
+               return 0;
+
+       priv->gpio_count = plat->pins;
+       priv->bank_name = plat->name;
+
+       return 0;
+}
+
+static int gpio_dwapb_bind(struct udevice *dev)
+{
+       struct gpio_dwapb_platdata *plat = dev_get_platdata(dev);
+       const void *blob = gd->fdt_blob;
+       struct udevice *subdev;
+       fdt_addr_t base;
+       int node, bank = 0;
+       const char *name;
+
+       /* If this is a child device, there is nothing to do here */
+       if (plat)
+               return 0;
+
+       base = fdtdec_get_addr(blob, dev->of_offset, "reg");
+       if (base == FDT_ADDR_T_NONE) {
+               debug("Can't get the GPIO register base address\n");
+               return -ENXIO;
+       }
+
+       name = fdt_get_name(blob, dev->of_offset, NULL);
+

drivers/gpio/dwapb_gpio.c line 132

Quoted 10 lines
drivers/gpio/dwapb_gpio.c new file +10 -0
+       for (node = fdt_first_subnode(blob, dev->of_offset);
+            node > 0;
+            node = fdt_next_subnode(blob, node)) {
+               int ret;
+
+               if (!fdtdec_get_bool(blob, node, "gpio-controller"))
+                       continue;
+
+               plat = NULL;
+               plat = calloc(1, sizeof(*plat));

I suppose this should use devm_alloc() now.

drivers/gpio/dwapb_gpio.c line 140

Quoted 8 lines
drivers/gpio/dwapb_gpio.c new file +8 -0
+               if (!plat)
+                       return -ENOMEM;
+
+               plat->base = base;
+               plat->bank = bank;
+               plat->pins = fdtdec_get_int(blob, node, "snps,nr-gpios", 0);
+               snprintf(plat->name, sizeof(plat->name) - 1, "%s-bank%i-",
+                        name, bank);

Why such a long name? That's going to be a pain to type in the 'gpio' command.

Quoted 28 lines
drivers/gpio/dwapb_gpio.c new file +27 -1
+
+               ret = device_bind(dev, dev->driver, plat->name,
+                                 plat, -1, &subdev);
+               if (ret)
+                       return ret;
+
+               subdev->of_offset = node;
+               bank++;
+       }
+
+
+       return 0;
+}
+
+static const struct udevice_id gpio_dwapb_ids[] = {
+       { .compatible = "snps,dw-apb-gpio" },
+       { }
+};
+
+U_BOOT_DRIVER(gpio_dwapb) = {
+       .name           = "gpio-dwapb",
+       .id             = UCLASS_GPIO,
+       .of_match       = gpio_dwapb_ids,
+       .ops            = &gpio_dwapb_ops,
+       .bind           = gpio_dwapb_bind,
+       .probe          = gpio_dwapb_probe,
+};
--
Quoted 2 lines

2.1.4

Regards,
Simon

#2 lore raw

PATCH 2/2 arm: socfpga: Enable DWAPB GPIO driver

In reply to Marek Vasut

Hi Marek,

Quoted 36 lines · Marek Vasut

Enable the DWAPB GPIO driver for SoCFPGA Cyclone V and Arria V.

Cc Simon Glass <[email protected]>
Cc Dinh Nguyen <[email protected]>
---
 include/configs/socfpga_arria5.h   | 2 +-
 include/configs/socfpga_common.h   | 6 ++++++
 include/configs/socfpga_cyclone5.h | 2 +-
 3 files changed, 8 insertions(+), 2 deletions(-)
include/configs/socfpga_arria5.h +1 -1
index 7aee1ce..5a4417f 100644
@@ -26,6 +26,7 @@
 #define CONFIG_CMD_EXT4_WRITE
 #define CONFIG_CMD_FAT
 #define CONFIG_CMD_FS_GENERIC
+#define CONFIG_CMD_GPIO
 #define CONFIG_CMD_GREPENV
 #define CONFIG_CMD_MII
 #define CONFIG_CMD_MMC
@@ -33,7 +34,6 @@
 #define CONFIG_CMD_USB
 #define CONFIG_CMD_USB_MASS_STORAGE
 
-
 /* Memory configurations */
 #define PHYS_SDRAM_1_SIZE              0x40000000      /* 1GiB on SoCDK */
 
include/configs/socfpga_common.h +0 -0
index e8473b8..0298360 100644

include/configs/socfpga_common.h line 120

Quoted 7 lines
include/configs/socfpga_common.h +4 -0
@@ -114,6 +114,12 @@
 #endif
 
 /*
+ * GPIO Driver
+ */
+#define CONFIG_DM_GPIO
+#define CONFIG_DWAPB_GPIO

Should use Kconfig.

Quoted 26 lines
include/configs/socfpga_common.h +2 -0
+
+/*
  * L4 OSC1 Timer 0
  */
 /* This timer uses eosc1, whose clock frequency is fixed at any condition. */
include/configs/socfpga_cyclone5.h +1 -2
index 33d04fd..9a9c85a 100644
@@ -26,6 +26,7 @@
 #define CONFIG_CMD_EXT4_WRITE
 #define CONFIG_CMD_FAT
 #define CONFIG_CMD_FS_GENERIC
+#define CONFIG_CMD_GPIO
 #define CONFIG_CMD_GREPENV
 #define CONFIG_CMD_MII
 #define CONFIG_CMD_MMC
@@ -33,7 +34,6 @@
 #define CONFIG_CMD_USB
 #define CONFIG_CMD_USB_MASS_STORAGE
 
-
 /* Memory configurations */
 #define PHYS_SDRAM_1_SIZE              0x40000000      /* 1GiB on SoCDK */
 
--
Quoted 2 lines

2.1.4

Regards,
Simon

#4 lore raw

PATCH 1/2 gpio: Add DW APB GPIO driver

In reply to Simon Glass
Quoted 1 line · Simon Glass

Hi Marek,

Hi,

Quoted 6 lines · Marek Vasut
Quoted 5 lines

Add driver for the DesignWare APB GPIO IP block.
This driver is DM capable and probes from DT.

[...]

Quoted 4 lines
Quoted 4 lines
drivers/gpio/dwapb_gpio.c new file +4 -0
+#define GPIO_SWPORTA_DR                0x00
+#define GPIO_SWPORTA_DDR       0x04
+#define GPIO_INTEN             0x30
+#define GPIO_INTMASK           0x34
Quoted 8 lines

drivers/gpio/dwapb_gpio.c line 31

Quoted 6 lines
drivers/gpio/dwapb_gpio.c new file +6 -0
+#define GPIO_INTTYPE_LEVEL     0x38
+#define GPIO_INT_POLARITY      0x3c
+#define GPIO_INTSTATUS         0x40
+#define GPIO_PORTA_DEBOUNCE    0x48
+#define GPIO_PORTA_EOI         0x4c
+#define GPIO_EXT_PORTA         0x50

Should use C structure, right?

My understanding is that we no longer want C structs . Tom ?

[...]

Quoted 7 lines

drivers/gpio/dwapb_gpio.c line 85

Quoted 5 lines
drivers/gpio/dwapb_gpio.c new file +5 -0
+static const struct dm_gpio_ops gpio_dwapb_ops = {
+       .direction_input        = dwapb_gpio_direction_input,
+       .direction_output       = dwapb_gpio_direction_output,
+       .get_value              = dwapb_gpio_get_value,
+       .set_value              = dwapb_gpio_set_value,

Do you want to implement .function?

No, the pinmuxing on SoCFPGA is still in a weird state.

Quoted 41 lines
Quoted 41 lines
drivers/gpio/dwapb_gpio.c new file +41 -0
+};
+
+static int gpio_dwapb_probe(struct udevice *dev)
+{
+       struct gpio_dev_priv *priv = dev_get_uclass_priv(dev);
+       struct gpio_dwapb_platdata *plat = dev->platdata;
+
+       if (!plat)
+               return 0;
+
+       priv->gpio_count = plat->pins;
+       priv->bank_name = plat->name;
+
+       return 0;
+}
+
+static int gpio_dwapb_bind(struct udevice *dev)
+{
+       struct gpio_dwapb_platdata *plat = dev_get_platdata(dev);
+       const void *blob = gd->fdt_blob;
+       struct udevice *subdev;
+       fdt_addr_t base;
+       int node, bank = 0;
+       const char *name;
+
+       /* If this is a child device, there is nothing to do here */
+       if (plat)
+               return 0;
+
+       base = fdtdec_get_addr(blob, dev->of_offset, "reg");
+       if (base == FDT_ADDR_T_NONE) {
+               debug("Can't get the GPIO register base address\n");
+               return -ENXIO;
+       }
+
+       name = fdt_get_name(blob, dev->of_offset, NULL);
+
+       for (node = fdt_first_subnode(blob, dev->of_offset);
+            node > 0;
+            node = fdt_next_subnode(blob, node)) {
+               int ret;
Quoted 8 lines

drivers/gpio/dwapb_gpio.c line 132

Quoted 6 lines
drivers/gpio/dwapb_gpio.c new file +6 -0
+
+               if (!fdtdec_get_bool(blob, node, "gpio-controller"))
+                       continue;
+
+               plat = NULL;
+               plat = calloc(1, sizeof(*plat));

I suppose this should use devm_alloc() now.

Is that even in u-boot/master ? Also, I'm not sure it's a good idea to put this in if I use this driver in SPL.

Quoted 11 lines
Quoted 8 lines
drivers/gpio/dwapb_gpio.c new file +6 -0
+               if (!plat)
+                       return -ENOMEM;
+
+               plat->base = base;
+               plat->bank = bank;
+               plat->pins = fdtdec_get_int(blob, node, "snps,nr-gpios",

0); + snprintf(plat->name, sizeof(plat->name) - 1,
"%s-bank%i-", + name, bank);

Why such a long name? That's going to be a pain to type in the 'gpio' command.

Do you have a suggestion please ?

Also, I can as well use "gpio <operation> N" , where N is a number.

Quoted 32 lines
Quoted 28 lines
drivers/gpio/dwapb_gpio.c new file +27 -1
+
+               ret = device_bind(dev, dev->driver, plat->name,
+                                 plat, -1, &subdev);
+               if (ret)
+                       return ret;
+
+               subdev->of_offset = node;
+               bank++;
+       }
+
+
+       return 0;
+}
+
+static const struct udevice_id gpio_dwapb_ids[] = {
+       { .compatible = "snps,dw-apb-gpio" },
+       { }
+};
+
+U_BOOT_DRIVER(gpio_dwapb) = {
+       .name           = "gpio-dwapb",
+       .id             = UCLASS_GPIO,
+       .of_match       = gpio_dwapb_ids,
+       .ops            = &gpio_dwapb_ops,
+       .bind           = gpio_dwapb_bind,
+       .probe          = gpio_dwapb_probe,
+};
--
Quoted 1 line

2.1.4

Regards,
Simon

#5 lore raw

PATCH 1/2 gpio: Add DW APB GPIO driver

Hi Marek,

Quoted 91 lines · Marek Vasut
Quoted 1 line · Simon Glass

Hi Marek,

Hi,

Quoted 6 lines · Marek Vasut
Quoted 5 lines

Add driver for the DesignWare APB GPIO IP block.
This driver is DM capable and probes from DT.

[...]

Quoted 4 lines
Quoted 4 lines
drivers/gpio/dwapb_gpio.c new file +4 -0
+#define GPIO_SWPORTA_DR                0x00
+#define GPIO_SWPORTA_DDR       0x04
+#define GPIO_INTEN             0x30
+#define GPIO_INTMASK           0x34
Quoted 8 lines

drivers/gpio/dwapb_gpio.c line 31

Quoted 6 lines
drivers/gpio/dwapb_gpio.c new file +6 -0
+#define GPIO_INTTYPE_LEVEL     0x38
+#define GPIO_INT_POLARITY      0x3c
+#define GPIO_INTSTATUS         0x40
+#define GPIO_PORTA_DEBOUNCE    0x48
+#define GPIO_PORTA_EOI         0x4c
+#define GPIO_EXT_PORTA         0x50

Should use C structure, right?

My understanding is that we no longer want C structs . Tom ?

[...]

Quoted 7 lines

drivers/gpio/dwapb_gpio.c line 85

Quoted 5 lines
drivers/gpio/dwapb_gpio.c new file +5 -0
+static const struct dm_gpio_ops gpio_dwapb_ops = {
+       .direction_input        = dwapb_gpio_direction_input,
+       .direction_output       = dwapb_gpio_direction_output,
+       .get_value              = dwapb_gpio_get_value,
+       .set_value              = dwapb_gpio_set_value,

Do you want to implement .function?

No, the pinmuxing on SoCFPGA is still in a weird state.

Quoted 41 lines
Quoted 41 lines
drivers/gpio/dwapb_gpio.c new file +41 -0
+};
+
+static int gpio_dwapb_probe(struct udevice *dev)
+{
+       struct gpio_dev_priv *priv = dev_get_uclass_priv(dev);
+       struct gpio_dwapb_platdata *plat = dev->platdata;
+
+       if (!plat)
+               return 0;
+
+       priv->gpio_count = plat->pins;
+       priv->bank_name = plat->name;
+
+       return 0;
+}
+
+static int gpio_dwapb_bind(struct udevice *dev)
+{
+       struct gpio_dwapb_platdata *plat = dev_get_platdata(dev);
+       const void *blob = gd->fdt_blob;
+       struct udevice *subdev;
+       fdt_addr_t base;
+       int node, bank = 0;
+       const char *name;
+
+       /* If this is a child device, there is nothing to do here */
+       if (plat)
+               return 0;
+
+       base = fdtdec_get_addr(blob, dev->of_offset, "reg");
+       if (base == FDT_ADDR_T_NONE) {
+               debug("Can't get the GPIO register base address\n");
+               return -ENXIO;
+       }
+
+       name = fdt_get_name(blob, dev->of_offset, NULL);
+
+       for (node = fdt_first_subnode(blob, dev->of_offset);
+            node > 0;
+            node = fdt_next_subnode(blob, node)) {
+               int ret;
Quoted 8 lines

drivers/gpio/dwapb_gpio.c line 132

Quoted 6 lines
drivers/gpio/dwapb_gpio.c new file +6 -0
+
+               if (!fdtdec_get_bool(blob, node, "gpio-controller"))
+                       continue;
+
+               plat = NULL;
+               plat = calloc(1, sizeof(*plat));

I suppose this should use devm_alloc() now.

Quoted 2 lines

Is that even in u-boot/master ? Also, I'm not sure it's a good idea to put this in if I use this driver in SPL.

Yes it's very new. Only in dm/master.

It's only compiled in when enabled, so you can still use it in SPL.

Up to you. At some point I think we should convert all driver allocs to use devm so that we know what allocation is going on.

Quoted 10 lines
Quoted 10 lines
Quoted 9 lines
drivers/gpio/dwapb_gpio.c new file +6 -0
+               if (!plat)
+                       return -ENOMEM;
+
+               plat->base = base;
+               plat->bank = bank;
+               plat->pins = fdtdec_get_int(blob, node, "snps,nr-gpios",

0); + snprintf(plat->name, sizeof(plat->name) - 1,
"%s-bank%i-", + name, bank);

Quoted 4 lines
Quoted 2 lines

Why such a long name? That's going to be a pain to type in the 'gpio' command.

Do you have a suggestion please ?

A, B, C is good if you have <=26 banks. Tegra does that.

Exynos does PA0, PA1, PB0, PC0, PC1, etc.

Quoted 35 lines

Also, I can as well use "gpio <operation> N" , where N is a number.

Quoted 32 lines
Quoted 28 lines
drivers/gpio/dwapb_gpio.c new file +27 -1
+
+               ret = device_bind(dev, dev->driver, plat->name,
+                                 plat, -1, &subdev);
+               if (ret)
+                       return ret;
+
+               subdev->of_offset = node;
+               bank++;
+       }
+
+
+       return 0;
+}
+
+static const struct udevice_id gpio_dwapb_ids[] = {
+       { .compatible = "snps,dw-apb-gpio" },
+       { }
+};
+
+U_BOOT_DRIVER(gpio_dwapb) = {
+       .name           = "gpio-dwapb",
+       .id             = UCLASS_GPIO,
+       .of_match       = gpio_dwapb_ids,
+       .ops            = &gpio_dwapb_ops,
+       .bind           = gpio_dwapb_bind,
+       .probe          = gpio_dwapb_probe,
+};
--
Quoted 1 line

2.1.4

Regards,
Simon

Regards,
Simon

#6 lore raw

PATCH 1/2 gpio: Add DW APB GPIO driver

Quoted 1 line · Simon Glass

Hi Marek,

Hi Simon,

[...]

Quoted 11 lines
Quoted 10 lines
Quoted 7 lines

drivers/gpio/dwapb_gpio.c line 132

Quoted 5 lines
drivers/gpio/dwapb_gpio.c new file +5 -0
+               if (!fdtdec_get_bool(blob, node, "gpio-controller"))
+                       continue;
+
+               plat = NULL;
+               plat = calloc(1, sizeof(*plat));

I suppose this should use devm_alloc() now.

Is that even in u-boot/master ? Also, I'm not sure it's a good idea to put this in if I use this driver in SPL.

Quoted 6 lines

Yes it's very new. Only in dm/master.

It's only compiled in when enabled, so you can still use it in SPL.

Up to you. At some point I think we should convert all driver allocs to use devm so that we know what allocation is going on.

When is this landing in master ? I don't mind either way, but I can do a linting pass on the socfpga when things settle down too.

Quoted 10 lines
Quoted 10 lines
Quoted 10 lines
Quoted 9 lines
drivers/gpio/dwapb_gpio.c new file +6 -0
+               if (!plat)
+                       return -ENOMEM;
+
+               plat->base = base;
+               plat->bank = bank;
+               plat->pins = fdtdec_get_int(blob, node,

"snps,nr-gpios", 0); + snprintf(plat->name,
sizeof(plat->name) - 1, "%s-bank%i-", + name,
bank);

Quoted 8 lines
Quoted 4 lines
Quoted 2 lines

Why such a long name? That's going to be a pain to type in the 'gpio' command.

Do you have a suggestion please ?

A, B, C is good if you have <=26 banks. Tegra does that.

Exynos does PA0, PA1, PB0, PC0, PC1, etc.

How do I identify which one is PA0/PA1/PA2 , shall I perform some transformation on the register address of the GPIO block or example ? But how can I assure that if the next SoCFPGA has these addresses completely different, these GPIO numbers will be stable ? Isn't it better to be explicit about the GPIO block ID then ?

Also, remember that I have an FPGA in the same package, which has a lot of I/O.

Quoted 1 line
Quoted 1 line

Also, I can as well use "gpio <operation> N" , where N is a number.

What about this ? How does indexing the GPIOs with plain number fit into the picture please ?

[...]

#7 lore raw

PATCH 1/2 gpio: Add DW APB GPIO driver

Hi Marek,

Quoted 20 lines · Marek Vasut
Quoted 1 line · Simon Glass

Hi Marek,

Hi Simon,

[...]

Quoted 13 lines
Quoted 10 lines
Quoted 7 lines

drivers/gpio/dwapb_gpio.c line 132

Quoted 5 lines
drivers/gpio/dwapb_gpio.c new file +5 -0
+               if (!fdtdec_get_bool(blob, node, "gpio-controller"))
+                       continue;
+
+               plat = NULL;
+               plat = calloc(1, sizeof(*plat));

I suppose this should use devm_alloc() now.

Is that even in u-boot/master ? Also, I'm not sure it's a good idea to put this in if I use this driver in SPL.

Yes it's very new. Only in dm/master.

Quoted 7 lines
Quoted 4 lines

It's only compiled in when enabled, so you can still use it in SPL.

Up to you. At some point I think we should convert all driver allocs to use devm so that we know what allocation is going on.

When is this landing in master ? I don't mind either way, but I can do a linting pass on the socfpga when things settle down too.

Hopefully I'll have a pull request out on Friday.

Quoted 16 lines
Quoted 16 lines
Quoted 15 lines
Quoted 11 lines
Quoted 10 lines
drivers/gpio/dwapb_gpio.c new file +6 -0
+               if (!plat)
+                       return -ENOMEM;
+
+               plat->base = base;
+               plat->bank = bank;
+               plat->pins = fdtdec_get_int(blob, node,

"snps,nr-gpios", 0); + snprintf(plat->name,
sizeof(plat->name) - 1, "%s-bank%i-", + name,
bank);

Quoted 2 lines

Why such a long name? That's going to be a pain to type in the 'gpio' command.

Do you have a suggestion please ?

Quoted 8 lines
Quoted 3 lines

A, B, C is good if you have <=26 banks. Tegra does that.

Exynos does PA0, PA1, PB0, PC0, PC1, etc.

How do I identify which one is PA0/PA1/PA2 , shall I perform some transformation on the register address of the GPIO block or example ? But how can I assure that if the next SoCFPGA has these addresses completely different, these GPIO numbers will be stable ? Isn't it better to be explicit about the GPIO block ID then ?

It's up to you. Normally each bank has a name and the datasheet specifies it. In your case if not you could think about a naming scheme.

Quoted 7 lines

Also, remember that I have an FPGA in the same package, which has a lot of I/O.

Quoted 1 line
Quoted 1 line

Also, I can as well use "gpio <operation> N" , where N is a number.

What about this ? How does indexing the GPIOs with plain number fit into the picture please ?

Driver model GPIO handles this automatically. If you can add different numbers of GPIO blocks you might consider adding them as different GPIO banks with their own names. The global number depends on the probe order which depends on the bind order (i.e. device tree node order). But names are safer than numbers - a small change can change all the numbers. There is a function to get the global number given a GPIO device and offset.

Regards,
Simon

#8 lore raw

PATCH 1/2 gpio: Add DW APB GPIO driver

Quoted 1 line · Simon Glass

Hi Marek,

Hi Simon,

Quoted 23 lines · Marek Vasut
Quoted 22 lines · Simon Glass
Quoted 1 line

Hi Marek,

Hi Simon,

[...]

Quoted 15 lines
Quoted 10 lines
Quoted 7 lines

drivers/gpio/dwapb_gpio.c line 132

Quoted 5 lines

+ if (!fdtdec_get_bool(blob, node,
"gpio-controller")) + continue;

drivers/gpio/dwapb_gpio.c new file +3 -0
+
+               plat = NULL;
+               plat = calloc(1, sizeof(*plat));

I suppose this should use devm_alloc() now.

Is that even in u-boot/master ? Also, I'm not sure it's a good idea to put this in if I use this driver in SPL.

Yes it's very new. Only in dm/master.

It's only compiled in when enabled, so you can still use it in SPL.

Quoted 7 lines
Quoted 5 lines
Quoted 2 lines

Up to you. At some point I think we should convert all driver allocs to use devm so that we know what allocation is going on.

When is this landing in master ? I don't mind either way, but I can do a linting pass on the socfpga when things settle down too.

Hopefully I'll have a pull request out on Friday.

Cool!

Quoted 25 lines
Quoted 17 lines
Quoted 17 lines
Quoted 10 lines
Quoted 10 lines
Quoted 9 lines
drivers/gpio/dwapb_gpio.c new file +6 -0
+               if (!plat)
+                       return -ENOMEM;
+
+               plat->base = base;
+               plat->bank = bank;
+               plat->pins = fdtdec_get_int(blob, node,

"snps,nr-gpios", 0); + snprintf(plat->name,
sizeof(plat->name) - 1, "%s-bank%i-", +
name, bank);

Quoted 4 lines
Quoted 2 lines

Why such a long name? That's going to be a pain to type in the 'gpio' command.

Do you have a suggestion please ?

A, B, C is good if you have <=26 banks. Tegra does that.

Quoted 7 lines
Quoted 1 line

Exynos does PA0, PA1, PB0, PC0, PC1, etc.

How do I identify which one is PA0/PA1/PA2 , shall I perform some transformation on the register address of the GPIO block or example ? But how can I assure that if the next SoCFPGA has these addresses completely different, these GPIO numbers will be stable ? Isn't it better to be explicit about the GPIO block ID then ?

Quoted 3 lines

It's up to you. Normally each bank has a name and the datasheet specifies it. In your case if not you could think about a naming scheme.

Can you please take a look into arch/arm/dts/socfpga.dtsi ? The system has three GPIO controllers (look for gpio0, gpio1, gpio2) and each of these controllers has one bank (porta, portb, portc) .

I can name my gpios portxN , where x is either of a,b,c and N is the GPIO number. The problem is, I cannot determine in dwapb_gpio_bind() which one is "porta", "portb" and "portc" because all I have is the physical addess of the GPIO controller and the index of the bank in the namespace of that controller.

Sure, I can do some sort of global counting in the driver, but I would like to avoid that sort of thing. I can also add some kind of ad-hoc DT prop, but that's also not a good idea I think. Do you have any suggestion for me please ?

Quoted 8 lines
Quoted 7 lines

Also, remember that I have an FPGA in the same package, which has a lot of I/O.

Quoted 1 line
Quoted 1 line

Also, I can as well use "gpio <operation> N" , where N is a number.

What about this ? How does indexing the GPIOs with plain number fit into the picture please ?

Quoted 7 lines

Driver model GPIO handles this automatically. If you can add different numbers of GPIO blocks you might consider adding them as different GPIO banks with their own names. The global number depends on the probe order which depends on the bind order (i.e. device tree node order). But names are safer than numbers - a small change can change all the numbers. There is a function to get the global number given a GPIO device and offset.

I see, thanks for clarifying!

#9 lore raw

PATCH 1/2 gpio: Add DW APB GPIO driver

Hi Marek,

Quoted 77 lines · Marek Vasut
Quoted 1 line · Simon Glass

Hi Marek,

Hi Simon,

Quoted 23 lines · Marek Vasut
Quoted 22 lines · Simon Glass
Quoted 1 line

Hi Marek,

Hi Simon,

[...]

Quoted 15 lines
Quoted 10 lines
Quoted 7 lines

Review

Quoted 5 lines

+ if (!fdtdec_get_bool(blob, node,
"gpio-controller")) + continue;

(quoted diff) +3 -0
+
+               plat = NULL;
+               plat = calloc(1, sizeof(*plat));

I suppose this should use devm_alloc() now.

Is that even in u-boot/master ? Also, I'm not sure it's a good idea to put this in if I use this driver in SPL.

Yes it's very new. Only in dm/master.

It's only compiled in when enabled, so you can still use it in SPL.

Quoted 7 lines
Quoted 5 lines
Quoted 2 lines

Up to you. At some point I think we should convert all driver allocs to use devm so that we know what allocation is going on.

When is this landing in master ? I don't mind either way, but I can do a linting pass on the socfpga when things settle down too.

Hopefully I'll have a pull request out on Friday.

Cool!

Quoted 25 lines
Quoted 17 lines
Quoted 17 lines
Quoted 10 lines
Quoted 10 lines
Quoted 9 lines
(quoted diff) +6 -0
+               if (!plat)
+                       return -ENOMEM;
+
+               plat->base = base;
+               plat->bank = bank;
+               plat->pins = fdtdec_get_int(blob, node,

"snps,nr-gpios", 0); + snprintf(plat->name,
sizeof(plat->name) - 1, "%s-bank%i-", +
name, bank);

Quoted 4 lines
Quoted 2 lines

Why such a long name? That's going to be a pain to type in the 'gpio' command.

Do you have a suggestion please ?

A, B, C is good if you have <=26 banks. Tegra does that.

Quoted 7 lines
Quoted 1 line

Exynos does PA0, PA1, PB0, PC0, PC1, etc.

How do I identify which one is PA0/PA1/PA2 , shall I perform some transformation on the register address of the GPIO block or example ? But how can I assure that if the next SoCFPGA has these addresses completely different, these GPIO numbers will be stable ? Isn't it better to be explicit about the GPIO block ID then ?

Quoted 3 lines

It's up to you. Normally each bank has a name and the datasheet specifies it. In your case if not you could think about a naming scheme.

Can you please take a look into arch/arm/dts/socfpga.dtsi ? The system has three GPIO controllers (look for gpio0, gpio1, gpio2) and each of these controllers has one bank (porta, portb, portc) .

I can name my gpios portxN , where x is either of a,b,c and N is the GPIO number. The problem is, I cannot determine in dwapb_gpio_bind() which one is "porta", "portb" and "portc" because all I have is the physical addess of the GPIO controller and the index of the bank in the namespace of that controller.

Quoted 4 lines

Sure, I can do some sort of global counting in the driver, but I would like to avoid that sort of thing. I can also add some kind of ad-hoc DT prop, but that's also not a good idea I think. Do you have any suggestion for me please ?

One option is to use the device tree node name but it isn't very friendly - gpio0 at xxxxx. You could perhaps add a new property like 'bank-name'?

Quoted 17 lines
Quoted 9 lines
Quoted 8 lines

Also, remember that I have an FPGA in the same package, which has a lot of I/O.

Quoted 1 line
Quoted 1 line

Also, I can as well use "gpio <operation> N" , where N is a number.

What about this ? How does indexing the GPIOs with plain number fit into the picture please ?

Quoted 7 lines

Driver model GPIO handles this automatically. If you can add different numbers of GPIO blocks you might consider adding them as different GPIO banks with their own names. The global number depends on the probe order which depends on the bind order (i.e. device tree node order). But names are safer than numbers - a small change can change all the numbers. There is a function to get the global number given a GPIO device and offset.

Quoted 1 line

I see, thanks for clarifying!

Regards,
Simon

#10 lore raw

PATCH 1/2 gpio: Add DW APB GPIO driver

Quoted 1 line · Simon Glass

Hi Marek,

Hi!

Quoted 5 lines · Marek Vasut
Quoted 4 lines · Simon Glass
Quoted 1 line

Hi Marek,

Hi Simon,

[...]

Quoted 14 lines
Quoted 14 lines
Quoted 3 lines

It's up to you. Normally each bank has a name and the datasheet specifies it. In your case if not you could think about a naming scheme.

Can you please take a look into arch/arm/dts/socfpga.dtsi ? The system has three GPIO controllers (look for gpio0, gpio1, gpio2) and each of these controllers has one bank (porta, portb, portc) .

I can name my gpios portxN , where x is either of a,b,c and N is the GPIO number. The problem is, I cannot determine in dwapb_gpio_bind() which one is "porta", "portb" and "portc" because all I have is the physical addess of the GPIO controller and the index of the bank in the namespace of that controller.

Quoted 7 lines
Quoted 4 lines

Sure, I can do some sort of global counting in the driver, but I would like to avoid that sort of thing. I can also add some kind of ad-hoc DT prop, but that's also not a good idea I think. Do you have any suggestion for me please ?

One option is to use the device tree node name but it isn't very friendly - gpio0 at xxxxx.

That's what I do now pretty much.

Quoted 1 line

You could perhaps add a new property like 'bank-name'?

Do we want to add ad-hoc DT nodes which are
a) Not describing hardware
b) Not part of the official DT bindings for that platform ?

Is that really a way to go ?

[...]

Best regards,
Marek Vasut

#11 lore raw

PATCH 1/2 gpio: Add DW APB GPIO driver

Hi Marek,

Quoted 39 lines · Marek Vasut
Quoted 1 line · Simon Glass

Hi Marek,

Hi!

Quoted 5 lines · Marek Vasut
Quoted 4 lines · Simon Glass
Quoted 1 line

Hi Marek,

Hi Simon,

[...]

Quoted 14 lines
Quoted 14 lines
Quoted 3 lines

It's up to you. Normally each bank has a name and the datasheet specifies it. In your case if not you could think about a naming scheme.

Can you please take a look into arch/arm/dts/socfpga.dtsi ? The system has three GPIO controllers (look for gpio0, gpio1, gpio2) and each of these controllers has one bank (porta, portb, portc) .

I can name my gpios portxN , where x is either of a,b,c and N is the GPIO number. The problem is, I cannot determine in dwapb_gpio_bind() which one is "porta", "portb" and "portc" because all I have is the physical addess of the GPIO controller and the index of the bank in the namespace of that controller.

Quoted 7 lines
Quoted 4 lines

Sure, I can do some sort of global counting in the driver, but I would like to avoid that sort of thing. I can also add some kind of ad-hoc DT prop, but that's also not a good idea I think. Do you have any suggestion for me please ?

One option is to use the device tree node name but it isn't very friendly - gpio0 at xxxxx.

That's what I do now pretty much.

Quoted 1 line

You could perhaps add a new property like 'bank-name'?

Quoted 9 lines

Do we want to add ad-hoc DT nodes which are
a) Not describing hardware
b) Not part of the official DT bindings for that platform ?

Is that really a way to go ?

[...]

It needs to be part of the official binding. Naming the hardware is part of the hardware definition - see for example the regulator-name property for regulators.

Another option is to use an alias:

aliases {
gpio0 = &gpio_0;
gpio1 = &gpio_1;
gpio2 = &gpio_2;
}

Then you can turn gpio0 into bank A, gpio1 into bank B, etc.

Regards,
Simon

#12 lore raw

PATCH 1/2 gpio: Add DW APB GPIO driver

Quoted 1 line · Simon Glass

Hi Marek,

Hi Simon,

Quoted 45 lines · Marek Vasut
Quoted 44 lines · Simon Glass
Quoted 1 line

Hi Marek,

Hi!

Quoted 5 lines · Marek Vasut
Quoted 4 lines · Simon Glass
Quoted 1 line

Hi Marek,

Hi Simon,

[...]

Quoted 14 lines
Quoted 14 lines
Quoted 3 lines

It's up to you. Normally each bank has a name and the datasheet specifies it. In your case if not you could think about a naming scheme.

Can you please take a look into arch/arm/dts/socfpga.dtsi ? The system has three GPIO controllers (look for gpio0, gpio1, gpio2) and each of these controllers has one bank (porta, portb, portc) .

I can name my gpios portxN , where x is either of a,b,c and N is the GPIO number. The problem is, I cannot determine in dwapb_gpio_bind() which one is "porta", "portb" and "portc" because all I have is the physical addess of the GPIO controller and the index of the bank in the namespace of that controller.

Quoted 7 lines
Quoted 4 lines

Sure, I can do some sort of global counting in the driver, but I would like to avoid that sort of thing. I can also add some kind of ad-hoc DT prop, but that's also not a good idea I think. Do you have any suggestion for me please ?

One option is to use the device tree node name but it isn't very friendly - gpio0 at xxxxx.

That's what I do now pretty much.

Quoted 1 line

You could perhaps add a new property like 'bank-name'?

Do we want to add ad-hoc DT nodes which are
a) Not describing hardware
b) Not part of the official DT bindings for that platform ?

Quoted 7 lines
Quoted 3 lines

Is that really a way to go ?

[...]

It needs to be part of the official binding. Naming the hardware is part of the hardware definition - see for example the regulator-name property for regulators.

So what do you think about introducing a 'bank-name' property then ? I think this might work just fine ?

Quoted 9 lines

Another option is to use an alias:

aliases {
   gpio0 = &gpio_0;
   gpio1 = &gpio_1;
   gpio2 = &gpio_2;
}

Then you can turn gpio0 into bank A, gpio1 into bank B, etc.

Is there a function which maps the udevice->dev->of_offset into an alias's seq ID ?

Best regards,
Marek Vasut

#13 lore raw

PATCH 1/2 gpio: Add DW APB GPIO driver

Hi Marek,

Quoted 53 lines · Marek Vasut
Quoted 1 line · Simon Glass

Hi Marek,

Hi Simon,

Quoted 47 lines · Marek Vasut
Quoted 46 lines · Simon Glass
Quoted 1 line

Hi Marek,

Hi!

Quoted 5 lines · Marek Vasut
Quoted 4 lines · Simon Glass
Quoted 1 line

Hi Marek,

Hi Simon,

[...]

Quoted 14 lines
Quoted 14 lines
Quoted 3 lines

It's up to you. Normally each bank has a name and the datasheet specifies it. In your case if not you could think about a naming scheme.

Can you please take a look into arch/arm/dts/socfpga.dtsi ? The system has three GPIO controllers (look for gpio0, gpio1, gpio2) and each of these controllers has one bank (porta, portb, portc) .

I can name my gpios portxN , where x is either of a,b,c and N is the GPIO number. The problem is, I cannot determine in dwapb_gpio_bind() which one is "porta", "portb" and "portc" because all I have is the physical addess of the GPIO controller and the index of the bank in the namespace of that controller.

Quoted 7 lines
Quoted 4 lines

Sure, I can do some sort of global counting in the driver, but I would like to avoid that sort of thing. I can also add some kind of ad-hoc DT prop, but that's also not a good idea I think. Do you have any suggestion for me please ?

One option is to use the device tree node name but it isn't very friendly - gpio0 at xxxxx.

That's what I do now pretty much.

Quoted 1 line

You could perhaps add a new property like 'bank-name'?

Do we want to add ad-hoc DT nodes which are
a) Not describing hardware
b) Not part of the official DT bindings for that platform ?

Is that really a way to go ?

Quoted 8 lines
Quoted 5 lines
Quoted 1 line

[...]

It needs to be part of the official binding. Naming the hardware is part of the hardware definition - see for example the regulator-name property for regulators.

So what do you think about introducing a 'bank-name' property then ? I think this might work just fine ?

I think it's OK - just make sure you send the GPIO binding change to Linux too.

Quoted 9 lines
Quoted 9 lines

Another option is to use an alias:

aliases {
   gpio0 = &gpio_0;
   gpio1 = &gpio_1;
   gpio2 = &gpio_2;
}
Quoted 4 lines
Quoted 1 line

Then you can turn gpio0 into bank A, gpio1 into bank B, etc.

Is there a function which maps the udevice->dev->of_offset into an alias's seq ID ?

dev->seq, once it is probed. Until it is probed it doesn't have a sequence number (by definition).

You can use fdtdec_get_alias_seq() but I don't recommend it. We're trying to drop fdtdec eventually.

Regards,
Simon

#14 lore raw

PATCH 1/2 gpio: Add DW APB GPIO driver

Quoted 80 lines · Simon Glass

Hi Marek,

Quoted 53 lines · Marek Vasut
Quoted 1 line · Simon Glass

Hi Marek,

Hi Simon,

Quoted 48 lines · Marek Vasut
Quoted 47 lines · Simon Glass
Quoted 1 line

Hi Marek,

Hi!

Quoted 5 lines · Marek Vasut
Quoted 4 lines · Simon Glass
Quoted 1 line

Hi Marek,

Hi Simon,

[...]

Quoted 15 lines
Quoted 15 lines
Quoted 3 lines

It's up to you. Normally each bank has a name and the datasheet specifies it. In your case if not you could think about a naming scheme.

Can you please take a look into arch/arm/dts/socfpga.dtsi ? The system has three GPIO controllers (look for gpio0, gpio1, gpio2) and each of these controllers has one bank (porta, portb, portc) .

I can name my gpios portxN , where x is either of a,b,c and N is the GPIO number. The problem is, I cannot determine in dwapb_gpio_bind() which one is "porta", "portb" and "portc" because all I have is the physical addess of the GPIO controller and the index of the bank in the namespace of that controller.

Quoted 7 lines
Quoted 4 lines

Sure, I can do some sort of global counting in the driver, but I would like to avoid that sort of thing. I can also add some kind of ad-hoc DT prop, but that's also not a good idea I think. Do you have any suggestion for me please ?

One option is to use the device tree node name but it isn't very friendly - gpio0 at xxxxx.

That's what I do now pretty much.

Quoted 1 line

You could perhaps add a new property like 'bank-name'?

Do we want to add ad-hoc DT nodes which are
a) Not describing hardware
b) Not part of the official DT bindings for that platform ?

Is that really a way to go ?

Quoted 8 lines
Quoted 5 lines
Quoted 1 line

[...]

It needs to be part of the official binding. Naming the hardware is part of the hardware definition - see for example the regulator-name property for regulators.

So what do you think about introducing a 'bank-name' property then ? I think this might work just fine ?

I think it's OK - just make sure you send the GPIO binding change to Linux too.

Quoted 12 lines
Quoted 11 lines

Another option is to use an alias:

aliases {

   gpio0 = &gpio_0;
   gpio1 = &gpio_1;
   gpio2 = &gpio_2;

}

Then you can turn gpio0 into bank A, gpio1 into bank B, etc.

Quoted 8 lines
Quoted 2 lines

Is there a function which maps the udevice->dev->of_offset into an alias's seq ID ?

dev->seq, once it is probed. Until it is probed it doesn't have a sequence number (by definition).

You can use fdtdec_get_alias_seq() but I don't recommend it. We're trying to drop fdtdec eventually.

OK. I sent a V2, so that should be OK now.