xref: /openbmc/u-boot/arch/arm/mach-omap2/am33xx/emif4.c (revision 83d290c56fab2d38cd1ab4c4cc7099559c1d5046)
1*83d290c5STom Rini // SPDX-License-Identifier: GPL-2.0+
2983e3700STom Rini /*
3983e3700STom Rini  * emif4.c
4983e3700STom Rini  *
5983e3700STom Rini  * AM33XX emif4 configuration file
6983e3700STom Rini  *
7983e3700STom Rini  * Copyright (C) 2011, Texas Instruments, Incorporated - http://www.ti.com/
8983e3700STom Rini  */
9983e3700STom Rini 
10983e3700STom Rini #include <common.h>
11983e3700STom Rini #include <asm/arch/cpu.h>
12983e3700STom Rini #include <asm/arch/ddr_defs.h>
13983e3700STom Rini #include <asm/arch/hardware.h>
14983e3700STom Rini #include <asm/arch/clock.h>
15983e3700STom Rini #include <asm/arch/sys_proto.h>
16983e3700STom Rini #include <asm/io.h>
17983e3700STom Rini #include <asm/emif.h>
18983e3700STom Rini 
19983e3700STom Rini static struct vtp_reg *vtpreg[2] = {
20983e3700STom Rini 				(struct vtp_reg *)VTP0_CTRL_ADDR,
21983e3700STom Rini 				(struct vtp_reg *)VTP1_CTRL_ADDR};
22983e3700STom Rini #ifdef CONFIG_AM33XX
23983e3700STom Rini static struct ddr_ctrl *ddrctrl = (struct ddr_ctrl *)DDR_CTRL_ADDR;
24983e3700STom Rini #endif
25983e3700STom Rini #ifdef CONFIG_AM43XX
26983e3700STom Rini static struct ddr_ctrl *ddrctrl = (struct ddr_ctrl *)DDR_CTRL_ADDR;
27983e3700STom Rini static struct cm_device_inst *cm_device =
28983e3700STom Rini 				(struct cm_device_inst *)CM_DEVICE_INST;
29983e3700STom Rini #endif
30983e3700STom Rini 
3186277339STom Rini #ifdef CONFIG_TI814X
config_dmm(const struct dmm_lisa_map_regs * regs)32983e3700STom Rini void config_dmm(const struct dmm_lisa_map_regs *regs)
33983e3700STom Rini {
3486277339STom Rini 	struct dmm_lisa_map_regs *hw_lisa_map_regs =
3586277339STom Rini 				(struct dmm_lisa_map_regs *)DMM_BASE;
3686277339STom Rini 
37983e3700STom Rini 	enable_dmm_clocks();
38983e3700STom Rini 
39983e3700STom Rini 	writel(0, &hw_lisa_map_regs->dmm_lisa_map_3);
40983e3700STom Rini 	writel(0, &hw_lisa_map_regs->dmm_lisa_map_2);
41983e3700STom Rini 	writel(0, &hw_lisa_map_regs->dmm_lisa_map_1);
42983e3700STom Rini 	writel(0, &hw_lisa_map_regs->dmm_lisa_map_0);
43983e3700STom Rini 
44983e3700STom Rini 	writel(regs->dmm_lisa_map_3, &hw_lisa_map_regs->dmm_lisa_map_3);
45983e3700STom Rini 	writel(regs->dmm_lisa_map_2, &hw_lisa_map_regs->dmm_lisa_map_2);
46983e3700STom Rini 	writel(regs->dmm_lisa_map_1, &hw_lisa_map_regs->dmm_lisa_map_1);
47983e3700STom Rini 	writel(regs->dmm_lisa_map_0, &hw_lisa_map_regs->dmm_lisa_map_0);
48983e3700STom Rini }
49983e3700STom Rini #endif
50983e3700STom Rini 
config_vtp(int nr)51983e3700STom Rini static void config_vtp(int nr)
52983e3700STom Rini {
53983e3700STom Rini 	writel(readl(&vtpreg[nr]->vtp0ctrlreg) | VTP_CTRL_ENABLE,
54983e3700STom Rini 			&vtpreg[nr]->vtp0ctrlreg);
55983e3700STom Rini 	writel(readl(&vtpreg[nr]->vtp0ctrlreg) & (~VTP_CTRL_START_EN),
56983e3700STom Rini 			&vtpreg[nr]->vtp0ctrlreg);
57983e3700STom Rini 	writel(readl(&vtpreg[nr]->vtp0ctrlreg) | VTP_CTRL_START_EN,
58983e3700STom Rini 			&vtpreg[nr]->vtp0ctrlreg);
59983e3700STom Rini 
60983e3700STom Rini 	/* Poll for READY */
61983e3700STom Rini 	while ((readl(&vtpreg[nr]->vtp0ctrlreg) & VTP_CTRL_READY) !=
62983e3700STom Rini 			VTP_CTRL_READY)
63983e3700STom Rini 		;
64983e3700STom Rini }
65983e3700STom Rini 
ddr_pll_config(unsigned int ddrpll_m)66983e3700STom Rini void __weak ddr_pll_config(unsigned int ddrpll_m)
67983e3700STom Rini {
68983e3700STom Rini }
69983e3700STom Rini 
config_ddr(unsigned int pll,const struct ctrl_ioregs * ioregs,const struct ddr_data * data,const struct cmd_control * ctrl,const struct emif_regs * regs,int nr)70983e3700STom Rini void config_ddr(unsigned int pll, const struct ctrl_ioregs *ioregs,
71983e3700STom Rini 		const struct ddr_data *data, const struct cmd_control *ctrl,
72983e3700STom Rini 		const struct emif_regs *regs, int nr)
73983e3700STom Rini {
74983e3700STom Rini 	ddr_pll_config(pll);
75983e3700STom Rini 	config_vtp(nr);
76983e3700STom Rini 	config_cmd_ctrl(ctrl, nr);
77983e3700STom Rini 
78983e3700STom Rini 	config_ddr_data(data, nr);
79983e3700STom Rini #ifdef CONFIG_AM33XX
80983e3700STom Rini 	config_io_ctrl(ioregs);
81983e3700STom Rini 
82983e3700STom Rini 	/* Set CKE to be controlled by EMIF/DDR PHY */
83983e3700STom Rini 	writel(DDR_CKE_CTRL_NORMAL, &ddrctrl->ddrckectrl);
84983e3700STom Rini 
85983e3700STom Rini #endif
86983e3700STom Rini #ifdef CONFIG_AM43XX
87983e3700STom Rini 	writel(readl(&cm_device->cm_dll_ctrl) & ~0x1, &cm_device->cm_dll_ctrl);
88983e3700STom Rini 	while ((readl(&cm_device->cm_dll_ctrl) & CM_DLL_READYST) == 0)
89983e3700STom Rini 		;
90983e3700STom Rini 
91983e3700STom Rini 	config_io_ctrl(ioregs);
92983e3700STom Rini 
93983e3700STom Rini 	/* Set CKE to be controlled by EMIF/DDR PHY */
94983e3700STom Rini 	writel(DDR_CKE_CTRL_NORMAL, &ddrctrl->ddrckectrl);
95983e3700STom Rini 
96983e3700STom Rini 	if (emif_sdram_type(regs->sdram_config) == EMIF_SDRAM_TYPE_DDR3)
97e18945adSDave Gerlach #ifndef CONFIG_SPL_RTC_DDR_SUPPORT
98983e3700STom Rini 		/* Allow EMIF to control DDR_RESET */
99983e3700STom Rini 		writel(0x00000000, &ddrctrl->ddrioctrl);
100e18945adSDave Gerlach #else
101e18945adSDave Gerlach 		/* Override EMIF DDR_RESET control */
102e18945adSDave Gerlach 		writel(0x80000000, &ddrctrl->ddrioctrl);
103e18945adSDave Gerlach #endif /* CONFIG_SPL_RTC_DDR_SUPPORT */
104983e3700STom Rini #endif
105983e3700STom Rini 
106983e3700STom Rini 	/* Program EMIF instance */
107983e3700STom Rini 	config_ddr_phy(regs, nr);
108983e3700STom Rini 	set_sdram_timings(regs, nr);
109983e3700STom Rini 	if (get_emif_rev(EMIF1_BASE) == EMIF_4D5)
110983e3700STom Rini 		config_sdram_emif4d5(regs, nr);
111983e3700STom Rini 	else
112983e3700STom Rini 		config_sdram(regs, nr);
113983e3700STom Rini }
114