24 #define TPM_MAX_WTX_PACKAGES 50
26 #define TPM_WTX_MSLEEP_TIME 20
28 #define TPM_MSLEEP_TIME 3
30 #define TPM_MAX_TRIES 5000
31 #define TPM_INFINEON_DEV_VEN_VALUE 0x15D1
33 #define TPM_INF_IO_PORT 0x0
34 #define TPM_INF_IO_MEM 0x1
36 #define TPM_INF_ADDR 0x0
37 #define TPM_INF_DATA 0x1
56 static inline void tpm_data_out(
unsigned char data,
unsigned char offset)
59 outb(data, tpm_dev.data_regs + offset);
61 writeb(data, tpm_dev.mem_base + tpm_dev.data_regs + offset);
64 static inline unsigned char tpm_data_in(
unsigned char offset)
67 return inb(tpm_dev.data_regs + offset);
69 return readb(tpm_dev.mem_base + tpm_dev.data_regs + offset);
72 static inline void tpm_config_out(
unsigned char data,
unsigned char offset)
75 outb(data, tpm_dev.config_port + offset);
77 writeb(data, tpm_dev.mem_base + tpm_dev.index_off + offset);
80 static inline unsigned char tpm_config_in(
unsigned char offset)
83 return inb(tpm_dev.config_port + offset);
85 return readb(tpm_dev.mem_base + tpm_dev.index_off + offset);
146 static int number_of_wtx;
148 static int empty_fifo(
struct tpm_chip *
chip,
int clear_wrfifo)
155 for (i = 0; i < 4096; i++) {
156 status = tpm_data_in(
WRFIFO);
157 if (status == 0xff) {
176 status = tpm_data_in(
RDFIFO);
177 status = tpm_data_in(
STAT);
181 }
while ((status & (1 <<
STAT_RDA)) != 0);
185 static int wait(
struct tpm_chip *chip,
int wait_for_bit)
190 status = tpm_data_in(
STAT);
192 if (status & 1 << wait_for_bit)
196 if (i == TPM_MAX_TRIES) {
198 dev_err(chip->
dev,
"Timeout in wait(STAT_XFE)\n");
200 dev_err(chip->
dev,
"Timeout in wait(STAT_RDA)\n");
206 static void wait_and_send(
struct tpm_chip *chip,
u8 sendbyte)
209 tpm_data_out(sendbyte,
WRFIFO);
220 static void tpm_wtx(
struct tpm_chip *chip)
223 dev_info(chip->
dev,
"Granting WTX (%02d / %02d)\n",
227 wait_and_send(chip, 0x00);
228 wait_and_send(chip, 0x00);
232 static void tpm_wtx_abort(
struct tpm_chip *chip)
237 wait_and_send(chip, 0x00);
238 wait_and_send(chip, 0x00);
252 for (i = 0; i < 4; i++) {
261 "Wrong transport protocol implementation!\n");
267 size = ((buf[2] << 8) | buf[3]);
269 for (i = 0; i <
size; i++) {
274 if ((size == 0x6D00) && (buf[1] == 0x80)) {
275 dev_err(chip->
dev,
"Error handling on vendor layer!\n");
279 for (i = 0; i <
size; i++)
303 dev_err(chip->
dev,
"ERROR-package received:\n");
306 "-> Negative acknowledgement"
307 " - retransmit command!\n");
313 static int tpm_inf_send(
struct tpm_chip *chip,
u8 * buf,
size_t count)
317 u8 count_high, count_low, count_4, count_3, count_2, count_1;
322 ret = empty_fifo(chip, 1);
324 dev_err(chip->
dev,
"Timeout while clearing FIFO\n");
332 count_4 = (count & 0xff000000) >> 24;
333 count_3 = (count & 0x00ff0000) >> 16;
334 count_2 = (count & 0x0000ff00) >> 8;
335 count_1 = (count & 0x000000ff);
336 count_high = ((count + 6) & 0xffffff00) >> 8;
337 count_low = ((count + 6) & 0x000000ff);
342 wait_and_send(chip, count_high);
343 wait_and_send(chip, count_low);
348 wait_and_send(chip, count_4);
349 wait_and_send(chip, count_3);
350 wait_and_send(chip, count_2);
351 wait_and_send(chip, count_1);
354 for (i = 0; i <
count; i++) {
355 wait_and_send(chip, buf[i]);
360 static void tpm_inf_cancel(
struct tpm_chip *chip)
369 static u8 tpm_inf_status(
struct tpm_chip *chip)
371 return tpm_data_in(
STAT);
380 &dev_attr_pubek.attr,
383 &dev_attr_cancel.attr,
399 .recv = tpm_inf_recv,
400 .send = tpm_inf_send,
401 .cancel = tpm_inf_cancel,
402 .status = tpm_inf_status,
403 .req_complete_mask = 0,
404 .req_complete_val = 0,
405 .attr_group = &inf_attr_grp,
406 .miscdev = {.fops = &inf_ops,},
430 if (pnp_port_valid(dev, 0) && pnp_port_valid(dev, 1) &&
435 tpm_dev.config_port = pnp_port_start(dev, 0);
436 tpm_dev.config_size = pnp_port_len(dev, 0);
437 tpm_dev.data_regs = pnp_port_start(dev, 1);
438 tpm_dev.data_size = pnp_port_len(dev, 1);
439 if ((tpm_dev.data_size < 4) || (tpm_dev.config_size < 2)) {
445 if (!((tpm_dev.data_regs >> 8) & 0xff)) {
451 "tpm_infineon0") ==
NULL) {
456 "tpm_infineon0") ==
NULL) {
461 }
else if (pnp_mem_valid(dev, 0) &&
466 tpm_dev.map_base = pnp_mem_start(dev, 0);
467 tpm_dev.map_size = pnp_mem_len(dev, 0);
474 "tpm_infineon0") ==
NULL) {
479 tpm_dev.mem_base =
ioremap(tpm_dev.map_base, tpm_dev.map_size);
480 if (tpm_dev.mem_base ==
NULL) {
494 tpm_dev.data_regs = 0x0;
515 switch ((productid[0] << 8) | productid[1]) {
517 snprintf(chipname,
sizeof(chipname),
" (SLD 9630 TT 1.1)");
520 snprintf(chipname,
sizeof(chipname),
" (SLB 9635 TT 1.2)");
523 snprintf(chipname,
sizeof(chipname),
" (unknown chip)");
531 tpm_config_out((tpm_dev.data_regs >> 8) & 0xff,
TPM_INF_DATA);
533 tpm_config_out((tpm_dev.data_regs & 0xff),
TPM_INF_DATA);
541 if ((ioh << 8 | iol) != tpm_dev.data_regs) {
543 "Could not set IO-data registers to 0x%x\n",
546 goto err_release_region;
559 "config base 0x%lx, "
561 "chip version 0x%02x%02x, "
562 "vendor id 0x%x%x (Infineon), "
563 "product id 0x%02x%02x"
566 tpm_dev.config_port :
567 tpm_dev.map_base + tpm_dev.index_off,
570 tpm_dev.map_base + tpm_dev.data_regs,
571 version[0], version[1],
572 vendorid[0], vendorid[1],
573 productid[0], productid[1], chipname);
576 goto err_release_region;
581 goto err_release_region;
599 struct tpm_chip *chip = pnp_get_drvdata(dev);
605 tpm_dev.config_size);
617 struct tpm_chip *chip = pnp_get_drvdata(dev);
626 rc = tpm_inf_send(chip, savestate,
sizeof(savestate));
628 dev_err(&dev->
dev,
"error while saving TPM state\n");
635 static int tpm_inf_pnp_resume(
struct pnp_dev *dev)
640 tpm_config_out((tpm_dev.data_regs >> 8) & 0xff,
TPM_INF_DATA);
642 tpm_config_out((tpm_dev.data_regs & 0xff),
TPM_INF_DATA);
652 static struct pnp_driver tpm_inf_pnp_driver = {
653 .name =
"tpm_inf_pnp",
654 .id_table = tpm_inf_pnp_tbl,
655 .probe = tpm_inf_pnp_probe,
656 .suspend = tpm_inf_pnp_suspend,
657 .resume = tpm_inf_pnp_resume,
661 static int __init init_inf(
void)
666 static void __exit cleanup_inf(
void)