2 * Copyright (c) 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/kernel.h>
20 #include <linux/of_address.h>
23 #include <soc/tegra/fuse.h>
24 #include <soc/tegra/common.h>
28 #define FUSE_SKU_INFO 0x10
30 #define PMC_STRAPPING_OPT_A_RAM_CODE_SHIFT 4
31 #define PMC_STRAPPING_OPT_A_RAM_CODE_MASK_LONG \
32 (0xf << PMC_STRAPPING_OPT_A_RAM_CODE_SHIFT)
33 #define PMC_STRAPPING_OPT_A_RAM_CODE_MASK_SHORT \
34 (0x3 << PMC_STRAPPING_OPT_A_RAM_CODE_SHIFT)
36 static void __iomem
*apbmisc_base
;
37 static void __iomem
*strapping_base
;
38 static bool long_ram_code
;
40 u32
tegra_read_chipid(void)
43 WARN(1, "Tegra Chip ID not yet available\n");
47 return readl_relaxed(apbmisc_base
+ 4);
50 u8
tegra_get_chip_id(void)
52 return (tegra_read_chipid() >> 8) & 0xff;
55 u32
tegra_read_straps(void)
58 return readl_relaxed(strapping_base
);
63 u32
tegra_read_ram_code(void)
65 u32 straps
= tegra_read_straps();
68 straps
&= PMC_STRAPPING_OPT_A_RAM_CODE_MASK_LONG
;
70 straps
&= PMC_STRAPPING_OPT_A_RAM_CODE_MASK_SHORT
;
72 return straps
>> PMC_STRAPPING_OPT_A_RAM_CODE_SHIFT
;
75 static const struct of_device_id apbmisc_match
[] __initconst
= {
76 { .compatible
= "nvidia,tegra20-apbmisc", },
77 { .compatible
= "nvidia,tegra186-misc", },
81 void __init
tegra_init_revision(void)
83 u32 id
, chip_id
, minor_rev
;
86 id
= tegra_read_chipid();
87 chip_id
= (id
>> 8) & 0xff;
88 minor_rev
= (id
>> 16) & 0xf;
92 rev
= TEGRA_REVISION_A01
;
95 rev
= TEGRA_REVISION_A02
;
98 if (chip_id
== TEGRA20
&& (tegra_fuse_read_spare(18) ||
99 tegra_fuse_read_spare(19)))
100 rev
= TEGRA_REVISION_A03p
;
102 rev
= TEGRA_REVISION_A03
;
105 rev
= TEGRA_REVISION_A04
;
108 rev
= TEGRA_REVISION_UNKNOWN
;
111 tegra_sku_info
.revision
= rev
;
113 tegra_sku_info
.sku_id
= tegra_fuse_read_early(FUSE_SKU_INFO
);
116 void __init
tegra_init_apbmisc(void)
118 struct resource apbmisc
, straps
;
119 struct device_node
*np
;
121 np
= of_find_matching_node(NULL
, apbmisc_match
);
124 * Fall back to legacy initialization for 32-bit ARM only. All
125 * 64-bit ARM device tree files for Tegra are required to have
128 * This is for backwards-compatibility with old device trees
129 * that didn't contain an APBMISC node.
131 if (IS_ENABLED(CONFIG_ARM
) && soc_is_tegra()) {
132 /* APBMISC registers (chip revision, ...) */
133 apbmisc
.start
= 0x70000800;
134 apbmisc
.end
= 0x70000863;
135 apbmisc
.flags
= IORESOURCE_MEM
;
137 /* strapping options */
138 if (tegra_get_chip_id() == TEGRA124
) {
139 straps
.start
= 0x7000e864;
140 straps
.end
= 0x7000e867;
142 straps
.start
= 0x70000008;
143 straps
.end
= 0x7000000b;
146 straps
.flags
= IORESOURCE_MEM
;
148 pr_warn("Using APBMISC region %pR\n", &apbmisc
);
149 pr_warn("Using strapping options registers %pR\n",
153 * At this point we're not running on Tegra, so play
154 * nice with multi-platform kernels.
160 * Extract information from the device tree if we've found a
163 if (of_address_to_resource(np
, 0, &apbmisc
) < 0) {
164 pr_err("failed to get APBMISC registers\n");
168 if (of_address_to_resource(np
, 1, &straps
) < 0) {
169 pr_err("failed to get strapping options registers\n");
174 apbmisc_base
= ioremap_nocache(apbmisc
.start
, resource_size(&apbmisc
));
176 pr_err("failed to map APBMISC registers\n");
178 strapping_base
= ioremap_nocache(straps
.start
, resource_size(&straps
));
180 pr_err("failed to map strapping options registers\n");
182 long_ram_code
= of_property_read_bool(np
, "nvidia,long-ram-code");