host.c 2.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107
  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 "../host/ehci.h"
  27. #include "ci.h"
  28. #include "bits.h"
  29. #include "host.h"
  30. static struct hc_driver __read_mostly ci_ehci_hc_driver;
  31. static irqreturn_t host_irq(struct ci13xxx *ci)
  32. {
  33. return usb_hcd_irq(ci->irq, ci->hcd);
  34. }
  35. static int host_start(struct ci13xxx *ci)
  36. {
  37. struct usb_hcd *hcd;
  38. struct ehci_hcd *ehci;
  39. int ret;
  40. if (usb_disabled())
  41. return -ENODEV;
  42. hcd = usb_create_hcd(&ci_ehci_hc_driver, ci->dev, dev_name(ci->dev));
  43. if (!hcd)
  44. return -ENOMEM;
  45. dev_set_drvdata(ci->dev, ci);
  46. hcd->rsrc_start = ci->hw_bank.phys;
  47. hcd->rsrc_len = ci->hw_bank.size;
  48. hcd->regs = ci->hw_bank.abs;
  49. hcd->has_tt = 1;
  50. hcd->power_budget = ci->platdata->power_budget;
  51. hcd->phy = ci->transceiver;
  52. ehci = hcd_to_ehci(hcd);
  53. ehci->caps = ci->hw_bank.cap;
  54. ehci->has_hostpc = ci->hw_bank.lpm;
  55. ret = usb_add_hcd(hcd, 0, 0);
  56. if (ret)
  57. usb_put_hcd(hcd);
  58. else
  59. ci->hcd = hcd;
  60. if (ci->platdata->flags & CI13XXX_DISABLE_STREAMING)
  61. hw_write(ci, OP_USBMODE, USBMODE_CI_SDIS, USBMODE_CI_SDIS);
  62. return ret;
  63. }
  64. static void host_stop(struct ci13xxx *ci)
  65. {
  66. struct usb_hcd *hcd = ci->hcd;
  67. usb_remove_hcd(hcd);
  68. usb_put_hcd(hcd);
  69. }
  70. int ci_hdrc_host_init(struct ci13xxx *ci)
  71. {
  72. struct ci_role_driver *rdrv;
  73. if (!hw_read(ci, CAP_DCCPARAMS, DCCPARAMS_HC))
  74. return -ENXIO;
  75. rdrv = devm_kzalloc(ci->dev, sizeof(struct ci_role_driver), GFP_KERNEL);
  76. if (!rdrv)
  77. return -ENOMEM;
  78. rdrv->start = host_start;
  79. rdrv->stop = host_stop;
  80. rdrv->irq = host_irq;
  81. rdrv->name = "host";
  82. ci->roles[CI_ROLE_HOST] = rdrv;
  83. ehci_init_driver(&ci_ehci_hc_driver, NULL);
  84. return 0;
  85. }