ohci-pxa27x.c 8.3 KB

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