phy-ath79-usb.c 2.5 KB

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