blob: adda650fe8d2cffce2d49cebf150ee5d614657d5 [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
20DECLARE_GLOBAL_DATA_PTR;
21
Chandan Nath98b036e2011-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 Kipiszc1399b42013-07-18 15:13:04 -040038#if defined(CONFIG_SPL_BUILD) || defined(CONFIG_NOR_BOOT)
39#ifdef CONFIG_TI81XX
Matt Porter40355102013-03-15 10:07:07 +000040static struct dmm_lisa_map_regs *hw_lisa_map_regs =
41 (struct dmm_lisa_map_regs *)DMM_BASE;
Steve Kipiszc1399b42013-07-18 15:13:04 -040042#endif
TENART Antoine35c7e522013-07-02 12:05:59 +020043#ifndef CONFIG_TI816X
Matt Porter65991ec2013-03-15 10:07:03 +000044static struct vtp_reg *vtpreg[2] = {
45 (struct vtp_reg *)VTP0_CTRL_ADDR,
46 (struct vtp_reg *)VTP1_CTRL_ADDR};
TENART Antoine35c7e522013-07-02 12:05:59 +020047#endif
Matt Porter65991ec2013-03-15 10:07:03 +000048#ifdef CONFIG_AM33XX
Tom Rini4d451122012-07-30 14:13:16 -070049static struct ddr_ctrl *ddrctrl = (struct ddr_ctrl *)DDR_CTRL_ADDR;
Matt Porter65991ec2013-03-15 10:07:03 +000050#endif
Tom Rini4d451122012-07-30 14:13:16 -070051
Steve Kipiszc1399b42013-07-18 15:13:04 -040052#ifdef CONFIG_TI81XX
Matt Porter40355102013-03-15 10:07:07 +000053void config_dmm(const struct dmm_lisa_map_regs *regs)
54{
55 enable_dmm_clocks();
56
57 writel(0, &hw_lisa_map_regs->dmm_lisa_map_3);
58 writel(0, &hw_lisa_map_regs->dmm_lisa_map_2);
59 writel(0, &hw_lisa_map_regs->dmm_lisa_map_1);
60 writel(0, &hw_lisa_map_regs->dmm_lisa_map_0);
61
62 writel(regs->dmm_lisa_map_3, &hw_lisa_map_regs->dmm_lisa_map_3);
63 writel(regs->dmm_lisa_map_2, &hw_lisa_map_regs->dmm_lisa_map_2);
64 writel(regs->dmm_lisa_map_1, &hw_lisa_map_regs->dmm_lisa_map_1);
65 writel(regs->dmm_lisa_map_0, &hw_lisa_map_regs->dmm_lisa_map_0);
66}
Steve Kipiszc1399b42013-07-18 15:13:04 -040067#endif
Matt Porter40355102013-03-15 10:07:07 +000068
TENART Antoine35c7e522013-07-02 12:05:59 +020069#ifndef CONFIG_TI816X
Matt Porter65991ec2013-03-15 10:07:03 +000070static void config_vtp(int nr)
Chandan Nath98b036e2011-10-14 02:58:24 +000071{
Matt Porter65991ec2013-03-15 10:07:03 +000072 writel(readl(&vtpreg[nr]->vtp0ctrlreg) | VTP_CTRL_ENABLE,
73 &vtpreg[nr]->vtp0ctrlreg);
74 writel(readl(&vtpreg[nr]->vtp0ctrlreg) & (~VTP_CTRL_START_EN),
75 &vtpreg[nr]->vtp0ctrlreg);
76 writel(readl(&vtpreg[nr]->vtp0ctrlreg) | VTP_CTRL_START_EN,
77 &vtpreg[nr]->vtp0ctrlreg);
Chandan Nath98b036e2011-10-14 02:58:24 +000078
79 /* Poll for READY */
Matt Porter65991ec2013-03-15 10:07:03 +000080 while ((readl(&vtpreg[nr]->vtp0ctrlreg) & VTP_CTRL_READY) !=
Chandan Nath98b036e2011-10-14 02:58:24 +000081 VTP_CTRL_READY)
82 ;
83}
TENART Antoine35c7e522013-07-02 12:05:59 +020084#endif
Chandan Nath98b036e2011-10-14 02:58:24 +000085
Lokesh Vutla89a83bf2013-07-30 10:48:52 +053086void __weak ddr_pll_config(unsigned int ddrpll_m)
87{
88}
89
Lokesh Vutla303b2672013-12-10 15:02:21 +053090void config_ddr(unsigned int pll, const struct ctrl_ioregs *ioregs,
Peter Korsgaardeb6cf7b2012-10-18 01:21:12 +000091 const struct ddr_data *data, const struct cmd_control *ctrl,
Matt Porter65991ec2013-03-15 10:07:03 +000092 const struct emif_regs *regs, int nr)
Chandan Nath98b036e2011-10-14 02:58:24 +000093{
Peter Korsgaardeb6cf7b2012-10-18 01:21:12 +000094 ddr_pll_config(pll);
TENART Antoine35c7e522013-07-02 12:05:59 +020095#ifndef CONFIG_TI816X
Matt Porter65991ec2013-03-15 10:07:03 +000096 config_vtp(nr);
TENART Antoine35c7e522013-07-02 12:05:59 +020097#endif
Matt Porter65991ec2013-03-15 10:07:03 +000098 config_cmd_ctrl(ctrl, nr);
Chandan Nath98b036e2011-10-14 02:58:24 +000099
Matt Porter65991ec2013-03-15 10:07:03 +0000100 config_ddr_data(data, nr);
101#ifdef CONFIG_AM33XX
Lokesh Vutla303b2672013-12-10 15:02:21 +0530102 config_io_ctrl(ioregs);
Chandan Nath98b036e2011-10-14 02:58:24 +0000103
Tom Rini4b020fe2012-07-30 14:13:56 -0700104 /* Set CKE to be controlled by EMIF/DDR PHY */
105 writel(DDR_CKE_CTRL_NORMAL, &ddrctrl->ddrckectrl);
Matt Porter65991ec2013-03-15 10:07:03 +0000106#endif
Tom Rini4b020fe2012-07-30 14:13:56 -0700107 /* Program EMIF instance */
Matt Porter65991ec2013-03-15 10:07:03 +0000108 config_ddr_phy(regs, nr);
109 set_sdram_timings(regs, nr);
110 config_sdram(regs, nr);
Chandan Nath98b036e2011-10-14 02:58:24 +0000111}
112#endif