blob: 97d6a31da1506c3f9e1a530b8d63818326819797 [file] [log] [blame]
Igor Opaniuk309e65b2020-01-28 14:42:25 +01001// SPDX-License-Identifier: GPL-2.0+
2/*
3 * Copyright 2020 Toradex
4 */
5
6#include <common.h>
Simon Glassed38aef2020-05-10 11:40:03 -06007#include <command.h>
Simon Glass2dc9c342020-05-10 11:40:01 -06008#include <image.h>
Simon Glass97589732020-05-10 11:40:02 -06009#include <init.h>
Simon Glass0f2af882020-05-10 11:40:05 -060010#include <log.h>
Igor Opaniuk309e65b2020-01-28 14:42:25 +010011#include <asm/arch/clock.h>
12#include <asm/arch/ddr.h>
13#include <asm/arch/imx8mm_pins.h>
14#include <asm/arch/sys_proto.h>
Simon Glass3ba929a2020-10-30 21:38:53 -060015#include <asm/global_data.h>
Igor Opaniuk309e65b2020-01-28 14:42:25 +010016#include <asm/io.h>
17#include <asm/mach-imx/boot_mode.h>
18#include <asm/mach-imx/iomux-v3.h>
19#include <cpu_func.h>
20#include <dm/device.h>
21#include <dm/device-internal.h>
22#include <dm/uclass.h>
23#include <dm/uclass-internal.h>
24#include <hang.h>
Max Krummenacher22c01332020-10-28 11:58:12 +020025#include <i2c.h>
Igor Opaniuk309e65b2020-01-28 14:42:25 +010026#include <power/bd71837.h>
Max Krummenacher22c01332020-10-28 11:58:12 +020027#include <power/pca9450.h>
Igor Opaniuk309e65b2020-01-28 14:42:25 +010028#include <power/pmic.h>
29#include <spl.h>
30
31DECLARE_GLOBAL_DATA_PTR;
32
Max Krummenacher22c01332020-10-28 11:58:12 +020033#define I2C_PMIC_BUS_ID 1
34
Igor Opaniuk309e65b2020-01-28 14:42:25 +010035int spl_board_boot_device(enum boot_device boot_dev_spl)
36{
37 switch (boot_dev_spl) {
38 case MMC1_BOOT:
39 return BOOT_DEVICE_MMC1;
40 case SD2_BOOT:
41 case MMC2_BOOT:
42 return BOOT_DEVICE_MMC2;
43 case SD3_BOOT:
44 case MMC3_BOOT:
45 return BOOT_DEVICE_MMC1;
46 case USB_BOOT:
47 return BOOT_DEVICE_BOARD;
48 default:
49 return BOOT_DEVICE_NONE;
50 }
51}
52
53void spl_dram_init(void)
54{
55 ddr_init(&dram_timing);
56}
57
58void spl_board_init(void)
59{
60 /* Serial download mode */
61 if (is_usb_boot()) {
62 puts("Back to ROM, SDP\n");
63 restore_boot_params();
64 }
65 puts("Normal Boot\n");
66}
67
68#ifdef CONFIG_SPL_LOAD_FIT
69int board_fit_config_name_match(const char *name)
70{
71 /* Just empty function now - can't decide what to choose */
72 debug("%s: %s\n", __func__, name);
73
74 return 0;
75}
76#endif
77
78#define UART_PAD_CTRL (PAD_CTL_PUE | PAD_CTL_PE | PAD_CTL_DSE4)
79#define WDOG_PAD_CTRL (PAD_CTL_DSE6 | PAD_CTL_ODE | PAD_CTL_PUE | PAD_CTL_PE)
80
81/* Verdin UART_3, Console/Debug UART */
82static iomux_v3_cfg_t const uart_pads[] = {
83 IMX8MM_PAD_SAI2_RXFS_UART1_TX | MUX_PAD_CTRL(UART_PAD_CTRL),
84 IMX8MM_PAD_SAI2_RXC_UART1_RX | MUX_PAD_CTRL(UART_PAD_CTRL),
85};
86
87static iomux_v3_cfg_t const wdog_pads[] = {
88 IMX8MM_PAD_GPIO1_IO02_WDOG1_WDOG_B | MUX_PAD_CTRL(WDOG_PAD_CTRL),
89};
90
91int board_early_init_f(void)
92{
93 struct wdog_regs *wdog = (struct wdog_regs *)WDOG1_BASE_ADDR;
94
95 imx_iomux_v3_setup_multiple_pads(wdog_pads, ARRAY_SIZE(wdog_pads));
96
97 set_wdog_reset(wdog);
98
99 imx_iomux_v3_setup_multiple_pads(uart_pads, ARRAY_SIZE(uart_pads));
100
101 return 0;
102}
103
104int power_init_board(void)
105{
106 struct udevice *dev;
107 int ret;
108
Max Krummenacher22c01332020-10-28 11:58:12 +0200109 if (IS_ENABLED(CONFIG_SPL_DM_PMIC_PCA9450)) {
110 ret = pmic_get("pmic", &dev);
111 if (ret == -ENODEV) {
112 puts("No pmic found\n");
113 return ret;
114 }
Igor Opaniuk309e65b2020-01-28 14:42:25 +0100115
Max Krummenacher22c01332020-10-28 11:58:12 +0200116 if (ret != 0)
117 return ret;
Igor Opaniuk309e65b2020-01-28 14:42:25 +0100118
Max Krummenacher22c01332020-10-28 11:58:12 +0200119 /* BUCKxOUT_DVS0/1 control BUCK123 output, clear PRESET_EN */
120 pmic_reg_write(dev, PCA9450_BUCK123_DVS, 0x29);
Igor Opaniuk309e65b2020-01-28 14:42:25 +0100121
Max Krummenacher22c01332020-10-28 11:58:12 +0200122 /* increase VDD_DRAM to 0.975v for 1.5Ghz DDR */
123 pmic_reg_write(dev, PCA9450_BUCK3OUT_DVS0, 0x1c);
Igor Opaniuk309e65b2020-01-28 14:42:25 +0100124
Max Krummenacher22c01332020-10-28 11:58:12 +0200125 /* set WDOG_B_CFG to cold reset */
126 pmic_reg_write(dev, PCA9450_RESET_CTRL, 0xA1);
Igor Opaniuk309e65b2020-01-28 14:42:25 +0100127
Max Krummenacher49793d22020-10-28 11:58:14 +0200128 pmic_reg_write(dev, PCA9450_CONFIG2, 0x1);
129
Max Krummenacher22c01332020-10-28 11:58:12 +0200130 return 0;
131 }
Igor Opaniuk309e65b2020-01-28 14:42:25 +0100132
133 return 0;
134}
135
136void board_init_f(ulong dummy)
137{
138 struct udevice *dev;
139 int ret;
140
141 arch_cpu_init();
142
143 init_uart_clk(0);
144
145 board_early_init_f();
146
147 timer_init();
148
149 preloader_console_init();
150
151 /* Clear the BSS. */
152 memset(__bss_start, 0, __bss_end - __bss_start);
153
154 ret = spl_early_init();
155 if (ret) {
156 debug("spl_early_init() failed: %d\n", ret);
157 hang();
158 }
159
160 ret = uclass_get_device_by_name(UCLASS_CLK,
161 "clock-controller@30380000",
162 &dev);
163 if (ret < 0) {
164 printf("Failed to find clock node. Check device tree\n");
165 hang();
166 }
167
168 enable_tzc380();
169
170 power_init_board();
171
172 /* DDR initialization */
173 spl_dram_init();
174
175 board_init_r(NULL, 0);
176}