summaryrefslogtreecommitdiff
path: root/cmd
diff options
context:
space:
mode:
authorTom Rini <[email protected]>2022-04-20 14:33:53 -0400
committerTom Rini <[email protected]>2022-04-20 14:33:53 -0400
commite2743c2aa0390f9590c13197cfee288a11b88dc0 (patch)
tree127dc4d0079353e6f5cb7df708bfc5bc5f348bb5 /cmd
parent246e03476ba325051600017b552460d7f37c3191 (diff)
parentdd2b8c1155d016800cbbaa1bd70efdd81f9da493 (diff)
Merge branch '2022-04-20-assorted-improvements'
- Two TI K3 updates, update SYS_MALLOC_F_LEN default to be 0x2000 and move TI am33xx to use that as well, fix DT relocation with multiple DRAM banks, and add a gpio read sub-command.
Diffstat (limited to 'cmd')
-rw-r--r--cmd/Kconfig7
-rw-r--r--cmd/gpio.c45
2 files changed, 49 insertions, 3 deletions
diff --git a/cmd/Kconfig b/cmd/Kconfig
index d3abe3a06bf..f580797d2d3 100644
--- a/cmd/Kconfig
+++ b/cmd/Kconfig
@@ -996,6 +996,13 @@ config CMD_GPIO
help
GPIO support.
+config CMD_GPIO_READ
+ bool "gpio read - save GPIO value to variable"
+ depends on CMD_GPIO
+ help
+ Enables the 'gpio read' command that saves the value
+ of a GPIO pin to a variable.
+
config CMD_PWM
bool "pwm"
depends on DM_PWM
diff --git a/cmd/gpio.c b/cmd/gpio.c
index 4150024e628..53e9ce666f9 100644
--- a/cmd/gpio.c
+++ b/cmd/gpio.c
@@ -12,6 +12,9 @@
#include <dm.h>
#include <log.h>
#include <malloc.h>
+#ifdef CONFIG_CMD_GPIO_READ
+#include <env.h>
+#endif
#include <asm/gpio.h>
#include <linux/err.h>
@@ -25,6 +28,9 @@ enum gpio_cmd {
GPIOC_SET,
GPIOC_CLEAR,
GPIOC_TOGGLE,
+#ifdef CONFIG_CMD_GPIO_READ
+ GPIOC_READ,
+#endif
};
#if defined(CONFIG_DM_GPIO) && !defined(gpio_status)
@@ -125,6 +131,9 @@ static int do_gpio(struct cmd_tbl *cmdtp, int flag, int argc,
enum gpio_cmd sub_cmd;
int value;
const char *str_cmd, *str_gpio = NULL;
+#ifdef CONFIG_CMD_GPIO_READ
+ const char *str_var = NULL;
+#endif
int ret;
#ifdef CONFIG_DM_GPIO
bool all = false;
@@ -137,12 +146,21 @@ static int do_gpio(struct cmd_tbl *cmdtp, int flag, int argc,
argc -= 2;
argv += 2;
#ifdef CONFIG_DM_GPIO
- if (argc > 0 && !strcmp(*argv, "-a")) {
+ if (argc > 0 && !strncmp(str_cmd, "status", 2) && !strcmp(*argv, "-a")) {
all = true;
argc--;
argv++;
}
#endif
+#ifdef CONFIG_CMD_GPIO_READ
+ if (argc > 0 && !strncmp(str_cmd, "read", 2)) {
+ if (argc < 2)
+ goto show_usage;
+ str_var = *argv;
+ argc--;
+ argv++;
+ }
+#endif
if (argc > 0)
str_gpio = *argv;
if (!strncmp(str_cmd, "status", 2)) {
@@ -174,6 +192,11 @@ static int do_gpio(struct cmd_tbl *cmdtp, int flag, int argc,
case 't':
sub_cmd = GPIOC_TOGGLE;
break;
+#ifdef CONFIG_CMD_GPIO_READ
+ case 'r':
+ sub_cmd = GPIOC_READ;
+ break;
+#endif
default:
goto show_usage;
}
@@ -205,7 +228,11 @@ static int do_gpio(struct cmd_tbl *cmdtp, int flag, int argc,
}
/* finally, let's do it: set direction and exec command */
- if (sub_cmd == GPIOC_INPUT) {
+ if (sub_cmd == GPIOC_INPUT
+#ifdef CONFIG_CMD_GPIO_READ
+ || sub_cmd == GPIOC_READ
+#endif
+ ) {
gpio_direction_input(gpio);
value = gpio_get_value(gpio);
} else {
@@ -233,9 +260,17 @@ static int do_gpio(struct cmd_tbl *cmdtp, int flag, int argc,
goto err;
} else {
printf("%d\n", value);
+#ifdef CONFIG_CMD_GPIO_READ
+ if (sub_cmd == GPIOC_READ)
+ env_set_ulong(str_var, (ulong)value);
+#endif
}
- if (sub_cmd != GPIOC_INPUT && !IS_ERR_VALUE(value)) {
+ if (sub_cmd != GPIOC_INPUT && !IS_ERR_VALUE(value)
+#ifdef CONFIG_CMD_GPIO_READ
+ && sub_cmd != GPIOC_READ
+#endif
+ ) {
int nval = gpio_get_value(gpio);
if (IS_ERR_VALUE(nval)) {
@@ -267,4 +302,8 @@ U_BOOT_CMD(gpio, 4, 0, do_gpio,
"query and control gpio pins",
"<input|set|clear|toggle> <pin>\n"
" - input/set/clear/toggle the specified pin\n"
+#ifdef CONFIG_CMD_GPIO_READ
+ "gpio read <name> <pin>\n"
+ " - set environment variable 'name' to the specified pin\n"
+#endif
"gpio status [-a] [<bank> | <pin>] - show [all/claimed] GPIOs");