blob: 33e9b0c09af208762f7f8f58b4c3895798618233 [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
James Ralston4a8f1dd2012-09-10 10:14:02 +020055 Lynx Point-LP (PCH) 0x9c22 32 hard yes yes yes
Jean Delvareae7b0492008-01-27 18:14:49 +010056
57 Features supported by this driver:
58 Software PEC no
59 Hardware PEC yes
60 Block buffer yes
61 Block process call transaction no
Jean Delvare63420642008-01-27 18:14:50 +010062 I2C block read transaction yes (doesn't use the block buffer)
David Woodhouse55fee8d2010-10-31 21:07:00 +010063 Slave mode no
Daniel Kurtz636752b2012-07-24 14:13:58 +020064 Interrupt processing yes
Jean Delvareae7b0492008-01-27 18:14:49 +010065
66 See the file Documentation/i2c/busses/i2c-i801 for details.
Linus Torvalds1da177e2005-04-16 15:20:36 -070067*/
68
Daniel Kurtz636752b2012-07-24 14:13:58 +020069#include <linux/interrupt.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070070#include <linux/module.h>
71#include <linux/pci.h>
72#include <linux/kernel.h>
73#include <linux/stddef.h>
74#include <linux/delay.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070075#include <linux/ioport.h>
76#include <linux/init.h>
77#include <linux/i2c.h>
Jean Delvare54fb4a052008-07-14 22:38:33 +020078#include <linux/acpi.h>
Jean Delvare1561bfe2009-01-07 14:29:17 +010079#include <linux/io.h>
Hans de Goedefa5bfab2009-03-30 21:46:44 +020080#include <linux/dmi.h>
Ben Hutchings665a96b2011-01-10 22:11:22 +010081#include <linux/slab.h>
Daniel Kurtz636752b2012-07-24 14:13:58 +020082#include <linux/wait.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070083
Linus Torvalds1da177e2005-04-16 15:20:36 -070084/* I801 SMBus address offsets */
David Woodhouse0cd96eb2010-10-31 21:06:59 +010085#define SMBHSTSTS(p) (0 + (p)->smba)
86#define SMBHSTCNT(p) (2 + (p)->smba)
87#define SMBHSTCMD(p) (3 + (p)->smba)
88#define SMBHSTADD(p) (4 + (p)->smba)
89#define SMBHSTDAT0(p) (5 + (p)->smba)
90#define SMBHSTDAT1(p) (6 + (p)->smba)
91#define SMBBLKDAT(p) (7 + (p)->smba)
92#define SMBPEC(p) (8 + (p)->smba) /* ICH3 and later */
93#define SMBAUXSTS(p) (12 + (p)->smba) /* ICH4 and later */
94#define SMBAUXCTL(p) (13 + (p)->smba) /* ICH4 and later */
Linus Torvalds1da177e2005-04-16 15:20:36 -070095
96/* PCI Address Constants */
Jean Delvare6dcc19d2006-06-12 21:53:02 +020097#define SMBBAR 4
Daniel Kurtz636752b2012-07-24 14:13:58 +020098#define SMBPCISTS 0x006
Linus Torvalds1da177e2005-04-16 15:20:36 -070099#define SMBHSTCFG 0x040
Linus Torvalds1da177e2005-04-16 15:20:36 -0700100
Daniel Kurtz636752b2012-07-24 14:13:58 +0200101/* Host status bits for SMBPCISTS */
102#define SMBPCISTS_INTS 0x08
103
Linus Torvalds1da177e2005-04-16 15:20:36 -0700104/* Host configuration bits for SMBHSTCFG */
105#define SMBHSTCFG_HST_EN 1
106#define SMBHSTCFG_SMB_SMI_EN 2
107#define SMBHSTCFG_I2C_EN 4
108
Lucas De Marchi25985ed2011-03-30 22:57:33 -0300109/* Auxiliary control register bits, ICH4+ only */
Oleg Ryjkovca8b9e32007-07-12 14:12:31 +0200110#define SMBAUXCTL_CRC 1
111#define SMBAUXCTL_E32B 2
112
Linus Torvalds1da177e2005-04-16 15:20:36 -0700113/* Other settings */
Jean Delvare84c1af42012-03-26 21:47:19 +0200114#define MAX_RETRIES 400
Linus Torvalds1da177e2005-04-16 15:20:36 -0700115
116/* I801 command constants */
117#define I801_QUICK 0x00
118#define I801_BYTE 0x04
119#define I801_BYTE_DATA 0x08
120#define I801_WORD_DATA 0x0C
Jean Delvareae7b0492008-01-27 18:14:49 +0100121#define I801_PROC_CALL 0x10 /* unimplemented */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700122#define I801_BLOCK_DATA 0x14
Jean Delvare63420642008-01-27 18:14:50 +0100123#define I801_I2C_BLOCK_DATA 0x18 /* ICH5 and later */
Daniel Kurtzedbeea62012-07-24 14:13:58 +0200124
125/* I801 Host Control register bits */
126#define SMBHSTCNT_INTREN 0x01
127#define SMBHSTCNT_KILL 0x02
128#define SMBHSTCNT_LAST_BYTE 0x20
129#define SMBHSTCNT_START 0x40
130#define SMBHSTCNT_PEC_EN 0x80 /* ICH3 and later */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700131
Oleg Ryjkovca8b9e32007-07-12 14:12:31 +0200132/* I801 Hosts Status register bits */
133#define SMBHSTSTS_BYTE_DONE 0x80
134#define SMBHSTSTS_INUSE_STS 0x40
135#define SMBHSTSTS_SMBALERT_STS 0x20
136#define SMBHSTSTS_FAILED 0x10
137#define SMBHSTSTS_BUS_ERR 0x08
138#define SMBHSTSTS_DEV_ERR 0x04
139#define SMBHSTSTS_INTR 0x02
140#define SMBHSTSTS_HOST_BUSY 0x01
Linus Torvalds1da177e2005-04-16 15:20:36 -0700141
Daniel Kurtz70a1cc12012-07-24 14:13:58 +0200142#define STATUS_ERROR_FLAGS (SMBHSTSTS_FAILED | SMBHSTSTS_BUS_ERR | \
143 SMBHSTSTS_DEV_ERR)
144
145#define STATUS_FLAGS (SMBHSTSTS_BYTE_DONE | SMBHSTSTS_INTR | \
146 STATUS_ERROR_FLAGS)
Jean Delvarecf898dc2008-07-14 22:38:33 +0200147
Jean Delvarea6e5e2b2011-05-01 18:18:49 +0200148/* Older devices have their ID defined in <linux/pci_ids.h> */
149#define PCI_DEVICE_ID_INTEL_COUGARPOINT_SMBUS 0x1c22
150#define PCI_DEVICE_ID_INTEL_PATSBURG_SMBUS 0x1d22
David Woodhouse55fee8d2010-10-31 21:07:00 +0100151/* Patsburg also has three 'Integrated Device Function' SMBus controllers */
152#define PCI_DEVICE_ID_INTEL_PATSBURG_SMBUS_IDF0 0x1d70
153#define PCI_DEVICE_ID_INTEL_PATSBURG_SMBUS_IDF1 0x1d71
154#define PCI_DEVICE_ID_INTEL_PATSBURG_SMBUS_IDF2 0x1d72
Seth Heasley6e2a8512011-05-24 20:58:49 +0200155#define PCI_DEVICE_ID_INTEL_PANTHERPOINT_SMBUS 0x1e22
Jean Delvarea6e5e2b2011-05-01 18:18:49 +0200156#define PCI_DEVICE_ID_INTEL_DH89XXCC_SMBUS 0x2330
157#define PCI_DEVICE_ID_INTEL_5_3400_SERIES_SMBUS 0x3b30
Seth Heasley062737f2012-03-26 21:47:19 +0200158#define PCI_DEVICE_ID_INTEL_LYNXPOINT_SMBUS 0x8c22
James Ralston4a8f1dd2012-09-10 10:14:02 +0200159#define PCI_DEVICE_ID_INTEL_LYNXPOINT_LP_SMBUS 0x9c22
David Woodhouse55fee8d2010-10-31 21:07:00 +0100160
David Woodhouse0cd96eb2010-10-31 21:06:59 +0100161struct i801_priv {
162 struct i2c_adapter adapter;
163 unsigned long smba;
164 unsigned char original_hstcfg;
165 struct pci_dev *pci_dev;
166 unsigned int features;
Daniel Kurtz636752b2012-07-24 14:13:58 +0200167
168 /* isr processing */
169 wait_queue_head_t waitq;
170 u8 status;
Daniel Kurtzd3ff6ce2012-07-24 14:13:59 +0200171
172 /* Command state used by isr for byte-by-byte block transactions */
173 u8 cmd;
174 bool is_read;
175 int count;
176 int len;
177 u8 *data;
David Woodhouse0cd96eb2010-10-31 21:06:59 +0100178};
179
Jean Delvared6072f82005-09-25 16:37:04 +0200180static struct pci_driver i801_driver;
Jean Delvare369f6f42008-01-27 18:14:50 +0100181
182#define FEATURE_SMBUS_PEC (1 << 0)
183#define FEATURE_BLOCK_BUFFER (1 << 1)
184#define FEATURE_BLOCK_PROC (1 << 2)
185#define FEATURE_I2C_BLOCK_READ (1 << 3)
Daniel Kurtz636752b2012-07-24 14:13:58 +0200186#define FEATURE_IRQ (1 << 4)
Jean Delvaree7198fb2011-05-24 20:58:49 +0200187/* Not really a feature, but it's convenient to handle it as such */
188#define FEATURE_IDF (1 << 15)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700189
Jean Delvareadff6872010-05-21 18:40:54 +0200190static const char *i801_feature_names[] = {
191 "SMBus PEC",
192 "Block buffer",
193 "Block process call",
194 "I2C block read",
Daniel Kurtz636752b2012-07-24 14:13:58 +0200195 "Interrupt",
Jean Delvareadff6872010-05-21 18:40:54 +0200196};
197
198static unsigned int disable_features;
199module_param(disable_features, uint, S_IRUGO | S_IWUSR);
200MODULE_PARM_DESC(disable_features, "Disable selected driver features");
201
Jean Delvarecf898dc2008-07-14 22:38:33 +0200202/* Make sure the SMBus host is ready to start transmitting.
203 Return 0 if it is, -EBUSY if it is not. */
David Woodhouse0cd96eb2010-10-31 21:06:59 +0100204static int i801_check_pre(struct i801_priv *priv)
Jean Delvarecf898dc2008-07-14 22:38:33 +0200205{
206 int status;
207
David Woodhouse0cd96eb2010-10-31 21:06:59 +0100208 status = inb_p(SMBHSTSTS(priv));
Jean Delvarecf898dc2008-07-14 22:38:33 +0200209 if (status & SMBHSTSTS_HOST_BUSY) {
David Woodhouse0cd96eb2010-10-31 21:06:59 +0100210 dev_err(&priv->pci_dev->dev, "SMBus is busy, can't use it!\n");
Jean Delvarecf898dc2008-07-14 22:38:33 +0200211 return -EBUSY;
212 }
213
214 status &= STATUS_FLAGS;
215 if (status) {
David Woodhouse0cd96eb2010-10-31 21:06:59 +0100216 dev_dbg(&priv->pci_dev->dev, "Clearing status flags (%02x)\n",
Jean Delvarecf898dc2008-07-14 22:38:33 +0200217 status);
David Woodhouse0cd96eb2010-10-31 21:06:59 +0100218 outb_p(status, SMBHSTSTS(priv));
219 status = inb_p(SMBHSTSTS(priv)) & STATUS_FLAGS;
Jean Delvarecf898dc2008-07-14 22:38:33 +0200220 if (status) {
David Woodhouse0cd96eb2010-10-31 21:06:59 +0100221 dev_err(&priv->pci_dev->dev,
Jean Delvarecf898dc2008-07-14 22:38:33 +0200222 "Failed clearing status flags (%02x)\n",
223 status);
224 return -EBUSY;
225 }
226 }
227
228 return 0;
229}
230
Jean Delvare6cad93c2012-07-24 14:13:58 +0200231/*
232 * Convert the status register to an error code, and clear it.
233 * Note that status only contains the bits we want to clear, not the
234 * actual register value.
235 */
236static int i801_check_post(struct i801_priv *priv, int status)
Jean Delvarecf898dc2008-07-14 22:38:33 +0200237{
238 int result = 0;
239
Daniel Kurtz636752b2012-07-24 14:13:58 +0200240 /*
241 * If the SMBus is still busy, we give up
242 * Note: This timeout condition only happens when using polling
243 * transactions. For interrupt operation, NAK/timeout is indicated by
244 * DEV_ERR.
245 */
Jean Delvare6cad93c2012-07-24 14:13:58 +0200246 if (unlikely(status < 0)) {
David Woodhouse0cd96eb2010-10-31 21:06:59 +0100247 dev_err(&priv->pci_dev->dev, "Transaction timeout\n");
Jean Delvarecf898dc2008-07-14 22:38:33 +0200248 /* try to stop the current command */
David Woodhouse0cd96eb2010-10-31 21:06:59 +0100249 dev_dbg(&priv->pci_dev->dev, "Terminating the current operation\n");
250 outb_p(inb_p(SMBHSTCNT(priv)) | SMBHSTCNT_KILL,
251 SMBHSTCNT(priv));
Jean Delvare84c1af42012-03-26 21:47:19 +0200252 usleep_range(1000, 2000);
David Woodhouse0cd96eb2010-10-31 21:06:59 +0100253 outb_p(inb_p(SMBHSTCNT(priv)) & (~SMBHSTCNT_KILL),
254 SMBHSTCNT(priv));
Jean Delvarecf898dc2008-07-14 22:38:33 +0200255
256 /* Check if it worked */
David Woodhouse0cd96eb2010-10-31 21:06:59 +0100257 status = inb_p(SMBHSTSTS(priv));
Jean Delvarecf898dc2008-07-14 22:38:33 +0200258 if ((status & SMBHSTSTS_HOST_BUSY) ||
259 !(status & SMBHSTSTS_FAILED))
David Woodhouse0cd96eb2010-10-31 21:06:59 +0100260 dev_err(&priv->pci_dev->dev,
Jean Delvarecf898dc2008-07-14 22:38:33 +0200261 "Failed terminating the transaction\n");
David Woodhouse0cd96eb2010-10-31 21:06:59 +0100262 outb_p(STATUS_FLAGS, SMBHSTSTS(priv));
Jean Delvarecf898dc2008-07-14 22:38:33 +0200263 return -ETIMEDOUT;
264 }
265
266 if (status & SMBHSTSTS_FAILED) {
267 result = -EIO;
David Woodhouse0cd96eb2010-10-31 21:06:59 +0100268 dev_err(&priv->pci_dev->dev, "Transaction failed\n");
Jean Delvarecf898dc2008-07-14 22:38:33 +0200269 }
270 if (status & SMBHSTSTS_DEV_ERR) {
271 result = -ENXIO;
David Woodhouse0cd96eb2010-10-31 21:06:59 +0100272 dev_dbg(&priv->pci_dev->dev, "No response\n");
Jean Delvarecf898dc2008-07-14 22:38:33 +0200273 }
274 if (status & SMBHSTSTS_BUS_ERR) {
275 result = -EAGAIN;
David Woodhouse0cd96eb2010-10-31 21:06:59 +0100276 dev_dbg(&priv->pci_dev->dev, "Lost arbitration\n");
Jean Delvarecf898dc2008-07-14 22:38:33 +0200277 }
278
Jean Delvare6cad93c2012-07-24 14:13:58 +0200279 /* Clear status flags except BYTE_DONE, to be cleared by caller */
280 outb_p(status, SMBHSTSTS(priv));
Jean Delvarecf898dc2008-07-14 22:38:33 +0200281
282 return result;
283}
284
Jean Delvare6cad93c2012-07-24 14:13:58 +0200285/* Wait for BUSY being cleared and either INTR or an error flag being set */
286static int i801_wait_intr(struct i801_priv *priv)
287{
288 int timeout = 0;
289 int status;
290
291 /* We will always wait for a fraction of a second! */
292 do {
293 usleep_range(250, 500);
294 status = inb_p(SMBHSTSTS(priv));
295 } while (((status & SMBHSTSTS_HOST_BUSY) ||
296 !(status & (STATUS_ERROR_FLAGS | SMBHSTSTS_INTR))) &&
297 (timeout++ < MAX_RETRIES));
298
299 if (timeout > MAX_RETRIES) {
300 dev_dbg(&priv->pci_dev->dev, "INTR Timeout!\n");
301 return -ETIMEDOUT;
302 }
303 return status & (STATUS_ERROR_FLAGS | SMBHSTSTS_INTR);
304}
305
306/* Wait for either BYTE_DONE or an error flag being set */
307static int i801_wait_byte_done(struct i801_priv *priv)
308{
309 int timeout = 0;
310 int status;
311
312 /* We will always wait for a fraction of a second! */
313 do {
314 usleep_range(250, 500);
315 status = inb_p(SMBHSTSTS(priv));
316 } while (!(status & (STATUS_ERROR_FLAGS | SMBHSTSTS_BYTE_DONE)) &&
317 (timeout++ < MAX_RETRIES));
318
319 if (timeout > MAX_RETRIES) {
320 dev_dbg(&priv->pci_dev->dev, "BYTE_DONE Timeout!\n");
321 return -ETIMEDOUT;
322 }
323 return status & STATUS_ERROR_FLAGS;
324}
325
David Woodhouse0cd96eb2010-10-31 21:06:59 +0100326static int i801_transaction(struct i801_priv *priv, int xact)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700327{
Jean Delvare2b738092008-07-14 22:38:32 +0200328 int status;
Jean Delvarecf898dc2008-07-14 22:38:33 +0200329 int result;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700330
David Woodhouse0cd96eb2010-10-31 21:06:59 +0100331 result = i801_check_pre(priv);
Jean Delvarecf898dc2008-07-14 22:38:33 +0200332 if (result < 0)
333 return result;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700334
Daniel Kurtz636752b2012-07-24 14:13:58 +0200335 if (priv->features & FEATURE_IRQ) {
336 outb_p(xact | SMBHSTCNT_INTREN | SMBHSTCNT_START,
337 SMBHSTCNT(priv));
338 wait_event(priv->waitq, (status = priv->status));
339 priv->status = 0;
340 return i801_check_post(priv, status);
341 }
342
Oleg Ryjkov7edcb9a2007-07-12 14:12:31 +0200343 /* the current contents of SMBHSTCNT can be overwritten, since PEC,
Daniel Kurtz37af8712012-07-24 14:13:58 +0200344 * SMBSCMD are passed in xact */
Daniel Kurtzedbeea62012-07-24 14:13:58 +0200345 outb_p(xact | SMBHSTCNT_START, SMBHSTCNT(priv));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700346
Jean Delvare6cad93c2012-07-24 14:13:58 +0200347 status = i801_wait_intr(priv);
348 return i801_check_post(priv, status);
Oleg Ryjkovca8b9e32007-07-12 14:12:31 +0200349}
350
David Woodhouse0cd96eb2010-10-31 21:06:59 +0100351static int i801_block_transaction_by_block(struct i801_priv *priv,
352 union i2c_smbus_data *data,
Oleg Ryjkov7edcb9a2007-07-12 14:12:31 +0200353 char read_write, int hwpec)
354{
355 int i, len;
David Brownell97140342008-07-14 22:38:25 +0200356 int status;
Oleg Ryjkov7edcb9a2007-07-12 14:12:31 +0200357
David Woodhouse0cd96eb2010-10-31 21:06:59 +0100358 inb_p(SMBHSTCNT(priv)); /* reset the data buffer index */
Oleg Ryjkov7edcb9a2007-07-12 14:12:31 +0200359
360 /* Use 32-byte buffer to process this transaction */
361 if (read_write == I2C_SMBUS_WRITE) {
362 len = data->block[0];
David Woodhouse0cd96eb2010-10-31 21:06:59 +0100363 outb_p(len, SMBHSTDAT0(priv));
Oleg Ryjkov7edcb9a2007-07-12 14:12:31 +0200364 for (i = 0; i < len; i++)
David Woodhouse0cd96eb2010-10-31 21:06:59 +0100365 outb_p(data->block[i+1], SMBBLKDAT(priv));
Oleg Ryjkov7edcb9a2007-07-12 14:12:31 +0200366 }
367
Daniel Kurtz37af8712012-07-24 14:13:58 +0200368 status = i801_transaction(priv, I801_BLOCK_DATA |
Daniel Kurtzedbeea62012-07-24 14:13:58 +0200369 (hwpec ? SMBHSTCNT_PEC_EN : 0));
David Brownell97140342008-07-14 22:38:25 +0200370 if (status)
371 return status;
Oleg Ryjkov7edcb9a2007-07-12 14:12:31 +0200372
373 if (read_write == I2C_SMBUS_READ) {
David Woodhouse0cd96eb2010-10-31 21:06:59 +0100374 len = inb_p(SMBHSTDAT0(priv));
Oleg Ryjkov7edcb9a2007-07-12 14:12:31 +0200375 if (len < 1 || len > I2C_SMBUS_BLOCK_MAX)
David Brownell97140342008-07-14 22:38:25 +0200376 return -EPROTO;
Oleg Ryjkov7edcb9a2007-07-12 14:12:31 +0200377
378 data->block[0] = len;
379 for (i = 0; i < len; i++)
David Woodhouse0cd96eb2010-10-31 21:06:59 +0100380 data->block[i + 1] = inb_p(SMBBLKDAT(priv));
Oleg Ryjkov7edcb9a2007-07-12 14:12:31 +0200381 }
382 return 0;
383}
384
Daniel Kurtzd3ff6ce2012-07-24 14:13:59 +0200385static void i801_isr_byte_done(struct i801_priv *priv)
386{
387 if (priv->is_read) {
388 /* For SMBus block reads, length is received with first byte */
389 if (((priv->cmd & 0x1c) == I801_BLOCK_DATA) &&
390 (priv->count == 0)) {
391 priv->len = inb_p(SMBHSTDAT0(priv));
392 if (priv->len < 1 || priv->len > I2C_SMBUS_BLOCK_MAX) {
393 dev_err(&priv->pci_dev->dev,
394 "Illegal SMBus block read size %d\n",
395 priv->len);
396 /* FIXME: Recover */
397 priv->len = I2C_SMBUS_BLOCK_MAX;
398 } else {
399 dev_dbg(&priv->pci_dev->dev,
400 "SMBus block read size is %d\n",
401 priv->len);
402 }
403 priv->data[-1] = priv->len;
404 }
405
406 /* Read next byte */
407 if (priv->count < priv->len)
408 priv->data[priv->count++] = inb(SMBBLKDAT(priv));
409 else
410 dev_dbg(&priv->pci_dev->dev,
411 "Discarding extra byte on block read\n");
412
413 /* Set LAST_BYTE for last byte of read transaction */
414 if (priv->count == priv->len - 1)
415 outb_p(priv->cmd | SMBHSTCNT_LAST_BYTE,
416 SMBHSTCNT(priv));
417 } else if (priv->count < priv->len - 1) {
418 /* Write next byte, except for IRQ after last byte */
419 outb_p(priv->data[++priv->count], SMBBLKDAT(priv));
420 }
421
422 /* Clear BYTE_DONE to continue with next byte */
423 outb_p(SMBHSTSTS_BYTE_DONE, SMBHSTSTS(priv));
424}
425
Daniel Kurtzefa3cb12012-07-24 14:13:57 +0200426/*
Daniel Kurtzd3ff6ce2012-07-24 14:13:59 +0200427 * There are two kinds of interrupts:
428 *
429 * 1) i801 signals transaction completion with one of these interrupts:
430 * INTR - Success
431 * DEV_ERR - Invalid command, NAK or communication timeout
432 * BUS_ERR - SMI# transaction collision
433 * FAILED - transaction was canceled due to a KILL request
434 * When any of these occur, update ->status and wake up the waitq.
435 * ->status must be cleared before kicking off the next transaction.
436 *
437 * 2) For byte-by-byte (I2C read/write) transactions, one BYTE_DONE interrupt
438 * occurs for each byte of a byte-by-byte to prepare the next byte.
Daniel Kurtz636752b2012-07-24 14:13:58 +0200439 */
440static irqreturn_t i801_isr(int irq, void *dev_id)
441{
442 struct i801_priv *priv = dev_id;
443 u16 pcists;
444 u8 status;
445
446 /* Confirm this is our interrupt */
447 pci_read_config_word(priv->pci_dev, SMBPCISTS, &pcists);
448 if (!(pcists & SMBPCISTS_INTS))
449 return IRQ_NONE;
450
451 status = inb_p(SMBHSTSTS(priv));
452 if (status != 0x42)
453 dev_dbg(&priv->pci_dev->dev, "irq: status = %02x\n", status);
454
Daniel Kurtzd3ff6ce2012-07-24 14:13:59 +0200455 if (status & SMBHSTSTS_BYTE_DONE)
456 i801_isr_byte_done(priv);
457
Daniel Kurtz636752b2012-07-24 14:13:58 +0200458 /*
459 * Clear irq sources and report transaction result.
460 * ->status must be cleared before the next transaction is started.
461 */
462 status &= SMBHSTSTS_INTR | STATUS_ERROR_FLAGS;
463 if (status) {
464 outb_p(status, SMBHSTSTS(priv));
465 priv->status |= status;
466 wake_up(&priv->waitq);
467 }
468
469 return IRQ_HANDLED;
470}
471
472/*
Daniel Kurtzefa3cb12012-07-24 14:13:57 +0200473 * For "byte-by-byte" block transactions:
474 * I2C write uses cmd=I801_BLOCK_DATA, I2C_EN=1
475 * I2C read uses cmd=I801_I2C_BLOCK_DATA
476 */
David Woodhouse0cd96eb2010-10-31 21:06:59 +0100477static int i801_block_transaction_byte_by_byte(struct i801_priv *priv,
478 union i2c_smbus_data *data,
Jean Delvare63420642008-01-27 18:14:50 +0100479 char read_write, int command,
480 int hwpec)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700481{
482 int i, len;
483 int smbcmd;
Jean Delvare2b738092008-07-14 22:38:32 +0200484 int status;
Jean Delvarecf898dc2008-07-14 22:38:33 +0200485 int result;
Jean Delvarecf898dc2008-07-14 22:38:33 +0200486
David Woodhouse0cd96eb2010-10-31 21:06:59 +0100487 result = i801_check_pre(priv);
Jean Delvarecf898dc2008-07-14 22:38:33 +0200488 if (result < 0)
489 return result;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700490
Oleg Ryjkov7edcb9a2007-07-12 14:12:31 +0200491 len = data->block[0];
Linus Torvalds1da177e2005-04-16 15:20:36 -0700492
493 if (read_write == I2C_SMBUS_WRITE) {
David Woodhouse0cd96eb2010-10-31 21:06:59 +0100494 outb_p(len, SMBHSTDAT0(priv));
495 outb_p(data->block[1], SMBBLKDAT(priv));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700496 }
497
Daniel Kurtzefa3cb12012-07-24 14:13:57 +0200498 if (command == I2C_SMBUS_I2C_BLOCK_DATA &&
499 read_write == I2C_SMBUS_READ)
500 smbcmd = I801_I2C_BLOCK_DATA;
501 else
502 smbcmd = I801_BLOCK_DATA;
503
Daniel Kurtzd3ff6ce2012-07-24 14:13:59 +0200504 if (priv->features & FEATURE_IRQ) {
505 priv->is_read = (read_write == I2C_SMBUS_READ);
506 if (len == 1 && priv->is_read)
507 smbcmd |= SMBHSTCNT_LAST_BYTE;
508 priv->cmd = smbcmd | SMBHSTCNT_INTREN;
509 priv->len = len;
510 priv->count = 0;
511 priv->data = &data->block[1];
512
513 outb_p(priv->cmd | SMBHSTCNT_START, SMBHSTCNT(priv));
514 wait_event(priv->waitq, (status = priv->status));
515 priv->status = 0;
516 return i801_check_post(priv, status);
517 }
518
Linus Torvalds1da177e2005-04-16 15:20:36 -0700519 for (i = 1; i <= len; i++) {
Daniel Kurtzefa3cb12012-07-24 14:13:57 +0200520 if (i == len && read_write == I2C_SMBUS_READ)
Daniel Kurtzedbeea62012-07-24 14:13:58 +0200521 smbcmd |= SMBHSTCNT_LAST_BYTE;
Daniel Kurtz37af8712012-07-24 14:13:58 +0200522 outb_p(smbcmd, SMBHSTCNT(priv));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700523
Linus Torvalds1da177e2005-04-16 15:20:36 -0700524 if (i == 1)
Daniel Kurtzedbeea62012-07-24 14:13:58 +0200525 outb_p(inb(SMBHSTCNT(priv)) | SMBHSTCNT_START,
David Woodhouse0cd96eb2010-10-31 21:06:59 +0100526 SMBHSTCNT(priv));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700527
Jean Delvare6cad93c2012-07-24 14:13:58 +0200528 status = i801_wait_byte_done(priv);
529 if (status)
530 goto exit;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700531
Jean Delvare63420642008-01-27 18:14:50 +0100532 if (i == 1 && read_write == I2C_SMBUS_READ
533 && command != I2C_SMBUS_I2C_BLOCK_DATA) {
David Woodhouse0cd96eb2010-10-31 21:06:59 +0100534 len = inb_p(SMBHSTDAT0(priv));
Jean Delvarecf898dc2008-07-14 22:38:33 +0200535 if (len < 1 || len > I2C_SMBUS_BLOCK_MAX) {
David Woodhouse0cd96eb2010-10-31 21:06:59 +0100536 dev_err(&priv->pci_dev->dev,
Jean Delvarecf898dc2008-07-14 22:38:33 +0200537 "Illegal SMBus block read size %d\n",
538 len);
539 /* Recover */
David Woodhouse0cd96eb2010-10-31 21:06:59 +0100540 while (inb_p(SMBHSTSTS(priv)) &
541 SMBHSTSTS_HOST_BUSY)
542 outb_p(SMBHSTSTS_BYTE_DONE,
543 SMBHSTSTS(priv));
544 outb_p(SMBHSTSTS_INTR, SMBHSTSTS(priv));
David Brownell97140342008-07-14 22:38:25 +0200545 return -EPROTO;
Jean Delvarecf898dc2008-07-14 22:38:33 +0200546 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700547 data->block[0] = len;
548 }
549
550 /* Retrieve/store value in SMBBLKDAT */
551 if (read_write == I2C_SMBUS_READ)
David Woodhouse0cd96eb2010-10-31 21:06:59 +0100552 data->block[i] = inb_p(SMBBLKDAT(priv));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700553 if (read_write == I2C_SMBUS_WRITE && i+1 <= len)
David Woodhouse0cd96eb2010-10-31 21:06:59 +0100554 outb_p(data->block[i+1], SMBBLKDAT(priv));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700555
Jean Delvarecf898dc2008-07-14 22:38:33 +0200556 /* signals SMBBLKDAT ready */
Jean Delvare6cad93c2012-07-24 14:13:58 +0200557 outb_p(SMBHSTSTS_BYTE_DONE, SMBHSTSTS(priv));
Oleg Ryjkov7edcb9a2007-07-12 14:12:31 +0200558 }
Jean Delvarecf898dc2008-07-14 22:38:33 +0200559
Jean Delvare6cad93c2012-07-24 14:13:58 +0200560 status = i801_wait_intr(priv);
561exit:
562 return i801_check_post(priv, status);
Oleg Ryjkov7edcb9a2007-07-12 14:12:31 +0200563}
564
David Woodhouse0cd96eb2010-10-31 21:06:59 +0100565static int i801_set_block_buffer_mode(struct i801_priv *priv)
Oleg Ryjkov7edcb9a2007-07-12 14:12:31 +0200566{
David Woodhouse0cd96eb2010-10-31 21:06:59 +0100567 outb_p(inb_p(SMBAUXCTL(priv)) | SMBAUXCTL_E32B, SMBAUXCTL(priv));
568 if ((inb_p(SMBAUXCTL(priv)) & SMBAUXCTL_E32B) == 0)
David Brownell97140342008-07-14 22:38:25 +0200569 return -EIO;
Oleg Ryjkov7edcb9a2007-07-12 14:12:31 +0200570 return 0;
571}
572
573/* Block transaction function */
David Woodhouse0cd96eb2010-10-31 21:06:59 +0100574static int i801_block_transaction(struct i801_priv *priv,
575 union i2c_smbus_data *data, char read_write,
Oleg Ryjkov7edcb9a2007-07-12 14:12:31 +0200576 int command, int hwpec)
577{
578 int result = 0;
579 unsigned char hostc;
580
581 if (command == I2C_SMBUS_I2C_BLOCK_DATA) {
582 if (read_write == I2C_SMBUS_WRITE) {
583 /* set I2C_EN bit in configuration register */
David Woodhouse0cd96eb2010-10-31 21:06:59 +0100584 pci_read_config_byte(priv->pci_dev, SMBHSTCFG, &hostc);
585 pci_write_config_byte(priv->pci_dev, SMBHSTCFG,
Oleg Ryjkov7edcb9a2007-07-12 14:12:31 +0200586 hostc | SMBHSTCFG_I2C_EN);
David Woodhouse0cd96eb2010-10-31 21:06:59 +0100587 } else if (!(priv->features & FEATURE_I2C_BLOCK_READ)) {
588 dev_err(&priv->pci_dev->dev,
Jean Delvare63420642008-01-27 18:14:50 +0100589 "I2C block read is unsupported!\n");
David Brownell97140342008-07-14 22:38:25 +0200590 return -EOPNOTSUPP;
Oleg Ryjkov7edcb9a2007-07-12 14:12:31 +0200591 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700592 }
593
Jean Delvare63420642008-01-27 18:14:50 +0100594 if (read_write == I2C_SMBUS_WRITE
595 || command == I2C_SMBUS_I2C_BLOCK_DATA) {
Oleg Ryjkov7edcb9a2007-07-12 14:12:31 +0200596 if (data->block[0] < 1)
597 data->block[0] = 1;
598 if (data->block[0] > I2C_SMBUS_BLOCK_MAX)
599 data->block[0] = I2C_SMBUS_BLOCK_MAX;
600 } else {
Jean Delvare63420642008-01-27 18:14:50 +0100601 data->block[0] = 32; /* max for SMBus block reads */
Oleg Ryjkov7edcb9a2007-07-12 14:12:31 +0200602 }
603
Jean Delvarec074c392010-03-13 20:56:53 +0100604 /* Experience has shown that the block buffer can only be used for
605 SMBus (not I2C) block transactions, even though the datasheet
606 doesn't mention this limitation. */
David Woodhouse0cd96eb2010-10-31 21:06:59 +0100607 if ((priv->features & FEATURE_BLOCK_BUFFER)
Jean Delvarec074c392010-03-13 20:56:53 +0100608 && command != I2C_SMBUS_I2C_BLOCK_DATA
David Woodhouse0cd96eb2010-10-31 21:06:59 +0100609 && i801_set_block_buffer_mode(priv) == 0)
610 result = i801_block_transaction_by_block(priv, data,
611 read_write, hwpec);
Oleg Ryjkov7edcb9a2007-07-12 14:12:31 +0200612 else
David Woodhouse0cd96eb2010-10-31 21:06:59 +0100613 result = i801_block_transaction_byte_by_byte(priv, data,
614 read_write,
Jean Delvare63420642008-01-27 18:14:50 +0100615 command, hwpec);
Oleg Ryjkov7edcb9a2007-07-12 14:12:31 +0200616
Jean Delvare63420642008-01-27 18:14:50 +0100617 if (command == I2C_SMBUS_I2C_BLOCK_DATA
618 && read_write == I2C_SMBUS_WRITE) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700619 /* restore saved configuration register value */
David Woodhouse0cd96eb2010-10-31 21:06:59 +0100620 pci_write_config_byte(priv->pci_dev, SMBHSTCFG, hostc);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700621 }
622 return result;
623}
624
David Brownell97140342008-07-14 22:38:25 +0200625/* Return negative errno on error. */
Ivo Manca3fb21c62010-05-21 18:40:55 +0200626static s32 i801_access(struct i2c_adapter *adap, u16 addr,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700627 unsigned short flags, char read_write, u8 command,
Ivo Manca3fb21c62010-05-21 18:40:55 +0200628 int size, union i2c_smbus_data *data)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700629{
Jean Delvaree8aac4a2005-10-26 21:34:42 +0200630 int hwpec;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700631 int block = 0;
632 int ret, xact = 0;
David Woodhouse0cd96eb2010-10-31 21:06:59 +0100633 struct i801_priv *priv = i2c_get_adapdata(adap);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700634
David Woodhouse0cd96eb2010-10-31 21:06:59 +0100635 hwpec = (priv->features & FEATURE_SMBUS_PEC) && (flags & I2C_CLIENT_PEC)
Jean Delvaree8aac4a2005-10-26 21:34:42 +0200636 && size != I2C_SMBUS_QUICK
637 && size != I2C_SMBUS_I2C_BLOCK_DATA;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700638
639 switch (size) {
640 case I2C_SMBUS_QUICK:
641 outb_p(((addr & 0x7f) << 1) | (read_write & 0x01),
David Woodhouse0cd96eb2010-10-31 21:06:59 +0100642 SMBHSTADD(priv));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700643 xact = I801_QUICK;
644 break;
645 case I2C_SMBUS_BYTE:
646 outb_p(((addr & 0x7f) << 1) | (read_write & 0x01),
David Woodhouse0cd96eb2010-10-31 21:06:59 +0100647 SMBHSTADD(priv));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700648 if (read_write == I2C_SMBUS_WRITE)
David Woodhouse0cd96eb2010-10-31 21:06:59 +0100649 outb_p(command, SMBHSTCMD(priv));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700650 xact = I801_BYTE;
651 break;
652 case I2C_SMBUS_BYTE_DATA:
653 outb_p(((addr & 0x7f) << 1) | (read_write & 0x01),
David Woodhouse0cd96eb2010-10-31 21:06:59 +0100654 SMBHSTADD(priv));
655 outb_p(command, SMBHSTCMD(priv));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700656 if (read_write == I2C_SMBUS_WRITE)
David Woodhouse0cd96eb2010-10-31 21:06:59 +0100657 outb_p(data->byte, SMBHSTDAT0(priv));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700658 xact = I801_BYTE_DATA;
659 break;
660 case I2C_SMBUS_WORD_DATA:
661 outb_p(((addr & 0x7f) << 1) | (read_write & 0x01),
David Woodhouse0cd96eb2010-10-31 21:06:59 +0100662 SMBHSTADD(priv));
663 outb_p(command, SMBHSTCMD(priv));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700664 if (read_write == I2C_SMBUS_WRITE) {
David Woodhouse0cd96eb2010-10-31 21:06:59 +0100665 outb_p(data->word & 0xff, SMBHSTDAT0(priv));
666 outb_p((data->word & 0xff00) >> 8, SMBHSTDAT1(priv));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700667 }
668 xact = I801_WORD_DATA;
669 break;
670 case I2C_SMBUS_BLOCK_DATA:
Linus Torvalds1da177e2005-04-16 15:20:36 -0700671 outb_p(((addr & 0x7f) << 1) | (read_write & 0x01),
David Woodhouse0cd96eb2010-10-31 21:06:59 +0100672 SMBHSTADD(priv));
673 outb_p(command, SMBHSTCMD(priv));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700674 block = 1;
675 break;
Jean Delvare63420642008-01-27 18:14:50 +0100676 case I2C_SMBUS_I2C_BLOCK_DATA:
677 /* NB: page 240 of ICH5 datasheet shows that the R/#W
678 * bit should be cleared here, even when reading */
David Woodhouse0cd96eb2010-10-31 21:06:59 +0100679 outb_p((addr & 0x7f) << 1, SMBHSTADD(priv));
Jean Delvare63420642008-01-27 18:14:50 +0100680 if (read_write == I2C_SMBUS_READ) {
681 /* NB: page 240 of ICH5 datasheet also shows
682 * that DATA1 is the cmd field when reading */
David Woodhouse0cd96eb2010-10-31 21:06:59 +0100683 outb_p(command, SMBHSTDAT1(priv));
Jean Delvare63420642008-01-27 18:14:50 +0100684 } else
David Woodhouse0cd96eb2010-10-31 21:06:59 +0100685 outb_p(command, SMBHSTCMD(priv));
Jean Delvare63420642008-01-27 18:14:50 +0100686 block = 1;
687 break;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700688 default:
David Woodhouse0cd96eb2010-10-31 21:06:59 +0100689 dev_err(&priv->pci_dev->dev, "Unsupported transaction %d\n",
690 size);
David Brownell97140342008-07-14 22:38:25 +0200691 return -EOPNOTSUPP;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700692 }
693
Oleg Ryjkovca8b9e32007-07-12 14:12:31 +0200694 if (hwpec) /* enable/disable hardware PEC */
David Woodhouse0cd96eb2010-10-31 21:06:59 +0100695 outb_p(inb_p(SMBAUXCTL(priv)) | SMBAUXCTL_CRC, SMBAUXCTL(priv));
Oleg Ryjkovca8b9e32007-07-12 14:12:31 +0200696 else
David Woodhouse0cd96eb2010-10-31 21:06:59 +0100697 outb_p(inb_p(SMBAUXCTL(priv)) & (~SMBAUXCTL_CRC),
698 SMBAUXCTL(priv));
Jean Delvaree8aac4a2005-10-26 21:34:42 +0200699
Ivo Manca3fb21c62010-05-21 18:40:55 +0200700 if (block)
David Woodhouse0cd96eb2010-10-31 21:06:59 +0100701 ret = i801_block_transaction(priv, data, read_write, size,
702 hwpec);
Oleg Ryjkov7edcb9a2007-07-12 14:12:31 +0200703 else
Daniel Kurtz37af8712012-07-24 14:13:58 +0200704 ret = i801_transaction(priv, xact);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700705
Jean Delvarec79cfba2006-04-20 02:43:18 -0700706 /* Some BIOSes don't like it when PEC is enabled at reboot or resume
Oleg Ryjkov7edcb9a2007-07-12 14:12:31 +0200707 time, so we forcibly disable it after every transaction. Turn off
708 E32B for the same reason. */
Jean Delvarea0921b62008-01-27 18:14:50 +0100709 if (hwpec || block)
David Woodhouse0cd96eb2010-10-31 21:06:59 +0100710 outb_p(inb_p(SMBAUXCTL(priv)) &
711 ~(SMBAUXCTL_CRC | SMBAUXCTL_E32B), SMBAUXCTL(priv));
Jean Delvarec79cfba2006-04-20 02:43:18 -0700712
Ivo Manca3fb21c62010-05-21 18:40:55 +0200713 if (block)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700714 return ret;
Ivo Manca3fb21c62010-05-21 18:40:55 +0200715 if (ret)
David Brownell97140342008-07-14 22:38:25 +0200716 return ret;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700717 if ((read_write == I2C_SMBUS_WRITE) || (xact == I801_QUICK))
718 return 0;
719
720 switch (xact & 0x7f) {
721 case I801_BYTE: /* Result put in SMBHSTDAT0 */
722 case I801_BYTE_DATA:
David Woodhouse0cd96eb2010-10-31 21:06:59 +0100723 data->byte = inb_p(SMBHSTDAT0(priv));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700724 break;
725 case I801_WORD_DATA:
David Woodhouse0cd96eb2010-10-31 21:06:59 +0100726 data->word = inb_p(SMBHSTDAT0(priv)) +
727 (inb_p(SMBHSTDAT1(priv)) << 8);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700728 break;
729 }
730 return 0;
731}
732
733
734static u32 i801_func(struct i2c_adapter *adapter)
735{
David Woodhouse0cd96eb2010-10-31 21:06:59 +0100736 struct i801_priv *priv = i2c_get_adapdata(adapter);
737
Linus Torvalds1da177e2005-04-16 15:20:36 -0700738 return I2C_FUNC_SMBUS_QUICK | I2C_FUNC_SMBUS_BYTE |
Jean Delvare369f6f42008-01-27 18:14:50 +0100739 I2C_FUNC_SMBUS_BYTE_DATA | I2C_FUNC_SMBUS_WORD_DATA |
740 I2C_FUNC_SMBUS_BLOCK_DATA | I2C_FUNC_SMBUS_WRITE_I2C_BLOCK |
David Woodhouse0cd96eb2010-10-31 21:06:59 +0100741 ((priv->features & FEATURE_SMBUS_PEC) ? I2C_FUNC_SMBUS_PEC : 0) |
742 ((priv->features & FEATURE_I2C_BLOCK_READ) ?
Jean Delvare63420642008-01-27 18:14:50 +0100743 I2C_FUNC_SMBUS_READ_I2C_BLOCK : 0);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700744}
745
Jean Delvare8f9082c2006-09-03 22:39:46 +0200746static const struct i2c_algorithm smbus_algorithm = {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700747 .smbus_xfer = i801_access,
748 .functionality = i801_func,
749};
750
Axel Lin3527bd52012-01-12 20:32:04 +0100751static DEFINE_PCI_DEVICE_TABLE(i801_ids) = {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700752 { PCI_DEVICE(PCI_VENDOR_ID_INTEL, PCI_DEVICE_ID_INTEL_82801AA_3) },
753 { PCI_DEVICE(PCI_VENDOR_ID_INTEL, PCI_DEVICE_ID_INTEL_82801AB_3) },
754 { PCI_DEVICE(PCI_VENDOR_ID_INTEL, PCI_DEVICE_ID_INTEL_82801BA_2) },
755 { PCI_DEVICE(PCI_VENDOR_ID_INTEL, PCI_DEVICE_ID_INTEL_82801CA_3) },
756 { PCI_DEVICE(PCI_VENDOR_ID_INTEL, PCI_DEVICE_ID_INTEL_82801DB_3) },
757 { PCI_DEVICE(PCI_VENDOR_ID_INTEL, PCI_DEVICE_ID_INTEL_82801EB_3) },
758 { PCI_DEVICE(PCI_VENDOR_ID_INTEL, PCI_DEVICE_ID_INTEL_ESB_4) },
759 { PCI_DEVICE(PCI_VENDOR_ID_INTEL, PCI_DEVICE_ID_INTEL_ICH6_16) },
760 { PCI_DEVICE(PCI_VENDOR_ID_INTEL, PCI_DEVICE_ID_INTEL_ICH7_17) },
Jason Gastonb0a70b52005-04-16 15:24:45 -0700761 { PCI_DEVICE(PCI_VENDOR_ID_INTEL, PCI_DEVICE_ID_INTEL_ESB2_17) },
Jason Gaston8254fc42006-01-09 10:58:08 -0800762 { PCI_DEVICE(PCI_VENDOR_ID_INTEL, PCI_DEVICE_ID_INTEL_ICH8_5) },
Jason Gastonadbc2a12006-11-22 15:19:12 -0800763 { PCI_DEVICE(PCI_VENDOR_ID_INTEL, PCI_DEVICE_ID_INTEL_ICH9_6) },
Seth Heasleycb04e952010-10-04 13:27:14 -0700764 { PCI_DEVICE(PCI_VENDOR_ID_INTEL, PCI_DEVICE_ID_INTEL_EP80579_1) },
Gaston, Jason Dd28dc712008-02-24 20:03:42 +0100765 { PCI_DEVICE(PCI_VENDOR_ID_INTEL, PCI_DEVICE_ID_INTEL_ICH10_4) },
766 { PCI_DEVICE(PCI_VENDOR_ID_INTEL, PCI_DEVICE_ID_INTEL_ICH10_5) },
Seth Heasleycb04e952010-10-04 13:27:14 -0700767 { PCI_DEVICE(PCI_VENDOR_ID_INTEL, PCI_DEVICE_ID_INTEL_5_3400_SERIES_SMBUS) },
768 { PCI_DEVICE(PCI_VENDOR_ID_INTEL, PCI_DEVICE_ID_INTEL_COUGARPOINT_SMBUS) },
Seth Heasleye30d9852010-10-31 21:06:59 +0100769 { PCI_DEVICE(PCI_VENDOR_ID_INTEL, PCI_DEVICE_ID_INTEL_PATSBURG_SMBUS) },
David Woodhouse55fee8d2010-10-31 21:07:00 +0100770 { PCI_DEVICE(PCI_VENDOR_ID_INTEL, PCI_DEVICE_ID_INTEL_PATSBURG_SMBUS_IDF0) },
771 { PCI_DEVICE(PCI_VENDOR_ID_INTEL, PCI_DEVICE_ID_INTEL_PATSBURG_SMBUS_IDF1) },
772 { PCI_DEVICE(PCI_VENDOR_ID_INTEL, PCI_DEVICE_ID_INTEL_PATSBURG_SMBUS_IDF2) },
Seth Heasley662cda82011-03-20 14:50:53 +0100773 { PCI_DEVICE(PCI_VENDOR_ID_INTEL, PCI_DEVICE_ID_INTEL_DH89XXCC_SMBUS) },
Seth Heasley6e2a8512011-05-24 20:58:49 +0200774 { PCI_DEVICE(PCI_VENDOR_ID_INTEL, PCI_DEVICE_ID_INTEL_PANTHERPOINT_SMBUS) },
Seth Heasley062737f2012-03-26 21:47:19 +0200775 { PCI_DEVICE(PCI_VENDOR_ID_INTEL, PCI_DEVICE_ID_INTEL_LYNXPOINT_SMBUS) },
James Ralston4a8f1dd2012-09-10 10:14:02 +0200776 { PCI_DEVICE(PCI_VENDOR_ID_INTEL, PCI_DEVICE_ID_INTEL_LYNXPOINT_LP_SMBUS) },
Linus Torvalds1da177e2005-04-16 15:20:36 -0700777 { 0, }
778};
779
Ivo Manca3fb21c62010-05-21 18:40:55 +0200780MODULE_DEVICE_TABLE(pci, i801_ids);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700781
Jean Delvare8eacfce2011-05-24 20:58:49 +0200782#if defined CONFIG_X86 && defined CONFIG_DMI
Jean Delvare1561bfe2009-01-07 14:29:17 +0100783static unsigned char apanel_addr;
784
785/* Scan the system ROM for the signature "FJKEYINF" */
786static __init const void __iomem *bios_signature(const void __iomem *bios)
787{
788 ssize_t offset;
789 const unsigned char signature[] = "FJKEYINF";
790
791 for (offset = 0; offset < 0x10000; offset += 0x10) {
792 if (check_signature(bios + offset, signature,
793 sizeof(signature)-1))
794 return bios + offset;
795 }
796 return NULL;
797}
798
799static void __init input_apanel_init(void)
800{
801 void __iomem *bios;
802 const void __iomem *p;
803
804 bios = ioremap(0xF0000, 0x10000); /* Can't fail */
805 p = bios_signature(bios);
806 if (p) {
807 /* just use the first address */
808 apanel_addr = readb(p + 8 + 3) >> 1;
809 }
810 iounmap(bios);
811}
Jean Delvare1561bfe2009-01-07 14:29:17 +0100812
Hans de Goedefa5bfab2009-03-30 21:46:44 +0200813struct dmi_onboard_device_info {
814 const char *name;
815 u8 type;
816 unsigned short i2c_addr;
817 const char *i2c_type;
818};
819
820static struct dmi_onboard_device_info __devinitdata dmi_devices[] = {
821 { "Syleus", DMI_DEV_TYPE_OTHER, 0x73, "fscsyl" },
822 { "Hermes", DMI_DEV_TYPE_OTHER, 0x73, "fscher" },
823 { "Hades", DMI_DEV_TYPE_OTHER, 0x73, "fschds" },
824};
825
826static void __devinit dmi_check_onboard_device(u8 type, const char *name,
827 struct i2c_adapter *adap)
828{
829 int i;
830 struct i2c_board_info info;
831
832 for (i = 0; i < ARRAY_SIZE(dmi_devices); i++) {
833 /* & ~0x80, ignore enabled/disabled bit */
834 if ((type & ~0x80) != dmi_devices[i].type)
835 continue;
Jean Delvarefaabd472010-07-09 16:22:51 +0200836 if (strcasecmp(name, dmi_devices[i].name))
Hans de Goedefa5bfab2009-03-30 21:46:44 +0200837 continue;
838
839 memset(&info, 0, sizeof(struct i2c_board_info));
840 info.addr = dmi_devices[i].i2c_addr;
841 strlcpy(info.type, dmi_devices[i].i2c_type, I2C_NAME_SIZE);
842 i2c_new_device(adap, &info);
843 break;
844 }
845}
846
847/* We use our own function to check for onboard devices instead of
848 dmi_find_device() as some buggy BIOS's have the devices we are interested
849 in marked as disabled */
850static void __devinit dmi_check_onboard_devices(const struct dmi_header *dm,
851 void *adap)
852{
853 int i, count;
854
855 if (dm->type != 10)
856 return;
857
858 count = (dm->length - sizeof(struct dmi_header)) / 2;
859 for (i = 0; i < count; i++) {
860 const u8 *d = (char *)(dm + 1) + (i * 2);
861 const char *name = ((char *) dm) + dm->length;
862 u8 type = d[0];
863 u8 s = d[1];
864
865 if (!s)
866 continue;
867 s--;
868 while (s > 0 && name[0]) {
869 name += strlen(name) + 1;
870 s--;
871 }
872 if (name[0] == 0) /* Bogus string reference */
873 continue;
874
875 dmi_check_onboard_device(type, name, adap);
876 }
877}
Hans de Goedefa5bfab2009-03-30 21:46:44 +0200878
Jean Delvaree7198fb2011-05-24 20:58:49 +0200879/* Register optional slaves */
880static void __devinit i801_probe_optional_slaves(struct i801_priv *priv)
881{
882 /* Only register slaves on main SMBus channel */
883 if (priv->features & FEATURE_IDF)
884 return;
885
Jean Delvaree7198fb2011-05-24 20:58:49 +0200886 if (apanel_addr) {
887 struct i2c_board_info info;
888
889 memset(&info, 0, sizeof(struct i2c_board_info));
890 info.addr = apanel_addr;
891 strlcpy(info.type, "fujitsu_apanel", I2C_NAME_SIZE);
892 i2c_new_device(&priv->adapter, &info);
893 }
Jean Delvare8eacfce2011-05-24 20:58:49 +0200894
Jean Delvaree7198fb2011-05-24 20:58:49 +0200895 if (dmi_name_in_vendors("FUJITSU"))
896 dmi_walk(dmi_check_onboard_devices, &priv->adapter);
Jean Delvaree7198fb2011-05-24 20:58:49 +0200897}
Jean Delvare8eacfce2011-05-24 20:58:49 +0200898#else
899static void __init input_apanel_init(void) {}
900static void __devinit i801_probe_optional_slaves(struct i801_priv *priv) {}
901#endif /* CONFIG_X86 && CONFIG_DMI */
Jean Delvaree7198fb2011-05-24 20:58:49 +0200902
Ivo Manca3fb21c62010-05-21 18:40:55 +0200903static int __devinit i801_probe(struct pci_dev *dev,
904 const struct pci_device_id *id)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700905{
Jean Delvare02dd7ae2006-06-12 21:53:41 +0200906 unsigned char temp;
Jean Delvareadff6872010-05-21 18:40:54 +0200907 int err, i;
David Woodhouse0cd96eb2010-10-31 21:06:59 +0100908 struct i801_priv *priv;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700909
David Woodhouse0cd96eb2010-10-31 21:06:59 +0100910 priv = kzalloc(sizeof(*priv), GFP_KERNEL);
911 if (!priv)
912 return -ENOMEM;
913
914 i2c_set_adapdata(&priv->adapter, priv);
915 priv->adapter.owner = THIS_MODULE;
916 priv->adapter.class = I2C_CLASS_HWMON | I2C_CLASS_SPD;
917 priv->adapter.algo = &smbus_algorithm;
918
919 priv->pci_dev = dev;
Jean Delvare250d1bd2006-12-10 21:21:33 +0100920 switch (dev->device) {
Jean Delvaree7198fb2011-05-24 20:58:49 +0200921 case PCI_DEVICE_ID_INTEL_PATSBURG_SMBUS_IDF0:
922 case PCI_DEVICE_ID_INTEL_PATSBURG_SMBUS_IDF1:
923 case PCI_DEVICE_ID_INTEL_PATSBURG_SMBUS_IDF2:
924 priv->features |= FEATURE_IDF;
925 /* fall through */
Jean Delvaree0e8398c2010-05-21 18:40:55 +0200926 default:
David Woodhouse0cd96eb2010-10-31 21:06:59 +0100927 priv->features |= FEATURE_I2C_BLOCK_READ;
Jean Delvare63420642008-01-27 18:14:50 +0100928 /* fall through */
929 case PCI_DEVICE_ID_INTEL_82801DB_3:
David Woodhouse0cd96eb2010-10-31 21:06:59 +0100930 priv->features |= FEATURE_SMBUS_PEC;
931 priv->features |= FEATURE_BLOCK_BUFFER;
Jean Delvaree0e8398c2010-05-21 18:40:55 +0200932 /* fall through */
933 case PCI_DEVICE_ID_INTEL_82801CA_3:
934 case PCI_DEVICE_ID_INTEL_82801BA_2:
935 case PCI_DEVICE_ID_INTEL_82801AB_3:
936 case PCI_DEVICE_ID_INTEL_82801AA_3:
Jean Delvare250d1bd2006-12-10 21:21:33 +0100937 break;
Jean Delvare250d1bd2006-12-10 21:21:33 +0100938 }
Jean Delvare02dd7ae2006-06-12 21:53:41 +0200939
Jean Delvare29b60852012-07-24 14:13:59 +0200940 /* IRQ processing tested on CougarPoint PCH, ICH5, ICH7-M and ICH10 */
941 if (dev->device == PCI_DEVICE_ID_INTEL_COUGARPOINT_SMBUS ||
942 dev->device == PCI_DEVICE_ID_INTEL_82801EB_3 ||
943 dev->device == PCI_DEVICE_ID_INTEL_ICH7_17 ||
944 dev->device == PCI_DEVICE_ID_INTEL_ICH8_5 ||
945 dev->device == PCI_DEVICE_ID_INTEL_ICH9_6 ||
946 dev->device == PCI_DEVICE_ID_INTEL_ICH10_4 ||
947 dev->device == PCI_DEVICE_ID_INTEL_ICH10_5)
Daniel Kurtz636752b2012-07-24 14:13:58 +0200948 priv->features |= FEATURE_IRQ;
949
Jean Delvareadff6872010-05-21 18:40:54 +0200950 /* Disable features on user request */
951 for (i = 0; i < ARRAY_SIZE(i801_feature_names); i++) {
David Woodhouse0cd96eb2010-10-31 21:06:59 +0100952 if (priv->features & disable_features & (1 << i))
Jean Delvareadff6872010-05-21 18:40:54 +0200953 dev_notice(&dev->dev, "%s disabled by user\n",
954 i801_feature_names[i]);
955 }
David Woodhouse0cd96eb2010-10-31 21:06:59 +0100956 priv->features &= ~disable_features;
Jean Delvareadff6872010-05-21 18:40:54 +0200957
Jean Delvare02dd7ae2006-06-12 21:53:41 +0200958 err = pci_enable_device(dev);
959 if (err) {
960 dev_err(&dev->dev, "Failed to enable SMBus PCI device (%d)\n",
961 err);
962 goto exit;
963 }
964
965 /* Determine the address of the SMBus area */
David Woodhouse0cd96eb2010-10-31 21:06:59 +0100966 priv->smba = pci_resource_start(dev, SMBBAR);
967 if (!priv->smba) {
Jean Delvare02dd7ae2006-06-12 21:53:41 +0200968 dev_err(&dev->dev, "SMBus base address uninitialized, "
969 "upgrade BIOS\n");
970 err = -ENODEV;
Daniel Ritzd6fcb3b2006-06-27 18:40:54 +0200971 goto exit;
Jean Delvare02dd7ae2006-06-12 21:53:41 +0200972 }
973
Jean Delvare54fb4a052008-07-14 22:38:33 +0200974 err = acpi_check_resource_conflict(&dev->resource[SMBBAR]);
Jean Delvare18669ea2009-10-04 22:53:45 +0200975 if (err) {
976 err = -ENODEV;
Jean Delvare54fb4a052008-07-14 22:38:33 +0200977 goto exit;
Jean Delvare18669ea2009-10-04 22:53:45 +0200978 }
Jean Delvare54fb4a052008-07-14 22:38:33 +0200979
Jean Delvare02dd7ae2006-06-12 21:53:41 +0200980 err = pci_request_region(dev, SMBBAR, i801_driver.name);
981 if (err) {
982 dev_err(&dev->dev, "Failed to request SMBus region "
David Woodhouse0cd96eb2010-10-31 21:06:59 +0100983 "0x%lx-0x%Lx\n", priv->smba,
Andrew Morton598736c2006-06-30 01:56:20 -0700984 (unsigned long long)pci_resource_end(dev, SMBBAR));
Daniel Ritzd6fcb3b2006-06-27 18:40:54 +0200985 goto exit;
Jean Delvare02dd7ae2006-06-12 21:53:41 +0200986 }
987
David Woodhouse0cd96eb2010-10-31 21:06:59 +0100988 pci_read_config_byte(priv->pci_dev, SMBHSTCFG, &temp);
989 priv->original_hstcfg = temp;
Jean Delvare02dd7ae2006-06-12 21:53:41 +0200990 temp &= ~SMBHSTCFG_I2C_EN; /* SMBus timing */
991 if (!(temp & SMBHSTCFG_HST_EN)) {
992 dev_info(&dev->dev, "Enabling SMBus device\n");
993 temp |= SMBHSTCFG_HST_EN;
994 }
David Woodhouse0cd96eb2010-10-31 21:06:59 +0100995 pci_write_config_byte(priv->pci_dev, SMBHSTCFG, temp);
Jean Delvare02dd7ae2006-06-12 21:53:41 +0200996
Daniel Kurtz636752b2012-07-24 14:13:58 +0200997 if (temp & SMBHSTCFG_SMB_SMI_EN) {
Jean Delvare02dd7ae2006-06-12 21:53:41 +0200998 dev_dbg(&dev->dev, "SMBus using interrupt SMI#\n");
Daniel Kurtz636752b2012-07-24 14:13:58 +0200999 /* Disable SMBus interrupt feature if SMBus using SMI# */
1000 priv->features &= ~FEATURE_IRQ;
Daniel Kurtz636752b2012-07-24 14:13:58 +02001001 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07001002
Jean Delvarea0921b62008-01-27 18:14:50 +01001003 /* Clear special mode bits */
David Woodhouse0cd96eb2010-10-31 21:06:59 +01001004 if (priv->features & (FEATURE_SMBUS_PEC | FEATURE_BLOCK_BUFFER))
1005 outb_p(inb_p(SMBAUXCTL(priv)) &
1006 ~(SMBAUXCTL_CRC | SMBAUXCTL_E32B), SMBAUXCTL(priv));
Jean Delvarea0921b62008-01-27 18:14:50 +01001007
Daniel Kurtz636752b2012-07-24 14:13:58 +02001008 if (priv->features & FEATURE_IRQ) {
1009 init_waitqueue_head(&priv->waitq);
1010
1011 err = request_irq(dev->irq, i801_isr, IRQF_SHARED,
1012 i801_driver.name, priv);
1013 if (err) {
1014 dev_err(&dev->dev, "Failed to allocate irq %d: %d\n",
1015 dev->irq, err);
1016 goto exit_release;
1017 }
Jean Delvare29b60852012-07-24 14:13:59 +02001018 dev_info(&dev->dev, "SMBus using PCI Interrupt\n");
Daniel Kurtz636752b2012-07-24 14:13:58 +02001019 }
1020
Robert P. J. Day405ae7d2007-02-17 19:13:42 +01001021 /* set up the sysfs linkage to our parent device */
David Woodhouse0cd96eb2010-10-31 21:06:59 +01001022 priv->adapter.dev.parent = &dev->dev;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001023
Jean Delvare7e2193a8f2009-12-06 17:06:27 +01001024 /* Retry up to 3 times on lost arbitration */
David Woodhouse0cd96eb2010-10-31 21:06:59 +01001025 priv->adapter.retries = 3;
Jean Delvare7e2193a8f2009-12-06 17:06:27 +01001026
David Woodhouse0cd96eb2010-10-31 21:06:59 +01001027 snprintf(priv->adapter.name, sizeof(priv->adapter.name),
1028 "SMBus I801 adapter at %04lx", priv->smba);
1029 err = i2c_add_adapter(&priv->adapter);
Jean Delvare02dd7ae2006-06-12 21:53:41 +02001030 if (err) {
1031 dev_err(&dev->dev, "Failed to add SMBus adapter\n");
Daniel Kurtz636752b2012-07-24 14:13:58 +02001032 goto exit_free_irq;
Jean Delvare02dd7ae2006-06-12 21:53:41 +02001033 }
Jean Delvare1561bfe2009-01-07 14:29:17 +01001034
Jean Delvaree7198fb2011-05-24 20:58:49 +02001035 i801_probe_optional_slaves(priv);
Jean Delvare1561bfe2009-01-07 14:29:17 +01001036
David Woodhouse0cd96eb2010-10-31 21:06:59 +01001037 pci_set_drvdata(dev, priv);
Daniel Kurtz636752b2012-07-24 14:13:58 +02001038
Daniel Ritzd6fcb3b2006-06-27 18:40:54 +02001039 return 0;
Jean Delvare02dd7ae2006-06-12 21:53:41 +02001040
Daniel Kurtz636752b2012-07-24 14:13:58 +02001041exit_free_irq:
1042 if (priv->features & FEATURE_IRQ)
1043 free_irq(dev->irq, priv);
Daniel Ritzd6fcb3b2006-06-27 18:40:54 +02001044exit_release:
1045 pci_release_region(dev, SMBBAR);
Jean Delvare02dd7ae2006-06-12 21:53:41 +02001046exit:
David Woodhouse0cd96eb2010-10-31 21:06:59 +01001047 kfree(priv);
Jean Delvare02dd7ae2006-06-12 21:53:41 +02001048 return err;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001049}
1050
1051static void __devexit i801_remove(struct pci_dev *dev)
1052{
David Woodhouse0cd96eb2010-10-31 21:06:59 +01001053 struct i801_priv *priv = pci_get_drvdata(dev);
1054
1055 i2c_del_adapter(&priv->adapter);
1056 pci_write_config_byte(dev, SMBHSTCFG, priv->original_hstcfg);
Daniel Kurtz636752b2012-07-24 14:13:58 +02001057
1058 if (priv->features & FEATURE_IRQ)
1059 free_irq(dev->irq, priv);
Jean Delvare6dcc19d2006-06-12 21:53:02 +02001060 pci_release_region(dev, SMBBAR);
Daniel Kurtz636752b2012-07-24 14:13:58 +02001061
David Woodhouse0cd96eb2010-10-31 21:06:59 +01001062 pci_set_drvdata(dev, NULL);
1063 kfree(priv);
Daniel Ritzd6fcb3b2006-06-27 18:40:54 +02001064 /*
1065 * do not call pci_disable_device(dev) since it can cause hard hangs on
1066 * some systems during power-off (eg. Fujitsu-Siemens Lifebook E8010)
1067 */
Linus Torvalds1da177e2005-04-16 15:20:36 -07001068}
1069
Jean Delvarea5aaea32007-03-22 19:49:01 +01001070#ifdef CONFIG_PM
1071static int i801_suspend(struct pci_dev *dev, pm_message_t mesg)
1072{
David Woodhouse0cd96eb2010-10-31 21:06:59 +01001073 struct i801_priv *priv = pci_get_drvdata(dev);
1074
Jean Delvarea5aaea32007-03-22 19:49:01 +01001075 pci_save_state(dev);
David Woodhouse0cd96eb2010-10-31 21:06:59 +01001076 pci_write_config_byte(dev, SMBHSTCFG, priv->original_hstcfg);
Jean Delvarea5aaea32007-03-22 19:49:01 +01001077 pci_set_power_state(dev, pci_choose_state(dev, mesg));
1078 return 0;
1079}
1080
1081static int i801_resume(struct pci_dev *dev)
1082{
1083 pci_set_power_state(dev, PCI_D0);
1084 pci_restore_state(dev);
1085 return pci_enable_device(dev);
1086}
1087#else
1088#define i801_suspend NULL
1089#define i801_resume NULL
1090#endif
1091
Linus Torvalds1da177e2005-04-16 15:20:36 -07001092static struct pci_driver i801_driver = {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001093 .name = "i801_smbus",
1094 .id_table = i801_ids,
1095 .probe = i801_probe,
1096 .remove = __devexit_p(i801_remove),
Jean Delvarea5aaea32007-03-22 19:49:01 +01001097 .suspend = i801_suspend,
1098 .resume = i801_resume,
Linus Torvalds1da177e2005-04-16 15:20:36 -07001099};
1100
1101static int __init i2c_i801_init(void)
1102{
Jean Delvare6aa14642011-05-24 20:58:49 +02001103 if (dmi_name_in_vendors("FUJITSU"))
1104 input_apanel_init();
Linus Torvalds1da177e2005-04-16 15:20:36 -07001105 return pci_register_driver(&i801_driver);
1106}
1107
1108static void __exit i2c_i801_exit(void)
1109{
1110 pci_unregister_driver(&i801_driver);
1111}
1112
Jean Delvare63420642008-01-27 18:14:50 +01001113MODULE_AUTHOR("Mark D. Studebaker <mdsxyz123@yahoo.com>, "
1114 "Jean Delvare <khali@linux-fr.org>");
Linus Torvalds1da177e2005-04-16 15:20:36 -07001115MODULE_DESCRIPTION("I801 SMBus driver");
1116MODULE_LICENSE("GPL");
1117
1118module_init(i2c_i801_init);
1119module_exit(i2c_i801_exit);