phy-ath79-usb.c 2.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109
  1. // SPDX-License-Identifier: GPL-2.0+
  2. /*
  3. * Atheros AR71XX/9XXX USB PHY driver
  4. *
  5. * Copyright (C) 2015-2018 Alban Bedel <albeu@free.fr>
  6. */
  7. #include <linux/mod_devicetable.h>
  8. #include <linux/module.h>
  9. #include <linux/platform_device.h>
  10. #include <linux/phy/phy.h>
  11. #include <linux/reset.h>
  12. struct ath79_usb_phy {
  13. struct reset_control *reset;
  14. /* The suspend override logic is inverted, hence the no prefix
  15. * to make the code a bit easier to understand.
  16. */
  17. struct reset_control *no_suspend_override;
  18. };
  19. static int ath79_usb_phy_power_on(struct phy *phy)
  20. {
  21. struct ath79_usb_phy *priv = phy_get_drvdata(phy);
  22. int err = 0;
  23. if (priv->no_suspend_override) {
  24. err = reset_control_assert(priv->no_suspend_override);
  25. if (err)
  26. return err;
  27. }
  28. err = reset_control_deassert(priv->reset);
  29. if (err && priv->no_suspend_override)
  30. reset_control_deassert(priv->no_suspend_override);
  31. return err;
  32. }
  33. static int ath79_usb_phy_power_off(struct phy *phy)
  34. {
  35. struct ath79_usb_phy *priv = phy_get_drvdata(phy);
  36. int err = 0;
  37. err = reset_control_assert(priv->reset);
  38. if (err)
  39. return err;
  40. if (priv->no_suspend_override) {
  41. err = reset_control_deassert(priv->no_suspend_override);
  42. if (err)
  43. reset_control_deassert(priv->reset);
  44. }
  45. return err;
  46. }
  47. static const struct phy_ops ath79_usb_phy_ops = {
  48. .power_on = ath79_usb_phy_power_on,
  49. .power_off = ath79_usb_phy_power_off,
  50. .owner = THIS_MODULE,
  51. };
  52. static int ath79_usb_phy_probe(struct platform_device *pdev)
  53. {
  54. struct ath79_usb_phy *priv;
  55. struct phy *phy;
  56. priv = devm_kzalloc(&pdev->dev, sizeof(*priv), GFP_KERNEL);
  57. if (!priv)
  58. return -ENOMEM;
  59. priv->reset = devm_reset_control_get(&pdev->dev, "phy");
  60. if (IS_ERR(priv->reset))
  61. return PTR_ERR(priv->reset);
  62. priv->no_suspend_override = devm_reset_control_get_optional(
  63. &pdev->dev, "usb-suspend-override");
  64. if (IS_ERR(priv->no_suspend_override))
  65. return PTR_ERR(priv->no_suspend_override);
  66. phy = devm_phy_create(&pdev->dev, NULL, &ath79_usb_phy_ops);
  67. if (IS_ERR(phy))
  68. return PTR_ERR(phy);
  69. phy_set_drvdata(phy, priv);
  70. return PTR_ERR_OR_ZERO(devm_of_phy_provider_register(
  71. &pdev->dev, of_phy_simple_xlate));
  72. }
  73. static const struct of_device_id ath79_usb_phy_of_match[] = {
  74. { .compatible = "qca,ar7100-usb-phy" },
  75. {}
  76. };
  77. MODULE_DEVICE_TABLE(of, ath79_usb_phy_of_match);
  78. static struct platform_driver ath79_usb_phy_driver = {
  79. .probe = ath79_usb_phy_probe,
  80. .driver = {
  81. .of_match_table = ath79_usb_phy_of_match,
  82. .name = "ath79-usb-phy",
  83. }
  84. };
  85. module_platform_driver(ath79_usb_phy_driver);
  86. MODULE_DESCRIPTION("ATH79 USB PHY driver");
  87. MODULE_AUTHOR("Alban Bedel <albeu@free.fr>");
  88. MODULE_LICENSE("GPL");