2019-09-09 05:42:30 -04:00
|
|
|
#ifndef __GENERATED_SDRAM_PHY_H
|
|
|
|
#define __GENERATED_SDRAM_PHY_H
|
2021-06-28 09:37:42 -04:00
|
|
|
|
2019-09-09 05:42:30 -04:00
|
|
|
#include <hw/common.h>
|
|
|
|
#include <generated/csr.h>
|
2020-05-19 02:16:11 -04:00
|
|
|
|
2021-06-28 09:37:42 -04:00
|
|
|
#define DFII_CONTROL_SEL 0x01
|
|
|
|
#define DFII_CONTROL_CKE 0x02
|
|
|
|
#define DFII_CONTROL_ODT 0x04
|
|
|
|
#define DFII_CONTROL_RESET_N 0x08
|
2020-05-19 02:16:11 -04:00
|
|
|
|
2021-06-28 09:37:42 -04:00
|
|
|
#define DFII_COMMAND_CS 0x01
|
|
|
|
#define DFII_COMMAND_WE 0x02
|
|
|
|
#define DFII_COMMAND_CAS 0x04
|
|
|
|
#define DFII_COMMAND_RAS 0x08
|
|
|
|
#define DFII_COMMAND_WRDATA 0x10
|
|
|
|
#define DFII_COMMAND_RDDATA 0x20
|
2019-09-09 05:42:30 -04:00
|
|
|
|
2020-04-16 05:38:43 -04:00
|
|
|
#define SDRAM_PHY_USDDRPHY
|
2020-08-07 17:14:09 -04:00
|
|
|
#define SDRAM_PHY_XDR 2
|
|
|
|
#define SDRAM_PHY_DATABITS 64
|
2021-07-20 04:24:11 -04:00
|
|
|
#define SDRAM_PHY_DFI_DATABITS 128
|
2020-04-16 05:38:43 -04:00
|
|
|
#define SDRAM_PHY_PHASES 4
|
2020-09-30 13:49:38 -04:00
|
|
|
#define SDRAM_PHY_CL 9
|
|
|
|
#define SDRAM_PHY_CWL 9
|
2020-12-17 12:21:53 -05:00
|
|
|
#define SDRAM_PHY_CMD_LATENCY 0
|
|
|
|
#define SDRAM_PHY_RDPHASE 3
|
|
|
|
#define SDRAM_PHY_WRPHASE 3
|
2020-04-16 05:38:43 -04:00
|
|
|
#define SDRAM_PHY_WRITE_LEVELING_CAPABLE
|
2020-10-12 12:50:31 -04:00
|
|
|
#define SDRAM_PHY_WRITE_LATENCY_CALIBRATION_CAPABLE
|
2020-04-16 05:38:43 -04:00
|
|
|
#define SDRAM_PHY_READ_LEVELING_CAPABLE
|
2022-03-30 06:59:53 -04:00
|
|
|
#define SDRAM_PHY_DQ_DQS_RATIO 8
|
|
|
|
#define SDRAM_PHY_MODULES 8
|
2020-04-16 05:38:43 -04:00
|
|
|
#define SDRAM_PHY_DELAYS 512
|
2020-09-24 09:03:26 -04:00
|
|
|
#define SDRAM_PHY_BITSLIPS 8
|
2023-01-10 08:45:19 -05:00
|
|
|
#define SDRAM_PHY_DDR4
|
|
|
|
#define SDRAM_PHY_SUPPORTED_MEMORY 0x0000000080000000ULL
|
2019-09-09 05:42:30 -04:00
|
|
|
|
2021-05-26 12:09:26 -04:00
|
|
|
void cdelay(int i);
|
2019-09-09 05:42:30 -04:00
|
|
|
|
2021-05-18 05:26:40 -04:00
|
|
|
__attribute__((unused)) static inline void command_p0(int cmd)
|
2019-09-09 05:42:30 -04:00
|
|
|
{
|
2021-06-28 09:37:42 -04:00
|
|
|
sdram_dfii_pi0_command_write(cmd);
|
|
|
|
sdram_dfii_pi0_command_issue_write(1);
|
2019-09-09 05:42:30 -04:00
|
|
|
}
|
2021-05-18 05:26:40 -04:00
|
|
|
__attribute__((unused)) static inline void command_p1(int cmd)
|
2019-09-09 05:42:30 -04:00
|
|
|
{
|
2021-06-28 09:37:42 -04:00
|
|
|
sdram_dfii_pi1_command_write(cmd);
|
|
|
|
sdram_dfii_pi1_command_issue_write(1);
|
2019-09-09 05:42:30 -04:00
|
|
|
}
|
2021-05-18 05:26:40 -04:00
|
|
|
__attribute__((unused)) static inline void command_p2(int cmd)
|
2019-09-09 05:42:30 -04:00
|
|
|
{
|
2021-06-28 09:37:42 -04:00
|
|
|
sdram_dfii_pi2_command_write(cmd);
|
|
|
|
sdram_dfii_pi2_command_issue_write(1);
|
2019-09-09 05:42:30 -04:00
|
|
|
}
|
2021-05-18 05:26:40 -04:00
|
|
|
__attribute__((unused)) static inline void command_p3(int cmd)
|
2019-09-09 05:42:30 -04:00
|
|
|
{
|
2021-06-28 09:37:42 -04:00
|
|
|
sdram_dfii_pi3_command_write(cmd);
|
|
|
|
sdram_dfii_pi3_command_issue_write(1);
|
2019-09-09 05:42:30 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
#define DFII_PIX_DATA_SIZE CSR_SDRAM_DFII_PI0_WRDATA_SIZE
|
|
|
|
|
2021-06-28 09:37:42 -04:00
|
|
|
static inline unsigned long sdram_dfii_pix_wrdata_addr(int phase)
|
|
|
|
{
|
|
|
|
switch (phase) {
|
|
|
|
case 0: return CSR_SDRAM_DFII_PI0_WRDATA_ADDR;
|
2021-05-18 05:26:40 -04:00
|
|
|
case 1: return CSR_SDRAM_DFII_PI1_WRDATA_ADDR;
|
|
|
|
case 2: return CSR_SDRAM_DFII_PI2_WRDATA_ADDR;
|
|
|
|
case 3: return CSR_SDRAM_DFII_PI3_WRDATA_ADDR;
|
2021-06-28 09:37:42 -04:00
|
|
|
default: return 0;
|
|
|
|
}
|
2021-05-18 05:26:40 -04:00
|
|
|
}
|
2021-06-28 09:37:42 -04:00
|
|
|
static inline unsigned long sdram_dfii_pix_rddata_addr(int phase)
|
|
|
|
{
|
|
|
|
switch (phase) {
|
|
|
|
case 0: return CSR_SDRAM_DFII_PI0_RDDATA_ADDR;
|
2021-05-18 05:26:40 -04:00
|
|
|
case 1: return CSR_SDRAM_DFII_PI1_RDDATA_ADDR;
|
|
|
|
case 2: return CSR_SDRAM_DFII_PI2_RDDATA_ADDR;
|
|
|
|
case 3: return CSR_SDRAM_DFII_PI3_RDDATA_ADDR;
|
2021-06-28 09:37:42 -04:00
|
|
|
default: return 0;
|
|
|
|
}
|
2021-05-18 05:26:40 -04:00
|
|
|
}
|
2021-07-23 08:44:15 -04:00
|
|
|
|
2021-01-29 06:49:19 -05:00
|
|
|
#define DDRX_MR_WRLVL_ADDRESS 1
|
|
|
|
#define DDRX_MR_WRLVL_RESET 769
|
|
|
|
#define DDRX_MR_WRLVL_BIT 7
|
2019-09-09 05:42:30 -04:00
|
|
|
|
2021-05-18 05:26:40 -04:00
|
|
|
static inline void init_sequence(void)
|
2019-09-09 05:42:30 -04:00
|
|
|
{
|
|
|
|
/* Release reset */
|
|
|
|
sdram_dfii_pi0_address_write(0x0);
|
|
|
|
sdram_dfii_pi0_baddress_write(0);
|
|
|
|
sdram_dfii_control_write(DFII_CONTROL_ODT|DFII_CONTROL_RESET_N);
|
|
|
|
cdelay(50000);
|
|
|
|
|
|
|
|
/* Bring CKE high */
|
|
|
|
sdram_dfii_pi0_address_write(0x0);
|
|
|
|
sdram_dfii_pi0_baddress_write(0);
|
|
|
|
sdram_dfii_control_write(DFII_CONTROL_CKE|DFII_CONTROL_ODT|DFII_CONTROL_RESET_N);
|
|
|
|
cdelay(10000);
|
|
|
|
|
|
|
|
/* Load Mode Register 3 */
|
|
|
|
sdram_dfii_pi0_address_write(0x0);
|
|
|
|
sdram_dfii_pi0_baddress_write(3);
|
|
|
|
command_p0(DFII_COMMAND_RAS|DFII_COMMAND_CAS|DFII_COMMAND_WE|DFII_COMMAND_CS);
|
|
|
|
|
|
|
|
/* Load Mode Register 6 */
|
|
|
|
sdram_dfii_pi0_address_write(0x0);
|
|
|
|
sdram_dfii_pi0_baddress_write(6);
|
|
|
|
command_p0(DFII_COMMAND_RAS|DFII_COMMAND_CAS|DFII_COMMAND_WE|DFII_COMMAND_CS);
|
|
|
|
|
|
|
|
/* Load Mode Register 5 */
|
2020-11-17 11:12:02 -05:00
|
|
|
sdram_dfii_pi0_address_write(0x400);
|
2019-09-09 05:42:30 -04:00
|
|
|
sdram_dfii_pi0_baddress_write(5);
|
|
|
|
command_p0(DFII_COMMAND_RAS|DFII_COMMAND_CAS|DFII_COMMAND_WE|DFII_COMMAND_CS);
|
|
|
|
|
|
|
|
/* Load Mode Register 4 */
|
|
|
|
sdram_dfii_pi0_address_write(0x0);
|
|
|
|
sdram_dfii_pi0_baddress_write(4);
|
|
|
|
command_p0(DFII_COMMAND_RAS|DFII_COMMAND_CAS|DFII_COMMAND_WE|DFII_COMMAND_CS);
|
|
|
|
|
|
|
|
/* Load Mode Register 2, CWL=9 */
|
|
|
|
sdram_dfii_pi0_address_write(0x200);
|
|
|
|
sdram_dfii_pi0_baddress_write(2);
|
|
|
|
command_p0(DFII_COMMAND_RAS|DFII_COMMAND_CAS|DFII_COMMAND_WE|DFII_COMMAND_CS);
|
|
|
|
|
|
|
|
/* Load Mode Register 1 */
|
|
|
|
sdram_dfii_pi0_address_write(0x301);
|
|
|
|
sdram_dfii_pi0_baddress_write(1);
|
|
|
|
command_p0(DFII_COMMAND_RAS|DFII_COMMAND_CAS|DFII_COMMAND_WE|DFII_COMMAND_CS);
|
|
|
|
|
2020-09-30 05:51:24 -04:00
|
|
|
/* Load Mode Register 0, CL=9, BL=8 */
|
|
|
|
sdram_dfii_pi0_address_write(0x100);
|
2019-09-09 05:42:30 -04:00
|
|
|
sdram_dfii_pi0_baddress_write(0);
|
|
|
|
command_p0(DFII_COMMAND_RAS|DFII_COMMAND_CAS|DFII_COMMAND_WE|DFII_COMMAND_CS);
|
|
|
|
cdelay(200);
|
|
|
|
|
|
|
|
/* ZQ Calibration */
|
|
|
|
sdram_dfii_pi0_address_write(0x400);
|
|
|
|
sdram_dfii_pi0_baddress_write(0);
|
|
|
|
command_p0(DFII_COMMAND_WE|DFII_COMMAND_CS);
|
|
|
|
cdelay(200);
|
|
|
|
|
|
|
|
}
|
2021-06-28 09:37:42 -04:00
|
|
|
|
|
|
|
#endif /* __GENERATED_SDRAM_PHY_H */
|