forked from ~ljy/RK356X_SDK_RELEASE

hc
2024-05-10 37f49e37ab4cb5d0bc4c60eb5c6d4dd57db767bb
kernel/drivers/soc/tegra/fuse/tegra-apbmisc.c
....@@ -1,18 +1,6 @@
1
+// SPDX-License-Identifier: GPL-2.0-only
12 /*
23 * Copyright (c) 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
- *
164 */
175
186 #include <linux/kernel.h>
....@@ -33,18 +21,15 @@
3321 #define PMC_STRAPPING_OPT_A_RAM_CODE_MASK_SHORT \
3422 (0x3 << PMC_STRAPPING_OPT_A_RAM_CODE_SHIFT)
3523
36
-static void __iomem *apbmisc_base;
37
-static void __iomem *strapping_base;
3824 static bool long_ram_code;
25
+static u32 strapping;
26
+static u32 chipid;
3927
4028 u32 tegra_read_chipid(void)
4129 {
42
- if (!apbmisc_base) {
43
- WARN(1, "Tegra Chip ID not yet available\n");
44
- return 0;
45
- }
30
+ WARN(!chipid, "Tegra APB MISC not yet available\n");
4631
47
- return readl_relaxed(apbmisc_base + 4);
32
+ return chipid;
4833 }
4934
5035 u8 tegra_get_chip_id(void)
....@@ -52,12 +37,46 @@
5237 return (tegra_read_chipid() >> 8) & 0xff;
5338 }
5439
40
+u8 tegra_get_major_rev(void)
41
+{
42
+ return (tegra_read_chipid() >> 4) & 0xf;
43
+}
44
+
45
+u8 tegra_get_minor_rev(void)
46
+{
47
+ return (tegra_read_chipid() >> 16) & 0xf;
48
+}
49
+
50
+u8 tegra_get_platform(void)
51
+{
52
+ return (tegra_read_chipid() >> 20) & 0xf;
53
+}
54
+
55
+bool tegra_is_silicon(void)
56
+{
57
+ switch (tegra_get_chip_id()) {
58
+ case TEGRA194:
59
+ case TEGRA234:
60
+ if (tegra_get_platform() == 0)
61
+ return true;
62
+
63
+ return false;
64
+ }
65
+
66
+ /*
67
+ * Chips prior to Tegra194 have a different way of determining whether
68
+ * they are silicon or not. Since we never supported simulation on the
69
+ * older Tegra chips, don't bother extracting the information and just
70
+ * report that we're running on silicon.
71
+ */
72
+ return true;
73
+}
74
+
5575 u32 tegra_read_straps(void)
5676 {
57
- if (strapping_base)
58
- return readl_relaxed(strapping_base);
59
- else
60
- return 0;
77
+ WARN(!chipid, "Tegra ABP MISC not yet available\n");
78
+
79
+ return strapping;
6180 }
6281
6382 u32 tegra_read_ram_code(void)
....@@ -75,46 +94,45 @@
7594 static const struct of_device_id apbmisc_match[] __initconst = {
7695 { .compatible = "nvidia,tegra20-apbmisc", },
7796 { .compatible = "nvidia,tegra186-misc", },
97
+ { .compatible = "nvidia,tegra194-misc", },
98
+ { .compatible = "nvidia,tegra234-misc", },
7899 {},
79100 };
80101
81102 void __init tegra_init_revision(void)
82103 {
83
- u32 id, chip_id, minor_rev;
84
- int rev;
104
+ u8 chip_id, minor_rev;
85105
86
- id = tegra_read_chipid();
87
- chip_id = (id >> 8) & 0xff;
88
- minor_rev = (id >> 16) & 0xf;
106
+ chip_id = tegra_get_chip_id();
107
+ minor_rev = tegra_get_minor_rev();
89108
90109 switch (minor_rev) {
91110 case 1:
92
- rev = TEGRA_REVISION_A01;
111
+ tegra_sku_info.revision = TEGRA_REVISION_A01;
93112 break;
94113 case 2:
95
- rev = TEGRA_REVISION_A02;
114
+ tegra_sku_info.revision = TEGRA_REVISION_A02;
96115 break;
97116 case 3:
98117 if (chip_id == TEGRA20 && (tegra_fuse_read_spare(18) ||
99118 tegra_fuse_read_spare(19)))
100
- rev = TEGRA_REVISION_A03p;
119
+ tegra_sku_info.revision = TEGRA_REVISION_A03p;
101120 else
102
- rev = TEGRA_REVISION_A03;
121
+ tegra_sku_info.revision = TEGRA_REVISION_A03;
103122 break;
104123 case 4:
105
- rev = TEGRA_REVISION_A04;
124
+ tegra_sku_info.revision = TEGRA_REVISION_A04;
106125 break;
107126 default:
108
- rev = TEGRA_REVISION_UNKNOWN;
127
+ tegra_sku_info.revision = TEGRA_REVISION_UNKNOWN;
109128 }
110
-
111
- tegra_sku_info.revision = rev;
112129
113130 tegra_sku_info.sku_id = tegra_fuse_read_early(FUSE_SKU_INFO);
114131 }
115132
116133 void __init tegra_init_apbmisc(void)
117134 {
135
+ void __iomem *apbmisc_base, *strapping_base;
118136 struct resource apbmisc, straps;
119137 struct device_node *np;
120138
....@@ -171,13 +189,21 @@
171189 }
172190 }
173191
174
- apbmisc_base = ioremap_nocache(apbmisc.start, resource_size(&apbmisc));
175
- if (!apbmisc_base)
192
+ apbmisc_base = ioremap(apbmisc.start, resource_size(&apbmisc));
193
+ if (!apbmisc_base) {
176194 pr_err("failed to map APBMISC registers\n");
195
+ } else {
196
+ chipid = readl_relaxed(apbmisc_base + 4);
197
+ iounmap(apbmisc_base);
198
+ }
177199
178
- strapping_base = ioremap_nocache(straps.start, resource_size(&straps));
179
- if (!strapping_base)
200
+ strapping_base = ioremap(straps.start, resource_size(&straps));
201
+ if (!strapping_base) {
180202 pr_err("failed to map strapping options registers\n");
203
+ } else {
204
+ strapping = readl_relaxed(strapping_base);
205
+ iounmap(strapping_base);
206
+ }
181207
182208 long_ram_code = of_property_read_bool(np, "nvidia,long-ram-code");
183209 }