blob: 2b174c787ae4858f133627724825b85c06b1e261 [file] [log] [blame]
Aaron Durbin76c37002012-10-30 09:03:43 -05001/*
2 * This file is part of the coreboot project.
3 *
4 * Copyright (C) 2008-2009 coresystems GmbH
5 *
6 * This program is free software; you can redistribute it and/or
7 * modify it under the terms of the GNU General Public License as
8 * published by the Free Software Foundation; version 2 of
9 * the License.
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.
Aaron Durbin76c37002012-10-30 09:03:43 -050015 */
16
17#include <arch/io.h>
Aaron Durbin76c37002012-10-30 09:03:43 -050018#include <console/console.h>
19#include <device/pci_ids.h>
20#include <device/pci_def.h>
21#include "pch.h"
22#include "smbus.h"
23
24void enable_smbus(void)
25{
26 device_t dev;
27
28 /* Set the SMBus device statically. */
29 dev = PCI_DEV(0x0, 0x1f, 0x3);
30
31 /* Check to make sure we've got the right device. */
32 if (pci_read_config16(dev, 0x0) != 0x8086) {
33 die("SMBus controller not found!");
34 }
35
36 /* Set SMBus I/O base. */
37 pci_write_config32(dev, SMB_BASE,
38 SMBUS_IO_BASE | PCI_BASE_ADDRESS_SPACE_IO);
39
40 /* Set SMBus enable. */
41 pci_write_config8(dev, HOSTC, HST_EN);
42
43 /* Set SMBus I/O space enable. */
44 pci_write_config16(dev, PCI_COMMAND, PCI_COMMAND_IO);
45
46 /* Disable interrupt generation. */
47 outb(0, SMBUS_IO_BASE + SMBHSTCTL);
48
49 /* Clear any lingering errors, so transactions can run. */
50 outb(inb(SMBUS_IO_BASE + SMBHSTSTAT), SMBUS_IO_BASE + SMBHSTSTAT);
Stefan Reinauer5ab52dd2015-01-05 13:01:01 -080051 printk(BIOS_DEBUG, "SMBus controller enabled.\n");
Aaron Durbin76c37002012-10-30 09:03:43 -050052}
53
54int smbus_read_byte(unsigned device, unsigned address)
55{
56 return do_smbus_read_byte(SMBUS_IO_BASE, device, address);
57}