tegra-apbmisc.c 2.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115
  1. /*
  2. * Copyright (c) 2014, NVIDIA CORPORATION. All rights reserved.
  3. *
  4. * This program is free software; you can redistribute it and/or modify it
  5. * under the terms and conditions of the GNU General Public License,
  6. * version 2, as published by the Free Software Foundation.
  7. *
  8. * This program is distributed in the hope it will be useful, but WITHOUT
  9. * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
  10. * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
  11. * more details.
  12. *
  13. * You should have received a copy of the GNU General Public License
  14. * along with this program. If not, see <http://www.gnu.org/licenses/>.
  15. *
  16. */
  17. #include <linux/kernel.h>
  18. #include <linux/of.h>
  19. #include <linux/of_address.h>
  20. #include <linux/io.h>
  21. #include <soc/tegra/fuse.h>
  22. #include "fuse.h"
  23. #define APBMISC_BASE 0x70000800
  24. #define APBMISC_SIZE 0x64
  25. #define FUSE_SKU_INFO 0x10
  26. static void __iomem *apbmisc_base;
  27. static void __iomem *strapping_base;
  28. u32 tegra_read_chipid(void)
  29. {
  30. return readl_relaxed(apbmisc_base + 4);
  31. }
  32. u8 tegra_get_chip_id(void)
  33. {
  34. if (!apbmisc_base) {
  35. WARN(1, "Tegra Chip ID not yet available\n");
  36. return 0;
  37. }
  38. return (tegra_read_chipid() >> 8) & 0xff;
  39. }
  40. u32 tegra_read_straps(void)
  41. {
  42. if (strapping_base)
  43. return readl_relaxed(strapping_base);
  44. else
  45. return 0;
  46. }
  47. static const struct of_device_id apbmisc_match[] __initconst = {
  48. { .compatible = "nvidia,tegra20-apbmisc", },
  49. {},
  50. };
  51. void __init tegra_init_revision(void)
  52. {
  53. u32 id, chip_id, minor_rev;
  54. int rev;
  55. id = tegra_read_chipid();
  56. chip_id = (id >> 8) & 0xff;
  57. minor_rev = (id >> 16) & 0xf;
  58. switch (minor_rev) {
  59. case 1:
  60. rev = TEGRA_REVISION_A01;
  61. break;
  62. case 2:
  63. rev = TEGRA_REVISION_A02;
  64. break;
  65. case 3:
  66. if (chip_id == TEGRA20 && (tegra20_spare_fuse_early(18) ||
  67. tegra20_spare_fuse_early(19)))
  68. rev = TEGRA_REVISION_A03p;
  69. else
  70. rev = TEGRA_REVISION_A03;
  71. break;
  72. case 4:
  73. rev = TEGRA_REVISION_A04;
  74. break;
  75. default:
  76. rev = TEGRA_REVISION_UNKNOWN;
  77. }
  78. tegra_sku_info.revision = rev;
  79. if (chip_id == TEGRA20)
  80. tegra_sku_info.sku_id = tegra20_fuse_early(FUSE_SKU_INFO);
  81. else
  82. tegra_sku_info.sku_id = tegra30_fuse_readl(FUSE_SKU_INFO);
  83. }
  84. void __init tegra_init_apbmisc(void)
  85. {
  86. struct device_node *np;
  87. np = of_find_matching_node(NULL, apbmisc_match);
  88. apbmisc_base = of_iomap(np, 0);
  89. if (!apbmisc_base) {
  90. pr_warn("ioremap tegra apbmisc failed. using %08x instead\n",
  91. APBMISC_BASE);
  92. apbmisc_base = ioremap(APBMISC_BASE, APBMISC_SIZE);
  93. }
  94. strapping_base = of_iomap(np, 1);
  95. if (!strapping_base)
  96. pr_err("ioremap tegra strapping_base failed\n");
  97. }