b7c79075eb02144e96685116abb1a3c87b4dca0f
[coreboot.git] / src / southbridge / intel / i82371eb / i82371eb_early_smbus.c
1 /*
2  * This file is part of the coreboot project.
3  *
4  * Copyright (C) 2007 Uwe Hermann <uwe@hermann-uwe.de>
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; either version 2 of the License, or
9  * (at your option) any later version.
10  *
11  * This program is distributed in the hope that it will be useful,
12  * but WITHOUT ANY WARRANTY; without even the implied warranty of
13  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
14  * GNU General Public License for more details.
15  *
16  * You should have received a copy of the GNU General Public License
17  * along with this program; if not, write to the Free Software
18  * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301 USA
19  */
20
21 #include <stdint.h>
22 #include <arch/io.h>
23 #include <arch/romcc_io.h>
24 #include <console/console.h>
25 #include <device/pci_ids.h>
26 #include <device/pci_def.h>
27 #include "i82371eb.h"
28 #include "i82371eb_smbus.h"
29
30 int smbus_read_byte(u8 device, u8 address);
31
32 void enable_smbus(void)
33 {
34         device_t dev;
35         u8 reg8;
36         u16 reg16;
37
38         /* Get the SMBus/PM device of the 82371AB/EB/MB. */
39         dev = pci_locate_device(PCI_ID(PCI_VENDOR_ID_INTEL,
40                                 PCI_DEVICE_ID_INTEL_82371AB_SMB_ACPI), 0);
41
42         /* Set the SMBus I/O base. */
43         pci_write_config32(dev, SMBBA, SMBUS_IO_BASE | 1);
44
45         /* Enable the SMBus controller host interface. */
46         reg8 = pci_read_config8(dev, SMBHSTCFG);
47         reg8 |= SMB_HST_EN;
48         pci_write_config8(dev, SMBHSTCFG, reg8);
49
50         /* Enable access to the SMBus I/O space. */
51         reg16 = pci_read_config16(dev, PCI_COMMAND);
52         reg16 |= PCI_COMMAND_IO;
53         pci_write_config16(dev, PCI_COMMAND, reg16);
54
55         /* Clear any lingering errors, so the transaction will run. */
56         outb(inb(SMBUS_IO_BASE + SMBHST_STATUS), SMBUS_IO_BASE + SMBHST_STATUS);
57 }
58
59 int smbus_read_byte(u8 device, u8 address)
60 {
61         return do_smbus_read_byte(SMBUS_IO_BASE, device, address);
62 }