host.c 3.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136
  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/io.h>
  23. #include <linux/usb.h>
  24. #include <linux/usb/hcd.h>
  25. #include <linux/usb/chipidea.h>
  26. #include <linux/regulator/consumer.h>
  27. #include "../host/ehci.h"
  28. #include "ci.h"
  29. #include "bits.h"
  30. #include "host.h"
  31. static struct hc_driver __read_mostly ci_ehci_hc_driver;
  32. static irqreturn_t host_irq(struct ci_hdrc *ci)
  33. {
  34. return usb_hcd_irq(ci->irq, ci->hcd);
  35. }
  36. static int host_start(struct ci_hdrc *ci)
  37. {
  38. struct usb_hcd *hcd;
  39. struct ehci_hcd *ehci;
  40. int ret;
  41. if (usb_disabled())
  42. return -ENODEV;
  43. hcd = usb_create_hcd(&ci_ehci_hc_driver, ci->dev, dev_name(ci->dev));
  44. if (!hcd)
  45. return -ENOMEM;
  46. dev_set_drvdata(ci->dev, ci);
  47. hcd->rsrc_start = ci->hw_bank.phys;
  48. hcd->rsrc_len = ci->hw_bank.size;
  49. hcd->regs = ci->hw_bank.abs;
  50. hcd->has_tt = 1;
  51. hcd->power_budget = ci->platdata->power_budget;
  52. hcd->phy = ci->transceiver;
  53. ehci = hcd_to_ehci(hcd);
  54. ehci->caps = ci->hw_bank.cap;
  55. ehci->has_hostpc = ci->hw_bank.lpm;
  56. ehci->has_tdi_phy_lpm = ci->hw_bank.lpm;
  57. if (ci->platdata->reg_vbus) {
  58. ret = regulator_enable(ci->platdata->reg_vbus);
  59. if (ret) {
  60. dev_err(ci->dev,
  61. "Failed to enable vbus regulator, ret=%d\n",
  62. ret);
  63. goto put_hcd;
  64. }
  65. }
  66. ret = usb_add_hcd(hcd, 0, 0);
  67. if (ret)
  68. goto disable_reg;
  69. else
  70. ci->hcd = hcd;
  71. if (ci->platdata->flags & CI_HDRC_DISABLE_STREAMING)
  72. hw_write(ci, OP_USBMODE, USBMODE_CI_SDIS, USBMODE_CI_SDIS);
  73. return ret;
  74. disable_reg:
  75. regulator_disable(ci->platdata->reg_vbus);
  76. put_hcd:
  77. usb_put_hcd(hcd);
  78. return ret;
  79. }
  80. static void host_stop(struct ci_hdrc *ci)
  81. {
  82. struct usb_hcd *hcd = ci->hcd;
  83. usb_remove_hcd(hcd);
  84. usb_put_hcd(hcd);
  85. if (ci->platdata->reg_vbus)
  86. regulator_disable(ci->platdata->reg_vbus);
  87. }
  88. void ci_hdrc_host_destroy(struct ci_hdrc *ci)
  89. {
  90. if (ci->role == CI_ROLE_HOST)
  91. host_stop(ci);
  92. }
  93. int ci_hdrc_host_init(struct ci_hdrc *ci)
  94. {
  95. struct ci_role_driver *rdrv;
  96. if (!hw_read(ci, CAP_DCCPARAMS, DCCPARAMS_HC))
  97. return -ENXIO;
  98. rdrv = devm_kzalloc(ci->dev, sizeof(struct ci_role_driver), GFP_KERNEL);
  99. if (!rdrv)
  100. return -ENOMEM;
  101. rdrv->start = host_start;
  102. rdrv->stop = host_stop;
  103. rdrv->irq = host_irq;
  104. rdrv->name = "host";
  105. ci->roles[CI_ROLE_HOST] = rdrv;
  106. ehci_init_driver(&ci_ehci_hc_driver, NULL);
  107. return 0;
  108. }