tpm_atmel.h 3.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140
  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. struct tpm_atmel_priv {
  25. int region_size;
  26. int have_region;
  27. unsigned long base;
  28. void __iomem *iobase;
  29. };
  30. #ifdef CONFIG_PPC64
  31. #include <asm/prom.h>
  32. #define atmel_getb(priv, offset) readb(priv->iobase + offset)
  33. #define atmel_putb(val, priv, offset) writeb(val, priv->iobase + offset)
  34. #define atmel_request_region request_mem_region
  35. #define atmel_release_region release_mem_region
  36. static inline void atmel_put_base_addr(void __iomem *iobase)
  37. {
  38. iounmap(iobase);
  39. }
  40. static void __iomem * atmel_get_base_addr(unsigned long *base, int *region_size)
  41. {
  42. struct device_node *dn;
  43. unsigned long address, size;
  44. const unsigned int *reg;
  45. int reglen;
  46. int naddrc;
  47. int nsizec;
  48. dn = of_find_node_by_name(NULL, "tpm");
  49. if (!dn)
  50. return NULL;
  51. if (!of_device_is_compatible(dn, "AT97SC3201")) {
  52. of_node_put(dn);
  53. return NULL;
  54. }
  55. reg = of_get_property(dn, "reg", &reglen);
  56. naddrc = of_n_addr_cells(dn);
  57. nsizec = of_n_size_cells(dn);
  58. of_node_put(dn);
  59. if (naddrc == 2)
  60. address = ((unsigned long) reg[0] << 32) | reg[1];
  61. else
  62. address = reg[0];
  63. if (nsizec == 2)
  64. size =
  65. ((unsigned long) reg[naddrc] << 32) | reg[naddrc + 1];
  66. else
  67. size = reg[naddrc];
  68. *base = address;
  69. *region_size = size;
  70. return ioremap(*base, *region_size);
  71. }
  72. #else
  73. #define atmel_getb(chip, offset) inb(atmel_get_priv(chip)->base + offset)
  74. #define atmel_putb(val, chip, offset) \
  75. outb(val, atmel_get_priv(chip)->base + offset)
  76. #define atmel_request_region request_region
  77. #define atmel_release_region release_region
  78. /* Atmel definitions */
  79. enum tpm_atmel_addr {
  80. TPM_ATMEL_BASE_ADDR_LO = 0x08,
  81. TPM_ATMEL_BASE_ADDR_HI = 0x09
  82. };
  83. /* Verify this is a 1.1 Atmel TPM */
  84. static int atmel_verify_tpm11(void)
  85. {
  86. /* verify that it is an Atmel part */
  87. if (tpm_read_index(TPM_ADDR, 4) != 'A' ||
  88. tpm_read_index(TPM_ADDR, 5) != 'T' ||
  89. tpm_read_index(TPM_ADDR, 6) != 'M' ||
  90. tpm_read_index(TPM_ADDR, 7) != 'L')
  91. return 1;
  92. /* query chip for its version number */
  93. if (tpm_read_index(TPM_ADDR, 0x00) != 1 ||
  94. tpm_read_index(TPM_ADDR, 0x01) != 1)
  95. return 1;
  96. /* This is an atmel supported part */
  97. return 0;
  98. }
  99. static inline void atmel_put_base_addr(void __iomem *iobase)
  100. {
  101. }
  102. /* Determine where to talk to device */
  103. static void __iomem * atmel_get_base_addr(unsigned long *base, int *region_size)
  104. {
  105. int lo, hi;
  106. if (atmel_verify_tpm11() != 0)
  107. return NULL;
  108. lo = tpm_read_index(TPM_ADDR, TPM_ATMEL_BASE_ADDR_LO);
  109. hi = tpm_read_index(TPM_ADDR, TPM_ATMEL_BASE_ADDR_HI);
  110. *base = (hi << 8) | lo;
  111. *region_size = 2;
  112. return ioport_map(*base, *region_size);
  113. }
  114. #endif