MCP55: Cosmetic fixes, switch to u8 et al.
[coreboot.git] / src / southbridge / nvidia / mcp55 / 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  * Copyright (C) 2006,2007 AMD
7  * Written by Yinghai Lu <yinghai.lu@amd.com> for AMD.
8  *
9  * This program is free software; you can redistribute it and/or modify
10  * it under the terms of the GNU General Public License as published by
11  * the Free Software Foundation; either version 2 of the License, or
12  * (at your option) any later version.
13  *
14  * This program is distributed in the hope that it will be useful,
15  * but WITHOUT ANY WARRANTY; without even the implied warranty of
16  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
17  * GNU General Public License for more details.
18  *
19  * You should have received a copy of the GNU General Public License
20  * along with this program; if not, write to the Free Software
21  * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301 USA
22  */
23
24 #include <console/console.h>
25 #include <device/device.h>
26 #include <device/pci.h>
27 #include <device/pci_ids.h>
28 #include <device/pci_ops.h>
29 #include <device/smbus.h>
30 #include <bitops.h>
31 #include <arch/io.h>
32 #include "mcp55.h"
33 #include "smbus.h"
34
35 static int lsmbus_recv_byte(device_t dev)
36 {
37         unsigned device;
38         struct resource *res;
39         struct bus *pbus;
40
41         device = dev->path.i2c.device;
42         pbus = get_pbus_smbus(dev);
43
44         res = find_resource(pbus->dev, 0x20 + (pbus->link_num * 4));
45
46         return do_smbus_recv_byte(res->base, device);
47 }
48
49 static int lsmbus_send_byte(device_t dev, u8 val)
50 {
51         unsigned device;
52         struct resource *res;
53         struct bus *pbus;
54
55         device = dev->path.i2c.device;
56         pbus = get_pbus_smbus(dev);
57
58         res = find_resource(pbus->dev, 0x20 + (pbus->link_num * 4));
59
60         return do_smbus_send_byte(res->base, device, val);
61 }
62
63 static int lsmbus_read_byte(device_t dev, u8 address)
64 {
65         unsigned device;
66         struct resource *res;
67         struct bus *pbus;
68
69         device = dev->path.i2c.device;
70         pbus = get_pbus_smbus(dev);
71
72         res = find_resource(pbus->dev, 0x20 + (pbus->link_num * 4));
73
74         return do_smbus_read_byte(res->base, device, address);
75 }
76
77 static int lsmbus_write_byte(device_t dev, u8 address, u8 val)
78 {
79         unsigned device;
80         struct resource *res;
81         struct bus *pbus;
82
83         device = dev->path.i2c.device;
84         pbus = get_pbus_smbus(dev);
85
86         res = find_resource(pbus->dev, 0x20 + (pbus->link_num * 4));
87
88         return do_smbus_write_byte(res->base, device, address, val);
89 }
90 static struct smbus_bus_operations lops_smbus_bus = {
91         .recv_byte      = lsmbus_recv_byte,
92         .send_byte      = lsmbus_send_byte,
93         .read_byte      = lsmbus_read_byte,
94         .write_byte     = lsmbus_write_byte,
95 };
96
97 #if CONFIG_GENERATE_ACPI_TABLES == 1
98 unsigned pm_base;
99 #endif
100
101 static void mcp55_sm_read_resources(device_t dev)
102 {
103         unsigned long index;
104
105         /* Get the normal pci resources of this device */
106         pci_dev_read_resources(dev);
107
108         for (index = 0x60; index <= 0x68; index+=4) { // We got another 3.
109                 pci_get_resource(dev, index);
110         }
111         compact_resources(dev);
112 }
113
114 static void mcp55_sm_init(device_t dev)
115 {
116 #if CONFIG_GENERATE_ACPI_TABLES == 1
117         struct resource *res;
118
119         res = find_resource(dev, 0x60);
120
121         if (res)
122                 pm_base = res->base;
123 #endif
124 }
125
126 static struct device_operations smbus_ops = {
127         .read_resources = mcp55_sm_read_resources,
128         .set_resources  = pci_dev_set_resources,
129         .enable_resources       = pci_dev_enable_resources,
130         .init           = mcp55_sm_init,
131         .scan_bus       = scan_static_bus,
132 //      .enable         = mcp55_enable,
133         .ops_pci        = &mcp55_pci_ops,
134         .ops_smbus_bus  = &lops_smbus_bus,
135 };
136 static const struct pci_driver smbus_driver __pci_driver = {
137         .ops    = &smbus_ops,
138         .vendor = PCI_VENDOR_ID_NVIDIA,
139         .device = PCI_DEVICE_ID_NVIDIA_MCP55_SM2,
140 };
141