2 * Copyright (C) 2005 IBM Corporation
9 * Device driver for TCG/TCPA TPM (trusted platform module).
10 * Specifications at www.trustedcomputinggroup.org
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
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.
25 struct tpm_atmel_priv {
36 #define atmel_getb(priv, offset) readb(priv->iobase + offset)
37 #define atmel_putb(val, priv, offset) writeb(val, priv->iobase + offset)
38 #define atmel_request_region request_mem_region
39 #define atmel_release_region release_mem_region
41 static inline void atmel_put_base_addr(void __iomem *iobase)
46 static void __iomem * atmel_get_base_addr(unsigned long *base, int *region_size)
48 struct device_node *dn;
49 unsigned long address, size;
50 const unsigned int *reg;
55 dn = of_find_node_by_name(NULL, "tpm");
60 if (!of_device_is_compatible(dn, "AT97SC3201")) {
65 reg = of_get_property(dn, "reg", ®len);
66 naddrc = of_n_addr_cells(dn);
67 nsizec = of_n_size_cells(dn);
73 address = ((unsigned long) reg[0] << 32) | reg[1];
79 ((unsigned long) reg[naddrc] << 32) | reg[naddrc + 1];
85 return ioremap(*base, *region_size);
88 #define atmel_getb(chip, offset) inb(atmel_get_priv(chip)->base + offset)
89 #define atmel_putb(val, chip, offset) \
90 outb(val, atmel_get_priv(chip)->base + offset)
91 #define atmel_request_region request_region
92 #define atmel_release_region release_region
93 /* Atmel definitions */
95 TPM_ATMEL_BASE_ADDR_LO = 0x08,
96 TPM_ATMEL_BASE_ADDR_HI = 0x09
99 static inline int tpm_read_index(int base, int index)
102 return inb(base+1) & 0xFF;
105 /* Verify this is a 1.1 Atmel TPM */
106 static int atmel_verify_tpm11(void)
109 /* verify that it is an Atmel part */
110 if (tpm_read_index(TPM_ADDR, 4) != 'A' ||
111 tpm_read_index(TPM_ADDR, 5) != 'T' ||
112 tpm_read_index(TPM_ADDR, 6) != 'M' ||
113 tpm_read_index(TPM_ADDR, 7) != 'L')
116 /* query chip for its version number */
117 if (tpm_read_index(TPM_ADDR, 0x00) != 1 ||
118 tpm_read_index(TPM_ADDR, 0x01) != 1)
121 /* This is an atmel supported part */
125 static inline void atmel_put_base_addr(void __iomem *iobase)
129 /* Determine where to talk to device */
130 static void __iomem * atmel_get_base_addr(unsigned long *base, int *region_size)
134 if (atmel_verify_tpm11() != 0)
137 lo = tpm_read_index(TPM_ADDR, TPM_ATMEL_BASE_ADDR_LO);
138 hi = tpm_read_index(TPM_ADDR, TPM_ATMEL_BASE_ADDR_HI);
140 *base = (hi << 8) | lo;
143 return ioport_map(*base, *region_size);