Lines Matching +full:burst +full:- +full:read

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
48 * struct tpm_i2c_cr50_priv_data - Driver private data.
63 * tpm_cr50_i2c_int_handler() - cr50 interrupt handler.
77 struct tpm_i2c_cr50_priv_data *priv = dev_get_drvdata(&chip->dev); in tpm_cr50_i2c_int_handler()
79 complete(&priv->tpm_ready); in tpm_cr50_i2c_int_handler()
85 * tpm_cr50_i2c_wait_tpm_ready() - Wait for tpm to signal ready.
92 * - 0: Success.
93 * - -errno: A POSIX error code.
97 struct tpm_i2c_cr50_priv_data *priv = dev_get_drvdata(&chip->dev); in tpm_cr50_i2c_wait_tpm_ready()
100 if (priv->irq <= 0) { in tpm_cr50_i2c_wait_tpm_ready()
106 if (!wait_for_completion_timeout(&priv->tpm_ready, chip->timeout_a)) { in tpm_cr50_i2c_wait_tpm_ready()
107 dev_warn(&chip->dev, "Timeout waiting for TPM ready\n"); in tpm_cr50_i2c_wait_tpm_ready()
108 return -ETIMEDOUT; in tpm_cr50_i2c_wait_tpm_ready()
115 * tpm_cr50_i2c_enable_tpm_irq() - Enable TPM irq.
120 struct tpm_i2c_cr50_priv_data *priv = dev_get_drvdata(&chip->dev); in tpm_cr50_i2c_enable_tpm_irq()
122 if (priv->irq > 0) { in tpm_cr50_i2c_enable_tpm_irq()
123 reinit_completion(&priv->tpm_ready); in tpm_cr50_i2c_enable_tpm_irq()
124 enable_irq(priv->irq); in tpm_cr50_i2c_enable_tpm_irq()
129 * tpm_cr50_i2c_disable_tpm_irq() - Disable TPM irq.
134 struct tpm_i2c_cr50_priv_data *priv = dev_get_drvdata(&chip->dev); in tpm_cr50_i2c_disable_tpm_irq()
136 if (priv->irq > 0) in tpm_cr50_i2c_disable_tpm_irq()
137 disable_irq(priv->irq); in tpm_cr50_i2c_disable_tpm_irq()
141 * tpm_cr50_i2c_transfer_message() - Transfer a message over i2c.
150 * - 0: Success.
151 * - -errno: A POSIX error code.
171 return -EIO; in tpm_cr50_i2c_transfer_message()
175 * tpm_cr50_i2c_read() - Read from TPM register.
177 * @addr: Register address to read from.
178 * @buffer: Read destination, provided by caller.
179 * @len: Number of bytes to read.
183 * bytes are read from TPM response into the provided 'buffer'.
186 * - 0: Success.
187 * - -errno: A POSIX error code.
191 struct i2c_client *client = to_i2c_client(chip->dev.parent); in tpm_cr50_i2c_read()
193 .addr = client->addr, in tpm_cr50_i2c_read()
198 .addr = client->addr, in tpm_cr50_i2c_read()
209 rc = tpm_cr50_i2c_transfer_message(&chip->dev, client->adapter, &msg_reg_addr); in tpm_cr50_i2c_read()
218 /* Read response data from the TPM */ in tpm_cr50_i2c_read()
219 rc = tpm_cr50_i2c_transfer_message(&chip->dev, client->adapter, &msg_response); 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()
268 rc = tpm_cr50_i2c_transfer_message(&chip->dev, client->adapter, &msg); in tpm_cr50_i2c_write()
285 * tpm_cr50_check_locality() - Verify if required TPM locality is active.
290 * - loc: Success.
291 * - -errno: A POSIX error code.
306 return -EIO; in tpm_cr50_check_locality()
310 * tpm_cr50_release_locality() - Release TPM locality.
315 * - 0: Success.
316 * - -errno: A POSIX error code.
320 struct i2c_client *client = to_i2c_client(chip->dev.parent); in tpm_cr50_release_locality()
336 i2c_unlock_bus(client->adapter, I2C_LOCK_SEGMENT); in tpm_cr50_release_locality()
341 * tpm_cr50_request_locality() - Request TPM locality.
346 * - loc: Success.
347 * - -errno: A POSIX error code.
351 struct i2c_client *client = to_i2c_client(chip->dev.parent); in tpm_cr50_request_locality()
356 i2c_lock_bus(client->adapter, I2C_LOCK_SEGMENT); in tpm_cr50_request_locality()
365 stop = jiffies + chip->timeout_a; in tpm_cr50_request_locality()
373 rc = -ETIMEDOUT; in tpm_cr50_request_locality()
376 i2c_unlock_bus(client->adapter, I2C_LOCK_SEGMENT); in tpm_cr50_request_locality()
381 * tpm_cr50_i2c_tis_status() - Read cr50 tis status.
384 * cr50 requires all 4 bytes of status register to be read.
393 if (tpm_cr50_i2c_read(chip, TPM_I2C_STS(chip->locality), buf, sizeof(buf)) < 0) in tpm_cr50_i2c_tis_status()
400 * tpm_cr50_i2c_tis_set_ready() - Set status register to ready.
409 tpm_cr50_i2c_write(chip, TPM_I2C_STS(chip->locality), buf, sizeof(buf)); in tpm_cr50_i2c_tis_set_ready()
414 * tpm_cr50_i2c_get_burst_and_status() - Get burst count and status.
417 * @burst: Return value for burst.
420 * cr50 uses bytes 3:2 of status register for burst count and
421 * all 4 bytes must be read.
424 * - 0: Success.
425 * - -errno: A POSIX error code.
428 size_t *burst, u32 *status) in tpm_cr50_i2c_get_burst_and_status() argument
436 stop = jiffies + chip->timeout_b; in tpm_cr50_i2c_get_burst_and_status()
439 if (tpm_cr50_i2c_read(chip, TPM_I2C_STS(chip->locality), buf, sizeof(buf)) < 0) { in tpm_cr50_i2c_get_burst_and_status()
445 *burst = le16_to_cpup((__le16 *)(buf + 1)); in tpm_cr50_i2c_get_burst_and_status()
448 *burst > 0 && *burst <= TPM_CR50_MAX_BUFSIZE - 1) in tpm_cr50_i2c_get_burst_and_status()
454 dev_err(&chip->dev, "Timeout reading burst and status\n"); in tpm_cr50_i2c_get_burst_and_status()
455 return -ETIMEDOUT; in tpm_cr50_i2c_get_burst_and_status()
459 * tpm_cr50_i2c_tis_recv() - TPM reception callback.
462 * @buf_len: Buffer length to read.
465 * - >= 0: Number of read bytes.
466 * - -errno: A POSIX error code.
473 u8 addr = TPM_I2C_DATA_FIFO(chip->locality); in tpm_cr50_i2c_tis_recv()
478 return -EINVAL; in tpm_cr50_i2c_tis_recv()
485 dev_err(&chip->dev, in tpm_cr50_i2c_tis_recv()
488 rc = -EIO; in tpm_cr50_i2c_tis_recv()
492 /* Read first chunk of burstcnt bytes */ in tpm_cr50_i2c_tis_recv()
495 dev_err(&chip->dev, "Read of first chunk failed\n"); in tpm_cr50_i2c_tis_recv()
502 dev_err(&chip->dev, "Buffer too small to receive i2c data\n"); in tpm_cr50_i2c_tis_recv()
503 rc = -E2BIG; in tpm_cr50_i2c_tis_recv()
507 /* Now read the rest of the data */ in tpm_cr50_i2c_tis_recv()
510 /* Read updated burst count and check status */ in tpm_cr50_i2c_tis_recv()
515 len = min_t(size_t, burstcnt, expected - cur); in tpm_cr50_i2c_tis_recv()
518 dev_err(&chip->dev, "Read failed\n"); in tpm_cr50_i2c_tis_recv()
530 dev_err(&chip->dev, "Data still available\n"); in tpm_cr50_i2c_tis_recv()
531 rc = -EIO; in tpm_cr50_i2c_tis_recv()
546 * tpm_cr50_i2c_tis_send() - TPM transmission callback.
552 * - 0: Success.
553 * - -errno: A POSIX error code.
564 stop = jiffies + chip->timeout_b; in tpm_cr50_i2c_tis_send()
567 rc = -ETIMEDOUT; in tpm_cr50_i2c_tis_send()
581 /* Read burst count and check status */ in tpm_cr50_i2c_tis_send()
587 * Use burstcnt - 1 to account for the address byte in tpm_cr50_i2c_tis_send()
590 limit = min_t(size_t, burstcnt - 1, len); in tpm_cr50_i2c_tis_send()
591 rc = tpm_cr50_i2c_write(chip, TPM_I2C_DATA_FIFO(chip->locality), in tpm_cr50_i2c_tis_send()
594 dev_err(&chip->dev, "Write failed\n"); in tpm_cr50_i2c_tis_send()
599 len -= limit; in tpm_cr50_i2c_tis_send()
607 dev_err(&chip->dev, "Data still expected\n"); in tpm_cr50_i2c_tis_send()
608 rc = -EIO; in tpm_cr50_i2c_tis_send()
613 rc = tpm_cr50_i2c_write(chip, TPM_I2C_STS(chip->locality), tpm_go, in tpm_cr50_i2c_tis_send()
616 dev_err(&chip->dev, "Start command failed\n"); in tpm_cr50_i2c_tis_send()
630 * tpm_cr50_i2c_req_canceled() - Callback to notify a request cancel.
648 ret = device_property_read_u8(dev, "firmware-power-managed", &val); in tpm_cr50_i2c_is_firmware_power_managed()
685 * tpm_cr50_vid_to_name() - Maps VID to name.
706 * tpm_cr50_i2c_probe() - Driver probe function.
710 * - 0: Success.
711 * - -errno: A POSIX error code.
716 struct device *dev = &client->dev; in tpm_cr50_i2c_probe()
723 if (!i2c_check_functionality(client->adapter, I2C_FUNC_I2C)) in tpm_cr50_i2c_probe()
724 return -ENODEV; in tpm_cr50_i2c_probe()
732 return -ENOMEM; in tpm_cr50_i2c_probe()
735 chip->flags |= TPM_CHIP_FLAG_TPM2; in tpm_cr50_i2c_probe()
737 chip->flags |= TPM_CHIP_FLAG_FIRMWARE_POWER_MANAGED; in tpm_cr50_i2c_probe()
740 chip->timeout_a = msecs_to_jiffies(TIS_SHORT_TIMEOUT); in tpm_cr50_i2c_probe()
741 chip->timeout_b = msecs_to_jiffies(TIS_LONG_TIMEOUT); in tpm_cr50_i2c_probe()
742 chip->timeout_c = msecs_to_jiffies(TIS_SHORT_TIMEOUT); in tpm_cr50_i2c_probe()
743 chip->timeout_d = msecs_to_jiffies(TIS_SHORT_TIMEOUT); in tpm_cr50_i2c_probe()
745 dev_set_drvdata(&chip->dev, priv); in tpm_cr50_i2c_probe()
746 init_completion(&priv->tpm_ready); in tpm_cr50_i2c_probe()
748 if (client->irq > 0) { in tpm_cr50_i2c_probe()
749 rc = devm_request_irq(dev, client->irq, tpm_cr50_i2c_int_handler, in tpm_cr50_i2c_probe()
752 dev->driver->name, chip); in tpm_cr50_i2c_probe()
754 dev_err(dev, "Failed to probe IRQ %d\n", client->irq); in tpm_cr50_i2c_probe()
758 priv->irq = client->irq; in tpm_cr50_i2c_probe()
770 /* Read four bytes from DID_VID register */ in tpm_cr50_i2c_probe()
773 dev_err(dev, "Could not read vendor id\n"); in tpm_cr50_i2c_probe()
790 return -ENODEV; in tpm_cr50_i2c_probe()
795 client->addr, client->irq, vendor >> 16); in tpm_cr50_i2c_probe()
800 * tpm_cr50_i2c_remove() - Driver remove function.
804 * - 0: Success.
805 * - -errno: A POSIX error code.
810 struct device *dev = &client->dev; in tpm_cr50_i2c_remove()