Colin Cross | 73625e3 | 2010-06-23 15:49:17 -0700 | [diff] [blame] | 1 | /* |
| 2 | * arch/arm/mach-tegra/fuse.c |
| 3 | * |
| 4 | * Copyright (C) 2010 Google, Inc. |
| 5 | * |
| 6 | * Author: |
| 7 | * Colin Cross <ccross@android.com> |
| 8 | * |
| 9 | * This software is licensed under the terms of the GNU General Public |
| 10 | * License version 2, as published by the Free Software Foundation, and |
| 11 | * may be copied, distributed, and modified under those terms. |
| 12 | * |
| 13 | * This program is distributed in the hope that it will be useful, |
| 14 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 15 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 16 | * GNU General Public License for more details. |
| 17 | * |
| 18 | */ |
| 19 | |
| 20 | #include <linux/kernel.h> |
| 21 | #include <linux/io.h> |
| 22 | |
| 23 | #include <mach/iomap.h> |
| 24 | |
| 25 | #include "fuse.h" |
Olof Johansson | d262f49 | 2011-10-13 00:14:08 -0700 | [diff] [blame] | 26 | #include "apbio.h" |
Colin Cross | 73625e3 | 2010-06-23 15:49:17 -0700 | [diff] [blame] | 27 | |
| 28 | #define FUSE_UID_LOW 0x108 |
| 29 | #define FUSE_UID_HIGH 0x10c |
| 30 | #define FUSE_SKU_INFO 0x110 |
| 31 | #define FUSE_SPARE_BIT 0x200 |
| 32 | |
Olof Johansson | 9a1086d | 2011-10-13 00:31:20 -0700 | [diff] [blame^] | 33 | int tegra_sku_id; |
| 34 | int tegra_cpu_process_id; |
| 35 | int tegra_core_process_id; |
| 36 | enum tegra_revision tegra_revision; |
| 37 | |
| 38 | static const char *tegra_revision_name[TEGRA_REVISION_MAX] = { |
| 39 | [TEGRA_REVISION_UNKNOWN] = "unknown", |
| 40 | [TEGRA_REVISION_A01] = "A01", |
| 41 | [TEGRA_REVISION_A02] = "A02", |
| 42 | [TEGRA_REVISION_A03] = "A03", |
| 43 | [TEGRA_REVISION_A03p] = "A03 prime", |
| 44 | [TEGRA_REVISION_A04] = "A04", |
| 45 | }; |
| 46 | |
Olof Johansson | d262f49 | 2011-10-13 00:14:08 -0700 | [diff] [blame] | 47 | static inline u32 tegra_fuse_readl(unsigned long offset) |
Colin Cross | 73625e3 | 2010-06-23 15:49:17 -0700 | [diff] [blame] | 48 | { |
Olof Johansson | d262f49 | 2011-10-13 00:14:08 -0700 | [diff] [blame] | 49 | return tegra_apb_readl(TEGRA_FUSE_BASE + offset); |
Colin Cross | 73625e3 | 2010-06-23 15:49:17 -0700 | [diff] [blame] | 50 | } |
| 51 | |
Olof Johansson | 9a1086d | 2011-10-13 00:31:20 -0700 | [diff] [blame^] | 52 | static inline bool get_spare_fuse(int bit) |
| 53 | { |
| 54 | return tegra_fuse_readl(FUSE_SPARE_BIT + bit * 4); |
| 55 | } |
| 56 | |
| 57 | static enum tegra_revision tegra_get_revision(void) |
| 58 | { |
| 59 | void __iomem *chip_id = IO_ADDRESS(TEGRA_APB_MISC_BASE) + 0x804; |
| 60 | u32 id = readl(chip_id); |
| 61 | u32 minor_rev = (id >> 16) & 0xf; |
| 62 | u32 chipid = (id >> 8) & 0xff; |
| 63 | |
| 64 | switch (minor_rev) { |
| 65 | case 1: |
| 66 | return TEGRA_REVISION_A01; |
| 67 | case 2: |
| 68 | return TEGRA_REVISION_A02; |
| 69 | case 3: |
| 70 | if (chipid == 0x20 && (get_spare_fuse(18) || get_spare_fuse(19))) |
| 71 | return TEGRA_REVISION_A03p; |
| 72 | else |
| 73 | return TEGRA_REVISION_A03; |
| 74 | case 4: |
| 75 | return TEGRA_REVISION_A04; |
| 76 | default: |
| 77 | return TEGRA_REVISION_UNKNOWN; |
| 78 | } |
| 79 | } |
| 80 | |
Colin Cross | 73625e3 | 2010-06-23 15:49:17 -0700 | [diff] [blame] | 81 | void tegra_init_fuse(void) |
| 82 | { |
| 83 | u32 reg = readl(IO_TO_VIRT(TEGRA_CLK_RESET_BASE + 0x48)); |
| 84 | reg |= 1 << 28; |
| 85 | writel(reg, IO_TO_VIRT(TEGRA_CLK_RESET_BASE + 0x48)); |
| 86 | |
Olof Johansson | 9a1086d | 2011-10-13 00:31:20 -0700 | [diff] [blame^] | 87 | reg = tegra_fuse_readl(FUSE_SKU_INFO); |
| 88 | tegra_sku_id = reg & 0xFF; |
| 89 | |
| 90 | reg = tegra_fuse_readl(FUSE_SPARE_BIT); |
| 91 | tegra_cpu_process_id = (reg >> 6) & 3; |
| 92 | |
| 93 | reg = tegra_fuse_readl(FUSE_SPARE_BIT); |
| 94 | tegra_core_process_id = (reg >> 12) & 3; |
| 95 | |
| 96 | tegra_revision = tegra_get_revision(); |
| 97 | |
| 98 | pr_info("Tegra Revision: %s SKU: %d CPU Process: %d Core Process: %d\n", |
| 99 | tegra_revision_name[tegra_get_revision()], |
| 100 | tegra_sku_id, tegra_cpu_process_id, |
| 101 | tegra_core_process_id); |
Colin Cross | 73625e3 | 2010-06-23 15:49:17 -0700 | [diff] [blame] | 102 | } |
| 103 | |
| 104 | unsigned long long tegra_chip_uid(void) |
| 105 | { |
| 106 | unsigned long long lo, hi; |
| 107 | |
Olof Johansson | d262f49 | 2011-10-13 00:14:08 -0700 | [diff] [blame] | 108 | lo = tegra_fuse_readl(FUSE_UID_LOW); |
| 109 | hi = tegra_fuse_readl(FUSE_UID_HIGH); |
Colin Cross | 73625e3 | 2010-06-23 15:49:17 -0700 | [diff] [blame] | 110 | return (hi << 32ull) | lo; |
| 111 | } |