1c942fddfSThomas Gleixner // SPDX-License-Identifier: GPL-2.0-or-later 21da177e4SLinus Torvalds /* 31da177e4SLinus Torvalds Copyright (c) 1998 - 2002 Frodo Looijaard <frodol@dds.nl> and 41da177e4SLinus Torvalds Philip Edelbrock <phil@netroedge.com> 51da177e4SLinus Torvalds 61da177e4SLinus Torvalds */ 71da177e4SLinus Torvalds 81da177e4SLinus Torvalds /* 91da177e4SLinus Torvalds Supports: 101da177e4SLinus Torvalds Intel PIIX4, 440MX 11506a8b6cSFlavio Leitner Serverworks OSB4, CSB5, CSB6, HT-1000, HT-1100 122a2f7404SAndrew Armenia ATI IXP200, IXP300, IXP400, SB600, SB700/SP5100, SB800 13032f708bSShane Huang AMD Hudson-2, ML, CZ 1424beb83aSPu Wen Hygon CZ 151da177e4SLinus Torvalds SMSC Victory66 161da177e4SLinus Torvalds 172a2f7404SAndrew Armenia Note: we assume there can only be one device, with one or more 182a2f7404SAndrew Armenia SMBus interfaces. 192fee61d2SChristian Fetzer The device can register multiple i2c_adapters (up to PIIX4_MAX_ADAPTERS). 202fee61d2SChristian Fetzer For devices supporting multiple ports the i2c_adapter should provide 212fee61d2SChristian Fetzer an i2c_algorithm to access them. 221da177e4SLinus Torvalds */ 231da177e4SLinus Torvalds 241da177e4SLinus Torvalds #include <linux/module.h> 251da177e4SLinus Torvalds #include <linux/moduleparam.h> 261da177e4SLinus Torvalds #include <linux/pci.h> 271da177e4SLinus Torvalds #include <linux/kernel.h> 281da177e4SLinus Torvalds #include <linux/delay.h> 291da177e4SLinus Torvalds #include <linux/stddef.h> 301da177e4SLinus Torvalds #include <linux/ioport.h> 311da177e4SLinus Torvalds #include <linux/i2c.h> 32c415b303SDaniel J Blueman #include <linux/slab.h> 331da177e4SLinus Torvalds #include <linux/dmi.h> 3454fb4a05SJean Delvare #include <linux/acpi.h> 3521782180SH Hartley Sweeten #include <linux/io.h> 361da177e4SLinus Torvalds 371da177e4SLinus Torvalds 381da177e4SLinus Torvalds /* PIIX4 SMBus address offsets */ 391da177e4SLinus Torvalds #define SMBHSTSTS (0 + piix4_smba) 401da177e4SLinus Torvalds #define SMBHSLVSTS (1 + piix4_smba) 411da177e4SLinus Torvalds #define SMBHSTCNT (2 + piix4_smba) 421da177e4SLinus Torvalds #define SMBHSTCMD (3 + piix4_smba) 431da177e4SLinus Torvalds #define SMBHSTADD (4 + piix4_smba) 441da177e4SLinus Torvalds #define SMBHSTDAT0 (5 + piix4_smba) 451da177e4SLinus Torvalds #define SMBHSTDAT1 (6 + piix4_smba) 461da177e4SLinus Torvalds #define SMBBLKDAT (7 + piix4_smba) 471da177e4SLinus Torvalds #define SMBSLVCNT (8 + piix4_smba) 481da177e4SLinus Torvalds #define SMBSHDWCMD (9 + piix4_smba) 491da177e4SLinus Torvalds #define SMBSLVEVT (0xA + piix4_smba) 501da177e4SLinus Torvalds #define SMBSLVDAT (0xC + piix4_smba) 511da177e4SLinus Torvalds 521da177e4SLinus Torvalds /* count for request_region */ 53f43128c7SRicardo Ribalda #define SMBIOSIZE 9 541da177e4SLinus Torvalds 551da177e4SLinus Torvalds /* PCI Address Constants */ 561da177e4SLinus Torvalds #define SMBBA 0x090 571da177e4SLinus Torvalds #define SMBHSTCFG 0x0D2 581da177e4SLinus Torvalds #define SMBSLVC 0x0D3 591da177e4SLinus Torvalds #define SMBSHDW1 0x0D4 601da177e4SLinus Torvalds #define SMBSHDW2 0x0D5 611da177e4SLinus Torvalds #define SMBREV 0x0D6 621da177e4SLinus Torvalds 631da177e4SLinus Torvalds /* Other settings */ 641da177e4SLinus Torvalds #define MAX_TIMEOUT 500 651da177e4SLinus Torvalds #define ENABLE_INT9 0 661da177e4SLinus Torvalds 671da177e4SLinus Torvalds /* PIIX4 constants */ 681da177e4SLinus Torvalds #define PIIX4_QUICK 0x00 691da177e4SLinus Torvalds #define PIIX4_BYTE 0x04 701da177e4SLinus Torvalds #define PIIX4_BYTE_DATA 0x08 711da177e4SLinus Torvalds #define PIIX4_WORD_DATA 0x0C 721da177e4SLinus Torvalds #define PIIX4_BLOCK_DATA 0x14 731da177e4SLinus Torvalds 74ca2061e1SChristian Fetzer /* Multi-port constants */ 75ca2061e1SChristian Fetzer #define PIIX4_MAX_ADAPTERS 4 76528d53a1SJean Delvare #define HUDSON2_MAIN_PORTS 2 /* HUDSON2, KERNCZ reserves ports 3, 4 */ 77ca2061e1SChristian Fetzer 782fee61d2SChristian Fetzer /* SB800 constants */ 792fee61d2SChristian Fetzer #define SB800_PIIX4_SMB_IDX 0xcd6 8093102cb4STerry Bowman #define SB800_PIIX4_SMB_MAP_SIZE 2 812fee61d2SChristian Fetzer 8288fa2dfbSRicardo Ribalda Delgado #define KERNCZ_IMC_IDX 0x3e 8388fa2dfbSRicardo Ribalda Delgado #define KERNCZ_IMC_DATA 0x3f 8488fa2dfbSRicardo Ribalda Delgado 856befa3fdSJean Delvare /* 866befa3fdSJean Delvare * SB800 port is selected by bits 2:1 of the smb_en register (0x2c) 876befa3fdSJean Delvare * or the smb_sel register (0x2e), depending on bit 0 of register 0x2f. 886befa3fdSJean Delvare * Hudson-2/Bolton port is always selected by bits 2:1 of register 0x2f. 896befa3fdSJean Delvare */ 902fee61d2SChristian Fetzer #define SB800_PIIX4_PORT_IDX 0x2c 916befa3fdSJean Delvare #define SB800_PIIX4_PORT_IDX_ALT 0x2e 926befa3fdSJean Delvare #define SB800_PIIX4_PORT_IDX_SEL 0x2f 932fee61d2SChristian Fetzer #define SB800_PIIX4_PORT_IDX_MASK 0x06 940fe16195SGuenter Roeck #define SB800_PIIX4_PORT_IDX_SHIFT 1 950fe16195SGuenter Roeck 96c7c06a15SAndrew Cooks /* On kerncz and Hudson2, SmBus0Sel is at bit 20:19 of PMx00 DecodeEn */ 970fe16195SGuenter Roeck #define SB800_PIIX4_PORT_IDX_KERNCZ 0x02 980fe16195SGuenter Roeck #define SB800_PIIX4_PORT_IDX_MASK_KERNCZ 0x18 990fe16195SGuenter Roeck #define SB800_PIIX4_PORT_IDX_SHIFT_KERNCZ 3 1002fee61d2SChristian Fetzer 1011da177e4SLinus Torvalds /* insmod parameters */ 1021da177e4SLinus Torvalds 1031da177e4SLinus Torvalds /* If force is set to anything different from 0, we forcibly enable the 1041da177e4SLinus Torvalds PIIX4. DANGEROUS! */ 10560507095SJean Delvare static int force; 1061da177e4SLinus Torvalds module_param (force, int, 0); 1071da177e4SLinus Torvalds MODULE_PARM_DESC(force, "Forcibly enable the PIIX4. DANGEROUS!"); 1081da177e4SLinus Torvalds 1091da177e4SLinus Torvalds /* If force_addr is set to anything different from 0, we forcibly enable 1101da177e4SLinus Torvalds the PIIX4 at the given address. VERY DANGEROUS! */ 11160507095SJean Delvare static int force_addr; 112c78babccSDavid Howells module_param_hw(force_addr, int, ioport, 0); 1131da177e4SLinus Torvalds MODULE_PARM_DESC(force_addr, 1141da177e4SLinus Torvalds "Forcibly enable the PIIX4 at the given address. " 1151da177e4SLinus Torvalds "EXTREMELY DANGEROUS!"); 1161da177e4SLinus Torvalds 117b1c1759cSDavid Milburn static int srvrworks_csb5_delay; 118d6072f84SJean Delvare static struct pci_driver piix4_driver; 1191da177e4SLinus Torvalds 1200b255e92SBill Pemberton static const struct dmi_system_id piix4_dmi_blacklist[] = { 121c2fc54fcSJean Delvare { 122c2fc54fcSJean Delvare .ident = "Sapphire AM2RD790", 123c2fc54fcSJean Delvare .matches = { 124c2fc54fcSJean Delvare DMI_MATCH(DMI_BOARD_VENDOR, "SAPPHIRE Inc."), 125c2fc54fcSJean Delvare DMI_MATCH(DMI_BOARD_NAME, "PC-AM2RD790"), 126c2fc54fcSJean Delvare }, 127c2fc54fcSJean Delvare }, 128c2fc54fcSJean Delvare { 129c2fc54fcSJean Delvare .ident = "DFI Lanparty UT 790FX", 130c2fc54fcSJean Delvare .matches = { 131c2fc54fcSJean Delvare DMI_MATCH(DMI_BOARD_VENDOR, "DFI Inc."), 132c2fc54fcSJean Delvare DMI_MATCH(DMI_BOARD_NAME, "LP UT 790FX"), 133c2fc54fcSJean Delvare }, 134c2fc54fcSJean Delvare }, 135c2fc54fcSJean Delvare { } 136c2fc54fcSJean Delvare }; 137c2fc54fcSJean Delvare 138c2fc54fcSJean Delvare /* The IBM entry is in a separate table because we only check it 139c2fc54fcSJean Delvare on Intel-based systems */ 1400b255e92SBill Pemberton static const struct dmi_system_id piix4_dmi_ibm[] = { 1411da177e4SLinus Torvalds { 1421da177e4SLinus Torvalds .ident = "IBM", 1431da177e4SLinus Torvalds .matches = { DMI_MATCH(DMI_SYS_VENDOR, "IBM"), }, 1441da177e4SLinus Torvalds }, 1451da177e4SLinus Torvalds { }, 1461da177e4SLinus Torvalds }; 1471da177e4SLinus Torvalds 1486befa3fdSJean Delvare /* 1496befa3fdSJean Delvare * SB800 globals 1506befa3fdSJean Delvare */ 1516befa3fdSJean Delvare static u8 piix4_port_sel_sb800; 1520fe16195SGuenter Roeck static u8 piix4_port_mask_sb800; 1530fe16195SGuenter Roeck static u8 piix4_port_shift_sb800; 154725d2e3fSChristian Fetzer static const char *piix4_main_port_names_sb800[PIIX4_MAX_ADAPTERS] = { 15552795f6fSJean Delvare " port 0", " port 2", " port 3", " port 4" 156725d2e3fSChristian Fetzer }; 15752795f6fSJean Delvare static const char *piix4_aux_port_name_sb800 = " port 1"; 158725d2e3fSChristian Fetzer 15914a8086dSAndrew Armenia struct i2c_piix4_adapdata { 16014a8086dSAndrew Armenia unsigned short smba; 1612fee61d2SChristian Fetzer 1622fee61d2SChristian Fetzer /* SB800 */ 1632fee61d2SChristian Fetzer bool sb800_main; 16488fa2dfbSRicardo Ribalda Delgado bool notify_imc; 16533f5ccc3SJean Delvare u8 port; /* Port number, shifted */ 16614a8086dSAndrew Armenia }; 16714a8086dSAndrew Armenia 168*a3325d22STerry Bowman static int piix4_sb800_region_request(struct device *dev) 169*a3325d22STerry Bowman { 170*a3325d22STerry Bowman if (!request_muxed_region(SB800_PIIX4_SMB_IDX, SB800_PIIX4_SMB_MAP_SIZE, 171*a3325d22STerry Bowman "sb800_piix4_smb")) { 172*a3325d22STerry Bowman dev_err(dev, 173*a3325d22STerry Bowman "SMBus base address index region 0x%x already in use.\n", 174*a3325d22STerry Bowman SB800_PIIX4_SMB_IDX); 175*a3325d22STerry Bowman return -EBUSY; 176*a3325d22STerry Bowman } 177*a3325d22STerry Bowman 178*a3325d22STerry Bowman return 0; 179*a3325d22STerry Bowman } 180*a3325d22STerry Bowman 181*a3325d22STerry Bowman static void piix4_sb800_region_release(struct device *dev) 182*a3325d22STerry Bowman { 183*a3325d22STerry Bowman release_region(SB800_PIIX4_SMB_IDX, SB800_PIIX4_SMB_MAP_SIZE); 184*a3325d22STerry Bowman } 185*a3325d22STerry Bowman 1860b255e92SBill Pemberton static int piix4_setup(struct pci_dev *PIIX4_dev, 1871da177e4SLinus Torvalds const struct pci_device_id *id) 1881da177e4SLinus Torvalds { 1891da177e4SLinus Torvalds unsigned char temp; 19014a8086dSAndrew Armenia unsigned short piix4_smba; 1911da177e4SLinus Torvalds 192b1c1759cSDavid Milburn if ((PIIX4_dev->vendor == PCI_VENDOR_ID_SERVERWORKS) && 193b1c1759cSDavid Milburn (PIIX4_dev->device == PCI_DEVICE_ID_SERVERWORKS_CSB5)) 194b1c1759cSDavid Milburn srvrworks_csb5_delay = 1; 195b1c1759cSDavid Milburn 196c2fc54fcSJean Delvare /* On some motherboards, it was reported that accessing the SMBus 197c2fc54fcSJean Delvare caused severe hardware problems */ 198c2fc54fcSJean Delvare if (dmi_check_system(piix4_dmi_blacklist)) { 199c2fc54fcSJean Delvare dev_err(&PIIX4_dev->dev, 200c2fc54fcSJean Delvare "Accessing the SMBus on this system is unsafe!\n"); 201c2fc54fcSJean Delvare return -EPERM; 202c2fc54fcSJean Delvare } 203c2fc54fcSJean Delvare 2041da177e4SLinus Torvalds /* Don't access SMBus on IBM systems which get corrupted eeproms */ 205c2fc54fcSJean Delvare if (dmi_check_system(piix4_dmi_ibm) && 2061da177e4SLinus Torvalds PIIX4_dev->vendor == PCI_VENDOR_ID_INTEL) { 207f9ba6c04SJean Delvare dev_err(&PIIX4_dev->dev, "IBM system detected; this module " 2081da177e4SLinus Torvalds "may corrupt your serial eeprom! Refusing to load " 2091da177e4SLinus Torvalds "module!\n"); 2101da177e4SLinus Torvalds return -EPERM; 2111da177e4SLinus Torvalds } 2121da177e4SLinus Torvalds 2131da177e4SLinus Torvalds /* Determine the address of the SMBus areas */ 2141da177e4SLinus Torvalds if (force_addr) { 2151da177e4SLinus Torvalds piix4_smba = force_addr & 0xfff0; 2161da177e4SLinus Torvalds force = 0; 2171da177e4SLinus Torvalds } else { 2181da177e4SLinus Torvalds pci_read_config_word(PIIX4_dev, SMBBA, &piix4_smba); 2191da177e4SLinus Torvalds piix4_smba &= 0xfff0; 2201da177e4SLinus Torvalds if(piix4_smba == 0) { 221fa63cd56SJean Delvare dev_err(&PIIX4_dev->dev, "SMBus base address " 2221da177e4SLinus Torvalds "uninitialized - upgrade BIOS or use " 2231da177e4SLinus Torvalds "force_addr=0xaddr\n"); 2241da177e4SLinus Torvalds return -ENODEV; 2251da177e4SLinus Torvalds } 2261da177e4SLinus Torvalds } 2271da177e4SLinus Torvalds 22854fb4a05SJean Delvare if (acpi_check_region(piix4_smba, SMBIOSIZE, piix4_driver.name)) 22918669eabSJean Delvare return -ENODEV; 23054fb4a05SJean Delvare 231d6072f84SJean Delvare if (!request_region(piix4_smba, SMBIOSIZE, piix4_driver.name)) { 232fa63cd56SJean Delvare dev_err(&PIIX4_dev->dev, "SMBus region 0x%x already in use!\n", 2331da177e4SLinus Torvalds piix4_smba); 234fa63cd56SJean Delvare return -EBUSY; 2351da177e4SLinus Torvalds } 2361da177e4SLinus Torvalds 2371da177e4SLinus Torvalds pci_read_config_byte(PIIX4_dev, SMBHSTCFG, &temp); 2381da177e4SLinus Torvalds 2391da177e4SLinus Torvalds /* If force_addr is set, we program the new address here. Just to make 2401da177e4SLinus Torvalds sure, we disable the PIIX4 first. */ 2411da177e4SLinus Torvalds if (force_addr) { 2421da177e4SLinus Torvalds pci_write_config_byte(PIIX4_dev, SMBHSTCFG, temp & 0xfe); 2431da177e4SLinus Torvalds pci_write_config_word(PIIX4_dev, SMBBA, piix4_smba); 2441da177e4SLinus Torvalds pci_write_config_byte(PIIX4_dev, SMBHSTCFG, temp | 0x01); 2451da177e4SLinus Torvalds dev_info(&PIIX4_dev->dev, "WARNING: SMBus interface set to " 2461da177e4SLinus Torvalds "new address %04x!\n", piix4_smba); 2471da177e4SLinus Torvalds } else if ((temp & 1) == 0) { 2481da177e4SLinus Torvalds if (force) { 2491da177e4SLinus Torvalds /* This should never need to be done, but has been 2501da177e4SLinus Torvalds * noted that many Dell machines have the SMBus 2511da177e4SLinus Torvalds * interface on the PIIX4 disabled!? NOTE: This assumes 2521da177e4SLinus Torvalds * I/O space and other allocations WERE done by the 2531da177e4SLinus Torvalds * Bios! Don't complain if your hardware does weird 2541da177e4SLinus Torvalds * things after enabling this. :') Check for Bios 2551da177e4SLinus Torvalds * updates before resorting to this. 2561da177e4SLinus Torvalds */ 2571da177e4SLinus Torvalds pci_write_config_byte(PIIX4_dev, SMBHSTCFG, 2581da177e4SLinus Torvalds temp | 1); 2598117e41eSJoe Perches dev_notice(&PIIX4_dev->dev, 2608117e41eSJoe Perches "WARNING: SMBus interface has been FORCEFULLY ENABLED!\n"); 2611da177e4SLinus Torvalds } else { 2621da177e4SLinus Torvalds dev_err(&PIIX4_dev->dev, 26366f8a8ffSJean Delvare "SMBus Host Controller not enabled!\n"); 2641da177e4SLinus Torvalds release_region(piix4_smba, SMBIOSIZE); 2651da177e4SLinus Torvalds return -ENODEV; 2661da177e4SLinus Torvalds } 2671da177e4SLinus Torvalds } 2681da177e4SLinus Torvalds 26954aaa1caSRudolf Marek if (((temp & 0x0E) == 8) || ((temp & 0x0E) == 2)) 27066f8a8ffSJean Delvare dev_dbg(&PIIX4_dev->dev, "Using IRQ for SMBus\n"); 2711da177e4SLinus Torvalds else if ((temp & 0x0E) == 0) 27266f8a8ffSJean Delvare dev_dbg(&PIIX4_dev->dev, "Using SMI# for SMBus\n"); 2731da177e4SLinus Torvalds else 2741da177e4SLinus Torvalds dev_err(&PIIX4_dev->dev, "Illegal Interrupt configuration " 2751da177e4SLinus Torvalds "(or code out of date)!\n"); 2761da177e4SLinus Torvalds 2771da177e4SLinus Torvalds pci_read_config_byte(PIIX4_dev, SMBREV, &temp); 278fa63cd56SJean Delvare dev_info(&PIIX4_dev->dev, 279fa63cd56SJean Delvare "SMBus Host Controller at 0x%x, revision %d\n", 280fa63cd56SJean Delvare piix4_smba, temp); 2811da177e4SLinus Torvalds 28214a8086dSAndrew Armenia return piix4_smba; 2831da177e4SLinus Torvalds } 2841da177e4SLinus Torvalds 2850b255e92SBill Pemberton static int piix4_setup_sb800(struct pci_dev *PIIX4_dev, 286a94dd00fSRudolf Marek const struct pci_device_id *id, u8 aux) 28787e1960eSShane Huang { 28814a8086dSAndrew Armenia unsigned short piix4_smba; 2896befa3fdSJean Delvare u8 smba_en_lo, smba_en_hi, smb_en, smb_en_status, port_sel; 290032f708bSShane Huang u8 i2ccfg, i2ccfg_offset = 0x10; 291*a3325d22STerry Bowman int retval; 29287e1960eSShane Huang 2933806e94bSCrane Cai /* SB800 and later SMBus does not support forcing address */ 29487e1960eSShane Huang if (force || force_addr) { 2953806e94bSCrane Cai dev_err(&PIIX4_dev->dev, "SMBus does not support " 29687e1960eSShane Huang "forcing address!\n"); 29787e1960eSShane Huang return -EINVAL; 29887e1960eSShane Huang } 29987e1960eSShane Huang 30087e1960eSShane Huang /* Determine the address of the SMBus areas */ 301032f708bSShane Huang if ((PIIX4_dev->vendor == PCI_VENDOR_ID_AMD && 302032f708bSShane Huang PIIX4_dev->device == PCI_DEVICE_ID_AMD_HUDSON2_SMBUS && 303032f708bSShane Huang PIIX4_dev->revision >= 0x41) || 304032f708bSShane Huang (PIIX4_dev->vendor == PCI_VENDOR_ID_AMD && 305bcb29994SVincent Wan PIIX4_dev->device == PCI_DEVICE_ID_AMD_KERNCZ_SMBUS && 30624beb83aSPu Wen PIIX4_dev->revision >= 0x49) || 30724beb83aSPu Wen (PIIX4_dev->vendor == PCI_VENDOR_ID_HYGON && 30824beb83aSPu Wen PIIX4_dev->device == PCI_DEVICE_ID_AMD_KERNCZ_SMBUS)) 309032f708bSShane Huang smb_en = 0x00; 310032f708bSShane Huang else 311a94dd00fSRudolf Marek smb_en = (aux) ? 0x28 : 0x2c; 312a94dd00fSRudolf Marek 313*a3325d22STerry Bowman retval = piix4_sb800_region_request(&PIIX4_dev->dev); 314*a3325d22STerry Bowman if (retval) 315*a3325d22STerry Bowman return retval; 31604b6fcabSGuenter Roeck 3172fee61d2SChristian Fetzer outb_p(smb_en, SB800_PIIX4_SMB_IDX); 3182fee61d2SChristian Fetzer smba_en_lo = inb_p(SB800_PIIX4_SMB_IDX + 1); 3192fee61d2SChristian Fetzer outb_p(smb_en + 1, SB800_PIIX4_SMB_IDX); 3202fee61d2SChristian Fetzer smba_en_hi = inb_p(SB800_PIIX4_SMB_IDX + 1); 32104b6fcabSGuenter Roeck 322*a3325d22STerry Bowman piix4_sb800_region_release(&PIIX4_dev->dev); 32387e1960eSShane Huang 324032f708bSShane Huang if (!smb_en) { 325032f708bSShane Huang smb_en_status = smba_en_lo & 0x10; 326032f708bSShane Huang piix4_smba = smba_en_hi << 8; 327032f708bSShane Huang if (aux) 328032f708bSShane Huang piix4_smba |= 0x20; 329032f708bSShane Huang } else { 330032f708bSShane Huang smb_en_status = smba_en_lo & 0x01; 331032f708bSShane Huang piix4_smba = ((smba_en_hi << 8) | smba_en_lo) & 0xffe0; 332032f708bSShane Huang } 333032f708bSShane Huang 334032f708bSShane Huang if (!smb_en_status) { 33587e1960eSShane Huang dev_err(&PIIX4_dev->dev, 33666f8a8ffSJean Delvare "SMBus Host Controller not enabled!\n"); 33787e1960eSShane Huang return -ENODEV; 33887e1960eSShane Huang } 33987e1960eSShane Huang 34087e1960eSShane Huang if (acpi_check_region(piix4_smba, SMBIOSIZE, piix4_driver.name)) 34118669eabSJean Delvare return -ENODEV; 34287e1960eSShane Huang 34387e1960eSShane Huang if (!request_region(piix4_smba, SMBIOSIZE, piix4_driver.name)) { 34487e1960eSShane Huang dev_err(&PIIX4_dev->dev, "SMBus region 0x%x already in use!\n", 34587e1960eSShane Huang piix4_smba); 34687e1960eSShane Huang return -EBUSY; 34787e1960eSShane Huang } 34887e1960eSShane Huang 349a94dd00fSRudolf Marek /* Aux SMBus does not support IRQ information */ 350a94dd00fSRudolf Marek if (aux) { 351a94dd00fSRudolf Marek dev_info(&PIIX4_dev->dev, 35285fd0fe6SShane Huang "Auxiliary SMBus Host Controller at 0x%x\n", 35385fd0fe6SShane Huang piix4_smba); 354a94dd00fSRudolf Marek return piix4_smba; 355a94dd00fSRudolf Marek } 356a94dd00fSRudolf Marek 35787e1960eSShane Huang /* Request the SMBus I2C bus config region */ 35887e1960eSShane Huang if (!request_region(piix4_smba + i2ccfg_offset, 1, "i2ccfg")) { 35987e1960eSShane Huang dev_err(&PIIX4_dev->dev, "SMBus I2C bus config region " 36087e1960eSShane Huang "0x%x already in use!\n", piix4_smba + i2ccfg_offset); 36187e1960eSShane Huang release_region(piix4_smba, SMBIOSIZE); 36287e1960eSShane Huang return -EBUSY; 36387e1960eSShane Huang } 36487e1960eSShane Huang i2ccfg = inb_p(piix4_smba + i2ccfg_offset); 36587e1960eSShane Huang release_region(piix4_smba + i2ccfg_offset, 1); 36687e1960eSShane Huang 36787e1960eSShane Huang if (i2ccfg & 1) 36866f8a8ffSJean Delvare dev_dbg(&PIIX4_dev->dev, "Using IRQ for SMBus\n"); 36987e1960eSShane Huang else 37066f8a8ffSJean Delvare dev_dbg(&PIIX4_dev->dev, "Using SMI# for SMBus\n"); 37187e1960eSShane Huang 37287e1960eSShane Huang dev_info(&PIIX4_dev->dev, 37387e1960eSShane Huang "SMBus Host Controller at 0x%x, revision %d\n", 37487e1960eSShane Huang piix4_smba, i2ccfg >> 4); 37587e1960eSShane Huang 3766befa3fdSJean Delvare /* Find which register is used for port selection */ 37724beb83aSPu Wen if (PIIX4_dev->vendor == PCI_VENDOR_ID_AMD || 37824beb83aSPu Wen PIIX4_dev->vendor == PCI_VENDOR_ID_HYGON) { 379c7c06a15SAndrew Cooks if (PIIX4_dev->device == PCI_DEVICE_ID_AMD_KERNCZ_SMBUS || 380c7c06a15SAndrew Cooks (PIIX4_dev->device == PCI_DEVICE_ID_AMD_HUDSON2_SMBUS && 381c7c06a15SAndrew Cooks PIIX4_dev->revision >= 0x1F)) { 3820fe16195SGuenter Roeck piix4_port_sel_sb800 = SB800_PIIX4_PORT_IDX_KERNCZ; 3830fe16195SGuenter Roeck piix4_port_mask_sb800 = SB800_PIIX4_PORT_IDX_MASK_KERNCZ; 3840fe16195SGuenter Roeck piix4_port_shift_sb800 = SB800_PIIX4_PORT_IDX_SHIFT_KERNCZ; 385c7c06a15SAndrew Cooks } else { 3866befa3fdSJean Delvare piix4_port_sel_sb800 = SB800_PIIX4_PORT_IDX_ALT; 3870fe16195SGuenter Roeck piix4_port_mask_sb800 = SB800_PIIX4_PORT_IDX_MASK; 3880fe16195SGuenter Roeck piix4_port_shift_sb800 = SB800_PIIX4_PORT_IDX_SHIFT; 3890fe16195SGuenter Roeck } 3906befa3fdSJean Delvare } else { 391*a3325d22STerry Bowman retval = piix4_sb800_region_request(&PIIX4_dev->dev); 392*a3325d22STerry Bowman if (retval) { 39304b6fcabSGuenter Roeck release_region(piix4_smba, SMBIOSIZE); 394*a3325d22STerry Bowman return retval; 39504b6fcabSGuenter Roeck } 39604b6fcabSGuenter Roeck 3976befa3fdSJean Delvare outb_p(SB800_PIIX4_PORT_IDX_SEL, SB800_PIIX4_SMB_IDX); 3986befa3fdSJean Delvare port_sel = inb_p(SB800_PIIX4_SMB_IDX + 1); 3996befa3fdSJean Delvare piix4_port_sel_sb800 = (port_sel & 0x01) ? 4006befa3fdSJean Delvare SB800_PIIX4_PORT_IDX_ALT : 4016befa3fdSJean Delvare SB800_PIIX4_PORT_IDX; 4020fe16195SGuenter Roeck piix4_port_mask_sb800 = SB800_PIIX4_PORT_IDX_MASK; 4030fe16195SGuenter Roeck piix4_port_shift_sb800 = SB800_PIIX4_PORT_IDX_SHIFT; 404*a3325d22STerry Bowman piix4_sb800_region_release(&PIIX4_dev->dev); 4056befa3fdSJean Delvare } 4066befa3fdSJean Delvare 4076befa3fdSJean Delvare dev_info(&PIIX4_dev->dev, 4086befa3fdSJean Delvare "Using register 0x%02x for SMBus port selection\n", 4096befa3fdSJean Delvare (unsigned int)piix4_port_sel_sb800); 4106befa3fdSJean Delvare 41114a8086dSAndrew Armenia return piix4_smba; 41287e1960eSShane Huang } 41387e1960eSShane Huang 4140b255e92SBill Pemberton static int piix4_setup_aux(struct pci_dev *PIIX4_dev, 4152a2f7404SAndrew Armenia const struct pci_device_id *id, 4162a2f7404SAndrew Armenia unsigned short base_reg_addr) 4172a2f7404SAndrew Armenia { 4182a2f7404SAndrew Armenia /* Set up auxiliary SMBus controllers found on some 4192a2f7404SAndrew Armenia * AMD chipsets e.g. SP5100 (SB700 derivative) */ 4202a2f7404SAndrew Armenia 4212a2f7404SAndrew Armenia unsigned short piix4_smba; 4222a2f7404SAndrew Armenia 4232a2f7404SAndrew Armenia /* Read address of auxiliary SMBus controller */ 4242a2f7404SAndrew Armenia pci_read_config_word(PIIX4_dev, base_reg_addr, &piix4_smba); 4252a2f7404SAndrew Armenia if ((piix4_smba & 1) == 0) { 4262a2f7404SAndrew Armenia dev_dbg(&PIIX4_dev->dev, 4272a2f7404SAndrew Armenia "Auxiliary SMBus controller not enabled\n"); 4282a2f7404SAndrew Armenia return -ENODEV; 4292a2f7404SAndrew Armenia } 4302a2f7404SAndrew Armenia 4312a2f7404SAndrew Armenia piix4_smba &= 0xfff0; 4322a2f7404SAndrew Armenia if (piix4_smba == 0) { 4332a2f7404SAndrew Armenia dev_dbg(&PIIX4_dev->dev, 4342a2f7404SAndrew Armenia "Auxiliary SMBus base address uninitialized\n"); 4352a2f7404SAndrew Armenia return -ENODEV; 4362a2f7404SAndrew Armenia } 4372a2f7404SAndrew Armenia 4382a2f7404SAndrew Armenia if (acpi_check_region(piix4_smba, SMBIOSIZE, piix4_driver.name)) 4392a2f7404SAndrew Armenia return -ENODEV; 4402a2f7404SAndrew Armenia 4412a2f7404SAndrew Armenia if (!request_region(piix4_smba, SMBIOSIZE, piix4_driver.name)) { 4422a2f7404SAndrew Armenia dev_err(&PIIX4_dev->dev, "Auxiliary SMBus region 0x%x " 4432a2f7404SAndrew Armenia "already in use!\n", piix4_smba); 4442a2f7404SAndrew Armenia return -EBUSY; 4452a2f7404SAndrew Armenia } 4462a2f7404SAndrew Armenia 4472a2f7404SAndrew Armenia dev_info(&PIIX4_dev->dev, 4482a2f7404SAndrew Armenia "Auxiliary SMBus Host Controller at 0x%x\n", 4492a2f7404SAndrew Armenia piix4_smba); 4502a2f7404SAndrew Armenia 4512a2f7404SAndrew Armenia return piix4_smba; 4522a2f7404SAndrew Armenia } 4532a2f7404SAndrew Armenia 454e154bf6fSAndrew Armenia static int piix4_transaction(struct i2c_adapter *piix4_adapter) 4551da177e4SLinus Torvalds { 456e154bf6fSAndrew Armenia struct i2c_piix4_adapdata *adapdata = i2c_get_adapdata(piix4_adapter); 457e154bf6fSAndrew Armenia unsigned short piix4_smba = adapdata->smba; 4581da177e4SLinus Torvalds int temp; 4591da177e4SLinus Torvalds int result = 0; 4601da177e4SLinus Torvalds int timeout = 0; 4611da177e4SLinus Torvalds 462e154bf6fSAndrew Armenia dev_dbg(&piix4_adapter->dev, "Transaction (pre): CNT=%02x, CMD=%02x, " 4631da177e4SLinus Torvalds "ADD=%02x, DAT0=%02x, DAT1=%02x\n", inb_p(SMBHSTCNT), 4641da177e4SLinus Torvalds inb_p(SMBHSTCMD), inb_p(SMBHSTADD), inb_p(SMBHSTDAT0), 4651da177e4SLinus Torvalds inb_p(SMBHSTDAT1)); 4661da177e4SLinus Torvalds 4671da177e4SLinus Torvalds /* Make sure the SMBus host is ready to start transmitting */ 4681da177e4SLinus Torvalds if ((temp = inb_p(SMBHSTSTS)) != 0x00) { 469e154bf6fSAndrew Armenia dev_dbg(&piix4_adapter->dev, "SMBus busy (%02x). " 4701da177e4SLinus Torvalds "Resetting...\n", temp); 4711da177e4SLinus Torvalds outb_p(temp, SMBHSTSTS); 4721da177e4SLinus Torvalds if ((temp = inb_p(SMBHSTSTS)) != 0x00) { 473e154bf6fSAndrew Armenia dev_err(&piix4_adapter->dev, "Failed! (%02x)\n", temp); 47497140342SDavid Brownell return -EBUSY; 4751da177e4SLinus Torvalds } else { 476e154bf6fSAndrew Armenia dev_dbg(&piix4_adapter->dev, "Successful!\n"); 4771da177e4SLinus Torvalds } 4781da177e4SLinus Torvalds } 4791da177e4SLinus Torvalds 4801da177e4SLinus Torvalds /* start the transaction by setting bit 6 */ 4811da177e4SLinus Torvalds outb_p(inb(SMBHSTCNT) | 0x040, SMBHSTCNT); 4821da177e4SLinus Torvalds 4831da177e4SLinus Torvalds /* We will always wait for a fraction of a second! (See PIIX4 docs errata) */ 484b1c1759cSDavid Milburn if (srvrworks_csb5_delay) /* Extra delay for SERVERWORKS_CSB5 */ 4850e89b2feSGuenter Roeck usleep_range(2000, 2100); 486b1c1759cSDavid Milburn else 4870e89b2feSGuenter Roeck usleep_range(250, 500); 488b1c1759cSDavid Milburn 489b6a31950SRoel Kluin while ((++timeout < MAX_TIMEOUT) && 490b1c1759cSDavid Milburn ((temp = inb_p(SMBHSTSTS)) & 0x01)) 4910e89b2feSGuenter Roeck usleep_range(250, 500); 4921da177e4SLinus Torvalds 4931da177e4SLinus Torvalds /* If the SMBus is still busy, we give up */ 494b6a31950SRoel Kluin if (timeout == MAX_TIMEOUT) { 495e154bf6fSAndrew Armenia dev_err(&piix4_adapter->dev, "SMBus Timeout!\n"); 49697140342SDavid Brownell result = -ETIMEDOUT; 4971da177e4SLinus Torvalds } 4981da177e4SLinus Torvalds 4991da177e4SLinus Torvalds if (temp & 0x10) { 50097140342SDavid Brownell result = -EIO; 501e154bf6fSAndrew Armenia dev_err(&piix4_adapter->dev, "Error: Failed bus transaction\n"); 5021da177e4SLinus Torvalds } 5031da177e4SLinus Torvalds 5041da177e4SLinus Torvalds if (temp & 0x08) { 50597140342SDavid Brownell result = -EIO; 506e154bf6fSAndrew Armenia dev_dbg(&piix4_adapter->dev, "Bus collision! SMBus may be " 5071da177e4SLinus Torvalds "locked until next hard reset. (sorry!)\n"); 5081da177e4SLinus Torvalds /* Clock stops and slave is stuck in mid-transmission */ 5091da177e4SLinus Torvalds } 5101da177e4SLinus Torvalds 5111da177e4SLinus Torvalds if (temp & 0x04) { 51297140342SDavid Brownell result = -ENXIO; 513e154bf6fSAndrew Armenia dev_dbg(&piix4_adapter->dev, "Error: no response!\n"); 5141da177e4SLinus Torvalds } 5151da177e4SLinus Torvalds 5161da177e4SLinus Torvalds if (inb_p(SMBHSTSTS) != 0x00) 5171da177e4SLinus Torvalds outb_p(inb(SMBHSTSTS), SMBHSTSTS); 5181da177e4SLinus Torvalds 5191da177e4SLinus Torvalds if ((temp = inb_p(SMBHSTSTS)) != 0x00) { 520e154bf6fSAndrew Armenia dev_err(&piix4_adapter->dev, "Failed reset at end of " 5211da177e4SLinus Torvalds "transaction (%02x)\n", temp); 5221da177e4SLinus Torvalds } 523e154bf6fSAndrew Armenia dev_dbg(&piix4_adapter->dev, "Transaction (post): CNT=%02x, CMD=%02x, " 5241da177e4SLinus Torvalds "ADD=%02x, DAT0=%02x, DAT1=%02x\n", inb_p(SMBHSTCNT), 5251da177e4SLinus Torvalds inb_p(SMBHSTCMD), inb_p(SMBHSTADD), inb_p(SMBHSTDAT0), 5261da177e4SLinus Torvalds inb_p(SMBHSTDAT1)); 5271da177e4SLinus Torvalds return result; 5281da177e4SLinus Torvalds } 5291da177e4SLinus Torvalds 53097140342SDavid Brownell /* Return negative errno on error. */ 5311da177e4SLinus Torvalds static s32 piix4_access(struct i2c_adapter * adap, u16 addr, 5321da177e4SLinus Torvalds unsigned short flags, char read_write, 5331da177e4SLinus Torvalds u8 command, int size, union i2c_smbus_data * data) 5341da177e4SLinus Torvalds { 53514a8086dSAndrew Armenia struct i2c_piix4_adapdata *adapdata = i2c_get_adapdata(adap); 53614a8086dSAndrew Armenia unsigned short piix4_smba = adapdata->smba; 5371da177e4SLinus Torvalds int i, len; 53897140342SDavid Brownell int status; 5391da177e4SLinus Torvalds 5401da177e4SLinus Torvalds switch (size) { 5411da177e4SLinus Torvalds case I2C_SMBUS_QUICK: 542fa63cd56SJean Delvare outb_p((addr << 1) | read_write, 5431da177e4SLinus Torvalds SMBHSTADD); 5441da177e4SLinus Torvalds size = PIIX4_QUICK; 5451da177e4SLinus Torvalds break; 5461da177e4SLinus Torvalds case I2C_SMBUS_BYTE: 547fa63cd56SJean Delvare outb_p((addr << 1) | read_write, 5481da177e4SLinus Torvalds SMBHSTADD); 5491da177e4SLinus Torvalds if (read_write == I2C_SMBUS_WRITE) 5501da177e4SLinus Torvalds outb_p(command, SMBHSTCMD); 5511da177e4SLinus Torvalds size = PIIX4_BYTE; 5521da177e4SLinus Torvalds break; 5531da177e4SLinus Torvalds case I2C_SMBUS_BYTE_DATA: 554fa63cd56SJean Delvare outb_p((addr << 1) | read_write, 5551da177e4SLinus Torvalds SMBHSTADD); 5561da177e4SLinus Torvalds outb_p(command, SMBHSTCMD); 5571da177e4SLinus Torvalds if (read_write == I2C_SMBUS_WRITE) 5581da177e4SLinus Torvalds outb_p(data->byte, SMBHSTDAT0); 5591da177e4SLinus Torvalds size = PIIX4_BYTE_DATA; 5601da177e4SLinus Torvalds break; 5611da177e4SLinus Torvalds case I2C_SMBUS_WORD_DATA: 562fa63cd56SJean Delvare outb_p((addr << 1) | read_write, 5631da177e4SLinus Torvalds SMBHSTADD); 5641da177e4SLinus Torvalds outb_p(command, SMBHSTCMD); 5651da177e4SLinus Torvalds if (read_write == I2C_SMBUS_WRITE) { 5661da177e4SLinus Torvalds outb_p(data->word & 0xff, SMBHSTDAT0); 5671da177e4SLinus Torvalds outb_p((data->word & 0xff00) >> 8, SMBHSTDAT1); 5681da177e4SLinus Torvalds } 5691da177e4SLinus Torvalds size = PIIX4_WORD_DATA; 5701da177e4SLinus Torvalds break; 5711da177e4SLinus Torvalds case I2C_SMBUS_BLOCK_DATA: 572fa63cd56SJean Delvare outb_p((addr << 1) | read_write, 5731da177e4SLinus Torvalds SMBHSTADD); 5741da177e4SLinus Torvalds outb_p(command, SMBHSTCMD); 5751da177e4SLinus Torvalds if (read_write == I2C_SMBUS_WRITE) { 5761da177e4SLinus Torvalds len = data->block[0]; 577fa63cd56SJean Delvare if (len == 0 || len > I2C_SMBUS_BLOCK_MAX) 578fa63cd56SJean Delvare return -EINVAL; 5791da177e4SLinus Torvalds outb_p(len, SMBHSTDAT0); 580d7a4c763SWolfram Sang inb_p(SMBHSTCNT); /* Reset SMBBLKDAT */ 5811da177e4SLinus Torvalds for (i = 1; i <= len; i++) 5821da177e4SLinus Torvalds outb_p(data->block[i], SMBBLKDAT); 5831da177e4SLinus Torvalds } 5841da177e4SLinus Torvalds size = PIIX4_BLOCK_DATA; 5851da177e4SLinus Torvalds break; 586ac7fc4fbSJean Delvare default: 587ac7fc4fbSJean Delvare dev_warn(&adap->dev, "Unsupported transaction %d\n", size); 588ac7fc4fbSJean Delvare return -EOPNOTSUPP; 5891da177e4SLinus Torvalds } 5901da177e4SLinus Torvalds 5911da177e4SLinus Torvalds outb_p((size & 0x1C) + (ENABLE_INT9 & 1), SMBHSTCNT); 5921da177e4SLinus Torvalds 593e154bf6fSAndrew Armenia status = piix4_transaction(adap); 59497140342SDavid Brownell if (status) 59597140342SDavid Brownell return status; 5961da177e4SLinus Torvalds 5971da177e4SLinus Torvalds if ((read_write == I2C_SMBUS_WRITE) || (size == PIIX4_QUICK)) 5981da177e4SLinus Torvalds return 0; 5991da177e4SLinus Torvalds 6001da177e4SLinus Torvalds 6011da177e4SLinus Torvalds switch (size) { 6023578a075SJean Delvare case PIIX4_BYTE: 6031da177e4SLinus Torvalds case PIIX4_BYTE_DATA: 6041da177e4SLinus Torvalds data->byte = inb_p(SMBHSTDAT0); 6051da177e4SLinus Torvalds break; 6061da177e4SLinus Torvalds case PIIX4_WORD_DATA: 6071da177e4SLinus Torvalds data->word = inb_p(SMBHSTDAT0) + (inb_p(SMBHSTDAT1) << 8); 6081da177e4SLinus Torvalds break; 6091da177e4SLinus Torvalds case PIIX4_BLOCK_DATA: 6101da177e4SLinus Torvalds data->block[0] = inb_p(SMBHSTDAT0); 611fa63cd56SJean Delvare if (data->block[0] == 0 || data->block[0] > I2C_SMBUS_BLOCK_MAX) 612fa63cd56SJean Delvare return -EPROTO; 613d7a4c763SWolfram Sang inb_p(SMBHSTCNT); /* Reset SMBBLKDAT */ 6141da177e4SLinus Torvalds for (i = 1; i <= data->block[0]; i++) 6151da177e4SLinus Torvalds data->block[i] = inb_p(SMBBLKDAT); 6161da177e4SLinus Torvalds break; 6171da177e4SLinus Torvalds } 6181da177e4SLinus Torvalds return 0; 6191da177e4SLinus Torvalds } 6201da177e4SLinus Torvalds 62188fa2dfbSRicardo Ribalda Delgado static uint8_t piix4_imc_read(uint8_t idx) 62288fa2dfbSRicardo Ribalda Delgado { 62388fa2dfbSRicardo Ribalda Delgado outb_p(idx, KERNCZ_IMC_IDX); 62488fa2dfbSRicardo Ribalda Delgado return inb_p(KERNCZ_IMC_DATA); 62588fa2dfbSRicardo Ribalda Delgado } 62688fa2dfbSRicardo Ribalda Delgado 62788fa2dfbSRicardo Ribalda Delgado static void piix4_imc_write(uint8_t idx, uint8_t value) 62888fa2dfbSRicardo Ribalda Delgado { 62988fa2dfbSRicardo Ribalda Delgado outb_p(idx, KERNCZ_IMC_IDX); 63088fa2dfbSRicardo Ribalda Delgado outb_p(value, KERNCZ_IMC_DATA); 63188fa2dfbSRicardo Ribalda Delgado } 63288fa2dfbSRicardo Ribalda Delgado 63388fa2dfbSRicardo Ribalda Delgado static int piix4_imc_sleep(void) 63488fa2dfbSRicardo Ribalda Delgado { 63588fa2dfbSRicardo Ribalda Delgado int timeout = MAX_TIMEOUT; 63688fa2dfbSRicardo Ribalda Delgado 63788fa2dfbSRicardo Ribalda Delgado if (!request_muxed_region(KERNCZ_IMC_IDX, 2, "smbus_kerncz_imc")) 63888fa2dfbSRicardo Ribalda Delgado return -EBUSY; 63988fa2dfbSRicardo Ribalda Delgado 64088fa2dfbSRicardo Ribalda Delgado /* clear response register */ 64188fa2dfbSRicardo Ribalda Delgado piix4_imc_write(0x82, 0x00); 64288fa2dfbSRicardo Ribalda Delgado /* request ownership flag */ 64388fa2dfbSRicardo Ribalda Delgado piix4_imc_write(0x83, 0xB4); 64488fa2dfbSRicardo Ribalda Delgado /* kick off IMC Mailbox command 96 */ 64588fa2dfbSRicardo Ribalda Delgado piix4_imc_write(0x80, 0x96); 64688fa2dfbSRicardo Ribalda Delgado 64788fa2dfbSRicardo Ribalda Delgado while (timeout--) { 64888fa2dfbSRicardo Ribalda Delgado if (piix4_imc_read(0x82) == 0xfa) { 64988fa2dfbSRicardo Ribalda Delgado release_region(KERNCZ_IMC_IDX, 2); 65088fa2dfbSRicardo Ribalda Delgado return 0; 65188fa2dfbSRicardo Ribalda Delgado } 65288fa2dfbSRicardo Ribalda Delgado usleep_range(1000, 2000); 65388fa2dfbSRicardo Ribalda Delgado } 65488fa2dfbSRicardo Ribalda Delgado 65588fa2dfbSRicardo Ribalda Delgado release_region(KERNCZ_IMC_IDX, 2); 65688fa2dfbSRicardo Ribalda Delgado return -ETIMEDOUT; 65788fa2dfbSRicardo Ribalda Delgado } 65888fa2dfbSRicardo Ribalda Delgado 65988fa2dfbSRicardo Ribalda Delgado static void piix4_imc_wakeup(void) 66088fa2dfbSRicardo Ribalda Delgado { 66188fa2dfbSRicardo Ribalda Delgado int timeout = MAX_TIMEOUT; 66288fa2dfbSRicardo Ribalda Delgado 66388fa2dfbSRicardo Ribalda Delgado if (!request_muxed_region(KERNCZ_IMC_IDX, 2, "smbus_kerncz_imc")) 66488fa2dfbSRicardo Ribalda Delgado return; 66588fa2dfbSRicardo Ribalda Delgado 66688fa2dfbSRicardo Ribalda Delgado /* clear response register */ 66788fa2dfbSRicardo Ribalda Delgado piix4_imc_write(0x82, 0x00); 66888fa2dfbSRicardo Ribalda Delgado /* release ownership flag */ 66988fa2dfbSRicardo Ribalda Delgado piix4_imc_write(0x83, 0xB5); 67088fa2dfbSRicardo Ribalda Delgado /* kick off IMC Mailbox command 96 */ 67188fa2dfbSRicardo Ribalda Delgado piix4_imc_write(0x80, 0x96); 67288fa2dfbSRicardo Ribalda Delgado 67388fa2dfbSRicardo Ribalda Delgado while (timeout--) { 67488fa2dfbSRicardo Ribalda Delgado if (piix4_imc_read(0x82) == 0xfa) 67588fa2dfbSRicardo Ribalda Delgado break; 67688fa2dfbSRicardo Ribalda Delgado usleep_range(1000, 2000); 67788fa2dfbSRicardo Ribalda Delgado } 67888fa2dfbSRicardo Ribalda Delgado 67988fa2dfbSRicardo Ribalda Delgado release_region(KERNCZ_IMC_IDX, 2); 68088fa2dfbSRicardo Ribalda Delgado } 68188fa2dfbSRicardo Ribalda Delgado 6822fee61d2SChristian Fetzer /* 6832fee61d2SChristian Fetzer * Handles access to multiple SMBus ports on the SB800. 6842fee61d2SChristian Fetzer * The port is selected by bits 2:1 of the smb_en register (0x2c). 6852fee61d2SChristian Fetzer * Returns negative errno on error. 6862fee61d2SChristian Fetzer * 6872fee61d2SChristian Fetzer * Note: The selected port must be returned to the initial selection to avoid 6882fee61d2SChristian Fetzer * problems on certain systems. 6892fee61d2SChristian Fetzer */ 6902fee61d2SChristian Fetzer static s32 piix4_access_sb800(struct i2c_adapter *adap, u16 addr, 6912fee61d2SChristian Fetzer unsigned short flags, char read_write, 6922fee61d2SChristian Fetzer u8 command, int size, union i2c_smbus_data *data) 6932fee61d2SChristian Fetzer { 6942fee61d2SChristian Fetzer struct i2c_piix4_adapdata *adapdata = i2c_get_adapdata(adap); 695701dc207SRicardo Ribalda unsigned short piix4_smba = adapdata->smba; 696701dc207SRicardo Ribalda int retries = MAX_TIMEOUT; 697701dc207SRicardo Ribalda int smbslvcnt; 6982fee61d2SChristian Fetzer u8 smba_en_lo; 6992fee61d2SChristian Fetzer u8 port; 7002fee61d2SChristian Fetzer int retval; 7012fee61d2SChristian Fetzer 702*a3325d22STerry Bowman retval = piix4_sb800_region_request(&adap->dev); 703*a3325d22STerry Bowman if (retval) 704*a3325d22STerry Bowman return retval; 705bbb27fc3SRicardo Ribalda 706701dc207SRicardo Ribalda /* Request the SMBUS semaphore, avoid conflicts with the IMC */ 707701dc207SRicardo Ribalda smbslvcnt = inb_p(SMBSLVCNT); 708701dc207SRicardo Ribalda do { 709701dc207SRicardo Ribalda outb_p(smbslvcnt | 0x10, SMBSLVCNT); 710701dc207SRicardo Ribalda 711701dc207SRicardo Ribalda /* Check the semaphore status */ 712701dc207SRicardo Ribalda smbslvcnt = inb_p(SMBSLVCNT); 713701dc207SRicardo Ribalda if (smbslvcnt & 0x10) 714701dc207SRicardo Ribalda break; 715701dc207SRicardo Ribalda 716701dc207SRicardo Ribalda usleep_range(1000, 2000); 717701dc207SRicardo Ribalda } while (--retries); 718701dc207SRicardo Ribalda /* SMBus is still owned by the IMC, we give up */ 719bbb27fc3SRicardo Ribalda if (!retries) { 72004b6fcabSGuenter Roeck retval = -EBUSY; 72104b6fcabSGuenter Roeck goto release; 722bbb27fc3SRicardo Ribalda } 7232fee61d2SChristian Fetzer 72488fa2dfbSRicardo Ribalda Delgado /* 72588fa2dfbSRicardo Ribalda Delgado * Notify the IMC (Integrated Micro Controller) if required. 72688fa2dfbSRicardo Ribalda Delgado * Among other responsibilities, the IMC is in charge of monitoring 72788fa2dfbSRicardo Ribalda Delgado * the System fans and temperature sensors, and act accordingly. 72888fa2dfbSRicardo Ribalda Delgado * All this is done through SMBus and can/will collide 72988fa2dfbSRicardo Ribalda Delgado * with our transactions if they are long (BLOCK_DATA). 73088fa2dfbSRicardo Ribalda Delgado * Therefore we need to request the ownership flag during those 73188fa2dfbSRicardo Ribalda Delgado * transactions. 73288fa2dfbSRicardo Ribalda Delgado */ 73388fa2dfbSRicardo Ribalda Delgado if ((size == I2C_SMBUS_BLOCK_DATA) && adapdata->notify_imc) { 73488fa2dfbSRicardo Ribalda Delgado int ret; 73588fa2dfbSRicardo Ribalda Delgado 73688fa2dfbSRicardo Ribalda Delgado ret = piix4_imc_sleep(); 73788fa2dfbSRicardo Ribalda Delgado switch (ret) { 73888fa2dfbSRicardo Ribalda Delgado case -EBUSY: 73988fa2dfbSRicardo Ribalda Delgado dev_warn(&adap->dev, 74088fa2dfbSRicardo Ribalda Delgado "IMC base address index region 0x%x already in use.\n", 74188fa2dfbSRicardo Ribalda Delgado KERNCZ_IMC_IDX); 74288fa2dfbSRicardo Ribalda Delgado break; 74388fa2dfbSRicardo Ribalda Delgado case -ETIMEDOUT: 74488fa2dfbSRicardo Ribalda Delgado dev_warn(&adap->dev, 74588fa2dfbSRicardo Ribalda Delgado "Failed to communicate with the IMC.\n"); 74688fa2dfbSRicardo Ribalda Delgado break; 74788fa2dfbSRicardo Ribalda Delgado default: 74888fa2dfbSRicardo Ribalda Delgado break; 74988fa2dfbSRicardo Ribalda Delgado } 75088fa2dfbSRicardo Ribalda Delgado 75188fa2dfbSRicardo Ribalda Delgado /* If IMC communication fails do not retry */ 75288fa2dfbSRicardo Ribalda Delgado if (ret) { 75388fa2dfbSRicardo Ribalda Delgado dev_warn(&adap->dev, 75488fa2dfbSRicardo Ribalda Delgado "Continuing without IMC notification.\n"); 75588fa2dfbSRicardo Ribalda Delgado adapdata->notify_imc = false; 75688fa2dfbSRicardo Ribalda Delgado } 75788fa2dfbSRicardo Ribalda Delgado } 75888fa2dfbSRicardo Ribalda Delgado 7596befa3fdSJean Delvare outb_p(piix4_port_sel_sb800, SB800_PIIX4_SMB_IDX); 7602fee61d2SChristian Fetzer smba_en_lo = inb_p(SB800_PIIX4_SMB_IDX + 1); 7612fee61d2SChristian Fetzer 7622fee61d2SChristian Fetzer port = adapdata->port; 7630fe16195SGuenter Roeck if ((smba_en_lo & piix4_port_mask_sb800) != port) 7640fe16195SGuenter Roeck outb_p((smba_en_lo & ~piix4_port_mask_sb800) | port, 7652fee61d2SChristian Fetzer SB800_PIIX4_SMB_IDX + 1); 7662fee61d2SChristian Fetzer 7672fee61d2SChristian Fetzer retval = piix4_access(adap, addr, flags, read_write, 7682fee61d2SChristian Fetzer command, size, data); 7692fee61d2SChristian Fetzer 7702fee61d2SChristian Fetzer outb_p(smba_en_lo, SB800_PIIX4_SMB_IDX + 1); 7712fee61d2SChristian Fetzer 772701dc207SRicardo Ribalda /* Release the semaphore */ 773701dc207SRicardo Ribalda outb_p(smbslvcnt | 0x20, SMBSLVCNT); 774701dc207SRicardo Ribalda 77588fa2dfbSRicardo Ribalda Delgado if ((size == I2C_SMBUS_BLOCK_DATA) && adapdata->notify_imc) 77688fa2dfbSRicardo Ribalda Delgado piix4_imc_wakeup(); 77788fa2dfbSRicardo Ribalda Delgado 77804b6fcabSGuenter Roeck release: 779*a3325d22STerry Bowman piix4_sb800_region_release(&adap->dev); 7802fee61d2SChristian Fetzer return retval; 7812fee61d2SChristian Fetzer } 7822fee61d2SChristian Fetzer 7831da177e4SLinus Torvalds static u32 piix4_func(struct i2c_adapter *adapter) 7841da177e4SLinus Torvalds { 7851da177e4SLinus Torvalds return I2C_FUNC_SMBUS_QUICK | I2C_FUNC_SMBUS_BYTE | 7861da177e4SLinus Torvalds I2C_FUNC_SMBUS_BYTE_DATA | I2C_FUNC_SMBUS_WORD_DATA | 7871da177e4SLinus Torvalds I2C_FUNC_SMBUS_BLOCK_DATA; 7881da177e4SLinus Torvalds } 7891da177e4SLinus Torvalds 7908f9082c5SJean Delvare static const struct i2c_algorithm smbus_algorithm = { 7911da177e4SLinus Torvalds .smbus_xfer = piix4_access, 7921da177e4SLinus Torvalds .functionality = piix4_func, 7931da177e4SLinus Torvalds }; 7941da177e4SLinus Torvalds 7952fee61d2SChristian Fetzer static const struct i2c_algorithm piix4_smbus_algorithm_sb800 = { 7962fee61d2SChristian Fetzer .smbus_xfer = piix4_access_sb800, 7972fee61d2SChristian Fetzer .functionality = piix4_func, 7982fee61d2SChristian Fetzer }; 7992fee61d2SChristian Fetzer 800392debf1SJingoo Han static const struct pci_device_id piix4_ids[] = { 8019b7389c0SJean Delvare { PCI_DEVICE(PCI_VENDOR_ID_INTEL, PCI_DEVICE_ID_INTEL_82371AB_3) }, 8029b7389c0SJean Delvare { PCI_DEVICE(PCI_VENDOR_ID_INTEL, PCI_DEVICE_ID_INTEL_82443MX_3) }, 8039b7389c0SJean Delvare { PCI_DEVICE(PCI_VENDOR_ID_EFAR, PCI_DEVICE_ID_EFAR_SLC90E66_3) }, 8049b7389c0SJean Delvare { PCI_DEVICE(PCI_VENDOR_ID_ATI, PCI_DEVICE_ID_ATI_IXP200_SMBUS) }, 8059b7389c0SJean Delvare { PCI_DEVICE(PCI_VENDOR_ID_ATI, PCI_DEVICE_ID_ATI_IXP300_SMBUS) }, 8069b7389c0SJean Delvare { PCI_DEVICE(PCI_VENDOR_ID_ATI, PCI_DEVICE_ID_ATI_IXP400_SMBUS) }, 8079b7389c0SJean Delvare { PCI_DEVICE(PCI_VENDOR_ID_ATI, PCI_DEVICE_ID_ATI_SBX00_SMBUS) }, 8083806e94bSCrane Cai { PCI_DEVICE(PCI_VENDOR_ID_AMD, PCI_DEVICE_ID_AMD_HUDSON2_SMBUS) }, 809bcb29994SVincent Wan { PCI_DEVICE(PCI_VENDOR_ID_AMD, PCI_DEVICE_ID_AMD_KERNCZ_SMBUS) }, 81024beb83aSPu Wen { PCI_DEVICE(PCI_VENDOR_ID_HYGON, PCI_DEVICE_ID_AMD_KERNCZ_SMBUS) }, 8119b7389c0SJean Delvare { PCI_DEVICE(PCI_VENDOR_ID_SERVERWORKS, 8129b7389c0SJean Delvare PCI_DEVICE_ID_SERVERWORKS_OSB4) }, 8139b7389c0SJean Delvare { PCI_DEVICE(PCI_VENDOR_ID_SERVERWORKS, 8149b7389c0SJean Delvare PCI_DEVICE_ID_SERVERWORKS_CSB5) }, 8159b7389c0SJean Delvare { PCI_DEVICE(PCI_VENDOR_ID_SERVERWORKS, 8169b7389c0SJean Delvare PCI_DEVICE_ID_SERVERWORKS_CSB6) }, 8179b7389c0SJean Delvare { PCI_DEVICE(PCI_VENDOR_ID_SERVERWORKS, 8189b7389c0SJean Delvare PCI_DEVICE_ID_SERVERWORKS_HT1000SB) }, 819506a8b6cSFlavio Leitner { PCI_DEVICE(PCI_VENDOR_ID_SERVERWORKS, 820506a8b6cSFlavio Leitner PCI_DEVICE_ID_SERVERWORKS_HT1100LD) }, 8211da177e4SLinus Torvalds { 0, } 8221da177e4SLinus Torvalds }; 8231da177e4SLinus Torvalds 8241da177e4SLinus Torvalds MODULE_DEVICE_TABLE (pci, piix4_ids); 8251da177e4SLinus Torvalds 826ca2061e1SChristian Fetzer static struct i2c_adapter *piix4_main_adapters[PIIX4_MAX_ADAPTERS]; 8272a2f7404SAndrew Armenia static struct i2c_adapter *piix4_aux_adapter; 828528d53a1SJean Delvare static int piix4_adapter_count; 829e154bf6fSAndrew Armenia 8300b255e92SBill Pemberton static int piix4_add_adapter(struct pci_dev *dev, unsigned short smba, 83188fa2dfbSRicardo Ribalda Delgado bool sb800_main, u8 port, bool notify_imc, 8320183eb8bSJean Delvare u8 hw_port_nr, const char *name, 8330183eb8bSJean Delvare struct i2c_adapter **padap) 834e154bf6fSAndrew Armenia { 835e154bf6fSAndrew Armenia struct i2c_adapter *adap; 836e154bf6fSAndrew Armenia struct i2c_piix4_adapdata *adapdata; 837e154bf6fSAndrew Armenia int retval; 838e154bf6fSAndrew Armenia 839e154bf6fSAndrew Armenia adap = kzalloc(sizeof(*adap), GFP_KERNEL); 840e154bf6fSAndrew Armenia if (adap == NULL) { 841e154bf6fSAndrew Armenia release_region(smba, SMBIOSIZE); 842e154bf6fSAndrew Armenia return -ENOMEM; 843e154bf6fSAndrew Armenia } 844e154bf6fSAndrew Armenia 845e154bf6fSAndrew Armenia adap->owner = THIS_MODULE; 846e154bf6fSAndrew Armenia adap->class = I2C_CLASS_HWMON | I2C_CLASS_SPD; 84783c60158SJean Delvare adap->algo = sb800_main ? &piix4_smbus_algorithm_sb800 84883c60158SJean Delvare : &smbus_algorithm; 849e154bf6fSAndrew Armenia 850e154bf6fSAndrew Armenia adapdata = kzalloc(sizeof(*adapdata), GFP_KERNEL); 851e154bf6fSAndrew Armenia if (adapdata == NULL) { 852e154bf6fSAndrew Armenia kfree(adap); 853e154bf6fSAndrew Armenia release_region(smba, SMBIOSIZE); 854e154bf6fSAndrew Armenia return -ENOMEM; 855e154bf6fSAndrew Armenia } 856e154bf6fSAndrew Armenia 857e154bf6fSAndrew Armenia adapdata->smba = smba; 85883c60158SJean Delvare adapdata->sb800_main = sb800_main; 8590fe16195SGuenter Roeck adapdata->port = port << piix4_port_shift_sb800; 86088fa2dfbSRicardo Ribalda Delgado adapdata->notify_imc = notify_imc; 861e154bf6fSAndrew Armenia 862e154bf6fSAndrew Armenia /* set up the sysfs linkage to our parent device */ 863e154bf6fSAndrew Armenia adap->dev.parent = &dev->dev; 864e154bf6fSAndrew Armenia 8650183eb8bSJean Delvare if (has_acpi_companion(&dev->dev)) { 8660183eb8bSJean Delvare acpi_preset_companion(&adap->dev, 8670183eb8bSJean Delvare ACPI_COMPANION(&dev->dev), 8680183eb8bSJean Delvare hw_port_nr); 8690183eb8bSJean Delvare } 8700183eb8bSJean Delvare 871e154bf6fSAndrew Armenia snprintf(adap->name, sizeof(adap->name), 872725d2e3fSChristian Fetzer "SMBus PIIX4 adapter%s at %04x", name, smba); 873e154bf6fSAndrew Armenia 874e154bf6fSAndrew Armenia i2c_set_adapdata(adap, adapdata); 875e154bf6fSAndrew Armenia 876e154bf6fSAndrew Armenia retval = i2c_add_adapter(adap); 877e154bf6fSAndrew Armenia if (retval) { 878e154bf6fSAndrew Armenia kfree(adapdata); 879e154bf6fSAndrew Armenia kfree(adap); 880e154bf6fSAndrew Armenia release_region(smba, SMBIOSIZE); 881e154bf6fSAndrew Armenia return retval; 882e154bf6fSAndrew Armenia } 883e154bf6fSAndrew Armenia 884e154bf6fSAndrew Armenia *padap = adap; 885e154bf6fSAndrew Armenia return 0; 886e154bf6fSAndrew Armenia } 887e154bf6fSAndrew Armenia 88888fa2dfbSRicardo Ribalda Delgado static int piix4_add_adapters_sb800(struct pci_dev *dev, unsigned short smba, 88988fa2dfbSRicardo Ribalda Delgado bool notify_imc) 8902fee61d2SChristian Fetzer { 8912fee61d2SChristian Fetzer struct i2c_piix4_adapdata *adapdata; 8922fee61d2SChristian Fetzer int port; 8932fee61d2SChristian Fetzer int retval; 8942fee61d2SChristian Fetzer 895528d53a1SJean Delvare if (dev->device == PCI_DEVICE_ID_AMD_KERNCZ_SMBUS || 896528d53a1SJean Delvare (dev->device == PCI_DEVICE_ID_AMD_HUDSON2_SMBUS && 897528d53a1SJean Delvare dev->revision >= 0x1F)) { 898528d53a1SJean Delvare piix4_adapter_count = HUDSON2_MAIN_PORTS; 899528d53a1SJean Delvare } else { 900528d53a1SJean Delvare piix4_adapter_count = PIIX4_MAX_ADAPTERS; 901528d53a1SJean Delvare } 902528d53a1SJean Delvare 903528d53a1SJean Delvare for (port = 0; port < piix4_adapter_count; port++) { 9040183eb8bSJean Delvare u8 hw_port_nr = port == 0 ? 0 : port + 1; 9050183eb8bSJean Delvare 90688fa2dfbSRicardo Ribalda Delgado retval = piix4_add_adapter(dev, smba, true, port, notify_imc, 9070183eb8bSJean Delvare hw_port_nr, 908725d2e3fSChristian Fetzer piix4_main_port_names_sb800[port], 9092fee61d2SChristian Fetzer &piix4_main_adapters[port]); 9102fee61d2SChristian Fetzer if (retval < 0) 9112fee61d2SChristian Fetzer goto error; 9122fee61d2SChristian Fetzer } 9132fee61d2SChristian Fetzer 9142fee61d2SChristian Fetzer return retval; 9152fee61d2SChristian Fetzer 9162fee61d2SChristian Fetzer error: 9172fee61d2SChristian Fetzer dev_err(&dev->dev, 9182fee61d2SChristian Fetzer "Error setting up SB800 adapters. Unregistering!\n"); 9192fee61d2SChristian Fetzer while (--port >= 0) { 9202fee61d2SChristian Fetzer adapdata = i2c_get_adapdata(piix4_main_adapters[port]); 9212fee61d2SChristian Fetzer if (adapdata->smba) { 9222fee61d2SChristian Fetzer i2c_del_adapter(piix4_main_adapters[port]); 9232fee61d2SChristian Fetzer kfree(adapdata); 9242fee61d2SChristian Fetzer kfree(piix4_main_adapters[port]); 9252fee61d2SChristian Fetzer piix4_main_adapters[port] = NULL; 9262fee61d2SChristian Fetzer } 9272fee61d2SChristian Fetzer } 9282fee61d2SChristian Fetzer 9292fee61d2SChristian Fetzer return retval; 9302fee61d2SChristian Fetzer } 9312fee61d2SChristian Fetzer 9320b255e92SBill Pemberton static int piix4_probe(struct pci_dev *dev, const struct pci_device_id *id) 9331da177e4SLinus Torvalds { 9341da177e4SLinus Torvalds int retval; 93552795f6fSJean Delvare bool is_sb800 = false; 9361da177e4SLinus Torvalds 93776b3e28fSCrane Cai if ((dev->vendor == PCI_VENDOR_ID_ATI && 93876b3e28fSCrane Cai dev->device == PCI_DEVICE_ID_ATI_SBX00_SMBUS && 93976b3e28fSCrane Cai dev->revision >= 0x40) || 94024beb83aSPu Wen dev->vendor == PCI_VENDOR_ID_AMD || 94124beb83aSPu Wen dev->vendor == PCI_VENDOR_ID_HYGON) { 94288fa2dfbSRicardo Ribalda Delgado bool notify_imc = false; 94352795f6fSJean Delvare is_sb800 = true; 94452795f6fSJean Delvare 94524beb83aSPu Wen if ((dev->vendor == PCI_VENDOR_ID_AMD || 94624beb83aSPu Wen dev->vendor == PCI_VENDOR_ID_HYGON) && 94788fa2dfbSRicardo Ribalda Delgado dev->device == PCI_DEVICE_ID_AMD_KERNCZ_SMBUS) { 94888fa2dfbSRicardo Ribalda Delgado u8 imc; 94988fa2dfbSRicardo Ribalda Delgado 95088fa2dfbSRicardo Ribalda Delgado /* 95188fa2dfbSRicardo Ribalda Delgado * Detect if IMC is active or not, this method is 95288fa2dfbSRicardo Ribalda Delgado * described on coreboot's AMD IMC notes 95388fa2dfbSRicardo Ribalda Delgado */ 95488fa2dfbSRicardo Ribalda Delgado pci_bus_read_config_byte(dev->bus, PCI_DEVFN(0x14, 3), 95588fa2dfbSRicardo Ribalda Delgado 0x40, &imc); 95688fa2dfbSRicardo Ribalda Delgado if (imc & 0x80) 95788fa2dfbSRicardo Ribalda Delgado notify_imc = true; 95888fa2dfbSRicardo Ribalda Delgado } 95988fa2dfbSRicardo Ribalda Delgado 96087e1960eSShane Huang /* base address location etc changed in SB800 */ 961a94dd00fSRudolf Marek retval = piix4_setup_sb800(dev, id, 0); 96204b6fcabSGuenter Roeck if (retval < 0) 9632fee61d2SChristian Fetzer return retval; 96487e1960eSShane Huang 9652fee61d2SChristian Fetzer /* 9662fee61d2SChristian Fetzer * Try to register multiplexed main SMBus adapter, 9672fee61d2SChristian Fetzer * give up if we can't 9682fee61d2SChristian Fetzer */ 96988fa2dfbSRicardo Ribalda Delgado retval = piix4_add_adapters_sb800(dev, retval, notify_imc); 97004b6fcabSGuenter Roeck if (retval < 0) 9712fee61d2SChristian Fetzer return retval; 9722fee61d2SChristian Fetzer } else { 9732fee61d2SChristian Fetzer retval = piix4_setup(dev, id); 97414a8086dSAndrew Armenia if (retval < 0) 9751da177e4SLinus Torvalds return retval; 9761da177e4SLinus Torvalds 9772a2f7404SAndrew Armenia /* Try to register main SMBus adapter, give up if we can't */ 9780183eb8bSJean Delvare retval = piix4_add_adapter(dev, retval, false, 0, false, 0, 9790183eb8bSJean Delvare "", &piix4_main_adapters[0]); 9802a2f7404SAndrew Armenia if (retval < 0) 9812a2f7404SAndrew Armenia return retval; 9822fee61d2SChristian Fetzer } 9832a2f7404SAndrew Armenia 9842a2f7404SAndrew Armenia /* Check for auxiliary SMBus on some AMD chipsets */ 985a94dd00fSRudolf Marek retval = -ENODEV; 986a94dd00fSRudolf Marek 9872a2f7404SAndrew Armenia if (dev->vendor == PCI_VENDOR_ID_ATI && 988a94dd00fSRudolf Marek dev->device == PCI_DEVICE_ID_ATI_SBX00_SMBUS) { 989a94dd00fSRudolf Marek if (dev->revision < 0x40) { 9902a2f7404SAndrew Armenia retval = piix4_setup_aux(dev, id, 0x58); 991a94dd00fSRudolf Marek } else { 992a94dd00fSRudolf Marek /* SB800 added aux bus too */ 993a94dd00fSRudolf Marek retval = piix4_setup_sb800(dev, id, 1); 994a94dd00fSRudolf Marek } 995a94dd00fSRudolf Marek } 996a94dd00fSRudolf Marek 997a94dd00fSRudolf Marek if (dev->vendor == PCI_VENDOR_ID_AMD && 998f27237c1SAdam Honse (dev->device == PCI_DEVICE_ID_AMD_HUDSON2_SMBUS || 999f27237c1SAdam Honse dev->device == PCI_DEVICE_ID_AMD_KERNCZ_SMBUS)) { 1000a94dd00fSRudolf Marek retval = piix4_setup_sb800(dev, id, 1); 1001a94dd00fSRudolf Marek } 1002a94dd00fSRudolf Marek 10032a2f7404SAndrew Armenia if (retval > 0) { 10042a2f7404SAndrew Armenia /* Try to add the aux adapter if it exists, 10052a2f7404SAndrew Armenia * piix4_add_adapter will clean up if this fails */ 10060183eb8bSJean Delvare piix4_add_adapter(dev, retval, false, 0, false, 1, 100752795f6fSJean Delvare is_sb800 ? piix4_aux_port_name_sb800 : "", 1008725d2e3fSChristian Fetzer &piix4_aux_adapter); 10092a2f7404SAndrew Armenia } 10102a2f7404SAndrew Armenia 10112a2f7404SAndrew Armenia return 0; 10121da177e4SLinus Torvalds } 10131da177e4SLinus Torvalds 10140b255e92SBill Pemberton static void piix4_adap_remove(struct i2c_adapter *adap) 101514a8086dSAndrew Armenia { 101614a8086dSAndrew Armenia struct i2c_piix4_adapdata *adapdata = i2c_get_adapdata(adap); 101714a8086dSAndrew Armenia 101814a8086dSAndrew Armenia if (adapdata->smba) { 101914a8086dSAndrew Armenia i2c_del_adapter(adap); 102004b6fcabSGuenter Roeck if (adapdata->port == (0 << piix4_port_shift_sb800)) 102114a8086dSAndrew Armenia release_region(adapdata->smba, SMBIOSIZE); 1022e154bf6fSAndrew Armenia kfree(adapdata); 1023e154bf6fSAndrew Armenia kfree(adap); 102414a8086dSAndrew Armenia } 102514a8086dSAndrew Armenia } 102614a8086dSAndrew Armenia 10270b255e92SBill Pemberton static void piix4_remove(struct pci_dev *dev) 10281da177e4SLinus Torvalds { 1029528d53a1SJean Delvare int port = piix4_adapter_count; 1030ca2061e1SChristian Fetzer 1031ca2061e1SChristian Fetzer while (--port >= 0) { 1032ca2061e1SChristian Fetzer if (piix4_main_adapters[port]) { 1033ca2061e1SChristian Fetzer piix4_adap_remove(piix4_main_adapters[port]); 1034ca2061e1SChristian Fetzer piix4_main_adapters[port] = NULL; 1035ca2061e1SChristian Fetzer } 1036e154bf6fSAndrew Armenia } 10372a2f7404SAndrew Armenia 10382a2f7404SAndrew Armenia if (piix4_aux_adapter) { 10392a2f7404SAndrew Armenia piix4_adap_remove(piix4_aux_adapter); 10402a2f7404SAndrew Armenia piix4_aux_adapter = NULL; 10412a2f7404SAndrew Armenia } 10421da177e4SLinus Torvalds } 10431da177e4SLinus Torvalds 10441da177e4SLinus Torvalds static struct pci_driver piix4_driver = { 10451da177e4SLinus Torvalds .name = "piix4_smbus", 10461da177e4SLinus Torvalds .id_table = piix4_ids, 10471da177e4SLinus Torvalds .probe = piix4_probe, 10480b255e92SBill Pemberton .remove = piix4_remove, 10491da177e4SLinus Torvalds }; 10501da177e4SLinus Torvalds 105156f21788SAxel Lin module_pci_driver(piix4_driver); 10521da177e4SLinus Torvalds 1053f80531c8SJarkko Nikula MODULE_AUTHOR("Frodo Looijaard <frodol@dds.nl>"); 1054f80531c8SJarkko Nikula MODULE_AUTHOR("Philip Edelbrock <phil@netroedge.com>"); 10551da177e4SLinus Torvalds MODULE_DESCRIPTION("PIIX4 SMBus driver"); 10561da177e4SLinus Torvalds MODULE_LICENSE("GPL"); 1057