Stefan Reinauer | 8e07382 | 2012-04-04 00:07:22 +0200 | [diff] [blame] | 1 | /* |
| 2 | * This file is part of the coreboot project. |
| 3 | * |
Stefan Reinauer | 8e07382 | 2012-04-04 00:07:22 +0200 | [diff] [blame] | 4 | * |
| 5 | * This program is free software; you can redistribute it and/or |
| 6 | * modify it under the terms of the GNU General Public License as |
| 7 | * published by the Free Software Foundation; version 2 of |
| 8 | * the License. |
| 9 | * |
| 10 | * This program is distributed in the hope that it will be useful, |
| 11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 13 | * GNU General Public License for more details. |
Stefan Reinauer | 8e07382 | 2012-04-04 00:07:22 +0200 | [diff] [blame] | 14 | */ |
| 15 | |
Stefan Reinauer | 8e07382 | 2012-04-04 00:07:22 +0200 | [diff] [blame] | 16 | #include <device/device.h> |
| 17 | #include <device/path.h> |
| 18 | #include <device/smbus.h> |
| 19 | #include <device/pci.h> |
| 20 | #include <device/pci_ids.h> |
| 21 | #include <device/pci_ops.h> |
Kyösti Mälkki | 1cae454 | 2020-01-06 12:31:34 +0200 | [diff] [blame] | 22 | #include <device/smbus_host.h> |
Stefan Reinauer | 8e07382 | 2012-04-04 00:07:22 +0200 | [diff] [blame] | 23 | #include "pch.h" |
Stefan Reinauer | 8e07382 | 2012-04-04 00:07:22 +0200 | [diff] [blame] | 24 | |
Elyes HAOUAS | 4aec340 | 2018-05-25 08:29:27 +0200 | [diff] [blame] | 25 | static void pch_smbus_init(struct device *dev) |
Stefan Reinauer | 8e07382 | 2012-04-04 00:07:22 +0200 | [diff] [blame] | 26 | { |
| 27 | struct resource *res; |
| 28 | u16 reg16; |
| 29 | |
| 30 | /* Enable clock gating */ |
| 31 | reg16 = pci_read_config32(dev, 0x80); |
| 32 | reg16 &= ~((1 << 8)|(1 << 10)|(1 << 12)|(1 << 14)); |
| 33 | pci_write_config32(dev, 0x80, reg16); |
| 34 | |
| 35 | /* Set Receive Slave Address */ |
| 36 | res = find_resource(dev, PCI_BASE_ADDRESS_4); |
| 37 | if (res) |
Kyösti Mälkki | 73451fd | 2020-01-06 19:00:31 +0200 | [diff] [blame] | 38 | smbus_set_slave_addr(res->base, SMBUS_SLAVE_ADDR); |
Stefan Reinauer | 8e07382 | 2012-04-04 00:07:22 +0200 | [diff] [blame] | 39 | } |
| 40 | |
Elyes HAOUAS | 4aec340 | 2018-05-25 08:29:27 +0200 | [diff] [blame] | 41 | static int lsmbus_read_byte(struct device *dev, u8 address) |
Stefan Reinauer | 8e07382 | 2012-04-04 00:07:22 +0200 | [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_read_byte(res->base, device, address); |
| 52 | } |
| 53 | |
Elyes HAOUAS | 4aec340 | 2018-05-25 08:29:27 +0200 | [diff] [blame] | 54 | static int lsmbus_write_byte(struct device *dev, u8 address, u8 val) |
Vladimir Serbinenko | e57718f | 2014-01-27 23:48:27 +0100 | [diff] [blame] | 55 | { |
| 56 | u16 device; |
| 57 | struct resource *res; |
| 58 | struct bus *pbus; |
| 59 | |
| 60 | device = dev->path.i2c.device; |
| 61 | pbus = get_pbus_smbus(dev); |
| 62 | res = find_resource(pbus->dev, 0x20); |
| 63 | |
| 64 | return do_smbus_write_byte(res->base, device, address, val); |
| 65 | } |
| 66 | |
Stefan Reinauer | 8e07382 | 2012-04-04 00:07:22 +0200 | [diff] [blame] | 67 | static struct smbus_bus_operations lops_smbus_bus = { |
| 68 | .read_byte = lsmbus_read_byte, |
Vladimir Serbinenko | e57718f | 2014-01-27 23:48:27 +0100 | [diff] [blame] | 69 | .write_byte = lsmbus_write_byte, |
Stefan Reinauer | 8e07382 | 2012-04-04 00:07:22 +0200 | [diff] [blame] | 70 | }; |
| 71 | |
Stefan Reinauer | 8e07382 | 2012-04-04 00:07:22 +0200 | [diff] [blame] | 72 | static struct pci_operations smbus_pci_ops = { |
Subrata Banik | 4a0f071 | 2019-03-20 14:29:47 +0530 | [diff] [blame] | 73 | .set_subsystem = pci_dev_set_subsystem, |
Stefan Reinauer | 8e07382 | 2012-04-04 00:07:22 +0200 | [diff] [blame] | 74 | }; |
| 75 | |
Elyes HAOUAS | 4aec340 | 2018-05-25 08:29:27 +0200 | [diff] [blame] | 76 | static void smbus_read_resources(struct device *dev) |
Stefan Reinauer | 8e07382 | 2012-04-04 00:07:22 +0200 | [diff] [blame] | 77 | { |
| 78 | struct resource *res = new_resource(dev, PCI_BASE_ADDRESS_4); |
| 79 | res->base = SMBUS_IO_BASE; |
| 80 | res->size = 32; |
| 81 | res->limit = res->base + res->size - 1; |
| 82 | res->flags = IORESOURCE_IO | IORESOURCE_FIXED | IORESOURCE_RESERVE | |
| 83 | IORESOURCE_STORED | IORESOURCE_ASSIGNED; |
| 84 | |
| 85 | /* Also add MMIO resource */ |
| 86 | res = pci_get_resource(dev, PCI_BASE_ADDRESS_0); |
| 87 | } |
| 88 | |
Aaron Durbin | aa090cb | 2017-09-13 16:01:52 -0600 | [diff] [blame] | 89 | static const char *smbus_acpi_name(const struct device *dev) |
Patrick Rudolph | 604f698 | 2017-06-07 09:46:52 +0200 | [diff] [blame] | 90 | { |
| 91 | return "SBUS"; |
| 92 | } |
| 93 | |
Stefan Reinauer | 8e07382 | 2012-04-04 00:07:22 +0200 | [diff] [blame] | 94 | static struct device_operations smbus_ops = { |
| 95 | .read_resources = smbus_read_resources, |
| 96 | .set_resources = pci_dev_set_resources, |
| 97 | .enable_resources = pci_dev_enable_resources, |
Kyösti Mälkki | d0e212c | 2015-02-26 20:47:47 +0200 | [diff] [blame] | 98 | .scan_bus = scan_smbus, |
Stefan Reinauer | 8e07382 | 2012-04-04 00:07:22 +0200 | [diff] [blame] | 99 | .init = pch_smbus_init, |
| 100 | .ops_smbus_bus = &lops_smbus_bus, |
| 101 | .ops_pci = &smbus_pci_ops, |
Patrick Rudolph | 604f698 | 2017-06-07 09:46:52 +0200 | [diff] [blame] | 102 | .acpi_name = smbus_acpi_name, |
Stefan Reinauer | 8e07382 | 2012-04-04 00:07:22 +0200 | [diff] [blame] | 103 | }; |
| 104 | |
Stefan Reinauer | 9a380ab | 2012-06-22 13:16:11 -0700 | [diff] [blame] | 105 | static const unsigned short pci_device_ids[] = { 0x1c22, 0x1e22, 0 }; |
Stefan Reinauer | 8e07382 | 2012-04-04 00:07:22 +0200 | [diff] [blame] | 106 | |
Stefan Reinauer | 9a380ab | 2012-06-22 13:16:11 -0700 | [diff] [blame] | 107 | static const struct pci_driver pch_smbus __pci_driver = { |
| 108 | .ops = &smbus_ops, |
| 109 | .vendor = PCI_VENDOR_ID_INTEL, |
| 110 | .devices = pci_device_ids, |
Stefan Reinauer | 8e07382 | 2012-04-04 00:07:22 +0200 | [diff] [blame] | 111 | }; |