Lines Matching +full:smbus +full:- +full:timeout +full:- +full:disable
1 // SPDX-License-Identifier: GPL-2.0-or-later
3 Copyright (c) 1998 - 2002 Frodo Looijaard <frodol@dds.nl> and
11 Serverworks OSB4, CSB5, CSB6, HT-1000, HT-1100
13 AMD Hudson-2, ML, CZ
18 SMBus interfaces.
38 /* PIIX4 SMBus address offsets */
74 /* Multi-port constants */
88 * Hudson-2/Bolton port is always selected by bits 2:1 of register 0x2f.
128 DMI_MATCH(DMI_BOARD_NAME, "PC-AM2RD790"),
142 on Intel-based systems */
180 if (mmio_cfg->use_mmio) { in piix4_sb800_region_request()
187 "SMBus base address memory region 0x%x already in use.\n", in piix4_sb800_region_request()
189 return -EBUSY; in piix4_sb800_region_request()
197 dev_err(dev, "SMBus base address mapping failed.\n"); in piix4_sb800_region_request()
198 return -ENOMEM; in piix4_sb800_region_request()
201 mmio_cfg->addr = addr; in piix4_sb800_region_request()
209 "SMBus base address index region 0x%x already in use.\n", in piix4_sb800_region_request()
211 return -EBUSY; in piix4_sb800_region_request()
220 if (mmio_cfg->use_mmio) { in piix4_sb800_region_release()
221 iounmap(mmio_cfg->addr); in piix4_sb800_region_release()
234 * w/ SMBus PCI revision ID 0x51 or greater. MMIO is supported on in piix4_sb800_use_mmio()
237 return (PIIX4_dev->vendor == PCI_VENDOR_ID_AMD && in piix4_sb800_use_mmio()
238 PIIX4_dev->device == PCI_DEVICE_ID_AMD_KERNCZ_SMBUS && in piix4_sb800_use_mmio()
239 PIIX4_dev->revision >= 0x51); in piix4_sb800_use_mmio()
248 if ((PIIX4_dev->vendor == PCI_VENDOR_ID_SERVERWORKS) && in piix4_setup()
249 (PIIX4_dev->device == PCI_DEVICE_ID_SERVERWORKS_CSB5)) in piix4_setup()
252 /* On some motherboards, it was reported that accessing the SMBus in piix4_setup()
255 dev_err(&PIIX4_dev->dev, in piix4_setup()
256 "Accessing the SMBus on this system is unsafe!\n"); in piix4_setup()
257 return -EPERM; in piix4_setup()
260 /* Don't access SMBus on IBM systems which get corrupted eeproms */ in piix4_setup()
262 PIIX4_dev->vendor == PCI_VENDOR_ID_INTEL) { in piix4_setup()
263 dev_err(&PIIX4_dev->dev, "IBM system detected; this module " in piix4_setup()
266 return -EPERM; in piix4_setup()
269 /* Determine the address of the SMBus areas */ in piix4_setup()
277 dev_err(&PIIX4_dev->dev, "SMBus base address " in piix4_setup()
278 "uninitialized - upgrade BIOS or use " in piix4_setup()
280 return -ENODEV; in piix4_setup()
285 return -ENODEV; in piix4_setup()
288 dev_err(&PIIX4_dev->dev, "SMBus region 0x%x already in use!\n", in piix4_setup()
290 return -EBUSY; in piix4_setup()
296 sure, we disable the PIIX4 first. */ in piix4_setup()
301 dev_info(&PIIX4_dev->dev, "WARNING: SMBus interface set to " in piix4_setup()
306 * noted that many Dell machines have the SMBus in piix4_setup()
315 dev_notice(&PIIX4_dev->dev, in piix4_setup()
316 "WARNING: SMBus interface has been FORCEFULLY ENABLED!\n"); in piix4_setup()
318 dev_err(&PIIX4_dev->dev, in piix4_setup()
319 "SMBus Host Controller not enabled!\n"); in piix4_setup()
321 return -ENODEV; in piix4_setup()
326 dev_dbg(&PIIX4_dev->dev, "Using IRQ for SMBus\n"); in piix4_setup()
328 dev_dbg(&PIIX4_dev->dev, "Using SMI# for SMBus\n"); in piix4_setup()
330 dev_err(&PIIX4_dev->dev, "Illegal Interrupt configuration " in piix4_setup()
334 dev_info(&PIIX4_dev->dev, in piix4_setup()
335 "SMBus Host Controller at 0x%x, revision %d\n", in piix4_setup()
353 retval = piix4_sb800_region_request(&PIIX4_dev->dev, &mmio_cfg); in piix4_setup_sb800_smba()
367 piix4_sb800_region_release(&PIIX4_dev->dev, &mmio_cfg); in piix4_setup_sb800_smba()
380 dev_err(&PIIX4_dev->dev, in piix4_setup_sb800_smba()
381 "SMBus Host Controller not enabled!\n"); in piix4_setup_sb800_smba()
382 return -ENODEV; in piix4_setup_sb800_smba()
397 /* SB800 and later SMBus does not support forcing address */ in piix4_setup_sb800()
399 dev_err(&PIIX4_dev->dev, "SMBus does not support " in piix4_setup_sb800()
401 return -EINVAL; in piix4_setup_sb800()
404 /* Determine the address of the SMBus areas */ in piix4_setup_sb800()
405 if ((PIIX4_dev->vendor == PCI_VENDOR_ID_AMD && in piix4_setup_sb800()
406 PIIX4_dev->device == PCI_DEVICE_ID_AMD_HUDSON2_SMBUS && in piix4_setup_sb800()
407 PIIX4_dev->revision >= 0x41) || in piix4_setup_sb800()
408 (PIIX4_dev->vendor == PCI_VENDOR_ID_AMD && in piix4_setup_sb800()
409 PIIX4_dev->device == PCI_DEVICE_ID_AMD_KERNCZ_SMBUS && in piix4_setup_sb800()
410 PIIX4_dev->revision >= 0x49) || in piix4_setup_sb800()
411 (PIIX4_dev->vendor == PCI_VENDOR_ID_HYGON && in piix4_setup_sb800()
412 PIIX4_dev->device == PCI_DEVICE_ID_AMD_KERNCZ_SMBUS)) in piix4_setup_sb800()
424 return -ENODEV; in piix4_setup_sb800()
427 dev_err(&PIIX4_dev->dev, "SMBus region 0x%x already in use!\n", in piix4_setup_sb800()
429 return -EBUSY; in piix4_setup_sb800()
432 /* Aux SMBus does not support IRQ information */ in piix4_setup_sb800()
434 dev_info(&PIIX4_dev->dev, in piix4_setup_sb800()
435 "Auxiliary SMBus Host Controller at 0x%x\n", in piix4_setup_sb800()
440 /* Request the SMBus I2C bus config region */ in piix4_setup_sb800()
442 dev_err(&PIIX4_dev->dev, "SMBus I2C bus config region " in piix4_setup_sb800()
445 return -EBUSY; in piix4_setup_sb800()
451 dev_dbg(&PIIX4_dev->dev, "Using IRQ for SMBus\n"); in piix4_setup_sb800()
453 dev_dbg(&PIIX4_dev->dev, "Using SMI# for SMBus\n"); in piix4_setup_sb800()
455 dev_info(&PIIX4_dev->dev, in piix4_setup_sb800()
456 "SMBus Host Controller at 0x%x, revision %d\n", in piix4_setup_sb800()
460 if (PIIX4_dev->vendor == PCI_VENDOR_ID_AMD || in piix4_setup_sb800()
461 PIIX4_dev->vendor == PCI_VENDOR_ID_HYGON) { in piix4_setup_sb800()
462 if (PIIX4_dev->device == PCI_DEVICE_ID_AMD_KERNCZ_SMBUS || in piix4_setup_sb800()
463 (PIIX4_dev->device == PCI_DEVICE_ID_AMD_HUDSON2_SMBUS && in piix4_setup_sb800()
464 PIIX4_dev->revision >= 0x1F)) { in piix4_setup_sb800()
475 retval = piix4_sb800_region_request(&PIIX4_dev->dev, &mmio_cfg); in piix4_setup_sb800()
488 piix4_sb800_region_release(&PIIX4_dev->dev, &mmio_cfg); in piix4_setup_sb800()
491 dev_info(&PIIX4_dev->dev, in piix4_setup_sb800()
492 "Using register 0x%02x for SMBus port selection\n", in piix4_setup_sb800()
502 /* Set up auxiliary SMBus controllers found on some in piix4_setup_aux()
507 /* Read address of auxiliary SMBus controller */ in piix4_setup_aux()
510 dev_dbg(&PIIX4_dev->dev, in piix4_setup_aux()
511 "Auxiliary SMBus controller not enabled\n"); in piix4_setup_aux()
512 return -ENODEV; in piix4_setup_aux()
517 dev_dbg(&PIIX4_dev->dev, in piix4_setup_aux()
518 "Auxiliary SMBus base address uninitialized\n"); in piix4_setup_aux()
519 return -ENODEV; in piix4_setup_aux()
523 return -ENODEV; in piix4_setup_aux()
526 dev_err(&PIIX4_dev->dev, "Auxiliary SMBus region 0x%x " in piix4_setup_aux()
528 return -EBUSY; in piix4_setup_aux()
531 dev_info(&PIIX4_dev->dev, in piix4_setup_aux()
532 "Auxiliary SMBus Host Controller at 0x%x\n", in piix4_setup_aux()
541 unsigned short piix4_smba = adapdata->smba; in piix4_transaction()
544 int timeout = 0; in piix4_transaction() local
546 dev_dbg(&piix4_adapter->dev, "Transaction (pre): CNT=%02x, CMD=%02x, " in piix4_transaction()
551 /* Make sure the SMBus host is ready to start transmitting */ in piix4_transaction()
553 dev_dbg(&piix4_adapter->dev, "SMBus busy (%02x). " in piix4_transaction()
557 dev_err(&piix4_adapter->dev, "Failed! (%02x)\n", temp); in piix4_transaction()
558 return -EBUSY; in piix4_transaction()
560 dev_dbg(&piix4_adapter->dev, "Successful!\n"); in piix4_transaction()
573 while ((++timeout < MAX_TIMEOUT) && in piix4_transaction()
577 /* If the SMBus is still busy, we give up */ in piix4_transaction()
578 if (timeout == MAX_TIMEOUT) { in piix4_transaction()
579 dev_err(&piix4_adapter->dev, "SMBus Timeout!\n"); in piix4_transaction()
580 result = -ETIMEDOUT; in piix4_transaction()
584 result = -EIO; in piix4_transaction()
585 dev_err(&piix4_adapter->dev, "Error: Failed bus transaction\n"); in piix4_transaction()
589 result = -EIO; in piix4_transaction()
590 dev_dbg(&piix4_adapter->dev, "Bus collision! SMBus may be " in piix4_transaction()
592 /* Clock stops and slave is stuck in mid-transmission */ in piix4_transaction()
596 result = -ENXIO; in piix4_transaction()
597 dev_dbg(&piix4_adapter->dev, "Error: no response!\n"); in piix4_transaction()
604 dev_err(&piix4_adapter->dev, "Failed reset at end of " in piix4_transaction()
607 dev_dbg(&piix4_adapter->dev, "Transaction (post): CNT=%02x, CMD=%02x, " in piix4_transaction()
620 unsigned short piix4_smba = adapdata->smba; in piix4_access()
642 outb_p(data->byte, SMBHSTDAT0); in piix4_access()
650 outb_p(data->word & 0xff, SMBHSTDAT0); in piix4_access()
651 outb_p((data->word & 0xff00) >> 8, SMBHSTDAT1); in piix4_access()
660 len = data->block[0]; in piix4_access()
662 return -EINVAL; in piix4_access()
666 outb_p(data->block[i], SMBBLKDAT); in piix4_access()
671 dev_warn(&adap->dev, "Unsupported transaction %d\n", size); in piix4_access()
672 return -EOPNOTSUPP; in piix4_access()
688 data->byte = inb_p(SMBHSTDAT0); in piix4_access()
691 data->word = inb_p(SMBHSTDAT0) + (inb_p(SMBHSTDAT1) << 8); in piix4_access()
694 data->block[0] = inb_p(SMBHSTDAT0); in piix4_access()
695 if (data->block[0] == 0 || data->block[0] > I2C_SMBUS_BLOCK_MAX) in piix4_access()
696 return -EPROTO; in piix4_access()
698 for (i = 1; i <= data->block[0]; i++) in piix4_access()
699 data->block[i] = inb_p(SMBBLKDAT); in piix4_access()
719 int timeout = MAX_TIMEOUT; in piix4_imc_sleep() local
722 return -EBUSY; in piix4_imc_sleep()
731 while (timeout--) { in piix4_imc_sleep()
740 return -ETIMEDOUT; in piix4_imc_sleep()
745 int timeout = MAX_TIMEOUT; in piix4_imc_wakeup() local
757 while (timeout--) { in piix4_imc_wakeup()
770 if (mmio_cfg->use_mmio) { in piix4_sb800_port_sel()
771 smba_en_lo = ioread8(mmio_cfg->addr + piix4_port_sel_sb800); in piix4_sb800_port_sel()
774 iowrite8(val, mmio_cfg->addr + piix4_port_sel_sb800); in piix4_sb800_port_sel()
790 * Handles access to multiple SMBus ports on the SB800.
802 unsigned short piix4_smba = adapdata->smba; in piix4_access_sb800()
808 retval = piix4_sb800_region_request(&adap->dev, &adapdata->mmio_cfg); in piix4_access_sb800()
812 /* Request the SMBUS semaphore, avoid conflicts with the IMC */ in piix4_access_sb800()
823 } while (--retries); in piix4_access_sb800()
824 /* SMBus is still owned by the IMC, we give up */ in piix4_access_sb800()
826 retval = -EBUSY; in piix4_access_sb800()
834 * All this is done through SMBus and can/will collide in piix4_access_sb800()
839 if ((size == I2C_SMBUS_BLOCK_DATA) && adapdata->notify_imc) { in piix4_access_sb800()
844 case -EBUSY: in piix4_access_sb800()
845 dev_warn(&adap->dev, in piix4_access_sb800()
849 case -ETIMEDOUT: in piix4_access_sb800()
850 dev_warn(&adap->dev, in piix4_access_sb800()
859 dev_warn(&adap->dev, in piix4_access_sb800()
861 adapdata->notify_imc = false; in piix4_access_sb800()
865 prev_port = piix4_sb800_port_sel(adapdata->port, &adapdata->mmio_cfg); in piix4_access_sb800()
870 piix4_sb800_port_sel(prev_port, &adapdata->mmio_cfg); in piix4_access_sb800()
875 if ((size == I2C_SMBUS_BLOCK_DATA) && adapdata->notify_imc) in piix4_access_sb800()
879 piix4_sb800_region_release(&adap->dev, &adapdata->mmio_cfg); in piix4_access_sb800()
942 return -ENOMEM; in piix4_add_adapter()
945 adap->owner = THIS_MODULE; in piix4_add_adapter()
946 adap->class = I2C_CLASS_HWMON | I2C_CLASS_SPD; in piix4_add_adapter()
947 adap->algo = sb800_main ? &piix4_smbus_algorithm_sb800 in piix4_add_adapter()
954 return -ENOMEM; in piix4_add_adapter()
957 adapdata->mmio_cfg.use_mmio = piix4_sb800_use_mmio(dev); in piix4_add_adapter()
958 adapdata->smba = smba; in piix4_add_adapter()
959 adapdata->sb800_main = sb800_main; in piix4_add_adapter()
960 adapdata->port = port << piix4_port_shift_sb800; in piix4_add_adapter()
961 adapdata->notify_imc = notify_imc; in piix4_add_adapter()
964 adap->dev.parent = &dev->dev; in piix4_add_adapter()
966 if (has_acpi_companion(&dev->dev)) { in piix4_add_adapter()
967 acpi_preset_companion(&adap->dev, in piix4_add_adapter()
968 ACPI_COMPANION(&dev->dev), in piix4_add_adapter()
972 snprintf(adap->name, sizeof(adap->name), in piix4_add_adapter()
973 "SMBus PIIX4 adapter%s at %04x", name, smba); in piix4_add_adapter()
996 if (dev->device == PCI_DEVICE_ID_AMD_KERNCZ_SMBUS || in piix4_add_adapters_sb800()
997 (dev->device == PCI_DEVICE_ID_AMD_HUDSON2_SMBUS && in piix4_add_adapters_sb800()
998 dev->revision >= 0x1F)) { in piix4_add_adapters_sb800()
1018 dev_err(&dev->dev, in piix4_add_adapters_sb800()
1020 while (--port >= 0) { in piix4_add_adapters_sb800()
1022 if (adapdata->smba) { in piix4_add_adapters_sb800()
1038 if ((dev->vendor == PCI_VENDOR_ID_ATI && in piix4_probe()
1039 dev->device == PCI_DEVICE_ID_ATI_SBX00_SMBUS && in piix4_probe()
1040 dev->revision >= 0x40) || in piix4_probe()
1041 dev->vendor == PCI_VENDOR_ID_AMD || in piix4_probe()
1042 dev->vendor == PCI_VENDOR_ID_HYGON) { in piix4_probe()
1046 if ((dev->vendor == PCI_VENDOR_ID_AMD || in piix4_probe()
1047 dev->vendor == PCI_VENDOR_ID_HYGON) && in piix4_probe()
1048 dev->device == PCI_DEVICE_ID_AMD_KERNCZ_SMBUS) { in piix4_probe()
1055 pci_bus_read_config_byte(dev->bus, PCI_DEVFN(0x14, 3), in piix4_probe()
1067 * Try to register multiplexed main SMBus adapter, in piix4_probe()
1078 /* Try to register main SMBus adapter, give up if we can't */ in piix4_probe()
1086 /* Check for auxiliary SMBus on some AMD chipsets */ in piix4_probe()
1087 retval = -ENODEV; in piix4_probe()
1089 if (dev->vendor == PCI_VENDOR_ID_ATI && in piix4_probe()
1090 dev->device == PCI_DEVICE_ID_ATI_SBX00_SMBUS) { in piix4_probe()
1091 if (dev->revision < 0x40) { in piix4_probe()
1099 if (dev->vendor == PCI_VENDOR_ID_AMD && in piix4_probe()
1100 (dev->device == PCI_DEVICE_ID_AMD_HUDSON2_SMBUS || in piix4_probe()
1101 dev->device == PCI_DEVICE_ID_AMD_KERNCZ_SMBUS)) { in piix4_probe()
1120 if (adapdata->smba) { in piix4_adap_remove()
1122 if (adapdata->port == (0 << piix4_port_shift_sb800)) in piix4_adap_remove()
1123 release_region(adapdata->smba, SMBIOSIZE); in piix4_adap_remove()
1133 while (--port >= 0) { in piix4_remove()
1157 MODULE_DESCRIPTION("PIIX4 SMBus driver");