Duncan Laurie | c88c54c | 2014-04-30 16:36:13 -0700 | [diff] [blame] | 1 | /* |
| 2 | * This file is part of the coreboot project. |
| 3 | * |
| 4 | * Copyright (C) 2008-2009 coresystems GmbH |
| 5 | * Copyright (C) 2014 Google Inc. |
| 6 | * |
| 7 | * This program is free software; you can redistribute it and/or modify |
| 8 | * it under the terms of the GNU General Public License as published by |
| 9 | * the Free Software Foundation; version 2 of 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. |
Duncan Laurie | c88c54c | 2014-04-30 16:36:13 -0700 | [diff] [blame] | 15 | */ |
| 16 | |
| 17 | #include <arch/io.h> |
| 18 | #include <console/console.h> |
| 19 | #include <device/device.h> |
| 20 | #include <device/path.h> |
| 21 | #include <device/smbus.h> |
| 22 | #include <device/smbus_def.h> |
| 23 | #include <device/pci.h> |
| 24 | #include <device/pci_ids.h> |
| 25 | #include <device/pci_ops.h> |
Julius Werner | 4ee4bd5 | 2014-10-20 13:46:39 -0700 | [diff] [blame] | 26 | #include <soc/iomap.h> |
| 27 | #include <soc/ramstage.h> |
| 28 | #include <soc/smbus.h> |
Duncan Laurie | c88c54c | 2014-04-30 16:36:13 -0700 | [diff] [blame] | 29 | |
| 30 | static void pch_smbus_init(device_t dev) |
| 31 | { |
| 32 | struct resource *res; |
| 33 | u16 reg16; |
| 34 | |
| 35 | /* Enable clock gating */ |
| 36 | reg16 = pci_read_config32(dev, 0x80); |
| 37 | reg16 &= ~((1 << 8)|(1 << 10)|(1 << 12)|(1 << 14)); |
| 38 | pci_write_config32(dev, 0x80, reg16); |
| 39 | |
| 40 | /* Set Receive Slave Address */ |
| 41 | res = find_resource(dev, PCI_BASE_ADDRESS_4); |
| 42 | if (res) |
| 43 | outb(SMBUS_SLAVE_ADDR, res->base + SMB_RCV_SLVA); |
| 44 | } |
| 45 | |
| 46 | static int lsmbus_read_byte(device_t dev, u8 address) |
| 47 | { |
| 48 | u16 device; |
| 49 | struct resource *res; |
| 50 | struct bus *pbus; |
| 51 | |
| 52 | device = dev->path.i2c.device; |
| 53 | pbus = get_pbus_smbus(dev); |
| 54 | res = find_resource(pbus->dev, PCI_BASE_ADDRESS_4); |
| 55 | |
| 56 | return do_smbus_read_byte(res->base, device, address); |
| 57 | } |
| 58 | |
| 59 | static int lsmbus_write_byte(device_t dev, u8 address, u8 data) |
| 60 | { |
| 61 | u16 device; |
| 62 | struct resource *res; |
| 63 | struct bus *pbus; |
| 64 | |
| 65 | device = dev->path.i2c.device; |
| 66 | pbus = get_pbus_smbus(dev); |
| 67 | res = find_resource(pbus->dev, PCI_BASE_ADDRESS_4); |
| 68 | return do_smbus_write_byte(res->base, device, address, data); |
| 69 | } |
| 70 | |
| 71 | static struct smbus_bus_operations lops_smbus_bus = { |
| 72 | .read_byte = lsmbus_read_byte, |
| 73 | .write_byte = lsmbus_write_byte, |
| 74 | }; |
| 75 | |
| 76 | static void smbus_read_resources(device_t dev) |
| 77 | { |
| 78 | struct resource *res = new_resource(dev, PCI_BASE_ADDRESS_4); |
| 79 | res->base = SMBUS_BASE_ADDRESS; |
| 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 | |
| 89 | static struct device_operations smbus_ops = { |
| 90 | .read_resources = &smbus_read_resources, |
| 91 | .set_resources = &pci_dev_set_resources, |
| 92 | .enable_resources = &pci_dev_enable_resources, |
Kyösti Mälkki | d0e212c | 2015-02-26 20:47:47 +0200 | [diff] [blame] | 93 | .scan_bus = &scan_smbus, |
Duncan Laurie | c88c54c | 2014-04-30 16:36:13 -0700 | [diff] [blame] | 94 | .init = &pch_smbus_init, |
| 95 | .ops_smbus_bus = &lops_smbus_bus, |
| 96 | .ops_pci = &broadwell_pci_ops, |
| 97 | }; |
| 98 | |
| 99 | static const unsigned short pci_device_ids[] = { |
| 100 | 0x9c22, /* LynxPoint */ |
| 101 | 0x9ca2, /* WildcatPoint */ |
| 102 | 0 |
| 103 | }; |
| 104 | |
| 105 | static const struct pci_driver pch_smbus __pci_driver = { |
| 106 | .ops = &smbus_ops, |
| 107 | .vendor = PCI_VENDOR_ID_INTEL, |
| 108 | .devices = pci_device_ids, |
| 109 | }; |