blob: d65b4aaf81bf3ceb458b81c3ed2a638fb6565c7e [file] [log] [blame]
Angel Pons182dbde2020-04-02 23:49:05 +02001/* SPDX-License-Identifier: GPL-2.0-only */
Vladimir Serbinenko888d5592013-11-13 17:53:38 +01002
Angel Pons90e9f542020-06-01 19:31:53 +02003#include <device/pci_def.h>
Elyes HAOUAS25d20d32020-04-06 09:12:50 +02004#include <device/pci_ids.h>
Kyösti Mälkkif1b58b72019-03-01 13:43:02 +02005#include <device/pci_ops.h>
Kyösti Mälkki1cae4542020-01-06 12:31:34 +02006#include <device/smbus_host.h>
Angel Pons90e9f542020-06-01 19:31:53 +02007#include "early_smbus.h"
Vladimir Serbinenko888d5592013-11-13 17:53:38 +01008
Kyösti Mälkkif555a582020-01-06 19:41:42 +02009uintptr_t smbus_base(void)
Vladimir Serbinenko888d5592013-11-13 17:53:38 +010010{
Angel Ponsb21bffa2020-07-03 01:02:28 +020011 return CONFIG_FIXED_SMBUS_IO_BASE;
Kyösti Mälkkif555a582020-01-06 19:41:42 +020012}
Vladimir Serbinenko888d5592013-11-13 17:53:38 +010013
Kyösti Mälkkif555a582020-01-06 19:41:42 +020014int smbus_enable_iobar(uintptr_t base)
15{
Vladimir Serbinenko888d5592013-11-13 17:53:38 +010016 /* Set the SMBus device statically. */
Angel Pons90e9f542020-06-01 19:31:53 +020017 const pci_devfn_t dev = PCI_DEV_SMBUS;
Vladimir Serbinenko888d5592013-11-13 17:53:38 +010018
19 /* Check to make sure we've got the right device. */
Elyes HAOUAS25d20d32020-04-06 09:12:50 +020020 if (pci_read_config16(dev, PCI_VENDOR_ID) != PCI_VENDOR_ID_INTEL)
Kyösti Mälkkif555a582020-01-06 19:41:42 +020021 return -1;
Vladimir Serbinenko888d5592013-11-13 17:53:38 +010022
23 /* Set SMBus I/O base. */
Angel Pons90e9f542020-06-01 19:31:53 +020024 pci_write_config32(dev, SMB_BASE, base | PCI_BASE_ADDRESS_SPACE_IO);
Vladimir Serbinenko888d5592013-11-13 17:53:38 +010025
26 /* Set SMBus enable. */
27 pci_write_config8(dev, HOSTC, HST_EN);
28
29 /* Set SMBus I/O space enable. */
30 pci_write_config16(dev, PCI_COMMAND, PCI_COMMAND_IO);
31
Kyösti Mälkkif555a582020-01-06 19:41:42 +020032 return 0;
Vladimir Serbinenko888d5592013-11-13 17:53:38 +010033}