omap-usb-host.c 19 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715
  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/module.h>
  21. #include <linux/types.h>
  22. #include <linux/slab.h>
  23. #include <linux/delay.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/cpu.h>
  29. #include <linux/platform_device.h>
  30. #include <linux/platform_data/usb-omap.h>
  31. #include <linux/pm_runtime.h>
  32. #include "omap-usb.h"
  33. #define USBHS_DRIVER_NAME "usbhs_omap"
  34. #define OMAP_EHCI_DEVICE "ehci-omap"
  35. #define OMAP_OHCI_DEVICE "ohci-omap3"
  36. /* OMAP USBHOST Register addresses */
  37. /* UHH Register Set */
  38. #define OMAP_UHH_REVISION (0x00)
  39. #define OMAP_UHH_SYSCONFIG (0x10)
  40. #define OMAP_UHH_SYSCONFIG_MIDLEMODE (1 << 12)
  41. #define OMAP_UHH_SYSCONFIG_CACTIVITY (1 << 8)
  42. #define OMAP_UHH_SYSCONFIG_SIDLEMODE (1 << 3)
  43. #define OMAP_UHH_SYSCONFIG_ENAWAKEUP (1 << 2)
  44. #define OMAP_UHH_SYSCONFIG_SOFTRESET (1 << 1)
  45. #define OMAP_UHH_SYSCONFIG_AUTOIDLE (1 << 0)
  46. #define OMAP_UHH_SYSSTATUS (0x14)
  47. #define OMAP_UHH_HOSTCONFIG (0x40)
  48. #define OMAP_UHH_HOSTCONFIG_ULPI_BYPASS (1 << 0)
  49. #define OMAP_UHH_HOSTCONFIG_ULPI_P1_BYPASS (1 << 0)
  50. #define OMAP_UHH_HOSTCONFIG_ULPI_P2_BYPASS (1 << 11)
  51. #define OMAP_UHH_HOSTCONFIG_ULPI_P3_BYPASS (1 << 12)
  52. #define OMAP_UHH_HOSTCONFIG_INCR4_BURST_EN (1 << 2)
  53. #define OMAP_UHH_HOSTCONFIG_INCR8_BURST_EN (1 << 3)
  54. #define OMAP_UHH_HOSTCONFIG_INCR16_BURST_EN (1 << 4)
  55. #define OMAP_UHH_HOSTCONFIG_INCRX_ALIGN_EN (1 << 5)
  56. #define OMAP_UHH_HOSTCONFIG_P1_CONNECT_STATUS (1 << 8)
  57. #define OMAP_UHH_HOSTCONFIG_P2_CONNECT_STATUS (1 << 9)
  58. #define OMAP_UHH_HOSTCONFIG_P3_CONNECT_STATUS (1 << 10)
  59. #define OMAP4_UHH_HOSTCONFIG_APP_START_CLK (1 << 31)
  60. /* OMAP4-specific defines */
  61. #define OMAP4_UHH_SYSCONFIG_IDLEMODE_CLEAR (3 << 2)
  62. #define OMAP4_UHH_SYSCONFIG_NOIDLE (1 << 2)
  63. #define OMAP4_UHH_SYSCONFIG_STDBYMODE_CLEAR (3 << 4)
  64. #define OMAP4_UHH_SYSCONFIG_NOSTDBY (1 << 4)
  65. #define OMAP4_UHH_SYSCONFIG_SOFTRESET (1 << 0)
  66. #define OMAP4_P1_MODE_CLEAR (3 << 16)
  67. #define OMAP4_P1_MODE_TLL (1 << 16)
  68. #define OMAP4_P1_MODE_HSIC (3 << 16)
  69. #define OMAP4_P2_MODE_CLEAR (3 << 18)
  70. #define OMAP4_P2_MODE_TLL (1 << 18)
  71. #define OMAP4_P2_MODE_HSIC (3 << 18)
  72. #define OMAP_UHH_DEBUG_CSR (0x44)
  73. /* Values of UHH_REVISION - Note: these are not given in the TRM */
  74. #define OMAP_USBHS_REV1 0x00000010 /* OMAP3 */
  75. #define OMAP_USBHS_REV2 0x50700100 /* OMAP4 */
  76. #define is_omap_usbhs_rev1(x) (x->usbhs_rev == OMAP_USBHS_REV1)
  77. #define is_omap_usbhs_rev2(x) (x->usbhs_rev == OMAP_USBHS_REV2)
  78. #define is_ehci_phy_mode(x) (x == OMAP_EHCI_PORT_MODE_PHY)
  79. #define is_ehci_tll_mode(x) (x == OMAP_EHCI_PORT_MODE_TLL)
  80. #define is_ehci_hsic_mode(x) (x == OMAP_EHCI_PORT_MODE_HSIC)
  81. struct usbhs_hcd_omap {
  82. struct clk *xclk60mhsp1_ck;
  83. struct clk *xclk60mhsp2_ck;
  84. struct clk *utmi_p1_fck;
  85. struct clk *usbhost_p1_fck;
  86. struct clk *utmi_p2_fck;
  87. struct clk *usbhost_p2_fck;
  88. struct clk *init_60m_fclk;
  89. struct clk *ehci_logic_fck;
  90. void __iomem *uhh_base;
  91. struct usbhs_omap_platform_data platdata;
  92. u32 usbhs_rev;
  93. spinlock_t lock;
  94. };
  95. /*-------------------------------------------------------------------------*/
  96. const char usbhs_driver_name[] = USBHS_DRIVER_NAME;
  97. static u64 usbhs_dmamask = DMA_BIT_MASK(32);
  98. /*-------------------------------------------------------------------------*/
  99. static inline void usbhs_write(void __iomem *base, u32 reg, u32 val)
  100. {
  101. __raw_writel(val, base + reg);
  102. }
  103. static inline u32 usbhs_read(void __iomem *base, u32 reg)
  104. {
  105. return __raw_readl(base + reg);
  106. }
  107. static inline void usbhs_writeb(void __iomem *base, u8 reg, u8 val)
  108. {
  109. __raw_writeb(val, base + reg);
  110. }
  111. static inline u8 usbhs_readb(void __iomem *base, u8 reg)
  112. {
  113. return __raw_readb(base + reg);
  114. }
  115. /*-------------------------------------------------------------------------*/
  116. static struct platform_device *omap_usbhs_alloc_child(const char *name,
  117. struct resource *res, int num_resources, void *pdata,
  118. size_t pdata_size, struct device *dev)
  119. {
  120. struct platform_device *child;
  121. int ret;
  122. child = platform_device_alloc(name, 0);
  123. if (!child) {
  124. dev_err(dev, "platform_device_alloc %s failed\n", name);
  125. goto err_end;
  126. }
  127. ret = platform_device_add_resources(child, res, num_resources);
  128. if (ret) {
  129. dev_err(dev, "platform_device_add_resources failed\n");
  130. goto err_alloc;
  131. }
  132. ret = platform_device_add_data(child, pdata, pdata_size);
  133. if (ret) {
  134. dev_err(dev, "platform_device_add_data failed\n");
  135. goto err_alloc;
  136. }
  137. child->dev.dma_mask = &usbhs_dmamask;
  138. dma_set_coherent_mask(&child->dev, DMA_BIT_MASK(32));
  139. child->dev.parent = dev;
  140. ret = platform_device_add(child);
  141. if (ret) {
  142. dev_err(dev, "platform_device_add failed\n");
  143. goto err_alloc;
  144. }
  145. return child;
  146. err_alloc:
  147. platform_device_put(child);
  148. err_end:
  149. return NULL;
  150. }
  151. static int omap_usbhs_alloc_children(struct platform_device *pdev)
  152. {
  153. struct device *dev = &pdev->dev;
  154. struct usbhs_hcd_omap *omap;
  155. struct ehci_hcd_omap_platform_data *ehci_data;
  156. struct ohci_hcd_omap_platform_data *ohci_data;
  157. struct platform_device *ehci;
  158. struct platform_device *ohci;
  159. struct resource *res;
  160. struct resource resources[2];
  161. int ret;
  162. omap = platform_get_drvdata(pdev);
  163. ehci_data = omap->platdata.ehci_data;
  164. ohci_data = omap->platdata.ohci_data;
  165. res = platform_get_resource_byname(pdev, IORESOURCE_MEM, "ehci");
  166. if (!res) {
  167. dev_err(dev, "EHCI get resource IORESOURCE_MEM failed\n");
  168. ret = -ENODEV;
  169. goto err_end;
  170. }
  171. resources[0] = *res;
  172. res = platform_get_resource_byname(pdev, IORESOURCE_IRQ, "ehci-irq");
  173. if (!res) {
  174. dev_err(dev, " EHCI get resource IORESOURCE_IRQ failed\n");
  175. ret = -ENODEV;
  176. goto err_end;
  177. }
  178. resources[1] = *res;
  179. ehci = omap_usbhs_alloc_child(OMAP_EHCI_DEVICE, resources, 2, ehci_data,
  180. sizeof(*ehci_data), dev);
  181. if (!ehci) {
  182. dev_err(dev, "omap_usbhs_alloc_child failed\n");
  183. ret = -ENOMEM;
  184. goto err_end;
  185. }
  186. res = platform_get_resource_byname(pdev, IORESOURCE_MEM, "ohci");
  187. if (!res) {
  188. dev_err(dev, "OHCI get resource IORESOURCE_MEM failed\n");
  189. ret = -ENODEV;
  190. goto err_ehci;
  191. }
  192. resources[0] = *res;
  193. res = platform_get_resource_byname(pdev, IORESOURCE_IRQ, "ohci-irq");
  194. if (!res) {
  195. dev_err(dev, "OHCI get resource IORESOURCE_IRQ failed\n");
  196. ret = -ENODEV;
  197. goto err_ehci;
  198. }
  199. resources[1] = *res;
  200. ohci = omap_usbhs_alloc_child(OMAP_OHCI_DEVICE, resources, 2, ohci_data,
  201. sizeof(*ohci_data), dev);
  202. if (!ohci) {
  203. dev_err(dev, "omap_usbhs_alloc_child failed\n");
  204. ret = -ENOMEM;
  205. goto err_ehci;
  206. }
  207. return 0;
  208. err_ehci:
  209. platform_device_unregister(ehci);
  210. err_end:
  211. return ret;
  212. }
  213. static bool is_ohci_port(enum usbhs_omap_port_mode pmode)
  214. {
  215. switch (pmode) {
  216. case OMAP_OHCI_PORT_MODE_PHY_6PIN_DATSE0:
  217. case OMAP_OHCI_PORT_MODE_PHY_6PIN_DPDM:
  218. case OMAP_OHCI_PORT_MODE_PHY_3PIN_DATSE0:
  219. case OMAP_OHCI_PORT_MODE_PHY_4PIN_DPDM:
  220. case OMAP_OHCI_PORT_MODE_TLL_6PIN_DATSE0:
  221. case OMAP_OHCI_PORT_MODE_TLL_6PIN_DPDM:
  222. case OMAP_OHCI_PORT_MODE_TLL_3PIN_DATSE0:
  223. case OMAP_OHCI_PORT_MODE_TLL_4PIN_DPDM:
  224. case OMAP_OHCI_PORT_MODE_TLL_2PIN_DATSE0:
  225. case OMAP_OHCI_PORT_MODE_TLL_2PIN_DPDM:
  226. return true;
  227. default:
  228. return false;
  229. }
  230. }
  231. static int usbhs_runtime_resume(struct device *dev)
  232. {
  233. struct usbhs_hcd_omap *omap = dev_get_drvdata(dev);
  234. struct usbhs_omap_platform_data *pdata = &omap->platdata;
  235. unsigned long flags;
  236. dev_dbg(dev, "usbhs_runtime_resume\n");
  237. if (!pdata) {
  238. dev_dbg(dev, "missing platform_data\n");
  239. return -ENODEV;
  240. }
  241. omap_tll_enable();
  242. spin_lock_irqsave(&omap->lock, flags);
  243. if (omap->ehci_logic_fck && !IS_ERR(omap->ehci_logic_fck))
  244. clk_enable(omap->ehci_logic_fck);
  245. if (is_ehci_tll_mode(pdata->port_mode[0]))
  246. clk_enable(omap->usbhost_p1_fck);
  247. if (is_ehci_tll_mode(pdata->port_mode[1]))
  248. clk_enable(omap->usbhost_p2_fck);
  249. clk_enable(omap->utmi_p1_fck);
  250. clk_enable(omap->utmi_p2_fck);
  251. spin_unlock_irqrestore(&omap->lock, flags);
  252. return 0;
  253. }
  254. static int usbhs_runtime_suspend(struct device *dev)
  255. {
  256. struct usbhs_hcd_omap *omap = dev_get_drvdata(dev);
  257. struct usbhs_omap_platform_data *pdata = &omap->platdata;
  258. unsigned long flags;
  259. dev_dbg(dev, "usbhs_runtime_suspend\n");
  260. if (!pdata) {
  261. dev_dbg(dev, "missing platform_data\n");
  262. return -ENODEV;
  263. }
  264. spin_lock_irqsave(&omap->lock, flags);
  265. if (is_ehci_tll_mode(pdata->port_mode[0]))
  266. clk_disable(omap->usbhost_p1_fck);
  267. if (is_ehci_tll_mode(pdata->port_mode[1]))
  268. clk_disable(omap->usbhost_p2_fck);
  269. clk_disable(omap->utmi_p2_fck);
  270. clk_disable(omap->utmi_p1_fck);
  271. if (omap->ehci_logic_fck && !IS_ERR(omap->ehci_logic_fck))
  272. clk_disable(omap->ehci_logic_fck);
  273. spin_unlock_irqrestore(&omap->lock, flags);
  274. omap_tll_disable();
  275. return 0;
  276. }
  277. static void omap_usbhs_init(struct device *dev)
  278. {
  279. struct usbhs_hcd_omap *omap = dev_get_drvdata(dev);
  280. struct usbhs_omap_platform_data *pdata = &omap->platdata;
  281. unsigned long flags;
  282. unsigned reg;
  283. dev_dbg(dev, "starting TI HSUSB Controller\n");
  284. if (pdata->ehci_data->phy_reset) {
  285. if (gpio_is_valid(pdata->ehci_data->reset_gpio_port[0]))
  286. gpio_request_one(pdata->ehci_data->reset_gpio_port[0],
  287. GPIOF_OUT_INIT_LOW, "USB1 PHY reset");
  288. if (gpio_is_valid(pdata->ehci_data->reset_gpio_port[1]))
  289. gpio_request_one(pdata->ehci_data->reset_gpio_port[1],
  290. GPIOF_OUT_INIT_LOW, "USB2 PHY reset");
  291. /* Hold the PHY in RESET for enough time till DIR is high */
  292. udelay(10);
  293. }
  294. pm_runtime_get_sync(dev);
  295. spin_lock_irqsave(&omap->lock, flags);
  296. omap->usbhs_rev = usbhs_read(omap->uhh_base, OMAP_UHH_REVISION);
  297. dev_dbg(dev, "OMAP UHH_REVISION 0x%x\n", omap->usbhs_rev);
  298. reg = usbhs_read(omap->uhh_base, OMAP_UHH_HOSTCONFIG);
  299. /* setup ULPI bypass and burst configurations */
  300. reg |= (OMAP_UHH_HOSTCONFIG_INCR4_BURST_EN
  301. | OMAP_UHH_HOSTCONFIG_INCR8_BURST_EN
  302. | OMAP_UHH_HOSTCONFIG_INCR16_BURST_EN);
  303. reg |= OMAP4_UHH_HOSTCONFIG_APP_START_CLK;
  304. reg &= ~OMAP_UHH_HOSTCONFIG_INCRX_ALIGN_EN;
  305. if (is_omap_usbhs_rev1(omap)) {
  306. if (pdata->port_mode[0] == OMAP_USBHS_PORT_MODE_UNUSED)
  307. reg &= ~OMAP_UHH_HOSTCONFIG_P1_CONNECT_STATUS;
  308. if (pdata->port_mode[1] == OMAP_USBHS_PORT_MODE_UNUSED)
  309. reg &= ~OMAP_UHH_HOSTCONFIG_P2_CONNECT_STATUS;
  310. if (pdata->port_mode[2] == OMAP_USBHS_PORT_MODE_UNUSED)
  311. reg &= ~OMAP_UHH_HOSTCONFIG_P3_CONNECT_STATUS;
  312. /* Bypass the TLL module for PHY mode operation */
  313. if (cpu_is_omap3430() && (omap_rev() <= OMAP3430_REV_ES2_1)) {
  314. dev_dbg(dev, "OMAP3 ES version <= ES2.1\n");
  315. if (is_ehci_phy_mode(pdata->port_mode[0]) ||
  316. is_ehci_phy_mode(pdata->port_mode[1]) ||
  317. is_ehci_phy_mode(pdata->port_mode[2]))
  318. reg &= ~OMAP_UHH_HOSTCONFIG_ULPI_BYPASS;
  319. else
  320. reg |= OMAP_UHH_HOSTCONFIG_ULPI_BYPASS;
  321. } else {
  322. dev_dbg(dev, "OMAP3 ES version > ES2.1\n");
  323. if (is_ehci_phy_mode(pdata->port_mode[0]))
  324. reg &= ~OMAP_UHH_HOSTCONFIG_ULPI_P1_BYPASS;
  325. else
  326. reg |= OMAP_UHH_HOSTCONFIG_ULPI_P1_BYPASS;
  327. if (is_ehci_phy_mode(pdata->port_mode[1]))
  328. reg &= ~OMAP_UHH_HOSTCONFIG_ULPI_P2_BYPASS;
  329. else
  330. reg |= OMAP_UHH_HOSTCONFIG_ULPI_P2_BYPASS;
  331. if (is_ehci_phy_mode(pdata->port_mode[2]))
  332. reg &= ~OMAP_UHH_HOSTCONFIG_ULPI_P3_BYPASS;
  333. else
  334. reg |= OMAP_UHH_HOSTCONFIG_ULPI_P3_BYPASS;
  335. }
  336. } else if (is_omap_usbhs_rev2(omap)) {
  337. /* Clear port mode fields for PHY mode*/
  338. reg &= ~OMAP4_P1_MODE_CLEAR;
  339. reg &= ~OMAP4_P2_MODE_CLEAR;
  340. if (is_ehci_tll_mode(pdata->port_mode[0]) ||
  341. (is_ohci_port(pdata->port_mode[0])))
  342. reg |= OMAP4_P1_MODE_TLL;
  343. else if (is_ehci_hsic_mode(pdata->port_mode[0]))
  344. reg |= OMAP4_P1_MODE_HSIC;
  345. if (is_ehci_tll_mode(pdata->port_mode[1]) ||
  346. (is_ohci_port(pdata->port_mode[1])))
  347. reg |= OMAP4_P2_MODE_TLL;
  348. else if (is_ehci_hsic_mode(pdata->port_mode[1]))
  349. reg |= OMAP4_P2_MODE_HSIC;
  350. }
  351. usbhs_write(omap->uhh_base, OMAP_UHH_HOSTCONFIG, reg);
  352. dev_dbg(dev, "UHH setup done, uhh_hostconfig=%x\n", reg);
  353. spin_unlock_irqrestore(&omap->lock, flags);
  354. pm_runtime_put_sync(dev);
  355. if (pdata->ehci_data->phy_reset) {
  356. /* Hold the PHY in RESET for enough time till
  357. * PHY is settled and ready
  358. */
  359. udelay(10);
  360. if (gpio_is_valid(pdata->ehci_data->reset_gpio_port[0]))
  361. gpio_set_value_cansleep
  362. (pdata->ehci_data->reset_gpio_port[0], 1);
  363. if (gpio_is_valid(pdata->ehci_data->reset_gpio_port[1]))
  364. gpio_set_value_cansleep
  365. (pdata->ehci_data->reset_gpio_port[1], 1);
  366. }
  367. }
  368. static void omap_usbhs_deinit(struct device *dev)
  369. {
  370. struct usbhs_hcd_omap *omap = dev_get_drvdata(dev);
  371. struct usbhs_omap_platform_data *pdata = &omap->platdata;
  372. if (pdata->ehci_data->phy_reset) {
  373. if (gpio_is_valid(pdata->ehci_data->reset_gpio_port[0]))
  374. gpio_free(pdata->ehci_data->reset_gpio_port[0]);
  375. if (gpio_is_valid(pdata->ehci_data->reset_gpio_port[1]))
  376. gpio_free(pdata->ehci_data->reset_gpio_port[1]);
  377. }
  378. }
  379. /**
  380. * usbhs_omap_probe - initialize TI-based HCDs
  381. *
  382. * Allocates basic resources for this USB host controller.
  383. */
  384. static int __devinit usbhs_omap_probe(struct platform_device *pdev)
  385. {
  386. struct device *dev = &pdev->dev;
  387. struct usbhs_omap_platform_data *pdata = dev->platform_data;
  388. struct usbhs_hcd_omap *omap;
  389. struct resource *res;
  390. int ret = 0;
  391. int i;
  392. if (!pdata) {
  393. dev_err(dev, "Missing platform data\n");
  394. ret = -ENOMEM;
  395. goto end_probe;
  396. }
  397. omap = kzalloc(sizeof(*omap), GFP_KERNEL);
  398. if (!omap) {
  399. dev_err(dev, "Memory allocation failed\n");
  400. ret = -ENOMEM;
  401. goto end_probe;
  402. }
  403. spin_lock_init(&omap->lock);
  404. for (i = 0; i < OMAP3_HS_USB_PORTS; i++)
  405. omap->platdata.port_mode[i] = pdata->port_mode[i];
  406. omap->platdata.ehci_data = pdata->ehci_data;
  407. omap->platdata.ohci_data = pdata->ohci_data;
  408. pm_runtime_enable(dev);
  409. for (i = 0; i < OMAP3_HS_USB_PORTS; i++)
  410. if (is_ehci_phy_mode(i) || is_ehci_tll_mode(i) ||
  411. is_ehci_hsic_mode(i)) {
  412. omap->ehci_logic_fck = clk_get(dev, "ehci_logic_fck");
  413. if (IS_ERR(omap->ehci_logic_fck)) {
  414. ret = PTR_ERR(omap->ehci_logic_fck);
  415. dev_warn(dev, "ehci_logic_fck failed:%d\n",
  416. ret);
  417. }
  418. break;
  419. }
  420. omap->utmi_p1_fck = clk_get(dev, "utmi_p1_gfclk");
  421. if (IS_ERR(omap->utmi_p1_fck)) {
  422. ret = PTR_ERR(omap->utmi_p1_fck);
  423. dev_err(dev, "utmi_p1_gfclk failed error:%d\n", ret);
  424. goto err_end;
  425. }
  426. omap->xclk60mhsp1_ck = clk_get(dev, "xclk60mhsp1_ck");
  427. if (IS_ERR(omap->xclk60mhsp1_ck)) {
  428. ret = PTR_ERR(omap->xclk60mhsp1_ck);
  429. dev_err(dev, "xclk60mhsp1_ck failed error:%d\n", ret);
  430. goto err_utmi_p1_fck;
  431. }
  432. omap->utmi_p2_fck = clk_get(dev, "utmi_p2_gfclk");
  433. if (IS_ERR(omap->utmi_p2_fck)) {
  434. ret = PTR_ERR(omap->utmi_p2_fck);
  435. dev_err(dev, "utmi_p2_gfclk failed error:%d\n", ret);
  436. goto err_xclk60mhsp1_ck;
  437. }
  438. omap->xclk60mhsp2_ck = clk_get(dev, "xclk60mhsp2_ck");
  439. if (IS_ERR(omap->xclk60mhsp2_ck)) {
  440. ret = PTR_ERR(omap->xclk60mhsp2_ck);
  441. dev_err(dev, "xclk60mhsp2_ck failed error:%d\n", ret);
  442. goto err_utmi_p2_fck;
  443. }
  444. omap->usbhost_p1_fck = clk_get(dev, "usb_host_hs_utmi_p1_clk");
  445. if (IS_ERR(omap->usbhost_p1_fck)) {
  446. ret = PTR_ERR(omap->usbhost_p1_fck);
  447. dev_err(dev, "usbhost_p1_fck failed error:%d\n", ret);
  448. goto err_xclk60mhsp2_ck;
  449. }
  450. omap->usbhost_p2_fck = clk_get(dev, "usb_host_hs_utmi_p2_clk");
  451. if (IS_ERR(omap->usbhost_p2_fck)) {
  452. ret = PTR_ERR(omap->usbhost_p2_fck);
  453. dev_err(dev, "usbhost_p2_fck failed error:%d\n", ret);
  454. goto err_usbhost_p1_fck;
  455. }
  456. omap->init_60m_fclk = clk_get(dev, "init_60m_fclk");
  457. if (IS_ERR(omap->init_60m_fclk)) {
  458. ret = PTR_ERR(omap->init_60m_fclk);
  459. dev_err(dev, "init_60m_fclk failed error:%d\n", ret);
  460. goto err_usbhost_p2_fck;
  461. }
  462. if (is_ehci_phy_mode(pdata->port_mode[0])) {
  463. /* for OMAP3 , the clk set paretn fails */
  464. ret = clk_set_parent(omap->utmi_p1_fck,
  465. omap->xclk60mhsp1_ck);
  466. if (ret != 0)
  467. dev_err(dev, "xclk60mhsp1_ck set parent"
  468. "failed error:%d\n", ret);
  469. } else if (is_ehci_tll_mode(pdata->port_mode[0])) {
  470. ret = clk_set_parent(omap->utmi_p1_fck,
  471. omap->init_60m_fclk);
  472. if (ret != 0)
  473. dev_err(dev, "init_60m_fclk set parent"
  474. "failed error:%d\n", ret);
  475. }
  476. if (is_ehci_phy_mode(pdata->port_mode[1])) {
  477. ret = clk_set_parent(omap->utmi_p2_fck,
  478. omap->xclk60mhsp2_ck);
  479. if (ret != 0)
  480. dev_err(dev, "xclk60mhsp2_ck set parent"
  481. "failed error:%d\n", ret);
  482. } else if (is_ehci_tll_mode(pdata->port_mode[1])) {
  483. ret = clk_set_parent(omap->utmi_p2_fck,
  484. omap->init_60m_fclk);
  485. if (ret != 0)
  486. dev_err(dev, "init_60m_fclk set parent"
  487. "failed error:%d\n", ret);
  488. }
  489. res = platform_get_resource_byname(pdev, IORESOURCE_MEM, "uhh");
  490. if (!res) {
  491. dev_err(dev, "UHH EHCI get resource failed\n");
  492. ret = -ENODEV;
  493. goto err_init_60m_fclk;
  494. }
  495. omap->uhh_base = ioremap(res->start, resource_size(res));
  496. if (!omap->uhh_base) {
  497. dev_err(dev, "UHH ioremap failed\n");
  498. ret = -ENOMEM;
  499. goto err_init_60m_fclk;
  500. }
  501. platform_set_drvdata(pdev, omap);
  502. omap_usbhs_init(dev);
  503. ret = omap_usbhs_alloc_children(pdev);
  504. if (ret) {
  505. dev_err(dev, "omap_usbhs_alloc_children failed\n");
  506. goto err_alloc;
  507. }
  508. goto end_probe;
  509. err_alloc:
  510. omap_usbhs_deinit(&pdev->dev);
  511. iounmap(omap->uhh_base);
  512. err_init_60m_fclk:
  513. clk_put(omap->init_60m_fclk);
  514. err_usbhost_p2_fck:
  515. clk_put(omap->usbhost_p2_fck);
  516. err_usbhost_p1_fck:
  517. clk_put(omap->usbhost_p1_fck);
  518. err_xclk60mhsp2_ck:
  519. clk_put(omap->xclk60mhsp2_ck);
  520. err_utmi_p2_fck:
  521. clk_put(omap->utmi_p2_fck);
  522. err_xclk60mhsp1_ck:
  523. clk_put(omap->xclk60mhsp1_ck);
  524. err_utmi_p1_fck:
  525. clk_put(omap->utmi_p1_fck);
  526. err_end:
  527. clk_put(omap->ehci_logic_fck);
  528. pm_runtime_disable(dev);
  529. kfree(omap);
  530. end_probe:
  531. return ret;
  532. }
  533. /**
  534. * usbhs_omap_remove - shutdown processing for UHH & TLL HCDs
  535. * @pdev: USB Host Controller being removed
  536. *
  537. * Reverses the effect of usbhs_omap_probe().
  538. */
  539. static int __devexit usbhs_omap_remove(struct platform_device *pdev)
  540. {
  541. struct usbhs_hcd_omap *omap = platform_get_drvdata(pdev);
  542. omap_usbhs_deinit(&pdev->dev);
  543. iounmap(omap->uhh_base);
  544. clk_put(omap->init_60m_fclk);
  545. clk_put(omap->usbhost_p2_fck);
  546. clk_put(omap->usbhost_p1_fck);
  547. clk_put(omap->xclk60mhsp2_ck);
  548. clk_put(omap->utmi_p2_fck);
  549. clk_put(omap->xclk60mhsp1_ck);
  550. clk_put(omap->utmi_p1_fck);
  551. clk_put(omap->ehci_logic_fck);
  552. pm_runtime_disable(&pdev->dev);
  553. kfree(omap);
  554. return 0;
  555. }
  556. static const struct dev_pm_ops usbhsomap_dev_pm_ops = {
  557. .runtime_suspend = usbhs_runtime_suspend,
  558. .runtime_resume = usbhs_runtime_resume,
  559. };
  560. static struct platform_driver usbhs_omap_driver = {
  561. .driver = {
  562. .name = (char *)usbhs_driver_name,
  563. .owner = THIS_MODULE,
  564. .pm = &usbhsomap_dev_pm_ops,
  565. },
  566. .remove = __exit_p(usbhs_omap_remove),
  567. };
  568. MODULE_AUTHOR("Keshava Munegowda <keshava_mgowda@ti.com>");
  569. MODULE_ALIAS("platform:" USBHS_DRIVER_NAME);
  570. MODULE_LICENSE("GPL v2");
  571. MODULE_DESCRIPTION("usb host common core driver for omap EHCI and OHCI");
  572. static int __init omap_usbhs_drvinit(void)
  573. {
  574. return platform_driver_probe(&usbhs_omap_driver, usbhs_omap_probe);
  575. }
  576. /*
  577. * init before ehci and ohci drivers;
  578. * The usbhs core driver should be initialized much before
  579. * the omap ehci and ohci probe functions are called.
  580. * This usbhs core driver should be initialized after
  581. * usb tll driver
  582. */
  583. fs_initcall_sync(omap_usbhs_drvinit);
  584. static void __exit omap_usbhs_drvexit(void)
  585. {
  586. platform_driver_unregister(&usbhs_omap_driver);
  587. }
  588. module_exit(omap_usbhs_drvexit);