ohci-ssb.c 4.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214
  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. usb_remove_hcd(hcd);
  76. iounmap(hcd->regs);
  77. usb_put_hcd(hcd);
  78. ssb_device_disable(dev, 0);
  79. }
  80. static int ssb_ohci_attach(struct ssb_device *dev)
  81. {
  82. struct ssb_ohci_device *ohcidev;
  83. struct usb_hcd *hcd;
  84. int err = -ENOMEM;
  85. u32 tmp, flags = 0;
  86. if (dev->id.coreid == SSB_DEV_USB11_HOSTDEV)
  87. flags |= SSB_OHCI_TMSLOW_HOSTMODE;
  88. ssb_device_enable(dev, flags);
  89. hcd = usb_create_hcd(&ssb_ohci_hc_driver, dev->dev,
  90. dev_name(dev->dev));
  91. if (!hcd)
  92. goto err_dev_disable;
  93. ohcidev = hcd_to_ssb_ohci(hcd);
  94. ohcidev->enable_flags = flags;
  95. tmp = ssb_read32(dev, SSB_ADMATCH0);
  96. hcd->rsrc_start = ssb_admatch_base(tmp);
  97. hcd->rsrc_len = ssb_admatch_size(tmp);
  98. hcd->regs = ioremap_nocache(hcd->rsrc_start, hcd->rsrc_len);
  99. if (!hcd->regs)
  100. goto err_put_hcd;
  101. err = usb_add_hcd(hcd, dev->irq, IRQF_DISABLED | IRQF_SHARED);
  102. if (err)
  103. goto err_iounmap;
  104. ssb_set_drvdata(dev, hcd);
  105. return err;
  106. err_iounmap:
  107. iounmap(hcd->regs);
  108. err_put_hcd:
  109. usb_put_hcd(hcd);
  110. err_dev_disable:
  111. ssb_device_disable(dev, flags);
  112. return err;
  113. }
  114. static int ssb_ohci_probe(struct ssb_device *dev,
  115. const struct ssb_device_id *id)
  116. {
  117. int err;
  118. u16 chipid_top;
  119. /* USBcores are only connected on embedded devices. */
  120. chipid_top = (dev->bus->chip_id & 0xFF00);
  121. if (chipid_top != 0x4700 && chipid_top != 0x5300)
  122. return -ENODEV;
  123. /* TODO: Probably need checks here; is the core connected? */
  124. if (usb_disabled())
  125. return -ENODEV;
  126. /* We currently always attach SSB_DEV_USB11_HOSTDEV
  127. * as HOST OHCI. If we want to attach it as Client device,
  128. * we must branch here and call into the (yet to
  129. * be written) Client mode driver. Same for remove(). */
  130. err = ssb_ohci_attach(dev);
  131. return err;
  132. }
  133. static void ssb_ohci_remove(struct ssb_device *dev)
  134. {
  135. ssb_ohci_detach(dev);
  136. }
  137. #ifdef CONFIG_PM
  138. static int ssb_ohci_suspend(struct ssb_device *dev, pm_message_t state)
  139. {
  140. ssb_device_disable(dev, 0);
  141. return 0;
  142. }
  143. static int ssb_ohci_resume(struct ssb_device *dev)
  144. {
  145. struct usb_hcd *hcd = ssb_get_drvdata(dev);
  146. struct ssb_ohci_device *ohcidev = hcd_to_ssb_ohci(hcd);
  147. ssb_device_enable(dev, ohcidev->enable_flags);
  148. ohci_finish_controller_resume(hcd);
  149. return 0;
  150. }
  151. #else /* !CONFIG_PM */
  152. #define ssb_ohci_suspend NULL
  153. #define ssb_ohci_resume NULL
  154. #endif /* CONFIG_PM */
  155. static const struct ssb_device_id ssb_ohci_table[] = {
  156. SSB_DEVICE(SSB_VENDOR_BROADCOM, SSB_DEV_USB11_HOSTDEV, SSB_ANY_REV),
  157. SSB_DEVICE(SSB_VENDOR_BROADCOM, SSB_DEV_USB11_HOST, SSB_ANY_REV),
  158. SSB_DEVTABLE_END
  159. };
  160. MODULE_DEVICE_TABLE(ssb, ssb_ohci_table);
  161. static struct ssb_driver ssb_ohci_driver = {
  162. .name = KBUILD_MODNAME,
  163. .id_table = ssb_ohci_table,
  164. .probe = ssb_ohci_probe,
  165. .remove = ssb_ohci_remove,
  166. .suspend = ssb_ohci_suspend,
  167. .resume = ssb_ohci_resume,
  168. };