blob: d3478aaadd77a20b24db39f668ea1efb1f826f1c [file] [log] [blame]
Kylene Jo Hallad5ea3c2005-11-13 16:07:41 -08001/*
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
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
Kylene Jo Hall90612b32005-11-18 01:10:58 -080030
31static inline void atmel_put_base_addr(struct tpm_vendor_specific
32 *vendor)
Kylene Jo Hallad5ea3c2005-11-13 16:07:41 -080033{
34 iounmap(vendor->iobase);
35}
36
Kylene Jo Hall90612b32005-11-18 01:10:58 -080037static void __iomem * atmel_get_base_addr(struct tpm_vendor_specific *vendor)
Kylene Jo Hallad5ea3c2005-11-13 16:07:41 -080038{
39 struct device_node *dn;
40 unsigned long address, size;
41 unsigned int *reg;
42 int reglen;
43 int naddrc;
44 int nsizec;
45
46 dn = of_find_node_by_name(NULL, "tpm");
47
48 if (!dn)
Kylene Jo Hall90612b32005-11-18 01:10:58 -080049 return NULL;
Kylene Jo Hallad5ea3c2005-11-13 16:07:41 -080050
51 if (!device_is_compatible(dn, "AT97SC3201")) {
52 of_node_put(dn);
Kylene Jo Hall90612b32005-11-18 01:10:58 -080053 return NULL;
Kylene Jo Hallad5ea3c2005-11-13 16:07:41 -080054 }
55
56 reg = (unsigned int *) get_property(dn, "reg", &reglen);
57 naddrc = prom_n_addr_cells(dn);
58 nsizec = prom_n_size_cells(dn);
59
60 of_node_put(dn);
61
62
63 if (naddrc == 2)
64 address = ((unsigned long) reg[0] << 32) | reg[1];
65 else
66 address = reg[0];
67
68 if (nsizec == 2)
69 size =
70 ((unsigned long) reg[naddrc] << 32) | reg[naddrc + 1];
71 else
72 size = reg[naddrc];
73
74 vendor->base = address;
75 vendor->region_size = size;
Kylene Jo Hall90612b32005-11-18 01:10:58 -080076 return ioremap(vendor->base, vendor->region_size);
Kylene Jo Hallad5ea3c2005-11-13 16:07:41 -080077}
78#else
79#define atmel_getb(chip, offset) inb(chip->vendor->base + offset)
80#define atmel_putb(val, chip, offset) outb(val, chip->vendor->base + offset)
81#define atmel_request_region request_region
82#define atmel_release_region release_region
83/* Atmel definitions */
84enum tpm_atmel_addr {
85 TPM_ATMEL_BASE_ADDR_LO = 0x08,
86 TPM_ATMEL_BASE_ADDR_HI = 0x09
87};
88
89/* Verify this is a 1.1 Atmel TPM */
90static int atmel_verify_tpm11(void)
91{
92
93 /* verify that it is an Atmel part */
94 if (tpm_read_index(TPM_ADDR, 4) != 'A' ||
95 tpm_read_index(TPM_ADDR, 5) != 'T' ||
96 tpm_read_index(TPM_ADDR, 6) != 'M' ||
97 tpm_read_index(TPM_ADDR, 7) != 'L')
98 return 1;
99
100 /* query chip for its version number */
101 if (tpm_read_index(TPM_ADDR, 0x00) != 1 ||
102 tpm_read_index(TPM_ADDR, 0x01) != 1)
103 return 1;
104
105 /* This is an atmel supported part */
106 return 0;
107}
108
Kylene Jo Hall90612b32005-11-18 01:10:58 -0800109static inline void atmel_put_base_addr(struct tpm_vendor_specific
110 *vendor)
Kylene Jo Hallad5ea3c2005-11-13 16:07:41 -0800111{
112}
113
114/* Determine where to talk to device */
Kylene Jo Hall90612b32005-11-18 01:10:58 -0800115static void __iomem * atmel_get_base_addr(struct tpm_vendor_specific
Kylene Jo Hallad5ea3c2005-11-13 16:07:41 -0800116 *vendor)
117{
118 int lo, hi;
119
120 if (atmel_verify_tpm11() != 0)
Kylene Jo Hall90612b32005-11-18 01:10:58 -0800121 return NULL;
Kylene Jo Hallad5ea3c2005-11-13 16:07:41 -0800122
123 lo = tpm_read_index(TPM_ADDR, TPM_ATMEL_BASE_ADDR_LO);
124 hi = tpm_read_index(TPM_ADDR, TPM_ATMEL_BASE_ADDR_HI);
125
126 vendor->base = (hi << 8) | lo;
127 vendor->region_size = 2;
128
Kylene Jo Hall90612b32005-11-18 01:10:58 -0800129 return ioport_map(vendor->base, vendor->region_size);
Kylene Jo Hallad5ea3c2005-11-13 16:07:41 -0800130}
131#endif