host.c 2.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104
  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. return ret;
  61. }
  62. static void host_stop(struct ci13xxx *ci)
  63. {
  64. struct usb_hcd *hcd = ci->hcd;
  65. usb_remove_hcd(hcd);
  66. usb_put_hcd(hcd);
  67. }
  68. int ci_hdrc_host_init(struct ci13xxx *ci)
  69. {
  70. struct ci_role_driver *rdrv;
  71. if (!hw_read(ci, CAP_DCCPARAMS, DCCPARAMS_HC))
  72. return -ENXIO;
  73. rdrv = devm_kzalloc(ci->dev, sizeof(struct ci_role_driver), GFP_KERNEL);
  74. if (!rdrv)
  75. return -ENOMEM;
  76. rdrv->start = host_start;
  77. rdrv->stop = host_stop;
  78. rdrv->irq = host_irq;
  79. rdrv->name = "host";
  80. ci->roles[CI_ROLE_HOST] = rdrv;
  81. ehci_init_driver(&ci_ehci_hc_driver, NULL);
  82. return 0;
  83. }