Tom Rini | 83d290c | 2018-05-06 17:58:06 -0400 | [diff] [blame] | 1 | // SPDX-License-Identifier: GPL-2.0+ |
Chandan Nath | 62d7fe7c | 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 | 62d7fe7c | 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 | b971dfa | 2012-07-03 09:20:06 -0700 | [diff] [blame] | 15 | #include <asm/arch/sys_proto.h> |
Chandan Nath | 62d7fe7c | 2011-10-14 02:58:24 +0000 | [diff] [blame] | 16 | #include <asm/io.h> |
Tom Rini | fda35eb | 2012-07-03 08:51:34 -0700 | [diff] [blame] | 17 | #include <asm/emif.h> |
Chandan Nath | 62d7fe7c | 2011-10-14 02:58:24 +0000 | [diff] [blame] | 18 | |
Matt Porter | 3ba65f9 | 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 | 942d3f0 | 2012-07-30 14:13:16 -0700 | [diff] [blame] | 23 | static struct ddr_ctrl *ddrctrl = (struct ddr_ctrl *)DDR_CTRL_ADDR; |
Matt Porter | 3ba65f9 | 2013-03-15 10:07:03 +0000 | [diff] [blame] | 24 | #endif |
Lokesh Vutla | d3daba1 | 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 | 942d3f0 | 2012-07-30 14:13:16 -0700 | [diff] [blame] | 30 | |
Tom Rini | 8627733 | 2017-05-16 14:46:35 -0400 | [diff] [blame] | 31 | #ifdef CONFIG_TI814X |
Matt Porter | 4fab8d7 | 2013-03-15 10:07:07 +0000 | [diff] [blame] | 32 | void config_dmm(const struct dmm_lisa_map_regs *regs) |
| 33 | { |
Tom Rini | 8627733 | 2017-05-16 14:46:35 -0400 | [diff] [blame] | 34 | struct dmm_lisa_map_regs *hw_lisa_map_regs = |
| 35 | (struct dmm_lisa_map_regs *)DMM_BASE; |
| 36 | |
Matt Porter | 4fab8d7 | 2013-03-15 10:07:07 +0000 | [diff] [blame] | 37 | enable_dmm_clocks(); |
| 38 | |
| 39 | writel(0, &hw_lisa_map_regs->dmm_lisa_map_3); |
| 40 | writel(0, &hw_lisa_map_regs->dmm_lisa_map_2); |
| 41 | writel(0, &hw_lisa_map_regs->dmm_lisa_map_1); |
| 42 | writel(0, &hw_lisa_map_regs->dmm_lisa_map_0); |
| 43 | |
| 44 | writel(regs->dmm_lisa_map_3, &hw_lisa_map_regs->dmm_lisa_map_3); |
| 45 | writel(regs->dmm_lisa_map_2, &hw_lisa_map_regs->dmm_lisa_map_2); |
| 46 | writel(regs->dmm_lisa_map_1, &hw_lisa_map_regs->dmm_lisa_map_1); |
| 47 | writel(regs->dmm_lisa_map_0, &hw_lisa_map_regs->dmm_lisa_map_0); |
| 48 | } |
Steve Kipisz | c5c7a7c | 2013-07-18 15:13:04 -0400 | [diff] [blame] | 49 | #endif |
Matt Porter | 4fab8d7 | 2013-03-15 10:07:07 +0000 | [diff] [blame] | 50 | |
Matt Porter | 3ba65f9 | 2013-03-15 10:07:03 +0000 | [diff] [blame] | 51 | static void config_vtp(int nr) |
Chandan Nath | 62d7fe7c | 2011-10-14 02:58:24 +0000 | [diff] [blame] | 52 | { |
Matt Porter | 3ba65f9 | 2013-03-15 10:07:03 +0000 | [diff] [blame] | 53 | writel(readl(&vtpreg[nr]->vtp0ctrlreg) | VTP_CTRL_ENABLE, |
| 54 | &vtpreg[nr]->vtp0ctrlreg); |
| 55 | writel(readl(&vtpreg[nr]->vtp0ctrlreg) & (~VTP_CTRL_START_EN), |
| 56 | &vtpreg[nr]->vtp0ctrlreg); |
| 57 | writel(readl(&vtpreg[nr]->vtp0ctrlreg) | VTP_CTRL_START_EN, |
| 58 | &vtpreg[nr]->vtp0ctrlreg); |
Chandan Nath | 62d7fe7c | 2011-10-14 02:58:24 +0000 | [diff] [blame] | 59 | |
| 60 | /* Poll for READY */ |
Matt Porter | 3ba65f9 | 2013-03-15 10:07:03 +0000 | [diff] [blame] | 61 | while ((readl(&vtpreg[nr]->vtp0ctrlreg) & VTP_CTRL_READY) != |
Chandan Nath | 62d7fe7c | 2011-10-14 02:58:24 +0000 | [diff] [blame] | 62 | VTP_CTRL_READY) |
| 63 | ; |
| 64 | } |
| 65 | |
Lokesh Vutla | 94d77fb | 2013-07-30 10:48:52 +0530 | [diff] [blame] | 66 | void __weak ddr_pll_config(unsigned int ddrpll_m) |
| 67 | { |
| 68 | } |
| 69 | |
Lokesh Vutla | 965de8b | 2013-12-10 15:02:21 +0530 | [diff] [blame] | 70 | void config_ddr(unsigned int pll, const struct ctrl_ioregs *ioregs, |
Peter Korsgaard | c00f69d | 2012-10-18 01:21:12 +0000 | [diff] [blame] | 71 | const struct ddr_data *data, const struct cmd_control *ctrl, |
Matt Porter | 3ba65f9 | 2013-03-15 10:07:03 +0000 | [diff] [blame] | 72 | const struct emif_regs *regs, int nr) |
Chandan Nath | 62d7fe7c | 2011-10-14 02:58:24 +0000 | [diff] [blame] | 73 | { |
Peter Korsgaard | c00f69d | 2012-10-18 01:21:12 +0000 | [diff] [blame] | 74 | ddr_pll_config(pll); |
Matt Porter | 3ba65f9 | 2013-03-15 10:07:03 +0000 | [diff] [blame] | 75 | config_vtp(nr); |
| 76 | config_cmd_ctrl(ctrl, nr); |
Tom Rini | 318f27c | 2012-07-30 14:13:56 -0700 | [diff] [blame] | 77 | |
Matt Porter | 3ba65f9 | 2013-03-15 10:07:03 +0000 | [diff] [blame] | 78 | config_ddr_data(data, nr); |
| 79 | #ifdef CONFIG_AM33XX |
Lokesh Vutla | 965de8b | 2013-12-10 15:02:21 +0530 | [diff] [blame] | 80 | config_io_ctrl(ioregs); |
Tom Rini | 318f27c | 2012-07-30 14:13:56 -0700 | [diff] [blame] | 81 | |
| 82 | /* Set CKE to be controlled by EMIF/DDR PHY */ |
| 83 | writel(DDR_CKE_CTRL_NORMAL, &ddrctrl->ddrckectrl); |
James Doublesin | fc46bae | 2014-12-22 16:26:11 -0600 | [diff] [blame] | 84 | |
Matt Porter | 3ba65f9 | 2013-03-15 10:07:03 +0000 | [diff] [blame] | 85 | #endif |
Lokesh Vutla | d3daba1 | 2013-12-10 15:02:22 +0530 | [diff] [blame] | 86 | #ifdef CONFIG_AM43XX |
| 87 | writel(readl(&cm_device->cm_dll_ctrl) & ~0x1, &cm_device->cm_dll_ctrl); |
Jeroen Hofstee | 878cae6 | 2014-06-18 21:22:35 +0200 | [diff] [blame] | 88 | while ((readl(&cm_device->cm_dll_ctrl) & CM_DLL_READYST) == 0) |
Lokesh Vutla | d3daba1 | 2013-12-10 15:02:22 +0530 | [diff] [blame] | 89 | ; |
Lokesh Vutla | d3daba1 | 2013-12-10 15:02:22 +0530 | [diff] [blame] | 90 | |
| 91 | config_io_ctrl(ioregs); |
| 92 | |
| 93 | /* Set CKE to be controlled by EMIF/DDR PHY */ |
| 94 | writel(DDR_CKE_CTRL_NORMAL, &ddrctrl->ddrckectrl); |
James Doublesin | fc46bae | 2014-12-22 16:26:11 -0600 | [diff] [blame] | 95 | |
Tom Rini | 7c352cd | 2015-06-05 15:51:11 +0530 | [diff] [blame] | 96 | if (emif_sdram_type(regs->sdram_config) == EMIF_SDRAM_TYPE_DDR3) |
Dave Gerlach | e18945a | 2018-03-17 13:24:30 +0530 | [diff] [blame] | 97 | #ifndef CONFIG_SPL_RTC_DDR_SUPPORT |
Tom Rini | 7c352cd | 2015-06-05 15:51:11 +0530 | [diff] [blame] | 98 | /* Allow EMIF to control DDR_RESET */ |
| 99 | writel(0x00000000, &ddrctrl->ddrioctrl); |
Dave Gerlach | e18945a | 2018-03-17 13:24:30 +0530 | [diff] [blame] | 100 | #else |
| 101 | /* Override EMIF DDR_RESET control */ |
| 102 | writel(0x80000000, &ddrctrl->ddrioctrl); |
| 103 | #endif /* CONFIG_SPL_RTC_DDR_SUPPORT */ |
Lokesh Vutla | d3daba1 | 2013-12-10 15:02:22 +0530 | [diff] [blame] | 104 | #endif |
| 105 | |
Tom Rini | 318f27c | 2012-07-30 14:13:56 -0700 | [diff] [blame] | 106 | /* Program EMIF instance */ |
Matt Porter | 3ba65f9 | 2013-03-15 10:07:03 +0000 | [diff] [blame] | 107 | config_ddr_phy(regs, nr); |
| 108 | set_sdram_timings(regs, nr); |
Lokesh Vutla | d3daba1 | 2013-12-10 15:02:22 +0530 | [diff] [blame] | 109 | if (get_emif_rev(EMIF1_BASE) == EMIF_4D5) |
| 110 | config_sdram_emif4d5(regs, nr); |
| 111 | else |
| 112 | config_sdram(regs, nr); |
Chandan Nath | 62d7fe7c | 2011-10-14 02:58:24 +0000 | [diff] [blame] | 113 | } |