Simon Glass | 430e167 | 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 | { |
Simon Glass | 0e38bd8 | 2023-01-06 08:52:32 -0600 | [diff] [blame] | 18 | struct udevice *dev; |
| 19 | |
| 20 | if (uclass_first_device_err(UCLASS_VIDEO_CONSOLE, &dev)) |
| 21 | return CMD_RET_FAILURE; |
| 22 | vidconsole_list_fonts(dev); |
Simon Glass | 430e167 | 2022-10-06 08:36:16 -0600 | [diff] [blame] | 23 | |
| 24 | return 0; |
| 25 | } |
| 26 | |
| 27 | static int do_font_select(struct cmd_tbl *cmdtp, int flag, int argc, |
| 28 | char *const argv[]) |
| 29 | { |
| 30 | struct udevice *dev; |
| 31 | const char *name; |
| 32 | uint size = 0; |
| 33 | int ret; |
| 34 | |
| 35 | if (argc < 2) |
| 36 | return CMD_RET_USAGE; |
| 37 | |
| 38 | if (uclass_first_device_err(UCLASS_VIDEO_CONSOLE, &dev)) |
| 39 | return CMD_RET_FAILURE; |
| 40 | name = argv[1]; |
| 41 | if (argc == 3) |
| 42 | size = dectoul(argv[2], NULL); |
| 43 | ret = vidconsole_select_font(dev, name, size); |
| 44 | if (ret) { |
| 45 | printf("Failed (error %d)\n", ret); |
| 46 | return CMD_RET_FAILURE; |
| 47 | } |
| 48 | |
| 49 | return 0; |
| 50 | } |
| 51 | static int do_font_size(struct cmd_tbl *cmdtp, int flag, int argc, |
| 52 | char *const argv[]) |
| 53 | { |
Simon Glass | 0e38bd8 | 2023-01-06 08:52:32 -0600 | [diff] [blame] | 54 | const char *font_name; |
Simon Glass | 430e167 | 2022-10-06 08:36:16 -0600 | [diff] [blame] | 55 | struct udevice *dev; |
| 56 | uint size; |
| 57 | int ret; |
| 58 | |
| 59 | if (argc != 2) |
| 60 | return CMD_RET_USAGE; |
| 61 | |
| 62 | if (uclass_first_device_err(UCLASS_VIDEO_CONSOLE, &dev)) |
| 63 | return CMD_RET_FAILURE; |
Dzmitry Sankouski | 4f6e348 | 2023-03-07 13:21:15 +0300 | [diff] [blame] | 64 | ret = vidconsole_get_font_size(dev, &font_name, &size); |
| 65 | if (ret) { |
| 66 | printf("Failed (error %d)\n", ret); |
| 67 | return CMD_RET_FAILURE; |
| 68 | } |
Simon Glass | 430e167 | 2022-10-06 08:36:16 -0600 | [diff] [blame] | 69 | |
| 70 | size = dectoul(argv[1], NULL); |
Simon Glass | 0e38bd8 | 2023-01-06 08:52:32 -0600 | [diff] [blame] | 71 | |
| 72 | ret = vidconsole_select_font(dev, font_name, size); |
Simon Glass | 430e167 | 2022-10-06 08:36:16 -0600 | [diff] [blame] | 73 | if (ret) { |
| 74 | printf("Failed (error %d)\n", ret); |
| 75 | return CMD_RET_FAILURE; |
| 76 | } |
| 77 | |
| 78 | return 0; |
| 79 | } |
| 80 | |
| 81 | |
Tom Rini | 3616218 | 2023-10-07 15:13:08 -0400 | [diff] [blame] | 82 | U_BOOT_LONGHELP(font, |
Simon Glass | 430e167 | 2022-10-06 08:36:16 -0600 | [diff] [blame] | 83 | "list - list available fonts\n" |
| 84 | "font select <name> [<size>] - select font to use\n" |
Tom Rini | 3616218 | 2023-10-07 15:13:08 -0400 | [diff] [blame] | 85 | "font size <size> - select font size to"); |
Simon Glass | 430e167 | 2022-10-06 08:36:16 -0600 | [diff] [blame] | 86 | |
| 87 | U_BOOT_CMD_WITH_SUBCMDS(font, "Fonts", font_help_text, |
| 88 | U_BOOT_SUBCMD_MKENT(list, 1, 1, do_font_list), |
| 89 | U_BOOT_SUBCMD_MKENT(select, 3, 1, do_font_select), |
| 90 | U_BOOT_SUBCMD_MKENT(size, 2, 1, do_font_size)); |