comphy_mux.c 3.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135
  1. // SPDX-License-Identifier: GPL-2.0+
  2. /*
  3. * Copyright (C) 2015-2016 Marvell International Ltd.
  4. */
  5. #include <common.h>
  6. #include <asm/io.h>
  7. #include "comphy.h"
  8. #include "comphy_hpipe.h"
  9. /*
  10. * comphy_mux_check_config()
  11. * description: this function passes over the COMPHY lanes and check if the type
  12. * is valid for specific lane. If the type is not valid,
  13. * the function update the struct and set the type of the lane as
  14. * PHY_TYPE_UNCONNECTED
  15. */
  16. static void comphy_mux_check_config(struct comphy_mux_data *mux_data,
  17. struct comphy_map *comphy_map_data, int comphy_max_lanes)
  18. {
  19. struct comphy_mux_options *mux_opt;
  20. int lane, opt, valid;
  21. debug_enter();
  22. for (lane = 0; lane < comphy_max_lanes;
  23. lane++, comphy_map_data++, mux_data++) {
  24. /* Don't check ignored COMPHYs */
  25. if (comphy_map_data->type == PHY_TYPE_IGNORE)
  26. continue;
  27. mux_opt = mux_data->mux_values;
  28. for (opt = 0, valid = 0; opt < mux_data->max_lane_values;
  29. opt++, mux_opt++) {
  30. if (mux_opt->type == comphy_map_data->type) {
  31. valid = 1;
  32. break;
  33. }
  34. }
  35. if (valid == 0) {
  36. debug("lane number %d, had invalid type %d\n",
  37. lane, comphy_map_data->type);
  38. debug("set lane %d as type %d\n", lane,
  39. PHY_TYPE_UNCONNECTED);
  40. comphy_map_data->type = PHY_TYPE_UNCONNECTED;
  41. } else {
  42. debug("lane number %d, has type %d\n",
  43. lane, comphy_map_data->type);
  44. }
  45. }
  46. debug_exit();
  47. }
  48. static u32 comphy_mux_get_mux_value(struct comphy_mux_data *mux_data,
  49. u32 type, int lane)
  50. {
  51. struct comphy_mux_options *mux_opt;
  52. int opt;
  53. u32 value = 0;
  54. debug_enter();
  55. mux_opt = mux_data->mux_values;
  56. for (opt = 0 ; opt < mux_data->max_lane_values; opt++, mux_opt++) {
  57. if (mux_opt->type == type) {
  58. value = mux_opt->mux_value;
  59. break;
  60. }
  61. }
  62. debug_exit();
  63. return value;
  64. }
  65. static void comphy_mux_reg_write(struct comphy_mux_data *mux_data,
  66. struct comphy_map *comphy_map_data,
  67. int comphy_max_lanes,
  68. void __iomem *selector_base,
  69. const fdt32_t *mux_lane_order, u32 bitcount)
  70. {
  71. u32 lane, value, offset, mask;
  72. debug_enter();
  73. for (lane = 0; lane < comphy_max_lanes;
  74. lane++, comphy_map_data++, mux_data++) {
  75. if (comphy_map_data->type == PHY_TYPE_IGNORE)
  76. continue;
  77. /*
  78. * if the order of nodes in selector base register is
  79. * nontrivial, use mapping from mux_lane_order
  80. */
  81. if (mux_lane_order)
  82. offset = fdt32_to_cpu(mux_lane_order[lane]) * bitcount;
  83. else
  84. offset = lane * bitcount;
  85. mask = (((1 << bitcount) - 1) << offset);
  86. value = (comphy_mux_get_mux_value(mux_data,
  87. comphy_map_data->type,
  88. lane) << offset);
  89. reg_set(selector_base, value, mask);
  90. }
  91. debug_exit();
  92. }
  93. void comphy_mux_init(struct chip_serdes_phy_config *chip_cfg,
  94. struct comphy_map *comphy_map_data,
  95. void __iomem *selector_base)
  96. {
  97. struct comphy_mux_data *mux_data;
  98. const fdt32_t *mux_lane_order;
  99. u32 mux_bitcount;
  100. u32 comphy_max_lanes;
  101. debug_enter();
  102. comphy_max_lanes = chip_cfg->comphy_lanes_count;
  103. mux_data = chip_cfg->mux_data;
  104. mux_lane_order = chip_cfg->comphy_mux_lane_order;
  105. mux_bitcount = chip_cfg->comphy_mux_bitcount;
  106. /* check if the configuration is valid */
  107. comphy_mux_check_config(mux_data, comphy_map_data, comphy_max_lanes);
  108. /* Init COMPHY selectors */
  109. comphy_mux_reg_write(mux_data, comphy_map_data, comphy_max_lanes,
  110. selector_base, mux_lane_order, mux_bitcount);
  111. debug_exit();
  112. }