blob: f69cb93a74cfb66388b76d12a9971e097154e7f5 [file] [log] [blame]
Uwe Hermann1410c2d2007-05-29 10:37:52 +00001/*
Stefan Reinauer7e61e452008-01-18 10:35:56 +00002 * This file is part of the coreboot project.
Uwe Hermann1410c2d2007-05-29 10:37:52 +00003 *
4 * Copyright (C) 2007 Uwe Hermann <uwe@hermann-uwe.de>
5 *
6 * This program is free software; you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License as published by
8 * the Free Software Foundation; either version 2 of the License, or
9 * (at your option) any later version.
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.
Uwe Hermann1410c2d2007-05-29 10:37:52 +000015 */
16
Uwe Hermann9da69f82007-11-30 02:08:26 +000017#include <stdint.h>
Kyösti Mälkki7cdcc382020-01-06 19:00:31 +020018#include <console/console.h>
Kyösti Mälkkif1b58b72019-03-01 13:43:02 +020019#include <device/pci_ops.h>
Kyösti Mälkki8a41f4b2019-02-08 18:14:34 +020020#include <device/pci.h>
Uwe Hermann1410c2d2007-05-29 10:37:52 +000021#include <device/pci_ids.h>
Uwe Hermann115c5b92010-10-09 17:00:18 +000022#include <device/pci_def.h>
Kyösti Mälkki1cae4542020-01-06 12:31:34 +020023#include <device/smbus_host.h>
Uwe Hermann1410c2d2007-05-29 10:37:52 +000024#include "i82371eb.h"
Richard Smithcb8eab42006-07-24 04:25:47 +000025
Kyösti Mälkki7a955752020-01-07 12:18:24 +020026void i82371eb_early_init(void)
27{
28 enable_smbus();
29 enable_pm();
30}
31
Uwe Hermann115c5b92010-10-09 17:00:18 +000032void enable_smbus(void)
Richard Smithcb8eab42006-07-24 04:25:47 +000033{
Antonello Dettorif068a732016-09-03 10:45:33 +020034 pci_devfn_t dev;
Uwe Hermann9da69f82007-11-30 02:08:26 +000035 u8 reg8;
36 u16 reg16;
Uwe Hermann1410c2d2007-05-29 10:37:52 +000037
Uwe Hermann115c5b92010-10-09 17:00:18 +000038 /* Get the SMBus/PM device of the 82371AB/EB/MB. */
Uwe Hermann1410c2d2007-05-29 10:37:52 +000039 dev = pci_locate_device(PCI_ID(PCI_VENDOR_ID_INTEL,
Uwe Hermann447aafe2007-11-29 01:44:43 +000040 PCI_DEVICE_ID_INTEL_82371AB_SMB_ACPI), 0);
Uwe Hermann1410c2d2007-05-29 10:37:52 +000041
Uwe Hermann1410c2d2007-05-29 10:37:52 +000042 /* Set the SMBus I/O base. */
43 pci_write_config32(dev, SMBBA, SMBUS_IO_BASE | 1);
44
Uwe Hermann9da69f82007-11-30 02:08:26 +000045 /* Enable the SMBus controller host interface. */
Uwe Hermann1410c2d2007-05-29 10:37:52 +000046 reg8 = pci_read_config8(dev, SMBHSTCFG);
47 reg8 |= SMB_HST_EN;
48 pci_write_config8(dev, SMBHSTCFG, reg8);
49
50 /* Enable access to the SMBus I/O space. */
Uwe Hermann56a91252007-06-03 16:57:27 +000051 reg16 = pci_read_config16(dev, PCI_COMMAND);
Uwe Hermann9da69f82007-11-30 02:08:26 +000052 reg16 |= PCI_COMMAND_IO;
Uwe Hermann56a91252007-06-03 16:57:27 +000053 pci_write_config16(dev, PCI_COMMAND, reg16);
Uwe Hermann1410c2d2007-05-29 10:37:52 +000054
Kyösti Mälkki7cdcc382020-01-06 19:00:31 +020055 smbus_host_reset(SMBUS_IO_BASE);
56
57 printk(BIOS_DEBUG, "SMBus controller enabled\n");
Richard Smithd7088c42006-07-30 00:23:20 +000058}
59
Uwe Hermann115c5b92010-10-09 17:00:18 +000060int smbus_read_byte(u8 device, u8 address)
Richard Smithd7088c42006-07-30 00:23:20 +000061{
62 return do_smbus_read_byte(SMBUS_IO_BASE, device, address);
63}