omap-usb-host.c 26 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924
  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 <linux/gpio.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 = ~(u32)0;
  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. child->dev.coherent_dma_mask = 0xffffffff;
  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. if (pdata->ehci_data->phy_reset) {
  412. if (gpio_is_valid(pdata->ehci_data->reset_gpio_port[0])) {
  413. gpio_request(pdata->ehci_data->reset_gpio_port[0],
  414. "USB1 PHY reset");
  415. gpio_direction_output
  416. (pdata->ehci_data->reset_gpio_port[0], 0);
  417. }
  418. if (gpio_is_valid(pdata->ehci_data->reset_gpio_port[1])) {
  419. gpio_request(pdata->ehci_data->reset_gpio_port[1],
  420. "USB2 PHY reset");
  421. gpio_direction_output
  422. (pdata->ehci_data->reset_gpio_port[1], 0);
  423. }
  424. /* Hold the PHY in RESET for enough time till DIR is high */
  425. udelay(10);
  426. }
  427. omap->usbhs_rev = usbhs_read(omap->uhh_base, OMAP_UHH_REVISION);
  428. dev_dbg(dev, "OMAP UHH_REVISION 0x%x\n", omap->usbhs_rev);
  429. reg = usbhs_read(omap->uhh_base, OMAP_UHH_HOSTCONFIG);
  430. /* setup ULPI bypass and burst configurations */
  431. reg |= (OMAP_UHH_HOSTCONFIG_INCR4_BURST_EN
  432. | OMAP_UHH_HOSTCONFIG_INCR8_BURST_EN
  433. | OMAP_UHH_HOSTCONFIG_INCR16_BURST_EN);
  434. reg |= OMAP4_UHH_HOSTCONFIG_APP_START_CLK;
  435. reg &= ~OMAP_UHH_HOSTCONFIG_INCRX_ALIGN_EN;
  436. if (is_omap_usbhs_rev1(omap)) {
  437. if (pdata->port_mode[0] == OMAP_USBHS_PORT_MODE_UNUSED)
  438. reg &= ~OMAP_UHH_HOSTCONFIG_P1_CONNECT_STATUS;
  439. if (pdata->port_mode[1] == OMAP_USBHS_PORT_MODE_UNUSED)
  440. reg &= ~OMAP_UHH_HOSTCONFIG_P2_CONNECT_STATUS;
  441. if (pdata->port_mode[2] == OMAP_USBHS_PORT_MODE_UNUSED)
  442. reg &= ~OMAP_UHH_HOSTCONFIG_P3_CONNECT_STATUS;
  443. /* Bypass the TLL module for PHY mode operation */
  444. if (cpu_is_omap3430() && (omap_rev() <= OMAP3430_REV_ES2_1)) {
  445. dev_dbg(dev, "OMAP3 ES version <= ES2.1\n");
  446. if (is_ehci_phy_mode(pdata->port_mode[0]) ||
  447. is_ehci_phy_mode(pdata->port_mode[1]) ||
  448. is_ehci_phy_mode(pdata->port_mode[2]))
  449. reg &= ~OMAP_UHH_HOSTCONFIG_ULPI_BYPASS;
  450. else
  451. reg |= OMAP_UHH_HOSTCONFIG_ULPI_BYPASS;
  452. } else {
  453. dev_dbg(dev, "OMAP3 ES version > ES2.1\n");
  454. if (is_ehci_phy_mode(pdata->port_mode[0]))
  455. reg &= ~OMAP_UHH_HOSTCONFIG_ULPI_P1_BYPASS;
  456. else
  457. reg |= OMAP_UHH_HOSTCONFIG_ULPI_P1_BYPASS;
  458. if (is_ehci_phy_mode(pdata->port_mode[1]))
  459. reg &= ~OMAP_UHH_HOSTCONFIG_ULPI_P2_BYPASS;
  460. else
  461. reg |= OMAP_UHH_HOSTCONFIG_ULPI_P2_BYPASS;
  462. if (is_ehci_phy_mode(pdata->port_mode[2]))
  463. reg &= ~OMAP_UHH_HOSTCONFIG_ULPI_P3_BYPASS;
  464. else
  465. reg |= OMAP_UHH_HOSTCONFIG_ULPI_P3_BYPASS;
  466. }
  467. } else if (is_omap_usbhs_rev2(omap)) {
  468. /* Clear port mode fields for PHY mode*/
  469. reg &= ~OMAP4_P1_MODE_CLEAR;
  470. reg &= ~OMAP4_P2_MODE_CLEAR;
  471. if (is_ehci_tll_mode(pdata->port_mode[0]) ||
  472. (is_ohci_port(pdata->port_mode[0])))
  473. reg |= OMAP4_P1_MODE_TLL;
  474. else if (is_ehci_hsic_mode(pdata->port_mode[0]))
  475. reg |= OMAP4_P1_MODE_HSIC;
  476. if (is_ehci_tll_mode(pdata->port_mode[1]) ||
  477. (is_ohci_port(pdata->port_mode[1])))
  478. reg |= OMAP4_P2_MODE_TLL;
  479. else if (is_ehci_hsic_mode(pdata->port_mode[1]))
  480. reg |= OMAP4_P2_MODE_HSIC;
  481. }
  482. usbhs_write(omap->uhh_base, OMAP_UHH_HOSTCONFIG, reg);
  483. dev_dbg(dev, "UHH setup done, uhh_hostconfig=%x\n", reg);
  484. if (is_ehci_tll_mode(pdata->port_mode[0]) ||
  485. is_ehci_tll_mode(pdata->port_mode[1]) ||
  486. is_ehci_tll_mode(pdata->port_mode[2]) ||
  487. (is_ohci_port(pdata->port_mode[0])) ||
  488. (is_ohci_port(pdata->port_mode[1])) ||
  489. (is_ohci_port(pdata->port_mode[2]))) {
  490. /* Enable UTMI mode for required TLL channels */
  491. if (is_omap_usbhs_rev2(omap))
  492. usbhs_omap_tll_init(dev, OMAP_REV2_TLL_CHANNEL_COUNT);
  493. else
  494. usbhs_omap_tll_init(dev, OMAP_TLL_CHANNEL_COUNT);
  495. }
  496. if (pdata->ehci_data->phy_reset) {
  497. /* Hold the PHY in RESET for enough time till
  498. * PHY is settled and ready
  499. */
  500. udelay(10);
  501. if (gpio_is_valid(pdata->ehci_data->reset_gpio_port[0]))
  502. gpio_set_value
  503. (pdata->ehci_data->reset_gpio_port[0], 1);
  504. if (gpio_is_valid(pdata->ehci_data->reset_gpio_port[1]))
  505. gpio_set_value
  506. (pdata->ehci_data->reset_gpio_port[1], 1);
  507. }
  508. spin_unlock_irqrestore(&omap->lock, flags);
  509. pm_runtime_put_sync(dev);
  510. }
  511. static void omap_usbhs_deinit(struct device *dev)
  512. {
  513. struct usbhs_hcd_omap *omap = dev_get_drvdata(dev);
  514. struct usbhs_omap_platform_data *pdata = &omap->platdata;
  515. if (pdata->ehci_data->phy_reset) {
  516. if (gpio_is_valid(pdata->ehci_data->reset_gpio_port[0]))
  517. gpio_free(pdata->ehci_data->reset_gpio_port[0]);
  518. if (gpio_is_valid(pdata->ehci_data->reset_gpio_port[1]))
  519. gpio_free(pdata->ehci_data->reset_gpio_port[1]);
  520. }
  521. }
  522. /**
  523. * usbhs_omap_probe - initialize TI-based HCDs
  524. *
  525. * Allocates basic resources for this USB host controller.
  526. */
  527. static int __devinit usbhs_omap_probe(struct platform_device *pdev)
  528. {
  529. struct device *dev = &pdev->dev;
  530. struct usbhs_omap_platform_data *pdata = dev->platform_data;
  531. struct usbhs_hcd_omap *omap;
  532. struct resource *res;
  533. int ret = 0;
  534. int i;
  535. if (!pdata) {
  536. dev_err(dev, "Missing platform data\n");
  537. ret = -ENOMEM;
  538. goto end_probe;
  539. }
  540. omap = kzalloc(sizeof(*omap), GFP_KERNEL);
  541. if (!omap) {
  542. dev_err(dev, "Memory allocation failed\n");
  543. ret = -ENOMEM;
  544. goto end_probe;
  545. }
  546. spin_lock_init(&omap->lock);
  547. for (i = 0; i < OMAP3_HS_USB_PORTS; i++)
  548. omap->platdata.port_mode[i] = pdata->port_mode[i];
  549. omap->platdata.ehci_data = pdata->ehci_data;
  550. omap->platdata.ohci_data = pdata->ohci_data;
  551. pm_runtime_enable(dev);
  552. for (i = 0; i < OMAP3_HS_USB_PORTS; i++)
  553. if (is_ehci_phy_mode(i) || is_ehci_tll_mode(i) ||
  554. is_ehci_hsic_mode(i)) {
  555. omap->ehci_logic_fck = clk_get(dev, "ehci_logic_fck");
  556. if (IS_ERR(omap->ehci_logic_fck)) {
  557. ret = PTR_ERR(omap->ehci_logic_fck);
  558. dev_warn(dev, "ehci_logic_fck failed:%d\n",
  559. ret);
  560. }
  561. break;
  562. }
  563. omap->utmi_p1_fck = clk_get(dev, "utmi_p1_gfclk");
  564. if (IS_ERR(omap->utmi_p1_fck)) {
  565. ret = PTR_ERR(omap->utmi_p1_fck);
  566. dev_err(dev, "utmi_p1_gfclk failed error:%d\n", ret);
  567. goto err_end;
  568. }
  569. omap->xclk60mhsp1_ck = clk_get(dev, "xclk60mhsp1_ck");
  570. if (IS_ERR(omap->xclk60mhsp1_ck)) {
  571. ret = PTR_ERR(omap->xclk60mhsp1_ck);
  572. dev_err(dev, "xclk60mhsp1_ck failed error:%d\n", ret);
  573. goto err_utmi_p1_fck;
  574. }
  575. omap->utmi_p2_fck = clk_get(dev, "utmi_p2_gfclk");
  576. if (IS_ERR(omap->utmi_p2_fck)) {
  577. ret = PTR_ERR(omap->utmi_p2_fck);
  578. dev_err(dev, "utmi_p2_gfclk failed error:%d\n", ret);
  579. goto err_xclk60mhsp1_ck;
  580. }
  581. omap->xclk60mhsp2_ck = clk_get(dev, "xclk60mhsp2_ck");
  582. if (IS_ERR(omap->xclk60mhsp2_ck)) {
  583. ret = PTR_ERR(omap->xclk60mhsp2_ck);
  584. dev_err(dev, "xclk60mhsp2_ck failed error:%d\n", ret);
  585. goto err_utmi_p2_fck;
  586. }
  587. omap->usbhost_p1_fck = clk_get(dev, "usb_host_hs_utmi_p1_clk");
  588. if (IS_ERR(omap->usbhost_p1_fck)) {
  589. ret = PTR_ERR(omap->usbhost_p1_fck);
  590. dev_err(dev, "usbhost_p1_fck failed error:%d\n", ret);
  591. goto err_xclk60mhsp2_ck;
  592. }
  593. omap->usbtll_p1_fck = clk_get(dev, "usb_tll_hs_usb_ch0_clk");
  594. if (IS_ERR(omap->usbtll_p1_fck)) {
  595. ret = PTR_ERR(omap->usbtll_p1_fck);
  596. dev_err(dev, "usbtll_p1_fck failed error:%d\n", ret);
  597. goto err_usbhost_p1_fck;
  598. }
  599. omap->usbhost_p2_fck = clk_get(dev, "usb_host_hs_utmi_p2_clk");
  600. if (IS_ERR(omap->usbhost_p2_fck)) {
  601. ret = PTR_ERR(omap->usbhost_p2_fck);
  602. dev_err(dev, "usbhost_p2_fck failed error:%d\n", ret);
  603. goto err_usbtll_p1_fck;
  604. }
  605. omap->usbtll_p2_fck = clk_get(dev, "usb_tll_hs_usb_ch1_clk");
  606. if (IS_ERR(omap->usbtll_p2_fck)) {
  607. ret = PTR_ERR(omap->usbtll_p2_fck);
  608. dev_err(dev, "usbtll_p2_fck failed error:%d\n", ret);
  609. goto err_usbhost_p2_fck;
  610. }
  611. omap->init_60m_fclk = clk_get(dev, "init_60m_fclk");
  612. if (IS_ERR(omap->init_60m_fclk)) {
  613. ret = PTR_ERR(omap->init_60m_fclk);
  614. dev_err(dev, "init_60m_fclk failed error:%d\n", ret);
  615. goto err_usbtll_p2_fck;
  616. }
  617. if (is_ehci_phy_mode(pdata->port_mode[0])) {
  618. /* for OMAP3 , the clk set paretn fails */
  619. ret = clk_set_parent(omap->utmi_p1_fck,
  620. omap->xclk60mhsp1_ck);
  621. if (ret != 0)
  622. dev_err(dev, "xclk60mhsp1_ck set parent"
  623. "failed error:%d\n", ret);
  624. } else if (is_ehci_tll_mode(pdata->port_mode[0])) {
  625. ret = clk_set_parent(omap->utmi_p1_fck,
  626. omap->init_60m_fclk);
  627. if (ret != 0)
  628. dev_err(dev, "init_60m_fclk set parent"
  629. "failed error:%d\n", ret);
  630. }
  631. if (is_ehci_phy_mode(pdata->port_mode[1])) {
  632. ret = clk_set_parent(omap->utmi_p2_fck,
  633. omap->xclk60mhsp2_ck);
  634. if (ret != 0)
  635. dev_err(dev, "xclk60mhsp2_ck set parent"
  636. "failed error:%d\n", ret);
  637. } else if (is_ehci_tll_mode(pdata->port_mode[1])) {
  638. ret = clk_set_parent(omap->utmi_p2_fck,
  639. omap->init_60m_fclk);
  640. if (ret != 0)
  641. dev_err(dev, "init_60m_fclk set parent"
  642. "failed error:%d\n", ret);
  643. }
  644. res = platform_get_resource_byname(pdev, IORESOURCE_MEM, "uhh");
  645. if (!res) {
  646. dev_err(dev, "UHH EHCI get resource failed\n");
  647. ret = -ENODEV;
  648. goto err_init_60m_fclk;
  649. }
  650. omap->uhh_base = ioremap(res->start, resource_size(res));
  651. if (!omap->uhh_base) {
  652. dev_err(dev, "UHH ioremap failed\n");
  653. ret = -ENOMEM;
  654. goto err_init_60m_fclk;
  655. }
  656. res = platform_get_resource_byname(pdev, IORESOURCE_MEM, "tll");
  657. if (!res) {
  658. dev_err(dev, "UHH EHCI get resource failed\n");
  659. ret = -ENODEV;
  660. goto err_tll;
  661. }
  662. omap->tll_base = ioremap(res->start, resource_size(res));
  663. if (!omap->tll_base) {
  664. dev_err(dev, "TLL ioremap failed\n");
  665. ret = -ENOMEM;
  666. goto err_tll;
  667. }
  668. platform_set_drvdata(pdev, omap);
  669. ret = omap_usbhs_alloc_children(pdev);
  670. if (ret) {
  671. dev_err(dev, "omap_usbhs_alloc_children failed\n");
  672. goto err_alloc;
  673. }
  674. omap_usbhs_init(dev);
  675. goto end_probe;
  676. err_alloc:
  677. iounmap(omap->tll_base);
  678. err_tll:
  679. iounmap(omap->uhh_base);
  680. err_init_60m_fclk:
  681. clk_put(omap->init_60m_fclk);
  682. err_usbtll_p2_fck:
  683. clk_put(omap->usbtll_p2_fck);
  684. err_usbhost_p2_fck:
  685. clk_put(omap->usbhost_p2_fck);
  686. err_usbtll_p1_fck:
  687. clk_put(omap->usbtll_p1_fck);
  688. err_usbhost_p1_fck:
  689. clk_put(omap->usbhost_p1_fck);
  690. err_xclk60mhsp2_ck:
  691. clk_put(omap->xclk60mhsp2_ck);
  692. err_utmi_p2_fck:
  693. clk_put(omap->utmi_p2_fck);
  694. err_xclk60mhsp1_ck:
  695. clk_put(omap->xclk60mhsp1_ck);
  696. err_utmi_p1_fck:
  697. clk_put(omap->utmi_p1_fck);
  698. err_end:
  699. clk_put(omap->ehci_logic_fck);
  700. pm_runtime_disable(dev);
  701. kfree(omap);
  702. end_probe:
  703. return ret;
  704. }
  705. /**
  706. * usbhs_omap_remove - shutdown processing for UHH & TLL HCDs
  707. * @pdev: USB Host Controller being removed
  708. *
  709. * Reverses the effect of usbhs_omap_probe().
  710. */
  711. static int __devexit usbhs_omap_remove(struct platform_device *pdev)
  712. {
  713. struct usbhs_hcd_omap *omap = platform_get_drvdata(pdev);
  714. omap_usbhs_deinit(&pdev->dev);
  715. iounmap(omap->tll_base);
  716. iounmap(omap->uhh_base);
  717. clk_put(omap->init_60m_fclk);
  718. clk_put(omap->usbtll_p2_fck);
  719. clk_put(omap->usbhost_p2_fck);
  720. clk_put(omap->usbtll_p1_fck);
  721. clk_put(omap->usbhost_p1_fck);
  722. clk_put(omap->xclk60mhsp2_ck);
  723. clk_put(omap->utmi_p2_fck);
  724. clk_put(omap->xclk60mhsp1_ck);
  725. clk_put(omap->utmi_p1_fck);
  726. clk_put(omap->ehci_logic_fck);
  727. pm_runtime_disable(&pdev->dev);
  728. kfree(omap);
  729. return 0;
  730. }
  731. static const struct dev_pm_ops usbhsomap_dev_pm_ops = {
  732. .runtime_suspend = usbhs_runtime_suspend,
  733. .runtime_resume = usbhs_runtime_resume,
  734. };
  735. static struct platform_driver usbhs_omap_driver = {
  736. .driver = {
  737. .name = (char *)usbhs_driver_name,
  738. .owner = THIS_MODULE,
  739. .pm = &usbhsomap_dev_pm_ops,
  740. },
  741. .remove = __exit_p(usbhs_omap_remove),
  742. };
  743. MODULE_AUTHOR("Keshava Munegowda <keshava_mgowda@ti.com>");
  744. MODULE_ALIAS("platform:" USBHS_DRIVER_NAME);
  745. MODULE_LICENSE("GPL v2");
  746. MODULE_DESCRIPTION("usb host common core driver for omap EHCI and OHCI");
  747. static int __init omap_usbhs_drvinit(void)
  748. {
  749. return platform_driver_probe(&usbhs_omap_driver, usbhs_omap_probe);
  750. }
  751. /*
  752. * init before ehci and ohci drivers;
  753. * The usbhs core driver should be initialized much before
  754. * the omap ehci and ohci probe functions are called.
  755. */
  756. fs_initcall(omap_usbhs_drvinit);
  757. static void __exit omap_usbhs_drvexit(void)
  758. {
  759. platform_driver_unregister(&usbhs_omap_driver);
  760. }
  761. module_exit(omap_usbhs_drvexit);