Angel Pons | 0612b27 | 2020-04-05 15:46:56 +0200 | [diff] [blame] | 1 | /* SPDX-License-Identifier: GPL-2.0-only */ |
Aamir Bohra | 52f2974 | 2017-04-19 18:19:14 +0530 | [diff] [blame] | 2 | |
| 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 Bohra | 52f2974 | 2017-04-19 18:19:14 +0530 | [diff] [blame] | 8 | #include <soc/smbus.h> |
Kyösti Mälkki | 1cae454 | 2020-01-06 12:31:34 +0200 | [diff] [blame] | 9 | #include <device/smbus_host.h> |
Aamir Bohra | 52f2974 | 2017-04-19 18:19:14 +0530 | [diff] [blame] | 10 | #include "smbuslib.h" |
| 11 | |
Elyes HAOUAS | 4a13126 | 2018-09-16 17:35:48 +0200 | [diff] [blame] | 12 | static int lsmbus_read_byte(struct device *dev, u8 address) |
Aamir Bohra | 52f2974 | 2017-04-19 18:19:14 +0530 | [diff] [blame] | 13 | { |
| 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älkki | 4ae9f1e | 2020-01-01 17:42:45 +0200 | [diff] [blame] | 20 | return do_smbus_read_byte(res->base, device, address); |
Aamir Bohra | 52f2974 | 2017-04-19 18:19:14 +0530 | [diff] [blame] | 21 | } |
| 22 | |
Elyes HAOUAS | 4a13126 | 2018-09-16 17:35:48 +0200 | [diff] [blame] | 23 | static int lsmbus_write_byte(struct device *dev, u8 address, u8 data) |
Aamir Bohra | 52f2974 | 2017-04-19 18:19:14 +0530 | [diff] [blame] | 24 | { |
| 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älkki | 4ae9f1e | 2020-01-01 17:42:45 +0200 | [diff] [blame] | 32 | return do_smbus_write_byte(res->base, device, address, data); |
Aamir Bohra | 52f2974 | 2017-04-19 18:19:14 +0530 | [diff] [blame] | 33 | } |
| 34 | |
| 35 | static struct smbus_bus_operations lops_smbus_bus = { |
| 36 | .read_byte = lsmbus_read_byte, |
| 37 | .write_byte = lsmbus_write_byte, |
| 38 | }; |
| 39 | |
Elyes HAOUAS | 4a13126 | 2018-09-16 17:35:48 +0200 | [diff] [blame] | 40 | static void pch_smbus_init(struct device *dev) |
Aamir Bohra | 52f2974 | 2017-04-19 18:19:14 +0530 | [diff] [blame] | 41 | { |
| 42 | struct resource *res; |
Aamir Bohra | 52f2974 | 2017-04-19 18:19:14 +0530 | [diff] [blame] | 43 | |
| 44 | /* Enable clock gating */ |
Nico Huber | 6278867 | 2017-08-17 16:08:00 +0200 | [diff] [blame] | 45 | pci_update_config32(dev, 0x80, |
| 46 | ~((1 << 8) | (1 << 10) | (1 << 12) | (1 << 14)), 0); |
Aamir Bohra | 52f2974 | 2017-04-19 18:19:14 +0530 | [diff] [blame] | 47 | |
| 48 | /* Set Receive Slave Address */ |
Angel Pons | c1bfbe0 | 2021-11-03 13:18:53 +0100 | [diff] [blame] | 49 | res = probe_resource(dev, PCI_BASE_ADDRESS_4); |
Aamir Bohra | 52f2974 | 2017-04-19 18:19:14 +0530 | [diff] [blame] | 50 | if (res) |
Kyösti Mälkki | 73451fd | 2020-01-06 19:00:31 +0200 | [diff] [blame] | 51 | smbus_set_slave_addr(res->base, SMBUS_SLAVE_ADDR); |
Aamir Bohra | 52f2974 | 2017-04-19 18:19:14 +0530 | [diff] [blame] | 52 | } |
| 53 | |
Elyes HAOUAS | 4a13126 | 2018-09-16 17:35:48 +0200 | [diff] [blame] | 54 | static void smbus_read_resources(struct device *dev) |
Aamir Bohra | 52f2974 | 2017-04-19 18:19:14 +0530 | [diff] [blame] | 55 | { |
Paul Menzel | a081583 | 2021-05-25 12:34:16 +0200 | [diff] [blame] | 56 | pci_dev_read_resources(dev); |
| 57 | |
Aamir Bohra | 52f2974 | 2017-04-19 18:19:14 +0530 | [diff] [blame] | 58 | 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 Bohra | 52f2974 | 2017-04-19 18:19:14 +0530 | [diff] [blame] | 64 | } |
| 65 | |
| 66 | static struct device_operations smbus_ops = { |
Elyes HAOUAS | 1d19127 | 2018-11-27 12:23:48 +0100 | [diff] [blame] | 67 | .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 Banik | 6bbc91a | 2017-12-07 14:55:51 +0530 | [diff] [blame] | 72 | .ops_pci = &pci_dev_ops_pci, |
Aamir Bohra | 52f2974 | 2017-04-19 18:19:14 +0530 | [diff] [blame] | 73 | .ops_smbus_bus = &lops_smbus_bus, |
| 74 | }; |
| 75 | |
| 76 | static const unsigned short pci_device_ids[] = { |
Maxim Polyakov | 0c5dd9f | 2020-08-14 19:24:12 +0300 | [diff] [blame] | 77 | PCI_DEVICE_ID_INTEL_APL_SMBUS, |
Lijian Zhao | bbedef9 | 2017-07-29 16:38:38 -0700 | [diff] [blame] | 78 | PCI_DEVICE_ID_INTEL_CNL_SMBUS, |
Patrick Rudolph | 2c70708 | 2020-10-19 17:40:02 +0200 | [diff] [blame] | 79 | PCI_DEVICE_ID_INTEL_CNP_H_SMBUS, |
Aamir Bohra | 52f2974 | 2017-04-19 18:19:14 +0530 | [diff] [blame] | 80 | PCI_DEVICE_ID_INTEL_SPT_LP_SMBUS, |
| 81 | PCI_DEVICE_ID_INTEL_SPT_H_SMBUS, |
Maxim Polyakov | 571d07d | 2019-08-22 13:11:32 +0300 | [diff] [blame] | 82 | PCI_DEVICE_ID_INTEL_LWB_SMBUS_SUPER, |
Jonathan Zhang | c9ece50 | 2019-11-25 12:41:15 -0800 | [diff] [blame] | 83 | PCI_DEVICE_ID_INTEL_LWB_SMBUS, |
Aamir Bohra | 9eac039 | 2018-06-30 12:07:04 +0530 | [diff] [blame] | 84 | PCI_DEVICE_ID_INTEL_ICP_LP_SMBUS, |
Ronak Kanabar | da7ffb48 | 2019-02-05 01:51:13 +0530 | [diff] [blame] | 85 | PCI_DEVICE_ID_INTEL_CMP_SMBUS, |
Gaggery Tsai | 12a651c | 2019-12-05 11:23:20 -0800 | [diff] [blame] | 86 | PCI_DEVICE_ID_INTEL_CMP_H_SMBUS, |
Ravi Sarawadi | 6b5bf40 | 2019-10-21 22:25:04 -0700 | [diff] [blame] | 87 | PCI_DEVICE_ID_INTEL_TGP_LP_SMBUS, |
Jeremy Soller | 191a8d7 | 2021-08-10 14:06:51 -0600 | [diff] [blame] | 88 | PCI_DEVICE_ID_INTEL_TGP_H_SMBUS, |
Tan, Lean Sheng | 2613609 | 2020-01-20 19:13:56 -0800 | [diff] [blame] | 89 | PCI_DEVICE_ID_INTEL_MCC_SMBUS, |
Meera Ravindranath | 3f4af0d | 2020-02-12 16:01:22 +0530 | [diff] [blame] | 90 | PCI_DEVICE_ID_INTEL_JSP_SMBUS, |
Subrata Banik | f672f7f | 2020-08-03 14:29:25 +0530 | [diff] [blame] | 91 | PCI_DEVICE_ID_INTEL_ADP_P_SMBUS, |
| 92 | PCI_DEVICE_ID_INTEL_ADP_S_SMBUS, |
Usha P | af5a9d6 | 2022-01-17 20:24:31 +0530 | [diff] [blame^] | 93 | PCI_DEVICE_ID_INTEL_ADP_M_N_SMBUS, |
Jeff Daly | 2a81cab | 2022-01-06 16:32:11 -0500 | [diff] [blame] | 94 | PCI_DEVICE_ID_INTEL_DNV_SMBUS_LEGACY, |
Aamir Bohra | 52f2974 | 2017-04-19 18:19:14 +0530 | [diff] [blame] | 95 | 0 |
| 96 | }; |
| 97 | |
| 98 | static const struct pci_driver pch_smbus __pci_driver = { |
| 99 | .ops = &smbus_ops, |
| 100 | .vendor = PCI_VENDOR_ID_INTEL, |
| 101 | .devices = pci_device_ids, |
| 102 | }; |