blob: e2369f7da412c932f4c411b340695715f7d764c7 [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>
Wentao Xu8d6150c2011-06-22 11:03:18 -040040#include <platform/clock.h>
41#include <platform/machtype.h>
Amol Jadidb1edb32011-07-18 14:24:46 -070042#include <qgic.h>
Shashank Mittalc69512e2010-09-22 16:40:48 -070043#include <i2c_qup.h>
Amol Jadic52c8a32011-07-12 11:27:04 -070044#include <gsbi.h>
45#include <uart_dm.h>
Amol Jadi4421e652011-06-16 15:00:48 -070046#include <mmu.h>
47#include <arch/arm/mmu.h>
Wentao Xu8d6150c2011-06-22 11:03:18 -040048#include <dev/lcdc.h>
Amol Jadi4421e652011-06-16 15:00:48 -070049
Amol Jadiaeda4e62011-07-19 18:07:29 -070050static uint32_t ticks_per_sec = 0;
51
Amol Jadi4421e652011-06-16 15:00:48 -070052#define MB (1024*1024)
53
Amol Jadi4421e652011-06-16 15:00:48 -070054/* LK memory - cacheable, write through */
55#define LK_MEMORY (MMU_MEMORY_TYPE_NORMAL_WRITE_THROUGH | \
56 MMU_MEMORY_AP_READ_WRITE)
57
58/* Kernel region - cacheable, write through */
59#define KERNEL_MEMORY (MMU_MEMORY_TYPE_NORMAL_WRITE_THROUGH | \
60 MMU_MEMORY_AP_READ_WRITE)
61
62/* Scratch region - cacheable, write through */
63#define SCRATCH_MEMORY (MMU_MEMORY_TYPE_NORMAL_WRITE_THROUGH | \
64 MMU_MEMORY_AP_READ_WRITE)
65
66/* Peripherals - non-shared device */
67#define IOMAP_MEMORY (MMU_MEMORY_TYPE_DEVICE_NON_SHARED | \
68 MMU_MEMORY_AP_READ_WRITE)
69
Amol Jadi4421e652011-06-16 15:00:48 -070070#define MSM_IOMAP_SIZE ((MSM_IOMAP_END - MSM_IOMAP_BASE)/MB)
71
72mmu_section_t mmu_section_table[] = {
73/* Physical addr, Virtual addr, Size (in MB), Flags */
Ajay Dudanib01e5062011-12-03 23:23:42 -080074 {MEMBASE, MEMBASE, (MEMSIZE / MB), LK_MEMORY},
75 {BASE_ADDR, BASE_ADDR, 44, KERNEL_MEMORY},
76 {SCRATCH_ADDR, SCRATCH_ADDR, 128, SCRATCH_MEMORY},
77 {MSM_IOMAP_BASE, MSM_IOMAP_BASE, MSM_IOMAP_SIZE, IOMAP_MEMORY},
Amol Jadi4421e652011-06-16 15:00:48 -070078};
Shashank Mittalc69512e2010-09-22 16:40:48 -070079
80#define CONVERT_ENDIAN_U32(val) \
81 ((((uint32_t)(val) & 0x000000FF) << 24) | \
82 (((uint32_t)(val) & 0x0000FF00) << 8) | \
83 (((uint32_t)(val) & 0x00FF0000) >> 8) | \
84 (((uint32_t)(val) & 0xFF000000) >> 24))
85
86#define CONVERT_ENDIAN_U16(val) \
87 ((((uint16_t)(val) & 0x00FF) << 8) | \
88 (((uint16_t)(val) & 0xFF00) >> 8))
89
90/* Configuration Data Table */
91#define CDT_MAGIC_NUMBER 0x43445400
Ajay Dudanib01e5062011-12-03 23:23:42 -080092struct cdt_header {
93 uint32_t magic; /* Magic number */
94 uint16_t version; /* Version number */
95 uint32_t reserved1;
96 uint32_t reserved2;
97} __attribute__ ((packed));
Shashank Mittal23b8f422010-04-16 19:27:21 -070098
Shashank Mittal23b8f422010-04-16 19:27:21 -070099void platform_init_timer();
100
Shashank Mittal23b8f422010-04-16 19:27:21 -0700101struct fbcon_config *lcdc_init(void);
102
Amol Jadi84a546a2011-03-02 12:09:11 -0800103/* CRCI - mmc slot mapping.
104 * mmc slot numbering start from 1.
105 * entry at index 0 is just dummy.
106 */
Ajay Dudanib01e5062011-12-03 23:23:42 -0800107uint8_t sdc_crci_map[5] = { 0, 1, 4, 2, 5 };
Amol Jadi84a546a2011-03-02 12:09:11 -0800108
Shashank Mittal23b8f422010-04-16 19:27:21 -0700109void platform_early_init(void)
110{
Ajay Dudanib01e5062011-12-03 23:23:42 -0800111 uart_init(target_uart_gsbi());
112 qgic_init();
113 platform_init_timer();
Shashank Mittal23b8f422010-04-16 19:27:21 -0700114}
115
116void platform_init(void)
117{
Ajay Dudanib01e5062011-12-03 23:23:42 -0800118 dprintf(INFO, "platform_init()\n");
Shashank Mittal23b8f422010-04-16 19:27:21 -0700119}
120
121void display_init(void)
122{
Ajay Dudanib01e5062011-12-03 23:23:42 -0800123 struct fbcon_config *fb_cfg;
Shashank Mittal402d0972010-09-29 10:09:52 -0700124#if DISPLAY_TYPE_LCDC
Ajay Dudanib01e5062011-12-03 23:23:42 -0800125 struct lcdc_timing_parameters *lcd_timing;
126 mdp_clock_init();
127 if (board_machtype() == LINUX_MACHTYPE_8660_FLUID) {
128 mmss_pixel_clock_configure(PIXEL_CLK_INDEX_25M);
129 } else {
130 mmss_pixel_clock_configure(PIXEL_CLK_INDEX_54M);
131 }
132 lcd_timing = get_lcd_timing();
133 fb_cfg = lcdc_init_set(lcd_timing);
134 fbcon_setup(fb_cfg);
135 fbcon_clear();
136 panel_poweron();
Shashank Mittal402d0972010-09-29 10:09:52 -0700137#endif
Chandan Uddaraju78ae6752010-10-19 12:57:10 -0700138#if DISPLAY_TYPE_MIPI
Ajay Dudanib01e5062011-12-03 23:23:42 -0800139 mdp_clock_init();
140 configure_dsicore_dsiclk();
141 configure_dsicore_byteclk();
142 configure_dsicore_pclk();
Kinson Chikfe931032011-07-21 10:01:34 -0700143
Ajay Dudanib01e5062011-12-03 23:23:42 -0800144 fb_cfg = mipi_init();
145 fbcon_setup(fb_cfg);
Chandan Uddaraju78ae6752010-10-19 12:57:10 -0700146#endif
Channagoud Kadabie4884122011-09-21 23:54:44 +0530147#if DISPLAY_TYPE_HDMI
Ajay Dudanib01e5062011-12-03 23:23:42 -0800148 struct hdmi_disp_mode_timing_type *hdmi_timing;
149 mdp_clock_init();
150 hdmi_display_init();
151 hdmi_timing = hdmi_common_init_panel_info();
152 fb_cfg = hdmi_dtv_init(hdmi_timing);
153 fbcon_setup(fb_cfg);
Channagoud Kadabie4884122011-09-21 23:54:44 +0530154#endif
Shashank Mittal23b8f422010-04-16 19:27:21 -0700155}
156
Shashank Mittalc648e712010-10-06 18:37:42 -0700157void display_shutdown(void)
158{
Chandan Uddaraju78ae6752010-10-19 12:57:10 -0700159#if DISPLAY_TYPE_LCDC
Ajay Dudanib01e5062011-12-03 23:23:42 -0800160 /* Turning off LCDC */
161 lcdc_shutdown();
Chandan Uddaraju78ae6752010-10-19 12:57:10 -0700162#endif
163#if DISPLAY_TYPE_MIPI
Ajay Dudanib01e5062011-12-03 23:23:42 -0800164 mipi_dsi_shutdown();
Chandan Uddaraju78ae6752010-10-19 12:57:10 -0700165#endif
Channagoud Kadabie4884122011-09-21 23:54:44 +0530166#if DISPLAY_TYPE_HDMI
Ajay Dudanib01e5062011-12-03 23:23:42 -0800167 hdmi_display_shutdown();
Channagoud Kadabie4884122011-09-21 23:54:44 +0530168#endif
Shashank Mittalc648e712010-10-06 18:37:42 -0700169}
170
Ajay Dudanib01e5062011-12-03 23:23:42 -0800171static struct qup_i2c_dev *dev = NULL;
Shashank Mittalc69512e2010-09-22 16:40:48 -0700172
Ajay Dudanib01e5062011-12-03 23:23:42 -0800173uint32_t eprom_read(uint16_t addr, uint8_t count)
174{
175 uint32_t ret = 0;
176 if (!dev) {
177 return ret;
178 }
179 /* Create a i2c_msg buffer, that is used to put the controller into
180 * read mode and then to read some data.
181 */
182 struct i2c_msg msg_buf[] = {
183 {EEPROM_I2C_ADDRESS, I2C_M_WR, 2, &addr},
184 {EEPROM_I2C_ADDRESS, I2C_M_RD, count, &ret}
185 };
Shashank Mittalc69512e2010-09-22 16:40:48 -0700186
Ajay Dudanib01e5062011-12-03 23:23:42 -0800187 qup_i2c_xfer(dev, msg_buf, 2);
188 return ret;
Shashank Mittalc69512e2010-09-22 16:40:48 -0700189}
190
191/* Read EEPROM to find out product id. Return 0 in case of failure */
Ajay Dudanib01e5062011-12-03 23:23:42 -0800192uint32_t platform_id_read(void)
Shashank Mittalc69512e2010-09-22 16:40:48 -0700193{
Ajay Dudanib01e5062011-12-03 23:23:42 -0800194 uint32_t id = 0;
195 uint16_t offset = 0;
196 dev = qup_i2c_init(GSBI_ID_8, 100000, 24000000);
197 if (!dev) {
198 return id;
199 }
200 /* Check if EPROM is valid */
201 if (CONVERT_ENDIAN_U32(eprom_read(0, 4)) == CDT_MAGIC_NUMBER) {
202 /* Get offset for platform ID info from Meta Data block 0 */
203 offset = eprom_read(CONVERT_ENDIAN_U16(0 +
204 sizeof(struct
205 cdt_header)), 2);
206 /* Read platform ID */
207 id = eprom_read(CONVERT_ENDIAN_U16(offset), 4);
208 id = CONVERT_ENDIAN_U32(id);
209 id = (id & 0x00FF0000) >> 16;
210 }
211 return id;
Shashank Mittalc69512e2010-09-22 16:40:48 -0700212}
213
Amol Jadi4421e652011-06-16 15:00:48 -0700214/* Setup memory for this platform */
215void platform_init_mmu_mappings(void)
216{
Ajay Dudanib01e5062011-12-03 23:23:42 -0800217 uint32_t i;
218 uint32_t sections;
219 uint32_t table_size = ARRAY_SIZE(mmu_section_table);
Amol Jadi4421e652011-06-16 15:00:48 -0700220
Ajay Dudanib01e5062011-12-03 23:23:42 -0800221 for (i = 0; i < table_size; i++) {
222 sections = mmu_section_table[i].num_of_sections;
Amol Jadi4421e652011-06-16 15:00:48 -0700223
Ajay Dudanib01e5062011-12-03 23:23:42 -0800224 while (sections--) {
225 arm_mmu_map_section(mmu_section_table[i].paddress +
226 sections * MB,
227 mmu_section_table[i].vaddress +
228 sections * MB,
229 mmu_section_table[i].flags);
230 }
231 }
Amol Jadi4421e652011-06-16 15:00:48 -0700232}
233
234/* Do any platform specific cleanup just before kernel entry */
235void platform_uninit(void)
236{
237 /* As a effect of enabling caches, display gets shutdown even before
238 * the splash screen shows up. Until we can speed up the splash screen
239 * display, add an artificial delay so that current user experience
240 * is not affected.
241 */
242 mdelay(400);
243
Amol Jadi4421e652011-06-16 15:00:48 -0700244#if DISPLAY_SPLASH_SCREEN
245 display_shutdown();
246#endif
Amol Jadid7cfc032012-01-09 16:56:08 -0800247
248 platform_uninit_timer();
Amol Jadi4421e652011-06-16 15:00:48 -0700249}
Amol Jadiaeda4e62011-07-19 18:07:29 -0700250
251/* Initialize DGT timer */
252void platform_init_timer(void)
253{
254 /* disable timer */
255 writel(0, DGT_ENABLE);
256
257 /* DGT uses LPXO source which is 27MHz.
258 * Set clock divider to 4.
259 */
260 writel(3, DGT_CLK_CTL);
261
Ajay Dudanib01e5062011-12-03 23:23:42 -0800262 ticks_per_sec = 6750000; /* (27 MHz / 4) */
Amol Jadiaeda4e62011-07-19 18:07:29 -0700263}
264
265/* Returns timer ticks per sec */
266uint32_t platform_tick_rate(void)
267{
268 return ticks_per_sec;
269}