omap4-common.c 5.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231
  1. /*
  2. * OMAP4 specific common source file.
  3. *
  4. * Copyright (C) 2010 Texas Instruments, Inc.
  5. * Author:
  6. * Santosh Shilimkar <santosh.shilimkar@ti.com>
  7. *
  8. *
  9. * This program is free software,you can redistribute it and/or modify
  10. * it under the terms of the GNU General Public License version 2 as
  11. * published by the Free Software Foundation.
  12. */
  13. #include <linux/kernel.h>
  14. #include <linux/init.h>
  15. #include <linux/io.h>
  16. #include <linux/irq.h>
  17. #include <linux/irqchip.h>
  18. #include <linux/platform_device.h>
  19. #include <linux/memblock.h>
  20. #include <linux/of_irq.h>
  21. #include <linux/of_platform.h>
  22. #include <linux/export.h>
  23. #include <linux/irqchip/arm-gic.h>
  24. #include <linux/of_address.h>
  25. #include <linux/reboot.h>
  26. #include <linux/genalloc.h>
  27. #include <asm/hardware/cache-l2x0.h>
  28. #include <asm/mach/map.h>
  29. #include <asm/memblock.h>
  30. #include <asm/smp_twd.h>
  31. #include "omap-wakeupgen.h"
  32. #include "soc.h"
  33. #include "iomap.h"
  34. #include "common.h"
  35. #include "prminst44xx.h"
  36. #include "prcm_mpu44xx.h"
  37. #include "omap4-sar-layout.h"
  38. #include "omap-secure.h"
  39. #include "sram.h"
  40. #ifdef CONFIG_CACHE_L2X0
  41. static void __iomem *l2cache_base;
  42. #endif
  43. static void __iomem *sar_ram_base;
  44. static void __iomem *gic_dist_base_addr;
  45. static void __iomem *twd_base;
  46. #define IRQ_LOCALTIMER 29
  47. void gic_dist_disable(void)
  48. {
  49. if (gic_dist_base_addr)
  50. writel_relaxed(0x0, gic_dist_base_addr + GIC_DIST_CTRL);
  51. }
  52. void gic_dist_enable(void)
  53. {
  54. if (gic_dist_base_addr)
  55. writel_relaxed(0x1, gic_dist_base_addr + GIC_DIST_CTRL);
  56. }
  57. bool gic_dist_disabled(void)
  58. {
  59. return !(readl_relaxed(gic_dist_base_addr + GIC_DIST_CTRL) & 0x1);
  60. }
  61. void gic_timer_retrigger(void)
  62. {
  63. u32 twd_int = readl_relaxed(twd_base + TWD_TIMER_INTSTAT);
  64. u32 gic_int = readl_relaxed(gic_dist_base_addr + GIC_DIST_PENDING_SET);
  65. u32 twd_ctrl = readl_relaxed(twd_base + TWD_TIMER_CONTROL);
  66. if (twd_int && !(gic_int & BIT(IRQ_LOCALTIMER))) {
  67. /*
  68. * The local timer interrupt got lost while the distributor was
  69. * disabled. Ack the pending interrupt, and retrigger it.
  70. */
  71. pr_warn("%s: lost localtimer interrupt\n", __func__);
  72. writel_relaxed(1, twd_base + TWD_TIMER_INTSTAT);
  73. if (!(twd_ctrl & TWD_TIMER_CONTROL_PERIODIC)) {
  74. writel_relaxed(1, twd_base + TWD_TIMER_COUNTER);
  75. twd_ctrl |= TWD_TIMER_CONTROL_ENABLE;
  76. writel_relaxed(twd_ctrl, twd_base + TWD_TIMER_CONTROL);
  77. }
  78. }
  79. }
  80. #ifdef CONFIG_CACHE_L2X0
  81. void __iomem *omap4_get_l2cache_base(void)
  82. {
  83. return l2cache_base;
  84. }
  85. void omap4_l2c310_write_sec(unsigned long val, unsigned reg)
  86. {
  87. unsigned smc_op;
  88. switch (reg) {
  89. case L2X0_CTRL:
  90. smc_op = OMAP4_MON_L2X0_CTRL_INDEX;
  91. break;
  92. case L2X0_AUX_CTRL:
  93. smc_op = OMAP4_MON_L2X0_AUXCTRL_INDEX;
  94. break;
  95. case L2X0_DEBUG_CTRL:
  96. smc_op = OMAP4_MON_L2X0_DBG_CTRL_INDEX;
  97. break;
  98. case L310_PREFETCH_CTRL:
  99. smc_op = OMAP4_MON_L2X0_PREFETCH_INDEX;
  100. break;
  101. case L310_POWER_CTRL:
  102. pr_info_once("OMAP L2C310: ROM does not support power control setting\n");
  103. return;
  104. default:
  105. WARN_ONCE(1, "OMAP L2C310: ignoring write to reg 0x%x\n", reg);
  106. return;
  107. }
  108. omap_smc1(smc_op, val);
  109. }
  110. int __init omap_l2_cache_init(void)
  111. {
  112. /* Static mapping, never released */
  113. l2cache_base = ioremap(OMAP44XX_L2CACHE_BASE, SZ_4K);
  114. if (WARN_ON(!l2cache_base))
  115. return -ENOMEM;
  116. return 0;
  117. }
  118. #endif
  119. void __iomem *omap4_get_sar_ram_base(void)
  120. {
  121. return sar_ram_base;
  122. }
  123. /*
  124. * SAR RAM used to save and restore the HW
  125. * context in low power modes
  126. */
  127. static int __init omap4_sar_ram_init(void)
  128. {
  129. unsigned long sar_base;
  130. /*
  131. * To avoid code running on other OMAPs in
  132. * multi-omap builds
  133. */
  134. if (cpu_is_omap44xx())
  135. sar_base = OMAP44XX_SAR_RAM_BASE;
  136. else if (soc_is_omap54xx())
  137. sar_base = OMAP54XX_SAR_RAM_BASE;
  138. else
  139. return -ENOMEM;
  140. /* Static mapping, never released */
  141. sar_ram_base = ioremap(sar_base, SZ_16K);
  142. if (WARN_ON(!sar_ram_base))
  143. return -ENOMEM;
  144. return 0;
  145. }
  146. omap_early_initcall(omap4_sar_ram_init);
  147. static const struct of_device_id intc_match[] = {
  148. { .compatible = "ti,omap4-wugen-mpu", },
  149. { .compatible = "ti,omap5-wugen-mpu", },
  150. { },
  151. };
  152. static struct device_node *intc_node;
  153. unsigned int omap4_xlate_irq(unsigned int hwirq)
  154. {
  155. struct of_phandle_args irq_data;
  156. unsigned int irq;
  157. if (!intc_node)
  158. intc_node = of_find_matching_node(NULL, intc_match);
  159. if (WARN_ON(!intc_node))
  160. return hwirq;
  161. irq_data.np = intc_node;
  162. irq_data.args_count = 3;
  163. irq_data.args[0] = 0;
  164. irq_data.args[1] = hwirq - OMAP44XX_IRQ_GIC_START;
  165. irq_data.args[2] = IRQ_TYPE_LEVEL_HIGH;
  166. irq = irq_create_of_mapping(&irq_data);
  167. if (WARN_ON(!irq))
  168. irq = hwirq;
  169. return irq;
  170. }
  171. void __init omap_gic_of_init(void)
  172. {
  173. struct device_node *np;
  174. intc_node = of_find_matching_node(NULL, intc_match);
  175. if (WARN_ON(!intc_node)) {
  176. pr_err("No WUGEN found in DT, system will misbehave.\n");
  177. pr_err("UPDATE YOUR DEVICE TREE!\n");
  178. }
  179. /* Extract GIC distributor and TWD bases for OMAP4460 ROM Errata WA */
  180. if (!cpu_is_omap446x())
  181. goto skip_errata_init;
  182. np = of_find_compatible_node(NULL, NULL, "arm,cortex-a9-gic");
  183. gic_dist_base_addr = of_iomap(np, 0);
  184. WARN_ON(!gic_dist_base_addr);
  185. np = of_find_compatible_node(NULL, NULL, "arm,cortex-a9-twd-timer");
  186. twd_base = of_iomap(np, 0);
  187. WARN_ON(!twd_base);
  188. skip_errata_init:
  189. irqchip_init();
  190. }