ldpaa_wriop.c 2.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165
  1. // SPDX-License-Identifier: GPL-2.0+
  2. /*
  3. * Copyright (C) 2015 Freescale Semiconductor
  4. */
  5. #include <common.h>
  6. #include <asm/io.h>
  7. #include <asm/types.h>
  8. #include <malloc.h>
  9. #include <net.h>
  10. #include <linux/compat.h>
  11. #include <asm/arch/fsl_serdes.h>
  12. #include <fsl-mc/ldpaa_wriop.h>
  13. struct wriop_dpmac_info dpmac_info[NUM_WRIOP_PORTS];
  14. __weak phy_interface_t wriop_dpmac_enet_if(int dpmac_id, int lane_prtc)
  15. {
  16. return PHY_INTERFACE_MODE_NONE;
  17. }
  18. void wriop_init_dpmac(int sd, int dpmac_id, int lane_prtcl)
  19. {
  20. phy_interface_t enet_if;
  21. dpmac_info[dpmac_id].enabled = 0;
  22. dpmac_info[dpmac_id].id = 0;
  23. dpmac_info[dpmac_id].phy_addr = -1;
  24. dpmac_info[dpmac_id].enet_if = PHY_INTERFACE_MODE_NONE;
  25. enet_if = wriop_dpmac_enet_if(dpmac_id, lane_prtcl);
  26. if (enet_if != PHY_INTERFACE_MODE_NONE) {
  27. dpmac_info[dpmac_id].enabled = 1;
  28. dpmac_info[dpmac_id].id = dpmac_id;
  29. dpmac_info[dpmac_id].enet_if = enet_if;
  30. }
  31. }
  32. void wriop_init_dpmac_enet_if(int dpmac_id, phy_interface_t enet_if)
  33. {
  34. dpmac_info[dpmac_id].enabled = 1;
  35. dpmac_info[dpmac_id].id = dpmac_id;
  36. dpmac_info[dpmac_id].phy_addr = -1;
  37. dpmac_info[dpmac_id].enet_if = enet_if;
  38. }
  39. /*TODO what it do */
  40. static int wriop_dpmac_to_index(int dpmac_id)
  41. {
  42. int i;
  43. for (i = WRIOP1_DPMAC1; i < NUM_WRIOP_PORTS; i++) {
  44. if (dpmac_info[i].id == dpmac_id)
  45. return i;
  46. }
  47. return -1;
  48. }
  49. void wriop_disable_dpmac(int dpmac_id)
  50. {
  51. int i = wriop_dpmac_to_index(dpmac_id);
  52. if (i == -1)
  53. return;
  54. dpmac_info[i].enabled = 0;
  55. wriop_dpmac_disable(dpmac_id);
  56. }
  57. void wriop_enable_dpmac(int dpmac_id)
  58. {
  59. int i = wriop_dpmac_to_index(dpmac_id);
  60. if (i == -1)
  61. return;
  62. dpmac_info[i].enabled = 1;
  63. wriop_dpmac_enable(dpmac_id);
  64. }
  65. u8 wriop_is_enabled_dpmac(int dpmac_id)
  66. {
  67. int i = wriop_dpmac_to_index(dpmac_id);
  68. if (i == -1)
  69. return -1;
  70. return dpmac_info[i].enabled;
  71. }
  72. void wriop_set_mdio(int dpmac_id, struct mii_dev *bus)
  73. {
  74. int i = wriop_dpmac_to_index(dpmac_id);
  75. if (i == -1)
  76. return;
  77. dpmac_info[i].bus = bus;
  78. }
  79. struct mii_dev *wriop_get_mdio(int dpmac_id)
  80. {
  81. int i = wriop_dpmac_to_index(dpmac_id);
  82. if (i == -1)
  83. return NULL;
  84. return dpmac_info[i].bus;
  85. }
  86. void wriop_set_phy_address(int dpmac_id, int address)
  87. {
  88. int i = wriop_dpmac_to_index(dpmac_id);
  89. if (i == -1)
  90. return;
  91. dpmac_info[i].phy_addr = address;
  92. }
  93. int wriop_get_phy_address(int dpmac_id)
  94. {
  95. int i = wriop_dpmac_to_index(dpmac_id);
  96. if (i == -1)
  97. return -1;
  98. return dpmac_info[i].phy_addr;
  99. }
  100. void wriop_set_phy_dev(int dpmac_id, struct phy_device *phydev)
  101. {
  102. int i = wriop_dpmac_to_index(dpmac_id);
  103. if (i == -1)
  104. return;
  105. dpmac_info[i].phydev = phydev;
  106. }
  107. struct phy_device *wriop_get_phy_dev(int dpmac_id)
  108. {
  109. int i = wriop_dpmac_to_index(dpmac_id);
  110. if (i == -1)
  111. return NULL;
  112. return dpmac_info[i].phydev;
  113. }
  114. phy_interface_t wriop_get_enet_if(int dpmac_id)
  115. {
  116. int i = wriop_dpmac_to_index(dpmac_id);
  117. if (i == -1)
  118. return PHY_INTERFACE_MODE_NONE;
  119. if (dpmac_info[i].enabled)
  120. return dpmac_info[i].enet_if;
  121. return PHY_INTERFACE_MODE_NONE;
  122. }