blob: c306751ceadb44c24757b02281de24779038b1cb [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 Delvareb3b8df92014-11-12 10:20:40 +01005 Copyright (C) 2007 - 2014 Jean Delvare <jdelvare@suse.de>
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.
Linus Torvalds1da177e2005-04-16 15:20:36 -070018*/
19
20/*
Jean Delvarece316112014-07-17 15:03:24 +020021 * Supports the following Intel I/O Controller Hubs (ICH):
22 *
23 * I/O Block I2C
24 * region SMBus Block proc. block
25 * Chip name PCI ID size PEC buffer call read
26 * ---------------------------------------------------------------------------
27 * 82801AA (ICH) 0x2413 16 no no no no
28 * 82801AB (ICH0) 0x2423 16 no no no no
29 * 82801BA (ICH2) 0x2443 16 no no no no
30 * 82801CA (ICH3) 0x2483 32 soft no no no
31 * 82801DB (ICH4) 0x24c3 32 hard yes no no
32 * 82801E (ICH5) 0x24d3 32 hard yes yes yes
33 * 6300ESB 0x25a4 32 hard yes yes yes
34 * 82801F (ICH6) 0x266a 32 hard yes yes yes
35 * 6310ESB/6320ESB 0x269b 32 hard yes yes yes
36 * 82801G (ICH7) 0x27da 32 hard yes yes yes
37 * 82801H (ICH8) 0x283e 32 hard yes yes yes
38 * 82801I (ICH9) 0x2930 32 hard yes yes yes
39 * EP80579 (Tolapai) 0x5032 32 hard yes yes yes
40 * ICH10 0x3a30 32 hard yes yes yes
41 * ICH10 0x3a60 32 hard yes yes yes
42 * 5/3400 Series (PCH) 0x3b30 32 hard yes yes yes
43 * 6 Series (PCH) 0x1c22 32 hard yes yes yes
44 * Patsburg (PCH) 0x1d22 32 hard yes yes yes
45 * Patsburg (PCH) IDF 0x1d70 32 hard yes yes yes
46 * Patsburg (PCH) IDF 0x1d71 32 hard yes yes yes
47 * Patsburg (PCH) IDF 0x1d72 32 hard yes yes yes
48 * DH89xxCC (PCH) 0x2330 32 hard yes yes yes
49 * Panther Point (PCH) 0x1e22 32 hard yes yes yes
50 * Lynx Point (PCH) 0x8c22 32 hard yes yes yes
51 * Lynx Point-LP (PCH) 0x9c22 32 hard yes yes yes
52 * Avoton (SOC) 0x1f3c 32 hard yes yes yes
53 * Wellsburg (PCH) 0x8d22 32 hard yes yes yes
54 * Wellsburg (PCH) MS 0x8d7d 32 hard yes yes yes
55 * Wellsburg (PCH) MS 0x8d7e 32 hard yes yes yes
56 * Wellsburg (PCH) MS 0x8d7f 32 hard yes yes yes
57 * Coleto Creek (PCH) 0x23b0 32 hard yes yes yes
Jean Delvareb299de82014-07-17 15:04:41 +020058 * Wildcat Point (PCH) 0x8ca2 32 hard yes yes yes
Jean Delvarece316112014-07-17 15:03:24 +020059 * Wildcat Point-LP (PCH) 0x9ca2 32 hard yes yes yes
60 * BayTrail (SOC) 0x0f12 32 hard yes yes yes
james.d.ralston@intel.com3e27a842014-10-13 15:20:24 -070061 * Sunrise Point-H (PCH) 0xa123 32 hard yes yes yes
Devin Ryles3eee17992014-11-05 16:30:03 -050062 * Sunrise Point-LP (PCH) 0x9d23 32 hard yes yes yes
Mika Westerberg84d7f2e2015-10-13 15:41:39 +030063 * DNV (SOC) 0x19df 32 hard yes yes yes
Jarkko Nikuladd77f422015-10-22 17:16:58 +030064 * Broxton (SOC) 0x5ad4 32 hard yes yes yes
Jean Delvarece316112014-07-17 15:03:24 +020065 *
66 * Features supported by this driver:
67 * Software PEC no
68 * Hardware PEC yes
69 * Block buffer yes
70 * Block process call transaction no
71 * I2C block read transaction yes (doesn't use the block buffer)
72 * Slave mode no
73 * Interrupt processing yes
74 *
75 * See the file Documentation/i2c/busses/i2c-i801 for details.
76 */
Linus Torvalds1da177e2005-04-16 15:20:36 -070077
Daniel Kurtz636752b2012-07-24 14:13:58 +020078#include <linux/interrupt.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070079#include <linux/module.h>
80#include <linux/pci.h>
81#include <linux/kernel.h>
82#include <linux/stddef.h>
83#include <linux/delay.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070084#include <linux/ioport.h>
85#include <linux/init.h>
86#include <linux/i2c.h>
Jean Delvare54fb4a052008-07-14 22:38:33 +020087#include <linux/acpi.h>
Jean Delvare1561bfe2009-01-07 14:29:17 +010088#include <linux/io.h>
Hans de Goedefa5bfab2009-03-30 21:46:44 +020089#include <linux/dmi.h>
Ben Hutchings665a96b2011-01-10 22:11:22 +010090#include <linux/slab.h>
Daniel Kurtz636752b2012-07-24 14:13:58 +020091#include <linux/wait.h>
Jean Delvare3ad7ea12012-10-05 22:23:53 +020092#include <linux/err.h>
Mika Westerberg94246932015-08-06 13:46:25 +010093#include <linux/platform_device.h>
94#include <linux/platform_data/itco_wdt.h>
Jean Delvare3ad7ea12012-10-05 22:23:53 +020095
Jean Delvare79e3e5b2012-10-28 21:37:01 +010096#if (defined CONFIG_I2C_MUX_GPIO || defined CONFIG_I2C_MUX_GPIO_MODULE) && \
97 defined CONFIG_DMI
Jean Delvare3ad7ea12012-10-05 22:23:53 +020098#include <linux/gpio.h>
99#include <linux/i2c-mux-gpio.h>
Jean Delvare3ad7ea12012-10-05 22:23:53 +0200100#endif
Linus Torvalds1da177e2005-04-16 15:20:36 -0700101
Linus Torvalds1da177e2005-04-16 15:20:36 -0700102/* I801 SMBus address offsets */
David Woodhouse0cd96eb2010-10-31 21:06:59 +0100103#define SMBHSTSTS(p) (0 + (p)->smba)
104#define SMBHSTCNT(p) (2 + (p)->smba)
105#define SMBHSTCMD(p) (3 + (p)->smba)
106#define SMBHSTADD(p) (4 + (p)->smba)
107#define SMBHSTDAT0(p) (5 + (p)->smba)
108#define SMBHSTDAT1(p) (6 + (p)->smba)
109#define SMBBLKDAT(p) (7 + (p)->smba)
110#define SMBPEC(p) (8 + (p)->smba) /* ICH3 and later */
111#define SMBAUXSTS(p) (12 + (p)->smba) /* ICH4 and later */
112#define SMBAUXCTL(p) (13 + (p)->smba) /* ICH4 and later */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700113
114/* PCI Address Constants */
Jean Delvare6dcc19d2006-06-12 21:53:02 +0200115#define SMBBAR 4
Jean Delvareaeb8a3d2014-11-12 10:25:37 +0100116#define SMBPCICTL 0x004
Daniel Kurtz636752b2012-07-24 14:13:58 +0200117#define SMBPCISTS 0x006
Linus Torvalds1da177e2005-04-16 15:20:36 -0700118#define SMBHSTCFG 0x040
Mika Westerberg94246932015-08-06 13:46:25 +0100119#define TCOBASE 0x050
120#define TCOCTL 0x054
121
122#define ACPIBASE 0x040
123#define ACPIBASE_SMI_OFF 0x030
124#define ACPICTRL 0x044
125#define ACPICTRL_EN 0x080
126
127#define SBREG_BAR 0x10
128#define SBREG_SMBCTRL 0xc6000c
Linus Torvalds1da177e2005-04-16 15:20:36 -0700129
Daniel Kurtz636752b2012-07-24 14:13:58 +0200130/* Host status bits for SMBPCISTS */
131#define SMBPCISTS_INTS 0x08
132
Jean Delvareaeb8a3d2014-11-12 10:25:37 +0100133/* Control bits for SMBPCICTL */
134#define SMBPCICTL_INTDIS 0x0400
135
Linus Torvalds1da177e2005-04-16 15:20:36 -0700136/* Host configuration bits for SMBHSTCFG */
137#define SMBHSTCFG_HST_EN 1
138#define SMBHSTCFG_SMB_SMI_EN 2
139#define SMBHSTCFG_I2C_EN 4
140
Mika Westerberg94246932015-08-06 13:46:25 +0100141/* TCO configuration bits for TCOCTL */
142#define TCOCTL_EN 0x0100
143
Lucas De Marchi25985ed2011-03-30 22:57:33 -0300144/* Auxiliary control register bits, ICH4+ only */
Oleg Ryjkovca8b9e32007-07-12 14:12:31 +0200145#define SMBAUXCTL_CRC 1
146#define SMBAUXCTL_E32B 2
147
Linus Torvalds1da177e2005-04-16 15:20:36 -0700148/* Other settings */
Jean Delvare84c1af42012-03-26 21:47:19 +0200149#define MAX_RETRIES 400
Linus Torvalds1da177e2005-04-16 15:20:36 -0700150
151/* I801 command constants */
152#define I801_QUICK 0x00
153#define I801_BYTE 0x04
154#define I801_BYTE_DATA 0x08
155#define I801_WORD_DATA 0x0C
Jean Delvareae7b0492008-01-27 18:14:49 +0100156#define I801_PROC_CALL 0x10 /* unimplemented */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700157#define I801_BLOCK_DATA 0x14
Jean Delvare63420642008-01-27 18:14:50 +0100158#define I801_I2C_BLOCK_DATA 0x18 /* ICH5 and later */
Daniel Kurtzedbeea62012-07-24 14:13:58 +0200159
160/* I801 Host Control register bits */
161#define SMBHSTCNT_INTREN 0x01
162#define SMBHSTCNT_KILL 0x02
163#define SMBHSTCNT_LAST_BYTE 0x20
164#define SMBHSTCNT_START 0x40
165#define SMBHSTCNT_PEC_EN 0x80 /* ICH3 and later */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700166
Oleg Ryjkovca8b9e32007-07-12 14:12:31 +0200167/* I801 Hosts Status register bits */
168#define SMBHSTSTS_BYTE_DONE 0x80
169#define SMBHSTSTS_INUSE_STS 0x40
170#define SMBHSTSTS_SMBALERT_STS 0x20
171#define SMBHSTSTS_FAILED 0x10
172#define SMBHSTSTS_BUS_ERR 0x08
173#define SMBHSTSTS_DEV_ERR 0x04
174#define SMBHSTSTS_INTR 0x02
175#define SMBHSTSTS_HOST_BUSY 0x01
Linus Torvalds1da177e2005-04-16 15:20:36 -0700176
Daniel Kurtz70a1cc12012-07-24 14:13:58 +0200177#define STATUS_ERROR_FLAGS (SMBHSTSTS_FAILED | SMBHSTSTS_BUS_ERR | \
178 SMBHSTSTS_DEV_ERR)
179
180#define STATUS_FLAGS (SMBHSTSTS_BYTE_DONE | SMBHSTSTS_INTR | \
181 STATUS_ERROR_FLAGS)
Jean Delvarecf898dc2008-07-14 22:38:33 +0200182
Jean Delvarea6e5e2b2011-05-01 18:18:49 +0200183/* Older devices have their ID defined in <linux/pci_ids.h> */
Jean Delvarece316112014-07-17 15:03:24 +0200184#define PCI_DEVICE_ID_INTEL_BAYTRAIL_SMBUS 0x0f12
Alan Cox39e8e302014-08-19 17:37:28 +0300185#define PCI_DEVICE_ID_INTEL_BRASWELL_SMBUS 0x2292
Jean Delvarece316112014-07-17 15:03:24 +0200186#define PCI_DEVICE_ID_INTEL_COUGARPOINT_SMBUS 0x1c22
187#define PCI_DEVICE_ID_INTEL_PATSBURG_SMBUS 0x1d22
David Woodhouse55fee8d2010-10-31 21:07:00 +0100188/* Patsburg also has three 'Integrated Device Function' SMBus controllers */
Jean Delvarece316112014-07-17 15:03:24 +0200189#define PCI_DEVICE_ID_INTEL_PATSBURG_SMBUS_IDF0 0x1d70
190#define PCI_DEVICE_ID_INTEL_PATSBURG_SMBUS_IDF1 0x1d71
191#define PCI_DEVICE_ID_INTEL_PATSBURG_SMBUS_IDF2 0x1d72
192#define PCI_DEVICE_ID_INTEL_PANTHERPOINT_SMBUS 0x1e22
193#define PCI_DEVICE_ID_INTEL_AVOTON_SMBUS 0x1f3c
194#define PCI_DEVICE_ID_INTEL_DH89XXCC_SMBUS 0x2330
195#define PCI_DEVICE_ID_INTEL_COLETOCREEK_SMBUS 0x23b0
196#define PCI_DEVICE_ID_INTEL_5_3400_SERIES_SMBUS 0x3b30
197#define PCI_DEVICE_ID_INTEL_LYNXPOINT_SMBUS 0x8c22
Jean Delvareb299de82014-07-17 15:04:41 +0200198#define PCI_DEVICE_ID_INTEL_WILDCATPOINT_SMBUS 0x8ca2
Jean Delvarece316112014-07-17 15:03:24 +0200199#define PCI_DEVICE_ID_INTEL_WELLSBURG_SMBUS 0x8d22
200#define PCI_DEVICE_ID_INTEL_WELLSBURG_SMBUS_MS0 0x8d7d
201#define PCI_DEVICE_ID_INTEL_WELLSBURG_SMBUS_MS1 0x8d7e
202#define PCI_DEVICE_ID_INTEL_WELLSBURG_SMBUS_MS2 0x8d7f
203#define PCI_DEVICE_ID_INTEL_LYNXPOINT_LP_SMBUS 0x9c22
James Ralstonafc65922013-11-04 09:29:48 -0800204#define PCI_DEVICE_ID_INTEL_WILDCATPOINT_LP_SMBUS 0x9ca2
james.d.ralston@intel.com3e27a842014-10-13 15:20:24 -0700205#define PCI_DEVICE_ID_INTEL_SUNRISEPOINT_H_SMBUS 0xa123
Devin Ryles3eee17992014-11-05 16:30:03 -0500206#define PCI_DEVICE_ID_INTEL_SUNRISEPOINT_LP_SMBUS 0x9d23
Mika Westerberg84d7f2e2015-10-13 15:41:39 +0300207#define PCI_DEVICE_ID_INTEL_DNV_SMBUS 0x19df
Jarkko Nikuladd77f422015-10-22 17:16:58 +0300208#define PCI_DEVICE_ID_INTEL_BROXTON_SMBUS 0x5ad4
David Woodhouse55fee8d2010-10-31 21:07:00 +0100209
Jean Delvare3ad7ea12012-10-05 22:23:53 +0200210struct i801_mux_config {
211 char *gpio_chip;
212 unsigned values[3];
213 int n_values;
214 unsigned classes[3];
215 unsigned gpios[2]; /* Relative to gpio_chip->base */
216 int n_gpios;
217};
218
David Woodhouse0cd96eb2010-10-31 21:06:59 +0100219struct i801_priv {
220 struct i2c_adapter adapter;
221 unsigned long smba;
222 unsigned char original_hstcfg;
223 struct pci_dev *pci_dev;
224 unsigned int features;
Daniel Kurtz636752b2012-07-24 14:13:58 +0200225
226 /* isr processing */
227 wait_queue_head_t waitq;
228 u8 status;
Daniel Kurtzd3ff6ce2012-07-24 14:13:59 +0200229
230 /* Command state used by isr for byte-by-byte block transactions */
231 u8 cmd;
232 bool is_read;
233 int count;
234 int len;
235 u8 *data;
Jean Delvare3ad7ea12012-10-05 22:23:53 +0200236
Jean Delvare79e3e5b2012-10-28 21:37:01 +0100237#if (defined CONFIG_I2C_MUX_GPIO || defined CONFIG_I2C_MUX_GPIO_MODULE) && \
238 defined CONFIG_DMI
Jean Delvare3ad7ea12012-10-05 22:23:53 +0200239 const struct i801_mux_config *mux_drvdata;
Jean Delvare3ad7ea12012-10-05 22:23:53 +0200240 struct platform_device *mux_pdev;
241#endif
Mika Westerberg94246932015-08-06 13:46:25 +0100242 struct platform_device *tco_pdev;
David Woodhouse0cd96eb2010-10-31 21:06:59 +0100243};
244
Jean Delvare369f6f42008-01-27 18:14:50 +0100245#define FEATURE_SMBUS_PEC (1 << 0)
246#define FEATURE_BLOCK_BUFFER (1 << 1)
247#define FEATURE_BLOCK_PROC (1 << 2)
248#define FEATURE_I2C_BLOCK_READ (1 << 3)
Daniel Kurtz636752b2012-07-24 14:13:58 +0200249#define FEATURE_IRQ (1 << 4)
Jean Delvaree7198fb2011-05-24 20:58:49 +0200250/* Not really a feature, but it's convenient to handle it as such */
251#define FEATURE_IDF (1 << 15)
Mika Westerberg94246932015-08-06 13:46:25 +0100252#define FEATURE_TCO (1 << 16)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700253
Jean Delvareadff6872010-05-21 18:40:54 +0200254static const char *i801_feature_names[] = {
255 "SMBus PEC",
256 "Block buffer",
257 "Block process call",
258 "I2C block read",
Daniel Kurtz636752b2012-07-24 14:13:58 +0200259 "Interrupt",
Jean Delvareadff6872010-05-21 18:40:54 +0200260};
261
262static unsigned int disable_features;
263module_param(disable_features, uint, S_IRUGO | S_IWUSR);
Jean Delvare53229342013-05-15 02:44:10 +0000264MODULE_PARM_DESC(disable_features, "Disable selected driver features:\n"
265 "\t\t 0x01 disable SMBus PEC\n"
266 "\t\t 0x02 disable the block buffer\n"
267 "\t\t 0x08 disable the I2C block read functionality\n"
268 "\t\t 0x10 don't use interrupts ");
Jean Delvareadff6872010-05-21 18:40:54 +0200269
Jean Delvarecf898dc2008-07-14 22:38:33 +0200270/* Make sure the SMBus host is ready to start transmitting.
271 Return 0 if it is, -EBUSY if it is not. */
David Woodhouse0cd96eb2010-10-31 21:06:59 +0100272static int i801_check_pre(struct i801_priv *priv)
Jean Delvarecf898dc2008-07-14 22:38:33 +0200273{
274 int status;
275
David Woodhouse0cd96eb2010-10-31 21:06:59 +0100276 status = inb_p(SMBHSTSTS(priv));
Jean Delvarecf898dc2008-07-14 22:38:33 +0200277 if (status & SMBHSTSTS_HOST_BUSY) {
David Woodhouse0cd96eb2010-10-31 21:06:59 +0100278 dev_err(&priv->pci_dev->dev, "SMBus is busy, can't use it!\n");
Jean Delvarecf898dc2008-07-14 22:38:33 +0200279 return -EBUSY;
280 }
281
282 status &= STATUS_FLAGS;
283 if (status) {
David Woodhouse0cd96eb2010-10-31 21:06:59 +0100284 dev_dbg(&priv->pci_dev->dev, "Clearing status flags (%02x)\n",
Jean Delvarecf898dc2008-07-14 22:38:33 +0200285 status);
David Woodhouse0cd96eb2010-10-31 21:06:59 +0100286 outb_p(status, SMBHSTSTS(priv));
287 status = inb_p(SMBHSTSTS(priv)) & STATUS_FLAGS;
Jean Delvarecf898dc2008-07-14 22:38:33 +0200288 if (status) {
David Woodhouse0cd96eb2010-10-31 21:06:59 +0100289 dev_err(&priv->pci_dev->dev,
Jean Delvarecf898dc2008-07-14 22:38:33 +0200290 "Failed clearing status flags (%02x)\n",
291 status);
292 return -EBUSY;
293 }
294 }
295
296 return 0;
297}
298
Jean Delvare6cad93c2012-07-24 14:13:58 +0200299/*
300 * Convert the status register to an error code, and clear it.
301 * Note that status only contains the bits we want to clear, not the
302 * actual register value.
303 */
304static int i801_check_post(struct i801_priv *priv, int status)
Jean Delvarecf898dc2008-07-14 22:38:33 +0200305{
306 int result = 0;
307
Daniel Kurtz636752b2012-07-24 14:13:58 +0200308 /*
309 * If the SMBus is still busy, we give up
310 * Note: This timeout condition only happens when using polling
311 * transactions. For interrupt operation, NAK/timeout is indicated by
312 * DEV_ERR.
313 */
Jean Delvare6cad93c2012-07-24 14:13:58 +0200314 if (unlikely(status < 0)) {
David Woodhouse0cd96eb2010-10-31 21:06:59 +0100315 dev_err(&priv->pci_dev->dev, "Transaction timeout\n");
Jean Delvarecf898dc2008-07-14 22:38:33 +0200316 /* try to stop the current command */
David Woodhouse0cd96eb2010-10-31 21:06:59 +0100317 dev_dbg(&priv->pci_dev->dev, "Terminating the current operation\n");
318 outb_p(inb_p(SMBHSTCNT(priv)) | SMBHSTCNT_KILL,
319 SMBHSTCNT(priv));
Jean Delvare84c1af42012-03-26 21:47:19 +0200320 usleep_range(1000, 2000);
David Woodhouse0cd96eb2010-10-31 21:06:59 +0100321 outb_p(inb_p(SMBHSTCNT(priv)) & (~SMBHSTCNT_KILL),
322 SMBHSTCNT(priv));
Jean Delvarecf898dc2008-07-14 22:38:33 +0200323
324 /* Check if it worked */
David Woodhouse0cd96eb2010-10-31 21:06:59 +0100325 status = inb_p(SMBHSTSTS(priv));
Jean Delvarecf898dc2008-07-14 22:38:33 +0200326 if ((status & SMBHSTSTS_HOST_BUSY) ||
327 !(status & SMBHSTSTS_FAILED))
David Woodhouse0cd96eb2010-10-31 21:06:59 +0100328 dev_err(&priv->pci_dev->dev,
Jean Delvarecf898dc2008-07-14 22:38:33 +0200329 "Failed terminating the transaction\n");
David Woodhouse0cd96eb2010-10-31 21:06:59 +0100330 outb_p(STATUS_FLAGS, SMBHSTSTS(priv));
Jean Delvarecf898dc2008-07-14 22:38:33 +0200331 return -ETIMEDOUT;
332 }
333
334 if (status & SMBHSTSTS_FAILED) {
335 result = -EIO;
David Woodhouse0cd96eb2010-10-31 21:06:59 +0100336 dev_err(&priv->pci_dev->dev, "Transaction failed\n");
Jean Delvarecf898dc2008-07-14 22:38:33 +0200337 }
338 if (status & SMBHSTSTS_DEV_ERR) {
339 result = -ENXIO;
David Woodhouse0cd96eb2010-10-31 21:06:59 +0100340 dev_dbg(&priv->pci_dev->dev, "No response\n");
Jean Delvarecf898dc2008-07-14 22:38:33 +0200341 }
342 if (status & SMBHSTSTS_BUS_ERR) {
343 result = -EAGAIN;
David Woodhouse0cd96eb2010-10-31 21:06:59 +0100344 dev_dbg(&priv->pci_dev->dev, "Lost arbitration\n");
Jean Delvarecf898dc2008-07-14 22:38:33 +0200345 }
346
Jean Delvare6cad93c2012-07-24 14:13:58 +0200347 /* Clear status flags except BYTE_DONE, to be cleared by caller */
348 outb_p(status, SMBHSTSTS(priv));
Jean Delvarecf898dc2008-07-14 22:38:33 +0200349
350 return result;
351}
352
Jean Delvare6cad93c2012-07-24 14:13:58 +0200353/* Wait for BUSY being cleared and either INTR or an error flag being set */
354static int i801_wait_intr(struct i801_priv *priv)
355{
356 int timeout = 0;
357 int status;
358
359 /* We will always wait for a fraction of a second! */
360 do {
361 usleep_range(250, 500);
362 status = inb_p(SMBHSTSTS(priv));
363 } while (((status & SMBHSTSTS_HOST_BUSY) ||
364 !(status & (STATUS_ERROR_FLAGS | SMBHSTSTS_INTR))) &&
365 (timeout++ < MAX_RETRIES));
366
367 if (timeout > MAX_RETRIES) {
368 dev_dbg(&priv->pci_dev->dev, "INTR Timeout!\n");
369 return -ETIMEDOUT;
370 }
371 return status & (STATUS_ERROR_FLAGS | SMBHSTSTS_INTR);
372}
373
374/* Wait for either BYTE_DONE or an error flag being set */
375static int i801_wait_byte_done(struct i801_priv *priv)
376{
377 int timeout = 0;
378 int status;
379
380 /* We will always wait for a fraction of a second! */
381 do {
382 usleep_range(250, 500);
383 status = inb_p(SMBHSTSTS(priv));
384 } while (!(status & (STATUS_ERROR_FLAGS | SMBHSTSTS_BYTE_DONE)) &&
385 (timeout++ < MAX_RETRIES));
386
387 if (timeout > MAX_RETRIES) {
388 dev_dbg(&priv->pci_dev->dev, "BYTE_DONE Timeout!\n");
389 return -ETIMEDOUT;
390 }
391 return status & STATUS_ERROR_FLAGS;
392}
393
David Woodhouse0cd96eb2010-10-31 21:06:59 +0100394static int i801_transaction(struct i801_priv *priv, int xact)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700395{
Jean Delvare2b738092008-07-14 22:38:32 +0200396 int status;
Jean Delvarecf898dc2008-07-14 22:38:33 +0200397 int result;
Jean Delvareb3b8df92014-11-12 10:20:40 +0100398 const struct i2c_adapter *adap = &priv->adapter;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700399
David Woodhouse0cd96eb2010-10-31 21:06:59 +0100400 result = i801_check_pre(priv);
Jean Delvarecf898dc2008-07-14 22:38:33 +0200401 if (result < 0)
402 return result;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700403
Daniel Kurtz636752b2012-07-24 14:13:58 +0200404 if (priv->features & FEATURE_IRQ) {
405 outb_p(xact | SMBHSTCNT_INTREN | SMBHSTCNT_START,
406 SMBHSTCNT(priv));
Jean Delvareb3b8df92014-11-12 10:20:40 +0100407 result = wait_event_timeout(priv->waitq,
408 (status = priv->status),
409 adap->timeout);
410 if (!result) {
411 status = -ETIMEDOUT;
412 dev_warn(&priv->pci_dev->dev,
413 "Timeout waiting for interrupt!\n");
414 }
Daniel Kurtz636752b2012-07-24 14:13:58 +0200415 priv->status = 0;
416 return i801_check_post(priv, status);
417 }
418
Oleg Ryjkov7edcb9a2007-07-12 14:12:31 +0200419 /* the current contents of SMBHSTCNT can be overwritten, since PEC,
Daniel Kurtz37af8712012-07-24 14:13:58 +0200420 * SMBSCMD are passed in xact */
Daniel Kurtzedbeea62012-07-24 14:13:58 +0200421 outb_p(xact | SMBHSTCNT_START, SMBHSTCNT(priv));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700422
Jean Delvare6cad93c2012-07-24 14:13:58 +0200423 status = i801_wait_intr(priv);
424 return i801_check_post(priv, status);
Oleg Ryjkovca8b9e32007-07-12 14:12:31 +0200425}
426
David Woodhouse0cd96eb2010-10-31 21:06:59 +0100427static int i801_block_transaction_by_block(struct i801_priv *priv,
428 union i2c_smbus_data *data,
Oleg Ryjkov7edcb9a2007-07-12 14:12:31 +0200429 char read_write, int hwpec)
430{
431 int i, len;
David Brownell97140342008-07-14 22:38:25 +0200432 int status;
Oleg Ryjkov7edcb9a2007-07-12 14:12:31 +0200433
David Woodhouse0cd96eb2010-10-31 21:06:59 +0100434 inb_p(SMBHSTCNT(priv)); /* reset the data buffer index */
Oleg Ryjkov7edcb9a2007-07-12 14:12:31 +0200435
436 /* Use 32-byte buffer to process this transaction */
437 if (read_write == I2C_SMBUS_WRITE) {
438 len = data->block[0];
David Woodhouse0cd96eb2010-10-31 21:06:59 +0100439 outb_p(len, SMBHSTDAT0(priv));
Oleg Ryjkov7edcb9a2007-07-12 14:12:31 +0200440 for (i = 0; i < len; i++)
David Woodhouse0cd96eb2010-10-31 21:06:59 +0100441 outb_p(data->block[i+1], SMBBLKDAT(priv));
Oleg Ryjkov7edcb9a2007-07-12 14:12:31 +0200442 }
443
Daniel Kurtz37af8712012-07-24 14:13:58 +0200444 status = i801_transaction(priv, I801_BLOCK_DATA |
Daniel Kurtzedbeea62012-07-24 14:13:58 +0200445 (hwpec ? SMBHSTCNT_PEC_EN : 0));
David Brownell97140342008-07-14 22:38:25 +0200446 if (status)
447 return status;
Oleg Ryjkov7edcb9a2007-07-12 14:12:31 +0200448
449 if (read_write == I2C_SMBUS_READ) {
David Woodhouse0cd96eb2010-10-31 21:06:59 +0100450 len = inb_p(SMBHSTDAT0(priv));
Oleg Ryjkov7edcb9a2007-07-12 14:12:31 +0200451 if (len < 1 || len > I2C_SMBUS_BLOCK_MAX)
David Brownell97140342008-07-14 22:38:25 +0200452 return -EPROTO;
Oleg Ryjkov7edcb9a2007-07-12 14:12:31 +0200453
454 data->block[0] = len;
455 for (i = 0; i < len; i++)
David Woodhouse0cd96eb2010-10-31 21:06:59 +0100456 data->block[i + 1] = inb_p(SMBBLKDAT(priv));
Oleg Ryjkov7edcb9a2007-07-12 14:12:31 +0200457 }
458 return 0;
459}
460
Daniel Kurtzd3ff6ce2012-07-24 14:13:59 +0200461static void i801_isr_byte_done(struct i801_priv *priv)
462{
463 if (priv->is_read) {
464 /* For SMBus block reads, length is received with first byte */
465 if (((priv->cmd & 0x1c) == I801_BLOCK_DATA) &&
466 (priv->count == 0)) {
467 priv->len = inb_p(SMBHSTDAT0(priv));
468 if (priv->len < 1 || priv->len > I2C_SMBUS_BLOCK_MAX) {
469 dev_err(&priv->pci_dev->dev,
470 "Illegal SMBus block read size %d\n",
471 priv->len);
472 /* FIXME: Recover */
473 priv->len = I2C_SMBUS_BLOCK_MAX;
474 } else {
475 dev_dbg(&priv->pci_dev->dev,
476 "SMBus block read size is %d\n",
477 priv->len);
478 }
479 priv->data[-1] = priv->len;
480 }
481
482 /* Read next byte */
483 if (priv->count < priv->len)
484 priv->data[priv->count++] = inb(SMBBLKDAT(priv));
485 else
486 dev_dbg(&priv->pci_dev->dev,
487 "Discarding extra byte on block read\n");
488
489 /* Set LAST_BYTE for last byte of read transaction */
490 if (priv->count == priv->len - 1)
491 outb_p(priv->cmd | SMBHSTCNT_LAST_BYTE,
492 SMBHSTCNT(priv));
493 } else if (priv->count < priv->len - 1) {
494 /* Write next byte, except for IRQ after last byte */
495 outb_p(priv->data[++priv->count], SMBBLKDAT(priv));
496 }
497
498 /* Clear BYTE_DONE to continue with next byte */
499 outb_p(SMBHSTSTS_BYTE_DONE, SMBHSTSTS(priv));
500}
501
Daniel Kurtzefa3cb12012-07-24 14:13:57 +0200502/*
Daniel Kurtzd3ff6ce2012-07-24 14:13:59 +0200503 * There are two kinds of interrupts:
504 *
505 * 1) i801 signals transaction completion with one of these interrupts:
506 * INTR - Success
507 * DEV_ERR - Invalid command, NAK or communication timeout
508 * BUS_ERR - SMI# transaction collision
509 * FAILED - transaction was canceled due to a KILL request
510 * When any of these occur, update ->status and wake up the waitq.
511 * ->status must be cleared before kicking off the next transaction.
512 *
513 * 2) For byte-by-byte (I2C read/write) transactions, one BYTE_DONE interrupt
514 * occurs for each byte of a byte-by-byte to prepare the next byte.
Daniel Kurtz636752b2012-07-24 14:13:58 +0200515 */
516static irqreturn_t i801_isr(int irq, void *dev_id)
517{
518 struct i801_priv *priv = dev_id;
519 u16 pcists;
520 u8 status;
521
522 /* Confirm this is our interrupt */
523 pci_read_config_word(priv->pci_dev, SMBPCISTS, &pcists);
524 if (!(pcists & SMBPCISTS_INTS))
525 return IRQ_NONE;
526
527 status = inb_p(SMBHSTSTS(priv));
Daniel Kurtzd3ff6ce2012-07-24 14:13:59 +0200528 if (status & SMBHSTSTS_BYTE_DONE)
529 i801_isr_byte_done(priv);
530
Daniel Kurtz636752b2012-07-24 14:13:58 +0200531 /*
532 * Clear irq sources and report transaction result.
533 * ->status must be cleared before the next transaction is started.
534 */
535 status &= SMBHSTSTS_INTR | STATUS_ERROR_FLAGS;
536 if (status) {
537 outb_p(status, SMBHSTSTS(priv));
538 priv->status |= status;
539 wake_up(&priv->waitq);
540 }
541
542 return IRQ_HANDLED;
543}
544
545/*
Daniel Kurtzefa3cb12012-07-24 14:13:57 +0200546 * For "byte-by-byte" block transactions:
547 * I2C write uses cmd=I801_BLOCK_DATA, I2C_EN=1
548 * I2C read uses cmd=I801_I2C_BLOCK_DATA
549 */
David Woodhouse0cd96eb2010-10-31 21:06:59 +0100550static int i801_block_transaction_byte_by_byte(struct i801_priv *priv,
551 union i2c_smbus_data *data,
Jean Delvare63420642008-01-27 18:14:50 +0100552 char read_write, int command,
553 int hwpec)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700554{
555 int i, len;
556 int smbcmd;
Jean Delvare2b738092008-07-14 22:38:32 +0200557 int status;
Jean Delvarecf898dc2008-07-14 22:38:33 +0200558 int result;
Jean Delvareb3b8df92014-11-12 10:20:40 +0100559 const struct i2c_adapter *adap = &priv->adapter;
Jean Delvarecf898dc2008-07-14 22:38:33 +0200560
David Woodhouse0cd96eb2010-10-31 21:06:59 +0100561 result = i801_check_pre(priv);
Jean Delvarecf898dc2008-07-14 22:38:33 +0200562 if (result < 0)
563 return result;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700564
Oleg Ryjkov7edcb9a2007-07-12 14:12:31 +0200565 len = data->block[0];
Linus Torvalds1da177e2005-04-16 15:20:36 -0700566
567 if (read_write == I2C_SMBUS_WRITE) {
David Woodhouse0cd96eb2010-10-31 21:06:59 +0100568 outb_p(len, SMBHSTDAT0(priv));
569 outb_p(data->block[1], SMBBLKDAT(priv));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700570 }
571
Daniel Kurtzefa3cb12012-07-24 14:13:57 +0200572 if (command == I2C_SMBUS_I2C_BLOCK_DATA &&
573 read_write == I2C_SMBUS_READ)
574 smbcmd = I801_I2C_BLOCK_DATA;
575 else
576 smbcmd = I801_BLOCK_DATA;
577
Daniel Kurtzd3ff6ce2012-07-24 14:13:59 +0200578 if (priv->features & FEATURE_IRQ) {
579 priv->is_read = (read_write == I2C_SMBUS_READ);
580 if (len == 1 && priv->is_read)
581 smbcmd |= SMBHSTCNT_LAST_BYTE;
582 priv->cmd = smbcmd | SMBHSTCNT_INTREN;
583 priv->len = len;
584 priv->count = 0;
585 priv->data = &data->block[1];
586
587 outb_p(priv->cmd | SMBHSTCNT_START, SMBHSTCNT(priv));
Jean Delvareb3b8df92014-11-12 10:20:40 +0100588 result = wait_event_timeout(priv->waitq,
589 (status = priv->status),
590 adap->timeout);
591 if (!result) {
592 status = -ETIMEDOUT;
593 dev_warn(&priv->pci_dev->dev,
594 "Timeout waiting for interrupt!\n");
595 }
Daniel Kurtzd3ff6ce2012-07-24 14:13:59 +0200596 priv->status = 0;
597 return i801_check_post(priv, status);
598 }
599
Linus Torvalds1da177e2005-04-16 15:20:36 -0700600 for (i = 1; i <= len; i++) {
Daniel Kurtzefa3cb12012-07-24 14:13:57 +0200601 if (i == len && read_write == I2C_SMBUS_READ)
Daniel Kurtzedbeea62012-07-24 14:13:58 +0200602 smbcmd |= SMBHSTCNT_LAST_BYTE;
Daniel Kurtz37af8712012-07-24 14:13:58 +0200603 outb_p(smbcmd, SMBHSTCNT(priv));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700604
Linus Torvalds1da177e2005-04-16 15:20:36 -0700605 if (i == 1)
Daniel Kurtzedbeea62012-07-24 14:13:58 +0200606 outb_p(inb(SMBHSTCNT(priv)) | SMBHSTCNT_START,
David Woodhouse0cd96eb2010-10-31 21:06:59 +0100607 SMBHSTCNT(priv));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700608
Jean Delvare6cad93c2012-07-24 14:13:58 +0200609 status = i801_wait_byte_done(priv);
610 if (status)
611 goto exit;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700612
Jean Delvare63420642008-01-27 18:14:50 +0100613 if (i == 1 && read_write == I2C_SMBUS_READ
614 && command != I2C_SMBUS_I2C_BLOCK_DATA) {
David Woodhouse0cd96eb2010-10-31 21:06:59 +0100615 len = inb_p(SMBHSTDAT0(priv));
Jean Delvarecf898dc2008-07-14 22:38:33 +0200616 if (len < 1 || len > I2C_SMBUS_BLOCK_MAX) {
David Woodhouse0cd96eb2010-10-31 21:06:59 +0100617 dev_err(&priv->pci_dev->dev,
Jean Delvarecf898dc2008-07-14 22:38:33 +0200618 "Illegal SMBus block read size %d\n",
619 len);
620 /* Recover */
David Woodhouse0cd96eb2010-10-31 21:06:59 +0100621 while (inb_p(SMBHSTSTS(priv)) &
622 SMBHSTSTS_HOST_BUSY)
623 outb_p(SMBHSTSTS_BYTE_DONE,
624 SMBHSTSTS(priv));
625 outb_p(SMBHSTSTS_INTR, SMBHSTSTS(priv));
David Brownell97140342008-07-14 22:38:25 +0200626 return -EPROTO;
Jean Delvarecf898dc2008-07-14 22:38:33 +0200627 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700628 data->block[0] = len;
629 }
630
631 /* Retrieve/store value in SMBBLKDAT */
632 if (read_write == I2C_SMBUS_READ)
David Woodhouse0cd96eb2010-10-31 21:06:59 +0100633 data->block[i] = inb_p(SMBBLKDAT(priv));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700634 if (read_write == I2C_SMBUS_WRITE && i+1 <= len)
David Woodhouse0cd96eb2010-10-31 21:06:59 +0100635 outb_p(data->block[i+1], SMBBLKDAT(priv));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700636
Jean Delvarecf898dc2008-07-14 22:38:33 +0200637 /* signals SMBBLKDAT ready */
Jean Delvare6cad93c2012-07-24 14:13:58 +0200638 outb_p(SMBHSTSTS_BYTE_DONE, SMBHSTSTS(priv));
Oleg Ryjkov7edcb9a2007-07-12 14:12:31 +0200639 }
Jean Delvarecf898dc2008-07-14 22:38:33 +0200640
Jean Delvare6cad93c2012-07-24 14:13:58 +0200641 status = i801_wait_intr(priv);
642exit:
643 return i801_check_post(priv, status);
Oleg Ryjkov7edcb9a2007-07-12 14:12:31 +0200644}
645
David Woodhouse0cd96eb2010-10-31 21:06:59 +0100646static int i801_set_block_buffer_mode(struct i801_priv *priv)
Oleg Ryjkov7edcb9a2007-07-12 14:12:31 +0200647{
David Woodhouse0cd96eb2010-10-31 21:06:59 +0100648 outb_p(inb_p(SMBAUXCTL(priv)) | SMBAUXCTL_E32B, SMBAUXCTL(priv));
649 if ((inb_p(SMBAUXCTL(priv)) & SMBAUXCTL_E32B) == 0)
David Brownell97140342008-07-14 22:38:25 +0200650 return -EIO;
Oleg Ryjkov7edcb9a2007-07-12 14:12:31 +0200651 return 0;
652}
653
654/* Block transaction function */
David Woodhouse0cd96eb2010-10-31 21:06:59 +0100655static int i801_block_transaction(struct i801_priv *priv,
656 union i2c_smbus_data *data, char read_write,
Oleg Ryjkov7edcb9a2007-07-12 14:12:31 +0200657 int command, int hwpec)
658{
659 int result = 0;
660 unsigned char hostc;
661
662 if (command == I2C_SMBUS_I2C_BLOCK_DATA) {
663 if (read_write == I2C_SMBUS_WRITE) {
664 /* set I2C_EN bit in configuration register */
David Woodhouse0cd96eb2010-10-31 21:06:59 +0100665 pci_read_config_byte(priv->pci_dev, SMBHSTCFG, &hostc);
666 pci_write_config_byte(priv->pci_dev, SMBHSTCFG,
Oleg Ryjkov7edcb9a2007-07-12 14:12:31 +0200667 hostc | SMBHSTCFG_I2C_EN);
David Woodhouse0cd96eb2010-10-31 21:06:59 +0100668 } else if (!(priv->features & FEATURE_I2C_BLOCK_READ)) {
669 dev_err(&priv->pci_dev->dev,
Jean Delvare63420642008-01-27 18:14:50 +0100670 "I2C block read is unsupported!\n");
David Brownell97140342008-07-14 22:38:25 +0200671 return -EOPNOTSUPP;
Oleg Ryjkov7edcb9a2007-07-12 14:12:31 +0200672 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700673 }
674
Jean Delvare63420642008-01-27 18:14:50 +0100675 if (read_write == I2C_SMBUS_WRITE
676 || command == I2C_SMBUS_I2C_BLOCK_DATA) {
Oleg Ryjkov7edcb9a2007-07-12 14:12:31 +0200677 if (data->block[0] < 1)
678 data->block[0] = 1;
679 if (data->block[0] > I2C_SMBUS_BLOCK_MAX)
680 data->block[0] = I2C_SMBUS_BLOCK_MAX;
681 } else {
Jean Delvare63420642008-01-27 18:14:50 +0100682 data->block[0] = 32; /* max for SMBus block reads */
Oleg Ryjkov7edcb9a2007-07-12 14:12:31 +0200683 }
684
Jean Delvarec074c392010-03-13 20:56:53 +0100685 /* Experience has shown that the block buffer can only be used for
686 SMBus (not I2C) block transactions, even though the datasheet
687 doesn't mention this limitation. */
David Woodhouse0cd96eb2010-10-31 21:06:59 +0100688 if ((priv->features & FEATURE_BLOCK_BUFFER)
Jean Delvarec074c392010-03-13 20:56:53 +0100689 && command != I2C_SMBUS_I2C_BLOCK_DATA
David Woodhouse0cd96eb2010-10-31 21:06:59 +0100690 && i801_set_block_buffer_mode(priv) == 0)
691 result = i801_block_transaction_by_block(priv, data,
692 read_write, hwpec);
Oleg Ryjkov7edcb9a2007-07-12 14:12:31 +0200693 else
David Woodhouse0cd96eb2010-10-31 21:06:59 +0100694 result = i801_block_transaction_byte_by_byte(priv, data,
695 read_write,
Jean Delvare63420642008-01-27 18:14:50 +0100696 command, hwpec);
Oleg Ryjkov7edcb9a2007-07-12 14:12:31 +0200697
Jean Delvare63420642008-01-27 18:14:50 +0100698 if (command == I2C_SMBUS_I2C_BLOCK_DATA
699 && read_write == I2C_SMBUS_WRITE) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700700 /* restore saved configuration register value */
David Woodhouse0cd96eb2010-10-31 21:06:59 +0100701 pci_write_config_byte(priv->pci_dev, SMBHSTCFG, hostc);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700702 }
703 return result;
704}
705
David Brownell97140342008-07-14 22:38:25 +0200706/* Return negative errno on error. */
Ivo Manca3fb21c62010-05-21 18:40:55 +0200707static s32 i801_access(struct i2c_adapter *adap, u16 addr,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700708 unsigned short flags, char read_write, u8 command,
Ivo Manca3fb21c62010-05-21 18:40:55 +0200709 int size, union i2c_smbus_data *data)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700710{
Jean Delvaree8aac4a2005-10-26 21:34:42 +0200711 int hwpec;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700712 int block = 0;
713 int ret, xact = 0;
David Woodhouse0cd96eb2010-10-31 21:06:59 +0100714 struct i801_priv *priv = i2c_get_adapdata(adap);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700715
David Woodhouse0cd96eb2010-10-31 21:06:59 +0100716 hwpec = (priv->features & FEATURE_SMBUS_PEC) && (flags & I2C_CLIENT_PEC)
Jean Delvaree8aac4a2005-10-26 21:34:42 +0200717 && size != I2C_SMBUS_QUICK
718 && size != I2C_SMBUS_I2C_BLOCK_DATA;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700719
720 switch (size) {
721 case I2C_SMBUS_QUICK:
722 outb_p(((addr & 0x7f) << 1) | (read_write & 0x01),
David Woodhouse0cd96eb2010-10-31 21:06:59 +0100723 SMBHSTADD(priv));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700724 xact = I801_QUICK;
725 break;
726 case I2C_SMBUS_BYTE:
727 outb_p(((addr & 0x7f) << 1) | (read_write & 0x01),
David Woodhouse0cd96eb2010-10-31 21:06:59 +0100728 SMBHSTADD(priv));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700729 if (read_write == I2C_SMBUS_WRITE)
David Woodhouse0cd96eb2010-10-31 21:06:59 +0100730 outb_p(command, SMBHSTCMD(priv));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700731 xact = I801_BYTE;
732 break;
733 case I2C_SMBUS_BYTE_DATA:
734 outb_p(((addr & 0x7f) << 1) | (read_write & 0x01),
David Woodhouse0cd96eb2010-10-31 21:06:59 +0100735 SMBHSTADD(priv));
736 outb_p(command, SMBHSTCMD(priv));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700737 if (read_write == I2C_SMBUS_WRITE)
David Woodhouse0cd96eb2010-10-31 21:06:59 +0100738 outb_p(data->byte, SMBHSTDAT0(priv));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700739 xact = I801_BYTE_DATA;
740 break;
741 case I2C_SMBUS_WORD_DATA:
742 outb_p(((addr & 0x7f) << 1) | (read_write & 0x01),
David Woodhouse0cd96eb2010-10-31 21:06:59 +0100743 SMBHSTADD(priv));
744 outb_p(command, SMBHSTCMD(priv));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700745 if (read_write == I2C_SMBUS_WRITE) {
David Woodhouse0cd96eb2010-10-31 21:06:59 +0100746 outb_p(data->word & 0xff, SMBHSTDAT0(priv));
747 outb_p((data->word & 0xff00) >> 8, SMBHSTDAT1(priv));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700748 }
749 xact = I801_WORD_DATA;
750 break;
751 case I2C_SMBUS_BLOCK_DATA:
Linus Torvalds1da177e2005-04-16 15:20:36 -0700752 outb_p(((addr & 0x7f) << 1) | (read_write & 0x01),
David Woodhouse0cd96eb2010-10-31 21:06:59 +0100753 SMBHSTADD(priv));
754 outb_p(command, SMBHSTCMD(priv));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700755 block = 1;
756 break;
Jean Delvare63420642008-01-27 18:14:50 +0100757 case I2C_SMBUS_I2C_BLOCK_DATA:
758 /* NB: page 240 of ICH5 datasheet shows that the R/#W
759 * bit should be cleared here, even when reading */
David Woodhouse0cd96eb2010-10-31 21:06:59 +0100760 outb_p((addr & 0x7f) << 1, SMBHSTADD(priv));
Jean Delvare63420642008-01-27 18:14:50 +0100761 if (read_write == I2C_SMBUS_READ) {
762 /* NB: page 240 of ICH5 datasheet also shows
763 * that DATA1 is the cmd field when reading */
David Woodhouse0cd96eb2010-10-31 21:06:59 +0100764 outb_p(command, SMBHSTDAT1(priv));
Jean Delvare63420642008-01-27 18:14:50 +0100765 } else
David Woodhouse0cd96eb2010-10-31 21:06:59 +0100766 outb_p(command, SMBHSTCMD(priv));
Jean Delvare63420642008-01-27 18:14:50 +0100767 block = 1;
768 break;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700769 default:
David Woodhouse0cd96eb2010-10-31 21:06:59 +0100770 dev_err(&priv->pci_dev->dev, "Unsupported transaction %d\n",
771 size);
David Brownell97140342008-07-14 22:38:25 +0200772 return -EOPNOTSUPP;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700773 }
774
Oleg Ryjkovca8b9e32007-07-12 14:12:31 +0200775 if (hwpec) /* enable/disable hardware PEC */
David Woodhouse0cd96eb2010-10-31 21:06:59 +0100776 outb_p(inb_p(SMBAUXCTL(priv)) | SMBAUXCTL_CRC, SMBAUXCTL(priv));
Oleg Ryjkovca8b9e32007-07-12 14:12:31 +0200777 else
David Woodhouse0cd96eb2010-10-31 21:06:59 +0100778 outb_p(inb_p(SMBAUXCTL(priv)) & (~SMBAUXCTL_CRC),
779 SMBAUXCTL(priv));
Jean Delvaree8aac4a2005-10-26 21:34:42 +0200780
Ivo Manca3fb21c62010-05-21 18:40:55 +0200781 if (block)
David Woodhouse0cd96eb2010-10-31 21:06:59 +0100782 ret = i801_block_transaction(priv, data, read_write, size,
783 hwpec);
Oleg Ryjkov7edcb9a2007-07-12 14:12:31 +0200784 else
Daniel Kurtz37af8712012-07-24 14:13:58 +0200785 ret = i801_transaction(priv, xact);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700786
Jean Delvarec79cfba2006-04-20 02:43:18 -0700787 /* Some BIOSes don't like it when PEC is enabled at reboot or resume
Oleg Ryjkov7edcb9a2007-07-12 14:12:31 +0200788 time, so we forcibly disable it after every transaction. Turn off
789 E32B for the same reason. */
Jean Delvarea0921b62008-01-27 18:14:50 +0100790 if (hwpec || block)
David Woodhouse0cd96eb2010-10-31 21:06:59 +0100791 outb_p(inb_p(SMBAUXCTL(priv)) &
792 ~(SMBAUXCTL_CRC | SMBAUXCTL_E32B), SMBAUXCTL(priv));
Jean Delvarec79cfba2006-04-20 02:43:18 -0700793
Ivo Manca3fb21c62010-05-21 18:40:55 +0200794 if (block)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700795 return ret;
Ivo Manca3fb21c62010-05-21 18:40:55 +0200796 if (ret)
David Brownell97140342008-07-14 22:38:25 +0200797 return ret;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700798 if ((read_write == I2C_SMBUS_WRITE) || (xact == I801_QUICK))
799 return 0;
800
801 switch (xact & 0x7f) {
802 case I801_BYTE: /* Result put in SMBHSTDAT0 */
803 case I801_BYTE_DATA:
David Woodhouse0cd96eb2010-10-31 21:06:59 +0100804 data->byte = inb_p(SMBHSTDAT0(priv));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700805 break;
806 case I801_WORD_DATA:
David Woodhouse0cd96eb2010-10-31 21:06:59 +0100807 data->word = inb_p(SMBHSTDAT0(priv)) +
808 (inb_p(SMBHSTDAT1(priv)) << 8);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700809 break;
810 }
811 return 0;
812}
813
814
815static u32 i801_func(struct i2c_adapter *adapter)
816{
David Woodhouse0cd96eb2010-10-31 21:06:59 +0100817 struct i801_priv *priv = i2c_get_adapdata(adapter);
818
Linus Torvalds1da177e2005-04-16 15:20:36 -0700819 return I2C_FUNC_SMBUS_QUICK | I2C_FUNC_SMBUS_BYTE |
Jean Delvare369f6f42008-01-27 18:14:50 +0100820 I2C_FUNC_SMBUS_BYTE_DATA | I2C_FUNC_SMBUS_WORD_DATA |
821 I2C_FUNC_SMBUS_BLOCK_DATA | I2C_FUNC_SMBUS_WRITE_I2C_BLOCK |
David Woodhouse0cd96eb2010-10-31 21:06:59 +0100822 ((priv->features & FEATURE_SMBUS_PEC) ? I2C_FUNC_SMBUS_PEC : 0) |
823 ((priv->features & FEATURE_I2C_BLOCK_READ) ?
Jean Delvare63420642008-01-27 18:14:50 +0100824 I2C_FUNC_SMBUS_READ_I2C_BLOCK : 0);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700825}
826
Jean Delvare8f9082c2006-09-03 22:39:46 +0200827static const struct i2c_algorithm smbus_algorithm = {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700828 .smbus_xfer = i801_access,
829 .functionality = i801_func,
830};
831
Jingoo Han392debf2013-12-03 08:11:20 +0900832static const struct pci_device_id i801_ids[] = {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700833 { PCI_DEVICE(PCI_VENDOR_ID_INTEL, PCI_DEVICE_ID_INTEL_82801AA_3) },
834 { PCI_DEVICE(PCI_VENDOR_ID_INTEL, PCI_DEVICE_ID_INTEL_82801AB_3) },
835 { PCI_DEVICE(PCI_VENDOR_ID_INTEL, PCI_DEVICE_ID_INTEL_82801BA_2) },
836 { PCI_DEVICE(PCI_VENDOR_ID_INTEL, PCI_DEVICE_ID_INTEL_82801CA_3) },
837 { PCI_DEVICE(PCI_VENDOR_ID_INTEL, PCI_DEVICE_ID_INTEL_82801DB_3) },
838 { PCI_DEVICE(PCI_VENDOR_ID_INTEL, PCI_DEVICE_ID_INTEL_82801EB_3) },
839 { PCI_DEVICE(PCI_VENDOR_ID_INTEL, PCI_DEVICE_ID_INTEL_ESB_4) },
840 { PCI_DEVICE(PCI_VENDOR_ID_INTEL, PCI_DEVICE_ID_INTEL_ICH6_16) },
841 { PCI_DEVICE(PCI_VENDOR_ID_INTEL, PCI_DEVICE_ID_INTEL_ICH7_17) },
Jason Gastonb0a70b52005-04-16 15:24:45 -0700842 { PCI_DEVICE(PCI_VENDOR_ID_INTEL, PCI_DEVICE_ID_INTEL_ESB2_17) },
Jason Gaston8254fc42006-01-09 10:58:08 -0800843 { PCI_DEVICE(PCI_VENDOR_ID_INTEL, PCI_DEVICE_ID_INTEL_ICH8_5) },
Jason Gastonadbc2a12006-11-22 15:19:12 -0800844 { PCI_DEVICE(PCI_VENDOR_ID_INTEL, PCI_DEVICE_ID_INTEL_ICH9_6) },
Seth Heasleycb04e952010-10-04 13:27:14 -0700845 { PCI_DEVICE(PCI_VENDOR_ID_INTEL, PCI_DEVICE_ID_INTEL_EP80579_1) },
Gaston, Jason Dd28dc712008-02-24 20:03:42 +0100846 { PCI_DEVICE(PCI_VENDOR_ID_INTEL, PCI_DEVICE_ID_INTEL_ICH10_4) },
847 { PCI_DEVICE(PCI_VENDOR_ID_INTEL, PCI_DEVICE_ID_INTEL_ICH10_5) },
Seth Heasleycb04e952010-10-04 13:27:14 -0700848 { PCI_DEVICE(PCI_VENDOR_ID_INTEL, PCI_DEVICE_ID_INTEL_5_3400_SERIES_SMBUS) },
849 { PCI_DEVICE(PCI_VENDOR_ID_INTEL, PCI_DEVICE_ID_INTEL_COUGARPOINT_SMBUS) },
Seth Heasleye30d9852010-10-31 21:06:59 +0100850 { PCI_DEVICE(PCI_VENDOR_ID_INTEL, PCI_DEVICE_ID_INTEL_PATSBURG_SMBUS) },
David Woodhouse55fee8d2010-10-31 21:07:00 +0100851 { PCI_DEVICE(PCI_VENDOR_ID_INTEL, PCI_DEVICE_ID_INTEL_PATSBURG_SMBUS_IDF0) },
852 { PCI_DEVICE(PCI_VENDOR_ID_INTEL, PCI_DEVICE_ID_INTEL_PATSBURG_SMBUS_IDF1) },
853 { PCI_DEVICE(PCI_VENDOR_ID_INTEL, PCI_DEVICE_ID_INTEL_PATSBURG_SMBUS_IDF2) },
Seth Heasley662cda82011-03-20 14:50:53 +0100854 { PCI_DEVICE(PCI_VENDOR_ID_INTEL, PCI_DEVICE_ID_INTEL_DH89XXCC_SMBUS) },
Seth Heasley6e2a8512011-05-24 20:58:49 +0200855 { PCI_DEVICE(PCI_VENDOR_ID_INTEL, PCI_DEVICE_ID_INTEL_PANTHERPOINT_SMBUS) },
Seth Heasley062737f2012-03-26 21:47:19 +0200856 { PCI_DEVICE(PCI_VENDOR_ID_INTEL, PCI_DEVICE_ID_INTEL_LYNXPOINT_SMBUS) },
James Ralston4a8f1dd2012-09-10 10:14:02 +0200857 { PCI_DEVICE(PCI_VENDOR_ID_INTEL, PCI_DEVICE_ID_INTEL_LYNXPOINT_LP_SMBUS) },
Seth Heasleyc2db409c2013-01-30 15:25:32 +0000858 { PCI_DEVICE(PCI_VENDOR_ID_INTEL, PCI_DEVICE_ID_INTEL_AVOTON_SMBUS) },
James Ralstona3fc0ff2013-02-14 09:15:33 +0000859 { PCI_DEVICE(PCI_VENDOR_ID_INTEL, PCI_DEVICE_ID_INTEL_WELLSBURG_SMBUS) },
860 { PCI_DEVICE(PCI_VENDOR_ID_INTEL, PCI_DEVICE_ID_INTEL_WELLSBURG_SMBUS_MS0) },
861 { PCI_DEVICE(PCI_VENDOR_ID_INTEL, PCI_DEVICE_ID_INTEL_WELLSBURG_SMBUS_MS1) },
862 { PCI_DEVICE(PCI_VENDOR_ID_INTEL, PCI_DEVICE_ID_INTEL_WELLSBURG_SMBUS_MS2) },
Seth Heasleyf39901c2013-06-19 16:59:57 -0700863 { PCI_DEVICE(PCI_VENDOR_ID_INTEL, PCI_DEVICE_ID_INTEL_COLETOCREEK_SMBUS) },
Jean Delvareb299de82014-07-17 15:04:41 +0200864 { PCI_DEVICE(PCI_VENDOR_ID_INTEL, PCI_DEVICE_ID_INTEL_WILDCATPOINT_SMBUS) },
James Ralstonafc65922013-11-04 09:29:48 -0800865 { PCI_DEVICE(PCI_VENDOR_ID_INTEL, PCI_DEVICE_ID_INTEL_WILDCATPOINT_LP_SMBUS) },
Chew, Kean ho1b31e9b2014-03-01 00:03:56 +0800866 { PCI_DEVICE(PCI_VENDOR_ID_INTEL, PCI_DEVICE_ID_INTEL_BAYTRAIL_SMBUS) },
Alan Cox39e8e302014-08-19 17:37:28 +0300867 { PCI_DEVICE(PCI_VENDOR_ID_INTEL, PCI_DEVICE_ID_INTEL_BRASWELL_SMBUS) },
james.d.ralston@intel.com3e27a842014-10-13 15:20:24 -0700868 { PCI_DEVICE(PCI_VENDOR_ID_INTEL, PCI_DEVICE_ID_INTEL_SUNRISEPOINT_H_SMBUS) },
Devin Ryles3eee17992014-11-05 16:30:03 -0500869 { PCI_DEVICE(PCI_VENDOR_ID_INTEL, PCI_DEVICE_ID_INTEL_SUNRISEPOINT_LP_SMBUS) },
Mika Westerberg84d7f2e2015-10-13 15:41:39 +0300870 { PCI_DEVICE(PCI_VENDOR_ID_INTEL, PCI_DEVICE_ID_INTEL_DNV_SMBUS) },
Jarkko Nikuladd77f422015-10-22 17:16:58 +0300871 { PCI_DEVICE(PCI_VENDOR_ID_INTEL, PCI_DEVICE_ID_INTEL_BROXTON_SMBUS) },
Linus Torvalds1da177e2005-04-16 15:20:36 -0700872 { 0, }
873};
874
Ivo Manca3fb21c62010-05-21 18:40:55 +0200875MODULE_DEVICE_TABLE(pci, i801_ids);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700876
Jean Delvare8eacfce2011-05-24 20:58:49 +0200877#if defined CONFIG_X86 && defined CONFIG_DMI
Jean Delvare1561bfe2009-01-07 14:29:17 +0100878static unsigned char apanel_addr;
879
880/* Scan the system ROM for the signature "FJKEYINF" */
881static __init const void __iomem *bios_signature(const void __iomem *bios)
882{
883 ssize_t offset;
884 const unsigned char signature[] = "FJKEYINF";
885
886 for (offset = 0; offset < 0x10000; offset += 0x10) {
887 if (check_signature(bios + offset, signature,
888 sizeof(signature)-1))
889 return bios + offset;
890 }
891 return NULL;
892}
893
894static void __init input_apanel_init(void)
895{
896 void __iomem *bios;
897 const void __iomem *p;
898
899 bios = ioremap(0xF0000, 0x10000); /* Can't fail */
900 p = bios_signature(bios);
901 if (p) {
902 /* just use the first address */
903 apanel_addr = readb(p + 8 + 3) >> 1;
904 }
905 iounmap(bios);
906}
Jean Delvare1561bfe2009-01-07 14:29:17 +0100907
Hans de Goedefa5bfab2009-03-30 21:46:44 +0200908struct dmi_onboard_device_info {
909 const char *name;
910 u8 type;
911 unsigned short i2c_addr;
912 const char *i2c_type;
913};
914
Bill Pemberton0b255e92012-11-27 15:59:38 -0500915static const struct dmi_onboard_device_info dmi_devices[] = {
Hans de Goedefa5bfab2009-03-30 21:46:44 +0200916 { "Syleus", DMI_DEV_TYPE_OTHER, 0x73, "fscsyl" },
917 { "Hermes", DMI_DEV_TYPE_OTHER, 0x73, "fscher" },
918 { "Hades", DMI_DEV_TYPE_OTHER, 0x73, "fschds" },
919};
920
Bill Pemberton0b255e92012-11-27 15:59:38 -0500921static void dmi_check_onboard_device(u8 type, const char *name,
922 struct i2c_adapter *adap)
Hans de Goedefa5bfab2009-03-30 21:46:44 +0200923{
924 int i;
925 struct i2c_board_info info;
926
927 for (i = 0; i < ARRAY_SIZE(dmi_devices); i++) {
928 /* & ~0x80, ignore enabled/disabled bit */
929 if ((type & ~0x80) != dmi_devices[i].type)
930 continue;
Jean Delvarefaabd472010-07-09 16:22:51 +0200931 if (strcasecmp(name, dmi_devices[i].name))
Hans de Goedefa5bfab2009-03-30 21:46:44 +0200932 continue;
933
934 memset(&info, 0, sizeof(struct i2c_board_info));
935 info.addr = dmi_devices[i].i2c_addr;
936 strlcpy(info.type, dmi_devices[i].i2c_type, I2C_NAME_SIZE);
937 i2c_new_device(adap, &info);
938 break;
939 }
940}
941
942/* We use our own function to check for onboard devices instead of
943 dmi_find_device() as some buggy BIOS's have the devices we are interested
944 in marked as disabled */
Bill Pemberton0b255e92012-11-27 15:59:38 -0500945static void dmi_check_onboard_devices(const struct dmi_header *dm, void *adap)
Hans de Goedefa5bfab2009-03-30 21:46:44 +0200946{
947 int i, count;
948
949 if (dm->type != 10)
950 return;
951
952 count = (dm->length - sizeof(struct dmi_header)) / 2;
953 for (i = 0; i < count; i++) {
954 const u8 *d = (char *)(dm + 1) + (i * 2);
955 const char *name = ((char *) dm) + dm->length;
956 u8 type = d[0];
957 u8 s = d[1];
958
959 if (!s)
960 continue;
961 s--;
962 while (s > 0 && name[0]) {
963 name += strlen(name) + 1;
964 s--;
965 }
966 if (name[0] == 0) /* Bogus string reference */
967 continue;
968
969 dmi_check_onboard_device(type, name, adap);
970 }
971}
Hans de Goedefa5bfab2009-03-30 21:46:44 +0200972
Jean Delvaree7198fb2011-05-24 20:58:49 +0200973/* Register optional slaves */
Bill Pemberton0b255e92012-11-27 15:59:38 -0500974static void i801_probe_optional_slaves(struct i801_priv *priv)
Jean Delvaree7198fb2011-05-24 20:58:49 +0200975{
976 /* Only register slaves on main SMBus channel */
977 if (priv->features & FEATURE_IDF)
978 return;
979
Jean Delvaree7198fb2011-05-24 20:58:49 +0200980 if (apanel_addr) {
981 struct i2c_board_info info;
982
983 memset(&info, 0, sizeof(struct i2c_board_info));
984 info.addr = apanel_addr;
985 strlcpy(info.type, "fujitsu_apanel", I2C_NAME_SIZE);
986 i2c_new_device(&priv->adapter, &info);
987 }
Jean Delvare8eacfce2011-05-24 20:58:49 +0200988
Jean Delvaree7198fb2011-05-24 20:58:49 +0200989 if (dmi_name_in_vendors("FUJITSU"))
990 dmi_walk(dmi_check_onboard_devices, &priv->adapter);
Jean Delvaree7198fb2011-05-24 20:58:49 +0200991}
Jean Delvare8eacfce2011-05-24 20:58:49 +0200992#else
993static void __init input_apanel_init(void) {}
Bill Pemberton0b255e92012-11-27 15:59:38 -0500994static void i801_probe_optional_slaves(struct i801_priv *priv) {}
Jean Delvare8eacfce2011-05-24 20:58:49 +0200995#endif /* CONFIG_X86 && CONFIG_DMI */
Jean Delvaree7198fb2011-05-24 20:58:49 +0200996
Jean Delvare79e3e5b2012-10-28 21:37:01 +0100997#if (defined CONFIG_I2C_MUX_GPIO || defined CONFIG_I2C_MUX_GPIO_MODULE) && \
998 defined CONFIG_DMI
Jean Delvare3ad7ea12012-10-05 22:23:53 +0200999static struct i801_mux_config i801_mux_config_asus_z8_d12 = {
1000 .gpio_chip = "gpio_ich",
1001 .values = { 0x02, 0x03 },
1002 .n_values = 2,
1003 .classes = { I2C_CLASS_SPD, I2C_CLASS_SPD },
1004 .gpios = { 52, 53 },
1005 .n_gpios = 2,
1006};
1007
1008static struct i801_mux_config i801_mux_config_asus_z8_d18 = {
1009 .gpio_chip = "gpio_ich",
1010 .values = { 0x02, 0x03, 0x01 },
1011 .n_values = 3,
1012 .classes = { I2C_CLASS_SPD, I2C_CLASS_SPD, I2C_CLASS_SPD },
1013 .gpios = { 52, 53 },
1014 .n_gpios = 2,
1015};
1016
Bill Pemberton0b255e92012-11-27 15:59:38 -05001017static const struct dmi_system_id mux_dmi_table[] = {
Jean Delvare3ad7ea12012-10-05 22:23:53 +02001018 {
1019 .matches = {
1020 DMI_MATCH(DMI_BOARD_VENDOR, "ASUSTeK Computer INC."),
1021 DMI_MATCH(DMI_BOARD_NAME, "Z8NA-D6(C)"),
1022 },
1023 .driver_data = &i801_mux_config_asus_z8_d12,
1024 },
1025 {
1026 .matches = {
1027 DMI_MATCH(DMI_BOARD_VENDOR, "ASUSTeK Computer INC."),
1028 DMI_MATCH(DMI_BOARD_NAME, "Z8P(N)E-D12(X)"),
1029 },
1030 .driver_data = &i801_mux_config_asus_z8_d12,
1031 },
1032 {
1033 .matches = {
1034 DMI_MATCH(DMI_BOARD_VENDOR, "ASUSTeK Computer INC."),
1035 DMI_MATCH(DMI_BOARD_NAME, "Z8NH-D12"),
1036 },
1037 .driver_data = &i801_mux_config_asus_z8_d12,
1038 },
1039 {
1040 .matches = {
1041 DMI_MATCH(DMI_BOARD_VENDOR, "ASUSTeK Computer INC."),
1042 DMI_MATCH(DMI_BOARD_NAME, "Z8PH-D12/IFB"),
1043 },
1044 .driver_data = &i801_mux_config_asus_z8_d12,
1045 },
1046 {
1047 .matches = {
1048 DMI_MATCH(DMI_BOARD_VENDOR, "ASUSTeK Computer INC."),
1049 DMI_MATCH(DMI_BOARD_NAME, "Z8NR-D12"),
1050 },
1051 .driver_data = &i801_mux_config_asus_z8_d12,
1052 },
1053 {
1054 .matches = {
1055 DMI_MATCH(DMI_BOARD_VENDOR, "ASUSTeK Computer INC."),
1056 DMI_MATCH(DMI_BOARD_NAME, "Z8P(N)H-D12"),
1057 },
1058 .driver_data = &i801_mux_config_asus_z8_d12,
1059 },
1060 {
1061 .matches = {
1062 DMI_MATCH(DMI_BOARD_VENDOR, "ASUSTeK Computer INC."),
1063 DMI_MATCH(DMI_BOARD_NAME, "Z8PG-D18"),
1064 },
1065 .driver_data = &i801_mux_config_asus_z8_d18,
1066 },
1067 {
1068 .matches = {
1069 DMI_MATCH(DMI_BOARD_VENDOR, "ASUSTeK Computer INC."),
1070 DMI_MATCH(DMI_BOARD_NAME, "Z8PE-D18"),
1071 },
1072 .driver_data = &i801_mux_config_asus_z8_d18,
1073 },
1074 {
1075 .matches = {
1076 DMI_MATCH(DMI_BOARD_VENDOR, "ASUSTeK Computer INC."),
1077 DMI_MATCH(DMI_BOARD_NAME, "Z8PS-D12"),
1078 },
1079 .driver_data = &i801_mux_config_asus_z8_d12,
1080 },
1081 { }
1082};
1083
Jean Delvare3ad7ea12012-10-05 22:23:53 +02001084/* Setup multiplexing if needed */
Bill Pemberton0b255e92012-11-27 15:59:38 -05001085static int i801_add_mux(struct i801_priv *priv)
Jean Delvare3ad7ea12012-10-05 22:23:53 +02001086{
1087 struct device *dev = &priv->adapter.dev;
1088 const struct i801_mux_config *mux_config;
Jean Delvare3ad7ea12012-10-05 22:23:53 +02001089 struct i2c_mux_gpio_platform_data gpio_data;
Jean Delvaref82b8622012-10-05 22:23:54 +02001090 int err;
Jean Delvare3ad7ea12012-10-05 22:23:53 +02001091
1092 if (!priv->mux_drvdata)
1093 return 0;
1094 mux_config = priv->mux_drvdata;
1095
Jean Delvare3ad7ea12012-10-05 22:23:53 +02001096 /* Prepare the platform data */
1097 memset(&gpio_data, 0, sizeof(struct i2c_mux_gpio_platform_data));
1098 gpio_data.parent = priv->adapter.nr;
1099 gpio_data.values = mux_config->values;
1100 gpio_data.n_values = mux_config->n_values;
1101 gpio_data.classes = mux_config->classes;
Jean Delvaref82b8622012-10-05 22:23:54 +02001102 gpio_data.gpio_chip = mux_config->gpio_chip;
1103 gpio_data.gpios = mux_config->gpios;
Jean Delvare3ad7ea12012-10-05 22:23:53 +02001104 gpio_data.n_gpios = mux_config->n_gpios;
1105 gpio_data.idle = I2C_MUX_GPIO_NO_IDLE;
1106
1107 /* Register the mux device */
1108 priv->mux_pdev = platform_device_register_data(dev, "i2c-mux-gpio",
Jean Delvaref82b8622012-10-05 22:23:54 +02001109 PLATFORM_DEVID_AUTO, &gpio_data,
Jean Delvare3ad7ea12012-10-05 22:23:53 +02001110 sizeof(struct i2c_mux_gpio_platform_data));
1111 if (IS_ERR(priv->mux_pdev)) {
1112 err = PTR_ERR(priv->mux_pdev);
1113 priv->mux_pdev = NULL;
1114 dev_err(dev, "Failed to register i2c-mux-gpio device\n");
1115 return err;
1116 }
1117
1118 return 0;
1119}
1120
Bill Pemberton0b255e92012-11-27 15:59:38 -05001121static void i801_del_mux(struct i801_priv *priv)
Jean Delvare3ad7ea12012-10-05 22:23:53 +02001122{
1123 if (priv->mux_pdev)
1124 platform_device_unregister(priv->mux_pdev);
1125}
1126
Bill Pemberton0b255e92012-11-27 15:59:38 -05001127static unsigned int i801_get_adapter_class(struct i801_priv *priv)
Jean Delvare3ad7ea12012-10-05 22:23:53 +02001128{
1129 const struct dmi_system_id *id;
1130 const struct i801_mux_config *mux_config;
1131 unsigned int class = I2C_CLASS_HWMON | I2C_CLASS_SPD;
1132 int i;
1133
1134 id = dmi_first_match(mux_dmi_table);
1135 if (id) {
Jean Delvare28901f52012-10-28 21:37:01 +01001136 /* Remove branch classes from trunk */
Jean Delvare3ad7ea12012-10-05 22:23:53 +02001137 mux_config = id->driver_data;
1138 for (i = 0; i < mux_config->n_values; i++)
1139 class &= ~mux_config->classes[i];
1140
1141 /* Remember for later */
1142 priv->mux_drvdata = mux_config;
1143 }
1144
1145 return class;
1146}
1147#else
1148static inline int i801_add_mux(struct i801_priv *priv) { return 0; }
1149static inline void i801_del_mux(struct i801_priv *priv) { }
1150
1151static inline unsigned int i801_get_adapter_class(struct i801_priv *priv)
1152{
1153 return I2C_CLASS_HWMON | I2C_CLASS_SPD;
1154}
1155#endif
1156
Mika Westerberg94246932015-08-06 13:46:25 +01001157static const struct itco_wdt_platform_data tco_platform_data = {
1158 .name = "Intel PCH",
1159 .version = 4,
1160};
1161
1162static DEFINE_SPINLOCK(p2sb_spinlock);
1163
1164static void i801_add_tco(struct i801_priv *priv)
1165{
1166 struct pci_dev *pci_dev = priv->pci_dev;
1167 struct resource tco_res[3], *res;
1168 struct platform_device *pdev;
1169 unsigned int devfn;
1170 u32 tco_base, tco_ctl;
1171 u32 base_addr, ctrl_val;
1172 u64 base64_addr;
1173
1174 if (!(priv->features & FEATURE_TCO))
1175 return;
1176
1177 pci_read_config_dword(pci_dev, TCOBASE, &tco_base);
1178 pci_read_config_dword(pci_dev, TCOCTL, &tco_ctl);
1179 if (!(tco_ctl & TCOCTL_EN))
1180 return;
1181
1182 memset(tco_res, 0, sizeof(tco_res));
1183
1184 res = &tco_res[ICH_RES_IO_TCO];
1185 res->start = tco_base & ~1;
1186 res->end = res->start + 32 - 1;
1187 res->flags = IORESOURCE_IO;
1188
1189 /*
1190 * Power Management registers.
1191 */
1192 devfn = PCI_DEVFN(PCI_SLOT(pci_dev->devfn), 2);
1193 pci_bus_read_config_dword(pci_dev->bus, devfn, ACPIBASE, &base_addr);
1194
1195 res = &tco_res[ICH_RES_IO_SMI];
1196 res->start = (base_addr & ~1) + ACPIBASE_SMI_OFF;
1197 res->end = res->start + 3;
1198 res->flags = IORESOURCE_IO;
1199
1200 /*
1201 * Enable the ACPI I/O space.
1202 */
1203 pci_bus_read_config_dword(pci_dev->bus, devfn, ACPICTRL, &ctrl_val);
1204 ctrl_val |= ACPICTRL_EN;
1205 pci_bus_write_config_dword(pci_dev->bus, devfn, ACPICTRL, ctrl_val);
1206
1207 /*
1208 * We must access the NO_REBOOT bit over the Primary to Sideband
1209 * bridge (P2SB). The BIOS prevents the P2SB device from being
1210 * enumerated by the PCI subsystem, so we need to unhide/hide it
1211 * to lookup the P2SB BAR.
1212 */
1213 spin_lock(&p2sb_spinlock);
1214
1215 devfn = PCI_DEVFN(PCI_SLOT(pci_dev->devfn), 1);
1216
1217 /* Unhide the P2SB device */
1218 pci_bus_write_config_byte(pci_dev->bus, devfn, 0xe1, 0x0);
1219
1220 pci_bus_read_config_dword(pci_dev->bus, devfn, SBREG_BAR, &base_addr);
1221 base64_addr = base_addr & 0xfffffff0;
1222
1223 pci_bus_read_config_dword(pci_dev->bus, devfn, SBREG_BAR + 0x4, &base_addr);
1224 base64_addr |= (u64)base_addr << 32;
1225
1226 /* Hide the P2SB device */
1227 pci_bus_write_config_byte(pci_dev->bus, devfn, 0xe1, 0x1);
1228 spin_unlock(&p2sb_spinlock);
1229
1230 res = &tco_res[ICH_RES_MEM_OFF];
1231 res->start = (resource_size_t)base64_addr + SBREG_SMBCTRL;
1232 res->end = res->start + 3;
1233 res->flags = IORESOURCE_MEM;
1234
1235 pdev = platform_device_register_resndata(&pci_dev->dev, "iTCO_wdt", -1,
1236 tco_res, 3, &tco_platform_data,
1237 sizeof(tco_platform_data));
1238 if (IS_ERR(pdev)) {
1239 dev_warn(&pci_dev->dev, "failed to create iTCO device\n");
1240 return;
1241 }
1242
1243 priv->tco_pdev = pdev;
1244}
1245
Bill Pemberton0b255e92012-11-27 15:59:38 -05001246static int i801_probe(struct pci_dev *dev, const struct pci_device_id *id)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001247{
Jean Delvare02dd7ae2006-06-12 21:53:41 +02001248 unsigned char temp;
Jean Delvareadff6872010-05-21 18:40:54 +02001249 int err, i;
David Woodhouse0cd96eb2010-10-31 21:06:59 +01001250 struct i801_priv *priv;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001251
Jarkko Nikula1621c592015-02-13 15:52:23 +02001252 priv = devm_kzalloc(&dev->dev, sizeof(*priv), GFP_KERNEL);
David Woodhouse0cd96eb2010-10-31 21:06:59 +01001253 if (!priv)
1254 return -ENOMEM;
1255
1256 i2c_set_adapdata(&priv->adapter, priv);
1257 priv->adapter.owner = THIS_MODULE;
Jean Delvare3ad7ea12012-10-05 22:23:53 +02001258 priv->adapter.class = i801_get_adapter_class(priv);
David Woodhouse0cd96eb2010-10-31 21:06:59 +01001259 priv->adapter.algo = &smbus_algorithm;
Dustin Byford8eb5c872015-10-23 12:27:07 -07001260 priv->adapter.dev.parent = &dev->dev;
1261 ACPI_COMPANION_SET(&priv->adapter.dev, ACPI_COMPANION(&dev->dev));
1262 priv->adapter.retries = 3;
David Woodhouse0cd96eb2010-10-31 21:06:59 +01001263
1264 priv->pci_dev = dev;
Jean Delvare250d1bd2006-12-10 21:21:33 +01001265 switch (dev->device) {
Mika Westerberg94246932015-08-06 13:46:25 +01001266 case PCI_DEVICE_ID_INTEL_SUNRISEPOINT_H_SMBUS:
1267 case PCI_DEVICE_ID_INTEL_SUNRISEPOINT_LP_SMBUS:
Mika Westerberg84d7f2e2015-10-13 15:41:39 +03001268 case PCI_DEVICE_ID_INTEL_DNV_SMBUS:
Mika Westerberg94246932015-08-06 13:46:25 +01001269 priv->features |= FEATURE_I2C_BLOCK_READ;
1270 priv->features |= FEATURE_IRQ;
1271 priv->features |= FEATURE_SMBUS_PEC;
1272 priv->features |= FEATURE_BLOCK_BUFFER;
1273 priv->features |= FEATURE_TCO;
1274 break;
1275
Jean Delvaree7198fb2011-05-24 20:58:49 +02001276 case PCI_DEVICE_ID_INTEL_PATSBURG_SMBUS_IDF0:
1277 case PCI_DEVICE_ID_INTEL_PATSBURG_SMBUS_IDF1:
1278 case PCI_DEVICE_ID_INTEL_PATSBURG_SMBUS_IDF2:
James Ralstona3fc0ff2013-02-14 09:15:33 +00001279 case PCI_DEVICE_ID_INTEL_WELLSBURG_SMBUS_MS0:
1280 case PCI_DEVICE_ID_INTEL_WELLSBURG_SMBUS_MS1:
1281 case PCI_DEVICE_ID_INTEL_WELLSBURG_SMBUS_MS2:
Jean Delvaree7198fb2011-05-24 20:58:49 +02001282 priv->features |= FEATURE_IDF;
1283 /* fall through */
Jean Delvaree0e8398c2010-05-21 18:40:55 +02001284 default:
David Woodhouse0cd96eb2010-10-31 21:06:59 +01001285 priv->features |= FEATURE_I2C_BLOCK_READ;
Jean Delvare6676a842012-12-16 21:11:55 +01001286 priv->features |= FEATURE_IRQ;
Jean Delvare63420642008-01-27 18:14:50 +01001287 /* fall through */
1288 case PCI_DEVICE_ID_INTEL_82801DB_3:
David Woodhouse0cd96eb2010-10-31 21:06:59 +01001289 priv->features |= FEATURE_SMBUS_PEC;
1290 priv->features |= FEATURE_BLOCK_BUFFER;
Jean Delvaree0e8398c2010-05-21 18:40:55 +02001291 /* fall through */
1292 case PCI_DEVICE_ID_INTEL_82801CA_3:
1293 case PCI_DEVICE_ID_INTEL_82801BA_2:
1294 case PCI_DEVICE_ID_INTEL_82801AB_3:
1295 case PCI_DEVICE_ID_INTEL_82801AA_3:
Jean Delvare250d1bd2006-12-10 21:21:33 +01001296 break;
Jean Delvare250d1bd2006-12-10 21:21:33 +01001297 }
Jean Delvare02dd7ae2006-06-12 21:53:41 +02001298
Jean Delvareadff6872010-05-21 18:40:54 +02001299 /* Disable features on user request */
1300 for (i = 0; i < ARRAY_SIZE(i801_feature_names); i++) {
David Woodhouse0cd96eb2010-10-31 21:06:59 +01001301 if (priv->features & disable_features & (1 << i))
Jean Delvareadff6872010-05-21 18:40:54 +02001302 dev_notice(&dev->dev, "%s disabled by user\n",
1303 i801_feature_names[i]);
1304 }
David Woodhouse0cd96eb2010-10-31 21:06:59 +01001305 priv->features &= ~disable_features;
Jean Delvareadff6872010-05-21 18:40:54 +02001306
Jarkko Nikulafef220d2015-02-13 15:52:25 +02001307 err = pcim_enable_device(dev);
Jean Delvare02dd7ae2006-06-12 21:53:41 +02001308 if (err) {
1309 dev_err(&dev->dev, "Failed to enable SMBus PCI device (%d)\n",
1310 err);
Jarkko Nikulafef220d2015-02-13 15:52:25 +02001311 return err;
Jean Delvare02dd7ae2006-06-12 21:53:41 +02001312 }
Jarkko Nikulafef220d2015-02-13 15:52:25 +02001313 pcim_pin_device(dev);
Jean Delvare02dd7ae2006-06-12 21:53:41 +02001314
1315 /* Determine the address of the SMBus area */
David Woodhouse0cd96eb2010-10-31 21:06:59 +01001316 priv->smba = pci_resource_start(dev, SMBBAR);
1317 if (!priv->smba) {
Jarkko Nikula9cbbf3d2015-02-13 15:52:21 +02001318 dev_err(&dev->dev,
1319 "SMBus base address uninitialized, upgrade BIOS\n");
Jarkko Nikulafef220d2015-02-13 15:52:25 +02001320 return -ENODEV;
Jean Delvare02dd7ae2006-06-12 21:53:41 +02001321 }
1322
Jean Delvare54fb4a052008-07-14 22:38:33 +02001323 err = acpi_check_resource_conflict(&dev->resource[SMBBAR]);
Jean Delvare18669ea2009-10-04 22:53:45 +02001324 if (err) {
Jarkko Nikulafef220d2015-02-13 15:52:25 +02001325 return -ENODEV;
Jean Delvare18669ea2009-10-04 22:53:45 +02001326 }
Jean Delvare54fb4a052008-07-14 22:38:33 +02001327
Jarkko Nikulafef220d2015-02-13 15:52:25 +02001328 err = pcim_iomap_regions(dev, 1 << SMBBAR,
1329 dev_driver_string(&dev->dev));
Jean Delvare02dd7ae2006-06-12 21:53:41 +02001330 if (err) {
Jarkko Nikula9cbbf3d2015-02-13 15:52:21 +02001331 dev_err(&dev->dev,
1332 "Failed to request SMBus region 0x%lx-0x%Lx\n",
1333 priv->smba,
Andrew Morton598736c2006-06-30 01:56:20 -07001334 (unsigned long long)pci_resource_end(dev, SMBBAR));
Jarkko Nikulafef220d2015-02-13 15:52:25 +02001335 return err;
Jean Delvare02dd7ae2006-06-12 21:53:41 +02001336 }
1337
David Woodhouse0cd96eb2010-10-31 21:06:59 +01001338 pci_read_config_byte(priv->pci_dev, SMBHSTCFG, &temp);
1339 priv->original_hstcfg = temp;
Jean Delvare02dd7ae2006-06-12 21:53:41 +02001340 temp &= ~SMBHSTCFG_I2C_EN; /* SMBus timing */
1341 if (!(temp & SMBHSTCFG_HST_EN)) {
1342 dev_info(&dev->dev, "Enabling SMBus device\n");
1343 temp |= SMBHSTCFG_HST_EN;
1344 }
David Woodhouse0cd96eb2010-10-31 21:06:59 +01001345 pci_write_config_byte(priv->pci_dev, SMBHSTCFG, temp);
Jean Delvare02dd7ae2006-06-12 21:53:41 +02001346
Daniel Kurtz636752b2012-07-24 14:13:58 +02001347 if (temp & SMBHSTCFG_SMB_SMI_EN) {
Jean Delvare02dd7ae2006-06-12 21:53:41 +02001348 dev_dbg(&dev->dev, "SMBus using interrupt SMI#\n");
Daniel Kurtz636752b2012-07-24 14:13:58 +02001349 /* Disable SMBus interrupt feature if SMBus using SMI# */
1350 priv->features &= ~FEATURE_IRQ;
Daniel Kurtz636752b2012-07-24 14:13:58 +02001351 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07001352
Jean Delvarea0921b62008-01-27 18:14:50 +01001353 /* Clear special mode bits */
David Woodhouse0cd96eb2010-10-31 21:06:59 +01001354 if (priv->features & (FEATURE_SMBUS_PEC | FEATURE_BLOCK_BUFFER))
1355 outb_p(inb_p(SMBAUXCTL(priv)) &
1356 ~(SMBAUXCTL_CRC | SMBAUXCTL_E32B), SMBAUXCTL(priv));
Jean Delvarea0921b62008-01-27 18:14:50 +01001357
Jean Delvareb3b8df92014-11-12 10:20:40 +01001358 /* Default timeout in interrupt mode: 200 ms */
1359 priv->adapter.timeout = HZ / 5;
1360
Daniel Kurtz636752b2012-07-24 14:13:58 +02001361 if (priv->features & FEATURE_IRQ) {
Jean Delvareaeb8a3d2014-11-12 10:25:37 +01001362 u16 pcictl, pcists;
1363
1364 /* Complain if an interrupt is already pending */
1365 pci_read_config_word(priv->pci_dev, SMBPCISTS, &pcists);
1366 if (pcists & SMBPCISTS_INTS)
1367 dev_warn(&dev->dev, "An interrupt is pending!\n");
1368
1369 /* Check if interrupts have been disabled */
1370 pci_read_config_word(priv->pci_dev, SMBPCICTL, &pcictl);
1371 if (pcictl & SMBPCICTL_INTDIS) {
1372 dev_info(&dev->dev, "Interrupts are disabled\n");
1373 priv->features &= ~FEATURE_IRQ;
1374 }
1375 }
1376
1377 if (priv->features & FEATURE_IRQ) {
Daniel Kurtz636752b2012-07-24 14:13:58 +02001378 init_waitqueue_head(&priv->waitq);
1379
Jarkko Nikula1621c592015-02-13 15:52:23 +02001380 err = devm_request_irq(&dev->dev, dev->irq, i801_isr,
1381 IRQF_SHARED,
1382 dev_driver_string(&dev->dev), priv);
Daniel Kurtz636752b2012-07-24 14:13:58 +02001383 if (err) {
1384 dev_err(&dev->dev, "Failed to allocate irq %d: %d\n",
1385 dev->irq, err);
Jean Delvareae944712014-11-12 10:24:07 +01001386 priv->features &= ~FEATURE_IRQ;
Daniel Kurtz636752b2012-07-24 14:13:58 +02001387 }
1388 }
Jean Delvareae944712014-11-12 10:24:07 +01001389 dev_info(&dev->dev, "SMBus using %s\n",
1390 priv->features & FEATURE_IRQ ? "PCI interrupt" : "polling");
Daniel Kurtz636752b2012-07-24 14:13:58 +02001391
Mika Westerberg94246932015-08-06 13:46:25 +01001392 i801_add_tco(priv);
1393
David Woodhouse0cd96eb2010-10-31 21:06:59 +01001394 snprintf(priv->adapter.name, sizeof(priv->adapter.name),
1395 "SMBus I801 adapter at %04lx", priv->smba);
1396 err = i2c_add_adapter(&priv->adapter);
Jean Delvare02dd7ae2006-06-12 21:53:41 +02001397 if (err) {
1398 dev_err(&dev->dev, "Failed to add SMBus adapter\n");
Jarkko Nikulafef220d2015-02-13 15:52:25 +02001399 return err;
Jean Delvare02dd7ae2006-06-12 21:53:41 +02001400 }
Jean Delvare1561bfe2009-01-07 14:29:17 +01001401
Jean Delvaree7198fb2011-05-24 20:58:49 +02001402 i801_probe_optional_slaves(priv);
Jean Delvare3ad7ea12012-10-05 22:23:53 +02001403 /* We ignore errors - multiplexing is optional */
1404 i801_add_mux(priv);
Jean Delvare1561bfe2009-01-07 14:29:17 +01001405
David Woodhouse0cd96eb2010-10-31 21:06:59 +01001406 pci_set_drvdata(dev, priv);
Daniel Kurtz636752b2012-07-24 14:13:58 +02001407
Daniel Ritzd6fcb3b2006-06-27 18:40:54 +02001408 return 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001409}
1410
Bill Pemberton0b255e92012-11-27 15:59:38 -05001411static void i801_remove(struct pci_dev *dev)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001412{
David Woodhouse0cd96eb2010-10-31 21:06:59 +01001413 struct i801_priv *priv = pci_get_drvdata(dev);
1414
Jean Delvare3ad7ea12012-10-05 22:23:53 +02001415 i801_del_mux(priv);
David Woodhouse0cd96eb2010-10-31 21:06:59 +01001416 i2c_del_adapter(&priv->adapter);
1417 pci_write_config_byte(dev, SMBHSTCFG, priv->original_hstcfg);
Daniel Kurtz636752b2012-07-24 14:13:58 +02001418
Mika Westerberg94246932015-08-06 13:46:25 +01001419 platform_device_unregister(priv->tco_pdev);
1420
Daniel Ritzd6fcb3b2006-06-27 18:40:54 +02001421 /*
1422 * do not call pci_disable_device(dev) since it can cause hard hangs on
1423 * some systems during power-off (eg. Fujitsu-Siemens Lifebook E8010)
1424 */
Linus Torvalds1da177e2005-04-16 15:20:36 -07001425}
1426
Jean Delvarea5aaea32007-03-22 19:49:01 +01001427#ifdef CONFIG_PM
1428static int i801_suspend(struct pci_dev *dev, pm_message_t mesg)
1429{
David Woodhouse0cd96eb2010-10-31 21:06:59 +01001430 struct i801_priv *priv = pci_get_drvdata(dev);
1431
Jean Delvarea5aaea32007-03-22 19:49:01 +01001432 pci_save_state(dev);
David Woodhouse0cd96eb2010-10-31 21:06:59 +01001433 pci_write_config_byte(dev, SMBHSTCFG, priv->original_hstcfg);
Jean Delvarea5aaea32007-03-22 19:49:01 +01001434 pci_set_power_state(dev, pci_choose_state(dev, mesg));
1435 return 0;
1436}
1437
1438static int i801_resume(struct pci_dev *dev)
1439{
1440 pci_set_power_state(dev, PCI_D0);
1441 pci_restore_state(dev);
Jarkko Nikulaf85da3f2015-02-13 15:52:24 +02001442 return 0;
Jean Delvarea5aaea32007-03-22 19:49:01 +01001443}
1444#else
1445#define i801_suspend NULL
1446#define i801_resume NULL
1447#endif
1448
Linus Torvalds1da177e2005-04-16 15:20:36 -07001449static struct pci_driver i801_driver = {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001450 .name = "i801_smbus",
1451 .id_table = i801_ids,
1452 .probe = i801_probe,
Bill Pemberton0b255e92012-11-27 15:59:38 -05001453 .remove = i801_remove,
Jean Delvarea5aaea32007-03-22 19:49:01 +01001454 .suspend = i801_suspend,
1455 .resume = i801_resume,
Linus Torvalds1da177e2005-04-16 15:20:36 -07001456};
1457
1458static int __init i2c_i801_init(void)
1459{
Jean Delvare6aa14642011-05-24 20:58:49 +02001460 if (dmi_name_in_vendors("FUJITSU"))
1461 input_apanel_init();
Linus Torvalds1da177e2005-04-16 15:20:36 -07001462 return pci_register_driver(&i801_driver);
1463}
1464
1465static void __exit i2c_i801_exit(void)
1466{
1467 pci_unregister_driver(&i801_driver);
1468}
1469
Jean Delvare7c81c602014-01-29 20:40:08 +01001470MODULE_AUTHOR("Mark D. Studebaker <mdsxyz123@yahoo.com>, Jean Delvare <jdelvare@suse.de>");
Linus Torvalds1da177e2005-04-16 15:20:36 -07001471MODULE_DESCRIPTION("I801 SMBus driver");
1472MODULE_LICENSE("GPL");
1473
1474module_init(i2c_i801_init);
1475module_exit(i2c_i801_exit);