fixed.c 1.9 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091
  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 <malloc.h>
  10. #include <phy.h>
  11. #include <dm.h>
  12. #include <fdt_support.h>
  13. #include <asm/global_data.h>
  14. DECLARE_GLOBAL_DATA_PTR;
  15. int fixedphy_probe(struct phy_device *phydev)
  16. {
  17. /* fixed-link phy must not be reset by core phy code */
  18. phydev->flags |= PHY_FLAG_BROKEN_RESET;
  19. return 0;
  20. }
  21. int fixedphy_config(struct phy_device *phydev)
  22. {
  23. ofnode node = phy_get_ofnode(phydev);
  24. struct fixed_link *priv;
  25. u32 val;
  26. if (!ofnode_valid(node))
  27. return -EINVAL;
  28. /* check for mandatory properties within fixed-link node */
  29. val = ofnode_read_u32_default(node, "speed", 0);
  30. if (val != SPEED_10 && val != SPEED_100 && val != SPEED_1000 &&
  31. val != SPEED_2500 && val != SPEED_10000) {
  32. printf("ERROR: no/invalid speed given in fixed-link node!");
  33. return -EINVAL;
  34. }
  35. priv = malloc(sizeof(*priv));
  36. if (!priv)
  37. return -ENOMEM;
  38. memset(priv, 0, sizeof(*priv));
  39. phydev->priv = priv;
  40. priv->link_speed = val;
  41. priv->duplex = ofnode_read_bool(node, "full-duplex");
  42. priv->pause = ofnode_read_bool(node, "pause");
  43. priv->asym_pause = ofnode_read_bool(node, "asym-pause");
  44. return 0;
  45. }
  46. int fixedphy_startup(struct phy_device *phydev)
  47. {
  48. struct fixed_link *priv = phydev->priv;
  49. phydev->asym_pause = priv->asym_pause;
  50. phydev->pause = priv->pause;
  51. phydev->duplex = priv->duplex;
  52. phydev->speed = priv->link_speed;
  53. phydev->link = 1;
  54. return 0;
  55. }
  56. int fixedphy_shutdown(struct phy_device *phydev)
  57. {
  58. return 0;
  59. }
  60. static struct phy_driver fixedphy_driver = {
  61. .uid = PHY_FIXED_ID,
  62. .mask = 0xffffffff,
  63. .name = "Fixed PHY",
  64. .features = PHY_GBIT_FEATURES | SUPPORTED_MII,
  65. .probe = fixedphy_probe,
  66. .config = fixedphy_config,
  67. .startup = fixedphy_startup,
  68. .shutdown = fixedphy_shutdown,
  69. };
  70. int phy_fixed_init(void)
  71. {
  72. phy_register(&fixedphy_driver);
  73. return 0;
  74. }