Corey Osgood | e99bd10 | 2007-06-14 06:10:57 +0000 | [diff] [blame] | 1 | /* |
Stefan Reinauer | 7e61e45 | 2008-01-18 10:35:56 +0000 | [diff] [blame] | 2 | * This file is part of the coreboot project. |
Corey Osgood | e99bd10 | 2007-06-14 06:10:57 +0000 | [diff] [blame] | 3 | * |
| 4 | * Copyright (C) 2005 Tyan Computer |
| 5 | * (Written by Yinghai Lu <yinghailu@gmail.com> for Tyan Computer) |
| 6 | * Copyright (C) 2007 Corey Osgood <corey.osgood@gmail.com> |
| 7 | * |
| 8 | * This program is free software; you can redistribute it and/or modify |
| 9 | * it under the terms of the GNU General Public License as published by |
| 10 | * the Free Software Foundation; either version 2 of the License, or |
| 11 | * (at your option) any later version. |
| 12 | * |
| 13 | * This program is distributed in the hope that it will be useful, |
| 14 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 15 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 16 | * GNU General Public License for more details. |
Corey Osgood | e99bd10 | 2007-06-14 06:10:57 +0000 | [diff] [blame] | 17 | */ |
| 18 | |
Uwe Hermann | 212d0a2 | 2010-10-13 23:00:41 +0000 | [diff] [blame] | 19 | #include <arch/io.h> |
Uwe Hermann | 212d0a2 | 2010-10-13 23:00:41 +0000 | [diff] [blame] | 20 | #include <console/console.h> |
Corey Osgood | e99bd10 | 2007-06-14 06:10:57 +0000 | [diff] [blame] | 21 | #include <device/pci_ids.h> |
Uwe Hermann | 212d0a2 | 2010-10-13 23:00:41 +0000 | [diff] [blame] | 22 | #include <device/pci_def.h> |
Stefan Reinauer | 138be83 | 2010-02-27 01:50:21 +0000 | [diff] [blame] | 23 | #include "i82801bx.h" |
stepan | 836ae29 | 2010-12-08 05:42:47 +0000 | [diff] [blame] | 24 | #include "smbus.h" |
Corey Osgood | e99bd10 | 2007-06-14 06:10:57 +0000 | [diff] [blame] | 25 | |
Uwe Hermann | 212d0a2 | 2010-10-13 23:00:41 +0000 | [diff] [blame] | 26 | void enable_smbus(void) |
Corey Osgood | e99bd10 | 2007-06-14 06:10:57 +0000 | [diff] [blame] | 27 | { |
| 28 | device_t dev; |
Uwe Hermann | dfb3c13 | 2007-06-19 22:47:11 +0000 | [diff] [blame] | 29 | |
Uwe Hermann | 0ea281f | 2010-10-11 21:38:49 +0000 | [diff] [blame] | 30 | /* Set the SMBus device statically (D31:F3). */ |
Corey Osgood | e99bd10 | 2007-06-14 06:10:57 +0000 | [diff] [blame] | 31 | dev = PCI_DEV(0x0, 0x1f, 0x3); |
Uwe Hermann | dfb3c13 | 2007-06-19 22:47:11 +0000 | [diff] [blame] | 32 | |
Uwe Hermann | dfb3c13 | 2007-06-19 22:47:11 +0000 | [diff] [blame] | 33 | /* Set SMBus I/O base. */ |
| 34 | pci_write_config32(dev, SMB_BASE, |
| 35 | SMBUS_IO_BASE | PCI_BASE_ADDRESS_SPACE_IO); |
| 36 | |
| 37 | /* Set SMBus enable. */ |
Corey Osgood | e99bd10 | 2007-06-14 06:10:57 +0000 | [diff] [blame] | 38 | pci_write_config8(dev, HOSTC, HST_EN); |
Uwe Hermann | dfb3c13 | 2007-06-19 22:47:11 +0000 | [diff] [blame] | 39 | |
| 40 | /* Set SMBus I/O space enable. */ |
Corey Osgood | e99bd10 | 2007-06-14 06:10:57 +0000 | [diff] [blame] | 41 | pci_write_config16(dev, PCI_COMMAND, PCI_COMMAND_IO); |
Uwe Hermann | dfb3c13 | 2007-06-19 22:47:11 +0000 | [diff] [blame] | 42 | |
| 43 | /* Disable interrupt generation. */ |
Corey Osgood | e99bd10 | 2007-06-14 06:10:57 +0000 | [diff] [blame] | 44 | outb(0, SMBUS_IO_BASE + SMBHSTCTL); |
Uwe Hermann | dfb3c13 | 2007-06-19 22:47:11 +0000 | [diff] [blame] | 45 | |
| 46 | /* Clear any lingering errors, so transactions can run. */ |
Corey Osgood | e99bd10 | 2007-06-14 06:10:57 +0000 | [diff] [blame] | 47 | outb(inb(SMBUS_IO_BASE + SMBHSTSTAT), SMBUS_IO_BASE + SMBHSTSTAT); |
Uwe Hermann | dfb3c13 | 2007-06-19 22:47:11 +0000 | [diff] [blame] | 48 | |
Stefan Reinauer | 5ab52dd | 2015-01-05 13:01:01 -0800 | [diff] [blame] | 49 | printk(BIOS_DEBUG, "SMBus controller enabled\n"); |
Corey Osgood | e99bd10 | 2007-06-14 06:10:57 +0000 | [diff] [blame] | 50 | } |
| 51 | |
Uwe Hermann | 212d0a2 | 2010-10-13 23:00:41 +0000 | [diff] [blame] | 52 | int smbus_read_byte(u8 device, u8 address) |
Corey Osgood | e99bd10 | 2007-06-14 06:10:57 +0000 | [diff] [blame] | 53 | { |
Uwe Hermann | 3b8db81 | 2010-10-08 16:40:23 +0000 | [diff] [blame] | 54 | return do_smbus_read_byte(SMBUS_IO_BASE, device, address); |
Corey Osgood | e99bd10 | 2007-06-14 06:10:57 +0000 | [diff] [blame] | 55 | } |