Simon Glass | 9e972c3 | 2022-10-06 08:36:16 -0600 | [diff] [blame] | 1 | // SPDX-License-Identifier: GPL-2.0+ |
| 2 | /* |
| 3 | * video commands |
| 4 | * |
| 5 | * Copyright 2022 Google LLC |
| 6 | * Written by Simon Glass <sjg@chromium.org> |
| 7 | */ |
| 8 | |
| 9 | #include <common.h> |
| 10 | #include <command.h> |
| 11 | #include <dm.h> |
| 12 | #include <video.h> |
| 13 | #include <video_console.h> |
| 14 | |
| 15 | static int do_font_list(struct cmd_tbl *cmdtp, int flag, int argc, |
| 16 | char *const argv[]) |
| 17 | { |
| 18 | vidconsole_list_fonts(); |
| 19 | |
| 20 | return 0; |
| 21 | } |
| 22 | |
| 23 | static int do_font_select(struct cmd_tbl *cmdtp, int flag, int argc, |
| 24 | char *const argv[]) |
| 25 | { |
| 26 | struct udevice *dev; |
| 27 | const char *name; |
| 28 | uint size = 0; |
| 29 | int ret; |
| 30 | |
| 31 | if (argc < 2) |
| 32 | return CMD_RET_USAGE; |
| 33 | |
| 34 | if (uclass_first_device_err(UCLASS_VIDEO_CONSOLE, &dev)) |
| 35 | return CMD_RET_FAILURE; |
| 36 | name = argv[1]; |
| 37 | if (argc == 3) |
| 38 | size = dectoul(argv[2], NULL); |
| 39 | ret = vidconsole_select_font(dev, name, size); |
| 40 | if (ret) { |
| 41 | printf("Failed (error %d)\n", ret); |
| 42 | return CMD_RET_FAILURE; |
| 43 | } |
| 44 | |
| 45 | return 0; |
| 46 | } |
| 47 | static int do_font_size(struct cmd_tbl *cmdtp, int flag, int argc, |
| 48 | char *const argv[]) |
| 49 | { |
| 50 | struct udevice *dev; |
| 51 | uint size; |
| 52 | int ret; |
| 53 | |
| 54 | if (argc != 2) |
| 55 | return CMD_RET_USAGE; |
| 56 | |
| 57 | if (uclass_first_device_err(UCLASS_VIDEO_CONSOLE, &dev)) |
| 58 | return CMD_RET_FAILURE; |
| 59 | |
| 60 | size = dectoul(argv[1], NULL); |
| 61 | ret = vidconsole_select_font(dev, NULL, size); |
| 62 | if (ret) { |
| 63 | printf("Failed (error %d)\n", ret); |
| 64 | return CMD_RET_FAILURE; |
| 65 | } |
| 66 | |
| 67 | return 0; |
| 68 | } |
| 69 | |
| 70 | |
| 71 | #ifdef CONFIG_SYS_LONGHELP |
| 72 | static char font_help_text[] = |
| 73 | "list - list available fonts\n" |
| 74 | "font select <name> [<size>] - select font to use\n" |
| 75 | "font size <size> - select font size to"; |
| 76 | #endif |
| 77 | |
| 78 | U_BOOT_CMD_WITH_SUBCMDS(font, "Fonts", font_help_text, |
| 79 | U_BOOT_SUBCMD_MKENT(list, 1, 1, do_font_list), |
| 80 | U_BOOT_SUBCMD_MKENT(select, 3, 1, do_font_select), |
| 81 | U_BOOT_SUBCMD_MKENT(size, 2, 1, do_font_size)); |