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 | |
Kyösti Mälkki | bdaec07 | 2019-03-02 23:18:29 +0200 | [diff] [blame] | 16 | #include <arch/io.h> |
Aamir Bohra | 52f2974 | 2017-04-19 18:19:14 +0530 | [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> |
Aamir Bohra | 52f2974 | 2017-04-19 18:19:14 +0530 | [diff] [blame] | 22 | #include <soc/smbus.h> |
Kyösti Mälkki | bbcf1a0 | 2020-01-01 17:42:45 +0200 | [diff] [blame] | 23 | #include <southbridge/intel/common/smbus.h> |
Kyösti Mälkki | 1cae454 | 2020-01-06 12:31:34 +0200 | [diff] [blame] | 24 | #include <device/smbus_host.h> |
Aamir Bohra | 52f2974 | 2017-04-19 18:19:14 +0530 | [diff] [blame] | 25 | #include "smbuslib.h" |
| 26 | |
Elyes HAOUAS | 4a13126 | 2018-09-16 17:35:48 +0200 | [diff] [blame] | 27 | static int lsmbus_read_byte(struct device *dev, u8 address) |
Aamir Bohra | 52f2974 | 2017-04-19 18:19:14 +0530 | [diff] [blame] | 28 | { |
| 29 | u16 device; |
| 30 | struct resource *res; |
| 31 | struct bus *pbus; |
| 32 | device = dev->path.i2c.device; |
| 33 | pbus = get_pbus_smbus(dev); |
| 34 | res = find_resource(pbus->dev, PCI_BASE_ADDRESS_4); |
Kyösti Mälkki | 4ae9f1e | 2020-01-01 17:42:45 +0200 | [diff] [blame] | 35 | return do_smbus_read_byte(res->base, device, address); |
Aamir Bohra | 52f2974 | 2017-04-19 18:19:14 +0530 | [diff] [blame] | 36 | } |
| 37 | |
Elyes HAOUAS | 4a13126 | 2018-09-16 17:35:48 +0200 | [diff] [blame] | 38 | static int lsmbus_write_byte(struct device *dev, u8 address, u8 data) |
Aamir Bohra | 52f2974 | 2017-04-19 18:19:14 +0530 | [diff] [blame] | 39 | { |
| 40 | u16 device; |
| 41 | struct resource *res; |
| 42 | struct bus *pbus; |
| 43 | |
| 44 | device = dev->path.i2c.device; |
| 45 | pbus = get_pbus_smbus(dev); |
| 46 | res = find_resource(pbus->dev, PCI_BASE_ADDRESS_4); |
Kyösti Mälkki | 4ae9f1e | 2020-01-01 17:42:45 +0200 | [diff] [blame] | 47 | return do_smbus_write_byte(res->base, device, address, data); |
Aamir Bohra | 52f2974 | 2017-04-19 18:19:14 +0530 | [diff] [blame] | 48 | } |
| 49 | |
| 50 | static struct smbus_bus_operations lops_smbus_bus = { |
| 51 | .read_byte = lsmbus_read_byte, |
| 52 | .write_byte = lsmbus_write_byte, |
| 53 | }; |
| 54 | |
Elyes HAOUAS | 4a13126 | 2018-09-16 17:35:48 +0200 | [diff] [blame] | 55 | static void pch_smbus_init(struct device *dev) |
Aamir Bohra | 52f2974 | 2017-04-19 18:19:14 +0530 | [diff] [blame] | 56 | { |
| 57 | struct resource *res; |
Aamir Bohra | 52f2974 | 2017-04-19 18:19:14 +0530 | [diff] [blame] | 58 | |
| 59 | /* Enable clock gating */ |
Nico Huber | 6278867 | 2017-08-17 16:08:00 +0200 | [diff] [blame] | 60 | pci_update_config32(dev, 0x80, |
| 61 | ~((1 << 8) | (1 << 10) | (1 << 12) | (1 << 14)), 0); |
Aamir Bohra | 52f2974 | 2017-04-19 18:19:14 +0530 | [diff] [blame] | 62 | |
| 63 | /* Set Receive Slave Address */ |
| 64 | res = find_resource(dev, PCI_BASE_ADDRESS_4); |
| 65 | if (res) |
| 66 | outb(SMBUS_SLAVE_ADDR, res->base + SMB_RCV_SLVA); |
| 67 | } |
| 68 | |
Elyes HAOUAS | 4a13126 | 2018-09-16 17:35:48 +0200 | [diff] [blame] | 69 | static void smbus_read_resources(struct device *dev) |
Aamir Bohra | 52f2974 | 2017-04-19 18:19:14 +0530 | [diff] [blame] | 70 | { |
| 71 | struct resource *res = new_resource(dev, PCI_BASE_ADDRESS_4); |
| 72 | res->base = SMBUS_IO_BASE; |
| 73 | res->size = 32; |
| 74 | res->limit = res->base + res->size - 1; |
| 75 | res->flags = IORESOURCE_IO | IORESOURCE_FIXED | IORESOURCE_RESERVE | |
| 76 | IORESOURCE_STORED | IORESOURCE_ASSIGNED; |
| 77 | |
| 78 | /* Also add MMIO resource */ |
| 79 | res = pci_get_resource(dev, PCI_BASE_ADDRESS_0); |
| 80 | } |
| 81 | |
| 82 | static struct device_operations smbus_ops = { |
Elyes HAOUAS | 1d19127 | 2018-11-27 12:23:48 +0100 | [diff] [blame] | 83 | .read_resources = smbus_read_resources, |
| 84 | .set_resources = pci_dev_set_resources, |
| 85 | .enable_resources = pci_dev_enable_resources, |
| 86 | .scan_bus = scan_smbus, |
| 87 | .init = pch_smbus_init, |
Subrata Banik | 6bbc91a | 2017-12-07 14:55:51 +0530 | [diff] [blame] | 88 | .ops_pci = &pci_dev_ops_pci, |
Aamir Bohra | 52f2974 | 2017-04-19 18:19:14 +0530 | [diff] [blame] | 89 | .ops_smbus_bus = &lops_smbus_bus, |
| 90 | }; |
| 91 | |
| 92 | static const unsigned short pci_device_ids[] = { |
Lijian Zhao | bbedef9 | 2017-07-29 16:38:38 -0700 | [diff] [blame] | 93 | PCI_DEVICE_ID_INTEL_CNL_SMBUS, |
Aamir Bohra | 52f2974 | 2017-04-19 18:19:14 +0530 | [diff] [blame] | 94 | PCI_DEVICE_ID_INTEL_SPT_LP_SMBUS, |
| 95 | PCI_DEVICE_ID_INTEL_SPT_H_SMBUS, |
Maxim Polyakov | 571d07d | 2019-08-22 13:11:32 +0300 | [diff] [blame] | 96 | PCI_DEVICE_ID_INTEL_LWB_SMBUS_SUPER, |
Jonathan Zhang | c9ece50 | 2019-11-25 12:41:15 -0800 | [diff] [blame] | 97 | PCI_DEVICE_ID_INTEL_LWB_SMBUS, |
Aamir Bohra | 9eac039 | 2018-06-30 12:07:04 +0530 | [diff] [blame] | 98 | PCI_DEVICE_ID_INTEL_ICP_LP_SMBUS, |
Ronak Kanabar | da7ffb48 | 2019-02-05 01:51:13 +0530 | [diff] [blame] | 99 | PCI_DEVICE_ID_INTEL_CMP_SMBUS, |
Gaggery Tsai | 12a651c | 2019-12-05 11:23:20 -0800 | [diff] [blame] | 100 | PCI_DEVICE_ID_INTEL_CMP_H_SMBUS, |
Ravi Sarawadi | 6b5bf40 | 2019-10-21 22:25:04 -0700 | [diff] [blame] | 101 | PCI_DEVICE_ID_INTEL_TGP_LP_SMBUS, |
rkanabar | 263f129 | 2019-11-28 10:41:45 +0530 | [diff] [blame] | 102 | PCI_DEVICE_ID_INTEL_JSP_PRE_PROD_SMBUS, |
Aamir Bohra | 52f2974 | 2017-04-19 18:19:14 +0530 | [diff] [blame] | 103 | 0 |
| 104 | }; |
| 105 | |
| 106 | static const struct pci_driver pch_smbus __pci_driver = { |
| 107 | .ops = &smbus_ops, |
| 108 | .vendor = PCI_VENDOR_ID_INTEL, |
| 109 | .devices = pci_device_ids, |
| 110 | }; |