xref: /openbmc/u-boot/arch/arm/mach-omap2/am33xx/chilisom.c (revision 83d290c56fab2d38cd1ab4c4cc7099559c1d5046)
1*83d290c5STom Rini // SPDX-License-Identifier: GPL-2.0+
2a73c8b32SMarcin Niestroj /*
3a73c8b32SMarcin Niestroj  * Copyright (C) 2011, Texas Instruments, Incorporated - http://www.ti.com/
4a73c8b32SMarcin Niestroj  * Copyright (C) 2017, Grinn - http://grinn-global.com/
5a73c8b32SMarcin Niestroj  */
6a73c8b32SMarcin Niestroj 
7a73c8b32SMarcin Niestroj #include <common.h>
8a73c8b32SMarcin Niestroj #include <asm/arch/clock.h>
9a73c8b32SMarcin Niestroj #include <asm/arch/clk_synthesizer.h>
10a73c8b32SMarcin Niestroj #include <asm/arch/cpu.h>
11a73c8b32SMarcin Niestroj #include <asm/arch/ddr_defs.h>
12a73c8b32SMarcin Niestroj #include <asm/arch/hardware.h>
13a73c8b32SMarcin Niestroj #include <asm/arch/omap.h>
14a73c8b32SMarcin Niestroj #include <asm/arch/mem.h>
15a73c8b32SMarcin Niestroj #include <asm/arch/mux.h>
16a73c8b32SMarcin Niestroj #include <asm/arch/sys_proto.h>
17a73c8b32SMarcin Niestroj #include <asm/emif.h>
18a73c8b32SMarcin Niestroj #include <asm/io.h>
19a73c8b32SMarcin Niestroj #include <errno.h>
20a73c8b32SMarcin Niestroj #include <i2c.h>
21a73c8b32SMarcin Niestroj #include <power/tps65217.h>
22a73c8b32SMarcin Niestroj #include <spl.h>
23a73c8b32SMarcin Niestroj 
24a73c8b32SMarcin Niestroj #ifndef CONFIG_SKIP_LOWLEVEL_INIT
25a73c8b32SMarcin Niestroj 
26a73c8b32SMarcin Niestroj static struct ctrl_dev *cdev = (struct ctrl_dev *)CTRL_DEVICE_BASE;
27a73c8b32SMarcin Niestroj 
28a73c8b32SMarcin Niestroj static struct module_pin_mux i2c0_pin_mux[] = {
29a73c8b32SMarcin Niestroj 	{OFFSET(i2c0_sda), (MODE(0) | RXACTIVE |
30a73c8b32SMarcin Niestroj 			PULLUDEN | SLEWCTRL)}, /* I2C_DATA */
31a73c8b32SMarcin Niestroj 	{OFFSET(i2c0_scl), (MODE(0) | RXACTIVE |
32a73c8b32SMarcin Niestroj 			PULLUDEN | SLEWCTRL)}, /* I2C_SCLK */
33a73c8b32SMarcin Niestroj 	{-1},
34a73c8b32SMarcin Niestroj };
35a73c8b32SMarcin Niestroj 
36a73c8b32SMarcin Niestroj static struct module_pin_mux nand_pin_mux[] = {
37a73c8b32SMarcin Niestroj 	{OFFSET(gpmc_ad0), (MODE(0) | PULLUP_EN | RXACTIVE)},	/* NAND AD0 */
38a73c8b32SMarcin Niestroj 	{OFFSET(gpmc_ad1), (MODE(0) | PULLUP_EN | RXACTIVE)},	/* NAND AD1 */
39a73c8b32SMarcin Niestroj 	{OFFSET(gpmc_ad2), (MODE(0) | PULLUP_EN | RXACTIVE)},	/* NAND AD2 */
40a73c8b32SMarcin Niestroj 	{OFFSET(gpmc_ad3), (MODE(0) | PULLUP_EN | RXACTIVE)},	/* NAND AD3 */
41a73c8b32SMarcin Niestroj 	{OFFSET(gpmc_ad4), (MODE(0) | PULLUP_EN | RXACTIVE)},	/* NAND AD4 */
42a73c8b32SMarcin Niestroj 	{OFFSET(gpmc_ad5), (MODE(0) | PULLUP_EN | RXACTIVE)},	/* NAND AD5 */
43a73c8b32SMarcin Niestroj 	{OFFSET(gpmc_ad6), (MODE(0) | PULLUP_EN | RXACTIVE)},	/* NAND AD6 */
44a73c8b32SMarcin Niestroj 	{OFFSET(gpmc_ad7), (MODE(0) | PULLUP_EN | RXACTIVE)},	/* NAND AD7 */
45a73c8b32SMarcin Niestroj 	{OFFSET(gpmc_wait0), (MODE(0) | RXACTIVE | PULLUP_EN)}, /* NAND WAIT */
46a73c8b32SMarcin Niestroj 	{OFFSET(gpmc_wpn), (MODE(7) | PULLUP_EN | RXACTIVE)},	/* NAND_WPN */
47a73c8b32SMarcin Niestroj 	{OFFSET(gpmc_csn0), (MODE(0) | PULLUDEN)},	/* NAND_CS0 */
48a73c8b32SMarcin Niestroj 	{OFFSET(gpmc_advn_ale), (MODE(0) | PULLUDEN)}, /* NAND_ADV_ALE */
49a73c8b32SMarcin Niestroj 	{OFFSET(gpmc_oen_ren), (MODE(0) | PULLUDEN)},	/* NAND_OE */
50a73c8b32SMarcin Niestroj 	{OFFSET(gpmc_wen), (MODE(0) | PULLUDEN)},	/* NAND_WEN */
51a73c8b32SMarcin Niestroj 	{OFFSET(gpmc_be0n_cle), (MODE(0) | PULLUDEN)},	/* NAND_BE_CLE */
52a73c8b32SMarcin Niestroj 	{-1},
53a73c8b32SMarcin Niestroj };
54a73c8b32SMarcin Niestroj 
enable_i2c0_pin_mux(void)55a73c8b32SMarcin Niestroj static void enable_i2c0_pin_mux(void)
56a73c8b32SMarcin Niestroj {
57a73c8b32SMarcin Niestroj 	configure_module_pin_mux(i2c0_pin_mux);
58a73c8b32SMarcin Niestroj }
59a73c8b32SMarcin Niestroj 
chilisom_enable_pin_mux(void)60a73c8b32SMarcin Niestroj void chilisom_enable_pin_mux(void)
61a73c8b32SMarcin Niestroj {
62a73c8b32SMarcin Niestroj 	/* chilisom pin mux */
63a73c8b32SMarcin Niestroj 	configure_module_pin_mux(nand_pin_mux);
64a73c8b32SMarcin Niestroj }
65a73c8b32SMarcin Niestroj 
66a73c8b32SMarcin Niestroj static const struct ddr_data ddr3_chilisom_data = {
67a73c8b32SMarcin Niestroj 	.datardsratio0 = MT41K256M16HA125E_RD_DQS,
68a73c8b32SMarcin Niestroj 	.datawdsratio0 = MT41K256M16HA125E_WR_DQS,
69a73c8b32SMarcin Niestroj 	.datafwsratio0 = MT41K256M16HA125E_PHY_FIFO_WE,
70a73c8b32SMarcin Niestroj 	.datawrsratio0 = MT41K256M16HA125E_PHY_WR_DATA,
71a73c8b32SMarcin Niestroj };
72a73c8b32SMarcin Niestroj 
73a73c8b32SMarcin Niestroj static const struct cmd_control ddr3_chilisom_cmd_ctrl_data = {
74a73c8b32SMarcin Niestroj 	.cmd0csratio = MT41K256M16HA125E_RATIO,
75a73c8b32SMarcin Niestroj 	.cmd0iclkout = MT41K256M16HA125E_INVERT_CLKOUT,
76a73c8b32SMarcin Niestroj 
77a73c8b32SMarcin Niestroj 	.cmd1csratio = MT41K256M16HA125E_RATIO,
78a73c8b32SMarcin Niestroj 	.cmd1iclkout = MT41K256M16HA125E_INVERT_CLKOUT,
79a73c8b32SMarcin Niestroj 
80a73c8b32SMarcin Niestroj 	.cmd2csratio = MT41K256M16HA125E_RATIO,
81a73c8b32SMarcin Niestroj 	.cmd2iclkout = MT41K256M16HA125E_INVERT_CLKOUT,
82a73c8b32SMarcin Niestroj };
83a73c8b32SMarcin Niestroj 
84a73c8b32SMarcin Niestroj static struct emif_regs ddr3_chilisom_emif_reg_data = {
85a73c8b32SMarcin Niestroj 	.sdram_config = MT41K256M16HA125E_EMIF_SDCFG,
86a73c8b32SMarcin Niestroj 	.ref_ctrl = MT41K256M16HA125E_EMIF_SDREF,
87a73c8b32SMarcin Niestroj 	.sdram_tim1 = MT41K256M16HA125E_EMIF_TIM1,
88a73c8b32SMarcin Niestroj 	.sdram_tim2 = MT41K256M16HA125E_EMIF_TIM2,
89a73c8b32SMarcin Niestroj 	.sdram_tim3 = MT41K256M16HA125E_EMIF_TIM3,
90a73c8b32SMarcin Niestroj 	.ocp_config = 0x00141414,
91a73c8b32SMarcin Niestroj 	.zq_config = MT41K256M16HA125E_ZQ_CFG,
92a73c8b32SMarcin Niestroj 	.emif_ddr_phy_ctlr_1 = MT41K256M16HA125E_EMIF_READ_LATENCY,
93a73c8b32SMarcin Niestroj };
94a73c8b32SMarcin Niestroj 
chilisom_spl_board_init(void)95a73c8b32SMarcin Niestroj void chilisom_spl_board_init(void)
96a73c8b32SMarcin Niestroj {
97a73c8b32SMarcin Niestroj 	int mpu_vdd;
98a73c8b32SMarcin Niestroj 	int usb_cur_lim;
99a73c8b32SMarcin Niestroj 
100a73c8b32SMarcin Niestroj 	enable_i2c0_pin_mux();
101a73c8b32SMarcin Niestroj 
102a73c8b32SMarcin Niestroj 	/* Get the frequency */
103a73c8b32SMarcin Niestroj 	dpll_mpu_opp100.m = am335x_get_efuse_mpu_max_freq(cdev);
104a73c8b32SMarcin Niestroj 
105a73c8b32SMarcin Niestroj 
106a73c8b32SMarcin Niestroj 	if (i2c_probe(TPS65217_CHIP_PM))
107a73c8b32SMarcin Niestroj 		return;
108a73c8b32SMarcin Niestroj 
109a73c8b32SMarcin Niestroj 	/*
110a73c8b32SMarcin Niestroj 	 * Increase USB current limit to 1300mA or 1800mA and set
111a73c8b32SMarcin Niestroj 	 * the MPU voltage controller as needed.
112a73c8b32SMarcin Niestroj 	 */
113a73c8b32SMarcin Niestroj 	if (dpll_mpu_opp100.m == MPUPLL_M_1000) {
114a73c8b32SMarcin Niestroj 		usb_cur_lim = TPS65217_USB_INPUT_CUR_LIMIT_1800MA;
115a73c8b32SMarcin Niestroj 		mpu_vdd = TPS65217_DCDC_VOLT_SEL_1325MV;
116a73c8b32SMarcin Niestroj 	} else {
117a73c8b32SMarcin Niestroj 		usb_cur_lim = TPS65217_USB_INPUT_CUR_LIMIT_1300MA;
118a73c8b32SMarcin Niestroj 		mpu_vdd = TPS65217_DCDC_VOLT_SEL_1275MV;
119a73c8b32SMarcin Niestroj 	}
120a73c8b32SMarcin Niestroj 
121a73c8b32SMarcin Niestroj 	if (tps65217_reg_write(TPS65217_PROT_LEVEL_NONE,
122a73c8b32SMarcin Niestroj 			       TPS65217_POWER_PATH,
123a73c8b32SMarcin Niestroj 			       usb_cur_lim,
124a73c8b32SMarcin Niestroj 			       TPS65217_USB_INPUT_CUR_LIMIT_MASK))
125a73c8b32SMarcin Niestroj 		puts("tps65217_reg_write failure\n");
126a73c8b32SMarcin Niestroj 
127a73c8b32SMarcin Niestroj 	/* Set DCDC3 (CORE) voltage to 1.125V */
128a73c8b32SMarcin Niestroj 	if (tps65217_voltage_update(TPS65217_DEFDCDC3,
129a73c8b32SMarcin Niestroj 				    TPS65217_DCDC_VOLT_SEL_1125MV)) {
130a73c8b32SMarcin Niestroj 		puts("tps65217_voltage_update failure\n");
131a73c8b32SMarcin Niestroj 		return;
132a73c8b32SMarcin Niestroj 	}
133a73c8b32SMarcin Niestroj 	/* Set CORE Frequencies to OPP100 */
134a73c8b32SMarcin Niestroj 	do_setup_dpll(&dpll_core_regs, &dpll_core_opp100);
135a73c8b32SMarcin Niestroj 
136a73c8b32SMarcin Niestroj 	/* Set DCDC2 (MPU) voltage */
137a73c8b32SMarcin Niestroj 	if (tps65217_voltage_update(TPS65217_DEFDCDC2, mpu_vdd)) {
138a73c8b32SMarcin Niestroj 		puts("tps65217_voltage_update failure\n");
139a73c8b32SMarcin Niestroj 		return;
140a73c8b32SMarcin Niestroj 	}
141a73c8b32SMarcin Niestroj 
142a73c8b32SMarcin Niestroj 	/* Set LDO3 to 1.8V and LDO4 to 3.3V */
143a73c8b32SMarcin Niestroj 	if (tps65217_reg_write(TPS65217_PROT_LEVEL_2,
144a73c8b32SMarcin Niestroj 			       TPS65217_DEFLS1,
145a73c8b32SMarcin Niestroj 			       TPS65217_LDO_VOLTAGE_OUT_1_8,
146a73c8b32SMarcin Niestroj 			       TPS65217_LDO_MASK))
147a73c8b32SMarcin Niestroj 		puts("tps65217_reg_write failure\n");
148a73c8b32SMarcin Niestroj 
149a73c8b32SMarcin Niestroj 	if (tps65217_reg_write(TPS65217_PROT_LEVEL_2,
150a73c8b32SMarcin Niestroj 			       TPS65217_DEFLS2,
151a73c8b32SMarcin Niestroj 			       TPS65217_LDO_VOLTAGE_OUT_3_3,
152a73c8b32SMarcin Niestroj 			       TPS65217_LDO_MASK))
153a73c8b32SMarcin Niestroj 		puts("tps65217_reg_write failure\n");
154a73c8b32SMarcin Niestroj 
155a73c8b32SMarcin Niestroj 	/* Set MPU Frequency to what we detected now that voltages are set */
156a73c8b32SMarcin Niestroj 	do_setup_dpll(&dpll_mpu_regs, &dpll_mpu_opp100);
157a73c8b32SMarcin Niestroj }
158a73c8b32SMarcin Niestroj 
159a73c8b32SMarcin Niestroj #define OSC	(V_OSCK/1000000)
160a73c8b32SMarcin Niestroj const struct dpll_params dpll_ddr_chilisom = {
161a73c8b32SMarcin Niestroj 		400, OSC-1, 1, -1, -1, -1, -1};
162a73c8b32SMarcin Niestroj 
get_dpll_ddr_params(void)163a73c8b32SMarcin Niestroj const struct dpll_params *get_dpll_ddr_params(void)
164a73c8b32SMarcin Niestroj {
165a73c8b32SMarcin Niestroj 	return &dpll_ddr_chilisom;
166a73c8b32SMarcin Niestroj }
167a73c8b32SMarcin Niestroj 
168a73c8b32SMarcin Niestroj const struct ctrl_ioregs ioregs_chilisom = {
169a73c8b32SMarcin Niestroj 	.cm0ioctl		= MT41K256M16HA125E_IOCTRL_VALUE,
170a73c8b32SMarcin Niestroj 	.cm1ioctl		= MT41K256M16HA125E_IOCTRL_VALUE,
171a73c8b32SMarcin Niestroj 	.cm2ioctl		= MT41K256M16HA125E_IOCTRL_VALUE,
172a73c8b32SMarcin Niestroj 	.dt0ioctl		= MT41K256M16HA125E_IOCTRL_VALUE,
173a73c8b32SMarcin Niestroj 	.dt1ioctl		= MT41K256M16HA125E_IOCTRL_VALUE,
174a73c8b32SMarcin Niestroj };
175a73c8b32SMarcin Niestroj 
sdram_init(void)176a73c8b32SMarcin Niestroj void sdram_init(void)
177a73c8b32SMarcin Niestroj {
178a73c8b32SMarcin Niestroj 	config_ddr(400, &ioregs_chilisom,
179a73c8b32SMarcin Niestroj 		   &ddr3_chilisom_data,
180a73c8b32SMarcin Niestroj 		   &ddr3_chilisom_cmd_ctrl_data,
181a73c8b32SMarcin Niestroj 		   &ddr3_chilisom_emif_reg_data, 0);
182a73c8b32SMarcin Niestroj }
183a73c8b32SMarcin Niestroj 
184a73c8b32SMarcin Niestroj #endif /* CONFIG_SKIP_LOWLEVEL_INIT */
185