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 mux_opt = mux_data->mux_values;
31 for (opt = 0, valid = 0; opt < mux_data->max_lane_values;
33 if (mux_opt->type == comphy_map_data->type) {
39 debug("lane number %d, had invalid type %d\n",
40 lane, comphy_map_data->type);
41 debug("set lane %d as type %d\n", lane,
42 PHY_TYPE_UNCONNECTED);
43 comphy_map_data->type = PHY_TYPE_UNCONNECTED;
45 debug("lane number %d, has type %d\n",
46 lane, comphy_map_data->type);
53 static u32 comphy_mux_get_mux_value(struct comphy_mux_data *mux_data,
56 struct comphy_mux_options *mux_opt;
62 mux_opt = mux_data->mux_values;
63 for (opt = 0 ; opt < mux_data->max_lane_values; opt++, mux_opt++) {
64 if (mux_opt->type == type) {
65 value = mux_opt->mux_value;
75 static void comphy_mux_reg_write(struct comphy_mux_data *mux_data,
76 struct comphy_map *comphy_map_data,
78 void __iomem *selector_base, u32 bitcount)
80 u32 lane, value, offset, mask;
84 for (lane = 0; lane < comphy_max_lanes;
85 lane++, comphy_map_data++, mux_data++) {
86 offset = lane * bitcount;
87 mask = (((1 << bitcount) - 1) << offset);
88 value = (comphy_mux_get_mux_value(mux_data,
89 comphy_map_data->type,
91 reg_set(selector_base, value, mask);
97 void comphy_mux_init(struct chip_serdes_phy_config *chip_cfg,
98 struct comphy_map *comphy_map_data,
99 void __iomem *selector_base)
101 struct comphy_mux_data *mux_data;
103 u32 comphy_max_lanes;
107 comphy_max_lanes = chip_cfg->comphy_lanes_count;
108 mux_data = chip_cfg->mux_data;
109 mux_bitcount = chip_cfg->comphy_mux_bitcount;
111 /* check if the configuration is valid */
112 comphy_mux_check_config(mux_data, comphy_map_data, comphy_max_lanes);
113 /* Init COMPHY selectors */
114 comphy_mux_reg_write(mux_data, comphy_map_data, comphy_max_lanes,
115 selector_base, mux_bitcount);