]>
git.ipfire.org Git - thirdparty/u-boot.git/blob - drivers/phy/marvell/comphy_mux.c
1 // SPDX-License-Identifier: GPL-2.0+
3 * Copyright (C) 2015-2016 Marvell International Ltd.
10 #include "comphy_hpipe.h"
13 * comphy_mux_check_config()
14 * description: this function passes over the COMPHY lanes and check if the type
15 * is valid for specific lane. If the type is not valid,
16 * the function update the struct and set the type of the lane as
17 * PHY_TYPE_UNCONNECTED
19 static void comphy_mux_check_config(struct comphy_mux_data
*mux_data
,
20 struct comphy_map
*comphy_map_data
, int comphy_max_lanes
)
22 struct comphy_mux_options
*mux_opt
;
27 for (lane
= 0; lane
< comphy_max_lanes
;
28 lane
++, comphy_map_data
++, mux_data
++) {
29 /* Don't check ignored COMPHYs */
30 if (comphy_map_data
->type
== PHY_TYPE_IGNORE
)
33 mux_opt
= mux_data
->mux_values
;
34 for (opt
= 0, valid
= 0; opt
< mux_data
->max_lane_values
;
36 if (mux_opt
->type
== comphy_map_data
->type
) {
42 debug("lane number %d, had invalid type %d\n",
43 lane
, comphy_map_data
->type
);
44 debug("set lane %d as type %d\n", lane
,
45 PHY_TYPE_UNCONNECTED
);
46 comphy_map_data
->type
= PHY_TYPE_UNCONNECTED
;
48 debug("lane number %d, has type %d\n",
49 lane
, comphy_map_data
->type
);
56 static u32
comphy_mux_get_mux_value(struct comphy_mux_data
*mux_data
,
59 struct comphy_mux_options
*mux_opt
;
65 mux_opt
= mux_data
->mux_values
;
66 for (opt
= 0 ; opt
< mux_data
->max_lane_values
; opt
++, mux_opt
++) {
67 if (mux_opt
->type
== type
) {
68 value
= mux_opt
->mux_value
;
78 static void comphy_mux_reg_write(struct comphy_mux_data
*mux_data
,
79 struct comphy_map
*comphy_map_data
,
81 void __iomem
*selector_base
, u32 bitcount
)
83 u32 lane
, value
, offset
, mask
;
87 for (lane
= 0; lane
< comphy_max_lanes
;
88 lane
++, comphy_map_data
++, mux_data
++) {
89 if (comphy_map_data
->type
== PHY_TYPE_IGNORE
)
92 offset
= lane
* bitcount
;
93 mask
= (((1 << bitcount
) - 1) << offset
);
94 value
= (comphy_mux_get_mux_value(mux_data
,
95 comphy_map_data
->type
,
97 reg_set(selector_base
, value
, mask
);
103 void comphy_mux_init(struct chip_serdes_phy_config
*chip_cfg
,
104 struct comphy_map
*comphy_map_data
,
105 void __iomem
*selector_base
)
107 struct comphy_mux_data
*mux_data
;
109 u32 comphy_max_lanes
;
113 comphy_max_lanes
= chip_cfg
->comphy_lanes_count
;
114 mux_data
= chip_cfg
->mux_data
;
115 mux_bitcount
= chip_cfg
->comphy_mux_bitcount
;
117 /* check if the configuration is valid */
118 comphy_mux_check_config(mux_data
, comphy_map_data
, comphy_max_lanes
);
119 /* Init COMPHY selectors */
120 comphy_mux_reg_write(mux_data
, comphy_map_data
, comphy_max_lanes
,
121 selector_base
, mux_bitcount
);