blob: 97618b0d26b658d38cd8086873448746590022f7 [file] [log] [blame]
Aamir Bohra52f29742017-04-19 18:19:14 +05301/*
2 * This file is part of the coreboot project.
3 *
Aamir Bohra52f29742017-04-19 18:19:14 +05304 *
5 * This program is free software; you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License as published by
7 * the Free Software Foundation; version 2 of the License.
8 *
9 * This program is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 * GNU General Public License for more details.
13 */
14
15#include <device/device.h>
16#include <device/path.h>
17#include <device/smbus.h>
18#include <device/pci.h>
19#include <device/pci_ids.h>
Aamir Bohra52f29742017-04-19 18:19:14 +053020#include <soc/smbus.h>
Kyösti Mälkki1cae4542020-01-06 12:31:34 +020021#include <device/smbus_host.h>
Aamir Bohra52f29742017-04-19 18:19:14 +053022#include "smbuslib.h"
23
Elyes HAOUAS4a131262018-09-16 17:35:48 +020024static int lsmbus_read_byte(struct device *dev, u8 address)
Aamir Bohra52f29742017-04-19 18:19:14 +053025{
26 u16 device;
27 struct resource *res;
28 struct bus *pbus;
29 device = dev->path.i2c.device;
30 pbus = get_pbus_smbus(dev);
31 res = find_resource(pbus->dev, PCI_BASE_ADDRESS_4);
Kyösti Mälkki4ae9f1e2020-01-01 17:42:45 +020032 return do_smbus_read_byte(res->base, device, address);
Aamir Bohra52f29742017-04-19 18:19:14 +053033}
34
Elyes HAOUAS4a131262018-09-16 17:35:48 +020035static int lsmbus_write_byte(struct device *dev, u8 address, u8 data)
Aamir Bohra52f29742017-04-19 18:19:14 +053036{
37 u16 device;
38 struct resource *res;
39 struct bus *pbus;
40
41 device = dev->path.i2c.device;
42 pbus = get_pbus_smbus(dev);
43 res = find_resource(pbus->dev, PCI_BASE_ADDRESS_4);
Kyösti Mälkki4ae9f1e2020-01-01 17:42:45 +020044 return do_smbus_write_byte(res->base, device, address, data);
Aamir Bohra52f29742017-04-19 18:19:14 +053045}
46
47static struct smbus_bus_operations lops_smbus_bus = {
48 .read_byte = lsmbus_read_byte,
49 .write_byte = lsmbus_write_byte,
50};
51
Elyes HAOUAS4a131262018-09-16 17:35:48 +020052static void pch_smbus_init(struct device *dev)
Aamir Bohra52f29742017-04-19 18:19:14 +053053{
54 struct resource *res;
Aamir Bohra52f29742017-04-19 18:19:14 +053055
56 /* Enable clock gating */
Nico Huber62788672017-08-17 16:08:00 +020057 pci_update_config32(dev, 0x80,
58 ~((1 << 8) | (1 << 10) | (1 << 12) | (1 << 14)), 0);
Aamir Bohra52f29742017-04-19 18:19:14 +053059
60 /* Set Receive Slave Address */
61 res = find_resource(dev, PCI_BASE_ADDRESS_4);
62 if (res)
Kyösti Mälkki73451fd2020-01-06 19:00:31 +020063 smbus_set_slave_addr(res->base, SMBUS_SLAVE_ADDR);
Aamir Bohra52f29742017-04-19 18:19:14 +053064}
65
Elyes HAOUAS4a131262018-09-16 17:35:48 +020066static void smbus_read_resources(struct device *dev)
Aamir Bohra52f29742017-04-19 18:19:14 +053067{
68 struct resource *res = new_resource(dev, PCI_BASE_ADDRESS_4);
69 res->base = SMBUS_IO_BASE;
70 res->size = 32;
71 res->limit = res->base + res->size - 1;
72 res->flags = IORESOURCE_IO | IORESOURCE_FIXED | IORESOURCE_RESERVE |
73 IORESOURCE_STORED | IORESOURCE_ASSIGNED;
74
75 /* Also add MMIO resource */
76 res = pci_get_resource(dev, PCI_BASE_ADDRESS_0);
77}
78
79static struct device_operations smbus_ops = {
Elyes HAOUAS1d191272018-11-27 12:23:48 +010080 .read_resources = smbus_read_resources,
81 .set_resources = pci_dev_set_resources,
82 .enable_resources = pci_dev_enable_resources,
83 .scan_bus = scan_smbus,
84 .init = pch_smbus_init,
Subrata Banik6bbc91a2017-12-07 14:55:51 +053085 .ops_pci = &pci_dev_ops_pci,
Aamir Bohra52f29742017-04-19 18:19:14 +053086 .ops_smbus_bus = &lops_smbus_bus,
87};
88
89static const unsigned short pci_device_ids[] = {
Lijian Zhaobbedef92017-07-29 16:38:38 -070090 PCI_DEVICE_ID_INTEL_CNL_SMBUS,
Aamir Bohra52f29742017-04-19 18:19:14 +053091 PCI_DEVICE_ID_INTEL_SPT_LP_SMBUS,
92 PCI_DEVICE_ID_INTEL_SPT_H_SMBUS,
Maxim Polyakov571d07d2019-08-22 13:11:32 +030093 PCI_DEVICE_ID_INTEL_LWB_SMBUS_SUPER,
Jonathan Zhangc9ece502019-11-25 12:41:15 -080094 PCI_DEVICE_ID_INTEL_LWB_SMBUS,
Aamir Bohra9eac0392018-06-30 12:07:04 +053095 PCI_DEVICE_ID_INTEL_ICP_LP_SMBUS,
Ronak Kanabarda7ffb482019-02-05 01:51:13 +053096 PCI_DEVICE_ID_INTEL_CMP_SMBUS,
Gaggery Tsai12a651c2019-12-05 11:23:20 -080097 PCI_DEVICE_ID_INTEL_CMP_H_SMBUS,
Ravi Sarawadi6b5bf402019-10-21 22:25:04 -070098 PCI_DEVICE_ID_INTEL_TGP_LP_SMBUS,
Tan, Lean Sheng26136092020-01-20 19:13:56 -080099 PCI_DEVICE_ID_INTEL_MCC_SMBUS,
Meera Ravindranath3f4af0d2020-02-12 16:01:22 +0530100 PCI_DEVICE_ID_INTEL_JSP_SMBUS,
Aamir Bohra52f29742017-04-19 18:19:14 +0530101 0
102};
103
104static const struct pci_driver pch_smbus __pci_driver = {
105 .ops = &smbus_ops,
106 .vendor = PCI_VENDOR_ID_INTEL,
107 .devices = pci_device_ids,
108};