Aamir Bohra | 52f2974 | 2017-04-19 18:19:14 +0530 | [diff] [blame] | 1 | /* |
| 2 | * This file is part of the coreboot project. |
| 3 | * |
| 4 | * Copyright (C) 2017 Intel Corporation. |
| 5 | * |
| 6 | * This program is free software; you can redistribute it and/or modify |
| 7 | * it under the terms of the GNU General Public License as published by |
| 8 | * the Free Software Foundation; version 2 of 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. |
| 14 | */ |
| 15 | |
| 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> |
| 22 | #include <soc/smbus.h> |
| 23 | #include "smbuslib.h" |
| 24 | |
| 25 | static int lsmbus_read_byte(device_t dev, u8 address) |
| 26 | { |
| 27 | u16 device; |
| 28 | struct resource *res; |
| 29 | struct bus *pbus; |
| 30 | device = dev->path.i2c.device; |
| 31 | pbus = get_pbus_smbus(dev); |
| 32 | res = find_resource(pbus->dev, PCI_BASE_ADDRESS_4); |
| 33 | return smbus_read8(res->base, device, address); |
| 34 | } |
| 35 | |
| 36 | static int lsmbus_write_byte(device_t dev, u8 address, u8 data) |
| 37 | { |
| 38 | u16 device; |
| 39 | struct resource *res; |
| 40 | struct bus *pbus; |
| 41 | |
| 42 | device = dev->path.i2c.device; |
| 43 | pbus = get_pbus_smbus(dev); |
| 44 | res = find_resource(pbus->dev, PCI_BASE_ADDRESS_4); |
| 45 | return smbus_write8(res->base, device, address, data); |
| 46 | } |
| 47 | |
| 48 | static struct smbus_bus_operations lops_smbus_bus = { |
| 49 | .read_byte = lsmbus_read_byte, |
| 50 | .write_byte = lsmbus_write_byte, |
| 51 | }; |
| 52 | |
| 53 | static void pch_smbus_init(device_t dev) |
| 54 | { |
| 55 | struct resource *res; |
Aamir Bohra | 52f2974 | 2017-04-19 18:19:14 +0530 | [diff] [blame] | 56 | |
| 57 | /* Enable clock gating */ |
Nico Huber | 6278867 | 2017-08-17 16:08:00 +0200 | [diff] [blame] | 58 | pci_update_config32(dev, 0x80, |
| 59 | ~((1 << 8) | (1 << 10) | (1 << 12) | (1 << 14)), 0); |
Aamir Bohra | 52f2974 | 2017-04-19 18:19:14 +0530 | [diff] [blame] | 60 | |
| 61 | /* Set Receive Slave Address */ |
| 62 | res = find_resource(dev, PCI_BASE_ADDRESS_4); |
| 63 | if (res) |
| 64 | outb(SMBUS_SLAVE_ADDR, res->base + SMB_RCV_SLVA); |
| 65 | } |
| 66 | |
| 67 | static void smbus_read_resources(device_t dev) |
| 68 | { |
| 69 | struct resource *res = new_resource(dev, PCI_BASE_ADDRESS_4); |
| 70 | res->base = SMBUS_IO_BASE; |
| 71 | res->size = 32; |
| 72 | res->limit = res->base + res->size - 1; |
| 73 | res->flags = IORESOURCE_IO | IORESOURCE_FIXED | IORESOURCE_RESERVE | |
| 74 | IORESOURCE_STORED | IORESOURCE_ASSIGNED; |
| 75 | |
| 76 | /* Also add MMIO resource */ |
| 77 | res = pci_get_resource(dev, PCI_BASE_ADDRESS_0); |
| 78 | } |
| 79 | |
| 80 | static struct device_operations smbus_ops = { |
| 81 | .read_resources = &smbus_read_resources, |
| 82 | .set_resources = &pci_dev_set_resources, |
| 83 | .enable_resources = &pci_dev_enable_resources, |
| 84 | .scan_bus = &scan_smbus, |
| 85 | .init = &pch_smbus_init, |
Subrata Banik | 6bbc91a | 2017-12-07 14:55:51 +0530 | [diff] [blame] | 86 | .ops_pci = &pci_dev_ops_pci, |
Aamir Bohra | 52f2974 | 2017-04-19 18:19:14 +0530 | [diff] [blame] | 87 | .ops_smbus_bus = &lops_smbus_bus, |
| 88 | }; |
| 89 | |
| 90 | static const unsigned short pci_device_ids[] = { |
Lijian Zhao | bbedef9 | 2017-07-29 16:38:38 -0700 | [diff] [blame] | 91 | PCI_DEVICE_ID_INTEL_CNL_SMBUS, |
Aamir Bohra | 52f2974 | 2017-04-19 18:19:14 +0530 | [diff] [blame] | 92 | PCI_DEVICE_ID_INTEL_SPT_LP_SMBUS, |
| 93 | PCI_DEVICE_ID_INTEL_SPT_H_SMBUS, |
V Sowmya | acc2a48 | 2018-01-23 15:27:23 +0530 | [diff] [blame] | 94 | PCI_DEVICE_ID_INTEL_KBP_H_SMBUS, |
Aamir Bohra | 52f2974 | 2017-04-19 18:19:14 +0530 | [diff] [blame] | 95 | 0 |
| 96 | }; |
| 97 | |
| 98 | static const struct pci_driver pch_smbus __pci_driver = { |
| 99 | .ops = &smbus_ops, |
| 100 | .vendor = PCI_VENDOR_ID_INTEL, |
| 101 | .devices = pci_device_ids, |
| 102 | }; |