ohci-pxa27x.c 8.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359
  1. /*
  2. * OHCI HCD (Host Controller Driver) for USB.
  3. *
  4. * (C) Copyright 1999 Roman Weissgaerber <weissg@vienna.at>
  5. * (C) Copyright 2000-2002 David Brownell <dbrownell@users.sourceforge.net>
  6. * (C) Copyright 2002 Hewlett-Packard Company
  7. *
  8. * Bus Glue for pxa27x
  9. *
  10. * Written by Christopher Hoover <ch@hpl.hp.com>
  11. * Based on fragments of previous driver by Russell King et al.
  12. *
  13. * Modified for LH7A404 from ohci-sa1111.c
  14. * by Durgesh Pattamatta <pattamattad@sharpsec.com>
  15. *
  16. * Modified for pxa27x from ohci-lh7a404.c
  17. * by Nick Bane <nick@cecomputing.co.uk> 26-8-2004
  18. *
  19. * This file is licenced under the GPL.
  20. */
  21. #include <linux/device.h>
  22. #include <linux/signal.h>
  23. #include <linux/platform_device.h>
  24. #include <asm/mach-types.h>
  25. #include <asm/hardware.h>
  26. #include <asm/arch/pxa-regs.h>
  27. #define PMM_NPS_MODE 1
  28. #define PMM_GLOBAL_MODE 2
  29. #define PMM_PERPORT_MODE 3
  30. #define PXA_UHC_MAX_PORTNUM 3
  31. #define UHCRHPS(x) __REG2( 0x4C000050, (x)<<2 )
  32. static int pxa27x_ohci_pmm_state;
  33. /*
  34. PMM_NPS_MODE -- PMM Non-power switching mode
  35. Ports are powered continuously.
  36. PMM_GLOBAL_MODE -- PMM global switching mode
  37. All ports are powered at the same time.
  38. PMM_PERPORT_MODE -- PMM per port switching mode
  39. Ports are powered individually.
  40. */
  41. static int pxa27x_ohci_select_pmm( int mode )
  42. {
  43. pxa27x_ohci_pmm_state = mode;
  44. switch ( mode ) {
  45. case PMM_NPS_MODE:
  46. UHCRHDA |= RH_A_NPS;
  47. break;
  48. case PMM_GLOBAL_MODE:
  49. UHCRHDA &= ~(RH_A_NPS & RH_A_PSM);
  50. break;
  51. case PMM_PERPORT_MODE:
  52. UHCRHDA &= ~(RH_A_NPS);
  53. UHCRHDA |= RH_A_PSM;
  54. /* Set port power control mask bits, only 3 ports. */
  55. UHCRHDB |= (0x7<<17);
  56. break;
  57. default:
  58. printk( KERN_ERR
  59. "Invalid mode %d, set to non-power switch mode.\n",
  60. mode );
  61. pxa27x_ohci_pmm_state = PMM_NPS_MODE;
  62. UHCRHDA |= RH_A_NPS;
  63. }
  64. return 0;
  65. }
  66. extern int usb_disabled(void);
  67. /*-------------------------------------------------------------------------*/
  68. static void pxa27x_start_hc(struct platform_device *dev)
  69. {
  70. pxa_set_cken(CKEN10_USBHOST, 1);
  71. UHCHR |= UHCHR_FHR;
  72. udelay(11);
  73. UHCHR &= ~UHCHR_FHR;
  74. UHCHR |= UHCHR_FSBIR;
  75. while (UHCHR & UHCHR_FSBIR)
  76. cpu_relax();
  77. /* This could be properly abstracted away through the
  78. device data the day more machines are supported and
  79. their differences can be figured out correctly. */
  80. if (machine_is_mainstone()) {
  81. /* setup Port1 GPIO pin. */
  82. pxa_gpio_mode( 88 | GPIO_ALT_FN_1_IN); /* USBHPWR1 */
  83. pxa_gpio_mode( 89 | GPIO_ALT_FN_2_OUT); /* USBHPEN1 */
  84. /* Set the Power Control Polarity Low and Power Sense
  85. Polarity Low to active low. Supply power to USB ports. */
  86. UHCHR = (UHCHR | UHCHR_PCPL | UHCHR_PSPL) &
  87. ~(UHCHR_SSEP1 | UHCHR_SSEP2 | UHCHR_SSEP3 | UHCHR_SSE);
  88. pxa27x_ohci_pmm_state = PMM_PERPORT_MODE;
  89. }
  90. UHCHR &= ~UHCHR_SSE;
  91. UHCHIE = (UHCHIE_UPRIE | UHCHIE_RWIE);
  92. /* Clear any OTG Pin Hold */
  93. if (PSSR & PSSR_OTGPH)
  94. PSSR |= PSSR_OTGPH;
  95. }
  96. static void pxa27x_stop_hc(struct platform_device *dev)
  97. {
  98. UHCHR |= UHCHR_FHR;
  99. udelay(11);
  100. UHCHR &= ~UHCHR_FHR;
  101. UHCCOMS |= 1;
  102. udelay(10);
  103. pxa_set_cken(CKEN10_USBHOST, 0);
  104. }
  105. /*-------------------------------------------------------------------------*/
  106. /* configure so an HC device and id are always provided */
  107. /* always called with process context; sleeping is OK */
  108. /**
  109. * usb_hcd_pxa27x_probe - initialize pxa27x-based HCDs
  110. * Context: !in_interrupt()
  111. *
  112. * Allocates basic resources for this USB host controller, and
  113. * then invokes the start() method for the HCD associated with it
  114. * through the hotplug entry's driver_data.
  115. *
  116. */
  117. int usb_hcd_pxa27x_probe (const struct hc_driver *driver,
  118. struct platform_device *dev)
  119. {
  120. int retval;
  121. struct usb_hcd *hcd;
  122. if (dev->resource[1].flags != IORESOURCE_IRQ) {
  123. pr_debug ("resource[1] is not IORESOURCE_IRQ");
  124. return -ENOMEM;
  125. }
  126. hcd = usb_create_hcd (driver, &dev->dev, "pxa27x");
  127. if (!hcd)
  128. return -ENOMEM;
  129. hcd->rsrc_start = dev->resource[0].start;
  130. hcd->rsrc_len = dev->resource[0].end - dev->resource[0].start + 1;
  131. if (!request_mem_region(hcd->rsrc_start, hcd->rsrc_len, hcd_name)) {
  132. pr_debug("request_mem_region failed");
  133. retval = -EBUSY;
  134. goto err1;
  135. }
  136. hcd->regs = ioremap(hcd->rsrc_start, hcd->rsrc_len);
  137. if (!hcd->regs) {
  138. pr_debug("ioremap failed");
  139. retval = -ENOMEM;
  140. goto err2;
  141. }
  142. pxa27x_start_hc(dev);
  143. /* Select Power Management Mode */
  144. pxa27x_ohci_select_pmm(pxa27x_ohci_pmm_state);
  145. ohci_hcd_init(hcd_to_ohci(hcd));
  146. retval = usb_add_hcd(hcd, dev->resource[1].start, SA_INTERRUPT);
  147. if (retval == 0)
  148. return retval;
  149. pxa27x_stop_hc(dev);
  150. iounmap(hcd->regs);
  151. err2:
  152. release_mem_region(hcd->rsrc_start, hcd->rsrc_len);
  153. err1:
  154. usb_put_hcd(hcd);
  155. return retval;
  156. }
  157. /* may be called without controller electrically present */
  158. /* may be called with controller, bus, and devices active */
  159. /**
  160. * usb_hcd_pxa27x_remove - shutdown processing for pxa27x-based HCDs
  161. * @dev: USB Host Controller being removed
  162. * Context: !in_interrupt()
  163. *
  164. * Reverses the effect of usb_hcd_pxa27x_probe(), first invoking
  165. * the HCD's stop() method. It is always called from a thread
  166. * context, normally "rmmod", "apmd", or something similar.
  167. *
  168. */
  169. void usb_hcd_pxa27x_remove (struct usb_hcd *hcd, struct platform_device *dev)
  170. {
  171. usb_remove_hcd(hcd);
  172. pxa27x_stop_hc(dev);
  173. iounmap(hcd->regs);
  174. release_mem_region(hcd->rsrc_start, hcd->rsrc_len);
  175. usb_put_hcd(hcd);
  176. }
  177. /*-------------------------------------------------------------------------*/
  178. static int __devinit
  179. ohci_pxa27x_start (struct usb_hcd *hcd)
  180. {
  181. struct ohci_hcd *ohci = hcd_to_ohci (hcd);
  182. int ret;
  183. ohci_dbg (ohci, "ohci_pxa27x_start, ohci:%p", ohci);
  184. /* The value of NDP in roothub_a is incorrect on this hardware */
  185. ohci->num_ports = 3;
  186. if ((ret = ohci_init(ohci)) < 0)
  187. return ret;
  188. if ((ret = ohci_run (ohci)) < 0) {
  189. err ("can't start %s", hcd->self.bus_name);
  190. ohci_stop (hcd);
  191. return ret;
  192. }
  193. return 0;
  194. }
  195. /*-------------------------------------------------------------------------*/
  196. static const struct hc_driver ohci_pxa27x_hc_driver = {
  197. .description = hcd_name,
  198. .product_desc = "PXA27x OHCI",
  199. .hcd_priv_size = sizeof(struct ohci_hcd),
  200. /*
  201. * generic hardware linkage
  202. */
  203. .irq = ohci_irq,
  204. .flags = HCD_USB11 | HCD_MEMORY,
  205. /*
  206. * basic lifecycle operations
  207. */
  208. .start = ohci_pxa27x_start,
  209. .stop = ohci_stop,
  210. /*
  211. * managing i/o requests and associated device resources
  212. */
  213. .urb_enqueue = ohci_urb_enqueue,
  214. .urb_dequeue = ohci_urb_dequeue,
  215. .endpoint_disable = ohci_endpoint_disable,
  216. /*
  217. * scheduling support
  218. */
  219. .get_frame_number = ohci_get_frame,
  220. /*
  221. * root hub support
  222. */
  223. .hub_status_data = ohci_hub_status_data,
  224. .hub_control = ohci_hub_control,
  225. #ifdef CONFIG_PM
  226. .bus_suspend = ohci_bus_suspend,
  227. .bus_resume = ohci_bus_resume,
  228. #endif
  229. .start_port_reset = ohci_start_port_reset,
  230. };
  231. /*-------------------------------------------------------------------------*/
  232. static int ohci_hcd_pxa27x_drv_probe(struct device *dev)
  233. {
  234. struct platform_device *pdev = to_platform_device(dev);
  235. int ret;
  236. pr_debug ("In ohci_hcd_pxa27x_drv_probe");
  237. if (usb_disabled())
  238. return -ENODEV;
  239. ret = usb_hcd_pxa27x_probe(&ohci_pxa27x_hc_driver, pdev);
  240. return ret;
  241. }
  242. static int ohci_hcd_pxa27x_drv_remove(struct device *dev)
  243. {
  244. struct platform_device *pdev = to_platform_device(dev);
  245. struct usb_hcd *hcd = dev_get_drvdata(dev);
  246. usb_hcd_pxa27x_remove(hcd, pdev);
  247. return 0;
  248. }
  249. static int ohci_hcd_pxa27x_drv_suspend(struct device *dev, pm_message_t state)
  250. {
  251. // struct platform_device *pdev = to_platform_device(dev);
  252. // struct usb_hcd *hcd = dev_get_drvdata(dev);
  253. printk("%s: not implemented yet\n", __FUNCTION__);
  254. return 0;
  255. }
  256. static int ohci_hcd_pxa27x_drv_resume(struct device *dev)
  257. {
  258. // struct platform_device *pdev = to_platform_device(dev);
  259. // struct usb_hcd *hcd = dev_get_drvdata(dev);
  260. printk("%s: not implemented yet\n", __FUNCTION__);
  261. return 0;
  262. }
  263. static struct device_driver ohci_hcd_pxa27x_driver = {
  264. .name = "pxa27x-ohci",
  265. .bus = &platform_bus_type,
  266. .probe = ohci_hcd_pxa27x_drv_probe,
  267. .remove = ohci_hcd_pxa27x_drv_remove,
  268. .suspend = ohci_hcd_pxa27x_drv_suspend,
  269. .resume = ohci_hcd_pxa27x_drv_resume,
  270. };
  271. static int __init ohci_hcd_pxa27x_init (void)
  272. {
  273. pr_debug (DRIVER_INFO " (pxa27x)");
  274. pr_debug ("block sizes: ed %d td %d\n",
  275. sizeof (struct ed), sizeof (struct td));
  276. return driver_register(&ohci_hcd_pxa27x_driver);
  277. }
  278. static void __exit ohci_hcd_pxa27x_cleanup (void)
  279. {
  280. driver_unregister(&ohci_hcd_pxa27x_driver);
  281. }
  282. module_init (ohci_hcd_pxa27x_init);
  283. module_exit (ohci_hcd_pxa27x_cleanup);