2 * This file is part of the coreboot project.
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.
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.
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.
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
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>
35 static int lsmbus_recv_byte(device_t dev)
41 device = dev->path.i2c.device;
42 pbus = get_pbus_smbus(dev);
44 res = find_resource(pbus->dev, 0x20 + (pbus->link_num * 4));
46 return do_smbus_recv_byte(res->base, device);
49 static int lsmbus_send_byte(device_t dev, uint8_t val)
55 device = dev->path.i2c.device;
56 pbus = get_pbus_smbus(dev);
58 res = find_resource(pbus->dev, 0x20 + (pbus->link_num * 4));
60 return do_smbus_send_byte(res->base, device, val);
63 static int lsmbus_read_byte(device_t dev, uint8_t address)
69 device = dev->path.i2c.device;
70 pbus = get_pbus_smbus(dev);
72 res = find_resource(pbus->dev, 0x20 + (pbus->link_num * 4));
74 return do_smbus_read_byte(res->base, device, address);
77 static int lsmbus_write_byte(device_t dev, uint8_t address, uint8_t val)
83 device = dev->path.i2c.device;
84 pbus = get_pbus_smbus(dev);
86 res = find_resource(pbus->dev, 0x20 + (pbus->link_num * 4));
88 return do_smbus_write_byte(res->base, device, address, val);
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,
97 #if CONFIG_GENERATE_ACPI_TABLES == 1
101 static void mcp55_sm_read_resources(device_t dev)
105 /* Get the normal pci resources of this device */
106 pci_dev_read_resources(dev);
108 for (index = 0x60; index <= 0x68; index+=4) { // We got another 3.
109 pci_get_resource(dev, index);
111 compact_resources(dev);
114 static void mcp55_sm_init(device_t dev)
116 #if CONFIG_GENERATE_ACPI_TABLES == 1
117 struct resource *res;
119 res = find_resource(dev, 0x60);
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,
136 static const struct pci_driver smbus_driver __pci_driver = {
138 .vendor = PCI_VENDOR_ID_NVIDIA,
139 .device = PCI_DEVICE_ID_NVIDIA_MCP55_SM2,