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. */ |
Vladimir Serbinenko | 888d559 | 2013-11-13 17:53:38 +0100 | [diff] [blame] | 3 | |
Elyes HAOUAS | 25d20d3 | 2020-04-06 09:12:50 +0200 | [diff] [blame^] | 4 | #include <device/pci_ids.h> |
Kyösti Mälkki | f1b58b7 | 2019-03-01 13:43:02 +0200 | [diff] [blame] | 5 | #include <device/pci_ops.h> |
Vladimir Serbinenko | 888d559 | 2013-11-13 17:53:38 +0100 | [diff] [blame] | 6 | #include <device/pci_def.h> |
Kyösti Mälkki | 1cae454 | 2020-01-06 12:31:34 +0200 | [diff] [blame] | 7 | #include <device/smbus_host.h> |
Vladimir Serbinenko | 888d559 | 2013-11-13 17:53:38 +0100 | [diff] [blame] | 8 | #include "pch.h" |
Vladimir Serbinenko | 888d559 | 2013-11-13 17:53:38 +0100 | [diff] [blame] | 9 | |
Kyösti Mälkki | f555a58 | 2020-01-06 19:41:42 +0200 | [diff] [blame] | 10 | uintptr_t smbus_base(void) |
Vladimir Serbinenko | 888d559 | 2013-11-13 17:53:38 +0100 | [diff] [blame] | 11 | { |
Kyösti Mälkki | f555a58 | 2020-01-06 19:41:42 +0200 | [diff] [blame] | 12 | return SMBUS_IO_BASE; |
| 13 | } |
Vladimir Serbinenko | 888d559 | 2013-11-13 17:53:38 +0100 | [diff] [blame] | 14 | |
Kyösti Mälkki | f555a58 | 2020-01-06 19:41:42 +0200 | [diff] [blame] | 15 | int smbus_enable_iobar(uintptr_t base) |
| 16 | { |
Vladimir Serbinenko | 888d559 | 2013-11-13 17:53:38 +0100 | [diff] [blame] | 17 | /* Set the SMBus device statically. */ |
Kyösti Mälkki | f555a58 | 2020-01-06 19:41:42 +0200 | [diff] [blame] | 18 | pci_devfn_t dev = PCI_DEV(0x0, 0x1f, 0x3); |
Vladimir Serbinenko | 888d559 | 2013-11-13 17:53:38 +0100 | [diff] [blame] | 19 | |
| 20 | /* Check to make sure we've got the right device. */ |
Elyes HAOUAS | 25d20d3 | 2020-04-06 09:12:50 +0200 | [diff] [blame^] | 21 | if (pci_read_config16(dev, PCI_VENDOR_ID) != PCI_VENDOR_ID_INTEL) |
Kyösti Mälkki | f555a58 | 2020-01-06 19:41:42 +0200 | [diff] [blame] | 22 | return -1; |
Vladimir Serbinenko | 888d559 | 2013-11-13 17:53:38 +0100 | [diff] [blame] | 23 | |
| 24 | /* Set SMBus I/O base. */ |
| 25 | pci_write_config32(dev, SMB_BASE, |
Kyösti Mälkki | f555a58 | 2020-01-06 19:41:42 +0200 | [diff] [blame] | 26 | base | PCI_BASE_ADDRESS_SPACE_IO); |
Vladimir Serbinenko | 888d559 | 2013-11-13 17:53:38 +0100 | [diff] [blame] | 27 | |
| 28 | /* Set SMBus enable. */ |
| 29 | pci_write_config8(dev, HOSTC, HST_EN); |
| 30 | |
| 31 | /* Set SMBus I/O space enable. */ |
| 32 | pci_write_config16(dev, PCI_COMMAND, PCI_COMMAND_IO); |
| 33 | |
Kyösti Mälkki | f555a58 | 2020-01-06 19:41:42 +0200 | [diff] [blame] | 34 | return 0; |
Vladimir Serbinenko | 888d559 | 2013-11-13 17:53:38 +0100 | [diff] [blame] | 35 | } |
| 36 | |
Martin Roth | ff744bf | 2019-10-23 21:46:03 -0600 | [diff] [blame] | 37 | int smbus_read_byte(unsigned int device, unsigned int address) |
Vladimir Serbinenko | 888d559 | 2013-11-13 17:53:38 +0100 | [diff] [blame] | 38 | { |
| 39 | return do_smbus_read_byte(SMBUS_IO_BASE, device, address); |
| 40 | } |
| 41 | |
Martin Roth | ff744bf | 2019-10-23 21:46:03 -0600 | [diff] [blame] | 42 | int smbus_write_byte(unsigned int device, unsigned int address, u8 data) |
Vladimir Serbinenko | 888d559 | 2013-11-13 17:53:38 +0100 | [diff] [blame] | 43 | { |
| 44 | return do_smbus_write_byte(SMBUS_IO_BASE, device, address, data); |
| 45 | } |
| 46 | |
Martin Roth | ff744bf | 2019-10-23 21:46:03 -0600 | [diff] [blame] | 47 | int smbus_block_read(unsigned int device, unsigned int cmd, u8 bytes, u8 *buf) |
Vladimir Serbinenko | 888d559 | 2013-11-13 17:53:38 +0100 | [diff] [blame] | 48 | { |
| 49 | return do_smbus_block_read(SMBUS_IO_BASE, device, cmd, bytes, buf); |
| 50 | } |
| 51 | |
Martin Roth | ff744bf | 2019-10-23 21:46:03 -0600 | [diff] [blame] | 52 | int smbus_block_write(unsigned int device, unsigned int cmd, u8 bytes, const u8 *buf) |
Vladimir Serbinenko | 888d559 | 2013-11-13 17:53:38 +0100 | [diff] [blame] | 53 | { |
| 54 | return do_smbus_block_write(SMBUS_IO_BASE, device, cmd, bytes, buf); |
| 55 | } |