fuse.c 3.2 KB
Newer Older
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21
/*
 * arch/arm/mach-tegra/fuse.c
 *
 * Copyright (C) 2010 Google, Inc.
 *
 * Author:
 *	Colin Cross <ccross@android.com>
 *
 * This software is licensed under the terms of the GNU General Public
 * License version 2, as published by the Free Software Foundation, and
 * may be copied, distributed, and modified under those terms.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 *
 */

#include <linux/kernel.h>
#include <linux/io.h>
22
#include <linux/export.h>
23 24 25 26

#include <mach/iomap.h>

#include "fuse.h"
27
#include "apbio.h"
28 29 30 31 32 33

#define FUSE_UID_LOW		0x108
#define FUSE_UID_HIGH		0x10c
#define FUSE_SKU_INFO		0x110
#define FUSE_SPARE_BIT		0x200

34 35 36
int tegra_sku_id;
int tegra_cpu_process_id;
int tegra_core_process_id;
37
int tegra_chip_id;
38 39
enum tegra_revision tegra_revision;

40 41 42 43 44 45 46 47 48 49 50
/* The BCT to use at boot is specified by board straps that can be read
 * through a APB misc register and decoded. 2 bits, i.e. 4 possible BCTs.
 */
int tegra_bct_strapping;

#define STRAP_OPT 0x008
#define GMI_AD0 (1 << 4)
#define GMI_AD1 (1 << 5)
#define RAM_ID_MASK (GMI_AD0 | GMI_AD1)
#define RAM_CODE_SHIFT 4

51 52 53 54 55 56 57 58 59
static const char *tegra_revision_name[TEGRA_REVISION_MAX] = {
	[TEGRA_REVISION_UNKNOWN] = "unknown",
	[TEGRA_REVISION_A01]     = "A01",
	[TEGRA_REVISION_A02]     = "A02",
	[TEGRA_REVISION_A03]     = "A03",
	[TEGRA_REVISION_A03p]    = "A03 prime",
	[TEGRA_REVISION_A04]     = "A04",
};

60
static inline u32 tegra_fuse_readl(unsigned long offset)
61
{
62
	return tegra_apb_readl(TEGRA_FUSE_BASE + offset);
63 64
}

65
static inline bool get_spare_fuse(int bit)
66
{
67
	return tegra_fuse_readl(FUSE_SPARE_BIT + bit * 4);
68 69
}

70
static enum tegra_revision tegra_get_revision(u32 id)
71
{
72 73 74 75 76 77 78 79
	u32 minor_rev = (id >> 16) & 0xf;

	switch (minor_rev) {
	case 1:
		return TEGRA_REVISION_A01;
	case 2:
		return TEGRA_REVISION_A02;
	case 3:
80 81
		if (tegra_chip_id == TEGRA20 &&
			(get_spare_fuse(18) || get_spare_fuse(19)))
82 83 84 85 86 87 88 89
			return TEGRA_REVISION_A03p;
		else
			return TEGRA_REVISION_A03;
	case 4:
		return TEGRA_REVISION_A04;
	default:
		return TEGRA_REVISION_UNKNOWN;
	}
90 91 92 93
}

void tegra_init_fuse(void)
{
94 95
	u32 id;

96
	u32 reg = readl(IO_ADDRESS(TEGRA_CLK_RESET_BASE + 0x48));
97
	reg |= 1 << 28;
98
	writel(reg, IO_ADDRESS(TEGRA_CLK_RESET_BASE + 0x48));
99

100 101 102 103 104 105 106 107 108
	reg = tegra_fuse_readl(FUSE_SKU_INFO);
	tegra_sku_id = reg & 0xFF;

	reg = tegra_fuse_readl(FUSE_SPARE_BIT);
	tegra_cpu_process_id = (reg >> 6) & 3;

	reg = tegra_fuse_readl(FUSE_SPARE_BIT);
	tegra_core_process_id = (reg >> 12) & 3;

109 110 111
	reg = tegra_apb_readl(TEGRA_APB_MISC_BASE + STRAP_OPT);
	tegra_bct_strapping = (reg & RAM_ID_MASK) >> RAM_CODE_SHIFT;

112 113 114 115
	id = readl_relaxed(IO_ADDRESS(TEGRA_APB_MISC_BASE) + 0x804);
	tegra_chip_id = (id >> 8) & 0xff;

	tegra_revision = tegra_get_revision(id);
116 117

	pr_info("Tegra Revision: %s SKU: %d CPU Process: %d Core Process: %d\n",
118
		tegra_revision_name[tegra_revision],
119 120
		tegra_sku_id, tegra_cpu_process_id,
		tegra_core_process_id);
121 122 123 124 125 126
}

unsigned long long tegra_chip_uid(void)
{
	unsigned long long lo, hi;

127 128
	lo = tegra_fuse_readl(FUSE_UID_LOW);
	hi = tegra_fuse_readl(FUSE_UID_HIGH);
129 130
	return (hi << 32ull) | lo;
}
131
EXPORT_SYMBOL(tegra_chip_uid);