blob: 8c357757c13a207a8b00ce444b283f567a19ecc2 [file] [log] [blame]
Tim Harvey256dba02021-03-02 14:00:21 -08001// SPDX-License-Identifier: GPL-2.0+
2/*
3 * Copyright 2021 Gateworks Corporation
4 */
5
6#include <common.h>
7#include <cpu_func.h>
8#include <hang.h>
9#include <i2c.h>
10#include <image.h>
11#include <init.h>
12#include <log.h>
13#include <spl.h>
14#include <asm/io.h>
15#include <asm/mach-imx/gpio.h>
16#include <asm/mach-imx/iomux-v3.h>
17#include <asm/arch/clock.h>
18#include <asm/arch/imx8mm_pins.h>
19#include <asm/arch/sys_proto.h>
20#include <asm/mach-imx/boot_mode.h>
21#include <asm/arch/ddr.h>
22#include <asm-generic/gpio.h>
23
24#include <dm/uclass.h>
25#include <dm/device.h>
26#include <dm/uclass-internal.h>
27#include <dm/device-internal.h>
28
Tim Harvey1b7fbf62021-06-30 16:50:02 -070029#include <power/bd71837.h>
Tim Harvey256dba02021-03-02 14:00:21 -080030#include <power/mp5416.h>
31
32#include "gsc.h"
33#include "lpddr4_timing.h"
34
35#define PCIE_RSTN IMX_GPIO_NR(4, 6)
36
37DECLARE_GLOBAL_DATA_PTR;
38
39static void spl_dram_init(int size)
40{
41 struct dram_timing_info *dram_timing;
42
43 switch (size) {
44 case 1:
45 dram_timing = &dram_timing_1gb;
46 break;
47 case 4:
48 dram_timing = &dram_timing_4gb;
49 break;
50 default:
51 printf("Unknown DDR configuration: %d GiB\n", size);
52 dram_timing = &dram_timing_1gb;
53 size = 1;
54 }
55
56 printf("DRAM : LPDDR4 %d GiB\n", size);
57 ddr_init(dram_timing);
58 writel(size, M4_BOOTROM_BASE_ADDR);
59}
60
61#define UART_PAD_CTRL (PAD_CTL_DSE6 | PAD_CTL_FSEL1)
62#define WDOG_PAD_CTRL (PAD_CTL_DSE6 | PAD_CTL_ODE | PAD_CTL_PUE | PAD_CTL_PE)
63
64static iomux_v3_cfg_t const uart_pads[] = {
65 IMX8MM_PAD_UART2_RXD_UART2_RX | MUX_PAD_CTRL(UART_PAD_CTRL),
66 IMX8MM_PAD_UART2_TXD_UART2_TX | MUX_PAD_CTRL(UART_PAD_CTRL),
67};
68
69static iomux_v3_cfg_t const wdog_pads[] = {
70 IMX8MM_PAD_GPIO1_IO02_WDOG1_WDOG_B | MUX_PAD_CTRL(WDOG_PAD_CTRL),
71};
72
73int board_early_init_f(void)
74{
75 struct wdog_regs *wdog = (struct wdog_regs *)WDOG1_BASE_ADDR;
76
77 imx_iomux_v3_setup_multiple_pads(wdog_pads, ARRAY_SIZE(wdog_pads));
78
79 set_wdog_reset(wdog);
80
81 imx_iomux_v3_setup_multiple_pads(uart_pads, ARRAY_SIZE(uart_pads));
82
83 return 0;
84}
85
86/*
87 * Model specific PMIC adjustments necessary prior to DRAM init
88 *
89 * Note that we can not use pmic dm drivers here as we have a generic
90 * venice dt that does not have board-specific pmic's defined.
91 *
Tim Harvey1b7fbf62021-06-30 16:50:02 -070092 * Instead we must use dm_i2c so we a helpers to give us
93 * clrsetbit functions we would otherwise have if we could use PMIC dm
94 * drivers.
Tim Harvey256dba02021-03-02 14:00:21 -080095 */
Tim Harvey1b7fbf62021-06-30 16:50:02 -070096static int dm_i2c_clrsetbits(struct udevice *dev, uint reg, uint clr, uint set)
97{
98 int ret;
99 u8 val;
100
101 ret = dm_i2c_read(dev, reg, &val, 1);
102 if (ret)
103 return ret;
104 val = (val & ~clr) | set;
105
106 return dm_i2c_write(dev, reg, &val, 1);
107}
108
Tim Harvey256dba02021-03-02 14:00:21 -0800109static int power_init_board(void)
110{
111 const char *model = gsc_get_model();
112 struct udevice *bus;
113 struct udevice *dev;
114 int ret;
115
116 if ((!strncmp(model, "GW71", 4)) ||
117 (!strncmp(model, "GW72", 4)) ||
118 (!strncmp(model, "GW73", 4))) {
119 ret = uclass_get_device_by_name(UCLASS_I2C, "i2c@30a20000", &bus);
120 if (ret) {
121 printf("PMIC : failed I2C1 probe: %d\n", ret);
122 return ret;
123 }
124 ret = dm_i2c_probe(bus, 0x69, 0, &dev);
125 if (ret) {
126 printf("PMIC : failed probe: %d\n", ret);
127 return ret;
128 }
129 puts("PMIC : MP5416\n");
130
131 /* set VDD_ARM SW3 to 0.92V for 1.6GHz */
132 dm_i2c_reg_write(dev, MP5416_VSET_SW3,
133 BIT(7) | MP5416_VSET_SW3_SVAL(920000));
134 }
135
Tim Harvey1b7fbf62021-06-30 16:50:02 -0700136 else if (!strncmp(model, "GW7901", 6)) {
137 ret = uclass_get_device_by_name(UCLASS_I2C, "i2c@30a30000", &bus);
138 if (ret) {
139 printf("PMIC : failed I2C2 probe: %d\n", ret);
140 return ret;
141 }
142 ret = dm_i2c_probe(bus, 0x4b, 0, &dev);
143 if (ret) {
144 printf("PMIC : failed probe: %d\n", ret);
145 return ret;
146 }
147 puts("PMIC : BD71847\n");
148
149 /* unlock the PMIC regs */
150 dm_i2c_reg_write(dev, BD718XX_REGLOCK, 0x1);
151
152 /* set switchers to forced PWM mode */
153 dm_i2c_clrsetbits(dev, BD718XX_BUCK1_CTRL, 0, 0x8);
154 dm_i2c_clrsetbits(dev, BD718XX_BUCK2_CTRL, 0, 0x8);
155 dm_i2c_clrsetbits(dev, BD718XX_1ST_NODVS_BUCK_CTRL, 0, 0x8);
156 dm_i2c_clrsetbits(dev, BD718XX_2ND_NODVS_BUCK_CTRL, 0, 0x8);
157 dm_i2c_clrsetbits(dev, BD718XX_3RD_NODVS_BUCK_CTRL, 0, 0x8);
158 dm_i2c_clrsetbits(dev, BD718XX_4TH_NODVS_BUCK_CTRL, 0, 0x8);
159
160 /* increase VDD_0P95 (VDD_GPU/VPU/DRAM) to 0.975v for 1.5Ghz DDR */
161 dm_i2c_reg_write(dev, BD718XX_1ST_NODVS_BUCK_VOLT, 0x83);
162
163 /* increase VDD_SOC to 0.85v before first DRAM access */
164 dm_i2c_reg_write(dev, BD718XX_BUCK1_VOLT_RUN, 0x0f);
165
166 /* increase VDD_ARM to 0.92v for 800 and 1600Mhz */
167 dm_i2c_reg_write(dev, BD718XX_BUCK2_VOLT_RUN, 0x16);
168
169 /* Lock the PMIC regs */
170 dm_i2c_reg_write(dev, BD718XX_REGLOCK, 0x11);
171 }
172
Tim Harvey256dba02021-03-02 14:00:21 -0800173 return 0;
174}
175
176void board_init_f(ulong dummy)
177{
178 struct udevice *dev;
179 int ret;
180 int dram_sz;
181
182 arch_cpu_init();
183
184 init_uart_clk(1);
185
186 board_early_init_f();
187
188 timer_init();
189
190 preloader_console_init();
191
192 /* Clear the BSS. */
193 memset(__bss_start, 0, __bss_end - __bss_start);
194
195 ret = spl_early_init();
196 if (ret) {
197 debug("spl_early_init() failed: %d\n", ret);
198 hang();
199 }
200
201 ret = uclass_get_device_by_name(UCLASS_CLK,
202 "clock-controller@30380000",
203 &dev);
204 if (ret < 0) {
205 printf("Failed to find clock node. Check device tree\n");
206 hang();
207 }
208
209 enable_tzc380();
210
211 /* need to hold PCIe switch in reset otherwise it can lock i2c bus EEPROM is on */
212 gpio_request(PCIE_RSTN, "perst#");
213 gpio_direction_output(PCIE_RSTN, 0);
214
215 /* GSC */
216 dram_sz = gsc_init(0);
217
218 /* PMIC */
219 power_init_board();
220
221 /* DDR initialization */
222 spl_dram_init(dram_sz);
223
224 board_init_r(NULL, 0);
225}
226
227/* determine prioritized order of boot devices to load U-Boot from */
228void board_boot_order(u32 *spl_boot_list)
229{
230 /*
231 * If the SPL was loaded via serial loader, we try to get
232 * U-Boot proper via USB SDP.
233 */
234 if (spl_boot_device() == BOOT_DEVICE_BOARD)
235 spl_boot_list[0] = BOOT_DEVICE_BOARD;
236
237 /* we have only eMMC in default venice dt */
238 spl_boot_list[0] = BOOT_DEVICE_MMC1;
239}
240
241/* return boot device based on where the SPL was loaded from */
242int spl_board_boot_device(enum boot_device boot_dev_spl)
243{
244 switch (boot_dev_spl) {
245 case USB_BOOT:
246 return BOOT_DEVICE_BOARD;
247 /* SDHC2 */
248 case SD2_BOOT:
249 case MMC2_BOOT:
250 return BOOT_DEVICE_MMC1;
251 /* SDHC3 */
252 case SD3_BOOT:
253 case MMC3_BOOT:
254 return BOOT_DEVICE_MMC2;
255 default:
256 return BOOT_DEVICE_NONE;
257 }
258}