2 * Copyright (C) 2014 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>
12 #include <linux/init.h>
14 #include <linux/pci.h>
16 #include <asm/mach-malta/malta-pm.h>
18 static struct pci_bus *pm_pci_bus;
19 static resource_size_t pm_io_offset;
21 int mips_pm_suspend(unsigned state)
26 if (!pm_pci_bus || !pm_io_offset)
29 /* Ensure the power button status is clear */
31 sts = inw(pm_io_offset + PIIX4_FUNC3IO_PMSTS);
32 if (!(sts & PIIX4_FUNC3IO_PMSTS_PWRBTN_STS))
34 outw(sts, pm_io_offset + PIIX4_FUNC3IO_PMSTS);
37 /* Enable entry to suspend */
38 outw(state | PIIX4_FUNC3IO_PMCNTRL_SUS_EN,
39 pm_io_offset + PIIX4_FUNC3IO_PMCNTRL);
41 /* If the special cycle occurs too soon this doesn't work... */
45 * The PIIX4 will enter the suspend state only after seeing a special
46 * cycle with the correct magic data on the PCI bus. Generate that
49 spec_devid = PCI_DEVID(0, PCI_DEVFN(0x1f, 0x7));
50 pci_bus_write_config_dword(pm_pci_bus, spec_devid, 0,
53 /* Give the system some time to power down */
59 static int __init malta_pm_setup(void)
62 int res, io_region = PCI_BRIDGE_RESOURCES;
64 /* Find a reference to the PCI bus */
65 pm_pci_bus = pci_find_next_bus(NULL);
67 pr_warn("malta-pm: failed to find reference to PCI bus\n");
71 /* Find the PIIX4 PM device */
72 dev = pci_get_subsys(PCI_VENDOR_ID_INTEL,
73 PCI_DEVICE_ID_INTEL_82371AB_3, PCI_ANY_ID,
76 pr_warn("malta-pm: failed to find PIIX4 PM\n");
80 /* Request access to the PIIX4 PM IO registers */
81 res = pci_request_region(dev, io_region, "PIIX4 PM IO registers");
83 pr_warn("malta-pm: failed to request PM IO registers (%d)\n",
89 /* Find the offset to the PIIX4 PM IO registers */
90 pm_io_offset = pci_resource_start(dev, io_region);
96 late_initcall(malta_pm_setup);