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