Angel Pons | 182dbde | 2020-04-02 23:49:05 +0200 | [diff] [blame] | 1 | /* SPDX-License-Identifier: GPL-2.0-only */ |
Arthur Heymans | 7b9c139 | 2017-04-09 20:40:39 +0200 | [diff] [blame] | 2 | |
Arthur Heymans | 7b9c139 | 2017-04-09 20:40:39 +0200 | [diff] [blame] | 3 | #include <device/device.h> |
| 4 | #include <device/path.h> |
| 5 | #include <device/smbus.h> |
| 6 | #include <device/pci.h> |
Elyes HAOUAS | a4dd33c | 2020-08-11 09:39:43 +0200 | [diff] [blame] | 7 | #include <device/pci_def.h> |
Arthur Heymans | 7b9c139 | 2017-04-09 20:40:39 +0200 | [diff] [blame] | 8 | #include <device/pci_ids.h> |
| 9 | #include <device/pci_ops.h> |
Kyösti Mälkki | 1cae454 | 2020-01-06 12:31:34 +0200 | [diff] [blame] | 10 | #include <device/smbus_host.h> |
Arthur Heymans | 16fe790 | 2017-04-12 17:01:31 +0200 | [diff] [blame] | 11 | #include "i82801jx.h" |
Arthur Heymans | 7b9c139 | 2017-04-09 20:40:39 +0200 | [diff] [blame] | 12 | |
Elyes HAOUAS | 1a8c1df | 2018-05-13 13:36:44 +0200 | [diff] [blame] | 13 | static void pch_smbus_init(struct device *dev) |
Arthur Heymans | 7b9c139 | 2017-04-09 20:40:39 +0200 | [diff] [blame] | 14 | { |
Arthur Heymans | 7b9c139 | 2017-04-09 20:40:39 +0200 | [diff] [blame] | 15 | /* Enable clock gating */ |
Angel Pons | 2048cb4 | 2020-06-08 02:09:33 +0200 | [diff] [blame] | 16 | pci_and_config16(dev, 0x80, ~((1 << 8) | (1 << 10) | (1 << 12) | (1 << 14))); |
Arthur Heymans | 7b9c139 | 2017-04-09 20:40:39 +0200 | [diff] [blame] | 17 | } |
| 18 | |
Elyes HAOUAS | 1a8c1df | 2018-05-13 13:36:44 +0200 | [diff] [blame] | 19 | static int lsmbus_read_byte(struct device *dev, u8 address) |
Arthur Heymans | 7b9c139 | 2017-04-09 20:40:39 +0200 | [diff] [blame] | 20 | { |
| 21 | u16 device; |
| 22 | struct resource *res; |
| 23 | struct bus *pbus; |
| 24 | |
| 25 | device = dev->path.i2c.device; |
| 26 | pbus = get_pbus_smbus(dev); |
Elyes HAOUAS | a4dd33c | 2020-08-11 09:39:43 +0200 | [diff] [blame] | 27 | res = find_resource(pbus->dev, PCI_BASE_ADDRESS_4); |
Arthur Heymans | 7b9c139 | 2017-04-09 20:40:39 +0200 | [diff] [blame] | 28 | |
| 29 | return do_smbus_read_byte(res->base, device, address); |
| 30 | } |
| 31 | |
Angel Pons | bb19d39 | 2020-12-05 20:23:40 +0100 | [diff] [blame] | 32 | static int lsmbus_write_byte(struct device *dev, u8 address, u8 data) |
Arthur Heymans | 7b9c139 | 2017-04-09 20:40:39 +0200 | [diff] [blame] | 33 | { |
| 34 | u16 device; |
| 35 | struct resource *res; |
| 36 | struct bus *pbus; |
| 37 | |
| 38 | device = dev->path.i2c.device; |
| 39 | pbus = get_pbus_smbus(dev); |
Elyes HAOUAS | a4dd33c | 2020-08-11 09:39:43 +0200 | [diff] [blame] | 40 | res = find_resource(pbus->dev, PCI_BASE_ADDRESS_4); |
Angel Pons | bb19d39 | 2020-12-05 20:23:40 +0100 | [diff] [blame] | 41 | return do_smbus_write_byte(res->base, device, address, data); |
Arthur Heymans | 7b9c139 | 2017-04-09 20:40:39 +0200 | [diff] [blame] | 42 | } |
| 43 | |
Angel Pons | 244cf7d | 2020-12-05 20:25:27 +0100 | [diff] [blame] | 44 | static int lsmbus_block_write(struct device *dev, u8 cmd, u8 bytes, const u8 *buf) |
Arthur Heymans | 33863b6 | 2017-09-07 17:05:17 +0200 | [diff] [blame] | 45 | { |
| 46 | u16 device; |
| 47 | struct resource *res; |
| 48 | struct bus *pbus; |
| 49 | |
| 50 | device = dev->path.i2c.device; |
| 51 | pbus = get_pbus_smbus(dev); |
Elyes HAOUAS | a4dd33c | 2020-08-11 09:39:43 +0200 | [diff] [blame] | 52 | res = find_resource(pbus->dev, PCI_BASE_ADDRESS_4); |
Arthur Heymans | 33863b6 | 2017-09-07 17:05:17 +0200 | [diff] [blame] | 53 | return do_smbus_block_write(res->base, device, cmd, bytes, buf); |
| 54 | } |
| 55 | |
Elyes HAOUAS | 1a8c1df | 2018-05-13 13:36:44 +0200 | [diff] [blame] | 56 | static int lsmbus_block_read(struct device *dev, u8 cmd, u8 bytes, u8 *buf) |
Arthur Heymans | 33863b6 | 2017-09-07 17:05:17 +0200 | [diff] [blame] | 57 | { |
| 58 | u16 device; |
| 59 | struct resource *res; |
| 60 | struct bus *pbus; |
| 61 | |
| 62 | device = dev->path.i2c.device; |
| 63 | pbus = get_pbus_smbus(dev); |
Elyes HAOUAS | a4dd33c | 2020-08-11 09:39:43 +0200 | [diff] [blame] | 64 | res = find_resource(pbus->dev, PCI_BASE_ADDRESS_4); |
Arthur Heymans | 33863b6 | 2017-09-07 17:05:17 +0200 | [diff] [blame] | 65 | return do_smbus_block_read(res->base, device, cmd, bytes, buf); |
| 66 | } |
| 67 | |
Arthur Heymans | 7b9c139 | 2017-04-09 20:40:39 +0200 | [diff] [blame] | 68 | static struct smbus_bus_operations lops_smbus_bus = { |
| 69 | .read_byte = lsmbus_read_byte, |
| 70 | .write_byte = lsmbus_write_byte, |
Angel Pons | 244cf7d | 2020-12-05 20:25:27 +0100 | [diff] [blame] | 71 | .block_read = lsmbus_block_read, |
| 72 | .block_write = lsmbus_block_write, |
Arthur Heymans | 7b9c139 | 2017-04-09 20:40:39 +0200 | [diff] [blame] | 73 | }; |
| 74 | |
Elyes HAOUAS | 1a8c1df | 2018-05-13 13:36:44 +0200 | [diff] [blame] | 75 | static void smbus_read_resources(struct device *dev) |
Arthur Heymans | 7b9c139 | 2017-04-09 20:40:39 +0200 | [diff] [blame] | 76 | { |
| 77 | struct resource *res = new_resource(dev, PCI_BASE_ADDRESS_4); |
Angel Pons | b21bffa | 2020-07-03 01:02:28 +0200 | [diff] [blame] | 78 | res->base = CONFIG_FIXED_SMBUS_IO_BASE; |
Arthur Heymans | 7b9c139 | 2017-04-09 20:40:39 +0200 | [diff] [blame] | 79 | res->size = 32; |
| 80 | res->limit = res->base + res->size - 1; |
| 81 | res->flags = IORESOURCE_IO | IORESOURCE_FIXED | IORESOURCE_RESERVE | |
| 82 | IORESOURCE_STORED | IORESOURCE_ASSIGNED; |
| 83 | |
| 84 | /* Also add MMIO resource */ |
| 85 | res = pci_get_resource(dev, PCI_BASE_ADDRESS_0); |
| 86 | } |
| 87 | |
| 88 | static struct device_operations smbus_ops = { |
| 89 | .read_resources = smbus_read_resources, |
| 90 | .set_resources = pci_dev_set_resources, |
| 91 | .enable_resources = pci_dev_enable_resources, |
| 92 | .scan_bus = scan_smbus, |
| 93 | .init = pch_smbus_init, |
| 94 | .ops_smbus_bus = &lops_smbus_bus, |
Angel Pons | 1fc0edd | 2020-05-31 00:03:28 +0200 | [diff] [blame] | 95 | .ops_pci = &pci_dev_ops_pci, |
Arthur Heymans | 7b9c139 | 2017-04-09 20:40:39 +0200 | [diff] [blame] | 96 | }; |
| 97 | |
Arthur Heymans | 349e085 | 2017-04-09 20:48:37 +0200 | [diff] [blame] | 98 | static const unsigned short pci_device_ids[] = |
| 99 | { |
| 100 | 0x3a30, |
| 101 | 0x3a60, |
| 102 | 0 |
| 103 | }; |
Arthur Heymans | 7b9c139 | 2017-04-09 20:40:39 +0200 | [diff] [blame] | 104 | |
| 105 | static const struct pci_driver pch_smbus __pci_driver = { |
| 106 | .ops = &smbus_ops, |
| 107 | .vendor = PCI_VENDOR_ID_INTEL, |
| 108 | .devices = pci_device_ids, |
| 109 | }; |