Stefan Roese | ede2c66 | 2021-04-07 09:12:38 +0200 | [diff] [blame] | 1 | // SPDX-License-Identifier: GPL-2.0+ |
| 2 | /* |
Stefan Roese | 03f13af | 2022-04-07 09:11:54 +0200 | [diff] [blame] | 3 | * Copyright (C) 2021-2022 Stefan Roese <sr@denx.de> |
Stefan Roese | ede2c66 | 2021-04-07 09:12:38 +0200 | [diff] [blame] | 4 | */ |
| 5 | |
| 6 | #include <dm.h> |
| 7 | #include <ram.h> |
Stefan Roese | 03f13af | 2022-04-07 09:11:54 +0200 | [diff] [blame] | 8 | #include <asm/gpio.h> |
Stefan Roese | ede2c66 | 2021-04-07 09:12:38 +0200 | [diff] [blame] | 9 | |
| 10 | #include <mach/octeon_ddr.h> |
| 11 | #include <mach/cvmx-qlm.h> |
| 12 | #include <mach/octeon_qlm.h> |
| 13 | #include <mach/octeon_fdt.h> |
| 14 | #include <mach/cvmx-helper.h> |
| 15 | #include <mach/cvmx-helper-cfg.h> |
| 16 | #include <mach/cvmx-helper-util.h> |
| 17 | #include <mach/cvmx-bgxx-defs.h> |
| 18 | |
| 19 | #include "board_ddr.h" |
| 20 | |
| 21 | #define NIC23_DEF_DRAM_FREQ 800 |
| 22 | |
| 23 | static u8 octeon_nic23_cfg0_spd_values[512] = { |
| 24 | OCTEON_NIC23_CFG0_SPD_VALUES |
| 25 | }; |
| 26 | |
| 27 | static struct ddr_conf board_ddr_conf[] = { |
| 28 | OCTEON_NIC23_DDR_CONFIGURATION |
| 29 | }; |
| 30 | |
| 31 | struct ddr_conf *octeon_ddr_conf_table_get(int *count, int *def_ddr_freq) |
| 32 | { |
| 33 | *count = ARRAY_SIZE(board_ddr_conf); |
| 34 | *def_ddr_freq = NIC23_DEF_DRAM_FREQ; |
| 35 | |
| 36 | return board_ddr_conf; |
| 37 | } |
| 38 | |
| 39 | int board_fix_fdt(void *fdt) |
| 40 | { |
| 41 | u32 range_data[5 * 8]; |
| 42 | bool rev4; |
| 43 | int node; |
| 44 | int rc; |
| 45 | |
| 46 | /* |
| 47 | * ToDo: |
| 48 | * Read rev4 info from EEPROM or where the original U-Boot does |
| 49 | * and don't hard-code it here. |
| 50 | */ |
| 51 | rev4 = true; |
| 52 | |
| 53 | debug("%s() rev4: %s\n", __func__, rev4 ? "true" : "false"); |
| 54 | /* Patch the PHY configuration based on board revision */ |
| 55 | rc = octeon_fdt_patch_rename(fdt, |
| 56 | rev4 ? "4,nor-flash" : "4,no-nor-flash", |
| 57 | "cavium,board-trim", false, NULL, NULL); |
| 58 | if (!rev4) { |
| 59 | /* Modify the ranges for CS 0 */ |
| 60 | node = fdt_node_offset_by_compatible(fdt, -1, |
| 61 | "cavium,octeon-3860-bootbus"); |
| 62 | if (node < 0) { |
| 63 | printf("%s: Error: cannot find boot bus in device tree!\n", |
| 64 | __func__); |
| 65 | return -1; |
| 66 | } |
| 67 | |
| 68 | rc = fdtdec_get_int_array(fdt, node, "ranges", |
| 69 | range_data, 5 * 8); |
| 70 | if (rc) { |
| 71 | printf("%s: Error reading ranges from boot bus FDT\n", |
| 72 | __func__); |
| 73 | return -1; |
| 74 | } |
| 75 | range_data[2] = cpu_to_fdt32(0x10000); |
| 76 | range_data[3] = 0; |
| 77 | range_data[4] = 0; |
| 78 | rc = fdt_setprop(fdt, node, "ranges", range_data, |
| 79 | sizeof(range_data)); |
| 80 | if (rc) { |
| 81 | printf("%s: Error updating boot bus ranges in fdt\n", |
| 82 | __func__); |
| 83 | } |
| 84 | } |
| 85 | return rc; |
| 86 | } |
| 87 | |
Stefan Roese | 03f13af | 2022-04-07 09:11:54 +0200 | [diff] [blame] | 88 | int board_early_init_f(void) |
| 89 | { |
| 90 | struct gpio_desc gpio = {}; |
| 91 | ofnode node; |
| 92 | |
| 93 | /* Initial GPIO configuration */ |
| 94 | |
| 95 | /* GPIO 7: Vitesse reset */ |
| 96 | node = ofnode_by_compatible(ofnode_null(), "vitesse,vsc7224"); |
| 97 | if (ofnode_valid(node)) { |
| 98 | gpio_request_by_name_nodev(node, "los", 0, &gpio, GPIOD_IS_IN); |
| 99 | dm_gpio_free(gpio.dev, &gpio); |
| 100 | gpio_request_by_name_nodev(node, "reset", 0, &gpio, |
| 101 | GPIOD_IS_OUT); |
| 102 | if (dm_gpio_is_valid(&gpio)) { |
| 103 | /* Vitesse reset */ |
| 104 | debug("%s: Setting GPIO 7 to 1\n", __func__); |
| 105 | dm_gpio_set_value(&gpio, 1); |
| 106 | } |
| 107 | dm_gpio_free(gpio.dev, &gpio); |
| 108 | } |
| 109 | |
| 110 | /* SFP+ transmitters */ |
| 111 | ofnode_for_each_compatible_node(node, "ethernet,sfp-slot") { |
| 112 | gpio_request_by_name_nodev(node, "tx_disable", 0, |
| 113 | &gpio, GPIOD_IS_OUT); |
| 114 | if (dm_gpio_is_valid(&gpio)) { |
| 115 | debug("%s: Setting GPIO %d to 1\n", __func__, |
| 116 | gpio.offset); |
| 117 | dm_gpio_set_value(&gpio, 1); |
| 118 | } |
| 119 | dm_gpio_free(gpio.dev, &gpio); |
| 120 | gpio_request_by_name_nodev(node, "mod_abs", 0, &gpio, |
| 121 | GPIOD_IS_IN); |
| 122 | dm_gpio_free(gpio.dev, &gpio); |
| 123 | gpio_request_by_name_nodev(node, "tx_error", 0, &gpio, |
| 124 | GPIOD_IS_IN); |
| 125 | dm_gpio_free(gpio.dev, &gpio); |
| 126 | gpio_request_by_name_nodev(node, "rx_los", 0, &gpio, |
| 127 | GPIOD_IS_IN); |
| 128 | dm_gpio_free(gpio.dev, &gpio); |
| 129 | } |
| 130 | |
| 131 | return 0; |
| 132 | } |
| 133 | |
Stefan Roese | ede2c66 | 2021-04-07 09:12:38 +0200 | [diff] [blame] | 134 | void board_configure_qlms(void) |
| 135 | { |
| 136 | octeon_configure_qlm(4, 3000, CVMX_QLM_MODE_SATA_2X1, 0, 0, 0, 0); |
| 137 | octeon_configure_qlm(5, 103125, CVMX_QLM_MODE_XFI_1X2, 0, 0, 2, 0); |
| 138 | /* Apply amplitude tuning to 10G interface */ |
| 139 | octeon_qlm_tune_v3(0, 4, 3000, -1, -1, 7, -1); |
| 140 | octeon_qlm_tune_v3(0, 5, 103125, 0x19, 0x0, -1, -1); |
| 141 | octeon_qlm_set_channel_v3(0, 5, 0); |
| 142 | octeon_qlm_dfe_disable(0, 5, -1, 103125, CVMX_QLM_MODE_XFI_1X2); |
| 143 | debug("QLM 4 reference clock: %d\n" |
| 144 | "DLM 5 reference clock: %d\n", |
| 145 | cvmx_qlm_measure_clock(4), cvmx_qlm_measure_clock(5)); |
| 146 | } |
| 147 | |
| 148 | int board_late_init(void) |
| 149 | { |
Stefan Roese | 03f13af | 2022-04-07 09:11:54 +0200 | [diff] [blame] | 150 | struct gpio_desc gpio = {}; |
| 151 | ofnode node; |
| 152 | |
| 153 | /* Turn on SFP+ transmitters */ |
| 154 | ofnode_for_each_compatible_node(node, "ethernet,sfp-slot") { |
| 155 | gpio_request_by_name_nodev(node, "tx_disable", 0, |
| 156 | &gpio, GPIOD_IS_OUT); |
| 157 | if (dm_gpio_is_valid(&gpio)) { |
| 158 | debug("%s: Setting GPIO %d to 0\n", __func__, |
| 159 | gpio.offset); |
| 160 | dm_gpio_set_value(&gpio, 0); |
| 161 | } |
| 162 | dm_gpio_free(gpio.dev, &gpio); |
| 163 | } |
| 164 | |
Stefan Roese | ede2c66 | 2021-04-07 09:12:38 +0200 | [diff] [blame] | 165 | board_configure_qlms(); |
| 166 | |
| 167 | return 0; |
| 168 | } |
Stefan Roese | 03f13af | 2022-04-07 09:11:54 +0200 | [diff] [blame] | 169 | |
| 170 | int last_stage_init(void) |
| 171 | { |
| 172 | struct gpio_desc gpio = {}; |
| 173 | ofnode node; |
| 174 | |
| 175 | node = ofnode_by_compatible(ofnode_null(), "vitesse,vsc7224"); |
| 176 | if (!ofnode_valid(node)) { |
| 177 | printf("Vitesse SPF DT node not found!"); |
| 178 | return 0; |
| 179 | } |
| 180 | |
| 181 | gpio_request_by_name_nodev(node, "reset", 0, &gpio, GPIOD_IS_OUT); |
| 182 | if (dm_gpio_is_valid(&gpio)) { |
| 183 | /* Take Vitesse retimer out of reset */ |
| 184 | debug("%s: Setting GPIO 7 to 0\n", __func__); |
| 185 | dm_gpio_set_value(&gpio, 0); |
| 186 | mdelay(50); |
| 187 | } |
| 188 | dm_gpio_free(gpio.dev, &gpio); |
| 189 | |
| 190 | return 0; |
| 191 | } |