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/platform_device.h>
14 #include <linux/pm_runtime.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 defined(CONFIG_ARCH_TEGRA_241_SOC)
43 static u32 tegra30_fuse_read_early(struct tegra_fuse *fuse, unsigned int offset)
45 if (WARN_ON(!fuse->base))
48 return readl_relaxed(fuse->base + FUSE_BEGIN + offset);
51 static u32 tegra30_fuse_read(struct tegra_fuse *fuse, unsigned int offset)
56 err = pm_runtime_resume_and_get(fuse->dev);
60 value = readl_relaxed(fuse->base + FUSE_BEGIN + offset);
62 pm_runtime_put(fuse->dev);
67 static void __init tegra30_fuse_add_randomness(void)
71 randomness[0] = tegra_sku_info.sku_id;
72 randomness[1] = tegra_read_straps();
73 randomness[2] = tegra_read_chipid();
74 randomness[3] = tegra_sku_info.cpu_process_id << 16;
75 randomness[3] |= tegra_sku_info.soc_process_id;
76 randomness[4] = tegra_sku_info.cpu_speedo_id << 16;
77 randomness[4] |= tegra_sku_info.soc_speedo_id;
78 randomness[5] = tegra_fuse_read_early(FUSE_VENDOR_CODE);
79 randomness[6] = tegra_fuse_read_early(FUSE_FAB_CODE);
80 randomness[7] = tegra_fuse_read_early(FUSE_LOT_CODE_0);
81 randomness[8] = tegra_fuse_read_early(FUSE_LOT_CODE_1);
82 randomness[9] = tegra_fuse_read_early(FUSE_WAFER_ID);
83 randomness[10] = tegra_fuse_read_early(FUSE_X_COORDINATE);
84 randomness[11] = tegra_fuse_read_early(FUSE_Y_COORDINATE);
86 add_device_randomness(randomness, sizeof(randomness));
89 static void __init tegra30_fuse_init(struct tegra_fuse *fuse)
91 fuse->read_early = tegra30_fuse_read_early;
92 fuse->read = tegra30_fuse_read;
94 tegra_init_revision();
96 if (fuse->soc->speedo_init)
97 fuse->soc->speedo_init(&tegra_sku_info);
99 tegra30_fuse_add_randomness();
103 #ifdef CONFIG_ARCH_TEGRA_3x_SOC
104 static const struct tegra_fuse_info tegra30_fuse_info = {
105 .read = tegra30_fuse_read,
110 const struct tegra_fuse_soc tegra30_fuse_soc = {
111 .init = tegra30_fuse_init,
112 .speedo_init = tegra30_init_speedo_data,
113 .info = &tegra30_fuse_info,
114 .soc_attr_group = &tegra_soc_attr_group,
115 .clk_suspend_on = false,
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,
131 .clk_suspend_on = false,
135 #if defined(CONFIG_ARCH_TEGRA_124_SOC) || defined(CONFIG_ARCH_TEGRA_132_SOC)
136 static const struct nvmem_cell_info tegra124_fuse_cells[] = {
138 .name = "tsensor-cpu1",
144 .name = "tsensor-cpu2",
150 .name = "tsensor-cpu0",
156 .name = "xusb-pad-calibration",
162 .name = "tsensor-cpu3",
168 .name = "sata-calibration",
174 .name = "tsensor-gpu",
180 .name = "tsensor-mem0",
186 .name = "tsensor-mem1",
192 .name = "tsensor-pllx",
198 .name = "tsensor-common",
204 .name = "tsensor-realignment",
212 static const struct nvmem_cell_lookup tegra124_fuse_lookups[] = {
214 .nvmem_name = "fuse",
215 .cell_name = "xusb-pad-calibration",
216 .dev_id = "7009f000.padctl",
217 .con_id = "calibration",
219 .nvmem_name = "fuse",
220 .cell_name = "sata-calibration",
221 .dev_id = "70020000.sata",
222 .con_id = "calibration",
224 .nvmem_name = "fuse",
225 .cell_name = "tsensor-common",
226 .dev_id = "700e2000.thermal-sensor",
229 .nvmem_name = "fuse",
230 .cell_name = "tsensor-realignment",
231 .dev_id = "700e2000.thermal-sensor",
232 .con_id = "realignment",
234 .nvmem_name = "fuse",
235 .cell_name = "tsensor-cpu0",
236 .dev_id = "700e2000.thermal-sensor",
239 .nvmem_name = "fuse",
240 .cell_name = "tsensor-cpu1",
241 .dev_id = "700e2000.thermal-sensor",
244 .nvmem_name = "fuse",
245 .cell_name = "tsensor-cpu2",
246 .dev_id = "700e2000.thermal-sensor",
249 .nvmem_name = "fuse",
250 .cell_name = "tsensor-cpu3",
251 .dev_id = "700e2000.thermal-sensor",
254 .nvmem_name = "fuse",
255 .cell_name = "tsensor-mem0",
256 .dev_id = "700e2000.thermal-sensor",
259 .nvmem_name = "fuse",
260 .cell_name = "tsensor-mem1",
261 .dev_id = "700e2000.thermal-sensor",
264 .nvmem_name = "fuse",
265 .cell_name = "tsensor-gpu",
266 .dev_id = "700e2000.thermal-sensor",
269 .nvmem_name = "fuse",
270 .cell_name = "tsensor-pllx",
271 .dev_id = "700e2000.thermal-sensor",
276 static const struct tegra_fuse_info tegra124_fuse_info = {
277 .read = tegra30_fuse_read,
282 const struct tegra_fuse_soc tegra124_fuse_soc = {
283 .init = tegra30_fuse_init,
284 .speedo_init = tegra124_init_speedo_data,
285 .info = &tegra124_fuse_info,
286 .lookups = tegra124_fuse_lookups,
287 .num_lookups = ARRAY_SIZE(tegra124_fuse_lookups),
288 .cells = tegra124_fuse_cells,
289 .num_cells = ARRAY_SIZE(tegra124_fuse_cells),
290 .soc_attr_group = &tegra_soc_attr_group,
291 .clk_suspend_on = true,
295 #if defined(CONFIG_ARCH_TEGRA_210_SOC)
296 static const struct nvmem_cell_info tegra210_fuse_cells[] = {
298 .name = "tsensor-cpu1",
304 .name = "tsensor-cpu2",
310 .name = "tsensor-cpu0",
316 .name = "xusb-pad-calibration",
322 .name = "tsensor-cpu3",
328 .name = "sata-calibration",
334 .name = "tsensor-gpu",
340 .name = "tsensor-mem0",
346 .name = "tsensor-mem1",
352 .name = "tsensor-pllx",
358 .name = "tsensor-common",
364 .name = "gpu-calibration",
370 .name = "xusb-pad-calibration-ext",
378 static const struct nvmem_cell_lookup tegra210_fuse_lookups[] = {
380 .nvmem_name = "fuse",
381 .cell_name = "tsensor-cpu1",
382 .dev_id = "700e2000.thermal-sensor",
385 .nvmem_name = "fuse",
386 .cell_name = "tsensor-cpu2",
387 .dev_id = "700e2000.thermal-sensor",
390 .nvmem_name = "fuse",
391 .cell_name = "tsensor-cpu0",
392 .dev_id = "700e2000.thermal-sensor",
395 .nvmem_name = "fuse",
396 .cell_name = "xusb-pad-calibration",
397 .dev_id = "7009f000.padctl",
398 .con_id = "calibration",
400 .nvmem_name = "fuse",
401 .cell_name = "tsensor-cpu3",
402 .dev_id = "700e2000.thermal-sensor",
405 .nvmem_name = "fuse",
406 .cell_name = "sata-calibration",
407 .dev_id = "70020000.sata",
408 .con_id = "calibration",
410 .nvmem_name = "fuse",
411 .cell_name = "tsensor-gpu",
412 .dev_id = "700e2000.thermal-sensor",
415 .nvmem_name = "fuse",
416 .cell_name = "tsensor-mem0",
417 .dev_id = "700e2000.thermal-sensor",
420 .nvmem_name = "fuse",
421 .cell_name = "tsensor-mem1",
422 .dev_id = "700e2000.thermal-sensor",
425 .nvmem_name = "fuse",
426 .cell_name = "tsensor-pllx",
427 .dev_id = "700e2000.thermal-sensor",
430 .nvmem_name = "fuse",
431 .cell_name = "tsensor-common",
432 .dev_id = "700e2000.thermal-sensor",
435 .nvmem_name = "fuse",
436 .cell_name = "gpu-calibration",
437 .dev_id = "57000000.gpu",
438 .con_id = "calibration",
440 .nvmem_name = "fuse",
441 .cell_name = "xusb-pad-calibration-ext",
442 .dev_id = "7009f000.padctl",
443 .con_id = "calibration-ext",
447 static const struct tegra_fuse_info tegra210_fuse_info = {
448 .read = tegra30_fuse_read,
453 const struct tegra_fuse_soc tegra210_fuse_soc = {
454 .init = tegra30_fuse_init,
455 .speedo_init = tegra210_init_speedo_data,
456 .info = &tegra210_fuse_info,
457 .lookups = tegra210_fuse_lookups,
458 .cells = tegra210_fuse_cells,
459 .num_cells = ARRAY_SIZE(tegra210_fuse_cells),
460 .num_lookups = ARRAY_SIZE(tegra210_fuse_lookups),
461 .soc_attr_group = &tegra_soc_attr_group,
462 .clk_suspend_on = false,
466 #if defined(CONFIG_ARCH_TEGRA_186_SOC)
467 static const struct nvmem_cell_info tegra186_fuse_cells[] = {
469 .name = "xusb-pad-calibration",
475 .name = "xusb-pad-calibration-ext",
483 static const struct nvmem_cell_lookup tegra186_fuse_lookups[] = {
485 .nvmem_name = "fuse",
486 .cell_name = "xusb-pad-calibration",
487 .dev_id = "3520000.padctl",
488 .con_id = "calibration",
490 .nvmem_name = "fuse",
491 .cell_name = "xusb-pad-calibration-ext",
492 .dev_id = "3520000.padctl",
493 .con_id = "calibration-ext",
497 static const struct nvmem_keepout tegra186_fuse_keepouts[] = {
498 { .start = 0x01c, .end = 0x0f0 },
499 { .start = 0x138, .end = 0x198 },
500 { .start = 0x1d8, .end = 0x250 },
501 { .start = 0x280, .end = 0x290 },
502 { .start = 0x340, .end = 0x344 }
505 static const struct tegra_fuse_info tegra186_fuse_info = {
506 .read = tegra30_fuse_read,
511 const struct tegra_fuse_soc tegra186_fuse_soc = {
512 .init = tegra30_fuse_init,
513 .info = &tegra186_fuse_info,
514 .lookups = tegra186_fuse_lookups,
515 .num_lookups = ARRAY_SIZE(tegra186_fuse_lookups),
516 .cells = tegra186_fuse_cells,
517 .num_cells = ARRAY_SIZE(tegra186_fuse_cells),
518 .keepouts = tegra186_fuse_keepouts,
519 .num_keepouts = ARRAY_SIZE(tegra186_fuse_keepouts),
520 .soc_attr_group = &tegra_soc_attr_group,
521 .clk_suspend_on = false,
525 #if defined(CONFIG_ARCH_TEGRA_194_SOC)
526 static const struct nvmem_cell_info tegra194_fuse_cells[] = {
528 .name = "xusb-pad-calibration",
534 .name = "gpu-gcplex-config-fuse",
540 .name = "xusb-pad-calibration-ext",
560 static const struct nvmem_cell_lookup tegra194_fuse_lookups[] = {
562 .nvmem_name = "fuse",
563 .cell_name = "xusb-pad-calibration",
564 .dev_id = "3520000.padctl",
565 .con_id = "calibration",
567 .nvmem_name = "fuse",
568 .cell_name = "xusb-pad-calibration-ext",
569 .dev_id = "3520000.padctl",
570 .con_id = "calibration-ext",
572 .nvmem_name = "fuse",
573 .cell_name = "gpu-gcplex-config-fuse",
574 .dev_id = "17000000.gpu",
575 .con_id = "gcplex-config-fuse",
577 .nvmem_name = "fuse",
578 .cell_name = "gpu-pdi0",
579 .dev_id = "17000000.gpu",
582 .nvmem_name = "fuse",
583 .cell_name = "gpu-pdi1",
584 .dev_id = "17000000.gpu",
589 static const struct nvmem_keepout tegra194_fuse_keepouts[] = {
590 { .start = 0x01c, .end = 0x0b8 },
591 { .start = 0x12c, .end = 0x198 },
592 { .start = 0x1a0, .end = 0x1bc },
593 { .start = 0x1d8, .end = 0x250 },
594 { .start = 0x270, .end = 0x290 },
595 { .start = 0x310, .end = 0x45c }
598 static const struct tegra_fuse_info tegra194_fuse_info = {
599 .read = tegra30_fuse_read,
604 const struct tegra_fuse_soc tegra194_fuse_soc = {
605 .init = tegra30_fuse_init,
606 .info = &tegra194_fuse_info,
607 .lookups = tegra194_fuse_lookups,
608 .num_lookups = ARRAY_SIZE(tegra194_fuse_lookups),
609 .cells = tegra194_fuse_cells,
610 .num_cells = ARRAY_SIZE(tegra194_fuse_cells),
611 .keepouts = tegra194_fuse_keepouts,
612 .num_keepouts = ARRAY_SIZE(tegra194_fuse_keepouts),
613 .soc_attr_group = &tegra194_soc_attr_group,
614 .clk_suspend_on = false,
618 #if defined(CONFIG_ARCH_TEGRA_234_SOC)
619 static const struct nvmem_cell_info tegra234_fuse_cells[] = {
621 .name = "xusb-pad-calibration",
627 .name = "xusb-pad-calibration-ext",
635 static const struct nvmem_cell_lookup tegra234_fuse_lookups[] = {
637 .nvmem_name = "fuse",
638 .cell_name = "xusb-pad-calibration",
639 .dev_id = "3520000.padctl",
640 .con_id = "calibration",
642 .nvmem_name = "fuse",
643 .cell_name = "xusb-pad-calibration-ext",
644 .dev_id = "3520000.padctl",
645 .con_id = "calibration-ext",
649 static const struct nvmem_keepout tegra234_fuse_keepouts[] = {
650 { .start = 0x01c, .end = 0x0c8 },
651 { .start = 0x12c, .end = 0x184 },
652 { .start = 0x190, .end = 0x198 },
653 { .start = 0x1a0, .end = 0x204 },
654 { .start = 0x21c, .end = 0x250 },
655 { .start = 0x25c, .end = 0x2f0 },
656 { .start = 0x310, .end = 0x3d8 },
657 { .start = 0x400, .end = 0x4f0 },
658 { .start = 0x4f8, .end = 0x7e8 },
659 { .start = 0x8d0, .end = 0x8d8 },
660 { .start = 0xacc, .end = 0xf00 }
663 static const struct tegra_fuse_info tegra234_fuse_info = {
664 .read = tegra30_fuse_read,
669 const struct tegra_fuse_soc tegra234_fuse_soc = {
670 .init = tegra30_fuse_init,
671 .info = &tegra234_fuse_info,
672 .lookups = tegra234_fuse_lookups,
673 .num_lookups = ARRAY_SIZE(tegra234_fuse_lookups),
674 .cells = tegra234_fuse_cells,
675 .num_cells = ARRAY_SIZE(tegra234_fuse_cells),
676 .keepouts = tegra234_fuse_keepouts,
677 .num_keepouts = ARRAY_SIZE(tegra234_fuse_keepouts),
678 .soc_attr_group = &tegra194_soc_attr_group,
679 .clk_suspend_on = false,
683 #if defined(CONFIG_ARCH_TEGRA_241_SOC)
684 static const struct tegra_fuse_info tegra241_fuse_info = {
685 .read = tegra30_fuse_read,
690 static const struct nvmem_keepout tegra241_fuse_keepouts[] = {
691 { .start = 0xc, .end = 0x1600c }
694 const struct tegra_fuse_soc tegra241_fuse_soc = {
695 .init = tegra30_fuse_init,
696 .info = &tegra241_fuse_info,
697 .keepouts = tegra241_fuse_keepouts,
698 .num_keepouts = ARRAY_SIZE(tegra241_fuse_keepouts),
699 .soc_attr_group = &tegra194_soc_attr_group,