ldpaa_wriop.c 3.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192
  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. int phy_num;
  22. dpmac_info[dpmac_id].enabled = 0;
  23. dpmac_info[dpmac_id].id = 0;
  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. for (phy_num = 0; phy_num < WRIOP_MAX_PHY_NUM; phy_num++) {
  32. dpmac_info[dpmac_id].phydev[phy_num] = NULL;
  33. dpmac_info[dpmac_id].phy_addr[phy_num] = -1;
  34. }
  35. }
  36. void wriop_init_dpmac_enet_if(int dpmac_id, phy_interface_t enet_if)
  37. {
  38. int phy_num;
  39. dpmac_info[dpmac_id].enabled = 1;
  40. dpmac_info[dpmac_id].id = dpmac_id;
  41. dpmac_info[dpmac_id].enet_if = enet_if;
  42. for (phy_num = 0; phy_num < WRIOP_MAX_PHY_NUM; phy_num++) {
  43. dpmac_info[dpmac_id].phydev[phy_num] = NULL;
  44. dpmac_info[dpmac_id].phy_addr[phy_num] = -1;
  45. }
  46. }
  47. /*TODO what it do */
  48. static int wriop_dpmac_to_index(int dpmac_id)
  49. {
  50. int i;
  51. for (i = WRIOP1_DPMAC1; i < NUM_WRIOP_PORTS; i++) {
  52. if (dpmac_info[i].id == dpmac_id)
  53. return i;
  54. }
  55. return -1;
  56. }
  57. int wriop_disable_dpmac(int dpmac_id)
  58. {
  59. int i = wriop_dpmac_to_index(dpmac_id);
  60. if (i == -1)
  61. return -ENODEV;
  62. dpmac_info[i].enabled = 0;
  63. wriop_dpmac_disable(dpmac_id);
  64. return 0;
  65. }
  66. int wriop_enable_dpmac(int dpmac_id)
  67. {
  68. int i = wriop_dpmac_to_index(dpmac_id);
  69. if (i == -1)
  70. return -ENODEV;
  71. dpmac_info[i].enabled = 1;
  72. wriop_dpmac_enable(dpmac_id);
  73. return 0;
  74. }
  75. int wriop_is_enabled_dpmac(int dpmac_id)
  76. {
  77. int i = wriop_dpmac_to_index(dpmac_id);
  78. if (i == -1)
  79. return -ENODEV;
  80. return dpmac_info[i].enabled;
  81. }
  82. int wriop_set_mdio(int dpmac_id, struct mii_dev *bus)
  83. {
  84. int i = wriop_dpmac_to_index(dpmac_id);
  85. if (i == -1)
  86. return -ENODEV;
  87. dpmac_info[i].bus = bus;
  88. return 0;
  89. }
  90. struct mii_dev *wriop_get_mdio(int dpmac_id)
  91. {
  92. int i = wriop_dpmac_to_index(dpmac_id);
  93. if (i == -1)
  94. return NULL;
  95. return dpmac_info[i].bus;
  96. }
  97. int wriop_set_phy_address(int dpmac_id, int phy_num, int address)
  98. {
  99. int i = wriop_dpmac_to_index(dpmac_id);
  100. if (i == -1)
  101. return -ENODEV;
  102. if (phy_num < 0 || phy_num >= WRIOP_MAX_PHY_NUM)
  103. return -EINVAL;
  104. dpmac_info[i].phy_addr[phy_num] = address;
  105. return 0;
  106. }
  107. int wriop_get_phy_address(int dpmac_id, int phy_num)
  108. {
  109. int i = wriop_dpmac_to_index(dpmac_id);
  110. if (i == -1)
  111. return -ENODEV;
  112. if (phy_num < 0 || phy_num >= WRIOP_MAX_PHY_NUM)
  113. return -EINVAL;
  114. return dpmac_info[i].phy_addr[phy_num];
  115. }
  116. int wriop_set_phy_dev(int dpmac_id, int phy_num, struct phy_device *phydev)
  117. {
  118. int i = wriop_dpmac_to_index(dpmac_id);
  119. if (i == -1)
  120. return -ENODEV;
  121. if (phy_num < 0 || phy_num >= WRIOP_MAX_PHY_NUM)
  122. return -EINVAL;
  123. dpmac_info[i].phydev[phy_num] = phydev;
  124. return 0;
  125. }
  126. struct phy_device *wriop_get_phy_dev(int dpmac_id, int phy_num)
  127. {
  128. int i = wriop_dpmac_to_index(dpmac_id);
  129. if (i == -1)
  130. return NULL;
  131. if (phy_num < 0 || phy_num >= WRIOP_MAX_PHY_NUM)
  132. return NULL;
  133. return dpmac_info[i].phydev[phy_num];
  134. }
  135. phy_interface_t wriop_get_enet_if(int dpmac_id)
  136. {
  137. int i = wriop_dpmac_to_index(dpmac_id);
  138. if (i == -1)
  139. return PHY_INTERFACE_MODE_NONE;
  140. if (dpmac_info[i].enabled)
  141. return dpmac_info[i].enet_if;
  142. return PHY_INTERFACE_MODE_NONE;
  143. }