blob: 898dcf9c7adeaac26d932b6e8c6a6e8d90e9be66 [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 Delvare84c1af42012-03-26 21:47:19 +02005 Copyright (C) 2007 - 2012 Jean Delvare <khali@linux-fr.org>
David Woodhouse0cd96eb2010-10-31 21:06:59 +01006 Copyright (C) 2010 Intel Corporation,
7 David Woodhouse <dwmw2@infradead.org>
Linus Torvalds1da177e2005-04-16 15:20:36 -07008
9 This program is free software; you can redistribute it and/or modify
10 it under the terms of the GNU General Public License as published by
11 the Free Software Foundation; either version 2 of the License, or
12 (at your option) any later version.
13
14 This program is distributed in the hope that it will be useful,
15 but WITHOUT ANY WARRANTY; without even the implied warranty of
16 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17 GNU General Public License for more details.
18
19 You should have received a copy of the GNU General Public License
20 along with this program; if not, write to the Free Software
21 Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
22*/
23
24/*
Jean Delvareae7b0492008-01-27 18:14:49 +010025 Supports the following Intel I/O Controller Hubs (ICH):
26
27 I/O Block I2C
28 region SMBus Block proc. block
29 Chip name PCI ID size PEC buffer call read
30 ----------------------------------------------------------------------
31 82801AA (ICH) 0x2413 16 no no no no
32 82801AB (ICH0) 0x2423 16 no no no no
33 82801BA (ICH2) 0x2443 16 no no no no
34 82801CA (ICH3) 0x2483 32 soft no no no
35 82801DB (ICH4) 0x24c3 32 hard yes no no
36 82801E (ICH5) 0x24d3 32 hard yes yes yes
37 6300ESB 0x25a4 32 hard yes yes yes
38 82801F (ICH6) 0x266a 32 hard yes yes yes
39 6310ESB/6320ESB 0x269b 32 hard yes yes yes
40 82801G (ICH7) 0x27da 32 hard yes yes yes
41 82801H (ICH8) 0x283e 32 hard yes yes yes
42 82801I (ICH9) 0x2930 32 hard yes yes yes
Seth Heasleycb04e952010-10-04 13:27:14 -070043 EP80579 (Tolapai) 0x5032 32 hard yes yes yes
Gaston, Jason Dd28dc712008-02-24 20:03:42 +010044 ICH10 0x3a30 32 hard yes yes yes
45 ICH10 0x3a60 32 hard yes yes yes
Seth Heasleycb04e952010-10-04 13:27:14 -070046 5/3400 Series (PCH) 0x3b30 32 hard yes yes yes
Seth Heasley662cda82011-03-20 14:50:53 +010047 6 Series (PCH) 0x1c22 32 hard yes yes yes
Seth Heasleye30d9852010-10-31 21:06:59 +010048 Patsburg (PCH) 0x1d22 32 hard yes yes yes
David Woodhouse55fee8d2010-10-31 21:07:00 +010049 Patsburg (PCH) IDF 0x1d70 32 hard yes yes yes
50 Patsburg (PCH) IDF 0x1d71 32 hard yes yes yes
51 Patsburg (PCH) IDF 0x1d72 32 hard yes yes yes
Seth Heasley662cda82011-03-20 14:50:53 +010052 DH89xxCC (PCH) 0x2330 32 hard yes yes yes
Seth Heasley6e2a8512011-05-24 20:58:49 +020053 Panther Point (PCH) 0x1e22 32 hard yes yes yes
Seth Heasley062737f2012-03-26 21:47:19 +020054 Lynx Point (PCH) 0x8c22 32 hard yes yes yes
Jean Delvareae7b0492008-01-27 18:14:49 +010055
56 Features supported by this driver:
57 Software PEC no
58 Hardware PEC yes
59 Block buffer yes
60 Block process call transaction no
Jean Delvare63420642008-01-27 18:14:50 +010061 I2C block read transaction yes (doesn't use the block buffer)
David Woodhouse55fee8d2010-10-31 21:07:00 +010062 Slave mode no
Daniel Kurtz636752b2012-07-24 14:13:58 +020063 Interrupt processing yes
Jean Delvareae7b0492008-01-27 18:14:49 +010064
65 See the file Documentation/i2c/busses/i2c-i801 for details.
Linus Torvalds1da177e2005-04-16 15:20:36 -070066*/
67
Daniel Kurtz636752b2012-07-24 14:13:58 +020068#include <linux/interrupt.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070069#include <linux/module.h>
70#include <linux/pci.h>
71#include <linux/kernel.h>
72#include <linux/stddef.h>
73#include <linux/delay.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070074#include <linux/ioport.h>
75#include <linux/init.h>
76#include <linux/i2c.h>
Jean Delvare54fb4a052008-07-14 22:38:33 +020077#include <linux/acpi.h>
Jean Delvare1561bfe2009-01-07 14:29:17 +010078#include <linux/io.h>
Hans de Goedefa5bfab2009-03-30 21:46:44 +020079#include <linux/dmi.h>
Ben Hutchings665a96b2011-01-10 22:11:22 +010080#include <linux/slab.h>
Daniel Kurtz636752b2012-07-24 14:13:58 +020081#include <linux/wait.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070082
Linus Torvalds1da177e2005-04-16 15:20:36 -070083/* I801 SMBus address offsets */
David Woodhouse0cd96eb2010-10-31 21:06:59 +010084#define SMBHSTSTS(p) (0 + (p)->smba)
85#define SMBHSTCNT(p) (2 + (p)->smba)
86#define SMBHSTCMD(p) (3 + (p)->smba)
87#define SMBHSTADD(p) (4 + (p)->smba)
88#define SMBHSTDAT0(p) (5 + (p)->smba)
89#define SMBHSTDAT1(p) (6 + (p)->smba)
90#define SMBBLKDAT(p) (7 + (p)->smba)
91#define SMBPEC(p) (8 + (p)->smba) /* ICH3 and later */
92#define SMBAUXSTS(p) (12 + (p)->smba) /* ICH4 and later */
93#define SMBAUXCTL(p) (13 + (p)->smba) /* ICH4 and later */
Linus Torvalds1da177e2005-04-16 15:20:36 -070094
95/* PCI Address Constants */
Jean Delvare6dcc19d2006-06-12 21:53:02 +020096#define SMBBAR 4
Daniel Kurtz636752b2012-07-24 14:13:58 +020097#define SMBPCISTS 0x006
Linus Torvalds1da177e2005-04-16 15:20:36 -070098#define SMBHSTCFG 0x040
Linus Torvalds1da177e2005-04-16 15:20:36 -070099
Daniel Kurtz636752b2012-07-24 14:13:58 +0200100/* Host status bits for SMBPCISTS */
101#define SMBPCISTS_INTS 0x08
102
Linus Torvalds1da177e2005-04-16 15:20:36 -0700103/* Host configuration bits for SMBHSTCFG */
104#define SMBHSTCFG_HST_EN 1
105#define SMBHSTCFG_SMB_SMI_EN 2
106#define SMBHSTCFG_I2C_EN 4
107
Lucas De Marchi25985ed2011-03-30 22:57:33 -0300108/* Auxiliary control register bits, ICH4+ only */
Oleg Ryjkovca8b9e32007-07-12 14:12:31 +0200109#define SMBAUXCTL_CRC 1
110#define SMBAUXCTL_E32B 2
111
Linus Torvalds1da177e2005-04-16 15:20:36 -0700112/* Other settings */
Jean Delvare84c1af42012-03-26 21:47:19 +0200113#define MAX_RETRIES 400
Linus Torvalds1da177e2005-04-16 15:20:36 -0700114
115/* I801 command constants */
116#define I801_QUICK 0x00
117#define I801_BYTE 0x04
118#define I801_BYTE_DATA 0x08
119#define I801_WORD_DATA 0x0C
Jean Delvareae7b0492008-01-27 18:14:49 +0100120#define I801_PROC_CALL 0x10 /* unimplemented */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700121#define I801_BLOCK_DATA 0x14
Jean Delvare63420642008-01-27 18:14:50 +0100122#define I801_I2C_BLOCK_DATA 0x18 /* ICH5 and later */
Daniel Kurtzedbeea62012-07-24 14:13:58 +0200123
124/* I801 Host Control register bits */
125#define SMBHSTCNT_INTREN 0x01
126#define SMBHSTCNT_KILL 0x02
127#define SMBHSTCNT_LAST_BYTE 0x20
128#define SMBHSTCNT_START 0x40
129#define SMBHSTCNT_PEC_EN 0x80 /* ICH3 and later */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700130
Oleg Ryjkovca8b9e32007-07-12 14:12:31 +0200131/* I801 Hosts Status register bits */
132#define SMBHSTSTS_BYTE_DONE 0x80
133#define SMBHSTSTS_INUSE_STS 0x40
134#define SMBHSTSTS_SMBALERT_STS 0x20
135#define SMBHSTSTS_FAILED 0x10
136#define SMBHSTSTS_BUS_ERR 0x08
137#define SMBHSTSTS_DEV_ERR 0x04
138#define SMBHSTSTS_INTR 0x02
139#define SMBHSTSTS_HOST_BUSY 0x01
Linus Torvalds1da177e2005-04-16 15:20:36 -0700140
Daniel Kurtz70a1cc12012-07-24 14:13:58 +0200141#define STATUS_ERROR_FLAGS (SMBHSTSTS_FAILED | SMBHSTSTS_BUS_ERR | \
142 SMBHSTSTS_DEV_ERR)
143
144#define STATUS_FLAGS (SMBHSTSTS_BYTE_DONE | SMBHSTSTS_INTR | \
145 STATUS_ERROR_FLAGS)
Jean Delvarecf898dc2008-07-14 22:38:33 +0200146
Jean Delvarea6e5e2b2011-05-01 18:18:49 +0200147/* Older devices have their ID defined in <linux/pci_ids.h> */
148#define PCI_DEVICE_ID_INTEL_COUGARPOINT_SMBUS 0x1c22
149#define PCI_DEVICE_ID_INTEL_PATSBURG_SMBUS 0x1d22
David Woodhouse55fee8d2010-10-31 21:07:00 +0100150/* Patsburg also has three 'Integrated Device Function' SMBus controllers */
151#define PCI_DEVICE_ID_INTEL_PATSBURG_SMBUS_IDF0 0x1d70
152#define PCI_DEVICE_ID_INTEL_PATSBURG_SMBUS_IDF1 0x1d71
153#define PCI_DEVICE_ID_INTEL_PATSBURG_SMBUS_IDF2 0x1d72
Seth Heasley6e2a8512011-05-24 20:58:49 +0200154#define PCI_DEVICE_ID_INTEL_PANTHERPOINT_SMBUS 0x1e22
Jean Delvarea6e5e2b2011-05-01 18:18:49 +0200155#define PCI_DEVICE_ID_INTEL_DH89XXCC_SMBUS 0x2330
156#define PCI_DEVICE_ID_INTEL_5_3400_SERIES_SMBUS 0x3b30
Seth Heasley062737f2012-03-26 21:47:19 +0200157#define PCI_DEVICE_ID_INTEL_LYNXPOINT_SMBUS 0x8c22
David Woodhouse55fee8d2010-10-31 21:07:00 +0100158
David Woodhouse0cd96eb2010-10-31 21:06:59 +0100159struct i801_priv {
160 struct i2c_adapter adapter;
161 unsigned long smba;
162 unsigned char original_hstcfg;
163 struct pci_dev *pci_dev;
164 unsigned int features;
Daniel Kurtz636752b2012-07-24 14:13:58 +0200165
166 /* isr processing */
167 wait_queue_head_t waitq;
168 u8 status;
Daniel Kurtzd3ff6ce2012-07-24 14:13:59 +0200169
170 /* Command state used by isr for byte-by-byte block transactions */
171 u8 cmd;
172 bool is_read;
173 int count;
174 int len;
175 u8 *data;
David Woodhouse0cd96eb2010-10-31 21:06:59 +0100176};
177
Jean Delvared6072f82005-09-25 16:37:04 +0200178static struct pci_driver i801_driver;
Jean Delvare369f6f42008-01-27 18:14:50 +0100179
180#define FEATURE_SMBUS_PEC (1 << 0)
181#define FEATURE_BLOCK_BUFFER (1 << 1)
182#define FEATURE_BLOCK_PROC (1 << 2)
183#define FEATURE_I2C_BLOCK_READ (1 << 3)
Daniel Kurtz636752b2012-07-24 14:13:58 +0200184#define FEATURE_IRQ (1 << 4)
Jean Delvaree7198fb2011-05-24 20:58:49 +0200185/* Not really a feature, but it's convenient to handle it as such */
186#define FEATURE_IDF (1 << 15)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700187
Jean Delvareadff6872010-05-21 18:40:54 +0200188static const char *i801_feature_names[] = {
189 "SMBus PEC",
190 "Block buffer",
191 "Block process call",
192 "I2C block read",
Daniel Kurtz636752b2012-07-24 14:13:58 +0200193 "Interrupt",
Jean Delvareadff6872010-05-21 18:40:54 +0200194};
195
196static unsigned int disable_features;
197module_param(disable_features, uint, S_IRUGO | S_IWUSR);
198MODULE_PARM_DESC(disable_features, "Disable selected driver features");
199
Jean Delvarecf898dc2008-07-14 22:38:33 +0200200/* Make sure the SMBus host is ready to start transmitting.
201 Return 0 if it is, -EBUSY if it is not. */
David Woodhouse0cd96eb2010-10-31 21:06:59 +0100202static int i801_check_pre(struct i801_priv *priv)
Jean Delvarecf898dc2008-07-14 22:38:33 +0200203{
204 int status;
205
David Woodhouse0cd96eb2010-10-31 21:06:59 +0100206 status = inb_p(SMBHSTSTS(priv));
Jean Delvarecf898dc2008-07-14 22:38:33 +0200207 if (status & SMBHSTSTS_HOST_BUSY) {
David Woodhouse0cd96eb2010-10-31 21:06:59 +0100208 dev_err(&priv->pci_dev->dev, "SMBus is busy, can't use it!\n");
Jean Delvarecf898dc2008-07-14 22:38:33 +0200209 return -EBUSY;
210 }
211
212 status &= STATUS_FLAGS;
213 if (status) {
David Woodhouse0cd96eb2010-10-31 21:06:59 +0100214 dev_dbg(&priv->pci_dev->dev, "Clearing status flags (%02x)\n",
Jean Delvarecf898dc2008-07-14 22:38:33 +0200215 status);
David Woodhouse0cd96eb2010-10-31 21:06:59 +0100216 outb_p(status, SMBHSTSTS(priv));
217 status = inb_p(SMBHSTSTS(priv)) & STATUS_FLAGS;
Jean Delvarecf898dc2008-07-14 22:38:33 +0200218 if (status) {
David Woodhouse0cd96eb2010-10-31 21:06:59 +0100219 dev_err(&priv->pci_dev->dev,
Jean Delvarecf898dc2008-07-14 22:38:33 +0200220 "Failed clearing status flags (%02x)\n",
221 status);
222 return -EBUSY;
223 }
224 }
225
226 return 0;
227}
228
Jean Delvare6cad93c2012-07-24 14:13:58 +0200229/*
230 * Convert the status register to an error code, and clear it.
231 * Note that status only contains the bits we want to clear, not the
232 * actual register value.
233 */
234static int i801_check_post(struct i801_priv *priv, int status)
Jean Delvarecf898dc2008-07-14 22:38:33 +0200235{
236 int result = 0;
237
Daniel Kurtz636752b2012-07-24 14:13:58 +0200238 /*
239 * If the SMBus is still busy, we give up
240 * Note: This timeout condition only happens when using polling
241 * transactions. For interrupt operation, NAK/timeout is indicated by
242 * DEV_ERR.
243 */
Jean Delvare6cad93c2012-07-24 14:13:58 +0200244 if (unlikely(status < 0)) {
David Woodhouse0cd96eb2010-10-31 21:06:59 +0100245 dev_err(&priv->pci_dev->dev, "Transaction timeout\n");
Jean Delvarecf898dc2008-07-14 22:38:33 +0200246 /* try to stop the current command */
David Woodhouse0cd96eb2010-10-31 21:06:59 +0100247 dev_dbg(&priv->pci_dev->dev, "Terminating the current operation\n");
248 outb_p(inb_p(SMBHSTCNT(priv)) | SMBHSTCNT_KILL,
249 SMBHSTCNT(priv));
Jean Delvare84c1af42012-03-26 21:47:19 +0200250 usleep_range(1000, 2000);
David Woodhouse0cd96eb2010-10-31 21:06:59 +0100251 outb_p(inb_p(SMBHSTCNT(priv)) & (~SMBHSTCNT_KILL),
252 SMBHSTCNT(priv));
Jean Delvarecf898dc2008-07-14 22:38:33 +0200253
254 /* Check if it worked */
David Woodhouse0cd96eb2010-10-31 21:06:59 +0100255 status = inb_p(SMBHSTSTS(priv));
Jean Delvarecf898dc2008-07-14 22:38:33 +0200256 if ((status & SMBHSTSTS_HOST_BUSY) ||
257 !(status & SMBHSTSTS_FAILED))
David Woodhouse0cd96eb2010-10-31 21:06:59 +0100258 dev_err(&priv->pci_dev->dev,
Jean Delvarecf898dc2008-07-14 22:38:33 +0200259 "Failed terminating the transaction\n");
David Woodhouse0cd96eb2010-10-31 21:06:59 +0100260 outb_p(STATUS_FLAGS, SMBHSTSTS(priv));
Jean Delvarecf898dc2008-07-14 22:38:33 +0200261 return -ETIMEDOUT;
262 }
263
264 if (status & SMBHSTSTS_FAILED) {
265 result = -EIO;
David Woodhouse0cd96eb2010-10-31 21:06:59 +0100266 dev_err(&priv->pci_dev->dev, "Transaction failed\n");
Jean Delvarecf898dc2008-07-14 22:38:33 +0200267 }
268 if (status & SMBHSTSTS_DEV_ERR) {
269 result = -ENXIO;
David Woodhouse0cd96eb2010-10-31 21:06:59 +0100270 dev_dbg(&priv->pci_dev->dev, "No response\n");
Jean Delvarecf898dc2008-07-14 22:38:33 +0200271 }
272 if (status & SMBHSTSTS_BUS_ERR) {
273 result = -EAGAIN;
David Woodhouse0cd96eb2010-10-31 21:06:59 +0100274 dev_dbg(&priv->pci_dev->dev, "Lost arbitration\n");
Jean Delvarecf898dc2008-07-14 22:38:33 +0200275 }
276
Jean Delvare6cad93c2012-07-24 14:13:58 +0200277 /* Clear status flags except BYTE_DONE, to be cleared by caller */
278 outb_p(status, SMBHSTSTS(priv));
Jean Delvarecf898dc2008-07-14 22:38:33 +0200279
280 return result;
281}
282
Jean Delvare6cad93c2012-07-24 14:13:58 +0200283/* Wait for BUSY being cleared and either INTR or an error flag being set */
284static int i801_wait_intr(struct i801_priv *priv)
285{
286 int timeout = 0;
287 int status;
288
289 /* We will always wait for a fraction of a second! */
290 do {
291 usleep_range(250, 500);
292 status = inb_p(SMBHSTSTS(priv));
293 } while (((status & SMBHSTSTS_HOST_BUSY) ||
294 !(status & (STATUS_ERROR_FLAGS | SMBHSTSTS_INTR))) &&
295 (timeout++ < MAX_RETRIES));
296
297 if (timeout > MAX_RETRIES) {
298 dev_dbg(&priv->pci_dev->dev, "INTR Timeout!\n");
299 return -ETIMEDOUT;
300 }
301 return status & (STATUS_ERROR_FLAGS | SMBHSTSTS_INTR);
302}
303
304/* Wait for either BYTE_DONE or an error flag being set */
305static int i801_wait_byte_done(struct i801_priv *priv)
306{
307 int timeout = 0;
308 int status;
309
310 /* We will always wait for a fraction of a second! */
311 do {
312 usleep_range(250, 500);
313 status = inb_p(SMBHSTSTS(priv));
314 } while (!(status & (STATUS_ERROR_FLAGS | SMBHSTSTS_BYTE_DONE)) &&
315 (timeout++ < MAX_RETRIES));
316
317 if (timeout > MAX_RETRIES) {
318 dev_dbg(&priv->pci_dev->dev, "BYTE_DONE Timeout!\n");
319 return -ETIMEDOUT;
320 }
321 return status & STATUS_ERROR_FLAGS;
322}
323
David Woodhouse0cd96eb2010-10-31 21:06:59 +0100324static int i801_transaction(struct i801_priv *priv, int xact)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700325{
Jean Delvare2b738092008-07-14 22:38:32 +0200326 int status;
Jean Delvarecf898dc2008-07-14 22:38:33 +0200327 int result;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700328
David Woodhouse0cd96eb2010-10-31 21:06:59 +0100329 result = i801_check_pre(priv);
Jean Delvarecf898dc2008-07-14 22:38:33 +0200330 if (result < 0)
331 return result;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700332
Daniel Kurtz636752b2012-07-24 14:13:58 +0200333 if (priv->features & FEATURE_IRQ) {
334 outb_p(xact | SMBHSTCNT_INTREN | SMBHSTCNT_START,
335 SMBHSTCNT(priv));
336 wait_event(priv->waitq, (status = priv->status));
337 priv->status = 0;
338 return i801_check_post(priv, status);
339 }
340
Oleg Ryjkov7edcb9a2007-07-12 14:12:31 +0200341 /* the current contents of SMBHSTCNT can be overwritten, since PEC,
Daniel Kurtz37af8712012-07-24 14:13:58 +0200342 * SMBSCMD are passed in xact */
Daniel Kurtzedbeea62012-07-24 14:13:58 +0200343 outb_p(xact | SMBHSTCNT_START, SMBHSTCNT(priv));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700344
Jean Delvare6cad93c2012-07-24 14:13:58 +0200345 status = i801_wait_intr(priv);
346 return i801_check_post(priv, status);
Oleg Ryjkovca8b9e32007-07-12 14:12:31 +0200347}
348
David Woodhouse0cd96eb2010-10-31 21:06:59 +0100349static int i801_block_transaction_by_block(struct i801_priv *priv,
350 union i2c_smbus_data *data,
Oleg Ryjkov7edcb9a2007-07-12 14:12:31 +0200351 char read_write, int hwpec)
352{
353 int i, len;
David Brownell97140342008-07-14 22:38:25 +0200354 int status;
Oleg Ryjkov7edcb9a2007-07-12 14:12:31 +0200355
David Woodhouse0cd96eb2010-10-31 21:06:59 +0100356 inb_p(SMBHSTCNT(priv)); /* reset the data buffer index */
Oleg Ryjkov7edcb9a2007-07-12 14:12:31 +0200357
358 /* Use 32-byte buffer to process this transaction */
359 if (read_write == I2C_SMBUS_WRITE) {
360 len = data->block[0];
David Woodhouse0cd96eb2010-10-31 21:06:59 +0100361 outb_p(len, SMBHSTDAT0(priv));
Oleg Ryjkov7edcb9a2007-07-12 14:12:31 +0200362 for (i = 0; i < len; i++)
David Woodhouse0cd96eb2010-10-31 21:06:59 +0100363 outb_p(data->block[i+1], SMBBLKDAT(priv));
Oleg Ryjkov7edcb9a2007-07-12 14:12:31 +0200364 }
365
Daniel Kurtz37af8712012-07-24 14:13:58 +0200366 status = i801_transaction(priv, I801_BLOCK_DATA |
Daniel Kurtzedbeea62012-07-24 14:13:58 +0200367 (hwpec ? SMBHSTCNT_PEC_EN : 0));
David Brownell97140342008-07-14 22:38:25 +0200368 if (status)
369 return status;
Oleg Ryjkov7edcb9a2007-07-12 14:12:31 +0200370
371 if (read_write == I2C_SMBUS_READ) {
David Woodhouse0cd96eb2010-10-31 21:06:59 +0100372 len = inb_p(SMBHSTDAT0(priv));
Oleg Ryjkov7edcb9a2007-07-12 14:12:31 +0200373 if (len < 1 || len > I2C_SMBUS_BLOCK_MAX)
David Brownell97140342008-07-14 22:38:25 +0200374 return -EPROTO;
Oleg Ryjkov7edcb9a2007-07-12 14:12:31 +0200375
376 data->block[0] = len;
377 for (i = 0; i < len; i++)
David Woodhouse0cd96eb2010-10-31 21:06:59 +0100378 data->block[i + 1] = inb_p(SMBBLKDAT(priv));
Oleg Ryjkov7edcb9a2007-07-12 14:12:31 +0200379 }
380 return 0;
381}
382
Daniel Kurtzd3ff6ce2012-07-24 14:13:59 +0200383static void i801_isr_byte_done(struct i801_priv *priv)
384{
385 if (priv->is_read) {
386 /* For SMBus block reads, length is received with first byte */
387 if (((priv->cmd & 0x1c) == I801_BLOCK_DATA) &&
388 (priv->count == 0)) {
389 priv->len = inb_p(SMBHSTDAT0(priv));
390 if (priv->len < 1 || priv->len > I2C_SMBUS_BLOCK_MAX) {
391 dev_err(&priv->pci_dev->dev,
392 "Illegal SMBus block read size %d\n",
393 priv->len);
394 /* FIXME: Recover */
395 priv->len = I2C_SMBUS_BLOCK_MAX;
396 } else {
397 dev_dbg(&priv->pci_dev->dev,
398 "SMBus block read size is %d\n",
399 priv->len);
400 }
401 priv->data[-1] = priv->len;
402 }
403
404 /* Read next byte */
405 if (priv->count < priv->len)
406 priv->data[priv->count++] = inb(SMBBLKDAT(priv));
407 else
408 dev_dbg(&priv->pci_dev->dev,
409 "Discarding extra byte on block read\n");
410
411 /* Set LAST_BYTE for last byte of read transaction */
412 if (priv->count == priv->len - 1)
413 outb_p(priv->cmd | SMBHSTCNT_LAST_BYTE,
414 SMBHSTCNT(priv));
415 } else if (priv->count < priv->len - 1) {
416 /* Write next byte, except for IRQ after last byte */
417 outb_p(priv->data[++priv->count], SMBBLKDAT(priv));
418 }
419
420 /* Clear BYTE_DONE to continue with next byte */
421 outb_p(SMBHSTSTS_BYTE_DONE, SMBHSTSTS(priv));
422}
423
Daniel Kurtzefa3cb12012-07-24 14:13:57 +0200424/*
Daniel Kurtzd3ff6ce2012-07-24 14:13:59 +0200425 * There are two kinds of interrupts:
426 *
427 * 1) i801 signals transaction completion with one of these interrupts:
428 * INTR - Success
429 * DEV_ERR - Invalid command, NAK or communication timeout
430 * BUS_ERR - SMI# transaction collision
431 * FAILED - transaction was canceled due to a KILL request
432 * When any of these occur, update ->status and wake up the waitq.
433 * ->status must be cleared before kicking off the next transaction.
434 *
435 * 2) For byte-by-byte (I2C read/write) transactions, one BYTE_DONE interrupt
436 * occurs for each byte of a byte-by-byte to prepare the next byte.
Daniel Kurtz636752b2012-07-24 14:13:58 +0200437 */
438static irqreturn_t i801_isr(int irq, void *dev_id)
439{
440 struct i801_priv *priv = dev_id;
441 u16 pcists;
442 u8 status;
443
444 /* Confirm this is our interrupt */
445 pci_read_config_word(priv->pci_dev, SMBPCISTS, &pcists);
446 if (!(pcists & SMBPCISTS_INTS))
447 return IRQ_NONE;
448
449 status = inb_p(SMBHSTSTS(priv));
450 if (status != 0x42)
451 dev_dbg(&priv->pci_dev->dev, "irq: status = %02x\n", status);
452
Daniel Kurtzd3ff6ce2012-07-24 14:13:59 +0200453 if (status & SMBHSTSTS_BYTE_DONE)
454 i801_isr_byte_done(priv);
455
Daniel Kurtz636752b2012-07-24 14:13:58 +0200456 /*
457 * Clear irq sources and report transaction result.
458 * ->status must be cleared before the next transaction is started.
459 */
460 status &= SMBHSTSTS_INTR | STATUS_ERROR_FLAGS;
461 if (status) {
462 outb_p(status, SMBHSTSTS(priv));
463 priv->status |= status;
464 wake_up(&priv->waitq);
465 }
466
467 return IRQ_HANDLED;
468}
469
470/*
Daniel Kurtzefa3cb12012-07-24 14:13:57 +0200471 * For "byte-by-byte" block transactions:
472 * I2C write uses cmd=I801_BLOCK_DATA, I2C_EN=1
473 * I2C read uses cmd=I801_I2C_BLOCK_DATA
474 */
David Woodhouse0cd96eb2010-10-31 21:06:59 +0100475static int i801_block_transaction_byte_by_byte(struct i801_priv *priv,
476 union i2c_smbus_data *data,
Jean Delvare63420642008-01-27 18:14:50 +0100477 char read_write, int command,
478 int hwpec)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700479{
480 int i, len;
481 int smbcmd;
Jean Delvare2b738092008-07-14 22:38:32 +0200482 int status;
Jean Delvarecf898dc2008-07-14 22:38:33 +0200483 int result;
Jean Delvarecf898dc2008-07-14 22:38:33 +0200484
David Woodhouse0cd96eb2010-10-31 21:06:59 +0100485 result = i801_check_pre(priv);
Jean Delvarecf898dc2008-07-14 22:38:33 +0200486 if (result < 0)
487 return result;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700488
Oleg Ryjkov7edcb9a2007-07-12 14:12:31 +0200489 len = data->block[0];
Linus Torvalds1da177e2005-04-16 15:20:36 -0700490
491 if (read_write == I2C_SMBUS_WRITE) {
David Woodhouse0cd96eb2010-10-31 21:06:59 +0100492 outb_p(len, SMBHSTDAT0(priv));
493 outb_p(data->block[1], SMBBLKDAT(priv));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700494 }
495
Daniel Kurtzefa3cb12012-07-24 14:13:57 +0200496 if (command == I2C_SMBUS_I2C_BLOCK_DATA &&
497 read_write == I2C_SMBUS_READ)
498 smbcmd = I801_I2C_BLOCK_DATA;
499 else
500 smbcmd = I801_BLOCK_DATA;
501
Daniel Kurtzd3ff6ce2012-07-24 14:13:59 +0200502 if (priv->features & FEATURE_IRQ) {
503 priv->is_read = (read_write == I2C_SMBUS_READ);
504 if (len == 1 && priv->is_read)
505 smbcmd |= SMBHSTCNT_LAST_BYTE;
506 priv->cmd = smbcmd | SMBHSTCNT_INTREN;
507 priv->len = len;
508 priv->count = 0;
509 priv->data = &data->block[1];
510
511 outb_p(priv->cmd | SMBHSTCNT_START, SMBHSTCNT(priv));
512 wait_event(priv->waitq, (status = priv->status));
513 priv->status = 0;
514 return i801_check_post(priv, status);
515 }
516
Linus Torvalds1da177e2005-04-16 15:20:36 -0700517 for (i = 1; i <= len; i++) {
Daniel Kurtzefa3cb12012-07-24 14:13:57 +0200518 if (i == len && read_write == I2C_SMBUS_READ)
Daniel Kurtzedbeea62012-07-24 14:13:58 +0200519 smbcmd |= SMBHSTCNT_LAST_BYTE;
Daniel Kurtz37af8712012-07-24 14:13:58 +0200520 outb_p(smbcmd, SMBHSTCNT(priv));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700521
Linus Torvalds1da177e2005-04-16 15:20:36 -0700522 if (i == 1)
Daniel Kurtzedbeea62012-07-24 14:13:58 +0200523 outb_p(inb(SMBHSTCNT(priv)) | SMBHSTCNT_START,
David Woodhouse0cd96eb2010-10-31 21:06:59 +0100524 SMBHSTCNT(priv));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700525
Jean Delvare6cad93c2012-07-24 14:13:58 +0200526 status = i801_wait_byte_done(priv);
527 if (status)
528 goto exit;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700529
Jean Delvare63420642008-01-27 18:14:50 +0100530 if (i == 1 && read_write == I2C_SMBUS_READ
531 && command != I2C_SMBUS_I2C_BLOCK_DATA) {
David Woodhouse0cd96eb2010-10-31 21:06:59 +0100532 len = inb_p(SMBHSTDAT0(priv));
Jean Delvarecf898dc2008-07-14 22:38:33 +0200533 if (len < 1 || len > I2C_SMBUS_BLOCK_MAX) {
David Woodhouse0cd96eb2010-10-31 21:06:59 +0100534 dev_err(&priv->pci_dev->dev,
Jean Delvarecf898dc2008-07-14 22:38:33 +0200535 "Illegal SMBus block read size %d\n",
536 len);
537 /* Recover */
David Woodhouse0cd96eb2010-10-31 21:06:59 +0100538 while (inb_p(SMBHSTSTS(priv)) &
539 SMBHSTSTS_HOST_BUSY)
540 outb_p(SMBHSTSTS_BYTE_DONE,
541 SMBHSTSTS(priv));
542 outb_p(SMBHSTSTS_INTR, SMBHSTSTS(priv));
David Brownell97140342008-07-14 22:38:25 +0200543 return -EPROTO;
Jean Delvarecf898dc2008-07-14 22:38:33 +0200544 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700545 data->block[0] = len;
546 }
547
548 /* Retrieve/store value in SMBBLKDAT */
549 if (read_write == I2C_SMBUS_READ)
David Woodhouse0cd96eb2010-10-31 21:06:59 +0100550 data->block[i] = inb_p(SMBBLKDAT(priv));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700551 if (read_write == I2C_SMBUS_WRITE && i+1 <= len)
David Woodhouse0cd96eb2010-10-31 21:06:59 +0100552 outb_p(data->block[i+1], SMBBLKDAT(priv));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700553
Jean Delvarecf898dc2008-07-14 22:38:33 +0200554 /* signals SMBBLKDAT ready */
Jean Delvare6cad93c2012-07-24 14:13:58 +0200555 outb_p(SMBHSTSTS_BYTE_DONE, SMBHSTSTS(priv));
Oleg Ryjkov7edcb9a2007-07-12 14:12:31 +0200556 }
Jean Delvarecf898dc2008-07-14 22:38:33 +0200557
Jean Delvare6cad93c2012-07-24 14:13:58 +0200558 status = i801_wait_intr(priv);
559exit:
560 return i801_check_post(priv, status);
Oleg Ryjkov7edcb9a2007-07-12 14:12:31 +0200561}
562
David Woodhouse0cd96eb2010-10-31 21:06:59 +0100563static int i801_set_block_buffer_mode(struct i801_priv *priv)
Oleg Ryjkov7edcb9a2007-07-12 14:12:31 +0200564{
David Woodhouse0cd96eb2010-10-31 21:06:59 +0100565 outb_p(inb_p(SMBAUXCTL(priv)) | SMBAUXCTL_E32B, SMBAUXCTL(priv));
566 if ((inb_p(SMBAUXCTL(priv)) & SMBAUXCTL_E32B) == 0)
David Brownell97140342008-07-14 22:38:25 +0200567 return -EIO;
Oleg Ryjkov7edcb9a2007-07-12 14:12:31 +0200568 return 0;
569}
570
571/* Block transaction function */
David Woodhouse0cd96eb2010-10-31 21:06:59 +0100572static int i801_block_transaction(struct i801_priv *priv,
573 union i2c_smbus_data *data, char read_write,
Oleg Ryjkov7edcb9a2007-07-12 14:12:31 +0200574 int command, int hwpec)
575{
576 int result = 0;
577 unsigned char hostc;
578
579 if (command == I2C_SMBUS_I2C_BLOCK_DATA) {
580 if (read_write == I2C_SMBUS_WRITE) {
581 /* set I2C_EN bit in configuration register */
David Woodhouse0cd96eb2010-10-31 21:06:59 +0100582 pci_read_config_byte(priv->pci_dev, SMBHSTCFG, &hostc);
583 pci_write_config_byte(priv->pci_dev, SMBHSTCFG,
Oleg Ryjkov7edcb9a2007-07-12 14:12:31 +0200584 hostc | SMBHSTCFG_I2C_EN);
David Woodhouse0cd96eb2010-10-31 21:06:59 +0100585 } else if (!(priv->features & FEATURE_I2C_BLOCK_READ)) {
586 dev_err(&priv->pci_dev->dev,
Jean Delvare63420642008-01-27 18:14:50 +0100587 "I2C block read is unsupported!\n");
David Brownell97140342008-07-14 22:38:25 +0200588 return -EOPNOTSUPP;
Oleg Ryjkov7edcb9a2007-07-12 14:12:31 +0200589 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700590 }
591
Jean Delvare63420642008-01-27 18:14:50 +0100592 if (read_write == I2C_SMBUS_WRITE
593 || command == I2C_SMBUS_I2C_BLOCK_DATA) {
Oleg Ryjkov7edcb9a2007-07-12 14:12:31 +0200594 if (data->block[0] < 1)
595 data->block[0] = 1;
596 if (data->block[0] > I2C_SMBUS_BLOCK_MAX)
597 data->block[0] = I2C_SMBUS_BLOCK_MAX;
598 } else {
Jean Delvare63420642008-01-27 18:14:50 +0100599 data->block[0] = 32; /* max for SMBus block reads */
Oleg Ryjkov7edcb9a2007-07-12 14:12:31 +0200600 }
601
Jean Delvarec074c392010-03-13 20:56:53 +0100602 /* Experience has shown that the block buffer can only be used for
603 SMBus (not I2C) block transactions, even though the datasheet
604 doesn't mention this limitation. */
David Woodhouse0cd96eb2010-10-31 21:06:59 +0100605 if ((priv->features & FEATURE_BLOCK_BUFFER)
Jean Delvarec074c392010-03-13 20:56:53 +0100606 && command != I2C_SMBUS_I2C_BLOCK_DATA
David Woodhouse0cd96eb2010-10-31 21:06:59 +0100607 && i801_set_block_buffer_mode(priv) == 0)
608 result = i801_block_transaction_by_block(priv, data,
609 read_write, hwpec);
Oleg Ryjkov7edcb9a2007-07-12 14:12:31 +0200610 else
David Woodhouse0cd96eb2010-10-31 21:06:59 +0100611 result = i801_block_transaction_byte_by_byte(priv, data,
612 read_write,
Jean Delvare63420642008-01-27 18:14:50 +0100613 command, hwpec);
Oleg Ryjkov7edcb9a2007-07-12 14:12:31 +0200614
Jean Delvare63420642008-01-27 18:14:50 +0100615 if (command == I2C_SMBUS_I2C_BLOCK_DATA
616 && read_write == I2C_SMBUS_WRITE) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700617 /* restore saved configuration register value */
David Woodhouse0cd96eb2010-10-31 21:06:59 +0100618 pci_write_config_byte(priv->pci_dev, SMBHSTCFG, hostc);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700619 }
620 return result;
621}
622
David Brownell97140342008-07-14 22:38:25 +0200623/* Return negative errno on error. */
Ivo Manca3fb21c62010-05-21 18:40:55 +0200624static s32 i801_access(struct i2c_adapter *adap, u16 addr,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700625 unsigned short flags, char read_write, u8 command,
Ivo Manca3fb21c62010-05-21 18:40:55 +0200626 int size, union i2c_smbus_data *data)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700627{
Jean Delvaree8aac4a2005-10-26 21:34:42 +0200628 int hwpec;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700629 int block = 0;
630 int ret, xact = 0;
David Woodhouse0cd96eb2010-10-31 21:06:59 +0100631 struct i801_priv *priv = i2c_get_adapdata(adap);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700632
David Woodhouse0cd96eb2010-10-31 21:06:59 +0100633 hwpec = (priv->features & FEATURE_SMBUS_PEC) && (flags & I2C_CLIENT_PEC)
Jean Delvaree8aac4a2005-10-26 21:34:42 +0200634 && size != I2C_SMBUS_QUICK
635 && size != I2C_SMBUS_I2C_BLOCK_DATA;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700636
637 switch (size) {
638 case I2C_SMBUS_QUICK:
639 outb_p(((addr & 0x7f) << 1) | (read_write & 0x01),
David Woodhouse0cd96eb2010-10-31 21:06:59 +0100640 SMBHSTADD(priv));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700641 xact = I801_QUICK;
642 break;
643 case I2C_SMBUS_BYTE:
644 outb_p(((addr & 0x7f) << 1) | (read_write & 0x01),
David Woodhouse0cd96eb2010-10-31 21:06:59 +0100645 SMBHSTADD(priv));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700646 if (read_write == I2C_SMBUS_WRITE)
David Woodhouse0cd96eb2010-10-31 21:06:59 +0100647 outb_p(command, SMBHSTCMD(priv));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700648 xact = I801_BYTE;
649 break;
650 case I2C_SMBUS_BYTE_DATA:
651 outb_p(((addr & 0x7f) << 1) | (read_write & 0x01),
David Woodhouse0cd96eb2010-10-31 21:06:59 +0100652 SMBHSTADD(priv));
653 outb_p(command, SMBHSTCMD(priv));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700654 if (read_write == I2C_SMBUS_WRITE)
David Woodhouse0cd96eb2010-10-31 21:06:59 +0100655 outb_p(data->byte, SMBHSTDAT0(priv));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700656 xact = I801_BYTE_DATA;
657 break;
658 case I2C_SMBUS_WORD_DATA:
659 outb_p(((addr & 0x7f) << 1) | (read_write & 0x01),
David Woodhouse0cd96eb2010-10-31 21:06:59 +0100660 SMBHSTADD(priv));
661 outb_p(command, SMBHSTCMD(priv));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700662 if (read_write == I2C_SMBUS_WRITE) {
David Woodhouse0cd96eb2010-10-31 21:06:59 +0100663 outb_p(data->word & 0xff, SMBHSTDAT0(priv));
664 outb_p((data->word & 0xff00) >> 8, SMBHSTDAT1(priv));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700665 }
666 xact = I801_WORD_DATA;
667 break;
668 case I2C_SMBUS_BLOCK_DATA:
Linus Torvalds1da177e2005-04-16 15:20:36 -0700669 outb_p(((addr & 0x7f) << 1) | (read_write & 0x01),
David Woodhouse0cd96eb2010-10-31 21:06:59 +0100670 SMBHSTADD(priv));
671 outb_p(command, SMBHSTCMD(priv));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700672 block = 1;
673 break;
Jean Delvare63420642008-01-27 18:14:50 +0100674 case I2C_SMBUS_I2C_BLOCK_DATA:
675 /* NB: page 240 of ICH5 datasheet shows that the R/#W
676 * bit should be cleared here, even when reading */
David Woodhouse0cd96eb2010-10-31 21:06:59 +0100677 outb_p((addr & 0x7f) << 1, SMBHSTADD(priv));
Jean Delvare63420642008-01-27 18:14:50 +0100678 if (read_write == I2C_SMBUS_READ) {
679 /* NB: page 240 of ICH5 datasheet also shows
680 * that DATA1 is the cmd field when reading */
David Woodhouse0cd96eb2010-10-31 21:06:59 +0100681 outb_p(command, SMBHSTDAT1(priv));
Jean Delvare63420642008-01-27 18:14:50 +0100682 } else
David Woodhouse0cd96eb2010-10-31 21:06:59 +0100683 outb_p(command, SMBHSTCMD(priv));
Jean Delvare63420642008-01-27 18:14:50 +0100684 block = 1;
685 break;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700686 default:
David Woodhouse0cd96eb2010-10-31 21:06:59 +0100687 dev_err(&priv->pci_dev->dev, "Unsupported transaction %d\n",
688 size);
David Brownell97140342008-07-14 22:38:25 +0200689 return -EOPNOTSUPP;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700690 }
691
Oleg Ryjkovca8b9e32007-07-12 14:12:31 +0200692 if (hwpec) /* enable/disable hardware PEC */
David Woodhouse0cd96eb2010-10-31 21:06:59 +0100693 outb_p(inb_p(SMBAUXCTL(priv)) | SMBAUXCTL_CRC, SMBAUXCTL(priv));
Oleg Ryjkovca8b9e32007-07-12 14:12:31 +0200694 else
David Woodhouse0cd96eb2010-10-31 21:06:59 +0100695 outb_p(inb_p(SMBAUXCTL(priv)) & (~SMBAUXCTL_CRC),
696 SMBAUXCTL(priv));
Jean Delvaree8aac4a2005-10-26 21:34:42 +0200697
Ivo Manca3fb21c62010-05-21 18:40:55 +0200698 if (block)
David Woodhouse0cd96eb2010-10-31 21:06:59 +0100699 ret = i801_block_transaction(priv, data, read_write, size,
700 hwpec);
Oleg Ryjkov7edcb9a2007-07-12 14:12:31 +0200701 else
Daniel Kurtz37af8712012-07-24 14:13:58 +0200702 ret = i801_transaction(priv, xact);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700703
Jean Delvarec79cfba2006-04-20 02:43:18 -0700704 /* Some BIOSes don't like it when PEC is enabled at reboot or resume
Oleg Ryjkov7edcb9a2007-07-12 14:12:31 +0200705 time, so we forcibly disable it after every transaction. Turn off
706 E32B for the same reason. */
Jean Delvarea0921b62008-01-27 18:14:50 +0100707 if (hwpec || block)
David Woodhouse0cd96eb2010-10-31 21:06:59 +0100708 outb_p(inb_p(SMBAUXCTL(priv)) &
709 ~(SMBAUXCTL_CRC | SMBAUXCTL_E32B), SMBAUXCTL(priv));
Jean Delvarec79cfba2006-04-20 02:43:18 -0700710
Ivo Manca3fb21c62010-05-21 18:40:55 +0200711 if (block)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700712 return ret;
Ivo Manca3fb21c62010-05-21 18:40:55 +0200713 if (ret)
David Brownell97140342008-07-14 22:38:25 +0200714 return ret;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700715 if ((read_write == I2C_SMBUS_WRITE) || (xact == I801_QUICK))
716 return 0;
717
718 switch (xact & 0x7f) {
719 case I801_BYTE: /* Result put in SMBHSTDAT0 */
720 case I801_BYTE_DATA:
David Woodhouse0cd96eb2010-10-31 21:06:59 +0100721 data->byte = inb_p(SMBHSTDAT0(priv));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700722 break;
723 case I801_WORD_DATA:
David Woodhouse0cd96eb2010-10-31 21:06:59 +0100724 data->word = inb_p(SMBHSTDAT0(priv)) +
725 (inb_p(SMBHSTDAT1(priv)) << 8);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700726 break;
727 }
728 return 0;
729}
730
731
732static u32 i801_func(struct i2c_adapter *adapter)
733{
David Woodhouse0cd96eb2010-10-31 21:06:59 +0100734 struct i801_priv *priv = i2c_get_adapdata(adapter);
735
Linus Torvalds1da177e2005-04-16 15:20:36 -0700736 return I2C_FUNC_SMBUS_QUICK | I2C_FUNC_SMBUS_BYTE |
Jean Delvare369f6f42008-01-27 18:14:50 +0100737 I2C_FUNC_SMBUS_BYTE_DATA | I2C_FUNC_SMBUS_WORD_DATA |
738 I2C_FUNC_SMBUS_BLOCK_DATA | I2C_FUNC_SMBUS_WRITE_I2C_BLOCK |
David Woodhouse0cd96eb2010-10-31 21:06:59 +0100739 ((priv->features & FEATURE_SMBUS_PEC) ? I2C_FUNC_SMBUS_PEC : 0) |
740 ((priv->features & FEATURE_I2C_BLOCK_READ) ?
Jean Delvare63420642008-01-27 18:14:50 +0100741 I2C_FUNC_SMBUS_READ_I2C_BLOCK : 0);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700742}
743
Jean Delvare8f9082c2006-09-03 22:39:46 +0200744static const struct i2c_algorithm smbus_algorithm = {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700745 .smbus_xfer = i801_access,
746 .functionality = i801_func,
747};
748
Axel Lin3527bd52012-01-12 20:32:04 +0100749static DEFINE_PCI_DEVICE_TABLE(i801_ids) = {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700750 { PCI_DEVICE(PCI_VENDOR_ID_INTEL, PCI_DEVICE_ID_INTEL_82801AA_3) },
751 { PCI_DEVICE(PCI_VENDOR_ID_INTEL, PCI_DEVICE_ID_INTEL_82801AB_3) },
752 { PCI_DEVICE(PCI_VENDOR_ID_INTEL, PCI_DEVICE_ID_INTEL_82801BA_2) },
753 { PCI_DEVICE(PCI_VENDOR_ID_INTEL, PCI_DEVICE_ID_INTEL_82801CA_3) },
754 { PCI_DEVICE(PCI_VENDOR_ID_INTEL, PCI_DEVICE_ID_INTEL_82801DB_3) },
755 { PCI_DEVICE(PCI_VENDOR_ID_INTEL, PCI_DEVICE_ID_INTEL_82801EB_3) },
756 { PCI_DEVICE(PCI_VENDOR_ID_INTEL, PCI_DEVICE_ID_INTEL_ESB_4) },
757 { PCI_DEVICE(PCI_VENDOR_ID_INTEL, PCI_DEVICE_ID_INTEL_ICH6_16) },
758 { PCI_DEVICE(PCI_VENDOR_ID_INTEL, PCI_DEVICE_ID_INTEL_ICH7_17) },
Jason Gastonb0a70b52005-04-16 15:24:45 -0700759 { PCI_DEVICE(PCI_VENDOR_ID_INTEL, PCI_DEVICE_ID_INTEL_ESB2_17) },
Jason Gaston8254fc42006-01-09 10:58:08 -0800760 { PCI_DEVICE(PCI_VENDOR_ID_INTEL, PCI_DEVICE_ID_INTEL_ICH8_5) },
Jason Gastonadbc2a12006-11-22 15:19:12 -0800761 { PCI_DEVICE(PCI_VENDOR_ID_INTEL, PCI_DEVICE_ID_INTEL_ICH9_6) },
Seth Heasleycb04e952010-10-04 13:27:14 -0700762 { PCI_DEVICE(PCI_VENDOR_ID_INTEL, PCI_DEVICE_ID_INTEL_EP80579_1) },
Gaston, Jason Dd28dc712008-02-24 20:03:42 +0100763 { PCI_DEVICE(PCI_VENDOR_ID_INTEL, PCI_DEVICE_ID_INTEL_ICH10_4) },
764 { PCI_DEVICE(PCI_VENDOR_ID_INTEL, PCI_DEVICE_ID_INTEL_ICH10_5) },
Seth Heasleycb04e952010-10-04 13:27:14 -0700765 { PCI_DEVICE(PCI_VENDOR_ID_INTEL, PCI_DEVICE_ID_INTEL_5_3400_SERIES_SMBUS) },
766 { PCI_DEVICE(PCI_VENDOR_ID_INTEL, PCI_DEVICE_ID_INTEL_COUGARPOINT_SMBUS) },
Seth Heasleye30d9852010-10-31 21:06:59 +0100767 { PCI_DEVICE(PCI_VENDOR_ID_INTEL, PCI_DEVICE_ID_INTEL_PATSBURG_SMBUS) },
David Woodhouse55fee8d2010-10-31 21:07:00 +0100768 { PCI_DEVICE(PCI_VENDOR_ID_INTEL, PCI_DEVICE_ID_INTEL_PATSBURG_SMBUS_IDF0) },
769 { PCI_DEVICE(PCI_VENDOR_ID_INTEL, PCI_DEVICE_ID_INTEL_PATSBURG_SMBUS_IDF1) },
770 { PCI_DEVICE(PCI_VENDOR_ID_INTEL, PCI_DEVICE_ID_INTEL_PATSBURG_SMBUS_IDF2) },
Seth Heasley662cda82011-03-20 14:50:53 +0100771 { PCI_DEVICE(PCI_VENDOR_ID_INTEL, PCI_DEVICE_ID_INTEL_DH89XXCC_SMBUS) },
Seth Heasley6e2a8512011-05-24 20:58:49 +0200772 { PCI_DEVICE(PCI_VENDOR_ID_INTEL, PCI_DEVICE_ID_INTEL_PANTHERPOINT_SMBUS) },
Seth Heasley062737f2012-03-26 21:47:19 +0200773 { PCI_DEVICE(PCI_VENDOR_ID_INTEL, PCI_DEVICE_ID_INTEL_LYNXPOINT_SMBUS) },
Linus Torvalds1da177e2005-04-16 15:20:36 -0700774 { 0, }
775};
776
Ivo Manca3fb21c62010-05-21 18:40:55 +0200777MODULE_DEVICE_TABLE(pci, i801_ids);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700778
Jean Delvare8eacfce2011-05-24 20:58:49 +0200779#if defined CONFIG_X86 && defined CONFIG_DMI
Jean Delvare1561bfe2009-01-07 14:29:17 +0100780static unsigned char apanel_addr;
781
782/* Scan the system ROM for the signature "FJKEYINF" */
783static __init const void __iomem *bios_signature(const void __iomem *bios)
784{
785 ssize_t offset;
786 const unsigned char signature[] = "FJKEYINF";
787
788 for (offset = 0; offset < 0x10000; offset += 0x10) {
789 if (check_signature(bios + offset, signature,
790 sizeof(signature)-1))
791 return bios + offset;
792 }
793 return NULL;
794}
795
796static void __init input_apanel_init(void)
797{
798 void __iomem *bios;
799 const void __iomem *p;
800
801 bios = ioremap(0xF0000, 0x10000); /* Can't fail */
802 p = bios_signature(bios);
803 if (p) {
804 /* just use the first address */
805 apanel_addr = readb(p + 8 + 3) >> 1;
806 }
807 iounmap(bios);
808}
Jean Delvare1561bfe2009-01-07 14:29:17 +0100809
Hans de Goedefa5bfab2009-03-30 21:46:44 +0200810struct dmi_onboard_device_info {
811 const char *name;
812 u8 type;
813 unsigned short i2c_addr;
814 const char *i2c_type;
815};
816
817static struct dmi_onboard_device_info __devinitdata dmi_devices[] = {
818 { "Syleus", DMI_DEV_TYPE_OTHER, 0x73, "fscsyl" },
819 { "Hermes", DMI_DEV_TYPE_OTHER, 0x73, "fscher" },
820 { "Hades", DMI_DEV_TYPE_OTHER, 0x73, "fschds" },
821};
822
823static void __devinit dmi_check_onboard_device(u8 type, const char *name,
824 struct i2c_adapter *adap)
825{
826 int i;
827 struct i2c_board_info info;
828
829 for (i = 0; i < ARRAY_SIZE(dmi_devices); i++) {
830 /* & ~0x80, ignore enabled/disabled bit */
831 if ((type & ~0x80) != dmi_devices[i].type)
832 continue;
Jean Delvarefaabd472010-07-09 16:22:51 +0200833 if (strcasecmp(name, dmi_devices[i].name))
Hans de Goedefa5bfab2009-03-30 21:46:44 +0200834 continue;
835
836 memset(&info, 0, sizeof(struct i2c_board_info));
837 info.addr = dmi_devices[i].i2c_addr;
838 strlcpy(info.type, dmi_devices[i].i2c_type, I2C_NAME_SIZE);
839 i2c_new_device(adap, &info);
840 break;
841 }
842}
843
844/* We use our own function to check for onboard devices instead of
845 dmi_find_device() as some buggy BIOS's have the devices we are interested
846 in marked as disabled */
847static void __devinit dmi_check_onboard_devices(const struct dmi_header *dm,
848 void *adap)
849{
850 int i, count;
851
852 if (dm->type != 10)
853 return;
854
855 count = (dm->length - sizeof(struct dmi_header)) / 2;
856 for (i = 0; i < count; i++) {
857 const u8 *d = (char *)(dm + 1) + (i * 2);
858 const char *name = ((char *) dm) + dm->length;
859 u8 type = d[0];
860 u8 s = d[1];
861
862 if (!s)
863 continue;
864 s--;
865 while (s > 0 && name[0]) {
866 name += strlen(name) + 1;
867 s--;
868 }
869 if (name[0] == 0) /* Bogus string reference */
870 continue;
871
872 dmi_check_onboard_device(type, name, adap);
873 }
874}
Hans de Goedefa5bfab2009-03-30 21:46:44 +0200875
Jean Delvaree7198fb2011-05-24 20:58:49 +0200876/* Register optional slaves */
877static void __devinit i801_probe_optional_slaves(struct i801_priv *priv)
878{
879 /* Only register slaves on main SMBus channel */
880 if (priv->features & FEATURE_IDF)
881 return;
882
Jean Delvaree7198fb2011-05-24 20:58:49 +0200883 if (apanel_addr) {
884 struct i2c_board_info info;
885
886 memset(&info, 0, sizeof(struct i2c_board_info));
887 info.addr = apanel_addr;
888 strlcpy(info.type, "fujitsu_apanel", I2C_NAME_SIZE);
889 i2c_new_device(&priv->adapter, &info);
890 }
Jean Delvare8eacfce2011-05-24 20:58:49 +0200891
Jean Delvaree7198fb2011-05-24 20:58:49 +0200892 if (dmi_name_in_vendors("FUJITSU"))
893 dmi_walk(dmi_check_onboard_devices, &priv->adapter);
Jean Delvaree7198fb2011-05-24 20:58:49 +0200894}
Jean Delvare8eacfce2011-05-24 20:58:49 +0200895#else
896static void __init input_apanel_init(void) {}
897static void __devinit i801_probe_optional_slaves(struct i801_priv *priv) {}
898#endif /* CONFIG_X86 && CONFIG_DMI */
Jean Delvaree7198fb2011-05-24 20:58:49 +0200899
Ivo Manca3fb21c62010-05-21 18:40:55 +0200900static int __devinit i801_probe(struct pci_dev *dev,
901 const struct pci_device_id *id)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700902{
Jean Delvare02dd7ae2006-06-12 21:53:41 +0200903 unsigned char temp;
Jean Delvareadff6872010-05-21 18:40:54 +0200904 int err, i;
David Woodhouse0cd96eb2010-10-31 21:06:59 +0100905 struct i801_priv *priv;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700906
David Woodhouse0cd96eb2010-10-31 21:06:59 +0100907 priv = kzalloc(sizeof(*priv), GFP_KERNEL);
908 if (!priv)
909 return -ENOMEM;
910
911 i2c_set_adapdata(&priv->adapter, priv);
912 priv->adapter.owner = THIS_MODULE;
913 priv->adapter.class = I2C_CLASS_HWMON | I2C_CLASS_SPD;
914 priv->adapter.algo = &smbus_algorithm;
915
916 priv->pci_dev = dev;
Jean Delvare250d1bd2006-12-10 21:21:33 +0100917 switch (dev->device) {
Jean Delvaree7198fb2011-05-24 20:58:49 +0200918 case PCI_DEVICE_ID_INTEL_PATSBURG_SMBUS_IDF0:
919 case PCI_DEVICE_ID_INTEL_PATSBURG_SMBUS_IDF1:
920 case PCI_DEVICE_ID_INTEL_PATSBURG_SMBUS_IDF2:
921 priv->features |= FEATURE_IDF;
922 /* fall through */
Jean Delvaree0e8398c2010-05-21 18:40:55 +0200923 default:
David Woodhouse0cd96eb2010-10-31 21:06:59 +0100924 priv->features |= FEATURE_I2C_BLOCK_READ;
Jean Delvare63420642008-01-27 18:14:50 +0100925 /* fall through */
926 case PCI_DEVICE_ID_INTEL_82801DB_3:
David Woodhouse0cd96eb2010-10-31 21:06:59 +0100927 priv->features |= FEATURE_SMBUS_PEC;
928 priv->features |= FEATURE_BLOCK_BUFFER;
Jean Delvaree0e8398c2010-05-21 18:40:55 +0200929 /* fall through */
930 case PCI_DEVICE_ID_INTEL_82801CA_3:
931 case PCI_DEVICE_ID_INTEL_82801BA_2:
932 case PCI_DEVICE_ID_INTEL_82801AB_3:
933 case PCI_DEVICE_ID_INTEL_82801AA_3:
Jean Delvare250d1bd2006-12-10 21:21:33 +0100934 break;
Jean Delvare250d1bd2006-12-10 21:21:33 +0100935 }
Jean Delvare02dd7ae2006-06-12 21:53:41 +0200936
Jean Delvare29b60852012-07-24 14:13:59 +0200937 /* IRQ processing tested on CougarPoint PCH, ICH5, ICH7-M and ICH10 */
938 if (dev->device == PCI_DEVICE_ID_INTEL_COUGARPOINT_SMBUS ||
939 dev->device == PCI_DEVICE_ID_INTEL_82801EB_3 ||
940 dev->device == PCI_DEVICE_ID_INTEL_ICH7_17 ||
941 dev->device == PCI_DEVICE_ID_INTEL_ICH8_5 ||
942 dev->device == PCI_DEVICE_ID_INTEL_ICH9_6 ||
943 dev->device == PCI_DEVICE_ID_INTEL_ICH10_4 ||
944 dev->device == PCI_DEVICE_ID_INTEL_ICH10_5)
Daniel Kurtz636752b2012-07-24 14:13:58 +0200945 priv->features |= FEATURE_IRQ;
946
Jean Delvareadff6872010-05-21 18:40:54 +0200947 /* Disable features on user request */
948 for (i = 0; i < ARRAY_SIZE(i801_feature_names); i++) {
David Woodhouse0cd96eb2010-10-31 21:06:59 +0100949 if (priv->features & disable_features & (1 << i))
Jean Delvareadff6872010-05-21 18:40:54 +0200950 dev_notice(&dev->dev, "%s disabled by user\n",
951 i801_feature_names[i]);
952 }
David Woodhouse0cd96eb2010-10-31 21:06:59 +0100953 priv->features &= ~disable_features;
Jean Delvareadff6872010-05-21 18:40:54 +0200954
Jean Delvare02dd7ae2006-06-12 21:53:41 +0200955 err = pci_enable_device(dev);
956 if (err) {
957 dev_err(&dev->dev, "Failed to enable SMBus PCI device (%d)\n",
958 err);
959 goto exit;
960 }
961
962 /* Determine the address of the SMBus area */
David Woodhouse0cd96eb2010-10-31 21:06:59 +0100963 priv->smba = pci_resource_start(dev, SMBBAR);
964 if (!priv->smba) {
Jean Delvare02dd7ae2006-06-12 21:53:41 +0200965 dev_err(&dev->dev, "SMBus base address uninitialized, "
966 "upgrade BIOS\n");
967 err = -ENODEV;
Daniel Ritzd6fcb3b2006-06-27 18:40:54 +0200968 goto exit;
Jean Delvare02dd7ae2006-06-12 21:53:41 +0200969 }
970
Jean Delvare54fb4a052008-07-14 22:38:33 +0200971 err = acpi_check_resource_conflict(&dev->resource[SMBBAR]);
Jean Delvare18669ea2009-10-04 22:53:45 +0200972 if (err) {
973 err = -ENODEV;
Jean Delvare54fb4a052008-07-14 22:38:33 +0200974 goto exit;
Jean Delvare18669ea2009-10-04 22:53:45 +0200975 }
Jean Delvare54fb4a052008-07-14 22:38:33 +0200976
Jean Delvare02dd7ae2006-06-12 21:53:41 +0200977 err = pci_request_region(dev, SMBBAR, i801_driver.name);
978 if (err) {
979 dev_err(&dev->dev, "Failed to request SMBus region "
David Woodhouse0cd96eb2010-10-31 21:06:59 +0100980 "0x%lx-0x%Lx\n", priv->smba,
Andrew Morton598736c2006-06-30 01:56:20 -0700981 (unsigned long long)pci_resource_end(dev, SMBBAR));
Daniel Ritzd6fcb3b2006-06-27 18:40:54 +0200982 goto exit;
Jean Delvare02dd7ae2006-06-12 21:53:41 +0200983 }
984
David Woodhouse0cd96eb2010-10-31 21:06:59 +0100985 pci_read_config_byte(priv->pci_dev, SMBHSTCFG, &temp);
986 priv->original_hstcfg = temp;
Jean Delvare02dd7ae2006-06-12 21:53:41 +0200987 temp &= ~SMBHSTCFG_I2C_EN; /* SMBus timing */
988 if (!(temp & SMBHSTCFG_HST_EN)) {
989 dev_info(&dev->dev, "Enabling SMBus device\n");
990 temp |= SMBHSTCFG_HST_EN;
991 }
David Woodhouse0cd96eb2010-10-31 21:06:59 +0100992 pci_write_config_byte(priv->pci_dev, SMBHSTCFG, temp);
Jean Delvare02dd7ae2006-06-12 21:53:41 +0200993
Daniel Kurtz636752b2012-07-24 14:13:58 +0200994 if (temp & SMBHSTCFG_SMB_SMI_EN) {
Jean Delvare02dd7ae2006-06-12 21:53:41 +0200995 dev_dbg(&dev->dev, "SMBus using interrupt SMI#\n");
Daniel Kurtz636752b2012-07-24 14:13:58 +0200996 /* Disable SMBus interrupt feature if SMBus using SMI# */
997 priv->features &= ~FEATURE_IRQ;
Daniel Kurtz636752b2012-07-24 14:13:58 +0200998 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700999
Jean Delvarea0921b62008-01-27 18:14:50 +01001000 /* Clear special mode bits */
David Woodhouse0cd96eb2010-10-31 21:06:59 +01001001 if (priv->features & (FEATURE_SMBUS_PEC | FEATURE_BLOCK_BUFFER))
1002 outb_p(inb_p(SMBAUXCTL(priv)) &
1003 ~(SMBAUXCTL_CRC | SMBAUXCTL_E32B), SMBAUXCTL(priv));
Jean Delvarea0921b62008-01-27 18:14:50 +01001004
Daniel Kurtz636752b2012-07-24 14:13:58 +02001005 if (priv->features & FEATURE_IRQ) {
1006 init_waitqueue_head(&priv->waitq);
1007
1008 err = request_irq(dev->irq, i801_isr, IRQF_SHARED,
1009 i801_driver.name, priv);
1010 if (err) {
1011 dev_err(&dev->dev, "Failed to allocate irq %d: %d\n",
1012 dev->irq, err);
1013 goto exit_release;
1014 }
Jean Delvare29b60852012-07-24 14:13:59 +02001015 dev_info(&dev->dev, "SMBus using PCI Interrupt\n");
Daniel Kurtz636752b2012-07-24 14:13:58 +02001016 }
1017
Robert P. J. Day405ae7d2007-02-17 19:13:42 +01001018 /* set up the sysfs linkage to our parent device */
David Woodhouse0cd96eb2010-10-31 21:06:59 +01001019 priv->adapter.dev.parent = &dev->dev;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001020
Jean Delvare7e2193a2009-12-06 17:06:27 +01001021 /* Retry up to 3 times on lost arbitration */
David Woodhouse0cd96eb2010-10-31 21:06:59 +01001022 priv->adapter.retries = 3;
Jean Delvare7e2193a2009-12-06 17:06:27 +01001023
David Woodhouse0cd96eb2010-10-31 21:06:59 +01001024 snprintf(priv->adapter.name, sizeof(priv->adapter.name),
1025 "SMBus I801 adapter at %04lx", priv->smba);
1026 err = i2c_add_adapter(&priv->adapter);
Jean Delvare02dd7ae2006-06-12 21:53:41 +02001027 if (err) {
1028 dev_err(&dev->dev, "Failed to add SMBus adapter\n");
Daniel Kurtz636752b2012-07-24 14:13:58 +02001029 goto exit_free_irq;
Jean Delvare02dd7ae2006-06-12 21:53:41 +02001030 }
Jean Delvare1561bfe2009-01-07 14:29:17 +01001031
Jean Delvaree7198fb2011-05-24 20:58:49 +02001032 i801_probe_optional_slaves(priv);
Jean Delvare1561bfe2009-01-07 14:29:17 +01001033
David Woodhouse0cd96eb2010-10-31 21:06:59 +01001034 pci_set_drvdata(dev, priv);
Daniel Kurtz636752b2012-07-24 14:13:58 +02001035
Daniel Ritzd6fcb3b2006-06-27 18:40:54 +02001036 return 0;
Jean Delvare02dd7ae2006-06-12 21:53:41 +02001037
Daniel Kurtz636752b2012-07-24 14:13:58 +02001038exit_free_irq:
1039 if (priv->features & FEATURE_IRQ)
1040 free_irq(dev->irq, priv);
Daniel Ritzd6fcb3b2006-06-27 18:40:54 +02001041exit_release:
1042 pci_release_region(dev, SMBBAR);
Jean Delvare02dd7ae2006-06-12 21:53:41 +02001043exit:
David Woodhouse0cd96eb2010-10-31 21:06:59 +01001044 kfree(priv);
Jean Delvare02dd7ae2006-06-12 21:53:41 +02001045 return err;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001046}
1047
1048static void __devexit i801_remove(struct pci_dev *dev)
1049{
David Woodhouse0cd96eb2010-10-31 21:06:59 +01001050 struct i801_priv *priv = pci_get_drvdata(dev);
1051
1052 i2c_del_adapter(&priv->adapter);
1053 pci_write_config_byte(dev, SMBHSTCFG, priv->original_hstcfg);
Daniel Kurtz636752b2012-07-24 14:13:58 +02001054
1055 if (priv->features & FEATURE_IRQ)
1056 free_irq(dev->irq, priv);
Jean Delvare6dcc19d2006-06-12 21:53:02 +02001057 pci_release_region(dev, SMBBAR);
Daniel Kurtz636752b2012-07-24 14:13:58 +02001058
David Woodhouse0cd96eb2010-10-31 21:06:59 +01001059 pci_set_drvdata(dev, NULL);
1060 kfree(priv);
Daniel Ritzd6fcb3b2006-06-27 18:40:54 +02001061 /*
1062 * do not call pci_disable_device(dev) since it can cause hard hangs on
1063 * some systems during power-off (eg. Fujitsu-Siemens Lifebook E8010)
1064 */
Linus Torvalds1da177e2005-04-16 15:20:36 -07001065}
1066
Jean Delvarea5aaea32007-03-22 19:49:01 +01001067#ifdef CONFIG_PM
1068static int i801_suspend(struct pci_dev *dev, pm_message_t mesg)
1069{
David Woodhouse0cd96eb2010-10-31 21:06:59 +01001070 struct i801_priv *priv = pci_get_drvdata(dev);
1071
Jean Delvarea5aaea32007-03-22 19:49:01 +01001072 pci_save_state(dev);
David Woodhouse0cd96eb2010-10-31 21:06:59 +01001073 pci_write_config_byte(dev, SMBHSTCFG, priv->original_hstcfg);
Jean Delvarea5aaea32007-03-22 19:49:01 +01001074 pci_set_power_state(dev, pci_choose_state(dev, mesg));
1075 return 0;
1076}
1077
1078static int i801_resume(struct pci_dev *dev)
1079{
1080 pci_set_power_state(dev, PCI_D0);
1081 pci_restore_state(dev);
1082 return pci_enable_device(dev);
1083}
1084#else
1085#define i801_suspend NULL
1086#define i801_resume NULL
1087#endif
1088
Linus Torvalds1da177e2005-04-16 15:20:36 -07001089static struct pci_driver i801_driver = {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001090 .name = "i801_smbus",
1091 .id_table = i801_ids,
1092 .probe = i801_probe,
1093 .remove = __devexit_p(i801_remove),
Jean Delvarea5aaea32007-03-22 19:49:01 +01001094 .suspend = i801_suspend,
1095 .resume = i801_resume,
Linus Torvalds1da177e2005-04-16 15:20:36 -07001096};
1097
1098static int __init i2c_i801_init(void)
1099{
Jean Delvare6aa14642011-05-24 20:58:49 +02001100 if (dmi_name_in_vendors("FUJITSU"))
1101 input_apanel_init();
Linus Torvalds1da177e2005-04-16 15:20:36 -07001102 return pci_register_driver(&i801_driver);
1103}
1104
1105static void __exit i2c_i801_exit(void)
1106{
1107 pci_unregister_driver(&i801_driver);
1108}
1109
Jean Delvare63420642008-01-27 18:14:50 +01001110MODULE_AUTHOR("Mark D. Studebaker <mdsxyz123@yahoo.com>, "
1111 "Jean Delvare <khali@linux-fr.org>");
Linus Torvalds1da177e2005-04-16 15:20:36 -07001112MODULE_DESCRIPTION("I801 SMBus driver");
1113MODULE_LICENSE("GPL");
1114
1115module_init(i2c_i801_init);
1116module_exit(i2c_i801_exit);