diff mbox

[U-Boot,v2,1/4] ehci-omap: Clean up added ehci-omap.c

Message ID CAAL8m4z1pG_9o7-VTwURDJKy+wdX9oe98D5iR7Ant3EGZiySSA@mail.gmail.com
State Superseded
Headers show

Commit Message

Govindraj Jan. 17, 2012, 6:10 a.m. UTC
On Thu, Jan 12, 2012 at 4:22 PM, Govindraj <govindraj.ti@gmail.com> wrote:
> On Thu, Jan 12, 2012 at 2:53 PM, Igor Grinberg <grinberg@compulab.co.il> wrote:
>> Hi Govindraj,
>>
>> On 01/12/12 07:45, Govindraj wrote:
>>> Hi Igor,
>>>
>>> On Wed, Jan 11, 2012 at 8:33 PM, Igor Grinberg <grinberg@compulab.co.il> wrote:
>>>> Hi Guys,
>>>>
>>>> On 01/11/12 16:34, Marek Vasut wrote:
>>>>>> On Wed, Jan 11, 2012 at 6:58 PM, Marek Vasut <marek.vasut@gmail.com> wrote:
>>>>>>>> On Wed, Jan 11, 2012 at 6:16 PM, Marek Vasut <marek.vasut@gmail.com> wrote:
>>>>>>>>>> On Wed, Jan 11, 2012 at 4:22 PM, Marek Vasut <marek.vasut@gmail.com>
>>>>> wrote:
>>>>>>>>>>>> Hi Marek,
>>>>>>>>>>>>
>>>>>>>>>>>> Thanks for you review.
>>>>>>>>>>>>
>>>>>>>>>>>> On Tue, Jan 10, 2012 at 9:37 PM, Marek Vasut
>>>>>>>>>>>> <marek.vasut@gmail.com>
>>>>>>>
>>>>>>> wrote:
>>>>>>>>>>>>>> From: "Govindraj.R" <govindraj.raja@ti.com>
>>>>>>>>>>>>>>
>>>>>>>>>>>>>> Clean up added ehci-omap.c and make it generic for re-use
>>>>>>>>>>>>>> across soc having same ehci ip block. Also pass the modes to
>>>>>>>>>>>>>> be configured and configure the ports accordingly. All usb
>>>>>>>>>>>>>> layers are not cache aligned till then keep cache off for usb
>>>>>>>>>>>>>> ops as ehci will use internally dma for all usb ops.
>>>>>>>>>>>>>>
>>>>>>>>>>>>>> * Add a generic common header ehci-omap.h having common ip
>>>>>>>>>>>>>> block data and reg shifts.
>>>>>>>>>>>>>> * Rename and modify ehci-omap3 to ehci.h retain only
>>>>>>>>>>>>>> conflicting sysc reg shifts remove others and move to common
>>>>>>>>>>>>>> header file.
>>>>>>>>>>>>>
>>>>>>>>>>>>> Don't reimplement the ulpi stuff ... there's already some ulpi
>>>>>>>>>>>>> stuff in uboot that needs fixing, so fix it and use it.
>>>>>>>>>>>>
>>>>>>>>>>>> I am not implementing any ulpi stuff I am just configuring OMAP on
>>>>>>>>>>>> soc usb host controller (ehci). All the configuration stuff
>>>>>>>>>>>> is OMAP specific things which are done in ehci-omap.c file
>>>>>>>>>>>>
>>>>>>>>>>>> stuffs done are like soft-reset, port mode to be used and putting
>>>>>>>>>>>> port in no -idle mode(omap specific pm implementation) etc.
>>>>>>>>>>>
>>>>>>>>>>> This stuff:
>>>>>>>>>>>
>>>>>>>>>>> +/* ULPI */
>>>>>>>>>>> +#define ULPI_SET(a)                                    (a + 1)
>>>>>>>>>>> +#define ULPI_CLR(a)                                    (a + 2)
>>>>>>>>>>> +#define ULPI_FUNC_CTRL                                 0x04
>>>>>>>>>>> +#define ULPI_FUNC_CTRL_RESET                           (1 << 5)
>>>>>>>>>>>
>>>>>>>>>>> is just accidentally conforming to ULPI spec?
>>>>>>>>>>
>>>>>>>>>> These are for configuring INSNREG05_ULPI reg in EHCI reg map
>>>>>>>>>> of omap while configuring in ulpi-phy mode.
>>>>>>>>>>
>>>>>>>>>> looking into struct ulpi_regs {..}
>>>>>>>>>> then it doesn't map this configuration.
>>>>>>>>>
>>>>>>>>> Can you point me to some documentation about this please? It's not
>>>>>>>>> that I don't trust you, I'd rather prefer to avoid unnecessary
>>>>>>>>> duplication.
>>>>>>>>
>>>>>>>> Yes that would be fine.
>>>>>>>>
>>>>>>>> You can download the omap4460 public trm from here:
>>>>>>>>
>>>>>>>> http://www.ti.com/pdfs/wtbu/OMAP4460_ES.1x_PUBLIC_TRM_vM.zip
>>>>>>>>
>>>>>>>> Go to chapter 23.11.6.6.1 EHCI Register Summary
>>>>>>>> (page number 5171 and 5186/87)
>>>>>>>
>>>>>>> Sure, but the macro above looks more like 23.11.6.3, doesn't it ? And for
>>>>>>> that purpose, the struct ulpi_regs is fitting ok.
>>>>>>>
>>>>>>> Actually ... can you check the ulpi_read and ulpi_write stuff that's
>>>>>>> already in u-boot and explain why they can not be used with this port?
>>>>>>
>>>>>> echi-omap.c is no where writing to those registers
>>>>>> and the macro was used only to configure INSNREG05_ULPI reg in EHCI reg map
>>>>>>
>>>>>> reg map in 23.11.6.3 used only for a external ulpi-phy communication.
>>>>>> and debug purpose(to view vid, pid etc) and to hack external phy
>>>>>> configuration through ulpi commands
>>>>>> from omap - usb host controller point of view only needs
>>>>>> INSNREG05_ULPI reg in EHCI reg configuration
>>>>>> rest on soc host controller takes care of it.
>>>>>
>>>>> Can someone else comment on this? I think I don't understand well (as I'm not
>>>>> OMAP guy).
>>>>
>>>> Well, it is on my list, actually,
>>>> but I will be able to get to it only in a couple of days.
>>>> (I'm really busy right now).
>>>>
>>>
>>> Could you please let me know what exactly that you will be
>>> updating?
>>>
>>> So that I can accordingly post my v3 of this patch fixing comments
>>> from Marek Vasut <marek.vasut@gmail.com>
>>
>> Well, I did not say, I'm going to update anything.
>> What I meant is that I'm going to look into TI's documentation
>> regarding EHCI and the ULPI to understand the dependencies and see
>> how your code meets those and if the generic ULPI layer can be used
>> for that.
>>
>
> okay, Thanks,
>
>> So to lower the work load from from you, I'd suggest you to wait
>> till Monday (if you can of course) to let me look into this.
>

Gentle Ping.

And just to clarify further there is no code duplication for ulpi read writes
in ehci-omap.c done with this patch.
Patch intends only in configuring ehci to right modes as specified by
board file.  Modes possible are hsic_mode, tll_mode, ulpi_phy mode.

This patch is derived with reference to linux kernel and even there
we can see that no ulpi_reg map registers are used and only ehci
is configured is respective mode as passed by board data.

Here [1] is the patch fixing Marek Vasut <marek.vasut@gmail.com>
comments.

This corrected patch along with dependent patch from
Ilya Yanok <yanok@emcraft.com>
[PATCH V4 1/2] ehci-omap: driver for EHCI host on OMAP3

Is available here:
git://gitorious.org/denx_u-boot/denx_uboot_omap.git v2_ehci_omap

--
Thanks,
Govindraj.R

[1]:

From 56b1b94128495ed4bf83e2f20f3884833e2aa082 Mon Sep 17 00:00:00 2001
From: "Govindraj.R" <govindraj.raja@ti.com>
Date: Tue, 27 Dec 2011 14:53:12 +0530
Subject: [PATCH 2/6] ehci-omap: Clean up added ehci-omap.c

Clean up added ehci-omap.c and make it generic for re-use across
soc having same ehci ip block. Also pass the modes to be configured
and configure the ports accordingly. All usb layers are not cache
aligned till then keep cache off for usb ops as ehci will use
internally dma for all usb ops.

* Add a generic common header ehci-omap.h having common ip block
  data and reg shifts.
* Rename and modify ehci-omap3 to ehci.h retain only conflicting
  sysc reg shifts remove others and move to common header file.

Signed-off-by: Govindraj.R <govindraj.raja@ti.com>
---
 arch/arm/include/asm/arch-omap3/ehci.h       |   55 ++++++
 arch/arm/include/asm/arch-omap3/ehci_omap3.h |   58 -------
 arch/arm/include/asm/arch-omap4/ehci.h       |   49 ++++++
 arch/arm/include/asm/ehci-omap.h             |  147 +++++++++++++++++
 drivers/usb/host/ehci-omap.c                 |  228 +++++++++++++++++++-------
 5 files changed, 423 insertions(+), 114 deletions(-)
 create mode 100644 arch/arm/include/asm/arch-omap3/ehci.h
 delete mode 100644 arch/arm/include/asm/arch-omap3/ehci_omap3.h
 create mode 100644 arch/arm/include/asm/arch-omap4/ehci.h
 create mode 100644 arch/arm/include/asm/ehci-omap.h

 	return 0;
@@ -72,31 +151,31 @@ static inline void omap_ehci_phy_reset(int on, int delay)
 #endif

 /* Reset is needed otherwise the kernel-driver will throw an error. */
-int ehci_hcd_stop(void)
+int omap_ehci_hcd_stop(void)
 {
-	debug("Resetting OMAP3 EHCI\n");
+	debug("Resetting OMAP EHCI\n");
 	omap_ehci_phy_reset(1, 0);
-	writel(OMAP_UHH_SYSCONFIG_SOFTRESET,
-			OMAP3_UHH_BASE + OMAP_UHH_SYSCONFIG);
-	/* disable USB clocks */
-	struct prcm *prcm_base = (struct prcm *)PRCM_BASE;
-	sr32(&prcm_base->iclken_usbhost, 0, 1, 0);
-	sr32(&prcm_base->fclken_usbhost, 0, 2, 0);
-	sr32(&prcm_base->iclken3_core, 2, 1, 0);
-	sr32(&prcm_base->fclken3_core, 2, 1, 0);
+
+	if (omap_uhh_reset() < 0)
+		return -1;
+
+	if (omap_ehci_tll_reset() < 0)
+		return -1;
+
 	return 0;
 }

 /*
- * Initialize the OMAP3 EHCI controller and PHY.
- * Based on "drivers/usb/host/ehci-omap.c" from Linux 2.6.37.
+ * Initialize the OMAP EHCI controller and PHY.
+ * Based on "drivers/usb/host/ehci-omap.c" from Linux 3.1
  * See there for additional Copyrights.
  */
-int ehci_hcd_init(void)
+int omap_ehci_hcd_init(struct omap_usbhs_board_data *usbhs_pdata)
 {
-	int ret;
+	int ret = 0;
+	unsigned int i, reg = 0, rev = 0, tll_cnt = 0;

-	debug("Initializing OMAP3 EHCI\n");
+	debug("Initializing OMAP EHCI\n");

 	ret = board_usb_init();
 	if (ret < 0)
@@ -105,52 +184,89 @@ int ehci_hcd_init(void)
 	/* Put the PHY in RESET */
 	omap_ehci_phy_reset(1, 10);

-	struct prcm *prcm_base = (struct prcm *)PRCM_BASE;
-	/* Enable USBHOST_L3_ICLK (USBHOST_MICLK) */
-	sr32(&prcm_base->iclken_usbhost, 0, 1, 1);
-	/*
-	 * Enable USBHOST_48M_FCLK (USBHOST_FCLK1)
-	 * and USBHOST_120M_FCLK (USBHOST_FCLK2)
-	 */
-	sr32(&prcm_base->fclken_usbhost, 0, 2, 3);
-	/* Enable USBTTL_ICLK */
-	sr32(&prcm_base->iclken3_core, 2, 1, 1);
-	/* Enable USBTTL_FCLK */
-	sr32(&prcm_base->fclken3_core, 2, 1, 1);
-	debug("USB clocks enabled\n");
+	ret = omap_uhh_reset();
+	if (ret < 0)
+		return ret;

-	/* perform TLL soft reset, and wait until reset is complete */
-	writel(OMAP_USBTLL_SYSCONFIG_SOFTRESET,
-		OMAP3_USBTLL_BASE + OMAP_USBTLL_SYSCONFIG);
-	/* Wait for TLL reset to complete */
-	while (!(readl(OMAP3_USBTLL_BASE + OMAP_USBTLL_SYSSTATUS)
-			& OMAP_USBTLL_SYSSTATUS_RESETDONE))
-		;
-	debug("TLL reset done\n");
+	ret = omap_ehci_tll_reset();
+	if (ret)
+		return ret;

 	writel(OMAP_USBTLL_SYSCONFIG_ENAWAKEUP |
 		OMAP_USBTLL_SYSCONFIG_SIDLEMODE |
-		OMAP_USBTLL_SYSCONFIG_CACTIVITY,
-		OMAP3_USBTLL_BASE + OMAP_USBTLL_SYSCONFIG);
+		OMAP_USBTLL_SYSCONFIG_CACTIVITY, &usbtll->sysc);

 	/* Put UHH in NoIdle/NoStandby mode */
-	writel(OMAP_UHH_SYSCONFIG_ENAWAKEUP
-		| OMAP_UHH_SYSCONFIG_SIDLEMODE
-		| OMAP_UHH_SYSCONFIG_CACTIVITY
-		| OMAP_UHH_SYSCONFIG_MIDLEMODE,
-		OMAP3_UHH_BASE + OMAP_UHH_SYSCONFIG);
-
-	/* setup burst configurations */
-	writel(OMAP_UHH_HOSTCONFIG_INCR4_BURST_EN
-		| OMAP_UHH_HOSTCONFIG_INCR8_BURST_EN
-		| OMAP_UHH_HOSTCONFIG_INCR16_BURST_EN,
-		OMAP3_UHH_BASE + OMAP_UHH_HOSTCONFIG);
+	writel(OMAP_UHH_SYSCONFIG_VAL, &uhh->sysc);
+
+	/* setup ULPI bypass and burst configurations */
+	clrsetbits_le32(&reg, OMAP_UHH_HOSTCONFIG_INCRX_ALIGN_EN,
+		(OMAP_UHH_HOSTCONFIG_INCR4_BURST_EN |
+		OMAP_UHH_HOSTCONFIG_INCR8_BURST_EN |
+		OMAP_UHH_HOSTCONFIG_INCR16_BURST_EN));
+
+	rev = readl(&uhh->rev);
+	if (rev == OMAP_USBHS_REV1) {
+		if (is_ehci_phy_mode(usbhs_pdata->port_mode[0]))
+			clrbits_le32(&reg, OMAP_UHH_HOSTCONFIG_ULPI_P1_BYPASS);
+		else
+			setbits_le32(&reg, OMAP_UHH_HOSTCONFIG_ULPI_P1_BYPASS);
+
+		if (is_ehci_phy_mode(usbhs_pdata->port_mode[1]))
+			clrbits_le32(&reg, OMAP_UHH_HOSTCONFIG_ULPI_P2_BYPASS);
+		else
+			setbits_le32(&reg, OMAP_UHH_HOSTCONFIG_ULPI_P1_BYPASS);
+
+		if (is_ehci_phy_mode(usbhs_pdata->port_mode[2]))
+			clrbits_le32(&reg, OMAP_UHH_HOSTCONFIG_ULPI_P3_BYPASS);
+		else
+			setbits_le32(&reg, OMAP_UHH_HOSTCONFIG_ULPI_P1_BYPASS);
+
+		tll_cnt = OMAP_REV1_TLL_CHANNEL_COUNT;
+	} else if (rev == OMAP_USBHS_REV2) {
+
+		clrsetbits_le32(&reg, (OMAP_P1_MODE_CLEAR | OMAP_P2_MODE_CLEAR),
+					OMAP4_UHH_HOSTCONFIG_APP_START_CLK);
+
+		/* Clear port mode fields for PHY mode*/
+
+		if (is_ehci_hsic_mode(usbhs_pdata->port_mode[0]))
+			setbits_le32(&reg, OMAP_P1_MODE_HSIC);
+
+		if (is_ehci_hsic_mode(usbhs_pdata->port_mode[1]))
+			setbits_le32(&reg, OMAP_P2_MODE_HSIC);
+
+		tll_cnt = OMAP_REV2_TLL_CHANNEL_COUNT;
+	}
+
+	debug("OMAP UHH_REVISION 0x%x\n", rev);
+	writel(reg, &uhh->hostconfig);
+
+	if (is_ehci_hsic_mode(usbhs_pdata->port_mode[0]) ||
+			is_ehci_hsic_mode(usbhs_pdata->port_mode[1]))
+		omap_usbhs_hsic_init(tll_cnt);

 	omap_ehci_phy_reset(0, 10);

-	hccr = (struct ehci_hccr *)(OMAP3_EHCI_BASE);
-	hcor = (struct ehci_hcor *)(OMAP3_EHCI_BASE + 0x10);
+	/*
+	 * An undocumented "feature" in the OMAP3 EHCI controller,
+	 * causes suspended ports to be taken out of suspend when
+	 * the USBCMD.Run/Stop bit is cleared (for example when
+	 * we do ehci_bus_suspend).
+	 * This breaks suspend-resume if the root-hub is allowed
+	 * to suspend. Writing 1 to this undocumented register bit
+	 * disables this feature and restores normal behavior.
+	 */
+	writel(EHCI_INSNREG04_DISABLE_UNSUSPEND, &ehci->insreg04);
+
+	for (i = 0; i < OMAP_HS_USB_PORTS; i++)
+		if (is_ehci_phy_mode(usbhs_pdata->port_mode[i]))
+			omap_ehci_soft_phy_reset(i);
+
+	dcache_disable();
+	hccr = (struct ehci_hccr *)(OMAP_EHCI_BASE);
+	hcor = (struct ehci_hcor *)(OMAP_EHCI_BASE + 0x10);

-	debug("OMAP3 EHCI init done\n");
+	debug("OMAP EHCI init done\n");
 	return 0;
 }

Comments

Igor Grinberg Jan. 18, 2012, 5:51 p.m. UTC | #1
Hi Govindraj,

On 01/17/12 08:10, Govindraj wrote:
> 
> And just to clarify further there is no code duplication for ulpi read writes
> in ehci-omap.c done with this patch.

This is not just about code duplication,
this is also about using the ULPI framework instead of direct writes to the
ULPI PHYs.

> Patch intends only in configuring ehci to right modes as specified by
> board file.  Modes possible are hsic_mode, tll_mode, ulpi_phy mode.
> 
> This patch is derived with reference to linux kernel and even there
> we can see that no ulpi_reg map registers are used and only ehci
> is configured is respective mode as passed by board data.

This is not correct. They are used, see:
drivers/usb/host/ehci-omap.c file, omap_ehci_soft_phy_reset() function.
It does exactly the same, but yes it does not use the ULPI framework,
because in Linux currently, there is no generic enough ULPI framework,
so drivers can use it.
There were discussions about it and decided that until there is such
a framework, things can be done the way they are.

> 
> Here [1] is the patch fixing Marek Vasut <marek.vasut@gmail.com>
> comments.
> 
> This corrected patch along with dependent patch from
> Ilya Yanok <yanok@emcraft.com>
> [PATCH V4 1/2] ehci-omap: driver for EHCI host on OMAP3
> 
> Is available here:
> git://gitorious.org/denx_u-boot/denx_uboot_omap.git v2_ehci_omap
> 
> --
> Thanks,
> Govindraj.R
> 
> [1]:
> 
>>From 56b1b94128495ed4bf83e2f20f3884833e2aa082 Mon Sep 17 00:00:00 2001
> From: "Govindraj.R" <govindraj.raja@ti.com>
> Date: Tue, 27 Dec 2011 14:53:12 +0530
> Subject: [PATCH 2/6] ehci-omap: Clean up added ehci-omap.c
> 
> Clean up added ehci-omap.c and make it generic for re-use across
> soc having same ehci ip block. Also pass the modes to be configured
> and configure the ports accordingly. All usb layers are not cache
> aligned till then keep cache off for usb ops as ehci will use
> internally dma for all usb ops.
> 
> * Add a generic common header ehci-omap.h having common ip block
>   data and reg shifts.
> * Rename and modify ehci-omap3 to ehci.h retain only conflicting
>   sysc reg shifts remove others and move to common header file.
> 
> Signed-off-by: Govindraj.R <govindraj.raja@ti.com>
> ---
>  arch/arm/include/asm/arch-omap3/ehci.h       |   55 ++++++
>  arch/arm/include/asm/arch-omap3/ehci_omap3.h |   58 -------
>  arch/arm/include/asm/arch-omap4/ehci.h       |   49 ++++++
>  arch/arm/include/asm/ehci-omap.h             |  147 +++++++++++++++++
>  drivers/usb/host/ehci-omap.c                 |  228 +++++++++++++++++++-------
>  5 files changed, 423 insertions(+), 114 deletions(-)
>  create mode 100644 arch/arm/include/asm/arch-omap3/ehci.h
>  delete mode 100644 arch/arm/include/asm/arch-omap3/ehci_omap3.h
>  create mode 100644 arch/arm/include/asm/arch-omap4/ehci.h
>  create mode 100644 arch/arm/include/asm/ehci-omap.h
> 
> diff --git a/arch/arm/include/asm/arch-omap3/ehci.h
> b/arch/arm/include/asm/arch-omap3/ehci.h
> new file mode 100644
> index 0000000..d622363
> --- /dev/null
> +++ b/arch/arm/include/asm/arch-omap3/ehci.h
> @@ -0,0 +1,55 @@
> +/*
> + * (C) Copyright 2011
> + * Alexander Holler <holler@ahsoftware.de>
> + *
> + * Based on "drivers/usb/host/ehci-omap.c" from Linux 2.6.37
> + *
> + * See there for additional Copyrights.
> + *
> + * See file CREDITS for list of people who contributed to this
> + * project.
> + *
> + * This program is free software; you can redistribute it and/or
> + * modify it under the terms of the GNU General Public License as
> + * published by the Free Software Foundation; either version 2 of
> + * the License, or (at your option) any later version.
> + *
> + * This program is distributed in the hope that it will be useful,
> + * but WITHOUT ANY WARRANTY; without even the implied warranty of
> + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
> + * GNU General Public License for more details.
> + *
> + * You should have received a copy of the GNU General Public License
> + * along with this program; if not, write to the Free Software
> + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
> + * MA 02110-1301 USA
> + */
> +#ifndef _EHCI_H_
> +#define _EHCI_H_

hmmm... isn't it too generic?
I think you should have included a part of the path to the file,
so no namespace collision will occure.
something like _OMAP3_EHCI_H_?

> +
> +/* USB/EHCI registers */
> +#define OMAP_USBTLL_BASE				0x48062000UL
> +#define OMAP_UHH_BASE					0x48064000UL
> +#define OMAP_EHCI_BASE					0x48064800UL
> +
> +/* TLL Register Set */
> +#define OMAP_USBTLL_SYSCONFIG_SOFTRESET			(1 << 1)
> +#define OMAP_USBTLL_SYSCONFIG_ENAWAKEUP			(1 << 2)
> +#define OMAP_USBTLL_SYSCONFIG_SIDLEMODE			(1 << 3)
> +#define OMAP_USBTLL_SYSCONFIG_CACTIVITY			(1 << 8)
> +#define OMAP_USBTLL_SYSSTATUS_RESETDONE			1
> +
> +/* UHH Register Set */
> +#define OMAP_UHH_SYSCONFIG_SOFTRESET			(1 << 1)
> +#define OMAP_UHH_SYSCONFIG_CACTIVITY			(1 << 8)
> +#define OMAP_UHH_SYSCONFIG_SIDLEMODE			(1 << 3)
> +#define OMAP_UHH_SYSCONFIG_ENAWAKEUP			(1 << 2)
> +#define OMAP_UHH_SYSCONFIG_MIDLEMODE			(1 << 12)
> +#define OMAP_UHH_SYSSTATUS_EHCI_RESETDONE		(1 << 2)
> +
> +#define OMAP_UHH_SYSCONFIG_VAL		(OMAP_UHH_SYSCONFIG_CACTIVITY | \
> +					OMAP_UHH_SYSCONFIG_SIDLEMODE | \
> +					OMAP_UHH_SYSCONFIG_ENAWAKEUP | \
> +					OMAP_UHH_SYSCONFIG_MIDLEMODE)
> +
> +#endif /* _EHCI_H_ */
> diff --git a/arch/arm/include/asm/arch-omap3/ehci_omap3.h
> b/arch/arm/include/asm/arch-omap3/ehci_omap3.h
> deleted file mode 100644
> index cd01f50..0000000
> --- a/arch/arm/include/asm/arch-omap3/ehci_omap3.h
> +++ /dev/null
> @@ -1,58 +0,0 @@
> -/*
> - * (C) Copyright 2011
> - * Alexander Holler <holler@ahsoftware.de>
> - *
> - * Based on "drivers/usb/host/ehci-omap.c" from Linux 2.6.37
> - *
> - * See there for additional Copyrights.
> - *
> - * See file CREDITS for list of people who contributed to this
> - * project.
> - *
> - * This program is free software; you can redistribute it and/or
> - * modify it under the terms of the GNU General Public License as
> - * published by the Free Software Foundation; either version 2 of
> - * the License, or (at your option) any later version.
> - *
> - * This program is distributed in the hope that it will be useful,
> - * but WITHOUT ANY WARRANTY; without even the implied warranty of
> - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
> - * GNU General Public License for more details.
> - *
> - * You should have received a copy of the GNU General Public License
> - * along with this program; if not, write to the Free Software
> - * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
> - * MA 02110-1301 USA
> - */
> -#ifndef _EHCI_OMAP3_H_
> -#define _EHCI_OMAP3_H_
> -
> -/* USB/EHCI registers */
> -#define OMAP3_USBTLL_BASE				0x48062000UL
> -#define OMAP3_UHH_BASE					0x48064000UL
> -#define OMAP3_EHCI_BASE					0x48064800UL
> -
> -/* TLL Register Set */
> -#define	OMAP_USBTLL_SYSCONFIG				(0x10)
> -#define	OMAP_USBTLL_SYSCONFIG_SOFTRESET			(1 << 1)
> -#define	OMAP_USBTLL_SYSCONFIG_ENAWAKEUP			(1 << 2)
> -#define	OMAP_USBTLL_SYSCONFIG_SIDLEMODE			(1 << 3)
> -#define	OMAP_USBTLL_SYSCONFIG_CACTIVITY			(1 << 8)
> -
> -#define	OMAP_USBTLL_SYSSTATUS				(0x14)
> -#define	OMAP_USBTLL_SYSSTATUS_RESETDONE			(1 << 0)
> -
> -/* UHH Register Set */
> -#define	OMAP_UHH_SYSCONFIG				(0x10)
> -#define	OMAP_UHH_SYSCONFIG_SOFTRESET			(1 << 1)
> -#define	OMAP_UHH_SYSCONFIG_CACTIVITY			(1 << 8)
> -#define	OMAP_UHH_SYSCONFIG_SIDLEMODE			(1 << 3)
> -#define	OMAP_UHH_SYSCONFIG_ENAWAKEUP			(1 << 2)
> -#define	OMAP_UHH_SYSCONFIG_MIDLEMODE			(1 << 12)
> -
> -#define	OMAP_UHH_HOSTCONFIG				(0x40)
> -#define OMAP_UHH_HOSTCONFIG_INCR4_BURST_EN		(1 << 2)
> -#define OMAP_UHH_HOSTCONFIG_INCR8_BURST_EN		(1 << 3)
> -#define OMAP_UHH_HOSTCONFIG_INCR16_BURST_EN		(1 << 4)
> -
> -#endif /* _EHCI_OMAP3_H_ */
> diff --git a/arch/arm/include/asm/arch-omap4/ehci.h
> b/arch/arm/include/asm/arch-omap4/ehci.h
> new file mode 100644
> index 0000000..eaa82cf
> --- /dev/null
> +++ b/arch/arm/include/asm/arch-omap4/ehci.h
> @@ -0,0 +1,49 @@
> +/*
> + * OMAP EHCI port support
> + * Based on LINUX KERNEL
> + * drivers/usb/host/ehci-omap.c and drivers/mfd/omap-usb-host.c
> + *
> + * Copyright (C) 2011 Texas Instruments Incorporated - http://www.ti.com
> + * Author: Govindraj R <govindraj.raja@ti.com>
> + *
> + * This program is free software: you can redistribute it and/or modify
> + * it under the terms of the GNU General Public License version 2  of
> + * the License as published by the Free Software Foundation.
> + *
> + * This program is distributed in the hope that it will be useful,
> + * but WITHOUT ANY WARRANTY; without even the implied warranty of
> + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
> + * GNU General Public License for more details.
> + *
> + * You should have received a copy of the GNU General Public License
> + * along with this program. If not, see <http://www.gnu.org/licenses/>.
> + */
> +
> +#ifndef _EHCI_H
> +#define _EHCI_H

see what I mean? above you have _EHCI_H_ and here _EHCI_H...
That is too confusing...
IMO, something like _OMAP4_EHCI_H_ will do here.

> +
> +#define OMAP_EHCI_BASE				(OMAP44XX_L4_CORE_BASE + 0x64C00)
> +#define OMAP_UHH_BASE				(OMAP44XX_L4_CORE_BASE + 0x64000)
> +#define OMAP_USBTLL_BASE			(OMAP44XX_L4_CORE_BASE + 0x62000)
> +
> +/* UHH, TLL and opt clocks */
> +#define CM_L3INIT_HSUSBHOST_CLKCTRL		0x4A009358UL
> +
> +#define HSUSBHOST_CLKCTRL_CLKSEL_UTMI_P1_MASK	(1 << 24)
> +
> +/* TLL Register Set */
> +#define OMAP_USBTLL_SYSCONFIG_SIDLEMODE		(1 << 3)
> +#define OMAP_USBTLL_SYSCONFIG_ENAWAKEUP		(1 << 2)
> +#define OMAP_USBTLL_SYSCONFIG_SOFTRESET		(1 << 1)
> +#define OMAP_USBTLL_SYSCONFIG_CACTIVITY		(1 << 8)
> +#define OMAP_USBTLL_SYSSTATUS_RESETDONE		1
> +
> +#define OMAP_UHH_SYSCONFIG_SOFTRESET		1
> +#define OMAP_UHH_SYSSTATUS_EHCI_RESETDONE	(1 << 2)
> +#define OMAP_UHH_SYSCONFIG_NOIDLE		(1 << 2)
> +#define OMAP_UHH_SYSCONFIG_NOSTDBY		(1 << 4)
> +
> +#define OMAP_UHH_SYSCONFIG_VAL	(OMAP_UHH_SYSCONFIG_NOIDLE | \
> +					OMAP_UHH_SYSCONFIG_NOSTDBY)
> +
> +#endif /* _EHCI_H */
> diff --git a/arch/arm/include/asm/ehci-omap.h b/arch/arm/include/asm/ehci-omap.h
> new file mode 100644
> index 0000000..ac68db7
> --- /dev/null
> +++ b/arch/arm/include/asm/ehci-omap.h
> @@ -0,0 +1,147 @@
> +/*
> + * OMAP EHCI port support
> + * Based on LINUX KERNEL
> + * drivers/usb/host/ehci-omap.c and drivers/mfd/omap-usb-host.c
> + *
> + * Copyright (C) 2011 Texas Instruments Incorporated - http://www.ti.com*
> + * Author: Govindraj R <govindraj.raja@ti.com>
> + *
> + * This program is free software: you can redistribute it and/or modify
> + * it under the terms of the GNU General Public License version 2  of
> + * the License as published by the Free Software Foundation.
> + *
> + * This program is distributed in the hope that it will be useful,
> + * but WITHOUT ANY WARRANTY; without even the implied warranty of
> + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
> + * GNU General Public License for more details.
> + *
> + * You should have received a copy of the GNU General Public License
> + * along with this program. If not, see <http://www.gnu.org/licenses/>.
> + */
> +
> +#ifndef EHCI_H
> +#define EHCI_H

And even worth... now there are three of them!!!
No, this is not good... what about OMAP5 will it be EHCI__H?
Probably here, something like _OMAP_COMMON_EHCI_H_ will do?

> +
> +enum usbhs_omap_port_mode {
> +	OMAP_USBHS_PORT_MODE_UNUSED,
> +	OMAP_EHCI_PORT_MODE_PHY,
> +	OMAP_EHCI_PORT_MODE_TLL,
> +	OMAP_EHCI_PORT_MODE_HSIC,
> +};
> +
> +#ifdef CONFIG_SYS_USB_EHCI_MAX_ROOT_PORTS
> +#define OMAP_HS_USB_PORTS	CONFIG_SYS_USB_EHCI_MAX_ROOT_PORTS
> +#else
> +#define OMAP_HS_USB_PORTS	3
> +#endif
> +
> +#define is_ehci_phy_mode(x)	((x) == OMAP_EHCI_PORT_MODE_PHY)
> +#define is_ehci_tll_mode(x)	((x) == OMAP_EHCI_PORT_MODE_TLL)
> +#define is_ehci_hsic_mode(x)	((x) == OMAP_EHCI_PORT_MODE_HSIC)
> +
> +/* Values of UHH_REVISION - Note: these are not given in the TRM */
> +#define OMAP_USBHS_REV1					0x00000010 /* OMAP3 */
> +#define OMAP_USBHS_REV2					0x50700100 /* OMAP4 */
> +
> +/* UHH Register Set */
> +#define OMAP_UHH_HOSTCONFIG_INCR4_BURST_EN		(1 << 2)
> +#define OMAP_UHH_HOSTCONFIG_INCR8_BURST_EN		(1 << 3)
> +#define OMAP_UHH_HOSTCONFIG_INCR16_BURST_EN		(1 << 4)
> +#define OMAP_UHH_HOSTCONFIG_INCRX_ALIGN_EN		(1 << 5)
> +
> +#define OMAP_UHH_HOSTCONFIG_ULPI_P1_BYPASS		1
> +#define OMAP_UHH_HOSTCONFIG_ULPI_P2_BYPASS		(1 << 11)
> +#define OMAP_UHH_HOSTCONFIG_ULPI_P3_BYPASS		(1 << 12)
> +#define OMAP4_UHH_HOSTCONFIG_APP_START_CLK		(1 << 31)
> +
> +#define OMAP_P1_MODE_CLEAR				(3 << 16)
> +#define OMAP_P1_MODE_TLL				(1 << 16)
> +#define OMAP_P1_MODE_HSIC				(3 << 16)
> +#define OMAP_P2_MODE_CLEAR				(3 << 18)
> +#define OMAP_P2_MODE_TLL				(1 << 18)
> +#define OMAP_P2_MODE_HSIC				(3 << 18)
> +
> +/* EHCI Register Set */
> +#define EHCI_INSNREG04_DISABLE_UNSUSPEND		(1 << 5)
> +#define EHCI_INSNREG05_ULPI_CONTROL_SHIFT		31
> +#define EHCI_INSNREG05_ULPI_PORTSEL_SHIFT		24
> +#define EHCI_INSNREG05_ULPI_OPSEL_SHIFT			22
> +#define EHCI_INSNREG05_ULPI_REGADD_SHIFT		16
> +
> +#define OMAP_REV1_TLL_CHANNEL_COUNT			3
> +#define OMAP_REV2_TLL_CHANNEL_COUNT			2
> +
> +/* TLL Register Set */
> +#define OMAP_TLL_CHANNEL_CONF(num)			(0x004 * num)
> +#define OMAP_TLL_CHANNEL_CONF_DRVVBUS			(1 << 16)
> +#define OMAP_TLL_CHANNEL_CONF_CHRGVBUS			(1 << 15)
> +#define OMAP_TLL_CHANNEL_CONF_ULPINOBITSTUFF		(1 << 11)
> +#define OMAP_TLL_CHANNEL_CONF_CHANMODE_TRANSPARENT_UTMI	(2 << 1)
> +#define OMAP_TLL_CHANNEL_CONF_CHANEN			1
> +
> +/* ULPI */
> +#define ULPI_SET(a)					(a + 1)

This is the offset of each "set" register of ULPI PHY

> +#define ULPI_CLR(a)					(a + 2)

This is the offset of each "clear" register of ULPI PHY

> +#define ULPI_FUNC_CTRL					0x04

This is the offset of the "Function Control register" of the ULPI PHY
This is already defined as ulpi_regs.function_ctrl member in
include/usb/ulpi.h file.

> +#define ULPI_FUNC_CTRL_RESET				(1 << 5)

This is the reset bin inside the "Function Control register" of the ULPI PHY
This bit is already defined in the include/usb/ulpi.h file.

> +
> +struct omap_usbhs_board_data {
> +	enum usbhs_omap_port_mode port_mode[OMAP_HS_USB_PORTS];
> +};
> +
> +struct omap_usbtll {
> +	u32 rev;		/* 0x00 */
> +	u32 hwinfo;		/* 0x04 */
> +	u8 reserved1[0x8];
> +	u32 sysc;		/* 0x10 */
> +	u32 syss;		/* 0x14 */
> +	u32 irqst;		/* 0x18 */
> +	u32 irqen;		/* 0x1c */
> +	u8 reserved2[0x10];
> +	u32 shared_conf;	/* 0x30 */
> +	u8 reserved3[0xc];
> +	u32 channel_conf;	/* 0x40 */
> +};
> +
> +struct omap_uhh {
> +	u32 rev;	/* 0x00 */
> +	u32 hwinfo;	/* 0x04 */
> +	u8 reserved1[0x8];
> +	u32 sysc;	/* 0x10 */
> +	u32 syss;	/* 0x14 */
> +	u8 reserved2[0x28];
> +	u32 hostconfig;	/* 0x40 */
> +	u32 debugcsr;	/* 0x44 */
> +};
> +
> +struct omap_ehci {
> +	u32 hccapbase;		/* 0x00 */
> +	u32 hcsparams;		/* 0x04 */
> +	u32 hccparams;		/* 0x08 */
> +	u8 reserved1[0x04];
> +	u32 usbcmd;		/* 0x10 */
> +	u32 usbsts;		/* 0x14 */
> +	u32 usbintr;		/* 0x18 */
> +	u32 frindex;		/* 0x1c */
> +	u32 ctrldssegment;	/* 0x20 */
> +	u32 periodiclistbase;	/* 0x24 */
> +	u32 asysnclistaddr;	/* 0x28 */
> +	u8 reserved2[0x24];
> +	u32 configflag;		/* 0x50 */
> +	u32 portsc_i;		/* 0x54 */
> +	u8 reserved3[0x38];
> +	u32 insreg00;		/* 0x90 */
> +	u32 insreg01;		/* 0x94 */
> +	u32 insreg02;		/* 0x98 */
> +	u32 insreg03;		/* 0x9c */
> +	u32 insreg04;		/* 0xa0 */
> +	u32 insreg05_utmi_ulpi;	/* 0xa4 */
> +	u32 insreg06;		/* 0xa8 */
> +	u32 insreg07;		/* 0xac */
> +	u32 insreg08;		/* 0xb0 */
> +};
> +
> +int omap_ehci_hcd_init(struct omap_usbhs_board_data *usbhs_pdata);
> +int omap_ehci_hcd_stop(void);
> +
> +#endif /* EHCI_H */
> diff --git a/drivers/usb/host/ehci-omap.c b/drivers/usb/host/ehci-omap.c
> index 93d3bb7..01c22e6 100644
> --- a/drivers/usb/host/ehci-omap.c
> +++ b/drivers/usb/host/ehci-omap.c
> @@ -27,14 +27,93 @@
>   */
>  #include <common.h>
>  #include <usb.h>
> +#include <errno.h>
>  #include <asm/io.h>
>  #include <asm/gpio.h>
> -#include <asm/arch/clocks.h>
> -#include <asm/arch/clocks_omap3.h>
> -#include <asm/arch/ehci_omap3.h>
> -#include <asm/arch/sys_proto.h>
> +#include <asm/arch/ehci.h>
> +#include <asm/ehci-omap.h>
>  #include "ehci-core.h"
> 
> +static struct omap_uhh *const uhh = (struct omap_uhh *)OMAP_UHH_BASE;
> +static struct omap_usbtll *const usbtll = (struct omap_usbtll
> *)OMAP_USBTLL_BASE;
> +static struct omap_ehci *const ehci = (struct omap_ehci *)OMAP_EHCI_BASE;
> +
> +static int omap_uhh_reset(void)
> +{
> +	unsigned long init = get_timer(0);
> +
> +	/* perform UHH soft reset, and wait until reset is complete */
> +	writel(OMAP_UHH_SYSCONFIG_SOFTRESET, &uhh->sysc);
> +
> +	/* Wait for UHH reset to complete */
> +	while (!(readl(&uhh->syss) & OMAP_UHH_SYSSTATUS_EHCI_RESETDONE))
> +		if (get_timer(init) > CONFIG_SYS_HZ) {
> +			debug("OMAP UHH error: timeout resetting ehci\n");
> +			return -EL3RST;
> +		}
> +
> +	return 0;
> +}
> +
> +static int omap_ehci_tll_reset(void)
> +{
> +	unsigned long init = get_timer(0);
> +
> +	/* perform TLL soft reset, and wait until reset is complete */
> +	writel(OMAP_USBTLL_SYSCONFIG_SOFTRESET, &usbtll->sysc);
> +
> +	/* Wait for TLL reset to complete */
> +	while (!(readl(&usbtll->syss) & OMAP_USBTLL_SYSSTATUS_RESETDONE))
> +		if (get_timer(init) > CONFIG_SYS_HZ) {
> +			debug("OMAP EHCI error: timeout resetting TLL\n");
> +			return -EL3RST;
> +	}
> +
> +	return 0;
> +}
> +
> +static void omap_usbhs_hsic_init(int tll_cnt)
> +{
> +	unsigned int reg;
> +	int i;
> +
> +	/* Enable channels now */
> +	for (i = 0; i < tll_cnt; i++) {
> +		reg = readl(&usbtll->channel_conf + OMAP_TLL_CHANNEL_CONF(i));
> +
> +		setbits_le32(&reg, (OMAP_TLL_CHANNEL_CONF_CHANMODE_TRANSPARENT_UTMI
> +			| OMAP_TLL_CHANNEL_CONF_ULPINOBITSTUFF
> +			| OMAP_TLL_CHANNEL_CONF_DRVVBUS
> +			| OMAP_TLL_CHANNEL_CONF_CHRGVBUS
> +			| OMAP_TLL_CHANNEL_CONF_CHANEN));
> +
> +		writel(reg, &usbtll->channel_conf + OMAP_TLL_CHANNEL_CONF(i));
> +	}
> +}
> +
> +static void omap_ehci_soft_phy_reset(int port)
> +{
> +	unsigned int reg = 0;
> +	unsigned long init = get_timer(0);
> +
> +	/* FUNCTION_CTRL_SET register */
> +	reg = ULPI_FUNC_CTRL_RESET |
> +		(ULPI_SET(ULPI_FUNC_CTRL) << EHCI_INSNREG05_ULPI_REGADD_SHIFT) |
> +		(2 << EHCI_INSNREG05_ULPI_OPSEL_SHIFT) |
> +		((port + 1) << EHCI_INSNREG05_ULPI_PORTSEL_SHIFT) |
> +		(1 << EHCI_INSNREG05_ULPI_CONTROL_SHIFT);
> +
> +	writel(reg, &ehci->insreg05_utmi_ulpi);
> +
> +	/* Wait for ULPI access completion */
> +	while ((readl(&ehci->insreg05_utmi_ulpi) &
> +			(1 << EHCI_INSNREG05_ULPI_CONTROL_SHIFT)))
> +		if (get_timer(init) > CONFIG_SYS_HZ) {
> +			debug("OMAP EHCI error: timeout resetting phy\n");
> +			break;
> +		}
> +}

Ok, this function is kind of "duplication" of the ULPI code.
ulpi_reset() function in drivers/usb/ulpi/ulpi.c provides an implementation
of the ULPI spec. and should be used by the drivers.
What it lacks currently, is a way to pass a port number to the viewport
implementation and of course the omap-ulpi-viewport(.c) implementation itself...
So, IMO, the right way would be to implement ULPI accessors (omap-ulpi-viewport.c)
and add an ability to pass some kind of private data to the viewport, which
in case of OMAP will be the port number.

Now, I know, that this will add much more code then this function does, but
it is always about using frameworks, otherwise each board file can implement
the whole U-Boot startup....

> +
>  inline int __board_usb_init(void)
>  {
>  	return 0;
> @@ -72,31 +151,31 @@ static inline void omap_ehci_phy_reset(int on, int delay)
>  #endif
> 
>  /* Reset is needed otherwise the kernel-driver will throw an error. */
> -int ehci_hcd_stop(void)
> +int omap_ehci_hcd_stop(void)
>  {
> -	debug("Resetting OMAP3 EHCI\n");
> +	debug("Resetting OMAP EHCI\n");
>  	omap_ehci_phy_reset(1, 0);
> -	writel(OMAP_UHH_SYSCONFIG_SOFTRESET,
> -			OMAP3_UHH_BASE + OMAP_UHH_SYSCONFIG);
> -	/* disable USB clocks */
> -	struct prcm *prcm_base = (struct prcm *)PRCM_BASE;
> -	sr32(&prcm_base->iclken_usbhost, 0, 1, 0);
> -	sr32(&prcm_base->fclken_usbhost, 0, 2, 0);
> -	sr32(&prcm_base->iclken3_core, 2, 1, 0);
> -	sr32(&prcm_base->fclken3_core, 2, 1, 0);
> +
> +	if (omap_uhh_reset() < 0)
> +		return -1;
> +
> +	if (omap_ehci_tll_reset() < 0)
> +		return -1;
> +
>  	return 0;
>  }
> 
>  /*
> - * Initialize the OMAP3 EHCI controller and PHY.
> - * Based on "drivers/usb/host/ehci-omap.c" from Linux 2.6.37.
> + * Initialize the OMAP EHCI controller and PHY.
> + * Based on "drivers/usb/host/ehci-omap.c" from Linux 3.1
>   * See there for additional Copyrights.
>   */
> -int ehci_hcd_init(void)
> +int omap_ehci_hcd_init(struct omap_usbhs_board_data *usbhs_pdata)
>  {
> -	int ret;
> +	int ret = 0;
> +	unsigned int i, reg = 0, rev = 0, tll_cnt = 0;
> 
> -	debug("Initializing OMAP3 EHCI\n");
> +	debug("Initializing OMAP EHCI\n");
> 
>  	ret = board_usb_init();
>  	if (ret < 0)
> @@ -105,52 +184,89 @@ int ehci_hcd_init(void)
>  	/* Put the PHY in RESET */
>  	omap_ehci_phy_reset(1, 10);
> 
> -	struct prcm *prcm_base = (struct prcm *)PRCM_BASE;
> -	/* Enable USBHOST_L3_ICLK (USBHOST_MICLK) */
> -	sr32(&prcm_base->iclken_usbhost, 0, 1, 1);
> -	/*
> -	 * Enable USBHOST_48M_FCLK (USBHOST_FCLK1)
> -	 * and USBHOST_120M_FCLK (USBHOST_FCLK2)
> -	 */
> -	sr32(&prcm_base->fclken_usbhost, 0, 2, 3);
> -	/* Enable USBTTL_ICLK */
> -	sr32(&prcm_base->iclken3_core, 2, 1, 1);
> -	/* Enable USBTTL_FCLK */
> -	sr32(&prcm_base->fclken3_core, 2, 1, 1);
> -	debug("USB clocks enabled\n");
> +	ret = omap_uhh_reset();
> +	if (ret < 0)
> +		return ret;
> 
> -	/* perform TLL soft reset, and wait until reset is complete */
> -	writel(OMAP_USBTLL_SYSCONFIG_SOFTRESET,
> -		OMAP3_USBTLL_BASE + OMAP_USBTLL_SYSCONFIG);
> -	/* Wait for TLL reset to complete */
> -	while (!(readl(OMAP3_USBTLL_BASE + OMAP_USBTLL_SYSSTATUS)
> -			& OMAP_USBTLL_SYSSTATUS_RESETDONE))
> -		;
> -	debug("TLL reset done\n");
> +	ret = omap_ehci_tll_reset();
> +	if (ret)
> +		return ret;

You do both resets unconditionally, shouldn't you check which mode
the port is in and only reset the right one?
Is it because all of them need to be configurred?

> 
>  	writel(OMAP_USBTLL_SYSCONFIG_ENAWAKEUP |
>  		OMAP_USBTLL_SYSCONFIG_SIDLEMODE |
> -		OMAP_USBTLL_SYSCONFIG_CACTIVITY,
> -		OMAP3_USBTLL_BASE + OMAP_USBTLL_SYSCONFIG);
> +		OMAP_USBTLL_SYSCONFIG_CACTIVITY, &usbtll->sysc);
> 
>  	/* Put UHH in NoIdle/NoStandby mode */
> -	writel(OMAP_UHH_SYSCONFIG_ENAWAKEUP
> -		| OMAP_UHH_SYSCONFIG_SIDLEMODE
> -		| OMAP_UHH_SYSCONFIG_CACTIVITY
> -		| OMAP_UHH_SYSCONFIG_MIDLEMODE,
> -		OMAP3_UHH_BASE + OMAP_UHH_SYSCONFIG);
> -
> -	/* setup burst configurations */
> -	writel(OMAP_UHH_HOSTCONFIG_INCR4_BURST_EN
> -		| OMAP_UHH_HOSTCONFIG_INCR8_BURST_EN
> -		| OMAP_UHH_HOSTCONFIG_INCR16_BURST_EN,
> -		OMAP3_UHH_BASE + OMAP_UHH_HOSTCONFIG);
> +	writel(OMAP_UHH_SYSCONFIG_VAL, &uhh->sysc);
> +
> +	/* setup ULPI bypass and burst configurations */
> +	clrsetbits_le32(&reg, OMAP_UHH_HOSTCONFIG_INCRX_ALIGN_EN,
> +		(OMAP_UHH_HOSTCONFIG_INCR4_BURST_EN |
> +		OMAP_UHH_HOSTCONFIG_INCR8_BURST_EN |
> +		OMAP_UHH_HOSTCONFIG_INCR16_BURST_EN));
> +
> +	rev = readl(&uhh->rev);
> +	if (rev == OMAP_USBHS_REV1) {
> +		if (is_ehci_phy_mode(usbhs_pdata->port_mode[0]))
> +			clrbits_le32(&reg, OMAP_UHH_HOSTCONFIG_ULPI_P1_BYPASS);
> +		else
> +			setbits_le32(&reg, OMAP_UHH_HOSTCONFIG_ULPI_P1_BYPASS);
> +
> +		if (is_ehci_phy_mode(usbhs_pdata->port_mode[1]))
> +			clrbits_le32(&reg, OMAP_UHH_HOSTCONFIG_ULPI_P2_BYPASS);
> +		else
> +			setbits_le32(&reg, OMAP_UHH_HOSTCONFIG_ULPI_P1_BYPASS);
> +
> +		if (is_ehci_phy_mode(usbhs_pdata->port_mode[2]))
> +			clrbits_le32(&reg, OMAP_UHH_HOSTCONFIG_ULPI_P3_BYPASS);
> +		else
> +			setbits_le32(&reg, OMAP_UHH_HOSTCONFIG_ULPI_P1_BYPASS);
> +
> +		tll_cnt = OMAP_REV1_TLL_CHANNEL_COUNT;
> +	} else if (rev == OMAP_USBHS_REV2) {
> +
> +		clrsetbits_le32(&reg, (OMAP_P1_MODE_CLEAR | OMAP_P2_MODE_CLEAR),
> +					OMAP4_UHH_HOSTCONFIG_APP_START_CLK);
> +
> +		/* Clear port mode fields for PHY mode*/
> +
> +		if (is_ehci_hsic_mode(usbhs_pdata->port_mode[0]))
> +			setbits_le32(&reg, OMAP_P1_MODE_HSIC);
> +
> +		if (is_ehci_hsic_mode(usbhs_pdata->port_mode[1]))
> +			setbits_le32(&reg, OMAP_P2_MODE_HSIC);
> +
> +		tll_cnt = OMAP_REV2_TLL_CHANNEL_COUNT;
> +	}
> +
> +	debug("OMAP UHH_REVISION 0x%x\n", rev);
> +	writel(reg, &uhh->hostconfig);
> +
> +	if (is_ehci_hsic_mode(usbhs_pdata->port_mode[0]) ||
> +			is_ehci_hsic_mode(usbhs_pdata->port_mode[1]))
> +		omap_usbhs_hsic_init(tll_cnt);
> 
>  	omap_ehci_phy_reset(0, 10);
> 
> -	hccr = (struct ehci_hccr *)(OMAP3_EHCI_BASE);
> -	hcor = (struct ehci_hcor *)(OMAP3_EHCI_BASE + 0x10);
> +	/*
> +	 * An undocumented "feature" in the OMAP3 EHCI controller,
> +	 * causes suspended ports to be taken out of suspend when
> +	 * the USBCMD.Run/Stop bit is cleared (for example when
> +	 * we do ehci_bus_suspend).
> +	 * This breaks suspend-resume if the root-hub is allowed
> +	 * to suspend. Writing 1 to this undocumented register bit
> +	 * disables this feature and restores normal behavior.
> +	 */
> +	writel(EHCI_INSNREG04_DISABLE_UNSUSPEND, &ehci->insreg04);
> +
> +	for (i = 0; i < OMAP_HS_USB_PORTS; i++)
> +		if (is_ehci_phy_mode(usbhs_pdata->port_mode[i]))
> +			omap_ehci_soft_phy_reset(i);
> +
> +	dcache_disable();
> +	hccr = (struct ehci_hccr *)(OMAP_EHCI_BASE);
> +	hcor = (struct ehci_hcor *)(OMAP_EHCI_BASE + 0x10);
> 
> -	debug("OMAP3 EHCI init done\n");
> +	debug("OMAP EHCI init done\n");
>  	return 0;
>  }
Govindraj Jan. 19, 2012, 8:15 a.m. UTC | #2
On Wed, Jan 18, 2012 at 11:21 PM, Igor Grinberg <grinberg@compulab.co.il> wrote:
> Hi Govindraj,
>
> On 01/17/12 08:10, Govindraj wrote:
>>
>> And just to clarify further there is no code duplication for ulpi read writes
>> in ehci-omap.c done with this patch.
>
> This is not just about code duplication,
> this is also about using the ULPI framework instead of direct writes to the
> ULPI PHYs.
>
>> Patch intends only in configuring ehci to right modes as specified by
>> board file.  Modes possible are hsic_mode, tll_mode, ulpi_phy mode.
>>
>> This patch is derived with reference to linux kernel and even there
>> we can see that no ulpi_reg map registers are used and only ehci
>> is configured is respective mode as passed by board data.
>
> This is not correct. They are used, see:
> drivers/usb/host/ehci-omap.c file, omap_ehci_soft_phy_reset() function.
> It does exactly the same, but yes it does not use the ULPI framework,
> because in Linux currently, there is no generic enough ULPI framework,
> so drivers can use it.

linux-2.6/drivers/usb/otg/ulpi.c ?

> There were discussions about it and decided that until there is such
> a framework, things can be done the way they are.
>
>>
>> Here [1] is the patch fixing Marek Vasut <marek.vasut@gmail.com>
>> comments.
>>
>> This corrected patch along with dependent patch from
>> Ilya Yanok <yanok@emcraft.com>
>> [PATCH V4 1/2] ehci-omap: driver for EHCI host on OMAP3
>>
>> Is available here:
>> git://gitorious.org/denx_u-boot/denx_uboot_omap.git v2_ehci_omap
>>
>> --
>> Thanks,
>> Govindraj.R
>>
>> [1]:
>>
>>>From 56b1b94128495ed4bf83e2f20f3884833e2aa082 Mon Sep 17 00:00:00 2001
>> From: "Govindraj.R" <govindraj.raja@ti.com>
>> Date: Tue, 27 Dec 2011 14:53:12 +0530
>> Subject: [PATCH 2/6] ehci-omap: Clean up added ehci-omap.c
>>
>> Clean up added ehci-omap.c and make it generic for re-use across
>> soc having same ehci ip block. Also pass the modes to be configured
>> and configure the ports accordingly. All usb layers are not cache
>> aligned till then keep cache off for usb ops as ehci will use
>> internally dma for all usb ops.
>>
>> * Add a generic common header ehci-omap.h having common ip block
>>   data and reg shifts.
>> * Rename and modify ehci-omap3 to ehci.h retain only conflicting
>>   sysc reg shifts remove others and move to common header file.
>>
>> Signed-off-by: Govindraj.R <govindraj.raja@ti.com>
>> ---
>>  arch/arm/include/asm/arch-omap3/ehci.h       |   55 ++++++
>>  arch/arm/include/asm/arch-omap3/ehci_omap3.h |   58 -------
>>  arch/arm/include/asm/arch-omap4/ehci.h       |   49 ++++++
>>  arch/arm/include/asm/ehci-omap.h             |  147 +++++++++++++++++
>>  drivers/usb/host/ehci-omap.c                 |  228 +++++++++++++++++++-------
>>  5 files changed, 423 insertions(+), 114 deletions(-)
>>  create mode 100644 arch/arm/include/asm/arch-omap3/ehci.h
>>  delete mode 100644 arch/arm/include/asm/arch-omap3/ehci_omap3.h
>>  create mode 100644 arch/arm/include/asm/arch-omap4/ehci.h
>>  create mode 100644 arch/arm/include/asm/ehci-omap.h
>>
>> diff --git a/arch/arm/include/asm/arch-omap3/ehci.h
>> b/arch/arm/include/asm/arch-omap3/ehci.h
>> new file mode 100644
>> index 0000000..d622363
>> --- /dev/null
>> +++ b/arch/arm/include/asm/arch-omap3/ehci.h
>> @@ -0,0 +1,55 @@
>> +/*
>> + * (C) Copyright 2011
>> + * Alexander Holler <holler@ahsoftware.de>
>> + *
>> + * Based on "drivers/usb/host/ehci-omap.c" from Linux 2.6.37
>> + *
>> + * See there for additional Copyrights.
>> + *
>> + * See file CREDITS for list of people who contributed to this
>> + * project.
>> + *
>> + * This program is free software; you can redistribute it and/or
>> + * modify it under the terms of the GNU General Public License as
>> + * published by the Free Software Foundation; either version 2 of
>> + * the License, or (at your option) any later version.
>> + *
>> + * This program is distributed in the hope that it will be useful,
>> + * but WITHOUT ANY WARRANTY; without even the implied warranty of
>> + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
>> + * GNU General Public License for more details.
>> + *
>> + * You should have received a copy of the GNU General Public License
>> + * along with this program; if not, write to the Free Software
>> + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
>> + * MA 02110-1301 USA
>> + */
>> +#ifndef _EHCI_H_
>> +#define _EHCI_H_
>
> hmmm... isn't it too generic?
> I think you should have included a part of the path to the file,
> so no namespace collision will occure.
> something like _OMAP3_EHCI_H_?
>

since these include's are part of arch folder
will not collide with other ones.

But still its better to have _OMAP3_EHCI_H_

will correct this.


>> +
>> +/* USB/EHCI registers */
>> +#define OMAP_USBTLL_BASE                             0x48062000UL
>> +#define OMAP_UHH_BASE                                        0x48064000UL
>> +#define OMAP_EHCI_BASE                                       0x48064800UL
>> +
>> +/* TLL Register Set */
>> +#define OMAP_USBTLL_SYSCONFIG_SOFTRESET                      (1 << 1)
>> +#define OMAP_USBTLL_SYSCONFIG_ENAWAKEUP                      (1 << 2)
>> +#define OMAP_USBTLL_SYSCONFIG_SIDLEMODE                      (1 << 3)
>> +#define OMAP_USBTLL_SYSCONFIG_CACTIVITY                      (1 << 8)
>> +#define OMAP_USBTLL_SYSSTATUS_RESETDONE                      1
>> +
>> +/* UHH Register Set */
>> +#define OMAP_UHH_SYSCONFIG_SOFTRESET                 (1 << 1)
>> +#define OMAP_UHH_SYSCONFIG_CACTIVITY                 (1 << 8)
>> +#define OMAP_UHH_SYSCONFIG_SIDLEMODE                 (1 << 3)
>> +#define OMAP_UHH_SYSCONFIG_ENAWAKEUP                 (1 << 2)
>> +#define OMAP_UHH_SYSCONFIG_MIDLEMODE                 (1 << 12)
>> +#define OMAP_UHH_SYSSTATUS_EHCI_RESETDONE            (1 << 2)
>> +
>> +#define OMAP_UHH_SYSCONFIG_VAL               (OMAP_UHH_SYSCONFIG_CACTIVITY | \
>> +                                     OMAP_UHH_SYSCONFIG_SIDLEMODE | \
>> +                                     OMAP_UHH_SYSCONFIG_ENAWAKEUP | \
>> +                                     OMAP_UHH_SYSCONFIG_MIDLEMODE)
>> +
>> +#endif /* _EHCI_H_ */
>> diff --git a/arch/arm/include/asm/arch-omap3/ehci_omap3.h
>> b/arch/arm/include/asm/arch-omap3/ehci_omap3.h
>> deleted file mode 100644
>> index cd01f50..0000000
>> --- a/arch/arm/include/asm/arch-omap3/ehci_omap3.h
>> +++ /dev/null
>> @@ -1,58 +0,0 @@
>> -/*
>> - * (C) Copyright 2011
>> - * Alexander Holler <holler@ahsoftware.de>
>> - *
>> - * Based on "drivers/usb/host/ehci-omap.c" from Linux 2.6.37
>> - *
>> - * See there for additional Copyrights.
>> - *
>> - * See file CREDITS for list of people who contributed to this
>> - * project.
>> - *
>> - * This program is free software; you can redistribute it and/or
>> - * modify it under the terms of the GNU General Public License as
>> - * published by the Free Software Foundation; either version 2 of
>> - * the License, or (at your option) any later version.
>> - *
>> - * This program is distributed in the hope that it will be useful,
>> - * but WITHOUT ANY WARRANTY; without even the implied warranty of
>> - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
>> - * GNU General Public License for more details.
>> - *
>> - * You should have received a copy of the GNU General Public License
>> - * along with this program; if not, write to the Free Software
>> - * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
>> - * MA 02110-1301 USA
>> - */
>> -#ifndef _EHCI_OMAP3_H_
>> -#define _EHCI_OMAP3_H_
>> -
>> -/* USB/EHCI registers */
>> -#define OMAP3_USBTLL_BASE                            0x48062000UL
>> -#define OMAP3_UHH_BASE                                       0x48064000UL
>> -#define OMAP3_EHCI_BASE                                      0x48064800UL
>> -
>> -/* TLL Register Set */
>> -#define      OMAP_USBTLL_SYSCONFIG                           (0x10)
>> -#define      OMAP_USBTLL_SYSCONFIG_SOFTRESET                 (1 << 1)
>> -#define      OMAP_USBTLL_SYSCONFIG_ENAWAKEUP                 (1 << 2)
>> -#define      OMAP_USBTLL_SYSCONFIG_SIDLEMODE                 (1 << 3)
>> -#define      OMAP_USBTLL_SYSCONFIG_CACTIVITY                 (1 << 8)
>> -
>> -#define      OMAP_USBTLL_SYSSTATUS                           (0x14)
>> -#define      OMAP_USBTLL_SYSSTATUS_RESETDONE                 (1 << 0)
>> -
>> -/* UHH Register Set */
>> -#define      OMAP_UHH_SYSCONFIG                              (0x10)
>> -#define      OMAP_UHH_SYSCONFIG_SOFTRESET                    (1 << 1)
>> -#define      OMAP_UHH_SYSCONFIG_CACTIVITY                    (1 << 8)
>> -#define      OMAP_UHH_SYSCONFIG_SIDLEMODE                    (1 << 3)
>> -#define      OMAP_UHH_SYSCONFIG_ENAWAKEUP                    (1 << 2)
>> -#define      OMAP_UHH_SYSCONFIG_MIDLEMODE                    (1 << 12)
>> -
>> -#define      OMAP_UHH_HOSTCONFIG                             (0x40)
>> -#define OMAP_UHH_HOSTCONFIG_INCR4_BURST_EN           (1 << 2)
>> -#define OMAP_UHH_HOSTCONFIG_INCR8_BURST_EN           (1 << 3)
>> -#define OMAP_UHH_HOSTCONFIG_INCR16_BURST_EN          (1 << 4)
>> -
>> -#endif /* _EHCI_OMAP3_H_ */
>> diff --git a/arch/arm/include/asm/arch-omap4/ehci.h
>> b/arch/arm/include/asm/arch-omap4/ehci.h
>> new file mode 100644
>> index 0000000..eaa82cf
>> --- /dev/null
>> +++ b/arch/arm/include/asm/arch-omap4/ehci.h
>> @@ -0,0 +1,49 @@
>> +/*
>> + * OMAP EHCI port support
>> + * Based on LINUX KERNEL
>> + * drivers/usb/host/ehci-omap.c and drivers/mfd/omap-usb-host.c
>> + *
>> + * Copyright (C) 2011 Texas Instruments Incorporated - http://www.ti.com
>> + * Author: Govindraj R <govindraj.raja@ti.com>
>> + *
>> + * This program is free software: you can redistribute it and/or modify
>> + * it under the terms of the GNU General Public License version 2  of
>> + * the License as published by the Free Software Foundation.
>> + *
>> + * This program is distributed in the hope that it will be useful,
>> + * but WITHOUT ANY WARRANTY; without even the implied warranty of
>> + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
>> + * GNU General Public License for more details.
>> + *
>> + * You should have received a copy of the GNU General Public License
>> + * along with this program. If not, see <http://www.gnu.org/licenses/>.
>> + */
>> +
>> +#ifndef _EHCI_H
>> +#define _EHCI_H
>
> see what I mean? above you have _EHCI_H_ and here _EHCI_H...
> That is too confusing...
> IMO, something like _OMAP4_EHCI_H_ will do here.
>

will correct it.


>> +
>> +#define OMAP_EHCI_BASE                               (OMAP44XX_L4_CORE_BASE + 0x64C00)
>> +#define OMAP_UHH_BASE                                (OMAP44XX_L4_CORE_BASE + 0x64000)
>> +#define OMAP_USBTLL_BASE                     (OMAP44XX_L4_CORE_BASE + 0x62000)
>> +
>> +/* UHH, TLL and opt clocks */
>> +#define CM_L3INIT_HSUSBHOST_CLKCTRL          0x4A009358UL
>> +
>> +#define HSUSBHOST_CLKCTRL_CLKSEL_UTMI_P1_MASK        (1 << 24)
>> +
>> +/* TLL Register Set */
>> +#define OMAP_USBTLL_SYSCONFIG_SIDLEMODE              (1 << 3)
>> +#define OMAP_USBTLL_SYSCONFIG_ENAWAKEUP              (1 << 2)
>> +#define OMAP_USBTLL_SYSCONFIG_SOFTRESET              (1 << 1)
>> +#define OMAP_USBTLL_SYSCONFIG_CACTIVITY              (1 << 8)
>> +#define OMAP_USBTLL_SYSSTATUS_RESETDONE              1
>> +
>> +#define OMAP_UHH_SYSCONFIG_SOFTRESET         1
>> +#define OMAP_UHH_SYSSTATUS_EHCI_RESETDONE    (1 << 2)
>> +#define OMAP_UHH_SYSCONFIG_NOIDLE            (1 << 2)
>> +#define OMAP_UHH_SYSCONFIG_NOSTDBY           (1 << 4)
>> +
>> +#define OMAP_UHH_SYSCONFIG_VAL       (OMAP_UHH_SYSCONFIG_NOIDLE | \
>> +                                     OMAP_UHH_SYSCONFIG_NOSTDBY)
>> +
>> +#endif /* _EHCI_H */
>> diff --git a/arch/arm/include/asm/ehci-omap.h b/arch/arm/include/asm/ehci-omap.h
>> new file mode 100644
>> index 0000000..ac68db7
>> --- /dev/null
>> +++ b/arch/arm/include/asm/ehci-omap.h
>> @@ -0,0 +1,147 @@
>> +/*
>> + * OMAP EHCI port support
>> + * Based on LINUX KERNEL
>> + * drivers/usb/host/ehci-omap.c and drivers/mfd/omap-usb-host.c
>> + *
>> + * Copyright (C) 2011 Texas Instruments Incorporated - http://www.ti.com*
>> + * Author: Govindraj R <govindraj.raja@ti.com>
>> + *
>> + * This program is free software: you can redistribute it and/or modify
>> + * it under the terms of the GNU General Public License version 2  of
>> + * the License as published by the Free Software Foundation.
>> + *
>> + * This program is distributed in the hope that it will be useful,
>> + * but WITHOUT ANY WARRANTY; without even the implied warranty of
>> + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
>> + * GNU General Public License for more details.
>> + *
>> + * You should have received a copy of the GNU General Public License
>> + * along with this program. If not, see <http://www.gnu.org/licenses/>.
>> + */
>> +
>> +#ifndef EHCI_H
>> +#define EHCI_H
>
> And even worth... now there are three of them!!!
> No, this is not good... what about OMAP5 will it be EHCI__H?
> Probably here, something like _OMAP_COMMON_EHCI_H_ will do?
>

sure will do it.

>> +
>> +enum usbhs_omap_port_mode {
>> +     OMAP_USBHS_PORT_MODE_UNUSED,
>> +     OMAP_EHCI_PORT_MODE_PHY,
>> +     OMAP_EHCI_PORT_MODE_TLL,
>> +     OMAP_EHCI_PORT_MODE_HSIC,
>> +};
>> +
>> +#ifdef CONFIG_SYS_USB_EHCI_MAX_ROOT_PORTS
>> +#define OMAP_HS_USB_PORTS    CONFIG_SYS_USB_EHCI_MAX_ROOT_PORTS
>> +#else
>> +#define OMAP_HS_USB_PORTS    3
>> +#endif
>> +
>> +#define is_ehci_phy_mode(x)  ((x) == OMAP_EHCI_PORT_MODE_PHY)
>> +#define is_ehci_tll_mode(x)  ((x) == OMAP_EHCI_PORT_MODE_TLL)
>> +#define is_ehci_hsic_mode(x) ((x) == OMAP_EHCI_PORT_MODE_HSIC)
>> +
>> +/* Values of UHH_REVISION - Note: these are not given in the TRM */
>> +#define OMAP_USBHS_REV1                                      0x00000010 /* OMAP3 */
>> +#define OMAP_USBHS_REV2                                      0x50700100 /* OMAP4 */
>> +
>> +/* UHH Register Set */
>> +#define OMAP_UHH_HOSTCONFIG_INCR4_BURST_EN           (1 << 2)
>> +#define OMAP_UHH_HOSTCONFIG_INCR8_BURST_EN           (1 << 3)
>> +#define OMAP_UHH_HOSTCONFIG_INCR16_BURST_EN          (1 << 4)
>> +#define OMAP_UHH_HOSTCONFIG_INCRX_ALIGN_EN           (1 << 5)
>> +
>> +#define OMAP_UHH_HOSTCONFIG_ULPI_P1_BYPASS           1
>> +#define OMAP_UHH_HOSTCONFIG_ULPI_P2_BYPASS           (1 << 11)
>> +#define OMAP_UHH_HOSTCONFIG_ULPI_P3_BYPASS           (1 << 12)
>> +#define OMAP4_UHH_HOSTCONFIG_APP_START_CLK           (1 << 31)
>> +
>> +#define OMAP_P1_MODE_CLEAR                           (3 << 16)
>> +#define OMAP_P1_MODE_TLL                             (1 << 16)
>> +#define OMAP_P1_MODE_HSIC                            (3 << 16)
>> +#define OMAP_P2_MODE_CLEAR                           (3 << 18)
>> +#define OMAP_P2_MODE_TLL                             (1 << 18)
>> +#define OMAP_P2_MODE_HSIC                            (3 << 18)
>> +
>> +/* EHCI Register Set */
>> +#define EHCI_INSNREG04_DISABLE_UNSUSPEND             (1 << 5)
>> +#define EHCI_INSNREG05_ULPI_CONTROL_SHIFT            31
>> +#define EHCI_INSNREG05_ULPI_PORTSEL_SHIFT            24
>> +#define EHCI_INSNREG05_ULPI_OPSEL_SHIFT                      22
>> +#define EHCI_INSNREG05_ULPI_REGADD_SHIFT             16
>> +
>> +#define OMAP_REV1_TLL_CHANNEL_COUNT                  3
>> +#define OMAP_REV2_TLL_CHANNEL_COUNT                  2
>> +
>> +/* TLL Register Set */
>> +#define OMAP_TLL_CHANNEL_CONF(num)                   (0x004 * num)
>> +#define OMAP_TLL_CHANNEL_CONF_DRVVBUS                        (1 << 16)
>> +#define OMAP_TLL_CHANNEL_CONF_CHRGVBUS                       (1 << 15)
>> +#define OMAP_TLL_CHANNEL_CONF_ULPINOBITSTUFF         (1 << 11)
>> +#define OMAP_TLL_CHANNEL_CONF_CHANMODE_TRANSPARENT_UTMI      (2 << 1)
>> +#define OMAP_TLL_CHANNEL_CONF_CHANEN                 1
>> +
>> +/* ULPI */
>> +#define ULPI_SET(a)                                  (a + 1)
>
> This is the offset of each "set" register of ULPI PHY
>
>> +#define ULPI_CLR(a)                                  (a + 2)
>
> This is the offset of each "clear" register of ULPI PHY
>
>> +#define ULPI_FUNC_CTRL                                       0x04
>
> This is the offset of the "Function Control register" of the ULPI PHY
> This is already defined as ulpi_regs.function_ctrl member in
> include/usb/ulpi.h file.
>
>> +#define ULPI_FUNC_CTRL_RESET                         (1 << 5)
>
> This is the reset bin inside the "Function Control register" of the ULPI PHY
> This bit is already defined in the include/usb/ulpi.h file.
>

yes but these are not dedicated reg maps that can be written.

on omap usb host controller is coupled with tll module to compose the
ULPI TLL interface
and the way to speak to them is using the INSNREG05_ULPI which has the
reg address field
and value to be written.

ulpi framework needs a full reg map to read write registers.

[..]

ulpi_write(ulpi_viewport,
                        &ulpi->function_ctrl_set, ULPI_FC_RESET);

[..]

from above code snip what we need is dedicated ulpi reg start address
to get func ctrl.

so these api's cannot be used.

>> +
>> +struct omap_usbhs_board_data {
>> +     enum usbhs_omap_port_mode port_mode[OMAP_HS_USB_PORTS];
>> +};
>> +
>> +struct omap_usbtll {
>> +     u32 rev;                /* 0x00 */
>> +     u32 hwinfo;             /* 0x04 */
>> +     u8 reserved1[0x8];
>> +     u32 sysc;               /* 0x10 */

[...]

>> +}
>> +
>> +static void omap_ehci_soft_phy_reset(int port)
>> +{
>> +     unsigned int reg = 0;
>> +     unsigned long init = get_timer(0);
>> +
>> +     /* FUNCTION_CTRL_SET register */
>> +     reg = ULPI_FUNC_CTRL_RESET |
>> +             (ULPI_SET(ULPI_FUNC_CTRL) << EHCI_INSNREG05_ULPI_REGADD_SHIFT) |
>> +             (2 << EHCI_INSNREG05_ULPI_OPSEL_SHIFT) |
>> +             ((port + 1) << EHCI_INSNREG05_ULPI_PORTSEL_SHIFT) |
>> +             (1 << EHCI_INSNREG05_ULPI_CONTROL_SHIFT);
>> +
>> +     writel(reg, &ehci->insreg05_utmi_ulpi);
>> +
>> +     /* Wait for ULPI access completion */
>> +     while ((readl(&ehci->insreg05_utmi_ulpi) &
>> +                     (1 << EHCI_INSNREG05_ULPI_CONTROL_SHIFT)))
>> +             if (get_timer(init) > CONFIG_SYS_HZ) {
>> +                     debug("OMAP EHCI error: timeout resetting phy\n");
>> +                     break;
>> +             }
>> +}
>
> Ok, this function is kind of "duplication" of the ULPI code.
> ulpi_reset() function in drivers/usb/ulpi/ulpi.c provides an implementation
> of the ULPI spec. and should be used by the drivers.
> What it lacks currently, is a way to pass a port number to the viewport
> implementation and of course the omap-ulpi-viewport(.c) implementation itself...
> So, IMO, the right way would be to implement ULPI accessors (omap-ulpi-viewport.c)

so you mean add omap-ulpi-viewport.c which will do ulpi read writes
for ulpi implementation
within tll module of omap host controller.

we just need func reset to be done for ulpi which is done using ehci register
INSNREG05_ULPI. IMHO I don't see any use case or true requirement of
omap-ulpi-viewport.c framework.

> and add an ability to pass some kind of private data to the viewport, which
> in case of OMAP will be the port number.
>
> Now, I know, that this will add much more code then this function does, but
> it is always about using frameworks, otherwise each board file can implement
> the whole U-Boot startup....
>
> +
>>  inline int __board_usb_init(void)
>>  {
>>       return 0;
>> @@ -72,31 +151,31 @@ static inline void omap_ehci_phy_reset(int on, int delay)
>>  #endif
>>
>>  /* Reset is needed otherwise the kernel-driver will throw an error. */
>> -int ehci_hcd_stop(void)
>> +int omap_ehci_hcd_stop(void)
>>  {
>> -     debug("Resetting OMAP3 EHCI\n");
>> +     debug("Resetting OMAP EHCI\n");
>>       omap_ehci_phy_reset(1, 0);
>> -     writel(OMAP_UHH_SYSCONFIG_SOFTRESET,
>> -                     OMAP3_UHH_BASE + OMAP_UHH_SYSCONFIG);
>> -     /* disable USB clocks */
>> -     struct prcm *prcm_base = (struct prcm *)PRCM_BASE;
>> -     sr32(&prcm_base->iclken_usbhost, 0, 1, 0);
>> -     sr32(&prcm_base->fclken_usbhost, 0, 2, 0);
>> -     sr32(&prcm_base->iclken3_core, 2, 1, 0);
>> -     sr32(&prcm_base->fclken3_core, 2, 1, 0);
>> +
>> +     if (omap_uhh_reset() < 0)
>> +             return -1;
>> +
>> +     if (omap_ehci_tll_reset() < 0)
>> +             return -1;
>> +
>>       return 0;
>>  }
>>
>>  /*
>> - * Initialize the OMAP3 EHCI controller and PHY.
>> - * Based on "drivers/usb/host/ehci-omap.c" from Linux 2.6.37.
>> + * Initialize the OMAP EHCI controller and PHY.
>> + * Based on "drivers/usb/host/ehci-omap.c" from Linux 3.1
>>   * See there for additional Copyrights.
>>   */
>> -int ehci_hcd_init(void)
>> +int omap_ehci_hcd_init(struct omap_usbhs_board_data *usbhs_pdata)
>>  {
>> -     int ret;
>> +     int ret = 0;
>> +     unsigned int i, reg = 0, rev = 0, tll_cnt = 0;
>>
>> -     debug("Initializing OMAP3 EHCI\n");
>> +     debug("Initializing OMAP EHCI\n");
>>
>>       ret = board_usb_init();
>>       if (ret < 0)
>> @@ -105,52 +184,89 @@ int ehci_hcd_init(void)
>>       /* Put the PHY in RESET */
>>       omap_ehci_phy_reset(1, 10);
>>
>> -     struct prcm *prcm_base = (struct prcm *)PRCM_BASE;
>> -     /* Enable USBHOST_L3_ICLK (USBHOST_MICLK) */
>> -     sr32(&prcm_base->iclken_usbhost, 0, 1, 1);
>> -     /*
>> -      * Enable USBHOST_48M_FCLK (USBHOST_FCLK1)
>> -      * and USBHOST_120M_FCLK (USBHOST_FCLK2)
>> -      */
>> -     sr32(&prcm_base->fclken_usbhost, 0, 2, 3);
>> -     /* Enable USBTTL_ICLK */
>> -     sr32(&prcm_base->iclken3_core, 2, 1, 1);
>> -     /* Enable USBTTL_FCLK */
>> -     sr32(&prcm_base->fclken3_core, 2, 1, 1);
>> -     debug("USB clocks enabled\n");
>> +     ret = omap_uhh_reset();
>> +     if (ret < 0)
>> +             return ret;
>>
>> -     /* perform TLL soft reset, and wait until reset is complete */
>> -     writel(OMAP_USBTLL_SYSCONFIG_SOFTRESET,
>> -             OMAP3_USBTLL_BASE + OMAP_USBTLL_SYSCONFIG);
>> -     /* Wait for TLL reset to complete */
>> -     while (!(readl(OMAP3_USBTLL_BASE + OMAP_USBTLL_SYSSTATUS)
>> -                     & OMAP_USBTLL_SYSSTATUS_RESETDONE))
>> -             ;
>> -     debug("TLL reset done\n");
>> +     ret = omap_ehci_tll_reset();
>> +     if (ret)
>> +             return ret;
>
> You do both resets unconditionally, shouldn't you check which mode
> the port is in and only reset the right one?
> Is it because all of them need to be configurred?
>

yes, and to set sys_config register settings.

--
Thanks,
Govindraj.R
Igor Grinberg Jan. 22, 2012, 12:20 p.m. UTC | #3
On 01/19/12 10:15, Govindraj wrote:
> On Wed, Jan 18, 2012 at 11:21 PM, Igor Grinberg <grinberg@compulab.co.il> wrote:
>> Hi Govindraj,
>>
>> On 01/17/12 08:10, Govindraj wrote:
>>>
>>> And just to clarify further there is no code duplication for ulpi read writes
>>> in ehci-omap.c done with this patch.
>>
>> This is not just about code duplication,
>> this is also about using the ULPI framework instead of direct writes to the
>> ULPI PHYs.
>>
>>> Patch intends only in configuring ehci to right modes as specified by
>>> board file.  Modes possible are hsic_mode, tll_mode, ulpi_phy mode.
>>>
>>> This patch is derived with reference to linux kernel and even there
>>> we can see that no ulpi_reg map registers are used and only ehci
>>> is configured is respective mode as passed by board data.
>>
>> This is not correct. They are used, see:
>> drivers/usb/host/ehci-omap.c file, omap_ehci_soft_phy_reset() function.
>> It does exactly the same, but yes it does not use the ULPI framework,
>> because in Linux currently, there is no generic enough ULPI framework,
>> so drivers can use it.
> 
> linux-2.6/drivers/usb/otg/ulpi.c ?

No, this is a kind of attempt to implement the ULPI framework,
but not really a good one... and that is the reason why no driver inside
drivers/usb/otg/ is using it...

> 
>> There were discussions about it and decided that until there is such
>> a framework, things can be done the way they are.
>>
>>>
>>> Here [1] is the patch fixing Marek Vasut <marek.vasut@gmail.com>
>>> comments.
>>>
>>> This corrected patch along with dependent patch from
>>> Ilya Yanok <yanok@emcraft.com>
>>> [PATCH V4 1/2] ehci-omap: driver for EHCI host on OMAP3
>>>
>>> Is available here:
>>> git://gitorious.org/denx_u-boot/denx_uboot_omap.git v2_ehci_omap
>>>
>>> --
>>> Thanks,
>>> Govindraj.R
>>>
>>> [1]:
>>>
>>> >From 56b1b94128495ed4bf83e2f20f3884833e2aa082 Mon Sep 17 00:00:00 2001
>>> From: "Govindraj.R" <govindraj.raja@ti.com>
>>> Date: Tue, 27 Dec 2011 14:53:12 +0530
>>> Subject: [PATCH 2/6] ehci-omap: Clean up added ehci-omap.c
>>>
>>> Clean up added ehci-omap.c and make it generic for re-use across
>>> soc having same ehci ip block. Also pass the modes to be configured
>>> and configure the ports accordingly. All usb layers are not cache
>>> aligned till then keep cache off for usb ops as ehci will use
>>> internally dma for all usb ops.
>>>
>>> * Add a generic common header ehci-omap.h having common ip block
>>>   data and reg shifts.
>>> * Rename and modify ehci-omap3 to ehci.h retain only conflicting
>>>   sysc reg shifts remove others and move to common header file.
>>>
>>> Signed-off-by: Govindraj.R <govindraj.raja@ti.com>
>>> ---
>>>  arch/arm/include/asm/arch-omap3/ehci.h       |   55 ++++++
>>>  arch/arm/include/asm/arch-omap3/ehci_omap3.h |   58 -------
>>>  arch/arm/include/asm/arch-omap4/ehci.h       |   49 ++++++
>>>  arch/arm/include/asm/ehci-omap.h             |  147 +++++++++++++++++
>>>  drivers/usb/host/ehci-omap.c                 |  228 +++++++++++++++++++-------
>>>  5 files changed, 423 insertions(+), 114 deletions(-)
>>>  create mode 100644 arch/arm/include/asm/arch-omap3/ehci.h
>>>  delete mode 100644 arch/arm/include/asm/arch-omap3/ehci_omap3.h
>>>  create mode 100644 arch/arm/include/asm/arch-omap4/ehci.h
>>>  create mode 100644 arch/arm/include/asm/ehci-omap.h
>>>
>>> diff --git a/arch/arm/include/asm/arch-omap3/ehci.h
>>> b/arch/arm/include/asm/arch-omap3/ehci.h
>>> new file mode 100644
>>> index 0000000..d622363
>>> --- /dev/null
>>> +++ b/arch/arm/include/asm/arch-omap3/ehci.h
>>> @@ -0,0 +1,55 @@
>>> +/*
>>> + * (C) Copyright 2011
>>> + * Alexander Holler <holler@ahsoftware.de>
>>> + *
>>> + * Based on "drivers/usb/host/ehci-omap.c" from Linux 2.6.37
>>> + *
>>> + * See there for additional Copyrights.
>>> + *
>>> + * See file CREDITS for list of people who contributed to this
>>> + * project.
>>> + *
>>> + * This program is free software; you can redistribute it and/or
>>> + * modify it under the terms of the GNU General Public License as
>>> + * published by the Free Software Foundation; either version 2 of
>>> + * the License, or (at your option) any later version.
>>> + *
>>> + * This program is distributed in the hope that it will be useful,
>>> + * but WITHOUT ANY WARRANTY; without even the implied warranty of
>>> + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
>>> + * GNU General Public License for more details.
>>> + *
>>> + * You should have received a copy of the GNU General Public License
>>> + * along with this program; if not, write to the Free Software
>>> + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
>>> + * MA 02110-1301 USA
>>> + */
>>> +#ifndef _EHCI_H_
>>> +#define _EHCI_H_
>>
>> hmmm... isn't it too generic?
>> I think you should have included a part of the path to the file,
>> so no namespace collision will occure.
>> something like _OMAP3_EHCI_H_?
>>
> 
> since these include's are part of arch folder
> will not collide with other ones.
> 
> But still its better to have _OMAP3_EHCI_H_
> 
> will correct this.
> 
> 
>>> +
>>> +/* USB/EHCI registers */
>>> +#define OMAP_USBTLL_BASE                             0x48062000UL
>>> +#define OMAP_UHH_BASE                                        0x48064000UL
>>> +#define OMAP_EHCI_BASE                                       0x48064800UL
>>> +
>>> +/* TLL Register Set */
>>> +#define OMAP_USBTLL_SYSCONFIG_SOFTRESET                      (1 << 1)
>>> +#define OMAP_USBTLL_SYSCONFIG_ENAWAKEUP                      (1 << 2)
>>> +#define OMAP_USBTLL_SYSCONFIG_SIDLEMODE                      (1 << 3)
>>> +#define OMAP_USBTLL_SYSCONFIG_CACTIVITY                      (1 << 8)
>>> +#define OMAP_USBTLL_SYSSTATUS_RESETDONE                      1
>>> +
>>> +/* UHH Register Set */
>>> +#define OMAP_UHH_SYSCONFIG_SOFTRESET                 (1 << 1)
>>> +#define OMAP_UHH_SYSCONFIG_CACTIVITY                 (1 << 8)
>>> +#define OMAP_UHH_SYSCONFIG_SIDLEMODE                 (1 << 3)
>>> +#define OMAP_UHH_SYSCONFIG_ENAWAKEUP                 (1 << 2)
>>> +#define OMAP_UHH_SYSCONFIG_MIDLEMODE                 (1 << 12)
>>> +#define OMAP_UHH_SYSSTATUS_EHCI_RESETDONE            (1 << 2)
>>> +
>>> +#define OMAP_UHH_SYSCONFIG_VAL               (OMAP_UHH_SYSCONFIG_CACTIVITY | \
>>> +                                     OMAP_UHH_SYSCONFIG_SIDLEMODE | \
>>> +                                     OMAP_UHH_SYSCONFIG_ENAWAKEUP | \
>>> +                                     OMAP_UHH_SYSCONFIG_MIDLEMODE)
>>> +
>>> +#endif /* _EHCI_H_ */
>>> diff --git a/arch/arm/include/asm/arch-omap3/ehci_omap3.h
>>> b/arch/arm/include/asm/arch-omap3/ehci_omap3.h
>>> deleted file mode 100644
>>> index cd01f50..0000000
>>> --- a/arch/arm/include/asm/arch-omap3/ehci_omap3.h
>>> +++ /dev/null
>>> @@ -1,58 +0,0 @@
>>> -/*
>>> - * (C) Copyright 2011
>>> - * Alexander Holler <holler@ahsoftware.de>
>>> - *
>>> - * Based on "drivers/usb/host/ehci-omap.c" from Linux 2.6.37
>>> - *
>>> - * See there for additional Copyrights.
>>> - *
>>> - * See file CREDITS for list of people who contributed to this
>>> - * project.
>>> - *
>>> - * This program is free software; you can redistribute it and/or
>>> - * modify it under the terms of the GNU General Public License as
>>> - * published by the Free Software Foundation; either version 2 of
>>> - * the License, or (at your option) any later version.
>>> - *
>>> - * This program is distributed in the hope that it will be useful,
>>> - * but WITHOUT ANY WARRANTY; without even the implied warranty of
>>> - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
>>> - * GNU General Public License for more details.
>>> - *
>>> - * You should have received a copy of the GNU General Public License
>>> - * along with this program; if not, write to the Free Software
>>> - * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
>>> - * MA 02110-1301 USA
>>> - */
>>> -#ifndef _EHCI_OMAP3_H_
>>> -#define _EHCI_OMAP3_H_
>>> -
>>> -/* USB/EHCI registers */
>>> -#define OMAP3_USBTLL_BASE                            0x48062000UL
>>> -#define OMAP3_UHH_BASE                                       0x48064000UL
>>> -#define OMAP3_EHCI_BASE                                      0x48064800UL
>>> -
>>> -/* TLL Register Set */
>>> -#define      OMAP_USBTLL_SYSCONFIG                           (0x10)
>>> -#define      OMAP_USBTLL_SYSCONFIG_SOFTRESET                 (1 << 1)
>>> -#define      OMAP_USBTLL_SYSCONFIG_ENAWAKEUP                 (1 << 2)
>>> -#define      OMAP_USBTLL_SYSCONFIG_SIDLEMODE                 (1 << 3)
>>> -#define      OMAP_USBTLL_SYSCONFIG_CACTIVITY                 (1 << 8)
>>> -
>>> -#define      OMAP_USBTLL_SYSSTATUS                           (0x14)
>>> -#define      OMAP_USBTLL_SYSSTATUS_RESETDONE                 (1 << 0)
>>> -
>>> -/* UHH Register Set */
>>> -#define      OMAP_UHH_SYSCONFIG                              (0x10)
>>> -#define      OMAP_UHH_SYSCONFIG_SOFTRESET                    (1 << 1)
>>> -#define      OMAP_UHH_SYSCONFIG_CACTIVITY                    (1 << 8)
>>> -#define      OMAP_UHH_SYSCONFIG_SIDLEMODE                    (1 << 3)
>>> -#define      OMAP_UHH_SYSCONFIG_ENAWAKEUP                    (1 << 2)
>>> -#define      OMAP_UHH_SYSCONFIG_MIDLEMODE                    (1 << 12)
>>> -
>>> -#define      OMAP_UHH_HOSTCONFIG                             (0x40)
>>> -#define OMAP_UHH_HOSTCONFIG_INCR4_BURST_EN           (1 << 2)
>>> -#define OMAP_UHH_HOSTCONFIG_INCR8_BURST_EN           (1 << 3)
>>> -#define OMAP_UHH_HOSTCONFIG_INCR16_BURST_EN          (1 << 4)
>>> -
>>> -#endif /* _EHCI_OMAP3_H_ */
>>> diff --git a/arch/arm/include/asm/arch-omap4/ehci.h
>>> b/arch/arm/include/asm/arch-omap4/ehci.h
>>> new file mode 100644
>>> index 0000000..eaa82cf
>>> --- /dev/null
>>> +++ b/arch/arm/include/asm/arch-omap4/ehci.h
>>> @@ -0,0 +1,49 @@
>>> +/*
>>> + * OMAP EHCI port support
>>> + * Based on LINUX KERNEL
>>> + * drivers/usb/host/ehci-omap.c and drivers/mfd/omap-usb-host.c
>>> + *
>>> + * Copyright (C) 2011 Texas Instruments Incorporated - http://www.ti.com
>>> + * Author: Govindraj R <govindraj.raja@ti.com>
>>> + *
>>> + * This program is free software: you can redistribute it and/or modify
>>> + * it under the terms of the GNU General Public License version 2  of
>>> + * the License as published by the Free Software Foundation.
>>> + *
>>> + * This program is distributed in the hope that it will be useful,
>>> + * but WITHOUT ANY WARRANTY; without even the implied warranty of
>>> + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
>>> + * GNU General Public License for more details.
>>> + *
>>> + * You should have received a copy of the GNU General Public License
>>> + * along with this program. If not, see <http://www.gnu.org/licenses/>.
>>> + */
>>> +
>>> +#ifndef _EHCI_H
>>> +#define _EHCI_H
>>
>> see what I mean? above you have _EHCI_H_ and here _EHCI_H...
>> That is too confusing...
>> IMO, something like _OMAP4_EHCI_H_ will do here.
>>
> 
> will correct it.
> 
> 
>>> +
>>> +#define OMAP_EHCI_BASE                               (OMAP44XX_L4_CORE_BASE + 0x64C00)
>>> +#define OMAP_UHH_BASE                                (OMAP44XX_L4_CORE_BASE + 0x64000)
>>> +#define OMAP_USBTLL_BASE                     (OMAP44XX_L4_CORE_BASE + 0x62000)
>>> +
>>> +/* UHH, TLL and opt clocks */
>>> +#define CM_L3INIT_HSUSBHOST_CLKCTRL          0x4A009358UL
>>> +
>>> +#define HSUSBHOST_CLKCTRL_CLKSEL_UTMI_P1_MASK        (1 << 24)
>>> +
>>> +/* TLL Register Set */
>>> +#define OMAP_USBTLL_SYSCONFIG_SIDLEMODE              (1 << 3)
>>> +#define OMAP_USBTLL_SYSCONFIG_ENAWAKEUP              (1 << 2)
>>> +#define OMAP_USBTLL_SYSCONFIG_SOFTRESET              (1 << 1)
>>> +#define OMAP_USBTLL_SYSCONFIG_CACTIVITY              (1 << 8)
>>> +#define OMAP_USBTLL_SYSSTATUS_RESETDONE              1
>>> +
>>> +#define OMAP_UHH_SYSCONFIG_SOFTRESET         1
>>> +#define OMAP_UHH_SYSSTATUS_EHCI_RESETDONE    (1 << 2)
>>> +#define OMAP_UHH_SYSCONFIG_NOIDLE            (1 << 2)
>>> +#define OMAP_UHH_SYSCONFIG_NOSTDBY           (1 << 4)
>>> +
>>> +#define OMAP_UHH_SYSCONFIG_VAL       (OMAP_UHH_SYSCONFIG_NOIDLE | \
>>> +                                     OMAP_UHH_SYSCONFIG_NOSTDBY)
>>> +
>>> +#endif /* _EHCI_H */
>>> diff --git a/arch/arm/include/asm/ehci-omap.h b/arch/arm/include/asm/ehci-omap.h
>>> new file mode 100644
>>> index 0000000..ac68db7
>>> --- /dev/null
>>> +++ b/arch/arm/include/asm/ehci-omap.h
>>> @@ -0,0 +1,147 @@
>>> +/*
>>> + * OMAP EHCI port support
>>> + * Based on LINUX KERNEL
>>> + * drivers/usb/host/ehci-omap.c and drivers/mfd/omap-usb-host.c
>>> + *
>>> + * Copyright (C) 2011 Texas Instruments Incorporated - http://www.ti.com*
>>> + * Author: Govindraj R <govindraj.raja@ti.com>
>>> + *
>>> + * This program is free software: you can redistribute it and/or modify
>>> + * it under the terms of the GNU General Public License version 2  of
>>> + * the License as published by the Free Software Foundation.
>>> + *
>>> + * This program is distributed in the hope that it will be useful,
>>> + * but WITHOUT ANY WARRANTY; without even the implied warranty of
>>> + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
>>> + * GNU General Public License for more details.
>>> + *
>>> + * You should have received a copy of the GNU General Public License
>>> + * along with this program. If not, see <http://www.gnu.org/licenses/>.
>>> + */
>>> +
>>> +#ifndef EHCI_H
>>> +#define EHCI_H
>>
>> And even worth... now there are three of them!!!
>> No, this is not good... what about OMAP5 will it be EHCI__H?
>> Probably here, something like _OMAP_COMMON_EHCI_H_ will do?
>>
> 
> sure will do it.
> 
>>> +
>>> +enum usbhs_omap_port_mode {
>>> +     OMAP_USBHS_PORT_MODE_UNUSED,
>>> +     OMAP_EHCI_PORT_MODE_PHY,
>>> +     OMAP_EHCI_PORT_MODE_TLL,
>>> +     OMAP_EHCI_PORT_MODE_HSIC,
>>> +};
>>> +
>>> +#ifdef CONFIG_SYS_USB_EHCI_MAX_ROOT_PORTS
>>> +#define OMAP_HS_USB_PORTS    CONFIG_SYS_USB_EHCI_MAX_ROOT_PORTS
>>> +#else
>>> +#define OMAP_HS_USB_PORTS    3
>>> +#endif
>>> +
>>> +#define is_ehci_phy_mode(x)  ((x) == OMAP_EHCI_PORT_MODE_PHY)
>>> +#define is_ehci_tll_mode(x)  ((x) == OMAP_EHCI_PORT_MODE_TLL)
>>> +#define is_ehci_hsic_mode(x) ((x) == OMAP_EHCI_PORT_MODE_HSIC)
>>> +
>>> +/* Values of UHH_REVISION - Note: these are not given in the TRM */
>>> +#define OMAP_USBHS_REV1                                      0x00000010 /* OMAP3 */
>>> +#define OMAP_USBHS_REV2                                      0x50700100 /* OMAP4 */
>>> +
>>> +/* UHH Register Set */
>>> +#define OMAP_UHH_HOSTCONFIG_INCR4_BURST_EN           (1 << 2)
>>> +#define OMAP_UHH_HOSTCONFIG_INCR8_BURST_EN           (1 << 3)
>>> +#define OMAP_UHH_HOSTCONFIG_INCR16_BURST_EN          (1 << 4)
>>> +#define OMAP_UHH_HOSTCONFIG_INCRX_ALIGN_EN           (1 << 5)
>>> +
>>> +#define OMAP_UHH_HOSTCONFIG_ULPI_P1_BYPASS           1
>>> +#define OMAP_UHH_HOSTCONFIG_ULPI_P2_BYPASS           (1 << 11)
>>> +#define OMAP_UHH_HOSTCONFIG_ULPI_P3_BYPASS           (1 << 12)
>>> +#define OMAP4_UHH_HOSTCONFIG_APP_START_CLK           (1 << 31)
>>> +
>>> +#define OMAP_P1_MODE_CLEAR                           (3 << 16)
>>> +#define OMAP_P1_MODE_TLL                             (1 << 16)
>>> +#define OMAP_P1_MODE_HSIC                            (3 << 16)
>>> +#define OMAP_P2_MODE_CLEAR                           (3 << 18)
>>> +#define OMAP_P2_MODE_TLL                             (1 << 18)
>>> +#define OMAP_P2_MODE_HSIC                            (3 << 18)
>>> +
>>> +/* EHCI Register Set */
>>> +#define EHCI_INSNREG04_DISABLE_UNSUSPEND             (1 << 5)
>>> +#define EHCI_INSNREG05_ULPI_CONTROL_SHIFT            31
>>> +#define EHCI_INSNREG05_ULPI_PORTSEL_SHIFT            24
>>> +#define EHCI_INSNREG05_ULPI_OPSEL_SHIFT                      22
>>> +#define EHCI_INSNREG05_ULPI_REGADD_SHIFT             16
>>> +
>>> +#define OMAP_REV1_TLL_CHANNEL_COUNT                  3
>>> +#define OMAP_REV2_TLL_CHANNEL_COUNT                  2
>>> +
>>> +/* TLL Register Set */
>>> +#define OMAP_TLL_CHANNEL_CONF(num)                   (0x004 * num)
>>> +#define OMAP_TLL_CHANNEL_CONF_DRVVBUS                        (1 << 16)
>>> +#define OMAP_TLL_CHANNEL_CONF_CHRGVBUS                       (1 << 15)
>>> +#define OMAP_TLL_CHANNEL_CONF_ULPINOBITSTUFF         (1 << 11)
>>> +#define OMAP_TLL_CHANNEL_CONF_CHANMODE_TRANSPARENT_UTMI      (2 << 1)
>>> +#define OMAP_TLL_CHANNEL_CONF_CHANEN                 1
>>> +
>>> +/* ULPI */
>>> +#define ULPI_SET(a)                                  (a + 1)
>>
>> This is the offset of each "set" register of ULPI PHY
>>
>>> +#define ULPI_CLR(a)                                  (a + 2)
>>
>> This is the offset of each "clear" register of ULPI PHY
>>
>>> +#define ULPI_FUNC_CTRL                                       0x04
>>
>> This is the offset of the "Function Control register" of the ULPI PHY
>> This is already defined as ulpi_regs.function_ctrl member in
>> include/usb/ulpi.h file.
>>
>>> +#define ULPI_FUNC_CTRL_RESET                         (1 << 5)
>>
>> This is the reset bin inside the "Function Control register" of the ULPI PHY
>> This bit is already defined in the include/usb/ulpi.h file.
>>
> 
> yes but these are not dedicated reg maps that can be written.

Well, they are, but over the ULPI... just like "any" other bus...

> 
> on omap usb host controller is coupled with tll module to compose the
> ULPI TLL interface
> and the way to speak to them is using the INSNREG05_ULPI which has the
> reg address field
> and value to be written.
> 
> ulpi framework needs a full reg map to read write registers.

No, the reg map is virtual and is supplied as the register offset:
U-Boot: line 38 in drivers/usb/ulpi/ulpi.c:
static struct ulpi_regs *ulpi = (struct ulpi_regs *)0;

> 
> [..]
> 
> ulpi_write(ulpi_viewport,
>                         &ulpi->function_ctrl_set, ULPI_FC_RESET);
> 
> [..]
> 
> from above code snip what we need is dedicated ulpi reg start address
> to get func ctrl.

No you don't. As I've already said, it is virtual (e.g. 0x0).
Current ULPI framework deals with it, after adding the ability to
specify the port number, you will only need to call the correct
API function, in your case the ulpi_reset().

> 
> so these api's cannot be used.

It can be used, but the port number needs to be passed.

> 
>>> +
>>> +struct omap_usbhs_board_data {
>>> +     enum usbhs_omap_port_mode port_mode[OMAP_HS_USB_PORTS];
>>> +};
>>> +
>>> +struct omap_usbtll {
>>> +     u32 rev;                /* 0x00 */
>>> +     u32 hwinfo;             /* 0x04 */
>>> +     u8 reserved1[0x8];
>>> +     u32 sysc;               /* 0x10 */
> 
> [...]
> 
>>> +}
>>> +
>>> +static void omap_ehci_soft_phy_reset(int port)
>>> +{
>>> +     unsigned int reg = 0;
>>> +     unsigned long init = get_timer(0);
>>> +
>>> +     /* FUNCTION_CTRL_SET register */
>>> +     reg = ULPI_FUNC_CTRL_RESET |
>>> +             (ULPI_SET(ULPI_FUNC_CTRL) << EHCI_INSNREG05_ULPI_REGADD_SHIFT) |
>>> +             (2 << EHCI_INSNREG05_ULPI_OPSEL_SHIFT) |
>>> +             ((port + 1) << EHCI_INSNREG05_ULPI_PORTSEL_SHIFT) |
>>> +             (1 << EHCI_INSNREG05_ULPI_CONTROL_SHIFT);
>>> +
>>> +     writel(reg, &ehci->insreg05_utmi_ulpi);
>>> +
>>> +     /* Wait for ULPI access completion */
>>> +     while ((readl(&ehci->insreg05_utmi_ulpi) &
>>> +                     (1 << EHCI_INSNREG05_ULPI_CONTROL_SHIFT)))
>>> +             if (get_timer(init) > CONFIG_SYS_HZ) {
>>> +                     debug("OMAP EHCI error: timeout resetting phy\n");
>>> +                     break;
>>> +             }
>>> +}
>>
>> Ok, this function is kind of "duplication" of the ULPI code.
>> ulpi_reset() function in drivers/usb/ulpi/ulpi.c provides an implementation
>> of the ULPI spec. and should be used by the drivers.
>> What it lacks currently, is a way to pass a port number to the viewport
>> implementation and of course the omap-ulpi-viewport(.c) implementation itself...
>> So, IMO, the right way would be to implement ULPI accessors (omap-ulpi-viewport.c)
> 
> so you mean add omap-ulpi-viewport.c which will do ulpi read writes
> for ulpi implementation
> within tll module of omap host controller.

No. What I meant is that omap-ulpi-viewport.c will do the ULPI access
to the PHY (which is not TLL), but after the above question, I think
it can do both: TLL and non-TLL.

> 
> we just need func reset to be done for ulpi which is done using ehci register
> INSNREG05_ULPI. IMHO I don't see any use case or true requirement of
> omap-ulpi-viewport.c framework.

The fact that the reset is done by writing the ULPI_FUNC_CTRL_RESET bit
of the ULPI_FUNC_CTRL register - is the requirement...
For example tomorrow, you will find out that besides reset, you also need
to set some other bit in a register inside the ULPI PHY (e.g. VBUS), so
you will implement another "ehci" function that will do a write to ULPI
and thus duplicate another portion of code...

> 
>> and add an ability to pass some kind of private data to the viewport, which
>> in case of OMAP will be the port number.
>>
>> Now, I know, that this will add much more code then this function does, but
>> it is always about using frameworks, otherwise each board file can implement
>> the whole U-Boot startup....
>>
>> +
>>>  inline int __board_usb_init(void)
>>>  {
>>>       return 0;
>>> @@ -72,31 +151,31 @@ static inline void omap_ehci_phy_reset(int on, int delay)
>>>  #endif
>>>
>>>  /* Reset is needed otherwise the kernel-driver will throw an error. */
>>> -int ehci_hcd_stop(void)
>>> +int omap_ehci_hcd_stop(void)
>>>  {
>>> -     debug("Resetting OMAP3 EHCI\n");
>>> +     debug("Resetting OMAP EHCI\n");
>>>       omap_ehci_phy_reset(1, 0);
>>> -     writel(OMAP_UHH_SYSCONFIG_SOFTRESET,
>>> -                     OMAP3_UHH_BASE + OMAP_UHH_SYSCONFIG);
>>> -     /* disable USB clocks */
>>> -     struct prcm *prcm_base = (struct prcm *)PRCM_BASE;
>>> -     sr32(&prcm_base->iclken_usbhost, 0, 1, 0);
>>> -     sr32(&prcm_base->fclken_usbhost, 0, 2, 0);
>>> -     sr32(&prcm_base->iclken3_core, 2, 1, 0);
>>> -     sr32(&prcm_base->fclken3_core, 2, 1, 0);
>>> +
>>> +     if (omap_uhh_reset() < 0)
>>> +             return -1;
>>> +
>>> +     if (omap_ehci_tll_reset() < 0)
>>> +             return -1;
>>> +
>>>       return 0;
>>>  }
>>>
>>>  /*
>>> - * Initialize the OMAP3 EHCI controller and PHY.
>>> - * Based on "drivers/usb/host/ehci-omap.c" from Linux 2.6.37.
>>> + * Initialize the OMAP EHCI controller and PHY.
>>> + * Based on "drivers/usb/host/ehci-omap.c" from Linux 3.1
>>>   * See there for additional Copyrights.
>>>   */
>>> -int ehci_hcd_init(void)
>>> +int omap_ehci_hcd_init(struct omap_usbhs_board_data *usbhs_pdata)
>>>  {
>>> -     int ret;
>>> +     int ret = 0;
>>> +     unsigned int i, reg = 0, rev = 0, tll_cnt = 0;
>>>
>>> -     debug("Initializing OMAP3 EHCI\n");
>>> +     debug("Initializing OMAP EHCI\n");
>>>
>>>       ret = board_usb_init();
>>>       if (ret < 0)
>>> @@ -105,52 +184,89 @@ int ehci_hcd_init(void)
>>>       /* Put the PHY in RESET */
>>>       omap_ehci_phy_reset(1, 10);
>>>
>>> -     struct prcm *prcm_base = (struct prcm *)PRCM_BASE;
>>> -     /* Enable USBHOST_L3_ICLK (USBHOST_MICLK) */
>>> -     sr32(&prcm_base->iclken_usbhost, 0, 1, 1);
>>> -     /*
>>> -      * Enable USBHOST_48M_FCLK (USBHOST_FCLK1)
>>> -      * and USBHOST_120M_FCLK (USBHOST_FCLK2)
>>> -      */
>>> -     sr32(&prcm_base->fclken_usbhost, 0, 2, 3);
>>> -     /* Enable USBTTL_ICLK */
>>> -     sr32(&prcm_base->iclken3_core, 2, 1, 1);
>>> -     /* Enable USBTTL_FCLK */
>>> -     sr32(&prcm_base->fclken3_core, 2, 1, 1);
>>> -     debug("USB clocks enabled\n");
>>> +     ret = omap_uhh_reset();
>>> +     if (ret < 0)
>>> +             return ret;
>>>
>>> -     /* perform TLL soft reset, and wait until reset is complete */
>>> -     writel(OMAP_USBTLL_SYSCONFIG_SOFTRESET,
>>> -             OMAP3_USBTLL_BASE + OMAP_USBTLL_SYSCONFIG);
>>> -     /* Wait for TLL reset to complete */
>>> -     while (!(readl(OMAP3_USBTLL_BASE + OMAP_USBTLL_SYSSTATUS)
>>> -                     & OMAP_USBTLL_SYSSTATUS_RESETDONE))
>>> -             ;
>>> -     debug("TLL reset done\n");
>>> +     ret = omap_ehci_tll_reset();
>>> +     if (ret)
>>> +             return ret;
>>
>> You do both resets unconditionally, shouldn't you check which mode
>> the port is in and only reset the right one?
>> Is it because all of them need to be configurred?
>>
> 
> yes, and to set sys_config register settings.

Ok.
Govindraj Jan. 25, 2012, 9:04 a.m. UTC | #4
Hi Igor,

On Sun, Jan 22, 2012 at 5:50 PM, Igor Grinberg <grinberg@compulab.co.il> wrote:
> On 01/19/12 10:15, Govindraj wrote:
>> On Wed, Jan 18, 2012 at 11:21 PM, Igor Grinberg <grinberg@compulab.co.il> wrote:
>>> Hi Govindraj,
>>>
>>> On 01/17/12 08:10, Govindraj wrote:
>>>>

[...]

>>>> +             if (get_timer(init) > CONFIG_SYS_HZ) {
>>>> +                     debug("OMAP EHCI error: timeout resetting phy\n");
>>>> +                     break;
>>>> +             }
>>>> +}
>>>
>>> Ok, this function is kind of "duplication" of the ULPI code.
>>> ulpi_reset() function in drivers/usb/ulpi/ulpi.c provides an implementation
>>> of the ULPI spec. and should be used by the drivers.
>>> What it lacks currently, is a way to pass a port number to the viewport
>>> implementation and of course the omap-ulpi-viewport(.c) implementation itself...
>>> So, IMO, the right way would be to implement ULPI accessors (omap-ulpi-viewport.c)
>>
>> so you mean add omap-ulpi-viewport.c which will do ulpi read writes
>> for ulpi implementation
>> within tll module of omap host controller.
>
> No. What I meant is that omap-ulpi-viewport.c will do the ULPI access
> to the PHY (which is not TLL), but after the above question, I think
> it can do both: TLL and non-TLL.
>
>>
>> we just need func reset to be done for ulpi which is done using ehci register
>> INSNREG05_ULPI. IMHO I don't see any use case or true requirement of
>> omap-ulpi-viewport.c framework.
>
> The fact that the reset is done by writing the ULPI_FUNC_CTRL_RESET bit
> of the ULPI_FUNC_CTRL register - is the requirement...
> For example tomorrow, you will find out that besides reset, you also need
> to set some other bit in a register inside the ULPI PHY (e.g. VBUS), so
> you will implement another "ehci" function that will do a write to ULPI
> and thus duplicate another portion of code...
>
>>
>>> and add an ability to pass some kind of private data to the viewport, which
>>> in case of OMAP will be the port number.


I started on adding omap-ulpi-viewport.c which will work with ulpi.c
if omap_ehci.c is used.

for port id can we just set a global data field that will inform the
omap_view port
on the port id, or we have to modify most api's syntax in
"drivers/usb/ulpi/ulpi.c"

Is it okay to have the port id from ehci-omap.c set and used in
"drivers/usb/ulpi/omap-ulpi-viewport.c" ?

--
Thanks,
Govindraj.R
Igor Grinberg Jan. 25, 2012, 1:40 p.m. UTC | #5
Hi Govindraj,

On 01/25/12 11:04, Govindraj wrote:
> Hi Igor,
> 
> On Sun, Jan 22, 2012 at 5:50 PM, Igor Grinberg <grinberg@compulab.co.il> wrote:
>> On 01/19/12 10:15, Govindraj wrote:
>>> On Wed, Jan 18, 2012 at 11:21 PM, Igor Grinberg <grinberg@compulab.co.il> wrote:
>>>> Hi Govindraj,
>>>>
>>>> On 01/17/12 08:10, Govindraj wrote:
>>>>>

[...]

>>>> and add an ability to pass some kind of private data to the viewport, which
>>>> in case of OMAP will be the port number.
> 
> 
> I started on adding omap-ulpi-viewport.c which will work with ulpi.c
> if omap_ehci.c is used.

Good! Thanks for working on that.

> 
> for port id can we just set a global data field that will inform the
> omap_view port
> on the port id, or we have to modify most api's syntax in
> "drivers/usb/ulpi/ulpi.c"

IMO, we should modify the API, because it does not make sense
to use the generic layer, but workaround some missing feature...

My suggestion for the change is:
1) introduce some kind of
struct ulpi_viewport {
	u32 viewport_addr;
	uint portnum;
}

2) use the above struct _instead_ of the "u32 ulpi_viewport" parameter

Another way, would be instead of uint portnum, use void *private_data,
but I think it will just complicate things too much and there will be no
real benefit (and also will add, otherwise needless, castings).
If the above structure will not be enough for some platform,
it can be extended easily and without changing the API anymore.
diff mbox

Patch

diff --git a/arch/arm/include/asm/arch-omap3/ehci.h
b/arch/arm/include/asm/arch-omap3/ehci.h
new file mode 100644
index 0000000..d622363
--- /dev/null
+++ b/arch/arm/include/asm/arch-omap3/ehci.h
@@ -0,0 +1,55 @@ 
+/*
+ * (C) Copyright 2011
+ * Alexander Holler <holler@ahsoftware.de>
+ *
+ * Based on "drivers/usb/host/ehci-omap.c" from Linux 2.6.37
+ *
+ * See there for additional Copyrights.
+ *
+ * See file CREDITS for list of people who contributed to this
+ * project.
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU General Public License as
+ * published by the Free Software Foundation; either version 2 of
+ * the License, or (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
+ * MA 02110-1301 USA
+ */
+#ifndef _EHCI_H_
+#define _EHCI_H_
+
+/* USB/EHCI registers */
+#define OMAP_USBTLL_BASE				0x48062000UL
+#define OMAP_UHH_BASE					0x48064000UL
+#define OMAP_EHCI_BASE					0x48064800UL
+
+/* TLL Register Set */
+#define OMAP_USBTLL_SYSCONFIG_SOFTRESET			(1 << 1)
+#define OMAP_USBTLL_SYSCONFIG_ENAWAKEUP			(1 << 2)
+#define OMAP_USBTLL_SYSCONFIG_SIDLEMODE			(1 << 3)
+#define OMAP_USBTLL_SYSCONFIG_CACTIVITY			(1 << 8)
+#define OMAP_USBTLL_SYSSTATUS_RESETDONE			1
+
+/* UHH Register Set */
+#define OMAP_UHH_SYSCONFIG_SOFTRESET			(1 << 1)
+#define OMAP_UHH_SYSCONFIG_CACTIVITY			(1 << 8)
+#define OMAP_UHH_SYSCONFIG_SIDLEMODE			(1 << 3)
+#define OMAP_UHH_SYSCONFIG_ENAWAKEUP			(1 << 2)
+#define OMAP_UHH_SYSCONFIG_MIDLEMODE			(1 << 12)
+#define OMAP_UHH_SYSSTATUS_EHCI_RESETDONE		(1 << 2)
+
+#define OMAP_UHH_SYSCONFIG_VAL		(OMAP_UHH_SYSCONFIG_CACTIVITY | \
+					OMAP_UHH_SYSCONFIG_SIDLEMODE | \
+					OMAP_UHH_SYSCONFIG_ENAWAKEUP | \
+					OMAP_UHH_SYSCONFIG_MIDLEMODE)
+
+#endif /* _EHCI_H_ */
diff --git a/arch/arm/include/asm/arch-omap3/ehci_omap3.h
b/arch/arm/include/asm/arch-omap3/ehci_omap3.h
deleted file mode 100644
index cd01f50..0000000
--- a/arch/arm/include/asm/arch-omap3/ehci_omap3.h
+++ /dev/null
@@ -1,58 +0,0 @@ 
-/*
- * (C) Copyright 2011
- * Alexander Holler <holler@ahsoftware.de>
- *
- * Based on "drivers/usb/host/ehci-omap.c" from Linux 2.6.37
- *
- * See there for additional Copyrights.
- *
- * See file CREDITS for list of people who contributed to this
- * project.
- *
- * This program is free software; you can redistribute it and/or
- * modify it under the terms of the GNU General Public License as
- * published by the Free Software Foundation; either version 2 of
- * the License, or (at your option) any later version.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with this program; if not, write to the Free Software
- * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
- * MA 02110-1301 USA
- */
-#ifndef _EHCI_OMAP3_H_
-#define _EHCI_OMAP3_H_
-
-/* USB/EHCI registers */
-#define OMAP3_USBTLL_BASE				0x48062000UL
-#define OMAP3_UHH_BASE					0x48064000UL
-#define OMAP3_EHCI_BASE					0x48064800UL
-
-/* TLL Register Set */
-#define	OMAP_USBTLL_SYSCONFIG				(0x10)
-#define	OMAP_USBTLL_SYSCONFIG_SOFTRESET			(1 << 1)
-#define	OMAP_USBTLL_SYSCONFIG_ENAWAKEUP			(1 << 2)
-#define	OMAP_USBTLL_SYSCONFIG_SIDLEMODE			(1 << 3)
-#define	OMAP_USBTLL_SYSCONFIG_CACTIVITY			(1 << 8)
-
-#define	OMAP_USBTLL_SYSSTATUS				(0x14)
-#define	OMAP_USBTLL_SYSSTATUS_RESETDONE			(1 << 0)
-
-/* UHH Register Set */
-#define	OMAP_UHH_SYSCONFIG				(0x10)
-#define	OMAP_UHH_SYSCONFIG_SOFTRESET			(1 << 1)
-#define	OMAP_UHH_SYSCONFIG_CACTIVITY			(1 << 8)
-#define	OMAP_UHH_SYSCONFIG_SIDLEMODE			(1 << 3)
-#define	OMAP_UHH_SYSCONFIG_ENAWAKEUP			(1 << 2)
-#define	OMAP_UHH_SYSCONFIG_MIDLEMODE			(1 << 12)
-
-#define	OMAP_UHH_HOSTCONFIG				(0x40)
-#define OMAP_UHH_HOSTCONFIG_INCR4_BURST_EN		(1 << 2)
-#define OMAP_UHH_HOSTCONFIG_INCR8_BURST_EN		(1 << 3)
-#define OMAP_UHH_HOSTCONFIG_INCR16_BURST_EN		(1 << 4)
-
-#endif /* _EHCI_OMAP3_H_ */
diff --git a/arch/arm/include/asm/arch-omap4/ehci.h
b/arch/arm/include/asm/arch-omap4/ehci.h
new file mode 100644
index 0000000..eaa82cf
--- /dev/null
+++ b/arch/arm/include/asm/arch-omap4/ehci.h
@@ -0,0 +1,49 @@ 
+/*
+ * OMAP EHCI port support
+ * Based on LINUX KERNEL
+ * drivers/usb/host/ehci-omap.c and drivers/mfd/omap-usb-host.c
+ *
+ * Copyright (C) 2011 Texas Instruments Incorporated - http://www.ti.com
+ * Author: Govindraj R <govindraj.raja@ti.com>
+ *
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License version 2  of
+ * the License as published by the Free Software Foundation.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program. If not, see <http://www.gnu.org/licenses/>.
+ */
+
+#ifndef _EHCI_H
+#define _EHCI_H
+
+#define OMAP_EHCI_BASE				(OMAP44XX_L4_CORE_BASE + 0x64C00)
+#define OMAP_UHH_BASE				(OMAP44XX_L4_CORE_BASE + 0x64000)
+#define OMAP_USBTLL_BASE			(OMAP44XX_L4_CORE_BASE + 0x62000)
+
+/* UHH, TLL and opt clocks */
+#define CM_L3INIT_HSUSBHOST_CLKCTRL		0x4A009358UL
+
+#define HSUSBHOST_CLKCTRL_CLKSEL_UTMI_P1_MASK	(1 << 24)
+
+/* TLL Register Set */
+#define OMAP_USBTLL_SYSCONFIG_SIDLEMODE		(1 << 3)
+#define OMAP_USBTLL_SYSCONFIG_ENAWAKEUP		(1 << 2)
+#define OMAP_USBTLL_SYSCONFIG_SOFTRESET		(1 << 1)
+#define OMAP_USBTLL_SYSCONFIG_CACTIVITY		(1 << 8)
+#define OMAP_USBTLL_SYSSTATUS_RESETDONE		1
+
+#define OMAP_UHH_SYSCONFIG_SOFTRESET		1
+#define OMAP_UHH_SYSSTATUS_EHCI_RESETDONE	(1 << 2)
+#define OMAP_UHH_SYSCONFIG_NOIDLE		(1 << 2)
+#define OMAP_UHH_SYSCONFIG_NOSTDBY		(1 << 4)
+
+#define OMAP_UHH_SYSCONFIG_VAL	(OMAP_UHH_SYSCONFIG_NOIDLE | \
+					OMAP_UHH_SYSCONFIG_NOSTDBY)
+
+#endif /* _EHCI_H */
diff --git a/arch/arm/include/asm/ehci-omap.h b/arch/arm/include/asm/ehci-omap.h
new file mode 100644
index 0000000..ac68db7
--- /dev/null
+++ b/arch/arm/include/asm/ehci-omap.h
@@ -0,0 +1,147 @@ 
+/*
+ * OMAP EHCI port support
+ * Based on LINUX KERNEL
+ * drivers/usb/host/ehci-omap.c and drivers/mfd/omap-usb-host.c
+ *
+ * Copyright (C) 2011 Texas Instruments Incorporated - http://www.ti.com*
+ * Author: Govindraj R <govindraj.raja@ti.com>
+ *
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License version 2  of
+ * the License as published by the Free Software Foundation.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program. If not, see <http://www.gnu.org/licenses/>.
+ */
+
+#ifndef EHCI_H
+#define EHCI_H
+
+enum usbhs_omap_port_mode {
+	OMAP_USBHS_PORT_MODE_UNUSED,
+	OMAP_EHCI_PORT_MODE_PHY,
+	OMAP_EHCI_PORT_MODE_TLL,
+	OMAP_EHCI_PORT_MODE_HSIC,
+};
+
+#ifdef CONFIG_SYS_USB_EHCI_MAX_ROOT_PORTS
+#define OMAP_HS_USB_PORTS	CONFIG_SYS_USB_EHCI_MAX_ROOT_PORTS
+#else
+#define OMAP_HS_USB_PORTS	3
+#endif
+
+#define is_ehci_phy_mode(x)	((x) == OMAP_EHCI_PORT_MODE_PHY)
+#define is_ehci_tll_mode(x)	((x) == OMAP_EHCI_PORT_MODE_TLL)
+#define is_ehci_hsic_mode(x)	((x) == OMAP_EHCI_PORT_MODE_HSIC)
+
+/* Values of UHH_REVISION - Note: these are not given in the TRM */
+#define OMAP_USBHS_REV1					0x00000010 /* OMAP3 */
+#define OMAP_USBHS_REV2					0x50700100 /* OMAP4 */
+
+/* UHH Register Set */
+#define OMAP_UHH_HOSTCONFIG_INCR4_BURST_EN		(1 << 2)
+#define OMAP_UHH_HOSTCONFIG_INCR8_BURST_EN		(1 << 3)
+#define OMAP_UHH_HOSTCONFIG_INCR16_BURST_EN		(1 << 4)
+#define OMAP_UHH_HOSTCONFIG_INCRX_ALIGN_EN		(1 << 5)
+
+#define OMAP_UHH_HOSTCONFIG_ULPI_P1_BYPASS		1
+#define OMAP_UHH_HOSTCONFIG_ULPI_P2_BYPASS		(1 << 11)
+#define OMAP_UHH_HOSTCONFIG_ULPI_P3_BYPASS		(1 << 12)
+#define OMAP4_UHH_HOSTCONFIG_APP_START_CLK		(1 << 31)
+
+#define OMAP_P1_MODE_CLEAR				(3 << 16)
+#define OMAP_P1_MODE_TLL				(1 << 16)
+#define OMAP_P1_MODE_HSIC				(3 << 16)
+#define OMAP_P2_MODE_CLEAR				(3 << 18)
+#define OMAP_P2_MODE_TLL				(1 << 18)
+#define OMAP_P2_MODE_HSIC				(3 << 18)
+
+/* EHCI Register Set */
+#define EHCI_INSNREG04_DISABLE_UNSUSPEND		(1 << 5)
+#define EHCI_INSNREG05_ULPI_CONTROL_SHIFT		31
+#define EHCI_INSNREG05_ULPI_PORTSEL_SHIFT		24
+#define EHCI_INSNREG05_ULPI_OPSEL_SHIFT			22
+#define EHCI_INSNREG05_ULPI_REGADD_SHIFT		16
+
+#define OMAP_REV1_TLL_CHANNEL_COUNT			3
+#define OMAP_REV2_TLL_CHANNEL_COUNT			2
+
+/* TLL Register Set */
+#define OMAP_TLL_CHANNEL_CONF(num)			(0x004 * num)
+#define OMAP_TLL_CHANNEL_CONF_DRVVBUS			(1 << 16)
+#define OMAP_TLL_CHANNEL_CONF_CHRGVBUS			(1 << 15)
+#define OMAP_TLL_CHANNEL_CONF_ULPINOBITSTUFF		(1 << 11)
+#define OMAP_TLL_CHANNEL_CONF_CHANMODE_TRANSPARENT_UTMI	(2 << 1)
+#define OMAP_TLL_CHANNEL_CONF_CHANEN			1
+
+/* ULPI */
+#define ULPI_SET(a)					(a + 1)
+#define ULPI_CLR(a)					(a + 2)
+#define ULPI_FUNC_CTRL					0x04
+#define ULPI_FUNC_CTRL_RESET				(1 << 5)
+
+struct omap_usbhs_board_data {
+	enum usbhs_omap_port_mode port_mode[OMAP_HS_USB_PORTS];
+};
+
+struct omap_usbtll {
+	u32 rev;		/* 0x00 */
+	u32 hwinfo;		/* 0x04 */
+	u8 reserved1[0x8];
+	u32 sysc;		/* 0x10 */
+	u32 syss;		/* 0x14 */
+	u32 irqst;		/* 0x18 */
+	u32 irqen;		/* 0x1c */
+	u8 reserved2[0x10];
+	u32 shared_conf;	/* 0x30 */
+	u8 reserved3[0xc];
+	u32 channel_conf;	/* 0x40 */
+};
+
+struct omap_uhh {
+	u32 rev;	/* 0x00 */
+	u32 hwinfo;	/* 0x04 */
+	u8 reserved1[0x8];
+	u32 sysc;	/* 0x10 */
+	u32 syss;	/* 0x14 */
+	u8 reserved2[0x28];
+	u32 hostconfig;	/* 0x40 */
+	u32 debugcsr;	/* 0x44 */
+};
+
+struct omap_ehci {
+	u32 hccapbase;		/* 0x00 */
+	u32 hcsparams;		/* 0x04 */
+	u32 hccparams;		/* 0x08 */
+	u8 reserved1[0x04];
+	u32 usbcmd;		/* 0x10 */
+	u32 usbsts;		/* 0x14 */
+	u32 usbintr;		/* 0x18 */
+	u32 frindex;		/* 0x1c */
+	u32 ctrldssegment;	/* 0x20 */
+	u32 periodiclistbase;	/* 0x24 */
+	u32 asysnclistaddr;	/* 0x28 */
+	u8 reserved2[0x24];
+	u32 configflag;		/* 0x50 */
+	u32 portsc_i;		/* 0x54 */
+	u8 reserved3[0x38];
+	u32 insreg00;		/* 0x90 */
+	u32 insreg01;		/* 0x94 */
+	u32 insreg02;		/* 0x98 */
+	u32 insreg03;		/* 0x9c */
+	u32 insreg04;		/* 0xa0 */
+	u32 insreg05_utmi_ulpi;	/* 0xa4 */
+	u32 insreg06;		/* 0xa8 */
+	u32 insreg07;		/* 0xac */
+	u32 insreg08;		/* 0xb0 */
+};
+
+int omap_ehci_hcd_init(struct omap_usbhs_board_data *usbhs_pdata);
+int omap_ehci_hcd_stop(void);
+
+#endif /* EHCI_H */
diff --git a/drivers/usb/host/ehci-omap.c b/drivers/usb/host/ehci-omap.c
index 93d3bb7..01c22e6 100644
--- a/drivers/usb/host/ehci-omap.c
+++ b/drivers/usb/host/ehci-omap.c
@@ -27,14 +27,93 @@ 
  */
 #include <common.h>
 #include <usb.h>
+#include <errno.h>
 #include <asm/io.h>
 #include <asm/gpio.h>
-#include <asm/arch/clocks.h>
-#include <asm/arch/clocks_omap3.h>
-#include <asm/arch/ehci_omap3.h>
-#include <asm/arch/sys_proto.h>
+#include <asm/arch/ehci.h>
+#include <asm/ehci-omap.h>
 #include "ehci-core.h"

+static struct omap_uhh *const uhh = (struct omap_uhh *)OMAP_UHH_BASE;
+static struct omap_usbtll *const usbtll = (struct omap_usbtll
*)OMAP_USBTLL_BASE;
+static struct omap_ehci *const ehci = (struct omap_ehci *)OMAP_EHCI_BASE;
+
+static int omap_uhh_reset(void)
+{
+	unsigned long init = get_timer(0);
+
+	/* perform UHH soft reset, and wait until reset is complete */
+	writel(OMAP_UHH_SYSCONFIG_SOFTRESET, &uhh->sysc);
+
+	/* Wait for UHH reset to complete */
+	while (!(readl(&uhh->syss) & OMAP_UHH_SYSSTATUS_EHCI_RESETDONE))
+		if (get_timer(init) > CONFIG_SYS_HZ) {
+			debug("OMAP UHH error: timeout resetting ehci\n");
+			return -EL3RST;
+		}
+
+	return 0;
+}
+
+static int omap_ehci_tll_reset(void)
+{
+	unsigned long init = get_timer(0);
+
+	/* perform TLL soft reset, and wait until reset is complete */
+	writel(OMAP_USBTLL_SYSCONFIG_SOFTRESET, &usbtll->sysc);
+
+	/* Wait for TLL reset to complete */
+	while (!(readl(&usbtll->syss) & OMAP_USBTLL_SYSSTATUS_RESETDONE))
+		if (get_timer(init) > CONFIG_SYS_HZ) {
+			debug("OMAP EHCI error: timeout resetting TLL\n");
+			return -EL3RST;
+	}
+
+	return 0;
+}
+
+static void omap_usbhs_hsic_init(int tll_cnt)
+{
+	unsigned int reg;
+	int i;
+
+	/* Enable channels now */
+	for (i = 0; i < tll_cnt; i++) {
+		reg = readl(&usbtll->channel_conf + OMAP_TLL_CHANNEL_CONF(i));
+
+		setbits_le32(&reg, (OMAP_TLL_CHANNEL_CONF_CHANMODE_TRANSPARENT_UTMI
+			| OMAP_TLL_CHANNEL_CONF_ULPINOBITSTUFF
+			| OMAP_TLL_CHANNEL_CONF_DRVVBUS
+			| OMAP_TLL_CHANNEL_CONF_CHRGVBUS
+			| OMAP_TLL_CHANNEL_CONF_CHANEN));
+
+		writel(reg, &usbtll->channel_conf + OMAP_TLL_CHANNEL_CONF(i));
+	}
+}
+
+static void omap_ehci_soft_phy_reset(int port)
+{
+	unsigned int reg = 0;
+	unsigned long init = get_timer(0);
+
+	/* FUNCTION_CTRL_SET register */
+	reg = ULPI_FUNC_CTRL_RESET |
+		(ULPI_SET(ULPI_FUNC_CTRL) << EHCI_INSNREG05_ULPI_REGADD_SHIFT) |
+		(2 << EHCI_INSNREG05_ULPI_OPSEL_SHIFT) |
+		((port + 1) << EHCI_INSNREG05_ULPI_PORTSEL_SHIFT) |
+		(1 << EHCI_INSNREG05_ULPI_CONTROL_SHIFT);
+
+	writel(reg, &ehci->insreg05_utmi_ulpi);
+
+	/* Wait for ULPI access completion */
+	while ((readl(&ehci->insreg05_utmi_ulpi) &
+			(1 << EHCI_INSNREG05_ULPI_CONTROL_SHIFT)))
+		if (get_timer(init) > CONFIG_SYS_HZ) {
+			debug("OMAP EHCI error: timeout resetting phy\n");
+			break;
+		}
+}
+
 inline int __board_usb_init(void)
 {