ehci-w90x900.c 3.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179
  1. /*
  2. * linux/driver/usb/host/ehci-w90x900.c
  3. *
  4. * Copyright (c) 2008 Nuvoton technology corporation.
  5. *
  6. * Wan ZongShun <mcuos.com@gmail.com>
  7. *
  8. * This program is free software; you can redistribute it and/or modify
  9. * it under the terms of the GNU General Public License as published by
  10. * the Free Software Foundation;version 2 of the License.
  11. *
  12. */
  13. #include <linux/platform_device.h>
  14. /* enable phy0 and phy1 for w90p910 */
  15. #define ENPHY (0x01<<8)
  16. #define PHY0_CTR (0xA4)
  17. #define PHY1_CTR (0xA8)
  18. static int usb_w90x900_probe(const struct hc_driver *driver,
  19. struct platform_device *pdev)
  20. {
  21. struct usb_hcd *hcd;
  22. struct ehci_hcd *ehci;
  23. struct resource *res;
  24. int retval = 0, irq;
  25. unsigned long val;
  26. res = platform_get_resource(pdev, IORESOURCE_MEM, 0);
  27. if (!res) {
  28. retval = -ENXIO;
  29. goto err1;
  30. }
  31. hcd = usb_create_hcd(driver, &pdev->dev, "w90x900 EHCI");
  32. if (!hcd) {
  33. retval = -ENOMEM;
  34. goto err1;
  35. }
  36. hcd->rsrc_start = res->start;
  37. hcd->rsrc_len = resource_size(res);
  38. if (!request_mem_region(hcd->rsrc_start, hcd->rsrc_len, hcd_name)) {
  39. retval = -EBUSY;
  40. goto err2;
  41. }
  42. hcd->regs = ioremap(hcd->rsrc_start, hcd->rsrc_len);
  43. if (hcd->regs == NULL) {
  44. retval = -EFAULT;
  45. goto err3;
  46. }
  47. ehci = hcd_to_ehci(hcd);
  48. ehci->caps = hcd->regs;
  49. ehci->regs = hcd->regs +
  50. HC_LENGTH(ehci, ehci_readl(ehci, &ehci->caps->hc_capbase));
  51. /* enable PHY 0,1,the regs only apply to w90p910
  52. * 0xA4,0xA8 were offsets of PHY0 and PHY1 controller of
  53. * w90p910 IC relative to ehci->regs.
  54. */
  55. val = __raw_readl(ehci->regs+PHY0_CTR);
  56. val |= ENPHY;
  57. __raw_writel(val, ehci->regs+PHY0_CTR);
  58. val = __raw_readl(ehci->regs+PHY1_CTR);
  59. val |= ENPHY;
  60. __raw_writel(val, ehci->regs+PHY1_CTR);
  61. irq = platform_get_irq(pdev, 0);
  62. if (irq < 0)
  63. goto err4;
  64. retval = usb_add_hcd(hcd, irq, IRQF_SHARED);
  65. if (retval != 0)
  66. goto err4;
  67. return retval;
  68. err4:
  69. iounmap(hcd->regs);
  70. err3:
  71. release_mem_region(hcd->rsrc_start, hcd->rsrc_len);
  72. err2:
  73. usb_put_hcd(hcd);
  74. err1:
  75. return retval;
  76. }
  77. static
  78. void usb_w90x900_remove(struct usb_hcd *hcd, struct platform_device *pdev)
  79. {
  80. usb_remove_hcd(hcd);
  81. iounmap(hcd->regs);
  82. release_mem_region(hcd->rsrc_start, hcd->rsrc_len);
  83. usb_put_hcd(hcd);
  84. }
  85. static const struct hc_driver ehci_w90x900_hc_driver = {
  86. .description = hcd_name,
  87. .product_desc = "Nuvoton w90x900 EHCI Host Controller",
  88. .hcd_priv_size = sizeof(struct ehci_hcd),
  89. /*
  90. * generic hardware linkage
  91. */
  92. .irq = ehci_irq,
  93. .flags = HCD_USB2|HCD_MEMORY,
  94. /*
  95. * basic lifecycle operations
  96. */
  97. .reset = ehci_setup,
  98. .start = ehci_run,
  99. .stop = ehci_stop,
  100. .shutdown = ehci_shutdown,
  101. /*
  102. * managing i/o requests and associated device resources
  103. */
  104. .urb_enqueue = ehci_urb_enqueue,
  105. .urb_dequeue = ehci_urb_dequeue,
  106. .endpoint_disable = ehci_endpoint_disable,
  107. .endpoint_reset = ehci_endpoint_reset,
  108. /*
  109. * scheduling support
  110. */
  111. .get_frame_number = ehci_get_frame,
  112. /*
  113. * root hub support
  114. */
  115. .hub_status_data = ehci_hub_status_data,
  116. .hub_control = ehci_hub_control,
  117. #ifdef CONFIG_PM
  118. .bus_suspend = ehci_bus_suspend,
  119. .bus_resume = ehci_bus_resume,
  120. #endif
  121. .relinquish_port = ehci_relinquish_port,
  122. .port_handed_over = ehci_port_handed_over,
  123. .clear_tt_buffer_complete = ehci_clear_tt_buffer_complete,
  124. };
  125. static int ehci_w90x900_probe(struct platform_device *pdev)
  126. {
  127. if (usb_disabled())
  128. return -ENODEV;
  129. return usb_w90x900_probe(&ehci_w90x900_hc_driver, pdev);
  130. }
  131. static int ehci_w90x900_remove(struct platform_device *pdev)
  132. {
  133. struct usb_hcd *hcd = platform_get_drvdata(pdev);
  134. usb_w90x900_remove(hcd, pdev);
  135. return 0;
  136. }
  137. static struct platform_driver ehci_hcd_w90x900_driver = {
  138. .probe = ehci_w90x900_probe,
  139. .remove = ehci_w90x900_remove,
  140. .driver = {
  141. .name = "w90x900-ehci",
  142. .owner = THIS_MODULE,
  143. },
  144. };
  145. MODULE_AUTHOR("Wan ZongShun <mcuos.com@gmail.com>");
  146. MODULE_DESCRIPTION("w90p910 usb ehci driver!");
  147. MODULE_LICENSE("GPL");
  148. MODULE_ALIAS("platform:w90p910-ehci");