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