blob: 158b4833b6e77b99abb171c20e56cfbca43aa03b [file] [log] [blame]
Amol Jadicd43ea02011-02-15 20:56:04 -08001/*
Duy Truongf3ac7b32013-02-13 01:07:28 -08002 * Copyright (c) 2011-2012, The Linux Foundation. All rights reserved.
Amol Jadicd43ea02011-02-15 20:56:04 -08003 *
4 * Redistribution and use in source and binary forms, with or without
5 * modification, are permitted provided that the following conditions
6 * are met:
7 * * Redistributions of source code must retain the above copyright
8 * notice, this list of conditions and the following disclaimer.
9 * * Redistributions in binary form must reproduce the above copyright
10 * notice, this list of conditions and the following disclaimer in
11 * the documentation and/or other materials provided with the
12 * distribution.
13 * * Neither the name of Google, Inc. nor the names of its contributors
14 * may be used to endorse or promote products derived from this
15 * software without specific prior written permission.
16 *
17 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
18 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
19 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
20 * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
21 * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
22 * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
23 * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS
24 * OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
25 * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
26 * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
27 * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
28 * SUCH DAMAGE.
29 */
30
31#include <debug.h>
32#include <reg.h>
33#include <platform/iomap.h>
Amol Jadidb1edb32011-07-18 14:24:46 -070034#include <qgic.h>
Amol Jadic52c8a32011-07-12 11:27:04 -070035#include <uart_dm.h>
Kinson Chike5c93432011-06-17 09:10:29 -070036#include <dev/fbcon.h>
Amol Jadida055742011-06-14 16:15:12 -070037#include <mmu.h>
38#include <arch/arm/mmu.h>
Shashank Mittala635abf2012-03-28 18:11:43 -070039#include <board.h>
Amol Jadicd43ea02011-02-15 20:56:04 -080040
Amol Jadicd43ea02011-02-15 20:56:04 -080041extern void platform_init_timer(void);
Greg Grisco1073a5e2011-07-28 18:59:18 -070042extern void platform_panel_backlight_on(void);
43extern void platform_uninit_timer(void);
Kinson Chike5c93432011-06-17 09:10:29 -070044extern void mipi_panel_reset(void);
45extern void mipi_dsi_panel_power_on(void);
46extern void mdp_clock_init(void);
47extern void mmss_clock_init(void);
48extern struct fbcon_config *mipi_init(void);
49extern void mipi_dsi_shutdown(void);
Shashank Mittal30262902012-02-21 15:37:24 -080050extern void msm_clocks_init(void);
Amol Jadicd43ea02011-02-15 20:56:04 -080051
Amol Jadiaeda4e62011-07-19 18:07:29 -070052static uint32_t ticks_per_sec = 0;
Shashank Mittale2ad8762012-02-07 15:15:11 -080053static uint8_t display_enabled = 0;
Amol Jadiaeda4e62011-07-19 18:07:29 -070054
Amol Jadida055742011-06-14 16:15:12 -070055#define MB (1024*1024)
56
57#define MSM_IOMAP_SIZE ((MSM_IOMAP_END - MSM_IOMAP_BASE)/MB)
58
59/* LK memory - cacheable, write through */
60#define LK_MEMORY (MMU_MEMORY_TYPE_NORMAL_WRITE_THROUGH | \
61 MMU_MEMORY_AP_READ_WRITE)
62
63/* Kernel region - cacheable, write through */
64#define KERNEL_MEMORY (MMU_MEMORY_TYPE_NORMAL_WRITE_THROUGH | \
Amol Jadi0228e9f2011-12-19 17:21:36 -080065 MMU_MEMORY_AP_READ_WRITE | MMU_MEMORY_XN)
Amol Jadida055742011-06-14 16:15:12 -070066
67/* Scratch region - cacheable, write through */
68#define SCRATCH_MEMORY (MMU_MEMORY_TYPE_NORMAL_WRITE_THROUGH | \
Amol Jadi0228e9f2011-12-19 17:21:36 -080069 MMU_MEMORY_AP_READ_WRITE | MMU_MEMORY_XN)
Amol Jadida055742011-06-14 16:15:12 -070070
71/* Peripherals - non-shared device */
72#define IOMAP_MEMORY (MMU_MEMORY_TYPE_DEVICE_NON_SHARED | \
Amol Jadi0228e9f2011-12-19 17:21:36 -080073 MMU_MEMORY_AP_READ_WRITE | MMU_MEMORY_XN)
74
75/* IMEM: Must set execute never bit to avoid instruction prefetch from TZ */
76#define IMEM_MEMORY (MMU_MEMORY_TYPE_STRONGLY_ORDERED | \
77 MMU_MEMORY_AP_READ_WRITE | MMU_MEMORY_XN)
Amol Jadida055742011-06-14 16:15:12 -070078
Amol Jadida055742011-06-14 16:15:12 -070079mmu_section_t mmu_section_table[] = {
80/* Physical addr, Virtual addr, Size (in MB), Flags */
Ajay Dudanib01e5062011-12-03 23:23:42 -080081 {MEMBASE, MEMBASE, (MEMSIZE / MB), LK_MEMORY},
82 {BASE_ADDR, BASE_ADDR, 44, KERNEL_MEMORY},
Channagoud Kadabi7d84dd62012-08-24 21:20:56 +053083 {SCRATCH_ADDR, SCRATCH_ADDR, 768, SCRATCH_MEMORY},
Ajay Dudanib01e5062011-12-03 23:23:42 -080084 {MSM_IOMAP_BASE, MSM_IOMAP_BASE, MSM_IOMAP_SIZE, IOMAP_MEMORY},
Amol Jadi0228e9f2011-12-19 17:21:36 -080085 {MSM_IMEM_BASE, MSM_IMEM_BASE, 1, IMEM_MEMORY},
Amol Jadida055742011-06-14 16:15:12 -070086};
87
Amol Jadicd43ea02011-02-15 20:56:04 -080088void platform_early_init(void)
89{
Shashank Mittal30262902012-02-21 15:37:24 -080090 msm_clocks_init();
Ajay Dudanib01e5062011-12-03 23:23:42 -080091 qgic_init();
92 platform_init_timer();
Shashank Mittala635abf2012-03-28 18:11:43 -070093 board_init();
Amol Jadicd43ea02011-02-15 20:56:04 -080094}
95
96void platform_init(void)
97{
Ajay Dudanib01e5062011-12-03 23:23:42 -080098 dprintf(INFO, "platform_init()\n");
Amol Jadicd43ea02011-02-15 20:56:04 -080099}
Kinson Chike5c93432011-06-17 09:10:29 -0700100
Amol Jadi4421e652011-06-16 15:00:48 -0700101void platform_uninit(void)
102{
Amol Jadi4421e652011-06-16 15:00:48 -0700103#if DISPLAY_SPLASH_SCREEN
104 display_shutdown();
105#endif
Shashank Mittalac23fa12012-02-13 17:38:15 -0800106
Amol Jadid7cfc032012-01-09 16:56:08 -0800107 platform_uninit_timer();
Amol Jadi4421e652011-06-16 15:00:48 -0700108}
109
Amol Jadida055742011-06-14 16:15:12 -0700110/* Setup memory for this platform */
111void platform_init_mmu_mappings(void)
112{
Ajay Dudanib01e5062011-12-03 23:23:42 -0800113 uint32_t i;
114 uint32_t sections;
115 uint32_t table_size = ARRAY_SIZE(mmu_section_table);
Amol Jadida055742011-06-14 16:15:12 -0700116
Ajay Dudanib01e5062011-12-03 23:23:42 -0800117 for (i = 0; i < table_size; i++) {
118 sections = mmu_section_table[i].num_of_sections;
Amol Jadida055742011-06-14 16:15:12 -0700119
Ajay Dudanib01e5062011-12-03 23:23:42 -0800120 while (sections--) {
121 arm_mmu_map_section(mmu_section_table[i].paddress +
122 sections * MB,
123 mmu_section_table[i].vaddress +
124 sections * MB,
125 mmu_section_table[i].flags);
126 }
127 }
Amol Jadida055742011-06-14 16:15:12 -0700128}
Amol Jadiaeda4e62011-07-19 18:07:29 -0700129
130/* Initialize DGT timer */
131void platform_init_timer(void)
132{
133 /* disable timer */
134 writel(0, DGT_ENABLE);
135
136 /* DGT uses LPXO source which is 27MHz.
137 * Set clock divider to 4.
138 */
139 writel(3, DGT_CLK_CTL);
140
Ajay Dudanib01e5062011-12-03 23:23:42 -0800141 ticks_per_sec = 6750000; /* (27 MHz / 4) */
Amol Jadiaeda4e62011-07-19 18:07:29 -0700142}
143
144/* Returns timer ticks per sec */
145uint32_t platform_tick_rate(void)
146{
147 return ticks_per_sec;
148}
Channagoud Kadabi80e776b2013-02-15 19:52:12 -0800149
150/* Return true if the pmic type matches */
151uint8_t platform_pmic_type(uint32_t pmic_type)
152{
153 uint8_t ret = 0;
154 uint8_t i = 0;
155 uint8_t num_ent = 0;
156 struct board_pmic_data pmic_info[SMEM_V7_SMEM_MAX_PMIC_DEVICES];
157
158 num_ent = board_pmic_info(&pmic_info, SMEM_V7_SMEM_MAX_PMIC_DEVICES);
159
160 for(i = 0; i < num_ent; i++) {
161 if (pmic_info[i].pmic_type == pmic_type) {
162 ret = 1;
163 break;
164 }
165 }
166
167 return ret;
168}