blob: 1a3416fb2a96afb5d631d2af277bdce184690a63 [file] [log] [blame]
Simon Glass3b65ee32019-12-06 21:41:54 -07001// SPDX-License-Identifier: GPL-2.0
2/*
3 * Intel PMC command
4 *
5 * Copyright 2019 Google LLC
6 */
7
Simon Glass3b65ee32019-12-06 21:41:54 -07008#include <command.h>
9#include <dm.h>
10#include <power/acpi_pmc.h>
11
12static int get_pmc_dev(struct udevice **devp)
13{
14 struct udevice *dev;
15 int ret;
16
17 ret = uclass_first_device_err(UCLASS_ACPI_PMC, &dev);
18 if (ret) {
19 printf("Could not find device (err=%d)\n", ret);
20 return ret;
21 }
22 ret = pmc_init(dev);
23 if (ret) {
24 printf("Could not init device (err=%d)\n", ret);
25 return ret;
26 }
27 *devp = dev;
28
29 return 0;
30}
31
Simon Glass09140112020-05-10 11:40:03 -060032static int do_pmc_init(struct cmd_tbl *cmdtp, int flag, int argc,
33 char *const argv[])
Simon Glass3b65ee32019-12-06 21:41:54 -070034{
35 struct udevice *dev;
36 int ret;
37
38 ret = get_pmc_dev(&dev);
39 if (ret)
40 return CMD_RET_FAILURE;
41
42 return 0;
43}
44
Simon Glass09140112020-05-10 11:40:03 -060045static int do_pmc_info(struct cmd_tbl *cmdtp, int flag, int argc,
46 char *const argv[])
Simon Glass3b65ee32019-12-06 21:41:54 -070047{
48 struct udevice *dev;
49 int ret;
50
51 ret = get_pmc_dev(&dev);
52 if (ret)
53 return CMD_RET_FAILURE;
54 pmc_dump_info(dev);
55
56 return 0;
57}
58
Simon Glass09140112020-05-10 11:40:03 -060059static struct cmd_tbl cmd_pmc_sub[] = {
Simon Glass3b65ee32019-12-06 21:41:54 -070060 U_BOOT_CMD_MKENT(init, 0, 1, do_pmc_init, "", ""),
61 U_BOOT_CMD_MKENT(info, 0, 1, do_pmc_info, "", ""),
62};
63
Simon Glass09140112020-05-10 11:40:03 -060064static int do_pmc(struct cmd_tbl *cmdtp, int flag, int argc, char *const argv[])
Simon Glass3b65ee32019-12-06 21:41:54 -070065{
Simon Glass09140112020-05-10 11:40:03 -060066 const struct cmd_tbl *cp;
Simon Glass3b65ee32019-12-06 21:41:54 -070067
68 if (argc < 2) /* no subcommand */
69 return cmd_usage(cmdtp);
70
71 cp = find_cmd_tbl(argv[1], &cmd_pmc_sub[0], ARRAY_SIZE(cmd_pmc_sub));
72 if (!cp)
73 return CMD_RET_USAGE;
74
75 return cp->cmd(cmdtp, flag, argc, argv);
76}
77
78U_BOOT_CMD(
79 pmc, 2, 1, do_pmc, "Power-management controller info",
80 "info - read state and show info about the PMC\n"
81 "pmc init - read state from the PMC\n"
82 );