blob: 04bc894a992a025736d82ca63c5277ec415ef51f [file] [log] [blame]
Shashank Mittal23b8f422010-04-16 19:27:21 -07001/*
2 * Copyright (c) 2008, Google Inc.
3 * All rights reserved.
4 * Copyright (c) 2009-2010, Code Aurora Forum. All rights reserved.
5 *
6 * Redistribution and use in source and binary forms, with or without
7 * modification, are permitted provided that the following conditions
8 * are met:
9 * * Redistributions of source code must retain the above copyright
10 * notice, this list of conditions and the following disclaimer.
11 * * Redistributions in binary form must reproduce the above copyright
12 * notice, this list of conditions and the following disclaimer in
13 * the documentation and/or other materials provided with the
14 * distribution.
15 * * Neither the name of Google, Inc. nor the names of its contributors
16 * may be used to endorse or promote products derived from this
17 * software without specific prior written permission.
18 *
19 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
20 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
21 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
22 * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
23 * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
24 * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
25 * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS
26 * OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
27 * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
28 * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
29 * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
30 * SUCH DAMAGE.
31 */
32
33#include <debug.h>
34#include <reg.h>
35
36#include <dev/fbcon.h>
37#include <kernel/thread.h>
38#include <platform/debug.h>
39#include <platform/iomap.h>
Amol Jadidb1edb32011-07-18 14:24:46 -070040#include <qgic.h>
Shashank Mittalc69512e2010-09-22 16:40:48 -070041#include <i2c_qup.h>
Amol Jadic52c8a32011-07-12 11:27:04 -070042#include <gsbi.h>
43#include <uart_dm.h>
Amol Jadi4421e652011-06-16 15:00:48 -070044#include <mmu.h>
45#include <arch/arm/mmu.h>
46
47#define MB (1024*1024)
48
49
50/* LK memory - cacheable, write through */
51#define LK_MEMORY (MMU_MEMORY_TYPE_NORMAL_WRITE_THROUGH | \
52 MMU_MEMORY_AP_READ_WRITE)
53
54/* Kernel region - cacheable, write through */
55#define KERNEL_MEMORY (MMU_MEMORY_TYPE_NORMAL_WRITE_THROUGH | \
56 MMU_MEMORY_AP_READ_WRITE)
57
58/* Scratch region - cacheable, write through */
59#define SCRATCH_MEMORY (MMU_MEMORY_TYPE_NORMAL_WRITE_THROUGH | \
60 MMU_MEMORY_AP_READ_WRITE)
61
62/* Peripherals - non-shared device */
63#define IOMAP_MEMORY (MMU_MEMORY_TYPE_DEVICE_NON_SHARED | \
64 MMU_MEMORY_AP_READ_WRITE)
65
66
67#define MSM_IOMAP_SIZE ((MSM_IOMAP_END - MSM_IOMAP_BASE)/MB)
68
69mmu_section_t mmu_section_table[] = {
70/* Physical addr, Virtual addr, Size (in MB), Flags */
71 {MEMBASE, MEMBASE, (MEMSIZE/MB), LK_MEMORY},
72 {BASE_ADDR, BASE_ADDR, 44, KERNEL_MEMORY},
73 {SCRATCH_ADDR, SCRATCH_ADDR, 128, SCRATCH_MEMORY},
74 {MSM_IOMAP_BASE, MSM_IOMAP_BASE, MSM_IOMAP_SIZE, IOMAP_MEMORY},
75};
Shashank Mittalc69512e2010-09-22 16:40:48 -070076
77#define CONVERT_ENDIAN_U32(val) \
78 ((((uint32_t)(val) & 0x000000FF) << 24) | \
79 (((uint32_t)(val) & 0x0000FF00) << 8) | \
80 (((uint32_t)(val) & 0x00FF0000) >> 8) | \
81 (((uint32_t)(val) & 0xFF000000) >> 24))
82
83#define CONVERT_ENDIAN_U16(val) \
84 ((((uint16_t)(val) & 0x00FF) << 8) | \
85 (((uint16_t)(val) & 0xFF00) >> 8))
86
87/* Configuration Data Table */
88#define CDT_MAGIC_NUMBER 0x43445400
89struct cdt_header
90{
91 uint32_t magic; /* Magic number */
92 uint16_t version; /* Version number */
93 uint32_t reserved1;
94 uint32_t reserved2;
95}__attribute__((packed));
Shashank Mittal23b8f422010-04-16 19:27:21 -070096
Shashank Mittal23b8f422010-04-16 19:27:21 -070097void platform_init_timer();
98
Shashank Mittal23b8f422010-04-16 19:27:21 -070099
100struct fbcon_config *lcdc_init(void);
101
Amol Jadi84a546a2011-03-02 12:09:11 -0800102/* CRCI - mmc slot mapping.
103 * mmc slot numbering start from 1.
104 * entry at index 0 is just dummy.
105 */
106uint8_t sdc_crci_map[5] = {0, 1, 4, 2, 5};
107
Shashank Mittal23b8f422010-04-16 19:27:21 -0700108void platform_early_init(void)
109{
Amol Jadic52c8a32011-07-12 11:27:04 -0700110 uart_init(target_uart_gsbi());
Amol Jadidb1edb32011-07-18 14:24:46 -0700111 qgic_init();
Shashank Mittal23b8f422010-04-16 19:27:21 -0700112 platform_init_timer();
113}
114
115void platform_init(void)
116{
117 dprintf(INFO, "platform_init()\n");
Subbaraman Narayanamurthy05872db2011-02-28 11:34:58 -0800118 ce_clock_init();
Shashank Mittal23b8f422010-04-16 19:27:21 -0700119}
120
121void display_init(void)
122{
Shashank Mittal402d0972010-09-29 10:09:52 -0700123 struct fbcon_config *fb_cfg;
124#if DISPLAY_TYPE_LCDC
125 mdp_clock_init();
Kinson Chikfe931032011-07-21 10:01:34 -0700126 mmss_pixel_clock_configure();
Shashank Mittal402d0972010-09-29 10:09:52 -0700127 fb_cfg = lcdc_init();
128 panel_poweron();
129 fbcon_setup(fb_cfg);
130#endif
Chandan Uddaraju78ae6752010-10-19 12:57:10 -0700131#if DISPLAY_TYPE_MIPI
132 mdp_clock_init();
Kinson Chikfe931032011-07-21 10:01:34 -0700133 configure_dsicore_dsiclk();
134 configure_dsicore_byteclk();
135 configure_dsicore_pclk();
136
Chandan Uddaraju78ae6752010-10-19 12:57:10 -0700137 fb_cfg = mipi_init();
138 fbcon_setup(fb_cfg);
139#endif
140
Shashank Mittal23b8f422010-04-16 19:27:21 -0700141}
142
Shashank Mittalc648e712010-10-06 18:37:42 -0700143void display_shutdown(void)
144{
Chandan Uddaraju78ae6752010-10-19 12:57:10 -0700145#if DISPLAY_TYPE_LCDC
Shashank Mittalc648e712010-10-06 18:37:42 -0700146 /* Turning off LCDC */
147 lcdc_shutdown();
Chandan Uddaraju78ae6752010-10-19 12:57:10 -0700148#endif
149#if DISPLAY_TYPE_MIPI
150 mipi_dsi_shutdown();
151#endif
Shashank Mittalc648e712010-10-06 18:37:42 -0700152}
153
Shashank Mittalc69512e2010-09-22 16:40:48 -0700154static struct qup_i2c_dev* dev = NULL;
155
156uint32_t eprom_read (uint16_t addr, uint8_t count) {
157 uint32_t ret = 0;
158 if(!dev){
159 return ret;
160 }
161 /* Create a i2c_msg buffer, that is used to put the controller into
162 * read mode and then to read some data.
163 */
164 struct i2c_msg msg_buf[] = {
165 {EEPROM_I2C_ADDRESS, I2C_M_WR, 2, &addr},
166 {EEPROM_I2C_ADDRESS, I2C_M_RD, count, &ret}
167 };
168
169 qup_i2c_xfer(dev, msg_buf, 2);
170 return ret;
171}
172
173/* Read EEPROM to find out product id. Return 0 in case of failure */
174uint32_t platform_id_read (void)
175{
176 uint32_t id = 0;
177 uint16_t offset = 0;
Amol Jadic52c8a32011-07-12 11:27:04 -0700178 dev = qup_i2c_init(GSBI_ID_8, 100000, 24000000);
Shashank Mittalc69512e2010-09-22 16:40:48 -0700179 if(!dev){
180 return id;
181 }
182 /* Check if EPROM is valid */
183 if (CONVERT_ENDIAN_U32(eprom_read(0, 4)) == CDT_MAGIC_NUMBER)
184 {
185 /* Get offset for platform ID info from Meta Data block 0 */
186 offset = eprom_read(CONVERT_ENDIAN_U16(0 +
187 sizeof(struct cdt_header)), 2);
188 /* Read platform ID */
189 id = eprom_read(CONVERT_ENDIAN_U16(offset), 4);
190 id = CONVERT_ENDIAN_U32(id);
191 id = (id & 0x00FF0000) >> 16;
192 }
193 return id;
194}
195
Amol Jadi4421e652011-06-16 15:00:48 -0700196/* Setup memory for this platform */
197void platform_init_mmu_mappings(void)
198{
199 uint32_t i;
200 uint32_t sections;
201 uint32_t table_size = ARRAY_SIZE(mmu_section_table);
202
203 for (i = 0; i < table_size; i++)
204 {
205 sections = mmu_section_table[i].num_of_sections;
206
207 while (sections--)
208 {
209 arm_mmu_map_section(mmu_section_table[i].paddress + sections*MB,
210 mmu_section_table[i].vaddress + sections*MB,
211 mmu_section_table[i].flags);
212 }
213 }
214}
215
216/* Do any platform specific cleanup just before kernel entry */
217void platform_uninit(void)
218{
219 /* As a effect of enabling caches, display gets shutdown even before
220 * the splash screen shows up. Until we can speed up the splash screen
221 * display, add an artificial delay so that current user experience
222 * is not affected.
223 */
224 mdelay(400);
225
226 platform_uninit_timer();
227#if DISPLAY_SPLASH_SCREEN
228 display_shutdown();
229#endif
230}