pm-rcar-gen2.c 3.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124
  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/of.h>
  14. #include <linux/smp.h>
  15. #include <linux/soc/renesas/rcar-sysc.h>
  16. #include <asm/io.h>
  17. #include "common.h"
  18. #include "rcar-gen2.h"
  19. /* RST */
  20. #define RST 0xe6160000
  21. #define CA15BAR 0x0020 /* CA15 Boot Address Register */
  22. #define CA7BAR 0x0030 /* CA7 Boot Address Register */
  23. #define CA15RESCNT 0x0040 /* CA15 Reset Control Register */
  24. #define CA7RESCNT 0x0044 /* CA7 Reset Control Register */
  25. /* SYS Boot Address Register */
  26. #define SBAR_BAREN BIT(4) /* SBAR is valid */
  27. /* Reset Control Registers */
  28. #define CA15RESCNT_CODE 0xa5a50000
  29. #define CA15RESCNT_CPUS 0xf /* CPU0-3 */
  30. #define CA7RESCNT_CODE 0x5a5a0000
  31. #define CA7RESCNT_CPUS 0xf /* CPU0-3 */
  32. /* On-chip RAM */
  33. #define ICRAM1 0xe63c0000 /* Inter Connect RAM1 (4 KiB) */
  34. static inline u32 phys_to_sbar(phys_addr_t addr)
  35. {
  36. return (addr >> 8) & 0xfffffc00;
  37. }
  38. /* SYSC */
  39. #define SYSCIER 0x0c
  40. #define SYSCIMR 0x10
  41. #if defined(CONFIG_SMP)
  42. static void __init rcar_gen2_sysc_init(u32 syscier)
  43. {
  44. rcar_sysc_init(0xe6180000, syscier);
  45. }
  46. #else /* CONFIG_SMP */
  47. static inline void rcar_gen2_sysc_init(u32 syscier) {}
  48. #endif /* CONFIG_SMP */
  49. void __init rcar_gen2_pm_init(void)
  50. {
  51. void __iomem *p;
  52. u32 bar;
  53. static int once;
  54. struct device_node *np, *cpus;
  55. bool has_a7 = false;
  56. bool has_a15 = false;
  57. phys_addr_t boot_vector_addr = ICRAM1;
  58. u32 syscier = 0;
  59. if (once++)
  60. return;
  61. cpus = of_find_node_by_path("/cpus");
  62. if (!cpus)
  63. return;
  64. for_each_child_of_node(cpus, np) {
  65. if (of_device_is_compatible(np, "arm,cortex-a15"))
  66. has_a15 = true;
  67. else if (of_device_is_compatible(np, "arm,cortex-a7"))
  68. has_a7 = true;
  69. }
  70. if (of_machine_is_compatible("renesas,r8a7790"))
  71. syscier = 0x013111ef;
  72. else if (of_machine_is_compatible("renesas,r8a7791"))
  73. syscier = 0x00111003;
  74. /* RAM for jump stub, because BAR requires 256KB aligned address */
  75. p = ioremap_nocache(boot_vector_addr, shmobile_boot_size);
  76. memcpy_toio(p, shmobile_boot_vector, shmobile_boot_size);
  77. iounmap(p);
  78. /* setup reset vectors */
  79. p = ioremap_nocache(RST, 0x63);
  80. bar = phys_to_sbar(boot_vector_addr);
  81. if (has_a15) {
  82. writel_relaxed(bar, p + CA15BAR);
  83. writel_relaxed(bar | SBAR_BAREN, p + CA15BAR);
  84. /* de-assert reset for CA15 CPUs */
  85. writel_relaxed((readl_relaxed(p + CA15RESCNT) &
  86. ~CA15RESCNT_CPUS) | CA15RESCNT_CODE,
  87. p + CA15RESCNT);
  88. }
  89. if (has_a7) {
  90. writel_relaxed(bar, p + CA7BAR);
  91. writel_relaxed(bar | SBAR_BAREN, p + CA7BAR);
  92. /* de-assert reset for CA7 CPUs */
  93. writel_relaxed((readl_relaxed(p + CA7RESCNT) &
  94. ~CA7RESCNT_CPUS) | CA7RESCNT_CODE,
  95. p + CA7RESCNT);
  96. }
  97. iounmap(p);
  98. rcar_gen2_sysc_init(syscier);
  99. shmobile_smp_apmu_suspend_init();
  100. }