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 | { |
| 14 | u16 reg16; |
| 15 | |
| 16 | /* Enable clock gating */ |
| 17 | reg16 = pci_read_config16(dev, 0x80); |
| 18 | reg16 &= ~((1 << 8)|(1 << 10)|(1 << 12)|(1 << 14)); |
| 19 | pci_write_config16(dev, 0x80, reg16); |
| 20 | } |
| 21 | |
Elyes HAOUAS | 8aa5073 | 2018-05-13 13:34:58 +0200 | [diff] [blame] | 22 | static int lsmbus_read_byte(struct device *dev, u8 address) |
Vladimir Serbinenko | caf1df0 | 2014-08-01 02:49:27 +0200 | [diff] [blame] | 23 | { |
| 24 | u16 device; |
| 25 | struct resource *res; |
| 26 | struct bus *pbus; |
| 27 | |
| 28 | device = dev->path.i2c.device; |
| 29 | pbus = get_pbus_smbus(dev); |
| 30 | res = find_resource(pbus->dev, 0x20); |
| 31 | |
| 32 | return do_smbus_read_byte(res->base, device, address); |
| 33 | } |
| 34 | |
Elyes HAOUAS | 8aa5073 | 2018-05-13 13:34:58 +0200 | [diff] [blame] | 35 | static int lsmbus_write_byte(struct device *dev, u8 address, u8 val) |
Vladimir Serbinenko | caf1df0 | 2014-08-01 02:49:27 +0200 | [diff] [blame] | 36 | { |
| 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, 0x20); |
| 44 | |
| 45 | return do_smbus_write_byte(res->base, device, address, val); |
| 46 | } |
| 47 | |
| 48 | static struct smbus_bus_operations lops_smbus_bus = { |
| 49 | .read_byte = lsmbus_read_byte, |
| 50 | .write_byte = lsmbus_write_byte, |
| 51 | }; |
| 52 | |
Vladimir Serbinenko | caf1df0 | 2014-08-01 02:49:27 +0200 | [diff] [blame] | 53 | static struct pci_operations smbus_pci_ops = { |
Subrata Banik | 4a0f071 | 2019-03-20 14:29:47 +0530 | [diff] [blame] | 54 | .set_subsystem = pci_dev_set_subsystem, |
Vladimir Serbinenko | caf1df0 | 2014-08-01 02:49:27 +0200 | [diff] [blame] | 55 | }; |
| 56 | |
Elyes HAOUAS | 8aa5073 | 2018-05-13 13:34:58 +0200 | [diff] [blame] | 57 | static void smbus_read_resources(struct device *dev) |
Vladimir Serbinenko | caf1df0 | 2014-08-01 02:49:27 +0200 | [diff] [blame] | 58 | { |
| 59 | struct resource *res = new_resource(dev, PCI_BASE_ADDRESS_4); |
| 60 | res->base = SMBUS_IO_BASE; |
| 61 | res->size = 32; |
| 62 | res->limit = res->base + res->size - 1; |
| 63 | res->flags = IORESOURCE_IO | IORESOURCE_FIXED | IORESOURCE_RESERVE | |
| 64 | IORESOURCE_STORED | IORESOURCE_ASSIGNED; |
| 65 | |
| 66 | /* Also add MMIO resource */ |
| 67 | res = pci_get_resource(dev, PCI_BASE_ADDRESS_0); |
| 68 | } |
| 69 | |
| 70 | static struct device_operations smbus_ops = { |
| 71 | .read_resources = smbus_read_resources, |
| 72 | .set_resources = pci_dev_set_resources, |
| 73 | .enable_resources = pci_dev_enable_resources, |
Kyösti Mälkki | d0e212c | 2015-02-26 20:47:47 +0200 | [diff] [blame] | 74 | .scan_bus = scan_smbus, |
Vladimir Serbinenko | caf1df0 | 2014-08-01 02:49:27 +0200 | [diff] [blame] | 75 | .init = pch_smbus_init, |
| 76 | .ops_smbus_bus = &lops_smbus_bus, |
| 77 | .ops_pci = &smbus_pci_ops, |
| 78 | }; |
| 79 | |
Vladimir Serbinenko | caf1df0 | 2014-08-01 02:49:27 +0200 | [diff] [blame] | 80 | static const struct pci_driver pch_smbus __pci_driver = { |
| 81 | .ops = &smbus_ops, |
| 82 | .vendor = PCI_VENDOR_ID_INTEL, |
Felix Singer | 7f8b0cd8 | 2019-11-10 11:04:08 +0100 | [diff] [blame] | 83 | .device = PCI_DEVICE_ID_INTEL_82801IB_SMB, |
Vladimir Serbinenko | caf1df0 | 2014-08-01 02:49:27 +0200 | [diff] [blame] | 84 | }; |