fixed.c 2.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111
  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. static 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. static int fixedphy_config(struct phy_device *phydev)
  22. {
  23. ofnode node = phy_get_ofnode(phydev);
  24. struct fixed_link *priv;
  25. bool old_binding = false;
  26. u32 old_val[5];
  27. u32 val;
  28. if (!ofnode_valid(node))
  29. return -EINVAL;
  30. /* check for mandatory properties within fixed-link node */
  31. val = ofnode_read_u32_default(node, "speed", 0);
  32. if (!val) {
  33. /* try old binding */
  34. old_binding = true;
  35. if (ofnode_read_u32_array(node, "fixed-link", old_val,
  36. ARRAY_SIZE(old_val))) {
  37. printf("ERROR: no/invalid <fixed-link> property!\n");
  38. return -ENOENT;
  39. }
  40. val = old_val[2];
  41. }
  42. if (val != SPEED_10 && val != SPEED_100 && val != SPEED_1000 &&
  43. val != SPEED_2500 && val != SPEED_10000) {
  44. printf("ERROR: no/invalid speed given in fixed-link node!\n");
  45. return -EINVAL;
  46. }
  47. priv = malloc(sizeof(*priv));
  48. if (!priv)
  49. return -ENOMEM;
  50. memset(priv, 0, sizeof(*priv));
  51. phydev->priv = priv;
  52. priv->link_speed = val;
  53. if (!old_binding) {
  54. priv->duplex = ofnode_read_bool(node, "full-duplex");
  55. priv->pause = ofnode_read_bool(node, "pause");
  56. priv->asym_pause = ofnode_read_bool(node, "asym-pause");
  57. } else {
  58. priv->duplex = old_val[1];
  59. priv->pause = old_val[3];
  60. priv->asym_pause = old_val[4];
  61. }
  62. return 0;
  63. }
  64. static int fixedphy_startup(struct phy_device *phydev)
  65. {
  66. struct fixed_link *priv = phydev->priv;
  67. phydev->asym_pause = priv->asym_pause;
  68. phydev->pause = priv->pause;
  69. phydev->duplex = priv->duplex;
  70. phydev->speed = priv->link_speed;
  71. phydev->link = 1;
  72. return 0;
  73. }
  74. static int fixedphy_shutdown(struct phy_device *phydev)
  75. {
  76. return 0;
  77. }
  78. static struct phy_driver fixedphy_driver = {
  79. .uid = PHY_FIXED_ID,
  80. .mask = 0xffffffff,
  81. .name = "Fixed PHY",
  82. .features = PHY_GBIT_FEATURES | SUPPORTED_MII,
  83. .probe = fixedphy_probe,
  84. .config = fixedphy_config,
  85. .startup = fixedphy_startup,
  86. .shutdown = fixedphy_shutdown,
  87. };
  88. int phy_fixed_init(void)
  89. {
  90. phy_register(&fixedphy_driver);
  91. return 0;
  92. }