Colin Cross | 73625e3 | 2010-06-23 15:49:17 -0700 | [diff] [blame] | 1 | /* |
| 2 | * arch/arm/mach-tegra/fuse.c |
| 3 | * |
| 4 | * Copyright (C) 2010 Google, Inc. |
| 5 | * |
| 6 | * Author: |
| 7 | * Colin Cross <ccross@android.com> |
| 8 | * |
| 9 | * This software is licensed under the terms of the GNU General Public |
| 10 | * License version 2, as published by the Free Software Foundation, and |
| 11 | * may be copied, distributed, and modified under those terms. |
| 12 | * |
| 13 | * This program is distributed in the hope that it will be useful, |
| 14 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 15 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 16 | * GNU General Public License for more details. |
| 17 | * |
| 18 | */ |
| 19 | |
| 20 | #include <linux/kernel.h> |
| 21 | #include <linux/io.h> |
Linus Torvalds | 3480059 | 2012-03-27 16:41:24 -0700 | [diff] [blame] | 22 | #include <linux/export.h> |
Prashant Gaikwad | c7736ed | 2013-01-11 13:16:19 +0530 | [diff] [blame] | 23 | #include <linux/tegra-soc.h> |
Colin Cross | 73625e3 | 2010-06-23 15:49:17 -0700 | [diff] [blame] | 24 | |
Colin Cross | 73625e3 | 2010-06-23 15:49:17 -0700 | [diff] [blame] | 25 | #include "fuse.h" |
Stephen Warren | 2be39c0 | 2012-10-04 14:24:09 -0600 | [diff] [blame] | 26 | #include "iomap.h" |
Olof Johansson | d262f49 | 2011-10-13 00:14:08 -0700 | [diff] [blame] | 27 | #include "apbio.h" |
Colin Cross | 73625e3 | 2010-06-23 15:49:17 -0700 | [diff] [blame] | 28 | |
| 29 | #define FUSE_UID_LOW 0x108 |
| 30 | #define FUSE_UID_HIGH 0x10c |
| 31 | #define FUSE_SKU_INFO 0x110 |
Danny Huang | 1f851a2 | 2012-11-15 15:42:32 +0800 | [diff] [blame] | 32 | |
| 33 | #define TEGRA20_FUSE_SPARE_BIT 0x200 |
Danny Huang | f8ddda7 | 2012-11-15 15:42:34 +0800 | [diff] [blame] | 34 | #define TEGRA30_FUSE_SPARE_BIT 0x244 |
Colin Cross | 73625e3 | 2010-06-23 15:49:17 -0700 | [diff] [blame] | 35 | |
Olof Johansson | 9a1086d | 2011-10-13 00:31:20 -0700 | [diff] [blame] | 36 | int tegra_sku_id; |
| 37 | int tegra_cpu_process_id; |
| 38 | int tegra_core_process_id; |
Peter De Schrijver | 4c4ad66 | 2012-02-10 01:47:42 +0200 | [diff] [blame] | 39 | int tegra_chip_id; |
Danny Huang | f8ddda7 | 2012-11-15 15:42:34 +0800 | [diff] [blame] | 40 | int tegra_cpu_speedo_id; /* only exist in Tegra30 and later */ |
Danny Huang | 25cd5a3 | 2012-11-15 15:42:33 +0800 | [diff] [blame] | 41 | int tegra_soc_speedo_id; |
Olof Johansson | 9a1086d | 2011-10-13 00:31:20 -0700 | [diff] [blame] | 42 | enum tegra_revision tegra_revision; |
| 43 | |
Danny Huang | 1f851a2 | 2012-11-15 15:42:32 +0800 | [diff] [blame] | 44 | static int tegra_fuse_spare_bit; |
Danny Huang | 25cd5a3 | 2012-11-15 15:42:33 +0800 | [diff] [blame] | 45 | static void (*tegra_init_speedo_data)(void); |
Danny Huang | 1f851a2 | 2012-11-15 15:42:32 +0800 | [diff] [blame] | 46 | |
Olof Johansson | dee4718 | 2011-10-17 16:39:24 -0700 | [diff] [blame] | 47 | /* The BCT to use at boot is specified by board straps that can be read |
| 48 | * through a APB misc register and decoded. 2 bits, i.e. 4 possible BCTs. |
| 49 | */ |
| 50 | int tegra_bct_strapping; |
| 51 | |
| 52 | #define STRAP_OPT 0x008 |
| 53 | #define GMI_AD0 (1 << 4) |
| 54 | #define GMI_AD1 (1 << 5) |
| 55 | #define RAM_ID_MASK (GMI_AD0 | GMI_AD1) |
| 56 | #define RAM_CODE_SHIFT 4 |
| 57 | |
Olof Johansson | 9a1086d | 2011-10-13 00:31:20 -0700 | [diff] [blame] | 58 | static const char *tegra_revision_name[TEGRA_REVISION_MAX] = { |
| 59 | [TEGRA_REVISION_UNKNOWN] = "unknown", |
| 60 | [TEGRA_REVISION_A01] = "A01", |
| 61 | [TEGRA_REVISION_A02] = "A02", |
| 62 | [TEGRA_REVISION_A03] = "A03", |
| 63 | [TEGRA_REVISION_A03p] = "A03 prime", |
| 64 | [TEGRA_REVISION_A04] = "A04", |
| 65 | }; |
| 66 | |
Danny Huang | 1f851a2 | 2012-11-15 15:42:32 +0800 | [diff] [blame] | 67 | u32 tegra_fuse_readl(unsigned long offset) |
Colin Cross | 73625e3 | 2010-06-23 15:49:17 -0700 | [diff] [blame] | 68 | { |
Olof Johansson | d262f49 | 2011-10-13 00:14:08 -0700 | [diff] [blame] | 69 | return tegra_apb_readl(TEGRA_FUSE_BASE + offset); |
Colin Cross | 73625e3 | 2010-06-23 15:49:17 -0700 | [diff] [blame] | 70 | } |
| 71 | |
Danny Huang | 1f851a2 | 2012-11-15 15:42:32 +0800 | [diff] [blame] | 72 | bool tegra_spare_fuse(int bit) |
Colin Cross | 73625e3 | 2010-06-23 15:49:17 -0700 | [diff] [blame] | 73 | { |
Danny Huang | 1f851a2 | 2012-11-15 15:42:32 +0800 | [diff] [blame] | 74 | return tegra_fuse_readl(tegra_fuse_spare_bit + bit * 4); |
Olof Johansson | 9a1086d | 2011-10-13 00:31:20 -0700 | [diff] [blame] | 75 | } |
| 76 | |
Peter De Schrijver | 35b1498 | 2012-02-10 01:47:41 +0200 | [diff] [blame] | 77 | static enum tegra_revision tegra_get_revision(u32 id) |
Olof Johansson | 9a1086d | 2011-10-13 00:31:20 -0700 | [diff] [blame] | 78 | { |
Olof Johansson | 9a1086d | 2011-10-13 00:31:20 -0700 | [diff] [blame] | 79 | u32 minor_rev = (id >> 16) & 0xf; |
Olof Johansson | 9a1086d | 2011-10-13 00:31:20 -0700 | [diff] [blame] | 80 | |
| 81 | switch (minor_rev) { |
| 82 | case 1: |
| 83 | return TEGRA_REVISION_A01; |
| 84 | case 2: |
| 85 | return TEGRA_REVISION_A02; |
| 86 | case 3: |
Peter De Schrijver | 35b1498 | 2012-02-10 01:47:41 +0200 | [diff] [blame] | 87 | if (tegra_chip_id == TEGRA20 && |
Danny Huang | 1f851a2 | 2012-11-15 15:42:32 +0800 | [diff] [blame] | 88 | (tegra_spare_fuse(18) || tegra_spare_fuse(19))) |
Olof Johansson | 9a1086d | 2011-10-13 00:31:20 -0700 | [diff] [blame] | 89 | return TEGRA_REVISION_A03p; |
| 90 | else |
| 91 | return TEGRA_REVISION_A03; |
| 92 | case 4: |
| 93 | return TEGRA_REVISION_A04; |
| 94 | default: |
| 95 | return TEGRA_REVISION_UNKNOWN; |
| 96 | } |
Colin Cross | 73625e3 | 2010-06-23 15:49:17 -0700 | [diff] [blame] | 97 | } |
| 98 | |
Danny Huang | 25cd5a3 | 2012-11-15 15:42:33 +0800 | [diff] [blame] | 99 | static void tegra_get_process_id(void) |
| 100 | { |
| 101 | u32 reg; |
| 102 | |
| 103 | reg = tegra_fuse_readl(tegra_fuse_spare_bit); |
| 104 | tegra_cpu_process_id = (reg >> 6) & 3; |
| 105 | reg = tegra_fuse_readl(tegra_fuse_spare_bit); |
| 106 | tegra_core_process_id = (reg >> 12) & 3; |
| 107 | } |
| 108 | |
Prashant Gaikwad | c7736ed | 2013-01-11 13:16:19 +0530 | [diff] [blame] | 109 | u32 tegra_read_chipid(void) |
| 110 | { |
| 111 | return readl_relaxed(IO_ADDRESS(TEGRA_APB_MISC_BASE) + 0x804); |
| 112 | } |
| 113 | |
Colin Cross | 73625e3 | 2010-06-23 15:49:17 -0700 | [diff] [blame] | 114 | void tegra_init_fuse(void) |
| 115 | { |
Peter De Schrijver | 35b1498 | 2012-02-10 01:47:41 +0200 | [diff] [blame] | 116 | u32 id; |
| 117 | |
Laxman Dewangan | f8e798a | 2012-08-10 18:33:02 +0530 | [diff] [blame] | 118 | u32 reg = readl(IO_ADDRESS(TEGRA_CLK_RESET_BASE + 0x48)); |
Colin Cross | 73625e3 | 2010-06-23 15:49:17 -0700 | [diff] [blame] | 119 | reg |= 1 << 28; |
Laxman Dewangan | f8e798a | 2012-08-10 18:33:02 +0530 | [diff] [blame] | 120 | writel(reg, IO_ADDRESS(TEGRA_CLK_RESET_BASE + 0x48)); |
Colin Cross | 73625e3 | 2010-06-23 15:49:17 -0700 | [diff] [blame] | 121 | |
Olof Johansson | 9a1086d | 2011-10-13 00:31:20 -0700 | [diff] [blame] | 122 | reg = tegra_fuse_readl(FUSE_SKU_INFO); |
| 123 | tegra_sku_id = reg & 0xFF; |
| 124 | |
Olof Johansson | dee4718 | 2011-10-17 16:39:24 -0700 | [diff] [blame] | 125 | reg = tegra_apb_readl(TEGRA_APB_MISC_BASE + STRAP_OPT); |
| 126 | tegra_bct_strapping = (reg & RAM_ID_MASK) >> RAM_CODE_SHIFT; |
| 127 | |
Prashant Gaikwad | c7736ed | 2013-01-11 13:16:19 +0530 | [diff] [blame] | 128 | id = tegra_read_chipid(); |
Peter De Schrijver | 35b1498 | 2012-02-10 01:47:41 +0200 | [diff] [blame] | 129 | tegra_chip_id = (id >> 8) & 0xff; |
| 130 | |
Danny Huang | 25cd5a3 | 2012-11-15 15:42:33 +0800 | [diff] [blame] | 131 | switch (tegra_chip_id) { |
| 132 | case TEGRA20: |
Danny Huang | f8ddda7 | 2012-11-15 15:42:34 +0800 | [diff] [blame] | 133 | tegra_fuse_spare_bit = TEGRA20_FUSE_SPARE_BIT; |
Danny Huang | 25cd5a3 | 2012-11-15 15:42:33 +0800 | [diff] [blame] | 134 | tegra_init_speedo_data = &tegra20_init_speedo_data; |
| 135 | break; |
Danny Huang | f8ddda7 | 2012-11-15 15:42:34 +0800 | [diff] [blame] | 136 | case TEGRA30: |
| 137 | tegra_fuse_spare_bit = TEGRA30_FUSE_SPARE_BIT; |
| 138 | tegra_init_speedo_data = &tegra30_init_speedo_data; |
| 139 | break; |
Danny Huang | 25cd5a3 | 2012-11-15 15:42:33 +0800 | [diff] [blame] | 140 | default: |
Danny Huang | f8ddda7 | 2012-11-15 15:42:34 +0800 | [diff] [blame] | 141 | pr_warn("Tegra: unknown chip id %d\n", tegra_chip_id); |
| 142 | tegra_fuse_spare_bit = TEGRA20_FUSE_SPARE_BIT; |
Danny Huang | 25cd5a3 | 2012-11-15 15:42:33 +0800 | [diff] [blame] | 143 | tegra_init_speedo_data = &tegra_get_process_id; |
| 144 | } |
| 145 | |
Peter De Schrijver | 35b1498 | 2012-02-10 01:47:41 +0200 | [diff] [blame] | 146 | tegra_revision = tegra_get_revision(id); |
Danny Huang | 25cd5a3 | 2012-11-15 15:42:33 +0800 | [diff] [blame] | 147 | tegra_init_speedo_data(); |
Olof Johansson | 9a1086d | 2011-10-13 00:31:20 -0700 | [diff] [blame] | 148 | |
| 149 | pr_info("Tegra Revision: %s SKU: %d CPU Process: %d Core Process: %d\n", |
Peter De Schrijver | 35b1498 | 2012-02-10 01:47:41 +0200 | [diff] [blame] | 150 | tegra_revision_name[tegra_revision], |
Olof Johansson | 9a1086d | 2011-10-13 00:31:20 -0700 | [diff] [blame] | 151 | tegra_sku_id, tegra_cpu_process_id, |
| 152 | tegra_core_process_id); |
Colin Cross | 73625e3 | 2010-06-23 15:49:17 -0700 | [diff] [blame] | 153 | } |
| 154 | |
| 155 | unsigned long long tegra_chip_uid(void) |
| 156 | { |
| 157 | unsigned long long lo, hi; |
| 158 | |
Olof Johansson | d262f49 | 2011-10-13 00:14:08 -0700 | [diff] [blame] | 159 | lo = tegra_fuse_readl(FUSE_UID_LOW); |
| 160 | hi = tegra_fuse_readl(FUSE_UID_HIGH); |
Colin Cross | 73625e3 | 2010-06-23 15:49:17 -0700 | [diff] [blame] | 161 | return (hi << 32ull) | lo; |
| 162 | } |
Henning Heinold | e87e06c | 2012-01-13 16:38:37 +1100 | [diff] [blame] | 163 | EXPORT_SYMBOL(tegra_chip_uid); |