Merge tag 'scsi-fixes' of git://git.kernel.org/pub/scm/linux/kernel/git/jejb/scsi
[linux/fpc-iii.git] / drivers / char / tpm / tpm_atmel.h
blobba37e77e8af349554b9a924d0b786fcd048831b7
1 /* SPDX-License-Identifier: GPL-2.0-only */
2 /*
3 * Copyright (C) 2005 IBM Corporation
5 * Authors:
6 * Kylene Hall <kjhall@us.ibm.com>
8 * Maintained by: <tpmdd-devel@lists.sourceforge.net>
10 * Device driver for TCG/TCPA TPM (trusted platform module).
11 * Specifications at www.trustedcomputinggroup.org
13 * These difference are required on power because the device must be
14 * discovered through the device tree and iomap must be used to get
15 * around the need for holes in the io_page_mask. This does not happen
16 * automatically because the tpm is not a normal pci device and lives
17 * under the root node.
20 struct tpm_atmel_priv {
21 int region_size;
22 int have_region;
23 unsigned long base;
24 void __iomem *iobase;
27 #ifdef CONFIG_PPC64
29 #include <asm/prom.h>
31 #define atmel_getb(priv, offset) readb(priv->iobase + offset)
32 #define atmel_putb(val, priv, offset) writeb(val, priv->iobase + offset)
33 #define atmel_request_region request_mem_region
34 #define atmel_release_region release_mem_region
36 static inline void atmel_put_base_addr(void __iomem *iobase)
38 iounmap(iobase);
41 static void __iomem * atmel_get_base_addr(unsigned long *base, int *region_size)
43 struct device_node *dn;
44 unsigned long address, size;
45 const unsigned int *reg;
46 int reglen;
47 int naddrc;
48 int nsizec;
50 dn = of_find_node_by_name(NULL, "tpm");
52 if (!dn)
53 return NULL;
55 if (!of_device_is_compatible(dn, "AT97SC3201")) {
56 of_node_put(dn);
57 return NULL;
60 reg = of_get_property(dn, "reg", &reglen);
61 naddrc = of_n_addr_cells(dn);
62 nsizec = of_n_size_cells(dn);
64 of_node_put(dn);
67 if (naddrc == 2)
68 address = ((unsigned long) reg[0] << 32) | reg[1];
69 else
70 address = reg[0];
72 if (nsizec == 2)
73 size =
74 ((unsigned long) reg[naddrc] << 32) | reg[naddrc + 1];
75 else
76 size = reg[naddrc];
78 *base = address;
79 *region_size = size;
80 return ioremap(*base, *region_size);
82 #else
83 #define atmel_getb(chip, offset) inb(atmel_get_priv(chip)->base + offset)
84 #define atmel_putb(val, chip, offset) \
85 outb(val, atmel_get_priv(chip)->base + offset)
86 #define atmel_request_region request_region
87 #define atmel_release_region release_region
88 /* Atmel definitions */
89 enum tpm_atmel_addr {
90 TPM_ATMEL_BASE_ADDR_LO = 0x08,
91 TPM_ATMEL_BASE_ADDR_HI = 0x09
94 static inline int tpm_read_index(int base, int index)
96 outb(index, base);
97 return inb(base+1) & 0xFF;
100 /* Verify this is a 1.1 Atmel TPM */
101 static int atmel_verify_tpm11(void)
104 /* verify that it is an Atmel part */
105 if (tpm_read_index(TPM_ADDR, 4) != 'A' ||
106 tpm_read_index(TPM_ADDR, 5) != 'T' ||
107 tpm_read_index(TPM_ADDR, 6) != 'M' ||
108 tpm_read_index(TPM_ADDR, 7) != 'L')
109 return 1;
111 /* query chip for its version number */
112 if (tpm_read_index(TPM_ADDR, 0x00) != 1 ||
113 tpm_read_index(TPM_ADDR, 0x01) != 1)
114 return 1;
116 /* This is an atmel supported part */
117 return 0;
120 static inline void atmel_put_base_addr(void __iomem *iobase)
124 /* Determine where to talk to device */
125 static void __iomem * atmel_get_base_addr(unsigned long *base, int *region_size)
127 int lo, hi;
129 if (atmel_verify_tpm11() != 0)
130 return NULL;
132 lo = tpm_read_index(TPM_ADDR, TPM_ATMEL_BASE_ADDR_LO);
133 hi = tpm_read_index(TPM_ADDR, TPM_ATMEL_BASE_ADDR_HI);
135 *base = (hi << 8) | lo;
136 *region_size = 2;
138 return ioport_map(*base, *region_size);
140 #endif