xref: /rk3399_rockchip-uboot/drivers/usb/musb/davinci.c (revision 0910d0bcb85acdf09b9dfd8ded452367b540a4ad)
1 /*
2  * TI's Davinci platform specific USB wrapper functions.
3  *
4  * Copyright (c) 2008 Texas Instruments
5  *
6  * This program is free software; you can redistribute it and/or
7  * modify it under the terms of the GNU General Public License as
8  * published by the Free Software Foundation; either version 2 of
9  * the License, or (at your option) any later version.
10  *
11  * This program is distributed in the hope that it will be useful,
12  * but WITHOUT ANY WARRANTY; without even the implied warranty of
13  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14  * GNU General Public License for more details.
15  *
16  * You should have received a copy of the GNU General Public License
17  * along with this program; if not, write to the Free Software
18  * Foundation, Inc., 59 Temple Place, Suite 330, Boston,
19  * MA 02111-1307 USA
20  *
21  * Author: Thomas Abraham t-abraham@ti.com, Texas Instruments
22  */
23 
24 #include <common.h>
25 #include <asm/io.h>
26 #include "davinci.h"
27 #include <asm/arch/hardware.h>
28 
29 #if !defined(CONFIG_DV_USBPHY_CTL)
30 #define CONFIG_DV_USBPHY_CTL (USBPHY_SESNDEN | USBPHY_VBDTCTEN)
31 #endif
32 
33 /* MUSB platform configuration */
34 struct musb_config musb_cfg = {
35 	.regs		= (struct musb_regs *)MENTOR_USB0_BASE,
36 	.timeout	= DAVINCI_USB_TIMEOUT,
37 	.musb_speed	= 0,
38 };
39 
40 /* MUSB module register overlay */
41 struct davinci_usb_regs *dregs;
42 
43 /*
44  * Enable the USB phy
45  */
46 static u8 phy_on(void)
47 {
48 	u32 timeout;
49 #ifdef DAVINCI_DM365EVM
50 	u32 val;
51 #endif
52 	/* Wait until the USB phy is turned on */
53 #ifdef DAVINCI_DM365EVM
54 	writel(USBPHY_PHY24MHZ | USBPHY_SESNDEN |
55 			USBPHY_VBDTCTEN, USBPHY_CTL_PADDR);
56 #else
57 	writel(CONFIG_DV_USBPHY_CTL, USBPHY_CTL_PADDR);
58 #endif
59 	timeout = musb_cfg.timeout;
60 
61 #ifdef DAVINCI_DM365EVM
62 	/* Set the ownership of GIO33 to USB */
63 	val = readl(PINMUX4);
64 	val &= ~(PINMUX4_USBDRVBUS_BITCLEAR);
65 	val |= PINMUX4_USBDRVBUS_BITSET;
66 	writel(val, PINMUX4);
67 #endif
68 	while (timeout--)
69 		if (readl(USBPHY_CTL_PADDR) & USBPHY_PHYCLKGD)
70 			return 1;
71 
72 	/* USB phy was not turned on */
73 	return 0;
74 }
75 
76 /*
77  * Disable the USB phy
78  */
79 static void phy_off(void)
80 {
81 	/* powerdown the on-chip PHY and its oscillator */
82 	writel(USBPHY_OSCPDWN | USBPHY_PHYPDWN, USBPHY_CTL_PADDR);
83 }
84 
85 void __enable_vbus(void)
86 {
87 	/*
88 	 *  nothing to do, vbus is handled through the cpu.
89 	 *  Define this function in board code, if it is
90 	 *  different on your board.
91 	 */
92 }
93 void  enable_vbus(void)
94 	__attribute__((weak, alias("__enable_vbus")));
95 
96 /*
97  * This function performs Davinci platform specific initialization for usb0.
98  */
99 int musb_platform_init(void)
100 {
101 	u32  revision;
102 
103 	/* enable USB VBUS */
104 	enable_vbus();
105 
106 	/* start the on-chip USB phy and its pll */
107 	if (!phy_on())
108 		return -1;
109 
110 	/* reset the controller */
111 	dregs = (struct davinci_usb_regs *)DAVINCI_USB0_BASE;
112 	writel(1, &dregs->ctrlr);
113 	udelay(5000);
114 
115 	/* Returns zero if e.g. not clocked */
116 	revision = readl(&dregs->version);
117 	if (!revision)
118 		return -1;
119 
120 	/* Disable all interrupts */
121 	writel(DAVINCI_USB_USBINT_MASK | DAVINCI_USB_RXINT_MASK |
122 			DAVINCI_USB_TXINT_MASK , &dregs->intmsksetr);
123 	return 0;
124 }
125 
126 /*
127  * This function performs Davinci platform specific deinitialization for usb0.
128  */
129 void musb_platform_deinit(void)
130 {
131 	/* Turn of the phy */
132 	phy_off();
133 
134 	/* flush any interrupts */
135 	writel(DAVINCI_USB_USBINT_MASK | DAVINCI_USB_TXINT_MASK |
136 			DAVINCI_USB_RXINT_MASK , &dregs->intclrr);
137 }
138