tpm_atmel.h 3.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131
  1. /*
  2. * Copyright (C) 2005 IBM Corporation
  3. *
  4. * Authors:
  5. * Kylene Hall <kjhall@us.ibm.com>
  6. *
  7. * Maintained by: <tpmdd-devel@lists.sourceforge.net>
  8. *
  9. * Device driver for TCG/TCPA TPM (trusted platform module).
  10. * Specifications at www.trustedcomputinggroup.org
  11. *
  12. * This program is free software; you can redistribute it and/or
  13. * modify it under the terms of the GNU General Public License as
  14. * published by the Free Software Foundation, version 2 of the
  15. * License.
  16. *
  17. * These difference are required on power because the device must be
  18. * discovered through the device tree and iomap must be used to get
  19. * around the need for holes in the io_page_mask. This does not happen
  20. * automatically because the tpm is not a normal pci device and lives
  21. * under the root node.
  22. *
  23. */
  24. #ifdef CONFIG_PPC64
  25. #include <asm/prom.h>
  26. #define atmel_getb(chip, offset) readb(chip->vendor->iobase + offset);
  27. #define atmel_putb(val, chip, offset) writeb(val, chip->vendor->iobase + offset)
  28. #define atmel_request_region request_mem_region
  29. #define atmel_release_region release_mem_region
  30. static inline void atmel_put_base_addr(void __iomem *iobase)
  31. {
  32. iounmap(iobase);
  33. }
  34. static void __iomem * atmel_get_base_addr(unsigned long *base, int *region_size)
  35. {
  36. struct device_node *dn;
  37. unsigned long address, size;
  38. const unsigned int *reg;
  39. int reglen;
  40. int naddrc;
  41. int nsizec;
  42. dn = of_find_node_by_name(NULL, "tpm");
  43. if (!dn)
  44. return NULL;
  45. if (!of_device_is_compatible(dn, "AT97SC3201")) {
  46. of_node_put(dn);
  47. return NULL;
  48. }
  49. reg = of_get_property(dn, "reg", &reglen);
  50. naddrc = of_n_addr_cells(dn);
  51. nsizec = of_n_size_cells(dn);
  52. of_node_put(dn);
  53. if (naddrc == 2)
  54. address = ((unsigned long) reg[0] << 32) | reg[1];
  55. else
  56. address = reg[0];
  57. if (nsizec == 2)
  58. size =
  59. ((unsigned long) reg[naddrc] << 32) | reg[naddrc + 1];
  60. else
  61. size = reg[naddrc];
  62. *base = address;
  63. *region_size = size;
  64. return ioremap(*base, *region_size);
  65. }
  66. #else
  67. #define atmel_getb(chip, offset) inb(chip->vendor->base + offset)
  68. #define atmel_putb(val, chip, offset) outb(val, chip->vendor->base + offset)
  69. #define atmel_request_region request_region
  70. #define atmel_release_region release_region
  71. /* Atmel definitions */
  72. enum tpm_atmel_addr {
  73. TPM_ATMEL_BASE_ADDR_LO = 0x08,
  74. TPM_ATMEL_BASE_ADDR_HI = 0x09
  75. };
  76. /* Verify this is a 1.1 Atmel TPM */
  77. static int atmel_verify_tpm11(void)
  78. {
  79. /* verify that it is an Atmel part */
  80. if (tpm_read_index(TPM_ADDR, 4) != 'A' ||
  81. tpm_read_index(TPM_ADDR, 5) != 'T' ||
  82. tpm_read_index(TPM_ADDR, 6) != 'M' ||
  83. tpm_read_index(TPM_ADDR, 7) != 'L')
  84. return 1;
  85. /* query chip for its version number */
  86. if (tpm_read_index(TPM_ADDR, 0x00) != 1 ||
  87. tpm_read_index(TPM_ADDR, 0x01) != 1)
  88. return 1;
  89. /* This is an atmel supported part */
  90. return 0;
  91. }
  92. static inline void atmel_put_base_addr(void __iomem *iobase)
  93. {
  94. }
  95. /* Determine where to talk to device */
  96. static void __iomem * atmel_get_base_addr(unsigned long *base, int *region_size)
  97. {
  98. int lo, hi;
  99. if (atmel_verify_tpm11() != 0)
  100. return NULL;
  101. lo = tpm_read_index(TPM_ADDR, TPM_ATMEL_BASE_ADDR_LO);
  102. hi = tpm_read_index(TPM_ADDR, TPM_ATMEL_BASE_ADDR_HI);
  103. *base = (hi << 8) | lo;
  104. *region_size = 2;
  105. return ioport_map(*base, *region_size);
  106. }
  107. #endif