Chandan Nath | 62d7fe7c | 2011-10-14 02:58:24 +0000 | [diff] [blame] | 1 | /* |
| 2 | * emif4.c |
| 3 | * |
| 4 | * AM33XX emif4 configuration file |
| 5 | * |
| 6 | * Copyright (C) 2011, Texas Instruments, Incorporated - http://www.ti.com/ |
| 7 | * |
Wolfgang Denk | 1a45966 | 2013-07-08 09:37:19 +0200 | [diff] [blame] | 8 | * SPDX-License-Identifier: GPL-2.0+ |
Chandan Nath | 62d7fe7c | 2011-10-14 02:58:24 +0000 | [diff] [blame] | 9 | */ |
| 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 Rini | b971dfa | 2012-07-03 09:20:06 -0700 | [diff] [blame] | 16 | #include <asm/arch/sys_proto.h> |
Chandan Nath | 62d7fe7c | 2011-10-14 02:58:24 +0000 | [diff] [blame] | 17 | #include <asm/io.h> |
Tom Rini | fda35eb | 2012-07-03 08:51:34 -0700 | [diff] [blame] | 18 | #include <asm/emif.h> |
Chandan Nath | 62d7fe7c | 2011-10-14 02:58:24 +0000 | [diff] [blame] | 19 | |
| 20 | DECLARE_GLOBAL_DATA_PTR; |
| 21 | |
Chandan Nath | 62d7fe7c | 2011-10-14 02:58:24 +0000 | [diff] [blame] | 22 | int 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 | |
| 31 | void 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 Kipisz | c5c7a7c | 2013-07-18 15:13:04 -0400 | [diff] [blame^] | 38 | #if defined(CONFIG_SPL_BUILD) || defined(CONFIG_NOR_BOOT) |
| 39 | #ifdef CONFIG_TI81XX |
Matt Porter | 4fab8d7 | 2013-03-15 10:07:07 +0000 | [diff] [blame] | 40 | static struct dmm_lisa_map_regs *hw_lisa_map_regs = |
| 41 | (struct dmm_lisa_map_regs *)DMM_BASE; |
Steve Kipisz | c5c7a7c | 2013-07-18 15:13:04 -0400 | [diff] [blame^] | 42 | #endif |
Matt Porter | 3ba65f9 | 2013-03-15 10:07:03 +0000 | [diff] [blame] | 43 | static struct vtp_reg *vtpreg[2] = { |
| 44 | (struct vtp_reg *)VTP0_CTRL_ADDR, |
| 45 | (struct vtp_reg *)VTP1_CTRL_ADDR}; |
| 46 | #ifdef CONFIG_AM33XX |
Tom Rini | 942d3f0 | 2012-07-30 14:13:16 -0700 | [diff] [blame] | 47 | static struct ddr_ctrl *ddrctrl = (struct ddr_ctrl *)DDR_CTRL_ADDR; |
Matt Porter | 3ba65f9 | 2013-03-15 10:07:03 +0000 | [diff] [blame] | 48 | #endif |
Tom Rini | 942d3f0 | 2012-07-30 14:13:16 -0700 | [diff] [blame] | 49 | |
Steve Kipisz | c5c7a7c | 2013-07-18 15:13:04 -0400 | [diff] [blame^] | 50 | #ifdef CONFIG_TI81XX |
Matt Porter | 4fab8d7 | 2013-03-15 10:07:07 +0000 | [diff] [blame] | 51 | void 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 Kipisz | c5c7a7c | 2013-07-18 15:13:04 -0400 | [diff] [blame^] | 65 | #endif |
Matt Porter | 4fab8d7 | 2013-03-15 10:07:07 +0000 | [diff] [blame] | 66 | |
Matt Porter | 3ba65f9 | 2013-03-15 10:07:03 +0000 | [diff] [blame] | 67 | static void config_vtp(int nr) |
Chandan Nath | 62d7fe7c | 2011-10-14 02:58:24 +0000 | [diff] [blame] | 68 | { |
Matt Porter | 3ba65f9 | 2013-03-15 10:07:03 +0000 | [diff] [blame] | 69 | 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 Nath | 62d7fe7c | 2011-10-14 02:58:24 +0000 | [diff] [blame] | 75 | |
| 76 | /* Poll for READY */ |
Matt Porter | 3ba65f9 | 2013-03-15 10:07:03 +0000 | [diff] [blame] | 77 | while ((readl(&vtpreg[nr]->vtp0ctrlreg) & VTP_CTRL_READY) != |
Chandan Nath | 62d7fe7c | 2011-10-14 02:58:24 +0000 | [diff] [blame] | 78 | VTP_CTRL_READY) |
| 79 | ; |
| 80 | } |
| 81 | |
Peter Korsgaard | c00f69d | 2012-10-18 01:21:12 +0000 | [diff] [blame] | 82 | void config_ddr(unsigned int pll, unsigned int ioctrl, |
| 83 | const struct ddr_data *data, const struct cmd_control *ctrl, |
Matt Porter | 3ba65f9 | 2013-03-15 10:07:03 +0000 | [diff] [blame] | 84 | const struct emif_regs *regs, int nr) |
Chandan Nath | 62d7fe7c | 2011-10-14 02:58:24 +0000 | [diff] [blame] | 85 | { |
Tom Rini | 318f27c | 2012-07-30 14:13:56 -0700 | [diff] [blame] | 86 | enable_emif_clocks(); |
Peter Korsgaard | c00f69d | 2012-10-18 01:21:12 +0000 | [diff] [blame] | 87 | ddr_pll_config(pll); |
Matt Porter | 3ba65f9 | 2013-03-15 10:07:03 +0000 | [diff] [blame] | 88 | config_vtp(nr); |
| 89 | config_cmd_ctrl(ctrl, nr); |
Tom Rini | 318f27c | 2012-07-30 14:13:56 -0700 | [diff] [blame] | 90 | |
Matt Porter | 3ba65f9 | 2013-03-15 10:07:03 +0000 | [diff] [blame] | 91 | config_ddr_data(data, nr); |
| 92 | #ifdef CONFIG_AM33XX |
Peter Korsgaard | c00f69d | 2012-10-18 01:21:12 +0000 | [diff] [blame] | 93 | config_io_ctrl(ioctrl); |
Tom Rini | 318f27c | 2012-07-30 14:13:56 -0700 | [diff] [blame] | 94 | |
| 95 | /* Set CKE to be controlled by EMIF/DDR PHY */ |
| 96 | writel(DDR_CKE_CTRL_NORMAL, &ddrctrl->ddrckectrl); |
Matt Porter | 3ba65f9 | 2013-03-15 10:07:03 +0000 | [diff] [blame] | 97 | #endif |
Tom Rini | 318f27c | 2012-07-30 14:13:56 -0700 | [diff] [blame] | 98 | |
| 99 | /* Program EMIF instance */ |
Matt Porter | 3ba65f9 | 2013-03-15 10:07:03 +0000 | [diff] [blame] | 100 | config_ddr_phy(regs, nr); |
| 101 | set_sdram_timings(regs, nr); |
| 102 | config_sdram(regs, nr); |
Chandan Nath | 62d7fe7c | 2011-10-14 02:58:24 +0000 | [diff] [blame] | 103 | } |
| 104 | #endif |