1 // SPDX-License-Identifier: GPL-2.0-only
3 * Copyright (c) 2013-2014, NVIDIA CORPORATION. All rights reserved.
6 #include <linux/device.h>
10 #include <linux/kernel.h>
11 #include <linux/nvmem-consumer.h>
12 #include <linux/of_device.h>
13 #include <linux/of_address.h>
14 #include <linux/platform_device.h>
15 #include <linux/random.h>
17 #include <soc/tegra/fuse.h>
21 #define FUSE_BEGIN 0x100
23 /* Tegra30 and later */
24 #define FUSE_VENDOR_CODE 0x100
25 #define FUSE_FAB_CODE 0x104
26 #define FUSE_LOT_CODE_0 0x108
27 #define FUSE_LOT_CODE_1 0x10c
28 #define FUSE_WAFER_ID 0x110
29 #define FUSE_X_COORDINATE 0x114
30 #define FUSE_Y_COORDINATE 0x118
32 #define FUSE_HAS_REVISION_INFO BIT(0)
34 #if defined(CONFIG_ARCH_TEGRA_3x_SOC) || \
35 defined(CONFIG_ARCH_TEGRA_114_SOC) || \
36 defined(CONFIG_ARCH_TEGRA_124_SOC) || \
37 defined(CONFIG_ARCH_TEGRA_132_SOC) || \
38 defined(CONFIG_ARCH_TEGRA_210_SOC) || \
39 defined(CONFIG_ARCH_TEGRA_186_SOC) || \
40 defined(CONFIG_ARCH_TEGRA_194_SOC) || \
41 defined(CONFIG_ARCH_TEGRA_234_SOC)
42 static u32 tegra30_fuse_read_early(struct tegra_fuse *fuse, unsigned int offset)
44 if (WARN_ON(!fuse->base))
47 return readl_relaxed(fuse->base + FUSE_BEGIN + offset);
50 static u32 tegra30_fuse_read(struct tegra_fuse *fuse, unsigned int offset)
55 err = clk_prepare_enable(fuse->clk);
57 dev_err(fuse->dev, "failed to enable FUSE clock: %d\n", err);
61 value = readl_relaxed(fuse->base + FUSE_BEGIN + offset);
63 clk_disable_unprepare(fuse->clk);
68 static void __init tegra30_fuse_add_randomness(void)
72 randomness[0] = tegra_sku_info.sku_id;
73 randomness[1] = tegra_read_straps();
74 randomness[2] = tegra_read_chipid();
75 randomness[3] = tegra_sku_info.cpu_process_id << 16;
76 randomness[3] |= tegra_sku_info.soc_process_id;
77 randomness[4] = tegra_sku_info.cpu_speedo_id << 16;
78 randomness[4] |= tegra_sku_info.soc_speedo_id;
79 randomness[5] = tegra_fuse_read_early(FUSE_VENDOR_CODE);
80 randomness[6] = tegra_fuse_read_early(FUSE_FAB_CODE);
81 randomness[7] = tegra_fuse_read_early(FUSE_LOT_CODE_0);
82 randomness[8] = tegra_fuse_read_early(FUSE_LOT_CODE_1);
83 randomness[9] = tegra_fuse_read_early(FUSE_WAFER_ID);
84 randomness[10] = tegra_fuse_read_early(FUSE_X_COORDINATE);
85 randomness[11] = tegra_fuse_read_early(FUSE_Y_COORDINATE);
87 add_device_randomness(randomness, sizeof(randomness));
90 static void __init tegra30_fuse_init(struct tegra_fuse *fuse)
92 fuse->read_early = tegra30_fuse_read_early;
93 fuse->read = tegra30_fuse_read;
95 tegra_init_revision();
97 if (fuse->soc->speedo_init)
98 fuse->soc->speedo_init(&tegra_sku_info);
100 tegra30_fuse_add_randomness();
104 #ifdef CONFIG_ARCH_TEGRA_3x_SOC
105 static const struct tegra_fuse_info tegra30_fuse_info = {
106 .read = tegra30_fuse_read,
111 const struct tegra_fuse_soc tegra30_fuse_soc = {
112 .init = tegra30_fuse_init,
113 .speedo_init = tegra30_init_speedo_data,
114 .info = &tegra30_fuse_info,
115 .soc_attr_group = &tegra_soc_attr_group,
119 #ifdef CONFIG_ARCH_TEGRA_114_SOC
120 static const struct tegra_fuse_info tegra114_fuse_info = {
121 .read = tegra30_fuse_read,
126 const struct tegra_fuse_soc tegra114_fuse_soc = {
127 .init = tegra30_fuse_init,
128 .speedo_init = tegra114_init_speedo_data,
129 .info = &tegra114_fuse_info,
130 .soc_attr_group = &tegra_soc_attr_group,
134 #if defined(CONFIG_ARCH_TEGRA_124_SOC) || defined(CONFIG_ARCH_TEGRA_132_SOC)
135 static const struct nvmem_cell_lookup tegra124_fuse_lookups[] = {
137 .nvmem_name = "fuse",
138 .cell_name = "xusb-pad-calibration",
139 .dev_id = "7009f000.padctl",
140 .con_id = "calibration",
142 .nvmem_name = "fuse",
143 .cell_name = "sata-calibration",
144 .dev_id = "70020000.sata",
145 .con_id = "calibration",
147 .nvmem_name = "fuse",
148 .cell_name = "tsensor-common",
149 .dev_id = "700e2000.thermal-sensor",
152 .nvmem_name = "fuse",
153 .cell_name = "tsensor-realignment",
154 .dev_id = "700e2000.thermal-sensor",
155 .con_id = "realignment",
157 .nvmem_name = "fuse",
158 .cell_name = "tsensor-cpu0",
159 .dev_id = "700e2000.thermal-sensor",
162 .nvmem_name = "fuse",
163 .cell_name = "tsensor-cpu1",
164 .dev_id = "700e2000.thermal-sensor",
167 .nvmem_name = "fuse",
168 .cell_name = "tsensor-cpu2",
169 .dev_id = "700e2000.thermal-sensor",
172 .nvmem_name = "fuse",
173 .cell_name = "tsensor-cpu3",
174 .dev_id = "700e2000.thermal-sensor",
177 .nvmem_name = "fuse",
178 .cell_name = "tsensor-mem0",
179 .dev_id = "700e2000.thermal-sensor",
182 .nvmem_name = "fuse",
183 .cell_name = "tsensor-mem1",
184 .dev_id = "700e2000.thermal-sensor",
187 .nvmem_name = "fuse",
188 .cell_name = "tsensor-gpu",
189 .dev_id = "700e2000.thermal-sensor",
192 .nvmem_name = "fuse",
193 .cell_name = "tsensor-pllx",
194 .dev_id = "700e2000.thermal-sensor",
199 static const struct tegra_fuse_info tegra124_fuse_info = {
200 .read = tegra30_fuse_read,
205 const struct tegra_fuse_soc tegra124_fuse_soc = {
206 .init = tegra30_fuse_init,
207 .speedo_init = tegra124_init_speedo_data,
208 .info = &tegra124_fuse_info,
209 .lookups = tegra124_fuse_lookups,
210 .num_lookups = ARRAY_SIZE(tegra124_fuse_lookups),
211 .soc_attr_group = &tegra_soc_attr_group,
215 #if defined(CONFIG_ARCH_TEGRA_210_SOC)
216 static const struct nvmem_cell_lookup tegra210_fuse_lookups[] = {
218 .nvmem_name = "fuse",
219 .cell_name = "tsensor-cpu1",
220 .dev_id = "700e2000.thermal-sensor",
223 .nvmem_name = "fuse",
224 .cell_name = "tsensor-cpu2",
225 .dev_id = "700e2000.thermal-sensor",
228 .nvmem_name = "fuse",
229 .cell_name = "tsensor-cpu0",
230 .dev_id = "700e2000.thermal-sensor",
233 .nvmem_name = "fuse",
234 .cell_name = "xusb-pad-calibration",
235 .dev_id = "7009f000.padctl",
236 .con_id = "calibration",
238 .nvmem_name = "fuse",
239 .cell_name = "tsensor-cpu3",
240 .dev_id = "700e2000.thermal-sensor",
243 .nvmem_name = "fuse",
244 .cell_name = "sata-calibration",
245 .dev_id = "70020000.sata",
246 .con_id = "calibration",
248 .nvmem_name = "fuse",
249 .cell_name = "tsensor-gpu",
250 .dev_id = "700e2000.thermal-sensor",
253 .nvmem_name = "fuse",
254 .cell_name = "tsensor-mem0",
255 .dev_id = "700e2000.thermal-sensor",
258 .nvmem_name = "fuse",
259 .cell_name = "tsensor-mem1",
260 .dev_id = "700e2000.thermal-sensor",
263 .nvmem_name = "fuse",
264 .cell_name = "tsensor-pllx",
265 .dev_id = "700e2000.thermal-sensor",
268 .nvmem_name = "fuse",
269 .cell_name = "tsensor-common",
270 .dev_id = "700e2000.thermal-sensor",
273 .nvmem_name = "fuse",
274 .cell_name = "gpu-calibration",
275 .dev_id = "57000000.gpu",
276 .con_id = "calibration",
278 .nvmem_name = "fuse",
279 .cell_name = "xusb-pad-calibration-ext",
280 .dev_id = "7009f000.padctl",
281 .con_id = "calibration-ext",
285 static const struct tegra_fuse_info tegra210_fuse_info = {
286 .read = tegra30_fuse_read,
291 const struct tegra_fuse_soc tegra210_fuse_soc = {
292 .init = tegra30_fuse_init,
293 .speedo_init = tegra210_init_speedo_data,
294 .info = &tegra210_fuse_info,
295 .lookups = tegra210_fuse_lookups,
296 .num_lookups = ARRAY_SIZE(tegra210_fuse_lookups),
297 .soc_attr_group = &tegra_soc_attr_group,
301 #if defined(CONFIG_ARCH_TEGRA_186_SOC)
302 static const struct nvmem_cell_lookup tegra186_fuse_lookups[] = {
304 .nvmem_name = "fuse",
305 .cell_name = "xusb-pad-calibration",
306 .dev_id = "3520000.padctl",
307 .con_id = "calibration",
309 .nvmem_name = "fuse",
310 .cell_name = "xusb-pad-calibration-ext",
311 .dev_id = "3520000.padctl",
312 .con_id = "calibration-ext",
316 static const struct tegra_fuse_info tegra186_fuse_info = {
317 .read = tegra30_fuse_read,
322 const struct tegra_fuse_soc tegra186_fuse_soc = {
323 .init = tegra30_fuse_init,
324 .info = &tegra186_fuse_info,
325 .lookups = tegra186_fuse_lookups,
326 .num_lookups = ARRAY_SIZE(tegra186_fuse_lookups),
327 .soc_attr_group = &tegra_soc_attr_group,
331 #if defined(CONFIG_ARCH_TEGRA_194_SOC)
332 static const struct nvmem_cell_lookup tegra194_fuse_lookups[] = {
334 .nvmem_name = "fuse",
335 .cell_name = "xusb-pad-calibration",
336 .dev_id = "3520000.padctl",
337 .con_id = "calibration",
339 .nvmem_name = "fuse",
340 .cell_name = "xusb-pad-calibration-ext",
341 .dev_id = "3520000.padctl",
342 .con_id = "calibration-ext",
346 static const struct tegra_fuse_info tegra194_fuse_info = {
347 .read = tegra30_fuse_read,
352 const struct tegra_fuse_soc tegra194_fuse_soc = {
353 .init = tegra30_fuse_init,
354 .info = &tegra194_fuse_info,
355 .lookups = tegra194_fuse_lookups,
356 .num_lookups = ARRAY_SIZE(tegra194_fuse_lookups),
357 .soc_attr_group = &tegra194_soc_attr_group,
361 #if defined(CONFIG_ARCH_TEGRA_234_SOC)
362 static const struct nvmem_cell_lookup tegra234_fuse_lookups[] = {
364 .nvmem_name = "fuse",
365 .cell_name = "xusb-pad-calibration",
366 .dev_id = "3520000.padctl",
367 .con_id = "calibration",
369 .nvmem_name = "fuse",
370 .cell_name = "xusb-pad-calibration-ext",
371 .dev_id = "3520000.padctl",
372 .con_id = "calibration-ext",
376 static const struct tegra_fuse_info tegra234_fuse_info = {
377 .read = tegra30_fuse_read,
382 const struct tegra_fuse_soc tegra234_fuse_soc = {
383 .init = tegra30_fuse_init,
384 .info = &tegra234_fuse_info,
385 .lookups = tegra234_fuse_lookups,
386 .num_lookups = ARRAY_SIZE(tegra234_fuse_lookups),
387 .soc_attr_group = &tegra194_soc_attr_group,