sandbox-phy.c 2.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120
  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. #define DRIVER_DATA 0x12345678
  10. struct sandbox_phy_priv {
  11. bool initialized;
  12. bool on;
  13. bool broken;
  14. };
  15. static int sandbox_phy_power_on(struct phy *phy)
  16. {
  17. struct sandbox_phy_priv *priv = dev_get_priv(phy->dev);
  18. if (!priv->initialized)
  19. return -EIO;
  20. if (priv->broken)
  21. return -EIO;
  22. priv->on = true;
  23. return 0;
  24. }
  25. static int sandbox_phy_power_off(struct phy *phy)
  26. {
  27. struct sandbox_phy_priv *priv = dev_get_priv(phy->dev);
  28. if (!priv->initialized)
  29. return -EIO;
  30. if (priv->broken)
  31. return -EIO;
  32. /*
  33. * for validation purpose, let's says that power off
  34. * works only for PHY 0
  35. */
  36. if (phy->id)
  37. return -EIO;
  38. priv->on = false;
  39. return 0;
  40. }
  41. static int sandbox_phy_init(struct phy *phy)
  42. {
  43. struct sandbox_phy_priv *priv = dev_get_priv(phy->dev);
  44. priv->initialized = true;
  45. priv->on = true;
  46. return 0;
  47. }
  48. static int sandbox_phy_exit(struct phy *phy)
  49. {
  50. struct sandbox_phy_priv *priv = dev_get_priv(phy->dev);
  51. priv->initialized = false;
  52. priv->on = false;
  53. return 0;
  54. }
  55. static int sandbox_phy_bind(struct udevice *dev)
  56. {
  57. if (dev_get_driver_data(dev) != DRIVER_DATA)
  58. return -ENODATA;
  59. return 0;
  60. }
  61. static int sandbox_phy_probe(struct udevice *dev)
  62. {
  63. struct sandbox_phy_priv *priv = dev_get_priv(dev);
  64. priv->initialized = false;
  65. priv->on = false;
  66. priv->broken = dev_read_bool(dev, "broken");
  67. return 0;
  68. }
  69. static struct phy_ops sandbox_phy_ops = {
  70. .power_on = sandbox_phy_power_on,
  71. .power_off = sandbox_phy_power_off,
  72. .init = sandbox_phy_init,
  73. .exit = sandbox_phy_exit,
  74. };
  75. static const struct udevice_id sandbox_phy_ids[] = {
  76. { .compatible = "sandbox,phy_no_driver_data",
  77. },
  78. { .compatible = "sandbox,phy",
  79. .data = DRIVER_DATA
  80. },
  81. { }
  82. };
  83. U_BOOT_DRIVER(phy_sandbox) = {
  84. .name = "phy_sandbox",
  85. .id = UCLASS_PHY,
  86. .bind = sandbox_phy_bind,
  87. .of_match = sandbox_phy_ids,
  88. .ops = &sandbox_phy_ops,
  89. .probe = sandbox_phy_probe,
  90. .priv_auto = sizeof(struct sandbox_phy_priv),
  91. };