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