Angel Pons | 182dbde | 2020-04-02 23:49:05 +0200 | [diff] [blame] | 1 | /* SPDX-License-Identifier: GPL-2.0-only */ |
Vladimir Serbinenko | 888d559 | 2013-11-13 17:53:38 +0100 | [diff] [blame] | 2 | |
Vladimir Serbinenko | 888d559 | 2013-11-13 17:53:38 +0100 | [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> |
Vladimir Serbinenko | 888d559 | 2013-11-13 17:53:38 +0100 | [diff] [blame] | 10 | #include "pch.h" |
Vladimir Serbinenko | 888d559 | 2013-11-13 17:53:38 +0100 | [diff] [blame] | 11 | |
Elyes HAOUAS | be84140 | 2018-05-13 13:40:39 +0200 | [diff] [blame] | 12 | static void pch_smbus_init(struct device *dev) |
Vladimir Serbinenko | 888d559 | 2013-11-13 17:53:38 +0100 | [diff] [blame] | 13 | { |
| 14 | struct resource *res; |
| 15 | u16 reg16; |
| 16 | |
| 17 | /* Enable clock gating */ |
| 18 | reg16 = pci_read_config32(dev, 0x80); |
| 19 | reg16 &= ~((1 << 8)|(1 << 10)|(1 << 12)|(1 << 14)); |
| 20 | pci_write_config32(dev, 0x80, reg16); |
| 21 | |
| 22 | /* Set Receive Slave Address */ |
| 23 | res = find_resource(dev, PCI_BASE_ADDRESS_4); |
| 24 | if (res) |
Kyösti Mälkki | 73451fd | 2020-01-06 19:00:31 +0200 | [diff] [blame] | 25 | smbus_set_slave_addr(res->base, SMBUS_SLAVE_ADDR); |
Vladimir Serbinenko | 888d559 | 2013-11-13 17:53:38 +0100 | [diff] [blame] | 26 | } |
| 27 | |
Elyes HAOUAS | be84140 | 2018-05-13 13:40:39 +0200 | [diff] [blame] | 28 | static int lsmbus_read_byte(struct device *dev, u8 address) |
Vladimir Serbinenko | 888d559 | 2013-11-13 17:53:38 +0100 | [diff] [blame] | 29 | { |
| 30 | u16 device; |
| 31 | struct resource *res; |
| 32 | struct bus *pbus; |
| 33 | |
| 34 | device = dev->path.i2c.device; |
| 35 | pbus = get_pbus_smbus(dev); |
| 36 | res = find_resource(pbus->dev, 0x20); |
| 37 | |
| 38 | return do_smbus_read_byte(res->base, device, address); |
| 39 | } |
| 40 | |
Elyes HAOUAS | be84140 | 2018-05-13 13:40:39 +0200 | [diff] [blame] | 41 | static int lsmbus_write_byte(struct device *dev, u8 address, u8 val) |
Vladimir Serbinenko | 5f20dbf | 2014-01-27 23:57:44 +0100 | [diff] [blame] | 42 | { |
| 43 | u16 device; |
| 44 | struct resource *res; |
| 45 | struct bus *pbus; |
| 46 | |
| 47 | device = dev->path.i2c.device; |
| 48 | pbus = get_pbus_smbus(dev); |
| 49 | res = find_resource(pbus->dev, 0x20); |
| 50 | |
| 51 | return do_smbus_write_byte(res->base, device, address, val); |
| 52 | } |
| 53 | |
Vladimir Serbinenko | 888d559 | 2013-11-13 17:53:38 +0100 | [diff] [blame] | 54 | static struct smbus_bus_operations lops_smbus_bus = { |
| 55 | .read_byte = lsmbus_read_byte, |
Vladimir Serbinenko | 5f20dbf | 2014-01-27 23:57:44 +0100 | [diff] [blame] | 56 | .write_byte = lsmbus_write_byte, |
Vladimir Serbinenko | 888d559 | 2013-11-13 17:53:38 +0100 | [diff] [blame] | 57 | }; |
| 58 | |
Elyes HAOUAS | be84140 | 2018-05-13 13:40:39 +0200 | [diff] [blame] | 59 | static void smbus_read_resources(struct device *dev) |
Vladimir Serbinenko | 888d559 | 2013-11-13 17:53:38 +0100 | [diff] [blame] | 60 | { |
| 61 | struct resource *res = new_resource(dev, PCI_BASE_ADDRESS_4); |
Angel Pons | b21bffa | 2020-07-03 01:02:28 +0200 | [diff] [blame^] | 62 | res->base = CONFIG_FIXED_SMBUS_IO_BASE; |
Vladimir Serbinenko | 888d559 | 2013-11-13 17:53:38 +0100 | [diff] [blame] | 63 | res->size = 32; |
| 64 | res->limit = res->base + res->size - 1; |
| 65 | res->flags = IORESOURCE_IO | IORESOURCE_FIXED | IORESOURCE_RESERVE | |
| 66 | IORESOURCE_STORED | IORESOURCE_ASSIGNED; |
| 67 | |
| 68 | /* Also add MMIO resource */ |
| 69 | res = pci_get_resource(dev, PCI_BASE_ADDRESS_0); |
| 70 | } |
| 71 | |
| 72 | static struct device_operations smbus_ops = { |
| 73 | .read_resources = smbus_read_resources, |
| 74 | .set_resources = pci_dev_set_resources, |
| 75 | .enable_resources = pci_dev_enable_resources, |
Kyösti Mälkki | d0e212c | 2015-02-26 20:47:47 +0200 | [diff] [blame] | 76 | .scan_bus = scan_smbus, |
Vladimir Serbinenko | 888d559 | 2013-11-13 17:53:38 +0100 | [diff] [blame] | 77 | .init = pch_smbus_init, |
| 78 | .ops_smbus_bus = &lops_smbus_bus, |
Angel Pons | 1fc0edd | 2020-05-31 00:03:28 +0200 | [diff] [blame] | 79 | .ops_pci = &pci_dev_ops_pci, |
Vladimir Serbinenko | 888d559 | 2013-11-13 17:53:38 +0100 | [diff] [blame] | 80 | }; |
| 81 | |
Felix Singer | 838fbc7 | 2019-11-21 21:23:32 +0100 | [diff] [blame] | 82 | static const unsigned short pci_device_ids[] = { |
| 83 | 0x1c22, |
| 84 | 0x1e22, |
| 85 | PCI_DID_INTEL_IBEXPEAK_SMBUS, |
| 86 | 0 |
| 87 | }; |
Vladimir Serbinenko | 888d559 | 2013-11-13 17:53:38 +0100 | [diff] [blame] | 88 | |
| 89 | static const struct pci_driver pch_smbus __pci_driver = { |
| 90 | .ops = &smbus_ops, |
| 91 | .vendor = PCI_VENDOR_ID_INTEL, |
| 92 | .devices = pci_device_ids, |
| 93 | }; |