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