omap-usb-host.c 25 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875
  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/platform_device.h>
  25. #include <linux/clk.h>
  26. #include <linux/dma-mapping.h>
  27. #include <linux/spinlock.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. /* TLL Register Set */
  36. #define OMAP_USBTLL_REVISION (0x00)
  37. #define OMAP_USBTLL_SYSCONFIG (0x10)
  38. #define OMAP_USBTLL_SYSCONFIG_CACTIVITY (1 << 8)
  39. #define OMAP_USBTLL_SYSCONFIG_SIDLEMODE (1 << 3)
  40. #define OMAP_USBTLL_SYSCONFIG_ENAWAKEUP (1 << 2)
  41. #define OMAP_USBTLL_SYSCONFIG_SOFTRESET (1 << 1)
  42. #define OMAP_USBTLL_SYSCONFIG_AUTOIDLE (1 << 0)
  43. #define OMAP_USBTLL_SYSSTATUS (0x14)
  44. #define OMAP_USBTLL_SYSSTATUS_RESETDONE (1 << 0)
  45. #define OMAP_USBTLL_IRQSTATUS (0x18)
  46. #define OMAP_USBTLL_IRQENABLE (0x1C)
  47. #define OMAP_TLL_SHARED_CONF (0x30)
  48. #define OMAP_TLL_SHARED_CONF_USB_90D_DDR_EN (1 << 6)
  49. #define OMAP_TLL_SHARED_CONF_USB_180D_SDR_EN (1 << 5)
  50. #define OMAP_TLL_SHARED_CONF_USB_DIVRATION (1 << 2)
  51. #define OMAP_TLL_SHARED_CONF_FCLK_REQ (1 << 1)
  52. #define OMAP_TLL_SHARED_CONF_FCLK_IS_ON (1 << 0)
  53. #define OMAP_TLL_CHANNEL_CONF(num) (0x040 + 0x004 * num)
  54. #define OMAP_TLL_CHANNEL_CONF_FSLSMODE_SHIFT 24
  55. #define OMAP_TLL_CHANNEL_CONF_ULPINOBITSTUFF (1 << 11)
  56. #define OMAP_TLL_CHANNEL_CONF_ULPI_ULPIAUTOIDLE (1 << 10)
  57. #define OMAP_TLL_CHANNEL_CONF_UTMIAUTOIDLE (1 << 9)
  58. #define OMAP_TLL_CHANNEL_CONF_ULPIDDRMODE (1 << 8)
  59. #define OMAP_TLL_CHANNEL_CONF_CHANMODE_FSLS (1 << 1)
  60. #define OMAP_TLL_CHANNEL_CONF_CHANEN (1 << 0)
  61. #define OMAP_TLL_FSLSMODE_6PIN_PHY_DAT_SE0 0x0
  62. #define OMAP_TLL_FSLSMODE_6PIN_PHY_DP_DM 0x1
  63. #define OMAP_TLL_FSLSMODE_3PIN_PHY 0x2
  64. #define OMAP_TLL_FSLSMODE_4PIN_PHY 0x3
  65. #define OMAP_TLL_FSLSMODE_6PIN_TLL_DAT_SE0 0x4
  66. #define OMAP_TLL_FSLSMODE_6PIN_TLL_DP_DM 0x5
  67. #define OMAP_TLL_FSLSMODE_3PIN_TLL 0x6
  68. #define OMAP_TLL_FSLSMODE_4PIN_TLL 0x7
  69. #define OMAP_TLL_FSLSMODE_2PIN_TLL_DAT_SE0 0xA
  70. #define OMAP_TLL_FSLSMODE_2PIN_DAT_DP_DM 0xB
  71. #define OMAP_TLL_ULPI_FUNCTION_CTRL(num) (0x804 + 0x100 * num)
  72. #define OMAP_TLL_ULPI_INTERFACE_CTRL(num) (0x807 + 0x100 * num)
  73. #define OMAP_TLL_ULPI_OTG_CTRL(num) (0x80A + 0x100 * num)
  74. #define OMAP_TLL_ULPI_INT_EN_RISE(num) (0x80D + 0x100 * num)
  75. #define OMAP_TLL_ULPI_INT_EN_FALL(num) (0x810 + 0x100 * num)
  76. #define OMAP_TLL_ULPI_INT_STATUS(num) (0x813 + 0x100 * num)
  77. #define OMAP_TLL_ULPI_INT_LATCH(num) (0x814 + 0x100 * num)
  78. #define OMAP_TLL_ULPI_DEBUG(num) (0x815 + 0x100 * num)
  79. #define OMAP_TLL_ULPI_SCRATCH_REGISTER(num) (0x816 + 0x100 * num)
  80. #define OMAP_TLL_CHANNEL_COUNT 3
  81. #define OMAP_TLL_CHANNEL_1_EN_MASK (1 << 0)
  82. #define OMAP_TLL_CHANNEL_2_EN_MASK (1 << 1)
  83. #define OMAP_TLL_CHANNEL_3_EN_MASK (1 << 2)
  84. /* UHH Register Set */
  85. #define OMAP_UHH_REVISION (0x00)
  86. #define OMAP_UHH_SYSCONFIG (0x10)
  87. #define OMAP_UHH_SYSCONFIG_MIDLEMODE (1 << 12)
  88. #define OMAP_UHH_SYSCONFIG_CACTIVITY (1 << 8)
  89. #define OMAP_UHH_SYSCONFIG_SIDLEMODE (1 << 3)
  90. #define OMAP_UHH_SYSCONFIG_ENAWAKEUP (1 << 2)
  91. #define OMAP_UHH_SYSCONFIG_SOFTRESET (1 << 1)
  92. #define OMAP_UHH_SYSCONFIG_AUTOIDLE (1 << 0)
  93. #define OMAP_UHH_SYSSTATUS (0x14)
  94. #define OMAP_UHH_HOSTCONFIG (0x40)
  95. #define OMAP_UHH_HOSTCONFIG_ULPI_BYPASS (1 << 0)
  96. #define OMAP_UHH_HOSTCONFIG_ULPI_P1_BYPASS (1 << 0)
  97. #define OMAP_UHH_HOSTCONFIG_ULPI_P2_BYPASS (1 << 11)
  98. #define OMAP_UHH_HOSTCONFIG_ULPI_P3_BYPASS (1 << 12)
  99. #define OMAP_UHH_HOSTCONFIG_INCR4_BURST_EN (1 << 2)
  100. #define OMAP_UHH_HOSTCONFIG_INCR8_BURST_EN (1 << 3)
  101. #define OMAP_UHH_HOSTCONFIG_INCR16_BURST_EN (1 << 4)
  102. #define OMAP_UHH_HOSTCONFIG_INCRX_ALIGN_EN (1 << 5)
  103. #define OMAP_UHH_HOSTCONFIG_P1_CONNECT_STATUS (1 << 8)
  104. #define OMAP_UHH_HOSTCONFIG_P2_CONNECT_STATUS (1 << 9)
  105. #define OMAP_UHH_HOSTCONFIG_P3_CONNECT_STATUS (1 << 10)
  106. #define OMAP4_UHH_HOSTCONFIG_APP_START_CLK (1 << 31)
  107. /* OMAP4-specific defines */
  108. #define OMAP4_UHH_SYSCONFIG_IDLEMODE_CLEAR (3 << 2)
  109. #define OMAP4_UHH_SYSCONFIG_NOIDLE (1 << 2)
  110. #define OMAP4_UHH_SYSCONFIG_STDBYMODE_CLEAR (3 << 4)
  111. #define OMAP4_UHH_SYSCONFIG_NOSTDBY (1 << 4)
  112. #define OMAP4_UHH_SYSCONFIG_SOFTRESET (1 << 0)
  113. #define OMAP4_P1_MODE_CLEAR (3 << 16)
  114. #define OMAP4_P1_MODE_TLL (1 << 16)
  115. #define OMAP4_P1_MODE_HSIC (3 << 16)
  116. #define OMAP4_P2_MODE_CLEAR (3 << 18)
  117. #define OMAP4_P2_MODE_TLL (1 << 18)
  118. #define OMAP4_P2_MODE_HSIC (3 << 18)
  119. #define OMAP_REV2_TLL_CHANNEL_COUNT 2
  120. #define OMAP_UHH_DEBUG_CSR (0x44)
  121. /* Values of UHH_REVISION - Note: these are not given in the TRM */
  122. #define OMAP_USBHS_REV1 0x00000010 /* OMAP3 */
  123. #define OMAP_USBHS_REV2 0x50700100 /* OMAP4 */
  124. #define is_omap_usbhs_rev1(x) (x->usbhs_rev == OMAP_USBHS_REV1)
  125. #define is_omap_usbhs_rev2(x) (x->usbhs_rev == OMAP_USBHS_REV2)
  126. #define is_ehci_phy_mode(x) (x == OMAP_EHCI_PORT_MODE_PHY)
  127. #define is_ehci_tll_mode(x) (x == OMAP_EHCI_PORT_MODE_TLL)
  128. #define is_ehci_hsic_mode(x) (x == OMAP_EHCI_PORT_MODE_HSIC)
  129. struct usbhs_hcd_omap {
  130. struct clk *xclk60mhsp1_ck;
  131. struct clk *xclk60mhsp2_ck;
  132. struct clk *utmi_p1_fck;
  133. struct clk *usbhost_p1_fck;
  134. struct clk *usbtll_p1_fck;
  135. struct clk *utmi_p2_fck;
  136. struct clk *usbhost_p2_fck;
  137. struct clk *usbtll_p2_fck;
  138. struct clk *init_60m_fclk;
  139. struct clk *ehci_logic_fck;
  140. void __iomem *uhh_base;
  141. void __iomem *tll_base;
  142. struct usbhs_omap_platform_data platdata;
  143. u32 usbhs_rev;
  144. spinlock_t lock;
  145. };
  146. /*-------------------------------------------------------------------------*/
  147. const char usbhs_driver_name[] = USBHS_DRIVER_NAME;
  148. static u64 usbhs_dmamask = DMA_BIT_MASK(32);
  149. /*-------------------------------------------------------------------------*/
  150. static inline void usbhs_write(void __iomem *base, u32 reg, u32 val)
  151. {
  152. __raw_writel(val, base + reg);
  153. }
  154. static inline u32 usbhs_read(void __iomem *base, u32 reg)
  155. {
  156. return __raw_readl(base + reg);
  157. }
  158. static inline void usbhs_writeb(void __iomem *base, u8 reg, u8 val)
  159. {
  160. __raw_writeb(val, base + reg);
  161. }
  162. static inline u8 usbhs_readb(void __iomem *base, u8 reg)
  163. {
  164. return __raw_readb(base + reg);
  165. }
  166. /*-------------------------------------------------------------------------*/
  167. static struct platform_device *omap_usbhs_alloc_child(const char *name,
  168. struct resource *res, int num_resources, void *pdata,
  169. size_t pdata_size, struct device *dev)
  170. {
  171. struct platform_device *child;
  172. int ret;
  173. child = platform_device_alloc(name, 0);
  174. if (!child) {
  175. dev_err(dev, "platform_device_alloc %s failed\n", name);
  176. goto err_end;
  177. }
  178. ret = platform_device_add_resources(child, res, num_resources);
  179. if (ret) {
  180. dev_err(dev, "platform_device_add_resources failed\n");
  181. goto err_alloc;
  182. }
  183. ret = platform_device_add_data(child, pdata, pdata_size);
  184. if (ret) {
  185. dev_err(dev, "platform_device_add_data failed\n");
  186. goto err_alloc;
  187. }
  188. child->dev.dma_mask = &usbhs_dmamask;
  189. dma_set_coherent_mask(&child->dev, DMA_BIT_MASK(32));
  190. child->dev.parent = dev;
  191. ret = platform_device_add(child);
  192. if (ret) {
  193. dev_err(dev, "platform_device_add failed\n");
  194. goto err_alloc;
  195. }
  196. return child;
  197. err_alloc:
  198. platform_device_put(child);
  199. err_end:
  200. return NULL;
  201. }
  202. static int omap_usbhs_alloc_children(struct platform_device *pdev)
  203. {
  204. struct device *dev = &pdev->dev;
  205. struct usbhs_hcd_omap *omap;
  206. struct ehci_hcd_omap_platform_data *ehci_data;
  207. struct ohci_hcd_omap_platform_data *ohci_data;
  208. struct platform_device *ehci;
  209. struct platform_device *ohci;
  210. struct resource *res;
  211. struct resource resources[2];
  212. int ret;
  213. omap = platform_get_drvdata(pdev);
  214. ehci_data = omap->platdata.ehci_data;
  215. ohci_data = omap->platdata.ohci_data;
  216. res = platform_get_resource_byname(pdev, IORESOURCE_MEM, "ehci");
  217. if (!res) {
  218. dev_err(dev, "EHCI get resource IORESOURCE_MEM failed\n");
  219. ret = -ENODEV;
  220. goto err_end;
  221. }
  222. resources[0] = *res;
  223. res = platform_get_resource_byname(pdev, IORESOURCE_IRQ, "ehci-irq");
  224. if (!res) {
  225. dev_err(dev, " EHCI get resource IORESOURCE_IRQ failed\n");
  226. ret = -ENODEV;
  227. goto err_end;
  228. }
  229. resources[1] = *res;
  230. ehci = omap_usbhs_alloc_child(OMAP_EHCI_DEVICE, resources, 2, ehci_data,
  231. sizeof(*ehci_data), dev);
  232. if (!ehci) {
  233. dev_err(dev, "omap_usbhs_alloc_child failed\n");
  234. ret = -ENOMEM;
  235. goto err_end;
  236. }
  237. res = platform_get_resource_byname(pdev, IORESOURCE_MEM, "ohci");
  238. if (!res) {
  239. dev_err(dev, "OHCI get resource IORESOURCE_MEM failed\n");
  240. ret = -ENODEV;
  241. goto err_ehci;
  242. }
  243. resources[0] = *res;
  244. res = platform_get_resource_byname(pdev, IORESOURCE_IRQ, "ohci-irq");
  245. if (!res) {
  246. dev_err(dev, "OHCI get resource IORESOURCE_IRQ failed\n");
  247. ret = -ENODEV;
  248. goto err_ehci;
  249. }
  250. resources[1] = *res;
  251. ohci = omap_usbhs_alloc_child(OMAP_OHCI_DEVICE, resources, 2, ohci_data,
  252. sizeof(*ohci_data), dev);
  253. if (!ohci) {
  254. dev_err(dev, "omap_usbhs_alloc_child failed\n");
  255. ret = -ENOMEM;
  256. goto err_ehci;
  257. }
  258. return 0;
  259. err_ehci:
  260. platform_device_unregister(ehci);
  261. err_end:
  262. return ret;
  263. }
  264. static bool is_ohci_port(enum usbhs_omap_port_mode pmode)
  265. {
  266. switch (pmode) {
  267. case OMAP_OHCI_PORT_MODE_PHY_6PIN_DATSE0:
  268. case OMAP_OHCI_PORT_MODE_PHY_6PIN_DPDM:
  269. case OMAP_OHCI_PORT_MODE_PHY_3PIN_DATSE0:
  270. case OMAP_OHCI_PORT_MODE_PHY_4PIN_DPDM:
  271. case OMAP_OHCI_PORT_MODE_TLL_6PIN_DATSE0:
  272. case OMAP_OHCI_PORT_MODE_TLL_6PIN_DPDM:
  273. case OMAP_OHCI_PORT_MODE_TLL_3PIN_DATSE0:
  274. case OMAP_OHCI_PORT_MODE_TLL_4PIN_DPDM:
  275. case OMAP_OHCI_PORT_MODE_TLL_2PIN_DATSE0:
  276. case OMAP_OHCI_PORT_MODE_TLL_2PIN_DPDM:
  277. return true;
  278. default:
  279. return false;
  280. }
  281. }
  282. /*
  283. * convert the port-mode enum to a value we can use in the FSLSMODE
  284. * field of USBTLL_CHANNEL_CONF
  285. */
  286. static unsigned ohci_omap3_fslsmode(enum usbhs_omap_port_mode mode)
  287. {
  288. switch (mode) {
  289. case OMAP_USBHS_PORT_MODE_UNUSED:
  290. case OMAP_OHCI_PORT_MODE_PHY_6PIN_DATSE0:
  291. return OMAP_TLL_FSLSMODE_6PIN_PHY_DAT_SE0;
  292. case OMAP_OHCI_PORT_MODE_PHY_6PIN_DPDM:
  293. return OMAP_TLL_FSLSMODE_6PIN_PHY_DP_DM;
  294. case OMAP_OHCI_PORT_MODE_PHY_3PIN_DATSE0:
  295. return OMAP_TLL_FSLSMODE_3PIN_PHY;
  296. case OMAP_OHCI_PORT_MODE_PHY_4PIN_DPDM:
  297. return OMAP_TLL_FSLSMODE_4PIN_PHY;
  298. case OMAP_OHCI_PORT_MODE_TLL_6PIN_DATSE0:
  299. return OMAP_TLL_FSLSMODE_6PIN_TLL_DAT_SE0;
  300. case OMAP_OHCI_PORT_MODE_TLL_6PIN_DPDM:
  301. return OMAP_TLL_FSLSMODE_6PIN_TLL_DP_DM;
  302. case OMAP_OHCI_PORT_MODE_TLL_3PIN_DATSE0:
  303. return OMAP_TLL_FSLSMODE_3PIN_TLL;
  304. case OMAP_OHCI_PORT_MODE_TLL_4PIN_DPDM:
  305. return OMAP_TLL_FSLSMODE_4PIN_TLL;
  306. case OMAP_OHCI_PORT_MODE_TLL_2PIN_DATSE0:
  307. return OMAP_TLL_FSLSMODE_2PIN_TLL_DAT_SE0;
  308. case OMAP_OHCI_PORT_MODE_TLL_2PIN_DPDM:
  309. return OMAP_TLL_FSLSMODE_2PIN_DAT_DP_DM;
  310. default:
  311. pr_warning("Invalid port mode, using default\n");
  312. return OMAP_TLL_FSLSMODE_6PIN_PHY_DAT_SE0;
  313. }
  314. }
  315. static void usbhs_omap_tll_init(struct device *dev, u8 tll_channel_count)
  316. {
  317. struct usbhs_hcd_omap *omap = dev_get_drvdata(dev);
  318. struct usbhs_omap_platform_data *pdata = dev->platform_data;
  319. unsigned reg;
  320. int i;
  321. /* Program Common TLL register */
  322. reg = usbhs_read(omap->tll_base, OMAP_TLL_SHARED_CONF);
  323. reg |= (OMAP_TLL_SHARED_CONF_FCLK_IS_ON
  324. | OMAP_TLL_SHARED_CONF_USB_DIVRATION);
  325. reg &= ~OMAP_TLL_SHARED_CONF_USB_90D_DDR_EN;
  326. reg &= ~OMAP_TLL_SHARED_CONF_USB_180D_SDR_EN;
  327. usbhs_write(omap->tll_base, OMAP_TLL_SHARED_CONF, reg);
  328. /* Enable channels now */
  329. for (i = 0; i < tll_channel_count; i++) {
  330. reg = usbhs_read(omap->tll_base,
  331. OMAP_TLL_CHANNEL_CONF(i));
  332. if (is_ohci_port(pdata->port_mode[i])) {
  333. reg |= ohci_omap3_fslsmode(pdata->port_mode[i])
  334. << OMAP_TLL_CHANNEL_CONF_FSLSMODE_SHIFT;
  335. reg |= OMAP_TLL_CHANNEL_CONF_CHANMODE_FSLS;
  336. } else if (pdata->port_mode[i] == OMAP_EHCI_PORT_MODE_TLL) {
  337. /* Disable AutoIdle, BitStuffing and use SDR Mode */
  338. reg &= ~(OMAP_TLL_CHANNEL_CONF_UTMIAUTOIDLE
  339. | OMAP_TLL_CHANNEL_CONF_ULPINOBITSTUFF
  340. | OMAP_TLL_CHANNEL_CONF_ULPIDDRMODE);
  341. } else
  342. continue;
  343. reg |= OMAP_TLL_CHANNEL_CONF_CHANEN;
  344. usbhs_write(omap->tll_base,
  345. OMAP_TLL_CHANNEL_CONF(i), reg);
  346. usbhs_writeb(omap->tll_base,
  347. OMAP_TLL_ULPI_SCRATCH_REGISTER(i), 0xbe);
  348. }
  349. }
  350. static int usbhs_runtime_resume(struct device *dev)
  351. {
  352. struct usbhs_hcd_omap *omap = dev_get_drvdata(dev);
  353. struct usbhs_omap_platform_data *pdata = &omap->platdata;
  354. unsigned long flags;
  355. dev_dbg(dev, "usbhs_runtime_resume\n");
  356. if (!pdata) {
  357. dev_dbg(dev, "missing platform_data\n");
  358. return -ENODEV;
  359. }
  360. spin_lock_irqsave(&omap->lock, flags);
  361. if (omap->ehci_logic_fck && !IS_ERR(omap->ehci_logic_fck))
  362. clk_enable(omap->ehci_logic_fck);
  363. if (is_ehci_tll_mode(pdata->port_mode[0])) {
  364. clk_enable(omap->usbhost_p1_fck);
  365. clk_enable(omap->usbtll_p1_fck);
  366. }
  367. if (is_ehci_tll_mode(pdata->port_mode[1])) {
  368. clk_enable(omap->usbhost_p2_fck);
  369. clk_enable(omap->usbtll_p2_fck);
  370. }
  371. clk_enable(omap->utmi_p1_fck);
  372. clk_enable(omap->utmi_p2_fck);
  373. spin_unlock_irqrestore(&omap->lock, flags);
  374. return 0;
  375. }
  376. static int usbhs_runtime_suspend(struct device *dev)
  377. {
  378. struct usbhs_hcd_omap *omap = dev_get_drvdata(dev);
  379. struct usbhs_omap_platform_data *pdata = &omap->platdata;
  380. unsigned long flags;
  381. dev_dbg(dev, "usbhs_runtime_suspend\n");
  382. if (!pdata) {
  383. dev_dbg(dev, "missing platform_data\n");
  384. return -ENODEV;
  385. }
  386. spin_lock_irqsave(&omap->lock, flags);
  387. if (is_ehci_tll_mode(pdata->port_mode[0])) {
  388. clk_disable(omap->usbhost_p1_fck);
  389. clk_disable(omap->usbtll_p1_fck);
  390. }
  391. if (is_ehci_tll_mode(pdata->port_mode[1])) {
  392. clk_disable(omap->usbhost_p2_fck);
  393. clk_disable(omap->usbtll_p2_fck);
  394. }
  395. clk_disable(omap->utmi_p2_fck);
  396. clk_disable(omap->utmi_p1_fck);
  397. if (omap->ehci_logic_fck && !IS_ERR(omap->ehci_logic_fck))
  398. clk_disable(omap->ehci_logic_fck);
  399. spin_unlock_irqrestore(&omap->lock, flags);
  400. return 0;
  401. }
  402. static void omap_usbhs_init(struct device *dev)
  403. {
  404. struct usbhs_hcd_omap *omap = dev_get_drvdata(dev);
  405. struct usbhs_omap_platform_data *pdata = &omap->platdata;
  406. unsigned long flags;
  407. unsigned reg;
  408. dev_dbg(dev, "starting TI HSUSB Controller\n");
  409. pm_runtime_get_sync(dev);
  410. spin_lock_irqsave(&omap->lock, flags);
  411. omap->usbhs_rev = usbhs_read(omap->uhh_base, OMAP_UHH_REVISION);
  412. dev_dbg(dev, "OMAP UHH_REVISION 0x%x\n", omap->usbhs_rev);
  413. reg = usbhs_read(omap->uhh_base, OMAP_UHH_HOSTCONFIG);
  414. /* setup ULPI bypass and burst configurations */
  415. reg |= (OMAP_UHH_HOSTCONFIG_INCR4_BURST_EN
  416. | OMAP_UHH_HOSTCONFIG_INCR8_BURST_EN
  417. | OMAP_UHH_HOSTCONFIG_INCR16_BURST_EN);
  418. reg |= OMAP4_UHH_HOSTCONFIG_APP_START_CLK;
  419. reg &= ~OMAP_UHH_HOSTCONFIG_INCRX_ALIGN_EN;
  420. if (is_omap_usbhs_rev1(omap)) {
  421. if (pdata->port_mode[0] == OMAP_USBHS_PORT_MODE_UNUSED)
  422. reg &= ~OMAP_UHH_HOSTCONFIG_P1_CONNECT_STATUS;
  423. if (pdata->port_mode[1] == OMAP_USBHS_PORT_MODE_UNUSED)
  424. reg &= ~OMAP_UHH_HOSTCONFIG_P2_CONNECT_STATUS;
  425. if (pdata->port_mode[2] == OMAP_USBHS_PORT_MODE_UNUSED)
  426. reg &= ~OMAP_UHH_HOSTCONFIG_P3_CONNECT_STATUS;
  427. /* Bypass the TLL module for PHY mode operation */
  428. if (cpu_is_omap3430() && (omap_rev() <= OMAP3430_REV_ES2_1)) {
  429. dev_dbg(dev, "OMAP3 ES version <= ES2.1\n");
  430. if (is_ehci_phy_mode(pdata->port_mode[0]) ||
  431. is_ehci_phy_mode(pdata->port_mode[1]) ||
  432. is_ehci_phy_mode(pdata->port_mode[2]))
  433. reg &= ~OMAP_UHH_HOSTCONFIG_ULPI_BYPASS;
  434. else
  435. reg |= OMAP_UHH_HOSTCONFIG_ULPI_BYPASS;
  436. } else {
  437. dev_dbg(dev, "OMAP3 ES version > ES2.1\n");
  438. if (is_ehci_phy_mode(pdata->port_mode[0]))
  439. reg &= ~OMAP_UHH_HOSTCONFIG_ULPI_P1_BYPASS;
  440. else
  441. reg |= OMAP_UHH_HOSTCONFIG_ULPI_P1_BYPASS;
  442. if (is_ehci_phy_mode(pdata->port_mode[1]))
  443. reg &= ~OMAP_UHH_HOSTCONFIG_ULPI_P2_BYPASS;
  444. else
  445. reg |= OMAP_UHH_HOSTCONFIG_ULPI_P2_BYPASS;
  446. if (is_ehci_phy_mode(pdata->port_mode[2]))
  447. reg &= ~OMAP_UHH_HOSTCONFIG_ULPI_P3_BYPASS;
  448. else
  449. reg |= OMAP_UHH_HOSTCONFIG_ULPI_P3_BYPASS;
  450. }
  451. } else if (is_omap_usbhs_rev2(omap)) {
  452. /* Clear port mode fields for PHY mode*/
  453. reg &= ~OMAP4_P1_MODE_CLEAR;
  454. reg &= ~OMAP4_P2_MODE_CLEAR;
  455. if (is_ehci_tll_mode(pdata->port_mode[0]) ||
  456. (is_ohci_port(pdata->port_mode[0])))
  457. reg |= OMAP4_P1_MODE_TLL;
  458. else if (is_ehci_hsic_mode(pdata->port_mode[0]))
  459. reg |= OMAP4_P1_MODE_HSIC;
  460. if (is_ehci_tll_mode(pdata->port_mode[1]) ||
  461. (is_ohci_port(pdata->port_mode[1])))
  462. reg |= OMAP4_P2_MODE_TLL;
  463. else if (is_ehci_hsic_mode(pdata->port_mode[1]))
  464. reg |= OMAP4_P2_MODE_HSIC;
  465. }
  466. usbhs_write(omap->uhh_base, OMAP_UHH_HOSTCONFIG, reg);
  467. dev_dbg(dev, "UHH setup done, uhh_hostconfig=%x\n", reg);
  468. if (is_ehci_tll_mode(pdata->port_mode[0]) ||
  469. is_ehci_tll_mode(pdata->port_mode[1]) ||
  470. is_ehci_tll_mode(pdata->port_mode[2]) ||
  471. (is_ohci_port(pdata->port_mode[0])) ||
  472. (is_ohci_port(pdata->port_mode[1])) ||
  473. (is_ohci_port(pdata->port_mode[2]))) {
  474. /* Enable UTMI mode for required TLL channels */
  475. if (is_omap_usbhs_rev2(omap))
  476. usbhs_omap_tll_init(dev, OMAP_REV2_TLL_CHANNEL_COUNT);
  477. else
  478. usbhs_omap_tll_init(dev, OMAP_TLL_CHANNEL_COUNT);
  479. }
  480. spin_unlock_irqrestore(&omap->lock, flags);
  481. pm_runtime_put_sync(dev);
  482. }
  483. /**
  484. * usbhs_omap_probe - initialize TI-based HCDs
  485. *
  486. * Allocates basic resources for this USB host controller.
  487. */
  488. static int __devinit usbhs_omap_probe(struct platform_device *pdev)
  489. {
  490. struct device *dev = &pdev->dev;
  491. struct usbhs_omap_platform_data *pdata = dev->platform_data;
  492. struct usbhs_hcd_omap *omap;
  493. struct resource *res;
  494. int ret = 0;
  495. int i;
  496. if (!pdata) {
  497. dev_err(dev, "Missing platform data\n");
  498. ret = -ENOMEM;
  499. goto end_probe;
  500. }
  501. omap = kzalloc(sizeof(*omap), GFP_KERNEL);
  502. if (!omap) {
  503. dev_err(dev, "Memory allocation failed\n");
  504. ret = -ENOMEM;
  505. goto end_probe;
  506. }
  507. spin_lock_init(&omap->lock);
  508. for (i = 0; i < OMAP3_HS_USB_PORTS; i++)
  509. omap->platdata.port_mode[i] = pdata->port_mode[i];
  510. omap->platdata.ehci_data = pdata->ehci_data;
  511. omap->platdata.ohci_data = pdata->ohci_data;
  512. pm_runtime_enable(dev);
  513. for (i = 0; i < OMAP3_HS_USB_PORTS; i++)
  514. if (is_ehci_phy_mode(i) || is_ehci_tll_mode(i) ||
  515. is_ehci_hsic_mode(i)) {
  516. omap->ehci_logic_fck = clk_get(dev, "ehci_logic_fck");
  517. if (IS_ERR(omap->ehci_logic_fck)) {
  518. ret = PTR_ERR(omap->ehci_logic_fck);
  519. dev_warn(dev, "ehci_logic_fck failed:%d\n",
  520. ret);
  521. }
  522. break;
  523. }
  524. omap->utmi_p1_fck = clk_get(dev, "utmi_p1_gfclk");
  525. if (IS_ERR(omap->utmi_p1_fck)) {
  526. ret = PTR_ERR(omap->utmi_p1_fck);
  527. dev_err(dev, "utmi_p1_gfclk failed error:%d\n", ret);
  528. goto err_end;
  529. }
  530. omap->xclk60mhsp1_ck = clk_get(dev, "xclk60mhsp1_ck");
  531. if (IS_ERR(omap->xclk60mhsp1_ck)) {
  532. ret = PTR_ERR(omap->xclk60mhsp1_ck);
  533. dev_err(dev, "xclk60mhsp1_ck failed error:%d\n", ret);
  534. goto err_utmi_p1_fck;
  535. }
  536. omap->utmi_p2_fck = clk_get(dev, "utmi_p2_gfclk");
  537. if (IS_ERR(omap->utmi_p2_fck)) {
  538. ret = PTR_ERR(omap->utmi_p2_fck);
  539. dev_err(dev, "utmi_p2_gfclk failed error:%d\n", ret);
  540. goto err_xclk60mhsp1_ck;
  541. }
  542. omap->xclk60mhsp2_ck = clk_get(dev, "xclk60mhsp2_ck");
  543. if (IS_ERR(omap->xclk60mhsp2_ck)) {
  544. ret = PTR_ERR(omap->xclk60mhsp2_ck);
  545. dev_err(dev, "xclk60mhsp2_ck failed error:%d\n", ret);
  546. goto err_utmi_p2_fck;
  547. }
  548. omap->usbhost_p1_fck = clk_get(dev, "usb_host_hs_utmi_p1_clk");
  549. if (IS_ERR(omap->usbhost_p1_fck)) {
  550. ret = PTR_ERR(omap->usbhost_p1_fck);
  551. dev_err(dev, "usbhost_p1_fck failed error:%d\n", ret);
  552. goto err_xclk60mhsp2_ck;
  553. }
  554. omap->usbtll_p1_fck = clk_get(dev, "usb_tll_hs_usb_ch0_clk");
  555. if (IS_ERR(omap->usbtll_p1_fck)) {
  556. ret = PTR_ERR(omap->usbtll_p1_fck);
  557. dev_err(dev, "usbtll_p1_fck failed error:%d\n", ret);
  558. goto err_usbhost_p1_fck;
  559. }
  560. omap->usbhost_p2_fck = clk_get(dev, "usb_host_hs_utmi_p2_clk");
  561. if (IS_ERR(omap->usbhost_p2_fck)) {
  562. ret = PTR_ERR(omap->usbhost_p2_fck);
  563. dev_err(dev, "usbhost_p2_fck failed error:%d\n", ret);
  564. goto err_usbtll_p1_fck;
  565. }
  566. omap->usbtll_p2_fck = clk_get(dev, "usb_tll_hs_usb_ch1_clk");
  567. if (IS_ERR(omap->usbtll_p2_fck)) {
  568. ret = PTR_ERR(omap->usbtll_p2_fck);
  569. dev_err(dev, "usbtll_p2_fck failed error:%d\n", ret);
  570. goto err_usbhost_p2_fck;
  571. }
  572. omap->init_60m_fclk = clk_get(dev, "init_60m_fclk");
  573. if (IS_ERR(omap->init_60m_fclk)) {
  574. ret = PTR_ERR(omap->init_60m_fclk);
  575. dev_err(dev, "init_60m_fclk failed error:%d\n", ret);
  576. goto err_usbtll_p2_fck;
  577. }
  578. if (is_ehci_phy_mode(pdata->port_mode[0])) {
  579. /* for OMAP3 , the clk set paretn fails */
  580. ret = clk_set_parent(omap->utmi_p1_fck,
  581. omap->xclk60mhsp1_ck);
  582. if (ret != 0)
  583. dev_err(dev, "xclk60mhsp1_ck set parent"
  584. "failed error:%d\n", ret);
  585. } else if (is_ehci_tll_mode(pdata->port_mode[0])) {
  586. ret = clk_set_parent(omap->utmi_p1_fck,
  587. omap->init_60m_fclk);
  588. if (ret != 0)
  589. dev_err(dev, "init_60m_fclk set parent"
  590. "failed error:%d\n", ret);
  591. }
  592. if (is_ehci_phy_mode(pdata->port_mode[1])) {
  593. ret = clk_set_parent(omap->utmi_p2_fck,
  594. omap->xclk60mhsp2_ck);
  595. if (ret != 0)
  596. dev_err(dev, "xclk60mhsp2_ck set parent"
  597. "failed error:%d\n", ret);
  598. } else if (is_ehci_tll_mode(pdata->port_mode[1])) {
  599. ret = clk_set_parent(omap->utmi_p2_fck,
  600. omap->init_60m_fclk);
  601. if (ret != 0)
  602. dev_err(dev, "init_60m_fclk set parent"
  603. "failed error:%d\n", ret);
  604. }
  605. res = platform_get_resource_byname(pdev, IORESOURCE_MEM, "uhh");
  606. if (!res) {
  607. dev_err(dev, "UHH EHCI get resource failed\n");
  608. ret = -ENODEV;
  609. goto err_init_60m_fclk;
  610. }
  611. omap->uhh_base = ioremap(res->start, resource_size(res));
  612. if (!omap->uhh_base) {
  613. dev_err(dev, "UHH ioremap failed\n");
  614. ret = -ENOMEM;
  615. goto err_init_60m_fclk;
  616. }
  617. res = platform_get_resource_byname(pdev, IORESOURCE_MEM, "tll");
  618. if (!res) {
  619. dev_err(dev, "UHH EHCI get resource failed\n");
  620. ret = -ENODEV;
  621. goto err_tll;
  622. }
  623. omap->tll_base = ioremap(res->start, resource_size(res));
  624. if (!omap->tll_base) {
  625. dev_err(dev, "TLL ioremap failed\n");
  626. ret = -ENOMEM;
  627. goto err_tll;
  628. }
  629. platform_set_drvdata(pdev, omap);
  630. omap_usbhs_init(dev);
  631. ret = omap_usbhs_alloc_children(pdev);
  632. if (ret) {
  633. dev_err(dev, "omap_usbhs_alloc_children failed\n");
  634. goto err_alloc;
  635. }
  636. goto end_probe;
  637. err_alloc:
  638. iounmap(omap->tll_base);
  639. err_tll:
  640. iounmap(omap->uhh_base);
  641. err_init_60m_fclk:
  642. clk_put(omap->init_60m_fclk);
  643. err_usbtll_p2_fck:
  644. clk_put(omap->usbtll_p2_fck);
  645. err_usbhost_p2_fck:
  646. clk_put(omap->usbhost_p2_fck);
  647. err_usbtll_p1_fck:
  648. clk_put(omap->usbtll_p1_fck);
  649. err_usbhost_p1_fck:
  650. clk_put(omap->usbhost_p1_fck);
  651. err_xclk60mhsp2_ck:
  652. clk_put(omap->xclk60mhsp2_ck);
  653. err_utmi_p2_fck:
  654. clk_put(omap->utmi_p2_fck);
  655. err_xclk60mhsp1_ck:
  656. clk_put(omap->xclk60mhsp1_ck);
  657. err_utmi_p1_fck:
  658. clk_put(omap->utmi_p1_fck);
  659. err_end:
  660. clk_put(omap->ehci_logic_fck);
  661. pm_runtime_disable(dev);
  662. kfree(omap);
  663. end_probe:
  664. return ret;
  665. }
  666. /**
  667. * usbhs_omap_remove - shutdown processing for UHH & TLL HCDs
  668. * @pdev: USB Host Controller being removed
  669. *
  670. * Reverses the effect of usbhs_omap_probe().
  671. */
  672. static int __devexit usbhs_omap_remove(struct platform_device *pdev)
  673. {
  674. struct usbhs_hcd_omap *omap = platform_get_drvdata(pdev);
  675. iounmap(omap->tll_base);
  676. iounmap(omap->uhh_base);
  677. clk_put(omap->init_60m_fclk);
  678. clk_put(omap->usbtll_p2_fck);
  679. clk_put(omap->usbhost_p2_fck);
  680. clk_put(omap->usbtll_p1_fck);
  681. clk_put(omap->usbhost_p1_fck);
  682. clk_put(omap->xclk60mhsp2_ck);
  683. clk_put(omap->utmi_p2_fck);
  684. clk_put(omap->xclk60mhsp1_ck);
  685. clk_put(omap->utmi_p1_fck);
  686. clk_put(omap->ehci_logic_fck);
  687. pm_runtime_disable(&pdev->dev);
  688. kfree(omap);
  689. return 0;
  690. }
  691. static const struct dev_pm_ops usbhsomap_dev_pm_ops = {
  692. .runtime_suspend = usbhs_runtime_suspend,
  693. .runtime_resume = usbhs_runtime_resume,
  694. };
  695. static struct platform_driver usbhs_omap_driver = {
  696. .driver = {
  697. .name = (char *)usbhs_driver_name,
  698. .owner = THIS_MODULE,
  699. .pm = &usbhsomap_dev_pm_ops,
  700. },
  701. .remove = __exit_p(usbhs_omap_remove),
  702. };
  703. MODULE_AUTHOR("Keshava Munegowda <keshava_mgowda@ti.com>");
  704. MODULE_ALIAS("platform:" USBHS_DRIVER_NAME);
  705. MODULE_LICENSE("GPL v2");
  706. MODULE_DESCRIPTION("usb host common core driver for omap EHCI and OHCI");
  707. static int __init omap_usbhs_drvinit(void)
  708. {
  709. return platform_driver_probe(&usbhs_omap_driver, usbhs_omap_probe);
  710. }
  711. /*
  712. * init before ehci and ohci drivers;
  713. * The usbhs core driver should be initialized much before
  714. * the omap ehci and ohci probe functions are called.
  715. */
  716. fs_initcall(omap_usbhs_drvinit);
  717. static void __exit omap_usbhs_drvexit(void)
  718. {
  719. platform_driver_unregister(&usbhs_omap_driver);
  720. }
  721. module_exit(omap_usbhs_drvexit);