Lines Matching +full:fixed +full:- +full:burst
1 // SPDX-License-Identifier: GPL-2.0
10 * - Use an interrupt for transaction status instead of hardcoded delays.
11 * - Must use write+wait+read read protocol.
12 * - All 4 bytes of status register must be read/written at once.
13 * - Burst count max is 63 bytes, and burst count behaves slightly differently
15 * - When reading from FIFO the full burstcnt must be read instead of just
45 * struct tpm_i2c_cr50_priv_data - Driver private data.
47 * If irq <= 0, then a fixed timeout is used instead of waiting for irq.
60 * tpm_cr50_i2c_int_handler() - cr50 interrupt handler.
66 * processing but is instead used to avoid fixed delays.
74 struct tpm_i2c_cr50_priv_data *priv = dev_get_drvdata(&chip->dev); in tpm_cr50_i2c_int_handler()
76 complete(&priv->tpm_ready); in tpm_cr50_i2c_int_handler()
82 * tpm_cr50_i2c_wait_tpm_ready() - Wait for tpm to signal ready.
85 * Wait for completion interrupt if available, otherwise use a fixed
89 * - 0: Success.
90 * - -errno: A POSIX error code.
94 struct tpm_i2c_cr50_priv_data *priv = dev_get_drvdata(&chip->dev); in tpm_cr50_i2c_wait_tpm_ready()
96 /* Use a safe fixed delay if interrupt is not supported */ in tpm_cr50_i2c_wait_tpm_ready()
97 if (priv->irq <= 0) { in tpm_cr50_i2c_wait_tpm_ready()
103 if (!wait_for_completion_timeout(&priv->tpm_ready, chip->timeout_a)) { in tpm_cr50_i2c_wait_tpm_ready()
104 dev_warn(&chip->dev, "Timeout waiting for TPM ready\n"); in tpm_cr50_i2c_wait_tpm_ready()
105 return -ETIMEDOUT; in tpm_cr50_i2c_wait_tpm_ready()
112 * tpm_cr50_i2c_enable_tpm_irq() - Enable TPM irq.
117 struct tpm_i2c_cr50_priv_data *priv = dev_get_drvdata(&chip->dev); in tpm_cr50_i2c_enable_tpm_irq()
119 if (priv->irq > 0) { in tpm_cr50_i2c_enable_tpm_irq()
120 reinit_completion(&priv->tpm_ready); in tpm_cr50_i2c_enable_tpm_irq()
121 enable_irq(priv->irq); in tpm_cr50_i2c_enable_tpm_irq()
126 * tpm_cr50_i2c_disable_tpm_irq() - Disable TPM irq.
131 struct tpm_i2c_cr50_priv_data *priv = dev_get_drvdata(&chip->dev); in tpm_cr50_i2c_disable_tpm_irq()
133 if (priv->irq > 0) in tpm_cr50_i2c_disable_tpm_irq()
134 disable_irq(priv->irq); in tpm_cr50_i2c_disable_tpm_irq()
138 * tpm_cr50_i2c_transfer_message() - Transfer a message over i2c.
147 * - 0: Success.
148 * - -errno: A POSIX error code.
168 return -EIO; in tpm_cr50_i2c_transfer_message()
172 * tpm_cr50_i2c_read() - Read from TPM register.
183 * - 0: Success.
184 * - -errno: A POSIX error code.
188 struct i2c_client *client = to_i2c_client(chip->dev.parent); in tpm_cr50_i2c_read()
190 .addr = client->addr, in tpm_cr50_i2c_read()
195 .addr = client->addr, in tpm_cr50_i2c_read()
202 i2c_lock_bus(client->adapter, I2C_LOCK_SEGMENT); in tpm_cr50_i2c_read()
208 rc = tpm_cr50_i2c_transfer_message(&chip->dev, client->adapter, &msg_reg_addr); in tpm_cr50_i2c_read()
218 rc = tpm_cr50_i2c_transfer_message(&chip->dev, client->adapter, &msg_response); in tpm_cr50_i2c_read()
222 i2c_unlock_bus(client->adapter, I2C_LOCK_SEGMENT); in tpm_cr50_i2c_read()
231 * tpm_cr50_i2c_write()- Write to TPM register.
242 * - 0: Success.
243 * - -errno: A POSIX error code.
248 struct tpm_i2c_cr50_priv_data *priv = dev_get_drvdata(&chip->dev); in tpm_cr50_i2c_write()
249 struct i2c_client *client = to_i2c_client(chip->dev.parent); in tpm_cr50_i2c_write()
251 .addr = client->addr, in tpm_cr50_i2c_write()
253 .buf = priv->buf in tpm_cr50_i2c_write()
257 if (len > TPM_CR50_MAX_BUFSIZE - 1) in tpm_cr50_i2c_write()
258 return -EINVAL; in tpm_cr50_i2c_write()
261 priv->buf[0] = addr; in tpm_cr50_i2c_write()
262 memcpy(priv->buf + 1, buffer, len); in tpm_cr50_i2c_write()
264 i2c_lock_bus(client->adapter, I2C_LOCK_SEGMENT); in tpm_cr50_i2c_write()
270 rc = tpm_cr50_i2c_transfer_message(&chip->dev, client->adapter, &msg); in tpm_cr50_i2c_write()
279 i2c_unlock_bus(client->adapter, I2C_LOCK_SEGMENT); in tpm_cr50_i2c_write()
288 * tpm_cr50_check_locality() - Verify TPM locality 0 is active.
292 * - 0: Success.
293 * - -errno: A POSIX error code.
308 return -EIO; in tpm_cr50_check_locality()
312 * tpm_cr50_release_locality() - Release TPM locality.
332 * tpm_cr50_request_locality() - Request TPM locality 0.
336 * - 0: Success.
337 * - -errno: A POSIX error code.
352 stop = jiffies + chip->timeout_a; in tpm_cr50_request_locality()
360 return -ETIMEDOUT; in tpm_cr50_request_locality()
364 * tpm_cr50_i2c_tis_status() - Read cr50 tis status.
383 * tpm_cr50_i2c_tis_set_ready() - Set status register to ready.
397 * tpm_cr50_i2c_get_burst_and_status() - Get burst count and status.
400 * @burst: Return value for burst.
403 * cr50 uses bytes 3:2 of status register for burst count and
407 * - 0: Success.
408 * - -errno: A POSIX error code.
411 size_t *burst, u32 *status) in tpm_cr50_i2c_get_burst_and_status() argument
419 stop = jiffies + chip->timeout_b; in tpm_cr50_i2c_get_burst_and_status()
428 *burst = le16_to_cpup((__le16 *)(buf + 1)); in tpm_cr50_i2c_get_burst_and_status()
431 *burst > 0 && *burst <= TPM_CR50_MAX_BUFSIZE - 1) in tpm_cr50_i2c_get_burst_and_status()
437 dev_err(&chip->dev, "Timeout reading burst and status\n"); in tpm_cr50_i2c_get_burst_and_status()
438 return -ETIMEDOUT; in tpm_cr50_i2c_get_burst_and_status()
442 * tpm_cr50_i2c_tis_recv() - TPM reception callback.
448 * - >= 0: Number of read bytes.
449 * - -errno: A POSIX error code.
461 return -EINVAL; in tpm_cr50_i2c_tis_recv()
468 dev_err(&chip->dev, in tpm_cr50_i2c_tis_recv()
471 rc = -EIO; in tpm_cr50_i2c_tis_recv()
478 dev_err(&chip->dev, "Read of first chunk failed\n"); in tpm_cr50_i2c_tis_recv()
485 dev_err(&chip->dev, "Buffer too small to receive i2c data\n"); in tpm_cr50_i2c_tis_recv()
486 rc = -E2BIG; in tpm_cr50_i2c_tis_recv()
493 /* Read updated burst count and check status */ in tpm_cr50_i2c_tis_recv()
498 len = min_t(size_t, burstcnt, expected - cur); in tpm_cr50_i2c_tis_recv()
501 dev_err(&chip->dev, "Read failed\n"); in tpm_cr50_i2c_tis_recv()
513 dev_err(&chip->dev, "Data still available\n"); in tpm_cr50_i2c_tis_recv()
514 rc = -EIO; in tpm_cr50_i2c_tis_recv()
531 * tpm_cr50_i2c_tis_send() - TPM transmission callback.
537 * - 0: Success.
538 * - -errno: A POSIX error code.
553 stop = jiffies + chip->timeout_b; in tpm_cr50_i2c_tis_send()
556 rc = -ETIMEDOUT; in tpm_cr50_i2c_tis_send()
570 /* Read burst count and check status */ in tpm_cr50_i2c_tis_send()
576 * Use burstcnt - 1 to account for the address byte in tpm_cr50_i2c_tis_send()
579 limit = min_t(size_t, burstcnt - 1, len); in tpm_cr50_i2c_tis_send()
582 dev_err(&chip->dev, "Write failed\n"); in tpm_cr50_i2c_tis_send()
587 len -= limit; in tpm_cr50_i2c_tis_send()
595 dev_err(&chip->dev, "Data still expected\n"); in tpm_cr50_i2c_tis_send()
596 rc = -EIO; in tpm_cr50_i2c_tis_send()
604 dev_err(&chip->dev, "Start command failed\n"); in tpm_cr50_i2c_tis_send()
619 * tpm_cr50_i2c_req_canceled() - Callback to notify a request cancel.
637 ret = device_property_read_u8(dev, "firmware-power-managed", &val); in tpm_cr50_i2c_is_firmware_power_managed()
672 * tpm_cr50_i2c_probe() - Driver probe function.
676 * - 0: Success.
677 * - -errno: A POSIX error code.
682 struct device *dev = &client->dev; in tpm_cr50_i2c_probe()
688 if (!i2c_check_functionality(client->adapter, I2C_FUNC_I2C)) in tpm_cr50_i2c_probe()
689 return -ENODEV; in tpm_cr50_i2c_probe()
697 return -ENOMEM; in tpm_cr50_i2c_probe()
700 chip->flags |= TPM_CHIP_FLAG_TPM2; in tpm_cr50_i2c_probe()
702 chip->flags |= TPM_CHIP_FLAG_FIRMWARE_POWER_MANAGED; in tpm_cr50_i2c_probe()
705 chip->timeout_a = msecs_to_jiffies(TIS_SHORT_TIMEOUT); in tpm_cr50_i2c_probe()
706 chip->timeout_b = msecs_to_jiffies(TIS_LONG_TIMEOUT); in tpm_cr50_i2c_probe()
707 chip->timeout_c = msecs_to_jiffies(TIS_SHORT_TIMEOUT); in tpm_cr50_i2c_probe()
708 chip->timeout_d = msecs_to_jiffies(TIS_SHORT_TIMEOUT); in tpm_cr50_i2c_probe()
710 dev_set_drvdata(&chip->dev, priv); in tpm_cr50_i2c_probe()
711 init_completion(&priv->tpm_ready); in tpm_cr50_i2c_probe()
713 if (client->irq > 0) { in tpm_cr50_i2c_probe()
714 rc = devm_request_irq(dev, client->irq, tpm_cr50_i2c_int_handler, in tpm_cr50_i2c_probe()
717 dev->driver->name, chip); in tpm_cr50_i2c_probe()
719 dev_err(dev, "Failed to probe IRQ %d\n", client->irq); in tpm_cr50_i2c_probe()
723 priv->irq = client->irq; in tpm_cr50_i2c_probe()
747 return -ENODEV; in tpm_cr50_i2c_probe()
752 client->addr, client->irq, vendor >> 16); in tpm_cr50_i2c_probe()
757 * tpm_cr50_i2c_remove() - Driver remove function.
761 * - 0: Success.
762 * - -errno: A POSIX error code.
767 struct device *dev = &client->dev; in tpm_cr50_i2c_remove()