efi_loader: type of efi_secure_mode
[oweals/u-boot.git] / cmd / gpio.c
index 8ce8ba909d4f5fe8e8c8b6e3dc4a208cc6a0bb02..4fdb3135fc1a47fd022c019bd6fada71e32e207d 100644 (file)
@@ -10,6 +10,7 @@
 #include <command.h>
 #include <errno.h>
 #include <dm.h>
+#include <log.h>
 #include <malloc.h>
 #include <asm/gpio.h>
 #include <linux/err.h>
@@ -117,7 +118,8 @@ static int do_gpio_status(bool all, const char *gpio_name)
 }
 #endif
 
-static int do_gpio(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[])
+static int do_gpio(struct cmd_tbl *cmdtp, int flag, int argc,
+                  char *const argv[])
 {
        unsigned int gpio;
        enum gpio_cmd sub_cmd;
@@ -225,23 +227,40 @@ static int do_gpio(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[])
                gpio_direction_output(gpio, value);
        }
        printf("gpio: pin %s (gpio %u) value is ", str_gpio, gpio);
-       if (IS_ERR_VALUE(value))
+
+       if (IS_ERR_VALUE(value)) {
                printf("unknown (ret=%d)\n", value);
-       else
+               goto err;
+       } else {
                printf("%d\n", value);
+       }
+
        if (sub_cmd != GPIOC_INPUT && !IS_ERR_VALUE(value)) {
                int nval = gpio_get_value(gpio);
 
-               if (IS_ERR_VALUE(nval))
+               if (IS_ERR_VALUE(nval)) {
                        printf("   Warning: no access to GPIO output value\n");
-               else if (nval != value)
+                       goto err;
+               } else if (nval != value) {
                        printf("   Warning: value of pin is still %d\n", nval);
+                       goto err;
+               }
        }
 
        if (ret != -EBUSY)
                gpio_free(gpio);
 
-       return value;
+       /*
+        * Whilst wrong, the legacy gpio input command returns the pin
+        * value, or CMD_RET_FAILURE (which is indistinguishable from a
+        * valid pin value).
+        */
+       return (sub_cmd == GPIOC_INPUT) ? value : CMD_RET_SUCCESS;
+
+err:
+       if (ret != -EBUSY)
+               gpio_free(gpio);
+       return CMD_RET_FAILURE;
 }
 
 U_BOOT_CMD(gpio, 4, 0, do_gpio,