[U-Boot] [PATCH] 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.
Signed-off-by: Ley Foon Tan ley.foon.tan@intel.com --- drivers/gpio/dwapb_gpio.c | 17 +++++++++++++++++ 1 file changed, 17 insertions(+)
diff --git a/drivers/gpio/dwapb_gpio.c b/drivers/gpio/dwapb_gpio.c index 3b5c181..e2b6e69 100644 --- a/drivers/gpio/dwapb_gpio.c +++ b/drivers/gpio/dwapb_gpio.c @@ -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");

On 08/15/2018 08:05 PM, Ley Foon Tan wrote:
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.
Signed-off-by: Ley Foon Tan ley.foon.tan@intel.com
drivers/gpio/dwapb_gpio.c | 17 +++++++++++++++++ 1 file changed, 17 insertions(+)
diff --git a/drivers/gpio/dwapb_gpio.c b/drivers/gpio/dwapb_gpio.c index 3b5c181..e2b6e69 100644 --- a/drivers/gpio/dwapb_gpio.c +++ b/drivers/gpio/dwapb_gpio.c @@ -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);
This should be done in probe, not bind. Also, it should be undone in .remove.
base = dev_read_addr(dev); if (base == FDT_ADDR_T_NONE) { debug("Can't get the GPIO register base address\n");

This changes the driver to use dev_read_addr() which is safe both for flat trees and live trees.
Signed-off-by: Ley Foon Tan ley.foon.tan@intel.com --- drivers/gpio/dwapb_gpio.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/drivers/gpio/dwapb_gpio.c b/drivers/gpio/dwapb_gpio.c index a118f58..680b11a 100644 --- a/drivers/gpio/dwapb_gpio.c +++ b/drivers/gpio/dwapb_gpio.c @@ -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;

On 08/15/2018 08:05 PM, Ley Foon Tan wrote:
This changes the driver to use dev_read_addr() which is safe both for flat trees and live trees.
Signed-off-by: Ley Foon Tan ley.foon.tan@intel.com
Acked-by: Marek Vasut marex@denx.de
drivers/gpio/dwapb_gpio.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/drivers/gpio/dwapb_gpio.c b/drivers/gpio/dwapb_gpio.c index a118f58..680b11a 100644 --- a/drivers/gpio/dwapb_gpio.c +++ b/drivers/gpio/dwapb_gpio.c @@ -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;

On Wed, Aug 15, 2018 at 6:14 PM Marek Vasut marex@denx.de wrote:
On 08/15/2018 08:05 PM, Ley Foon Tan wrote:
This changes the driver to use dev_read_addr() which is safe both for flat trees and live trees.
Signed-off-by: Ley Foon Tan ley.foon.tan@intel.com
Acked-by: Marek Vasut marex@denx.de
drivers/gpio/dwapb_gpio.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/drivers/gpio/dwapb_gpio.c b/drivers/gpio/dwapb_gpio.c index a118f58..680b11a 100644 --- a/drivers/gpio/dwapb_gpio.c +++ b/drivers/gpio/dwapb_gpio.c @@ -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;
--
Hi Marek
Do you merge this patch too?
Regards Ley Foon

On 08/15/2018 08:05 PM, Ley Foon Tan wrote:
This changes the driver to use dev_read_addr() which is safe both for flat trees and live trees.
Signed-off-by: Ley Foon Tan ley.foon.tan@intel.com
drivers/gpio/dwapb_gpio.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/drivers/gpio/dwapb_gpio.c b/drivers/gpio/dwapb_gpio.c index a118f58..680b11a 100644 --- a/drivers/gpio/dwapb_gpio.c +++ b/drivers/gpio/dwapb_gpio.c @@ -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.

Enabled get_function support for dwapb where the function will return the state of GPIO port.
Signed-off-by: Chin Liang See chin.liang.see@intel.com Signed-off-by: Ley Foon Tan ley.foon.tan@intel.com --- drivers/gpio/dwapb_gpio.c | 15 +++++++++++++++ 1 file changed, 15 insertions(+)
diff --git a/drivers/gpio/dwapb_gpio.c b/drivers/gpio/dwapb_gpio.c index 680b11a..3b5c181 100644 --- a/drivers/gpio/dwapb_gpio.c +++ b/drivers/gpio/dwapb_gpio.c @@ -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)

On 08/15/2018 08:05 PM, Ley Foon Tan wrote:
Enabled get_function support for dwapb where the function will return the state of GPIO port.
Signed-off-by: Chin Liang See chin.liang.see@intel.com Signed-off-by: Ley Foon Tan ley.foon.tan@intel.com
drivers/gpio/dwapb_gpio.c | 15 +++++++++++++++ 1 file changed, 15 insertions(+)
diff --git a/drivers/gpio/dwapb_gpio.c b/drivers/gpio/dwapb_gpio.c index 680b11a..3b5c181 100644 --- a/drivers/gpio/dwapb_gpio.c +++ b/drivers/gpio/dwapb_gpio.c @@ -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)
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)

On Wed, Aug 15, 2018 at 6:12 PM, Marek Vasut marex@denx.de wrote:
On 08/15/2018 08:05 PM, Ley Foon Tan wrote:
Enabled get_function support for dwapb where the function will return the state of GPIO port.
Signed-off-by: Chin Liang See chin.liang.see@intel.com Signed-off-by: Ley Foon Tan ley.foon.tan@intel.com
drivers/gpio/dwapb_gpio.c | 15 +++++++++++++++ 1 file changed, 15 insertions(+)
diff --git a/drivers/gpio/dwapb_gpio.c b/drivers/gpio/dwapb_gpio.c index 680b11a..3b5c181 100644 --- a/drivers/gpio/dwapb_gpio.c +++ b/drivers/gpio/dwapb_gpio.c @@ -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)
if (gpio & BIT(offset)) ?
Will change this.
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)
Regards Ley Foon
participants (3)
-
Ley Foon Tan
-
Ley Foon Tan
-
Marek Vasut