blob: 679c6c41f64b49babf8b0a7505d56a2c4093f6c7 [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
Jarkko Nikula15407792018-02-16 11:24:29 +020061 * Braswell (SOC) 0x2292 32 hard yes yes yes
james.d.ralston@intel.com3e27a842014-10-13 15:20:24 -070062 * Sunrise Point-H (PCH) 0xa123 32 hard yes yes yes
Devin Ryles3eee17992014-11-05 16:30:03 -050063 * Sunrise Point-LP (PCH) 0x9d23 32 hard yes yes yes
Mika Westerberg84d7f2e2015-10-13 15:41:39 +030064 * DNV (SOC) 0x19df 32 hard yes yes yes
Jarkko Nikuladd77f422015-10-22 17:16:58 +030065 * Broxton (SOC) 0x5ad4 32 hard yes yes yes
Alexandra Yatescdc5a312015-11-05 11:40:25 -080066 * Lewisburg (PCH) 0xa1a3 32 hard yes yes yes
67 * Lewisburg Supersku (PCH) 0xa223 32 hard yes yes yes
Andy Shevchenko31158762016-09-23 11:56:01 +030068 * Kaby Lake PCH-H (PCH) 0xa2a3 32 hard yes yes yes
Mika Westerberg9827f9e2017-02-01 19:20:59 +030069 * Gemini Lake (SOC) 0x31d4 32 hard yes yes yes
Srinivas Pandruvada09a1de02017-05-18 11:23:06 +030070 * Cannon Lake-H (PCH) 0xa323 32 hard yes yes yes
71 * Cannon Lake-LP (PCH) 0x9da3 32 hard yes yes yes
Jarkko Nikulacb09d942017-09-21 16:23:16 +030072 * Cedar Fork (PCH) 0x18df 32 hard yes yes yes
Mika Westerberg0bff2a82018-06-28 16:08:24 +030073 * Ice Lake-LP (PCH) 0x34a3 32 hard yes yes yes
Jarkko Nikula5cd1c562019-03-15 12:56:49 +020074 * Comet Lake (PCH) 0x02a3 32 hard yes yes yes
Jean Delvarece316112014-07-17 15:03:24 +020075 *
76 * Features supported by this driver:
77 * Software PEC no
78 * Hardware PEC yes
79 * Block buffer yes
80 * Block process call transaction no
81 * I2C block read transaction yes (doesn't use the block buffer)
82 * Slave mode no
Benjamin Tissoires7b0ed332016-06-24 16:39:49 +020083 * SMBus Host Notify yes
Jean Delvarece316112014-07-17 15:03:24 +020084 * Interrupt processing yes
85 *
86 * See the file Documentation/i2c/busses/i2c-i801 for details.
87 */
Linus Torvalds1da177e2005-04-16 15:20:36 -070088
Daniel Kurtz636752b2012-07-24 14:13:58 +020089#include <linux/interrupt.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070090#include <linux/module.h>
91#include <linux/pci.h>
92#include <linux/kernel.h>
93#include <linux/stddef.h>
94#include <linux/delay.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070095#include <linux/ioport.h>
96#include <linux/init.h>
97#include <linux/i2c.h>
Benjamin Tissoires7b0ed332016-06-24 16:39:49 +020098#include <linux/i2c-smbus.h>
Jean Delvare54fb4a052008-07-14 22:38:33 +020099#include <linux/acpi.h>
Jean Delvare1561bfe2009-01-07 14:29:17 +0100100#include <linux/io.h>
Hans de Goedefa5bfab2009-03-30 21:46:44 +0200101#include <linux/dmi.h>
Ben Hutchings665a96b2011-01-10 22:11:22 +0100102#include <linux/slab.h>
Daniel Kurtz636752b2012-07-24 14:13:58 +0200103#include <linux/wait.h>
Jean Delvare3ad7ea12012-10-05 22:23:53 +0200104#include <linux/err.h>
Mika Westerberg94246932015-08-06 13:46:25 +0100105#include <linux/platform_device.h>
106#include <linux/platform_data/itco_wdt.h>
Jarkko Nikulaa7401ca2016-03-10 14:12:22 +0200107#include <linux/pm_runtime.h>
Jean Delvare3ad7ea12012-10-05 22:23:53 +0200108
Javier Martinez Canillas175c7082016-07-21 12:11:01 -0400109#if IS_ENABLED(CONFIG_I2C_MUX_GPIO) && defined CONFIG_DMI
Jean Delvare3ad7ea12012-10-05 22:23:53 +0200110#include <linux/gpio.h>
Wolfram Sang62ea22c2018-04-19 22:00:08 +0200111#include <linux/platform_data/i2c-mux-gpio.h>
Jean Delvare3ad7ea12012-10-05 22:23:53 +0200112#endif
Linus Torvalds1da177e2005-04-16 15:20:36 -0700113
Linus Torvalds1da177e2005-04-16 15:20:36 -0700114/* I801 SMBus address offsets */
David Woodhouse0cd96eb2010-10-31 21:06:59 +0100115#define SMBHSTSTS(p) (0 + (p)->smba)
116#define SMBHSTCNT(p) (2 + (p)->smba)
117#define SMBHSTCMD(p) (3 + (p)->smba)
118#define SMBHSTADD(p) (4 + (p)->smba)
119#define SMBHSTDAT0(p) (5 + (p)->smba)
120#define SMBHSTDAT1(p) (6 + (p)->smba)
121#define SMBBLKDAT(p) (7 + (p)->smba)
122#define SMBPEC(p) (8 + (p)->smba) /* ICH3 and later */
123#define SMBAUXSTS(p) (12 + (p)->smba) /* ICH4 and later */
124#define SMBAUXCTL(p) (13 + (p)->smba) /* ICH4 and later */
Benjamin Tissoires7b0ed332016-06-24 16:39:49 +0200125#define SMBSLVSTS(p) (16 + (p)->smba) /* ICH3 and later */
126#define SMBSLVCMD(p) (17 + (p)->smba) /* ICH3 and later */
127#define SMBNTFDADD(p) (20 + (p)->smba) /* ICH3 and later */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700128
129/* PCI Address Constants */
Jean Delvare6dcc19d2006-06-12 21:53:02 +0200130#define SMBBAR 4
Jean Delvareaeb8a3d2014-11-12 10:25:37 +0100131#define SMBPCICTL 0x004
Daniel Kurtz636752b2012-07-24 14:13:58 +0200132#define SMBPCISTS 0x006
Linus Torvalds1da177e2005-04-16 15:20:36 -0700133#define SMBHSTCFG 0x040
Mika Westerberg94246932015-08-06 13:46:25 +0100134#define TCOBASE 0x050
135#define TCOCTL 0x054
136
137#define ACPIBASE 0x040
138#define ACPIBASE_SMI_OFF 0x030
139#define ACPICTRL 0x044
140#define ACPICTRL_EN 0x080
141
142#define SBREG_BAR 0x10
143#define SBREG_SMBCTRL 0xc6000c
Felipe Balbi851a1512018-09-03 11:24:57 +0300144#define SBREG_SMBCTRL_DNV 0xcf000c
Linus Torvalds1da177e2005-04-16 15:20:36 -0700145
Daniel Kurtz636752b2012-07-24 14:13:58 +0200146/* Host status bits for SMBPCISTS */
Benjamin Tissoiresfe9ba3e2016-10-13 14:10:37 +0200147#define SMBPCISTS_INTS BIT(3)
Daniel Kurtz636752b2012-07-24 14:13:58 +0200148
Jean Delvareaeb8a3d2014-11-12 10:25:37 +0100149/* Control bits for SMBPCICTL */
Benjamin Tissoiresfe9ba3e2016-10-13 14:10:37 +0200150#define SMBPCICTL_INTDIS BIT(10)
Jean Delvareaeb8a3d2014-11-12 10:25:37 +0100151
Linus Torvalds1da177e2005-04-16 15:20:36 -0700152/* Host configuration bits for SMBHSTCFG */
Benjamin Tissoiresfe9ba3e2016-10-13 14:10:37 +0200153#define SMBHSTCFG_HST_EN BIT(0)
154#define SMBHSTCFG_SMB_SMI_EN BIT(1)
155#define SMBHSTCFG_I2C_EN BIT(2)
156#define SMBHSTCFG_SPD_WD BIT(4)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700157
Mika Westerberg94246932015-08-06 13:46:25 +0100158/* TCO configuration bits for TCOCTL */
Benjamin Tissoiresfe9ba3e2016-10-13 14:10:37 +0200159#define TCOCTL_EN BIT(8)
Mika Westerberg94246932015-08-06 13:46:25 +0100160
Ellen Wang97d34ec2016-07-01 22:42:15 +0200161/* Auxiliary status register bits, ICH4+ only */
Benjamin Tissoiresfe9ba3e2016-10-13 14:10:37 +0200162#define SMBAUXSTS_CRCE BIT(0)
163#define SMBAUXSTS_STCO BIT(1)
Ellen Wang97d34ec2016-07-01 22:42:15 +0200164
Lucas De Marchi25985ed2011-03-30 22:57:33 -0300165/* Auxiliary control register bits, ICH4+ only */
Benjamin Tissoiresfe9ba3e2016-10-13 14:10:37 +0200166#define SMBAUXCTL_CRC BIT(0)
167#define SMBAUXCTL_E32B BIT(1)
Oleg Ryjkovca8b9e32007-07-12 14:12:31 +0200168
Linus Torvalds1da177e2005-04-16 15:20:36 -0700169/* Other settings */
Jean Delvare84c1af42012-03-26 21:47:19 +0200170#define MAX_RETRIES 400
Linus Torvalds1da177e2005-04-16 15:20:36 -0700171
172/* I801 command constants */
173#define I801_QUICK 0x00
174#define I801_BYTE 0x04
175#define I801_BYTE_DATA 0x08
176#define I801_WORD_DATA 0x0C
Jean Delvareae7b0492008-01-27 18:14:49 +0100177#define I801_PROC_CALL 0x10 /* unimplemented */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700178#define I801_BLOCK_DATA 0x14
Jean Delvare63420642008-01-27 18:14:50 +0100179#define I801_I2C_BLOCK_DATA 0x18 /* ICH5 and later */
Daniel Kurtzedbeea62012-07-24 14:13:58 +0200180
181/* I801 Host Control register bits */
Benjamin Tissoiresfe9ba3e2016-10-13 14:10:37 +0200182#define SMBHSTCNT_INTREN BIT(0)
183#define SMBHSTCNT_KILL BIT(1)
184#define SMBHSTCNT_LAST_BYTE BIT(5)
185#define SMBHSTCNT_START BIT(6)
186#define SMBHSTCNT_PEC_EN BIT(7) /* ICH3 and later */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700187
Oleg Ryjkovca8b9e32007-07-12 14:12:31 +0200188/* I801 Hosts Status register bits */
Benjamin Tissoiresfe9ba3e2016-10-13 14:10:37 +0200189#define SMBHSTSTS_BYTE_DONE BIT(7)
190#define SMBHSTSTS_INUSE_STS BIT(6)
191#define SMBHSTSTS_SMBALERT_STS BIT(5)
192#define SMBHSTSTS_FAILED BIT(4)
193#define SMBHSTSTS_BUS_ERR BIT(3)
194#define SMBHSTSTS_DEV_ERR BIT(2)
195#define SMBHSTSTS_INTR BIT(1)
196#define SMBHSTSTS_HOST_BUSY BIT(0)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700197
Benjamin Tissoires9786b1f2016-10-13 14:10:36 +0200198/* Host Notify Status register bits */
Benjamin Tissoiresfe9ba3e2016-10-13 14:10:37 +0200199#define SMBSLVSTS_HST_NTFY_STS BIT(0)
Benjamin Tissoires7b0ed332016-06-24 16:39:49 +0200200
Benjamin Tissoires9786b1f2016-10-13 14:10:36 +0200201/* Host Notify Command register bits */
Benjamin Tissoiresfe9ba3e2016-10-13 14:10:37 +0200202#define SMBSLVCMD_HST_NTFY_INTREN BIT(0)
Benjamin Tissoires7b0ed332016-06-24 16:39:49 +0200203
Daniel Kurtz70a1cc12012-07-24 14:13:58 +0200204#define STATUS_ERROR_FLAGS (SMBHSTSTS_FAILED | SMBHSTSTS_BUS_ERR | \
205 SMBHSTSTS_DEV_ERR)
206
207#define STATUS_FLAGS (SMBHSTSTS_BYTE_DONE | SMBHSTSTS_INTR | \
208 STATUS_ERROR_FLAGS)
Jean Delvarecf898dc2008-07-14 22:38:33 +0200209
Jean Delvarea6e5e2b2011-05-01 18:18:49 +0200210/* Older devices have their ID defined in <linux/pci_ids.h> */
Jean Delvarece316112014-07-17 15:03:24 +0200211#define PCI_DEVICE_ID_INTEL_BAYTRAIL_SMBUS 0x0f12
Jarkko Nikulacb09d942017-09-21 16:23:16 +0300212#define PCI_DEVICE_ID_INTEL_CDF_SMBUS 0x18df
Andy Shevchenko34b57f42016-03-09 14:14:17 +0200213#define PCI_DEVICE_ID_INTEL_DNV_SMBUS 0x19df
Jean Delvarece316112014-07-17 15:03:24 +0200214#define PCI_DEVICE_ID_INTEL_COUGARPOINT_SMBUS 0x1c22
215#define PCI_DEVICE_ID_INTEL_PATSBURG_SMBUS 0x1d22
David Woodhouse55fee8d2010-10-31 21:07:00 +0100216/* Patsburg also has three 'Integrated Device Function' SMBus controllers */
Jean Delvarece316112014-07-17 15:03:24 +0200217#define PCI_DEVICE_ID_INTEL_PATSBURG_SMBUS_IDF0 0x1d70
218#define PCI_DEVICE_ID_INTEL_PATSBURG_SMBUS_IDF1 0x1d71
219#define PCI_DEVICE_ID_INTEL_PATSBURG_SMBUS_IDF2 0x1d72
220#define PCI_DEVICE_ID_INTEL_PANTHERPOINT_SMBUS 0x1e22
221#define PCI_DEVICE_ID_INTEL_AVOTON_SMBUS 0x1f3c
Andy Shevchenko34b57f42016-03-09 14:14:17 +0200222#define PCI_DEVICE_ID_INTEL_BRASWELL_SMBUS 0x2292
Jean Delvarece316112014-07-17 15:03:24 +0200223#define PCI_DEVICE_ID_INTEL_DH89XXCC_SMBUS 0x2330
224#define PCI_DEVICE_ID_INTEL_COLETOCREEK_SMBUS 0x23b0
Mika Westerberg9827f9e2017-02-01 19:20:59 +0300225#define PCI_DEVICE_ID_INTEL_GEMINILAKE_SMBUS 0x31d4
Mika Westerberg0bff2a82018-06-28 16:08:24 +0300226#define PCI_DEVICE_ID_INTEL_ICELAKE_LP_SMBUS 0x34a3
Jean Delvarece316112014-07-17 15:03:24 +0200227#define PCI_DEVICE_ID_INTEL_5_3400_SERIES_SMBUS 0x3b30
Andy Shevchenko34b57f42016-03-09 14:14:17 +0200228#define PCI_DEVICE_ID_INTEL_BROXTON_SMBUS 0x5ad4
Jean Delvarece316112014-07-17 15:03:24 +0200229#define PCI_DEVICE_ID_INTEL_LYNXPOINT_SMBUS 0x8c22
Jean Delvareb299de82014-07-17 15:04:41 +0200230#define PCI_DEVICE_ID_INTEL_WILDCATPOINT_SMBUS 0x8ca2
Jean Delvarece316112014-07-17 15:03:24 +0200231#define PCI_DEVICE_ID_INTEL_WELLSBURG_SMBUS 0x8d22
232#define PCI_DEVICE_ID_INTEL_WELLSBURG_SMBUS_MS0 0x8d7d
233#define PCI_DEVICE_ID_INTEL_WELLSBURG_SMBUS_MS1 0x8d7e
234#define PCI_DEVICE_ID_INTEL_WELLSBURG_SMBUS_MS2 0x8d7f
235#define PCI_DEVICE_ID_INTEL_LYNXPOINT_LP_SMBUS 0x9c22
James Ralstonafc65922013-11-04 09:29:48 -0800236#define PCI_DEVICE_ID_INTEL_WILDCATPOINT_LP_SMBUS 0x9ca2
Devin Ryles3eee17992014-11-05 16:30:03 -0500237#define PCI_DEVICE_ID_INTEL_SUNRISEPOINT_LP_SMBUS 0x9d23
Srinivas Pandruvada09a1de02017-05-18 11:23:06 +0300238#define PCI_DEVICE_ID_INTEL_CANNONLAKE_LP_SMBUS 0x9da3
Andy Shevchenko34b57f42016-03-09 14:14:17 +0200239#define PCI_DEVICE_ID_INTEL_SUNRISEPOINT_H_SMBUS 0xa123
Alexandra Yatescdc5a312015-11-05 11:40:25 -0800240#define PCI_DEVICE_ID_INTEL_LEWISBURG_SMBUS 0xa1a3
241#define PCI_DEVICE_ID_INTEL_LEWISBURG_SSKU_SMBUS 0xa223
Andy Shevchenko31158762016-09-23 11:56:01 +0300242#define PCI_DEVICE_ID_INTEL_KABYLAKE_PCH_H_SMBUS 0xa2a3
Srinivas Pandruvada09a1de02017-05-18 11:23:06 +0300243#define PCI_DEVICE_ID_INTEL_CANNONLAKE_H_SMBUS 0xa323
Jarkko Nikula5cd1c562019-03-15 12:56:49 +0200244#define PCI_DEVICE_ID_INTEL_COMETLAKE_SMBUS 0x02a3
David Woodhouse55fee8d2010-10-31 21:07:00 +0100245
Jean Delvare3ad7ea12012-10-05 22:23:53 +0200246struct i801_mux_config {
247 char *gpio_chip;
248 unsigned values[3];
249 int n_values;
250 unsigned classes[3];
251 unsigned gpios[2]; /* Relative to gpio_chip->base */
252 int n_gpios;
253};
254
David Woodhouse0cd96eb2010-10-31 21:06:59 +0100255struct i801_priv {
256 struct i2c_adapter adapter;
257 unsigned long smba;
258 unsigned char original_hstcfg;
Benjamin Tissoires22e94bd2016-10-13 14:10:35 +0200259 unsigned char original_slvcmd;
David Woodhouse0cd96eb2010-10-31 21:06:59 +0100260 struct pci_dev *pci_dev;
261 unsigned int features;
Daniel Kurtz636752b2012-07-24 14:13:58 +0200262
263 /* isr processing */
264 wait_queue_head_t waitq;
265 u8 status;
Daniel Kurtzd3ff6ce2012-07-24 14:13:59 +0200266
267 /* Command state used by isr for byte-by-byte block transactions */
268 u8 cmd;
269 bool is_read;
270 int count;
271 int len;
272 u8 *data;
Jean Delvare3ad7ea12012-10-05 22:23:53 +0200273
Javier Martinez Canillas175c7082016-07-21 12:11:01 -0400274#if IS_ENABLED(CONFIG_I2C_MUX_GPIO) && defined CONFIG_DMI
Jean Delvare3ad7ea12012-10-05 22:23:53 +0200275 const struct i801_mux_config *mux_drvdata;
Jean Delvare3ad7ea12012-10-05 22:23:53 +0200276 struct platform_device *mux_pdev;
277#endif
Mika Westerberg94246932015-08-06 13:46:25 +0100278 struct platform_device *tco_pdev;
Mika Westerberga7ae8192016-06-09 16:56:28 +0300279
280 /*
281 * If set to true the host controller registers are reserved for
282 * ACPI AML use. Protected by acpi_lock.
283 */
284 bool acpi_reserved;
285 struct mutex acpi_lock;
David Woodhouse0cd96eb2010-10-31 21:06:59 +0100286};
287
Benjamin Tissoiresf91fba62016-10-13 14:10:38 +0200288#define FEATURE_SMBUS_PEC BIT(0)
289#define FEATURE_BLOCK_BUFFER BIT(1)
290#define FEATURE_BLOCK_PROC BIT(2)
291#define FEATURE_I2C_BLOCK_READ BIT(3)
292#define FEATURE_IRQ BIT(4)
293#define FEATURE_HOST_NOTIFY BIT(5)
Jean Delvaree7198fb2011-05-24 20:58:49 +0200294/* Not really a feature, but it's convenient to handle it as such */
Benjamin Tissoiresf91fba62016-10-13 14:10:38 +0200295#define FEATURE_IDF BIT(15)
296#define FEATURE_TCO BIT(16)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700297
Jean Delvareadff6872010-05-21 18:40:54 +0200298static const char *i801_feature_names[] = {
299 "SMBus PEC",
300 "Block buffer",
301 "Block process call",
302 "I2C block read",
Daniel Kurtz636752b2012-07-24 14:13:58 +0200303 "Interrupt",
Benjamin Tissoires7b0ed332016-06-24 16:39:49 +0200304 "SMBus Host Notify",
Jean Delvareadff6872010-05-21 18:40:54 +0200305};
306
307static unsigned int disable_features;
308module_param(disable_features, uint, S_IRUGO | S_IWUSR);
Jean Delvare53229342013-05-15 02:44:10 +0000309MODULE_PARM_DESC(disable_features, "Disable selected driver features:\n"
310 "\t\t 0x01 disable SMBus PEC\n"
311 "\t\t 0x02 disable the block buffer\n"
312 "\t\t 0x08 disable the I2C block read functionality\n"
Benjamin Tissoires7b0ed332016-06-24 16:39:49 +0200313 "\t\t 0x10 don't use interrupts\n"
314 "\t\t 0x20 disable SMBus Host Notify ");
Jean Delvareadff6872010-05-21 18:40:54 +0200315
Jean Delvarecf898dc2008-07-14 22:38:33 +0200316/* Make sure the SMBus host is ready to start transmitting.
317 Return 0 if it is, -EBUSY if it is not. */
David Woodhouse0cd96eb2010-10-31 21:06:59 +0100318static int i801_check_pre(struct i801_priv *priv)
Jean Delvarecf898dc2008-07-14 22:38:33 +0200319{
320 int status;
321
David Woodhouse0cd96eb2010-10-31 21:06:59 +0100322 status = inb_p(SMBHSTSTS(priv));
Jean Delvarecf898dc2008-07-14 22:38:33 +0200323 if (status & SMBHSTSTS_HOST_BUSY) {
David Woodhouse0cd96eb2010-10-31 21:06:59 +0100324 dev_err(&priv->pci_dev->dev, "SMBus is busy, can't use it!\n");
Jean Delvarecf898dc2008-07-14 22:38:33 +0200325 return -EBUSY;
326 }
327
328 status &= STATUS_FLAGS;
329 if (status) {
David Woodhouse0cd96eb2010-10-31 21:06:59 +0100330 dev_dbg(&priv->pci_dev->dev, "Clearing status flags (%02x)\n",
Jean Delvarecf898dc2008-07-14 22:38:33 +0200331 status);
David Woodhouse0cd96eb2010-10-31 21:06:59 +0100332 outb_p(status, SMBHSTSTS(priv));
333 status = inb_p(SMBHSTSTS(priv)) & STATUS_FLAGS;
Jean Delvarecf898dc2008-07-14 22:38:33 +0200334 if (status) {
David Woodhouse0cd96eb2010-10-31 21:06:59 +0100335 dev_err(&priv->pci_dev->dev,
Jean Delvarecf898dc2008-07-14 22:38:33 +0200336 "Failed clearing status flags (%02x)\n",
337 status);
338 return -EBUSY;
339 }
340 }
341
Ellen Wang97d34ec2016-07-01 22:42:15 +0200342 /*
343 * Clear CRC status if needed.
344 * During normal operation, i801_check_post() takes care
345 * of it after every operation. We do it here only in case
346 * the hardware was already in this state when the driver
347 * started.
348 */
349 if (priv->features & FEATURE_SMBUS_PEC) {
350 status = inb_p(SMBAUXSTS(priv)) & SMBAUXSTS_CRCE;
351 if (status) {
352 dev_dbg(&priv->pci_dev->dev,
353 "Clearing aux status flags (%02x)\n", status);
354 outb_p(status, SMBAUXSTS(priv));
355 status = inb_p(SMBAUXSTS(priv)) & SMBAUXSTS_CRCE;
356 if (status) {
357 dev_err(&priv->pci_dev->dev,
358 "Failed clearing aux status flags (%02x)\n",
359 status);
360 return -EBUSY;
361 }
362 }
363 }
364
Jean Delvarecf898dc2008-07-14 22:38:33 +0200365 return 0;
366}
367
Jean Delvare6cad93c2012-07-24 14:13:58 +0200368/*
369 * Convert the status register to an error code, and clear it.
370 * Note that status only contains the bits we want to clear, not the
371 * actual register value.
372 */
373static int i801_check_post(struct i801_priv *priv, int status)
Jean Delvarecf898dc2008-07-14 22:38:33 +0200374{
375 int result = 0;
376
Daniel Kurtz636752b2012-07-24 14:13:58 +0200377 /*
378 * If the SMBus is still busy, we give up
379 * Note: This timeout condition only happens when using polling
380 * transactions. For interrupt operation, NAK/timeout is indicated by
381 * DEV_ERR.
382 */
Jean Delvare6cad93c2012-07-24 14:13:58 +0200383 if (unlikely(status < 0)) {
David Woodhouse0cd96eb2010-10-31 21:06:59 +0100384 dev_err(&priv->pci_dev->dev, "Transaction timeout\n");
Jean Delvarecf898dc2008-07-14 22:38:33 +0200385 /* try to stop the current command */
David Woodhouse0cd96eb2010-10-31 21:06:59 +0100386 dev_dbg(&priv->pci_dev->dev, "Terminating the current operation\n");
387 outb_p(inb_p(SMBHSTCNT(priv)) | SMBHSTCNT_KILL,
388 SMBHSTCNT(priv));
Jean Delvare84c1af42012-03-26 21:47:19 +0200389 usleep_range(1000, 2000);
David Woodhouse0cd96eb2010-10-31 21:06:59 +0100390 outb_p(inb_p(SMBHSTCNT(priv)) & (~SMBHSTCNT_KILL),
391 SMBHSTCNT(priv));
Jean Delvarecf898dc2008-07-14 22:38:33 +0200392
393 /* Check if it worked */
David Woodhouse0cd96eb2010-10-31 21:06:59 +0100394 status = inb_p(SMBHSTSTS(priv));
Jean Delvarecf898dc2008-07-14 22:38:33 +0200395 if ((status & SMBHSTSTS_HOST_BUSY) ||
396 !(status & SMBHSTSTS_FAILED))
David Woodhouse0cd96eb2010-10-31 21:06:59 +0100397 dev_err(&priv->pci_dev->dev,
Jean Delvarecf898dc2008-07-14 22:38:33 +0200398 "Failed terminating the transaction\n");
David Woodhouse0cd96eb2010-10-31 21:06:59 +0100399 outb_p(STATUS_FLAGS, SMBHSTSTS(priv));
Jean Delvarecf898dc2008-07-14 22:38:33 +0200400 return -ETIMEDOUT;
401 }
402
403 if (status & SMBHSTSTS_FAILED) {
404 result = -EIO;
David Woodhouse0cd96eb2010-10-31 21:06:59 +0100405 dev_err(&priv->pci_dev->dev, "Transaction failed\n");
Jean Delvarecf898dc2008-07-14 22:38:33 +0200406 }
407 if (status & SMBHSTSTS_DEV_ERR) {
Ellen Wang97d34ec2016-07-01 22:42:15 +0200408 /*
409 * This may be a PEC error, check and clear it.
410 *
411 * AUXSTS is handled differently from HSTSTS.
412 * For HSTSTS, i801_isr() or i801_wait_intr()
413 * has already cleared the error bits in hardware,
414 * and we are passed a copy of the original value
415 * in "status".
416 * For AUXSTS, the hardware register is left
417 * for us to handle here.
418 * This is asymmetric, slightly iffy, but safe,
419 * since all this code is serialized and the CRCE
420 * bit is harmless as long as it's cleared before
421 * the next operation.
422 */
423 if ((priv->features & FEATURE_SMBUS_PEC) &&
424 (inb_p(SMBAUXSTS(priv)) & SMBAUXSTS_CRCE)) {
425 outb_p(SMBAUXSTS_CRCE, SMBAUXSTS(priv));
426 result = -EBADMSG;
427 dev_dbg(&priv->pci_dev->dev, "PEC error\n");
428 } else {
429 result = -ENXIO;
430 dev_dbg(&priv->pci_dev->dev, "No response\n");
431 }
Jean Delvarecf898dc2008-07-14 22:38:33 +0200432 }
433 if (status & SMBHSTSTS_BUS_ERR) {
434 result = -EAGAIN;
David Woodhouse0cd96eb2010-10-31 21:06:59 +0100435 dev_dbg(&priv->pci_dev->dev, "Lost arbitration\n");
Jean Delvarecf898dc2008-07-14 22:38:33 +0200436 }
437
Jean Delvare6cad93c2012-07-24 14:13:58 +0200438 /* Clear status flags except BYTE_DONE, to be cleared by caller */
439 outb_p(status, SMBHSTSTS(priv));
Jean Delvarecf898dc2008-07-14 22:38:33 +0200440
441 return result;
442}
443
Jean Delvare6cad93c2012-07-24 14:13:58 +0200444/* Wait for BUSY being cleared and either INTR or an error flag being set */
445static int i801_wait_intr(struct i801_priv *priv)
446{
447 int timeout = 0;
448 int status;
449
450 /* We will always wait for a fraction of a second! */
451 do {
452 usleep_range(250, 500);
453 status = inb_p(SMBHSTSTS(priv));
454 } while (((status & SMBHSTSTS_HOST_BUSY) ||
455 !(status & (STATUS_ERROR_FLAGS | SMBHSTSTS_INTR))) &&
456 (timeout++ < MAX_RETRIES));
457
458 if (timeout > MAX_RETRIES) {
459 dev_dbg(&priv->pci_dev->dev, "INTR Timeout!\n");
460 return -ETIMEDOUT;
461 }
462 return status & (STATUS_ERROR_FLAGS | SMBHSTSTS_INTR);
463}
464
465/* Wait for either BYTE_DONE or an error flag being set */
466static int i801_wait_byte_done(struct i801_priv *priv)
467{
468 int timeout = 0;
469 int status;
470
471 /* We will always wait for a fraction of a second! */
472 do {
473 usleep_range(250, 500);
474 status = inb_p(SMBHSTSTS(priv));
475 } while (!(status & (STATUS_ERROR_FLAGS | SMBHSTSTS_BYTE_DONE)) &&
476 (timeout++ < MAX_RETRIES));
477
478 if (timeout > MAX_RETRIES) {
479 dev_dbg(&priv->pci_dev->dev, "BYTE_DONE Timeout!\n");
480 return -ETIMEDOUT;
481 }
482 return status & STATUS_ERROR_FLAGS;
483}
484
David Woodhouse0cd96eb2010-10-31 21:06:59 +0100485static int i801_transaction(struct i801_priv *priv, int xact)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700486{
Jean Delvare2b738092008-07-14 22:38:32 +0200487 int status;
Jean Delvarecf898dc2008-07-14 22:38:33 +0200488 int result;
Jean Delvareb3b8df92014-11-12 10:20:40 +0100489 const struct i2c_adapter *adap = &priv->adapter;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700490
David Woodhouse0cd96eb2010-10-31 21:06:59 +0100491 result = i801_check_pre(priv);
Jean Delvarecf898dc2008-07-14 22:38:33 +0200492 if (result < 0)
493 return result;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700494
Daniel Kurtz636752b2012-07-24 14:13:58 +0200495 if (priv->features & FEATURE_IRQ) {
496 outb_p(xact | SMBHSTCNT_INTREN | SMBHSTCNT_START,
497 SMBHSTCNT(priv));
Jean Delvareb3b8df92014-11-12 10:20:40 +0100498 result = wait_event_timeout(priv->waitq,
499 (status = priv->status),
500 adap->timeout);
501 if (!result) {
502 status = -ETIMEDOUT;
503 dev_warn(&priv->pci_dev->dev,
504 "Timeout waiting for interrupt!\n");
505 }
Daniel Kurtz636752b2012-07-24 14:13:58 +0200506 priv->status = 0;
507 return i801_check_post(priv, status);
508 }
509
Oleg Ryjkov7edcb9a2007-07-12 14:12:31 +0200510 /* the current contents of SMBHSTCNT can be overwritten, since PEC,
Daniel Kurtz37af8712012-07-24 14:13:58 +0200511 * SMBSCMD are passed in xact */
Daniel Kurtzedbeea62012-07-24 14:13:58 +0200512 outb_p(xact | SMBHSTCNT_START, SMBHSTCNT(priv));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700513
Jean Delvare6cad93c2012-07-24 14:13:58 +0200514 status = i801_wait_intr(priv);
515 return i801_check_post(priv, status);
Oleg Ryjkovca8b9e32007-07-12 14:12:31 +0200516}
517
David Woodhouse0cd96eb2010-10-31 21:06:59 +0100518static int i801_block_transaction_by_block(struct i801_priv *priv,
519 union i2c_smbus_data *data,
Oleg Ryjkov7edcb9a2007-07-12 14:12:31 +0200520 char read_write, int hwpec)
521{
522 int i, len;
David Brownell97140342008-07-14 22:38:25 +0200523 int status;
Oleg Ryjkov7edcb9a2007-07-12 14:12:31 +0200524
David Woodhouse0cd96eb2010-10-31 21:06:59 +0100525 inb_p(SMBHSTCNT(priv)); /* reset the data buffer index */
Oleg Ryjkov7edcb9a2007-07-12 14:12:31 +0200526
527 /* Use 32-byte buffer to process this transaction */
528 if (read_write == I2C_SMBUS_WRITE) {
529 len = data->block[0];
David Woodhouse0cd96eb2010-10-31 21:06:59 +0100530 outb_p(len, SMBHSTDAT0(priv));
Oleg Ryjkov7edcb9a2007-07-12 14:12:31 +0200531 for (i = 0; i < len; i++)
David Woodhouse0cd96eb2010-10-31 21:06:59 +0100532 outb_p(data->block[i+1], SMBBLKDAT(priv));
Oleg Ryjkov7edcb9a2007-07-12 14:12:31 +0200533 }
534
Daniel Kurtz37af8712012-07-24 14:13:58 +0200535 status = i801_transaction(priv, I801_BLOCK_DATA |
Daniel Kurtzedbeea62012-07-24 14:13:58 +0200536 (hwpec ? SMBHSTCNT_PEC_EN : 0));
David Brownell97140342008-07-14 22:38:25 +0200537 if (status)
538 return status;
Oleg Ryjkov7edcb9a2007-07-12 14:12:31 +0200539
540 if (read_write == I2C_SMBUS_READ) {
David Woodhouse0cd96eb2010-10-31 21:06:59 +0100541 len = inb_p(SMBHSTDAT0(priv));
Oleg Ryjkov7edcb9a2007-07-12 14:12:31 +0200542 if (len < 1 || len > I2C_SMBUS_BLOCK_MAX)
David Brownell97140342008-07-14 22:38:25 +0200543 return -EPROTO;
Oleg Ryjkov7edcb9a2007-07-12 14:12:31 +0200544
545 data->block[0] = len;
546 for (i = 0; i < len; i++)
David Woodhouse0cd96eb2010-10-31 21:06:59 +0100547 data->block[i + 1] = inb_p(SMBBLKDAT(priv));
Oleg Ryjkov7edcb9a2007-07-12 14:12:31 +0200548 }
549 return 0;
550}
551
Daniel Kurtzd3ff6ce2012-07-24 14:13:59 +0200552static void i801_isr_byte_done(struct i801_priv *priv)
553{
554 if (priv->is_read) {
555 /* For SMBus block reads, length is received with first byte */
556 if (((priv->cmd & 0x1c) == I801_BLOCK_DATA) &&
557 (priv->count == 0)) {
558 priv->len = inb_p(SMBHSTDAT0(priv));
559 if (priv->len < 1 || priv->len > I2C_SMBUS_BLOCK_MAX) {
560 dev_err(&priv->pci_dev->dev,
561 "Illegal SMBus block read size %d\n",
562 priv->len);
563 /* FIXME: Recover */
564 priv->len = I2C_SMBUS_BLOCK_MAX;
565 } else {
566 dev_dbg(&priv->pci_dev->dev,
567 "SMBus block read size is %d\n",
568 priv->len);
569 }
570 priv->data[-1] = priv->len;
571 }
572
573 /* Read next byte */
574 if (priv->count < priv->len)
575 priv->data[priv->count++] = inb(SMBBLKDAT(priv));
576 else
577 dev_dbg(&priv->pci_dev->dev,
578 "Discarding extra byte on block read\n");
579
580 /* Set LAST_BYTE for last byte of read transaction */
581 if (priv->count == priv->len - 1)
582 outb_p(priv->cmd | SMBHSTCNT_LAST_BYTE,
583 SMBHSTCNT(priv));
584 } else if (priv->count < priv->len - 1) {
585 /* Write next byte, except for IRQ after last byte */
586 outb_p(priv->data[++priv->count], SMBBLKDAT(priv));
587 }
588
589 /* Clear BYTE_DONE to continue with next byte */
590 outb_p(SMBHSTSTS_BYTE_DONE, SMBHSTSTS(priv));
591}
592
Benjamin Tissoires7b0ed332016-06-24 16:39:49 +0200593static irqreturn_t i801_host_notify_isr(struct i801_priv *priv)
594{
595 unsigned short addr;
Benjamin Tissoires7b0ed332016-06-24 16:39:49 +0200596
597 addr = inb_p(SMBNTFDADD(priv)) >> 1;
Benjamin Tissoires7b0ed332016-06-24 16:39:49 +0200598
Benjamin Tissoiresc912a252016-10-13 14:10:39 +0200599 /*
600 * With the tested platforms, reading SMBNTFDDAT (22 + (p)->smba)
Benjamin Tissoires4d5538f2016-10-13 14:10:40 +0200601 * always returns 0. Our current implementation doesn't provide
602 * data, so we just ignore it.
Benjamin Tissoiresc912a252016-10-13 14:10:39 +0200603 */
Benjamin Tissoires4d5538f2016-10-13 14:10:40 +0200604 i2c_handle_smbus_host_notify(&priv->adapter, addr);
Benjamin Tissoires7b0ed332016-06-24 16:39:49 +0200605
606 /* clear Host Notify bit and return */
607 outb_p(SMBSLVSTS_HST_NTFY_STS, SMBSLVSTS(priv));
608 return IRQ_HANDLED;
609}
610
Daniel Kurtzefa3cb12012-07-24 14:13:57 +0200611/*
Benjamin Tissoires7b0ed332016-06-24 16:39:49 +0200612 * There are three kinds of interrupts:
Daniel Kurtzd3ff6ce2012-07-24 14:13:59 +0200613 *
614 * 1) i801 signals transaction completion with one of these interrupts:
615 * INTR - Success
616 * DEV_ERR - Invalid command, NAK or communication timeout
617 * BUS_ERR - SMI# transaction collision
618 * FAILED - transaction was canceled due to a KILL request
619 * When any of these occur, update ->status and wake up the waitq.
620 * ->status must be cleared before kicking off the next transaction.
621 *
622 * 2) For byte-by-byte (I2C read/write) transactions, one BYTE_DONE interrupt
623 * occurs for each byte of a byte-by-byte to prepare the next byte.
Benjamin Tissoires7b0ed332016-06-24 16:39:49 +0200624 *
625 * 3) Host Notify interrupts
Daniel Kurtz636752b2012-07-24 14:13:58 +0200626 */
627static irqreturn_t i801_isr(int irq, void *dev_id)
628{
629 struct i801_priv *priv = dev_id;
630 u16 pcists;
631 u8 status;
632
633 /* Confirm this is our interrupt */
634 pci_read_config_word(priv->pci_dev, SMBPCISTS, &pcists);
635 if (!(pcists & SMBPCISTS_INTS))
636 return IRQ_NONE;
637
Benjamin Tissoires7b0ed332016-06-24 16:39:49 +0200638 if (priv->features & FEATURE_HOST_NOTIFY) {
639 status = inb_p(SMBSLVSTS(priv));
640 if (status & SMBSLVSTS_HST_NTFY_STS)
641 return i801_host_notify_isr(priv);
642 }
643
Daniel Kurtz636752b2012-07-24 14:13:58 +0200644 status = inb_p(SMBHSTSTS(priv));
Daniel Kurtzd3ff6ce2012-07-24 14:13:59 +0200645 if (status & SMBHSTSTS_BYTE_DONE)
646 i801_isr_byte_done(priv);
647
Daniel Kurtz636752b2012-07-24 14:13:58 +0200648 /*
649 * Clear irq sources and report transaction result.
650 * ->status must be cleared before the next transaction is started.
651 */
652 status &= SMBHSTSTS_INTR | STATUS_ERROR_FLAGS;
653 if (status) {
654 outb_p(status, SMBHSTSTS(priv));
Jean Delvarea90bc5d2016-05-25 09:37:02 +0200655 priv->status = status;
Daniel Kurtz636752b2012-07-24 14:13:58 +0200656 wake_up(&priv->waitq);
657 }
658
659 return IRQ_HANDLED;
660}
661
662/*
Daniel Kurtzefa3cb12012-07-24 14:13:57 +0200663 * For "byte-by-byte" block transactions:
664 * I2C write uses cmd=I801_BLOCK_DATA, I2C_EN=1
665 * I2C read uses cmd=I801_I2C_BLOCK_DATA
666 */
David Woodhouse0cd96eb2010-10-31 21:06:59 +0100667static int i801_block_transaction_byte_by_byte(struct i801_priv *priv,
668 union i2c_smbus_data *data,
Jean Delvare63420642008-01-27 18:14:50 +0100669 char read_write, int command,
670 int hwpec)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700671{
672 int i, len;
673 int smbcmd;
Jean Delvare2b738092008-07-14 22:38:32 +0200674 int status;
Jean Delvarecf898dc2008-07-14 22:38:33 +0200675 int result;
Jean Delvareb3b8df92014-11-12 10:20:40 +0100676 const struct i2c_adapter *adap = &priv->adapter;
Jean Delvarecf898dc2008-07-14 22:38:33 +0200677
David Woodhouse0cd96eb2010-10-31 21:06:59 +0100678 result = i801_check_pre(priv);
Jean Delvarecf898dc2008-07-14 22:38:33 +0200679 if (result < 0)
680 return result;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700681
Oleg Ryjkov7edcb9a2007-07-12 14:12:31 +0200682 len = data->block[0];
Linus Torvalds1da177e2005-04-16 15:20:36 -0700683
684 if (read_write == I2C_SMBUS_WRITE) {
David Woodhouse0cd96eb2010-10-31 21:06:59 +0100685 outb_p(len, SMBHSTDAT0(priv));
686 outb_p(data->block[1], SMBBLKDAT(priv));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700687 }
688
Daniel Kurtzefa3cb12012-07-24 14:13:57 +0200689 if (command == I2C_SMBUS_I2C_BLOCK_DATA &&
690 read_write == I2C_SMBUS_READ)
691 smbcmd = I801_I2C_BLOCK_DATA;
692 else
693 smbcmd = I801_BLOCK_DATA;
694
Daniel Kurtzd3ff6ce2012-07-24 14:13:59 +0200695 if (priv->features & FEATURE_IRQ) {
696 priv->is_read = (read_write == I2C_SMBUS_READ);
697 if (len == 1 && priv->is_read)
698 smbcmd |= SMBHSTCNT_LAST_BYTE;
699 priv->cmd = smbcmd | SMBHSTCNT_INTREN;
700 priv->len = len;
701 priv->count = 0;
702 priv->data = &data->block[1];
703
704 outb_p(priv->cmd | SMBHSTCNT_START, SMBHSTCNT(priv));
Jean Delvareb3b8df92014-11-12 10:20:40 +0100705 result = wait_event_timeout(priv->waitq,
706 (status = priv->status),
707 adap->timeout);
708 if (!result) {
709 status = -ETIMEDOUT;
710 dev_warn(&priv->pci_dev->dev,
711 "Timeout waiting for interrupt!\n");
712 }
Daniel Kurtzd3ff6ce2012-07-24 14:13:59 +0200713 priv->status = 0;
714 return i801_check_post(priv, status);
715 }
716
Linus Torvalds1da177e2005-04-16 15:20:36 -0700717 for (i = 1; i <= len; i++) {
Daniel Kurtzefa3cb12012-07-24 14:13:57 +0200718 if (i == len && read_write == I2C_SMBUS_READ)
Daniel Kurtzedbeea62012-07-24 14:13:58 +0200719 smbcmd |= SMBHSTCNT_LAST_BYTE;
Daniel Kurtz37af8712012-07-24 14:13:58 +0200720 outb_p(smbcmd, SMBHSTCNT(priv));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700721
Linus Torvalds1da177e2005-04-16 15:20:36 -0700722 if (i == 1)
Daniel Kurtzedbeea62012-07-24 14:13:58 +0200723 outb_p(inb(SMBHSTCNT(priv)) | SMBHSTCNT_START,
David Woodhouse0cd96eb2010-10-31 21:06:59 +0100724 SMBHSTCNT(priv));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700725
Jean Delvare6cad93c2012-07-24 14:13:58 +0200726 status = i801_wait_byte_done(priv);
727 if (status)
728 goto exit;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700729
Jean Delvare63420642008-01-27 18:14:50 +0100730 if (i == 1 && read_write == I2C_SMBUS_READ
731 && command != I2C_SMBUS_I2C_BLOCK_DATA) {
David Woodhouse0cd96eb2010-10-31 21:06:59 +0100732 len = inb_p(SMBHSTDAT0(priv));
Jean Delvarecf898dc2008-07-14 22:38:33 +0200733 if (len < 1 || len > I2C_SMBUS_BLOCK_MAX) {
David Woodhouse0cd96eb2010-10-31 21:06:59 +0100734 dev_err(&priv->pci_dev->dev,
Jean Delvarecf898dc2008-07-14 22:38:33 +0200735 "Illegal SMBus block read size %d\n",
736 len);
737 /* Recover */
David Woodhouse0cd96eb2010-10-31 21:06:59 +0100738 while (inb_p(SMBHSTSTS(priv)) &
739 SMBHSTSTS_HOST_BUSY)
740 outb_p(SMBHSTSTS_BYTE_DONE,
741 SMBHSTSTS(priv));
742 outb_p(SMBHSTSTS_INTR, SMBHSTSTS(priv));
David Brownell97140342008-07-14 22:38:25 +0200743 return -EPROTO;
Jean Delvarecf898dc2008-07-14 22:38:33 +0200744 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700745 data->block[0] = len;
746 }
747
748 /* Retrieve/store value in SMBBLKDAT */
749 if (read_write == I2C_SMBUS_READ)
David Woodhouse0cd96eb2010-10-31 21:06:59 +0100750 data->block[i] = inb_p(SMBBLKDAT(priv));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700751 if (read_write == I2C_SMBUS_WRITE && i+1 <= len)
David Woodhouse0cd96eb2010-10-31 21:06:59 +0100752 outb_p(data->block[i+1], SMBBLKDAT(priv));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700753
Jean Delvarecf898dc2008-07-14 22:38:33 +0200754 /* signals SMBBLKDAT ready */
Jean Delvare6cad93c2012-07-24 14:13:58 +0200755 outb_p(SMBHSTSTS_BYTE_DONE, SMBHSTSTS(priv));
Oleg Ryjkov7edcb9a2007-07-12 14:12:31 +0200756 }
Jean Delvarecf898dc2008-07-14 22:38:33 +0200757
Jean Delvare6cad93c2012-07-24 14:13:58 +0200758 status = i801_wait_intr(priv);
759exit:
760 return i801_check_post(priv, status);
Oleg Ryjkov7edcb9a2007-07-12 14:12:31 +0200761}
762
David Woodhouse0cd96eb2010-10-31 21:06:59 +0100763static int i801_set_block_buffer_mode(struct i801_priv *priv)
Oleg Ryjkov7edcb9a2007-07-12 14:12:31 +0200764{
David Woodhouse0cd96eb2010-10-31 21:06:59 +0100765 outb_p(inb_p(SMBAUXCTL(priv)) | SMBAUXCTL_E32B, SMBAUXCTL(priv));
766 if ((inb_p(SMBAUXCTL(priv)) & SMBAUXCTL_E32B) == 0)
David Brownell97140342008-07-14 22:38:25 +0200767 return -EIO;
Oleg Ryjkov7edcb9a2007-07-12 14:12:31 +0200768 return 0;
769}
770
771/* Block transaction function */
David Woodhouse0cd96eb2010-10-31 21:06:59 +0100772static int i801_block_transaction(struct i801_priv *priv,
773 union i2c_smbus_data *data, char read_write,
Oleg Ryjkov7edcb9a2007-07-12 14:12:31 +0200774 int command, int hwpec)
775{
776 int result = 0;
777 unsigned char hostc;
778
779 if (command == I2C_SMBUS_I2C_BLOCK_DATA) {
780 if (read_write == I2C_SMBUS_WRITE) {
781 /* set I2C_EN bit in configuration register */
David Woodhouse0cd96eb2010-10-31 21:06:59 +0100782 pci_read_config_byte(priv->pci_dev, SMBHSTCFG, &hostc);
783 pci_write_config_byte(priv->pci_dev, SMBHSTCFG,
Oleg Ryjkov7edcb9a2007-07-12 14:12:31 +0200784 hostc | SMBHSTCFG_I2C_EN);
David Woodhouse0cd96eb2010-10-31 21:06:59 +0100785 } else if (!(priv->features & FEATURE_I2C_BLOCK_READ)) {
786 dev_err(&priv->pci_dev->dev,
Jean Delvare63420642008-01-27 18:14:50 +0100787 "I2C block read is unsupported!\n");
David Brownell97140342008-07-14 22:38:25 +0200788 return -EOPNOTSUPP;
Oleg Ryjkov7edcb9a2007-07-12 14:12:31 +0200789 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700790 }
791
Jean Delvare63420642008-01-27 18:14:50 +0100792 if (read_write == I2C_SMBUS_WRITE
793 || command == I2C_SMBUS_I2C_BLOCK_DATA) {
Oleg Ryjkov7edcb9a2007-07-12 14:12:31 +0200794 if (data->block[0] < 1)
795 data->block[0] = 1;
796 if (data->block[0] > I2C_SMBUS_BLOCK_MAX)
797 data->block[0] = I2C_SMBUS_BLOCK_MAX;
798 } else {
Jean Delvare63420642008-01-27 18:14:50 +0100799 data->block[0] = 32; /* max for SMBus block reads */
Oleg Ryjkov7edcb9a2007-07-12 14:12:31 +0200800 }
801
Jean Delvarec074c392010-03-13 20:56:53 +0100802 /* Experience has shown that the block buffer can only be used for
803 SMBus (not I2C) block transactions, even though the datasheet
804 doesn't mention this limitation. */
David Woodhouse0cd96eb2010-10-31 21:06:59 +0100805 if ((priv->features & FEATURE_BLOCK_BUFFER)
Jean Delvarec074c392010-03-13 20:56:53 +0100806 && command != I2C_SMBUS_I2C_BLOCK_DATA
David Woodhouse0cd96eb2010-10-31 21:06:59 +0100807 && i801_set_block_buffer_mode(priv) == 0)
808 result = i801_block_transaction_by_block(priv, data,
809 read_write, hwpec);
Oleg Ryjkov7edcb9a2007-07-12 14:12:31 +0200810 else
David Woodhouse0cd96eb2010-10-31 21:06:59 +0100811 result = i801_block_transaction_byte_by_byte(priv, data,
812 read_write,
Jean Delvare63420642008-01-27 18:14:50 +0100813 command, hwpec);
Oleg Ryjkov7edcb9a2007-07-12 14:12:31 +0200814
Jean Delvare63420642008-01-27 18:14:50 +0100815 if (command == I2C_SMBUS_I2C_BLOCK_DATA
816 && read_write == I2C_SMBUS_WRITE) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700817 /* restore saved configuration register value */
David Woodhouse0cd96eb2010-10-31 21:06:59 +0100818 pci_write_config_byte(priv->pci_dev, SMBHSTCFG, hostc);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700819 }
820 return result;
821}
822
David Brownell97140342008-07-14 22:38:25 +0200823/* Return negative errno on error. */
Ivo Manca3fb21c62010-05-21 18:40:55 +0200824static s32 i801_access(struct i2c_adapter *adap, u16 addr,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700825 unsigned short flags, char read_write, u8 command,
Ivo Manca3fb21c62010-05-21 18:40:55 +0200826 int size, union i2c_smbus_data *data)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700827{
Jean Delvaree8aac4a2005-10-26 21:34:42 +0200828 int hwpec;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700829 int block = 0;
Jarkko Nikulaa7401ca2016-03-10 14:12:22 +0200830 int ret = 0, xact = 0;
David Woodhouse0cd96eb2010-10-31 21:06:59 +0100831 struct i801_priv *priv = i2c_get_adapdata(adap);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700832
Mika Westerberga7ae8192016-06-09 16:56:28 +0300833 mutex_lock(&priv->acpi_lock);
834 if (priv->acpi_reserved) {
835 mutex_unlock(&priv->acpi_lock);
836 return -EBUSY;
837 }
838
Jarkko Nikulaa7401ca2016-03-10 14:12:22 +0200839 pm_runtime_get_sync(&priv->pci_dev->dev);
840
David Woodhouse0cd96eb2010-10-31 21:06:59 +0100841 hwpec = (priv->features & FEATURE_SMBUS_PEC) && (flags & I2C_CLIENT_PEC)
Jean Delvaree8aac4a2005-10-26 21:34:42 +0200842 && size != I2C_SMBUS_QUICK
843 && size != I2C_SMBUS_I2C_BLOCK_DATA;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700844
845 switch (size) {
846 case I2C_SMBUS_QUICK:
847 outb_p(((addr & 0x7f) << 1) | (read_write & 0x01),
David Woodhouse0cd96eb2010-10-31 21:06:59 +0100848 SMBHSTADD(priv));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700849 xact = I801_QUICK;
850 break;
851 case I2C_SMBUS_BYTE:
852 outb_p(((addr & 0x7f) << 1) | (read_write & 0x01),
David Woodhouse0cd96eb2010-10-31 21:06:59 +0100853 SMBHSTADD(priv));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700854 if (read_write == I2C_SMBUS_WRITE)
David Woodhouse0cd96eb2010-10-31 21:06:59 +0100855 outb_p(command, SMBHSTCMD(priv));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700856 xact = I801_BYTE;
857 break;
858 case I2C_SMBUS_BYTE_DATA:
859 outb_p(((addr & 0x7f) << 1) | (read_write & 0x01),
David Woodhouse0cd96eb2010-10-31 21:06:59 +0100860 SMBHSTADD(priv));
861 outb_p(command, SMBHSTCMD(priv));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700862 if (read_write == I2C_SMBUS_WRITE)
David Woodhouse0cd96eb2010-10-31 21:06:59 +0100863 outb_p(data->byte, SMBHSTDAT0(priv));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700864 xact = I801_BYTE_DATA;
865 break;
866 case I2C_SMBUS_WORD_DATA:
867 outb_p(((addr & 0x7f) << 1) | (read_write & 0x01),
David Woodhouse0cd96eb2010-10-31 21:06:59 +0100868 SMBHSTADD(priv));
869 outb_p(command, SMBHSTCMD(priv));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700870 if (read_write == I2C_SMBUS_WRITE) {
David Woodhouse0cd96eb2010-10-31 21:06:59 +0100871 outb_p(data->word & 0xff, SMBHSTDAT0(priv));
872 outb_p((data->word & 0xff00) >> 8, SMBHSTDAT1(priv));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700873 }
874 xact = I801_WORD_DATA;
875 break;
876 case I2C_SMBUS_BLOCK_DATA:
Linus Torvalds1da177e2005-04-16 15:20:36 -0700877 outb_p(((addr & 0x7f) << 1) | (read_write & 0x01),
David Woodhouse0cd96eb2010-10-31 21:06:59 +0100878 SMBHSTADD(priv));
879 outb_p(command, SMBHSTCMD(priv));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700880 block = 1;
881 break;
Jean Delvare63420642008-01-27 18:14:50 +0100882 case I2C_SMBUS_I2C_BLOCK_DATA:
Jean Delvareba9ad2a2016-10-11 13:13:27 +0200883 /*
884 * NB: page 240 of ICH5 datasheet shows that the R/#W
885 * bit should be cleared here, even when reading.
886 * However if SPD Write Disable is set (Lynx Point and later),
887 * the read will fail if we don't set the R/#W bit.
888 */
889 outb_p(((addr & 0x7f) << 1) |
890 ((priv->original_hstcfg & SMBHSTCFG_SPD_WD) ?
891 (read_write & 0x01) : 0),
892 SMBHSTADD(priv));
Jean Delvare63420642008-01-27 18:14:50 +0100893 if (read_write == I2C_SMBUS_READ) {
894 /* NB: page 240 of ICH5 datasheet also shows
895 * that DATA1 is the cmd field when reading */
David Woodhouse0cd96eb2010-10-31 21:06:59 +0100896 outb_p(command, SMBHSTDAT1(priv));
Jean Delvare63420642008-01-27 18:14:50 +0100897 } else
David Woodhouse0cd96eb2010-10-31 21:06:59 +0100898 outb_p(command, SMBHSTCMD(priv));
Jean Delvare63420642008-01-27 18:14:50 +0100899 block = 1;
900 break;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700901 default:
David Woodhouse0cd96eb2010-10-31 21:06:59 +0100902 dev_err(&priv->pci_dev->dev, "Unsupported transaction %d\n",
903 size);
Jarkko Nikulaa7401ca2016-03-10 14:12:22 +0200904 ret = -EOPNOTSUPP;
905 goto out;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700906 }
907
Oleg Ryjkovca8b9e32007-07-12 14:12:31 +0200908 if (hwpec) /* enable/disable hardware PEC */
David Woodhouse0cd96eb2010-10-31 21:06:59 +0100909 outb_p(inb_p(SMBAUXCTL(priv)) | SMBAUXCTL_CRC, SMBAUXCTL(priv));
Oleg Ryjkovca8b9e32007-07-12 14:12:31 +0200910 else
David Woodhouse0cd96eb2010-10-31 21:06:59 +0100911 outb_p(inb_p(SMBAUXCTL(priv)) & (~SMBAUXCTL_CRC),
912 SMBAUXCTL(priv));
Jean Delvaree8aac4a2005-10-26 21:34:42 +0200913
Ivo Manca3fb21c62010-05-21 18:40:55 +0200914 if (block)
David Woodhouse0cd96eb2010-10-31 21:06:59 +0100915 ret = i801_block_transaction(priv, data, read_write, size,
916 hwpec);
Oleg Ryjkov7edcb9a2007-07-12 14:12:31 +0200917 else
Daniel Kurtz37af8712012-07-24 14:13:58 +0200918 ret = i801_transaction(priv, xact);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700919
Jean Delvarec79cfba2006-04-20 02:43:18 -0700920 /* Some BIOSes don't like it when PEC is enabled at reboot or resume
Oleg Ryjkov7edcb9a2007-07-12 14:12:31 +0200921 time, so we forcibly disable it after every transaction. Turn off
922 E32B for the same reason. */
Jean Delvarea0921b62008-01-27 18:14:50 +0100923 if (hwpec || block)
David Woodhouse0cd96eb2010-10-31 21:06:59 +0100924 outb_p(inb_p(SMBAUXCTL(priv)) &
925 ~(SMBAUXCTL_CRC | SMBAUXCTL_E32B), SMBAUXCTL(priv));
Jean Delvarec79cfba2006-04-20 02:43:18 -0700926
Ivo Manca3fb21c62010-05-21 18:40:55 +0200927 if (block)
Jarkko Nikulaa7401ca2016-03-10 14:12:22 +0200928 goto out;
Ivo Manca3fb21c62010-05-21 18:40:55 +0200929 if (ret)
Jarkko Nikulaa7401ca2016-03-10 14:12:22 +0200930 goto out;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700931 if ((read_write == I2C_SMBUS_WRITE) || (xact == I801_QUICK))
Jarkko Nikulaa7401ca2016-03-10 14:12:22 +0200932 goto out;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700933
934 switch (xact & 0x7f) {
935 case I801_BYTE: /* Result put in SMBHSTDAT0 */
936 case I801_BYTE_DATA:
David Woodhouse0cd96eb2010-10-31 21:06:59 +0100937 data->byte = inb_p(SMBHSTDAT0(priv));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700938 break;
939 case I801_WORD_DATA:
David Woodhouse0cd96eb2010-10-31 21:06:59 +0100940 data->word = inb_p(SMBHSTDAT0(priv)) +
941 (inb_p(SMBHSTDAT1(priv)) << 8);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700942 break;
943 }
Jarkko Nikulaa7401ca2016-03-10 14:12:22 +0200944
945out:
946 pm_runtime_mark_last_busy(&priv->pci_dev->dev);
947 pm_runtime_put_autosuspend(&priv->pci_dev->dev);
Mika Westerberga7ae8192016-06-09 16:56:28 +0300948 mutex_unlock(&priv->acpi_lock);
Jarkko Nikulaa7401ca2016-03-10 14:12:22 +0200949 return ret;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700950}
951
952
953static u32 i801_func(struct i2c_adapter *adapter)
954{
David Woodhouse0cd96eb2010-10-31 21:06:59 +0100955 struct i801_priv *priv = i2c_get_adapdata(adapter);
956
Linus Torvalds1da177e2005-04-16 15:20:36 -0700957 return I2C_FUNC_SMBUS_QUICK | I2C_FUNC_SMBUS_BYTE |
Jean Delvare369f6f42008-01-27 18:14:50 +0100958 I2C_FUNC_SMBUS_BYTE_DATA | I2C_FUNC_SMBUS_WORD_DATA |
959 I2C_FUNC_SMBUS_BLOCK_DATA | I2C_FUNC_SMBUS_WRITE_I2C_BLOCK |
David Woodhouse0cd96eb2010-10-31 21:06:59 +0100960 ((priv->features & FEATURE_SMBUS_PEC) ? I2C_FUNC_SMBUS_PEC : 0) |
961 ((priv->features & FEATURE_I2C_BLOCK_READ) ?
Benjamin Tissoires7b0ed332016-06-24 16:39:49 +0200962 I2C_FUNC_SMBUS_READ_I2C_BLOCK : 0) |
963 ((priv->features & FEATURE_HOST_NOTIFY) ?
964 I2C_FUNC_SMBUS_HOST_NOTIFY : 0);
965}
966
Benjamin Tissoires4d5538f2016-10-13 14:10:40 +0200967static void i801_enable_host_notify(struct i2c_adapter *adapter)
Benjamin Tissoires7b0ed332016-06-24 16:39:49 +0200968{
969 struct i801_priv *priv = i2c_get_adapdata(adapter);
970
971 if (!(priv->features & FEATURE_HOST_NOTIFY))
Benjamin Tissoires4d5538f2016-10-13 14:10:40 +0200972 return;
Benjamin Tissoires7b0ed332016-06-24 16:39:49 +0200973
Benjamin Tissoires22e94bd2016-10-13 14:10:35 +0200974 if (!(SMBSLVCMD_HST_NTFY_INTREN & priv->original_slvcmd))
975 outb_p(SMBSLVCMD_HST_NTFY_INTREN | priv->original_slvcmd,
976 SMBSLVCMD(priv));
977
Benjamin Tissoires7b0ed332016-06-24 16:39:49 +0200978 /* clear Host Notify bit to allow a new notification */
979 outb_p(SMBSLVSTS_HST_NTFY_STS, SMBSLVSTS(priv));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700980}
981
Benjamin Tissoires22e94bd2016-10-13 14:10:35 +0200982static void i801_disable_host_notify(struct i801_priv *priv)
983{
984 if (!(priv->features & FEATURE_HOST_NOTIFY))
985 return;
986
987 outb_p(priv->original_slvcmd, SMBSLVCMD(priv));
988}
989
Jean Delvare8f9082c2006-09-03 22:39:46 +0200990static const struct i2c_algorithm smbus_algorithm = {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700991 .smbus_xfer = i801_access,
992 .functionality = i801_func,
993};
994
Jingoo Han392debf2013-12-03 08:11:20 +0900995static const struct pci_device_id i801_ids[] = {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700996 { PCI_DEVICE(PCI_VENDOR_ID_INTEL, PCI_DEVICE_ID_INTEL_82801AA_3) },
997 { PCI_DEVICE(PCI_VENDOR_ID_INTEL, PCI_DEVICE_ID_INTEL_82801AB_3) },
998 { PCI_DEVICE(PCI_VENDOR_ID_INTEL, PCI_DEVICE_ID_INTEL_82801BA_2) },
999 { PCI_DEVICE(PCI_VENDOR_ID_INTEL, PCI_DEVICE_ID_INTEL_82801CA_3) },
1000 { PCI_DEVICE(PCI_VENDOR_ID_INTEL, PCI_DEVICE_ID_INTEL_82801DB_3) },
1001 { PCI_DEVICE(PCI_VENDOR_ID_INTEL, PCI_DEVICE_ID_INTEL_82801EB_3) },
1002 { PCI_DEVICE(PCI_VENDOR_ID_INTEL, PCI_DEVICE_ID_INTEL_ESB_4) },
1003 { PCI_DEVICE(PCI_VENDOR_ID_INTEL, PCI_DEVICE_ID_INTEL_ICH6_16) },
1004 { PCI_DEVICE(PCI_VENDOR_ID_INTEL, PCI_DEVICE_ID_INTEL_ICH7_17) },
Jason Gastonb0a70b52005-04-16 15:24:45 -07001005 { PCI_DEVICE(PCI_VENDOR_ID_INTEL, PCI_DEVICE_ID_INTEL_ESB2_17) },
Jason Gaston8254fc42006-01-09 10:58:08 -08001006 { PCI_DEVICE(PCI_VENDOR_ID_INTEL, PCI_DEVICE_ID_INTEL_ICH8_5) },
Jason Gastonadbc2a12006-11-22 15:19:12 -08001007 { PCI_DEVICE(PCI_VENDOR_ID_INTEL, PCI_DEVICE_ID_INTEL_ICH9_6) },
Seth Heasleycb04e952010-10-04 13:27:14 -07001008 { PCI_DEVICE(PCI_VENDOR_ID_INTEL, PCI_DEVICE_ID_INTEL_EP80579_1) },
Gaston, Jason Dd28dc712008-02-24 20:03:42 +01001009 { PCI_DEVICE(PCI_VENDOR_ID_INTEL, PCI_DEVICE_ID_INTEL_ICH10_4) },
1010 { PCI_DEVICE(PCI_VENDOR_ID_INTEL, PCI_DEVICE_ID_INTEL_ICH10_5) },
Seth Heasleycb04e952010-10-04 13:27:14 -07001011 { PCI_DEVICE(PCI_VENDOR_ID_INTEL, PCI_DEVICE_ID_INTEL_5_3400_SERIES_SMBUS) },
1012 { PCI_DEVICE(PCI_VENDOR_ID_INTEL, PCI_DEVICE_ID_INTEL_COUGARPOINT_SMBUS) },
Seth Heasleye30d9852010-10-31 21:06:59 +01001013 { PCI_DEVICE(PCI_VENDOR_ID_INTEL, PCI_DEVICE_ID_INTEL_PATSBURG_SMBUS) },
David Woodhouse55fee8d2010-10-31 21:07:00 +01001014 { PCI_DEVICE(PCI_VENDOR_ID_INTEL, PCI_DEVICE_ID_INTEL_PATSBURG_SMBUS_IDF0) },
1015 { PCI_DEVICE(PCI_VENDOR_ID_INTEL, PCI_DEVICE_ID_INTEL_PATSBURG_SMBUS_IDF1) },
1016 { PCI_DEVICE(PCI_VENDOR_ID_INTEL, PCI_DEVICE_ID_INTEL_PATSBURG_SMBUS_IDF2) },
Seth Heasley662cda82011-03-20 14:50:53 +01001017 { PCI_DEVICE(PCI_VENDOR_ID_INTEL, PCI_DEVICE_ID_INTEL_DH89XXCC_SMBUS) },
Seth Heasley6e2a8512011-05-24 20:58:49 +02001018 { PCI_DEVICE(PCI_VENDOR_ID_INTEL, PCI_DEVICE_ID_INTEL_PANTHERPOINT_SMBUS) },
Seth Heasley062737f2012-03-26 21:47:19 +02001019 { PCI_DEVICE(PCI_VENDOR_ID_INTEL, PCI_DEVICE_ID_INTEL_LYNXPOINT_SMBUS) },
James Ralston4a8f1dd2012-09-10 10:14:02 +02001020 { PCI_DEVICE(PCI_VENDOR_ID_INTEL, PCI_DEVICE_ID_INTEL_LYNXPOINT_LP_SMBUS) },
Seth Heasleyc2db409c2013-01-30 15:25:32 +00001021 { PCI_DEVICE(PCI_VENDOR_ID_INTEL, PCI_DEVICE_ID_INTEL_AVOTON_SMBUS) },
James Ralstona3fc0ff2013-02-14 09:15:33 +00001022 { PCI_DEVICE(PCI_VENDOR_ID_INTEL, PCI_DEVICE_ID_INTEL_WELLSBURG_SMBUS) },
1023 { PCI_DEVICE(PCI_VENDOR_ID_INTEL, PCI_DEVICE_ID_INTEL_WELLSBURG_SMBUS_MS0) },
1024 { PCI_DEVICE(PCI_VENDOR_ID_INTEL, PCI_DEVICE_ID_INTEL_WELLSBURG_SMBUS_MS1) },
1025 { PCI_DEVICE(PCI_VENDOR_ID_INTEL, PCI_DEVICE_ID_INTEL_WELLSBURG_SMBUS_MS2) },
Seth Heasleyf39901c2013-06-19 16:59:57 -07001026 { PCI_DEVICE(PCI_VENDOR_ID_INTEL, PCI_DEVICE_ID_INTEL_COLETOCREEK_SMBUS) },
Mika Westerberg9827f9e2017-02-01 19:20:59 +03001027 { PCI_DEVICE(PCI_VENDOR_ID_INTEL, PCI_DEVICE_ID_INTEL_GEMINILAKE_SMBUS) },
Jean Delvareb299de82014-07-17 15:04:41 +02001028 { PCI_DEVICE(PCI_VENDOR_ID_INTEL, PCI_DEVICE_ID_INTEL_WILDCATPOINT_SMBUS) },
James Ralstonafc65922013-11-04 09:29:48 -08001029 { PCI_DEVICE(PCI_VENDOR_ID_INTEL, PCI_DEVICE_ID_INTEL_WILDCATPOINT_LP_SMBUS) },
Chew, Kean ho1b31e9b2014-03-01 00:03:56 +08001030 { PCI_DEVICE(PCI_VENDOR_ID_INTEL, PCI_DEVICE_ID_INTEL_BAYTRAIL_SMBUS) },
Alan Cox39e8e302014-08-19 17:37:28 +03001031 { PCI_DEVICE(PCI_VENDOR_ID_INTEL, PCI_DEVICE_ID_INTEL_BRASWELL_SMBUS) },
james.d.ralston@intel.com3e27a842014-10-13 15:20:24 -07001032 { PCI_DEVICE(PCI_VENDOR_ID_INTEL, PCI_DEVICE_ID_INTEL_SUNRISEPOINT_H_SMBUS) },
Devin Ryles3eee17992014-11-05 16:30:03 -05001033 { PCI_DEVICE(PCI_VENDOR_ID_INTEL, PCI_DEVICE_ID_INTEL_SUNRISEPOINT_LP_SMBUS) },
Jarkko Nikulacb09d942017-09-21 16:23:16 +03001034 { PCI_DEVICE(PCI_VENDOR_ID_INTEL, PCI_DEVICE_ID_INTEL_CDF_SMBUS) },
Mika Westerberg84d7f2e2015-10-13 15:41:39 +03001035 { PCI_DEVICE(PCI_VENDOR_ID_INTEL, PCI_DEVICE_ID_INTEL_DNV_SMBUS) },
Jarkko Nikuladd77f422015-10-22 17:16:58 +03001036 { PCI_DEVICE(PCI_VENDOR_ID_INTEL, PCI_DEVICE_ID_INTEL_BROXTON_SMBUS) },
Alexandra Yatescdc5a312015-11-05 11:40:25 -08001037 { PCI_DEVICE(PCI_VENDOR_ID_INTEL, PCI_DEVICE_ID_INTEL_LEWISBURG_SMBUS) },
1038 { PCI_DEVICE(PCI_VENDOR_ID_INTEL, PCI_DEVICE_ID_INTEL_LEWISBURG_SSKU_SMBUS) },
Andy Shevchenko31158762016-09-23 11:56:01 +03001039 { PCI_DEVICE(PCI_VENDOR_ID_INTEL, PCI_DEVICE_ID_INTEL_KABYLAKE_PCH_H_SMBUS) },
Srinivas Pandruvada09a1de02017-05-18 11:23:06 +03001040 { PCI_DEVICE(PCI_VENDOR_ID_INTEL, PCI_DEVICE_ID_INTEL_CANNONLAKE_H_SMBUS) },
1041 { PCI_DEVICE(PCI_VENDOR_ID_INTEL, PCI_DEVICE_ID_INTEL_CANNONLAKE_LP_SMBUS) },
Mika Westerberg0bff2a82018-06-28 16:08:24 +03001042 { PCI_DEVICE(PCI_VENDOR_ID_INTEL, PCI_DEVICE_ID_INTEL_ICELAKE_LP_SMBUS) },
Jarkko Nikula5cd1c562019-03-15 12:56:49 +02001043 { PCI_DEVICE(PCI_VENDOR_ID_INTEL, PCI_DEVICE_ID_INTEL_COMETLAKE_SMBUS) },
Linus Torvalds1da177e2005-04-16 15:20:36 -07001044 { 0, }
1045};
1046
Ivo Manca3fb21c62010-05-21 18:40:55 +02001047MODULE_DEVICE_TABLE(pci, i801_ids);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001048
Jean Delvare8eacfce2011-05-24 20:58:49 +02001049#if defined CONFIG_X86 && defined CONFIG_DMI
Jean Delvare1561bfe2009-01-07 14:29:17 +01001050static unsigned char apanel_addr;
1051
1052/* Scan the system ROM for the signature "FJKEYINF" */
1053static __init const void __iomem *bios_signature(const void __iomem *bios)
1054{
1055 ssize_t offset;
1056 const unsigned char signature[] = "FJKEYINF";
1057
1058 for (offset = 0; offset < 0x10000; offset += 0x10) {
1059 if (check_signature(bios + offset, signature,
1060 sizeof(signature)-1))
1061 return bios + offset;
1062 }
1063 return NULL;
1064}
1065
1066static void __init input_apanel_init(void)
1067{
1068 void __iomem *bios;
1069 const void __iomem *p;
1070
1071 bios = ioremap(0xF0000, 0x10000); /* Can't fail */
1072 p = bios_signature(bios);
1073 if (p) {
1074 /* just use the first address */
1075 apanel_addr = readb(p + 8 + 3) >> 1;
1076 }
1077 iounmap(bios);
1078}
Jean Delvare1561bfe2009-01-07 14:29:17 +01001079
Hans de Goedefa5bfab2009-03-30 21:46:44 +02001080struct dmi_onboard_device_info {
1081 const char *name;
1082 u8 type;
1083 unsigned short i2c_addr;
1084 const char *i2c_type;
1085};
1086
Bill Pemberton0b255e92012-11-27 15:59:38 -05001087static const struct dmi_onboard_device_info dmi_devices[] = {
Hans de Goedefa5bfab2009-03-30 21:46:44 +02001088 { "Syleus", DMI_DEV_TYPE_OTHER, 0x73, "fscsyl" },
1089 { "Hermes", DMI_DEV_TYPE_OTHER, 0x73, "fscher" },
1090 { "Hades", DMI_DEV_TYPE_OTHER, 0x73, "fschds" },
1091};
1092
Bill Pemberton0b255e92012-11-27 15:59:38 -05001093static void dmi_check_onboard_device(u8 type, const char *name,
1094 struct i2c_adapter *adap)
Hans de Goedefa5bfab2009-03-30 21:46:44 +02001095{
1096 int i;
1097 struct i2c_board_info info;
1098
1099 for (i = 0; i < ARRAY_SIZE(dmi_devices); i++) {
1100 /* & ~0x80, ignore enabled/disabled bit */
1101 if ((type & ~0x80) != dmi_devices[i].type)
1102 continue;
Jean Delvarefaabd472010-07-09 16:22:51 +02001103 if (strcasecmp(name, dmi_devices[i].name))
Hans de Goedefa5bfab2009-03-30 21:46:44 +02001104 continue;
1105
1106 memset(&info, 0, sizeof(struct i2c_board_info));
1107 info.addr = dmi_devices[i].i2c_addr;
1108 strlcpy(info.type, dmi_devices[i].i2c_type, I2C_NAME_SIZE);
1109 i2c_new_device(adap, &info);
1110 break;
1111 }
1112}
1113
1114/* We use our own function to check for onboard devices instead of
1115 dmi_find_device() as some buggy BIOS's have the devices we are interested
1116 in marked as disabled */
Bill Pemberton0b255e92012-11-27 15:59:38 -05001117static void dmi_check_onboard_devices(const struct dmi_header *dm, void *adap)
Hans de Goedefa5bfab2009-03-30 21:46:44 +02001118{
1119 int i, count;
1120
1121 if (dm->type != 10)
1122 return;
1123
1124 count = (dm->length - sizeof(struct dmi_header)) / 2;
1125 for (i = 0; i < count; i++) {
1126 const u8 *d = (char *)(dm + 1) + (i * 2);
1127 const char *name = ((char *) dm) + dm->length;
1128 u8 type = d[0];
1129 u8 s = d[1];
1130
1131 if (!s)
1132 continue;
1133 s--;
1134 while (s > 0 && name[0]) {
1135 name += strlen(name) + 1;
1136 s--;
1137 }
1138 if (name[0] == 0) /* Bogus string reference */
1139 continue;
1140
1141 dmi_check_onboard_device(type, name, adap);
1142 }
1143}
Hans de Goedefa5bfab2009-03-30 21:46:44 +02001144
Jean Delvaree7198fb2011-05-24 20:58:49 +02001145/* Register optional slaves */
Bill Pemberton0b255e92012-11-27 15:59:38 -05001146static void i801_probe_optional_slaves(struct i801_priv *priv)
Jean Delvaree7198fb2011-05-24 20:58:49 +02001147{
1148 /* Only register slaves on main SMBus channel */
1149 if (priv->features & FEATURE_IDF)
1150 return;
1151
Jean Delvaree7198fb2011-05-24 20:58:49 +02001152 if (apanel_addr) {
1153 struct i2c_board_info info;
1154
1155 memset(&info, 0, sizeof(struct i2c_board_info));
1156 info.addr = apanel_addr;
1157 strlcpy(info.type, "fujitsu_apanel", I2C_NAME_SIZE);
1158 i2c_new_device(&priv->adapter, &info);
1159 }
Jean Delvare8eacfce2011-05-24 20:58:49 +02001160
Jean Delvaree7198fb2011-05-24 20:58:49 +02001161 if (dmi_name_in_vendors("FUJITSU"))
1162 dmi_walk(dmi_check_onboard_devices, &priv->adapter);
Jean Delvaree7198fb2011-05-24 20:58:49 +02001163}
Jean Delvare8eacfce2011-05-24 20:58:49 +02001164#else
1165static void __init input_apanel_init(void) {}
Bill Pemberton0b255e92012-11-27 15:59:38 -05001166static void i801_probe_optional_slaves(struct i801_priv *priv) {}
Jean Delvare8eacfce2011-05-24 20:58:49 +02001167#endif /* CONFIG_X86 && CONFIG_DMI */
Jean Delvaree7198fb2011-05-24 20:58:49 +02001168
Javier Martinez Canillas175c7082016-07-21 12:11:01 -04001169#if IS_ENABLED(CONFIG_I2C_MUX_GPIO) && defined CONFIG_DMI
Jean Delvare3ad7ea12012-10-05 22:23:53 +02001170static struct i801_mux_config i801_mux_config_asus_z8_d12 = {
1171 .gpio_chip = "gpio_ich",
1172 .values = { 0x02, 0x03 },
1173 .n_values = 2,
1174 .classes = { I2C_CLASS_SPD, I2C_CLASS_SPD },
1175 .gpios = { 52, 53 },
1176 .n_gpios = 2,
1177};
1178
1179static struct i801_mux_config i801_mux_config_asus_z8_d18 = {
1180 .gpio_chip = "gpio_ich",
1181 .values = { 0x02, 0x03, 0x01 },
1182 .n_values = 3,
1183 .classes = { I2C_CLASS_SPD, I2C_CLASS_SPD, I2C_CLASS_SPD },
1184 .gpios = { 52, 53 },
1185 .n_gpios = 2,
1186};
1187
Bill Pemberton0b255e92012-11-27 15:59:38 -05001188static const struct dmi_system_id mux_dmi_table[] = {
Jean Delvare3ad7ea12012-10-05 22:23:53 +02001189 {
1190 .matches = {
1191 DMI_MATCH(DMI_BOARD_VENDOR, "ASUSTeK Computer INC."),
1192 DMI_MATCH(DMI_BOARD_NAME, "Z8NA-D6(C)"),
1193 },
1194 .driver_data = &i801_mux_config_asus_z8_d12,
1195 },
1196 {
1197 .matches = {
1198 DMI_MATCH(DMI_BOARD_VENDOR, "ASUSTeK Computer INC."),
1199 DMI_MATCH(DMI_BOARD_NAME, "Z8P(N)E-D12(X)"),
1200 },
1201 .driver_data = &i801_mux_config_asus_z8_d12,
1202 },
1203 {
1204 .matches = {
1205 DMI_MATCH(DMI_BOARD_VENDOR, "ASUSTeK Computer INC."),
1206 DMI_MATCH(DMI_BOARD_NAME, "Z8NH-D12"),
1207 },
1208 .driver_data = &i801_mux_config_asus_z8_d12,
1209 },
1210 {
1211 .matches = {
1212 DMI_MATCH(DMI_BOARD_VENDOR, "ASUSTeK Computer INC."),
1213 DMI_MATCH(DMI_BOARD_NAME, "Z8PH-D12/IFB"),
1214 },
1215 .driver_data = &i801_mux_config_asus_z8_d12,
1216 },
1217 {
1218 .matches = {
1219 DMI_MATCH(DMI_BOARD_VENDOR, "ASUSTeK Computer INC."),
1220 DMI_MATCH(DMI_BOARD_NAME, "Z8NR-D12"),
1221 },
1222 .driver_data = &i801_mux_config_asus_z8_d12,
1223 },
1224 {
1225 .matches = {
1226 DMI_MATCH(DMI_BOARD_VENDOR, "ASUSTeK Computer INC."),
1227 DMI_MATCH(DMI_BOARD_NAME, "Z8P(N)H-D12"),
1228 },
1229 .driver_data = &i801_mux_config_asus_z8_d12,
1230 },
1231 {
1232 .matches = {
1233 DMI_MATCH(DMI_BOARD_VENDOR, "ASUSTeK Computer INC."),
1234 DMI_MATCH(DMI_BOARD_NAME, "Z8PG-D18"),
1235 },
1236 .driver_data = &i801_mux_config_asus_z8_d18,
1237 },
1238 {
1239 .matches = {
1240 DMI_MATCH(DMI_BOARD_VENDOR, "ASUSTeK Computer INC."),
1241 DMI_MATCH(DMI_BOARD_NAME, "Z8PE-D18"),
1242 },
1243 .driver_data = &i801_mux_config_asus_z8_d18,
1244 },
1245 {
1246 .matches = {
1247 DMI_MATCH(DMI_BOARD_VENDOR, "ASUSTeK Computer INC."),
1248 DMI_MATCH(DMI_BOARD_NAME, "Z8PS-D12"),
1249 },
1250 .driver_data = &i801_mux_config_asus_z8_d12,
1251 },
1252 { }
1253};
1254
Jean Delvare3ad7ea12012-10-05 22:23:53 +02001255/* Setup multiplexing if needed */
Bill Pemberton0b255e92012-11-27 15:59:38 -05001256static int i801_add_mux(struct i801_priv *priv)
Jean Delvare3ad7ea12012-10-05 22:23:53 +02001257{
1258 struct device *dev = &priv->adapter.dev;
1259 const struct i801_mux_config *mux_config;
Jean Delvare3ad7ea12012-10-05 22:23:53 +02001260 struct i2c_mux_gpio_platform_data gpio_data;
Jean Delvaref82b8622012-10-05 22:23:54 +02001261 int err;
Jean Delvare3ad7ea12012-10-05 22:23:53 +02001262
1263 if (!priv->mux_drvdata)
1264 return 0;
1265 mux_config = priv->mux_drvdata;
1266
Jean Delvare3ad7ea12012-10-05 22:23:53 +02001267 /* Prepare the platform data */
1268 memset(&gpio_data, 0, sizeof(struct i2c_mux_gpio_platform_data));
1269 gpio_data.parent = priv->adapter.nr;
1270 gpio_data.values = mux_config->values;
1271 gpio_data.n_values = mux_config->n_values;
1272 gpio_data.classes = mux_config->classes;
Jean Delvaref82b8622012-10-05 22:23:54 +02001273 gpio_data.gpio_chip = mux_config->gpio_chip;
1274 gpio_data.gpios = mux_config->gpios;
Jean Delvare3ad7ea12012-10-05 22:23:53 +02001275 gpio_data.n_gpios = mux_config->n_gpios;
1276 gpio_data.idle = I2C_MUX_GPIO_NO_IDLE;
1277
1278 /* Register the mux device */
1279 priv->mux_pdev = platform_device_register_data(dev, "i2c-mux-gpio",
Jean Delvaref82b8622012-10-05 22:23:54 +02001280 PLATFORM_DEVID_AUTO, &gpio_data,
Jean Delvare3ad7ea12012-10-05 22:23:53 +02001281 sizeof(struct i2c_mux_gpio_platform_data));
1282 if (IS_ERR(priv->mux_pdev)) {
1283 err = PTR_ERR(priv->mux_pdev);
1284 priv->mux_pdev = NULL;
1285 dev_err(dev, "Failed to register i2c-mux-gpio device\n");
1286 return err;
1287 }
1288
1289 return 0;
1290}
1291
Bill Pemberton0b255e92012-11-27 15:59:38 -05001292static void i801_del_mux(struct i801_priv *priv)
Jean Delvare3ad7ea12012-10-05 22:23:53 +02001293{
1294 if (priv->mux_pdev)
1295 platform_device_unregister(priv->mux_pdev);
1296}
1297
Bill Pemberton0b255e92012-11-27 15:59:38 -05001298static unsigned int i801_get_adapter_class(struct i801_priv *priv)
Jean Delvare3ad7ea12012-10-05 22:23:53 +02001299{
1300 const struct dmi_system_id *id;
1301 const struct i801_mux_config *mux_config;
1302 unsigned int class = I2C_CLASS_HWMON | I2C_CLASS_SPD;
1303 int i;
1304
1305 id = dmi_first_match(mux_dmi_table);
1306 if (id) {
Jean Delvare28901f52012-10-28 21:37:01 +01001307 /* Remove branch classes from trunk */
Jean Delvare3ad7ea12012-10-05 22:23:53 +02001308 mux_config = id->driver_data;
1309 for (i = 0; i < mux_config->n_values; i++)
1310 class &= ~mux_config->classes[i];
1311
1312 /* Remember for later */
1313 priv->mux_drvdata = mux_config;
1314 }
1315
1316 return class;
1317}
1318#else
1319static inline int i801_add_mux(struct i801_priv *priv) { return 0; }
1320static inline void i801_del_mux(struct i801_priv *priv) { }
1321
1322static inline unsigned int i801_get_adapter_class(struct i801_priv *priv)
1323{
1324 return I2C_CLASS_HWMON | I2C_CLASS_SPD;
1325}
1326#endif
1327
Mika Westerberg94246932015-08-06 13:46:25 +01001328static const struct itco_wdt_platform_data tco_platform_data = {
1329 .name = "Intel PCH",
1330 .version = 4,
1331};
1332
1333static DEFINE_SPINLOCK(p2sb_spinlock);
1334
1335static void i801_add_tco(struct i801_priv *priv)
1336{
1337 struct pci_dev *pci_dev = priv->pci_dev;
1338 struct resource tco_res[3], *res;
1339 struct platform_device *pdev;
1340 unsigned int devfn;
1341 u32 tco_base, tco_ctl;
1342 u32 base_addr, ctrl_val;
1343 u64 base64_addr;
Qiuxu Zhuobfd44732017-08-15 00:04:50 +08001344 u8 hidden;
Mika Westerberg94246932015-08-06 13:46:25 +01001345
1346 if (!(priv->features & FEATURE_TCO))
1347 return;
1348
1349 pci_read_config_dword(pci_dev, TCOBASE, &tco_base);
1350 pci_read_config_dword(pci_dev, TCOCTL, &tco_ctl);
1351 if (!(tco_ctl & TCOCTL_EN))
1352 return;
1353
1354 memset(tco_res, 0, sizeof(tco_res));
1355
1356 res = &tco_res[ICH_RES_IO_TCO];
1357 res->start = tco_base & ~1;
1358 res->end = res->start + 32 - 1;
1359 res->flags = IORESOURCE_IO;
1360
1361 /*
1362 * Power Management registers.
1363 */
1364 devfn = PCI_DEVFN(PCI_SLOT(pci_dev->devfn), 2);
1365 pci_bus_read_config_dword(pci_dev->bus, devfn, ACPIBASE, &base_addr);
1366
1367 res = &tco_res[ICH_RES_IO_SMI];
1368 res->start = (base_addr & ~1) + ACPIBASE_SMI_OFF;
1369 res->end = res->start + 3;
1370 res->flags = IORESOURCE_IO;
1371
1372 /*
1373 * Enable the ACPI I/O space.
1374 */
1375 pci_bus_read_config_dword(pci_dev->bus, devfn, ACPICTRL, &ctrl_val);
1376 ctrl_val |= ACPICTRL_EN;
1377 pci_bus_write_config_dword(pci_dev->bus, devfn, ACPICTRL, ctrl_val);
1378
1379 /*
1380 * We must access the NO_REBOOT bit over the Primary to Sideband
1381 * bridge (P2SB). The BIOS prevents the P2SB device from being
1382 * enumerated by the PCI subsystem, so we need to unhide/hide it
1383 * to lookup the P2SB BAR.
1384 */
1385 spin_lock(&p2sb_spinlock);
1386
1387 devfn = PCI_DEVFN(PCI_SLOT(pci_dev->devfn), 1);
1388
Qiuxu Zhuobfd44732017-08-15 00:04:50 +08001389 /* Unhide the P2SB device, if it is hidden */
1390 pci_bus_read_config_byte(pci_dev->bus, devfn, 0xe1, &hidden);
1391 if (hidden)
1392 pci_bus_write_config_byte(pci_dev->bus, devfn, 0xe1, 0x0);
Mika Westerberg94246932015-08-06 13:46:25 +01001393
1394 pci_bus_read_config_dword(pci_dev->bus, devfn, SBREG_BAR, &base_addr);
1395 base64_addr = base_addr & 0xfffffff0;
1396
1397 pci_bus_read_config_dword(pci_dev->bus, devfn, SBREG_BAR + 0x4, &base_addr);
1398 base64_addr |= (u64)base_addr << 32;
1399
Qiuxu Zhuobfd44732017-08-15 00:04:50 +08001400 /* Hide the P2SB device, if it was hidden before */
1401 if (hidden)
1402 pci_bus_write_config_byte(pci_dev->bus, devfn, 0xe1, hidden);
Mika Westerberg94246932015-08-06 13:46:25 +01001403 spin_unlock(&p2sb_spinlock);
1404
1405 res = &tco_res[ICH_RES_MEM_OFF];
Felipe Balbi851a1512018-09-03 11:24:57 +03001406 if (pci_dev->device == PCI_DEVICE_ID_INTEL_DNV_SMBUS)
1407 res->start = (resource_size_t)base64_addr + SBREG_SMBCTRL_DNV;
1408 else
1409 res->start = (resource_size_t)base64_addr + SBREG_SMBCTRL;
1410
Mika Westerberg94246932015-08-06 13:46:25 +01001411 res->end = res->start + 3;
1412 res->flags = IORESOURCE_MEM;
1413
1414 pdev = platform_device_register_resndata(&pci_dev->dev, "iTCO_wdt", -1,
1415 tco_res, 3, &tco_platform_data,
1416 sizeof(tco_platform_data));
1417 if (IS_ERR(pdev)) {
1418 dev_warn(&pci_dev->dev, "failed to create iTCO device\n");
1419 return;
1420 }
1421
1422 priv->tco_pdev = pdev;
1423}
1424
Mika Westerberga7ae8192016-06-09 16:56:28 +03001425#ifdef CONFIG_ACPI
Mika Westerberg7fd6d982018-08-30 11:50:13 +03001426static bool i801_acpi_is_smbus_ioport(const struct i801_priv *priv,
1427 acpi_physical_address address)
1428{
1429 return address >= priv->smba &&
1430 address <= pci_resource_end(priv->pci_dev, SMBBAR);
1431}
1432
Mika Westerberga7ae8192016-06-09 16:56:28 +03001433static acpi_status
1434i801_acpi_io_handler(u32 function, acpi_physical_address address, u32 bits,
1435 u64 *value, void *handler_context, void *region_context)
1436{
1437 struct i801_priv *priv = handler_context;
1438 struct pci_dev *pdev = priv->pci_dev;
1439 acpi_status status;
1440
1441 /*
1442 * Once BIOS AML code touches the OpRegion we warn and inhibit any
1443 * further access from the driver itself. This device is now owned
1444 * by the system firmware.
1445 */
1446 mutex_lock(&priv->acpi_lock);
1447
Mika Westerberg7fd6d982018-08-30 11:50:13 +03001448 if (!priv->acpi_reserved && i801_acpi_is_smbus_ioport(priv, address)) {
Mika Westerberga7ae8192016-06-09 16:56:28 +03001449 priv->acpi_reserved = true;
1450
1451 dev_warn(&pdev->dev, "BIOS is accessing SMBus registers\n");
1452 dev_warn(&pdev->dev, "Driver SMBus register access inhibited\n");
1453
1454 /*
1455 * BIOS is accessing the host controller so prevent it from
1456 * suspending automatically from now on.
1457 */
1458 pm_runtime_get_sync(&pdev->dev);
1459 }
1460
1461 if ((function & ACPI_IO_MASK) == ACPI_READ)
1462 status = acpi_os_read_port(address, (u32 *)value, bits);
1463 else
1464 status = acpi_os_write_port(address, (u32)*value, bits);
1465
1466 mutex_unlock(&priv->acpi_lock);
1467
1468 return status;
1469}
1470
1471static int i801_acpi_probe(struct i801_priv *priv)
1472{
1473 struct acpi_device *adev;
1474 acpi_status status;
1475
1476 adev = ACPI_COMPANION(&priv->pci_dev->dev);
1477 if (adev) {
1478 status = acpi_install_address_space_handler(adev->handle,
1479 ACPI_ADR_SPACE_SYSTEM_IO, i801_acpi_io_handler,
1480 NULL, priv);
1481 if (ACPI_SUCCESS(status))
1482 return 0;
1483 }
1484
1485 return acpi_check_resource_conflict(&priv->pci_dev->resource[SMBBAR]);
1486}
1487
1488static void i801_acpi_remove(struct i801_priv *priv)
1489{
1490 struct acpi_device *adev;
1491
1492 adev = ACPI_COMPANION(&priv->pci_dev->dev);
1493 if (!adev)
1494 return;
1495
1496 acpi_remove_address_space_handler(adev->handle,
1497 ACPI_ADR_SPACE_SYSTEM_IO, i801_acpi_io_handler);
1498
1499 mutex_lock(&priv->acpi_lock);
1500 if (priv->acpi_reserved)
1501 pm_runtime_put(&priv->pci_dev->dev);
1502 mutex_unlock(&priv->acpi_lock);
1503}
1504#else
1505static inline int i801_acpi_probe(struct i801_priv *priv) { return 0; }
1506static inline void i801_acpi_remove(struct i801_priv *priv) { }
1507#endif
1508
Bill Pemberton0b255e92012-11-27 15:59:38 -05001509static int i801_probe(struct pci_dev *dev, const struct pci_device_id *id)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001510{
Jean Delvare02dd7ae2006-06-12 21:53:41 +02001511 unsigned char temp;
Jean Delvareadff6872010-05-21 18:40:54 +02001512 int err, i;
David Woodhouse0cd96eb2010-10-31 21:06:59 +01001513 struct i801_priv *priv;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001514
Jarkko Nikula1621c592015-02-13 15:52:23 +02001515 priv = devm_kzalloc(&dev->dev, sizeof(*priv), GFP_KERNEL);
David Woodhouse0cd96eb2010-10-31 21:06:59 +01001516 if (!priv)
1517 return -ENOMEM;
1518
1519 i2c_set_adapdata(&priv->adapter, priv);
1520 priv->adapter.owner = THIS_MODULE;
Jean Delvare3ad7ea12012-10-05 22:23:53 +02001521 priv->adapter.class = i801_get_adapter_class(priv);
David Woodhouse0cd96eb2010-10-31 21:06:59 +01001522 priv->adapter.algo = &smbus_algorithm;
Dustin Byford8eb5c872015-10-23 12:27:07 -07001523 priv->adapter.dev.parent = &dev->dev;
1524 ACPI_COMPANION_SET(&priv->adapter.dev, ACPI_COMPANION(&dev->dev));
1525 priv->adapter.retries = 3;
Mika Westerberga7ae8192016-06-09 16:56:28 +03001526 mutex_init(&priv->acpi_lock);
David Woodhouse0cd96eb2010-10-31 21:06:59 +01001527
1528 priv->pci_dev = dev;
Jean Delvare250d1bd2006-12-10 21:21:33 +01001529 switch (dev->device) {
Mika Westerberg94246932015-08-06 13:46:25 +01001530 case PCI_DEVICE_ID_INTEL_SUNRISEPOINT_H_SMBUS:
1531 case PCI_DEVICE_ID_INTEL_SUNRISEPOINT_LP_SMBUS:
Srinivas Pandruvada09a1de02017-05-18 11:23:06 +03001532 case PCI_DEVICE_ID_INTEL_CANNONLAKE_H_SMBUS:
1533 case PCI_DEVICE_ID_INTEL_CANNONLAKE_LP_SMBUS:
Alexandra Yates1a1503c2016-02-17 18:21:21 -08001534 case PCI_DEVICE_ID_INTEL_LEWISBURG_SMBUS:
1535 case PCI_DEVICE_ID_INTEL_LEWISBURG_SSKU_SMBUS:
Jarkko Nikulacb09d942017-09-21 16:23:16 +03001536 case PCI_DEVICE_ID_INTEL_CDF_SMBUS:
Mika Westerberg84d7f2e2015-10-13 15:41:39 +03001537 case PCI_DEVICE_ID_INTEL_DNV_SMBUS:
Andy Shevchenko31158762016-09-23 11:56:01 +03001538 case PCI_DEVICE_ID_INTEL_KABYLAKE_PCH_H_SMBUS:
Mika Westerberg0bff2a82018-06-28 16:08:24 +03001539 case PCI_DEVICE_ID_INTEL_ICELAKE_LP_SMBUS:
Jarkko Nikula5cd1c562019-03-15 12:56:49 +02001540 case PCI_DEVICE_ID_INTEL_COMETLAKE_SMBUS:
Mika Westerberg94246932015-08-06 13:46:25 +01001541 priv->features |= FEATURE_I2C_BLOCK_READ;
1542 priv->features |= FEATURE_IRQ;
1543 priv->features |= FEATURE_SMBUS_PEC;
1544 priv->features |= FEATURE_BLOCK_BUFFER;
Mika Westerberg1f6dbb02016-09-20 15:30:53 +03001545 /* If we have ACPI based watchdog use that instead */
1546 if (!acpi_has_watchdog())
1547 priv->features |= FEATURE_TCO;
Benjamin Tissoires7b0ed332016-06-24 16:39:49 +02001548 priv->features |= FEATURE_HOST_NOTIFY;
Mika Westerberg94246932015-08-06 13:46:25 +01001549 break;
1550
Jean Delvaree7198fb2011-05-24 20:58:49 +02001551 case PCI_DEVICE_ID_INTEL_PATSBURG_SMBUS_IDF0:
1552 case PCI_DEVICE_ID_INTEL_PATSBURG_SMBUS_IDF1:
1553 case PCI_DEVICE_ID_INTEL_PATSBURG_SMBUS_IDF2:
James Ralstona3fc0ff2013-02-14 09:15:33 +00001554 case PCI_DEVICE_ID_INTEL_WELLSBURG_SMBUS_MS0:
1555 case PCI_DEVICE_ID_INTEL_WELLSBURG_SMBUS_MS1:
1556 case PCI_DEVICE_ID_INTEL_WELLSBURG_SMBUS_MS2:
Jean Delvaree7198fb2011-05-24 20:58:49 +02001557 priv->features |= FEATURE_IDF;
1558 /* fall through */
Jean Delvaree0e8398c2010-05-21 18:40:55 +02001559 default:
David Woodhouse0cd96eb2010-10-31 21:06:59 +01001560 priv->features |= FEATURE_I2C_BLOCK_READ;
Jean Delvare6676a842012-12-16 21:11:55 +01001561 priv->features |= FEATURE_IRQ;
Jean Delvare63420642008-01-27 18:14:50 +01001562 /* fall through */
1563 case PCI_DEVICE_ID_INTEL_82801DB_3:
David Woodhouse0cd96eb2010-10-31 21:06:59 +01001564 priv->features |= FEATURE_SMBUS_PEC;
1565 priv->features |= FEATURE_BLOCK_BUFFER;
Jean Delvaree0e8398c2010-05-21 18:40:55 +02001566 /* fall through */
1567 case PCI_DEVICE_ID_INTEL_82801CA_3:
Benjamin Tissoires7b0ed332016-06-24 16:39:49 +02001568 priv->features |= FEATURE_HOST_NOTIFY;
1569 /* fall through */
Jean Delvaree0e8398c2010-05-21 18:40:55 +02001570 case PCI_DEVICE_ID_INTEL_82801BA_2:
1571 case PCI_DEVICE_ID_INTEL_82801AB_3:
1572 case PCI_DEVICE_ID_INTEL_82801AA_3:
Jean Delvare250d1bd2006-12-10 21:21:33 +01001573 break;
Jean Delvare250d1bd2006-12-10 21:21:33 +01001574 }
Jean Delvare02dd7ae2006-06-12 21:53:41 +02001575
Jean Delvareadff6872010-05-21 18:40:54 +02001576 /* Disable features on user request */
1577 for (i = 0; i < ARRAY_SIZE(i801_feature_names); i++) {
David Woodhouse0cd96eb2010-10-31 21:06:59 +01001578 if (priv->features & disable_features & (1 << i))
Jean Delvareadff6872010-05-21 18:40:54 +02001579 dev_notice(&dev->dev, "%s disabled by user\n",
1580 i801_feature_names[i]);
1581 }
David Woodhouse0cd96eb2010-10-31 21:06:59 +01001582 priv->features &= ~disable_features;
Jean Delvareadff6872010-05-21 18:40:54 +02001583
Jarkko Nikulafef220d2015-02-13 15:52:25 +02001584 err = pcim_enable_device(dev);
Jean Delvare02dd7ae2006-06-12 21:53:41 +02001585 if (err) {
1586 dev_err(&dev->dev, "Failed to enable SMBus PCI device (%d)\n",
1587 err);
Jarkko Nikulafef220d2015-02-13 15:52:25 +02001588 return err;
Jean Delvare02dd7ae2006-06-12 21:53:41 +02001589 }
Jarkko Nikulafef220d2015-02-13 15:52:25 +02001590 pcim_pin_device(dev);
Jean Delvare02dd7ae2006-06-12 21:53:41 +02001591
1592 /* Determine the address of the SMBus area */
David Woodhouse0cd96eb2010-10-31 21:06:59 +01001593 priv->smba = pci_resource_start(dev, SMBBAR);
1594 if (!priv->smba) {
Jarkko Nikula9cbbf3d2015-02-13 15:52:21 +02001595 dev_err(&dev->dev,
1596 "SMBus base address uninitialized, upgrade BIOS\n");
Jarkko Nikulafef220d2015-02-13 15:52:25 +02001597 return -ENODEV;
Jean Delvare02dd7ae2006-06-12 21:53:41 +02001598 }
1599
Mika Westerberga7ae8192016-06-09 16:56:28 +03001600 if (i801_acpi_probe(priv))
Jarkko Nikulafef220d2015-02-13 15:52:25 +02001601 return -ENODEV;
Jean Delvare54fb4a052008-07-14 22:38:33 +02001602
Jarkko Nikulafef220d2015-02-13 15:52:25 +02001603 err = pcim_iomap_regions(dev, 1 << SMBBAR,
1604 dev_driver_string(&dev->dev));
Jean Delvare02dd7ae2006-06-12 21:53:41 +02001605 if (err) {
Jarkko Nikula9cbbf3d2015-02-13 15:52:21 +02001606 dev_err(&dev->dev,
1607 "Failed to request SMBus region 0x%lx-0x%Lx\n",
1608 priv->smba,
Andrew Morton598736c2006-06-30 01:56:20 -07001609 (unsigned long long)pci_resource_end(dev, SMBBAR));
Mika Westerberga7ae8192016-06-09 16:56:28 +03001610 i801_acpi_remove(priv);
Jarkko Nikulafef220d2015-02-13 15:52:25 +02001611 return err;
Jean Delvare02dd7ae2006-06-12 21:53:41 +02001612 }
1613
David Woodhouse0cd96eb2010-10-31 21:06:59 +01001614 pci_read_config_byte(priv->pci_dev, SMBHSTCFG, &temp);
1615 priv->original_hstcfg = temp;
Jean Delvare02dd7ae2006-06-12 21:53:41 +02001616 temp &= ~SMBHSTCFG_I2C_EN; /* SMBus timing */
1617 if (!(temp & SMBHSTCFG_HST_EN)) {
1618 dev_info(&dev->dev, "Enabling SMBus device\n");
1619 temp |= SMBHSTCFG_HST_EN;
1620 }
David Woodhouse0cd96eb2010-10-31 21:06:59 +01001621 pci_write_config_byte(priv->pci_dev, SMBHSTCFG, temp);
Jean Delvare02dd7ae2006-06-12 21:53:41 +02001622
Daniel Kurtz636752b2012-07-24 14:13:58 +02001623 if (temp & SMBHSTCFG_SMB_SMI_EN) {
Jean Delvare02dd7ae2006-06-12 21:53:41 +02001624 dev_dbg(&dev->dev, "SMBus using interrupt SMI#\n");
Daniel Kurtz636752b2012-07-24 14:13:58 +02001625 /* Disable SMBus interrupt feature if SMBus using SMI# */
1626 priv->features &= ~FEATURE_IRQ;
Daniel Kurtz636752b2012-07-24 14:13:58 +02001627 }
Jean Delvareba9ad2a2016-10-11 13:13:27 +02001628 if (temp & SMBHSTCFG_SPD_WD)
1629 dev_info(&dev->dev, "SPD Write Disable is set\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -07001630
Jean Delvarea0921b62008-01-27 18:14:50 +01001631 /* Clear special mode bits */
David Woodhouse0cd96eb2010-10-31 21:06:59 +01001632 if (priv->features & (FEATURE_SMBUS_PEC | FEATURE_BLOCK_BUFFER))
1633 outb_p(inb_p(SMBAUXCTL(priv)) &
1634 ~(SMBAUXCTL_CRC | SMBAUXCTL_E32B), SMBAUXCTL(priv));
Jean Delvarea0921b62008-01-27 18:14:50 +01001635
Jean Delvarea086bb82018-04-11 18:03:31 +02001636 /* Remember original Host Notify setting */
1637 if (priv->features & FEATURE_HOST_NOTIFY)
1638 priv->original_slvcmd = inb_p(SMBSLVCMD(priv));
1639
Jean Delvareb3b8df92014-11-12 10:20:40 +01001640 /* Default timeout in interrupt mode: 200 ms */
1641 priv->adapter.timeout = HZ / 5;
1642
Hans de Goede6e0c9502017-11-22 12:28:17 +01001643 if (dev->irq == IRQ_NOTCONNECTED)
1644 priv->features &= ~FEATURE_IRQ;
1645
Daniel Kurtz636752b2012-07-24 14:13:58 +02001646 if (priv->features & FEATURE_IRQ) {
Jean Delvareaeb8a3d2014-11-12 10:25:37 +01001647 u16 pcictl, pcists;
1648
1649 /* Complain if an interrupt is already pending */
1650 pci_read_config_word(priv->pci_dev, SMBPCISTS, &pcists);
1651 if (pcists & SMBPCISTS_INTS)
1652 dev_warn(&dev->dev, "An interrupt is pending!\n");
1653
1654 /* Check if interrupts have been disabled */
1655 pci_read_config_word(priv->pci_dev, SMBPCICTL, &pcictl);
1656 if (pcictl & SMBPCICTL_INTDIS) {
1657 dev_info(&dev->dev, "Interrupts are disabled\n");
1658 priv->features &= ~FEATURE_IRQ;
1659 }
1660 }
1661
1662 if (priv->features & FEATURE_IRQ) {
Daniel Kurtz636752b2012-07-24 14:13:58 +02001663 init_waitqueue_head(&priv->waitq);
1664
Jarkko Nikula1621c592015-02-13 15:52:23 +02001665 err = devm_request_irq(&dev->dev, dev->irq, i801_isr,
1666 IRQF_SHARED,
1667 dev_driver_string(&dev->dev), priv);
Daniel Kurtz636752b2012-07-24 14:13:58 +02001668 if (err) {
1669 dev_err(&dev->dev, "Failed to allocate irq %d: %d\n",
1670 dev->irq, err);
Jean Delvareae944712014-11-12 10:24:07 +01001671 priv->features &= ~FEATURE_IRQ;
Daniel Kurtz636752b2012-07-24 14:13:58 +02001672 }
1673 }
Jean Delvareae944712014-11-12 10:24:07 +01001674 dev_info(&dev->dev, "SMBus using %s\n",
1675 priv->features & FEATURE_IRQ ? "PCI interrupt" : "polling");
Daniel Kurtz636752b2012-07-24 14:13:58 +02001676
Mika Westerberg94246932015-08-06 13:46:25 +01001677 i801_add_tco(priv);
1678
David Woodhouse0cd96eb2010-10-31 21:06:59 +01001679 snprintf(priv->adapter.name, sizeof(priv->adapter.name),
1680 "SMBus I801 adapter at %04lx", priv->smba);
1681 err = i2c_add_adapter(&priv->adapter);
Jean Delvare02dd7ae2006-06-12 21:53:41 +02001682 if (err) {
Mika Westerberga7ae8192016-06-09 16:56:28 +03001683 i801_acpi_remove(priv);
Jarkko Nikulafef220d2015-02-13 15:52:25 +02001684 return err;
Jean Delvare02dd7ae2006-06-12 21:53:41 +02001685 }
Jean Delvare1561bfe2009-01-07 14:29:17 +01001686
Benjamin Tissoires4d5538f2016-10-13 14:10:40 +02001687 i801_enable_host_notify(&priv->adapter);
Benjamin Tissoires7b0ed332016-06-24 16:39:49 +02001688
Jean Delvaree7198fb2011-05-24 20:58:49 +02001689 i801_probe_optional_slaves(priv);
Jean Delvare3ad7ea12012-10-05 22:23:53 +02001690 /* We ignore errors - multiplexing is optional */
1691 i801_add_mux(priv);
Jean Delvare1561bfe2009-01-07 14:29:17 +01001692
David Woodhouse0cd96eb2010-10-31 21:06:59 +01001693 pci_set_drvdata(dev, priv);
Daniel Kurtz636752b2012-07-24 14:13:58 +02001694
Jarkko Nikulaa7401ca2016-03-10 14:12:22 +02001695 pm_runtime_set_autosuspend_delay(&dev->dev, 1000);
1696 pm_runtime_use_autosuspend(&dev->dev);
1697 pm_runtime_put_autosuspend(&dev->dev);
1698 pm_runtime_allow(&dev->dev);
1699
Daniel Ritzd6fcb3b2006-06-27 18:40:54 +02001700 return 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001701}
1702
Bill Pemberton0b255e92012-11-27 15:59:38 -05001703static void i801_remove(struct pci_dev *dev)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001704{
David Woodhouse0cd96eb2010-10-31 21:06:59 +01001705 struct i801_priv *priv = pci_get_drvdata(dev);
1706
Jarkko Nikulaa7401ca2016-03-10 14:12:22 +02001707 pm_runtime_forbid(&dev->dev);
1708 pm_runtime_get_noresume(&dev->dev);
1709
Benjamin Tissoires22e94bd2016-10-13 14:10:35 +02001710 i801_disable_host_notify(priv);
Jean Delvare3ad7ea12012-10-05 22:23:53 +02001711 i801_del_mux(priv);
David Woodhouse0cd96eb2010-10-31 21:06:59 +01001712 i2c_del_adapter(&priv->adapter);
Mika Westerberga7ae8192016-06-09 16:56:28 +03001713 i801_acpi_remove(priv);
David Woodhouse0cd96eb2010-10-31 21:06:59 +01001714 pci_write_config_byte(dev, SMBHSTCFG, priv->original_hstcfg);
Daniel Kurtz636752b2012-07-24 14:13:58 +02001715
Mika Westerberg94246932015-08-06 13:46:25 +01001716 platform_device_unregister(priv->tco_pdev);
1717
Daniel Ritzd6fcb3b2006-06-27 18:40:54 +02001718 /*
1719 * do not call pci_disable_device(dev) since it can cause hard hangs on
1720 * some systems during power-off (eg. Fujitsu-Siemens Lifebook E8010)
1721 */
Linus Torvalds1da177e2005-04-16 15:20:36 -07001722}
1723
Jean Delvaref7f6d912018-04-11 18:05:34 +02001724static void i801_shutdown(struct pci_dev *dev)
1725{
1726 struct i801_priv *priv = pci_get_drvdata(dev);
1727
1728 /* Restore config registers to avoid hard hang on some systems */
1729 i801_disable_host_notify(priv);
1730 pci_write_config_byte(dev, SMBHSTCFG, priv->original_hstcfg);
1731}
1732
Anders Roxell4b2f9bd52018-05-14 11:33:26 +02001733#ifdef CONFIG_PM_SLEEP
Jarkko Nikula2ee73c42016-03-10 14:12:21 +02001734static int i801_suspend(struct device *dev)
Jean Delvarea5aaea32007-03-22 19:49:01 +01001735{
Jarkko Nikula2ee73c42016-03-10 14:12:21 +02001736 struct pci_dev *pci_dev = to_pci_dev(dev);
1737 struct i801_priv *priv = pci_get_drvdata(pci_dev);
David Woodhouse0cd96eb2010-10-31 21:06:59 +01001738
Jarkko Nikula2ee73c42016-03-10 14:12:21 +02001739 pci_write_config_byte(pci_dev, SMBHSTCFG, priv->original_hstcfg);
Jean Delvarea5aaea32007-03-22 19:49:01 +01001740 return 0;
1741}
1742
Jarkko Nikula2ee73c42016-03-10 14:12:21 +02001743static int i801_resume(struct device *dev)
Jean Delvarea5aaea32007-03-22 19:49:01 +01001744{
Benjamin Tissoires7b0ed332016-06-24 16:39:49 +02001745 struct pci_dev *pci_dev = to_pci_dev(dev);
1746 struct i801_priv *priv = pci_get_drvdata(pci_dev);
Benjamin Tissoires7b0ed332016-06-24 16:39:49 +02001747
Benjamin Tissoires4d5538f2016-10-13 14:10:40 +02001748 i801_enable_host_notify(&priv->adapter);
Benjamin Tissoires7b0ed332016-06-24 16:39:49 +02001749
Jarkko Nikulaf85da3f2015-02-13 15:52:24 +02001750 return 0;
Jean Delvarea5aaea32007-03-22 19:49:01 +01001751}
Jean Delvarea5aaea32007-03-22 19:49:01 +01001752#endif
1753
Jean Delvarea9c80882018-04-25 11:53:40 +02001754static SIMPLE_DEV_PM_OPS(i801_pm_ops, i801_suspend, i801_resume);
Jarkko Nikula2ee73c42016-03-10 14:12:21 +02001755
Linus Torvalds1da177e2005-04-16 15:20:36 -07001756static struct pci_driver i801_driver = {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001757 .name = "i801_smbus",
1758 .id_table = i801_ids,
1759 .probe = i801_probe,
Bill Pemberton0b255e92012-11-27 15:59:38 -05001760 .remove = i801_remove,
Jean Delvaref7f6d912018-04-11 18:05:34 +02001761 .shutdown = i801_shutdown,
Jarkko Nikula2ee73c42016-03-10 14:12:21 +02001762 .driver = {
1763 .pm = &i801_pm_ops,
1764 },
Linus Torvalds1da177e2005-04-16 15:20:36 -07001765};
1766
1767static int __init i2c_i801_init(void)
1768{
Jean Delvare6aa14642011-05-24 20:58:49 +02001769 if (dmi_name_in_vendors("FUJITSU"))
1770 input_apanel_init();
Linus Torvalds1da177e2005-04-16 15:20:36 -07001771 return pci_register_driver(&i801_driver);
1772}
1773
1774static void __exit i2c_i801_exit(void)
1775{
1776 pci_unregister_driver(&i801_driver);
1777}
1778
Jean Delvare7c81c60f2014-01-29 20:40:08 +01001779MODULE_AUTHOR("Mark D. Studebaker <mdsxyz123@yahoo.com>, Jean Delvare <jdelvare@suse.de>");
Linus Torvalds1da177e2005-04-16 15:20:36 -07001780MODULE_DESCRIPTION("I801 SMBus driver");
1781MODULE_LICENSE("GPL");
1782
1783module_init(i2c_i801_init);
1784module_exit(i2c_i801_exit);