[PATCH] tpm: updates for new hardware
[linux-2.6/openmoko-kernel/knife-kernel.git] / drivers / char / tpm / tpm_atmel.h
blob3c5b9a8d1c497d66bba68ec66f9ace9670d0ac42
1 /*
2 * Copyright (C) 2005 IBM Corporation
4 * Authors:
5 * Kylene Hall <kjhall@us.ibm.com>
7 * Maintained by: <tpmdd_devel@lists.sourceforge.net>
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
15 * License.
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 #ifdef CONFIG_PPC64
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(struct tpm_vendor_specific *vendor)
32 iounmap(vendor->iobase);
35 static int atmel_get_base_addr(struct tpm_vendor_specific *vendor)
37 struct device_node *dn;
38 unsigned long address, size;
39 unsigned int *reg;
40 int reglen;
41 int naddrc;
42 int nsizec;
44 dn = of_find_node_by_name(NULL, "tpm");
46 if (!dn)
47 return 1;
49 if (!device_is_compatible(dn, "AT97SC3201")) {
50 of_node_put(dn);
51 return 1;
54 reg = (unsigned int *) get_property(dn, "reg", &reglen);
55 naddrc = prom_n_addr_cells(dn);
56 nsizec = prom_n_size_cells(dn);
58 of_node_put(dn);
61 if (naddrc == 2)
62 address = ((unsigned long) reg[0] << 32) | reg[1];
63 else
64 address = reg[0];
66 if (nsizec == 2)
67 size =
68 ((unsigned long) reg[naddrc] << 32) | reg[naddrc + 1];
69 else
70 size = reg[naddrc];
72 vendor->base = address;
73 vendor->region_size = size;
74 vendor->iobase = ioremap(address, size);
75 return 0;
77 #else
78 #define atmel_getb(chip, offset) inb(chip->vendor->base + offset)
79 #define atmel_putb(val, chip, offset) outb(val, chip->vendor->base + offset)
80 #define atmel_request_region request_region
81 #define atmel_release_region release_region
82 /* Atmel definitions */
83 enum tpm_atmel_addr {
84 TPM_ATMEL_BASE_ADDR_LO = 0x08,
85 TPM_ATMEL_BASE_ADDR_HI = 0x09
88 /* Verify this is a 1.1 Atmel TPM */
89 static int atmel_verify_tpm11(void)
92 /* verify that it is an Atmel part */
93 if (tpm_read_index(TPM_ADDR, 4) != 'A' ||
94 tpm_read_index(TPM_ADDR, 5) != 'T' ||
95 tpm_read_index(TPM_ADDR, 6) != 'M' ||
96 tpm_read_index(TPM_ADDR, 7) != 'L')
97 return 1;
99 /* query chip for its version number */
100 if (tpm_read_index(TPM_ADDR, 0x00) != 1 ||
101 tpm_read_index(TPM_ADDR, 0x01) != 1)
102 return 1;
104 /* This is an atmel supported part */
105 return 0;
108 static inline void atmel_put_base_addr(struct tpm_vendor_specific *vendor)
112 /* Determine where to talk to device */
113 static unsigned long atmel_get_base_addr(struct tpm_vendor_specific
114 *vendor)
116 int lo, hi;
118 if (atmel_verify_tpm11() != 0)
119 return 1;
121 lo = tpm_read_index(TPM_ADDR, TPM_ATMEL_BASE_ADDR_LO);
122 hi = tpm_read_index(TPM_ADDR, TPM_ATMEL_BASE_ADDR_HI);
124 vendor->base = (hi << 8) | lo;
125 vendor->region_size = 2;
127 return 0;
129 #endif