blob: b87c872012b20c05183829399034f28fea03def5 [file] [log] [blame]
Angel Pons182dbde2020-04-02 23:49:05 +02001/* SPDX-License-Identifier: GPL-2.0-only */
2/* This file is part of the coreboot project. */
Vladimir Serbinenko888d5592013-11-13 17:53:38 +01003
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>
Vladimir Serbinenko888d5592013-11-13 17:53:38 +01006#include <device/pci_def.h>
Kyösti Mälkki1cae4542020-01-06 12:31:34 +02007#include <device/smbus_host.h>
Vladimir Serbinenko888d5592013-11-13 17:53:38 +01008#include "pch.h"
Vladimir Serbinenko888d5592013-11-13 17:53:38 +01009
Kyösti Mälkkif555a582020-01-06 19:41:42 +020010uintptr_t smbus_base(void)
Vladimir Serbinenko888d5592013-11-13 17:53:38 +010011{
Kyösti Mälkkif555a582020-01-06 19:41:42 +020012 return SMBUS_IO_BASE;
13}
Vladimir Serbinenko888d5592013-11-13 17:53:38 +010014
Kyösti Mälkkif555a582020-01-06 19:41:42 +020015int smbus_enable_iobar(uintptr_t base)
16{
Vladimir Serbinenko888d5592013-11-13 17:53:38 +010017 /* Set the SMBus device statically. */
Kyösti Mälkkif555a582020-01-06 19:41:42 +020018 pci_devfn_t dev = PCI_DEV(0x0, 0x1f, 0x3);
Vladimir Serbinenko888d5592013-11-13 17:53:38 +010019
20 /* Check to make sure we've got the right device. */
Elyes HAOUAS25d20d32020-04-06 09:12:50 +020021 if (pci_read_config16(dev, PCI_VENDOR_ID) != PCI_VENDOR_ID_INTEL)
Kyösti Mälkkif555a582020-01-06 19:41:42 +020022 return -1;
Vladimir Serbinenko888d5592013-11-13 17:53:38 +010023
24 /* Set SMBus I/O base. */
25 pci_write_config32(dev, SMB_BASE,
Kyösti Mälkkif555a582020-01-06 19:41:42 +020026 base | PCI_BASE_ADDRESS_SPACE_IO);
Vladimir Serbinenko888d5592013-11-13 17:53:38 +010027
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älkkif555a582020-01-06 19:41:42 +020034 return 0;
Vladimir Serbinenko888d5592013-11-13 17:53:38 +010035}
36
Martin Rothff744bf2019-10-23 21:46:03 -060037int smbus_read_byte(unsigned int device, unsigned int address)
Vladimir Serbinenko888d5592013-11-13 17:53:38 +010038{
39 return do_smbus_read_byte(SMBUS_IO_BASE, device, address);
40}
41
Martin Rothff744bf2019-10-23 21:46:03 -060042int smbus_write_byte(unsigned int device, unsigned int address, u8 data)
Vladimir Serbinenko888d5592013-11-13 17:53:38 +010043{
44 return do_smbus_write_byte(SMBUS_IO_BASE, device, address, data);
45}
46
Martin Rothff744bf2019-10-23 21:46:03 -060047int smbus_block_read(unsigned int device, unsigned int cmd, u8 bytes, u8 *buf)
Vladimir Serbinenko888d5592013-11-13 17:53:38 +010048{
49 return do_smbus_block_read(SMBUS_IO_BASE, device, cmd, bytes, buf);
50}
51
Martin Rothff744bf2019-10-23 21:46:03 -060052int smbus_block_write(unsigned int device, unsigned int cmd, u8 bytes, const u8 *buf)
Vladimir Serbinenko888d5592013-11-13 17:53:38 +010053{
54 return do_smbus_block_write(SMBUS_IO_BASE, device, cmd, bytes, buf);
55}