CK804: Cosmetic fixes, switch to u8 et al.
[coreboot.git] / src / southbridge / nvidia / ck804 / early_smbus.c
1 /*
2  * This file is part of the coreboot project.
3  *
4  * Copyright (C) 2004 Tyan Computer
5  * Written by Yinghai Lu <yhlu@tyan.com> for Tyan Computer.
6  *
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.
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.
15  *
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
19  */
20
21 #include <stdint.h>
22 #include <arch/io.h>
23 #include <arch/romcc_io.h>
24 #include <console/console.h>
25 #include <device/pci_def.h>
26 #include <device/pci_ids.h>
27
28 #include "smbus.h"
29 #include "early_smbus.h"
30
31 #define SMBUS_BAR_BASE 0x20
32 #define SMBUS_IO_BASE 0x1000
33 #define SMBUS_IO_SIZE 0x0040
34
35 #define SMBUS_BAR(x) (SMBUS_BAR_BASE + 4 * (x))
36 #define SMBUS_BASE(x) (SMBUS_IO_BASE + SMBUS_IO_SIZE * (x))
37
38 void enable_smbus(void)
39 {
40         device_t dev;
41
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");
46
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);
50
51         /* Set SMBus I/O space enable. */
52         pci_write_config16(dev, 0x4, 0x01);
53
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);
57
58         print_debug("SMBus controller enabled\n");
59 }
60
61 int ck804_smbus_read_byte(unsigned bus, unsigned device, unsigned address)
62 {
63         return do_smbus_read_byte(SMBUS_BASE(bus), device, address);
64 }
65
66 int ck804_smbus_write_byte(unsigned bus, unsigned device, unsigned address,
67                            unsigned char val)
68 {
69         return do_smbus_write_byte(SMBUS_BASE(bus), device, address, val);
70 }
71
72 int smbus_read_byte(unsigned device, unsigned address)
73 {
74         return ck804_smbus_read_byte(0, device, address);
75 }
76
77 int smbus_write_byte(unsigned device, unsigned address, unsigned char val)
78 {
79         return ck804_smbus_write_byte(0, device, address, val);
80 }