blob: 9d54d60bb17d4b0981559a7e448298e41454d9c3 [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>
Max Krummenacher22c01332020-10-28 11:58:12 +020026#include <power/pca9450.h>
Igor Opaniuk309e65b2020-01-28 14:42:25 +010027#include <power/pmic.h>
28#include <spl.h>
29
30DECLARE_GLOBAL_DATA_PTR;
31
Max Krummenacher22c01332020-10-28 11:58:12 +020032#define I2C_PMIC_BUS_ID 1
33
Igor Opaniuk309e65b2020-01-28 14:42:25 +010034int spl_board_boot_device(enum boot_device boot_dev_spl)
35{
36 switch (boot_dev_spl) {
Marcel Ziswiler2b910a22022-08-22 15:06:02 +020037 case MMC1_BOOT: /* eMMC */
Igor Opaniuk309e65b2020-01-28 14:42:25 +010038 return BOOT_DEVICE_MMC1;
Marcel Ziswiler2b910a22022-08-22 15:06:02 +020039 case SD2_BOOT: /* SD card */
Igor Opaniuk309e65b2020-01-28 14:42:25 +010040 case MMC2_BOOT:
41 return BOOT_DEVICE_MMC2;
Igor Opaniuk309e65b2020-01-28 14:42:25 +010042 case USB_BOOT:
43 return BOOT_DEVICE_BOARD;
44 default:
45 return BOOT_DEVICE_NONE;
46 }
47}
48
49void spl_dram_init(void)
50{
51 ddr_init(&dram_timing);
52}
53
54void spl_board_init(void)
55{
Marek Vasut085555f2022-09-19 21:41:15 +020056 arch_misc_init();
Igor Opaniuk309e65b2020-01-28 14:42:25 +010057}
58
59#ifdef CONFIG_SPL_LOAD_FIT
60int board_fit_config_name_match(const char *name)
61{
62 /* Just empty function now - can't decide what to choose */
63 debug("%s: %s\n", __func__, name);
64
65 return 0;
66}
67#endif
68
Marek Vasut483350a2022-04-08 02:15:00 +020069__weak void board_early_init(void)
Igor Opaniuk309e65b2020-01-28 14:42:25 +010070{
Marek Vasut483350a2022-04-08 02:15:00 +020071 init_uart_clk(0);
Igor Opaniuk309e65b2020-01-28 14:42:25 +010072}
73
74int power_init_board(void)
75{
76 struct udevice *dev;
77 int ret;
78
Max Krummenacher22c01332020-10-28 11:58:12 +020079 if (IS_ENABLED(CONFIG_SPL_DM_PMIC_PCA9450)) {
Marcel Ziswiler2712c782022-07-21 15:41:23 +020080 ret = pmic_get("pmic@25", &dev);
Max Krummenacher22c01332020-10-28 11:58:12 +020081 if (ret == -ENODEV) {
82 puts("No pmic found\n");
83 return ret;
84 }
Igor Opaniuk309e65b2020-01-28 14:42:25 +010085
Max Krummenacher22c01332020-10-28 11:58:12 +020086 if (ret != 0)
87 return ret;
Igor Opaniuk309e65b2020-01-28 14:42:25 +010088
Max Krummenacher22c01332020-10-28 11:58:12 +020089 /* BUCKxOUT_DVS0/1 control BUCK123 output, clear PRESET_EN */
90 pmic_reg_write(dev, PCA9450_BUCK123_DVS, 0x29);
Igor Opaniuk309e65b2020-01-28 14:42:25 +010091
Max Krummenacher22c01332020-10-28 11:58:12 +020092 /* increase VDD_DRAM to 0.975v for 1.5Ghz DDR */
93 pmic_reg_write(dev, PCA9450_BUCK3OUT_DVS0, 0x1c);
Igor Opaniuk309e65b2020-01-28 14:42:25 +010094
Max Krummenacher49793d22020-10-28 11:58:14 +020095 pmic_reg_write(dev, PCA9450_CONFIG2, 0x1);
96
Max Krummenacher22c01332020-10-28 11:58:12 +020097 return 0;
98 }
Igor Opaniuk309e65b2020-01-28 14:42:25 +010099
100 return 0;
101}
102
103void board_init_f(ulong dummy)
104{
105 struct udevice *dev;
106 int ret;
107
108 arch_cpu_init();
109
Marek Vasut483350a2022-04-08 02:15:00 +0200110 board_early_init();
Igor Opaniuk309e65b2020-01-28 14:42:25 +0100111
112 timer_init();
113
Igor Opaniuk309e65b2020-01-28 14:42:25 +0100114 /* Clear the BSS. */
115 memset(__bss_start, 0, __bss_end - __bss_start);
116
117 ret = spl_early_init();
118 if (ret) {
119 debug("spl_early_init() failed: %d\n", ret);
120 hang();
121 }
122
123 ret = uclass_get_device_by_name(UCLASS_CLK,
124 "clock-controller@30380000",
125 &dev);
126 if (ret < 0) {
127 printf("Failed to find clock node. Check device tree\n");
128 hang();
129 }
130
Marcel Ziswiler5d29c4d2022-05-17 00:21:45 +0200131 preloader_console_init();
132
Igor Opaniuk309e65b2020-01-28 14:42:25 +0100133 enable_tzc380();
134
135 power_init_board();
136
137 /* DDR initialization */
138 spl_dram_init();
139
140 board_init_r(NULL, 0);
141}