fixed.c 1.7 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980
  1. // SPDX-License-Identifier: GPL-2.0+
  2. /*
  3. * Fixed-Link phy
  4. *
  5. * Copyright 2017 Bernecker & Rainer Industrieelektronik GmbH
  6. */
  7. #include <config.h>
  8. #include <common.h>
  9. #include <phy.h>
  10. #include <dm.h>
  11. #include <fdt_support.h>
  12. DECLARE_GLOBAL_DATA_PTR;
  13. int fixedphy_probe(struct phy_device *phydev)
  14. {
  15. struct fixed_link *priv;
  16. int ofnode = phydev->addr;
  17. u32 val;
  18. /* check for mandatory properties within fixed-link node */
  19. val = fdt_getprop_u32_default_node(gd->fdt_blob,
  20. ofnode, 0, "speed", 0);
  21. if (val != SPEED_10 && val != SPEED_100 && val != SPEED_1000) {
  22. printf("ERROR: no/invalid speed given in fixed-link node!");
  23. return -EINVAL;
  24. }
  25. priv = malloc(sizeof(*priv));
  26. if (!priv)
  27. return -ENOMEM;
  28. memset(priv, 0, sizeof(*priv));
  29. phydev->priv = priv;
  30. priv->link_speed = val;
  31. priv->duplex = fdtdec_get_bool(gd->fdt_blob, ofnode, "full-duplex");
  32. priv->pause = fdtdec_get_bool(gd->fdt_blob, ofnode, "pause");
  33. priv->asym_pause = fdtdec_get_bool(gd->fdt_blob, ofnode, "asym-pause");
  34. /* fixed-link phy must not be reset by core phy code */
  35. phydev->flags |= PHY_FLAG_BROKEN_RESET;
  36. return 0;
  37. }
  38. int fixedphy_startup(struct phy_device *phydev)
  39. {
  40. struct fixed_link *priv = phydev->priv;
  41. phydev->asym_pause = priv->asym_pause;
  42. phydev->pause = priv->pause;
  43. phydev->duplex = priv->duplex;
  44. phydev->speed = priv->link_speed;
  45. phydev->link = 1;
  46. return 0;
  47. }
  48. int fixedphy_shutdown(struct phy_device *phydev)
  49. {
  50. return 0;
  51. }
  52. static struct phy_driver fixedphy_driver = {
  53. .uid = PHY_FIXED_ID,
  54. .mask = 0xffffffff,
  55. .name = "Fixed PHY",
  56. .features = PHY_GBIT_FEATURES | SUPPORTED_MII,
  57. .probe = fixedphy_probe,
  58. .startup = fixedphy_startup,
  59. .shutdown = fixedphy_shutdown,
  60. };
  61. int phy_fixed_init(void)
  62. {
  63. phy_register(&fixedphy_driver);
  64. return 0;
  65. }