Skip to contentSkip to conversation

dm: omap: Provide access to driver model for am335x, and move boards

PATCH Superseded Simon Glass 2 participants 33 messages Oct 23, 2014 – Oct 24, 2014

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

v2 cover dm: omap: Provide access to driver model for am335x, and move boards

This series adjusts the serial and GPIO drivers, used by Beaglebone for example, to work with driver model. Since there are still boards using these drivers but not driver model, this adds new functionality rather than replacing what exists.

Several patches tweak and fix the existing driver model serial and GPIO implementation.

There are two Beaglebone Black configurations:

- Device tree control with verified boot
- No device tree control

The first uses device tree to select the serial console and provide information needed by the serial driver (similar to how things work on Tegra). The second uses platform data provided by a common board file.

Both are converted, so this is a good example of how to support both device tree and platform data if needed.

In addition, in v2, the rest of the OMAP3 boards are converted to driver model.

Changes in v2:
- Fix "is available" typo
- Use of_match_ptr() to avoid #ifdef
- Add patch to move OMAP3 boards to driver model also

Simon Glass (15):
dm: gpio: Support numbered GPIOs
dm: serial: Reset the watchdog while waiting in getc()
dm: serial: ns16550: Correct logic for checking for character
dm: ns16550: Use an address instead of a pointer for the uart base
dm: ns16550: Correct the probe logic for platform data
dm: serial: Support CONFIG_CONS_INDEX if available
dm: dts: omap: Select correct console for beaglebone
dm: omap: gpio: Put _get_gpio_value() logic into its own function
dm: omap: gpio: Support driver model
dm: am33xx: Provide platform data for GPIOs
dm: am33xx: Provide platform data for serial
dm: omap: serial: Add driver model support
dm: am335x: Remove serial options from CONFIG_SYS_EXTRA_OPTIONS
dm: am33xx: Move to driver model for GPIO and serial
dm: omap3: Move to driver model for GPIO and serial

 arch/arm/cpu/armv7/am33xx/board.c        |  61 +++++++
 arch/arm/cpu/armv7/omap3/board.c         |  26 ++-
 arch/arm/dts/am335x-bone-common.dtsi     |   4 +
 arch/arm/include/asm/omap_gpio.h         |  19 +-
 board/isee/igep00x0/igep00x0.c           |  13 ++
 board/logicpd/zoom1/zoom1.c              |  13 ++
 board/overo/overo.c                      |  13 ++
 board/ti/beagle/beagle.c                 |  47 +++--
 board/ti/beagle/led.c                    |  61 ++++---
 configs/am335x_boneblack_defconfig       |   2 +-
 configs/am335x_boneblack_vboot_defconfig |   2 +-
 drivers/gpio/gpio-uclass.c               |  37 ++--
 drivers/gpio/omap_gpio.c                 | 297 +++++++++++++++++++++++++++----
 drivers/mmc/omap_hsmmc.c                 |  15 +-
 drivers/serial/Makefile                  |   1 +
 drivers/serial/ns16550.c                 |  13 +-
 drivers/serial/serial-uclass.c           |  16 +-
 drivers/serial/serial_omap.c             |  47 +++++
 include/configs/ti_am335x_common.h       |  11 ++
 include/configs/ti_omap3_common.h        |  19 +-
 include/ns16550.h                        |   2 +-
 21 files changed, 603 insertions(+), 116 deletions(-)
 create mode 100644 drivers/serial/serial_omap.c
Signature · 1 line
2.1.0.rc2.206.gedb03e5
#1 lore raw

PATCH v2 1/15 dm: gpio: Support numbered GPIOs

At present banks must be named and it is not possible to refer to GPIOs by number in driver model. Some boards use numbering - e.g. OMAP. It is fairly easy to support by detecting the absense of a bank name (which starts with a letter).

Add support for numbered GPIOs in addition to the existing bank support.

---

Changes in v2: None

 drivers/gpio/gpio-uclass.c | 37 +++++++++++++++++++++++++------------
 1 file changed, 25 insertions(+), 12 deletions(-)
drivers/gpio/gpio-uclass.c +25 -12
index f1bbc58..a5ffd85 100644
@@ -8,6 +8,7 @@
 #include <dm.h>
 #include <errno.h>
 #include <asm/gpio.h>
+#include <linux/ctype.h>
 
 /**
  * gpio_to_device() - Convert global GPIO number to device, number
@@ -43,35 +44,47 @@ static int gpio_to_device(unsigned int gpio, struct udevice **devp,
 int gpio_lookup_name(const char *name, struct udevice **devp,
 		     unsigned int *offsetp, unsigned int *gpiop)
 {
-	struct gpio_dev_priv *uc_priv;
+	struct gpio_dev_priv *uc_priv = NULL;
 	struct udevice *dev;
+	ulong offset;
+	int numeric;
 	int ret;
 
 	if (devp)
 		*devp = NULL;
+	numeric = isdigit(*name) ? simple_strtoul(name, NULL, 10) : -1;
 	for (ret = uclass_first_device(UCLASS_GPIO, &dev);
 	     dev;
 	     ret = uclass_next_device(&dev)) {
-		ulong offset;
 		int len;
 
 		uc_priv = dev->uclass_priv;
+		if (numeric != -1) {
+			offset = numeric - uc_priv->gpio_base;
+			/* Allow GPIOs to be numbered from 0 */
+			if (offset >= 0 && offset < uc_priv->gpio_count)
+				break;
+		}
+
 		len = uc_priv->bank_name ? strlen(uc_priv->bank_name) : 0;
 
 		if (!strncasecmp(name, uc_priv->bank_name, len)) {
-			if (strict_strtoul(name + len, 10, &offset))
-				continue;
-			if (devp)
-				*devp = dev;
-			if (offsetp)
-				*offsetp = offset;
-			if (gpiop)
-				*gpiop = uc_priv->gpio_base + offset;
-			return 0;
+			if (!strict_strtoul(name + len, 10, &offset))
+				break;
 		}
 	}
 
-	return ret ? ret : -EINVAL;
+	if (!dev)
+		return ret ? ret : -EINVAL;
+
+	if (devp)
+		*devp = dev;
+	if (offsetp)
+		*offsetp = offset;
+	if (gpiop)
+		*gpiop = uc_priv->gpio_base + offset;
+
+	return 0;
 }
 
 /**
Signature · 1 line
2.1.0.rc2.206.gedb03e5
#2 lore raw

PATCH v2 1/15 dm: gpio: Support numbered GPIOs

Quoted 5 lines · Simon Glass

At present banks must be named and it is not possible to refer to GPIOs by number in driver model. Some boards use numbering - e.g. OMAP. It is fairly easy to support by detecting the absense of a bank name (which starts with a letter).

Quoted 7 lines

Add support for numbered GPIOs in addition to the existing bank support.

---

Changes in v2: None

Applied to u-boot-dm/master

#3 lore raw

PATCH v2 2/15 dm: serial: Reset the watchdog while waiting in getc()

In reply to Simon Glass

We have moved the busy-wait loop out of drivers and into the uclass. This means that we must reset the watchdog when busy-waiting.

Note: some drivers may still have a busy-wait even with driver model, as a transition mechanism. Driver model will tolerate this, and is can be cleaned up when all users of the driver use driver model. An example is ns16550.

---

Changes in v2: None

 drivers/serial/serial-uclass.c | 5 +++++
 1 file changed, 5 insertions(+)
drivers/serial/serial-uclass.c +5 -0
index 1a75950..1983a3d 100644
@@ -11,9 +11,12 @@
 #include <os.h>
 #include <serial.h>
 #include <stdio_dev.h>
+#include <watchdog.h>
 #include <dm/lists.h>
 #include <dm/device-internal.h>
 
+#include <ns16550.h>
+
 DECLARE_GLOBAL_DATA_PTR;
 
 /* The currently-selected console serial device */
@@ -119,6 +122,8 @@ static int serial_getc_dev(struct udevice *dev)
 
 	do {
 		err = ops->getc(dev);
+		if (err == -EAGAIN)
+			WATCHDOG_RESET();
 	} while (err == -EAGAIN);
 
 	return err >= 0 ? err : 0;
Signature · 1 line
2.1.0.rc2.206.gedb03e5
#4 lore raw

PATCH v2 2/15 dm: serial: Reset the watchdog while waiting in getc()

Quoted 8 lines · Simon Glass

We have moved the busy-wait loop out of drivers and into the uclass. This means that we must reset the watchdog when busy-waiting.

Note: some drivers may still have a busy-wait even with driver model, as a transition mechanism. Driver model will tolerate this, and is can be cleaned up when all users of the driver use driver model. An example is ns16550.

Quoted 8 lines

---

Changes in v2: None

 drivers/serial/serial-uclass.c | 5 +++++
 1 file changed, 5 insertions(+)

Applied to u-boot-dm/master

#5 lore raw

PATCH v2 3/15 dm: serial: ns16550: Correct logic for checking for character

In reply to Simon Glass

There is a bug in the logic which checks for an available character. This can cause invalid characters to be received - this was noticed on beaglebone. Fix it.

---

Changes in v2: None

 drivers/serial/ns16550.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/serial/ns16550.c +1 -1
index 63a9ef6..fe6cc26 100644
@@ -253,7 +253,7 @@ static int ns16550_serial_getc(struct udevice *dev)
 {
 	struct NS16550 *const com_port = dev_get_priv(dev);
 
-	if (!serial_in(&com_port->lsr) & UART_LSR_DR)
+	if (!(serial_in(&com_port->lsr) & UART_LSR_DR))
 		return -EAGAIN;
 
 	return serial_in(&com_port->rbr);
Signature · 1 line
2.1.0.rc2.206.gedb03e5
#6 lore raw

PATCH v2 3/15 dm: serial: ns16550: Correct logic for checking for character

Quoted 9 lines · Simon Glass

There is a bug in the logic which checks for an available character. This can cause invalid characters to be received - this was noticed on beaglebone. Fix it.

---

Changes in v2: None

Applied to u-boot-dm/master

#7 lore raw

PATCH v2 4/15 dm: ns16550: Use an address instead of a pointer for the uart base

In reply to Simon Glass

It is inconvenient to have to use casts when specifying platform data. Also it is not strictly correct, since we should use map_sysmem() to convert an address to a pointer.

Adjust the platform data to use an address.

---

Changes in v2: None

 drivers/serial/ns16550.c | 6 +++---
 include/ns16550.h        | 2 +-
 2 files changed, 4 insertions(+), 4 deletions(-)
drivers/serial/ns16550.c +3 -3
index fe6cc26..2301f0a 100644
@@ -61,7 +61,7 @@ static void ns16550_writeb(NS16550_t port, int offset, int value)
 	unsigned char *addr;
 
 	offset *= 1 << plat->reg_shift;
-	addr = plat->base + offset;
+	addr = map_sysmem(plat->base, 0) + offset;
 	/*
 	 * As far as we know it doesn't make sense to support selection of
 	 * these options at run-time, so use the existing CONFIG options.
@@ -85,7 +85,7 @@ static int ns16550_readb(NS16550_t port, int offset)
 	unsigned char *addr;
 
 	offset *= 1 << plat->reg_shift;
-	addr = plat->base + offset;
+	addr = map_sysmem(plat->base, 0) + offset;
 #ifdef CONFIG_SYS_NS16550_PORT_MAPPED
 	return inb(addr);
 #elif defined(CONFIG_SYS_NS16550_MEM32) && !defined(CONFIG_SYS_BIG_ENDIAN)
@@ -291,7 +291,7 @@ int ns16550_serial_ofdata_to_platdata(struct udevice *dev)
 	if (addr == FDT_ADDR_T_NONE)
 		return -EINVAL;
 
-	plat->base = (unsigned char *)addr;
+	plat->base = addr;
 	plat->reg_shift = fdtdec_get_int(gd->fdt_blob, dev->of_offset,
 					 "reg-shift", 1);
 	com_port->plat = plat;
include/ns16550.h +1 -1
index 5784cfd..0607379 100644
@@ -53,7 +53,7 @@
  * @clock:		UART base clock speed in Hz
  */
 struct ns16550_platdata {
-	unsigned char *base;
+	unsigned long base;
 	int reg_shift;
 	int clock;
 };
Signature · 1 line
2.1.0.rc2.206.gedb03e5
#8 lore raw

PATCH v2 4/15 dm: ns16550: Use an address instead of a pointer for the uart base

Quoted 8 lines · Simon Glass

It is inconvenient to have to use casts when specifying platform data. Also it is not strictly correct, since we should use map_sysmem() to convert an address to a pointer.

Adjust the platform data to use an address.

Quoted 7 lines

---

Changes in v2: None

 drivers/serial/ns16550.c | 6 +++---
 include/ns16550.h        | 2 +-
 2 files changed, 4 insertions(+), 4 deletions(-)

Applied to u-boot-dm/master

#9 lore raw

PATCH v2 5/15 dm: ns16550: Correct the probe logic for platform data

In reply to Simon Glass

The probe logic sets up the pointer to the platform data in the device tree decode method. It should be done in the probe() method, and anyway the device tree decode method can't be used when CONFIG_OF_CONTROL is not enabled.

Fix these two problems.

---

Changes in v2: None

 drivers/serial/ns16550.c | 5 +++--
 1 file changed, 3 insertions(+), 2 deletions(-)
drivers/serial/ns16550.c +3 -2
index 2301f0a..0799aa4 100644
@@ -276,14 +276,15 @@ int ns16550_serial_probe(struct udevice *dev)
 {
 	struct NS16550 *const com_port = dev_get_priv(dev);
 
+	com_port->plat = dev_get_platdata(dev);
 	NS16550_init(com_port, -1);
 
 	return 0;
 }
 
+#ifdef CONFIG_OF_CONTROL
 int ns16550_serial_ofdata_to_platdata(struct udevice *dev)
 {
-	struct NS16550 *const com_port = dev_get_priv(dev);
 	struct ns16550_platdata *plat = dev->platdata;
 	fdt_addr_t addr;
 
@@ -294,10 +295,10 @@ int ns16550_serial_ofdata_to_platdata(struct udevice *dev)
 	plat->base = addr;
 	plat->reg_shift = fdtdec_get_int(gd->fdt_blob, dev->of_offset,
 					 "reg-shift", 1);
-	com_port->plat = plat;
 
 	return 0;
 }
+#endif
 
 const struct dm_serial_ops ns16550_serial_ops = {
 	.putc = ns16550_serial_putc,
Signature · 1 line
2.1.0.rc2.206.gedb03e5
#10 lore raw

PATCH v2 5/15 dm: ns16550: Correct the probe logic for platform data

Quoted 7 lines · Simon Glass

The probe logic sets up the pointer to the platform data in the device tree decode method. It should be done in the probe() method, and anyway the device tree decode method can't be used when CONFIG_OF_CONTROL is not enabled.

Fix these two problems.

Quoted 8 lines

---

Changes in v2: None

 drivers/serial/ns16550.c | 5 +++--
 1 file changed, 3 insertions(+), 2 deletions(-)

Applied to u-boot-dm/master

#11 lore raw

PATCH v2 6/15 dm: serial: Support CONFIG_CONS_INDEX if available

In reply to Simon Glass

Try to use this option to select the correct uart for the console. This mimics the behaviour of drivers/serial.c.

---

Changes in v2:
- Fix "is available" typo

 drivers/serial/serial-uclass.c | 11 ++++++++++-
 1 file changed, 10 insertions(+), 1 deletion(-)
drivers/serial/serial-uclass.c +10 -1
index 1983a3d..c9383dc 100644
@@ -50,13 +50,22 @@ static void serial_find_console_or_panic(void)
 	}
 #endif
 	/*
+	 * Try to use CONFIG_CONS_INDEX if available (it is numbered from 1!).
+	 *
 	 * Failing that, get the device with sequence number 0, or in extremis
 	 * just the first serial device we can find. But we insist on having
 	 * a console (even if it is silent).
 	 */
-	if (uclass_get_device_by_seq(UCLASS_SERIAL, 0, &cur_dev) &&
+#ifdef CONFIG_CONS_INDEX
+#define INDEX (CONFIG_CONS_INDEX - 1)
+#else
+#define INDEX 0
+#endif
+	if (uclass_get_device_by_seq(UCLASS_SERIAL, INDEX, &cur_dev) &&
+	    uclass_get_device(UCLASS_SERIAL, INDEX, &cur_dev) &&
 	    (uclass_first_device(UCLASS_SERIAL, &cur_dev) || !cur_dev))
 		panic("No serial driver found");
+#undef INDEX
 }
 
 /* Called prior to relocation */
Signature · 1 line
2.1.0.rc2.206.gedb03e5
#12 lore raw

PATCH v2 6/15 dm: serial: Support CONFIG_CONS_INDEX if available

Quoted 5 lines · Simon Glass

Try to use this option to select the correct uart for the console. This mimics the behaviour of drivers/serial.c.

Quoted 7 lines

---

Changes in v2:
- Fix "is available" typo

 drivers/serial/serial-uclass.c | 11 ++++++++++-
 1 file changed, 10 insertions(+), 1 deletion(-)

Applied to u-boot-dm/master

#13 lore raw

PATCH v2 7/15 dm: dts: omap: Select correct console for beaglebone

In reply to Simon Glass

Select serial0 as the console.

---

Changes in v2: None

 arch/arm/dts/am335x-bone-common.dtsi | 4 ++++
 1 file changed, 4 insertions(+)
arch/arm/dts/am335x-bone-common.dtsi +4 -0
index 2f66ded..e70b4d1 100644
@@ -10,6 +10,10 @@
 	model = "TI AM335x BeagleBone";
 	compatible = "ti,am335x-bone", "ti,am33xx";
 
+	chosen {
+		stdout-path = &uart0;
+	};
+
 	cpus {
 		cpu at 0 {
 			cpu0-supply = <&dcdc2_reg>;
Signature · 1 line
2.1.0.rc2.206.gedb03e5
#15 lore raw

PATCH v2 8/15 dm: omap: gpio: Put _get_gpio_value() logic into its own function

In reply to Simon Glass

Add a separate internal helper function to get a GPIO value, so that we will be able to call it with the driver model version and avoid code duplication.

Also move gpio_get_bank() and check_gpio() down below the helper functions as these won't be needed with driver model.

---

Changes in v2: None

 drivers/gpio/omap_gpio.c | 78 ++++++++++++++++++++++++++----------------------
 1 file changed, 42 insertions(+), 36 deletions(-)
drivers/gpio/omap_gpio.c +42 -36
index 13dcf79..d2d2640 100644
@@ -26,11 +26,6 @@
 #define OMAP_GPIO_DIR_OUT	0
 #define OMAP_GPIO_DIR_IN	1
 
-static inline const struct gpio_bank *get_gpio_bank(int gpio)
-{
-	return &omap_gpio_bank[gpio >> 5];
-}
-
 static inline int get_gpio_index(int gpio)
 {
 	return gpio & 0x1f;
@@ -41,15 +36,6 @@ int gpio_is_valid(int gpio)
 	return (gpio >= 0) && (gpio < OMAP_MAX_GPIO);
 }
 
-static int check_gpio(int gpio)
-{
-	if (!gpio_is_valid(gpio)) {
-		printf("ERROR : check_gpio: invalid GPIO %d\n", gpio);
-		return -1;
-	}
-	return 0;
-}
-
 static void _set_gpio_direction(const struct gpio_bank *bank, int gpio,
 				int is_input)
 {
@@ -118,6 +104,46 @@ static void _set_gpio_dataout(const struct gpio_bank *bank, int gpio,
 	__raw_writel(l, reg);
 }
 
+static int _get_gpio_value(const struct gpio_bank *bank, int gpio)
+{
+	void *reg = bank->base;
+	int input;
+
+	switch (bank->method) {
+	case METHOD_GPIO_24XX:
+		input = _get_gpio_direction(bank, gpio);
+		switch (input) {
+		case OMAP_GPIO_DIR_IN:
+			reg += OMAP_GPIO_DATAIN;
+			break;
+		case OMAP_GPIO_DIR_OUT:
+			reg += OMAP_GPIO_DATAOUT;
+			break;
+		default:
+			return -1;
+		}
+		break;
+	default:
+		return -1;
+	}
+
+	return (__raw_readl(reg) & (1 << gpio)) != 0;
+}
+
+static inline const struct gpio_bank *get_gpio_bank(int gpio)
+{
+	return &omap_gpio_bank[gpio >> 5];
+}
+
+static int check_gpio(int gpio)
+{
+	if (!gpio_is_valid(gpio)) {
+		printf("ERROR : check_gpio: invalid GPIO %d\n", gpio);
+		return -1;
+	}
+	return 0;
+}
+
 /**
  * Set value of the specified gpio
  */
@@ -139,32 +165,12 @@ int gpio_set_value(unsigned gpio, int value)
 int gpio_get_value(unsigned gpio)
 {
 	const struct gpio_bank *bank;
-	void *reg;
-	int input;
 
 	if (check_gpio(gpio) < 0)
 		return -1;
 	bank = get_gpio_bank(gpio);
-	reg = bank->base;
-	switch (bank->method) {
-	case METHOD_GPIO_24XX:
-		input = _get_gpio_direction(bank, get_gpio_index(gpio));
-		switch (input) {
-		case OMAP_GPIO_DIR_IN:
-			reg += OMAP_GPIO_DATAIN;
-			break;
-		case OMAP_GPIO_DIR_OUT:
-			reg += OMAP_GPIO_DATAOUT;
-			break;
-		default:
-			return -1;
-		}
-		break;
-	default:
-		return -1;
-	}
-	return (__raw_readl(reg)
-			& (1 << get_gpio_index(gpio))) != 0;
+
+	return _get_gpio_value(bank, get_gpio_index(gpio));
 }
 
 /**
Signature · 1 line
2.1.0.rc2.206.gedb03e5
#16 lore raw

PATCH v2 8/15 dm: omap: gpio: Put _get_gpio_value() logic into its own function

Quoted 7 lines · Simon Glass

Add a separate internal helper function to get a GPIO value, so that we will be able to call it with the driver model version and avoid code duplication.

Also move gpio_get_bank() and check_gpio() down below the helper functions as these won't be needed with driver model.

Quoted 8 lines

---

Changes in v2: None

 drivers/gpio/omap_gpio.c | 78 ++++++++++++++++++++++++++----------------------
 1 file changed, 42 insertions(+), 36 deletions(-)

Applied to u-boot-dm/master

#17 lore raw

PATCH v2 9/15 dm: omap: gpio: Support driver model

In reply to Simon Glass

Add driver model support to this driver, while retaining support for the legacy system. Driver model GPIO support is enabled with CONFIG_DM_GPIO as usual.

Since gpio_is_valid() no longer exists, we can use the -EINVAL error returned from gpio_request().

---

Changes in v2: None

 arch/arm/include/asm/omap_gpio.h |  19 +++-
 drivers/gpio/omap_gpio.c         | 221 +++++++++++++++++++++++++++++++++++++++
 drivers/mmc/omap_hsmmc.c         |  15 ++-
 3 files changed, 248 insertions(+), 7 deletions(-)
arch/arm/include/asm/omap_gpio.h +17 -2
index 5d25d04..839af54 100644
@@ -23,6 +23,21 @@
 
 #include <asm/arch/cpu.h>
 
+enum gpio_method {
+	METHOD_GPIO_24XX	= 4,
+};
+
+#ifdef CONFIG_DM_GPIO
+
+/* Information about a GPIO bank */
+struct omap_gpio_platdata {
+	int bank_index;
+	ulong base;	/* address of registers in physical memory */
+	enum gpio_method method;
+};
+
+#else
+
 struct gpio_bank {
 	void *base;
 	int method;
@@ -30,8 +45,6 @@ struct gpio_bank {
 
 extern const struct gpio_bank *const omap_gpio_bank;
 
-#define METHOD_GPIO_24XX	4
-
 /**
  * Check if gpio is valid.
  *
@@ -39,4 +52,6 @@ extern const struct gpio_bank *const omap_gpio_bank;
  * @return 1 if ok, 0 on error
  */
 int gpio_is_valid(int gpio);
+#endif
+
 #endif /* _GPIO_H_ */
drivers/gpio/omap_gpio.c +221 -0

242 lines not on this page · raw message

drivers/mmc/omap_hsmmc.c +10 -5
index 5b0c302..ef2cbf9 100644
@@ -67,14 +67,19 @@ static int mmc_write_data(struct hsmmc *mmc_base, const char *buf,
 #ifdef OMAP_HSMMC_USE_GPIO
 static int omap_mmc_setup_gpio_in(int gpio, const char *label)
 {
-	if (!gpio_is_valid(gpio))
-		return -1;
+	int ret;
 
-	if (gpio_request(gpio, label) < 0)
+#ifndef CONFIG_DM_GPIO
+	if (!gpio_is_valid(gpio))
 		return -1;
+#endif
+	ret = gpio_request(gpio, label);
+	if (ret)
+		return ret;
 
-	if (gpio_direction_input(gpio) < 0)
-		return -1;
+	ret = gpio_direction_input(gpio);
+	if (ret)
+		return ret;
 
 	return gpio;
 }
Signature · 1 line
2.1.0.rc2.206.gedb03e5
#18 lore raw

PATCH v2 9/15 dm: omap: gpio: Support driver model

Quoted 9 lines · Simon Glass

Add driver model support to this driver, while retaining support for the legacy system. Driver model GPIO support is enabled with CONFIG_DM_GPIO as usual.

Since gpio_is_valid() no longer exists, we can use the -EINVAL error returned from gpio_request().

Quoted 8 lines

---

Changes in v2: None

 arch/arm/include/asm/omap_gpio.h |  19 +++-
 drivers/gpio/omap_gpio.c         | 221 +++++++++++++++++++++++++++++++++++++++
 drivers/mmc/omap_hsmmc.c         |  15 ++-
 3 files changed, 248 insertions(+), 7 deletions(-)

Applied to u-boot-dm/master

#19 lore raw

PATCH v2 10/15 dm: am33xx: Provide platform data for GPIOs

In reply to Simon Glass

Provide suitable platform data for am33xx boards, so that these boards can use driver model for GPIO access.

---

Changes in v2: None

 arch/arm/cpu/armv7/am33xx/board.c | 28 ++++++++++++++++++++++++++++
 1 file changed, 28 insertions(+)
arch/arm/cpu/armv7/am33xx/board.c +28 -0
index 828d10b..7aa8198 100644
@@ -9,6 +9,7 @@
  */
 
 #include <common.h>
+#include <dm.h>
 #include <errno.h>
 #include <spl.h>
 #include <asm/arch/cpu.h>
@@ -36,6 +37,31 @@
 
 DECLARE_GLOBAL_DATA_PTR;
 
+#ifdef CONFIG_DM_GPIO
+static const struct omap_gpio_platdata am33xx_gpio[] = {
+	{ 0, AM33XX_GPIO0_BASE, METHOD_GPIO_24XX },
+	{ 1, AM33XX_GPIO1_BASE, METHOD_GPIO_24XX },
+	{ 2, AM33XX_GPIO2_BASE, METHOD_GPIO_24XX },
+	{ 3, AM33XX_GPIO3_BASE, METHOD_GPIO_24XX },
+#ifdef CONFIG_AM43XX
+	{ 4, AM33XX_GPIO4_BASE, METHOD_GPIO_24XX },
+	{ 5, AM33XX_GPIO5_BASE, METHOD_GPIO_24XX },
+#endif
+};
+
+U_BOOT_DEVICES(am33xx_gpios) = {
+	{ "gpio_omap", &am33xx_gpio[0] },
+	{ "gpio_omap", &am33xx_gpio[1] },
+	{ "gpio_omap", &am33xx_gpio[2] },
+	{ "gpio_omap", &am33xx_gpio[3] },
+#ifdef CONFIG_AM43XX
+	{ "gpio_omap", &am33xx_gpio[4] },
+	{ "gpio_omap", &am33xx_gpio[5] },
+#endif
+};
+
+#else
+
 static const struct gpio_bank gpio_bank_am33xx[] = {
 	{ (void *)AM33XX_GPIO0_BASE, METHOD_GPIO_24XX },
 	{ (void *)AM33XX_GPIO1_BASE, METHOD_GPIO_24XX },
@@ -49,6 +75,8 @@ static const struct gpio_bank gpio_bank_am33xx[] = {
 
 const struct gpio_bank *const omap_gpio_bank = gpio_bank_am33xx;
 
+#endif
+
 #if defined(CONFIG_OMAP_HSMMC) && !defined(CONFIG_SPL_BUILD)
 int cpu_mmc_init(bd_t *bis)
 {
Signature · 1 line
2.1.0.rc2.206.gedb03e5
#20 lore raw

PATCH v2 10/15 dm: am33xx: Provide platform data for GPIOs

Quoted 11 lines · Simon Glass

Provide suitable platform data for am33xx boards, so that these boards can use driver model for GPIO access.

---

Changes in v2: None

 arch/arm/cpu/armv7/am33xx/board.c | 28 ++++++++++++++++++++++++++++
 1 file changed, 28 insertions(+)

Applied to u-boot-dm/master

#21 lore raw

PATCH v2 11/15 dm: am33xx: Provide platform data for serial

In reply to Simon Glass

Provide suitable platform data for am33xx boards, so that these boards can use driver model for serial.

---

Changes in v2: None

 arch/arm/cpu/armv7/am33xx/board.c | 33 +++++++++++++++++++++++++++++++++
 1 file changed, 33 insertions(+)
arch/arm/cpu/armv7/am33xx/board.c +33 -0
index 7aa8198..29b1d73 100644
@@ -11,6 +11,7 @@
 #include <common.h>
 #include <dm.h>
 #include <errno.h>
+#include <ns16550.h>
 #include <spl.h>
 #include <asm/arch/cpu.h>
 #include <asm/arch/hardware.h>
@@ -60,6 +61,38 @@ U_BOOT_DEVICES(am33xx_gpios) = {
 #endif
 };
 
+# ifndef CONFIG_OF_CONTROL
+/*
+ * TODO(sjg at chromium.org): When we can move SPL serial to DM, we can remove
+ * the CONFIGs. At the same time, we should move this to the board files.
+ */
+static const struct ns16550_platdata am33xx_serial[] = {
+	{ CONFIG_SYS_NS16550_COM1, 2, CONFIG_SYS_NS16550_CLK },
+#  ifdef CONFIG_SYS_NS16550_COM2
+	{ CONFIG_SYS_NS16550_COM2, 2, CONFIG_SYS_NS16550_CLK },
+#   ifdef CONFIG_SYS_NS16550_COM3
+	{ CONFIG_SYS_NS16550_COM3, 2, CONFIG_SYS_NS16550_CLK },
+	{ CONFIG_SYS_NS16550_COM4, 2, CONFIG_SYS_NS16550_CLK },
+	{ CONFIG_SYS_NS16550_COM5, 2, CONFIG_SYS_NS16550_CLK },
+	{ CONFIG_SYS_NS16550_COM6, 2, CONFIG_SYS_NS16550_CLK },
+#   endif
+#  endif
+};
+
+U_BOOT_DEVICES(am33xx_uarts) = {
+	{ "serial_omap", &am33xx_serial[0] },
+#  ifdef CONFIG_SYS_NS16550_COM2
+	{ "serial_omap", &am33xx_serial[1] },
+#   ifdef CONFIG_SYS_NS16550_COM3
+	{ "serial_omap", &am33xx_serial[2] },
+	{ "serial_omap", &am33xx_serial[3] },
+	{ "serial_omap", &am33xx_serial[4] },
+	{ "serial_omap", &am33xx_serial[5] },
+#   endif
+#  endif
+};
+# endif
+
 #else
 
 static const struct gpio_bank gpio_bank_am33xx[] = {
Signature · 1 line
2.1.0.rc2.206.gedb03e5
#22 lore raw

PATCH v2 11/15 dm: am33xx: Provide platform data for serial

Quoted 11 lines · Simon Glass

Provide suitable platform data for am33xx boards, so that these boards can use driver model for serial.

---

Changes in v2: None

 arch/arm/cpu/armv7/am33xx/board.c | 33 +++++++++++++++++++++++++++++++++
 1 file changed, 33 insertions(+)

Applied to u-boot-dm/master

#23 lore raw

PATCH v2 12/15 dm: omap: serial: Add driver model support

In reply to Simon Glass

Add driver model support to this driver, while retaining support for the legacy system. Driver model serial support is enabled with CONFIG_DM_SERIAL as usual.

---

Changes in v2:
- Use of_match_ptr() to avoid #ifdef

 drivers/serial/Makefile      |  1 +
 drivers/serial/serial_omap.c | 47 ++++++++++++++++++++++++++++++++++++++++++++
 2 files changed, 48 insertions(+)
 create mode 100644 drivers/serial/serial_omap.c
drivers/serial/Makefile +1 -0
index 17c56ea..cd87d18 100644
@@ -41,6 +41,7 @@ obj-$(CONFIG_MXS_AUART) += mxs_auart.o
 obj-$(CONFIG_ARC_SERIAL) += serial_arc.o
 obj-$(CONFIG_TEGRA_SERIAL) += serial_tegra.o
 obj-$(CONFIG_UNIPHIER_SERIAL) += serial_uniphier.o
+obj-$(CONFIG_OMAP_SERIAL) += serial_omap.o
 
 ifndef CONFIG_SPL_BUILD
 obj-$(CONFIG_USB_TTY) += usbtty.o
drivers/serial/serial_omap.c new file +47 -0

47 lines not on this page · raw message

Signature · 1 line
2.1.0.rc2.206.gedb03e5
#24 lore raw

PATCH v2 12/15 dm: omap: serial: Add driver model support

Quoted 8 lines · Simon Glass

Add driver model support to this driver, while retaining support for the legacy system. Driver model serial support is enabled with CONFIG_DM_SERIAL as usual.

---

Quoted 7 lines

Changes in v2:
- Use of_match_ptr() to avoid #ifdef

 drivers/serial/Makefile      |  1 +
 drivers/serial/serial_omap.c | 47 ++++++++++++++++++++++++++++++++++++++++++++
 2 files changed, 48 insertions(+)
 create mode 100644 drivers/serial/serial_omap.c

Applied to u-boot-dm/master

#25 lore raw

PATCH v2 13/15 dm: am335x: Remove serial options from CONFIG_SYS_EXTRA_OPTIONS

In reply to Simon Glass

With these options in place it is not possible to change the serial port using 'make menuconfig' or similar. It seems to result in duplicate defines.

For example:

In file included from include/linux/kconfig.h:4:0,

                 from <command-line>:0:

include/generated/autoconf.h:20:0: note: this is the location of the previous definition
#define CONFIG_CONS_INDEX 2
^

The default option seems to be 1 anyway, in board/ti/am335x/Kconfig.

Remove the options so that we can adjust the serial port if required.

---

Changes in v2: None

 configs/am335x_boneblack_defconfig       | 2 +-
 configs/am335x_boneblack_vboot_defconfig | 2 +-
 2 files changed, 2 insertions(+), 2 deletions(-)
configs/am335x_boneblack_defconfig +1 -1
index 38450c0..b631c41 100644
@@ -1,4 +1,4 @@
 CONFIG_SPL=y
-CONFIG_SYS_EXTRA_OPTIONS="SERIAL1,CONS_INDEX=1,EMMC_BOOT"
+CONFIG_SYS_EXTRA_OPTIONS="EMMC_BOOT"
 +S:CONFIG_ARM=y
 +S:CONFIG_TARGET_AM335X_EVM=y
configs/am335x_boneblack_vboot_defconfig +1 -1
index e257143..5837a0a 100644
@@ -1,5 +1,5 @@
 CONFIG_SPL=y
-CONFIG_SYS_EXTRA_OPTIONS="SERIAL1,CONS_INDEX=1,EMMC_BOOT,ENABLE_VBOOT"
+CONFIG_SYS_EXTRA_OPTIONS="EMMC_BOOT,ENABLE_VBOOT"
 +S:CONFIG_ARM=y
 +S:CONFIG_TARGET_AM335X_EVM=y
 CONFIG_OF_CONTROL=y
Signature · 1 line
2.1.0.rc2.206.gedb03e5
#26 lore raw

PATCH v2 13/15 dm: am335x: Remove serial options from CONFIG_SYS_EXTRA_OPTIONS

Quoted 18 lines · Simon Glass

With these options in place it is not possible to change the serial port using 'make menuconfig' or similar. It seems to result in duplicate defines.

For example:

In file included from include/linux/kconfig.h:4:0,

                 from <command-line>:0:

include/generated/autoconf.h:20:0: note: this is the location of the previous definition
#define CONFIG_CONS_INDEX 2
^

The default option seems to be 1 anyway, in board/ti/am335x/Kconfig.

Remove the options so that we can adjust the serial port if required.

Quoted 7 lines

---

Changes in v2: None

 configs/am335x_boneblack_defconfig       | 2 +-
 configs/am335x_boneblack_vboot_defconfig | 2 +-
 2 files changed, 2 insertions(+), 2 deletions(-)

Applied to u-boot-dm/master

#27 lore raw

PATCH v2 14/15 dm: am33xx: Move to driver model for GPIO and serial

In reply to Simon Glass

Adjust the configuration for the am33xx boards, including beaglebone black to use driver model.

This can be extended to other OMAP boards once platform data is provided for them.

---

Changes in v2: None

 include/configs/ti_am335x_common.h | 11 +++++++++++
 1 file changed, 11 insertions(+)
include/configs/ti_am335x_common.h +11 -0
index 80976e7..5ed86d9 100644
@@ -19,12 +19,23 @@
 #define CONFIG_SYS_TIMERBASE		0x48040000	/* Use Timer2 */
 #define CONFIG_SPL_AM33XX_ENABLE_RTC32K_OSC
 
+#ifndef CONFIG_SPL_BUILD
+# define CONFIG_DM
+# define CONFIG_CMD_DM
+# define CONFIG_DM_GPIO
+# define CONFIG_DM_SERIAL
+# define CONFIG_OMAP_SERIAL
+# define CONFIG_SYS_MALLOC_F_LEN	(1 << 10)
+#endif
+
 #include <asm/arch/omap.h>
 
 /* NS16550 Configuration */
 #define CONFIG_SYS_NS16550
+#ifdef CONFIG_SPL_BUILD
 #define CONFIG_SYS_NS16550_SERIAL
 #define CONFIG_SYS_NS16550_REG_SIZE	(-4)
+#endif
 #define CONFIG_SYS_NS16550_CLK		48000000
 
 /* Network defines. */
Signature · 1 line
2.1.0.rc2.206.gedb03e5
#28 lore raw

PATCH v2 14/15 dm: am33xx: Move to driver model for GPIO and serial

Quoted 6 lines · Simon Glass

Adjust the configuration for the am33xx boards, including beaglebone black to use driver model.

This can be extended to other OMAP boards once platform data is provided for them.

Quoted 8 lines

---

Changes in v2: None

 include/configs/ti_am335x_common.h | 11 +++++++++++
 1 file changed, 11 insertions(+)

Applied to u-boot-dm/master

#29 lore raw

PATCH v2 15/15 dm: omap3: Move to driver model for GPIO and serial

In reply to Simon Glass

Adjust the configuration for the am33xx boards, including beagleboard, to use driver model.

---

Changes in v2:
- Add patch to move OMAP3 boards to driver model also

 arch/arm/cpu/armv7/omap3/board.c  | 26 ++++++++++++++++-
 board/isee/igep00x0/igep00x0.c    | 13 +++++++++
 board/logicpd/zoom1/zoom1.c       | 13 +++++++++
 board/overo/overo.c               | 13 +++++++++
 board/ti/beagle/beagle.c          | 47 +++++++++++++++++++-----------
 board/ti/beagle/led.c             | 61 +++++++++++++++++++--------------------
 include/configs/ti_omap3_common.h | 19 ++++++++++--
 7 files changed, 140 insertions(+), 52 deletions(-)
arch/arm/cpu/armv7/omap3/board.c +25 -1
index 667e77f..e6996b5 100644
@@ -17,13 +17,14 @@
  * SPDX-License-Identifier:	GPL-2.0+
  */
 #include <common.h>
+#include <dm.h>
 #include <spl.h>
 #include <asm/io.h>
 #include <asm/arch/sys_proto.h>
 #include <asm/arch/mem.h>
 #include <asm/cache.h>
 #include <asm/armv7.h>
-#include <asm/arch/gpio.h>
+#include <asm/gpio.h>
 #include <asm/omap_common.h>
 #include <asm/arch/mmc_host_def.h>
 #include <i2c.h>
@@ -38,6 +39,27 @@ static void omap3_setup_aux_cr(void);
 static void omap3_invalidate_l2_cache_secure(void);
 #endif
 
+#ifdef CONFIG_DM_GPIO
+static const struct omap_gpio_platdata omap34xx_gpio[] = {
+	{ 0, OMAP34XX_GPIO1_BASE, METHOD_GPIO_24XX },
+	{ 1, OMAP34XX_GPIO2_BASE, METHOD_GPIO_24XX },
+	{ 2, OMAP34XX_GPIO3_BASE, METHOD_GPIO_24XX },
+	{ 3, OMAP34XX_GPIO4_BASE, METHOD_GPIO_24XX },
+	{ 4, OMAP34XX_GPIO5_BASE, METHOD_GPIO_24XX },
+	{ 5, OMAP34XX_GPIO6_BASE, METHOD_GPIO_24XX },
+};
+
+U_BOOT_DEVICES(am33xx_gpios) = {
+	{ "gpio_omap", &omap34xx_gpio[0] },
+	{ "gpio_omap", &omap34xx_gpio[1] },
+	{ "gpio_omap", &omap34xx_gpio[2] },
+	{ "gpio_omap", &omap34xx_gpio[3] },
+	{ "gpio_omap", &omap34xx_gpio[4] },
+	{ "gpio_omap", &omap34xx_gpio[5] },
+};
+
+#else
+
 static const struct gpio_bank gpio_bank_34xx[6] = {
 	{ (void *)OMAP34XX_GPIO1_BASE, METHOD_GPIO_24XX },
 	{ (void *)OMAP34XX_GPIO2_BASE, METHOD_GPIO_24XX },
@@ -49,6 +71,8 @@ static const struct gpio_bank gpio_bank_34xx[6] = {
 
 const struct gpio_bank *const omap_gpio_bank = gpio_bank_34xx;
 
+#endif
+
 #ifdef CONFIG_SPL_BUILD
 /*
 * We use static variables because global data is not ready yet.
board/isee/igep00x0/igep00x0.c +13 -0
index 3b2b1f1..7b87cc2 100644
@@ -5,6 +5,8 @@
  * SPDX-License-Identifier:	GPL-2.0+
  */
 #include <common.h>
+#include <dm.h>
+#include <ns16550.h>
 #include <twl4030.h>
 #include <netdev.h>
 #include <asm/gpio.h>
@@ -30,6 +32,17 @@ static const u32 gpmc_lan_config[] = {
 };
 #endif
 
+static const struct ns16550_platdata igep_serial = {
+	OMAP34XX_UART3,
+	2,
+	V_NS16550_CLK
+};
+
+U_BOOT_DEVICE(igep_uart) = {
+	"serial_omap",
+	&igep_serial
+};
+
 /*
  * Routine: board_init
  * Description: Early hardware init.
board/logicpd/zoom1/zoom1.c +13 -0
index 461a852..9ef0026 100644
@@ -15,6 +15,8 @@
  * SPDX-License-Identifier:	GPL-2.0+
  */
 #include <common.h>
+#include <dm.h>
+#include <ns16550.h>
 #include <netdev.h>
 #include <twl4030.h>
 #include <asm/io.h>
@@ -41,6 +43,17 @@ static const u32 gpmc_lab_enet[] = {
 	/*CONF7- computed as params */
 };
 
+static const struct ns16550_platdata zoom1_serial = {
+	OMAP34XX_UART3,
+	2,
+	V_NS16550_CLK
+};
+
+U_BOOT_DEVICE(zoom1_uart) = {
+	"serial_omap",
+	&zoom1_serial
+};
+
 /*
  * Routine: board_init
  * Description: Early hardware init.
board/overo/overo.c +13 -0
index 13220c5..7506820 100644
@@ -13,6 +13,8 @@
  * SPDX-License-Identifier:	GPL-2.0+
  */
 #include <common.h>
+#include <dm.h>
+#include <ns16550.h>
 #include <netdev.h>
 #include <twl4030.h>
 #include <linux/mtd/nand.h>
@@ -73,6 +75,17 @@ static const u32 gpmc_lan_config[] = {
     /*CONFIG7- computed as params */
 };
 
+static const struct ns16550_platdata overo_serial = {
+	OMAP34XX_UART3,
+	2,
+	V_NS16550_CLK
+};
+
+U_BOOT_DEVICE(overo_uart) = {
+	"serial_omap",
+	&overo_serial
+};
+
 /*
  * Routine: board_init
  * Description: Early hardware init.
board/ti/beagle/beagle.c +30 -17

71 lines not on this page · raw message

board/ti/beagle/led.c +30 -31

77 lines not on this page · raw message

include/configs/ti_omap3_common.h +16 -3
index 3b19d3d..3c634ee 100644
@@ -18,6 +18,15 @@
 #include <asm/arch/cpu.h>
 #include <asm/arch/omap3.h>
 
+#ifndef CONFIG_SPL_BUILD
+# define CONFIG_DM
+# define CONFIG_CMD_DM
+# define CONFIG_DM_GPIO
+# define CONFIG_DM_SERIAL
+# define CONFIG_OMAP_SERIAL
+# define CONFIG_SYS_MALLOC_F_LEN	(1 << 10)
+#endif
+
 /* The chip has SDRC controller */
 #define CONFIG_SDRC
 
@@ -28,16 +37,20 @@
 /* NS16550 Configuration */
 #define V_NS16550_CLK			48000000	/* 48MHz (APLL96/2) */
 #define CONFIG_SYS_NS16550
-#define CONFIG_SYS_NS16550_SERIAL
-#define CONFIG_SYS_NS16550_REG_SIZE	(-4)
-#define CONFIG_SYS_NS16550_CLK		V_NS16550_CLK
+#ifdef CONFIG_SPL_BUILD
+# define CONFIG_SYS_NS16550_SERIAL
+# define CONFIG_SYS_NS16550_REG_SIZE	(-4)
+# define CONFIG_SYS_NS16550_CLK		V_NS16550_CLK
+#endif
 #define CONFIG_SYS_BAUDRATE_TABLE	{4800, 9600, 19200, 38400, 57600, \
 					115200}
 
 /* Select serial console configuration */
 #define CONFIG_CONS_INDEX		3
+#ifdef CONFIG_SPL_BUILD
 #define CONFIG_SYS_NS16550_COM3		OMAP34XX_UART3
 #define CONFIG_SERIAL3			3
+#endif
 
 /* Physical Memory Map */
 #define PHYS_SDRAM_1		OMAP34XX_SDRC_CS0
Signature · 1 line
2.1.0.rc2.206.gedb03e5
#30 lore raw

PATCH v2 15/15 dm: omap3: Move to driver model for GPIO and serial

Quoted 4 lines · Simon Glass

Adjust the configuration for the am33xx boards, including beagleboard, to use driver model.

Signature · 8 lines
Tom
-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 836 bytes
Desc: Digital signature
URL: <http://lists.denx.de/pipermail/u-boot/attachments/20141023/881da610/attachment.pgp>
#32 lore raw

v2 cover dm: omap: Provide access to driver model for am335x, and move boards

In reply to Simon Glass

Hi,

Quoted 20 lines · Simon Glass

This series adjusts the serial and GPIO drivers, used by Beaglebone for example, to work with driver model. Since there are still boards using these drivers but not driver model, this adds new functionality rather than replacing what exists.

Several patches tweak and fix the existing driver model serial and GPIO implementation.

There are two Beaglebone Black configurations:

- Device tree control with verified boot
- No device tree control

The first uses device tree to select the serial console and provide information needed by the serial driver (similar to how things work on Tegra). The second uses platform data provided by a common board file.

Both are converted, so this is a good example of how to support both device tree and platform data if needed.

Quoted 8 lines

In addition, in v2, the rest of the OMAP3 boards are converted to driver model.

Changes in v2:
- Fix "is available" typo
- Use of_match_ptr() to avoid #ifdef
- Add patch to move OMAP3 boards to driver model also

Note: the OMAP3 changes are all in the last patch. I will send a pull for the other patches soon, but leave the last patch out for now.

Regards,
Simon