blob: 8c31db6424671ebe380d1307bb9ae2655fea6ebb [file] [log] [blame]
Shashank Mittal23b8f422010-04-16 19:27:21 -07001/*
2 * Copyright (c) 2008, Google Inc.
3 * All rights reserved.
Aparna Mallavarapu88713ed2013-01-07 20:21:37 +05304 * Copyright (c) 2009-2013, The Linux Foundation. All rights reserved.
Shashank Mittal23b8f422010-04-16 19:27:21 -07005 *
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>
Aparna Mallavarapu88713ed2013-01-07 20:21:37 +053042#include <platform/pmic.h>
Amol Jadidb1edb32011-07-18 14:24:46 -070043#include <qgic.h>
Shashank Mittalc69512e2010-09-22 16:40:48 -070044#include <i2c_qup.h>
Amol Jadic52c8a32011-07-12 11:27:04 -070045#include <gsbi.h>
46#include <uart_dm.h>
Amol Jadi4421e652011-06-16 15:00:48 -070047#include <mmu.h>
48#include <arch/arm/mmu.h>
Wentao Xu8d6150c2011-06-22 11:03:18 -040049#include <dev/lcdc.h>
Amol Jadi4421e652011-06-16 15:00:48 -070050
Amol Jadiaeda4e62011-07-19 18:07:29 -070051static uint32_t ticks_per_sec = 0;
52
Amol Jadi4421e652011-06-16 15:00:48 -070053#define MB (1024*1024)
54
Amol Jadi4421e652011-06-16 15:00:48 -070055/* LK memory - cacheable, write through */
Channagoud Kadabi418b90d2012-07-18 11:26:36 +053056#define LK_MEMORY (MMU_MEMORY_TYPE_STRONGLY_ORDERED | \
Amol Jadi4421e652011-06-16 15:00:48 -070057 MMU_MEMORY_AP_READ_WRITE)
58
59/* Kernel region - cacheable, write through */
60#define KERNEL_MEMORY (MMU_MEMORY_TYPE_NORMAL_WRITE_THROUGH | \
61 MMU_MEMORY_AP_READ_WRITE)
62
63/* Scratch region - cacheable, write through */
64#define SCRATCH_MEMORY (MMU_MEMORY_TYPE_NORMAL_WRITE_THROUGH | \
65 MMU_MEMORY_AP_READ_WRITE)
66
67/* Peripherals - non-shared device */
68#define IOMAP_MEMORY (MMU_MEMORY_TYPE_DEVICE_NON_SHARED | \
69 MMU_MEMORY_AP_READ_WRITE)
70
Amol Jadi4421e652011-06-16 15:00:48 -070071#define MSM_IOMAP_SIZE ((MSM_IOMAP_END - MSM_IOMAP_BASE)/MB)
72
73mmu_section_t mmu_section_table[] = {
74/* Physical addr, Virtual addr, Size (in MB), Flags */
Ajay Dudanib01e5062011-12-03 23:23:42 -080075 {MEMBASE, MEMBASE, (MEMSIZE / MB), LK_MEMORY},
76 {BASE_ADDR, BASE_ADDR, 44, KERNEL_MEMORY},
77 {SCRATCH_ADDR, SCRATCH_ADDR, 128, SCRATCH_MEMORY},
78 {MSM_IOMAP_BASE, MSM_IOMAP_BASE, MSM_IOMAP_SIZE, IOMAP_MEMORY},
Amol Jadi4421e652011-06-16 15:00:48 -070079};
Shashank Mittalc69512e2010-09-22 16:40:48 -070080
81#define CONVERT_ENDIAN_U32(val) \
82 ((((uint32_t)(val) & 0x000000FF) << 24) | \
83 (((uint32_t)(val) & 0x0000FF00) << 8) | \
84 (((uint32_t)(val) & 0x00FF0000) >> 8) | \
85 (((uint32_t)(val) & 0xFF000000) >> 24))
86
87#define CONVERT_ENDIAN_U16(val) \
88 ((((uint16_t)(val) & 0x00FF) << 8) | \
89 (((uint16_t)(val) & 0xFF00) >> 8))
90
91/* Configuration Data Table */
92#define CDT_MAGIC_NUMBER 0x43445400
Ajay Dudanib01e5062011-12-03 23:23:42 -080093struct cdt_header {
94 uint32_t magic; /* Magic number */
95 uint16_t version; /* Version number */
96 uint32_t reserved1;
97 uint32_t reserved2;
98} __attribute__ ((packed));
Shashank Mittal23b8f422010-04-16 19:27:21 -070099
Shashank Mittal23b8f422010-04-16 19:27:21 -0700100void platform_init_timer();
101
Shashank Mittal23b8f422010-04-16 19:27:21 -0700102struct fbcon_config *lcdc_init(void);
103
Amol Jadi84a546a2011-03-02 12:09:11 -0800104/* CRCI - mmc slot mapping.
105 * mmc slot numbering start from 1.
106 * entry at index 0 is just dummy.
107 */
Ajay Dudanib01e5062011-12-03 23:23:42 -0800108uint8_t sdc_crci_map[5] = { 0, 1, 4, 2, 5 };
Amol Jadi84a546a2011-03-02 12:09:11 -0800109
Shashank Mittal23b8f422010-04-16 19:27:21 -0700110void platform_early_init(void)
111{
Amol Jadia63aaff2012-02-01 15:51:50 -0800112 uint8_t gsbi_id = target_uart_gsbi();
113 uart_dm_init(gsbi_id, GSBI_BASE(gsbi_id), GSBI_UART_DM_BASE(gsbi_id));
Ajay Dudanib01e5062011-12-03 23:23:42 -0800114 qgic_init();
115 platform_init_timer();
Shashank Mittal23b8f422010-04-16 19:27:21 -0700116}
117
118void platform_init(void)
119{
Ajay Dudanib01e5062011-12-03 23:23:42 -0800120 dprintf(INFO, "platform_init()\n");
Shashank Mittal23b8f422010-04-16 19:27:21 -0700121}
122
123void display_init(void)
124{
Ajay Dudanib01e5062011-12-03 23:23:42 -0800125 struct fbcon_config *fb_cfg;
Shashank Mittal402d0972010-09-29 10:09:52 -0700126#if DISPLAY_TYPE_LCDC
Ajay Dudanib01e5062011-12-03 23:23:42 -0800127 struct lcdc_timing_parameters *lcd_timing;
128 mdp_clock_init();
129 if (board_machtype() == LINUX_MACHTYPE_8660_FLUID) {
130 mmss_pixel_clock_configure(PIXEL_CLK_INDEX_25M);
131 } else {
132 mmss_pixel_clock_configure(PIXEL_CLK_INDEX_54M);
133 }
134 lcd_timing = get_lcd_timing();
135 fb_cfg = lcdc_init_set(lcd_timing);
136 fbcon_setup(fb_cfg);
137 fbcon_clear();
138 panel_poweron();
Shashank Mittal402d0972010-09-29 10:09:52 -0700139#endif
Chandan Uddaraju78ae6752010-10-19 12:57:10 -0700140#if DISPLAY_TYPE_MIPI
Ajay Dudanib01e5062011-12-03 23:23:42 -0800141 mdp_clock_init();
142 configure_dsicore_dsiclk();
143 configure_dsicore_byteclk();
144 configure_dsicore_pclk();
Kinson Chikfe931032011-07-21 10:01:34 -0700145
Ajay Dudanib01e5062011-12-03 23:23:42 -0800146 fb_cfg = mipi_init();
147 fbcon_setup(fb_cfg);
Chandan Uddaraju78ae6752010-10-19 12:57:10 -0700148#endif
Channagoud Kadabie4884122011-09-21 23:54:44 +0530149#if DISPLAY_TYPE_HDMI
Ajay Dudanib01e5062011-12-03 23:23:42 -0800150 struct hdmi_disp_mode_timing_type *hdmi_timing;
151 mdp_clock_init();
Ajay Singh Parmar2dad3572013-02-13 20:37:41 +0530152 hdmi_power_init();
153 fb_cfg = get_fbcon();
154 hdmi_set_fb_addr(fb_cfg.base);
Ajay Dudanib01e5062011-12-03 23:23:42 -0800155 fbcon_setup(fb_cfg);
Ajay Singh Parmar2dad3572013-02-13 20:37:41 +0530156 hdmi_dtv_init();
157 hdmi_dtv_on();
158 hdmi_msm_turn_on();
Channagoud Kadabie4884122011-09-21 23:54:44 +0530159#endif
Shashank Mittal23b8f422010-04-16 19:27:21 -0700160}
161
Shashank Mittalc648e712010-10-06 18:37:42 -0700162void display_shutdown(void)
163{
Chandan Uddaraju78ae6752010-10-19 12:57:10 -0700164#if DISPLAY_TYPE_LCDC
Aparna Mallavarapu88713ed2013-01-07 20:21:37 +0530165 unsigned rc = 0;
Ajay Dudanib01e5062011-12-03 23:23:42 -0800166 /* Turning off LCDC */
Aparna Mallavarapu88713ed2013-01-07 20:21:37 +0530167 rc = panel_set_backlight(0);
168 if (rc)
169 dprintf(CRITICAL, "Error in setting panel backlight\n");
Ajay Dudanib01e5062011-12-03 23:23:42 -0800170 lcdc_shutdown();
Aparna Mallavarapu88713ed2013-01-07 20:21:37 +0530171 pm8901_ldo_disable(LDO_L2);
Chandan Uddaraju78ae6752010-10-19 12:57:10 -0700172#endif
173#if DISPLAY_TYPE_MIPI
Ajay Dudanib01e5062011-12-03 23:23:42 -0800174 mipi_dsi_shutdown();
Chandan Uddaraju78ae6752010-10-19 12:57:10 -0700175#endif
Channagoud Kadabie4884122011-09-21 23:54:44 +0530176#if DISPLAY_TYPE_HDMI
Ajay Dudanib01e5062011-12-03 23:23:42 -0800177 hdmi_display_shutdown();
Channagoud Kadabie4884122011-09-21 23:54:44 +0530178#endif
Shashank Mittalc648e712010-10-06 18:37:42 -0700179}
180
Ajay Dudanib01e5062011-12-03 23:23:42 -0800181static struct qup_i2c_dev *dev = NULL;
Shashank Mittalc69512e2010-09-22 16:40:48 -0700182
Ajay Dudanib01e5062011-12-03 23:23:42 -0800183uint32_t eprom_read(uint16_t addr, uint8_t count)
184{
185 uint32_t ret = 0;
186 if (!dev) {
187 return ret;
188 }
189 /* Create a i2c_msg buffer, that is used to put the controller into
190 * read mode and then to read some data.
191 */
192 struct i2c_msg msg_buf[] = {
193 {EEPROM_I2C_ADDRESS, I2C_M_WR, 2, &addr},
194 {EEPROM_I2C_ADDRESS, I2C_M_RD, count, &ret}
195 };
Shashank Mittalc69512e2010-09-22 16:40:48 -0700196
Ajay Dudanib01e5062011-12-03 23:23:42 -0800197 qup_i2c_xfer(dev, msg_buf, 2);
198 return ret;
Shashank Mittalc69512e2010-09-22 16:40:48 -0700199}
200
201/* Read EEPROM to find out product id. Return 0 in case of failure */
Ajay Dudanib01e5062011-12-03 23:23:42 -0800202uint32_t platform_id_read(void)
Shashank Mittalc69512e2010-09-22 16:40:48 -0700203{
Ajay Dudanib01e5062011-12-03 23:23:42 -0800204 uint32_t id = 0;
205 uint16_t offset = 0;
206 dev = qup_i2c_init(GSBI_ID_8, 100000, 24000000);
207 if (!dev) {
208 return id;
209 }
210 /* Check if EPROM is valid */
211 if (CONVERT_ENDIAN_U32(eprom_read(0, 4)) == CDT_MAGIC_NUMBER) {
212 /* Get offset for platform ID info from Meta Data block 0 */
213 offset = eprom_read(CONVERT_ENDIAN_U16(0 +
214 sizeof(struct
215 cdt_header)), 2);
216 /* Read platform ID */
217 id = eprom_read(CONVERT_ENDIAN_U16(offset), 4);
218 id = CONVERT_ENDIAN_U32(id);
219 id = (id & 0x00FF0000) >> 16;
220 }
221 return id;
Shashank Mittalc69512e2010-09-22 16:40:48 -0700222}
223
Amol Jadi4421e652011-06-16 15:00:48 -0700224/* Setup memory for this platform */
225void platform_init_mmu_mappings(void)
226{
Ajay Dudanib01e5062011-12-03 23:23:42 -0800227 uint32_t i;
228 uint32_t sections;
229 uint32_t table_size = ARRAY_SIZE(mmu_section_table);
Amol Jadi4421e652011-06-16 15:00:48 -0700230
Ajay Dudanib01e5062011-12-03 23:23:42 -0800231 for (i = 0; i < table_size; i++) {
232 sections = mmu_section_table[i].num_of_sections;
Amol Jadi4421e652011-06-16 15:00:48 -0700233
Ajay Dudanib01e5062011-12-03 23:23:42 -0800234 while (sections--) {
235 arm_mmu_map_section(mmu_section_table[i].paddress +
236 sections * MB,
237 mmu_section_table[i].vaddress +
238 sections * MB,
239 mmu_section_table[i].flags);
240 }
241 }
Amol Jadi4421e652011-06-16 15:00:48 -0700242}
243
244/* Do any platform specific cleanup just before kernel entry */
245void platform_uninit(void)
246{
247 /* As a effect of enabling caches, display gets shutdown even before
248 * the splash screen shows up. Until we can speed up the splash screen
249 * display, add an artificial delay so that current user experience
250 * is not affected.
251 */
252 mdelay(400);
253
Amol Jadi4421e652011-06-16 15:00:48 -0700254#if DISPLAY_SPLASH_SCREEN
255 display_shutdown();
256#endif
Amol Jadid7cfc032012-01-09 16:56:08 -0800257
258 platform_uninit_timer();
Amol Jadi4421e652011-06-16 15:00:48 -0700259}
Amol Jadiaeda4e62011-07-19 18:07:29 -0700260
261/* Initialize DGT timer */
262void platform_init_timer(void)
263{
264 /* disable timer */
265 writel(0, DGT_ENABLE);
266
267 /* DGT uses LPXO source which is 27MHz.
268 * Set clock divider to 4.
269 */
270 writel(3, DGT_CLK_CTL);
271
Ajay Dudanib01e5062011-12-03 23:23:42 -0800272 ticks_per_sec = 6750000; /* (27 MHz / 4) */
Amol Jadiaeda4e62011-07-19 18:07:29 -0700273}
274
275/* Returns timer ticks per sec */
276uint32_t platform_tick_rate(void)
277{
278 return ticks_per_sec;
279}