2005-04-17 00:20:36 +02:00
|
|
|
/*
|
|
|
|
* SMBus 2.0 driver for AMD-8111 IO-Hub.
|
|
|
|
*
|
|
|
|
* Copyright (c) 2002 Vojtech Pavlik
|
|
|
|
*
|
|
|
|
* This program is free software; you can redistribute it and/or modify
|
|
|
|
* it under the terms of the GNU General Public License as published by
|
|
|
|
* the Free Software Foundation version 2.
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include <linux/module.h>
|
|
|
|
#include <linux/pci.h>
|
|
|
|
#include <linux/kernel.h>
|
|
|
|
#include <linux/stddef.h>
|
|
|
|
#include <linux/ioport.h>
|
|
|
|
#include <linux/i2c.h>
|
|
|
|
#include <linux/delay.h>
|
2008-07-14 22:38:33 +02:00
|
|
|
#include <linux/acpi.h>
|
include cleanup: Update gfp.h and slab.h includes to prepare for breaking implicit slab.h inclusion from percpu.h
percpu.h is included by sched.h and module.h and thus ends up being
included when building most .c files. percpu.h includes slab.h which
in turn includes gfp.h making everything defined by the two files
universally available and complicating inclusion dependencies.
percpu.h -> slab.h dependency is about to be removed. Prepare for
this change by updating users of gfp and slab facilities include those
headers directly instead of assuming availability. As this conversion
needs to touch large number of source files, the following script is
used as the basis of conversion.
http://userweb.kernel.org/~tj/misc/slabh-sweep.py
The script does the followings.
* Scan files for gfp and slab usages and update includes such that
only the necessary includes are there. ie. if only gfp is used,
gfp.h, if slab is used, slab.h.
* When the script inserts a new include, it looks at the include
blocks and try to put the new include such that its order conforms
to its surrounding. It's put in the include block which contains
core kernel includes, in the same order that the rest are ordered -
alphabetical, Christmas tree, rev-Xmas-tree or at the end if there
doesn't seem to be any matching order.
* If the script can't find a place to put a new include (mostly
because the file doesn't have fitting include block), it prints out
an error message indicating which .h file needs to be added to the
file.
The conversion was done in the following steps.
1. The initial automatic conversion of all .c files updated slightly
over 4000 files, deleting around 700 includes and adding ~480 gfp.h
and ~3000 slab.h inclusions. The script emitted errors for ~400
files.
2. Each error was manually checked. Some didn't need the inclusion,
some needed manual addition while adding it to implementation .h or
embedding .c file was more appropriate for others. This step added
inclusions to around 150 files.
3. The script was run again and the output was compared to the edits
from #2 to make sure no file was left behind.
4. Several build tests were done and a couple of problems were fixed.
e.g. lib/decompress_*.c used malloc/free() wrappers around slab
APIs requiring slab.h to be added manually.
5. The script was run on all .h files but without automatically
editing them as sprinkling gfp.h and slab.h inclusions around .h
files could easily lead to inclusion dependency hell. Most gfp.h
inclusion directives were ignored as stuff from gfp.h was usually
wildly available and often used in preprocessor macros. Each
slab.h inclusion directive was examined and added manually as
necessary.
6. percpu.h was updated not to include slab.h.
7. Build test were done on the following configurations and failures
were fixed. CONFIG_GCOV_KERNEL was turned off for all tests (as my
distributed build env didn't work with gcov compiles) and a few
more options had to be turned off depending on archs to make things
build (like ipr on powerpc/64 which failed due to missing writeq).
* x86 and x86_64 UP and SMP allmodconfig and a custom test config.
* powerpc and powerpc64 SMP allmodconfig
* sparc and sparc64 SMP allmodconfig
* ia64 SMP allmodconfig
* s390 SMP allmodconfig
* alpha SMP allmodconfig
* um on x86_64 SMP allmodconfig
8. percpu.h modifications were reverted so that it could be applied as
a separate patch and serve as bisection point.
Given the fact that I had only a couple of failures from tests on step
6, I'm fairly confident about the coverage of this conversion patch.
If there is a breakage, it's likely to be something in one of the arch
headers which should be easily discoverable easily on most builds of
the specific arch.
Signed-off-by: Tejun Heo <tj@kernel.org>
Guess-its-ok-by: Christoph Lameter <cl@linux-foundation.org>
Cc: Ingo Molnar <mingo@redhat.com>
Cc: Lee Schermerhorn <Lee.Schermerhorn@hp.com>
2010-03-24 09:04:11 +01:00
|
|
|
#include <linux/slab.h>
|
2010-05-21 18:41:01 +02:00
|
|
|
#include <linux/io.h>
|
2005-04-17 00:20:36 +02:00
|
|
|
|
|
|
|
MODULE_LICENSE("GPL");
|
|
|
|
MODULE_AUTHOR ("Vojtech Pavlik <vojtech@suse.cz>");
|
|
|
|
MODULE_DESCRIPTION("AMD8111 SMBus 2.0 driver");
|
|
|
|
|
|
|
|
struct amd_smbus {
|
|
|
|
struct pci_dev *dev;
|
|
|
|
struct i2c_adapter adapter;
|
|
|
|
int base;
|
|
|
|
int size;
|
|
|
|
};
|
|
|
|
|
2005-09-25 16:37:04 +02:00
|
|
|
static struct pci_driver amd8111_driver;
|
|
|
|
|
2005-04-17 00:20:36 +02:00
|
|
|
/*
|
|
|
|
* AMD PCI control registers definitions.
|
|
|
|
*/
|
|
|
|
|
|
|
|
#define AMD_PCI_MISC 0x48
|
|
|
|
|
|
|
|
#define AMD_PCI_MISC_SCI 0x04 /* deliver SCI */
|
|
|
|
#define AMD_PCI_MISC_INT 0x02 /* deliver PCI IRQ */
|
|
|
|
#define AMD_PCI_MISC_SPEEDUP 0x01 /* 16x clock speedup */
|
|
|
|
|
|
|
|
/*
|
|
|
|
* ACPI 2.0 chapter 13 PCI interface definitions.
|
|
|
|
*/
|
|
|
|
|
|
|
|
#define AMD_EC_DATA 0x00 /* data register */
|
|
|
|
#define AMD_EC_SC 0x04 /* status of controller */
|
|
|
|
#define AMD_EC_CMD 0x04 /* command register */
|
|
|
|
#define AMD_EC_ICR 0x08 /* interrupt control register */
|
|
|
|
|
|
|
|
#define AMD_EC_SC_SMI 0x04 /* smi event pending */
|
|
|
|
#define AMD_EC_SC_SCI 0x02 /* sci event pending */
|
|
|
|
#define AMD_EC_SC_BURST 0x01 /* burst mode enabled */
|
|
|
|
#define AMD_EC_SC_CMD 0x08 /* byte in data reg is command */
|
|
|
|
#define AMD_EC_SC_IBF 0x02 /* data ready for embedded controller */
|
|
|
|
#define AMD_EC_SC_OBF 0x01 /* data ready for host */
|
|
|
|
|
|
|
|
#define AMD_EC_CMD_RD 0x80 /* read EC */
|
|
|
|
#define AMD_EC_CMD_WR 0x81 /* write EC */
|
|
|
|
#define AMD_EC_CMD_BE 0x82 /* enable burst mode */
|
|
|
|
#define AMD_EC_CMD_BD 0x83 /* disable burst mode */
|
|
|
|
#define AMD_EC_CMD_QR 0x84 /* query EC */
|
|
|
|
|
|
|
|
/*
|
|
|
|
* ACPI 2.0 chapter 13 access of registers of the EC
|
|
|
|
*/
|
|
|
|
|
2010-10-24 18:16:58 +02:00
|
|
|
static int amd_ec_wait_write(struct amd_smbus *smbus)
|
2005-04-17 00:20:36 +02:00
|
|
|
{
|
|
|
|
int timeout = 500;
|
|
|
|
|
2009-02-24 19:19:48 +01:00
|
|
|
while ((inb(smbus->base + AMD_EC_SC) & AMD_EC_SC_IBF) && --timeout)
|
2005-04-17 00:20:36 +02:00
|
|
|
udelay(1);
|
|
|
|
|
|
|
|
if (!timeout) {
|
2007-02-13 22:09:02 +01:00
|
|
|
dev_warn(&smbus->dev->dev,
|
|
|
|
"Timeout while waiting for IBF to clear\n");
|
2008-07-14 22:38:25 +02:00
|
|
|
return -ETIMEDOUT;
|
2005-04-17 00:20:36 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2010-10-24 18:16:58 +02:00
|
|
|
static int amd_ec_wait_read(struct amd_smbus *smbus)
|
2005-04-17 00:20:36 +02:00
|
|
|
{
|
|
|
|
int timeout = 500;
|
|
|
|
|
2009-02-24 19:19:48 +01:00
|
|
|
while ((~inb(smbus->base + AMD_EC_SC) & AMD_EC_SC_OBF) && --timeout)
|
2005-04-17 00:20:36 +02:00
|
|
|
udelay(1);
|
|
|
|
|
|
|
|
if (!timeout) {
|
2007-02-13 22:09:02 +01:00
|
|
|
dev_warn(&smbus->dev->dev,
|
|
|
|
"Timeout while waiting for OBF to set\n");
|
2008-07-14 22:38:25 +02:00
|
|
|
return -ETIMEDOUT;
|
2005-04-17 00:20:36 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2010-10-24 18:16:58 +02:00
|
|
|
static int amd_ec_read(struct amd_smbus *smbus, unsigned char address,
|
2007-02-13 22:09:02 +01:00
|
|
|
unsigned char *data)
|
2005-04-17 00:20:36 +02:00
|
|
|
{
|
2008-07-14 22:38:25 +02:00
|
|
|
int status;
|
|
|
|
|
|
|
|
status = amd_ec_wait_write(smbus);
|
|
|
|
if (status)
|
|
|
|
return status;
|
2005-04-17 00:20:36 +02:00
|
|
|
outb(AMD_EC_CMD_RD, smbus->base + AMD_EC_CMD);
|
|
|
|
|
2008-07-14 22:38:25 +02:00
|
|
|
status = amd_ec_wait_write(smbus);
|
|
|
|
if (status)
|
|
|
|
return status;
|
2005-04-17 00:20:36 +02:00
|
|
|
outb(address, smbus->base + AMD_EC_DATA);
|
|
|
|
|
2008-07-14 22:38:25 +02:00
|
|
|
status = amd_ec_wait_read(smbus);
|
|
|
|
if (status)
|
|
|
|
return status;
|
2005-04-17 00:20:36 +02:00
|
|
|
*data = inb(smbus->base + AMD_EC_DATA);
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2010-10-24 18:16:58 +02:00
|
|
|
static int amd_ec_write(struct amd_smbus *smbus, unsigned char address,
|
2007-02-13 22:09:02 +01:00
|
|
|
unsigned char data)
|
2005-04-17 00:20:36 +02:00
|
|
|
{
|
2008-07-14 22:38:25 +02:00
|
|
|
int status;
|
|
|
|
|
|
|
|
status = amd_ec_wait_write(smbus);
|
|
|
|
if (status)
|
|
|
|
return status;
|
2005-04-17 00:20:36 +02:00
|
|
|
outb(AMD_EC_CMD_WR, smbus->base + AMD_EC_CMD);
|
|
|
|
|
2008-07-14 22:38:25 +02:00
|
|
|
status = amd_ec_wait_write(smbus);
|
|
|
|
if (status)
|
|
|
|
return status;
|
2005-04-17 00:20:36 +02:00
|
|
|
outb(address, smbus->base + AMD_EC_DATA);
|
|
|
|
|
2008-07-14 22:38:25 +02:00
|
|
|
status = amd_ec_wait_write(smbus);
|
|
|
|
if (status)
|
|
|
|
return status;
|
2005-04-17 00:20:36 +02:00
|
|
|
outb(data, smbus->base + AMD_EC_DATA);
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* ACPI 2.0 chapter 13 SMBus 2.0 EC register model
|
|
|
|
*/
|
|
|
|
|
|
|
|
#define AMD_SMB_PRTCL 0x00 /* protocol, PEC */
|
|
|
|
#define AMD_SMB_STS 0x01 /* status */
|
|
|
|
#define AMD_SMB_ADDR 0x02 /* address */
|
|
|
|
#define AMD_SMB_CMD 0x03 /* command */
|
|
|
|
#define AMD_SMB_DATA 0x04 /* 32 data registers */
|
|
|
|
#define AMD_SMB_BCNT 0x24 /* number of data bytes */
|
|
|
|
#define AMD_SMB_ALRM_A 0x25 /* alarm address */
|
|
|
|
#define AMD_SMB_ALRM_D 0x26 /* 2 bytes alarm data */
|
|
|
|
|
|
|
|
#define AMD_SMB_STS_DONE 0x80
|
|
|
|
#define AMD_SMB_STS_ALRM 0x40
|
|
|
|
#define AMD_SMB_STS_RES 0x20
|
|
|
|
#define AMD_SMB_STS_STATUS 0x1f
|
|
|
|
|
|
|
|
#define AMD_SMB_STATUS_OK 0x00
|
|
|
|
#define AMD_SMB_STATUS_FAIL 0x07
|
|
|
|
#define AMD_SMB_STATUS_DNAK 0x10
|
|
|
|
#define AMD_SMB_STATUS_DERR 0x11
|
|
|
|
#define AMD_SMB_STATUS_CMD_DENY 0x12
|
|
|
|
#define AMD_SMB_STATUS_UNKNOWN 0x13
|
|
|
|
#define AMD_SMB_STATUS_ACC_DENY 0x17
|
|
|
|
#define AMD_SMB_STATUS_TIMEOUT 0x18
|
|
|
|
#define AMD_SMB_STATUS_NOTSUP 0x19
|
|
|
|
#define AMD_SMB_STATUS_BUSY 0x1A
|
|
|
|
#define AMD_SMB_STATUS_PEC 0x1F
|
|
|
|
|
|
|
|
#define AMD_SMB_PRTCL_WRITE 0x00
|
|
|
|
#define AMD_SMB_PRTCL_READ 0x01
|
|
|
|
#define AMD_SMB_PRTCL_QUICK 0x02
|
|
|
|
#define AMD_SMB_PRTCL_BYTE 0x04
|
|
|
|
#define AMD_SMB_PRTCL_BYTE_DATA 0x06
|
|
|
|
#define AMD_SMB_PRTCL_WORD_DATA 0x08
|
|
|
|
#define AMD_SMB_PRTCL_BLOCK_DATA 0x0a
|
|
|
|
#define AMD_SMB_PRTCL_PROC_CALL 0x0c
|
|
|
|
#define AMD_SMB_PRTCL_BLOCK_PROC_CALL 0x0d
|
|
|
|
#define AMD_SMB_PRTCL_I2C_BLOCK_DATA 0x4a
|
|
|
|
#define AMD_SMB_PRTCL_PEC 0x80
|
|
|
|
|
|
|
|
|
2007-02-13 22:09:02 +01:00
|
|
|
static s32 amd8111_access(struct i2c_adapter * adap, u16 addr,
|
|
|
|
unsigned short flags, char read_write, u8 command, int size,
|
|
|
|
union i2c_smbus_data * data)
|
2005-04-17 00:20:36 +02:00
|
|
|
{
|
|
|
|
struct amd_smbus *smbus = adap->algo_data;
|
|
|
|
unsigned char protocol, len, pec, temp[2];
|
2010-10-24 18:16:58 +02:00
|
|
|
int i, status;
|
2005-04-17 00:20:36 +02:00
|
|
|
|
2007-02-13 22:09:02 +01:00
|
|
|
protocol = (read_write == I2C_SMBUS_READ) ? AMD_SMB_PRTCL_READ
|
|
|
|
: AMD_SMB_PRTCL_WRITE;
|
2005-04-17 00:20:36 +02:00
|
|
|
pec = (flags & I2C_CLIENT_PEC) ? AMD_SMB_PRTCL_PEC : 0;
|
|
|
|
|
|
|
|
switch (size) {
|
|
|
|
case I2C_SMBUS_QUICK:
|
|
|
|
protocol |= AMD_SMB_PRTCL_QUICK;
|
|
|
|
read_write = I2C_SMBUS_WRITE;
|
|
|
|
break;
|
|
|
|
|
|
|
|
case I2C_SMBUS_BYTE:
|
2010-10-24 18:16:58 +02:00
|
|
|
if (read_write == I2C_SMBUS_WRITE) {
|
|
|
|
status = amd_ec_write(smbus, AMD_SMB_CMD,
|
|
|
|
command);
|
|
|
|
if (status)
|
|
|
|
return status;
|
|
|
|
}
|
2005-04-17 00:20:36 +02:00
|
|
|
protocol |= AMD_SMB_PRTCL_BYTE;
|
|
|
|
break;
|
|
|
|
|
|
|
|
case I2C_SMBUS_BYTE_DATA:
|
2010-10-24 18:16:58 +02:00
|
|
|
status = amd_ec_write(smbus, AMD_SMB_CMD, command);
|
|
|
|
if (status)
|
|
|
|
return status;
|
|
|
|
if (read_write == I2C_SMBUS_WRITE) {
|
|
|
|
status = amd_ec_write(smbus, AMD_SMB_DATA,
|
|
|
|
data->byte);
|
|
|
|
if (status)
|
|
|
|
return status;
|
|
|
|
}
|
2005-04-17 00:20:36 +02:00
|
|
|
protocol |= AMD_SMB_PRTCL_BYTE_DATA;
|
|
|
|
break;
|
|
|
|
|
|
|
|
case I2C_SMBUS_WORD_DATA:
|
2010-10-24 18:16:58 +02:00
|
|
|
status = amd_ec_write(smbus, AMD_SMB_CMD, command);
|
|
|
|
if (status)
|
|
|
|
return status;
|
2005-04-17 00:20:36 +02:00
|
|
|
if (read_write == I2C_SMBUS_WRITE) {
|
2010-10-24 18:16:58 +02:00
|
|
|
status = amd_ec_write(smbus, AMD_SMB_DATA,
|
|
|
|
data->word & 0xff);
|
|
|
|
if (status)
|
|
|
|
return status;
|
|
|
|
status = amd_ec_write(smbus, AMD_SMB_DATA + 1,
|
|
|
|
data->word >> 8);
|
|
|
|
if (status)
|
|
|
|
return status;
|
2005-04-17 00:20:36 +02:00
|
|
|
}
|
|
|
|
protocol |= AMD_SMB_PRTCL_WORD_DATA | pec;
|
|
|
|
break;
|
|
|
|
|
|
|
|
case I2C_SMBUS_BLOCK_DATA:
|
2010-10-24 18:16:58 +02:00
|
|
|
status = amd_ec_write(smbus, AMD_SMB_CMD, command);
|
|
|
|
if (status)
|
|
|
|
return status;
|
2005-04-17 00:20:36 +02:00
|
|
|
if (read_write == I2C_SMBUS_WRITE) {
|
2007-02-13 22:09:02 +01:00
|
|
|
len = min_t(u8, data->block[0],
|
|
|
|
I2C_SMBUS_BLOCK_MAX);
|
2010-10-24 18:16:58 +02:00
|
|
|
status = amd_ec_write(smbus, AMD_SMB_BCNT, len);
|
|
|
|
if (status)
|
|
|
|
return status;
|
|
|
|
for (i = 0; i < len; i++) {
|
|
|
|
status =
|
|
|
|
amd_ec_write(smbus, AMD_SMB_DATA + i,
|
|
|
|
data->block[i + 1]);
|
|
|
|
if (status)
|
|
|
|
return status;
|
|
|
|
}
|
2005-04-17 00:20:36 +02:00
|
|
|
}
|
|
|
|
protocol |= AMD_SMB_PRTCL_BLOCK_DATA | pec;
|
|
|
|
break;
|
|
|
|
|
|
|
|
case I2C_SMBUS_I2C_BLOCK_DATA:
|
2007-02-13 22:09:02 +01:00
|
|
|
len = min_t(u8, data->block[0],
|
|
|
|
I2C_SMBUS_BLOCK_MAX);
|
2010-10-24 18:16:58 +02:00
|
|
|
status = amd_ec_write(smbus, AMD_SMB_CMD, command);
|
|
|
|
if (status)
|
|
|
|
return status;
|
|
|
|
status = amd_ec_write(smbus, AMD_SMB_BCNT, len);
|
|
|
|
if (status)
|
|
|
|
return status;
|
2005-04-17 00:20:36 +02:00
|
|
|
if (read_write == I2C_SMBUS_WRITE)
|
2010-10-24 18:16:58 +02:00
|
|
|
for (i = 0; i < len; i++) {
|
|
|
|
status =
|
|
|
|
amd_ec_write(smbus, AMD_SMB_DATA + i,
|
|
|
|
data->block[i + 1]);
|
|
|
|
if (status)
|
|
|
|
return status;
|
|
|
|
}
|
2005-04-17 00:20:36 +02:00
|
|
|
protocol |= AMD_SMB_PRTCL_I2C_BLOCK_DATA;
|
|
|
|
break;
|
|
|
|
|
|
|
|
case I2C_SMBUS_PROC_CALL:
|
2010-10-24 18:16:58 +02:00
|
|
|
status = amd_ec_write(smbus, AMD_SMB_CMD, command);
|
|
|
|
if (status)
|
|
|
|
return status;
|
|
|
|
status = amd_ec_write(smbus, AMD_SMB_DATA,
|
|
|
|
data->word & 0xff);
|
|
|
|
if (status)
|
|
|
|
return status;
|
|
|
|
status = amd_ec_write(smbus, AMD_SMB_DATA + 1,
|
|
|
|
data->word >> 8);
|
|
|
|
if (status)
|
|
|
|
return status;
|
2005-04-17 00:20:36 +02:00
|
|
|
protocol = AMD_SMB_PRTCL_PROC_CALL | pec;
|
|
|
|
read_write = I2C_SMBUS_READ;
|
|
|
|
break;
|
|
|
|
|
|
|
|
case I2C_SMBUS_BLOCK_PROC_CALL:
|
2007-03-22 19:49:00 +01:00
|
|
|
len = min_t(u8, data->block[0],
|
|
|
|
I2C_SMBUS_BLOCK_MAX - 1);
|
2010-10-24 18:16:58 +02:00
|
|
|
status = amd_ec_write(smbus, AMD_SMB_CMD, command);
|
|
|
|
if (status)
|
|
|
|
return status;
|
|
|
|
status = amd_ec_write(smbus, AMD_SMB_BCNT, len);
|
|
|
|
if (status)
|
|
|
|
return status;
|
|
|
|
for (i = 0; i < len; i++) {
|
|
|
|
status = amd_ec_write(smbus, AMD_SMB_DATA + i,
|
|
|
|
data->block[i + 1]);
|
|
|
|
if (status)
|
|
|
|
return status;
|
|
|
|
}
|
2005-04-17 00:20:36 +02:00
|
|
|
protocol = AMD_SMB_PRTCL_BLOCK_PROC_CALL | pec;
|
|
|
|
read_write = I2C_SMBUS_READ;
|
|
|
|
break;
|
|
|
|
|
|
|
|
default:
|
|
|
|
dev_warn(&adap->dev, "Unsupported transaction %d\n", size);
|
2008-07-14 22:38:25 +02:00
|
|
|
return -EOPNOTSUPP;
|
2005-04-17 00:20:36 +02:00
|
|
|
}
|
|
|
|
|
2010-10-24 18:16:58 +02:00
|
|
|
status = amd_ec_write(smbus, AMD_SMB_ADDR, addr << 1);
|
|
|
|
if (status)
|
|
|
|
return status;
|
|
|
|
status = amd_ec_write(smbus, AMD_SMB_PRTCL, protocol);
|
|
|
|
if (status)
|
|
|
|
return status;
|
2005-04-17 00:20:36 +02:00
|
|
|
|
2010-10-24 18:16:58 +02:00
|
|
|
status = amd_ec_read(smbus, AMD_SMB_STS, temp + 0);
|
|
|
|
if (status)
|
|
|
|
return status;
|
2005-04-17 00:20:36 +02:00
|
|
|
|
|
|
|
if (~temp[0] & AMD_SMB_STS_DONE) {
|
|
|
|
udelay(500);
|
2010-10-24 18:16:58 +02:00
|
|
|
status = amd_ec_read(smbus, AMD_SMB_STS, temp + 0);
|
|
|
|
if (status)
|
|
|
|
return status;
|
2005-04-17 00:20:36 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
if (~temp[0] & AMD_SMB_STS_DONE) {
|
|
|
|
msleep(1);
|
2010-10-24 18:16:58 +02:00
|
|
|
status = amd_ec_read(smbus, AMD_SMB_STS, temp + 0);
|
|
|
|
if (status)
|
|
|
|
return status;
|
2005-04-17 00:20:36 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
if ((~temp[0] & AMD_SMB_STS_DONE) || (temp[0] & AMD_SMB_STS_STATUS))
|
2008-07-14 22:38:25 +02:00
|
|
|
return -EIO;
|
2005-04-17 00:20:36 +02:00
|
|
|
|
|
|
|
if (read_write == I2C_SMBUS_WRITE)
|
|
|
|
return 0;
|
|
|
|
|
|
|
|
switch (size) {
|
|
|
|
case I2C_SMBUS_BYTE:
|
|
|
|
case I2C_SMBUS_BYTE_DATA:
|
2010-10-24 18:16:58 +02:00
|
|
|
status = amd_ec_read(smbus, AMD_SMB_DATA, &data->byte);
|
|
|
|
if (status)
|
|
|
|
return status;
|
2005-04-17 00:20:36 +02:00
|
|
|
break;
|
|
|
|
|
|
|
|
case I2C_SMBUS_WORD_DATA:
|
|
|
|
case I2C_SMBUS_PROC_CALL:
|
2010-10-24 18:16:58 +02:00
|
|
|
status = amd_ec_read(smbus, AMD_SMB_DATA, temp + 0);
|
|
|
|
if (status)
|
|
|
|
return status;
|
|
|
|
status = amd_ec_read(smbus, AMD_SMB_DATA + 1, temp + 1);
|
|
|
|
if (status)
|
|
|
|
return status;
|
2005-04-17 00:20:36 +02:00
|
|
|
data->word = (temp[1] << 8) | temp[0];
|
|
|
|
break;
|
|
|
|
|
|
|
|
case I2C_SMBUS_BLOCK_DATA:
|
|
|
|
case I2C_SMBUS_BLOCK_PROC_CALL:
|
2010-10-24 18:16:58 +02:00
|
|
|
status = amd_ec_read(smbus, AMD_SMB_BCNT, &len);
|
|
|
|
if (status)
|
|
|
|
return status;
|
2007-02-13 22:09:02 +01:00
|
|
|
len = min_t(u8, len, I2C_SMBUS_BLOCK_MAX);
|
2005-04-17 00:20:36 +02:00
|
|
|
case I2C_SMBUS_I2C_BLOCK_DATA:
|
2010-10-24 18:16:58 +02:00
|
|
|
for (i = 0; i < len; i++) {
|
|
|
|
status = amd_ec_read(smbus, AMD_SMB_DATA + i,
|
|
|
|
data->block + i + 1);
|
|
|
|
if (status)
|
|
|
|
return status;
|
|
|
|
}
|
2005-04-17 00:20:36 +02:00
|
|
|
data->block[0] = len;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
static u32 amd8111_func(struct i2c_adapter *adapter)
|
|
|
|
{
|
2007-02-13 22:09:02 +01:00
|
|
|
return I2C_FUNC_SMBUS_QUICK | I2C_FUNC_SMBUS_BYTE |
|
|
|
|
I2C_FUNC_SMBUS_BYTE_DATA |
|
2005-04-17 00:20:36 +02:00
|
|
|
I2C_FUNC_SMBUS_WORD_DATA | I2C_FUNC_SMBUS_BLOCK_DATA |
|
|
|
|
I2C_FUNC_SMBUS_PROC_CALL | I2C_FUNC_SMBUS_BLOCK_PROC_CALL |
|
2007-10-13 23:56:33 +02:00
|
|
|
I2C_FUNC_SMBUS_I2C_BLOCK | I2C_FUNC_SMBUS_PEC;
|
2005-04-17 00:20:36 +02:00
|
|
|
}
|
|
|
|
|
2006-09-03 22:39:46 +02:00
|
|
|
static const struct i2c_algorithm smbus_algorithm = {
|
2005-04-17 00:20:36 +02:00
|
|
|
.smbus_xfer = amd8111_access,
|
|
|
|
.functionality = amd8111_func,
|
|
|
|
};
|
|
|
|
|
|
|
|
|
2013-12-03 00:11:20 +01:00
|
|
|
static const struct pci_device_id amd8111_ids[] = {
|
2005-04-17 00:20:36 +02:00
|
|
|
{ PCI_DEVICE(PCI_VENDOR_ID_AMD, PCI_DEVICE_ID_AMD_8111_SMBUS2) },
|
|
|
|
{ 0, }
|
|
|
|
};
|
|
|
|
|
|
|
|
MODULE_DEVICE_TABLE (pci, amd8111_ids);
|
|
|
|
|
2012-11-27 21:59:38 +01:00
|
|
|
static int amd8111_probe(struct pci_dev *dev, const struct pci_device_id *id)
|
2005-04-17 00:20:36 +02:00
|
|
|
{
|
|
|
|
struct amd_smbus *smbus;
|
2007-02-13 22:09:02 +01:00
|
|
|
int error;
|
2005-04-17 00:20:36 +02:00
|
|
|
|
2007-02-13 22:09:02 +01:00
|
|
|
if (!(pci_resource_flags(dev, 0) & IORESOURCE_IO))
|
2005-04-17 00:20:36 +02:00
|
|
|
return -ENODEV;
|
|
|
|
|
2005-10-17 23:09:43 +02:00
|
|
|
smbus = kzalloc(sizeof(struct amd_smbus), GFP_KERNEL);
|
2005-04-17 00:20:36 +02:00
|
|
|
if (!smbus)
|
|
|
|
return -ENOMEM;
|
|
|
|
|
|
|
|
smbus->dev = dev;
|
|
|
|
smbus->base = pci_resource_start(dev, 0);
|
|
|
|
smbus->size = pci_resource_len(dev, 0);
|
|
|
|
|
2008-07-14 22:38:33 +02:00
|
|
|
error = acpi_check_resource_conflict(&dev->resource[0]);
|
2009-10-04 22:53:45 +02:00
|
|
|
if (error) {
|
|
|
|
error = -ENODEV;
|
2008-07-14 22:38:33 +02:00
|
|
|
goto out_kfree;
|
2009-10-04 22:53:45 +02:00
|
|
|
}
|
2008-07-14 22:38:33 +02:00
|
|
|
|
2007-02-13 22:09:02 +01:00
|
|
|
if (!request_region(smbus->base, smbus->size, amd8111_driver.name)) {
|
|
|
|
error = -EBUSY;
|
2005-04-17 00:20:36 +02:00
|
|
|
goto out_kfree;
|
2007-02-13 22:09:02 +01:00
|
|
|
}
|
2005-04-17 00:20:36 +02:00
|
|
|
|
|
|
|
smbus->adapter.owner = THIS_MODULE;
|
2007-05-01 23:26:28 +02:00
|
|
|
snprintf(smbus->adapter.name, sizeof(smbus->adapter.name),
|
2005-04-17 00:20:36 +02:00
|
|
|
"SMBus2 AMD8111 adapter at %04x", smbus->base);
|
2008-07-14 22:38:29 +02:00
|
|
|
smbus->adapter.class = I2C_CLASS_HWMON | I2C_CLASS_SPD;
|
2005-04-17 00:20:36 +02:00
|
|
|
smbus->adapter.algo = &smbus_algorithm;
|
|
|
|
smbus->adapter.algo_data = smbus;
|
|
|
|
|
2007-02-17 19:13:42 +01:00
|
|
|
/* set up the sysfs linkage to our parent device */
|
2005-04-17 00:20:36 +02:00
|
|
|
smbus->adapter.dev.parent = &dev->dev;
|
|
|
|
|
2007-02-13 22:09:02 +01:00
|
|
|
pci_write_config_dword(smbus->dev, AMD_PCI_MISC, 0);
|
2005-04-17 00:20:36 +02:00
|
|
|
error = i2c_add_adapter(&smbus->adapter);
|
|
|
|
if (error)
|
|
|
|
goto out_release_region;
|
|
|
|
|
|
|
|
pci_set_drvdata(dev, smbus);
|
|
|
|
return 0;
|
|
|
|
|
|
|
|
out_release_region:
|
|
|
|
release_region(smbus->base, smbus->size);
|
|
|
|
out_kfree:
|
|
|
|
kfree(smbus);
|
2007-02-13 22:09:02 +01:00
|
|
|
return error;
|
2005-04-17 00:20:36 +02:00
|
|
|
}
|
|
|
|
|
2012-11-27 21:59:38 +01:00
|
|
|
static void amd8111_remove(struct pci_dev *dev)
|
2005-04-17 00:20:36 +02:00
|
|
|
{
|
|
|
|
struct amd_smbus *smbus = pci_get_drvdata(dev);
|
|
|
|
|
|
|
|
i2c_del_adapter(&smbus->adapter);
|
|
|
|
release_region(smbus->base, smbus->size);
|
|
|
|
kfree(smbus);
|
|
|
|
}
|
|
|
|
|
|
|
|
static struct pci_driver amd8111_driver = {
|
|
|
|
.name = "amd8111_smbus2",
|
|
|
|
.id_table = amd8111_ids,
|
|
|
|
.probe = amd8111_probe,
|
2012-11-27 21:59:38 +01:00
|
|
|
.remove = amd8111_remove,
|
2005-04-17 00:20:36 +02:00
|
|
|
};
|
|
|
|
|
2012-07-24 14:13:56 +02:00
|
|
|
module_pci_driver(amd8111_driver);
|