blob: 83f90601df61c7358b3f9f54355ce7f97bc7ef31 [file] [log] [blame]
Unnati Gandhib3820bc2014-07-04 16:56:27 +05301/* Copyright (c) 2014, The Linux Foundation. All rights reserved.
2 *
3 * Redistribution and use in source and binary forms, with or without
4 * 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.
15 *
16 * THIS SOFTWARE IS PROVIDED "AS IS" AND ANY EXPRESS OR IMPLIED
17 * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
18 * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT
19 * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS
20 * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
21 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
22 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR
23 * BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
24 * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE
25 * OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN
26 * IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
27 */
28
29#include <debug.h>
30#include <reg.h>
31#include <platform/iomap.h>
32#include <qgic.h>
33#include <qtimer.h>
34#include <mmu.h>
35#include <arch/arm/mmu.h>
36#include <smem.h>
37
Unnati Gandhif4cb6622014-08-28 13:54:56 +053038#define MB (1024*1024)
39
40#define MSM_IOMAP_SIZE ((MSM_IOMAP_END - MSM_IOMAP_BASE)/MB)
41#define A7_SS_SIZE ((A7_SS_END - A7_SS_BASE)/MB)
42
43/* LK memory - cacheable, write through */
44#define LK_MEMORY (MMU_MEMORY_TYPE_NORMAL_WRITE_THROUGH | \
45 MMU_MEMORY_AP_READ_WRITE)
46
47/* Peripherals - non-shared device */
48#define IOMAP_MEMORY (MMU_MEMORY_TYPE_DEVICE_SHARED | \
49 MMU_MEMORY_AP_READ_WRITE | MMU_MEMORY_XN)
50
51/* IMEM memory - cacheable, write through */
52#define IMEM_MEMORY (MMU_MEMORY_TYPE_NORMAL_WRITE_THROUGH | \
53 MMU_MEMORY_AP_READ_WRITE | MMU_MEMORY_XN)
54
55static mmu_section_t mmu_section_table[] = {
56/* Physical addr, Virtual addr, Size (in MB), Flags */
57 { MEMBASE, MEMBASE, (MEMSIZE / MB), LK_MEMORY},
58 { MSM_IOMAP_BASE, MSM_IOMAP_BASE, MSM_IOMAP_SIZE, IOMAP_MEMORY},
59 { A7_SS_BASE, A7_SS_BASE, A7_SS_SIZE, IOMAP_MEMORY},
60 { SYSTEM_IMEM_BASE, SYSTEM_IMEM_BASE, 1, IMEM_MEMORY},
61};
62
63static struct smem_ram_ptable ram_ptable;
64
Unnati Gandhib3820bc2014-07-04 16:56:27 +053065void platform_early_init(void)
66{
Unnati Gandhia556a4d2014-08-12 10:42:21 +053067 board_init();
Unnati Gandhif4cb6622014-08-28 13:54:56 +053068 platform_clock_init();
Unnati Gandhib3820bc2014-07-04 16:56:27 +053069 qgic_init();
70 qtimer_init();
71}
72
73void platform_init(void)
74{
75 dprintf(INFO, "platform_init()\n");
76}
77
78void platform_uninit(void)
79{
80 qtimer_uninit();
Unnati Gandhic43a2802014-09-19 17:27:25 +053081 if (!platform_boot_dev_isemmc())
82 qpic_nand_uninit();
Unnati Gandhib3820bc2014-07-04 16:56:27 +053083}
Unnati Gandhif4cb6622014-08-28 13:54:56 +053084
85uint32_t platform_get_sclk_count(void)
86{
87 return readl(MPM2_MPM_SLEEP_TIMETICK_COUNT_VAL);
88}
89
90addr_t get_bs_info_addr()
91{
92 return ((addr_t)BS_INFO_ADDR);
93}
94
95int platform_use_identity_mmu_mappings(void)
96{
97 /* Use only the mappings specified in this file. */
98 return 0;
99}
100
101/* Setup memory for this platform */
102void platform_init_mmu_mappings(void)
103{
104 uint32_t i;
105 uint32_t sections;
106 uint32_t table_size = ARRAY_SIZE(mmu_section_table);
107 ram_partition ptn_entry;
108 uint32_t len = 0;
109
110 ASSERT(smem_ram_ptable_init_v1());
111
112 len = smem_get_ram_ptable_len();
113
114 /* Configure the MMU page entries for SDRAM and IMEM memory read
115 from the smem ram table*/
116 for(i = 0; i < len; i++)
117 {
118 smem_get_ram_ptable_entry(&ptn_entry, i);
119 if(ptn_entry.type == SYS_MEMORY)
120 {
121 if((ptn_entry.category == SDRAM) ||
122 (ptn_entry.category == IMEM))
123 {
124 /* Check to ensure that start address is 1MB aligned */
125 ASSERT((ptn_entry.start & (MB-1)) == 0);
126
127 sections = (ptn_entry.size) / MB;
128 while(sections--)
129 {
130 arm_mmu_map_section(ptn_entry.start +
131 sections * MB,
132 ptn_entry.start +
133 sections * MB,
134 (MMU_MEMORY_TYPE_NORMAL_WRITE_THROUGH | \
135 MMU_MEMORY_AP_READ_WRITE | MMU_MEMORY_XN));
136 }
137 }
138 }
139 }
140
141 /* Configure the MMU page entries for memory read from the
142 mmu_section_table */
143 for (i = 0; i < table_size; i++)
144 {
145 sections = mmu_section_table[i].num_of_sections;
146
147 while (sections--)
148 {
149 arm_mmu_map_section(mmu_section_table[i].paddress +
150 sections * MB,
151 mmu_section_table[i].vaddress +
152 sections * MB,
153 mmu_section_table[i].flags);
154 }
155 }
156}
157
158addr_t platform_get_virt_to_phys_mapping(addr_t virt_addr)
159{
160 /* Using 1-1 mapping on this platform. */
161 return virt_addr;
162}
163
164addr_t platform_get_phys_to_virt_mapping(addr_t phys_addr)
165{
166 /* Using 1-1 mapping on this platform. */
167 return phys_addr;
168}
169
170/* DYNAMIC SMEM REGION feature enables LK to dynamically
171 * read the SMEM addr info from TCSR_TZ_WONCE register.
172 * The first word read, if indicates a MAGIC number, then
173 * Dynamic SMEM is assumed to be enabled. Read the remaining
174 * SMEM info for SMEM Size and Phy_addr from the other bytes.
175 */
176uint32_t platform_get_smem_base_addr()
177{
178 struct smem_addr_info *smem_info = NULL;
179
180 smem_info = (struct smem_addr_info *)readl(TCSR_TZ_WONCE);
181 if(smem_info && (smem_info->identifier == SMEM_TARGET_INFO_IDENTIFIER))
182 return smem_info->phy_addr;
183 else
184 return MSM_SHARED_BASE;
185}
186
Unnati Gandhi6c92a4f2014-11-18 18:01:51 +0530187int platform_is_msm8909()
188{
189 uint32_t platform = board_platform_id();
190 uint32_t ret = 0;
191
192 switch(platform)
193 {
194 case MSM8909:
195 case MSM8209:
196 case MSM8208:
197 case APQ8009:
198 ret = 1;
199 break;
200 default:
201 ret = 0;
202 };
203
204 return ret;
205}
206
207int boot_device_mask(int val)
208{
209 return ((val & 0x0E) >> 1);
210}
Unnati Gandhi24885052014-11-27 16:57:49 +0530211
212uint32_t platform_detect_panel()
213{
214 uint32_t panel;
215
216 /* Bits 28:29 of this register are read to know
217 the panel config, and pick up DT accordingly.
218
219 00 -no limit, suport HD
220 01 - limit to 720P
221 10- limit to qHD
222 11- limit to fWVGA
223
224 */
225 panel = readl(SECURITY_CONTROL_CORE_FEATURE_CONFIG0);
226 panel = (panel & 0x30000000) >> 28;
227
228 return panel;
229}