Skip to contentSkip to conversation

Allow GPIOs to be referenced by label

PATCH In review Andrey Smirnov 3 participants 19 messages Oct 27, 2018 – Nov 6, 2018

Subsystems (6)
lore
Share & tools
lore
#0 lore raw

cover Allow GPIOs to be referenced by label

Everyone:

This patch series is the result of my work on extending various gpio_* commands in Barebox CLI to allow referencing GPIOs by a label assigned to them via Device Tree or in any other way.

Sascha:

AFAICT majority of callers of simple_strto*() functions don't really do very strict error checking which seems really undesirable. With kstrto*() functions in place, and assuming there's no objections to that, what do you think about a separate patch series to replace all of the uses of simple_strto*() with kstrto*() and eventually drop majority of simple_strto*() implementation code?

Thanks,
Andrey Smirnov

Andrey Smirnov (11):
gpio: VF610: Propagate error code of gpiochip_add() up
VF610: Initialize pinctrl driver before gpio linux/ctype.h: Port _tolower()
lib: Port kstrtox.c from Linux kernel
commands: gpio: Move argument parsing into a shared function
commands: gpio: Use kstrtoint() instead of simple_strtoul()
gpiolib: Introduce gpio_find_by_label()
commands: gpio: Allow GPIOs to be specified by label
VF610: zii-vf610-dev: Drop switch reset GPIO configuration
VF610: zii-vf610-dev: Replace board code with gpio-hog nodes
ARM: rdu2: Replace board code with gpio-hog nodes

 arch/arm/boards/zii-imx6q-rdu2/board.c |  38 ---
 arch/arm/boards/zii-vf610-dev/board.c  |  61 -----
 arch/arm/dts/imx6qdl-zii-rdu2.dtsi     |  36 +++
 arch/arm/dts/vf610-zii-cfu1.dts        |  25 ++
 arch/arm/dts/vf610-zii-ssmb-spu3.dts   |   9 +
 commands/gpio.c                        |  54 ++--
 drivers/gpio/gpio-vf610.c              |   5 +-
 drivers/gpio/gpiolib.c                 |  17 ++
 drivers/pinctrl/pinctrl-vf610.c        |   2 +-
 include/gpio.h                         |   6 +
 include/linux/ctype.h                  |   9 +
 include/linux/kernel.h                 |  95 +++++++
 include/linux/string.h                 |   2 +
 lib/Makefile                           |   1 +
 lib/kstrtox.c                          | 366 +++++++++++++++++++++++++
 lib/kstrtox.h                          |   9 +
 16 files changed, 613 insertions(+), 122 deletions(-)
 create mode 100644 lib/kstrtox.c
 create mode 100644 lib/kstrtox.h
Signature · 7 lines
2.17.1


_______________________________________________
barebox mailing list
[email protected]
http://lists.infradead.org/mailman/listinfo/barebox
#1 lore raw

PATCH 1/11 gpio: VF610: Propagate error code of gpiochip_add() up

Propagate error code of gpiochip_add() up the call chain. This won't do any meaningful cleanup, but at least it will make problems noticable.

---
 drivers/gpio/gpio-vf610.c | 3 +--
 1 file changed, 1 insertion(+), 2 deletions(-)
drivers/gpio/gpio-vf610.c +1 -2
index 2aff62be5..9ac838f3b 100644
@@ -142,9 +142,8 @@ static int vf610_gpio_probe(struct device_d *dev)
 
 	port->chip.base *= VF610_GPIO_PER_PORT;
 	port->chip.dev = dev;
-	gpiochip_add(&port->chip);
 
-	return 0;
+	return gpiochip_add(&port->chip);
 
 free_port:
 	free(port);
Signature · 7 lines
2.17.1


_______________________________________________
barebox mailing list
[email protected]
http://lists.infradead.org/mailman/listinfo/barebox
#2 lore raw

PATCH 2/11 VF610: Initialize pinctrl driver before gpio

In reply to Andrey Smirnov

GPIO driver on VF610 depends on functionality implemented by pinctrl driver in its gpio_direction_*() calls. The proboing status quo works fine for post-initcall scenarious, but in order for gpio-hogs to be processed correctly we need to have pinctrl driver present by the time GPIO driver is being probed.

Move GPIO driver to 'postcore' and pinctrl to 'core' to fix this issue.

---
 drivers/gpio/gpio-vf610.c       | 2 +-
 drivers/pinctrl/pinctrl-vf610.c | 2 +-
 2 files changed, 2 insertions(+), 2 deletions(-)
drivers/gpio/gpio-vf610.c +1 -1
index 9ac838f3b..ab35310fb 100644
@@ -160,4 +160,4 @@ static int __init gpio_vf610_init(void)
 {
 	return platform_driver_register(&vf610_gpio_driver);
 }
-core_initcall(gpio_vf610_init);
+postcore_initcall(gpio_vf610_init);
drivers/pinctrl/pinctrl-vf610.c +1 -1
index a46b0e2ca..662fa9b6c 100644
@@ -165,4 +165,4 @@ static int pinctrl_vf610_init(void)
 {
 	return platform_driver_register(&pinctrl_vf610_driver);
 }
-postcore_initcall(pinctrl_vf610_init);
+core_initcall(pinctrl_vf610_init);
Signature · 7 lines
2.17.1


_______________________________________________
barebox mailing list
[email protected]
http://lists.infradead.org/mailman/listinfo/barebox
#3 lore raw

PATCH 3/11 linux/ctype.h: Port _tolower()

In reply to Andrey Smirnov
---
 include/linux/ctype.h | 9 +++++++++
 1 file changed, 9 insertions(+)
include/linux/ctype.h +9 -0
index 74fb73577..633c3862d 100644
@@ -53,4 +53,13 @@ static inline unsigned char __toupper(unsigned char c)
 #define tolower(c) __tolower(c)
 #define toupper(c) __toupper(c)
 
+/*
+ * Fast implementation of tolower() for internal usage. Do not use in your
+ * code.
+ */
+static inline char _tolower(const char c)
+{
+	return c | 0x20;
+}
+
 #endif
Signature · 7 lines
2.17.1


_______________________________________________
barebox mailing list
[email protected]
http://lists.infradead.org/mailman/listinfo/barebox
#4 lore raw

PATCH 4/11 lib: Port kstrtox.c from Linux kernel

In reply to Andrey Smirnov
---
 include/linux/kernel.h |  95 +++++++++++
 include/linux/string.h |   2 +
 lib/Makefile           |   1 +
 lib/kstrtox.c          | 366 +++++++++++++++++++++++++++++++++++++++++
 lib/kstrtox.h          |   9 +
 5 files changed, 473 insertions(+)
 create mode 100644 lib/kstrtox.c
 create mode 100644 lib/kstrtox.h
include/linux/kernel.h +95 -0
index ab713f20e..cc6d6f746 100644
@@ -269,4 +269,99 @@ extern char *bin2hex(char *dst, const void *src, size_t count);
 #define swap(a, b) \
 	do { typeof(a) __tmp = (a); (a) = (b); (b) = __tmp; } while (0)
 
+
+/* Internal, do not use. */
+int __must_check _kstrtoul(const char *s, unsigned int base, unsigned long *res);
+int __must_check _kstrtol(const char *s, unsigned int base, long *res);
+
+int __must_check kstrtoull(const char *s, unsigned int base, unsigned long long *res);
+int __must_check kstrtoll(const char *s, unsigned int base, long long *res);
+
+/**
+ * kstrtoul - convert a string to an unsigned long
+ * @s: The start of the string. The string must be null-terminated, and may also
+ *  include a single newline before its terminating null. The first character
+ *  may also be a plus sign, but not a minus sign.
+ * @base: The number base to use. The maximum supported base is 16. If base is
+ *  given as 0, then the base of the string is automatically detected with the
+ *  conventional semantics - If it begins with 0x the number will be parsed as a
+ *  hexadecimal (case insensitive), if it otherwise begins with 0, it will be
+ *  parsed as an octal number. Otherwise it will be parsed as a decimal.
+ * @res: Where to write the result of the conversion on success.
+ *
+ * Returns 0 on success, -ERANGE on overflow and -EINVAL on parsing error.
+ * Used as a replacement for the obsolete simple_strtoull. Return code must
+ * be checked.
+*/
+static inline int __must_check kstrtoul(const char *s, unsigned int base, unsigned long *res)
+{
+	/*
+	 * We want to shortcut function call, but
+	 * __builtin_types_compatible_p(unsigned long, unsigned long long) = 0.
+	 */
+	if (sizeof(unsigned long) == sizeof(unsigned long long) &&
+	    __alignof__(unsigned long) == __alignof__(unsigned long long))
+		return kstrtoull(s, base, (unsigned long long *)res);
+	else
+		return _kstrtoul(s, base, res);
+}
+
+/**
+ * kstrtol - convert a string to a long
+ * @s: The start of the string. The string must be null-terminated, and may also
+ *  include a single newline before its terminating null. The first character
+ *  may also be a plus sign or a minus sign.
+ * @base: The number base to use. The maximum supported base is 16. If base is
+ *  given as 0, then the base of the string is automatically detected with the
+ *  conventional semantics - If it begins with 0x the number will be parsed as a
+ *  hexadecimal (case insensitive), if it otherwise begins with 0, it will be
+ *  parsed as an octal number. Otherwise it will be parsed as a decimal.
+ * @res: Where to write the result of the conversion on success.
+ *
+ * Returns 0 on success, -ERANGE on overflow and -EINVAL on parsing error.
+ * Used as a replacement for the obsolete simple_strtoull. Return code must
+ * be checked.
+ */
+static inline int __must_check kstrtol(const char *s, unsigned int base, long *res)
+{
+	/*
+	 * We want to shortcut function call, but
+	 * __builtin_types_compatible_p(long, long long) = 0.
+	 */
+	if (sizeof(long) == sizeof(long long) &&
+	    __alignof__(long) == __alignof__(long long))
+		return kstrtoll(s, base, (long long *)res);
+	else
+		return _kstrtol(s, base, res);
+}
+
+int __must_check kstrtouint(const char *s, unsigned int base, unsigned int *res);
+int __must_check kstrtoint(const char *s, unsigned int base, int *res);
+
+static inline int __must_check kstrtou64(const char *s, unsigned int base, u64 *res)
+{
+	return kstrtoull(s, base, res);
+}
+
+static inline int __must_check kstrtos64(const char *s, unsigned int base, s64 *res)
+{
+	return kstrtoll(s, base, res);
+}
+
+static inline int __must_check kstrtou32(const char *s, unsigned int base, u32 *res)
+{
+	return kstrtouint(s, base, res);
+}
+
+static inline int __must_check kstrtos32(const char *s, unsigned int base, s32 *res)
+{
+	return kstrtoint(s, base, res);
+}
+
+int __must_check kstrtou16(const char *s, unsigned int base, u16 *res);
+int __must_check kstrtos16(const char *s, unsigned int base, s16 *res);
+int __must_check kstrtou8(const char *s, unsigned int base, u8 *res);
+int __must_check kstrtos8(const char *s, unsigned int base, s8 *res);
+int __must_check kstrtobool(const char *s, bool *res);
+
 #endif /* _LINUX_KERNEL_H */
include/linux/string.h +2 -0
index c9823dab8..fd42f5020 100644
@@ -134,4 +134,6 @@ static inline void *kmemdup(const void *src, size_t len, gfp_t gfp)
 	return memdup(src, len);
 }
 
+extern int kstrtobool(const char *s, bool *res);
+
 #endif /* _LINUX_STRING_H_ */
lib/Makefile +1 -0
index 693945fb2..24dc3d9ee 100644
@@ -5,6 +5,7 @@ obj-y			+= rbtree.o
 obj-y			+= display_options.o
 obj-y			+= string.o
 obj-y			+= strtox.o
+obj-y			+= kstrtox.o
 obj-y			+= vsprintf.o
 pbl-$(CONFIG_PBL_CONSOLE) += vsprintf.o
 obj-y			+= div64.o
lib/kstrtox.c new file +366 -0

367 lines not on this page · raw message

lib/kstrtox.h new file +9 -0
new file mode 100644
index 000000000..3b4637bcd
@@ -0,0 +1,9 @@
+/* SPDX-License-Identifier: GPL-2.0 */
+#ifndef _LIB_KSTRTOX_H
+#define _LIB_KSTRTOX_H
+
+#define KSTRTOX_OVERFLOW	(1U << 31)
+const char *_parse_integer_fixup_radix(const char *s, unsigned int *base);
+unsigned int _parse_integer(const char *s, unsigned int base, unsigned long long *res);
+
+#endif
Signature · 7 lines
2.17.1


_______________________________________________
barebox mailing list
[email protected]
http://lists.infradead.org/mailman/listinfo/barebox
#5 lore raw

PATCH 5/11 commands: gpio: Move argument parsing into a shared function

In reply to Andrey Smirnov
---
 commands/gpio.c | 48 +++++++++++++++++++++++++++++-------------------
 1 file changed, 29 insertions(+), 19 deletions(-)
commands/gpio.c +29 -19
index 08ecc152d..5a28493d1 100644
@@ -16,14 +16,29 @@
 #include <errno.h>
 #include <gpio.h>
 
-static int do_gpio_get_value(int argc, char *argv[])
+static int get_gpio_and_value(int argc, char *argv[],
+			      int *gpio, int *value)
 {
-	int gpio, value;
+	const int count = value ? 3 : 2;
 
-	if (argc < 2)
+	if (argc < count)
 		return COMMAND_ERROR_USAGE;
 
-	gpio = simple_strtoul(argv[1], NULL, 0);
+	*gpio = simple_strtoul(argv[1], NULL, 0);
+
+	if (value)
+		*value = simple_strtoul(argv[2], NULL, 0);
+
+	return 0;
+}
+
+static int do_gpio_get_value(int argc, char *argv[])
+{
+	int gpio, value, ret;
+
+	ret = get_gpio_and_value(argc, argv, &gpio, NULL);
+	if (ret)
+		return ret;
 
 	value = gpio_get_value(gpio);
 	if (value < 0)
@@ -41,13 +56,11 @@ BAREBOX_CMD_END
 
 static int do_gpio_set_value(int argc, char *argv[])
 {
-	int gpio, value;
-
-	if (argc < 3)
-		return COMMAND_ERROR_USAGE;
+	int gpio, value, ret;
 
-	gpio = simple_strtoul(argv[1], NULL, 0);
-	value = simple_strtoul(argv[2], NULL, 0);
+	ret = get_gpio_and_value(argc, argv, &gpio, &value);
+	if (ret)
+		return ret;
 
 	gpio_set_value(gpio, value);
 
@@ -65,10 +78,9 @@ static int do_gpio_direction_input(int argc, char *argv[])
 {
 	int gpio, ret;
 
-	if (argc < 2)
-		return COMMAND_ERROR_USAGE;
-
-	gpio = simple_strtoul(argv[1], NULL, 0);
+	ret = get_gpio_and_value(argc, argv, &gpio, NULL);
+	if (ret)
+		return ret;
 
 	ret = gpio_direction_input(gpio);
 	if (ret)
@@ -88,11 +100,9 @@ static int do_gpio_direction_output(int argc, char *argv[])
 {
 	int gpio, value, ret;
 
-	if (argc < 3)
-		return COMMAND_ERROR_USAGE;
-
-	gpio = simple_strtoul(argv[1], NULL, 0);
-	value = simple_strtoul(argv[2], NULL, 0);
+	ret = get_gpio_and_value(argc, argv, &gpio, &value);
+	if (ret)
+		return ret;
 
 	ret = gpio_direction_output(gpio, value);
 	if (ret)
Signature · 7 lines
2.17.1


_______________________________________________
barebox mailing list
[email protected]
http://lists.infradead.org/mailman/listinfo/barebox
#6 lore raw

PATCH 6/11 commands: gpio: Use kstrtoint() instead of simple_strtoul()

In reply to Andrey Smirnov

Use kstrtoint() instead of simple_strtoul() in order to properly handle invalid arguments. Current code using simple_strtoul() results in following:

barebox@ZII RDU2 Board:/ gpio_get_value foo
barebox@ZII RDU2 Board:/ echo $?
0

whereas with this patch we get:

barebox@ZII RDU2 Board:/ gpio_get_value foo
gpio_get_value: Invalid argument

---
 commands/gpio.c | 9 ++++++---
 1 file changed, 6 insertions(+), 3 deletions(-)
commands/gpio.c +6 -3
index 5a28493d1..3a2b8624f 100644
@@ -20,16 +20,19 @@ static int get_gpio_and_value(int argc, char *argv[],
 			      int *gpio, int *value)
 {
 	const int count = value ? 3 : 2;
+	int ret;
 
 	if (argc < count)
 		return COMMAND_ERROR_USAGE;
 
-	*gpio = simple_strtoul(argv[1], NULL, 0);
+	ret = kstrtoint(argv[1], 0, gpio);
+	if (ret < 0)
+		return ret;
 
 	if (value)
-		*value = simple_strtoul(argv[2], NULL, 0);
+		ret = kstrtoint(argv[2], 0, value);
 
-	return 0;
+	return ret;
 }
 
 static int do_gpio_get_value(int argc, char *argv[])
Signature · 7 lines
2.17.1


_______________________________________________
barebox mailing list
[email protected]
http://lists.infradead.org/mailman/listinfo/barebox
#7 lore raw

PATCH 7/11 gpiolib: Introduce gpio_find_by_label()

In reply to Andrey Smirnov

Introduce gpio_find_by_label() in order to allow manipulating GPIOs by the labels assigned to them via DT or board/driver code.

---
 drivers/gpio/gpiolib.c | 17 +++++++++++++++++
 include/gpio.h         |  6 ++++++
 2 files changed, 23 insertions(+)
drivers/gpio/gpiolib.c +17 -0
index b83a27de7..afece61d9 100644
@@ -91,6 +91,23 @@ done:
 	return ret;
 }
 
+int gpio_find_by_label(const char *label)
+{
+	int i;
+
+	for (i = 0; i < ARCH_NR_GPIOS; i++) {
+		struct gpio_info *info = &gpio_desc[i];
+
+		if (!info->requested || !info->chip || !info->label)
+			continue;
+
+		if (!strcmp(info->label, label))
+			return i;
+	}
+
+	return -ENOENT;
+}
+
 void gpio_free(unsigned gpio)
 {
 	struct gpio_info *gi = gpio_to_desc(gpio);
include/gpio.h +6 -0
index e42fa2338..38d6ba2df 100644
@@ -92,6 +92,11 @@ static inline int gpio_request(unsigned gpio, const char *label)
 	return 0;
 }
 
+static inline int gpio_find_by_label(const char *label)
+{
+	return -ENOSYS;
+}
+
 static inline void gpio_free(unsigned gpio)
 {
 }
@@ -114,6 +119,7 @@ static inline void gpio_free_array(const struct gpio *array, size_t num)
 }
 #else
 int gpio_request(unsigned gpio, const char *label);
+int gpio_find_by_label(const char *label);
 void gpio_free(unsigned gpio);
 int gpio_request_one(unsigned gpio, unsigned long flags, const char *label);
 int gpio_request_array(const struct gpio *array, size_t num);
Signature · 7 lines
2.17.1


_______________________________________________
barebox mailing list
[email protected]
http://lists.infradead.org/mailman/listinfo/barebox
#8 lore raw

PATCH 8/11 commands: gpio: Allow GPIOs to be specified by label

In reply to Andrey Smirnov
---
 commands/gpio.c | 11 +++++++----
 1 file changed, 7 insertions(+), 4 deletions(-)
commands/gpio.c +7 -4
index 3a2b8624f..951ad2c28 100644
@@ -20,14 +20,17 @@ static int get_gpio_and_value(int argc, char *argv[],
 			      int *gpio, int *value)
 {
 	const int count = value ? 3 : 2;
-	int ret;
+	int ret = 0;
 
 	if (argc < count)
 		return COMMAND_ERROR_USAGE;
 
-	ret = kstrtoint(argv[1], 0, gpio);
-	if (ret < 0)
-		return ret;
+	*gpio = gpio_find_by_label(argv[1]);
+	if (*gpio < 0) {
+		ret = kstrtoint(argv[1], 0, gpio);
+		if (ret < 0)
+			return ret;
+	}
 
 	if (value)
 		ret = kstrtoint(argv[2], 0, value);
Signature · 7 lines
2.17.1


_______________________________________________
barebox mailing list
[email protected]
http://lists.infradead.org/mailman/listinfo/barebox
#9 lore raw

PATCH 9/11 VF610: zii-vf610-dev: Drop switch reset GPIO configuration

In reply to Andrey Smirnov

This GPIO is controlled by MV88E6xxx driver, so there's no need to explicitly configure this GPIO.

---
 arch/arm/boards/zii-vf610-dev/board.c | 5 -----
 1 file changed, 5 deletions(-)
arch/arm/boards/zii-vf610-dev/board.c +0 -5
index 275d0a432..a8fa1ef61 100644
@@ -63,11 +63,6 @@ late_initcall(zii_vf610_cfu1_expose_signals);
 static int zii_vf610_cfu1_spu3_expose_signals(void)
 {
 	static const struct gpio signals[] = {
-		{
-			.gpio  = 107,
-			.flags  = GPIOF_OUT_INIT_HIGH,
-			.label = "soc_sw_rstn",
-		},
 		{
 			.gpio  = 98,
 			.flags = GPIOF_IN,
Signature · 7 lines
2.17.1


_______________________________________________
barebox mailing list
[email protected]
http://lists.infradead.org/mailman/listinfo/barebox
#10 lore raw

PATCH 10/11 VF610: zii-vf610-dev: Replace board code with gpio-hog nodes

In reply to Andrey Smirnov
---
 arch/arm/boards/zii-vf610-dev/board.c | 56 ---------------------------
 arch/arm/dts/vf610-zii-cfu1.dts       | 25 ++++++++++++
 arch/arm/dts/vf610-zii-ssmb-spu3.dts  |  9 +++++
 3 files changed, 34 insertions(+), 56 deletions(-)
arch/arm/boards/zii-vf610-dev/board.c +0 -56
index a8fa1ef61..cb4216272 100644
@@ -22,62 +22,6 @@
 #include <envfs.h>
 #include <mach/bbu.h>
 
-
-static int expose_signals(const struct gpio *signals,
-			  size_t signal_num)
-{
-	int ret, i;
-
-	ret = gpio_request_array(signals, signal_num);
-	if (ret)
-		return ret;
-
-	for (i = 0; i < signal_num; i++)
-		export_env_ull(signals[i].label, signals[i].gpio);
-
-	return 0;
-}
-
-static int zii_vf610_cfu1_expose_signals(void)
-{
-	static const struct gpio signals[] = {
-		{
-			.gpio  = 132,
-			.flags = GPIOF_IN,
-			.label = "fim_sd",
-		},
-		{
-			.gpio  = 118,
-			.flags = GPIOF_OUT_INIT_LOW,
-			.label = "fim_tdis",
-		},
-	};
-
-	if (!of_machine_is_compatible("zii,vf610cfu1"))
-		return 0;
-
-	return expose_signals(signals, ARRAY_SIZE(signals));
-}
-late_initcall(zii_vf610_cfu1_expose_signals);
-
-static int zii_vf610_cfu1_spu3_expose_signals(void)
-{
-	static const struct gpio signals[] = {
-		{
-			.gpio  = 98,
-			.flags = GPIOF_IN,
-			.label = "e6352_intn",
-		},
-	};
-
-	if (!of_machine_is_compatible("zii,vf610spu3") &&
-	    !of_machine_is_compatible("zii,vf610cfu1"))
-		return 0;
-
-	return expose_signals(signals, ARRAY_SIZE(signals));
-}
-late_initcall(zii_vf610_cfu1_spu3_expose_signals);
-
 static int zii_vf610_dev_print_clocks(void)
 {
 	int i;
arch/arm/dts/vf610-zii-cfu1.dts +25 -0
index 149333596..74ec9fd1d 100644
@@ -19,3 +19,28 @@
 	};
 };
 
+
+&gpio3 {
+	fim-tdis {
+		gpio-hog;
+		gpios = <22 GPIO_ACTIVE_HIGH>;
+		output-low;
+		line-name = "fim_tdis";
+	};
+
+	e6352-intn {
+		gpio-hog;
+		gpios = <2 GPIO_ACTIVE_HIGH>;
+		input;
+		line-name = "e6352_intn";
+	};
+};
+
+&gpio4 {
+	fim-sd {
+		gpio-hog;
+		gpios = <4 GPIO_ACTIVE_HIGH>;
+		input;
+		line-name = "fim_sd";
+	};
+};
\ No newline at end of file
arch/arm/dts/vf610-zii-ssmb-spu3.dts +9 -0
index 5b2460caf..6ffa1d958 100644
@@ -14,3 +14,12 @@
 		switch-eeprom = &switch0;
 	};
 };
+
+&gpio3 {
+	e6352-intn {
+		gpio-hog;
+		gpios = <2 GPIO_ACTIVE_HIGH>;
+		input;
+		line-name = "e6352_intn";
+	};
+};
Signature · 7 lines
2.17.1


_______________________________________________
barebox mailing list
[email protected]
http://lists.infradead.org/mailman/listinfo/barebox
maintainer
#11 lore raw

Re: [PATCH 10/11] VF610: zii-vf610-dev: Replace board code with gpio-hog nodes

Quoted 23 lines · Andrey Smirnov
arch/arm/dts/vf610-zii-cfu1.dts +15 -0
index 149333596..74ec9fd1d 100644
@@ -19,3 +19,28 @@
 	};
 };
 
+
+&gpio3 {
+	fim-tdis {
+		gpio-hog;
+		gpios = <22 GPIO_ACTIVE_HIGH>;
+		output-low;
+		line-name = "fim_tdis";
+	};
+
+	e6352-intn {
+		gpio-hog;
+		gpios = <2 GPIO_ACTIVE_HIGH>;
+		input;
+		line-name = "e6352_intn";
+	};

arch/arm/dts/vf610-zii-cfu1.dts line 46

Quoted 10 lines
arch/arm/dts/vf610-zii-cfu1.dts +10 -0
+};
+
+&gpio4 {
+	fim-sd {
+		gpio-hog;
+		gpios = <4 GPIO_ACTIVE_HIGH>;
+		input;
+		line-name = "fim_sd";
+	};
+};

Hog GPIOs are GPIOs that are initialized once in the Kernel and from then on can never be changed. Is this true for these GPIOs you change here? I just want to make sure that you do not use gpio-hog in barebox to configure it and do something different in the Kernel because you pass another devicetree to the kernel. Or, to put it differently, you should be able to pass the barebox devicetree to Linux and still have a fully operating system.

If that is true then I can apply these patches. Otherwise I would prefer some gpio-init mechanism that is implemented in barebox and the Kernel just don't cares.

Sascha

Signature · 9 lines
Pengutronix e.K.                           |                             |
Industrial Linux Solutions                 | http://www.pengutronix.de/  |
Peiner Str. 6-8, 31137 Hildesheim, Germany | Phone: +49-5121-206917-0    |
Amtsgericht Hildesheim, HRA 2686           | Fax:   +49-5121-206917-5555 |

_______________________________________________
barebox mailing list
[email protected]
http://lists.infradead.org/mailman/listinfo/barebox
#12 lore raw

Re: [PATCH 10/11] VF610: zii-vf610-dev: Replace board code with gpio-hog nodes

Quoted 36 lines · Sascha Hauer
Quoted 23 lines · Andrey Smirnov
arch/arm/dts/vf610-zii-cfu1.dts +15 -0
index 149333596..74ec9fd1d 100644
@@ -19,3 +19,28 @@
      };
 };
 
+
+&gpio3 {
+     fim-tdis {
+             gpio-hog;
+             gpios = <22 GPIO_ACTIVE_HIGH>;
+             output-low;
+             line-name = "fim_tdis";
+     };
+
+     e6352-intn {
+             gpio-hog;
+             gpios = <2 GPIO_ACTIVE_HIGH>;
+             input;
+             line-name = "e6352_intn";
+     };

arch/arm/dts/vf610-zii-cfu1.dts line 46

Quoted 10 lines
arch/arm/dts/vf610-zii-cfu1.dts +10 -0
+};
+
+&gpio4 {
+     fim-sd {
+             gpio-hog;
+             gpios = <4 GPIO_ACTIVE_HIGH>;
+             input;
+             line-name = "fim_sd";
+     };
+};
Quoted 8 lines

Hog GPIOs are GPIOs that are initialized once in the Kernel and from then on can never be changed. Is this true for these GPIOs you change here? I just want to make sure that you do not use gpio-hog in barebox to configure it and do something different in the Kernel because you pass another devicetree to the kernel. Or, to put it differently, you should be able to pass the barebox devicetree to Linux and still have a fully operating system.

Those GPIOs are exposed for debugging/board bringup purposes mostly:
"fim_*" are "signal detect" and "tx disable" signals from an fiber optic transmitter module and "e6352_intn" is an interrupt line from Marvell switch. Linux kernel has appropriate drivers that "consume" those GPIOs, so passing BB's DT might result in conflicts in those drivers (I am not 100% sure), so this is probably a violation of the rule you laid out above.

This is not really crucial code to have in general, so I'll move the DT changes out into a separate patch that I can carry in our upstream patch delta (It'll probably be dropped eventually).

Thanks,
Andrey Smirnov

_______________________________________________
barebox mailing list
[email protected]
http://lists.infradead.org/mailman/listinfo/barebox

#13 lore raw

PATCH 11/11 ARM: rdu2: Replace board code with gpio-hog nodes

In reply to Andrey Smirnov
---
 arch/arm/boards/zii-imx6q-rdu2/board.c | 38 --------------------------
 arch/arm/dts/imx6qdl-zii-rdu2.dtsi     | 36 ++++++++++++++++++++++++
 2 files changed, 36 insertions(+), 38 deletions(-)
arch/arm/boards/zii-imx6q-rdu2/board.c +0 -38
index c99f993f0..e174032c9 100644
@@ -97,44 +97,6 @@ static int rdu2_reset_audio_touchscreen_nfc(void)
  */
 late_initcall(rdu2_reset_audio_touchscreen_nfc);
 
-static const struct gpio rdu2_front_panel_usb_gpios[] = {
-	{
-		.gpio = IMX_GPIO_NR(3, 19),
-		.flags = GPIOF_OUT_INIT_LOW,
-		.label = "usb-emulation",
-	},
-	{
-		.gpio = IMX_GPIO_NR(3, 20),
-		.flags = GPIOF_OUT_INIT_HIGH,
-		.label = "usb-mode1",
-	},
-	{
-		.gpio = IMX_GPIO_NR(3, 23),
-		.flags = GPIOF_OUT_INIT_HIGH,
-		.label = "usb-mode2",
-	},
-};
-
-static int rdu2_enable_front_panel_usb(void)
-{
-	int ret;
-
-	if (!of_machine_is_compatible("zii,imx6q-zii-rdu2") &&
-	    !of_machine_is_compatible("zii,imx6qp-zii-rdu2"))
-		return 0;
-
-	ret = gpio_request_array(rdu2_front_panel_usb_gpios,
-				 ARRAY_SIZE(rdu2_front_panel_usb_gpios));
-	if (ret) {
-		pr_err("Failed to request RDU2 front panel USB gpios: %s\n",
-		       strerror(-ret));
-
-	}
-
-	return ret;
-}
-late_initcall(rdu2_enable_front_panel_usb);
-
 static int rdu2_devices_init(void)
 {
 	if (!of_machine_is_compatible("zii,imx6q-zii-rdu2") &&
arch/arm/dts/imx6qdl-zii-rdu2.dtsi +36 -0
index 3915c34df..a3f6dbd15 100644
@@ -130,3 +130,39 @@
 		};
 	};
 };
+
+&gpio3 {
+	pinctrl-names = "default";
+	pinctrl-0 = <&pinctrl_gpio3_hog>;
+
+	usb-emulation {
+		gpio-hog;
+		gpios = <19 GPIO_ACTIVE_HIGH>;
+		output-low;
+		line-name = "usb-emulation";
+	};
+
+	usb-mode1 {
+		gpio-hog;
+		gpios = <20 GPIO_ACTIVE_HIGH>;
+		output-high;
+		line-name = "usb-mode1";
+	};
+
+	usb-mode2 {
+		gpio-hog;
+		gpios = <23 GPIO_ACTIVE_HIGH>;
+		output-high;
+		line-name = "usb-mode2";
+	};
+};
+
+&iomuxc {
+	pinctrl_gpio3_hog: gpio3hoggrp {
+		fsl,pins = <
+			MX6QDL_PAD_EIM_D19__GPIO3_IO19		0x40000038
+			MX6QDL_PAD_EIM_D20__GPIO3_IO20		0x40000038
+			MX6QDL_PAD_EIM_D23__GPIO3_IO23		0x40000038
+		>;
+	};
+};
Signature · 7 lines
2.17.1


_______________________________________________
barebox mailing list
[email protected]
http://lists.infradead.org/mailman/listinfo/barebox
#14 lore raw

Re: [PATCH 11/11] ARM: rdu2: Replace board code with gpio-hog nodes

Quoted 2 lines · Andrey Smirnov

Sascha, it seems that this patch was not applied. This one, unlike "VF610: zii-vf610-dev: Replace board code with gpio-hog nodes", will _not_ interfere with kernel boot in any way, it just configures UCS1002 into USB data pass-through(default bootstrapping is BCD 1.2 mode). It should be safe to have.

Thanks,
Andrey Smirnov

_______________________________________________
barebox mailing list
[email protected]
http://lists.infradead.org/mailman/listinfo/barebox

maintainer
#15 lore raw

Re: [PATCH 11/11] ARM: rdu2: Replace board code with gpio-hog nodes

Quoted 9 lines · Andrey Smirnov
Quoted 2 lines · Andrey Smirnov

Sascha, it seems that this patch was not applied. This one, unlike "VF610: zii-vf610-dev: Replace board code with gpio-hog nodes", will _not_ interfere with kernel boot in any way, it just configures UCS1002 into USB data pass-through(default bootstrapping is BCD 1.2 mode). It should be safe to have.

Ok, applied now.

Sascha

Signature · 9 lines
Pengutronix e.K.                           |                             |
Industrial Linux Solutions                 | http://www.pengutronix.de/  |
Peiner Str. 6-8, 31137 Hildesheim, Germany | Phone: +49-5121-206917-0    |
Amtsgericht Hildesheim, HRA 2686           | Fax:   +49-5121-206917-5555 |

_______________________________________________
barebox mailing list
[email protected]
http://lists.infradead.org/mailman/listinfo/barebox
#16 lore raw
In reply to Andrey Smirnov

Hi Andrey.

Quoted 3 lines

This patch series is the result of my work on extending various gpio_* commands in Barebox CLI to allow referencing GPIOs by a label assigned to them via Device Tree or in any other way.

Thanks, I have missed this in the past.

I browsed the patches.
There are a few that is missing a newline, that you may fix if you post a v2. But other than that everything looked good to me.

Quoted 6 lines

AFAICT majority of callers of simple_strto*() functions don't really do very strict error checking which seems really undesirable. With kstrto*() functions in place, and assuming there's no objections to that, what do you think about a separate patch series to replace all of the uses of simple_strto*() with kstrto*() and eventually drop majority of simple_strto*() implementation code?

There should be only one implmentation, and the more strict variant makes good sense.

Sam

_______________________________________________
barebox mailing list
[email protected]
http://lists.infradead.org/mailman/listinfo/barebox

maintainer
#17 lore raw
Quoted 19 lines · Sam Ravnborg

Hi Andrey.

Quoted 3 lines

This patch series is the result of my work on extending various gpio_* commands in Barebox CLI to allow referencing GPIOs by a label assigned to them via Device Tree or in any other way.

Thanks, I have missed this in the past.

I browsed the patches.
There are a few that is missing a newline, that you may fix if you post a v2. But other than that everything looked good to me.

Quoted 6 lines

AFAICT majority of callers of simple_strto*() functions don't really do very strict error checking which seems really undesirable. With kstrto*() functions in place, and assuming there's no objections to that, what do you think about a separate patch series to replace all of the uses of simple_strto*() with kstrto*() and eventually drop majority of simple_strto*() implementation code?

Quoted 2 lines

There should be only one implmentation, and the more strict variant makes good sense.

The kstrtox functions epect a terminating 0 or a newline at the end of the string. strtoull_suffix() is at least one place that cannot directly be implemented with the kernel functions.

Otherwise yes, I am also in favour to be more strict with the string checking.

Sascha

Signature · 9 lines
Pengutronix e.K.                           |                             |
Industrial Linux Solutions                 | http://www.pengutronix.de/  |
Peiner Str. 6-8, 31137 Hildesheim, Germany | Phone: +49-5121-206917-0    |
Amtsgericht Hildesheim, HRA 2686           | Fax:   +49-5121-206917-5555 |

_______________________________________________
barebox mailing list
[email protected]
http://lists.infradead.org/mailman/listinfo/barebox
maintainer
#18 lore raw
In reply to Andrey Smirnov
Quoted 15 lines · Andrey Smirnov

Everyone:

This patch series is the result of my work on extending various gpio_* commands in Barebox CLI to allow referencing GPIOs by a label assigned to them via Device Tree or in any other way.

Sascha:

AFAICT majority of callers of simple_strto*() functions don't really do very strict error checking which seems really undesirable. With kstrto*() functions in place, and assuming there's no objections to that, what do you think about a separate patch series to replace all of the uses of simple_strto*() with kstrto*() and eventually drop majority of simple_strto*() implementation code?

Quoted 2 lines

Thanks,
Andrey Smirnov

Applied 1-9 for now, see comment to 10/11.

Sascha

Signature · 9 lines
Pengutronix e.K.                           |                             |
Industrial Linux Solutions                 | http://www.pengutronix.de/  |
Peiner Str. 6-8, 31137 Hildesheim, Germany | Phone: +49-5121-206917-0    |
Amtsgericht Hildesheim, HRA 2686           | Fax:   +49-5121-206917-5555 |

_______________________________________________
barebox mailing list
[email protected]
http://lists.infradead.org/mailman/listinfo/barebox