arch import user (historical) | 98d0d30 | 2005-07-06 17:13:46 +0000 | [diff] [blame] | 1 | /* |
Uwe Hermann | 8af6d55 | 2010-10-17 19:13:18 +0000 | [diff] [blame] | 2 | * 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) | 98d0d30 | 2005-07-06 17:13:46 +0000 | [diff] [blame] | 15 | */ |
| 16 | |
Jonathan Kollasch | d8bed0a | 2010-10-27 17:26:57 +0000 | [diff] [blame] | 17 | #include <stdint.h> |
| 18 | #include <arch/io.h> |
Jonathan Kollasch | d8bed0a | 2010-10-27 17:26:57 +0000 | [diff] [blame] | 19 | #include <console/console.h> |
| 20 | #include <device/pci_def.h> |
| 21 | #include <device/pci_ids.h> |
| 22 | |
stepan | 836ae29 | 2010-12-08 05:42:47 +0000 | [diff] [blame] | 23 | #include "smbus.h" |
| 24 | #include "early_smbus.h" |
arch import user (historical) | 98d0d30 | 2005-07-06 17:13:46 +0000 | [diff] [blame] | 25 | |
Jonathan Kollasch | d8bed0a | 2010-10-27 17:26:57 +0000 | [diff] [blame] | 26 | #define SMBUS_BAR_BASE 0x20 |
arch import user (historical) | 98d0d30 | 2005-07-06 17:13:46 +0000 | [diff] [blame] | 27 | #define SMBUS_IO_BASE 0x1000 |
Jonathan Kollasch | d8bed0a | 2010-10-27 17:26:57 +0000 | [diff] [blame] | 28 | #define SMBUS_IO_SIZE 0x0040 |
arch import user (historical) | 98d0d30 | 2005-07-06 17:13:46 +0000 | [diff] [blame] | 29 | |
Jonathan Kollasch | d8bed0a | 2010-10-27 17:26:57 +0000 | [diff] [blame] | 30 | #define SMBUS_BAR(x) (SMBUS_BAR_BASE + 4 * (x)) |
| 31 | #define SMBUS_BASE(x) (SMBUS_IO_BASE + SMBUS_IO_SIZE * (x)) |
| 32 | |
| 33 | void enable_smbus(void) |
arch import user (historical) | 98d0d30 | 2005-07-06 17:13:46 +0000 | [diff] [blame] | 34 | { |
| 35 | device_t dev; |
Jonathan Kollasch | d8bed0a | 2010-10-27 17:26:57 +0000 | [diff] [blame] | 36 | |
| 37 | dev = pci_locate_device(PCI_ID(PCI_VENDOR_ID_NVIDIA, |
| 38 | PCI_DEVICE_ID_NVIDIA_CK804_SMB), 0); |
Uwe Hermann | 7f3d48c | 2008-10-02 18:19:17 +0000 | [diff] [blame] | 39 | if (dev == PCI_DEV_INVALID) |
Stefan Reinauer | 64ed2b7 | 2010-03-31 14:47:43 +0000 | [diff] [blame] | 40 | die("SMBus controller not found\n"); |
Myles Watson | 64caf36 | 2008-09-18 16:27:00 +0000 | [diff] [blame] | 41 | |
Uwe Hermann | 7f3d48c | 2008-10-02 18:19:17 +0000 | [diff] [blame] | 42 | /* Set SMBus I/O base. */ |
Jonathan Kollasch | d8bed0a | 2010-10-27 17:26:57 +0000 | [diff] [blame] | 43 | pci_write_config32(dev, SMBUS_BAR(0), SMBUS_BASE(0) | 1); |
| 44 | pci_write_config32(dev, SMBUS_BAR(1), SMBUS_BASE(1) | 1); |
Uwe Hermann | 7f3d48c | 2008-10-02 18:19:17 +0000 | [diff] [blame] | 45 | |
| 46 | /* Set SMBus I/O space enable. */ |
arch import user (historical) | 98d0d30 | 2005-07-06 17:13:46 +0000 | [diff] [blame] | 47 | pci_write_config16(dev, 0x4, 0x01); |
Uwe Hermann | 7f3d48c | 2008-10-02 18:19:17 +0000 | [diff] [blame] | 48 | |
| 49 | /* Clear any lingering errors, so the transaction will run. */ |
Jonathan Kollasch | d8bed0a | 2010-10-27 17:26:57 +0000 | [diff] [blame] | 50 | outb(inb(SMBUS_BASE(0) + SMBHSTSTAT), SMBUS_BASE(0) + SMBHSTSTAT); |
| 51 | outb(inb(SMBUS_BASE(1) + SMBHSTSTAT), SMBUS_BASE(1) + SMBHSTSTAT); |
| 52 | |
Stefan Reinauer | 5ab52dd | 2015-01-05 13:01:01 -0800 | [diff] [blame] | 53 | printk(BIOS_DEBUG, "SMBus controller enabled\n"); |
arch import user (historical) | 98d0d30 | 2005-07-06 17:13:46 +0000 | [diff] [blame] | 54 | } |
| 55 | |
Jonathan Kollasch | d8bed0a | 2010-10-27 17:26:57 +0000 | [diff] [blame] | 56 | int ck804_smbus_read_byte(unsigned bus, unsigned device, unsigned address) |
arch import user (historical) | 98d0d30 | 2005-07-06 17:13:46 +0000 | [diff] [blame] | 57 | { |
Jonathan Kollasch | d8bed0a | 2010-10-27 17:26:57 +0000 | [diff] [blame] | 58 | return do_smbus_read_byte(SMBUS_BASE(bus), device, address); |
arch import user (historical) | 98d0d30 | 2005-07-06 17:13:46 +0000 | [diff] [blame] | 59 | } |
Uwe Hermann | 7f3d48c | 2008-10-02 18:19:17 +0000 | [diff] [blame] | 60 | |
Jonathan Kollasch | d8bed0a | 2010-10-27 17:26:57 +0000 | [diff] [blame] | 61 | int ck804_smbus_write_byte(unsigned bus, unsigned device, unsigned address, |
Uwe Hermann | 7e2fbd5 | 2011-01-04 17:36:55 +0000 | [diff] [blame] | 62 | unsigned char val) |
arch import user (historical) | 98d0d30 | 2005-07-06 17:13:46 +0000 | [diff] [blame] | 63 | { |
Jonathan Kollasch | d8bed0a | 2010-10-27 17:26:57 +0000 | [diff] [blame] | 64 | return do_smbus_write_byte(SMBUS_BASE(bus), device, address, val); |
| 65 | } |
| 66 | |
| 67 | int smbus_read_byte(unsigned device, unsigned address) |
| 68 | { |
| 69 | return ck804_smbus_read_byte(0, device, address); |
| 70 | } |
| 71 | |
| 72 | int 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) | 98d0d30 | 2005-07-06 17:13:46 +0000 | [diff] [blame] | 75 | } |