blob: 43a96a123920c8d75773735b3070e7b4872ddd62 [file] [log] [blame]
Linus Torvalds1da177e2005-04-16 15:20:36 -07001/*
2 SMBus driver for nVidia nForce2 MCP
3
4 Added nForce3 Pro 150 Thomas Leibold <thomas@plx.com>,
5 Ported to 2.5 Patrick Dreker <patrick@dreker.de>,
6 Copyright (c) 2003 Hans-Frieder Vogt <hfvogt@arcor.de>,
7 Based on
8 SMBus 2.0 driver for AMD-8111 IO-Hub
9 Copyright (c) 2002 Vojtech Pavlik
10
11 This program is free software; you can redistribute it and/or modify
12 it under the terms of the GNU General Public License as published by
13 the Free Software Foundation; either version 2 of the License, or
14 (at your option) any later version.
15
16 This program is distributed in the hope that it will be useful,
17 but WITHOUT ANY WARRANTY; without even the implied warranty of
18 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
19 GNU General Public License for more details.
20
21 You should have received a copy of the GNU General Public License
22 along with this program; if not, write to the Free Software
23 Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
24*/
25
26/*
27 SUPPORTED DEVICES PCI ID
28 nForce2 MCP 0064
29 nForce2 Ultra 400 MCP 0084
30 nForce3 Pro150 MCP 00D4
31 nForce3 250Gb MCP 00E4
32 nForce4 MCP 0052
Jean Delvare7c72ccf2005-12-18 17:25:18 +010033 nForce4 MCP-04 0034
Jean Delvared2dd14a2009-03-28 21:34:41 +010034 nForce MCP51 0264
35 nForce MCP55 0368
Jean Delvaref75803d2007-05-01 23:26:29 +020036 nForce MCP61 03EB
37 nForce MCP65 0446
Jean Delvared2dd14a2009-03-28 21:34:41 +010038 nForce MCP67 0542
39 nForce MCP73 07D8
40 nForce MCP78S 0752
41 nForce MCP79 0AA2
Linus Torvalds1da177e2005-04-16 15:20:36 -070042
43 This driver supports the 2 SMBuses that are included in the MCP of the
Hans-Frieder Vogtad04d5c2006-12-10 21:21:29 +010044 nForce2/3/4/5xx chipsets.
Linus Torvalds1da177e2005-04-16 15:20:36 -070045*/
46
47/* Note: we assume there can only be one nForce2, with two SMBus interfaces */
48
Linus Torvalds1da177e2005-04-16 15:20:36 -070049#include <linux/module.h>
50#include <linux/pci.h>
51#include <linux/kernel.h>
52#include <linux/stddef.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070053#include <linux/ioport.h>
54#include <linux/init.h>
55#include <linux/i2c.h>
56#include <linux/delay.h>
Jean Delvare08851d62008-05-18 20:49:40 +020057#include <linux/dmi.h>
Jean Delvare54fb4a052008-07-14 22:38:33 +020058#include <linux/acpi.h>
Tejun Heo5a0e3ad2010-03-24 17:04:11 +090059#include <linux/slab.h>
H Hartley Sweeten21782182010-05-21 18:41:01 +020060#include <linux/io.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070061
62MODULE_LICENSE("GPL");
Hans-Frieder Vogtad04d5c2006-12-10 21:21:29 +010063MODULE_AUTHOR ("Hans-Frieder Vogt <hfvogt@gmx.net>");
64MODULE_DESCRIPTION("nForce2/3/4/5xx SMBus driver");
Linus Torvalds1da177e2005-04-16 15:20:36 -070065
66
67struct nforce2_smbus {
Linus Torvalds1da177e2005-04-16 15:20:36 -070068 struct i2c_adapter adapter;
69 int base;
70 int size;
Oleg Ryjkovb53c8222007-07-12 14:12:29 +020071 int blockops;
Oleg Ryjkovd49584c2007-10-13 23:56:33 +020072 int can_abort;
Linus Torvalds1da177e2005-04-16 15:20:36 -070073};
74
75
76/*
77 * nVidia nForce2 SMBus control register definitions
Jean Delvare5c7ae652006-04-25 14:18:16 +020078 * (Newer incarnations use standard BARs 4 and 5 instead)
Linus Torvalds1da177e2005-04-16 15:20:36 -070079 */
80#define NFORCE_PCI_SMB1 0x50
81#define NFORCE_PCI_SMB2 0x54
82
83
84/*
85 * ACPI 2.0 chapter 13 SMBus 2.0 EC register model
86 */
87#define NVIDIA_SMB_PRTCL (smbus->base + 0x00) /* protocol, PEC */
88#define NVIDIA_SMB_STS (smbus->base + 0x01) /* status */
89#define NVIDIA_SMB_ADDR (smbus->base + 0x02) /* address */
90#define NVIDIA_SMB_CMD (smbus->base + 0x03) /* command */
91#define NVIDIA_SMB_DATA (smbus->base + 0x04) /* 32 data registers */
Oleg Ryjkovb53c8222007-07-12 14:12:29 +020092#define NVIDIA_SMB_BCNT (smbus->base + 0x24) /* number of data
93 bytes */
Oleg Ryjkovd49584c2007-10-13 23:56:33 +020094#define NVIDIA_SMB_STATUS_ABRT (smbus->base + 0x3c) /* register used to
95 check the status of
96 the abort command */
97#define NVIDIA_SMB_CTRL (smbus->base + 0x3e) /* control register */
Linus Torvalds1da177e2005-04-16 15:20:36 -070098
Oleg Ryjkovd49584c2007-10-13 23:56:33 +020099#define NVIDIA_SMB_STATUS_ABRT_STS 0x01 /* Bit to notify that
100 abort succeeded */
101#define NVIDIA_SMB_CTRL_ABORT 0x20
Linus Torvalds1da177e2005-04-16 15:20:36 -0700102#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
106
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
Oleg Ryjkovb53c8222007-07-12 14:12:29 +0200113#define NVIDIA_SMB_PRTCL_BLOCK_DATA 0x0a
Linus Torvalds1da177e2005-04-16 15:20:36 -0700114#define NVIDIA_SMB_PRTCL_PEC 0x80
115
Oleg Ryjkov41535492007-10-13 23:56:33 +0200116/* Misc definitions */
117#define MAX_TIMEOUT 100
118
Jean Delvare08851d62008-05-18 20:49:40 +0200119/* We disable the second SMBus channel on these boards */
120static struct dmi_system_id __devinitdata nforce2_dmi_blacklist2[] = {
121 {
122 .ident = "DFI Lanparty NF4 Expert",
123 .matches = {
124 DMI_MATCH(DMI_BOARD_VENDOR, "DFI Corp,LTD"),
125 DMI_MATCH(DMI_BOARD_NAME, "LP UT NF4 Expert"),
126 },
127 },
128 { }
129};
130
Jean Delvared6072f82005-09-25 16:37:04 +0200131static struct pci_driver nforce2_driver;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700132
Jean Delvare279e9022008-07-14 22:38:21 +0200133/* For multiplexing support, we need a global reference to the 1st
134 SMBus channel */
135#if defined CONFIG_I2C_NFORCE2_S4985 || defined CONFIG_I2C_NFORCE2_S4985_MODULE
136struct i2c_adapter *nforce2_smbus;
137EXPORT_SYMBOL_GPL(nforce2_smbus);
138
139static void nforce2_set_reference(struct i2c_adapter *adap)
140{
141 nforce2_smbus = adap;
142}
143#else
144static inline void nforce2_set_reference(struct i2c_adapter *adap) { }
145#endif
146
Oleg Ryjkovd49584c2007-10-13 23:56:33 +0200147static void nforce2_abort(struct i2c_adapter *adap)
148{
149 struct nforce2_smbus *smbus = adap->algo_data;
150 int timeout = 0;
151 unsigned char temp;
152
153 dev_dbg(&adap->dev, "Aborting current transaction\n");
154
155 outb_p(NVIDIA_SMB_CTRL_ABORT, NVIDIA_SMB_CTRL);
156 do {
157 msleep(1);
158 temp = inb_p(NVIDIA_SMB_STATUS_ABRT);
159 } while (!(temp & NVIDIA_SMB_STATUS_ABRT_STS) &&
160 (timeout++ < MAX_TIMEOUT));
161 if (!(temp & NVIDIA_SMB_STATUS_ABRT_STS))
162 dev_err(&adap->dev, "Can't reset the smbus\n");
163 outb_p(NVIDIA_SMB_STATUS_ABRT_STS, NVIDIA_SMB_STATUS_ABRT);
164}
165
Oleg Ryjkov41535492007-10-13 23:56:33 +0200166static int nforce2_check_status(struct i2c_adapter *adap)
167{
168 struct nforce2_smbus *smbus = adap->algo_data;
169 int timeout = 0;
170 unsigned char temp;
171
172 do {
173 msleep(1);
174 temp = inb_p(NVIDIA_SMB_STS);
175 } while ((!temp) && (timeout++ < MAX_TIMEOUT));
176
Roel Kluin4ccc28f2009-05-05 08:39:24 +0200177 if (timeout > MAX_TIMEOUT) {
Oleg Ryjkov41535492007-10-13 23:56:33 +0200178 dev_dbg(&adap->dev, "SMBus Timeout!\n");
Oleg Ryjkovd49584c2007-10-13 23:56:33 +0200179 if (smbus->can_abort)
180 nforce2_abort(adap);
David Brownell97140342008-07-14 22:38:25 +0200181 return -ETIMEDOUT;
Oleg Ryjkov41535492007-10-13 23:56:33 +0200182 }
183 if (!(temp & NVIDIA_SMB_STS_DONE) || (temp & NVIDIA_SMB_STS_STATUS)) {
184 dev_dbg(&adap->dev, "Transaction failed (0x%02x)!\n", temp);
David Brownell97140342008-07-14 22:38:25 +0200185 return -EIO;
Oleg Ryjkov41535492007-10-13 23:56:33 +0200186 }
187 return 0;
188}
189
David Brownell97140342008-07-14 22:38:25 +0200190/* Return negative errno on error */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700191static s32 nforce2_access(struct i2c_adapter * adap, u16 addr,
192 unsigned short flags, char read_write,
193 u8 command, int size, union i2c_smbus_data * data)
194{
195 struct nforce2_smbus *smbus = adap->algo_data;
Oleg Ryjkov41535492007-10-13 23:56:33 +0200196 unsigned char protocol, pec;
Oleg Ryjkovb53c8222007-07-12 14:12:29 +0200197 u8 len;
David Brownell97140342008-07-14 22:38:25 +0200198 int i, status;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700199
200 protocol = (read_write == I2C_SMBUS_READ) ? NVIDIA_SMB_PRTCL_READ :
201 NVIDIA_SMB_PRTCL_WRITE;
202 pec = (flags & I2C_CLIENT_PEC) ? NVIDIA_SMB_PRTCL_PEC : 0;
203
204 switch (size) {
205
206 case I2C_SMBUS_QUICK:
207 protocol |= NVIDIA_SMB_PRTCL_QUICK;
208 read_write = I2C_SMBUS_WRITE;
209 break;
210
211 case I2C_SMBUS_BYTE:
212 if (read_write == I2C_SMBUS_WRITE)
213 outb_p(command, NVIDIA_SMB_CMD);
214 protocol |= NVIDIA_SMB_PRTCL_BYTE;
215 break;
216
217 case I2C_SMBUS_BYTE_DATA:
218 outb_p(command, NVIDIA_SMB_CMD);
219 if (read_write == I2C_SMBUS_WRITE)
220 outb_p(data->byte, NVIDIA_SMB_DATA);
221 protocol |= NVIDIA_SMB_PRTCL_BYTE_DATA;
222 break;
223
224 case I2C_SMBUS_WORD_DATA:
225 outb_p(command, NVIDIA_SMB_CMD);
226 if (read_write == I2C_SMBUS_WRITE) {
227 outb_p(data->word, NVIDIA_SMB_DATA);
228 outb_p(data->word >> 8, NVIDIA_SMB_DATA+1);
229 }
230 protocol |= NVIDIA_SMB_PRTCL_WORD_DATA | pec;
231 break;
232
Oleg Ryjkovb53c8222007-07-12 14:12:29 +0200233 case I2C_SMBUS_BLOCK_DATA:
234 outb_p(command, NVIDIA_SMB_CMD);
235 if (read_write == I2C_SMBUS_WRITE) {
236 len = data->block[0];
237 if ((len == 0) || (len > I2C_SMBUS_BLOCK_MAX)) {
238 dev_err(&adap->dev,
239 "Transaction failed "
240 "(requested block size: %d)\n",
241 len);
David Brownell97140342008-07-14 22:38:25 +0200242 return -EINVAL;
Oleg Ryjkovb53c8222007-07-12 14:12:29 +0200243 }
244 outb_p(len, NVIDIA_SMB_BCNT);
245 for (i = 0; i < I2C_SMBUS_BLOCK_MAX; i++)
246 outb_p(data->block[i + 1],
247 NVIDIA_SMB_DATA+i);
248 }
249 protocol |= NVIDIA_SMB_PRTCL_BLOCK_DATA | pec;
250 break;
251
Linus Torvalds1da177e2005-04-16 15:20:36 -0700252 default:
253 dev_err(&adap->dev, "Unsupported transaction %d\n", size);
David Brownell97140342008-07-14 22:38:25 +0200254 return -EOPNOTSUPP;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700255 }
256
257 outb_p((addr & 0x7f) << 1, NVIDIA_SMB_ADDR);
258 outb_p(protocol, NVIDIA_SMB_PRTCL);
259
David Brownell97140342008-07-14 22:38:25 +0200260 status = nforce2_check_status(adap);
261 if (status)
262 return status;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700263
264 if (read_write == I2C_SMBUS_WRITE)
265 return 0;
266
267 switch (size) {
268
269 case I2C_SMBUS_BYTE:
270 case I2C_SMBUS_BYTE_DATA:
271 data->byte = inb_p(NVIDIA_SMB_DATA);
272 break;
273
274 case I2C_SMBUS_WORD_DATA:
Linus Torvalds1da177e2005-04-16 15:20:36 -0700275 data->word = inb_p(NVIDIA_SMB_DATA) | (inb_p(NVIDIA_SMB_DATA+1) << 8);
276 break;
Oleg Ryjkovb53c8222007-07-12 14:12:29 +0200277
278 case I2C_SMBUS_BLOCK_DATA:
279 len = inb_p(NVIDIA_SMB_BCNT);
Oleg Ryjkov41535492007-10-13 23:56:33 +0200280 if ((len <= 0) || (len > I2C_SMBUS_BLOCK_MAX)) {
281 dev_err(&adap->dev, "Transaction failed "
282 "(received block size: 0x%02x)\n",
283 len);
David Brownell97140342008-07-14 22:38:25 +0200284 return -EPROTO;
Oleg Ryjkov41535492007-10-13 23:56:33 +0200285 }
Oleg Ryjkovb53c8222007-07-12 14:12:29 +0200286 for (i = 0; i < len; i++)
287 data->block[i+1] = inb_p(NVIDIA_SMB_DATA + i);
288 data->block[0] = len;
289 break;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700290 }
291
292 return 0;
293}
294
295
296static u32 nforce2_func(struct i2c_adapter *adapter)
297{
298 /* other functionality might be possible, but is not tested */
299 return I2C_FUNC_SMBUS_QUICK | I2C_FUNC_SMBUS_BYTE |
Oleg Ryjkovb53c8222007-07-12 14:12:29 +0200300 I2C_FUNC_SMBUS_BYTE_DATA | I2C_FUNC_SMBUS_WORD_DATA |
Jean Delvareac3f5752007-10-13 23:56:33 +0200301 I2C_FUNC_SMBUS_PEC |
Oleg Ryjkovb53c8222007-07-12 14:12:29 +0200302 (((struct nforce2_smbus*)adapter->algo_data)->blockops ?
303 I2C_FUNC_SMBUS_BLOCK_DATA : 0);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700304}
305
Hans-Frieder Vogtad04d5c2006-12-10 21:21:29 +0100306static struct i2c_algorithm smbus_algorithm = {
307 .smbus_xfer = nforce2_access,
308 .functionality = nforce2_func,
309};
310
Linus Torvalds1da177e2005-04-16 15:20:36 -0700311
Axel Lin3527bd52012-01-12 20:32:04 +0100312static DEFINE_PCI_DEVICE_TABLE(nforce2_ids) = {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700313 { PCI_DEVICE(PCI_VENDOR_ID_NVIDIA, PCI_DEVICE_ID_NVIDIA_NFORCE2_SMBUS) },
314 { PCI_DEVICE(PCI_VENDOR_ID_NVIDIA, PCI_DEVICE_ID_NVIDIA_NFORCE2S_SMBUS) },
315 { PCI_DEVICE(PCI_VENDOR_ID_NVIDIA, PCI_DEVICE_ID_NVIDIA_NFORCE3_SMBUS) },
316 { PCI_DEVICE(PCI_VENDOR_ID_NVIDIA, PCI_DEVICE_ID_NVIDIA_NFORCE3S_SMBUS) },
317 { PCI_DEVICE(PCI_VENDOR_ID_NVIDIA, PCI_DEVICE_ID_NVIDIA_NFORCE4_SMBUS) },
Jean Delvare7c72ccf2005-12-18 17:25:18 +0100318 { PCI_DEVICE(PCI_VENDOR_ID_NVIDIA, PCI_DEVICE_ID_NVIDIA_NFORCE_MCP04_SMBUS) },
Jean Delvare5c7ae652006-04-25 14:18:16 +0200319 { PCI_DEVICE(PCI_VENDOR_ID_NVIDIA, PCI_DEVICE_ID_NVIDIA_NFORCE_MCP51_SMBUS) },
320 { PCI_DEVICE(PCI_VENDOR_ID_NVIDIA, PCI_DEVICE_ID_NVIDIA_NFORCE_MCP55_SMBUS) },
Jean Delvaref75803d2007-05-01 23:26:29 +0200321 { PCI_DEVICE(PCI_VENDOR_ID_NVIDIA, PCI_DEVICE_ID_NVIDIA_NFORCE_MCP61_SMBUS) },
322 { PCI_DEVICE(PCI_VENDOR_ID_NVIDIA, PCI_DEVICE_ID_NVIDIA_NFORCE_MCP65_SMBUS) },
Jean Delvared2dd14a2009-03-28 21:34:41 +0100323 { PCI_DEVICE(PCI_VENDOR_ID_NVIDIA, PCI_DEVICE_ID_NVIDIA_NFORCE_MCP67_SMBUS) },
324 { PCI_DEVICE(PCI_VENDOR_ID_NVIDIA, PCI_DEVICE_ID_NVIDIA_NFORCE_MCP73_SMBUS) },
325 { PCI_DEVICE(PCI_VENDOR_ID_NVIDIA, PCI_DEVICE_ID_NVIDIA_NFORCE_MCP78S_SMBUS) },
326 { PCI_DEVICE(PCI_VENDOR_ID_NVIDIA, PCI_DEVICE_ID_NVIDIA_NFORCE_MCP79_SMBUS) },
Linus Torvalds1da177e2005-04-16 15:20:36 -0700327 { 0 }
328};
329
Linus Torvalds1da177e2005-04-16 15:20:36 -0700330MODULE_DEVICE_TABLE (pci, nforce2_ids);
331
332
Jean Delvare5c7ae652006-04-25 14:18:16 +0200333static int __devinit nforce2_probe_smb (struct pci_dev *dev, int bar,
334 int alt_reg, struct nforce2_smbus *smbus, const char *name)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700335{
Linus Torvalds1da177e2005-04-16 15:20:36 -0700336 int error;
337
Jean Delvare5c7ae652006-04-25 14:18:16 +0200338 smbus->base = pci_resource_start(dev, bar);
339 if (smbus->base) {
340 smbus->size = pci_resource_len(dev, bar);
341 } else {
342 /* Older incarnations of the device used non-standard BARs */
343 u16 iobase;
344
345 if (pci_read_config_word(dev, alt_reg, &iobase)
346 != PCIBIOS_SUCCESSFUL) {
347 dev_err(&dev->dev, "Error reading PCI config for %s\n",
348 name);
David Brownell97140342008-07-14 22:38:25 +0200349 return -EIO;
Jean Delvare5c7ae652006-04-25 14:18:16 +0200350 }
351
352 smbus->base = iobase & PCI_BASE_ADDRESS_IO_MASK;
Hans-Frieder Vogtad04d5c2006-12-10 21:21:29 +0100353 smbus->size = 64;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700354 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700355
Jean Delvare54fb4a052008-07-14 22:38:33 +0200356 error = acpi_check_region(smbus->base, smbus->size,
357 nforce2_driver.name);
358 if (error)
Jean Delvare7c1f59c2012-01-12 20:32:03 +0100359 return error;
Jean Delvare54fb4a052008-07-14 22:38:33 +0200360
Jean Delvared6072f82005-09-25 16:37:04 +0200361 if (!request_region(smbus->base, smbus->size, nforce2_driver.name)) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700362 dev_err(&smbus->adapter.dev, "Error requesting region %02x .. %02X for %s\n",
363 smbus->base, smbus->base+smbus->size-1, name);
David Brownell97140342008-07-14 22:38:25 +0200364 return -EBUSY;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700365 }
Hans-Frieder Vogtad04d5c2006-12-10 21:21:29 +0100366 smbus->adapter.owner = THIS_MODULE;
Jean Delvare3401b2f2008-07-14 22:38:29 +0200367 smbus->adapter.class = I2C_CLASS_HWMON | I2C_CLASS_SPD;
Hans-Frieder Vogtad04d5c2006-12-10 21:21:29 +0100368 smbus->adapter.algo = &smbus_algorithm;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700369 smbus->adapter.algo_data = smbus;
370 smbus->adapter.dev.parent = &dev->dev;
David Brownell2096b952007-05-01 23:26:28 +0200371 snprintf(smbus->adapter.name, sizeof(smbus->adapter.name),
Linus Torvalds1da177e2005-04-16 15:20:36 -0700372 "SMBus nForce2 adapter at %04x", smbus->base);
373
374 error = i2c_add_adapter(&smbus->adapter);
375 if (error) {
376 dev_err(&smbus->adapter.dev, "Failed to register adapter.\n");
377 release_region(smbus->base, smbus->size);
David Brownell97140342008-07-14 22:38:25 +0200378 return error;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700379 }
380 dev_info(&smbus->adapter.dev, "nForce2 SMBus adapter at %#x\n", smbus->base);
381 return 0;
382}
383
384
385static int __devinit nforce2_probe(struct pci_dev *dev, const struct pci_device_id *id)
386{
387 struct nforce2_smbus *smbuses;
388 int res1, res2;
389
390 /* we support 2 SMBus adapters */
Jean Delvare078d9fe2005-10-17 23:12:36 +0200391 if (!(smbuses = kzalloc(2*sizeof(struct nforce2_smbus), GFP_KERNEL)))
Linus Torvalds1da177e2005-04-16 15:20:36 -0700392 return -ENOMEM;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700393 pci_set_drvdata(dev, smbuses);
394
Oleg Ryjkovb53c8222007-07-12 14:12:29 +0200395 switch(dev->device) {
Jean Delvare541b6a72008-01-27 18:14:44 +0100396 case PCI_DEVICE_ID_NVIDIA_NFORCE2_SMBUS:
Oleg Ryjkovb53c8222007-07-12 14:12:29 +0200397 case PCI_DEVICE_ID_NVIDIA_NFORCE_MCP51_SMBUS:
398 case PCI_DEVICE_ID_NVIDIA_NFORCE_MCP55_SMBUS:
399 smbuses[0].blockops = 1;
400 smbuses[1].blockops = 1;
Oleg Ryjkovd49584c2007-10-13 23:56:33 +0200401 smbuses[0].can_abort = 1;
402 smbuses[1].can_abort = 1;
Oleg Ryjkovb53c8222007-07-12 14:12:29 +0200403 }
404
Linus Torvalds1da177e2005-04-16 15:20:36 -0700405 /* SMBus adapter 1 */
Jean Delvare5c7ae652006-04-25 14:18:16 +0200406 res1 = nforce2_probe_smb(dev, 4, NFORCE_PCI_SMB1, &smbuses[0], "SMB1");
Chase Douglas7c4fda12010-05-21 18:41:01 +0200407 if (res1 < 0)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700408 smbuses[0].base = 0; /* to have a check value */
Chase Douglas7c4fda12010-05-21 18:41:01 +0200409
Jean Delvare5c7ae652006-04-25 14:18:16 +0200410 /* SMBus adapter 2 */
Jean Delvare08851d62008-05-18 20:49:40 +0200411 if (dmi_check_system(nforce2_dmi_blacklist2)) {
412 dev_err(&dev->dev, "Disabling SMB2 for safety reasons.\n");
413 res2 = -EPERM;
414 smbuses[1].base = 0;
415 } else {
416 res2 = nforce2_probe_smb(dev, 5, NFORCE_PCI_SMB2, &smbuses[1],
417 "SMB2");
Chase Douglas7c4fda12010-05-21 18:41:01 +0200418 if (res2 < 0)
Jean Delvare08851d62008-05-18 20:49:40 +0200419 smbuses[1].base = 0; /* to have a check value */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700420 }
Chase Douglas7c4fda12010-05-21 18:41:01 +0200421
Linus Torvalds1da177e2005-04-16 15:20:36 -0700422 if ((res1 < 0) && (res2 < 0)) {
423 /* we did not find even one of the SMBuses, so we give up */
424 kfree(smbuses);
425 return -ENODEV;
426 }
427
Jean Delvare279e9022008-07-14 22:38:21 +0200428 nforce2_set_reference(&smbuses[0].adapter);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700429 return 0;
430}
431
432
433static void __devexit nforce2_remove(struct pci_dev *dev)
434{
Joe Perchesb18a5c82011-01-10 22:11:22 +0100435 struct nforce2_smbus *smbuses = pci_get_drvdata(dev);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700436
Jean Delvare279e9022008-07-14 22:38:21 +0200437 nforce2_set_reference(NULL);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700438 if (smbuses[0].base) {
439 i2c_del_adapter(&smbuses[0].adapter);
440 release_region(smbuses[0].base, smbuses[0].size);
441 }
442 if (smbuses[1].base) {
443 i2c_del_adapter(&smbuses[1].adapter);
444 release_region(smbuses[1].base, smbuses[1].size);
445 }
446 kfree(smbuses);
447}
448
449static struct pci_driver nforce2_driver = {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700450 .name = "nForce2_smbus",
451 .id_table = nforce2_ids,
452 .probe = nforce2_probe,
453 .remove = __devexit_p(nforce2_remove),
454};
455
456static int __init nforce2_init(void)
457{
458 return pci_register_driver(&nforce2_driver);
459}
460
461static void __exit nforce2_exit(void)
462{
463 pci_unregister_driver(&nforce2_driver);
464}
465
466module_init(nforce2_init);
467module_exit(nforce2_exit);
468