- O2, enums, and switch statements work in romcc
[coreboot.git] / src / southbridge / amd / amd8111 / amd8111_acpi.c
1 #include <console/console.h>
2 #include <device/device.h>
3 #include <device/pci.h>
4 #include <device/pci_ids.h>
5 #include <device/pci_ops.h>
6 #include <pc80/mc146818rtc.h>
7 #include "amd8111.h"
8
9 #define PREVIOUS_POWER_STATE 0x43
10 #define MAINBOARD_POWER_OFF 0
11 #define MAINBOARD_POWER_ON 1
12
13 #ifndef MAINBOARD_POWER_ON_AFTER_POWER_FAIL
14 #define MAINBOARD_POWER_ON_AFTER_POWER_FAIL MAINBOARD_POWER_ON
15 #endif
16
17
18 static void acpi_init(struct device *dev)
19 {
20         uint8_t byte;
21         uint16_t word;
22         int on;
23
24 #if 0
25         printk_debug("ACPI: disabling NMI watchdog.. ");
26         pci_read_config_byte(dev, 0x49, &byte);
27         pci_write_config_byte(dev, 0x49, byte | (1<<2));
28
29
30         pci_read_config_byte(dev, 0x41, &byte);
31         pci_write_config_byte(dev, 0x41, byte | (1<<6)|(1<<2));
32
33         /* added from sourceforge */
34         pci_read_config_byte(dev, 0x48, &byte);
35         pci_write_config_byte(dev, 0x48, byte | (1<<3));
36
37         printk_debug("done.\n");
38
39
40         printk_debug("ACPI: Routing IRQ 12 to PS2 port.. ");
41         pci_read_config_word(dev, 0x46, &word);
42         pci_write_config_word(dev, 0x46, word | (1<<9));
43         printk_debug("done.\n");
44
45         
46         printk_debug("ACPI: setting PM class code.. ");
47         pci_write_config_dword(dev, 0x60, 0x06800000);
48         printk_debug("done.\n");
49 #endif
50         on = MAINBOARD_POWER_ON_AFTER_POWER_FAIL;
51         get_option(&on, "power_on_after_fail");
52         byte = pci_read_config8(dev, PREVIOUS_POWER_STATE);
53         byte &= ~0x40;
54         if (!on) {
55                 byte |= 0x40;
56         }
57         pci_write_config8(dev, PREVIOUS_POWER_STATE, byte);
58         printk_info("set power %s after power fail\n", on?"on":"off");
59
60 }
61
62 static struct device_operations acpi_ops  = {
63         .read_resources   = pci_dev_read_resources,
64         .set_resources    = pci_dev_set_resources,
65         .enable_resources = pci_dev_enable_resources,
66         .init             = acpi_init,
67         .scan_bus         = 0,
68         .enable           = amd8111_enable,
69 };
70
71 static struct pci_driver acpi_driver __pci_driver = {
72         .ops    = &acpi_ops,
73         .vendor = PCI_VENDOR_ID_AMD,
74         .device = PCI_DEVICE_ID_AMD_8111_ACPI,
75 };
76