11da177e4SLinus Torvalds /* 21da177e4SLinus Torvalds Copyright (c) 1998 - 2002 Frodo Looijaard <frodol@dds.nl> and 31da177e4SLinus Torvalds Philip Edelbrock <phil@netroedge.com> 41da177e4SLinus Torvalds 51da177e4SLinus Torvalds This program is free software; you can redistribute it and/or modify 61da177e4SLinus Torvalds it under the terms of the GNU General Public License as published by 71da177e4SLinus Torvalds the Free Software Foundation; either version 2 of the License, or 81da177e4SLinus Torvalds (at your option) any later version. 91da177e4SLinus Torvalds 101da177e4SLinus Torvalds This program is distributed in the hope that it will be useful, 111da177e4SLinus Torvalds but WITHOUT ANY WARRANTY; without even the implied warranty of 121da177e4SLinus Torvalds MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 131da177e4SLinus Torvalds GNU General Public License for more details. 141da177e4SLinus Torvalds */ 151da177e4SLinus Torvalds 161da177e4SLinus Torvalds /* 171da177e4SLinus Torvalds Supports: 181da177e4SLinus Torvalds Intel PIIX4, 440MX 19506a8b6cSFlavio Leitner Serverworks OSB4, CSB5, CSB6, HT-1000, HT-1100 202a2f7404SAndrew Armenia ATI IXP200, IXP300, IXP400, SB600, SB700/SP5100, SB800 21032f708bSShane Huang AMD Hudson-2, ML, CZ 221da177e4SLinus Torvalds SMSC Victory66 231da177e4SLinus Torvalds 242a2f7404SAndrew Armenia Note: we assume there can only be one device, with one or more 252a2f7404SAndrew Armenia SMBus interfaces. 262fee61d2SChristian Fetzer The device can register multiple i2c_adapters (up to PIIX4_MAX_ADAPTERS). 272fee61d2SChristian Fetzer For devices supporting multiple ports the i2c_adapter should provide 282fee61d2SChristian Fetzer an i2c_algorithm to access them. 291da177e4SLinus Torvalds */ 301da177e4SLinus Torvalds 311da177e4SLinus Torvalds #include <linux/module.h> 321da177e4SLinus Torvalds #include <linux/moduleparam.h> 331da177e4SLinus Torvalds #include <linux/pci.h> 341da177e4SLinus Torvalds #include <linux/kernel.h> 351da177e4SLinus Torvalds #include <linux/delay.h> 361da177e4SLinus Torvalds #include <linux/stddef.h> 371da177e4SLinus Torvalds #include <linux/ioport.h> 381da177e4SLinus Torvalds #include <linux/i2c.h> 39c415b303SDaniel J Blueman #include <linux/slab.h> 401da177e4SLinus Torvalds #include <linux/dmi.h> 4154fb4a05SJean Delvare #include <linux/acpi.h> 4221782180SH Hartley Sweeten #include <linux/io.h> 432fee61d2SChristian Fetzer #include <linux/mutex.h> 441da177e4SLinus Torvalds 451da177e4SLinus Torvalds 461da177e4SLinus Torvalds /* PIIX4 SMBus address offsets */ 471da177e4SLinus Torvalds #define SMBHSTSTS (0 + piix4_smba) 481da177e4SLinus Torvalds #define SMBHSLVSTS (1 + piix4_smba) 491da177e4SLinus Torvalds #define SMBHSTCNT (2 + piix4_smba) 501da177e4SLinus Torvalds #define SMBHSTCMD (3 + piix4_smba) 511da177e4SLinus Torvalds #define SMBHSTADD (4 + piix4_smba) 521da177e4SLinus Torvalds #define SMBHSTDAT0 (5 + piix4_smba) 531da177e4SLinus Torvalds #define SMBHSTDAT1 (6 + piix4_smba) 541da177e4SLinus Torvalds #define SMBBLKDAT (7 + piix4_smba) 551da177e4SLinus Torvalds #define SMBSLVCNT (8 + piix4_smba) 561da177e4SLinus Torvalds #define SMBSHDWCMD (9 + piix4_smba) 571da177e4SLinus Torvalds #define SMBSLVEVT (0xA + piix4_smba) 581da177e4SLinus Torvalds #define SMBSLVDAT (0xC + piix4_smba) 591da177e4SLinus Torvalds 601da177e4SLinus Torvalds /* count for request_region */ 61f43128c7SRicardo Ribalda #define SMBIOSIZE 9 621da177e4SLinus Torvalds 631da177e4SLinus Torvalds /* PCI Address Constants */ 641da177e4SLinus Torvalds #define SMBBA 0x090 651da177e4SLinus Torvalds #define SMBHSTCFG 0x0D2 661da177e4SLinus Torvalds #define SMBSLVC 0x0D3 671da177e4SLinus Torvalds #define SMBSHDW1 0x0D4 681da177e4SLinus Torvalds #define SMBSHDW2 0x0D5 691da177e4SLinus Torvalds #define SMBREV 0x0D6 701da177e4SLinus Torvalds 711da177e4SLinus Torvalds /* Other settings */ 721da177e4SLinus Torvalds #define MAX_TIMEOUT 500 731da177e4SLinus Torvalds #define ENABLE_INT9 0 741da177e4SLinus Torvalds 751da177e4SLinus Torvalds /* PIIX4 constants */ 761da177e4SLinus Torvalds #define PIIX4_QUICK 0x00 771da177e4SLinus Torvalds #define PIIX4_BYTE 0x04 781da177e4SLinus Torvalds #define PIIX4_BYTE_DATA 0x08 791da177e4SLinus Torvalds #define PIIX4_WORD_DATA 0x0C 801da177e4SLinus Torvalds #define PIIX4_BLOCK_DATA 0x14 811da177e4SLinus Torvalds 82ca2061e1SChristian Fetzer /* Multi-port constants */ 83ca2061e1SChristian Fetzer #define PIIX4_MAX_ADAPTERS 4 84ca2061e1SChristian Fetzer 852fee61d2SChristian Fetzer /* SB800 constants */ 862fee61d2SChristian Fetzer #define SB800_PIIX4_SMB_IDX 0xcd6 872fee61d2SChristian Fetzer 8888fa2dfbSRicardo Ribalda Delgado #define KERNCZ_IMC_IDX 0x3e 8988fa2dfbSRicardo Ribalda Delgado #define KERNCZ_IMC_DATA 0x3f 9088fa2dfbSRicardo Ribalda Delgado 916befa3fdSJean Delvare /* 926befa3fdSJean Delvare * SB800 port is selected by bits 2:1 of the smb_en register (0x2c) 936befa3fdSJean Delvare * or the smb_sel register (0x2e), depending on bit 0 of register 0x2f. 946befa3fdSJean Delvare * Hudson-2/Bolton port is always selected by bits 2:1 of register 0x2f. 956befa3fdSJean Delvare */ 962fee61d2SChristian Fetzer #define SB800_PIIX4_PORT_IDX 0x2c 976befa3fdSJean Delvare #define SB800_PIIX4_PORT_IDX_ALT 0x2e 986befa3fdSJean Delvare #define SB800_PIIX4_PORT_IDX_SEL 0x2f 992fee61d2SChristian Fetzer #define SB800_PIIX4_PORT_IDX_MASK 0x06 1000fe16195SGuenter Roeck #define SB800_PIIX4_PORT_IDX_SHIFT 1 1010fe16195SGuenter Roeck 1020fe16195SGuenter Roeck /* On kerncz, SmBus0Sel is at bit 20:19 of PMx00 DecodeEn */ 1030fe16195SGuenter Roeck #define SB800_PIIX4_PORT_IDX_KERNCZ 0x02 1040fe16195SGuenter Roeck #define SB800_PIIX4_PORT_IDX_MASK_KERNCZ 0x18 1050fe16195SGuenter Roeck #define SB800_PIIX4_PORT_IDX_SHIFT_KERNCZ 3 1062fee61d2SChristian Fetzer 1071da177e4SLinus Torvalds /* insmod parameters */ 1081da177e4SLinus Torvalds 1091da177e4SLinus Torvalds /* If force is set to anything different from 0, we forcibly enable the 1101da177e4SLinus Torvalds PIIX4. DANGEROUS! */ 11160507095SJean Delvare static int force; 1121da177e4SLinus Torvalds module_param (force, int, 0); 1131da177e4SLinus Torvalds MODULE_PARM_DESC(force, "Forcibly enable the PIIX4. DANGEROUS!"); 1141da177e4SLinus Torvalds 1151da177e4SLinus Torvalds /* If force_addr is set to anything different from 0, we forcibly enable 1161da177e4SLinus Torvalds the PIIX4 at the given address. VERY DANGEROUS! */ 11760507095SJean Delvare static int force_addr; 118c78babccSDavid Howells module_param_hw(force_addr, int, ioport, 0); 1191da177e4SLinus Torvalds MODULE_PARM_DESC(force_addr, 1201da177e4SLinus Torvalds "Forcibly enable the PIIX4 at the given address. " 1211da177e4SLinus Torvalds "EXTREMELY DANGEROUS!"); 1221da177e4SLinus Torvalds 123b1c1759cSDavid Milburn static int srvrworks_csb5_delay; 124d6072f84SJean Delvare static struct pci_driver piix4_driver; 1251da177e4SLinus Torvalds 1260b255e92SBill Pemberton static const struct dmi_system_id piix4_dmi_blacklist[] = { 127c2fc54fcSJean Delvare { 128c2fc54fcSJean Delvare .ident = "Sapphire AM2RD790", 129c2fc54fcSJean Delvare .matches = { 130c2fc54fcSJean Delvare DMI_MATCH(DMI_BOARD_VENDOR, "SAPPHIRE Inc."), 131c2fc54fcSJean Delvare DMI_MATCH(DMI_BOARD_NAME, "PC-AM2RD790"), 132c2fc54fcSJean Delvare }, 133c2fc54fcSJean Delvare }, 134c2fc54fcSJean Delvare { 135c2fc54fcSJean Delvare .ident = "DFI Lanparty UT 790FX", 136c2fc54fcSJean Delvare .matches = { 137c2fc54fcSJean Delvare DMI_MATCH(DMI_BOARD_VENDOR, "DFI Inc."), 138c2fc54fcSJean Delvare DMI_MATCH(DMI_BOARD_NAME, "LP UT 790FX"), 139c2fc54fcSJean Delvare }, 140c2fc54fcSJean Delvare }, 141c2fc54fcSJean Delvare { } 142c2fc54fcSJean Delvare }; 143c2fc54fcSJean Delvare 144c2fc54fcSJean Delvare /* The IBM entry is in a separate table because we only check it 145c2fc54fcSJean Delvare on Intel-based systems */ 1460b255e92SBill Pemberton static const struct dmi_system_id piix4_dmi_ibm[] = { 1471da177e4SLinus Torvalds { 1481da177e4SLinus Torvalds .ident = "IBM", 1491da177e4SLinus Torvalds .matches = { DMI_MATCH(DMI_SYS_VENDOR, "IBM"), }, 1501da177e4SLinus Torvalds }, 1511da177e4SLinus Torvalds { }, 1521da177e4SLinus Torvalds }; 1531da177e4SLinus Torvalds 1546befa3fdSJean Delvare /* 1556befa3fdSJean Delvare * SB800 globals 1566befa3fdSJean Delvare * piix4_mutex_sb800 protects piix4_port_sel_sb800 and the pair 1576befa3fdSJean Delvare * of I/O ports at SB800_PIIX4_SMB_IDX. 1586befa3fdSJean Delvare */ 159a28e3517SJean Delvare static DEFINE_MUTEX(piix4_mutex_sb800); 1606befa3fdSJean Delvare static u8 piix4_port_sel_sb800; 1610fe16195SGuenter Roeck static u8 piix4_port_mask_sb800; 1620fe16195SGuenter Roeck static u8 piix4_port_shift_sb800; 163725d2e3fSChristian Fetzer static const char *piix4_main_port_names_sb800[PIIX4_MAX_ADAPTERS] = { 16452795f6fSJean Delvare " port 0", " port 2", " port 3", " port 4" 165725d2e3fSChristian Fetzer }; 16652795f6fSJean Delvare static const char *piix4_aux_port_name_sb800 = " port 1"; 167725d2e3fSChristian Fetzer 16814a8086dSAndrew Armenia struct i2c_piix4_adapdata { 16914a8086dSAndrew Armenia unsigned short smba; 1702fee61d2SChristian Fetzer 1712fee61d2SChristian Fetzer /* SB800 */ 1722fee61d2SChristian Fetzer bool sb800_main; 17388fa2dfbSRicardo Ribalda Delgado bool notify_imc; 17433f5ccc3SJean Delvare u8 port; /* Port number, shifted */ 17514a8086dSAndrew Armenia }; 17614a8086dSAndrew Armenia 1770b255e92SBill Pemberton static int piix4_setup(struct pci_dev *PIIX4_dev, 1781da177e4SLinus Torvalds const struct pci_device_id *id) 1791da177e4SLinus Torvalds { 1801da177e4SLinus Torvalds unsigned char temp; 18114a8086dSAndrew Armenia unsigned short piix4_smba; 1821da177e4SLinus Torvalds 183b1c1759cSDavid Milburn if ((PIIX4_dev->vendor == PCI_VENDOR_ID_SERVERWORKS) && 184b1c1759cSDavid Milburn (PIIX4_dev->device == PCI_DEVICE_ID_SERVERWORKS_CSB5)) 185b1c1759cSDavid Milburn srvrworks_csb5_delay = 1; 186b1c1759cSDavid Milburn 187c2fc54fcSJean Delvare /* On some motherboards, it was reported that accessing the SMBus 188c2fc54fcSJean Delvare caused severe hardware problems */ 189c2fc54fcSJean Delvare if (dmi_check_system(piix4_dmi_blacklist)) { 190c2fc54fcSJean Delvare dev_err(&PIIX4_dev->dev, 191c2fc54fcSJean Delvare "Accessing the SMBus on this system is unsafe!\n"); 192c2fc54fcSJean Delvare return -EPERM; 193c2fc54fcSJean Delvare } 194c2fc54fcSJean Delvare 1951da177e4SLinus Torvalds /* Don't access SMBus on IBM systems which get corrupted eeproms */ 196c2fc54fcSJean Delvare if (dmi_check_system(piix4_dmi_ibm) && 1971da177e4SLinus Torvalds PIIX4_dev->vendor == PCI_VENDOR_ID_INTEL) { 198f9ba6c04SJean Delvare dev_err(&PIIX4_dev->dev, "IBM system detected; this module " 1991da177e4SLinus Torvalds "may corrupt your serial eeprom! Refusing to load " 2001da177e4SLinus Torvalds "module!\n"); 2011da177e4SLinus Torvalds return -EPERM; 2021da177e4SLinus Torvalds } 2031da177e4SLinus Torvalds 2041da177e4SLinus Torvalds /* Determine the address of the SMBus areas */ 2051da177e4SLinus Torvalds if (force_addr) { 2061da177e4SLinus Torvalds piix4_smba = force_addr & 0xfff0; 2071da177e4SLinus Torvalds force = 0; 2081da177e4SLinus Torvalds } else { 2091da177e4SLinus Torvalds pci_read_config_word(PIIX4_dev, SMBBA, &piix4_smba); 2101da177e4SLinus Torvalds piix4_smba &= 0xfff0; 2111da177e4SLinus Torvalds if(piix4_smba == 0) { 212fa63cd56SJean Delvare dev_err(&PIIX4_dev->dev, "SMBus base address " 2131da177e4SLinus Torvalds "uninitialized - upgrade BIOS or use " 2141da177e4SLinus Torvalds "force_addr=0xaddr\n"); 2151da177e4SLinus Torvalds return -ENODEV; 2161da177e4SLinus Torvalds } 2171da177e4SLinus Torvalds } 2181da177e4SLinus Torvalds 21954fb4a05SJean Delvare if (acpi_check_region(piix4_smba, SMBIOSIZE, piix4_driver.name)) 22018669eabSJean Delvare return -ENODEV; 22154fb4a05SJean Delvare 222d6072f84SJean Delvare if (!request_region(piix4_smba, SMBIOSIZE, piix4_driver.name)) { 223fa63cd56SJean Delvare dev_err(&PIIX4_dev->dev, "SMBus region 0x%x already in use!\n", 2241da177e4SLinus Torvalds piix4_smba); 225fa63cd56SJean Delvare return -EBUSY; 2261da177e4SLinus Torvalds } 2271da177e4SLinus Torvalds 2281da177e4SLinus Torvalds pci_read_config_byte(PIIX4_dev, SMBHSTCFG, &temp); 2291da177e4SLinus Torvalds 2301da177e4SLinus Torvalds /* If force_addr is set, we program the new address here. Just to make 2311da177e4SLinus Torvalds sure, we disable the PIIX4 first. */ 2321da177e4SLinus Torvalds if (force_addr) { 2331da177e4SLinus Torvalds pci_write_config_byte(PIIX4_dev, SMBHSTCFG, temp & 0xfe); 2341da177e4SLinus Torvalds pci_write_config_word(PIIX4_dev, SMBBA, piix4_smba); 2351da177e4SLinus Torvalds pci_write_config_byte(PIIX4_dev, SMBHSTCFG, temp | 0x01); 2361da177e4SLinus Torvalds dev_info(&PIIX4_dev->dev, "WARNING: SMBus interface set to " 2371da177e4SLinus Torvalds "new address %04x!\n", piix4_smba); 2381da177e4SLinus Torvalds } else if ((temp & 1) == 0) { 2391da177e4SLinus Torvalds if (force) { 2401da177e4SLinus Torvalds /* This should never need to be done, but has been 2411da177e4SLinus Torvalds * noted that many Dell machines have the SMBus 2421da177e4SLinus Torvalds * interface on the PIIX4 disabled!? NOTE: This assumes 2431da177e4SLinus Torvalds * I/O space and other allocations WERE done by the 2441da177e4SLinus Torvalds * Bios! Don't complain if your hardware does weird 2451da177e4SLinus Torvalds * things after enabling this. :') Check for Bios 2461da177e4SLinus Torvalds * updates before resorting to this. 2471da177e4SLinus Torvalds */ 2481da177e4SLinus Torvalds pci_write_config_byte(PIIX4_dev, SMBHSTCFG, 2491da177e4SLinus Torvalds temp | 1); 2508117e41eSJoe Perches dev_notice(&PIIX4_dev->dev, 2518117e41eSJoe Perches "WARNING: SMBus interface has been FORCEFULLY ENABLED!\n"); 2521da177e4SLinus Torvalds } else { 2531da177e4SLinus Torvalds dev_err(&PIIX4_dev->dev, 25466f8a8ffSJean Delvare "SMBus Host Controller not enabled!\n"); 2551da177e4SLinus Torvalds release_region(piix4_smba, SMBIOSIZE); 2561da177e4SLinus Torvalds return -ENODEV; 2571da177e4SLinus Torvalds } 2581da177e4SLinus Torvalds } 2591da177e4SLinus Torvalds 26054aaa1caSRudolf Marek if (((temp & 0x0E) == 8) || ((temp & 0x0E) == 2)) 26166f8a8ffSJean Delvare dev_dbg(&PIIX4_dev->dev, "Using IRQ for SMBus\n"); 2621da177e4SLinus Torvalds else if ((temp & 0x0E) == 0) 26366f8a8ffSJean Delvare dev_dbg(&PIIX4_dev->dev, "Using SMI# for SMBus\n"); 2641da177e4SLinus Torvalds else 2651da177e4SLinus Torvalds dev_err(&PIIX4_dev->dev, "Illegal Interrupt configuration " 2661da177e4SLinus Torvalds "(or code out of date)!\n"); 2671da177e4SLinus Torvalds 2681da177e4SLinus Torvalds pci_read_config_byte(PIIX4_dev, SMBREV, &temp); 269fa63cd56SJean Delvare dev_info(&PIIX4_dev->dev, 270fa63cd56SJean Delvare "SMBus Host Controller at 0x%x, revision %d\n", 271fa63cd56SJean Delvare piix4_smba, temp); 2721da177e4SLinus Torvalds 27314a8086dSAndrew Armenia return piix4_smba; 2741da177e4SLinus Torvalds } 2751da177e4SLinus Torvalds 2760b255e92SBill Pemberton static int piix4_setup_sb800(struct pci_dev *PIIX4_dev, 277a94dd00fSRudolf Marek const struct pci_device_id *id, u8 aux) 27887e1960eSShane Huang { 27914a8086dSAndrew Armenia unsigned short piix4_smba; 2806befa3fdSJean Delvare u8 smba_en_lo, smba_en_hi, smb_en, smb_en_status, port_sel; 281032f708bSShane Huang u8 i2ccfg, i2ccfg_offset = 0x10; 28287e1960eSShane Huang 2833806e94bSCrane Cai /* SB800 and later SMBus does not support forcing address */ 28487e1960eSShane Huang if (force || force_addr) { 2853806e94bSCrane Cai dev_err(&PIIX4_dev->dev, "SMBus does not support " 28687e1960eSShane Huang "forcing address!\n"); 28787e1960eSShane Huang return -EINVAL; 28887e1960eSShane Huang } 28987e1960eSShane Huang 29087e1960eSShane Huang /* Determine the address of the SMBus areas */ 291032f708bSShane Huang if ((PIIX4_dev->vendor == PCI_VENDOR_ID_AMD && 292032f708bSShane Huang PIIX4_dev->device == PCI_DEVICE_ID_AMD_HUDSON2_SMBUS && 293032f708bSShane Huang PIIX4_dev->revision >= 0x41) || 294032f708bSShane Huang (PIIX4_dev->vendor == PCI_VENDOR_ID_AMD && 295bcb29994SVincent Wan PIIX4_dev->device == PCI_DEVICE_ID_AMD_KERNCZ_SMBUS && 296032f708bSShane Huang PIIX4_dev->revision >= 0x49)) 297032f708bSShane Huang smb_en = 0x00; 298032f708bSShane Huang else 299a94dd00fSRudolf Marek smb_en = (aux) ? 0x28 : 0x2c; 300a94dd00fSRudolf Marek 301a28e3517SJean Delvare mutex_lock(&piix4_mutex_sb800); 3022fee61d2SChristian Fetzer outb_p(smb_en, SB800_PIIX4_SMB_IDX); 3032fee61d2SChristian Fetzer smba_en_lo = inb_p(SB800_PIIX4_SMB_IDX + 1); 3042fee61d2SChristian Fetzer outb_p(smb_en + 1, SB800_PIIX4_SMB_IDX); 3052fee61d2SChristian Fetzer smba_en_hi = inb_p(SB800_PIIX4_SMB_IDX + 1); 306a28e3517SJean Delvare mutex_unlock(&piix4_mutex_sb800); 30787e1960eSShane Huang 308032f708bSShane Huang if (!smb_en) { 309032f708bSShane Huang smb_en_status = smba_en_lo & 0x10; 310032f708bSShane Huang piix4_smba = smba_en_hi << 8; 311032f708bSShane Huang if (aux) 312032f708bSShane Huang piix4_smba |= 0x20; 313032f708bSShane Huang } else { 314032f708bSShane Huang smb_en_status = smba_en_lo & 0x01; 315032f708bSShane Huang piix4_smba = ((smba_en_hi << 8) | smba_en_lo) & 0xffe0; 316032f708bSShane Huang } 317032f708bSShane Huang 318032f708bSShane Huang if (!smb_en_status) { 31987e1960eSShane Huang dev_err(&PIIX4_dev->dev, 32066f8a8ffSJean Delvare "SMBus Host Controller not enabled!\n"); 32187e1960eSShane Huang return -ENODEV; 32287e1960eSShane Huang } 32387e1960eSShane Huang 32487e1960eSShane Huang if (acpi_check_region(piix4_smba, SMBIOSIZE, piix4_driver.name)) 32518669eabSJean Delvare return -ENODEV; 32687e1960eSShane Huang 32787e1960eSShane Huang if (!request_region(piix4_smba, SMBIOSIZE, piix4_driver.name)) { 32887e1960eSShane Huang dev_err(&PIIX4_dev->dev, "SMBus region 0x%x already in use!\n", 32987e1960eSShane Huang piix4_smba); 33087e1960eSShane Huang return -EBUSY; 33187e1960eSShane Huang } 33287e1960eSShane Huang 333a94dd00fSRudolf Marek /* Aux SMBus does not support IRQ information */ 334a94dd00fSRudolf Marek if (aux) { 335a94dd00fSRudolf Marek dev_info(&PIIX4_dev->dev, 33685fd0fe6SShane Huang "Auxiliary SMBus Host Controller at 0x%x\n", 33785fd0fe6SShane Huang piix4_smba); 338a94dd00fSRudolf Marek return piix4_smba; 339a94dd00fSRudolf Marek } 340a94dd00fSRudolf Marek 34187e1960eSShane Huang /* Request the SMBus I2C bus config region */ 34287e1960eSShane Huang if (!request_region(piix4_smba + i2ccfg_offset, 1, "i2ccfg")) { 34387e1960eSShane Huang dev_err(&PIIX4_dev->dev, "SMBus I2C bus config region " 34487e1960eSShane Huang "0x%x already in use!\n", piix4_smba + i2ccfg_offset); 34587e1960eSShane Huang release_region(piix4_smba, SMBIOSIZE); 34687e1960eSShane Huang return -EBUSY; 34787e1960eSShane Huang } 34887e1960eSShane Huang i2ccfg = inb_p(piix4_smba + i2ccfg_offset); 34987e1960eSShane Huang release_region(piix4_smba + i2ccfg_offset, 1); 35087e1960eSShane Huang 35187e1960eSShane Huang if (i2ccfg & 1) 35266f8a8ffSJean Delvare dev_dbg(&PIIX4_dev->dev, "Using IRQ for SMBus\n"); 35387e1960eSShane Huang else 35466f8a8ffSJean Delvare dev_dbg(&PIIX4_dev->dev, "Using SMI# for SMBus\n"); 35587e1960eSShane Huang 35687e1960eSShane Huang dev_info(&PIIX4_dev->dev, 35787e1960eSShane Huang "SMBus Host Controller at 0x%x, revision %d\n", 35887e1960eSShane Huang piix4_smba, i2ccfg >> 4); 35987e1960eSShane Huang 3606befa3fdSJean Delvare /* Find which register is used for port selection */ 3616befa3fdSJean Delvare if (PIIX4_dev->vendor == PCI_VENDOR_ID_AMD) { 3620fe16195SGuenter Roeck switch (PIIX4_dev->device) { 3630fe16195SGuenter Roeck case PCI_DEVICE_ID_AMD_KERNCZ_SMBUS: 3640fe16195SGuenter Roeck piix4_port_sel_sb800 = SB800_PIIX4_PORT_IDX_KERNCZ; 3650fe16195SGuenter Roeck piix4_port_mask_sb800 = SB800_PIIX4_PORT_IDX_MASK_KERNCZ; 3660fe16195SGuenter Roeck piix4_port_shift_sb800 = SB800_PIIX4_PORT_IDX_SHIFT_KERNCZ; 3670fe16195SGuenter Roeck break; 3680fe16195SGuenter Roeck case PCI_DEVICE_ID_AMD_HUDSON2_SMBUS: 3690fe16195SGuenter Roeck default: 3706befa3fdSJean Delvare piix4_port_sel_sb800 = SB800_PIIX4_PORT_IDX_ALT; 3710fe16195SGuenter Roeck piix4_port_mask_sb800 = SB800_PIIX4_PORT_IDX_MASK; 3720fe16195SGuenter Roeck piix4_port_shift_sb800 = SB800_PIIX4_PORT_IDX_SHIFT; 3730fe16195SGuenter Roeck break; 3740fe16195SGuenter Roeck } 3756befa3fdSJean Delvare } else { 3766befa3fdSJean Delvare mutex_lock(&piix4_mutex_sb800); 3776befa3fdSJean Delvare outb_p(SB800_PIIX4_PORT_IDX_SEL, SB800_PIIX4_SMB_IDX); 3786befa3fdSJean Delvare port_sel = inb_p(SB800_PIIX4_SMB_IDX + 1); 3796befa3fdSJean Delvare piix4_port_sel_sb800 = (port_sel & 0x01) ? 3806befa3fdSJean Delvare SB800_PIIX4_PORT_IDX_ALT : 3816befa3fdSJean Delvare SB800_PIIX4_PORT_IDX; 3820fe16195SGuenter Roeck piix4_port_mask_sb800 = SB800_PIIX4_PORT_IDX_MASK; 3830fe16195SGuenter Roeck piix4_port_shift_sb800 = SB800_PIIX4_PORT_IDX_SHIFT; 3846befa3fdSJean Delvare mutex_unlock(&piix4_mutex_sb800); 3856befa3fdSJean Delvare } 3866befa3fdSJean Delvare 3876befa3fdSJean Delvare dev_info(&PIIX4_dev->dev, 3886befa3fdSJean Delvare "Using register 0x%02x for SMBus port selection\n", 3896befa3fdSJean Delvare (unsigned int)piix4_port_sel_sb800); 3906befa3fdSJean Delvare 39114a8086dSAndrew Armenia return piix4_smba; 39287e1960eSShane Huang } 39387e1960eSShane Huang 3940b255e92SBill Pemberton static int piix4_setup_aux(struct pci_dev *PIIX4_dev, 3952a2f7404SAndrew Armenia const struct pci_device_id *id, 3962a2f7404SAndrew Armenia unsigned short base_reg_addr) 3972a2f7404SAndrew Armenia { 3982a2f7404SAndrew Armenia /* Set up auxiliary SMBus controllers found on some 3992a2f7404SAndrew Armenia * AMD chipsets e.g. SP5100 (SB700 derivative) */ 4002a2f7404SAndrew Armenia 4012a2f7404SAndrew Armenia unsigned short piix4_smba; 4022a2f7404SAndrew Armenia 4032a2f7404SAndrew Armenia /* Read address of auxiliary SMBus controller */ 4042a2f7404SAndrew Armenia pci_read_config_word(PIIX4_dev, base_reg_addr, &piix4_smba); 4052a2f7404SAndrew Armenia if ((piix4_smba & 1) == 0) { 4062a2f7404SAndrew Armenia dev_dbg(&PIIX4_dev->dev, 4072a2f7404SAndrew Armenia "Auxiliary SMBus controller not enabled\n"); 4082a2f7404SAndrew Armenia return -ENODEV; 4092a2f7404SAndrew Armenia } 4102a2f7404SAndrew Armenia 4112a2f7404SAndrew Armenia piix4_smba &= 0xfff0; 4122a2f7404SAndrew Armenia if (piix4_smba == 0) { 4132a2f7404SAndrew Armenia dev_dbg(&PIIX4_dev->dev, 4142a2f7404SAndrew Armenia "Auxiliary SMBus base address uninitialized\n"); 4152a2f7404SAndrew Armenia return -ENODEV; 4162a2f7404SAndrew Armenia } 4172a2f7404SAndrew Armenia 4182a2f7404SAndrew Armenia if (acpi_check_region(piix4_smba, SMBIOSIZE, piix4_driver.name)) 4192a2f7404SAndrew Armenia return -ENODEV; 4202a2f7404SAndrew Armenia 4212a2f7404SAndrew Armenia if (!request_region(piix4_smba, SMBIOSIZE, piix4_driver.name)) { 4222a2f7404SAndrew Armenia dev_err(&PIIX4_dev->dev, "Auxiliary SMBus region 0x%x " 4232a2f7404SAndrew Armenia "already in use!\n", piix4_smba); 4242a2f7404SAndrew Armenia return -EBUSY; 4252a2f7404SAndrew Armenia } 4262a2f7404SAndrew Armenia 4272a2f7404SAndrew Armenia dev_info(&PIIX4_dev->dev, 4282a2f7404SAndrew Armenia "Auxiliary SMBus Host Controller at 0x%x\n", 4292a2f7404SAndrew Armenia piix4_smba); 4302a2f7404SAndrew Armenia 4312a2f7404SAndrew Armenia return piix4_smba; 4322a2f7404SAndrew Armenia } 4332a2f7404SAndrew Armenia 434e154bf6fSAndrew Armenia static int piix4_transaction(struct i2c_adapter *piix4_adapter) 4351da177e4SLinus Torvalds { 436e154bf6fSAndrew Armenia struct i2c_piix4_adapdata *adapdata = i2c_get_adapdata(piix4_adapter); 437e154bf6fSAndrew Armenia unsigned short piix4_smba = adapdata->smba; 4381da177e4SLinus Torvalds int temp; 4391da177e4SLinus Torvalds int result = 0; 4401da177e4SLinus Torvalds int timeout = 0; 4411da177e4SLinus Torvalds 442e154bf6fSAndrew Armenia dev_dbg(&piix4_adapter->dev, "Transaction (pre): CNT=%02x, CMD=%02x, " 4431da177e4SLinus Torvalds "ADD=%02x, DAT0=%02x, DAT1=%02x\n", inb_p(SMBHSTCNT), 4441da177e4SLinus Torvalds inb_p(SMBHSTCMD), inb_p(SMBHSTADD), inb_p(SMBHSTDAT0), 4451da177e4SLinus Torvalds inb_p(SMBHSTDAT1)); 4461da177e4SLinus Torvalds 4471da177e4SLinus Torvalds /* Make sure the SMBus host is ready to start transmitting */ 4481da177e4SLinus Torvalds if ((temp = inb_p(SMBHSTSTS)) != 0x00) { 449e154bf6fSAndrew Armenia dev_dbg(&piix4_adapter->dev, "SMBus busy (%02x). " 4501da177e4SLinus Torvalds "Resetting...\n", temp); 4511da177e4SLinus Torvalds outb_p(temp, SMBHSTSTS); 4521da177e4SLinus Torvalds if ((temp = inb_p(SMBHSTSTS)) != 0x00) { 453e154bf6fSAndrew Armenia dev_err(&piix4_adapter->dev, "Failed! (%02x)\n", temp); 45497140342SDavid Brownell return -EBUSY; 4551da177e4SLinus Torvalds } else { 456e154bf6fSAndrew Armenia dev_dbg(&piix4_adapter->dev, "Successful!\n"); 4571da177e4SLinus Torvalds } 4581da177e4SLinus Torvalds } 4591da177e4SLinus Torvalds 4601da177e4SLinus Torvalds /* start the transaction by setting bit 6 */ 4611da177e4SLinus Torvalds outb_p(inb(SMBHSTCNT) | 0x040, SMBHSTCNT); 4621da177e4SLinus Torvalds 4631da177e4SLinus Torvalds /* We will always wait for a fraction of a second! (See PIIX4 docs errata) */ 464b1c1759cSDavid Milburn if (srvrworks_csb5_delay) /* Extra delay for SERVERWORKS_CSB5 */ 465*0e89b2feSGuenter Roeck usleep_range(2000, 2100); 466b1c1759cSDavid Milburn else 467*0e89b2feSGuenter Roeck usleep_range(250, 500); 468b1c1759cSDavid Milburn 469b6a31950SRoel Kluin while ((++timeout < MAX_TIMEOUT) && 470b1c1759cSDavid Milburn ((temp = inb_p(SMBHSTSTS)) & 0x01)) 471*0e89b2feSGuenter Roeck usleep_range(250, 500); 4721da177e4SLinus Torvalds 4731da177e4SLinus Torvalds /* If the SMBus is still busy, we give up */ 474b6a31950SRoel Kluin if (timeout == MAX_TIMEOUT) { 475e154bf6fSAndrew Armenia dev_err(&piix4_adapter->dev, "SMBus Timeout!\n"); 47697140342SDavid Brownell result = -ETIMEDOUT; 4771da177e4SLinus Torvalds } 4781da177e4SLinus Torvalds 4791da177e4SLinus Torvalds if (temp & 0x10) { 48097140342SDavid Brownell result = -EIO; 481e154bf6fSAndrew Armenia dev_err(&piix4_adapter->dev, "Error: Failed bus transaction\n"); 4821da177e4SLinus Torvalds } 4831da177e4SLinus Torvalds 4841da177e4SLinus Torvalds if (temp & 0x08) { 48597140342SDavid Brownell result = -EIO; 486e154bf6fSAndrew Armenia dev_dbg(&piix4_adapter->dev, "Bus collision! SMBus may be " 4871da177e4SLinus Torvalds "locked until next hard reset. (sorry!)\n"); 4881da177e4SLinus Torvalds /* Clock stops and slave is stuck in mid-transmission */ 4891da177e4SLinus Torvalds } 4901da177e4SLinus Torvalds 4911da177e4SLinus Torvalds if (temp & 0x04) { 49297140342SDavid Brownell result = -ENXIO; 493e154bf6fSAndrew Armenia dev_dbg(&piix4_adapter->dev, "Error: no response!\n"); 4941da177e4SLinus Torvalds } 4951da177e4SLinus Torvalds 4961da177e4SLinus Torvalds if (inb_p(SMBHSTSTS) != 0x00) 4971da177e4SLinus Torvalds outb_p(inb(SMBHSTSTS), SMBHSTSTS); 4981da177e4SLinus Torvalds 4991da177e4SLinus Torvalds if ((temp = inb_p(SMBHSTSTS)) != 0x00) { 500e154bf6fSAndrew Armenia dev_err(&piix4_adapter->dev, "Failed reset at end of " 5011da177e4SLinus Torvalds "transaction (%02x)\n", temp); 5021da177e4SLinus Torvalds } 503e154bf6fSAndrew Armenia dev_dbg(&piix4_adapter->dev, "Transaction (post): CNT=%02x, CMD=%02x, " 5041da177e4SLinus Torvalds "ADD=%02x, DAT0=%02x, DAT1=%02x\n", inb_p(SMBHSTCNT), 5051da177e4SLinus Torvalds inb_p(SMBHSTCMD), inb_p(SMBHSTADD), inb_p(SMBHSTDAT0), 5061da177e4SLinus Torvalds inb_p(SMBHSTDAT1)); 5071da177e4SLinus Torvalds return result; 5081da177e4SLinus Torvalds } 5091da177e4SLinus Torvalds 51097140342SDavid Brownell /* Return negative errno on error. */ 5111da177e4SLinus Torvalds static s32 piix4_access(struct i2c_adapter * adap, u16 addr, 5121da177e4SLinus Torvalds unsigned short flags, char read_write, 5131da177e4SLinus Torvalds u8 command, int size, union i2c_smbus_data * data) 5141da177e4SLinus Torvalds { 51514a8086dSAndrew Armenia struct i2c_piix4_adapdata *adapdata = i2c_get_adapdata(adap); 51614a8086dSAndrew Armenia unsigned short piix4_smba = adapdata->smba; 5171da177e4SLinus Torvalds int i, len; 51897140342SDavid Brownell int status; 5191da177e4SLinus Torvalds 5201da177e4SLinus Torvalds switch (size) { 5211da177e4SLinus Torvalds case I2C_SMBUS_QUICK: 522fa63cd56SJean Delvare outb_p((addr << 1) | read_write, 5231da177e4SLinus Torvalds SMBHSTADD); 5241da177e4SLinus Torvalds size = PIIX4_QUICK; 5251da177e4SLinus Torvalds break; 5261da177e4SLinus Torvalds case I2C_SMBUS_BYTE: 527fa63cd56SJean Delvare outb_p((addr << 1) | read_write, 5281da177e4SLinus Torvalds SMBHSTADD); 5291da177e4SLinus Torvalds if (read_write == I2C_SMBUS_WRITE) 5301da177e4SLinus Torvalds outb_p(command, SMBHSTCMD); 5311da177e4SLinus Torvalds size = PIIX4_BYTE; 5321da177e4SLinus Torvalds break; 5331da177e4SLinus Torvalds case I2C_SMBUS_BYTE_DATA: 534fa63cd56SJean Delvare outb_p((addr << 1) | read_write, 5351da177e4SLinus Torvalds SMBHSTADD); 5361da177e4SLinus Torvalds outb_p(command, SMBHSTCMD); 5371da177e4SLinus Torvalds if (read_write == I2C_SMBUS_WRITE) 5381da177e4SLinus Torvalds outb_p(data->byte, SMBHSTDAT0); 5391da177e4SLinus Torvalds size = PIIX4_BYTE_DATA; 5401da177e4SLinus Torvalds break; 5411da177e4SLinus Torvalds case I2C_SMBUS_WORD_DATA: 542fa63cd56SJean Delvare outb_p((addr << 1) | read_write, 5431da177e4SLinus Torvalds SMBHSTADD); 5441da177e4SLinus Torvalds outb_p(command, SMBHSTCMD); 5451da177e4SLinus Torvalds if (read_write == I2C_SMBUS_WRITE) { 5461da177e4SLinus Torvalds outb_p(data->word & 0xff, SMBHSTDAT0); 5471da177e4SLinus Torvalds outb_p((data->word & 0xff00) >> 8, SMBHSTDAT1); 5481da177e4SLinus Torvalds } 5491da177e4SLinus Torvalds size = PIIX4_WORD_DATA; 5501da177e4SLinus Torvalds break; 5511da177e4SLinus Torvalds case I2C_SMBUS_BLOCK_DATA: 552fa63cd56SJean Delvare outb_p((addr << 1) | read_write, 5531da177e4SLinus Torvalds SMBHSTADD); 5541da177e4SLinus Torvalds outb_p(command, SMBHSTCMD); 5551da177e4SLinus Torvalds if (read_write == I2C_SMBUS_WRITE) { 5561da177e4SLinus Torvalds len = data->block[0]; 557fa63cd56SJean Delvare if (len == 0 || len > I2C_SMBUS_BLOCK_MAX) 558fa63cd56SJean Delvare return -EINVAL; 5591da177e4SLinus Torvalds outb_p(len, SMBHSTDAT0); 560d7a4c763SWolfram Sang inb_p(SMBHSTCNT); /* Reset SMBBLKDAT */ 5611da177e4SLinus Torvalds for (i = 1; i <= len; i++) 5621da177e4SLinus Torvalds outb_p(data->block[i], SMBBLKDAT); 5631da177e4SLinus Torvalds } 5641da177e4SLinus Torvalds size = PIIX4_BLOCK_DATA; 5651da177e4SLinus Torvalds break; 566ac7fc4fbSJean Delvare default: 567ac7fc4fbSJean Delvare dev_warn(&adap->dev, "Unsupported transaction %d\n", size); 568ac7fc4fbSJean Delvare return -EOPNOTSUPP; 5691da177e4SLinus Torvalds } 5701da177e4SLinus Torvalds 5711da177e4SLinus Torvalds outb_p((size & 0x1C) + (ENABLE_INT9 & 1), SMBHSTCNT); 5721da177e4SLinus Torvalds 573e154bf6fSAndrew Armenia status = piix4_transaction(adap); 57497140342SDavid Brownell if (status) 57597140342SDavid Brownell return status; 5761da177e4SLinus Torvalds 5771da177e4SLinus Torvalds if ((read_write == I2C_SMBUS_WRITE) || (size == PIIX4_QUICK)) 5781da177e4SLinus Torvalds return 0; 5791da177e4SLinus Torvalds 5801da177e4SLinus Torvalds 5811da177e4SLinus Torvalds switch (size) { 5823578a075SJean Delvare case PIIX4_BYTE: 5831da177e4SLinus Torvalds case PIIX4_BYTE_DATA: 5841da177e4SLinus Torvalds data->byte = inb_p(SMBHSTDAT0); 5851da177e4SLinus Torvalds break; 5861da177e4SLinus Torvalds case PIIX4_WORD_DATA: 5871da177e4SLinus Torvalds data->word = inb_p(SMBHSTDAT0) + (inb_p(SMBHSTDAT1) << 8); 5881da177e4SLinus Torvalds break; 5891da177e4SLinus Torvalds case PIIX4_BLOCK_DATA: 5901da177e4SLinus Torvalds data->block[0] = inb_p(SMBHSTDAT0); 591fa63cd56SJean Delvare if (data->block[0] == 0 || data->block[0] > I2C_SMBUS_BLOCK_MAX) 592fa63cd56SJean Delvare return -EPROTO; 593d7a4c763SWolfram Sang inb_p(SMBHSTCNT); /* Reset SMBBLKDAT */ 5941da177e4SLinus Torvalds for (i = 1; i <= data->block[0]; i++) 5951da177e4SLinus Torvalds data->block[i] = inb_p(SMBBLKDAT); 5961da177e4SLinus Torvalds break; 5971da177e4SLinus Torvalds } 5981da177e4SLinus Torvalds return 0; 5991da177e4SLinus Torvalds } 6001da177e4SLinus Torvalds 60188fa2dfbSRicardo Ribalda Delgado static uint8_t piix4_imc_read(uint8_t idx) 60288fa2dfbSRicardo Ribalda Delgado { 60388fa2dfbSRicardo Ribalda Delgado outb_p(idx, KERNCZ_IMC_IDX); 60488fa2dfbSRicardo Ribalda Delgado return inb_p(KERNCZ_IMC_DATA); 60588fa2dfbSRicardo Ribalda Delgado } 60688fa2dfbSRicardo Ribalda Delgado 60788fa2dfbSRicardo Ribalda Delgado static void piix4_imc_write(uint8_t idx, uint8_t value) 60888fa2dfbSRicardo Ribalda Delgado { 60988fa2dfbSRicardo Ribalda Delgado outb_p(idx, KERNCZ_IMC_IDX); 61088fa2dfbSRicardo Ribalda Delgado outb_p(value, KERNCZ_IMC_DATA); 61188fa2dfbSRicardo Ribalda Delgado } 61288fa2dfbSRicardo Ribalda Delgado 61388fa2dfbSRicardo Ribalda Delgado static int piix4_imc_sleep(void) 61488fa2dfbSRicardo Ribalda Delgado { 61588fa2dfbSRicardo Ribalda Delgado int timeout = MAX_TIMEOUT; 61688fa2dfbSRicardo Ribalda Delgado 61788fa2dfbSRicardo Ribalda Delgado if (!request_muxed_region(KERNCZ_IMC_IDX, 2, "smbus_kerncz_imc")) 61888fa2dfbSRicardo Ribalda Delgado return -EBUSY; 61988fa2dfbSRicardo Ribalda Delgado 62088fa2dfbSRicardo Ribalda Delgado /* clear response register */ 62188fa2dfbSRicardo Ribalda Delgado piix4_imc_write(0x82, 0x00); 62288fa2dfbSRicardo Ribalda Delgado /* request ownership flag */ 62388fa2dfbSRicardo Ribalda Delgado piix4_imc_write(0x83, 0xB4); 62488fa2dfbSRicardo Ribalda Delgado /* kick off IMC Mailbox command 96 */ 62588fa2dfbSRicardo Ribalda Delgado piix4_imc_write(0x80, 0x96); 62688fa2dfbSRicardo Ribalda Delgado 62788fa2dfbSRicardo Ribalda Delgado while (timeout--) { 62888fa2dfbSRicardo Ribalda Delgado if (piix4_imc_read(0x82) == 0xfa) { 62988fa2dfbSRicardo Ribalda Delgado release_region(KERNCZ_IMC_IDX, 2); 63088fa2dfbSRicardo Ribalda Delgado return 0; 63188fa2dfbSRicardo Ribalda Delgado } 63288fa2dfbSRicardo Ribalda Delgado usleep_range(1000, 2000); 63388fa2dfbSRicardo Ribalda Delgado } 63488fa2dfbSRicardo Ribalda Delgado 63588fa2dfbSRicardo Ribalda Delgado release_region(KERNCZ_IMC_IDX, 2); 63688fa2dfbSRicardo Ribalda Delgado return -ETIMEDOUT; 63788fa2dfbSRicardo Ribalda Delgado } 63888fa2dfbSRicardo Ribalda Delgado 63988fa2dfbSRicardo Ribalda Delgado static void piix4_imc_wakeup(void) 64088fa2dfbSRicardo Ribalda Delgado { 64188fa2dfbSRicardo Ribalda Delgado int timeout = MAX_TIMEOUT; 64288fa2dfbSRicardo Ribalda Delgado 64388fa2dfbSRicardo Ribalda Delgado if (!request_muxed_region(KERNCZ_IMC_IDX, 2, "smbus_kerncz_imc")) 64488fa2dfbSRicardo Ribalda Delgado return; 64588fa2dfbSRicardo Ribalda Delgado 64688fa2dfbSRicardo Ribalda Delgado /* clear response register */ 64788fa2dfbSRicardo Ribalda Delgado piix4_imc_write(0x82, 0x00); 64888fa2dfbSRicardo Ribalda Delgado /* release ownership flag */ 64988fa2dfbSRicardo Ribalda Delgado piix4_imc_write(0x83, 0xB5); 65088fa2dfbSRicardo Ribalda Delgado /* kick off IMC Mailbox command 96 */ 65188fa2dfbSRicardo Ribalda Delgado piix4_imc_write(0x80, 0x96); 65288fa2dfbSRicardo Ribalda Delgado 65388fa2dfbSRicardo Ribalda Delgado while (timeout--) { 65488fa2dfbSRicardo Ribalda Delgado if (piix4_imc_read(0x82) == 0xfa) 65588fa2dfbSRicardo Ribalda Delgado break; 65688fa2dfbSRicardo Ribalda Delgado usleep_range(1000, 2000); 65788fa2dfbSRicardo Ribalda Delgado } 65888fa2dfbSRicardo Ribalda Delgado 65988fa2dfbSRicardo Ribalda Delgado release_region(KERNCZ_IMC_IDX, 2); 66088fa2dfbSRicardo Ribalda Delgado } 66188fa2dfbSRicardo Ribalda Delgado 6622fee61d2SChristian Fetzer /* 6632fee61d2SChristian Fetzer * Handles access to multiple SMBus ports on the SB800. 6642fee61d2SChristian Fetzer * The port is selected by bits 2:1 of the smb_en register (0x2c). 6652fee61d2SChristian Fetzer * Returns negative errno on error. 6662fee61d2SChristian Fetzer * 6672fee61d2SChristian Fetzer * Note: The selected port must be returned to the initial selection to avoid 6682fee61d2SChristian Fetzer * problems on certain systems. 6692fee61d2SChristian Fetzer */ 6702fee61d2SChristian Fetzer static s32 piix4_access_sb800(struct i2c_adapter *adap, u16 addr, 6712fee61d2SChristian Fetzer unsigned short flags, char read_write, 6722fee61d2SChristian Fetzer u8 command, int size, union i2c_smbus_data *data) 6732fee61d2SChristian Fetzer { 6742fee61d2SChristian Fetzer struct i2c_piix4_adapdata *adapdata = i2c_get_adapdata(adap); 675701dc207SRicardo Ribalda unsigned short piix4_smba = adapdata->smba; 676701dc207SRicardo Ribalda int retries = MAX_TIMEOUT; 677701dc207SRicardo Ribalda int smbslvcnt; 6782fee61d2SChristian Fetzer u8 smba_en_lo; 6792fee61d2SChristian Fetzer u8 port; 6802fee61d2SChristian Fetzer int retval; 6812fee61d2SChristian Fetzer 682bbb27fc3SRicardo Ribalda mutex_lock(&piix4_mutex_sb800); 683bbb27fc3SRicardo Ribalda 684701dc207SRicardo Ribalda /* Request the SMBUS semaphore, avoid conflicts with the IMC */ 685701dc207SRicardo Ribalda smbslvcnt = inb_p(SMBSLVCNT); 686701dc207SRicardo Ribalda do { 687701dc207SRicardo Ribalda outb_p(smbslvcnt | 0x10, SMBSLVCNT); 688701dc207SRicardo Ribalda 689701dc207SRicardo Ribalda /* Check the semaphore status */ 690701dc207SRicardo Ribalda smbslvcnt = inb_p(SMBSLVCNT); 691701dc207SRicardo Ribalda if (smbslvcnt & 0x10) 692701dc207SRicardo Ribalda break; 693701dc207SRicardo Ribalda 694701dc207SRicardo Ribalda usleep_range(1000, 2000); 695701dc207SRicardo Ribalda } while (--retries); 696701dc207SRicardo Ribalda /* SMBus is still owned by the IMC, we give up */ 697bbb27fc3SRicardo Ribalda if (!retries) { 698bbb27fc3SRicardo Ribalda mutex_unlock(&piix4_mutex_sb800); 699701dc207SRicardo Ribalda return -EBUSY; 700bbb27fc3SRicardo Ribalda } 7012fee61d2SChristian Fetzer 70288fa2dfbSRicardo Ribalda Delgado /* 70388fa2dfbSRicardo Ribalda Delgado * Notify the IMC (Integrated Micro Controller) if required. 70488fa2dfbSRicardo Ribalda Delgado * Among other responsibilities, the IMC is in charge of monitoring 70588fa2dfbSRicardo Ribalda Delgado * the System fans and temperature sensors, and act accordingly. 70688fa2dfbSRicardo Ribalda Delgado * All this is done through SMBus and can/will collide 70788fa2dfbSRicardo Ribalda Delgado * with our transactions if they are long (BLOCK_DATA). 70888fa2dfbSRicardo Ribalda Delgado * Therefore we need to request the ownership flag during those 70988fa2dfbSRicardo Ribalda Delgado * transactions. 71088fa2dfbSRicardo Ribalda Delgado */ 71188fa2dfbSRicardo Ribalda Delgado if ((size == I2C_SMBUS_BLOCK_DATA) && adapdata->notify_imc) { 71288fa2dfbSRicardo Ribalda Delgado int ret; 71388fa2dfbSRicardo Ribalda Delgado 71488fa2dfbSRicardo Ribalda Delgado ret = piix4_imc_sleep(); 71588fa2dfbSRicardo Ribalda Delgado switch (ret) { 71688fa2dfbSRicardo Ribalda Delgado case -EBUSY: 71788fa2dfbSRicardo Ribalda Delgado dev_warn(&adap->dev, 71888fa2dfbSRicardo Ribalda Delgado "IMC base address index region 0x%x already in use.\n", 71988fa2dfbSRicardo Ribalda Delgado KERNCZ_IMC_IDX); 72088fa2dfbSRicardo Ribalda Delgado break; 72188fa2dfbSRicardo Ribalda Delgado case -ETIMEDOUT: 72288fa2dfbSRicardo Ribalda Delgado dev_warn(&adap->dev, 72388fa2dfbSRicardo Ribalda Delgado "Failed to communicate with the IMC.\n"); 72488fa2dfbSRicardo Ribalda Delgado break; 72588fa2dfbSRicardo Ribalda Delgado default: 72688fa2dfbSRicardo Ribalda Delgado break; 72788fa2dfbSRicardo Ribalda Delgado } 72888fa2dfbSRicardo Ribalda Delgado 72988fa2dfbSRicardo Ribalda Delgado /* If IMC communication fails do not retry */ 73088fa2dfbSRicardo Ribalda Delgado if (ret) { 73188fa2dfbSRicardo Ribalda Delgado dev_warn(&adap->dev, 73288fa2dfbSRicardo Ribalda Delgado "Continuing without IMC notification.\n"); 73388fa2dfbSRicardo Ribalda Delgado adapdata->notify_imc = false; 73488fa2dfbSRicardo Ribalda Delgado } 73588fa2dfbSRicardo Ribalda Delgado } 73688fa2dfbSRicardo Ribalda Delgado 7376befa3fdSJean Delvare outb_p(piix4_port_sel_sb800, SB800_PIIX4_SMB_IDX); 7382fee61d2SChristian Fetzer smba_en_lo = inb_p(SB800_PIIX4_SMB_IDX + 1); 7392fee61d2SChristian Fetzer 7402fee61d2SChristian Fetzer port = adapdata->port; 7410fe16195SGuenter Roeck if ((smba_en_lo & piix4_port_mask_sb800) != port) 7420fe16195SGuenter Roeck outb_p((smba_en_lo & ~piix4_port_mask_sb800) | port, 7432fee61d2SChristian Fetzer SB800_PIIX4_SMB_IDX + 1); 7442fee61d2SChristian Fetzer 7452fee61d2SChristian Fetzer retval = piix4_access(adap, addr, flags, read_write, 7462fee61d2SChristian Fetzer command, size, data); 7472fee61d2SChristian Fetzer 7482fee61d2SChristian Fetzer outb_p(smba_en_lo, SB800_PIIX4_SMB_IDX + 1); 7492fee61d2SChristian Fetzer 750701dc207SRicardo Ribalda /* Release the semaphore */ 751701dc207SRicardo Ribalda outb_p(smbslvcnt | 0x20, SMBSLVCNT); 752701dc207SRicardo Ribalda 75388fa2dfbSRicardo Ribalda Delgado if ((size == I2C_SMBUS_BLOCK_DATA) && adapdata->notify_imc) 75488fa2dfbSRicardo Ribalda Delgado piix4_imc_wakeup(); 75588fa2dfbSRicardo Ribalda Delgado 756bbb27fc3SRicardo Ribalda mutex_unlock(&piix4_mutex_sb800); 757bbb27fc3SRicardo Ribalda 7582fee61d2SChristian Fetzer return retval; 7592fee61d2SChristian Fetzer } 7602fee61d2SChristian Fetzer 7611da177e4SLinus Torvalds static u32 piix4_func(struct i2c_adapter *adapter) 7621da177e4SLinus Torvalds { 7631da177e4SLinus Torvalds return I2C_FUNC_SMBUS_QUICK | I2C_FUNC_SMBUS_BYTE | 7641da177e4SLinus Torvalds I2C_FUNC_SMBUS_BYTE_DATA | I2C_FUNC_SMBUS_WORD_DATA | 7651da177e4SLinus Torvalds I2C_FUNC_SMBUS_BLOCK_DATA; 7661da177e4SLinus Torvalds } 7671da177e4SLinus Torvalds 7688f9082c5SJean Delvare static const struct i2c_algorithm smbus_algorithm = { 7691da177e4SLinus Torvalds .smbus_xfer = piix4_access, 7701da177e4SLinus Torvalds .functionality = piix4_func, 7711da177e4SLinus Torvalds }; 7721da177e4SLinus Torvalds 7732fee61d2SChristian Fetzer static const struct i2c_algorithm piix4_smbus_algorithm_sb800 = { 7742fee61d2SChristian Fetzer .smbus_xfer = piix4_access_sb800, 7752fee61d2SChristian Fetzer .functionality = piix4_func, 7762fee61d2SChristian Fetzer }; 7772fee61d2SChristian Fetzer 778392debf1SJingoo Han static const struct pci_device_id piix4_ids[] = { 7799b7389c0SJean Delvare { PCI_DEVICE(PCI_VENDOR_ID_INTEL, PCI_DEVICE_ID_INTEL_82371AB_3) }, 7809b7389c0SJean Delvare { PCI_DEVICE(PCI_VENDOR_ID_INTEL, PCI_DEVICE_ID_INTEL_82443MX_3) }, 7819b7389c0SJean Delvare { PCI_DEVICE(PCI_VENDOR_ID_EFAR, PCI_DEVICE_ID_EFAR_SLC90E66_3) }, 7829b7389c0SJean Delvare { PCI_DEVICE(PCI_VENDOR_ID_ATI, PCI_DEVICE_ID_ATI_IXP200_SMBUS) }, 7839b7389c0SJean Delvare { PCI_DEVICE(PCI_VENDOR_ID_ATI, PCI_DEVICE_ID_ATI_IXP300_SMBUS) }, 7849b7389c0SJean Delvare { PCI_DEVICE(PCI_VENDOR_ID_ATI, PCI_DEVICE_ID_ATI_IXP400_SMBUS) }, 7859b7389c0SJean Delvare { PCI_DEVICE(PCI_VENDOR_ID_ATI, PCI_DEVICE_ID_ATI_SBX00_SMBUS) }, 7863806e94bSCrane Cai { PCI_DEVICE(PCI_VENDOR_ID_AMD, PCI_DEVICE_ID_AMD_HUDSON2_SMBUS) }, 787bcb29994SVincent Wan { PCI_DEVICE(PCI_VENDOR_ID_AMD, PCI_DEVICE_ID_AMD_KERNCZ_SMBUS) }, 7889b7389c0SJean Delvare { PCI_DEVICE(PCI_VENDOR_ID_SERVERWORKS, 7899b7389c0SJean Delvare PCI_DEVICE_ID_SERVERWORKS_OSB4) }, 7909b7389c0SJean Delvare { PCI_DEVICE(PCI_VENDOR_ID_SERVERWORKS, 7919b7389c0SJean Delvare PCI_DEVICE_ID_SERVERWORKS_CSB5) }, 7929b7389c0SJean Delvare { PCI_DEVICE(PCI_VENDOR_ID_SERVERWORKS, 7939b7389c0SJean Delvare PCI_DEVICE_ID_SERVERWORKS_CSB6) }, 7949b7389c0SJean Delvare { PCI_DEVICE(PCI_VENDOR_ID_SERVERWORKS, 7959b7389c0SJean Delvare PCI_DEVICE_ID_SERVERWORKS_HT1000SB) }, 796506a8b6cSFlavio Leitner { PCI_DEVICE(PCI_VENDOR_ID_SERVERWORKS, 797506a8b6cSFlavio Leitner PCI_DEVICE_ID_SERVERWORKS_HT1100LD) }, 7981da177e4SLinus Torvalds { 0, } 7991da177e4SLinus Torvalds }; 8001da177e4SLinus Torvalds 8011da177e4SLinus Torvalds MODULE_DEVICE_TABLE (pci, piix4_ids); 8021da177e4SLinus Torvalds 803ca2061e1SChristian Fetzer static struct i2c_adapter *piix4_main_adapters[PIIX4_MAX_ADAPTERS]; 8042a2f7404SAndrew Armenia static struct i2c_adapter *piix4_aux_adapter; 805e154bf6fSAndrew Armenia 8060b255e92SBill Pemberton static int piix4_add_adapter(struct pci_dev *dev, unsigned short smba, 80788fa2dfbSRicardo Ribalda Delgado bool sb800_main, u8 port, bool notify_imc, 808725d2e3fSChristian Fetzer const char *name, struct i2c_adapter **padap) 809e154bf6fSAndrew Armenia { 810e154bf6fSAndrew Armenia struct i2c_adapter *adap; 811e154bf6fSAndrew Armenia struct i2c_piix4_adapdata *adapdata; 812e154bf6fSAndrew Armenia int retval; 813e154bf6fSAndrew Armenia 814e154bf6fSAndrew Armenia adap = kzalloc(sizeof(*adap), GFP_KERNEL); 815e154bf6fSAndrew Armenia if (adap == NULL) { 816e154bf6fSAndrew Armenia release_region(smba, SMBIOSIZE); 817e154bf6fSAndrew Armenia return -ENOMEM; 818e154bf6fSAndrew Armenia } 819e154bf6fSAndrew Armenia 820e154bf6fSAndrew Armenia adap->owner = THIS_MODULE; 821e154bf6fSAndrew Armenia adap->class = I2C_CLASS_HWMON | I2C_CLASS_SPD; 82283c60158SJean Delvare adap->algo = sb800_main ? &piix4_smbus_algorithm_sb800 82383c60158SJean Delvare : &smbus_algorithm; 824e154bf6fSAndrew Armenia 825e154bf6fSAndrew Armenia adapdata = kzalloc(sizeof(*adapdata), GFP_KERNEL); 826e154bf6fSAndrew Armenia if (adapdata == NULL) { 827e154bf6fSAndrew Armenia kfree(adap); 828e154bf6fSAndrew Armenia release_region(smba, SMBIOSIZE); 829e154bf6fSAndrew Armenia return -ENOMEM; 830e154bf6fSAndrew Armenia } 831e154bf6fSAndrew Armenia 832e154bf6fSAndrew Armenia adapdata->smba = smba; 83383c60158SJean Delvare adapdata->sb800_main = sb800_main; 8340fe16195SGuenter Roeck adapdata->port = port << piix4_port_shift_sb800; 83588fa2dfbSRicardo Ribalda Delgado adapdata->notify_imc = notify_imc; 836e154bf6fSAndrew Armenia 837e154bf6fSAndrew Armenia /* set up the sysfs linkage to our parent device */ 838e154bf6fSAndrew Armenia adap->dev.parent = &dev->dev; 839e154bf6fSAndrew Armenia 840e154bf6fSAndrew Armenia snprintf(adap->name, sizeof(adap->name), 841725d2e3fSChristian Fetzer "SMBus PIIX4 adapter%s at %04x", name, smba); 842e154bf6fSAndrew Armenia 843e154bf6fSAndrew Armenia i2c_set_adapdata(adap, adapdata); 844e154bf6fSAndrew Armenia 845e154bf6fSAndrew Armenia retval = i2c_add_adapter(adap); 846e154bf6fSAndrew Armenia if (retval) { 847e154bf6fSAndrew Armenia kfree(adapdata); 848e154bf6fSAndrew Armenia kfree(adap); 849e154bf6fSAndrew Armenia release_region(smba, SMBIOSIZE); 850e154bf6fSAndrew Armenia return retval; 851e154bf6fSAndrew Armenia } 852e154bf6fSAndrew Armenia 853e154bf6fSAndrew Armenia *padap = adap; 854e154bf6fSAndrew Armenia return 0; 855e154bf6fSAndrew Armenia } 856e154bf6fSAndrew Armenia 85788fa2dfbSRicardo Ribalda Delgado static int piix4_add_adapters_sb800(struct pci_dev *dev, unsigned short smba, 85888fa2dfbSRicardo Ribalda Delgado bool notify_imc) 8592fee61d2SChristian Fetzer { 8602fee61d2SChristian Fetzer struct i2c_piix4_adapdata *adapdata; 8612fee61d2SChristian Fetzer int port; 8622fee61d2SChristian Fetzer int retval; 8632fee61d2SChristian Fetzer 8642fee61d2SChristian Fetzer for (port = 0; port < PIIX4_MAX_ADAPTERS; port++) { 86588fa2dfbSRicardo Ribalda Delgado retval = piix4_add_adapter(dev, smba, true, port, notify_imc, 866725d2e3fSChristian Fetzer piix4_main_port_names_sb800[port], 8672fee61d2SChristian Fetzer &piix4_main_adapters[port]); 8682fee61d2SChristian Fetzer if (retval < 0) 8692fee61d2SChristian Fetzer goto error; 8702fee61d2SChristian Fetzer } 8712fee61d2SChristian Fetzer 8722fee61d2SChristian Fetzer return retval; 8732fee61d2SChristian Fetzer 8742fee61d2SChristian Fetzer error: 8752fee61d2SChristian Fetzer dev_err(&dev->dev, 8762fee61d2SChristian Fetzer "Error setting up SB800 adapters. Unregistering!\n"); 8772fee61d2SChristian Fetzer while (--port >= 0) { 8782fee61d2SChristian Fetzer adapdata = i2c_get_adapdata(piix4_main_adapters[port]); 8792fee61d2SChristian Fetzer if (adapdata->smba) { 8802fee61d2SChristian Fetzer i2c_del_adapter(piix4_main_adapters[port]); 8812fee61d2SChristian Fetzer kfree(adapdata); 8822fee61d2SChristian Fetzer kfree(piix4_main_adapters[port]); 8832fee61d2SChristian Fetzer piix4_main_adapters[port] = NULL; 8842fee61d2SChristian Fetzer } 8852fee61d2SChristian Fetzer } 8862fee61d2SChristian Fetzer 8872fee61d2SChristian Fetzer return retval; 8882fee61d2SChristian Fetzer } 8892fee61d2SChristian Fetzer 8900b255e92SBill Pemberton static int piix4_probe(struct pci_dev *dev, const struct pci_device_id *id) 8911da177e4SLinus Torvalds { 8921da177e4SLinus Torvalds int retval; 89352795f6fSJean Delvare bool is_sb800 = false; 8941da177e4SLinus Torvalds 89576b3e28fSCrane Cai if ((dev->vendor == PCI_VENDOR_ID_ATI && 89676b3e28fSCrane Cai dev->device == PCI_DEVICE_ID_ATI_SBX00_SMBUS && 89776b3e28fSCrane Cai dev->revision >= 0x40) || 8982fee61d2SChristian Fetzer dev->vendor == PCI_VENDOR_ID_AMD) { 89988fa2dfbSRicardo Ribalda Delgado bool notify_imc = false; 90052795f6fSJean Delvare is_sb800 = true; 90152795f6fSJean Delvare 9022fee61d2SChristian Fetzer if (!request_region(SB800_PIIX4_SMB_IDX, 2, "smba_idx")) { 9032fee61d2SChristian Fetzer dev_err(&dev->dev, 9042fee61d2SChristian Fetzer "SMBus base address index region 0x%x already in use!\n", 9052fee61d2SChristian Fetzer SB800_PIIX4_SMB_IDX); 9062fee61d2SChristian Fetzer return -EBUSY; 9072fee61d2SChristian Fetzer } 9082fee61d2SChristian Fetzer 90988fa2dfbSRicardo Ribalda Delgado if (dev->vendor == PCI_VENDOR_ID_AMD && 91088fa2dfbSRicardo Ribalda Delgado dev->device == PCI_DEVICE_ID_AMD_KERNCZ_SMBUS) { 91188fa2dfbSRicardo Ribalda Delgado u8 imc; 91288fa2dfbSRicardo Ribalda Delgado 91388fa2dfbSRicardo Ribalda Delgado /* 91488fa2dfbSRicardo Ribalda Delgado * Detect if IMC is active or not, this method is 91588fa2dfbSRicardo Ribalda Delgado * described on coreboot's AMD IMC notes 91688fa2dfbSRicardo Ribalda Delgado */ 91788fa2dfbSRicardo Ribalda Delgado pci_bus_read_config_byte(dev->bus, PCI_DEVFN(0x14, 3), 91888fa2dfbSRicardo Ribalda Delgado 0x40, &imc); 91988fa2dfbSRicardo Ribalda Delgado if (imc & 0x80) 92088fa2dfbSRicardo Ribalda Delgado notify_imc = true; 92188fa2dfbSRicardo Ribalda Delgado } 92288fa2dfbSRicardo Ribalda Delgado 92387e1960eSShane Huang /* base address location etc changed in SB800 */ 924a94dd00fSRudolf Marek retval = piix4_setup_sb800(dev, id, 0); 9252fee61d2SChristian Fetzer if (retval < 0) { 9262fee61d2SChristian Fetzer release_region(SB800_PIIX4_SMB_IDX, 2); 9272fee61d2SChristian Fetzer return retval; 9282fee61d2SChristian Fetzer } 92987e1960eSShane Huang 9302fee61d2SChristian Fetzer /* 9312fee61d2SChristian Fetzer * Try to register multiplexed main SMBus adapter, 9322fee61d2SChristian Fetzer * give up if we can't 9332fee61d2SChristian Fetzer */ 93488fa2dfbSRicardo Ribalda Delgado retval = piix4_add_adapters_sb800(dev, retval, notify_imc); 9352fee61d2SChristian Fetzer if (retval < 0) { 9362fee61d2SChristian Fetzer release_region(SB800_PIIX4_SMB_IDX, 2); 9372fee61d2SChristian Fetzer return retval; 9382fee61d2SChristian Fetzer } 9392fee61d2SChristian Fetzer } else { 9402fee61d2SChristian Fetzer retval = piix4_setup(dev, id); 94114a8086dSAndrew Armenia if (retval < 0) 9421da177e4SLinus Torvalds return retval; 9431da177e4SLinus Torvalds 9442a2f7404SAndrew Armenia /* Try to register main SMBus adapter, give up if we can't */ 94588fa2dfbSRicardo Ribalda Delgado retval = piix4_add_adapter(dev, retval, false, 0, false, "", 9462fee61d2SChristian Fetzer &piix4_main_adapters[0]); 9472a2f7404SAndrew Armenia if (retval < 0) 9482a2f7404SAndrew Armenia return retval; 9492fee61d2SChristian Fetzer } 9502a2f7404SAndrew Armenia 9512a2f7404SAndrew Armenia /* Check for auxiliary SMBus on some AMD chipsets */ 952a94dd00fSRudolf Marek retval = -ENODEV; 953a94dd00fSRudolf Marek 9542a2f7404SAndrew Armenia if (dev->vendor == PCI_VENDOR_ID_ATI && 955a94dd00fSRudolf Marek dev->device == PCI_DEVICE_ID_ATI_SBX00_SMBUS) { 956a94dd00fSRudolf Marek if (dev->revision < 0x40) { 9572a2f7404SAndrew Armenia retval = piix4_setup_aux(dev, id, 0x58); 958a94dd00fSRudolf Marek } else { 959a94dd00fSRudolf Marek /* SB800 added aux bus too */ 960a94dd00fSRudolf Marek retval = piix4_setup_sb800(dev, id, 1); 961a94dd00fSRudolf Marek } 962a94dd00fSRudolf Marek } 963a94dd00fSRudolf Marek 964a94dd00fSRudolf Marek if (dev->vendor == PCI_VENDOR_ID_AMD && 965a94dd00fSRudolf Marek dev->device == PCI_DEVICE_ID_AMD_HUDSON2_SMBUS) { 966a94dd00fSRudolf Marek retval = piix4_setup_sb800(dev, id, 1); 967a94dd00fSRudolf Marek } 968a94dd00fSRudolf Marek 9692a2f7404SAndrew Armenia if (retval > 0) { 9702a2f7404SAndrew Armenia /* Try to add the aux adapter if it exists, 9712a2f7404SAndrew Armenia * piix4_add_adapter will clean up if this fails */ 97288fa2dfbSRicardo Ribalda Delgado piix4_add_adapter(dev, retval, false, 0, false, 97352795f6fSJean Delvare is_sb800 ? piix4_aux_port_name_sb800 : "", 974725d2e3fSChristian Fetzer &piix4_aux_adapter); 9752a2f7404SAndrew Armenia } 9762a2f7404SAndrew Armenia 9772a2f7404SAndrew Armenia return 0; 9781da177e4SLinus Torvalds } 9791da177e4SLinus Torvalds 9800b255e92SBill Pemberton static void piix4_adap_remove(struct i2c_adapter *adap) 98114a8086dSAndrew Armenia { 98214a8086dSAndrew Armenia struct i2c_piix4_adapdata *adapdata = i2c_get_adapdata(adap); 98314a8086dSAndrew Armenia 98414a8086dSAndrew Armenia if (adapdata->smba) { 98514a8086dSAndrew Armenia i2c_del_adapter(adap); 98645fd4470SJean Delvare if (adapdata->port == (0 << piix4_port_shift_sb800)) { 98714a8086dSAndrew Armenia release_region(adapdata->smba, SMBIOSIZE); 988a28e3517SJean Delvare if (adapdata->sb800_main) 9892fee61d2SChristian Fetzer release_region(SB800_PIIX4_SMB_IDX, 2); 9902fee61d2SChristian Fetzer } 991e154bf6fSAndrew Armenia kfree(adapdata); 992e154bf6fSAndrew Armenia kfree(adap); 99314a8086dSAndrew Armenia } 99414a8086dSAndrew Armenia } 99514a8086dSAndrew Armenia 9960b255e92SBill Pemberton static void piix4_remove(struct pci_dev *dev) 9971da177e4SLinus Torvalds { 998ca2061e1SChristian Fetzer int port = PIIX4_MAX_ADAPTERS; 999ca2061e1SChristian Fetzer 1000ca2061e1SChristian Fetzer while (--port >= 0) { 1001ca2061e1SChristian Fetzer if (piix4_main_adapters[port]) { 1002ca2061e1SChristian Fetzer piix4_adap_remove(piix4_main_adapters[port]); 1003ca2061e1SChristian Fetzer piix4_main_adapters[port] = NULL; 1004ca2061e1SChristian Fetzer } 1005e154bf6fSAndrew Armenia } 10062a2f7404SAndrew Armenia 10072a2f7404SAndrew Armenia if (piix4_aux_adapter) { 10082a2f7404SAndrew Armenia piix4_adap_remove(piix4_aux_adapter); 10092a2f7404SAndrew Armenia piix4_aux_adapter = NULL; 10102a2f7404SAndrew Armenia } 10111da177e4SLinus Torvalds } 10121da177e4SLinus Torvalds 10131da177e4SLinus Torvalds static struct pci_driver piix4_driver = { 10141da177e4SLinus Torvalds .name = "piix4_smbus", 10151da177e4SLinus Torvalds .id_table = piix4_ids, 10161da177e4SLinus Torvalds .probe = piix4_probe, 10170b255e92SBill Pemberton .remove = piix4_remove, 10181da177e4SLinus Torvalds }; 10191da177e4SLinus Torvalds 102056f21788SAxel Lin module_pci_driver(piix4_driver); 10211da177e4SLinus Torvalds 10221da177e4SLinus Torvalds MODULE_AUTHOR("Frodo Looijaard <frodol@dds.nl> and " 10231da177e4SLinus Torvalds "Philip Edelbrock <phil@netroedge.com>"); 10241da177e4SLinus Torvalds MODULE_DESCRIPTION("PIIX4 SMBus driver"); 10251da177e4SLinus Torvalds MODULE_LICENSE("GPL"); 1026