ohci-cns3xxx.c 3.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166
  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 __devinit
  13. cns3xxx_ohci_start(struct usb_hcd *hcd)
  14. {
  15. struct ohci_hcd *ohci = hcd_to_ohci(hcd);
  16. int ret;
  17. /*
  18. * EHCI and OHCI share the same clock and power,
  19. * resetting twice would cause the 1st controller been reset.
  20. * Therefore only do power up at the first up device, and
  21. * power down at the last down device.
  22. *
  23. * Set USB AHB INCR length to 16
  24. */
  25. if (atomic_inc_return(&usb_pwr_ref) == 1) {
  26. cns3xxx_pwr_power_up(1 << PM_PLL_HM_PD_CTRL_REG_OFFSET_PLL_USB);
  27. cns3xxx_pwr_clk_en(1 << PM_CLK_GATE_REG_OFFSET_USB_HOST);
  28. cns3xxx_pwr_soft_rst(1 << PM_SOFT_RST_REG_OFFST_USB_HOST);
  29. __raw_writel((__raw_readl(MISC_CHIP_CONFIG_REG) | (0X2 << 24)),
  30. MISC_CHIP_CONFIG_REG);
  31. }
  32. ret = ohci_init(ohci);
  33. if (ret < 0)
  34. return ret;
  35. ohci->num_ports = 1;
  36. ret = ohci_run(ohci);
  37. if (ret < 0) {
  38. err("can't start %s", hcd->self.bus_name);
  39. ohci_stop(hcd);
  40. return ret;
  41. }
  42. return 0;
  43. }
  44. static const struct hc_driver cns3xxx_ohci_hc_driver = {
  45. .description = hcd_name,
  46. .product_desc = "CNS3XXX OHCI Host controller",
  47. .hcd_priv_size = sizeof(struct ohci_hcd),
  48. .irq = ohci_irq,
  49. .flags = HCD_USB11 | HCD_MEMORY,
  50. .start = cns3xxx_ohci_start,
  51. .stop = ohci_stop,
  52. .shutdown = ohci_shutdown,
  53. .urb_enqueue = ohci_urb_enqueue,
  54. .urb_dequeue = ohci_urb_dequeue,
  55. .endpoint_disable = ohci_endpoint_disable,
  56. .get_frame_number = ohci_get_frame,
  57. .hub_status_data = ohci_hub_status_data,
  58. .hub_control = ohci_hub_control,
  59. #ifdef CONFIG_PM
  60. .bus_suspend = ohci_bus_suspend,
  61. .bus_resume = ohci_bus_resume,
  62. #endif
  63. .start_port_reset = ohci_start_port_reset,
  64. };
  65. static int cns3xxx_ohci_probe(struct platform_device *pdev)
  66. {
  67. struct device *dev = &pdev->dev;
  68. struct usb_hcd *hcd;
  69. const struct hc_driver *driver = &cns3xxx_ohci_hc_driver;
  70. struct resource *res;
  71. int irq;
  72. int retval;
  73. if (usb_disabled())
  74. return -ENODEV;
  75. res = platform_get_resource(pdev, IORESOURCE_IRQ, 0);
  76. if (!res) {
  77. dev_err(dev, "Found HC with no IRQ.\n");
  78. return -ENODEV;
  79. }
  80. irq = res->start;
  81. hcd = usb_create_hcd(driver, dev, dev_name(dev));
  82. if (!hcd)
  83. return -ENOMEM;
  84. res = platform_get_resource(pdev, IORESOURCE_MEM, 0);
  85. if (!res) {
  86. dev_err(dev, "Found HC with no register addr.\n");
  87. retval = -ENODEV;
  88. goto err1;
  89. }
  90. hcd->rsrc_start = res->start;
  91. hcd->rsrc_len = resource_size(res);
  92. if (!request_mem_region(hcd->rsrc_start, hcd->rsrc_len,
  93. driver->description)) {
  94. dev_dbg(dev, "controller already in use\n");
  95. retval = -EBUSY;
  96. goto err1;
  97. }
  98. hcd->regs = ioremap(hcd->rsrc_start, hcd->rsrc_len);
  99. if (!hcd->regs) {
  100. dev_dbg(dev, "error mapping memory\n");
  101. retval = -EFAULT;
  102. goto err2;
  103. }
  104. ohci_hcd_init(hcd_to_ohci(hcd));
  105. retval = usb_add_hcd(hcd, irq, IRQF_SHARED);
  106. if (retval == 0)
  107. return retval;
  108. iounmap(hcd->regs);
  109. err2:
  110. release_mem_region(hcd->rsrc_start, hcd->rsrc_len);
  111. err1:
  112. usb_put_hcd(hcd);
  113. return retval;
  114. }
  115. static int cns3xxx_ohci_remove(struct platform_device *pdev)
  116. {
  117. struct usb_hcd *hcd = platform_get_drvdata(pdev);
  118. usb_remove_hcd(hcd);
  119. iounmap(hcd->regs);
  120. release_mem_region(hcd->rsrc_start, hcd->rsrc_len);
  121. /*
  122. * EHCI and OHCI share the same clock and power,
  123. * resetting twice would cause the 1st controller been reset.
  124. * Therefore only do power up at the first up device, and
  125. * power down at the last down device.
  126. */
  127. if (atomic_dec_return(&usb_pwr_ref) == 0)
  128. cns3xxx_pwr_clk_dis(1 << PM_CLK_GATE_REG_OFFSET_USB_HOST);
  129. usb_put_hcd(hcd);
  130. platform_set_drvdata(pdev, NULL);
  131. return 0;
  132. }
  133. MODULE_ALIAS("platform:cns3xxx-ohci");
  134. static struct platform_driver ohci_hcd_cns3xxx_driver = {
  135. .probe = cns3xxx_ohci_probe,
  136. .remove = cns3xxx_ohci_remove,
  137. .driver = {
  138. .name = "cns3xxx-ohci",
  139. },
  140. };