2 * This file is part of the coreboot project.
4 * Copyright (C) 2010 Advanced Micro Devices, Inc.
6 * This program is free software; you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License as published by
8 * the Free Software Foundation; version 2 of the License.
10 * This program is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU General Public License for more details.
15 * You should have received a copy of the GNU General Public License
16 * along with this program; if not, write to the Free Software
17 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
20 #include <console/console.h>
21 #include <device/device.h>
22 #include <device/pci.h>
23 #include <device/pci_ids.h>
24 #include <device/pci_ops.h>
25 #include <device/smbus.h>
26 #include <pc80/mc146818rtc.h>
29 #include <cpu/x86/lapic.h>
30 #include <arch/ioapic.h>
37 #define MAINBOARD_POWER_OFF 0
38 #define MAINBOARD_POWER_ON 1
40 #ifndef CONFIG_MAINBOARD_POWER_ON_AFTER_POWER_FAIL
41 #define CONFIG_MAINBOARD_POWER_ON_AFTER_POWER_FAIL MAINBOARD_POWER_ON
53 #define BIT8 (1 << 8 )
54 #define BIT9 (1 << 9 )
55 #define BIT10 (1 << 10)
56 #define BIT11 (1 << 11)
57 #define BIT12 (1 << 12)
58 #define BIT13 (1 << 13)
59 #define BIT14 (1 << 14)
60 #define BIT15 (1 << 15)
62 #define BIT16 (1 << 16)
63 #define BIT17 (1 << 17)
64 #define BIT18 (1 << 18)
65 #define BIT19 (1 << 19)
66 #define BIT20 (1 << 20)
67 #define BIT21 (1 << 21)
68 #define BIT22 (1 << 22)
69 #define BIT23 (1 << 23)
70 #define BIT24 (1 << 24)
71 #define BIT25 (1 << 25)
72 #define BIT26 (1 << 26)
73 #define BIT27 (1 << 27)
74 #define BIT28 (1 << 28)
75 #define BIT29 (1 << 29)
76 #define BIT30 (1 << 30)
77 #define BIT31 (1 << 31)
80 * SB800 enables all USB controllers by default in SMBUS Control.
81 * SB800 enables SATA by default in SMBUS Control.
84 static void sm_init(device_t dev)
89 printk(BIOS_INFO, "sm_init().\n");
91 ioapic_base = 0xFEC00000;//pci_read_config32(dev, 0x74) & (0xffffffe0); /* some like mem resource, but does not have enable bit */
92 /* Don't rename APIC ID */
93 /* TODO: We should call setup_ioapic() here. But kernel hangs if cpu is K8.
94 * We need to check out why and change back. */
95 clear_ioapic(ioapic_base);
96 //setup_ioapic(ioapic_base, 0);
98 /* enable serial irq */
99 byte = pm_ioread(0x54);
100 byte |= 1 << 7; /* enable serial irq function */
102 byte |= 4 << 2; /* set NumSerIrqBits=4 */
103 pm_iowrite(0x54, byte);
105 pm_iowrite(0x00, 0x0E);
106 pm_iowrite(0x0B, 0x02);
107 /* 2.11 IO Trap Settings */
108 abcfg_reg(0x10090, 1 << 16, 1 << 16);
111 //pci_write_config32(dev, 0xF0, AB_INDX);
112 pm_iowrite(0xE0, AB_INDX & 0xFF);
113 pm_iowrite(0xE1, (AB_INDX >> 8) & 0xFF);
114 pm_iowrite(0xE2, (AB_INDX >> 16) & 0xFF);
115 pm_iowrite(0xE3, (AB_INDX >> 24) & 0xFF);
116 /* Initialize the real time clock */
119 byte = pm_ioread(0x8);
120 byte |= 1 << 2 | 1 << 4;
121 pm_iowrite(0x08, byte);
122 byte = pm_ioread(0x9);
124 pm_iowrite(0x09, byte);
126 abcfg_reg(0x10060, (BIT31), BIT31);
127 abcfg_reg(0x1009C, (BIT4 + BIT5), BIT4 + BIT5);
128 abcfg_reg(0x9C, (BIT2 + BIT3 + BIT4 + BIT5 + BIT6 + BIT7), BIT2 + BIT3 + BIT4 + BIT5 + BIT6 + BIT7);
129 abcfg_reg(0x90, (BIT21 + BIT22 + BIT23), BIT21 + BIT22 + BIT23);
130 abcfg_reg(0xF0, (BIT6 + BIT5), BIT6 + BIT5);
131 abcfg_reg(0x10090, (BIT9 + BIT10 + BIT11 + BIT12), BIT9 + BIT10 + BIT11 + BIT12);
132 abcfg_reg(0x58, (BIT10), BIT10);
133 abcfg_reg(0xF0, (BIT3 + BIT4), BIT3 + BIT4);
134 abcfg_reg(0x54, (BIT1), BIT1);
136 axindxc_reg(0x02, BIT9, BIT9);
137 axindxc_reg(0x10, BIT9, BIT9);
139 /* 4.2 Enabling Upstream DMA Access */
140 axcfg_reg(0x04, 1 << 2, 1 << 2);
141 /* 4.3 Enabling PCIB Prefetch Settings */
142 abcfg_reg(0x10060, 1 << 20, 1 << 20);
143 abcfg_reg(0x10064, 1 << 20, 1 << 20);
145 /* 4.4 Enabling OHCI Prefetch for Performance Enhancement, A12 */
146 abcfg_reg(0x80, 1 << 0, 1<< 0);
148 /* 4.5 B-Link Client's Credit Variable Settings for the Downstream Arbitration Equation */
149 /* 4.6 Enabling Additional Address Bits Checking in Downstream */
150 abcfg_reg(0x9c, 1 << 0, 1 << 0);
151 //abcfg_reg(0x9c, 3 << 0, 3 << 0); //A11
153 /* 4.7 Set B-Link Prefetch Mode */
154 abcfg_reg(0x80, 3 << 17, 3 << 17);
156 // RPR Enabled SMI ordering enhancement. ABCFG 0x90[21]
157 // RPR USB Delay A-Link Express L1 State. ABCFG 0x90[17]
158 abcfg_reg(0x90, 1 << 17 | 1 << 21, 1 << 17 | 1 << 21);
159 /* 4.8 Enabling Detection of Upstream Interrupts */
160 abcfg_reg(0x94, 1 << 20 | 0x7FFFF, 1 << 20 | 0x00FEE);
162 /* 4.9: Enabling Downstream Posted Transactions to Pass Non-Posted
163 * Transactions for the K8 Platform (for All Revisions) */
164 abcfg_reg(0x10090, 1 << 8, 1 << 8);
166 /* 4.10:Programming Cycle Delay for AB and BIF Clock Gating */
167 /* 4.11:Enabling AB Int_Arbiter Enhancement (for All Revisions) */
168 abcfg_reg(0x10054, 0xFFFF0000, 0x01040000);
169 abcfg_reg(0x54, 0xFF << 16, 4 << 16);
170 abcfg_reg(0x54, 1 << 24, 0 << 24);
171 abcfg_reg(0x54, 1 << 26, 1 << 26);
172 abcfg_reg(0x98, 0xFFFFFF00, 0x00004700);
174 /* 4.12: Enabling AB and BIF Clock Gating */
175 abcfg_reg(0x10054, 0x0000FFFF, 0x07FF);
177 /* 4.13:Enabling Requester ID for upstream traffic. */
178 abcfg_reg(0x98, 3 << 16, 3 << 16);
180 abcfg_reg(0x50, 1 << 2, 0 << 2);
182 /* 5.2 Enabling GPP Port A/B/C/D */
183 //abcfg_reg(0xC0, 0xF << 4, 0xF << 4);
185 /* Enable SCI as irq9. */
188 /* Enabled IRQ input */
192 abcfg_reg(0x90, 0xFFFFFFFF, 0x00F80040);
193 abcfg_reg(0xA0, 0xFFFFFFFF, 0x00000000);
194 abcfg_reg(0xA4, 0xFFFFFFFF, 0x00000000);
195 abcfg_reg(0xC0, 0xFFFFFFFF, 0x0000F014);
196 abcfg_reg(0x98, 0xFFFFFFFF, 0X01034700);
199 static int lsmbus_recv_byte(device_t dev)
202 struct resource *res;
205 device = dev->path.i2c.device;
206 pbus = get_pbus_smbus(dev);
208 res = find_resource(pbus->dev, 0x90);
210 return do_smbus_recv_byte(res->base, device);
213 static int lsmbus_send_byte(device_t dev, u8 val)
216 struct resource *res;
219 device = dev->path.i2c.device;
220 pbus = get_pbus_smbus(dev);
222 res = find_resource(pbus->dev, 0x90);
224 return do_smbus_send_byte(res->base, device, val);
227 static int lsmbus_read_byte(device_t dev, u8 address)
230 struct resource *res;
233 device = dev->path.i2c.device;
234 pbus = get_pbus_smbus(dev);
236 res = find_resource(pbus->dev, 0x90);
238 return do_smbus_read_byte(res->base, device, address);
241 static int lsmbus_write_byte(device_t dev, u8 address, u8 val)
244 struct resource *res;
247 device = dev->path.i2c.device;
248 pbus = get_pbus_smbus(dev);
250 res = find_resource(pbus->dev, 0x90);
252 return do_smbus_write_byte(res->base, device, address, val);
254 static struct smbus_bus_operations lops_smbus_bus = {
255 .recv_byte = lsmbus_recv_byte,
256 .send_byte = lsmbus_send_byte,
257 .read_byte = lsmbus_read_byte,
258 .write_byte = lsmbus_write_byte,
261 static void sb800_sm_read_resources(device_t dev)
263 struct resource *res;
266 /* rpr2.14: Hides SM bus controller Bar1 where stores HPET MMIO base address */
267 byte = pm_ioread(0x55);
269 pm_iowrite(0x55, byte);
271 /* Get the normal pci resources of this device */
272 /* pci_dev_read_resources(dev); */
274 byte = pm_ioread(0x55);
276 pm_iowrite(0x55, byte);
279 res = new_resource(dev, 0x74);
280 res->base = 0xfec00000;
281 res->size = 256 * 0x10;
282 res->limit = 0xFEFFFFFUL; /* res->base + res->size -1; */
285 res->flags = IORESOURCE_MEM | IORESOURCE_FIXED;
287 #if 0 /* Linux ACPI crashes when it is 1. For late debugging. */
288 res = new_resource(dev, 0x14); /* TODO: hpet */
289 res->base = 0xfed00000; /* reset hpet to widely accepted address */
291 res->limit = 0xFFFFFFFFUL; /* res->base + res->size -1; */
294 res->flags = IORESOURCE_MEM | IORESOURCE_FIXED;
296 /* dev->command |= PCI_COMMAND_MEMORY | PCI_COMMAND_MASTER; */
299 //res = new_resource(dev, 0x90);
302 //res->limit = 0xFFFFUL; /* res->base + res->size -1; */
305 //res->flags = IORESOURCE_IO | IORESOURCE_FIXED;
308 compact_resources(dev);
311 static void sb800_sm_set_resources(struct device *dev)
313 struct resource *res;
316 pci_dev_set_resources(dev);
319 /* rpr2.14: Make HPET MMIO decoding controlled by the memory enable bit in command register of LPC ISA bridage */
320 byte = pm_ioread(0x52);
322 pm_iowrite(0x52, byte);
324 res = find_resource(dev, 0x74);
326 printk(BIOS_INFO, "sb800_sm_set_resources, res->base=0x%llx\n", res->base);
328 //pci_write_config32(dev, 0x74, res->base | 1 << 3);
329 pm_iowrite(0x34, res->base | 0x7);
330 pm_iowrite(0x35, (res->base >> 8) & 0xFF);
331 pm_iowrite(0x36, (res->base >> 16) & 0xFF);
332 pm_iowrite(0x37, (res->base >> 24) & 0xFF);
333 #if 0 /* TODO:hpet */
334 res = find_resource(dev, 0x14);
335 pci_write_config32(dev, 0x14, res->base);
337 //res = find_resource(dev, 0x90);
338 //pci_write_config32(dev, 0x90, res->base | 1);
341 static struct pci_operations lops_pci = {
342 .set_subsystem = pci_dev_set_subsystem,
344 static struct device_operations smbus_ops = {
345 .read_resources = sb800_sm_read_resources,
346 .set_resources = sb800_sm_set_resources,
347 .enable_resources = pci_dev_enable_resources,
349 .scan_bus = scan_static_bus,
350 .ops_pci = &lops_pci,
351 .ops_smbus_bus = &lops_smbus_bus,
353 static const struct pci_driver smbus_driver __pci_driver = {
355 .vendor = PCI_VENDOR_ID_ATI,
356 .device = PCI_DEVICE_ID_ATI_SB800_SM,