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