blob: 595914af2dff22d2c1ad884a488c628c2903c73c [file] [log] [blame]
Yinghai Luc65bd562007-02-01 00:10:05 +00001/*
Stefan Reinauer7e61e452008-01-18 10:35:56 +00002 * This file is part of the coreboot project.
Yinghai Luc65bd562007-02-01 00:10:05 +00003 *
4 * Copyright (C) 2004 Tyan Computer
5 * Written by Yinghai Lu <yhlu@tyan.com> for Tyan Computer.
6 * Copyright (C) 2006,2007 AMD
7 * Written by Yinghai Lu <yinghai.lu@amd.com> for AMD.
8 *
9 * This program is free software; you can redistribute it and/or modify
10 * it under the terms of the GNU General Public License as published by
11 * the Free Software Foundation; either version 2 of the License, or
12 * (at your option) any later version.
13 *
14 * This program is distributed in the hope that it will be useful,
15 * but WITHOUT ANY WARRANTY; without even the implied warranty of
16 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17 * GNU General Public License for more details.
Yinghai Luc65bd562007-02-01 00:10:05 +000018 */
19
stepan836ae292010-12-08 05:42:47 +000020#include "smbus.h"
Yinghai Luc65bd562007-02-01 00:10:05 +000021
22#define SMBUS0_IO_BASE 0x1000
Uwe Hermannc7f0c8f2011-01-04 19:51:33 +000023#define SMBUS1_IO_BASE (0x1000 + (1 << 8))
24/* Size: 0x40 */
Yinghai Luc65bd562007-02-01 00:10:05 +000025
26static void enable_smbus(void)
27{
Antonello Dettori8126daf2016-09-03 10:45:33 +020028 pci_devfn_t dev;
Yinghai Luc65bd562007-02-01 00:10:05 +000029 dev = pci_locate_device(PCI_ID(0x10de, 0x0368), 0);
Stefan Reinauerd55e26f2010-04-25 13:54:30 +000030
Ward Vandewegef648d612010-11-08 17:41:43 +000031 if (dev == PCI_DEV_INVALID)
32 die("SMBus controller not found\n");
Yinghai Luc65bd562007-02-01 00:10:05 +000033
Uwe Hermannc7f0c8f2011-01-04 19:51:33 +000034 /* Set SMBus I/O base. */
Yinghai Luc65bd562007-02-01 00:10:05 +000035 pci_write_config32(dev, 0x20, SMBUS0_IO_BASE | 1);
36 pci_write_config32(dev, 0x24, SMBUS1_IO_BASE | 1);
Uwe Hermannc7f0c8f2011-01-04 19:51:33 +000037
38 /* Set SMBus I/O space enable. */
Yinghai Luc65bd562007-02-01 00:10:05 +000039 pci_write_config16(dev, 0x4, 0x01);
Uwe Hermannc7f0c8f2011-01-04 19:51:33 +000040
41 /* Clear any lingering errors, so the transaction will run. */
Yinghai Luc65bd562007-02-01 00:10:05 +000042 outb(inb(SMBUS0_IO_BASE + SMBHSTSTAT), SMBUS0_IO_BASE + SMBHSTSTAT);
43 outb(inb(SMBUS1_IO_BASE + SMBHSTSTAT), SMBUS1_IO_BASE + SMBHSTSTAT);
44}
45
Stefan Reinauerd55e26f2010-04-25 13:54:30 +000046static inline int smbus_recv_byte(unsigned device)
Yinghai Luc65bd562007-02-01 00:10:05 +000047{
48 return do_smbus_recv_byte(SMBUS0_IO_BASE, device);
49}
Stefan Reinauerd55e26f2010-04-25 13:54:30 +000050
51static inline int smbus_send_byte(unsigned device, unsigned char val)
Yinghai Luc65bd562007-02-01 00:10:05 +000052{
53 return do_smbus_send_byte(SMBUS0_IO_BASE, device, val);
54}
Stefan Reinauerd55e26f2010-04-25 13:54:30 +000055
56static inline int smbus_read_byte(unsigned device, unsigned address)
Yinghai Luc65bd562007-02-01 00:10:05 +000057{
58 return do_smbus_read_byte(SMBUS0_IO_BASE, device, address);
59}
Stefan Reinauerd55e26f2010-04-25 13:54:30 +000060
Uwe Hermannc7f0c8f2011-01-04 19:51:33 +000061static inline int smbus_write_byte(unsigned device, unsigned address,
62 unsigned char val)
Yinghai Luc65bd562007-02-01 00:10:05 +000063{
64 return do_smbus_write_byte(SMBUS0_IO_BASE, device, address, val);
65}
66
Stefan Reinauerd55e26f2010-04-25 13:54:30 +000067static inline int smbusx_recv_byte(unsigned smb_index, unsigned device)
Yinghai Luc65bd562007-02-01 00:10:05 +000068{
Uwe Hermannc7f0c8f2011-01-04 19:51:33 +000069 return do_smbus_recv_byte(SMBUS0_IO_BASE + (smb_index << 8), device);
Yinghai Luc65bd562007-02-01 00:10:05 +000070}
Stefan Reinauerd55e26f2010-04-25 13:54:30 +000071
Uwe Hermannc7f0c8f2011-01-04 19:51:33 +000072static inline int smbusx_send_byte(unsigned smb_index, unsigned device,
73 unsigned char val)
Yinghai Luc65bd562007-02-01 00:10:05 +000074{
Uwe Hermannc7f0c8f2011-01-04 19:51:33 +000075 return do_smbus_send_byte(SMBUS0_IO_BASE + (smb_index << 8),
76 device, val);
Yinghai Luc65bd562007-02-01 00:10:05 +000077}
Stefan Reinauerd55e26f2010-04-25 13:54:30 +000078
Uwe Hermannc7f0c8f2011-01-04 19:51:33 +000079static inline int smbusx_read_byte(unsigned smb_index, unsigned device,
80 unsigned address)
Yinghai Luc65bd562007-02-01 00:10:05 +000081{
Uwe Hermannc7f0c8f2011-01-04 19:51:33 +000082 return do_smbus_read_byte(SMBUS0_IO_BASE + (smb_index << 8),
83 device, address);
Yinghai Luc65bd562007-02-01 00:10:05 +000084}
Stefan Reinauerd55e26f2010-04-25 13:54:30 +000085
Uwe Hermannc7f0c8f2011-01-04 19:51:33 +000086static inline int smbusx_write_byte(unsigned smb_index, unsigned device,
87 unsigned address, unsigned char val)
Yinghai Luc65bd562007-02-01 00:10:05 +000088{
Uwe Hermannc7f0c8f2011-01-04 19:51:33 +000089 return do_smbus_write_byte(SMBUS0_IO_BASE + (smb_index << 8),
90 device, address, val);
Yinghai Luc65bd562007-02-01 00:10:05 +000091}