omap-usb-host.c 21 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803
  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. int nports;
  82. struct clk **utmi_clk;
  83. struct clk **hsic60m_clk;
  84. struct clk **hsic480m_clk;
  85. struct clk *xclk60mhsp1_ck;
  86. struct clk *xclk60mhsp2_ck;
  87. struct clk *utmi_p1_gfclk;
  88. struct clk *utmi_p2_gfclk;
  89. struct clk *init_60m_fclk;
  90. struct clk *ehci_logic_fck;
  91. void __iomem *uhh_base;
  92. struct usbhs_omap_platform_data *pdata;
  93. u32 usbhs_rev;
  94. spinlock_t lock;
  95. };
  96. /*-------------------------------------------------------------------------*/
  97. const char usbhs_driver_name[] = USBHS_DRIVER_NAME;
  98. static u64 usbhs_dmamask = DMA_BIT_MASK(32);
  99. /*-------------------------------------------------------------------------*/
  100. static inline void usbhs_write(void __iomem *base, u32 reg, u32 val)
  101. {
  102. __raw_writel(val, base + reg);
  103. }
  104. static inline u32 usbhs_read(void __iomem *base, u32 reg)
  105. {
  106. return __raw_readl(base + reg);
  107. }
  108. static inline void usbhs_writeb(void __iomem *base, u8 reg, u8 val)
  109. {
  110. __raw_writeb(val, base + reg);
  111. }
  112. static inline u8 usbhs_readb(void __iomem *base, u8 reg)
  113. {
  114. return __raw_readb(base + reg);
  115. }
  116. /*-------------------------------------------------------------------------*/
  117. static struct platform_device *omap_usbhs_alloc_child(const char *name,
  118. struct resource *res, int num_resources, void *pdata,
  119. size_t pdata_size, struct device *dev)
  120. {
  121. struct platform_device *child;
  122. int ret;
  123. child = platform_device_alloc(name, 0);
  124. if (!child) {
  125. dev_err(dev, "platform_device_alloc %s failed\n", name);
  126. goto err_end;
  127. }
  128. ret = platform_device_add_resources(child, res, num_resources);
  129. if (ret) {
  130. dev_err(dev, "platform_device_add_resources failed\n");
  131. goto err_alloc;
  132. }
  133. ret = platform_device_add_data(child, pdata, pdata_size);
  134. if (ret) {
  135. dev_err(dev, "platform_device_add_data failed\n");
  136. goto err_alloc;
  137. }
  138. child->dev.dma_mask = &usbhs_dmamask;
  139. dma_set_coherent_mask(&child->dev, DMA_BIT_MASK(32));
  140. child->dev.parent = dev;
  141. ret = platform_device_add(child);
  142. if (ret) {
  143. dev_err(dev, "platform_device_add failed\n");
  144. goto err_alloc;
  145. }
  146. return child;
  147. err_alloc:
  148. platform_device_put(child);
  149. err_end:
  150. return NULL;
  151. }
  152. static int omap_usbhs_alloc_children(struct platform_device *pdev)
  153. {
  154. struct device *dev = &pdev->dev;
  155. struct usbhs_omap_platform_data *pdata = dev->platform_data;
  156. struct platform_device *ehci;
  157. struct platform_device *ohci;
  158. struct resource *res;
  159. struct resource resources[2];
  160. int ret;
  161. res = platform_get_resource_byname(pdev, IORESOURCE_MEM, "ehci");
  162. if (!res) {
  163. dev_err(dev, "EHCI get resource IORESOURCE_MEM failed\n");
  164. ret = -ENODEV;
  165. goto err_end;
  166. }
  167. resources[0] = *res;
  168. res = platform_get_resource_byname(pdev, IORESOURCE_IRQ, "ehci-irq");
  169. if (!res) {
  170. dev_err(dev, " EHCI get resource IORESOURCE_IRQ failed\n");
  171. ret = -ENODEV;
  172. goto err_end;
  173. }
  174. resources[1] = *res;
  175. ehci = omap_usbhs_alloc_child(OMAP_EHCI_DEVICE, resources, 2, pdata,
  176. sizeof(*pdata), dev);
  177. if (!ehci) {
  178. dev_err(dev, "omap_usbhs_alloc_child failed\n");
  179. ret = -ENOMEM;
  180. goto err_end;
  181. }
  182. res = platform_get_resource_byname(pdev, IORESOURCE_MEM, "ohci");
  183. if (!res) {
  184. dev_err(dev, "OHCI get resource IORESOURCE_MEM failed\n");
  185. ret = -ENODEV;
  186. goto err_ehci;
  187. }
  188. resources[0] = *res;
  189. res = platform_get_resource_byname(pdev, IORESOURCE_IRQ, "ohci-irq");
  190. if (!res) {
  191. dev_err(dev, "OHCI get resource IORESOURCE_IRQ failed\n");
  192. ret = -ENODEV;
  193. goto err_ehci;
  194. }
  195. resources[1] = *res;
  196. ohci = omap_usbhs_alloc_child(OMAP_OHCI_DEVICE, resources, 2, pdata,
  197. sizeof(*pdata), dev);
  198. if (!ohci) {
  199. dev_err(dev, "omap_usbhs_alloc_child failed\n");
  200. ret = -ENOMEM;
  201. goto err_ehci;
  202. }
  203. return 0;
  204. err_ehci:
  205. platform_device_unregister(ehci);
  206. err_end:
  207. return ret;
  208. }
  209. static bool is_ohci_port(enum usbhs_omap_port_mode pmode)
  210. {
  211. switch (pmode) {
  212. case OMAP_OHCI_PORT_MODE_PHY_6PIN_DATSE0:
  213. case OMAP_OHCI_PORT_MODE_PHY_6PIN_DPDM:
  214. case OMAP_OHCI_PORT_MODE_PHY_3PIN_DATSE0:
  215. case OMAP_OHCI_PORT_MODE_PHY_4PIN_DPDM:
  216. case OMAP_OHCI_PORT_MODE_TLL_6PIN_DATSE0:
  217. case OMAP_OHCI_PORT_MODE_TLL_6PIN_DPDM:
  218. case OMAP_OHCI_PORT_MODE_TLL_3PIN_DATSE0:
  219. case OMAP_OHCI_PORT_MODE_TLL_4PIN_DPDM:
  220. case OMAP_OHCI_PORT_MODE_TLL_2PIN_DATSE0:
  221. case OMAP_OHCI_PORT_MODE_TLL_2PIN_DPDM:
  222. return true;
  223. default:
  224. return false;
  225. }
  226. }
  227. static int usbhs_runtime_resume(struct device *dev)
  228. {
  229. struct usbhs_hcd_omap *omap = dev_get_drvdata(dev);
  230. struct usbhs_omap_platform_data *pdata = omap->pdata;
  231. unsigned long flags;
  232. int i, r;
  233. dev_dbg(dev, "usbhs_runtime_resume\n");
  234. omap_tll_enable();
  235. spin_lock_irqsave(&omap->lock, flags);
  236. if (!IS_ERR(omap->ehci_logic_fck))
  237. clk_enable(omap->ehci_logic_fck);
  238. for (i = 0; i < omap->nports; i++) {
  239. switch (pdata->port_mode[i]) {
  240. case OMAP_EHCI_PORT_MODE_HSIC:
  241. if (!IS_ERR(omap->hsic60m_clk[i])) {
  242. r = clk_enable(omap->hsic60m_clk[i]);
  243. if (r) {
  244. dev_err(dev,
  245. "Can't enable port %d hsic60m clk:%d\n",
  246. i, r);
  247. }
  248. }
  249. if (!IS_ERR(omap->hsic480m_clk[i])) {
  250. r = clk_enable(omap->hsic480m_clk[i]);
  251. if (r) {
  252. dev_err(dev,
  253. "Can't enable port %d hsic480m clk:%d\n",
  254. i, r);
  255. }
  256. }
  257. /* Fall through as HSIC mode needs utmi_clk */
  258. case OMAP_EHCI_PORT_MODE_TLL:
  259. if (!IS_ERR(omap->utmi_clk[i])) {
  260. r = clk_enable(omap->utmi_clk[i]);
  261. if (r) {
  262. dev_err(dev,
  263. "Can't enable port %d clk : %d\n",
  264. i, r);
  265. }
  266. }
  267. break;
  268. default:
  269. break;
  270. }
  271. }
  272. spin_unlock_irqrestore(&omap->lock, flags);
  273. return 0;
  274. }
  275. static int usbhs_runtime_suspend(struct device *dev)
  276. {
  277. struct usbhs_hcd_omap *omap = dev_get_drvdata(dev);
  278. struct usbhs_omap_platform_data *pdata = omap->pdata;
  279. unsigned long flags;
  280. int i;
  281. dev_dbg(dev, "usbhs_runtime_suspend\n");
  282. spin_lock_irqsave(&omap->lock, flags);
  283. for (i = 0; i < omap->nports; i++) {
  284. switch (pdata->port_mode[i]) {
  285. case OMAP_EHCI_PORT_MODE_HSIC:
  286. if (!IS_ERR(omap->hsic60m_clk[i]))
  287. clk_disable(omap->hsic60m_clk[i]);
  288. if (!IS_ERR(omap->hsic480m_clk[i]))
  289. clk_disable(omap->hsic480m_clk[i]);
  290. /* Fall through as utmi_clks were used in HSIC mode */
  291. case OMAP_EHCI_PORT_MODE_TLL:
  292. if (!IS_ERR(omap->utmi_clk[i]))
  293. clk_disable(omap->utmi_clk[i]);
  294. break;
  295. default:
  296. break;
  297. }
  298. }
  299. if (!IS_ERR(omap->ehci_logic_fck))
  300. clk_disable(omap->ehci_logic_fck);
  301. spin_unlock_irqrestore(&omap->lock, flags);
  302. omap_tll_disable();
  303. return 0;
  304. }
  305. static void omap_usbhs_init(struct device *dev)
  306. {
  307. struct usbhs_hcd_omap *omap = dev_get_drvdata(dev);
  308. struct usbhs_omap_platform_data *pdata = omap->pdata;
  309. unsigned long flags;
  310. unsigned reg;
  311. dev_dbg(dev, "starting TI HSUSB Controller\n");
  312. if (pdata->phy_reset) {
  313. if (gpio_is_valid(pdata->reset_gpio_port[0]))
  314. gpio_request_one(pdata->reset_gpio_port[0],
  315. GPIOF_OUT_INIT_LOW, "USB1 PHY reset");
  316. if (gpio_is_valid(pdata->reset_gpio_port[1]))
  317. gpio_request_one(pdata->reset_gpio_port[1],
  318. GPIOF_OUT_INIT_LOW, "USB2 PHY reset");
  319. /* Hold the PHY in RESET for enough time till DIR is high */
  320. udelay(10);
  321. }
  322. pm_runtime_get_sync(dev);
  323. spin_lock_irqsave(&omap->lock, flags);
  324. reg = usbhs_read(omap->uhh_base, OMAP_UHH_HOSTCONFIG);
  325. /* setup ULPI bypass and burst configurations */
  326. reg |= (OMAP_UHH_HOSTCONFIG_INCR4_BURST_EN
  327. | OMAP_UHH_HOSTCONFIG_INCR8_BURST_EN
  328. | OMAP_UHH_HOSTCONFIG_INCR16_BURST_EN);
  329. reg |= OMAP4_UHH_HOSTCONFIG_APP_START_CLK;
  330. reg &= ~OMAP_UHH_HOSTCONFIG_INCRX_ALIGN_EN;
  331. if (is_omap_usbhs_rev1(omap)) {
  332. if (pdata->port_mode[0] == OMAP_USBHS_PORT_MODE_UNUSED)
  333. reg &= ~OMAP_UHH_HOSTCONFIG_P1_CONNECT_STATUS;
  334. if (pdata->port_mode[1] == OMAP_USBHS_PORT_MODE_UNUSED)
  335. reg &= ~OMAP_UHH_HOSTCONFIG_P2_CONNECT_STATUS;
  336. if (pdata->port_mode[2] == OMAP_USBHS_PORT_MODE_UNUSED)
  337. reg &= ~OMAP_UHH_HOSTCONFIG_P3_CONNECT_STATUS;
  338. /* Bypass the TLL module for PHY mode operation */
  339. if (pdata->single_ulpi_bypass) {
  340. dev_dbg(dev, "OMAP3 ES version <= ES2.1\n");
  341. if (is_ehci_phy_mode(pdata->port_mode[0]) ||
  342. is_ehci_phy_mode(pdata->port_mode[1]) ||
  343. is_ehci_phy_mode(pdata->port_mode[2]))
  344. reg &= ~OMAP_UHH_HOSTCONFIG_ULPI_BYPASS;
  345. else
  346. reg |= OMAP_UHH_HOSTCONFIG_ULPI_BYPASS;
  347. } else {
  348. dev_dbg(dev, "OMAP3 ES version > ES2.1\n");
  349. if (is_ehci_phy_mode(pdata->port_mode[0]))
  350. reg &= ~OMAP_UHH_HOSTCONFIG_ULPI_P1_BYPASS;
  351. else
  352. reg |= OMAP_UHH_HOSTCONFIG_ULPI_P1_BYPASS;
  353. if (is_ehci_phy_mode(pdata->port_mode[1]))
  354. reg &= ~OMAP_UHH_HOSTCONFIG_ULPI_P2_BYPASS;
  355. else
  356. reg |= OMAP_UHH_HOSTCONFIG_ULPI_P2_BYPASS;
  357. if (is_ehci_phy_mode(pdata->port_mode[2]))
  358. reg &= ~OMAP_UHH_HOSTCONFIG_ULPI_P3_BYPASS;
  359. else
  360. reg |= OMAP_UHH_HOSTCONFIG_ULPI_P3_BYPASS;
  361. }
  362. } else if (is_omap_usbhs_rev2(omap)) {
  363. /* Clear port mode fields for PHY mode*/
  364. reg &= ~OMAP4_P1_MODE_CLEAR;
  365. reg &= ~OMAP4_P2_MODE_CLEAR;
  366. if (is_ehci_tll_mode(pdata->port_mode[0]) ||
  367. (is_ohci_port(pdata->port_mode[0])))
  368. reg |= OMAP4_P1_MODE_TLL;
  369. else if (is_ehci_hsic_mode(pdata->port_mode[0]))
  370. reg |= OMAP4_P1_MODE_HSIC;
  371. if (is_ehci_tll_mode(pdata->port_mode[1]) ||
  372. (is_ohci_port(pdata->port_mode[1])))
  373. reg |= OMAP4_P2_MODE_TLL;
  374. else if (is_ehci_hsic_mode(pdata->port_mode[1]))
  375. reg |= OMAP4_P2_MODE_HSIC;
  376. }
  377. usbhs_write(omap->uhh_base, OMAP_UHH_HOSTCONFIG, reg);
  378. dev_dbg(dev, "UHH setup done, uhh_hostconfig=%x\n", reg);
  379. spin_unlock_irqrestore(&omap->lock, flags);
  380. pm_runtime_put_sync(dev);
  381. if (pdata->phy_reset) {
  382. /* Hold the PHY in RESET for enough time till
  383. * PHY is settled and ready
  384. */
  385. udelay(10);
  386. if (gpio_is_valid(pdata->reset_gpio_port[0]))
  387. gpio_set_value_cansleep
  388. (pdata->reset_gpio_port[0], 1);
  389. if (gpio_is_valid(pdata->reset_gpio_port[1]))
  390. gpio_set_value_cansleep
  391. (pdata->reset_gpio_port[1], 1);
  392. }
  393. }
  394. static void omap_usbhs_deinit(struct device *dev)
  395. {
  396. struct usbhs_hcd_omap *omap = dev_get_drvdata(dev);
  397. struct usbhs_omap_platform_data *pdata = omap->pdata;
  398. if (pdata->phy_reset) {
  399. if (gpio_is_valid(pdata->reset_gpio_port[0]))
  400. gpio_free(pdata->reset_gpio_port[0]);
  401. if (gpio_is_valid(pdata->reset_gpio_port[1]))
  402. gpio_free(pdata->reset_gpio_port[1]);
  403. }
  404. }
  405. /**
  406. * usbhs_omap_probe - initialize TI-based HCDs
  407. *
  408. * Allocates basic resources for this USB host controller.
  409. */
  410. static int usbhs_omap_probe(struct platform_device *pdev)
  411. {
  412. struct device *dev = &pdev->dev;
  413. struct usbhs_omap_platform_data *pdata = dev->platform_data;
  414. struct usbhs_hcd_omap *omap;
  415. struct resource *res;
  416. int ret = 0;
  417. int i;
  418. bool need_logic_fck;
  419. if (!pdata) {
  420. dev_err(dev, "Missing platform data\n");
  421. return -ENODEV;
  422. }
  423. omap = devm_kzalloc(dev, sizeof(*omap), GFP_KERNEL);
  424. if (!omap) {
  425. dev_err(dev, "Memory allocation failed\n");
  426. return -ENOMEM;
  427. }
  428. res = platform_get_resource_byname(pdev, IORESOURCE_MEM, "uhh");
  429. omap->uhh_base = devm_request_and_ioremap(dev, res);
  430. if (!omap->uhh_base) {
  431. dev_err(dev, "Resource request/ioremap failed\n");
  432. return -EADDRNOTAVAIL;
  433. }
  434. spin_lock_init(&omap->lock);
  435. omap->pdata = pdata;
  436. pm_runtime_enable(dev);
  437. platform_set_drvdata(pdev, omap);
  438. pm_runtime_get_sync(dev);
  439. omap->usbhs_rev = usbhs_read(omap->uhh_base, OMAP_UHH_REVISION);
  440. /* we need to call runtime suspend before we update omap->nports
  441. * to prevent unbalanced clk_disable()
  442. */
  443. pm_runtime_put_sync(dev);
  444. /*
  445. * If platform data contains nports then use that
  446. * else make out number of ports from USBHS revision
  447. */
  448. if (pdata->nports) {
  449. omap->nports = pdata->nports;
  450. } else {
  451. switch (omap->usbhs_rev) {
  452. case OMAP_USBHS_REV1:
  453. omap->nports = 3;
  454. break;
  455. case OMAP_USBHS_REV2:
  456. omap->nports = 2;
  457. break;
  458. default:
  459. omap->nports = OMAP3_HS_USB_PORTS;
  460. dev_dbg(dev,
  461. "USB HOST Rev:0x%d not recognized, assuming %d ports\n",
  462. omap->usbhs_rev, omap->nports);
  463. break;
  464. }
  465. }
  466. i = sizeof(struct clk *) * omap->nports;
  467. omap->utmi_clk = devm_kzalloc(dev, i, GFP_KERNEL);
  468. omap->hsic480m_clk = devm_kzalloc(dev, i, GFP_KERNEL);
  469. omap->hsic60m_clk = devm_kzalloc(dev, i, GFP_KERNEL);
  470. if (!omap->utmi_clk || !omap->hsic480m_clk || !omap->hsic60m_clk) {
  471. dev_err(dev, "Memory allocation failed\n");
  472. ret = -ENOMEM;
  473. goto err_mem;
  474. }
  475. need_logic_fck = false;
  476. for (i = 0; i < omap->nports; i++) {
  477. if (is_ehci_phy_mode(i) || is_ehci_tll_mode(i) ||
  478. is_ehci_hsic_mode(i))
  479. need_logic_fck |= true;
  480. }
  481. omap->ehci_logic_fck = ERR_PTR(-EINVAL);
  482. if (need_logic_fck) {
  483. omap->ehci_logic_fck = clk_get(dev, "ehci_logic_fck");
  484. if (IS_ERR(omap->ehci_logic_fck)) {
  485. ret = PTR_ERR(omap->ehci_logic_fck);
  486. dev_dbg(dev, "ehci_logic_fck failed:%d\n", ret);
  487. }
  488. }
  489. omap->utmi_p1_gfclk = clk_get(dev, "utmi_p1_gfclk");
  490. if (IS_ERR(omap->utmi_p1_gfclk)) {
  491. ret = PTR_ERR(omap->utmi_p1_gfclk);
  492. dev_err(dev, "utmi_p1_gfclk failed error:%d\n", ret);
  493. goto err_p1_gfclk;
  494. }
  495. omap->utmi_p2_gfclk = clk_get(dev, "utmi_p2_gfclk");
  496. if (IS_ERR(omap->utmi_p2_gfclk)) {
  497. ret = PTR_ERR(omap->utmi_p2_gfclk);
  498. dev_err(dev, "utmi_p2_gfclk failed error:%d\n", ret);
  499. goto err_p2_gfclk;
  500. }
  501. omap->xclk60mhsp1_ck = clk_get(dev, "xclk60mhsp1_ck");
  502. if (IS_ERR(omap->xclk60mhsp1_ck)) {
  503. ret = PTR_ERR(omap->xclk60mhsp1_ck);
  504. dev_err(dev, "xclk60mhsp1_ck failed error:%d\n", ret);
  505. goto err_xclk60mhsp1;
  506. }
  507. omap->xclk60mhsp2_ck = clk_get(dev, "xclk60mhsp2_ck");
  508. if (IS_ERR(omap->xclk60mhsp2_ck)) {
  509. ret = PTR_ERR(omap->xclk60mhsp2_ck);
  510. dev_err(dev, "xclk60mhsp2_ck failed error:%d\n", ret);
  511. goto err_xclk60mhsp2;
  512. }
  513. omap->init_60m_fclk = clk_get(dev, "init_60m_fclk");
  514. if (IS_ERR(omap->init_60m_fclk)) {
  515. ret = PTR_ERR(omap->init_60m_fclk);
  516. dev_err(dev, "init_60m_fclk failed error:%d\n", ret);
  517. goto err_init60m;
  518. }
  519. for (i = 0; i < omap->nports; i++) {
  520. char clkname[30];
  521. /* clock names are indexed from 1*/
  522. snprintf(clkname, sizeof(clkname),
  523. "usb_host_hs_utmi_p%d_clk", i + 1);
  524. /* If a clock is not found we won't bail out as not all
  525. * platforms have all clocks and we can function without
  526. * them
  527. */
  528. omap->utmi_clk[i] = clk_get(dev, clkname);
  529. if (IS_ERR(omap->utmi_clk[i]))
  530. dev_dbg(dev, "Failed to get clock : %s : %ld\n",
  531. clkname, PTR_ERR(omap->utmi_clk[i]));
  532. snprintf(clkname, sizeof(clkname),
  533. "usb_host_hs_hsic480m_p%d_clk", i + 1);
  534. omap->hsic480m_clk[i] = clk_get(dev, clkname);
  535. if (IS_ERR(omap->hsic480m_clk[i]))
  536. dev_dbg(dev, "Failed to get clock : %s : %ld\n",
  537. clkname, PTR_ERR(omap->hsic480m_clk[i]));
  538. snprintf(clkname, sizeof(clkname),
  539. "usb_host_hs_hsic60m_p%d_clk", i + 1);
  540. omap->hsic60m_clk[i] = clk_get(dev, clkname);
  541. if (IS_ERR(omap->hsic60m_clk[i]))
  542. dev_dbg(dev, "Failed to get clock : %s : %ld\n",
  543. clkname, PTR_ERR(omap->hsic60m_clk[i]));
  544. }
  545. if (is_ehci_phy_mode(pdata->port_mode[0])) {
  546. /* for OMAP3 , the clk set paretn fails */
  547. ret = clk_set_parent(omap->utmi_p1_gfclk,
  548. omap->xclk60mhsp1_ck);
  549. if (ret != 0)
  550. dev_err(dev, "xclk60mhsp1_ck set parent"
  551. "failed error:%d\n", ret);
  552. } else if (is_ehci_tll_mode(pdata->port_mode[0])) {
  553. ret = clk_set_parent(omap->utmi_p1_gfclk,
  554. omap->init_60m_fclk);
  555. if (ret != 0)
  556. dev_err(dev, "init_60m_fclk set parent"
  557. "failed error:%d\n", ret);
  558. }
  559. if (is_ehci_phy_mode(pdata->port_mode[1])) {
  560. ret = clk_set_parent(omap->utmi_p2_gfclk,
  561. omap->xclk60mhsp2_ck);
  562. if (ret != 0)
  563. dev_err(dev, "xclk60mhsp2_ck set parent"
  564. "failed error:%d\n", ret);
  565. } else if (is_ehci_tll_mode(pdata->port_mode[1])) {
  566. ret = clk_set_parent(omap->utmi_p2_gfclk,
  567. omap->init_60m_fclk);
  568. if (ret != 0)
  569. dev_err(dev, "init_60m_fclk set parent"
  570. "failed error:%d\n", ret);
  571. }
  572. omap_usbhs_init(dev);
  573. ret = omap_usbhs_alloc_children(pdev);
  574. if (ret) {
  575. dev_err(dev, "omap_usbhs_alloc_children failed\n");
  576. goto err_alloc;
  577. }
  578. return 0;
  579. err_alloc:
  580. omap_usbhs_deinit(&pdev->dev);
  581. for (i = 0; i < omap->nports; i++) {
  582. if (!IS_ERR(omap->utmi_clk[i]))
  583. clk_put(omap->utmi_clk[i]);
  584. if (!IS_ERR(omap->hsic60m_clk[i]))
  585. clk_put(omap->hsic60m_clk[i]);
  586. if (!IS_ERR(omap->hsic480m_clk[i]))
  587. clk_put(omap->hsic480m_clk[i]);
  588. }
  589. clk_put(omap->init_60m_fclk);
  590. err_init60m:
  591. clk_put(omap->xclk60mhsp2_ck);
  592. err_xclk60mhsp2:
  593. clk_put(omap->xclk60mhsp1_ck);
  594. err_xclk60mhsp1:
  595. clk_put(omap->utmi_p2_gfclk);
  596. err_p2_gfclk:
  597. clk_put(omap->utmi_p1_gfclk);
  598. err_p1_gfclk:
  599. if (!IS_ERR(omap->ehci_logic_fck))
  600. clk_put(omap->ehci_logic_fck);
  601. err_mem:
  602. pm_runtime_disable(dev);
  603. return ret;
  604. }
  605. /**
  606. * usbhs_omap_remove - shutdown processing for UHH & TLL HCDs
  607. * @pdev: USB Host Controller being removed
  608. *
  609. * Reverses the effect of usbhs_omap_probe().
  610. */
  611. static int usbhs_omap_remove(struct platform_device *pdev)
  612. {
  613. struct usbhs_hcd_omap *omap = platform_get_drvdata(pdev);
  614. int i;
  615. omap_usbhs_deinit(&pdev->dev);
  616. for (i = 0; i < omap->nports; i++) {
  617. if (!IS_ERR(omap->utmi_clk[i]))
  618. clk_put(omap->utmi_clk[i]);
  619. if (!IS_ERR(omap->hsic60m_clk[i]))
  620. clk_put(omap->hsic60m_clk[i]);
  621. if (!IS_ERR(omap->hsic480m_clk[i]))
  622. clk_put(omap->hsic480m_clk[i]);
  623. }
  624. clk_put(omap->init_60m_fclk);
  625. clk_put(omap->utmi_p1_gfclk);
  626. clk_put(omap->utmi_p2_gfclk);
  627. clk_put(omap->xclk60mhsp2_ck);
  628. clk_put(omap->xclk60mhsp1_ck);
  629. if (!IS_ERR(omap->ehci_logic_fck))
  630. clk_put(omap->ehci_logic_fck);
  631. pm_runtime_disable(&pdev->dev);
  632. return 0;
  633. }
  634. static const struct dev_pm_ops usbhsomap_dev_pm_ops = {
  635. .runtime_suspend = usbhs_runtime_suspend,
  636. .runtime_resume = usbhs_runtime_resume,
  637. };
  638. static struct platform_driver usbhs_omap_driver = {
  639. .driver = {
  640. .name = (char *)usbhs_driver_name,
  641. .owner = THIS_MODULE,
  642. .pm = &usbhsomap_dev_pm_ops,
  643. },
  644. .remove = __exit_p(usbhs_omap_remove),
  645. };
  646. MODULE_AUTHOR("Keshava Munegowda <keshava_mgowda@ti.com>");
  647. MODULE_ALIAS("platform:" USBHS_DRIVER_NAME);
  648. MODULE_LICENSE("GPL v2");
  649. MODULE_DESCRIPTION("usb host common core driver for omap EHCI and OHCI");
  650. static int __init omap_usbhs_drvinit(void)
  651. {
  652. return platform_driver_probe(&usbhs_omap_driver, usbhs_omap_probe);
  653. }
  654. /*
  655. * init before ehci and ohci drivers;
  656. * The usbhs core driver should be initialized much before
  657. * the omap ehci and ohci probe functions are called.
  658. * This usbhs core driver should be initialized after
  659. * usb tll driver
  660. */
  661. fs_initcall_sync(omap_usbhs_drvinit);
  662. static void __exit omap_usbhs_drvexit(void)
  663. {
  664. platform_driver_unregister(&usbhs_omap_driver);
  665. }
  666. module_exit(omap_usbhs_drvexit);