2019-05-28 17:10:04 +00:00
|
|
|
// SPDX-License-Identifier: GPL-2.0-only
|
2014-06-12 15:36:37 +00:00
|
|
|
/*
|
2023-05-11 13:20:48 +00:00
|
|
|
* Copyright (c) 2014-2023, NVIDIA CORPORATION. All rights reserved.
|
2014-06-12 15:36:37 +00:00
|
|
|
*/
|
|
|
|
|
2023-10-17 05:23:18 +00:00
|
|
|
#include <linux/acpi.h>
|
2020-11-04 16:48:38 +00:00
|
|
|
#include <linux/export.h>
|
2023-07-27 14:32:46 +00:00
|
|
|
#include <linux/io.h>
|
2014-06-12 15:36:37 +00:00
|
|
|
#include <linux/kernel.h>
|
2023-10-17 05:23:18 +00:00
|
|
|
#include <linux/mod_devicetable.h>
|
2014-06-12 15:36:37 +00:00
|
|
|
#include <linux/of.h>
|
|
|
|
#include <linux/of_address.h>
|
|
|
|
|
2015-05-04 11:30:50 +00:00
|
|
|
#include <soc/tegra/common.h>
|
2023-07-27 14:32:46 +00:00
|
|
|
#include <soc/tegra/fuse.h>
|
2014-06-12 15:36:37 +00:00
|
|
|
|
|
|
|
#include "fuse.h"
|
|
|
|
|
|
|
|
#define FUSE_SKU_INFO 0x10
|
|
|
|
|
2022-05-11 20:16:43 +00:00
|
|
|
#define ERD_ERR_CONFIG 0x120c
|
|
|
|
#define ERD_MASK_INBAND_ERR 0x1
|
|
|
|
|
2015-03-12 14:47:55 +00:00
|
|
|
#define PMC_STRAPPING_OPT_A_RAM_CODE_SHIFT 4
|
|
|
|
#define PMC_STRAPPING_OPT_A_RAM_CODE_MASK_LONG \
|
|
|
|
(0xf << PMC_STRAPPING_OPT_A_RAM_CODE_SHIFT)
|
|
|
|
#define PMC_STRAPPING_OPT_A_RAM_CODE_MASK_SHORT \
|
|
|
|
(0x3 << PMC_STRAPPING_OPT_A_RAM_CODE_SHIFT)
|
|
|
|
|
2022-05-11 20:16:43 +00:00
|
|
|
static void __iomem *apbmisc_base;
|
2015-03-12 14:47:55 +00:00
|
|
|
static bool long_ram_code;
|
2019-12-18 18:23:01 +00:00
|
|
|
static u32 strapping;
|
|
|
|
static u32 chipid;
|
2014-06-12 15:36:37 +00:00
|
|
|
|
|
|
|
u32 tegra_read_chipid(void)
|
|
|
|
{
|
2020-07-17 13:41:42 +00:00
|
|
|
WARN(!chipid, "Tegra APB MISC not yet available\n");
|
2014-06-12 15:36:37 +00:00
|
|
|
|
2019-12-18 18:23:01 +00:00
|
|
|
return chipid;
|
2017-06-26 15:21:17 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
u8 tegra_get_chip_id(void)
|
|
|
|
{
|
2014-07-11 09:13:30 +00:00
|
|
|
return (tegra_read_chipid() >> 8) & 0xff;
|
2014-06-12 15:36:37 +00:00
|
|
|
}
|
|
|
|
|
soc/tegra: fuse: Add custom SoC attributes
Add a custom SoC attribute for Tegra to expose the HIDREV register
fields to userspace via the sysfs. This register provides additional
details about the type of device (eg, silicon, FPGA, etc) as well as
revision. Exposing this information is useful for identifying the
exact device revision and device type.
For Tegra devices up until Tegra186, the majorrev and minorrev fields of
the HIDREV register are used to determine the device revision and device
type. For Tegra194, the majorrev and minorrev fields only determine the
revision. Starting with Tegra194, there is an additional field,
pre_si_platform (which occupies bits 20-23), that now determines device
type. Therefore, for all Tegra devices, add a custom SoC attribute for
the majorrev and minorrev fields and for Tegra194 add an additional
attribute for the pre_si_platform field.
Signed-off-by: Jon Hunter <jonathanh@nvidia.com>
Signed-off-by: Thierry Reding <treding@nvidia.com>
2020-04-17 12:39:48 +00:00
|
|
|
u8 tegra_get_major_rev(void)
|
|
|
|
{
|
|
|
|
return (tegra_read_chipid() >> 4) & 0xf;
|
|
|
|
}
|
|
|
|
|
|
|
|
u8 tegra_get_minor_rev(void)
|
|
|
|
{
|
|
|
|
return (tegra_read_chipid() >> 16) & 0xf;
|
|
|
|
}
|
|
|
|
|
2020-09-17 10:07:45 +00:00
|
|
|
u8 tegra_get_platform(void)
|
|
|
|
{
|
|
|
|
return (tegra_read_chipid() >> 20) & 0xf;
|
|
|
|
}
|
|
|
|
|
2020-09-17 10:07:46 +00:00
|
|
|
bool tegra_is_silicon(void)
|
|
|
|
{
|
|
|
|
switch (tegra_get_chip_id()) {
|
|
|
|
case TEGRA194:
|
2020-09-17 10:07:47 +00:00
|
|
|
case TEGRA234:
|
2023-10-17 05:23:22 +00:00
|
|
|
case TEGRA241:
|
2023-05-11 13:20:48 +00:00
|
|
|
case TEGRA264:
|
2020-09-17 10:07:46 +00:00
|
|
|
if (tegra_get_platform() == 0)
|
|
|
|
return true;
|
|
|
|
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Chips prior to Tegra194 have a different way of determining whether
|
|
|
|
* they are silicon or not. Since we never supported simulation on the
|
|
|
|
* older Tegra chips, don't bother extracting the information and just
|
|
|
|
* report that we're running on silicon.
|
|
|
|
*/
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2014-06-12 15:36:37 +00:00
|
|
|
u32 tegra_read_straps(void)
|
|
|
|
{
|
2019-12-18 18:23:02 +00:00
|
|
|
WARN(!chipid, "Tegra ABP MISC not yet available\n");
|
|
|
|
|
2019-12-18 18:23:01 +00:00
|
|
|
return strapping;
|
2014-06-12 15:36:37 +00:00
|
|
|
}
|
|
|
|
|
2015-03-12 14:47:55 +00:00
|
|
|
u32 tegra_read_ram_code(void)
|
|
|
|
{
|
|
|
|
u32 straps = tegra_read_straps();
|
|
|
|
|
|
|
|
if (long_ram_code)
|
|
|
|
straps &= PMC_STRAPPING_OPT_A_RAM_CODE_MASK_LONG;
|
|
|
|
else
|
|
|
|
straps &= PMC_STRAPPING_OPT_A_RAM_CODE_MASK_SHORT;
|
|
|
|
|
|
|
|
return straps >> PMC_STRAPPING_OPT_A_RAM_CODE_SHIFT;
|
|
|
|
}
|
2020-11-04 16:48:38 +00:00
|
|
|
EXPORT_SYMBOL_GPL(tegra_read_ram_code);
|
2015-03-12 14:47:55 +00:00
|
|
|
|
2022-05-11 20:16:43 +00:00
|
|
|
/*
|
|
|
|
* The function sets ERD(Error Response Disable) bit.
|
|
|
|
* This allows to mask inband errors and always send an
|
|
|
|
* OKAY response from CBB to the master which caused error.
|
|
|
|
*/
|
|
|
|
int tegra194_miscreg_mask_serror(void)
|
|
|
|
{
|
|
|
|
if (!apbmisc_base)
|
|
|
|
return -EPROBE_DEFER;
|
|
|
|
|
|
|
|
if (!of_machine_is_compatible("nvidia,tegra194")) {
|
|
|
|
WARN(1, "Only supported for Tegra194 devices!\n");
|
|
|
|
return -EOPNOTSUPP;
|
|
|
|
}
|
|
|
|
|
|
|
|
writel_relaxed(ERD_MASK_INBAND_ERR,
|
|
|
|
apbmisc_base + ERD_ERR_CONFIG);
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
EXPORT_SYMBOL(tegra194_miscreg_mask_serror);
|
|
|
|
|
2014-06-12 15:36:37 +00:00
|
|
|
static const struct of_device_id apbmisc_match[] __initconst = {
|
|
|
|
{ .compatible = "nvidia,tegra20-apbmisc", },
|
2017-06-26 15:25:24 +00:00
|
|
|
{ .compatible = "nvidia,tegra186-misc", },
|
2020-01-03 08:30:17 +00:00
|
|
|
{ .compatible = "nvidia,tegra194-misc", },
|
2020-09-17 10:07:48 +00:00
|
|
|
{ .compatible = "nvidia,tegra234-misc", },
|
2014-06-12 15:36:37 +00:00
|
|
|
{},
|
|
|
|
};
|
|
|
|
|
|
|
|
void __init tegra_init_revision(void)
|
|
|
|
{
|
2020-04-17 12:39:49 +00:00
|
|
|
u8 chip_id, minor_rev;
|
2014-06-12 15:36:37 +00:00
|
|
|
|
2020-04-17 12:39:49 +00:00
|
|
|
chip_id = tegra_get_chip_id();
|
|
|
|
minor_rev = tegra_get_minor_rev();
|
2014-06-12 15:36:37 +00:00
|
|
|
|
|
|
|
switch (minor_rev) {
|
|
|
|
case 1:
|
2020-04-17 12:39:49 +00:00
|
|
|
tegra_sku_info.revision = TEGRA_REVISION_A01;
|
2014-06-12 15:36:37 +00:00
|
|
|
break;
|
|
|
|
case 2:
|
2020-04-17 12:39:49 +00:00
|
|
|
tegra_sku_info.revision = TEGRA_REVISION_A02;
|
2014-06-12 15:36:37 +00:00
|
|
|
break;
|
|
|
|
case 3:
|
2015-04-29 14:54:04 +00:00
|
|
|
if (chip_id == TEGRA20 && (tegra_fuse_read_spare(18) ||
|
|
|
|
tegra_fuse_read_spare(19)))
|
2020-04-17 12:39:49 +00:00
|
|
|
tegra_sku_info.revision = TEGRA_REVISION_A03p;
|
2014-06-12 15:36:37 +00:00
|
|
|
else
|
2020-04-17 12:39:49 +00:00
|
|
|
tegra_sku_info.revision = TEGRA_REVISION_A03;
|
2014-06-12 15:36:37 +00:00
|
|
|
break;
|
|
|
|
case 4:
|
2020-04-17 12:39:49 +00:00
|
|
|
tegra_sku_info.revision = TEGRA_REVISION_A04;
|
2014-06-12 15:36:37 +00:00
|
|
|
break;
|
|
|
|
default:
|
2020-04-17 12:39:49 +00:00
|
|
|
tegra_sku_info.revision = TEGRA_REVISION_UNKNOWN;
|
2014-06-12 15:36:37 +00:00
|
|
|
}
|
|
|
|
|
2015-04-29 14:54:04 +00:00
|
|
|
tegra_sku_info.sku_id = tegra_fuse_read_early(FUSE_SKU_INFO);
|
2022-11-09 14:20:22 +00:00
|
|
|
tegra_sku_info.platform = tegra_get_platform();
|
2014-06-12 15:36:37 +00:00
|
|
|
}
|
|
|
|
|
2023-10-17 05:23:17 +00:00
|
|
|
static void tegra_init_apbmisc_resources(struct resource *apbmisc,
|
|
|
|
struct resource *straps)
|
2014-06-12 15:36:37 +00:00
|
|
|
{
|
2022-05-11 20:16:43 +00:00
|
|
|
void __iomem *strapping_base;
|
2023-10-17 05:23:17 +00:00
|
|
|
|
|
|
|
apbmisc_base = ioremap(apbmisc->start, resource_size(apbmisc));
|
|
|
|
if (apbmisc_base)
|
|
|
|
chipid = readl_relaxed(apbmisc_base + 4);
|
|
|
|
else
|
|
|
|
pr_err("failed to map APBMISC registers\n");
|
|
|
|
|
|
|
|
strapping_base = ioremap(straps->start, resource_size(straps));
|
|
|
|
if (strapping_base) {
|
|
|
|
strapping = readl_relaxed(strapping_base);
|
|
|
|
iounmap(strapping_base);
|
|
|
|
} else {
|
|
|
|
pr_err("failed to map strapping options registers\n");
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2023-10-17 05:23:18 +00:00
|
|
|
/**
|
|
|
|
* tegra_init_apbmisc - Initializes Tegra APBMISC and Strapping registers.
|
|
|
|
*
|
|
|
|
* This is called during early init as some of the old 32-bit ARM code needs
|
|
|
|
* information from the APBMISC registers very early during boot.
|
|
|
|
*/
|
2023-10-17 05:23:17 +00:00
|
|
|
void __init tegra_init_apbmisc(void)
|
|
|
|
{
|
2015-05-04 11:30:50 +00:00
|
|
|
struct resource apbmisc, straps;
|
2014-06-12 15:36:37 +00:00
|
|
|
struct device_node *np;
|
|
|
|
|
|
|
|
np = of_find_matching_node(NULL, apbmisc_match);
|
2015-05-04 11:30:50 +00:00
|
|
|
if (!np) {
|
|
|
|
/*
|
|
|
|
* Fall back to legacy initialization for 32-bit ARM only. All
|
|
|
|
* 64-bit ARM device tree files for Tegra are required to have
|
|
|
|
* an APBMISC node.
|
|
|
|
*
|
|
|
|
* This is for backwards-compatibility with old device trees
|
|
|
|
* that didn't contain an APBMISC node.
|
|
|
|
*/
|
|
|
|
if (IS_ENABLED(CONFIG_ARM) && soc_is_tegra()) {
|
|
|
|
/* APBMISC registers (chip revision, ...) */
|
|
|
|
apbmisc.start = 0x70000800;
|
|
|
|
apbmisc.end = 0x70000863;
|
|
|
|
apbmisc.flags = IORESOURCE_MEM;
|
|
|
|
|
|
|
|
/* strapping options */
|
2019-12-18 18:23:03 +00:00
|
|
|
if (of_machine_is_compatible("nvidia,tegra124")) {
|
2015-05-04 11:30:50 +00:00
|
|
|
straps.start = 0x7000e864;
|
|
|
|
straps.end = 0x7000e867;
|
|
|
|
} else {
|
|
|
|
straps.start = 0x70000008;
|
|
|
|
straps.end = 0x7000000b;
|
|
|
|
}
|
|
|
|
|
|
|
|
straps.flags = IORESOURCE_MEM;
|
|
|
|
|
|
|
|
pr_warn("Using APBMISC region %pR\n", &apbmisc);
|
|
|
|
pr_warn("Using strapping options registers %pR\n",
|
|
|
|
&straps);
|
|
|
|
} else {
|
|
|
|
/*
|
|
|
|
* At this point we're not running on Tegra, so play
|
|
|
|
* nice with multi-platform kernels.
|
|
|
|
*/
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
/*
|
|
|
|
* Extract information from the device tree if we've found a
|
|
|
|
* matching node.
|
|
|
|
*/
|
|
|
|
if (of_address_to_resource(np, 0, &apbmisc) < 0) {
|
|
|
|
pr_err("failed to get APBMISC registers\n");
|
2022-06-15 12:32:32 +00:00
|
|
|
goto put;
|
2015-05-04 11:30:50 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
if (of_address_to_resource(np, 1, &straps) < 0) {
|
|
|
|
pr_err("failed to get strapping options registers\n");
|
2022-06-15 12:32:32 +00:00
|
|
|
goto put;
|
2015-05-04 11:30:50 +00:00
|
|
|
}
|
2014-06-12 15:36:37 +00:00
|
|
|
}
|
|
|
|
|
2023-10-17 05:23:17 +00:00
|
|
|
tegra_init_apbmisc_resources(&apbmisc, &straps);
|
2015-03-12 14:47:55 +00:00
|
|
|
long_ram_code = of_property_read_bool(np, "nvidia,long-ram-code");
|
2022-06-15 12:32:32 +00:00
|
|
|
|
|
|
|
put:
|
|
|
|
of_node_put(np);
|
2014-06-12 15:36:37 +00:00
|
|
|
}
|
2023-10-17 05:23:18 +00:00
|
|
|
|
|
|
|
#ifdef CONFIG_ACPI
|
|
|
|
static const struct acpi_device_id apbmisc_acpi_match[] = {
|
|
|
|
{ "NVDA2010" },
|
|
|
|
{ /* sentinel */ }
|
|
|
|
};
|
|
|
|
|
|
|
|
void tegra_acpi_init_apbmisc(void)
|
|
|
|
{
|
|
|
|
struct resource *resources[2] = { NULL };
|
|
|
|
struct resource_entry *rentry;
|
|
|
|
struct acpi_device *adev = NULL;
|
|
|
|
struct list_head resource_list;
|
|
|
|
int rcount = 0;
|
|
|
|
int ret;
|
|
|
|
|
|
|
|
adev = acpi_dev_get_first_match_dev(apbmisc_acpi_match[0].id, NULL, -1);
|
|
|
|
if (!adev)
|
|
|
|
return;
|
|
|
|
|
|
|
|
INIT_LIST_HEAD(&resource_list);
|
|
|
|
|
|
|
|
ret = acpi_dev_get_memory_resources(adev, &resource_list);
|
|
|
|
if (ret < 0) {
|
|
|
|
pr_err("failed to get APBMISC memory resources");
|
|
|
|
goto out_put_acpi_dev;
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Get required memory resources.
|
|
|
|
*
|
|
|
|
* resources[0]: apbmisc.
|
|
|
|
* resources[1]: straps.
|
|
|
|
*/
|
|
|
|
resource_list_for_each_entry(rentry, &resource_list) {
|
|
|
|
if (rcount >= ARRAY_SIZE(resources))
|
|
|
|
break;
|
|
|
|
|
|
|
|
resources[rcount++] = rentry->res;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!resources[0]) {
|
|
|
|
pr_err("failed to get APBMISC registers\n");
|
|
|
|
goto out_free_resource_list;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!resources[1]) {
|
|
|
|
pr_err("failed to get strapping options registers\n");
|
|
|
|
goto out_free_resource_list;
|
|
|
|
}
|
|
|
|
|
|
|
|
tegra_init_apbmisc_resources(resources[0], resources[1]);
|
|
|
|
|
|
|
|
out_free_resource_list:
|
|
|
|
acpi_dev_free_resource_list(&resource_list);
|
|
|
|
|
|
|
|
out_put_acpi_dev:
|
|
|
|
acpi_dev_put(adev);
|
|
|
|
}
|
|
|
|
#else
|
|
|
|
void tegra_acpi_init_apbmisc(void)
|
|
|
|
{
|
|
|
|
}
|
|
|
|
#endif
|