Konstantin Porotchkin | 646b5cc | 2018-06-07 18:48:49 +0300 | [diff] [blame] | 1 | /* |
| 2 | * Copyright (C) 2018 Marvell International Ltd. |
| 3 | * |
| 4 | * SPDX-License-Identifier: BSD-3-Clause |
| 5 | * https://spdx.org/licenses |
| 6 | */ |
| 7 | |
| 8 | #include <arch_helpers.h> |
Antonio Nino Diaz | e0f9063 | 2018-12-14 00:18:21 +0000 | [diff] [blame] | 9 | #include <common/debug.h> |
| 10 | #include <drivers/mentor/mi2cv.h> |
| 11 | #include <lib/mmio.h> |
| 12 | |
Konstantin Porotchkin | 646b5cc | 2018-06-07 18:48:49 +0300 | [diff] [blame] | 13 | #include <mv_ddr_if.h> |
| 14 | #include <mvebu_def.h> |
| 15 | #include <plat_marvell.h> |
| 16 | |
| 17 | #define MVEBU_AP_MPP_CTRL0_7_REG MVEBU_AP_MPP_REGS(0) |
| 18 | #define MVEBU_AP_MPP_CTRL4_OFFS 16 |
| 19 | #define MVEBU_AP_MPP_CTRL5_OFFS 20 |
| 20 | #define MVEBU_AP_MPP_CTRL4_I2C0_SDA_ENA 0x3 |
| 21 | #define MVEBU_AP_MPP_CTRL5_I2C0_SCK_ENA 0x3 |
| 22 | |
| 23 | #define MVEBU_CP_MPP_CTRL37_OFFS 20 |
| 24 | #define MVEBU_CP_MPP_CTRL38_OFFS 24 |
| 25 | #define MVEBU_CP_MPP_CTRL37_I2C0_SCK_ENA 0x2 |
| 26 | #define MVEBU_CP_MPP_CTRL38_I2C0_SDA_ENA 0x2 |
| 27 | |
| 28 | #define MVEBU_MPP_CTRL_MASK 0xf |
| 29 | |
| 30 | /* |
| 31 | * This struct provides the DRAM training code with |
| 32 | * the appropriate board DRAM configuration |
| 33 | */ |
| 34 | static struct mv_ddr_topology_map board_topology_map = { |
| 35 | /* MISL board with 1CS 8Gb x4 devices of Micron 2400T */ |
| 36 | DEBUG_LEVEL_ERROR, |
| 37 | 0x1, /* active interfaces */ |
| 38 | /* cs_mask, mirror, dqs_swap, ck_swap X subphys */ |
| 39 | { { { {0x1, 0x0, 0, 0}, /* FIXME: change the cs mask for all 64 bit */ |
| 40 | {0x1, 0x0, 0, 0}, |
| 41 | {0x1, 0x0, 0, 0}, |
| 42 | {0x1, 0x0, 0, 0}, |
| 43 | {0x1, 0x0, 0, 0}, |
| 44 | {0x1, 0x0, 0, 0}, |
| 45 | {0x1, 0x0, 0, 0}, |
| 46 | {0x1, 0x0, 0, 0}, |
| 47 | {0x1, 0x0, 0, 0} }, |
| 48 | /* TODO: double check if the speed bin is 2400T */ |
| 49 | SPEED_BIN_DDR_2400T, /* speed_bin */ |
| 50 | MV_DDR_DEV_WIDTH_8BIT, /* sdram device width */ |
| 51 | MV_DDR_DIE_CAP_8GBIT, /* die capacity */ |
| 52 | MV_DDR_FREQ_SAR, /* frequency */ |
| 53 | 0, 0, /* cas_l, cas_wl */ |
| 54 | MV_DDR_TEMP_LOW} }, /* temperature */ |
Alex Leibovich | ed2fb47 | 2019-02-25 12:24:29 +0200 | [diff] [blame] | 55 | #if DDR32 |
| 56 | MV_DDR_32BIT_ECC_PUP8_BUS_MASK, /* subphys mask */ |
Alex Leibovich | ed2fb47 | 2019-02-25 12:24:29 +0200 | [diff] [blame] | 57 | #else |
Konstantin Porotchkin | 646b5cc | 2018-06-07 18:48:49 +0300 | [diff] [blame] | 58 | MV_DDR_64BIT_ECC_PUP8_BUS_MASK, /* subphys mask */ |
Alex Leibovich | ed2fb47 | 2019-02-25 12:24:29 +0200 | [diff] [blame] | 59 | #endif |
Alex Leibovich | 04a5468 | 2019-03-10 16:45:02 +0200 | [diff] [blame] | 60 | MV_DDR_CFG_SPD, /* ddr configuration data source */ |
Konstantin Porotchkin | 646b5cc | 2018-06-07 18:48:49 +0300 | [diff] [blame] | 61 | { {0} }, /* raw spd data */ |
| 62 | {0}, /* timing parameters */ |
| 63 | { /* electrical configuration */ |
| 64 | { /* memory electrical configuration */ |
| 65 | MV_DDR_RTT_NOM_PARK_RZQ_DISABLE, /* rtt_nom */ |
| 66 | { |
| 67 | MV_DDR_RTT_NOM_PARK_RZQ_DIV4, /* rtt_park 1cs */ |
| 68 | MV_DDR_RTT_NOM_PARK_RZQ_DIV1 /* rtt_park 2cs */ |
| 69 | }, |
| 70 | { |
| 71 | MV_DDR_RTT_WR_DYN_ODT_OFF, /* rtt_wr 1cs */ |
| 72 | MV_DDR_RTT_WR_RZQ_DIV2 /* rtt_wr 2cs */ |
| 73 | }, |
| 74 | MV_DDR_DIC_RZQ_DIV7 /* dic */ |
| 75 | }, |
| 76 | { /* phy electrical configuration */ |
| 77 | MV_DDR_OHM_30, /* data_drv_p */ |
| 78 | MV_DDR_OHM_30, /* data_drv_n */ |
| 79 | MV_DDR_OHM_30, /* ctrl_drv_p */ |
| 80 | MV_DDR_OHM_30, /* ctrl_drv_n */ |
| 81 | { |
| 82 | MV_DDR_OHM_60, /* odt_p 1cs */ |
| 83 | MV_DDR_OHM_120 /* odt_p 2cs */ |
| 84 | }, |
| 85 | { |
| 86 | MV_DDR_OHM_60, /* odt_n 1cs */ |
| 87 | MV_DDR_OHM_120 /* odt_n 2cs */ |
| 88 | }, |
| 89 | }, |
| 90 | { /* mac electrical configuration */ |
| 91 | MV_DDR_ODT_CFG_NORMAL, /* odtcfg_pattern */ |
| 92 | MV_DDR_ODT_CFG_ALWAYS_ON, /* odtcfg_write */ |
| 93 | MV_DDR_ODT_CFG_NORMAL, /* odtcfg_read */ |
| 94 | }, |
| 95 | } |
| 96 | }; |
| 97 | |
| 98 | struct mv_ddr_topology_map *mv_ddr_topology_map_get(void) |
| 99 | { |
| 100 | /* Return the board topology as defined in the board code */ |
| 101 | return &board_topology_map; |
| 102 | } |
| 103 | |
| 104 | static void mpp_config(void) |
| 105 | { |
| 106 | uintptr_t reg; |
| 107 | uint32_t val; |
| 108 | |
| 109 | reg = MVEBU_CP_MPP_REGS(0, 4); |
| 110 | /* configure CP0 MPP 37 and 38 to i2c */ |
| 111 | val = mmio_read_32(reg); |
| 112 | val &= ~((MVEBU_MPP_CTRL_MASK << MVEBU_CP_MPP_CTRL37_OFFS) | |
| 113 | (MVEBU_MPP_CTRL_MASK << MVEBU_CP_MPP_CTRL38_OFFS)); |
| 114 | val |= (MVEBU_CP_MPP_CTRL37_I2C0_SCK_ENA << |
| 115 | MVEBU_CP_MPP_CTRL37_OFFS) | |
| 116 | (MVEBU_CP_MPP_CTRL38_I2C0_SDA_ENA << |
| 117 | MVEBU_CP_MPP_CTRL38_OFFS); |
| 118 | mmio_write_32(reg, val); |
| 119 | } |
| 120 | |
| 121 | /* |
| 122 | * This function may modify the default DRAM parameters |
| 123 | * based on information received from SPD or bootloader |
| 124 | * configuration located on non volatile storage |
| 125 | */ |
| 126 | void plat_marvell_dram_update_topology(void) |
| 127 | { |
| 128 | struct mv_ddr_topology_map *tm = mv_ddr_topology_map_get(); |
| 129 | |
| 130 | INFO("Gathering DRAM information\n"); |
| 131 | |
| 132 | if (tm->cfg_src == MV_DDR_CFG_SPD) { |
| 133 | /* configure MPPs to enable i2c */ |
| 134 | mpp_config(); |
| 135 | |
| 136 | /* initialize i2c */ |
| 137 | i2c_init((void *)MVEBU_CP0_I2C_BASE); |
| 138 | |
| 139 | /* select SPD memory page 0 to access DRAM configuration */ |
| 140 | i2c_write(I2C_SPD_P0_ADDR, 0x0, 1, tm->spd_data.all_bytes, 1); |
| 141 | |
| 142 | /* read data from spd */ |
| 143 | i2c_read(I2C_SPD_ADDR, 0x0, 1, tm->spd_data.all_bytes, |
| 144 | sizeof(tm->spd_data.all_bytes)); |
| 145 | } |
| 146 | } |