1 // SPDX-License-Identifier: GPL-2.0+
2 /*
3  * Copyright 2015 Freescale Semiconductor, Inc.
4  */
5 
6 #include <asm/io.h>
7 #include <asm/arch/fsl_serdes.h>
8 #include <fsl-mc/fsl_mc.h>
9 
10 #define MC_BOOT_ENV_VAR "mcinitcmd"
11 
12 #if defined(CONFIG_RESET_PHY_R)
reset_phy(void)13 void reset_phy(void)
14 {
15 	mc_env_boot();
16 }
17 #endif /* CONFIG_RESET_PHY_R */
18 
19 #if defined(CONFIG_MULTI_DTB_FIT)
20 
21 /* Structure to hold SERDES protocols supported (network interfaces are
22  * described in the DTS).
23  *
24  * @serdes_block: the index of the SERDES block
25  * @serdes_protocol: the decimal value of the protocol supported
26  * @dts_needed: DTS notes describing the current configuration are needed
27  *
28  * When dts_needed is true, the board_fit_config_name_match() function
29  * will try to exactly match the current configuration of the block with a DTS
30  * name provided.
31  */
32 static struct serdes_configuration {
33 	u8 serdes_block;
34 	u32 serdes_protocol;
35 	bool dts_needed;
36 } supported_protocols[] = {
37 	/* Serdes block #1 */
38 	{1, 42, true},
39 
40 	/* Serdes block #2 */
41 	{2, 65, false},
42 };
43 
44 #define SUPPORTED_SERDES_PROTOCOLS ARRAY_SIZE(supported_protocols)
45 
protocol_supported(u8 serdes_block,u32 protocol)46 static bool protocol_supported(u8 serdes_block, u32 protocol)
47 {
48 	struct serdes_configuration serdes_conf;
49 	int i;
50 
51 	for (i = 0; i < SUPPORTED_SERDES_PROTOCOLS; i++) {
52 		serdes_conf = supported_protocols[i];
53 		if (serdes_conf.serdes_block == serdes_block &&
54 		    serdes_conf.serdes_protocol == protocol)
55 			return true;
56 	}
57 
58 	return false;
59 }
60 
get_str_protocol(u8 serdes_block,u32 protocol,char * str)61 static void get_str_protocol(u8 serdes_block, u32 protocol, char *str)
62 {
63 	struct serdes_configuration serdes_conf;
64 	int i;
65 
66 	for (i = 0; i < SUPPORTED_SERDES_PROTOCOLS; i++) {
67 		serdes_conf = supported_protocols[i];
68 		if (serdes_conf.serdes_block == serdes_block &&
69 		    serdes_conf.serdes_protocol == protocol) {
70 			if (serdes_conf.dts_needed == true)
71 				sprintf(str, "%u", protocol);
72 			else
73 				sprintf(str, "x");
74 			return;
75 		}
76 	}
77 }
78 
board_fit_config_name_match(const char * name)79 int board_fit_config_name_match(const char *name)
80 {
81 	struct ccsr_gur *gur = (void *)(CFG_SYS_FSL_GUTS_ADDR);
82 	u32 rcw_status = in_le32(&gur->rcwsr[28]);
83 	char srds_s1_str[2], srds_s2_str[2];
84 	u32 srds_s1, srds_s2;
85 	char expected_dts[100];
86 
87 	srds_s1 = rcw_status & FSL_CHASSIS3_RCWSR28_SRDS1_PRTCL_MASK;
88 	srds_s1 >>= FSL_CHASSIS3_RCWSR28_SRDS1_PRTCL_SHIFT;
89 
90 	srds_s2 = rcw_status & FSL_CHASSIS3_RCWSR28_SRDS2_PRTCL_MASK;
91 	srds_s2 >>= FSL_CHASSIS3_RCWSR28_SRDS2_PRTCL_SHIFT;
92 
93 	/* Check for supported protocols. The default DTS will be used
94 	 * in this case
95 	 */
96 	if (!protocol_supported(1, srds_s1) ||
97 	    !protocol_supported(2, srds_s2))
98 		return -1;
99 
100 	get_str_protocol(1, srds_s1, srds_s1_str);
101 	get_str_protocol(2, srds_s2, srds_s2_str);
102 
103 	printf("expected_dts %s\n", expected_dts);
104 	sprintf(expected_dts, "fsl-ls2080a-qds-%s-%s",
105 		srds_s1_str, srds_s2_str);
106 
107 	if (!strcmp(name, expected_dts))
108 		return 0;
109 
110 	printf("this is not!\n");
111 	return -1;
112 }
113 
114 #endif
115