pm-rcar-gen2.c 3.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136
  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 <asm/io.h>
  18. #include <asm/cputype.h>
  19. #include "common.h"
  20. #include "rcar-gen2.h"
  21. /* RST */
  22. #define RST 0xe6160000
  23. #define CA15BAR 0x0020 /* CA15 Boot Address Register */
  24. #define CA7BAR 0x0030 /* CA7 Boot Address Register */
  25. #define CA15RESCNT 0x0040 /* CA15 Reset Control Register */
  26. #define CA7RESCNT 0x0044 /* CA7 Reset Control Register */
  27. /* SYS Boot Address Register */
  28. #define SBAR_BAREN BIT(4) /* SBAR is valid */
  29. /* Reset Control Registers */
  30. #define CA15RESCNT_CODE 0xa5a50000
  31. #define CA15RESCNT_CPUS 0xf /* CPU0-3 */
  32. #define CA7RESCNT_CODE 0x5a5a0000
  33. #define CA7RESCNT_CPUS 0xf /* CPU0-3 */
  34. /* On-chip RAM */
  35. #define ICRAM1 0xe63c0000 /* Inter Connect RAM1 (4 KiB) */
  36. static inline u32 phys_to_sbar(phys_addr_t addr)
  37. {
  38. return (addr >> 8) & 0xfffffc00;
  39. }
  40. void __init rcar_gen2_pm_init(void)
  41. {
  42. void __iomem *p;
  43. u32 bar;
  44. static int once;
  45. struct device_node *np, *cpus;
  46. bool has_a7 = false;
  47. bool has_a15 = false;
  48. struct resource res;
  49. int error;
  50. if (once++)
  51. return;
  52. cpus = of_find_node_by_path("/cpus");
  53. if (!cpus)
  54. return;
  55. for_each_child_of_node(cpus, np) {
  56. if (of_device_is_compatible(np, "arm,cortex-a15"))
  57. has_a15 = true;
  58. else if (of_device_is_compatible(np, "arm,cortex-a7"))
  59. has_a7 = true;
  60. }
  61. np = of_find_compatible_node(NULL, NULL, "renesas,smp-sram");
  62. if (!np) {
  63. /* No smp-sram in DT, fall back to hardcoded address */
  64. res = (struct resource)DEFINE_RES_MEM(ICRAM1,
  65. shmobile_boot_size);
  66. goto map;
  67. }
  68. error = of_address_to_resource(np, 0, &res);
  69. if (error) {
  70. pr_err("Failed to get smp-sram address: %d\n", error);
  71. return;
  72. }
  73. map:
  74. /* RAM for jump stub, because BAR requires 256KB aligned address */
  75. if (res.start & (256 * 1024 - 1) ||
  76. resource_size(&res) < shmobile_boot_size) {
  77. pr_err("Invalid smp-sram region\n");
  78. return;
  79. }
  80. p = ioremap(res.start, resource_size(&res));
  81. if (!p)
  82. return;
  83. /*
  84. * install the reset vector, use the largest version if we have enough
  85. * memory available
  86. */
  87. if (resource_size(&res) >= shmobile_boot_size_gen2) {
  88. shmobile_boot_cpu_gen2 = read_cpuid_mpidr();
  89. memcpy_toio(p, shmobile_boot_vector_gen2,
  90. shmobile_boot_size_gen2);
  91. } else {
  92. memcpy_toio(p, shmobile_boot_vector, shmobile_boot_size);
  93. }
  94. iounmap(p);
  95. /* setup reset vectors */
  96. p = ioremap_nocache(RST, 0x63);
  97. bar = phys_to_sbar(res.start);
  98. if (has_a15) {
  99. writel_relaxed(bar, p + CA15BAR);
  100. writel_relaxed(bar | SBAR_BAREN, p + CA15BAR);
  101. /* de-assert reset for CA15 CPUs */
  102. writel_relaxed((readl_relaxed(p + CA15RESCNT) &
  103. ~CA15RESCNT_CPUS) | CA15RESCNT_CODE,
  104. p + CA15RESCNT);
  105. }
  106. if (has_a7) {
  107. writel_relaxed(bar, p + CA7BAR);
  108. writel_relaxed(bar | SBAR_BAREN, p + CA7BAR);
  109. /* de-assert reset for CA7 CPUs */
  110. writel_relaxed((readl_relaxed(p + CA7RESCNT) &
  111. ~CA7RESCNT_CPUS) | CA7RESCNT_CODE,
  112. p + CA7RESCNT);
  113. }
  114. iounmap(p);
  115. shmobile_smp_apmu_suspend_init();
  116. }