Skip to contentSkip to conversation

gpio: dwapb_gpio: Add reset ctrl to driver

PATCH Superseded Ley Foon Tan 3 participants 7 messages Aug 16, 2018 GPIO

v2 of 5 Superseded Latest is v5 →

lore
Share & tools
lore
#0 lore raw

PATCH v2 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.

---
v2:
- Move reset to probe() function.

---
 drivers/gpio/dwapb_gpio.c | 20 +++++++++++++++++++-
 1 file changed, 19 insertions(+), 1 deletion(-)
drivers/gpio/dwapb_gpio.c +19 -1
index 7cf2d47..dfe1e6d 100644
@@ -15,6 +15,7 @@
 #include <dm/lists.h>
 #include <dm/root.h>
 #include <errno.h>
+#include <reset.h>
 
 DECLARE_GLOBAL_DATA_PTR;
 
@@ -99,13 +100,30 @@ static const struct dm_gpio_ops gpio_dwapb_ops = {
 	.get_function		= dwapb_gpio_get_function,
 };
 
+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_probe(struct udevice *dev)
 {
 	struct gpio_dev_priv *priv = dev_get_uclass_priv(dev);
 	struct gpio_dwapb_platdata *plat = dev->platdata;
 
-	if (!plat)
+	if (!plat) {
+		/* Reset on parent device only */
+		gpio_dwapb_reset(dev);
 		return 0;
+	}
 
 	priv->gpio_count = plat->pins;
 	priv->bank_name = plat->name;
Signature · 1 line
2.2.2
#1 lore raw

PATCH v2 1/1 gpio: dwapb_gpio: Enable get_function support

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

---
v2: Change to use "if (gpio & BIT(offset))" bit masking.

---
 drivers/gpio/dwapb_gpio.c | 14 ++++++++++++++
 1 file changed, 14 insertions(+)
drivers/gpio/dwapb_gpio.c +14 -0
index 680b11a..7cf2d47 100644
@@ -78,11 +78,25 @@ 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);
+	u32 gpio;
+
+	gpio = readl(plat->base + GPIO_SWPORT_DDR(plat->bank));
+
+	if (gpio & BIT(offset))
+		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
#2 lore raw

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

In reply to Ley Foon Tan
Quoted 51 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.

---
v2:
- Move reset to probe() function.

---
 drivers/gpio/dwapb_gpio.c | 20 +++++++++++++++++++-
 1 file changed, 19 insertions(+), 1 deletion(-)
drivers/gpio/dwapb_gpio.c +15 -0
index 7cf2d47..dfe1e6d 100644
@@ -15,6 +15,7 @@
 #include <dm/lists.h>
 #include <dm/root.h>
 #include <errno.h>
+#include <reset.h>
 
 DECLARE_GLOBAL_DATA_PTR;
 
@@ -99,13 +100,30 @@ static const struct dm_gpio_ops gpio_dwapb_ops = {
 	.get_function		= dwapb_gpio_get_function,
 };
 
+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_probe(struct udevice *dev)
 {
 	struct gpio_dev_priv *priv = dev_get_uclass_priv(dev);
 	struct gpio_dwapb_platdata *plat = dev->platdata;

drivers/gpio/dwapb_gpio.c static const struct dm_gpio_ops gpio_dwapb_ops = { · line 129

Quoted 10 lines
drivers/gpio/dwapb_gpio.c +4 -1
 
-	if (!plat)
+	if (!plat) {
+		/* Reset on parent device only */
+		gpio_dwapb_reset(dev);
 		return 0;
+	}
 
 	priv->gpio_count = plat->pins;
 	priv->bank_name = plat->name;

What about .remove() and reset_release ?

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

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

Quoted 59 lines · Marek Vasut
Quoted 58 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.

---
v2:
- Move reset to probe() function.

---
 drivers/gpio/dwapb_gpio.c | 20 +++++++++++++++++++-
 1 file changed, 19 insertions(+), 1 deletion(-)
drivers/gpio/dwapb_gpio.c +19 -1
index 7cf2d47..dfe1e6d 100644
@@ -15,6 +15,7 @@
 #include <dm/lists.h>
 #include <dm/root.h>
 #include <errno.h>
+#include <reset.h>
 
 DECLARE_GLOBAL_DATA_PTR;
 
@@ -99,13 +100,30 @@ static const struct dm_gpio_ops gpio_dwapb_ops = {
      .get_function           = dwapb_gpio_get_function,
 };
 
+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_probe(struct udevice *dev)
 {
      struct gpio_dev_priv *priv = dev_get_uclass_priv(dev);
      struct gpio_dwapb_platdata *plat = dev->platdata;
 
-     if (!plat)
+     if (!plat) {
+             /* Reset on parent device only */
+             gpio_dwapb_reset(dev);
              return 0;
+     }
 
Quoted 5 lines

drivers/gpio/dwapb_gpio.c static const struct dm_gpio_ops gpio_dwapb_ops = { · line 129

Quoted 3 lines
drivers/gpio/dwapb_gpio.c +0 -0
      priv->gpio_count = plat->pins;
      priv->bank_name = plat->name;

What about .remove() and reset_release ?

This driver doesn't implement .remove, should we add this to assert reset?

Regards
Ley Foon

#4 lore raw

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

Quoted 60 lines · Ley Foon Tan
Quoted 59 lines · Marek Vasut
Quoted 58 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.

---
v2:
- Move reset to probe() function.

---
 drivers/gpio/dwapb_gpio.c | 20 +++++++++++++++++++-
 1 file changed, 19 insertions(+), 1 deletion(-)
drivers/gpio/dwapb_gpio.c +19 -1
index 7cf2d47..dfe1e6d 100644
@@ -15,6 +15,7 @@
 #include <dm/lists.h>
 #include <dm/root.h>
 #include <errno.h>
+#include <reset.h>
 
 DECLARE_GLOBAL_DATA_PTR;
 
@@ -99,13 +100,30 @@ static const struct dm_gpio_ops gpio_dwapb_ops = {
      .get_function           = dwapb_gpio_get_function,
 };
 
+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_probe(struct udevice *dev)
 {
      struct gpio_dev_priv *priv = dev_get_uclass_priv(dev);
      struct gpio_dwapb_platdata *plat = dev->platdata;
 
-     if (!plat)
+     if (!plat) {
+             /* Reset on parent device only */
+             gpio_dwapb_reset(dev);
              return 0;
+     }
 
Quoted 6 lines
Quoted 5 lines

drivers/gpio/dwapb_gpio.c static const struct dm_gpio_ops gpio_dwapb_ops = { · line 129

Quoted 3 lines
drivers/gpio/dwapb_gpio.c +0 -0
      priv->gpio_count = plat->pins;
      priv->bank_name = plat->name;

What about .remove() and reset_release ?

This driver doesn't implement .remove, should we add this to assert reset?

Yes

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

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

Quoted 61 lines · Marek Vasut
Quoted 60 lines · Ley Foon Tan
Quoted 59 lines · Marek Vasut
Quoted 58 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.

---
v2:
- Move reset to probe() function.

---
 drivers/gpio/dwapb_gpio.c | 20 +++++++++++++++++++-
 1 file changed, 19 insertions(+), 1 deletion(-)
drivers/gpio/dwapb_gpio.c +19 -1
index 7cf2d47..dfe1e6d 100644
@@ -15,6 +15,7 @@
 #include <dm/lists.h>
 #include <dm/root.h>
 #include <errno.h>
+#include <reset.h>
 
 DECLARE_GLOBAL_DATA_PTR;
 
@@ -99,13 +100,30 @@ static const struct dm_gpio_ops gpio_dwapb_ops = {
      .get_function           = dwapb_gpio_get_function,
 };
 
+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_probe(struct udevice *dev)
 {
      struct gpio_dev_priv *priv = dev_get_uclass_priv(dev);
      struct gpio_dwapb_platdata *plat = dev->platdata;
 
-     if (!plat)
+     if (!plat) {
+             /* Reset on parent device only */
+             gpio_dwapb_reset(dev);
              return 0;
+     }
 
Quoted 8 lines
Quoted 6 lines
Quoted 5 lines

drivers/gpio/dwapb_gpio.c static const struct dm_gpio_ops gpio_dwapb_ops = { · line 129

Quoted 3 lines
drivers/gpio/dwapb_gpio.c +0 -0
      priv->gpio_count = plat->pins;
      priv->bank_name = plat->name;

What about .remove() and reset_release ?

This driver doesn't implement .remove, should we add this to assert reset?

Yes

Okay, will try to add it.

BTW, when .remove will be call in Uboot?

Regards
Ley Foon

#6 lore raw

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

Quoted 67 lines · Ley Foon Tan
Quoted 66 lines · Marek Vasut
Quoted 65 lines · Ley Foon Tan
Quoted 64 lines · Marek Vasut
Quoted 51 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.

---
v2:
- Move reset to probe() function.

---
 drivers/gpio/dwapb_gpio.c | 20 +++++++++++++++++++-
 1 file changed, 19 insertions(+), 1 deletion(-)
drivers/gpio/dwapb_gpio.c +15 -0
index 7cf2d47..dfe1e6d 100644
@@ -15,6 +15,7 @@
 #include <dm/lists.h>
 #include <dm/root.h>
 #include <errno.h>
+#include <reset.h>
 
 DECLARE_GLOBAL_DATA_PTR;
 
@@ -99,13 +100,30 @@ static const struct dm_gpio_ops gpio_dwapb_ops = {
      .get_function           = dwapb_gpio_get_function,
 };
 
+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_probe(struct udevice *dev)
 {
      struct gpio_dev_priv *priv = dev_get_uclass_priv(dev);
      struct gpio_dwapb_platdata *plat = dev->platdata;

drivers/gpio/dwapb_gpio.c static const struct dm_gpio_ops gpio_dwapb_ops = { · line 129

Quoted 10 lines
drivers/gpio/dwapb_gpio.c +4 -1
 
-     if (!plat)
+     if (!plat) {
+             /* Reset on parent device only */
+             gpio_dwapb_reset(dev);
              return 0;
+     }
 
      priv->gpio_count = plat->pins;
      priv->bank_name = plat->name;

What about .remove() and reset_release ?

Quoted 6 lines
Quoted 3 lines
Quoted 1 line

This driver doesn't implement .remove, should we add this to assert reset?

Yes

Okay, will try to add it.

BTW, when .remove will be call in Uboot?

When removing the driver and possibly before booting Linux.

Signature · 2 lines
Best regards,
Marek Vasut