1 // SPDX-License-Identifier: GPL-2.0+
3 * da8xx.c - TI's DA8xx platform specific usb wrapper functions.
5 * Author: Ajay Kumar Gupta <ajay.gupta@ti.com>
7 * Based on drivers/usb/musb/davinci.c
9 * Copyright (C) 2009 Texas Instruments Incorporated
13 #include "musb_core.h"
14 #include <asm/arch/da8xx-usb.h>
16 /* MUSB platform configuration */
17 struct musb_config musb_cfg = {
18 .regs = (struct musb_regs *)DA8XX_USB_OTG_CORE_BASE,
19 .timeout = DA8XX_USB_OTG_TIMEOUT,
24 * This function enables VBUS by driving the GPIO Bank4 Pin 15 high.
26 static void enable_vbus(void)
30 /* configure GPIO bank4 pin 15 in output direction */
31 value = readl(&davinci_gpio_bank45->dir);
32 writel((value & (~DA8XX_USB_VBUS_GPIO)), &davinci_gpio_bank45->dir);
34 /* set GPIO bank4 pin 15 high to drive VBUS */
35 value = readl(&davinci_gpio_bank45->set_data);
36 writel((value | DA8XX_USB_VBUS_GPIO), &davinci_gpio_bank45->set_data);
40 * Enable the usb0 phy. This initialization procedure is explained in
41 * the DA8xx USB user guide document.
43 static u8 phy_on(void)
48 cfgchip2 = readl(&davinci_syscfg_regs->cfgchip2);
50 cfgchip2 &= ~(CFGCHIP2_RESET | CFGCHIP2_PHYPWRDN | CFGCHIP2_OTGPWRDN |
51 CFGCHIP2_OTGMODE | CFGCHIP2_REFFREQ);
52 cfgchip2 |= CFGCHIP2_SESENDEN | CFGCHIP2_VBDTCTEN | CFGCHIP2_PHY_PLLON |
53 CFGCHIP2_REFFREQ_24MHZ;
55 writel(cfgchip2, &davinci_syscfg_regs->cfgchip2);
57 /* wait until the usb phy pll locks */
58 timeout = musb_cfg.timeout;
60 if (readl(&davinci_syscfg_regs->cfgchip2) & CFGCHIP2_PHYCLKGD)
63 /* USB phy was not turned on */
70 static void phy_off(void)
75 * Power down the on-chip PHY.
77 cfgchip2 = readl(&davinci_syscfg_regs->cfgchip2);
78 cfgchip2 &= ~CFGCHIP2_PHY_PLLON;
79 cfgchip2 |= CFGCHIP2_PHYPWRDN | CFGCHIP2_OTGPWRDN;
80 writel(cfgchip2, &davinci_syscfg_regs->cfgchip2);
84 * This function performs DA8xx platform specific initialization for usb0.
86 int musb_platform_init(void)
90 /* enable psc for usb2.0 */
96 /* reset the controller */
97 writel(0x1, &da8xx_usb_regs->control);
100 /* start the on-chip usb phy and its pll */
104 /* Returns zero if e.g. not clocked */
105 revision = readl(&da8xx_usb_regs->revision);
109 /* Disable all interrupts */
110 writel((DA8XX_USB_USBINT_MASK | DA8XX_USB_TXINT_MASK |
111 DA8XX_USB_RXINT_MASK), &da8xx_usb_regs->intmsk_set);
116 * This function performs DA8xx platform specific deinitialization for usb0.
118 void musb_platform_deinit(void)
120 /* Turn of the phy */
123 /* flush any interrupts */
124 writel((DA8XX_USB_USBINT_MASK | DA8XX_USB_TXINT_MASK |
125 DA8XX_USB_RXINT_MASK), &da8xx_usb_regs->intmsk_clr);
126 writel(0, &da8xx_usb_regs->eoi);