Re: [U-Boot] [PATCH v1] gpio: fixes for gpio-hog support

2019-07-29 Thread Tom Rini
On Wed, Jul 17, 2019 at 06:59:51AM +0200, Heiko Schocher wrote:

> recently added gpio hog patch was "in discussion"
> state with Simon Glass. This patch now adds most
> of comments from Simon Glass.
> 
> Signed-off-by: Heiko Schocher 

Applied to u-boot/master, thanks!

-- 
Tom


signature.asc
Description: PGP signature
___
U-Boot mailing list
U-Boot@lists.denx.de
https://lists.denx.de/listinfo/u-boot


[U-Boot] [PATCH v1] gpio: fixes for gpio-hog support

2019-07-16 Thread Heiko Schocher
recently added gpio hog patch was "in discussion"
state with Simon Glass. This patch now adds most
of comments from Simon Glass.

Signed-off-by: Heiko Schocher 

---
clean travis build, see result:
https://travis-ci.org/hsdenx/u-boot-test/builds/558774593

Based on mainline:
6070ef409c - Merge branch '2019-07-12-master-imports'

Tom applied version 4 of the patchset, but patch is
in discussion with Simon and I prepared already a v5

This patch includes now comments from Simon:
  - add example for line-name in Documentation
  - drop .gpio-hog suffix in Documentation
as not longer needed.
  - rework gpio_hog_lookup_name() which now returns
error code and pointer to gpio desc is passed.
  - rename DM_GPIO_HOG to GPIO_HOG
  - set device name only if line-name property is set
  - remove dm_gpio_set_dir() call as this is already done
through gpio_dev_request_index()
  - check some error codes
  - tried to add a comment to gpio_dev_request_index())
and renamed function paramter "dev" to "gpio_dev"
  - use IS_ENABLED()
  - fix comments for gpio_dev_request_index()
  - add warning if probing one gpio_hog fails and continue
with probing the next gpio hog.

not yet implemented:
- question if gpio_desc can be stored in private device
  data, but this can be fixed later.


 common/board_r.c   |   4 +-
 doc/device-tree-bindings/gpio/gpio.txt |  17 ++--
 drivers/gpio/Kconfig   |   2 +-
 drivers/gpio/gpio-uclass.c | 103 ++---
 include/asm-generic/gpio.h |  12 +--
 5 files changed, 96 insertions(+), 42 deletions(-)

diff --git a/common/board_r.c b/common/board_r.c
index abc31b17b8..e7ce11c30a 100644
--- a/common/board_r.c
+++ b/common/board_r.c
@@ -49,7 +49,7 @@
 #include 
 #include 
 #include 
-#if defined(CONFIG_DM_GPIO_HOG)
+#if defined(CONFIG_GPIO_HOG)
 #include 
 #endif
 
@@ -799,7 +799,7 @@ static init_fnc_t init_sequence_r[] = {
 #ifdef CONFIG_CMD_NET
initr_ethaddr,
 #endif
-#if defined(CONFIG_DM_GPIO_HOG)
+#if defined(CONFIG_GPIO_HOG)
gpio_hog_probe_all,
 #endif
 #ifdef CONFIG_BOARD_LATE_INIT
diff --git a/doc/device-tree-bindings/gpio/gpio.txt 
b/doc/device-tree-bindings/gpio/gpio.txt
index e774439369..e146917ff3 100644
--- a/doc/device-tree-bindings/gpio/gpio.txt
+++ b/doc/device-tree-bindings/gpio/gpio.txt
@@ -252,6 +252,7 @@ Example:
 boot_rescue {
 gpio-hog;
 input;
+line-name = "foo-bar-gpio";
 gpios = <7 GPIO_ACTIVE_LOW>;
 };
 };
@@ -259,9 +260,13 @@ Example:
 For the above Example you can than access the gpio in your boardcode
 with:
 
-desc = gpio_hog_lookup_name("boot_rescue.gpio-hog");
-if (desc) {
-if (dm_gpio_get_value(desc))
-printf("\nBooting into Rescue System\n");
-   else
-   printf("\nBoot normal\n");
+   struct gpio_desc *desc;
+   int ret;
+
+   ret = gpio_hog_lookup_name("boot_rescue", );
+   if (ret)
+   return;
+   if (dm_gpio_get_value(desc) == 1)
+   printf("\nBooting into Rescue System\n");
+   else if (dm_gpio_get_value(desc) == 0)
+   printf("\nBoot normal\n");
diff --git a/drivers/gpio/Kconfig b/drivers/gpio/Kconfig
index fa1c99700f..3f1a24013c 100644
--- a/drivers/gpio/Kconfig
+++ b/drivers/gpio/Kconfig
@@ -14,7 +14,7 @@ config DM_GPIO
  particular GPIOs that they provide. The uclass interface
  is defined in include/asm-generic/gpio.h.
 
-config DM_GPIO_HOG
+config GPIO_HOG
bool "Enable GPIO hog support"
depends on DM_GPIO
default n
diff --git a/drivers/gpio/gpio-uclass.c b/drivers/gpio/gpio-uclass.c
index 308d0863ad..01cfa2f788 100644
--- a/drivers/gpio/gpio-uclass.c
+++ b/drivers/gpio/gpio-uclass.c
@@ -144,7 +144,7 @@ static int gpio_find_and_xlate(struct gpio_desc *desc,
return gpio_xlate_offs_flags(desc->dev, desc, args);
 }
 
-#if defined(CONFIG_DM_GPIO_HOG)
+#if defined(CONFIG_GPIO_HOG)
 
 struct gpio_hog_priv {
struct gpio_desc gpiod;
@@ -181,9 +181,8 @@ static int gpio_hog_ofdata_to_platdata(struct udevice *dev)
return ret;
}
nodename = dev_read_string(dev, "line-name");
-   if (!nodename)
-   nodename = dev_read_name(dev);
-   device_set_name(dev, nodename);
+   if (nodename)
+   device_set_name(dev, nodename);
 
return 0;
 }
@@ -202,9 +201,15 @@ static int gpio_hog_probe(struct udevice *dev)
  dev->name);
return ret;
}
-   dm_gpio_set_dir(>gpiod);
-   if (plat->gpiod_flags == GPIOD_IS_OUT)
-   dm_gpio_set_value(>gpiod, plat->value);
+
+   if (plat->gpiod_flags == GPIOD_IS_OUT) {
+   ret = dm_gpio_set_value(>gpiod, plat->value);
+   if (ret < 0) {
+