blob: 1754734f03ef52e3b524caf456785715c5dd100c [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
17#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>
24#include <arch/io.h>
Arthur Heymans16fe7902017-04-12 17:01:31 +020025#include <southbridge/intel/common/smbus.h>
Stefan Reinauer8e073822012-04-04 00:07:22 +020026#include "pch.h"
Stefan Reinauer8e073822012-04-04 00:07:22 +020027
Elyes HAOUAS4aec3402018-05-25 08:29:27 +020028static void pch_smbus_init(struct device *dev)
Stefan Reinauer8e073822012-04-04 00:07:22 +020029{
30 struct resource *res;
31 u16 reg16;
32
33 /* Enable clock gating */
34 reg16 = pci_read_config32(dev, 0x80);
35 reg16 &= ~((1 << 8)|(1 << 10)|(1 << 12)|(1 << 14));
36 pci_write_config32(dev, 0x80, reg16);
37
38 /* Set Receive Slave Address */
39 res = find_resource(dev, PCI_BASE_ADDRESS_4);
40 if (res)
41 outb(SMBUS_SLAVE_ADDR, res->base + SMB_RCV_SLVA);
42}
43
Elyes HAOUAS4aec3402018-05-25 08:29:27 +020044static int lsmbus_read_byte(struct device *dev, u8 address)
Stefan Reinauer8e073822012-04-04 00:07:22 +020045{
46 u16 device;
47 struct resource *res;
48 struct bus *pbus;
49
50 device = dev->path.i2c.device;
51 pbus = get_pbus_smbus(dev);
52 res = find_resource(pbus->dev, 0x20);
53
54 return do_smbus_read_byte(res->base, device, address);
55}
56
Elyes HAOUAS4aec3402018-05-25 08:29:27 +020057static int lsmbus_write_byte(struct device *dev, u8 address, u8 val)
Vladimir Serbinenkoe57718f2014-01-27 23:48:27 +010058{
59 u16 device;
60 struct resource *res;
61 struct bus *pbus;
62
63 device = dev->path.i2c.device;
64 pbus = get_pbus_smbus(dev);
65 res = find_resource(pbus->dev, 0x20);
66
67 return do_smbus_write_byte(res->base, device, address, val);
68}
69
Stefan Reinauer8e073822012-04-04 00:07:22 +020070static struct smbus_bus_operations lops_smbus_bus = {
71 .read_byte = lsmbus_read_byte,
Vladimir Serbinenkoe57718f2014-01-27 23:48:27 +010072 .write_byte = lsmbus_write_byte,
Stefan Reinauer8e073822012-04-04 00:07:22 +020073};
74
Elyes HAOUAS4aec3402018-05-25 08:29:27 +020075static void smbus_set_subsystem(struct device *dev, unsigned vendor,
76 unsigned device)
Stefan Reinauer8e073822012-04-04 00:07:22 +020077{
78 if (!vendor || !device) {
79 pci_write_config32(dev, PCI_SUBSYSTEM_VENDOR_ID,
80 pci_read_config32(dev, PCI_VENDOR_ID));
81 } else {
82 pci_write_config32(dev, PCI_SUBSYSTEM_VENDOR_ID,
83 ((device & 0xffff) << 16) | (vendor & 0xffff));
84 }
85}
86
87static struct pci_operations smbus_pci_ops = {
88 .set_subsystem = smbus_set_subsystem,
89};
90
Elyes HAOUAS4aec3402018-05-25 08:29:27 +020091static void smbus_read_resources(struct device *dev)
Stefan Reinauer8e073822012-04-04 00:07:22 +020092{
93 struct resource *res = new_resource(dev, PCI_BASE_ADDRESS_4);
94 res->base = SMBUS_IO_BASE;
95 res->size = 32;
96 res->limit = res->base + res->size - 1;
97 res->flags = IORESOURCE_IO | IORESOURCE_FIXED | IORESOURCE_RESERVE |
98 IORESOURCE_STORED | IORESOURCE_ASSIGNED;
99
100 /* Also add MMIO resource */
101 res = pci_get_resource(dev, PCI_BASE_ADDRESS_0);
102}
103
Aaron Durbinaa090cb2017-09-13 16:01:52 -0600104static const char *smbus_acpi_name(const struct device *dev)
Patrick Rudolph604f6982017-06-07 09:46:52 +0200105{
106 return "SBUS";
107}
108
Stefan Reinauer8e073822012-04-04 00:07:22 +0200109static struct device_operations smbus_ops = {
110 .read_resources = smbus_read_resources,
111 .set_resources = pci_dev_set_resources,
112 .enable_resources = pci_dev_enable_resources,
Kyösti Mälkkid0e212c2015-02-26 20:47:47 +0200113 .scan_bus = scan_smbus,
Stefan Reinauer8e073822012-04-04 00:07:22 +0200114 .init = pch_smbus_init,
115 .ops_smbus_bus = &lops_smbus_bus,
116 .ops_pci = &smbus_pci_ops,
Patrick Rudolph604f6982017-06-07 09:46:52 +0200117 .acpi_name = smbus_acpi_name,
Stefan Reinauer8e073822012-04-04 00:07:22 +0200118};
119
Stefan Reinauer9a380ab2012-06-22 13:16:11 -0700120static const unsigned short pci_device_ids[] = { 0x1c22, 0x1e22, 0 };
Stefan Reinauer8e073822012-04-04 00:07:22 +0200121
Stefan Reinauer9a380ab2012-06-22 13:16:11 -0700122static const struct pci_driver pch_smbus __pci_driver = {
123 .ops = &smbus_ops,
124 .vendor = PCI_VENDOR_ID_INTEL,
125 .devices = pci_device_ids,
Stefan Reinauer8e073822012-04-04 00:07:22 +0200126};