All of lore.kernel.org
 help / color / mirror / Atom feed
From: Simon Glass <sjg@chromium.org>
To: u-boot@lists.denx.de
Subject: [U-Boot] [PATCH v2 32/50] x86: sysreset: Implement power-off if available
Date: Thu, 25 Apr 2019 21:59:04 -0600	[thread overview]
Message-ID: <20190426035922.20596-33-sjg@chromium.org> (raw)
In-Reply-To: <20190426035922.20596-1-sjg@chromium.org>

On modern x86 devices we can power the system off using the power-
management features of the PCH. Add an implementation for this.

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

Changes in v2:
- Add new patch to implement power-off if available

 drivers/sysreset/sysreset_x86.c | 82 +++++++++++++++++++++++++++++++++
 1 file changed, 82 insertions(+)

diff --git a/drivers/sysreset/sysreset_x86.c b/drivers/sysreset/sysreset_x86.c
index d484ec5de49..bd759aa8bf4 100644
--- a/drivers/sysreset/sysreset_x86.c
+++ b/drivers/sysreset/sysreset_x86.c
@@ -7,14 +7,80 @@
 
 #include <common.h>
 #include <dm.h>
+#include <pch.h>
 #include <sysreset.h>
 #include <asm/io.h>
 #include <asm/processor.h>
 #include <efi_loader.h>
 
+struct x86_sysreset_platdata {
+	struct udevice *pch;
+};
+
+#define   PWRBTN_STS	(1 << 8)
+
+#define   SLP_EN	(1 << 13)
+#define   SLP_TYP	(7 << 10)
+#define    SLP_TYP_S5	7
+
+/*
+ * Power down the machine by using the power management sleep control
+ * of the chipset. This will currently only work on Intel chipsets.
+ * However, adapting it to new chipsets is fairly simple. You will
+ * have to find the IO address of the power management register block
+ * in your southbridge, and look up the appropriate SLP_TYP_S5 value
+ * from your southbridge's data sheet.
+ *
+ * This function never returns.
+ */
+int pch_sysreset_power_off(struct udevice *dev)
+{
+	struct x86_sysreset_platdata *plat = dev_get_platdata(dev);
+	struct pch_pmbase_info pm;
+	u32 reg32;
+	int ret;
+
+	if (!plat->pch)
+		return -ENOENT;
+	ret = pch_ioctl(plat->pch, PCH_REQ_PMBASE_INFO, &pm, sizeof(pm));
+	if (ret)
+		return ret;
+
+
+	/* Mask interrupts or system might stay in a coma
+	 * (not executing code anymore, but not powered off either)
+	 */
+	asm("cli");
+
+	/*
+	 * Avoid any GPI waking the system from S5* or the system might stay in
+	 * a coma
+	 */
+	outl(0x00000000, pm.base + pm.gpio0_en_ofs);
+
+	/* Clear Power Button Status */
+	outw(PWRBTN_STS, pm.base + pm.pm1_sts_ofs);
+
+	/* PMBASE + 4, Bit 10-12, Sleeping Type, * set to 111 -> S5, soft_off */
+	reg32 = inl(pm.base + pm.pm1_cnt_ofs);
+
+	/* Set Sleeping Type to S5 (poweroff) */
+	reg32 &= ~(SLP_EN | SLP_TYP);
+	reg32 |= SLP_TYP_S5;
+	outl(reg32, pm.base + pm.pm1_cnt_ofs);
+
+	/* Now set the Sleep Enable bit */
+	reg32 |= SLP_EN;
+	outl(reg32, pm.base + pm.pm1_cnt_ofs);
+
+	for (;;)
+		asm("hlt");
+}
+
 static int x86_sysreset_request(struct udevice *dev, enum sysreset_t type)
 {
 	int value;
+	int ret;
 
 	switch (type) {
 	case SYSRESET_WARM:
@@ -23,6 +89,11 @@ static int x86_sysreset_request(struct udevice *dev, enum sysreset_t type)
 	case SYSRESET_COLD:
 		value = SYS_RST | RST_CPU | FULL_RST;
 		break;
+	case SYSRESET_POWER_OFF:
+		ret = pch_sysreset_power_off(dev);
+		if (ret)
+			return ret;
+		return -EINPROGRESS;
 	default:
 		return -ENOSYS;
 	}
@@ -57,6 +128,15 @@ void __efi_runtime EFIAPI efi_reset_system(
 }
 #endif
 
+static int x86_sysreset_probe(struct udevice *dev)
+{
+	struct x86_sysreset_platdata *plat = dev_get_platdata(dev);
+
+	/* Locate the PCH if there is one. It isn't essential */
+	uclass_first_device(UCLASS_PCH, &plat->pch);
+
+	return 0;
+}
 
 static const struct udevice_id x86_sysreset_ids[] = {
 	{ .compatible = "x86,reset" },
@@ -72,4 +152,6 @@ U_BOOT_DRIVER(x86_sysreset) = {
 	.id = UCLASS_SYSRESET,
 	.of_match = x86_sysreset_ids,
 	.ops = &x86_sysreset_ops,
+	.probe = x86_sysreset_probe,
+	.platdata_auto_alloc_size	= sizeof(struct x86_sysreset_platdata),
 };
-- 
2.21.0.593.g511ec345e18-goog

  parent reply	other threads:[~2019-04-26  3:59 UTC|newest]

Thread overview: 113+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2019-04-26  3:58 [U-Boot] [PATCH v2 00/50] x86: Add support for booting from TPL Simon Glass
2019-04-26  3:58 ` [U-Boot] [PATCH v2 01/50] binman: Don't generate an error in 'text' entry constructor Simon Glass
2019-05-01 15:16   ` Bin Meng
2019-04-26  3:58 ` [U-Boot] [PATCH v2 02/50] binman: Don't show image-skip message by default Simon Glass
2019-05-01 11:59   ` Bin Meng
2019-05-01 15:16     ` Bin Meng
2019-04-26  3:58 ` [U-Boot] [PATCH v2 03/50] binman: Add a missing comment in Entry_vblock Simon Glass
2019-05-01 15:16   ` Bin Meng
2019-04-26  3:58 ` [U-Boot] [PATCH v2 04/50] dm: core: Fix translate condition in ofnode_get_addr_size() Simon Glass
2019-05-01 15:16   ` Bin Meng
2019-04-26  3:58 ` [U-Boot] [PATCH v2 05/50] cros_ec: Use a hyphen in the uclass name Simon Glass
2019-05-01 12:00   ` Bin Meng
2019-05-02 16:53     ` Simon Glass
2019-04-26  3:58 ` [U-Boot] [PATCH v2 06/50] spl: Allow sandbox to build a device-tree file Simon Glass
2019-05-01 12:13   ` Bin Meng
2019-05-01 15:16     ` Bin Meng
2019-04-26  3:58 ` [U-Boot] [PATCH v2 07/50] binman: Allow sections to have an offset Simon Glass
2019-05-01 12:13   ` Bin Meng
2019-05-01 15:16     ` Bin Meng
2019-04-26  3:58 ` [U-Boot] [PATCH v2 08/50] x86: start64: Fix copyright message Simon Glass
2019-05-01 15:16   ` Bin Meng
2019-04-26  3:58 ` [U-Boot] [PATCH v2 09/50] x86: mp_init: Use proper error numbers Simon Glass
2019-05-01 15:16   ` Bin Meng
2019-04-26  3:58 ` [U-Boot] [PATCH v2 10/50] x86: Add a way to reinit the cpu Simon Glass
2019-05-01 15:16   ` Bin Meng
2019-04-26  3:58 ` [U-Boot] [PATCH v2 11/50] x86: dts: Add device-tree labels for rtc and reset Simon Glass
2019-05-01 15:25   ` Bin Meng
2019-04-26  3:58 ` [U-Boot] [PATCH v2 12/50] x86: Update a stale comment about ifdtool Simon Glass
2019-05-01 15:25   ` Bin Meng
2019-04-26  3:58 ` [U-Boot] [PATCH v2 13/50] x86: Support SPL and TPL Simon Glass
2019-05-01 15:25   ` Bin Meng
2019-04-26  3:58 ` [U-Boot] [PATCH v2 14/50] x86: Support booting with TPL Simon Glass
2019-05-01 15:25   ` Bin Meng
2019-04-26  3:58 ` [U-Boot] [PATCH v2 15/50] x86: Add a handoff header file Simon Glass
2019-05-01 15:25   ` Bin Meng
2019-04-26  3:58 ` [U-Boot] [PATCH v2 16/50] x86: broadwell: Improve SDRAM debugging output Simon Glass
2019-05-01 15:25   ` Bin Meng
2019-04-26  3:58 ` [U-Boot] [PATCH v2 17/50] x86: broadwell: Allow SDRAM init from SPL Simon Glass
2019-05-01 13:03   ` Bin Meng
2019-05-01 15:25     ` Bin Meng
2019-04-26  3:58 ` [U-Boot] [PATCH v2 18/50] x86: Move init of debug UART to cpu.c Simon Glass
2019-05-01 15:25   ` Bin Meng
2019-04-26  3:58 ` [U-Boot] [PATCH v2 19/50] x86: broadwell: Split CPU init Simon Glass
2019-05-01 15:25   ` Bin Meng
2019-04-26  3:58 ` [U-Boot] [PATCH v2 20/50] x86: Add support for starting from SPL/TPL Simon Glass
2019-05-01 13:03   ` Bin Meng
2019-05-01 15:25     ` Bin Meng
2019-04-26  3:58 ` [U-Boot] [PATCH v2 21/50] x86: Allow 16-bit init to be in TPL Simon Glass
2019-05-01 15:34   ` Bin Meng
2019-04-26  3:58 ` [U-Boot] [PATCH v2 22/50] x86: broadwell: Allow booting from SPL Simon Glass
2019-05-01 15:34   ` Bin Meng
2019-04-26  3:58 ` [U-Boot] [PATCH v2 23/50] x86: broadwell: Select refcode and CPU code for SPL Simon Glass
2019-05-01 15:35   ` Bin Meng
2019-04-26  3:58 ` [U-Boot] [PATCH v2 24/50] x86: Add common Intel " Simon Glass
2019-05-01 15:35   ` Bin Meng
2019-04-26  3:58 ` [U-Boot] [PATCH v2 25/50] x86: Support saving MRC data from SPL Simon Glass
2019-05-01 15:35   ` Bin Meng
2019-04-26  3:58 ` [U-Boot] [PATCH v2 26/50] x86: Add a simple TPL implementation Simon Glass
2019-05-01 15:35   ` Bin Meng
2019-04-26  3:58 ` [U-Boot] [PATCH v2 27/50] x86: mrccache: Add more debugging Simon Glass
2019-05-01 15:35   ` Bin Meng
2019-04-26  3:59 ` [U-Boot] [PATCH v2 28/50] x86: sysreset: Separate out the EFI code Simon Glass
2019-05-01 13:42   ` Bin Meng
2019-05-01 18:56     ` Heinrich Schuchardt
2019-04-26  3:59 ` [U-Boot] [PATCH v2 29/50] x86: pch: Add an ioctl to read power-management info Simon Glass
2019-05-01 13:42   ` Bin Meng
2019-05-01 15:43     ` Bin Meng
2019-04-26  3:59 ` [U-Boot] [PATCH v2 30/50] x86: ivybridge: Implement PCH_REQ_PMBASE_INFO Simon Glass
2019-05-01 13:42   ` Bin Meng
2019-05-01 15:43     ` Bin Meng
2019-04-26  3:59 ` [U-Boot] [PATCH v2 31/50] x86: broadwell: " Simon Glass
2019-05-01 14:50   ` Bin Meng
2019-05-01 15:43     ` Bin Meng
2019-04-26  3:59 ` Simon Glass [this message]
2019-05-01 14:50   ` [U-Boot] [PATCH v2 32/50] x86: sysreset: Implement power-off if available Bin Meng
2019-04-26  3:59 ` [U-Boot] [PATCH v2 33/50] x86: Support TPL in Intel common code Simon Glass
2019-05-01 15:44   ` Bin Meng
2019-04-26  3:59 ` [U-Boot] [PATCH v2 34/50] x86: Don't set up MTRRs in SPL Simon Glass
2019-05-01 15:44   ` Bin Meng
2019-04-26  3:59 ` [U-Boot] [PATCH v2 35/50] x86: Don't generate a bootstage report " Simon Glass
2019-05-01 15:44   ` Bin Meng
2019-04-26  3:59 ` [U-Boot] [PATCH v2 36/50] x86: Support PCI VGA ROM when TPL is used Simon Glass
2019-05-01 15:44   ` Bin Meng
2019-04-26  3:59 ` [U-Boot] [PATCH v2 37/50] x86: sysreset: Implement the get_last() method Simon Glass
2019-05-01 15:48   ` Bin Meng
2019-04-26  3:59 ` [U-Boot] [PATCH v2 38/50] x86: Add documention on the samus flashmap Simon Glass
2019-04-26  3:59 ` [U-Boot] [PATCH v2 39/50] x86: samus: Update device tree for SPL Simon Glass
2019-05-01 15:52   ` Bin Meng
2019-04-26  3:59 ` [U-Boot] [PATCH v2 40/50] x86: samus: Update device tree for verified boot Simon Glass
2019-04-26  3:59 ` [U-Boot] [PATCH v2 41/50] x86: Update device tree for TPL Simon Glass
2019-05-01 16:00   ` Bin Meng
2019-04-26  3:59 ` [U-Boot] [PATCH v2 42/50] x86: Update device tree for Chromium OS verified boot Simon Glass
2019-04-26  3:59 ` [U-Boot] [PATCH v2 43/50] x86: Fix device-tree indentation Simon Glass
2019-04-26  3:59 ` [U-Boot] [PATCH v2 44/50] x86: samus: Increase the pre-reloc memory again Simon Glass
2019-04-26  3:59 ` [U-Boot] [PATCH v2 45/50] Revert "pci: Scale MAX_PCI_REGIONS based on CONFIG_NR_DRAM_BANKS" Simon Glass
2019-05-01 16:09   ` Bin Meng
2019-05-02  9:24     ` Thierry Reding
2019-05-02 16:22       ` Simon Glass
2019-05-07  9:28         ` Bin Meng
2019-05-08  3:04           ` Simon Glass
2019-05-08  3:25             ` Bin Meng
2019-05-09 15:34             ` Thierry Reding
2019-04-26  3:59 ` [U-Boot] [PATCH v2 46/50] x86: Enable the RTC on all boards Simon Glass
2019-05-01 16:17   ` Bin Meng
2019-04-26  3:59 ` [U-Boot] [PATCH v2 47/50] x86: Update the memory map a little Simon Glass
2019-05-01 16:17   ` Bin Meng
2019-04-26  3:59 ` [U-Boot] [PATCH v2 48/50] x86: broadwell: Update PCH to work in TPL Simon Glass
2019-05-01 16:17   ` Bin Meng
2019-04-26  3:59 ` [U-Boot] [PATCH v2 49/50] x86: Add a way to jump from TPL to SPL Simon Glass
2019-05-01 16:17   ` Bin Meng
2019-05-02 16:53     ` Simon Glass
2019-04-26  3:59 ` [U-Boot] [PATCH v2 50/50] x86: samus: Add a target to boot through TPL Simon Glass
2019-05-01 16:20 ` [U-Boot] [PATCH v2 00/50] x86: Add support for booting from TPL Bin Meng

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20190426035922.20596-33-sjg@chromium.org \
    --to=sjg@chromium.org \
    --cc=u-boot@lists.denx.de \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.