Chandan Nath | 62d7fe7c | 2011-10-14 02:58:24 +0000 | [diff] [blame] | 1 | /* |
| 2 | * DDR Configuration for AM33xx devices. |
| 3 | * |
Wolfgang Denk | 1a45966 | 2013-07-08 09:37:19 +0200 | [diff] [blame] | 4 | * Copyright (C) 2011 Texas Instruments Incorporated - http://www.ti.com/ |
Chandan Nath | 62d7fe7c | 2011-10-14 02:58:24 +0000 | [diff] [blame] | 5 | * |
Wolfgang Denk | 1a45966 | 2013-07-08 09:37:19 +0200 | [diff] [blame] | 6 | * SPDX-License-Identifier: GPL-2.0+ |
Chandan Nath | 62d7fe7c | 2011-10-14 02:58:24 +0000 | [diff] [blame] | 7 | */ |
| 8 | |
| 9 | #include <asm/arch/cpu.h> |
| 10 | #include <asm/arch/ddr_defs.h> |
Satyanarayana, Sandhya | 6995a28 | 2012-08-09 18:29:57 +0000 | [diff] [blame] | 11 | #include <asm/arch/sys_proto.h> |
Chandan Nath | 62d7fe7c | 2011-10-14 02:58:24 +0000 | [diff] [blame] | 12 | #include <asm/io.h> |
Tom Rini | 7d5eb34 | 2012-05-29 09:02:15 -0700 | [diff] [blame] | 13 | #include <asm/emif.h> |
Chandan Nath | 62d7fe7c | 2011-10-14 02:58:24 +0000 | [diff] [blame] | 14 | |
| 15 | /** |
| 16 | * Base address for EMIF instances |
| 17 | */ |
Matt Porter | 3ba65f9 | 2013-03-15 10:07:03 +0000 | [diff] [blame] | 18 | static 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 Nath | 62d7fe7c | 2011-10-14 02:58:24 +0000 | [diff] [blame] | 21 | |
| 22 | /** |
Matt Porter | 3ba65f9 | 2013-03-15 10:07:03 +0000 | [diff] [blame] | 23 | * Base addresses for DDR PHY cmd/data regs |
Chandan Nath | 62d7fe7c | 2011-10-14 02:58:24 +0000 | [diff] [blame] | 24 | */ |
Matt Porter | 3ba65f9 | 2013-03-15 10:07:03 +0000 | [diff] [blame] | 25 | static 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 | |
| 29 | static 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 Nath | 62d7fe7c | 2011-10-14 02:58:24 +0000 | [diff] [blame] | 32 | |
| 33 | /** |
| 34 | * Base address for ddr io control instances |
| 35 | */ |
| 36 | static struct ddr_cmdtctrl *ioctrl_reg = { |
| 37 | (struct ddr_cmdtctrl *)DDR_CONTROL_BASE_ADDR}; |
| 38 | |
| 39 | /** |
Chandan Nath | 62d7fe7c | 2011-10-14 02:58:24 +0000 | [diff] [blame] | 40 | * Configure SDRAM |
| 41 | */ |
Matt Porter | 3ba65f9 | 2013-03-15 10:07:03 +0000 | [diff] [blame] | 42 | void config_sdram(const struct emif_regs *regs, int nr) |
Chandan Nath | 62d7fe7c | 2011-10-14 02:58:24 +0000 | [diff] [blame] | 43 | { |
Tom Rini | 1c382ea | 2013-02-26 16:35:33 -0500 | [diff] [blame] | 44 | 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 Porter | 3ba65f9 | 2013-03-15 10:07:03 +0000 | [diff] [blame] | 50 | writel(0x2800, &emif_reg[nr]->emif_sdram_ref_ctrl); |
| 51 | writel(regs->zq_config, &emif_reg[nr]->emif_zq_config); |
Satyanarayana, Sandhya | 6995a28 | 2012-08-09 18:29:57 +0000 | [diff] [blame] | 52 | writel(regs->sdram_config, &cstat->secure_emif_sdram_config); |
Matt Porter | 3ba65f9 | 2013-03-15 10:07:03 +0000 | [diff] [blame] | 53 | 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, Sandhya | 6995a28 | 2012-08-09 18:29:57 +0000 | [diff] [blame] | 56 | } |
Matt Porter | 3ba65f9 | 2013-03-15 10:07:03 +0000 | [diff] [blame] | 57 | 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 Nath | 62d7fe7c | 2011-10-14 02:58:24 +0000 | [diff] [blame] | 60 | } |
| 61 | |
| 62 | /** |
| 63 | * Set SDRAM timings |
| 64 | */ |
Matt Porter | 3ba65f9 | 2013-03-15 10:07:03 +0000 | [diff] [blame] | 65 | void set_sdram_timings(const struct emif_regs *regs, int nr) |
Chandan Nath | 62d7fe7c | 2011-10-14 02:58:24 +0000 | [diff] [blame] | 66 | { |
Matt Porter | 3ba65f9 | 2013-03-15 10:07:03 +0000 | [diff] [blame] | 67 | 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 Nath | 62d7fe7c | 2011-10-14 02:58:24 +0000 | [diff] [blame] | 73 | } |
| 74 | |
| 75 | /** |
| 76 | * Configure DDR PHY |
| 77 | */ |
Matt Porter | 3ba65f9 | 2013-03-15 10:07:03 +0000 | [diff] [blame] | 78 | void config_ddr_phy(const struct emif_regs *regs, int nr) |
Chandan Nath | 62d7fe7c | 2011-10-14 02:58:24 +0000 | [diff] [blame] | 79 | { |
Matt Porter | 3ba65f9 | 2013-03-15 10:07:03 +0000 | [diff] [blame] | 80 | 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 Nath | 62d7fe7c | 2011-10-14 02:58:24 +0000 | [diff] [blame] | 84 | } |
| 85 | |
| 86 | /** |
| 87 | * Configure DDR CMD control registers |
| 88 | */ |
Matt Porter | 3ba65f9 | 2013-03-15 10:07:03 +0000 | [diff] [blame] | 89 | void config_cmd_ctrl(const struct cmd_control *cmd, int nr) |
Chandan Nath | 62d7fe7c | 2011-10-14 02:58:24 +0000 | [diff] [blame] | 90 | { |
Lokesh Vutla | 965de8b | 2013-12-10 15:02:21 +0530 | [diff] [blame^] | 91 | if (!cmd) |
| 92 | return; |
| 93 | |
Matt Porter | 3ba65f9 | 2013-03-15 10:07:03 +0000 | [diff] [blame] | 94 | writel(cmd->cmd0csratio, &ddr_cmd_reg[nr]->cm0csratio); |
Matt Porter | 3ba65f9 | 2013-03-15 10:07:03 +0000 | [diff] [blame] | 95 | writel(cmd->cmd0iclkout, &ddr_cmd_reg[nr]->cm0iclkout); |
Chandan Nath | 62d7fe7c | 2011-10-14 02:58:24 +0000 | [diff] [blame] | 96 | |
Matt Porter | 3ba65f9 | 2013-03-15 10:07:03 +0000 | [diff] [blame] | 97 | writel(cmd->cmd1csratio, &ddr_cmd_reg[nr]->cm1csratio); |
Matt Porter | 3ba65f9 | 2013-03-15 10:07:03 +0000 | [diff] [blame] | 98 | writel(cmd->cmd1iclkout, &ddr_cmd_reg[nr]->cm1iclkout); |
Chandan Nath | 62d7fe7c | 2011-10-14 02:58:24 +0000 | [diff] [blame] | 99 | |
Matt Porter | 3ba65f9 | 2013-03-15 10:07:03 +0000 | [diff] [blame] | 100 | writel(cmd->cmd2csratio, &ddr_cmd_reg[nr]->cm2csratio); |
Matt Porter | 3ba65f9 | 2013-03-15 10:07:03 +0000 | [diff] [blame] | 101 | writel(cmd->cmd2iclkout, &ddr_cmd_reg[nr]->cm2iclkout); |
Chandan Nath | 62d7fe7c | 2011-10-14 02:58:24 +0000 | [diff] [blame] | 102 | } |
| 103 | |
| 104 | /** |
| 105 | * Configure DDR DATA registers |
| 106 | */ |
Matt Porter | 3ba65f9 | 2013-03-15 10:07:03 +0000 | [diff] [blame] | 107 | void config_ddr_data(const struct ddr_data *data, int nr) |
Chandan Nath | 62d7fe7c | 2011-10-14 02:58:24 +0000 | [diff] [blame] | 108 | { |
Matt Porter | 3ba65f9 | 2013-03-15 10:07:03 +0000 | [diff] [blame] | 109 | int i; |
| 110 | |
Lokesh Vutla | 965de8b | 2013-12-10 15:02:21 +0530 | [diff] [blame^] | 111 | if (!data) |
| 112 | return; |
| 113 | |
Matt Porter | 3ba65f9 | 2013-03-15 10:07:03 +0000 | [diff] [blame] | 114 | 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 Porter | 3ba65f9 | 2013-03-15 10:07:03 +0000 | [diff] [blame] | 127 | } |
Chandan Nath | 62d7fe7c | 2011-10-14 02:58:24 +0000 | [diff] [blame] | 128 | } |
| 129 | |
Lokesh Vutla | 965de8b | 2013-12-10 15:02:21 +0530 | [diff] [blame^] | 130 | void config_io_ctrl(const struct ctrl_ioregs *ioregs) |
Chandan Nath | 62d7fe7c | 2011-10-14 02:58:24 +0000 | [diff] [blame] | 131 | { |
Lokesh Vutla | 965de8b | 2013-12-10 15:02:21 +0530 | [diff] [blame^] | 132 | 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 Nath | 62d7fe7c | 2011-10-14 02:58:24 +0000 | [diff] [blame] | 146 | } |