blob: 52d483d3b3be2c568afe972d5ac4b3738251a985 [file] [log] [blame]
Vladimir Serbinenko888d5592013-11-13 17:53:38 +01001/*
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 Serbinenko888d5592013-11-13 17:53:38 +010015 */
16
Kyösti Mälkkif1b58b72019-03-01 13:43:02 +020017#include <device/pci_ops.h>
Vladimir Serbinenko888d5592013-11-13 17:53:38 +010018#include <device/pci_def.h>
Kyösti Mälkki1cae4542020-01-06 12:31:34 +020019#include <device/smbus_host.h>
Vladimir Serbinenko888d5592013-11-13 17:53:38 +010020#include "pch.h"
Vladimir Serbinenko888d5592013-11-13 17:53:38 +010021
Kyösti Mälkkif555a582020-01-06 19:41:42 +020022uintptr_t smbus_base(void)
Vladimir Serbinenko888d5592013-11-13 17:53:38 +010023{
Kyösti Mälkkif555a582020-01-06 19:41:42 +020024 return SMBUS_IO_BASE;
25}
Vladimir Serbinenko888d5592013-11-13 17:53:38 +010026
Kyösti Mälkkif555a582020-01-06 19:41:42 +020027int smbus_enable_iobar(uintptr_t base)
28{
Vladimir Serbinenko888d5592013-11-13 17:53:38 +010029 /* Set the SMBus device statically. */
Kyösti Mälkkif555a582020-01-06 19:41:42 +020030 pci_devfn_t dev = PCI_DEV(0x0, 0x1f, 0x3);
Vladimir Serbinenko888d5592013-11-13 17:53:38 +010031
32 /* Check to make sure we've got the right device. */
Kyösti Mälkkif555a582020-01-06 19:41:42 +020033 if (pci_read_config16(dev, 0x0) != 0x8086)
34 return -1;
Vladimir Serbinenko888d5592013-11-13 17:53:38 +010035
36 /* Set SMBus I/O base. */
37 pci_write_config32(dev, SMB_BASE,
Kyösti Mälkkif555a582020-01-06 19:41:42 +020038 base | PCI_BASE_ADDRESS_SPACE_IO);
Vladimir Serbinenko888d5592013-11-13 17:53:38 +010039
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älkkif555a582020-01-06 19:41:42 +020046 return 0;
Vladimir Serbinenko888d5592013-11-13 17:53:38 +010047}
48
Martin Rothff744bf2019-10-23 21:46:03 -060049int smbus_read_byte(unsigned int device, unsigned int address)
Vladimir Serbinenko888d5592013-11-13 17:53:38 +010050{
51 return do_smbus_read_byte(SMBUS_IO_BASE, device, address);
52}
53
Martin Rothff744bf2019-10-23 21:46:03 -060054int smbus_write_byte(unsigned int device, unsigned int address, u8 data)
Vladimir Serbinenko888d5592013-11-13 17:53:38 +010055{
56 return do_smbus_write_byte(SMBUS_IO_BASE, device, address, data);
57}
58
Martin Rothff744bf2019-10-23 21:46:03 -060059int smbus_block_read(unsigned int device, unsigned int cmd, u8 bytes, u8 *buf)
Vladimir Serbinenko888d5592013-11-13 17:53:38 +010060{
61 return do_smbus_block_read(SMBUS_IO_BASE, device, cmd, bytes, buf);
62}
63
Martin Rothff744bf2019-10-23 21:46:03 -060064int smbus_block_write(unsigned int device, unsigned int cmd, u8 bytes, const u8 *buf)
Vladimir Serbinenko888d5592013-11-13 17:53:38 +010065{
66 return do_smbus_block_write(SMBUS_IO_BASE, device, cmd, bytes, buf);
67}