xref: /rk3399_ARM-atf/drivers/st/ddr/phy/phyinit/include/ddrphy_phyinit_usercustom.h (revision eaaf26e3e6ac347cbfda00b6ba7d327e715d68f0)
1*79629b1aSNicolas Le Bayon /*
2*79629b1aSNicolas Le Bayon  * Copyright (C) 2021-2024, STMicroelectronics - All Rights Reserved
3*79629b1aSNicolas Le Bayon  *
4*79629b1aSNicolas Le Bayon  * SPDX-License-Identifier: BSD-3-Clause
5*79629b1aSNicolas Le Bayon  */
6*79629b1aSNicolas Le Bayon 
7*79629b1aSNicolas Le Bayon #ifndef DDRPHY_PHYINIT_USERCUSTOM_H
8*79629b1aSNicolas Le Bayon #define DDRPHY_PHYINIT_USERCUSTOM_H
9*79629b1aSNicolas Le Bayon 
10*79629b1aSNicolas Le Bayon #include <stdbool.h>
11*79629b1aSNicolas Le Bayon #include <stdint.h>
12*79629b1aSNicolas Le Bayon 
13*79629b1aSNicolas Le Bayon #include <ddrphy_csr_all_cdefines.h>
14*79629b1aSNicolas Le Bayon 
15*79629b1aSNicolas Le Bayon #include <drivers/st/stm32mp2_ddr.h>
16*79629b1aSNicolas Le Bayon 
17*79629b1aSNicolas Le Bayon /* Message Block Structure Definitions */
18*79629b1aSNicolas Le Bayon #if STM32MP_DDR3_TYPE
19*79629b1aSNicolas Le Bayon #include <mnpmusrammsgblock_ddr3.h>
20*79629b1aSNicolas Le Bayon #elif STM32MP_DDR4_TYPE
21*79629b1aSNicolas Le Bayon #include <mnpmusrammsgblock_ddr4.h>
22*79629b1aSNicolas Le Bayon #else /* STM32MP_LPDDR4_TYPE */
23*79629b1aSNicolas Le Bayon #include <mnpmusrammsgblock_lpddr4.h>
24*79629b1aSNicolas Le Bayon #endif /* STM32MP_DDR3_TYPE */
25*79629b1aSNicolas Le Bayon 
26*79629b1aSNicolas Le Bayon /*
27*79629b1aSNicolas Le Bayon  * -------------------------------------------------------------
28*79629b1aSNicolas Le Bayon  * Defines for Firmware Images
29*79629b1aSNicolas Le Bayon  * - indicate IMEM/DMEM address, size (bytes) and offsets.
30*79629b1aSNicolas Le Bayon  * -------------------------------------------------------------
31*79629b1aSNicolas Le Bayon  *
32*79629b1aSNicolas Le Bayon  * IMEM_SIZE max size of instruction memory.
33*79629b1aSNicolas Le Bayon  * DMEM_SIZE max size of data memory.
34*79629b1aSNicolas Le Bayon  *
35*79629b1aSNicolas Le Bayon  * IMEM_ST_ADDR start of IMEM address in memory.
36*79629b1aSNicolas Le Bayon  * DMEM_ST_ADDR start of DMEM address in memory.
37*79629b1aSNicolas Le Bayon  * DMEM_BIN_OFFSET start offset in DMEM memory (message block).
38*79629b1aSNicolas Le Bayon  */
39*79629b1aSNicolas Le Bayon #if STM32MP_DDR3_TYPE
40*79629b1aSNicolas Le Bayon #define IMEM_SIZE			0x4C28U
41*79629b1aSNicolas Le Bayon #define DMEM_SIZE			0x6C8U
42*79629b1aSNicolas Le Bayon #elif STM32MP_DDR4_TYPE
43*79629b1aSNicolas Le Bayon #define IMEM_SIZE			0x6D24U
44*79629b1aSNicolas Le Bayon #define DMEM_SIZE			0x6CCU
45*79629b1aSNicolas Le Bayon #else /* STM32MP_LPDDR4_TYPE */
46*79629b1aSNicolas Le Bayon #define IMEM_SIZE			0x7E50U
47*79629b1aSNicolas Le Bayon #define DMEM_SIZE			0x67CU
48*79629b1aSNicolas Le Bayon #endif /* STM32MP_DDR3_TYPE */
49*79629b1aSNicolas Le Bayon #define IMEM_ST_ADDR			0x50000U
50*79629b1aSNicolas Le Bayon #define DMEM_ST_ADDR			0x54000U
51*79629b1aSNicolas Le Bayon #define DMEM_BIN_OFFSET			0x200U
52*79629b1aSNicolas Le Bayon 
53*79629b1aSNicolas Le Bayon /*
54*79629b1aSNicolas Le Bayon  * ------------------
55*79629b1aSNicolas Le Bayon  * Type definitions
56*79629b1aSNicolas Le Bayon  * ------------------
57*79629b1aSNicolas Le Bayon  */
58*79629b1aSNicolas Le Bayon 
59*79629b1aSNicolas Le Bayon /* A structure used to SRAM memory address space */
60*79629b1aSNicolas Le Bayon enum return_offset_lastaddr {
61*79629b1aSNicolas Le Bayon 	RETURN_OFFSET,
62*79629b1aSNicolas Le Bayon 	RETURN_LASTADDR
63*79629b1aSNicolas Le Bayon };
64*79629b1aSNicolas Le Bayon 
65*79629b1aSNicolas Le Bayon /* Enumeration of instructions for PhyInit Register Interface */
66*79629b1aSNicolas Le Bayon enum reginstr {
67*79629b1aSNicolas Le Bayon 	STARTTRACK,	/* Start register tracking */
68*79629b1aSNicolas Le Bayon 	STOPTRACK,	/* Stop register tracking */
69*79629b1aSNicolas Le Bayon 	SAVEREGS,	/* Save(read) tracked register values */
70*79629b1aSNicolas Le Bayon 	RESTOREREGS,	/* Restore (write) saved register values */
71*79629b1aSNicolas Le Bayon };
72*79629b1aSNicolas Le Bayon 
73*79629b1aSNicolas Le Bayon /* Data structure to store register address/value pairs */
74*79629b1aSNicolas Le Bayon struct reg_addr_val {
75*79629b1aSNicolas Le Bayon 	uint32_t	address;	/* Register address */
76*79629b1aSNicolas Le Bayon 	uint16_t	value;		/* Register value */
77*79629b1aSNicolas Le Bayon };
78*79629b1aSNicolas Le Bayon 
79*79629b1aSNicolas Le Bayon /* Target CSR for the impedance value for ddrphy_phyinit_mapdrvstren() */
80*79629b1aSNicolas Le Bayon enum drvtype {
81*79629b1aSNicolas Le Bayon 	DRVSTRENFSDQP,
82*79629b1aSNicolas Le Bayon 	DRVSTRENFSDQN,
83*79629b1aSNicolas Le Bayon 	ODTSTRENP,
84*79629b1aSNicolas Le Bayon 	ODTSTRENN,
85*79629b1aSNicolas Le Bayon 	ADRVSTRENP,
86*79629b1aSNicolas Le Bayon 	ADRVSTRENN
87*79629b1aSNicolas Le Bayon };
88*79629b1aSNicolas Le Bayon 
89*79629b1aSNicolas Le Bayon /*
90*79629b1aSNicolas Le Bayon  * -------------------------------------------------------------
91*79629b1aSNicolas Le Bayon  * Fixed Function prototypes
92*79629b1aSNicolas Le Bayon  * -------------------------------------------------------------
93*79629b1aSNicolas Le Bayon  */
94*79629b1aSNicolas Le Bayon int ddrphy_phyinit_sequence(struct stm32mp_ddr_config *config, bool skip_training, bool reten);
95*79629b1aSNicolas Le Bayon int ddrphy_phyinit_restore_sequence(void);
96*79629b1aSNicolas Le Bayon int ddrphy_phyinit_c_initphyconfig(struct stm32mp_ddr_config *config,
97*79629b1aSNicolas Le Bayon 				   struct pmu_smb_ddr_1d *mb_ddr_1d, uint32_t *ardptrinitval);
98*79629b1aSNicolas Le Bayon void ddrphy_phyinit_d_loadimem(void);
99*79629b1aSNicolas Le Bayon void ddrphy_phyinit_progcsrskiptrain(struct stm32mp_ddr_config *config,
100*79629b1aSNicolas Le Bayon 				     struct pmu_smb_ddr_1d *mb_ddr_1d, uint32_t ardptrinitval);
101*79629b1aSNicolas Le Bayon int ddrphy_phyinit_f_loaddmem(struct stm32mp_ddr_config *config, struct pmu_smb_ddr_1d *mb_ddr_1d);
102*79629b1aSNicolas Le Bayon int ddrphy_phyinit_g_execfw(void);
103*79629b1aSNicolas Le Bayon void ddrphy_phyinit_i_loadpieimage(struct stm32mp_ddr_config *config, bool skip_training);
104*79629b1aSNicolas Le Bayon void ddrphy_phyinit_loadpieprodcode(void);
105*79629b1aSNicolas Le Bayon int ddrphy_phyinit_mapdrvstren(uint32_t drvstren_ohm, enum drvtype targetcsr);
106*79629b1aSNicolas Le Bayon int ddrphy_phyinit_calcmb(struct stm32mp_ddr_config *config, struct pmu_smb_ddr_1d *mb_ddr_1d);
107*79629b1aSNicolas Le Bayon void ddrphy_phyinit_writeoutmem(uint32_t *mem, uint32_t mem_offset, uint32_t mem_size);
108*79629b1aSNicolas Le Bayon void ddrphy_phyinit_writeoutmsgblk(uint16_t *mem, uint32_t mem_offset, uint32_t mem_size);
109*79629b1aSNicolas Le Bayon int ddrphy_phyinit_isdbytedisabled(struct stm32mp_ddr_config *config,
110*79629b1aSNicolas Le Bayon 				   struct pmu_smb_ddr_1d *mb_ddr_1d, uint32_t dbytenumber);
111*79629b1aSNicolas Le Bayon int ddrphy_phyinit_trackreg(uint32_t adr);
112*79629b1aSNicolas Le Bayon int ddrphy_phyinit_reginterface(enum reginstr myreginstr, uint32_t adr, uint16_t dat);
113*79629b1aSNicolas Le Bayon 
114*79629b1aSNicolas Le Bayon void ddrphy_phyinit_usercustom_custompretrain(struct stm32mp_ddr_config *config);
115*79629b1aSNicolas Le Bayon int ddrphy_phyinit_usercustom_g_waitfwdone(void);
116*79629b1aSNicolas Le Bayon int ddrphy_phyinit_usercustom_saveretregs(struct stm32mp_ddr_config *config);
117*79629b1aSNicolas Le Bayon 
118*79629b1aSNicolas Le Bayon #endif /* DDRPHY_PHYINIT_USERCUSTOM_H */
119