Angel Pons | 182dbde | 2020-04-02 23:49:05 +0200 | [diff] [blame] | 1 | /* SPDX-License-Identifier: GPL-2.0-only */ |
Vladimir Serbinenko | caf1df0 | 2014-08-01 02:49:27 +0200 | [diff] [blame] | 2 | |
Vladimir Serbinenko | caf1df0 | 2014-08-01 02:49:27 +0200 | [diff] [blame] | 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> |
| 8 | #include <device/pci_ops.h> |
Kyösti Mälkki | 1cae454 | 2020-01-06 12:31:34 +0200 | [diff] [blame] | 9 | #include <device/smbus_host.h> |
Arthur Heymans | 16fe790 | 2017-04-12 17:01:31 +0200 | [diff] [blame] | 10 | #include "i82801ix.h" |
Vladimir Serbinenko | caf1df0 | 2014-08-01 02:49:27 +0200 | [diff] [blame] | 11 | |
Elyes HAOUAS | 8aa5073 | 2018-05-13 13:34:58 +0200 | [diff] [blame] | 12 | static void pch_smbus_init(struct device *dev) |
Vladimir Serbinenko | caf1df0 | 2014-08-01 02:49:27 +0200 | [diff] [blame] | 13 | { |
Vladimir Serbinenko | caf1df0 | 2014-08-01 02:49:27 +0200 | [diff] [blame] | 14 | /* Enable clock gating */ |
Angel Pons | 6740647 | 2020-06-08 11:13:42 +0200 | [diff] [blame] | 15 | pci_and_config16(dev, 0x80, ~((1 << 8) | (1 << 10) | (1 << 12) | (1 << 14))); |
Vladimir Serbinenko | caf1df0 | 2014-08-01 02:49:27 +0200 | [diff] [blame] | 16 | } |
| 17 | |
Elyes HAOUAS | 8aa5073 | 2018-05-13 13:34:58 +0200 | [diff] [blame] | 18 | static int lsmbus_read_byte(struct device *dev, u8 address) |
Vladimir Serbinenko | caf1df0 | 2014-08-01 02:49:27 +0200 | [diff] [blame] | 19 | { |
| 20 | u16 device; |
| 21 | struct resource *res; |
| 22 | struct bus *pbus; |
| 23 | |
| 24 | device = dev->path.i2c.device; |
| 25 | pbus = get_pbus_smbus(dev); |
| 26 | res = find_resource(pbus->dev, 0x20); |
| 27 | |
| 28 | return do_smbus_read_byte(res->base, device, address); |
| 29 | } |
| 30 | |
Elyes HAOUAS | 8aa5073 | 2018-05-13 13:34:58 +0200 | [diff] [blame] | 31 | static int lsmbus_write_byte(struct device *dev, u8 address, u8 val) |
Vladimir Serbinenko | caf1df0 | 2014-08-01 02:49:27 +0200 | [diff] [blame] | 32 | { |
| 33 | u16 device; |
| 34 | struct resource *res; |
| 35 | struct bus *pbus; |
| 36 | |
| 37 | device = dev->path.i2c.device; |
| 38 | pbus = get_pbus_smbus(dev); |
| 39 | res = find_resource(pbus->dev, 0x20); |
| 40 | |
| 41 | return do_smbus_write_byte(res->base, device, address, val); |
| 42 | } |
| 43 | |
| 44 | static struct smbus_bus_operations lops_smbus_bus = { |
| 45 | .read_byte = lsmbus_read_byte, |
| 46 | .write_byte = lsmbus_write_byte, |
| 47 | }; |
| 48 | |
Elyes HAOUAS | 8aa5073 | 2018-05-13 13:34:58 +0200 | [diff] [blame] | 49 | static void smbus_read_resources(struct device *dev) |
Vladimir Serbinenko | caf1df0 | 2014-08-01 02:49:27 +0200 | [diff] [blame] | 50 | { |
| 51 | struct resource *res = new_resource(dev, PCI_BASE_ADDRESS_4); |
Angel Pons | b21bffa | 2020-07-03 01:02:28 +0200 | [diff] [blame^] | 52 | res->base = CONFIG_FIXED_SMBUS_IO_BASE; |
Vladimir Serbinenko | caf1df0 | 2014-08-01 02:49:27 +0200 | [diff] [blame] | 53 | res->size = 32; |
| 54 | res->limit = res->base + res->size - 1; |
| 55 | res->flags = IORESOURCE_IO | IORESOURCE_FIXED | IORESOURCE_RESERVE | |
| 56 | IORESOURCE_STORED | IORESOURCE_ASSIGNED; |
| 57 | |
| 58 | /* Also add MMIO resource */ |
| 59 | res = pci_get_resource(dev, PCI_BASE_ADDRESS_0); |
| 60 | } |
| 61 | |
| 62 | static struct device_operations smbus_ops = { |
| 63 | .read_resources = smbus_read_resources, |
| 64 | .set_resources = pci_dev_set_resources, |
| 65 | .enable_resources = pci_dev_enable_resources, |
Kyösti Mälkki | d0e212c | 2015-02-26 20:47:47 +0200 | [diff] [blame] | 66 | .scan_bus = scan_smbus, |
Vladimir Serbinenko | caf1df0 | 2014-08-01 02:49:27 +0200 | [diff] [blame] | 67 | .init = pch_smbus_init, |
| 68 | .ops_smbus_bus = &lops_smbus_bus, |
Angel Pons | 1fc0edd | 2020-05-31 00:03:28 +0200 | [diff] [blame] | 69 | .ops_pci = &pci_dev_ops_pci, |
Vladimir Serbinenko | caf1df0 | 2014-08-01 02:49:27 +0200 | [diff] [blame] | 70 | }; |
| 71 | |
Vladimir Serbinenko | caf1df0 | 2014-08-01 02:49:27 +0200 | [diff] [blame] | 72 | static const struct pci_driver pch_smbus __pci_driver = { |
| 73 | .ops = &smbus_ops, |
| 74 | .vendor = PCI_VENDOR_ID_INTEL, |
Felix Singer | 7f8b0cd8 | 2019-11-10 11:04:08 +0100 | [diff] [blame] | 75 | .device = PCI_DEVICE_ID_INTEL_82801IB_SMB, |
Vladimir Serbinenko | caf1df0 | 2014-08-01 02:49:27 +0200 | [diff] [blame] | 76 | }; |