Angel Pons | 182dbde | 2020-04-02 23:49:05 +0200 | [diff] [blame] | 1 | /* SPDX-License-Identifier: GPL-2.0-only */ |
Patrick Georgi | e72a8a3 | 2012-11-06 11:05:09 +0100 | [diff] [blame] | 2 | |
Kyösti Mälkki | f1b58b7 | 2019-03-01 13:43:02 +0200 | [diff] [blame] | 3 | #include <device/pci_ops.h> |
Patrick Georgi | e72a8a3 | 2012-11-06 11:05:09 +0100 | [diff] [blame] | 4 | #include <device/pci_def.h> |
Felix Singer | 7f8b0cd8 | 2019-11-10 11:04:08 +0100 | [diff] [blame] | 5 | #include <device/pci_ids.h> |
Kyösti Mälkki | 1cae454 | 2020-01-06 12:31:34 +0200 | [diff] [blame] | 6 | #include <device/smbus_host.h> |
Patrick Georgi | e72a8a3 | 2012-11-06 11:05:09 +0100 | [diff] [blame] | 7 | #include "i82801ix.h" |
Patrick Georgi | e72a8a3 | 2012-11-06 11:05:09 +0100 | [diff] [blame] | 8 | |
Kyösti Mälkki | f555a58 | 2020-01-06 19:41:42 +0200 | [diff] [blame] | 9 | uintptr_t smbus_base(void) |
Patrick Georgi | e72a8a3 | 2012-11-06 11:05:09 +0100 | [diff] [blame] | 10 | { |
Kyösti Mälkki | f555a58 | 2020-01-06 19:41:42 +0200 | [diff] [blame] | 11 | return SMBUS_IO_BASE; |
| 12 | } |
Patrick Georgi | e72a8a3 | 2012-11-06 11:05:09 +0100 | [diff] [blame] | 13 | |
Kyösti Mälkki | f555a58 | 2020-01-06 19:41:42 +0200 | [diff] [blame] | 14 | int smbus_enable_iobar(uintptr_t base) |
| 15 | { |
Patrick Georgi | e72a8a3 | 2012-11-06 11:05:09 +0100 | [diff] [blame] | 16 | /* Set the SMBus device statically. */ |
Kyösti Mälkki | f555a58 | 2020-01-06 19:41:42 +0200 | [diff] [blame] | 17 | pci_devfn_t dev = PCI_DEV(0x0, 0x1f, 0x3); |
Patrick Georgi | e72a8a3 | 2012-11-06 11:05:09 +0100 | [diff] [blame] | 18 | |
| 19 | /* Check to make sure we've got the right device. */ |
Felix Singer | 7f8b0cd8 | 2019-11-10 11:04:08 +0100 | [diff] [blame] | 20 | if (pci_read_config16(dev, 0x2) != PCI_DEVICE_ID_INTEL_82801IB_SMB) |
Kyösti Mälkki | f555a58 | 2020-01-06 19:41:42 +0200 | [diff] [blame] | 21 | return -1; |
Patrick Georgi | e72a8a3 | 2012-11-06 11:05:09 +0100 | [diff] [blame] | 22 | |
| 23 | /* Set SMBus I/O base. */ |
| 24 | pci_write_config32(dev, SMB_BASE, |
Kyösti Mälkki | f555a58 | 2020-01-06 19:41:42 +0200 | [diff] [blame] | 25 | base | PCI_BASE_ADDRESS_SPACE_IO); |
Patrick Georgi | e72a8a3 | 2012-11-06 11:05:09 +0100 | [diff] [blame] | 26 | |
| 27 | /* Set SMBus enable. */ |
| 28 | pci_write_config8(dev, HOSTC, HST_EN); |
| 29 | |
| 30 | /* Set SMBus I/O space enable. */ |
| 31 | pci_write_config16(dev, PCI_COMMAND, PCI_COMMAND_IO); |
| 32 | |
Kyösti Mälkki | f555a58 | 2020-01-06 19:41:42 +0200 | [diff] [blame] | 33 | return 0; |
Patrick Georgi | e72a8a3 | 2012-11-06 11:05:09 +0100 | [diff] [blame] | 34 | } |
| 35 | |
Martin Roth | ff744bf | 2019-10-23 21:46:03 -0600 | [diff] [blame] | 36 | int smbus_read_byte(unsigned int device, unsigned int address) |
Patrick Georgi | e72a8a3 | 2012-11-06 11:05:09 +0100 | [diff] [blame] | 37 | { |
| 38 | return do_smbus_read_byte(SMBUS_IO_BASE, device, address); |
| 39 | } |