blob: cffd4abcf7f51fb495e653d3288b6820b5735431 [file] [log] [blame]
Chandan Nath98b036e2011-10-14 02:58:24 +00001/*
2 * DDR Configuration for AM33xx devices.
3 *
4 * Copyright (C) 2011 Texas Instruments Incorporated -
5http://www.ti.com/
6 *
7 * This program is free software; you can redistribute it and/or
8 * modify it under the terms of the GNU General Public License as
9 * published by the Free Software Foundation; either version 2 of
10 * the License, or (at your option) any later version.
11 *
12 * This program is distributed .as is. WITHOUT ANY WARRANTY of any
13 * kind, whether express or implied; without even the implied warranty
14 * of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 * GNU General Public License for more details.
16 */
17
18#include <asm/arch/cpu.h>
19#include <asm/arch/ddr_defs.h>
20#include <asm/io.h>
Tom Rini0d654712012-05-29 09:02:15 -070021#include <asm/emif.h>
Chandan Nath98b036e2011-10-14 02:58:24 +000022
23/**
24 * Base address for EMIF instances
25 */
Tom Rini0d654712012-05-29 09:02:15 -070026static struct emif_reg_struct *emif_reg = {
27 (struct emif_reg_struct *)EMIF4_0_CFG_BASE};
Chandan Nath98b036e2011-10-14 02:58:24 +000028
29/**
30 * Base address for DDR instance
31 */
32static struct ddr_regs *ddr_reg[2] = {
33 (struct ddr_regs *)DDR_PHY_BASE_ADDR,
34 (struct ddr_regs *)DDR_PHY_BASE_ADDR2};
35
36/**
37 * Base address for ddr io control instances
38 */
39static struct ddr_cmdtctrl *ioctrl_reg = {
40 (struct ddr_cmdtctrl *)DDR_CONTROL_BASE_ADDR};
41
42/**
Chandan Nath98b036e2011-10-14 02:58:24 +000043 * Configure SDRAM
44 */
Tom Rinib668ae42012-07-24 14:55:38 -070045void config_sdram(const struct emif_regs *regs)
Chandan Nath98b036e2011-10-14 02:58:24 +000046{
Tom Rinib668ae42012-07-24 14:55:38 -070047 writel(regs->ref_ctrl, &emif_reg->emif_sdram_ref_ctrl);
48 writel(regs->ref_ctrl, &emif_reg->emif_sdram_ref_ctrl_shdw);
Tom Rini323315a2012-07-30 14:49:50 -070049 if (regs->zq_config)
50 writel(regs->zq_config, &emif_reg->emif_zq_config);
Tom Rinib668ae42012-07-24 14:55:38 -070051 writel(regs->sdram_config, &emif_reg->emif_sdram_config);
Chandan Nath98b036e2011-10-14 02:58:24 +000052}
53
54/**
55 * Set SDRAM timings
56 */
Tom Rinib668ae42012-07-24 14:55:38 -070057void set_sdram_timings(const struct emif_regs *regs)
Chandan Nath98b036e2011-10-14 02:58:24 +000058{
Tom Rinib668ae42012-07-24 14:55:38 -070059 writel(regs->sdram_tim1, &emif_reg->emif_sdram_tim_1);
60 writel(regs->sdram_tim1, &emif_reg->emif_sdram_tim_1_shdw);
61 writel(regs->sdram_tim2, &emif_reg->emif_sdram_tim_2);
62 writel(regs->sdram_tim2, &emif_reg->emif_sdram_tim_2_shdw);
63 writel(regs->sdram_tim3, &emif_reg->emif_sdram_tim_3);
64 writel(regs->sdram_tim3, &emif_reg->emif_sdram_tim_3_shdw);
Chandan Nath98b036e2011-10-14 02:58:24 +000065}
66
67/**
68 * Configure DDR PHY
69 */
Tom Rinib668ae42012-07-24 14:55:38 -070070void config_ddr_phy(const struct emif_regs *regs)
Chandan Nath98b036e2011-10-14 02:58:24 +000071{
Tom Rinib668ae42012-07-24 14:55:38 -070072 writel(regs->emif_ddr_phy_ctlr_1, &emif_reg->emif_ddr_phy_ctrl_1);
73 writel(regs->emif_ddr_phy_ctlr_1, &emif_reg->emif_ddr_phy_ctrl_1_shdw);
Chandan Nath98b036e2011-10-14 02:58:24 +000074}
75
76/**
77 * Configure DDR CMD control registers
78 */
Tom Rini6f868cf2012-07-24 14:54:41 -070079void config_cmd_ctrl(const struct cmd_control *cmd)
Chandan Nath98b036e2011-10-14 02:58:24 +000080{
81 writel(cmd->cmd0csratio, &ddr_reg[0]->cm0csratio);
Chandan Nath98b036e2011-10-14 02:58:24 +000082 writel(cmd->cmd0dldiff, &ddr_reg[0]->cm0dldiff);
83 writel(cmd->cmd0iclkout, &ddr_reg[0]->cm0iclkout);
84
85 writel(cmd->cmd1csratio, &ddr_reg[0]->cm1csratio);
Chandan Nath98b036e2011-10-14 02:58:24 +000086 writel(cmd->cmd1dldiff, &ddr_reg[0]->cm1dldiff);
87 writel(cmd->cmd1iclkout, &ddr_reg[0]->cm1iclkout);
88
89 writel(cmd->cmd2csratio, &ddr_reg[0]->cm2csratio);
Chandan Nath98b036e2011-10-14 02:58:24 +000090 writel(cmd->cmd2dldiff, &ddr_reg[0]->cm2dldiff);
91 writel(cmd->cmd2iclkout, &ddr_reg[0]->cm2iclkout);
Chandan Nath98b036e2011-10-14 02:58:24 +000092}
93
94/**
95 * Configure DDR DATA registers
96 */
Tom Rini6f868cf2012-07-24 14:54:41 -070097void config_ddr_data(int macrono, const struct ddr_data *data)
Chandan Nath98b036e2011-10-14 02:58:24 +000098{
99 writel(data->datardsratio0, &ddr_reg[macrono]->dt0rdsratio0);
Chandan Nath98b036e2011-10-14 02:58:24 +0000100 writel(data->datawdsratio0, &ddr_reg[macrono]->dt0wdsratio0);
Chandan Nath98b036e2011-10-14 02:58:24 +0000101 writel(data->datawiratio0, &ddr_reg[macrono]->dt0wiratio0);
Chandan Nath98b036e2011-10-14 02:58:24 +0000102 writel(data->datagiratio0, &ddr_reg[macrono]->dt0giratio0);
Chandan Nath98b036e2011-10-14 02:58:24 +0000103 writel(data->datafwsratio0, &ddr_reg[macrono]->dt0fwsratio0);
Chandan Nath98b036e2011-10-14 02:58:24 +0000104 writel(data->datawrsratio0, &ddr_reg[macrono]->dt0wrsratio0);
Tom Rini3e444582012-07-30 11:49:47 -0700105 writel(data->datauserank0delay, &ddr_reg[macrono]->dt0rdelays0);
Chandan Nath98b036e2011-10-14 02:58:24 +0000106 writel(data->datadldiff0, &ddr_reg[macrono]->dt0dldiff0);
Chandan Nath98b036e2011-10-14 02:58:24 +0000107}
108
Tom Rinib239b3b2012-07-24 16:31:26 -0700109void config_io_ctrl(unsigned long val)
Chandan Nath98b036e2011-10-14 02:58:24 +0000110{
Tom Rinib239b3b2012-07-24 16:31:26 -0700111 writel(val, &ioctrl_reg->cm0ioctl);
112 writel(val, &ioctrl_reg->cm1ioctl);
113 writel(val, &ioctrl_reg->cm2ioctl);
114 writel(val, &ioctrl_reg->dt0ioctl);
115 writel(val, &ioctrl_reg->dt1ioctl);
Chandan Nath98b036e2011-10-14 02:58:24 +0000116}