2 * This file is part of the coreboot project.
4 * Copyright (C) 2004 Tyan Computer
5 * Written by Yinghai Lu <yhlu@tyan.com> for Tyan Computer.
7 * This program is free software; you can redistribute it and/or modify
8 * it under the terms of the GNU General Public License as published by
9 * the Free Software Foundation; version 2 of the License.
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.
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
23 #include <arch/romcc_io.h>
24 #include <console/console.h>
25 #include <device/pci_def.h>
26 #include <device/pci_ids.h>
29 #include "early_smbus.h"
31 #define SMBUS_BAR_BASE 0x20
32 #define SMBUS_IO_BASE 0x1000
33 #define SMBUS_IO_SIZE 0x0040
35 #define SMBUS_BAR(x) (SMBUS_BAR_BASE + 4 * (x))
36 #define SMBUS_BASE(x) (SMBUS_IO_BASE + SMBUS_IO_SIZE * (x))
38 void enable_smbus(void)
42 dev = pci_locate_device(PCI_ID(PCI_VENDOR_ID_NVIDIA,
43 PCI_DEVICE_ID_NVIDIA_CK804_SMB), 0);
44 if (dev == PCI_DEV_INVALID)
45 die("SMBus controller not found\n");
47 /* Set SMBus I/O base. */
48 pci_write_config32(dev, SMBUS_BAR(0), SMBUS_BASE(0) | 1);
49 pci_write_config32(dev, SMBUS_BAR(1), SMBUS_BASE(1) | 1);
51 /* Set SMBus I/O space enable. */
52 pci_write_config16(dev, 0x4, 0x01);
54 /* Clear any lingering errors, so the transaction will run. */
55 outb(inb(SMBUS_BASE(0) + SMBHSTSTAT), SMBUS_BASE(0) + SMBHSTSTAT);
56 outb(inb(SMBUS_BASE(1) + SMBHSTSTAT), SMBUS_BASE(1) + SMBHSTSTAT);
58 print_debug("SMBus controller enabled\n");
61 int ck804_smbus_read_byte(unsigned bus, unsigned device, unsigned address)
63 return do_smbus_read_byte(SMBUS_BASE(bus), device, address);
66 int ck804_smbus_write_byte(unsigned bus, unsigned device, unsigned address,
69 return do_smbus_write_byte(SMBUS_BASE(bus), device, address, val);
72 int smbus_read_byte(unsigned device, unsigned address)
74 return ck804_smbus_read_byte(0, device, address);
77 int smbus_write_byte(unsigned device, unsigned address, unsigned char val)
79 return ck804_smbus_write_byte(0, device, address, val);