blob: 5f4c6fe26722321814821d6f287b209f9771370f [file] [log] [blame]
arch import user (historical)98d0d302005-07-06 17:13:46 +00001/*
Uwe Hermann8af6d552010-10-17 19:13:18 +00002 * This file is part of the coreboot project.
3 *
4 * Copyright (C) 2004 Tyan Computer
5 * Written by Yinghai Lu <yhlu@tyan.com> for Tyan Computer.
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.
arch import user (historical)98d0d302005-07-06 17:13:46 +000015 */
16
Jonathan Kollaschd8bed0a2010-10-27 17:26:57 +000017#include <stdint.h>
18#include <arch/io.h>
Jonathan Kollaschd8bed0a2010-10-27 17:26:57 +000019#include <console/console.h>
20#include <device/pci_def.h>
21#include <device/pci_ids.h>
22
stepan836ae292010-12-08 05:42:47 +000023#include "smbus.h"
24#include "early_smbus.h"
arch import user (historical)98d0d302005-07-06 17:13:46 +000025
Jonathan Kollaschd8bed0a2010-10-27 17:26:57 +000026#define SMBUS_BAR_BASE 0x20
arch import user (historical)98d0d302005-07-06 17:13:46 +000027#define SMBUS_IO_BASE 0x1000
Jonathan Kollaschd8bed0a2010-10-27 17:26:57 +000028#define SMBUS_IO_SIZE 0x0040
arch import user (historical)98d0d302005-07-06 17:13:46 +000029
Jonathan Kollaschd8bed0a2010-10-27 17:26:57 +000030#define SMBUS_BAR(x) (SMBUS_BAR_BASE + 4 * (x))
31#define SMBUS_BASE(x) (SMBUS_IO_BASE + SMBUS_IO_SIZE * (x))
32
33void enable_smbus(void)
arch import user (historical)98d0d302005-07-06 17:13:46 +000034{
35 device_t dev;
Jonathan Kollaschd8bed0a2010-10-27 17:26:57 +000036
37 dev = pci_locate_device(PCI_ID(PCI_VENDOR_ID_NVIDIA,
38 PCI_DEVICE_ID_NVIDIA_CK804_SMB), 0);
Uwe Hermann7f3d48c2008-10-02 18:19:17 +000039 if (dev == PCI_DEV_INVALID)
Stefan Reinauer64ed2b72010-03-31 14:47:43 +000040 die("SMBus controller not found\n");
Myles Watson64caf362008-09-18 16:27:00 +000041
Uwe Hermann7f3d48c2008-10-02 18:19:17 +000042 /* Set SMBus I/O base. */
Jonathan Kollaschd8bed0a2010-10-27 17:26:57 +000043 pci_write_config32(dev, SMBUS_BAR(0), SMBUS_BASE(0) | 1);
44 pci_write_config32(dev, SMBUS_BAR(1), SMBUS_BASE(1) | 1);
Uwe Hermann7f3d48c2008-10-02 18:19:17 +000045
46 /* Set SMBus I/O space enable. */
arch import user (historical)98d0d302005-07-06 17:13:46 +000047 pci_write_config16(dev, 0x4, 0x01);
Uwe Hermann7f3d48c2008-10-02 18:19:17 +000048
49 /* Clear any lingering errors, so the transaction will run. */
Jonathan Kollaschd8bed0a2010-10-27 17:26:57 +000050 outb(inb(SMBUS_BASE(0) + SMBHSTSTAT), SMBUS_BASE(0) + SMBHSTSTAT);
51 outb(inb(SMBUS_BASE(1) + SMBHSTSTAT), SMBUS_BASE(1) + SMBHSTSTAT);
52
Stefan Reinauer5ab52dd2015-01-05 13:01:01 -080053 printk(BIOS_DEBUG, "SMBus controller enabled\n");
arch import user (historical)98d0d302005-07-06 17:13:46 +000054}
55
Jonathan Kollaschd8bed0a2010-10-27 17:26:57 +000056int ck804_smbus_read_byte(unsigned bus, unsigned device, unsigned address)
arch import user (historical)98d0d302005-07-06 17:13:46 +000057{
Jonathan Kollaschd8bed0a2010-10-27 17:26:57 +000058 return do_smbus_read_byte(SMBUS_BASE(bus), device, address);
arch import user (historical)98d0d302005-07-06 17:13:46 +000059}
Uwe Hermann7f3d48c2008-10-02 18:19:17 +000060
Jonathan Kollaschd8bed0a2010-10-27 17:26:57 +000061int ck804_smbus_write_byte(unsigned bus, unsigned device, unsigned address,
Uwe Hermann7e2fbd52011-01-04 17:36:55 +000062 unsigned char val)
arch import user (historical)98d0d302005-07-06 17:13:46 +000063{
Jonathan Kollaschd8bed0a2010-10-27 17:26:57 +000064 return do_smbus_write_byte(SMBUS_BASE(bus), device, address, val);
65}
66
67int smbus_read_byte(unsigned device, unsigned address)
68{
69 return ck804_smbus_read_byte(0, device, address);
70}
71
72int smbus_write_byte(unsigned device, unsigned address, unsigned char val)
73{
74 return ck804_smbus_write_byte(0, device, address, val);
arch import user (historical)98d0d302005-07-06 17:13:46 +000075}