Stefan Reinauer | debb11f | 2008-10-29 04:46:52 +0000 | [diff] [blame] | 1 | /* |
| 2 | * This file is part of the coreboot project. |
| 3 | * |
Stefan Reinauer | a8e1168 | 2009-03-11 14:54:18 +0000 | [diff] [blame] | 4 | * Copyright (C) 2008-2009 coresystems GmbH |
Stefan Reinauer | debb11f | 2008-10-29 04:46:52 +0000 | [diff] [blame] | 5 | * |
Stefan Reinauer | a8e1168 | 2009-03-11 14:54:18 +0000 | [diff] [blame] | 6 | * This program is free software; you can redistribute it and/or |
| 7 | * modify it under the terms of the GNU General Public License as |
| 8 | * published by the Free Software Foundation; version 2 of |
| 9 | * the License. |
Stefan Reinauer | debb11f | 2008-10-29 04:46:52 +0000 | [diff] [blame] | 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. |
Stefan Reinauer | debb11f | 2008-10-29 04:46:52 +0000 | [diff] [blame] | 15 | */ |
| 16 | |
Patrick Georgi | d083595 | 2010-10-05 09:07:10 +0000 | [diff] [blame] | 17 | #include <arch/io.h> |
Kyösti Mälkki | f1b58b7 | 2019-03-01 13:43:02 +0200 | [diff] [blame^] | 18 | #include <device/pci_ops.h> |
Patrick Georgi | d083595 | 2010-10-05 09:07:10 +0000 | [diff] [blame] | 19 | #include <console/console.h> |
Patrick Georgi | d083595 | 2010-10-05 09:07:10 +0000 | [diff] [blame] | 20 | #include <device/pci_def.h> |
Arthur Heymans | 16fe790 | 2017-04-12 17:01:31 +0200 | [diff] [blame] | 21 | #include <southbridge/intel/common/smbus.h> |
Stefan Reinauer | debb11f | 2008-10-29 04:46:52 +0000 | [diff] [blame] | 22 | #include "i82801gx.h" |
Stefan Reinauer | debb11f | 2008-10-29 04:46:52 +0000 | [diff] [blame] | 23 | |
Patrick Georgi | d083595 | 2010-10-05 09:07:10 +0000 | [diff] [blame] | 24 | void enable_smbus(void) |
Stefan Reinauer | debb11f | 2008-10-29 04:46:52 +0000 | [diff] [blame] | 25 | { |
Antonello Dettori | 061d781 | 2016-08-30 22:05:32 +0200 | [diff] [blame] | 26 | pci_devfn_t dev; |
Stefan Reinauer | debb11f | 2008-10-29 04:46:52 +0000 | [diff] [blame] | 27 | |
| 28 | /* Set the SMBus device statically. */ |
| 29 | dev = PCI_DEV(0x0, 0x1f, 0x3); |
| 30 | |
| 31 | /* Check to make sure we've got the right device. */ |
Arthur Heymans | 3f111b0 | 2017-03-09 12:02:52 +0100 | [diff] [blame] | 32 | if (pci_read_config16(dev, 0x2) != 0x27da) |
Stefan Reinauer | debb11f | 2008-10-29 04:46:52 +0000 | [diff] [blame] | 33 | die("SMBus controller not found!"); |
Stefan Reinauer | debb11f | 2008-10-29 04:46:52 +0000 | [diff] [blame] | 34 | |
| 35 | /* Set SMBus I/O base. */ |
| 36 | pci_write_config32(dev, SMB_BASE, |
| 37 | SMBUS_IO_BASE | PCI_BASE_ADDRESS_SPACE_IO); |
| 38 | |
| 39 | /* Set SMBus enable. */ |
| 40 | pci_write_config8(dev, HOSTC, HST_EN); |
| 41 | |
| 42 | /* Set SMBus I/O space enable. */ |
| 43 | pci_write_config16(dev, PCI_COMMAND, PCI_COMMAND_IO); |
| 44 | |
| 45 | /* Disable interrupt generation. */ |
| 46 | outb(0, SMBUS_IO_BASE + SMBHSTCTL); |
| 47 | |
| 48 | /* Clear any lingering errors, so transactions can run. */ |
| 49 | outb(inb(SMBUS_IO_BASE + SMBHSTSTAT), SMBUS_IO_BASE + SMBHSTSTAT); |
Stefan Reinauer | 5ab52dd | 2015-01-05 13:01:01 -0800 | [diff] [blame] | 50 | printk(BIOS_DEBUG, "SMBus controller enabled.\n"); |
Stefan Reinauer | debb11f | 2008-10-29 04:46:52 +0000 | [diff] [blame] | 51 | } |
| 52 | |
Arthur Heymans | 3f111b0 | 2017-03-09 12:02:52 +0100 | [diff] [blame] | 53 | int smbus_read_byte(unsigned int device, unsigned int address) |
Stefan Reinauer | debb11f | 2008-10-29 04:46:52 +0000 | [diff] [blame] | 54 | { |
Stefan Reinauer | a8e1168 | 2009-03-11 14:54:18 +0000 | [diff] [blame] | 55 | return do_smbus_read_byte(SMBUS_IO_BASE, device, address); |
Stefan Reinauer | debb11f | 2008-10-29 04:46:52 +0000 | [diff] [blame] | 56 | } |
Arthur Heymans | 2a7c519 | 2017-03-20 22:32:02 +0100 | [diff] [blame] | 57 | |
Kyösti Mälkki | c01a505 | 2019-01-30 09:39:23 +0200 | [diff] [blame] | 58 | int i2c_eeprom_read(unsigned int device, unsigned int offset, u32 bytes, u8 *buf) |
Arthur Heymans | 2a7c519 | 2017-03-20 22:32:02 +0100 | [diff] [blame] | 59 | { |
Kyösti Mälkki | c01a505 | 2019-01-30 09:39:23 +0200 | [diff] [blame] | 60 | return do_i2c_eeprom_read(SMBUS_IO_BASE, device, offset, bytes, buf); |
Arthur Heymans | 2a7c519 | 2017-03-20 22:32:02 +0100 | [diff] [blame] | 61 | } |
Arthur Heymans | ad29ec3 | 2017-05-05 21:08:00 +0200 | [diff] [blame] | 62 | |
| 63 | int smbus_block_read(unsigned int device, unsigned int cmd, u8 bytes, u8 *buf) |
| 64 | { |
| 65 | return do_smbus_block_read(SMBUS_IO_BASE, device, cmd, bytes, buf); |
| 66 | } |
| 67 | |
| 68 | int smbus_block_write(unsigned int device, unsigned int cmd, u8 bytes, |
| 69 | const u8 *buf) |
| 70 | { |
| 71 | return do_smbus_block_write(SMBUS_IO_BASE, device, cmd, bytes, buf); |
| 72 | } |