Lines Matching +full:i2c +full:- +full:retry +full:- +full:count
1 // SPDX-License-Identifier: GPL-2.0-or-later
3 * ATMEL I2C TPM AT97SC3204T
9 * Device driver for ATMEL I2C TPMs.
11 * Teddy Reed determined the basic I2C command flow, unlike other I2C TPM
12 * devices the raw TCG formatted TPM command data is written via I2C and then
13 * raw TCG formatted TPM command data is returned via I2C.
22 #include <linux/i2c.h>
35 * fair number of read responses in the buffer so a 2nd retry can be
42 struct priv_data *priv = dev_get_drvdata(&chip->dev); in i2c_atmel_send()
43 struct i2c_client *client = to_i2c_client(chip->dev.parent); in i2c_atmel_send()
46 priv->len = 0; in i2c_atmel_send()
49 return -EIO; in i2c_atmel_send()
53 dev_dbg(&chip->dev, in i2c_atmel_send()
54 "%s(buf=%*ph len=%0zx) -> sts=%d\n", __func__, in i2c_atmel_send()
62 return -E2BIG; in i2c_atmel_send()
67 static int i2c_atmel_recv(struct tpm_chip *chip, u8 *buf, size_t count) in i2c_atmel_recv() argument
69 struct priv_data *priv = dev_get_drvdata(&chip->dev); in i2c_atmel_recv()
70 struct i2c_client *client = to_i2c_client(chip->dev.parent); in i2c_atmel_recv()
71 struct tpm_header *hdr = (struct tpm_header *)priv->buffer; in i2c_atmel_recv()
75 if (priv->len == 0) in i2c_atmel_recv()
76 return -EIO; in i2c_atmel_recv()
79 * whole message in read_status then we need to re-read the in i2c_atmel_recv()
81 expected_len = be32_to_cpu(hdr->length); in i2c_atmel_recv()
82 if (expected_len > count) in i2c_atmel_recv()
83 return -ENOMEM; in i2c_atmel_recv()
85 if (priv->len >= expected_len) { in i2c_atmel_recv()
86 dev_dbg(&chip->dev, in i2c_atmel_recv()
87 "%s early(buf=%*ph count=%0zx) -> ret=%d\n", __func__, in i2c_atmel_recv()
88 (int)min_t(size_t, 64, expected_len), buf, count, in i2c_atmel_recv()
90 memcpy(buf, priv->buffer, expected_len); in i2c_atmel_recv()
95 dev_dbg(&chip->dev, in i2c_atmel_recv()
96 "%s reread(buf=%*ph count=%0zx) -> ret=%d\n", __func__, in i2c_atmel_recv()
97 (int)min_t(size_t, 64, expected_len), buf, count, in i2c_atmel_recv()
104 dev_err(&chip->dev, "TPM operation cancellation was requested, but is not supported"); in i2c_atmel_cancel()
109 struct priv_data *priv = dev_get_drvdata(&chip->dev); in i2c_atmel_read_status()
110 struct i2c_client *client = to_i2c_client(chip->dev.parent); in i2c_atmel_read_status()
113 /* The TPM fails the I2C read until it is ready, so we do the entire in i2c_atmel_read_status()
116 priv->len = 0; in i2c_atmel_read_status()
117 memset(priv->buffer, 0, sizeof(priv->buffer)); in i2c_atmel_read_status()
122 rc = i2c_master_recv(client, priv->buffer, sizeof(priv->buffer)); in i2c_atmel_read_status()
123 dev_dbg(&chip->dev, in i2c_atmel_read_status()
128 priv->len = rc; in i2c_atmel_read_status()
153 struct device *dev = &client->dev; in i2c_atmel_probe()
156 if (!i2c_check_functionality(client->adapter, I2C_FUNC_I2C)) in i2c_atmel_probe()
157 return -ENODEV; in i2c_atmel_probe()
165 return -ENOMEM; in i2c_atmel_probe()
168 chip->timeout_a = msecs_to_jiffies(TPM_I2C_SHORT_TIMEOUT); in i2c_atmel_probe()
169 chip->timeout_b = msecs_to_jiffies(TPM_I2C_LONG_TIMEOUT); in i2c_atmel_probe()
170 chip->timeout_c = msecs_to_jiffies(TPM_I2C_SHORT_TIMEOUT); in i2c_atmel_probe()
171 chip->timeout_d = msecs_to_jiffies(TPM_I2C_SHORT_TIMEOUT); in i2c_atmel_probe()
173 dev_set_drvdata(&chip->dev, priv); in i2c_atmel_probe()
184 struct device *dev = &(client->dev); in i2c_atmel_remove()
194 MODULE_DEVICE_TABLE(i2c, i2c_atmel_id);
220 MODULE_DESCRIPTION("Atmel TPM I2C Driver");