Re: [U-Boot] [PATCH v8 13/14] dm: Enable gpio command to support driver model

2014-02-26 Thread Tom Rini
On Mon, Feb 17, 2014 at 03:06:47PM -0700, Simon Glass wrote:

 Now that named GPIO banks are supported, along with a way of obtaining
 the status of a GPIO (input or output), we can provide an enhanced
 GPIO command for driver model. Where the driver provides its own operation
 for obtaining the GPIO state, this is used, otherwise a generic version
 is sufficient.
[snip]
 +#if defined(CONFIG_DM_GPIO)
 + /*
 +  * TODO(s...@chromium.org): Convert this code over to use the GPIO
 +  * uclass interface instead of the numbered GPIO compatibility
 +  * layer.
 +  */
 + ret = gpio_lookup_name(str_gpio, NULL, NULL, gpio);
 + if (ret)
 + return cmd_process_error(cmdtp, ret);

Since this is part of the initial lets show DM code shouldn't we do
this TODO before merging?

-- 
Tom


signature.asc
Description: Digital signature
___
U-Boot mailing list
U-Boot@lists.denx.de
http://lists.denx.de/mailman/listinfo/u-boot


Re: [U-Boot] [PATCH v8 13/14] dm: Enable gpio command to support driver model

2014-02-26 Thread Simon Glass
Hi Tom,

On 26 February 2014 09:34, Tom Rini tr...@ti.com wrote:

 On Mon, Feb 17, 2014 at 03:06:47PM -0700, Simon Glass wrote:

  Now that named GPIO banks are supported, along with a way of obtaining
  the status of a GPIO (input or output), we can provide an enhanced
  GPIO command for driver model. Where the driver provides its own
 operation
  for obtaining the GPIO state, this is used, otherwise a generic version
  is sufficient.
 [snip]
  +#if defined(CONFIG_DM_GPIO)
  + /*
  +  * TODO(s...@chromium.org): Convert this code over to use the GPIO
  +  * uclass interface instead of the numbered GPIO compatibility
  +  * layer.
  +  */
  + ret = gpio_lookup_name(str_gpio, NULL, NULL, gpio);
  + if (ret)
  + return cmd_process_error(cmdtp, ret);

 Since this is part of the initial lets show DM code shouldn't we do
 this TODO before merging?


The problem is that this is generic code, which must work with and without
driver model. So we can't move the command code over to exclusively use
driver model until all GPIO drivers use driver model.

Regards,
Simon
___
U-Boot mailing list
U-Boot@lists.denx.de
http://lists.denx.de/mailman/listinfo/u-boot


Re: [U-Boot] [PATCH v8 13/14] dm: Enable gpio command to support driver model

2014-02-26 Thread Tom Rini
On Wed, Feb 26, 2014 at 10:21:15AM -0700, Simon Glass wrote:

 Hi Tom,
 
 On 26 February 2014 09:34, Tom Rini tr...@ti.com wrote:
 
  On Mon, Feb 17, 2014 at 03:06:47PM -0700, Simon Glass wrote:
 
   Now that named GPIO banks are supported, along with a way of obtaining
   the status of a GPIO (input or output), we can provide an enhanced
   GPIO command for driver model. Where the driver provides its own
  operation
   for obtaining the GPIO state, this is used, otherwise a generic version
   is sufficient.
  [snip]
   +#if defined(CONFIG_DM_GPIO)
   + /*
   +  * TODO(s...@chromium.org): Convert this code over to use the GPIO
   +  * uclass interface instead of the numbered GPIO compatibility
   +  * layer.
   +  */
   + ret = gpio_lookup_name(str_gpio, NULL, NULL, gpio);
   + if (ret)
   + return cmd_process_error(cmdtp, ret);
 
  Since this is part of the initial lets show DM code shouldn't we do
  this TODO before merging?
 
 
 The problem is that this is generic code, which must work with and without
 driver model. So we can't move the command code over to exclusively use
 driver model until all GPIO drivers use driver model.

OK, since we're inside a CONFIG_DM_GPIO can you just expand the comment
a little so it's clear it's blocked by further conversion?

-- 
Tom


signature.asc
Description: Digital signature
___
U-Boot mailing list
U-Boot@lists.denx.de
http://lists.denx.de/mailman/listinfo/u-boot


Re: [U-Boot] [PATCH v8 13/14] dm: Enable gpio command to support driver model

2014-02-26 Thread Simon Glass
Hi Tom,

On 26 February 2014 10:28, Tom Rini tr...@ti.com wrote:

 On Wed, Feb 26, 2014 at 10:21:15AM -0700, Simon Glass wrote:

  Hi Tom,
 
  On 26 February 2014 09:34, Tom Rini tr...@ti.com wrote:
 
   On Mon, Feb 17, 2014 at 03:06:47PM -0700, Simon Glass wrote:
  
Now that named GPIO banks are supported, along with a way of
 obtaining
the status of a GPIO (input or output), we can provide an enhanced
GPIO command for driver model. Where the driver provides its own
   operation
for obtaining the GPIO state, this is used, otherwise a generic
 version
is sufficient.
   [snip]
+#if defined(CONFIG_DM_GPIO)
+ /*
+  * TODO(s...@chromium.org): Convert this code over to use the
 GPIO
+  * uclass interface instead of the numbered GPIO compatibility
+  * layer.
+  */
+ ret = gpio_lookup_name(str_gpio, NULL, NULL, gpio);
+ if (ret)
+ return cmd_process_error(cmdtp, ret);
  
   Since this is part of the initial lets show DM code shouldn't we do
   this TODO before merging?
  
 
  The problem is that this is generic code, which must work with and
 without
  driver model. So we can't move the command code over to exclusively use
  driver model until all GPIO drivers use driver model.

 OK, since we're inside a CONFIG_DM_GPIO can you just expand the comment
 a little so it's clear it's blocked by further conversion?


Sure, I'll do that and retest, resend.

Regards,
Simon
___
U-Boot mailing list
U-Boot@lists.denx.de
http://lists.denx.de/mailman/listinfo/u-boot


[U-Boot] [PATCH v8 13/14] dm: Enable gpio command to support driver model

2014-02-17 Thread Simon Glass
Now that named GPIO banks are supported, along with a way of obtaining
the status of a GPIO (input or output), we can provide an enhanced
GPIO command for driver model. Where the driver provides its own operation
for obtaining the GPIO state, this is used, otherwise a generic version
is sufficient.

Signed-off-by: Simon Glass s...@chromium.org
---

Changes in v8: None
Changes in v7: None
Changes in v6: None
Changes in v5: None
Changes in v4: None
Changes in v3: None
Changes in v2: None

 common/cmd_gpio.c | 127 --
 1 file changed, 114 insertions(+), 13 deletions(-)

diff --git a/common/cmd_gpio.c b/common/cmd_gpio.c
index 47eee89..c6758c1 100644
--- a/common/cmd_gpio.c
+++ b/common/cmd_gpio.c
@@ -8,7 +8,7 @@
 
 #include common.h
 #include command.h
-
+#include dm.h
 #include asm/gpio.h
 
 #ifndef name_to_gpio
@@ -22,25 +22,115 @@ enum gpio_cmd {
GPIO_TOGGLE,
 };
 
+#if defined(CONFIG_DM_GPIO)  !defined(gpio_status)
+static const char * const gpio_function[] = {
+   input,
+   output,
+   unknown,
+};
+
+static void show_gpio(struct device *dev, const char *bank_name, int offset)
+{
+   struct dm_gpio_ops *ops = gpio_get_ops(dev);
+   char buf[80];
+   int ret;
+
+   *buf = '\0';
+   if (ops-get_state) {
+   ret = ops-get_state(dev, offset, buf, sizeof(buf));
+   if (ret) {
+   puts(unknown);
+   return;
+   }
+   } else {
+   int func =  GPIOF_UNKNOWN;
+   int ret;
+
+   if (ops-get_function) {
+   ret = ops-get_function(dev, offset);
+   if (ret = 0  ret  ARRAY_SIZE(gpio_function))
+   func = ret;
+   }
+   sprintf(buf, %s%u: %8s %d, bank_name, offset,
+   gpio_function[func], ops-get_value(dev, offset));
+   }
+
+   puts(buf);
+   puts(\n);
+}
+
+static int do_gpio_status(const char *gpio_name)
+{
+   struct device *dev;
+   int newline = 0;
+   int ret;
+
+   if (gpio_name  !*gpio_name)
+   gpio_name = NULL;
+   for (ret = uclass_first_device(UCLASS_GPIO, dev);
+dev;
+ret = uclass_next_device(dev)) {
+   const char *bank_name;
+   int num_bits;
+
+   bank_name = gpio_get_bank_info(dev, num_bits);
+
+   if (!gpio_name || !bank_name ||
+   !strncmp(gpio_name, bank_name, strlen(bank_name))) {
+   const char *p = NULL;
+   int offset;
+
+   if (bank_name) {
+   if (newline)
+   putc('\n');
+   printf(Bank %s:\n, bank_name);
+   }
+   newline = 1;
+   if (gpio_name  bank_name) {
+   p = gpio_name + strlen(bank_name);
+   offset = simple_strtoul(p, NULL, 10);
+   show_gpio(dev, bank_name, offset);
+   } else {
+   for (offset = 0; offset  num_bits; offset++)
+   show_gpio(dev, bank_name, offset);
+   }
+   }
+   }
+
+   return ret;
+}
+#endif
+
 static int do_gpio(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[])
 {
-   int gpio;
+   unsigned int gpio;
enum gpio_cmd sub_cmd;
ulong value;
-   const char *str_cmd, *str_gpio;
+   const char *str_cmd, *str_gpio = NULL;
+#ifdef CONFIG_DM_GPIO
+   int ret;
+#endif
 
+   if (argc  2)
+ show_usage:
+   return CMD_RET_USAGE;
+   str_cmd = argv[1];
+   if (argc  2)
+   str_gpio = argv[2];
+   if (!strcmp(str_cmd, status)) {
+   /* Support deprecated gpio_status() */
 #ifdef gpio_status
-   if (argc == 2  !strcmp(argv[1], status)) {
gpio_status();
return 0;
-   }
+#elif defined(CONFIG_DM_GPIO)
+   return cmd_process_error(cmdtp, do_gpio_status(str_gpio));
+#else
+   goto show_usage;
 #endif
+   }
 
-   if (argc != 3)
- show_usage:
-   return CMD_RET_USAGE;
-   str_cmd = argv[1];
-   str_gpio = argv[2];
+   if (!str_gpio)
+   goto show_usage;
 
/* parse the behavior */
switch (*str_cmd) {
@@ -51,11 +141,21 @@ static int do_gpio(cmd_tbl_t *cmdtp, int flag, int argc, 
char * const argv[])
default:  goto show_usage;
}
 
+#if defined(CONFIG_DM_GPIO)
+   /*
+* TODO(s...@chromium.org): Convert this code over to use the GPIO
+* uclass interface instead of the numbered GPIO compatibility
+* layer.
+*/
+   ret = gpio_lookup_name(str_gpio, NULL,