ohci-ssb.c 5.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249
  1. /*
  2. * Sonics Silicon Backplane
  3. * Broadcom USB-core OHCI driver
  4. *
  5. * Copyright 2007 Michael Buesch <mb@bu3sch.de>
  6. *
  7. * Derived from the OHCI-PCI driver
  8. * Copyright 1999 Roman Weissgaerber
  9. * Copyright 2000-2002 David Brownell
  10. * Copyright 1999 Linus Torvalds
  11. * Copyright 1999 Gregory P. Smith
  12. *
  13. * Derived from the USBcore related parts of Broadcom-SB
  14. * Copyright 2005 Broadcom Corporation
  15. *
  16. * Licensed under the GNU/GPL. See COPYING for details.
  17. */
  18. #include <linux/ssb/ssb.h>
  19. #define SSB_OHCI_TMSLOW_HOSTMODE (1 << 29)
  20. struct ssb_ohci_device {
  21. struct ohci_hcd ohci; /* _must_ be at the beginning. */
  22. u32 enable_flags;
  23. };
  24. static inline
  25. struct ssb_ohci_device *hcd_to_ssb_ohci(struct usb_hcd *hcd)
  26. {
  27. return (struct ssb_ohci_device *)(hcd->hcd_priv);
  28. }
  29. static int ssb_ohci_reset(struct usb_hcd *hcd)
  30. {
  31. struct ssb_ohci_device *ohcidev = hcd_to_ssb_ohci(hcd);
  32. struct ohci_hcd *ohci = &ohcidev->ohci;
  33. int err;
  34. ohci_hcd_init(ohci);
  35. err = ohci_init(ohci);
  36. return err;
  37. }
  38. static int ssb_ohci_start(struct usb_hcd *hcd)
  39. {
  40. struct ssb_ohci_device *ohcidev = hcd_to_ssb_ohci(hcd);
  41. struct ohci_hcd *ohci = &ohcidev->ohci;
  42. int err;
  43. err = ohci_run(ohci);
  44. if (err < 0) {
  45. ohci_err(ohci, "can't start\n");
  46. ohci_stop(hcd);
  47. }
  48. return err;
  49. }
  50. #ifdef CONFIG_PM
  51. static int ssb_ohci_hcd_suspend(struct usb_hcd *hcd, pm_message_t message)
  52. {
  53. struct ssb_ohci_device *ohcidev = hcd_to_ssb_ohci(hcd);
  54. struct ohci_hcd *ohci = &ohcidev->ohci;
  55. unsigned long flags;
  56. spin_lock_irqsave(&ohci->lock, flags);
  57. ohci_writel(ohci, OHCI_INTR_MIE, &ohci->regs->intrdisable);
  58. ohci_readl(ohci, &ohci->regs->intrdisable); /* commit write */
  59. /* make sure snapshot being resumed re-enumerates everything */
  60. if (message.event == PM_EVENT_PRETHAW)
  61. ohci_usb_reset(ohci);
  62. clear_bit(HCD_FLAG_HW_ACCESSIBLE, &hcd->flags);
  63. spin_unlock_irqrestore(&ohci->lock, flags);
  64. return 0;
  65. }
  66. static int ssb_ohci_hcd_resume(struct usb_hcd *hcd)
  67. {
  68. set_bit(HCD_FLAG_HW_ACCESSIBLE, &hcd->flags);
  69. usb_hcd_resume_root_hub(hcd);
  70. return 0;
  71. }
  72. #endif /* CONFIG_PM */
  73. static const struct hc_driver ssb_ohci_hc_driver = {
  74. .description = "ssb-usb-ohci",
  75. .product_desc = "SSB OHCI Controller",
  76. .hcd_priv_size = sizeof(struct ssb_ohci_device),
  77. .irq = ohci_irq,
  78. .flags = HCD_MEMORY | HCD_USB11,
  79. .reset = ssb_ohci_reset,
  80. .start = ssb_ohci_start,
  81. .stop = ohci_stop,
  82. .shutdown = ohci_shutdown,
  83. #ifdef CONFIG_PM
  84. .suspend = ssb_ohci_hcd_suspend,
  85. .resume = ssb_ohci_hcd_resume,
  86. #endif
  87. .urb_enqueue = ohci_urb_enqueue,
  88. .urb_dequeue = ohci_urb_dequeue,
  89. .endpoint_disable = ohci_endpoint_disable,
  90. .get_frame_number = ohci_get_frame,
  91. .hub_status_data = ohci_hub_status_data,
  92. .hub_control = ohci_hub_control,
  93. .hub_irq_enable = ohci_rhsc_enable,
  94. #ifdef CONFIG_PM
  95. .bus_suspend = ohci_bus_suspend,
  96. .bus_resume = ohci_bus_resume,
  97. #endif
  98. .start_port_reset = ohci_start_port_reset,
  99. };
  100. static void ssb_ohci_detach(struct ssb_device *dev)
  101. {
  102. struct usb_hcd *hcd = ssb_get_drvdata(dev);
  103. usb_remove_hcd(hcd);
  104. iounmap(hcd->regs);
  105. usb_put_hcd(hcd);
  106. ssb_device_disable(dev, 0);
  107. }
  108. static int ssb_ohci_attach(struct ssb_device *dev)
  109. {
  110. struct ssb_ohci_device *ohcidev;
  111. struct usb_hcd *hcd;
  112. int err = -ENOMEM;
  113. u32 tmp, flags = 0;
  114. if (dev->id.coreid == SSB_DEV_USB11_HOSTDEV)
  115. flags |= SSB_OHCI_TMSLOW_HOSTMODE;
  116. ssb_device_enable(dev, flags);
  117. hcd = usb_create_hcd(&ssb_ohci_hc_driver, dev->dev,
  118. dev->dev->bus_id);
  119. if (!hcd)
  120. goto err_dev_disable;
  121. ohcidev = hcd_to_ssb_ohci(hcd);
  122. ohcidev->enable_flags = flags;
  123. tmp = ssb_read32(dev, SSB_ADMATCH0);
  124. hcd->rsrc_start = ssb_admatch_base(tmp);
  125. hcd->rsrc_len = ssb_admatch_size(tmp);
  126. hcd->regs = ioremap_nocache(hcd->rsrc_start, hcd->rsrc_len);
  127. if (!hcd->regs)
  128. goto err_put_hcd;
  129. err = usb_add_hcd(hcd, dev->irq, IRQF_SHARED);
  130. if (err)
  131. goto err_iounmap;
  132. ssb_set_drvdata(dev, hcd);
  133. return err;
  134. err_iounmap:
  135. iounmap(hcd->regs);
  136. err_put_hcd:
  137. usb_put_hcd(hcd);
  138. err_dev_disable:
  139. ssb_device_disable(dev, flags);
  140. return err;
  141. }
  142. static int ssb_ohci_probe(struct ssb_device *dev,
  143. const struct ssb_device_id *id)
  144. {
  145. int err;
  146. u16 chipid_top;
  147. /* USBcores are only connected on embedded devices. */
  148. chipid_top = (dev->bus->chip_id & 0xFF00);
  149. if (chipid_top != 0x4700 && chipid_top != 0x5300)
  150. return -ENODEV;
  151. /* TODO: Probably need checks here; is the core connected? */
  152. if (usb_disabled())
  153. return -ENODEV;
  154. /* We currently always attach SSB_DEV_USB11_HOSTDEV
  155. * as HOST OHCI. If we want to attach it as Client device,
  156. * we must branch here and call into the (yet to
  157. * be written) Client mode driver. Same for remove(). */
  158. err = ssb_ohci_attach(dev);
  159. return err;
  160. }
  161. static void ssb_ohci_remove(struct ssb_device *dev)
  162. {
  163. ssb_ohci_detach(dev);
  164. }
  165. #ifdef CONFIG_PM
  166. static int ssb_ohci_suspend(struct ssb_device *dev, pm_message_t state)
  167. {
  168. ssb_device_disable(dev, 0);
  169. return 0;
  170. }
  171. static int ssb_ohci_resume(struct ssb_device *dev)
  172. {
  173. struct usb_hcd *hcd = ssb_get_drvdata(dev);
  174. struct ssb_ohci_device *ohcidev = hcd_to_ssb_ohci(hcd);
  175. ssb_device_enable(dev, ohcidev->enable_flags);
  176. return 0;
  177. }
  178. #else /* !CONFIG_PM */
  179. #define ssb_ohci_suspend NULL
  180. #define ssb_ohci_resume NULL
  181. #endif /* CONFIG_PM */
  182. static const struct ssb_device_id ssb_ohci_table[] = {
  183. SSB_DEVICE(SSB_VENDOR_BROADCOM, SSB_DEV_USB11_HOSTDEV, SSB_ANY_REV),
  184. SSB_DEVICE(SSB_VENDOR_BROADCOM, SSB_DEV_USB11_HOST, SSB_ANY_REV),
  185. SSB_DEVTABLE_END
  186. };
  187. MODULE_DEVICE_TABLE(ssb, ssb_ohci_table);
  188. static struct ssb_driver ssb_ohci_driver = {
  189. .name = KBUILD_MODNAME,
  190. .id_table = ssb_ohci_table,
  191. .probe = ssb_ohci_probe,
  192. .remove = ssb_ohci_remove,
  193. .suspend = ssb_ohci_suspend,
  194. .resume = ssb_ohci_resume,
  195. };