pm-rcar-gen2.c 3.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160
  1. /*
  2. * R-Car Generation 2 Power management support
  3. *
  4. * Copyright (C) 2013 - 2015 Renesas Electronics Corporation
  5. * Copyright (C) 2011 Renesas Solutions Corp.
  6. * Copyright (C) 2011 Magnus Damm
  7. *
  8. * This file is subject to the terms and conditions of the GNU General Public
  9. * License. See the file "COPYING" in the main directory of this archive
  10. * for more details.
  11. */
  12. #include <linux/kernel.h>
  13. #include <linux/ioport.h>
  14. #include <linux/of.h>
  15. #include <linux/of_address.h>
  16. #include <linux/smp.h>
  17. #include <linux/soc/renesas/rcar-sysc.h>
  18. #include <asm/io.h>
  19. #include <asm/cputype.h>
  20. #include "common.h"
  21. #include "rcar-gen2.h"
  22. /* RST */
  23. #define RST 0xe6160000
  24. #define CA15BAR 0x0020 /* CA15 Boot Address Register */
  25. #define CA7BAR 0x0030 /* CA7 Boot Address Register */
  26. #define CA15RESCNT 0x0040 /* CA15 Reset Control Register */
  27. #define CA7RESCNT 0x0044 /* CA7 Reset Control Register */
  28. /* SYS Boot Address Register */
  29. #define SBAR_BAREN BIT(4) /* SBAR is valid */
  30. /* Reset Control Registers */
  31. #define CA15RESCNT_CODE 0xa5a50000
  32. #define CA15RESCNT_CPUS 0xf /* CPU0-3 */
  33. #define CA7RESCNT_CODE 0x5a5a0000
  34. #define CA7RESCNT_CPUS 0xf /* CPU0-3 */
  35. /* On-chip RAM */
  36. #define ICRAM1 0xe63c0000 /* Inter Connect RAM1 (4 KiB) */
  37. static inline u32 phys_to_sbar(phys_addr_t addr)
  38. {
  39. return (addr >> 8) & 0xfffffc00;
  40. }
  41. /* SYSC */
  42. #define SYSCIER 0x0c
  43. #define SYSCIMR 0x10
  44. #if defined(CONFIG_SMP)
  45. static void __init rcar_gen2_sysc_init(u32 syscier)
  46. {
  47. rcar_sysc_init(0xe6180000, syscier);
  48. }
  49. #else /* CONFIG_SMP */
  50. static inline void rcar_gen2_sysc_init(u32 syscier) {}
  51. #endif /* CONFIG_SMP */
  52. void __init rcar_gen2_pm_init(void)
  53. {
  54. void __iomem *p;
  55. u32 bar;
  56. static int once;
  57. struct device_node *np, *cpus;
  58. bool has_a7 = false;
  59. bool has_a15 = false;
  60. struct resource res;
  61. u32 syscier = 0;
  62. int error;
  63. if (once++)
  64. return;
  65. cpus = of_find_node_by_path("/cpus");
  66. if (!cpus)
  67. return;
  68. for_each_child_of_node(cpus, np) {
  69. if (of_device_is_compatible(np, "arm,cortex-a15"))
  70. has_a15 = true;
  71. else if (of_device_is_compatible(np, "arm,cortex-a7"))
  72. has_a7 = true;
  73. }
  74. if (of_machine_is_compatible("renesas,r8a7790"))
  75. syscier = 0x013111ef;
  76. else if (of_machine_is_compatible("renesas,r8a7791"))
  77. syscier = 0x00111003;
  78. np = of_find_compatible_node(NULL, NULL, "renesas,smp-sram");
  79. if (!np) {
  80. /* No smp-sram in DT, fall back to hardcoded address */
  81. res = (struct resource)DEFINE_RES_MEM(ICRAM1,
  82. shmobile_boot_size);
  83. goto map;
  84. }
  85. error = of_address_to_resource(np, 0, &res);
  86. if (error) {
  87. pr_err("Failed to get smp-sram address: %d\n", error);
  88. return;
  89. }
  90. map:
  91. /* RAM for jump stub, because BAR requires 256KB aligned address */
  92. if (res.start & (256 * 1024 - 1) ||
  93. resource_size(&res) < shmobile_boot_size) {
  94. pr_err("Invalid smp-sram region\n");
  95. return;
  96. }
  97. p = ioremap(res.start, resource_size(&res));
  98. if (!p)
  99. return;
  100. /*
  101. * install the reset vector, use the largest version if we have enough
  102. * memory available
  103. */
  104. if (resource_size(&res) >= shmobile_boot_size_gen2) {
  105. shmobile_boot_cpu_gen2 = read_cpuid_mpidr();
  106. memcpy_toio(p, shmobile_boot_vector_gen2,
  107. shmobile_boot_size_gen2);
  108. } else {
  109. memcpy_toio(p, shmobile_boot_vector, shmobile_boot_size);
  110. }
  111. iounmap(p);
  112. /* setup reset vectors */
  113. p = ioremap_nocache(RST, 0x63);
  114. bar = phys_to_sbar(res.start);
  115. if (has_a15) {
  116. writel_relaxed(bar, p + CA15BAR);
  117. writel_relaxed(bar | SBAR_BAREN, p + CA15BAR);
  118. /* de-assert reset for CA15 CPUs */
  119. writel_relaxed((readl_relaxed(p + CA15RESCNT) &
  120. ~CA15RESCNT_CPUS) | CA15RESCNT_CODE,
  121. p + CA15RESCNT);
  122. }
  123. if (has_a7) {
  124. writel_relaxed(bar, p + CA7BAR);
  125. writel_relaxed(bar | SBAR_BAREN, p + CA7BAR);
  126. /* de-assert reset for CA7 CPUs */
  127. writel_relaxed((readl_relaxed(p + CA7RESCNT) &
  128. ~CA7RESCNT_CPUS) | CA7RESCNT_CODE,
  129. p + CA7RESCNT);
  130. }
  131. iounmap(p);
  132. rcar_gen2_sysc_init(syscier);
  133. shmobile_smp_apmu_suspend_init();
  134. }