blob: b011c493a764b1d1877a575cf1a34a9fe3bfd8c5 [file] [log] [blame]
Stefan Reinauer8e073822012-04-04 00:07:22 +02001/*
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.
Stefan Reinauer8e073822012-04-04 00:07:22 +020015 */
16
Stefan Reinauer8e073822012-04-04 00:07:22 +020017#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>
Stefan Reinauer8e073822012-04-04 00:07:22 +020024#include "pch.h"
Stefan Reinauer8e073822012-04-04 00:07:22 +020025
Elyes HAOUAS4aec3402018-05-25 08:29:27 +020026static void pch_smbus_init(struct device *dev)
Stefan Reinauer8e073822012-04-04 00:07:22 +020027{
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);
Stefan Reinauer8e073822012-04-04 00:07:22 +020040}
41
Elyes HAOUAS4aec3402018-05-25 08:29:27 +020042static int lsmbus_read_byte(struct device *dev, u8 address)
Stefan Reinauer8e073822012-04-04 00:07:22 +020043{
44 u16 device;
45 struct resource *res;
46 struct bus *pbus;
47
48 device = dev->path.i2c.device;
49 pbus = get_pbus_smbus(dev);
50 res = find_resource(pbus->dev, 0x20);
51
52 return do_smbus_read_byte(res->base, device, address);
53}
54
Elyes HAOUAS4aec3402018-05-25 08:29:27 +020055static int lsmbus_write_byte(struct device *dev, u8 address, u8 val)
Vladimir Serbinenkoe57718f2014-01-27 23:48:27 +010056{
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, 0x20);
64
65 return do_smbus_write_byte(res->base, device, address, val);
66}
67
Stefan Reinauer8e073822012-04-04 00:07:22 +020068static struct smbus_bus_operations lops_smbus_bus = {
69 .read_byte = lsmbus_read_byte,
Vladimir Serbinenkoe57718f2014-01-27 23:48:27 +010070 .write_byte = lsmbus_write_byte,
Stefan Reinauer8e073822012-04-04 00:07:22 +020071};
72
Stefan Reinauer8e073822012-04-04 00:07:22 +020073static struct pci_operations smbus_pci_ops = {
Subrata Banik4a0f0712019-03-20 14:29:47 +053074 .set_subsystem = pci_dev_set_subsystem,
Stefan Reinauer8e073822012-04-04 00:07:22 +020075};
76
Elyes HAOUAS4aec3402018-05-25 08:29:27 +020077static void smbus_read_resources(struct device *dev)
Stefan Reinauer8e073822012-04-04 00:07:22 +020078{
79 struct resource *res = new_resource(dev, PCI_BASE_ADDRESS_4);
80 res->base = SMBUS_IO_BASE;
81 res->size = 32;
82 res->limit = res->base + res->size - 1;
83 res->flags = IORESOURCE_IO | IORESOURCE_FIXED | IORESOURCE_RESERVE |
84 IORESOURCE_STORED | IORESOURCE_ASSIGNED;
85
86 /* Also add MMIO resource */
87 res = pci_get_resource(dev, PCI_BASE_ADDRESS_0);
88}
89
Aaron Durbinaa090cb2017-09-13 16:01:52 -060090static const char *smbus_acpi_name(const struct device *dev)
Patrick Rudolph604f6982017-06-07 09:46:52 +020091{
92 return "SBUS";
93}
94
Stefan Reinauer8e073822012-04-04 00:07:22 +020095static struct device_operations smbus_ops = {
96 .read_resources = smbus_read_resources,
97 .set_resources = pci_dev_set_resources,
98 .enable_resources = pci_dev_enable_resources,
Kyösti Mälkkid0e212c2015-02-26 20:47:47 +020099 .scan_bus = scan_smbus,
Stefan Reinauer8e073822012-04-04 00:07:22 +0200100 .init = pch_smbus_init,
101 .ops_smbus_bus = &lops_smbus_bus,
102 .ops_pci = &smbus_pci_ops,
Patrick Rudolph604f6982017-06-07 09:46:52 +0200103 .acpi_name = smbus_acpi_name,
Stefan Reinauer8e073822012-04-04 00:07:22 +0200104};
105
Stefan Reinauer9a380ab2012-06-22 13:16:11 -0700106static const unsigned short pci_device_ids[] = { 0x1c22, 0x1e22, 0 };
Stefan Reinauer8e073822012-04-04 00:07:22 +0200107
Stefan Reinauer9a380ab2012-06-22 13:16:11 -0700108static const struct pci_driver pch_smbus __pci_driver = {
109 .ops = &smbus_ops,
110 .vendor = PCI_VENDOR_ID_INTEL,
111 .devices = pci_device_ids,
Stefan Reinauer8e073822012-04-04 00:07:22 +0200112};