omap-usb-host.c 21 KB

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