Tom Rini | 10e4779 | 2018-05-06 17:58:06 -0400 | [diff] [blame] | 1 | // SPDX-License-Identifier: GPL-2.0+ |
Phil Sutter | d76eba6 | 2015-12-25 14:41:25 +0100 | [diff] [blame] | 2 | /* |
| 3 | * |
| 4 | * Copyright (C) 2015 Phil Sutter <phil@nwl.cc> |
Phil Sutter | d76eba6 | 2015-12-25 14:41:25 +0100 | [diff] [blame] | 5 | */ |
| 6 | |
Simon Glass | 9758973 | 2020-05-10 11:40:02 -0600 | [diff] [blame] | 7 | #include <init.h> |
Phil Sutter | d76eba6 | 2015-12-25 14:41:25 +0100 | [diff] [blame] | 8 | #include <miiphy.h> |
Simon Glass | 3ba929a | 2020-10-30 21:38:53 -0600 | [diff] [blame] | 9 | #include <asm/global_data.h> |
Phil Sutter | d76eba6 | 2015-12-25 14:41:25 +0100 | [diff] [blame] | 10 | #include <asm/io.h> |
| 11 | #include <asm/arch/cpu.h> |
| 12 | #include <asm/arch/soc.h> |
Simon Glass | 4dcacfc | 2020-05-10 11:40:13 -0600 | [diff] [blame] | 13 | #include <linux/bitops.h> |
Phil Sutter | d76eba6 | 2015-12-25 14:41:25 +0100 | [diff] [blame] | 14 | #include <linux/mbus.h> |
| 15 | |
| 16 | #include "../drivers/ddr/marvell/axp/ddr3_hw_training.h" |
| 17 | #include "../arch/arm/mach-mvebu/serdes/axp/high_speed_env_spec.h" |
| 18 | #include "../arch/arm/mach-mvebu/serdes/axp/board_env_spec.h" |
| 19 | |
Phil Sutter | e91d688 | 2021-03-05 21:05:11 +0100 | [diff] [blame] | 20 | #include "cmd_syno.h" |
| 21 | |
Phil Sutter | d76eba6 | 2015-12-25 14:41:25 +0100 | [diff] [blame] | 22 | DECLARE_GLOBAL_DATA_PTR; |
| 23 | |
| 24 | /* GPP and MPP settings as found in mvBoardEnvSpec.c of Synology's U-Boot */ |
| 25 | |
| 26 | #define DS414_GPP_OUT_VAL_LOW (BIT(25) | BIT(30)) |
| 27 | #define DS414_GPP_OUT_VAL_MID (BIT(10) | BIT(15)) |
| 28 | #define DS414_GPP_OUT_VAL_HIGH (0) |
| 29 | |
| 30 | #define DS414_GPP_OUT_POL_LOW (0) |
| 31 | #define DS414_GPP_OUT_POL_MID (0) |
| 32 | #define DS414_GPP_OUT_POL_HIGH (0) |
| 33 | |
| 34 | #define DS414_GPP_OUT_ENA_LOW (~(BIT(25) | BIT(30))) |
| 35 | #define DS414_GPP_OUT_ENA_MID (~(BIT(10) | BIT(12) | \ |
| 36 | BIT(13) | BIT(14) | BIT(15))) |
| 37 | #define DS414_GPP_OUT_ENA_HIGH (~0) |
| 38 | |
| 39 | static const u32 ds414_mpp_control[] = { |
| 40 | 0x11111111, |
| 41 | 0x22221111, |
| 42 | 0x22222222, |
| 43 | 0x00000000, |
| 44 | 0x11110000, |
| 45 | 0x00004000, |
| 46 | 0x00000000, |
| 47 | 0x00000000, |
| 48 | 0x00000000 |
| 49 | }; |
| 50 | |
| 51 | /* DDR3 static MC configuration */ |
| 52 | |
| 53 | /* 1G_v1 (4x2Gbits) adapted by DS414 */ |
| 54 | MV_DRAM_MC_INIT syno_ddr3_b0_667_1g_v1[MV_MAX_DDR3_STATIC_SIZE] = { |
| 55 | {0x00001400, 0x73014A28}, /*DDR SDRAM Configuration Register */ |
| 56 | {0x00001404, 0x30000800}, /*Dunit Control Low Register */ |
| 57 | {0x00001408, 0x44148887}, /*DDR SDRAM Timing (Low) Register */ |
| 58 | {0x0000140C, 0x3AD83FEA}, /*DDR SDRAM Timing (High) Register */ |
| 59 | |
| 60 | {0x00001410, 0x14000000}, /*DDR SDRAM Address Control Register */ |
| 61 | |
| 62 | {0x00001414, 0x00000000}, /*DDR SDRAM Open Pages Control Register */ |
| 63 | {0x00001418, 0x00000e00}, /*DDR SDRAM Operation Register */ |
| 64 | {0x00001420, 0x00000004}, /*DDR SDRAM Extended Mode Register */ |
| 65 | {0x00001424, 0x0000F3FF}, /*Dunit Control High Register */ |
| 66 | {0x00001428, 0x000F8830}, /*Dunit Control High Register */ |
| 67 | {0x0000142C, 0x054C36F4}, /*Dunit Control High Register */ |
| 68 | {0x0000147C, 0x0000C671}, |
| 69 | |
| 70 | {0x000014a0, 0x00000001}, |
| 71 | {0x000014a8, 0x00000100}, /*2:1 */ |
| 72 | {0x00020220, 0x00000006}, |
| 73 | |
| 74 | {0x00001494, 0x00010000}, /*DDR SDRAM ODT Control (Low) Register */ |
| 75 | {0x00001498, 0x00000000}, /*DDR SDRAM ODT Control (High) Register */ |
| 76 | {0x0000149C, 0x00000001}, /*DDR Dunit ODT Control Register */ |
| 77 | |
| 78 | {0x000014C0, 0x192424C9}, /* DRAM address and Control Driving Strenght */ |
| 79 | {0x000014C4, 0x0AAA24C9}, /* DRAM Data and DQS Driving Strenght */ |
| 80 | |
| 81 | {0x000200e8, 0x3FFF0E01}, /* DO NOT Modify - Open Mbus Window - 2G - Mbus is required for the training sequence*/ |
| 82 | {0x00020184, 0x3FFFFFE0}, /* DO NOT Modify - Close fast path Window to - 2G */ |
| 83 | |
| 84 | {0x0001504, 0x3FFFFFE1}, /* CS0 Size */ |
| 85 | {0x000150C, 0x00000000}, /* CS1 Size */ |
| 86 | {0x0001514, 0x00000000}, /* CS2 Size */ |
| 87 | {0x000151C, 0x00000000}, /* CS3 Size */ |
| 88 | |
| 89 | {0x00001538, 0x00000009}, /*Read Data Sample Delays Register */ |
| 90 | {0x0000153C, 0x00000009}, /*Read Data Ready Delay Register */ |
| 91 | |
| 92 | {0x000015D0, 0x00000650}, /*MR0 */ |
| 93 | {0x000015D4, 0x00000044}, /*MR1 */ |
| 94 | {0x000015D8, 0x00000010}, /*MR2 */ |
| 95 | {0x000015DC, 0x00000000}, /*MR3 */ |
| 96 | |
| 97 | {0x000015E4, 0x00203c18}, /*ZQC Configuration Register */ |
| 98 | {0x000015EC, 0xF800A225}, /*DDR PHY */ |
| 99 | |
| 100 | {0x0, 0x0} |
| 101 | }; |
| 102 | |
| 103 | MV_DRAM_MODES ds414_ddr_modes[MV_DDR3_MODES_NUMBER] = { |
| 104 | {"ds414_1333-667", 0x3, 0x5, 0x0, A0, syno_ddr3_b0_667_1g_v1, NULL}, |
| 105 | }; |
| 106 | |
| 107 | extern MV_SERDES_CHANGE_M_PHY serdes_change_m_phy[]; |
| 108 | |
| 109 | MV_BIN_SERDES_CFG ds414_serdes_cfg[] = { |
| 110 | { MV_PEX_ROOT_COMPLEX, 0x02011111, 0x00000000, |
| 111 | { PEX_BUS_MODE_X4, PEX_BUS_MODE_X1, PEX_BUS_DISABLED, |
| 112 | PEX_BUS_DISABLED }, |
| 113 | 0x0040, serdes_change_m_phy |
| 114 | } |
| 115 | }; |
| 116 | |
| 117 | MV_DRAM_MODES *ddr3_get_static_ddr_mode(void) |
| 118 | { |
| 119 | return &ds414_ddr_modes[0]; |
| 120 | } |
| 121 | |
Stefan Roese | f00854f | 2019-04-08 14:51:49 +0200 | [diff] [blame] | 122 | MV_BIN_SERDES_CFG *board_serdes_cfg_get(void) |
Phil Sutter | d76eba6 | 2015-12-25 14:41:25 +0100 | [diff] [blame] | 123 | { |
| 124 | return &ds414_serdes_cfg[0]; |
| 125 | } |
| 126 | |
| 127 | u8 board_sat_r_get(u8 dev_num, u8 reg) |
| 128 | { |
Stefan Roese | f00854f | 2019-04-08 14:51:49 +0200 | [diff] [blame] | 129 | return 0xf; /* All PEX ports support PCIe Gen2 */ |
Phil Sutter | d76eba6 | 2015-12-25 14:41:25 +0100 | [diff] [blame] | 130 | } |
| 131 | |
| 132 | int board_early_init_f(void) |
| 133 | { |
| 134 | int i; |
| 135 | |
| 136 | /* Set GPP Out value */ |
| 137 | reg_write(GPP_DATA_OUT_REG(0), DS414_GPP_OUT_VAL_LOW); |
| 138 | reg_write(GPP_DATA_OUT_REG(1), DS414_GPP_OUT_VAL_MID); |
| 139 | reg_write(GPP_DATA_OUT_REG(2), DS414_GPP_OUT_VAL_HIGH); |
| 140 | |
| 141 | /* set GPP polarity */ |
| 142 | reg_write(GPP_DATA_IN_POL_REG(0), DS414_GPP_OUT_POL_LOW); |
| 143 | reg_write(GPP_DATA_IN_POL_REG(1), DS414_GPP_OUT_POL_MID); |
| 144 | reg_write(GPP_DATA_IN_POL_REG(2), DS414_GPP_OUT_POL_HIGH); |
| 145 | |
| 146 | /* Set GPP Out Enable */ |
| 147 | reg_write(GPP_DATA_OUT_EN_REG(0), DS414_GPP_OUT_ENA_LOW); |
| 148 | reg_write(GPP_DATA_OUT_EN_REG(1), DS414_GPP_OUT_ENA_MID); |
| 149 | reg_write(GPP_DATA_OUT_EN_REG(2), DS414_GPP_OUT_ENA_HIGH); |
| 150 | |
| 151 | for (i = 0; i < ARRAY_SIZE(ds414_mpp_control); i++) |
| 152 | reg_write(MPP_CONTROL_REG(i), ds414_mpp_control[i]); |
| 153 | |
| 154 | return 0; |
| 155 | } |
| 156 | |
| 157 | int board_init(void) |
| 158 | { |
| 159 | u32 pwr_mng_ctrl_reg; |
| 160 | |
| 161 | /* Adress of boot parameters */ |
| 162 | gd->bd->bi_boot_params = mvebu_sdram_bar(0) + 0x100; |
| 163 | |
| 164 | /* Gate unused clocks |
| 165 | * |
| 166 | * Note: Disabling unused PCIe lanes will hang PCI bus scan. |
| 167 | * Once this is resolved, bits 10-12, 26 and 27 can be |
| 168 | * unset here as well. |
| 169 | */ |
| 170 | pwr_mng_ctrl_reg = reg_read(POWER_MNG_CTRL_REG); |
| 171 | pwr_mng_ctrl_reg &= ~(BIT(0)); /* Audio */ |
| 172 | pwr_mng_ctrl_reg &= ~(BIT(1) | BIT(2)); /* GE3, GE2 */ |
| 173 | pwr_mng_ctrl_reg &= ~(BIT(14) | BIT(15)); /* SATA0 link and core */ |
| 174 | pwr_mng_ctrl_reg &= ~(BIT(16)); /* LCD */ |
| 175 | pwr_mng_ctrl_reg &= ~(BIT(17)); /* SDIO */ |
| 176 | pwr_mng_ctrl_reg &= ~(BIT(19) | BIT(20)); /* USB1 and USB2 */ |
| 177 | pwr_mng_ctrl_reg &= ~(BIT(29) | BIT(30)); /* SATA1 link and core */ |
| 178 | reg_write(POWER_MNG_CTRL_REG, pwr_mng_ctrl_reg); |
| 179 | |
Phil Sutter | e91d688 | 2021-03-05 21:05:11 +0100 | [diff] [blame] | 180 | return 0; |
| 181 | } |
| 182 | |
| 183 | int misc_init_r(void) |
| 184 | { |
| 185 | if (!env_get("ethaddr")) { |
| 186 | puts("Incomplete environment, populating from SPI flash\n"); |
| 187 | do_syno_populate(0, NULL); |
| 188 | } |
Phil Sutter | d76eba6 | 2015-12-25 14:41:25 +0100 | [diff] [blame] | 189 | return 0; |
| 190 | } |
| 191 | |
| 192 | int checkboard(void) |
| 193 | { |
| 194 | puts("Board: DS414\n"); |
| 195 | |
| 196 | return 0; |
| 197 | } |