Vladimir Serbinenko | 888d559 | 2013-11-13 17:53:38 +0100 | [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. |
Vladimir Serbinenko | 888d559 | 2013-11-13 17:53:38 +0100 | [diff] [blame] | 15 | */ |
| 16 | |
Vladimir Serbinenko | 888d559 | 2013-11-13 17:53:38 +0100 | [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> |
Vladimir Serbinenko | 888d559 | 2013-11-13 17:53:38 +0100 | [diff] [blame] | 25 | #include "pch.h" |
Vladimir Serbinenko | 888d559 | 2013-11-13 17:53:38 +0100 | [diff] [blame] | 26 | |
Elyes HAOUAS | be84140 | 2018-05-13 13:40:39 +0200 | [diff] [blame] | 27 | static void pch_smbus_init(struct device *dev) |
Vladimir Serbinenko | 888d559 | 2013-11-13 17:53:38 +0100 | [diff] [blame] | 28 | { |
| 29 | struct resource *res; |
| 30 | u16 reg16; |
| 31 | |
| 32 | /* Enable clock gating */ |
| 33 | reg16 = pci_read_config32(dev, 0x80); |
| 34 | reg16 &= ~((1 << 8)|(1 << 10)|(1 << 12)|(1 << 14)); |
| 35 | pci_write_config32(dev, 0x80, reg16); |
| 36 | |
| 37 | /* Set Receive Slave Address */ |
| 38 | res = find_resource(dev, PCI_BASE_ADDRESS_4); |
| 39 | if (res) |
| 40 | outb(SMBUS_SLAVE_ADDR, res->base + SMB_RCV_SLVA); |
| 41 | } |
| 42 | |
Elyes HAOUAS | be84140 | 2018-05-13 13:40:39 +0200 | [diff] [blame] | 43 | static int lsmbus_read_byte(struct device *dev, u8 address) |
Vladimir Serbinenko | 888d559 | 2013-11-13 17:53:38 +0100 | [diff] [blame] | 44 | { |
| 45 | u16 device; |
| 46 | struct resource *res; |
| 47 | struct bus *pbus; |
| 48 | |
| 49 | device = dev->path.i2c.device; |
| 50 | pbus = get_pbus_smbus(dev); |
| 51 | res = find_resource(pbus->dev, 0x20); |
| 52 | |
| 53 | return do_smbus_read_byte(res->base, device, address); |
| 54 | } |
| 55 | |
Elyes HAOUAS | be84140 | 2018-05-13 13:40:39 +0200 | [diff] [blame] | 56 | static int lsmbus_write_byte(struct device *dev, u8 address, u8 val) |
Vladimir Serbinenko | 5f20dbf | 2014-01-27 23:57:44 +0100 | [diff] [blame] | 57 | { |
| 58 | u16 device; |
| 59 | struct resource *res; |
| 60 | struct bus *pbus; |
| 61 | |
| 62 | device = dev->path.i2c.device; |
| 63 | pbus = get_pbus_smbus(dev); |
| 64 | res = find_resource(pbus->dev, 0x20); |
| 65 | |
| 66 | return do_smbus_write_byte(res->base, device, address, val); |
| 67 | } |
| 68 | |
Vladimir Serbinenko | 888d559 | 2013-11-13 17:53:38 +0100 | [diff] [blame] | 69 | static struct smbus_bus_operations lops_smbus_bus = { |
| 70 | .read_byte = lsmbus_read_byte, |
Vladimir Serbinenko | 5f20dbf | 2014-01-27 23:57:44 +0100 | [diff] [blame] | 71 | .write_byte = lsmbus_write_byte, |
Vladimir Serbinenko | 888d559 | 2013-11-13 17:53:38 +0100 | [diff] [blame] | 72 | }; |
| 73 | |
Vladimir Serbinenko | 888d559 | 2013-11-13 17:53:38 +0100 | [diff] [blame] | 74 | static struct pci_operations smbus_pci_ops = { |
Subrata Banik | 4a0f071 | 2019-03-20 14:29:47 +0530 | [diff] [blame] | 75 | .set_subsystem = pci_dev_set_subsystem, |
Vladimir Serbinenko | 888d559 | 2013-11-13 17:53:38 +0100 | [diff] [blame] | 76 | }; |
| 77 | |
Elyes HAOUAS | be84140 | 2018-05-13 13:40:39 +0200 | [diff] [blame] | 78 | static void smbus_read_resources(struct device *dev) |
Vladimir Serbinenko | 888d559 | 2013-11-13 17:53:38 +0100 | [diff] [blame] | 79 | { |
| 80 | struct resource *res = new_resource(dev, PCI_BASE_ADDRESS_4); |
| 81 | res->base = SMBUS_IO_BASE; |
| 82 | res->size = 32; |
| 83 | res->limit = res->base + res->size - 1; |
| 84 | res->flags = IORESOURCE_IO | IORESOURCE_FIXED | IORESOURCE_RESERVE | |
| 85 | IORESOURCE_STORED | IORESOURCE_ASSIGNED; |
| 86 | |
| 87 | /* Also add MMIO resource */ |
| 88 | res = pci_get_resource(dev, PCI_BASE_ADDRESS_0); |
| 89 | } |
| 90 | |
| 91 | static struct device_operations smbus_ops = { |
| 92 | .read_resources = smbus_read_resources, |
| 93 | .set_resources = pci_dev_set_resources, |
| 94 | .enable_resources = pci_dev_enable_resources, |
Kyösti Mälkki | d0e212c | 2015-02-26 20:47:47 +0200 | [diff] [blame] | 95 | .scan_bus = scan_smbus, |
Vladimir Serbinenko | 888d559 | 2013-11-13 17:53:38 +0100 | [diff] [blame] | 96 | .init = pch_smbus_init, |
| 97 | .ops_smbus_bus = &lops_smbus_bus, |
| 98 | .ops_pci = &smbus_pci_ops, |
| 99 | }; |
| 100 | |
| 101 | static const unsigned short pci_device_ids[] = { 0x1c22, 0x1e22, 0x3b30, 0 }; |
| 102 | |
| 103 | static const struct pci_driver pch_smbus __pci_driver = { |
| 104 | .ops = &smbus_ops, |
| 105 | .vendor = PCI_VENDOR_ID_INTEL, |
| 106 | .devices = pci_device_ids, |
| 107 | }; |