cpu.c 3.3 KB

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