omap-usb-host.c 19 KB

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