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