blob: 1a77c820ae97f7604be995faa4a850b7943da230 [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>
19#include <power/pmic.h>
20#include <mmc.h>
21
22DECLARE_GLOBAL_DATA_PTR;
23
Przemyslaw Marczak1d07c102014-09-01 13:50:46 +020024#ifdef CONFIG_SET_DFU_ALT_INFO
Przemyslaw Marczak899a5282015-02-17 12:24:11 +010025void set_dfu_alt_info(char *interface, char *devstr)
Przemyslaw Marczak1d07c102014-09-01 13:50:46 +020026{
27 size_t buf_size = CONFIG_SET_DFU_ALT_BUF_LEN;
28 ALLOC_CACHE_ALIGN_BUFFER(char, buf, buf_size);
29 char *alt_info = "Settings not found!";
30 char *status = "error!\n";
31 char *alt_setting;
32 char *alt_sep;
33 int offset = 0;
34
35 puts("DFU alt info setting: ");
36
Przemyslaw Marczak899a5282015-02-17 12:24:11 +010037 alt_setting = get_dfu_alt_boot(interface, devstr);
Przemyslaw Marczak1d07c102014-09-01 13:50:46 +020038 if (alt_setting) {
39 setenv("dfu_alt_boot", alt_setting);
40 offset = snprintf(buf, buf_size, "%s", alt_setting);
41 }
42
Przemyslaw Marczak899a5282015-02-17 12:24:11 +010043 alt_setting = get_dfu_alt_system(interface, devstr);
Przemyslaw Marczak1d07c102014-09-01 13:50:46 +020044 if (alt_setting) {
45 if (offset)
46 alt_sep = ";";
47 else
48 alt_sep = "";
49
50 offset += snprintf(buf + offset, buf_size - offset,
51 "%s%s", alt_sep, alt_setting);
52 }
53
54 if (offset) {
55 alt_info = buf;
56 status = "done\n";
57 }
58
59 setenv("dfu_alt_info", alt_info);
60 puts(status);
61}
62#endif
63
Piotr Wilczekeee2fab2014-01-22 15:54:32 +010064#ifdef CONFIG_ENV_VARS_UBOOT_RUNTIME_CONFIG
65void set_board_info(void)
66{
67 char info[64];
68
Przemyslaw Marczak0dc579f2014-09-01 13:50:42 +020069 snprintf(info, ARRAY_SIZE(info), "%u.%u", (s5p_cpu_rev & 0xf0) >> 4,
70 s5p_cpu_rev & 0xf);
Piotr Wilczekeee2fab2014-01-22 15:54:32 +010071 setenv("soc_rev", info);
72
73 snprintf(info, ARRAY_SIZE(info), "%x", s5p_cpu_id);
74 setenv("soc_id", info);
75
76#ifdef CONFIG_REVISION_TAG
77 snprintf(info, ARRAY_SIZE(info), "%x", get_board_rev());
78 setenv("board_rev", info);
79#endif
80#ifdef CONFIG_OF_LIBFDT
Przemyslaw Marczakc9c36bf2014-09-01 13:50:50 +020081 const char *bdtype = "";
82 const char *bdname = CONFIG_SYS_BOARD;
83
84#ifdef CONFIG_BOARD_TYPES
85 bdtype = get_board_type();
86 sprintf(info, "%s%s", bdname, bdtype);
87 setenv("boardname", info);
88#endif
89 snprintf(info, ARRAY_SIZE(info), "%s%x-%s%s.dtb",
90 CONFIG_SYS_SOC, s5p_cpu_id, bdname, bdtype);
Piotr Wilczekeee2fab2014-01-22 15:54:32 +010091 setenv("fdtfile", info);
92#endif
93}
94#endif /* CONFIG_ENV_VARS_UBOOT_RUNTIME_CONFIG */
95
Przemyslaw Marczak9d29a682014-01-22 11:24:17 +010096#ifdef CONFIG_LCD_MENU
97static int power_key_pressed(u32 reg)
98{
99 struct pmic *pmic;
100 u32 status;
101 u32 mask;
102
103 pmic = pmic_get(KEY_PWR_PMIC_NAME);
104 if (!pmic) {
105 printf("%s: Not found\n", KEY_PWR_PMIC_NAME);
106 return 0;
107 }
108
109 if (pmic_probe(pmic))
110 return 0;
111
112 if (reg == KEY_PWR_STATUS_REG)
113 mask = KEY_PWR_STATUS_MASK;
114 else
115 mask = KEY_PWR_INTERRUPT_MASK;
116
117 if (pmic_reg_read(pmic, reg, &status))
118 return 0;
119
120 return !!(status & mask);
121}
122
123static int key_pressed(int key)
124{
125 int value;
126
127 switch (key) {
128 case KEY_POWER:
129 value = power_key_pressed(KEY_PWR_INTERRUPT_REG);
130 break;
131 case KEY_VOLUMEUP:
132 value = !gpio_get_value(KEY_VOL_UP_GPIO);
133 break;
134 case KEY_VOLUMEDOWN:
135 value = !gpio_get_value(KEY_VOL_DOWN_GPIO);
136 break;
137 default:
138 value = 0;
139 break;
140 }
141
142 return value;
143}
144
145static int check_keys(void)
146{
147 int keys = 0;
148
149 if (key_pressed(KEY_POWER))
150 keys += KEY_POWER;
151 if (key_pressed(KEY_VOLUMEUP))
152 keys += KEY_VOLUMEUP;
153 if (key_pressed(KEY_VOLUMEDOWN))
154 keys += KEY_VOLUMEDOWN;
155
156 return keys;
157}
158
159/*
160 * 0 BOOT_MODE_INFO
161 * 1 BOOT_MODE_THOR
162 * 2 BOOT_MODE_UMS
163 * 3 BOOT_MODE_DFU
164 * 4 BOOT_MODE_EXIT
165 */
166static char *
Przemyslaw Marczake6bfe792014-04-30 13:28:06 +0200167mode_name[BOOT_MODE_EXIT + 1][2] = {
168 {"DEVICE", ""},
169 {"THOR", "thor"},
170 {"UMS", "ums"},
171 {"DFU", "dfu"},
Przemyslaw Marczak5c7b8a32014-04-30 13:28:07 +0200172 {"GPT", "gpt"},
Inha Song0954dd62014-04-30 13:28:08 +0200173 {"ENV", "env"},
Przemyslaw Marczake6bfe792014-04-30 13:28:06 +0200174 {"EXIT", ""},
Przemyslaw Marczak9d29a682014-01-22 11:24:17 +0100175};
176
177static char *
178mode_info[BOOT_MODE_EXIT + 1] = {
179 "info",
180 "downloader",
181 "mass storage",
182 "firmware update",
Przemyslaw Marczak5c7b8a32014-04-30 13:28:07 +0200183 "restore",
Inha Song0954dd62014-04-30 13:28:08 +0200184 "default",
Przemyslaw Marczak9d29a682014-01-22 11:24:17 +0100185 "and run normal boot"
186};
187
Przemyslaw Marczak9d29a682014-01-22 11:24:17 +0100188static char *
Przemyslaw Marczake6bfe792014-04-30 13:28:06 +0200189mode_cmd[BOOT_MODE_EXIT + 1] = {
190 "",
191 "thor 0 mmc 0",
192 "ums 0 mmc 0",
193 "dfu 0 mmc 0",
Przemyslaw Marczak5c7b8a32014-04-30 13:28:07 +0200194 "gpt write mmc 0 $partitions",
Inha Song0954dd62014-04-30 13:28:08 +0200195 "env default -a; saveenv",
Przemyslaw Marczake6bfe792014-04-30 13:28:06 +0200196 "",
Przemyslaw Marczak9d29a682014-01-22 11:24:17 +0100197};
198
199static void display_board_info(void)
200{
201#ifdef CONFIG_GENERIC_MMC
202 struct mmc *mmc = find_mmc_device(0);
203#endif
204 vidinfo_t *vid = &panel_info;
205
206 lcd_position_cursor(4, 4);
207
208 lcd_printf("%s\n\t", U_BOOT_VERSION);
209 lcd_puts("\n\t\tBoard Info:\n");
210#ifdef CONFIG_SYS_BOARD
211 lcd_printf("\tBoard name: %s\n", CONFIG_SYS_BOARD);
212#endif
213#ifdef CONFIG_REVISION_TAG
214 lcd_printf("\tBoard rev: %u\n", get_board_rev());
215#endif
216 lcd_printf("\tDRAM banks: %u\n", CONFIG_NR_DRAM_BANKS);
217 lcd_printf("\tDRAM size: %u MB\n", gd->ram_size / SZ_1M);
218
219#ifdef CONFIG_GENERIC_MMC
220 if (mmc) {
221 if (!mmc->capacity)
222 mmc_init(mmc);
223
224 lcd_printf("\teMMC size: %llu MB\n", mmc->capacity / SZ_1M);
225 }
226#endif
227 if (vid)
228 lcd_printf("\tDisplay resolution: %u x % u\n",
229 vid->vl_col, vid->vl_row);
230
231 lcd_printf("\tDisplay BPP: %u\n", 1 << vid->vl_bpix);
232}
233
234static int mode_leave_menu(int mode)
235{
236 char *exit_option;
Przemyslaw Marczake6bfe792014-04-30 13:28:06 +0200237 char *exit_reset = "reset";
Przemyslaw Marczak9d29a682014-01-22 11:24:17 +0100238 char *exit_back = "back";
239 cmd_tbl_t *cmd;
240 int cmd_result;
Przemyslaw Marczak9d29a682014-01-22 11:24:17 +0100241 int leave;
242
243 lcd_clear();
244
245 switch (mode) {
246 case BOOT_MODE_EXIT:
247 return 1;
248 case BOOT_MODE_INFO:
249 display_board_info();
250 exit_option = exit_back;
251 leave = 0;
252 break;
253 default:
Przemyslaw Marczake6bfe792014-04-30 13:28:06 +0200254 cmd = find_cmd(mode_name[mode][1]);
Przemyslaw Marczak9d29a682014-01-22 11:24:17 +0100255 if (cmd) {
Przemyslaw Marczake6bfe792014-04-30 13:28:06 +0200256 printf("Enter: %s %s\n", mode_name[mode][0],
Przemyslaw Marczak9d29a682014-01-22 11:24:17 +0100257 mode_info[mode]);
Przemyslaw Marczake6bfe792014-04-30 13:28:06 +0200258 lcd_printf("\n\n\t%s %s\n", mode_name[mode][0],
Przemyslaw Marczak9d29a682014-01-22 11:24:17 +0100259 mode_info[mode]);
260 lcd_puts("\n\tDo not turn off device before finish!\n");
261
Przemyslaw Marczake6bfe792014-04-30 13:28:06 +0200262 cmd_result = run_command(mode_cmd[mode], 0);
Przemyslaw Marczak9d29a682014-01-22 11:24:17 +0100263
264 if (cmd_result == CMD_RET_SUCCESS) {
265 printf("Command finished\n");
266 lcd_clear();
267 lcd_printf("\n\n\t%s finished\n",
Przemyslaw Marczake6bfe792014-04-30 13:28:06 +0200268 mode_name[mode][0]);
Przemyslaw Marczak9d29a682014-01-22 11:24:17 +0100269
Przemyslaw Marczake6bfe792014-04-30 13:28:06 +0200270 exit_option = exit_reset;
Przemyslaw Marczak9d29a682014-01-22 11:24:17 +0100271 leave = 1;
272 } else {
273 printf("Command error\n");
274 lcd_clear();
275 lcd_printf("\n\n\t%s command error\n",
Przemyslaw Marczake6bfe792014-04-30 13:28:06 +0200276 mode_name[mode][0]);
Przemyslaw Marczak9d29a682014-01-22 11:24:17 +0100277
278 exit_option = exit_back;
279 leave = 0;
280 }
281 } else {
282 lcd_puts("\n\n\tThis mode is not supported.\n");
283 exit_option = exit_back;
284 leave = 0;
285 }
286 }
287
288 lcd_printf("\n\n\tPress POWER KEY to %s\n", exit_option);
289
290 /* Clear PWR button Rising edge interrupt status flag */
291 power_key_pressed(KEY_PWR_INTERRUPT_REG);
292
293 /* Wait for PWR key */
294 while (!key_pressed(KEY_POWER))
295 mdelay(1);
296
297 lcd_clear();
298 return leave;
299}
300
301static void display_download_menu(int mode)
302{
303 char *selection[BOOT_MODE_EXIT + 1];
304 int i;
305
306 for (i = 0; i <= BOOT_MODE_EXIT; i++)
307 selection[i] = "[ ]";
308
309 selection[mode] = "[=>]";
310
311 lcd_clear();
Przemyslaw Marczak605d7e22014-04-30 13:28:10 +0200312 lcd_printf("\n\n\t\tDownload Mode Menu\n\n");
Przemyslaw Marczak9d29a682014-01-22 11:24:17 +0100313
314 for (i = 0; i <= BOOT_MODE_EXIT; i++)
315 lcd_printf("\t%s %s - %s\n\n", selection[i],
Przemyslaw Marczake6bfe792014-04-30 13:28:06 +0200316 mode_name[i][0],
Przemyslaw Marczak9d29a682014-01-22 11:24:17 +0100317 mode_info[i]);
318}
319
320static void download_menu(void)
321{
322 int mode = 0;
323 int last_mode = 0;
324 int run;
Przemyslaw Marczak605d7e22014-04-30 13:28:10 +0200325 int key = 0;
326 int timeout = 15; /* sec */
327 int i;
Przemyslaw Marczak9d29a682014-01-22 11:24:17 +0100328
329 display_download_menu(mode);
330
Przemyslaw Marczak605d7e22014-04-30 13:28:10 +0200331 lcd_puts("\n");
332
333 /* Start count if no key is pressed */
334 while (check_keys())
335 continue;
336
337 while (timeout--) {
338 lcd_printf("\r\tNormal boot will start in: %2.d seconds.",
339 timeout);
340
341 /* about 1000 ms in for loop */
342 for (i = 0; i < 10; i++) {
343 mdelay(100);
344 key = check_keys();
345 if (key)
346 break;
347 }
348 if (key)
349 break;
350 }
351
352 if (!key) {
353 lcd_clear();
354 return;
355 }
356
Przemyslaw Marczak9d29a682014-01-22 11:24:17 +0100357 while (1) {
358 run = 0;
359
360 if (mode != last_mode)
361 display_download_menu(mode);
362
363 last_mode = mode;
Przemyslaw Marczakf418a1c2014-04-30 13:28:09 +0200364 mdelay(200);
Przemyslaw Marczak9d29a682014-01-22 11:24:17 +0100365
366 key = check_keys();
367 switch (key) {
368 case KEY_POWER:
369 run = 1;
370 break;
371 case KEY_VOLUMEUP:
372 if (mode > 0)
373 mode--;
374 break;
375 case KEY_VOLUMEDOWN:
376 if (mode < BOOT_MODE_EXIT)
377 mode++;
378 break;
379 default:
380 break;
381 }
382
383 if (run) {
384 if (mode_leave_menu(mode))
Przemyslaw Marczake6bfe792014-04-30 13:28:06 +0200385 run_command("reset", 0);
Przemyslaw Marczak9d29a682014-01-22 11:24:17 +0100386
387 display_download_menu(mode);
388 }
389 }
390
391 lcd_clear();
392}
393
Przemyslaw Marczak9d29a682014-01-22 11:24:17 +0100394void check_boot_mode(void)
395{
396 int pwr_key;
397
398 pwr_key = power_key_pressed(KEY_PWR_STATUS_REG);
399 if (!pwr_key)
400 return;
401
402 /* Clear PWR button Rising edge interrupt status flag */
403 power_key_pressed(KEY_PWR_INTERRUPT_REG);
404
405 if (key_pressed(KEY_VOLUMEUP))
Przemyslaw Marczak605d7e22014-04-30 13:28:10 +0200406 download_menu();
Przemyslaw Marczak9d29a682014-01-22 11:24:17 +0100407 else if (key_pressed(KEY_VOLUMEDOWN))
408 mode_leave_menu(BOOT_MODE_THOR);
409}
410
411void keys_init(void)
412{
413 /* Set direction to input */
Simon Glass7f196102014-10-20 19:48:39 -0600414 gpio_request(KEY_VOL_UP_GPIO, "volume-up");
415 gpio_request(KEY_VOL_DOWN_GPIO, "volume-down");
Przemyslaw Marczak9d29a682014-01-22 11:24:17 +0100416 gpio_direction_input(KEY_VOL_UP_GPIO);
417 gpio_direction_input(KEY_VOL_DOWN_GPIO);
418}
419#endif /* CONFIG_LCD_MENU */
Przemyslaw Marczak679549d2014-01-22 11:24:12 +0100420
421#ifdef CONFIG_CMD_BMP
422void draw_logo(void)
423{
424 int x, y;
425 ulong addr;
426
427 addr = panel_info.logo_addr;
428 if (!addr) {
429 error("There is no logo data.");
430 return;
431 }
432
433 if (panel_info.vl_width >= panel_info.logo_width) {
434 x = ((panel_info.vl_width - panel_info.logo_width) >> 1);
Przemyslaw Marczak903afe12013-11-29 18:30:43 +0100435 x += panel_info.logo_x_offset; /* For X center align */
Przemyslaw Marczak679549d2014-01-22 11:24:12 +0100436 } else {
437 x = 0;
438 printf("Warning: image width is bigger than display width\n");
439 }
440
441 if (panel_info.vl_height >= panel_info.logo_height) {
442 y = ((panel_info.vl_height - panel_info.logo_height) >> 1);
Przemyslaw Marczak903afe12013-11-29 18:30:43 +0100443 y += panel_info.logo_y_offset; /* For Y center align */
Przemyslaw Marczak679549d2014-01-22 11:24:12 +0100444 } else {
445 y = 0;
446 printf("Warning: image height is bigger than display height\n");
447 }
448
449 bmp_display(addr, x, y);
450}
451#endif /* CONFIG_CMD_BMP */