Skip to contentSkip to conversation

gpio: mxs: add name_to_gpio() function

PATCH New Mans Rullgard 2 participants 2 messages Dec 15, 2015 – Jan 3, 2016

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

PATCH 1/1 gpio: mxs: add name_to_gpio() function

Override the default name_to_gpio() function with one that accepts strings of the form bank:pin. If a colon is present in the provided name, it behaves like the default version.

This lets the "gpio" command work with sane names rather than requiring the user to enter the bank/pin composite in decimal.

---
 drivers/gpio/mxs_gpio.c | 15 +++++++++++++++
 1 file changed, 15 insertions(+)
drivers/gpio/mxs_gpio.c +15 -0
index da0199b..b54a10b 100644
@@ -114,3 +114,18 @@ int gpio_free(unsigned gpio)
 {
 	return 0;
 }
+
+int name_to_gpio(const char *name)
+{
+	unsigned bank, pin;
+	char *end;
+
+	bank = simple_strtoul(name, &end, 10);
+
+	if (!*end || *end != ':')
+		return bank;
+
+	pin = simple_strtoul(end + 1, NULL, 10);
+
+	return (bank << MXS_PAD_BANK_SHIFT) | (pin << MXS_PAD_PIN_SHIFT);
+}
Signature · 1 line
2.6.3
#1 lore raw

PATCH 1/1 gpio: mxs: add name_to_gpio() function

Quoted 26 lines · Mans Rullgard

Override the default name_to_gpio() function with one that accepts strings of the form bank:pin. If a colon is present in the provided name, it behaves like the default version.

This lets the "gpio" command work with sane names rather than requiring the user to enter the bank/pin composite in decimal.

---
 drivers/gpio/mxs_gpio.c | 15 +++++++++++++++
 1 file changed, 15 insertions(+)
drivers/gpio/mxs_gpio.c +5 -0
index da0199b..b54a10b 100644
@@ -114,3 +114,18 @@ int gpio_free(unsigned gpio)
 {
 	return 0;
 }
+
+int name_to_gpio(const char *name)
+{
+	unsigned bank, pin;
+	char *end;

drivers/gpio/mxs_gpio.c int gpio_free(unsigned gpio) · line 131

Quoted 10 lines
drivers/gpio/mxs_gpio.c +10 -0
+
+	bank = simple_strtoul(name, &end, 10);
+
+	if (!*end || *end != ':')
+		return bank;
+
+	pin = simple_strtoul(end + 1, NULL, 10);
+
+	return (bank << MXS_PAD_BANK_SHIFT) | (pin << MXS_PAD_PIN_SHIFT);
+}

Best regards,
Stefano Babic

Signature · 5 lines
=====================================================================
DENX Software Engineering GmbH,      Managing Director: Wolfgang Denk
HRB 165235 Munich, Office: Kirchenstr.5, D-82194 Groebenzell, Germany
Phone: +49-8142-66989-53 Fax: +49-8142-66989-80 Email: sbabic at denx.de
=====================================================================