blob: 2b135c75e83969dfc6352e04ebc65382923d0596 [file] [log] [blame]
Angel Pons0612b272020-04-05 15:46:56 +02001/* SPDX-License-Identifier: GPL-2.0-only */
Aamir Bohra52f29742017-04-19 18:19:14 +05302
3#include <device/device.h>
4#include <device/path.h>
5#include <device/smbus.h>
6#include <device/pci.h>
7#include <device/pci_ids.h>
Aamir Bohra52f29742017-04-19 18:19:14 +05308#include <soc/smbus.h>
Kyösti Mälkki1cae4542020-01-06 12:31:34 +02009#include <device/smbus_host.h>
Aamir Bohra52f29742017-04-19 18:19:14 +053010#include "smbuslib.h"
11
Elyes HAOUAS4a131262018-09-16 17:35:48 +020012static int lsmbus_read_byte(struct device *dev, u8 address)
Aamir Bohra52f29742017-04-19 18:19:14 +053013{
14 u16 device;
15 struct resource *res;
16 struct bus *pbus;
17 device = dev->path.i2c.device;
18 pbus = get_pbus_smbus(dev);
19 res = find_resource(pbus->dev, PCI_BASE_ADDRESS_4);
Kyösti Mälkki4ae9f1e2020-01-01 17:42:45 +020020 return do_smbus_read_byte(res->base, device, address);
Aamir Bohra52f29742017-04-19 18:19:14 +053021}
22
Elyes HAOUAS4a131262018-09-16 17:35:48 +020023static int lsmbus_write_byte(struct device *dev, u8 address, u8 data)
Aamir Bohra52f29742017-04-19 18:19:14 +053024{
25 u16 device;
26 struct resource *res;
27 struct bus *pbus;
28
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_write_byte(res->base, device, address, data);
Aamir Bohra52f29742017-04-19 18:19:14 +053033}
34
35static struct smbus_bus_operations lops_smbus_bus = {
36 .read_byte = lsmbus_read_byte,
37 .write_byte = lsmbus_write_byte,
38};
39
Elyes HAOUAS4a131262018-09-16 17:35:48 +020040static void pch_smbus_init(struct device *dev)
Aamir Bohra52f29742017-04-19 18:19:14 +053041{
42 struct resource *res;
Aamir Bohra52f29742017-04-19 18:19:14 +053043
44 /* Enable clock gating */
Nico Huber62788672017-08-17 16:08:00 +020045 pci_update_config32(dev, 0x80,
46 ~((1 << 8) | (1 << 10) | (1 << 12) | (1 << 14)), 0);
Aamir Bohra52f29742017-04-19 18:19:14 +053047
48 /* Set Receive Slave Address */
Angel Ponsc1bfbe02021-11-03 13:18:53 +010049 res = probe_resource(dev, PCI_BASE_ADDRESS_4);
Aamir Bohra52f29742017-04-19 18:19:14 +053050 if (res)
Kyösti Mälkki73451fd2020-01-06 19:00:31 +020051 smbus_set_slave_addr(res->base, SMBUS_SLAVE_ADDR);
Aamir Bohra52f29742017-04-19 18:19:14 +053052}
53
Elyes HAOUAS4a131262018-09-16 17:35:48 +020054static void smbus_read_resources(struct device *dev)
Aamir Bohra52f29742017-04-19 18:19:14 +053055{
Paul Menzela0815832021-05-25 12:34:16 +020056 pci_dev_read_resources(dev);
57
Aamir Bohra52f29742017-04-19 18:19:14 +053058 struct resource *res = new_resource(dev, PCI_BASE_ADDRESS_4);
59 res->base = SMBUS_IO_BASE;
60 res->size = 32;
61 res->limit = res->base + res->size - 1;
62 res->flags = IORESOURCE_IO | IORESOURCE_FIXED | IORESOURCE_RESERVE |
63 IORESOURCE_STORED | IORESOURCE_ASSIGNED;
Aamir Bohra52f29742017-04-19 18:19:14 +053064}
65
66static struct device_operations smbus_ops = {
Elyes HAOUAS1d191272018-11-27 12:23:48 +010067 .read_resources = smbus_read_resources,
68 .set_resources = pci_dev_set_resources,
69 .enable_resources = pci_dev_enable_resources,
70 .scan_bus = scan_smbus,
71 .init = pch_smbus_init,
Subrata Banik6bbc91a2017-12-07 14:55:51 +053072 .ops_pci = &pci_dev_ops_pci,
Aamir Bohra52f29742017-04-19 18:19:14 +053073 .ops_smbus_bus = &lops_smbus_bus,
74};
75
76static const unsigned short pci_device_ids[] = {
Felix Singer43b7f412022-03-07 04:34:52 +010077 PCI_DID_INTEL_APL_SMBUS,
78 PCI_DID_INTEL_CNL_SMBUS,
79 PCI_DID_INTEL_CNP_H_SMBUS,
80 PCI_DID_INTEL_SPT_LP_SMBUS,
81 PCI_DID_INTEL_SPT_H_SMBUS,
82 PCI_DID_INTEL_LWB_SMBUS_SUPER,
83 PCI_DID_INTEL_LWB_SMBUS,
84 PCI_DID_INTEL_ICP_LP_SMBUS,
85 PCI_DID_INTEL_CMP_SMBUS,
86 PCI_DID_INTEL_CMP_H_SMBUS,
87 PCI_DID_INTEL_TGP_LP_SMBUS,
88 PCI_DID_INTEL_TGP_H_SMBUS,
89 PCI_DID_INTEL_MCC_SMBUS,
90 PCI_DID_INTEL_JSP_SMBUS,
91 PCI_DID_INTEL_ADP_P_SMBUS,
92 PCI_DID_INTEL_ADP_S_SMBUS,
93 PCI_DID_INTEL_ADP_M_N_SMBUS,
94 PCI_DID_INTEL_DNV_SMBUS_LEGACY,
Aamir Bohra52f29742017-04-19 18:19:14 +053095 0
96};
97
98static const struct pci_driver pch_smbus __pci_driver = {
99 .ops = &smbus_ops,
Felix Singer43b7f412022-03-07 04:34:52 +0100100 .vendor = PCI_VID_INTEL,
Aamir Bohra52f29742017-04-19 18:19:14 +0530101 .devices = pci_device_ids,
102};