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