blob: ff659b837a49994aa4eeb5f84a6db401c5381409 [file] [log] [blame]
Aaron Durbin76c37002012-10-30 09:03:43 -05001/*
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
8 * published by the Free Software Foundation; version 2 of
9 * the License.
10 *
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.
Aaron Durbin76c37002012-10-30 09:03:43 -050015 */
16
Aaron Durbin76c37002012-10-30 09:03:43 -050017#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>
Kyösti Mälkki1cae4542020-01-06 12:31:34 +020023#include <device/smbus_host.h>
Aaron Durbin76c37002012-10-30 09:03:43 -050024#include "pch.h"
Aaron Durbin76c37002012-10-30 09:03:43 -050025
Elyes HAOUAS38f1d132018-09-17 08:44:18 +020026static void pch_smbus_init(struct device *dev)
Aaron Durbin76c37002012-10-30 09:03:43 -050027{
28 struct resource *res;
29 u16 reg16;
30
31 /* Enable clock gating */
32 reg16 = pci_read_config32(dev, 0x80);
33 reg16 &= ~((1 << 8)|(1 << 10)|(1 << 12)|(1 << 14));
34 pci_write_config32(dev, 0x80, reg16);
35
36 /* Set Receive Slave Address */
37 res = find_resource(dev, PCI_BASE_ADDRESS_4);
38 if (res)
Kyösti Mälkki73451fd2020-01-06 19:00:31 +020039 smbus_set_slave_addr(res->base, SMBUS_SLAVE_ADDR);
Aaron Durbin76c37002012-10-30 09:03:43 -050040}
41
Elyes HAOUAS38f1d132018-09-17 08:44:18 +020042static int lsmbus_read_byte(struct device *dev, u8 address)
Aaron Durbin76c37002012-10-30 09:03:43 -050043{
44 u16 device;
45 struct resource *res;
46 struct bus *pbus;
47
48 device = dev->path.i2c.device;
49 pbus = get_pbus_smbus(dev);
Duncan Laurie88707332013-07-15 09:07:20 -070050 res = find_resource(pbus->dev, PCI_BASE_ADDRESS_4);
Aaron Durbin76c37002012-10-30 09:03:43 -050051
52 return do_smbus_read_byte(res->base, device, address);
53}
54
Elyes HAOUAS38f1d132018-09-17 08:44:18 +020055static int lsmbus_write_byte(struct device *dev, u8 address, u8 data)
Duncan Laurie88707332013-07-15 09:07:20 -070056{
57 u16 device;
58 struct resource *res;
59 struct bus *pbus;
60
61 device = dev->path.i2c.device;
62 pbus = get_pbus_smbus(dev);
63 res = find_resource(pbus->dev, PCI_BASE_ADDRESS_4);
64 return do_smbus_write_byte(res->base, device, address, data);
65}
66
Aaron Durbin76c37002012-10-30 09:03:43 -050067static struct smbus_bus_operations lops_smbus_bus = {
68 .read_byte = lsmbus_read_byte,
Duncan Laurie88707332013-07-15 09:07:20 -070069 .write_byte = lsmbus_write_byte,
Aaron Durbin76c37002012-10-30 09:03:43 -050070};
71
Aaron Durbin76c37002012-10-30 09:03:43 -050072static struct pci_operations smbus_pci_ops = {
Subrata Banik4a0f0712019-03-20 14:29:47 +053073 .set_subsystem = pci_dev_set_subsystem,
Aaron Durbin76c37002012-10-30 09:03:43 -050074};
75
Elyes HAOUAS38f1d132018-09-17 08:44:18 +020076static void smbus_read_resources(struct device *dev)
Aaron Durbin76c37002012-10-30 09:03:43 -050077{
78 struct resource *res = new_resource(dev, PCI_BASE_ADDRESS_4);
79 res->base = SMBUS_IO_BASE;
80 res->size = 32;
81 res->limit = res->base + res->size - 1;
82 res->flags = IORESOURCE_IO | IORESOURCE_FIXED | IORESOURCE_RESERVE |
83 IORESOURCE_STORED | IORESOURCE_ASSIGNED;
84
85 /* Also add MMIO resource */
86 res = pci_get_resource(dev, PCI_BASE_ADDRESS_0);
87}
88
89static struct device_operations smbus_ops = {
90 .read_resources = smbus_read_resources,
91 .set_resources = pci_dev_set_resources,
92 .enable_resources = pci_dev_enable_resources,
Kyösti Mälkkid0e212c2015-02-26 20:47:47 +020093 .scan_bus = scan_smbus,
Aaron Durbin76c37002012-10-30 09:03:43 -050094 .init = pch_smbus_init,
95 .ops_smbus_bus = &lops_smbus_bus,
96 .ops_pci = &smbus_pci_ops,
97};
98
Tristan Corrick946d3f92018-10-31 02:21:07 +130099static const unsigned short pci_device_ids[] = {
100 0x1c22, 0x1e22, 0x8c22, 0x9c22,
101 0
102};
Aaron Durbin76c37002012-10-30 09:03:43 -0500103
104static const struct pci_driver pch_smbus __pci_driver = {
105 .ops = &smbus_ops,
106 .vendor = PCI_VENDOR_ID_INTEL,
107 .devices = pci_device_ids,
108};