Tegra EHCI driver
Subsystems (5)
cover Tegra EHCI driver
This patch series adds support for EHCI compliant USB host controllers found in Tegra SoCs. The EHCI driver depends on the Tegra PHY configuration interface that is used by both the ehci driver and the gadget driver. Tested on 2.6.38rc4.
Benoit Goby (2):
[ARM] tegra: Add support for Tegra USB PHYs
usb: host: Add EHCI driver for NVIDIA Tegra SoCs
Gary King (1):
usb: host: ehci-hcd: Add controller_resets_phy quirk
Robert Morell (1):
USB: ehci: tegra: Align DMA transfers to 32 bytes
arch/arm/mach-tegra/Makefile | 1 + arch/arm/mach-tegra/include/mach/usb_phy.h | 83 +++ arch/arm/mach-tegra/usb_phy.c | 794 ++++++++++++++++++++++++++++ drivers/usb/Kconfig | 1 + drivers/usb/host/Kconfig | 8 + drivers/usb/host/ehci-hcd.c | 8 +- drivers/usb/host/ehci-tegra.c | 763 ++++++++++++++++++++++++++ drivers/usb/host/ehci.h | 1 + include/linux/tegra_usb.h | 35 ++ 9 files changed, 1693 insertions(+), 1 deletions(-) create mode 100644 arch/arm/mach-tegra/include/mach/usb_phy.h create mode 100644 arch/arm/mach-tegra/usb_phy.c create mode 100644 drivers/usb/host/ehci-tegra.c create mode 100644 include/linux/tegra_usb.h
Signature · 6 lines
1.7.3.1 -- To unsubscribe from this list: send the line "unsubscribe linux-usb" in the body of a message to [email protected] More majordomo info at http://vger.kernel.org/majordomo-info.html
A message that is not in the archive (sent off-list or not yet received): 1297228927-23497-1-git-send-email-benoit-z5hGa2qSFaRBDgjK7y7TUQ@public.gmane.org
PATCH 1/4 tegra: Add support for Tegra USB PHYs
Interface used by Tegra's gadget driver and ehci driver to power on and configure the USB PHYs.
--- arch/arm/mach-tegra/Makefile | 1 + arch/arm/mach-tegra/include/mach/usb_phy.h | 83 +++ arch/arm/mach-tegra/usb_phy.c | 794 ++++++++++++++++++++++++++++ 3 files changed, 878 insertions(+), 0 deletions(-) create mode 100644 arch/arm/mach-tegra/include/mach/usb_phy.h create mode 100644 arch/arm/mach-tegra/usb_phy.c
arch/arm/mach-tegra/Makefile +1 -0
@@ -15,6 +15,7 @@ obj-$(CONFIG_HOTPLUG_CPU) += hotplug.o obj-$(CONFIG_TEGRA_SYSTEM_DMA) += dma.o obj-$(CONFIG_CPU_FREQ) += cpu-tegra.o obj-$(CONFIG_TEGRA_PCI) += pcie.o +obj-$(CONFIG_USB_SUPPORT) += usb_phy.o obj-${CONFIG_MACH_HARMONY} += board-harmony.o obj-${CONFIG_MACH_HARMONY} += board-harmony-pinmux.o
arch/arm/mach-tegra/include/mach/usb_phy.h new file +83 -0
83 lines not on this page · raw message
arch/arm/mach-tegra/usb_phy.c new file +794 -0
794 lines not on this page · raw message
Signature · 6 lines
1.7.3.1 -- To unsubscribe from this list: send the line "unsubscribe linux-tegra" in the body of a message to [email protected] More majordomo info at http://vger.kernel.org/majordomo-info.html
A message that is not in the archive (sent off-list or not yet received): 1297228927-23497-2-git-send-email-benoit-z5hGa2qSFaRBDgjK7y7TUQ@public.gmane.org
Re: [PATCH 1/4] [ARM] tegra: Add support for Tegra USB PHYs
Quoted 5 lines · Benoit Goby
Interface used by Tegra's gadget driver and ehci driver to power on and configure the USB PHYs.
Signed-off-by Benoit Goby <[email protected]>---
For some reason this patch (along with patch 3) appears to contain spaces as indentation (no hard tabs), although patches 2 and 4 in this series have the correct tabs.
[...]
arch/arm/mach-tegra/usb_phy.c line 33
Quoted 2 lines
arch/arm/mach-tegra/usb_phy.c new file +2
-0+#define USB_USBSTS 0x144 +#define USB_USBSTS_PCI (1 << 2)
This doesn't appear to be used?
[...]
Quoted 7 lines
arch/arm/mach-tegra/usb_phy.c new file +7
-0+static DEFINE_SPINLOCK (utmip_pad_lock); +static int utmip_pad_count; + +static const int udc_freq_table[] = { +12000000 , +13000000 , +19200000 ,
arch/arm/mach-tegra/usb_phy.c line 166
Quoted 10 lines
arch/arm/mach-tegra/usb_phy.c new file +10
-0+ 26000000, +}; + +static const u8 udc_delay_table[][4 ] = { +/* ENABLE_DLY, STABLE_CNT, ACTIVE_DLY, XTAL_FREQ_CNT */ + {0x02 ,0x2F ,0x04 ,0x76 },/* 12 MHz */ + {0x02 ,0x33 ,0x05 ,0x7F },/* 13 MHz */ + {0x03 ,0x4B ,0x06 ,0xBB },/* 19.2 MHz */ + {0x04 ,0x66 ,0x09 ,0xFE },/* 26 Mhz */ +};
Use an array of structs here? Writing "UTMIP_PLL_ACTIVE_DLY_COUNT(udc_delay_table[phy->freq_sel][2])" below is a lot less clear and more prone to bugs than, say, "UTMIP_PLL_ACTIVE_DLY_COUNT(udc_delay_table[phy->freq_sel].active_dly)".
It'd be even better to combine all three tables into one; something like:
static const struct udc_... udc_table[] = {
{ .freq = 12000000,
.delay = {
.enable = 0x02,
.stable = 0x2f,
.active = 0x04
},
.xtal_freq_cnt = 0x76,
.debounce = 0x7530,
},
[... etc]
};[...]
arch/arm/mach-tegra/usb_phy.c line 201
Quoted 6 lines
arch/arm/mach-tegra/usb_phy.c new file +6
-0+static int utmip_pad_open (struct tegra_usb_phy *phy) +{ + phy->pad_clk =clk_get_sys ("utmip-pad" ,NULL ); +if (IS_ERR (phy->pad_clk)) { +pr_err ("%s: can't get utmip pad clock\n" , __func__); +return -1 ;
return PTR_ERR(phy->pad_clk);
Quoted 14 lines
arch/arm/mach-tegra/usb_phy.c new file +14
-0+ } + +if (phy->instance ==0 ) { + phy->pad_regs = phy->regs; + }else { + phy->pad_regs =ioremap (TEGRA_USB_BASE ,TEGRA_USB_SIZE ); +if (!phy->pad_regs) { +pr_err ("%s: can't remap usb registers\n" , __func__); +clk_put (phy->pad_clk); +return -ENOMEM ; + } + } +return 0 ; +}
[...]
arch/arm/mach-tegra/usb_phy.c line 251
Quoted 8 lines
arch/arm/mach-tegra/usb_phy.c new file +8
-0+static int utmip_pad_power_off (struct tegra_usb_phy *phy) +{ +unsigned long val, flags; +void __iomem *base = phy->pad_regs; + +if (!utmip_pad_count) { +pr_err ("%s: utmip pad already powered off\n" , __func__); +return -1 ;
return -EINVAL?
Quoted 19 lines
arch/arm/mach-tegra/usb_phy.c new file +19
-0+ } + +clk_enable (phy->pad_clk); + +spin_lock_irqsave (&utmip_pad_lock, flags); + +if (--utmip_pad_count ==0 ) { + val =readl (base +UTMIP_BIAS_CFG0 ); + val |=UTMIP_OTGPD |UTMIP_BIASPD ; +writel (val, base +UTMIP_BIAS_CFG0 ); + } + +spin_unlock_irqrestore (&utmip_pad_lock, flags); + +clk_disable (phy->pad_clk); + +return 0 ; +} +
[...]
arch/arm/mach-tegra/usb_phy.c line 573
Quoted 12 lines
arch/arm/mach-tegra/usb_phy.c new file +12
-0+static void ulpi_phy_power_on (struct tegra_usb_phy *phy) +{ +unsigned long val; +void __iomem *base = phy->regs; +struct tegra_ulpi_config *config = phy->config; + +gpio_direction_output (config->reset_gpio,0 ); +msleep (5 ); +gpio_direction_output (config->reset_gpio,1 ); + +clk_enable (phy->clk); +msleep (1 );
This msleep seems excessive. Does it take that long for the clock to settle?
Quoted 23 lines
arch/arm/mach-tegra/usb_phy.c new file +23
-0+ + val =readl (base +USB_SUSP_CTRL ); + val |=UHSIC_RESET ; +writel (val, base +USB_SUSP_CTRL ); + + val =readl (base +ULPI_TIMING_CTRL_0 ); + val |=ULPI_OUTPUT_PINMUX_BYP |ULPI_CLKOUT_PINMUX_BYP ; +writel (val, base +ULPI_TIMING_CTRL_0 ); + + val =readl (base +USB_SUSP_CTRL ); + val |=ULPI_PHY_ENABLE ; +writel (val, base +USB_SUSP_CTRL ); + + val =0 ; +writel (val, base +ULPI_TIMING_CTRL_1 ); + + val |=ULPI_DATA_TRIMMER_SEL (4 ); + val |=ULPI_STPDIRNXT_TRIMMER_SEL (4 ); + val |=ULPI_DIR_TRIMMER_SEL (4 ); +writel (val, base +ULPI_TIMING_CTRL_1 ); +udelay (10 ); + + val |=ULPI_DATA_TRIMMER_LOAD ;
arch/arm/mach-tegra/usb_phy.c line 606
Quoted 10 lines
arch/arm/mach-tegra/usb_phy.c new file +10
-0+ val |=ULPI_STPDIRNXT_TRIMMER_LOAD ; + val |=ULPI_DIR_TRIMMER_LOAD ; +writel (val, base +ULPI_TIMING_CTRL_1 ); + + val =ULPI_WAKEUP |ULPI_RD_RW_WRITE |ULPI_PORT (0 ); +writel (val, base +ULPI_VIEWPORT ); + +if (utmi_wait_register (base +ULPI_VIEWPORT ,ULPI_WAKEUP ,0 )) { +pr_err ("%s: timeout waiting for ulpi phy wakeup\n" , __func__); +return ;
Why does this function return void if it can fail? tegra_usb_phy_power_on() can propagate the error.
Quoted 19 lines
arch/arm/mach-tegra/usb_phy.c new file +19
-0+ } + +/* Fix VbusInvalid due to floating VBUS */ +ulpi_viewport_write (phy,0x08 ,0x40 ); +ulpi_viewport_write (phy,0x0B ,0x80 ); + + val =readl (base +USB_PORTSC1 ); + val |=USB_PORTSC1_WKOC |USB_PORTSC1_WKDS |USB_PORTSC1_WKCN ; +writel (val, base +USB_PORTSC1 ); + + val =readl (base +USB_SUSP_CTRL ); + val |=USB_SUSP_CLR ; +writel (val, base +USB_SUSP_CTRL ); +udelay (100 ); + + val =readl (base +USB_SUSP_CTRL ); + val &= ~USB_SUSP_CLR ; +writel (val, base +USB_SUSP_CTRL ); +}
[...]
Quoted 10 lines
arch/arm/mach-tegra/usb_phy.c new file +10
-0+struct tegra_usb_phy *tegra_usb_phy_open (int instance,void __iomem *regs, +void *config,enum tegra_usb_phy_mode phy_mode) +{ +struct tegra_usb_phy *phy; +struct tegra_ulpi_config *ulpi_config; +unsigned long parent_rate; +int freq_sel; +int err; + + phy =kmalloc (sizeof (struct tegra_usb_phy ),GFP_KERNEL );
arch/arm/mach-tegra/usb_phy.c line 663
Quoted 10 lines
arch/arm/mach-tegra/usb_phy.c new file +10
-0+if (!phy) +return ERR_PTR (-ENOMEM ); + + phy->instance = instance; + phy->regs = regs; + phy->config = config; + phy->mode = phy_mode; + +if (!phy->config) { +if (instance ==1 ) {
Instead of all of the (instance == 1) checks here and below (I count eleven separate places this is checked), it might be more readable to have a macro or static inline function such as bool phy_is_ulpi(phy).
Quoted 44 lines
arch/arm/mach-tegra/usb_phy.c new file +44
-0+pr_err ("%s: ulpi phy configuration missing" , __func__); + err = -EINVAL ; + goto err0; + }else { + phy->config = &utmip_default[instance]; + } + } + + phy->pll_u =clk_get_sys (NULL ,"pll_u" ); +if (IS_ERR (phy->pll_u)) { +pr_err ("Can't get pll_u clock\n" ); + err =PTR_ERR (phy->pll_u); + goto err0; + } +clk_enable (phy->pll_u); + + parent_rate =clk_get_rate (clk_get_parent (phy->pll_u)); +for (freq_sel =0 ; freq_sel <ARRAY_SIZE (udc_freq_table); freq_sel++) { +if (udc_freq_table[freq_sel] == parent_rate) +break ; + } +if (freq_sel ==ARRAY_SIZE (udc_freq_table)) { +pr_err ("invalid pll_u parent rate %ld\n" , parent_rate); + err = -EINVAL ; + goto err1; + } + phy->freq_sel = freq_sel; + +if (phy->instance ==1 ) { + ulpi_config = config; + phy->clk =clk_get_sys (NULL , ulpi_config->clk); +if (IS_ERR (phy->clk)) { +pr_err ("%s: can't get ulpi clock\n" , __func__); + err = -ENXIO ; + goto err1; + } +tegra_gpio_enable (ulpi_config->reset_gpio); +gpio_request (ulpi_config->reset_gpio,"ulpi_phy_reset_b" ); +gpio_direction_output (ulpi_config->reset_gpio,0 ); + }else { + err =utmip_pad_open (phy); +if (err <0 ) + goto err1; + }
arch/arm/mach-tegra/usb_phy.c line 717
Quoted 10 lines
arch/arm/mach-tegra/usb_phy.c new file +10
-0+ +return phy; + +err1: +clk_disable (phy->pll_u); +clk_put (phy->pll_u); +err0: +kfree (phy); +return ERR_PTR (err); +}
[...]
The rest seems okay.
Quoted 3 lines
--
1.7.3.1
--
To unsubscribe from this list: send the line "unsubscribe linux-tegra" in the body of a message to [email protected] More majordomo info at http://vger.kernel.org/majordomo-info.html
A message that is not in the archive (sent off-list or not yet received): 20110209070540.GA17627-f3YH7lVHJt/FT5IIyIEb6QC/[email protected]
Re: [PATCH 1/4] [ARM] tegra: Add support for Tegra USB PHYs
Quoted 18 lines · On Tue, Feb 8, 2011 at 11:05 PM, <[email protected].…
arch/arm/mach-tegra/usb_phy.c line 573
Quoted 12 lines · Benoit Goby
arch/arm/mach-tegra/usb_phy.c new file +12
-0+static void ulpi_phy_power_on (struct tegra_usb_phy *phy) +{ + unsigned long val; + void __iomem *base = phy->regs; + struct tegra_ulpi_config *config = phy->config; + + gpio_direction_output(config->reset_gpio, 0); + msleep(5); + gpio_direction_output(config->reset_gpio, 1); + + clk_enable(phy->clk); + msleep(1);This msleep seems excessive. Does it take that long for the clock to settle?
I tried to use smaller delays but got enumeration issues with delays <1ms, so I'm keeping the msleep.
Benoit
--
To unsubscribe from this list: send the line "unsubscribe linux-tegra" in the body of a message to [email protected] More majordomo info at http://vger.kernel.org/majordomo-info.html
Re: [PATCH 1/4] [ARM] tegra: Add support for Tegra USB PHYs
In reply to a message not in the archiveHello,
Quoted 10 lines · Benoit Goby
Interface used by Tegra's gadget driver and ehci driver to power on and configure the USB PHYs.
+ */
arch/arm/mach-tegra/usb_phy.c new file +6
-0+ +#include <linux/resource.h> +#include <linux/delay.h> +#include <linux/slab.h> +#include <linux/err.h> +#include <linux/platform_device.h>
arch/arm/mach-tegra/usb_phy.c line 35
Quoted 10 lines
arch/arm/mach-tegra/usb_phy.c new file +10
-0+#include <linux/io.h> +#include <linux/gpio.h> +#include <asm/mach-types.h> +#include <mach/usb_phy.h> +#include <mach/iomap.h> + +#define USB_USBSTS 0x144 +#define USB_USBSTS_PCI (1 << 2) + +#define ULPI_VIEWPORT 0x170
It look like your core is a arc/chipidea/mips one that is already used on other product (msm) for example.
Can't you merge with them ?
for example
Quoted 13 lines
arch/arm/mach-tegra/usb_phy.c new file +13
-0+static int utmi_wait_register (void __iomem *reg,u32 mask,u32 result) +{ +unsigned long timeout =2000 ; +do { +if ((readl (reg) & mask) == result) +return 0 ; +udelay (1 ); + timeout--; + }while (timeout); +return -1 ; +} +static void ulpi_viewport_write (struct tegra_usb_phy *phy,u8 addr,u8 data) +{
arch/arm/mach-tegra/usb_phy.c line 298
Quoted 10 lines
arch/arm/mach-tegra/usb_phy.c new file +10
-0+unsigned long val; +void __iomem *base = phy->regs; + + val =ULPI_RUN |ULPI_RD_RW_WRITE |ULPI_PORT (0 ); + val |=ULPI_ADDR (addr) |ULPI_DATA_WR (data); +writel (val, base +ULPI_VIEWPORT ); + +if (utmi_wait_register (base +ULPI_VIEWPORT ,ULPI_RUN ,0 )) +pr_err ("%s: timeout accessing ulpi phy\n" , __func__); +}
look very similar to what is in drivers/usb/otg/msm72k_otg.c
+static int ulpi_write(struct otg_transceiver *otg, u32 val, u32 reg) +{
+ struct msm_otg *motg = container_of(otg, struct msm_otg, otg);
+ int cnt = 0;
+
+ /* initiate write operation */
+ writel(ULPI_RUN | ULPI_WRITE |
+ ULPI_ADDR(reg) | ULPI_DATA(val),
+ USB_ULPI_VIEWPORT);
+
+ /* wait for completion */
+ while (cnt < ULPI_IO_TIMEOUT_USEC) {
+ if (!(readl(USB_ULPI_VIEWPORT) & ULPI_RUN))
+ break;
+ udelay(1);
+ cnt++;
+ }
+
+ if (cnt >= ULPI_IO_TIMEOUT_USEC) {
+ dev_err(otg->dev, "ulpi_write: timeout\n");
+ return -ETIMEDOUT;
+ }
+ return 0;
+}
Matthieu
--
To unsubscribe from this list: send the line "unsubscribe linux-usb" in the body of a message to [email protected] More majordomo info at http://vger.kernel.org/majordomo-info.html
PATCH 2/4 usb: host: ehci-hcd: Add controller_resets_phy quirk
In reply to a message not in the archiveFrom: Gary King <[email protected]>
Tegra quirk: Resetting the controller has the side effect of resetting the PHY. Only reset the controller when doing so won't also reset the phy.
--- drivers/usb/host/ehci-hcd.c | 3 ++- drivers/usb/host/ehci.h | 1 + 2 files changed, 3 insertions(+), 1 deletions(-)
drivers/usb/host/ehci-hcd.c +2 -1
@@ -275,7 +275,8 @@ static int ehci_reset (struct ehci_hcd *ehci) command |=CMD_RESET ;dbg_cmd (ehci,"reset" , command); -ehci_writel (ehci, command, &ehci->regs->command); +if (!ehci->controller_resets_phy) +ehci_writel (ehci, command, &ehci->regs->command);ehci_to_hcd (ehci)->state =HC_STATE_HALT ; ehci->next_statechange = jiffies; retval = handshake (ehci, &ehci->regs->command,
drivers/usb/host/ehci.h +1 -0
@@ -134,6 +134,7 @@ struct ehci_hcd { /* one per controller */ unsigned amd_pll_fix:1; unsigned fs_i_thresh:1; /* Intel iso scheduling */ unsigned use_dummy_qh:1; /* AMD Frame List table quirk*/ + unsigned controller_resets_phy:1; /* Tegra quirk *//* required for usb32 quirk */ #define OHCI_CTRL_HCFS (3 << 6)
Signature · 6 lines
1.7.3.1 -- To unsubscribe from this list: send the line "unsubscribe linux-tegra" in the body of a message to [email protected] More majordomo info at http://vger.kernel.org/majordomo-info.html
A message that is not in the archive (sent off-list or not yet received): 1297228927-23497-3-git-send-email-benoit-z5hGa2qSFaRBDgjK7y7TUQ@public.gmane.org
Re: [PATCH 2/4] usb: host: ehci-hcd: Add controller_resets_phy quirk
Quoted 32 lines · Benoit Goby
From: Gary King <[email protected]>
Tegra quirk: Resetting the controller has the side effect of resetting the PHY. Only reset the controller when doing so won't also reset the phy.
Signed-off-by Gary King <[email protected]>Signed-off-by Benoit Goby <[email protected]>--- drivers/usb/host/ehci-hcd.c | 3 ++- drivers/usb/host/ehci.h | 1 + 2 files changed, 3 insertions(+), 1 deletions(-)drivers/usb/host/ehci-hcd.c +2
-1@@ -275,7 +275,8 @@ static int ehci_reset (struct ehci_hcd *ehci) command |=CMD_RESET ;dbg_cmd (ehci,"reset" , command); -ehci_writel (ehci, command, &ehci->regs->command); +if (!ehci->controller_resets_phy) +ehci_writel (ehci, command, &ehci->regs->command);ehci_to_hcd (ehci)->state =HC_STATE_HALT ; ehci->next_statechange = jiffies; retval = handshake (ehci, &ehci->regs->command,drivers/usb/host/ehci.h +0
-0
drivers/usb/host/ehci.h struct ehci_hcd { /* one per controller */ · line 140
Quoted 7 lines
drivers/usb/host/ehci.h +1
-0@@ -134,6 +134,7 @@ struct ehci_hcd { /* one per controller */ unsigned amd_pll_fix:1; unsigned fs_i_thresh:1; /* Intel iso scheduling */ unsigned use_dummy_qh:1; /* AMD Frame List table quirk*/ + unsigned controller_resets_phy:1; /* Tegra quirk *//* required for usb32 quirk */ #define OHCI_CTRL_HCFS (3 << 6)
Instead of something that prevent reset, shouldn't tdi platform have a callback to restore phy config ?
And I think we should use ehci_is_TDI(ehci) condition. No need to introduce another flags. The problem is common to all tdi core.
Matthieu
PS : This may help to remove ehci_msm_run.
--
To unsubscribe from this list: send the line "unsubscribe linux-usb" in the body of a message to [email protected] More majordomo info at http://vger.kernel.org/majordomo-info.html
A message that is not in the archive (sent off-list or not yet received): 4D52BA75.5010409-ITF29qwbsa/[email protected]
Re: [PATCH 2/4] usb: host: ehci-hcd: Add controller_resets_phy quirk
Hi Matthieu,
Quoted 43 lines · Matthieu CASTET
Quoted 32 lines · Benoit Goby
From: Gary King <[email protected]>
Tegra quirk: Resetting the controller has the side effect of resetting the PHY. Only reset the controller when doing so won't also reset the phy.
Signed-off-by Gary King <[email protected]>Signed-off-by Benoit Goby <[email protected]>--- drivers/usb/host/ehci-hcd.c | 3 ++- drivers/usb/host/ehci.h | 1 + 2 files changed, 3 insertions(+), 1 deletions(-)drivers/usb/host/ehci-hcd.c +2
-1@@ -275,7 +275,8 @@ static int ehci_reset (struct ehci_hcd *ehci) command |=CMD_RESET ;dbg_cmd (ehci,"reset" , command); -ehci_writel (ehci, command, &ehci->regs->command); +if (!ehci->controller_resets_phy) +ehci_writel (ehci, command, &ehci->regs->command);ehci_to_hcd (ehci)->state =HC_STATE_HALT ; ehci->next_statechange = jiffies; retval = handshake (ehci, &ehci->regs->command,drivers/usb/host/ehci.h +0
-0drivers/usb/host/ehci.h struct ehci_hcd { /* one per controller */ · line 140
Quoted 7 lines
drivers/usb/host/ehci.h +1
-0@@ -134,6 +134,7 @@ struct ehci_hcd { /* one per controller */ unsigned amd_pll_fix:1; unsigned fs_i_thresh:1; /* Intel iso scheduling */ unsigned use_dummy_qh:1; /* AMD Frame List table quirk*/ + unsigned controller_resets_phy:1; /* Tegra quirk *//* required for usb32 quirk */ #define OHCI_CTRL_HCFS (3 << 6)Instead of something that prevent reset, shouldn't tdi platform have a callback to restore phy config ?
Quoted 7 lines
And I think we should use
ehci_is_TDI(ehci)condition. No need to introduce another flags. The problem is common to all tdi core.Matthieu
PS : This may help to remove
ehci_msm_run.
The reason for having ehci_msm_run is to configure some MSM specific registers (not just the HC mode bit) after controller reset. In the current code, there is no way HCD can register it's own tdi_reset method. If we can have such mechanism, then ehci_msm_run() can be removed.
Thanks,
Pavan
Signature · 6 lines
Sent by a consultant of the Qualcomm Innovation Center, Inc. The Qualcomm Innovation Center, Inc. is a member of the Code Aurora Forum. -- To unsubscribe from this list: send the line "unsubscribe linux-tegra" in the body of a message to [email protected] More majordomo info at http://vger.kernel.org/majordomo-info.html
PATCH 3/4 usb: host: Add EHCI driver for NVIDIA Tegra SoCs
In reply to a message not in the archive--- drivers/usb/Kconfig | 1 + drivers/usb/host/Kconfig | 8 + drivers/usb/host/ehci-hcd.c | 5 + drivers/usb/host/ehci-tegra.c | 673 +++++++++++++++++++++++++++++++++++++++++ include/linux/tegra_usb.h | 35 +++ 5 files changed, 722 insertions(+), 0 deletions(-) create mode 100644 drivers/usb/host/ehci-tegra.c create mode 100644 include/linux/tegra_usb.h
drivers/usb/Kconfig +1 -0
@@ -59,6 +59,7 @@ config USB_ARCH_HAS_EHCI default y if PPC_MPC512x default y if SOC_AU1200 default y if ARCH_IXP4XX + default y if ARCH_TEGRA default y if ARCH_W90X900 default y if ARCH_AT91SAM9G45 default y if ARCH_MXC
drivers/usb/host/Kconfig +8 -0
@@ -459,6 +459,14 @@ config USB_HWA_HCD To compile this driver a module, choose M here: the module will be called "hwa-hc". +config USB_TEGRA_HCD + boolean "NVIDIA Tegra HCD support" + depends on USB && ARCH_TEGRA && USB_EHCI_HCD + select USB_EHCI_ROOT_HUB_TT + help + This driver enables support for the internal USB Host Controller + found in NVIDIA Tegra SoCs. The Tegra controller is EHCI compliant. + config USB_IMX21_HCD tristate "iMX21 HCD support" depends on USB && ARM && MACH_MX21
drivers/usb/host/ehci-hcd.c +5 -0
@@ -1246,6 +1246,11 @@ MODULE_LICENSE ("GPL");#define PLATFORM_DRIVER ehci_msm_driver#endif +#ifdef CONFIG_ARCH_TEGRA +#include "ehci-tegra.c" +#define PLATFORM_DRIVER tegra_ehci_driver +#endif +#if !defined(PCI_DRIVER ) && !defined(PLATFORM_DRIVER ) && \ !defined(PS3_SYSTEM_BUS_DRIVER ) && !defined(OF_PLATFORM_DRIVER ) && \ !defined(XILINX_OF_PLATFORM_DRIVER )
drivers/usb/host/ehci-tegra.c new file +673 -0
673 lines not on this page · raw message
include/linux/tegra_usb.h new file +35 -0
@@ -0,0 +1,35 @@ +/* +* Copyright (C) 2010 Google, Inc. +* +* 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 _TEGRA_USB_H_ +#define _TEGRA_USB_H_ + +enum tegra_usb_operating_modes { +TEGRA_USB_DEVICE , +TEGRA_USB_HOST , +TEGRA_USB_OTG , +}; + +struct tegra_ehci_platform_data { +enum tegra_usb_operating_modes operating_mode; +/* power down the phy on bus suspend */ +int power_down_on_bus_suspend; +void *phy_config; +}; + +#endif /* _TEGRA_USB_H_ */
Signature · 6 lines
1.7.3.1 -- To unsubscribe from this list: send the line "unsubscribe linux-usb" in the body of a message to [email protected] More majordomo info at http://vger.kernel.org/majordomo-info.html
A message that is not in the archive (sent off-list or not yet received): 1297228927-23497-4-git-send-email-benoit-z5hGa2qSFaRBDgjK7y7TUQ@public.gmane.org
Re: [PATCH 3/4] usb: host: Add EHCI driver for NVIDIA Tegra SoCs
Hi,
Quoted 1 line · Benoit Goby
Signed-off-by Benoit Goby <[email protected]>
_clk);
Quoted 106 lines
drivers/usb/host/ehci-tegra.c new file +106
-0+} + +static int tegra_ehci_hub_control ( +struct usb_hcd *hcd, +u16 typeReq, +u16 wValue, +u16 wIndex, +char *buf, +u16 wLength +) +{ +struct ehci_hcd *ehci =hcd_to_ehci (hcd); +struct tegra_ehci_hcd *tegra =dev_get_drvdata (hcd->self.controller); +u32 __iomem *status_reg; +u32 temp; +unsigned long flags; +int retval =0 ; + + status_reg = &ehci->regs->port_status[(wIndex &0xff ) -1 ]; + +spin_lock_irqsave (&ehci->lock, flags); + +/* +* In ehci_hub_control() for USB_PORT_FEAT_ENABLE clears the other bits +* that are write on clear, by writing back the register read value, so +* USB_PORT_FEAT_ENABLE is handled by masking the set on clear bits +*/ +if (typeReq == ClearPortFeature && wValue ==USB_PORT_FEAT_ENABLE ) { + temp =ehci_readl (ehci, status_reg) & ~PORT_RWC_BITS ; +ehci_writel (ehci, temp & ~PORT_PE , status_reg); + goto done; + } + +else if (typeReq == GetPortStatus) { + temp =ehci_readl (ehci, status_reg); +if (tegra->port_resuming && !(temp &PORT_SUSPEND )) { +/* resume completed */ + tegra->port_resuming =0 ; +tegra_usb_phy_postresume (tegra->phy); + } + } + +else if (typeReq == SetPortFeature && wValue ==USB_PORT_FEAT_SUSPEND ) { + temp =ehci_readl (ehci, status_reg); +if ((temp &PORT_PE ) ==0 || (temp &PORT_RESET ) !=0 ) { + retval = -EPIPE ; + goto done; + } + +/* After above check the port must be connected. +* Set appropriate bit thus could put phy into low power +* mode if we have hostpc feature +*/ + temp &= ~PORT_WKCONN_E ; + temp |=PORT_WKDISC_E |PORT_WKOC_E ; +ehci_writel (ehci, temp |PORT_SUSPEND , status_reg); +if (handshake (ehci, status_reg,PORT_SUSPEND , +PORT_SUSPEND ,5000 )) +pr_err ("%s: timeout waiting for SUSPEND\n" , __func__); +set_bit ((wIndex &0xff ) -1 , &ehci->suspended_ports); + goto done; + } + +/* +* Tegra host controller will time the resume operation to clear the bit +* when the port control state switches to HS or FS Idle. This behavior +* is different from EHCI where the host controller driver is required +* to set this bit to a zero after the resume duration is timed in the +* driver. +*/ +else if (typeReq == ClearPortFeature && + wValue ==USB_PORT_FEAT_SUSPEND ) { + temp =ehci_readl (ehci, status_reg); +if ((temp &PORT_RESET ) || !(temp &PORT_PE )) { + retval = -EPIPE ; + goto done; + } + +if (!(temp &PORT_SUSPEND )) + goto done; + +tegra_usb_phy_preresume (tegra->phy); + + ehci->reset_done[wIndex-1 ] = jiffies +msecs_to_jiffies (25 ); + + temp &= ~(PORT_RWC_BITS |PORT_WAKE_BITS ); +/* start resume signalling */ +ehci_writel (ehci, temp |PORT_RESUME , status_reg); + +spin_unlock_irqrestore (&ehci->lock, flags); +msleep (20 ); +spin_lock_irqsave (&ehci->lock, flags); + +/* polling PORT_RESUME until the controller clear this bit */ +if (handshake (ehci, status_reg,PORT_RESUME ,0 ,2000 )) +pr_err ("%s: timeout waiting for RESUME\n" , __func__); + +/* polling PORT_SUSPEND until the controller clear this bit */ +if (handshake (ehci, status_reg,PORT_SUSPEND ,0 ,2000 )) +pr_err ("%s: timeout waiting for SUSPEND\n" , __func__); + + ehci->reset_done[wIndex-1 ] =0 ; + + tegra->port_resuming =1 ; + goto done; + }
drivers/usb/host/ehci-tegra.c line 181
Quoted 10 lines
drivers/usb/host/ehci-tegra.c new file +10
-0+ +spin_unlock_irqrestore (&ehci->lock, flags); + +/* Handle the hub control events here */ +return ehci_hub_control (hcd, typeReq, wValue, wIndex, buf, wLength); +done: +spin_unlock_irqrestore (&ehci->lock, flags); +return retval; +} +
I don't know enough usb layer, but can't you done something similar than in msm otg : let's the otg layer handle the power management ?
Quoted 17 lines
drivers/usb/host/ehci-tegra.c new file +17
-0+static int tegra_ehci_reset (struct usb_hcd *hcd) +{ +unsigned long temp; +int usec =250 *1000 ;/* see ehci_reset */ + + temp =readl (hcd->regs +TEGRA_USB_USBCMD_REG_OFFSET ); + temp |=TEGRA_USB_USBCMD_RESET ; +writel (temp, hcd->regs +TEGRA_USB_USBCMD_REG_OFFSET ); + +do { + temp =readl (hcd->regs +TEGRA_USB_USBCMD_REG_OFFSET ); +if (!(temp &TEGRA_USB_USBCMD_RESET )) +break ; +udelay (1 ); + usec--; + }while (usec); +
drivers/usb/host/ehci-tegra.c line 208
Quoted 10 lines
drivers/usb/host/ehci-tegra.c new file +10
-0+if (!usec) +return -ETIMEDOUT ; + +/* Set to Host mode by setting bit 0-1 of USB device mode register */ + temp =readl (hcd->regs +TEGRA_USB_USBMODE_REG_OFFSET ); +writel ((temp |TEGRA_USB_USBMODE_HOST ), + (hcd->regs +TEGRA_USB_USBMODE_REG_OFFSET )); + +return 0 ; +}
Why can't you use tdi_reset that already this for you ?
Matthieu
--
To unsubscribe from this list: send the line "unsubscribe linux-tegra" in the body of a message to [email protected] More majordomo info at http://vger.kernel.org/majordomo-info.html
A message that is not in the archive (sent off-list or not yet received): 4D5257FA.1030605-ITF29qwbsa/[email protected]
Re: [PATCH 3/4] usb: host: Add EHCI driver for NVIDIA Tegra SoCs
Quoted 15 lines · Matthieu CASTET
drivers/usb/host/ehci-tegra.c line 83
Quoted 10 lines · Benoit Goby
drivers/usb/host/ehci-tegra.c new file +10
-0+static int tegra_ehci_hub_control ( + struct usb_hcd *hcd, + u16 typeReq, + u16 wValue, + u16 wIndex, + char *buf, + u16 wLength +) +{ +I don't know enough usb layer, but can't you done something similar than in msm otg : let's the otg layer handle the power management ?
Quoted 2 lines
This function overrides ehci_hub_control to fix tegra specific quirks when we suspend/resume the root hub. I don't see how this could be handled at the otg level.
Benoit
--
To unsubscribe from this list: send the line "unsubscribe linux-usb" in the body of a message to [email protected] More majordomo info at http://vger.kernel.org/majordomo-info.html
Re: [PATCH 3/4] usb: host: Add EHCI driver for NVIDIA Tegra SoCs
In reply to a message not in the archiveQuoted 16 lines · Benoit Goby
Signed-off-by Benoit Goby<[email protected]>--- drivers/usb/Kconfig | 1 + drivers/usb/host/Kconfig | 8 + drivers/usb/host/ehci-hcd.c | 5 + drivers/usb/host/ehci-tegra.c | 673 +++++++++++++++++++++++++++++++++++++++++ include/linux/tegra_usb.h | 35 +++ 5 files changed, 722 insertions(+), 0 deletions(-)create mode 100644
drivers/usb/host/ehci-tegra.ccreate mode 100644include/linux/tegra_usb.hdrivers/usb/Kconfig +0
-0
drivers/usb/Kconfig config USB_ARCH_HAS_EHCI · line 63
Quoted 5 lines
drivers/usb/Kconfig +1
-0@@ -59,6 +59,7 @@ config USB_ARCH_HAS_EHCI default y if PPC_MPC512x default y if SOC_AU1200 default y if ARCH_IXP4XX + default y if ARCH_TEGRA default y if ARCH_W90X900
This doesn't belong here.
Do 'select USB_ARCH_HAS_EHCI' in your arch specific Kconfig instead.
David Daney
--
To unsubscribe from this list: send the line "unsubscribe linux-usb" in the body of a message to [email protected] More majordomo info at http://vger.kernel.org/majordomo-info.html
PATCH 4/4 USB: ehci: tegra: Align DMA transfers to 32 bytes
In reply to a message not in the archiveFrom: Robert Morell <[email protected]>
The Tegra2 USB controller doesn't properly deal with misaligned DMA buffers, causing corruption. This is especially prevalent with USB network adapters, where skbuff alignment is often in the middle of a 4-byte dword.
To avoid this, allocate a temporary buffer for the DMA if the provided buffer isn't sufficiently aligned.
--- drivers/usb/host/ehci-tegra.c | 90 +++++++++++++++++++++++++++++++++++++++++ 1 files changed, 90 insertions(+), 0 deletions(-)
drivers/usb/host/ehci-tegra.c +90 -0
@@ -32,6 +32,8 @@#define TEGRA_USB_USBMODE_HOST (3 << 0)#define TEGRA_USB_PORTSC1_PTC (x) (((x) & 0xf) << 16) +#define TEGRA_USB_DMA_ALIGN 32 +struct tegra_ehci_hcd {struct ehci_hcd *ehci;struct tegra_usb_phy *phy;
@@ -423,6 +425,92 @@ static int tegra_ehci_bus_resume(struct usb_hcd *hcd) }#endif +struct temp_buffer { +void *kmalloc_ptr; +void *old_xfer_buffer; +u8 data[0 ]; +}; + +static void free_temp_buffer (struct urb *urb) +{ +enum dma_data_direction dir; +struct temp_buffer *temp; + +if (!(urb->transfer_flags &URB_ALIGNED_TEMP_BUFFER )) +return ; + + dir =usb_urb_dir_in (urb) ?DMA_FROM_DEVICE :DMA_TO_DEVICE ; + + temp = container_of(urb->transfer_buffer, struct temp_buffer, + data); + +if (dir ==DMA_FROM_DEVICE ) +memcpy (temp->old_xfer_buffer, temp->data, + urb->transfer_buffer_length); + urb->transfer_buffer = temp->old_xfer_buffer; +kfree (temp->kmalloc_ptr); + + urb->transfer_flags &= ~URB_ALIGNED_TEMP_BUFFER ; +} + +static int alloc_temp_buffer (struct urb *urb,gfp_t mem_flags) +{ +enum dma_data_direction dir; +struct temp_buffer *temp, *kmalloc_ptr; +size_t kmalloc_size; + +if (urb->num_sgs || urb->sg || + urb->transfer_buffer_length ==0 || + !((uintptr_t )urb->transfer_buffer & (TEGRA_USB_DMA_ALIGN -1 ))) +return 0 ; + + dir =usb_urb_dir_in (urb) ?DMA_FROM_DEVICE :DMA_TO_DEVICE ; + +/* Allocate a buffer with enough padding for alignment */ + kmalloc_size = urb->transfer_buffer_length + +sizeof (struct temp_buffer ) +TEGRA_USB_DMA_ALIGN -1 ; + + kmalloc_ptr =kmalloc (kmalloc_size, mem_flags); +if (!kmalloc_ptr) +return -ENOMEM ; + +/* Position our struct temp_buffer such that data is aligned */ + temp =PTR_ALIGN (kmalloc_ptr +1 ,TEGRA_USB_DMA_ALIGN ) -1 ; + + temp->kmalloc_ptr = kmalloc_ptr; + temp->old_xfer_buffer = urb->transfer_buffer; +if (dir ==DMA_TO_DEVICE ) +memcpy (temp->data, urb->transfer_buffer, + urb->transfer_buffer_length); + urb->transfer_buffer = temp->data; + + urb->transfer_flags |=URB_ALIGNED_TEMP_BUFFER ; + +return 0 ; +} + +static int tegra_ehci_map_urb_for_dma (struct usb_hcd *hcd,struct urb *urb, +gfp_t mem_flags) +{ +int ret; + + ret =alloc_temp_buffer (urb, mem_flags); +if (ret) +return ret; + + ret =usb_hcd_map_urb_for_dma (hcd, urb, mem_flags); +if (ret) +free_temp_buffer (urb); + +return ret; +} + +static void tegra_ehci_unmap_urb_for_dma (struct usb_hcd *hcd,struct urb *urb) +{ +usb_hcd_unmap_urb_for_dma (hcd, urb); +free_temp_buffer (urb); +} +static const struct hc_driver tegra_ehci_hc_driver = { .description = hcd_name, .product_desc ="Tegra EHCI Host Controller" ,
@@ -438,6 +526,8 @@ static const struct hc_driver tegra_ehci_hc_driver = { .shutdown = tegra_ehci_shutdown, .urb_enqueue = ehci_urb_enqueue, .urb_dequeue = ehci_urb_dequeue, + .map_urb_for_dma = tegra_ehci_map_urb_for_dma, + .unmap_urb_for_dma = tegra_ehci_unmap_urb_for_dma, .endpoint_disable = ehci_endpoint_disable, .endpoint_reset = ehci_endpoint_reset, .get_frame_number = ehci_get_frame,
Signature · 6 lines
1.7.3.1 -- To unsubscribe from this list: send the line "unsubscribe linux-usb" in the body of a message to [email protected] More majordomo info at http://vger.kernel.org/majordomo-info.html