blob: 9261690dbd5227d362d28a6324f801a512aeac85 [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>
Kyösti Mälkki1cae4542020-01-06 12:31:34 +020022#include <device/smbus_host.h>
Stefan Reinauerdebb11f2008-10-29 04:46:52 +000023#include "i82801gx.h"
Stefan Reinauer109ab312009-08-12 16:08:05 +000024
Elyes HAOUAS99667032018-05-13 12:47:28 +020025static int lsmbus_read_byte(struct device *dev, u8 address)
Stefan Reinauerdebb11f2008-10-29 04:46:52 +000026{
27 u16 device;
28 struct resource *res;
Stefan Reinauera8e11682009-03-11 14:54:18 +000029 struct bus *pbus;
Stefan Reinauerdebb11f2008-10-29 04:46:52 +000030
Stefan Reinauer2b34db82009-02-28 20:10:20 +000031 device = dev->path.i2c.device;
Stefan Reinauera8e11682009-03-11 14:54:18 +000032 pbus = get_pbus_smbus(dev);
33 res = find_resource(pbus->dev, 0x20);
Stefan Reinauerdebb11f2008-10-29 04:46:52 +000034
35 return do_smbus_read_byte(res->base, device, address);
36}
37
Elyes HAOUAS99667032018-05-13 12:47:28 +020038static int lsmbus_write_byte(struct device *dev, u8 address, u8 data)
Sven Schnelle718afbe2011-10-23 15:36:15 +020039{
40 u16 device;
41 struct resource *res;
42 struct bus *pbus;
43
44 device = dev->path.i2c.device;
45 pbus = get_pbus_smbus(dev);
46 res = find_resource(pbus->dev, 0x20);
47 return do_smbus_write_byte(res->base, device, address, data);
48}
49
Elyes HAOUAS99667032018-05-13 12:47:28 +020050static int lsmbus_block_write(struct device *dev, u8 cmd, u8 bytes,
51 const u8 *buf)
Sven Schnelle718afbe2011-10-23 15:36:15 +020052{
53 u16 device;
54 struct resource *res;
55 struct bus *pbus;
56
57 device = dev->path.i2c.device;
58 pbus = get_pbus_smbus(dev);
59 res = find_resource(pbus->dev, 0x20);
60 return do_smbus_block_write(res->base, device, cmd, bytes, buf);
61}
62
Elyes HAOUAS99667032018-05-13 12:47:28 +020063static int lsmbus_block_read(struct device *dev, u8 cmd, u8 bytes, u8 *buf)
Sven Schnelle718afbe2011-10-23 15:36:15 +020064{
65 u16 device;
66 struct resource *res;
67 struct bus *pbus;
68
69 device = dev->path.i2c.device;
70 pbus = get_pbus_smbus(dev);
71 res = find_resource(pbus->dev, 0x20);
72 return do_smbus_block_read(res->base, device, cmd, bytes, buf);
73}
74
75
Stefan Reinauerdebb11f2008-10-29 04:46:52 +000076static struct smbus_bus_operations lops_smbus_bus = {
Stefan Reinauera8e11682009-03-11 14:54:18 +000077 .read_byte = lsmbus_read_byte,
Sven Schnelle718afbe2011-10-23 15:36:15 +020078 .write_byte = lsmbus_write_byte,
79 .block_read = lsmbus_block_read,
80 .block_write = lsmbus_block_write,
Stefan Reinauera8e11682009-03-11 14:54:18 +000081};
82
Stefan Reinauera8e11682009-03-11 14:54:18 +000083static struct pci_operations smbus_pci_ops = {
Subrata Banik4a0f0712019-03-20 14:29:47 +053084 .set_subsystem = pci_dev_set_subsystem,
Stefan Reinauerdebb11f2008-10-29 04:46:52 +000085};
86
Elyes HAOUAS99667032018-05-13 12:47:28 +020087static void smbus_read_resources(struct device *dev)
Sven Schnelle3c976792011-10-23 15:30:29 +020088{
89 struct resource *res = new_resource(dev, PCI_BASE_ADDRESS_4);
90 res->base = SMBUS_IO_BASE;
91 res->size = 32;
92 res->limit = res->base + res->size - 1;
93 res->flags = IORESOURCE_IO | IORESOURCE_FIXED | IORESOURCE_RESERVE |
94 IORESOURCE_STORED | IORESOURCE_ASSIGNED;
95}
96
Stefan Reinauerdebb11f2008-10-29 04:46:52 +000097static struct device_operations smbus_ops = {
Sven Schnelle3c976792011-10-23 15:30:29 +020098 .read_resources = smbus_read_resources,
Stefan Reinauerdebb11f2008-10-29 04:46:52 +000099 .set_resources = pci_dev_set_resources,
100 .enable_resources = pci_dev_enable_resources,
Kyösti Mälkkid0e212c2015-02-26 20:47:47 +0200101 .scan_bus = scan_smbus,
Stefan Reinauerdebb11f2008-10-29 04:46:52 +0000102 .enable = i82801gx_enable,
103 .ops_smbus_bus = &lops_smbus_bus,
Stefan Reinauera8e11682009-03-11 14:54:18 +0000104 .ops_pci = &smbus_pci_ops,
Stefan Reinauerdebb11f2008-10-29 04:46:52 +0000105};
106
107/* 82801GB/GR/GDH/GBM/GHM/GU (ICH7/ICH7R/ICH7DH/ICH7-M/ICH7-M DH/ICH7-U) */
108static const struct pci_driver i82801gx_smbus __pci_driver = {
109 .ops = &smbus_ops,
110 .vendor = PCI_VENDOR_ID_INTEL,
Uwe Hermann5d7a1c82008-10-31 18:41:09 +0000111 .device = 0x27da,
Stefan Reinauerdebb11f2008-10-29 04:46:52 +0000112};