Ajay Dudani | 232ce81 | 2009-12-02 00:14:11 -0800 | [diff] [blame] | 1 | /* |
| 2 | * Copyright (c) 2008, Google Inc. |
| 3 | * All rights reserved. |
Duy Truong | f3ac7b3 | 2013-02-13 01:07:28 -0800 | [diff] [blame] | 4 | * Copyright (c) 2009-2011, The Linux Foundation. All rights reserved. |
Ajay Dudani | 232ce81 | 2009-12-02 00:14:11 -0800 | [diff] [blame] | 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 | |
Chandan Uddaraju | c009e4d | 2010-09-08 17:06:45 -0700 | [diff] [blame] | 35 | #include <reg.h> |
Ajay Dudani | 232ce81 | 2009-12-02 00:14:11 -0800 | [diff] [blame] | 36 | #include <dev/fbcon.h> |
| 37 | #include <kernel/thread.h> |
| 38 | #include <platform/debug.h> |
Amol Jadi | aeda4e6 | 2011-07-19 18:07:29 -0700 | [diff] [blame] | 39 | #include <platform/iomap.h> |
Chandan Uddaraju | c009e4d | 2010-09-08 17:06:45 -0700 | [diff] [blame] | 40 | #include <mddi_hw.h> |
| 41 | #include "gpio_hw.h" |
Wentao Xu | 97df7fd | 2011-01-19 15:01:17 -0500 | [diff] [blame] | 42 | #include <dev/lcdc.h> |
Ajay Dudani | 232ce81 | 2009-12-02 00:14:11 -0800 | [diff] [blame] | 43 | |
| 44 | void platform_init_interrupts(void); |
| 45 | void platform_init_timer(); |
| 46 | |
Shashank Mittal | 1ddc04c | 2010-12-21 14:39:07 -0800 | [diff] [blame] | 47 | void uart2_clock_init(void); |
Ajay Dudani | 232ce81 | 2009-12-02 00:14:11 -0800 | [diff] [blame] | 48 | void uart_init(void); |
| 49 | |
| 50 | struct fbcon_config *lcdc_init(void); |
Amol Jadi | aeda4e6 | 2011-07-19 18:07:29 -0700 | [diff] [blame] | 51 | static uint32_t ticks_per_sec = 0; |
Ajay Dudani | 232ce81 | 2009-12-02 00:14:11 -0800 | [diff] [blame] | 52 | |
Shashank Mittal | 1ddc04c | 2010-12-21 14:39:07 -0800 | [diff] [blame] | 53 | #define ARRAY_SIZE(a) (sizeof(a)/(sizeof((a)[0]))) |
| 54 | |
| 55 | static unsigned uart2_gpio_table[] = { |
Ajay Dudani | b01e506 | 2011-12-03 23:23:42 -0800 | [diff] [blame] | 56 | 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 Mittal | 1ddc04c | 2010-12-21 14:39:07 -0800 | [diff] [blame] | 60 | }; |
| 61 | |
Amol Jadi | 84a546a | 2011-03-02 12:09:11 -0800 | [diff] [blame] | 62 | /* CRCI - mmc slot mapping. |
| 63 | * mmc slot numbering start from 1. |
| 64 | * entry at index 0 is just dummy. |
| 65 | */ |
Ajay Dudani | b01e506 | 2011-12-03 23:23:42 -0800 | [diff] [blame] | 66 | uint8_t sdc_crci_map[5] = { 0, 6, 7, 12, 13 }; |
Amol Jadi | 84a546a | 2011-03-02 12:09:11 -0800 | [diff] [blame] | 67 | |
Shashank Mittal | 1ddc04c | 2010-12-21 14:39:07 -0800 | [diff] [blame] | 68 | void uart2_mux_init(void) |
| 69 | { |
Ajay Dudani | b01e506 | 2011-12-03 23:23:42 -0800 | [diff] [blame] | 70 | platform_gpios_enable(uart2_gpio_table, ARRAY_SIZE(uart2_gpio_table)); |
Shashank Mittal | 1ddc04c | 2010-12-21 14:39:07 -0800 | [diff] [blame] | 71 | } |
| 72 | |
Ajay Dudani | 232ce81 | 2009-12-02 00:14:11 -0800 | [diff] [blame] | 73 | void platform_early_init(void) |
| 74 | { |
Shashank Mittal | 1ddc04c | 2010-12-21 14:39:07 -0800 | [diff] [blame] | 75 | #if WITH_DEBUG_UART |
| 76 | uart2_mux_init(); |
| 77 | uart2_clock_init(); |
| 78 | uart_init(); |
| 79 | #endif |
Ajay Dudani | 232ce81 | 2009-12-02 00:14:11 -0800 | [diff] [blame] | 80 | platform_init_interrupts(); |
| 81 | platform_init_timer(); |
| 82 | } |
| 83 | |
| 84 | void platform_init(void) |
| 85 | { |
| 86 | struct fbcon_config *fb_cfg; |
| 87 | |
| 88 | dprintf(INFO, "platform_init()\n"); |
| 89 | acpu_clock_init(); |
Subbaraman Narayanamurthy | 4cc2973 | 2010-10-18 15:57:58 -0700 | [diff] [blame] | 90 | adm_enable_clock(); |
Chandan Uddaraju | 2412050 | 2009-12-12 19:17:04 -0800 | [diff] [blame] | 91 | } |
| 92 | |
Chandan Uddaraju | c009e4d | 2010-09-08 17:06:45 -0700 | [diff] [blame] | 93 | void mdp4_display_intf_sel(int output, int intf) |
| 94 | { |
Ajay Dudani | b01e506 | 2011-12-03 23:23:42 -0800 | [diff] [blame] | 95 | 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 Uddaraju | c009e4d | 2010-09-08 17:06:45 -0700 | [diff] [blame] | 100 | |
Ajay Dudani | b01e506 | 2011-12-03 23:23:42 -0800 | [diff] [blame] | 101 | 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 Uddaraju | c009e4d | 2010-09-08 17:06:45 -0700 | [diff] [blame] | 114 | |
Ajay Dudani | b01e506 | 2011-12-03 23:23:42 -0800 | [diff] [blame] | 115 | bits &= ~mask; |
| 116 | bits |= intf; |
| 117 | writel(bits, MSM_MDP_BASE1 + 0x0038); /* MDP_DISP_INTF_SEL */ |
Chandan Uddaraju | c009e4d | 2010-09-08 17:06:45 -0700 | [diff] [blame] | 118 | } |
| 119 | |
Chandan Uddaraju | 2412050 | 2009-12-12 19:17:04 -0800 | [diff] [blame] | 120 | void display_init(void) |
| 121 | { |
Wentao Xu | 97df7fd | 2011-01-19 15:01:17 -0500 | [diff] [blame] | 122 | struct fbcon_config *fb_cfg; |
Chandan Uddaraju | c009e4d | 2010-09-08 17:06:45 -0700 | [diff] [blame] | 123 | |
| 124 | #if DISPLAY_TYPE_MDDI |
Ajay Dudani | b01e506 | 2011-12-03 23:23:42 -0800 | [diff] [blame] | 125 | 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 Uddaraju | c009e4d | 2010-09-08 17:06:45 -0700 | [diff] [blame] | 131 | #endif |
| 132 | |
| 133 | #if DISPLAY_TYPE_LCDC |
Channagoud Kadabi | 956cf50 | 2012-03-08 03:49:50 +0530 | [diff] [blame] | 134 | 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 Mittal | 3704083 | 2010-08-24 15:57:57 -0700 | [diff] [blame] | 142 | #endif |
Ajay Dudani | 232ce81 | 2009-12-02 00:14:11 -0800 | [diff] [blame] | 143 | } |
Shashank Mittal | 58317a7 | 2010-10-11 17:02:57 -0700 | [diff] [blame] | 144 | |
| 145 | void display_shutdown(void) |
| 146 | { |
| 147 | #if DISPLAY_TYPE_LCDC |
Ajay Dudani | b01e506 | 2011-12-03 23:23:42 -0800 | [diff] [blame] | 148 | /* Turning off LCDC */ |
Channagoud Kadabi | 956cf50 | 2012-03-08 03:49:50 +0530 | [diff] [blame] | 149 | if(!machine_is_ffa()) { |
| 150 | lcdc_shutdown(); |
| 151 | } |
Shashank Mittal | 58317a7 | 2010-10-11 17:02:57 -0700 | [diff] [blame] | 152 | #endif |
| 153 | } |
| 154 | |
Amol Jadi | 4421e65 | 2011-06-16 15:00:48 -0700 | [diff] [blame] | 155 | void platform_uninit(void) |
| 156 | { |
Amol Jadi | 4421e65 | 2011-06-16 15:00:48 -0700 | [diff] [blame] | 157 | #if DISPLAY_SPLASH_SCREEN |
| 158 | display_shutdown(); |
| 159 | #endif |
Amol Jadi | d7cfc03 | 2012-01-09 16:56:08 -0800 | [diff] [blame] | 160 | |
| 161 | platform_uninit_timer(); |
Amol Jadi | 4421e65 | 2011-06-16 15:00:48 -0700 | [diff] [blame] | 162 | } |
Amol Jadi | aeda4e6 | 2011-07-19 18:07:29 -0700 | [diff] [blame] | 163 | |
| 164 | /* Initialize DGT timer */ |
| 165 | void 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 Dudani | b01e506 | 2011-12-03 23:23:42 -0800 | [diff] [blame] | 175 | if (val >= 1) |
Amol Jadi | aeda4e6 | 2011-07-19 18:07:29 -0700 | [diff] [blame] | 176 | writel(1, DGT_CLK_CTL); |
| 177 | |
| 178 | #if _EMMC_BOOT |
Ajay Dudani | b01e506 | 2011-12-03 23:23:42 -0800 | [diff] [blame] | 179 | ticks_per_sec = 19200000; /* Uses TCXO (19.2 MHz) */ |
Amol Jadi | aeda4e6 | 2011-07-19 18:07:29 -0700 | [diff] [blame] | 180 | #else |
Ajay Dudani | b01e506 | 2011-12-03 23:23:42 -0800 | [diff] [blame] | 181 | ticks_per_sec = 6144000; /* Uses LPXO/4 (24.576 MHz / 4) */ |
Amol Jadi | aeda4e6 | 2011-07-19 18:07:29 -0700 | [diff] [blame] | 182 | #endif |
| 183 | } |
| 184 | |
| 185 | /* Returns platform specific ticks per sec */ |
| 186 | uint32_t platform_tick_rate(void) |
| 187 | { |
| 188 | return ticks_per_sec; |
| 189 | } |