host.c 3.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161
  1. /*
  2. * host.c - ChipIdea USB host controller driver
  3. *
  4. * Copyright (c) 2012 Intel Corporation
  5. *
  6. * Author: Alexander Shishkin
  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 version 2 as
  10. * published by the Free Software Foundation.
  11. *
  12. * This program is distributed in the hope that it will be useful,
  13. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  14. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  15. * GNU General Public License for more details.
  16. *
  17. * You should have received a copy of the GNU General Public License
  18. * along with this program; if not, write to the Free Software
  19. * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
  20. */
  21. #include <linux/kernel.h>
  22. #include <linux/usb.h>
  23. #include <linux/usb/hcd.h>
  24. #include <linux/usb/chipidea.h>
  25. #define CHIPIDEA_EHCI
  26. #include "../host/ehci-hcd.c"
  27. #include "ci.h"
  28. #include "bits.h"
  29. #include "host.h"
  30. static int ci_ehci_setup(struct usb_hcd *hcd)
  31. {
  32. struct ehci_hcd *ehci = hcd_to_ehci(hcd);
  33. int ret;
  34. hcd->has_tt = 1;
  35. ret = ehci_setup(hcd);
  36. if (ret)
  37. return ret;
  38. ehci_port_power(ehci, 0);
  39. return ret;
  40. }
  41. static const struct hc_driver ci_ehci_hc_driver = {
  42. .description = "ehci_hcd",
  43. .product_desc = "ChipIdea HDRC EHCI",
  44. .hcd_priv_size = sizeof(struct ehci_hcd),
  45. /*
  46. * generic hardware linkage
  47. */
  48. .irq = ehci_irq,
  49. .flags = HCD_MEMORY | HCD_USB2,
  50. /*
  51. * basic lifecycle operations
  52. */
  53. .reset = ci_ehci_setup,
  54. .start = ehci_run,
  55. .stop = ehci_stop,
  56. .shutdown = ehci_shutdown,
  57. /*
  58. * managing i/o requests and associated device resources
  59. */
  60. .urb_enqueue = ehci_urb_enqueue,
  61. .urb_dequeue = ehci_urb_dequeue,
  62. .endpoint_disable = ehci_endpoint_disable,
  63. .endpoint_reset = ehci_endpoint_reset,
  64. /*
  65. * scheduling support
  66. */
  67. .get_frame_number = ehci_get_frame,
  68. /*
  69. * root hub support
  70. */
  71. .hub_status_data = ehci_hub_status_data,
  72. .hub_control = ehci_hub_control,
  73. .bus_suspend = ehci_bus_suspend,
  74. .bus_resume = ehci_bus_resume,
  75. .relinquish_port = ehci_relinquish_port,
  76. .port_handed_over = ehci_port_handed_over,
  77. .clear_tt_buffer_complete = ehci_clear_tt_buffer_complete,
  78. };
  79. static irqreturn_t host_irq(struct ci13xxx *ci)
  80. {
  81. return usb_hcd_irq(ci->irq, ci->hcd);
  82. }
  83. static int host_start(struct ci13xxx *ci)
  84. {
  85. struct usb_hcd *hcd;
  86. struct ehci_hcd *ehci;
  87. int ret;
  88. if (usb_disabled())
  89. return -ENODEV;
  90. hcd = usb_create_hcd(&ci_ehci_hc_driver, ci->dev, dev_name(ci->dev));
  91. if (!hcd)
  92. return -ENOMEM;
  93. dev_set_drvdata(ci->dev, ci);
  94. hcd->rsrc_start = ci->hw_bank.phys;
  95. hcd->rsrc_len = ci->hw_bank.size;
  96. hcd->regs = ci->hw_bank.abs;
  97. hcd->has_tt = 1;
  98. hcd->power_budget = ci->platdata->power_budget;
  99. hcd->phy = ci->transceiver;
  100. ehci = hcd_to_ehci(hcd);
  101. ehci->caps = ci->hw_bank.cap;
  102. ehci->has_hostpc = ci->hw_bank.lpm;
  103. ret = usb_add_hcd(hcd, 0, 0);
  104. if (ret)
  105. usb_put_hcd(hcd);
  106. else
  107. ci->hcd = hcd;
  108. return ret;
  109. }
  110. static void host_stop(struct ci13xxx *ci)
  111. {
  112. struct usb_hcd *hcd = ci->hcd;
  113. usb_remove_hcd(hcd);
  114. usb_put_hcd(hcd);
  115. }
  116. int ci_hdrc_host_init(struct ci13xxx *ci)
  117. {
  118. struct ci_role_driver *rdrv;
  119. if (!hw_read(ci, CAP_DCCPARAMS, DCCPARAMS_HC))
  120. return -ENXIO;
  121. rdrv = devm_kzalloc(ci->dev, sizeof(struct ci_role_driver), GFP_KERNEL);
  122. if (!rdrv)
  123. return -ENOMEM;
  124. rdrv->start = host_start;
  125. rdrv->stop = host_stop;
  126. rdrv->irq = host_irq;
  127. rdrv->name = "host";
  128. ci->roles[CI_ROLE_HOST] = rdrv;
  129. return 0;
  130. }