Arthur Heymans | 7b9c139 | 2017-04-09 20:40:39 +0200 | [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. |
| 15 | */ |
| 16 | |
Arthur Heymans | 7b9c139 | 2017-04-09 20:40:39 +0200 | [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> |
Arthur Heymans | 16fe790 | 2017-04-12 17:01:31 +0200 | [diff] [blame] | 23 | #include <southbridge/intel/common/smbus.h> |
| 24 | #include "i82801jx.h" |
Arthur Heymans | 7b9c139 | 2017-04-09 20:40:39 +0200 | [diff] [blame] | 25 | |
Elyes HAOUAS | 1a8c1df | 2018-05-13 13:36:44 +0200 | [diff] [blame] | 26 | static void pch_smbus_init(struct device *dev) |
Arthur Heymans | 7b9c139 | 2017-04-09 20:40:39 +0200 | [diff] [blame] | 27 | { |
| 28 | u16 reg16; |
| 29 | |
| 30 | /* Enable clock gating */ |
| 31 | reg16 = pci_read_config16(dev, 0x80); |
| 32 | reg16 &= ~((1 << 8)|(1 << 10)|(1 << 12)|(1 << 14)); |
| 33 | pci_write_config16(dev, 0x80, reg16); |
| 34 | } |
| 35 | |
Elyes HAOUAS | 1a8c1df | 2018-05-13 13:36:44 +0200 | [diff] [blame] | 36 | static int lsmbus_read_byte(struct device *dev, u8 address) |
Arthur Heymans | 7b9c139 | 2017-04-09 20:40:39 +0200 | [diff] [blame] | 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, 0x20); |
| 45 | |
| 46 | return do_smbus_read_byte(res->base, device, address); |
| 47 | } |
| 48 | |
Elyes HAOUAS | 1a8c1df | 2018-05-13 13:36:44 +0200 | [diff] [blame] | 49 | static int lsmbus_write_byte(struct device *dev, u8 address, u8 val) |
Arthur Heymans | 7b9c139 | 2017-04-09 20:40:39 +0200 | [diff] [blame] | 50 | { |
| 51 | u16 device; |
| 52 | struct resource *res; |
| 53 | struct bus *pbus; |
| 54 | |
| 55 | device = dev->path.i2c.device; |
| 56 | pbus = get_pbus_smbus(dev); |
| 57 | res = find_resource(pbus->dev, 0x20); |
| 58 | |
| 59 | return do_smbus_write_byte(res->base, device, address, val); |
| 60 | } |
| 61 | |
Elyes HAOUAS | 1a8c1df | 2018-05-13 13:36:44 +0200 | [diff] [blame] | 62 | static int lsmbus_block_write(struct device *dev, u8 cmd, u8 bytes, |
| 63 | const u8 *buf) |
Arthur Heymans | 33863b6 | 2017-09-07 17:05:17 +0200 | [diff] [blame] | 64 | { |
| 65 | u16 device; |
| 66 | struct resource *res; |
| 67 | struct bus *pbus; |
| 68 | |
| 69 | device = dev->path.i2c.device; |
| 70 | pbus = get_pbus_smbus(dev); |
| 71 | res = find_resource(pbus->dev, 0x20); |
| 72 | return do_smbus_block_write(res->base, device, cmd, bytes, buf); |
| 73 | } |
| 74 | |
Elyes HAOUAS | 1a8c1df | 2018-05-13 13:36:44 +0200 | [diff] [blame] | 75 | static int lsmbus_block_read(struct device *dev, u8 cmd, u8 bytes, u8 *buf) |
Arthur Heymans | 33863b6 | 2017-09-07 17:05:17 +0200 | [diff] [blame] | 76 | { |
| 77 | u16 device; |
| 78 | struct resource *res; |
| 79 | struct bus *pbus; |
| 80 | |
| 81 | device = dev->path.i2c.device; |
| 82 | pbus = get_pbus_smbus(dev); |
| 83 | res = find_resource(pbus->dev, 0x20); |
| 84 | return do_smbus_block_read(res->base, device, cmd, bytes, buf); |
| 85 | } |
| 86 | |
Arthur Heymans | 7b9c139 | 2017-04-09 20:40:39 +0200 | [diff] [blame] | 87 | static struct smbus_bus_operations lops_smbus_bus = { |
| 88 | .read_byte = lsmbus_read_byte, |
| 89 | .write_byte = lsmbus_write_byte, |
Arthur Heymans | 33863b6 | 2017-09-07 17:05:17 +0200 | [diff] [blame] | 90 | .block_read = lsmbus_block_read, |
| 91 | .block_write = lsmbus_block_write, |
Arthur Heymans | 7b9c139 | 2017-04-09 20:40:39 +0200 | [diff] [blame] | 92 | }; |
| 93 | |
Arthur Heymans | 7b9c139 | 2017-04-09 20:40:39 +0200 | [diff] [blame] | 94 | static struct pci_operations smbus_pci_ops = { |
Subrata Banik | 4a0f071 | 2019-03-20 14:29:47 +0530 | [diff] [blame^] | 95 | .set_subsystem = pci_dev_set_subsystem, |
Arthur Heymans | 7b9c139 | 2017-04-09 20:40:39 +0200 | [diff] [blame] | 96 | }; |
| 97 | |
Elyes HAOUAS | 1a8c1df | 2018-05-13 13:36:44 +0200 | [diff] [blame] | 98 | static void smbus_read_resources(struct device *dev) |
Arthur Heymans | 7b9c139 | 2017-04-09 20:40:39 +0200 | [diff] [blame] | 99 | { |
| 100 | struct resource *res = new_resource(dev, PCI_BASE_ADDRESS_4); |
| 101 | res->base = SMBUS_IO_BASE; |
| 102 | res->size = 32; |
| 103 | res->limit = res->base + res->size - 1; |
| 104 | res->flags = IORESOURCE_IO | IORESOURCE_FIXED | IORESOURCE_RESERVE | |
| 105 | IORESOURCE_STORED | IORESOURCE_ASSIGNED; |
| 106 | |
| 107 | /* Also add MMIO resource */ |
| 108 | res = pci_get_resource(dev, PCI_BASE_ADDRESS_0); |
| 109 | } |
| 110 | |
| 111 | static struct device_operations smbus_ops = { |
| 112 | .read_resources = smbus_read_resources, |
| 113 | .set_resources = pci_dev_set_resources, |
| 114 | .enable_resources = pci_dev_enable_resources, |
| 115 | .scan_bus = scan_smbus, |
| 116 | .init = pch_smbus_init, |
| 117 | .ops_smbus_bus = &lops_smbus_bus, |
| 118 | .ops_pci = &smbus_pci_ops, |
| 119 | }; |
| 120 | |
Arthur Heymans | 349e085 | 2017-04-09 20:48:37 +0200 | [diff] [blame] | 121 | static const unsigned short pci_device_ids[] = |
| 122 | { |
| 123 | 0x3a30, |
| 124 | 0x3a60, |
| 125 | 0 |
| 126 | }; |
Arthur Heymans | 7b9c139 | 2017-04-09 20:40:39 +0200 | [diff] [blame] | 127 | |
| 128 | static const struct pci_driver pch_smbus __pci_driver = { |
| 129 | .ops = &smbus_ops, |
| 130 | .vendor = PCI_VENDOR_ID_INTEL, |
| 131 | .devices = pci_device_ids, |
| 132 | }; |