ehci-w90x900.c 4.0 KB

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