blob: 948007c4a830f130faf8dea937902e86b7e6e08d [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>
9#include <errno.h>
10#include <fdtdec.h>
Simon Glassf11478f2019-12-28 10:45:07 -070011#include <hang.h>
Simon Glassa7b51302019-11-14 12:57:46 -070012#include <init.h>
Simon Glass274e0b02020-05-10 11:39:56 -060013#include <net.h>
Rajeshwari Birje987b0dd2013-12-26 09:44:17 +053014#include <spi.h>
15#include <tmu.h>
16#include <netdev.h>
17#include <asm/io.h>
Simon Glass37f11622014-10-20 19:48:37 -060018#include <asm/gpio.h>
Rajeshwari Birje987b0dd2013-12-26 09:44:17 +053019#include <asm/arch/board.h>
20#include <asm/arch/cpu.h>
21#include <asm/arch/dwmmc.h>
Rajeshwari Birje987b0dd2013-12-26 09:44:17 +053022#include <asm/arch/mmc.h>
23#include <asm/arch/pinmux.h>
24#include <asm/arch/power.h>
Ajay Kumar11763482014-09-05 16:53:30 +053025#include <asm/arch/system.h>
Rajeshwari Birje987b0dd2013-12-26 09:44:17 +053026#include <asm/arch/sromc.h>
Piotr Wilczek2c3eed52014-03-07 14:59:45 +010027#include <lcd.h>
Przemyslaw Marczak110aa292015-04-20 20:07:50 +020028#include <i2c.h>
Marek Szyprowskibc4a2e32020-01-17 14:02:44 +010029#include <mmc.h>
30#include <stdio_dev.h>
Lukasz Majewski7573b962015-03-03 17:32:03 +010031#include <usb.h>
Joonyoung Shim95d3a1d2015-05-22 18:14:24 +020032#include <dwc3-uboot.h>
33#include <samsung/misc.h>
Thomas Abraham8d84faa2016-04-23 22:18:14 +053034#include <dm/pinctrl.h>
35#include <dm.h>
Rajeshwari Birje987b0dd2013-12-26 09:44:17 +053036
37DECLARE_GLOBAL_DATA_PTR;
38
Jeroen Hofstee5cd82942014-10-08 22:57:28 +020039__weak int exynos_early_init_f(void)
Piotr Wilczek942d0a92014-03-07 14:59:43 +010040{
41 return 0;
42}
Piotr Wilczek942d0a92014-03-07 14:59:43 +010043
Jeroen Hofstee5cd82942014-10-08 22:57:28 +020044__weak int exynos_power_init(void)
Piotr Wilczek942d0a92014-03-07 14:59:43 +010045{
46 return 0;
47}
Piotr Wilczek942d0a92014-03-07 14:59:43 +010048
Marek Szyprowskibc4a2e32020-01-17 14:02:44 +010049/**
50 * get_boot_mmc_dev() - read boot MMC device id from XOM[7:5] pins.
51 */
52static int get_boot_mmc_dev(void)
53{
54 u32 mode = readl(EXYNOS4_OP_MODE) & 0x1C;
55
56 if (mode == 0x04)
57 return 2; /* MMC2: SD */
58
59 /* MMC0: eMMC or unknown */
60 return 0;
61}
62
Rajeshwari Birje987b0dd2013-12-26 09:44:17 +053063#if defined CONFIG_EXYNOS_TMU
64/* Boot Time Thermal Analysis for SoC temperature threshold breach */
65static void boot_temp_check(void)
66{
67 int temp;
68
69 switch (tmu_monitor(&temp)) {
70 case TMU_STATUS_NORMAL:
71 break;
72 case TMU_STATUS_TRIPPED:
73 /*
74 * Status TRIPPED ans WARNING means corresponding threshold
75 * breach
76 */
77 puts("EXYNOS_TMU: TRIPPING! Device power going down ...\n");
78 set_ps_hold_ctrl();
79 hang();
80 break;
81 case TMU_STATUS_WARNING:
82 puts("EXYNOS_TMU: WARNING! Temperature very high\n");
83 break;
84 case TMU_STATUS_INIT:
85 /*
86 * TMU_STATUS_INIT means something is wrong with temperature
87 * sensing and TMU status was changed back from NORMAL to INIT.
88 */
89 puts("EXYNOS_TMU: WARNING! Temperature sensing not done\n");
90 break;
91 default:
92 debug("EXYNOS_TMU: Unknown TMU state\n");
93 }
94}
95#endif
96
97int board_init(void)
98{
99 gd->bd->bi_boot_params = (PHYS_SDRAM_1 + 0x100UL);
100#if defined CONFIG_EXYNOS_TMU
101 if (tmu_init(gd->fdt_blob) != TMU_STATUS_NORMAL) {
102 debug("%s: Failed to init TMU\n", __func__);
103 return -1;
104 }
105 boot_temp_check();
106#endif
Przemyslaw Marczakc32a04c2015-02-17 14:50:25 +0100107#ifdef CONFIG_TZSW_RESERVED_DRAM_SIZE
108 /* The last few MB of memory can be reserved for secure firmware */
109 ulong size = CONFIG_TZSW_RESERVED_DRAM_SIZE;
Rajeshwari Birje987b0dd2013-12-26 09:44:17 +0530110
Przemyslaw Marczakc32a04c2015-02-17 14:50:25 +0100111 gd->ram_size -= size;
112 gd->bd->bi_dram[CONFIG_NR_DRAM_BANKS - 1].size -= size;
113#endif
Rajeshwari Birje987b0dd2013-12-26 09:44:17 +0530114 return exynos_init();
115}
116
117int dram_init(void)
118{
Łukasz Majewski33d7a192015-03-04 10:54:48 +0100119 unsigned int i;
Thomas Abraham8d84faa2016-04-23 22:18:14 +0530120 unsigned long addr;
Rajeshwari Birje987b0dd2013-12-26 09:44:17 +0530121
122 for (i = 0; i < CONFIG_NR_DRAM_BANKS; i++) {
123 addr = CONFIG_SYS_SDRAM_BASE + (i * SDRAM_BANK_SIZE);
124 gd->ram_size += get_ram_size((long *)addr, SDRAM_BANK_SIZE);
125 }
126 return 0;
127}
128
Simon Glass2f949c32017-03-31 08:40:32 -0600129int dram_init_banksize(void)
Rajeshwari Birje987b0dd2013-12-26 09:44:17 +0530130{
Łukasz Majewski33d7a192015-03-04 10:54:48 +0100131 unsigned int i;
Thomas Abraham8d84faa2016-04-23 22:18:14 +0530132 unsigned long addr, size;
Rajeshwari Birje987b0dd2013-12-26 09:44:17 +0530133
134 for (i = 0; i < CONFIG_NR_DRAM_BANKS; i++) {
135 addr = CONFIG_SYS_SDRAM_BASE + (i * SDRAM_BANK_SIZE);
136 size = get_ram_size((long *)addr, SDRAM_BANK_SIZE);
137
138 gd->bd->bi_dram[i].start = addr;
139 gd->bd->bi_dram[i].size = size;
140 }
Simon Glass2f949c32017-03-31 08:40:32 -0600141
142 return 0;
Rajeshwari Birje987b0dd2013-12-26 09:44:17 +0530143}
144
145static int board_uart_init(void)
146{
Thomas Abraham8d84faa2016-04-23 22:18:14 +0530147#ifndef CONFIG_PINCTRL_EXYNOS
Rajeshwari Birje987b0dd2013-12-26 09:44:17 +0530148 int err, uart_id, ret = 0;
149
150 for (uart_id = PERIPH_ID_UART0; uart_id <= PERIPH_ID_UART3; uart_id++) {
151 err = exynos_pinmux_config(uart_id, PINMUX_FLAG_NONE);
152 if (err) {
153 debug("UART%d not configured\n",
154 (uart_id - PERIPH_ID_UART0));
155 ret |= err;
156 }
157 }
158 return ret;
Thomas Abraham8d84faa2016-04-23 22:18:14 +0530159#else
160 return 0;
161#endif
Rajeshwari Birje987b0dd2013-12-26 09:44:17 +0530162}
163
164#ifdef CONFIG_BOARD_EARLY_INIT_F
165int board_early_init_f(void)
166{
167 int err;
Przemyslaw Marczak4d2a92c2014-09-01 13:50:49 +0200168#ifdef CONFIG_BOARD_TYPES
169 set_board_type();
170#endif
Rajeshwari Birje987b0dd2013-12-26 09:44:17 +0530171 err = board_uart_init();
172 if (err) {
173 debug("UART init failed\n");
174 return err;
175 }
176
177#ifdef CONFIG_SYS_I2C_INIT_BOARD
178 board_i2c_init(gd->fdt_blob);
179#endif
Ajay Kumar11763482014-09-05 16:53:30 +0530180
Piotr Wilczek942d0a92014-03-07 14:59:43 +0100181 return exynos_early_init_f();
Rajeshwari Birje987b0dd2013-12-26 09:44:17 +0530182}
183#endif
184
Przemyslaw Marczak110aa292015-04-20 20:07:50 +0200185#if defined(CONFIG_POWER) || defined(CONFIG_DM_PMIC)
Rajeshwari Birje987b0dd2013-12-26 09:44:17 +0530186int power_init_board(void)
187{
Rajeshwari Birje987b0dd2013-12-26 09:44:17 +0530188 set_ps_hold_ctrl();
189
Piotr Wilczek942d0a92014-03-07 14:59:43 +0100190 return exynos_power_init();
Rajeshwari Birje987b0dd2013-12-26 09:44:17 +0530191}
192#endif
193
Piotr Wilczek2c3eed52014-03-07 14:59:45 +0100194#ifdef CONFIG_SMC911X
Rajeshwari Birje987b0dd2013-12-26 09:44:17 +0530195static int decode_sromc(const void *blob, struct fdt_sromc *config)
196{
197 int err;
198 int node;
199
200 node = fdtdec_next_compatible(blob, 0, COMPAT_SAMSUNG_EXYNOS5_SROMC);
201 if (node < 0) {
202 debug("Could not find SROMC node\n");
203 return node;
204 }
205
206 config->bank = fdtdec_get_int(blob, node, "bank", 0);
207 config->width = fdtdec_get_int(blob, node, "width", 2);
208
209 err = fdtdec_get_int_array(blob, node, "srom-timing", config->timing,
210 FDT_SROM_TIMING_COUNT);
211 if (err < 0) {
212 debug("Could not decode SROMC configuration Error: %s\n",
213 fdt_strerror(err));
214 return -FDT_ERR_NOTFOUND;
215 }
216 return 0;
217}
Piotr Wilczek2c3eed52014-03-07 14:59:45 +0100218#endif
Rajeshwari Birje987b0dd2013-12-26 09:44:17 +0530219
220int board_eth_init(bd_t *bis)
221{
222#ifdef CONFIG_SMC911X
223 u32 smc_bw_conf, smc_bc_conf;
224 struct fdt_sromc config;
225 fdt_addr_t base_addr;
226 int node;
227
228 node = decode_sromc(gd->fdt_blob, &config);
229 if (node < 0) {
230 debug("%s: Could not find sromc configuration\n", __func__);
231 return 0;
232 }
233 node = fdtdec_next_compatible(gd->fdt_blob, node, COMPAT_SMSC_LAN9215);
234 if (node < 0) {
235 debug("%s: Could not find lan9215 configuration\n", __func__);
236 return 0;
237 }
238
239 /* We now have a node, so any problems from now on are errors */
240 base_addr = fdtdec_get_addr(gd->fdt_blob, node, "reg");
241 if (base_addr == FDT_ADDR_T_NONE) {
242 debug("%s: Could not find lan9215 address\n", __func__);
243 return -1;
244 }
245
246 /* Ethernet needs data bus width of 16 bits */
247 if (config.width != 2) {
248 debug("%s: Unsupported bus width %d\n", __func__,
249 config.width);
250 return -1;
251 }
252 smc_bw_conf = SROMC_DATA16_WIDTH(config.bank)
253 | SROMC_BYTE_ENABLE(config.bank);
254
255 smc_bc_conf = SROMC_BC_TACS(config.timing[FDT_SROM_TACS]) |
256 SROMC_BC_TCOS(config.timing[FDT_SROM_TCOS]) |
257 SROMC_BC_TACC(config.timing[FDT_SROM_TACC]) |
258 SROMC_BC_TCOH(config.timing[FDT_SROM_TCOH]) |
259 SROMC_BC_TAH(config.timing[FDT_SROM_TAH]) |
260 SROMC_BC_TACP(config.timing[FDT_SROM_TACP]) |
261 SROMC_BC_PMC(config.timing[FDT_SROM_PMC]);
262
263 /* Select and configure the SROMC bank */
264 exynos_pinmux_config(PERIPH_ID_SROMC, config.bank);
265 s5p_config_sromc(config.bank, smc_bw_conf, smc_bc_conf);
266 return smc911x_initialize(0, base_addr);
267#endif
268 return 0;
269}
270
Krzysztof Kozlowskic51bd0b2019-03-06 19:37:52 +0100271#if defined(CONFIG_DISPLAY_BOARDINFO) || defined(CONFIG_DISPLAY_BOARDINFO_LATE)
Piotr Wilczek3df7aff2014-03-07 14:59:42 +0100272int checkboard(void)
273{
Simon Glass6ceeff42019-01-11 18:37:07 -0700274 if (IS_ENABLED(CONFIG_BOARD_TYPES)) {
Krzysztof Kozlowski36476ee2019-03-06 19:37:51 +0100275 const char *board_info;
276
277 if (IS_ENABLED(CONFIG_DISPLAY_BOARDINFO_LATE)) {
278 /*
279 * Printing type requires having revision, although
280 * this will succeed only if done late.
281 * Otherwise revision will be set in misc_init_r().
282 */
283 set_board_revision();
284 }
285
286 board_info = get_board_type();
Simon Glass6ceeff42019-01-11 18:37:07 -0700287
288 if (board_info)
289 printf("Type: %s\n", board_info);
290 }
Piotr Wilczek3df7aff2014-03-07 14:59:42 +0100291
Piotr Wilczek3df7aff2014-03-07 14:59:42 +0100292 return 0;
293}
Rajeshwari Birje987b0dd2013-12-26 09:44:17 +0530294#endif
Rajeshwari Birje987b0dd2013-12-26 09:44:17 +0530295
296#ifdef CONFIG_BOARD_LATE_INIT
297int board_late_init(void)
298{
Simon Glassfe3f6432018-11-06 15:21:26 -0700299 struct udevice *dev;
300 int ret;
Marek Szyprowskibc4a2e32020-01-17 14:02:44 +0100301 int mmcbootdev = get_boot_mmc_dev();
302 char mmcbootdev_str[16];
Rajeshwari Birje987b0dd2013-12-26 09:44:17 +0530303
Simon Glassfe3f6432018-11-06 15:21:26 -0700304 stdio_print_current_devices();
305 ret = uclass_first_device_err(UCLASS_CROS_EC, &dev);
306 if (ret && ret != -ENODEV) {
Rajeshwari Birje987b0dd2013-12-26 09:44:17 +0530307 /* Force console on */
308 gd->flags &= ~GD_FLG_SILENT;
309
Simon Glassfe3f6432018-11-06 15:21:26 -0700310 printf("cros-ec communications failure %d\n", ret);
Rajeshwari Birje987b0dd2013-12-26 09:44:17 +0530311 puts("\nPlease reset with Power+Refresh\n\n");
312 panic("Cannot init cros-ec device");
313 return -1;
314 }
Marek Szyprowskibc4a2e32020-01-17 14:02:44 +0100315
316 printf("Boot device: MMC(%u)\n", mmcbootdev);
317 sprintf(mmcbootdev_str, "%u", mmcbootdev);
318 env_set("mmcbootdev", mmcbootdev_str);
319
Rajeshwari Birje987b0dd2013-12-26 09:44:17 +0530320 return 0;
321}
322#endif
323
Piotr Wilczek2c3eed52014-03-07 14:59:45 +0100324#ifdef CONFIG_MISC_INIT_R
325int misc_init_r(void)
326{
Krzysztof Kozlowski36476ee2019-03-06 19:37:51 +0100327 if (IS_ENABLED(CONFIG_BOARD_TYPES) &&
328 !IS_ENABLED(CONFIG_DISPLAY_BOARDINFO_LATE)) {
329 /*
330 * If revision was not set by late display boardinfo,
331 * set it here. At this point regulators should be already
332 * available.
333 */
334 set_board_revision();
335 }
336
Piotr Wilczek2c3eed52014-03-07 14:59:45 +0100337#ifdef CONFIG_ENV_VARS_UBOOT_RUNTIME_CONFIG
338 set_board_info();
339#endif
340#ifdef CONFIG_LCD_MENU
341 keys_init();
342 check_boot_mode();
343#endif
344#ifdef CONFIG_CMD_BMP
345 if (panel_info.logo_on)
346 draw_logo();
347#endif
348 return 0;
349}
350#endif
Joonyoung Shim7a3e8062015-01-15 11:45:56 +0900351
352void reset_misc(void)
353{
354 struct gpio_desc gpio = {};
355 int node;
356
357 node = fdt_node_offset_by_compatible(gd->fdt_blob, 0,
358 "samsung,emmc-reset");
359 if (node < 0)
360 return;
361
Simon Glass1d9af1f2017-05-30 21:47:09 -0600362 gpio_request_by_name_nodev(offset_to_ofnode(node), "reset-gpio", 0,
363 &gpio, GPIOD_IS_OUT);
Joonyoung Shim7a3e8062015-01-15 11:45:56 +0900364
365 if (dm_gpio_is_valid(&gpio)) {
366 /*
367 * Reset eMMC
368 *
369 * FIXME: Need to optimize delay time. Minimum 1usec pulse is
370 * required by 'JEDEC Standard No.84-A441' (eMMC)
371 * document but real delay time is expected to greater
372 * than 1usec.
373 */
374 dm_gpio_set_value(&gpio, 0);
375 mdelay(10);
376 dm_gpio_set_value(&gpio, 1);
377 }
378}
Lukasz Majewski7573b962015-03-03 17:32:03 +0100379
380int board_usb_cleanup(int index, enum usb_init_type init)
381{
Joonyoung Shim95d3a1d2015-05-22 18:14:24 +0200382#ifdef CONFIG_USB_DWC3
383 dwc3_uboot_exit(index);
384#endif
Lukasz Majewski7573b962015-03-03 17:32:03 +0100385 return 0;
386}
Marek Szyprowskibc4a2e32020-01-17 14:02:44 +0100387
388int mmc_get_env_dev(void)
389{
390 return get_boot_mmc_dev();
391}