Lines Matching +full:multi +full:- +full:chip

1 // SPDX-License-Identifier: GPL-2.0-only
62 /* In addition to the data itself, the buffer must fit the 7-bit I2C
66 struct tpm_chip *chip; member
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
88 * The i2c_smbus* functions do not work for this chip.
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()
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()
125 rc = __i2c_transfer(tpm_dev.client->adapter, msgs, 2); in iic_tpm_read()
137 rc = __i2c_transfer(tpm_dev.client->adapter, in iic_tpm_read()
162 rc = __i2c_transfer(tpm_dev.client->adapter, in iic_tpm_read()
171 len -= msglen; 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()
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()
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
312 static bool check_locality(struct tpm_chip *chip, int loc) in check_locality() argument
331 static void release_locality(struct tpm_chip *chip, int loc, int force) in release_locality() argument
344 static int request_locality(struct tpm_chip *chip, int loc) in request_locality() argument
349 if (check_locality(chip, loc)) in request_locality()
355 stop = jiffies + chip->timeout_a; in request_locality()
357 if (check_locality(chip, loc)) in request_locality()
362 return -ETIME; in request_locality()
365 static u8 tpm_tis_i2c_status(struct tpm_chip *chip) in tpm_tis_i2c_status() argument
367 /* NOTE: since I2C read may fail, return 0 in this case --> time-out */ in tpm_tis_i2c_status()
382 static void tpm_tis_i2c_ready(struct tpm_chip *chip) in tpm_tis_i2c_ready() argument
389 static ssize_t get_burstcount(struct tpm_chip *chip) in get_burstcount() argument
397 stop = jiffies + chip->timeout_d; in get_burstcount()
410 return -EBUSY; in get_burstcount()
413 static int wait_for_stat(struct tpm_chip *chip, u8 mask, unsigned long timeout, in wait_for_stat() argument
419 *status = tpm_tis_i2c_status(chip); in wait_for_stat()
427 *status = tpm_tis_i2c_status(chip); in wait_for_stat()
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
444 burstcnt = get_burstcount(chip); 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
475 size = -EIO; in tpm_tis_i2c_recv()
480 size = recv_data(chip, buf, TPM_HEADER_SIZE); in tpm_tis_i2c_recv()
482 dev_err(&chip->dev, "Unable to read header\n"); in tpm_tis_i2c_recv()
488 size = -EIO; in tpm_tis_i2c_recv()
492 size += recv_data(chip, &buf[TPM_HEADER_SIZE], 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()
502 dev_err(&chip->dev, "Error left over data\n"); in tpm_tis_i2c_recv()
503 size = -EIO; in tpm_tis_i2c_recv()
508 tpm_tis_i2c_ready(chip); in tpm_tis_i2c_recv()
513 release_locality(chip, tpm_dev.locality, 0); in tpm_tis_i2c_recv()
517 static int tpm_tis_i2c_send(struct tpm_chip *chip, u8 *buf, size_t len) in tpm_tis_i2c_send() argument
526 return -E2BIG; in tpm_tis_i2c_send()
528 if (request_locality(chip, 0) < 0) in tpm_tis_i2c_send()
529 return -EBUSY; in tpm_tis_i2c_send()
531 status = tpm_tis_i2c_status(chip); in tpm_tis_i2c_send()
533 tpm_tis_i2c_ready(chip); in tpm_tis_i2c_send()
535 (chip, TPM_STS_COMMAND_READY, 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()
543 burstcnt = get_burstcount(chip); 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()
561 rc = -EIO; in tpm_tis_i2c_send()
565 wait_for_stat(chip, TPM_STS_VALID, in tpm_tis_i2c_send()
566 chip->timeout_c, &status); in tpm_tis_i2c_send()
569 rc = -EIO; 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()
587 tpm_tis_i2c_ready(chip); in tpm_tis_i2c_send()
592 release_locality(chip, tpm_dev.locality, 0); in tpm_tis_i2c_send()
596 static bool tpm_tis_i2c_req_canceled(struct tpm_chip *chip, u8 status) in tpm_tis_i2c_req_canceled() argument
616 struct tpm_chip *chip; in tpm_tis_i2c_init() local
618 chip = tpmm_chip_alloc(dev, &tpm_tis_i2c); in tpm_tis_i2c_init()
619 if (IS_ERR(chip)) in tpm_tis_i2c_init()
620 return PTR_ERR(chip); in tpm_tis_i2c_init()
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()
628 if (request_locality(chip, 0) != 0) { 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()
653 tpm_dev.chip = chip; in tpm_tis_i2c_init()
655 return tpm_chip_register(chip); in tpm_tis_i2c_init()
657 release_locality(chip, tpm_dev.locality, 1); in tpm_tis_i2c_init()
687 struct device *dev = &(client->dev); in tpm_tis_i2c_probe()
691 return -EBUSY; /* We only support one client */ in tpm_tis_i2c_probe()
694 if (!i2c_check_functionality(client->adapter, I2C_FUNC_I2C)) { in tpm_tis_i2c_probe()
696 return -ENODEV; in tpm_tis_i2c_probe()
700 rc = tpm_tis_i2c_init(&client->dev); in tpm_tis_i2c_probe()
703 rc = -ENODEV; in tpm_tis_i2c_probe()
710 struct tpm_chip *chip = tpm_dev.chip; in tpm_tis_i2c_remove() local
712 tpm_chip_unregister(chip); in tpm_tis_i2c_remove()
713 release_locality(chip, tpm_dev.locality, 1); in tpm_tis_i2c_remove()