blob: 299b918455a36999242027de9312fe98ce811db7 [file] [log] [blame]
Linus Torvalds1da177e2005-04-16 15:20:36 -07001/*
Linus Torvalds1da177e2005-04-16 15:20:36 -07002 Copyright (c) 1998 - 2002 Frodo Looijaard <frodol@dds.nl>,
3 Philip Edelbrock <phil@netroedge.com>, and Mark D. Studebaker
4 <mdsxyz123@yahoo.com>
Jean Delvarecf898dc2008-07-14 22:38:33 +02005 Copyright (C) 2007, 2008 Jean Delvare <khali@linux-fr.org>
Linus Torvalds1da177e2005-04-16 15:20:36 -07006
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; either version 2 of the License, or
10 (at your option) any later version.
11
12 This program is distributed in the hope that it will be useful,
13 but WITHOUT ANY WARRANTY; without even the implied warranty of
14 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 GNU General Public License for more details.
16
17 You should have received a copy of the GNU General Public License
18 along with this program; if not, write to the Free Software
19 Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
20*/
21
22/*
Jean Delvareae7b0492008-01-27 18:14:49 +010023 Supports the following Intel I/O Controller Hubs (ICH):
24
25 I/O Block I2C
26 region SMBus Block proc. block
27 Chip name PCI ID size PEC buffer call read
28 ----------------------------------------------------------------------
29 82801AA (ICH) 0x2413 16 no no no no
30 82801AB (ICH0) 0x2423 16 no no no no
31 82801BA (ICH2) 0x2443 16 no no no no
32 82801CA (ICH3) 0x2483 32 soft no no no
33 82801DB (ICH4) 0x24c3 32 hard yes no no
34 82801E (ICH5) 0x24d3 32 hard yes yes yes
35 6300ESB 0x25a4 32 hard yes yes yes
36 82801F (ICH6) 0x266a 32 hard yes yes yes
37 6310ESB/6320ESB 0x269b 32 hard yes yes yes
38 82801G (ICH7) 0x27da 32 hard yes yes yes
39 82801H (ICH8) 0x283e 32 hard yes yes yes
40 82801I (ICH9) 0x2930 32 hard yes yes yes
Gaston, Jason Dd28dc712008-02-24 20:03:42 +010041 Tolapai 0x5032 32 hard yes yes yes
42 ICH10 0x3a30 32 hard yes yes yes
43 ICH10 0x3a60 32 hard yes yes yes
Seth Heasley39376432010-03-02 12:23:39 +010044 3400/5 Series (PCH) 0x3b30 32 hard yes yes yes
45 Cougar Point (PCH) 0x1c22 32 hard yes yes yes
Jean Delvareae7b0492008-01-27 18:14:49 +010046
47 Features supported by this driver:
48 Software PEC no
49 Hardware PEC yes
50 Block buffer yes
51 Block process call transaction no
Jean Delvare63420642008-01-27 18:14:50 +010052 I2C block read transaction yes (doesn't use the block buffer)
Jean Delvareae7b0492008-01-27 18:14:49 +010053
54 See the file Documentation/i2c/busses/i2c-i801 for details.
Linus Torvalds1da177e2005-04-16 15:20:36 -070055*/
56
57/* Note: we assume there can only be one I801, with one SMBus interface */
58
Linus Torvalds1da177e2005-04-16 15:20:36 -070059#include <linux/module.h>
60#include <linux/pci.h>
61#include <linux/kernel.h>
62#include <linux/stddef.h>
63#include <linux/delay.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070064#include <linux/ioport.h>
65#include <linux/init.h>
66#include <linux/i2c.h>
Jean Delvare54fb4a052008-07-14 22:38:33 +020067#include <linux/acpi.h>
Jean Delvare1561bfe2009-01-07 14:29:17 +010068#include <linux/io.h>
Hans de Goedefa5bfab2009-03-30 21:46:44 +020069#include <linux/dmi.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070070
Linus Torvalds1da177e2005-04-16 15:20:36 -070071/* I801 SMBus address offsets */
72#define SMBHSTSTS (0 + i801_smba)
73#define SMBHSTCNT (2 + i801_smba)
74#define SMBHSTCMD (3 + i801_smba)
75#define SMBHSTADD (4 + i801_smba)
76#define SMBHSTDAT0 (5 + i801_smba)
77#define SMBHSTDAT1 (6 + i801_smba)
78#define SMBBLKDAT (7 + i801_smba)
Jean Delvareae7b0492008-01-27 18:14:49 +010079#define SMBPEC (8 + i801_smba) /* ICH3 and later */
80#define SMBAUXSTS (12 + i801_smba) /* ICH4 and later */
81#define SMBAUXCTL (13 + i801_smba) /* ICH4 and later */
Linus Torvalds1da177e2005-04-16 15:20:36 -070082
83/* PCI Address Constants */
Jean Delvare6dcc19d2006-06-12 21:53:02 +020084#define SMBBAR 4
Linus Torvalds1da177e2005-04-16 15:20:36 -070085#define SMBHSTCFG 0x040
Linus Torvalds1da177e2005-04-16 15:20:36 -070086
87/* Host configuration bits for SMBHSTCFG */
88#define SMBHSTCFG_HST_EN 1
89#define SMBHSTCFG_SMB_SMI_EN 2
90#define SMBHSTCFG_I2C_EN 4
91
Oleg Ryjkovca8b9e32007-07-12 14:12:31 +020092/* Auxillary control register bits, ICH4+ only */
93#define SMBAUXCTL_CRC 1
94#define SMBAUXCTL_E32B 2
95
96/* kill bit for SMBHSTCNT */
97#define SMBHSTCNT_KILL 2
98
Linus Torvalds1da177e2005-04-16 15:20:36 -070099/* Other settings */
100#define MAX_TIMEOUT 100
101#define ENABLE_INT9 0 /* set to 0x01 to enable - untested */
102
103/* I801 command constants */
104#define I801_QUICK 0x00
105#define I801_BYTE 0x04
106#define I801_BYTE_DATA 0x08
107#define I801_WORD_DATA 0x0C
Jean Delvareae7b0492008-01-27 18:14:49 +0100108#define I801_PROC_CALL 0x10 /* unimplemented */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700109#define I801_BLOCK_DATA 0x14
Jean Delvare63420642008-01-27 18:14:50 +0100110#define I801_I2C_BLOCK_DATA 0x18 /* ICH5 and later */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700111#define I801_BLOCK_LAST 0x34
Jean Delvare63420642008-01-27 18:14:50 +0100112#define I801_I2C_BLOCK_LAST 0x38 /* ICH5 and later */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700113#define I801_START 0x40
Jean Delvareae7b0492008-01-27 18:14:49 +0100114#define I801_PEC_EN 0x80 /* ICH3 and later */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700115
Oleg Ryjkovca8b9e32007-07-12 14:12:31 +0200116/* I801 Hosts Status register bits */
117#define SMBHSTSTS_BYTE_DONE 0x80
118#define SMBHSTSTS_INUSE_STS 0x40
119#define SMBHSTSTS_SMBALERT_STS 0x20
120#define SMBHSTSTS_FAILED 0x10
121#define SMBHSTSTS_BUS_ERR 0x08
122#define SMBHSTSTS_DEV_ERR 0x04
123#define SMBHSTSTS_INTR 0x02
124#define SMBHSTSTS_HOST_BUSY 0x01
Linus Torvalds1da177e2005-04-16 15:20:36 -0700125
Jean Delvarecf898dc2008-07-14 22:38:33 +0200126#define STATUS_FLAGS (SMBHSTSTS_BYTE_DONE | SMBHSTSTS_FAILED | \
127 SMBHSTSTS_BUS_ERR | SMBHSTSTS_DEV_ERR | \
128 SMBHSTSTS_INTR)
129
Jean Delvare6dcc19d2006-06-12 21:53:02 +0200130static unsigned long i801_smba;
Jean Delvarea5aaea32007-03-22 19:49:01 +0100131static unsigned char i801_original_hstcfg;
Jean Delvared6072f82005-09-25 16:37:04 +0200132static struct pci_driver i801_driver;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700133static struct pci_dev *I801_dev;
Jean Delvare369f6f42008-01-27 18:14:50 +0100134
135#define FEATURE_SMBUS_PEC (1 << 0)
136#define FEATURE_BLOCK_BUFFER (1 << 1)
137#define FEATURE_BLOCK_PROC (1 << 2)
138#define FEATURE_I2C_BLOCK_READ (1 << 3)
139static unsigned int i801_features;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700140
Jean Delvarecf898dc2008-07-14 22:38:33 +0200141/* Make sure the SMBus host is ready to start transmitting.
142 Return 0 if it is, -EBUSY if it is not. */
143static int i801_check_pre(void)
144{
145 int status;
146
147 status = inb_p(SMBHSTSTS);
148 if (status & SMBHSTSTS_HOST_BUSY) {
149 dev_err(&I801_dev->dev, "SMBus is busy, can't use it!\n");
150 return -EBUSY;
151 }
152
153 status &= STATUS_FLAGS;
154 if (status) {
155 dev_dbg(&I801_dev->dev, "Clearing status flags (%02x)\n",
156 status);
157 outb_p(status, SMBHSTSTS);
158 status = inb_p(SMBHSTSTS) & STATUS_FLAGS;
159 if (status) {
160 dev_err(&I801_dev->dev,
161 "Failed clearing status flags (%02x)\n",
162 status);
163 return -EBUSY;
164 }
165 }
166
167 return 0;
168}
169
170/* Convert the status register to an error code, and clear it. */
171static int i801_check_post(int status, int timeout)
172{
173 int result = 0;
174
175 /* If the SMBus is still busy, we give up */
176 if (timeout) {
177 dev_err(&I801_dev->dev, "Transaction timeout\n");
178 /* try to stop the current command */
179 dev_dbg(&I801_dev->dev, "Terminating the current operation\n");
180 outb_p(inb_p(SMBHSTCNT) | SMBHSTCNT_KILL, SMBHSTCNT);
181 msleep(1);
182 outb_p(inb_p(SMBHSTCNT) & (~SMBHSTCNT_KILL), SMBHSTCNT);
183
184 /* Check if it worked */
185 status = inb_p(SMBHSTSTS);
186 if ((status & SMBHSTSTS_HOST_BUSY) ||
187 !(status & SMBHSTSTS_FAILED))
188 dev_err(&I801_dev->dev,
189 "Failed terminating the transaction\n");
190 outb_p(STATUS_FLAGS, SMBHSTSTS);
191 return -ETIMEDOUT;
192 }
193
194 if (status & SMBHSTSTS_FAILED) {
195 result = -EIO;
196 dev_err(&I801_dev->dev, "Transaction failed\n");
197 }
198 if (status & SMBHSTSTS_DEV_ERR) {
199 result = -ENXIO;
200 dev_dbg(&I801_dev->dev, "No response\n");
201 }
202 if (status & SMBHSTSTS_BUS_ERR) {
203 result = -EAGAIN;
204 dev_dbg(&I801_dev->dev, "Lost arbitration\n");
205 }
206
207 if (result) {
208 /* Clear error flags */
209 outb_p(status & STATUS_FLAGS, SMBHSTSTS);
210 status = inb_p(SMBHSTSTS) & STATUS_FLAGS;
211 if (status) {
212 dev_warn(&I801_dev->dev, "Failed clearing status "
213 "flags at end of transaction (%02x)\n",
214 status);
215 }
216 }
217
218 return result;
219}
220
Oleg Ryjkov7edcb9a2007-07-12 14:12:31 +0200221static int i801_transaction(int xact)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700222{
Jean Delvare2b738092008-07-14 22:38:32 +0200223 int status;
Jean Delvarecf898dc2008-07-14 22:38:33 +0200224 int result;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700225 int timeout = 0;
226
Jean Delvarecf898dc2008-07-14 22:38:33 +0200227 result = i801_check_pre();
228 if (result < 0)
229 return result;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700230
Oleg Ryjkov7edcb9a2007-07-12 14:12:31 +0200231 /* the current contents of SMBHSTCNT can be overwritten, since PEC,
232 * INTREN, SMBSCMD are passed in xact */
233 outb_p(xact | I801_START, SMBHSTCNT);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700234
235 /* We will always wait for a fraction of a second! */
236 do {
237 msleep(1);
Jean Delvare2b738092008-07-14 22:38:32 +0200238 status = inb_p(SMBHSTSTS);
239 } while ((status & SMBHSTSTS_HOST_BUSY) && (timeout++ < MAX_TIMEOUT));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700240
Roel Kluin4ccc28f2009-05-05 08:39:24 +0200241 result = i801_check_post(status, timeout > MAX_TIMEOUT);
Jean Delvarecf898dc2008-07-14 22:38:33 +0200242 if (result < 0)
243 return result;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700244
Jean Delvarecf898dc2008-07-14 22:38:33 +0200245 outb_p(SMBHSTSTS_INTR, SMBHSTSTS);
246 return 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700247}
248
Oleg Ryjkovca8b9e32007-07-12 14:12:31 +0200249/* wait for INTR bit as advised by Intel */
250static void i801_wait_hwpec(void)
251{
252 int timeout = 0;
Jean Delvare2b738092008-07-14 22:38:32 +0200253 int status;
Oleg Ryjkovca8b9e32007-07-12 14:12:31 +0200254
255 do {
256 msleep(1);
Jean Delvare2b738092008-07-14 22:38:32 +0200257 status = inb_p(SMBHSTSTS);
258 } while ((!(status & SMBHSTSTS_INTR))
Oleg Ryjkovca8b9e32007-07-12 14:12:31 +0200259 && (timeout++ < MAX_TIMEOUT));
260
Roel Kluin4ccc28f2009-05-05 08:39:24 +0200261 if (timeout > MAX_TIMEOUT)
Oleg Ryjkovca8b9e32007-07-12 14:12:31 +0200262 dev_dbg(&I801_dev->dev, "PEC Timeout!\n");
Roel Kluin4ccc28f2009-05-05 08:39:24 +0200263
Jean Delvare2b738092008-07-14 22:38:32 +0200264 outb_p(status, SMBHSTSTS);
Oleg Ryjkovca8b9e32007-07-12 14:12:31 +0200265}
266
Oleg Ryjkov7edcb9a2007-07-12 14:12:31 +0200267static int i801_block_transaction_by_block(union i2c_smbus_data *data,
268 char read_write, int hwpec)
269{
270 int i, len;
David Brownell97140342008-07-14 22:38:25 +0200271 int status;
Oleg Ryjkov7edcb9a2007-07-12 14:12:31 +0200272
273 inb_p(SMBHSTCNT); /* reset the data buffer index */
274
275 /* Use 32-byte buffer to process this transaction */
276 if (read_write == I2C_SMBUS_WRITE) {
277 len = data->block[0];
278 outb_p(len, SMBHSTDAT0);
279 for (i = 0; i < len; i++)
280 outb_p(data->block[i+1], SMBBLKDAT);
281 }
282
David Brownell97140342008-07-14 22:38:25 +0200283 status = i801_transaction(I801_BLOCK_DATA | ENABLE_INT9 |
284 I801_PEC_EN * hwpec);
285 if (status)
286 return status;
Oleg Ryjkov7edcb9a2007-07-12 14:12:31 +0200287
288 if (read_write == I2C_SMBUS_READ) {
289 len = inb_p(SMBHSTDAT0);
290 if (len < 1 || len > I2C_SMBUS_BLOCK_MAX)
David Brownell97140342008-07-14 22:38:25 +0200291 return -EPROTO;
Oleg Ryjkov7edcb9a2007-07-12 14:12:31 +0200292
293 data->block[0] = len;
294 for (i = 0; i < len; i++)
295 data->block[i + 1] = inb_p(SMBBLKDAT);
296 }
297 return 0;
298}
299
300static int i801_block_transaction_byte_by_byte(union i2c_smbus_data *data,
Jean Delvare63420642008-01-27 18:14:50 +0100301 char read_write, int command,
302 int hwpec)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700303{
304 int i, len;
305 int smbcmd;
Jean Delvare2b738092008-07-14 22:38:32 +0200306 int status;
Jean Delvarecf898dc2008-07-14 22:38:33 +0200307 int result;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700308 int timeout;
Jean Delvarecf898dc2008-07-14 22:38:33 +0200309
310 result = i801_check_pre();
311 if (result < 0)
312 return result;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700313
Oleg Ryjkov7edcb9a2007-07-12 14:12:31 +0200314 len = data->block[0];
Linus Torvalds1da177e2005-04-16 15:20:36 -0700315
316 if (read_write == I2C_SMBUS_WRITE) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700317 outb_p(len, SMBHSTDAT0);
318 outb_p(data->block[1], SMBBLKDAT);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700319 }
320
321 for (i = 1; i <= len; i++) {
Jean Delvare63420642008-01-27 18:14:50 +0100322 if (i == len && read_write == I2C_SMBUS_READ) {
323 if (command == I2C_SMBUS_I2C_BLOCK_DATA)
324 smbcmd = I801_I2C_BLOCK_LAST;
325 else
326 smbcmd = I801_BLOCK_LAST;
327 } else {
328 if (command == I2C_SMBUS_I2C_BLOCK_DATA
329 && read_write == I2C_SMBUS_READ)
330 smbcmd = I801_I2C_BLOCK_DATA;
331 else
332 smbcmd = I801_BLOCK_DATA;
333 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700334 outb_p(smbcmd | ENABLE_INT9, SMBHSTCNT);
335
Linus Torvalds1da177e2005-04-16 15:20:36 -0700336 if (i == 1)
337 outb_p(inb(SMBHSTCNT) | I801_START, SMBHSTCNT);
338
339 /* We will always wait for a fraction of a second! */
340 timeout = 0;
341 do {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700342 msleep(1);
Jean Delvare2b738092008-07-14 22:38:32 +0200343 status = inb_p(SMBHSTSTS);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700344 }
Jean Delvare2b738092008-07-14 22:38:32 +0200345 while ((!(status & SMBHSTSTS_BYTE_DONE))
Oleg Ryjkovca8b9e32007-07-12 14:12:31 +0200346 && (timeout++ < MAX_TIMEOUT));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700347
Roel Kluin4ccc28f2009-05-05 08:39:24 +0200348 result = i801_check_post(status, timeout > MAX_TIMEOUT);
Jean Delvarecf898dc2008-07-14 22:38:33 +0200349 if (result < 0)
350 return result;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700351
Jean Delvare63420642008-01-27 18:14:50 +0100352 if (i == 1 && read_write == I2C_SMBUS_READ
353 && command != I2C_SMBUS_I2C_BLOCK_DATA) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700354 len = inb_p(SMBHSTDAT0);
Jean Delvarecf898dc2008-07-14 22:38:33 +0200355 if (len < 1 || len > I2C_SMBUS_BLOCK_MAX) {
356 dev_err(&I801_dev->dev,
357 "Illegal SMBus block read size %d\n",
358 len);
359 /* Recover */
360 while (inb_p(SMBHSTSTS) & SMBHSTSTS_HOST_BUSY)
361 outb_p(SMBHSTSTS_BYTE_DONE, SMBHSTSTS);
362 outb_p(SMBHSTSTS_INTR, SMBHSTSTS);
David Brownell97140342008-07-14 22:38:25 +0200363 return -EPROTO;
Jean Delvarecf898dc2008-07-14 22:38:33 +0200364 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700365 data->block[0] = len;
366 }
367
368 /* Retrieve/store value in SMBBLKDAT */
369 if (read_write == I2C_SMBUS_READ)
370 data->block[i] = inb_p(SMBBLKDAT);
371 if (read_write == I2C_SMBUS_WRITE && i+1 <= len)
372 outb_p(data->block[i+1], SMBBLKDAT);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700373
Jean Delvarecf898dc2008-07-14 22:38:33 +0200374 /* signals SMBBLKDAT ready */
375 outb_p(SMBHSTSTS_BYTE_DONE | SMBHSTSTS_INTR, SMBHSTSTS);
Oleg Ryjkov7edcb9a2007-07-12 14:12:31 +0200376 }
Jean Delvarecf898dc2008-07-14 22:38:33 +0200377
378 return 0;
Oleg Ryjkov7edcb9a2007-07-12 14:12:31 +0200379}
380
381static int i801_set_block_buffer_mode(void)
382{
383 outb_p(inb_p(SMBAUXCTL) | SMBAUXCTL_E32B, SMBAUXCTL);
384 if ((inb_p(SMBAUXCTL) & SMBAUXCTL_E32B) == 0)
David Brownell97140342008-07-14 22:38:25 +0200385 return -EIO;
Oleg Ryjkov7edcb9a2007-07-12 14:12:31 +0200386 return 0;
387}
388
389/* Block transaction function */
390static int i801_block_transaction(union i2c_smbus_data *data, char read_write,
391 int command, int hwpec)
392{
393 int result = 0;
394 unsigned char hostc;
395
396 if (command == I2C_SMBUS_I2C_BLOCK_DATA) {
397 if (read_write == I2C_SMBUS_WRITE) {
398 /* set I2C_EN bit in configuration register */
399 pci_read_config_byte(I801_dev, SMBHSTCFG, &hostc);
400 pci_write_config_byte(I801_dev, SMBHSTCFG,
401 hostc | SMBHSTCFG_I2C_EN);
Jean Delvare63420642008-01-27 18:14:50 +0100402 } else if (!(i801_features & FEATURE_I2C_BLOCK_READ)) {
Oleg Ryjkov7edcb9a2007-07-12 14:12:31 +0200403 dev_err(&I801_dev->dev,
Jean Delvare63420642008-01-27 18:14:50 +0100404 "I2C block read is unsupported!\n");
David Brownell97140342008-07-14 22:38:25 +0200405 return -EOPNOTSUPP;
Oleg Ryjkov7edcb9a2007-07-12 14:12:31 +0200406 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700407 }
408
Jean Delvare63420642008-01-27 18:14:50 +0100409 if (read_write == I2C_SMBUS_WRITE
410 || command == I2C_SMBUS_I2C_BLOCK_DATA) {
Oleg Ryjkov7edcb9a2007-07-12 14:12:31 +0200411 if (data->block[0] < 1)
412 data->block[0] = 1;
413 if (data->block[0] > I2C_SMBUS_BLOCK_MAX)
414 data->block[0] = I2C_SMBUS_BLOCK_MAX;
415 } else {
Jean Delvare63420642008-01-27 18:14:50 +0100416 data->block[0] = 32; /* max for SMBus block reads */
Oleg Ryjkov7edcb9a2007-07-12 14:12:31 +0200417 }
418
Jean Delvarec074c392010-03-13 20:56:53 +0100419 /* Experience has shown that the block buffer can only be used for
420 SMBus (not I2C) block transactions, even though the datasheet
421 doesn't mention this limitation. */
Jean Delvare369f6f42008-01-27 18:14:50 +0100422 if ((i801_features & FEATURE_BLOCK_BUFFER)
Jean Delvarec074c392010-03-13 20:56:53 +0100423 && command != I2C_SMBUS_I2C_BLOCK_DATA
Jean Delvare369f6f42008-01-27 18:14:50 +0100424 && i801_set_block_buffer_mode() == 0)
Oleg Ryjkov7edcb9a2007-07-12 14:12:31 +0200425 result = i801_block_transaction_by_block(data, read_write,
426 hwpec);
427 else
428 result = i801_block_transaction_byte_by_byte(data, read_write,
Jean Delvare63420642008-01-27 18:14:50 +0100429 command, hwpec);
Oleg Ryjkov7edcb9a2007-07-12 14:12:31 +0200430
431 if (result == 0 && hwpec)
Oleg Ryjkovca8b9e32007-07-12 14:12:31 +0200432 i801_wait_hwpec();
Linus Torvalds1da177e2005-04-16 15:20:36 -0700433
Jean Delvare63420642008-01-27 18:14:50 +0100434 if (command == I2C_SMBUS_I2C_BLOCK_DATA
435 && read_write == I2C_SMBUS_WRITE) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700436 /* restore saved configuration register value */
437 pci_write_config_byte(I801_dev, SMBHSTCFG, hostc);
438 }
439 return result;
440}
441
David Brownell97140342008-07-14 22:38:25 +0200442/* Return negative errno on error. */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700443static s32 i801_access(struct i2c_adapter * adap, u16 addr,
444 unsigned short flags, char read_write, u8 command,
445 int size, union i2c_smbus_data * data)
446{
Jean Delvaree8aac4a2005-10-26 21:34:42 +0200447 int hwpec;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700448 int block = 0;
449 int ret, xact = 0;
450
Jean Delvare369f6f42008-01-27 18:14:50 +0100451 hwpec = (i801_features & FEATURE_SMBUS_PEC) && (flags & I2C_CLIENT_PEC)
Jean Delvaree8aac4a2005-10-26 21:34:42 +0200452 && size != I2C_SMBUS_QUICK
453 && size != I2C_SMBUS_I2C_BLOCK_DATA;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700454
455 switch (size) {
456 case I2C_SMBUS_QUICK:
457 outb_p(((addr & 0x7f) << 1) | (read_write & 0x01),
458 SMBHSTADD);
459 xact = I801_QUICK;
460 break;
461 case I2C_SMBUS_BYTE:
462 outb_p(((addr & 0x7f) << 1) | (read_write & 0x01),
463 SMBHSTADD);
464 if (read_write == I2C_SMBUS_WRITE)
465 outb_p(command, SMBHSTCMD);
466 xact = I801_BYTE;
467 break;
468 case I2C_SMBUS_BYTE_DATA:
469 outb_p(((addr & 0x7f) << 1) | (read_write & 0x01),
470 SMBHSTADD);
471 outb_p(command, SMBHSTCMD);
472 if (read_write == I2C_SMBUS_WRITE)
473 outb_p(data->byte, SMBHSTDAT0);
474 xact = I801_BYTE_DATA;
475 break;
476 case I2C_SMBUS_WORD_DATA:
477 outb_p(((addr & 0x7f) << 1) | (read_write & 0x01),
478 SMBHSTADD);
479 outb_p(command, SMBHSTCMD);
480 if (read_write == I2C_SMBUS_WRITE) {
481 outb_p(data->word & 0xff, SMBHSTDAT0);
482 outb_p((data->word & 0xff00) >> 8, SMBHSTDAT1);
483 }
484 xact = I801_WORD_DATA;
485 break;
486 case I2C_SMBUS_BLOCK_DATA:
Linus Torvalds1da177e2005-04-16 15:20:36 -0700487 outb_p(((addr & 0x7f) << 1) | (read_write & 0x01),
488 SMBHSTADD);
489 outb_p(command, SMBHSTCMD);
490 block = 1;
491 break;
Jean Delvare63420642008-01-27 18:14:50 +0100492 case I2C_SMBUS_I2C_BLOCK_DATA:
493 /* NB: page 240 of ICH5 datasheet shows that the R/#W
494 * bit should be cleared here, even when reading */
495 outb_p((addr & 0x7f) << 1, SMBHSTADD);
496 if (read_write == I2C_SMBUS_READ) {
497 /* NB: page 240 of ICH5 datasheet also shows
498 * that DATA1 is the cmd field when reading */
499 outb_p(command, SMBHSTDAT1);
500 } else
501 outb_p(command, SMBHSTCMD);
502 block = 1;
503 break;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700504 default:
505 dev_err(&I801_dev->dev, "Unsupported transaction %d\n", size);
David Brownell97140342008-07-14 22:38:25 +0200506 return -EOPNOTSUPP;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700507 }
508
Oleg Ryjkovca8b9e32007-07-12 14:12:31 +0200509 if (hwpec) /* enable/disable hardware PEC */
510 outb_p(inb_p(SMBAUXCTL) | SMBAUXCTL_CRC, SMBAUXCTL);
511 else
512 outb_p(inb_p(SMBAUXCTL) & (~SMBAUXCTL_CRC), SMBAUXCTL);
Jean Delvaree8aac4a2005-10-26 21:34:42 +0200513
Linus Torvalds1da177e2005-04-16 15:20:36 -0700514 if(block)
Jean Delvare585b3162005-10-26 21:31:15 +0200515 ret = i801_block_transaction(data, read_write, size, hwpec);
Oleg Ryjkov7edcb9a2007-07-12 14:12:31 +0200516 else
517 ret = i801_transaction(xact | ENABLE_INT9);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700518
Jean Delvarec79cfba2006-04-20 02:43:18 -0700519 /* Some BIOSes don't like it when PEC is enabled at reboot or resume
Oleg Ryjkov7edcb9a2007-07-12 14:12:31 +0200520 time, so we forcibly disable it after every transaction. Turn off
521 E32B for the same reason. */
Jean Delvarea0921b62008-01-27 18:14:50 +0100522 if (hwpec || block)
Oleg Ryjkov7edcb9a2007-07-12 14:12:31 +0200523 outb_p(inb_p(SMBAUXCTL) & ~(SMBAUXCTL_CRC | SMBAUXCTL_E32B),
524 SMBAUXCTL);
Jean Delvarec79cfba2006-04-20 02:43:18 -0700525
Linus Torvalds1da177e2005-04-16 15:20:36 -0700526 if(block)
527 return ret;
528 if(ret)
David Brownell97140342008-07-14 22:38:25 +0200529 return ret;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700530 if ((read_write == I2C_SMBUS_WRITE) || (xact == I801_QUICK))
531 return 0;
532
533 switch (xact & 0x7f) {
534 case I801_BYTE: /* Result put in SMBHSTDAT0 */
535 case I801_BYTE_DATA:
536 data->byte = inb_p(SMBHSTDAT0);
537 break;
538 case I801_WORD_DATA:
539 data->word = inb_p(SMBHSTDAT0) + (inb_p(SMBHSTDAT1) << 8);
540 break;
541 }
542 return 0;
543}
544
545
546static u32 i801_func(struct i2c_adapter *adapter)
547{
548 return I2C_FUNC_SMBUS_QUICK | I2C_FUNC_SMBUS_BYTE |
Jean Delvare369f6f42008-01-27 18:14:50 +0100549 I2C_FUNC_SMBUS_BYTE_DATA | I2C_FUNC_SMBUS_WORD_DATA |
550 I2C_FUNC_SMBUS_BLOCK_DATA | I2C_FUNC_SMBUS_WRITE_I2C_BLOCK |
Jean Delvare63420642008-01-27 18:14:50 +0100551 ((i801_features & FEATURE_SMBUS_PEC) ? I2C_FUNC_SMBUS_PEC : 0) |
552 ((i801_features & FEATURE_I2C_BLOCK_READ) ?
553 I2C_FUNC_SMBUS_READ_I2C_BLOCK : 0);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700554}
555
Jean Delvare8f9082c2006-09-03 22:39:46 +0200556static const struct i2c_algorithm smbus_algorithm = {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700557 .smbus_xfer = i801_access,
558 .functionality = i801_func,
559};
560
561static struct i2c_adapter i801_adapter = {
562 .owner = THIS_MODULE,
Jean Delvare3401b2f2008-07-14 22:38:29 +0200563 .class = I2C_CLASS_HWMON | I2C_CLASS_SPD,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700564 .algo = &smbus_algorithm,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700565};
566
Márton Németh4111ecd2010-03-02 12:23:37 +0100567static const struct pci_device_id i801_ids[] = {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700568 { PCI_DEVICE(PCI_VENDOR_ID_INTEL, PCI_DEVICE_ID_INTEL_82801AA_3) },
569 { PCI_DEVICE(PCI_VENDOR_ID_INTEL, PCI_DEVICE_ID_INTEL_82801AB_3) },
570 { PCI_DEVICE(PCI_VENDOR_ID_INTEL, PCI_DEVICE_ID_INTEL_82801BA_2) },
571 { PCI_DEVICE(PCI_VENDOR_ID_INTEL, PCI_DEVICE_ID_INTEL_82801CA_3) },
572 { PCI_DEVICE(PCI_VENDOR_ID_INTEL, PCI_DEVICE_ID_INTEL_82801DB_3) },
573 { PCI_DEVICE(PCI_VENDOR_ID_INTEL, PCI_DEVICE_ID_INTEL_82801EB_3) },
574 { PCI_DEVICE(PCI_VENDOR_ID_INTEL, PCI_DEVICE_ID_INTEL_ESB_4) },
575 { PCI_DEVICE(PCI_VENDOR_ID_INTEL, PCI_DEVICE_ID_INTEL_ICH6_16) },
576 { PCI_DEVICE(PCI_VENDOR_ID_INTEL, PCI_DEVICE_ID_INTEL_ICH7_17) },
Jason Gastonb0a70b52005-04-16 15:24:45 -0700577 { PCI_DEVICE(PCI_VENDOR_ID_INTEL, PCI_DEVICE_ID_INTEL_ESB2_17) },
Jason Gaston8254fc42006-01-09 10:58:08 -0800578 { PCI_DEVICE(PCI_VENDOR_ID_INTEL, PCI_DEVICE_ID_INTEL_ICH8_5) },
Jason Gastonadbc2a12006-11-22 15:19:12 -0800579 { PCI_DEVICE(PCI_VENDOR_ID_INTEL, PCI_DEVICE_ID_INTEL_ICH9_6) },
Jason Gastone07bc672007-10-13 23:56:31 +0200580 { PCI_DEVICE(PCI_VENDOR_ID_INTEL, PCI_DEVICE_ID_INTEL_TOLAPAI_1) },
Gaston, Jason Dd28dc712008-02-24 20:03:42 +0100581 { PCI_DEVICE(PCI_VENDOR_ID_INTEL, PCI_DEVICE_ID_INTEL_ICH10_4) },
582 { PCI_DEVICE(PCI_VENDOR_ID_INTEL, PCI_DEVICE_ID_INTEL_ICH10_5) },
Seth Heasleyc429a242008-10-22 20:21:29 +0200583 { PCI_DEVICE(PCI_VENDOR_ID_INTEL, PCI_DEVICE_ID_INTEL_PCH_SMBUS) },
Seth Heasley39376432010-03-02 12:23:39 +0100584 { PCI_DEVICE(PCI_VENDOR_ID_INTEL, PCI_DEVICE_ID_INTEL_CPT_SMBUS) },
Linus Torvalds1da177e2005-04-16 15:20:36 -0700585 { 0, }
586};
587
588MODULE_DEVICE_TABLE (pci, i801_ids);
589
Jean Delvare1561bfe2009-01-07 14:29:17 +0100590#if defined CONFIG_INPUT_APANEL || defined CONFIG_INPUT_APANEL_MODULE
591static unsigned char apanel_addr;
592
593/* Scan the system ROM for the signature "FJKEYINF" */
594static __init const void __iomem *bios_signature(const void __iomem *bios)
595{
596 ssize_t offset;
597 const unsigned char signature[] = "FJKEYINF";
598
599 for (offset = 0; offset < 0x10000; offset += 0x10) {
600 if (check_signature(bios + offset, signature,
601 sizeof(signature)-1))
602 return bios + offset;
603 }
604 return NULL;
605}
606
607static void __init input_apanel_init(void)
608{
609 void __iomem *bios;
610 const void __iomem *p;
611
612 bios = ioremap(0xF0000, 0x10000); /* Can't fail */
613 p = bios_signature(bios);
614 if (p) {
615 /* just use the first address */
616 apanel_addr = readb(p + 8 + 3) >> 1;
617 }
618 iounmap(bios);
619}
620#else
621static void __init input_apanel_init(void) {}
622#endif
623
Hans de Goedefa5bfab2009-03-30 21:46:44 +0200624#if defined CONFIG_SENSORS_FSCHMD || defined CONFIG_SENSORS_FSCHMD_MODULE
625struct dmi_onboard_device_info {
626 const char *name;
627 u8 type;
628 unsigned short i2c_addr;
629 const char *i2c_type;
630};
631
632static struct dmi_onboard_device_info __devinitdata dmi_devices[] = {
633 { "Syleus", DMI_DEV_TYPE_OTHER, 0x73, "fscsyl" },
634 { "Hermes", DMI_DEV_TYPE_OTHER, 0x73, "fscher" },
635 { "Hades", DMI_DEV_TYPE_OTHER, 0x73, "fschds" },
636};
637
638static void __devinit dmi_check_onboard_device(u8 type, const char *name,
639 struct i2c_adapter *adap)
640{
641 int i;
642 struct i2c_board_info info;
643
644 for (i = 0; i < ARRAY_SIZE(dmi_devices); i++) {
645 /* & ~0x80, ignore enabled/disabled bit */
646 if ((type & ~0x80) != dmi_devices[i].type)
647 continue;
648 if (strcmp(name, dmi_devices[i].name))
649 continue;
650
651 memset(&info, 0, sizeof(struct i2c_board_info));
652 info.addr = dmi_devices[i].i2c_addr;
653 strlcpy(info.type, dmi_devices[i].i2c_type, I2C_NAME_SIZE);
654 i2c_new_device(adap, &info);
655 break;
656 }
657}
658
659/* We use our own function to check for onboard devices instead of
660 dmi_find_device() as some buggy BIOS's have the devices we are interested
661 in marked as disabled */
662static void __devinit dmi_check_onboard_devices(const struct dmi_header *dm,
663 void *adap)
664{
665 int i, count;
666
667 if (dm->type != 10)
668 return;
669
670 count = (dm->length - sizeof(struct dmi_header)) / 2;
671 for (i = 0; i < count; i++) {
672 const u8 *d = (char *)(dm + 1) + (i * 2);
673 const char *name = ((char *) dm) + dm->length;
674 u8 type = d[0];
675 u8 s = d[1];
676
677 if (!s)
678 continue;
679 s--;
680 while (s > 0 && name[0]) {
681 name += strlen(name) + 1;
682 s--;
683 }
684 if (name[0] == 0) /* Bogus string reference */
685 continue;
686
687 dmi_check_onboard_device(type, name, adap);
688 }
689}
690#endif
691
Linus Torvalds1da177e2005-04-16 15:20:36 -0700692static int __devinit i801_probe(struct pci_dev *dev, const struct pci_device_id *id)
693{
Jean Delvare02dd7ae2006-06-12 21:53:41 +0200694 unsigned char temp;
Jean Delvare455f3322006-06-12 21:52:02 +0200695 int err;
Hans de Goedefa5bfab2009-03-30 21:46:44 +0200696#if defined CONFIG_SENSORS_FSCHMD || defined CONFIG_SENSORS_FSCHMD_MODULE
697 const char *vendor;
698#endif
Linus Torvalds1da177e2005-04-16 15:20:36 -0700699
Jean Delvare02dd7ae2006-06-12 21:53:41 +0200700 I801_dev = dev;
Jean Delvare369f6f42008-01-27 18:14:50 +0100701 i801_features = 0;
Jean Delvare250d1bd2006-12-10 21:21:33 +0100702 switch (dev->device) {
Jean Delvare250d1bd2006-12-10 21:21:33 +0100703 case PCI_DEVICE_ID_INTEL_82801EB_3:
704 case PCI_DEVICE_ID_INTEL_ESB_4:
705 case PCI_DEVICE_ID_INTEL_ICH6_16:
706 case PCI_DEVICE_ID_INTEL_ICH7_17:
707 case PCI_DEVICE_ID_INTEL_ESB2_17:
708 case PCI_DEVICE_ID_INTEL_ICH8_5:
709 case PCI_DEVICE_ID_INTEL_ICH9_6:
Gaston, Jason Dd28dc712008-02-24 20:03:42 +0100710 case PCI_DEVICE_ID_INTEL_TOLAPAI_1:
711 case PCI_DEVICE_ID_INTEL_ICH10_4:
712 case PCI_DEVICE_ID_INTEL_ICH10_5:
Seth Heasleyc429a242008-10-22 20:21:29 +0200713 case PCI_DEVICE_ID_INTEL_PCH_SMBUS:
Seth Heasley39376432010-03-02 12:23:39 +0100714 case PCI_DEVICE_ID_INTEL_CPT_SMBUS:
Jean Delvare63420642008-01-27 18:14:50 +0100715 i801_features |= FEATURE_I2C_BLOCK_READ;
716 /* fall through */
717 case PCI_DEVICE_ID_INTEL_82801DB_3:
Jean Delvare369f6f42008-01-27 18:14:50 +0100718 i801_features |= FEATURE_SMBUS_PEC;
719 i801_features |= FEATURE_BLOCK_BUFFER;
Jean Delvare250d1bd2006-12-10 21:21:33 +0100720 break;
Jean Delvare250d1bd2006-12-10 21:21:33 +0100721 }
Jean Delvare02dd7ae2006-06-12 21:53:41 +0200722
723 err = pci_enable_device(dev);
724 if (err) {
725 dev_err(&dev->dev, "Failed to enable SMBus PCI device (%d)\n",
726 err);
727 goto exit;
728 }
729
730 /* Determine the address of the SMBus area */
731 i801_smba = pci_resource_start(dev, SMBBAR);
732 if (!i801_smba) {
733 dev_err(&dev->dev, "SMBus base address uninitialized, "
734 "upgrade BIOS\n");
735 err = -ENODEV;
Daniel Ritzd6fcb3b2006-06-27 18:40:54 +0200736 goto exit;
Jean Delvare02dd7ae2006-06-12 21:53:41 +0200737 }
738
Jean Delvare54fb4a052008-07-14 22:38:33 +0200739 err = acpi_check_resource_conflict(&dev->resource[SMBBAR]);
Jean Delvare18669ea2009-10-04 22:53:45 +0200740 if (err) {
741 err = -ENODEV;
Jean Delvare54fb4a052008-07-14 22:38:33 +0200742 goto exit;
Jean Delvare18669ea2009-10-04 22:53:45 +0200743 }
Jean Delvare54fb4a052008-07-14 22:38:33 +0200744
Jean Delvare02dd7ae2006-06-12 21:53:41 +0200745 err = pci_request_region(dev, SMBBAR, i801_driver.name);
746 if (err) {
747 dev_err(&dev->dev, "Failed to request SMBus region "
Andrew Morton598736c2006-06-30 01:56:20 -0700748 "0x%lx-0x%Lx\n", i801_smba,
749 (unsigned long long)pci_resource_end(dev, SMBBAR));
Daniel Ritzd6fcb3b2006-06-27 18:40:54 +0200750 goto exit;
Jean Delvare02dd7ae2006-06-12 21:53:41 +0200751 }
752
753 pci_read_config_byte(I801_dev, SMBHSTCFG, &temp);
Jean Delvarea5aaea32007-03-22 19:49:01 +0100754 i801_original_hstcfg = temp;
Jean Delvare02dd7ae2006-06-12 21:53:41 +0200755 temp &= ~SMBHSTCFG_I2C_EN; /* SMBus timing */
756 if (!(temp & SMBHSTCFG_HST_EN)) {
757 dev_info(&dev->dev, "Enabling SMBus device\n");
758 temp |= SMBHSTCFG_HST_EN;
759 }
760 pci_write_config_byte(I801_dev, SMBHSTCFG, temp);
761
762 if (temp & SMBHSTCFG_SMB_SMI_EN)
763 dev_dbg(&dev->dev, "SMBus using interrupt SMI#\n");
764 else
765 dev_dbg(&dev->dev, "SMBus using PCI Interrupt\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -0700766
Jean Delvarea0921b62008-01-27 18:14:50 +0100767 /* Clear special mode bits */
768 if (i801_features & (FEATURE_SMBUS_PEC | FEATURE_BLOCK_BUFFER))
769 outb_p(inb_p(SMBAUXCTL) & ~(SMBAUXCTL_CRC | SMBAUXCTL_E32B),
770 SMBAUXCTL);
771
Robert P. J. Day405ae7d2007-02-17 19:13:42 +0100772 /* set up the sysfs linkage to our parent device */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700773 i801_adapter.dev.parent = &dev->dev;
774
Jean Delvare7e2193a2009-12-06 17:06:27 +0100775 /* Retry up to 3 times on lost arbitration */
776 i801_adapter.retries = 3;
777
David Brownell2096b952007-05-01 23:26:28 +0200778 snprintf(i801_adapter.name, sizeof(i801_adapter.name),
Jean Delvare6dcc19d2006-06-12 21:53:02 +0200779 "SMBus I801 adapter at %04lx", i801_smba);
Jean Delvare02dd7ae2006-06-12 21:53:41 +0200780 err = i2c_add_adapter(&i801_adapter);
781 if (err) {
782 dev_err(&dev->dev, "Failed to add SMBus adapter\n");
Daniel Ritzd6fcb3b2006-06-27 18:40:54 +0200783 goto exit_release;
Jean Delvare02dd7ae2006-06-12 21:53:41 +0200784 }
Jean Delvare1561bfe2009-01-07 14:29:17 +0100785
786 /* Register optional slaves */
787#if defined CONFIG_INPUT_APANEL || defined CONFIG_INPUT_APANEL_MODULE
788 if (apanel_addr) {
789 struct i2c_board_info info;
790
791 memset(&info, 0, sizeof(struct i2c_board_info));
792 info.addr = apanel_addr;
793 strlcpy(info.type, "fujitsu_apanel", I2C_NAME_SIZE);
794 i2c_new_device(&i801_adapter, &info);
795 }
796#endif
Hans de Goedefa5bfab2009-03-30 21:46:44 +0200797#if defined CONFIG_SENSORS_FSCHMD || defined CONFIG_SENSORS_FSCHMD_MODULE
798 vendor = dmi_get_system_info(DMI_BOARD_VENDOR);
799 if (vendor && !strcmp(vendor, "FUJITSU SIEMENS"))
800 dmi_walk(dmi_check_onboard_devices, &i801_adapter);
801#endif
Jean Delvare1561bfe2009-01-07 14:29:17 +0100802
Daniel Ritzd6fcb3b2006-06-27 18:40:54 +0200803 return 0;
Jean Delvare02dd7ae2006-06-12 21:53:41 +0200804
Daniel Ritzd6fcb3b2006-06-27 18:40:54 +0200805exit_release:
806 pci_release_region(dev, SMBBAR);
Jean Delvare02dd7ae2006-06-12 21:53:41 +0200807exit:
808 return err;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700809}
810
811static void __devexit i801_remove(struct pci_dev *dev)
812{
813 i2c_del_adapter(&i801_adapter);
Jean Delvarea5aaea32007-03-22 19:49:01 +0100814 pci_write_config_byte(I801_dev, SMBHSTCFG, i801_original_hstcfg);
Jean Delvare6dcc19d2006-06-12 21:53:02 +0200815 pci_release_region(dev, SMBBAR);
Daniel Ritzd6fcb3b2006-06-27 18:40:54 +0200816 /*
817 * do not call pci_disable_device(dev) since it can cause hard hangs on
818 * some systems during power-off (eg. Fujitsu-Siemens Lifebook E8010)
819 */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700820}
821
Jean Delvarea5aaea32007-03-22 19:49:01 +0100822#ifdef CONFIG_PM
823static int i801_suspend(struct pci_dev *dev, pm_message_t mesg)
824{
825 pci_save_state(dev);
826 pci_write_config_byte(dev, SMBHSTCFG, i801_original_hstcfg);
827 pci_set_power_state(dev, pci_choose_state(dev, mesg));
828 return 0;
829}
830
831static int i801_resume(struct pci_dev *dev)
832{
833 pci_set_power_state(dev, PCI_D0);
834 pci_restore_state(dev);
835 return pci_enable_device(dev);
836}
837#else
838#define i801_suspend NULL
839#define i801_resume NULL
840#endif
841
Linus Torvalds1da177e2005-04-16 15:20:36 -0700842static struct pci_driver i801_driver = {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700843 .name = "i801_smbus",
844 .id_table = i801_ids,
845 .probe = i801_probe,
846 .remove = __devexit_p(i801_remove),
Jean Delvarea5aaea32007-03-22 19:49:01 +0100847 .suspend = i801_suspend,
848 .resume = i801_resume,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700849};
850
851static int __init i2c_i801_init(void)
852{
Jean Delvare1561bfe2009-01-07 14:29:17 +0100853 input_apanel_init();
Linus Torvalds1da177e2005-04-16 15:20:36 -0700854 return pci_register_driver(&i801_driver);
855}
856
857static void __exit i2c_i801_exit(void)
858{
859 pci_unregister_driver(&i801_driver);
860}
861
Jean Delvare63420642008-01-27 18:14:50 +0100862MODULE_AUTHOR("Mark D. Studebaker <mdsxyz123@yahoo.com>, "
863 "Jean Delvare <khali@linux-fr.org>");
Linus Torvalds1da177e2005-04-16 15:20:36 -0700864MODULE_DESCRIPTION("I801 SMBus driver");
865MODULE_LICENSE("GPL");
866
867module_init(i2c_i801_init);
868module_exit(i2c_i801_exit);