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>,
6 Copyright (C) 2007 - 2014 Jean Delvare <jdelvare@suse.de>
16 * region SMBus Block proc. block
18 * ---------------------------------------------------------------------------
43 * Lynx Point-LP (PCH) 0x9c22 32 hard yes yes yes
51 * Wildcat Point-LP (PCH) 0x9ca2 32 hard yes yes yes
54 * Sunrise Point-H (PCH) 0xa123 32 hard yes yes yes
55 * Sunrise Point-LP (PCH) 0x9d23 32 hard yes yes yes
61 * Kaby Lake PCH-H (PCH) 0xa2a3 32 hard yes yes yes
63 * Cannon Lake-H (PCH) 0xa323 32 hard yes yes yes
64 * Cannon Lake-LP (PCH) 0x9da3 32 hard yes yes yes
66 * Ice Lake-LP (PCH) 0x34a3 32 hard yes yes yes
67 * Ice Lake-N (PCH) 0x38a3 32 hard yes yes yes
69 * Comet Lake-H (PCH) 0x06a3 32 hard yes yes yes
71 * Tiger Lake-LP (PCH) 0xa0a3 32 hard yes yes yes
72 * Tiger Lake-H (PCH) 0x43a3 32 hard yes yes yes
74 * Comet Lake-V (PCH) 0xa3a3 32 hard yes yes yes
75 * Alder Lake-S (PCH) 0x7aa3 32 hard yes yes yes
76 * Alder Lake-P (PCH) 0x51a3 32 hard yes yes yes
77 * Alder Lake-M (PCH) 0x54a3 32 hard yes yes yes
78 * Raptor Lake-S (PCH) 0x7a23 32 hard yes yes yes
79 * Meteor Lake-P (SOC) 0x7e22 32 hard yes yes yes
80 * Meteor Lake SoC-S (SOC) 0xae22 32 hard yes yes yes
81 * Meteor Lake PCH-S (PCH) 0x7f23 32 hard yes yes yes
83 * Arrow Lake-H (SOC) 0x7722 32 hard yes yes yes
84 * Panther Lake-H (SOC) 0xe322 32 hard yes yes yes
85 * Panther Lake-P (SOC) 0xe422 32 hard yes yes yes
94 * SMBus Host Notify yes
97 * See the file Documentation/i2c/busses/i2c-i801.rst for details.
111 #include <linux/i2c-mux.h>
112 #include <linux/i2c-smbus.h>
128 #include <linux/platform_data/i2c-mux-gpio.h>
131 /* I801 SMBus address offsets */
132 #define SMBHSTSTS(p) (0 + (p)->smba)
133 #define SMBHSTCNT(p) (2 + (p)->smba)
134 #define SMBHSTCMD(p) (3 + (p)->smba)
135 #define SMBHSTADD(p) (4 + (p)->smba)
136 #define SMBHSTDAT0(p) (5 + (p)->smba)
137 #define SMBHSTDAT1(p) (6 + (p)->smba)
138 #define SMBBLKDAT(p) (7 + (p)->smba)
139 #define SMBPEC(p) (8 + (p)->smba) /* ICH3 and later */
140 #define SMBAUXSTS(p) (12 + (p)->smba) /* ICH4 and later */
141 #define SMBAUXCTL(p) (13 + (p)->smba) /* ICH4 and later */
142 #define SMBSLVSTS(p) (16 + (p)->smba) /* ICH3 and later */
143 #define SMBSLVCMD(p) (17 + (p)->smba) /* ICH3 and later */
144 #define SMBNTFDADD(p) (20 + (p)->smba) /* ICH3 and later */
223 /* Patsburg also has three 'Integrated Device Function' SMBus controllers */
273 unsigned gpios[2]; /* Relative to gpio_chip->base */
290 /* Command state used by isr for byte-by-byte block transactions */
323 "SMBus PEC",
328 "SMBus Host Notify",
333 MODULE_PARM_DESC(disable_features, "Disable selected driver features:\n"
334 "\t\t 0x01 disable SMBus PEC\n"
335 "\t\t 0x02 disable the block buffer\n"
336 "\t\t 0x08 disable the I2C block read functionality\n"
338 "\t\t 0x20 disable SMBus Host Notify ");
345 pci_err(priv->pci_dev, "Illegal SMBus block read size %u\n", len);
346 return -EPROTO;
356 if (!(priv->features & FEATURE_SMBUS_PEC))
362 return -EBADMSG;
368 /* Make sure the SMBus host is ready to start transmitting.
369 Return 0 if it is, -EBUSY if it is not. */
376 pci_err(priv->pci_dev, "SMBus is busy, can't use it!\n");
377 return -EBUSY;
382 pci_dbg(priv->pci_dev, "Clearing status flags (%02x)\n", status);
395 pci_dbg(priv->pci_dev, "Clearing aux status flag CRCE\n");
405 * If the SMBus is still busy, we give up
417 dev_dbg(&priv->pci_dev->dev,
419 return -ETIMEDOUT;
423 result = -EIO;
424 dev_err(&priv->pci_dev->dev, "Transaction failed\n");
444 pci_dbg(priv->pci_dev, "PEC error\n");
446 result = -ENXIO;
447 pci_dbg(priv->pci_dev, "No response\n");
451 result = -EAGAIN;
452 dev_dbg(&priv->pci_dev->dev, "Lost arbitration\n");
461 unsigned long timeout = jiffies + priv->adapter.timeout;
471 } while (time_is_after_eq_jiffies(timeout));
473 return -ETIMEDOUT;
479 unsigned long timeout = jiffies + priv->adapter.timeout;
487 } while (time_is_after_eq_jiffies(timeout));
489 return -ETIMEDOUT;
495 const struct i2c_adapter *adap = &priv->adapter;
497 if (priv->features & FEATURE_IRQ) {
498 reinit_completion(&priv->done);
501 result = wait_for_completion_timeout(&priv->done, adap->timeout);
502 return result ? priv->status : -ETIMEDOUT;
524 return -EOPNOTSUPP;
531 len = data->block[0];
535 outb_p(data->block[i+1], SMBBLKDAT(priv));
550 data->block[0] = len;
553 data->block[i + 1] = inb_p(SMBBLKDAT(priv));
562 if (priv->is_read) {
568 if (priv->len == SMBUS_LEN_SENTINEL) {
569 priv->len = i801_get_block_len(priv);
570 if (priv->len < 0)
572 priv->len = I2C_SMBUS_BLOCK_MAX;
574 priv->data[-1] = priv->len;
578 if (priv->count < priv->len)
579 priv->data[priv->count++] = inb(SMBBLKDAT(priv));
581 dev_dbg(&priv->pci_dev->dev,
585 if (priv->count == priv->len - 1)
586 outb_p(priv->cmd | SMBHSTCNT_LAST_BYTE,
588 } else if (priv->count < priv->len - 1) {
590 outb_p(priv->data[++priv->count], SMBBLKDAT(priv));
601 * With the tested platforms, reading SMBNTFDDAT (22 + (p)->smba)
605 i2c_handle_smbus_host_notify(&priv->adapter, addr);
616 * INTR - Success
617 * DEV_ERR - Invalid command, NAK or communication timeout
618 * BUS_ERR - SMI# transaction collision
619 * FAILED - transaction was canceled due to a KILL request
620 * When any of these occur, update ->status and signal completion.
622 * 2) For byte-by-byte (I2C read/write) transactions, one BYTE_DONE interrupt
623 * occurs for each byte of a byte-by-byte to prepare the next byte.
634 pci_read_config_word(priv->pci_dev, PCI_STATUS, &pcists);
638 if (priv->features & FEATURE_HOST_NOTIFY) {
658 priv->status = status & STATUS_ERROR_FLAGS;
659 complete(&priv->done);
666 * For "byte-by-byte" block transactions:
678 const struct i2c_adapter *adap = &priv->adapter;
681 return -EOPNOTSUPP;
683 len = data->block[0];
687 outb_p(data->block[1], SMBBLKDAT(priv));
696 if (priv->features & FEATURE_IRQ) {
697 priv->is_read = (read_write == I2C_SMBUS_READ);
698 if (len == 1 && priv->is_read)
700 priv->cmd = smbcmd | SMBHSTCNT_INTREN;
701 priv->len = len;
702 priv->count = 0;
703 priv->data = &data->block[1];
705 reinit_completion(&priv->done);
706 outb_p(priv->cmd | SMBHSTCNT_START, SMBHSTCNT(priv));
707 result = wait_for_completion_timeout(&priv->done, adap->timeout);
708 return result ? priv->status : -ETIMEDOUT;
734 return -EPROTO;
736 data->block[0] = len;
740 data->block[i] = inb_p(SMBBLKDAT(priv));
741 if (i == len - 1)
746 outb_p(data->block[i+1], SMBBLKDAT(priv));
780 outb_p(data->byte, SMBHSTDAT0(priv));
787 outb_p(data->word & 0xff, SMBHSTDAT0(priv));
788 outb_p((data->word & 0xff00) >> 8, SMBHSTDAT1(priv));
795 outb_p(data->word & 0xff, SMBHSTDAT0(priv));
796 outb_p((data->word & 0xff00) >> 8, SMBHSTDAT1(priv));
802 pci_err(priv->pci_dev, "Unsupported transaction %d\n", command);
803 return -EOPNOTSUPP;
813 data->byte = inb_p(SMBHSTDAT0(priv));
817 data->word = inb_p(SMBHSTDAT0(priv)) +
830 data->block[0] = SMBUS_LEN_SENTINEL;
831 else if (data->block[0] < 1 || data->block[0] > I2C_SMBUS_BLOCK_MAX)
832 return -EPROTO;
841 if (priv->features & FEATURE_BLOCK_BUFFER)
853 if (data->block[0] < 1 || data->block[0] > I2C_SMBUS_BLOCK_MAX)
854 return -EPROTO;
857 * even when reading. However if SPD Write Disable is set (Lynx Point and later),
861 priv->original_hstcfg & SMBHSTCFG_SPD_WD ? read_write : I2C_SMBUS_WRITE);
871 pci_read_config_byte(priv->pci_dev, SMBHSTCFG, &hostc);
872 pci_write_config_byte(priv->pci_dev, SMBHSTCFG, hostc | SMBHSTCFG_I2C_EN);
873 } else if (!(priv->features & FEATURE_I2C_BLOCK_READ)) {
874 pci_err(priv->pci_dev, "I2C block read is unsupported!\n");
875 return -EOPNOTSUPP;
883 pci_write_config_byte(priv->pci_dev, SMBHSTCFG, hostc);
896 if (priv->acpi_reserved)
897 return -EBUSY;
899 pm_runtime_get_sync(&priv->pci_dev->dev);
905 hwpec = (priv->features & FEATURE_SMBUS_PEC) && (flags & I2C_CLIENT_PEC)
909 if (hwpec) /* enable/disable hardware PEC */
925 * time, so we forcibly disable it after every transaction.
931 * Unlock the SMBus device for use by BIOS/ACPI,
936 pm_runtime_mark_last_busy(&priv->pci_dev->dev);
937 pm_runtime_put_autosuspend(&priv->pci_dev->dev);
950 ((priv->features & FEATURE_SMBUS_PEC) ? I2C_FUNC_SMBUS_PEC : 0) |
951 ((priv->features & FEATURE_BLOCK_PROC) ?
953 ((priv->features & FEATURE_I2C_BLOCK_READ) ?
955 ((priv->features & FEATURE_HOST_NOTIFY) ?
963 if (!(priv->features & FEATURE_HOST_NOTIFY))
969 * SMBus Alert.
972 priv->original_slvcmd, SMBSLVCMD(priv));
980 if (!(priv->features & FEATURE_HOST_NOTIFY))
983 outb_p(priv->original_slvcmd, SMBSLVCMD(priv));
1080 sizeof(signature)-1))
1141 if (dm->type != DMI_ENTRY_ONBOARD_DEVICE)
1144 count = (dm->length - sizeof(struct dmi_header)) / 2;
1147 const char *name = ((char *) dm) + dm->length;
1153 s--;
1156 s--;
1168 /* Only register targets on main SMBus channel */
1169 if (priv->features & FEATURE_IDF)
1178 i2c_new_client_device(&priv->adapter, &info);
1182 dmi_walk(dmi_check_onboard_devices, &priv->adapter);
1184 /* Instantiate SPD EEPROMs unless the SMBus is multiplexed */
1186 if (!priv->mux_pdev)
1188 i2c_register_spd(&priv->adapter);
1216 DMI_MATCH(DMI_BOARD_NAME, "Z8NA-D6(C)"),
1223 DMI_MATCH(DMI_BOARD_NAME, "Z8P(N)E-D12(X)"),
1230 DMI_MATCH(DMI_BOARD_NAME, "Z8NH-D12"),
1237 DMI_MATCH(DMI_BOARD_NAME, "Z8PH-D12/IFB"),
1244 DMI_MATCH(DMI_BOARD_NAME, "Z8NR-D12"),
1251 DMI_MATCH(DMI_BOARD_NAME, "Z8P(N)H-D12"),
1258 DMI_MATCH(DMI_BOARD_NAME, "Z8PG-D18"),
1265 DMI_MATCH(DMI_BOARD_NAME, "Z8PE-D18"),
1272 DMI_MATCH(DMI_BOARD_NAME, "Z8PS-D12"),
1286 dev->type != &i2c_adapter_type ||
1287 i2c_root_adapter(dev) != &priv->adapter)
1299 struct device *dev = &priv->adapter.dev;
1310 mux_config = id->driver_data;
1314 gpio_data.parent = priv->adapter.nr;
1315 gpio_data.values = mux_config->values;
1316 gpio_data.n_values = mux_config->n_values;
1321 struct_size(lookup, table, mux_config->n_gpios + 1),
1325 lookup->dev_id = "i2c-mux-gpio";
1326 for (i = 0; i < mux_config->n_gpios; i++)
1327 lookup->table[i] = GPIO_LOOKUP(mux_config->gpio_chip,
1328 mux_config->gpios[i], "mux", 0);
1331 priv->mux_notifier_block.notifier_call = i801_notifier_call;
1332 if (bus_register_notifier(&i2c_bus_type, &priv->mux_notifier_block))
1341 priv->mux_pdev = platform_device_register_data(dev, "i2c-mux-gpio",
1344 if (IS_ERR(priv->mux_pdev)) {
1347 dev_err(dev, "Failed to register i2c-mux-gpio device\n");
1349 priv->lookup = lookup;
1355 bus_unregister_notifier(&i2c_bus_type, &priv->mux_notifier_block);
1356 platform_device_unregister(priv->mux_pdev);
1357 gpiod_remove_lookup_table(priv->lookup);
1380 ret = p2sb_bar(pci_dev->bus, 0, res);
1384 if (pci_dev->device == PCI_DEVICE_ID_INTEL_DNV_SMBUS)
1385 res->start += SBREG_SMBCTRL_DNV;
1387 res->start += SBREG_SMBCTRL;
1389 res->end = res->start + 3;
1391 return platform_device_register_resndata(&pci_dev->dev, "iTCO_wdt", -1,
1403 return platform_device_register_resndata(&pci_dev->dev, "iTCO_wdt", -1,
1409 struct pci_dev *pci_dev = priv->pci_dev;
1417 if (!(priv->features & (FEATURE_TCO_SPT | FEATURE_TCO_CNL)))
1431 res->start = tco_base & ~1;
1432 res->end = res->start + 32 - 1;
1433 res->flags = IORESOURCE_IO;
1435 if (priv->features & FEATURE_TCO_CNL)
1436 priv->tco_pdev = i801_add_tco_cnl(pci_dev, tco_res);
1438 priv->tco_pdev = i801_add_tco_spt(pci_dev, tco_res);
1440 if (IS_ERR(priv->tco_pdev))
1441 dev_warn(&pci_dev->dev, "failed to create iTCO device\n");
1448 return address >= priv->smba &&
1449 address <= pci_resource_end(priv->pci_dev, SMBBAR);
1457 struct pci_dev *pdev = priv->pci_dev;
1465 i2c_lock_bus(&priv->adapter, I2C_LOCK_SEGMENT);
1467 if (!priv->acpi_reserved && i801_acpi_is_smbus_ioport(priv, address)) {
1468 priv->acpi_reserved = true;
1470 dev_warn(&pdev->dev, "BIOS is accessing SMBus registers\n");
1471 dev_warn(&pdev->dev, "Driver SMBus register access inhibited\n");
1477 pm_runtime_get_sync(&pdev->dev);
1485 i2c_unlock_bus(&priv->adapter, I2C_LOCK_SEGMENT);
1492 acpi_handle ah = ACPI_HANDLE(&priv->pci_dev->dev);
1500 return acpi_check_resource_conflict(&priv->pci_dev->resource[SMBBAR]);
1505 acpi_handle ah = ACPI_HANDLE(&priv->pci_dev->dev);
1516 unsigned char hstcfg = priv->original_hstcfg;
1518 hstcfg &= ~SMBHSTCFG_I2C_EN; /* SMBus timing */
1520 pci_write_config_byte(priv->pci_dev, SMBHSTCFG, hstcfg);
1525 outb_p(priv->original_hstcnt, SMBHSTCNT(priv));
1526 pci_write_config_byte(priv->pci_dev, SMBHSTCFG, priv->original_hstcfg);
1534 priv = devm_kzalloc(&dev->dev, sizeof(*priv), GFP_KERNEL);
1536 return -ENOMEM;
1538 i2c_set_adapdata(&priv->adapter, priv);
1539 priv->adapter.owner = THIS_MODULE;
1540 priv->adapter.class = I2C_CLASS_HWMON;
1541 priv->adapter.algo = &smbus_algorithm;
1542 priv->adapter.dev.parent = &dev->dev;
1543 acpi_use_parent_companion(&priv->adapter.dev);
1544 priv->adapter.retries = 3;
1546 priv->pci_dev = dev;
1547 priv->features = id->driver_data;
1549 /* Disable features on user request */
1551 if (priv->features & disable_features & (1 << i))
1552 dev_notice(&dev->dev, "%s disabled by user\n",
1555 priv->features &= ~disable_features;
1558 if (!(priv->features & FEATURE_BLOCK_BUFFER))
1559 priv->features &= ~FEATURE_BLOCK_PROC;
1567 dev_err(&dev->dev, "Failed to enable SMBus PCI device (%d)\n",
1572 /* Determine the address of the SMBus area */
1573 priv->smba = pci_resource_start(dev, SMBBAR);
1574 if (!priv->smba) {
1575 dev_err(&dev->dev,
1576 "SMBus base address uninitialized, upgrade BIOS\n");
1577 return -ENODEV;
1581 return -ENODEV;
1585 dev_err(&dev->dev,
1586 "Failed to request SMBus region 0x%lx-0x%Lx\n",
1587 priv->smba,
1593 pci_read_config_byte(priv->pci_dev, SMBHSTCFG, &priv->original_hstcfg);
1595 if (!(priv->original_hstcfg & SMBHSTCFG_HST_EN))
1596 dev_info(&dev->dev, "Enabling SMBus device\n");
1598 if (priv->original_hstcfg & SMBHSTCFG_SMB_SMI_EN) {
1599 dev_dbg(&dev->dev, "SMBus using interrupt SMI#\n");
1600 /* Disable SMBus interrupt feature if SMBus using SMI# */
1601 priv->features &= ~FEATURE_IRQ;
1603 if (priv->original_hstcfg & SMBHSTCFG_SPD_WD)
1604 dev_info(&dev->dev, "SPD Write Disable is set\n");
1607 if (priv->features & (FEATURE_SMBUS_PEC | FEATURE_BLOCK_BUFFER))
1611 /* Default timeout in interrupt mode: 200 ms */
1612 priv->adapter.timeout = HZ / 5;
1614 if (dev->irq == IRQ_NOTCONNECTED)
1615 priv->features &= ~FEATURE_IRQ;
1617 if (priv->features & FEATURE_IRQ) {
1621 pci_read_config_word(priv->pci_dev, PCI_STATUS, &pcists);
1623 dev_warn(&dev->dev, "An interrupt is pending!\n");
1626 if (priv->features & FEATURE_IRQ) {
1627 init_completion(&priv->done);
1629 err = devm_request_irq(&dev->dev, dev->irq, i801_isr,
1632 dev_err(&dev->dev, "Failed to allocate irq %d: %d\n",
1633 dev->irq, err);
1634 priv->features &= ~FEATURE_IRQ;
1637 dev_info(&dev->dev, "SMBus using %s\n",
1638 priv->features & FEATURE_IRQ ? "PCI interrupt" : "polling");
1641 if (!(priv->features & FEATURE_IRQ))
1642 priv->features &= ~FEATURE_HOST_NOTIFY;
1645 priv->original_hstcnt = inb_p(SMBHSTCNT(priv)) & ~SMBHSTCNT_KILL;
1646 if (priv->features & FEATURE_HOST_NOTIFY)
1647 priv->original_slvcmd = inb_p(SMBSLVCMD(priv));
1655 snprintf(priv->adapter.name, sizeof(priv->adapter.name),
1656 "SMBus %s adapter at %04lx",
1657 (priv->features & FEATURE_IDF) ? "I801 IDF" : "I801",
1658 priv->smba);
1660 err = i2c_add_adapter(&priv->adapter);
1662 platform_device_unregister(priv->tco_pdev);
1668 i801_enable_host_notify(&priv->adapter);
1670 /* We ignore errors - multiplexing is optional */
1676 dev_pm_set_driver_flags(&dev->dev, DPM_FLAG_NO_DIRECT_COMPLETE);
1677 pm_runtime_set_autosuspend_delay(&dev->dev, 1000);
1678 pm_runtime_use_autosuspend(&dev->dev);
1679 pm_runtime_put_autosuspend(&dev->dev);
1680 pm_runtime_allow(&dev->dev);
1691 i2c_del_adapter(&priv->adapter);
1694 platform_device_unregister(priv->tco_pdev);
1697 if (!priv->acpi_reserved)
1698 pm_runtime_get_noresume(&dev->dev);
1704 * some systems during power-off (eg. Fujitsu-Siemens Lifebook E8010)
1721 i2c_mark_adapter_suspended(&priv->adapter);
1732 i801_enable_host_notify(&priv->adapter);
1733 i2c_mark_adapter_resumed(&priv->adapter);
1761 MODULE_DESCRIPTION("I801 SMBus driver");