2 Copyright (c) 1998 - 2002 Frodo Looijaard <frodol@dds.nl>,
3 Philip Edelbrock <phil@netroedge.com>, and Mark D. Studebaker
5 Copyright (C) 2007, 2008 Jean Delvare <khali@linux-fr.org>
7 This program is free software; you can redistribute it and/or modify
8 it under the terms of the GNU General Public License as published by
9 the Free Software Foundation; either version 2 of the License, or
10 (at your option) any later version.
12 This program is distributed in the hope that it will be useful,
13 but WITHOUT ANY WARRANTY; without even the implied warranty of
14 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 GNU General Public License for more details.
17 You should have received a copy of the GNU General Public License
18 along with this program; if not, write to the Free Software
19 Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
23 Supports the following Intel I/O Controller Hubs (ICH):
26 region SMBus Block proc. block
27 Chip name PCI ID size PEC buffer call read
28 ----------------------------------------------------------------------
29 82801AA (ICH) 0x2413 16 no no no no
30 82801AB (ICH0) 0x2423 16 no no no no
31 82801BA (ICH2) 0x2443 16 no no no no
32 82801CA (ICH3) 0x2483 32 soft no no no
33 82801DB (ICH4) 0x24c3 32 hard yes no no
34 82801E (ICH5) 0x24d3 32 hard yes yes yes
35 6300ESB 0x25a4 32 hard yes yes yes
36 82801F (ICH6) 0x266a 32 hard yes yes yes
37 6310ESB/6320ESB 0x269b 32 hard yes yes yes
38 82801G (ICH7) 0x27da 32 hard yes yes yes
39 82801H (ICH8) 0x283e 32 hard yes yes yes
40 82801I (ICH9) 0x2930 32 hard yes yes yes
41 Tolapai 0x5032 32 hard yes yes yes
42 ICH10 0x3a30 32 hard yes yes yes
43 ICH10 0x3a60 32 hard yes yes yes
45 Features supported by this driver:
49 Block process call transaction no
50 I2C block read transaction yes (doesn't use the block buffer)
52 See the file Documentation/i2c/busses/i2c-i801 for details.
55 /* Note: we assume there can only be one I801, with one SMBus interface */
57 #include <linux/module.h>
58 #include <linux/pci.h>
59 #include <linux/kernel.h>
60 #include <linux/stddef.h>
61 #include <linux/delay.h>
62 #include <linux/ioport.h>
63 #include <linux/init.h>
64 #include <linux/i2c.h>
65 #include <linux/acpi.h>
68 /* I801 SMBus address offsets */
69 #define SMBHSTSTS (0 + i801_smba)
70 #define SMBHSTCNT (2 + i801_smba)
71 #define SMBHSTCMD (3 + i801_smba)
72 #define SMBHSTADD (4 + i801_smba)
73 #define SMBHSTDAT0 (5 + i801_smba)
74 #define SMBHSTDAT1 (6 + i801_smba)
75 #define SMBBLKDAT (7 + i801_smba)
76 #define SMBPEC (8 + i801_smba) /* ICH3 and later */
77 #define SMBAUXSTS (12 + i801_smba) /* ICH4 and later */
78 #define SMBAUXCTL (13 + i801_smba) /* ICH4 and later */
80 /* PCI Address Constants */
82 #define SMBHSTCFG 0x040
84 /* Host configuration bits for SMBHSTCFG */
85 #define SMBHSTCFG_HST_EN 1
86 #define SMBHSTCFG_SMB_SMI_EN 2
87 #define SMBHSTCFG_I2C_EN 4
89 /* Auxillary control register bits, ICH4+ only */
90 #define SMBAUXCTL_CRC 1
91 #define SMBAUXCTL_E32B 2
93 /* kill bit for SMBHSTCNT */
94 #define SMBHSTCNT_KILL 2
97 #define MAX_TIMEOUT 100
98 #define ENABLE_INT9 0 /* set to 0x01 to enable - untested */
100 /* I801 command constants */
101 #define I801_QUICK 0x00
102 #define I801_BYTE 0x04
103 #define I801_BYTE_DATA 0x08
104 #define I801_WORD_DATA 0x0C
105 #define I801_PROC_CALL 0x10 /* unimplemented */
106 #define I801_BLOCK_DATA 0x14
107 #define I801_I2C_BLOCK_DATA 0x18 /* ICH5 and later */
108 #define I801_BLOCK_LAST 0x34
109 #define I801_I2C_BLOCK_LAST 0x38 /* ICH5 and later */
110 #define I801_START 0x40
111 #define I801_PEC_EN 0x80 /* ICH3 and later */
113 /* I801 Hosts Status register bits */
114 #define SMBHSTSTS_BYTE_DONE 0x80
115 #define SMBHSTSTS_INUSE_STS 0x40
116 #define SMBHSTSTS_SMBALERT_STS 0x20
117 #define SMBHSTSTS_FAILED 0x10
118 #define SMBHSTSTS_BUS_ERR 0x08
119 #define SMBHSTSTS_DEV_ERR 0x04
120 #define SMBHSTSTS_INTR 0x02
121 #define SMBHSTSTS_HOST_BUSY 0x01
123 #define STATUS_FLAGS (SMBHSTSTS_BYTE_DONE | SMBHSTSTS_FAILED | \
124 SMBHSTSTS_BUS_ERR | SMBHSTSTS_DEV_ERR | \
127 static unsigned long i801_smba
;
128 static unsigned char i801_original_hstcfg
;
129 static struct pci_driver i801_driver
;
130 static struct pci_dev
*I801_dev
;
132 #define FEATURE_SMBUS_PEC (1 << 0)
133 #define FEATURE_BLOCK_BUFFER (1 << 1)
134 #define FEATURE_BLOCK_PROC (1 << 2)
135 #define FEATURE_I2C_BLOCK_READ (1 << 3)
136 static unsigned int i801_features
;
138 /* Make sure the SMBus host is ready to start transmitting.
139 Return 0 if it is, -EBUSY if it is not. */
140 static int i801_check_pre(void)
144 status
= inb_p(SMBHSTSTS
);
145 if (status
& SMBHSTSTS_HOST_BUSY
) {
146 dev_err(&I801_dev
->dev
, "SMBus is busy, can't use it!\n");
150 status
&= STATUS_FLAGS
;
152 dev_dbg(&I801_dev
->dev
, "Clearing status flags (%02x)\n",
154 outb_p(status
, SMBHSTSTS
);
155 status
= inb_p(SMBHSTSTS
) & STATUS_FLAGS
;
157 dev_err(&I801_dev
->dev
,
158 "Failed clearing status flags (%02x)\n",
167 /* Convert the status register to an error code, and clear it. */
168 static int i801_check_post(int status
, int timeout
)
172 /* If the SMBus is still busy, we give up */
174 dev_err(&I801_dev
->dev
, "Transaction timeout\n");
175 /* try to stop the current command */
176 dev_dbg(&I801_dev
->dev
, "Terminating the current operation\n");
177 outb_p(inb_p(SMBHSTCNT
) | SMBHSTCNT_KILL
, SMBHSTCNT
);
179 outb_p(inb_p(SMBHSTCNT
) & (~SMBHSTCNT_KILL
), SMBHSTCNT
);
181 /* Check if it worked */
182 status
= inb_p(SMBHSTSTS
);
183 if ((status
& SMBHSTSTS_HOST_BUSY
) ||
184 !(status
& SMBHSTSTS_FAILED
))
185 dev_err(&I801_dev
->dev
,
186 "Failed terminating the transaction\n");
187 outb_p(STATUS_FLAGS
, SMBHSTSTS
);
191 if (status
& SMBHSTSTS_FAILED
) {
193 dev_err(&I801_dev
->dev
, "Transaction failed\n");
195 if (status
& SMBHSTSTS_DEV_ERR
) {
197 dev_dbg(&I801_dev
->dev
, "No response\n");
199 if (status
& SMBHSTSTS_BUS_ERR
) {
201 dev_dbg(&I801_dev
->dev
, "Lost arbitration\n");
205 /* Clear error flags */
206 outb_p(status
& STATUS_FLAGS
, SMBHSTSTS
);
207 status
= inb_p(SMBHSTSTS
) & STATUS_FLAGS
;
209 dev_warn(&I801_dev
->dev
, "Failed clearing status "
210 "flags at end of transaction (%02x)\n",
218 static int i801_transaction(int xact
)
224 result
= i801_check_pre();
228 /* the current contents of SMBHSTCNT can be overwritten, since PEC,
229 * INTREN, SMBSCMD are passed in xact */
230 outb_p(xact
| I801_START
, SMBHSTCNT
);
232 /* We will always wait for a fraction of a second! */
235 status
= inb_p(SMBHSTSTS
);
236 } while ((status
& SMBHSTSTS_HOST_BUSY
) && (timeout
++ < MAX_TIMEOUT
));
238 result
= i801_check_post(status
, timeout
>= MAX_TIMEOUT
);
242 outb_p(SMBHSTSTS_INTR
, SMBHSTSTS
);
246 /* wait for INTR bit as advised by Intel */
247 static void i801_wait_hwpec(void)
254 status
= inb_p(SMBHSTSTS
);
255 } while ((!(status
& SMBHSTSTS_INTR
))
256 && (timeout
++ < MAX_TIMEOUT
));
258 if (timeout
>= MAX_TIMEOUT
) {
259 dev_dbg(&I801_dev
->dev
, "PEC Timeout!\n");
261 outb_p(status
, SMBHSTSTS
);
264 static int i801_block_transaction_by_block(union i2c_smbus_data
*data
,
265 char read_write
, int hwpec
)
270 inb_p(SMBHSTCNT
); /* reset the data buffer index */
272 /* Use 32-byte buffer to process this transaction */
273 if (read_write
== I2C_SMBUS_WRITE
) {
274 len
= data
->block
[0];
275 outb_p(len
, SMBHSTDAT0
);
276 for (i
= 0; i
< len
; i
++)
277 outb_p(data
->block
[i
+1], SMBBLKDAT
);
280 status
= i801_transaction(I801_BLOCK_DATA
| ENABLE_INT9
|
281 I801_PEC_EN
* hwpec
);
285 if (read_write
== I2C_SMBUS_READ
) {
286 len
= inb_p(SMBHSTDAT0
);
287 if (len
< 1 || len
> I2C_SMBUS_BLOCK_MAX
)
290 data
->block
[0] = len
;
291 for (i
= 0; i
< len
; i
++)
292 data
->block
[i
+ 1] = inb_p(SMBBLKDAT
);
297 static int i801_block_transaction_byte_by_byte(union i2c_smbus_data
*data
,
298 char read_write
, int command
,
307 result
= i801_check_pre();
311 len
= data
->block
[0];
313 if (read_write
== I2C_SMBUS_WRITE
) {
314 outb_p(len
, SMBHSTDAT0
);
315 outb_p(data
->block
[1], SMBBLKDAT
);
318 for (i
= 1; i
<= len
; i
++) {
319 if (i
== len
&& read_write
== I2C_SMBUS_READ
) {
320 if (command
== I2C_SMBUS_I2C_BLOCK_DATA
)
321 smbcmd
= I801_I2C_BLOCK_LAST
;
323 smbcmd
= I801_BLOCK_LAST
;
325 if (command
== I2C_SMBUS_I2C_BLOCK_DATA
326 && read_write
== I2C_SMBUS_READ
)
327 smbcmd
= I801_I2C_BLOCK_DATA
;
329 smbcmd
= I801_BLOCK_DATA
;
331 outb_p(smbcmd
| ENABLE_INT9
, SMBHSTCNT
);
334 outb_p(inb(SMBHSTCNT
) | I801_START
, SMBHSTCNT
);
336 /* We will always wait for a fraction of a second! */
340 status
= inb_p(SMBHSTSTS
);
342 while ((!(status
& SMBHSTSTS_BYTE_DONE
))
343 && (timeout
++ < MAX_TIMEOUT
));
345 result
= i801_check_post(status
, timeout
>= MAX_TIMEOUT
);
349 if (i
== 1 && read_write
== I2C_SMBUS_READ
350 && command
!= I2C_SMBUS_I2C_BLOCK_DATA
) {
351 len
= inb_p(SMBHSTDAT0
);
352 if (len
< 1 || len
> I2C_SMBUS_BLOCK_MAX
) {
353 dev_err(&I801_dev
->dev
,
354 "Illegal SMBus block read size %d\n",
357 while (inb_p(SMBHSTSTS
) & SMBHSTSTS_HOST_BUSY
)
358 outb_p(SMBHSTSTS_BYTE_DONE
, SMBHSTSTS
);
359 outb_p(SMBHSTSTS_INTR
, SMBHSTSTS
);
362 data
->block
[0] = len
;
365 /* Retrieve/store value in SMBBLKDAT */
366 if (read_write
== I2C_SMBUS_READ
)
367 data
->block
[i
] = inb_p(SMBBLKDAT
);
368 if (read_write
== I2C_SMBUS_WRITE
&& i
+1 <= len
)
369 outb_p(data
->block
[i
+1], SMBBLKDAT
);
371 /* signals SMBBLKDAT ready */
372 outb_p(SMBHSTSTS_BYTE_DONE
| SMBHSTSTS_INTR
, SMBHSTSTS
);
378 static int i801_set_block_buffer_mode(void)
380 outb_p(inb_p(SMBAUXCTL
) | SMBAUXCTL_E32B
, SMBAUXCTL
);
381 if ((inb_p(SMBAUXCTL
) & SMBAUXCTL_E32B
) == 0)
386 /* Block transaction function */
387 static int i801_block_transaction(union i2c_smbus_data
*data
, char read_write
,
388 int command
, int hwpec
)
393 if (command
== I2C_SMBUS_I2C_BLOCK_DATA
) {
394 if (read_write
== I2C_SMBUS_WRITE
) {
395 /* set I2C_EN bit in configuration register */
396 pci_read_config_byte(I801_dev
, SMBHSTCFG
, &hostc
);
397 pci_write_config_byte(I801_dev
, SMBHSTCFG
,
398 hostc
| SMBHSTCFG_I2C_EN
);
399 } else if (!(i801_features
& FEATURE_I2C_BLOCK_READ
)) {
400 dev_err(&I801_dev
->dev
,
401 "I2C block read is unsupported!\n");
406 if (read_write
== I2C_SMBUS_WRITE
407 || command
== I2C_SMBUS_I2C_BLOCK_DATA
) {
408 if (data
->block
[0] < 1)
410 if (data
->block
[0] > I2C_SMBUS_BLOCK_MAX
)
411 data
->block
[0] = I2C_SMBUS_BLOCK_MAX
;
413 data
->block
[0] = 32; /* max for SMBus block reads */
416 if ((i801_features
& FEATURE_BLOCK_BUFFER
)
417 && !(command
== I2C_SMBUS_I2C_BLOCK_DATA
418 && read_write
== I2C_SMBUS_READ
)
419 && i801_set_block_buffer_mode() == 0)
420 result
= i801_block_transaction_by_block(data
, read_write
,
423 result
= i801_block_transaction_byte_by_byte(data
, read_write
,
426 if (result
== 0 && hwpec
)
429 if (command
== I2C_SMBUS_I2C_BLOCK_DATA
430 && read_write
== I2C_SMBUS_WRITE
) {
431 /* restore saved configuration register value */
432 pci_write_config_byte(I801_dev
, SMBHSTCFG
, hostc
);
437 /* Return negative errno on error. */
438 static s32
i801_access(struct i2c_adapter
* adap
, u16 addr
,
439 unsigned short flags
, char read_write
, u8 command
,
440 int size
, union i2c_smbus_data
* data
)
446 hwpec
= (i801_features
& FEATURE_SMBUS_PEC
) && (flags
& I2C_CLIENT_PEC
)
447 && size
!= I2C_SMBUS_QUICK
448 && size
!= I2C_SMBUS_I2C_BLOCK_DATA
;
451 case I2C_SMBUS_QUICK
:
452 outb_p(((addr
& 0x7f) << 1) | (read_write
& 0x01),
457 outb_p(((addr
& 0x7f) << 1) | (read_write
& 0x01),
459 if (read_write
== I2C_SMBUS_WRITE
)
460 outb_p(command
, SMBHSTCMD
);
463 case I2C_SMBUS_BYTE_DATA
:
464 outb_p(((addr
& 0x7f) << 1) | (read_write
& 0x01),
466 outb_p(command
, SMBHSTCMD
);
467 if (read_write
== I2C_SMBUS_WRITE
)
468 outb_p(data
->byte
, SMBHSTDAT0
);
469 xact
= I801_BYTE_DATA
;
471 case I2C_SMBUS_WORD_DATA
:
472 outb_p(((addr
& 0x7f) << 1) | (read_write
& 0x01),
474 outb_p(command
, SMBHSTCMD
);
475 if (read_write
== I2C_SMBUS_WRITE
) {
476 outb_p(data
->word
& 0xff, SMBHSTDAT0
);
477 outb_p((data
->word
& 0xff00) >> 8, SMBHSTDAT1
);
479 xact
= I801_WORD_DATA
;
481 case I2C_SMBUS_BLOCK_DATA
:
482 outb_p(((addr
& 0x7f) << 1) | (read_write
& 0x01),
484 outb_p(command
, SMBHSTCMD
);
487 case I2C_SMBUS_I2C_BLOCK_DATA
:
488 /* NB: page 240 of ICH5 datasheet shows that the R/#W
489 * bit should be cleared here, even when reading */
490 outb_p((addr
& 0x7f) << 1, SMBHSTADD
);
491 if (read_write
== I2C_SMBUS_READ
) {
492 /* NB: page 240 of ICH5 datasheet also shows
493 * that DATA1 is the cmd field when reading */
494 outb_p(command
, SMBHSTDAT1
);
496 outb_p(command
, SMBHSTCMD
);
500 dev_err(&I801_dev
->dev
, "Unsupported transaction %d\n", size
);
504 if (hwpec
) /* enable/disable hardware PEC */
505 outb_p(inb_p(SMBAUXCTL
) | SMBAUXCTL_CRC
, SMBAUXCTL
);
507 outb_p(inb_p(SMBAUXCTL
) & (~SMBAUXCTL_CRC
), SMBAUXCTL
);
510 ret
= i801_block_transaction(data
, read_write
, size
, hwpec
);
512 ret
= i801_transaction(xact
| ENABLE_INT9
);
514 /* Some BIOSes don't like it when PEC is enabled at reboot or resume
515 time, so we forcibly disable it after every transaction. Turn off
516 E32B for the same reason. */
518 outb_p(inb_p(SMBAUXCTL
) & ~(SMBAUXCTL_CRC
| SMBAUXCTL_E32B
),
525 if ((read_write
== I2C_SMBUS_WRITE
) || (xact
== I801_QUICK
))
528 switch (xact
& 0x7f) {
529 case I801_BYTE
: /* Result put in SMBHSTDAT0 */
531 data
->byte
= inb_p(SMBHSTDAT0
);
534 data
->word
= inb_p(SMBHSTDAT0
) + (inb_p(SMBHSTDAT1
) << 8);
541 static u32
i801_func(struct i2c_adapter
*adapter
)
543 return I2C_FUNC_SMBUS_QUICK
| I2C_FUNC_SMBUS_BYTE
|
544 I2C_FUNC_SMBUS_BYTE_DATA
| I2C_FUNC_SMBUS_WORD_DATA
|
545 I2C_FUNC_SMBUS_BLOCK_DATA
| I2C_FUNC_SMBUS_WRITE_I2C_BLOCK
|
546 ((i801_features
& FEATURE_SMBUS_PEC
) ? I2C_FUNC_SMBUS_PEC
: 0) |
547 ((i801_features
& FEATURE_I2C_BLOCK_READ
) ?
548 I2C_FUNC_SMBUS_READ_I2C_BLOCK
: 0);
551 static const struct i2c_algorithm smbus_algorithm
= {
552 .smbus_xfer
= i801_access
,
553 .functionality
= i801_func
,
556 static struct i2c_adapter i801_adapter
= {
557 .owner
= THIS_MODULE
,
558 .id
= I2C_HW_SMBUS_I801
,
559 .class = I2C_CLASS_HWMON
| I2C_CLASS_SPD
,
560 .algo
= &smbus_algorithm
,
563 static struct pci_device_id i801_ids
[] = {
564 { PCI_DEVICE(PCI_VENDOR_ID_INTEL
, PCI_DEVICE_ID_INTEL_82801AA_3
) },
565 { PCI_DEVICE(PCI_VENDOR_ID_INTEL
, PCI_DEVICE_ID_INTEL_82801AB_3
) },
566 { PCI_DEVICE(PCI_VENDOR_ID_INTEL
, PCI_DEVICE_ID_INTEL_82801BA_2
) },
567 { PCI_DEVICE(PCI_VENDOR_ID_INTEL
, PCI_DEVICE_ID_INTEL_82801CA_3
) },
568 { PCI_DEVICE(PCI_VENDOR_ID_INTEL
, PCI_DEVICE_ID_INTEL_82801DB_3
) },
569 { PCI_DEVICE(PCI_VENDOR_ID_INTEL
, PCI_DEVICE_ID_INTEL_82801EB_3
) },
570 { PCI_DEVICE(PCI_VENDOR_ID_INTEL
, PCI_DEVICE_ID_INTEL_ESB_4
) },
571 { PCI_DEVICE(PCI_VENDOR_ID_INTEL
, PCI_DEVICE_ID_INTEL_ICH6_16
) },
572 { PCI_DEVICE(PCI_VENDOR_ID_INTEL
, PCI_DEVICE_ID_INTEL_ICH7_17
) },
573 { PCI_DEVICE(PCI_VENDOR_ID_INTEL
, PCI_DEVICE_ID_INTEL_ESB2_17
) },
574 { PCI_DEVICE(PCI_VENDOR_ID_INTEL
, PCI_DEVICE_ID_INTEL_ICH8_5
) },
575 { PCI_DEVICE(PCI_VENDOR_ID_INTEL
, PCI_DEVICE_ID_INTEL_ICH9_6
) },
576 { PCI_DEVICE(PCI_VENDOR_ID_INTEL
, PCI_DEVICE_ID_INTEL_TOLAPAI_1
) },
577 { PCI_DEVICE(PCI_VENDOR_ID_INTEL
, PCI_DEVICE_ID_INTEL_ICH10_4
) },
578 { PCI_DEVICE(PCI_VENDOR_ID_INTEL
, PCI_DEVICE_ID_INTEL_ICH10_5
) },
582 MODULE_DEVICE_TABLE (pci
, i801_ids
);
584 static int __devinit
i801_probe(struct pci_dev
*dev
, const struct pci_device_id
*id
)
591 switch (dev
->device
) {
592 case PCI_DEVICE_ID_INTEL_82801EB_3
:
593 case PCI_DEVICE_ID_INTEL_ESB_4
:
594 case PCI_DEVICE_ID_INTEL_ICH6_16
:
595 case PCI_DEVICE_ID_INTEL_ICH7_17
:
596 case PCI_DEVICE_ID_INTEL_ESB2_17
:
597 case PCI_DEVICE_ID_INTEL_ICH8_5
:
598 case PCI_DEVICE_ID_INTEL_ICH9_6
:
599 case PCI_DEVICE_ID_INTEL_TOLAPAI_1
:
600 case PCI_DEVICE_ID_INTEL_ICH10_4
:
601 case PCI_DEVICE_ID_INTEL_ICH10_5
:
602 i801_features
|= FEATURE_I2C_BLOCK_READ
;
604 case PCI_DEVICE_ID_INTEL_82801DB_3
:
605 i801_features
|= FEATURE_SMBUS_PEC
;
606 i801_features
|= FEATURE_BLOCK_BUFFER
;
610 err
= pci_enable_device(dev
);
612 dev_err(&dev
->dev
, "Failed to enable SMBus PCI device (%d)\n",
617 /* Determine the address of the SMBus area */
618 i801_smba
= pci_resource_start(dev
, SMBBAR
);
620 dev_err(&dev
->dev
, "SMBus base address uninitialized, "
626 err
= acpi_check_resource_conflict(&dev
->resource
[SMBBAR
]);
630 err
= pci_request_region(dev
, SMBBAR
, i801_driver
.name
);
632 dev_err(&dev
->dev
, "Failed to request SMBus region "
633 "0x%lx-0x%Lx\n", i801_smba
,
634 (unsigned long long)pci_resource_end(dev
, SMBBAR
));
638 pci_read_config_byte(I801_dev
, SMBHSTCFG
, &temp
);
639 i801_original_hstcfg
= temp
;
640 temp
&= ~SMBHSTCFG_I2C_EN
; /* SMBus timing */
641 if (!(temp
& SMBHSTCFG_HST_EN
)) {
642 dev_info(&dev
->dev
, "Enabling SMBus device\n");
643 temp
|= SMBHSTCFG_HST_EN
;
645 pci_write_config_byte(I801_dev
, SMBHSTCFG
, temp
);
647 if (temp
& SMBHSTCFG_SMB_SMI_EN
)
648 dev_dbg(&dev
->dev
, "SMBus using interrupt SMI#\n");
650 dev_dbg(&dev
->dev
, "SMBus using PCI Interrupt\n");
652 /* Clear special mode bits */
653 if (i801_features
& (FEATURE_SMBUS_PEC
| FEATURE_BLOCK_BUFFER
))
654 outb_p(inb_p(SMBAUXCTL
) & ~(SMBAUXCTL_CRC
| SMBAUXCTL_E32B
),
657 /* set up the sysfs linkage to our parent device */
658 i801_adapter
.dev
.parent
= &dev
->dev
;
660 snprintf(i801_adapter
.name
, sizeof(i801_adapter
.name
),
661 "SMBus I801 adapter at %04lx", i801_smba
);
662 err
= i2c_add_adapter(&i801_adapter
);
664 dev_err(&dev
->dev
, "Failed to add SMBus adapter\n");
670 pci_release_region(dev
, SMBBAR
);
675 static void __devexit
i801_remove(struct pci_dev
*dev
)
677 i2c_del_adapter(&i801_adapter
);
678 pci_write_config_byte(I801_dev
, SMBHSTCFG
, i801_original_hstcfg
);
679 pci_release_region(dev
, SMBBAR
);
681 * do not call pci_disable_device(dev) since it can cause hard hangs on
682 * some systems during power-off (eg. Fujitsu-Siemens Lifebook E8010)
687 static int i801_suspend(struct pci_dev
*dev
, pm_message_t mesg
)
690 pci_write_config_byte(dev
, SMBHSTCFG
, i801_original_hstcfg
);
691 pci_set_power_state(dev
, pci_choose_state(dev
, mesg
));
695 static int i801_resume(struct pci_dev
*dev
)
697 pci_set_power_state(dev
, PCI_D0
);
698 pci_restore_state(dev
);
699 return pci_enable_device(dev
);
702 #define i801_suspend NULL
703 #define i801_resume NULL
706 static struct pci_driver i801_driver
= {
707 .name
= "i801_smbus",
708 .id_table
= i801_ids
,
710 .remove
= __devexit_p(i801_remove
),
711 .suspend
= i801_suspend
,
712 .resume
= i801_resume
,
715 static int __init
i2c_i801_init(void)
717 return pci_register_driver(&i801_driver
);
720 static void __exit
i2c_i801_exit(void)
722 pci_unregister_driver(&i801_driver
);
725 MODULE_AUTHOR("Mark D. Studebaker <mdsxyz123@yahoo.com>, "
726 "Jean Delvare <khali@linux-fr.org>");
727 MODULE_DESCRIPTION("I801 SMBus driver");
728 MODULE_LICENSE("GPL");
730 module_init(i2c_i801_init
);
731 module_exit(i2c_i801_exit
);