Angel Pons | 182dbde | 2020-04-02 23:49:05 +0200 | [diff] [blame^] | 1 | /* SPDX-License-Identifier: GPL-2.0-only */ |
| 2 | /* This file is part of the coreboot project. */ |
Stefan Reinauer | debb11f | 2008-10-29 04:46:52 +0000 | [diff] [blame] | 3 | |
Stefan Reinauer | a8e1168 | 2009-03-11 14:54:18 +0000 | [diff] [blame] | 4 | #include <device/device.h> |
| 5 | #include <device/path.h> |
| 6 | #include <device/smbus.h> |
| 7 | #include <device/pci.h> |
| 8 | #include <device/pci_ids.h> |
Kyösti Mälkki | 1cae454 | 2020-01-06 12:31:34 +0200 | [diff] [blame] | 9 | #include <device/smbus_host.h> |
Stefan Reinauer | debb11f | 2008-10-29 04:46:52 +0000 | [diff] [blame] | 10 | #include "i82801gx.h" |
Stefan Reinauer | 109ab31 | 2009-08-12 16:08:05 +0000 | [diff] [blame] | 11 | |
Elyes HAOUAS | 9966703 | 2018-05-13 12:47:28 +0200 | [diff] [blame] | 12 | static int lsmbus_read_byte(struct device *dev, u8 address) |
Stefan Reinauer | debb11f | 2008-10-29 04:46:52 +0000 | [diff] [blame] | 13 | { |
| 14 | u16 device; |
| 15 | struct resource *res; |
Stefan Reinauer | a8e1168 | 2009-03-11 14:54:18 +0000 | [diff] [blame] | 16 | struct bus *pbus; |
Stefan Reinauer | debb11f | 2008-10-29 04:46:52 +0000 | [diff] [blame] | 17 | |
Stefan Reinauer | 2b34db8 | 2009-02-28 20:10:20 +0000 | [diff] [blame] | 18 | device = dev->path.i2c.device; |
Stefan Reinauer | a8e1168 | 2009-03-11 14:54:18 +0000 | [diff] [blame] | 19 | pbus = get_pbus_smbus(dev); |
| 20 | res = find_resource(pbus->dev, 0x20); |
Stefan Reinauer | debb11f | 2008-10-29 04:46:52 +0000 | [diff] [blame] | 21 | |
| 22 | return do_smbus_read_byte(res->base, device, address); |
| 23 | } |
| 24 | |
Elyes HAOUAS | 9966703 | 2018-05-13 12:47:28 +0200 | [diff] [blame] | 25 | static int lsmbus_write_byte(struct device *dev, u8 address, u8 data) |
Sven Schnelle | 718afbe | 2011-10-23 15:36:15 +0200 | [diff] [blame] | 26 | { |
| 27 | u16 device; |
| 28 | struct resource *res; |
| 29 | struct bus *pbus; |
| 30 | |
| 31 | device = dev->path.i2c.device; |
| 32 | pbus = get_pbus_smbus(dev); |
| 33 | res = find_resource(pbus->dev, 0x20); |
| 34 | return do_smbus_write_byte(res->base, device, address, data); |
| 35 | } |
| 36 | |
Elyes HAOUAS | 9966703 | 2018-05-13 12:47:28 +0200 | [diff] [blame] | 37 | static int lsmbus_block_write(struct device *dev, u8 cmd, u8 bytes, |
| 38 | const u8 *buf) |
Sven Schnelle | 718afbe | 2011-10-23 15:36:15 +0200 | [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, 0x20); |
| 47 | return do_smbus_block_write(res->base, device, cmd, bytes, buf); |
| 48 | } |
| 49 | |
Elyes HAOUAS | 9966703 | 2018-05-13 12:47:28 +0200 | [diff] [blame] | 50 | static int lsmbus_block_read(struct device *dev, u8 cmd, u8 bytes, u8 *buf) |
Sven Schnelle | 718afbe | 2011-10-23 15:36:15 +0200 | [diff] [blame] | 51 | { |
| 52 | u16 device; |
| 53 | struct resource *res; |
| 54 | struct bus *pbus; |
| 55 | |
| 56 | device = dev->path.i2c.device; |
| 57 | pbus = get_pbus_smbus(dev); |
| 58 | res = find_resource(pbus->dev, 0x20); |
| 59 | return do_smbus_block_read(res->base, device, cmd, bytes, buf); |
| 60 | } |
| 61 | |
| 62 | |
Stefan Reinauer | debb11f | 2008-10-29 04:46:52 +0000 | [diff] [blame] | 63 | static struct smbus_bus_operations lops_smbus_bus = { |
Stefan Reinauer | a8e1168 | 2009-03-11 14:54:18 +0000 | [diff] [blame] | 64 | .read_byte = lsmbus_read_byte, |
Sven Schnelle | 718afbe | 2011-10-23 15:36:15 +0200 | [diff] [blame] | 65 | .write_byte = lsmbus_write_byte, |
| 66 | .block_read = lsmbus_block_read, |
| 67 | .block_write = lsmbus_block_write, |
Stefan Reinauer | a8e1168 | 2009-03-11 14:54:18 +0000 | [diff] [blame] | 68 | }; |
| 69 | |
Stefan Reinauer | a8e1168 | 2009-03-11 14:54:18 +0000 | [diff] [blame] | 70 | static struct pci_operations smbus_pci_ops = { |
Subrata Banik | 4a0f071 | 2019-03-20 14:29:47 +0530 | [diff] [blame] | 71 | .set_subsystem = pci_dev_set_subsystem, |
Stefan Reinauer | debb11f | 2008-10-29 04:46:52 +0000 | [diff] [blame] | 72 | }; |
| 73 | |
Elyes HAOUAS | 9966703 | 2018-05-13 12:47:28 +0200 | [diff] [blame] | 74 | static void smbus_read_resources(struct device *dev) |
Sven Schnelle | 3c97679 | 2011-10-23 15:30:29 +0200 | [diff] [blame] | 75 | { |
| 76 | struct resource *res = new_resource(dev, PCI_BASE_ADDRESS_4); |
| 77 | res->base = SMBUS_IO_BASE; |
| 78 | res->size = 32; |
| 79 | res->limit = res->base + res->size - 1; |
| 80 | res->flags = IORESOURCE_IO | IORESOURCE_FIXED | IORESOURCE_RESERVE | |
| 81 | IORESOURCE_STORED | IORESOURCE_ASSIGNED; |
| 82 | } |
| 83 | |
Stefan Reinauer | debb11f | 2008-10-29 04:46:52 +0000 | [diff] [blame] | 84 | static struct device_operations smbus_ops = { |
Sven Schnelle | 3c97679 | 2011-10-23 15:30:29 +0200 | [diff] [blame] | 85 | .read_resources = smbus_read_resources, |
Stefan Reinauer | debb11f | 2008-10-29 04:46:52 +0000 | [diff] [blame] | 86 | .set_resources = pci_dev_set_resources, |
| 87 | .enable_resources = pci_dev_enable_resources, |
Kyösti Mälkki | d0e212c | 2015-02-26 20:47:47 +0200 | [diff] [blame] | 88 | .scan_bus = scan_smbus, |
Stefan Reinauer | debb11f | 2008-10-29 04:46:52 +0000 | [diff] [blame] | 89 | .enable = i82801gx_enable, |
| 90 | .ops_smbus_bus = &lops_smbus_bus, |
Stefan Reinauer | a8e1168 | 2009-03-11 14:54:18 +0000 | [diff] [blame] | 91 | .ops_pci = &smbus_pci_ops, |
Stefan Reinauer | debb11f | 2008-10-29 04:46:52 +0000 | [diff] [blame] | 92 | }; |
| 93 | |
| 94 | /* 82801GB/GR/GDH/GBM/GHM/GU (ICH7/ICH7R/ICH7DH/ICH7-M/ICH7-M DH/ICH7-U) */ |
| 95 | static const struct pci_driver i82801gx_smbus __pci_driver = { |
| 96 | .ops = &smbus_ops, |
| 97 | .vendor = PCI_VENDOR_ID_INTEL, |
Uwe Hermann | 5d7a1c8 | 2008-10-31 18:41:09 +0000 | [diff] [blame] | 98 | .device = 0x27da, |
Stefan Reinauer | debb11f | 2008-10-29 04:46:52 +0000 | [diff] [blame] | 99 | }; |