Angel Pons | 182dbde | 2020-04-02 23:49:05 +0200 | [diff] [blame^] | 1 | /* SPDX-License-Identifier: GPL-2.0-only */ |
| 2 | /* This file is part of the coreboot project. */ |
Stefan Reinauer | 8e07382 | 2012-04-04 00:07:22 +0200 | [diff] [blame] | 3 | |
Stefan Reinauer | 8e07382 | 2012-04-04 00:07:22 +0200 | [diff] [blame] | 4 | #include <device/device.h> |
| 5 | #include <device/path.h> |
| 6 | #include <device/smbus.h> |
| 7 | #include <device/pci.h> |
| 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> |
Stefan Reinauer | 8e07382 | 2012-04-04 00:07:22 +0200 | [diff] [blame] | 11 | #include "pch.h" |
Stefan Reinauer | 8e07382 | 2012-04-04 00:07:22 +0200 | [diff] [blame] | 12 | |
Elyes HAOUAS | 4aec340 | 2018-05-25 08:29:27 +0200 | [diff] [blame] | 13 | static void pch_smbus_init(struct device *dev) |
Stefan Reinauer | 8e07382 | 2012-04-04 00:07:22 +0200 | [diff] [blame] | 14 | { |
| 15 | struct resource *res; |
| 16 | u16 reg16; |
| 17 | |
| 18 | /* Enable clock gating */ |
| 19 | reg16 = pci_read_config32(dev, 0x80); |
| 20 | reg16 &= ~((1 << 8)|(1 << 10)|(1 << 12)|(1 << 14)); |
| 21 | pci_write_config32(dev, 0x80, reg16); |
| 22 | |
| 23 | /* Set Receive Slave Address */ |
| 24 | res = find_resource(dev, PCI_BASE_ADDRESS_4); |
| 25 | if (res) |
Kyösti Mälkki | 73451fd | 2020-01-06 19:00:31 +0200 | [diff] [blame] | 26 | smbus_set_slave_addr(res->base, SMBUS_SLAVE_ADDR); |
Stefan Reinauer | 8e07382 | 2012-04-04 00:07:22 +0200 | [diff] [blame] | 27 | } |
| 28 | |
Elyes HAOUAS | 4aec340 | 2018-05-25 08:29:27 +0200 | [diff] [blame] | 29 | static int lsmbus_read_byte(struct device *dev, u8 address) |
Stefan Reinauer | 8e07382 | 2012-04-04 00:07:22 +0200 | [diff] [blame] | 30 | { |
| 31 | u16 device; |
| 32 | struct resource *res; |
| 33 | struct bus *pbus; |
| 34 | |
| 35 | device = dev->path.i2c.device; |
| 36 | pbus = get_pbus_smbus(dev); |
| 37 | res = find_resource(pbus->dev, 0x20); |
| 38 | |
| 39 | return do_smbus_read_byte(res->base, device, address); |
| 40 | } |
| 41 | |
Elyes HAOUAS | 4aec340 | 2018-05-25 08:29:27 +0200 | [diff] [blame] | 42 | static int lsmbus_write_byte(struct device *dev, u8 address, u8 val) |
Vladimir Serbinenko | e57718f | 2014-01-27 23:48:27 +0100 | [diff] [blame] | 43 | { |
| 44 | u16 device; |
| 45 | struct resource *res; |
| 46 | struct bus *pbus; |
| 47 | |
| 48 | device = dev->path.i2c.device; |
| 49 | pbus = get_pbus_smbus(dev); |
| 50 | res = find_resource(pbus->dev, 0x20); |
| 51 | |
| 52 | return do_smbus_write_byte(res->base, device, address, val); |
| 53 | } |
| 54 | |
Stefan Reinauer | 8e07382 | 2012-04-04 00:07:22 +0200 | [diff] [blame] | 55 | static struct smbus_bus_operations lops_smbus_bus = { |
| 56 | .read_byte = lsmbus_read_byte, |
Vladimir Serbinenko | e57718f | 2014-01-27 23:48:27 +0100 | [diff] [blame] | 57 | .write_byte = lsmbus_write_byte, |
Stefan Reinauer | 8e07382 | 2012-04-04 00:07:22 +0200 | [diff] [blame] | 58 | }; |
| 59 | |
Stefan Reinauer | 8e07382 | 2012-04-04 00:07:22 +0200 | [diff] [blame] | 60 | static struct pci_operations smbus_pci_ops = { |
Subrata Banik | 4a0f071 | 2019-03-20 14:29:47 +0530 | [diff] [blame] | 61 | .set_subsystem = pci_dev_set_subsystem, |
Stefan Reinauer | 8e07382 | 2012-04-04 00:07:22 +0200 | [diff] [blame] | 62 | }; |
| 63 | |
Elyes HAOUAS | 4aec340 | 2018-05-25 08:29:27 +0200 | [diff] [blame] | 64 | static void smbus_read_resources(struct device *dev) |
Stefan Reinauer | 8e07382 | 2012-04-04 00:07:22 +0200 | [diff] [blame] | 65 | { |
| 66 | struct resource *res = new_resource(dev, PCI_BASE_ADDRESS_4); |
| 67 | res->base = SMBUS_IO_BASE; |
| 68 | res->size = 32; |
| 69 | res->limit = res->base + res->size - 1; |
| 70 | res->flags = IORESOURCE_IO | IORESOURCE_FIXED | IORESOURCE_RESERVE | |
| 71 | IORESOURCE_STORED | IORESOURCE_ASSIGNED; |
| 72 | |
| 73 | /* Also add MMIO resource */ |
| 74 | res = pci_get_resource(dev, PCI_BASE_ADDRESS_0); |
| 75 | } |
| 76 | |
Aaron Durbin | aa090cb | 2017-09-13 16:01:52 -0600 | [diff] [blame] | 77 | static const char *smbus_acpi_name(const struct device *dev) |
Patrick Rudolph | 604f698 | 2017-06-07 09:46:52 +0200 | [diff] [blame] | 78 | { |
| 79 | return "SBUS"; |
| 80 | } |
| 81 | |
Stefan Reinauer | 8e07382 | 2012-04-04 00:07:22 +0200 | [diff] [blame] | 82 | static struct device_operations smbus_ops = { |
| 83 | .read_resources = smbus_read_resources, |
| 84 | .set_resources = pci_dev_set_resources, |
| 85 | .enable_resources = pci_dev_enable_resources, |
Kyösti Mälkki | d0e212c | 2015-02-26 20:47:47 +0200 | [diff] [blame] | 86 | .scan_bus = scan_smbus, |
Stefan Reinauer | 8e07382 | 2012-04-04 00:07:22 +0200 | [diff] [blame] | 87 | .init = pch_smbus_init, |
| 88 | .ops_smbus_bus = &lops_smbus_bus, |
| 89 | .ops_pci = &smbus_pci_ops, |
Patrick Rudolph | 604f698 | 2017-06-07 09:46:52 +0200 | [diff] [blame] | 90 | .acpi_name = smbus_acpi_name, |
Stefan Reinauer | 8e07382 | 2012-04-04 00:07:22 +0200 | [diff] [blame] | 91 | }; |
| 92 | |
Stefan Reinauer | 9a380ab | 2012-06-22 13:16:11 -0700 | [diff] [blame] | 93 | static const unsigned short pci_device_ids[] = { 0x1c22, 0x1e22, 0 }; |
Stefan Reinauer | 8e07382 | 2012-04-04 00:07:22 +0200 | [diff] [blame] | 94 | |
Stefan Reinauer | 9a380ab | 2012-06-22 13:16:11 -0700 | [diff] [blame] | 95 | static const struct pci_driver pch_smbus __pci_driver = { |
| 96 | .ops = &smbus_ops, |
| 97 | .vendor = PCI_VENDOR_ID_INTEL, |
| 98 | .devices = pci_device_ids, |
Stefan Reinauer | 8e07382 | 2012-04-04 00:07:22 +0200 | [diff] [blame] | 99 | }; |