070cc22a00e0f0c5c7c1f6d13ddfb6bfc8644cf6
[coreboot.git] / src / southbridge / intel / i82801xx / i82801xx_early_smbus.c
1 /*
2  * This file is part of the LinuxBIOS project.
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.
17  *
18  * You should have received a copy of the GNU General Public License
19  * along with this program; if not, write to the Free Software
20  * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301 USA
21  */
22
23 #include <device/pci_ids.h>
24 #include "i82801xx.h"
25 #include "i82801xx_smbus.h"
26
27 static void enable_smbus(void)
28 {
29         device_t dev;
30         uint16_t device_id;
31         
32         /* Set the SMBus device staticly */
33         dev = PCI_DEV(0x0, 0x1f, 0x3);
34         
35         /* Check to make sure we've got the right device */
36         device_id = pci_read_config16(dev, 0x2);
37         
38         /* Clear bits 7-4, since those are the only bits that vary between models */
39         device_id &= 0xff0f;
40         
41         if(device_id != 0x2403)
42         {
43                 die("Device not found, Corey probably screwed up!");
44         }
45         
46         /* Set SMBus I/O base */
47         pci_write_config32(dev, SMB_BASE, SMBUS_IO_BASE | PCI_BASE_ADDRESS_SPACE_IO);
48         /* Set SMBus enable */
49         pci_write_config8(dev, HOSTC, HST_EN);
50         /* Set SMBus I/O space enable */ 
51         pci_write_config16(dev, PCI_COMMAND, PCI_COMMAND_IO);
52         /* Disable interrupt generation */ 
53         outb(0, SMBUS_IO_BASE + SMBHSTCTL);
54         /* Clear any lingering errors, so transactions can run */
55         outb(inb(SMBUS_IO_BASE + SMBHSTSTAT), SMBUS_IO_BASE + SMBHSTSTAT);
56         print_debug("SMBus controller enabled\r\n");
57 }
58
59 static inline int smbus_read_byte(unsigned device, unsigned address)
60 {
61         return do_smbus_read_byte(device, address);
62 }
63
64 static void smbus_write_byte(unsigned device, unsigned address, unsigned char val)
65 {
66         print_err("Unimplemented smbus_write_byte() called\r\n");
67         return;
68 }
69
70 static inline int smbus_write_block(unsigned device, unsigned length, unsigned cmd, 
71                  unsigned data1, unsigned data2)
72 {
73         return do_smbus_write_block(device, length, cmd, data1, data2);
74 }