blob: cafeba9fccdbfb6e7077f408f580919c5fe52abd [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
33static int do_pmc_init(cmd_tbl_t *cmdtp, int flag, int argc, char *const argv[])
34{
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
45static int do_pmc_info(cmd_tbl_t *cmdtp, int flag, int argc, char *const argv[])
46{
47 struct udevice *dev;
48 int ret;
49
50 ret = get_pmc_dev(&dev);
51 if (ret)
52 return CMD_RET_FAILURE;
53 pmc_dump_info(dev);
54
55 return 0;
56}
57
58static cmd_tbl_t cmd_pmc_sub[] = {
59 U_BOOT_CMD_MKENT(init, 0, 1, do_pmc_init, "", ""),
60 U_BOOT_CMD_MKENT(info, 0, 1, do_pmc_info, "", ""),
61};
62
63static int do_pmc(cmd_tbl_t *cmdtp, int flag, int argc, char *const argv[])
64{
65 const cmd_tbl_t *cp;
66
67 if (argc < 2) /* no subcommand */
68 return cmd_usage(cmdtp);
69
70 cp = find_cmd_tbl(argv[1], &cmd_pmc_sub[0], ARRAY_SIZE(cmd_pmc_sub));
71 if (!cp)
72 return CMD_RET_USAGE;
73
74 return cp->cmd(cmdtp, flag, argc, argv);
75}
76
77U_BOOT_CMD(
78 pmc, 2, 1, do_pmc, "Power-management controller info",
79 "info - read state and show info about the PMC\n"
80 "pmc init - read state from the PMC\n"
81 );