Skip to contentSkip to conversation

arm64: Pine64/A64: USB support

PATCH New Andre Przywara 5 participants 17 messages Oct 21, 2016 – Oct 30, 2016

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

cover arm64: Pine64/A64: USB support

Hi,

these two patches enable the first USB host controller on the Pine64 board. This allows to load and boot from USB pen drives inserted into the lower USB socket on the board, for instance.
The first patch massages the OHCI driver to compile cleanly for 64-bit. This is admittedly cutting some corners, as a proper 64-bit fix for that beast is a bit more involved. But apparently the A64 is the first 64-bit user and here the fixes are completely safe, as all memory is always below 4GB. If someone more familiar with that driver could insert checks that the EDs and TDs are allocated from below 4GB (which is an OHCI architecture limit as I understand it), I'd be grateful.

The second patch from Amit then adds the right symbols here and there to enable the USB controller, which just piggy-backs on the H3 support.

This just enables one of the two host controllers (the lower socket), enabling the other one requires some more tweaking of a PHY switch, as the second host controller shares a PHY with the OTG controller. Also we might prefer to use the OTG port as an OTG port in U-Boot (for fastboot support, for instance).

Amit Singh Tomar (1):
sunxi: A64: enable USB support

Andre Przywara (1):
drivers: USB: OHCI: allow compilation for 64-bit targets

 arch/arm/dts/sun50i-a64-pine64-common.dtsi  | 12 ++++++++++++
 arch/arm/dts/sun50i-a64.dtsi                | 29 +++++++++++++++++++++++++++++
 arch/arm/include/asm/arch-sunxi/cpu_sun4i.h |  2 +-
 arch/arm/mach-sunxi/usb_phy.c               |  5 +++--
 configs/pine64_plus_defconfig               |  1 +
 drivers/usb/host/ehci-sunxi.c               |  7 ++++---
 drivers/usb/host/ohci-hcd.c                 | 21 +++++++++++----------
 drivers/usb/host/ohci-sunxi.c               |  3 ++-
 drivers/usb/host/ohci.h                     | 11 +++++++----
 include/configs/sun50i.h                    |  5 +++++
 10 files changed, 75 insertions(+), 21 deletions(-)
Signature · 1 line
2.8.2
#1 lore raw

PATCH 1/2 drivers: USB: OHCI: allow compilation for 64-bit targets

OHCI has a known limitation of allowing only 32-bit DMA buffer addresses, so we have a lot of u32 variables around, which are assigned to pointers and vice versa. This obviously creates issues with 64-bit systems, so the compiler complains here and there.
To allow compilation for 64-bit boards which use only memory below 4GB anyway (and to avoid more invasive fixes), adjust some casts and types and assume that the EDs and TDs are all located in the lower 4GB. This fixes compilation of the OHCI driver for the Pine64.

---
 drivers/usb/host/ohci-hcd.c   | 21 +++++++++++----------
 drivers/usb/host/ohci-sunxi.c |  2 +-
 drivers/usb/host/ohci.h       | 11 +++++++----
 3 files changed, 19 insertions(+), 15 deletions(-)
drivers/usb/host/ohci-hcd.c +11 -10
index ccbfc02..0f6d03e 100644
@@ -682,7 +682,7 @@ static int ep_link(ohci_t *ohci, ed_t *edi)
 		ed->hwNextED = 0;
 		flush_dcache_ed(ed);
 		if (ohci->ed_controltail == NULL)
-			ohci_writel(ed, &ohci->regs->ed_controlhead);
+			ohci_writel((uintptr_t)ed, &ohci->regs->ed_controlhead);
 		else
 			ohci->ed_controltail->hwNextED =
 						   m32_swap((unsigned long)ed);
@@ -700,7 +700,7 @@ static int ep_link(ohci_t *ohci, ed_t *edi)
 		ed->hwNextED = 0;
 		flush_dcache_ed(ed);
 		if (ohci->ed_bulktail == NULL)
-			ohci_writel(ed, &ohci->regs->ed_bulkhead);
+			ohci_writel((uintptr_t)ed, &ohci->regs->ed_bulkhead);
 		else
 			ohci->ed_bulktail->hwNextED =
 						   m32_swap((unsigned long)ed);
@@ -753,7 +753,7 @@ static void periodic_unlink(struct ohci *ohci, volatile struct ed *ed,
 
 		/* ED might have been unlinked through another path */
 		while (*ed_p != 0) {
-			if (((struct ed *)
+			if (((struct ed *)(uintptr_t)
 					m32_swap((unsigned long)ed_p)) == ed) {
 				*ed_p = ed->hwNextED;
 				aligned_ed_p = (unsigned long)ed_p;
@@ -762,7 +762,7 @@ static void periodic_unlink(struct ohci *ohci, volatile struct ed *ed,
 					aligned_ed_p + ARCH_DMA_MINALIGN);
 				break;
 			}
-			ed_p = &(((struct ed *)
+			ed_p = &(((struct ed *)(uintptr_t)
 				     m32_swap((unsigned long)ed_p))->hwNextED);
 		}
 	}
@@ -798,7 +798,7 @@ static int ep_unlink(ohci_t *ohci, ed_t *edi)
 		if (ohci->ed_controltail == ed) {
 			ohci->ed_controltail = ed->ed_prev;
 		} else {
-			((ed_t *)m32_swap(
+			((ed_t *)(uintptr_t)m32_swap(
 			    *((__u32 *)&ed->hwNextED)))->ed_prev = ed->ed_prev;
 		}
 		break;
@@ -819,7 +819,7 @@ static int ep_unlink(ohci_t *ohci, ed_t *edi)
 		if (ohci->ed_bulktail == ed) {
 			ohci->ed_bulktail = ed->ed_prev;
 		} else {
-			((ed_t *)m32_swap(
+			((ed_t *)(uintptr_t)m32_swap(
 			     *((__u32 *)&ed->hwNextED)))->ed_prev = ed->ed_prev;
 		}
 		break;
@@ -914,12 +914,13 @@ static void td_fill(ohci_t *ohci, unsigned int info,
 
 	/* fill the old dummy TD */
 	td = urb_priv->td [index] =
-			     (td_t *)(m32_swap(urb_priv->ed->hwTailP) & ~0xf);
+			     (td_t *)(uintptr_t)
+			     (m32_swap(urb_priv->ed->hwTailP) & ~0xf);
 
 	td->ed = urb_priv->ed;
 	td->next_dl_td = NULL;
 	td->index = index;
-	td->data = (__u32)data;
+	td->data = (uintptr_t)data;
 #ifdef OHCI_FILL_TRACE
 	if (usb_pipebulk(urb_priv->pipe) && usb_pipeout(urb_priv->pipe)) {
 		for (i = 0; i < len; i++)
@@ -1099,7 +1100,7 @@ static void check_status(td_t *td_list)
  * we reverse the reversed done-list */
 static td_t *dl_reverse_done_list(ohci_t *ohci)
 {
-	__u32 td_list_hc;
+	uintptr_t td_list_hc;
 	td_t *td_rev = NULL;
 	td_t *td_list = NULL;
 
@@ -1862,7 +1863,7 @@ static int hc_start(ohci_t *ohci)
 	ohci_writel(0, &ohci->regs->ed_controlhead);
 	ohci_writel(0, &ohci->regs->ed_bulkhead);
 
-	ohci_writel((__u32)ohci->hcca,
+	ohci_writel((uintptr_t)ohci->hcca,
 		    &ohci->regs->hcca); /* reset clears this */
 
 	fminterval = 0x2edf;
drivers/usb/host/ohci-sunxi.c +1 -1
index 2a1e8bf..0689374 100644
@@ -51,7 +51,7 @@ static int ohci_usb_probe(struct udevice *dev)
 	extra_ahb_gate_mask = 1 << AHB_GATE_OFFSET_USB_EHCI0;
 #endif
 	priv->usb_gate_mask = CCM_USB_CTRL_OHCI0_CLK;
-	priv->phy_index = ((u32)regs - (SUNXI_USB1_BASE + 0x400)) / BASE_DIST;
+	priv->phy_index = ((uintptr_t)regs - (SUNXI_USB1_BASE + 0x400)) / BASE_DIST;
 	priv->ahb_gate_mask <<= priv->phy_index * AHB_CLK_DIST;
 	extra_ahb_gate_mask <<= priv->phy_index * AHB_CLK_DIST;
 	priv->usb_gate_mask <<= priv->phy_index;
drivers/usb/host/ohci.h +7 -4
index 9b0c4a2..db0924c 100644
@@ -10,12 +10,15 @@
 /*
  * e.g. PCI controllers need this
  */
+
+#include <asm/io.h>
+
 #ifdef CONFIG_SYS_OHCI_SWAP_REG_ACCESS
-# define ohci_readl(a) __swap_32(*((volatile u32 *)(a)))
-# define ohci_writel(a, b) (*((volatile u32 *)(b)) = __swap_32((volatile u32)a))
+# define ohci_readl(a) __swap_32(readl(a))
+# define ohci_writel(v, a) writel(__swap_32(v), a)
 #else
-# define ohci_readl(a) (*((volatile u32 *)(a)))
-# define ohci_writel(a, b) (*((volatile u32 *)(b)) = ((volatile u32)a))
+# define ohci_readl(a) readl(a)
+# define ohci_writel(v, a) writel(v, a)
 #endif /* CONFIG_SYS_OHCI_SWAP_REG_ACCESS */
 
 #if ARCH_DMA_MINALIGN > 16
Signature · 1 line
2.8.2
#11 lore raw

PATCH 2/2 sunxi: A64: enable USB support

In reply to Andre Przywara

From: Amit Singh Tomar <[email protected]>

Mostly by adding MACH_SUN50I to some existing #ifdefs enable support for the the HCI0 USB host controller on the A64.
Fix up some minor 64-bit hiccups on the way.
Add the bare minimum DT bits to the A64 .dtsi and enable the controllers and the PHY on the Pine64.
This is limited to the first USB controller at the moment, which is connected to the lower USB socket on the Pine64 board. [Andre: remove unneeded defines, enable OHCI, add commit message]

---
 arch/arm/dts/sun50i-a64-pine64-common.dtsi  | 12 ++++++++++++
 arch/arm/dts/sun50i-a64.dtsi                | 29 +++++++++++++++++++++++++++++
 arch/arm/include/asm/arch-sunxi/cpu_sun4i.h |  2 +-
 arch/arm/mach-sunxi/usb_phy.c               |  5 +++--
 configs/pine64_plus_defconfig               |  1 +
 drivers/usb/host/ehci-sunxi.c               |  7 ++++---
 drivers/usb/host/ohci-sunxi.c               |  1 +
 include/configs/sun50i.h                    |  5 +++++
 8 files changed, 56 insertions(+), 6 deletions(-)
arch/arm/dts/sun50i-a64-pine64-common.dtsi +12 -0
index c0fde44..9ec81c6 100644
@@ -79,3 +79,15 @@
 	pinctrl-0 = <&i2c1_pins>;
 	status = "okay";
 };
+
+&usbphy {
+       status = "okay";
+};
+
+&ohci1 {
+       status = "okay";
+};
+
+&ehci1 {
+       status = "okay";
+};
arch/arm/dts/sun50i-a64.dtsi +29 -0
index 7d0dc76..bef0d00 100644
@@ -653,5 +653,34 @@
 			#address-cells = <1>;
 			#size-cells = <0>;
 		};
+
+		usbphy: phy at 1c1b810 {
+			compatible = "allwinner,sun50i-a64-usb-phy",
+				     "allwinner,sun8i-a33-usb-phy";
+			reg = <0x01c1b810 0x14>, <0x01c1b800 0x4>;
+			reg-names = "phy_ctrl", "pmu1";
+			status = "disabled";
+			#phy-cells = <1>;
+		};
+
+		ehci1: usb at 01c1b000 {
+			compatible = "allwinner,sun50i-a64-ehci",
+				     "generic-ehci";
+			reg = <0x01c1b000 0x100>;
+			interrupts = <GIC_SPI 74 IRQ_TYPE_LEVEL_HIGH>;
+			phys = <&usbphy 1>;
+			phy-names = "usb";
+			status = "disabled";
+		};
+
+		ohci1: usb at 01c1b400 {
+			compatible = "allwinner,sun50i-a64-ohci",
+				     "generic-ohci";
+			reg = <0x01c1b400 0x100>;
+			interrupts = <GIC_SPI 75 IRQ_TYPE_LEVEL_HIGH>;
+			phys = <&usbphy 1>;
+			phy-names = "usb";
+			status = "enabled";
+		};
 	};
 };
arch/arm/include/asm/arch-sunxi/cpu_sun4i.h +1 -1
index 5f93830..7232f6d 100644
@@ -56,7 +56,7 @@
 #define SUNXI_USB2_BASE			0x01c1c000
 #endif
 #ifdef CONFIG_SUNXI_GEN_SUN6I
-#ifdef CONFIG_MACH_SUN8I_H3
+#if defined(CONFIG_MACH_SUN8I_H3) || defined(CONFIG_MACH_SUN50I)
 #define SUNXI_USBPHY_BASE		0x01c19000
 #define SUNXI_USB0_BASE			0x01c1a000
 #define SUNXI_USB1_BASE			0x01c1b000
arch/arm/mach-sunxi/usb_phy.c +3 -2
index bd1bbee..278587b 100644
@@ -146,12 +146,13 @@ __maybe_unused static void usb_phy_write(struct sunxi_usb_phy *phy, int addr,
 	}
 }
 
-#if defined CONFIG_MACH_SUN8I_H3
+#if defined(CONFIG_MACH_SUN8I_H3) || defined(CONFIG_MACH_SUN50I)
 static void sunxi_usb_phy_config(struct sunxi_usb_phy *phy)
 {
+#if defined CONFIG_MACH_SUN8I_H3
 	if (phy->id == 0)
 		clrbits_le32(SUNXI_USBPHY_BASE + REG_PHY_UNK_H3, 0x01);
-
+#endif
 	clrbits_le32(phy->base + REG_PMU_UNK_H3, 0x02);
 }
 #elif defined CONFIG_MACH_SUN8I_A83T
configs/pine64_plus_defconfig +1 -0
index 6f82190..bd3e2e6 100644
@@ -10,3 +10,4 @@ CONFIG_DEFAULT_DEVICE_TREE="sun50i-a64-pine64-plus"
 # CONFIG_CMD_FLASH is not set
 # CONFIG_CMD_FPGA is not set
 CONFIG_SUN8I_EMAC=y
+CONFIG_USB_EHCI_HCD=y
drivers/usb/host/ehci-sunxi.c +4 -3
index f2d83e3..5bb97ff 100644
@@ -45,10 +45,10 @@ static int ehci_usb_probe(struct udevice *dev)
 	 * clocks resp. phys.
 	 */
 	priv->ahb_gate_mask = 1 << AHB_GATE_OFFSET_USB_EHCI0;
-#ifdef CONFIG_MACH_SUN8I_H3
+#if defined(CONFIG_MACH_SUN8I_H3) || defined(CONFIG_MACH_SUN50I)
 	extra_ahb_gate_mask = 1 << AHB_GATE_OFFSET_USB_OHCI0;
 #endif
-	priv->phy_index = ((u32)hccr - SUNXI_USB1_BASE) / BASE_DIST;
+	priv->phy_index = ((uintptr_t)hccr - SUNXI_USB1_BASE) / BASE_DIST;
 	priv->ahb_gate_mask <<= priv->phy_index * AHB_CLK_DIST;
 	extra_ahb_gate_mask <<= priv->phy_index * AHB_CLK_DIST;
 	priv->phy_index++; /* Non otg phys start at 1 */
@@ -63,7 +63,7 @@ static int ehci_usb_probe(struct udevice *dev)
 	sunxi_usb_phy_init(priv->phy_index);
 	sunxi_usb_phy_power_on(priv->phy_index);
 
-	hcor = (struct ehci_hcor *)((uint32_t)hccr +
+	hcor = (struct ehci_hcor *)((uintptr_t)hccr +
 				    HC_LENGTH(ehci_readl(&hccr->cr_capbase)));
 
 	return ehci_register(dev, hccr, hcor, NULL, 0, plat->init_type);
@@ -98,6 +98,7 @@ static const struct udevice_id ehci_usb_ids[] = {
 	{ .compatible = "allwinner,sun8i-a83t-ehci", },
 	{ .compatible = "allwinner,sun8i-h3-ehci",  },
 	{ .compatible = "allwinner,sun9i-a80-ehci", },
+	{ .compatible = "allwinner,sun50i-a64-ehci", },
 	{ }
 };
 
drivers/usb/host/ohci-sunxi.c +1 -0
index 0689374..0c45eec 100644
@@ -101,6 +101,7 @@ static const struct udevice_id ohci_usb_ids[] = {
 	{ .compatible = "allwinner,sun8i-a83t-ohci", },
 	{ .compatible = "allwinner,sun8i-h3-ohci",  },
 	{ .compatible = "allwinner,sun9i-a80-ohci", },
+	{ .compatible = "allwinner,sun50i-a64-ohci", },
 	{ }
 };
 
include/configs/sun50i.h +5 -0
index 0fdb4c7..3e5708b 100644
@@ -11,6 +11,11 @@
  * A64 specific configuration
  */
 
+#ifdef CONFIG_USB_EHCI
+#define CONFIG_USB_EHCI_SUNXI
+#define CONFIG_USB_MAX_CONTROLLER_COUNT 1
+#endif
+
 #define CONFIG_SUNXI_USB_PHYS	1
 
 #define COUNTER_FREQUENCY	CONFIG_TIMER_CLK_FREQ
Signature · 1 line
2.8.2
#12 lore raw

PATCH 2/2 sunxi: A64: enable USB support

Quoted 176 lines · Andre Przywara

From: Amit Singh Tomar <[email protected]>

Mostly by adding MACH_SUN50I to some existing #ifdefs enable support for the the HCI0 USB host controller on the A64.
Fix up some minor 64-bit hiccups on the way.
Add the bare minimum DT bits to the A64 .dtsi and enable the controllers and the PHY on the Pine64.
This is limited to the first USB controller at the moment, which is connected to the lower USB socket on the Pine64 board. [Andre: remove unneeded defines, enable OHCI, add commit message]

---
 arch/arm/dts/sun50i-a64-pine64-common.dtsi  | 12 ++++++++++++
 arch/arm/dts/sun50i-a64.dtsi                | 29 +++++++++++++++++++++++++++++
 arch/arm/include/asm/arch-sunxi/cpu_sun4i.h |  2 +-
 arch/arm/mach-sunxi/usb_phy.c               |  5 +++--
 configs/pine64_plus_defconfig               |  1 +
 drivers/usb/host/ehci-sunxi.c               |  7 ++++---
 drivers/usb/host/ohci-sunxi.c               |  1 +
 include/configs/sun50i.h                    |  5 +++++
 8 files changed, 56 insertions(+), 6 deletions(-)
arch/arm/dts/sun50i-a64-pine64-common.dtsi +12 -0
index c0fde44..9ec81c6 100644
@@ -79,3 +79,15 @@
        pinctrl-0 = <&i2c1_pins>;
        status = "okay";
 };
+
+&usbphy {
+       status = "okay";
+};
+
+&ohci1 {
+       status = "okay";
+};
+
+&ehci1 {
+       status = "okay";
+};
arch/arm/dts/sun50i-a64.dtsi +29 -0
index 7d0dc76..bef0d00 100644
@@ -653,5 +653,34 @@
                        #address-cells = <1>;
                        #size-cells = <0>;
                };
+
+               usbphy: phy at 1c1b810 {
+                       compatible = "allwinner,sun50i-a64-usb-phy",
+                                    "allwinner,sun8i-a33-usb-phy";
+                       reg = <0x01c1b810 0x14>, <0x01c1b800 0x4>;
+                       reg-names = "phy_ctrl", "pmu1";
+                       status = "disabled";
+                       #phy-cells = <1>;
+               };
+
+               ehci1: usb at 01c1b000 {
+                       compatible = "allwinner,sun50i-a64-ehci",
+                                    "generic-ehci";
+                       reg = <0x01c1b000 0x100>;
+                       interrupts = <GIC_SPI 74 IRQ_TYPE_LEVEL_HIGH>;
+                       phys = <&usbphy 1>;
+                       phy-names = "usb";
+                       status = "disabled";
+               };
+
+               ohci1: usb at 01c1b400 {
+                       compatible = "allwinner,sun50i-a64-ohci",
+                                    "generic-ohci";
+                       reg = <0x01c1b400 0x100>;
+                       interrupts = <GIC_SPI 75 IRQ_TYPE_LEVEL_HIGH>;
+                       phys = <&usbphy 1>;
+                       phy-names = "usb";
+                       status = "enabled";
+               };
        };
 };
arch/arm/include/asm/arch-sunxi/cpu_sun4i.h +1 -1
index 5f93830..7232f6d 100644
@@ -56,7 +56,7 @@
 #define SUNXI_USB2_BASE                        0x01c1c000
 #endif
 #ifdef CONFIG_SUNXI_GEN_SUN6I
-#ifdef CONFIG_MACH_SUN8I_H3
+#if defined(CONFIG_MACH_SUN8I_H3) || defined(CONFIG_MACH_SUN50I)
 #define SUNXI_USBPHY_BASE              0x01c19000
 #define SUNXI_USB0_BASE                        0x01c1a000
 #define SUNXI_USB1_BASE                        0x01c1b000
arch/arm/mach-sunxi/usb_phy.c +3 -2
index bd1bbee..278587b 100644
@@ -146,12 +146,13 @@ __maybe_unused static void usb_phy_write(struct sunxi_usb_phy *phy, int addr,
        }
 }
 
-#if defined CONFIG_MACH_SUN8I_H3
+#if defined(CONFIG_MACH_SUN8I_H3) || defined(CONFIG_MACH_SUN50I)
 static void sunxi_usb_phy_config(struct sunxi_usb_phy *phy)
 {
+#if defined CONFIG_MACH_SUN8I_H3
        if (phy->id == 0)
                clrbits_le32(SUNXI_USBPHY_BASE + REG_PHY_UNK_H3, 0x01);
-
+#endif
        clrbits_le32(phy->base + REG_PMU_UNK_H3, 0x02);
 }
 #elif defined CONFIG_MACH_SUN8I_A83T
configs/pine64_plus_defconfig +1 -0
index 6f82190..bd3e2e6 100644
@@ -10,3 +10,4 @@ CONFIG_DEFAULT_DEVICE_TREE="sun50i-a64-pine64-plus"
 # CONFIG_CMD_FLASH is not set
 # CONFIG_CMD_FPGA is not set
 CONFIG_SUN8I_EMAC=y
+CONFIG_USB_EHCI_HCD=y
drivers/usb/host/ehci-sunxi.c +4 -3
index f2d83e3..5bb97ff 100644
@@ -45,10 +45,10 @@ static int ehci_usb_probe(struct udevice *dev)
         * clocks resp. phys.
         */
        priv->ahb_gate_mask = 1 << AHB_GATE_OFFSET_USB_EHCI0;
-#ifdef CONFIG_MACH_SUN8I_H3
+#if defined(CONFIG_MACH_SUN8I_H3) || defined(CONFIG_MACH_SUN50I)
        extra_ahb_gate_mask = 1 << AHB_GATE_OFFSET_USB_OHCI0;
 #endif
-       priv->phy_index = ((u32)hccr - SUNXI_USB1_BASE) / BASE_DIST;
+       priv->phy_index = ((uintptr_t)hccr - SUNXI_USB1_BASE) / BASE_DIST;
        priv->ahb_gate_mask <<= priv->phy_index * AHB_CLK_DIST;
        extra_ahb_gate_mask <<= priv->phy_index * AHB_CLK_DIST;
        priv->phy_index++; /* Non otg phys start at 1 */
@@ -63,7 +63,7 @@ static int ehci_usb_probe(struct udevice *dev)
        sunxi_usb_phy_init(priv->phy_index);
        sunxi_usb_phy_power_on(priv->phy_index);
 
-       hcor = (struct ehci_hcor *)((uint32_t)hccr +
+       hcor = (struct ehci_hcor *)((uintptr_t)hccr +
                                    HC_LENGTH(ehci_readl(&hccr->cr_capbase)));
 
        return ehci_register(dev, hccr, hcor, NULL, 0, plat->init_type);
@@ -98,6 +98,7 @@ static const struct udevice_id ehci_usb_ids[] = {
        { .compatible = "allwinner,sun8i-a83t-ehci", },
        { .compatible = "allwinner,sun8i-h3-ehci",  },
        { .compatible = "allwinner,sun9i-a80-ehci", },
+       { .compatible = "allwinner,sun50i-a64-ehci", },
        { }
 };
 
drivers/usb/host/ohci-sunxi.c +1 -0
index 0689374..0c45eec 100644
@@ -101,6 +101,7 @@ static const struct udevice_id ohci_usb_ids[] = {
        { .compatible = "allwinner,sun8i-a83t-ohci", },
        { .compatible = "allwinner,sun8i-h3-ohci",  },
        { .compatible = "allwinner,sun9i-a80-ohci", },
+       { .compatible = "allwinner,sun50i-a64-ohci", },
        { }
 };
 
include/configs/sun50i.h +0 -0
index 0fdb4c7..3e5708b 100644

include/configs/sun50i.h line 16

Quoted 6 lines
include/configs/sun50i.h +3 -0
@@ -11,6 +11,11 @@
  * A64 specific configuration
  */
 
+#ifdef CONFIG_USB_EHCI
+#define CONFIG_USB_EHCI_SUNXI
+#define CONFIG_USB_MAX_CONTROLLER_COUNT 1

Since the driver is dm-driven this config not need.

thanks!a

Signature · 4 lines
Jagan Teki
Free Software Engineer | www.openedev.com
U-Boot, Linux | Upstream Maintainer
Hyderabad, India.
#2 lore raw

PATCH 1/2 drivers: USB: OHCI: allow compilation for 64-bit targets

In reply to Andre Przywara
Quoted 127 lines · Andre Przywara

OHCI has a known limitation of allowing only 32-bit DMA buffer addresses, so we have a lot of u32 variables around, which are assigned to pointers and vice versa. This obviously creates issues with 64-bit systems, so the compiler complains here and there.
To allow compilation for 64-bit boards which use only memory below 4GB anyway (and to avoid more invasive fixes), adjust some casts and types and assume that the EDs and TDs are all located in the lower 4GB. This fixes compilation of the OHCI driver for the Pine64.

---
 drivers/usb/host/ohci-hcd.c   | 21 +++++++++++----------
 drivers/usb/host/ohci-sunxi.c |  2 +-
 drivers/usb/host/ohci.h       | 11 +++++++----
 3 files changed, 19 insertions(+), 15 deletions(-)
drivers/usb/host/ohci-hcd.c +11 -10
index ccbfc02..0f6d03e 100644
@@ -682,7 +682,7 @@ static int ep_link(ohci_t *ohci, ed_t *edi)
                ed->hwNextED = 0;
                flush_dcache_ed(ed);
                if (ohci->ed_controltail == NULL)
-                       ohci_writel(ed, &ohci->regs->ed_controlhead);
+                       ohci_writel((uintptr_t)ed, &ohci->regs->ed_controlhead);
                else
                        ohci->ed_controltail->hwNextED =
                                                   m32_swap((unsigned long)ed);
@@ -700,7 +700,7 @@ static int ep_link(ohci_t *ohci, ed_t *edi)
                ed->hwNextED = 0;
                flush_dcache_ed(ed);
                if (ohci->ed_bulktail == NULL)
-                       ohci_writel(ed, &ohci->regs->ed_bulkhead);
+                       ohci_writel((uintptr_t)ed, &ohci->regs->ed_bulkhead);
                else
                        ohci->ed_bulktail->hwNextED =
                                                   m32_swap((unsigned long)ed);
@@ -753,7 +753,7 @@ static void periodic_unlink(struct ohci *ohci, volatile struct ed *ed,
 
                /* ED might have been unlinked through another path */
                while (*ed_p != 0) {
-                       if (((struct ed *)
+                       if (((struct ed *)(uintptr_t)
                                        m32_swap((unsigned long)ed_p)) == ed) {
                                *ed_p = ed->hwNextED;
                                aligned_ed_p = (unsigned long)ed_p;
@@ -762,7 +762,7 @@ static void periodic_unlink(struct ohci *ohci, volatile struct ed *ed,
                                        aligned_ed_p + ARCH_DMA_MINALIGN);
                                break;
                        }
-                       ed_p = &(((struct ed *)
+                       ed_p = &(((struct ed *)(uintptr_t)
                                     m32_swap((unsigned long)ed_p))->hwNextED);
                }
        }
@@ -798,7 +798,7 @@ static int ep_unlink(ohci_t *ohci, ed_t *edi)
                if (ohci->ed_controltail == ed) {
                        ohci->ed_controltail = ed->ed_prev;
                } else {
-                       ((ed_t *)m32_swap(
+                       ((ed_t *)(uintptr_t)m32_swap(
                            *((__u32 *)&ed->hwNextED)))->ed_prev = ed->ed_prev;
                }
                break;
@@ -819,7 +819,7 @@ static int ep_unlink(ohci_t *ohci, ed_t *edi)
                if (ohci->ed_bulktail == ed) {
                        ohci->ed_bulktail = ed->ed_prev;
                } else {
-                       ((ed_t *)m32_swap(
+                       ((ed_t *)(uintptr_t)m32_swap(
                             *((__u32 *)&ed->hwNextED)))->ed_prev = ed->ed_prev;
                }
                break;
@@ -914,12 +914,13 @@ static void td_fill(ohci_t *ohci, unsigned int info,
 
        /* fill the old dummy TD */
        td = urb_priv->td [index] =
-                            (td_t *)(m32_swap(urb_priv->ed->hwTailP) & ~0xf);
+                            (td_t *)(uintptr_t)
+                            (m32_swap(urb_priv->ed->hwTailP) & ~0xf);
 
        td->ed = urb_priv->ed;
        td->next_dl_td = NULL;
        td->index = index;
-       td->data = (__u32)data;
+       td->data = (uintptr_t)data;
 #ifdef OHCI_FILL_TRACE
        if (usb_pipebulk(urb_priv->pipe) && usb_pipeout(urb_priv->pipe)) {
                for (i = 0; i < len; i++)
@@ -1099,7 +1100,7 @@ static void check_status(td_t *td_list)
  * we reverse the reversed done-list */
 static td_t *dl_reverse_done_list(ohci_t *ohci)
 {
-       __u32 td_list_hc;
+       uintptr_t td_list_hc;
        td_t *td_rev = NULL;
        td_t *td_list = NULL;
 
@@ -1862,7 +1863,7 @@ static int hc_start(ohci_t *ohci)
        ohci_writel(0, &ohci->regs->ed_controlhead);
        ohci_writel(0, &ohci->regs->ed_bulkhead);
 
-       ohci_writel((__u32)ohci->hcca,
+       ohci_writel((uintptr_t)ohci->hcca,
                    &ohci->regs->hcca); /* reset clears this */
 
        fminterval = 0x2edf;
drivers/usb/host/ohci-sunxi.c +1 -1
index 2a1e8bf..0689374 100644
@@ -51,7 +51,7 @@ static int ohci_usb_probe(struct udevice *dev)
        extra_ahb_gate_mask = 1 << AHB_GATE_OFFSET_USB_EHCI0;
 #endif
        priv->usb_gate_mask = CCM_USB_CTRL_OHCI0_CLK;
-       priv->phy_index = ((u32)regs - (SUNXI_USB1_BASE + 0x400)) / BASE_DIST;
+       priv->phy_index = ((uintptr_t)regs - (SUNXI_USB1_BASE + 0x400)) / BASE_DIST;
        priv->ahb_gate_mask <<= priv->phy_index * AHB_CLK_DIST;
        extra_ahb_gate_mask <<= priv->phy_index * AHB_CLK_DIST;
        priv->usb_gate_mask <<= priv->phy_index;
drivers/usb/host/ohci.h +0 -0
index 9b0c4a2..db0924c 100644
@@ -10,12 +10,15 @@
 /*

drivers/usb/host/ohci.h line 18

Quoted 10 lines
drivers/usb/host/ohci.h +5 -2
  * e.g. PCI controllers need this
  */
+
+#include <asm/io.h>
+
 #ifdef CONFIG_SYS_OHCI_SWAP_REG_ACCESS
-# define ohci_readl(a) __swap_32(*((volatile u32 *)(a)))
-# define ohci_writel(a, b) (*((volatile u32 *)(b)) = __swap_32((volatile u32)a))
+# define ohci_readl(a) __swap_32(readl(a))
+# define ohci_writel(v, a) writel(__swap_32(v), a)

Not sure about writel here, why v? volatile casting to a here becomes v?

thanks!

Signature · 4 lines
Jagan Teki
Free Software Engineer | www.openedev.com
U-Boot, Linux | Upstream Maintainer
Hyderabad, India.
#3 lore raw

PATCH 1/2 drivers: USB: OHCI: allow compilation for 64-bit targets

On 22/10/16 18:10, Jagan Teki wrote:

Hi,

Quoted 132 lines · Andre Przywara
Quoted 131 lines

OHCI has a known limitation of allowing only 32-bit DMA buffer addresses, so we have a lot of u32 variables around, which are assigned to pointers and vice versa. This obviously creates issues with 64-bit systems, so the compiler complains here and there.
To allow compilation for 64-bit boards which use only memory below 4GB anyway (and to avoid more invasive fixes), adjust some casts and types and assume that the EDs and TDs are all located in the lower 4GB. This fixes compilation of the OHCI driver for the Pine64.

---
 drivers/usb/host/ohci-hcd.c   | 21 +++++++++++----------
 drivers/usb/host/ohci-sunxi.c |  2 +-
 drivers/usb/host/ohci.h       | 11 +++++++----
 3 files changed, 19 insertions(+), 15 deletions(-)
drivers/usb/host/ohci-hcd.c +11 -10
index ccbfc02..0f6d03e 100644
@@ -682,7 +682,7 @@ static int ep_link(ohci_t *ohci, ed_t *edi)
                ed->hwNextED = 0;
                flush_dcache_ed(ed);
                if (ohci->ed_controltail == NULL)
-                       ohci_writel(ed, &ohci->regs->ed_controlhead);
+                       ohci_writel((uintptr_t)ed, &ohci->regs->ed_controlhead);
                else
                        ohci->ed_controltail->hwNextED =
                                                   m32_swap((unsigned long)ed);
@@ -700,7 +700,7 @@ static int ep_link(ohci_t *ohci, ed_t *edi)
                ed->hwNextED = 0;
                flush_dcache_ed(ed);
                if (ohci->ed_bulktail == NULL)
-                       ohci_writel(ed, &ohci->regs->ed_bulkhead);
+                       ohci_writel((uintptr_t)ed, &ohci->regs->ed_bulkhead);
                else
                        ohci->ed_bulktail->hwNextED =
                                                   m32_swap((unsigned long)ed);
@@ -753,7 +753,7 @@ static void periodic_unlink(struct ohci *ohci, volatile struct ed *ed,
 
                /* ED might have been unlinked through another path */
                while (*ed_p != 0) {
-                       if (((struct ed *)
+                       if (((struct ed *)(uintptr_t)
                                        m32_swap((unsigned long)ed_p)) == ed) {
                                *ed_p = ed->hwNextED;
                                aligned_ed_p = (unsigned long)ed_p;
@@ -762,7 +762,7 @@ static void periodic_unlink(struct ohci *ohci, volatile struct ed *ed,
                                        aligned_ed_p + ARCH_DMA_MINALIGN);
                                break;
                        }
-                       ed_p = &(((struct ed *)
+                       ed_p = &(((struct ed *)(uintptr_t)
                                     m32_swap((unsigned long)ed_p))->hwNextED);
                }
        }
@@ -798,7 +798,7 @@ static int ep_unlink(ohci_t *ohci, ed_t *edi)
                if (ohci->ed_controltail == ed) {
                        ohci->ed_controltail = ed->ed_prev;
                } else {
-                       ((ed_t *)m32_swap(
+                       ((ed_t *)(uintptr_t)m32_swap(
                            *((__u32 *)&ed->hwNextED)))->ed_prev = ed->ed_prev;
                }
                break;
@@ -819,7 +819,7 @@ static int ep_unlink(ohci_t *ohci, ed_t *edi)
                if (ohci->ed_bulktail == ed) {
                        ohci->ed_bulktail = ed->ed_prev;
                } else {
-                       ((ed_t *)m32_swap(
+                       ((ed_t *)(uintptr_t)m32_swap(
                             *((__u32 *)&ed->hwNextED)))->ed_prev = ed->ed_prev;
                }
                break;
@@ -914,12 +914,13 @@ static void td_fill(ohci_t *ohci, unsigned int info,
 
        /* fill the old dummy TD */
        td = urb_priv->td [index] =
-                            (td_t *)(m32_swap(urb_priv->ed->hwTailP) & ~0xf);
+                            (td_t *)(uintptr_t)
+                            (m32_swap(urb_priv->ed->hwTailP) & ~0xf);
 
        td->ed = urb_priv->ed;
        td->next_dl_td = NULL;
        td->index = index;
-       td->data = (__u32)data;
+       td->data = (uintptr_t)data;
 #ifdef OHCI_FILL_TRACE
        if (usb_pipebulk(urb_priv->pipe) && usb_pipeout(urb_priv->pipe)) {
                for (i = 0; i < len; i++)
@@ -1099,7 +1100,7 @@ static void check_status(td_t *td_list)
  * we reverse the reversed done-list */
 static td_t *dl_reverse_done_list(ohci_t *ohci)
 {
-       __u32 td_list_hc;
+       uintptr_t td_list_hc;
        td_t *td_rev = NULL;
        td_t *td_list = NULL;
 
@@ -1862,7 +1863,7 @@ static int hc_start(ohci_t *ohci)
        ohci_writel(0, &ohci->regs->ed_controlhead);
        ohci_writel(0, &ohci->regs->ed_bulkhead);
 
-       ohci_writel((__u32)ohci->hcca,
+       ohci_writel((uintptr_t)ohci->hcca,
                    &ohci->regs->hcca); /* reset clears this */
 
        fminterval = 0x2edf;
drivers/usb/host/ohci-sunxi.c +1 -1
index 2a1e8bf..0689374 100644
@@ -51,7 +51,7 @@ static int ohci_usb_probe(struct udevice *dev)
        extra_ahb_gate_mask = 1 << AHB_GATE_OFFSET_USB_EHCI0;
 #endif
        priv->usb_gate_mask = CCM_USB_CTRL_OHCI0_CLK;
-       priv->phy_index = ((u32)regs - (SUNXI_USB1_BASE + 0x400)) / BASE_DIST;
+       priv->phy_index = ((uintptr_t)regs - (SUNXI_USB1_BASE + 0x400)) / BASE_DIST;
        priv->ahb_gate_mask <<= priv->phy_index * AHB_CLK_DIST;
        extra_ahb_gate_mask <<= priv->phy_index * AHB_CLK_DIST;
        priv->usb_gate_mask <<= priv->phy_index;
drivers/usb/host/ohci.h +2 -0
index 9b0c4a2..db0924c 100644
@@ -10,12 +10,15 @@
 /*
  * e.g. PCI controllers need this
  */
+
+#include <asm/io.h>
Quoted 8 lines

drivers/usb/host/ohci.h line 18

Quoted 6 lines
drivers/usb/host/ohci.h +3 -2
+
 #ifdef CONFIG_SYS_OHCI_SWAP_REG_ACCESS
-# define ohci_readl(a) __swap_32(*((volatile u32 *)(a)))
-# define ohci_writel(a, b) (*((volatile u32 *)(b)) = __swap_32((volatile u32)a))
+# define ohci_readl(a) __swap_32(readl(a))
+# define ohci_writel(v, a) writel(__swap_32(v), a)

Not sure about writel here, why v? volatile casting to a here becomes v?

I was getting really confused about a and b here, especially since b is the address and a the value, in contrast to ohci_readl, where a is the address.
So I thought I rather stick with the traditional writel() definitions, which use "v" for value and "a" or "c" for the address.

It shouldn't change anything in the callers, really, except from the (desired) behaviour of not warning anymore.

Cheers,
Andre.

#4 lore raw

PATCH 1/2 drivers: USB: OHCI: allow compilation for 64-bit targets

Quoted 145 lines · Andr? Przywara

On 22/10/16 18:10, Jagan Teki wrote:

Hi,

Quoted 132 lines · Andre Przywara
Quoted 131 lines

OHCI has a known limitation of allowing only 32-bit DMA buffer addresses, so we have a lot of u32 variables around, which are assigned to pointers and vice versa. This obviously creates issues with 64-bit systems, so the compiler complains here and there.
To allow compilation for 64-bit boards which use only memory below 4GB anyway (and to avoid more invasive fixes), adjust some casts and types and assume that the EDs and TDs are all located in the lower 4GB. This fixes compilation of the OHCI driver for the Pine64.

---
 drivers/usb/host/ohci-hcd.c   | 21 +++++++++++----------
 drivers/usb/host/ohci-sunxi.c |  2 +-
 drivers/usb/host/ohci.h       | 11 +++++++----
 3 files changed, 19 insertions(+), 15 deletions(-)
drivers/usb/host/ohci-hcd.c +11 -10
index ccbfc02..0f6d03e 100644
@@ -682,7 +682,7 @@ static int ep_link(ohci_t *ohci, ed_t *edi)
                ed->hwNextED = 0;
                flush_dcache_ed(ed);
                if (ohci->ed_controltail == NULL)
-                       ohci_writel(ed, &ohci->regs->ed_controlhead);
+                       ohci_writel((uintptr_t)ed, &ohci->regs->ed_controlhead);
                else
                        ohci->ed_controltail->hwNextED =
                                                   m32_swap((unsigned long)ed);
@@ -700,7 +700,7 @@ static int ep_link(ohci_t *ohci, ed_t *edi)
                ed->hwNextED = 0;
                flush_dcache_ed(ed);
                if (ohci->ed_bulktail == NULL)
-                       ohci_writel(ed, &ohci->regs->ed_bulkhead);
+                       ohci_writel((uintptr_t)ed, &ohci->regs->ed_bulkhead);
                else
                        ohci->ed_bulktail->hwNextED =
                                                   m32_swap((unsigned long)ed);
@@ -753,7 +753,7 @@ static void periodic_unlink(struct ohci *ohci, volatile struct ed *ed,
 
                /* ED might have been unlinked through another path */
                while (*ed_p != 0) {
-                       if (((struct ed *)
+                       if (((struct ed *)(uintptr_t)
                                        m32_swap((unsigned long)ed_p)) == ed) {
                                *ed_p = ed->hwNextED;
                                aligned_ed_p = (unsigned long)ed_p;
@@ -762,7 +762,7 @@ static void periodic_unlink(struct ohci *ohci, volatile struct ed *ed,
                                        aligned_ed_p + ARCH_DMA_MINALIGN);
                                break;
                        }
-                       ed_p = &(((struct ed *)
+                       ed_p = &(((struct ed *)(uintptr_t)
                                     m32_swap((unsigned long)ed_p))->hwNextED);
                }
        }
@@ -798,7 +798,7 @@ static int ep_unlink(ohci_t *ohci, ed_t *edi)
                if (ohci->ed_controltail == ed) {
                        ohci->ed_controltail = ed->ed_prev;
                } else {
-                       ((ed_t *)m32_swap(
+                       ((ed_t *)(uintptr_t)m32_swap(
                            *((__u32 *)&ed->hwNextED)))->ed_prev = ed->ed_prev;
                }
                break;
@@ -819,7 +819,7 @@ static int ep_unlink(ohci_t *ohci, ed_t *edi)
                if (ohci->ed_bulktail == ed) {
                        ohci->ed_bulktail = ed->ed_prev;
                } else {
-                       ((ed_t *)m32_swap(
+                       ((ed_t *)(uintptr_t)m32_swap(
                             *((__u32 *)&ed->hwNextED)))->ed_prev = ed->ed_prev;
                }
                break;
@@ -914,12 +914,13 @@ static void td_fill(ohci_t *ohci, unsigned int info,
 
        /* fill the old dummy TD */
        td = urb_priv->td [index] =
-                            (td_t *)(m32_swap(urb_priv->ed->hwTailP) & ~0xf);
+                            (td_t *)(uintptr_t)
+                            (m32_swap(urb_priv->ed->hwTailP) & ~0xf);
 
        td->ed = urb_priv->ed;
        td->next_dl_td = NULL;
        td->index = index;
-       td->data = (__u32)data;
+       td->data = (uintptr_t)data;
 #ifdef OHCI_FILL_TRACE
        if (usb_pipebulk(urb_priv->pipe) && usb_pipeout(urb_priv->pipe)) {
                for (i = 0; i < len; i++)
@@ -1099,7 +1100,7 @@ static void check_status(td_t *td_list)
  * we reverse the reversed done-list */
 static td_t *dl_reverse_done_list(ohci_t *ohci)
 {
-       __u32 td_list_hc;
+       uintptr_t td_list_hc;
        td_t *td_rev = NULL;
        td_t *td_list = NULL;
 
@@ -1862,7 +1863,7 @@ static int hc_start(ohci_t *ohci)
        ohci_writel(0, &ohci->regs->ed_controlhead);
        ohci_writel(0, &ohci->regs->ed_bulkhead);
 
-       ohci_writel((__u32)ohci->hcca,
+       ohci_writel((uintptr_t)ohci->hcca,
                    &ohci->regs->hcca); /* reset clears this */
 
        fminterval = 0x2edf;
drivers/usb/host/ohci-sunxi.c +1 -1
index 2a1e8bf..0689374 100644
@@ -51,7 +51,7 @@ static int ohci_usb_probe(struct udevice *dev)
        extra_ahb_gate_mask = 1 << AHB_GATE_OFFSET_USB_EHCI0;
 #endif
        priv->usb_gate_mask = CCM_USB_CTRL_OHCI0_CLK;
-       priv->phy_index = ((u32)regs - (SUNXI_USB1_BASE + 0x400)) / BASE_DIST;
+       priv->phy_index = ((uintptr_t)regs - (SUNXI_USB1_BASE + 0x400)) / BASE_DIST;
        priv->ahb_gate_mask <<= priv->phy_index * AHB_CLK_DIST;
        extra_ahb_gate_mask <<= priv->phy_index * AHB_CLK_DIST;
        priv->usb_gate_mask <<= priv->phy_index;
drivers/usb/host/ohci.h +2 -0
index 9b0c4a2..db0924c 100644
@@ -10,12 +10,15 @@
 /*
  * e.g. PCI controllers need this
  */
+
+#include <asm/io.h>
Quoted 8 lines

drivers/usb/host/ohci.h line 18

Quoted 6 lines
drivers/usb/host/ohci.h +3 -2
+
 #ifdef CONFIG_SYS_OHCI_SWAP_REG_ACCESS
-# define ohci_readl(a) __swap_32(*((volatile u32 *)(a)))
-# define ohci_writel(a, b) (*((volatile u32 *)(b)) = __swap_32((volatile u32)a))
+# define ohci_readl(a) __swap_32(readl(a))
+# define ohci_writel(v, a) writel(__swap_32(v), a)

Not sure about writel here, why v? volatile casting to a here becomes v?

Quoted 8 lines

I was getting really confused about a and b here, especially since b is the address and a the value, in contrast to ohci_readl, where a is the address.
So I thought I rather stick with the traditional writel() definitions, which use "v" for value and "a" or "c" for the address.

It shouldn't change anything in the callers, really, except from the (desired) behaviour of not warning anymore.

OK - Better to make this as a separate patch since this seems unrelated change.

thanks!

Signature · 4 lines
Jagan Teki
Free Software Engineer | www.openedev.com
U-Boot, Linux | Upstream Maintainer
Hyderabad, India.
#5 lore raw

PATCH 1/2 drivers: USB: OHCI: allow compilation for 64-bit targets

Quoted 137 lines · Jagan Teki
Quoted 136 lines · Andr? Przywara

On 22/10/16 18:10, Jagan Teki wrote:

Hi,

Quoted 132 lines · Andre Przywara
Quoted 131 lines

OHCI has a known limitation of allowing only 32-bit DMA buffer addresses, so we have a lot of u32 variables around, which are assigned to pointers and vice versa. This obviously creates issues with 64-bit systems, so the compiler complains here and there.
To allow compilation for 64-bit boards which use only memory below 4GB anyway (and to avoid more invasive fixes), adjust some casts and types and assume that the EDs and TDs are all located in the lower 4GB. This fixes compilation of the OHCI driver for the Pine64.

---
 drivers/usb/host/ohci-hcd.c   | 21 +++++++++++----------
 drivers/usb/host/ohci-sunxi.c |  2 +-
 drivers/usb/host/ohci.h       | 11 +++++++----
 3 files changed, 19 insertions(+), 15 deletions(-)
drivers/usb/host/ohci-hcd.c +11 -10
index ccbfc02..0f6d03e 100644
@@ -682,7 +682,7 @@ static int ep_link(ohci_t *ohci, ed_t *edi)
                ed->hwNextED = 0;
                flush_dcache_ed(ed);
                if (ohci->ed_controltail == NULL)
-                       ohci_writel(ed, &ohci->regs->ed_controlhead);
+                       ohci_writel((uintptr_t)ed, &ohci->regs->ed_controlhead);
                else
                        ohci->ed_controltail->hwNextED =
                                                   m32_swap((unsigned long)ed);
@@ -700,7 +700,7 @@ static int ep_link(ohci_t *ohci, ed_t *edi)
                ed->hwNextED = 0;
                flush_dcache_ed(ed);
                if (ohci->ed_bulktail == NULL)
-                       ohci_writel(ed, &ohci->regs->ed_bulkhead);
+                       ohci_writel((uintptr_t)ed, &ohci->regs->ed_bulkhead);
                else
                        ohci->ed_bulktail->hwNextED =
                                                   m32_swap((unsigned long)ed);
@@ -753,7 +753,7 @@ static void periodic_unlink(struct ohci *ohci, volatile struct ed *ed,
 
                /* ED might have been unlinked through another path */
                while (*ed_p != 0) {
-                       if (((struct ed *)
+                       if (((struct ed *)(uintptr_t)
                                        m32_swap((unsigned long)ed_p)) == ed) {
                                *ed_p = ed->hwNextED;
                                aligned_ed_p = (unsigned long)ed_p;
@@ -762,7 +762,7 @@ static void periodic_unlink(struct ohci *ohci, volatile struct ed *ed,
                                        aligned_ed_p + ARCH_DMA_MINALIGN);
                                break;
                        }
-                       ed_p = &(((struct ed *)
+                       ed_p = &(((struct ed *)(uintptr_t)
                                     m32_swap((unsigned long)ed_p))->hwNextED);
                }
        }
@@ -798,7 +798,7 @@ static int ep_unlink(ohci_t *ohci, ed_t *edi)
                if (ohci->ed_controltail == ed) {
                        ohci->ed_controltail = ed->ed_prev;
                } else {
-                       ((ed_t *)m32_swap(
+                       ((ed_t *)(uintptr_t)m32_swap(
                            *((__u32 *)&ed->hwNextED)))->ed_prev = ed->ed_prev;
                }
                break;
@@ -819,7 +819,7 @@ static int ep_unlink(ohci_t *ohci, ed_t *edi)
                if (ohci->ed_bulktail == ed) {
                        ohci->ed_bulktail = ed->ed_prev;
                } else {
-                       ((ed_t *)m32_swap(
+                       ((ed_t *)(uintptr_t)m32_swap(
                             *((__u32 *)&ed->hwNextED)))->ed_prev = ed->ed_prev;
                }
                break;
@@ -914,12 +914,13 @@ static void td_fill(ohci_t *ohci, unsigned int info,
 
        /* fill the old dummy TD */
        td = urb_priv->td [index] =
-                            (td_t *)(m32_swap(urb_priv->ed->hwTailP) & ~0xf);
+                            (td_t *)(uintptr_t)
+                            (m32_swap(urb_priv->ed->hwTailP) & ~0xf);
 
        td->ed = urb_priv->ed;
        td->next_dl_td = NULL;
        td->index = index;
-       td->data = (__u32)data;
+       td->data = (uintptr_t)data;
 #ifdef OHCI_FILL_TRACE
        if (usb_pipebulk(urb_priv->pipe) && usb_pipeout(urb_priv->pipe)) {
                for (i = 0; i < len; i++)
@@ -1099,7 +1100,7 @@ static void check_status(td_t *td_list)
  * we reverse the reversed done-list */
 static td_t *dl_reverse_done_list(ohci_t *ohci)
 {
-       __u32 td_list_hc;
+       uintptr_t td_list_hc;
        td_t *td_rev = NULL;
        td_t *td_list = NULL;
 
@@ -1862,7 +1863,7 @@ static int hc_start(ohci_t *ohci)
        ohci_writel(0, &ohci->regs->ed_controlhead);
        ohci_writel(0, &ohci->regs->ed_bulkhead);
 
-       ohci_writel((__u32)ohci->hcca,
+       ohci_writel((uintptr_t)ohci->hcca,
                    &ohci->regs->hcca); /* reset clears this */
 
        fminterval = 0x2edf;
drivers/usb/host/ohci-sunxi.c +1 -1
index 2a1e8bf..0689374 100644
@@ -51,7 +51,7 @@ static int ohci_usb_probe(struct udevice *dev)
        extra_ahb_gate_mask = 1 << AHB_GATE_OFFSET_USB_EHCI0;
 #endif
        priv->usb_gate_mask = CCM_USB_CTRL_OHCI0_CLK;
-       priv->phy_index = ((u32)regs - (SUNXI_USB1_BASE + 0x400)) / BASE_DIST;
+       priv->phy_index = ((uintptr_t)regs - (SUNXI_USB1_BASE + 0x400)) / BASE_DIST;
        priv->ahb_gate_mask <<= priv->phy_index * AHB_CLK_DIST;
        extra_ahb_gate_mask <<= priv->phy_index * AHB_CLK_DIST;
        priv->usb_gate_mask <<= priv->phy_index;
drivers/usb/host/ohci.h +2 -0
index 9b0c4a2..db0924c 100644
@@ -10,12 +10,15 @@
 /*
  * e.g. PCI controllers need this
  */
+
+#include <asm/io.h>
Quoted 8 lines
Quoted 8 lines
Quoted 8 lines

drivers/usb/host/ohci.h line 18

Quoted 6 lines
drivers/usb/host/ohci.h +3 -2
+
 #ifdef CONFIG_SYS_OHCI_SWAP_REG_ACCESS
-# define ohci_readl(a) __swap_32(*((volatile u32 *)(a)))
-# define ohci_writel(a, b) (*((volatile u32 *)(b)) = __swap_32((volatile u32)a))
+# define ohci_readl(a) __swap_32(readl(a))
+# define ohci_writel(v, a) writel(__swap_32(v), a)

Not sure about writel here, why v? volatile casting to a here becomes v?

Looking at this again I am not really sure what you mean. The definition of ohci_writel() was a bit "naive", assuming that just using a volatile cast fulfills all architectural requirements of a non-cachable, device MMIO write. On ARM we are loosing the barrier compared to writel(), for instance.
Since OHCI is used by many architectures, I think we should stick with the arch-native writel() semantics, and just add the swap on top.

Quoted 11 lines
Quoted 9 lines

I was getting really confused about a and b here, especially since b is the address and a the value, in contrast to ohci_readl, where a is the address.
So I thought I rather stick with the traditional writel() definitions, which use "v" for value and "a" or "c" for the address.

It shouldn't change anything in the callers, really, except from the (desired) behaviour of not warning anymore.

OK - Better to make this as a separate patch since this seems unrelated change.

TBH this was just a drive-by fix, so I'd rather drop this than posting another pointless fix. My hope was that by re-using writel() we could just fix this on the way. Please note that *this* bit does not change the behaviour at all, it just changes the parameter names in the macro definition.

Cheers,
Andre.

#13 lore raw

PATCH 2/2 sunxi: A64: enable USB support

In reply to Jagan Teki

Hello!

Quoted 2 lines

Since the driver is dm-driven this config not need.

I tried not to use this config but then driver don't get compiled.

You're talking about CONFIG_USB_EHCI and CONFIG_USB_EHCI_SUNXI, right ?

Thanks
Amit.

#14 lore raw

PATCH 2/2 sunxi: A64: enable USB support

Quoted 8 lines · Amit Tomer

Hello!

Quoted 2 lines

Since the driver is dm-driven this config not need.

I tried not to use this config but then driver don't get compiled.

You're talking about CONFIG_USB_EHCI and CONFIG_USB_EHCI_SUNXI, right ?

CONFIG_USB_MAX_CONTROLLER_COUNT, try to rebase u-boot.git/master. Will update the u-boot-sunxi soon

thanks!

Signature · 4 lines
Jagan Teki
Free Software Engineer | www.openedev.com
U-Boot, Linux | Upstream Maintainer
Hyderabad, India.
#6 lore raw

PATCH 1/2 drivers: USB: OHCI: allow compilation for 64-bit targets

In reply to André Przywara
Quoted 165 lines · Andr? Przywara
Quoted 137 lines · Jagan Teki
Quoted 136 lines · Andr? Przywara

On 22/10/16 18:10, Jagan Teki wrote:

Hi,

Quoted 132 lines · Andre Przywara
Quoted 131 lines

OHCI has a known limitation of allowing only 32-bit DMA buffer addresses, so we have a lot of u32 variables around, which are assigned to pointers and vice versa. This obviously creates issues with 64-bit systems, so the compiler complains here and there.
To allow compilation for 64-bit boards which use only memory below 4GB anyway (and to avoid more invasive fixes), adjust some casts and types and assume that the EDs and TDs are all located in the lower 4GB. This fixes compilation of the OHCI driver for the Pine64.

---
 drivers/usb/host/ohci-hcd.c   | 21 +++++++++++----------
 drivers/usb/host/ohci-sunxi.c |  2 +-
 drivers/usb/host/ohci.h       | 11 +++++++----
 3 files changed, 19 insertions(+), 15 deletions(-)
drivers/usb/host/ohci-hcd.c +11 -10
index ccbfc02..0f6d03e 100644
@@ -682,7 +682,7 @@ static int ep_link(ohci_t *ohci, ed_t *edi)
                ed->hwNextED = 0;
                flush_dcache_ed(ed);
                if (ohci->ed_controltail == NULL)
-                       ohci_writel(ed, &ohci->regs->ed_controlhead);
+                       ohci_writel((uintptr_t)ed, &ohci->regs->ed_controlhead);
                else
                        ohci->ed_controltail->hwNextED =
                                                   m32_swap((unsigned long)ed);
@@ -700,7 +700,7 @@ static int ep_link(ohci_t *ohci, ed_t *edi)
                ed->hwNextED = 0;
                flush_dcache_ed(ed);
                if (ohci->ed_bulktail == NULL)
-                       ohci_writel(ed, &ohci->regs->ed_bulkhead);
+                       ohci_writel((uintptr_t)ed, &ohci->regs->ed_bulkhead);
                else
                        ohci->ed_bulktail->hwNextED =
                                                   m32_swap((unsigned long)ed);
@@ -753,7 +753,7 @@ static void periodic_unlink(struct ohci *ohci, volatile struct ed *ed,
 
                /* ED might have been unlinked through another path */
                while (*ed_p != 0) {
-                       if (((struct ed *)
+                       if (((struct ed *)(uintptr_t)
                                        m32_swap((unsigned long)ed_p)) == ed) {
                                *ed_p = ed->hwNextED;
                                aligned_ed_p = (unsigned long)ed_p;
@@ -762,7 +762,7 @@ static void periodic_unlink(struct ohci *ohci, volatile struct ed *ed,
                                        aligned_ed_p + ARCH_DMA_MINALIGN);
                                break;
                        }
-                       ed_p = &(((struct ed *)
+                       ed_p = &(((struct ed *)(uintptr_t)
                                     m32_swap((unsigned long)ed_p))->hwNextED);
                }
        }
@@ -798,7 +798,7 @@ static int ep_unlink(ohci_t *ohci, ed_t *edi)
                if (ohci->ed_controltail == ed) {
                        ohci->ed_controltail = ed->ed_prev;
                } else {
-                       ((ed_t *)m32_swap(
+                       ((ed_t *)(uintptr_t)m32_swap(
                            *((__u32 *)&ed->hwNextED)))->ed_prev = ed->ed_prev;
                }
                break;
@@ -819,7 +819,7 @@ static int ep_unlink(ohci_t *ohci, ed_t *edi)
                if (ohci->ed_bulktail == ed) {
                        ohci->ed_bulktail = ed->ed_prev;
                } else {
-                       ((ed_t *)m32_swap(
+                       ((ed_t *)(uintptr_t)m32_swap(
                             *((__u32 *)&ed->hwNextED)))->ed_prev = ed->ed_prev;
                }
                break;
@@ -914,12 +914,13 @@ static void td_fill(ohci_t *ohci, unsigned int info,
 
        /* fill the old dummy TD */
        td = urb_priv->td [index] =
-                            (td_t *)(m32_swap(urb_priv->ed->hwTailP) & ~0xf);
+                            (td_t *)(uintptr_t)
+                            (m32_swap(urb_priv->ed->hwTailP) & ~0xf);
 
        td->ed = urb_priv->ed;
        td->next_dl_td = NULL;
        td->index = index;
-       td->data = (__u32)data;
+       td->data = (uintptr_t)data;
 #ifdef OHCI_FILL_TRACE
        if (usb_pipebulk(urb_priv->pipe) && usb_pipeout(urb_priv->pipe)) {
                for (i = 0; i < len; i++)
@@ -1099,7 +1100,7 @@ static void check_status(td_t *td_list)
  * we reverse the reversed done-list */
 static td_t *dl_reverse_done_list(ohci_t *ohci)
 {
-       __u32 td_list_hc;
+       uintptr_t td_list_hc;
        td_t *td_rev = NULL;
        td_t *td_list = NULL;
 
@@ -1862,7 +1863,7 @@ static int hc_start(ohci_t *ohci)
        ohci_writel(0, &ohci->regs->ed_controlhead);
        ohci_writel(0, &ohci->regs->ed_bulkhead);
 
-       ohci_writel((__u32)ohci->hcca,
+       ohci_writel((uintptr_t)ohci->hcca,
                    &ohci->regs->hcca); /* reset clears this */
 
        fminterval = 0x2edf;
drivers/usb/host/ohci-sunxi.c +1 -1
index 2a1e8bf..0689374 100644
@@ -51,7 +51,7 @@ static int ohci_usb_probe(struct udevice *dev)
        extra_ahb_gate_mask = 1 << AHB_GATE_OFFSET_USB_EHCI0;
 #endif
        priv->usb_gate_mask = CCM_USB_CTRL_OHCI0_CLK;
-       priv->phy_index = ((u32)regs - (SUNXI_USB1_BASE + 0x400)) / BASE_DIST;
+       priv->phy_index = ((uintptr_t)regs - (SUNXI_USB1_BASE + 0x400)) / BASE_DIST;
        priv->ahb_gate_mask <<= priv->phy_index * AHB_CLK_DIST;
        extra_ahb_gate_mask <<= priv->phy_index * AHB_CLK_DIST;
        priv->usb_gate_mask <<= priv->phy_index;
drivers/usb/host/ohci.h +2 -0
index 9b0c4a2..db0924c 100644
@@ -10,12 +10,15 @@
 /*
  * e.g. PCI controllers need this
  */
+
+#include <asm/io.h>
Quoted 8 lines
Quoted 8 lines
Quoted 8 lines

drivers/usb/host/ohci.h line 18

Quoted 6 lines
drivers/usb/host/ohci.h +3 -2
+
 #ifdef CONFIG_SYS_OHCI_SWAP_REG_ACCESS
-# define ohci_readl(a) __swap_32(*((volatile u32 *)(a)))
-# define ohci_writel(a, b) (*((volatile u32 *)(b)) = __swap_32((volatile u32)a))
+# define ohci_readl(a) __swap_32(readl(a))
+# define ohci_writel(v, a) writel(__swap_32(v), a)

Not sure about writel here, why v? volatile casting to a here becomes v?

Looking at this again I am not really sure what you mean. The definition of ohci_writel() was a bit "naive", assuming that just using a volatile cast fulfills all architectural requirements of a non-cachable, device MMIO write. On ARM we are loosing the barrier compared to writel(), for instance.
Since OHCI is used by many architectures, I think we should stick with the arch-native writel() semantics, and just add the swap on top.

Quoted 10 lines
Quoted 9 lines

I was getting really confused about a and b here, especially since b is the address and a the value, in contrast to ohci_readl, where a is the address.
So I thought I rather stick with the traditional writel() definitions, which use "v" for value and "a" or "c" for the address.

It shouldn't change anything in the callers, really, except from the (desired) behaviour of not warning anymore.

Quoted 7 lines
Quoted 1 line

OK - Better to make this as a separate patch since this seems unrelated change.

TBH this was just a drive-by fix, so I'd rather drop this than posting another pointless fix. My hope was that by re-using writel() we could just fix this on the way. Please note that *this* bit does not change the behaviour at all, it just changes the parameter names in the macro definition.

Though, it is a parameter change - this is not related to the current patch, are you agree? If so please update the commit message about this change so-that in long run we can get some history about this change.

thanks!

Signature · 4 lines
Jagan Teki
Free Software Engineer | www.openedev.com
U-Boot, Linux | Upstream Maintainer
Hyderabad, India.
#7 lore raw

PATCH 1/2 drivers: USB: OHCI: allow compilation for 64-bit targets

In reply to Andre Przywara

Hi,

Quoted 10 lines · Andre Przywara

OHCI has a known limitation of allowing only 32-bit DMA buffer addresses, so we have a lot of u32 variables around, which are assigned to pointers and vice versa. This obviously creates issues with 64-bit systems, so the compiler complains here and there.
To allow compilation for 64-bit boards which use only memory below 4GB anyway (and to avoid more invasive fixes), adjust some casts and types and assume that the EDs and TDs are all located in the lower 4GB. This fixes compilation of the OHCI driver for the Pine64.

Patch looks good to me:

Regards,

Hans

p.s.

About the ohci_writel macro changes also giving the macro parameters more sensible names, I believe it is fine to do this while at it and that this does not need to be split out.

Quoted 136 lines
---
 drivers/usb/host/ohci-hcd.c   | 21 +++++++++++----------
 drivers/usb/host/ohci-sunxi.c |  2 +-
 drivers/usb/host/ohci.h       | 11 +++++++----
 3 files changed, 19 insertions(+), 15 deletions(-)
drivers/usb/host/ohci-hcd.c +11 -10
index ccbfc02..0f6d03e 100644
@@ -682,7 +682,7 @@ static int ep_link(ohci_t *ohci, ed_t *edi)
 		ed->hwNextED = 0;
 		flush_dcache_ed(ed);
 		if (ohci->ed_controltail == NULL)
-			ohci_writel(ed, &ohci->regs->ed_controlhead);
+			ohci_writel((uintptr_t)ed, &ohci->regs->ed_controlhead);
 		else
 			ohci->ed_controltail->hwNextED =
 						   m32_swap((unsigned long)ed);
@@ -700,7 +700,7 @@ static int ep_link(ohci_t *ohci, ed_t *edi)
 		ed->hwNextED = 0;
 		flush_dcache_ed(ed);
 		if (ohci->ed_bulktail == NULL)
-			ohci_writel(ed, &ohci->regs->ed_bulkhead);
+			ohci_writel((uintptr_t)ed, &ohci->regs->ed_bulkhead);
 		else
 			ohci->ed_bulktail->hwNextED =
 						   m32_swap((unsigned long)ed);
@@ -753,7 +753,7 @@ static void periodic_unlink(struct ohci *ohci, volatile struct ed *ed,
 
 		/* ED might have been unlinked through another path */
 		while (*ed_p != 0) {
-			if (((struct ed *)
+			if (((struct ed *)(uintptr_t)
 					m32_swap((unsigned long)ed_p)) == ed) {
 				*ed_p = ed->hwNextED;
 				aligned_ed_p = (unsigned long)ed_p;
@@ -762,7 +762,7 @@ static void periodic_unlink(struct ohci *ohci, volatile struct ed *ed,
 					aligned_ed_p + ARCH_DMA_MINALIGN);
 				break;
 			}
-			ed_p = &(((struct ed *)
+			ed_p = &(((struct ed *)(uintptr_t)
 				     m32_swap((unsigned long)ed_p))->hwNextED);
 		}
 	}
@@ -798,7 +798,7 @@ static int ep_unlink(ohci_t *ohci, ed_t *edi)
 		if (ohci->ed_controltail == ed) {
 			ohci->ed_controltail = ed->ed_prev;
 		} else {
-			((ed_t *)m32_swap(
+			((ed_t *)(uintptr_t)m32_swap(
 			    *((__u32 *)&ed->hwNextED)))->ed_prev = ed->ed_prev;
 		}
 		break;
@@ -819,7 +819,7 @@ static int ep_unlink(ohci_t *ohci, ed_t *edi)
 		if (ohci->ed_bulktail == ed) {
 			ohci->ed_bulktail = ed->ed_prev;
 		} else {
-			((ed_t *)m32_swap(
+			((ed_t *)(uintptr_t)m32_swap(
 			     *((__u32 *)&ed->hwNextED)))->ed_prev = ed->ed_prev;
 		}
 		break;
@@ -914,12 +914,13 @@ static void td_fill(ohci_t *ohci, unsigned int info,
 
 	/* fill the old dummy TD */
 	td = urb_priv->td [index] =
-			     (td_t *)(m32_swap(urb_priv->ed->hwTailP) & ~0xf);
+			     (td_t *)(uintptr_t)
+			     (m32_swap(urb_priv->ed->hwTailP) & ~0xf);
 
 	td->ed = urb_priv->ed;
 	td->next_dl_td = NULL;
 	td->index = index;
-	td->data = (__u32)data;
+	td->data = (uintptr_t)data;
 #ifdef OHCI_FILL_TRACE
 	if (usb_pipebulk(urb_priv->pipe) && usb_pipeout(urb_priv->pipe)) {
 		for (i = 0; i < len; i++)
@@ -1099,7 +1100,7 @@ static void check_status(td_t *td_list)
  * we reverse the reversed done-list */
 static td_t *dl_reverse_done_list(ohci_t *ohci)
 {
-	__u32 td_list_hc;
+	uintptr_t td_list_hc;
 	td_t *td_rev = NULL;
 	td_t *td_list = NULL;
 
@@ -1862,7 +1863,7 @@ static int hc_start(ohci_t *ohci)
 	ohci_writel(0, &ohci->regs->ed_controlhead);
 	ohci_writel(0, &ohci->regs->ed_bulkhead);
 
-	ohci_writel((__u32)ohci->hcca,
+	ohci_writel((uintptr_t)ohci->hcca,
 		    &ohci->regs->hcca); /* reset clears this */
 
 	fminterval = 0x2edf;
drivers/usb/host/ohci-sunxi.c +1 -1
index 2a1e8bf..0689374 100644
@@ -51,7 +51,7 @@ static int ohci_usb_probe(struct udevice *dev)
 	extra_ahb_gate_mask = 1 << AHB_GATE_OFFSET_USB_EHCI0;
 #endif
 	priv->usb_gate_mask = CCM_USB_CTRL_OHCI0_CLK;
-	priv->phy_index = ((u32)regs - (SUNXI_USB1_BASE + 0x400)) / BASE_DIST;
+	priv->phy_index = ((uintptr_t)regs - (SUNXI_USB1_BASE + 0x400)) / BASE_DIST;
 	priv->ahb_gate_mask <<= priv->phy_index * AHB_CLK_DIST;
 	extra_ahb_gate_mask <<= priv->phy_index * AHB_CLK_DIST;
 	priv->usb_gate_mask <<= priv->phy_index;
drivers/usb/host/ohci.h +7 -4
index 9b0c4a2..db0924c 100644
@@ -10,12 +10,15 @@
 /*
  * e.g. PCI controllers need this
  */
+
+#include <asm/io.h>
+
 #ifdef CONFIG_SYS_OHCI_SWAP_REG_ACCESS
-# define ohci_readl(a) __swap_32(*((volatile u32 *)(a)))
-# define ohci_writel(a, b) (*((volatile u32 *)(b)) = __swap_32((volatile u32)a))
+# define ohci_readl(a) __swap_32(readl(a))
+# define ohci_writel(v, a) writel(__swap_32(v), a)
 #else
-# define ohci_readl(a) (*((volatile u32 *)(a)))
-# define ohci_writel(a, b) (*((volatile u32 *)(b)) = ((volatile u32)a))
+# define ohci_readl(a) readl(a)
+# define ohci_writel(v, a) writel(v, a)
 #endif /* CONFIG_SYS_OHCI_SWAP_REG_ACCESS */
 
 #if ARCH_DMA_MINALIGN > 16
#15 lore raw

PATCH 2/2 sunxi: A64: enable USB support

In reply to Andre Przywara

Hi,

Quoted 11 lines · Andre Przywara

From: Amit Singh Tomar <[email protected]>

Mostly by adding MACH_SUN50I to some existing #ifdefs enable support for the the HCI0 USB host controller on the A64.
Fix up some minor 64-bit hiccups on the way.
Add the bare minimum DT bits to the A64 .dtsi and enable the controllers and the PHY on the Pine64.
This is limited to the first USB controller at the moment, which is connected to the lower USB socket on the Pine64 board. [Andre: remove unneeded defines, enable OHCI, add commit message]

Quoted 2 lines

Other then CONFIG_USB_MAX_CONTROLLER_COUNT no longer being necessary (it should be dropped from include/configs/sun50i.h) this patch looks good to me and is:

Note I cannot merged it till Marek merges the first patch in the series, which really needs to go through the u-boot-usb tree.

Regards,

Hans

Quoted 175 lines
---
 arch/arm/dts/sun50i-a64-pine64-common.dtsi  | 12 ++++++++++++
 arch/arm/dts/sun50i-a64.dtsi                | 29 +++++++++++++++++++++++++++++
 arch/arm/include/asm/arch-sunxi/cpu_sun4i.h |  2 +-
 arch/arm/mach-sunxi/usb_phy.c               |  5 +++--
 configs/pine64_plus_defconfig               |  1 +
 drivers/usb/host/ehci-sunxi.c               |  7 ++++---
 drivers/usb/host/ohci-sunxi.c               |  1 +
 include/configs/sun50i.h                    |  5 +++++
 8 files changed, 56 insertions(+), 6 deletions(-)
arch/arm/dts/sun50i-a64-pine64-common.dtsi +12 -0
index c0fde44..9ec81c6 100644
@@ -79,3 +79,15 @@
 	pinctrl-0 = <&i2c1_pins>;
 	status = "okay";
 };
+
+&usbphy {
+       status = "okay";
+};
+
+&ohci1 {
+       status = "okay";
+};
+
+&ehci1 {
+       status = "okay";
+};
arch/arm/dts/sun50i-a64.dtsi +29 -0
index 7d0dc76..bef0d00 100644
@@ -653,5 +653,34 @@
 			#address-cells = <1>;
 			#size-cells = <0>;
 		};
+
+		usbphy: phy at 1c1b810 {
+			compatible = "allwinner,sun50i-a64-usb-phy",
+				     "allwinner,sun8i-a33-usb-phy";
+			reg = <0x01c1b810 0x14>, <0x01c1b800 0x4>;
+			reg-names = "phy_ctrl", "pmu1";
+			status = "disabled";
+			#phy-cells = <1>;
+		};
+
+		ehci1: usb at 01c1b000 {
+			compatible = "allwinner,sun50i-a64-ehci",
+				     "generic-ehci";
+			reg = <0x01c1b000 0x100>;
+			interrupts = <GIC_SPI 74 IRQ_TYPE_LEVEL_HIGH>;
+			phys = <&usbphy 1>;
+			phy-names = "usb";
+			status = "disabled";
+		};
+
+		ohci1: usb at 01c1b400 {
+			compatible = "allwinner,sun50i-a64-ohci",
+				     "generic-ohci";
+			reg = <0x01c1b400 0x100>;
+			interrupts = <GIC_SPI 75 IRQ_TYPE_LEVEL_HIGH>;
+			phys = <&usbphy 1>;
+			phy-names = "usb";
+			status = "enabled";
+		};
 	};
 };
arch/arm/include/asm/arch-sunxi/cpu_sun4i.h +1 -1
index 5f93830..7232f6d 100644
@@ -56,7 +56,7 @@
 #define SUNXI_USB2_BASE			0x01c1c000
 #endif
 #ifdef CONFIG_SUNXI_GEN_SUN6I
-#ifdef CONFIG_MACH_SUN8I_H3
+#if defined(CONFIG_MACH_SUN8I_H3) || defined(CONFIG_MACH_SUN50I)
 #define SUNXI_USBPHY_BASE		0x01c19000
 #define SUNXI_USB0_BASE			0x01c1a000
 #define SUNXI_USB1_BASE			0x01c1b000
arch/arm/mach-sunxi/usb_phy.c +3 -2
index bd1bbee..278587b 100644
@@ -146,12 +146,13 @@ __maybe_unused static void usb_phy_write(struct sunxi_usb_phy *phy, int addr,
 	}
 }
 
-#if defined CONFIG_MACH_SUN8I_H3
+#if defined(CONFIG_MACH_SUN8I_H3) || defined(CONFIG_MACH_SUN50I)
 static void sunxi_usb_phy_config(struct sunxi_usb_phy *phy)
 {
+#if defined CONFIG_MACH_SUN8I_H3
 	if (phy->id == 0)
 		clrbits_le32(SUNXI_USBPHY_BASE + REG_PHY_UNK_H3, 0x01);
-
+#endif
 	clrbits_le32(phy->base + REG_PMU_UNK_H3, 0x02);
 }
 #elif defined CONFIG_MACH_SUN8I_A83T
configs/pine64_plus_defconfig +1 -0
index 6f82190..bd3e2e6 100644
@@ -10,3 +10,4 @@ CONFIG_DEFAULT_DEVICE_TREE="sun50i-a64-pine64-plus"
 # CONFIG_CMD_FLASH is not set
 # CONFIG_CMD_FPGA is not set
 CONFIG_SUN8I_EMAC=y
+CONFIG_USB_EHCI_HCD=y
drivers/usb/host/ehci-sunxi.c +4 -3
index f2d83e3..5bb97ff 100644
@@ -45,10 +45,10 @@ static int ehci_usb_probe(struct udevice *dev)
 	 * clocks resp. phys.
 	 */
 	priv->ahb_gate_mask = 1 << AHB_GATE_OFFSET_USB_EHCI0;
-#ifdef CONFIG_MACH_SUN8I_H3
+#if defined(CONFIG_MACH_SUN8I_H3) || defined(CONFIG_MACH_SUN50I)
 	extra_ahb_gate_mask = 1 << AHB_GATE_OFFSET_USB_OHCI0;
 #endif
-	priv->phy_index = ((u32)hccr - SUNXI_USB1_BASE) / BASE_DIST;
+	priv->phy_index = ((uintptr_t)hccr - SUNXI_USB1_BASE) / BASE_DIST;
 	priv->ahb_gate_mask <<= priv->phy_index * AHB_CLK_DIST;
 	extra_ahb_gate_mask <<= priv->phy_index * AHB_CLK_DIST;
 	priv->phy_index++; /* Non otg phys start at 1 */
@@ -63,7 +63,7 @@ static int ehci_usb_probe(struct udevice *dev)
 	sunxi_usb_phy_init(priv->phy_index);
 	sunxi_usb_phy_power_on(priv->phy_index);
 
-	hcor = (struct ehci_hcor *)((uint32_t)hccr +
+	hcor = (struct ehci_hcor *)((uintptr_t)hccr +
 				    HC_LENGTH(ehci_readl(&hccr->cr_capbase)));
 
 	return ehci_register(dev, hccr, hcor, NULL, 0, plat->init_type);
@@ -98,6 +98,7 @@ static const struct udevice_id ehci_usb_ids[] = {
 	{ .compatible = "allwinner,sun8i-a83t-ehci", },
 	{ .compatible = "allwinner,sun8i-h3-ehci",  },
 	{ .compatible = "allwinner,sun9i-a80-ehci", },
+	{ .compatible = "allwinner,sun50i-a64-ehci", },
 	{ }
 };
 
drivers/usb/host/ohci-sunxi.c +1 -0
index 0689374..0c45eec 100644
@@ -101,6 +101,7 @@ static const struct udevice_id ohci_usb_ids[] = {
 	{ .compatible = "allwinner,sun8i-a83t-ohci", },
 	{ .compatible = "allwinner,sun8i-h3-ohci",  },
 	{ .compatible = "allwinner,sun9i-a80-ohci", },
+	{ .compatible = "allwinner,sun50i-a64-ohci", },
 	{ }
 };
 
include/configs/sun50i.h +5 -0
index 0fdb4c7..3e5708b 100644
@@ -11,6 +11,11 @@
  * A64 specific configuration
  */
 
+#ifdef CONFIG_USB_EHCI
+#define CONFIG_USB_EHCI_SUNXI
+#define CONFIG_USB_MAX_CONTROLLER_COUNT 1
+#endif
+
 #define CONFIG_SUNXI_USB_PHYS	1
 
 #define COUNTER_FREQUENCY	CONFIG_TIMER_CLK_FREQ
Applied
#8 lore raw

PATCH 1/2 drivers: USB: OHCI: allow compilation for 64-bit targets

In reply to Hans de Goede
Quoted 12 lines · Hans de Goede

Hi,

Quoted 9 lines · Andre Przywara

OHCI has a known limitation of allowing only 32-bit DMA buffer addresses, so we have a lot of u32 variables around, which are assigned to pointers and vice versa. This obviously creates issues with 64-bit systems, so the compiler complains here and there.
To allow compilation for 64-bit boards which use only memory below 4GB anyway (and to avoid more invasive fixes), adjust some casts and types and assume that the EDs and TDs are all located in the lower 4GB. This fixes compilation of the OHCI driver for the Pine64.

Quoted 5 lines
Quoted 1 line

Patch looks good to me:

Applied, thanks.

Andre, it would be nice if you CC'd me on the original submission.

Quoted 9 lines

Regards,

Hans

p.s.

About the ohci_writel macro changes also giving the macro parameters more sensible names, I believe it is fine to do this while at it and that this does not need to be split out.

Indeed, I am fine with it as well.

Signature · 2 lines
Best regards,
Marek Vasut
#9 lore raw

PATCH 1/2 drivers: USB: OHCI: allow compilation for 64-bit targets

Quoted 15 lines · Marek Vasut
Quoted 14 lines · Hans de Goede

Hi,

Quoted 10 lines · Andre Przywara

OHCI has a known limitation of allowing only 32-bit DMA buffer addresses, so we have a lot of u32 variables around, which are assigned to pointers and vice versa. This obviously creates issues with 64-bit systems, so the compiler complains here and there.
To allow compilation for 64-bit boards which use only memory below 4GB anyway (and to avoid more invasive fixes), adjust some casts and types and assume that the EDs and TDs are all located in the lower 4GB. This fixes compilation of the OHCI driver for the Pine64.

Quoted 7 lines
Quoted 3 lines

Patch looks good to me:

Applied, thanks.

Andre, it would be nice if you CC'd me on the original submission.

Yeah, sorry about that. I think I had you in To: on my --dry-run test, but somehow managed to drop you after fixing "just one more thing".

Thanks for applying this!

Cheers,
Andre.

Quoted 13 lines
Quoted 10 lines

Regards,

Hans

p.s.

About the ohci_writel macro changes also giving the macro parameters more sensible names, I believe it is fine to do this while at it and that this does not need to be split out.

Indeed, I am fine with it as well.

#16 lore raw

[U-Boot] [linux-sunxi] Re: [U-Boot, 2/2] sunxi: A64: enable USB support

In reply to Hans de Goede

Hi,

Quoted 17 lines · Hans de Goede

Hi,

Quoted 11 lines · Andre Przywara

From: Amit Singh Tomar <[email protected]>

Mostly by adding MACH_SUN50I to some existing #ifdefs enable support for the the HCI0 USB host controller on the A64.
Fix up some minor 64-bit hiccups on the way.
Add the bare minimum DT bits to the A64 .dtsi and enable the controllers and the PHY on the Pine64.
This is limited to the first USB controller at the moment, which is connected to the lower USB socket on the Pine64 board. [Andre: remove unneeded defines, enable OHCI, add commit message]

Quoted 2 lines
Quoted 8 lines

Other then CONFIG_USB_MAX_CONTROLLER_COUNT no longer being necessary (it should be dropped from include/configs/sun50i.h) this patch looks good to me and is:

Note I cannot merged it till Marek merges the first patch in the series, which really needs to go through the u-boot-usb tree.

Marek just send out a pull-req with this patch in there so I've added this patch to my tree and will include it in the pull-req I will send out later today.

Regards,

Hans

Quoted 176 lines
Quoted 175 lines
---
 arch/arm/dts/sun50i-a64-pine64-common.dtsi  | 12 ++++++++++++
 arch/arm/dts/sun50i-a64.dtsi                | 29 +++++++++++++++++++++++++++++
 arch/arm/include/asm/arch-sunxi/cpu_sun4i.h |  2 +-
 arch/arm/mach-sunxi/usb_phy.c               |  5 +++--
 configs/pine64_plus_defconfig               |  1 +
 drivers/usb/host/ehci-sunxi.c               |  7 ++++---
 drivers/usb/host/ohci-sunxi.c               |  1 +
 include/configs/sun50i.h                    |  5 +++++
 8 files changed, 56 insertions(+), 6 deletions(-)
arch/arm/dts/sun50i-a64-pine64-common.dtsi +12 -0
index c0fde44..9ec81c6 100644
@@ -79,3 +79,15 @@
     pinctrl-0 = <&i2c1_pins>;
     status = "okay";
 };
+
+&usbphy {
+       status = "okay";
+};
+
+&ohci1 {
+       status = "okay";
+};
+
+&ehci1 {
+       status = "okay";
+};
arch/arm/dts/sun50i-a64.dtsi +29 -0
index 7d0dc76..bef0d00 100644
@@ -653,5 +653,34 @@
             #address-cells = <1>;
             #size-cells = <0>;
         };
+
+        usbphy: phy at 1c1b810 {
+            compatible = "allwinner,sun50i-a64-usb-phy",
+                     "allwinner,sun8i-a33-usb-phy";
+            reg = <0x01c1b810 0x14>, <0x01c1b800 0x4>;
+            reg-names = "phy_ctrl", "pmu1";
+            status = "disabled";
+            #phy-cells = <1>;
+        };
+
+        ehci1: usb at 01c1b000 {
+            compatible = "allwinner,sun50i-a64-ehci",
+                     "generic-ehci";
+            reg = <0x01c1b000 0x100>;
+            interrupts = <GIC_SPI 74 IRQ_TYPE_LEVEL_HIGH>;
+            phys = <&usbphy 1>;
+            phy-names = "usb";
+            status = "disabled";
+        };
+
+        ohci1: usb at 01c1b400 {
+            compatible = "allwinner,sun50i-a64-ohci",
+                     "generic-ohci";
+            reg = <0x01c1b400 0x100>;
+            interrupts = <GIC_SPI 75 IRQ_TYPE_LEVEL_HIGH>;
+            phys = <&usbphy 1>;
+            phy-names = "usb";
+            status = "enabled";
+        };
     };
 };
arch/arm/include/asm/arch-sunxi/cpu_sun4i.h +1 -1
index 5f93830..7232f6d 100644
@@ -56,7 +56,7 @@
 #define SUNXI_USB2_BASE            0x01c1c000
 #endif
 #ifdef CONFIG_SUNXI_GEN_SUN6I
-#ifdef CONFIG_MACH_SUN8I_H3
+#if defined(CONFIG_MACH_SUN8I_H3) || defined(CONFIG_MACH_SUN50I)
 #define SUNXI_USBPHY_BASE        0x01c19000
 #define SUNXI_USB0_BASE            0x01c1a000
 #define SUNXI_USB1_BASE            0x01c1b000
arch/arm/mach-sunxi/usb_phy.c +3 -2
index bd1bbee..278587b 100644
@@ -146,12 +146,13 @@ __maybe_unused static void usb_phy_write(struct sunxi_usb_phy *phy, int addr,
     }
 }
 
-#if defined CONFIG_MACH_SUN8I_H3
+#if defined(CONFIG_MACH_SUN8I_H3) || defined(CONFIG_MACH_SUN50I)
 static void sunxi_usb_phy_config(struct sunxi_usb_phy *phy)
 {
+#if defined CONFIG_MACH_SUN8I_H3
     if (phy->id == 0)
         clrbits_le32(SUNXI_USBPHY_BASE + REG_PHY_UNK_H3, 0x01);
-
+#endif
     clrbits_le32(phy->base + REG_PMU_UNK_H3, 0x02);
 }
 #elif defined CONFIG_MACH_SUN8I_A83T
configs/pine64_plus_defconfig +1 -0
index 6f82190..bd3e2e6 100644
@@ -10,3 +10,4 @@ CONFIG_DEFAULT_DEVICE_TREE="sun50i-a64-pine64-plus"
 # CONFIG_CMD_FLASH is not set
 # CONFIG_CMD_FPGA is not set
 CONFIG_SUN8I_EMAC=y
+CONFIG_USB_EHCI_HCD=y
drivers/usb/host/ehci-sunxi.c +4 -3
index f2d83e3..5bb97ff 100644
@@ -45,10 +45,10 @@ static int ehci_usb_probe(struct udevice *dev)
      * clocks resp. phys.
      */
     priv->ahb_gate_mask = 1 << AHB_GATE_OFFSET_USB_EHCI0;
-#ifdef CONFIG_MACH_SUN8I_H3
+#if defined(CONFIG_MACH_SUN8I_H3) || defined(CONFIG_MACH_SUN50I)
     extra_ahb_gate_mask = 1 << AHB_GATE_OFFSET_USB_OHCI0;
 #endif
-    priv->phy_index = ((u32)hccr - SUNXI_USB1_BASE) / BASE_DIST;
+    priv->phy_index = ((uintptr_t)hccr - SUNXI_USB1_BASE) / BASE_DIST;
     priv->ahb_gate_mask <<= priv->phy_index * AHB_CLK_DIST;
     extra_ahb_gate_mask <<= priv->phy_index * AHB_CLK_DIST;
     priv->phy_index++; /* Non otg phys start at 1 */
@@ -63,7 +63,7 @@ static int ehci_usb_probe(struct udevice *dev)
     sunxi_usb_phy_init(priv->phy_index);
     sunxi_usb_phy_power_on(priv->phy_index);
 
-    hcor = (struct ehci_hcor *)((uint32_t)hccr +
+    hcor = (struct ehci_hcor *)((uintptr_t)hccr +
                     HC_LENGTH(ehci_readl(&hccr->cr_capbase)));
 
     return ehci_register(dev, hccr, hcor, NULL, 0, plat->init_type);
@@ -98,6 +98,7 @@ static const struct udevice_id ehci_usb_ids[] = {
     { .compatible = "allwinner,sun8i-a83t-ehci", },
     { .compatible = "allwinner,sun8i-h3-ehci",  },
     { .compatible = "allwinner,sun9i-a80-ehci", },
+    { .compatible = "allwinner,sun50i-a64-ehci", },
     { }
 };
 
drivers/usb/host/ohci-sunxi.c +1 -0
index 0689374..0c45eec 100644
@@ -101,6 +101,7 @@ static const struct udevice_id ohci_usb_ids[] = {
     { .compatible = "allwinner,sun8i-a83t-ohci", },
     { .compatible = "allwinner,sun8i-h3-ohci",  },
     { .compatible = "allwinner,sun9i-a80-ohci", },
+    { .compatible = "allwinner,sun50i-a64-ohci", },
     { }
 };
 
include/configs/sun50i.h +5 -0
index 0fdb4c7..3e5708b 100644
@@ -11,6 +11,11 @@
  * A64 specific configuration
  */
 
+#ifdef CONFIG_USB_EHCI
+#define CONFIG_USB_EHCI_SUNXI
+#define CONFIG_USB_MAX_CONTROLLER_COUNT 1
+#endif
+
 #define CONFIG_SUNXI_USB_PHYS    1
 
 #define COUNTER_FREQUENCY    CONFIG_TIMER_CLK_FREQ
#10 lore raw

PATCH 1/2 drivers: USB: OHCI: allow compilation for 64-bit targets

In reply to André Przywara
Quoted 20 lines · Andr? Przywara
Quoted 19 lines · Marek Vasut
Quoted 17 lines · Hans de Goede

Hi,

Quoted 10 lines · Andre Przywara

OHCI has a known limitation of allowing only 32-bit DMA buffer addresses, so we have a lot of u32 variables around, which are assigned to pointers and vice versa. This obviously creates issues with 64-bit systems, so the compiler complains here and there.
To allow compilation for 64-bit boards which use only memory below 4GB anyway (and to avoid more invasive fixes), adjust some casts and types and assume that the EDs and TDs are all located in the lower 4GB. This fixes compilation of the OHCI driver for the Pine64.

Patch looks good to me:

Quoted 8 lines
Quoted 3 lines

Applied, thanks.

Andre, it would be nice if you CC'd me on the original submission.

Yeah, sorry about that. I think I had you in To: on my --dry-run test, but somehow managed to drop you after fixing "just one more thing".

Thanks for applying this!

np, PR is out too.

Signature · 2 lines
Best regards,
Marek Vasut