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 | |
Simon Glass | 9e972c3 | 2022-10-06 08:36:16 -0600 | [diff] [blame] | 58 | if (uclass_first_device_err(UCLASS_VIDEO_CONSOLE, &dev)) |
| 59 | return CMD_RET_FAILURE; |
Dzmitry Sankouski | 86c6a53 | 2023-03-07 13:21:15 +0300 | [diff] [blame] | 60 | ret = vidconsole_get_font_size(dev, &font_name, &size); |
| 61 | if (ret) { |
| 62 | printf("Failed (error %d)\n", ret); |
| 63 | return CMD_RET_FAILURE; |
| 64 | } |
Simon Glass | 9e972c3 | 2022-10-06 08:36:16 -0600 | [diff] [blame] | 65 | |
Simon Glass | 4f0336d | 2024-01-07 17:14:54 -0700 | [diff] [blame] | 66 | if (argc < 2) { |
| 67 | printf("%d\n", size); |
| 68 | } else { |
| 69 | size = dectoul(argv[1], NULL); |
Simon Glass | 3b175ba | 2023-01-06 08:52:32 -0600 | [diff] [blame] | 70 | |
Simon Glass | 4f0336d | 2024-01-07 17:14:54 -0700 | [diff] [blame] | 71 | ret = vidconsole_select_font(dev, font_name, size); |
| 72 | if (ret) { |
| 73 | printf("Failed (error %d)\n", ret); |
| 74 | return CMD_RET_FAILURE; |
| 75 | } |
Simon Glass | 9e972c3 | 2022-10-06 08:36:16 -0600 | [diff] [blame] | 76 | } |
| 77 | |
| 78 | return 0; |
| 79 | } |
| 80 | |
Tom Rini | 03f146c | 2023-10-07 15:13:08 -0400 | [diff] [blame] | 81 | U_BOOT_LONGHELP(font, |
Simon Glass | 9e972c3 | 2022-10-06 08:36:16 -0600 | [diff] [blame] | 82 | "list - list available fonts\n" |
| 83 | "font select <name> [<size>] - select font to use\n" |
Tom Rini | 03f146c | 2023-10-07 15:13:08 -0400 | [diff] [blame] | 84 | "font size <size> - select font size to"); |
Simon Glass | 9e972c3 | 2022-10-06 08:36:16 -0600 | [diff] [blame] | 85 | |
| 86 | U_BOOT_CMD_WITH_SUBCMDS(font, "Fonts", font_help_text, |
| 87 | U_BOOT_SUBCMD_MKENT(list, 1, 1, do_font_list), |
| 88 | U_BOOT_SUBCMD_MKENT(select, 3, 1, do_font_select), |
| 89 | U_BOOT_SUBCMD_MKENT(size, 2, 1, do_font_size)); |