ohci-omap.c 13 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541
  1. /*
  2. * OHCI HCD (Host Controller Driver) for USB.
  3. *
  4. * (C) Copyright 1999 Roman Weissgaerber <weissg@vienna.at>
  5. * (C) Copyright 2000-2005 David Brownell
  6. * (C) Copyright 2002 Hewlett-Packard Company
  7. *
  8. * OMAP Bus Glue
  9. *
  10. * Modified for OMAP by Tony Lindgren <tony@atomide.com>
  11. * Based on the 2.4 OMAP OHCI driver originally done by MontaVista Software Inc.
  12. * and on ohci-sa1111.c by Christopher Hoover <ch@hpl.hp.com>
  13. *
  14. * This file is licenced under the GPL.
  15. */
  16. #include <asm/hardware.h>
  17. #include <asm/io.h>
  18. #include <asm/mach-types.h>
  19. #include <asm/arch/hardware.h>
  20. #include <asm/arch/mux.h>
  21. #include <asm/arch/irqs.h>
  22. #include <asm/arch/gpio.h>
  23. #include <asm/arch/fpga.h>
  24. #include <asm/arch/usb.h>
  25. #include <asm/hardware/clock.h>
  26. /* OMAP-1510 OHCI has its own MMU for DMA */
  27. #define OMAP1510_LB_MEMSIZE 32 /* Should be same as SDRAM size */
  28. #define OMAP1510_LB_CLOCK_DIV 0xfffec10c
  29. #define OMAP1510_LB_MMU_CTL 0xfffec208
  30. #define OMAP1510_LB_MMU_LCK 0xfffec224
  31. #define OMAP1510_LB_MMU_LD_TLB 0xfffec228
  32. #define OMAP1510_LB_MMU_CAM_H 0xfffec22c
  33. #define OMAP1510_LB_MMU_CAM_L 0xfffec230
  34. #define OMAP1510_LB_MMU_RAM_H 0xfffec234
  35. #define OMAP1510_LB_MMU_RAM_L 0xfffec238
  36. #ifndef CONFIG_ARCH_OMAP
  37. #error "This file is OMAP bus glue. CONFIG_OMAP must be defined."
  38. #endif
  39. #ifdef CONFIG_TPS65010
  40. #include <asm/arch/tps65010.h>
  41. #else
  42. #define LOW 0
  43. #define HIGH 1
  44. #define GPIO1 1
  45. static inline int tps65010_set_gpio_out_value(unsigned gpio, unsigned value)
  46. {
  47. return 0;
  48. }
  49. #endif
  50. extern int usb_disabled(void);
  51. extern int ocpi_enable(void);
  52. static struct clk *usb_host_ck;
  53. static void omap_ohci_clock_power(int on)
  54. {
  55. if (on) {
  56. clk_enable(usb_host_ck);
  57. /* guesstimate for T5 == 1x 32K clock + APLL lock time */
  58. udelay(100);
  59. } else {
  60. clk_disable(usb_host_ck);
  61. }
  62. }
  63. /*
  64. * Board specific gang-switched transceiver power on/off.
  65. * NOTE: OSK supplies power from DC, not battery.
  66. */
  67. static int omap_ohci_transceiver_power(int on)
  68. {
  69. if (on) {
  70. if (machine_is_omap_innovator() && cpu_is_omap1510())
  71. fpga_write(fpga_read(INNOVATOR_FPGA_CAM_USB_CONTROL)
  72. | ((1 << 5/*usb1*/) | (1 << 3/*usb2*/)),
  73. INNOVATOR_FPGA_CAM_USB_CONTROL);
  74. else if (machine_is_omap_osk())
  75. tps65010_set_gpio_out_value(GPIO1, LOW);
  76. } else {
  77. if (machine_is_omap_innovator() && cpu_is_omap1510())
  78. fpga_write(fpga_read(INNOVATOR_FPGA_CAM_USB_CONTROL)
  79. & ~((1 << 5/*usb1*/) | (1 << 3/*usb2*/)),
  80. INNOVATOR_FPGA_CAM_USB_CONTROL);
  81. else if (machine_is_omap_osk())
  82. tps65010_set_gpio_out_value(GPIO1, HIGH);
  83. }
  84. return 0;
  85. }
  86. /*
  87. * OMAP-1510 specific Local Bus clock on/off
  88. */
  89. static int omap_1510_local_bus_power(int on)
  90. {
  91. if (on) {
  92. omap_writel((1 << 1) | (1 << 0), OMAP1510_LB_MMU_CTL);
  93. udelay(200);
  94. } else {
  95. omap_writel(0, OMAP1510_LB_MMU_CTL);
  96. }
  97. return 0;
  98. }
  99. /*
  100. * OMAP-1510 specific Local Bus initialization
  101. * NOTE: This assumes 32MB memory size in OMAP1510LB_MEMSIZE.
  102. * See also arch/mach-omap/memory.h for __virt_to_dma() and
  103. * __dma_to_virt() which need to match with the physical
  104. * Local Bus address below.
  105. */
  106. static int omap_1510_local_bus_init(void)
  107. {
  108. unsigned int tlb;
  109. unsigned long lbaddr, physaddr;
  110. omap_writel((omap_readl(OMAP1510_LB_CLOCK_DIV) & 0xfffffff8) | 0x4,
  111. OMAP1510_LB_CLOCK_DIV);
  112. /* Configure the Local Bus MMU table */
  113. for (tlb = 0; tlb < OMAP1510_LB_MEMSIZE; tlb++) {
  114. lbaddr = tlb * 0x00100000 + OMAP1510_LB_OFFSET;
  115. physaddr = tlb * 0x00100000 + PHYS_OFFSET;
  116. omap_writel((lbaddr & 0x0fffffff) >> 22, OMAP1510_LB_MMU_CAM_H);
  117. omap_writel(((lbaddr & 0x003ffc00) >> 6) | 0xc,
  118. OMAP1510_LB_MMU_CAM_L);
  119. omap_writel(physaddr >> 16, OMAP1510_LB_MMU_RAM_H);
  120. omap_writel((physaddr & 0x0000fc00) | 0x300, OMAP1510_LB_MMU_RAM_L);
  121. omap_writel(tlb << 4, OMAP1510_LB_MMU_LCK);
  122. omap_writel(0x1, OMAP1510_LB_MMU_LD_TLB);
  123. }
  124. /* Enable the walking table */
  125. omap_writel(omap_readl(OMAP1510_LB_MMU_CTL) | (1 << 3), OMAP1510_LB_MMU_CTL);
  126. udelay(200);
  127. return 0;
  128. }
  129. #ifdef CONFIG_USB_OTG
  130. static void start_hnp(struct ohci_hcd *ohci)
  131. {
  132. const unsigned port = ohci_to_hcd(ohci)->self.otg_port - 1;
  133. unsigned long flags;
  134. otg_start_hnp(ohci->transceiver);
  135. local_irq_save(flags);
  136. ohci->transceiver->state = OTG_STATE_A_SUSPEND;
  137. writel (RH_PS_PSS, &ohci->regs->roothub.portstatus [port]);
  138. OTG_CTRL_REG &= ~OTG_A_BUSREQ;
  139. local_irq_restore(flags);
  140. }
  141. #endif
  142. /*-------------------------------------------------------------------------*/
  143. static int omap_start_hc(struct ohci_hcd *ohci, struct platform_device *pdev)
  144. {
  145. struct omap_usb_config *config = pdev->dev.platform_data;
  146. int need_transceiver = (config->otg != 0);
  147. int ret;
  148. dev_dbg(&pdev->dev, "starting USB Controller\n");
  149. if (config->otg) {
  150. ohci_to_hcd(ohci)->self.otg_port = config->otg;
  151. /* default/minimum OTG power budget: 8 mA */
  152. ohci_to_hcd(ohci)->power_budget = 8;
  153. }
  154. /* boards can use OTG transceivers in non-OTG modes */
  155. need_transceiver = need_transceiver
  156. || machine_is_omap_h2() || machine_is_omap_h3();
  157. if (cpu_is_omap16xx())
  158. ocpi_enable();
  159. #ifdef CONFIG_ARCH_OMAP_OTG
  160. if (need_transceiver) {
  161. ohci->transceiver = otg_get_transceiver();
  162. if (ohci->transceiver) {
  163. int status = otg_set_host(ohci->transceiver,
  164. &ohci_to_hcd(ohci)->self);
  165. dev_dbg(&pdev->dev, "init %s transceiver, status %d\n",
  166. ohci->transceiver->label, status);
  167. if (status) {
  168. if (ohci->transceiver)
  169. put_device(ohci->transceiver->dev);
  170. return status;
  171. }
  172. } else {
  173. dev_err(&pdev->dev, "can't find transceiver\n");
  174. return -ENODEV;
  175. }
  176. }
  177. #endif
  178. omap_ohci_clock_power(1);
  179. if (cpu_is_omap1510()) {
  180. omap_1510_local_bus_power(1);
  181. omap_1510_local_bus_init();
  182. }
  183. if ((ret = ohci_init(ohci)) < 0)
  184. return ret;
  185. /* board-specific power switching and overcurrent support */
  186. if (machine_is_omap_osk() || machine_is_omap_innovator()) {
  187. u32 rh = roothub_a (ohci);
  188. /* power switching (ganged by default) */
  189. rh &= ~RH_A_NPS;
  190. /* TPS2045 switch for internal transceiver (port 1) */
  191. if (machine_is_omap_osk()) {
  192. ohci_to_hcd(ohci)->power_budget = 250;
  193. rh &= ~RH_A_NOCP;
  194. /* gpio9 for overcurrent detction */
  195. omap_cfg_reg(W8_1610_GPIO9);
  196. omap_request_gpio(9);
  197. omap_set_gpio_direction(9, 1 /* IN */);
  198. /* for paranoia's sake: disable USB.PUEN */
  199. omap_cfg_reg(W4_USB_HIGHZ);
  200. }
  201. ohci_writel(ohci, rh, &ohci->regs->roothub.a);
  202. distrust_firmware = 0;
  203. }
  204. /* FIXME khubd hub requests should manage power switching */
  205. omap_ohci_transceiver_power(1);
  206. /* board init will have already handled HMC and mux setup.
  207. * any external transceiver should already be initialized
  208. * too, so all configured ports use the right signaling now.
  209. */
  210. return 0;
  211. }
  212. static void omap_stop_hc(struct platform_device *pdev)
  213. {
  214. dev_dbg(&pdev->dev, "stopping USB Controller\n");
  215. omap_ohci_clock_power(0);
  216. }
  217. /*-------------------------------------------------------------------------*/
  218. void usb_hcd_omap_remove (struct usb_hcd *, struct platform_device *);
  219. /* configure so an HC device and id are always provided */
  220. /* always called with process context; sleeping is OK */
  221. /**
  222. * usb_hcd_omap_probe - initialize OMAP-based HCDs
  223. * Context: !in_interrupt()
  224. *
  225. * Allocates basic resources for this USB host controller, and
  226. * then invokes the start() method for the HCD associated with it
  227. * through the hotplug entry's driver_data.
  228. */
  229. int usb_hcd_omap_probe (const struct hc_driver *driver,
  230. struct platform_device *pdev)
  231. {
  232. int retval;
  233. struct usb_hcd *hcd = 0;
  234. struct ohci_hcd *ohci;
  235. if (pdev->num_resources != 2) {
  236. printk(KERN_ERR "hcd probe: invalid num_resources: %i\n",
  237. pdev->num_resources);
  238. return -ENODEV;
  239. }
  240. if (pdev->resource[0].flags != IORESOURCE_MEM
  241. || pdev->resource[1].flags != IORESOURCE_IRQ) {
  242. printk(KERN_ERR "hcd probe: invalid resource type\n");
  243. return -ENODEV;
  244. }
  245. usb_host_ck = clk_get(0, "usb_hhc_ck");
  246. if (IS_ERR(usb_host_ck))
  247. return PTR_ERR(usb_host_ck);
  248. hcd = usb_create_hcd (driver, &pdev->dev, pdev->dev.bus_id);
  249. if (!hcd) {
  250. retval = -ENOMEM;
  251. goto err0;
  252. }
  253. hcd->rsrc_start = pdev->resource[0].start;
  254. hcd->rsrc_len = pdev->resource[0].end - pdev->resource[0].start + 1;
  255. if (!request_mem_region(hcd->rsrc_start, hcd->rsrc_len, hcd_name)) {
  256. dev_dbg(&pdev->dev, "request_mem_region failed\n");
  257. retval = -EBUSY;
  258. goto err1;
  259. }
  260. hcd->regs = (void __iomem *) (int) IO_ADDRESS(hcd->rsrc_start);
  261. ohci = hcd_to_ohci(hcd);
  262. ohci_hcd_init(ohci);
  263. retval = omap_start_hc(ohci, pdev);
  264. if (retval < 0)
  265. goto err2;
  266. retval = usb_add_hcd(hcd, platform_get_irq(pdev, 0), SA_INTERRUPT);
  267. if (retval == 0)
  268. return retval;
  269. omap_stop_hc(pdev);
  270. err2:
  271. release_mem_region(hcd->rsrc_start, hcd->rsrc_len);
  272. err1:
  273. usb_put_hcd(hcd);
  274. err0:
  275. clk_put(usb_host_ck);
  276. return retval;
  277. }
  278. /* may be called with controller, bus, and devices active */
  279. /**
  280. * usb_hcd_omap_remove - shutdown processing for OMAP-based HCDs
  281. * @dev: USB Host Controller being removed
  282. * Context: !in_interrupt()
  283. *
  284. * Reverses the effect of usb_hcd_omap_probe(), first invoking
  285. * the HCD's stop() method. It is always called from a thread
  286. * context, normally "rmmod", "apmd", or something similar.
  287. *
  288. */
  289. void usb_hcd_omap_remove (struct usb_hcd *hcd, struct platform_device *pdev)
  290. {
  291. usb_remove_hcd(hcd);
  292. if (machine_is_omap_osk())
  293. omap_free_gpio(9);
  294. omap_stop_hc(pdev);
  295. release_mem_region(hcd->rsrc_start, hcd->rsrc_len);
  296. usb_put_hcd(hcd);
  297. clk_put(usb_host_ck);
  298. }
  299. /*-------------------------------------------------------------------------*/
  300. static int __devinit
  301. ohci_omap_start (struct usb_hcd *hcd)
  302. {
  303. struct omap_usb_config *config;
  304. struct ohci_hcd *ohci = hcd_to_ohci (hcd);
  305. int ret;
  306. config = hcd->self.controller->platform_data;
  307. if (config->otg || config->rwc)
  308. writel(OHCI_CTRL_RWC, &ohci->regs->control);
  309. if ((ret = ohci_run (ohci)) < 0) {
  310. dev_err(hcd->self.controller, "can't start\n");
  311. ohci_stop (hcd);
  312. return ret;
  313. }
  314. return 0;
  315. }
  316. /*-------------------------------------------------------------------------*/
  317. static const struct hc_driver ohci_omap_hc_driver = {
  318. .description = hcd_name,
  319. .product_desc = "OMAP OHCI",
  320. .hcd_priv_size = sizeof(struct ohci_hcd),
  321. /*
  322. * generic hardware linkage
  323. */
  324. .irq = ohci_irq,
  325. .flags = HCD_USB11 | HCD_MEMORY,
  326. /*
  327. * basic lifecycle operations
  328. */
  329. .start = ohci_omap_start,
  330. .stop = ohci_stop,
  331. /*
  332. * managing i/o requests and associated device resources
  333. */
  334. .urb_enqueue = ohci_urb_enqueue,
  335. .urb_dequeue = ohci_urb_dequeue,
  336. .endpoint_disable = ohci_endpoint_disable,
  337. /*
  338. * scheduling support
  339. */
  340. .get_frame_number = ohci_get_frame,
  341. /*
  342. * root hub support
  343. */
  344. .hub_status_data = ohci_hub_status_data,
  345. .hub_control = ohci_hub_control,
  346. #ifdef CONFIG_USB_SUSPEND
  347. .hub_suspend = ohci_hub_suspend,
  348. .hub_resume = ohci_hub_resume,
  349. #endif
  350. .start_port_reset = ohci_start_port_reset,
  351. };
  352. /*-------------------------------------------------------------------------*/
  353. static int ohci_hcd_omap_drv_probe(struct device *dev)
  354. {
  355. return usb_hcd_omap_probe(&ohci_omap_hc_driver,
  356. to_platform_device(dev));
  357. }
  358. static int ohci_hcd_omap_drv_remove(struct device *dev)
  359. {
  360. struct platform_device *pdev = to_platform_device(dev);
  361. struct usb_hcd *hcd = dev_get_drvdata(dev);
  362. struct ohci_hcd *ohci = hcd_to_ohci (hcd);
  363. usb_hcd_omap_remove(hcd, pdev);
  364. if (ohci->transceiver) {
  365. (void) otg_set_host(ohci->transceiver, 0);
  366. put_device(ohci->transceiver->dev);
  367. }
  368. dev_set_drvdata(dev, NULL);
  369. return 0;
  370. }
  371. /*-------------------------------------------------------------------------*/
  372. #ifdef CONFIG_PM
  373. static int ohci_omap_suspend(struct device *dev, pm_message_t message, u32 level)
  374. {
  375. struct ohci_hcd *ohci = hcd_to_ohci(dev_get_drvdata(dev));
  376. int status = -EINVAL;
  377. if (level != SUSPEND_POWER_DOWN)
  378. return 0;
  379. down(&ohci_to_hcd(ohci)->self.root_hub->serialize);
  380. status = ohci_hub_suspend(ohci_to_hcd(ohci));
  381. if (status == 0) {
  382. omap_ohci_clock_power(0);
  383. ohci_to_hcd(ohci)->self.root_hub->state =
  384. USB_STATE_SUSPENDED;
  385. ohci_to_hcd(ohci)->state = HC_STATE_SUSPENDED;
  386. dev->power.power_state = PMSG_SUSPEND;
  387. }
  388. up(&ohci_to_hcd(ohci)->self.root_hub->serialize);
  389. return status;
  390. }
  391. static int ohci_omap_resume(struct device *dev, u32 level)
  392. {
  393. struct ohci_hcd *ohci = hcd_to_ohci(dev_get_drvdata(dev));
  394. int status = 0;
  395. if (level != RESUME_POWER_ON)
  396. return 0;
  397. if (time_before(jiffies, ohci->next_statechange))
  398. msleep(5);
  399. ohci->next_statechange = jiffies;
  400. omap_ohci_clock_power(1);
  401. #ifdef CONFIG_USB_SUSPEND
  402. /* get extra cleanup even if remote wakeup isn't in use */
  403. status = usb_resume_device(ohci_to_hcd(ohci)->self.root_hub);
  404. #else
  405. down(&ohci_to_hcd(ohci)->self.root_hub->serialize);
  406. status = ohci_hub_resume(ohci_to_hcd(ohci));
  407. up(&ohci_to_hcd(ohci)->self.root_hub->serialize);
  408. #endif
  409. if (status == 0)
  410. dev->power.power_state = PMSG_ON;
  411. return status;
  412. }
  413. #endif
  414. /*-------------------------------------------------------------------------*/
  415. /*
  416. * Driver definition to register with the OMAP bus
  417. */
  418. static struct device_driver ohci_hcd_omap_driver = {
  419. .name = "ohci",
  420. .bus = &platform_bus_type,
  421. .probe = ohci_hcd_omap_drv_probe,
  422. .remove = ohci_hcd_omap_drv_remove,
  423. #ifdef CONFIG_PM
  424. .suspend = ohci_omap_suspend,
  425. .resume = ohci_omap_resume,
  426. #endif
  427. };
  428. static int __init ohci_hcd_omap_init (void)
  429. {
  430. printk (KERN_DEBUG "%s: " DRIVER_INFO " (OMAP)\n", hcd_name);
  431. if (usb_disabled())
  432. return -ENODEV;
  433. pr_debug("%s: block sizes: ed %Zd td %Zd\n", hcd_name,
  434. sizeof (struct ed), sizeof (struct td));
  435. return driver_register(&ohci_hcd_omap_driver);
  436. }
  437. static void __exit ohci_hcd_omap_cleanup (void)
  438. {
  439. driver_unregister(&ohci_hcd_omap_driver);
  440. }
  441. module_init (ohci_hcd_omap_init);
  442. module_exit (ohci_hcd_omap_cleanup);