blob: 72f78ea9f7b9560a3802e1ac53347b8065eac01c [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 <console/console.h>
18#include <device/device.h>
19#include <device/path.h>
20#include <device/smbus.h>
21#include <device/pci.h>
22#include <device/pci_ids.h>
23#include <device/pci_ops.h>
Stefan Reinauerdebb11f2008-10-29 04:46:52 +000024#include <arch/io.h>
Arthur Heymans16fe7902017-04-12 17:01:31 +020025#include <southbridge/intel/common/smbus.h>
Stefan Reinauerdebb11f2008-10-29 04:46:52 +000026#include "i82801gx.h"
Stefan Reinauer109ab312009-08-12 16:08:05 +000027
Elyes HAOUAS99667032018-05-13 12:47:28 +020028static int lsmbus_read_byte(struct device *dev, u8 address)
Stefan Reinauerdebb11f2008-10-29 04:46:52 +000029{
30 u16 device;
31 struct resource *res;
Stefan Reinauera8e11682009-03-11 14:54:18 +000032 struct bus *pbus;
Stefan Reinauerdebb11f2008-10-29 04:46:52 +000033
Stefan Reinauer2b34db82009-02-28 20:10:20 +000034 device = dev->path.i2c.device;
Stefan Reinauera8e11682009-03-11 14:54:18 +000035 pbus = get_pbus_smbus(dev);
36 res = find_resource(pbus->dev, 0x20);
Stefan Reinauerdebb11f2008-10-29 04:46:52 +000037
38 return do_smbus_read_byte(res->base, device, address);
39}
40
Elyes HAOUAS99667032018-05-13 12:47:28 +020041static int lsmbus_write_byte(struct device *dev, u8 address, u8 data)
Sven Schnelle718afbe2011-10-23 15:36:15 +020042{
43 u16 device;
44 struct resource *res;
45 struct bus *pbus;
46
47 device = dev->path.i2c.device;
48 pbus = get_pbus_smbus(dev);
49 res = find_resource(pbus->dev, 0x20);
50 return do_smbus_write_byte(res->base, device, address, data);
51}
52
Elyes HAOUAS99667032018-05-13 12:47:28 +020053static int lsmbus_block_write(struct device *dev, u8 cmd, u8 bytes,
54 const u8 *buf)
Sven Schnelle718afbe2011-10-23 15:36:15 +020055{
56 u16 device;
57 struct resource *res;
58 struct bus *pbus;
59
60 device = dev->path.i2c.device;
61 pbus = get_pbus_smbus(dev);
62 res = find_resource(pbus->dev, 0x20);
63 return do_smbus_block_write(res->base, device, cmd, bytes, buf);
64}
65
Elyes HAOUAS99667032018-05-13 12:47:28 +020066static int lsmbus_block_read(struct device *dev, u8 cmd, u8 bytes, u8 *buf)
Sven Schnelle718afbe2011-10-23 15:36:15 +020067{
68 u16 device;
69 struct resource *res;
70 struct bus *pbus;
71
72 device = dev->path.i2c.device;
73 pbus = get_pbus_smbus(dev);
74 res = find_resource(pbus->dev, 0x20);
75 return do_smbus_block_read(res->base, device, cmd, bytes, buf);
76}
77
78
Stefan Reinauerdebb11f2008-10-29 04:46:52 +000079static struct smbus_bus_operations lops_smbus_bus = {
Stefan Reinauera8e11682009-03-11 14:54:18 +000080 .read_byte = lsmbus_read_byte,
Sven Schnelle718afbe2011-10-23 15:36:15 +020081 .write_byte = lsmbus_write_byte,
82 .block_read = lsmbus_block_read,
83 .block_write = lsmbus_block_write,
Stefan Reinauera8e11682009-03-11 14:54:18 +000084};
85
Elyes HAOUAS99667032018-05-13 12:47:28 +020086static void smbus_set_subsystem(struct device *dev, unsigned int vendor,
87 unsigned int device)
Stefan Reinauera8e11682009-03-11 14:54:18 +000088{
89 if (!vendor || !device) {
90 pci_write_config32(dev, PCI_SUBSYSTEM_VENDOR_ID,
91 pci_read_config32(dev, PCI_VENDOR_ID));
92 } else {
93 pci_write_config32(dev, PCI_SUBSYSTEM_VENDOR_ID,
94 ((device & 0xffff) << 16) | (vendor & 0xffff));
95 }
96}
97
98static struct pci_operations smbus_pci_ops = {
99 .set_subsystem = smbus_set_subsystem,
Stefan Reinauerdebb11f2008-10-29 04:46:52 +0000100};
101
Elyes HAOUAS99667032018-05-13 12:47:28 +0200102static void smbus_read_resources(struct device *dev)
Sven Schnelle3c976792011-10-23 15:30:29 +0200103{
104 struct resource *res = new_resource(dev, PCI_BASE_ADDRESS_4);
105 res->base = SMBUS_IO_BASE;
106 res->size = 32;
107 res->limit = res->base + res->size - 1;
108 res->flags = IORESOURCE_IO | IORESOURCE_FIXED | IORESOURCE_RESERVE |
109 IORESOURCE_STORED | IORESOURCE_ASSIGNED;
110}
111
Stefan Reinauerdebb11f2008-10-29 04:46:52 +0000112static struct device_operations smbus_ops = {
Sven Schnelle3c976792011-10-23 15:30:29 +0200113 .read_resources = smbus_read_resources,
Stefan Reinauerdebb11f2008-10-29 04:46:52 +0000114 .set_resources = pci_dev_set_resources,
115 .enable_resources = pci_dev_enable_resources,
Kyösti Mälkkid0e212c2015-02-26 20:47:47 +0200116 .scan_bus = scan_smbus,
Stefan Reinauerdebb11f2008-10-29 04:46:52 +0000117 .enable = i82801gx_enable,
118 .ops_smbus_bus = &lops_smbus_bus,
Stefan Reinauera8e11682009-03-11 14:54:18 +0000119 .ops_pci = &smbus_pci_ops,
Stefan Reinauerdebb11f2008-10-29 04:46:52 +0000120};
121
122/* 82801GB/GR/GDH/GBM/GHM/GU (ICH7/ICH7R/ICH7DH/ICH7-M/ICH7-M DH/ICH7-U) */
123static const struct pci_driver i82801gx_smbus __pci_driver = {
124 .ops = &smbus_ops,
125 .vendor = PCI_VENDOR_ID_INTEL,
Uwe Hermann5d7a1c82008-10-31 18:41:09 +0000126 .device = 0x27da,
Stefan Reinauerdebb11f2008-10-29 04:46:52 +0000127};