2 * Copyright (C) 2015-2016 Marvell International Ltd.
4 * SPDX-License-Identifier: GPL-2.0+
11 #include "comphy_hpipe.h"
14 * comphy_mux_check_config()
15 * description: this function passes over the COMPHY lanes and check if the type
16 * is valid for specific lane. If the type is not valid,
17 * the function update the struct and set the type of the lane as
18 * PHY_TYPE_UNCONNECTED
20 static void comphy_mux_check_config(struct comphy_mux_data *mux_data,
21 struct comphy_map *comphy_map_data, int comphy_max_lanes)
23 struct comphy_mux_options *mux_opt;
28 for (lane = 0; lane < comphy_max_lanes;
29 lane++, comphy_map_data++, mux_data++) {
30 /* Don't check ignored COMPHYs */
31 if (comphy_map_data->type == PHY_TYPE_IGNORE)
34 mux_opt = mux_data->mux_values;
35 for (opt = 0, valid = 0; opt < mux_data->max_lane_values;
37 if (mux_opt->type == comphy_map_data->type) {
43 debug("lane number %d, had invalid type %d\n",
44 lane, comphy_map_data->type);
45 debug("set lane %d as type %d\n", lane,
46 PHY_TYPE_UNCONNECTED);
47 comphy_map_data->type = PHY_TYPE_UNCONNECTED;
49 debug("lane number %d, has type %d\n",
50 lane, comphy_map_data->type);
57 static u32 comphy_mux_get_mux_value(struct comphy_mux_data *mux_data,
60 struct comphy_mux_options *mux_opt;
66 mux_opt = mux_data->mux_values;
67 for (opt = 0 ; opt < mux_data->max_lane_values; opt++, mux_opt++) {
68 if (mux_opt->type == type) {
69 value = mux_opt->mux_value;
79 static void comphy_mux_reg_write(struct comphy_mux_data *mux_data,
80 struct comphy_map *comphy_map_data,
82 void __iomem *selector_base, u32 bitcount)
84 u32 lane, value, offset, mask;
88 for (lane = 0; lane < comphy_max_lanes;
89 lane++, comphy_map_data++, mux_data++) {
90 if (comphy_map_data->type == PHY_TYPE_IGNORE)
93 offset = lane * bitcount;
94 mask = (((1 << bitcount) - 1) << offset);
95 value = (comphy_mux_get_mux_value(mux_data,
96 comphy_map_data->type,
98 reg_set(selector_base, value, mask);
104 void comphy_mux_init(struct chip_serdes_phy_config *chip_cfg,
105 struct comphy_map *comphy_map_data,
106 void __iomem *selector_base)
108 struct comphy_mux_data *mux_data;
110 u32 comphy_max_lanes;
114 comphy_max_lanes = chip_cfg->comphy_lanes_count;
115 mux_data = chip_cfg->mux_data;
116 mux_bitcount = chip_cfg->comphy_mux_bitcount;
118 /* check if the configuration is valid */
119 comphy_mux_check_config(mux_data, comphy_map_data, comphy_max_lanes);
120 /* Init COMPHY selectors */
121 comphy_mux_reg_write(mux_data, comphy_map_data, comphy_max_lanes,
122 selector_base, mux_bitcount);