host.c 3.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145
  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 const struct hc_driver ci_ehci_hc_driver = {
  31. .description = "ehci_hcd",
  32. .product_desc = "ChipIdea HDRC EHCI",
  33. .hcd_priv_size = sizeof(struct ehci_hcd),
  34. /*
  35. * generic hardware linkage
  36. */
  37. .irq = ehci_irq,
  38. .flags = HCD_MEMORY | HCD_USB2,
  39. /*
  40. * basic lifecycle operations
  41. */
  42. .reset = ehci_setup,
  43. .start = ehci_run,
  44. .stop = ehci_stop,
  45. .shutdown = ehci_shutdown,
  46. /*
  47. * managing i/o requests and associated device resources
  48. */
  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. /*
  54. * scheduling support
  55. */
  56. .get_frame_number = ehci_get_frame,
  57. /*
  58. * root hub support
  59. */
  60. .hub_status_data = ehci_hub_status_data,
  61. .hub_control = ehci_hub_control,
  62. .bus_suspend = ehci_bus_suspend,
  63. .bus_resume = ehci_bus_resume,
  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 irqreturn_t host_irq(struct ci13xxx *ci)
  69. {
  70. return usb_hcd_irq(ci->irq, ci->hcd);
  71. }
  72. static int host_start(struct ci13xxx *ci)
  73. {
  74. struct usb_hcd *hcd;
  75. struct ehci_hcd *ehci;
  76. int ret;
  77. if (usb_disabled())
  78. return -ENODEV;
  79. hcd = usb_create_hcd(&ci_ehci_hc_driver, ci->dev, dev_name(ci->dev));
  80. if (!hcd)
  81. return -ENOMEM;
  82. dev_set_drvdata(ci->dev, ci);
  83. hcd->rsrc_start = ci->hw_bank.phys;
  84. hcd->rsrc_len = ci->hw_bank.size;
  85. hcd->regs = ci->hw_bank.abs;
  86. hcd->has_tt = 1;
  87. hcd->power_budget = ci->platdata->power_budget;
  88. hcd->phy = ci->transceiver;
  89. ehci = hcd_to_ehci(hcd);
  90. ehci->caps = ci->hw_bank.cap;
  91. ehci->has_hostpc = ci->hw_bank.lpm;
  92. ret = usb_add_hcd(hcd, 0, 0);
  93. if (ret)
  94. usb_put_hcd(hcd);
  95. else
  96. ci->hcd = hcd;
  97. return ret;
  98. }
  99. static void host_stop(struct ci13xxx *ci)
  100. {
  101. struct usb_hcd *hcd = ci->hcd;
  102. usb_remove_hcd(hcd);
  103. usb_put_hcd(hcd);
  104. }
  105. int ci_hdrc_host_init(struct ci13xxx *ci)
  106. {
  107. struct ci_role_driver *rdrv;
  108. if (!hw_read(ci, CAP_DCCPARAMS, DCCPARAMS_HC))
  109. return -ENXIO;
  110. rdrv = devm_kzalloc(ci->dev, sizeof(struct ci_role_driver), GFP_KERNEL);
  111. if (!rdrv)
  112. return -ENOMEM;
  113. rdrv->start = host_start;
  114. rdrv->stop = host_stop;
  115. rdrv->irq = host_irq;
  116. rdrv->name = "host";
  117. ci->roles[CI_ROLE_HOST] = rdrv;
  118. return 0;
  119. }