blob: e035cd284a6eb5e3bf1268acb00da3c5784e5ced [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.
Danny Huang7495b2e2013-03-18 19:17:34 +08005 * Copyright (c) 2013, NVIDIA CORPORATION. All rights reserved.
Colin Cross73625e32010-06-23 15:49:17 -07006 *
7 * Author:
8 * Colin Cross <ccross@android.com>
9 *
10 * This software is licensed under the terms of the GNU General Public
11 * License version 2, as published by the Free Software Foundation, and
12 * may be copied, distributed, and modified under those terms.
13 *
14 * This program is distributed in the hope that it will be useful,
15 * but WITHOUT ANY WARRANTY; without even the implied warranty of
16 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17 * GNU General Public License for more details.
18 *
19 */
20
21#include <linux/kernel.h>
22#include <linux/io.h>
Linus Torvalds34800592012-03-27 16:41:24 -070023#include <linux/export.h>
Prashant Gaikwadc7736ed2013-01-11 13:16:19 +053024#include <linux/tegra-soc.h>
Colin Cross73625e32010-06-23 15:49:17 -070025
Colin Cross73625e32010-06-23 15:49:17 -070026#include "fuse.h"
Stephen Warren2be39c02012-10-04 14:24:09 -060027#include "iomap.h"
Olof Johanssond262f492011-10-13 00:14:08 -070028#include "apbio.h"
Colin Cross73625e32010-06-23 15:49:17 -070029
30#define FUSE_UID_LOW 0x108
31#define FUSE_UID_HIGH 0x10c
32#define FUSE_SKU_INFO 0x110
Danny Huang1f851a22012-11-15 15:42:32 +080033
34#define TEGRA20_FUSE_SPARE_BIT 0x200
Danny Huangf8ddda72012-11-15 15:42:34 +080035#define TEGRA30_FUSE_SPARE_BIT 0x244
Colin Cross73625e32010-06-23 15:49:17 -070036
Olof Johansson9a1086d2011-10-13 00:31:20 -070037int tegra_sku_id;
38int tegra_cpu_process_id;
39int tegra_core_process_id;
Peter De Schrijver4c4ad662012-02-10 01:47:42 +020040int tegra_chip_id;
Danny Huangf8ddda72012-11-15 15:42:34 +080041int tegra_cpu_speedo_id; /* only exist in Tegra30 and later */
Danny Huang25cd5a32012-11-15 15:42:33 +080042int tegra_soc_speedo_id;
Olof Johansson9a1086d2011-10-13 00:31:20 -070043enum tegra_revision tegra_revision;
44
Danny Huang1f851a22012-11-15 15:42:32 +080045static int tegra_fuse_spare_bit;
Danny Huang25cd5a32012-11-15 15:42:33 +080046static void (*tegra_init_speedo_data)(void);
Danny Huang1f851a22012-11-15 15:42:32 +080047
Olof Johanssondee47182011-10-17 16:39:24 -070048/* The BCT to use at boot is specified by board straps that can be read
49 * through a APB misc register and decoded. 2 bits, i.e. 4 possible BCTs.
50 */
51int tegra_bct_strapping;
52
53#define STRAP_OPT 0x008
54#define GMI_AD0 (1 << 4)
55#define GMI_AD1 (1 << 5)
56#define RAM_ID_MASK (GMI_AD0 | GMI_AD1)
57#define RAM_CODE_SHIFT 4
58
Olof Johansson9a1086d2011-10-13 00:31:20 -070059static const char *tegra_revision_name[TEGRA_REVISION_MAX] = {
60 [TEGRA_REVISION_UNKNOWN] = "unknown",
61 [TEGRA_REVISION_A01] = "A01",
62 [TEGRA_REVISION_A02] = "A02",
63 [TEGRA_REVISION_A03] = "A03",
64 [TEGRA_REVISION_A03p] = "A03 prime",
65 [TEGRA_REVISION_A04] = "A04",
66};
67
Danny Huang1f851a22012-11-15 15:42:32 +080068u32 tegra_fuse_readl(unsigned long offset)
Colin Cross73625e32010-06-23 15:49:17 -070069{
Olof Johanssond262f492011-10-13 00:14:08 -070070 return tegra_apb_readl(TEGRA_FUSE_BASE + offset);
Colin Cross73625e32010-06-23 15:49:17 -070071}
72
Danny Huang1f851a22012-11-15 15:42:32 +080073bool tegra_spare_fuse(int bit)
Colin Cross73625e32010-06-23 15:49:17 -070074{
Danny Huang1f851a22012-11-15 15:42:32 +080075 return tegra_fuse_readl(tegra_fuse_spare_bit + bit * 4);
Olof Johansson9a1086d2011-10-13 00:31:20 -070076}
77
Peter De Schrijver35b14982012-02-10 01:47:41 +020078static enum tegra_revision tegra_get_revision(u32 id)
Olof Johansson9a1086d2011-10-13 00:31:20 -070079{
Olof Johansson9a1086d2011-10-13 00:31:20 -070080 u32 minor_rev = (id >> 16) & 0xf;
Olof Johansson9a1086d2011-10-13 00:31:20 -070081
82 switch (minor_rev) {
83 case 1:
84 return TEGRA_REVISION_A01;
85 case 2:
86 return TEGRA_REVISION_A02;
87 case 3:
Peter De Schrijver35b14982012-02-10 01:47:41 +020088 if (tegra_chip_id == TEGRA20 &&
Danny Huang1f851a22012-11-15 15:42:32 +080089 (tegra_spare_fuse(18) || tegra_spare_fuse(19)))
Olof Johansson9a1086d2011-10-13 00:31:20 -070090 return TEGRA_REVISION_A03p;
91 else
92 return TEGRA_REVISION_A03;
93 case 4:
94 return TEGRA_REVISION_A04;
95 default:
96 return TEGRA_REVISION_UNKNOWN;
97 }
Colin Cross73625e32010-06-23 15:49:17 -070098}
99
Danny Huang25cd5a32012-11-15 15:42:33 +0800100static void tegra_get_process_id(void)
101{
102 u32 reg;
103
104 reg = tegra_fuse_readl(tegra_fuse_spare_bit);
105 tegra_cpu_process_id = (reg >> 6) & 3;
106 reg = tegra_fuse_readl(tegra_fuse_spare_bit);
107 tegra_core_process_id = (reg >> 12) & 3;
108}
109
Prashant Gaikwadc7736ed2013-01-11 13:16:19 +0530110u32 tegra_read_chipid(void)
111{
112 return readl_relaxed(IO_ADDRESS(TEGRA_APB_MISC_BASE) + 0x804);
113}
114
Colin Cross73625e32010-06-23 15:49:17 -0700115void tegra_init_fuse(void)
116{
Peter De Schrijver35b14982012-02-10 01:47:41 +0200117 u32 id;
118
Laxman Dewanganf8e798a2012-08-10 18:33:02 +0530119 u32 reg = readl(IO_ADDRESS(TEGRA_CLK_RESET_BASE + 0x48));
Colin Cross73625e32010-06-23 15:49:17 -0700120 reg |= 1 << 28;
Laxman Dewanganf8e798a2012-08-10 18:33:02 +0530121 writel(reg, IO_ADDRESS(TEGRA_CLK_RESET_BASE + 0x48));
Colin Cross73625e32010-06-23 15:49:17 -0700122
Olof Johansson9a1086d2011-10-13 00:31:20 -0700123 reg = tegra_fuse_readl(FUSE_SKU_INFO);
124 tegra_sku_id = reg & 0xFF;
125
Olof Johanssondee47182011-10-17 16:39:24 -0700126 reg = tegra_apb_readl(TEGRA_APB_MISC_BASE + STRAP_OPT);
127 tegra_bct_strapping = (reg & RAM_ID_MASK) >> RAM_CODE_SHIFT;
128
Prashant Gaikwadc7736ed2013-01-11 13:16:19 +0530129 id = tegra_read_chipid();
Peter De Schrijver35b14982012-02-10 01:47:41 +0200130 tegra_chip_id = (id >> 8) & 0xff;
131
Danny Huang25cd5a32012-11-15 15:42:33 +0800132 switch (tegra_chip_id) {
133 case TEGRA20:
Danny Huangf8ddda72012-11-15 15:42:34 +0800134 tegra_fuse_spare_bit = TEGRA20_FUSE_SPARE_BIT;
Danny Huang25cd5a32012-11-15 15:42:33 +0800135 tegra_init_speedo_data = &tegra20_init_speedo_data;
136 break;
Danny Huangf8ddda72012-11-15 15:42:34 +0800137 case TEGRA30:
138 tegra_fuse_spare_bit = TEGRA30_FUSE_SPARE_BIT;
139 tegra_init_speedo_data = &tegra30_init_speedo_data;
140 break;
Danny Huang7495b2e2013-03-18 19:17:34 +0800141 case TEGRA114:
142 tegra_init_speedo_data = &tegra114_init_speedo_data;
143 break;
Danny Huang25cd5a32012-11-15 15:42:33 +0800144 default:
Danny Huangf8ddda72012-11-15 15:42:34 +0800145 pr_warn("Tegra: unknown chip id %d\n", tegra_chip_id);
146 tegra_fuse_spare_bit = TEGRA20_FUSE_SPARE_BIT;
Danny Huang25cd5a32012-11-15 15:42:33 +0800147 tegra_init_speedo_data = &tegra_get_process_id;
148 }
149
Peter De Schrijver35b14982012-02-10 01:47:41 +0200150 tegra_revision = tegra_get_revision(id);
Danny Huang25cd5a32012-11-15 15:42:33 +0800151 tegra_init_speedo_data();
Olof Johansson9a1086d2011-10-13 00:31:20 -0700152
153 pr_info("Tegra Revision: %s SKU: %d CPU Process: %d Core Process: %d\n",
Peter De Schrijver35b14982012-02-10 01:47:41 +0200154 tegra_revision_name[tegra_revision],
Olof Johansson9a1086d2011-10-13 00:31:20 -0700155 tegra_sku_id, tegra_cpu_process_id,
156 tegra_core_process_id);
Colin Cross73625e32010-06-23 15:49:17 -0700157}
158
159unsigned long long tegra_chip_uid(void)
160{
161 unsigned long long lo, hi;
162
Olof Johanssond262f492011-10-13 00:14:08 -0700163 lo = tegra_fuse_readl(FUSE_UID_LOW);
164 hi = tegra_fuse_readl(FUSE_UID_HIGH);
Colin Cross73625e32010-06-23 15:49:17 -0700165 return (hi << 32ull) | lo;
166}
Henning Heinolde87e06c2012-01-13 16:38:37 +1100167EXPORT_SYMBOL(tegra_chip_uid);