blob: 3232557d232366266a9d63ec882b4829a09e5877 [file] [log] [blame]
Ajay Dudani232ce812009-12-02 00:14:11 -08001/*
2 * Copyright (c) 2008, Google Inc.
3 * All rights reserved.
Duy Truongf3ac7b32013-02-13 01:07:28 -08004 * Copyright (c) 2009-2011, The Linux Foundation. All rights reserved.
Ajay Dudani232ce812009-12-02 00:14:11 -08005 *
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
Chandan Uddarajuc009e4d2010-09-08 17:06:45 -070035#include <reg.h>
Ajay Dudani232ce812009-12-02 00:14:11 -080036#include <dev/fbcon.h>
37#include <kernel/thread.h>
38#include <platform/debug.h>
Amol Jadiaeda4e62011-07-19 18:07:29 -070039#include <platform/iomap.h>
Chandan Uddarajuc009e4d2010-09-08 17:06:45 -070040#include <mddi_hw.h>
41#include "gpio_hw.h"
Wentao Xu97df7fd2011-01-19 15:01:17 -050042#include <dev/lcdc.h>
Ajay Dudani232ce812009-12-02 00:14:11 -080043
44void platform_init_interrupts(void);
45void platform_init_timer();
46
Shashank Mittal1ddc04c2010-12-21 14:39:07 -080047void uart2_clock_init(void);
Ajay Dudani232ce812009-12-02 00:14:11 -080048void uart_init(void);
49
50struct fbcon_config *lcdc_init(void);
Amol Jadiaeda4e62011-07-19 18:07:29 -070051static uint32_t ticks_per_sec = 0;
Ajay Dudani232ce812009-12-02 00:14:11 -080052
Shashank Mittal1ddc04c2010-12-21 14:39:07 -080053#define ARRAY_SIZE(a) (sizeof(a)/(sizeof((a)[0])))
54
55static unsigned uart2_gpio_table[] = {
Ajay Dudanib01e5062011-12-03 23:23:42 -080056 GPIO_CFG(49, 2, GPIO_OUTPUT, GPIO_PULL_DOWN, GPIO_2MA),
57 GPIO_CFG(50, 2, GPIO_INPUT, GPIO_PULL_DOWN, GPIO_2MA),
58 GPIO_CFG(51, 2, GPIO_INPUT, GPIO_PULL_DOWN, GPIO_2MA),
59 GPIO_CFG(52, 2, GPIO_OUTPUT, GPIO_PULL_DOWN, GPIO_2MA),
Shashank Mittal1ddc04c2010-12-21 14:39:07 -080060};
61
Amol Jadi84a546a2011-03-02 12:09:11 -080062/* CRCI - mmc slot mapping.
63 * mmc slot numbering start from 1.
64 * entry at index 0 is just dummy.
65 */
Ajay Dudanib01e5062011-12-03 23:23:42 -080066uint8_t sdc_crci_map[5] = { 0, 6, 7, 12, 13 };
Amol Jadi84a546a2011-03-02 12:09:11 -080067
Shashank Mittal1ddc04c2010-12-21 14:39:07 -080068void uart2_mux_init(void)
69{
Ajay Dudanib01e5062011-12-03 23:23:42 -080070 platform_gpios_enable(uart2_gpio_table, ARRAY_SIZE(uart2_gpio_table));
Shashank Mittal1ddc04c2010-12-21 14:39:07 -080071}
72
Ajay Dudani232ce812009-12-02 00:14:11 -080073void platform_early_init(void)
74{
Shashank Mittal1ddc04c2010-12-21 14:39:07 -080075#if WITH_DEBUG_UART
76 uart2_mux_init();
77 uart2_clock_init();
78 uart_init();
79#endif
Ajay Dudani232ce812009-12-02 00:14:11 -080080 platform_init_interrupts();
81 platform_init_timer();
82}
83
84void platform_init(void)
85{
86 struct fbcon_config *fb_cfg;
87
88 dprintf(INFO, "platform_init()\n");
89 acpu_clock_init();
Subbaraman Narayanamurthy4cc29732010-10-18 15:57:58 -070090 adm_enable_clock();
Chandan Uddaraju24120502009-12-12 19:17:04 -080091}
92
Chandan Uddarajuc009e4d2010-09-08 17:06:45 -070093void mdp4_display_intf_sel(int output, int intf)
94{
Ajay Dudanib01e5062011-12-03 23:23:42 -080095 unsigned bits, mask;
96 unsigned dma2_cfg_reg;
97 bits = readl(MSM_MDP_BASE1 + 0x0038);
98 mask = 0x03; /* 2 bits */
99 intf &= 0x03; /* 2 bits */
Chandan Uddarajuc009e4d2010-09-08 17:06:45 -0700100
Ajay Dudanib01e5062011-12-03 23:23:42 -0800101 switch (output) {
102 case EXTERNAL_INTF_SEL:
103 intf <<= 4;
104 mask <<= 4;
105 break;
106 case SECONDARY_INTF_SEL:
107 intf &= 0x02; /* only MDDI and EBI2 support */
108 intf <<= 2;
109 mask <<= 2;
110 break;
111 default:
112 break;
113 }
Chandan Uddarajuc009e4d2010-09-08 17:06:45 -0700114
Ajay Dudanib01e5062011-12-03 23:23:42 -0800115 bits &= ~mask;
116 bits |= intf;
117 writel(bits, MSM_MDP_BASE1 + 0x0038); /* MDP_DISP_INTF_SEL */
Chandan Uddarajuc009e4d2010-09-08 17:06:45 -0700118}
119
Chandan Uddaraju24120502009-12-12 19:17:04 -0800120void display_init(void)
121{
Wentao Xu97df7fd2011-01-19 15:01:17 -0500122 struct fbcon_config *fb_cfg;
Chandan Uddarajuc009e4d2010-09-08 17:06:45 -0700123
124#if DISPLAY_TYPE_MDDI
Ajay Dudanib01e5062011-12-03 23:23:42 -0800125 mddi_pmdh_clock_init();
126 mddi_panel_poweron();
127 /* We need to config GPIO 38 for Sleep clock with Spl Fun 2 */
128 toshiba_pmic_gpio_init(GPIO38_GPIO_CNTRL);
129 fb_cfg = mddi_init();
130 fbcon_setup(fb_cfg);
Chandan Uddarajuc009e4d2010-09-08 17:06:45 -0700131#endif
132
133#if DISPLAY_TYPE_LCDC
Channagoud Kadabi956cf502012-03-08 03:49:50 +0530134 if(!machine_is_ffa()) {
135 struct lcdc_timing_parameters *lcd_timing;
136 mdp_lcdc_clock_init();
137 lcd_timing = get_lcd_timing();
138 fb_cfg = lcdc_init_set(lcd_timing);
139 panel_poweron();
140 fbcon_setup(fb_cfg);
141 }
Shashank Mittal37040832010-08-24 15:57:57 -0700142#endif
Ajay Dudani232ce812009-12-02 00:14:11 -0800143}
Shashank Mittal58317a72010-10-11 17:02:57 -0700144
145void display_shutdown(void)
146{
147#if DISPLAY_TYPE_LCDC
Ajay Dudanib01e5062011-12-03 23:23:42 -0800148 /* Turning off LCDC */
Channagoud Kadabi956cf502012-03-08 03:49:50 +0530149 if(!machine_is_ffa()) {
150 lcdc_shutdown();
151 }
Shashank Mittal58317a72010-10-11 17:02:57 -0700152#endif
153}
154
Amol Jadi4421e652011-06-16 15:00:48 -0700155void platform_uninit(void)
156{
Amol Jadi4421e652011-06-16 15:00:48 -0700157#if DISPLAY_SPLASH_SCREEN
158 display_shutdown();
159#endif
Amol Jadid7cfc032012-01-09 16:56:08 -0800160
161 platform_uninit_timer();
Amol Jadi4421e652011-06-16 15:00:48 -0700162}
Amol Jadiaeda4e62011-07-19 18:07:29 -0700163
164/* Initialize DGT timer */
165void platform_init_timer(void)
166{
167 uint32_t val = 0;
168
169 /* Disable timer */
170 writel(0, DGT_ENABLE);
171
172 /* Check for the hardware revision */
173 val = readl(HW_REVISION_NUMBER);
174 val = (val >> 28) & 0x0F;
Ajay Dudanib01e5062011-12-03 23:23:42 -0800175 if (val >= 1)
Amol Jadiaeda4e62011-07-19 18:07:29 -0700176 writel(1, DGT_CLK_CTL);
177
178#if _EMMC_BOOT
Ajay Dudanib01e5062011-12-03 23:23:42 -0800179 ticks_per_sec = 19200000; /* Uses TCXO (19.2 MHz) */
Amol Jadiaeda4e62011-07-19 18:07:29 -0700180#else
Ajay Dudanib01e5062011-12-03 23:23:42 -0800181 ticks_per_sec = 6144000; /* Uses LPXO/4 (24.576 MHz / 4) */
Amol Jadiaeda4e62011-07-19 18:07:29 -0700182#endif
183}
184
185/* Returns platform specific ticks per sec */
186uint32_t platform_tick_rate(void)
187{
188 return ticks_per_sec;
189}