ehci-w90x900.c 4.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185
  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. /*ebable phy0 and phy1 for w90p910*/
  15. #define ENPHY (0x01<<8)
  16. #define PHY0_CTR (0xA4)
  17. #define PHY1_CTR (0xA8)
  18. static int __devinit 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 = res->end - res->start + 1;
  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. ehci->hcs_params = ehci_readl(ehci, &ehci->caps->hcs_params);
  62. ehci->sbrn = 0x20;
  63. irq = platform_get_irq(pdev, 0);
  64. if (irq < 0)
  65. goto err4;
  66. retval = usb_add_hcd(hcd, irq, IRQF_SHARED);
  67. if (retval != 0)
  68. goto err4;
  69. ehci_writel(ehci, 1, &ehci->regs->configured_flag);
  70. return retval;
  71. err4:
  72. iounmap(hcd->regs);
  73. err3:
  74. release_mem_region(hcd->rsrc_start, hcd->rsrc_len);
  75. err2:
  76. usb_put_hcd(hcd);
  77. err1:
  78. return retval;
  79. }
  80. static
  81. void usb_w90x900_remove(struct usb_hcd *hcd, struct platform_device *pdev)
  82. {
  83. usb_remove_hcd(hcd);
  84. iounmap(hcd->regs);
  85. release_mem_region(hcd->rsrc_start, hcd->rsrc_len);
  86. usb_put_hcd(hcd);
  87. }
  88. static const struct hc_driver ehci_w90x900_hc_driver = {
  89. .description = hcd_name,
  90. .product_desc = "Nuvoton w90x900 EHCI Host Controller",
  91. .hcd_priv_size = sizeof(struct ehci_hcd),
  92. /*
  93. * generic hardware linkage
  94. */
  95. .irq = ehci_irq,
  96. .flags = HCD_USB2|HCD_MEMORY,
  97. /*
  98. * basic lifecycle operations
  99. */
  100. .reset = ehci_init,
  101. .start = ehci_run,
  102. .stop = ehci_stop,
  103. .shutdown = ehci_shutdown,
  104. /*
  105. * managing i/o requests and associated device resources
  106. */
  107. .urb_enqueue = ehci_urb_enqueue,
  108. .urb_dequeue = ehci_urb_dequeue,
  109. .endpoint_disable = ehci_endpoint_disable,
  110. .endpoint_reset = ehci_endpoint_reset,
  111. /*
  112. * scheduling support
  113. */
  114. .get_frame_number = ehci_get_frame,
  115. /*
  116. * root hub support
  117. */
  118. .hub_status_data = ehci_hub_status_data,
  119. .hub_control = ehci_hub_control,
  120. #ifdef CONFIG_PM
  121. .bus_suspend = ehci_bus_suspend,
  122. .bus_resume = ehci_bus_resume,
  123. #endif
  124. .relinquish_port = ehci_relinquish_port,
  125. .port_handed_over = ehci_port_handed_over,
  126. .clear_tt_buffer_complete = ehci_clear_tt_buffer_complete,
  127. };
  128. static int __devinit ehci_w90x900_probe(struct platform_device *pdev)
  129. {
  130. if (usb_disabled())
  131. return -ENODEV;
  132. return usb_w90x900_probe(&ehci_w90x900_hc_driver, pdev);
  133. }
  134. static int __devexit ehci_w90x900_remove(struct platform_device *pdev)
  135. {
  136. struct usb_hcd *hcd = platform_get_drvdata(pdev);
  137. usb_w90x900_remove(hcd, pdev);
  138. return 0;
  139. }
  140. static struct platform_driver ehci_hcd_w90x900_driver = {
  141. .probe = ehci_w90x900_probe,
  142. .remove = __devexit_p(ehci_w90x900_remove),
  143. .driver = {
  144. .name = "w90x900-ehci",
  145. .owner = THIS_MODULE,
  146. },
  147. };
  148. MODULE_AUTHOR("Wan ZongShun <mcuos.com@gmail.com>");
  149. MODULE_DESCRIPTION("w90p910 usb ehci driver!");
  150. MODULE_LICENSE("GPL");
  151. MODULE_ALIAS("platform:w90p910-ehci");