ehci-npcm7xx.c 3.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157
  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 <[email protected]> <[email protected]>
  7. * Tomer Maimon <[email protected]> <[email protected]>
  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. res = platform_get_resource(pdev, IORESOURCE_MEM, 0);
  65. hcd->regs = devm_ioremap_resource(&pdev->dev, res);
  66. if (IS_ERR(hcd->regs)) {
  67. retval = PTR_ERR(hcd->regs);
  68. goto err_put_hcd;
  69. }
  70. hcd->rsrc_start = res->start;
  71. hcd->rsrc_len = resource_size(res);
  72. /* registers start at offset 0x0 */
  73. hcd_to_ehci(hcd)->caps = hcd->regs;
  74. retval = usb_add_hcd(hcd, irq, IRQF_SHARED);
  75. if (retval)
  76. goto err_put_hcd;
  77. device_wakeup_enable(hcd->self.controller);
  78. return retval;
  79. err_put_hcd:
  80. usb_put_hcd(hcd);
  81. fail:
  82. dev_err(&pdev->dev, "init fail, %d\n", retval);
  83. return retval;
  84. }
  85. static int npcm7xx_ehci_hcd_drv_remove(struct platform_device *pdev)
  86. {
  87. struct usb_hcd *hcd = platform_get_drvdata(pdev);
  88. usb_remove_hcd(hcd);
  89. usb_put_hcd(hcd);
  90. return 0;
  91. }
  92. static const struct of_device_id npcm7xx_ehci_id_table[] = {
  93. { .compatible = "nuvoton,npcm750-ehci" },
  94. { },
  95. };
  96. MODULE_DEVICE_TABLE(of, npcm7xx_ehci_id_table);
  97. static struct platform_driver npcm7xx_ehci_hcd_driver = {
  98. .probe = npcm7xx_ehci_hcd_drv_probe,
  99. .remove = npcm7xx_ehci_hcd_drv_remove,
  100. .shutdown = usb_hcd_platform_shutdown,
  101. .driver = {
  102. .name = "npcm7xx-ehci",
  103. .bus = &platform_bus_type,
  104. .pm = pm_ptr(&ehci_npcm7xx_pm_ops),
  105. .of_match_table = npcm7xx_ehci_id_table,
  106. }
  107. };
  108. static int __init ehci_npcm7xx_init(void)
  109. {
  110. if (usb_disabled())
  111. return -ENODEV;
  112. ehci_init_driver(&ehci_npcm7xx_hc_driver, NULL);
  113. return platform_driver_register(&npcm7xx_ehci_hcd_driver);
  114. }
  115. module_init(ehci_npcm7xx_init);
  116. static void __exit ehci_npcm7xx_cleanup(void)
  117. {
  118. platform_driver_unregister(&npcm7xx_ehci_hcd_driver);
  119. }
  120. module_exit(ehci_npcm7xx_cleanup);
  121. MODULE_DESCRIPTION(DRIVER_DESC);
  122. MODULE_ALIAS("platform:npcm7xx-ehci");
  123. MODULE_AUTHOR("Avi Fishman");
  124. MODULE_LICENSE("GPL v2");