Aaron Durbin | 76c3700 | 2012-10-30 09:03:43 -0500 | [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. |
Aaron Durbin | 76c3700 | 2012-10-30 09:03:43 -0500 | [diff] [blame] | 15 | */ |
| 16 | |
Aaron Durbin | 76c3700 | 2012-10-30 09:03:43 -0500 | [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> |
Kyösti Mälkki | 1cae454 | 2020-01-06 12:31:34 +0200 | [diff] [blame] | 23 | #include <device/smbus_host.h> |
Aaron Durbin | 76c3700 | 2012-10-30 09:03:43 -0500 | [diff] [blame] | 24 | #include "pch.h" |
Aaron Durbin | 76c3700 | 2012-10-30 09:03:43 -0500 | [diff] [blame] | 25 | |
Elyes HAOUAS | 38f1d13 | 2018-09-17 08:44:18 +0200 | [diff] [blame] | 26 | static void pch_smbus_init(struct device *dev) |
Aaron Durbin | 76c3700 | 2012-10-30 09:03:43 -0500 | [diff] [blame] | 27 | { |
| 28 | struct resource *res; |
| 29 | u16 reg16; |
| 30 | |
| 31 | /* Enable clock gating */ |
| 32 | reg16 = pci_read_config32(dev, 0x80); |
| 33 | reg16 &= ~((1 << 8)|(1 << 10)|(1 << 12)|(1 << 14)); |
| 34 | pci_write_config32(dev, 0x80, reg16); |
| 35 | |
| 36 | /* Set Receive Slave Address */ |
| 37 | res = find_resource(dev, PCI_BASE_ADDRESS_4); |
| 38 | if (res) |
Kyösti Mälkki | 73451fd | 2020-01-06 19:00:31 +0200 | [diff] [blame^] | 39 | smbus_set_slave_addr(res->base, SMBUS_SLAVE_ADDR); |
Aaron Durbin | 76c3700 | 2012-10-30 09:03:43 -0500 | [diff] [blame] | 40 | } |
| 41 | |
Elyes HAOUAS | 38f1d13 | 2018-09-17 08:44:18 +0200 | [diff] [blame] | 42 | static int lsmbus_read_byte(struct device *dev, u8 address) |
Aaron Durbin | 76c3700 | 2012-10-30 09:03:43 -0500 | [diff] [blame] | 43 | { |
| 44 | u16 device; |
| 45 | struct resource *res; |
| 46 | struct bus *pbus; |
| 47 | |
| 48 | device = dev->path.i2c.device; |
| 49 | pbus = get_pbus_smbus(dev); |
Duncan Laurie | 8870733 | 2013-07-15 09:07:20 -0700 | [diff] [blame] | 50 | res = find_resource(pbus->dev, PCI_BASE_ADDRESS_4); |
Aaron Durbin | 76c3700 | 2012-10-30 09:03:43 -0500 | [diff] [blame] | 51 | |
| 52 | return do_smbus_read_byte(res->base, device, address); |
| 53 | } |
| 54 | |
Elyes HAOUAS | 38f1d13 | 2018-09-17 08:44:18 +0200 | [diff] [blame] | 55 | static int lsmbus_write_byte(struct device *dev, u8 address, u8 data) |
Duncan Laurie | 8870733 | 2013-07-15 09:07:20 -0700 | [diff] [blame] | 56 | { |
| 57 | u16 device; |
| 58 | struct resource *res; |
| 59 | struct bus *pbus; |
| 60 | |
| 61 | device = dev->path.i2c.device; |
| 62 | pbus = get_pbus_smbus(dev); |
| 63 | res = find_resource(pbus->dev, PCI_BASE_ADDRESS_4); |
| 64 | return do_smbus_write_byte(res->base, device, address, data); |
| 65 | } |
| 66 | |
Aaron Durbin | 76c3700 | 2012-10-30 09:03:43 -0500 | [diff] [blame] | 67 | static struct smbus_bus_operations lops_smbus_bus = { |
| 68 | .read_byte = lsmbus_read_byte, |
Duncan Laurie | 8870733 | 2013-07-15 09:07:20 -0700 | [diff] [blame] | 69 | .write_byte = lsmbus_write_byte, |
Aaron Durbin | 76c3700 | 2012-10-30 09:03:43 -0500 | [diff] [blame] | 70 | }; |
| 71 | |
Aaron Durbin | 76c3700 | 2012-10-30 09:03:43 -0500 | [diff] [blame] | 72 | static struct pci_operations smbus_pci_ops = { |
Subrata Banik | 4a0f071 | 2019-03-20 14:29:47 +0530 | [diff] [blame] | 73 | .set_subsystem = pci_dev_set_subsystem, |
Aaron Durbin | 76c3700 | 2012-10-30 09:03:43 -0500 | [diff] [blame] | 74 | }; |
| 75 | |
Elyes HAOUAS | 38f1d13 | 2018-09-17 08:44:18 +0200 | [diff] [blame] | 76 | static void smbus_read_resources(struct device *dev) |
Aaron Durbin | 76c3700 | 2012-10-30 09:03:43 -0500 | [diff] [blame] | 77 | { |
| 78 | struct resource *res = new_resource(dev, PCI_BASE_ADDRESS_4); |
| 79 | res->base = SMBUS_IO_BASE; |
| 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, |
Aaron Durbin | 76c3700 | 2012-10-30 09:03:43 -0500 | [diff] [blame] | 94 | .init = pch_smbus_init, |
| 95 | .ops_smbus_bus = &lops_smbus_bus, |
| 96 | .ops_pci = &smbus_pci_ops, |
| 97 | }; |
| 98 | |
Tristan Corrick | 946d3f9 | 2018-10-31 02:21:07 +1300 | [diff] [blame] | 99 | static const unsigned short pci_device_ids[] = { |
| 100 | 0x1c22, 0x1e22, 0x8c22, 0x9c22, |
| 101 | 0 |
| 102 | }; |
Aaron Durbin | 76c3700 | 2012-10-30 09:03:43 -0500 | [diff] [blame] | 103 | |
| 104 | static const struct pci_driver pch_smbus __pci_driver = { |
| 105 | .ops = &smbus_ops, |
| 106 | .vendor = PCI_VENDOR_ID_INTEL, |
| 107 | .devices = pci_device_ids, |
| 108 | }; |