1 // SPDX-License-Identifier: GPL-2.0+
3 * am35x.c - TI's AM35x platform specific usb wrapper functions.
5 * Author: Ajay Kumar Gupta <ajay.gupta@ti.com>
7 * Based on drivers/usb/musb/da8xx.c
9 * Copyright (c) 2010 Texas Instruments Incorporated
16 /* MUSB platform configuration */
17 struct musb_config musb_cfg = {
18 .regs = (struct musb_regs *)AM35X_USB_OTG_CORE_BASE,
19 .timeout = AM35X_USB_OTG_TIMEOUT,
26 static u8 phy_on(void)
31 devconf2 = readl(&am35x_scm_general_regs->devconf2);
33 devconf2 &= ~(DEVCONF2_RESET | DEVCONF2_PHYPWRDN | DEVCONF2_OTGPWRDN |
34 DEVCONF2_OTGMODE | DEVCONF2_REFFREQ |
35 DEVCONF2_PHY_GPIOMODE);
36 devconf2 |= DEVCONF2_SESENDEN | DEVCONF2_VBDTCTEN | DEVCONF2_PHY_PLLON |
37 DEVCONF2_REFFREQ_13MHZ | DEVCONF2_DATPOL;
39 writel(devconf2, &am35x_scm_general_regs->devconf2);
41 /* wait until the USB phy is turned on */
42 timeout = musb_cfg.timeout;
44 if (readl(&am35x_scm_general_regs->devconf2) & DEVCONF2_PHYCKGD)
47 /* USB phy was not turned on */
54 static void phy_off(void)
59 * Power down the on-chip PHY.
61 devconf2 = readl(&am35x_scm_general_regs->devconf2);
63 devconf2 &= ~DEVCONF2_PHY_PLLON;
64 devconf2 |= DEVCONF2_PHYPWRDN | DEVCONF2_OTGPWRDN;
65 writel(devconf2, &am35x_scm_general_regs->devconf2);
69 * This function performs platform specific initialization for usb0.
71 int musb_platform_init(void)
76 /* global usb reset */
77 sw_reset = readl(&am35x_scm_general_regs->ip_sw_reset);
79 writel(sw_reset, &am35x_scm_general_regs->ip_sw_reset);
80 sw_reset &= ~(1 << 0);
81 writel(sw_reset, &am35x_scm_general_regs->ip_sw_reset);
83 /* reset the controller */
84 writel(0x1, &am35x_usb_regs->control);
87 /* start the on-chip usb phy and its pll */
91 /* Returns zero if e.g. not clocked */
92 revision = readl(&am35x_usb_regs->revision);
100 * This function performs platform specific deinitialization for usb0.
102 void musb_platform_deinit(void)
104 /* Turn off the phy */
109 * This function reads data from endpoint fifo for AM35x
110 * which supports only 32bit read operation.
112 * ep - endpoint number
113 * length - number of bytes to read from FIFO
114 * fifo_data - pointer to data buffer into which data is read
116 __attribute__((weak))
117 void read_fifo(u8 ep, u32 length, void *fifo_data)
119 u8 *data = (u8 *)fifo_data;
123 /* select the endpoint index */
124 writeb(ep, &musbr->index);
127 for (i = 0; i < (length >> 2); i++) {
128 val = readl(&musbr->fifox[ep]);
129 memcpy(data, &val, 4);
135 val = readl(&musbr->fifox[ep]);
136 memcpy(data, &val, length);