ARM: tegra: flexible spare fuse read function
[deliverable/linux.git] / arch / arm / mach-tegra / fuse.c
CommitLineData
73625e3e
CC
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>
34800598 22#include <linux/export.h>
73625e3e 23
73625e3e 24#include "fuse.h"
2be39c07 25#include "iomap.h"
d262f49d 26#include "apbio.h"
73625e3e
CC
27
28#define FUSE_UID_LOW 0x108
29#define FUSE_UID_HIGH 0x10c
30#define FUSE_SKU_INFO 0x110
1f851a26
DH
31
32#define TEGRA20_FUSE_SPARE_BIT 0x200
73625e3e 33
9a1086da
OJ
34int tegra_sku_id;
35int tegra_cpu_process_id;
36int tegra_core_process_id;
4c4ad669 37int tegra_chip_id;
9a1086da
OJ
38enum tegra_revision tegra_revision;
39
1f851a26
DH
40static int tegra_fuse_spare_bit;
41
dee47183
OJ
42/* The BCT to use at boot is specified by board straps that can be read
43 * through a APB misc register and decoded. 2 bits, i.e. 4 possible BCTs.
44 */
45int tegra_bct_strapping;
46
47#define STRAP_OPT 0x008
48#define GMI_AD0 (1 << 4)
49#define GMI_AD1 (1 << 5)
50#define RAM_ID_MASK (GMI_AD0 | GMI_AD1)
51#define RAM_CODE_SHIFT 4
52
9a1086da
OJ
53static const char *tegra_revision_name[TEGRA_REVISION_MAX] = {
54 [TEGRA_REVISION_UNKNOWN] = "unknown",
55 [TEGRA_REVISION_A01] = "A01",
56 [TEGRA_REVISION_A02] = "A02",
57 [TEGRA_REVISION_A03] = "A03",
58 [TEGRA_REVISION_A03p] = "A03 prime",
59 [TEGRA_REVISION_A04] = "A04",
60};
61
1f851a26 62u32 tegra_fuse_readl(unsigned long offset)
73625e3e 63{
d262f49d 64 return tegra_apb_readl(TEGRA_FUSE_BASE + offset);
73625e3e
CC
65}
66
1f851a26 67bool tegra_spare_fuse(int bit)
73625e3e 68{
1f851a26 69 return tegra_fuse_readl(tegra_fuse_spare_bit + bit * 4);
73625e3e
CC
70}
71
35b1498a 72static enum tegra_revision tegra_get_revision(u32 id)
73625e3e 73{
9a1086da 74 u32 minor_rev = (id >> 16) & 0xf;
9a1086da
OJ
75
76 switch (minor_rev) {
77 case 1:
78 return TEGRA_REVISION_A01;
79 case 2:
80 return TEGRA_REVISION_A02;
81 case 3:
35b1498a 82 if (tegra_chip_id == TEGRA20 &&
1f851a26 83 (tegra_spare_fuse(18) || tegra_spare_fuse(19)))
9a1086da
OJ
84 return TEGRA_REVISION_A03p;
85 else
86 return TEGRA_REVISION_A03;
87 case 4:
88 return TEGRA_REVISION_A04;
89 default:
90 return TEGRA_REVISION_UNKNOWN;
91 }
73625e3e
CC
92}
93
94void tegra_init_fuse(void)
95{
35b1498a
PDS
96 u32 id;
97
f8e798a9 98 u32 reg = readl(IO_ADDRESS(TEGRA_CLK_RESET_BASE + 0x48));
73625e3e 99 reg |= 1 << 28;
f8e798a9 100 writel(reg, IO_ADDRESS(TEGRA_CLK_RESET_BASE + 0x48));
73625e3e 101
9a1086da
OJ
102 reg = tegra_fuse_readl(FUSE_SKU_INFO);
103 tegra_sku_id = reg & 0xFF;
104
1f851a26
DH
105 tegra_fuse_spare_bit = TEGRA20_FUSE_SPARE_BIT;
106
107 reg = tegra_fuse_readl(tegra_fuse_spare_bit);
9a1086da
OJ
108 tegra_cpu_process_id = (reg >> 6) & 3;
109
1f851a26 110 reg = tegra_fuse_readl(tegra_fuse_spare_bit);
9a1086da
OJ
111 tegra_core_process_id = (reg >> 12) & 3;
112
dee47183
OJ
113 reg = tegra_apb_readl(TEGRA_APB_MISC_BASE + STRAP_OPT);
114 tegra_bct_strapping = (reg & RAM_ID_MASK) >> RAM_CODE_SHIFT;
115
35b1498a
PDS
116 id = readl_relaxed(IO_ADDRESS(TEGRA_APB_MISC_BASE) + 0x804);
117 tegra_chip_id = (id >> 8) & 0xff;
118
119 tegra_revision = tegra_get_revision(id);
9a1086da
OJ
120
121 pr_info("Tegra Revision: %s SKU: %d CPU Process: %d Core Process: %d\n",
35b1498a 122 tegra_revision_name[tegra_revision],
9a1086da
OJ
123 tegra_sku_id, tegra_cpu_process_id,
124 tegra_core_process_id);
73625e3e
CC
125}
126
127unsigned long long tegra_chip_uid(void)
128{
129 unsigned long long lo, hi;
130
d262f49d
OJ
131 lo = tegra_fuse_readl(FUSE_UID_LOW);
132 hi = tegra_fuse_readl(FUSE_UID_HIGH);
73625e3e
CC
133 return (hi << 32ull) | lo;
134}
e87e06cd 135EXPORT_SYMBOL(tegra_chip_uid);
This page took 0.141375 seconds and 5 git commands to generate.