Skip to contentSkip to conversation

dm: Introduce driver model for sunxi

PATCH Superseded Simon Glass 2 participants 10 messages Oct 31, 2014 – Nov 1, 2014

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

v3 cover dm: Introduce driver model for sunxi

This series adds driver model support for serial and GPIO for sunxi. Since I only have a sun7i board to test with, I have added a new config for the pcDuino3, which uses device tree and driver model. This should make it fairly easy to enable for the other boards at some point.

This series is available at u-boot-dm/sunix-working.

Changes in v3:
- Move enabling of 'dm' command to sunxi-common.h
- Put enabling of DM GPIO into sunxi-common.h
- Rebase to master
- Move DM enable options to sunxi-common

Changes in v2:
- Remove references to exynos and tegra
- Use the word 'bank' instead of 'port'
- Split non-sunxi patches into a separate dependent series

Simon Glass (6):
dm: sunxi: dts: Add sun7i device tree files
dm: sunxi: Add a new config for an FDT-based pcDuino3
dm: sunxi: Add pinmux functions which take a bank parameter
dm: sunxi: Make sure that GPIOs are requested
dm: sunxi: Modify the GPIO driver to support driver model
dm: sunxi: Add support for serial using driver model

 Makefile                                  |   3 +-
 arch/arm/cpu/armv7/sunxi/pinmux.c         |  32 +-
 arch/arm/dts/Makefile                     |   1 +
 arch/arm/dts/sun7i-a20-pcduino3.dts       | 177 ++++++
 arch/arm/dts/sun7i-a20.dtsi               | 988 ++++++++++++++++++++++++++++++
 arch/arm/dts/sunxi-common-regulators.dtsi |  89 +++
 arch/arm/include/asm/arch-sunxi/gpio.h    |   4 +-
 board/sunxi/MAINTAINERS                   |   1 +
 board/sunxi/ahci.c                        |   1 +
 configs/Linksprite_pcDuino3_fdt_defconfig |   8 +
 drivers/gpio/sunxi_gpio.c                 | 170 +++++
 drivers/serial/Makefile                   |   1 +
 drivers/serial/serial_dw.c                |  39 ++
 include/configs/sunxi-common.h            |  22 +-
 include/dt-bindings/input/input.h         | 525 ++++++++++++++++
 15 files changed, 2042 insertions(+), 19 deletions(-)
 create mode 100644 arch/arm/dts/sun7i-a20-pcduino3.dts
 create mode 100644 arch/arm/dts/sun7i-a20.dtsi
 create mode 100644 arch/arm/dts/sunxi-common-regulators.dtsi
 create mode 100644 configs/Linksprite_pcDuino3_fdt_defconfig
 create mode 100644 drivers/serial/serial_dw.c
 create mode 100644 include/dt-bindings/input/input.h
Signature · 1 line
2.1.0.rc2.206.gedb03e5
#1 lore raw

PATCH v3 1/6 dm: sunxi: dts: Add sun7i device tree files

These are from Linux 3.17-rc7 (commit fe82dcec). U-Boot only uses a small portion of these, but we may as well have something to look forward to.

The total compiled size is about 25KB.

---

Changes in v3: None
Changes in v2: None

 arch/arm/dts/sun7i-a20-pcduino3.dts       | 173 ++++++
 arch/arm/dts/sun7i-a20.dtsi               | 988 ++++++++++++++++++++++++++++++
 arch/arm/dts/sunxi-common-regulators.dtsi |  89 +++
 include/dt-bindings/input/input.h         | 525 ++++++++++++++++
 4 files changed, 1775 insertions(+)
 create mode 100644 arch/arm/dts/sun7i-a20-pcduino3.dts
 create mode 100644 arch/arm/dts/sun7i-a20.dtsi
 create mode 100644 arch/arm/dts/sunxi-common-regulators.dtsi
 create mode 100644 include/dt-bindings/input/input.h
arch/arm/dts/sun7i-a20-pcduino3.dts new file +173 -0
new file mode 100644
index 0000000..046dfc0
@@ -0,0 +1,173 @@
+/*
+ * Copyright 2014 Zoltan HERPAI
+ * Zoltan HERPAI <[email protected]>
+ *
+ * The code contained herein is licensed under the GNU General Public
+ * License. You may obtain a copy of the GNU General Public License
+ * Version 2 or later at the following locations:
+ *
+ * http://www.opensource.org/licenses/gpl-license.html
+ * http://www.gnu.org/copyleft/gpl.html
+ */
+
+/dts-v1/;
+/include/ "sun7i-a20.dtsi"
+/include/ "sunxi-common-regulators.dtsi"
+#include <dt-bindings/gpio/gpio.h>
+#include <dt-bindings/input/input.h>
+
+/ {
+	model = "LinkSprite pcDuino3";
+	compatible = "linksprite,pcduino3", "allwinner,sun7i-a20";
+
+	soc at 01c00000 {
+		mmc0: mmc at 01c0f000 {
+			pinctrl-names = "default";
+			pinctrl-0 = <&mmc0_pins_a>, <&mmc0_cd_pin_reference_design>;
+			vmmc-supply = <&reg_vcc3v3>;
+			bus-width = <4>;
+			cd-gpios = <&pio 7 1 0>; /* PH1 */
+			cd-inverted;
+			status = "okay";
+		};
+
+		usbphy: phy at 01c13400 {
+			usb1_vbus-supply = <&reg_usb1_vbus>;
+			usb2_vbus-supply = <&reg_usb2_vbus>;
+			status = "okay";
+		};
+
+		ehci0: usb at 01c14000 {
+			status = "okay";
+		};
+
+		ohci0: usb at 01c14400 {
+			status = "okay";
+		};
+
+		ahci: sata at 01c18000 {
+			target-supply = <&reg_ahci_5v>;
+			status = "okay";
+		};
+
+		ehci1: usb at 01c1c000 {
+			status = "okay";
+		};
+
+		ohci1: usb at 01c1c400 {
+			status = "okay";
+		};
+
+		pinctrl at 01c20800 {
+			ahci_pwr_pin_a: ahci_pwr_pin at 0 {
+				allwinner,pins = "PH2";
+			};
+
+			led_pins_pcduino3: led_pins at 0 {
+				allwinner,pins = "PH15", "PH16";
+				allwinner,function = "gpio_out";
+				allwinner,drive = <0>;
+				allwinner,pull = <0>;
+			};
+
+			key_pins_pcduino3: key_pins at 0 {
+				allwinner,pins = "PH17", "PH18", "PH19";
+				allwinner,function = "gpio_in";
+				allwinner,drive = <0>;
+				allwinner,pull = <0>;
+			};
+		};
+
+		ir0: ir at 01c21800 {
+			pinctrl-names = "default";
+			pinctrl-0 = <&ir0_pins_a>;
+			status = "okay";
+		};
+
+		uart0: serial at 01c28000 {
+			pinctrl-names = "default";
+			pinctrl-0 = <&uart0_pins_a>;
+			status = "okay";
+		};
+
+		i2c0: i2c at 01c2ac00 {
+			pinctrl-names = "default";
+			pinctrl-0 = <&i2c0_pins_a>;
+			status = "okay";
+
+			axp209: pmic at 34 {
+				compatible = "x-powers,axp209";
+				reg = <0x34>;
+				interrupt-parent = <&nmi_intc>;
+				interrupts = <0 8>;
+
+				interrupt-controller;
+				#interrupt-cells = <1>;
+			};
+		};
+
+		gmac: ethernet at 01c50000 {
+			pinctrl-names = "default";
+			pinctrl-0 = <&gmac_pins_mii_a>;
+			phy = <&phy1>;
+			phy-mode = "mii";
+			status = "okay";
+
+			phy1: ethernet-phy at 1 {
+				reg = <1>;
+			};
+		};
+	};
+
+	leds {
+		compatible = "gpio-leds";
+		pinctrl-names = "default";
+		pinctrl-0 = <&led_pins_pcduino3>;
+
+		tx {
+			label = "pcduino3:green:tx";
+			gpios = <&pio 7 15 GPIO_ACTIVE_LOW>;
+		};
+
+		rx {
+			label = "pcduino3:green:rx";
+			gpios = <&pio 7 16 GPIO_ACTIVE_LOW>;
+		};
+	};
+
+	gpio_keys {
+		compatible = "gpio-keys";
+		pinctrl-names = "default";
+		pinctrl-0 = <&key_pins_pcduino3>;
+		#address-cells = <1>;
+		#size-cells = <0>;
+		button at 0 {
+			label = "Key Back";
+			linux,code = <KEY_BACK>;
+			gpios = <&pio 7 17 GPIO_ACTIVE_LOW>;
+		};
+		button at 1 {
+			label = "Key Home";
+			linux,code = <KEY_HOME>;
+			gpios = <&pio 7 18 GPIO_ACTIVE_LOW>;
+		};
+		button at 2 {
+			label = "Key Menu";
+			linux,code = <KEY_MENU>;
+			gpios = <&pio 7 19 GPIO_ACTIVE_LOW>;
+		};
+	};
+
+	reg_usb1_vbus: usb1-vbus {
+		status = "okay";
+	};
+
+	reg_usb2_vbus: usb2-vbus {
+		status = "okay";
+	};
+
+	reg_ahci_5v: ahci-5v {
+		gpio = <&pio 7 2 0>;
+		status = "okay";
+	};
+};
arch/arm/dts/sun7i-a20.dtsi new file +988 -0

988 lines not on this page · raw message

arch/arm/dts/sunxi-common-regulators.dtsi new file +89 -0

89 lines not on this page · raw message

include/dt-bindings/input/input.h new file +525 -0

525 lines not on this page · raw message

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

PATCH v3 2/6 dm: sunxi: Add a new config for an FDT-based pcDuino3

In reply to Simon Glass

For now we won't want to mess with the existing configurations. Create a new one which will enable device tree and driver model. Note that this brings the device tree binary into u-boot-sunxi-with-spl.bin.

---

Changes in v3:
- Move enabling of 'dm' command to sunxi-common.h

Changes in v2: None

 Makefile                                  | 3 ++-
 arch/arm/dts/Makefile                     | 1 +
 board/sunxi/MAINTAINERS                   | 1 +
 configs/Linksprite_pcDuino3_fdt_defconfig | 8 ++++++++
 include/configs/sunxi-common.h            | 4 ++++
 5 files changed, 16 insertions(+), 1 deletion(-)
 create mode 100644 configs/Linksprite_pcDuino3_fdt_defconfig
Makefile +2 -1
index 26dacee..9c8a580 100644
@@ -946,7 +946,8 @@ u-boot-nand.gph: u-boot.bin FORCE
 ifneq ($(CONFIG_SUNXI),)
 OBJCOPYFLAGS_u-boot-sunxi-with-spl.bin = -I binary -O binary \
 				   --pad-to=$(CONFIG_SPL_PAD_TO) --gap-fill=0xff
-u-boot-sunxi-with-spl.bin: spl/sunxi-spl.bin u-boot.img FORCE
+u-boot-sunxi-with-spl.bin: spl/sunxi-spl.bin \
+			u-boot$(if $(CONFIG_OF_CONTROL),-dtb,).img FORCE
 	$(call if_changed,pad_cat)
 endif
 
arch/arm/dts/Makefile +1 -0
index c346063..7c7f7d8 100644
@@ -1,3 +1,4 @@
+dtb-$(CONFIG_SUN7I) +=  sun7i-a20-pcduino3.dtb
 dtb-$(CONFIG_S5PC100) += s5pc1xx-smdkc100.dtb
 dtb-$(CONFIG_S5PC110) += s5pc1xx-goni.dtb
 dtb-$(CONFIG_EXYNOS4) += exynos4210-origen.dtb \
board/sunxi/MAINTAINERS +1 -0
index febd126..d624f52 100644
@@ -22,6 +22,7 @@ F:	configs/A20-OLinuXino_MICRO_defconfig
 F:	configs/Bananapi_defconfig
 F:	configs/i12-tvbox_defconfig
 F:	configs/Linksprite_pcDuino3_defconfig
+F:	configs/Linksprite_pcDuino3_fdt_defconfig
 F:	configs/qt840a_defconfig
 
 CUBIEBOARD2 BOARD
configs/Linksprite_pcDuino3_fdt_defconfig new file +8 -0
new file mode 100644
index 0000000..e5f6236
@@ -0,0 +1,8 @@
+CONFIG_SPL=y
+CONFIG_SYS_EXTRA_OPTIONS="PCDUINO3,AXP209_POWER,SUNXI_GMAC,AHCI,SATAPWR=SUNXI_GPH(2),USB_EHCI,DM"
+CONFIG_FDTFILE="sun7i-a20-pcduino3.dtb"
+CONFIG_DEFAULT_DEVICE_TREE="sun7i-a20-pcduino3"
+CONFIG_OF_CONTROL=y
+CONFIG_OF_SEPARATE=y
++S:CONFIG_ARM=y
++S:CONFIG_TARGET_SUN7I=y
include/configs/sunxi-common.h +4 -0
index cc450e0..4d88991 100644
@@ -27,6 +27,10 @@
 
 #define CONFIG_SYS_TEXT_BASE		0x4a000000
 
+#if !defined(CONFIG_SPL_BUILD) && defined(CONFIG_DM)
+# define CONFIG_CMD_DM
+#endif
+
 /*
  * Display CPU information
  */
Signature · 1 line
2.1.0.rc2.206.gedb03e5
#3 lore raw

PATCH v3 3/6 dm: sunxi: Add pinmux functions which take a bank parameter

In reply to Simon Glass

With driver model we will have access to a bank pointer, so we want to use it rather than converting back to a number, and then back to a bank pointer. Add functions to provide this feature.

---

Changes in v3: None
Changes in v2: None

 arch/arm/cpu/armv7/sunxi/pinmux.c      | 32 +++++++++++++++++++++-----------
 arch/arm/include/asm/arch-sunxi/gpio.h |  4 +++-
 2 files changed, 24 insertions(+), 12 deletions(-)
arch/arm/cpu/armv7/sunxi/pinmux.c +21 -11
index 1f2843f..b026f78 100644
@@ -10,32 +10,42 @@
 #include <asm/io.h>
 #include <asm/arch/gpio.h>
 
-int sunxi_gpio_set_cfgpin(u32 pin, u32 val)
+void sunxi_gpio_set_cfgbank(struct sunxi_gpio *pio, int bank_offset, u32 val)
 {
-	u32 bank = GPIO_BANK(pin);
-	u32 index = GPIO_CFG_INDEX(pin);
-	u32 offset = GPIO_CFG_OFFSET(pin);
-	struct sunxi_gpio *pio = BANK_TO_GPIO(bank);
+	u32 index = GPIO_CFG_INDEX(bank_offset);
+	u32 offset = GPIO_CFG_OFFSET(bank_offset);
 
 	clrsetbits_le32(&pio->cfg[0] + index, 0xf << offset, val << offset);
-
-	return 0;
 }
 
-int sunxi_gpio_get_cfgpin(u32 pin)
+void sunxi_gpio_set_cfgpin(u32 pin, u32 val)
 {
-	u32 cfg;
 	u32 bank = GPIO_BANK(pin);
-	u32 index = GPIO_CFG_INDEX(pin);
-	u32 offset = GPIO_CFG_OFFSET(pin);
 	struct sunxi_gpio *pio = BANK_TO_GPIO(bank);
 
+	sunxi_gpio_set_cfgbank(pio, pin, val);
+}
+
+int sunxi_gpio_get_cfgbank(struct sunxi_gpio *pio, int bank_offset)
+{
+	u32 index = GPIO_CFG_INDEX(bank_offset);
+	u32 offset = GPIO_CFG_OFFSET(bank_offset);
+	u32 cfg;
+
 	cfg = readl(&pio->cfg[0] + index);
 	cfg >>= offset;
 
 	return cfg & 0xf;
 }
 
+int sunxi_gpio_get_cfgpin(u32 pin)
+{
+	u32 bank = GPIO_BANK(pin);
+	struct sunxi_gpio *pio = BANK_TO_GPIO(bank);
+
+	return sunxi_gpio_get_cfgbank(pio, pin);
+}
+
 int sunxi_gpio_set_drv(u32 pin, u32 val)
 {
 	u32 bank = GPIO_BANK(pin);
arch/arm/include/asm/arch-sunxi/gpio.h +3 -1
index 7bb6499..989ad80 100644
@@ -180,7 +180,9 @@ enum sunxi_gpio_number {
 #define SUNXI_GPIO_PULL_UP	1
 #define SUNXI_GPIO_PULL_DOWN	2
 
-int sunxi_gpio_set_cfgpin(u32 pin, u32 val);
+void sunxi_gpio_set_cfgbank(struct sunxi_gpio *pio, int bank_offset, u32 val);
+void sunxi_gpio_set_cfgpin(u32 pin, u32 val);
+int sunxi_gpio_get_cfgbank(struct sunxi_gpio *pio, int bank_offset);
 int sunxi_gpio_get_cfgpin(u32 pin);
 int sunxi_gpio_set_drv(u32 pin, u32 val);
 int sunxi_gpio_set_pull(u32 pin, u32 val);
Signature · 1 line
2.1.0.rc2.206.gedb03e5
#4 lore raw

PATCH v3 4/6 dm: sunxi: Make sure that GPIOs are requested

In reply to Simon Glass

The scsi_init() function uses a GPIO so should request it. There is no way to return an error here, and the request may be made multiple times, so just ignore errors for now.

---

Changes in v3: None
Changes in v2: None

 board/sunxi/ahci.c | 1 +
 1 file changed, 1 insertion(+)
board/sunxi/ahci.c +1 -0
index 0c262ea..5e12328 100644
@@ -74,6 +74,7 @@ void scsi_init(void)
 {
 	printf("SUNXI SCSI INIT\n");
 #ifdef CONFIG_SATAPWR
+	gpio_request(CONFIG_SATAPWR, "satapwr");
 	gpio_direction_output(CONFIG_SATAPWR, 1);
 #endif
 
Signature · 1 line
2.1.0.rc2.206.gedb03e5
#5 lore raw

PATCH v3 5/6 dm: sunxi: Modify the GPIO driver to support driver model

In reply to Simon Glass

This adds driver model support to the sunxi GPIO driver, using the device tree to trigger binding of the driver. The driver will still operate without driver model too.

---

Changes in v3:
- Put enabling of DM GPIO into sunxi-common.h

Changes in v2:
- Remove references to exynos and tegra
- Use the word 'bank' instead of 'port'

 drivers/gpio/sunxi_gpio.c      | 170 +++++++++++++++++++++++++++++++++++++++++
 include/configs/sunxi-common.h |   1 +
 2 files changed, 171 insertions(+)
drivers/gpio/sunxi_gpio.c +170 -0
index 0c50a8f..44135e5 100644
@@ -11,9 +11,25 @@
  */
 
 #include <common.h>
+#include <dm.h>
+#include <errno.h>
+#include <fdtdec.h>
+#include <malloc.h>
 #include <asm/io.h>
 #include <asm/gpio.h>
+#include <dm/device-internal.h>
 
+DECLARE_GLOBAL_DATA_PTR;
+
+#define SUNXI_GPIOS_PER_BANK	SUNXI_GPIO_A_NR
+
+struct sunxi_gpio_platdata {
+	struct sunxi_gpio *regs;
+	const char *bank_name;	/* Name of bank, e.g. "B" */
+	int gpio_count;
+};
+
+#ifndef CONFIG_DM_GPIO
 static int sunxi_gpio_output(u32 pin, u32 val)
 {
 	u32 dat;
@@ -100,3 +116,157 @@ int sunxi_name_to_gpio(const char *name)
 		return -1;
 	return group * 32 + pin;
 }
+#endif
+
+#ifdef CONFIG_DM_GPIO
+static int sunxi_gpio_direction_input(struct udevice *dev, unsigned offset)
+{
+	struct sunxi_gpio_platdata *plat = dev_get_platdata(dev);
+
+	sunxi_gpio_set_cfgbank(plat->regs, offset, SUNXI_GPIO_INPUT);
+
+	return 0;
+}
+
+static int sunxi_gpio_direction_output(struct udevice *dev, unsigned offset,
+				       int value)
+{
+	struct sunxi_gpio_platdata *plat = dev_get_platdata(dev);
+	u32 num = GPIO_NUM(offset);
+
+	sunxi_gpio_set_cfgbank(plat->regs, offset, SUNXI_GPIO_OUTPUT);
+	clrsetbits_le32(&plat->regs->dat, 1 << num, value ? (1 << num) : 0);
+
+	return 0;
+}
+
+static int sunxi_gpio_get_value(struct udevice *dev, unsigned offset)
+{
+	struct sunxi_gpio_platdata *plat = dev_get_platdata(dev);
+	u32 num = GPIO_NUM(offset);
+	unsigned dat;
+
+	dat = readl(&plat->regs->dat);
+	dat >>= num;
+
+	return dat & 0x1;
+}
+
+static int sunxi_gpio_set_value(struct udevice *dev, unsigned offset,
+				int value)
+{
+	struct sunxi_gpio_platdata *plat = dev_get_platdata(dev);
+	u32 num = GPIO_NUM(offset);
+
+	clrsetbits_le32(&plat->regs->dat, 1 << num, value ? (1 << num) : 0);
+	return 0;
+}
+
+static int sunxi_gpio_get_function(struct udevice *dev, unsigned offset)
+{
+	struct sunxi_gpio_platdata *plat = dev_get_platdata(dev);
+	int func;
+
+	func = sunxi_gpio_get_cfgbank(plat->regs, offset);
+	if (func == SUNXI_GPIO_OUTPUT)
+		return GPIOF_OUTPUT;
+	else if (func == SUNXI_GPIO_INPUT)
+		return GPIOF_INPUT;
+	else
+		return GPIOF_FUNC;
+}
+
+static const struct dm_gpio_ops gpio_sunxi_ops = {
+	.direction_input	= sunxi_gpio_direction_input,
+	.direction_output	= sunxi_gpio_direction_output,
+	.get_value		= sunxi_gpio_get_value,
+	.set_value		= sunxi_gpio_set_value,
+	.get_function		= sunxi_gpio_get_function,
+};
+
+/**
+ * Returns the name of a GPIO bank
+ *
+ * GPIO banks are named A, B, C, ...
+ *
+ * @bank:	Bank number (0, 1..n-1)
+ * @return allocated string containing the name
+ */
+static char *gpio_bank_name(int bank)
+{
+	char *name;
+
+	name = malloc(2);
+	if (name) {
+		name[0] = 'A' + bank;
+		name[1] = '\0';
+	}
+
+	return name;
+}
+
+static int gpio_sunxi_probe(struct udevice *dev)
+{
+	struct sunxi_gpio_platdata *plat = dev_get_platdata(dev);
+	struct gpio_dev_priv *uc_priv = dev->uclass_priv;
+
+	/* Tell the uclass how many GPIOs we have */
+	if (plat) {
+		uc_priv->gpio_count = plat->gpio_count;
+		uc_priv->bank_name = plat->bank_name;
+	}
+
+	return 0;
+}
+/**
+ * We have a top-level GPIO device with no actual GPIOs. It has a child
+ * device for each Sunxi bank.
+ */
+static int gpio_sunxi_bind(struct udevice *parent)
+{
+	struct sunxi_gpio_platdata *plat = parent->platdata;
+	struct sunxi_gpio_reg *ctlr;
+	int bank;
+	int ret;
+
+	/* If this is a child device, there is nothing to do here */
+	if (plat)
+		return 0;
+
+	ctlr = (struct sunxi_gpio_reg *)fdtdec_get_addr(gd->fdt_blob,
+						   parent->of_offset, "reg");
+	for (bank = 0; bank < SUNXI_GPIO_BANKS; bank++) {
+		struct sunxi_gpio_platdata *plat;
+		struct udevice *dev;
+
+		plat = calloc(1, sizeof(*plat));
+		if (!plat)
+			return -ENOMEM;
+		plat->regs = &ctlr->gpio_bank[bank];
+		plat->bank_name = gpio_bank_name(bank);
+		plat->gpio_count = SUNXI_GPIOS_PER_BANK;
+
+		ret = device_bind(parent, parent->driver,
+					plat->bank_name, plat, -1, &dev);
+		if (ret)
+			return ret;
+		dev->of_offset = parent->of_offset;
+	}
+
+	return 0;
+}
+
+static const struct udevice_id sunxi_gpio_ids[] = {
+	{ .compatible = "allwinner,sun7i-a20-pinctrl" },
+	{ }
+};
+
+U_BOOT_DRIVER(gpio_sunxi) = {
+	.name	= "gpio_sunxi",
+	.id	= UCLASS_GPIO,
+	.ops	= &gpio_sunxi_ops,
+	.of_match = sunxi_gpio_ids,
+	.bind	= gpio_sunxi_bind,
+	.probe	= gpio_sunxi_probe,
+};
+#endif
include/configs/sunxi-common.h +1 -0
index 4d88991..316e7d9 100644
@@ -29,6 +29,7 @@
 
 #if !defined(CONFIG_SPL_BUILD) && defined(CONFIG_DM)
 # define CONFIG_CMD_DM
+# define CONFIG_DM_GPIO
 #endif
 
 /*
Signature · 1 line
2.1.0.rc2.206.gedb03e5
#6 lore raw

PATCH v3 6/6 dm: sunxi: Add support for serial using driver model

In reply to Simon Glass

Add a driver for the designware serial UART used on sunxi. This just redirects to the normal ns16550 driver.

Add a stdout-path to the device tree so that the correct UART is chosen.

---

Changes in v3:
- Rebase to master
- Move DM enable options to sunxi-common

Changes in v2:
- Split non-sunxi patches into a separate dependent series

 arch/arm/dts/sun7i-a20-pcduino3.dts |  4 ++++
 drivers/serial/Makefile             |  1 +
 drivers/serial/serial_dw.c          | 39 +++++++++++++++++++++++++++++++++++++
 include/configs/sunxi-common.h      | 17 ++++++++++------
 4 files changed, 55 insertions(+), 6 deletions(-)
 create mode 100644 drivers/serial/serial_dw.c
arch/arm/dts/sun7i-a20-pcduino3.dts +4 -0
index 046dfc0..f7cc8e7 100644
@@ -20,6 +20,10 @@
 	model = "LinkSprite pcDuino3";
 	compatible = "linksprite,pcduino3", "allwinner,sun7i-a20";
 
+	chosen {
+		stdout-path = &uart0;
+	};
+
 	soc at 01c00000 {
 		mmc0: mmc at 01c0f000 {
 			pinctrl-names = "default";
drivers/serial/Makefile +1 -0
index 2c19ebc..8c84942 100644
@@ -19,6 +19,7 @@ obj-$(CONFIG_ALTERA_UART) += altera_uart.o
 obj-$(CONFIG_ALTERA_JTAG_UART) += altera_jtag_uart.o
 obj-$(CONFIG_ARM_DCC) += arm_dcc.o
 obj-$(CONFIG_ATMEL_USART) += atmel_usart.o
+obj-$(CONFIG_DW_SERIAL) += serial_dw.o
 obj-$(CONFIG_LPC32XX_HSUART) += lpc32xx_hsuart.o
 obj-$(CONFIG_MCFUART) += mcfuart.o
 obj-$(CONFIG_OPENCORES_YANU) += opencores_yanu.o
drivers/serial/serial_dw.c new file +39 -0
new file mode 100644
index 0000000..a348f29
@@ -0,0 +1,39 @@
+/*
+ * Copyright (c) 2014 Google, Inc
+ *
+ * SPDX-License-Identifier:	GPL-2.0+
+ */
+
+#include <common.h>
+#include <dm.h>
+#include <ns16550.h>
+#include <serial.h>
+
+static const struct udevice_id dw_serial_ids[] = {
+	{ .compatible = "snps,dw-apb-uart" },
+	{ }
+};
+
+static int dw_serial_ofdata_to_platdata(struct udevice *dev)
+{
+	struct ns16550_platdata *plat = dev_get_platdata(dev);
+	int ret;
+
+	ret = ns16550_serial_ofdata_to_platdata(dev);
+	if (ret)
+		return ret;
+	plat->clock = CONFIG_SYS_NS16550_CLK;
+
+	return 0;
+}
+
+U_BOOT_DRIVER(serial_ns16550) = {
+	.name	= "serial_dw",
+	.id	= UCLASS_SERIAL,
+	.of_match = dw_serial_ids,
+	.ofdata_to_platdata = dw_serial_ofdata_to_platdata,
+	.platdata_auto_alloc_size = sizeof(struct ns16550_platdata),
+	.priv_auto_alloc_size = sizeof(struct NS16550),
+	.probe = ns16550_serial_probe,
+	.ops	= &ns16550_serial_ops,
+};
include/configs/sunxi-common.h +11 -6
index 316e7d9..ce038ed 100644
@@ -30,6 +30,9 @@
 #if !defined(CONFIG_SPL_BUILD) && defined(CONFIG_DM)
 # define CONFIG_CMD_DM
 # define CONFIG_DM_GPIO
+# define CONFIG_DM_SERIAL
+# define CONFIG_DW_SERIAL
+# define CONFIG_SYS_MALLOC_F_LEN	(1 << 10)
 #endif
 
 /*
@@ -41,13 +44,15 @@
 #define CONFIG_SYS_NS16550
 #define CONFIG_SYS_NS16550_SERIAL
 /* ns16550 reg in the low bits of cpu reg */
-#define CONFIG_SYS_NS16550_REG_SIZE	-4
 #define CONFIG_SYS_NS16550_CLK		24000000
-#define CONFIG_SYS_NS16550_COM1		SUNXI_UART0_BASE
-#define CONFIG_SYS_NS16550_COM2		SUNXI_UART1_BASE
-#define CONFIG_SYS_NS16550_COM3		SUNXI_UART2_BASE
-#define CONFIG_SYS_NS16550_COM4		SUNXI_UART3_BASE
-#define CONFIG_SYS_NS16550_COM5		SUNXI_R_UART_BASE
+#ifndef CONFIG_DM_SERIAL
+# define CONFIG_SYS_NS16550_REG_SIZE	-4
+# define CONFIG_SYS_NS16550_COM1		SUNXI_UART0_BASE
+# define CONFIG_SYS_NS16550_COM2		SUNXI_UART1_BASE
+# define CONFIG_SYS_NS16550_COM3		SUNXI_UART2_BASE
+# define CONFIG_SYS_NS16550_COM4		SUNXI_UART3_BASE
+# define CONFIG_SYS_NS16550_COM5		SUNXI_R_UART_BASE
+#endif
 
 /* DRAM Base */
 #define CONFIG_SYS_SDRAM_BASE		0x40000000
Signature · 1 line
2.1.0.rc2.206.gedb03e5
#7 lore raw

v3 cover dm: Introduce driver model for sunxi

In reply to Simon Glass

Hi,

Quoted 18 lines · Simon Glass

This series adds driver model support for serial and GPIO for sunxi. Since I only have a sun7i board to test with, I have added a new config for the pcDuino3, which uses device tree and driver model. This should make it fairly easy to enable for the other boards at some point.

This series is available at u-boot-dm/sunix-working.

Changes in v3:
- Move enabling of 'dm' command to sunxi-common.h
- Put enabling of DM GPIO into sunxi-common.h
- Rebase to master
- Move DM enable options to sunxi-common

Changes in v2:
- Remove references to exynos and tegra
- Use the word 'bank' instead of 'port'
- Split non-sunxi patches into a separate dependent series

Quoted 7 lines

Simon Glass (6):
dm: sunxi: dts: Add sun7i device tree files
dm: sunxi: Add a new config for an FDT-based pcDuino3
dm: sunxi: Add pinmux functions which take a bank parameter
dm: sunxi: Make sure that GPIOs are requested
dm: sunxi: Modify the GPIO driver to support driver model
dm: sunxi: Add support for serial using driver model

Thanks, merged and pushed to u-boot-sunxi/next, I'm going to run some tests now, and when those are done I'll also push this to u-boot-sunxi/master and send a pull-req.

Regards,

Hans

#8 lore raw

v3 cover dm: Introduce driver model for sunxi

Hi,

Quoted 29 lines · Hans de Goede

Hi,

Quoted 18 lines · Simon Glass

This series adds driver model support for serial and GPIO for sunxi. Since I only have a sun7i board to test with, I have added a new config for the pcDuino3, which uses device tree and driver model. This should make it fairly easy to enable for the other boards at some point.

This series is available at u-boot-dm/sunix-working.

Changes in v3:
- Move enabling of 'dm' command to sunxi-common.h
- Put enabling of DM GPIO into sunxi-common.h
- Rebase to master
- Move DM enable options to sunxi-common

Changes in v2:
- Remove references to exynos and tegra
- Use the word 'bank' instead of 'port'
- Split non-sunxi patches into a separate dependent series

Quoted 7 lines

Simon Glass (6):
dm: sunxi: dts: Add sun7i device tree files
dm: sunxi: Add a new config for an FDT-based pcDuino3
dm: sunxi: Add pinmux functions which take a bank parameter
dm: sunxi: Make sure that GPIOs are requested
dm: sunxi: Modify the GPIO driver to support driver model
dm: sunxi: Add support for serial using driver model

Quoted 3 lines

Thanks, merged and pushed to u-boot-sunxi/next, I'm going to run some tests now, and when those are done I'll also push this to u-boot-sunxi/master and send a pull-req.

Hmm, so the testing did not go as smoothly as I hoped, there were some build issues with the FDT-based pcDuino3 target due to some Kconfig changes (variable renames) by Ian in u-boot-sunxi/next, those where easily fixed, and I've squashed those into the original fixes.

But then I hit problems booting from mmc or usb due to missing gpio_request calls.

I've created 2 fixes for these, and now everything works fine :) I've done a forced push to u-boot-sunxi/next with the fixed patch-set, but I cannot yet send a pull-req as my 2 extra patches need an Acked-by. I'll send them out right after this mail, and as soon as they have an Ack, I'll send the pull-req.

Regards,

Hans

Quoted 9 lines

Regards,

Hans
_______________________________________________
U-Boot mailing list
U-Boot at lists.denx.de
http://lists.denx.de/mailman/listinfo/u-boot

#9 lore raw

v3 cover dm: Introduce driver model for sunxi

Hi Hans,

Quoted 48 lines · Hans de Goede

Hi,

Quoted 4 lines · Hans de Goede

Hi,

Quoted 1 line · Simon Glass

This series adds driver model support for serial and GPIO for sunxi.

Since

Quoted 1 line
Quoted 1 line

I only have a sun7i board to test with, I have added a new config for

the

Quoted 24 lines
Quoted 16 lines

pcDuino3, which uses device tree and driver model. This should make it fairly easy to enable for the other boards at some point.

This series is available at u-boot-dm/sunix-working.

Changes in v3:
- Move enabling of 'dm' command to sunxi-common.h
- Put enabling of DM GPIO into sunxi-common.h
- Rebase to master
- Move DM enable options to sunxi-common

Changes in v2:
- Remove references to exynos and tegra
- Use the word 'bank' instead of 'port'
- Split non-sunxi patches into a separate dependent series

Quoted 7 lines

Simon Glass (6):
dm: sunxi: dts: Add sun7i device tree files
dm: sunxi: Add a new config for an FDT-based pcDuino3
dm: sunxi: Add pinmux functions which take a bank parameter
dm: sunxi: Make sure that GPIOs are requested
dm: sunxi: Modify the GPIO driver to support driver model
dm: sunxi: Add support for serial using driver model

Quoted 1 line

Thanks, merged and pushed to u-boot-sunxi/next, I'm going to run some

tests

Quoted 1 line

now, and when those are done I'll also push this to u-boot-sunxi/master

and

Quoted 1 line

send a pull-req.

Hmm, so the testing did not go as smoothly as I hoped, there were some build issues with the FDT-based pcDuino3 target due to some Kconfig changes (variable renames) by Ian in u-boot-sunxi/next, those where easily fixed, and I've squashed those into the original fixes.

But then I hit problems booting from mmc or usb due to missing gpio_request calls.

Quoted 7 lines

I've created 2 fixes for these, and now everything works fine :) I've done a forced push to u-boot-sunxi/next with the fixed patch-set, but I cannot yet send a pull-req as my 2 extra patches need an Acked-by. I'll send them out
right after this mail, and as soon as they have an Ack, I'll send the pull-req.

Thanks for your efforts here and for dealing with it so quickly. It's no fire drill, my comment about timing was just to avoid having an intrusive patch hanging over people.

Regards,
Simon