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