blob: 97791aaeffe2e1047381adc02d9c2a6f76bcd786 [file] [log] [blame]
Tom Rini10e47792018-05-06 17:58:06 -04001// SPDX-License-Identifier: GPL-2.0+
Rajeshwari Birje987b0dd2013-12-26 09:44:17 +05302/*
3 * (C) Copyright 2013 SAMSUNG Electronics
4 * Rajeshwari Shinde <rajeshwari.s@samsung.com>
Rajeshwari Birje987b0dd2013-12-26 09:44:17 +05305 */
6
7#include <common.h>
8#include <cros_ec.h>
Simon Glassed38aef2020-05-10 11:40:03 -06009#include <env.h>
Rajeshwari Birje987b0dd2013-12-26 09:44:17 +053010#include <errno.h>
11#include <fdtdec.h>
Simon Glassf11478f2019-12-28 10:45:07 -070012#include <hang.h>
Simon Glassa7b51302019-11-14 12:57:46 -070013#include <init.h>
Simon Glass0f2af882020-05-10 11:40:05 -060014#include <log.h>
Simon Glass274e0b02020-05-10 11:39:56 -060015#include <net.h>
Rajeshwari Birje987b0dd2013-12-26 09:44:17 +053016#include <spi.h>
17#include <tmu.h>
18#include <netdev.h>
Simon Glass3ba929a2020-10-30 21:38:53 -060019#include <asm/global_data.h>
Rajeshwari Birje987b0dd2013-12-26 09:44:17 +053020#include <asm/io.h>
Simon Glass37f11622014-10-20 19:48:37 -060021#include <asm/gpio.h>
Rajeshwari Birje987b0dd2013-12-26 09:44:17 +053022#include <asm/arch/board.h>
23#include <asm/arch/cpu.h>
24#include <asm/arch/dwmmc.h>
Rajeshwari Birje987b0dd2013-12-26 09:44:17 +053025#include <asm/arch/mmc.h>
26#include <asm/arch/pinmux.h>
27#include <asm/arch/power.h>
Ajay Kumar11763482014-09-05 16:53:30 +053028#include <asm/arch/system.h>
Piotr Wilczek2c3eed52014-03-07 14:59:45 +010029#include <lcd.h>
Przemyslaw Marczak110aa292015-04-20 20:07:50 +020030#include <i2c.h>
Marek Szyprowskibc4a2e32020-01-17 14:02:44 +010031#include <mmc.h>
32#include <stdio_dev.h>
Lukasz Majewski7573b962015-03-03 17:32:03 +010033#include <usb.h>
Joonyoung Shim95d3a1d2015-05-22 18:14:24 +020034#include <dwc3-uboot.h>
Simon Glassdbd79542020-05-10 11:40:11 -060035#include <linux/delay.h>
Joonyoung Shim95d3a1d2015-05-22 18:14:24 +020036#include <samsung/misc.h>
Thomas Abraham8d84faa2016-04-23 22:18:14 +053037#include <dm/pinctrl.h>
38#include <dm.h>
Rajeshwari Birje987b0dd2013-12-26 09:44:17 +053039
40DECLARE_GLOBAL_DATA_PTR;
41
Jeroen Hofstee5cd82942014-10-08 22:57:28 +020042__weak int exynos_early_init_f(void)
Piotr Wilczek942d0a92014-03-07 14:59:43 +010043{
44 return 0;
45}
Piotr Wilczek942d0a92014-03-07 14:59:43 +010046
Jeroen Hofstee5cd82942014-10-08 22:57:28 +020047__weak int exynos_power_init(void)
Piotr Wilczek942d0a92014-03-07 14:59:43 +010048{
49 return 0;
50}
Piotr Wilczek942d0a92014-03-07 14:59:43 +010051
Marek Szyprowskibc4a2e32020-01-17 14:02:44 +010052/**
53 * get_boot_mmc_dev() - read boot MMC device id from XOM[7:5] pins.
54 */
55static int get_boot_mmc_dev(void)
56{
57 u32 mode = readl(EXYNOS4_OP_MODE) & 0x1C;
58
59 if (mode == 0x04)
60 return 2; /* MMC2: SD */
61
62 /* MMC0: eMMC or unknown */
63 return 0;
64}
65
Rajeshwari Birje987b0dd2013-12-26 09:44:17 +053066#if defined CONFIG_EXYNOS_TMU
67/* Boot Time Thermal Analysis for SoC temperature threshold breach */
68static void boot_temp_check(void)
69{
70 int temp;
71
72 switch (tmu_monitor(&temp)) {
73 case TMU_STATUS_NORMAL:
74 break;
75 case TMU_STATUS_TRIPPED:
76 /*
77 * Status TRIPPED ans WARNING means corresponding threshold
78 * breach
79 */
80 puts("EXYNOS_TMU: TRIPPING! Device power going down ...\n");
81 set_ps_hold_ctrl();
82 hang();
83 break;
84 case TMU_STATUS_WARNING:
85 puts("EXYNOS_TMU: WARNING! Temperature very high\n");
86 break;
87 case TMU_STATUS_INIT:
88 /*
89 * TMU_STATUS_INIT means something is wrong with temperature
90 * sensing and TMU status was changed back from NORMAL to INIT.
91 */
92 puts("EXYNOS_TMU: WARNING! Temperature sensing not done\n");
93 break;
94 default:
95 debug("EXYNOS_TMU: Unknown TMU state\n");
96 }
97}
98#endif
99
100int board_init(void)
101{
102 gd->bd->bi_boot_params = (PHYS_SDRAM_1 + 0x100UL);
103#if defined CONFIG_EXYNOS_TMU
104 if (tmu_init(gd->fdt_blob) != TMU_STATUS_NORMAL) {
105 debug("%s: Failed to init TMU\n", __func__);
106 return -1;
107 }
108 boot_temp_check();
109#endif
Przemyslaw Marczakc32a04c2015-02-17 14:50:25 +0100110#ifdef CONFIG_TZSW_RESERVED_DRAM_SIZE
111 /* The last few MB of memory can be reserved for secure firmware */
112 ulong size = CONFIG_TZSW_RESERVED_DRAM_SIZE;
Rajeshwari Birje987b0dd2013-12-26 09:44:17 +0530113
Przemyslaw Marczakc32a04c2015-02-17 14:50:25 +0100114 gd->ram_size -= size;
115 gd->bd->bi_dram[CONFIG_NR_DRAM_BANKS - 1].size -= size;
116#endif
Rajeshwari Birje987b0dd2013-12-26 09:44:17 +0530117 return exynos_init();
118}
119
120int dram_init(void)
121{
Ɓukasz Majewski33d7a192015-03-04 10:54:48 +0100122 unsigned int i;
Thomas Abraham8d84faa2016-04-23 22:18:14 +0530123 unsigned long addr;
Rajeshwari Birje987b0dd2013-12-26 09:44:17 +0530124
125 for (i = 0; i < CONFIG_NR_DRAM_BANKS; i++) {
126 addr = CONFIG_SYS_SDRAM_BASE + (i * SDRAM_BANK_SIZE);
127 gd->ram_size += get_ram_size((long *)addr, SDRAM_BANK_SIZE);
128 }
129 return 0;
130}
131
Simon Glass2f949c32017-03-31 08:40:32 -0600132int dram_init_banksize(void)
Rajeshwari Birje987b0dd2013-12-26 09:44:17 +0530133{
Ɓukasz Majewski33d7a192015-03-04 10:54:48 +0100134 unsigned int i;
Thomas Abraham8d84faa2016-04-23 22:18:14 +0530135 unsigned long addr, size;
Rajeshwari Birje987b0dd2013-12-26 09:44:17 +0530136
137 for (i = 0; i < CONFIG_NR_DRAM_BANKS; i++) {
138 addr = CONFIG_SYS_SDRAM_BASE + (i * SDRAM_BANK_SIZE);
139 size = get_ram_size((long *)addr, SDRAM_BANK_SIZE);
140
141 gd->bd->bi_dram[i].start = addr;
142 gd->bd->bi_dram[i].size = size;
143 }
Simon Glass2f949c32017-03-31 08:40:32 -0600144
145 return 0;
Rajeshwari Birje987b0dd2013-12-26 09:44:17 +0530146}
147
148static int board_uart_init(void)
149{
Thomas Abraham8d84faa2016-04-23 22:18:14 +0530150#ifndef CONFIG_PINCTRL_EXYNOS
Rajeshwari Birje987b0dd2013-12-26 09:44:17 +0530151 int err, uart_id, ret = 0;
152
153 for (uart_id = PERIPH_ID_UART0; uart_id <= PERIPH_ID_UART3; uart_id++) {
154 err = exynos_pinmux_config(uart_id, PINMUX_FLAG_NONE);
155 if (err) {
156 debug("UART%d not configured\n",
157 (uart_id - PERIPH_ID_UART0));
158 ret |= err;
159 }
160 }
161 return ret;
Thomas Abraham8d84faa2016-04-23 22:18:14 +0530162#else
163 return 0;
164#endif
Rajeshwari Birje987b0dd2013-12-26 09:44:17 +0530165}
166
167#ifdef CONFIG_BOARD_EARLY_INIT_F
168int board_early_init_f(void)
169{
170 int err;
Przemyslaw Marczak4d2a92c2014-09-01 13:50:49 +0200171#ifdef CONFIG_BOARD_TYPES
172 set_board_type();
173#endif
Rajeshwari Birje987b0dd2013-12-26 09:44:17 +0530174 err = board_uart_init();
175 if (err) {
176 debug("UART init failed\n");
177 return err;
178 }
179
180#ifdef CONFIG_SYS_I2C_INIT_BOARD
181 board_i2c_init(gd->fdt_blob);
182#endif
Ajay Kumar11763482014-09-05 16:53:30 +0530183
Piotr Wilczek942d0a92014-03-07 14:59:43 +0100184 return exynos_early_init_f();
Rajeshwari Birje987b0dd2013-12-26 09:44:17 +0530185}
186#endif
187
Simon Glass31339412021-08-08 12:20:27 -0600188#if CONFIG_IS_ENABLED(POWER_LEGACY) || CONFIG_IS_ENABLED(DM_PMIC)
Rajeshwari Birje987b0dd2013-12-26 09:44:17 +0530189int power_init_board(void)
190{
Rajeshwari Birje987b0dd2013-12-26 09:44:17 +0530191 set_ps_hold_ctrl();
192
Piotr Wilczek942d0a92014-03-07 14:59:43 +0100193 return exynos_power_init();
Rajeshwari Birje987b0dd2013-12-26 09:44:17 +0530194}
195#endif
196
Krzysztof Kozlowskic51bd0b2019-03-06 19:37:52 +0100197#if defined(CONFIG_DISPLAY_BOARDINFO) || defined(CONFIG_DISPLAY_BOARDINFO_LATE)
Piotr Wilczek3df7aff2014-03-07 14:59:42 +0100198int checkboard(void)
199{
Simon Glass6ceeff42019-01-11 18:37:07 -0700200 if (IS_ENABLED(CONFIG_BOARD_TYPES)) {
Krzysztof Kozlowski36476ee2019-03-06 19:37:51 +0100201 const char *board_info;
202
203 if (IS_ENABLED(CONFIG_DISPLAY_BOARDINFO_LATE)) {
204 /*
205 * Printing type requires having revision, although
206 * this will succeed only if done late.
207 * Otherwise revision will be set in misc_init_r().
208 */
209 set_board_revision();
210 }
211
212 board_info = get_board_type();
Simon Glass6ceeff42019-01-11 18:37:07 -0700213
214 if (board_info)
215 printf("Type: %s\n", board_info);
216 }
Piotr Wilczek3df7aff2014-03-07 14:59:42 +0100217
Piotr Wilczek3df7aff2014-03-07 14:59:42 +0100218 return 0;
219}
Rajeshwari Birje987b0dd2013-12-26 09:44:17 +0530220#endif
Rajeshwari Birje987b0dd2013-12-26 09:44:17 +0530221
222#ifdef CONFIG_BOARD_LATE_INIT
223int board_late_init(void)
224{
Simon Glassfe3f6432018-11-06 15:21:26 -0700225 struct udevice *dev;
226 int ret;
Marek Szyprowskibc4a2e32020-01-17 14:02:44 +0100227 int mmcbootdev = get_boot_mmc_dev();
228 char mmcbootdev_str[16];
Rajeshwari Birje987b0dd2013-12-26 09:44:17 +0530229
Simon Glassfe3f6432018-11-06 15:21:26 -0700230 ret = uclass_first_device_err(UCLASS_CROS_EC, &dev);
231 if (ret && ret != -ENODEV) {
Rajeshwari Birje987b0dd2013-12-26 09:44:17 +0530232 /* Force console on */
233 gd->flags &= ~GD_FLG_SILENT;
234
Simon Glassfe3f6432018-11-06 15:21:26 -0700235 printf("cros-ec communications failure %d\n", ret);
Rajeshwari Birje987b0dd2013-12-26 09:44:17 +0530236 puts("\nPlease reset with Power+Refresh\n\n");
237 panic("Cannot init cros-ec device");
238 return -1;
239 }
Marek Szyprowskibc4a2e32020-01-17 14:02:44 +0100240
241 printf("Boot device: MMC(%u)\n", mmcbootdev);
242 sprintf(mmcbootdev_str, "%u", mmcbootdev);
243 env_set("mmcbootdev", mmcbootdev_str);
244
Rajeshwari Birje987b0dd2013-12-26 09:44:17 +0530245 return 0;
246}
247#endif
248
Piotr Wilczek2c3eed52014-03-07 14:59:45 +0100249#ifdef CONFIG_MISC_INIT_R
250int misc_init_r(void)
251{
Krzysztof Kozlowski36476ee2019-03-06 19:37:51 +0100252 if (IS_ENABLED(CONFIG_BOARD_TYPES) &&
253 !IS_ENABLED(CONFIG_DISPLAY_BOARDINFO_LATE)) {
254 /*
255 * If revision was not set by late display boardinfo,
256 * set it here. At this point regulators should be already
257 * available.
258 */
259 set_board_revision();
260 }
261
Piotr Wilczek2c3eed52014-03-07 14:59:45 +0100262#ifdef CONFIG_ENV_VARS_UBOOT_RUNTIME_CONFIG
263 set_board_info();
264#endif
265#ifdef CONFIG_LCD_MENU
266 keys_init();
267 check_boot_mode();
268#endif
269#ifdef CONFIG_CMD_BMP
270 if (panel_info.logo_on)
271 draw_logo();
272#endif
273 return 0;
274}
275#endif
Joonyoung Shim7a3e8062015-01-15 11:45:56 +0900276
277void reset_misc(void)
278{
279 struct gpio_desc gpio = {};
280 int node;
281
282 node = fdt_node_offset_by_compatible(gd->fdt_blob, 0,
283 "samsung,emmc-reset");
284 if (node < 0)
285 return;
286
Simon Glass1d9af1f2017-05-30 21:47:09 -0600287 gpio_request_by_name_nodev(offset_to_ofnode(node), "reset-gpio", 0,
288 &gpio, GPIOD_IS_OUT);
Joonyoung Shim7a3e8062015-01-15 11:45:56 +0900289
290 if (dm_gpio_is_valid(&gpio)) {
291 /*
292 * Reset eMMC
293 *
294 * FIXME: Need to optimize delay time. Minimum 1usec pulse is
295 * required by 'JEDEC Standard No.84-A441' (eMMC)
296 * document but real delay time is expected to greater
297 * than 1usec.
298 */
299 dm_gpio_set_value(&gpio, 0);
300 mdelay(10);
301 dm_gpio_set_value(&gpio, 1);
302 }
303}
Lukasz Majewski7573b962015-03-03 17:32:03 +0100304
305int board_usb_cleanup(int index, enum usb_init_type init)
306{
Joonyoung Shim95d3a1d2015-05-22 18:14:24 +0200307#ifdef CONFIG_USB_DWC3
308 dwc3_uboot_exit(index);
309#endif
Lukasz Majewski7573b962015-03-03 17:32:03 +0100310 return 0;
311}
Marek Szyprowskibc4a2e32020-01-17 14:02:44 +0100312
313int mmc_get_env_dev(void)
314{
315 return get_boot_mmc_dev();
316}