blob: 45a76a60fa2c09aaee81a285904ebbbe4add1507 [file] [log] [blame]
Tom Rini10e47792018-05-06 17:58:06 -04001/* SPDX-License-Identifier: GPL-2.0+ */
Bo Shenfd12de92013-11-15 11:12:37 +08002/*
3 * Copyright (C) 2013 Atmel Corporation
4 * Bo Shen <voice.shen@atmel.com>
5 *
Wenyou Yang0b326382016-02-01 18:12:16 +08006 * Copyright (C) 2015 Atmel Corporation
7 * Wenyou Yang <wenyou.yang@atmel.com>
Bo Shenfd12de92013-11-15 11:12:37 +08008 */
9
10#ifndef __ATMEL_MPDDRC_H__
11#define __ATMEL_MPDDRC_H__
12
Wenyou Yangaa0a58d2016-02-01 18:12:15 +080013struct atmel_mpddrc_config {
14 u32 mr;
15 u32 rtr;
16 u32 cr;
17 u32 tpr0;
18 u32 tpr1;
19 u32 tpr2;
20 u32 md;
21};
22
Bo Shenfd12de92013-11-15 11:12:37 +080023/*
24 * Only define the needed register in mpddr
25 * If other register needed, will add them later
26 */
27struct atmel_mpddr {
Wenyou Yang0b326382016-02-01 18:12:16 +080028 u32 mr; /* 0x00: Mode Register */
29 u32 rtr; /* 0x04: Refresh Timer Register */
30 u32 cr; /* 0x08: Configuration Register */
31 u32 tpr0; /* 0x0c: Timing Parameter 0 Register */
32 u32 tpr1; /* 0x10: Timing Parameter 1 Register */
33 u32 tpr2; /* 0x14: Timing Parameter 2 Register */
34 u32 reserved; /* 0x18: Reserved */
35 u32 lpr; /* 0x1c: Low-power Register */
36 u32 md; /* 0x20: Memory Device Register */
37 u32 reserved1; /* 0x24: Reserved */
38 u32 lpddr23_lpr; /* 0x28: LPDDR2-LPDDR3 Low-power Register*/
39 u32 cal_mr4; /* 0x2c: Calibration and MR4 Register */
40 u32 tim_cal; /* 0x30: Timing Calibration Register */
41 u32 io_calibr; /* 0x34: IO Calibration */
42 u32 ocms; /* 0x38: OCMS Register */
43 u32 ocms_key1; /* 0x3c: OCMS KEY1 Register */
44 u32 ocms_key2; /* 0x40: OCMS KEY2 Register */
45 u32 conf_arbiter; /* 0x44: Configuration Arbiter Register */
46 u32 timeout; /* 0x48: Timeout Port 0/1/2/3 Register */
47 u32 req_port0123; /* 0x4c: Request Port 0/1/2/3 Register */
48 u32 req_port4567; /* 0x50: Request Port 4/5/6/7 Register */
49 u32 bdw_port0123; /* 0x54: Bandwidth Port 0/1/2/3 Register */
50 u32 bdw_port4567; /* 0x58: Bandwidth Port 4/5/6/7 Register */
51 u32 rd_data_path; /* 0x5c: Read Datapath Register */
52 u32 reserved2[33];
53 u32 wpmr; /* 0xe4: Write Protection Mode Register */
54 u32 wpsr; /* 0xe8: Write Protection Status Register */
55 u32 reserved3[4];
56 u32 version; /* 0xfc: IP version */
Bo Shenfd12de92013-11-15 11:12:37 +080057};
58
Erik van Luijk59d780a2015-08-13 15:43:18 +020059
60int ddr2_init(const unsigned int base,
61 const unsigned int ram_address,
Wenyou Yangaa0a58d2016-02-01 18:12:15 +080062 const struct atmel_mpddrc_config *mpddr_value);
Bo Shenfd12de92013-11-15 11:12:37 +080063
Wenyou Yang0b326382016-02-01 18:12:16 +080064int ddr3_init(const unsigned int base,
65 const unsigned int ram_address,
66 const struct atmel_mpddrc_config *mpddr_value);
67
Bo Shenfd12de92013-11-15 11:12:37 +080068/* Bit field in mode register */
69#define ATMEL_MPDDRC_MR_MODE_NORMAL_CMD 0x0
70#define ATMEL_MPDDRC_MR_MODE_NOP_CMD 0x1
71#define ATMEL_MPDDRC_MR_MODE_PRCGALL_CMD 0x2
72#define ATMEL_MPDDRC_MR_MODE_LMR_CMD 0x3
73#define ATMEL_MPDDRC_MR_MODE_RFSH_CMD 0x4
74#define ATMEL_MPDDRC_MR_MODE_EXT_LMR_CMD 0x5
75#define ATMEL_MPDDRC_MR_MODE_DEEP_CMD 0x6
76#define ATMEL_MPDDRC_MR_MODE_LPDDR2_CMD 0x7
77
78/* Bit field in configuration register */
79#define ATMEL_MPDDRC_CR_NC_MASK 0x3
80#define ATMEL_MPDDRC_CR_NC_COL_9 0x0
81#define ATMEL_MPDDRC_CR_NC_COL_10 0x1
82#define ATMEL_MPDDRC_CR_NC_COL_11 0x2
83#define ATMEL_MPDDRC_CR_NC_COL_12 0x3
84#define ATMEL_MPDDRC_CR_NR_MASK (0x3 << 2)
85#define ATMEL_MPDDRC_CR_NR_ROW_11 (0x0 << 2)
86#define ATMEL_MPDDRC_CR_NR_ROW_12 (0x1 << 2)
87#define ATMEL_MPDDRC_CR_NR_ROW_13 (0x2 << 2)
88#define ATMEL_MPDDRC_CR_NR_ROW_14 (0x3 << 2)
89#define ATMEL_MPDDRC_CR_CAS_MASK (0x7 << 4)
90#define ATMEL_MPDDRC_CR_CAS_DDR_CAS2 (0x2 << 4)
91#define ATMEL_MPDDRC_CR_CAS_DDR_CAS3 (0x3 << 4)
92#define ATMEL_MPDDRC_CR_CAS_DDR_CAS4 (0x4 << 4)
93#define ATMEL_MPDDRC_CR_CAS_DDR_CAS5 (0x5 << 4)
94#define ATMEL_MPDDRC_CR_CAS_DDR_CAS6 (0x6 << 4)
95#define ATMEL_MPDDRC_CR_DLL_RESET_ENABLED (0x1 << 7)
96#define ATMEL_MPDDRC_CR_DIC_DS (0x1 << 8)
97#define ATMEL_MPDDRC_CR_DIS_DLL (0x1 << 9)
Wenyou Yang0151e862017-09-13 14:58:52 +080098#define ATMEL_MPDDRC_CR_ZQ_INIT (0x0 << 10)
99#define ATMEL_MPDDRC_CR_ZQ_LONG (0x1 << 10)
100#define ATMEL_MPDDRC_CR_ZQ_SHORT (0x2 << 10)
101#define ATMEL_MPDDRC_CR_ZQ_RESET (0x3 << 10)
Bo Shenfd12de92013-11-15 11:12:37 +0800102#define ATMEL_MPDDRC_CR_OCD_DEFAULT (0x7 << 12)
Heiko Schocher58342832014-10-31 08:30:59 +0100103#define ATMEL_MPDDRC_CR_DQMS_SHARED (0x1 << 16)
Bo Shenfd12de92013-11-15 11:12:37 +0800104#define ATMEL_MPDDRC_CR_ENRDM_ON (0x1 << 17)
105#define ATMEL_MPDDRC_CR_NB_8BANKS (0x1 << 20)
106#define ATMEL_MPDDRC_CR_NDQS_DISABLED (0x1 << 21)
107#define ATMEL_MPDDRC_CR_DECOD_INTERLEAVED (0x1 << 22)
108#define ATMEL_MPDDRC_CR_UNAL_SUPPORTED (0x1 << 23)
109
110/* Bit field in timing parameter 0 register */
111#define ATMEL_MPDDRC_TPR0_TRAS_OFFSET 0
112#define ATMEL_MPDDRC_TPR0_TRAS_MASK 0xf
113#define ATMEL_MPDDRC_TPR0_TRCD_OFFSET 4
114#define ATMEL_MPDDRC_TPR0_TRCD_MASK 0xf
115#define ATMEL_MPDDRC_TPR0_TWR_OFFSET 8
116#define ATMEL_MPDDRC_TPR0_TWR_MASK 0xf
117#define ATMEL_MPDDRC_TPR0_TRC_OFFSET 12
118#define ATMEL_MPDDRC_TPR0_TRC_MASK 0xf
119#define ATMEL_MPDDRC_TPR0_TRP_OFFSET 16
120#define ATMEL_MPDDRC_TPR0_TRP_MASK 0xf
121#define ATMEL_MPDDRC_TPR0_TRRD_OFFSET 20
122#define ATMEL_MPDDRC_TPR0_TRRD_MASK 0xf
123#define ATMEL_MPDDRC_TPR0_TWTR_OFFSET 24
124#define ATMEL_MPDDRC_TPR0_TWTR_MASK 0x7
125#define ATMEL_MPDDRC_TPR0_RDC_WRRD_OFFSET 27
126#define ATMEL_MPDDRC_TPR0_RDC_WRRD_MASK 0x1
127#define ATMEL_MPDDRC_TPR0_TMRD_OFFSET 28
128#define ATMEL_MPDDRC_TPR0_TMRD_MASK 0xf
129
130/* Bit field in timing parameter 1 register */
131#define ATMEL_MPDDRC_TPR1_TRFC_OFFSET 0
132#define ATMEL_MPDDRC_TPR1_TRFC_MASK 0x7f
133#define ATMEL_MPDDRC_TPR1_TXSNR_OFFSET 8
134#define ATMEL_MPDDRC_TPR1_TXSNR_MASK 0xff
135#define ATMEL_MPDDRC_TPR1_TXSRD_OFFSET 16
136#define ATMEL_MPDDRC_TPR1_TXSRD_MASK 0xff
137#define ATMEL_MPDDRC_TPR1_TXP_OFFSET 24
138#define ATMEL_MPDDRC_TPR1_TXP_MASK 0xf
139
140/* Bit field in timing parameter 2 register */
141#define ATMEL_MPDDRC_TPR2_TXARD_OFFSET 0
142#define ATMEL_MPDDRC_TPR2_TXARD_MASK 0xf
143#define ATMEL_MPDDRC_TPR2_TXARDS_OFFSET 4
144#define ATMEL_MPDDRC_TPR2_TXARDS_MASK 0xf
145#define ATMEL_MPDDRC_TPR2_TRPA_OFFSET 8
146#define ATMEL_MPDDRC_TPR2_TRPA_MASK 0xf
147#define ATMEL_MPDDRC_TPR2_TRTP_OFFSET 12
148#define ATMEL_MPDDRC_TPR2_TRTP_MASK 0x7
149#define ATMEL_MPDDRC_TPR2_TFAW_OFFSET 16
150#define ATMEL_MPDDRC_TPR2_TFAW_MASK 0xf
151
152/* Bit field in Memory Device Register */
Heiko Schochere98ecbc2016-08-17 09:13:23 +0200153#define ATMEL_MPDDRC_MD_SDR_SDRAM 0x0
154#define ATMEL_MPDDRC_MD_LP_SDR_SDRAM 0x1
155#define ATMEL_MPDDRC_MD_DDR_SDRAM 0x2
Bo Shenfd12de92013-11-15 11:12:37 +0800156#define ATMEL_MPDDRC_MD_LPDDR_SDRAM 0x3
Wenyou Yang0b326382016-02-01 18:12:16 +0800157#define ATMEL_MPDDRC_MD_DDR3_SDRAM 0x4
158#define ATMEL_MPDDRC_MD_LPDDR3_SDRAM 0x5
Bo Shenfd12de92013-11-15 11:12:37 +0800159#define ATMEL_MPDDRC_MD_DDR2_SDRAM 0x6
160#define ATMEL_MPDDRC_MD_DBW_MASK (0x1 << 4)
161#define ATMEL_MPDDRC_MD_DBW_32_BITS (0x0 << 4)
162#define ATMEL_MPDDRC_MD_DBW_16_BITS (0x1 << 4)
163
Wenyou Yang0b326382016-02-01 18:12:16 +0800164/* Bit field in I/O Calibration Register */
165#define ATMEL_MPDDRC_IO_CALIBR_RDIV 0x7
166
167#define ATMEL_MPDDRC_IO_CALIBR_LPDDR2_RZQ_34_3 0x1
168#define ATMEL_MPDDRC_IO_CALIBR_LPDDR2_RZQ_40 0x2
169#define ATMEL_MPDDRC_IO_CALIBR_LPDDR2_RZQ_48 0x3
170#define ATMEL_MPDDRC_IO_CALIBR_LPDDR2_RZQ_60 0x4
171#define ATMEL_MPDDRC_IO_CALIBR_LPDDR2_RZQ_80 0x6
172#define ATMEL_MPDDRC_IO_CALIBR_LPDDR2_RZQ_120 0x7
173
174#define ATMEL_MPDDRC_IO_CALIBR_DDR2_RZQ_35 0x2
175#define ATMEL_MPDDRC_IO_CALIBR_DDR2_RZQ_43 0x3
176#define ATMEL_MPDDRC_IO_CALIBR_DDR2_RZQ_52 0x4
177#define ATMEL_MPDDRC_IO_CALIBR_DDR2_RZQ_70 0x6
178#define ATMEL_MPDDRC_IO_CALIBR_DDR2_RZQ_105 0x7
179
180#define ATMEL_MPDDRC_IO_CALIBR_DDR3_RZQ_37 0x2
181#define ATMEL_MPDDRC_IO_CALIBR_DDR3_RZQ_44 0x3
182#define ATMEL_MPDDRC_IO_CALIBR_DDR3_RZQ_55 0x4
183#define ATMEL_MPDDRC_IO_CALIBR_DDR3_RZQ_73 0x6
184#define ATMEL_MPDDRC_IO_CALIBR_DDR3_RZQ_110 0x7
185
186#define ATMEL_MPDDRC_IO_CALIBR_DDR3_RZQ_37 0x2
187#define ATMEL_MPDDRC_IO_CALIBR_DDR3_RZQ_44 0x3
188#define ATMEL_MPDDRC_IO_CALIBR_DDR3_RZQ_55 0x4
189#define ATMEL_MPDDRC_IO_CALIBR_DDR3_RZQ_73 0x6
190#define ATMEL_MPDDRC_IO_CALIBR_DDR3_RZQ_110 0x7
191
Wenyou Yang5a0243e2017-03-23 14:35:33 +0800192#define ATMEL_MPDDRC_IO_CALIBR_TZQIO (0x7f << 8)
Wenyou Yang0b326382016-02-01 18:12:16 +0800193#define ATMEL_MPDDRC_IO_CALIBR_TZQIO_(x) (((x) & 0x7f) << 8)
194
Wenyou Yang5a0243e2017-03-23 14:35:33 +0800195#define ATMEL_MPDDRC_IO_CALIBR_CALCODEP (0xf << 16)
196#define ATMEL_MPDDRC_IO_CALIBR_CALCODEP_(x) (((x) & 0xf) << 16)
197#define ATMEL_MPDDRC_IO_CALIBR_CALCODEN (0xf << 20)
198#define ATMEL_MPDDRC_IO_CALIBR_CALCODEN_(x) (((x) & 0xf) << 20)
199
Wenyou Yang0b326382016-02-01 18:12:16 +0800200#define ATMEL_MPDDRC_IO_CALIBR_EN_CALIB (0x1 << 4)
201
202/* Bit field in Read Data Path Register */
203#define ATMEL_MPDDRC_RD_DATA_PATH_SHIFT_SAMPLING 0x3
204#define ATMEL_MPDDRC_RD_DATA_PATH_NO_SHIFT 0x0
205#define ATMEL_MPDDRC_RD_DATA_PATH_SHIFT_ONE_CYCLE 0x1
206#define ATMEL_MPDDRC_RD_DATA_PATH_SHIFT_TWO_CYCLE 0x2
207#define ATMEL_MPDDRC_RD_DATA_PATH_SHIFT_THREE_CYCLE 0x3
208
Bo Shenfd12de92013-11-15 11:12:37 +0800209#endif