blob: d2ff00a1eb0406ba2cf9cb54e0e5ff8ce5e5141a [file] [log] [blame]
Patrick Georgiac959032020-05-05 22:49:26 +02001/* SPDX-License-Identifier: GPL-2.0-or-later */
Uwe Hermann1410c2d2007-05-29 10:37:52 +00002
Uwe Hermann9da69f82007-11-30 02:08:26 +00003#include <stdint.h>
Kyösti Mälkkif1b58b72019-03-01 13:43:02 +02004#include <device/pci_ops.h>
Kyösti Mälkki8a41f4b2019-02-08 18:14:34 +02005#include <device/pci.h>
Uwe Hermann1410c2d2007-05-29 10:37:52 +00006#include <device/pci_ids.h>
Uwe Hermann115c5b92010-10-09 17:00:18 +00007#include <device/pci_def.h>
Kyösti Mälkki1cae4542020-01-06 12:31:34 +02008#include <device/smbus_host.h>
Uwe Hermann1410c2d2007-05-29 10:37:52 +00009#include "i82371eb.h"
Richard Smithcb8eab42006-07-24 04:25:47 +000010
Kyösti Mälkki7a955752020-01-07 12:18:24 +020011void i82371eb_early_init(void)
12{
13 enable_smbus();
14 enable_pm();
15}
16
Kyösti Mälkkif555a582020-01-06 19:41:42 +020017uintptr_t smbus_base(void)
18{
19 return SMBUS_IO_BASE;
20}
21
22int smbus_enable_iobar(uintptr_t base)
Richard Smithcb8eab42006-07-24 04:25:47 +000023{
Uwe Hermann9da69f82007-11-30 02:08:26 +000024 u8 reg8;
25 u16 reg16;
Uwe Hermann1410c2d2007-05-29 10:37:52 +000026
Uwe Hermann115c5b92010-10-09 17:00:18 +000027 /* Get the SMBus/PM device of the 82371AB/EB/MB. */
Felix Singer43b7f412022-03-07 04:34:52 +010028 const pci_devfn_t dev = pci_locate_device(PCI_ID(PCI_VID_INTEL,
29 PCI_DID_INTEL_82371AB_SMB_ACPI), 0);
Uwe Hermann1410c2d2007-05-29 10:37:52 +000030
Uwe Hermann1410c2d2007-05-29 10:37:52 +000031 /* Set the SMBus I/O base. */
Kyösti Mälkkif555a582020-01-06 19:41:42 +020032 pci_write_config32(dev, SMBBA, base | 1);
Uwe Hermann1410c2d2007-05-29 10:37:52 +000033
Uwe Hermann9da69f82007-11-30 02:08:26 +000034 /* Enable the SMBus controller host interface. */
Uwe Hermann1410c2d2007-05-29 10:37:52 +000035 reg8 = pci_read_config8(dev, SMBHSTCFG);
36 reg8 |= SMB_HST_EN;
37 pci_write_config8(dev, SMBHSTCFG, reg8);
38
39 /* Enable access to the SMBus I/O space. */
Uwe Hermann56a91252007-06-03 16:57:27 +000040 reg16 = pci_read_config16(dev, PCI_COMMAND);
Uwe Hermann9da69f82007-11-30 02:08:26 +000041 reg16 |= PCI_COMMAND_IO;
Uwe Hermann56a91252007-06-03 16:57:27 +000042 pci_write_config16(dev, PCI_COMMAND, reg16);
Uwe Hermann1410c2d2007-05-29 10:37:52 +000043
Kyösti Mälkkif555a582020-01-06 19:41:42 +020044 return 0;
Richard Smithd7088c42006-07-30 00:23:20 +000045}