Lines Matching +full:i2c +full:- +full:retry +full:- +full:count

1 // SPDX-License-Identifier: GPL-2.0-only
13 * Infineon I2C Protocol Stack Specification v0.20.
18 #include <linux/i2c.h>
25 /* max. number of iterations after I2C NAK */
31 /* max. number of iterations after I2C NAK for 'long' commands
62 /* In addition to the data itself, the buffer must fit the 7-bit I2C
74 * iic_tpm_read() - read from TPM register
80 * buffer (little-endian format, i.e. first byte is put into buffer[0]).
82 * NOTE: TPM is big-endian for multi-byte values. Multi-byte
86 * provided by the i2c core as the TPM currently does not support the
90 * Return -EIO on error, 0 on success.
96 .addr = tpm_dev.client->addr, in iic_tpm_read()
101 .addr = tpm_dev.client->addr, in iic_tpm_read()
109 int count; in iic_tpm_read() local
113 if (!tpm_dev.client->adapter->algo->master_xfer) in iic_tpm_read()
114 return -EOPNOTSUPP; in iic_tpm_read()
115 i2c_lock_bus(tpm_dev.client->adapter, I2C_LOCK_SEGMENT); in iic_tpm_read()
124 for (count = 0; count < MAX_COUNT; count++) { in iic_tpm_read()
125 rc = __i2c_transfer(tpm_dev.client->adapter, msgs, 2); in iic_tpm_read()
136 for (count = 0; count < MAX_COUNT; count++) { in iic_tpm_read()
137 rc = __i2c_transfer(tpm_dev.client->adapter, in iic_tpm_read()
153 for (count = 0; count < MAX_COUNT; count++) { in iic_tpm_read()
162 rc = __i2c_transfer(tpm_dev.client->adapter, in iic_tpm_read()
171 len -= msglen; in iic_tpm_read()
175 /* If the I2C adapter rejected the request (e.g in iic_tpm_read()
179 if (rc == -EOPNOTSUPP) in iic_tpm_read()
190 i2c_unlock_bus(tpm_dev.client->adapter, I2C_LOCK_SEGMENT); in iic_tpm_read()
199 return -EIO; in iic_tpm_read()
208 int rc = -EIO; in iic_tpm_write_generic()
209 int count; in iic_tpm_write_generic() local
212 .addr = tpm_dev.client->addr, in iic_tpm_write_generic()
218 return -EINVAL; in iic_tpm_write_generic()
220 if (!tpm_dev.client->adapter->algo->master_xfer) in iic_tpm_write_generic()
221 return -EOPNOTSUPP; in iic_tpm_write_generic()
222 i2c_lock_bus(tpm_dev.client->adapter, I2C_LOCK_SEGMENT); in iic_tpm_write_generic()
234 for (count = 0; count < max_count; count++) { in iic_tpm_write_generic()
235 rc = __i2c_transfer(tpm_dev.client->adapter, &msg1, 1); in iic_tpm_write_generic()
241 i2c_unlock_bus(tpm_dev.client->adapter, I2C_LOCK_SEGMENT); in iic_tpm_write_generic()
250 return -EIO; in iic_tpm_write_generic()
256 * iic_tpm_write() - write to TPM register
264 * NOTE: TPM is big-endian for multi-byte values. Multi-byte
269 * Return -EIO on error, 0 on success
355 stop = jiffies + chip->timeout_a; in request_locality()
362 return -ETIME; in request_locality()
367 /* NOTE: since I2C read may fail, return 0 in this case --> time-out */ in tpm_tis_i2c_status()
397 stop = jiffies + chip->timeout_d; in get_burstcount()
410 return -EBUSY; in get_burstcount()
433 return -ETIME; in wait_for_stat()
436 static int recv_data(struct tpm_chip *chip, u8 *buf, size_t count) in recv_data() argument
443 while (size < count) { in recv_data()
451 if (burstcnt > (count - size)) in recv_data()
452 burstcnt = count - size; in recv_data()
463 return -EIO; in recv_data()
468 static int tpm_tis_i2c_recv(struct tpm_chip *chip, u8 *buf, size_t count) in tpm_tis_i2c_recv() argument
474 if (count < TPM_HEADER_SIZE) { in tpm_tis_i2c_recv()
475 size = -EIO; in tpm_tis_i2c_recv()
482 dev_err(&chip->dev, "Unable to read header\n"); in tpm_tis_i2c_recv()
487 if (((size_t) expected > count) || (expected < TPM_HEADER_SIZE)) { in tpm_tis_i2c_recv()
488 size = -EIO; in tpm_tis_i2c_recv()
493 expected - TPM_HEADER_SIZE); in tpm_tis_i2c_recv()
495 dev_err(&chip->dev, "Unable to read remainder of result\n"); in tpm_tis_i2c_recv()
496 size = -ETIME; in tpm_tis_i2c_recv()
500 wait_for_stat(chip, TPM_STS_VALID, chip->timeout_c, &status); in tpm_tis_i2c_recv()
501 if (status & TPM_STS_DATA_AVAIL) { /* retry? */ in tpm_tis_i2c_recv()
502 dev_err(&chip->dev, "Error left over data\n"); in tpm_tis_i2c_recv()
503 size = -EIO; in tpm_tis_i2c_recv()
521 size_t count = 0; in tpm_tis_i2c_send() local
526 return -E2BIG; in tpm_tis_i2c_send()
529 return -EBUSY; in tpm_tis_i2c_send()
536 chip->timeout_b, &status) < 0) { in tpm_tis_i2c_send()
537 rc = -ETIME; in tpm_tis_i2c_send()
542 while (count < len - 1) { in tpm_tis_i2c_send()
549 if (burstcnt > (len - 1 - count)) in tpm_tis_i2c_send()
550 burstcnt = len - 1 - count; in tpm_tis_i2c_send()
553 &(buf[count]), burstcnt); in tpm_tis_i2c_send()
555 count += burstcnt; in tpm_tis_i2c_send()
561 rc = -EIO; in tpm_tis_i2c_send()
566 chip->timeout_c, &status); in tpm_tis_i2c_send()
569 rc = -EIO; in tpm_tis_i2c_send()
575 iic_tpm_write(TPM_DATA_FIFO(tpm_dev.locality), &(buf[count]), 1); in tpm_tis_i2c_send()
576 wait_for_stat(chip, TPM_STS_VALID, chip->timeout_c, &status); in tpm_tis_i2c_send()
578 rc = -EIO; in tpm_tis_i2c_send()
623 chip->timeout_a = msecs_to_jiffies(TIS_SHORT_TIMEOUT); in tpm_tis_i2c_init()
624 chip->timeout_b = msecs_to_jiffies(TIS_LONG_TIMEOUT); in tpm_tis_i2c_init()
625 chip->timeout_c = msecs_to_jiffies(TIS_SHORT_TIMEOUT); in tpm_tis_i2c_init()
626 chip->timeout_d = msecs_to_jiffies(TIS_SHORT_TIMEOUT); in tpm_tis_i2c_init()
630 rc = -ENODEV; in tpm_tis_i2c_init()
637 rc = -EIO; in tpm_tis_i2c_init()
647 rc = -ENODEV; in tpm_tis_i2c_init()
651 dev_info(dev, "1.2 TPM (device-id 0x%X)\n", vendor >> 16); in tpm_tis_i2c_init()
670 MODULE_DEVICE_TABLE(i2c, tpm_tis_i2c_table);
688 struct device *dev = &(client->dev); in tpm_tis_i2c_probe()
692 return -EBUSY; /* We only support one client */ in tpm_tis_i2c_probe()
695 if (!i2c_check_functionality(client->adapter, I2C_FUNC_I2C)) { in tpm_tis_i2c_probe()
696 dev_err(dev, "no algorithms associated to the i2c bus\n"); in tpm_tis_i2c_probe()
697 return -ENODEV; in tpm_tis_i2c_probe()
701 rc = tpm_tis_i2c_init(&client->dev); in tpm_tis_i2c_probe()
704 rc = -ENODEV; in tpm_tis_i2c_probe()
733 MODULE_DESCRIPTION("TPM TIS I2C Infineon Driver");