blob: 77eb5e76fc05db05033da2c7d15b1bca9bddafe8 [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 {
Channagoud Kadabibdac7092013-08-20 15:28:07 -0700139 case MSM8974AC:
140 case MSM8674AC:
141 case MSM8274AC:
142 case APQ8074AC:
143 ret = 1;
144 break;
145 default:
146 ret = 0;
147 };
148
149 return ret;
150}
151
152/* Check for 8974PRO AC chip */
153int platform_is_8974ac()
154{
155 uint32_t platform = board_platform_id();
156 int ret = 0;
157
158 switch(platform)
159 {
Amol Jadifbcd3ba2013-10-16 13:05:11 -0700160 case APQ8074AA:
161 case APQ8074AB:
162 case APQ8074AC:
163
164 case MSM8274AA:
165 case MSM8274AB:
166 case MSM8274AC:
167
168 case MSM8674AA:
169 case MSM8674AB:
170 case MSM8674AC:
171
172 case MSM8974AA:
173 case MSM8974AB:
174 case MSM8974AC:
175
176 ret = 1;
177 break;
178 default:
179 ret = 0;
180 };
181
182 return ret;
183}
184
sundarajan srinivasancd7d3272013-05-10 14:26:59 -0700185addr_t get_bs_info_addr()
Amol Jadibaee4742013-03-18 15:35:05 -0700186{
Amol Jadibaee4742013-03-18 15:35:05 -0700187 uint32_t soc_ver = board_soc_version();
Joel King46d2a452013-02-13 18:35:21 -0800188
Channagoud Kadabi0de103c2013-09-26 10:44:57 -0700189 if (platform_is_8974() && (soc_ver < BOARD_SOC_VERSION2))
sundarajan srinivasancd7d3272013-05-10 14:26:59 -0700190 return ((addr_t)BS_INFO_ADDR_V1);
Amol Jadibaee4742013-03-18 15:35:05 -0700191 else
sundarajan srinivasancd7d3272013-05-10 14:26:59 -0700192 return ((addr_t)BS_INFO_ADDR_V2);
Amol Jadibaee4742013-03-18 15:35:05 -0700193
Joel King46d2a452013-02-13 18:35:21 -0800194}
195
Deepa Dinamani7d6c8972011-12-14 15:16:56 -0800196void platform_uninit(void)
197{
Siddhartha Agrawal7ac6d512013-01-22 18:39:50 -0800198#if DISPLAY_SPLASH_SCREEN
199 display_shutdown();
200#endif
201
Deepa Dinamani81eddd52012-05-31 11:18:50 -0700202 qtimer_uninit();
Deepa Dinamani7d6c8972011-12-14 15:16:56 -0800203}
Neeti Desai13e688d2012-08-22 16:30:55 -0700204
Deepa Dinamani0da68842013-03-25 17:11:56 -0700205int platform_use_identity_mmu_mappings(void)
206{
207 /* Use only the mappings specified in this file. */
208 return 0;
209}
210
211addr_t platform_get_virt_to_phys_mapping(addr_t virt_addr)
212{
213 /* Return same address as we are using 1-1 mapping. */
214 return virt_addr;
215}
216
217addr_t platform_get_phys_to_virt_mapping(addr_t phys_addr)
218{
219 /* Return same address as we are using 1-1 mapping. */
220 return phys_addr;
221}
222
223
Neeti Desai13e688d2012-08-22 16:30:55 -0700224/* Setup memory for this platform */
225void platform_init_mmu_mappings(void)
226{
Neeti Desai13e688d2012-08-22 16:30:55 -0700227 uint32_t i;
228 uint32_t sections;
229 uint32_t table_size = ARRAY_SIZE(mmu_section_table);
230
231 ASSERT(smem_ram_ptable_init(&ram_ptable));
232
233 /* Configure the MMU page entries for SDRAM and IMEM memory read
234 from the smem ram table*/
235 for(i = 0; i < ram_ptable.len; i++)
Amol Jadid3d7cdc2013-01-16 17:02:01 -0800236 {
237 if(ram_ptable.parts[i].type == SYS_MEMORY)
Neeti Desai13e688d2012-08-22 16:30:55 -0700238 {
Amol Jadid3d7cdc2013-01-16 17:02:01 -0800239 if((ram_ptable.parts[i].category == SDRAM) ||
240 (ram_ptable.parts[i].category == IMEM))
241 {
242 /* Check to ensure that start address is 1MB aligned */
243 ASSERT((ram_ptable.parts[i].start & 0xFFFFF) == 0);
Neeti Desai13e688d2012-08-22 16:30:55 -0700244
Amol Jadid3d7cdc2013-01-16 17:02:01 -0800245 sections = (ram_ptable.parts[i].size) / MB;
246 while(sections--) {
247 arm_mmu_map_section(ram_ptable.parts[i].start +
248 sections * MB,
249 ram_ptable.parts[i].start +
250 sections * MB,
251 (MMU_MEMORY_TYPE_NORMAL_WRITE_THROUGH | \
252 MMU_MEMORY_AP_READ_WRITE | MMU_MEMORY_XN));
253 }
Neeti Desai13e688d2012-08-22 16:30:55 -0700254 }
255 }
256 }
257 /* Configure the MMU page entries for memory read from the
258 mmu_section_table */
259 for (i = 0; i < table_size; i++) {
260 sections = mmu_section_table[i].num_of_sections;
261
262 while (sections--) {
263 arm_mmu_map_section(mmu_section_table[i].paddress +
264 sections * MB,
265 mmu_section_table[i].vaddress +
266 sections * MB,
267 mmu_section_table[i].flags);
268 }
269 }
270}