2 Copyright (c) 1998 - 2002 Frodo Looijaard <frodol@dds.nl> and
3 Philip Edelbrock <phil@netroedge.com>
5 This program is free software; you can redistribute it and/or modify
6 it under the terms of the GNU General Public License as published by
7 the Free Software Foundation; either version 2 of the License, or
8 (at your option) any later version.
10 This program is distributed in the hope that it will be useful,
11 but WITHOUT ANY WARRANTY; without even the implied warranty of
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 GNU General Public License for more details.
19 Serverworks OSB4, CSB5, CSB6, HT-1000, HT-1100
20 ATI IXP200, IXP300, IXP400, SB600, SB700/SP5100, SB800
24 Note: we assume there can only be one device, with one or more
26 The device can register multiple i2c_adapters (up to PIIX4_MAX_ADAPTERS).
27 For devices supporting multiple ports the i2c_adapter should provide
28 an i2c_algorithm to access them.
31 #include <linux/module.h>
32 #include <linux/moduleparam.h>
33 #include <linux/pci.h>
34 #include <linux/kernel.h>
35 #include <linux/delay.h>
36 #include <linux/stddef.h>
37 #include <linux/ioport.h>
38 #include <linux/i2c.h>
39 #include <linux/slab.h>
40 #include <linux/dmi.h>
41 #include <linux/acpi.h>
45 /* PIIX4 SMBus address offsets */
46 #define SMBHSTSTS (0 + piix4_smba)
47 #define SMBHSLVSTS (1 + piix4_smba)
48 #define SMBHSTCNT (2 + piix4_smba)
49 #define SMBHSTCMD (3 + piix4_smba)
50 #define SMBHSTADD (4 + piix4_smba)
51 #define SMBHSTDAT0 (5 + piix4_smba)
52 #define SMBHSTDAT1 (6 + piix4_smba)
53 #define SMBBLKDAT (7 + piix4_smba)
54 #define SMBSLVCNT (8 + piix4_smba)
55 #define SMBSHDWCMD (9 + piix4_smba)
56 #define SMBSLVEVT (0xA + piix4_smba)
57 #define SMBSLVDAT (0xC + piix4_smba)
59 /* count for request_region */
62 /* PCI Address Constants */
64 #define SMBHSTCFG 0x0D2
66 #define SMBSHDW1 0x0D4
67 #define SMBSHDW2 0x0D5
71 #define MAX_TIMEOUT 500
75 #define PIIX4_QUICK 0x00
76 #define PIIX4_BYTE 0x04
77 #define PIIX4_BYTE_DATA 0x08
78 #define PIIX4_WORD_DATA 0x0C
79 #define PIIX4_BLOCK_DATA 0x14
81 /* Multi-port constants */
82 #define PIIX4_MAX_ADAPTERS 4
85 #define SB800_PIIX4_SMB_IDX 0xcd6
87 #define KERNCZ_IMC_IDX 0x3e
88 #define KERNCZ_IMC_DATA 0x3f
91 * SB800 port is selected by bits 2:1 of the smb_en register (0x2c)
92 * or the smb_sel register (0x2e), depending on bit 0 of register 0x2f.
93 * Hudson-2/Bolton port is always selected by bits 2:1 of register 0x2f.
95 #define SB800_PIIX4_PORT_IDX 0x2c
96 #define SB800_PIIX4_PORT_IDX_ALT 0x2e
97 #define SB800_PIIX4_PORT_IDX_SEL 0x2f
98 #define SB800_PIIX4_PORT_IDX_MASK 0x06
99 #define SB800_PIIX4_PORT_IDX_SHIFT 1
101 /* On kerncz, SmBus0Sel is at bit 20:19 of PMx00 DecodeEn */
102 #define SB800_PIIX4_PORT_IDX_KERNCZ 0x02
103 #define SB800_PIIX4_PORT_IDX_MASK_KERNCZ 0x18
104 #define SB800_PIIX4_PORT_IDX_SHIFT_KERNCZ 3
106 /* insmod parameters */
108 /* If force is set to anything different from 0, we forcibly enable the
111 module_param (force
, int, 0);
112 MODULE_PARM_DESC(force
, "Forcibly enable the PIIX4. DANGEROUS!");
114 /* If force_addr is set to anything different from 0, we forcibly enable
115 the PIIX4 at the given address. VERY DANGEROUS! */
116 static int force_addr
;
117 module_param_hw(force_addr
, int, ioport
, 0);
118 MODULE_PARM_DESC(force_addr
,
119 "Forcibly enable the PIIX4 at the given address. "
120 "EXTREMELY DANGEROUS!");
122 static int srvrworks_csb5_delay
;
123 static struct pci_driver piix4_driver
;
125 static const struct dmi_system_id piix4_dmi_blacklist
[] = {
127 .ident
= "Sapphire AM2RD790",
129 DMI_MATCH(DMI_BOARD_VENDOR
, "SAPPHIRE Inc."),
130 DMI_MATCH(DMI_BOARD_NAME
, "PC-AM2RD790"),
134 .ident
= "DFI Lanparty UT 790FX",
136 DMI_MATCH(DMI_BOARD_VENDOR
, "DFI Inc."),
137 DMI_MATCH(DMI_BOARD_NAME
, "LP UT 790FX"),
143 /* The IBM entry is in a separate table because we only check it
144 on Intel-based systems */
145 static const struct dmi_system_id piix4_dmi_ibm
[] = {
148 .matches
= { DMI_MATCH(DMI_SYS_VENDOR
, "IBM"), },
156 static u8 piix4_port_sel_sb800
;
157 static u8 piix4_port_mask_sb800
;
158 static u8 piix4_port_shift_sb800
;
159 static const char *piix4_main_port_names_sb800
[PIIX4_MAX_ADAPTERS
] = {
160 " port 0", " port 2", " port 3", " port 4"
162 static const char *piix4_aux_port_name_sb800
= " port 1";
164 struct i2c_piix4_adapdata
{
170 u8 port
; /* Port number, shifted */
173 static int piix4_setup(struct pci_dev
*PIIX4_dev
,
174 const struct pci_device_id
*id
)
177 unsigned short piix4_smba
;
179 if ((PIIX4_dev
->vendor
== PCI_VENDOR_ID_SERVERWORKS
) &&
180 (PIIX4_dev
->device
== PCI_DEVICE_ID_SERVERWORKS_CSB5
))
181 srvrworks_csb5_delay
= 1;
183 /* On some motherboards, it was reported that accessing the SMBus
184 caused severe hardware problems */
185 if (dmi_check_system(piix4_dmi_blacklist
)) {
186 dev_err(&PIIX4_dev
->dev
,
187 "Accessing the SMBus on this system is unsafe!\n");
191 /* Don't access SMBus on IBM systems which get corrupted eeproms */
192 if (dmi_check_system(piix4_dmi_ibm
) &&
193 PIIX4_dev
->vendor
== PCI_VENDOR_ID_INTEL
) {
194 dev_err(&PIIX4_dev
->dev
, "IBM system detected; this module "
195 "may corrupt your serial eeprom! Refusing to load "
200 /* Determine the address of the SMBus areas */
202 piix4_smba
= force_addr
& 0xfff0;
205 pci_read_config_word(PIIX4_dev
, SMBBA
, &piix4_smba
);
206 piix4_smba
&= 0xfff0;
207 if(piix4_smba
== 0) {
208 dev_err(&PIIX4_dev
->dev
, "SMBus base address "
209 "uninitialized - upgrade BIOS or use "
210 "force_addr=0xaddr\n");
215 if (acpi_check_region(piix4_smba
, SMBIOSIZE
, piix4_driver
.name
))
218 if (!request_region(piix4_smba
, SMBIOSIZE
, piix4_driver
.name
)) {
219 dev_err(&PIIX4_dev
->dev
, "SMBus region 0x%x already in use!\n",
224 pci_read_config_byte(PIIX4_dev
, SMBHSTCFG
, &temp
);
226 /* If force_addr is set, we program the new address here. Just to make
227 sure, we disable the PIIX4 first. */
229 pci_write_config_byte(PIIX4_dev
, SMBHSTCFG
, temp
& 0xfe);
230 pci_write_config_word(PIIX4_dev
, SMBBA
, piix4_smba
);
231 pci_write_config_byte(PIIX4_dev
, SMBHSTCFG
, temp
| 0x01);
232 dev_info(&PIIX4_dev
->dev
, "WARNING: SMBus interface set to "
233 "new address %04x!\n", piix4_smba
);
234 } else if ((temp
& 1) == 0) {
236 /* This should never need to be done, but has been
237 * noted that many Dell machines have the SMBus
238 * interface on the PIIX4 disabled!? NOTE: This assumes
239 * I/O space and other allocations WERE done by the
240 * Bios! Don't complain if your hardware does weird
241 * things after enabling this. :') Check for Bios
242 * updates before resorting to this.
244 pci_write_config_byte(PIIX4_dev
, SMBHSTCFG
,
246 dev_notice(&PIIX4_dev
->dev
,
247 "WARNING: SMBus interface has been FORCEFULLY ENABLED!\n");
249 dev_err(&PIIX4_dev
->dev
,
250 "SMBus Host Controller not enabled!\n");
251 release_region(piix4_smba
, SMBIOSIZE
);
256 if (((temp
& 0x0E) == 8) || ((temp
& 0x0E) == 2))
257 dev_dbg(&PIIX4_dev
->dev
, "Using IRQ for SMBus\n");
258 else if ((temp
& 0x0E) == 0)
259 dev_dbg(&PIIX4_dev
->dev
, "Using SMI# for SMBus\n");
261 dev_err(&PIIX4_dev
->dev
, "Illegal Interrupt configuration "
262 "(or code out of date)!\n");
264 pci_read_config_byte(PIIX4_dev
, SMBREV
, &temp
);
265 dev_info(&PIIX4_dev
->dev
,
266 "SMBus Host Controller at 0x%x, revision %d\n",
272 static int piix4_setup_sb800(struct pci_dev
*PIIX4_dev
,
273 const struct pci_device_id
*id
, u8 aux
)
275 unsigned short piix4_smba
;
276 u8 smba_en_lo
, smba_en_hi
, smb_en
, smb_en_status
, port_sel
;
277 u8 i2ccfg
, i2ccfg_offset
= 0x10;
279 /* SB800 and later SMBus does not support forcing address */
280 if (force
|| force_addr
) {
281 dev_err(&PIIX4_dev
->dev
, "SMBus does not support "
282 "forcing address!\n");
286 /* Determine the address of the SMBus areas */
287 if ((PIIX4_dev
->vendor
== PCI_VENDOR_ID_AMD
&&
288 PIIX4_dev
->device
== PCI_DEVICE_ID_AMD_HUDSON2_SMBUS
&&
289 PIIX4_dev
->revision
>= 0x41) ||
290 (PIIX4_dev
->vendor
== PCI_VENDOR_ID_AMD
&&
291 PIIX4_dev
->device
== PCI_DEVICE_ID_AMD_KERNCZ_SMBUS
&&
292 PIIX4_dev
->revision
>= 0x49))
295 smb_en
= (aux
) ? 0x28 : 0x2c;
297 if (!request_muxed_region(SB800_PIIX4_SMB_IDX
, 2, "sb800_piix4_smb")) {
298 dev_err(&PIIX4_dev
->dev
,
299 "SMB base address index region 0x%x already in use.\n",
300 SB800_PIIX4_SMB_IDX
);
304 outb_p(smb_en
, SB800_PIIX4_SMB_IDX
);
305 smba_en_lo
= inb_p(SB800_PIIX4_SMB_IDX
+ 1);
306 outb_p(smb_en
+ 1, SB800_PIIX4_SMB_IDX
);
307 smba_en_hi
= inb_p(SB800_PIIX4_SMB_IDX
+ 1);
309 release_region(SB800_PIIX4_SMB_IDX
, 2);
312 smb_en_status
= smba_en_lo
& 0x10;
313 piix4_smba
= smba_en_hi
<< 8;
317 smb_en_status
= smba_en_lo
& 0x01;
318 piix4_smba
= ((smba_en_hi
<< 8) | smba_en_lo
) & 0xffe0;
321 if (!smb_en_status
) {
322 dev_err(&PIIX4_dev
->dev
,
323 "SMBus Host Controller not enabled!\n");
327 if (acpi_check_region(piix4_smba
, SMBIOSIZE
, piix4_driver
.name
))
330 if (!request_region(piix4_smba
, SMBIOSIZE
, piix4_driver
.name
)) {
331 dev_err(&PIIX4_dev
->dev
, "SMBus region 0x%x already in use!\n",
336 /* Aux SMBus does not support IRQ information */
338 dev_info(&PIIX4_dev
->dev
,
339 "Auxiliary SMBus Host Controller at 0x%x\n",
344 /* Request the SMBus I2C bus config region */
345 if (!request_region(piix4_smba
+ i2ccfg_offset
, 1, "i2ccfg")) {
346 dev_err(&PIIX4_dev
->dev
, "SMBus I2C bus config region "
347 "0x%x already in use!\n", piix4_smba
+ i2ccfg_offset
);
348 release_region(piix4_smba
, SMBIOSIZE
);
351 i2ccfg
= inb_p(piix4_smba
+ i2ccfg_offset
);
352 release_region(piix4_smba
+ i2ccfg_offset
, 1);
355 dev_dbg(&PIIX4_dev
->dev
, "Using IRQ for SMBus\n");
357 dev_dbg(&PIIX4_dev
->dev
, "Using SMI# for SMBus\n");
359 dev_info(&PIIX4_dev
->dev
,
360 "SMBus Host Controller at 0x%x, revision %d\n",
361 piix4_smba
, i2ccfg
>> 4);
363 /* Find which register is used for port selection */
364 if (PIIX4_dev
->vendor
== PCI_VENDOR_ID_AMD
) {
365 switch (PIIX4_dev
->device
) {
366 case PCI_DEVICE_ID_AMD_KERNCZ_SMBUS
:
367 piix4_port_sel_sb800
= SB800_PIIX4_PORT_IDX_KERNCZ
;
368 piix4_port_mask_sb800
= SB800_PIIX4_PORT_IDX_MASK_KERNCZ
;
369 piix4_port_shift_sb800
= SB800_PIIX4_PORT_IDX_SHIFT_KERNCZ
;
371 case PCI_DEVICE_ID_AMD_HUDSON2_SMBUS
:
373 piix4_port_sel_sb800
= SB800_PIIX4_PORT_IDX_ALT
;
374 piix4_port_mask_sb800
= SB800_PIIX4_PORT_IDX_MASK
;
375 piix4_port_shift_sb800
= SB800_PIIX4_PORT_IDX_SHIFT
;
379 if (!request_muxed_region(SB800_PIIX4_SMB_IDX
, 2,
380 "sb800_piix4_smb")) {
381 release_region(piix4_smba
, SMBIOSIZE
);
385 outb_p(SB800_PIIX4_PORT_IDX_SEL
, SB800_PIIX4_SMB_IDX
);
386 port_sel
= inb_p(SB800_PIIX4_SMB_IDX
+ 1);
387 piix4_port_sel_sb800
= (port_sel
& 0x01) ?
388 SB800_PIIX4_PORT_IDX_ALT
:
389 SB800_PIIX4_PORT_IDX
;
390 piix4_port_mask_sb800
= SB800_PIIX4_PORT_IDX_MASK
;
391 piix4_port_shift_sb800
= SB800_PIIX4_PORT_IDX_SHIFT
;
392 release_region(SB800_PIIX4_SMB_IDX
, 2);
395 dev_info(&PIIX4_dev
->dev
,
396 "Using register 0x%02x for SMBus port selection\n",
397 (unsigned int)piix4_port_sel_sb800
);
402 static int piix4_setup_aux(struct pci_dev
*PIIX4_dev
,
403 const struct pci_device_id
*id
,
404 unsigned short base_reg_addr
)
406 /* Set up auxiliary SMBus controllers found on some
407 * AMD chipsets e.g. SP5100 (SB700 derivative) */
409 unsigned short piix4_smba
;
411 /* Read address of auxiliary SMBus controller */
412 pci_read_config_word(PIIX4_dev
, base_reg_addr
, &piix4_smba
);
413 if ((piix4_smba
& 1) == 0) {
414 dev_dbg(&PIIX4_dev
->dev
,
415 "Auxiliary SMBus controller not enabled\n");
419 piix4_smba
&= 0xfff0;
420 if (piix4_smba
== 0) {
421 dev_dbg(&PIIX4_dev
->dev
,
422 "Auxiliary SMBus base address uninitialized\n");
426 if (acpi_check_region(piix4_smba
, SMBIOSIZE
, piix4_driver
.name
))
429 if (!request_region(piix4_smba
, SMBIOSIZE
, piix4_driver
.name
)) {
430 dev_err(&PIIX4_dev
->dev
, "Auxiliary SMBus region 0x%x "
431 "already in use!\n", piix4_smba
);
435 dev_info(&PIIX4_dev
->dev
,
436 "Auxiliary SMBus Host Controller at 0x%x\n",
442 static int piix4_transaction(struct i2c_adapter
*piix4_adapter
)
444 struct i2c_piix4_adapdata
*adapdata
= i2c_get_adapdata(piix4_adapter
);
445 unsigned short piix4_smba
= adapdata
->smba
;
450 dev_dbg(&piix4_adapter
->dev
, "Transaction (pre): CNT=%02x, CMD=%02x, "
451 "ADD=%02x, DAT0=%02x, DAT1=%02x\n", inb_p(SMBHSTCNT
),
452 inb_p(SMBHSTCMD
), inb_p(SMBHSTADD
), inb_p(SMBHSTDAT0
),
455 /* Make sure the SMBus host is ready to start transmitting */
456 if ((temp
= inb_p(SMBHSTSTS
)) != 0x00) {
457 dev_dbg(&piix4_adapter
->dev
, "SMBus busy (%02x). "
458 "Resetting...\n", temp
);
459 outb_p(temp
, SMBHSTSTS
);
460 if ((temp
= inb_p(SMBHSTSTS
)) != 0x00) {
461 dev_err(&piix4_adapter
->dev
, "Failed! (%02x)\n", temp
);
464 dev_dbg(&piix4_adapter
->dev
, "Successful!\n");
468 /* start the transaction by setting bit 6 */
469 outb_p(inb(SMBHSTCNT
) | 0x040, SMBHSTCNT
);
471 /* We will always wait for a fraction of a second! (See PIIX4 docs errata) */
472 if (srvrworks_csb5_delay
) /* Extra delay for SERVERWORKS_CSB5 */
473 usleep_range(2000, 2100);
475 usleep_range(250, 500);
477 while ((++timeout
< MAX_TIMEOUT
) &&
478 ((temp
= inb_p(SMBHSTSTS
)) & 0x01))
479 usleep_range(250, 500);
481 /* If the SMBus is still busy, we give up */
482 if (timeout
== MAX_TIMEOUT
) {
483 dev_err(&piix4_adapter
->dev
, "SMBus Timeout!\n");
489 dev_err(&piix4_adapter
->dev
, "Error: Failed bus transaction\n");
494 dev_dbg(&piix4_adapter
->dev
, "Bus collision! SMBus may be "
495 "locked until next hard reset. (sorry!)\n");
496 /* Clock stops and slave is stuck in mid-transmission */
501 dev_dbg(&piix4_adapter
->dev
, "Error: no response!\n");
504 if (inb_p(SMBHSTSTS
) != 0x00)
505 outb_p(inb(SMBHSTSTS
), SMBHSTSTS
);
507 if ((temp
= inb_p(SMBHSTSTS
)) != 0x00) {
508 dev_err(&piix4_adapter
->dev
, "Failed reset at end of "
509 "transaction (%02x)\n", temp
);
511 dev_dbg(&piix4_adapter
->dev
, "Transaction (post): CNT=%02x, CMD=%02x, "
512 "ADD=%02x, DAT0=%02x, DAT1=%02x\n", inb_p(SMBHSTCNT
),
513 inb_p(SMBHSTCMD
), inb_p(SMBHSTADD
), inb_p(SMBHSTDAT0
),
518 /* Return negative errno on error. */
519 static s32
piix4_access(struct i2c_adapter
* adap
, u16 addr
,
520 unsigned short flags
, char read_write
,
521 u8 command
, int size
, union i2c_smbus_data
* data
)
523 struct i2c_piix4_adapdata
*adapdata
= i2c_get_adapdata(adap
);
524 unsigned short piix4_smba
= adapdata
->smba
;
529 case I2C_SMBUS_QUICK
:
530 outb_p((addr
<< 1) | read_write
,
535 outb_p((addr
<< 1) | read_write
,
537 if (read_write
== I2C_SMBUS_WRITE
)
538 outb_p(command
, SMBHSTCMD
);
541 case I2C_SMBUS_BYTE_DATA
:
542 outb_p((addr
<< 1) | read_write
,
544 outb_p(command
, SMBHSTCMD
);
545 if (read_write
== I2C_SMBUS_WRITE
)
546 outb_p(data
->byte
, SMBHSTDAT0
);
547 size
= PIIX4_BYTE_DATA
;
549 case I2C_SMBUS_WORD_DATA
:
550 outb_p((addr
<< 1) | read_write
,
552 outb_p(command
, SMBHSTCMD
);
553 if (read_write
== I2C_SMBUS_WRITE
) {
554 outb_p(data
->word
& 0xff, SMBHSTDAT0
);
555 outb_p((data
->word
& 0xff00) >> 8, SMBHSTDAT1
);
557 size
= PIIX4_WORD_DATA
;
559 case I2C_SMBUS_BLOCK_DATA
:
560 outb_p((addr
<< 1) | read_write
,
562 outb_p(command
, SMBHSTCMD
);
563 if (read_write
== I2C_SMBUS_WRITE
) {
564 len
= data
->block
[0];
565 if (len
== 0 || len
> I2C_SMBUS_BLOCK_MAX
)
567 outb_p(len
, SMBHSTDAT0
);
568 inb_p(SMBHSTCNT
); /* Reset SMBBLKDAT */
569 for (i
= 1; i
<= len
; i
++)
570 outb_p(data
->block
[i
], SMBBLKDAT
);
572 size
= PIIX4_BLOCK_DATA
;
575 dev_warn(&adap
->dev
, "Unsupported transaction %d\n", size
);
579 outb_p((size
& 0x1C) + (ENABLE_INT9
& 1), SMBHSTCNT
);
581 status
= piix4_transaction(adap
);
585 if ((read_write
== I2C_SMBUS_WRITE
) || (size
== PIIX4_QUICK
))
591 case PIIX4_BYTE_DATA
:
592 data
->byte
= inb_p(SMBHSTDAT0
);
594 case PIIX4_WORD_DATA
:
595 data
->word
= inb_p(SMBHSTDAT0
) + (inb_p(SMBHSTDAT1
) << 8);
597 case PIIX4_BLOCK_DATA
:
598 data
->block
[0] = inb_p(SMBHSTDAT0
);
599 if (data
->block
[0] == 0 || data
->block
[0] > I2C_SMBUS_BLOCK_MAX
)
601 inb_p(SMBHSTCNT
); /* Reset SMBBLKDAT */
602 for (i
= 1; i
<= data
->block
[0]; i
++)
603 data
->block
[i
] = inb_p(SMBBLKDAT
);
609 static uint8_t piix4_imc_read(uint8_t idx
)
611 outb_p(idx
, KERNCZ_IMC_IDX
);
612 return inb_p(KERNCZ_IMC_DATA
);
615 static void piix4_imc_write(uint8_t idx
, uint8_t value
)
617 outb_p(idx
, KERNCZ_IMC_IDX
);
618 outb_p(value
, KERNCZ_IMC_DATA
);
621 static int piix4_imc_sleep(void)
623 int timeout
= MAX_TIMEOUT
;
625 if (!request_muxed_region(KERNCZ_IMC_IDX
, 2, "smbus_kerncz_imc"))
628 /* clear response register */
629 piix4_imc_write(0x82, 0x00);
630 /* request ownership flag */
631 piix4_imc_write(0x83, 0xB4);
632 /* kick off IMC Mailbox command 96 */
633 piix4_imc_write(0x80, 0x96);
636 if (piix4_imc_read(0x82) == 0xfa) {
637 release_region(KERNCZ_IMC_IDX
, 2);
640 usleep_range(1000, 2000);
643 release_region(KERNCZ_IMC_IDX
, 2);
647 static void piix4_imc_wakeup(void)
649 int timeout
= MAX_TIMEOUT
;
651 if (!request_muxed_region(KERNCZ_IMC_IDX
, 2, "smbus_kerncz_imc"))
654 /* clear response register */
655 piix4_imc_write(0x82, 0x00);
656 /* release ownership flag */
657 piix4_imc_write(0x83, 0xB5);
658 /* kick off IMC Mailbox command 96 */
659 piix4_imc_write(0x80, 0x96);
662 if (piix4_imc_read(0x82) == 0xfa)
664 usleep_range(1000, 2000);
667 release_region(KERNCZ_IMC_IDX
, 2);
671 * Handles access to multiple SMBus ports on the SB800.
672 * The port is selected by bits 2:1 of the smb_en register (0x2c).
673 * Returns negative errno on error.
675 * Note: The selected port must be returned to the initial selection to avoid
676 * problems on certain systems.
678 static s32
piix4_access_sb800(struct i2c_adapter
*adap
, u16 addr
,
679 unsigned short flags
, char read_write
,
680 u8 command
, int size
, union i2c_smbus_data
*data
)
682 struct i2c_piix4_adapdata
*adapdata
= i2c_get_adapdata(adap
);
683 unsigned short piix4_smba
= adapdata
->smba
;
684 int retries
= MAX_TIMEOUT
;
690 if (!request_muxed_region(SB800_PIIX4_SMB_IDX
, 2, "sb800_piix4_smb"))
693 /* Request the SMBUS semaphore, avoid conflicts with the IMC */
694 smbslvcnt
= inb_p(SMBSLVCNT
);
696 outb_p(smbslvcnt
| 0x10, SMBSLVCNT
);
698 /* Check the semaphore status */
699 smbslvcnt
= inb_p(SMBSLVCNT
);
700 if (smbslvcnt
& 0x10)
703 usleep_range(1000, 2000);
705 /* SMBus is still owned by the IMC, we give up */
712 * Notify the IMC (Integrated Micro Controller) if required.
713 * Among other responsibilities, the IMC is in charge of monitoring
714 * the System fans and temperature sensors, and act accordingly.
715 * All this is done through SMBus and can/will collide
716 * with our transactions if they are long (BLOCK_DATA).
717 * Therefore we need to request the ownership flag during those
720 if ((size
== I2C_SMBUS_BLOCK_DATA
) && adapdata
->notify_imc
) {
723 ret
= piix4_imc_sleep();
727 "IMC base address index region 0x%x already in use.\n",
732 "Failed to communicate with the IMC.\n");
738 /* If IMC communication fails do not retry */
741 "Continuing without IMC notification.\n");
742 adapdata
->notify_imc
= false;
746 outb_p(piix4_port_sel_sb800
, SB800_PIIX4_SMB_IDX
);
747 smba_en_lo
= inb_p(SB800_PIIX4_SMB_IDX
+ 1);
749 port
= adapdata
->port
;
750 if ((smba_en_lo
& piix4_port_mask_sb800
) != port
)
751 outb_p((smba_en_lo
& ~piix4_port_mask_sb800
) | port
,
752 SB800_PIIX4_SMB_IDX
+ 1);
754 retval
= piix4_access(adap
, addr
, flags
, read_write
,
755 command
, size
, data
);
757 outb_p(smba_en_lo
, SB800_PIIX4_SMB_IDX
+ 1);
759 /* Release the semaphore */
760 outb_p(smbslvcnt
| 0x20, SMBSLVCNT
);
762 if ((size
== I2C_SMBUS_BLOCK_DATA
) && adapdata
->notify_imc
)
766 release_region(SB800_PIIX4_SMB_IDX
, 2);
770 static u32
piix4_func(struct i2c_adapter
*adapter
)
772 return I2C_FUNC_SMBUS_QUICK
| I2C_FUNC_SMBUS_BYTE
|
773 I2C_FUNC_SMBUS_BYTE_DATA
| I2C_FUNC_SMBUS_WORD_DATA
|
774 I2C_FUNC_SMBUS_BLOCK_DATA
;
777 static const struct i2c_algorithm smbus_algorithm
= {
778 .smbus_xfer
= piix4_access
,
779 .functionality
= piix4_func
,
782 static const struct i2c_algorithm piix4_smbus_algorithm_sb800
= {
783 .smbus_xfer
= piix4_access_sb800
,
784 .functionality
= piix4_func
,
787 static const struct pci_device_id piix4_ids
[] = {
788 { PCI_DEVICE(PCI_VENDOR_ID_INTEL
, PCI_DEVICE_ID_INTEL_82371AB_3
) },
789 { PCI_DEVICE(PCI_VENDOR_ID_INTEL
, PCI_DEVICE_ID_INTEL_82443MX_3
) },
790 { PCI_DEVICE(PCI_VENDOR_ID_EFAR
, PCI_DEVICE_ID_EFAR_SLC90E66_3
) },
791 { PCI_DEVICE(PCI_VENDOR_ID_ATI
, PCI_DEVICE_ID_ATI_IXP200_SMBUS
) },
792 { PCI_DEVICE(PCI_VENDOR_ID_ATI
, PCI_DEVICE_ID_ATI_IXP300_SMBUS
) },
793 { PCI_DEVICE(PCI_VENDOR_ID_ATI
, PCI_DEVICE_ID_ATI_IXP400_SMBUS
) },
794 { PCI_DEVICE(PCI_VENDOR_ID_ATI
, PCI_DEVICE_ID_ATI_SBX00_SMBUS
) },
795 { PCI_DEVICE(PCI_VENDOR_ID_AMD
, PCI_DEVICE_ID_AMD_HUDSON2_SMBUS
) },
796 { PCI_DEVICE(PCI_VENDOR_ID_AMD
, PCI_DEVICE_ID_AMD_KERNCZ_SMBUS
) },
797 { PCI_DEVICE(PCI_VENDOR_ID_SERVERWORKS
,
798 PCI_DEVICE_ID_SERVERWORKS_OSB4
) },
799 { PCI_DEVICE(PCI_VENDOR_ID_SERVERWORKS
,
800 PCI_DEVICE_ID_SERVERWORKS_CSB5
) },
801 { PCI_DEVICE(PCI_VENDOR_ID_SERVERWORKS
,
802 PCI_DEVICE_ID_SERVERWORKS_CSB6
) },
803 { PCI_DEVICE(PCI_VENDOR_ID_SERVERWORKS
,
804 PCI_DEVICE_ID_SERVERWORKS_HT1000SB
) },
805 { PCI_DEVICE(PCI_VENDOR_ID_SERVERWORKS
,
806 PCI_DEVICE_ID_SERVERWORKS_HT1100LD
) },
810 MODULE_DEVICE_TABLE (pci
, piix4_ids
);
812 static struct i2c_adapter
*piix4_main_adapters
[PIIX4_MAX_ADAPTERS
];
813 static struct i2c_adapter
*piix4_aux_adapter
;
815 static int piix4_add_adapter(struct pci_dev
*dev
, unsigned short smba
,
816 bool sb800_main
, u8 port
, bool notify_imc
,
817 const char *name
, struct i2c_adapter
**padap
)
819 struct i2c_adapter
*adap
;
820 struct i2c_piix4_adapdata
*adapdata
;
823 adap
= kzalloc(sizeof(*adap
), GFP_KERNEL
);
825 release_region(smba
, SMBIOSIZE
);
829 adap
->owner
= THIS_MODULE
;
830 adap
->class = I2C_CLASS_HWMON
| I2C_CLASS_SPD
;
831 adap
->algo
= sb800_main
? &piix4_smbus_algorithm_sb800
834 adapdata
= kzalloc(sizeof(*adapdata
), GFP_KERNEL
);
835 if (adapdata
== NULL
) {
837 release_region(smba
, SMBIOSIZE
);
841 adapdata
->smba
= smba
;
842 adapdata
->sb800_main
= sb800_main
;
843 adapdata
->port
= port
<< piix4_port_shift_sb800
;
844 adapdata
->notify_imc
= notify_imc
;
846 /* set up the sysfs linkage to our parent device */
847 adap
->dev
.parent
= &dev
->dev
;
849 snprintf(adap
->name
, sizeof(adap
->name
),
850 "SMBus PIIX4 adapter%s at %04x", name
, smba
);
852 i2c_set_adapdata(adap
, adapdata
);
854 retval
= i2c_add_adapter(adap
);
858 release_region(smba
, SMBIOSIZE
);
866 static int piix4_add_adapters_sb800(struct pci_dev
*dev
, unsigned short smba
,
869 struct i2c_piix4_adapdata
*adapdata
;
873 for (port
= 0; port
< PIIX4_MAX_ADAPTERS
; port
++) {
874 retval
= piix4_add_adapter(dev
, smba
, true, port
, notify_imc
,
875 piix4_main_port_names_sb800
[port
],
876 &piix4_main_adapters
[port
]);
885 "Error setting up SB800 adapters. Unregistering!\n");
886 while (--port
>= 0) {
887 adapdata
= i2c_get_adapdata(piix4_main_adapters
[port
]);
888 if (adapdata
->smba
) {
889 i2c_del_adapter(piix4_main_adapters
[port
]);
891 kfree(piix4_main_adapters
[port
]);
892 piix4_main_adapters
[port
] = NULL
;
899 static int piix4_probe(struct pci_dev
*dev
, const struct pci_device_id
*id
)
902 bool is_sb800
= false;
904 if ((dev
->vendor
== PCI_VENDOR_ID_ATI
&&
905 dev
->device
== PCI_DEVICE_ID_ATI_SBX00_SMBUS
&&
906 dev
->revision
>= 0x40) ||
907 dev
->vendor
== PCI_VENDOR_ID_AMD
) {
908 bool notify_imc
= false;
911 if (dev
->vendor
== PCI_VENDOR_ID_AMD
&&
912 dev
->device
== PCI_DEVICE_ID_AMD_KERNCZ_SMBUS
) {
916 * Detect if IMC is active or not, this method is
917 * described on coreboot's AMD IMC notes
919 pci_bus_read_config_byte(dev
->bus
, PCI_DEVFN(0x14, 3),
925 /* base address location etc changed in SB800 */
926 retval
= piix4_setup_sb800(dev
, id
, 0);
931 * Try to register multiplexed main SMBus adapter,
932 * give up if we can't
934 retval
= piix4_add_adapters_sb800(dev
, retval
, notify_imc
);
938 retval
= piix4_setup(dev
, id
);
942 /* Try to register main SMBus adapter, give up if we can't */
943 retval
= piix4_add_adapter(dev
, retval
, false, 0, false, "",
944 &piix4_main_adapters
[0]);
949 /* Check for auxiliary SMBus on some AMD chipsets */
952 if (dev
->vendor
== PCI_VENDOR_ID_ATI
&&
953 dev
->device
== PCI_DEVICE_ID_ATI_SBX00_SMBUS
) {
954 if (dev
->revision
< 0x40) {
955 retval
= piix4_setup_aux(dev
, id
, 0x58);
957 /* SB800 added aux bus too */
958 retval
= piix4_setup_sb800(dev
, id
, 1);
962 if (dev
->vendor
== PCI_VENDOR_ID_AMD
&&
963 dev
->device
== PCI_DEVICE_ID_AMD_HUDSON2_SMBUS
) {
964 retval
= piix4_setup_sb800(dev
, id
, 1);
968 /* Try to add the aux adapter if it exists,
969 * piix4_add_adapter will clean up if this fails */
970 piix4_add_adapter(dev
, retval
, false, 0, false,
971 is_sb800
? piix4_aux_port_name_sb800
: "",
978 static void piix4_adap_remove(struct i2c_adapter
*adap
)
980 struct i2c_piix4_adapdata
*adapdata
= i2c_get_adapdata(adap
);
982 if (adapdata
->smba
) {
983 i2c_del_adapter(adap
);
984 if (adapdata
->port
== (0 << piix4_port_shift_sb800
))
985 release_region(adapdata
->smba
, SMBIOSIZE
);
991 static void piix4_remove(struct pci_dev
*dev
)
993 int port
= PIIX4_MAX_ADAPTERS
;
995 while (--port
>= 0) {
996 if (piix4_main_adapters
[port
]) {
997 piix4_adap_remove(piix4_main_adapters
[port
]);
998 piix4_main_adapters
[port
] = NULL
;
1002 if (piix4_aux_adapter
) {
1003 piix4_adap_remove(piix4_aux_adapter
);
1004 piix4_aux_adapter
= NULL
;
1008 static struct pci_driver piix4_driver
= {
1009 .name
= "piix4_smbus",
1010 .id_table
= piix4_ids
,
1011 .probe
= piix4_probe
,
1012 .remove
= piix4_remove
,
1015 module_pci_driver(piix4_driver
);
1017 MODULE_AUTHOR("Frodo Looijaard <frodol@dds.nl> and "
1018 "Philip Edelbrock <phil@netroedge.com>");
1019 MODULE_DESCRIPTION("PIIX4 SMBus driver");
1020 MODULE_LICENSE("GPL");