25 #include <linux/i2c.h>
26 #include <linux/module.h>
28 #include <linux/wait.h>
32 #define TPM_BUFSIZE 1260
37 #define SLEEP_DURATION_LOW 55
38 #define SLEEP_DURATION_HI 65
45 #define MAX_COUNT_LONG 50
47 #define SLEEP_DURATION_LONG_LOW 200
48 #define SLEEP_DURATION_LONG_HI 220
51 #define SLEEP_DURATION_RESET_LOW 2400
52 #define SLEEP_DURATION_RESET_HI 2600
55 #define TPM_TIMEOUT_US_LOW (TPM_TIMEOUT * 1000)
56 #define TPM_TIMEOUT_US_HI (TPM_TIMEOUT_US_LOW + 2000)
59 #define TPM_TIS_I2C_DID_VID 0x000b15d1L
93 struct i2c_msg msg1 = { tpm_dev.client->addr, 0, 1, &addr };
100 if (!tpm_dev.client->adapter->algo->master_xfer)
104 for (count = 0; count <
MAX_COUNT; count++) {
118 for (count = 0; count <
MAX_COUNT; count++) {
134 static int iic_tpm_write_generic(
u8 addr,
u8 *buffer,
size_t len,
135 unsigned int sleep_low,
141 struct i2c_msg msg1 = { tpm_dev.client->addr, 0, len + 1, tpm_dev.buf };
146 if (!tpm_dev.client->adapter->algo->master_xfer)
151 tpm_dev.buf[0] =
addr;
152 memcpy(&(tpm_dev.buf[1]), buffer, len);
158 for (count = 0; count <
max_count; count++) {
189 static int iic_tpm_write(
u8 addr,
u8 *buffer,
size_t len)
199 static int iic_tpm_write_long(
u8 addr,
u8 *buffer,
size_t len)
225 #define TPM_ACCESS(l) (0x0000 | ((l) << 4))
226 #define TPM_STS(l) (0x0001 | ((l) << 4))
227 #define TPM_DATA_FIFO(l) (0x0005 | ((l) << 4))
228 #define TPM_DID_VID(l) (0x0006 | ((l) << 4))
252 if (iic_tpm_read(
TPM_ACCESS(loc), &buf, 1) < 0)
262 static int request_locality(
struct tpm_chip *chip,
int loc)
267 if (check_locality(chip, loc) >= 0)
275 if (check_locality(chip, loc) >= 0)
283 static u8 tpm_tis_i2c_status(
struct tpm_chip *chip)
287 if (iic_tpm_read(
TPM_STS(chip->
vendor.locality), &buf, 1) < 0)
293 static void tpm_tis_i2c_ready(
struct tpm_chip *chip)
311 if (iic_tpm_read(
TPM_STS(chip->
vendor.locality)+1, buf, 3) < 0)
314 burstcnt = (buf[2] << 16) + (buf[1] << 8) + buf[0];
324 static int wait_for_stat(
struct tpm_chip *chip,
u8 mask,
unsigned long timeout,
330 *status = tpm_tis_i2c_status(chip);
331 if ((*status & mask) == mask)
338 *status = tpm_tis_i2c_status(chip);
339 if ((*status & mask) == mask)
347 static int recv_data(
struct tpm_chip *chip,
u8 *buf,
size_t count)
354 while (size < count) {
355 burstcnt = get_burstcount(chip);
362 if (burstcnt > (count - size))
363 burstcnt = count -
size;
366 &(buf[size]), burstcnt);
380 static int tpm_tis_i2c_recv(
struct tpm_chip *chip,
u8 *buf,
size_t count)
393 dev_err(chip->
dev,
"Unable to read header\n");
398 if ((
size_t) expected > count) {
404 expected - TPM_HEADER_SIZE);
405 if (size < expected) {
406 dev_err(chip->
dev,
"Unable to read remainder of result\n");
419 tpm_tis_i2c_ready(chip);
424 release_locality(chip, chip->
vendor.locality, 0);
428 static int tpm_tis_i2c_send(
struct tpm_chip *chip,
u8 *buf,
size_t len)
439 if (request_locality(chip, 0) < 0)
442 status = tpm_tis_i2c_status(chip);
444 tpm_tis_i2c_ready(chip);
446 (chip, TPM_STS_COMMAND_READY,
447 chip->
vendor.timeout_b, &status) < 0) {
453 while (count < len - 1) {
454 burstcnt = get_burstcount(chip);
460 if (burstcnt > (len - 1 - count))
461 burstcnt = len - 1 -
count;
464 &(buf[count]), burstcnt);
477 chip->
vendor.timeout_c, &status);
499 tpm_tis_i2c_ready(chip);
504 release_locality(chip, chip->
vendor.locality, 0);
529 &dev_attr_pubek.attr,
531 &dev_attr_enabled.attr,
532 &dev_attr_active.attr,
533 &dev_attr_owned.attr,
534 &dev_attr_temp_deactivated.attr,
536 &dev_attr_cancel.attr,
537 &dev_attr_durations.attr,
538 &dev_attr_timeouts.attr,
547 .status = tpm_tis_i2c_status,
548 .recv = tpm_tis_i2c_recv,
549 .send = tpm_tis_i2c_send,
550 .cancel = tpm_tis_i2c_ready,
554 .attr_group = &tis_attr_grp,
555 .miscdev.fops = &tis_ops,
579 if (request_locality(chip, 0) != 0) {
598 dev_info(dev,
"1.2 TPM (device-id 0x%X)\n", vendor >> 16);
600 INIT_LIST_HEAD(&chip->
vendor.list);
609 release_locality(chip, chip->
vendor.locality, 1);
621 tpm_dev.client =
NULL;
628 {
"tpm_i2c_infineon", 0},
639 if (tpm_dev.client !=
NULL)
644 "no algorithms associated to the i2c bus\n");
648 client->
driver = &tpm_tis_i2c_driver;
650 rc = tpm_tis_i2c_init(&client->
dev);
653 tpm_dev.client =
NULL;
661 struct tpm_chip *chip = tpm_dev.chip;
662 release_locality(chip, chip->
vendor.locality, 1);
673 tpm_dev.client =
NULL;
679 static struct i2c_driver tpm_tis_i2c_driver = {
681 .id_table = tpm_tis_i2c_table,
682 .probe = tpm_tis_i2c_probe,
683 .remove = tpm_tis_i2c_remove,
685 .name =
"tpm_i2c_infineon",
687 .pm = &tpm_tis_i2c_ops,