blob: 5a7e1d4e1afb59cded814ef28bf7e080cd89afb5 [file] [log] [blame]
Amol Jadid3d7cdc2013-01-16 17:02:01 -08001/* Copyright (c) 2012-2013, The Linux Foundation. All rights reserved.
Deepa Dinamani7d6c8972011-12-14 15:16:56 -08002 *
3 * Redistribution and use in source and binary forms, with or without
Deepa Dinamani17338312012-10-18 11:29:54 -07004 * modification, are permitted provided that the following conditions are
5 * met:
6 * * Redistributions of source code must retain the above copyright
7 * notice, this list of conditions and the following disclaimer.
8 * * Redistributions in binary form must reproduce the above
9 * copyright notice, this list of conditions and the following
10 * disclaimer in the documentation and/or other materials provided
11 * with the distribution.
12 * * Neither the name of The Linux Foundation nor the names of its
13 * contributors may be used to endorse or promote products derived
14 * from this software without specific prior written permission.
Deepa Dinamani7d6c8972011-12-14 15:16:56 -080015 *
Deepa Dinamani17338312012-10-18 11:29:54 -070016 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
17 * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
18 * IMPLIED WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
19 * NON-INFRINGEMENT ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
20 * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
21 * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
22 * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;
23 * OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
24 * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
25 * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
26 * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
Deepa Dinamani7d6c8972011-12-14 15:16:56 -080027 */
28
29#include <debug.h>
30#include <reg.h>
31#include <platform/iomap.h>
32#include <qgic.h>
Deepa Dinamani81eddd52012-05-31 11:18:50 -070033#include <qtimer.h>
Amol Jadi29f95032012-06-22 12:52:54 -070034#include <platform/clock.h>
Neeti Desai13e688d2012-08-22 16:30:55 -070035#include <mmu.h>
36#include <arch/arm/mmu.h>
37#include <smem.h>
Amol Jadibaee4742013-03-18 15:35:05 -070038#include <board.h>
39#include <boot_stats.h>
Deepa Dinamani7d6c8972011-12-14 15:16:56 -080040
Neeti Desai13e688d2012-08-22 16:30:55 -070041#define MB (1024*1024)
42
43#define MSM_IOMAP_SIZE ((MSM_IOMAP_END - MSM_IOMAP_BASE)/MB)
44
45/* LK memory - cacheable, write through */
46#define LK_MEMORY (MMU_MEMORY_TYPE_NORMAL_WRITE_THROUGH | \
47 MMU_MEMORY_AP_READ_WRITE)
48
49/* Peripherals - non-shared device */
50#define IOMAP_MEMORY (MMU_MEMORY_TYPE_DEVICE_SHARED | \
51 MMU_MEMORY_AP_READ_WRITE | MMU_MEMORY_XN)
52
Deepa Dinamani0da68842013-03-25 17:11:56 -070053/* IMEM memory - cacheable, write through */
54#define IMEM_MEMORY (MMU_MEMORY_TYPE_NORMAL_WRITE_THROUGH | \
55 MMU_MEMORY_AP_READ_WRITE | MMU_MEMORY_XN)
56
Deepa Dinamani17338312012-10-18 11:29:54 -070057static mmu_section_t mmu_section_table[] = {
Deepa Dinamani0da68842013-03-25 17:11:56 -070058/* Physical addr, Virtual addr, Size (in MB), Flags */
59 {MEMBASE, MEMBASE, (MEMSIZE / MB), LK_MEMORY},
60 {MSM_IOMAP_BASE, MSM_IOMAP_BASE, MSM_IOMAP_SIZE, IOMAP_MEMORY},
61 /* IMEM needs a seperate entry in the table as it's length is only 0x8000. */
62 {SYSTEM_IMEM_BASE, SYSTEM_IMEM_BASE, 1, IMEM_MEMORY},
Neeti Desai13e688d2012-08-22 16:30:55 -070063};
Deepa Dinamani7d6c8972011-12-14 15:16:56 -080064
Deepa Dinamani17338312012-10-18 11:29:54 -070065static struct smem_ram_ptable ram_ptable;
66
Amol Jadibaee4742013-03-18 15:35:05 -070067/* Boot timestamps */
68#define BS_INFO_OFFSET (0x6B0)
69#define BS_INFO_ADDR_V1 (RPM_MSG_RAM_BASE + BS_INFO_OFFSET)
70#define BS_INFO_ADDR_V2 (MSM_SHARED_IMEM_BASE + BS_INFO_OFFSET)
71
Channagoud Kadabia178a502013-09-26 10:59:47 -070072/* Check for 8962 chip */
73int platform_is_8x62()
74{
75 uint32_t platform = board_platform_id();
76 int ret = 0;
77
78 switch(platform)
79 {
80 case APQ8062:
81 case MSM8262:
82 case MSM8962:
83 ret = 1;
84 break;
85 default:
86 ret = 0;
87 };
88
89 return ret;
90}
91
Deepa Dinamani7d6c8972011-12-14 15:16:56 -080092void platform_early_init(void)
93{
Neeti Desai465491e2012-07-31 12:53:35 -070094 board_init();
Amol Jadi29f95032012-06-22 12:52:54 -070095 platform_clock_init();
Deepa Dinamani7d6c8972011-12-14 15:16:56 -080096 qgic_init();
Deepa Dinamani81eddd52012-05-31 11:18:50 -070097 qtimer_init();
Deepa Dinamani7d6c8972011-12-14 15:16:56 -080098}
99
100void platform_init(void)
101{
102 dprintf(INFO, "platform_init()\n");
103}
104
sundarajan srinivasancd7d3272013-05-10 14:26:59 -0700105uint32_t platform_get_sclk_count(void)
Joel King46d2a452013-02-13 18:35:21 -0800106{
Amol Jadibaee4742013-03-18 15:35:05 -0700107 return readl(MPM2_MPM_SLEEP_TIMETICK_COUNT_VAL);
108}
Joel King46d2a452013-02-13 18:35:21 -0800109
Channagoud Kadabi0de103c2013-09-26 10:44:57 -0700110/* Check for 8974 chip */
111int platform_is_8974()
112{
113 uint32_t platform = board_platform_id();
114 int ret = 0;
115
116 switch(platform)
117 {
118 case APQ8074:
119 case MSM8274:
120 case MSM8674:
121 case MSM8974:
122 ret = 1;
123 break;
124 default:
125 ret = 0;
126 };
127
128 return ret;
129}
130
Amol Jadifbcd3ba2013-10-16 13:05:11 -0700131/* Check for 8974 PRO chip */
132int platform_is_8974Pro()
133{
134 uint32_t platform = board_platform_id();
135 int ret = 0;
136
137 switch(platform)
138 {
139 case APQ8074AA:
140 case APQ8074AB:
141 case APQ8074AC:
142
143 case MSM8274AA:
144 case MSM8274AB:
145 case MSM8274AC:
146
147 case MSM8674AA:
148 case MSM8674AB:
149 case MSM8674AC:
150
151 case MSM8974AA:
152 case MSM8974AB:
153 case MSM8974AC:
154
155 ret = 1;
156 break;
157 default:
158 ret = 0;
159 };
160
161 return ret;
162}
163
sundarajan srinivasancd7d3272013-05-10 14:26:59 -0700164addr_t get_bs_info_addr()
Amol Jadibaee4742013-03-18 15:35:05 -0700165{
Amol Jadibaee4742013-03-18 15:35:05 -0700166 uint32_t soc_ver = board_soc_version();
Joel King46d2a452013-02-13 18:35:21 -0800167
Channagoud Kadabi0de103c2013-09-26 10:44:57 -0700168 if (platform_is_8974() && (soc_ver < BOARD_SOC_VERSION2))
sundarajan srinivasancd7d3272013-05-10 14:26:59 -0700169 return ((addr_t)BS_INFO_ADDR_V1);
Amol Jadibaee4742013-03-18 15:35:05 -0700170 else
sundarajan srinivasancd7d3272013-05-10 14:26:59 -0700171 return ((addr_t)BS_INFO_ADDR_V2);
Amol Jadibaee4742013-03-18 15:35:05 -0700172
Joel King46d2a452013-02-13 18:35:21 -0800173}
174
Deepa Dinamani7d6c8972011-12-14 15:16:56 -0800175void platform_uninit(void)
176{
Siddhartha Agrawal7ac6d512013-01-22 18:39:50 -0800177#if DISPLAY_SPLASH_SCREEN
178 display_shutdown();
179#endif
180
Deepa Dinamani81eddd52012-05-31 11:18:50 -0700181 qtimer_uninit();
Deepa Dinamani7d6c8972011-12-14 15:16:56 -0800182}
Neeti Desai13e688d2012-08-22 16:30:55 -0700183
Deepa Dinamani0da68842013-03-25 17:11:56 -0700184int platform_use_identity_mmu_mappings(void)
185{
186 /* Use only the mappings specified in this file. */
187 return 0;
188}
189
190addr_t platform_get_virt_to_phys_mapping(addr_t virt_addr)
191{
192 /* Return same address as we are using 1-1 mapping. */
193 return virt_addr;
194}
195
196addr_t platform_get_phys_to_virt_mapping(addr_t phys_addr)
197{
198 /* Return same address as we are using 1-1 mapping. */
199 return phys_addr;
200}
201
202
Neeti Desai13e688d2012-08-22 16:30:55 -0700203/* Setup memory for this platform */
204void platform_init_mmu_mappings(void)
205{
Neeti Desai13e688d2012-08-22 16:30:55 -0700206 uint32_t i;
207 uint32_t sections;
208 uint32_t table_size = ARRAY_SIZE(mmu_section_table);
209
210 ASSERT(smem_ram_ptable_init(&ram_ptable));
211
212 /* Configure the MMU page entries for SDRAM and IMEM memory read
213 from the smem ram table*/
214 for(i = 0; i < ram_ptable.len; i++)
Amol Jadid3d7cdc2013-01-16 17:02:01 -0800215 {
216 if(ram_ptable.parts[i].type == SYS_MEMORY)
Neeti Desai13e688d2012-08-22 16:30:55 -0700217 {
Amol Jadid3d7cdc2013-01-16 17:02:01 -0800218 if((ram_ptable.parts[i].category == SDRAM) ||
219 (ram_ptable.parts[i].category == IMEM))
220 {
221 /* Check to ensure that start address is 1MB aligned */
222 ASSERT((ram_ptable.parts[i].start & 0xFFFFF) == 0);
Neeti Desai13e688d2012-08-22 16:30:55 -0700223
Amol Jadid3d7cdc2013-01-16 17:02:01 -0800224 sections = (ram_ptable.parts[i].size) / MB;
225 while(sections--) {
226 arm_mmu_map_section(ram_ptable.parts[i].start +
227 sections * MB,
228 ram_ptable.parts[i].start +
229 sections * MB,
230 (MMU_MEMORY_TYPE_NORMAL_WRITE_THROUGH | \
231 MMU_MEMORY_AP_READ_WRITE | MMU_MEMORY_XN));
232 }
Neeti Desai13e688d2012-08-22 16:30:55 -0700233 }
234 }
235 }
236 /* Configure the MMU page entries for memory read from the
237 mmu_section_table */
238 for (i = 0; i < table_size; i++) {
239 sections = mmu_section_table[i].num_of_sections;
240
241 while (sections--) {
242 arm_mmu_map_section(mmu_section_table[i].paddress +
243 sections * MB,
244 mmu_section_table[i].vaddress +
245 sections * MB,
246 mmu_section_table[i].flags);
247 }
248 }
249}