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