ehci-npcm7xx.c 3.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154
  1. // SPDX-License-Identifier: GPL-2.0
  2. /*
  3. * Nuvoton NPCM7xx driver for EHCI HCD
  4. *
  5. * Copyright (C) 2018 Nuvoton Technologies,
  6. * Avi Fishman <avi.fishman@nuvoton.com> <avifishman70@gmail.com>
  7. * Tomer Maimon <tomer.maimon@nuvoton.com> <tmaimon77@gmail.com>
  8. *
  9. * Based on various ehci-spear.c driver
  10. */
  11. #include <linux/dma-mapping.h>
  12. #include <linux/kernel.h>
  13. #include <linux/module.h>
  14. #include <linux/of.h>
  15. #include <linux/platform_device.h>
  16. #include <linux/pm.h>
  17. #include <linux/usb.h>
  18. #include <linux/usb/hcd.h>
  19. #include "ehci.h"
  20. #define DRIVER_DESC "EHCI npcm7xx driver"
  21. static struct hc_driver __read_mostly ehci_npcm7xx_hc_driver;
  22. static int __maybe_unused ehci_npcm7xx_drv_suspend(struct device *dev)
  23. {
  24. struct usb_hcd *hcd = dev_get_drvdata(dev);
  25. bool do_wakeup = device_may_wakeup(dev);
  26. return ehci_suspend(hcd, do_wakeup);
  27. }
  28. static int __maybe_unused ehci_npcm7xx_drv_resume(struct device *dev)
  29. {
  30. struct usb_hcd *hcd = dev_get_drvdata(dev);
  31. ehci_resume(hcd, false);
  32. return 0;
  33. }
  34. static SIMPLE_DEV_PM_OPS(ehci_npcm7xx_pm_ops, ehci_npcm7xx_drv_suspend,
  35. ehci_npcm7xx_drv_resume);
  36. static int npcm7xx_ehci_hcd_drv_probe(struct platform_device *pdev)
  37. {
  38. struct usb_hcd *hcd;
  39. struct resource *res;
  40. const struct hc_driver *driver = &ehci_npcm7xx_hc_driver;
  41. int irq;
  42. int retval;
  43. dev_dbg(&pdev->dev, "initializing npcm7xx ehci USB Controller\n");
  44. if (usb_disabled())
  45. return -ENODEV;
  46. irq = platform_get_irq(pdev, 0);
  47. if (irq < 0) {
  48. retval = irq;
  49. goto fail;
  50. }
  51. /*
  52. * Right now device-tree probed devices don't get dma_mask set.
  53. * Since shared usb code relies on it, set it here for now.
  54. * Once we have dma capability bindings this can go away.
  55. */
  56. retval = dma_coerce_mask_and_coherent(&pdev->dev, DMA_BIT_MASK(32));
  57. if (retval)
  58. goto fail;
  59. hcd = usb_create_hcd(driver, &pdev->dev, dev_name(&pdev->dev));
  60. if (!hcd) {
  61. retval = -ENOMEM;
  62. goto fail;
  63. }
  64. hcd->regs = devm_platform_get_and_ioremap_resource(pdev, 0, &res);
  65. if (IS_ERR(hcd->regs)) {
  66. retval = PTR_ERR(hcd->regs);
  67. goto err_put_hcd;
  68. }
  69. hcd->rsrc_start = res->start;
  70. hcd->rsrc_len = resource_size(res);
  71. /* registers start at offset 0x0 */
  72. hcd_to_ehci(hcd)->caps = hcd->regs;
  73. retval = usb_add_hcd(hcd, irq, IRQF_SHARED);
  74. if (retval)
  75. goto err_put_hcd;
  76. device_wakeup_enable(hcd->self.controller);
  77. return retval;
  78. err_put_hcd:
  79. usb_put_hcd(hcd);
  80. fail:
  81. dev_err(&pdev->dev, "init fail, %d\n", retval);
  82. return retval;
  83. }
  84. static void npcm7xx_ehci_hcd_drv_remove(struct platform_device *pdev)
  85. {
  86. struct usb_hcd *hcd = platform_get_drvdata(pdev);
  87. usb_remove_hcd(hcd);
  88. usb_put_hcd(hcd);
  89. }
  90. static const struct of_device_id npcm7xx_ehci_id_table[] = {
  91. { .compatible = "nuvoton,npcm750-ehci" },
  92. { },
  93. };
  94. MODULE_DEVICE_TABLE(of, npcm7xx_ehci_id_table);
  95. static struct platform_driver npcm7xx_ehci_hcd_driver = {
  96. .probe = npcm7xx_ehci_hcd_drv_probe,
  97. .remove_new = npcm7xx_ehci_hcd_drv_remove,
  98. .shutdown = usb_hcd_platform_shutdown,
  99. .driver = {
  100. .name = "npcm7xx-ehci",
  101. .bus = &platform_bus_type,
  102. .pm = pm_ptr(&ehci_npcm7xx_pm_ops),
  103. .of_match_table = npcm7xx_ehci_id_table,
  104. }
  105. };
  106. static int __init ehci_npcm7xx_init(void)
  107. {
  108. if (usb_disabled())
  109. return -ENODEV;
  110. ehci_init_driver(&ehci_npcm7xx_hc_driver, NULL);
  111. return platform_driver_register(&npcm7xx_ehci_hcd_driver);
  112. }
  113. module_init(ehci_npcm7xx_init);
  114. static void __exit ehci_npcm7xx_cleanup(void)
  115. {
  116. platform_driver_unregister(&npcm7xx_ehci_hcd_driver);
  117. }
  118. module_exit(ehci_npcm7xx_cleanup);
  119. MODULE_DESCRIPTION(DRIVER_DESC);
  120. MODULE_ALIAS("platform:npcm7xx-ehci");
  121. MODULE_AUTHOR("Avi Fishman");
  122. MODULE_LICENSE("GPL v2");