blob: 104d2a6574698ead2103a356ff7d5cd80f52f2f5 [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>
Rajeshwari Birje987b0dd2013-12-26 09:44:17 +053029#include <asm/arch/sromc.h>
Piotr Wilczek2c3eed52014-03-07 14:59:45 +010030#include <lcd.h>
Przemyslaw Marczak110aa292015-04-20 20:07:50 +020031#include <i2c.h>
Marek Szyprowskibc4a2e32020-01-17 14:02:44 +010032#include <mmc.h>
33#include <stdio_dev.h>
Lukasz Majewski7573b962015-03-03 17:32:03 +010034#include <usb.h>
Joonyoung Shim95d3a1d2015-05-22 18:14:24 +020035#include <dwc3-uboot.h>
Simon Glassdbd79542020-05-10 11:40:11 -060036#include <linux/delay.h>
Joonyoung Shim95d3a1d2015-05-22 18:14:24 +020037#include <samsung/misc.h>
Thomas Abraham8d84faa2016-04-23 22:18:14 +053038#include <dm/pinctrl.h>
39#include <dm.h>
Rajeshwari Birje987b0dd2013-12-26 09:44:17 +053040
41DECLARE_GLOBAL_DATA_PTR;
42
Jeroen Hofstee5cd82942014-10-08 22:57:28 +020043__weak int exynos_early_init_f(void)
Piotr Wilczek942d0a92014-03-07 14:59:43 +010044{
45 return 0;
46}
Piotr Wilczek942d0a92014-03-07 14:59:43 +010047
Jeroen Hofstee5cd82942014-10-08 22:57:28 +020048__weak int exynos_power_init(void)
Piotr Wilczek942d0a92014-03-07 14:59:43 +010049{
50 return 0;
51}
Piotr Wilczek942d0a92014-03-07 14:59:43 +010052
Marek Szyprowskibc4a2e32020-01-17 14:02:44 +010053/**
54 * get_boot_mmc_dev() - read boot MMC device id from XOM[7:5] pins.
55 */
56static int get_boot_mmc_dev(void)
57{
58 u32 mode = readl(EXYNOS4_OP_MODE) & 0x1C;
59
60 if (mode == 0x04)
61 return 2; /* MMC2: SD */
62
63 /* MMC0: eMMC or unknown */
64 return 0;
65}
66
Rajeshwari Birje987b0dd2013-12-26 09:44:17 +053067#if defined CONFIG_EXYNOS_TMU
68/* Boot Time Thermal Analysis for SoC temperature threshold breach */
69static void boot_temp_check(void)
70{
71 int temp;
72
73 switch (tmu_monitor(&temp)) {
74 case TMU_STATUS_NORMAL:
75 break;
76 case TMU_STATUS_TRIPPED:
77 /*
78 * Status TRIPPED ans WARNING means corresponding threshold
79 * breach
80 */
81 puts("EXYNOS_TMU: TRIPPING! Device power going down ...\n");
82 set_ps_hold_ctrl();
83 hang();
84 break;
85 case TMU_STATUS_WARNING:
86 puts("EXYNOS_TMU: WARNING! Temperature very high\n");
87 break;
88 case TMU_STATUS_INIT:
89 /*
90 * TMU_STATUS_INIT means something is wrong with temperature
91 * sensing and TMU status was changed back from NORMAL to INIT.
92 */
93 puts("EXYNOS_TMU: WARNING! Temperature sensing not done\n");
94 break;
95 default:
96 debug("EXYNOS_TMU: Unknown TMU state\n");
97 }
98}
99#endif
100
101int board_init(void)
102{
103 gd->bd->bi_boot_params = (PHYS_SDRAM_1 + 0x100UL);
104#if defined CONFIG_EXYNOS_TMU
105 if (tmu_init(gd->fdt_blob) != TMU_STATUS_NORMAL) {
106 debug("%s: Failed to init TMU\n", __func__);
107 return -1;
108 }
109 boot_temp_check();
110#endif
Przemyslaw Marczakc32a04c2015-02-17 14:50:25 +0100111#ifdef CONFIG_TZSW_RESERVED_DRAM_SIZE
112 /* The last few MB of memory can be reserved for secure firmware */
113 ulong size = CONFIG_TZSW_RESERVED_DRAM_SIZE;
Rajeshwari Birje987b0dd2013-12-26 09:44:17 +0530114
Przemyslaw Marczakc32a04c2015-02-17 14:50:25 +0100115 gd->ram_size -= size;
116 gd->bd->bi_dram[CONFIG_NR_DRAM_BANKS - 1].size -= size;
117#endif
Rajeshwari Birje987b0dd2013-12-26 09:44:17 +0530118 return exynos_init();
119}
120
121int dram_init(void)
122{
Ɓukasz Majewski33d7a192015-03-04 10:54:48 +0100123 unsigned int i;
Thomas Abraham8d84faa2016-04-23 22:18:14 +0530124 unsigned long addr;
Rajeshwari Birje987b0dd2013-12-26 09:44:17 +0530125
126 for (i = 0; i < CONFIG_NR_DRAM_BANKS; i++) {
127 addr = CONFIG_SYS_SDRAM_BASE + (i * SDRAM_BANK_SIZE);
128 gd->ram_size += get_ram_size((long *)addr, SDRAM_BANK_SIZE);
129 }
130 return 0;
131}
132
Simon Glass2f949c32017-03-31 08:40:32 -0600133int dram_init_banksize(void)
Rajeshwari Birje987b0dd2013-12-26 09:44:17 +0530134{
Ɓukasz Majewski33d7a192015-03-04 10:54:48 +0100135 unsigned int i;
Thomas Abraham8d84faa2016-04-23 22:18:14 +0530136 unsigned long addr, size;
Rajeshwari Birje987b0dd2013-12-26 09:44:17 +0530137
138 for (i = 0; i < CONFIG_NR_DRAM_BANKS; i++) {
139 addr = CONFIG_SYS_SDRAM_BASE + (i * SDRAM_BANK_SIZE);
140 size = get_ram_size((long *)addr, SDRAM_BANK_SIZE);
141
142 gd->bd->bi_dram[i].start = addr;
143 gd->bd->bi_dram[i].size = size;
144 }
Simon Glass2f949c32017-03-31 08:40:32 -0600145
146 return 0;
Rajeshwari Birje987b0dd2013-12-26 09:44:17 +0530147}
148
149static int board_uart_init(void)
150{
Thomas Abraham8d84faa2016-04-23 22:18:14 +0530151#ifndef CONFIG_PINCTRL_EXYNOS
Rajeshwari Birje987b0dd2013-12-26 09:44:17 +0530152 int err, uart_id, ret = 0;
153
154 for (uart_id = PERIPH_ID_UART0; uart_id <= PERIPH_ID_UART3; uart_id++) {
155 err = exynos_pinmux_config(uart_id, PINMUX_FLAG_NONE);
156 if (err) {
157 debug("UART%d not configured\n",
158 (uart_id - PERIPH_ID_UART0));
159 ret |= err;
160 }
161 }
162 return ret;
Thomas Abraham8d84faa2016-04-23 22:18:14 +0530163#else
164 return 0;
165#endif
Rajeshwari Birje987b0dd2013-12-26 09:44:17 +0530166}
167
168#ifdef CONFIG_BOARD_EARLY_INIT_F
169int board_early_init_f(void)
170{
171 int err;
Przemyslaw Marczak4d2a92c2014-09-01 13:50:49 +0200172#ifdef CONFIG_BOARD_TYPES
173 set_board_type();
174#endif
Rajeshwari Birje987b0dd2013-12-26 09:44:17 +0530175 err = board_uart_init();
176 if (err) {
177 debug("UART init failed\n");
178 return err;
179 }
180
181#ifdef CONFIG_SYS_I2C_INIT_BOARD
182 board_i2c_init(gd->fdt_blob);
183#endif
Ajay Kumar11763482014-09-05 16:53:30 +0530184
Piotr Wilczek942d0a92014-03-07 14:59:43 +0100185 return exynos_early_init_f();
Rajeshwari Birje987b0dd2013-12-26 09:44:17 +0530186}
187#endif
188
Przemyslaw Marczak110aa292015-04-20 20:07:50 +0200189#if defined(CONFIG_POWER) || defined(CONFIG_DM_PMIC)
Rajeshwari Birje987b0dd2013-12-26 09:44:17 +0530190int power_init_board(void)
191{
Rajeshwari Birje987b0dd2013-12-26 09:44:17 +0530192 set_ps_hold_ctrl();
193
Piotr Wilczek942d0a92014-03-07 14:59:43 +0100194 return exynos_power_init();
Rajeshwari Birje987b0dd2013-12-26 09:44:17 +0530195}
196#endif
197
Piotr Wilczek2c3eed52014-03-07 14:59:45 +0100198#ifdef CONFIG_SMC911X
Rajeshwari Birje987b0dd2013-12-26 09:44:17 +0530199static int decode_sromc(const void *blob, struct fdt_sromc *config)
200{
201 int err;
202 int node;
203
204 node = fdtdec_next_compatible(blob, 0, COMPAT_SAMSUNG_EXYNOS5_SROMC);
205 if (node < 0) {
206 debug("Could not find SROMC node\n");
207 return node;
208 }
209
210 config->bank = fdtdec_get_int(blob, node, "bank", 0);
211 config->width = fdtdec_get_int(blob, node, "width", 2);
212
213 err = fdtdec_get_int_array(blob, node, "srom-timing", config->timing,
214 FDT_SROM_TIMING_COUNT);
215 if (err < 0) {
216 debug("Could not decode SROMC configuration Error: %s\n",
217 fdt_strerror(err));
218 return -FDT_ERR_NOTFOUND;
219 }
220 return 0;
221}
Piotr Wilczek2c3eed52014-03-07 14:59:45 +0100222#endif
Rajeshwari Birje987b0dd2013-12-26 09:44:17 +0530223
Masahiro Yamadaf7ed78b2020-06-26 15:13:33 +0900224int board_eth_init(struct bd_info *bis)
Rajeshwari Birje987b0dd2013-12-26 09:44:17 +0530225{
226#ifdef CONFIG_SMC911X
227 u32 smc_bw_conf, smc_bc_conf;
228 struct fdt_sromc config;
229 fdt_addr_t base_addr;
230 int node;
231
232 node = decode_sromc(gd->fdt_blob, &config);
233 if (node < 0) {
234 debug("%s: Could not find sromc configuration\n", __func__);
235 return 0;
236 }
237 node = fdtdec_next_compatible(gd->fdt_blob, node, COMPAT_SMSC_LAN9215);
238 if (node < 0) {
239 debug("%s: Could not find lan9215 configuration\n", __func__);
240 return 0;
241 }
242
243 /* We now have a node, so any problems from now on are errors */
244 base_addr = fdtdec_get_addr(gd->fdt_blob, node, "reg");
245 if (base_addr == FDT_ADDR_T_NONE) {
246 debug("%s: Could not find lan9215 address\n", __func__);
247 return -1;
248 }
249
250 /* Ethernet needs data bus width of 16 bits */
251 if (config.width != 2) {
252 debug("%s: Unsupported bus width %d\n", __func__,
253 config.width);
254 return -1;
255 }
256 smc_bw_conf = SROMC_DATA16_WIDTH(config.bank)
257 | SROMC_BYTE_ENABLE(config.bank);
258
259 smc_bc_conf = SROMC_BC_TACS(config.timing[FDT_SROM_TACS]) |
260 SROMC_BC_TCOS(config.timing[FDT_SROM_TCOS]) |
261 SROMC_BC_TACC(config.timing[FDT_SROM_TACC]) |
262 SROMC_BC_TCOH(config.timing[FDT_SROM_TCOH]) |
263 SROMC_BC_TAH(config.timing[FDT_SROM_TAH]) |
264 SROMC_BC_TACP(config.timing[FDT_SROM_TACP]) |
265 SROMC_BC_PMC(config.timing[FDT_SROM_PMC]);
266
267 /* Select and configure the SROMC bank */
268 exynos_pinmux_config(PERIPH_ID_SROMC, config.bank);
269 s5p_config_sromc(config.bank, smc_bw_conf, smc_bc_conf);
270 return smc911x_initialize(0, base_addr);
271#endif
272 return 0;
273}
274
Krzysztof Kozlowskic51bd0b2019-03-06 19:37:52 +0100275#if defined(CONFIG_DISPLAY_BOARDINFO) || defined(CONFIG_DISPLAY_BOARDINFO_LATE)
Piotr Wilczek3df7aff2014-03-07 14:59:42 +0100276int checkboard(void)
277{
Simon Glass6ceeff42019-01-11 18:37:07 -0700278 if (IS_ENABLED(CONFIG_BOARD_TYPES)) {
Krzysztof Kozlowski36476ee2019-03-06 19:37:51 +0100279 const char *board_info;
280
281 if (IS_ENABLED(CONFIG_DISPLAY_BOARDINFO_LATE)) {
282 /*
283 * Printing type requires having revision, although
284 * this will succeed only if done late.
285 * Otherwise revision will be set in misc_init_r().
286 */
287 set_board_revision();
288 }
289
290 board_info = get_board_type();
Simon Glass6ceeff42019-01-11 18:37:07 -0700291
292 if (board_info)
293 printf("Type: %s\n", board_info);
294 }
Piotr Wilczek3df7aff2014-03-07 14:59:42 +0100295
Piotr Wilczek3df7aff2014-03-07 14:59:42 +0100296 return 0;
297}
Rajeshwari Birje987b0dd2013-12-26 09:44:17 +0530298#endif
Rajeshwari Birje987b0dd2013-12-26 09:44:17 +0530299
300#ifdef CONFIG_BOARD_LATE_INIT
301int board_late_init(void)
302{
Simon Glassfe3f6432018-11-06 15:21:26 -0700303 struct udevice *dev;
304 int ret;
Marek Szyprowskibc4a2e32020-01-17 14:02:44 +0100305 int mmcbootdev = get_boot_mmc_dev();
306 char mmcbootdev_str[16];
Rajeshwari Birje987b0dd2013-12-26 09:44:17 +0530307
Simon Glassfe3f6432018-11-06 15:21:26 -0700308 ret = uclass_first_device_err(UCLASS_CROS_EC, &dev);
309 if (ret && ret != -ENODEV) {
Rajeshwari Birje987b0dd2013-12-26 09:44:17 +0530310 /* Force console on */
311 gd->flags &= ~GD_FLG_SILENT;
312
Simon Glassfe3f6432018-11-06 15:21:26 -0700313 printf("cros-ec communications failure %d\n", ret);
Rajeshwari Birje987b0dd2013-12-26 09:44:17 +0530314 puts("\nPlease reset with Power+Refresh\n\n");
315 panic("Cannot init cros-ec device");
316 return -1;
317 }
Marek Szyprowskibc4a2e32020-01-17 14:02:44 +0100318
319 printf("Boot device: MMC(%u)\n", mmcbootdev);
320 sprintf(mmcbootdev_str, "%u", mmcbootdev);
321 env_set("mmcbootdev", mmcbootdev_str);
322
Rajeshwari Birje987b0dd2013-12-26 09:44:17 +0530323 return 0;
324}
325#endif
326
Piotr Wilczek2c3eed52014-03-07 14:59:45 +0100327#ifdef CONFIG_MISC_INIT_R
328int misc_init_r(void)
329{
Krzysztof Kozlowski36476ee2019-03-06 19:37:51 +0100330 if (IS_ENABLED(CONFIG_BOARD_TYPES) &&
331 !IS_ENABLED(CONFIG_DISPLAY_BOARDINFO_LATE)) {
332 /*
333 * If revision was not set by late display boardinfo,
334 * set it here. At this point regulators should be already
335 * available.
336 */
337 set_board_revision();
338 }
339
Piotr Wilczek2c3eed52014-03-07 14:59:45 +0100340#ifdef CONFIG_ENV_VARS_UBOOT_RUNTIME_CONFIG
341 set_board_info();
342#endif
343#ifdef CONFIG_LCD_MENU
344 keys_init();
345 check_boot_mode();
346#endif
347#ifdef CONFIG_CMD_BMP
348 if (panel_info.logo_on)
349 draw_logo();
350#endif
351 return 0;
352}
353#endif
Joonyoung Shim7a3e8062015-01-15 11:45:56 +0900354
355void reset_misc(void)
356{
357 struct gpio_desc gpio = {};
358 int node;
359
360 node = fdt_node_offset_by_compatible(gd->fdt_blob, 0,
361 "samsung,emmc-reset");
362 if (node < 0)
363 return;
364
Simon Glass1d9af1f2017-05-30 21:47:09 -0600365 gpio_request_by_name_nodev(offset_to_ofnode(node), "reset-gpio", 0,
366 &gpio, GPIOD_IS_OUT);
Joonyoung Shim7a3e8062015-01-15 11:45:56 +0900367
368 if (dm_gpio_is_valid(&gpio)) {
369 /*
370 * Reset eMMC
371 *
372 * FIXME: Need to optimize delay time. Minimum 1usec pulse is
373 * required by 'JEDEC Standard No.84-A441' (eMMC)
374 * document but real delay time is expected to greater
375 * than 1usec.
376 */
377 dm_gpio_set_value(&gpio, 0);
378 mdelay(10);
379 dm_gpio_set_value(&gpio, 1);
380 }
381}
Lukasz Majewski7573b962015-03-03 17:32:03 +0100382
383int board_usb_cleanup(int index, enum usb_init_type init)
384{
Joonyoung Shim95d3a1d2015-05-22 18:14:24 +0200385#ifdef CONFIG_USB_DWC3
386 dwc3_uboot_exit(index);
387#endif
Lukasz Majewski7573b962015-03-03 17:32:03 +0100388 return 0;
389}
Marek Szyprowskibc4a2e32020-01-17 14:02:44 +0100390
391int mmc_get_env_dev(void)
392{
393 return get_boot_mmc_dev();
394}