Add acpi_get_sleep_type() to i82371eb and P2B _PTS/_WAK methods
[coreboot.git] / src / southbridge / intel / i82371eb / smbus.c
1 /*
2  * This file is part of the coreboot project.
3  *
4  * Copyright (C) 2007 Uwe Hermann <uwe@hermann-uwe.de>
5  * Copyright (C) 2010 Keith Hui <buurin@gmail.com>
6  * Copyright (C) 2010 Idwer Vollering <vidwer@gmail.com>
7  * Copyright (C) 2010 Tobias Diedrich <ranma+coreboot@gmail.com>
8  *
9  * This program is free software; you can redistribute it and/or modify
10  * it under the terms of the GNU General Public License as published by
11  * the Free Software Foundation; either version 2 of the License, or
12  * (at your option) any later version.
13  *
14  * This program is distributed in the hope that it will be useful,
15  * but WITHOUT ANY WARRANTY; without even the implied warranty of
16  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
17  * GNU General Public License for more details.
18  *
19  * You should have received a copy of the GNU General Public License
20  * along with this program; if not, write to the Free Software
21  * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301 USA
22  */
23
24 #include <arch/io.h>
25 #include <console/console.h>
26 #include <stdint.h>
27 #include <device/device.h>
28 #include <device/pci.h>
29 #include <device/pci_ids.h>
30 #include <device/smbus.h>
31 #include "i82371eb.h"
32 #include "smbus.h"
33
34 #if CONFIG_HAVE_ACPI_RESUME == 1
35 extern u8 acpi_slp_type;
36 int acpi_get_sleep_type(void);
37 #endif
38
39 static void pwrmgt_enable(struct device *dev)
40 {
41         struct southbridge_intel_i82371eb_config *sb = dev->chip_info;
42         u32 reg, gpo = sb->gpo;
43
44         /* Sets the base address of power management ports. */
45         pci_write_config16(dev, PMBA, DEFAULT_PMBASE | 1);
46
47         /* Set Power Management IO Space Enable bit */
48         u8 val = pci_read_config8(dev, PMREGMISC);
49         pci_write_config8(dev, PMREGMISC, val | 1);
50
51         /* set global control:
52          * bit25 (lid_pol): 1=invert lid polarity
53          * bit24 (sm_freeze): 1=freeze idle and standby timers
54          * bit16 (end of smi): 0=disable smi assertion (cleared by hw)
55          * bits8-15,26: global standby timer inital count 127 * 4minutes
56          * bit2  (thrm_pol): 1=active low THRM#
57          * bit0  (smi_en): 1=disable smi generation upon smi event
58          */
59         reg = (sb->lid_polarity<<25)|
60               (1<<24)|
61               (0xff<<8)|
62               (sb->thrm_polarity<<2);
63         outl(reg, DEFAULT_PMBASE + GLBCTL);
64
65         /* set processor control:
66          * bit12 (stpclk_en): 1=enable stopping of host clk on lvl3
67          * bit11 (sleep_en): 1=enable slp# assertion on lvl3
68          * bit9 (cc_en): 1=enable clk control with lvl2 and lvl3 regs
69          */
70         outl(0, DEFAULT_PMBASE + PCNTRL);
71
72         /* disable smi event enables */
73         outw(0, DEFAULT_PMBASE + GLBEN);
74         outl(0, DEFAULT_PMBASE + DEVCTL);
75
76         /* set default gpo value.
77          * power-on default is 0x7fffbfffh */
78         if (gpo) {
79                 /* only 8bit access allowed */
80                 outb( gpo        & 0xff, DEFAULT_PMBASE + GPO0);
81                 outb((gpo >>  8) & 0xff, DEFAULT_PMBASE + GPO1);
82                 outb((gpo >> 16) & 0xff, DEFAULT_PMBASE + GPO2);
83                 outb((gpo >> 24) & 0xff, DEFAULT_PMBASE + GPO3);
84         } else {
85                 printk(BIOS_SPEW,
86                        "%s: gpo default missing in devicetree.cb!\n", __func__);
87         }
88
89         /* Clear status events. */
90         outw(0xffff,     DEFAULT_PMBASE + PMSTS);
91         outw(0xffff,     DEFAULT_PMBASE + GPSTS);
92         outw(0xffff,     DEFAULT_PMBASE + GLBSTS);
93         outl(0xffffffff, DEFAULT_PMBASE + DEVSTS);
94
95 #if CONFIG_HAVE_ACPI_RESUME == 1
96         /* this reads PMCNTRL, so we have to call it before writing the
97          * default value */
98         acpi_slp_type = acpi_get_sleep_type();
99 #endif
100
101         /* set PMCNTRL default */
102         outw(SUS_TYP_S0|SCI_EN, DEFAULT_PMBASE + PMCNTRL);
103 }
104
105 static void pwrmgt_read_resources(struct device *dev)
106 {
107         struct resource *res;
108
109         pci_dev_read_resources(dev);
110
111         res = new_resource(dev, 1);
112         res->base = DEFAULT_PMBASE;
113         res->size = 0x0040;
114         res->limit = 0xffff;
115         res->flags = IORESOURCE_IO | IORESOURCE_ASSIGNED | IORESOURCE_FIXED |
116                      IORESOURCE_RESERVE;
117
118         res = new_resource(dev, 2);
119         res->base = SMBUS_IO_BASE;
120         res->size = 0x0010;
121         res->limit = 0xffff;
122         res->flags = IORESOURCE_IO | IORESOURCE_ASSIGNED | IORESOURCE_FIXED |
123                      IORESOURCE_RESERVE;
124 }
125
126
127 static const struct smbus_bus_operations lops_smbus_bus = {
128 };
129
130 static const struct device_operations smbus_ops = {
131         .read_resources         = pwrmgt_read_resources,
132         .set_resources          = pci_dev_set_resources,
133         .enable_resources       = pci_dev_enable_resources,
134         .init                   = 0,
135         .scan_bus               = scan_static_bus,
136         .enable                 = pwrmgt_enable,
137         .ops_pci                = 0, /* No subsystem IDs on 82371EB! */
138         .ops_smbus_bus          = &lops_smbus_bus,
139 };
140
141 /* Note: There's no SMBus on 82371FB/SB/MX and 82437MX. */
142
143 /* Intel 82371AB/EB/MB */
144 static const struct pci_driver smbus_driver __pci_driver = {
145         .ops    = &smbus_ops,
146         .vendor = PCI_VENDOR_ID_INTEL,
147         .device = PCI_DEVICE_ID_INTEL_82371AB_SMB_ACPI,
148 };