Simon Glass | 8c50102 | 2019-12-06 21:41:54 -0700 | [diff] [blame] | 1 | // 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 | |
| 13 | static 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 Glass | ed38aef | 2020-05-10 11:40:03 -0600 | [diff] [blame] | 33 | static int do_pmc_init(struct cmd_tbl *cmdtp, int flag, int argc, |
| 34 | char *const argv[]) |
Simon Glass | 8c50102 | 2019-12-06 21:41:54 -0700 | [diff] [blame] | 35 | { |
| 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 Glass | ed38aef | 2020-05-10 11:40:03 -0600 | [diff] [blame] | 46 | static int do_pmc_info(struct cmd_tbl *cmdtp, int flag, int argc, |
| 47 | char *const argv[]) |
Simon Glass | 8c50102 | 2019-12-06 21:41:54 -0700 | [diff] [blame] | 48 | { |
| 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 Glass | ed38aef | 2020-05-10 11:40:03 -0600 | [diff] [blame] | 60 | static struct cmd_tbl cmd_pmc_sub[] = { |
Simon Glass | 8c50102 | 2019-12-06 21:41:54 -0700 | [diff] [blame] | 61 | U_BOOT_CMD_MKENT(init, 0, 1, do_pmc_init, "", ""), |
| 62 | U_BOOT_CMD_MKENT(info, 0, 1, do_pmc_info, "", ""), |
| 63 | }; |
| 64 | |
Simon Glass | ed38aef | 2020-05-10 11:40:03 -0600 | [diff] [blame] | 65 | static int do_pmc(struct cmd_tbl *cmdtp, int flag, int argc, char *const argv[]) |
Simon Glass | 8c50102 | 2019-12-06 21:41:54 -0700 | [diff] [blame] | 66 | { |
Simon Glass | ed38aef | 2020-05-10 11:40:03 -0600 | [diff] [blame] | 67 | const struct cmd_tbl *cp; |
Simon Glass | 8c50102 | 2019-12-06 21:41:54 -0700 | [diff] [blame] | 68 | |
| 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 | |
| 79 | U_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 | ); |