Skip to contentSkip to conversation

gpio: dwapb_gpio: Add reset ctrl to driver

PATCH Superseded Ley Foon Tan 3 participants 9 messages Aug 15, 2018 – Sep 4, 2018 GPIO

v1 of 5 Superseded Latest is v5 →

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 gpio: dwapb_gpio: Add reset ctrl to driver

Add code to reset all reset signals as in gpio DT node. A reset property is an optional feature, so only print out a warning and do not fail if a reset property is not present.

If a reset property is discovered, then use it to deassert, thus bringing the IP out of reset.

---
 drivers/gpio/dwapb_gpio.c | 17 +++++++++++++++++
 1 file changed, 17 insertions(+)
drivers/gpio/dwapb_gpio.c +17 -0
index 3b5c181..e2b6e69 100644
@@ -15,6 +15,7 @@
 #include <dm/lists.h>
 #include <dm/root.h>
 #include <errno.h>
+#include <reset.h>
 
 DECLARE_GLOBAL_DATA_PTR;
 
@@ -114,6 +115,20 @@ static int gpio_dwapb_probe(struct udevice *dev)
 	return 0;
 }
 
+static void gpio_dwapb_reset(struct udevice *dev)
+{
+	struct reset_ctl_bulk reset_bulk;
+	int ret;
+
+	ret = reset_get_bulk(dev, &reset_bulk);
+	if (ret) {
+		dev_warn(dev, "Can't get reset: %d\n", ret);
+		return;
+	}
+
+	reset_deassert_bulk(&reset_bulk);
+}
+
 static int gpio_dwapb_bind(struct udevice *dev)
 {
 	struct gpio_dwapb_platdata *plat = dev_get_platdata(dev);
@@ -126,6 +141,8 @@ static int gpio_dwapb_bind(struct udevice *dev)
 	if (plat)
 		return 0;
 
+	gpio_dwapb_reset(dev);
+
 	base = dev_read_addr(dev);
 	if (base == FDT_ADDR_T_NONE) {
 		debug("Can't get the GPIO register base address\n");
Signature · 1 line
2.2.2
#1 lore raw

PATCH 1/1 gpio: dwapb_gpio: Add reset ctrl to driver

Quoted 46 lines · Ley Foon Tan

Add code to reset all reset signals as in gpio DT node. A reset property is an optional feature, so only print out a warning and do not fail if a reset property is not present.

If a reset property is discovered, then use it to deassert, thus bringing the IP out of reset.

---
 drivers/gpio/dwapb_gpio.c | 17 +++++++++++++++++
 1 file changed, 17 insertions(+)
drivers/gpio/dwapb_gpio.c +15 -0
index 3b5c181..e2b6e69 100644
@@ -15,6 +15,7 @@
 #include <dm/lists.h>
 #include <dm/root.h>
 #include <errno.h>
+#include <reset.h>
 
 DECLARE_GLOBAL_DATA_PTR;
 
@@ -114,6 +115,20 @@ static int gpio_dwapb_probe(struct udevice *dev)
 	return 0;
 }
 
+static void gpio_dwapb_reset(struct udevice *dev)
+{
+	struct reset_ctl_bulk reset_bulk;
+	int ret;
+
+	ret = reset_get_bulk(dev, &reset_bulk);
+	if (ret) {
+		dev_warn(dev, "Can't get reset: %d\n", ret);
+		return;
+	}
+
+	reset_deassert_bulk(&reset_bulk);
+}
+
 static int gpio_dwapb_bind(struct udevice *dev)
 {
 	struct gpio_dwapb_platdata *plat = dev_get_platdata(dev);

drivers/gpio/dwapb_gpio.c static int gpio_dwapb_bind(struct udevice *dev) · line 144

Quoted 4 lines
drivers/gpio/dwapb_gpio.c +1 -0
@@ -126,6 +141,8 @@ static int gpio_dwapb_bind(struct udevice *dev)
 	if (plat)
 		return 0;
 
+	gpio_dwapb_reset(dev);

This should be done in probe, not bind. Also, it should be undone in .remove.

Quoted 4 lines
drivers/gpio/dwapb_gpio.c +0 -0
 	base = dev_read_addr(dev);
 	if (base == FDT_ADDR_T_NONE) {
 		debug("Can't get the GPIO register base address\n");
Signature · 2 lines
Best regards,
Marek Vasut
#2 lore raw

PATCH 1/1 gpio: dwapb_gpio: Change to use dev_read_addr()

In reply to Ley Foon Tan

This changes the driver to use dev_read_addr() which is safe both for flat trees and live trees.

---
 drivers/gpio/dwapb_gpio.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/gpio/dwapb_gpio.c +1 -1
index a118f58..680b11a 100644
@@ -111,7 +111,7 @@ static int gpio_dwapb_bind(struct udevice *dev)
 	if (plat)
 		return 0;
 
-	base = fdtdec_get_addr(blob, dev_of_offset(dev), "reg");
+	base = dev_read_addr(dev);
 	if (base == FDT_ADDR_T_NONE) {
 		debug("Can't get the GPIO register base address\n");
 		return -ENXIO;
Signature · 1 line
2.2.2
#3 lore raw

PATCH 1/1 gpio: dwapb_gpio: Change to use dev_read_addr()

Quoted 4 lines · Ley Foon Tan

This changes the driver to use dev_read_addr() which is safe both for flat trees and live trees.

Quoted 18 lines
---
 drivers/gpio/dwapb_gpio.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/gpio/dwapb_gpio.c +1 -1
index a118f58..680b11a 100644
@@ -111,7 +111,7 @@ static int gpio_dwapb_bind(struct udevice *dev)
 	if (plat)
 		return 0;
 
-	base = fdtdec_get_addr(blob, dev_of_offset(dev), "reg");
+	base = dev_read_addr(dev);
 	if (base == FDT_ADDR_T_NONE) {
 		debug("Can't get the GPIO register base address\n");
 		return -ENXIO;
Signature · 2 lines
Best regards,
Marek Vasut
#4 lore raw

PATCH 1/1 gpio: dwapb_gpio: Change to use dev_read_addr()

Quoted 21 lines · Marek Vasut
Quoted 4 lines · Ley Foon Tan

This changes the driver to use dev_read_addr() which is safe both for flat trees and live trees.

Quoted 12 lines
---
 drivers/gpio/dwapb_gpio.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/gpio/dwapb_gpio.c +0 -0
index a118f58..680b11a 100644
@@ -111,7 +111,7 @@ static int gpio_dwapb_bind(struct udevice *dev)
      if (plat)
              return 0;
 
Quoted 9 lines

drivers/gpio/dwapb_gpio.c static int gpio_dwapb_bind(struct udevice *dev) · line 117

Quoted 6 lines
drivers/gpio/dwapb_gpio.c +1 -1
-     base = fdtdec_get_addr(blob, dev_of_offset(dev), "reg");
+     base = dev_read_addr(dev);
      if (base == FDT_ADDR_T_NONE) {
              debug("Can't get the GPIO register base address\n");
              return -ENXIO;

--

Hi Marek

Do you merge this patch too?

Regards
Ley Foon

Applied
#5 lore raw

PATCH 1/1 gpio: dwapb_gpio: Change to use dev_read_addr()

In reply to Ley Foon Tan
Quoted 14 lines · Ley Foon Tan

This changes the driver to use dev_read_addr() which is safe both for flat trees and live trees.

---
 drivers/gpio/dwapb_gpio.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/gpio/dwapb_gpio.c +0 -0
index a118f58..680b11a 100644

drivers/gpio/dwapb_gpio.c static int gpio_dwapb_bind(struct udevice *dev) · line 117

Quoted 8 lines
drivers/gpio/dwapb_gpio.c +1 -1
@@ -111,7 +111,7 @@ static int gpio_dwapb_bind(struct udevice *dev)
 	if (plat)
 		return 0;
 
-	base = fdtdec_get_addr(blob, dev_of_offset(dev), "reg");
+	base = dev_read_addr(dev);
 	if (base == FDT_ADDR_T_NONE) {
 		debug("Can't get the GPIO register base address\n");
 		return -ENXIO;

Applied, thanks.

Signature · 2 lines
Best regards,
Marek Vasut
#6 lore raw

PATCH 1/1 gpio: dwapb_gpio: Enable get_function support

In reply to Ley Foon Tan

Enabled get_function support for dwapb where the function will return the state of GPIO port.

---
 drivers/gpio/dwapb_gpio.c | 15 +++++++++++++++
 1 file changed, 15 insertions(+)
drivers/gpio/dwapb_gpio.c +15 -0
index 680b11a..3b5c181 100644
@@ -78,11 +78,26 @@ static int dwapb_gpio_set_value(struct udevice *dev, unsigned pin, int val)
 	return 0;
 }
 
+static int dwapb_gpio_get_function(struct udevice *dev, unsigned offset)
+{
+	struct gpio_dwapb_platdata *plat = dev_get_platdata(dev);
+	int gpio;
+
+	gpio = readl(plat->base + GPIO_SWPORT_DDR(plat->bank));
+	gpio = (gpio >> offset) & 1;
+
+	if (gpio)
+		return GPIOF_OUTPUT;
+	else
+		return GPIOF_INPUT;
+}
+
 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,
+	.get_function		= dwapb_gpio_get_function,
 };
 
 static int gpio_dwapb_probe(struct udevice *dev)
Signature · 1 line
2.2.2
#7 lore raw

PATCH 1/1 gpio: dwapb_gpio: Enable get_function support

Quoted 16 lines · Ley Foon Tan

Enabled get_function support for dwapb where the function will return the state of GPIO port.

---
 drivers/gpio/dwapb_gpio.c | 15 +++++++++++++++
 1 file changed, 15 insertions(+)
drivers/gpio/dwapb_gpio.c +0 -0
index 680b11a..3b5c181 100644
@@ -78,11 +78,26 @@ static int dwapb_gpio_set_value(struct udevice *dev, unsigned pin, int val)
 	return 0;
 }

drivers/gpio/dwapb_gpio.c static int dwapb_gpio_set_value(struct udevice *dev, unsigned pin, int val) · line 89

Quoted 10 lines
drivers/gpio/dwapb_gpio.c +9 -0
 
+static int dwapb_gpio_get_function(struct udevice *dev, unsigned offset)
+{
+	struct gpio_dwapb_platdata *plat = dev_get_platdata(dev);
+	int gpio;
+
+	gpio = readl(plat->base + GPIO_SWPORT_DDR(plat->bank));
+	gpio = (gpio >> offset) & 1;
+
+	if (gpio)

if (gpio & BIT(offset)) ?

Quoted 15 lines
drivers/gpio/dwapb_gpio.c +6 -0
+		return GPIOF_OUTPUT;
+	else
+		return GPIOF_INPUT;
+}
+
 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,
+	.get_function		= dwapb_gpio_get_function,
 };
 
 static int gpio_dwapb_probe(struct udevice *dev)
Signature · 2 lines
Best regards,
Marek Vasut
#8 lore raw

PATCH 1/1 gpio: dwapb_gpio: Enable get_function support

Quoted 18 lines · Marek Vasut
Quoted 17 lines · Ley Foon Tan

Enabled get_function support for dwapb where the function will return the state of GPIO port.

---
 drivers/gpio/dwapb_gpio.c | 15 +++++++++++++++
 1 file changed, 15 insertions(+)
drivers/gpio/dwapb_gpio.c +0 -0
index 680b11a..3b5c181 100644
@@ -78,11 +78,26 @@ static int dwapb_gpio_set_value(struct udevice *dev, unsigned pin, int val)
      return 0;
 }
 
Quoted 11 lines

drivers/gpio/dwapb_gpio.c static int dwapb_gpio_set_value(struct udevice *dev, unsigned pin, int val) · line 89

Quoted 9 lines
drivers/gpio/dwapb_gpio.c +9 -0
+static int dwapb_gpio_get_function(struct udevice *dev, unsigned offset)
+{
+     struct gpio_dwapb_platdata *plat = dev_get_platdata(dev);
+     int gpio;
+
+     gpio = readl(plat->base + GPIO_SWPORT_DDR(plat->bank));
+     gpio = (gpio >> offset) & 1;
+
+     if (gpio)

if (gpio & BIT(offset)) ?

Will change this.

Quoted 14 lines
Quoted 14 lines
drivers/gpio/dwapb_gpio.c +6 -0
+             return GPIOF_OUTPUT;
+     else
+             return GPIOF_INPUT;
+}
+
 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,
+     .get_function           = dwapb_gpio_get_function,
 };
 
Quoted 4 lines

drivers/gpio/dwapb_gpio.c static int dwapb_gpio_set_value(struct udevice *dev, unsigned pin, int val) · line 103

Quoted 2 lines
drivers/gpio/dwapb_gpio.c +0 -0
 static int gpio_dwapb_probe(struct udevice *dev)

Regards
Ley Foon