Skip to contentSkip to conversation

x86: quark: Convert to driver model

PATCH New Bin Meng 2 participants 25 messages Sep 3, 2015 – Sep 11, 2015

Subsystems (3)
lore
Share & tools
lore

Bin Meng

author
#0 lore raw

v4 cover x86: quark: Convert to driver model

This series converts to use driver model for PCI/USB/ETH on Intel Galileo board, as well as optimizing the boot time.

Boot time performance degradation is observed with the conversion to use dm pci. Intel Quark SoC has a low end x86 processor with only 400MHz frequency and the most time consuming part is with MRC. Each MRC register programming requires indirect access via pci bus. With dm pci, accessing pci configuration space has some overhead. Unfortunately this single access overhead gets accumulated in the whole MRC process, and finally leads to twice boot time (25s) than before (12s).

To speed up the boot, create an optimized version of pci config read/write routines without bothering to go through driver model. Now it only takes about 3 seconds to finish MRC, which is really fast (8 times faster than dm pci, or 4 times faster than before).

The v2 series add complete PCIe root port and USB host support, which are the last 2 features on the Galileo board to enable.

Tested with a Mini-PCIe card (probe only) and a USB flash disk.

Simon, I reordered the patches so that the MRC optimizatin patch comes first. If you want to investigate driver model PCI overhead, you need to try the v1 patch series.

Changes in v4:
- Reorder via 'savedefconfig'
- Reorder via 'savedefconfig'

Changes in v3:
- Change to use dm_pci_read_config32()

Changes in v2:
- Drop v1 patch: "x86: quark: Make host bridge (b.d.f=0.0.0) visible", as pci_skip_dev() is not needed with the conversion to dm pci.
- Drop v1 patch: "dm: pci: Allow skipping device configuration", as full PCIe root port support has been added and there is no need to add such feature at this point. We can still add such capability to dm pci in the future whenever needed.
- Reorder to put patch "Optimize MRC execution time" as the first one in v2, as this patch addressed the slow boot time issue which exists before dm pci conversion, although it significantly improves more after dm pci conversion :-)
- Move qrk_pci_write_config_dword() and qrk_pci_read_config_dword() to arch/x86/cpu/quark/quark.c
- Rewrite this commit's message (ie: not mentioning dm pci conversion)
- New patch to avoid chicken and egg problem
- New patch to enable PCIe controller on quark/galileo
- Remove arch/x86/cpu/quark/pci.c completely
- New patch to add USB PHY initialization support
- Update commit message to remove "USB not working" statement, as in v2, full USB support has been added.
- New patch to add an inline API to test if a device is on a PCI bus
- Change to use device_is_on_pci_bus()
- New patch to add PCIe/USB static register programming after memory init

Bin Meng (11):
x86: quark: Optimize MRC execution time
x86: quark: Avoid chicken and egg problem
x86: Enable PCIe controller on quark/galileo
x86: Convert to use driver model pci on quark/galileo
x86: quark: Add USB PHY initialization support
x86: galileo: Convert to use CONFIG_DM_USB
net: designware: Fix build warnings
dm: pci: Add an inline API to test if a device is on a PCI bus
net: designware: Add support to PCI designware devices
x86: Convert to use driver model eth on quark/galileo
x86: quark: Add PCIe/USB static register programming after memory init

 arch/x86/cpu/quark/Makefile             |   1 -
 arch/x86/cpu/quark/msg_port.c           |  44 +++----
 arch/x86/cpu/quark/pci.c                |  70 -----------
 arch/x86/cpu/quark/quark.c              | 212 +++++++++++++++++++++++++++-----
 arch/x86/dts/galileo.dts                |   8 +-
 arch/x86/include/asm/arch-quark/quark.h | 107 ++++++++++++++++
 board/intel/galileo/galileo.c           |  56 +++++++++
 configs/galileo_defconfig               |   5 +-
 drivers/net/designware.c                |  46 ++++++-
 drivers/pci/pci-uclass.c                |   4 +-
 include/configs/galileo.h               |  13 +-
 include/pci.h                           |  15 +++
 12 files changed, 433 insertions(+), 148 deletions(-)
 delete mode 100644 arch/x86/cpu/quark/pci.c
Signature · 1 line
1.8.2.1
author
#1 lore raw

PATCH v4 1/11 x86: quark: Optimize MRC execution time

Intel Quark SoC has a low end x86 processor with only 400MHz frequency. Currently it takes about 15 seconds for U-Boot to boot to shell and the most time consuming part is with MRC, which is about 12 seconds. MRC programs lots of registers on the SoC internal message bus indirectly accessed via pci bus.

To speed up the boot, create an optimized version of pci config read/write dword routines which directly operate on PCI I/O ports. These two routines are inlined to provide better performance too. Now it only takes about 3 seconds to finish MRC, which is really fast (4 times faster than before).

---

Changes in v4: None
Changes in v3: None
Changes in v2:
- Drop v1 patch: "x86: quark: Make host bridge (b.d.f=0.0.0) visible", as pci_skip_dev() is not needed with the conversion to dm pci.
- Drop v1 patch: "dm: pci: Allow skipping device configuration", as full PCIe root port support has been added and there is no need to add such feature at this point. We can still add such capability to dm pci in the future whenever needed.
- Reorder to put patch "Optimize MRC execution time" as the first one in v2, as this patch addressed the slow boot time issue which exists before dm pci conversion, although it significantly improves more after dm pci conversion :-)
- Move qrk_pci_write_config_dword() and qrk_pci_read_config_dword() to arch/x86/cpu/quark/quark.c
- Rewrite this commit's message (ie: not mentioning dm pci conversion)

 arch/x86/cpu/quark/msg_port.c           | 44 ++++++++++++++++-----------------
 arch/x86/include/asm/arch-quark/quark.h | 35 ++++++++++++++++++++++++++
 2 files changed, 57 insertions(+), 22 deletions(-)
arch/x86/cpu/quark/msg_port.c +22 -22
index 31713e3..cf828f2 100644
@@ -5,34 +5,34 @@
  */
 
 #include <common.h>
-#include <pci.h>
 #include <asm/arch/device.h>
 #include <asm/arch/msg_port.h>
+#include <asm/arch/quark.h>
 
 void msg_port_setup(int op, int port, int reg)
 {
-	pci_write_config_dword(QUARK_HOST_BRIDGE, MSG_CTRL_REG,
-			       (((op) << 24) | ((port) << 16) |
-			       (((reg) << 8) & 0xff00) | MSG_BYTE_ENABLE));
+	qrk_pci_write_config_dword(QUARK_HOST_BRIDGE, MSG_CTRL_REG,
+				   (((op) << 24) | ((port) << 16) |
+				   (((reg) << 8) & 0xff00) | MSG_BYTE_ENABLE));
 }
 
 u32 msg_port_read(u8 port, u32 reg)
 {
 	u32 value;
 
-	pci_write_config_dword(QUARK_HOST_BRIDGE, MSG_CTRL_EXT_REG,
-			       reg & 0xffffff00);
+	qrk_pci_write_config_dword(QUARK_HOST_BRIDGE, MSG_CTRL_EXT_REG,
+				   reg & 0xffffff00);
 	msg_port_setup(MSG_OP_READ, port, reg);
-	pci_read_config_dword(QUARK_HOST_BRIDGE, MSG_DATA_REG, &value);
+	qrk_pci_read_config_dword(QUARK_HOST_BRIDGE, MSG_DATA_REG, &value);
 
 	return value;
 }
 
 void msg_port_write(u8 port, u32 reg, u32 value)
 {
-	pci_write_config_dword(QUARK_HOST_BRIDGE, MSG_DATA_REG, value);
-	pci_write_config_dword(QUARK_HOST_BRIDGE, MSG_CTRL_EXT_REG,
-			       reg & 0xffffff00);
+	qrk_pci_write_config_dword(QUARK_HOST_BRIDGE, MSG_DATA_REG, value);
+	qrk_pci_write_config_dword(QUARK_HOST_BRIDGE, MSG_CTRL_EXT_REG,
+				   reg & 0xffffff00);
 	msg_port_setup(MSG_OP_WRITE, port, reg);
 }
 
@@ -40,19 +40,19 @@ u32 msg_port_alt_read(u8 port, u32 reg)
 {
 	u32 value;
 
-	pci_write_config_dword(QUARK_HOST_BRIDGE, MSG_CTRL_EXT_REG,
-			       reg & 0xffffff00);
+	qrk_pci_write_config_dword(QUARK_HOST_BRIDGE, MSG_CTRL_EXT_REG,
+				   reg & 0xffffff00);
 	msg_port_setup(MSG_OP_ALT_READ, port, reg);
-	pci_read_config_dword(QUARK_HOST_BRIDGE, MSG_DATA_REG, &value);
+	qrk_pci_read_config_dword(QUARK_HOST_BRIDGE, MSG_DATA_REG, &value);
 
 	return value;
 }
 
 void msg_port_alt_write(u8 port, u32 reg, u32 value)
 {
-	pci_write_config_dword(QUARK_HOST_BRIDGE, MSG_DATA_REG, value);
-	pci_write_config_dword(QUARK_HOST_BRIDGE, MSG_CTRL_EXT_REG,
-			       reg & 0xffffff00);
+	qrk_pci_write_config_dword(QUARK_HOST_BRIDGE, MSG_DATA_REG, value);
+	qrk_pci_write_config_dword(QUARK_HOST_BRIDGE, MSG_CTRL_EXT_REG,
+				   reg & 0xffffff00);
 	msg_port_setup(MSG_OP_ALT_WRITE, port, reg);
 }
 
@@ -60,18 +60,18 @@ u32 msg_port_io_read(u8 port, u32 reg)
 {
 	u32 value;
 
-	pci_write_config_dword(QUARK_HOST_BRIDGE, MSG_CTRL_EXT_REG,
-			       reg & 0xffffff00);
+	qrk_pci_write_config_dword(QUARK_HOST_BRIDGE, MSG_CTRL_EXT_REG,
+				   reg & 0xffffff00);
 	msg_port_setup(MSG_OP_IO_READ, port, reg);
-	pci_read_config_dword(QUARK_HOST_BRIDGE, MSG_DATA_REG, &value);
+	qrk_pci_read_config_dword(QUARK_HOST_BRIDGE, MSG_DATA_REG, &value);
 
 	return value;
 }
 
 void msg_port_io_write(u8 port, u32 reg, u32 value)
 {
-	pci_write_config_dword(QUARK_HOST_BRIDGE, MSG_DATA_REG, value);
-	pci_write_config_dword(QUARK_HOST_BRIDGE, MSG_CTRL_EXT_REG,
-			       reg & 0xffffff00);
+	qrk_pci_write_config_dword(QUARK_HOST_BRIDGE, MSG_DATA_REG, value);
+	qrk_pci_write_config_dword(QUARK_HOST_BRIDGE, MSG_CTRL_EXT_REG,
+				   reg & 0xffffff00);
 	msg_port_setup(MSG_OP_IO_WRITE, port, reg);
 }
arch/x86/include/asm/arch-quark/quark.h +35 -0
index c997928..1ce5693 100644
@@ -89,6 +89,41 @@ struct quark_rcba {
 	u16	d20d21_ir;
 };
 
+#include <asm/io.h>
+#include <asm/pci.h>
+
+/**
+ * qrk_pci_read_config_dword() - Read a configuration value
+ *
+ * @dev:	PCI device address: bus, device and function
+ * @offset:	Dword offset within the device's configuration space
+ * @valuep:	Place to put the returned value
+ *
+ * Note: This routine is inlined to provide better performance on Quark
+ */
+static inline void qrk_pci_read_config_dword(pci_dev_t dev, int offset,
+					     u32 *valuep)
+{
+	outl(dev | offset | PCI_CFG_EN, PCI_REG_ADDR);
+	*valuep = inl(PCI_REG_DATA);
+}
+
+/**
+ * qrk_pci_write_config_dword() - Write a PCI configuration value
+ *
+ * @dev:	PCI device address: bus, device and function
+ * @offset:	Dword offset within the device's configuration space
+ * @value:	Value to write
+ *
+ * Note: This routine is inlined to provide better performance on Quark
+ */
+static inline void qrk_pci_write_config_dword(pci_dev_t dev, int offset,
+					      u32 value)
+{
+	outl(dev | offset | PCI_CFG_EN, PCI_REG_ADDR);
+	outl(value, PCI_REG_DATA);
+}
+
 #endif /* __ASSEMBLY__ */
 
 #endif /* _QUARK_H_ */
Signature · 1 line
1.8.2.1
#2 lore raw

PATCH v4 1/11 x86: quark: Optimize MRC execution time

Quoted 34 lines · Bin Meng

Intel Quark SoC has a low end x86 processor with only 400MHz frequency. Currently it takes about 15 seconds for U-Boot to boot to shell and the most time consuming part is with MRC, which is about 12 seconds. MRC programs lots of registers on the SoC internal message bus indirectly accessed via pci bus.

To speed up the boot, create an optimized version of pci config read/write dword routines which directly operate on PCI I/O ports. These two routines are inlined to provide better performance too. Now it only takes about 3 seconds to finish MRC, which is really fast (4 times faster than before).

---

Changes in v4: None
Changes in v3: None
Changes in v2:
- Drop v1 patch: "x86: quark: Make host bridge (b.d.f=0.0.0) visible", as pci_skip_dev() is not needed with the conversion to dm pci.
- Drop v1 patch: "dm: pci: Allow skipping device configuration", as full PCIe root port support has been added and there is no need to add such feature at this point. We can still add such capability to dm pci in the future whenever needed.
- Reorder to put patch "Optimize MRC execution time" as the first one in v2, as this patch addressed the slow boot time issue which exists before dm pci conversion, although it significantly improves more after dm pci conversion :-)
- Move qrk_pci_write_config_dword() and qrk_pci_read_config_dword() to arch/x86/cpu/quark/quark.c
- Rewrite this commit's message (ie: not mentioning dm pci conversion)

Quoted 3 lines
 arch/x86/cpu/quark/msg_port.c           | 44 ++++++++++++++++-----------------
 arch/x86/include/asm/arch-quark/quark.h | 35 ++++++++++++++++++++++++++
 2 files changed, 57 insertions(+), 22 deletions(-)

Applied to u-boot-x86, thanks!

author
#3 lore raw

PATCH v4 2/11 x86: quark: Avoid chicken and egg problem

In reply to Bin Meng

If we convert to use driver model pci on quark, we will encounter some chicken and egg problems like below:

- To enable PCIe root ports, we need program some registers on the message bus via pci bus. With driver model, the first time to access pci bus, the pci enumeration process will be triggered. But without first enabling PCIe root ports, pci enumeration just hangs when scanning PCIe root ports.
- Similar situation happens when trying to access GPIO from the PCIe enabling codes, as GPIO requires its block base address to be assigned via a pci configuration register in the bridge.

To avoid such dilemma, replace all pci calls in the quark codes to use the local version which does not go through driver model.

---

Changes in v4: None
Changes in v3: None
Changes in v2:
- New patch to avoid chicken and egg problem

 arch/x86/cpu/quark/quark.c | 30 +++++++++++++++---------------
 1 file changed, 15 insertions(+), 15 deletions(-)
arch/x86/cpu/quark/quark.c +15 -15
index 12ac376..2688a70 100644
@@ -31,32 +31,32 @@ static void unprotect_spi_flash(void)
 {
 	u32 bc;
 
-	bc = x86_pci_read_config32(QUARK_LEGACY_BRIDGE, 0xd8);
+	qrk_pci_read_config_dword(QUARK_LEGACY_BRIDGE, 0xd8, &bc);
 	bc |= 0x1;	/* unprotect the flash */
-	x86_pci_write_config32(QUARK_LEGACY_BRIDGE, 0xd8, bc);
+	qrk_pci_write_config_dword(QUARK_LEGACY_BRIDGE, 0xd8, bc);
 }
 
 static void quark_setup_bars(void)
 {
 	/* GPIO - D31:F0:R44h */
-	pci_write_config_dword(QUARK_LEGACY_BRIDGE, LB_GBA,
-			       CONFIG_GPIO_BASE | IO_BAR_EN);
+	qrk_pci_write_config_dword(QUARK_LEGACY_BRIDGE, LB_GBA,
+				   CONFIG_GPIO_BASE | IO_BAR_EN);
 
 	/* ACPI PM1 Block - D31:F0:R48h */
-	pci_write_config_dword(QUARK_LEGACY_BRIDGE, LB_PM1BLK,
-			       CONFIG_ACPI_PM1_BASE | IO_BAR_EN);
+	qrk_pci_write_config_dword(QUARK_LEGACY_BRIDGE, LB_PM1BLK,
+				   CONFIG_ACPI_PM1_BASE | IO_BAR_EN);
 
 	/* GPE0 - D31:F0:R4Ch */
-	pci_write_config_dword(QUARK_LEGACY_BRIDGE, LB_GPE0BLK,
-			       CONFIG_ACPI_GPE0_BASE | IO_BAR_EN);
+	qrk_pci_write_config_dword(QUARK_LEGACY_BRIDGE, LB_GPE0BLK,
+				   CONFIG_ACPI_GPE0_BASE | IO_BAR_EN);
 
 	/* WDT - D31:F0:R84h */
-	pci_write_config_dword(QUARK_LEGACY_BRIDGE, LB_WDTBA,
-			       CONFIG_WDT_BASE | IO_BAR_EN);
+	qrk_pci_write_config_dword(QUARK_LEGACY_BRIDGE, LB_WDTBA,
+				   CONFIG_WDT_BASE | IO_BAR_EN);
 
 	/* RCBA - D31:F0:RF0h */
-	pci_write_config_dword(QUARK_LEGACY_BRIDGE, LB_RCBA,
-			       CONFIG_RCBA_BASE | MEM_BAR_EN);
+	qrk_pci_write_config_dword(QUARK_LEGACY_BRIDGE, LB_RCBA,
+				   CONFIG_RCBA_BASE | MEM_BAR_EN);
 
 	/* ACPI P Block - Msg Port 04:R70h */
 	msg_port_write(MSG_PORT_RMU, PBLK_BA,
@@ -137,10 +137,10 @@ int cpu_eth_init(bd_t *bis)
 	u32 base;
 	int ret0, ret1;
 
-	pci_read_config_dword(QUARK_EMAC0, PCI_BASE_ADDRESS_0, &base);
+	qrk_pci_read_config_dword(QUARK_EMAC0, PCI_BASE_ADDRESS_0, &base);
 	ret0 = designware_initialize(base, PHY_INTERFACE_MODE_RMII);
 
-	pci_read_config_dword(QUARK_EMAC1, PCI_BASE_ADDRESS_0, &base);
+	qrk_pci_read_config_dword(QUARK_EMAC1, PCI_BASE_ADDRESS_0, &base);
 	ret1 = designware_initialize(base, PHY_INTERFACE_MODE_RMII);
 
 	if (ret0 < 0 && ret1 < 0)
@@ -154,7 +154,7 @@ void cpu_irq_init(void)
 	struct quark_rcba *rcba;
 	u32 base;
 
-	base = x86_pci_read_config32(QUARK_LEGACY_BRIDGE, LB_RCBA);
+	qrk_pci_read_config_dword(QUARK_LEGACY_BRIDGE, LB_RCBA, &base);
 	base &= ~MEM_BAR_EN;
 	rcba = (struct quark_rcba *)base;
 
Signature · 1 line
1.8.2.1
#4 lore raw

PATCH v4 2/11 x86: quark: Avoid chicken and egg problem

Quoted 20 lines · Bin Meng

If we convert to use driver model pci on quark, we will encounter some chicken and egg problems like below:

- To enable PCIe root ports, we need program some registers on the message bus via pci bus. With driver model, the first time to access pci bus, the pci enumeration process will be triggered. But without first enabling PCIe root ports, pci enumeration just hangs when scanning PCIe root ports.
- Similar situation happens when trying to access GPIO from the PCIe enabling codes, as GPIO requires its block base address to be assigned via a pci configuration register in the bridge.

To avoid such dilemma, replace all pci calls in the quark codes to use the local version which does not go through driver model.

---

Quoted 7 lines

Changes in v4: None
Changes in v3: None
Changes in v2:
- New patch to avoid chicken and egg problem

 arch/x86/cpu/quark/quark.c | 30 +++++++++++++++---------------
 1 file changed, 15 insertions(+), 15 deletions(-)

Applied to u-boot-x86, thanks!

author
#5 lore raw

PATCH v4 3/11 x86: Enable PCIe controller on quark/galileo

In reply to Bin Meng

Quark SoC holds the PCIe controller in reset following a power on. U-Boot needs to release the PCIe controller from reset. The PCIe controller (D23:F0/F1) will not be visible in PCI configuration space and any access to its PCI configuration registers will cause system hang while it is held in reset.

Enable PCIe controller per Quark firmware writer guide.

---

Changes in v4: None
Changes in v3: None
Changes in v2:
- New patch to enable PCIe controller on quark/galileo

 arch/x86/cpu/quark/quark.c              | 63 +++++++++++++++++++++++++++++++++
 arch/x86/include/asm/arch-quark/quark.h | 42 ++++++++++++++++++++++
 board/intel/galileo/galileo.c           | 56 +++++++++++++++++++++++++++++
 3 files changed, 161 insertions(+)
arch/x86/cpu/quark/quark.c +63 -0
index 2688a70..7c55d9e 100644
@@ -73,6 +73,58 @@ static void quark_setup_bars(void)
 		       CONFIG_PCIE_ECAM_BASE | MEM_BAR_EN);
 }
 
+static void quark_pcie_early_init(void)
+{
+	u32 pcie_cfg;
+
+	/*
+	 * Step1: Assert PCIe signal PERST#
+	 *
+	 * The CPU interface to the PERST# signal is platform dependent.
+	 * Call the board-specific codes to perform this task.
+	 */
+	board_assert_perst();
+
+	/* Step2: PHY common lane reset */
+	pcie_cfg = msg_port_alt_read(MSG_PORT_SOC_UNIT, PCIE_CFG);
+	pcie_cfg |= PCIE_PHY_LANE_RST;
+	msg_port_alt_write(MSG_PORT_SOC_UNIT, PCIE_CFG, pcie_cfg);
+	/* wait 1 ms for PHY common lane reset */
+	mdelay(1);
+
+	/* Step3: PHY sideband interface reset and controller main reset */
+	pcie_cfg = msg_port_alt_read(MSG_PORT_SOC_UNIT, PCIE_CFG);
+	pcie_cfg |= (PCIE_PHY_SB_RST | PCIE_CTLR_MAIN_RST);
+	msg_port_alt_write(MSG_PORT_SOC_UNIT, PCIE_CFG, pcie_cfg);
+	/* wait 80ms for PLL to lock */
+	mdelay(80);
+
+	/* Step4: Controller sideband interface reset */
+	pcie_cfg = msg_port_alt_read(MSG_PORT_SOC_UNIT, PCIE_CFG);
+	pcie_cfg |= PCIE_CTLR_SB_RST;
+	msg_port_alt_write(MSG_PORT_SOC_UNIT, PCIE_CFG, pcie_cfg);
+	/* wait 20ms for controller sideband interface reset */
+	mdelay(20);
+
+	/* Step5: De-assert PERST# */
+	board_deassert_perst();
+
+	/* Step6: Controller primary interface reset */
+	pcie_cfg = msg_port_alt_read(MSG_PORT_SOC_UNIT, PCIE_CFG);
+	pcie_cfg |= PCIE_CTLR_PRI_RST;
+	msg_port_alt_write(MSG_PORT_SOC_UNIT, PCIE_CFG, pcie_cfg);
+
+	/* Mixer Load Lane 0 */
+	pcie_cfg = msg_port_io_read(MSG_PORT_PCIE_AFE, PCIE_RXPICTRL0_L0);
+	pcie_cfg &= ~((1 << 6) | (1 << 7));
+	msg_port_io_write(MSG_PORT_PCIE_AFE, PCIE_RXPICTRL0_L0, pcie_cfg);
+
+	/* Mixer Load Lane 1 */
+	pcie_cfg = msg_port_io_read(MSG_PORT_PCIE_AFE, PCIE_RXPICTRL0_L1);
+	pcie_cfg &= ~((1 << 6) | (1 << 7));
+	msg_port_io_write(MSG_PORT_PCIE_AFE, PCIE_RXPICTRL0_L1, pcie_cfg);
+}
+
 static void quark_enable_legacy_seg(void)
 {
 	u32 hmisc2;
@@ -106,6 +158,17 @@ int arch_cpu_init(void)
 	 */
 	quark_setup_bars();
 
+	/*
+	 * Initialize PCIe controller
+	 *
+	 * Quark SoC holds the PCIe controller in reset following a power on.
+	 * U-Boot needs to release the PCIe controller from reset. The PCIe
+	 * controller (D23:F0/F1) will not be visible in PCI configuration
+	 * space and any access to its PCI configuration registers will cause
+	 * system hang while it is held in reset.
+	 */
+	quark_pcie_early_init();
+
 	/* Turn on legacy segments (A/B/E/F) decode to system RAM */
 	quark_enable_legacy_seg();
 
arch/x86/include/asm/arch-quark/quark.h +42 -0

60 lines not on this page · raw message

board/intel/galileo/galileo.c +56 -0

68 lines not on this page · raw message

Signature · 1 line
1.8.2.1
#6 lore raw

PATCH v4 3/11 x86: Enable PCIe controller on quark/galileo

Quoted 19 lines · Bin Meng

Quark SoC holds the PCIe controller in reset following a power on. U-Boot needs to release the PCIe controller from reset. The PCIe controller (D23:F0/F1) will not be visible in PCI configuration space and any access to its PCI configuration registers will cause system hang while it is held in reset.

Enable PCIe controller per Quark firmware writer guide.

---

Changes in v4: None
Changes in v3: None
Changes in v2:
- New patch to enable PCIe controller on quark/galileo

Quoted 5 lines
 arch/x86/cpu/quark/quark.c              | 63 +++++++++++++++++++++++++++++++++
 arch/x86/include/asm/arch-quark/quark.h | 42 ++++++++++++++++++++++
 board/intel/galileo/galileo.c           | 56 +++++++++++++++++++++++++++++
 3 files changed, 161 insertions(+)

Applied to u-boot-x86, thanks!

author
#7 lore raw

PATCH v4 4/11 x86: Convert to use driver model pci on quark/galileo

In reply to Bin Meng

Move to driver model pci for Intel quark/galileo.

---

Changes in v4:
- Reorder via 'savedefconfig'

Changes in v3: None
Changes in v2:
- Remove arch/x86/cpu/quark/pci.c completely

 arch/x86/cpu/quark/Makefile |  1 -
 arch/x86/cpu/quark/pci.c    | 70 ---------------------------------------------
 arch/x86/cpu/quark/quark.c  |  5 ----
 arch/x86/dts/galileo.dts    |  8 ++++--
 configs/galileo_defconfig   |  1 +
 include/configs/galileo.h   | 12 --------
 6 files changed, 7 insertions(+), 90 deletions(-)
 delete mode 100644 arch/x86/cpu/quark/pci.c
arch/x86/cpu/quark/Makefile +0 -1
index e87b424..8f1d018 100644
@@ -6,4 +6,3 @@
 
 obj-y += car.o dram.o msg_port.o quark.o
 obj-y += mrc.o mrc_util.o hte.o smc.o
-obj-$(CONFIG_PCI) += pci.o
arch/x86/cpu/quark/pci.c deleted +0 -70

70 lines not on this page · raw message

arch/x86/cpu/quark/quark.c +0 -5
index 7c55d9e..dda3c7c 100644
@@ -136,7 +136,6 @@ static void quark_enable_legacy_seg(void)
 
 int arch_cpu_init(void)
 {
-	struct pci_controller *hose;
 	int ret;
 
 	post_code(POST_CPU_INIT);
@@ -148,10 +147,6 @@ int arch_cpu_init(void)
 	if (ret)
 		return ret;
 
-	ret = pci_early_init_hose(&hose);
-	if (ret)
-		return ret;
-
 	/*
 	 * Quark SoC has some non-standard BARs (excluding PCI standard BARs)
 	 * which need be initialized with suggested values
arch/x86/dts/galileo.dts +6 -2
index d77ff8a..f119bf7 100644
@@ -54,8 +54,11 @@
 	pci {
 		#address-cells = <3>;
 		#size-cells = <2>;
-		compatible = "intel,pci";
-		device_type = "pci";
+		compatible = "pci-x86";
+		u-boot,dm-pre-reloc;
+		ranges = <0x02000000 0x0 0x90000000 0x90000000 0 0x20000000
+			  0x42000000 0x0 0xb0000000 0xb0000000 0 0x20000000
+			  0x01000000 0x0 0x2000 0x2000 0 0xe000>;
 
 		pciuart0: uart at 14,5 {
 			compatible = "pci8086,0936.00",
@@ -63,6 +66,7 @@
 					"pciclass,070002",
 					"pciclass,0700",
 					"x86-uart";
+			u-boot,dm-pre-reloc;
 			reg = <0x0000a500 0x0 0x0 0x0 0x0
 			       0x0200a510 0x0 0x0 0x0 0x0>;
 			reg-shift = <2>;
configs/galileo_defconfig +1 -0
index 6ef1090..59306a9 100644
@@ -14,6 +14,7 @@ CONFIG_OF_CONTROL=y
 CONFIG_SPI_FLASH=y
 CONFIG_NETDEVICES=y
 CONFIG_ETH_DESIGNWARE=y
+CONFIG_DM_PCI=y
 CONFIG_DM_RTC=y
 CONFIG_USE_PRIVATE_LIBGCC=y
 CONFIG_SYS_VSNPRINTF=y
include/configs/galileo.h +0 -12
index 3c3c6e9..b7ec279 100644
@@ -20,18 +20,6 @@
 /* ns16550 UART is memory-mapped in Quark SoC */
 #undef  CONFIG_SYS_NS16550_PORT_MAPPED
 
-#define CONFIG_PCI_MEM_BUS		0x90000000
-#define CONFIG_PCI_MEM_PHYS		CONFIG_PCI_MEM_BUS
-#define CONFIG_PCI_MEM_SIZE		0x20000000
-
-#define CONFIG_PCI_PREF_BUS		0xb0000000
-#define CONFIG_PCI_PREF_PHYS		CONFIG_PCI_PREF_BUS
-#define CONFIG_PCI_PREF_SIZE		0x20000000
-
-#define CONFIG_PCI_IO_BUS		0x2000
-#define CONFIG_PCI_IO_PHYS		CONFIG_PCI_IO_BUS
-#define CONFIG_PCI_IO_SIZE		0xe000
-
 #define CONFIG_SYS_EARLY_PCI_INIT
 #define CONFIG_PCI_PNP
 
Signature · 1 line
1.8.2.1
#8 lore raw

PATCH v4 4/11 x86: Convert to use driver model pci on quark/galileo

Quoted 14 lines · Bin Meng

Move to driver model pci for Intel quark/galileo.

---

Changes in v4:
- Reorder via 'savedefconfig'

Changes in v3: None
Changes in v2:
- Remove arch/x86/cpu/quark/pci.c completely

Quoted 8 lines
 arch/x86/cpu/quark/Makefile |  1 -
 arch/x86/cpu/quark/pci.c    | 70 ---------------------------------------------
 arch/x86/cpu/quark/quark.c  |  5 ----
 arch/x86/dts/galileo.dts    |  8 ++++--
 configs/galileo_defconfig   |  1 +
 include/configs/galileo.h   | 12 --------
 6 files changed, 7 insertions(+), 90 deletions(-)
 delete mode 100644 arch/x86/cpu/quark/pci.c

Applied to u-boot-x86, thanks!

author
#9 lore raw

PATCH v4 5/11 x86: quark: Add USB PHY initialization support

In reply to Bin Meng

USB PHY needs to be properly initialized per Quark firmware writer guide, otherwise the EHCI controller on Quark SoC won't work.

---

Changes in v4: None
Changes in v3: None
Changes in v2:
- New patch to add USB PHY initialization support

 arch/x86/cpu/quark/quark.c              | 41 +++++++++++++++++++++++++++++++++
 arch/x86/include/asm/arch-quark/quark.h |  8 +++++++
 2 files changed, 49 insertions(+)
arch/x86/cpu/quark/quark.c +41 -0
index dda3c7c..637c370 100644
@@ -125,6 +125,44 @@ static void quark_pcie_early_init(void)
 	msg_port_io_write(MSG_PORT_PCIE_AFE, PCIE_RXPICTRL0_L1, pcie_cfg);
 }
 
+static void quark_usb_early_init(void)
+{
+	u32 usb;
+
+	/* The sequence below comes from Quark firmware writer guide */
+
+	usb = msg_port_alt_read(MSG_PORT_USB_AFE, USB2_GLOBAL_PORT);
+	usb &= ~(1 << 1);
+	usb |= ((1 << 6) | (1 << 7));
+	msg_port_alt_write(MSG_PORT_USB_AFE, USB2_GLOBAL_PORT, usb);
+
+	usb = msg_port_alt_read(MSG_PORT_USB_AFE, USB2_COMPBG);
+	usb &= ~((1 << 8) | (1 << 9));
+	usb |= ((1 << 7) | (1 << 10));
+	msg_port_alt_write(MSG_PORT_USB_AFE, USB2_COMPBG, usb);
+
+	usb = msg_port_alt_read(MSG_PORT_USB_AFE, USB2_PLL2);
+	usb |= (1 << 29);
+	msg_port_alt_write(MSG_PORT_USB_AFE, USB2_PLL2, usb);
+
+	usb = msg_port_alt_read(MSG_PORT_USB_AFE, USB2_PLL1);
+	usb |= (1 << 1);
+	msg_port_alt_write(MSG_PORT_USB_AFE, USB2_PLL1, usb);
+
+	usb = msg_port_alt_read(MSG_PORT_USB_AFE, USB2_PLL1);
+	usb &= ~((1 << 3) | (1 << 4) | (1 << 5));
+	usb |= (1 << 6);
+	msg_port_alt_write(MSG_PORT_USB_AFE, USB2_PLL1, usb);
+
+	usb = msg_port_alt_read(MSG_PORT_USB_AFE, USB2_PLL2);
+	usb &= ~(1 << 29);
+	msg_port_alt_write(MSG_PORT_USB_AFE, USB2_PLL2, usb);
+
+	usb = msg_port_alt_read(MSG_PORT_USB_AFE, USB2_PLL2);
+	usb |= (1 << 24);
+	msg_port_alt_write(MSG_PORT_USB_AFE, USB2_PLL2, usb);
+}
+
 static void quark_enable_legacy_seg(void)
 {
 	u32 hmisc2;
@@ -164,6 +202,9 @@ int arch_cpu_init(void)
 	 */
 	quark_pcie_early_init();
 
+	/* Initialize USB2 PHY */
+	quark_usb_early_init();
+
 	/* Turn on legacy segments (A/B/E/F) decode to system RAM */
 	quark_enable_legacy_seg();
 
arch/x86/include/asm/arch-quark/quark.h +8 -0
index aad7fbe..5d81976 100644
@@ -12,6 +12,7 @@
 #define MSG_PORT_HOST_BRIDGE	0x03
 #define MSG_PORT_RMU		0x04
 #define MSG_PORT_MEM_MGR	0x05
+#define MSG_PORT_USB_AFE	0x14
 #define MSG_PORT_PCIE_AFE	0x16
 #define MSG_PORT_SOC_UNIT	0x31
 
@@ -49,6 +50,13 @@
 #define ESRAM_BLK_CTRL		0x82
 #define ESRAM_BLOCK_MODE	0x10000000
 
+/* Port 0x14: USB2 AFE Unit Port Registers */
+
+#define USB2_GLOBAL_PORT	0x4001
+#define USB2_PLL1		0x7f02
+#define USB2_PLL2		0x7f03
+#define USB2_COMPBG		0x7f04
+
 /* Port 0x16: PCIe AFE Unit Port Registers */
 
 #define PCIE_RXPICTRL0_L0	0x2080
Signature · 1 line
1.8.2.1
#10 lore raw

PATCH v4 5/11 x86: quark: Add USB PHY initialization support

Quoted 8 lines · Bin Meng

USB PHY needs to be properly initialized per Quark firmware writer guide, otherwise the EHCI controller on Quark SoC won't work.

---

Quoted 9 lines

Changes in v4: None
Changes in v3: None
Changes in v2:
- New patch to add USB PHY initialization support

 arch/x86/cpu/quark/quark.c              | 41 +++++++++++++++++++++++++++++++++
 arch/x86/include/asm/arch-quark/quark.h |  8 +++++++
 2 files changed, 49 insertions(+)

Applied to u-boot-x86, thanks!

author
#11 lore raw

PATCH v4 6/11 x86: galileo: Convert to use CONFIG_DM_USB

In reply to Bin Meng

Move to driver model for USB on Intel Galileo.

---

Changes in v4:
- Reorder via 'savedefconfig'

Changes in v3: None
Changes in v2:
- Update commit message to remove "USB not working" statement, as in v2, full USB support has been added.

 configs/galileo_defconfig | 2 ++
 1 file changed, 2 insertions(+)
configs/galileo_defconfig +2 -0
index 59306a9..d05154e 100644
@@ -16,5 +16,7 @@ CONFIG_NETDEVICES=y
 CONFIG_ETH_DESIGNWARE=y
 CONFIG_DM_PCI=y
 CONFIG_DM_RTC=y
+CONFIG_USB=y
+CONFIG_DM_USB=y
 CONFIG_USE_PRIVATE_LIBGCC=y
 CONFIG_SYS_VSNPRINTF=y
Signature · 1 line
1.8.2.1
#12 lore raw

PATCH v4 6/11 x86: galileo: Convert to use CONFIG_DM_USB

Quoted 10 lines · Bin Meng

Move to driver model for USB on Intel Galileo.

---

Changes in v4:
- Reorder via 'savedefconfig'

Quoted 7 lines

Changes in v3: None
Changes in v2:
- Update commit message to remove "USB not working" statement, as in v2, full USB support has been added.

 configs/galileo_defconfig | 2 ++
 1 file changed, 2 insertions(+)

Applied to u-boot-x86, thanks!

author
#13 lore raw

PATCH v4 7/11 net: designware: Fix build warnings

In reply to Bin Meng

When building dm version of designware eth driver on a platform with 64-bit phys_addr_t, it reports the following warnings:

drivers/net/designware.c: In function 'designware_eth_probe':
drivers/net/designware.c:599:2:
warning: format '%lx' expects argument of type 'long unsigned int', but argument 3 has type 'phys_addr_t' [-Wformat]
drivers/net/designware.c:600:21:
warning: cast to pointer from integer of different size [-Wint-to-pointer-cast]
drivers/net/designware.c:601:21:
warning: cast to pointer from integer of different size [-Wint-to-pointer-cast]

This commit fixes the build warnings.

---

Changes in v4: None
Changes in v3: None
Changes in v2: None

 drivers/net/designware.c | 8 ++++----
 1 file changed, 4 insertions(+), 4 deletions(-)
drivers/net/designware.c +4 -4
index d9cb507..ae78d21 100644
@@ -562,12 +562,12 @@ static int designware_eth_probe(struct udevice *dev)
 {
 	struct eth_pdata *pdata = dev_get_platdata(dev);
 	struct dw_eth_dev *priv = dev_get_priv(dev);
+	u32 iobase = pdata->iobase;
 	int ret;
 
-	debug("%s, iobase=%lx, priv=%p\n", __func__, pdata->iobase, priv);
-	priv->mac_regs_p = (struct eth_mac_regs *)pdata->iobase;
-	priv->dma_regs_p = (struct eth_dma_regs *)(pdata->iobase +
-			DW_DMA_BASE_OFFSET);
+	debug("%s, iobase=%x, priv=%p\n", __func__, iobase, priv);
+	priv->mac_regs_p = (struct eth_mac_regs *)iobase;
+	priv->dma_regs_p = (struct eth_dma_regs *)(iobase + DW_DMA_BASE_OFFSET);
 	priv->interface = pdata->phy_interface;
 
 	dw_mdio_init(dev->name, priv->mac_regs_p);
Signature · 1 line
1.8.2.1
#14 lore raw

PATCH v4 7/11 net: designware: Fix build warnings

Quoted 16 lines · Bin Meng

When building dm version of designware eth driver on a platform with 64-bit phys_addr_t, it reports the following warnings:

drivers/net/designware.c: In function 'designware_eth_probe':
drivers/net/designware.c:599:2:
warning: format '%lx' expects argument of type 'long unsigned int', but argument 3 has type 'phys_addr_t' [-Wformat]
drivers/net/designware.c:600:21:
warning: cast to pointer from integer of different size [-Wint-to-pointer-cast]
drivers/net/designware.c:601:21:
warning: cast to pointer from integer of different size [-Wint-to-pointer-cast]

This commit fixes the build warnings.

Quoted 8 lines

---

Changes in v4: None
Changes in v3: None
Changes in v2: None

 drivers/net/designware.c | 8 ++++----
 1 file changed, 4 insertions(+), 4 deletions(-)

Applied to u-boot-x86, thanks!

author
#15 lore raw

PATCH v4 8/11 dm: pci: Add an inline API to test if a device is on a PCI bus

In reply to Bin Meng

Introduce device_is_on_pci_bus() which can be utilized by driver to test if a device is on a PCI bus.

---

Changes in v4: None
Changes in v3: None
Changes in v2:
- New patch to add an inline API to test if a device is on a PCI bus

 drivers/pci/pci-uclass.c |  4 ++--
 include/pci.h            | 15 +++++++++++++++
 2 files changed, 17 insertions(+), 2 deletions(-)
drivers/pci/pci-uclass.c +2 -2
index ea70853..0756bbe 100644
@@ -238,7 +238,7 @@ int dm_pci_write_config(struct udevice *dev, int offset, unsigned long value,
 {
 	struct udevice *bus;
 
-	for (bus = dev; device_get_uclass_id(bus->parent) == UCLASS_PCI;)
+	for (bus = dev; device_is_on_pci_bus(bus);)
 		bus = bus->parent;
 	return pci_bus_write_config(bus, pci_get_bdf(dev), offset, value, size);
 }
@@ -303,7 +303,7 @@ int dm_pci_read_config(struct udevice *dev, int offset, unsigned long *valuep,
 {
 	struct udevice *bus;
 
-	for (bus = dev; device_get_uclass_id(bus->parent) == UCLASS_PCI;)
+	for (bus = dev; device_is_on_pci_bus(bus);)
 		bus = bus->parent;
 	return pci_bus_read_config(bus, pci_get_bdf(dev), offset, valuep,
 				   size);
include/pci.h +15 -0
index e24c970..293a021 100644
@@ -1273,5 +1273,20 @@ struct pci_driver_entry {
 		.match = __match, \
 		}
 
+#ifdef CONFIG_DM
+#include <dm.h>
+
+/**
+ * device_is_on_pci_bus - Test if a device is on a PCI bus
+ *
+ * @dev:	device to test
+ * @return:	true if it is on a PCI bus, false otherwise
+ */
+static inline bool device_is_on_pci_bus(struct udevice *dev)
+{
+	return device_get_uclass_id(dev->parent) == UCLASS_PCI;
+}
+#endif
+
 #endif /* __ASSEMBLY__ */
 #endif /* _PCI_H */
Signature · 1 line
1.8.2.1
#16 lore raw

PATCH v4 8/11 dm: pci: Add an inline API to test if a device is on a PCI bus

Quoted 8 lines · Bin Meng

Introduce device_is_on_pci_bus() which can be utilized by driver to test if a device is on a PCI bus.

---

Quoted 8 lines

Changes in v4: None
Changes in v3: None
Changes in v2:
- New patch to add an inline API to test if a device is on a PCI bus

 drivers/pci/pci-uclass.c |  4 ++--
 include/pci.h            | 15 +++++++++++++++
 2 files changed, 17 insertions(+), 2 deletions(-)

Applied to u-boot-x86, thanks!

#17 lore raw

PATCH v4 8/11 dm: pci: Add an inline API to test if a device is on a PCI bus

Hi Bin,

Quoted 14 lines · Simon Glass
Quoted 13 lines · Bin Meng

Introduce device_is_on_pci_bus() which can be utilized by driver to test if a device is on a PCI bus.

---

Changes in v4: None
Changes in v3: None
Changes in v2:
- New patch to add an inline API to test if a device is on a PCI bus

Quoted 5 lines
Quoted 3 lines
 drivers/pci/pci-uclass.c |  4 ++--
 include/pci.h            | 15 +++++++++++++++
 2 files changed, 17 insertions(+), 2 deletions(-)

Applied to u-boot-x86, thanks!

Sorry, I did not end up bringing this in from testing.

This causes build errors on quite a few boards - can you please take a look:

w+../include/pci.h: In function 'device_is_on_pci_bus':
w+../include/pci.h:1287:2: warning: implicit declaration of function 'device_get_uclass_id' [-Wimplicit-function-declaration]

boards:

alt,sniper,omap3_zoom1,p2571,omap3_beagle,mx6sxsabresd_spl,mx6ul_14x14_evk,devkit3250,apalis_t30,pcm051_rev3,pcm051_rev1,gose,venice2,ls2085ardb,mx6dlsabreauto,cm_t43,whistler,igep0030_nand,silk,am335x_boneblack,cairo,wandboard,birdland_bav335a,birdland_bav335b,mx6slevk_spl,am335x_evm_usbspl,igep0032,igep0030,devkit8000,chromebook_jerry,mx6qsabrelite,s5p_goni,snapper9g20,mx6sxsabresd,mx6dlsabresd,rpi_2,am335x_evm_nor,pengwyn,work_92105,tec-ng,trimslice,rpi,colibri_t30,igep0020,mx6cuboxi,cm_t335,ls2085aqds,beaver,am335x_baltos,mx6slevk_spinor,snapper9260,firefly-rk3288,jetson-tk1,mx6qsabresd,udoo,mx6sabresd_spl,igep0020_nand,am335x_evm_norboot,plutux,dalmore,marsboard,cgtqmx6qeval,am335x_evm_spiboot,lager,am335x_evm,cm_fx6,riotboard,omap3_logic,porter,pepper,omap3_overo,mx6slevk,am335x_boneblack_vboot,mx6qsabreauto,mx6qpsabreauto,am335x_gp_evm,p2371-0000,koelsch,am335x_igep0033,cardhu,e2220-1170

Regards,
Simon

author
#18 lore raw

PATCH v4 8/11 dm: pci: Add an inline API to test if a device is on a PCI bus

Hi Simon,

Quoted 27 lines · Simon Glass

Hi Bin,

Quoted 14 lines · Simon Glass
Quoted 13 lines · Bin Meng

Introduce device_is_on_pci_bus() which can be utilized by driver to test if a device is on a PCI bus.

---

Changes in v4: None
Changes in v3: None
Changes in v2:
- New patch to add an inline API to test if a device is on a PCI bus

Quoted 5 lines
Quoted 3 lines
 drivers/pci/pci-uclass.c |  4 ++--
 include/pci.h            | 15 +++++++++++++++
 2 files changed, 17 insertions(+), 2 deletions(-)

Applied to u-boot-x86, thanks!

Sorry, I did not end up bringing this in from testing.

This causes build errors on quite a few boards - can you please take a look:

Quoted 8 lines

w+../include/pci.h: In function 'device_is_on_pci_bus':
w+../include/pci.h:1287:2: warning: implicit declaration of function 'device_get_uclass_id' [-Wimplicit-function-declaration]

boards:

alt,sniper,omap3_zoom1,p2571,omap3_beagle,mx6sxsabresd_spl,mx6ul_14x14_evk,devkit3250,apalis_t30,pcm051_rev3,pcm051_rev1,gose,venice2,ls2085ardb,mx6dlsabreauto,cm_t43,whistler,igep0030_nand,silk,am335x_boneblack,cairo,wandboard,birdland_bav335a,birdland_bav335b,mx6slevk_spl,am335x_evm_usbspl,igep0032,igep0030,devkit8000,chromebook_jerry,mx6qsabrelite,s5p_goni,snapper9g20,mx6sxsabresd,mx6dlsabresd,rpi_2,am335x_evm_nor,pengwyn,work_92105,tec-ng,trimslice,rpi,colibri_t30,igep0020,mx6cuboxi,cm_t335,ls2085aqds,beaver,am335x_baltos,mx6slevk_spinor,snapper9260,firefly-rk3288,jetson-tk1,mx6qsabresd,udoo,mx6sabresd_spl,igep0020_nand,am335x_evm_norboot,plutux,dalmore,marsboard,cgtqmx6qeval,am335x_evm_spiboot,lager,am335x_evm,cm_fx6,riotboard,omap3_logic,porter,pepper,omap3_overo,mx6slevk,am335x_boneblack_vboot,mx6qsabreauto,mx6qpsabreauto,am335x_gp_evm,p2371-0000,koelsch,am335x_igep0033,cardhu,e2220-1170

Sorry, please check the v5 series @ http://patchwork.ozlabs.org/patch/516672/

Regards,
Bin

author
#19 lore raw

PATCH v4 9/11 net: designware: Add support to PCI designware devices

In reply to Bin Meng

The Designware ethernet controller is also seen on PCI bus, e.g. on Intel Quark SoC. Add this support in the DM version driver.

---

Changes in v4: None
Changes in v3:
- Change to use dm_pci_read_config32()

Changes in v2:
- Change to use device_is_on_pci_bus()

 drivers/net/designware.c | 38 ++++++++++++++++++++++++++++++++++++++
 1 file changed, 38 insertions(+)
drivers/net/designware.c +38 -0
index ae78d21..d45340c 100644
@@ -14,6 +14,7 @@
 #include <errno.h>
 #include <miiphy.h>
 #include <malloc.h>
+#include <pci.h>
 #include <linux/compiler.h>
 #include <linux/err.h>
 #include <asm/io.h>
@@ -558,6 +559,20 @@ static int designware_eth_write_hwaddr(struct udevice *dev)
 	return _dw_write_hwaddr(priv, pdata->enetaddr);
 }
 
+static int designware_eth_bind(struct udevice *dev)
+{
+	static int num_cards;
+	char name[20];
+
+	/* Create a unique device name for PCI type devices */
+	if (device_is_on_pci_bus(dev)) {
+		sprintf(name, "eth_designware#%u", num_cards++);
+		device_set_name(dev, name);
+	}
+
+	return 0;
+}
+
 static int designware_eth_probe(struct udevice *dev)
 {
 	struct eth_pdata *pdata = dev_get_platdata(dev);
@@ -565,6 +580,21 @@ static int designware_eth_probe(struct udevice *dev)
 	u32 iobase = pdata->iobase;
 	int ret;
 
+	/*
+	 * If we are on PCI bus, either directly attached to a PCI root port,
+	 * or via a PCI bridge, fill in platdata before we probe the hardware.
+	 */
+	if (device_is_on_pci_bus(dev)) {
+		pci_dev_t bdf = pci_get_bdf(dev);
+
+		dm_pci_read_config32(dev, PCI_BASE_ADDRESS_0, &iobase);
+		iobase &= PCI_BASE_ADDRESS_MEM_MASK;
+		iobase = pci_mem_to_phys(bdf, iobase);
+
+		pdata->iobase = iobase;
+		pdata->phy_interface = PHY_INTERFACE_MODE_RMII;
+	}
+
 	debug("%s, iobase=%x, priv=%p\n", __func__, iobase, priv);
 	priv->mac_regs_p = (struct eth_mac_regs *)iobase;
 	priv->dma_regs_p = (struct eth_dma_regs *)(iobase + DW_DMA_BASE_OFFSET);
@@ -617,10 +647,18 @@ U_BOOT_DRIVER(eth_designware) = {
 	.id	= UCLASS_ETH,
 	.of_match = designware_eth_ids,
 	.ofdata_to_platdata = designware_eth_ofdata_to_platdata,
+	.bind	= designware_eth_bind,
 	.probe	= designware_eth_probe,
 	.ops	= &designware_eth_ops,
 	.priv_auto_alloc_size = sizeof(struct dw_eth_dev),
 	.platdata_auto_alloc_size = sizeof(struct eth_pdata),
 	.flags = DM_FLAG_ALLOC_PRIV_DMA,
 };
+
+static struct pci_device_id supported[] = {
+	{ PCI_DEVICE(PCI_VENDOR_ID_INTEL, PCI_DEVICE_ID_INTEL_QRK_EMAC) },
+	{ }
+};
+
+U_BOOT_PCI_DEVICE(eth_designware, supported);
 #endif
Signature · 1 line
1.8.2.1
#20 lore raw

PATCH v4 9/11 net: designware: Add support to PCI designware devices

Hi Joe,

Quoted 11 lines · Bin Meng

The Designware ethernet controller is also seen on PCI bus, e.g. on Intel Quark SoC. Add this support in the DM version driver.

---

Changes in v4: None
Changes in v3:
- Change to use dm_pci_read_config32()

Quoted 5 lines

Changes in v2:
- Change to use device_is_on_pci_bus()

 drivers/net/designware.c | 38 ++++++++++++++++++++++++++++++++++++++
 1 file changed, 38 insertions(+)

Does this patch look OK to you?

Bin, perhaps (later) we should add a dm_pci_mem_to_phys(struct udevice *...) ?

Quoted 76 lines
drivers/net/designware.c +38 -1
index ae78d21..d45340c 100644
@@ -14,6 +14,7 @@
 #include <errno.h>
 #include <miiphy.h>
 #include <malloc.h>
+#include <pci.h>
 #include <linux/compiler.h>
 #include <linux/err.h>
 #include <asm/io.h>
@@ -558,6 +559,20 @@ static int designware_eth_write_hwaddr(struct udevice *dev)
        return _dw_write_hwaddr(priv, pdata->enetaddr);
 }
 
+static int designware_eth_bind(struct udevice *dev)
+{
+       static int num_cards;
+       char name[20];
+
+       /* Create a unique device name for PCI type devices */
+       if (device_is_on_pci_bus(dev)) {
+               sprintf(name, "eth_designware#%u", num_cards++);
+               device_set_name(dev, name);
+       }
+
+       return 0;
+}
+
 static int designware_eth_probe(struct udevice *dev)
 {
        struct eth_pdata *pdata = dev_get_platdata(dev);
@@ -565,6 +580,21 @@ static int designware_eth_probe(struct udevice *dev)
        u32 iobase = pdata->iobase;
        int ret;
 
+       /*
+        * If we are on PCI bus, either directly attached to a PCI root port,
+        * or via a PCI bridge, fill in platdata before we probe the hardware.
+        */
+       if (device_is_on_pci_bus(dev)) {
+               pci_dev_t bdf = pci_get_bdf(dev);
+
+               dm_pci_read_config32(dev, PCI_BASE_ADDRESS_0, &iobase);
+               iobase &= PCI_BASE_ADDRESS_MEM_MASK;
+               iobase = pci_mem_to_phys(bdf, iobase);
+
+               pdata->iobase = iobase;
+               pdata->phy_interface = PHY_INTERFACE_MODE_RMII;
+       }
+
        debug("%s, iobase=%x, priv=%p\n", __func__, iobase, priv);
        priv->mac_regs_p = (struct eth_mac_regs *)iobase;
        priv->dma_regs_p = (struct eth_dma_regs *)(iobase + DW_DMA_BASE_OFFSET);
@@ -617,10 +647,18 @@ U_BOOT_DRIVER(eth_designware) = {
        .id     = UCLASS_ETH,
        .of_match = designware_eth_ids,
        .ofdata_to_platdata = designware_eth_ofdata_to_platdata,
+       .bind   = designware_eth_bind,
        .probe  = designware_eth_probe,
        .ops    = &designware_eth_ops,
        .priv_auto_alloc_size = sizeof(struct dw_eth_dev),
        .platdata_auto_alloc_size = sizeof(struct eth_pdata),
        .flags = DM_FLAG_ALLOC_PRIV_DMA,
 };
+
+static struct pci_device_id supported[] = {
+       { PCI_DEVICE(PCI_VENDOR_ID_INTEL, PCI_DEVICE_ID_INTEL_QRK_EMAC) },
+       { }
+};
+
+U_BOOT_PCI_DEVICE(eth_designware, supported);
 #endif
--
Quoted 2 lines

1.8.2.1

Regards,
Simon

author
#21 lore raw

PATCH v4 9/11 net: designware: Add support to PCI designware devices

Hi Simon,

Quoted 17 lines · Simon Glass

Hi Joe,

Quoted 14 lines · Bin Meng

The Designware ethernet controller is also seen on PCI bus, e.g. on Intel Quark SoC. Add this support in the DM version driver.

---

Changes in v4: None
Changes in v3:
- Change to use dm_pci_read_config32()

Changes in v2:
- Change to use device_is_on_pci_bus()

Quoted 8 lines
Quoted 2 lines
 drivers/net/designware.c | 38 ++++++++++++++++++++++++++++++++++++++
 1 file changed, 38 insertions(+)

Does this patch look OK to you?

Bin, perhaps (later) we should add a dm_pci_mem_to_phys(struct udevice *...) ?

Yes, I think so.

Quoted 69 lines
Quoted 69 lines
drivers/net/designware.c +32 -0
index ae78d21..d45340c 100644
@@ -14,6 +14,7 @@
 #include <errno.h>
 #include <miiphy.h>
 #include <malloc.h>
+#include <pci.h>
 #include <linux/compiler.h>
 #include <linux/err.h>
 #include <asm/io.h>
@@ -558,6 +559,20 @@ static int designware_eth_write_hwaddr(struct udevice *dev)
        return _dw_write_hwaddr(priv, pdata->enetaddr);
 }
 
+static int designware_eth_bind(struct udevice *dev)
+{
+       static int num_cards;
+       char name[20];
+
+       /* Create a unique device name for PCI type devices */
+       if (device_is_on_pci_bus(dev)) {
+               sprintf(name, "eth_designware#%u", num_cards++);
+               device_set_name(dev, name);
+       }
+
+       return 0;
+}
+
 static int designware_eth_probe(struct udevice *dev)
 {
        struct eth_pdata *pdata = dev_get_platdata(dev);
@@ -565,6 +580,21 @@ static int designware_eth_probe(struct udevice *dev)
        u32 iobase = pdata->iobase;
        int ret;
 
+       /*
+        * If we are on PCI bus, either directly attached to a PCI root port,
+        * or via a PCI bridge, fill in platdata before we probe the hardware.
+        */
+       if (device_is_on_pci_bus(dev)) {
+               pci_dev_t bdf = pci_get_bdf(dev);
+
+               dm_pci_read_config32(dev, PCI_BASE_ADDRESS_0, &iobase);
+               iobase &= PCI_BASE_ADDRESS_MEM_MASK;
+               iobase = pci_mem_to_phys(bdf, iobase);
+
+               pdata->iobase = iobase;
+               pdata->phy_interface = PHY_INTERFACE_MODE_RMII;
+       }
+
        debug("%s, iobase=%x, priv=%p\n", __func__, iobase, priv);
        priv->mac_regs_p = (struct eth_mac_regs *)iobase;
        priv->dma_regs_p = (struct eth_dma_regs *)(iobase + DW_DMA_BASE_OFFSET);
@@ -617,10 +647,18 @@ U_BOOT_DRIVER(eth_designware) = {
        .id     = UCLASS_ETH,
        .of_match = designware_eth_ids,
        .ofdata_to_platdata = designware_eth_ofdata_to_platdata,
+       .bind   = designware_eth_bind,
        .probe  = designware_eth_probe,
        .ops    = &designware_eth_ops,
        .priv_auto_alloc_size = sizeof(struct dw_eth_dev),
        .platdata_auto_alloc_size = sizeof(struct eth_pdata),
        .flags = DM_FLAG_ALLOC_PRIV_DMA,
 };
+
Quoted 8 lines

drivers/net/designware.c U_BOOT_DRIVER(eth_designware) = {

Quoted 8 lines
drivers/net/designware.c +6 -1
+static struct pci_device_id supported[] = {
+       { PCI_DEVICE(PCI_VENDOR_ID_INTEL, PCI_DEVICE_ID_INTEL_QRK_EMAC) },
+       { }
+};
+
+U_BOOT_PCI_DEVICE(eth_designware, supported);
 #endif
--

Regards,
Bin

author
#22 lore raw

PATCH v4 10/11 x86: Convert to use driver model eth on quark/galileo

In reply to Bin Meng

Convert to use DM version of Designware ethernet driver on Intel quark/galileo.

---

Changes in v4: None
Changes in v3: None
Changes in v2: None

 arch/x86/cpu/quark/quark.c | 19 -------------------
 configs/galileo_defconfig  |  2 +-
 2 files changed, 1 insertion(+), 20 deletions(-)
arch/x86/cpu/quark/quark.c +0 -19
index 637c370..caa3875 100644
@@ -6,8 +6,6 @@
 
 #include <common.h>
 #include <mmc.h>
-#include <netdev.h>
-#include <phy.h>
 #include <asm/io.h>
 #include <asm/irq.h>
 #include <asm/pci.h>
@@ -231,23 +229,6 @@ int cpu_mmc_init(bd_t *bis)
 			    ARRAY_SIZE(mmc_supported));
 }
 
-int cpu_eth_init(bd_t *bis)
-{
-	u32 base;
-	int ret0, ret1;
-
-	qrk_pci_read_config_dword(QUARK_EMAC0, PCI_BASE_ADDRESS_0, &base);
-	ret0 = designware_initialize(base, PHY_INTERFACE_MODE_RMII);
-
-	qrk_pci_read_config_dword(QUARK_EMAC1, PCI_BASE_ADDRESS_0, &base);
-	ret1 = designware_initialize(base, PHY_INTERFACE_MODE_RMII);
-
-	if (ret0 < 0 && ret1 < 0)
-		return -1;
-	else
-		return 0;
-}
-
 void cpu_irq_init(void)
 {
 	struct quark_rcba *rcba;
configs/galileo_defconfig +1 -1
index d05154e..9623986 100644
@@ -12,7 +12,7 @@ CONFIG_BOOTSTAGE_REPORT=y
 CONFIG_CMD_BOOTSTAGE=y
 CONFIG_OF_CONTROL=y
 CONFIG_SPI_FLASH=y
-CONFIG_NETDEVICES=y
+CONFIG_DM_ETH=y
 CONFIG_ETH_DESIGNWARE=y
 CONFIG_DM_PCI=y
 CONFIG_DM_RTC=y
Signature · 1 line
1.8.2.1
author
#23 lore raw

PATCH v4 11/11 x86: quark: Add PCIe/USB static register programming after memory init

In reply to Bin Meng

This adds static register programming for PCIe and USB after memory init as required by Quark firmware writer guide. Although not doing this did not cause any malfunction, just do it for safety.

---

Changes in v4: None
Changes in v3: None
Changes in v2:
- New patch to add PCIe/USB static register programming after memory init

 arch/x86/cpu/quark/quark.c              | 64 +++++++++++++++++++++++++++++++++
 arch/x86/include/asm/arch-quark/quark.h | 22 ++++++++++++
 include/configs/galileo.h               |  1 +
 3 files changed, 87 insertions(+)
arch/x86/cpu/quark/quark.c +64 -0
index caa3875..934250b 100644
@@ -223,6 +223,53 @@ void reset_cpu(ulong addr)
 	x86_full_reset();
 }
 
+static void quark_pcie_init(void)
+{
+	u32 val;
+
+	/* PCIe upstream non-posted & posted request size */
+	qrk_pci_write_config_dword(QUARK_PCIE0, PCIE_RP_CCFG,
+				   CCFG_UPRS | CCFG_UNRS);
+	qrk_pci_write_config_dword(QUARK_PCIE1, PCIE_RP_CCFG,
+				   CCFG_UPRS | CCFG_UNRS);
+
+	/* PCIe packet fast transmit mode (IPF) */
+	qrk_pci_write_config_dword(QUARK_PCIE0, PCIE_RP_MPC2, MPC2_IPF);
+	qrk_pci_write_config_dword(QUARK_PCIE1, PCIE_RP_MPC2, MPC2_IPF);
+
+	/* PCIe message bus idle counter (SBIC) */
+	qrk_pci_read_config_dword(QUARK_PCIE0, PCIE_RP_MBC, &val);
+	val |= MBC_SBIC;
+	qrk_pci_write_config_dword(QUARK_PCIE0, PCIE_RP_MBC, val);
+	qrk_pci_read_config_dword(QUARK_PCIE1, PCIE_RP_MBC, &val);
+	val |= MBC_SBIC;
+	qrk_pci_write_config_dword(QUARK_PCIE1, PCIE_RP_MBC, val);
+}
+
+static void quark_usb_init(void)
+{
+	u32 bar;
+
+	/* Change USB EHCI packet buffer OUT/IN threshold */
+	qrk_pci_read_config_dword(QUARK_USB_EHCI, PCI_BASE_ADDRESS_0, &bar);
+	writel((0x7f << 16) | 0x7f, bar + EHCI_INSNREG01);
+
+	/* Disable USB device interrupts */
+	qrk_pci_read_config_dword(QUARK_USB_DEVICE, PCI_BASE_ADDRESS_0, &bar);
+	writel(0x7f, bar + USBD_INT_MASK);
+	writel((0xf << 16) | 0xf, bar + USBD_EP_INT_MASK);
+	writel((0xf << 16) | 0xf, bar + USBD_EP_INT_STS);
+}
+
+int arch_early_init_r(void)
+{
+	quark_pcie_init();
+
+	quark_usb_init();
+
+	return 0;
+}
+
 int cpu_mmc_init(bd_t *bis)
 {
 	return pci_mmc_init("Quark SDHCI", mmc_supported,
@@ -256,3 +303,20 @@ int arch_misc_init(void)
 {
 	return pirq_init();
 }
+
+void board_final_cleanup(void)
+{
+	struct quark_rcba *rcba;
+	u32 base, val;
+
+	qrk_pci_read_config_dword(QUARK_LEGACY_BRIDGE, LB_RCBA, &base);
+	base &= ~MEM_BAR_EN;
+	rcba = (struct quark_rcba *)base;
+
+	/* Initialize 'Component ID' to zero */
+	val = readl(&rcba->esd);
+	val &= ~0xff0000;
+	writel(val, &rcba->esd);
+
+	return;
+}
arch/x86/include/asm/arch-quark/quark.h +22 -0
index 5d81976..eb3afbf 100644
@@ -88,6 +88,20 @@
 /* 64KiB of RMU binary in flash */
 #define RMU_BINARY_SIZE		0x10000
 
+/* PCIe Root Port Configuration Registers */
+
+#define PCIE_RP_CCFG		0xd0
+#define CCFG_UPRS		(1 << 14)
+#define CCFG_UNRS		(1 << 15)
+#define CCFG_UNSD		(1 << 23)
+#define CCFG_UPSD		(1 << 24)
+
+#define PCIE_RP_MPC2		0xd4
+#define MPC2_IPF		(1 << 11)
+
+#define PCIE_RP_MBC		0xf4
+#define MBC_SBIC		(3 << 16)
+
 /* Legacy Bridge PCI Configuration Registers */
 #define LB_GBA			0x44
 #define LB_PM1BLK		0x48
@@ -100,6 +114,14 @@
 #define LB_BC			0xd8
 #define LB_RCBA			0xf0
 
+/* USB EHCI memory-mapped registers */
+#define EHCI_INSNREG01		0x94
+
+/* USB device memory-mapped registers */
+#define USBD_INT_MASK		0x410
+#define USBD_EP_INT_STS		0x414
+#define USBD_EP_INT_MASK	0x418
+
 #ifndef __ASSEMBLY__
 
 /* Root Complex Register Block */
include/configs/galileo.h +1 -0
index b7ec279..ba6c8f1 100644
@@ -15,6 +15,7 @@
 
 #define CONFIG_SYS_MONITOR_LEN		(1 << 20)
 #define CONFIG_BOARD_EARLY_INIT_F
+#define CONFIG_ARCH_EARLY_INIT_R
 #define CONFIG_ARCH_MISC_INIT
 
 /* ns16550 UART is memory-mapped in Quark SoC */
Signature · 1 line
1.8.2.1
#24 lore raw

PATCH v4 11/11 x86: quark: Add PCIe/USB static register programming after memory init

Quoted 14 lines · Bin Meng

This adds static register programming for PCIe and USB after memory init as required by Quark firmware writer guide. Although not doing this did not cause any malfunction, just do it for safety.

---

Changes in v4: None
Changes in v3: None
Changes in v2:
- New patch to add PCIe/USB static register programming after memory init

Quoted 4 lines
 arch/x86/cpu/quark/quark.c              | 64 +++++++++++++++++++++++++++++++++
 arch/x86/include/asm/arch-quark/quark.h | 22 ++++++++++++
 include/configs/galileo.h               |  1 +
 3 files changed, 87 insertions(+)

Applied to u-boot-x86, thanks!