blob: fd886c47f9a582d86c9f43517e06af90d7cd8c66 [file] [log] [blame]
Duncan Lauriec88c54c2014-04-30 16:36:13 -07001/*
2 * This file is part of the coreboot project.
3 *
4 * Copyright (C) 2008-2009 coresystems GmbH
5 * Copyright (C) 2014 Google Inc.
6 *
7 * This program is free software; you can redistribute it and/or modify
8 * it under the terms of the GNU General Public License as published by
9 * the Free Software Foundation; version 2 of 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.
Duncan Lauriec88c54c2014-04-30 16:36:13 -070015 */
16
17#include <arch/io.h>
Duncan Lauriec88c54c2014-04-30 16:36:13 -070018#include <device/pci_def.h>
19#include <reg_script.h>
Julius Werner4ee4bd52014-10-20 13:46:39 -070020#include <soc/iomap.h>
21#include <soc/pci_devs.h>
22#include <soc/smbus.h>
23#include <soc/romstage.h>
Duncan Lauriec88c54c2014-04-30 16:36:13 -070024
25static const struct reg_script smbus_init_script[] = {
26 /* Set SMBUS I/O base address */
27 REG_PCI_WRITE32(SMB_BASE, SMBUS_BASE_ADDRESS | 1),
28 /* Set SMBUS enable */
29 REG_PCI_WRITE8(HOSTC, HST_EN),
30 /* Enable I/O access */
31 REG_PCI_WRITE16(PCI_COMMAND, PCI_COMMAND_IO),
32 /* Disable interrupts */
33 REG_IO_WRITE8(SMBUS_BASE_ADDRESS + SMBHSTCTL, 0),
34 /* Clear errors */
35 REG_IO_WRITE8(SMBUS_BASE_ADDRESS + SMBHSTSTAT, 0xff),
Ryan Linaf9cbaa2014-10-01 15:53:39 -070036 /* Indicate the end of this array by REG_SCRIPT_END */
37 REG_SCRIPT_END,
Duncan Lauriec88c54c2014-04-30 16:36:13 -070038};
39
40void enable_smbus(void)
41{
42 reg_script_run_on_dev(PCH_DEV_SMBUS, smbus_init_script);
43}
44
Lee Leahy23602df2017-03-16 19:00:37 -070045int smbus_read_byte(unsigned int device, unsigned int address)
Duncan Lauriec88c54c2014-04-30 16:36:13 -070046{
47 return do_smbus_read_byte(SMBUS_BASE_ADDRESS, device, address);
48}