Tom Rini | 10e4779 | 2018-05-06 17:58:06 -0400 | [diff] [blame] | 1 | // SPDX-License-Identifier: GPL-2.0+ |
Chandan Nath | 98b036e | 2011-10-14 02:58:24 +0000 | [diff] [blame] | 2 | /* |
| 3 | * emif4.c |
| 4 | * |
| 5 | * AM33XX emif4 configuration file |
| 6 | * |
| 7 | * Copyright (C) 2011, Texas Instruments, Incorporated - http://www.ti.com/ |
Chandan Nath | 98b036e | 2011-10-14 02:58:24 +0000 | [diff] [blame] | 8 | */ |
| 9 | |
| 10 | #include <common.h> |
| 11 | #include <asm/arch/cpu.h> |
| 12 | #include <asm/arch/ddr_defs.h> |
| 13 | #include <asm/arch/hardware.h> |
| 14 | #include <asm/arch/clock.h> |
Tom Rini | 034aba7 | 2012-07-03 09:20:06 -0700 | [diff] [blame] | 15 | #include <asm/arch/sys_proto.h> |
Chandan Nath | 98b036e | 2011-10-14 02:58:24 +0000 | [diff] [blame] | 16 | #include <asm/io.h> |
Tom Rini | 3fd4456 | 2012-07-03 08:51:34 -0700 | [diff] [blame] | 17 | #include <asm/emif.h> |
Chandan Nath | 98b036e | 2011-10-14 02:58:24 +0000 | [diff] [blame] | 18 | |
Matt Porter | 65991ec | 2013-03-15 10:07:03 +0000 | [diff] [blame] | 19 | static struct vtp_reg *vtpreg[2] = { |
| 20 | (struct vtp_reg *)VTP0_CTRL_ADDR, |
| 21 | (struct vtp_reg *)VTP1_CTRL_ADDR}; |
| 22 | #ifdef CONFIG_AM33XX |
Tom Rini | 4d45112 | 2012-07-30 14:13:16 -0700 | [diff] [blame] | 23 | static struct ddr_ctrl *ddrctrl = (struct ddr_ctrl *)DDR_CTRL_ADDR; |
Matt Porter | 65991ec | 2013-03-15 10:07:03 +0000 | [diff] [blame] | 24 | #endif |
Lokesh Vutla | a82d4e1 | 2013-12-10 15:02:22 +0530 | [diff] [blame] | 25 | #ifdef CONFIG_AM43XX |
| 26 | static struct ddr_ctrl *ddrctrl = (struct ddr_ctrl *)DDR_CTRL_ADDR; |
| 27 | static struct cm_device_inst *cm_device = |
| 28 | (struct cm_device_inst *)CM_DEVICE_INST; |
| 29 | #endif |
Tom Rini | 4d45112 | 2012-07-30 14:13:16 -0700 | [diff] [blame] | 30 | |
Matt Porter | 65991ec | 2013-03-15 10:07:03 +0000 | [diff] [blame] | 31 | static void config_vtp(int nr) |
Chandan Nath | 98b036e | 2011-10-14 02:58:24 +0000 | [diff] [blame] | 32 | { |
Matt Porter | 65991ec | 2013-03-15 10:07:03 +0000 | [diff] [blame] | 33 | writel(readl(&vtpreg[nr]->vtp0ctrlreg) | VTP_CTRL_ENABLE, |
| 34 | &vtpreg[nr]->vtp0ctrlreg); |
| 35 | writel(readl(&vtpreg[nr]->vtp0ctrlreg) & (~VTP_CTRL_START_EN), |
| 36 | &vtpreg[nr]->vtp0ctrlreg); |
| 37 | writel(readl(&vtpreg[nr]->vtp0ctrlreg) | VTP_CTRL_START_EN, |
| 38 | &vtpreg[nr]->vtp0ctrlreg); |
Chandan Nath | 98b036e | 2011-10-14 02:58:24 +0000 | [diff] [blame] | 39 | |
| 40 | /* Poll for READY */ |
Matt Porter | 65991ec | 2013-03-15 10:07:03 +0000 | [diff] [blame] | 41 | while ((readl(&vtpreg[nr]->vtp0ctrlreg) & VTP_CTRL_READY) != |
Chandan Nath | 98b036e | 2011-10-14 02:58:24 +0000 | [diff] [blame] | 42 | VTP_CTRL_READY) |
| 43 | ; |
| 44 | } |
| 45 | |
Lokesh Vutla | 89a83bf | 2013-07-30 10:48:52 +0530 | [diff] [blame] | 46 | void __weak ddr_pll_config(unsigned int ddrpll_m) |
| 47 | { |
| 48 | } |
| 49 | |
Lokesh Vutla | 303b267 | 2013-12-10 15:02:21 +0530 | [diff] [blame] | 50 | void config_ddr(unsigned int pll, const struct ctrl_ioregs *ioregs, |
Peter Korsgaard | eb6cf7b | 2012-10-18 01:21:12 +0000 | [diff] [blame] | 51 | const struct ddr_data *data, const struct cmd_control *ctrl, |
Matt Porter | 65991ec | 2013-03-15 10:07:03 +0000 | [diff] [blame] | 52 | const struct emif_regs *regs, int nr) |
Chandan Nath | 98b036e | 2011-10-14 02:58:24 +0000 | [diff] [blame] | 53 | { |
Peter Korsgaard | eb6cf7b | 2012-10-18 01:21:12 +0000 | [diff] [blame] | 54 | ddr_pll_config(pll); |
Matt Porter | 65991ec | 2013-03-15 10:07:03 +0000 | [diff] [blame] | 55 | config_vtp(nr); |
| 56 | config_cmd_ctrl(ctrl, nr); |
Chandan Nath | 98b036e | 2011-10-14 02:58:24 +0000 | [diff] [blame] | 57 | |
Matt Porter | 65991ec | 2013-03-15 10:07:03 +0000 | [diff] [blame] | 58 | config_ddr_data(data, nr); |
| 59 | #ifdef CONFIG_AM33XX |
Lokesh Vutla | 303b267 | 2013-12-10 15:02:21 +0530 | [diff] [blame] | 60 | config_io_ctrl(ioregs); |
Chandan Nath | 98b036e | 2011-10-14 02:58:24 +0000 | [diff] [blame] | 61 | |
Tom Rini | 4b020fe | 2012-07-30 14:13:56 -0700 | [diff] [blame] | 62 | /* Set CKE to be controlled by EMIF/DDR PHY */ |
| 63 | writel(DDR_CKE_CTRL_NORMAL, &ddrctrl->ddrckectrl); |
James Doublesin | 53c723b | 2014-12-22 16:26:11 -0600 | [diff] [blame] | 64 | |
Matt Porter | 65991ec | 2013-03-15 10:07:03 +0000 | [diff] [blame] | 65 | #endif |
Lokesh Vutla | a82d4e1 | 2013-12-10 15:02:22 +0530 | [diff] [blame] | 66 | #ifdef CONFIG_AM43XX |
| 67 | writel(readl(&cm_device->cm_dll_ctrl) & ~0x1, &cm_device->cm_dll_ctrl); |
Jeroen Hofstee | 47c0295 | 2014-06-18 21:22:35 +0200 | [diff] [blame] | 68 | while ((readl(&cm_device->cm_dll_ctrl) & CM_DLL_READYST) == 0) |
Lokesh Vutla | a82d4e1 | 2013-12-10 15:02:22 +0530 | [diff] [blame] | 69 | ; |
Lokesh Vutla | a82d4e1 | 2013-12-10 15:02:22 +0530 | [diff] [blame] | 70 | |
| 71 | config_io_ctrl(ioregs); |
| 72 | |
| 73 | /* Set CKE to be controlled by EMIF/DDR PHY */ |
| 74 | writel(DDR_CKE_CTRL_NORMAL, &ddrctrl->ddrckectrl); |
James Doublesin | 53c723b | 2014-12-22 16:26:11 -0600 | [diff] [blame] | 75 | |
Tom Rini | be8d635 | 2015-06-05 15:51:11 +0530 | [diff] [blame] | 76 | if (emif_sdram_type(regs->sdram_config) == EMIF_SDRAM_TYPE_DDR3) |
Dave Gerlach | 382867f | 2018-03-17 13:24:30 +0530 | [diff] [blame] | 77 | #ifndef CONFIG_SPL_RTC_DDR_SUPPORT |
Tom Rini | be8d635 | 2015-06-05 15:51:11 +0530 | [diff] [blame] | 78 | /* Allow EMIF to control DDR_RESET */ |
| 79 | writel(0x00000000, &ddrctrl->ddrioctrl); |
Dave Gerlach | 382867f | 2018-03-17 13:24:30 +0530 | [diff] [blame] | 80 | #else |
| 81 | /* Override EMIF DDR_RESET control */ |
| 82 | writel(0x80000000, &ddrctrl->ddrioctrl); |
| 83 | #endif /* CONFIG_SPL_RTC_DDR_SUPPORT */ |
Lokesh Vutla | a82d4e1 | 2013-12-10 15:02:22 +0530 | [diff] [blame] | 84 | #endif |
| 85 | |
Tom Rini | 4b020fe | 2012-07-30 14:13:56 -0700 | [diff] [blame] | 86 | /* Program EMIF instance */ |
Matt Porter | 65991ec | 2013-03-15 10:07:03 +0000 | [diff] [blame] | 87 | config_ddr_phy(regs, nr); |
| 88 | set_sdram_timings(regs, nr); |
Lokesh Vutla | a82d4e1 | 2013-12-10 15:02:22 +0530 | [diff] [blame] | 89 | if (get_emif_rev(EMIF1_BASE) == EMIF_4D5) |
| 90 | config_sdram_emif4d5(regs, nr); |
| 91 | else |
| 92 | config_sdram(regs, nr); |
Chandan Nath | 98b036e | 2011-10-14 02:58:24 +0000 | [diff] [blame] | 93 | } |