Linux MIPS Architecture development
 help / color / mirror / Atom feed
* [PATCH 1/4] arch: mips: lantiq: return correct value for fpi clock on ar9
@ 2015-11-04 12:14 John Crispin
  2015-11-04 12:14 ` [PATCH 2/4] arch: mips: lantiq: initialize the USB core on boot John Crispin
                   ` (2 more replies)
  0 siblings, 3 replies; 5+ messages in thread
From: John Crispin @ 2015-11-04 12:14 UTC (permalink / raw)
  To: Ralf Baechle; +Cc: linux-mips

Some configurations of AR9 reported the incorrect speed for the fpi bus.

Signed-off-by: Ben Mulvihill <ben.mulvihill@gmail.com>
Signed-off-by: John Crispin <blogic@openwrt.org>
---
 arch/mips/lantiq/xway/clk.c |    5 +++--
 1 file changed, 3 insertions(+), 2 deletions(-)

diff --git a/arch/mips/lantiq/xway/clk.c b/arch/mips/lantiq/xway/clk.c
index 8750dc0..2ebe062 100644
--- a/arch/mips/lantiq/xway/clk.c
+++ b/arch/mips/lantiq/xway/clk.c
@@ -87,8 +87,9 @@ unsigned long ltq_ar9_fpi_hz(void)
 	unsigned long sys = ltq_ar9_sys_hz();
 
 	if (ltq_cgu_r32(CGU_SYS) & BIT(0))
-		return sys;
-	return sys >> 1;
+		return sys / 3;
+	else
+		return sys / 2;
 }
 
 unsigned long ltq_ar9_cpu_hz(void)
-- 
1.7.10.4

^ permalink raw reply related	[flat|nested] 5+ messages in thread

* [PATCH 2/4] arch: mips: lantiq: initialize the USB core on boot
  2015-11-04 12:14 [PATCH 1/4] arch: mips: lantiq: return correct value for fpi clock on ar9 John Crispin
@ 2015-11-04 12:14 ` John Crispin
  2015-11-04 12:14 ` [PATCH 3/4] arch: mips: lantiq: force the crossbar to big endian John Crispin
  2015-11-04 12:14 ` [PATCH 4/4] arch: mips: lantiq: disable xbar fpi burst mode John Crispin
  2 siblings, 0 replies; 5+ messages in thread
From: John Crispin @ 2015-11-04 12:14 UTC (permalink / raw)
  To: Ralf Baechle; +Cc: linux-mips

There is a DWC2 USB core in these SoCs. To make USB work we need to first
reset and power the state machine. These are SoC specific registers and
not part of the actual USB core.

Signed-off-by: Antti Seppälä <a.seppala@gmail.com>
Signed-off-by: John Crispin <blogic@openwrt.org>
---
 arch/mips/lantiq/xway/reset.c |   74 +++++++++++++++++++++++++++++++++++++++++
 1 file changed, 74 insertions(+)

diff --git a/arch/mips/lantiq/xway/reset.c b/arch/mips/lantiq/xway/reset.c
index fe68f9a..7b3e48b 100644
--- a/arch/mips/lantiq/xway/reset.c
+++ b/arch/mips/lantiq/xway/reset.c
@@ -44,6 +44,37 @@
 #define RCU_BOOT_SEL(x)		((x >> 18) & 0x7)
 #define RCU_BOOT_SEL_XRX200(x)	(((x >> 17) & 0xf) | ((x >> 8) & 0x10))
 
+/* dwc2 USB configuration registers */
+#define RCU_USB1CFG		0x0018
+#define RCU_USB2CFG		0x0034
+
+/* USB DMA endianness bits */
+#define RCU_USBCFG_HDSEL_BIT	BIT(11)
+#define RCU_USBCFG_HOST_END_BIT	BIT(10)
+#define RCU_USBCFG_SLV_END_BIT	BIT(9)
+
+/* USB reset bits */
+#define RCU_USBRESET		0x0010
+
+#define USBRESET_BIT		BIT(4)
+
+#define RCU_USBRESET2		0x0048
+
+#define USB1RESET_BIT		BIT(4)
+#define USB2RESET_BIT		BIT(5)
+
+#define RCU_CFG1A		0x0038
+#define RCU_CFG1B		0x003C
+
+/* USB PMU devices */
+#define PMU_AHBM		BIT(15)
+#define PMU_USB0		BIT(6)
+#define PMU_USB1		BIT(27)
+
+/* USB PHY PMU devices */
+#define PMU_USB0_P		BIT(0)
+#define PMU_USB1_P		BIT(26)
+
 /* remapped base addr of the reset control unit */
 static void __iomem *ltq_rcu_membase;
 static struct device_node *ltq_rcu_np;
@@ -200,6 +231,45 @@ static void ltq_machine_power_off(void)
 	unreachable();
 }
 
+static void ltq_usb_init(void)
+{
+	/* Power for USB cores 1 & 2 */
+	ltq_pmu_enable(PMU_AHBM);
+	ltq_pmu_enable(PMU_USB0);
+	ltq_pmu_enable(PMU_USB1);
+
+	ltq_rcu_w32(ltq_rcu_r32(RCU_CFG1A) | BIT(0), RCU_CFG1A);
+	ltq_rcu_w32(ltq_rcu_r32(RCU_CFG1B) | BIT(0), RCU_CFG1B);
+
+	/* Enable USB PHY power for cores 1 & 2 */
+	ltq_pmu_enable(PMU_USB0_P);
+	ltq_pmu_enable(PMU_USB1_P);
+
+	/* Configure cores to host mode */
+	ltq_rcu_w32(ltq_rcu_r32(RCU_USB1CFG) & ~RCU_USBCFG_HDSEL_BIT,
+		RCU_USB1CFG);
+	ltq_rcu_w32(ltq_rcu_r32(RCU_USB2CFG) & ~RCU_USBCFG_HDSEL_BIT,
+		RCU_USB2CFG);
+
+	/* Select DMA endianness (Host-endian: big-endian) */
+	ltq_rcu_w32((ltq_rcu_r32(RCU_USB1CFG) & ~RCU_USBCFG_SLV_END_BIT)
+		| RCU_USBCFG_HOST_END_BIT, RCU_USB1CFG);
+	ltq_rcu_w32(ltq_rcu_r32((RCU_USB2CFG) & ~RCU_USBCFG_SLV_END_BIT)
+		| RCU_USBCFG_HOST_END_BIT, RCU_USB2CFG);
+
+	/* Hard reset USB state machines */
+	ltq_rcu_w32(ltq_rcu_r32(RCU_USBRESET) | USBRESET_BIT, RCU_USBRESET);
+	udelay(50 * 1000);
+	ltq_rcu_w32(ltq_rcu_r32(RCU_USBRESET) & ~USBRESET_BIT, RCU_USBRESET);
+
+	/* Soft reset USB state machines */
+	ltq_rcu_w32(ltq_rcu_r32(RCU_USBRESET2)
+		| USB1RESET_BIT | USB2RESET_BIT, RCU_USBRESET2);
+	udelay(50 * 1000);
+	ltq_rcu_w32(ltq_rcu_r32(RCU_USBRESET2)
+		& ~(USB1RESET_BIT | USB2RESET_BIT), RCU_USBRESET2);
+}
+
 static int __init mips_reboot_setup(void)
 {
 	struct resource res;
@@ -223,6 +293,10 @@ static int __init mips_reboot_setup(void)
 	if (!ltq_rcu_membase)
 		panic("Failed to remap core memory");
 
+	if (of_machine_is_compatible("lantiq,ar9") ||
+	    of_machine_is_compatible("lantiq,vr9"))
+		ltq_usb_init();
+
 	_machine_restart = ltq_machine_restart;
 	_machine_halt = ltq_machine_halt;
 	pm_power_off = ltq_machine_power_off;
-- 
1.7.10.4

^ permalink raw reply related	[flat|nested] 5+ messages in thread

* [PATCH 3/4] arch: mips: lantiq: force the crossbar to big endian
  2015-11-04 12:14 [PATCH 1/4] arch: mips: lantiq: return correct value for fpi clock on ar9 John Crispin
  2015-11-04 12:14 ` [PATCH 2/4] arch: mips: lantiq: initialize the USB core on boot John Crispin
@ 2015-11-04 12:14 ` John Crispin
  2015-11-04 12:14 ` [PATCH 4/4] arch: mips: lantiq: disable xbar fpi burst mode John Crispin
  2 siblings, 0 replies; 5+ messages in thread
From: John Crispin @ 2015-11-04 12:14 UTC (permalink / raw)
  To: Ralf Baechle; +Cc: linux-mips

Signed-off-by: John Crispin <blogic@openwrt.org>
---
 arch/mips/lantiq/xway/reset.c |    8 ++++++++
 1 file changed, 8 insertions(+)

diff --git a/arch/mips/lantiq/xway/reset.c b/arch/mips/lantiq/xway/reset.c
index 7b3e48b..078fadf 100644
--- a/arch/mips/lantiq/xway/reset.c
+++ b/arch/mips/lantiq/xway/reset.c
@@ -33,6 +33,10 @@
 #define RCU_GFS_ADD0_XRX200	0x0020
 #define RCU_GFS_ADD1_XRX200	0x0068
 
+/* xbar BE flag */
+#define RCU_AHB_ENDIAN          0x004C
+#define RCU_VR9_BE_AHB1S        0x00000008
+
 /* reboot bit */
 #define RCU_RD_GPHY0_XRX200	BIT(31)
 #define RCU_RD_SRST		BIT(30)
@@ -297,6 +301,10 @@ static int __init mips_reboot_setup(void)
 	    of_machine_is_compatible("lantiq,vr9"))
 		ltq_usb_init();
 
+	if (of_machine_is_compatible("lantiq,vr9"))
+		ltq_rcu_w32(ltq_rcu_r32(RCU_AHB_ENDIAN) | RCU_VR9_BE_AHB1S,
+			    RCU_AHB_ENDIAN);
+
 	_machine_restart = ltq_machine_restart;
 	_machine_halt = ltq_machine_halt;
 	pm_power_off = ltq_machine_power_off;
-- 
1.7.10.4

^ permalink raw reply related	[flat|nested] 5+ messages in thread

* [PATCH 4/4] arch: mips: lantiq: disable xbar fpi burst mode
  2015-11-04 12:14 [PATCH 1/4] arch: mips: lantiq: return correct value for fpi clock on ar9 John Crispin
  2015-11-04 12:14 ` [PATCH 2/4] arch: mips: lantiq: initialize the USB core on boot John Crispin
  2015-11-04 12:14 ` [PATCH 3/4] arch: mips: lantiq: force the crossbar to big endian John Crispin
@ 2015-11-04 12:14 ` John Crispin
  2015-11-04 20:06   ` Sergei Shtylyov
  2 siblings, 1 reply; 5+ messages in thread
From: John Crispin @ 2015-11-04 12:14 UTC (permalink / raw)
  To: Ralf Baechle; +Cc: linux-mips

Signed-off-by: John Crispin <blogic@openwrt.org>
---
 arch/mips/lantiq/xway/sysctrl.c |   41 +++++++++++++++++++++++++++++++++++++++
 1 file changed, 41 insertions(+)

diff --git a/arch/mips/lantiq/xway/sysctrl.c b/arch/mips/lantiq/xway/sysctrl.c
index 2b15491..9147c4b 100644
--- a/arch/mips/lantiq/xway/sysctrl.c
+++ b/arch/mips/lantiq/xway/sysctrl.c
@@ -78,7 +78,15 @@
 #define pmu_w32(x, y)	ltq_w32((x), pmu_membase + (y))
 #define pmu_r32(x)	ltq_r32(pmu_membase + (x))
 
+#define XBAR_ALWAYS_LAST	0x430
+#define XBAR_FPI_BURST_EN	BIT(1)
+#define XBAR_AHB_BURST_EN	BIT(2)
+
+#define xbar_w32(x, y)	ltq_w32((x), ltq_xbar_membase + (y))
+#define xbar_r32(x)	ltq_r32(ltq_xbar_membase + (x))
+
 static void __iomem *pmu_membase;
+static void __iomem *ltq_xbar_membase;
 void __iomem *ltq_cgu_membase;
 void __iomem *ltq_ebu_membase;
 
@@ -179,6 +187,16 @@ static void pci_ext_disable(struct clk *clk)
 	ltq_cgu_w32((1 << 31) | (1 << 30), pcicr);
 }
 
+static void xbar_fpi_burst_disable(void)
+{
+	u32 reg;
+
+	/* bit 1 as 1 --burst; bit 1 as 0 -- single */
+	reg = xbar_r32(XBAR_ALWAYS_LAST);
+	reg &= ~XBAR_FPI_BURST_EN;
+	xbar_w32(reg, XBAR_ALWAYS_LAST);
+}
+
 /* enable a clockout source */
 static int clkout_enable(struct clk *clk)
 {
@@ -328,6 +346,26 @@ void __init ltq_soc_init(void)
 	if (!pmu_membase || !ltq_cgu_membase || !ltq_ebu_membase)
 		panic("Failed to remap core resources");
 
+
+	if (of_machine_is_compatible("lantiq,vr9")) {
+		struct resource res_xbar;
+		struct device_node *np_xbar =
+		of_find_compatible_node(NULL, NULL,
+			"lantiq,xbar-xway");
+		if (!np_xbar)
+			panic("Failed to load xbar nodes from devicetree");
+		if (of_address_to_resource(np_pmu, 0, &res_xbar))
+			panic("Failed to get xbar resources");
+		if (request_mem_region(res_xbar.start, resource_size(&res_xbar),
+			res_xbar.name) < 0)
+			panic("Failed to get xbar resources");
+
+		ltq_xbar_membase = ioremap_nocache(res_xbar.start,
+		resource_size(&res_xbar));
+		if (!ltq_xbar_membase)
+			panic("Failed to remap xbar resources");
+	}
+
 	/* make sure to unprotect the memory region where flash is located */
 	ltq_ebu_w32(ltq_ebu_r32(LTQ_EBU_BUSCON0) & ~EBU_WRDIS, LTQ_EBU_BUSCON0);
 
@@ -385,4 +423,7 @@ void __init ltq_soc_init(void)
 		clkdev_add_static(ltq_danube_cpu_hz(), ltq_danube_fpi_hz(),
 				ltq_danube_fpi_hz(), ltq_danube_pp32_hz());
 	}
+
+	if (of_machine_is_compatible("lantiq,vr9"))
+		xbar_fpi_burst_disable();
 }
-- 
1.7.10.4

^ permalink raw reply related	[flat|nested] 5+ messages in thread

* Re: [PATCH 4/4] arch: mips: lantiq: disable xbar fpi burst mode
  2015-11-04 12:14 ` [PATCH 4/4] arch: mips: lantiq: disable xbar fpi burst mode John Crispin
@ 2015-11-04 20:06   ` Sergei Shtylyov
  0 siblings, 0 replies; 5+ messages in thread
From: Sergei Shtylyov @ 2015-11-04 20:06 UTC (permalink / raw)
  To: John Crispin, Ralf Baechle; +Cc: linux-mips

Hello.

On 11/4/2015 3:14 PM, John Crispin wrote:

> Signed-off-by: John Crispin <blogic@openwrt.org>
> ---
>   arch/mips/lantiq/xway/sysctrl.c |   41 +++++++++++++++++++++++++++++++++++++++
>   1 file changed, 41 insertions(+)
>
> diff --git a/arch/mips/lantiq/xway/sysctrl.c b/arch/mips/lantiq/xway/sysctrl.c
> index 2b15491..9147c4b 100644
> --- a/arch/mips/lantiq/xway/sysctrl.c
> +++ b/arch/mips/lantiq/xway/sysctrl.c
[...]
> @@ -179,6 +187,16 @@ static void pci_ext_disable(struct clk *clk)
>   	ltq_cgu_w32((1 << 31) | (1 << 30), pcicr);
>   }
>
> +static void xbar_fpi_burst_disable(void)
> +{
> +	u32 reg;
> +
> +	/* bit 1 as 1 --burst; bit 1 as 0 -- single */
> +	reg = xbar_r32(XBAR_ALWAYS_LAST);
> +	reg &= ~XBAR_FPI_BURST_EN;
> +	xbar_w32(reg, XBAR_ALWAYS_LAST);
> +}
> +
>   /* enable a clockout source */
>   static int clkout_enable(struct clk *clk)
>   {
> @@ -328,6 +346,26 @@ void __init ltq_soc_init(void)
>   	if (!pmu_membase || !ltq_cgu_membase || !ltq_ebu_membase)
>   		panic("Failed to remap core resources");
>
> +

    Why two empty lines?

> +	if (of_machine_is_compatible("lantiq,vr9")) {
> +		struct resource res_xbar;
> +		struct device_node *np_xbar =
> +		of_find_compatible_node(NULL, NULL,
> +			"lantiq,xbar-xway");

    This needs to be indented more to the right and empty line needs to be 
added afterwards.

> +		if (!np_xbar)
> +			panic("Failed to load xbar nodes from devicetree");
> +		if (of_address_to_resource(np_pmu, 0, &res_xbar))
> +			panic("Failed to get xbar resources");
> +		if (request_mem_region(res_xbar.start, resource_size(&res_xbar),
> +			res_xbar.name) < 0)
> +			panic("Failed to get xbar resources");
> +
> +		ltq_xbar_membase = ioremap_nocache(res_xbar.start,
> +		resource_size(&res_xbar));

    This line needs to be indented more to the right.

[...]

MBR, Sergei

^ permalink raw reply	[flat|nested] 5+ messages in thread

end of thread, other threads:[~2015-11-04 20:06 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2015-11-04 12:14 [PATCH 1/4] arch: mips: lantiq: return correct value for fpi clock on ar9 John Crispin
2015-11-04 12:14 ` [PATCH 2/4] arch: mips: lantiq: initialize the USB core on boot John Crispin
2015-11-04 12:14 ` [PATCH 3/4] arch: mips: lantiq: force the crossbar to big endian John Crispin
2015-11-04 12:14 ` [PATCH 4/4] arch: mips: lantiq: disable xbar fpi burst mode John Crispin
2015-11-04 20:06   ` Sergei Shtylyov

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox