blob: 23f8a4b5ca42a4fe9d52d6b58c53af8268f44aac [file] [log] [blame]
Peter De Schrijver783c8f42014-06-12 18:36:37 +03001/*
2 * Copyright (c) 2013-2014, NVIDIA CORPORATION. All rights reserved.
3 *
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.
7 *
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
11 * more details.
12 *
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/>.
15 *
16 */
17
18#include <linux/device.h>
19#include <linux/clk.h>
20#include <linux/err.h>
21#include <linux/io.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>
27
28#include <soc/tegra/fuse.h>
29
30#include "fuse.h"
31
32#define FUSE_BEGIN 0x100
33
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
42
43#define FUSE_HAS_REVISION_INFO BIT(0)
44
Thierry Reding7e939de2015-04-29 16:54:04 +020045#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)
49static u32 tegra30_fuse_read_early(struct tegra_fuse *fuse, unsigned int offset)
Peter De Schrijver783c8f42014-06-12 18:36:37 +030050{
Thierry Reding7e939de2015-04-29 16:54:04 +020051 return readl_relaxed(fuse->base + FUSE_BEGIN + offset);
Peter De Schrijver783c8f42014-06-12 18:36:37 +030052}
53
Thierry Reding7e939de2015-04-29 16:54:04 +020054static u32 tegra30_fuse_read(struct tegra_fuse *fuse, unsigned int offset)
Peter De Schrijver783c8f42014-06-12 18:36:37 +030055{
Thierry Reding7e939de2015-04-29 16:54:04 +020056 u32 value;
57 int err;
Peter De Schrijver783c8f42014-06-12 18:36:37 +030058
Thierry Reding7e939de2015-04-29 16:54:04 +020059 err = clk_prepare_enable(fuse->clk);
60 if (err < 0) {
61 dev_err(fuse->dev, "failed to enable FUSE clock: %d\n", err);
62 return 0;
Peter De Schrijver783c8f42014-06-12 18:36:37 +030063 }
64
Thierry Reding7e939de2015-04-29 16:54:04 +020065 value = readl_relaxed(fuse->base + FUSE_BEGIN + offset);
Peter De Schrijver783c8f42014-06-12 18:36:37 +030066
Thierry Reding7e939de2015-04-29 16:54:04 +020067 clk_disable_unprepare(fuse->clk);
Peter De Schrijver783c8f42014-06-12 18:36:37 +030068
Thierry Reding7e939de2015-04-29 16:54:04 +020069 return value;
Peter De Schrijver783c8f42014-06-12 18:36:37 +030070}
71
Peter De Schrijver783c8f42014-06-12 18:36:37 +030072static void __init tegra30_fuse_add_randomness(void)
73{
74 u32 randomness[12];
75
76 randomness[0] = tegra_sku_info.sku_id;
77 randomness[1] = tegra_read_straps();
78 randomness[2] = tegra_read_chipid();
79 randomness[3] = tegra_sku_info.cpu_process_id << 16;
80 randomness[3] |= tegra_sku_info.core_process_id;
81 randomness[4] = tegra_sku_info.cpu_speedo_id << 16;
82 randomness[4] |= tegra_sku_info.soc_speedo_id;
Thierry Reding7e939de2015-04-29 16:54:04 +020083 randomness[5] = tegra_fuse_read_early(FUSE_VENDOR_CODE);
84 randomness[6] = tegra_fuse_read_early(FUSE_FAB_CODE);
85 randomness[7] = tegra_fuse_read_early(FUSE_LOT_CODE_0);
86 randomness[8] = tegra_fuse_read_early(FUSE_LOT_CODE_1);
87 randomness[9] = tegra_fuse_read_early(FUSE_WAFER_ID);
88 randomness[10] = tegra_fuse_read_early(FUSE_X_COORDINATE);
89 randomness[11] = tegra_fuse_read_early(FUSE_Y_COORDINATE);
Peter De Schrijver783c8f42014-06-12 18:36:37 +030090
91 add_device_randomness(randomness, sizeof(randomness));
92}
93
Thierry Reding7e939de2015-04-29 16:54:04 +020094static void __init tegra30_fuse_init(struct tegra_fuse *fuse)
Peter De Schrijver783c8f42014-06-12 18:36:37 +030095{
Thierry Reding7e939de2015-04-29 16:54:04 +020096 fuse->read_early = tegra30_fuse_read_early;
97 fuse->read = tegra30_fuse_read;
Peter De Schrijver783c8f42014-06-12 18:36:37 +030098
99 tegra_init_revision();
Thierry Reding7e939de2015-04-29 16:54:04 +0200100 fuse->soc->speedo_init(&tegra_sku_info);
Peter De Schrijver783c8f42014-06-12 18:36:37 +0300101 tegra30_fuse_add_randomness();
102}
Thierry Reding7e939de2015-04-29 16:54:04 +0200103#endif
104
105#ifdef CONFIG_ARCH_TEGRA_3x_SOC
106static const struct tegra_fuse_info tegra30_fuse_info = {
107 .read = tegra30_fuse_read,
108 .size = 0x2a4,
109 .spare = 0x144,
110};
111
112const struct tegra_fuse_soc tegra30_fuse_soc = {
113 .init = tegra30_fuse_init,
114 .speedo_init = tegra30_init_speedo_data,
115 .info = &tegra30_fuse_info,
116};
117#endif
118
119#ifdef CONFIG_ARCH_TEGRA_114_SOC
120static const struct tegra_fuse_info tegra114_fuse_info = {
121 .read = tegra30_fuse_read,
122 .size = 0x2a0,
123};
124
125const struct tegra_fuse_soc tegra114_fuse_soc = {
126 .init = tegra30_fuse_init,
127 .speedo_init = tegra114_init_speedo_data,
128 .info = &tegra114_fuse_info,
129};
130#endif
131
132#if defined(CONFIG_ARCH_TEGRA_124_SOC) || defined(CONFIG_ARCH_TEGRA_132_SOC)
133static const struct tegra_fuse_info tegra124_fuse_info = {
134 .read = tegra30_fuse_read,
135 .size = 0x300,
136};
137
138const struct tegra_fuse_soc tegra124_fuse_soc = {
139 .init = tegra30_fuse_init,
140 .speedo_init = tegra124_init_speedo_data,
141 .info = &tegra124_fuse_info,
142};
143#endif