cpu.c 3.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170
  1. // SPDX-License-Identifier: GPL-2.0
  2. #include <linux/err.h>
  3. #include <linux/module.h>
  4. #include <linux/io.h>
  5. #include <linux/of.h>
  6. #include <linux/of_address.h>
  7. #include <linux/slab.h>
  8. #include <linux/sys_soc.h>
  9. #include "hardware.h"
  10. #include "common.h"
  11. unsigned int __mxc_cpu_type;
  12. static unsigned int imx_soc_revision;
  13. void mxc_set_cpu_type(unsigned int type)
  14. {
  15. __mxc_cpu_type = type;
  16. }
  17. void imx_set_soc_revision(unsigned int rev)
  18. {
  19. imx_soc_revision = rev;
  20. }
  21. unsigned int imx_get_soc_revision(void)
  22. {
  23. return imx_soc_revision;
  24. }
  25. void imx_print_silicon_rev(const char *cpu, int srev)
  26. {
  27. if (srev == IMX_CHIP_REVISION_UNKNOWN)
  28. pr_info("CPU identified as %s, unknown revision\n", cpu);
  29. else
  30. pr_info("CPU identified as %s, silicon rev %d.%d\n",
  31. cpu, (srev >> 4) & 0xf, srev & 0xf);
  32. }
  33. void __init imx_set_aips(void __iomem *base)
  34. {
  35. unsigned int reg;
  36. /*
  37. * Set all MPROTx to be non-bufferable, trusted for R/W,
  38. * not forced to user-mode.
  39. */
  40. imx_writel(0x77777777, base + 0x0);
  41. imx_writel(0x77777777, base + 0x4);
  42. /*
  43. * Set all OPACRx to be non-bufferable, to not require
  44. * supervisor privilege level for access, allow for
  45. * write access and untrusted master access.
  46. */
  47. imx_writel(0x0, base + 0x40);
  48. imx_writel(0x0, base + 0x44);
  49. imx_writel(0x0, base + 0x48);
  50. imx_writel(0x0, base + 0x4C);
  51. reg = imx_readl(base + 0x50) & 0x00FFFFFF;
  52. imx_writel(reg, base + 0x50);
  53. }
  54. void __init imx_aips_allow_unprivileged_access(
  55. const char *compat)
  56. {
  57. void __iomem *aips_base_addr;
  58. struct device_node *np;
  59. for_each_compatible_node(np, NULL, compat) {
  60. aips_base_addr = of_iomap(np, 0);
  61. WARN_ON(!aips_base_addr);
  62. imx_set_aips(aips_base_addr);
  63. }
  64. }
  65. struct device * __init imx_soc_device_init(void)
  66. {
  67. struct soc_device_attribute *soc_dev_attr;
  68. struct soc_device *soc_dev;
  69. struct device_node *root;
  70. const char *soc_id;
  71. int ret;
  72. soc_dev_attr = kzalloc(sizeof(*soc_dev_attr), GFP_KERNEL);
  73. if (!soc_dev_attr)
  74. return NULL;
  75. soc_dev_attr->family = "Freescale i.MX";
  76. root = of_find_node_by_path("/");
  77. ret = of_property_read_string(root, "model", &soc_dev_attr->machine);
  78. of_node_put(root);
  79. if (ret)
  80. goto free_soc;
  81. switch (__mxc_cpu_type) {
  82. case MXC_CPU_MX1:
  83. soc_id = "i.MX1";
  84. break;
  85. case MXC_CPU_MX21:
  86. soc_id = "i.MX21";
  87. break;
  88. case MXC_CPU_MX25:
  89. soc_id = "i.MX25";
  90. break;
  91. case MXC_CPU_MX27:
  92. soc_id = "i.MX27";
  93. break;
  94. case MXC_CPU_MX31:
  95. soc_id = "i.MX31";
  96. break;
  97. case MXC_CPU_MX35:
  98. soc_id = "i.MX35";
  99. break;
  100. case MXC_CPU_MX51:
  101. soc_id = "i.MX51";
  102. break;
  103. case MXC_CPU_MX53:
  104. soc_id = "i.MX53";
  105. break;
  106. case MXC_CPU_IMX6SL:
  107. soc_id = "i.MX6SL";
  108. break;
  109. case MXC_CPU_IMX6DL:
  110. soc_id = "i.MX6DL";
  111. break;
  112. case MXC_CPU_IMX6SX:
  113. soc_id = "i.MX6SX";
  114. break;
  115. case MXC_CPU_IMX6Q:
  116. soc_id = "i.MX6Q";
  117. break;
  118. case MXC_CPU_IMX6UL:
  119. soc_id = "i.MX6UL";
  120. break;
  121. case MXC_CPU_IMX6ULL:
  122. soc_id = "i.MX6ULL";
  123. break;
  124. case MXC_CPU_IMX6ULZ:
  125. soc_id = "i.MX6ULZ";
  126. break;
  127. case MXC_CPU_IMX6SLL:
  128. soc_id = "i.MX6SLL";
  129. break;
  130. case MXC_CPU_IMX7D:
  131. soc_id = "i.MX7D";
  132. break;
  133. default:
  134. soc_id = "Unknown";
  135. }
  136. soc_dev_attr->soc_id = soc_id;
  137. soc_dev_attr->revision = kasprintf(GFP_KERNEL, "%d.%d",
  138. (imx_soc_revision >> 4) & 0xf,
  139. imx_soc_revision & 0xf);
  140. if (!soc_dev_attr->revision)
  141. goto free_soc;
  142. soc_dev = soc_device_register(soc_dev_attr);
  143. if (IS_ERR(soc_dev))
  144. goto free_rev;
  145. return soc_device_to_device(soc_dev);
  146. free_rev:
  147. kfree(soc_dev_attr->revision);
  148. free_soc:
  149. kfree(soc_dev_attr);
  150. return NULL;
  151. }