49 #include <linux/module.h>
50 #include <linux/pci.h>
51 #include <linux/kernel.h>
52 #include <linux/stddef.h>
55 #include <linux/i2c.h>
59 #include <linux/slab.h>
80 #define NFORCE_PCI_SMB1 0x50
81 #define NFORCE_PCI_SMB2 0x54
87 #define NVIDIA_SMB_PRTCL (smbus->base + 0x00)
88 #define NVIDIA_SMB_STS (smbus->base + 0x01)
89 #define NVIDIA_SMB_ADDR (smbus->base + 0x02)
90 #define NVIDIA_SMB_CMD (smbus->base + 0x03)
91 #define NVIDIA_SMB_DATA (smbus->base + 0x04)
92 #define NVIDIA_SMB_BCNT (smbus->base + 0x24)
94 #define NVIDIA_SMB_STATUS_ABRT (smbus->base + 0x3c)
97 #define NVIDIA_SMB_CTRL (smbus->base + 0x3e)
99 #define NVIDIA_SMB_STATUS_ABRT_STS 0x01
101 #define NVIDIA_SMB_CTRL_ABORT 0x20
102 #define NVIDIA_SMB_STS_DONE 0x80
103 #define NVIDIA_SMB_STS_ALRM 0x40
104 #define NVIDIA_SMB_STS_RES 0x20
105 #define NVIDIA_SMB_STS_STATUS 0x1f
107 #define NVIDIA_SMB_PRTCL_WRITE 0x00
108 #define NVIDIA_SMB_PRTCL_READ 0x01
109 #define NVIDIA_SMB_PRTCL_QUICK 0x02
110 #define NVIDIA_SMB_PRTCL_BYTE 0x04
111 #define NVIDIA_SMB_PRTCL_BYTE_DATA 0x06
112 #define NVIDIA_SMB_PRTCL_WORD_DATA 0x08
113 #define NVIDIA_SMB_PRTCL_BLOCK_DATA 0x0a
114 #define NVIDIA_SMB_PRTCL_PEC 0x80
117 #define MAX_TIMEOUT 100
122 .ident =
"DFI Lanparty NF4 Expert",
135 #if defined CONFIG_I2C_NFORCE2_S4985 || defined CONFIG_I2C_NFORCE2_S4985_MODULE
139 static void nforce2_set_reference(
struct i2c_adapter *adap)
141 nforce2_smbus = adap;
144 static inline void nforce2_set_reference(
struct i2c_adapter *adap) { }
147 static void nforce2_abort(
struct i2c_adapter *adap)
149 struct nforce2_smbus *smbus = adap->
algo_data;
153 dev_dbg(&adap->
dev,
"Aborting current transaction\n");
161 if (!(temp & NVIDIA_SMB_STATUS_ABRT_STS))
162 dev_err(&adap->
dev,
"Can't reset the smbus\n");
166 static int nforce2_check_status(
struct i2c_adapter *adap)
168 struct nforce2_smbus *smbus = adap->
algo_data;
184 dev_dbg(&adap->
dev,
"Transaction failed (0x%02x)!\n", temp);
192 unsigned short flags,
char read_write,
195 struct nforce2_smbus *smbus = adap->
algo_data;
236 len = data->
block[0];
239 "Transaction failed "
240 "(requested block size: %d)\n",
253 dev_err(&adap->
dev,
"Unsupported transaction %d\n", size);
260 status = nforce2_check_status(adap);
282 "(received block size: 0x%02x)\n",
286 for (i = 0; i < len; i++)
288 data->
block[0] = len;
302 (((
struct nforce2_smbus*)adapter->
algo_data)->blockops ?
307 .smbus_xfer = nforce2_access,
308 .functionality = nforce2_func,
334 int alt_reg,
struct nforce2_smbus *smbus,
const char *
name)
345 if (pci_read_config_word(dev, alt_reg, &iobase)
347 dev_err(&dev->
dev,
"Error reading PCI config for %s\n",
357 nforce2_driver.name);
362 dev_err(&smbus->
adapter.dev,
"Error requesting region %02x .. %02X for %s\n",
368 smbus->
adapter.algo = &smbus_algorithm;
369 smbus->
adapter.algo_data = smbus;
372 "SMBus nForce2 adapter at %04x", smbus->
base);
387 struct nforce2_smbus *smbuses;
391 if (!(smbuses = kzalloc(2*
sizeof(
struct nforce2_smbus),
GFP_KERNEL)))
393 pci_set_drvdata(dev, smbuses);
406 res1 = nforce2_probe_smb(dev, 4,
NFORCE_PCI_SMB1, &smbuses[0],
"SMB1");
412 dev_err(&dev->
dev,
"Disabling SMB2 for safety reasons.\n");
422 if ((res1 < 0) && (res2 < 0)) {
428 nforce2_set_reference(&smbuses[0].
adapter);
435 struct nforce2_smbus *smbuses = pci_get_drvdata(dev);
437 nforce2_set_reference(
NULL);
438 if (smbuses[0].
base) {
442 if (smbuses[1].base) {
450 .name =
"nForce2_smbus",
451 .id_table = nforce2_ids,
452 .probe = nforce2_probe,