ldpaa_wriop.c 2.5 KB

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