aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorPaul Burton <paul.burton@imgtec.com>2016-09-28 11:30:56 -0400
committerSebastian Reichel <sre@kernel.org>2016-10-17 23:13:37 -0400
commit29676833df1d9207cb665fe9869f6778a96045b9 (patch)
tree9c666239a17e2b65adc328bfb36514fa95d895f8
parent1001354ca34179f3db924eb66672442a173147dc (diff)
power: reset: Add Intel PIIX4 poweroff driver
Add a driver which allows powering off the system via an Intel PIIX4 southbridge, by entering the PIIX4 SOff state. This is useful on the MIPS Malta development board, where it will power down the FPGA based board until its ON/NMI button is pressed, or the QEMU implementation of the MIPS Malta board where it will cause QEMU to exit. Signed-off-by: Paul Burton <paul.burton@imgtec.com> Cc: Sebastian Reichel <sre@kernel.org> Cc: Dmitry Eremin-Solenikov <dbaryshkov@gmail.com> Cc: David Woodhouse <dwmw2@infradead.org> Cc: linux-pm@vger.kernel.org Signed-off-by: Sebastian Reichel <sre@kernel.org>
-rw-r--r--drivers/power/reset/Kconfig10
-rw-r--r--drivers/power/reset/Makefile1
-rw-r--r--drivers/power/reset/piix4-poweroff.c113
3 files changed, 124 insertions, 0 deletions
diff --git a/drivers/power/reset/Kconfig b/drivers/power/reset/Kconfig
index c74c3f67b8da..abeb77217a21 100644
--- a/drivers/power/reset/Kconfig
+++ b/drivers/power/reset/Kconfig
@@ -104,6 +104,16 @@ config POWER_RESET_MSM
104 help 104 help
105 Power off and restart support for Qualcomm boards. 105 Power off and restart support for Qualcomm boards.
106 106
107config POWER_RESET_PIIX4_POWEROFF
108 tristate "Intel PIIX4 power-off driver"
109 depends on PCI
110 depends on MIPS || COMPILE_TEST
111 help
112 This driver supports powering off a system using the Intel PIIX4
113 southbridge, for example the MIPS Malta development board. The
114 southbridge SOff state is entered in response to a request to
115 power off the system.
116
107config POWER_RESET_LTC2952 117config POWER_RESET_LTC2952
108 bool "LTC2952 PowerPath power-off driver" 118 bool "LTC2952 PowerPath power-off driver"
109 depends on OF_GPIO 119 depends on OF_GPIO
diff --git a/drivers/power/reset/Makefile b/drivers/power/reset/Makefile
index 1be307c7fc25..11dae3b56ff9 100644
--- a/drivers/power/reset/Makefile
+++ b/drivers/power/reset/Makefile
@@ -10,6 +10,7 @@ obj-$(CONFIG_POWER_RESET_GPIO_RESTART) += gpio-restart.o
10obj-$(CONFIG_POWER_RESET_HISI) += hisi-reboot.o 10obj-$(CONFIG_POWER_RESET_HISI) += hisi-reboot.o
11obj-$(CONFIG_POWER_RESET_IMX) += imx-snvs-poweroff.o 11obj-$(CONFIG_POWER_RESET_IMX) += imx-snvs-poweroff.o
12obj-$(CONFIG_POWER_RESET_MSM) += msm-poweroff.o 12obj-$(CONFIG_POWER_RESET_MSM) += msm-poweroff.o
13obj-$(CONFIG_POWER_RESET_PIIX4_POWEROFF) += piix4-poweroff.o
13obj-$(CONFIG_POWER_RESET_LTC2952) += ltc2952-poweroff.o 14obj-$(CONFIG_POWER_RESET_LTC2952) += ltc2952-poweroff.o
14obj-$(CONFIG_POWER_RESET_QNAP) += qnap-poweroff.o 15obj-$(CONFIG_POWER_RESET_QNAP) += qnap-poweroff.o
15obj-$(CONFIG_POWER_RESET_RESTART) += restart-poweroff.o 16obj-$(CONFIG_POWER_RESET_RESTART) += restart-poweroff.o
diff --git a/drivers/power/reset/piix4-poweroff.c b/drivers/power/reset/piix4-poweroff.c
new file mode 100644
index 000000000000..bacfc95783f0
--- /dev/null
+++ b/drivers/power/reset/piix4-poweroff.c
@@ -0,0 +1,113 @@
1/*
2 * Copyright (C) 2016 Imagination Technologies
3 * Author: Paul Burton <paul.burton@imgtec.com>
4 *
5 * This program is free software; you can redistribute it and/or modify it
6 * under the terms of the GNU General Public License as published by the
7 * Free Software Foundation; either version 2 of the License, or (at your
8 * option) any later version.
9 */
10
11#include <linux/delay.h>
12#include <linux/io.h>
13#include <linux/module.h>
14#include <linux/pci.h>
15#include <linux/pm.h>
16
17static struct pci_dev *pm_dev;
18static resource_size_t io_offset;
19
20enum piix4_pm_io_reg {
21 PIIX4_FUNC3IO_PMSTS = 0x00,
22#define PIIX4_FUNC3IO_PMSTS_PWRBTN_STS BIT(8)
23 PIIX4_FUNC3IO_PMCNTRL = 0x04,
24#define PIIX4_FUNC3IO_PMCNTRL_SUS_EN BIT(13)
25#define PIIX4_FUNC3IO_PMCNTRL_SUS_TYP_SOFF (0x0 << 10)
26};
27
28#define PIIX4_SUSPEND_MAGIC 0x00120002
29
30static const int piix4_pm_io_region = PCI_BRIDGE_RESOURCES;
31
32static void piix4_poweroff(void)
33{
34 int spec_devid;
35 u16 sts;
36
37 /* Ensure the power button status is clear */
38 while (1) {
39 sts = inw(io_offset + PIIX4_FUNC3IO_PMSTS);
40 if (!(sts & PIIX4_FUNC3IO_PMSTS_PWRBTN_STS))
41 break;
42 outw(sts, io_offset + PIIX4_FUNC3IO_PMSTS);
43 }
44
45 /* Enable entry to suspend */
46 outw(PIIX4_FUNC3IO_PMCNTRL_SUS_TYP_SOFF | PIIX4_FUNC3IO_PMCNTRL_SUS_EN,
47 io_offset + PIIX4_FUNC3IO_PMCNTRL);
48
49 /* If the special cycle occurs too soon this doesn't work... */
50 mdelay(10);
51
52 /*
53 * The PIIX4 will enter the suspend state only after seeing a special
54 * cycle with the correct magic data on the PCI bus. Generate that
55 * cycle now.
56 */
57 spec_devid = PCI_DEVID(0, PCI_DEVFN(0x1f, 0x7));
58 pci_bus_write_config_dword(pm_dev->bus, spec_devid, 0,
59 PIIX4_SUSPEND_MAGIC);
60
61 /* Give the system some time to power down, then error */
62 mdelay(1000);
63 pr_emerg("Unable to poweroff system\n");
64}
65
66static int piix4_poweroff_probe(struct pci_dev *dev,
67 const struct pci_device_id *id)
68{
69 int res;
70
71 if (pm_dev)
72 return -EINVAL;
73
74 /* Request access to the PIIX4 PM IO registers */
75 res = pci_request_region(dev, piix4_pm_io_region,
76 "PIIX4 PM IO registers");
77 if (res) {
78 dev_err(&dev->dev, "failed to request PM IO registers: %d\n",
79 res);
80 return res;
81 }
82
83 pm_dev = dev;
84 io_offset = pci_resource_start(dev, piix4_pm_io_region);
85 pm_power_off = piix4_poweroff;
86
87 return 0;
88}
89
90static void piix4_poweroff_remove(struct pci_dev *dev)
91{
92 if (pm_power_off == piix4_poweroff)
93 pm_power_off = NULL;
94
95 pci_release_region(dev, piix4_pm_io_region);
96 pm_dev = NULL;
97}
98
99static const struct pci_device_id piix4_poweroff_ids[] = {
100 { PCI_DEVICE(PCI_VENDOR_ID_INTEL, PCI_DEVICE_ID_INTEL_82371AB_3) },
101 { 0 },
102};
103
104static struct pci_driver piix4_poweroff_driver = {
105 .name = "piix4-poweroff",
106 .id_table = piix4_poweroff_ids,
107 .probe = piix4_poweroff_probe,
108 .remove = piix4_poweroff_remove,
109};
110
111module_pci_driver(piix4_poweroff_driver);
112MODULE_AUTHOR("Paul Burton <paul.burton@imgtec.com>");
113MODULE_LICENSE("GPL");