ehci-cns3xxx.c 4.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167
  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. hcd->has_tt = 0;
  33. retval = ehci_setup(hcd);
  34. if (retval)
  35. return retval;
  36. ehci_port_power(ehci, 0);
  37. return retval;
  38. }
  39. static const struct hc_driver cns3xxx_ehci_hc_driver = {
  40. .description = hcd_name,
  41. .product_desc = "CNS3XXX EHCI Host Controller",
  42. .hcd_priv_size = sizeof(struct ehci_hcd),
  43. .irq = ehci_irq,
  44. .flags = HCD_MEMORY | HCD_USB2,
  45. .reset = cns3xxx_ehci_init,
  46. .start = ehci_run,
  47. .stop = ehci_stop,
  48. .shutdown = ehci_shutdown,
  49. .urb_enqueue = ehci_urb_enqueue,
  50. .urb_dequeue = ehci_urb_dequeue,
  51. .endpoint_disable = ehci_endpoint_disable,
  52. .endpoint_reset = ehci_endpoint_reset,
  53. .get_frame_number = ehci_get_frame,
  54. .hub_status_data = ehci_hub_status_data,
  55. .hub_control = ehci_hub_control,
  56. #ifdef CONFIG_PM
  57. .bus_suspend = ehci_bus_suspend,
  58. .bus_resume = ehci_bus_resume,
  59. #endif
  60. .relinquish_port = ehci_relinquish_port,
  61. .port_handed_over = ehci_port_handed_over,
  62. .clear_tt_buffer_complete = ehci_clear_tt_buffer_complete,
  63. };
  64. static int cns3xxx_ehci_probe(struct platform_device *pdev)
  65. {
  66. struct device *dev = &pdev->dev;
  67. struct usb_hcd *hcd;
  68. const struct hc_driver *driver = &cns3xxx_ehci_hc_driver;
  69. struct resource *res;
  70. int irq;
  71. int retval;
  72. if (usb_disabled())
  73. return -ENODEV;
  74. res = platform_get_resource(pdev, IORESOURCE_IRQ, 0);
  75. if (!res) {
  76. dev_err(dev, "Found HC with no IRQ.\n");
  77. return -ENODEV;
  78. }
  79. irq = res->start;
  80. hcd = usb_create_hcd(driver, &pdev->dev, dev_name(&pdev->dev));
  81. if (!hcd)
  82. return -ENOMEM;
  83. res = platform_get_resource(pdev, IORESOURCE_MEM, 0);
  84. if (!res) {
  85. dev_err(dev, "Found HC with no register addr.\n");
  86. retval = -ENODEV;
  87. goto err1;
  88. }
  89. hcd->rsrc_start = res->start;
  90. hcd->rsrc_len = resource_size(res);
  91. if (!request_mem_region(hcd->rsrc_start, hcd->rsrc_len,
  92. driver->description)) {
  93. dev_dbg(dev, "controller already in use\n");
  94. retval = -EBUSY;
  95. goto err1;
  96. }
  97. hcd->regs = ioremap(hcd->rsrc_start, hcd->rsrc_len);
  98. if (hcd->regs == NULL) {
  99. dev_dbg(dev, "error mapping memory\n");
  100. retval = -EFAULT;
  101. goto err2;
  102. }
  103. retval = usb_add_hcd(hcd, irq, IRQF_SHARED);
  104. if (retval == 0)
  105. return retval;
  106. iounmap(hcd->regs);
  107. err2:
  108. release_mem_region(hcd->rsrc_start, hcd->rsrc_len);
  109. err1:
  110. usb_put_hcd(hcd);
  111. return retval;
  112. }
  113. static int cns3xxx_ehci_remove(struct platform_device *pdev)
  114. {
  115. struct usb_hcd *hcd = platform_get_drvdata(pdev);
  116. usb_remove_hcd(hcd);
  117. iounmap(hcd->regs);
  118. release_mem_region(hcd->rsrc_start, hcd->rsrc_len);
  119. /*
  120. * EHCI and OHCI share the same clock and power,
  121. * resetting twice would cause the 1st controller been reset.
  122. * Therefore only do power up at the first up device, and
  123. * power down at the last down device.
  124. */
  125. if (atomic_dec_return(&usb_pwr_ref) == 0)
  126. cns3xxx_pwr_clk_dis(1 << PM_CLK_GATE_REG_OFFSET_USB_HOST);
  127. usb_put_hcd(hcd);
  128. platform_set_drvdata(pdev, NULL);
  129. return 0;
  130. }
  131. MODULE_ALIAS("platform:cns3xxx-ehci");
  132. static struct platform_driver cns3xxx_ehci_driver = {
  133. .probe = cns3xxx_ehci_probe,
  134. .remove = cns3xxx_ehci_remove,
  135. .driver = {
  136. .name = "cns3xxx-ehci",
  137. },
  138. };