1 // SPDX-License-Identifier: GPL-2.0-only
3 * Copyright (c) 2013-2022, NVIDIA CORPORATION. All rights reserved.
6 #include <linux/device.h>
10 #include <linux/kernel.h>
11 #include <linux/nvmem-consumer.h>
12 #include <linux/nvmem-provider.h>
13 #include <linux/of_device.h>
14 #include <linux/of_address.h>
15 #include <linux/platform_device.h>
16 #include <linux/pm_runtime.h>
17 #include <linux/random.h>
19 #include <soc/tegra/fuse.h>
23 #define FUSE_BEGIN 0x100
25 /* Tegra30 and later */
26 #define FUSE_VENDOR_CODE 0x100
27 #define FUSE_FAB_CODE 0x104
28 #define FUSE_LOT_CODE_0 0x108
29 #define FUSE_LOT_CODE_1 0x10c
30 #define FUSE_WAFER_ID 0x110
31 #define FUSE_X_COORDINATE 0x114
32 #define FUSE_Y_COORDINATE 0x118
34 #define FUSE_HAS_REVISION_INFO BIT(0)
36 #if defined(CONFIG_ARCH_TEGRA_3x_SOC) || \
37 defined(CONFIG_ARCH_TEGRA_114_SOC) || \
38 defined(CONFIG_ARCH_TEGRA_124_SOC) || \
39 defined(CONFIG_ARCH_TEGRA_132_SOC) || \
40 defined(CONFIG_ARCH_TEGRA_210_SOC) || \
41 defined(CONFIG_ARCH_TEGRA_186_SOC) || \
42 defined(CONFIG_ARCH_TEGRA_194_SOC) || \
43 defined(CONFIG_ARCH_TEGRA_234_SOC)
44 static u32 tegra30_fuse_read_early(struct tegra_fuse *fuse, unsigned int offset)
46 if (WARN_ON(!fuse->base))
49 return readl_relaxed(fuse->base + FUSE_BEGIN + offset);
52 static u32 tegra30_fuse_read(struct tegra_fuse *fuse, unsigned int offset)
57 err = pm_runtime_resume_and_get(fuse->dev);
61 value = readl_relaxed(fuse->base + FUSE_BEGIN + offset);
63 pm_runtime_put(fuse->dev);
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,
116 .clk_suspend_on = false,
120 #ifdef CONFIG_ARCH_TEGRA_114_SOC
121 static const struct tegra_fuse_info tegra114_fuse_info = {
122 .read = tegra30_fuse_read,
127 const struct tegra_fuse_soc tegra114_fuse_soc = {
128 .init = tegra30_fuse_init,
129 .speedo_init = tegra114_init_speedo_data,
130 .info = &tegra114_fuse_info,
131 .soc_attr_group = &tegra_soc_attr_group,
132 .clk_suspend_on = false,
136 #if defined(CONFIG_ARCH_TEGRA_124_SOC) || defined(CONFIG_ARCH_TEGRA_132_SOC)
137 static const struct nvmem_cell_info tegra124_fuse_cells[] = {
139 .name = "tsensor-cpu1",
145 .name = "tsensor-cpu2",
151 .name = "tsensor-cpu0",
157 .name = "xusb-pad-calibration",
163 .name = "tsensor-cpu3",
169 .name = "sata-calibration",
175 .name = "tsensor-gpu",
181 .name = "tsensor-mem0",
187 .name = "tsensor-mem1",
193 .name = "tsensor-pllx",
199 .name = "tsensor-common",
205 .name = "tsensor-realignment",
213 static const struct nvmem_cell_lookup tegra124_fuse_lookups[] = {
215 .nvmem_name = "fuse",
216 .cell_name = "xusb-pad-calibration",
217 .dev_id = "7009f000.padctl",
218 .con_id = "calibration",
220 .nvmem_name = "fuse",
221 .cell_name = "sata-calibration",
222 .dev_id = "70020000.sata",
223 .con_id = "calibration",
225 .nvmem_name = "fuse",
226 .cell_name = "tsensor-common",
227 .dev_id = "700e2000.thermal-sensor",
230 .nvmem_name = "fuse",
231 .cell_name = "tsensor-realignment",
232 .dev_id = "700e2000.thermal-sensor",
233 .con_id = "realignment",
235 .nvmem_name = "fuse",
236 .cell_name = "tsensor-cpu0",
237 .dev_id = "700e2000.thermal-sensor",
240 .nvmem_name = "fuse",
241 .cell_name = "tsensor-cpu1",
242 .dev_id = "700e2000.thermal-sensor",
245 .nvmem_name = "fuse",
246 .cell_name = "tsensor-cpu2",
247 .dev_id = "700e2000.thermal-sensor",
250 .nvmem_name = "fuse",
251 .cell_name = "tsensor-cpu3",
252 .dev_id = "700e2000.thermal-sensor",
255 .nvmem_name = "fuse",
256 .cell_name = "tsensor-mem0",
257 .dev_id = "700e2000.thermal-sensor",
260 .nvmem_name = "fuse",
261 .cell_name = "tsensor-mem1",
262 .dev_id = "700e2000.thermal-sensor",
265 .nvmem_name = "fuse",
266 .cell_name = "tsensor-gpu",
267 .dev_id = "700e2000.thermal-sensor",
270 .nvmem_name = "fuse",
271 .cell_name = "tsensor-pllx",
272 .dev_id = "700e2000.thermal-sensor",
277 static const struct tegra_fuse_info tegra124_fuse_info = {
278 .read = tegra30_fuse_read,
283 const struct tegra_fuse_soc tegra124_fuse_soc = {
284 .init = tegra30_fuse_init,
285 .speedo_init = tegra124_init_speedo_data,
286 .info = &tegra124_fuse_info,
287 .lookups = tegra124_fuse_lookups,
288 .num_lookups = ARRAY_SIZE(tegra124_fuse_lookups),
289 .cells = tegra124_fuse_cells,
290 .num_cells = ARRAY_SIZE(tegra124_fuse_cells),
291 .soc_attr_group = &tegra_soc_attr_group,
292 .clk_suspend_on = true,
296 #if defined(CONFIG_ARCH_TEGRA_210_SOC)
297 static const struct nvmem_cell_info tegra210_fuse_cells[] = {
299 .name = "tsensor-cpu1",
305 .name = "tsensor-cpu2",
311 .name = "tsensor-cpu0",
317 .name = "xusb-pad-calibration",
323 .name = "tsensor-cpu3",
329 .name = "sata-calibration",
335 .name = "tsensor-gpu",
341 .name = "tsensor-mem0",
347 .name = "tsensor-mem1",
353 .name = "tsensor-pllx",
359 .name = "tsensor-common",
365 .name = "gpu-calibration",
371 .name = "xusb-pad-calibration-ext",
379 static const struct nvmem_cell_lookup tegra210_fuse_lookups[] = {
381 .nvmem_name = "fuse",
382 .cell_name = "tsensor-cpu1",
383 .dev_id = "700e2000.thermal-sensor",
386 .nvmem_name = "fuse",
387 .cell_name = "tsensor-cpu2",
388 .dev_id = "700e2000.thermal-sensor",
391 .nvmem_name = "fuse",
392 .cell_name = "tsensor-cpu0",
393 .dev_id = "700e2000.thermal-sensor",
396 .nvmem_name = "fuse",
397 .cell_name = "xusb-pad-calibration",
398 .dev_id = "7009f000.padctl",
399 .con_id = "calibration",
401 .nvmem_name = "fuse",
402 .cell_name = "tsensor-cpu3",
403 .dev_id = "700e2000.thermal-sensor",
406 .nvmem_name = "fuse",
407 .cell_name = "sata-calibration",
408 .dev_id = "70020000.sata",
409 .con_id = "calibration",
411 .nvmem_name = "fuse",
412 .cell_name = "tsensor-gpu",
413 .dev_id = "700e2000.thermal-sensor",
416 .nvmem_name = "fuse",
417 .cell_name = "tsensor-mem0",
418 .dev_id = "700e2000.thermal-sensor",
421 .nvmem_name = "fuse",
422 .cell_name = "tsensor-mem1",
423 .dev_id = "700e2000.thermal-sensor",
426 .nvmem_name = "fuse",
427 .cell_name = "tsensor-pllx",
428 .dev_id = "700e2000.thermal-sensor",
431 .nvmem_name = "fuse",
432 .cell_name = "tsensor-common",
433 .dev_id = "700e2000.thermal-sensor",
436 .nvmem_name = "fuse",
437 .cell_name = "gpu-calibration",
438 .dev_id = "57000000.gpu",
439 .con_id = "calibration",
441 .nvmem_name = "fuse",
442 .cell_name = "xusb-pad-calibration-ext",
443 .dev_id = "7009f000.padctl",
444 .con_id = "calibration-ext",
448 static const struct tegra_fuse_info tegra210_fuse_info = {
449 .read = tegra30_fuse_read,
454 const struct tegra_fuse_soc tegra210_fuse_soc = {
455 .init = tegra30_fuse_init,
456 .speedo_init = tegra210_init_speedo_data,
457 .info = &tegra210_fuse_info,
458 .lookups = tegra210_fuse_lookups,
459 .cells = tegra210_fuse_cells,
460 .num_cells = ARRAY_SIZE(tegra210_fuse_cells),
461 .num_lookups = ARRAY_SIZE(tegra210_fuse_lookups),
462 .soc_attr_group = &tegra_soc_attr_group,
463 .clk_suspend_on = false,
467 #if defined(CONFIG_ARCH_TEGRA_186_SOC)
468 static const struct nvmem_cell_info tegra186_fuse_cells[] = {
470 .name = "xusb-pad-calibration",
476 .name = "xusb-pad-calibration-ext",
484 static const struct nvmem_cell_lookup tegra186_fuse_lookups[] = {
486 .nvmem_name = "fuse",
487 .cell_name = "xusb-pad-calibration",
488 .dev_id = "3520000.padctl",
489 .con_id = "calibration",
491 .nvmem_name = "fuse",
492 .cell_name = "xusb-pad-calibration-ext",
493 .dev_id = "3520000.padctl",
494 .con_id = "calibration-ext",
498 static const struct nvmem_keepout tegra186_fuse_keepouts[] = {
499 { .start = 0x01c, .end = 0x0f0 },
500 { .start = 0x138, .end = 0x198 },
501 { .start = 0x1d8, .end = 0x250 },
502 { .start = 0x280, .end = 0x290 },
503 { .start = 0x340, .end = 0x344 }
506 static const struct tegra_fuse_info tegra186_fuse_info = {
507 .read = tegra30_fuse_read,
512 const struct tegra_fuse_soc tegra186_fuse_soc = {
513 .init = tegra30_fuse_init,
514 .info = &tegra186_fuse_info,
515 .lookups = tegra186_fuse_lookups,
516 .num_lookups = ARRAY_SIZE(tegra186_fuse_lookups),
517 .cells = tegra186_fuse_cells,
518 .num_cells = ARRAY_SIZE(tegra186_fuse_cells),
519 .keepouts = tegra186_fuse_keepouts,
520 .num_keepouts = ARRAY_SIZE(tegra186_fuse_keepouts),
521 .soc_attr_group = &tegra_soc_attr_group,
522 .clk_suspend_on = false,
526 #if defined(CONFIG_ARCH_TEGRA_194_SOC)
527 static const struct nvmem_cell_info tegra194_fuse_cells[] = {
529 .name = "xusb-pad-calibration",
535 .name = "gpu-gcplex-config-fuse",
541 .name = "xusb-pad-calibration-ext",
561 static const struct nvmem_cell_lookup tegra194_fuse_lookups[] = {
563 .nvmem_name = "fuse",
564 .cell_name = "xusb-pad-calibration",
565 .dev_id = "3520000.padctl",
566 .con_id = "calibration",
568 .nvmem_name = "fuse",
569 .cell_name = "xusb-pad-calibration-ext",
570 .dev_id = "3520000.padctl",
571 .con_id = "calibration-ext",
573 .nvmem_name = "fuse",
574 .cell_name = "gpu-gcplex-config-fuse",
575 .dev_id = "17000000.gpu",
576 .con_id = "gcplex-config-fuse",
578 .nvmem_name = "fuse",
579 .cell_name = "gpu-pdi0",
580 .dev_id = "17000000.gpu",
583 .nvmem_name = "fuse",
584 .cell_name = "gpu-pdi1",
585 .dev_id = "17000000.gpu",
590 static const struct nvmem_keepout tegra194_fuse_keepouts[] = {
591 { .start = 0x01c, .end = 0x0b8 },
592 { .start = 0x12c, .end = 0x198 },
593 { .start = 0x1a0, .end = 0x1bc },
594 { .start = 0x1d8, .end = 0x250 },
595 { .start = 0x270, .end = 0x290 },
596 { .start = 0x310, .end = 0x45c }
599 static const struct tegra_fuse_info tegra194_fuse_info = {
600 .read = tegra30_fuse_read,
605 const struct tegra_fuse_soc tegra194_fuse_soc = {
606 .init = tegra30_fuse_init,
607 .info = &tegra194_fuse_info,
608 .lookups = tegra194_fuse_lookups,
609 .num_lookups = ARRAY_SIZE(tegra194_fuse_lookups),
610 .cells = tegra194_fuse_cells,
611 .num_cells = ARRAY_SIZE(tegra194_fuse_cells),
612 .keepouts = tegra194_fuse_keepouts,
613 .num_keepouts = ARRAY_SIZE(tegra194_fuse_keepouts),
614 .soc_attr_group = &tegra194_soc_attr_group,
615 .clk_suspend_on = false,
619 #if defined(CONFIG_ARCH_TEGRA_234_SOC)
620 static const struct nvmem_cell_info tegra234_fuse_cells[] = {
622 .name = "xusb-pad-calibration",
628 .name = "xusb-pad-calibration-ext",
636 static const struct nvmem_cell_lookup tegra234_fuse_lookups[] = {
638 .nvmem_name = "fuse",
639 .cell_name = "xusb-pad-calibration",
640 .dev_id = "3520000.padctl",
641 .con_id = "calibration",
643 .nvmem_name = "fuse",
644 .cell_name = "xusb-pad-calibration-ext",
645 .dev_id = "3520000.padctl",
646 .con_id = "calibration-ext",
650 static const struct nvmem_keepout tegra234_fuse_keepouts[] = {
651 { .start = 0x01c, .end = 0x0c8 },
652 { .start = 0x12c, .end = 0x184 },
653 { .start = 0x190, .end = 0x198 },
654 { .start = 0x1a0, .end = 0x204 },
655 { .start = 0x21c, .end = 0x250 },
656 { .start = 0x25c, .end = 0x2f0 },
657 { .start = 0x310, .end = 0x3d8 },
658 { .start = 0x400, .end = 0x4f0 },
659 { .start = 0x4f8, .end = 0x7e8 },
660 { .start = 0x8d0, .end = 0x8d8 },
661 { .start = 0xacc, .end = 0xf00 }
664 static const struct tegra_fuse_info tegra234_fuse_info = {
665 .read = tegra30_fuse_read,
670 const struct tegra_fuse_soc tegra234_fuse_soc = {
671 .init = tegra30_fuse_init,
672 .info = &tegra234_fuse_info,
673 .lookups = tegra234_fuse_lookups,
674 .num_lookups = ARRAY_SIZE(tegra234_fuse_lookups),
675 .cells = tegra234_fuse_cells,
676 .num_cells = ARRAY_SIZE(tegra234_fuse_cells),
677 .keepouts = tegra234_fuse_keepouts,
678 .num_keepouts = ARRAY_SIZE(tegra234_fuse_keepouts),
679 .soc_attr_group = &tegra194_soc_attr_group,
680 .clk_suspend_on = false,