omap-usb-host.c 19 KB

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