CK804: Cosmetic fixes, switch to u8 et al.
[coreboot.git] / src / southbridge / nvidia / ck804 / 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 <console/console.h>
22 #include <device/device.h>
23 #include <device/pci.h>
24 #include <device/pci_ids.h>
25 #include <device/pci_ops.h>
26 #include <device/smbus.h>
27 #include <bitops.h>
28 #include <arch/io.h>
29 #include "ck804.h"
30 #include "smbus.h"
31
32 static int lsmbus_recv_byte(device_t dev)
33 {
34         unsigned device;
35         struct resource *res;
36         struct bus *pbus;
37
38         device = dev->path.i2c.device;
39         pbus = get_pbus_smbus(dev);
40
41         res = find_resource(pbus->dev, 0x20 + (pbus->link_num * 4));
42
43         return do_smbus_recv_byte(res->base, device);
44 }
45
46 static int lsmbus_send_byte(device_t dev, u8 val)
47 {
48         unsigned device;
49         struct resource *res;
50         struct bus *pbus;
51
52         device = dev->path.i2c.device;
53         pbus = get_pbus_smbus(dev);
54
55         res = find_resource(pbus->dev, 0x20 + (pbus->link_num * 4));
56
57         return do_smbus_send_byte(res->base, device, val);
58 }
59
60 static int lsmbus_read_byte(device_t dev, u8 address)
61 {
62         unsigned device;
63         struct resource *res;
64         struct bus *pbus;
65
66         device = dev->path.i2c.device;
67         pbus = get_pbus_smbus(dev);
68
69         res = find_resource(pbus->dev, 0x20 + (pbus->link_num * 4));
70
71         return do_smbus_read_byte(res->base, device, address);
72 }
73
74 static int lsmbus_write_byte(device_t dev, u8 address, u8 val)
75 {
76         unsigned device;
77         struct resource *res;
78         struct bus *pbus;
79
80         device = dev->path.i2c.device;
81         pbus = get_pbus_smbus(dev);
82
83         res = find_resource(pbus->dev, 0x20 + (pbus->link_num * 4));
84
85         return do_smbus_write_byte(res->base, device, address, val);
86 }
87
88 static struct smbus_bus_operations lops_smbus_bus = {
89         .recv_byte  = lsmbus_recv_byte,
90         .send_byte  = lsmbus_send_byte,
91         .read_byte  = lsmbus_read_byte,
92         .write_byte = lsmbus_write_byte,
93 };
94
95 static struct device_operations smbus_ops = {
96         .read_resources   = pci_dev_read_resources,
97         .set_resources    = pci_dev_set_resources,
98         .enable_resources = pci_dev_enable_resources,
99         .init             = 0,
100         .scan_bus         = scan_static_bus,
101         // .enable        = ck804_enable,
102         .ops_pci          = &ck804_pci_ops,
103         .ops_smbus_bus    = &lops_smbus_bus,
104 };
105
106 static const struct pci_driver smbus_driver __pci_driver = {
107         .ops    = &smbus_ops,
108         .vendor = PCI_VENDOR_ID_NVIDIA,
109         .device = PCI_DEVICE_ID_NVIDIA_CK804_SM,
110 };