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 | |
Simon Glass | 8c50102 | 2019-12-06 21:41:54 -0700 | [diff] [blame] | 8 | #include <command.h> |
| 9 | #include <dm.h> |
| 10 | #include <power/acpi_pmc.h> |
| 11 | |
| 12 | static 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 Glass | ed38aef | 2020-05-10 11:40:03 -0600 | [diff] [blame] | 32 | static int do_pmc_init(struct cmd_tbl *cmdtp, int flag, int argc, |
| 33 | char *const argv[]) |
Simon Glass | 8c50102 | 2019-12-06 21:41:54 -0700 | [diff] [blame] | 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 | |
Simon Glass | ed38aef | 2020-05-10 11:40:03 -0600 | [diff] [blame] | 45 | static int do_pmc_info(struct cmd_tbl *cmdtp, int flag, int argc, |
| 46 | char *const argv[]) |
Simon Glass | 8c50102 | 2019-12-06 21:41:54 -0700 | [diff] [blame] | 47 | { |
| 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 Glass | ed38aef | 2020-05-10 11:40:03 -0600 | [diff] [blame] | 59 | static struct cmd_tbl cmd_pmc_sub[] = { |
Simon Glass | 8c50102 | 2019-12-06 21:41:54 -0700 | [diff] [blame] | 60 | U_BOOT_CMD_MKENT(init, 0, 1, do_pmc_init, "", ""), |
| 61 | U_BOOT_CMD_MKENT(info, 0, 1, do_pmc_info, "", ""), |
| 62 | }; |
| 63 | |
Simon Glass | ed38aef | 2020-05-10 11:40:03 -0600 | [diff] [blame] | 64 | 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] | 65 | { |
Simon Glass | ed38aef | 2020-05-10 11:40:03 -0600 | [diff] [blame] | 66 | const struct cmd_tbl *cp; |
Simon Glass | 8c50102 | 2019-12-06 21:41:54 -0700 | [diff] [blame] | 67 | |
| 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 | |
| 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" |
| 82 | ); |