Shashank Mittal | 23b8f42 | 2010-04-16 19:27:21 -0700 | [diff] [blame] | 1 | /* |
| 2 | * Copyright (c) 2008, Google Inc. |
| 3 | * All rights reserved. |
Aparna Mallavarapu | 88713ed | 2013-01-07 20:21:37 +0530 | [diff] [blame] | 4 | * Copyright (c) 2009-2013, The Linux Foundation. All rights reserved. |
Shashank Mittal | 23b8f42 | 2010-04-16 19:27:21 -0700 | [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 | #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 Xu | 8d6150c | 2011-06-22 11:03:18 -0400 | [diff] [blame] | 40 | #include <platform/clock.h> |
| 41 | #include <platform/machtype.h> |
Aparna Mallavarapu | 88713ed | 2013-01-07 20:21:37 +0530 | [diff] [blame] | 42 | #include <platform/pmic.h> |
Amol Jadi | db1edb3 | 2011-07-18 14:24:46 -0700 | [diff] [blame] | 43 | #include <qgic.h> |
Shashank Mittal | c69512e | 2010-09-22 16:40:48 -0700 | [diff] [blame] | 44 | #include <i2c_qup.h> |
Amol Jadi | c52c8a3 | 2011-07-12 11:27:04 -0700 | [diff] [blame] | 45 | #include <gsbi.h> |
| 46 | #include <uart_dm.h> |
Amol Jadi | 4421e65 | 2011-06-16 15:00:48 -0700 | [diff] [blame] | 47 | #include <mmu.h> |
| 48 | #include <arch/arm/mmu.h> |
Wentao Xu | 8d6150c | 2011-06-22 11:03:18 -0400 | [diff] [blame] | 49 | #include <dev/lcdc.h> |
Amol Jadi | 4421e65 | 2011-06-16 15:00:48 -0700 | [diff] [blame] | 50 | |
Amol Jadi | aeda4e6 | 2011-07-19 18:07:29 -0700 | [diff] [blame] | 51 | static uint32_t ticks_per_sec = 0; |
| 52 | |
Amol Jadi | 4421e65 | 2011-06-16 15:00:48 -0700 | [diff] [blame] | 53 | #define MB (1024*1024) |
| 54 | |
Amol Jadi | 4421e65 | 2011-06-16 15:00:48 -0700 | [diff] [blame] | 55 | /* LK memory - cacheable, write through */ |
Channagoud Kadabi | 418b90d | 2012-07-18 11:26:36 +0530 | [diff] [blame] | 56 | #define LK_MEMORY (MMU_MEMORY_TYPE_STRONGLY_ORDERED | \ |
Amol Jadi | 4421e65 | 2011-06-16 15:00:48 -0700 | [diff] [blame] | 57 | 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 Jadi | 4421e65 | 2011-06-16 15:00:48 -0700 | [diff] [blame] | 71 | #define MSM_IOMAP_SIZE ((MSM_IOMAP_END - MSM_IOMAP_BASE)/MB) |
| 72 | |
| 73 | mmu_section_t mmu_section_table[] = { |
| 74 | /* Physical addr, Virtual addr, Size (in MB), Flags */ |
Ajay Dudani | b01e506 | 2011-12-03 23:23:42 -0800 | [diff] [blame] | 75 | {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 Jadi | 4421e65 | 2011-06-16 15:00:48 -0700 | [diff] [blame] | 79 | }; |
Shashank Mittal | c69512e | 2010-09-22 16:40:48 -0700 | [diff] [blame] | 80 | |
| 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 Dudani | b01e506 | 2011-12-03 23:23:42 -0800 | [diff] [blame] | 93 | struct 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 Mittal | 23b8f42 | 2010-04-16 19:27:21 -0700 | [diff] [blame] | 99 | |
Shashank Mittal | 23b8f42 | 2010-04-16 19:27:21 -0700 | [diff] [blame] | 100 | void platform_init_timer(); |
| 101 | |
Shashank Mittal | 23b8f42 | 2010-04-16 19:27:21 -0700 | [diff] [blame] | 102 | struct fbcon_config *lcdc_init(void); |
| 103 | |
Amol Jadi | 84a546a | 2011-03-02 12:09:11 -0800 | [diff] [blame] | 104 | /* CRCI - mmc slot mapping. |
| 105 | * mmc slot numbering start from 1. |
| 106 | * entry at index 0 is just dummy. |
| 107 | */ |
Ajay Dudani | b01e506 | 2011-12-03 23:23:42 -0800 | [diff] [blame] | 108 | uint8_t sdc_crci_map[5] = { 0, 1, 4, 2, 5 }; |
Amol Jadi | 84a546a | 2011-03-02 12:09:11 -0800 | [diff] [blame] | 109 | |
Shashank Mittal | 23b8f42 | 2010-04-16 19:27:21 -0700 | [diff] [blame] | 110 | void platform_early_init(void) |
| 111 | { |
Amol Jadi | a63aaff | 2012-02-01 15:51:50 -0800 | [diff] [blame] | 112 | uint8_t gsbi_id = target_uart_gsbi(); |
| 113 | uart_dm_init(gsbi_id, GSBI_BASE(gsbi_id), GSBI_UART_DM_BASE(gsbi_id)); |
Ajay Dudani | b01e506 | 2011-12-03 23:23:42 -0800 | [diff] [blame] | 114 | qgic_init(); |
| 115 | platform_init_timer(); |
Shashank Mittal | 23b8f42 | 2010-04-16 19:27:21 -0700 | [diff] [blame] | 116 | } |
| 117 | |
| 118 | void platform_init(void) |
| 119 | { |
Ajay Dudani | b01e506 | 2011-12-03 23:23:42 -0800 | [diff] [blame] | 120 | dprintf(INFO, "platform_init()\n"); |
Shashank Mittal | 23b8f42 | 2010-04-16 19:27:21 -0700 | [diff] [blame] | 121 | } |
| 122 | |
| 123 | void display_init(void) |
| 124 | { |
Ajay Dudani | b01e506 | 2011-12-03 23:23:42 -0800 | [diff] [blame] | 125 | struct fbcon_config *fb_cfg; |
Shashank Mittal | 402d097 | 2010-09-29 10:09:52 -0700 | [diff] [blame] | 126 | #if DISPLAY_TYPE_LCDC |
Ajay Dudani | b01e506 | 2011-12-03 23:23:42 -0800 | [diff] [blame] | 127 | 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 Mittal | 402d097 | 2010-09-29 10:09:52 -0700 | [diff] [blame] | 139 | #endif |
Chandan Uddaraju | 78ae675 | 2010-10-19 12:57:10 -0700 | [diff] [blame] | 140 | #if DISPLAY_TYPE_MIPI |
Ajay Dudani | b01e506 | 2011-12-03 23:23:42 -0800 | [diff] [blame] | 141 | mdp_clock_init(); |
| 142 | configure_dsicore_dsiclk(); |
| 143 | configure_dsicore_byteclk(); |
| 144 | configure_dsicore_pclk(); |
Kinson Chik | fe93103 | 2011-07-21 10:01:34 -0700 | [diff] [blame] | 145 | |
Ajay Dudani | b01e506 | 2011-12-03 23:23:42 -0800 | [diff] [blame] | 146 | fb_cfg = mipi_init(); |
| 147 | fbcon_setup(fb_cfg); |
Chandan Uddaraju | 78ae675 | 2010-10-19 12:57:10 -0700 | [diff] [blame] | 148 | #endif |
Channagoud Kadabi | e488412 | 2011-09-21 23:54:44 +0530 | [diff] [blame] | 149 | #if DISPLAY_TYPE_HDMI |
Ajay Dudani | b01e506 | 2011-12-03 23:23:42 -0800 | [diff] [blame] | 150 | struct hdmi_disp_mode_timing_type *hdmi_timing; |
| 151 | mdp_clock_init(); |
Ajay Singh Parmar | 2dad357 | 2013-02-13 20:37:41 +0530 | [diff] [blame] | 152 | hdmi_power_init(); |
| 153 | fb_cfg = get_fbcon(); |
| 154 | hdmi_set_fb_addr(fb_cfg.base); |
Ajay Dudani | b01e506 | 2011-12-03 23:23:42 -0800 | [diff] [blame] | 155 | fbcon_setup(fb_cfg); |
Ajay Singh Parmar | 2dad357 | 2013-02-13 20:37:41 +0530 | [diff] [blame] | 156 | hdmi_dtv_init(); |
| 157 | hdmi_dtv_on(); |
| 158 | hdmi_msm_turn_on(); |
Channagoud Kadabi | e488412 | 2011-09-21 23:54:44 +0530 | [diff] [blame] | 159 | #endif |
Shashank Mittal | 23b8f42 | 2010-04-16 19:27:21 -0700 | [diff] [blame] | 160 | } |
| 161 | |
Shashank Mittal | c648e71 | 2010-10-06 18:37:42 -0700 | [diff] [blame] | 162 | void display_shutdown(void) |
| 163 | { |
Chandan Uddaraju | 78ae675 | 2010-10-19 12:57:10 -0700 | [diff] [blame] | 164 | #if DISPLAY_TYPE_LCDC |
Aparna Mallavarapu | 88713ed | 2013-01-07 20:21:37 +0530 | [diff] [blame] | 165 | unsigned rc = 0; |
Ajay Dudani | b01e506 | 2011-12-03 23:23:42 -0800 | [diff] [blame] | 166 | /* Turning off LCDC */ |
Aparna Mallavarapu | 88713ed | 2013-01-07 20:21:37 +0530 | [diff] [blame] | 167 | rc = panel_set_backlight(0); |
| 168 | if (rc) |
| 169 | dprintf(CRITICAL, "Error in setting panel backlight\n"); |
Ajay Dudani | b01e506 | 2011-12-03 23:23:42 -0800 | [diff] [blame] | 170 | lcdc_shutdown(); |
Aparna Mallavarapu | 88713ed | 2013-01-07 20:21:37 +0530 | [diff] [blame] | 171 | pm8901_ldo_disable(LDO_L2); |
Chandan Uddaraju | 78ae675 | 2010-10-19 12:57:10 -0700 | [diff] [blame] | 172 | #endif |
| 173 | #if DISPLAY_TYPE_MIPI |
Ajay Dudani | b01e506 | 2011-12-03 23:23:42 -0800 | [diff] [blame] | 174 | mipi_dsi_shutdown(); |
Chandan Uddaraju | 78ae675 | 2010-10-19 12:57:10 -0700 | [diff] [blame] | 175 | #endif |
Channagoud Kadabi | e488412 | 2011-09-21 23:54:44 +0530 | [diff] [blame] | 176 | #if DISPLAY_TYPE_HDMI |
Ajay Dudani | b01e506 | 2011-12-03 23:23:42 -0800 | [diff] [blame] | 177 | hdmi_display_shutdown(); |
Channagoud Kadabi | e488412 | 2011-09-21 23:54:44 +0530 | [diff] [blame] | 178 | #endif |
Shashank Mittal | c648e71 | 2010-10-06 18:37:42 -0700 | [diff] [blame] | 179 | } |
| 180 | |
Ajay Dudani | b01e506 | 2011-12-03 23:23:42 -0800 | [diff] [blame] | 181 | static struct qup_i2c_dev *dev = NULL; |
Shashank Mittal | c69512e | 2010-09-22 16:40:48 -0700 | [diff] [blame] | 182 | |
Ajay Dudani | b01e506 | 2011-12-03 23:23:42 -0800 | [diff] [blame] | 183 | uint32_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 Mittal | c69512e | 2010-09-22 16:40:48 -0700 | [diff] [blame] | 196 | |
Ajay Dudani | b01e506 | 2011-12-03 23:23:42 -0800 | [diff] [blame] | 197 | qup_i2c_xfer(dev, msg_buf, 2); |
| 198 | return ret; |
Shashank Mittal | c69512e | 2010-09-22 16:40:48 -0700 | [diff] [blame] | 199 | } |
| 200 | |
| 201 | /* Read EEPROM to find out product id. Return 0 in case of failure */ |
Ajay Dudani | b01e506 | 2011-12-03 23:23:42 -0800 | [diff] [blame] | 202 | uint32_t platform_id_read(void) |
Shashank Mittal | c69512e | 2010-09-22 16:40:48 -0700 | [diff] [blame] | 203 | { |
Ajay Dudani | b01e506 | 2011-12-03 23:23:42 -0800 | [diff] [blame] | 204 | 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 Mittal | c69512e | 2010-09-22 16:40:48 -0700 | [diff] [blame] | 222 | } |
| 223 | |
Amol Jadi | 4421e65 | 2011-06-16 15:00:48 -0700 | [diff] [blame] | 224 | /* Setup memory for this platform */ |
| 225 | void platform_init_mmu_mappings(void) |
| 226 | { |
Ajay Dudani | b01e506 | 2011-12-03 23:23:42 -0800 | [diff] [blame] | 227 | uint32_t i; |
| 228 | uint32_t sections; |
| 229 | uint32_t table_size = ARRAY_SIZE(mmu_section_table); |
Amol Jadi | 4421e65 | 2011-06-16 15:00:48 -0700 | [diff] [blame] | 230 | |
Ajay Dudani | b01e506 | 2011-12-03 23:23:42 -0800 | [diff] [blame] | 231 | for (i = 0; i < table_size; i++) { |
| 232 | sections = mmu_section_table[i].num_of_sections; |
Amol Jadi | 4421e65 | 2011-06-16 15:00:48 -0700 | [diff] [blame] | 233 | |
Ajay Dudani | b01e506 | 2011-12-03 23:23:42 -0800 | [diff] [blame] | 234 | 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 Jadi | 4421e65 | 2011-06-16 15:00:48 -0700 | [diff] [blame] | 242 | } |
| 243 | |
| 244 | /* Do any platform specific cleanup just before kernel entry */ |
| 245 | void 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 Jadi | 4421e65 | 2011-06-16 15:00:48 -0700 | [diff] [blame] | 254 | #if DISPLAY_SPLASH_SCREEN |
| 255 | display_shutdown(); |
| 256 | #endif |
Amol Jadi | d7cfc03 | 2012-01-09 16:56:08 -0800 | [diff] [blame] | 257 | |
| 258 | platform_uninit_timer(); |
Amol Jadi | 4421e65 | 2011-06-16 15:00:48 -0700 | [diff] [blame] | 259 | } |
Amol Jadi | aeda4e6 | 2011-07-19 18:07:29 -0700 | [diff] [blame] | 260 | |
| 261 | /* Initialize DGT timer */ |
| 262 | void 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 Dudani | b01e506 | 2011-12-03 23:23:42 -0800 | [diff] [blame] | 272 | ticks_per_sec = 6750000; /* (27 MHz / 4) */ |
Amol Jadi | aeda4e6 | 2011-07-19 18:07:29 -0700 | [diff] [blame] | 273 | } |
| 274 | |
| 275 | /* Returns timer ticks per sec */ |
| 276 | uint32_t platform_tick_rate(void) |
| 277 | { |
| 278 | return ticks_per_sec; |
| 279 | } |