Uwe Hermann | 1410c2d | 2007-05-29 10:37:52 +0000 | [diff] [blame] | 1 | /* |
| 2 | * This file is part of the LinuxBIOS project. |
| 3 | * |
| 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. |
| 15 | * |
| 16 | * You should have received a copy of the GNU General Public License |
| 17 | * along with this program; if not, write to the Free Software |
| 18 | * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA |
| 19 | */ |
| 20 | |
| 21 | /* TODO: Implement smbus_write_byte(), smbus_recv_byte(), smbus_send_byte(). */ |
| 22 | |
| 23 | #include <device/pci_ids.h> |
| 24 | #include "i82371eb.h" |
Stefan Reinauer | a14b468 | 2006-08-04 07:50:59 +0000 | [diff] [blame] | 25 | #include "i82371eb_smbus.h" |
Richard Smith | cb8eab4 | 2006-07-24 04:25:47 +0000 | [diff] [blame] | 26 | |
| 27 | #define SMBUS_IO_BASE 0x0f00 |
| 28 | |
| 29 | static void enable_smbus(void) |
| 30 | { |
| 31 | device_t dev; |
Uwe Hermann | 1410c2d | 2007-05-29 10:37:52 +0000 | [diff] [blame] | 32 | uint8_t reg8; |
| 33 | uint16_t reg16; |
| 34 | |
| 35 | dev = pci_locate_device(PCI_ID(PCI_VENDOR_ID_INTEL, |
| 36 | PCI_DEVICE_ID_INTEL_82371AB_SMB), 0); |
| 37 | |
Richard Smith | cb8eab4 | 2006-07-24 04:25:47 +0000 | [diff] [blame] | 38 | if (dev == PCI_DEV_INVALID) { |
Uwe Hermann | 1410c2d | 2007-05-29 10:37:52 +0000 | [diff] [blame] | 39 | die("SMBus controller not found\r\n"); |
Richard Smith | cb8eab4 | 2006-07-24 04:25:47 +0000 | [diff] [blame] | 40 | } |
Richard Smith | cb8eab4 | 2006-07-24 04:25:47 +0000 | [diff] [blame] | 41 | print_spew("SMBus controller enabled\r\n"); |
Uwe Hermann | 1410c2d | 2007-05-29 10:37:52 +0000 | [diff] [blame] | 42 | |
| 43 | /* Set the SMBus I/O base. */ |
| 44 | pci_write_config32(dev, SMBBA, SMBUS_IO_BASE | 1); |
| 45 | |
| 46 | /* Enable the SMBus Controller Host Interface. */ |
| 47 | reg8 = pci_read_config8(dev, SMBHSTCFG); |
| 48 | reg8 |= SMB_HST_EN; |
| 49 | pci_write_config8(dev, SMBHSTCFG, reg8); |
| 50 | |
| 51 | /* Enable access to the SMBus I/O space. */ |
| 52 | reg16 = pci_read_config16(dev, PCICMD); |
| 53 | reg16 |= IOSE; |
| 54 | pci_write_config16(dev, PCICMD, reg16); |
| 55 | |
| 56 | /* Clear any lingering errors, so the transaction will run. */ |
| 57 | outb(inb(SMBUS_IO_BASE + SMBHST_STATUS), SMBUS_IO_BASE + SMBHST_STATUS); |
Richard Smith | d7088c4 | 2006-07-30 00:23:20 +0000 | [diff] [blame] | 58 | } |
| 59 | |
Uwe Hermann | 1410c2d | 2007-05-29 10:37:52 +0000 | [diff] [blame] | 60 | static int smbus_read_byte(unsigned int device, unsigned int address) |
Richard Smith | d7088c4 | 2006-07-30 00:23:20 +0000 | [diff] [blame] | 61 | { |
| 62 | return do_smbus_read_byte(SMBUS_IO_BASE, device, address); |
| 63 | } |