blob: e59f69e69702f10f8962c22ba9cc7f8d235a9a52 [file] [log] [blame]
Unnati Gandhi917c8612015-02-06 16:50:32 +05301/* Copyright (c) 2014-2015, The Linux Foundation. All rights reserved.
Unnati Gandhib3820bc2014-07-04 16:56:27 +05302 *
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>
Unnati Gandhiabb73ec2015-06-23 13:07:36 +053037#include <target/display.h>
Unnati Gandhib3820bc2014-07-04 16:56:27 +053038
Unnati Gandhif4cb6622014-08-28 13:54:56 +053039#define MB (1024*1024)
40
41#define MSM_IOMAP_SIZE ((MSM_IOMAP_END - MSM_IOMAP_BASE)/MB)
42#define A7_SS_SIZE ((A7_SS_END - A7_SS_BASE)/MB)
43
Matthew Qinfab78c32015-04-28 03:05:24 -040044/* LK memory - cacheable, write back */
45#define LK_MEMORY (MMU_MEMORY_TYPE_NORMAL_WRITE_BACK_ALLOCATE | \
Unnati Gandhif4cb6622014-08-28 13:54:56 +053046 MMU_MEMORY_AP_READ_WRITE)
47
Matthew Qinfab78c32015-04-28 03:05:24 -040048
49#define COMMON_MEMORY (MMU_MEMORY_TYPE_NORMAL_WRITE_THROUGH | \
50 MMU_MEMORY_AP_READ_WRITE | MMU_MEMORY_XN)
51
Unnati Gandhif4cb6622014-08-28 13:54:56 +053052/* Peripherals - non-shared device */
53#define IOMAP_MEMORY (MMU_MEMORY_TYPE_DEVICE_SHARED | \
54 MMU_MEMORY_AP_READ_WRITE | MMU_MEMORY_XN)
55
56/* IMEM memory - cacheable, write through */
57#define IMEM_MEMORY (MMU_MEMORY_TYPE_NORMAL_WRITE_THROUGH | \
58 MMU_MEMORY_AP_READ_WRITE | MMU_MEMORY_XN)
59
60static mmu_section_t mmu_section_table[] = {
61/* Physical addr, Virtual addr, Size (in MB), Flags */
62 { MEMBASE, MEMBASE, (MEMSIZE / MB), LK_MEMORY},
63 { MSM_IOMAP_BASE, MSM_IOMAP_BASE, MSM_IOMAP_SIZE, IOMAP_MEMORY},
64 { A7_SS_BASE, A7_SS_BASE, A7_SS_SIZE, IOMAP_MEMORY},
65 { SYSTEM_IMEM_BASE, SYSTEM_IMEM_BASE, 1, IMEM_MEMORY},
Matthew Qinfab78c32015-04-28 03:05:24 -040066 { MSM_SHARED_BASE, MSM_SHARED_BASE, 1, COMMON_MEMORY},
Unnati Gandhiabb73ec2015-06-23 13:07:36 +053067 { MIPI_FB_ADDR, MIPI_FB_ADDR, 10, COMMON_MEMORY},
Unnati Gandhif4cb6622014-08-28 13:54:56 +053068};
69
70static struct smem_ram_ptable ram_ptable;
71
Unnati Gandhib3820bc2014-07-04 16:56:27 +053072void platform_early_init(void)
73{
Unnati Gandhia556a4d2014-08-12 10:42:21 +053074 board_init();
Unnati Gandhif4cb6622014-08-28 13:54:56 +053075 platform_clock_init();
Unnati Gandhib3820bc2014-07-04 16:56:27 +053076 qgic_init();
77 qtimer_init();
78}
79
80void platform_init(void)
81{
82 dprintf(INFO, "platform_init()\n");
83}
84
85void platform_uninit(void)
86{
87 qtimer_uninit();
Unnati Gandhic43a2802014-09-19 17:27:25 +053088 if (!platform_boot_dev_isemmc())
89 qpic_nand_uninit();
Unnati Gandhib3820bc2014-07-04 16:56:27 +053090}
Unnati Gandhif4cb6622014-08-28 13:54:56 +053091
92uint32_t platform_get_sclk_count(void)
93{
94 return readl(MPM2_MPM_SLEEP_TIMETICK_COUNT_VAL);
95}
96
97addr_t get_bs_info_addr()
98{
99 return ((addr_t)BS_INFO_ADDR);
100}
101
102int platform_use_identity_mmu_mappings(void)
103{
104 /* Use only the mappings specified in this file. */
105 return 0;
106}
107
108/* Setup memory for this platform */
109void platform_init_mmu_mappings(void)
110{
111 uint32_t i;
112 uint32_t sections;
113 uint32_t table_size = ARRAY_SIZE(mmu_section_table);
114 ram_partition ptn_entry;
115 uint32_t len = 0;
116
117 ASSERT(smem_ram_ptable_init_v1());
118
119 len = smem_get_ram_ptable_len();
120
121 /* Configure the MMU page entries for SDRAM and IMEM memory read
122 from the smem ram table*/
123 for(i = 0; i < len; i++)
124 {
125 smem_get_ram_ptable_entry(&ptn_entry, i);
126 if(ptn_entry.type == SYS_MEMORY)
127 {
128 if((ptn_entry.category == SDRAM) ||
129 (ptn_entry.category == IMEM))
130 {
131 /* Check to ensure that start address is 1MB aligned */
132 ASSERT((ptn_entry.start & (MB-1)) == 0);
133
134 sections = (ptn_entry.size) / MB;
135 while(sections--)
136 {
137 arm_mmu_map_section(ptn_entry.start +
138 sections * MB,
139 ptn_entry.start +
140 sections * MB,
Matthew Qinfab78c32015-04-28 03:05:24 -0400141 (MMU_MEMORY_TYPE_NORMAL_WRITE_BACK_ALLOCATE | \
Unnati Gandhif4cb6622014-08-28 13:54:56 +0530142 MMU_MEMORY_AP_READ_WRITE | MMU_MEMORY_XN));
143 }
144 }
145 }
146 }
147
148 /* Configure the MMU page entries for memory read from the
149 mmu_section_table */
150 for (i = 0; i < table_size; i++)
151 {
152 sections = mmu_section_table[i].num_of_sections;
153
154 while (sections--)
155 {
156 arm_mmu_map_section(mmu_section_table[i].paddress +
157 sections * MB,
158 mmu_section_table[i].vaddress +
159 sections * MB,
160 mmu_section_table[i].flags);
161 }
162 }
163}
164
165addr_t platform_get_virt_to_phys_mapping(addr_t virt_addr)
166{
167 /* Using 1-1 mapping on this platform. */
168 return virt_addr;
169}
170
171addr_t platform_get_phys_to_virt_mapping(addr_t phys_addr)
172{
173 /* Using 1-1 mapping on this platform. */
174 return phys_addr;
175}
176
177/* DYNAMIC SMEM REGION feature enables LK to dynamically
178 * read the SMEM addr info from TCSR_TZ_WONCE register.
179 * The first word read, if indicates a MAGIC number, then
180 * Dynamic SMEM is assumed to be enabled. Read the remaining
181 * SMEM info for SMEM Size and Phy_addr from the other bytes.
182 */
183uint32_t platform_get_smem_base_addr()
184{
185 struct smem_addr_info *smem_info = NULL;
186
187 smem_info = (struct smem_addr_info *)readl(TCSR_TZ_WONCE);
188 if(smem_info && (smem_info->identifier == SMEM_TARGET_INFO_IDENTIFIER))
189 return smem_info->phy_addr;
190 else
191 return MSM_SHARED_BASE;
192}
193
Unnati Gandhi6c92a4f2014-11-18 18:01:51 +0530194int platform_is_msm8909()
195{
196 uint32_t platform = board_platform_id();
197 uint32_t ret = 0;
198
199 switch(platform)
200 {
201 case MSM8909:
202 case MSM8209:
203 case MSM8208:
204 case APQ8009:
Unnati Gandhi917c8612015-02-06 16:50:32 +0530205 case MSM8609:
Unnati Gandhi6c92a4f2014-11-18 18:01:51 +0530206 ret = 1;
207 break;
208 default:
209 ret = 0;
210 };
211
212 return ret;
213}
214
215int boot_device_mask(int val)
216{
217 return ((val & 0x0E) >> 1);
218}
Unnati Gandhi24885052014-11-27 16:57:49 +0530219
220uint32_t platform_detect_panel()
221{
222 uint32_t panel;
223
224 /* Bits 28:29 of this register are read to know
225 the panel config, and pick up DT accordingly.
226
227 00 -no limit, suport HD
228 01 - limit to 720P
229 10- limit to qHD
230 11- limit to fWVGA
231
232 */
233 panel = readl(SECURITY_CONTROL_CORE_FEATURE_CONFIG0);
234 panel = (panel & 0x30000000) >> 28;
235
236 return panel;
237}