blob: 68c7705178710804b16fa4814c7b53b1d5ad8268 [file] [log] [blame]
Chandan Nath98b036e2011-10-14 02:58:24 +00001/*
2 * emif4.c
3 *
4 * AM33XX emif4 configuration file
5 *
6 * Copyright (C) 2011, Texas Instruments, Incorporated - http://www.ti.com/
7 *
Wolfgang Denkd79de1d2013-07-08 09:37:19 +02008 * SPDX-License-Identifier: GPL-2.0+
Chandan Nath98b036e2011-10-14 02:58:24 +00009 */
10
11#include <common.h>
12#include <asm/arch/cpu.h>
13#include <asm/arch/ddr_defs.h>
14#include <asm/arch/hardware.h>
15#include <asm/arch/clock.h>
Tom Rini034aba72012-07-03 09:20:06 -070016#include <asm/arch/sys_proto.h>
Chandan Nath98b036e2011-10-14 02:58:24 +000017#include <asm/io.h>
Tom Rini3fd44562012-07-03 08:51:34 -070018#include <asm/emif.h>
Chandan Nath98b036e2011-10-14 02:58:24 +000019
Matt Porter65991ec2013-03-15 10:07:03 +000020static struct vtp_reg *vtpreg[2] = {
21 (struct vtp_reg *)VTP0_CTRL_ADDR,
22 (struct vtp_reg *)VTP1_CTRL_ADDR};
23#ifdef CONFIG_AM33XX
Tom Rini4d451122012-07-30 14:13:16 -070024static struct ddr_ctrl *ddrctrl = (struct ddr_ctrl *)DDR_CTRL_ADDR;
Matt Porter65991ec2013-03-15 10:07:03 +000025#endif
Lokesh Vutlaa82d4e12013-12-10 15:02:22 +053026#ifdef CONFIG_AM43XX
27static struct ddr_ctrl *ddrctrl = (struct ddr_ctrl *)DDR_CTRL_ADDR;
28static struct cm_device_inst *cm_device =
29 (struct cm_device_inst *)CM_DEVICE_INST;
30#endif
Tom Rini4d451122012-07-30 14:13:16 -070031
Tom Rinifbb25522017-05-16 14:46:35 -040032#ifdef CONFIG_TI814X
Matt Porter40355102013-03-15 10:07:07 +000033void config_dmm(const struct dmm_lisa_map_regs *regs)
34{
Tom Rinifbb25522017-05-16 14:46:35 -040035 struct dmm_lisa_map_regs *hw_lisa_map_regs =
36 (struct dmm_lisa_map_regs *)DMM_BASE;
37
Matt Porter40355102013-03-15 10:07:07 +000038 enable_dmm_clocks();
39
40 writel(0, &hw_lisa_map_regs->dmm_lisa_map_3);
41 writel(0, &hw_lisa_map_regs->dmm_lisa_map_2);
42 writel(0, &hw_lisa_map_regs->dmm_lisa_map_1);
43 writel(0, &hw_lisa_map_regs->dmm_lisa_map_0);
44
45 writel(regs->dmm_lisa_map_3, &hw_lisa_map_regs->dmm_lisa_map_3);
46 writel(regs->dmm_lisa_map_2, &hw_lisa_map_regs->dmm_lisa_map_2);
47 writel(regs->dmm_lisa_map_1, &hw_lisa_map_regs->dmm_lisa_map_1);
48 writel(regs->dmm_lisa_map_0, &hw_lisa_map_regs->dmm_lisa_map_0);
49}
Steve Kipiszc1399b42013-07-18 15:13:04 -040050#endif
Matt Porter40355102013-03-15 10:07:07 +000051
Matt Porter65991ec2013-03-15 10:07:03 +000052static void config_vtp(int nr)
Chandan Nath98b036e2011-10-14 02:58:24 +000053{
Matt Porter65991ec2013-03-15 10:07:03 +000054 writel(readl(&vtpreg[nr]->vtp0ctrlreg) | VTP_CTRL_ENABLE,
55 &vtpreg[nr]->vtp0ctrlreg);
56 writel(readl(&vtpreg[nr]->vtp0ctrlreg) & (~VTP_CTRL_START_EN),
57 &vtpreg[nr]->vtp0ctrlreg);
58 writel(readl(&vtpreg[nr]->vtp0ctrlreg) | VTP_CTRL_START_EN,
59 &vtpreg[nr]->vtp0ctrlreg);
Chandan Nath98b036e2011-10-14 02:58:24 +000060
61 /* Poll for READY */
Matt Porter65991ec2013-03-15 10:07:03 +000062 while ((readl(&vtpreg[nr]->vtp0ctrlreg) & VTP_CTRL_READY) !=
Chandan Nath98b036e2011-10-14 02:58:24 +000063 VTP_CTRL_READY)
64 ;
65}
66
Lokesh Vutla89a83bf2013-07-30 10:48:52 +053067void __weak ddr_pll_config(unsigned int ddrpll_m)
68{
69}
70
Lokesh Vutla303b2672013-12-10 15:02:21 +053071void config_ddr(unsigned int pll, const struct ctrl_ioregs *ioregs,
Peter Korsgaardeb6cf7b2012-10-18 01:21:12 +000072 const struct ddr_data *data, const struct cmd_control *ctrl,
Matt Porter65991ec2013-03-15 10:07:03 +000073 const struct emif_regs *regs, int nr)
Chandan Nath98b036e2011-10-14 02:58:24 +000074{
Peter Korsgaardeb6cf7b2012-10-18 01:21:12 +000075 ddr_pll_config(pll);
Matt Porter65991ec2013-03-15 10:07:03 +000076 config_vtp(nr);
77 config_cmd_ctrl(ctrl, nr);
Chandan Nath98b036e2011-10-14 02:58:24 +000078
Matt Porter65991ec2013-03-15 10:07:03 +000079 config_ddr_data(data, nr);
80#ifdef CONFIG_AM33XX
Lokesh Vutla303b2672013-12-10 15:02:21 +053081 config_io_ctrl(ioregs);
Chandan Nath98b036e2011-10-14 02:58:24 +000082
Tom Rini4b020fe2012-07-30 14:13:56 -070083 /* Set CKE to be controlled by EMIF/DDR PHY */
84 writel(DDR_CKE_CTRL_NORMAL, &ddrctrl->ddrckectrl);
James Doublesin53c723b2014-12-22 16:26:11 -060085
Matt Porter65991ec2013-03-15 10:07:03 +000086#endif
Lokesh Vutlaa82d4e12013-12-10 15:02:22 +053087#ifdef CONFIG_AM43XX
88 writel(readl(&cm_device->cm_dll_ctrl) & ~0x1, &cm_device->cm_dll_ctrl);
Jeroen Hofstee47c02952014-06-18 21:22:35 +020089 while ((readl(&cm_device->cm_dll_ctrl) & CM_DLL_READYST) == 0)
Lokesh Vutlaa82d4e12013-12-10 15:02:22 +053090 ;
Lokesh Vutlaa82d4e12013-12-10 15:02:22 +053091
92 config_io_ctrl(ioregs);
93
94 /* Set CKE to be controlled by EMIF/DDR PHY */
95 writel(DDR_CKE_CTRL_NORMAL, &ddrctrl->ddrckectrl);
James Doublesin53c723b2014-12-22 16:26:11 -060096
Tom Rinibe8d6352015-06-05 15:51:11 +053097 if (emif_sdram_type(regs->sdram_config) == EMIF_SDRAM_TYPE_DDR3)
98 /* Allow EMIF to control DDR_RESET */
99 writel(0x00000000, &ddrctrl->ddrioctrl);
Lokesh Vutlaa82d4e12013-12-10 15:02:22 +0530100#endif
101
Tom Rini4b020fe2012-07-30 14:13:56 -0700102 /* Program EMIF instance */
Matt Porter65991ec2013-03-15 10:07:03 +0000103 config_ddr_phy(regs, nr);
104 set_sdram_timings(regs, nr);
Lokesh Vutlaa82d4e12013-12-10 15:02:22 +0530105 if (get_emif_rev(EMIF1_BASE) == EMIF_4D5)
106 config_sdram_emif4d5(regs, nr);
107 else
108 config_sdram(regs, nr);
Chandan Nath98b036e2011-10-14 02:58:24 +0000109}