ohci-ssb.c 6.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261
  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. static const struct hc_driver ssb_ohci_hc_driver = {
  51. .description = "ssb-usb-ohci",
  52. .product_desc = "SSB OHCI Controller",
  53. .hcd_priv_size = sizeof(struct ssb_ohci_device),
  54. .irq = ohci_irq,
  55. .flags = HCD_MEMORY | HCD_USB11,
  56. .reset = ssb_ohci_reset,
  57. .start = ssb_ohci_start,
  58. .stop = ohci_stop,
  59. .shutdown = ohci_shutdown,
  60. .urb_enqueue = ohci_urb_enqueue,
  61. .urb_dequeue = ohci_urb_dequeue,
  62. .endpoint_disable = ohci_endpoint_disable,
  63. .get_frame_number = ohci_get_frame,
  64. .hub_status_data = ohci_hub_status_data,
  65. .hub_control = ohci_hub_control,
  66. #ifdef CONFIG_PM
  67. .bus_suspend = ohci_bus_suspend,
  68. .bus_resume = ohci_bus_resume,
  69. #endif
  70. .start_port_reset = ohci_start_port_reset,
  71. };
  72. static void ssb_ohci_detach(struct ssb_device *dev)
  73. {
  74. struct usb_hcd *hcd = ssb_get_drvdata(dev);
  75. if (hcd->driver->shutdown)
  76. hcd->driver->shutdown(hcd);
  77. usb_remove_hcd(hcd);
  78. iounmap(hcd->regs);
  79. release_mem_region(hcd->rsrc_start, hcd->rsrc_len);
  80. usb_put_hcd(hcd);
  81. ssb_device_disable(dev, 0);
  82. }
  83. static int ssb_ohci_attach(struct ssb_device *dev)
  84. {
  85. struct ssb_ohci_device *ohcidev;
  86. struct usb_hcd *hcd;
  87. int err = -ENOMEM;
  88. u32 tmp, flags = 0;
  89. if (dma_set_mask(dev->dma_dev, DMA_BIT_MASK(32)) ||
  90. dma_set_coherent_mask(dev->dma_dev, DMA_BIT_MASK(32)))
  91. return -EOPNOTSUPP;
  92. if (dev->id.coreid == SSB_DEV_USB11_HOSTDEV) {
  93. /* Put the device into host-mode. */
  94. flags |= SSB_OHCI_TMSLOW_HOSTMODE;
  95. ssb_device_enable(dev, flags);
  96. } else if (dev->id.coreid == SSB_DEV_USB20_HOST) {
  97. /*
  98. * USB 2.0 special considerations:
  99. *
  100. * In addition to the standard SSB reset sequence, the Host
  101. * Control Register must be programmed to bring the USB core
  102. * and various phy components out of reset.
  103. */
  104. ssb_device_enable(dev, 0);
  105. ssb_write32(dev, 0x200, 0x7ff);
  106. /* Change Flush control reg */
  107. tmp = ssb_read32(dev, 0x400);
  108. tmp &= ~8;
  109. ssb_write32(dev, 0x400, tmp);
  110. tmp = ssb_read32(dev, 0x400);
  111. /* Change Shim control reg */
  112. tmp = ssb_read32(dev, 0x304);
  113. tmp &= ~0x100;
  114. ssb_write32(dev, 0x304, tmp);
  115. tmp = ssb_read32(dev, 0x304);
  116. udelay(1);
  117. /* Work around for 5354 failures */
  118. if (dev->id.revision == 2 && dev->bus->chip_id == 0x5354) {
  119. /* Change syn01 reg */
  120. tmp = 0x00fe00fe;
  121. ssb_write32(dev, 0x894, tmp);
  122. /* Change syn03 reg */
  123. tmp = ssb_read32(dev, 0x89c);
  124. tmp |= 0x1;
  125. ssb_write32(dev, 0x89c, tmp);
  126. }
  127. } else
  128. ssb_device_enable(dev, 0);
  129. hcd = usb_create_hcd(&ssb_ohci_hc_driver, dev->dev,
  130. dev_name(dev->dev));
  131. if (!hcd)
  132. goto err_dev_disable;
  133. ohcidev = hcd_to_ssb_ohci(hcd);
  134. ohcidev->enable_flags = flags;
  135. tmp = ssb_read32(dev, SSB_ADMATCH0);
  136. hcd->rsrc_start = ssb_admatch_base(tmp);
  137. hcd->rsrc_len = ssb_admatch_size(tmp);
  138. hcd->regs = ioremap_nocache(hcd->rsrc_start, hcd->rsrc_len);
  139. if (!hcd->regs)
  140. goto err_put_hcd;
  141. err = usb_add_hcd(hcd, dev->irq, IRQF_DISABLED | IRQF_SHARED);
  142. if (err)
  143. goto err_iounmap;
  144. ssb_set_drvdata(dev, hcd);
  145. return err;
  146. err_iounmap:
  147. iounmap(hcd->regs);
  148. err_put_hcd:
  149. usb_put_hcd(hcd);
  150. err_dev_disable:
  151. ssb_device_disable(dev, flags);
  152. return err;
  153. }
  154. static int ssb_ohci_probe(struct ssb_device *dev,
  155. const struct ssb_device_id *id)
  156. {
  157. int err;
  158. u16 chipid_top;
  159. /* USBcores are only connected on embedded devices. */
  160. chipid_top = (dev->bus->chip_id & 0xFF00);
  161. if (chipid_top != 0x4700 && chipid_top != 0x5300)
  162. return -ENODEV;
  163. /* TODO: Probably need checks here; is the core connected? */
  164. if (usb_disabled())
  165. return -ENODEV;
  166. /* We currently always attach SSB_DEV_USB11_HOSTDEV
  167. * as HOST OHCI. If we want to attach it as Client device,
  168. * we must branch here and call into the (yet to
  169. * be written) Client mode driver. Same for remove(). */
  170. err = ssb_ohci_attach(dev);
  171. return err;
  172. }
  173. static void ssb_ohci_remove(struct ssb_device *dev)
  174. {
  175. ssb_ohci_detach(dev);
  176. }
  177. #ifdef CONFIG_PM
  178. static int ssb_ohci_suspend(struct ssb_device *dev, pm_message_t state)
  179. {
  180. ssb_device_disable(dev, 0);
  181. return 0;
  182. }
  183. static int ssb_ohci_resume(struct ssb_device *dev)
  184. {
  185. struct usb_hcd *hcd = ssb_get_drvdata(dev);
  186. struct ssb_ohci_device *ohcidev = hcd_to_ssb_ohci(hcd);
  187. ssb_device_enable(dev, ohcidev->enable_flags);
  188. ohci_finish_controller_resume(hcd);
  189. return 0;
  190. }
  191. #else /* !CONFIG_PM */
  192. #define ssb_ohci_suspend NULL
  193. #define ssb_ohci_resume NULL
  194. #endif /* CONFIG_PM */
  195. static const struct ssb_device_id ssb_ohci_table[] = {
  196. SSB_DEVICE(SSB_VENDOR_BROADCOM, SSB_DEV_USB11_HOSTDEV, SSB_ANY_REV),
  197. SSB_DEVICE(SSB_VENDOR_BROADCOM, SSB_DEV_USB11_HOST, SSB_ANY_REV),
  198. SSB_DEVICE(SSB_VENDOR_BROADCOM, SSB_DEV_USB20_HOST, SSB_ANY_REV),
  199. SSB_DEVTABLE_END
  200. };
  201. MODULE_DEVICE_TABLE(ssb, ssb_ohci_table);
  202. static struct ssb_driver ssb_ohci_driver = {
  203. .name = KBUILD_MODNAME,
  204. .id_table = ssb_ohci_table,
  205. .probe = ssb_ohci_probe,
  206. .remove = ssb_ohci_remove,
  207. .suspend = ssb_ohci_suspend,
  208. .resume = ssb_ohci_resume,
  209. };