blob: 03aedc2e63d56a5ad9c857ec8a550baaca9c6788 [file] [log] [blame]
Masahiro Yamadab614e162014-12-19 20:20:52 +09001/*
2 * UniPhier DDR PHY registers
3 *
Masahiro Yamada585b38c2015-05-29 17:30:08 +09004 * Copyright (C) 2014-2015 Masahiro Yamada <yamada.masahiro@socionext.com>
Masahiro Yamadab614e162014-12-19 20:20:52 +09005 *
6 * SPDX-License-Identifier: GPL-2.0+
7 */
8
9#ifndef ARCH_DDRPHY_REGS_H
10#define ARCH_DDRPHY_REGS_H
11
Masahiro Yamada11d6eff2015-12-16 10:44:28 +090012#include <linux/bitops.h>
Masahiro Yamadab614e162014-12-19 20:20:52 +090013#include <linux/compiler.h>
14
15#ifndef __ASSEMBLY__
16
17struct ddrphy {
18 u32 ridr; /* Revision Identification Register */
19 u32 pir; /* PHY Initialixation Register */
20 u32 pgcr[2]; /* PHY General Configuration Register */
21 u32 pgsr[2]; /* PHY General Status Register */
22 u32 pllcr; /* PLL Control Register */
23 u32 ptr[5]; /* PHY Timing Register */
24 u32 acmdlr; /* AC Master Delay Line Register */
25 u32 acbdlr; /* AC Bit Delay Line Register */
26 u32 aciocr; /* AC I/O Configuration Register */
27 u32 dxccr; /* DATX8 Common Configuration Register */
28 u32 dsgcr; /* DDR System General Configuration Register */
29 u32 dcr; /* DRAM Configuration Register */
30 u32 dtpr[3]; /* DRAM Timing Parameters Register */
31 u32 mr0; /* Mode Register 0 */
32 u32 mr1; /* Mode Register 1 */
33 u32 mr2; /* Mode Register 2 */
34 u32 mr3; /* Mode Register 3 */
35 u32 odtcr; /* ODT Configuration Register */
36 u32 dtcr; /* Data Training Configuration Register */
37 u32 dtar[4]; /* Data Training Address Register */
38 u32 dtdr[2]; /* Data Training Data Register */
39 u32 dtedr[2]; /* Data Training Eye Data Register */
Masahiro Yamada585b38c2015-05-29 17:30:08 +090040 u32 pgcr2; /* PHY General Configuration Register 2 */
41 u32 rsv0[8]; /* Reserved */
42 u32 rdimmgcr[2]; /* RDIMM General Configuration Register */
43 u32 rdimmcr0[2]; /* RDIMM Control Register */
Masahiro Yamadab614e162014-12-19 20:20:52 +090044 u32 dcuar; /* DCU Address Register */
45 u32 dcudr; /* DCU Data Register */
46 u32 dcurr; /* DCU Run Register */
47 u32 dculr; /* DCU Loop Register */
48 u32 dcugcr; /* DCU General Configuration Register */
49 u32 dcutpr; /* DCU Timing Parameters Register */
50 u32 dcusr[2]; /* DCU Status Register */
51 u32 rsv1[8]; /* Reserved */
52 u32 bistrr; /* BIST Run Register */
53 u32 bistwcr; /* BIST Word Count Register */
54 u32 bistmskr[3]; /* BIST Mask Register */
55 u32 bistlsr; /* BIST LFSR Sed Register */
56 u32 bistar[3]; /* BIST Address Register */
57 u32 bistudpr; /* BIST User Data Pattern Register */
58 u32 bistgsr; /* BIST General Status Register */
59 u32 bistwer; /* BIST Word Error Register */
60 u32 bistber[4]; /* BIST Bit Error Register */
61 u32 bistwcsr; /* BIST Word Count Status Register */
62 u32 bistfwr[3]; /* BIST Fail Word Register */
63 u32 rsv2[10]; /* Reserved */
64 u32 gpr[2]; /* General Purpose Register */
65 struct ddrphy_zq { /* ZQ */
66 u32 cr[2]; /* Impedance Control Register */
67 u32 sr[2]; /* Impedance Status Register */
68 } zq[4];
69 struct ddrphy_datx8 { /* DATX8 */
70 u32 gcr; /* General Configuration Register */
71 u32 gsr[2]; /* General Status Register */
72 u32 bdlr[5]; /* Bit Delay Line Register */
73 u32 lcdlr[3]; /* Local Calibrated Delay Line Register */
74 u32 mdlr; /* Master Delay Line Register */
75 u32 gtr; /* General Timing Register */
Masahiro Yamada585b38c2015-05-29 17:30:08 +090076 u32 gsr2; /* General Status Register 2 */
77 u32 rsv[2]; /* Reserved */
Masahiro Yamadab614e162014-12-19 20:20:52 +090078 } dx[9];
Masahiro Yamadad6bc30a2015-01-07 19:41:38 +090079};
Masahiro Yamadab614e162014-12-19 20:20:52 +090080
81#endif /* __ASSEMBLY__ */
82
Masahiro Yamada11d6eff2015-12-16 10:44:28 +090083#define PIR_INIT BIT(0) /* Initialization Trigger */
84#define PIR_ZCAL BIT(1) /* Impedance Calibration */
85#define PIR_PLLINIT BIT(4) /* PLL Initialization */
86#define PIR_DCAL BIT(5) /* DDL Calibration */
87#define PIR_PHYRST BIT(6) /* PHY Reset */
88#define PIR_DRAMRST BIT(7) /* DRAM Reset */
89#define PIR_DRAMINIT BIT(8) /* DRAM Initialization */
90#define PIR_WL BIT(9) /* Write Leveling */
91#define PIR_QSGATE BIT(10) /* Read DQS Gate Training */
92#define PIR_WLADJ BIT(11) /* Write Leveling Adjust */
93#define PIR_RDDSKW BIT(12) /* Read Data Bit Deskew */
94#define PIR_WRDSKW BIT(13) /* Write Data Bit Deskew */
95#define PIR_RDEYE BIT(14) /* Read Data Eye Training */
96#define PIR_WREYE BIT(15) /* Write Data Eye Training */
97#define PIR_LOCKBYP BIT(28) /* PLL Lock Bypass */
98#define PIR_DCALBYP BIT(29) /* DDL Calibration Bypass */
99#define PIR_ZCALBYP BIT(30) /* Impedance Calib Bypass */
100#define PIR_INITBYP BIT(31) /* Initialization Bypass */
Masahiro Yamadab614e162014-12-19 20:20:52 +0900101
Masahiro Yamada11d6eff2015-12-16 10:44:28 +0900102#define PGSR0_IDONE BIT(0) /* Initialization Done */
103#define PGSR0_PLDONE BIT(1) /* PLL Lock Done */
104#define PGSR0_DCDONE BIT(2) /* DDL Calibration Done */
105#define PGSR0_ZCDONE BIT(3) /* Impedance Calibration Done */
106#define PGSR0_DIDONE BIT(4) /* DRAM Initialization Done */
107#define PGSR0_WLDONE BIT(5) /* Write Leveling Done */
108#define PGSR0_QSGDONE BIT(6) /* DQS Gate Training Done */
109#define PGSR0_WLADONE BIT(7) /* Write Leveling Adjust Done */
110#define PGSR0_RDDONE BIT(8) /* Read Bit Deskew Done */
111#define PGSR0_WDDONE BIT(9) /* Write Bit Deskew Done */
112#define PGSR0_REDONE BIT(10) /* Read Eye Training Done */
113#define PGSR0_WEDONE BIT(11) /* Write Eye Training Done */
114#define PGSR0_IERR BIT(16) /* Initialization Error */
115#define PGSR0_PLERR BIT(17) /* PLL Lock Error */
116#define PGSR0_DCERR BIT(18) /* DDL Calibration Error */
117#define PGSR0_ZCERR BIT(19) /* Impedance Calib Error */
118#define PGSR0_DIERR BIT(20) /* DRAM Initialization Error */
119#define PGSR0_WLERR BIT(21) /* Write Leveling Error */
120#define PGSR0_QSGERR BIT(22) /* DQS Gate Training Error */
121#define PGSR0_WLAERR BIT(23) /* Write Leveling Adj Error */
122#define PGSR0_RDERR BIT(24) /* Read Bit Deskew Error */
123#define PGSR0_WDERR BIT(25) /* Write Bit Deskew Error */
124#define PGSR0_REERR BIT(26) /* Read Eye Training Error */
125#define PGSR0_WEERR BIT(27) /* Write Eye Training Error */
Masahiro Yamadab614e162014-12-19 20:20:52 +0900126#define PGSR0_DTERR_SHIFT 28 /* Data Training Error Status*/
127#define PGSR0_DTERR (7 << (PGSR0_DTERR_SHIFT))
Masahiro Yamada11d6eff2015-12-16 10:44:28 +0900128#define PGSR0_APLOCK BIT(31) /* AC PLL Lock */
Masahiro Yamadab614e162014-12-19 20:20:52 +0900129
130#define DXCCR_DQSRES_OPEN (0 << 5)
131#define DXCCR_DQSRES_688_OHM (1 << 5)
132#define DXCCR_DQSRES_611_OHM (2 << 5)
133#define DXCCR_DQSRES_550_OHM (3 << 5)
134#define DXCCR_DQSRES_500_OHM (4 << 5)
135#define DXCCR_DQSRES_458_OHM (5 << 5)
136#define DXCCR_DQSRES_393_OHM (6 << 5)
137#define DXCCR_DQSRES_344_OHM (7 << 5)
138
139#define DXCCR_DQSNRES_OPEN (0 << 9)
140#define DXCCR_DQSNRES_688_OHM (1 << 9)
141#define DXCCR_DQSNRES_611_OHM (2 << 9)
142#define DXCCR_DQSNRES_550_OHM (3 << 9)
143#define DXCCR_DQSNRES_500_OHM (4 << 9)
144#define DXCCR_DQSNRES_458_OHM (5 << 9)
145#define DXCCR_DQSNRES_393_OHM (6 << 9)
146#define DXCCR_DQSNRES_344_OHM (7 << 9)
147
148#define DTCR_DTRANK_SHIFT 4 /* Data Training Rank */
149#define DTCR_DTRANK_MASK (0x3 << (DTCR_DTRANK_SHIFT))
Masahiro Yamada11d6eff2015-12-16 10:44:28 +0900150#define DTCR_DTMPR BIT(6) /* Data Training using MPR */
Masahiro Yamadab04ed732015-12-16 10:42:29 +0900151#define DTCR_RANKEN_SHIFT 24 /* Rank Enable */
152#define DTCR_RANKEN_MASK (0xf << (DTCR_RANKEN_SHIFT))
Masahiro Yamadab614e162014-12-19 20:20:52 +0900153
154#define DXGCR_WLRKEN_SHIFT 26 /* Write Level Rank Enable */
155#define DXGCR_WLRKEN_MASK (0xf << (DXGCR_WLRKEN_SHIFT))
156
157/* SoC-specific parameters */
158#define NR_DATX8_PER_DDRPHY 2
159
Masahiro Yamada8497ccc2015-09-22 00:27:34 +0900160#if defined(CONFIG_ARCH_UNIPHIER_PH1_LD4) || \
161 defined(CONFIG_ARCH_UNIPHIER_PH1_SLD8)
Masahiro Yamadab614e162014-12-19 20:20:52 +0900162#define NR_DDRPHY_PER_CH 1
163#else
164#define NR_DDRPHY_PER_CH 2
165#endif
166
167#define NR_DDRCH 2
168
169#define DDRPHY_BASE(ch, phy) (0x5bc01000 + 0x200000 * (ch) + 0x1000 * (phy))
170
171#ifndef __ASSEMBLY__
Masahiro Yamada323d1f92015-09-22 00:27:39 +0900172int ph1_ld4_ddrphy_init(struct ddrphy __iomem *phy, int freq, int size);
173int ph1_pro4_ddrphy_init(struct ddrphy __iomem *phy, int freq, int size);
174int ph1_sld8_ddrphy_init(struct ddrphy __iomem *phy, int freq, int size);
Masahiro Yamadab614e162014-12-19 20:20:52 +0900175void ddrphy_prepare_training(struct ddrphy __iomem *phy, int rank);
176int ddrphy_training(struct ddrphy __iomem *phy);
177#endif
178
179#endif /* ARCH_DDRPHY_REGS_H */