omap-usb-host.c 30 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071
  1. /**
  2. * omap-usb-host.c - The USBHS core driver for OMAP EHCI & OHCI
  3. *
  4. * Copyright (C) 2011 Texas Instruments Incorporated - http://www.ti.com
  5. * Author: Keshava Munegowda <keshava_mgowda@ti.com>
  6. *
  7. * This program is free software: you can redistribute it and/or modify
  8. * it under the terms of the GNU General Public License version 2 of
  9. * the License as published by the Free Software Foundation.
  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, see <http://www.gnu.org/licenses/>.
  18. */
  19. #include <linux/kernel.h>
  20. #include <linux/types.h>
  21. #include <linux/slab.h>
  22. #include <linux/delay.h>
  23. #include <linux/platform_device.h>
  24. #include <linux/clk.h>
  25. #include <linux/dma-mapping.h>
  26. #include <linux/spinlock.h>
  27. #include <linux/gpio.h>
  28. #include <plat/usb.h>
  29. #define USBHS_DRIVER_NAME "usbhs-omap"
  30. #define OMAP_EHCI_DEVICE "ehci-omap"
  31. #define OMAP_OHCI_DEVICE "ohci-omap3"
  32. /* OMAP USBHOST Register addresses */
  33. /* TLL Register Set */
  34. #define OMAP_USBTLL_REVISION (0x00)
  35. #define OMAP_USBTLL_SYSCONFIG (0x10)
  36. #define OMAP_USBTLL_SYSCONFIG_CACTIVITY (1 << 8)
  37. #define OMAP_USBTLL_SYSCONFIG_SIDLEMODE (1 << 3)
  38. #define OMAP_USBTLL_SYSCONFIG_ENAWAKEUP (1 << 2)
  39. #define OMAP_USBTLL_SYSCONFIG_SOFTRESET (1 << 1)
  40. #define OMAP_USBTLL_SYSCONFIG_AUTOIDLE (1 << 0)
  41. #define OMAP_USBTLL_SYSSTATUS (0x14)
  42. #define OMAP_USBTLL_SYSSTATUS_RESETDONE (1 << 0)
  43. #define OMAP_USBTLL_IRQSTATUS (0x18)
  44. #define OMAP_USBTLL_IRQENABLE (0x1C)
  45. #define OMAP_TLL_SHARED_CONF (0x30)
  46. #define OMAP_TLL_SHARED_CONF_USB_90D_DDR_EN (1 << 6)
  47. #define OMAP_TLL_SHARED_CONF_USB_180D_SDR_EN (1 << 5)
  48. #define OMAP_TLL_SHARED_CONF_USB_DIVRATION (1 << 2)
  49. #define OMAP_TLL_SHARED_CONF_FCLK_REQ (1 << 1)
  50. #define OMAP_TLL_SHARED_CONF_FCLK_IS_ON (1 << 0)
  51. #define OMAP_TLL_CHANNEL_CONF(num) (0x040 + 0x004 * num)
  52. #define OMAP_TLL_CHANNEL_CONF_FSLSMODE_SHIFT 24
  53. #define OMAP_TLL_CHANNEL_CONF_ULPINOBITSTUFF (1 << 11)
  54. #define OMAP_TLL_CHANNEL_CONF_ULPI_ULPIAUTOIDLE (1 << 10)
  55. #define OMAP_TLL_CHANNEL_CONF_UTMIAUTOIDLE (1 << 9)
  56. #define OMAP_TLL_CHANNEL_CONF_ULPIDDRMODE (1 << 8)
  57. #define OMAP_TLL_CHANNEL_CONF_CHANMODE_FSLS (1 << 1)
  58. #define OMAP_TLL_CHANNEL_CONF_CHANEN (1 << 0)
  59. #define OMAP_TLL_FSLSMODE_6PIN_PHY_DAT_SE0 0x0
  60. #define OMAP_TLL_FSLSMODE_6PIN_PHY_DP_DM 0x1
  61. #define OMAP_TLL_FSLSMODE_3PIN_PHY 0x2
  62. #define OMAP_TLL_FSLSMODE_4PIN_PHY 0x3
  63. #define OMAP_TLL_FSLSMODE_6PIN_TLL_DAT_SE0 0x4
  64. #define OMAP_TLL_FSLSMODE_6PIN_TLL_DP_DM 0x5
  65. #define OMAP_TLL_FSLSMODE_3PIN_TLL 0x6
  66. #define OMAP_TLL_FSLSMODE_4PIN_TLL 0x7
  67. #define OMAP_TLL_FSLSMODE_2PIN_TLL_DAT_SE0 0xA
  68. #define OMAP_TLL_FSLSMODE_2PIN_DAT_DP_DM 0xB
  69. #define OMAP_TLL_ULPI_FUNCTION_CTRL(num) (0x804 + 0x100 * num)
  70. #define OMAP_TLL_ULPI_INTERFACE_CTRL(num) (0x807 + 0x100 * num)
  71. #define OMAP_TLL_ULPI_OTG_CTRL(num) (0x80A + 0x100 * num)
  72. #define OMAP_TLL_ULPI_INT_EN_RISE(num) (0x80D + 0x100 * num)
  73. #define OMAP_TLL_ULPI_INT_EN_FALL(num) (0x810 + 0x100 * num)
  74. #define OMAP_TLL_ULPI_INT_STATUS(num) (0x813 + 0x100 * num)
  75. #define OMAP_TLL_ULPI_INT_LATCH(num) (0x814 + 0x100 * num)
  76. #define OMAP_TLL_ULPI_DEBUG(num) (0x815 + 0x100 * num)
  77. #define OMAP_TLL_ULPI_SCRATCH_REGISTER(num) (0x816 + 0x100 * num)
  78. #define OMAP_TLL_CHANNEL_COUNT 3
  79. #define OMAP_TLL_CHANNEL_1_EN_MASK (1 << 0)
  80. #define OMAP_TLL_CHANNEL_2_EN_MASK (1 << 1)
  81. #define OMAP_TLL_CHANNEL_3_EN_MASK (1 << 2)
  82. /* UHH Register Set */
  83. #define OMAP_UHH_REVISION (0x00)
  84. #define OMAP_UHH_SYSCONFIG (0x10)
  85. #define OMAP_UHH_SYSCONFIG_MIDLEMODE (1 << 12)
  86. #define OMAP_UHH_SYSCONFIG_CACTIVITY (1 << 8)
  87. #define OMAP_UHH_SYSCONFIG_SIDLEMODE (1 << 3)
  88. #define OMAP_UHH_SYSCONFIG_ENAWAKEUP (1 << 2)
  89. #define OMAP_UHH_SYSCONFIG_SOFTRESET (1 << 1)
  90. #define OMAP_UHH_SYSCONFIG_AUTOIDLE (1 << 0)
  91. #define OMAP_UHH_SYSSTATUS (0x14)
  92. #define OMAP_UHH_HOSTCONFIG (0x40)
  93. #define OMAP_UHH_HOSTCONFIG_ULPI_BYPASS (1 << 0)
  94. #define OMAP_UHH_HOSTCONFIG_ULPI_P1_BYPASS (1 << 0)
  95. #define OMAP_UHH_HOSTCONFIG_ULPI_P2_BYPASS (1 << 11)
  96. #define OMAP_UHH_HOSTCONFIG_ULPI_P3_BYPASS (1 << 12)
  97. #define OMAP_UHH_HOSTCONFIG_INCR4_BURST_EN (1 << 2)
  98. #define OMAP_UHH_HOSTCONFIG_INCR8_BURST_EN (1 << 3)
  99. #define OMAP_UHH_HOSTCONFIG_INCR16_BURST_EN (1 << 4)
  100. #define OMAP_UHH_HOSTCONFIG_INCRX_ALIGN_EN (1 << 5)
  101. #define OMAP_UHH_HOSTCONFIG_P1_CONNECT_STATUS (1 << 8)
  102. #define OMAP_UHH_HOSTCONFIG_P2_CONNECT_STATUS (1 << 9)
  103. #define OMAP_UHH_HOSTCONFIG_P3_CONNECT_STATUS (1 << 10)
  104. #define OMAP4_UHH_HOSTCONFIG_APP_START_CLK (1 << 31)
  105. /* OMAP4-specific defines */
  106. #define OMAP4_UHH_SYSCONFIG_IDLEMODE_CLEAR (3 << 2)
  107. #define OMAP4_UHH_SYSCONFIG_NOIDLE (1 << 2)
  108. #define OMAP4_UHH_SYSCONFIG_STDBYMODE_CLEAR (3 << 4)
  109. #define OMAP4_UHH_SYSCONFIG_NOSTDBY (1 << 4)
  110. #define OMAP4_UHH_SYSCONFIG_SOFTRESET (1 << 0)
  111. #define OMAP4_P1_MODE_CLEAR (3 << 16)
  112. #define OMAP4_P1_MODE_TLL (1 << 16)
  113. #define OMAP4_P1_MODE_HSIC (3 << 16)
  114. #define OMAP4_P2_MODE_CLEAR (3 << 18)
  115. #define OMAP4_P2_MODE_TLL (1 << 18)
  116. #define OMAP4_P2_MODE_HSIC (3 << 18)
  117. #define OMAP_REV2_TLL_CHANNEL_COUNT 2
  118. #define OMAP_UHH_DEBUG_CSR (0x44)
  119. /* Values of UHH_REVISION - Note: these are not given in the TRM */
  120. #define OMAP_USBHS_REV1 0x00000010 /* OMAP3 */
  121. #define OMAP_USBHS_REV2 0x50700100 /* OMAP4 */
  122. #define is_omap_usbhs_rev1(x) (x->usbhs_rev == OMAP_USBHS_REV1)
  123. #define is_omap_usbhs_rev2(x) (x->usbhs_rev == OMAP_USBHS_REV2)
  124. #define is_ehci_phy_mode(x) (x == OMAP_EHCI_PORT_MODE_PHY)
  125. #define is_ehci_tll_mode(x) (x == OMAP_EHCI_PORT_MODE_TLL)
  126. #define is_ehci_hsic_mode(x) (x == OMAP_EHCI_PORT_MODE_HSIC)
  127. struct usbhs_hcd_omap {
  128. struct clk *usbhost_ick;
  129. struct clk *usbhost_hs_fck;
  130. struct clk *usbhost_fs_fck;
  131. struct clk *xclk60mhsp1_ck;
  132. struct clk *xclk60mhsp2_ck;
  133. struct clk *utmi_p1_fck;
  134. struct clk *usbhost_p1_fck;
  135. struct clk *usbtll_p1_fck;
  136. struct clk *utmi_p2_fck;
  137. struct clk *usbhost_p2_fck;
  138. struct clk *usbtll_p2_fck;
  139. struct clk *init_60m_fclk;
  140. struct clk *usbtll_fck;
  141. struct clk *usbtll_ick;
  142. void __iomem *uhh_base;
  143. void __iomem *tll_base;
  144. struct usbhs_omap_platform_data platdata;
  145. u32 usbhs_rev;
  146. spinlock_t lock;
  147. int count;
  148. };
  149. /*-------------------------------------------------------------------------*/
  150. const char usbhs_driver_name[] = USBHS_DRIVER_NAME;
  151. static u64 usbhs_dmamask = ~(u32)0;
  152. /*-------------------------------------------------------------------------*/
  153. static inline void usbhs_write(void __iomem *base, u32 reg, u32 val)
  154. {
  155. __raw_writel(val, base + reg);
  156. }
  157. static inline u32 usbhs_read(void __iomem *base, u32 reg)
  158. {
  159. return __raw_readl(base + reg);
  160. }
  161. static inline void usbhs_writeb(void __iomem *base, u8 reg, u8 val)
  162. {
  163. __raw_writeb(val, base + reg);
  164. }
  165. static inline u8 usbhs_readb(void __iomem *base, u8 reg)
  166. {
  167. return __raw_readb(base + reg);
  168. }
  169. /*-------------------------------------------------------------------------*/
  170. static struct platform_device *omap_usbhs_alloc_child(const char *name,
  171. struct resource *res, int num_resources, void *pdata,
  172. size_t pdata_size, struct device *dev)
  173. {
  174. struct platform_device *child;
  175. int ret;
  176. child = platform_device_alloc(name, 0);
  177. if (!child) {
  178. dev_err(dev, "platform_device_alloc %s failed\n", name);
  179. goto err_end;
  180. }
  181. ret = platform_device_add_resources(child, res, num_resources);
  182. if (ret) {
  183. dev_err(dev, "platform_device_add_resources failed\n");
  184. goto err_alloc;
  185. }
  186. ret = platform_device_add_data(child, pdata, pdata_size);
  187. if (ret) {
  188. dev_err(dev, "platform_device_add_data failed\n");
  189. goto err_alloc;
  190. }
  191. child->dev.dma_mask = &usbhs_dmamask;
  192. child->dev.coherent_dma_mask = 0xffffffff;
  193. child->dev.parent = dev;
  194. ret = platform_device_add(child);
  195. if (ret) {
  196. dev_err(dev, "platform_device_add failed\n");
  197. goto err_alloc;
  198. }
  199. return child;
  200. err_alloc:
  201. platform_device_put(child);
  202. err_end:
  203. return NULL;
  204. }
  205. static int omap_usbhs_alloc_children(struct platform_device *pdev)
  206. {
  207. struct device *dev = &pdev->dev;
  208. struct usbhs_hcd_omap *omap;
  209. struct ehci_hcd_omap_platform_data *ehci_data;
  210. struct ohci_hcd_omap_platform_data *ohci_data;
  211. struct platform_device *ehci;
  212. struct platform_device *ohci;
  213. struct resource *res;
  214. struct resource resources[2];
  215. int ret;
  216. omap = platform_get_drvdata(pdev);
  217. ehci_data = omap->platdata.ehci_data;
  218. ohci_data = omap->platdata.ohci_data;
  219. res = platform_get_resource_byname(pdev, IORESOURCE_MEM, "ehci");
  220. if (!res) {
  221. dev_err(dev, "EHCI get resource IORESOURCE_MEM failed\n");
  222. ret = -ENODEV;
  223. goto err_end;
  224. }
  225. resources[0] = *res;
  226. res = platform_get_resource_byname(pdev, IORESOURCE_IRQ, "ehci-irq");
  227. if (!res) {
  228. dev_err(dev, " EHCI get resource IORESOURCE_IRQ failed\n");
  229. ret = -ENODEV;
  230. goto err_end;
  231. }
  232. resources[1] = *res;
  233. ehci = omap_usbhs_alloc_child(OMAP_EHCI_DEVICE, resources, 2, ehci_data,
  234. sizeof(*ehci_data), dev);
  235. if (!ehci) {
  236. dev_err(dev, "omap_usbhs_alloc_child failed\n");
  237. ret = -ENOMEM;
  238. goto err_end;
  239. }
  240. res = platform_get_resource_byname(pdev, IORESOURCE_MEM, "ohci");
  241. if (!res) {
  242. dev_err(dev, "OHCI get resource IORESOURCE_MEM failed\n");
  243. ret = -ENODEV;
  244. goto err_ehci;
  245. }
  246. resources[0] = *res;
  247. res = platform_get_resource_byname(pdev, IORESOURCE_IRQ, "ohci-irq");
  248. if (!res) {
  249. dev_err(dev, "OHCI get resource IORESOURCE_IRQ failed\n");
  250. ret = -ENODEV;
  251. goto err_ehci;
  252. }
  253. resources[1] = *res;
  254. ohci = omap_usbhs_alloc_child(OMAP_OHCI_DEVICE, resources, 2, ohci_data,
  255. sizeof(*ohci_data), dev);
  256. if (!ohci) {
  257. dev_err(dev, "omap_usbhs_alloc_child failed\n");
  258. ret = -ENOMEM;
  259. goto err_ehci;
  260. }
  261. return 0;
  262. err_ehci:
  263. platform_device_unregister(ehci);
  264. err_end:
  265. return ret;
  266. }
  267. /**
  268. * usbhs_omap_probe - initialize TI-based HCDs
  269. *
  270. * Allocates basic resources for this USB host controller.
  271. */
  272. static int __devinit usbhs_omap_probe(struct platform_device *pdev)
  273. {
  274. struct device *dev = &pdev->dev;
  275. struct usbhs_omap_platform_data *pdata = dev->platform_data;
  276. struct usbhs_hcd_omap *omap;
  277. struct resource *res;
  278. int ret = 0;
  279. int i;
  280. if (!pdata) {
  281. dev_err(dev, "Missing platform data\n");
  282. ret = -ENOMEM;
  283. goto end_probe;
  284. }
  285. omap = kzalloc(sizeof(*omap), GFP_KERNEL);
  286. if (!omap) {
  287. dev_err(dev, "Memory allocation failed\n");
  288. ret = -ENOMEM;
  289. goto end_probe;
  290. }
  291. spin_lock_init(&omap->lock);
  292. for (i = 0; i < OMAP3_HS_USB_PORTS; i++)
  293. omap->platdata.port_mode[i] = pdata->port_mode[i];
  294. omap->platdata.ehci_data = pdata->ehci_data;
  295. omap->platdata.ohci_data = pdata->ohci_data;
  296. omap->usbhost_ick = clk_get(dev, "usbhost_ick");
  297. if (IS_ERR(omap->usbhost_ick)) {
  298. ret = PTR_ERR(omap->usbhost_ick);
  299. dev_err(dev, "usbhost_ick failed error:%d\n", ret);
  300. goto err_end;
  301. }
  302. omap->usbhost_hs_fck = clk_get(dev, "hs_fck");
  303. if (IS_ERR(omap->usbhost_hs_fck)) {
  304. ret = PTR_ERR(omap->usbhost_hs_fck);
  305. dev_err(dev, "usbhost_hs_fck failed error:%d\n", ret);
  306. goto err_usbhost_ick;
  307. }
  308. omap->usbhost_fs_fck = clk_get(dev, "fs_fck");
  309. if (IS_ERR(omap->usbhost_fs_fck)) {
  310. ret = PTR_ERR(omap->usbhost_fs_fck);
  311. dev_err(dev, "usbhost_fs_fck failed error:%d\n", ret);
  312. goto err_usbhost_hs_fck;
  313. }
  314. omap->usbtll_fck = clk_get(dev, "usbtll_fck");
  315. if (IS_ERR(omap->usbtll_fck)) {
  316. ret = PTR_ERR(omap->usbtll_fck);
  317. dev_err(dev, "usbtll_fck failed error:%d\n", ret);
  318. goto err_usbhost_fs_fck;
  319. }
  320. omap->usbtll_ick = clk_get(dev, "usbtll_ick");
  321. if (IS_ERR(omap->usbtll_ick)) {
  322. ret = PTR_ERR(omap->usbtll_ick);
  323. dev_err(dev, "usbtll_ick failed error:%d\n", ret);
  324. goto err_usbtll_fck;
  325. }
  326. omap->utmi_p1_fck = clk_get(dev, "utmi_p1_gfclk");
  327. if (IS_ERR(omap->utmi_p1_fck)) {
  328. ret = PTR_ERR(omap->utmi_p1_fck);
  329. dev_err(dev, "utmi_p1_gfclk failed error:%d\n", ret);
  330. goto err_usbtll_ick;
  331. }
  332. omap->xclk60mhsp1_ck = clk_get(dev, "xclk60mhsp1_ck");
  333. if (IS_ERR(omap->xclk60mhsp1_ck)) {
  334. ret = PTR_ERR(omap->xclk60mhsp1_ck);
  335. dev_err(dev, "xclk60mhsp1_ck failed error:%d\n", ret);
  336. goto err_utmi_p1_fck;
  337. }
  338. omap->utmi_p2_fck = clk_get(dev, "utmi_p2_gfclk");
  339. if (IS_ERR(omap->utmi_p2_fck)) {
  340. ret = PTR_ERR(omap->utmi_p2_fck);
  341. dev_err(dev, "utmi_p2_gfclk failed error:%d\n", ret);
  342. goto err_xclk60mhsp1_ck;
  343. }
  344. omap->xclk60mhsp2_ck = clk_get(dev, "xclk60mhsp2_ck");
  345. if (IS_ERR(omap->xclk60mhsp2_ck)) {
  346. ret = PTR_ERR(omap->xclk60mhsp2_ck);
  347. dev_err(dev, "xclk60mhsp2_ck failed error:%d\n", ret);
  348. goto err_utmi_p2_fck;
  349. }
  350. omap->usbhost_p1_fck = clk_get(dev, "usb_host_hs_utmi_p1_clk");
  351. if (IS_ERR(omap->usbhost_p1_fck)) {
  352. ret = PTR_ERR(omap->usbhost_p1_fck);
  353. dev_err(dev, "usbhost_p1_fck failed error:%d\n", ret);
  354. goto err_xclk60mhsp2_ck;
  355. }
  356. omap->usbtll_p1_fck = clk_get(dev, "usb_tll_hs_usb_ch0_clk");
  357. if (IS_ERR(omap->usbtll_p1_fck)) {
  358. ret = PTR_ERR(omap->usbtll_p1_fck);
  359. dev_err(dev, "usbtll_p1_fck failed error:%d\n", ret);
  360. goto err_usbhost_p1_fck;
  361. }
  362. omap->usbhost_p2_fck = clk_get(dev, "usb_host_hs_utmi_p2_clk");
  363. if (IS_ERR(omap->usbhost_p2_fck)) {
  364. ret = PTR_ERR(omap->usbhost_p2_fck);
  365. dev_err(dev, "usbhost_p2_fck failed error:%d\n", ret);
  366. goto err_usbtll_p1_fck;
  367. }
  368. omap->usbtll_p2_fck = clk_get(dev, "usb_tll_hs_usb_ch1_clk");
  369. if (IS_ERR(omap->usbtll_p2_fck)) {
  370. ret = PTR_ERR(omap->usbtll_p2_fck);
  371. dev_err(dev, "usbtll_p2_fck failed error:%d\n", ret);
  372. goto err_usbhost_p2_fck;
  373. }
  374. omap->init_60m_fclk = clk_get(dev, "init_60m_fclk");
  375. if (IS_ERR(omap->init_60m_fclk)) {
  376. ret = PTR_ERR(omap->init_60m_fclk);
  377. dev_err(dev, "init_60m_fclk failed error:%d\n", ret);
  378. goto err_usbtll_p2_fck;
  379. }
  380. res = platform_get_resource_byname(pdev, IORESOURCE_MEM, "uhh");
  381. if (!res) {
  382. dev_err(dev, "UHH EHCI get resource failed\n");
  383. ret = -ENODEV;
  384. goto err_init_60m_fclk;
  385. }
  386. omap->uhh_base = ioremap(res->start, resource_size(res));
  387. if (!omap->uhh_base) {
  388. dev_err(dev, "UHH ioremap failed\n");
  389. ret = -ENOMEM;
  390. goto err_init_60m_fclk;
  391. }
  392. res = platform_get_resource_byname(pdev, IORESOURCE_MEM, "tll");
  393. if (!res) {
  394. dev_err(dev, "UHH EHCI get resource failed\n");
  395. ret = -ENODEV;
  396. goto err_tll;
  397. }
  398. omap->tll_base = ioremap(res->start, resource_size(res));
  399. if (!omap->tll_base) {
  400. dev_err(dev, "TLL ioremap failed\n");
  401. ret = -ENOMEM;
  402. goto err_tll;
  403. }
  404. platform_set_drvdata(pdev, omap);
  405. ret = omap_usbhs_alloc_children(pdev);
  406. if (ret) {
  407. dev_err(dev, "omap_usbhs_alloc_children failed\n");
  408. goto err_alloc;
  409. }
  410. goto end_probe;
  411. err_alloc:
  412. iounmap(omap->tll_base);
  413. err_tll:
  414. iounmap(omap->uhh_base);
  415. err_init_60m_fclk:
  416. clk_put(omap->init_60m_fclk);
  417. err_usbtll_p2_fck:
  418. clk_put(omap->usbtll_p2_fck);
  419. err_usbhost_p2_fck:
  420. clk_put(omap->usbhost_p2_fck);
  421. err_usbtll_p1_fck:
  422. clk_put(omap->usbtll_p1_fck);
  423. err_usbhost_p1_fck:
  424. clk_put(omap->usbhost_p1_fck);
  425. err_xclk60mhsp2_ck:
  426. clk_put(omap->xclk60mhsp2_ck);
  427. err_utmi_p2_fck:
  428. clk_put(omap->utmi_p2_fck);
  429. err_xclk60mhsp1_ck:
  430. clk_put(omap->xclk60mhsp1_ck);
  431. err_utmi_p1_fck:
  432. clk_put(omap->utmi_p1_fck);
  433. err_usbtll_ick:
  434. clk_put(omap->usbtll_ick);
  435. err_usbtll_fck:
  436. clk_put(omap->usbtll_fck);
  437. err_usbhost_fs_fck:
  438. clk_put(omap->usbhost_fs_fck);
  439. err_usbhost_hs_fck:
  440. clk_put(omap->usbhost_hs_fck);
  441. err_usbhost_ick:
  442. clk_put(omap->usbhost_ick);
  443. err_end:
  444. kfree(omap);
  445. end_probe:
  446. return ret;
  447. }
  448. /**
  449. * usbhs_omap_remove - shutdown processing for UHH & TLL HCDs
  450. * @pdev: USB Host Controller being removed
  451. *
  452. * Reverses the effect of usbhs_omap_probe().
  453. */
  454. static int __devexit usbhs_omap_remove(struct platform_device *pdev)
  455. {
  456. struct usbhs_hcd_omap *omap = platform_get_drvdata(pdev);
  457. if (omap->count != 0) {
  458. dev_err(&pdev->dev,
  459. "Either EHCI or OHCI is still using usbhs core\n");
  460. return -EBUSY;
  461. }
  462. iounmap(omap->tll_base);
  463. iounmap(omap->uhh_base);
  464. clk_put(omap->init_60m_fclk);
  465. clk_put(omap->usbtll_p2_fck);
  466. clk_put(omap->usbhost_p2_fck);
  467. clk_put(omap->usbtll_p1_fck);
  468. clk_put(omap->usbhost_p1_fck);
  469. clk_put(omap->xclk60mhsp2_ck);
  470. clk_put(omap->utmi_p2_fck);
  471. clk_put(omap->xclk60mhsp1_ck);
  472. clk_put(omap->utmi_p1_fck);
  473. clk_put(omap->usbtll_ick);
  474. clk_put(omap->usbtll_fck);
  475. clk_put(omap->usbhost_fs_fck);
  476. clk_put(omap->usbhost_hs_fck);
  477. clk_put(omap->usbhost_ick);
  478. kfree(omap);
  479. return 0;
  480. }
  481. static bool is_ohci_port(enum usbhs_omap_port_mode pmode)
  482. {
  483. switch (pmode) {
  484. case OMAP_OHCI_PORT_MODE_PHY_6PIN_DATSE0:
  485. case OMAP_OHCI_PORT_MODE_PHY_6PIN_DPDM:
  486. case OMAP_OHCI_PORT_MODE_PHY_3PIN_DATSE0:
  487. case OMAP_OHCI_PORT_MODE_PHY_4PIN_DPDM:
  488. case OMAP_OHCI_PORT_MODE_TLL_6PIN_DATSE0:
  489. case OMAP_OHCI_PORT_MODE_TLL_6PIN_DPDM:
  490. case OMAP_OHCI_PORT_MODE_TLL_3PIN_DATSE0:
  491. case OMAP_OHCI_PORT_MODE_TLL_4PIN_DPDM:
  492. case OMAP_OHCI_PORT_MODE_TLL_2PIN_DATSE0:
  493. case OMAP_OHCI_PORT_MODE_TLL_2PIN_DPDM:
  494. return true;
  495. default:
  496. return false;
  497. }
  498. }
  499. /*
  500. * convert the port-mode enum to a value we can use in the FSLSMODE
  501. * field of USBTLL_CHANNEL_CONF
  502. */
  503. static unsigned ohci_omap3_fslsmode(enum usbhs_omap_port_mode mode)
  504. {
  505. switch (mode) {
  506. case OMAP_USBHS_PORT_MODE_UNUSED:
  507. case OMAP_OHCI_PORT_MODE_PHY_6PIN_DATSE0:
  508. return OMAP_TLL_FSLSMODE_6PIN_PHY_DAT_SE0;
  509. case OMAP_OHCI_PORT_MODE_PHY_6PIN_DPDM:
  510. return OMAP_TLL_FSLSMODE_6PIN_PHY_DP_DM;
  511. case OMAP_OHCI_PORT_MODE_PHY_3PIN_DATSE0:
  512. return OMAP_TLL_FSLSMODE_3PIN_PHY;
  513. case OMAP_OHCI_PORT_MODE_PHY_4PIN_DPDM:
  514. return OMAP_TLL_FSLSMODE_4PIN_PHY;
  515. case OMAP_OHCI_PORT_MODE_TLL_6PIN_DATSE0:
  516. return OMAP_TLL_FSLSMODE_6PIN_TLL_DAT_SE0;
  517. case OMAP_OHCI_PORT_MODE_TLL_6PIN_DPDM:
  518. return OMAP_TLL_FSLSMODE_6PIN_TLL_DP_DM;
  519. case OMAP_OHCI_PORT_MODE_TLL_3PIN_DATSE0:
  520. return OMAP_TLL_FSLSMODE_3PIN_TLL;
  521. case OMAP_OHCI_PORT_MODE_TLL_4PIN_DPDM:
  522. return OMAP_TLL_FSLSMODE_4PIN_TLL;
  523. case OMAP_OHCI_PORT_MODE_TLL_2PIN_DATSE0:
  524. return OMAP_TLL_FSLSMODE_2PIN_TLL_DAT_SE0;
  525. case OMAP_OHCI_PORT_MODE_TLL_2PIN_DPDM:
  526. return OMAP_TLL_FSLSMODE_2PIN_DAT_DP_DM;
  527. default:
  528. pr_warning("Invalid port mode, using default\n");
  529. return OMAP_TLL_FSLSMODE_6PIN_PHY_DAT_SE0;
  530. }
  531. }
  532. static void usbhs_omap_tll_init(struct device *dev, u8 tll_channel_count)
  533. {
  534. struct usbhs_hcd_omap *omap = dev_get_drvdata(dev);
  535. struct usbhs_omap_platform_data *pdata = dev->platform_data;
  536. unsigned reg;
  537. int i;
  538. /* Program Common TLL register */
  539. reg = usbhs_read(omap->tll_base, OMAP_TLL_SHARED_CONF);
  540. reg |= (OMAP_TLL_SHARED_CONF_FCLK_IS_ON
  541. | OMAP_TLL_SHARED_CONF_USB_DIVRATION);
  542. reg &= ~OMAP_TLL_SHARED_CONF_USB_90D_DDR_EN;
  543. reg &= ~OMAP_TLL_SHARED_CONF_USB_180D_SDR_EN;
  544. usbhs_write(omap->tll_base, OMAP_TLL_SHARED_CONF, reg);
  545. /* Enable channels now */
  546. for (i = 0; i < tll_channel_count; i++) {
  547. reg = usbhs_read(omap->tll_base,
  548. OMAP_TLL_CHANNEL_CONF(i));
  549. if (is_ohci_port(pdata->port_mode[i])) {
  550. reg |= ohci_omap3_fslsmode(pdata->port_mode[i])
  551. << OMAP_TLL_CHANNEL_CONF_FSLSMODE_SHIFT;
  552. reg |= OMAP_TLL_CHANNEL_CONF_CHANMODE_FSLS;
  553. } else if (pdata->port_mode[i] == OMAP_EHCI_PORT_MODE_TLL) {
  554. /* Disable AutoIdle, BitStuffing and use SDR Mode */
  555. reg &= ~(OMAP_TLL_CHANNEL_CONF_UTMIAUTOIDLE
  556. | OMAP_TLL_CHANNEL_CONF_ULPINOBITSTUFF
  557. | OMAP_TLL_CHANNEL_CONF_ULPIDDRMODE);
  558. } else
  559. continue;
  560. reg |= OMAP_TLL_CHANNEL_CONF_CHANEN;
  561. usbhs_write(omap->tll_base,
  562. OMAP_TLL_CHANNEL_CONF(i), reg);
  563. usbhs_writeb(omap->tll_base,
  564. OMAP_TLL_ULPI_SCRATCH_REGISTER(i), 0xbe);
  565. }
  566. }
  567. static int usbhs_enable(struct device *dev)
  568. {
  569. struct usbhs_hcd_omap *omap = dev_get_drvdata(dev);
  570. struct usbhs_omap_platform_data *pdata = &omap->platdata;
  571. unsigned long flags = 0;
  572. int ret = 0;
  573. unsigned long timeout;
  574. unsigned reg;
  575. dev_dbg(dev, "starting TI HSUSB Controller\n");
  576. if (!pdata) {
  577. dev_dbg(dev, "missing platform_data\n");
  578. return -ENODEV;
  579. }
  580. spin_lock_irqsave(&omap->lock, flags);
  581. if (omap->count > 0)
  582. goto end_count;
  583. clk_enable(omap->usbhost_ick);
  584. clk_enable(omap->usbhost_hs_fck);
  585. clk_enable(omap->usbhost_fs_fck);
  586. clk_enable(omap->usbtll_fck);
  587. clk_enable(omap->usbtll_ick);
  588. if (pdata->ehci_data->phy_reset) {
  589. if (gpio_is_valid(pdata->ehci_data->reset_gpio_port[0])) {
  590. gpio_request(pdata->ehci_data->reset_gpio_port[0],
  591. "USB1 PHY reset");
  592. gpio_direction_output
  593. (pdata->ehci_data->reset_gpio_port[0], 0);
  594. }
  595. if (gpio_is_valid(pdata->ehci_data->reset_gpio_port[1])) {
  596. gpio_request(pdata->ehci_data->reset_gpio_port[1],
  597. "USB2 PHY reset");
  598. gpio_direction_output
  599. (pdata->ehci_data->reset_gpio_port[1], 0);
  600. }
  601. /* Hold the PHY in RESET for enough time till DIR is high */
  602. udelay(10);
  603. }
  604. omap->usbhs_rev = usbhs_read(omap->uhh_base, OMAP_UHH_REVISION);
  605. dev_dbg(dev, "OMAP UHH_REVISION 0x%x\n", omap->usbhs_rev);
  606. /* perform TLL soft reset, and wait until reset is complete */
  607. usbhs_write(omap->tll_base, OMAP_USBTLL_SYSCONFIG,
  608. OMAP_USBTLL_SYSCONFIG_SOFTRESET);
  609. /* Wait for TLL reset to complete */
  610. timeout = jiffies + msecs_to_jiffies(1000);
  611. while (!(usbhs_read(omap->tll_base, OMAP_USBTLL_SYSSTATUS)
  612. & OMAP_USBTLL_SYSSTATUS_RESETDONE)) {
  613. cpu_relax();
  614. if (time_after(jiffies, timeout)) {
  615. dev_dbg(dev, "operation timed out\n");
  616. ret = -EINVAL;
  617. goto err_tll;
  618. }
  619. }
  620. dev_dbg(dev, "TLL RESET DONE\n");
  621. /* (1<<3) = no idle mode only for initial debugging */
  622. usbhs_write(omap->tll_base, OMAP_USBTLL_SYSCONFIG,
  623. OMAP_USBTLL_SYSCONFIG_ENAWAKEUP |
  624. OMAP_USBTLL_SYSCONFIG_SIDLEMODE |
  625. OMAP_USBTLL_SYSCONFIG_AUTOIDLE);
  626. /* Put UHH in NoIdle/NoStandby mode */
  627. reg = usbhs_read(omap->uhh_base, OMAP_UHH_SYSCONFIG);
  628. if (is_omap_usbhs_rev1(omap)) {
  629. reg |= (OMAP_UHH_SYSCONFIG_ENAWAKEUP
  630. | OMAP_UHH_SYSCONFIG_SIDLEMODE
  631. | OMAP_UHH_SYSCONFIG_CACTIVITY
  632. | OMAP_UHH_SYSCONFIG_MIDLEMODE);
  633. reg &= ~OMAP_UHH_SYSCONFIG_AUTOIDLE;
  634. } else if (is_omap_usbhs_rev2(omap)) {
  635. reg &= ~OMAP4_UHH_SYSCONFIG_IDLEMODE_CLEAR;
  636. reg |= OMAP4_UHH_SYSCONFIG_NOIDLE;
  637. reg &= ~OMAP4_UHH_SYSCONFIG_STDBYMODE_CLEAR;
  638. reg |= OMAP4_UHH_SYSCONFIG_NOSTDBY;
  639. }
  640. usbhs_write(omap->uhh_base, OMAP_UHH_SYSCONFIG, reg);
  641. reg = usbhs_read(omap->uhh_base, OMAP_UHH_HOSTCONFIG);
  642. /* setup ULPI bypass and burst configurations */
  643. reg |= (OMAP_UHH_HOSTCONFIG_INCR4_BURST_EN
  644. | OMAP_UHH_HOSTCONFIG_INCR8_BURST_EN
  645. | OMAP_UHH_HOSTCONFIG_INCR16_BURST_EN);
  646. reg |= OMAP4_UHH_HOSTCONFIG_APP_START_CLK;
  647. reg &= ~OMAP_UHH_HOSTCONFIG_INCRX_ALIGN_EN;
  648. if (is_omap_usbhs_rev1(omap)) {
  649. if (pdata->port_mode[0] == OMAP_USBHS_PORT_MODE_UNUSED)
  650. reg &= ~OMAP_UHH_HOSTCONFIG_P1_CONNECT_STATUS;
  651. if (pdata->port_mode[1] == OMAP_USBHS_PORT_MODE_UNUSED)
  652. reg &= ~OMAP_UHH_HOSTCONFIG_P2_CONNECT_STATUS;
  653. if (pdata->port_mode[2] == OMAP_USBHS_PORT_MODE_UNUSED)
  654. reg &= ~OMAP_UHH_HOSTCONFIG_P3_CONNECT_STATUS;
  655. /* Bypass the TLL module for PHY mode operation */
  656. if (cpu_is_omap3430() && (omap_rev() <= OMAP3430_REV_ES2_1)) {
  657. dev_dbg(dev, "OMAP3 ES version <= ES2.1\n");
  658. if (is_ehci_phy_mode(pdata->port_mode[0]) ||
  659. is_ehci_phy_mode(pdata->port_mode[1]) ||
  660. is_ehci_phy_mode(pdata->port_mode[2]))
  661. reg &= ~OMAP_UHH_HOSTCONFIG_ULPI_BYPASS;
  662. else
  663. reg |= OMAP_UHH_HOSTCONFIG_ULPI_BYPASS;
  664. } else {
  665. dev_dbg(dev, "OMAP3 ES version > ES2.1\n");
  666. if (is_ehci_phy_mode(pdata->port_mode[0]))
  667. reg &= ~OMAP_UHH_HOSTCONFIG_ULPI_P1_BYPASS;
  668. else
  669. reg |= OMAP_UHH_HOSTCONFIG_ULPI_P1_BYPASS;
  670. if (is_ehci_phy_mode(pdata->port_mode[1]))
  671. reg &= ~OMAP_UHH_HOSTCONFIG_ULPI_P2_BYPASS;
  672. else
  673. reg |= OMAP_UHH_HOSTCONFIG_ULPI_P2_BYPASS;
  674. if (is_ehci_phy_mode(pdata->port_mode[2]))
  675. reg &= ~OMAP_UHH_HOSTCONFIG_ULPI_P3_BYPASS;
  676. else
  677. reg |= OMAP_UHH_HOSTCONFIG_ULPI_P3_BYPASS;
  678. }
  679. } else if (is_omap_usbhs_rev2(omap)) {
  680. /* Clear port mode fields for PHY mode*/
  681. reg &= ~OMAP4_P1_MODE_CLEAR;
  682. reg &= ~OMAP4_P2_MODE_CLEAR;
  683. if (is_ehci_phy_mode(pdata->port_mode[0])) {
  684. ret = clk_set_parent(omap->utmi_p1_fck,
  685. omap->xclk60mhsp1_ck);
  686. if (ret != 0) {
  687. dev_err(dev, "xclk60mhsp1_ck set parent"
  688. "failed error:%d\n", ret);
  689. goto err_tll;
  690. }
  691. } else if (is_ehci_tll_mode(pdata->port_mode[0])) {
  692. ret = clk_set_parent(omap->utmi_p1_fck,
  693. omap->init_60m_fclk);
  694. if (ret != 0) {
  695. dev_err(dev, "init_60m_fclk set parent"
  696. "failed error:%d\n", ret);
  697. goto err_tll;
  698. }
  699. clk_enable(omap->usbhost_p1_fck);
  700. clk_enable(omap->usbtll_p1_fck);
  701. }
  702. if (is_ehci_phy_mode(pdata->port_mode[1])) {
  703. ret = clk_set_parent(omap->utmi_p2_fck,
  704. omap->xclk60mhsp2_ck);
  705. if (ret != 0) {
  706. dev_err(dev, "xclk60mhsp1_ck set parent"
  707. "failed error:%d\n", ret);
  708. goto err_tll;
  709. }
  710. } else if (is_ehci_tll_mode(pdata->port_mode[1])) {
  711. ret = clk_set_parent(omap->utmi_p2_fck,
  712. omap->init_60m_fclk);
  713. if (ret != 0) {
  714. dev_err(dev, "init_60m_fclk set parent"
  715. "failed error:%d\n", ret);
  716. goto err_tll;
  717. }
  718. clk_enable(omap->usbhost_p2_fck);
  719. clk_enable(omap->usbtll_p2_fck);
  720. }
  721. clk_enable(omap->utmi_p1_fck);
  722. clk_enable(omap->utmi_p2_fck);
  723. if (is_ehci_tll_mode(pdata->port_mode[0]) ||
  724. (is_ohci_port(pdata->port_mode[0])))
  725. reg |= OMAP4_P1_MODE_TLL;
  726. else if (is_ehci_hsic_mode(pdata->port_mode[0]))
  727. reg |= OMAP4_P1_MODE_HSIC;
  728. if (is_ehci_tll_mode(pdata->port_mode[1]) ||
  729. (is_ohci_port(pdata->port_mode[1])))
  730. reg |= OMAP4_P2_MODE_TLL;
  731. else if (is_ehci_hsic_mode(pdata->port_mode[1]))
  732. reg |= OMAP4_P2_MODE_HSIC;
  733. }
  734. usbhs_write(omap->uhh_base, OMAP_UHH_HOSTCONFIG, reg);
  735. dev_dbg(dev, "UHH setup done, uhh_hostconfig=%x\n", reg);
  736. if (is_ehci_tll_mode(pdata->port_mode[0]) ||
  737. is_ehci_tll_mode(pdata->port_mode[1]) ||
  738. is_ehci_tll_mode(pdata->port_mode[2]) ||
  739. (is_ohci_port(pdata->port_mode[0])) ||
  740. (is_ohci_port(pdata->port_mode[1])) ||
  741. (is_ohci_port(pdata->port_mode[2]))) {
  742. /* Enable UTMI mode for required TLL channels */
  743. if (is_omap_usbhs_rev2(omap))
  744. usbhs_omap_tll_init(dev, OMAP_REV2_TLL_CHANNEL_COUNT);
  745. else
  746. usbhs_omap_tll_init(dev, OMAP_TLL_CHANNEL_COUNT);
  747. }
  748. if (pdata->ehci_data->phy_reset) {
  749. /* Hold the PHY in RESET for enough time till
  750. * PHY is settled and ready
  751. */
  752. udelay(10);
  753. if (gpio_is_valid(pdata->ehci_data->reset_gpio_port[0]))
  754. gpio_set_value
  755. (pdata->ehci_data->reset_gpio_port[0], 1);
  756. if (gpio_is_valid(pdata->ehci_data->reset_gpio_port[1]))
  757. gpio_set_value
  758. (pdata->ehci_data->reset_gpio_port[1], 1);
  759. }
  760. end_count:
  761. omap->count++;
  762. spin_unlock_irqrestore(&omap->lock, flags);
  763. return 0;
  764. err_tll:
  765. if (pdata->ehci_data->phy_reset) {
  766. if (gpio_is_valid(pdata->ehci_data->reset_gpio_port[0]))
  767. gpio_free(pdata->ehci_data->reset_gpio_port[0]);
  768. if (gpio_is_valid(pdata->ehci_data->reset_gpio_port[1]))
  769. gpio_free(pdata->ehci_data->reset_gpio_port[1]);
  770. }
  771. clk_disable(omap->usbtll_ick);
  772. clk_disable(omap->usbtll_fck);
  773. clk_disable(omap->usbhost_fs_fck);
  774. clk_disable(omap->usbhost_hs_fck);
  775. clk_disable(omap->usbhost_ick);
  776. spin_unlock_irqrestore(&omap->lock, flags);
  777. return ret;
  778. }
  779. static void usbhs_disable(struct device *dev)
  780. {
  781. struct usbhs_hcd_omap *omap = dev_get_drvdata(dev);
  782. struct usbhs_omap_platform_data *pdata = &omap->platdata;
  783. unsigned long flags = 0;
  784. unsigned long timeout;
  785. dev_dbg(dev, "stopping TI HSUSB Controller\n");
  786. spin_lock_irqsave(&omap->lock, flags);
  787. if (omap->count == 0)
  788. goto end_disble;
  789. omap->count--;
  790. if (omap->count != 0)
  791. goto end_disble;
  792. /* Reset OMAP modules for insmod/rmmod to work */
  793. usbhs_write(omap->uhh_base, OMAP_UHH_SYSCONFIG,
  794. is_omap_usbhs_rev2(omap) ?
  795. OMAP4_UHH_SYSCONFIG_SOFTRESET :
  796. OMAP_UHH_SYSCONFIG_SOFTRESET);
  797. timeout = jiffies + msecs_to_jiffies(100);
  798. while (!(usbhs_read(omap->uhh_base, OMAP_UHH_SYSSTATUS)
  799. & (1 << 0))) {
  800. cpu_relax();
  801. if (time_after(jiffies, timeout))
  802. dev_dbg(dev, "operation timed out\n");
  803. }
  804. while (!(usbhs_read(omap->uhh_base, OMAP_UHH_SYSSTATUS)
  805. & (1 << 1))) {
  806. cpu_relax();
  807. if (time_after(jiffies, timeout))
  808. dev_dbg(dev, "operation timed out\n");
  809. }
  810. while (!(usbhs_read(omap->uhh_base, OMAP_UHH_SYSSTATUS)
  811. & (1 << 2))) {
  812. cpu_relax();
  813. if (time_after(jiffies, timeout))
  814. dev_dbg(dev, "operation timed out\n");
  815. }
  816. usbhs_write(omap->tll_base, OMAP_USBTLL_SYSCONFIG, (1 << 1));
  817. while (!(usbhs_read(omap->tll_base, OMAP_USBTLL_SYSSTATUS)
  818. & (1 << 0))) {
  819. cpu_relax();
  820. if (time_after(jiffies, timeout))
  821. dev_dbg(dev, "operation timed out\n");
  822. }
  823. if (is_omap_usbhs_rev2(omap)) {
  824. if (is_ehci_tll_mode(pdata->port_mode[0]))
  825. clk_enable(omap->usbtll_p1_fck);
  826. if (is_ehci_tll_mode(pdata->port_mode[1]))
  827. clk_enable(omap->usbtll_p2_fck);
  828. clk_disable(omap->utmi_p2_fck);
  829. clk_disable(omap->utmi_p1_fck);
  830. }
  831. clk_disable(omap->usbtll_ick);
  832. clk_disable(omap->usbtll_fck);
  833. clk_disable(omap->usbhost_fs_fck);
  834. clk_disable(omap->usbhost_hs_fck);
  835. clk_disable(omap->usbhost_ick);
  836. /* The gpio_free migh sleep; so unlock the spinlock */
  837. spin_unlock_irqrestore(&omap->lock, flags);
  838. if (pdata->ehci_data->phy_reset) {
  839. if (gpio_is_valid(pdata->ehci_data->reset_gpio_port[0]))
  840. gpio_free(pdata->ehci_data->reset_gpio_port[0]);
  841. if (gpio_is_valid(pdata->ehci_data->reset_gpio_port[1]))
  842. gpio_free(pdata->ehci_data->reset_gpio_port[1]);
  843. }
  844. return;
  845. end_disble:
  846. spin_unlock_irqrestore(&omap->lock, flags);
  847. }
  848. int omap_usbhs_enable(struct device *dev)
  849. {
  850. return usbhs_enable(dev->parent);
  851. }
  852. EXPORT_SYMBOL_GPL(omap_usbhs_enable);
  853. void omap_usbhs_disable(struct device *dev)
  854. {
  855. usbhs_disable(dev->parent);
  856. }
  857. EXPORT_SYMBOL_GPL(omap_usbhs_disable);
  858. static struct platform_driver usbhs_omap_driver = {
  859. .driver = {
  860. .name = (char *)usbhs_driver_name,
  861. .owner = THIS_MODULE,
  862. },
  863. .remove = __exit_p(usbhs_omap_remove),
  864. };
  865. MODULE_AUTHOR("Keshava Munegowda <keshava_mgowda@ti.com>");
  866. MODULE_ALIAS("platform:" USBHS_DRIVER_NAME);
  867. MODULE_LICENSE("GPL v2");
  868. MODULE_DESCRIPTION("usb host common core driver for omap EHCI and OHCI");
  869. static int __init omap_usbhs_drvinit(void)
  870. {
  871. return platform_driver_probe(&usbhs_omap_driver, usbhs_omap_probe);
  872. }
  873. /*
  874. * init before ehci and ohci drivers;
  875. * The usbhs core driver should be initialized much before
  876. * the omap ehci and ohci probe functions are called.
  877. */
  878. fs_initcall(omap_usbhs_drvinit);
  879. static void __exit omap_usbhs_drvexit(void)
  880. {
  881. platform_driver_unregister(&usbhs_omap_driver);
  882. }
  883. module_exit(omap_usbhs_drvexit);