diff mbox series

[U-Boot,v3,035/108] x86: power: Add a 'pmc' command

Message ID 20191021033913.220758-35-sjg@chromium.org
State Superseded
Delegated to: Bin Meng
Headers show
Series x86: Add initial support for apollolake | expand

Commit Message

Simon Glass Oct. 21, 2019, 3:38 a.m. UTC
Add a simple command to show information about the PMC.

Signed-off-by: Simon Glass <sjg@chromium.org>
---

Changes in v3:
- Rename power-mgr uclass to acpi-pmc

Changes in v2: None

 arch/Kconfig |  1 +
 cmd/Kconfig  |  8 ++++++
 cmd/Makefile |  1 +
 cmd/pmc.c    | 81 ++++++++++++++++++++++++++++++++++++++++++++++++++++
 4 files changed, 91 insertions(+)
 create mode 100644 cmd/pmc.c

Comments

Andy Shevchenko Oct. 21, 2019, 7:48 a.m. UTC | #1
On Mon, Oct 21, 2019 at 7:26 AM Simon Glass <sjg@chromium.org> wrote:
>
> Add a simple command to show information about the PMC.

PMC is a part of almost all Intel Atom SoCs. Can you describe how can
it be utilized for example in case of Tangier?
Simon Glass Oct. 21, 2019, 10:53 p.m. UTC | #2
Hi Andy,

On Mon, 21 Oct 2019 at 01:49, Andy Shevchenko <andy.shevchenko@gmail.com> wrote:
>
> On Mon, Oct 21, 2019 at 7:26 AM Simon Glass <sjg@chromium.org> wrote:
> >
> > Add a simple command to show information about the PMC.
>
> PMC is a part of almost all Intel Atom SoCs. Can you describe how can
> it be utilized for example in case of Tangier?

Well if the driver is enabled then I expect the 'pmc info' command
could be used there?

Regards,
SImon
Andy Shevchenko Oct. 22, 2019, 8:21 a.m. UTC | #3
On Tue, Oct 22, 2019 at 1:54 AM Simon Glass <sjg@chromium.org> wrote:
> On Mon, 21 Oct 2019 at 01:49, Andy Shevchenko <andy.shevchenko@gmail.com> wrote:
> >
> > On Mon, Oct 21, 2019 at 7:26 AM Simon Glass <sjg@chromium.org> wrote:
> > >
> > > Add a simple command to show information about the PMC.
> >
> > PMC is a part of almost all Intel Atom SoCs. Can you describe how can
> > it be utilized for example in case of Tangier?
>
> Well if the driver is enabled then I expect the 'pmc info' command
> could be used there?

PMC is unique to a platform / SoC. My question here is to provide some
skeleton / Documentation how other (non-APL) SoC drivers can enable
`pmc info` etc.
Simon Glass Oct. 22, 2019, 1:50 p.m. UTC | #4
Hi Andy,

On Tue, 22 Oct 2019 at 02:21, Andy Shevchenko <andy.shevchenko@gmail.com> wrote:
>
> On Tue, Oct 22, 2019 at 1:54 AM Simon Glass <sjg@chromium.org> wrote:
> > On Mon, 21 Oct 2019 at 01:49, Andy Shevchenko <andy.shevchenko@gmail.com> wrote:
> > >
> > > On Mon, Oct 21, 2019 at 7:26 AM Simon Glass <sjg@chromium.org> wrote:
> > > >
> > > > Add a simple command to show information about the PMC.
> > >
> > > PMC is a part of almost all Intel Atom SoCs. Can you describe how can
> > > it be utilized for example in case of Tangier?
> >
> > Well if the driver is enabled then I expect the 'pmc info' command
> > could be used there?
>
> PMC is unique to a platform / SoC. My question here is to provide some
> skeleton / Documentation how other (non-APL) SoC drivers can enable
> `pmc info` etc.

OK I see. I suspect that there might be some common fields but also
some fields specific to each SoC.

My expectation is that we would print out whatever of these fields
seems useful/suitable. Does that sound reasonable?

Regards,
Simon
diff mbox series

Patch

diff --git a/arch/Kconfig b/arch/Kconfig
index 8094e186636..e1f1fcd275b 100644
--- a/arch/Kconfig
+++ b/arch/Kconfig
@@ -135,6 +135,7 @@  config SANDBOX
 	imply DM_MDIO_MUX
 	imply ACPI_PMC
 	imply ACPI_PMC_SANDBOX
+	imply CMD_PMC
 
 config SH
 	bool "SuperH architecture"
diff --git a/cmd/Kconfig b/cmd/Kconfig
index 07060c63a7e..135b38b0260 100644
--- a/cmd/Kconfig
+++ b/cmd/Kconfig
@@ -228,6 +228,14 @@  config CMD_LICENSE
 	help
 	  Print GPL license text
 
+config CMD_PMC
+	bool "pmc"
+	help
+	  Provides access to the Intel Power-Management Controller (PMC) so
+	  that its state can be examined. This does not currently support
+	  changing the state but it is still useful for debugging and seeing
+	  what is going on.
+
 config CMD_REGINFO
 	bool "reginfo"
 	depends on PPC
diff --git a/cmd/Makefile b/cmd/Makefile
index ac843b4b16a..8151ba8741f 100644
--- a/cmd/Makefile
+++ b/cmd/Makefile
@@ -108,6 +108,7 @@  ifdef CONFIG_PCI
 obj-$(CONFIG_CMD_PCI) += pci.o
 endif
 obj-$(CONFIG_CMD_PINMUX) += pinmux.o
+obj-$(CONFIG_CMD_PMC) += pmc.o
 obj-$(CONFIG_CMD_PXE) += pxe.o
 obj-$(CONFIG_CMD_WOL) += wol.o
 obj-$(CONFIG_CMD_QFW) += qfw.o
diff --git a/cmd/pmc.c b/cmd/pmc.c
new file mode 100644
index 00000000000..cafeba9fccd
--- /dev/null
+++ b/cmd/pmc.c
@@ -0,0 +1,81 @@ 
+// SPDX-License-Identifier: GPL-2.0
+/*
+ * Intel PMC command
+ *
+ * Copyright 2019 Google LLC
+ */
+
+#include <common.h>
+#include <command.h>
+#include <dm.h>
+#include <power/acpi_pmc.h>
+
+static int get_pmc_dev(struct udevice **devp)
+{
+	struct udevice *dev;
+	int ret;
+
+	ret = uclass_first_device_err(UCLASS_ACPI_PMC, &dev);
+	if (ret) {
+		printf("Could not find device (err=%d)\n", ret);
+		return ret;
+	}
+	ret = pmc_init(dev);
+	if (ret) {
+		printf("Could not init device (err=%d)\n", ret);
+		return ret;
+	}
+	*devp = dev;
+
+	return 0;
+}
+
+static int do_pmc_init(cmd_tbl_t *cmdtp, int flag, int argc, char *const argv[])
+{
+	struct udevice *dev;
+	int ret;
+
+	ret = get_pmc_dev(&dev);
+	if (ret)
+		return CMD_RET_FAILURE;
+
+	return 0;
+}
+
+static int do_pmc_info(cmd_tbl_t *cmdtp, int flag, int argc, char *const argv[])
+{
+	struct udevice *dev;
+	int ret;
+
+	ret = get_pmc_dev(&dev);
+	if (ret)
+		return CMD_RET_FAILURE;
+	pmc_dump_info(dev);
+
+	return 0;
+}
+
+static cmd_tbl_t cmd_pmc_sub[] = {
+	U_BOOT_CMD_MKENT(init, 0, 1, do_pmc_init, "", ""),
+	U_BOOT_CMD_MKENT(info, 0, 1, do_pmc_info, "", ""),
+};
+
+static int do_pmc(cmd_tbl_t *cmdtp, int flag, int argc, char *const argv[])
+{
+	const cmd_tbl_t *cp;
+
+	if (argc < 2) /* no subcommand */
+		return cmd_usage(cmdtp);
+
+	cp = find_cmd_tbl(argv[1], &cmd_pmc_sub[0], ARRAY_SIZE(cmd_pmc_sub));
+	if (!cp)
+		return CMD_RET_USAGE;
+
+	return cp->cmd(cmdtp, flag, argc, argv);
+}
+
+U_BOOT_CMD(
+	pmc, 2, 1, do_pmc, "Power-management controller info",
+	"info - read state and show info about the PMC\n"
+	"pmc init - read state from the PMC\n"
+	);