blob: 4fb75398898988f334c22d5a40f1b3298da9e990 [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>
23#include <arch/io.h>
Arthur Heymans16fe7902017-04-12 17:01:31 +020024#include <southbridge/intel/common/smbus.h>
Stefan Reinauer8e073822012-04-04 00:07:22 +020025#include "pch.h"
Stefan Reinauer8e073822012-04-04 00:07:22 +020026
Elyes HAOUAS4aec3402018-05-25 08:29:27 +020027static void pch_smbus_init(struct device *dev)
Stefan Reinauer8e073822012-04-04 00:07:22 +020028{
29 struct resource *res;
30 u16 reg16;
31
32 /* Enable clock gating */
33 reg16 = pci_read_config32(dev, 0x80);
34 reg16 &= ~((1 << 8)|(1 << 10)|(1 << 12)|(1 << 14));
35 pci_write_config32(dev, 0x80, reg16);
36
37 /* Set Receive Slave Address */
38 res = find_resource(dev, PCI_BASE_ADDRESS_4);
39 if (res)
40 outb(SMBUS_SLAVE_ADDR, res->base + SMB_RCV_SLVA);
41}
42
Elyes HAOUAS4aec3402018-05-25 08:29:27 +020043static int lsmbus_read_byte(struct device *dev, u8 address)
Stefan Reinauer8e073822012-04-04 00:07:22 +020044{
45 u16 device;
46 struct resource *res;
47 struct bus *pbus;
48
49 device = dev->path.i2c.device;
50 pbus = get_pbus_smbus(dev);
51 res = find_resource(pbus->dev, 0x20);
52
53 return do_smbus_read_byte(res->base, device, address);
54}
55
Elyes HAOUAS4aec3402018-05-25 08:29:27 +020056static int lsmbus_write_byte(struct device *dev, u8 address, u8 val)
Vladimir Serbinenkoe57718f2014-01-27 23:48:27 +010057{
58 u16 device;
59 struct resource *res;
60 struct bus *pbus;
61
62 device = dev->path.i2c.device;
63 pbus = get_pbus_smbus(dev);
64 res = find_resource(pbus->dev, 0x20);
65
66 return do_smbus_write_byte(res->base, device, address, val);
67}
68
Stefan Reinauer8e073822012-04-04 00:07:22 +020069static struct smbus_bus_operations lops_smbus_bus = {
70 .read_byte = lsmbus_read_byte,
Vladimir Serbinenkoe57718f2014-01-27 23:48:27 +010071 .write_byte = lsmbus_write_byte,
Stefan Reinauer8e073822012-04-04 00:07:22 +020072};
73
Stefan Reinauer8e073822012-04-04 00:07:22 +020074static struct pci_operations smbus_pci_ops = {
Subrata Banik4a0f0712019-03-20 14:29:47 +053075 .set_subsystem = pci_dev_set_subsystem,
Stefan Reinauer8e073822012-04-04 00:07:22 +020076};
77
Elyes HAOUAS4aec3402018-05-25 08:29:27 +020078static void smbus_read_resources(struct device *dev)
Stefan Reinauer8e073822012-04-04 00:07:22 +020079{
80 struct resource *res = new_resource(dev, PCI_BASE_ADDRESS_4);
81 res->base = SMBUS_IO_BASE;
82 res->size = 32;
83 res->limit = res->base + res->size - 1;
84 res->flags = IORESOURCE_IO | IORESOURCE_FIXED | IORESOURCE_RESERVE |
85 IORESOURCE_STORED | IORESOURCE_ASSIGNED;
86
87 /* Also add MMIO resource */
88 res = pci_get_resource(dev, PCI_BASE_ADDRESS_0);
89}
90
Aaron Durbinaa090cb2017-09-13 16:01:52 -060091static const char *smbus_acpi_name(const struct device *dev)
Patrick Rudolph604f6982017-06-07 09:46:52 +020092{
93 return "SBUS";
94}
95
Stefan Reinauer8e073822012-04-04 00:07:22 +020096static struct device_operations smbus_ops = {
97 .read_resources = smbus_read_resources,
98 .set_resources = pci_dev_set_resources,
99 .enable_resources = pci_dev_enable_resources,
Kyösti Mälkkid0e212c2015-02-26 20:47:47 +0200100 .scan_bus = scan_smbus,
Stefan Reinauer8e073822012-04-04 00:07:22 +0200101 .init = pch_smbus_init,
102 .ops_smbus_bus = &lops_smbus_bus,
103 .ops_pci = &smbus_pci_ops,
Patrick Rudolph604f6982017-06-07 09:46:52 +0200104 .acpi_name = smbus_acpi_name,
Stefan Reinauer8e073822012-04-04 00:07:22 +0200105};
106
Stefan Reinauer9a380ab2012-06-22 13:16:11 -0700107static const unsigned short pci_device_ids[] = { 0x1c22, 0x1e22, 0 };
Stefan Reinauer8e073822012-04-04 00:07:22 +0200108
Stefan Reinauer9a380ab2012-06-22 13:16:11 -0700109static const struct pci_driver pch_smbus __pci_driver = {
110 .ops = &smbus_ops,
111 .vendor = PCI_VENDOR_ID_INTEL,
112 .devices = pci_device_ids,
Stefan Reinauer8e073822012-04-04 00:07:22 +0200113};