Duncan Laurie | c88c54c | 2014-04-30 16:36:13 -0700 | [diff] [blame] | 1 | /* |
| 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 Laurie | c88c54c | 2014-04-30 16:36:13 -0700 | [diff] [blame] | 15 | */ |
| 16 | |
| 17 | #include <arch/io.h> |
Duncan Laurie | c88c54c | 2014-04-30 16:36:13 -0700 | [diff] [blame] | 18 | #include <device/pci_def.h> |
| 19 | #include <reg_script.h> |
Julius Werner | 4ee4bd5 | 2014-10-20 13:46:39 -0700 | [diff] [blame] | 20 | #include <soc/iomap.h> |
| 21 | #include <soc/pci_devs.h> |
| 22 | #include <soc/smbus.h> |
| 23 | #include <soc/romstage.h> |
Duncan Laurie | c88c54c | 2014-04-30 16:36:13 -0700 | [diff] [blame] | 24 | |
| 25 | static 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 Lin | af9cbaa | 2014-10-01 15:53:39 -0700 | [diff] [blame] | 36 | /* Indicate the end of this array by REG_SCRIPT_END */ |
| 37 | REG_SCRIPT_END, |
Duncan Laurie | c88c54c | 2014-04-30 16:36:13 -0700 | [diff] [blame] | 38 | }; |
| 39 | |
| 40 | void enable_smbus(void) |
| 41 | { |
| 42 | reg_script_run_on_dev(PCH_DEV_SMBUS, smbus_init_script); |
| 43 | } |
| 44 | |
Lee Leahy | 23602df | 2017-03-16 19:00:37 -0700 | [diff] [blame] | 45 | int smbus_read_byte(unsigned int device, unsigned int address) |
Duncan Laurie | c88c54c | 2014-04-30 16:36:13 -0700 | [diff] [blame] | 46 | { |
| 47 | return do_smbus_read_byte(SMBUS_BASE_ADDRESS, device, address); |
| 48 | } |