Merge branch 'next'
[u-boot/qq2440-u-boot.git] / drivers / usb / musb / am35x.c
blob62c3a6f60aa8c066177ec11b79b68e023176142a
1 /*
2 * am35x.c - TI's AM35x platform specific usb wrapper functions.
4 * Author: Ajay Kumar Gupta <ajay.gupta@ti.com>
6 * Based on drivers/usb/musb/da8xx.c
8 * Copyright (c) 2010 Texas Instruments Incorporated
10 * SPDX-License-Identifier: GPL-2.0+
13 #include <common.h>
15 #include "am35x.h"
17 /* MUSB platform configuration */
18 struct musb_config musb_cfg = {
19 .regs = (struct musb_regs *)AM35X_USB_OTG_CORE_BASE,
20 .timeout = AM35X_USB_OTG_TIMEOUT,
21 .musb_speed = 0,
25 * Enable the USB phy
27 static u8 phy_on(void)
29 u32 devconf2;
30 u32 timeout;
32 devconf2 = readl(&am35x_scm_general_regs->devconf2);
34 devconf2 &= ~(DEVCONF2_RESET | DEVCONF2_PHYPWRDN | DEVCONF2_OTGPWRDN |
35 DEVCONF2_OTGMODE | DEVCONF2_REFFREQ |
36 DEVCONF2_PHY_GPIOMODE);
37 devconf2 |= DEVCONF2_SESENDEN | DEVCONF2_VBDTCTEN | DEVCONF2_PHY_PLLON |
38 DEVCONF2_REFFREQ_13MHZ | DEVCONF2_DATPOL;
40 writel(devconf2, &am35x_scm_general_regs->devconf2);
42 /* wait until the USB phy is turned on */
43 timeout = musb_cfg.timeout;
44 while (timeout--)
45 if (readl(&am35x_scm_general_regs->devconf2) & DEVCONF2_PHYCKGD)
46 return 1;
48 /* USB phy was not turned on */
49 return 0;
53 * Disable the USB phy
55 static void phy_off(void)
57 u32 devconf2;
60 * Power down the on-chip PHY.
62 devconf2 = readl(&am35x_scm_general_regs->devconf2);
64 devconf2 &= ~DEVCONF2_PHY_PLLON;
65 devconf2 |= DEVCONF2_PHYPWRDN | DEVCONF2_OTGPWRDN;
66 writel(devconf2, &am35x_scm_general_regs->devconf2);
70 * This function performs platform specific initialization for usb0.
72 int musb_platform_init(void)
74 u32 revision;
75 u32 sw_reset;
77 /* global usb reset */
78 sw_reset = readl(&am35x_scm_general_regs->ip_sw_reset);
79 sw_reset |= (1 << 0);
80 writel(sw_reset, &am35x_scm_general_regs->ip_sw_reset);
81 sw_reset &= ~(1 << 0);
82 writel(sw_reset, &am35x_scm_general_regs->ip_sw_reset);
84 /* reset the controller */
85 writel(0x1, &am35x_usb_regs->control);
86 udelay(5000);
88 /* start the on-chip usb phy and its pll */
89 if (phy_on() == 0)
90 return -1;
92 /* Returns zero if e.g. not clocked */
93 revision = readl(&am35x_usb_regs->revision);
94 if (revision == 0)
95 return -1;
97 return 0;
101 * This function performs platform specific deinitialization for usb0.
103 void musb_platform_deinit(void)
105 /* Turn off the phy */
106 phy_off();
110 * This function reads data from endpoint fifo for AM35x
111 * which supports only 32bit read operation.
113 * ep - endpoint number
114 * length - number of bytes to read from FIFO
115 * fifo_data - pointer to data buffer into which data is read
117 __attribute__((weak))
118 void read_fifo(u8 ep, u32 length, void *fifo_data)
120 u8 *data = (u8 *)fifo_data;
121 u32 val;
122 int i;
124 /* select the endpoint index */
125 writeb(ep, &musbr->index);
127 if (length > 4) {
128 for (i = 0; i < (length >> 2); i++) {
129 val = readl(&musbr->fifox[ep]);
130 memcpy(data, &val, 4);
131 data += 4;
133 length %= 4;
135 if (length > 0) {
136 val = readl(&musbr->fifox[ep]);
137 memcpy(data, &val, length);