Skip to contentSkip to conversation

M28: Added pin name support in GPIO driver

PATCH New Robert Deliën 2 participants 4 messages Nov 23, 2011 – Nov 24, 2011

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

PATCH v3 1/1 M28: Added pin name support in GPIO driver

This patch adds pin name support in the GPIO driver. With this patch applied, the gpio command supports pins to be addressed with friendly names.

Please note:
Function gpio_name_to_pin checks for set bits getting lost in translation and returns -EINVAL if this occurs, but a correctly translated name doesn't automatically produce a valid pin. It only means the bank/pin numbers fit the designated bitfields. After successful translation, validity needs to be checked separately.

arch/arm/include/asm/arch-mx28/gpio.h +3 -0
index 5abd7b1..37d3e88 100644
@@ -26,6 +26,9 @@
 #ifdef	CONFIG_MXS_GPIO
 void mxs_gpio_init(void);
 
+extern int gpio_name_to_pin(const char *name);
+#define gpio_name_to_pin(name)	gpio_name_to_pin(name)
+
 extern int gpio_invalid(int gp);
 #define gpio_invalid(gpio) gpio_invalid(gpio)
 
arch/blackfin/include/asm/gpio.h +21 -4
index 224688f..8128df1 100644
@@ -1,7 +1,24 @@
 /*
- * Copyright 2006-2009 Analog Devices Inc.
+ * (C) Copyright 2006-2009
+ * Analog Devices Inc.
  *
- * Licensed under the GPL-2 or later.
+ * See file CREDITS for list of people who contributed to this
+ * project.
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU General Public License as
+ * published by the Free Software Foundation; either version 2 of
+ * the License, or (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 59 Temple Place, Suite 330, Boston,
+ * MA 02111-1307 USA
  */
 
 #ifndef __ARCH_BLACKFIN_GPIO_H__
@@ -199,7 +216,7 @@ static inline int gpio_is_valid(int number)
 
 #include <linux/ctype.h>
 
-static inline int name_to_gpio(const char *name)
+static inline int gpio_name_to_pin(const char *name)
 {
 	int port_base;
 
@@ -246,7 +263,7 @@ static inline int name_to_gpio(const char *name)
 
 	return port_base + simple_strtoul(name, NULL, 10);
 }
-#define name_to_gpio(n) name_to_gpio(n)
+#define gpio_name_to_pin(n) gpio_name_to_pin(n)
 
 #define gpio_status() bfin_gpio_labels()
 
common/cmd_gpio.c +29 -10
index 51e11e7..8a70d0c 100644
@@ -1,9 +1,24 @@
 /*
- * Control GPIO pins on the fly
+ * (C) Copyright 2008-2011
+ * Analog Devices Inc.
  *
- * Copyright (c) 2008-2011 Analog Devices Inc.
+ * See file CREDITS for list of people who contributed to this
+ * project.
  *
- * Licensed under the GPL-2 or later.
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU General Public License as
+ * published by the Free Software Foundation; either version 2 of
+ * the License, or (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 59 Temple Place, Suite 330, Boston,
+ * MA 02111-1307 USA
  */
 
 #include <common.h>
@@ -11,8 +26,8 @@
 
 #include <asm/gpio.h>
 
-#ifndef name_to_gpio
-#define name_to_gpio(name) simple_strtoul(name, NULL, 10)
+#ifndef gpio_name_to_pin
+#define gpio_name_to_pin(name)	simple_strtoul(name, NULL, 10)
 #endif
 
 #ifndef gpio_invalid
@@ -41,8 +56,8 @@ static int do_gpio(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[])
 #endif
 
 	if (argc != 3)
- show_usage:
-		return cmd_usage(cmdtp);
+		goto show_usage;
+
 	str_cmd = argv[1];
 	str_gpio = argv[2];
 
@@ -56,9 +71,11 @@ static int do_gpio(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[])
 	}
 
 	/* turn the gpio name into a gpio number */
-	gpio = name_to_gpio(str_gpio);
-	if (gpio < 0)
-		goto show_usage;
+	gpio = gpio_name_to_pin(str_gpio);
+	if (gpio < 0) {
+		printf("gpio: unknown pin %s\n", str_gpio);
+		return -1;
+	}
 
 	/* check bank and pin number for validity */
 	if (gpio_invalid(gpio)) {
@@ -91,6 +108,8 @@ static int do_gpio(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[])
 	gpio_free(gpio);
 
 	return value;
+show_usage:
+	return cmd_usage(cmdtp);
 }
 
 U_BOOT_CMD(gpio, 3, 0, do_gpio,
drivers/gpio/mxs_gpio.c +41 -0

53 lines not on this page · raw message

#1 lore raw

PATCH v3 1/1 M28: Added pin name support in GPIO driver

Quoted 3 lines · On Wednesday 23 November 2011 16:10:49 Robert Deli?n wrote:

This patch adds pin name support in the GPIO driver. With this patch applied, the gpio command supports pins to be addressed with friendly names.

this patch is mangled as well

Quoted 17 lines
arch/blackfin/include/asm/gpio.h +10 -2
 
 /*
- * Copyright 2006-2009 Analog Devices Inc.
+ * (C) Copyright 2006-2009
+ * Analog Devices Inc.
  *
- * Licensed under the GPL-2 or later.
+ * See file CREDITS for list of people who contributed to this
+ * project.
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU General Public License as
+ * published by the Free Software Foundation; either version 2 of
+ * the License, or (at your option) any later version.
+ *

arch/blackfin/include/asm/gpio.h line 22

Quoted 10 lines
arch/blackfin/include/asm/gpio.h +9 -0
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 59 Temple Place, Suite 330, Boston,
+ * MA 02111-1307 USA
  */

NAK: don't monkey with unrelated stuff

Quoted 18 lines
common/cmd_gpio.c +9 -3
 
 /*
- * Control GPIO pins on the fly
+ * (C) Copyright 2008-2011
+ * Analog Devices Inc.
  *
- * Copyright (c) 2008-2011 Analog Devices Inc.
+ * See file CREDITS for list of people who contributed to this
+ * project.
  *
- * Licensed under the GPL-2 or later.
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU General Public License as
+ * published by the Free Software Foundation; either version 2 of
+ * the License, or (at your option) any later version.
+ *

common/cmd_gpio.c line 22

Quoted 10 lines
common/cmd_gpio.c +9 -0
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 59 Temple Place, Suite 330, Boston,
+ * MA 02111-1307 USA
  */

NAK: don't monkey with unrelated stuff

Quoted 24 lines
common/cmd_gpio.c +7 -5
 	if (argc != 3)
- show_usage:
-		return cmd_usage(cmdtp);
+		goto show_usage;
+
 	str_cmd = argv[1];
 	str_gpio = argv[2];
@@ -56,9 +71,11 @@ static int do_gpio(cmd_tbl_t *cmdtp, int flag, int argc,
 char * const argv[]) }
 
 	/* turn the gpio name into a gpio number */
-	gpio = name_to_gpio(str_gpio);
-	if (gpio < 0)
-		goto show_usage;
+	gpio = gpio_name_to_pin(str_gpio);
+	if (gpio < 0) {
+		printf("gpio: unknown pin %s\n", str_gpio);
+		return -1;
+	}
 
 	/* check bank and pin number for validity */
 	if (gpio_invalid(gpio)) {

common/cmd_gpio.c static int do_gpio(cmd_tbl_t *cmdtp, int flag, int argc, · line 113

Quoted 6 lines
common/cmd_gpio.c +2 -0
@@ -91,6 +108,8 @@ static int do_gpio(cmd_tbl_t *cmdtp, int flag, int argc,
 char * const argv[]) gpio_free(gpio);
 
 	return value;
+show_usage:
+	return cmd_usage(cmdtp);
 }

do not mix style and functional changes. i see no reason to change the code flow here.
-mike
-------------- next part --------------
A non-text attachment was scrubbed...
Name: not available
Type: application/pgp-signature
Size: 836 bytes
Desc: This is a digitally signed message part.
URL: <http://lists.denx.de/pipermail/u-boot/attachments/20111123/d1c8ad69/attachment.pgp>

#2 lore raw

PATCH v3 1/1 M28: Added pin name support in GPIO driver

In reply to Robert Deliën

common/cmd_gpio.c line 31

Quoted 5 lines · On Wednesday 23 November 2011 16:10:49 Robert Deli?n wrote:
common/cmd_gpio.c +2 -2
-#ifndef name_to_gpio
-#define name_to_gpio(name) simple_strtoul(name, NULL, 10)
+#ifndef gpio_name_to_pin
+#define gpio_name_to_pin(name)	simple_strtoul(name, NULL, 10)
 #endif

as for the underlying reason, i don't have a problem with renaming things. but the reason i picked "name_to_gpio" instead of "gpio_to_name" was that this is not part of the Linux GPIO API. i didn't want to use a name that'd end up clashing. but i guess the naming convention didn't translate well and it just confuses people.

gpio_to_name() should be fine. no need to mention "pin" in there.
-mike
-------------- next part --------------
A non-text attachment was scrubbed...
Name: not available
Type: application/pgp-signature
Size: 836 bytes
Desc: This is a digitally signed message part.
URL: <http://lists.denx.de/pipermail/u-boot/attachments/20111123/b6186a63/attachment.pgp>

#3 lore raw

PATCH v3 1/1 M28: Added pin name support in GPIO driver

Quoted 6 lines · On Wednesday 23 November 2011 17:33:02 Mike Frysinger wrote:
Quoted 5 lines · On Wednesday 23 November 2011 16:10:49 Robert Deli?n wrote:
common/cmd_gpio.c +2 -2
-#ifndef name_to_gpio
-#define name_to_gpio(name) simple_strtoul(name, NULL, 10)
+#ifndef gpio_name_to_pin
+#define gpio_name_to_pin(name)	simple_strtoul(name, NULL, 10)
Quoted 7 lines
Quoted 1 line

#endif

as for the underlying reason, i don't have a problem with renaming things. but the reason i picked "name_to_gpio" instead of "gpio_to_name" was that this is not part of the Linux GPIO API. i didn't want to use a name that'd end up clashing. but i guess the naming convention didn't translate well and it just confuses people.

actually, i lied. it's called "name_to_gpio" because it's converting from a name to a gpio. which is i why i guess you had "pin" in there.

the framework doesn't require everything start with "gpio". the Linux API already uses "irq_to_gpio" and "gpio_to_irq". so let's keep it "name_to_gpio" as it's more straightforward imo.
-mike
-------------- next part --------------
A non-text attachment was scrubbed...
Name: not available
Type: application/pgp-signature
Size: 836 bytes
Desc: This is a digitally signed message part.
URL: <http://lists.denx.de/pipermail/u-boot/attachments/20111124/e11957a0/attachment.pgp>