blob: 55dc3212ab66d1a68b8799a8cd0f90b21bbaee3e [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
20DECLARE_GLOBAL_DATA_PTR;
21
Chandan Nath62d7fe7c2011-10-14 02:58:24 +000022int dram_init(void)
23{
24 /* dram_init must store complete ramsize in gd->ram_size */
25 gd->ram_size = get_ram_size(
26 (void *)CONFIG_SYS_SDRAM_BASE,
27 CONFIG_MAX_RAM_BANK_SIZE);
28 return 0;
29}
30
31void dram_init_banksize(void)
32{
33 gd->bd->bi_dram[0].start = CONFIG_SYS_SDRAM_BASE;
34 gd->bd->bi_dram[0].size = gd->ram_size;
35}
36
37
Steve Kipiszc5c7a7c2013-07-18 15:13:04 -040038#if defined(CONFIG_SPL_BUILD) || defined(CONFIG_NOR_BOOT)
39#ifdef CONFIG_TI81XX
Matt Porter4fab8d72013-03-15 10:07:07 +000040static struct dmm_lisa_map_regs *hw_lisa_map_regs =
41 (struct dmm_lisa_map_regs *)DMM_BASE;
Steve Kipiszc5c7a7c2013-07-18 15:13:04 -040042#endif
Matt Porter3ba65f92013-03-15 10:07:03 +000043static struct vtp_reg *vtpreg[2] = {
44 (struct vtp_reg *)VTP0_CTRL_ADDR,
45 (struct vtp_reg *)VTP1_CTRL_ADDR};
46#ifdef CONFIG_AM33XX
Tom Rini942d3f02012-07-30 14:13:16 -070047static struct ddr_ctrl *ddrctrl = (struct ddr_ctrl *)DDR_CTRL_ADDR;
Matt Porter3ba65f92013-03-15 10:07:03 +000048#endif
Tom Rini942d3f02012-07-30 14:13:16 -070049
Steve Kipiszc5c7a7c2013-07-18 15:13:04 -040050#ifdef CONFIG_TI81XX
Matt Porter4fab8d72013-03-15 10:07:07 +000051void config_dmm(const struct dmm_lisa_map_regs *regs)
52{
53 enable_dmm_clocks();
54
55 writel(0, &hw_lisa_map_regs->dmm_lisa_map_3);
56 writel(0, &hw_lisa_map_regs->dmm_lisa_map_2);
57 writel(0, &hw_lisa_map_regs->dmm_lisa_map_1);
58 writel(0, &hw_lisa_map_regs->dmm_lisa_map_0);
59
60 writel(regs->dmm_lisa_map_3, &hw_lisa_map_regs->dmm_lisa_map_3);
61 writel(regs->dmm_lisa_map_2, &hw_lisa_map_regs->dmm_lisa_map_2);
62 writel(regs->dmm_lisa_map_1, &hw_lisa_map_regs->dmm_lisa_map_1);
63 writel(regs->dmm_lisa_map_0, &hw_lisa_map_regs->dmm_lisa_map_0);
64}
Steve Kipiszc5c7a7c2013-07-18 15:13:04 -040065#endif
Matt Porter4fab8d72013-03-15 10:07:07 +000066
Matt Porter3ba65f92013-03-15 10:07:03 +000067static void config_vtp(int nr)
Chandan Nath62d7fe7c2011-10-14 02:58:24 +000068{
Matt Porter3ba65f92013-03-15 10:07:03 +000069 writel(readl(&vtpreg[nr]->vtp0ctrlreg) | VTP_CTRL_ENABLE,
70 &vtpreg[nr]->vtp0ctrlreg);
71 writel(readl(&vtpreg[nr]->vtp0ctrlreg) & (~VTP_CTRL_START_EN),
72 &vtpreg[nr]->vtp0ctrlreg);
73 writel(readl(&vtpreg[nr]->vtp0ctrlreg) | VTP_CTRL_START_EN,
74 &vtpreg[nr]->vtp0ctrlreg);
Chandan Nath62d7fe7c2011-10-14 02:58:24 +000075
76 /* Poll for READY */
Matt Porter3ba65f92013-03-15 10:07:03 +000077 while ((readl(&vtpreg[nr]->vtp0ctrlreg) & VTP_CTRL_READY) !=
Chandan Nath62d7fe7c2011-10-14 02:58:24 +000078 VTP_CTRL_READY)
79 ;
80}
81
Peter Korsgaardc00f69d2012-10-18 01:21:12 +000082void config_ddr(unsigned int pll, unsigned int ioctrl,
83 const struct ddr_data *data, const struct cmd_control *ctrl,
Matt Porter3ba65f92013-03-15 10:07:03 +000084 const struct emif_regs *regs, int nr)
Chandan Nath62d7fe7c2011-10-14 02:58:24 +000085{
Tom Rini318f27c2012-07-30 14:13:56 -070086 enable_emif_clocks();
Peter Korsgaardc00f69d2012-10-18 01:21:12 +000087 ddr_pll_config(pll);
Matt Porter3ba65f92013-03-15 10:07:03 +000088 config_vtp(nr);
89 config_cmd_ctrl(ctrl, nr);
Tom Rini318f27c2012-07-30 14:13:56 -070090
Matt Porter3ba65f92013-03-15 10:07:03 +000091 config_ddr_data(data, nr);
92#ifdef CONFIG_AM33XX
Peter Korsgaardc00f69d2012-10-18 01:21:12 +000093 config_io_ctrl(ioctrl);
Tom Rini318f27c2012-07-30 14:13:56 -070094
95 /* Set CKE to be controlled by EMIF/DDR PHY */
96 writel(DDR_CKE_CTRL_NORMAL, &ddrctrl->ddrckectrl);
Matt Porter3ba65f92013-03-15 10:07:03 +000097#endif
Tom Rini318f27c2012-07-30 14:13:56 -070098
99 /* Program EMIF instance */
Matt Porter3ba65f92013-03-15 10:07:03 +0000100 config_ddr_phy(regs, nr);
101 set_sdram_timings(regs, nr);
102 config_sdram(regs, nr);
Chandan Nath62d7fe7c2011-10-14 02:58:24 +0000103}
104#endif