blob: 49d40244644f56bc5fcbd3c31554de91a3b29631 [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>
Przemyslaw Marczak110aa292015-04-20 20:07:50 +020029#include <i2c.h>
Marek Szyprowskibc4a2e32020-01-17 14:02:44 +010030#include <mmc.h>
31#include <stdio_dev.h>
Lukasz Majewski7573b962015-03-03 17:32:03 +010032#include <usb.h>
Joonyoung Shim95d3a1d2015-05-22 18:14:24 +020033#include <dwc3-uboot.h>
Simon Glassdbd79542020-05-10 11:40:11 -060034#include <linux/delay.h>
Joonyoung Shim95d3a1d2015-05-22 18:14:24 +020035#include <samsung/misc.h>
Thomas Abraham8d84faa2016-04-23 22:18:14 +053036#include <dm/pinctrl.h>
37#include <dm.h>
Rajeshwari Birje987b0dd2013-12-26 09:44:17 +053038
39DECLARE_GLOBAL_DATA_PTR;
40
Jeroen Hofstee5cd82942014-10-08 22:57:28 +020041__weak int exynos_early_init_f(void)
Piotr Wilczek942d0a92014-03-07 14:59:43 +010042{
43 return 0;
44}
Piotr Wilczek942d0a92014-03-07 14:59:43 +010045
Jeroen Hofstee5cd82942014-10-08 22:57:28 +020046__weak int exynos_power_init(void)
Piotr Wilczek942d0a92014-03-07 14:59:43 +010047{
48 return 0;
49}
Piotr Wilczek942d0a92014-03-07 14:59:43 +010050
Marek Szyprowskibc4a2e32020-01-17 14:02:44 +010051/**
52 * get_boot_mmc_dev() - read boot MMC device id from XOM[7:5] pins.
53 */
54static int get_boot_mmc_dev(void)
55{
56 u32 mode = readl(EXYNOS4_OP_MODE) & 0x1C;
57
58 if (mode == 0x04)
59 return 2; /* MMC2: SD */
60
61 /* MMC0: eMMC or unknown */
62 return 0;
63}
64
Rajeshwari Birje987b0dd2013-12-26 09:44:17 +053065#if defined CONFIG_EXYNOS_TMU
66/* Boot Time Thermal Analysis for SoC temperature threshold breach */
67static void boot_temp_check(void)
68{
69 int temp;
70
71 switch (tmu_monitor(&temp)) {
72 case TMU_STATUS_NORMAL:
73 break;
74 case TMU_STATUS_TRIPPED:
75 /*
76 * Status TRIPPED ans WARNING means corresponding threshold
77 * breach
78 */
79 puts("EXYNOS_TMU: TRIPPING! Device power going down ...\n");
80 set_ps_hold_ctrl();
81 hang();
82 break;
83 case TMU_STATUS_WARNING:
84 puts("EXYNOS_TMU: WARNING! Temperature very high\n");
85 break;
86 case TMU_STATUS_INIT:
87 /*
88 * TMU_STATUS_INIT means something is wrong with temperature
89 * sensing and TMU status was changed back from NORMAL to INIT.
90 */
91 puts("EXYNOS_TMU: WARNING! Temperature sensing not done\n");
92 break;
93 default:
94 debug("EXYNOS_TMU: Unknown TMU state\n");
95 }
96}
97#endif
98
99int board_init(void)
100{
101 gd->bd->bi_boot_params = (PHYS_SDRAM_1 + 0x100UL);
102#if defined CONFIG_EXYNOS_TMU
103 if (tmu_init(gd->fdt_blob) != TMU_STATUS_NORMAL) {
104 debug("%s: Failed to init TMU\n", __func__);
105 return -1;
106 }
107 boot_temp_check();
108#endif
Tom Rini5c1e7272022-04-06 10:33:32 -0400109#if CONFIG_VAL(SYS_MEM_TOP_HIDE)
Przemyslaw Marczakc32a04c2015-02-17 14:50:25 +0100110 /* The last few MB of memory can be reserved for secure firmware */
Tom Rini5c1e7272022-04-06 10:33:32 -0400111 ulong size = CONFIG_SYS_MEM_TOP_HIDE;
Rajeshwari Birje987b0dd2013-12-26 09:44:17 +0530112
Przemyslaw Marczakc32a04c2015-02-17 14:50:25 +0100113 gd->ram_size -= size;
114 gd->bd->bi_dram[CONFIG_NR_DRAM_BANKS - 1].size -= size;
115#endif
Rajeshwari Birje987b0dd2013-12-26 09:44:17 +0530116 return exynos_init();
117}
118
119int dram_init(void)
120{
Ɓukasz Majewski33d7a192015-03-04 10:54:48 +0100121 unsigned int i;
Thomas Abraham8d84faa2016-04-23 22:18:14 +0530122 unsigned long addr;
Rajeshwari Birje987b0dd2013-12-26 09:44:17 +0530123
124 for (i = 0; i < CONFIG_NR_DRAM_BANKS; i++) {
125 addr = CONFIG_SYS_SDRAM_BASE + (i * SDRAM_BANK_SIZE);
126 gd->ram_size += get_ram_size((long *)addr, SDRAM_BANK_SIZE);
127 }
128 return 0;
129}
130
Simon Glass2f949c32017-03-31 08:40:32 -0600131int dram_init_banksize(void)
Rajeshwari Birje987b0dd2013-12-26 09:44:17 +0530132{
Ɓukasz Majewski33d7a192015-03-04 10:54:48 +0100133 unsigned int i;
Thomas Abraham8d84faa2016-04-23 22:18:14 +0530134 unsigned long addr, size;
Rajeshwari Birje987b0dd2013-12-26 09:44:17 +0530135
136 for (i = 0; i < CONFIG_NR_DRAM_BANKS; i++) {
137 addr = CONFIG_SYS_SDRAM_BASE + (i * SDRAM_BANK_SIZE);
138 size = get_ram_size((long *)addr, SDRAM_BANK_SIZE);
139
140 gd->bd->bi_dram[i].start = addr;
141 gd->bd->bi_dram[i].size = size;
142 }
Simon Glass2f949c32017-03-31 08:40:32 -0600143
144 return 0;
Rajeshwari Birje987b0dd2013-12-26 09:44:17 +0530145}
146
147static int board_uart_init(void)
148{
Thomas Abraham8d84faa2016-04-23 22:18:14 +0530149#ifndef CONFIG_PINCTRL_EXYNOS
Rajeshwari Birje987b0dd2013-12-26 09:44:17 +0530150 int err, uart_id, ret = 0;
151
152 for (uart_id = PERIPH_ID_UART0; uart_id <= PERIPH_ID_UART3; uart_id++) {
153 err = exynos_pinmux_config(uart_id, PINMUX_FLAG_NONE);
154 if (err) {
155 debug("UART%d not configured\n",
156 (uart_id - PERIPH_ID_UART0));
157 ret |= err;
158 }
159 }
160 return ret;
Thomas Abraham8d84faa2016-04-23 22:18:14 +0530161#else
162 return 0;
163#endif
Rajeshwari Birje987b0dd2013-12-26 09:44:17 +0530164}
165
166#ifdef CONFIG_BOARD_EARLY_INIT_F
167int board_early_init_f(void)
168{
169 int err;
Przemyslaw Marczak4d2a92c2014-09-01 13:50:49 +0200170#ifdef CONFIG_BOARD_TYPES
171 set_board_type();
172#endif
Rajeshwari Birje987b0dd2013-12-26 09:44:17 +0530173 err = board_uart_init();
174 if (err) {
175 debug("UART init failed\n");
176 return err;
177 }
178
179#ifdef CONFIG_SYS_I2C_INIT_BOARD
180 board_i2c_init(gd->fdt_blob);
181#endif
Ajay Kumar11763482014-09-05 16:53:30 +0530182
Piotr Wilczek942d0a92014-03-07 14:59:43 +0100183 return exynos_early_init_f();
Rajeshwari Birje987b0dd2013-12-26 09:44:17 +0530184}
185#endif
186
Simon Glass31339412021-08-08 12:20:27 -0600187#if CONFIG_IS_ENABLED(POWER_LEGACY) || CONFIG_IS_ENABLED(DM_PMIC)
Rajeshwari Birje987b0dd2013-12-26 09:44:17 +0530188int power_init_board(void)
189{
Rajeshwari Birje987b0dd2013-12-26 09:44:17 +0530190 set_ps_hold_ctrl();
191
Piotr Wilczek942d0a92014-03-07 14:59:43 +0100192 return exynos_power_init();
Rajeshwari Birje987b0dd2013-12-26 09:44:17 +0530193}
194#endif
195
Krzysztof Kozlowskic51bd0b2019-03-06 19:37:52 +0100196#if defined(CONFIG_DISPLAY_BOARDINFO) || defined(CONFIG_DISPLAY_BOARDINFO_LATE)
Piotr Wilczek3df7aff2014-03-07 14:59:42 +0100197int checkboard(void)
198{
Simon Glass6ceeff42019-01-11 18:37:07 -0700199 if (IS_ENABLED(CONFIG_BOARD_TYPES)) {
Krzysztof Kozlowski36476ee2019-03-06 19:37:51 +0100200 const char *board_info;
201
202 if (IS_ENABLED(CONFIG_DISPLAY_BOARDINFO_LATE)) {
203 /*
204 * Printing type requires having revision, although
205 * this will succeed only if done late.
206 * Otherwise revision will be set in misc_init_r().
207 */
208 set_board_revision();
209 }
210
211 board_info = get_board_type();
Simon Glass6ceeff42019-01-11 18:37:07 -0700212
213 if (board_info)
214 printf("Type: %s\n", board_info);
215 }
Piotr Wilczek3df7aff2014-03-07 14:59:42 +0100216
Piotr Wilczek3df7aff2014-03-07 14:59:42 +0100217 return 0;
218}
Rajeshwari Birje987b0dd2013-12-26 09:44:17 +0530219#endif
Rajeshwari Birje987b0dd2013-12-26 09:44:17 +0530220
221#ifdef CONFIG_BOARD_LATE_INIT
222int board_late_init(void)
223{
Simon Glassfe3f6432018-11-06 15:21:26 -0700224 struct udevice *dev;
225 int ret;
Marek Szyprowskibc4a2e32020-01-17 14:02:44 +0100226 int mmcbootdev = get_boot_mmc_dev();
227 char mmcbootdev_str[16];
Rajeshwari Birje987b0dd2013-12-26 09:44:17 +0530228
Simon Glassfe3f6432018-11-06 15:21:26 -0700229 ret = uclass_first_device_err(UCLASS_CROS_EC, &dev);
230 if (ret && ret != -ENODEV) {
Rajeshwari Birje987b0dd2013-12-26 09:44:17 +0530231 /* Force console on */
232 gd->flags &= ~GD_FLG_SILENT;
233
Simon Glassfe3f6432018-11-06 15:21:26 -0700234 printf("cros-ec communications failure %d\n", ret);
Rajeshwari Birje987b0dd2013-12-26 09:44:17 +0530235 puts("\nPlease reset with Power+Refresh\n\n");
236 panic("Cannot init cros-ec device");
237 return -1;
238 }
Marek Szyprowskibc4a2e32020-01-17 14:02:44 +0100239
240 printf("Boot device: MMC(%u)\n", mmcbootdev);
241 sprintf(mmcbootdev_str, "%u", mmcbootdev);
242 env_set("mmcbootdev", mmcbootdev_str);
243
Rajeshwari Birje987b0dd2013-12-26 09:44:17 +0530244 return 0;
245}
246#endif
247
Piotr Wilczek2c3eed52014-03-07 14:59:45 +0100248#ifdef CONFIG_MISC_INIT_R
249int misc_init_r(void)
250{
Krzysztof Kozlowski36476ee2019-03-06 19:37:51 +0100251 if (IS_ENABLED(CONFIG_BOARD_TYPES) &&
252 !IS_ENABLED(CONFIG_DISPLAY_BOARDINFO_LATE)) {
253 /*
254 * If revision was not set by late display boardinfo,
255 * set it here. At this point regulators should be already
256 * available.
257 */
258 set_board_revision();
259 }
260
Piotr Wilczek2c3eed52014-03-07 14:59:45 +0100261#ifdef CONFIG_ENV_VARS_UBOOT_RUNTIME_CONFIG
262 set_board_info();
263#endif
Piotr Wilczek2c3eed52014-03-07 14:59:45 +0100264#ifdef CONFIG_CMD_BMP
265 if (panel_info.logo_on)
266 draw_logo();
267#endif
268 return 0;
269}
270#endif
Joonyoung Shim7a3e8062015-01-15 11:45:56 +0900271
272void reset_misc(void)
273{
274 struct gpio_desc gpio = {};
275 int node;
276
277 node = fdt_node_offset_by_compatible(gd->fdt_blob, 0,
278 "samsung,emmc-reset");
279 if (node < 0)
280 return;
281
Simon Glass1d9af1f2017-05-30 21:47:09 -0600282 gpio_request_by_name_nodev(offset_to_ofnode(node), "reset-gpio", 0,
283 &gpio, GPIOD_IS_OUT);
Joonyoung Shim7a3e8062015-01-15 11:45:56 +0900284
285 if (dm_gpio_is_valid(&gpio)) {
286 /*
287 * Reset eMMC
288 *
289 * FIXME: Need to optimize delay time. Minimum 1usec pulse is
290 * required by 'JEDEC Standard No.84-A441' (eMMC)
291 * document but real delay time is expected to greater
292 * than 1usec.
293 */
294 dm_gpio_set_value(&gpio, 0);
295 mdelay(10);
296 dm_gpio_set_value(&gpio, 1);
297 }
298}
Lukasz Majewski7573b962015-03-03 17:32:03 +0100299
300int board_usb_cleanup(int index, enum usb_init_type init)
301{
Joonyoung Shim95d3a1d2015-05-22 18:14:24 +0200302#ifdef CONFIG_USB_DWC3
303 dwc3_uboot_exit(index);
304#endif
Lukasz Majewski7573b962015-03-03 17:32:03 +0100305 return 0;
306}
Marek Szyprowskibc4a2e32020-01-17 14:02:44 +0100307
308int mmc_get_env_dev(void)
309{
310 return get_boot_mmc_dev();
311}