[U-Boot] [RFC PATCH 12/14] dm: tegra: Don't used named GPIOs in SPL

Simon Glass sjg at chromium.org
Wed Sep 24 01:30:06 CEST 2014


There is little point in supporting this, and it bloats the code.

(This may be moved into the uclass before final submission)

Signed-off-by: Simon Glass <sjg at chromium.org>
---

 drivers/gpio/tegra_gpio.c | 40 +++++++++++++++++++++++++++++++++++-----
 1 file changed, 35 insertions(+), 5 deletions(-)

diff --git a/drivers/gpio/tegra_gpio.c b/drivers/gpio/tegra_gpio.c
index 1cc4abb..39852b2 100644
--- a/drivers/gpio/tegra_gpio.c
+++ b/drivers/gpio/tegra_gpio.c
@@ -37,9 +37,15 @@ struct tegra_gpio_platdata {
 	int base_gpio;		/* Port number for this port (0, 1,.., n-1) */
 };
 
+#ifndef CONFIG_SPL_BUILD
+#define NAMED_PORTS
+#endif
+
 /* Information about each port at run-time */
 struct tegra_port_info {
+#ifdef NAMED_PORTS
 	char label[TEGRA_GPIOS_PER_PORT][GPIO_NAME_SIZE];
+#endif
 	struct gpio_ctlr_bank *bank;
 	int base_gpio;		/* Port number for this port (0, 1,.., n-1) */
 };
@@ -132,13 +138,29 @@ static void set_level(unsigned gpio, int high)
 	writel(u, &bank->gpio_out[GPIO_PORT(gpio)]);
 }
 
+/**
+ * gpio_is_requested() - check if a GPIO has been requested
+ *
+ * @state:	Bank to check
+ * @offset:	GPIO offset within bank to check
+ * @return true if marked as requested, false if not
+ */
+static inline bool gpio_is_requested(struct tegra_port_info *state, int offset)
+{
+#ifdef NAMED_PORTS
+	return *state->label[offset] != '\0';
+#else
+	return true;
+#endif
+}
+
 static int check_reserved(struct udevice *dev, unsigned offset,
 			  const char *func)
 {
 	struct tegra_port_info *state = dev_get_priv(dev);
 	struct gpio_dev_priv *uc_priv = dev->uclass_priv;
 
-	if (!*state->label[offset]) {
+	if (!gpio_is_requested(state, offset)) {
 		printf("tegra_gpio: %s: error: gpio %s%d not reserved\n",
 		       func, uc_priv->bank_name, offset);
 		return -EBUSY;
@@ -171,12 +193,12 @@ static int tegra_gpio_request(struct udevice *dev, unsigned offset,
 {
 	struct tegra_port_info *state = dev_get_priv(dev);
 
-	if (*state->label[offset])
+#ifdef NAMED_PORTS
+	if (gpio_is_requested(state, offset))
 		return -EBUSY;
-
 	strncpy(state->label[offset], label, GPIO_NAME_SIZE);
 	state->label[offset][GPIO_NAME_SIZE - 1] = '\0';
-
+#endif
 	/* Configure as a GPIO */
 	set_config(state->base_gpio + offset, 1);
 
@@ -185,13 +207,17 @@ static int tegra_gpio_request(struct udevice *dev, unsigned offset,
 
 static int tegra_gpio_free(struct udevice *dev, unsigned offset)
 {
+#ifdef NAMED_PORTS
 	struct tegra_port_info *state = dev_get_priv(dev);
+#endif
 	int ret;
 
 	ret = check_reserved(dev, offset, __func__);
 	if (ret)
 		return ret;
+#ifdef NAMED_PORTS
 	state->label[offset][0] = '\0';
+#endif
 
 	return 0;
 }
@@ -314,7 +340,7 @@ static int tegra_gpio_get_function(struct udevice *dev, unsigned offset)
 	struct tegra_port_info *state = dev_get_priv(dev);
 	int gpio = state->base_gpio + offset;
 
-	if (!*state->label[offset])
+	if (!gpio_is_requested(state, offset))
 		return GPIOF_UNUSED;
 	if (!get_config(gpio))
 		return GPIOF_FUNC;
@@ -335,7 +361,11 @@ static int tegra_gpio_get_state(struct udevice *dev, unsigned int offset,
 	int is_gpio;
 	int size;
 
+#ifdef NAMED_PORTS
 	label = state->label[offset];
+#else
+	label = "?";
+#endif
 	is_gpio = get_config(gpio); /* GPIO, not SFPIO */
 	size = snprintf(buf, bufsize, "%s%d: ",
 			uc_priv->bank_name ? uc_priv->bank_name : "", offset);
-- 
2.1.0.rc2.206.gedb03e5



More information about the U-Boot mailing list