Angel Pons | 182dbde | 2020-04-02 23:49:05 +0200 | [diff] [blame] | 1 | /* SPDX-License-Identifier: GPL-2.0-only */ |
Aaron Durbin | 76c3700 | 2012-10-30 09:03:43 -0500 | [diff] [blame] | 2 | |
Aaron Durbin | 76c3700 | 2012-10-30 09:03:43 -0500 | [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> |
Aaron Durbin | 76c3700 | 2012-10-30 09:03:43 -0500 | [diff] [blame] | 10 | #include "pch.h" |
Aaron Durbin | 76c3700 | 2012-10-30 09:03:43 -0500 | [diff] [blame] | 11 | |
Elyes HAOUAS | 38f1d13 | 2018-09-17 08:44:18 +0200 | [diff] [blame] | 12 | static void pch_smbus_init(struct device *dev) |
Aaron Durbin | 76c3700 | 2012-10-30 09:03:43 -0500 | [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); |
Aaron Durbin | 76c3700 | 2012-10-30 09:03:43 -0500 | [diff] [blame] | 26 | } |
| 27 | |
Elyes HAOUAS | 38f1d13 | 2018-09-17 08:44:18 +0200 | [diff] [blame] | 28 | static int lsmbus_read_byte(struct device *dev, u8 address) |
Aaron Durbin | 76c3700 | 2012-10-30 09:03:43 -0500 | [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); |
Duncan Laurie | 8870733 | 2013-07-15 09:07:20 -0700 | [diff] [blame] | 36 | res = find_resource(pbus->dev, PCI_BASE_ADDRESS_4); |
Aaron Durbin | 76c3700 | 2012-10-30 09:03:43 -0500 | [diff] [blame] | 37 | |
| 38 | return do_smbus_read_byte(res->base, device, address); |
| 39 | } |
| 40 | |
Elyes HAOUAS | 38f1d13 | 2018-09-17 08:44:18 +0200 | [diff] [blame] | 41 | static int lsmbus_write_byte(struct device *dev, u8 address, u8 data) |
Duncan Laurie | 8870733 | 2013-07-15 09:07:20 -0700 | [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, PCI_BASE_ADDRESS_4); |
| 50 | return do_smbus_write_byte(res->base, device, address, data); |
| 51 | } |
| 52 | |
Aaron Durbin | 76c3700 | 2012-10-30 09:03:43 -0500 | [diff] [blame] | 53 | static struct smbus_bus_operations lops_smbus_bus = { |
| 54 | .read_byte = lsmbus_read_byte, |
Duncan Laurie | 8870733 | 2013-07-15 09:07:20 -0700 | [diff] [blame] | 55 | .write_byte = lsmbus_write_byte, |
Aaron Durbin | 76c3700 | 2012-10-30 09:03:43 -0500 | [diff] [blame] | 56 | }; |
| 57 | |
Aaron Durbin | 76c3700 | 2012-10-30 09:03:43 -0500 | [diff] [blame] | 58 | static struct pci_operations smbus_pci_ops = { |
Subrata Banik | 4a0f071 | 2019-03-20 14:29:47 +0530 | [diff] [blame] | 59 | .set_subsystem = pci_dev_set_subsystem, |
Aaron Durbin | 76c3700 | 2012-10-30 09:03:43 -0500 | [diff] [blame] | 60 | }; |
| 61 | |
Elyes HAOUAS | 38f1d13 | 2018-09-17 08:44:18 +0200 | [diff] [blame] | 62 | static void smbus_read_resources(struct device *dev) |
Aaron Durbin | 76c3700 | 2012-10-30 09:03:43 -0500 | [diff] [blame] | 63 | { |
| 64 | struct resource *res = new_resource(dev, PCI_BASE_ADDRESS_4); |
| 65 | res->base = SMBUS_IO_BASE; |
| 66 | res->size = 32; |
| 67 | res->limit = res->base + res->size - 1; |
| 68 | res->flags = IORESOURCE_IO | IORESOURCE_FIXED | IORESOURCE_RESERVE | |
| 69 | IORESOURCE_STORED | IORESOURCE_ASSIGNED; |
| 70 | |
| 71 | /* Also add MMIO resource */ |
| 72 | res = pci_get_resource(dev, PCI_BASE_ADDRESS_0); |
| 73 | } |
| 74 | |
| 75 | static struct device_operations smbus_ops = { |
| 76 | .read_resources = smbus_read_resources, |
| 77 | .set_resources = pci_dev_set_resources, |
| 78 | .enable_resources = pci_dev_enable_resources, |
Kyösti Mälkki | d0e212c | 2015-02-26 20:47:47 +0200 | [diff] [blame] | 79 | .scan_bus = scan_smbus, |
Aaron Durbin | 76c3700 | 2012-10-30 09:03:43 -0500 | [diff] [blame] | 80 | .init = pch_smbus_init, |
| 81 | .ops_smbus_bus = &lops_smbus_bus, |
| 82 | .ops_pci = &smbus_pci_ops, |
| 83 | }; |
| 84 | |
Tristan Corrick | 946d3f9 | 2018-10-31 02:21:07 +1300 | [diff] [blame] | 85 | static const unsigned short pci_device_ids[] = { |
| 86 | 0x1c22, 0x1e22, 0x8c22, 0x9c22, |
| 87 | 0 |
| 88 | }; |
Aaron Durbin | 76c3700 | 2012-10-30 09:03:43 -0500 | [diff] [blame] | 89 | |
| 90 | static const struct pci_driver pch_smbus __pci_driver = { |
| 91 | .ops = &smbus_ops, |
| 92 | .vendor = PCI_VENDOR_ID_INTEL, |
| 93 | .devices = pci_device_ids, |
| 94 | }; |