blob: dd3abfe60c2c7375970effe6e04a13b1e20578fe [file] [log] [blame]
Vladimir Serbinenko888d5592013-11-13 17:53:38 +01001/*
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.
Vladimir Serbinenko888d5592013-11-13 17:53:38 +010015 */
16
Vladimir Serbinenko888d5592013-11-13 17:53:38 +010017#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>
Vladimir Serbinenko888d5592013-11-13 17:53:38 +010025#include "pch.h"
Vladimir Serbinenko888d5592013-11-13 17:53:38 +010026
Elyes HAOUASbe841402018-05-13 13:40:39 +020027static void pch_smbus_init(struct device *dev)
Vladimir Serbinenko888d5592013-11-13 17:53:38 +010028{
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 HAOUASbe841402018-05-13 13:40:39 +020043static int lsmbus_read_byte(struct device *dev, u8 address)
Vladimir Serbinenko888d5592013-11-13 17:53:38 +010044{
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 HAOUASbe841402018-05-13 13:40:39 +020056static int lsmbus_write_byte(struct device *dev, u8 address, u8 val)
Vladimir Serbinenko5f20dbf2014-01-27 23:57:44 +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
Vladimir Serbinenko888d5592013-11-13 17:53:38 +010069static struct smbus_bus_operations lops_smbus_bus = {
70 .read_byte = lsmbus_read_byte,
Vladimir Serbinenko5f20dbf2014-01-27 23:57:44 +010071 .write_byte = lsmbus_write_byte,
Vladimir Serbinenko888d5592013-11-13 17:53:38 +010072};
73
Vladimir Serbinenko888d5592013-11-13 17:53:38 +010074static struct pci_operations smbus_pci_ops = {
Subrata Banik4a0f0712019-03-20 14:29:47 +053075 .set_subsystem = pci_dev_set_subsystem,
Vladimir Serbinenko888d5592013-11-13 17:53:38 +010076};
77
Elyes HAOUASbe841402018-05-13 13:40:39 +020078static void smbus_read_resources(struct device *dev)
Vladimir Serbinenko888d5592013-11-13 17:53:38 +010079{
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
91static struct device_operations smbus_ops = {
92 .read_resources = smbus_read_resources,
93 .set_resources = pci_dev_set_resources,
94 .enable_resources = pci_dev_enable_resources,
Kyösti Mälkkid0e212c2015-02-26 20:47:47 +020095 .scan_bus = scan_smbus,
Vladimir Serbinenko888d5592013-11-13 17:53:38 +010096 .init = pch_smbus_init,
97 .ops_smbus_bus = &lops_smbus_bus,
98 .ops_pci = &smbus_pci_ops,
99};
100
101static const unsigned short pci_device_ids[] = { 0x1c22, 0x1e22, 0x3b30, 0 };
102
103static const struct pci_driver pch_smbus __pci_driver = {
104 .ops = &smbus_ops,
105 .vendor = PCI_VENDOR_ID_INTEL,
106 .devices = pci_device_ids,
107};