blob: bc735a35b2c99accaafefd026eb1936e23bcf92c [file] [log] [blame]
Arthur Heymans7b9c1392017-04-09 20:40:39 +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.
15 */
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>
26#include "i82801jx.h"
Arthur Heymans7b9c1392017-04-09 20:40:39 +020027
28static void pch_smbus_init(device_t dev)
29{
30 u16 reg16;
31
32 /* Enable clock gating */
33 reg16 = pci_read_config16(dev, 0x80);
34 reg16 &= ~((1 << 8)|(1 << 10)|(1 << 12)|(1 << 14));
35 pci_write_config16(dev, 0x80, reg16);
36}
37
38static int lsmbus_read_byte(device_t dev, u8 address)
39{
40 u16 device;
41 struct resource *res;
42 struct bus *pbus;
43
44 device = dev->path.i2c.device;
45 pbus = get_pbus_smbus(dev);
46 res = find_resource(pbus->dev, 0x20);
47
48 return do_smbus_read_byte(res->base, device, address);
49}
50
51static int lsmbus_write_byte(device_t dev, u8 address, u8 val)
52{
53 u16 device;
54 struct resource *res;
55 struct bus *pbus;
56
57 device = dev->path.i2c.device;
58 pbus = get_pbus_smbus(dev);
59 res = find_resource(pbus->dev, 0x20);
60
61 return do_smbus_write_byte(res->base, device, address, val);
62}
63
64static struct smbus_bus_operations lops_smbus_bus = {
65 .read_byte = lsmbus_read_byte,
66 .write_byte = lsmbus_write_byte,
67};
68
69static void smbus_set_subsystem(device_t dev, unsigned vendor, unsigned device)
70{
71 if (!vendor || !device) {
72 pci_write_config32(dev, PCI_SUBSYSTEM_VENDOR_ID,
73 pci_read_config32(dev, PCI_VENDOR_ID));
74 } else {
75 pci_write_config32(dev, PCI_SUBSYSTEM_VENDOR_ID,
76 ((device & 0xffff) << 16) | (vendor & 0xffff));
77 }
78}
79
80static struct pci_operations smbus_pci_ops = {
81 .set_subsystem = smbus_set_subsystem,
82};
83
84static void smbus_read_resources(device_t dev)
85{
86 struct resource *res = new_resource(dev, PCI_BASE_ADDRESS_4);
87 res->base = SMBUS_IO_BASE;
88 res->size = 32;
89 res->limit = res->base + res->size - 1;
90 res->flags = IORESOURCE_IO | IORESOURCE_FIXED | IORESOURCE_RESERVE |
91 IORESOURCE_STORED | IORESOURCE_ASSIGNED;
92
93 /* Also add MMIO resource */
94 res = pci_get_resource(dev, PCI_BASE_ADDRESS_0);
95}
96
97static struct device_operations smbus_ops = {
98 .read_resources = smbus_read_resources,
99 .set_resources = pci_dev_set_resources,
100 .enable_resources = pci_dev_enable_resources,
101 .scan_bus = scan_smbus,
102 .init = pch_smbus_init,
103 .ops_smbus_bus = &lops_smbus_bus,
104 .ops_pci = &smbus_pci_ops,
105};
106
Arthur Heymans349e0852017-04-09 20:48:37 +0200107static const unsigned short pci_device_ids[] =
108{
109 0x3a30,
110 0x3a60,
111 0
112};
Arthur Heymans7b9c1392017-04-09 20:40:39 +0200113
114static const struct pci_driver pch_smbus __pci_driver = {
115 .ops = &smbus_ops,
116 .vendor = PCI_VENDOR_ID_INTEL,
117 .devices = pci_device_ids,
118};