Merge tag 'xilinx-for-v2025.01-rc3-v2' of https://source.denx.de/u-boot/custodians...
[u-boot.git] / cmd / pmc.c
blob1a3416fb2a96afb5d631d2af277bdce184690a63
1 // SPDX-License-Identifier: GPL-2.0
2 /*
3 * Intel PMC command
5 * Copyright 2019 Google LLC
6 */
8 #include <command.h>
9 #include <dm.h>
10 #include <power/acpi_pmc.h>
12 static int get_pmc_dev(struct udevice **devp)
14 struct udevice *dev;
15 int ret;
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;
22 ret = pmc_init(dev);
23 if (ret) {
24 printf("Could not init device (err=%d)\n", ret);
25 return ret;
27 *devp = dev;
29 return 0;
32 static int do_pmc_init(struct cmd_tbl *cmdtp, int flag, int argc,
33 char *const argv[])
35 struct udevice *dev;
36 int ret;
38 ret = get_pmc_dev(&dev);
39 if (ret)
40 return CMD_RET_FAILURE;
42 return 0;
45 static int do_pmc_info(struct cmd_tbl *cmdtp, int flag, int argc,
46 char *const argv[])
48 struct udevice *dev;
49 int ret;
51 ret = get_pmc_dev(&dev);
52 if (ret)
53 return CMD_RET_FAILURE;
54 pmc_dump_info(dev);
56 return 0;
59 static struct cmd_tbl cmd_pmc_sub[] = {
60 U_BOOT_CMD_MKENT(init, 0, 1, do_pmc_init, "", ""),
61 U_BOOT_CMD_MKENT(info, 0, 1, do_pmc_info, "", ""),
64 static int do_pmc(struct cmd_tbl *cmdtp, int flag, int argc, char *const argv[])
66 const struct cmd_tbl *cp;
68 if (argc < 2) /* no subcommand */
69 return cmd_usage(cmdtp);
71 cp = find_cmd_tbl(argv[1], &cmd_pmc_sub[0], ARRAY_SIZE(cmd_pmc_sub));
72 if (!cp)
73 return CMD_RET_USAGE;
75 return cp->cmd(cmdtp, flag, argc, argv);
78 U_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"