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)
51 struct tegra_fuse_info {
54 enum speedo_idx speedo_idx;
57 static void __iomem *fuse_base;
58 static struct clk *fuse_clk;
59 static struct tegra_fuse_info *fuse_info;
61 u32 tegra30_fuse_readl(const unsigned int offset)
66 * early in the boot, the fuse clock will be enabled by
71 clk_prepare_enable(fuse_clk);
73 val = readl_relaxed(fuse_base + FUSE_BEGIN + offset);
76 clk_disable_unprepare(fuse_clk);
81 static struct tegra_fuse_info tegra30_info = {
84 .speedo_idx = SPEEDO_TEGRA30,
87 static struct tegra_fuse_info tegra114_info = {
89 .speedo_idx = SPEEDO_TEGRA114,
92 static struct tegra_fuse_info tegra124_info = {
94 .speedo_idx = SPEEDO_TEGRA124,
97 static const struct of_device_id tegra30_fuse_of_match[] = {
98 { .compatible = "nvidia,tegra30-efuse", .data = &tegra30_info },
99 { .compatible = "nvidia,tegra114-efuse", .data = &tegra114_info },
100 { .compatible = "nvidia,tegra124-efuse", .data = &tegra124_info },
104 static int tegra30_fuse_probe(struct platform_device *pdev)
106 const struct of_device_id *of_dev_id;
108 of_dev_id = of_match_device(tegra30_fuse_of_match, &pdev->dev);
112 fuse_clk = devm_clk_get(&pdev->dev, NULL);
113 if (IS_ERR(fuse_clk)) {
114 dev_err(&pdev->dev, "missing clock");
115 return PTR_ERR(fuse_clk);
118 platform_set_drvdata(pdev, NULL);
120 if (tegra_fuse_create_sysfs(&pdev->dev, fuse_info->size,
124 dev_dbg(&pdev->dev, "loaded\n");
129 static struct platform_driver tegra30_fuse_driver = {
130 .probe = tegra30_fuse_probe,
132 .name = "tegra_fuse",
133 .of_match_table = tegra30_fuse_of_match,
137 static int __init tegra30_fuse_init(void)
139 return platform_driver_register(&tegra30_fuse_driver);
141 postcore_initcall(tegra30_fuse_init);
143 /* Early boot code. This code is called before the devices are created */
145 typedef void (*speedo_f)(struct tegra_sku_info *sku_info);
147 static speedo_f __initdata speedo_tbl[] = {
148 [SPEEDO_TEGRA30] = tegra30_init_speedo_data,
149 [SPEEDO_TEGRA114] = tegra114_init_speedo_data,
150 [SPEEDO_TEGRA124] = tegra124_init_speedo_data,
153 static void __init tegra30_fuse_add_randomness(void)
157 randomness[0] = tegra_sku_info.sku_id;
158 randomness[1] = tegra_read_straps();
159 randomness[2] = tegra_read_chipid();
160 randomness[3] = tegra_sku_info.cpu_process_id << 16;
161 randomness[3] |= tegra_sku_info.core_process_id;
162 randomness[4] = tegra_sku_info.cpu_speedo_id << 16;
163 randomness[4] |= tegra_sku_info.soc_speedo_id;
164 randomness[5] = tegra30_fuse_readl(FUSE_VENDOR_CODE);
165 randomness[6] = tegra30_fuse_readl(FUSE_FAB_CODE);
166 randomness[7] = tegra30_fuse_readl(FUSE_LOT_CODE_0);
167 randomness[8] = tegra30_fuse_readl(FUSE_LOT_CODE_1);
168 randomness[9] = tegra30_fuse_readl(FUSE_WAFER_ID);
169 randomness[10] = tegra30_fuse_readl(FUSE_X_COORDINATE);
170 randomness[11] = tegra30_fuse_readl(FUSE_Y_COORDINATE);
172 add_device_randomness(randomness, sizeof(randomness));
175 static void __init legacy_fuse_init(void)
177 switch (tegra_get_chip_id()) {
179 fuse_info = &tegra30_info;
182 fuse_info = &tegra114_info;
185 fuse_info = &tegra124_info;
191 fuse_base = ioremap(TEGRA_FUSE_BASE, TEGRA_FUSE_SIZE);
194 bool __init tegra30_spare_fuse(int spare_bit)
196 u32 offset = fuse_info->spare_bit + spare_bit * 4;
198 return tegra30_fuse_readl(offset) & 1;
201 void __init tegra30_init_fuse_early(void)
203 struct device_node *np;
204 const struct of_device_id *of_match;
206 np = of_find_matching_node_and_match(NULL, tegra30_fuse_of_match,
209 fuse_base = of_iomap(np, 0);
210 fuse_info = (struct tegra_fuse_info *)of_match->data;
215 pr_warn("fuse DT node missing and unknown chip id: 0x%02x\n",
216 tegra_get_chip_id());
220 tegra_init_revision();
221 speedo_tbl[fuse_info->speedo_idx](&tegra_sku_info);
222 tegra30_fuse_add_randomness();