Round 2 of i82801AX fixes to get it into a usable shape.
[coreboot.git] / src / southbridge / intel / i82801ax / i82801ax_smbus.c
1 /*
2  * This file is part of the coreboot project.
3  *
4  * Copyright (C) 2005 Yinghai Lu <yinghailu@gmail.com>
5  *
6  * This program is free software; you can redistribute it and/or modify
7  * it under the terms of the GNU General Public License as published by
8  * the Free Software Foundation; either version 2 of the License, or
9  * (at your option) any later version.
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 <device/smbus.h>
23 #include <device/pci.h>
24 #include <device/pci_ids.h>
25 #include <arch/io.h>
26 #include "i82801ax.h"
27 #include "i82801ax_smbus.h"
28
29 static int lsmbus_read_byte(device_t dev, u8 address)
30 {
31         u16 device;
32         struct resource *res;
33         struct bus *pbus;
34
35         device = dev->path.i2c.device;
36         pbus = get_pbus_smbus(dev);
37         res = find_resource(pbus->dev, 0x20);
38
39         return do_smbus_read_byte(res->base, device, address);
40 }
41
42 static struct smbus_bus_operations lops_smbus_bus = {
43         .read_byte      = lsmbus_read_byte,
44 };
45
46 static const struct device_operations smbus_ops = {
47         .read_resources         = pci_dev_read_resources,
48         .set_resources          = pci_dev_set_resources,
49         .enable_resources       = pci_dev_enable_resources,
50         .init                   = 0,
51         .scan_bus               = scan_static_bus,
52         .enable                 = i82801ax_enable,
53         .ops_smbus_bus          = &lops_smbus_bus,
54 };
55
56 /* 82801AA (ICH) */
57 static const struct pci_driver i82801aa_smb __pci_driver = {
58         .ops    = &smbus_ops,
59         .vendor = PCI_VENDOR_ID_INTEL,
60         .device = PCI_DEVICE_ID_INTEL_82801AA_SMB,
61 };
62
63 /* 82801AB (ICH0) */
64 static const struct pci_driver i82801ab_smb __pci_driver = {
65         .ops    = &smbus_ops,
66         .vendor = PCI_VENDOR_ID_INTEL,
67         .device = PCI_DEVICE_ID_INTEL_82801AB_SMB,
68 };