1ad5ea3ccSKylene Jo Hall /* 2ad5ea3ccSKylene Jo Hall * Copyright (C) 2005 IBM Corporation 3ad5ea3ccSKylene Jo Hall * 4ad5ea3ccSKylene Jo Hall * Authors: 5ad5ea3ccSKylene Jo Hall * Kylene Hall <kjhall@us.ibm.com> 6ad5ea3ccSKylene Jo Hall * 7ad5ea3ccSKylene Jo Hall * Maintained by: <tpmdd_devel@lists.sourceforge.net> 8ad5ea3ccSKylene Jo Hall * 9ad5ea3ccSKylene Jo Hall * Device driver for TCG/TCPA TPM (trusted platform module). 10ad5ea3ccSKylene Jo Hall * Specifications at www.trustedcomputinggroup.org 11ad5ea3ccSKylene Jo Hall * 12ad5ea3ccSKylene Jo Hall * This program is free software; you can redistribute it and/or 13ad5ea3ccSKylene Jo Hall * modify it under the terms of the GNU General Public License as 14ad5ea3ccSKylene Jo Hall * published by the Free Software Foundation, version 2 of the 15ad5ea3ccSKylene Jo Hall * License. 16ad5ea3ccSKylene Jo Hall * 17ad5ea3ccSKylene Jo Hall * These difference are required on power because the device must be 18ad5ea3ccSKylene Jo Hall * discovered through the device tree and iomap must be used to get 19ad5ea3ccSKylene Jo Hall * around the need for holes in the io_page_mask. This does not happen 20ad5ea3ccSKylene Jo Hall * automatically because the tpm is not a normal pci device and lives 21ad5ea3ccSKylene Jo Hall * under the root node. 22ad5ea3ccSKylene Jo Hall * 23ad5ea3ccSKylene Jo Hall */ 24ad5ea3ccSKylene Jo Hall 25ad5ea3ccSKylene Jo Hall #ifdef CONFIG_PPC64 26ad5ea3ccSKylene Jo Hall #define atmel_getb(chip, offset) readb(chip->vendor->iobase + offset); 27ad5ea3ccSKylene Jo Hall #define atmel_putb(val, chip, offset) writeb(val, chip->vendor->iobase + offset) 28ad5ea3ccSKylene Jo Hall #define atmel_request_region request_mem_region 29ad5ea3ccSKylene Jo Hall #define atmel_release_region release_mem_region 30*90612b30SKylene Jo Hall 31*90612b30SKylene Jo Hall static inline void atmel_put_base_addr(struct tpm_vendor_specific 32*90612b30SKylene Jo Hall *vendor) 33ad5ea3ccSKylene Jo Hall { 34ad5ea3ccSKylene Jo Hall iounmap(vendor->iobase); 35ad5ea3ccSKylene Jo Hall } 36ad5ea3ccSKylene Jo Hall 37*90612b30SKylene Jo Hall static void __iomem * atmel_get_base_addr(struct tpm_vendor_specific *vendor) 38ad5ea3ccSKylene Jo Hall { 39ad5ea3ccSKylene Jo Hall struct device_node *dn; 40ad5ea3ccSKylene Jo Hall unsigned long address, size; 41ad5ea3ccSKylene Jo Hall unsigned int *reg; 42ad5ea3ccSKylene Jo Hall int reglen; 43ad5ea3ccSKylene Jo Hall int naddrc; 44ad5ea3ccSKylene Jo Hall int nsizec; 45ad5ea3ccSKylene Jo Hall 46ad5ea3ccSKylene Jo Hall dn = of_find_node_by_name(NULL, "tpm"); 47ad5ea3ccSKylene Jo Hall 48ad5ea3ccSKylene Jo Hall if (!dn) 49*90612b30SKylene Jo Hall return NULL; 50ad5ea3ccSKylene Jo Hall 51ad5ea3ccSKylene Jo Hall if (!device_is_compatible(dn, "AT97SC3201")) { 52ad5ea3ccSKylene Jo Hall of_node_put(dn); 53*90612b30SKylene Jo Hall return NULL; 54ad5ea3ccSKylene Jo Hall } 55ad5ea3ccSKylene Jo Hall 56ad5ea3ccSKylene Jo Hall reg = (unsigned int *) get_property(dn, "reg", ®len); 57ad5ea3ccSKylene Jo Hall naddrc = prom_n_addr_cells(dn); 58ad5ea3ccSKylene Jo Hall nsizec = prom_n_size_cells(dn); 59ad5ea3ccSKylene Jo Hall 60ad5ea3ccSKylene Jo Hall of_node_put(dn); 61ad5ea3ccSKylene Jo Hall 62ad5ea3ccSKylene Jo Hall 63ad5ea3ccSKylene Jo Hall if (naddrc == 2) 64ad5ea3ccSKylene Jo Hall address = ((unsigned long) reg[0] << 32) | reg[1]; 65ad5ea3ccSKylene Jo Hall else 66ad5ea3ccSKylene Jo Hall address = reg[0]; 67ad5ea3ccSKylene Jo Hall 68ad5ea3ccSKylene Jo Hall if (nsizec == 2) 69ad5ea3ccSKylene Jo Hall size = 70ad5ea3ccSKylene Jo Hall ((unsigned long) reg[naddrc] << 32) | reg[naddrc + 1]; 71ad5ea3ccSKylene Jo Hall else 72ad5ea3ccSKylene Jo Hall size = reg[naddrc]; 73ad5ea3ccSKylene Jo Hall 74ad5ea3ccSKylene Jo Hall vendor->base = address; 75ad5ea3ccSKylene Jo Hall vendor->region_size = size; 76*90612b30SKylene Jo Hall return ioremap(vendor->base, vendor->region_size); 77ad5ea3ccSKylene Jo Hall } 78ad5ea3ccSKylene Jo Hall #else 79ad5ea3ccSKylene Jo Hall #define atmel_getb(chip, offset) inb(chip->vendor->base + offset) 80ad5ea3ccSKylene Jo Hall #define atmel_putb(val, chip, offset) outb(val, chip->vendor->base + offset) 81ad5ea3ccSKylene Jo Hall #define atmel_request_region request_region 82ad5ea3ccSKylene Jo Hall #define atmel_release_region release_region 83ad5ea3ccSKylene Jo Hall /* Atmel definitions */ 84ad5ea3ccSKylene Jo Hall enum tpm_atmel_addr { 85ad5ea3ccSKylene Jo Hall TPM_ATMEL_BASE_ADDR_LO = 0x08, 86ad5ea3ccSKylene Jo Hall TPM_ATMEL_BASE_ADDR_HI = 0x09 87ad5ea3ccSKylene Jo Hall }; 88ad5ea3ccSKylene Jo Hall 89ad5ea3ccSKylene Jo Hall /* Verify this is a 1.1 Atmel TPM */ 90ad5ea3ccSKylene Jo Hall static int atmel_verify_tpm11(void) 91ad5ea3ccSKylene Jo Hall { 92ad5ea3ccSKylene Jo Hall 93ad5ea3ccSKylene Jo Hall /* verify that it is an Atmel part */ 94ad5ea3ccSKylene Jo Hall if (tpm_read_index(TPM_ADDR, 4) != 'A' || 95ad5ea3ccSKylene Jo Hall tpm_read_index(TPM_ADDR, 5) != 'T' || 96ad5ea3ccSKylene Jo Hall tpm_read_index(TPM_ADDR, 6) != 'M' || 97ad5ea3ccSKylene Jo Hall tpm_read_index(TPM_ADDR, 7) != 'L') 98ad5ea3ccSKylene Jo Hall return 1; 99ad5ea3ccSKylene Jo Hall 100ad5ea3ccSKylene Jo Hall /* query chip for its version number */ 101ad5ea3ccSKylene Jo Hall if (tpm_read_index(TPM_ADDR, 0x00) != 1 || 102ad5ea3ccSKylene Jo Hall tpm_read_index(TPM_ADDR, 0x01) != 1) 103ad5ea3ccSKylene Jo Hall return 1; 104ad5ea3ccSKylene Jo Hall 105ad5ea3ccSKylene Jo Hall /* This is an atmel supported part */ 106ad5ea3ccSKylene Jo Hall return 0; 107ad5ea3ccSKylene Jo Hall } 108ad5ea3ccSKylene Jo Hall 109*90612b30SKylene Jo Hall static inline void atmel_put_base_addr(struct tpm_vendor_specific 110*90612b30SKylene Jo Hall *vendor) 111ad5ea3ccSKylene Jo Hall { 112ad5ea3ccSKylene Jo Hall } 113ad5ea3ccSKylene Jo Hall 114ad5ea3ccSKylene Jo Hall /* Determine where to talk to device */ 115*90612b30SKylene Jo Hall static void __iomem * atmel_get_base_addr(struct tpm_vendor_specific 116ad5ea3ccSKylene Jo Hall *vendor) 117ad5ea3ccSKylene Jo Hall { 118ad5ea3ccSKylene Jo Hall int lo, hi; 119ad5ea3ccSKylene Jo Hall 120ad5ea3ccSKylene Jo Hall if (atmel_verify_tpm11() != 0) 121*90612b30SKylene Jo Hall return NULL; 122ad5ea3ccSKylene Jo Hall 123ad5ea3ccSKylene Jo Hall lo = tpm_read_index(TPM_ADDR, TPM_ATMEL_BASE_ADDR_LO); 124ad5ea3ccSKylene Jo Hall hi = tpm_read_index(TPM_ADDR, TPM_ATMEL_BASE_ADDR_HI); 125ad5ea3ccSKylene Jo Hall 126ad5ea3ccSKylene Jo Hall vendor->base = (hi << 8) | lo; 127ad5ea3ccSKylene Jo Hall vendor->region_size = 2; 128ad5ea3ccSKylene Jo Hall 129*90612b30SKylene Jo Hall return ioport_map(vendor->base, vendor->region_size); 130ad5ea3ccSKylene Jo Hall } 131ad5ea3ccSKylene Jo Hall #endif 132