blob: 68c7705178710804b16fa4814c7b53b1d5ad8268 [file] [log] [blame]
Chandan Nath62d7fe7c2011-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 Denk1a459662013-07-08 09:37:19 +02008 * SPDX-License-Identifier: GPL-2.0+
Chandan Nath62d7fe7c2011-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 Rinib971dfa2012-07-03 09:20:06 -070016#include <asm/arch/sys_proto.h>
Chandan Nath62d7fe7c2011-10-14 02:58:24 +000017#include <asm/io.h>
Tom Rinifda35eb2012-07-03 08:51:34 -070018#include <asm/emif.h>
Chandan Nath62d7fe7c2011-10-14 02:58:24 +000019
Matt Porter3ba65f92013-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 Rini942d3f02012-07-30 14:13:16 -070024static struct ddr_ctrl *ddrctrl = (struct ddr_ctrl *)DDR_CTRL_ADDR;
Matt Porter3ba65f92013-03-15 10:07:03 +000025#endif
Lokesh Vutlad3daba12013-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 Rini942d3f02012-07-30 14:13:16 -070031
Tom Rini86277332017-05-16 14:46:35 -040032#ifdef CONFIG_TI814X
Matt Porter4fab8d72013-03-15 10:07:07 +000033void config_dmm(const struct dmm_lisa_map_regs *regs)
34{
Tom Rini86277332017-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 Porter4fab8d72013-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 Kipiszc5c7a7c2013-07-18 15:13:04 -040050#endif
Matt Porter4fab8d72013-03-15 10:07:07 +000051
Matt Porter3ba65f92013-03-15 10:07:03 +000052static void config_vtp(int nr)
Chandan Nath62d7fe7c2011-10-14 02:58:24 +000053{
Matt Porter3ba65f92013-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 Nath62d7fe7c2011-10-14 02:58:24 +000060
61 /* Poll for READY */
Matt Porter3ba65f92013-03-15 10:07:03 +000062 while ((readl(&vtpreg[nr]->vtp0ctrlreg) & VTP_CTRL_READY) !=
Chandan Nath62d7fe7c2011-10-14 02:58:24 +000063 VTP_CTRL_READY)
64 ;
65}
66
Lokesh Vutla94d77fb2013-07-30 10:48:52 +053067void __weak ddr_pll_config(unsigned int ddrpll_m)
68{
69}
70
Lokesh Vutla965de8b2013-12-10 15:02:21 +053071void config_ddr(unsigned int pll, const struct ctrl_ioregs *ioregs,
Peter Korsgaardc00f69d2012-10-18 01:21:12 +000072 const struct ddr_data *data, const struct cmd_control *ctrl,
Matt Porter3ba65f92013-03-15 10:07:03 +000073 const struct emif_regs *regs, int nr)
Chandan Nath62d7fe7c2011-10-14 02:58:24 +000074{
Peter Korsgaardc00f69d2012-10-18 01:21:12 +000075 ddr_pll_config(pll);
Matt Porter3ba65f92013-03-15 10:07:03 +000076 config_vtp(nr);
77 config_cmd_ctrl(ctrl, nr);
Tom Rini318f27c2012-07-30 14:13:56 -070078
Matt Porter3ba65f92013-03-15 10:07:03 +000079 config_ddr_data(data, nr);
80#ifdef CONFIG_AM33XX
Lokesh Vutla965de8b2013-12-10 15:02:21 +053081 config_io_ctrl(ioregs);
Tom Rini318f27c2012-07-30 14:13:56 -070082
83 /* Set CKE to be controlled by EMIF/DDR PHY */
84 writel(DDR_CKE_CTRL_NORMAL, &ddrctrl->ddrckectrl);
James Doublesinfc46bae2014-12-22 16:26:11 -060085
Matt Porter3ba65f92013-03-15 10:07:03 +000086#endif
Lokesh Vutlad3daba12013-12-10 15:02:22 +053087#ifdef CONFIG_AM43XX
88 writel(readl(&cm_device->cm_dll_ctrl) & ~0x1, &cm_device->cm_dll_ctrl);
Jeroen Hofstee878cae62014-06-18 21:22:35 +020089 while ((readl(&cm_device->cm_dll_ctrl) & CM_DLL_READYST) == 0)
Lokesh Vutlad3daba12013-12-10 15:02:22 +053090 ;
Lokesh Vutlad3daba12013-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 Doublesinfc46bae2014-12-22 16:26:11 -060096
Tom Rini7c352cd2015-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 Vutlad3daba12013-12-10 15:02:22 +0530100#endif
101
Tom Rini318f27c2012-07-30 14:13:56 -0700102 /* Program EMIF instance */
Matt Porter3ba65f92013-03-15 10:07:03 +0000103 config_ddr_phy(regs, nr);
104 set_sdram_timings(regs, nr);
Lokesh Vutlad3daba12013-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 Nath62d7fe7c2011-10-14 02:58:24 +0000109}