blob: 255f333b692bb1e0ac66b8ae5e8b3965264acc84 [file] [log] [blame]
Chandan Nath62d7fe7c2011-10-14 02:58:24 +00001/*
2 * DDR Configuration for AM33xx devices.
3 *
Wolfgang Denk1a459662013-07-08 09:37:19 +02004 * Copyright (C) 2011 Texas Instruments Incorporated - http://www.ti.com/
Chandan Nath62d7fe7c2011-10-14 02:58:24 +00005 *
Wolfgang Denk1a459662013-07-08 09:37:19 +02006 * SPDX-License-Identifier: GPL-2.0+
Chandan Nath62d7fe7c2011-10-14 02:58:24 +00007 */
8
9#include <asm/arch/cpu.h>
10#include <asm/arch/ddr_defs.h>
Satyanarayana, Sandhya6995a282012-08-09 18:29:57 +000011#include <asm/arch/sys_proto.h>
Chandan Nath62d7fe7c2011-10-14 02:58:24 +000012#include <asm/io.h>
Tom Rini7d5eb342012-05-29 09:02:15 -070013#include <asm/emif.h>
Chandan Nath62d7fe7c2011-10-14 02:58:24 +000014
15/**
16 * Base address for EMIF instances
17 */
Matt Porter3ba65f92013-03-15 10:07:03 +000018static struct emif_reg_struct *emif_reg[2] = {
19 (struct emif_reg_struct *)EMIF4_0_CFG_BASE,
20 (struct emif_reg_struct *)EMIF4_1_CFG_BASE};
Chandan Nath62d7fe7c2011-10-14 02:58:24 +000021
22/**
Matt Porter3ba65f92013-03-15 10:07:03 +000023 * Base addresses for DDR PHY cmd/data regs
Chandan Nath62d7fe7c2011-10-14 02:58:24 +000024 */
Matt Porter3ba65f92013-03-15 10:07:03 +000025static struct ddr_cmd_regs *ddr_cmd_reg[2] = {
26 (struct ddr_cmd_regs *)DDR_PHY_CMD_ADDR,
27 (struct ddr_cmd_regs *)DDR_PHY_CMD_ADDR2};
28
29static struct ddr_data_regs *ddr_data_reg[2] = {
30 (struct ddr_data_regs *)DDR_PHY_DATA_ADDR,
31 (struct ddr_data_regs *)DDR_PHY_DATA_ADDR2};
Chandan Nath62d7fe7c2011-10-14 02:58:24 +000032
33/**
34 * Base address for ddr io control instances
35 */
36static struct ddr_cmdtctrl *ioctrl_reg = {
37 (struct ddr_cmdtctrl *)DDR_CONTROL_BASE_ADDR};
38
39/**
Chandan Nath62d7fe7c2011-10-14 02:58:24 +000040 * Configure SDRAM
41 */
Matt Porter3ba65f92013-03-15 10:07:03 +000042void config_sdram(const struct emif_regs *regs, int nr)
Chandan Nath62d7fe7c2011-10-14 02:58:24 +000043{
Tom Rini1c382ea2013-02-26 16:35:33 -050044 if (regs->zq_config) {
45 /*
46 * A value of 0x2800 for the REF CTRL will give us
47 * about 570us for a delay, which will be long enough
48 * to configure things.
49 */
Matt Porter3ba65f92013-03-15 10:07:03 +000050 writel(0x2800, &emif_reg[nr]->emif_sdram_ref_ctrl);
51 writel(regs->zq_config, &emif_reg[nr]->emif_zq_config);
Satyanarayana, Sandhya6995a282012-08-09 18:29:57 +000052 writel(regs->sdram_config, &cstat->secure_emif_sdram_config);
Matt Porter3ba65f92013-03-15 10:07:03 +000053 writel(regs->sdram_config, &emif_reg[nr]->emif_sdram_config);
54 writel(regs->ref_ctrl, &emif_reg[nr]->emif_sdram_ref_ctrl);
55 writel(regs->ref_ctrl, &emif_reg[nr]->emif_sdram_ref_ctrl_shdw);
Satyanarayana, Sandhya6995a282012-08-09 18:29:57 +000056 }
Matt Porter3ba65f92013-03-15 10:07:03 +000057 writel(regs->ref_ctrl, &emif_reg[nr]->emif_sdram_ref_ctrl);
58 writel(regs->ref_ctrl, &emif_reg[nr]->emif_sdram_ref_ctrl_shdw);
59 writel(regs->sdram_config, &emif_reg[nr]->emif_sdram_config);
Chandan Nath62d7fe7c2011-10-14 02:58:24 +000060}
61
62/**
63 * Set SDRAM timings
64 */
Matt Porter3ba65f92013-03-15 10:07:03 +000065void set_sdram_timings(const struct emif_regs *regs, int nr)
Chandan Nath62d7fe7c2011-10-14 02:58:24 +000066{
Matt Porter3ba65f92013-03-15 10:07:03 +000067 writel(regs->sdram_tim1, &emif_reg[nr]->emif_sdram_tim_1);
68 writel(regs->sdram_tim1, &emif_reg[nr]->emif_sdram_tim_1_shdw);
69 writel(regs->sdram_tim2, &emif_reg[nr]->emif_sdram_tim_2);
70 writel(regs->sdram_tim2, &emif_reg[nr]->emif_sdram_tim_2_shdw);
71 writel(regs->sdram_tim3, &emif_reg[nr]->emif_sdram_tim_3);
72 writel(regs->sdram_tim3, &emif_reg[nr]->emif_sdram_tim_3_shdw);
Chandan Nath62d7fe7c2011-10-14 02:58:24 +000073}
74
75/**
76 * Configure DDR PHY
77 */
Matt Porter3ba65f92013-03-15 10:07:03 +000078void config_ddr_phy(const struct emif_regs *regs, int nr)
Chandan Nath62d7fe7c2011-10-14 02:58:24 +000079{
Matt Porter3ba65f92013-03-15 10:07:03 +000080 writel(regs->emif_ddr_phy_ctlr_1,
81 &emif_reg[nr]->emif_ddr_phy_ctrl_1);
82 writel(regs->emif_ddr_phy_ctlr_1,
83 &emif_reg[nr]->emif_ddr_phy_ctrl_1_shdw);
Chandan Nath62d7fe7c2011-10-14 02:58:24 +000084}
85
86/**
87 * Configure DDR CMD control registers
88 */
Matt Porter3ba65f92013-03-15 10:07:03 +000089void config_cmd_ctrl(const struct cmd_control *cmd, int nr)
Chandan Nath62d7fe7c2011-10-14 02:58:24 +000090{
Lokesh Vutla965de8b2013-12-10 15:02:21 +053091 if (!cmd)
92 return;
93
Matt Porter3ba65f92013-03-15 10:07:03 +000094 writel(cmd->cmd0csratio, &ddr_cmd_reg[nr]->cm0csratio);
Matt Porter3ba65f92013-03-15 10:07:03 +000095 writel(cmd->cmd0iclkout, &ddr_cmd_reg[nr]->cm0iclkout);
Chandan Nath62d7fe7c2011-10-14 02:58:24 +000096
Matt Porter3ba65f92013-03-15 10:07:03 +000097 writel(cmd->cmd1csratio, &ddr_cmd_reg[nr]->cm1csratio);
Matt Porter3ba65f92013-03-15 10:07:03 +000098 writel(cmd->cmd1iclkout, &ddr_cmd_reg[nr]->cm1iclkout);
Chandan Nath62d7fe7c2011-10-14 02:58:24 +000099
Matt Porter3ba65f92013-03-15 10:07:03 +0000100 writel(cmd->cmd2csratio, &ddr_cmd_reg[nr]->cm2csratio);
Matt Porter3ba65f92013-03-15 10:07:03 +0000101 writel(cmd->cmd2iclkout, &ddr_cmd_reg[nr]->cm2iclkout);
Chandan Nath62d7fe7c2011-10-14 02:58:24 +0000102}
103
104/**
105 * Configure DDR DATA registers
106 */
Matt Porter3ba65f92013-03-15 10:07:03 +0000107void config_ddr_data(const struct ddr_data *data, int nr)
Chandan Nath62d7fe7c2011-10-14 02:58:24 +0000108{
Matt Porter3ba65f92013-03-15 10:07:03 +0000109 int i;
110
Lokesh Vutla965de8b2013-12-10 15:02:21 +0530111 if (!data)
112 return;
113
Matt Porter3ba65f92013-03-15 10:07:03 +0000114 for (i = 0; i < DDR_DATA_REGS_NR; i++) {
115 writel(data->datardsratio0,
116 &(ddr_data_reg[nr]+i)->dt0rdsratio0);
117 writel(data->datawdsratio0,
118 &(ddr_data_reg[nr]+i)->dt0wdsratio0);
119 writel(data->datawiratio0,
120 &(ddr_data_reg[nr]+i)->dt0wiratio0);
121 writel(data->datagiratio0,
122 &(ddr_data_reg[nr]+i)->dt0giratio0);
123 writel(data->datafwsratio0,
124 &(ddr_data_reg[nr]+i)->dt0fwsratio0);
125 writel(data->datawrsratio0,
126 &(ddr_data_reg[nr]+i)->dt0wrsratio0);
Matt Porter3ba65f92013-03-15 10:07:03 +0000127 }
Chandan Nath62d7fe7c2011-10-14 02:58:24 +0000128}
129
Lokesh Vutla965de8b2013-12-10 15:02:21 +0530130void config_io_ctrl(const struct ctrl_ioregs *ioregs)
Chandan Nath62d7fe7c2011-10-14 02:58:24 +0000131{
Lokesh Vutla965de8b2013-12-10 15:02:21 +0530132 if (!ioregs)
133 return;
134
135 writel(ioregs->cm0ioctl, &ioctrl_reg->cm0ioctl);
136 writel(ioregs->cm1ioctl, &ioctrl_reg->cm1ioctl);
137 writel(ioregs->cm2ioctl, &ioctrl_reg->cm2ioctl);
138 writel(ioregs->dt0ioctl, &ioctrl_reg->dt0ioctl);
139 writel(ioregs->dt1ioctl, &ioctrl_reg->dt1ioctl);
140#ifdef CONFIG_AM43XX
141 writel(ioregs->dt2ioctrl, &ioctrl_reg->dt2ioctrl);
142 writel(ioregs->dt3ioctrl, &ioctrl_reg->dt3ioctrl);
143 writel(ioregs->emif_sdram_config_ext,
144 &ioctrl_reg->emif_sdram_config_ext);
145#endif
Chandan Nath62d7fe7c2011-10-14 02:58:24 +0000146}