comphy_mux.c 2.9 KB

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