ohci-pxa27x.c 9.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383
  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. /*
  65. If you select PMM_PERPORT_MODE, you should set the port power
  66. */
  67. static int pxa27x_ohci_set_port_power( int port )
  68. {
  69. if ( (pxa27x_ohci_pmm_state==PMM_PERPORT_MODE)
  70. && (port>0) && (port<PXA_UHC_MAX_PORTNUM) ) {
  71. UHCRHPS(port) |= 0x100;
  72. return 0;
  73. }
  74. return -1;
  75. }
  76. /*
  77. If you select PMM_PERPORT_MODE, you should set the port power
  78. */
  79. static int pxa27x_ohci_clear_port_power( int port )
  80. {
  81. if ( (pxa27x_ohci_pmm_state==PMM_PERPORT_MODE)
  82. && (port>0) && (port<PXA_UHC_MAX_PORTNUM) ) {
  83. UHCRHPS(port) |= 0x200;
  84. return 0;
  85. }
  86. return -1;
  87. }
  88. extern int usb_disabled(void);
  89. /*-------------------------------------------------------------------------*/
  90. static void pxa27x_start_hc(struct platform_device *dev)
  91. {
  92. pxa_set_cken(CKEN10_USBHOST, 1);
  93. UHCHR |= UHCHR_FHR;
  94. udelay(11);
  95. UHCHR &= ~UHCHR_FHR;
  96. UHCHR |= UHCHR_FSBIR;
  97. while (UHCHR & UHCHR_FSBIR)
  98. cpu_relax();
  99. /* This could be properly abstracted away through the
  100. device data the day more machines are supported and
  101. their differences can be figured out correctly. */
  102. if (machine_is_mainstone()) {
  103. /* setup Port1 GPIO pin. */
  104. pxa_gpio_mode( 88 | GPIO_ALT_FN_1_IN); /* USBHPWR1 */
  105. pxa_gpio_mode( 89 | GPIO_ALT_FN_2_OUT); /* USBHPEN1 */
  106. /* Set the Power Control Polarity Low and Power Sense
  107. Polarity Low to active low. Supply power to USB ports. */
  108. UHCHR = (UHCHR | UHCHR_PCPL | UHCHR_PSPL) &
  109. ~(UHCHR_SSEP1 | UHCHR_SSEP2 | UHCHR_SSEP3 | UHCHR_SSE);
  110. }
  111. UHCHR &= ~UHCHR_SSE;
  112. UHCHIE = (UHCHIE_UPRIE | UHCHIE_RWIE);
  113. }
  114. static void pxa27x_stop_hc(struct platform_device *dev)
  115. {
  116. UHCHR |= UHCHR_FHR;
  117. udelay(11);
  118. UHCHR &= ~UHCHR_FHR;
  119. UHCCOMS |= 1;
  120. udelay(10);
  121. pxa_set_cken(CKEN10_USBHOST, 0);
  122. }
  123. /*-------------------------------------------------------------------------*/
  124. /* configure so an HC device and id are always provided */
  125. /* always called with process context; sleeping is OK */
  126. /**
  127. * usb_hcd_pxa27x_probe - initialize pxa27x-based HCDs
  128. * Context: !in_interrupt()
  129. *
  130. * Allocates basic resources for this USB host controller, and
  131. * then invokes the start() method for the HCD associated with it
  132. * through the hotplug entry's driver_data.
  133. *
  134. */
  135. int usb_hcd_pxa27x_probe (const struct hc_driver *driver,
  136. struct platform_device *dev)
  137. {
  138. int retval;
  139. struct usb_hcd *hcd;
  140. if (dev->resource[1].flags != IORESOURCE_IRQ) {
  141. pr_debug ("resource[1] is not IORESOURCE_IRQ");
  142. return -ENOMEM;
  143. }
  144. hcd = usb_create_hcd (driver, &dev->dev, "pxa27x");
  145. if (!hcd)
  146. return -ENOMEM;
  147. hcd->rsrc_start = dev->resource[0].start;
  148. hcd->rsrc_len = dev->resource[0].end - dev->resource[0].start + 1;
  149. if (!request_mem_region(hcd->rsrc_start, hcd->rsrc_len, hcd_name)) {
  150. pr_debug("request_mem_region failed");
  151. retval = -EBUSY;
  152. goto err1;
  153. }
  154. hcd->regs = ioremap(hcd->rsrc_start, hcd->rsrc_len);
  155. if (!hcd->regs) {
  156. pr_debug("ioremap failed");
  157. retval = -ENOMEM;
  158. goto err2;
  159. }
  160. pxa27x_start_hc(dev);
  161. /* Select Power Management Mode */
  162. pxa27x_ohci_select_pmm( PMM_PERPORT_MODE );
  163. /* If choosing PMM_PERPORT_MODE, we should set the port power before we use it. */
  164. if (pxa27x_ohci_set_port_power(1) < 0)
  165. printk(KERN_ERR "Setting port 1 power failed.\n");
  166. if (pxa27x_ohci_clear_port_power(2) < 0)
  167. printk(KERN_ERR "Setting port 2 power failed.\n");
  168. if (pxa27x_ohci_clear_port_power(3) < 0)
  169. printk(KERN_ERR "Setting port 3 power failed.\n");
  170. ohci_hcd_init(hcd_to_ohci(hcd));
  171. retval = usb_add_hcd(hcd, dev->resource[1].start, SA_INTERRUPT);
  172. if (retval == 0)
  173. return retval;
  174. pxa27x_stop_hc(dev);
  175. iounmap(hcd->regs);
  176. err2:
  177. release_mem_region(hcd->rsrc_start, hcd->rsrc_len);
  178. err1:
  179. usb_put_hcd(hcd);
  180. return retval;
  181. }
  182. /* may be called without controller electrically present */
  183. /* may be called with controller, bus, and devices active */
  184. /**
  185. * usb_hcd_pxa27x_remove - shutdown processing for pxa27x-based HCDs
  186. * @dev: USB Host Controller being removed
  187. * Context: !in_interrupt()
  188. *
  189. * Reverses the effect of usb_hcd_pxa27x_probe(), first invoking
  190. * the HCD's stop() method. It is always called from a thread
  191. * context, normally "rmmod", "apmd", or something similar.
  192. *
  193. */
  194. void usb_hcd_pxa27x_remove (struct usb_hcd *hcd, struct platform_device *dev)
  195. {
  196. usb_remove_hcd(hcd);
  197. pxa27x_stop_hc(dev);
  198. iounmap(hcd->regs);
  199. release_mem_region(hcd->rsrc_start, hcd->rsrc_len);
  200. usb_put_hcd(hcd);
  201. }
  202. /*-------------------------------------------------------------------------*/
  203. static int __devinit
  204. ohci_pxa27x_start (struct usb_hcd *hcd)
  205. {
  206. struct ohci_hcd *ohci = hcd_to_ohci (hcd);
  207. int ret;
  208. ohci_dbg (ohci, "ohci_pxa27x_start, ohci:%p", ohci);
  209. if ((ret = ohci_init(ohci)) < 0)
  210. return ret;
  211. if ((ret = ohci_run (ohci)) < 0) {
  212. err ("can't start %s", hcd->self.bus_name);
  213. ohci_stop (hcd);
  214. return ret;
  215. }
  216. return 0;
  217. }
  218. /*-------------------------------------------------------------------------*/
  219. static const struct hc_driver ohci_pxa27x_hc_driver = {
  220. .description = hcd_name,
  221. .product_desc = "PXA27x OHCI",
  222. .hcd_priv_size = sizeof(struct ohci_hcd),
  223. /*
  224. * generic hardware linkage
  225. */
  226. .irq = ohci_irq,
  227. .flags = HCD_USB11 | HCD_MEMORY,
  228. /*
  229. * basic lifecycle operations
  230. */
  231. .start = ohci_pxa27x_start,
  232. .stop = ohci_stop,
  233. /*
  234. * managing i/o requests and associated device resources
  235. */
  236. .urb_enqueue = ohci_urb_enqueue,
  237. .urb_dequeue = ohci_urb_dequeue,
  238. .endpoint_disable = ohci_endpoint_disable,
  239. /*
  240. * scheduling support
  241. */
  242. .get_frame_number = ohci_get_frame,
  243. /*
  244. * root hub support
  245. */
  246. .hub_status_data = ohci_hub_status_data,
  247. .hub_control = ohci_hub_control,
  248. #ifdef CONFIG_USB_SUSPEND
  249. .hub_suspend = ohci_hub_suspend,
  250. .hub_resume = ohci_hub_resume,
  251. #endif
  252. };
  253. /*-------------------------------------------------------------------------*/
  254. static int ohci_hcd_pxa27x_drv_probe(struct device *dev)
  255. {
  256. struct platform_device *pdev = to_platform_device(dev);
  257. int ret;
  258. pr_debug ("In ohci_hcd_pxa27x_drv_probe");
  259. if (usb_disabled())
  260. return -ENODEV;
  261. ret = usb_hcd_pxa27x_probe(&ohci_pxa27x_hc_driver, pdev);
  262. return ret;
  263. }
  264. static int ohci_hcd_pxa27x_drv_remove(struct device *dev)
  265. {
  266. struct platform_device *pdev = to_platform_device(dev);
  267. struct usb_hcd *hcd = dev_get_drvdata(dev);
  268. usb_hcd_pxa27x_remove(hcd, pdev);
  269. return 0;
  270. }
  271. static int ohci_hcd_pxa27x_drv_suspend(struct device *dev, pm_message_t state, u32 level)
  272. {
  273. // struct platform_device *pdev = to_platform_device(dev);
  274. // struct usb_hcd *hcd = dev_get_drvdata(dev);
  275. printk("%s: not implemented yet\n", __FUNCTION__);
  276. return 0;
  277. }
  278. static int ohci_hcd_pxa27x_drv_resume(struct device *dev, u32 level)
  279. {
  280. // struct platform_device *pdev = to_platform_device(dev);
  281. // struct usb_hcd *hcd = dev_get_drvdata(dev);
  282. printk("%s: not implemented yet\n", __FUNCTION__);
  283. return 0;
  284. }
  285. static struct device_driver ohci_hcd_pxa27x_driver = {
  286. .name = "pxa27x-ohci",
  287. .bus = &platform_bus_type,
  288. .probe = ohci_hcd_pxa27x_drv_probe,
  289. .remove = ohci_hcd_pxa27x_drv_remove,
  290. .suspend = ohci_hcd_pxa27x_drv_suspend,
  291. .resume = ohci_hcd_pxa27x_drv_resume,
  292. };
  293. static int __init ohci_hcd_pxa27x_init (void)
  294. {
  295. pr_debug (DRIVER_INFO " (pxa27x)");
  296. pr_debug ("block sizes: ed %d td %d\n",
  297. sizeof (struct ed), sizeof (struct td));
  298. return driver_register(&ohci_hcd_pxa27x_driver);
  299. }
  300. static void __exit ohci_hcd_pxa27x_cleanup (void)
  301. {
  302. driver_unregister(&ohci_hcd_pxa27x_driver);
  303. }
  304. module_init (ohci_hcd_pxa27x_init);
  305. module_exit (ohci_hcd_pxa27x_cleanup);