ohci-omap.c 14 KB

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