| .. | .. |
|---|
| 1 | +// SPDX-License-Identifier: GPL-2.0-only |
|---|
| 1 | 2 | /* |
|---|
| 2 | 3 | * 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 | | - * |
|---|
| 16 | 4 | */ |
|---|
| 17 | 5 | |
|---|
| 18 | 6 | #include <linux/kernel.h> |
|---|
| .. | .. |
|---|
| 33 | 21 | #define PMC_STRAPPING_OPT_A_RAM_CODE_MASK_SHORT \ |
|---|
| 34 | 22 | (0x3 << PMC_STRAPPING_OPT_A_RAM_CODE_SHIFT) |
|---|
| 35 | 23 | |
|---|
| 36 | | -static void __iomem *apbmisc_base; |
|---|
| 37 | | -static void __iomem *strapping_base; |
|---|
| 38 | 24 | static bool long_ram_code; |
|---|
| 25 | +static u32 strapping; |
|---|
| 26 | +static u32 chipid; |
|---|
| 39 | 27 | |
|---|
| 40 | 28 | u32 tegra_read_chipid(void) |
|---|
| 41 | 29 | { |
|---|
| 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"); |
|---|
| 46 | 31 | |
|---|
| 47 | | - return readl_relaxed(apbmisc_base + 4); |
|---|
| 32 | + return chipid; |
|---|
| 48 | 33 | } |
|---|
| 49 | 34 | |
|---|
| 50 | 35 | u8 tegra_get_chip_id(void) |
|---|
| .. | .. |
|---|
| 52 | 37 | return (tegra_read_chipid() >> 8) & 0xff; |
|---|
| 53 | 38 | } |
|---|
| 54 | 39 | |
|---|
| 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 | + |
|---|
| 55 | 75 | u32 tegra_read_straps(void) |
|---|
| 56 | 76 | { |
|---|
| 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; |
|---|
| 61 | 80 | } |
|---|
| 62 | 81 | |
|---|
| 63 | 82 | u32 tegra_read_ram_code(void) |
|---|
| .. | .. |
|---|
| 75 | 94 | static const struct of_device_id apbmisc_match[] __initconst = { |
|---|
| 76 | 95 | { .compatible = "nvidia,tegra20-apbmisc", }, |
|---|
| 77 | 96 | { .compatible = "nvidia,tegra186-misc", }, |
|---|
| 97 | + { .compatible = "nvidia,tegra194-misc", }, |
|---|
| 98 | + { .compatible = "nvidia,tegra234-misc", }, |
|---|
| 78 | 99 | {}, |
|---|
| 79 | 100 | }; |
|---|
| 80 | 101 | |
|---|
| 81 | 102 | void __init tegra_init_revision(void) |
|---|
| 82 | 103 | { |
|---|
| 83 | | - u32 id, chip_id, minor_rev; |
|---|
| 84 | | - int rev; |
|---|
| 104 | + u8 chip_id, minor_rev; |
|---|
| 85 | 105 | |
|---|
| 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(); |
|---|
| 89 | 108 | |
|---|
| 90 | 109 | switch (minor_rev) { |
|---|
| 91 | 110 | case 1: |
|---|
| 92 | | - rev = TEGRA_REVISION_A01; |
|---|
| 111 | + tegra_sku_info.revision = TEGRA_REVISION_A01; |
|---|
| 93 | 112 | break; |
|---|
| 94 | 113 | case 2: |
|---|
| 95 | | - rev = TEGRA_REVISION_A02; |
|---|
| 114 | + tegra_sku_info.revision = TEGRA_REVISION_A02; |
|---|
| 96 | 115 | break; |
|---|
| 97 | 116 | case 3: |
|---|
| 98 | 117 | if (chip_id == TEGRA20 && (tegra_fuse_read_spare(18) || |
|---|
| 99 | 118 | tegra_fuse_read_spare(19))) |
|---|
| 100 | | - rev = TEGRA_REVISION_A03p; |
|---|
| 119 | + tegra_sku_info.revision = TEGRA_REVISION_A03p; |
|---|
| 101 | 120 | else |
|---|
| 102 | | - rev = TEGRA_REVISION_A03; |
|---|
| 121 | + tegra_sku_info.revision = TEGRA_REVISION_A03; |
|---|
| 103 | 122 | break; |
|---|
| 104 | 123 | case 4: |
|---|
| 105 | | - rev = TEGRA_REVISION_A04; |
|---|
| 124 | + tegra_sku_info.revision = TEGRA_REVISION_A04; |
|---|
| 106 | 125 | break; |
|---|
| 107 | 126 | default: |
|---|
| 108 | | - rev = TEGRA_REVISION_UNKNOWN; |
|---|
| 127 | + tegra_sku_info.revision = TEGRA_REVISION_UNKNOWN; |
|---|
| 109 | 128 | } |
|---|
| 110 | | - |
|---|
| 111 | | - tegra_sku_info.revision = rev; |
|---|
| 112 | 129 | |
|---|
| 113 | 130 | tegra_sku_info.sku_id = tegra_fuse_read_early(FUSE_SKU_INFO); |
|---|
| 114 | 131 | } |
|---|
| 115 | 132 | |
|---|
| 116 | 133 | void __init tegra_init_apbmisc(void) |
|---|
| 117 | 134 | { |
|---|
| 135 | + void __iomem *apbmisc_base, *strapping_base; |
|---|
| 118 | 136 | struct resource apbmisc, straps; |
|---|
| 119 | 137 | struct device_node *np; |
|---|
| 120 | 138 | |
|---|
| .. | .. |
|---|
| 171 | 189 | } |
|---|
| 172 | 190 | } |
|---|
| 173 | 191 | |
|---|
| 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) { |
|---|
| 176 | 194 | pr_err("failed to map APBMISC registers\n"); |
|---|
| 195 | + } else { |
|---|
| 196 | + chipid = readl_relaxed(apbmisc_base + 4); |
|---|
| 197 | + iounmap(apbmisc_base); |
|---|
| 198 | + } |
|---|
| 177 | 199 | |
|---|
| 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) { |
|---|
| 180 | 202 | pr_err("failed to map strapping options registers\n"); |
|---|
| 203 | + } else { |
|---|
| 204 | + strapping = readl_relaxed(strapping_base); |
|---|
| 205 | + iounmap(strapping_base); |
|---|
| 206 | + } |
|---|
| 181 | 207 | |
|---|
| 182 | 208 | long_ram_code = of_property_read_bool(np, "nvidia,long-ram-code"); |
|---|
| 183 | 209 | } |
|---|