ehci-cns3xxx.c 4.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172
  1. /*
  2. * Copyright 2008 Cavium Networks
  3. *
  4. * This file is free software; you can redistribute it and/or modify
  5. * it under the terms of the GNU General Public License, Version 2, as
  6. * published by the Free Software Foundation.
  7. */
  8. #include <linux/platform_device.h>
  9. #include <linux/atomic.h>
  10. #include <mach/cns3xxx.h>
  11. #include <mach/pm.h>
  12. static int cns3xxx_ehci_init(struct usb_hcd *hcd)
  13. {
  14. struct ehci_hcd *ehci = hcd_to_ehci(hcd);
  15. int retval;
  16. /*
  17. * EHCI and OHCI share the same clock and power,
  18. * resetting twice would cause the 1st controller been reset.
  19. * Therefore only do power up at the first up device, and
  20. * power down at the last down device.
  21. *
  22. * Set USB AHB INCR length to 16
  23. */
  24. if (atomic_inc_return(&usb_pwr_ref) == 1) {
  25. cns3xxx_pwr_power_up(1 << PM_PLL_HM_PD_CTRL_REG_OFFSET_PLL_USB);
  26. cns3xxx_pwr_clk_en(1 << PM_CLK_GATE_REG_OFFSET_USB_HOST);
  27. cns3xxx_pwr_soft_rst(1 << PM_SOFT_RST_REG_OFFST_USB_HOST);
  28. __raw_writel((__raw_readl(MISC_CHIP_CONFIG_REG) | (0X2 << 24)),
  29. MISC_CHIP_CONFIG_REG);
  30. }
  31. ehci->caps = hcd->regs;
  32. ehci->regs = hcd->regs
  33. + HC_LENGTH(ehci, ehci_readl(ehci, &ehci->caps->hc_capbase));
  34. ehci->hcs_params = ehci_readl(ehci, &ehci->caps->hcs_params);
  35. hcd->has_tt = 0;
  36. ehci_reset(ehci);
  37. retval = ehci_init(hcd);
  38. if (retval)
  39. return retval;
  40. ehci_port_power(ehci, 0);
  41. return retval;
  42. }
  43. static const struct hc_driver cns3xxx_ehci_hc_driver = {
  44. .description = hcd_name,
  45. .product_desc = "CNS3XXX EHCI Host Controller",
  46. .hcd_priv_size = sizeof(struct ehci_hcd),
  47. .irq = ehci_irq,
  48. .flags = HCD_MEMORY | HCD_USB2,
  49. .reset = cns3xxx_ehci_init,
  50. .start = ehci_run,
  51. .stop = ehci_stop,
  52. .shutdown = ehci_shutdown,
  53. .urb_enqueue = ehci_urb_enqueue,
  54. .urb_dequeue = ehci_urb_dequeue,
  55. .endpoint_disable = ehci_endpoint_disable,
  56. .endpoint_reset = ehci_endpoint_reset,
  57. .get_frame_number = ehci_get_frame,
  58. .hub_status_data = ehci_hub_status_data,
  59. .hub_control = ehci_hub_control,
  60. #ifdef CONFIG_PM
  61. .bus_suspend = ehci_bus_suspend,
  62. .bus_resume = ehci_bus_resume,
  63. #endif
  64. .relinquish_port = ehci_relinquish_port,
  65. .port_handed_over = ehci_port_handed_over,
  66. .clear_tt_buffer_complete = ehci_clear_tt_buffer_complete,
  67. };
  68. static int cns3xxx_ehci_probe(struct platform_device *pdev)
  69. {
  70. struct device *dev = &pdev->dev;
  71. struct usb_hcd *hcd;
  72. const struct hc_driver *driver = &cns3xxx_ehci_hc_driver;
  73. struct resource *res;
  74. int irq;
  75. int retval;
  76. if (usb_disabled())
  77. return -ENODEV;
  78. res = platform_get_resource(pdev, IORESOURCE_IRQ, 0);
  79. if (!res) {
  80. dev_err(dev, "Found HC with no IRQ.\n");
  81. return -ENODEV;
  82. }
  83. irq = res->start;
  84. hcd = usb_create_hcd(driver, &pdev->dev, dev_name(&pdev->dev));
  85. if (!hcd)
  86. return -ENOMEM;
  87. res = platform_get_resource(pdev, IORESOURCE_MEM, 0);
  88. if (!res) {
  89. dev_err(dev, "Found HC with no register addr.\n");
  90. retval = -ENODEV;
  91. goto err1;
  92. }
  93. hcd->rsrc_start = res->start;
  94. hcd->rsrc_len = resource_size(res);
  95. if (!request_mem_region(hcd->rsrc_start, hcd->rsrc_len,
  96. driver->description)) {
  97. dev_dbg(dev, "controller already in use\n");
  98. retval = -EBUSY;
  99. goto err1;
  100. }
  101. hcd->regs = ioremap(hcd->rsrc_start, hcd->rsrc_len);
  102. if (hcd->regs == NULL) {
  103. dev_dbg(dev, "error mapping memory\n");
  104. retval = -EFAULT;
  105. goto err2;
  106. }
  107. retval = usb_add_hcd(hcd, irq, IRQF_SHARED);
  108. if (retval == 0)
  109. return retval;
  110. iounmap(hcd->regs);
  111. err2:
  112. release_mem_region(hcd->rsrc_start, hcd->rsrc_len);
  113. err1:
  114. usb_put_hcd(hcd);
  115. return retval;
  116. }
  117. static int cns3xxx_ehci_remove(struct platform_device *pdev)
  118. {
  119. struct usb_hcd *hcd = platform_get_drvdata(pdev);
  120. usb_remove_hcd(hcd);
  121. iounmap(hcd->regs);
  122. release_mem_region(hcd->rsrc_start, hcd->rsrc_len);
  123. /*
  124. * EHCI and OHCI share the same clock and power,
  125. * resetting twice would cause the 1st controller been reset.
  126. * Therefore only do power up at the first up device, and
  127. * power down at the last down device.
  128. */
  129. if (atomic_dec_return(&usb_pwr_ref) == 0)
  130. cns3xxx_pwr_clk_dis(1 << PM_CLK_GATE_REG_OFFSET_USB_HOST);
  131. usb_put_hcd(hcd);
  132. platform_set_drvdata(pdev, NULL);
  133. return 0;
  134. }
  135. MODULE_ALIAS("platform:cns3xxx-ehci");
  136. static struct platform_driver cns3xxx_ehci_driver = {
  137. .probe = cns3xxx_ehci_probe,
  138. .remove = cns3xxx_ehci_remove,
  139. .driver = {
  140. .name = "cns3xxx-ehci",
  141. },
  142. };