19934aba4SIcenowy Zheng /* 29934aba4SIcenowy Zheng * sun8i H3 platform dram controller register and constant defines 39934aba4SIcenowy Zheng * 49934aba4SIcenowy Zheng * (C) Copyright 2007-2015 Allwinner Technology Co. 59934aba4SIcenowy Zheng * Jerry Wang <wangflord@allwinnertech.com> 69934aba4SIcenowy Zheng * (C) Copyright 2015 Vishnu Patekar <vishnupatekar0510@gmail.com> 79934aba4SIcenowy Zheng * (C) Copyright 2014-2015 Hans de Goede <hdegoede@redhat.com> 89934aba4SIcenowy Zheng * (C) Copyright 2015 Jens Kuske <jenskuske@gmail.com> 99934aba4SIcenowy Zheng * 109934aba4SIcenowy Zheng * SPDX-License-Identifier: GPL-2.0+ 119934aba4SIcenowy Zheng */ 129934aba4SIcenowy Zheng 139934aba4SIcenowy Zheng #ifndef _SUNXI_DRAM_SUN8I_H3_H 149934aba4SIcenowy Zheng #define _SUNXI_DRAM_SUN8I_H3_H 159934aba4SIcenowy Zheng 16*1b48bbddSMasahiro Yamada #include <linux/bitops.h> 17*1b48bbddSMasahiro Yamada 189934aba4SIcenowy Zheng struct sunxi_mctl_com_reg { 199934aba4SIcenowy Zheng u32 cr; /* 0x00 control register */ 209934aba4SIcenowy Zheng u32 cr_r1; /* 0x04 rank 1 control register (R40 only) */ 219934aba4SIcenowy Zheng u8 res0[0x4]; /* 0x08 */ 229934aba4SIcenowy Zheng u32 tmr; /* 0x0c (unused on H3) */ 239934aba4SIcenowy Zheng u32 mcr[16][2]; /* 0x10 */ 249934aba4SIcenowy Zheng u32 bwcr; /* 0x90 bandwidth control register */ 259934aba4SIcenowy Zheng u32 maer; /* 0x94 master enable register */ 269934aba4SIcenowy Zheng u32 mapr; /* 0x98 master priority register */ 279934aba4SIcenowy Zheng u32 mcgcr; /* 0x9c */ 289934aba4SIcenowy Zheng u32 cpu_bwcr; /* 0xa0 */ 299934aba4SIcenowy Zheng u32 gpu_bwcr; /* 0xa4 */ 309934aba4SIcenowy Zheng u32 ve_bwcr; /* 0xa8 */ 319934aba4SIcenowy Zheng u32 disp_bwcr; /* 0xac */ 329934aba4SIcenowy Zheng u32 other_bwcr; /* 0xb0 */ 339934aba4SIcenowy Zheng u32 total_bwcr; /* 0xb4 */ 349934aba4SIcenowy Zheng u8 res1[0x8]; /* 0xb8 */ 359934aba4SIcenowy Zheng u32 swonr; /* 0xc0 */ 369934aba4SIcenowy Zheng u32 swoffr; /* 0xc4 */ 379934aba4SIcenowy Zheng u8 res2[0x8]; /* 0xc8 */ 389934aba4SIcenowy Zheng u32 cccr; /* 0xd0 */ 399934aba4SIcenowy Zheng u8 res3[0x54]; /* 0xd4 */ 409934aba4SIcenowy Zheng u32 mdfs_bwlr[3]; /* 0x128 (unused on H3) */ 419934aba4SIcenowy Zheng u8 res4[0x6cc]; /* 0x134 */ 429934aba4SIcenowy Zheng u32 protect; /* 0x800 */ 439934aba4SIcenowy Zheng }; 449934aba4SIcenowy Zheng 459934aba4SIcenowy Zheng #define MCTL_CR_BL8 (0x4 << 20) 469934aba4SIcenowy Zheng 479934aba4SIcenowy Zheng #define MCTL_CR_1T (0x1 << 19) 489934aba4SIcenowy Zheng #define MCTL_CR_2T (0x0 << 19) 499934aba4SIcenowy Zheng 509934aba4SIcenowy Zheng #define MCTL_CR_LPDDR3 (0x7 << 16) 519934aba4SIcenowy Zheng #define MCTL_CR_LPDDR2 (0x6 << 16) 529934aba4SIcenowy Zheng #define MCTL_CR_DDR3 (0x3 << 16) 539934aba4SIcenowy Zheng #define MCTL_CR_DDR2 (0x2 << 16) 549934aba4SIcenowy Zheng 559934aba4SIcenowy Zheng #define MCTL_CR_SEQUENTIAL (0x1 << 15) 569934aba4SIcenowy Zheng #define MCTL_CR_INTERLEAVED (0x0 << 15) 579934aba4SIcenowy Zheng 58f43a0099SIcenowy Zheng #define MCTL_CR_FULL_WIDTH (0x1 << 12) 59f43a0099SIcenowy Zheng #define MCTL_CR_HALF_WIDTH (0x0 << 12) 60f43a0099SIcenowy Zheng #define MCTL_CR_BUS_FULL_WIDTH(x) ((x) << 12) 619934aba4SIcenowy Zheng 629934aba4SIcenowy Zheng #define MCTL_CR_PAGE_SIZE(x) ((fls(x) - 4) << 8) 639934aba4SIcenowy Zheng #define MCTL_CR_ROW_BITS(x) (((x) - 1) << 4) 649934aba4SIcenowy Zheng #define MCTL_CR_EIGHT_BANKS (0x1 << 2) 659934aba4SIcenowy Zheng #define MCTL_CR_FOUR_BANKS (0x0 << 2) 669934aba4SIcenowy Zheng #define MCTL_CR_DUAL_RANK (0x1 << 0) 679934aba4SIcenowy Zheng #define MCTL_CR_SINGLE_RANK (0x0 << 0) 689934aba4SIcenowy Zheng 699934aba4SIcenowy Zheng /* 709934aba4SIcenowy Zheng * CR_R1 is a register found in the R40's DRAM controller. It sets various 719934aba4SIcenowy Zheng * parameters for rank 1. Bits [11:0] have the same meaning as the bits in 729934aba4SIcenowy Zheng * MCTL_CR, but they apply to rank 1 only. This implies we can have 739934aba4SIcenowy Zheng * different chips for rank 1 than rank 0. 749934aba4SIcenowy Zheng * 759934aba4SIcenowy Zheng * As address line A15 and CS1 chip select for rank 1 are muxed on the same 769934aba4SIcenowy Zheng * pin, if single rank is used, A15 must be muxed in. 779934aba4SIcenowy Zheng */ 789934aba4SIcenowy Zheng #define MCTL_CR_R1_MUX_A15 (0x1 << 21) 799934aba4SIcenowy Zheng 809934aba4SIcenowy Zheng #define PROTECT_MAGIC (0x94be6fa3) 819934aba4SIcenowy Zheng 829934aba4SIcenowy Zheng struct sunxi_mctl_ctl_reg { 839934aba4SIcenowy Zheng u32 pir; /* 0x00 PHY initialization register */ 849934aba4SIcenowy Zheng u32 pwrctl; /* 0x04 */ 859934aba4SIcenowy Zheng u32 mrctrl; /* 0x08 */ 869934aba4SIcenowy Zheng u32 clken; /* 0x0c */ 879934aba4SIcenowy Zheng u32 pgsr[2]; /* 0x10 PHY general status registers */ 889934aba4SIcenowy Zheng u32 statr; /* 0x18 */ 899934aba4SIcenowy Zheng u8 res1[0x10]; /* 0x1c */ 909934aba4SIcenowy Zheng u32 lp3mr11; /* 0x2c */ 919934aba4SIcenowy Zheng u32 mr[4]; /* 0x30 mode registers */ 929934aba4SIcenowy Zheng u32 pllgcr; /* 0x40 */ 939934aba4SIcenowy Zheng u32 ptr[5]; /* 0x44 PHY timing registers */ 949934aba4SIcenowy Zheng u32 dramtmg[9]; /* 0x58 DRAM timing registers */ 959934aba4SIcenowy Zheng u32 odtcfg; /* 0x7c */ 969934aba4SIcenowy Zheng u32 pitmg[2]; /* 0x80 PHY interface timing registers */ 979934aba4SIcenowy Zheng u8 res2[0x4]; /* 0x88 */ 989934aba4SIcenowy Zheng u32 rfshctl0; /* 0x8c */ 999934aba4SIcenowy Zheng u32 rfshtmg; /* 0x90 refresh timing */ 1009934aba4SIcenowy Zheng u32 rfshctl1; /* 0x94 */ 1019934aba4SIcenowy Zheng u32 pwrtmg; /* 0x98 */ 1029934aba4SIcenowy Zheng u8 res3[0x1c]; /* 0x9c */ 1039934aba4SIcenowy Zheng u32 vtfcr; /* 0xb8 (unused on H3) */ 1049934aba4SIcenowy Zheng u32 dqsgmr; /* 0xbc */ 1059934aba4SIcenowy Zheng u32 dtcr; /* 0xc0 */ 1069934aba4SIcenowy Zheng u32 dtar[4]; /* 0xc4 */ 1079934aba4SIcenowy Zheng u32 dtdr[2]; /* 0xd4 */ 1089934aba4SIcenowy Zheng u32 dtmr[2]; /* 0xdc */ 1099934aba4SIcenowy Zheng u32 dtbmr; /* 0xe4 */ 1109934aba4SIcenowy Zheng u32 catr[2]; /* 0xe8 */ 1119934aba4SIcenowy Zheng u32 dtedr[2]; /* 0xf0 */ 1129934aba4SIcenowy Zheng u8 res4[0x8]; /* 0xf8 */ 1139934aba4SIcenowy Zheng u32 pgcr[4]; /* 0x100 PHY general configuration registers */ 1149934aba4SIcenowy Zheng u32 iovcr[2]; /* 0x110 */ 1159934aba4SIcenowy Zheng u32 dqsdr; /* 0x118 */ 1169934aba4SIcenowy Zheng u32 dxccr; /* 0x11c */ 1179934aba4SIcenowy Zheng u32 odtmap; /* 0x120 */ 1189934aba4SIcenowy Zheng u32 zqctl[2]; /* 0x124 */ 1199934aba4SIcenowy Zheng u8 res6[0x14]; /* 0x12c */ 1209934aba4SIcenowy Zheng u32 zqcr; /* 0x140 ZQ control register */ 1219934aba4SIcenowy Zheng u32 zqsr; /* 0x144 ZQ status register */ 1229934aba4SIcenowy Zheng u32 zqdr[3]; /* 0x148 ZQ data registers */ 1239934aba4SIcenowy Zheng u8 res7[0x6c]; /* 0x154 */ 1249934aba4SIcenowy Zheng u32 sched; /* 0x1c0 */ 1259934aba4SIcenowy Zheng u32 perfhpr[2]; /* 0x1c4 */ 1269934aba4SIcenowy Zheng u32 perflpr[2]; /* 0x1cc */ 1279934aba4SIcenowy Zheng u32 perfwr[2]; /* 0x1d4 */ 1289934aba4SIcenowy Zheng u8 res8[0x24]; /* 0x1dc */ 1299934aba4SIcenowy Zheng u32 acmdlr; /* 0x200 AC master delay line register */ 1309934aba4SIcenowy Zheng u32 aclcdlr; /* 0x204 AC local calibrated delay line register */ 1319934aba4SIcenowy Zheng u32 aciocr; /* 0x208 AC I/O configuration register */ 1329934aba4SIcenowy Zheng u8 res9[0x4]; /* 0x20c */ 1339934aba4SIcenowy Zheng u32 acbdlr[31]; /* 0x210 AC bit delay line registers */ 1349934aba4SIcenowy Zheng u8 res10[0x74]; /* 0x28c */ 1359934aba4SIcenowy Zheng struct { /* 0x300 DATX8 modules*/ 1369934aba4SIcenowy Zheng u32 mdlr; /* 0x00 master delay line register */ 1379934aba4SIcenowy Zheng u32 lcdlr[3]; /* 0x04 local calibrated delay line registers */ 1389934aba4SIcenowy Zheng u32 bdlr[11]; /* 0x10 bit delay line registers */ 1399934aba4SIcenowy Zheng u32 sdlr; /* 0x3c output enable bit delay registers */ 1409934aba4SIcenowy Zheng u32 gtr; /* 0x40 general timing register */ 1419934aba4SIcenowy Zheng u32 gcr; /* 0x44 general configuration register */ 1429934aba4SIcenowy Zheng u32 gsr[3]; /* 0x48 general status registers */ 1439934aba4SIcenowy Zheng u8 res0[0x2c]; /* 0x54 */ 1449934aba4SIcenowy Zheng } dx[4]; 1459934aba4SIcenowy Zheng u8 res11[0x388]; /* 0x500 */ 1469934aba4SIcenowy Zheng u32 upd2; /* 0x888 */ 1479934aba4SIcenowy Zheng }; 1489934aba4SIcenowy Zheng 1499934aba4SIcenowy Zheng #define PTR3_TDINIT1(x) ((x) << 20) 1509934aba4SIcenowy Zheng #define PTR3_TDINIT0(x) ((x) << 0) 1519934aba4SIcenowy Zheng 1529934aba4SIcenowy Zheng #define PTR4_TDINIT3(x) ((x) << 20) 1539934aba4SIcenowy Zheng #define PTR4_TDINIT2(x) ((x) << 0) 1549934aba4SIcenowy Zheng 1559934aba4SIcenowy Zheng #define DRAMTMG0_TWTP(x) ((x) << 24) 1569934aba4SIcenowy Zheng #define DRAMTMG0_TFAW(x) ((x) << 16) 1579934aba4SIcenowy Zheng #define DRAMTMG0_TRAS_MAX(x) ((x) << 8) 1589934aba4SIcenowy Zheng #define DRAMTMG0_TRAS(x) ((x) << 0) 1599934aba4SIcenowy Zheng 1609934aba4SIcenowy Zheng #define DRAMTMG1_TXP(x) ((x) << 16) 1619934aba4SIcenowy Zheng #define DRAMTMG1_TRTP(x) ((x) << 8) 1629934aba4SIcenowy Zheng #define DRAMTMG1_TRC(x) ((x) << 0) 1639934aba4SIcenowy Zheng 1649934aba4SIcenowy Zheng #define DRAMTMG2_TCWL(x) ((x) << 24) 1659934aba4SIcenowy Zheng #define DRAMTMG2_TCL(x) ((x) << 16) 1669934aba4SIcenowy Zheng #define DRAMTMG2_TRD2WR(x) ((x) << 8) 1679934aba4SIcenowy Zheng #define DRAMTMG2_TWR2RD(x) ((x) << 0) 1689934aba4SIcenowy Zheng 1699934aba4SIcenowy Zheng #define DRAMTMG3_TMRW(x) ((x) << 16) 1709934aba4SIcenowy Zheng #define DRAMTMG3_TMRD(x) ((x) << 12) 1719934aba4SIcenowy Zheng #define DRAMTMG3_TMOD(x) ((x) << 0) 1729934aba4SIcenowy Zheng 1739934aba4SIcenowy Zheng #define DRAMTMG4_TRCD(x) ((x) << 24) 1749934aba4SIcenowy Zheng #define DRAMTMG4_TCCD(x) ((x) << 16) 1759934aba4SIcenowy Zheng #define DRAMTMG4_TRRD(x) ((x) << 8) 1769934aba4SIcenowy Zheng #define DRAMTMG4_TRP(x) ((x) << 0) 1779934aba4SIcenowy Zheng 1789934aba4SIcenowy Zheng #define DRAMTMG5_TCKSRX(x) ((x) << 24) 1799934aba4SIcenowy Zheng #define DRAMTMG5_TCKSRE(x) ((x) << 16) 1809934aba4SIcenowy Zheng #define DRAMTMG5_TCKESR(x) ((x) << 8) 1819934aba4SIcenowy Zheng #define DRAMTMG5_TCKE(x) ((x) << 0) 1829934aba4SIcenowy Zheng 1839934aba4SIcenowy Zheng #define RFSHTMG_TREFI(x) ((x) << 16) 1849934aba4SIcenowy Zheng #define RFSHTMG_TRFC(x) ((x) << 0) 1859934aba4SIcenowy Zheng 1869934aba4SIcenowy Zheng #define PIR_CLRSR (0x1 << 27) /* clear status registers */ 1879934aba4SIcenowy Zheng #define PIR_QSGATE (0x1 << 10) /* Read DQS gate training */ 1889934aba4SIcenowy Zheng #define PIR_DRAMINIT (0x1 << 8) /* DRAM initialization */ 1899934aba4SIcenowy Zheng #define PIR_DRAMRST (0x1 << 7) /* DRAM reset */ 1909934aba4SIcenowy Zheng #define PIR_PHYRST (0x1 << 6) /* PHY reset */ 1919934aba4SIcenowy Zheng #define PIR_DCAL (0x1 << 5) /* DDL calibration */ 1929934aba4SIcenowy Zheng #define PIR_PLLINIT (0x1 << 4) /* PLL initialization */ 1939934aba4SIcenowy Zheng #define PIR_ZCAL (0x1 << 1) /* ZQ calibration */ 1949934aba4SIcenowy Zheng #define PIR_INIT (0x1 << 0) /* PHY initialization trigger */ 1959934aba4SIcenowy Zheng 1969934aba4SIcenowy Zheng #define PGSR_INIT_DONE (0x1 << 0) /* PHY init done */ 1979934aba4SIcenowy Zheng 1989934aba4SIcenowy Zheng #define ZQCR_PWRDOWN (1U << 31) /* ZQ power down */ 1999934aba4SIcenowy Zheng 2009934aba4SIcenowy Zheng #define ACBDLR_WRITE_DELAY(x) ((x) << 8) 2019934aba4SIcenowy Zheng 2029934aba4SIcenowy Zheng #define DXBDLR_DQ(x) (x) /* DQ0-7 BDLR index */ 2039934aba4SIcenowy Zheng #define DXBDLR_DM 8 /* DM BDLR index */ 2049934aba4SIcenowy Zheng #define DXBDLR_DQS 9 /* DQS BDLR index */ 2059934aba4SIcenowy Zheng #define DXBDLR_DQSN 10 /* DQSN BDLR index */ 2069934aba4SIcenowy Zheng 2079934aba4SIcenowy Zheng #define DXBDLR_WRITE_DELAY(x) ((x) << 8) 2089934aba4SIcenowy Zheng #define DXBDLR_READ_DELAY(x) ((x) << 0) 2099934aba4SIcenowy Zheng 210f6457ce5SIcenowy Zheng /* 211f6457ce5SIcenowy Zheng * The delay parameters below allow to allegedly specify delay times of some 212f6457ce5SIcenowy Zheng * unknown unit for each individual bit trace in each of the four data bytes 213f6457ce5SIcenowy Zheng * the 32-bit wide access consists of. Also three control signals can be 214f6457ce5SIcenowy Zheng * adjusted individually. 215f6457ce5SIcenowy Zheng */ 216f6457ce5SIcenowy Zheng #define NR_OF_BYTE_LANES (32 / BITS_PER_BYTE) 217f6457ce5SIcenowy Zheng /* The eight data lines (DQn) plus DM, DQS and DQSN */ 218f6457ce5SIcenowy Zheng #define LINES_PER_BYTE_LANE (BITS_PER_BYTE + 3) 219f6457ce5SIcenowy Zheng struct dram_para { 220f6457ce5SIcenowy Zheng u16 page_size; 221f6457ce5SIcenowy Zheng u8 bus_full_width; 222f6457ce5SIcenowy Zheng u8 dual_rank; 223f6457ce5SIcenowy Zheng u8 row_bits; 224f6457ce5SIcenowy Zheng u8 bank_bits; 225f6457ce5SIcenowy Zheng const u8 dx_read_delays[NR_OF_BYTE_LANES][LINES_PER_BYTE_LANE]; 226f6457ce5SIcenowy Zheng const u8 dx_write_delays[NR_OF_BYTE_LANES][LINES_PER_BYTE_LANE]; 227f6457ce5SIcenowy Zheng const u8 ac_delays[31]; 228f6457ce5SIcenowy Zheng }; 229f6457ce5SIcenowy Zheng ns_to_t(int nanoseconds)230f6457ce5SIcenowy Zhengstatic inline int ns_to_t(int nanoseconds) 231f6457ce5SIcenowy Zheng { 232f6457ce5SIcenowy Zheng const unsigned int ctrl_freq = CONFIG_DRAM_CLK / 2; 233f6457ce5SIcenowy Zheng 234f6457ce5SIcenowy Zheng return DIV_ROUND_UP(ctrl_freq * nanoseconds, 1000); 235f6457ce5SIcenowy Zheng } 236f6457ce5SIcenowy Zheng 237f6457ce5SIcenowy Zheng void mctl_set_timing_params(uint16_t socid, struct dram_para *para); 238f6457ce5SIcenowy Zheng 2399934aba4SIcenowy Zheng #endif /* _SUNXI_DRAM_SUN8I_H3_H */ 240