| Submitter | Jana Rapava |
|---|---|
| Date | Nov. 5, 2011, 8:59 p.m. |
| Message ID | <1320526753-30544-1-git-send-email-fermata7@gmail.com> |
| Download | mbox | patch |
| Permalink | /patch/123891/ |
| State | Superseded |
| Delegated to: | Marek Vasut |
| Headers | show |
Comments
> This patch changes Efika USB support code to use generic ULPI > implementation instead of driver's own. The patchset for efika wasn't mainlined yet, please reintegrate and resubmit the whole thing. > > Signed-off-by: Jana Rapava <fermata7@gmail.com> > Cc: Marek Vasut <marek.vasut@gmail.com> > Cc: Remy Bohmer <linux@bohmer.net> > Cc: Stefano Babic <sbabic@denx.de> > Cc: Igor Grinberg <grinberg@compulab.co.il> > --- > board/efikamx/efikamx-usb.c | 105 > +++++-------------------------------------- include/configs/efikamx.h | > 1 + > 2 files changed, 13 insertions(+), 93 deletions(-) > > diff --git a/board/efikamx/efikamx-usb.c b/board/efikamx/efikamx-usb.c > index 3b42256..2a0341f 100644 > --- a/board/efikamx/efikamx-usb.c > +++ b/board/efikamx/efikamx-usb.c > @@ -205,104 +205,21 @@ void control_regs_setup(struct mx5_usb_control_regs > *control) udelay(10000); > } > > -#define ULPI_ADDR_SHIFT 16 > -#define ulpi_write_mask(value) ((value) & 0xff) > -#define ulpi_read_mask(value) (((value) >> 8) & 0xff) > - > -int ulpi_wait(struct usb_ehci *ehci, u32 ulpi_value, u32 ulpi_mask) > +void ulpi_set_flags(struct usb_ehci *ehci, struct ulpi_regs *ulpi) > { > - int timeout = ULPI_TIMEOUT; > - u32 tmp; > - > - writel(ulpi_value, &ehci->ulpi_viewpoint); > - > - /* Wait for the bits in ulpi_mask to become zero. */ > - while (--timeout) { > - tmp = readl(&ehci->ulpi_viewpoint); > - if (!(tmp & ulpi_mask)) > - break; > - WATCHDOG_RESET(); > - } > - > - return !timeout; > -} > - > -int ulpi_wakeup(struct usb_ehci *ehci) > -{ > - if (readl(&ehci->ulpi_viewpoint) & ULPI_SS) > - return 0; /* already awake */ > - return ulpi_wait(ehci, ULPI_WU, ULPI_WU); > -} > - > -void ulpi_write(struct usb_ehci *ehci, u32 reg, u32 value) > -{ > - u32 tmp; > - if (ulpi_wakeup(ehci)) { > - printf("ULPI wakeup timed out\n"); > - return; > - } > - > - tmp = ulpi_wait(ehci, ULPI_RWRUN | ULPI_RWCTRL | > - reg << ULPI_ADDR_SHIFT | ulpi_write_mask(value), ULPI_RWRUN); > - if (tmp) > - printf("ULPI write timed out\n"); > -} > - > -u32 ulpi_read(struct usb_ehci *ehci, u32 reg) > -{ > - if (ulpi_wakeup(ehci)) { > - printf("ULPI wakeup timed out\n"); > - return 0; > - } > - > - if (ulpi_wait(ehci, ULPI_RWRUN | reg << ULPI_ADDR_SHIFT, ULPI_RWRUN)) { > - printf("ULPI read timed out\n"); > - return 0; > - } > - > - return ulpi_read_mask(readl(&ehci->ulpi_viewpoint)); > -} > - > -void ulpi_init(struct usb_ehci *ehci, struct ulpi_regs *ulpi) > -{ > - u32 tmp = 0; > - int reg, i; > - > - /* Assemble ID from four ULPI ID registers (8 bits each). */ > - for (reg = ULPI_ID_REGS_COUNT - 1; reg >= 0; reg--) > - tmp |= ulpi_read(ehci, reg) << (reg * 8); > - > - /* Split ID into vendor and product ID. */ > - debug("Found ULPI TX, ID %04x:%04x\n", tmp >> 16, tmp & 0xffff); > - > - /* ULPI integrity check */ > - for (i = 0; i < 2; i++) { > - ulpi_write(ehci, (u32)&ulpi->scratch_write, > - ULPI_TEST_VALUE << i); > - tmp = ulpi_read(ehci, (u32)&ulpi->scratch_write); > - > - if (tmp != (ULPI_TEST_VALUE << i)) { > - printf("ULPI integrity check failed\n"); > - return; > - } > - } > - > - /* Set ULPI flags. */ > - ulpi_write(ehci, (u32)&ulpi->otg_ctrl_write, > - ULPI_OTG_EXTVBUSIND | > + ulpi_otg_ctrl_flags(ehci, ulpi, WRITE, ULPI_OTG_EXTVBUSIND | > ULPI_OTG_DM_PULLDOWN | ULPI_OTG_DP_PULLDOWN); > - ulpi_write(ehci, (u32)&ulpi->function_ctrl_write, > - ULPI_FC_XCVRSEL | ULPI_FC_OPMODE_NORMAL | > - ULPI_FC_SUSPENDM); > - ulpi_write(ehci, (u32)&ulpi->iface_ctrl_write, 0); > - ulpi_write(ehci, (u32)&ulpi->otg_ctrl_set, > - ULPI_OTG_DRVVBUS | ULPI_OTG_DRVVBUS_EXT); > + ulpi_function_ctrl_flags(ehci, ulpi, WRITE, ULPI_FC_XCVRSEL | > + ULPI_FC_OPMODE_NORMAL | ULPI_FC_SUSPENDM); > + ulpi_iface_ctrl_flags(ehci, ulpi, WRITE, 0); > > /* > - * NOTE: This violates USB specification, but otherwise, USB on Efika > - * doesn't charge VBUS and as a result, USB doesn't work. > + * NOTE: Setting ULPI_OTG_CHRGVBUS violates USB specification, > + * but otherwise, USB on Efika doesn't charge VBUS > + * and as a result, USB doesn't work. > */ > - ulpi_write(ehci, (u32)&ulpi->otg_ctrl_set, ULPI_OTG_CHRGVBUS); > + ulpi_otg_ctrl_flags(ehci, ulpi, SET, ULPI_OTG_DRVVBUS | > + ULPI_OTG_DRVVBUS_EXT | ULPI_OTG_CHRGVBUS); > } > > /* > @@ -353,6 +270,7 @@ void ehci1_init(struct usb_ehci *ehci, struct ulpi_regs > *ulpi) udelay(10000); > > ulpi_init(ehci, ulpi); > + ulpi_set_flags(ehci, ulpi); > } > > void ehci2_init(struct usb_ehci *ehci, struct ulpi_regs *ulpi) > @@ -372,6 +290,7 @@ void ehci2_init(struct usb_ehci *ehci, struct ulpi_regs > *ulpi) udelay(10000); > > ulpi_init(ehci, ulpi); > + ulpi_set_flags(ehci, ulpi); > } > > int ehci_hcd_init(void) > diff --git a/include/configs/efikamx.h b/include/configs/efikamx.h > index 537a1e4..988236b 100644 > --- a/include/configs/efikamx.h > +++ b/include/configs/efikamx.h > @@ -188,6 +188,7 @@ > #define CONFIG_EHCI_IS_TDI > #define CONFIG_USB_STORAGE > #define CONFIG_USB_KEYBOARD > +#define CONFIG_USB_ULPI > #endif /* CONFIG_CMD_USB */ > > /*
Patch
diff --git a/board/efikamx/efikamx-usb.c b/board/efikamx/efikamx-usb.c index 3b42256..2a0341f 100644 --- a/board/efikamx/efikamx-usb.c +++ b/board/efikamx/efikamx-usb.c @@ -205,104 +205,21 @@ void control_regs_setup(struct mx5_usb_control_regs *control) udelay(10000); } -#define ULPI_ADDR_SHIFT 16 -#define ulpi_write_mask(value) ((value) & 0xff) -#define ulpi_read_mask(value) (((value) >> 8) & 0xff) - -int ulpi_wait(struct usb_ehci *ehci, u32 ulpi_value, u32 ulpi_mask) +void ulpi_set_flags(struct usb_ehci *ehci, struct ulpi_regs *ulpi) { - int timeout = ULPI_TIMEOUT; - u32 tmp; - - writel(ulpi_value, &ehci->ulpi_viewpoint); - - /* Wait for the bits in ulpi_mask to become zero. */ - while (--timeout) { - tmp = readl(&ehci->ulpi_viewpoint); - if (!(tmp & ulpi_mask)) - break; - WATCHDOG_RESET(); - } - - return !timeout; -} - -int ulpi_wakeup(struct usb_ehci *ehci) -{ - if (readl(&ehci->ulpi_viewpoint) & ULPI_SS) - return 0; /* already awake */ - return ulpi_wait(ehci, ULPI_WU, ULPI_WU); -} - -void ulpi_write(struct usb_ehci *ehci, u32 reg, u32 value) -{ - u32 tmp; - if (ulpi_wakeup(ehci)) { - printf("ULPI wakeup timed out\n"); - return; - } - - tmp = ulpi_wait(ehci, ULPI_RWRUN | ULPI_RWCTRL | - reg << ULPI_ADDR_SHIFT | ulpi_write_mask(value), ULPI_RWRUN); - if (tmp) - printf("ULPI write timed out\n"); -} - -u32 ulpi_read(struct usb_ehci *ehci, u32 reg) -{ - if (ulpi_wakeup(ehci)) { - printf("ULPI wakeup timed out\n"); - return 0; - } - - if (ulpi_wait(ehci, ULPI_RWRUN | reg << ULPI_ADDR_SHIFT, ULPI_RWRUN)) { - printf("ULPI read timed out\n"); - return 0; - } - - return ulpi_read_mask(readl(&ehci->ulpi_viewpoint)); -} - -void ulpi_init(struct usb_ehci *ehci, struct ulpi_regs *ulpi) -{ - u32 tmp = 0; - int reg, i; - - /* Assemble ID from four ULPI ID registers (8 bits each). */ - for (reg = ULPI_ID_REGS_COUNT - 1; reg >= 0; reg--) - tmp |= ulpi_read(ehci, reg) << (reg * 8); - - /* Split ID into vendor and product ID. */ - debug("Found ULPI TX, ID %04x:%04x\n", tmp >> 16, tmp & 0xffff); - - /* ULPI integrity check */ - for (i = 0; i < 2; i++) { - ulpi_write(ehci, (u32)&ulpi->scratch_write, - ULPI_TEST_VALUE << i); - tmp = ulpi_read(ehci, (u32)&ulpi->scratch_write); - - if (tmp != (ULPI_TEST_VALUE << i)) { - printf("ULPI integrity check failed\n"); - return; - } - } - - /* Set ULPI flags. */ - ulpi_write(ehci, (u32)&ulpi->otg_ctrl_write, - ULPI_OTG_EXTVBUSIND | + ulpi_otg_ctrl_flags(ehci, ulpi, WRITE, ULPI_OTG_EXTVBUSIND | ULPI_OTG_DM_PULLDOWN | ULPI_OTG_DP_PULLDOWN); - ulpi_write(ehci, (u32)&ulpi->function_ctrl_write, - ULPI_FC_XCVRSEL | ULPI_FC_OPMODE_NORMAL | - ULPI_FC_SUSPENDM); - ulpi_write(ehci, (u32)&ulpi->iface_ctrl_write, 0); - ulpi_write(ehci, (u32)&ulpi->otg_ctrl_set, - ULPI_OTG_DRVVBUS | ULPI_OTG_DRVVBUS_EXT); + ulpi_function_ctrl_flags(ehci, ulpi, WRITE, ULPI_FC_XCVRSEL | + ULPI_FC_OPMODE_NORMAL | ULPI_FC_SUSPENDM); + ulpi_iface_ctrl_flags(ehci, ulpi, WRITE, 0); /* - * NOTE: This violates USB specification, but otherwise, USB on Efika - * doesn't charge VBUS and as a result, USB doesn't work. + * NOTE: Setting ULPI_OTG_CHRGVBUS violates USB specification, + * but otherwise, USB on Efika doesn't charge VBUS + * and as a result, USB doesn't work. */ - ulpi_write(ehci, (u32)&ulpi->otg_ctrl_set, ULPI_OTG_CHRGVBUS); + ulpi_otg_ctrl_flags(ehci, ulpi, SET, ULPI_OTG_DRVVBUS | + ULPI_OTG_DRVVBUS_EXT | ULPI_OTG_CHRGVBUS); } /* @@ -353,6 +270,7 @@ void ehci1_init(struct usb_ehci *ehci, struct ulpi_regs *ulpi) udelay(10000); ulpi_init(ehci, ulpi); + ulpi_set_flags(ehci, ulpi); } void ehci2_init(struct usb_ehci *ehci, struct ulpi_regs *ulpi) @@ -372,6 +290,7 @@ void ehci2_init(struct usb_ehci *ehci, struct ulpi_regs *ulpi) udelay(10000); ulpi_init(ehci, ulpi); + ulpi_set_flags(ehci, ulpi); } int ehci_hcd_init(void) diff --git a/include/configs/efikamx.h b/include/configs/efikamx.h index 537a1e4..988236b 100644 --- a/include/configs/efikamx.h +++ b/include/configs/efikamx.h @@ -188,6 +188,7 @@ #define CONFIG_EHCI_IS_TDI #define CONFIG_USB_STORAGE #define CONFIG_USB_KEYBOARD +#define CONFIG_USB_ULPI #endif /* CONFIG_CMD_USB */ /*
This patch changes Efika USB support code to use generic ULPI implementation instead of driver's own. Signed-off-by: Jana Rapava <fermata7@gmail.com> Cc: Marek Vasut <marek.vasut@gmail.com> Cc: Remy Bohmer <linux@bohmer.net> Cc: Stefano Babic <sbabic@denx.de> Cc: Igor Grinberg <grinberg@compulab.co.il> --- board/efikamx/efikamx-usb.c | 105 +++++-------------------------------------- include/configs/efikamx.h | 1 + 2 files changed, 13 insertions(+), 93 deletions(-)