blob: f0d69d4a48f0472e705f964b2a4522b31e879c95 [file] [log] [blame]
Przemyslaw Marczak679549d2014-01-22 11:24:12 +01001/*
2 * Copyright (C) 2013 Samsung Electronics
3 * Przemyslaw Marczak <p.marczak@samsung.com>
4 *
5 * SPDX-License-Identifier: GPL-2.0+
6 */
7
8#include <common.h>
9#include <lcd.h>
10#include <libtizen.h>
11#include <samsung/misc.h>
Przemyslaw Marczak9d29a682014-01-22 11:24:17 +010012#include <errno.h>
13#include <version.h>
Przemyslaw Marczak1d07c102014-09-01 13:50:46 +020014#include <malloc.h>
Alexey Brodkin1ace4022014-02-26 17:47:58 +040015#include <linux/sizes.h>
Przemyslaw Marczak9d29a682014-01-22 11:24:17 +010016#include <asm/arch/cpu.h>
Przemyslaw Marczak9d29a682014-01-22 11:24:17 +010017#include <asm/gpio.h>
18#include <linux/input.h>
Przemyslaw Marczakca2b9332015-05-13 13:38:25 +020019#include <dm.h>
Przemyslaw Marczak9d29a682014-01-22 11:24:17 +010020#include <power/pmic.h>
21#include <mmc.h>
22
23DECLARE_GLOBAL_DATA_PTR;
24
Przemyslaw Marczak1d07c102014-09-01 13:50:46 +020025#ifdef CONFIG_SET_DFU_ALT_INFO
Przemyslaw Marczak899a5282015-02-17 12:24:11 +010026void set_dfu_alt_info(char *interface, char *devstr)
Przemyslaw Marczak1d07c102014-09-01 13:50:46 +020027{
28 size_t buf_size = CONFIG_SET_DFU_ALT_BUF_LEN;
29 ALLOC_CACHE_ALIGN_BUFFER(char, buf, buf_size);
30 char *alt_info = "Settings not found!";
31 char *status = "error!\n";
32 char *alt_setting;
33 char *alt_sep;
34 int offset = 0;
35
36 puts("DFU alt info setting: ");
37
Przemyslaw Marczak899a5282015-02-17 12:24:11 +010038 alt_setting = get_dfu_alt_boot(interface, devstr);
Przemyslaw Marczak1d07c102014-09-01 13:50:46 +020039 if (alt_setting) {
40 setenv("dfu_alt_boot", alt_setting);
41 offset = snprintf(buf, buf_size, "%s", alt_setting);
42 }
43
Przemyslaw Marczak899a5282015-02-17 12:24:11 +010044 alt_setting = get_dfu_alt_system(interface, devstr);
Przemyslaw Marczak1d07c102014-09-01 13:50:46 +020045 if (alt_setting) {
46 if (offset)
47 alt_sep = ";";
48 else
49 alt_sep = "";
50
51 offset += snprintf(buf + offset, buf_size - offset,
52 "%s%s", alt_sep, alt_setting);
53 }
54
55 if (offset) {
56 alt_info = buf;
57 status = "done\n";
58 }
59
60 setenv("dfu_alt_info", alt_info);
61 puts(status);
62}
63#endif
64
Piotr Wilczekeee2fab2014-01-22 15:54:32 +010065#ifdef CONFIG_ENV_VARS_UBOOT_RUNTIME_CONFIG
66void set_board_info(void)
67{
68 char info[64];
69
Przemyslaw Marczak0dc579f2014-09-01 13:50:42 +020070 snprintf(info, ARRAY_SIZE(info), "%u.%u", (s5p_cpu_rev & 0xf0) >> 4,
71 s5p_cpu_rev & 0xf);
Piotr Wilczekeee2fab2014-01-22 15:54:32 +010072 setenv("soc_rev", info);
73
74 snprintf(info, ARRAY_SIZE(info), "%x", s5p_cpu_id);
75 setenv("soc_id", info);
76
77#ifdef CONFIG_REVISION_TAG
78 snprintf(info, ARRAY_SIZE(info), "%x", get_board_rev());
79 setenv("board_rev", info);
80#endif
81#ifdef CONFIG_OF_LIBFDT
Przemyslaw Marczakc9c36bf2014-09-01 13:50:50 +020082 const char *bdtype = "";
83 const char *bdname = CONFIG_SYS_BOARD;
84
85#ifdef CONFIG_BOARD_TYPES
86 bdtype = get_board_type();
87 sprintf(info, "%s%s", bdname, bdtype);
88 setenv("boardname", info);
89#endif
90 snprintf(info, ARRAY_SIZE(info), "%s%x-%s%s.dtb",
91 CONFIG_SYS_SOC, s5p_cpu_id, bdname, bdtype);
Piotr Wilczekeee2fab2014-01-22 15:54:32 +010092 setenv("fdtfile", info);
93#endif
94}
95#endif /* CONFIG_ENV_VARS_UBOOT_RUNTIME_CONFIG */
96
Przemyslaw Marczak9d29a682014-01-22 11:24:17 +010097#ifdef CONFIG_LCD_MENU
98static int power_key_pressed(u32 reg)
99{
100 struct pmic *pmic;
101 u32 status;
102 u32 mask;
103
104 pmic = pmic_get(KEY_PWR_PMIC_NAME);
105 if (!pmic) {
106 printf("%s: Not found\n", KEY_PWR_PMIC_NAME);
107 return 0;
108 }
109
110 if (pmic_probe(pmic))
111 return 0;
112
113 if (reg == KEY_PWR_STATUS_REG)
114 mask = KEY_PWR_STATUS_MASK;
115 else
116 mask = KEY_PWR_INTERRUPT_MASK;
117
118 if (pmic_reg_read(pmic, reg, &status))
119 return 0;
120
121 return !!(status & mask);
122}
123
124static int key_pressed(int key)
125{
126 int value;
127
128 switch (key) {
129 case KEY_POWER:
130 value = power_key_pressed(KEY_PWR_INTERRUPT_REG);
131 break;
132 case KEY_VOLUMEUP:
133 value = !gpio_get_value(KEY_VOL_UP_GPIO);
134 break;
135 case KEY_VOLUMEDOWN:
136 value = !gpio_get_value(KEY_VOL_DOWN_GPIO);
137 break;
138 default:
139 value = 0;
140 break;
141 }
142
143 return value;
144}
145
146static int check_keys(void)
147{
148 int keys = 0;
149
150 if (key_pressed(KEY_POWER))
151 keys += KEY_POWER;
152 if (key_pressed(KEY_VOLUMEUP))
153 keys += KEY_VOLUMEUP;
154 if (key_pressed(KEY_VOLUMEDOWN))
155 keys += KEY_VOLUMEDOWN;
156
157 return keys;
158}
159
160/*
161 * 0 BOOT_MODE_INFO
162 * 1 BOOT_MODE_THOR
163 * 2 BOOT_MODE_UMS
164 * 3 BOOT_MODE_DFU
165 * 4 BOOT_MODE_EXIT
166 */
167static char *
Przemyslaw Marczake6bfe792014-04-30 13:28:06 +0200168mode_name[BOOT_MODE_EXIT + 1][2] = {
169 {"DEVICE", ""},
170 {"THOR", "thor"},
171 {"UMS", "ums"},
172 {"DFU", "dfu"},
Przemyslaw Marczak5c7b8a32014-04-30 13:28:07 +0200173 {"GPT", "gpt"},
Inha Song0954dd62014-04-30 13:28:08 +0200174 {"ENV", "env"},
Przemyslaw Marczake6bfe792014-04-30 13:28:06 +0200175 {"EXIT", ""},
Przemyslaw Marczak9d29a682014-01-22 11:24:17 +0100176};
177
178static char *
179mode_info[BOOT_MODE_EXIT + 1] = {
180 "info",
181 "downloader",
182 "mass storage",
183 "firmware update",
Przemyslaw Marczak5c7b8a32014-04-30 13:28:07 +0200184 "restore",
Inha Song0954dd62014-04-30 13:28:08 +0200185 "default",
Przemyslaw Marczak9d29a682014-01-22 11:24:17 +0100186 "and run normal boot"
187};
188
Przemyslaw Marczak9d29a682014-01-22 11:24:17 +0100189static char *
Przemyslaw Marczake6bfe792014-04-30 13:28:06 +0200190mode_cmd[BOOT_MODE_EXIT + 1] = {
191 "",
192 "thor 0 mmc 0",
193 "ums 0 mmc 0",
194 "dfu 0 mmc 0",
Przemyslaw Marczak5c7b8a32014-04-30 13:28:07 +0200195 "gpt write mmc 0 $partitions",
Inha Song0954dd62014-04-30 13:28:08 +0200196 "env default -a; saveenv",
Przemyslaw Marczake6bfe792014-04-30 13:28:06 +0200197 "",
Przemyslaw Marczak9d29a682014-01-22 11:24:17 +0100198};
199
200static void display_board_info(void)
201{
202#ifdef CONFIG_GENERIC_MMC
203 struct mmc *mmc = find_mmc_device(0);
204#endif
205 vidinfo_t *vid = &panel_info;
206
207 lcd_position_cursor(4, 4);
208
209 lcd_printf("%s\n\t", U_BOOT_VERSION);
210 lcd_puts("\n\t\tBoard Info:\n");
211#ifdef CONFIG_SYS_BOARD
212 lcd_printf("\tBoard name: %s\n", CONFIG_SYS_BOARD);
213#endif
214#ifdef CONFIG_REVISION_TAG
215 lcd_printf("\tBoard rev: %u\n", get_board_rev());
216#endif
217 lcd_printf("\tDRAM banks: %u\n", CONFIG_NR_DRAM_BANKS);
218 lcd_printf("\tDRAM size: %u MB\n", gd->ram_size / SZ_1M);
219
220#ifdef CONFIG_GENERIC_MMC
221 if (mmc) {
222 if (!mmc->capacity)
223 mmc_init(mmc);
224
225 lcd_printf("\teMMC size: %llu MB\n", mmc->capacity / SZ_1M);
226 }
227#endif
228 if (vid)
229 lcd_printf("\tDisplay resolution: %u x % u\n",
230 vid->vl_col, vid->vl_row);
231
232 lcd_printf("\tDisplay BPP: %u\n", 1 << vid->vl_bpix);
233}
234
235static int mode_leave_menu(int mode)
236{
237 char *exit_option;
Przemyslaw Marczake6bfe792014-04-30 13:28:06 +0200238 char *exit_reset = "reset";
Przemyslaw Marczak9d29a682014-01-22 11:24:17 +0100239 char *exit_back = "back";
240 cmd_tbl_t *cmd;
241 int cmd_result;
Przemyslaw Marczak9d29a682014-01-22 11:24:17 +0100242 int leave;
243
244 lcd_clear();
245
246 switch (mode) {
247 case BOOT_MODE_EXIT:
248 return 1;
249 case BOOT_MODE_INFO:
250 display_board_info();
251 exit_option = exit_back;
252 leave = 0;
253 break;
254 default:
Przemyslaw Marczake6bfe792014-04-30 13:28:06 +0200255 cmd = find_cmd(mode_name[mode][1]);
Przemyslaw Marczak9d29a682014-01-22 11:24:17 +0100256 if (cmd) {
Przemyslaw Marczake6bfe792014-04-30 13:28:06 +0200257 printf("Enter: %s %s\n", mode_name[mode][0],
Przemyslaw Marczak9d29a682014-01-22 11:24:17 +0100258 mode_info[mode]);
Przemyslaw Marczake6bfe792014-04-30 13:28:06 +0200259 lcd_printf("\n\n\t%s %s\n", mode_name[mode][0],
Przemyslaw Marczak9d29a682014-01-22 11:24:17 +0100260 mode_info[mode]);
261 lcd_puts("\n\tDo not turn off device before finish!\n");
262
Przemyslaw Marczake6bfe792014-04-30 13:28:06 +0200263 cmd_result = run_command(mode_cmd[mode], 0);
Przemyslaw Marczak9d29a682014-01-22 11:24:17 +0100264
265 if (cmd_result == CMD_RET_SUCCESS) {
266 printf("Command finished\n");
267 lcd_clear();
268 lcd_printf("\n\n\t%s finished\n",
Przemyslaw Marczake6bfe792014-04-30 13:28:06 +0200269 mode_name[mode][0]);
Przemyslaw Marczak9d29a682014-01-22 11:24:17 +0100270
Przemyslaw Marczake6bfe792014-04-30 13:28:06 +0200271 exit_option = exit_reset;
Przemyslaw Marczak9d29a682014-01-22 11:24:17 +0100272 leave = 1;
273 } else {
274 printf("Command error\n");
275 lcd_clear();
276 lcd_printf("\n\n\t%s command error\n",
Przemyslaw Marczake6bfe792014-04-30 13:28:06 +0200277 mode_name[mode][0]);
Przemyslaw Marczak9d29a682014-01-22 11:24:17 +0100278
279 exit_option = exit_back;
280 leave = 0;
281 }
282 } else {
283 lcd_puts("\n\n\tThis mode is not supported.\n");
284 exit_option = exit_back;
285 leave = 0;
286 }
287 }
288
289 lcd_printf("\n\n\tPress POWER KEY to %s\n", exit_option);
290
291 /* Clear PWR button Rising edge interrupt status flag */
292 power_key_pressed(KEY_PWR_INTERRUPT_REG);
293
294 /* Wait for PWR key */
295 while (!key_pressed(KEY_POWER))
296 mdelay(1);
297
298 lcd_clear();
299 return leave;
300}
301
302static void display_download_menu(int mode)
303{
304 char *selection[BOOT_MODE_EXIT + 1];
305 int i;
306
307 for (i = 0; i <= BOOT_MODE_EXIT; i++)
308 selection[i] = "[ ]";
309
310 selection[mode] = "[=>]";
311
312 lcd_clear();
Przemyslaw Marczak605d7e22014-04-30 13:28:10 +0200313 lcd_printf("\n\n\t\tDownload Mode Menu\n\n");
Przemyslaw Marczak9d29a682014-01-22 11:24:17 +0100314
315 for (i = 0; i <= BOOT_MODE_EXIT; i++)
316 lcd_printf("\t%s %s - %s\n\n", selection[i],
Przemyslaw Marczake6bfe792014-04-30 13:28:06 +0200317 mode_name[i][0],
Przemyslaw Marczak9d29a682014-01-22 11:24:17 +0100318 mode_info[i]);
319}
320
321static void download_menu(void)
322{
323 int mode = 0;
324 int last_mode = 0;
325 int run;
Przemyslaw Marczak605d7e22014-04-30 13:28:10 +0200326 int key = 0;
327 int timeout = 15; /* sec */
328 int i;
Przemyslaw Marczak9d29a682014-01-22 11:24:17 +0100329
330 display_download_menu(mode);
331
Przemyslaw Marczak605d7e22014-04-30 13:28:10 +0200332 lcd_puts("\n");
333
334 /* Start count if no key is pressed */
335 while (check_keys())
336 continue;
337
338 while (timeout--) {
339 lcd_printf("\r\tNormal boot will start in: %2.d seconds.",
340 timeout);
341
342 /* about 1000 ms in for loop */
343 for (i = 0; i < 10; i++) {
344 mdelay(100);
345 key = check_keys();
346 if (key)
347 break;
348 }
349 if (key)
350 break;
351 }
352
353 if (!key) {
354 lcd_clear();
355 return;
356 }
357
Przemyslaw Marczak9d29a682014-01-22 11:24:17 +0100358 while (1) {
359 run = 0;
360
361 if (mode != last_mode)
362 display_download_menu(mode);
363
364 last_mode = mode;
Przemyslaw Marczakf418a1c2014-04-30 13:28:09 +0200365 mdelay(200);
Przemyslaw Marczak9d29a682014-01-22 11:24:17 +0100366
367 key = check_keys();
368 switch (key) {
369 case KEY_POWER:
370 run = 1;
371 break;
372 case KEY_VOLUMEUP:
373 if (mode > 0)
374 mode--;
375 break;
376 case KEY_VOLUMEDOWN:
377 if (mode < BOOT_MODE_EXIT)
378 mode++;
379 break;
380 default:
381 break;
382 }
383
384 if (run) {
385 if (mode_leave_menu(mode))
Przemyslaw Marczake6bfe792014-04-30 13:28:06 +0200386 run_command("reset", 0);
Przemyslaw Marczak9d29a682014-01-22 11:24:17 +0100387
388 display_download_menu(mode);
389 }
390 }
391
392 lcd_clear();
393}
394
Przemyslaw Marczak9d29a682014-01-22 11:24:17 +0100395void check_boot_mode(void)
396{
397 int pwr_key;
398
399 pwr_key = power_key_pressed(KEY_PWR_STATUS_REG);
400 if (!pwr_key)
401 return;
402
403 /* Clear PWR button Rising edge interrupt status flag */
404 power_key_pressed(KEY_PWR_INTERRUPT_REG);
405
406 if (key_pressed(KEY_VOLUMEUP))
Przemyslaw Marczak605d7e22014-04-30 13:28:10 +0200407 download_menu();
Przemyslaw Marczak9d29a682014-01-22 11:24:17 +0100408 else if (key_pressed(KEY_VOLUMEDOWN))
409 mode_leave_menu(BOOT_MODE_THOR);
410}
411
412void keys_init(void)
413{
414 /* Set direction to input */
Simon Glass7f196102014-10-20 19:48:39 -0600415 gpio_request(KEY_VOL_UP_GPIO, "volume-up");
416 gpio_request(KEY_VOL_DOWN_GPIO, "volume-down");
Przemyslaw Marczak9d29a682014-01-22 11:24:17 +0100417 gpio_direction_input(KEY_VOL_UP_GPIO);
418 gpio_direction_input(KEY_VOL_DOWN_GPIO);
419}
420#endif /* CONFIG_LCD_MENU */
Przemyslaw Marczak679549d2014-01-22 11:24:12 +0100421
422#ifdef CONFIG_CMD_BMP
423void draw_logo(void)
424{
425 int x, y;
426 ulong addr;
427
428 addr = panel_info.logo_addr;
429 if (!addr) {
430 error("There is no logo data.");
431 return;
432 }
433
434 if (panel_info.vl_width >= panel_info.logo_width) {
435 x = ((panel_info.vl_width - panel_info.logo_width) >> 1);
Przemyslaw Marczak903afe12013-11-29 18:30:43 +0100436 x += panel_info.logo_x_offset; /* For X center align */
Przemyslaw Marczak679549d2014-01-22 11:24:12 +0100437 } else {
438 x = 0;
439 printf("Warning: image width is bigger than display width\n");
440 }
441
442 if (panel_info.vl_height >= panel_info.logo_height) {
443 y = ((panel_info.vl_height - panel_info.logo_height) >> 1);
Przemyslaw Marczak903afe12013-11-29 18:30:43 +0100444 y += panel_info.logo_y_offset; /* For Y center align */
Przemyslaw Marczak679549d2014-01-22 11:24:12 +0100445 } else {
446 y = 0;
447 printf("Warning: image height is bigger than display height\n");
448 }
449
450 bmp_display(addr, x, y);
451}
452#endif /* CONFIG_CMD_BMP */