mail archive of the barebox mailing list
 help / color / mirror / Atom feed
* [PATCH 00/11] Allow GPIOs to be referenced by label
@ 2018-10-27  1:31 Andrey Smirnov
  2018-10-27  1:31 ` [PATCH 01/11] gpio: VF610: Propagate error code of gpiochip_add() up Andrey Smirnov
                   ` (12 more replies)
  0 siblings, 13 replies; 19+ messages in thread
From: Andrey Smirnov @ 2018-10-27  1:31 UTC (permalink / raw)
  To: barebox; +Cc: 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?

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

-- 
2.17.1


_______________________________________________
barebox mailing list
barebox@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/barebox

^ permalink raw reply	[flat|nested] 19+ messages in thread

* [PATCH 01/11] gpio: VF610: Propagate error code of gpiochip_add() up
  2018-10-27  1:31 [PATCH 00/11] Allow GPIOs to be referenced by label Andrey Smirnov
@ 2018-10-27  1:31 ` Andrey Smirnov
  2018-10-27  1:31 ` [PATCH 02/11] VF610: Initialize pinctrl driver before gpio Andrey Smirnov
                   ` (11 subsequent siblings)
  12 siblings, 0 replies; 19+ messages in thread
From: Andrey Smirnov @ 2018-10-27  1:31 UTC (permalink / raw)
  To: barebox; +Cc: Andrey Smirnov

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.

Signed-off-by: Andrey Smirnov <andrew.smirnov@gmail.com>
---
 drivers/gpio/gpio-vf610.c | 3 +--
 1 file changed, 1 insertion(+), 2 deletions(-)

diff --git a/drivers/gpio/gpio-vf610.c b/drivers/gpio/gpio-vf610.c
index 2aff62be5..9ac838f3b 100644
--- a/drivers/gpio/gpio-vf610.c
+++ b/drivers/gpio/gpio-vf610.c
@@ -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);
-- 
2.17.1


_______________________________________________
barebox mailing list
barebox@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/barebox

^ permalink raw reply	[flat|nested] 19+ messages in thread

* [PATCH 02/11] VF610: Initialize pinctrl driver before gpio
  2018-10-27  1:31 [PATCH 00/11] Allow GPIOs to be referenced by label Andrey Smirnov
  2018-10-27  1:31 ` [PATCH 01/11] gpio: VF610: Propagate error code of gpiochip_add() up Andrey Smirnov
@ 2018-10-27  1:31 ` Andrey Smirnov
  2018-10-27  1:31 ` [PATCH 03/11] linux/ctype.h: Port _tolower() Andrey Smirnov
                   ` (10 subsequent siblings)
  12 siblings, 0 replies; 19+ messages in thread
From: Andrey Smirnov @ 2018-10-27  1:31 UTC (permalink / raw)
  To: barebox; +Cc: 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.

Signed-off-by: Andrey Smirnov <andrew.smirnov@gmail.com>
---
 drivers/gpio/gpio-vf610.c       | 2 +-
 drivers/pinctrl/pinctrl-vf610.c | 2 +-
 2 files changed, 2 insertions(+), 2 deletions(-)

diff --git a/drivers/gpio/gpio-vf610.c b/drivers/gpio/gpio-vf610.c
index 9ac838f3b..ab35310fb 100644
--- a/drivers/gpio/gpio-vf610.c
+++ b/drivers/gpio/gpio-vf610.c
@@ -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);
diff --git a/drivers/pinctrl/pinctrl-vf610.c b/drivers/pinctrl/pinctrl-vf610.c
index a46b0e2ca..662fa9b6c 100644
--- a/drivers/pinctrl/pinctrl-vf610.c
+++ b/drivers/pinctrl/pinctrl-vf610.c
@@ -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);
-- 
2.17.1


_______________________________________________
barebox mailing list
barebox@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/barebox

^ permalink raw reply	[flat|nested] 19+ messages in thread

* [PATCH 03/11] linux/ctype.h: Port _tolower()
  2018-10-27  1:31 [PATCH 00/11] Allow GPIOs to be referenced by label Andrey Smirnov
  2018-10-27  1:31 ` [PATCH 01/11] gpio: VF610: Propagate error code of gpiochip_add() up Andrey Smirnov
  2018-10-27  1:31 ` [PATCH 02/11] VF610: Initialize pinctrl driver before gpio Andrey Smirnov
@ 2018-10-27  1:31 ` Andrey Smirnov
  2018-10-27  1:31 ` [PATCH 04/11] lib: Port kstrtox.c from Linux kernel Andrey Smirnov
                   ` (9 subsequent siblings)
  12 siblings, 0 replies; 19+ messages in thread
From: Andrey Smirnov @ 2018-10-27  1:31 UTC (permalink / raw)
  To: barebox; +Cc: Andrey Smirnov

Signed-off-by: Andrey Smirnov <andrew.smirnov@gmail.com>
---
 include/linux/ctype.h | 9 +++++++++
 1 file changed, 9 insertions(+)

diff --git a/include/linux/ctype.h b/include/linux/ctype.h
index 74fb73577..633c3862d 100644
--- a/include/linux/ctype.h
+++ b/include/linux/ctype.h
@@ -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
-- 
2.17.1


_______________________________________________
barebox mailing list
barebox@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/barebox

^ permalink raw reply	[flat|nested] 19+ messages in thread

* [PATCH 04/11] lib: Port kstrtox.c from Linux kernel
  2018-10-27  1:31 [PATCH 00/11] Allow GPIOs to be referenced by label Andrey Smirnov
                   ` (2 preceding siblings ...)
  2018-10-27  1:31 ` [PATCH 03/11] linux/ctype.h: Port _tolower() Andrey Smirnov
@ 2018-10-27  1:31 ` Andrey Smirnov
  2018-10-27  1:31 ` [PATCH 05/11] commands: gpio: Move argument parsing into a shared function Andrey Smirnov
                   ` (8 subsequent siblings)
  12 siblings, 0 replies; 19+ messages in thread
From: Andrey Smirnov @ 2018-10-27  1:31 UTC (permalink / raw)
  To: barebox; +Cc: Andrey Smirnov

Signed-off-by: Andrey Smirnov <andrew.smirnov@gmail.com>
---
 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

diff --git a/include/linux/kernel.h b/include/linux/kernel.h
index ab713f20e..cc6d6f746 100644
--- a/include/linux/kernel.h
+++ b/include/linux/kernel.h
@@ -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 */
diff --git a/include/linux/string.h b/include/linux/string.h
index c9823dab8..fd42f5020 100644
--- a/include/linux/string.h
+++ b/include/linux/string.h
@@ -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_ */
diff --git a/lib/Makefile b/lib/Makefile
index 693945fb2..24dc3d9ee 100644
--- a/lib/Makefile
+++ b/lib/Makefile
@@ -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
diff --git a/lib/kstrtox.c b/lib/kstrtox.c
new file mode 100644
index 000000000..0e4b59053
--- /dev/null
+++ b/lib/kstrtox.c
@@ -0,0 +1,366 @@
+// SPDX-License-Identifier: GPL-2.0
+/*
+ * Convert integer string representation to an integer.
+ * If an integer doesn't fit into specified type, -E is returned.
+ *
+ * Integer starts with optional sign.
+ * kstrtou*() functions do not accept sign "-".
+ *
+ * Radix 0 means autodetection: leading "0x" implies radix 16,
+ * leading "0" implies radix 8, otherwise radix is 10.
+ * Autodetection hints work after optional sign, but not before.
+ *
+ * If -E is returned, result is not touched.
+ */
+#include <linux/ctype.h>
+#include <linux/kernel.h>
+#include <linux/math64.h>
+#include <linux/types.h>
+
+#include "kstrtox.h"
+
+const char *_parse_integer_fixup_radix(const char *s, unsigned int *base)
+{
+	if (*base == 0) {
+		if (s[0] == '0') {
+			if (_tolower(s[1]) == 'x' && isxdigit(s[2]))
+				*base = 16;
+			else
+				*base = 8;
+		} else
+			*base = 10;
+	}
+	if (*base == 16 && s[0] == '0' && _tolower(s[1]) == 'x')
+		s += 2;
+	return s;
+}
+
+/*
+ * Convert non-negative integer string representation in explicitly given radix
+ * to an integer.
+ * Return number of characters consumed maybe or-ed with overflow bit.
+ * If overflow occurs, result integer (incorrect) is still returned.
+ *
+ * Don't you dare use this function.
+ */
+unsigned int _parse_integer(const char *s, unsigned int base, unsigned long long *p)
+{
+	unsigned long long res;
+	unsigned int rv;
+
+	res = 0;
+	rv = 0;
+	while (1) {
+		unsigned int c = *s;
+		unsigned int lc = c | 0x20; /* don't tolower() this line */
+		unsigned int val;
+
+		if ('0' <= c && c <= '9')
+			val = c - '0';
+		else if ('a' <= lc && lc <= 'f')
+			val = lc - 'a' + 10;
+		else
+			break;
+
+		if (val >= base)
+			break;
+		/*
+		 * Check for overflow only if we are within range of
+		 * it in the max base we support (16)
+		 */
+		if (unlikely(res & (~0ull << 60))) {
+			if (res > div_u64(ULLONG_MAX - val, base))
+				rv |= KSTRTOX_OVERFLOW;
+		}
+		res = res * base + val;
+		rv++;
+		s++;
+	}
+	*p = res;
+	return rv;
+}
+
+static int _kstrtoull(const char *s, unsigned int base, unsigned long long *res)
+{
+	unsigned long long _res;
+	unsigned int rv;
+
+	s = _parse_integer_fixup_radix(s, &base);
+	rv = _parse_integer(s, base, &_res);
+	if (rv & KSTRTOX_OVERFLOW)
+		return -ERANGE;
+	if (rv == 0)
+		return -EINVAL;
+	s += rv;
+	if (*s == '\n')
+		s++;
+	if (*s)
+		return -EINVAL;
+	*res = _res;
+	return 0;
+}
+
+/**
+ * kstrtoull - convert a string to an unsigned long 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.
+ */
+int kstrtoull(const char *s, unsigned int base, unsigned long long *res)
+{
+	if (s[0] == '+')
+		s++;
+	return _kstrtoull(s, base, res);
+}
+EXPORT_SYMBOL(kstrtoull);
+
+/**
+ * kstrtoll - convert a string to a long 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.
+ */
+int kstrtoll(const char *s, unsigned int base, long long *res)
+{
+	unsigned long long tmp;
+	int rv;
+
+	if (s[0] == '-') {
+		rv = _kstrtoull(s + 1, base, &tmp);
+		if (rv < 0)
+			return rv;
+		if ((long long)-tmp > 0)
+			return -ERANGE;
+		*res = -tmp;
+	} else {
+		rv = kstrtoull(s, base, &tmp);
+		if (rv < 0)
+			return rv;
+		if ((long long)tmp < 0)
+			return -ERANGE;
+		*res = tmp;
+	}
+	return 0;
+}
+EXPORT_SYMBOL(kstrtoll);
+
+/* Internal, do not use. */
+int _kstrtoul(const char *s, unsigned int base, unsigned long *res)
+{
+	unsigned long long tmp;
+	int rv;
+
+	rv = kstrtoull(s, base, &tmp);
+	if (rv < 0)
+		return rv;
+	if (tmp != (unsigned long long)(unsigned long)tmp)
+		return -ERANGE;
+	*res = tmp;
+	return 0;
+}
+EXPORT_SYMBOL(_kstrtoul);
+
+/* Internal, do not use. */
+int _kstrtol(const char *s, unsigned int base, long *res)
+{
+	long long tmp;
+	int rv;
+
+	rv = kstrtoll(s, base, &tmp);
+	if (rv < 0)
+		return rv;
+	if (tmp != (long long)(long)tmp)
+		return -ERANGE;
+	*res = tmp;
+	return 0;
+}
+EXPORT_SYMBOL(_kstrtol);
+
+/**
+ * kstrtouint - convert a string to an unsigned int
+ * @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.
+ */
+int kstrtouint(const char *s, unsigned int base, unsigned int *res)
+{
+	unsigned long long tmp;
+	int rv;
+
+	rv = kstrtoull(s, base, &tmp);
+	if (rv < 0)
+		return rv;
+	if (tmp != (unsigned long long)(unsigned int)tmp)
+		return -ERANGE;
+	*res = tmp;
+	return 0;
+}
+EXPORT_SYMBOL(kstrtouint);
+
+/**
+ * kstrtoint - convert a string to an int
+ * @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.
+ */
+int kstrtoint(const char *s, unsigned int base, int *res)
+{
+	long long tmp;
+	int rv;
+
+	rv = kstrtoll(s, base, &tmp);
+	if (rv < 0)
+		return rv;
+	if (tmp != (long long)(int)tmp)
+		return -ERANGE;
+	*res = tmp;
+	return 0;
+}
+EXPORT_SYMBOL(kstrtoint);
+
+int kstrtou16(const char *s, unsigned int base, u16 *res)
+{
+	unsigned long long tmp;
+	int rv;
+
+	rv = kstrtoull(s, base, &tmp);
+	if (rv < 0)
+		return rv;
+	if (tmp != (unsigned long long)(u16)tmp)
+		return -ERANGE;
+	*res = tmp;
+	return 0;
+}
+EXPORT_SYMBOL(kstrtou16);
+
+int kstrtos16(const char *s, unsigned int base, s16 *res)
+{
+	long long tmp;
+	int rv;
+
+	rv = kstrtoll(s, base, &tmp);
+	if (rv < 0)
+		return rv;
+	if (tmp != (long long)(s16)tmp)
+		return -ERANGE;
+	*res = tmp;
+	return 0;
+}
+EXPORT_SYMBOL(kstrtos16);
+
+int kstrtou8(const char *s, unsigned int base, u8 *res)
+{
+	unsigned long long tmp;
+	int rv;
+
+	rv = kstrtoull(s, base, &tmp);
+	if (rv < 0)
+		return rv;
+	if (tmp != (unsigned long long)(u8)tmp)
+		return -ERANGE;
+	*res = tmp;
+	return 0;
+}
+EXPORT_SYMBOL(kstrtou8);
+
+int kstrtos8(const char *s, unsigned int base, s8 *res)
+{
+	long long tmp;
+	int rv;
+
+	rv = kstrtoll(s, base, &tmp);
+	if (rv < 0)
+		return rv;
+	if (tmp != (long long)(s8)tmp)
+		return -ERANGE;
+	*res = tmp;
+	return 0;
+}
+EXPORT_SYMBOL(kstrtos8);
+
+/**
+ * kstrtobool - convert common user inputs into boolean values
+ * @s: input string
+ * @res: result
+ *
+ * This routine returns 0 iff the first character is one of 'Yy1Nn0', or
+ * [oO][NnFf] for "on" and "off". Otherwise it will return -EINVAL.  Value
+ * pointed to by res is updated upon finding a match.
+ */
+int kstrtobool(const char *s, bool *res)
+{
+	if (!s)
+		return -EINVAL;
+
+	switch (s[0]) {
+	case 'y':
+	case 'Y':
+	case '1':
+		*res = true;
+		return 0;
+	case 'n':
+	case 'N':
+	case '0':
+		*res = false;
+		return 0;
+	case 'o':
+	case 'O':
+		switch (s[1]) {
+		case 'n':
+		case 'N':
+			*res = true;
+			return 0;
+		case 'f':
+		case 'F':
+			*res = false;
+			return 0;
+		default:
+			break;
+		}
+	default:
+		break;
+	}
+
+	return -EINVAL;
+}
+EXPORT_SYMBOL(kstrtobool);
\ No newline at end of file
diff --git a/lib/kstrtox.h b/lib/kstrtox.h
new file mode 100644
index 000000000..3b4637bcd
--- /dev/null
+++ b/lib/kstrtox.h
@@ -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
-- 
2.17.1


_______________________________________________
barebox mailing list
barebox@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/barebox

^ permalink raw reply	[flat|nested] 19+ messages in thread

* [PATCH 05/11] commands: gpio: Move argument parsing into a shared function
  2018-10-27  1:31 [PATCH 00/11] Allow GPIOs to be referenced by label Andrey Smirnov
                   ` (3 preceding siblings ...)
  2018-10-27  1:31 ` [PATCH 04/11] lib: Port kstrtox.c from Linux kernel Andrey Smirnov
@ 2018-10-27  1:31 ` Andrey Smirnov
  2018-10-27  1:31 ` [PATCH 06/11] commands: gpio: Use kstrtoint() instead of simple_strtoul() Andrey Smirnov
                   ` (7 subsequent siblings)
  12 siblings, 0 replies; 19+ messages in thread
From: Andrey Smirnov @ 2018-10-27  1:31 UTC (permalink / raw)
  To: barebox; +Cc: Andrey Smirnov

Signed-off-by: Andrey Smirnov <andrew.smirnov@gmail.com>
---
 commands/gpio.c | 48 +++++++++++++++++++++++++++++-------------------
 1 file changed, 29 insertions(+), 19 deletions(-)

diff --git a/commands/gpio.c b/commands/gpio.c
index 08ecc152d..5a28493d1 100644
--- a/commands/gpio.c
+++ b/commands/gpio.c
@@ -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)
-- 
2.17.1


_______________________________________________
barebox mailing list
barebox@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/barebox

^ permalink raw reply	[flat|nested] 19+ messages in thread

* [PATCH 06/11] commands: gpio: Use kstrtoint() instead of simple_strtoul()
  2018-10-27  1:31 [PATCH 00/11] Allow GPIOs to be referenced by label Andrey Smirnov
                   ` (4 preceding siblings ...)
  2018-10-27  1:31 ` [PATCH 05/11] commands: gpio: Move argument parsing into a shared function Andrey Smirnov
@ 2018-10-27  1:31 ` Andrey Smirnov
  2018-10-27  1:31 ` [PATCH 07/11] gpiolib: Introduce gpio_find_by_label() Andrey Smirnov
                   ` (6 subsequent siblings)
  12 siblings, 0 replies; 19+ messages in thread
From: Andrey Smirnov @ 2018-10-27  1:31 UTC (permalink / raw)
  To: barebox; +Cc: 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

Signed-off-by: Andrey Smirnov <andrew.smirnov@gmail.com>
---
 commands/gpio.c | 9 ++++++---
 1 file changed, 6 insertions(+), 3 deletions(-)

diff --git a/commands/gpio.c b/commands/gpio.c
index 5a28493d1..3a2b8624f 100644
--- a/commands/gpio.c
+++ b/commands/gpio.c
@@ -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[])
-- 
2.17.1


_______________________________________________
barebox mailing list
barebox@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/barebox

^ permalink raw reply	[flat|nested] 19+ messages in thread

* [PATCH 07/11] gpiolib: Introduce gpio_find_by_label()
  2018-10-27  1:31 [PATCH 00/11] Allow GPIOs to be referenced by label Andrey Smirnov
                   ` (5 preceding siblings ...)
  2018-10-27  1:31 ` [PATCH 06/11] commands: gpio: Use kstrtoint() instead of simple_strtoul() Andrey Smirnov
@ 2018-10-27  1:31 ` Andrey Smirnov
  2018-10-27  1:31 ` [PATCH 08/11] commands: gpio: Allow GPIOs to be specified by label Andrey Smirnov
                   ` (5 subsequent siblings)
  12 siblings, 0 replies; 19+ messages in thread
From: Andrey Smirnov @ 2018-10-27  1:31 UTC (permalink / raw)
  To: barebox; +Cc: 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.

Signed-off-by: Andrey Smirnov <andrew.smirnov@gmail.com>
---
 drivers/gpio/gpiolib.c | 17 +++++++++++++++++
 include/gpio.h         |  6 ++++++
 2 files changed, 23 insertions(+)

diff --git a/drivers/gpio/gpiolib.c b/drivers/gpio/gpiolib.c
index b83a27de7..afece61d9 100644
--- a/drivers/gpio/gpiolib.c
+++ b/drivers/gpio/gpiolib.c
@@ -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);
diff --git a/include/gpio.h b/include/gpio.h
index e42fa2338..38d6ba2df 100644
--- a/include/gpio.h
+++ b/include/gpio.h
@@ -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);
-- 
2.17.1


_______________________________________________
barebox mailing list
barebox@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/barebox

^ permalink raw reply	[flat|nested] 19+ messages in thread

* [PATCH 08/11] commands: gpio: Allow GPIOs to be specified by label
  2018-10-27  1:31 [PATCH 00/11] Allow GPIOs to be referenced by label Andrey Smirnov
                   ` (6 preceding siblings ...)
  2018-10-27  1:31 ` [PATCH 07/11] gpiolib: Introduce gpio_find_by_label() Andrey Smirnov
@ 2018-10-27  1:31 ` Andrey Smirnov
  2018-10-27  1:31 ` [PATCH 09/11] VF610: zii-vf610-dev: Drop switch reset GPIO configuration Andrey Smirnov
                   ` (4 subsequent siblings)
  12 siblings, 0 replies; 19+ messages in thread
From: Andrey Smirnov @ 2018-10-27  1:31 UTC (permalink / raw)
  To: barebox; +Cc: Andrey Smirnov

Signed-off-by: Andrey Smirnov <andrew.smirnov@gmail.com>
---
 commands/gpio.c | 11 +++++++----
 1 file changed, 7 insertions(+), 4 deletions(-)

diff --git a/commands/gpio.c b/commands/gpio.c
index 3a2b8624f..951ad2c28 100644
--- a/commands/gpio.c
+++ b/commands/gpio.c
@@ -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);
-- 
2.17.1


_______________________________________________
barebox mailing list
barebox@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/barebox

^ permalink raw reply	[flat|nested] 19+ messages in thread

* [PATCH 09/11] VF610: zii-vf610-dev: Drop switch reset GPIO configuration
  2018-10-27  1:31 [PATCH 00/11] Allow GPIOs to be referenced by label Andrey Smirnov
                   ` (7 preceding siblings ...)
  2018-10-27  1:31 ` [PATCH 08/11] commands: gpio: Allow GPIOs to be specified by label Andrey Smirnov
@ 2018-10-27  1:31 ` Andrey Smirnov
  2018-10-27  1:31 ` [PATCH 10/11] VF610: zii-vf610-dev: Replace board code with gpio-hog nodes Andrey Smirnov
                   ` (3 subsequent siblings)
  12 siblings, 0 replies; 19+ messages in thread
From: Andrey Smirnov @ 2018-10-27  1:31 UTC (permalink / raw)
  To: barebox; +Cc: Andrey Smirnov

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

Signed-off-by: Andrey Smirnov <andrew.smirnov@gmail.com>
---
 arch/arm/boards/zii-vf610-dev/board.c | 5 -----
 1 file changed, 5 deletions(-)

diff --git a/arch/arm/boards/zii-vf610-dev/board.c b/arch/arm/boards/zii-vf610-dev/board.c
index 275d0a432..a8fa1ef61 100644
--- a/arch/arm/boards/zii-vf610-dev/board.c
+++ b/arch/arm/boards/zii-vf610-dev/board.c
@@ -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,
-- 
2.17.1


_______________________________________________
barebox mailing list
barebox@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/barebox

^ permalink raw reply	[flat|nested] 19+ messages in thread

* [PATCH 10/11] VF610: zii-vf610-dev: Replace board code with gpio-hog nodes
  2018-10-27  1:31 [PATCH 00/11] Allow GPIOs to be referenced by label Andrey Smirnov
                   ` (8 preceding siblings ...)
  2018-10-27  1:31 ` [PATCH 09/11] VF610: zii-vf610-dev: Drop switch reset GPIO configuration Andrey Smirnov
@ 2018-10-27  1:31 ` Andrey Smirnov
  2018-10-29 11:13   ` Sascha Hauer
  2018-10-27  1:31 ` [PATCH 11/11] ARM: rdu2: " Andrey Smirnov
                   ` (2 subsequent siblings)
  12 siblings, 1 reply; 19+ messages in thread
From: Andrey Smirnov @ 2018-10-27  1:31 UTC (permalink / raw)
  To: barebox; +Cc: Andrey Smirnov

Signed-off-by: Andrey Smirnov <andrew.smirnov@gmail.com>
---
 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(-)

diff --git a/arch/arm/boards/zii-vf610-dev/board.c b/arch/arm/boards/zii-vf610-dev/board.c
index a8fa1ef61..cb4216272 100644
--- a/arch/arm/boards/zii-vf610-dev/board.c
+++ b/arch/arm/boards/zii-vf610-dev/board.c
@@ -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;
diff --git a/arch/arm/dts/vf610-zii-cfu1.dts b/arch/arm/dts/vf610-zii-cfu1.dts
index 149333596..74ec9fd1d 100644
--- a/arch/arm/dts/vf610-zii-cfu1.dts
+++ b/arch/arm/dts/vf610-zii-cfu1.dts
@@ -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
diff --git a/arch/arm/dts/vf610-zii-ssmb-spu3.dts b/arch/arm/dts/vf610-zii-ssmb-spu3.dts
index 5b2460caf..6ffa1d958 100644
--- a/arch/arm/dts/vf610-zii-ssmb-spu3.dts
+++ b/arch/arm/dts/vf610-zii-ssmb-spu3.dts
@@ -14,3 +14,12 @@
 		switch-eeprom = &switch0;
 	};
 };
+
+&gpio3 {
+	e6352-intn {
+		gpio-hog;
+		gpios = <2 GPIO_ACTIVE_HIGH>;
+		input;
+		line-name = "e6352_intn";
+	};
+};
-- 
2.17.1


_______________________________________________
barebox mailing list
barebox@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/barebox

^ permalink raw reply	[flat|nested] 19+ messages in thread

* [PATCH 11/11] ARM: rdu2: Replace board code with gpio-hog nodes
  2018-10-27  1:31 [PATCH 00/11] Allow GPIOs to be referenced by label Andrey Smirnov
                   ` (9 preceding siblings ...)
  2018-10-27  1:31 ` [PATCH 10/11] VF610: zii-vf610-dev: Replace board code with gpio-hog nodes Andrey Smirnov
@ 2018-10-27  1:31 ` Andrey Smirnov
  2018-11-05 16:25   ` Andrey Smirnov
  2018-10-27  8:42 ` [PATCH 00/11] Allow GPIOs to be referenced by label Sam Ravnborg
  2018-10-29 11:14 ` Sascha Hauer
  12 siblings, 1 reply; 19+ messages in thread
From: Andrey Smirnov @ 2018-10-27  1:31 UTC (permalink / raw)
  To: barebox; +Cc: Andrey Smirnov

Signed-off-by: Andrey Smirnov <andrew.smirnov@gmail.com>
---
 arch/arm/boards/zii-imx6q-rdu2/board.c | 38 --------------------------
 arch/arm/dts/imx6qdl-zii-rdu2.dtsi     | 36 ++++++++++++++++++++++++
 2 files changed, 36 insertions(+), 38 deletions(-)

diff --git a/arch/arm/boards/zii-imx6q-rdu2/board.c b/arch/arm/boards/zii-imx6q-rdu2/board.c
index c99f993f0..e174032c9 100644
--- a/arch/arm/boards/zii-imx6q-rdu2/board.c
+++ b/arch/arm/boards/zii-imx6q-rdu2/board.c
@@ -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") &&
diff --git a/arch/arm/dts/imx6qdl-zii-rdu2.dtsi b/arch/arm/dts/imx6qdl-zii-rdu2.dtsi
index 3915c34df..a3f6dbd15 100644
--- a/arch/arm/dts/imx6qdl-zii-rdu2.dtsi
+++ b/arch/arm/dts/imx6qdl-zii-rdu2.dtsi
@@ -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
+		>;
+	};
+};
-- 
2.17.1


_______________________________________________
barebox mailing list
barebox@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/barebox

^ permalink raw reply	[flat|nested] 19+ messages in thread

* Re: [PATCH 00/11] Allow GPIOs to be referenced by label
  2018-10-27  1:31 [PATCH 00/11] Allow GPIOs to be referenced by label Andrey Smirnov
                   ` (10 preceding siblings ...)
  2018-10-27  1:31 ` [PATCH 11/11] ARM: rdu2: " Andrey Smirnov
@ 2018-10-27  8:42 ` Sam Ravnborg
  2018-10-29 11:17   ` Sascha Hauer
  2018-10-29 11:14 ` Sascha Hauer
  12 siblings, 1 reply; 19+ messages in thread
From: Sam Ravnborg @ 2018-10-27  8:42 UTC (permalink / raw)
  To: Andrey Smirnov; +Cc: barebox

Hi Andrey.

> 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.

> 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
barebox@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/barebox

^ permalink raw reply	[flat|nested] 19+ messages in thread

* Re: [PATCH 10/11] VF610: zii-vf610-dev: Replace board code with gpio-hog nodes
  2018-10-27  1:31 ` [PATCH 10/11] VF610: zii-vf610-dev: Replace board code with gpio-hog nodes Andrey Smirnov
@ 2018-10-29 11:13   ` Sascha Hauer
  2018-10-29 17:14     ` Andrey Smirnov
  0 siblings, 1 reply; 19+ messages in thread
From: Sascha Hauer @ 2018-10-29 11:13 UTC (permalink / raw)
  To: Andrey Smirnov; +Cc: barebox

On Fri, Oct 26, 2018 at 06:31:56PM -0700, Andrey Smirnov wrote:
> diff --git a/arch/arm/dts/vf610-zii-cfu1.dts b/arch/arm/dts/vf610-zii-cfu1.dts
> index 149333596..74ec9fd1d 100644
> --- a/arch/arm/dts/vf610-zii-cfu1.dts
> +++ b/arch/arm/dts/vf610-zii-cfu1.dts
> @@ -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";
> +	};
> +};

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


-- 
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
barebox@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/barebox

^ permalink raw reply	[flat|nested] 19+ messages in thread

* Re: [PATCH 00/11] Allow GPIOs to be referenced by label
  2018-10-27  1:31 [PATCH 00/11] Allow GPIOs to be referenced by label Andrey Smirnov
                   ` (11 preceding siblings ...)
  2018-10-27  8:42 ` [PATCH 00/11] Allow GPIOs to be referenced by label Sam Ravnborg
@ 2018-10-29 11:14 ` Sascha Hauer
  12 siblings, 0 replies; 19+ messages in thread
From: Sascha Hauer @ 2018-10-29 11:14 UTC (permalink / raw)
  To: Andrey Smirnov; +Cc: barebox

On Fri, Oct 26, 2018 at 06:31:46PM -0700, Andrey Smirnov wrote:
> 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

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

Sascha


-- 
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
barebox@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/barebox

^ permalink raw reply	[flat|nested] 19+ messages in thread

* Re: [PATCH 00/11] Allow GPIOs to be referenced by label
  2018-10-27  8:42 ` [PATCH 00/11] Allow GPIOs to be referenced by label Sam Ravnborg
@ 2018-10-29 11:17   ` Sascha Hauer
  0 siblings, 0 replies; 19+ messages in thread
From: Sascha Hauer @ 2018-10-29 11:17 UTC (permalink / raw)
  To: Sam Ravnborg; +Cc: Andrey Smirnov, barebox

On Sat, Oct 27, 2018 at 10:42:35AM +0200, Sam Ravnborg wrote:
> Hi Andrey.
> 
> > 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.
> 
> > 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.

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

-- 
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
barebox@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/barebox

^ permalink raw reply	[flat|nested] 19+ messages in thread

* Re: [PATCH 10/11] VF610: zii-vf610-dev: Replace board code with gpio-hog nodes
  2018-10-29 11:13   ` Sascha Hauer
@ 2018-10-29 17:14     ` Andrey Smirnov
  0 siblings, 0 replies; 19+ messages in thread
From: Andrey Smirnov @ 2018-10-29 17:14 UTC (permalink / raw)
  To: Sascha Hauer; +Cc: Barebox List

On Mon, Oct 29, 2018 at 4:13 AM Sascha Hauer <s.hauer@pengutronix.de> wrote:
>
> On Fri, Oct 26, 2018 at 06:31:56PM -0700, Andrey Smirnov wrote:
> > diff --git a/arch/arm/dts/vf610-zii-cfu1.dts b/arch/arm/dts/vf610-zii-cfu1.dts
> > index 149333596..74ec9fd1d 100644
> > --- a/arch/arm/dts/vf610-zii-cfu1.dts
> > +++ b/arch/arm/dts/vf610-zii-cfu1.dts
> > @@ -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";
> > +     };
> > +};
>
> 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
barebox@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/barebox

^ permalink raw reply	[flat|nested] 19+ messages in thread

* Re: [PATCH 11/11] ARM: rdu2: Replace board code with gpio-hog nodes
  2018-10-27  1:31 ` [PATCH 11/11] ARM: rdu2: " Andrey Smirnov
@ 2018-11-05 16:25   ` Andrey Smirnov
  2018-11-06  8:25     ` Sascha Hauer
  0 siblings, 1 reply; 19+ messages in thread
From: Andrey Smirnov @ 2018-11-05 16:25 UTC (permalink / raw)
  To: Barebox List

On Fri, Oct 26, 2018 at 6:32 PM Andrey Smirnov <andrew.smirnov@gmail.com> wrote:
>
> Signed-off-by: Andrey Smirnov <andrew.smirnov@gmail.com>

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
barebox@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/barebox

^ permalink raw reply	[flat|nested] 19+ messages in thread

* Re: [PATCH 11/11] ARM: rdu2: Replace board code with gpio-hog nodes
  2018-11-05 16:25   ` Andrey Smirnov
@ 2018-11-06  8:25     ` Sascha Hauer
  0 siblings, 0 replies; 19+ messages in thread
From: Sascha Hauer @ 2018-11-06  8:25 UTC (permalink / raw)
  To: Andrey Smirnov; +Cc: Barebox List

On Mon, Nov 05, 2018 at 08:25:44AM -0800, Andrey Smirnov wrote:
> On Fri, Oct 26, 2018 at 6:32 PM Andrey Smirnov <andrew.smirnov@gmail.com> wrote:
> >
> > Signed-off-by: Andrey Smirnov <andrew.smirnov@gmail.com>
> 
> 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


-- 
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
barebox@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/barebox

^ permalink raw reply	[flat|nested] 19+ messages in thread

end of thread, other threads:[~2018-11-06  8:25 UTC | newest]

Thread overview: 19+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2018-10-27  1:31 [PATCH 00/11] Allow GPIOs to be referenced by label Andrey Smirnov
2018-10-27  1:31 ` [PATCH 01/11] gpio: VF610: Propagate error code of gpiochip_add() up Andrey Smirnov
2018-10-27  1:31 ` [PATCH 02/11] VF610: Initialize pinctrl driver before gpio Andrey Smirnov
2018-10-27  1:31 ` [PATCH 03/11] linux/ctype.h: Port _tolower() Andrey Smirnov
2018-10-27  1:31 ` [PATCH 04/11] lib: Port kstrtox.c from Linux kernel Andrey Smirnov
2018-10-27  1:31 ` [PATCH 05/11] commands: gpio: Move argument parsing into a shared function Andrey Smirnov
2018-10-27  1:31 ` [PATCH 06/11] commands: gpio: Use kstrtoint() instead of simple_strtoul() Andrey Smirnov
2018-10-27  1:31 ` [PATCH 07/11] gpiolib: Introduce gpio_find_by_label() Andrey Smirnov
2018-10-27  1:31 ` [PATCH 08/11] commands: gpio: Allow GPIOs to be specified by label Andrey Smirnov
2018-10-27  1:31 ` [PATCH 09/11] VF610: zii-vf610-dev: Drop switch reset GPIO configuration Andrey Smirnov
2018-10-27  1:31 ` [PATCH 10/11] VF610: zii-vf610-dev: Replace board code with gpio-hog nodes Andrey Smirnov
2018-10-29 11:13   ` Sascha Hauer
2018-10-29 17:14     ` Andrey Smirnov
2018-10-27  1:31 ` [PATCH 11/11] ARM: rdu2: " Andrey Smirnov
2018-11-05 16:25   ` Andrey Smirnov
2018-11-06  8:25     ` Sascha Hauer
2018-10-27  8:42 ` [PATCH 00/11] Allow GPIOs to be referenced by label Sam Ravnborg
2018-10-29 11:17   ` Sascha Hauer
2018-10-29 11:14 ` Sascha Hauer

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox