blob: e0e2c48632cf37907170f1888786a2f21361c5a1 [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>
Simon Glasscf92e052015-09-02 17:24:58 -060015#include <memalign.h>
Alexey Brodkin1ace4022014-02-26 17:47:58 +040016#include <linux/sizes.h>
Przemyslaw Marczak9d29a682014-01-22 11:24:17 +010017#include <asm/arch/cpu.h>
Przemyslaw Marczak9d29a682014-01-22 11:24:17 +010018#include <asm/gpio.h>
19#include <linux/input.h>
Przemyslaw Marczakca2b9332015-05-13 13:38:25 +020020#include <dm.h>
Przemyslaw Marczak9d29a682014-01-22 11:24:17 +010021#include <power/pmic.h>
22#include <mmc.h>
23
24DECLARE_GLOBAL_DATA_PTR;
25
Przemyslaw Marczak1d07c102014-09-01 13:50:46 +020026#ifdef CONFIG_SET_DFU_ALT_INFO
Przemyslaw Marczak899a5282015-02-17 12:24:11 +010027void set_dfu_alt_info(char *interface, char *devstr)
Przemyslaw Marczak1d07c102014-09-01 13:50:46 +020028{
29 size_t buf_size = CONFIG_SET_DFU_ALT_BUF_LEN;
30 ALLOC_CACHE_ALIGN_BUFFER(char, buf, buf_size);
31 char *alt_info = "Settings not found!";
32 char *status = "error!\n";
33 char *alt_setting;
34 char *alt_sep;
35 int offset = 0;
36
37 puts("DFU alt info setting: ");
38
Przemyslaw Marczak899a5282015-02-17 12:24:11 +010039 alt_setting = get_dfu_alt_boot(interface, devstr);
Przemyslaw Marczak1d07c102014-09-01 13:50:46 +020040 if (alt_setting) {
41 setenv("dfu_alt_boot", alt_setting);
42 offset = snprintf(buf, buf_size, "%s", alt_setting);
43 }
44
Przemyslaw Marczak899a5282015-02-17 12:24:11 +010045 alt_setting = get_dfu_alt_system(interface, devstr);
Przemyslaw Marczak1d07c102014-09-01 13:50:46 +020046 if (alt_setting) {
47 if (offset)
48 alt_sep = ";";
49 else
50 alt_sep = "";
51
52 offset += snprintf(buf + offset, buf_size - offset,
53 "%s%s", alt_sep, alt_setting);
54 }
55
56 if (offset) {
57 alt_info = buf;
58 status = "done\n";
59 }
60
61 setenv("dfu_alt_info", alt_info);
62 puts(status);
63}
64#endif
65
Piotr Wilczekeee2fab2014-01-22 15:54:32 +010066#ifdef CONFIG_ENV_VARS_UBOOT_RUNTIME_CONFIG
67void set_board_info(void)
68{
69 char info[64];
70
Przemyslaw Marczak0dc579f2014-09-01 13:50:42 +020071 snprintf(info, ARRAY_SIZE(info), "%u.%u", (s5p_cpu_rev & 0xf0) >> 4,
72 s5p_cpu_rev & 0xf);
Piotr Wilczekeee2fab2014-01-22 15:54:32 +010073 setenv("soc_rev", info);
74
75 snprintf(info, ARRAY_SIZE(info), "%x", s5p_cpu_id);
76 setenv("soc_id", info);
77
78#ifdef CONFIG_REVISION_TAG
79 snprintf(info, ARRAY_SIZE(info), "%x", get_board_rev());
80 setenv("board_rev", info);
81#endif
82#ifdef CONFIG_OF_LIBFDT
Przemyslaw Marczakc9c36bf2014-09-01 13:50:50 +020083 const char *bdtype = "";
84 const char *bdname = CONFIG_SYS_BOARD;
85
86#ifdef CONFIG_BOARD_TYPES
87 bdtype = get_board_type();
88 sprintf(info, "%s%s", bdname, bdtype);
89 setenv("boardname", info);
90#endif
91 snprintf(info, ARRAY_SIZE(info), "%s%x-%s%s.dtb",
92 CONFIG_SYS_SOC, s5p_cpu_id, bdname, bdtype);
Piotr Wilczekeee2fab2014-01-22 15:54:32 +010093 setenv("fdtfile", info);
94#endif
95}
96#endif /* CONFIG_ENV_VARS_UBOOT_RUNTIME_CONFIG */
97
Przemyslaw Marczak9d29a682014-01-22 11:24:17 +010098#ifdef CONFIG_LCD_MENU
99static int power_key_pressed(u32 reg)
100{
101 struct pmic *pmic;
102 u32 status;
103 u32 mask;
104
105 pmic = pmic_get(KEY_PWR_PMIC_NAME);
106 if (!pmic) {
107 printf("%s: Not found\n", KEY_PWR_PMIC_NAME);
108 return 0;
109 }
110
111 if (pmic_probe(pmic))
112 return 0;
113
114 if (reg == KEY_PWR_STATUS_REG)
115 mask = KEY_PWR_STATUS_MASK;
116 else
117 mask = KEY_PWR_INTERRUPT_MASK;
118
119 if (pmic_reg_read(pmic, reg, &status))
120 return 0;
121
122 return !!(status & mask);
123}
124
125static int key_pressed(int key)
126{
127 int value;
128
129 switch (key) {
130 case KEY_POWER:
131 value = power_key_pressed(KEY_PWR_INTERRUPT_REG);
132 break;
133 case KEY_VOLUMEUP:
134 value = !gpio_get_value(KEY_VOL_UP_GPIO);
135 break;
136 case KEY_VOLUMEDOWN:
137 value = !gpio_get_value(KEY_VOL_DOWN_GPIO);
138 break;
139 default:
140 value = 0;
141 break;
142 }
143
144 return value;
145}
146
147static int check_keys(void)
148{
149 int keys = 0;
150
151 if (key_pressed(KEY_POWER))
152 keys += KEY_POWER;
153 if (key_pressed(KEY_VOLUMEUP))
154 keys += KEY_VOLUMEUP;
155 if (key_pressed(KEY_VOLUMEDOWN))
156 keys += KEY_VOLUMEDOWN;
157
158 return keys;
159}
160
161/*
162 * 0 BOOT_MODE_INFO
163 * 1 BOOT_MODE_THOR
164 * 2 BOOT_MODE_UMS
165 * 3 BOOT_MODE_DFU
166 * 4 BOOT_MODE_EXIT
167 */
168static char *
Przemyslaw Marczake6bfe792014-04-30 13:28:06 +0200169mode_name[BOOT_MODE_EXIT + 1][2] = {
170 {"DEVICE", ""},
171 {"THOR", "thor"},
172 {"UMS", "ums"},
173 {"DFU", "dfu"},
Przemyslaw Marczak5c7b8a32014-04-30 13:28:07 +0200174 {"GPT", "gpt"},
Inha Song0954dd62014-04-30 13:28:08 +0200175 {"ENV", "env"},
Przemyslaw Marczake6bfe792014-04-30 13:28:06 +0200176 {"EXIT", ""},
Przemyslaw Marczak9d29a682014-01-22 11:24:17 +0100177};
178
179static char *
180mode_info[BOOT_MODE_EXIT + 1] = {
181 "info",
182 "downloader",
183 "mass storage",
184 "firmware update",
Przemyslaw Marczak5c7b8a32014-04-30 13:28:07 +0200185 "restore",
Inha Song0954dd62014-04-30 13:28:08 +0200186 "default",
Przemyslaw Marczak9d29a682014-01-22 11:24:17 +0100187 "and run normal boot"
188};
189
Przemyslaw Marczak9d29a682014-01-22 11:24:17 +0100190static char *
Przemyslaw Marczake6bfe792014-04-30 13:28:06 +0200191mode_cmd[BOOT_MODE_EXIT + 1] = {
192 "",
193 "thor 0 mmc 0",
194 "ums 0 mmc 0",
195 "dfu 0 mmc 0",
Przemyslaw Marczak5c7b8a32014-04-30 13:28:07 +0200196 "gpt write mmc 0 $partitions",
Inha Song0954dd62014-04-30 13:28:08 +0200197 "env default -a; saveenv",
Przemyslaw Marczake6bfe792014-04-30 13:28:06 +0200198 "",
Przemyslaw Marczak9d29a682014-01-22 11:24:17 +0100199};
200
201static void display_board_info(void)
202{
203#ifdef CONFIG_GENERIC_MMC
204 struct mmc *mmc = find_mmc_device(0);
205#endif
206 vidinfo_t *vid = &panel_info;
207
208 lcd_position_cursor(4, 4);
209
210 lcd_printf("%s\n\t", U_BOOT_VERSION);
211 lcd_puts("\n\t\tBoard Info:\n");
212#ifdef CONFIG_SYS_BOARD
213 lcd_printf("\tBoard name: %s\n", CONFIG_SYS_BOARD);
214#endif
215#ifdef CONFIG_REVISION_TAG
216 lcd_printf("\tBoard rev: %u\n", get_board_rev());
217#endif
218 lcd_printf("\tDRAM banks: %u\n", CONFIG_NR_DRAM_BANKS);
219 lcd_printf("\tDRAM size: %u MB\n", gd->ram_size / SZ_1M);
220
221#ifdef CONFIG_GENERIC_MMC
222 if (mmc) {
223 if (!mmc->capacity)
224 mmc_init(mmc);
225
226 lcd_printf("\teMMC size: %llu MB\n", mmc->capacity / SZ_1M);
227 }
228#endif
229 if (vid)
230 lcd_printf("\tDisplay resolution: %u x % u\n",
231 vid->vl_col, vid->vl_row);
232
233 lcd_printf("\tDisplay BPP: %u\n", 1 << vid->vl_bpix);
234}
235
236static int mode_leave_menu(int mode)
237{
238 char *exit_option;
Przemyslaw Marczake6bfe792014-04-30 13:28:06 +0200239 char *exit_reset = "reset";
Przemyslaw Marczak9d29a682014-01-22 11:24:17 +0100240 char *exit_back = "back";
241 cmd_tbl_t *cmd;
242 int cmd_result;
Przemyslaw Marczak9d29a682014-01-22 11:24:17 +0100243 int leave;
244
245 lcd_clear();
246
247 switch (mode) {
248 case BOOT_MODE_EXIT:
249 return 1;
250 case BOOT_MODE_INFO:
251 display_board_info();
252 exit_option = exit_back;
253 leave = 0;
254 break;
255 default:
Przemyslaw Marczake6bfe792014-04-30 13:28:06 +0200256 cmd = find_cmd(mode_name[mode][1]);
Przemyslaw Marczak9d29a682014-01-22 11:24:17 +0100257 if (cmd) {
Przemyslaw Marczake6bfe792014-04-30 13:28:06 +0200258 printf("Enter: %s %s\n", mode_name[mode][0],
Przemyslaw Marczak9d29a682014-01-22 11:24:17 +0100259 mode_info[mode]);
Przemyslaw Marczake6bfe792014-04-30 13:28:06 +0200260 lcd_printf("\n\n\t%s %s\n", mode_name[mode][0],
Przemyslaw Marczak9d29a682014-01-22 11:24:17 +0100261 mode_info[mode]);
262 lcd_puts("\n\tDo not turn off device before finish!\n");
263
Przemyslaw Marczake6bfe792014-04-30 13:28:06 +0200264 cmd_result = run_command(mode_cmd[mode], 0);
Przemyslaw Marczak9d29a682014-01-22 11:24:17 +0100265
266 if (cmd_result == CMD_RET_SUCCESS) {
267 printf("Command finished\n");
268 lcd_clear();
269 lcd_printf("\n\n\t%s finished\n",
Przemyslaw Marczake6bfe792014-04-30 13:28:06 +0200270 mode_name[mode][0]);
Przemyslaw Marczak9d29a682014-01-22 11:24:17 +0100271
Przemyslaw Marczake6bfe792014-04-30 13:28:06 +0200272 exit_option = exit_reset;
Przemyslaw Marczak9d29a682014-01-22 11:24:17 +0100273 leave = 1;
274 } else {
275 printf("Command error\n");
276 lcd_clear();
277 lcd_printf("\n\n\t%s command error\n",
Przemyslaw Marczake6bfe792014-04-30 13:28:06 +0200278 mode_name[mode][0]);
Przemyslaw Marczak9d29a682014-01-22 11:24:17 +0100279
280 exit_option = exit_back;
281 leave = 0;
282 }
283 } else {
284 lcd_puts("\n\n\tThis mode is not supported.\n");
285 exit_option = exit_back;
286 leave = 0;
287 }
288 }
289
290 lcd_printf("\n\n\tPress POWER KEY to %s\n", exit_option);
291
292 /* Clear PWR button Rising edge interrupt status flag */
293 power_key_pressed(KEY_PWR_INTERRUPT_REG);
294
295 /* Wait for PWR key */
296 while (!key_pressed(KEY_POWER))
297 mdelay(1);
298
299 lcd_clear();
300 return leave;
301}
302
303static void display_download_menu(int mode)
304{
305 char *selection[BOOT_MODE_EXIT + 1];
306 int i;
307
308 for (i = 0; i <= BOOT_MODE_EXIT; i++)
309 selection[i] = "[ ]";
310
311 selection[mode] = "[=>]";
312
313 lcd_clear();
Przemyslaw Marczak605d7e22014-04-30 13:28:10 +0200314 lcd_printf("\n\n\t\tDownload Mode Menu\n\n");
Przemyslaw Marczak9d29a682014-01-22 11:24:17 +0100315
316 for (i = 0; i <= BOOT_MODE_EXIT; i++)
317 lcd_printf("\t%s %s - %s\n\n", selection[i],
Przemyslaw Marczake6bfe792014-04-30 13:28:06 +0200318 mode_name[i][0],
Przemyslaw Marczak9d29a682014-01-22 11:24:17 +0100319 mode_info[i]);
320}
321
322static void download_menu(void)
323{
324 int mode = 0;
325 int last_mode = 0;
326 int run;
Przemyslaw Marczak605d7e22014-04-30 13:28:10 +0200327 int key = 0;
328 int timeout = 15; /* sec */
329 int i;
Przemyslaw Marczak9d29a682014-01-22 11:24:17 +0100330
331 display_download_menu(mode);
332
Przemyslaw Marczak605d7e22014-04-30 13:28:10 +0200333 lcd_puts("\n");
334
335 /* Start count if no key is pressed */
336 while (check_keys())
337 continue;
338
339 while (timeout--) {
340 lcd_printf("\r\tNormal boot will start in: %2.d seconds.",
341 timeout);
342
343 /* about 1000 ms in for loop */
344 for (i = 0; i < 10; i++) {
345 mdelay(100);
346 key = check_keys();
347 if (key)
348 break;
349 }
350 if (key)
351 break;
352 }
353
354 if (!key) {
355 lcd_clear();
356 return;
357 }
358
Przemyslaw Marczak9d29a682014-01-22 11:24:17 +0100359 while (1) {
360 run = 0;
361
362 if (mode != last_mode)
363 display_download_menu(mode);
364
365 last_mode = mode;
Przemyslaw Marczakf418a1c2014-04-30 13:28:09 +0200366 mdelay(200);
Przemyslaw Marczak9d29a682014-01-22 11:24:17 +0100367
368 key = check_keys();
369 switch (key) {
370 case KEY_POWER:
371 run = 1;
372 break;
373 case KEY_VOLUMEUP:
374 if (mode > 0)
375 mode--;
376 break;
377 case KEY_VOLUMEDOWN:
378 if (mode < BOOT_MODE_EXIT)
379 mode++;
380 break;
381 default:
382 break;
383 }
384
385 if (run) {
386 if (mode_leave_menu(mode))
Przemyslaw Marczake6bfe792014-04-30 13:28:06 +0200387 run_command("reset", 0);
Przemyslaw Marczak9d29a682014-01-22 11:24:17 +0100388
389 display_download_menu(mode);
390 }
391 }
392
393 lcd_clear();
394}
395
Przemyslaw Marczak9d29a682014-01-22 11:24:17 +0100396void check_boot_mode(void)
397{
398 int pwr_key;
399
400 pwr_key = power_key_pressed(KEY_PWR_STATUS_REG);
401 if (!pwr_key)
402 return;
403
404 /* Clear PWR button Rising edge interrupt status flag */
405 power_key_pressed(KEY_PWR_INTERRUPT_REG);
406
407 if (key_pressed(KEY_VOLUMEUP))
Przemyslaw Marczak605d7e22014-04-30 13:28:10 +0200408 download_menu();
Przemyslaw Marczak9d29a682014-01-22 11:24:17 +0100409 else if (key_pressed(KEY_VOLUMEDOWN))
410 mode_leave_menu(BOOT_MODE_THOR);
411}
412
413void keys_init(void)
414{
415 /* Set direction to input */
Simon Glass7f196102014-10-20 19:48:39 -0600416 gpio_request(KEY_VOL_UP_GPIO, "volume-up");
417 gpio_request(KEY_VOL_DOWN_GPIO, "volume-down");
Przemyslaw Marczak9d29a682014-01-22 11:24:17 +0100418 gpio_direction_input(KEY_VOL_UP_GPIO);
419 gpio_direction_input(KEY_VOL_DOWN_GPIO);
420}
421#endif /* CONFIG_LCD_MENU */
Przemyslaw Marczak679549d2014-01-22 11:24:12 +0100422
423#ifdef CONFIG_CMD_BMP
424void draw_logo(void)
425{
426 int x, y;
427 ulong addr;
428
429 addr = panel_info.logo_addr;
430 if (!addr) {
431 error("There is no logo data.");
432 return;
433 }
434
435 if (panel_info.vl_width >= panel_info.logo_width) {
436 x = ((panel_info.vl_width - panel_info.logo_width) >> 1);
Przemyslaw Marczak903afe12013-11-29 18:30:43 +0100437 x += panel_info.logo_x_offset; /* For X center align */
Przemyslaw Marczak679549d2014-01-22 11:24:12 +0100438 } else {
439 x = 0;
440 printf("Warning: image width is bigger than display width\n");
441 }
442
443 if (panel_info.vl_height >= panel_info.logo_height) {
444 y = ((panel_info.vl_height - panel_info.logo_height) >> 1);
Przemyslaw Marczak903afe12013-11-29 18:30:43 +0100445 y += panel_info.logo_y_offset; /* For Y center align */
Przemyslaw Marczak679549d2014-01-22 11:24:12 +0100446 } else {
447 y = 0;
448 printf("Warning: image height is bigger than display height\n");
449 }
450
451 bmp_display(addr, x, y);
452}
453#endif /* CONFIG_CMD_BMP */