fixed.c 1.8 KB

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