Tom Rini | 10e4779 | 2018-05-06 17:58:06 -0400 | [diff] [blame] | 1 | // SPDX-License-Identifier: GPL-2.0+ |
Prabhakar Kushwaha | c158fad | 2015-03-20 19:28:26 -0700 | [diff] [blame] | 2 | /* |
| 3 | * Copyright 2015 Freescale Semiconductor, Inc. |
Prabhakar Kushwaha | c158fad | 2015-03-20 19:28:26 -0700 | [diff] [blame] | 4 | */ |
| 5 | |
Tom Rini | 44de6a9 | 2023-11-01 12:28:17 -0400 | [diff] [blame] | 6 | #include <vsprintf.h> |
| 7 | #include <linux/string.h> |
Prabhakar Kushwaha | c158fad | 2015-03-20 19:28:26 -0700 | [diff] [blame] | 8 | #include <asm/io.h> |
| 9 | #include <asm/arch/fsl_serdes.h> |
Bogdan Purcareata | 08bc014 | 2017-05-24 16:40:21 +0000 | [diff] [blame] | 10 | #include <fsl-mc/fsl_mc.h> |
Prabhakar Kushwaha | c158fad | 2015-03-20 19:28:26 -0700 | [diff] [blame] | 11 | |
Pratiyush Mohan Srivastava | 9abba11 | 2016-01-20 12:29:03 +0530 | [diff] [blame] | 12 | #define MC_BOOT_ENV_VAR "mcinitcmd" |
Prabhakar Kushwaha | c158fad | 2015-03-20 19:28:26 -0700 | [diff] [blame] | 13 | |
Bogdan Purcareata | 08bc014 | 2017-05-24 16:40:21 +0000 | [diff] [blame] | 14 | #if defined(CONFIG_RESET_PHY_R) |
| 15 | void reset_phy(void) |
| 16 | { |
| 17 | mc_env_boot(); |
| 18 | } |
| 19 | #endif /* CONFIG_RESET_PHY_R */ |
Ioana Ciornei | d838b56 | 2020-05-18 14:48:36 +0300 | [diff] [blame] | 20 | |
Ioana Ciornei | 9d249b3 | 2023-02-15 17:31:18 +0200 | [diff] [blame] | 21 | #if defined(CONFIG_MULTI_DTB_FIT) |
Ioana Ciornei | d838b56 | 2020-05-18 14:48:36 +0300 | [diff] [blame] | 22 | |
Ioana Ciornei | 9d249b3 | 2023-02-15 17:31:18 +0200 | [diff] [blame] | 23 | /* Structure to hold SERDES protocols supported (network interfaces are |
| 24 | * described in the DTS). |
Ioana Ciornei | d838b56 | 2020-05-18 14:48:36 +0300 | [diff] [blame] | 25 | * |
| 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 | */ |
| 34 | static 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 | |
| 48 | static 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 | |
| 63 | static 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 | |
| 81 | int board_fit_config_name_match(const char *name) |
| 82 | { |
Tom Rini | 376b88a | 2022-10-28 20:27:13 -0400 | [diff] [blame] | 83 | struct ccsr_gur *gur = (void *)(CFG_SYS_FSL_GUTS_ADDR); |
Ioana Ciornei | d838b56 | 2020-05-18 14:48:36 +0300 | [diff] [blame] | 84 | 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 |