blob: c038e0aba889697d85dd11418e4f909afef065d9 [file] [log] [blame]
Corey Osgoode99bd102007-06-14 06:10:57 +00001/*
Stefan Reinauer7e61e452008-01-18 10:35:56 +00002 * This file is part of the coreboot project.
Corey Osgoode99bd102007-06-14 06:10:57 +00003 *
4 * Copyright (C) 2005 Tyan Computer
5 * (Written by Yinghai Lu <yinghailu@gmail.com> for Tyan Computer)
6 * Copyright (C) 2007 Corey Osgood <corey.osgood@gmail.com>
7 *
8 * This program is free software; you can redistribute it and/or modify
9 * it under the terms of the GNU General Public License as published by
10 * the Free Software Foundation; either version 2 of the License, or
11 * (at your option) any later version.
12 *
13 * This program is distributed in the hope that it will be useful,
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 * GNU General Public License for more details.
Corey Osgoode99bd102007-06-14 06:10:57 +000017 */
18
Uwe Hermann212d0a22010-10-13 23:00:41 +000019#include <arch/io.h>
Uwe Hermann212d0a22010-10-13 23:00:41 +000020#include <console/console.h>
Corey Osgoode99bd102007-06-14 06:10:57 +000021#include <device/pci_ids.h>
Uwe Hermann212d0a22010-10-13 23:00:41 +000022#include <device/pci_def.h>
Stefan Reinauer138be832010-02-27 01:50:21 +000023#include "i82801bx.h"
stepan836ae292010-12-08 05:42:47 +000024#include "smbus.h"
Corey Osgoode99bd102007-06-14 06:10:57 +000025
Uwe Hermann212d0a22010-10-13 23:00:41 +000026void enable_smbus(void)
Corey Osgoode99bd102007-06-14 06:10:57 +000027{
28 device_t dev;
Uwe Hermanndfb3c132007-06-19 22:47:11 +000029
Uwe Hermann0ea281f2010-10-11 21:38:49 +000030 /* Set the SMBus device statically (D31:F3). */
Corey Osgoode99bd102007-06-14 06:10:57 +000031 dev = PCI_DEV(0x0, 0x1f, 0x3);
Uwe Hermanndfb3c132007-06-19 22:47:11 +000032
Uwe Hermanndfb3c132007-06-19 22:47:11 +000033 /* Set SMBus I/O base. */
34 pci_write_config32(dev, SMB_BASE,
35 SMBUS_IO_BASE | PCI_BASE_ADDRESS_SPACE_IO);
36
37 /* Set SMBus enable. */
Corey Osgoode99bd102007-06-14 06:10:57 +000038 pci_write_config8(dev, HOSTC, HST_EN);
Uwe Hermanndfb3c132007-06-19 22:47:11 +000039
40 /* Set SMBus I/O space enable. */
Corey Osgoode99bd102007-06-14 06:10:57 +000041 pci_write_config16(dev, PCI_COMMAND, PCI_COMMAND_IO);
Uwe Hermanndfb3c132007-06-19 22:47:11 +000042
43 /* Disable interrupt generation. */
Corey Osgoode99bd102007-06-14 06:10:57 +000044 outb(0, SMBUS_IO_BASE + SMBHSTCTL);
Uwe Hermanndfb3c132007-06-19 22:47:11 +000045
46 /* Clear any lingering errors, so transactions can run. */
Corey Osgoode99bd102007-06-14 06:10:57 +000047 outb(inb(SMBUS_IO_BASE + SMBHSTSTAT), SMBUS_IO_BASE + SMBHSTSTAT);
Uwe Hermanndfb3c132007-06-19 22:47:11 +000048
Stefan Reinauer5ab52dd2015-01-05 13:01:01 -080049 printk(BIOS_DEBUG, "SMBus controller enabled\n");
Corey Osgoode99bd102007-06-14 06:10:57 +000050}
51
Uwe Hermann212d0a22010-10-13 23:00:41 +000052int smbus_read_byte(u8 device, u8 address)
Corey Osgoode99bd102007-06-14 06:10:57 +000053{
Uwe Hermann3b8db812010-10-08 16:40:23 +000054 return do_smbus_read_byte(SMBUS_IO_BASE, device, address);
Corey Osgoode99bd102007-06-14 06:10:57 +000055}