sram.c 3.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120
  1. /*
  2. * linux/arch/arm/plat-omap/sram.c
  3. *
  4. * OMAP SRAM detection and management
  5. *
  6. * Copyright (C) 2005 Nokia Corporation
  7. * Written by Tony Lindgren <tony@atomide.com>
  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/config.h>
  14. #include <linux/module.h>
  15. #include <linux/kernel.h>
  16. #include <linux/init.h>
  17. #include <asm/mach/map.h>
  18. #include <asm/io.h>
  19. #include <asm/cacheflush.h>
  20. #include "sram.h"
  21. #define OMAP1_SRAM_BASE 0xd0000000
  22. #define OMAP1_SRAM_START 0x20000000
  23. #define SRAM_BOOTLOADER_SZ 0x80
  24. static unsigned long omap_sram_base;
  25. static unsigned long omap_sram_size;
  26. static unsigned long omap_sram_ceil;
  27. /*
  28. * The amount of SRAM depends on the core type:
  29. * 730 = 200K, 1510 = 512K, 5912 = 256K, 1610 = 16K, 1710 = 16K
  30. * Note that we cannot try to test for SRAM here because writes
  31. * to secure SRAM will hang the system. Also the SRAM is not
  32. * yet mapped at this point.
  33. */
  34. void __init omap_detect_sram(void)
  35. {
  36. omap_sram_base = OMAP1_SRAM_BASE;
  37. if (cpu_is_omap730())
  38. omap_sram_size = 0x32000;
  39. else if (cpu_is_omap1510())
  40. omap_sram_size = 0x80000;
  41. else if (cpu_is_omap1610() || cpu_is_omap1621() || cpu_is_omap1710())
  42. omap_sram_size = 0x4000;
  43. else if (cpu_is_omap1611())
  44. omap_sram_size = 0x3e800;
  45. else {
  46. printk(KERN_ERR "Could not detect SRAM size\n");
  47. omap_sram_size = 0x4000;
  48. }
  49. printk(KERN_INFO "SRAM size: 0x%lx\n", omap_sram_size);
  50. omap_sram_ceil = omap_sram_base + omap_sram_size;
  51. }
  52. static struct map_desc omap_sram_io_desc[] __initdata = {
  53. { /* .length gets filled in at runtime */
  54. .virtual = OMAP1_SRAM_BASE,
  55. .pfn = __phys_to_pfn(OMAP1_SRAM_START),
  56. .type = MT_DEVICE
  57. }
  58. };
  59. /*
  60. * In order to use last 2kB of SRAM on 1611b, we must round the size
  61. * up to multiple of PAGE_SIZE. We cannot use ioremap for SRAM, as
  62. * clock init needs SRAM early.
  63. */
  64. void __init omap_map_sram(void)
  65. {
  66. if (omap_sram_size == 0)
  67. return;
  68. omap_sram_io_desc[0].length = (omap_sram_size + PAGE_SIZE-1)/PAGE_SIZE;
  69. omap_sram_io_desc[0].length *= PAGE_SIZE;
  70. iotable_init(omap_sram_io_desc, ARRAY_SIZE(omap_sram_io_desc));
  71. /*
  72. * Looks like we need to preserve some bootloader code at the
  73. * beginning of SRAM for jumping to flash for reboot to work...
  74. */
  75. memset((void *)omap_sram_base + SRAM_BOOTLOADER_SZ, 0,
  76. omap_sram_size - SRAM_BOOTLOADER_SZ);
  77. }
  78. static void (*_omap_sram_reprogram_clock)(u32 dpllctl, u32 ckctl) = NULL;
  79. void omap_sram_reprogram_clock(u32 dpllctl, u32 ckctl)
  80. {
  81. if (_omap_sram_reprogram_clock == NULL)
  82. panic("Cannot use SRAM");
  83. return _omap_sram_reprogram_clock(dpllctl, ckctl);
  84. }
  85. void * omap_sram_push(void * start, unsigned long size)
  86. {
  87. if (size > (omap_sram_ceil - (omap_sram_base + SRAM_BOOTLOADER_SZ))) {
  88. printk(KERN_ERR "Not enough space in SRAM\n");
  89. return NULL;
  90. }
  91. omap_sram_ceil -= size;
  92. omap_sram_ceil &= ~0x3;
  93. memcpy((void *)omap_sram_ceil, start, size);
  94. return (void *)omap_sram_ceil;
  95. }
  96. void __init omap_sram_init(void)
  97. {
  98. omap_detect_sram();
  99. omap_map_sram();
  100. _omap_sram_reprogram_clock = omap_sram_push(sram_reprogram_clock,
  101. sram_reprogram_clock_sz);
  102. }