Lines Matching +full:i2c +full:- +full:transfer +full:- +full:timeout +full:- +full:us

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>
15 * I/O Block I2C
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
92 * I2C block read transaction yes (doesn't use the block buffer)
97 * See the file Documentation/i2c/busses/i2c-i801.rst for details.
110 #include <linux/i2c.h>
111 #include <linux/i2c-mux.h>
112 #include <linux/i2c-smbus.h>
128 #include <linux/platform_data/i2c-mux-gpio.h>
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 */
274 unsigned gpios[2]; /* Relative to gpio_chip->base */
291 /* Command state used by isr for byte-by-byte block transactions */
327 "I2C block read",
337 "\t\t 0x08 disable the I2C block read functionality\n"
344 unsigned long timeout = jiffies + priv->adapter.timeout;
354 } while (time_is_after_eq_jiffies(timeout));
356 return -ETIMEDOUT;
362 unsigned long timeout = jiffies + priv->adapter.timeout;
370 } while (time_is_after_eq_jiffies(timeout));
372 return -ETIMEDOUT;
380 pci_err(priv->pci_dev, "Illegal SMBus block read size %u\n", len);
381 return -EPROTO;
391 if (!(priv->features & FEATURE_SMBUS_PEC))
397 return -EBADMSG;
404 Return 0 if it is, -EBUSY if it is not. */
411 pci_err(priv->pci_dev, "SMBus is busy, can't use it!\n");
412 return -EBUSY;
417 pci_dbg(priv->pci_dev, "Clearing status flags (%02x)\n", status);
430 pci_dbg(priv->pci_dev, "Clearing aux status flag CRCE\n");
450 pci_dbg(priv->pci_dev, "Failed terminating the transaction\n");
451 return -ETIMEDOUT;
455 result = -EIO;
456 pci_err(priv->pci_dev, "Transaction failed\n");
468 * for us to handle here.
476 pci_dbg(priv->pci_dev, "PEC error\n");
478 result = -ENXIO;
479 pci_dbg(priv->pci_dev, "No response\n");
483 result = -EAGAIN;
484 pci_dbg(priv->pci_dev, "Lost arbitration\n");
493 const struct i2c_adapter *adap = &priv->adapter;
495 if (priv->features & FEATURE_IRQ) {
496 reinit_completion(&priv->done);
499 result = wait_for_completion_timeout(&priv->done, adap->timeout);
500 return result ? priv->status : -ETIMEDOUT;
522 return -EOPNOTSUPP;
529 len = data->block[0];
532 iowrite8_rep(SMBBLKDAT(priv), data->block + 1, len);
547 data->block[0] = len;
549 ioread8_rep(SMBBLKDAT(priv), data->block + 1, len);
558 if (priv->is_read) {
560 * At transfer start i801_smbus_block_transaction() marks
564 if (priv->len == SMBUS_LEN_SENTINEL) {
565 priv->len = i801_get_block_len(priv);
566 if (priv->len < 0)
568 priv->len = I2C_SMBUS_BLOCK_MAX;
570 priv->data[-1] = priv->len;
574 if (priv->count < priv->len)
575 priv->data[priv->count++] = ioread8(SMBBLKDAT(priv));
577 pci_dbg(priv->pci_dev, "Discarding extra byte on block read\n");
580 if (priv->count == priv->len - 1)
581 iowrite8(priv->cmd | SMBHSTCNT_LAST_BYTE,
583 } else if (priv->count < priv->len - 1) {
585 iowrite8(priv->data[++priv->count], SMBBLKDAT(priv));
596 * With the tested platforms, reading SMBNTFDDAT (22 + (p)->smba)
600 i2c_handle_smbus_host_notify(&priv->adapter, addr);
611 * INTR - Success
612 * DEV_ERR - Invalid command, NAK or communication timeout
613 * BUS_ERR - SMI# transaction collision
614 * FAILED - transaction was canceled due to a KILL request
615 * When any of these occur, update ->status and signal completion.
617 * 2) For byte-by-byte (I2C read/write) transactions, one BYTE_DONE interrupt
618 * occurs for each byte of a byte-by-byte to prepare the next byte.
629 pci_read_config_word(priv->pci_dev, PCI_STATUS, &pcists);
633 if (priv->features & FEATURE_HOST_NOTIFY) {
653 priv->status = status & STATUS_ERROR_FLAGS;
654 complete(&priv->done);
661 * For "byte-by-byte" block transactions:
662 * I2C write uses cmd=I801_BLOCK_DATA, I2C_EN=1
663 * I2C read uses cmd=I801_I2C_BLOCK_DATA
673 const struct i2c_adapter *adap = &priv->adapter;
676 return -EOPNOTSUPP;
678 len = data->block[0];
682 iowrite8(data->block[1], SMBBLKDAT(priv));
691 if (priv->features & FEATURE_IRQ) {
692 priv->is_read = (read_write == I2C_SMBUS_READ);
693 if (len == 1 && priv->is_read)
695 priv->cmd = smbcmd | SMBHSTCNT_INTREN;
696 priv->len = len;
697 priv->count = 0;
698 priv->data = &data->block[1];
700 reinit_completion(&priv->done);
701 iowrite8(priv->cmd | SMBHSTCNT_START, SMBHSTCNT(priv));
702 result = wait_for_completion_timeout(&priv->done, adap->timeout);
703 return result ? priv->status : -ETIMEDOUT;
716 * At transfer start i801_smbus_block_transaction() marks
729 return -EPROTO;
731 data->block[0] = len;
735 data->block[i] = ioread8(SMBBLKDAT(priv));
736 if (i == len - 1)
741 iowrite8(data->block[i+1], SMBBLKDAT(priv));
775 iowrite8(data->byte, SMBHSTDAT0(priv));
782 iowrite8(data->word & 0xff, SMBHSTDAT0(priv));
783 iowrite8((data->word & 0xff00) >> 8, SMBHSTDAT1(priv));
790 iowrite8(data->word & 0xff, SMBHSTDAT0(priv));
791 iowrite8((data->word & 0xff00) >> 8, SMBHSTDAT1(priv));
797 pci_err(priv->pci_dev, "Unsupported transaction %d\n", command);
798 return -EOPNOTSUPP;
808 data->byte = ioread8(SMBHSTDAT0(priv));
812 data->word = ioread8(SMBHSTDAT0(priv)) +
825 data->block[0] = SMBUS_LEN_SENTINEL;
826 else if (data->block[0] < 1 || data->block[0] > I2C_SMBUS_BLOCK_MAX)
827 return -EPROTO;
836 if (priv->features & FEATURE_BLOCK_BUFFER)
848 if (data->block[0] < 1 || data->block[0] > I2C_SMBUS_BLOCK_MAX)
849 return -EPROTO;
856 priv->original_hstcfg & SMBHSTCFG_SPD_WD ? read_write : I2C_SMBUS_WRITE);
866 pci_read_config_byte(priv->pci_dev, SMBHSTCFG, &hostc);
867 pci_write_config_byte(priv->pci_dev, SMBHSTCFG, hostc | SMBHSTCFG_I2C_EN);
868 } else if (!(priv->features & FEATURE_I2C_BLOCK_READ)) {
869 pci_err(priv->pci_dev, "I2C block read is unsupported!\n");
870 return -EOPNOTSUPP;
873 /* Block buffer isn't supported for I2C block transactions */
878 pci_write_config_byte(priv->pci_dev, SMBHSTCFG, hostc);
891 if (priv->acpi_reserved)
892 return -EBUSY;
894 pm_runtime_get_sync(&priv->pci_dev->dev);
900 hwpec = (priv->features & FEATURE_SMBUS_PEC) && (flags & I2C_CLIENT_PEC)
931 pm_runtime_mark_last_busy(&priv->pci_dev->dev);
932 pm_runtime_put_autosuspend(&priv->pci_dev->dev);
945 ((priv->features & FEATURE_SMBUS_PEC) ? I2C_FUNC_SMBUS_PEC : 0) |
946 ((priv->features & FEATURE_BLOCK_PROC) ?
948 ((priv->features & FEATURE_I2C_BLOCK_READ) ?
950 ((priv->features & FEATURE_HOST_NOTIFY) ?
958 if (!(priv->features & FEATURE_HOST_NOTIFY))
967 priv->original_slvcmd, SMBSLVCMD(priv));
975 if (!(priv->features & FEATURE_HOST_NOTIFY))
978 iowrite8(priv->original_slvcmd, SMBSLVCMD(priv));
1075 sizeof(signature)-1))
1136 if (dm->type != DMI_ENTRY_ONBOARD_DEVICE)
1139 count = (dm->length - sizeof(struct dmi_header)) / 2;
1142 const char *name = ((char *) dm) + dm->length;
1148 s--;
1151 s--;
1164 if (priv->features & FEATURE_IDF)
1173 i2c_new_client_device(&priv->adapter, &info);
1177 dmi_walk(dmi_check_onboard_devices, &priv->adapter);
1181 if (!priv->mux_pdev)
1183 i2c_register_spd(&priv->adapter);
1211 DMI_MATCH(DMI_BOARD_NAME, "Z8NA-D6(C)"),
1218 DMI_MATCH(DMI_BOARD_NAME, "Z8P(N)E-D12(X)"),
1225 DMI_MATCH(DMI_BOARD_NAME, "Z8NH-D12"),
1232 DMI_MATCH(DMI_BOARD_NAME, "Z8PH-D12/IFB"),
1239 DMI_MATCH(DMI_BOARD_NAME, "Z8NR-D12"),
1246 DMI_MATCH(DMI_BOARD_NAME, "Z8P(N)H-D12"),
1253 DMI_MATCH(DMI_BOARD_NAME, "Z8PG-D18"),
1260 DMI_MATCH(DMI_BOARD_NAME, "Z8PE-D18"),
1267 DMI_MATCH(DMI_BOARD_NAME, "Z8PS-D12"),
1281 dev->type != &i2c_adapter_type ||
1282 i2c_root_adapter(dev) != &priv->adapter)
1294 struct device *dev = &priv->adapter.dev;
1305 mux_config = id->driver_data;
1309 gpio_data.parent = priv->adapter.nr;
1310 gpio_data.values = mux_config->values;
1311 gpio_data.n_values = mux_config->n_values;
1316 struct_size(lookup, table, mux_config->n_gpios + 1),
1320 lookup->dev_id = "i2c-mux-gpio";
1321 for (i = 0; i < mux_config->n_gpios; i++)
1322 lookup->table[i] = GPIO_LOOKUP(mux_config->gpio_chip,
1323 mux_config->gpios[i], "mux", 0);
1326 priv->mux_notifier_block.notifier_call = i801_notifier_call;
1327 if (bus_register_notifier(&i2c_bus_type, &priv->mux_notifier_block))
1336 priv->mux_pdev = platform_device_register_data(dev, "i2c-mux-gpio",
1339 if (IS_ERR(priv->mux_pdev)) {
1342 dev_err(dev, "Failed to register i2c-mux-gpio device\n");
1344 priv->lookup = lookup;
1350 bus_unregister_notifier(&i2c_bus_type, &priv->mux_notifier_block);
1351 platform_device_unregister(priv->mux_pdev);
1352 gpiod_remove_lookup_table(priv->lookup);
1375 ret = p2sb_bar(pci_dev->bus, 0, res);
1379 if (pci_dev->device == PCI_DEVICE_ID_INTEL_DNV_SMBUS)
1380 res->start += SBREG_SMBCTRL_DNV;
1382 res->start += SBREG_SMBCTRL;
1384 res->end = res->start + 3;
1386 return platform_device_register_resndata(&pci_dev->dev, "iTCO_wdt", -1,
1398 return platform_device_register_resndata(&pci_dev->dev, "iTCO_wdt", -1,
1404 struct pci_dev *pci_dev = priv->pci_dev;
1412 if (!(priv->features & (FEATURE_TCO_SPT | FEATURE_TCO_CNL)))
1426 res->start = tco_base & ~1;
1427 res->end = res->start + 32 - 1;
1428 res->flags = IORESOURCE_IO;
1430 if (priv->features & FEATURE_TCO_CNL)
1431 priv->tco_pdev = i801_add_tco_cnl(pci_dev, tco_res);
1433 priv->tco_pdev = i801_add_tco_spt(pci_dev, tco_res);
1435 if (IS_ERR(priv->tco_pdev))
1443 return address >= pci_resource_start(priv->pci_dev, SMBBAR) &&
1444 address <= pci_resource_end(priv->pci_dev, SMBBAR);
1452 struct pci_dev *pdev = priv->pci_dev;
1460 i2c_lock_bus(&priv->adapter, I2C_LOCK_SEGMENT);
1462 if (!priv->acpi_reserved && i801_acpi_is_smbus_ioport(priv, address)) {
1463 priv->acpi_reserved = true;
1472 pm_runtime_get_sync(&pdev->dev);
1480 i2c_unlock_bus(&priv->adapter, I2C_LOCK_SEGMENT);
1487 acpi_handle ah = ACPI_HANDLE(&priv->pci_dev->dev);
1495 return acpi_check_resource_conflict(&priv->pci_dev->resource[SMBBAR]);
1500 acpi_handle ah = ACPI_HANDLE(&priv->pci_dev->dev);
1511 unsigned char hstcfg = priv->original_hstcfg;
1515 pci_write_config_byte(priv->pci_dev, SMBHSTCFG, hstcfg);
1520 iowrite8(priv->original_hstcnt, SMBHSTCNT(priv));
1521 pci_write_config_byte(priv->pci_dev, SMBHSTCFG, priv->original_hstcfg);
1529 priv = devm_kzalloc(&dev->dev, sizeof(*priv), GFP_KERNEL);
1531 return -ENOMEM;
1533 i2c_set_adapdata(&priv->adapter, priv);
1534 priv->adapter.owner = THIS_MODULE;
1535 priv->adapter.class = I2C_CLASS_HWMON;
1536 priv->adapter.algo = &smbus_algorithm;
1537 priv->adapter.dev.parent = &dev->dev;
1538 acpi_use_parent_companion(&priv->adapter.dev);
1539 priv->adapter.retries = 3;
1541 priv->pci_dev = dev;
1542 priv->features = id->driver_data;
1546 if (priv->features & disable_features & (1 << i))
1549 priv->features &= ~disable_features;
1552 if (!(priv->features & FEATURE_BLOCK_BUFFER))
1553 priv->features &= ~FEATURE_BLOCK_PROC;
1568 return -ENODEV;
1572 return -ENODEV;
1577 priv->smba = pcim_iomap_region(dev, bar, DRV_NAME);
1578 if (IS_ERR(priv->smba)) {
1582 return PTR_ERR(priv->smba);
1585 pci_read_config_byte(dev, SMBHSTCFG, &priv->original_hstcfg);
1587 if (!(priv->original_hstcfg & SMBHSTCFG_HST_EN))
1590 if (priv->original_hstcfg & SMBHSTCFG_SMB_SMI_EN) {
1593 priv->features &= ~FEATURE_IRQ;
1595 if (priv->original_hstcfg & SMBHSTCFG_SPD_WD)
1599 if (priv->features & (FEATURE_SMBUS_PEC | FEATURE_BLOCK_BUFFER))
1603 /* Default timeout in interrupt mode: 200 ms */
1604 priv->adapter.timeout = HZ / 5;
1606 if (dev->irq == IRQ_NOTCONNECTED)
1607 priv->features &= ~FEATURE_IRQ;
1609 if (priv->features & FEATURE_IRQ) {
1613 pci_read_config_word(priv->pci_dev, PCI_STATUS, &pcists);
1618 if (priv->features & FEATURE_IRQ) {
1619 init_completion(&priv->done);
1621 err = devm_request_irq(&dev->dev, dev->irq, i801_isr,
1624 pci_err(dev, "Failed to allocate irq %d: %d\n", dev->irq, err);
1625 priv->features &= ~FEATURE_IRQ;
1629 priv->features & FEATURE_IRQ ? "PCI interrupt" : "polling");
1632 if (!(priv->features & FEATURE_IRQ))
1633 priv->features &= ~FEATURE_HOST_NOTIFY;
1636 priv->original_hstcnt = ioread8(SMBHSTCNT(priv)) & ~SMBHSTCNT_KILL;
1637 if (priv->features & FEATURE_HOST_NOTIFY)
1638 priv->original_slvcmd = ioread8(SMBSLVCMD(priv));
1646 snprintf(priv->adapter.name, sizeof(priv->adapter.name),
1648 (priv->features & FEATURE_IDF) ? "I801 IDF" : "I801",
1651 err = i2c_add_adapter(&priv->adapter);
1653 platform_device_unregister(priv->tco_pdev);
1659 i801_enable_host_notify(&priv->adapter);
1661 /* We ignore errors - multiplexing is optional */
1667 dev_pm_set_driver_flags(&dev->dev, DPM_FLAG_NO_DIRECT_COMPLETE);
1668 pm_runtime_set_autosuspend_delay(&dev->dev, 1000);
1669 pm_runtime_use_autosuspend(&dev->dev);
1670 pm_runtime_put_autosuspend(&dev->dev);
1671 pm_runtime_allow(&dev->dev);
1682 i2c_del_adapter(&priv->adapter);
1685 platform_device_unregister(priv->tco_pdev);
1688 if (!priv->acpi_reserved)
1689 pm_runtime_get_noresume(&dev->dev);
1695 * some systems during power-off (eg. Fujitsu-Siemens Lifebook E8010)
1712 i2c_mark_adapter_suspended(&priv->adapter);
1723 i801_enable_host_notify(&priv->adapter);
1724 i2c_mark_adapter_resumed(&priv->adapter);