Note: we assume there can only be one device, with one SMBus interface.
*/
-#include <linux/config.h>
#include <linux/module.h>
#include <linux/pci.h>
#include <linux/kernel.h>
+#include <linux/delay.h>
#include <linux/stddef.h>
#include <linux/sched.h>
#include <linux/ioport.h>
#define AMD756_PROCESS_CALL 0x04
#define AMD756_BLOCK_DATA 0x05
-
-static unsigned short amd756_ioport = 0;
+static struct pci_driver amd756_driver;
+static unsigned short amd756_ioport;
/*
SMBUS event = I/O 28-29 bit 11
int result = 0;
int timeout = 0;
- dev_dbg(&adap->dev, ": Transaction (pre): GS=%04x, GE=%04x, ADD=%04x, "
+ dev_dbg(&adap->dev, "Transaction (pre): GS=%04x, GE=%04x, ADD=%04x, "
"DAT=%04x\n", inw_p(SMB_GLOBAL_STATUS),
inw_p(SMB_GLOBAL_ENABLE), inw_p(SMB_HOST_ADDRESS),
inb_p(SMB_HOST_DATA));
/* Make sure the SMBus host is ready to start transmitting */
if ((temp = inw_p(SMB_GLOBAL_STATUS)) & (GS_HST_STS | GS_SMB_STS)) {
- dev_dbg(&adap->dev, ": SMBus busy (%04x). Waiting... \n", temp);
+ dev_dbg(&adap->dev, "SMBus busy (%04x). Waiting...\n", temp);
do {
- i2c_delay(1);
+ msleep(1);
temp = inw_p(SMB_GLOBAL_STATUS);
} while ((temp & (GS_HST_STS | GS_SMB_STS)) &&
(timeout++ < MAX_TIMEOUT));
/* If the SMBus is still busy, we give up */
if (timeout >= MAX_TIMEOUT) {
- dev_dbg(&adap->dev, ": Busy wait timeout (%04x)\n", temp);
+ dev_dbg(&adap->dev, "Busy wait timeout (%04x)\n", temp);
goto abort;
}
timeout = 0;
/* We will always wait for a fraction of a second! */
do {
- i2c_delay(1);
+ msleep(1);
temp = inw_p(SMB_GLOBAL_STATUS);
} while ((temp & GS_HST_STS) && (timeout++ < MAX_TIMEOUT));
/* If the SMBus is still busy, we give up */
if (timeout >= MAX_TIMEOUT) {
- dev_dbg(&adap->dev, ": Completion timeout!\n");
+ dev_dbg(&adap->dev, "Completion timeout!\n");
goto abort;
}
if (temp & GS_PRERR_STS) {
result = -1;
- dev_dbg(&adap->dev, ": SMBus Protocol error (no response)!\n");
+ dev_dbg(&adap->dev, "SMBus Protocol error (no response)!\n");
}
if (temp & GS_COL_STS) {
result = -1;
- dev_warn(&adap->dev, " SMBus collision!\n");
+ dev_warn(&adap->dev, "SMBus collision!\n");
}
if (temp & GS_TO_STS) {
result = -1;
- dev_dbg(&adap->dev, ": SMBus protocol timeout!\n");
+ dev_dbg(&adap->dev, "SMBus protocol timeout!\n");
}
if (temp & GS_HCYC_STS)
- dev_dbg(&adap->dev, " SMBus protocol success!\n");
+ dev_dbg(&adap->dev, "SMBus protocol success!\n");
outw_p(GS_CLEAR_STS, SMB_GLOBAL_STATUS);
#ifdef DEBUG
if (((temp = inw_p(SMB_GLOBAL_STATUS)) & GS_CLEAR_STS) != 0x00) {
dev_dbg(&adap->dev,
- ": Failed reset at end of transaction (%04x)\n", temp);
+ "Failed reset at end of transaction (%04x)\n", temp);
}
#endif
dev_dbg(&adap->dev,
- ": Transaction (post): GS=%04x, GE=%04x, ADD=%04x, DAT=%04x\n",
+ "Transaction (post): GS=%04x, GE=%04x, ADD=%04x, DAT=%04x\n",
inw_p(SMB_GLOBAL_STATUS), inw_p(SMB_GLOBAL_ENABLE),
inw_p(SMB_HOST_ADDRESS), inb_p(SMB_HOST_DATA));
return result;
abort:
- dev_warn(&adap->dev, ": Sending abort.\n");
+ dev_warn(&adap->dev, "Sending abort\n");
outw_p(inw(SMB_GLOBAL_ENABLE) | GE_ABORT, SMB_GLOBAL_ENABLE);
- i2c_delay(100);
+ msleep(100);
outw_p(GS_CLEAR_STS, SMB_GLOBAL_STATUS);
return -1;
}
/** TODO: Should I supporte the 10-bit transfers? */
switch (size) {
case I2C_SMBUS_PROC_CALL:
- dev_dbg(&adap->dev, ": I2C_SMBUS_PROC_CALL not supported!\n");
+ dev_dbg(&adap->dev, "I2C_SMBUS_PROC_CALL not supported!\n");
/* TODO: Well... It is supported, I'm just not sure what to do here... */
return -1;
case I2C_SMBUS_QUICK:
I2C_FUNC_SMBUS_BLOCK_DATA | I2C_FUNC_SMBUS_PROC_CALL;
}
-static struct i2c_algorithm smbus_algorithm = {
- .name = "Non-I2C SMBus adapter",
- .id = I2C_ALGO_SMBUS,
+static const struct i2c_algorithm smbus_algorithm = {
.smbus_xfer = amd756_access,
.functionality = amd756_func,
};
-static struct i2c_adapter amd756_adapter = {
+struct i2c_adapter amd756_smbus = {
.owner = THIS_MODULE,
- .class = I2C_ADAP_CLASS_SMBUS,
+ .class = I2C_CLASS_HWMON,
.algo = &smbus_algorithm,
- .name = "unset",
};
enum chiptype { AMD756, AMD766, AMD768, NFORCE, AMD8111 };
+static const char* chipname[] = {
+ "AMD756", "AMD766", "AMD768",
+ "nVidia nForce", "AMD8111",
+};
static struct pci_device_id amd756_ids[] = {
- {PCI_VENDOR_ID_AMD, 0x740B, PCI_ANY_ID, PCI_ANY_ID, 0, 0, AMD756 },
- {PCI_VENDOR_ID_AMD, 0x7413, PCI_ANY_ID, PCI_ANY_ID, 0, 0, AMD766 },
- {PCI_VENDOR_ID_AMD, 0x7443, PCI_ANY_ID, PCI_ANY_ID, 0, 0, AMD768 },
- {PCI_VENDOR_ID_AMD, 0x746B, PCI_ANY_ID, PCI_ANY_ID, 0, 0, AMD8111 },
- {PCI_VENDOR_ID_NVIDIA, 0x01B4, PCI_ANY_ID, PCI_ANY_ID, 0, 0, NFORCE },
+ { PCI_DEVICE(PCI_VENDOR_ID_AMD, PCI_DEVICE_ID_AMD_VIPER_740B),
+ .driver_data = AMD756 },
+ { PCI_DEVICE(PCI_VENDOR_ID_AMD, PCI_DEVICE_ID_AMD_VIPER_7413),
+ .driver_data = AMD766 },
+ { PCI_DEVICE(PCI_VENDOR_ID_AMD, PCI_DEVICE_ID_AMD_OPUS_7443),
+ .driver_data = AMD768 },
+ { PCI_DEVICE(PCI_VENDOR_ID_AMD, PCI_DEVICE_ID_AMD_8111_SMBUS),
+ .driver_data = AMD8111 },
+ { PCI_DEVICE(PCI_VENDOR_ID_NVIDIA, PCI_DEVICE_ID_NVIDIA_NFORCE_SMBUS),
+ .driver_data = NFORCE },
{ 0, }
};
+MODULE_DEVICE_TABLE (pci, amd756_ids);
+
static int __devinit amd756_probe(struct pci_dev *pdev,
const struct pci_device_id *id)
{
u8 temp;
if (amd756_ioport) {
- dev_err(&pdev->dev, ": Only one device supported. "
- "(you have a strange motherboard, btw..)\n");
+ dev_err(&pdev->dev, "Only one device supported "
+ "(you have a strange motherboard, btw)\n");
return -ENODEV;
}
pci_read_config_byte(pdev, SMBGCFG, &temp);
if ((temp & 128) == 0) {
dev_err(&pdev->dev,
- ": Error: SMBus controller I/O not enabled!\n");
+ "Error: SMBus controller I/O not enabled!\n");
return -ENODEV;
}
amd756_ioport += SMB_ADDR_OFFSET;
}
- if (!request_region(amd756_ioport, SMB_IOSIZE, "amd756-smbus")) {
- dev_err(&pdev->dev, ": SMB region 0x%x already in use!\n",
+ if (!request_region(amd756_ioport, SMB_IOSIZE, amd756_driver.name)) {
+ dev_err(&pdev->dev, "SMB region 0x%x already in use!\n",
amd756_ioport);
return -ENODEV;
}
pci_read_config_byte(pdev, SMBREV, &temp);
- dev_dbg(&pdev->dev, ": SMBREV = 0x%X\n", temp);
- dev_dbg(&pdev->dev, ": AMD756_smba = 0x%X\n", amd756_ioport);
+ dev_dbg(&pdev->dev, "SMBREV = 0x%X\n", temp);
+ dev_dbg(&pdev->dev, "AMD756_smba = 0x%X\n", amd756_ioport);
/* set up the driverfs linkage to our parent device */
- amd756_adapter.dev.parent = &pdev->dev;
+ amd756_smbus.dev.parent = &pdev->dev;
- snprintf(amd756_adapter.name, I2C_NAME_SIZE,
- "SMBus AMD756 adapter at %04x", amd756_ioport);
+ sprintf(amd756_smbus.name, "SMBus %s adapter at %04x",
+ chipname[id->driver_data], amd756_ioport);
- error = i2c_add_adapter(&amd756_adapter);
+ error = i2c_add_adapter(&amd756_smbus);
if (error) {
dev_err(&pdev->dev,
- ": Adapter registration failed, module not inserted.\n");
+ "Adapter registration failed, module not inserted\n");
goto out_err;
}
static void __devexit amd756_remove(struct pci_dev *dev)
{
- i2c_del_adapter(&amd756_adapter);
+ i2c_del_adapter(&amd756_smbus);
release_region(amd756_ioport, SMB_IOSIZE);
}
static struct pci_driver amd756_driver = {
- .name = "amd756 smbus",
+ .name = "amd756_smbus",
.id_table = amd756_ids,
.probe = amd756_probe,
.remove = __devexit_p(amd756_remove),
static int __init amd756_init(void)
{
- return pci_module_init(&amd756_driver);
+ return pci_register_driver(&amd756_driver);
}
static void __exit amd756_exit(void)
MODULE_DESCRIPTION("AMD756/766/768/8111 and nVidia nForce SMBus driver");
MODULE_LICENSE("GPL");
+EXPORT_SYMBOL(amd756_smbus);
+
module_init(amd756_init)
module_exit(amd756_exit)