Patrick Georgi | be61a17 | 2010-12-18 07:48:43 +0000 | [diff] [blame] | 1 | /* |
| 2 | * This file is part of the coreboot project. |
| 3 | * |
| 4 | * Copyright (C) 2008-2009 coresystems GmbH |
| 5 | * |
| 6 | * This program is free software; you can redistribute it and/or |
| 7 | * modify it under the terms of the GNU General Public License as |
Uwe Hermann | 405721d | 2010-12-18 13:22:37 +0000 | [diff] [blame] | 8 | * published by the Free Software Foundation; version 2 of the License. |
Patrick Georgi | be61a17 | 2010-12-18 07:48:43 +0000 | [diff] [blame] | 9 | * |
| 10 | * This program is distributed in the hope that it will be useful, |
| 11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 13 | * GNU General Public License for more details. |
Patrick Georgi | be61a17 | 2010-12-18 07:48:43 +0000 | [diff] [blame] | 14 | */ |
| 15 | |
| 16 | #include <console/console.h> |
| 17 | #include <device/device.h> |
| 18 | #include <device/path.h> |
| 19 | #include <device/smbus.h> |
| 20 | #include <device/pci.h> |
| 21 | #include <device/pci_ids.h> |
| 22 | #include <device/pci_ops.h> |
| 23 | #include <arch/io.h> |
| 24 | #include "sch.h" |
| 25 | #include "smbus.h" |
| 26 | |
| 27 | static int lsmbus_read_byte(device_t dev, u8 address) |
| 28 | { |
| 29 | u16 device; |
| 30 | struct resource *res; |
| 31 | struct bus *pbus; |
| 32 | |
| 33 | device = dev->path.i2c.device; |
| 34 | pbus = get_pbus_smbus(dev); |
| 35 | res = find_resource(pbus->dev, 0x20); |
| 36 | |
| 37 | return do_smbus_read_byte(res->base, device, address); |
| 38 | } |
| 39 | |
| 40 | static struct smbus_bus_operations lops_smbus_bus = { |
| 41 | .read_byte = lsmbus_read_byte, |
| 42 | }; |
| 43 | |
| 44 | static void smbus_set_subsystem(device_t dev, unsigned vendor, unsigned device) |
| 45 | { |
| 46 | if (!vendor || !device) { |
| 47 | pci_write_config32(dev, PCI_SUBSYSTEM_VENDOR_ID, |
| 48 | pci_read_config32(dev, PCI_VENDOR_ID)); |
| 49 | } else { |
| 50 | pci_write_config32(dev, PCI_SUBSYSTEM_VENDOR_ID, |
| 51 | ((device & 0xffff) << 16) | (vendor & 0xffff)); |
| 52 | } |
| 53 | } |
| 54 | |
| 55 | static struct pci_operations smbus_pci_ops = { |
| 56 | .set_subsystem = smbus_set_subsystem, |
| 57 | }; |
| 58 | |
| 59 | static struct device_operations smbus_ops = { |
| 60 | .read_resources = pci_dev_read_resources, |
| 61 | .set_resources = pci_dev_set_resources, |
| 62 | .enable_resources = pci_dev_enable_resources, |
| 63 | .init = 0, |
Kyösti Mälkki | d0e212c | 2015-02-26 20:47:47 +0200 | [diff] [blame] | 64 | .scan_bus = scan_smbus, |
Patrick Georgi | be61a17 | 2010-12-18 07:48:43 +0000 | [diff] [blame] | 65 | .ops_smbus_bus = &lops_smbus_bus, |
| 66 | .ops_pci = &smbus_pci_ops, |
| 67 | }; |
| 68 | |
Uwe Hermann | 405721d | 2010-12-18 13:22:37 +0000 | [diff] [blame] | 69 | // FIXME |
Patrick Georgi | be61a17 | 2010-12-18 07:48:43 +0000 | [diff] [blame] | 70 | /* 82801GB/GR/GDH/GBM/GHM/GU (ICH7/ICH7R/ICH7DH/ICH7-M/ICH7-M DH/ICH7-U) */ |
| 71 | static const struct pci_driver i82801gx_smbus __pci_driver = { |
| 72 | .ops = &smbus_ops, |
| 73 | .vendor = PCI_VENDOR_ID_INTEL, |
| 74 | .device = 0x27da, |
| 75 | }; |