Note: we assume there can only be one device, with one or more SMBus interfaces. The device can register multiple i2c_adapters (up to PIIX4_MAX_ADAPTERS). For devices supporting multiple ports the i2c_adapter should provide an i2c_algorithm to access them.
*/
/* * SB800 port is selected by bits 2:1 of the smb_en register (0x2c) * or the smb_sel register (0x2e), depending on bit 0 of register 0x2f. * Hudson-2/Bolton port is always selected by bits 2:1 of register 0x2f.
*/ #define SB800_PIIX4_PORT_IDX 0x2c #define SB800_PIIX4_PORT_IDX_ALT 0x2e #define SB800_PIIX4_PORT_IDX_SEL 0x2f #define SB800_PIIX4_PORT_IDX_MASK 0x06 #define SB800_PIIX4_PORT_IDX_SHIFT 1
/* SmBus0Sel is at bit 20:19 of PMx00 DecodeEn */ #define SB800_PIIX4_PORT_IDX_KERNCZ (FCH_PM_DECODEEN + 0x02) #define SB800_PIIX4_PORT_IDX_MASK_KERNCZ (FCH_PM_DECODEEN_SMBUS0SEL >> 16) #define SB800_PIIX4_PORT_IDX_SHIFT_KERNCZ 3
/* If force is set to anything different from 0, we forcibly enable the
PIIX4. DANGEROUS! */ staticint force;
module_param (force, int, 0);
MODULE_PARM_DESC(force, "Forcibly enable the PIIX4. DANGEROUS!");
/* If force_addr is set to anything different from 0, we forcibly enable
the PIIX4 at the given address. VERY DANGEROUS! */ staticint force_addr;
module_param_hw(force_addr, int, ioport, 0);
MODULE_PARM_DESC(force_addr, "Forcibly enable the PIIX4 at the given address. " "EXTREMELY DANGEROUS!");
/* The IBM entry is in a separate table because we only check it
on Intel-based systems */ staticconststruct dmi_system_id piix4_dmi_ibm[] = {
{
.ident = "IBM",
.matches = { DMI_MATCH(DMI_SYS_VENDOR, "IBM"), },
},
{ }
};
/* * SB800 globals
*/ static u8 piix4_port_sel_sb800; static u8 piix4_port_mask_sb800; static u8 piix4_port_shift_sb800; staticconstchar *piix4_main_port_names_sb800[PIIX4_MAX_ADAPTERS] = { " port 0", " port 2", " port 3", " port 4"
}; staticconstchar *piix4_aux_port_name_sb800 = " port 1";
int piix4_sb800_region_request(struct device *dev, struct sb800_mmio_cfg *mmio_cfg)
{ if (mmio_cfg->use_mmio) { void __iomem *addr;
if (!request_mem_region_muxed(FCH_PM_BASE,
SB800_PIIX4_FCH_PM_SIZE, "sb800_piix4_smb")) {
dev_err(dev, "SMBus base address memory region 0x%x already in use.\n",
FCH_PM_BASE); return -EBUSY;
}
addr = ioremap(FCH_PM_BASE,
SB800_PIIX4_FCH_PM_SIZE); if (!addr) {
release_mem_region(FCH_PM_BASE,
SB800_PIIX4_FCH_PM_SIZE);
dev_err(dev, "SMBus base address mapping failed.\n"); return -ENOMEM;
}
mmio_cfg->addr = addr;
return 0;
}
if (!request_muxed_region(SB800_PIIX4_SMB_IDX, SB800_PIIX4_SMB_MAP_SIZE, "sb800_piix4_smb")) {
dev_err(dev, "SMBus base address index region 0x%x already in use.\n",
SB800_PIIX4_SMB_IDX); return -EBUSY;
}
staticbool piix4_sb800_use_mmio(struct pci_dev *PIIX4_dev)
{ /* * cd6h/cd7h port I/O accesses can be disabled on AMD processors * w/ SMBus PCI revision ID 0x51 or greater. MMIO is supported on * the same processors and is the recommended access method.
*/ return (PIIX4_dev->vendor == PCI_VENDOR_ID_AMD &&
PIIX4_dev->device == PCI_DEVICE_ID_AMD_KERNCZ_SMBUS &&
PIIX4_dev->revision >= 0x51);
}
/* On some motherboards, it was reported that accessing the SMBus
caused severe hardware problems */ if (dmi_check_system(piix4_dmi_blacklist)) {
dev_err(&PIIX4_dev->dev, "Accessing the SMBus on this system is unsafe!\n"); return -EPERM;
}
/* Don't access SMBus on IBM systems which get corrupted eeproms */ if (dmi_check_system(piix4_dmi_ibm) &&
PIIX4_dev->vendor == PCI_VENDOR_ID_INTEL) {
dev_err(&PIIX4_dev->dev, "IBM system detected; this module " "may corrupt your serial eeprom! Refusing to load " "module!\n"); return -EPERM;
}
/* Determine the address of the SMBus areas */ if (force_addr) {
piix4_smba = force_addr & 0xfff0;
force = 0;
} else {
pci_read_config_word(PIIX4_dev, SMBBA, &piix4_smba);
piix4_smba &= 0xfff0; if(piix4_smba == 0) {
dev_err(&PIIX4_dev->dev, "SMBus base address " "uninitialized - upgrade BIOS or use " "force_addr=0xaddr\n"); return -ENODEV;
}
}
if (acpi_check_region(piix4_smba, SMBIOSIZE, piix4_driver.name)) return -ENODEV;
if (!request_region(piix4_smba, SMBIOSIZE, piix4_driver.name)) {
dev_err(&PIIX4_dev->dev, "SMBus region 0x%x already in use!\n",
piix4_smba); return -EBUSY;
}
/* If force_addr is set, we program the new address here. Just to make
sure, we disable the PIIX4 first. */ if (force_addr) {
pci_write_config_byte(PIIX4_dev, SMBHSTCFG, temp & 0xfe);
pci_write_config_word(PIIX4_dev, SMBBA, piix4_smba);
pci_write_config_byte(PIIX4_dev, SMBHSTCFG, temp | 0x01);
dev_info(&PIIX4_dev->dev, "WARNING: SMBus interface set to " "new address %04x!\n", piix4_smba);
} elseif ((temp & 1) == 0) { if (force) { /* This should never need to be done, but has been * noted that many Dell machines have the SMBus * interface on the PIIX4 disabled!? NOTE: This assumes * I/O space and other allocations WERE done by the * Bios! Don't complain if your hardware does weird * things after enabling this. :') Check for Bios * updates before resorting to this.
*/
pci_write_config_byte(PIIX4_dev, SMBHSTCFG,
temp | 1);
dev_notice(&PIIX4_dev->dev, "WARNING: SMBus interface has been FORCEFULLY ENABLED!\n");
} else {
dev_err(&PIIX4_dev->dev, "SMBus Host Controller not enabled!\n");
release_region(piix4_smba, SMBIOSIZE); return -ENODEV;
}
}
if (((temp & 0x0E) == 8) || ((temp & 0x0E) == 2))
dev_dbg(&PIIX4_dev->dev, "Using IRQ for SMBus\n"); elseif ((temp & 0x0E) == 0)
dev_dbg(&PIIX4_dev->dev, "Using SMI# for SMBus\n"); else
dev_err(&PIIX4_dev->dev, "Illegal Interrupt configuration " "(or code out of date)!\n");
/* SB800 and later SMBus does not support forcing address */ if (force || force_addr) {
dev_err(&PIIX4_dev->dev, "SMBus does not support " "forcing address!\n"); return -EINVAL;
}
if (acpi_check_region(piix4_smba, SMBIOSIZE, piix4_driver.name)) return -ENODEV;
if (!request_region(piix4_smba, SMBIOSIZE, piix4_driver.name)) {
dev_err(&PIIX4_dev->dev, "SMBus region 0x%x already in use!\n",
piix4_smba); return -EBUSY;
}
/* Aux SMBus does not support IRQ information */ if (aux) {
dev_info(&PIIX4_dev->dev, "Auxiliary SMBus Host Controller at 0x%x\n",
piix4_smba); return piix4_smba;
}
/* Request the SMBus I2C bus config region */ if (!request_region(piix4_smba + i2ccfg_offset, 1, "i2ccfg")) {
dev_err(&PIIX4_dev->dev, "SMBus I2C bus config region " "0x%x already in use!\n", piix4_smba + i2ccfg_offset);
release_region(piix4_smba, SMBIOSIZE); return -EBUSY;
}
i2ccfg = inb_p(piix4_smba + i2ccfg_offset);
release_region(piix4_smba + i2ccfg_offset, 1);
if (i2ccfg & 1)
dev_dbg(&PIIX4_dev->dev, "Using IRQ for SMBus\n"); else
dev_dbg(&PIIX4_dev->dev, "Using SMI# for SMBus\n");
dev_info(&PIIX4_dev->dev, "Using register 0x%02x for SMBus port selection\n",
(unsignedint)piix4_port_sel_sb800);
return piix4_smba;
}
staticint piix4_setup_aux(struct pci_dev *PIIX4_dev, conststruct pci_device_id *id, unsignedshort base_reg_addr)
{ /* Set up auxiliary SMBus controllers found on some
* AMD chipsets e.g. SP5100 (SB700 derivative) */
unsignedshort piix4_smba;
/* Read address of auxiliary SMBus controller */
pci_read_config_word(PIIX4_dev, base_reg_addr, &piix4_smba); if ((piix4_smba & 1) == 0) {
dev_dbg(&PIIX4_dev->dev, "Auxiliary SMBus controller not enabled\n"); return -ENODEV;
}
piix4_smba &= 0xfff0; if (piix4_smba == 0) {
dev_dbg(&PIIX4_dev->dev, "Auxiliary SMBus base address uninitialized\n"); return -ENODEV;
}
if (acpi_check_region(piix4_smba, SMBIOSIZE, piix4_driver.name)) return -ENODEV;
if (!request_region(piix4_smba, SMBIOSIZE, piix4_driver.name)) {
dev_err(&PIIX4_dev->dev, "Auxiliary SMBus region 0x%x " "already in use!\n", piix4_smba); return -EBUSY;
}
dev_info(&PIIX4_dev->dev, "Auxiliary SMBus Host Controller at 0x%x\n",
piix4_smba);
return piix4_smba;
}
int piix4_transaction(struct i2c_adapter *piix4_adapter, unsignedshort piix4_smba)
{ int temp; int result = 0; int timeout = 0;
/* Make sure the SMBus host is ready to start transmitting */ if ((temp = inb_p(SMBHSTSTS)) != 0x00) {
dev_dbg(&piix4_adapter->dev, "SMBus busy (%02x). " "Resetting...\n", temp);
outb_p(temp, SMBHSTSTS); if ((temp = inb_p(SMBHSTSTS)) != 0x00) {
dev_err(&piix4_adapter->dev, "Failed! (%02x)\n", temp); return -EBUSY;
} else {
dev_dbg(&piix4_adapter->dev, "Successful!\n");
}
}
/* start the transaction by setting bit 6 */
outb_p(inb(SMBHSTCNT) | 0x040, SMBHSTCNT);
/* We will always wait for a fraction of a second! (See PIIX4 docs errata) */ if (srvrworks_csb5_delay) /* Extra delay for SERVERWORKS_CSB5 */
usleep_range(2000, 2100); else
usleep_range(250, 500);
/* If the SMBus is still busy, we give up */ if (timeout == MAX_TIMEOUT) {
dev_err(&piix4_adapter->dev, "SMBus Timeout!\n");
result = -ETIMEDOUT;
}
if (temp & 0x10) {
result = -EIO;
dev_err(&piix4_adapter->dev, "Error: Failed bus transaction\n");
}
if (temp & 0x08) {
result = -EIO;
dev_dbg(&piix4_adapter->dev, "Bus collision! SMBus may be " "locked until next hard reset. (sorry!)\n"); /* Clock stops and target is stuck in mid-transmission */
}
if (temp & 0x04) {
result = -ENXIO;
dev_dbg(&piix4_adapter->dev, "Error: no response!\n");
}
if (inb_p(SMBHSTSTS) != 0x00)
outb_p(inb(SMBHSTSTS), SMBHSTSTS);
if ((temp = inb_p(SMBHSTSTS)) != 0x00) {
dev_err(&piix4_adapter->dev, "Failed reset at end of " "transaction (%02x)\n", temp);
}
dev_dbg(&piix4_adapter->dev, "Transaction (post): CNT=%02x, CMD=%02x, " "ADD=%02x, DAT0=%02x, DAT1=%02x\n", inb_p(SMBHSTCNT),
inb_p(SMBHSTCMD), inb_p(SMBHSTADD), inb_p(SMBHSTDAT0),
inb_p(SMBHSTDAT1)); return result;
}
EXPORT_SYMBOL_NS_GPL(piix4_transaction, "PIIX4_SMBUS");
/* Return negative errno on error. */ static s32 piix4_access(struct i2c_adapter * adap, u16 addr, unsignedshort flags, char read_write,
u8 command, int size, union i2c_smbus_data * data)
{ struct i2c_piix4_adapdata *adapdata = i2c_get_adapdata(adap); unsignedshort piix4_smba = adapdata->smba; int i, len; int status;
switch (size) { case I2C_SMBUS_QUICK:
outb_p((addr << 1) | read_write,
SMBHSTADD);
size = PIIX4_QUICK; break; case I2C_SMBUS_BYTE:
outb_p((addr << 1) | read_write,
SMBHSTADD); if (read_write == I2C_SMBUS_WRITE)
outb_p(command, SMBHSTCMD);
size = PIIX4_BYTE; break; case I2C_SMBUS_BYTE_DATA:
outb_p((addr << 1) | read_write,
SMBHSTADD);
outb_p(command, SMBHSTCMD); if (read_write == I2C_SMBUS_WRITE)
outb_p(data->byte, SMBHSTDAT0);
size = PIIX4_BYTE_DATA; break; case I2C_SMBUS_WORD_DATA:
outb_p((addr << 1) | read_write,
SMBHSTADD);
outb_p(command, SMBHSTCMD); if (read_write == I2C_SMBUS_WRITE) {
outb_p(data->word & 0xff, SMBHSTDAT0);
outb_p((data->word & 0xff00) >> 8, SMBHSTDAT1);
}
size = PIIX4_WORD_DATA; break; case I2C_SMBUS_BLOCK_DATA:
outb_p((addr << 1) | read_write,
SMBHSTADD);
outb_p(command, SMBHSTCMD); if (read_write == I2C_SMBUS_WRITE) {
len = data->block[0]; if (len == 0 || len > I2C_SMBUS_BLOCK_MAX) return -EINVAL;
outb_p(len, SMBHSTDAT0);
inb_p(SMBHSTCNT); /* Reset SMBBLKDAT */ for (i = 1; i <= len; i++)
outb_p(data->block[i], SMBBLKDAT);
}
size = PIIX4_BLOCK_DATA; break; default:
dev_warn(&adap->dev, "Unsupported transaction %d\n", size); return -EOPNOTSUPP;
}
/* * Handles access to multiple SMBus ports on the SB800. * The port is selected by bits 2:1 of the smb_en register (0x2c). * Returns negative errno on error. * * Note: The selected port must be returned to the initial selection to avoid * problems on certain systems.
*/ static s32 piix4_access_sb800(struct i2c_adapter *adap, u16 addr, unsignedshort flags, char read_write,
u8 command, int size, union i2c_smbus_data *data)
{ struct i2c_piix4_adapdata *adapdata = i2c_get_adapdata(adap); unsignedshort piix4_smba = adapdata->smba; int retries = MAX_TIMEOUT; int smbslvcnt;
u8 prev_port; int retval;
retval = piix4_sb800_region_request(&adap->dev, &adapdata->mmio_cfg); if (retval) return retval;
/* Request the SMBUS semaphore, avoid conflicts with the IMC */
smbslvcnt = inb_p(SMBSLVCNT); do {
outb_p(smbslvcnt | 0x10, SMBSLVCNT);
/* Check the semaphore status */
smbslvcnt = inb_p(SMBSLVCNT); if (smbslvcnt & 0x10) break;
usleep_range(1000, 2000);
} while (--retries); /* SMBus is still owned by the IMC, we give up */ if (!retries) {
retval = -EBUSY; goto release;
}
/* * Notify the IMC (Integrated Micro Controller) if required. * Among other responsibilities, the IMC is in charge of monitoring * the System fans and temperature sensors, and act accordingly. * All this is done through SMBus and can/will collide * with our transactions if they are long (BLOCK_DATA). * Therefore we need to request the ownership flag during those * transactions.
*/ if ((size == I2C_SMBUS_BLOCK_DATA) && adapdata->notify_imc) { int ret;
ret = piix4_imc_sleep(); switch (ret) { case -EBUSY:
dev_warn(&adap->dev, "IMC base address index region 0x%x already in use.\n",
KERNCZ_IMC_IDX); break; case -ETIMEDOUT:
dev_warn(&adap->dev, "Failed to communicate with the IMC.\n"); break; default: break;
}
/* If IMC communication fails do not retry */ if (ret) {
dev_warn(&adap->dev, "Continuing without IMC notification.\n");
adapdata->notify_imc = false;
}
}
/* * The AUX bus can not be probed as on some platforms it reports all * devices present and all reads return "0". * This would allow the ee1004 to be probed incorrectly.
*/ if (port == 0)
i2c_register_spd_write_enable(adap);
*padap = adap; return 0;
}
staticint piix4_add_adapters_sb800(struct pci_dev *dev, unsignedshort smba, bool notify_imc)
{ struct i2c_piix4_adapdata *adapdata; int port; int retval;
/* * Detect if IMC is active or not, this method is * described on coreboot's AMD IMC notes
*/
pci_bus_read_config_byte(dev->bus, PCI_DEVFN(0x14, 3),
0x40, &imc); if (imc & 0x80)
notify_imc = true;
}
/* base address location etc changed in SB800 */
retval = piix4_setup_sb800(dev, id, 0); if (retval < 0) return retval;
/* * Try to register multiplexed main SMBus adapter, * give up if we can't
*/
retval = piix4_add_adapters_sb800(dev, retval, notify_imc); if (retval < 0) return retval;
} else {
retval = piix4_setup(dev, id); if (retval < 0) return retval;
/* Try to register main SMBus adapter, give up if we can't */
retval = piix4_add_adapter(dev, retval, false, 0, false, 0, "", &piix4_main_adapters[0]); if (retval < 0) return retval;
piix4_adapter_count = 1;
}
/* Check for auxiliary SMBus on some AMD chipsets */
retval = -ENODEV;
if (dev->vendor == PCI_VENDOR_ID_ATI &&
dev->device == PCI_DEVICE_ID_ATI_SBX00_SMBUS) { if (dev->revision < 0x40) {
retval = piix4_setup_aux(dev, id, 0x58);
} else { /* SB800 added aux bus too */
retval = piix4_setup_sb800(dev, id, 1);
}
}
status = acpi_get_handle(NULL, (acpi_string)SB800_ASF_ACPI_PATH, &handle); if (ACPI_SUCCESS(status))
is_asf = true;
if (dev->vendor == PCI_VENDOR_ID_AMD &&
(dev->device == PCI_DEVICE_ID_AMD_HUDSON2_SMBUS ||
dev->device == PCI_DEVICE_ID_AMD_KERNCZ_SMBUS)) { /* Do not setup AUX port if ASF is enabled */ if (!is_asf)
retval = piix4_setup_sb800(dev, id, 1);
}
if (retval > 0) { /* Try to add the aux adapter if it exists,
* piix4_add_adapter will clean up if this fails */
piix4_add_adapter(dev, retval, false, 0, false, 1,
is_sb800 ? piix4_aux_port_name_sb800 : "",
&piix4_aux_adapter);
}
Die Informationen auf dieser Webseite wurden
nach bestem Wissen sorgfältig zusammengestellt. Es wird jedoch weder Vollständigkeit, noch Richtigkeit,
noch Qualität der bereit gestellten Informationen zugesichert.
Bemerkung:
Die farbliche Syntaxdarstellung und die Messung sind noch experimentell.