diff mbox

[U-Boot] omap4_panda: Initialize the USB phy

Message ID 4EE75C6A.1060200@ti.com
State Changes Requested
Delegated to: Tom Rini
Headers show

Commit Message

Aneesh V Dec. 13, 2011, 2:08 p.m. UTC
Hi Chris,

On Tuesday 13 December 2011 06:34 PM, clalancette@gmail.com wrote:
> From: Chris Lalancette<clalancette@gmail.com>
>
> During misc_init_r, make sure to setup the clocks
> properly for the USB hub on the pandaboard.  With
> this in place, the USB hub and the ethernet works
> on the pandaboard.

I had created a similar patch a long time back. It's only now I realize
that I hadn't submitted it!! Anyway, here it is. I think there are a
couple of things that can be re-used to improve your patch.
1) You might want to replace the magic numbers with the symbols.
2) Run-time identification of the phy type.

 From c41559a4353a9b0822de7055fc11923f260de9ac Mon Sep 17 00:00:00 2001
From: Aneesh V <aneesh@ti.com>
Date: Wed, 17 Aug 2011 17:43:20 +0530
Subject: [PATCH] omap4: usb clock init for Panda board

Signed-off-by: Aneesh V <aneesh@ti.com>
---
  arch/arm/include/asm/arch-omap4/clocks.h |   29 ++++++++++++++-
  board/ti/panda/panda.c                   |   61 
++++++++++++++++++++++++++++++
  2 files changed, 89 insertions(+), 1 deletions(-)

Comments

Tom Rini Dec. 13, 2011, 4:43 p.m. UTC | #1
On Tue, Dec 13, 2011 at 7:08 AM, Aneesh V <aneesh@ti.com> wrote:
> Hi Chris,
>
>
> On Tuesday 13 December 2011 06:34 PM, clalancette@gmail.com wrote:
>>
>> From: Chris Lalancette<clalancette@gmail.com>
>>
>> During misc_init_r, make sure to setup the clocks
>> properly for the USB hub on the pandaboard.  With
>> this in place, the USB hub and the ethernet works
>> on the pandaboard.
>
>
> I had created a similar patch a long time back. It's only now I realize
> that I hadn't submitted it!! Anyway, here it is. I think there are a
> couple of things that can be re-used to improve your patch.
> 1) You might want to replace the magic numbers with the symbols.
> 2) Run-time identification of the phy type.

I take this as a "don't take either patch as-is" request and will
await a V2 from one of you before putting it into u-boot-ti/master and
sending a request to Albert.  Thanks!
clalancette@gmail.com Dec. 13, 2011, 6:18 p.m. UTC | #2
On Tue, Dec 13, 2011 at 11:43 AM, Tom Rini <tom.rini@gmail.com> wrote:
>> I had created a similar patch a long time back. It's only now I realize
>> that I hadn't submitted it!! Anyway, here it is. I think there are a
>> couple of things that can be re-used to improve your patch.
>> 1) You might want to replace the magic numbers with the symbols.
>> 2) Run-time identification of the phy type.
>
> I take this as a "don't take either patch as-is" request and will
> await a V2 from one of you before putting it into u-boot-ti/master and
> sending a request to Albert.  Thanks!

Right, I will take some combination of Aneesh's patch and my own and
resubmit soon.

Thanks,
Chris Lalancette
diff mbox

Patch

diff --git a/arch/arm/include/asm/arch-omap4/clocks.h 
b/arch/arm/include/asm/arch-omap4/clocks.h
index 374e064..6092e67 100644
--- a/arch/arm/include/asm/arch-omap4/clocks.h
+++ b/arch/arm/include/asm/arch-omap4/clocks.h
@@ -467,7 +467,12 @@  struct omap4_prcm_regs {
  	u32 prm_vc_cfg_channel;
  	u32 prm_vc_cfg_i2c_mode;
  	u32 prm_vc_cfg_i2c_clk;
-
+	u32 pad216[2392];
+	u32 altclksrc;
+	u32 pad217[128];
+	u32 auxclk1;
+	u32 auxclk2;
+	u32 auxclk3;
  };

  /* DPLL register offsets */
@@ -628,6 +633,28 @@  struct omap4_prcm_regs {
  #define PRM_VC_VAL_BYPASS_DATA_SHIFT		16
  #define PRM_VC_VAL_BYPASS_DATA_MASK		0xFF

+/* AUXCLKx reg fields */
+#define AUXCLK_ENABLE_MASK		(1 << 8)
+#define AUXCLK_SRCSELECT_SHIFT		1
+#define AUXCLK_SRCSELECT_MASK		(3 << 1)
+#define AUXCLK_CLKDIV_SHIFT		16
+#define AUXCLK_CLKDIV_MASK		(0xF << 16)
+
+#define AUXCLK_SRCSELECT_SYS_CLK	0
+#define AUXCLK_SRCSELECT_CORE_DPLL	1
+#define AUXCLK_SRCSELECT_PER_DPLL	2
+#define AUXCLK_SRCSELECT_ALTERNATE	3
+
+#define AUXCLK_CLKDIV_2		1
+#define AUXCLK_CLKDIV_16		0xF
+
+/* ALTCLKSRC */
+#define ALTCLKSRC_MODE_MASK		3
+#define ALTCLKSRC_ENABLE_INT_MASK	4
+#define ALTCLKSRC_ENABLE_EXT_MASK	8
+
+#define ALTCLKSRC_MODE_ACTIVE		1
+
  /* SMPS */
  #define SMPS_I2C_SLAVE_ADDR	0x12
  #define SMPS_REG_ADDR_VCORE1	0x55
diff --git a/board/ti/panda/panda.c b/board/ti/panda/panda.c
index 9afed80..0c0b97a 100644
--- a/board/ti/panda/panda.c
+++ b/board/ti/panda/panda.c
@@ -24,15 +24,75 @@ 
  #include <common.h>
  #include <asm/arch/sys_proto.h>
  #include <asm/arch/mmc_host_def.h>
+#include <asm/arch/clocks.h>
+#include <asm/arch/gpio.h>

  #include "panda_mux_data.h"

+#define PANDA_ULPI_PHY_TYPE_GPIO	182
+
  DECLARE_GLOBAL_DATA_PTR;

  const struct omap_sysinfo sysinfo = {
  	"Board: OMAP4 Panda\n"
  };

+static void usb_clk_init(void)
+{
+	u32 auxclk, altclksrc;
+	int phy_type;
+
+	/* EHCI is not supported on ES1.0 */
+	if (omap_revision() == OMAP4430_ES1_0)
+		return;
+
+	omap_set_gpio_direction(PANDA_ULPI_PHY_TYPE_GPIO, 1);
+	phy_type = omap_get_gpio_datain(PANDA_ULPI_PHY_TYPE_GPIO);
+
+	if (phy_type == 1) {
+		/* ULPI PHY supplied by auxclk3 derived from sys_clk */
+		debug("ULPI PHY supplied by auxclk3\n");
+
+		auxclk = readl(&prcm->auxclk3);
+		/* Select sys_clk */
+		auxclk &= ~AUXCLK_SRCSELECT_MASK;
+		auxclk |=  AUXCLK_SRCSELECT_SYS_CLK <<
+				AUXCLK_SRCSELECT_SHIFT;
+		/* Set the divisor to 2 */
+		auxclk &= ~AUXCLK_CLKDIV_MASK;
+		auxclk |= AUXCLK_CLKDIV_2 << AUXCLK_CLKDIV_SHIFT;
+		/* Request auxilary clock #3 */
+		auxclk |= AUXCLK_ENABLE_MASK;
+
+		writel(auxclk, &prcm->auxclk3);
+	} else {
+		/* ULPI PHY supplied by auxclk1 derived from PER dpll */
+		debug("ULPI PHY supplied by auxclk1\n");
+
+		auxclk = readl(&prcm->auxclk1);
+		/* Select per DPLL */
+		auxclk &= ~AUXCLK_SRCSELECT_MASK;
+		auxclk |=  AUXCLK_SRCSELECT_PER_DPLL <<
+				AUXCLK_SRCSELECT_SHIFT;
+		/* Set the divisor to 16 */
+		auxclk &= ~AUXCLK_CLKDIV_MASK;
+		auxclk |= AUXCLK_CLKDIV_16 << AUXCLK_CLKDIV_SHIFT;
+		/* Request auxilary clock #3 */
+		auxclk |= AUXCLK_ENABLE_MASK;
+
+		writel(auxclk, &prcm->auxclk1);
+	}
+
+	altclksrc = readl(&prcm->altclksrc);
+
+	/* Activate alternate system clock supplier */
+	altclksrc &= ~ALTCLKSRC_MODE_MASK;
+	altclksrc |= ALTCLKSRC_MODE_ACTIVE;
+	/* enable clocks */
+	altclksrc |= ALTCLKSRC_ENABLE_INT_MASK | ALTCLKSRC_ENABLE_EXT_MASK;
+
+	writel(altclksrc, &prcm->altclksrc);
+}
  /**
   * @brief board_init
   *
@@ -41,6 +101,7 @@  const struct omap_sysinfo sysinfo = {
  int board_init(void)
  {
  	gpmc_init();
+	usb_clk_init();

  	gd->bd->bi_arch_number = MACH_TYPE_OMAP4_PANDA;
  	gd->bd->bi_boot_params = (0x80000000 + 0x100); /* boot param addr */