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[] = { 5283468fe2STimo Alho #ifdef CONFIG_ARCH_TEGRA_186_SOC 5383468fe2STimo Alho { .compatible = "nvidia,tegra186-efuse", .data = &tegra186_fuse_soc }, 5483468fe2STimo Alho #endif 550dc5a0d8SThierry Reding #ifdef CONFIG_ARCH_TEGRA_210_SOC 560dc5a0d8SThierry Reding { .compatible = "nvidia,tegra210-efuse", .data = &tegra210_fuse_soc }, 570dc5a0d8SThierry Reding #endif 587e939de1SThierry Reding #ifdef CONFIG_ARCH_TEGRA_132_SOC 597e939de1SThierry Reding { .compatible = "nvidia,tegra132-efuse", .data = &tegra124_fuse_soc }, 607e939de1SThierry Reding #endif 617e939de1SThierry Reding #ifdef CONFIG_ARCH_TEGRA_124_SOC 627e939de1SThierry Reding { .compatible = "nvidia,tegra124-efuse", .data = &tegra124_fuse_soc }, 637e939de1SThierry Reding #endif 647e939de1SThierry Reding #ifdef CONFIG_ARCH_TEGRA_114_SOC 657e939de1SThierry Reding { .compatible = "nvidia,tegra114-efuse", .data = &tegra114_fuse_soc }, 667e939de1SThierry Reding #endif 677e939de1SThierry Reding #ifdef CONFIG_ARCH_TEGRA_3x_SOC 687e939de1SThierry Reding { .compatible = "nvidia,tegra30-efuse", .data = &tegra30_fuse_soc }, 697e939de1SThierry Reding #endif 707e939de1SThierry Reding #ifdef CONFIG_ARCH_TEGRA_2x_SOC 717e939de1SThierry Reding { .compatible = "nvidia,tegra20-efuse", .data = &tegra20_fuse_soc }, 727e939de1SThierry Reding #endif 737e939de1SThierry Reding { /* sentinel */ } 747e939de1SThierry Reding }; 757e939de1SThierry Reding 7696ee12b2SThierry Reding static int tegra_fuse_read(void *priv, unsigned int offset, void *value, 7796ee12b2SThierry Reding size_t bytes) 7896ee12b2SThierry Reding { 7996ee12b2SThierry Reding unsigned int count = bytes / 4, i; 8096ee12b2SThierry Reding struct tegra_fuse *fuse = priv; 8196ee12b2SThierry Reding u32 *buffer = value; 8296ee12b2SThierry Reding 8396ee12b2SThierry Reding for (i = 0; i < count; i++) 8496ee12b2SThierry Reding buffer[i] = fuse->read(fuse, offset + i * 4); 8596ee12b2SThierry Reding 8696ee12b2SThierry Reding return 0; 8796ee12b2SThierry Reding } 8896ee12b2SThierry Reding 89f4619c7fSThierry Reding static const struct nvmem_cell_info tegra_fuse_cells[] = { 90f4619c7fSThierry Reding { 91f4619c7fSThierry Reding .name = "tsensor-cpu1", 92f4619c7fSThierry Reding .offset = 0x084, 93f4619c7fSThierry Reding .bytes = 4, 94f4619c7fSThierry Reding .bit_offset = 0, 95f4619c7fSThierry Reding .nbits = 32, 96f4619c7fSThierry Reding }, { 97f4619c7fSThierry Reding .name = "tsensor-cpu2", 98f4619c7fSThierry Reding .offset = 0x088, 99f4619c7fSThierry Reding .bytes = 4, 100f4619c7fSThierry Reding .bit_offset = 0, 101f4619c7fSThierry Reding .nbits = 32, 102f4619c7fSThierry Reding }, { 103f4619c7fSThierry Reding .name = "tsensor-cpu0", 104f4619c7fSThierry Reding .offset = 0x098, 105f4619c7fSThierry Reding .bytes = 4, 106f4619c7fSThierry Reding .bit_offset = 0, 107f4619c7fSThierry Reding .nbits = 32, 108f4619c7fSThierry Reding }, { 109f4619c7fSThierry Reding .name = "xusb-pad-calibration", 110f4619c7fSThierry Reding .offset = 0x0f0, 111f4619c7fSThierry Reding .bytes = 4, 112f4619c7fSThierry Reding .bit_offset = 0, 113f4619c7fSThierry Reding .nbits = 32, 114f4619c7fSThierry Reding }, { 115f4619c7fSThierry Reding .name = "tsensor-cpu3", 116f4619c7fSThierry Reding .offset = 0x12c, 117f4619c7fSThierry Reding .bytes = 4, 118f4619c7fSThierry Reding .bit_offset = 0, 119f4619c7fSThierry Reding .nbits = 32, 120f4619c7fSThierry Reding }, { 121f4619c7fSThierry Reding .name = "sata-calibration", 122f4619c7fSThierry Reding .offset = 0x124, 123f4619c7fSThierry Reding .bytes = 1, 124f4619c7fSThierry Reding .bit_offset = 0, 125f4619c7fSThierry Reding .nbits = 2, 126f4619c7fSThierry Reding }, { 127f4619c7fSThierry Reding .name = "tsensor-gpu", 128f4619c7fSThierry Reding .offset = 0x154, 129f4619c7fSThierry Reding .bytes = 4, 130f4619c7fSThierry Reding .bit_offset = 0, 131f4619c7fSThierry Reding .nbits = 32, 132f4619c7fSThierry Reding }, { 133f4619c7fSThierry Reding .name = "tsensor-mem0", 134f4619c7fSThierry Reding .offset = 0x158, 135f4619c7fSThierry Reding .bytes = 4, 136f4619c7fSThierry Reding .bit_offset = 0, 137f4619c7fSThierry Reding .nbits = 32, 138f4619c7fSThierry Reding }, { 139f4619c7fSThierry Reding .name = "tsensor-mem1", 140f4619c7fSThierry Reding .offset = 0x15c, 141f4619c7fSThierry Reding .bytes = 4, 142f4619c7fSThierry Reding .bit_offset = 0, 143f4619c7fSThierry Reding .nbits = 32, 144f4619c7fSThierry Reding }, { 145f4619c7fSThierry Reding .name = "tsensor-pllx", 146f4619c7fSThierry Reding .offset = 0x160, 147f4619c7fSThierry Reding .bytes = 4, 148f4619c7fSThierry Reding .bit_offset = 0, 149f4619c7fSThierry Reding .nbits = 32, 150f4619c7fSThierry Reding }, { 151f4619c7fSThierry Reding .name = "tsensor-common", 152f4619c7fSThierry Reding .offset = 0x180, 153f4619c7fSThierry Reding .bytes = 4, 154f4619c7fSThierry Reding .bit_offset = 0, 155f4619c7fSThierry Reding .nbits = 32, 156f4619c7fSThierry Reding }, { 157f4619c7fSThierry Reding .name = "tsensor-realignment", 158f4619c7fSThierry Reding .offset = 0x1fc, 159f4619c7fSThierry Reding .bytes = 4, 160f4619c7fSThierry Reding .bit_offset = 0, 161f4619c7fSThierry Reding .nbits = 32, 162f4619c7fSThierry Reding }, { 163f4619c7fSThierry Reding .name = "gpu-calibration", 164f4619c7fSThierry Reding .offset = 0x204, 165f4619c7fSThierry Reding .bytes = 4, 166f4619c7fSThierry Reding .bit_offset = 0, 167f4619c7fSThierry Reding .nbits = 32, 168f4619c7fSThierry Reding }, { 169f4619c7fSThierry Reding .name = "xusb-pad-calibration-ext", 170f4619c7fSThierry Reding .offset = 0x250, 171f4619c7fSThierry Reding .bytes = 4, 172f4619c7fSThierry Reding .bit_offset = 0, 173f4619c7fSThierry Reding .nbits = 32, 174f4619c7fSThierry Reding }, 175f4619c7fSThierry Reding }; 176f4619c7fSThierry Reding 1777e939de1SThierry Reding static int tegra_fuse_probe(struct platform_device *pdev) 1787e939de1SThierry Reding { 1797e939de1SThierry Reding void __iomem *base = fuse->base; 18096ee12b2SThierry Reding struct nvmem_config nvmem; 1817e939de1SThierry Reding struct resource *res; 1827e939de1SThierry Reding int err; 1837e939de1SThierry Reding 1847e939de1SThierry Reding /* take over the memory region from the early initialization */ 1857e939de1SThierry Reding res = platform_get_resource(pdev, IORESOURCE_MEM, 0); 18655a042b3SDmitry Osipenko fuse->phys = res->start; 1877e939de1SThierry Reding fuse->base = devm_ioremap_resource(&pdev->dev, res); 18851294bf6STimo Alho if (IS_ERR(fuse->base)) { 18951294bf6STimo Alho err = PTR_ERR(fuse->base); 19051294bf6STimo Alho fuse->base = base; 19151294bf6STimo Alho return err; 19251294bf6STimo Alho } 1937e939de1SThierry Reding 1947e939de1SThierry Reding fuse->clk = devm_clk_get(&pdev->dev, "fuse"); 1957e939de1SThierry Reding if (IS_ERR(fuse->clk)) { 196f0b2835fSThierry Reding if (PTR_ERR(fuse->clk) != -EPROBE_DEFER) 1977e939de1SThierry Reding dev_err(&pdev->dev, "failed to get FUSE clock: %ld", 1987e939de1SThierry Reding PTR_ERR(fuse->clk)); 199f0b2835fSThierry Reding 20051294bf6STimo Alho fuse->base = base; 2017e939de1SThierry Reding return PTR_ERR(fuse->clk); 2027e939de1SThierry Reding } 2037e939de1SThierry Reding 2047e939de1SThierry Reding platform_set_drvdata(pdev, fuse); 2057e939de1SThierry Reding fuse->dev = &pdev->dev; 2067e939de1SThierry Reding 2077e939de1SThierry Reding if (fuse->soc->probe) { 2087e939de1SThierry Reding err = fuse->soc->probe(fuse); 2099f1022b8SThierry Reding if (err < 0) 2109f1022b8SThierry Reding goto restore; 21151294bf6STimo Alho } 2127e939de1SThierry Reding 21396ee12b2SThierry Reding memset(&nvmem, 0, sizeof(nvmem)); 21496ee12b2SThierry Reding nvmem.dev = &pdev->dev; 21596ee12b2SThierry Reding nvmem.name = "fuse"; 21696ee12b2SThierry Reding nvmem.id = -1; 21796ee12b2SThierry Reding nvmem.owner = THIS_MODULE; 218f4619c7fSThierry Reding nvmem.cells = tegra_fuse_cells; 219f4619c7fSThierry Reding nvmem.ncells = ARRAY_SIZE(tegra_fuse_cells); 22096ee12b2SThierry Reding nvmem.type = NVMEM_TYPE_OTP; 22196ee12b2SThierry Reding nvmem.read_only = true; 22296ee12b2SThierry Reding nvmem.root_only = true; 22396ee12b2SThierry Reding nvmem.reg_read = tegra_fuse_read; 22496ee12b2SThierry Reding nvmem.size = fuse->soc->info->size; 22596ee12b2SThierry Reding nvmem.word_size = 4; 22696ee12b2SThierry Reding nvmem.stride = 4; 22796ee12b2SThierry Reding nvmem.priv = fuse; 22896ee12b2SThierry Reding 22996ee12b2SThierry Reding fuse->nvmem = devm_nvmem_register(&pdev->dev, &nvmem); 23096ee12b2SThierry Reding if (IS_ERR(fuse->nvmem)) { 23196ee12b2SThierry Reding err = PTR_ERR(fuse->nvmem); 23296ee12b2SThierry Reding dev_err(&pdev->dev, "failed to register NVMEM device: %d\n", 23396ee12b2SThierry Reding err); 2349f1022b8SThierry Reding goto restore; 2359f1022b8SThierry Reding } 2367e939de1SThierry Reding 2377e939de1SThierry Reding /* release the early I/O memory mapping */ 2387e939de1SThierry Reding iounmap(base); 2397e939de1SThierry Reding 2407e939de1SThierry Reding return 0; 2419f1022b8SThierry Reding 2429f1022b8SThierry Reding restore: 2439f1022b8SThierry Reding fuse->base = base; 2449f1022b8SThierry Reding return err; 2457e939de1SThierry Reding } 2467e939de1SThierry Reding 2477e939de1SThierry Reding static struct platform_driver tegra_fuse_driver = { 2487e939de1SThierry Reding .driver = { 2497e939de1SThierry Reding .name = "tegra-fuse", 2507e939de1SThierry Reding .of_match_table = tegra_fuse_match, 2517e939de1SThierry Reding .suppress_bind_attrs = true, 2527e939de1SThierry Reding }, 2537e939de1SThierry Reding .probe = tegra_fuse_probe, 2547e939de1SThierry Reding }; 2551859217bSPaul Gortmaker builtin_platform_driver(tegra_fuse_driver); 2567e939de1SThierry Reding 2577e939de1SThierry Reding bool __init tegra_fuse_read_spare(unsigned int spare) 2587e939de1SThierry Reding { 2597e939de1SThierry Reding unsigned int offset = fuse->soc->info->spare + spare * 4; 2607e939de1SThierry Reding 2617e939de1SThierry Reding return fuse->read_early(fuse, offset) & 1; 2627e939de1SThierry Reding } 2637e939de1SThierry Reding 2647e939de1SThierry Reding u32 __init tegra_fuse_read_early(unsigned int offset) 2657e939de1SThierry Reding { 2667e939de1SThierry Reding return fuse->read_early(fuse, offset); 2677e939de1SThierry Reding } 2687e939de1SThierry Reding 2697e939de1SThierry Reding int tegra_fuse_readl(unsigned long offset, u32 *value) 2707e939de1SThierry Reding { 2710a728e0bSNagarjuna Kristam if (!fuse->read || !fuse->clk) 2727e939de1SThierry Reding return -EPROBE_DEFER; 2737e939de1SThierry Reding 2740a728e0bSNagarjuna Kristam if (IS_ERR(fuse->clk)) 2750a728e0bSNagarjuna Kristam return PTR_ERR(fuse->clk); 2760a728e0bSNagarjuna Kristam 2777e939de1SThierry Reding *value = fuse->read(fuse, offset); 2787e939de1SThierry Reding 2797e939de1SThierry Reding return 0; 2807e939de1SThierry Reding } 2817e939de1SThierry Reding EXPORT_SYMBOL(tegra_fuse_readl); 2827e939de1SThierry Reding 283783c8f4cSPeter De Schrijver static void tegra_enable_fuse_clk(void __iomem *base) 284783c8f4cSPeter De Schrijver { 285783c8f4cSPeter De Schrijver u32 reg; 286783c8f4cSPeter De Schrijver 287783c8f4cSPeter De Schrijver reg = readl_relaxed(base + 0x48); 288783c8f4cSPeter De Schrijver reg |= 1 << 28; 289783c8f4cSPeter De Schrijver writel(reg, base + 0x48); 290783c8f4cSPeter De Schrijver 291783c8f4cSPeter De Schrijver /* 292783c8f4cSPeter De Schrijver * Enable FUSE clock. This needs to be hardcoded because the clock 293783c8f4cSPeter De Schrijver * subsystem is not active during early boot. 294783c8f4cSPeter De Schrijver */ 295783c8f4cSPeter De Schrijver reg = readl(base + 0x14); 296783c8f4cSPeter De Schrijver reg |= 1 << 7; 297783c8f4cSPeter De Schrijver writel(reg, base + 0x14); 298783c8f4cSPeter De Schrijver } 299783c8f4cSPeter De Schrijver 30027a0342aSThierry Reding struct device * __init tegra_soc_device_register(void) 30127a0342aSThierry Reding { 30227a0342aSThierry Reding struct soc_device_attribute *attr; 30327a0342aSThierry Reding struct soc_device *dev; 30427a0342aSThierry Reding 30527a0342aSThierry Reding attr = kzalloc(sizeof(*attr), GFP_KERNEL); 30627a0342aSThierry Reding if (!attr) 30727a0342aSThierry Reding return NULL; 30827a0342aSThierry Reding 30927a0342aSThierry Reding attr->family = kasprintf(GFP_KERNEL, "Tegra"); 31027a0342aSThierry Reding attr->revision = kasprintf(GFP_KERNEL, "%d", tegra_sku_info.revision); 31127a0342aSThierry Reding attr->soc_id = kasprintf(GFP_KERNEL, "%u", tegra_get_chip_id()); 31227a0342aSThierry Reding 31327a0342aSThierry Reding dev = soc_device_register(attr); 31427a0342aSThierry Reding if (IS_ERR(dev)) { 31527a0342aSThierry Reding kfree(attr->soc_id); 31627a0342aSThierry Reding kfree(attr->revision); 31727a0342aSThierry Reding kfree(attr->family); 31827a0342aSThierry Reding kfree(attr); 31927a0342aSThierry Reding return ERR_CAST(dev); 32027a0342aSThierry Reding } 32127a0342aSThierry Reding 32227a0342aSThierry Reding return soc_device_to_device(dev); 32327a0342aSThierry Reding } 32427a0342aSThierry Reding 32524fa5af8SThierry Reding static int __init tegra_init_fuse(void) 326783c8f4cSPeter De Schrijver { 3277e939de1SThierry Reding const struct of_device_id *match; 328783c8f4cSPeter De Schrijver struct device_node *np; 3297e939de1SThierry Reding struct resource regs; 33024fa5af8SThierry Reding 331783c8f4cSPeter De Schrijver tegra_init_apbmisc(); 332783c8f4cSPeter De Schrijver 3337e939de1SThierry Reding np = of_find_matching_node_and_match(NULL, tegra_fuse_match, &match); 3347e939de1SThierry Reding if (!np) { 3357e939de1SThierry Reding /* 3367e939de1SThierry Reding * Fall back to legacy initialization for 32-bit ARM only. All 3377e939de1SThierry Reding * 64-bit ARM device tree files for Tegra are required to have 3387e939de1SThierry Reding * a FUSE node. 3397e939de1SThierry Reding * 3407e939de1SThierry Reding * This is for backwards-compatibility with old device trees 3417e939de1SThierry Reding * that didn't contain a FUSE node. 3427e939de1SThierry Reding */ 3437e939de1SThierry Reding if (IS_ENABLED(CONFIG_ARM) && soc_is_tegra()) { 3447e939de1SThierry Reding u8 chip = tegra_get_chip_id(); 3457e939de1SThierry Reding 3467e939de1SThierry Reding regs.start = 0x7000f800; 3477e939de1SThierry Reding regs.end = 0x7000fbff; 3487e939de1SThierry Reding regs.flags = IORESOURCE_MEM; 3497e939de1SThierry Reding 3507e939de1SThierry Reding switch (chip) { 3517e939de1SThierry Reding #ifdef CONFIG_ARCH_TEGRA_2x_SOC 3527e939de1SThierry Reding case TEGRA20: 3537e939de1SThierry Reding fuse->soc = &tegra20_fuse_soc; 3547e939de1SThierry Reding break; 3557e939de1SThierry Reding #endif 3567e939de1SThierry Reding 3577e939de1SThierry Reding #ifdef CONFIG_ARCH_TEGRA_3x_SOC 3587e939de1SThierry Reding case TEGRA30: 3597e939de1SThierry Reding fuse->soc = &tegra30_fuse_soc; 3607e939de1SThierry Reding break; 3617e939de1SThierry Reding #endif 3627e939de1SThierry Reding 3637e939de1SThierry Reding #ifdef CONFIG_ARCH_TEGRA_114_SOC 3647e939de1SThierry Reding case TEGRA114: 3657e939de1SThierry Reding fuse->soc = &tegra114_fuse_soc; 3667e939de1SThierry Reding break; 3677e939de1SThierry Reding #endif 3687e939de1SThierry Reding 3697e939de1SThierry Reding #ifdef CONFIG_ARCH_TEGRA_124_SOC 3707e939de1SThierry Reding case TEGRA124: 3717e939de1SThierry Reding fuse->soc = &tegra124_fuse_soc; 3727e939de1SThierry Reding break; 3737e939de1SThierry Reding #endif 3747e939de1SThierry Reding 3757e939de1SThierry Reding default: 3767e939de1SThierry Reding pr_warn("Unsupported SoC: %02x\n", chip); 3777e939de1SThierry Reding break; 3787e939de1SThierry Reding } 379783c8f4cSPeter De Schrijver } else { 3807e939de1SThierry Reding /* 3817e939de1SThierry Reding * At this point we're not running on Tegra, so play 3827e939de1SThierry Reding * nice with multi-platform kernels. 3837e939de1SThierry Reding */ 3847e939de1SThierry Reding return 0; 3857e939de1SThierry Reding } 3867e939de1SThierry Reding } else { 3877e939de1SThierry Reding /* 3887e939de1SThierry Reding * Extract information from the device tree if we've found a 3897e939de1SThierry Reding * matching node. 3907e939de1SThierry Reding */ 3917e939de1SThierry Reding if (of_address_to_resource(np, 0, ®s) < 0) { 3927e939de1SThierry Reding pr_err("failed to get FUSE register\n"); 39324fa5af8SThierry Reding return -ENXIO; 394783c8f4cSPeter De Schrijver } 395783c8f4cSPeter De Schrijver 3967e939de1SThierry Reding fuse->soc = match->data; 3977e939de1SThierry Reding } 3987e939de1SThierry Reding 3997e939de1SThierry Reding np = of_find_matching_node(NULL, car_match); 4007e939de1SThierry Reding if (np) { 4017e939de1SThierry Reding void __iomem *base = of_iomap(np, 0); 4027e939de1SThierry Reding if (base) { 4037e939de1SThierry Reding tegra_enable_fuse_clk(base); 4047e939de1SThierry Reding iounmap(base); 4057e939de1SThierry Reding } else { 4067e939de1SThierry Reding pr_err("failed to map clock registers\n"); 4077e939de1SThierry Reding return -ENXIO; 4087e939de1SThierry Reding } 4097e939de1SThierry Reding } 4107e939de1SThierry Reding 4117e939de1SThierry Reding fuse->base = ioremap_nocache(regs.start, resource_size(®s)); 4127e939de1SThierry Reding if (!fuse->base) { 4137e939de1SThierry Reding pr_err("failed to map FUSE registers\n"); 4147e939de1SThierry Reding return -ENXIO; 4157e939de1SThierry Reding } 4167e939de1SThierry Reding 4177e939de1SThierry Reding fuse->soc->init(fuse); 418783c8f4cSPeter De Schrijver 41903b3f4c8SThierry Reding pr_info("Tegra Revision: %s SKU: %d CPU Process: %d SoC Process: %d\n", 420783c8f4cSPeter De Schrijver tegra_revision_name[tegra_sku_info.revision], 421783c8f4cSPeter De Schrijver tegra_sku_info.sku_id, tegra_sku_info.cpu_process_id, 42203b3f4c8SThierry Reding tegra_sku_info.soc_process_id); 42303b3f4c8SThierry Reding pr_debug("Tegra CPU Speedo ID %d, SoC Speedo ID %d\n", 424783c8f4cSPeter De Schrijver tegra_sku_info.cpu_speedo_id, tegra_sku_info.soc_speedo_id); 42524fa5af8SThierry Reding 426*9f94faddSThierry Reding if (fuse->soc->lookups) { 427*9f94faddSThierry Reding size_t size = sizeof(*fuse->lookups) * fuse->soc->num_lookups; 428*9f94faddSThierry Reding 429*9f94faddSThierry Reding fuse->lookups = kmemdup(fuse->soc->lookups, size, GFP_KERNEL); 430*9f94faddSThierry Reding if (!fuse->lookups) 431*9f94faddSThierry Reding return -ENOMEM; 432*9f94faddSThierry Reding 433*9f94faddSThierry Reding nvmem_add_cell_lookups(fuse->lookups, fuse->soc->num_lookups); 434*9f94faddSThierry Reding } 43527a0342aSThierry Reding 43624fa5af8SThierry Reding return 0; 437783c8f4cSPeter De Schrijver } 43824fa5af8SThierry Reding early_initcall(tegra_init_fuse); 43927a0342aSThierry Reding 44027a0342aSThierry Reding #ifdef CONFIG_ARM64 44127a0342aSThierry Reding static int __init tegra_init_soc(void) 44227a0342aSThierry Reding { 443226cff48SThierry Reding struct device_node *np; 44427a0342aSThierry Reding struct device *soc; 44527a0342aSThierry Reding 446226cff48SThierry Reding /* make sure we're running on Tegra */ 447226cff48SThierry Reding np = of_find_matching_node(NULL, tegra_fuse_match); 448226cff48SThierry Reding if (!np) 449226cff48SThierry Reding return 0; 450226cff48SThierry Reding 451226cff48SThierry Reding of_node_put(np); 452226cff48SThierry Reding 45327a0342aSThierry Reding soc = tegra_soc_device_register(); 45427a0342aSThierry Reding if (IS_ERR(soc)) { 45527a0342aSThierry Reding pr_err("failed to register SoC device: %ld\n", PTR_ERR(soc)); 45627a0342aSThierry Reding return PTR_ERR(soc); 45727a0342aSThierry Reding } 45827a0342aSThierry Reding 45927a0342aSThierry Reding return 0; 46027a0342aSThierry Reding } 4619261b43eSThierry Reding device_initcall(tegra_init_soc); 46227a0342aSThierry Reding #endif 463