sandbox-phy.c 1.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104
  1. // SPDX-License-Identifier: GPL-2.0+
  2. /*
  3. * Copyright (C) 2017 Texas Instruments Incorporated - http://www.ti.com/
  4. * Written by Jean-Jacques Hiblot <jjhiblot@ti.com>
  5. */
  6. #include <common.h>
  7. #include <dm.h>
  8. #include <generic-phy.h>
  9. struct sandbox_phy_priv {
  10. bool initialized;
  11. bool on;
  12. bool broken;
  13. };
  14. static int sandbox_phy_power_on(struct phy *phy)
  15. {
  16. struct sandbox_phy_priv *priv = dev_get_priv(phy->dev);
  17. if (!priv->initialized)
  18. return -EIO;
  19. if (priv->broken)
  20. return -EIO;
  21. priv->on = true;
  22. return 0;
  23. }
  24. static int sandbox_phy_power_off(struct phy *phy)
  25. {
  26. struct sandbox_phy_priv *priv = dev_get_priv(phy->dev);
  27. if (!priv->initialized)
  28. return -EIO;
  29. if (priv->broken)
  30. return -EIO;
  31. /*
  32. * for validation purpose, let's says that power off
  33. * works only for PHY 0
  34. */
  35. if (phy->id)
  36. return -EIO;
  37. priv->on = false;
  38. return 0;
  39. }
  40. static int sandbox_phy_init(struct phy *phy)
  41. {
  42. struct sandbox_phy_priv *priv = dev_get_priv(phy->dev);
  43. priv->initialized = true;
  44. priv->on = true;
  45. return 0;
  46. }
  47. static int sandbox_phy_exit(struct phy *phy)
  48. {
  49. struct sandbox_phy_priv *priv = dev_get_priv(phy->dev);
  50. priv->initialized = false;
  51. priv->on = false;
  52. return 0;
  53. }
  54. static int sandbox_phy_probe(struct udevice *dev)
  55. {
  56. struct sandbox_phy_priv *priv = dev_get_priv(dev);
  57. priv->initialized = false;
  58. priv->on = false;
  59. priv->broken = dev_read_bool(dev, "broken");
  60. return 0;
  61. }
  62. static struct phy_ops sandbox_phy_ops = {
  63. .power_on = sandbox_phy_power_on,
  64. .power_off = sandbox_phy_power_off,
  65. .init = sandbox_phy_init,
  66. .exit = sandbox_phy_exit,
  67. };
  68. static const struct udevice_id sandbox_phy_ids[] = {
  69. { .compatible = "sandbox,phy" },
  70. { }
  71. };
  72. U_BOOT_DRIVER(phy_sandbox) = {
  73. .name = "phy_sandbox",
  74. .id = UCLASS_PHY,
  75. .of_match = sandbox_phy_ids,
  76. .ops = &sandbox_phy_ops,
  77. .probe = sandbox_phy_probe,
  78. .priv_auto_alloc_size = sizeof(struct sandbox_phy_priv),
  79. };