Vladimir Serbinenko | 888d559 | 2013-11-13 17:53:38 +0100 | [diff] [blame] | 1 | /* |
| 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. |
Vladimir Serbinenko | 888d559 | 2013-11-13 17:53:38 +0100 | [diff] [blame] | 15 | */ |
| 16 | |
| 17 | #include <arch/io.h> |
| 18 | #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 | |
| 24 | void 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 Reinauer | 5ab52dd | 2015-01-05 13:01:01 -0800 | [diff] [blame] | 51 | printk(BIOS_DEBUG, "SMBus controller enabled.\n"); |
Vladimir Serbinenko | 888d559 | 2013-11-13 17:53:38 +0100 | [diff] [blame] | 52 | } |
| 53 | |
| 54 | int smbus_read_byte(unsigned device, unsigned address) |
| 55 | { |
| 56 | return do_smbus_read_byte(SMBUS_IO_BASE, device, address); |
| 57 | } |
| 58 | |
| 59 | int smbus_write_byte(unsigned device, unsigned address, u8 data) |
| 60 | { |
| 61 | return do_smbus_write_byte(SMBUS_IO_BASE, device, address, data); |
| 62 | } |
| 63 | |
| 64 | int smbus_block_read(unsigned device, unsigned cmd, u8 bytes, u8 *buf) |
| 65 | { |
| 66 | return do_smbus_block_read(SMBUS_IO_BASE, device, cmd, bytes, buf); |
| 67 | } |
| 68 | |
| 69 | int smbus_block_write(unsigned device, unsigned cmd, u8 bytes, const u8 *buf) |
| 70 | { |
| 71 | return do_smbus_block_write(SMBUS_IO_BASE, device, cmd, bytes, buf); |
| 72 | } |