Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux
1
fork

Configure Feed

Select the types of activity you want to include in your feed.

phy: ti: phy-j721e-wiz: use OF data for device specific data

Move device specific data into OF data structure so it
is easier to maintain and we can get rid of if statements.

Signed-off-by: Roger Quadros <rogerq@kernel.org>
Reviewed-by: Matt Ranostay <mranostay@ti.com>
Link: https://lore.kernel.org/r/20220526064121.27625-1-rogerq@kernel.org
Signed-off-by: Vinod Koul <vkoul@kernel.org>

authored by

Roger Quadros and committed by
Vinod Koul
4daa43e9 5cda442d

+50 -25
+50 -25
drivers/phy/ti/phy-j721e-wiz.c
··· 253 253 AM64_WIZ_10G, 254 254 }; 255 255 256 + struct wiz_data { 257 + enum wiz_type type; 258 + const struct reg_field *refclk_dig_sel; 259 + const struct reg_field *pma_cmn_refclk1_dig_div; 260 + const struct wiz_clk_mux_sel *clk_mux_sel; 261 + unsigned int clk_div_sel_num; 262 + }; 263 + 256 264 #define WIZ_TYPEC_DIR_DEBOUNCE_MIN 100 /* ms */ 257 265 #define WIZ_TYPEC_DIR_DEBOUNCE_MAX 1000 258 266 ··· 298 290 struct clk *input_clks[WIZ_MAX_INPUT_CLOCKS]; 299 291 struct clk *output_clks[WIZ_MAX_OUTPUT_CLOCKS]; 300 292 struct clk_onecell_data clk_data; 293 + const struct wiz_data *data; 301 294 }; 302 295 303 296 static int wiz_reset(struct wiz *wiz) ··· 418 409 struct regmap *regmap = wiz->regmap; 419 410 int num_lanes = wiz->num_lanes; 420 411 struct device *dev = wiz->dev; 412 + const struct wiz_data *data = wiz->data; 421 413 int i; 422 414 423 415 wiz->por_en = devm_regmap_field_alloc(dev, regmap, por_en); ··· 455 445 return PTR_ERR(wiz->div_sel_field[CMN_REFCLK_DIG_DIV]); 456 446 } 457 447 458 - if (wiz->type == J721E_WIZ_16G) { 448 + if (data->pma_cmn_refclk1_dig_div) { 459 449 wiz->div_sel_field[CMN_REFCLK1_DIG_DIV] = 460 450 devm_regmap_field_alloc(dev, regmap, 461 - pma_cmn_refclk1_dig_div); 451 + *data->pma_cmn_refclk1_dig_div); 462 452 if (IS_ERR(wiz->div_sel_field[CMN_REFCLK1_DIG_DIV])) { 463 453 dev_err(dev, "PMA_CMN_REFCLK1_DIG_DIV reg field init failed\n"); 464 454 return PTR_ERR(wiz->div_sel_field[CMN_REFCLK1_DIG_DIV]); ··· 479 469 return PTR_ERR(wiz->mux_sel_field[PLL1_REFCLK]); 480 470 } 481 471 482 - if (wiz->type == J721E_WIZ_10G || wiz->type == AM64_WIZ_10G) 483 - wiz->mux_sel_field[REFCLK_DIG] = 484 - devm_regmap_field_alloc(dev, regmap, 485 - refclk_dig_sel_10g); 486 - else 487 - wiz->mux_sel_field[REFCLK_DIG] = 488 - devm_regmap_field_alloc(dev, regmap, 489 - refclk_dig_sel_16g); 490 - 472 + wiz->mux_sel_field[REFCLK_DIG] = devm_regmap_field_alloc(dev, regmap, 473 + *data->refclk_dig_sel); 491 474 if (IS_ERR(wiz->mux_sel_field[REFCLK_DIG])) { 492 475 dev_err(dev, "REFCLK_DIG_SEL reg field init failed\n"); 493 476 return PTR_ERR(wiz->mux_sel_field[REFCLK_DIG]); ··· 1081 1078 .fast_io = true, 1082 1079 }; 1083 1080 1081 + static struct wiz_data j721e_16g_data = { 1082 + .type = J721E_WIZ_16G, 1083 + .refclk_dig_sel = &refclk_dig_sel_16g, 1084 + .pma_cmn_refclk1_dig_div = &pma_cmn_refclk1_dig_div, 1085 + .clk_mux_sel = clk_mux_sel_16g, 1086 + .clk_div_sel_num = WIZ_DIV_NUM_CLOCKS_16G, 1087 + }; 1088 + 1089 + static struct wiz_data j721e_10g_data = { 1090 + .type = J721E_WIZ_10G, 1091 + .refclk_dig_sel = &refclk_dig_sel_10g, 1092 + .clk_mux_sel = clk_mux_sel_10g, 1093 + .clk_div_sel_num = WIZ_DIV_NUM_CLOCKS_10G, 1094 + }; 1095 + 1096 + static struct wiz_data am64_10g_data = { 1097 + .type = AM64_WIZ_10G, 1098 + .refclk_dig_sel = &refclk_dig_sel_10g, 1099 + .clk_mux_sel = clk_mux_sel_10g, 1100 + .clk_div_sel_num = WIZ_DIV_NUM_CLOCKS_10G, 1101 + }; 1102 + 1084 1103 static const struct of_device_id wiz_id_table[] = { 1085 1104 { 1086 - .compatible = "ti,j721e-wiz-16g", .data = (void *)J721E_WIZ_16G 1105 + .compatible = "ti,j721e-wiz-16g", .data = &j721e_16g_data, 1087 1106 }, 1088 1107 { 1089 - .compatible = "ti,j721e-wiz-10g", .data = (void *)J721E_WIZ_10G 1108 + .compatible = "ti,j721e-wiz-10g", .data = &j721e_10g_data, 1090 1109 }, 1091 1110 { 1092 - .compatible = "ti,am64-wiz-10g", .data = (void *)AM64_WIZ_10G 1111 + .compatible = "ti,am64-wiz-10g", .data = &am64_10g_data, 1093 1112 }, 1094 1113 {} 1095 1114 }; ··· 1170 1145 struct wiz *wiz; 1171 1146 int ret, val, i; 1172 1147 u32 num_lanes; 1148 + const struct wiz_data *data; 1173 1149 1174 1150 wiz = devm_kzalloc(dev, sizeof(*wiz), GFP_KERNEL); 1175 1151 if (!wiz) 1176 1152 return -ENOMEM; 1177 1153 1178 - wiz->type = (enum wiz_type)of_device_get_match_data(dev); 1154 + data = of_device_get_match_data(dev); 1155 + if (!data) { 1156 + dev_err(dev, "NULL device data\n"); 1157 + return -EINVAL; 1158 + } 1159 + 1160 + wiz->data = data; 1161 + wiz->type = data->type; 1179 1162 1180 1163 child_node = of_get_child_by_name(node, "serdes"); 1181 1164 if (!child_node) { ··· 1259 1226 wiz->dev = dev; 1260 1227 wiz->regmap = regmap; 1261 1228 wiz->num_lanes = num_lanes; 1262 - if (wiz->type == J721E_WIZ_10G || wiz->type == AM64_WIZ_10G) 1263 - wiz->clk_mux_sel = clk_mux_sel_10g; 1264 - else 1265 - wiz->clk_mux_sel = clk_mux_sel_16g; 1266 - 1229 + wiz->clk_mux_sel = data->clk_mux_sel; 1267 1230 wiz->clk_div_sel = clk_div_sel; 1268 - 1269 - if (wiz->type == J721E_WIZ_10G || wiz->type == AM64_WIZ_10G) 1270 - wiz->clk_div_sel_num = WIZ_DIV_NUM_CLOCKS_10G; 1271 - else 1272 - wiz->clk_div_sel_num = WIZ_DIV_NUM_CLOCKS_16G; 1231 + wiz->clk_div_sel_num = data->clk_div_sel_num; 1273 1232 1274 1233 platform_set_drvdata(pdev, wiz); 1275 1234