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