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