Skip to contentSkip to conversation

GPIO: Tegra2: add GPIO driver for Tegra2

PATCH Superseded Tom Warren 2 participants 5 messages Jun 16, 2011 – Jun 17, 2011

Subsystems (3)

v4 of 5 Superseded Latest is v5 →

lore
Share & tools
lore

Tom Warren

author
#0 lore raw

v4 cover GPIO: Tegra2: add GPIO driver for Tegra2

This patchset adds a GPIO driver for Tegra2 SoC, and enables it for all boards

Changes in V2:
- use 'gpio_pin' enum in gpio.h (Simon Glass review request)
- change 'GPIO_PORT8' to 'GPIO_FULLPORT' (Simon Glass request)
- change 'offset' to 'pin' globally
- enable GPIO for all boards (tegra2-common.h)
Changes in V3:
- use common cmd_gpio; remove redundant cmd processing code
- add gpio_request, gpio_free and gpio_toggle
- alias 'gpio_status' to 'gpio_info' for use in cmd_gpio
Changes in V4:
- update code as per Mike Frysinger's review comments
- rewrite gpio_info, aka gpio_status

Tom Warren (2):
GPIO: Tegra2: add GPIO driver for Tegra2
arm: Tegra2: GPIO: enable GPIO for Tegra2 boards

 arch/arm/include/asm/arch-tegra2/gpio.h |  250 +++++++++++++++++++++++++++++--
 arch/arm/include/asm/gpio.h             |   38 +++++
 drivers/gpio/Makefile                   |    1 +
 drivers/gpio/tegra2_gpio.c              |  254 +++++++++++++++++++++++++++++++
 include/configs/tegra2-common.h         |    2 +
 5 files changed, 535 insertions(+), 10 deletions(-)
 create mode 100644 arch/arm/include/asm/gpio.h
 create mode 100644 drivers/gpio/tegra2_gpio.c
Signature · 1 line
1.7.5.4
author
#1 lore raw

PATCH v4 1/2 GPIO: Tegra2: add GPIO driver for Tegra2

---
Changes in V2:
- use 'gpio_pin' enum in gpio.h (Simon Glass review request)
- change 'GPIO_PORT8' to 'GPIO_FULLPORT' (Simon Glass request)
- change 'offset' to 'pin' globally
Changes in V3:
- use common cmd_gpio; remove redundant cmd processing code
- add gpio_request, gpio_free and gpio_toggle
- alias 'gpio_status' to 'gpio_info' for use in cmd_gpio
Changes in V4:
- update code as per Mike Frysinger's review comments
- rewrite gpio_info, aka gpio_status

 arch/arm/include/asm/arch-tegra2/gpio.h |  250 +++++++++++++++++++++++++++++--
 arch/arm/include/asm/gpio.h             |   38 +++++
 drivers/gpio/Makefile                   |    1 +
 drivers/gpio/tegra2_gpio.c              |  254 +++++++++++++++++++++++++++++++
 4 files changed, 533 insertions(+), 10 deletions(-)
 create mode 100644 arch/arm/include/asm/gpio.h
 create mode 100644 drivers/gpio/tegra2_gpio.c
arch/arm/include/asm/arch-tegra2/gpio.h +240 -10
index 0fb8f0d..41e66fe 100644
@@ -23,11 +23,13 @@
 #define _TEGRA2_GPIO_H_
 
 /*
- * The Tegra 2x GPIO controller has 222 GPIOs arranged in 8 banks of 4 ports,
+ * The Tegra 2x GPIO controller has 224 GPIOs arranged in 7 banks of 4 ports,
  * each with 8 GPIOs.
  */
-#define TEGRA_GPIO_PORTS 4   /* The number of ports per bank */
-#define TEGRA_GPIO_BANKS 8   /* The number of banks */
+#define TEGRA_GPIO_PORTS	4	/* number of ports per bank */
+#define TEGRA_GPIO_BANKS	7	/* number of banks */
+#define MAX_NUM_GPIOS		(TEGRA_GPIO_PORTS * TEGRA_GPIO_BANKS * 8)
+#define GPIO_NAME_SIZE		20	/* gpio_request max label len */
 
 /* GPIO Controller registers for a single bank */
 struct gpio_ctlr_bank {
@@ -45,15 +47,243 @@ struct gpio_ctlr {
 	struct gpio_ctlr_bank gpio_bank[TEGRA_GPIO_BANKS];
 };
 
-#define GPIO_BANK(x)	((x) >> 5)
-#define GPIO_PORT(x)	(((x) >> 3) & 0x3)
-#define GPIO_BIT(x)	((x) & 0x7)
+#define GPIO_BANK(x)		((x) >> 5)
+#define GPIO_PORT(x)		(((x) >> 3) & 0x3)
+#define GPIO_FULLPORT(x)	((x) >> 3)
+#define GPIO_BIT(x)		((x) & 0x7)
+
+enum gpio_pin {
+	GPIO_PA0 = 0,	/* pin 0 */
+	GPIO_PA1,
+	GPIO_PA2,
+	GPIO_PA3,
+	GPIO_PA4,
+	GPIO_PA5,
+	GPIO_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
+	GPIO_PU1,
+	GPIO_PU2,
+	GPIO_PU3,
+	GPIO_PU4,
+	GPIO_PU5,
+	GPIO_PU6,
+	GPIO_PU7,
+	GPIO_PV0,	/* pin 168 */
+	GPIO_PV1,
+	GPIO_PV2,
+	GPIO_PV3,
+	GPIO_PV4,
+	GPIO_PV5,
+	GPIO_PV6,
+	GPIO_PV7,
+	GPIO_PW0,	/* pin 176 */
+	GPIO_PW1,
+	GPIO_PW2,
+	GPIO_PW3,
+	GPIO_PW4,
+	GPIO_PW5,
+	GPIO_PW6,
+	GPIO_PW7,
+	GPIO_PX0,	/* pin 184 */
+	GPIO_PX1,
+	GPIO_PX2,
+	GPIO_PX3,
+	GPIO_PX4,
+	GPIO_PX5,
+	GPIO_PX6,
+	GPIO_PX7,
+	GPIO_PY0,	/* pin 192 */
+	GPIO_PY1,
+	GPIO_PY2,
+	GPIO_PY3,
+	GPIO_PY4,
+	GPIO_PY5,
+	GPIO_PY6,
+	GPIO_PY7,
+	GPIO_PZ0,	/* pin 200 */
+	GPIO_PZ1,
+	GPIO_PZ2,
+	GPIO_PZ3,
+	GPIO_PZ4,
+	GPIO_PZ5,
+	GPIO_PZ6,
+	GPIO_PZ7,
+	GPIO_PAA0,	/* pin 208 */
+	GPIO_PAA1,
+	GPIO_PAA2,
+	GPIO_PAA3,
+	GPIO_PAA4,
+	GPIO_PAA5,
+	GPIO_PAA6,
+	GPIO_PAA7,
+	GPIO_PBB0,	/* pin 216 */
+	GPIO_PBB1,
+	GPIO_PBB2,
+	GPIO_PBB3,
+	GPIO_PBB4,
+	GPIO_PBB5,
+	GPIO_PBB6,
+	GPIO_PBB7,	/* pin 223 */
+};
 
 /*
- * GPIO_PI3 = Port I = 8, bit = 3.
- * Seaboard: used for UART/SPI selection
- * Harmony: not used
+ * Tegra2-specific GPIO API
  */
-#define GPIO_PI3	((8 << 3) | 3)
 
+void gpio_info(void);
+
+#define gpio_status()	gpio_info()
 #endif	/* TEGRA2_GPIO_H_ */
arch/arm/include/asm/gpio.h new file +38 -0
new file mode 100644
index 0000000..eb071d1
@@ -0,0 +1,38 @@
+/*
+ * Copyright (c) 2011, NVIDIA Corp. All rights reserved.
+ * 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 _GPIO_H_
+#define _GPIO_H_
+
+#include <asm/arch/gpio.h>
+/*
+ * Generic GPIO API
+ */
+
+int gpio_request(int gp, const char *label);
+void gpio_free(int gp);
+void gpio_toggle_value(int gp);
+int gpio_direction_input(int gp);
+int gpio_direction_output(int gp, int value);
+int gpio_get_value(int gp);
+void gpio_set_value(int gp, int value);
+
+#endif	/* _GPIO_H_ */
drivers/gpio/Makefile +1 -0
index a5fa2b5..1e3ae11 100644
@@ -31,6 +31,7 @@ COBJS-$(CONFIG_MARVELL_MFP)	+= mvmfp.o
 COBJS-$(CONFIG_MXC_GPIO)	+= mxc_gpio.o
 COBJS-$(CONFIG_PCA953X)		+= pca953x.o
 COBJS-$(CONFIG_S5P)		+= s5p_gpio.o
+COBJS-$(CONFIG_TEGRA2_GPIO)	+= tegra2_gpio.o
 
 COBJS	:= $(COBJS-y)
 SRCS 	:= $(COBJS:.o=.c)
drivers/gpio/tegra2_gpio.c new file +254 -0

254 lines not on this page · raw message

Signature · 1 line
1.7.5.4
author
#4 lore raw

PATCH v4 2/2 arm: Tegra2: GPIO: enable GPIO for Tegra2 boards

In reply to Tom Warren

---
Changes in V2:
- enable GPIO for all boards (tegra2-common.h)
Changes in V3:
- enable use of common cmd_gpio

 include/configs/tegra2-common.h |    2 ++
 1 files changed, 2 insertions(+), 0 deletions(-)
include/configs/tegra2-common.h +2 -0
index febce35..295ee11 100644
@@ -160,4 +160,6 @@
 						CONFIG_SYS_INIT_RAM_SIZE - \
 						GENERATED_GBL_DATA_SIZE)
 
+#define CONFIG_TEGRA2_GPIO
+#define CONFIG_CMD_GPIO
 #endif /* __TEGRA2_COMMON_H */
Signature · 1 line
1.7.5.4
#2 lore raw

PATCH v4 1/2 GPIO: Tegra2: add GPIO driver for Tegra2

In reply to Tom Warren

drivers/gpio/tegra2_gpio.c line 149

Quoted 6 lines · On Thursday, June 16, 2011 19:51:33 Tom Warren wrote:
drivers/gpio/tegra2_gpio.c new file +6 -0
+int gpio_request(int gp, const char *label)
+{
+	if (gp >= MAX_NUM_GPIOS)
+		return -1;
+
+	strncpy(gpio_names[gp].name, label, GPIO_NAME_SIZE);

if the label is >=GPIO_NAME_SIZE, the result will not be NUL terminated. i'd suggest you add something like this to after the strncpy call:

	gpio_names[gp].name[GPIO_NAME_SIZE - 1] = '\0';

Review

Quoted 1 line
(quoted diff) +1 -0
+	return (val >> GPIO_BIT(gp)) & 1;

could be written as !!(val >> GPIO_BIT(gp)), but up to you, or see how the code size works out

otherwise, looks fine. not that i looked too closely as i dont know anything about Tegra2 parts.
-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/20110616/8fd28e78/attachment.pgp

author
#3 lore raw

PATCH v4 1/2 GPIO: Tegra2: add GPIO driver for Tegra2

Mike,

Quoted 11 lines · Mike Frysinger

drivers/gpio/tegra2_gpio.c

Quoted 6 lines · On Thursday, June 16, 2011 19:51:33 Tom Warren wrote:
drivers/gpio/tegra2_gpio.c new file +6 -0
+int gpio_request(int gp, const char *label)
+{
+ ? ? if (gp >= MAX_NUM_GPIOS)
+ ? ? ? ? ? ? return -1;
+
+ ? ? strncpy(gpio_names[gp].name, label, GPIO_NAME_SIZE);

if the label is >=GPIO_NAME_SIZE, the result will not be NUL terminated. ?i'd suggest you add something like this to after the strncpy call:
? ? ? ?gpio_names[gp].name[GPIO_NAME_SIZE - 1] = '\0';

Will do. Thanks for the quick response!

Quoted 5 lines
Quoted 2 lines

+ ? ? return (val >> GPIO_BIT(gp)) & 1;

could be written as !!(val >> GPIO_BIT(gp)), but up to you, or see how the code size works out

I'll check it and update if your way is smaller. Thanks.

Quoted 5 lines

otherwise, looks fine. ?not that i looked too closely as i dont know anything about Tegra2 parts.
-mike

Thanks,

Tom