blob: 9a3ba2bffc50041f61c0a21f11af0b5c4ac8cefe [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
8#include <common.h>
9#include <command.h>
10#include <dm.h>
11#include <power/acpi_pmc.h>
12
13static int get_pmc_dev(struct udevice **devp)
14{
15 struct udevice *dev;
16 int ret;
17
18 ret = uclass_first_device_err(UCLASS_ACPI_PMC, &dev);
19 if (ret) {
20 printf("Could not find device (err=%d)\n", ret);
21 return ret;
22 }
23 ret = pmc_init(dev);
24 if (ret) {
25 printf("Could not init device (err=%d)\n", ret);
26 return ret;
27 }
28 *devp = dev;
29
30 return 0;
31}
32
Simon Glass09140112020-05-10 11:40:03 -060033static int do_pmc_init(struct cmd_tbl *cmdtp, int flag, int argc,
34 char *const argv[])
Simon Glass3b65ee32019-12-06 21:41:54 -070035{
36 struct udevice *dev;
37 int ret;
38
39 ret = get_pmc_dev(&dev);
40 if (ret)
41 return CMD_RET_FAILURE;
42
43 return 0;
44}
45
Simon Glass09140112020-05-10 11:40:03 -060046static int do_pmc_info(struct cmd_tbl *cmdtp, int flag, int argc,
47 char *const argv[])
Simon Glass3b65ee32019-12-06 21:41:54 -070048{
49 struct udevice *dev;
50 int ret;
51
52 ret = get_pmc_dev(&dev);
53 if (ret)
54 return CMD_RET_FAILURE;
55 pmc_dump_info(dev);
56
57 return 0;
58}
59
Simon Glass09140112020-05-10 11:40:03 -060060static struct cmd_tbl cmd_pmc_sub[] = {
Simon Glass3b65ee32019-12-06 21:41:54 -070061 U_BOOT_CMD_MKENT(init, 0, 1, do_pmc_init, "", ""),
62 U_BOOT_CMD_MKENT(info, 0, 1, do_pmc_info, "", ""),
63};
64
Simon Glass09140112020-05-10 11:40:03 -060065static int do_pmc(struct cmd_tbl *cmdtp, int flag, int argc, char *const argv[])
Simon Glass3b65ee32019-12-06 21:41:54 -070066{
Simon Glass09140112020-05-10 11:40:03 -060067 const struct cmd_tbl *cp;
Simon Glass3b65ee32019-12-06 21:41:54 -070068
69 if (argc < 2) /* no subcommand */
70 return cmd_usage(cmdtp);
71
72 cp = find_cmd_tbl(argv[1], &cmd_pmc_sub[0], ARRAY_SIZE(cmd_pmc_sub));
73 if (!cp)
74 return CMD_RET_USAGE;
75
76 return cp->cmd(cmdtp, flag, argc, argv);
77}
78
79U_BOOT_CMD(
80 pmc, 2, 1, do_pmc, "Power-management controller info",
81 "info - read state and show info about the PMC\n"
82 "pmc init - read state from the PMC\n"
83 );