blob: 95def1116ef02050764f3732e645ce52518d2bb2 [file] [log] [blame]
Aamir Bohra52f29742017-04-19 18:19:14 +05301/*
2 * This file is part of the coreboot project.
3 *
4 * Copyright (C) 2017 Intel Corporation.
5 *
6 * This program is free software; you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License as published by
8 * the Free Software Foundation; version 2 of the License.
9 *
10 * This program is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU General Public License for more details.
14 */
15
Kyösti Mälkkibdaec072019-03-02 23:18:29 +020016#include <arch/io.h>
Aamir Bohra52f29742017-04-19 18:19:14 +053017#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>
Aamir Bohra52f29742017-04-19 18:19:14 +053022#include <soc/smbus.h>
Kyösti Mälkkibbcf1a02020-01-01 17:42:45 +020023#include <southbridge/intel/common/smbus.h>
Aamir Bohra52f29742017-04-19 18:19:14 +053024#include "smbuslib.h"
25
Elyes HAOUAS4a131262018-09-16 17:35:48 +020026static int lsmbus_read_byte(struct device *dev, u8 address)
Aamir Bohra52f29742017-04-19 18:19:14 +053027{
28 u16 device;
29 struct resource *res;
30 struct bus *pbus;
31 device = dev->path.i2c.device;
32 pbus = get_pbus_smbus(dev);
33 res = find_resource(pbus->dev, PCI_BASE_ADDRESS_4);
Kyösti Mälkki4ae9f1e2020-01-01 17:42:45 +020034 return do_smbus_read_byte(res->base, device, address);
Aamir Bohra52f29742017-04-19 18:19:14 +053035}
36
Elyes HAOUAS4a131262018-09-16 17:35:48 +020037static int lsmbus_write_byte(struct device *dev, u8 address, u8 data)
Aamir Bohra52f29742017-04-19 18:19:14 +053038{
39 u16 device;
40 struct resource *res;
41 struct bus *pbus;
42
43 device = dev->path.i2c.device;
44 pbus = get_pbus_smbus(dev);
45 res = find_resource(pbus->dev, PCI_BASE_ADDRESS_4);
Kyösti Mälkki4ae9f1e2020-01-01 17:42:45 +020046 return do_smbus_write_byte(res->base, device, address, data);
Aamir Bohra52f29742017-04-19 18:19:14 +053047}
48
49static struct smbus_bus_operations lops_smbus_bus = {
50 .read_byte = lsmbus_read_byte,
51 .write_byte = lsmbus_write_byte,
52};
53
Elyes HAOUAS4a131262018-09-16 17:35:48 +020054static void pch_smbus_init(struct device *dev)
Aamir Bohra52f29742017-04-19 18:19:14 +053055{
56 struct resource *res;
Aamir Bohra52f29742017-04-19 18:19:14 +053057
58 /* Enable clock gating */
Nico Huber62788672017-08-17 16:08:00 +020059 pci_update_config32(dev, 0x80,
60 ~((1 << 8) | (1 << 10) | (1 << 12) | (1 << 14)), 0);
Aamir Bohra52f29742017-04-19 18:19:14 +053061
62 /* Set Receive Slave Address */
63 res = find_resource(dev, PCI_BASE_ADDRESS_4);
64 if (res)
65 outb(SMBUS_SLAVE_ADDR, res->base + SMB_RCV_SLVA);
66}
67
Elyes HAOUAS4a131262018-09-16 17:35:48 +020068static void smbus_read_resources(struct device *dev)
Aamir Bohra52f29742017-04-19 18:19:14 +053069{
70 struct resource *res = new_resource(dev, PCI_BASE_ADDRESS_4);
71 res->base = SMBUS_IO_BASE;
72 res->size = 32;
73 res->limit = res->base + res->size - 1;
74 res->flags = IORESOURCE_IO | IORESOURCE_FIXED | IORESOURCE_RESERVE |
75 IORESOURCE_STORED | IORESOURCE_ASSIGNED;
76
77 /* Also add MMIO resource */
78 res = pci_get_resource(dev, PCI_BASE_ADDRESS_0);
79}
80
81static struct device_operations smbus_ops = {
Elyes HAOUAS1d191272018-11-27 12:23:48 +010082 .read_resources = smbus_read_resources,
83 .set_resources = pci_dev_set_resources,
84 .enable_resources = pci_dev_enable_resources,
85 .scan_bus = scan_smbus,
86 .init = pch_smbus_init,
Subrata Banik6bbc91a2017-12-07 14:55:51 +053087 .ops_pci = &pci_dev_ops_pci,
Aamir Bohra52f29742017-04-19 18:19:14 +053088 .ops_smbus_bus = &lops_smbus_bus,
89};
90
91static const unsigned short pci_device_ids[] = {
Lijian Zhaobbedef92017-07-29 16:38:38 -070092 PCI_DEVICE_ID_INTEL_CNL_SMBUS,
Aamir Bohra52f29742017-04-19 18:19:14 +053093 PCI_DEVICE_ID_INTEL_SPT_LP_SMBUS,
94 PCI_DEVICE_ID_INTEL_SPT_H_SMBUS,
Maxim Polyakov571d07d2019-08-22 13:11:32 +030095 PCI_DEVICE_ID_INTEL_LWB_SMBUS_SUPER,
Jonathan Zhangc9ece502019-11-25 12:41:15 -080096 PCI_DEVICE_ID_INTEL_LWB_SMBUS,
Aamir Bohra9eac0392018-06-30 12:07:04 +053097 PCI_DEVICE_ID_INTEL_ICP_LP_SMBUS,
Ronak Kanabarda7ffb482019-02-05 01:51:13 +053098 PCI_DEVICE_ID_INTEL_CMP_SMBUS,
Gaggery Tsai12a651c2019-12-05 11:23:20 -080099 PCI_DEVICE_ID_INTEL_CMP_H_SMBUS,
Ravi Sarawadi6b5bf402019-10-21 22:25:04 -0700100 PCI_DEVICE_ID_INTEL_TGP_LP_SMBUS,
rkanabar263f1292019-11-28 10:41:45 +0530101 PCI_DEVICE_ID_INTEL_JSP_PRE_PROD_SMBUS,
Aamir Bohra52f29742017-04-19 18:19:14 +0530102 0
103};
104
105static const struct pci_driver pch_smbus __pci_driver = {
106 .ops = &smbus_ops,
107 .vendor = PCI_VENDOR_ID_INTEL,
108 .devices = pci_device_ids,
109};