blob: 6536055803c26e14be88159ca7db98ad85c2ed7f [file] [log] [blame]
Channagoud Kadabia7ab9312014-01-08 12:11:23 -08001/* Copyright (c) 2012-2014, 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
Deepa Dinamani7d6c8972011-12-14 15:16:56 -080072void platform_early_init(void)
73{
Neeti Desai465491e2012-07-31 12:53:35 -070074 board_init();
Amol Jadi29f95032012-06-22 12:52:54 -070075 platform_clock_init();
Deepa Dinamani7d6c8972011-12-14 15:16:56 -080076 qgic_init();
Deepa Dinamani81eddd52012-05-31 11:18:50 -070077 qtimer_init();
Deepa Dinamani7d6c8972011-12-14 15:16:56 -080078}
79
80void platform_init(void)
81{
82 dprintf(INFO, "platform_init()\n");
83}
84
sundarajan srinivasancd7d3272013-05-10 14:26:59 -070085uint32_t platform_get_sclk_count(void)
Joel King46d2a452013-02-13 18:35:21 -080086{
Amol Jadibaee4742013-03-18 15:35:05 -070087 return readl(MPM2_MPM_SLEEP_TIMETICK_COUNT_VAL);
88}
Joel King46d2a452013-02-13 18:35:21 -080089
Channagoud Kadabi0de103c2013-09-26 10:44:57 -070090/* Check for 8974 chip */
91int platform_is_8974()
92{
93 uint32_t platform = board_platform_id();
94 int ret = 0;
95
96 switch(platform)
97 {
98 case APQ8074:
99 case MSM8274:
100 case MSM8674:
101 case MSM8974:
102 ret = 1;
103 break;
104 default:
105 ret = 0;
106 };
107
108 return ret;
109}
110
Amol Jadifbcd3ba2013-10-16 13:05:11 -0700111/* Check for 8974 PRO chip */
112int platform_is_8974Pro()
113{
114 uint32_t platform = board_platform_id();
115 int ret = 0;
116
117 switch(platform)
118 {
Channagoud Kadabibdac7092013-08-20 15:28:07 -0700119 case MSM8974AC:
120 case MSM8674AC:
121 case MSM8274AC:
122 case APQ8074AC:
123 ret = 1;
124 break;
125 default:
126 ret = 0;
127 };
128
129 return ret;
130}
131
132/* Check for 8974PRO AC chip */
133int platform_is_8974ac()
134{
135 uint32_t platform = board_platform_id();
136 int ret = 0;
137
138 switch(platform)
139 {
Amol Jadifbcd3ba2013-10-16 13:05:11 -0700140 case APQ8074AA:
141 case APQ8074AB:
142 case APQ8074AC:
143
144 case MSM8274AA:
145 case MSM8274AB:
146 case MSM8274AC:
147
148 case MSM8674AA:
149 case MSM8674AB:
150 case MSM8674AC:
151
152 case MSM8974AA:
153 case MSM8974AB:
154 case MSM8974AC:
155
156 ret = 1;
157 break;
158 default:
159 ret = 0;
160 };
161
162 return ret;
163}
164
sundarajan srinivasancd7d3272013-05-10 14:26:59 -0700165addr_t get_bs_info_addr()
Amol Jadibaee4742013-03-18 15:35:05 -0700166{
Amol Jadibaee4742013-03-18 15:35:05 -0700167 uint32_t soc_ver = board_soc_version();
Joel King46d2a452013-02-13 18:35:21 -0800168
Channagoud Kadabi0de103c2013-09-26 10:44:57 -0700169 if (platform_is_8974() && (soc_ver < BOARD_SOC_VERSION2))
sundarajan srinivasancd7d3272013-05-10 14:26:59 -0700170 return ((addr_t)BS_INFO_ADDR_V1);
Amol Jadibaee4742013-03-18 15:35:05 -0700171 else
sundarajan srinivasancd7d3272013-05-10 14:26:59 -0700172 return ((addr_t)BS_INFO_ADDR_V2);
Amol Jadibaee4742013-03-18 15:35:05 -0700173
Joel King46d2a452013-02-13 18:35:21 -0800174}
175
Deepa Dinamani7d6c8972011-12-14 15:16:56 -0800176void platform_uninit(void)
177{
Siddhartha Agrawal7ac6d512013-01-22 18:39:50 -0800178#if DISPLAY_SPLASH_SCREEN
179 display_shutdown();
180#endif
181
Deepa Dinamani81eddd52012-05-31 11:18:50 -0700182 qtimer_uninit();
Deepa Dinamani7d6c8972011-12-14 15:16:56 -0800183}
Neeti Desai13e688d2012-08-22 16:30:55 -0700184
Deepa Dinamani0da68842013-03-25 17:11:56 -0700185int platform_use_identity_mmu_mappings(void)
186{
187 /* Use only the mappings specified in this file. */
188 return 0;
189}
190
191addr_t platform_get_virt_to_phys_mapping(addr_t virt_addr)
192{
193 /* Return same address as we are using 1-1 mapping. */
194 return virt_addr;
195}
196
197addr_t platform_get_phys_to_virt_mapping(addr_t phys_addr)
198{
199 /* Return same address as we are using 1-1 mapping. */
200 return phys_addr;
201}
202
203
Neeti Desai13e688d2012-08-22 16:30:55 -0700204/* Setup memory for this platform */
205void platform_init_mmu_mappings(void)
206{
Neeti Desai13e688d2012-08-22 16:30:55 -0700207 uint32_t i;
208 uint32_t sections;
209 uint32_t table_size = ARRAY_SIZE(mmu_section_table);
210
211 ASSERT(smem_ram_ptable_init(&ram_ptable));
212
213 /* Configure the MMU page entries for SDRAM and IMEM memory read
214 from the smem ram table*/
215 for(i = 0; i < ram_ptable.len; i++)
Amol Jadid3d7cdc2013-01-16 17:02:01 -0800216 {
217 if(ram_ptable.parts[i].type == SYS_MEMORY)
Neeti Desai13e688d2012-08-22 16:30:55 -0700218 {
Amol Jadid3d7cdc2013-01-16 17:02:01 -0800219 if((ram_ptable.parts[i].category == SDRAM) ||
220 (ram_ptable.parts[i].category == IMEM))
221 {
222 /* Check to ensure that start address is 1MB aligned */
223 ASSERT((ram_ptable.parts[i].start & 0xFFFFF) == 0);
Neeti Desai13e688d2012-08-22 16:30:55 -0700224
Amol Jadid3d7cdc2013-01-16 17:02:01 -0800225 sections = (ram_ptable.parts[i].size) / MB;
226 while(sections--) {
227 arm_mmu_map_section(ram_ptable.parts[i].start +
228 sections * MB,
229 ram_ptable.parts[i].start +
230 sections * MB,
231 (MMU_MEMORY_TYPE_NORMAL_WRITE_THROUGH | \
232 MMU_MEMORY_AP_READ_WRITE | MMU_MEMORY_XN));
233 }
Neeti Desai13e688d2012-08-22 16:30:55 -0700234 }
235 }
236 }
237 /* Configure the MMU page entries for memory read from the
238 mmu_section_table */
239 for (i = 0; i < table_size; i++) {
240 sections = mmu_section_table[i].num_of_sections;
241
242 while (sections--) {
243 arm_mmu_map_section(mmu_section_table[i].paddress +
244 sections * MB,
245 mmu_section_table[i].vaddress +
246 sections * MB,
247 mmu_section_table[i].flags);
248 }
249 }
250}