0fefd4ef4573d950caafabfbe7602f01ef0b986c
[coreboot.git] / src / southbridge / amd / sb600 / sb600_early_setup.c
1 /*
2  * This file is part of the coreboot project.
3  *
4  * Copyright (C) 2008 Advanced Micro Devices, Inc.
5  *
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.
9  *
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.
14  *
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
18  */
19
20 #include <reset.h>
21 #include <arch/cpu.h>
22 #include "sb600.h"
23 #include "sb600_smbus.c"
24
25 #define SMBUS_IO_BASE 0x1000    /* Is it a temporary SMBus I/O base address? */
26          /*SIZE 0x40 */
27
28 static void pmio_write(u8 reg, u8 value)
29 {
30         outb(reg, PM_INDEX);
31         outb(value, PM_INDEX + 1);
32 }
33
34 static u8 pmio_read(u8 reg)
35 {
36         outb(reg, PM_INDEX);
37         return inb(PM_INDEX + 1);
38 }
39
40 /* RPR 2.1: Get SB ASIC Revision. */
41 static u8 get_sb600_revision(void)
42 {
43         device_t dev;
44         dev = pci_locate_device(PCI_ID(0x1002, 0x4385), 0);
45
46         if (dev == PCI_DEV_INVALID) {
47                 die("SMBUS controller not found\n");
48                 /* NOT REACHED */
49         }
50         return pci_read_config8(dev, 0x08);
51 }
52
53
54 /***************************************
55 * Legacy devices are mapped to LPC space.
56 *       Serial port 0
57 *       KBC Port
58 *       ACPI Micro-controller port
59 *       LPC ROM size
60 *       This function does not change port 0x80 decoding.
61 *       Console output through any port besides 0x3f8 is unsupported.
62 *       If you use FWH ROMs, you have to setup IDSEL.
63 * NOTE: Call me ASAP, because I will reset LPC ROM size!
64 * Reviewed-by: Carl-Daniel Hailfinger
65 * Reviewed against AMD SB600 Register Reference Manual rev. 3.03, section 3.1
66 *       (LPC ISA Bridge)
67 ***************************************/
68 static void sb600_lpc_init(void)
69 {
70         u8 reg8;
71         u32 reg32;
72         device_t dev;
73
74         dev = pci_locate_device(PCI_ID(0x1002, 0x4385), 0);     /* SMBUS controller */
75         /* NOTE: Set BootTimerDisable, otherwise it would keep rebooting!!
76          * This bit has no meaning if debug strap is not enabled. So if the
77          * board keeps rebooting and the code fails to reach here, we could
78          * disable the debug strap first. */
79         reg32 = pci_read_config32(dev, 0x4C);
80         reg32 |= 1 << 31;
81         pci_write_config32(dev, 0x4C, reg32);
82
83         /* Enable lpc controller */
84         reg32 = pci_read_config32(dev, 0x64);
85         reg32 |= 1 << 20;
86         pci_write_config32(dev, 0x64, reg32);
87
88         dev = pci_locate_device(PCI_ID(0x1002, 0x438d), 0);     /* LPC Controller */
89         /* Decode port 0x3f8-0x3ff (Serial 0) */
90         // XXX Serial port decode on LPC is hardcoded to 0x3f8
91         reg8 = pci_read_config8(dev, 0x44);
92         reg8 |= 1 << 6;
93         pci_write_config8(dev, 0x44, reg8);
94
95         /* Decode port 0x60 & 0x64 (PS/2 keyboard) and port 0x62 & 0x66 (ACPI)*/
96         reg8 = pci_read_config8(dev, 0x47);
97         reg8 |= (1 << 5) | (1 << 6);
98         pci_write_config8(dev, 0x47, reg8);
99
100         /* SuperIO, LPC ROM */
101         reg8 = pci_read_config8(dev, 0x48);
102         /* Decode ports 0x2e-0x2f, 0x4e-0x4f (SuperI/O configuration) */
103         reg8 |= (1 << 1) | (1 << 0);
104         /* Decode variable LPC ROM address ranges 1&2 (see register 0x68-0x6b, 0x6c-0x6f) */
105         reg8 |= (1 << 3) | (1 << 4);
106         /* Decode port 0x70-0x73 (RTC) */
107         reg8 |= 1 << 6;
108         pci_write_config8(dev, 0x48, reg8);
109
110         /* hardware should enable LPC ROM by pin straps */
111         /* ROM access at 0xFFF80000/0xFFF00000 - 0xFFFFFFFF */
112         /* See detail in BDG-215SB600-03.pdf page 15. */
113         /* enable LPC ROM range mirroring start 0x000e(0000) */
114         pci_write_config16(dev, 0x68, 0x000e);
115         /* enable LPC ROM range mirroring end   0x000f(ffff) */
116         pci_write_config16(dev, 0x6a, 0x000f);
117         /* enable LPC ROM range start, 0xfff8(0000): 512KB, 0xfff0(0000): 1MB, 0xffe0(0000): 2MB, 0xffc0(0000): 4MB */
118         pci_write_config16(dev, 0x6c, 0xffc0);
119         /* enable LPC ROM range end at 0xffff(ffff) */
120         pci_write_config16(dev, 0x6e, 0xffff);
121 }
122
123 /* what is its usage? */
124 static u32 get_sbdn(u32 bus)
125 {
126         device_t dev;
127
128         /* Find the device. */
129         dev = pci_locate_device_on_bus(PCI_ID(0x1002, 0x4385), bus);
130         return (dev >> 15) & 0x1f;
131 }
132
133 static u8 dual_core(void)
134 {
135         return (pci_read_config32(PCI_DEV(0, 0x18, 3), 0xE8) & (0x3<<12)) != 0;
136 }
137
138 /*
139  * SB600 VFSMAF (VID/FID System Management Action Field) is 010b by default.
140  * RPR 2.3.3 C-state and VID/FID change for the K8 platform.
141 */
142 static void enable_fid_change_on_sb(u32 sbbusn, u32 sbdn)
143 {
144         u8 byte;
145         byte = pmio_read(0x9a);
146         byte &= ~0x34;
147         if (dual_core())
148                 byte |= 0x34;
149         else
150                 byte |= 0x04;
151         pmio_write(0x9a, byte);
152
153         byte = pmio_read(0x8f);
154         byte &= ~0x30;
155         byte |= 0x20;
156         pmio_write(0x8f, byte);
157
158         pmio_write(0x8b, 0x01);
159         pmio_write(0x8a, 0x90);
160
161         if(get_sb600_revision() > 0x13)
162                 pmio_write(0x88, 0x10);
163         else
164                 pmio_write(0x88, 0x06);
165
166         byte = pmio_read(0x7c);
167         byte &= ~0x01;
168         byte |= 0x01;
169         pmio_write(0x7c, byte);
170
171         /* Must be 0 for K8 platform. */
172         byte = pmio_read(0x68);
173         byte &= ~0x01;
174         pmio_write(0x68, byte);
175         /* Must be 0 for K8 platform. */
176         byte = pmio_read(0x8d);
177         byte &= ~(1<<6);
178         pmio_write(0x8d, byte);
179
180         byte = pmio_read(0x61);
181         byte &= ~0x04;
182         pmio_write(0x61, byte);
183
184         byte = pmio_read(0x42);
185         byte &= ~0x04;
186         pmio_write(0x42, byte);
187
188         if (get_sb600_revision() == 0x14) {
189                 pmio_write(0x89, 0x10);
190
191                 byte = pmio_read(0x52);
192                 byte |= 0x80;
193                 pmio_write(0x52, byte);
194         }
195 }
196
197 void hard_reset(void)
198 {
199         set_bios_reset();
200
201         /* full reset */
202         outb(0x0a, 0x0cf9);
203         outb(0x0e, 0x0cf9);
204 }
205
206 void soft_reset(void)
207 {
208         set_bios_reset();
209         /* link reset */
210         outb(0x06, 0x0cf9);
211 }
212
213 void sb600_pci_port80(void)
214 {
215         u8 byte;
216         device_t dev;
217
218         /* P2P Bridge */
219         dev = pci_locate_device(PCI_ID(0x1002, 0x4384), 0);
220
221         /* Chip Control: Enable subtractive decoding */
222         byte = pci_read_config8(dev, 0x40);
223         byte |= 1 << 5;
224         pci_write_config8(dev, 0x40, byte);
225
226         /* Misc Control: Enable subtractive decoding if 0x40 bit 5 is set */
227         byte = pci_read_config8(dev, 0x4B);
228         byte |= 1 << 7;
229         pci_write_config8(dev, 0x4B, byte);
230
231         /* The same IO Base and IO Limit here is meaningful because we set the
232          * bridge to be subtractive. During early setup stage, we have to make
233          * sure that data can go through port 0x80.
234          */
235         /* IO Base: 0xf000 */
236         byte = pci_read_config8(dev, 0x1C);
237         byte |= 0xF << 4;
238         pci_write_config8(dev, 0x1C, byte);
239
240         /* IO Limit: 0xf000 */
241         byte = pci_read_config8(dev, 0x1D);
242         byte |= 0xF << 4;
243         pci_write_config8(dev, 0x1D, byte);
244
245         /* PCI Command: Enable IO response */
246         byte = pci_read_config8(dev, 0x04);
247         byte |= 1 << 0;
248         pci_write_config8(dev, 0x04, byte);
249
250         /* LPC controller */
251         dev = pci_locate_device(PCI_ID(0x1002, 0x438D), 0);
252
253         byte = pci_read_config8(dev, 0x4A);
254         byte &= ~(1 << 5);      /* disable lpc port 80 */
255         pci_write_config8(dev, 0x4A, byte);
256 }
257
258 void sb600_lpc_port80(void)
259 {
260         u8 byte;
261         device_t dev;
262         u32 reg32;
263
264         /* Enable LPC controller */
265         dev = pci_locate_device(PCI_ID(0x1002, 0x4385), 0);
266         reg32 = pci_read_config32(dev, 0x64);
267         reg32 |= 0x00100000;    /* lpcEnable */
268         pci_write_config32(dev, 0x64, reg32);
269
270         /* Enable port 80 LPC decode in pci function 3 configuration space. */
271         dev = pci_locate_device(PCI_ID(0x1002, 0x438d), 0);
272         byte = pci_read_config8(dev, 0x4a);
273         byte |= 1 << 5;         /* enable port 80 */
274         pci_write_config8(dev, 0x4a, byte);
275 }
276
277 /* sbDevicesPorInitTable */
278 static void sb600_devices_por_init(void)
279 {
280         device_t dev;
281         u8 byte;
282
283         printk(BIOS_INFO, "sb600_devices_por_init()\n");
284         /* SMBus Device, BDF:0-20-0 */
285         printk(BIOS_INFO, "sb600_devices_por_init(): SMBus Device, BDF:0-20-0\n");
286         dev = pci_locate_device(PCI_ID(0x1002, 0x4385), 0);
287
288         if (dev == PCI_DEV_INVALID) {
289                 die("SMBUS controller not found\n");
290                 /* NOT REACHED */
291         }
292         printk(BIOS_INFO, "SMBus controller enabled, sb revision is 0x%x\n",
293                     get_sb600_revision());
294
295         /* sbPorAtStartOfTblCfg */
296         /* Set A-Link bridge access address. This address is set at device 14h, function 0, register 0xf0.
297          * This is an I/O address. The I/O address must be on 16-byte boundry.  */
298         pci_write_config32(dev, 0xf0, AB_INDX);
299
300         /* To enable AB/BIF DMA access, a specific register inside the BIF register space needs to be configured first. */
301         /*Enables the SB600 to send transactions upstream over A-Link Express interface. */
302         axcfg_reg(0x04, 1 << 2, 1 << 2);
303         axindxc_reg(0x21, 0xff, 0);
304
305         /* 2.3.5:Enabling Non-Posted Memory Write for the K8 Platform */
306         axindxc_reg(0x10, 1 << 9, 1 << 9);
307         /* END of sbPorAtStartOfTblCfg */
308
309         /* sbDevicesPorInitTables */
310         /* set smbus iobase */
311         pci_write_config32(dev, 0x10, SMBUS_IO_BASE | 1);
312
313         /* enable smbus controller interface */
314         byte = pci_read_config8(dev, 0xd2);
315         byte |= (1 << 0);
316         pci_write_config8(dev, 0xd2, byte);
317
318         /* set smbus 1, ASF 2.0 (Alert Standard Format), iobase */
319         pci_write_config16(dev, 0x58, SMBUS_IO_BASE | 0x11);
320
321         /* TODO: I don't know the useage of followed two lines. I copied them from CIM. */
322         pci_write_config8(dev, 0x0a, 0x1);
323         pci_write_config8(dev, 0x0b, 0x6);
324
325         /* KB2RstEnable */
326         pci_write_config8(dev, 0x40, 0xd4);
327
328         /* Enable ISA Address 0-960K decoding */
329         pci_write_config8(dev, 0x48, 0x0f);
330
331         /* Enable ISA  Address 0xC0000-0xDFFFF decode */
332         pci_write_config8(dev, 0x49, 0xff);
333
334         /* Enable decode cycles to IO C50, C51, C52 GPM controls. */
335         byte = pci_read_config8(dev, 0x41);
336         byte &= 0x80;
337         byte |= 0x33;
338         pci_write_config8(dev, 0x41, byte);
339
340         /* Legacy DMA Prefetch Enhancement, CIM masked it. */
341         /* pci_write_config8(dev, 0x43, 0x1); */
342
343         /* Disabling Legacy USB Fast SMI# */
344         byte = pci_read_config8(dev, 0x62);
345         byte |= 0x24;
346         pci_write_config8(dev, 0x62, byte);
347
348         /* Features Enable */
349         pci_write_config32(dev, 0x64, 0x829E7DBF); /* bit10: Enables the HPET interrupt. */
350
351         /* SerialIrq Control */
352         pci_write_config8(dev, 0x69, 0x90);
353
354         /* Test Mode, PCIB_SReset_En Mask is set. */
355         pci_write_config8(dev, 0x6c, 0x20);
356
357         /* IO Address Enable, CIM set 0x78 only and masked 0x79. */
358         /*pci_write_config8(dev, 0x79, 0x4F); */
359         pci_write_config8(dev, 0x78, 0xFF);
360
361         /* This register is not used on sb600. It came from older chipset. */
362         /*pci_write_config8(dev, 0x95, 0xFF); */
363
364         /* Set smbus iospace enable, I don't know why write 0x04 into reg5 that is reserved */
365         pci_write_config16(dev, 0x4, 0x0407);
366
367         /* clear any lingering errors, so the transaction will run */
368         outb(inb(SMBUS_IO_BASE + SMBHSTSTAT), SMBUS_IO_BASE + SMBHSTSTAT);
369
370         /* IDE Device, BDF:0-20-1 */
371         printk(BIOS_INFO, "sb600_devices_por_init(): IDE Device, BDF:0-20-1\n");
372         dev = pci_locate_device(PCI_ID(0x1002, 0x438C), 0);
373         /* Disable prefetch */
374         byte = pci_read_config8(dev, 0x63);
375         byte |= 0x1;
376         pci_write_config8(dev, 0x63, byte);
377
378         /* LPC Device, BDF:0-20-3 */
379         printk(BIOS_INFO, "sb600_devices_por_init(): LPC Device, BDF:0-20-3\n");
380         dev = pci_locate_device(PCI_ID(0x1002, 0x438D), 0);
381         /* DMA enable */
382         pci_write_config8(dev, 0x40, 0x04);
383
384         /* IO Port Decode Enable */
385         pci_write_config8(dev, 0x44, 0xFF);
386         pci_write_config8(dev, 0x45, 0xFF);
387         pci_write_config8(dev, 0x46, 0xC3);
388         pci_write_config8(dev, 0x47, 0xFF);
389
390         /* IO/Mem Port Decode Enable, I don't know why CIM disable some ports.
391          *  Disable LPC TimeOut counter, enable SuperIO Configuration Port (2e/2f),
392          * Alternate SuperIO Configuration Port (4e/4f), Wide Generic IO Port (64/65).
393          * Enable bits for LPC ROM memory address range 1&2 for 1M ROM setting.*/
394         byte = pci_read_config8(dev, 0x48);
395         byte |= (1 << 1) | (1 << 0);    /* enable Super IO config port 2e-2h, 4e-4f */
396         byte |= (1 << 3) | (1 << 4);    /* enable for LPC ROM address range1&2, Enable 512KB rom access at 0xFFF80000 - 0xFFFFFFFF */
397         byte |= 1 << 6;         /* enable for RTC I/O range */
398         pci_write_config8(dev, 0x48, byte);
399         pci_write_config8(dev, 0x49, 0xFF);
400         /* Enable 0x480-0x4bf, 0x4700-0x470B */
401         byte = pci_read_config8(dev, 0x4A);
402         byte |= ((1 << 1) + (1 << 6));  /*0x42, save the configuraion for port 0x80. */
403         pci_write_config8(dev, 0x4A, byte);
404
405         /* Set LPC ROM size, it has been done in sb600_lpc_init().
406          * enable LPC ROM range, 0xfff8: 512KB, 0xfff0: 1MB;
407          * enable LPC ROM range, 0xfff8: 512KB, 0xfff0: 1MB
408          * pci_write_config16(dev, 0x68, 0x000e)
409          * pci_write_config16(dev, 0x6c, 0xfff0);*/
410
411         /* Enable Tpm12_en and Tpm_legacy. I don't know what is its usage and copied from CIM. */
412         pci_write_config8(dev, 0x7C, 0x05);
413
414         /* P2P Bridge, BDF:0-20-4, the configuration of the registers in this dev are copied from CIM,
415          * TODO: I don't know what are their mean? */
416         printk(BIOS_INFO, "sb600_devices_por_init(): P2P Bridge, BDF:0-20-4\n");
417         dev = pci_locate_device(PCI_ID(0x1002, 0x4384), 0);
418         /* I don't know why CIM tried to write into a read-only reg! */
419         /*pci_write_config8(dev, 0x0c, 0x20) */ ;
420
421         /* Arbiter enable. */
422         pci_write_config8(dev, 0x43, 0xff);
423
424         /* Set PCDMA request into hight priority list. */
425         /* pci_write_config8(dev, 0x49, 0x1) */ ;
426
427         pci_write_config8(dev, 0x40, 0x26);
428
429         /* I don't know why CIM set reg0x1c as 0x11.
430          * System will block at sdram_initialize() if I set it before call sdram_initialize().
431          * If it is necessary to set reg0x1c as 0x11, please call this function after sdram_initialize().
432          * pci_write_config8(dev, 0x1c, 0x11);
433          * pci_write_config8(dev, 0x1d, 0x11);*/
434
435         /*CIM set this register; but I didn't find its description in RPR.
436         On DBM690T platform, I didn't find different between set and skip this register.
437         But on Filbert platform, the DEBUG message from serial port on Peanut board can't be displayed
438         after the bit0 of this register is set.
439         pci_write_config8(dev, 0x04, 0x21);
440         */
441         pci_write_config8(dev, 0x0d, 0x40);
442         pci_write_config8(dev, 0x1b, 0x40);
443         /* Enable PCIB_DUAL_EN_UP will fix potential problem with PCI cards. */
444         pci_write_config8(dev, 0x50, 0x01);
445
446         /* SATA Device, BDF:0-18-0, Non-Raid-5 SATA controller */
447         printk(BIOS_INFO, "sb600_devices_por_init(): SATA Device, BDF:0-18-0\n");
448         dev = pci_locate_device(PCI_ID(0x1002, 0x4380), 0);
449
450         /*PHY Global Control, we are using A14.
451          * default:  0x2c40 for ASIC revision A12 and below
452          *      0x2c00 for ASIC revision A13 and above.*/
453         pci_write_config16(dev, 0x86, 0x2C00);
454
455         /* PHY Port0-3 Control */
456         pci_write_config32(dev, 0x88, 0xB400DA);
457         pci_write_config32(dev, 0x8c, 0xB400DA);
458         pci_write_config32(dev, 0x90, 0xB400DA);
459         pci_write_config32(dev, 0x94, 0xB400DA);
460
461         /* Port0-3 BIST Control/Status */
462         pci_write_config8(dev, 0xa5, 0xB8);
463         pci_write_config8(dev, 0xad, 0xB8);
464         pci_write_config8(dev, 0xb5, 0xB8);
465         pci_write_config8(dev, 0xbd, 0xB8);
466 }
467
468 /* sbPmioPorInitTable, Pre-initializing PMIO register space
469 * The power management (PM) block is resident in the PCI/LPC/ISA bridge.
470 * The PM regs are accessed via IO mapped regs 0xcd6 and 0xcd7.
471 * The index address is first programmed into IO reg 0xcd6.
472 * Read or write values are accessed through IO reg 0xcd7.
473 */
474 static void sb600_pmio_por_init(void)
475 {
476         u8 byte;
477
478         printk(BIOS_INFO, "sb600_pmio_por_init()\n");
479         /* K8KbRstEn, KB_RST# control for K8 system. */
480         byte = pmio_read(0x66);
481         byte |= 0x20;
482         pmio_write(0x66, byte);
483
484         /* RPR2.3.4 S3/S4/S5 Function for the K8 Platform. */
485         byte = pmio_read(0x52);
486         byte &= 0xc0;
487         byte |= 0x08;
488         pmio_write(0x52, byte);
489
490         /* C state enable and SLP enable in C states. */
491         byte = pmio_read(0x67);
492         byte |= 0x6;
493         pmio_write(0x67, byte);
494
495         /* CIM sets 0x0e, but bit2 is for P4 system. */
496         byte = pmio_read(0x68);
497         byte &= 0xf0;
498         byte |= 0x0c;
499         pmio_write(0x68, byte);
500
501         /* Watch Dog Timer Control
502          * Set watchdog time base to 0xfec000f0 to avoid SCSI card boot failure.
503          * But I don't find WDT is enabled in SMBUS 0x41 bit3 in CIM.
504          */
505         pmio_write(0x6c, 0xf0);
506         pmio_write(0x6d, 0x00);
507         pmio_write(0x6e, 0xc0);
508         pmio_write(0x6f, 0xfe);
509
510         /* rpr2.14: Enables HPET periodical mode */
511         byte = pmio_read(0x9a);
512         byte |= 1 << 7;
513         pmio_write(0x9a, byte);
514         byte = pmio_read(0x9f);
515         byte |= 1 << 5;
516         pmio_write(0x9f, byte);
517         byte = pmio_read(0x9e);
518         byte |= (1 << 6) | (1 << 7);
519         pmio_write(0x9e, byte);
520
521         /* rpr2.14: Hides SM bus controller Bar1 where stores HPET MMIO base address */
522         /* We have to clear this bit here, otherwise the kernel hangs. */
523         byte = pmio_read(0x55);
524         byte |= 1 << 7;
525         byte |= 1 << 1;
526         pmio_write(0x55, byte);
527
528         /* rpr2.14: Make HPET MMIO decoding controlled by the memory enable bit in command register of LPC ISA bridage */
529         byte = pmio_read(0x52);
530         byte |= 1 << 6;
531         pmio_write(0x52, byte);
532
533         /* rpr2.22: PLL Reset */
534         byte = pmio_read(0x86);
535         byte |= 1 << 7;
536         pmio_write(0x86, byte);
537
538         /* rpr2.3.3 */
539         /* This provides 16us delay before the assertion of LDTSTP# when C3 is entered.
540         * The delay will allow USB DMA to go on in a continuous manner
541         */
542         pmio_write(0x89, 0x10);
543         /* Set this bit to allow pop-up request being latched during the minimum LDTSTP# assertion time */
544         byte = pmio_read(0x52);
545         byte |= 1 << 7;
546         pmio_write(0x52, byte);
547
548         /* rpr2.15: ASF Remote Control Action */
549         byte = pmio_read(0x9f);
550         byte |= 1 << 6;
551         pmio_write(0x9f, byte);
552
553         /* rpr2.19: Enabling Spread Spectrum */
554         byte = pmio_read(0x42);
555         byte |= 1 << 7;
556         pmio_write(0x42, byte);
557 }
558
559 /*
560 * Compliant with CIM_48's sbPciCfg.
561 * Add any south bridge setting.
562 */
563 static void sb600_pci_cfg(void)
564 {
565         device_t dev;
566         u8 byte;
567
568         /* SMBus Device, BDF:0-20-0 */
569         dev = pci_locate_device(PCI_ID(0x1002, 0x4385), 0);
570         /* Eable the hidden revision ID, available after A13. */
571         byte = pci_read_config8(dev, 0x70);
572         byte |= (1 << 8);
573         pci_write_config8(dev, 0x70, byte);
574         /* rpr2.20 Disable Timer IRQ Enhancement for proper operation of the 8254 timer, 0xae[5]. */
575         byte = pci_read_config8(dev, 0xae);
576         byte |= (1 << 5);
577         pci_write_config8(dev, 0xae, byte);
578
579         /* Enable watchdog decode timer */
580         byte = pci_read_config8(dev, 0x41);
581         byte |= (1 << 3);
582         pci_write_config8(dev, 0x41, byte);
583
584         /* Set to 1 to reset USB on the software (such as IO-64 or IO-CF9 cycles)
585          * generated PCIRST#. */
586         byte = pmio_read(0x65);
587         byte |= (1 << 4);
588         pmio_write(0x65, byte);
589         /*For A13 and above. */
590         if (get_sb600_revision() > 0x12) {
591                 /* rpr2.16 C-State Reset, PMIO 0x9f[7]. */
592                 byte = pmio_read(0x9f);
593                 byte |= (1 << 7);
594                 pmio_write(0x9f, byte);
595                 /* rpr2.17 PCI Clock Period will increase to 30.8ns. 0x53[7]. */
596                 byte = pmio_read(0x53);
597                 byte |= (1 << 7);
598                 pmio_write(0x53, byte);
599         }
600
601         /* IDE Device, BDF:0-20-1 */
602         dev = pci_locate_device(PCI_ID(0x1002, 0x438C), 0);
603         /* Enable IDE Explicit prefetch, 0x63[0] clear */
604         byte = pci_read_config8(dev, 0x63);
605         byte &= 0xfe;
606         pci_write_config8(dev, 0x63, byte);
607
608         /* LPC Device, BDF:0-20-3 */
609         dev = pci_locate_device(PCI_ID(0x1002, 0x438D), 0);
610         /* rpr7.2 Enabling LPC DMA function. */
611         byte = pci_read_config8(dev, 0x40);
612         byte |= (1 << 2);
613         pci_write_config8(dev, 0x40, byte);
614         /* rpr7.3 Disabling LPC TimeOut. 0x48[7] clear. */
615         byte = pci_read_config8(dev, 0x48);
616         byte &= 0x7f;
617         pci_write_config8(dev, 0x48, byte);
618         /* rpr7.5 Disabling LPC MSI Capability, 0x78[1] clear. */
619         byte = pci_read_config8(dev, 0x78);
620         byte &= 0xfd;
621         pci_write_config8(dev, 0x78, byte);
622
623         /* SATA Device, BDF:0-18-0, Non-Raid-5 SATA controller */
624         dev = pci_locate_device(PCI_ID(0x1002, 0x4380), 0);
625         /* rpr6.8 Disabling SATA MSI Capability, for A13 and above, 0x42[7]. */
626         if (0x12 < get_sb600_revision()) {
627                 u32 reg32;
628                 reg32 = pci_read_config32(dev, 0x40);
629                 reg32 |= (1 << 23);
630                 pci_write_config32(dev, 0x40, reg32);
631         }
632
633         /* EHCI Device, BDF:0-19-5, ehci usb controller */
634         dev = pci_locate_device(PCI_ID(0x1002, 0x4386), 0);
635         /* rpr5.10 Disabling USB EHCI MSI Capability. 0x50[6]. */
636         byte = pci_read_config8(dev, 0x50);
637         byte |= (1 << 6);
638         pci_write_config8(dev, 0x50, byte);
639
640         /* OHCI0 Device, BDF:0-19-0, ohci usb controller #0 */
641         dev = pci_locate_device(PCI_ID(0x1002, 0x4387), 0);
642         /* rpr5.11 Disabling USB OHCI MSI Capability. 0x40[12:8]=0x1f. */
643         byte = pci_read_config8(dev, 0x41);
644         byte |= 0x1f;
645         pci_write_config8(dev, 0x41, byte);
646
647 }
648
649 /*
650 * Compliant with CIM_48's ATSBPowerOnResetInitJSP
651 */
652 static void sb600_por_init(void)
653 {
654         /* sbDevicesPorInitTable + sbK8PorInitTable */
655         sb600_devices_por_init();
656
657         /* sbPmioPorInitTable + sbK8PmioPorInitTable */
658         sb600_pmio_por_init();
659 }
660
661 /*
662 * Compliant with CIM_48's AtiSbBeforePciInit
663 * It should be called during early POST after memory detection and BIOS shadowing but before PCI bus enumeration.
664 */
665 static void sb600_before_pci_init(void)
666 {
667         sb600_pci_cfg();
668 }
669
670 /*
671 * This function should be called after enable_sb600_smbus().
672 */
673 static void sb600_early_setup(void)
674 {
675         printk(BIOS_INFO, "sb600_early_setup()\n");
676         sb600_por_init();
677 }
678
679 static int smbus_read_byte(u32 device, u32 address)
680 {
681         return do_smbus_read_byte(SMBUS_IO_BASE, device, address);
682 }
683