blob: eb13fb12f79883cabf32b0099ac8b09a3dce6a41 [file] [log] [blame]
Simon Glass9e972c32022-10-06 08:36:16 -06001// 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 Glass9e972c32022-10-06 08:36:16 -06009#include <command.h>
10#include <dm.h>
11#include <video.h>
12#include <video_console.h>
13
14static int do_font_list(struct cmd_tbl *cmdtp, int flag, int argc,
15 char *const argv[])
16{
Simon Glass3b175ba2023-01-06 08:52:32 -060017 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 Glass9e972c32022-10-06 08:36:16 -060022
23 return 0;
24}
25
26static 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}
50static int do_font_size(struct cmd_tbl *cmdtp, int flag, int argc,
51 char *const argv[])
52{
Simon Glass3b175ba2023-01-06 08:52:32 -060053 const char *font_name;
Simon Glass9e972c32022-10-06 08:36:16 -060054 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 Sankouski86c6a532023-03-07 13:21:15 +030063 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 Glass9e972c32022-10-06 08:36:16 -060068
69 size = dectoul(argv[1], NULL);
Simon Glass3b175ba2023-01-06 08:52:32 -060070
71 ret = vidconsole_select_font(dev, font_name, size);
Simon Glass9e972c32022-10-06 08:36:16 -060072 if (ret) {
73 printf("Failed (error %d)\n", ret);
74 return CMD_RET_FAILURE;
75 }
76
77 return 0;
78}
79
Tom Rini03f146c2023-10-07 15:13:08 -040080U_BOOT_LONGHELP(font,
Simon Glass9e972c32022-10-06 08:36:16 -060081 "list - list available fonts\n"
82 "font select <name> [<size>] - select font to use\n"
Tom Rini03f146c2023-10-07 15:13:08 -040083 "font size <size> - select font size to");
Simon Glass9e972c32022-10-06 08:36:16 -060084
85U_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));