blob: e6033d251c56a138b4d1f9798df06f67110b232e [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
Tom Rinib7f70462023-12-14 13:16:45 -05006#include <config.h>
Tom Rinib08c38f2023-11-01 12:28:16 -04007#include <vsprintf.h>
8#include <linux/string.h>
Ashish Kumar1ef4c772017-08-31 16:12:55 +05309#include <asm/io.h>
10#include <asm/arch/fsl_serdes.h>
Bogdan Purcareata33ba9392017-10-05 06:56:53 +000011#include <fsl-mc/fsl_mc.h>
Bogdan Purcareata33ba9392017-10-05 06:56:53 +000012
13#if defined(CONFIG_RESET_PHY_R)
14void reset_phy(void)
15{
16 mc_env_boot();
17}
18#endif /* CONFIG_RESET_PHY_R */
Ioana Ciornei666a2fb2020-05-15 09:56:48 +030019
Ioana Ciornei2ead4432023-02-15 17:31:19 +020020#if defined(CONFIG_MULTI_DTB_FIT)
Ioana Ciornei666a2fb2020-05-15 09:56:48 +030021
Ioana Ciornei2ead4432023-02-15 17:31:19 +020022/* Structure to hold SERDES protocols supported (network interfaces are
23 * described in the DTS).
Ioana Ciornei666a2fb2020-05-15 09:56:48 +030024 *
25 * @serdes_block: the index of the SERDES block
26 * @serdes_protocol: the decimal value of the protocol supported
27 * @dts_needed: DTS notes describing the current configuration are needed
28 *
29 * When dts_needed is true, the board_fit_config_name_match() function
30 * will try to exactly match the current configuration of the block with a DTS
31 * name provided.
32 */
33static struct serdes_configuration {
34 u8 serdes_block;
35 u32 serdes_protocol;
36 bool dts_needed;
37} supported_protocols[] = {
38 /* Serdes block #1 */
39 {1, 21, true},
40 {1, 29, true},
41};
42
43#define SUPPORTED_SERDES_PROTOCOLS ARRAY_SIZE(supported_protocols)
44
45static bool protocol_supported(u8 serdes_block, u32 protocol)
46{
47 struct serdes_configuration serdes_conf;
48 int i;
49
50 for (i = 0; i < SUPPORTED_SERDES_PROTOCOLS; i++) {
51 serdes_conf = supported_protocols[i];
52 if (serdes_conf.serdes_block == serdes_block &&
53 serdes_conf.serdes_protocol == protocol)
54 return true;
55 }
56
57 return false;
58}
59
60static void get_str_protocol(u8 serdes_block, u32 protocol, char *str)
61{
62 struct serdes_configuration serdes_conf;
63 int i;
64
65 for (i = 0; i < SUPPORTED_SERDES_PROTOCOLS; i++) {
66 serdes_conf = supported_protocols[i];
67 if (serdes_conf.serdes_block == serdes_block &&
68 serdes_conf.serdes_protocol == protocol) {
69 if (serdes_conf.dts_needed == true)
70 sprintf(str, "%u", protocol);
71 else
72 sprintf(str, "x");
73 return;
74 }
75 }
76}
77
78int board_fit_config_name_match(const char *name)
79{
Tom Rini376b88a2022-10-28 20:27:13 -040080 struct ccsr_gur *gur = (void *)(CFG_SYS_FSL_GUTS_ADDR);
Ioana Ciornei666a2fb2020-05-15 09:56:48 +030081 char expected_dts[100];
82 char srds_s1_str[2];
83 u32 srds_s1, cfg;
84
85 cfg = in_le32(&gur->rcwsr[FSL_CHASSIS3_SRDS1_REGSR - 1]) &
86 FSL_CHASSIS3_SRDS1_PRTCL_MASK;
87 cfg >>= FSL_CHASSIS3_SRDS1_PRTCL_SHIFT;
88 srds_s1 = serdes_get_number(FSL_SRDS_1, cfg);
89
90 /* Check for supported protocols. The default DTS will be used
91 * in this case
92 */
93 if (!protocol_supported(1, srds_s1))
94 return -1;
95
96 get_str_protocol(1, srds_s1, srds_s1_str);
97
98 sprintf(expected_dts, "fsl-ls1088a-qds-%s-x", srds_s1_str);
99
100 if (!strcmp(name, expected_dts))
101 return 0;
102
103 return -1;
104}
105#endif