2 * (C) 2003 Linux Networx, SuSE Linux AG
3 * 2006.1 yhlu add dest apicid for IRQ0
5 #include <console/console.h>
6 #include <device/device.h>
7 #include <device/pci.h>
8 #include <device/pci_ids.h>
9 #include <device/pci_ops.h>
10 #include <pc80/mc146818rtc.h>
11 #include <pc80/isa-dma.h>
12 #include <cpu/x86/lapic.h>
19 unsigned int value_low, value_high;
22 static struct ioapicreg ioapicregvalues[] = {
23 #define ALL (0xff << 24)
25 #define DISABLED (1 << 16)
26 #define ENABLED (0 << 16)
27 #define TRIGGER_EDGE (0 << 15)
28 #define TRIGGER_LEVEL (1 << 15)
29 #define POLARITY_HIGH (0 << 13)
30 #define POLARITY_LOW (1 << 13)
31 #define PHYSICAL_DEST (0 << 11)
32 #define LOGICAL_DEST (1 << 11)
33 #define ExtINT (7 << 8)
37 /* IO-APIC virtual wire mode configuration */
38 /* mask, trigger, polarity, destination, delivery, vector */
39 { 0, ENABLED | TRIGGER_EDGE | POLARITY_HIGH | PHYSICAL_DEST | ExtINT, NONE},
49 { 10, DISABLED, NONE},
50 { 11, DISABLED, NONE},
51 { 12, DISABLED, NONE},
52 { 13, DISABLED, NONE},
53 { 14, DISABLED, NONE},
54 { 15, DISABLED, NONE},
55 { 16, DISABLED, NONE},
56 { 17, DISABLED, NONE},
57 { 18, DISABLED, NONE},
58 { 19, DISABLED, NONE},
59 { 20, DISABLED, NONE},
60 { 21, DISABLED, NONE},
61 { 22, DISABLED, NONE},
62 { 23, DISABLED, NONE},
63 /* Be careful and don't write past the end... */
66 static void setup_ioapic(void)
69 unsigned long value_low, value_high;
70 unsigned long ioapic_base = 0xfec00000;
71 volatile unsigned long *l;
72 struct ioapicreg *a = ioapicregvalues;
74 l = (unsigned long *) ioapic_base;
76 ioapicregvalues[0].value_high = lapicid()<<(56-32);
78 for (i = 0; i < sizeof(ioapicregvalues) / sizeof(ioapicregvalues[0]);
80 l[0] = (a->reg * 2) + 0x10;
83 l[0] = (a->reg *2) + 0x11;
86 if ((i==0) && (value_low == 0xffffffff)) {
87 printk_warning("IO APIC not responding.\n");
90 printk_spew("for IRQ, reg 0x%08x value 0x%08x 0x%08x\n",
91 a->reg, a->value_low, a->value_high);
95 static void enable_hpet(struct device *dev)
97 unsigned long hpet_address;
99 pci_write_config32(dev,0xa0, 0xfed00001);
100 hpet_address = pci_read_config32(dev,0xa0)& 0xfffffffe;
101 printk_debug("enabling HPET @0x%x\n", hpet_address);
105 static void lpc_init(struct device *dev)
110 /* IO APIC initialization */
111 byte = pci_read_config8(dev, 0x4B);
113 pci_write_config8(dev, 0x4B, byte);
116 /* posted memory write enable */
117 byte = pci_read_config8(dev, 0x46);
118 pci_write_config8(dev, 0x46, byte | (1<<0));
120 /* Enable 5Mib Rom window */
121 byte = pci_read_config8(dev, 0x43);
123 pci_write_config8(dev, 0x43, byte);
125 /* Enable Port 92 fast reset */
126 byte = pci_read_config8(dev, 0x41);
128 pci_write_config8(dev, 0x41, byte);
130 /* Enable Error reporting */
131 /* Set up sync flood detected */
132 byte = pci_read_config8(dev, 0x47);
134 pci_write_config8(dev, 0x47, byte);
136 /* Set up NMI on errors */
137 byte = pci_read_config8(dev, 0x40);
138 byte |= (1 << 1); /* clear PW2LPC error */
139 byte |= (1 << 6); /* clear LPCERR */
140 pci_write_config8(dev, 0x40, byte);
141 nmi_option = NMI_OFF;
142 get_option(&nmi_option, "nmi");
144 byte |= (1 << 7); /* set NMI */
145 pci_write_config8(dev, 0x40, byte);
148 /* Initialize the real time clock */
151 /* Initialize isa dma */
154 /* Initialize the High Precision Event Timers */
158 static void amd8111_lpc_read_resources(device_t dev)
160 struct resource *res;
162 /* Get the normal pci resources of this device */
163 pci_dev_read_resources(dev);
165 /* Add an extra subtractive resource for both memory and I/O */
166 res = new_resource(dev, IOINDEX_SUBTRACTIVE(0, 0));
167 res->flags = IORESOURCE_IO | IORESOURCE_SUBTRACTIVE | IORESOURCE_ASSIGNED;
169 res = new_resource(dev, IOINDEX_SUBTRACTIVE(1, 0));
170 res->flags = IORESOURCE_MEM | IORESOURCE_SUBTRACTIVE | IORESOURCE_ASSIGNED;
173 static void amd8111_lpc_enable_resources(device_t dev)
175 pci_dev_enable_resources(dev);
176 enable_childrens_resources(dev);
179 static void lpci_set_subsystem(device_t dev, unsigned vendor, unsigned device)
181 pci_write_config32(dev, 0x70,
182 ((device & 0xffff) << 16) | (vendor & 0xffff));
185 static struct pci_operations lops_pci = {
186 .set_subsystem = lpci_set_subsystem,
189 static struct device_operations lpc_ops = {
190 .read_resources = amd8111_lpc_read_resources,
191 .set_resources = pci_dev_set_resources,
192 .enable_resources = amd8111_lpc_enable_resources,
194 .scan_bus = scan_static_bus,
195 .enable = amd8111_enable,
196 .ops_pci = &lops_pci,
199 static struct pci_driver lpc_driver __pci_driver = {
201 .vendor = PCI_VENDOR_ID_AMD,
202 .device = PCI_DEVICE_ID_AMD_8111_ISA,