blob: 12e455d5b73043e8d9732d03bb0d8874c1677b49 [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 */
Channagoud Kadabi418b90d2012-07-18 11:26:36 +053055#define LK_MEMORY (MMU_MEMORY_TYPE_STRONGLY_ORDERED | \
Amol Jadi4421e652011-06-16 15:00:48 -070056 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{
Amol Jadia63aaff2012-02-01 15:51:50 -0800111 uint8_t gsbi_id = target_uart_gsbi();
112 uart_dm_init(gsbi_id, GSBI_BASE(gsbi_id), GSBI_UART_DM_BASE(gsbi_id));
Ajay Dudanib01e5062011-12-03 23:23:42 -0800113 qgic_init();
114 platform_init_timer();
Shashank Mittal23b8f422010-04-16 19:27:21 -0700115}
116
117void platform_init(void)
118{
Ajay Dudanib01e5062011-12-03 23:23:42 -0800119 dprintf(INFO, "platform_init()\n");
Shashank Mittal23b8f422010-04-16 19:27:21 -0700120}
121
122void display_init(void)
123{
Ajay Dudanib01e5062011-12-03 23:23:42 -0800124 struct fbcon_config *fb_cfg;
Shashank Mittal402d0972010-09-29 10:09:52 -0700125#if DISPLAY_TYPE_LCDC
Ajay Dudanib01e5062011-12-03 23:23:42 -0800126 struct lcdc_timing_parameters *lcd_timing;
127 mdp_clock_init();
128 if (board_machtype() == LINUX_MACHTYPE_8660_FLUID) {
129 mmss_pixel_clock_configure(PIXEL_CLK_INDEX_25M);
130 } else {
131 mmss_pixel_clock_configure(PIXEL_CLK_INDEX_54M);
132 }
133 lcd_timing = get_lcd_timing();
134 fb_cfg = lcdc_init_set(lcd_timing);
135 fbcon_setup(fb_cfg);
136 fbcon_clear();
137 panel_poweron();
Shashank Mittal402d0972010-09-29 10:09:52 -0700138#endif
Chandan Uddaraju78ae6752010-10-19 12:57:10 -0700139#if DISPLAY_TYPE_MIPI
Ajay Dudanib01e5062011-12-03 23:23:42 -0800140 mdp_clock_init();
141 configure_dsicore_dsiclk();
142 configure_dsicore_byteclk();
143 configure_dsicore_pclk();
Kinson Chikfe931032011-07-21 10:01:34 -0700144
Ajay Dudanib01e5062011-12-03 23:23:42 -0800145 fb_cfg = mipi_init();
146 fbcon_setup(fb_cfg);
Chandan Uddaraju78ae6752010-10-19 12:57:10 -0700147#endif
Channagoud Kadabie4884122011-09-21 23:54:44 +0530148#if DISPLAY_TYPE_HDMI
Ajay Dudanib01e5062011-12-03 23:23:42 -0800149 struct hdmi_disp_mode_timing_type *hdmi_timing;
150 mdp_clock_init();
151 hdmi_display_init();
152 hdmi_timing = hdmi_common_init_panel_info();
153 fb_cfg = hdmi_dtv_init(hdmi_timing);
154 fbcon_setup(fb_cfg);
Channagoud Kadabie4884122011-09-21 23:54:44 +0530155#endif
Shashank Mittal23b8f422010-04-16 19:27:21 -0700156}
157
Shashank Mittalc648e712010-10-06 18:37:42 -0700158void display_shutdown(void)
159{
Chandan Uddaraju78ae6752010-10-19 12:57:10 -0700160#if DISPLAY_TYPE_LCDC
Ajay Dudanib01e5062011-12-03 23:23:42 -0800161 /* Turning off LCDC */
162 lcdc_shutdown();
Chandan Uddaraju78ae6752010-10-19 12:57:10 -0700163#endif
164#if DISPLAY_TYPE_MIPI
Ajay Dudanib01e5062011-12-03 23:23:42 -0800165 mipi_dsi_shutdown();
Chandan Uddaraju78ae6752010-10-19 12:57:10 -0700166#endif
Channagoud Kadabie4884122011-09-21 23:54:44 +0530167#if DISPLAY_TYPE_HDMI
Ajay Dudanib01e5062011-12-03 23:23:42 -0800168 hdmi_display_shutdown();
Channagoud Kadabie4884122011-09-21 23:54:44 +0530169#endif
Shashank Mittalc648e712010-10-06 18:37:42 -0700170}
171
Ajay Dudanib01e5062011-12-03 23:23:42 -0800172static struct qup_i2c_dev *dev = NULL;
Shashank Mittalc69512e2010-09-22 16:40:48 -0700173
Ajay Dudanib01e5062011-12-03 23:23:42 -0800174uint32_t eprom_read(uint16_t addr, uint8_t count)
175{
176 uint32_t ret = 0;
177 if (!dev) {
178 return ret;
179 }
180 /* Create a i2c_msg buffer, that is used to put the controller into
181 * read mode and then to read some data.
182 */
183 struct i2c_msg msg_buf[] = {
184 {EEPROM_I2C_ADDRESS, I2C_M_WR, 2, &addr},
185 {EEPROM_I2C_ADDRESS, I2C_M_RD, count, &ret}
186 };
Shashank Mittalc69512e2010-09-22 16:40:48 -0700187
Ajay Dudanib01e5062011-12-03 23:23:42 -0800188 qup_i2c_xfer(dev, msg_buf, 2);
189 return ret;
Shashank Mittalc69512e2010-09-22 16:40:48 -0700190}
191
192/* Read EEPROM to find out product id. Return 0 in case of failure */
Ajay Dudanib01e5062011-12-03 23:23:42 -0800193uint32_t platform_id_read(void)
Shashank Mittalc69512e2010-09-22 16:40:48 -0700194{
Ajay Dudanib01e5062011-12-03 23:23:42 -0800195 uint32_t id = 0;
196 uint16_t offset = 0;
197 dev = qup_i2c_init(GSBI_ID_8, 100000, 24000000);
198 if (!dev) {
199 return id;
200 }
201 /* Check if EPROM is valid */
202 if (CONVERT_ENDIAN_U32(eprom_read(0, 4)) == CDT_MAGIC_NUMBER) {
203 /* Get offset for platform ID info from Meta Data block 0 */
204 offset = eprom_read(CONVERT_ENDIAN_U16(0 +
205 sizeof(struct
206 cdt_header)), 2);
207 /* Read platform ID */
208 id = eprom_read(CONVERT_ENDIAN_U16(offset), 4);
209 id = CONVERT_ENDIAN_U32(id);
210 id = (id & 0x00FF0000) >> 16;
211 }
212 return id;
Shashank Mittalc69512e2010-09-22 16:40:48 -0700213}
214
Amol Jadi4421e652011-06-16 15:00:48 -0700215/* Setup memory for this platform */
216void platform_init_mmu_mappings(void)
217{
Ajay Dudanib01e5062011-12-03 23:23:42 -0800218 uint32_t i;
219 uint32_t sections;
220 uint32_t table_size = ARRAY_SIZE(mmu_section_table);
Amol Jadi4421e652011-06-16 15:00:48 -0700221
Ajay Dudanib01e5062011-12-03 23:23:42 -0800222 for (i = 0; i < table_size; i++) {
223 sections = mmu_section_table[i].num_of_sections;
Amol Jadi4421e652011-06-16 15:00:48 -0700224
Ajay Dudanib01e5062011-12-03 23:23:42 -0800225 while (sections--) {
226 arm_mmu_map_section(mmu_section_table[i].paddress +
227 sections * MB,
228 mmu_section_table[i].vaddress +
229 sections * MB,
230 mmu_section_table[i].flags);
231 }
232 }
Amol Jadi4421e652011-06-16 15:00:48 -0700233}
234
235/* Do any platform specific cleanup just before kernel entry */
236void platform_uninit(void)
237{
238 /* As a effect of enabling caches, display gets shutdown even before
239 * the splash screen shows up. Until we can speed up the splash screen
240 * display, add an artificial delay so that current user experience
241 * is not affected.
242 */
243 mdelay(400);
244
Amol Jadi4421e652011-06-16 15:00:48 -0700245#if DISPLAY_SPLASH_SCREEN
246 display_shutdown();
247#endif
Amol Jadid7cfc032012-01-09 16:56:08 -0800248
249 platform_uninit_timer();
Amol Jadi4421e652011-06-16 15:00:48 -0700250}
Amol Jadiaeda4e62011-07-19 18:07:29 -0700251
252/* Initialize DGT timer */
253void platform_init_timer(void)
254{
255 /* disable timer */
256 writel(0, DGT_ENABLE);
257
258 /* DGT uses LPXO source which is 27MHz.
259 * Set clock divider to 4.
260 */
261 writel(3, DGT_CLK_CTL);
262
Ajay Dudanib01e5062011-12-03 23:23:42 -0800263 ticks_per_sec = 6750000; /* (27 MHz / 4) */
Amol Jadiaeda4e62011-07-19 18:07:29 -0700264}
265
266/* Returns timer ticks per sec */
267uint32_t platform_tick_rate(void)
268{
269 return ticks_per_sec;
270}