19952f691SThomas Gleixner // SPDX-License-Identifier: GPL-2.0-only 2783c8f4cSPeter De Schrijver /* 3783c8f4cSPeter De Schrijver * Copyright (c) 2013-2014, NVIDIA CORPORATION. All rights reserved. 4783c8f4cSPeter De Schrijver */ 5783c8f4cSPeter De Schrijver 67e939de1SThierry Reding #include <linux/clk.h> 7783c8f4cSPeter De Schrijver #include <linux/device.h> 8783c8f4cSPeter De Schrijver #include <linux/kobject.h> 91859217bSPaul Gortmaker #include <linux/init.h> 1027a0342aSThierry Reding #include <linux/io.h> 1196ee12b2SThierry Reding #include <linux/nvmem-consumer.h> 1296ee12b2SThierry Reding #include <linux/nvmem-provider.h> 13783c8f4cSPeter De Schrijver #include <linux/of.h> 14783c8f4cSPeter De Schrijver #include <linux/of_address.h> 1527a0342aSThierry Reding #include <linux/platform_device.h> 1627a0342aSThierry Reding #include <linux/slab.h> 1727a0342aSThierry Reding #include <linux/sys_soc.h> 18783c8f4cSPeter De Schrijver 1924fa5af8SThierry Reding #include <soc/tegra/common.h> 20783c8f4cSPeter De Schrijver #include <soc/tegra/fuse.h> 21783c8f4cSPeter De Schrijver 22783c8f4cSPeter De Schrijver #include "fuse.h" 23783c8f4cSPeter De Schrijver 24783c8f4cSPeter De Schrijver struct tegra_sku_info tegra_sku_info; 25f9fc3661SVince Hsu EXPORT_SYMBOL(tegra_sku_info); 26783c8f4cSPeter De Schrijver 27783c8f4cSPeter De Schrijver static const char *tegra_revision_name[TEGRA_REVISION_MAX] = { 28783c8f4cSPeter De Schrijver [TEGRA_REVISION_UNKNOWN] = "unknown", 29783c8f4cSPeter De Schrijver [TEGRA_REVISION_A01] = "A01", 30783c8f4cSPeter De Schrijver [TEGRA_REVISION_A02] = "A02", 31783c8f4cSPeter De Schrijver [TEGRA_REVISION_A03] = "A03", 32783c8f4cSPeter De Schrijver [TEGRA_REVISION_A03p] = "A03 prime", 33783c8f4cSPeter De Schrijver [TEGRA_REVISION_A04] = "A04", 34783c8f4cSPeter De Schrijver }; 35783c8f4cSPeter De Schrijver 36783c8f4cSPeter De Schrijver static const struct of_device_id car_match[] __initconst = { 37783c8f4cSPeter De Schrijver { .compatible = "nvidia,tegra20-car", }, 38783c8f4cSPeter De Schrijver { .compatible = "nvidia,tegra30-car", }, 39783c8f4cSPeter De Schrijver { .compatible = "nvidia,tegra114-car", }, 40783c8f4cSPeter De Schrijver { .compatible = "nvidia,tegra124-car", }, 419b07eb05SThierry Reding { .compatible = "nvidia,tegra132-car", }, 420dc5a0d8SThierry Reding { .compatible = "nvidia,tegra210-car", }, 43783c8f4cSPeter De Schrijver {}, 44783c8f4cSPeter De Schrijver }; 45783c8f4cSPeter De Schrijver 467e939de1SThierry Reding static struct tegra_fuse *fuse = &(struct tegra_fuse) { 477e939de1SThierry Reding .base = NULL, 487e939de1SThierry Reding .soc = NULL, 497e939de1SThierry Reding }; 507e939de1SThierry Reding 517e939de1SThierry Reding static const struct of_device_id tegra_fuse_match[] = { 523979a4c6SJC Kuo #ifdef CONFIG_ARCH_TEGRA_194_SOC 533979a4c6SJC Kuo { .compatible = "nvidia,tegra194-efuse", .data = &tegra194_fuse_soc }, 543979a4c6SJC Kuo #endif 5583468fe2STimo Alho #ifdef CONFIG_ARCH_TEGRA_186_SOC 5683468fe2STimo Alho { .compatible = "nvidia,tegra186-efuse", .data = &tegra186_fuse_soc }, 5783468fe2STimo Alho #endif 580dc5a0d8SThierry Reding #ifdef CONFIG_ARCH_TEGRA_210_SOC 590dc5a0d8SThierry Reding { .compatible = "nvidia,tegra210-efuse", .data = &tegra210_fuse_soc }, 600dc5a0d8SThierry Reding #endif 617e939de1SThierry Reding #ifdef CONFIG_ARCH_TEGRA_132_SOC 627e939de1SThierry Reding { .compatible = "nvidia,tegra132-efuse", .data = &tegra124_fuse_soc }, 637e939de1SThierry Reding #endif 647e939de1SThierry Reding #ifdef CONFIG_ARCH_TEGRA_124_SOC 657e939de1SThierry Reding { .compatible = "nvidia,tegra124-efuse", .data = &tegra124_fuse_soc }, 667e939de1SThierry Reding #endif 677e939de1SThierry Reding #ifdef CONFIG_ARCH_TEGRA_114_SOC 687e939de1SThierry Reding { .compatible = "nvidia,tegra114-efuse", .data = &tegra114_fuse_soc }, 697e939de1SThierry Reding #endif 707e939de1SThierry Reding #ifdef CONFIG_ARCH_TEGRA_3x_SOC 717e939de1SThierry Reding { .compatible = "nvidia,tegra30-efuse", .data = &tegra30_fuse_soc }, 727e939de1SThierry Reding #endif 737e939de1SThierry Reding #ifdef CONFIG_ARCH_TEGRA_2x_SOC 747e939de1SThierry Reding { .compatible = "nvidia,tegra20-efuse", .data = &tegra20_fuse_soc }, 757e939de1SThierry Reding #endif 767e939de1SThierry Reding { /* sentinel */ } 777e939de1SThierry Reding }; 787e939de1SThierry Reding 7996ee12b2SThierry Reding static int tegra_fuse_read(void *priv, unsigned int offset, void *value, 8096ee12b2SThierry Reding size_t bytes) 8196ee12b2SThierry Reding { 8296ee12b2SThierry Reding unsigned int count = bytes / 4, i; 8396ee12b2SThierry Reding struct tegra_fuse *fuse = priv; 8496ee12b2SThierry Reding u32 *buffer = value; 8596ee12b2SThierry Reding 8696ee12b2SThierry Reding for (i = 0; i < count; i++) 8796ee12b2SThierry Reding buffer[i] = fuse->read(fuse, offset + i * 4); 8896ee12b2SThierry Reding 8996ee12b2SThierry Reding return 0; 9096ee12b2SThierry Reding } 9196ee12b2SThierry Reding 92f4619c7fSThierry Reding static const struct nvmem_cell_info tegra_fuse_cells[] = { 93f4619c7fSThierry Reding { 94f4619c7fSThierry Reding .name = "tsensor-cpu1", 95f4619c7fSThierry Reding .offset = 0x084, 96f4619c7fSThierry Reding .bytes = 4, 97f4619c7fSThierry Reding .bit_offset = 0, 98f4619c7fSThierry Reding .nbits = 32, 99f4619c7fSThierry Reding }, { 100f4619c7fSThierry Reding .name = "tsensor-cpu2", 101f4619c7fSThierry Reding .offset = 0x088, 102f4619c7fSThierry Reding .bytes = 4, 103f4619c7fSThierry Reding .bit_offset = 0, 104f4619c7fSThierry Reding .nbits = 32, 105f4619c7fSThierry Reding }, { 106f4619c7fSThierry Reding .name = "tsensor-cpu0", 107f4619c7fSThierry Reding .offset = 0x098, 108f4619c7fSThierry Reding .bytes = 4, 109f4619c7fSThierry Reding .bit_offset = 0, 110f4619c7fSThierry Reding .nbits = 32, 111f4619c7fSThierry Reding }, { 112f4619c7fSThierry Reding .name = "xusb-pad-calibration", 113f4619c7fSThierry Reding .offset = 0x0f0, 114f4619c7fSThierry Reding .bytes = 4, 115f4619c7fSThierry Reding .bit_offset = 0, 116f4619c7fSThierry Reding .nbits = 32, 117f4619c7fSThierry Reding }, { 118f4619c7fSThierry Reding .name = "tsensor-cpu3", 119f4619c7fSThierry Reding .offset = 0x12c, 120f4619c7fSThierry Reding .bytes = 4, 121f4619c7fSThierry Reding .bit_offset = 0, 122f4619c7fSThierry Reding .nbits = 32, 123f4619c7fSThierry Reding }, { 124f4619c7fSThierry Reding .name = "sata-calibration", 125f4619c7fSThierry Reding .offset = 0x124, 126f4619c7fSThierry Reding .bytes = 1, 127f4619c7fSThierry Reding .bit_offset = 0, 128f4619c7fSThierry Reding .nbits = 2, 129f4619c7fSThierry Reding }, { 130f4619c7fSThierry Reding .name = "tsensor-gpu", 131f4619c7fSThierry Reding .offset = 0x154, 132f4619c7fSThierry Reding .bytes = 4, 133f4619c7fSThierry Reding .bit_offset = 0, 134f4619c7fSThierry Reding .nbits = 32, 135f4619c7fSThierry Reding }, { 136f4619c7fSThierry Reding .name = "tsensor-mem0", 137f4619c7fSThierry Reding .offset = 0x158, 138f4619c7fSThierry Reding .bytes = 4, 139f4619c7fSThierry Reding .bit_offset = 0, 140f4619c7fSThierry Reding .nbits = 32, 141f4619c7fSThierry Reding }, { 142f4619c7fSThierry Reding .name = "tsensor-mem1", 143f4619c7fSThierry Reding .offset = 0x15c, 144f4619c7fSThierry Reding .bytes = 4, 145f4619c7fSThierry Reding .bit_offset = 0, 146f4619c7fSThierry Reding .nbits = 32, 147f4619c7fSThierry Reding }, { 148f4619c7fSThierry Reding .name = "tsensor-pllx", 149f4619c7fSThierry Reding .offset = 0x160, 150f4619c7fSThierry Reding .bytes = 4, 151f4619c7fSThierry Reding .bit_offset = 0, 152f4619c7fSThierry Reding .nbits = 32, 153f4619c7fSThierry Reding }, { 154f4619c7fSThierry Reding .name = "tsensor-common", 155f4619c7fSThierry Reding .offset = 0x180, 156f4619c7fSThierry Reding .bytes = 4, 157f4619c7fSThierry Reding .bit_offset = 0, 158f4619c7fSThierry Reding .nbits = 32, 159f4619c7fSThierry Reding }, { 160f4619c7fSThierry Reding .name = "tsensor-realignment", 161f4619c7fSThierry Reding .offset = 0x1fc, 162f4619c7fSThierry Reding .bytes = 4, 163f4619c7fSThierry Reding .bit_offset = 0, 164f4619c7fSThierry Reding .nbits = 32, 165f4619c7fSThierry Reding }, { 166f4619c7fSThierry Reding .name = "gpu-calibration", 167f4619c7fSThierry Reding .offset = 0x204, 168f4619c7fSThierry Reding .bytes = 4, 169f4619c7fSThierry Reding .bit_offset = 0, 170f4619c7fSThierry Reding .nbits = 32, 171f4619c7fSThierry Reding }, { 172f4619c7fSThierry Reding .name = "xusb-pad-calibration-ext", 173f4619c7fSThierry Reding .offset = 0x250, 174f4619c7fSThierry Reding .bytes = 4, 175f4619c7fSThierry Reding .bit_offset = 0, 176f4619c7fSThierry Reding .nbits = 32, 177f4619c7fSThierry Reding }, 178f4619c7fSThierry Reding }; 179f4619c7fSThierry Reding 1807e939de1SThierry Reding static int tegra_fuse_probe(struct platform_device *pdev) 1817e939de1SThierry Reding { 1827e939de1SThierry Reding void __iomem *base = fuse->base; 18396ee12b2SThierry Reding struct nvmem_config nvmem; 1847e939de1SThierry Reding struct resource *res; 1857e939de1SThierry Reding int err; 1867e939de1SThierry Reding 1877e939de1SThierry Reding /* take over the memory region from the early initialization */ 1887e939de1SThierry Reding res = platform_get_resource(pdev, IORESOURCE_MEM, 0); 18955a042b3SDmitry Osipenko fuse->phys = res->start; 1907e939de1SThierry Reding fuse->base = devm_ioremap_resource(&pdev->dev, res); 19151294bf6STimo Alho if (IS_ERR(fuse->base)) { 19251294bf6STimo Alho err = PTR_ERR(fuse->base); 19351294bf6STimo Alho fuse->base = base; 19451294bf6STimo Alho return err; 19551294bf6STimo Alho } 1967e939de1SThierry Reding 1977e939de1SThierry Reding fuse->clk = devm_clk_get(&pdev->dev, "fuse"); 1987e939de1SThierry Reding if (IS_ERR(fuse->clk)) { 199f0b2835fSThierry Reding if (PTR_ERR(fuse->clk) != -EPROBE_DEFER) 2007e939de1SThierry Reding dev_err(&pdev->dev, "failed to get FUSE clock: %ld", 2017e939de1SThierry Reding PTR_ERR(fuse->clk)); 202f0b2835fSThierry Reding 20351294bf6STimo Alho fuse->base = base; 2047e939de1SThierry Reding return PTR_ERR(fuse->clk); 2057e939de1SThierry Reding } 2067e939de1SThierry Reding 2077e939de1SThierry Reding platform_set_drvdata(pdev, fuse); 2087e939de1SThierry Reding fuse->dev = &pdev->dev; 2097e939de1SThierry Reding 2107e939de1SThierry Reding if (fuse->soc->probe) { 2117e939de1SThierry Reding err = fuse->soc->probe(fuse); 2129f1022b8SThierry Reding if (err < 0) 2139f1022b8SThierry Reding goto restore; 21451294bf6STimo Alho } 2157e939de1SThierry Reding 21696ee12b2SThierry Reding memset(&nvmem, 0, sizeof(nvmem)); 21796ee12b2SThierry Reding nvmem.dev = &pdev->dev; 21896ee12b2SThierry Reding nvmem.name = "fuse"; 21996ee12b2SThierry Reding nvmem.id = -1; 22096ee12b2SThierry Reding nvmem.owner = THIS_MODULE; 221f4619c7fSThierry Reding nvmem.cells = tegra_fuse_cells; 222f4619c7fSThierry Reding nvmem.ncells = ARRAY_SIZE(tegra_fuse_cells); 22396ee12b2SThierry Reding nvmem.type = NVMEM_TYPE_OTP; 22496ee12b2SThierry Reding nvmem.read_only = true; 22596ee12b2SThierry Reding nvmem.root_only = true; 22696ee12b2SThierry Reding nvmem.reg_read = tegra_fuse_read; 22796ee12b2SThierry Reding nvmem.size = fuse->soc->info->size; 22896ee12b2SThierry Reding nvmem.word_size = 4; 22996ee12b2SThierry Reding nvmem.stride = 4; 23096ee12b2SThierry Reding nvmem.priv = fuse; 23196ee12b2SThierry Reding 23296ee12b2SThierry Reding fuse->nvmem = devm_nvmem_register(&pdev->dev, &nvmem); 23396ee12b2SThierry Reding if (IS_ERR(fuse->nvmem)) { 23496ee12b2SThierry Reding err = PTR_ERR(fuse->nvmem); 23596ee12b2SThierry Reding dev_err(&pdev->dev, "failed to register NVMEM device: %d\n", 23696ee12b2SThierry Reding err); 2379f1022b8SThierry Reding goto restore; 2389f1022b8SThierry Reding } 2397e939de1SThierry Reding 2407e939de1SThierry Reding /* release the early I/O memory mapping */ 2417e939de1SThierry Reding iounmap(base); 2427e939de1SThierry Reding 2437e939de1SThierry Reding return 0; 2449f1022b8SThierry Reding 2459f1022b8SThierry Reding restore: 2469f1022b8SThierry Reding fuse->base = base; 2479f1022b8SThierry Reding return err; 2487e939de1SThierry Reding } 2497e939de1SThierry Reding 2507e939de1SThierry Reding static struct platform_driver tegra_fuse_driver = { 2517e939de1SThierry Reding .driver = { 2527e939de1SThierry Reding .name = "tegra-fuse", 2537e939de1SThierry Reding .of_match_table = tegra_fuse_match, 2547e939de1SThierry Reding .suppress_bind_attrs = true, 2557e939de1SThierry Reding }, 2567e939de1SThierry Reding .probe = tegra_fuse_probe, 2577e939de1SThierry Reding }; 2581859217bSPaul Gortmaker builtin_platform_driver(tegra_fuse_driver); 2597e939de1SThierry Reding 2607e939de1SThierry Reding bool __init tegra_fuse_read_spare(unsigned int spare) 2617e939de1SThierry Reding { 2627e939de1SThierry Reding unsigned int offset = fuse->soc->info->spare + spare * 4; 2637e939de1SThierry Reding 2647e939de1SThierry Reding return fuse->read_early(fuse, offset) & 1; 2657e939de1SThierry Reding } 2667e939de1SThierry Reding 2677e939de1SThierry Reding u32 __init tegra_fuse_read_early(unsigned int offset) 2687e939de1SThierry Reding { 2697e939de1SThierry Reding return fuse->read_early(fuse, offset); 2707e939de1SThierry Reding } 2717e939de1SThierry Reding 2727e939de1SThierry Reding int tegra_fuse_readl(unsigned long offset, u32 *value) 2737e939de1SThierry Reding { 2740a728e0bSNagarjuna Kristam if (!fuse->read || !fuse->clk) 2757e939de1SThierry Reding return -EPROBE_DEFER; 2767e939de1SThierry Reding 2770a728e0bSNagarjuna Kristam if (IS_ERR(fuse->clk)) 2780a728e0bSNagarjuna Kristam return PTR_ERR(fuse->clk); 2790a728e0bSNagarjuna Kristam 2807e939de1SThierry Reding *value = fuse->read(fuse, offset); 2817e939de1SThierry Reding 2827e939de1SThierry Reding return 0; 2837e939de1SThierry Reding } 2847e939de1SThierry Reding EXPORT_SYMBOL(tegra_fuse_readl); 2857e939de1SThierry Reding 286783c8f4cSPeter De Schrijver static void tegra_enable_fuse_clk(void __iomem *base) 287783c8f4cSPeter De Schrijver { 288783c8f4cSPeter De Schrijver u32 reg; 289783c8f4cSPeter De Schrijver 290783c8f4cSPeter De Schrijver reg = readl_relaxed(base + 0x48); 291783c8f4cSPeter De Schrijver reg |= 1 << 28; 292783c8f4cSPeter De Schrijver writel(reg, base + 0x48); 293783c8f4cSPeter De Schrijver 294783c8f4cSPeter De Schrijver /* 295783c8f4cSPeter De Schrijver * Enable FUSE clock. This needs to be hardcoded because the clock 296783c8f4cSPeter De Schrijver * subsystem is not active during early boot. 297783c8f4cSPeter De Schrijver */ 298783c8f4cSPeter De Schrijver reg = readl(base + 0x14); 299783c8f4cSPeter De Schrijver reg |= 1 << 7; 300783c8f4cSPeter De Schrijver writel(reg, base + 0x14); 301783c8f4cSPeter De Schrijver } 302783c8f4cSPeter De Schrijver 303379ac9ebSJon Hunter static ssize_t major_show(struct device *dev, struct device_attribute *attr, 304379ac9ebSJon Hunter char *buf) 305379ac9ebSJon Hunter { 306379ac9ebSJon Hunter return sprintf(buf, "%d\n", tegra_get_major_rev()); 307379ac9ebSJon Hunter } 308379ac9ebSJon Hunter 309379ac9ebSJon Hunter static DEVICE_ATTR_RO(major); 310379ac9ebSJon Hunter 311379ac9ebSJon Hunter static ssize_t minor_show(struct device *dev, struct device_attribute *attr, 312379ac9ebSJon Hunter char *buf) 313379ac9ebSJon Hunter { 314379ac9ebSJon Hunter return sprintf(buf, "%d\n", tegra_get_minor_rev()); 315379ac9ebSJon Hunter } 316379ac9ebSJon Hunter 317379ac9ebSJon Hunter static DEVICE_ATTR_RO(minor); 318379ac9ebSJon Hunter 319379ac9ebSJon Hunter static struct attribute *tegra_soc_attr[] = { 320379ac9ebSJon Hunter &dev_attr_major.attr, 321379ac9ebSJon Hunter &dev_attr_minor.attr, 322379ac9ebSJon Hunter NULL, 323379ac9ebSJon Hunter }; 324379ac9ebSJon Hunter 325379ac9ebSJon Hunter const struct attribute_group tegra_soc_attr_group = { 326379ac9ebSJon Hunter .attrs = tegra_soc_attr, 327379ac9ebSJon Hunter }; 328379ac9ebSJon Hunter 329379ac9ebSJon Hunter #ifdef CONFIG_ARCH_TEGRA_194_SOC 330379ac9ebSJon Hunter static ssize_t platform_show(struct device *dev, struct device_attribute *attr, 331379ac9ebSJon Hunter char *buf) 332379ac9ebSJon Hunter { 333379ac9ebSJon Hunter /* 334379ac9ebSJon Hunter * Displays the value in the 'pre_si_platform' field of the HIDREV 335379ac9ebSJon Hunter * register for Tegra194 devices. A value of 0 indicates that the 336379ac9ebSJon Hunter * platform type is silicon and all other non-zero values indicate 337379ac9ebSJon Hunter * the type of simulation platform is being used. 338379ac9ebSJon Hunter */ 339*775edf78SThierry Reding return sprintf(buf, "%d\n", tegra_get_platform()); 340379ac9ebSJon Hunter } 341379ac9ebSJon Hunter 342379ac9ebSJon Hunter static DEVICE_ATTR_RO(platform); 343379ac9ebSJon Hunter 344379ac9ebSJon Hunter static struct attribute *tegra194_soc_attr[] = { 345379ac9ebSJon Hunter &dev_attr_major.attr, 346379ac9ebSJon Hunter &dev_attr_minor.attr, 347379ac9ebSJon Hunter &dev_attr_platform.attr, 348379ac9ebSJon Hunter NULL, 349379ac9ebSJon Hunter }; 350379ac9ebSJon Hunter 351379ac9ebSJon Hunter const struct attribute_group tegra194_soc_attr_group = { 352379ac9ebSJon Hunter .attrs = tegra194_soc_attr, 353379ac9ebSJon Hunter }; 354379ac9ebSJon Hunter #endif 355379ac9ebSJon Hunter 35627a0342aSThierry Reding struct device * __init tegra_soc_device_register(void) 35727a0342aSThierry Reding { 35827a0342aSThierry Reding struct soc_device_attribute *attr; 35927a0342aSThierry Reding struct soc_device *dev; 36027a0342aSThierry Reding 36127a0342aSThierry Reding attr = kzalloc(sizeof(*attr), GFP_KERNEL); 36227a0342aSThierry Reding if (!attr) 36327a0342aSThierry Reding return NULL; 36427a0342aSThierry Reding 36527a0342aSThierry Reding attr->family = kasprintf(GFP_KERNEL, "Tegra"); 36637558ac8SJon Hunter attr->revision = kasprintf(GFP_KERNEL, "%s", 36737558ac8SJon Hunter tegra_revision_name[tegra_sku_info.revision]); 36827a0342aSThierry Reding attr->soc_id = kasprintf(GFP_KERNEL, "%u", tegra_get_chip_id()); 369379ac9ebSJon Hunter attr->custom_attr_group = fuse->soc->soc_attr_group; 37027a0342aSThierry Reding 37127a0342aSThierry Reding dev = soc_device_register(attr); 37227a0342aSThierry Reding if (IS_ERR(dev)) { 37327a0342aSThierry Reding kfree(attr->soc_id); 37427a0342aSThierry Reding kfree(attr->revision); 37527a0342aSThierry Reding kfree(attr->family); 37627a0342aSThierry Reding kfree(attr); 37727a0342aSThierry Reding return ERR_CAST(dev); 37827a0342aSThierry Reding } 37927a0342aSThierry Reding 38027a0342aSThierry Reding return soc_device_to_device(dev); 38127a0342aSThierry Reding } 38227a0342aSThierry Reding 38324fa5af8SThierry Reding static int __init tegra_init_fuse(void) 384783c8f4cSPeter De Schrijver { 3857e939de1SThierry Reding const struct of_device_id *match; 386783c8f4cSPeter De Schrijver struct device_node *np; 3877e939de1SThierry Reding struct resource regs; 38824fa5af8SThierry Reding 389783c8f4cSPeter De Schrijver tegra_init_apbmisc(); 390783c8f4cSPeter De Schrijver 3917e939de1SThierry Reding np = of_find_matching_node_and_match(NULL, tegra_fuse_match, &match); 3927e939de1SThierry Reding if (!np) { 3937e939de1SThierry Reding /* 3947e939de1SThierry Reding * Fall back to legacy initialization for 32-bit ARM only. All 3957e939de1SThierry Reding * 64-bit ARM device tree files for Tegra are required to have 3967e939de1SThierry Reding * a FUSE node. 3977e939de1SThierry Reding * 3987e939de1SThierry Reding * This is for backwards-compatibility with old device trees 3997e939de1SThierry Reding * that didn't contain a FUSE node. 4007e939de1SThierry Reding */ 4017e939de1SThierry Reding if (IS_ENABLED(CONFIG_ARM) && soc_is_tegra()) { 4027e939de1SThierry Reding u8 chip = tegra_get_chip_id(); 4037e939de1SThierry Reding 4047e939de1SThierry Reding regs.start = 0x7000f800; 4057e939de1SThierry Reding regs.end = 0x7000fbff; 4067e939de1SThierry Reding regs.flags = IORESOURCE_MEM; 4077e939de1SThierry Reding 4087e939de1SThierry Reding switch (chip) { 4097e939de1SThierry Reding #ifdef CONFIG_ARCH_TEGRA_2x_SOC 4107e939de1SThierry Reding case TEGRA20: 4117e939de1SThierry Reding fuse->soc = &tegra20_fuse_soc; 4127e939de1SThierry Reding break; 4137e939de1SThierry Reding #endif 4147e939de1SThierry Reding 4157e939de1SThierry Reding #ifdef CONFIG_ARCH_TEGRA_3x_SOC 4167e939de1SThierry Reding case TEGRA30: 4177e939de1SThierry Reding fuse->soc = &tegra30_fuse_soc; 4187e939de1SThierry Reding break; 4197e939de1SThierry Reding #endif 4207e939de1SThierry Reding 4217e939de1SThierry Reding #ifdef CONFIG_ARCH_TEGRA_114_SOC 4227e939de1SThierry Reding case TEGRA114: 4237e939de1SThierry Reding fuse->soc = &tegra114_fuse_soc; 4247e939de1SThierry Reding break; 4257e939de1SThierry Reding #endif 4267e939de1SThierry Reding 4277e939de1SThierry Reding #ifdef CONFIG_ARCH_TEGRA_124_SOC 4287e939de1SThierry Reding case TEGRA124: 4297e939de1SThierry Reding fuse->soc = &tegra124_fuse_soc; 4307e939de1SThierry Reding break; 4317e939de1SThierry Reding #endif 4327e939de1SThierry Reding 4337e939de1SThierry Reding default: 4347e939de1SThierry Reding pr_warn("Unsupported SoC: %02x\n", chip); 4357e939de1SThierry Reding break; 4367e939de1SThierry Reding } 437783c8f4cSPeter De Schrijver } else { 4387e939de1SThierry Reding /* 4397e939de1SThierry Reding * At this point we're not running on Tegra, so play 4407e939de1SThierry Reding * nice with multi-platform kernels. 4417e939de1SThierry Reding */ 4427e939de1SThierry Reding return 0; 4437e939de1SThierry Reding } 4447e939de1SThierry Reding } else { 4457e939de1SThierry Reding /* 4467e939de1SThierry Reding * Extract information from the device tree if we've found a 4477e939de1SThierry Reding * matching node. 4487e939de1SThierry Reding */ 4497e939de1SThierry Reding if (of_address_to_resource(np, 0, ®s) < 0) { 4507e939de1SThierry Reding pr_err("failed to get FUSE register\n"); 45124fa5af8SThierry Reding return -ENXIO; 452783c8f4cSPeter De Schrijver } 453783c8f4cSPeter De Schrijver 4547e939de1SThierry Reding fuse->soc = match->data; 4557e939de1SThierry Reding } 4567e939de1SThierry Reding 4577e939de1SThierry Reding np = of_find_matching_node(NULL, car_match); 4587e939de1SThierry Reding if (np) { 4597e939de1SThierry Reding void __iomem *base = of_iomap(np, 0); 4607e939de1SThierry Reding if (base) { 4617e939de1SThierry Reding tegra_enable_fuse_clk(base); 4627e939de1SThierry Reding iounmap(base); 4637e939de1SThierry Reding } else { 4647e939de1SThierry Reding pr_err("failed to map clock registers\n"); 4657e939de1SThierry Reding return -ENXIO; 4667e939de1SThierry Reding } 4677e939de1SThierry Reding } 4687e939de1SThierry Reding 4694bdc0d67SChristoph Hellwig fuse->base = ioremap(regs.start, resource_size(®s)); 4707e939de1SThierry Reding if (!fuse->base) { 4717e939de1SThierry Reding pr_err("failed to map FUSE registers\n"); 4727e939de1SThierry Reding return -ENXIO; 4737e939de1SThierry Reding } 4747e939de1SThierry Reding 4757e939de1SThierry Reding fuse->soc->init(fuse); 476783c8f4cSPeter De Schrijver 47703b3f4c8SThierry Reding pr_info("Tegra Revision: %s SKU: %d CPU Process: %d SoC Process: %d\n", 478783c8f4cSPeter De Schrijver tegra_revision_name[tegra_sku_info.revision], 479783c8f4cSPeter De Schrijver tegra_sku_info.sku_id, tegra_sku_info.cpu_process_id, 48003b3f4c8SThierry Reding tegra_sku_info.soc_process_id); 48103b3f4c8SThierry Reding pr_debug("Tegra CPU Speedo ID %d, SoC Speedo ID %d\n", 482783c8f4cSPeter De Schrijver tegra_sku_info.cpu_speedo_id, tegra_sku_info.soc_speedo_id); 48324fa5af8SThierry Reding 4849f94faddSThierry Reding if (fuse->soc->lookups) { 4859f94faddSThierry Reding size_t size = sizeof(*fuse->lookups) * fuse->soc->num_lookups; 4869f94faddSThierry Reding 4879f94faddSThierry Reding fuse->lookups = kmemdup(fuse->soc->lookups, size, GFP_KERNEL); 4889f94faddSThierry Reding if (!fuse->lookups) 4899f94faddSThierry Reding return -ENOMEM; 4909f94faddSThierry Reding 4919f94faddSThierry Reding nvmem_add_cell_lookups(fuse->lookups, fuse->soc->num_lookups); 4929f94faddSThierry Reding } 49327a0342aSThierry Reding 49424fa5af8SThierry Reding return 0; 495783c8f4cSPeter De Schrijver } 49624fa5af8SThierry Reding early_initcall(tegra_init_fuse); 49727a0342aSThierry Reding 49827a0342aSThierry Reding #ifdef CONFIG_ARM64 49927a0342aSThierry Reding static int __init tegra_init_soc(void) 50027a0342aSThierry Reding { 501226cff48SThierry Reding struct device_node *np; 50227a0342aSThierry Reding struct device *soc; 50327a0342aSThierry Reding 504226cff48SThierry Reding /* make sure we're running on Tegra */ 505226cff48SThierry Reding np = of_find_matching_node(NULL, tegra_fuse_match); 506226cff48SThierry Reding if (!np) 507226cff48SThierry Reding return 0; 508226cff48SThierry Reding 509226cff48SThierry Reding of_node_put(np); 510226cff48SThierry Reding 51127a0342aSThierry Reding soc = tegra_soc_device_register(); 51227a0342aSThierry Reding if (IS_ERR(soc)) { 51327a0342aSThierry Reding pr_err("failed to register SoC device: %ld\n", PTR_ERR(soc)); 51427a0342aSThierry Reding return PTR_ERR(soc); 51527a0342aSThierry Reding } 51627a0342aSThierry Reding 51727a0342aSThierry Reding return 0; 51827a0342aSThierry Reding } 5199261b43eSThierry Reding device_initcall(tegra_init_soc); 52027a0342aSThierry Reding #endif 521