2 * Copyright (c) 2013-2014, NVIDIA CORPORATION. All rights reserved.
4 * This program is free software; you can redistribute it and/or modify it
5 * under the terms and conditions of the GNU General Public License,
6 * version 2, as published by the Free Software Foundation.
8 * This program is distributed in the hope it will be useful, but WITHOUT
9 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
10 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
13 * You should have received a copy of the GNU General Public License
14 * along with this program. If not, see <http://www.gnu.org/licenses/>.
18 #include <linux/device.h>
19 #include <linux/clk.h>
20 #include <linux/err.h>
22 #include <linux/kernel.h>
23 #include <linux/of_device.h>
24 #include <linux/of_address.h>
25 #include <linux/platform_device.h>
26 #include <linux/random.h>
28 #include <soc/tegra/fuse.h>
32 #define FUSE_BEGIN 0x100
34 /* Tegra30 and later */
35 #define FUSE_VENDOR_CODE 0x100
36 #define FUSE_FAB_CODE 0x104
37 #define FUSE_LOT_CODE_0 0x108
38 #define FUSE_LOT_CODE_1 0x10c
39 #define FUSE_WAFER_ID 0x110
40 #define FUSE_X_COORDINATE 0x114
41 #define FUSE_Y_COORDINATE 0x118
43 #define FUSE_HAS_REVISION_INFO BIT(0)
45 #if defined(CONFIG_ARCH_TEGRA_3x_SOC) || \
46 defined(CONFIG_ARCH_TEGRA_114_SOC) || \
47 defined(CONFIG_ARCH_TEGRA_124_SOC) || \
48 defined(CONFIG_ARCH_TEGRA_132_SOC) || \
49 defined(CONFIG_ARCH_TEGRA_210_SOC) || \
50 defined(CONFIG_ARCH_TEGRA_186_SOC) || \
51 defined(CONFIG_ARCH_TEGRA_194_SOC) || \
52 defined(CONFIG_ARCH_TEGRA_234_SOC)
53 static u32 tegra30_fuse_read_early(struct tegra_fuse *fuse, unsigned int offset)
55 if (WARN_ON(!fuse->base))
58 return readl_relaxed(fuse->base + FUSE_BEGIN + offset);
61 static u32 tegra30_fuse_read(struct tegra_fuse *fuse, unsigned int offset)
66 err = clk_prepare_enable(fuse->clk);
68 dev_err(fuse->dev, "failed to enable FUSE clock: %d\n", err);
72 value = readl_relaxed(fuse->base + FUSE_BEGIN + offset);
74 clk_disable_unprepare(fuse->clk);
79 static void __init tegra30_fuse_add_randomness(void)
83 randomness[0] = tegra_sku_info.sku_id;
84 randomness[1] = tegra_read_straps();
85 randomness[2] = tegra_read_chipid();
86 randomness[3] = tegra_sku_info.cpu_process_id << 16;
87 randomness[3] |= tegra_sku_info.soc_process_id;
88 randomness[4] = tegra_sku_info.cpu_speedo_id << 16;
89 randomness[4] |= tegra_sku_info.soc_speedo_id;
90 randomness[5] = tegra_fuse_read_early(FUSE_VENDOR_CODE);
91 randomness[6] = tegra_fuse_read_early(FUSE_FAB_CODE);
92 randomness[7] = tegra_fuse_read_early(FUSE_LOT_CODE_0);
93 randomness[8] = tegra_fuse_read_early(FUSE_LOT_CODE_1);
94 randomness[9] = tegra_fuse_read_early(FUSE_WAFER_ID);
95 randomness[10] = tegra_fuse_read_early(FUSE_X_COORDINATE);
96 randomness[11] = tegra_fuse_read_early(FUSE_Y_COORDINATE);
98 add_device_randomness(randomness, sizeof(randomness));
101 static void __init tegra30_fuse_init(struct tegra_fuse *fuse)
103 fuse->read_early = tegra30_fuse_read_early;
104 fuse->read = tegra30_fuse_read;
106 tegra_init_revision();
108 if (fuse->soc->speedo_init)
109 fuse->soc->speedo_init(&tegra_sku_info);
111 tegra30_fuse_add_randomness();
115 #ifdef CONFIG_ARCH_TEGRA_3x_SOC
116 static const struct tegra_fuse_info tegra30_fuse_info = {
117 .read = tegra30_fuse_read,
122 const struct tegra_fuse_soc tegra30_fuse_soc = {
123 .init = tegra30_fuse_init,
124 .speedo_init = tegra30_init_speedo_data,
125 .info = &tegra30_fuse_info,
129 #ifdef CONFIG_ARCH_TEGRA_114_SOC
130 static const struct tegra_fuse_info tegra114_fuse_info = {
131 .read = tegra30_fuse_read,
136 const struct tegra_fuse_soc tegra114_fuse_soc = {
137 .init = tegra30_fuse_init,
138 .speedo_init = tegra114_init_speedo_data,
139 .info = &tegra114_fuse_info,
143 #if defined(CONFIG_ARCH_TEGRA_124_SOC) || defined(CONFIG_ARCH_TEGRA_132_SOC)
144 static const struct tegra_fuse_info tegra124_fuse_info = {
145 .read = tegra30_fuse_read,
150 const struct tegra_fuse_soc tegra124_fuse_soc = {
151 .init = tegra30_fuse_init,
152 .speedo_init = tegra124_init_speedo_data,
153 .info = &tegra124_fuse_info,
157 #if defined(CONFIG_ARCH_TEGRA_210_SOC)
158 static const struct tegra_fuse_info tegra210_fuse_info = {
159 .read = tegra30_fuse_read,
164 const struct tegra_fuse_soc tegra210_fuse_soc = {
165 .init = tegra30_fuse_init,
166 .speedo_init = tegra210_init_speedo_data,
167 .info = &tegra210_fuse_info,
171 #if defined(CONFIG_ARCH_TEGRA_186_SOC)
172 static const struct tegra_fuse_info tegra186_fuse_info = {
173 .read = tegra30_fuse_read,
178 const struct tegra_fuse_soc tegra186_fuse_soc = {
179 .init = tegra30_fuse_init,
180 .info = &tegra186_fuse_info,