sandbox-phy.c 1.9 KB

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