blob: 8121742711fe25d581bfbe13c08337a8ce5196c9 [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>
Linus Torvalds34800592012-03-27 16:41:24 -070022#include <linux/export.h>
Colin Cross73625e32010-06-23 15:49:17 -070023
Colin Cross73625e32010-06-23 15:49:17 -070024#include "fuse.h"
Stephen Warren2be39c02012-10-04 14:24:09 -060025#include "iomap.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
Danny Huang1f851a22012-11-15 15:42:32 +080031
32#define TEGRA20_FUSE_SPARE_BIT 0x200
Danny Huangf8ddda72012-11-15 15:42:34 +080033#define TEGRA30_FUSE_SPARE_BIT 0x244
Colin Cross73625e32010-06-23 15:49:17 -070034
Olof Johansson9a1086d2011-10-13 00:31:20 -070035int tegra_sku_id;
36int tegra_cpu_process_id;
37int tegra_core_process_id;
Peter De Schrijver4c4ad662012-02-10 01:47:42 +020038int tegra_chip_id;
Danny Huangf8ddda72012-11-15 15:42:34 +080039int tegra_cpu_speedo_id; /* only exist in Tegra30 and later */
Danny Huang25cd5a32012-11-15 15:42:33 +080040int tegra_soc_speedo_id;
Olof Johansson9a1086d2011-10-13 00:31:20 -070041enum tegra_revision tegra_revision;
42
Danny Huang1f851a22012-11-15 15:42:32 +080043static int tegra_fuse_spare_bit;
Danny Huang25cd5a32012-11-15 15:42:33 +080044static void (*tegra_init_speedo_data)(void);
Danny Huang1f851a22012-11-15 15:42:32 +080045
Olof Johanssondee47182011-10-17 16:39:24 -070046/* The BCT to use at boot is specified by board straps that can be read
47 * through a APB misc register and decoded. 2 bits, i.e. 4 possible BCTs.
48 */
49int tegra_bct_strapping;
50
51#define STRAP_OPT 0x008
52#define GMI_AD0 (1 << 4)
53#define GMI_AD1 (1 << 5)
54#define RAM_ID_MASK (GMI_AD0 | GMI_AD1)
55#define RAM_CODE_SHIFT 4
56
Olof Johansson9a1086d2011-10-13 00:31:20 -070057static const char *tegra_revision_name[TEGRA_REVISION_MAX] = {
58 [TEGRA_REVISION_UNKNOWN] = "unknown",
59 [TEGRA_REVISION_A01] = "A01",
60 [TEGRA_REVISION_A02] = "A02",
61 [TEGRA_REVISION_A03] = "A03",
62 [TEGRA_REVISION_A03p] = "A03 prime",
63 [TEGRA_REVISION_A04] = "A04",
64};
65
Danny Huang1f851a22012-11-15 15:42:32 +080066u32 tegra_fuse_readl(unsigned long offset)
Colin Cross73625e32010-06-23 15:49:17 -070067{
Olof Johanssond262f492011-10-13 00:14:08 -070068 return tegra_apb_readl(TEGRA_FUSE_BASE + offset);
Colin Cross73625e32010-06-23 15:49:17 -070069}
70
Danny Huang1f851a22012-11-15 15:42:32 +080071bool tegra_spare_fuse(int bit)
Colin Cross73625e32010-06-23 15:49:17 -070072{
Danny Huang1f851a22012-11-15 15:42:32 +080073 return tegra_fuse_readl(tegra_fuse_spare_bit + bit * 4);
Olof Johansson9a1086d2011-10-13 00:31:20 -070074}
75
Peter De Schrijver35b14982012-02-10 01:47:41 +020076static enum tegra_revision tegra_get_revision(u32 id)
Olof Johansson9a1086d2011-10-13 00:31:20 -070077{
Olof Johansson9a1086d2011-10-13 00:31:20 -070078 u32 minor_rev = (id >> 16) & 0xf;
Olof Johansson9a1086d2011-10-13 00:31:20 -070079
80 switch (minor_rev) {
81 case 1:
82 return TEGRA_REVISION_A01;
83 case 2:
84 return TEGRA_REVISION_A02;
85 case 3:
Peter De Schrijver35b14982012-02-10 01:47:41 +020086 if (tegra_chip_id == TEGRA20 &&
Danny Huang1f851a22012-11-15 15:42:32 +080087 (tegra_spare_fuse(18) || tegra_spare_fuse(19)))
Olof Johansson9a1086d2011-10-13 00:31:20 -070088 return TEGRA_REVISION_A03p;
89 else
90 return TEGRA_REVISION_A03;
91 case 4:
92 return TEGRA_REVISION_A04;
93 default:
94 return TEGRA_REVISION_UNKNOWN;
95 }
Colin Cross73625e32010-06-23 15:49:17 -070096}
97
Danny Huang25cd5a32012-11-15 15:42:33 +080098static void tegra_get_process_id(void)
99{
100 u32 reg;
101
102 reg = tegra_fuse_readl(tegra_fuse_spare_bit);
103 tegra_cpu_process_id = (reg >> 6) & 3;
104 reg = tegra_fuse_readl(tegra_fuse_spare_bit);
105 tegra_core_process_id = (reg >> 12) & 3;
106}
107
Colin Cross73625e32010-06-23 15:49:17 -0700108void tegra_init_fuse(void)
109{
Peter De Schrijver35b14982012-02-10 01:47:41 +0200110 u32 id;
111
Laxman Dewanganf8e798a2012-08-10 18:33:02 +0530112 u32 reg = readl(IO_ADDRESS(TEGRA_CLK_RESET_BASE + 0x48));
Colin Cross73625e32010-06-23 15:49:17 -0700113 reg |= 1 << 28;
Laxman Dewanganf8e798a2012-08-10 18:33:02 +0530114 writel(reg, IO_ADDRESS(TEGRA_CLK_RESET_BASE + 0x48));
Colin Cross73625e32010-06-23 15:49:17 -0700115
Olof Johansson9a1086d2011-10-13 00:31:20 -0700116 reg = tegra_fuse_readl(FUSE_SKU_INFO);
117 tegra_sku_id = reg & 0xFF;
118
Olof Johanssondee47182011-10-17 16:39:24 -0700119 reg = tegra_apb_readl(TEGRA_APB_MISC_BASE + STRAP_OPT);
120 tegra_bct_strapping = (reg & RAM_ID_MASK) >> RAM_CODE_SHIFT;
121
Peter De Schrijver35b14982012-02-10 01:47:41 +0200122 id = readl_relaxed(IO_ADDRESS(TEGRA_APB_MISC_BASE) + 0x804);
123 tegra_chip_id = (id >> 8) & 0xff;
124
Danny Huang25cd5a32012-11-15 15:42:33 +0800125 switch (tegra_chip_id) {
126 case TEGRA20:
Danny Huangf8ddda72012-11-15 15:42:34 +0800127 tegra_fuse_spare_bit = TEGRA20_FUSE_SPARE_BIT;
Danny Huang25cd5a32012-11-15 15:42:33 +0800128 tegra_init_speedo_data = &tegra20_init_speedo_data;
129 break;
Danny Huangf8ddda72012-11-15 15:42:34 +0800130 case TEGRA30:
131 tegra_fuse_spare_bit = TEGRA30_FUSE_SPARE_BIT;
132 tegra_init_speedo_data = &tegra30_init_speedo_data;
133 break;
Danny Huang25cd5a32012-11-15 15:42:33 +0800134 default:
Danny Huangf8ddda72012-11-15 15:42:34 +0800135 pr_warn("Tegra: unknown chip id %d\n", tegra_chip_id);
136 tegra_fuse_spare_bit = TEGRA20_FUSE_SPARE_BIT;
Danny Huang25cd5a32012-11-15 15:42:33 +0800137 tegra_init_speedo_data = &tegra_get_process_id;
138 }
139
Peter De Schrijver35b14982012-02-10 01:47:41 +0200140 tegra_revision = tegra_get_revision(id);
Danny Huang25cd5a32012-11-15 15:42:33 +0800141 tegra_init_speedo_data();
Olof Johansson9a1086d2011-10-13 00:31:20 -0700142
143 pr_info("Tegra Revision: %s SKU: %d CPU Process: %d Core Process: %d\n",
Peter De Schrijver35b14982012-02-10 01:47:41 +0200144 tegra_revision_name[tegra_revision],
Olof Johansson9a1086d2011-10-13 00:31:20 -0700145 tegra_sku_id, tegra_cpu_process_id,
146 tegra_core_process_id);
Colin Cross73625e32010-06-23 15:49:17 -0700147}
148
149unsigned long long tegra_chip_uid(void)
150{
151 unsigned long long lo, hi;
152
Olof Johanssond262f492011-10-13 00:14:08 -0700153 lo = tegra_fuse_readl(FUSE_UID_LOW);
154 hi = tegra_fuse_readl(FUSE_UID_HIGH);
Colin Cross73625e32010-06-23 15:49:17 -0700155 return (hi << 32ull) | lo;
156}
Henning Heinolde87e06c2012-01-13 16:38:37 +1100157EXPORT_SYMBOL(tegra_chip_uid);