blob: 80dae3b35c4636b2e2e1e694e031ef59abf46e82 [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();
126 fb_cfg = lcdc_init();
127 panel_poweron();
128 fbcon_setup(fb_cfg);
129#endif
Chandan Uddaraju78ae6752010-10-19 12:57:10 -0700130#if DISPLAY_TYPE_MIPI
131 mdp_clock_init();
132 fb_cfg = mipi_init();
133 fbcon_setup(fb_cfg);
134#endif
135
Shashank Mittal23b8f422010-04-16 19:27:21 -0700136}
137
Shashank Mittalc648e712010-10-06 18:37:42 -0700138void display_shutdown(void)
139{
Chandan Uddaraju78ae6752010-10-19 12:57:10 -0700140#if DISPLAY_TYPE_LCDC
Shashank Mittalc648e712010-10-06 18:37:42 -0700141 /* Turning off LCDC */
142 lcdc_shutdown();
Chandan Uddaraju78ae6752010-10-19 12:57:10 -0700143#endif
144#if DISPLAY_TYPE_MIPI
145 mipi_dsi_shutdown();
146#endif
Shashank Mittalc648e712010-10-06 18:37:42 -0700147}
148
Shashank Mittalc69512e2010-09-22 16:40:48 -0700149static struct qup_i2c_dev* dev = NULL;
150
151uint32_t eprom_read (uint16_t addr, uint8_t count) {
152 uint32_t ret = 0;
153 if(!dev){
154 return ret;
155 }
156 /* Create a i2c_msg buffer, that is used to put the controller into
157 * read mode and then to read some data.
158 */
159 struct i2c_msg msg_buf[] = {
160 {EEPROM_I2C_ADDRESS, I2C_M_WR, 2, &addr},
161 {EEPROM_I2C_ADDRESS, I2C_M_RD, count, &ret}
162 };
163
164 qup_i2c_xfer(dev, msg_buf, 2);
165 return ret;
166}
167
168/* Read EEPROM to find out product id. Return 0 in case of failure */
169uint32_t platform_id_read (void)
170{
171 uint32_t id = 0;
172 uint16_t offset = 0;
Amol Jadic52c8a32011-07-12 11:27:04 -0700173 dev = qup_i2c_init(GSBI_ID_8, 100000, 24000000);
Shashank Mittalc69512e2010-09-22 16:40:48 -0700174 if(!dev){
175 return id;
176 }
177 /* Check if EPROM is valid */
178 if (CONVERT_ENDIAN_U32(eprom_read(0, 4)) == CDT_MAGIC_NUMBER)
179 {
180 /* Get offset for platform ID info from Meta Data block 0 */
181 offset = eprom_read(CONVERT_ENDIAN_U16(0 +
182 sizeof(struct cdt_header)), 2);
183 /* Read platform ID */
184 id = eprom_read(CONVERT_ENDIAN_U16(offset), 4);
185 id = CONVERT_ENDIAN_U32(id);
186 id = (id & 0x00FF0000) >> 16;
187 }
188 return id;
189}
190
Amol Jadi4421e652011-06-16 15:00:48 -0700191/* Setup memory for this platform */
192void platform_init_mmu_mappings(void)
193{
194 uint32_t i;
195 uint32_t sections;
196 uint32_t table_size = ARRAY_SIZE(mmu_section_table);
197
198 for (i = 0; i < table_size; i++)
199 {
200 sections = mmu_section_table[i].num_of_sections;
201
202 while (sections--)
203 {
204 arm_mmu_map_section(mmu_section_table[i].paddress + sections*MB,
205 mmu_section_table[i].vaddress + sections*MB,
206 mmu_section_table[i].flags);
207 }
208 }
209}
210
211/* Do any platform specific cleanup just before kernel entry */
212void platform_uninit(void)
213{
214 /* As a effect of enabling caches, display gets shutdown even before
215 * the splash screen shows up. Until we can speed up the splash screen
216 * display, add an artificial delay so that current user experience
217 * is not affected.
218 */
219 mdelay(400);
220
221 platform_uninit_timer();
222#if DISPLAY_SPLASH_SCREEN
223 display_shutdown();
224#endif
225}