1 // SPDX-License-Identifier: GPL-2.0+
5 * Board functions for Phytec phyCORE-AM335x R2 (PCL060 / PCM060) based boards
7 * Copyright (C) 2011, Texas Instruments, Incorporated - http://www.ti.com/
8 * Copyright (C) 2013 Lars Poeschel, Lemonage Software GmbH
9 * Copyright (C) 2015 Wadim Egorov, PHYTEC Messtechnik GmbH
10 * Copyright (C) 2019 DENX Software Engineering GmbH
16 #include <asm/arch/cpu.h>
17 #include <asm/arch/ddr_defs.h>
18 #include <asm/arch/clock.h>
19 #include <asm/arch/sys_proto.h>
20 #include <asm/global_data.h>
21 #include <power/tps65910.h>
22 #include <jffs2/load_kernel.h>
24 #include <fdt_support.h>
27 DECLARE_GLOBAL_DATA_PTR;
29 #ifdef CONFIG_SPL_BUILD
31 static struct ctrl_dev *cdev = (struct ctrl_dev *)CTRL_DEVICE_BASE;
34 #define DDR_CLK_MHZ 400 /* DDR_DPLL_MULT value */
36 #define OSC (V_OSCK / 1000000)
37 const struct dpll_params dpll_ddr = {
38 DDR_CLK_MHZ, OSC - 1, 1, -1, -1, -1, -1};
40 const struct dpll_params *get_dpll_ddr_params(void)
45 const struct ctrl_ioregs ioregs = {
53 static const struct cmd_control ddr3_cmd_ctrl_data = {
65 PHYCORE_R2_MT41K128M16JT_256MB,
66 PHYCORE_R2_MT41K256M16TW107IT_512MB,
67 PHYCORE_R2_MT41K512M16HA125IT_1024MB,
70 struct am335x_sdram_timings {
71 struct emif_regs ddr3_emif_reg_data;
72 struct ddr_data ddr3_data;
75 static struct am335x_sdram_timings physom_timings[] = {
76 [PHYCORE_R2_MT41K128M16JT_256MB] = {
77 .ddr3_emif_reg_data = {
78 .sdram_config = 0x61C052B2,
79 .ref_ctrl = 0x00000C30,
80 .sdram_tim1 = 0x0AAAD4DB,
81 .sdram_tim2 = 0x26437FDA,
82 .sdram_tim3 = 0x501F83FF,
83 .zq_config = 0x50074BE4,
84 .emif_ddr_phy_ctlr_1 = 0x7,
85 .ocp_config = 0x003d3d3d,
88 .datardsratio0 = 0x36,
89 .datawdsratio0 = 0x38,
90 .datafwsratio0 = 0x99,
91 .datawrsratio0 = 0x73,
94 [PHYCORE_R2_MT41K256M16TW107IT_512MB] = {
95 .ddr3_emif_reg_data = {
96 .sdram_config = 0x61C05332,
97 .ref_ctrl = 0x00000C30,
98 .sdram_tim1 = 0x0AAAD4DB,
99 .sdram_tim2 = 0x266B7FDA,
100 .sdram_tim3 = 0x501F867F,
101 .zq_config = 0x50074BE4,
102 .emif_ddr_phy_ctlr_1 = 0x7,
103 .ocp_config = 0x003d3d3d,
106 .datardsratio0 = 0x37,
107 .datawdsratio0 = 0x38,
108 .datafwsratio0 = 0x92,
109 .datawrsratio0 = 0x72,
112 [PHYCORE_R2_MT41K512M16HA125IT_1024MB] = {
113 .ddr3_emif_reg_data = {
114 .sdram_config = 0x61C053B2,
115 .ref_ctrl = 0x00000C30,
116 .sdram_tim1 = 0x0AAAD4DB,
117 .sdram_tim2 = 0x268F7FDA,
118 .sdram_tim3 = 0x501F88BF,
119 .zq_config = 0x50074BE4,
120 .emif_ddr_phy_ctlr_1 = 0x7,
121 .ocp_config = 0x003d3d3d,
124 .datardsratio0 = 0x38,
125 .datawdsratio0 = 0x4d,
126 .datafwsratio0 = 0x9d,
127 .datawrsratio0 = 0x82,
132 void sdram_init(void)
134 /* Configure memory to maximum supported size for detection */
135 int ram_type_index = PHYCORE_R2_MT41K512M16HA125IT_1024MB;
137 config_ddr(DDR_CLK_MHZ, &ioregs,
138 &physom_timings[ram_type_index].ddr3_data,
140 &physom_timings[ram_type_index].ddr3_emif_reg_data,
143 /* Detect memory physically present */
144 gd->ram_size = get_ram_size((void *)CONFIG_SYS_SDRAM_BASE,
145 CONFIG_MAX_RAM_BANK_SIZE);
147 /* Reconfigure memory for actual detected size */
148 switch (gd->ram_size) {
150 ram_type_index = PHYCORE_R2_MT41K512M16HA125IT_1024MB;
153 ram_type_index = PHYCORE_R2_MT41K256M16TW107IT_512MB;
157 ram_type_index = PHYCORE_R2_MT41K128M16JT_256MB;
160 config_ddr(DDR_CLK_MHZ, &ioregs,
161 &physom_timings[ram_type_index].ddr3_data,
163 &physom_timings[ram_type_index].ddr3_emif_reg_data,
167 const struct dpll_params *get_dpll_mpu_params(void)
169 int ind = get_sys_clk_index();
170 int freq = am335x_get_efuse_mpu_max_freq(cdev);
174 return &dpll_mpu_opp[ind][5];
176 return &dpll_mpu_opp[ind][4];
178 return &dpll_mpu_opp[ind][3];
180 return &dpll_mpu_opp[ind][2];
182 return &dpll_mpu_opp100;
184 return &dpll_mpu_opp[ind][0];
187 return &dpll_mpu_opp[ind][0];
190 static void scale_vcores_generic(int freq)
192 int sil_rev, mpu_vdd;
195 * We use a TPS65910 PMIC. For all MPU frequencies we support we use a
196 * CORE voltage of 1.10V. For MPU voltage we need to switch based on
197 * the frequency we are running at.
199 if (power_tps65910_init(0))
203 * Depending on MPU clock and PG we will need a different
204 * VDD to drive at that speed.
206 sil_rev = readl(&cdev->deviceid) >> 28;
207 mpu_vdd = am335x_get_tps65910_mpu_vdd(sil_rev, freq);
209 /* Tell the TPS65910 to use i2c */
210 tps65910_set_i2c_control();
212 /* First update MPU voltage. */
213 if (tps65910_voltage_update(MPU, mpu_vdd))
216 /* Second, update the CORE voltage. */
217 if (tps65910_voltage_update(CORE, TPS65910_OP_REG_SEL_1_1_0))
221 void scale_vcores(void)
225 freq = am335x_get_efuse_mpu_max_freq(cdev);
226 scale_vcores_generic(freq);
229 void set_uart_mux_conf(void)
231 enable_uart0_pin_mux();
234 void set_mux_conf_regs(void)
236 enable_i2c0_pin_mux();
237 enable_board_pin_mux();
242 * Basic board specific setup. Pinmux has been handled already.
246 gd->bd->bi_boot_params = CONFIG_SYS_SDRAM_BASE + 0x100;
250 #ifdef CONFIG_OF_BOARD_SETUP
251 int ft_board_setup(void *blob, struct bd_info *bd)
253 #ifdef CONFIG_FDT_FIXUP_PARTITIONS
254 static const struct node_info nodes[] = {
255 { "ti,omap2-nand", MTD_DEV_TYPE_NAND, },
258 fdt_fixup_mtdparts(blob, nodes, ARRAY_SIZE(nodes));