blob: fc6e199ea6af414fc0b47b4080a08a295c0c29b2 [file] [log] [blame]
Uwe Hermann1410c2d2007-05-29 10:37:52 +00001/*
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
Uwe Hermann9da69f82007-11-30 02:08:26 +000023#include <stdint.h>
Uwe Hermann1410c2d2007-05-29 10:37:52 +000024#include <device/pci_ids.h>
25#include "i82371eb.h"
Stefan Reinauera14b4682006-08-04 07:50:59 +000026#include "i82371eb_smbus.h"
Richard Smithcb8eab42006-07-24 04:25:47 +000027
28#define SMBUS_IO_BASE 0x0f00
29
30static void enable_smbus(void)
31{
32 device_t dev;
Uwe Hermann9da69f82007-11-30 02:08:26 +000033 u8 reg8;
34 u16 reg16;
Uwe Hermann1410c2d2007-05-29 10:37:52 +000035
Uwe Hermann9da69f82007-11-30 02:08:26 +000036 /* Check for SMBus device PCI ID on the 82371AB/EB/MB. */
Uwe Hermann1410c2d2007-05-29 10:37:52 +000037 dev = pci_locate_device(PCI_ID(PCI_VENDOR_ID_INTEL,
Uwe Hermann447aafe2007-11-29 01:44:43 +000038 PCI_DEVICE_ID_INTEL_82371AB_SMB_ACPI), 0);
Uwe Hermann1410c2d2007-05-29 10:37:52 +000039
Uwe Hermann9da69f82007-11-30 02:08:26 +000040 if (dev == PCI_DEV_INVALID)
Uwe Hermann1410c2d2007-05-29 10:37:52 +000041 die("SMBus controller not found\r\n");
Uwe Hermann9da69f82007-11-30 02:08:26 +000042
Richard Smithcb8eab42006-07-24 04:25:47 +000043 print_spew("SMBus controller enabled\r\n");
Uwe Hermann1410c2d2007-05-29 10:37:52 +000044
45 /* Set the SMBus I/O base. */
46 pci_write_config32(dev, SMBBA, SMBUS_IO_BASE | 1);
47
Uwe Hermann9da69f82007-11-30 02:08:26 +000048 /* Enable the SMBus controller host interface. */
Uwe Hermann1410c2d2007-05-29 10:37:52 +000049 reg8 = pci_read_config8(dev, SMBHSTCFG);
50 reg8 |= SMB_HST_EN;
51 pci_write_config8(dev, SMBHSTCFG, reg8);
52
53 /* Enable access to the SMBus I/O space. */
Uwe Hermann56a91252007-06-03 16:57:27 +000054 reg16 = pci_read_config16(dev, PCI_COMMAND);
Uwe Hermann9da69f82007-11-30 02:08:26 +000055 reg16 |= PCI_COMMAND_IO;
Uwe Hermann56a91252007-06-03 16:57:27 +000056 pci_write_config16(dev, PCI_COMMAND, reg16);
Uwe Hermann1410c2d2007-05-29 10:37:52 +000057
58 /* Clear any lingering errors, so the transaction will run. */
59 outb(inb(SMBUS_IO_BASE + SMBHST_STATUS), SMBUS_IO_BASE + SMBHST_STATUS);
Richard Smithd7088c42006-07-30 00:23:20 +000060}
61
Uwe Hermann9da69f82007-11-30 02:08:26 +000062static int smbus_read_byte(u8 device, u8 address)
Richard Smithd7088c42006-07-30 00:23:20 +000063{
64 return do_smbus_read_byte(SMBUS_IO_BASE, device, address);
65}