blob: 17fdd4086e6fcf87a4216592514fc622d17cb7b8 [file] [log] [blame]
Colin Cross73625e32010-06-23 15:49:17 -07001/*
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>
22
23#include <mach/iomap.h>
24
25#include "fuse.h"
Olof Johanssond262f492011-10-13 00:14:08 -070026#include "apbio.h"
Colin Cross73625e32010-06-23 15:49:17 -070027
28#define FUSE_UID_LOW 0x108
29#define FUSE_UID_HIGH 0x10c
30#define FUSE_SKU_INFO 0x110
31#define FUSE_SPARE_BIT 0x200
32
Olof Johansson9a1086d2011-10-13 00:31:20 -070033int tegra_sku_id;
34int tegra_cpu_process_id;
35int tegra_core_process_id;
36enum tegra_revision tegra_revision;
37
Olof Johanssondee47182011-10-17 16:39:24 -070038/* The BCT to use at boot is specified by board straps that can be read
39 * through a APB misc register and decoded. 2 bits, i.e. 4 possible BCTs.
40 */
41int tegra_bct_strapping;
42
43#define STRAP_OPT 0x008
44#define GMI_AD0 (1 << 4)
45#define GMI_AD1 (1 << 5)
46#define RAM_ID_MASK (GMI_AD0 | GMI_AD1)
47#define RAM_CODE_SHIFT 4
48
Olof Johansson9a1086d2011-10-13 00:31:20 -070049static const char *tegra_revision_name[TEGRA_REVISION_MAX] = {
50 [TEGRA_REVISION_UNKNOWN] = "unknown",
51 [TEGRA_REVISION_A01] = "A01",
52 [TEGRA_REVISION_A02] = "A02",
53 [TEGRA_REVISION_A03] = "A03",
54 [TEGRA_REVISION_A03p] = "A03 prime",
55 [TEGRA_REVISION_A04] = "A04",
56};
57
Olof Johanssond262f492011-10-13 00:14:08 -070058static inline u32 tegra_fuse_readl(unsigned long offset)
Colin Cross73625e32010-06-23 15:49:17 -070059{
Olof Johanssond262f492011-10-13 00:14:08 -070060 return tegra_apb_readl(TEGRA_FUSE_BASE + offset);
Colin Cross73625e32010-06-23 15:49:17 -070061}
62
Olof Johansson9a1086d2011-10-13 00:31:20 -070063static inline bool get_spare_fuse(int bit)
64{
65 return tegra_fuse_readl(FUSE_SPARE_BIT + bit * 4);
66}
67
68static enum tegra_revision tegra_get_revision(void)
69{
70 void __iomem *chip_id = IO_ADDRESS(TEGRA_APB_MISC_BASE) + 0x804;
71 u32 id = readl(chip_id);
72 u32 minor_rev = (id >> 16) & 0xf;
73 u32 chipid = (id >> 8) & 0xff;
74
75 switch (minor_rev) {
76 case 1:
77 return TEGRA_REVISION_A01;
78 case 2:
79 return TEGRA_REVISION_A02;
80 case 3:
81 if (chipid == 0x20 && (get_spare_fuse(18) || get_spare_fuse(19)))
82 return TEGRA_REVISION_A03p;
83 else
84 return TEGRA_REVISION_A03;
85 case 4:
86 return TEGRA_REVISION_A04;
87 default:
88 return TEGRA_REVISION_UNKNOWN;
89 }
90}
91
Colin Cross73625e32010-06-23 15:49:17 -070092void tegra_init_fuse(void)
93{
94 u32 reg = readl(IO_TO_VIRT(TEGRA_CLK_RESET_BASE + 0x48));
95 reg |= 1 << 28;
96 writel(reg, IO_TO_VIRT(TEGRA_CLK_RESET_BASE + 0x48));
97
Olof Johansson9a1086d2011-10-13 00:31:20 -070098 reg = tegra_fuse_readl(FUSE_SKU_INFO);
99 tegra_sku_id = reg & 0xFF;
100
101 reg = tegra_fuse_readl(FUSE_SPARE_BIT);
102 tegra_cpu_process_id = (reg >> 6) & 3;
103
104 reg = tegra_fuse_readl(FUSE_SPARE_BIT);
105 tegra_core_process_id = (reg >> 12) & 3;
106
Olof Johanssondee47182011-10-17 16:39:24 -0700107 reg = tegra_apb_readl(TEGRA_APB_MISC_BASE + STRAP_OPT);
108 tegra_bct_strapping = (reg & RAM_ID_MASK) >> RAM_CODE_SHIFT;
109
Olof Johansson9a1086d2011-10-13 00:31:20 -0700110 tegra_revision = tegra_get_revision();
111
112 pr_info("Tegra Revision: %s SKU: %d CPU Process: %d Core Process: %d\n",
113 tegra_revision_name[tegra_get_revision()],
114 tegra_sku_id, tegra_cpu_process_id,
115 tegra_core_process_id);
Colin Cross73625e32010-06-23 15:49:17 -0700116}
117
118unsigned long long tegra_chip_uid(void)
119{
120 unsigned long long lo, hi;
121
Olof Johanssond262f492011-10-13 00:14:08 -0700122 lo = tegra_fuse_readl(FUSE_UID_LOW);
123 hi = tegra_fuse_readl(FUSE_UID_HIGH);
Colin Cross73625e32010-06-23 15:49:17 -0700124 return (hi << 32ull) | lo;
125}