blob: f62f5fd274508bfce398022d4c11273bcdb2228b [file] [log] [blame]
Tom Rini10e47792018-05-06 17:58:06 -04001// SPDX-License-Identifier: GPL-2.0+
Ashish Kumar1ef4c772017-08-31 16:12:55 +05302/*
3 * Copyright 2017 NXP
Ashish Kumar1ef4c772017-08-31 16:12:55 +05304 */
5
Ashish Kumar1ef4c772017-08-31 16:12:55 +05306#include <asm/io.h>
7#include <asm/arch/fsl_serdes.h>
Bogdan Purcareata33ba9392017-10-05 06:56:53 +00008#include <fsl-mc/fsl_mc.h>
Bogdan Purcareata33ba9392017-10-05 06:56:53 +00009
10#if defined(CONFIG_RESET_PHY_R)
11void reset_phy(void)
12{
13 mc_env_boot();
14}
15#endif /* CONFIG_RESET_PHY_R */
Ioana Ciornei666a2fb2020-05-15 09:56:48 +030016
Ioana Ciornei2ead4432023-02-15 17:31:19 +020017#if defined(CONFIG_MULTI_DTB_FIT)
Ioana Ciornei666a2fb2020-05-15 09:56:48 +030018
Ioana Ciornei2ead4432023-02-15 17:31:19 +020019/* Structure to hold SERDES protocols supported (network interfaces are
20 * described in the DTS).
Ioana Ciornei666a2fb2020-05-15 09:56:48 +030021 *
22 * @serdes_block: the index of the SERDES block
23 * @serdes_protocol: the decimal value of the protocol supported
24 * @dts_needed: DTS notes describing the current configuration are needed
25 *
26 * When dts_needed is true, the board_fit_config_name_match() function
27 * will try to exactly match the current configuration of the block with a DTS
28 * name provided.
29 */
30static struct serdes_configuration {
31 u8 serdes_block;
32 u32 serdes_protocol;
33 bool dts_needed;
34} supported_protocols[] = {
35 /* Serdes block #1 */
36 {1, 21, true},
37 {1, 29, true},
38};
39
40#define SUPPORTED_SERDES_PROTOCOLS ARRAY_SIZE(supported_protocols)
41
42static bool protocol_supported(u8 serdes_block, u32 protocol)
43{
44 struct serdes_configuration serdes_conf;
45 int i;
46
47 for (i = 0; i < SUPPORTED_SERDES_PROTOCOLS; i++) {
48 serdes_conf = supported_protocols[i];
49 if (serdes_conf.serdes_block == serdes_block &&
50 serdes_conf.serdes_protocol == protocol)
51 return true;
52 }
53
54 return false;
55}
56
57static void get_str_protocol(u8 serdes_block, u32 protocol, char *str)
58{
59 struct serdes_configuration serdes_conf;
60 int i;
61
62 for (i = 0; i < SUPPORTED_SERDES_PROTOCOLS; i++) {
63 serdes_conf = supported_protocols[i];
64 if (serdes_conf.serdes_block == serdes_block &&
65 serdes_conf.serdes_protocol == protocol) {
66 if (serdes_conf.dts_needed == true)
67 sprintf(str, "%u", protocol);
68 else
69 sprintf(str, "x");
70 return;
71 }
72 }
73}
74
75int board_fit_config_name_match(const char *name)
76{
Tom Rini376b88a2022-10-28 20:27:13 -040077 struct ccsr_gur *gur = (void *)(CFG_SYS_FSL_GUTS_ADDR);
Ioana Ciornei666a2fb2020-05-15 09:56:48 +030078 char expected_dts[100];
79 char srds_s1_str[2];
80 u32 srds_s1, cfg;
81
82 cfg = in_le32(&gur->rcwsr[FSL_CHASSIS3_SRDS1_REGSR - 1]) &
83 FSL_CHASSIS3_SRDS1_PRTCL_MASK;
84 cfg >>= FSL_CHASSIS3_SRDS1_PRTCL_SHIFT;
85 srds_s1 = serdes_get_number(FSL_SRDS_1, cfg);
86
87 /* Check for supported protocols. The default DTS will be used
88 * in this case
89 */
90 if (!protocol_supported(1, srds_s1))
91 return -1;
92
93 get_str_protocol(1, srds_s1, srds_s1_str);
94
95 sprintf(expected_dts, "fsl-ls1088a-qds-%s-x", srds_s1_str);
96
97 if (!strcmp(name, expected_dts))
98 return 0;
99
100 return -1;
101}
102#endif