blob: 41c324ff5010635c299c80a48891e7ea619bd0ca [file] [log] [blame]
Patrick Georgi02363b52020-05-05 20:48:50 +02001/* This file is part of the coreboot project. */
Patrick Georgiac959032020-05-05 22:49:26 +02002/* SPDX-License-Identifier: GPL-2.0-or-later */
Uwe Hermann1410c2d2007-05-29 10:37:52 +00003
Uwe Hermann9da69f82007-11-30 02:08:26 +00004#include <stdint.h>
Kyösti Mälkkif1b58b72019-03-01 13:43:02 +02005#include <device/pci_ops.h>
Kyösti Mälkki8a41f4b2019-02-08 18:14:34 +02006#include <device/pci.h>
Uwe Hermann1410c2d2007-05-29 10:37:52 +00007#include <device/pci_ids.h>
Uwe Hermann115c5b92010-10-09 17:00:18 +00008#include <device/pci_def.h>
Kyösti Mälkki1cae4542020-01-06 12:31:34 +02009#include <device/smbus_host.h>
Uwe Hermann1410c2d2007-05-29 10:37:52 +000010#include "i82371eb.h"
Richard Smithcb8eab42006-07-24 04:25:47 +000011
Kyösti Mälkki7a955752020-01-07 12:18:24 +020012void i82371eb_early_init(void)
13{
14 enable_smbus();
15 enable_pm();
16}
17
Kyösti Mälkkif555a582020-01-06 19:41:42 +020018uintptr_t smbus_base(void)
19{
20 return SMBUS_IO_BASE;
21}
22
23int smbus_enable_iobar(uintptr_t base)
Richard Smithcb8eab42006-07-24 04:25:47 +000024{
Antonello Dettorif068a732016-09-03 10:45:33 +020025 pci_devfn_t dev;
Uwe Hermann9da69f82007-11-30 02:08:26 +000026 u8 reg8;
27 u16 reg16;
Uwe Hermann1410c2d2007-05-29 10:37:52 +000028
Uwe Hermann115c5b92010-10-09 17:00:18 +000029 /* Get the SMBus/PM device of the 82371AB/EB/MB. */
Uwe Hermann1410c2d2007-05-29 10:37:52 +000030 dev = pci_locate_device(PCI_ID(PCI_VENDOR_ID_INTEL,
Uwe Hermann447aafe2007-11-29 01:44:43 +000031 PCI_DEVICE_ID_INTEL_82371AB_SMB_ACPI), 0);
Uwe Hermann1410c2d2007-05-29 10:37:52 +000032
Uwe Hermann1410c2d2007-05-29 10:37:52 +000033 /* Set the SMBus I/O base. */
Kyösti Mälkkif555a582020-01-06 19:41:42 +020034 pci_write_config32(dev, SMBBA, base | 1);
Uwe Hermann1410c2d2007-05-29 10:37:52 +000035
Uwe Hermann9da69f82007-11-30 02:08:26 +000036 /* Enable the SMBus controller host interface. */
Uwe Hermann1410c2d2007-05-29 10:37:52 +000037 reg8 = pci_read_config8(dev, SMBHSTCFG);
38 reg8 |= SMB_HST_EN;
39 pci_write_config8(dev, SMBHSTCFG, reg8);
40
41 /* Enable access to the SMBus I/O space. */
Uwe Hermann56a91252007-06-03 16:57:27 +000042 reg16 = pci_read_config16(dev, PCI_COMMAND);
Uwe Hermann9da69f82007-11-30 02:08:26 +000043 reg16 |= PCI_COMMAND_IO;
Uwe Hermann56a91252007-06-03 16:57:27 +000044 pci_write_config16(dev, PCI_COMMAND, reg16);
Uwe Hermann1410c2d2007-05-29 10:37:52 +000045
Kyösti Mälkkif555a582020-01-06 19:41:42 +020046 return 0;
Richard Smithd7088c42006-07-30 00:23:20 +000047}
48
Uwe Hermann115c5b92010-10-09 17:00:18 +000049int smbus_read_byte(u8 device, u8 address)
Richard Smithd7088c42006-07-30 00:23:20 +000050{
51 return do_smbus_read_byte(SMBUS_IO_BASE, device, address);
52}