2 * Copyright (C) 2016 Imagination Technologies
3 * Author: Paul Burton <paul.burton@mips.com>
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.
11 #include <linux/delay.h>
13 #include <linux/module.h>
14 #include <linux/pci.h>
17 static struct pci_dev
*pm_dev
;
18 static resource_size_t io_offset
;
20 enum 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)
28 #define PIIX4_SUSPEND_MAGIC 0x00120002
30 static const int piix4_pm_io_region
= PCI_BRIDGE_RESOURCES
;
32 static void piix4_poweroff(void)
37 /* Ensure the power button status is clear */
39 sts
= inw(io_offset
+ PIIX4_FUNC3IO_PMSTS
);
40 if (!(sts
& PIIX4_FUNC3IO_PMSTS_PWRBTN_STS
))
42 outw(sts
, io_offset
+ PIIX4_FUNC3IO_PMSTS
);
45 /* Enable entry to suspend */
46 outw(PIIX4_FUNC3IO_PMCNTRL_SUS_TYP_SOFF
| PIIX4_FUNC3IO_PMCNTRL_SUS_EN
,
47 io_offset
+ PIIX4_FUNC3IO_PMCNTRL
);
49 /* If the special cycle occurs too soon this doesn't work... */
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
57 spec_devid
= PCI_DEVID(0, PCI_DEVFN(0x1f, 0x7));
58 pci_bus_write_config_dword(pm_dev
->bus
, spec_devid
, 0,
61 /* Give the system some time to power down, then error */
63 pr_emerg("Unable to poweroff system\n");
66 static int piix4_poweroff_probe(struct pci_dev
*dev
,
67 const struct pci_device_id
*id
)
74 /* Request access to the PIIX4 PM IO registers */
75 res
= pci_request_region(dev
, piix4_pm_io_region
,
76 "PIIX4 PM IO registers");
78 dev_err(&dev
->dev
, "failed to request PM IO registers: %d\n",
84 io_offset
= pci_resource_start(dev
, piix4_pm_io_region
);
85 pm_power_off
= piix4_poweroff
;
90 static void piix4_poweroff_remove(struct pci_dev
*dev
)
92 if (pm_power_off
== piix4_poweroff
)
95 pci_release_region(dev
, piix4_pm_io_region
);
99 static const struct pci_device_id piix4_poweroff_ids
[] = {
100 { PCI_DEVICE(PCI_VENDOR_ID_INTEL
, PCI_DEVICE_ID_INTEL_82371AB_3
) },
104 static 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
,
111 module_pci_driver(piix4_poweroff_driver
);
112 MODULE_AUTHOR("Paul Burton <paul.burton@mips.com>");
113 MODULE_LICENSE("GPL");