cpu-imx5.c 3.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164
  1. /*
  2. * Copyright 2008-2010 Freescale Semiconductor, Inc. All Rights Reserved.
  3. *
  4. * The code contained herein is licensed under the GNU General Public
  5. * License. You may obtain a copy of the GNU General Public License
  6. * Version 2 or later at the following locations:
  7. *
  8. * http://www.opensource.org/licenses/gpl-license.html
  9. * http://www.gnu.org/copyleft/gpl.html
  10. *
  11. * This file contains the CPU initialization code.
  12. */
  13. #include <linux/types.h>
  14. #include <linux/kernel.h>
  15. #include <linux/init.h>
  16. #include <linux/module.h>
  17. #include <linux/io.h>
  18. #include <linux/of.h>
  19. #include <linux/of_address.h>
  20. #include "hardware.h"
  21. #include "common.h"
  22. static int mx5_cpu_rev = -1;
  23. #define IIM_SREV 0x24
  24. static u32 imx5_read_srev_reg(const char *compat)
  25. {
  26. void __iomem *iim_base;
  27. struct device_node *np;
  28. u32 srev;
  29. np = of_find_compatible_node(NULL, NULL, compat);
  30. iim_base = of_iomap(np, 0);
  31. WARN_ON(!iim_base);
  32. srev = readl(iim_base + IIM_SREV) & 0xff;
  33. iounmap(iim_base);
  34. return srev;
  35. }
  36. static int get_mx51_srev(void)
  37. {
  38. u32 rev = imx5_read_srev_reg("fsl,imx51-iim");
  39. switch (rev) {
  40. case 0x0:
  41. return IMX_CHIP_REVISION_2_0;
  42. case 0x10:
  43. return IMX_CHIP_REVISION_3_0;
  44. default:
  45. return IMX_CHIP_REVISION_UNKNOWN;
  46. }
  47. }
  48. /*
  49. * Returns:
  50. * the silicon revision of the cpu
  51. */
  52. int mx51_revision(void)
  53. {
  54. if (mx5_cpu_rev == -1)
  55. mx5_cpu_rev = get_mx51_srev();
  56. return mx5_cpu_rev;
  57. }
  58. EXPORT_SYMBOL(mx51_revision);
  59. #ifdef CONFIG_NEON
  60. /*
  61. * All versions of the silicon before Rev. 3 have broken NEON implementations.
  62. * Dependent on link order - so the assumption is that vfp_init is called
  63. * before us.
  64. */
  65. int __init mx51_neon_fixup(void)
  66. {
  67. if (mx51_revision() < IMX_CHIP_REVISION_3_0 &&
  68. (elf_hwcap & HWCAP_NEON)) {
  69. elf_hwcap &= ~HWCAP_NEON;
  70. pr_info("Turning off NEON support, detected broken NEON implementation\n");
  71. }
  72. return 0;
  73. }
  74. #endif
  75. static int get_mx53_srev(void)
  76. {
  77. u32 rev = imx5_read_srev_reg("fsl,imx53-iim");
  78. switch (rev) {
  79. case 0x0:
  80. return IMX_CHIP_REVISION_1_0;
  81. case 0x2:
  82. return IMX_CHIP_REVISION_2_0;
  83. case 0x3:
  84. return IMX_CHIP_REVISION_2_1;
  85. default:
  86. return IMX_CHIP_REVISION_UNKNOWN;
  87. }
  88. }
  89. /*
  90. * Returns:
  91. * the silicon revision of the cpu
  92. */
  93. int mx53_revision(void)
  94. {
  95. if (mx5_cpu_rev == -1)
  96. mx5_cpu_rev = get_mx53_srev();
  97. return mx5_cpu_rev;
  98. }
  99. EXPORT_SYMBOL(mx53_revision);
  100. #define ARM_GPC 0x4
  101. #define DBGEN BIT(16)
  102. /*
  103. * This enables the DBGEN bit in ARM_GPC register, which is
  104. * required for accessing some performance counter features.
  105. * Technically it is only required while perf is used, but to
  106. * keep the source code simple we just enable it all the time
  107. * when the kernel configuration allows using the feature.
  108. */
  109. void __init imx5_pmu_init(void)
  110. {
  111. void __iomem *tigerp_base;
  112. struct device_node *np;
  113. u32 gpc;
  114. if (!IS_ENABLED(CONFIG_ARM_PMU))
  115. return;
  116. np = of_find_compatible_node(NULL, NULL, "arm,cortex-a8-pmu");
  117. if (!np)
  118. return;
  119. if (!of_property_read_bool(np, "secure-reg-access"))
  120. goto exit;
  121. of_node_put(np);
  122. np = of_find_compatible_node(NULL, NULL, "fsl,imx51-tigerp");
  123. if (!np)
  124. return;
  125. tigerp_base = of_iomap(np, 0);
  126. if (!tigerp_base)
  127. goto exit;
  128. gpc = readl_relaxed(tigerp_base + ARM_GPC);
  129. gpc |= DBGEN;
  130. writel_relaxed(gpc, tigerp_base + ARM_GPC);
  131. iounmap(tigerp_base);
  132. exit:
  133. of_node_put(np);
  134. }