blob: 693c2dc96d8f64c0addf9c798b2e3f7657a86c40 [file] [log] [blame]
Stefan Reinauerdebb11f2008-10-29 04:46:52 +00001/*
2 * This file is part of the coreboot project.
3 *
Stefan Reinauera8e11682009-03-11 14:54:18 +00004 * Copyright (C) 2008-2009 coresystems GmbH
Stefan Reinauerdebb11f2008-10-29 04:46:52 +00005 *
Stefan Reinauera8e11682009-03-11 14:54:18 +00006 * This program is free software; you can redistribute it and/or
7 * modify it under the terms of the GNU General Public License as
8 * published by the Free Software Foundation; version 2 of
9 * the License.
Stefan Reinauerdebb11f2008-10-29 04:46:52 +000010 *
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.
Stefan Reinauerdebb11f2008-10-29 04:46:52 +000015 */
16
Stefan Reinauera8e11682009-03-11 14:54:18 +000017#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>
Arthur Heymans16fe7902017-04-12 17:01:31 +020023#include <southbridge/intel/common/smbus.h>
Stefan Reinauerdebb11f2008-10-29 04:46:52 +000024#include "i82801gx.h"
Stefan Reinauer109ab312009-08-12 16:08:05 +000025
Elyes HAOUAS99667032018-05-13 12:47:28 +020026static int lsmbus_read_byte(struct device *dev, u8 address)
Stefan Reinauerdebb11f2008-10-29 04:46:52 +000027{
28 u16 device;
29 struct resource *res;
Stefan Reinauera8e11682009-03-11 14:54:18 +000030 struct bus *pbus;
Stefan Reinauerdebb11f2008-10-29 04:46:52 +000031
Stefan Reinauer2b34db82009-02-28 20:10:20 +000032 device = dev->path.i2c.device;
Stefan Reinauera8e11682009-03-11 14:54:18 +000033 pbus = get_pbus_smbus(dev);
34 res = find_resource(pbus->dev, 0x20);
Stefan Reinauerdebb11f2008-10-29 04:46:52 +000035
36 return do_smbus_read_byte(res->base, device, address);
37}
38
Elyes HAOUAS99667032018-05-13 12:47:28 +020039static int lsmbus_write_byte(struct device *dev, u8 address, u8 data)
Sven Schnelle718afbe2011-10-23 15:36:15 +020040{
41 u16 device;
42 struct resource *res;
43 struct bus *pbus;
44
45 device = dev->path.i2c.device;
46 pbus = get_pbus_smbus(dev);
47 res = find_resource(pbus->dev, 0x20);
48 return do_smbus_write_byte(res->base, device, address, data);
49}
50
Elyes HAOUAS99667032018-05-13 12:47:28 +020051static int lsmbus_block_write(struct device *dev, u8 cmd, u8 bytes,
52 const u8 *buf)
Sven Schnelle718afbe2011-10-23 15:36:15 +020053{
54 u16 device;
55 struct resource *res;
56 struct bus *pbus;
57
58 device = dev->path.i2c.device;
59 pbus = get_pbus_smbus(dev);
60 res = find_resource(pbus->dev, 0x20);
61 return do_smbus_block_write(res->base, device, cmd, bytes, buf);
62}
63
Elyes HAOUAS99667032018-05-13 12:47:28 +020064static int lsmbus_block_read(struct device *dev, u8 cmd, u8 bytes, u8 *buf)
Sven Schnelle718afbe2011-10-23 15:36:15 +020065{
66 u16 device;
67 struct resource *res;
68 struct bus *pbus;
69
70 device = dev->path.i2c.device;
71 pbus = get_pbus_smbus(dev);
72 res = find_resource(pbus->dev, 0x20);
73 return do_smbus_block_read(res->base, device, cmd, bytes, buf);
74}
75
76
Stefan Reinauerdebb11f2008-10-29 04:46:52 +000077static struct smbus_bus_operations lops_smbus_bus = {
Stefan Reinauera8e11682009-03-11 14:54:18 +000078 .read_byte = lsmbus_read_byte,
Sven Schnelle718afbe2011-10-23 15:36:15 +020079 .write_byte = lsmbus_write_byte,
80 .block_read = lsmbus_block_read,
81 .block_write = lsmbus_block_write,
Stefan Reinauera8e11682009-03-11 14:54:18 +000082};
83
Stefan Reinauera8e11682009-03-11 14:54:18 +000084static struct pci_operations smbus_pci_ops = {
Subrata Banik4a0f0712019-03-20 14:29:47 +053085 .set_subsystem = pci_dev_set_subsystem,
Stefan Reinauerdebb11f2008-10-29 04:46:52 +000086};
87
Elyes HAOUAS99667032018-05-13 12:47:28 +020088static void smbus_read_resources(struct device *dev)
Sven Schnelle3c976792011-10-23 15:30:29 +020089{
90 struct resource *res = new_resource(dev, PCI_BASE_ADDRESS_4);
91 res->base = SMBUS_IO_BASE;
92 res->size = 32;
93 res->limit = res->base + res->size - 1;
94 res->flags = IORESOURCE_IO | IORESOURCE_FIXED | IORESOURCE_RESERVE |
95 IORESOURCE_STORED | IORESOURCE_ASSIGNED;
96}
97
Stefan Reinauerdebb11f2008-10-29 04:46:52 +000098static struct device_operations smbus_ops = {
Sven Schnelle3c976792011-10-23 15:30:29 +020099 .read_resources = smbus_read_resources,
Stefan Reinauerdebb11f2008-10-29 04:46:52 +0000100 .set_resources = pci_dev_set_resources,
101 .enable_resources = pci_dev_enable_resources,
Kyösti Mälkkid0e212c2015-02-26 20:47:47 +0200102 .scan_bus = scan_smbus,
Stefan Reinauerdebb11f2008-10-29 04:46:52 +0000103 .enable = i82801gx_enable,
104 .ops_smbus_bus = &lops_smbus_bus,
Stefan Reinauera8e11682009-03-11 14:54:18 +0000105 .ops_pci = &smbus_pci_ops,
Stefan Reinauerdebb11f2008-10-29 04:46:52 +0000106};
107
108/* 82801GB/GR/GDH/GBM/GHM/GU (ICH7/ICH7R/ICH7DH/ICH7-M/ICH7-M DH/ICH7-U) */
109static const struct pci_driver i82801gx_smbus __pci_driver = {
110 .ops = &smbus_ops,
111 .vendor = PCI_VENDOR_ID_INTEL,
Uwe Hermann5d7a1c82008-10-31 18:41:09 +0000112 .device = 0x27da,
Stefan Reinauerdebb11f2008-10-29 04:46:52 +0000113};