Amol Jadi | cd43ea0 | 2011-02-15 20:56:04 -0800 | [diff] [blame] | 1 | /* |
Duy Truong | f3ac7b3 | 2013-02-13 01:07:28 -0800 | [diff] [blame] | 2 | * Copyright (c) 2011-2012, The Linux Foundation. All rights reserved. |
Amol Jadi | cd43ea0 | 2011-02-15 20:56:04 -0800 | [diff] [blame] | 3 | * |
| 4 | * Redistribution and use in source and binary forms, with or without |
| 5 | * modification, are permitted provided that the following conditions |
| 6 | * are met: |
| 7 | * * Redistributions of source code must retain the above copyright |
| 8 | * notice, this list of conditions and the following disclaimer. |
| 9 | * * Redistributions in binary form must reproduce the above copyright |
| 10 | * notice, this list of conditions and the following disclaimer in |
| 11 | * the documentation and/or other materials provided with the |
| 12 | * distribution. |
| 13 | * * Neither the name of Google, Inc. nor the names of its contributors |
| 14 | * may be used to endorse or promote products derived from this |
| 15 | * software without specific prior written permission. |
| 16 | * |
| 17 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS |
| 18 | * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT |
| 19 | * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS |
| 20 | * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE |
| 21 | * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, |
| 22 | * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, |
| 23 | * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS |
| 24 | * OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED |
| 25 | * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, |
| 26 | * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT |
| 27 | * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF |
| 28 | * SUCH DAMAGE. |
| 29 | */ |
| 30 | |
| 31 | #include <debug.h> |
| 32 | #include <reg.h> |
| 33 | #include <platform/iomap.h> |
Amol Jadi | db1edb3 | 2011-07-18 14:24:46 -0700 | [diff] [blame] | 34 | #include <qgic.h> |
Amol Jadi | c52c8a3 | 2011-07-12 11:27:04 -0700 | [diff] [blame] | 35 | #include <uart_dm.h> |
Kinson Chik | e5c9343 | 2011-06-17 09:10:29 -0700 | [diff] [blame] | 36 | #include <dev/fbcon.h> |
Amol Jadi | da05574 | 2011-06-14 16:15:12 -0700 | [diff] [blame] | 37 | #include <mmu.h> |
| 38 | #include <arch/arm/mmu.h> |
Shashank Mittal | a635abf | 2012-03-28 18:11:43 -0700 | [diff] [blame] | 39 | #include <board.h> |
Amol Jadi | cd43ea0 | 2011-02-15 20:56:04 -0800 | [diff] [blame] | 40 | |
Amol Jadi | cd43ea0 | 2011-02-15 20:56:04 -0800 | [diff] [blame] | 41 | extern void platform_init_timer(void); |
Greg Grisco | 1073a5e | 2011-07-28 18:59:18 -0700 | [diff] [blame] | 42 | extern void platform_panel_backlight_on(void); |
| 43 | extern void platform_uninit_timer(void); |
Kinson Chik | e5c9343 | 2011-06-17 09:10:29 -0700 | [diff] [blame] | 44 | extern void mipi_panel_reset(void); |
| 45 | extern void mipi_dsi_panel_power_on(void); |
| 46 | extern void mdp_clock_init(void); |
| 47 | extern void mmss_clock_init(void); |
| 48 | extern struct fbcon_config *mipi_init(void); |
| 49 | extern void mipi_dsi_shutdown(void); |
Shashank Mittal | 3026290 | 2012-02-21 15:37:24 -0800 | [diff] [blame] | 50 | extern void msm_clocks_init(void); |
Amol Jadi | cd43ea0 | 2011-02-15 20:56:04 -0800 | [diff] [blame] | 51 | |
Amol Jadi | aeda4e6 | 2011-07-19 18:07:29 -0700 | [diff] [blame] | 52 | static uint32_t ticks_per_sec = 0; |
Shashank Mittal | e2ad876 | 2012-02-07 15:15:11 -0800 | [diff] [blame] | 53 | static uint8_t display_enabled = 0; |
Amol Jadi | aeda4e6 | 2011-07-19 18:07:29 -0700 | [diff] [blame] | 54 | |
Amol Jadi | da05574 | 2011-06-14 16:15:12 -0700 | [diff] [blame] | 55 | #define MB (1024*1024) |
| 56 | |
| 57 | #define MSM_IOMAP_SIZE ((MSM_IOMAP_END - MSM_IOMAP_BASE)/MB) |
| 58 | |
| 59 | /* LK memory - cacheable, write through */ |
| 60 | #define LK_MEMORY (MMU_MEMORY_TYPE_NORMAL_WRITE_THROUGH | \ |
| 61 | MMU_MEMORY_AP_READ_WRITE) |
| 62 | |
| 63 | /* Kernel region - cacheable, write through */ |
| 64 | #define KERNEL_MEMORY (MMU_MEMORY_TYPE_NORMAL_WRITE_THROUGH | \ |
Amol Jadi | 0228e9f | 2011-12-19 17:21:36 -0800 | [diff] [blame] | 65 | MMU_MEMORY_AP_READ_WRITE | MMU_MEMORY_XN) |
Amol Jadi | da05574 | 2011-06-14 16:15:12 -0700 | [diff] [blame] | 66 | |
| 67 | /* Scratch region - cacheable, write through */ |
| 68 | #define SCRATCH_MEMORY (MMU_MEMORY_TYPE_NORMAL_WRITE_THROUGH | \ |
Amol Jadi | 0228e9f | 2011-12-19 17:21:36 -0800 | [diff] [blame] | 69 | MMU_MEMORY_AP_READ_WRITE | MMU_MEMORY_XN) |
Amol Jadi | da05574 | 2011-06-14 16:15:12 -0700 | [diff] [blame] | 70 | |
| 71 | /* Peripherals - non-shared device */ |
| 72 | #define IOMAP_MEMORY (MMU_MEMORY_TYPE_DEVICE_NON_SHARED | \ |
Amol Jadi | 0228e9f | 2011-12-19 17:21:36 -0800 | [diff] [blame] | 73 | MMU_MEMORY_AP_READ_WRITE | MMU_MEMORY_XN) |
| 74 | |
| 75 | /* IMEM: Must set execute never bit to avoid instruction prefetch from TZ */ |
| 76 | #define IMEM_MEMORY (MMU_MEMORY_TYPE_STRONGLY_ORDERED | \ |
| 77 | MMU_MEMORY_AP_READ_WRITE | MMU_MEMORY_XN) |
Amol Jadi | da05574 | 2011-06-14 16:15:12 -0700 | [diff] [blame] | 78 | |
Amol Jadi | da05574 | 2011-06-14 16:15:12 -0700 | [diff] [blame] | 79 | mmu_section_t mmu_section_table[] = { |
| 80 | /* Physical addr, Virtual addr, Size (in MB), Flags */ |
Ajay Dudani | b01e506 | 2011-12-03 23:23:42 -0800 | [diff] [blame] | 81 | {MEMBASE, MEMBASE, (MEMSIZE / MB), LK_MEMORY}, |
| 82 | {BASE_ADDR, BASE_ADDR, 44, KERNEL_MEMORY}, |
Channagoud Kadabi | 7d84dd6 | 2012-08-24 21:20:56 +0530 | [diff] [blame] | 83 | {SCRATCH_ADDR, SCRATCH_ADDR, 768, SCRATCH_MEMORY}, |
Ajay Dudani | b01e506 | 2011-12-03 23:23:42 -0800 | [diff] [blame] | 84 | {MSM_IOMAP_BASE, MSM_IOMAP_BASE, MSM_IOMAP_SIZE, IOMAP_MEMORY}, |
Amol Jadi | 0228e9f | 2011-12-19 17:21:36 -0800 | [diff] [blame] | 85 | {MSM_IMEM_BASE, MSM_IMEM_BASE, 1, IMEM_MEMORY}, |
Amol Jadi | da05574 | 2011-06-14 16:15:12 -0700 | [diff] [blame] | 86 | }; |
| 87 | |
Amol Jadi | cd43ea0 | 2011-02-15 20:56:04 -0800 | [diff] [blame] | 88 | void platform_early_init(void) |
| 89 | { |
Shashank Mittal | 3026290 | 2012-02-21 15:37:24 -0800 | [diff] [blame] | 90 | msm_clocks_init(); |
Ajay Dudani | b01e506 | 2011-12-03 23:23:42 -0800 | [diff] [blame] | 91 | qgic_init(); |
| 92 | platform_init_timer(); |
Shashank Mittal | a635abf | 2012-03-28 18:11:43 -0700 | [diff] [blame] | 93 | board_init(); |
Amol Jadi | cd43ea0 | 2011-02-15 20:56:04 -0800 | [diff] [blame] | 94 | } |
| 95 | |
| 96 | void platform_init(void) |
| 97 | { |
Ajay Dudani | b01e506 | 2011-12-03 23:23:42 -0800 | [diff] [blame] | 98 | dprintf(INFO, "platform_init()\n"); |
Amol Jadi | cd43ea0 | 2011-02-15 20:56:04 -0800 | [diff] [blame] | 99 | } |
Kinson Chik | e5c9343 | 2011-06-17 09:10:29 -0700 | [diff] [blame] | 100 | |
Amol Jadi | 4421e65 | 2011-06-16 15:00:48 -0700 | [diff] [blame] | 101 | void platform_uninit(void) |
| 102 | { |
Amol Jadi | 4421e65 | 2011-06-16 15:00:48 -0700 | [diff] [blame] | 103 | #if DISPLAY_SPLASH_SCREEN |
| 104 | display_shutdown(); |
| 105 | #endif |
Shashank Mittal | ac23fa1 | 2012-02-13 17:38:15 -0800 | [diff] [blame] | 106 | |
Amol Jadi | d7cfc03 | 2012-01-09 16:56:08 -0800 | [diff] [blame] | 107 | platform_uninit_timer(); |
Amol Jadi | 4421e65 | 2011-06-16 15:00:48 -0700 | [diff] [blame] | 108 | } |
| 109 | |
Amol Jadi | da05574 | 2011-06-14 16:15:12 -0700 | [diff] [blame] | 110 | /* Setup memory for this platform */ |
| 111 | void platform_init_mmu_mappings(void) |
| 112 | { |
Ajay Dudani | b01e506 | 2011-12-03 23:23:42 -0800 | [diff] [blame] | 113 | uint32_t i; |
| 114 | uint32_t sections; |
| 115 | uint32_t table_size = ARRAY_SIZE(mmu_section_table); |
Amol Jadi | da05574 | 2011-06-14 16:15:12 -0700 | [diff] [blame] | 116 | |
Ajay Dudani | b01e506 | 2011-12-03 23:23:42 -0800 | [diff] [blame] | 117 | for (i = 0; i < table_size; i++) { |
| 118 | sections = mmu_section_table[i].num_of_sections; |
Amol Jadi | da05574 | 2011-06-14 16:15:12 -0700 | [diff] [blame] | 119 | |
Ajay Dudani | b01e506 | 2011-12-03 23:23:42 -0800 | [diff] [blame] | 120 | while (sections--) { |
| 121 | arm_mmu_map_section(mmu_section_table[i].paddress + |
| 122 | sections * MB, |
| 123 | mmu_section_table[i].vaddress + |
| 124 | sections * MB, |
| 125 | mmu_section_table[i].flags); |
| 126 | } |
| 127 | } |
Amol Jadi | da05574 | 2011-06-14 16:15:12 -0700 | [diff] [blame] | 128 | } |
Amol Jadi | aeda4e6 | 2011-07-19 18:07:29 -0700 | [diff] [blame] | 129 | |
| 130 | /* Initialize DGT timer */ |
| 131 | void platform_init_timer(void) |
| 132 | { |
| 133 | /* disable timer */ |
| 134 | writel(0, DGT_ENABLE); |
| 135 | |
| 136 | /* DGT uses LPXO source which is 27MHz. |
| 137 | * Set clock divider to 4. |
| 138 | */ |
| 139 | writel(3, DGT_CLK_CTL); |
| 140 | |
Ajay Dudani | b01e506 | 2011-12-03 23:23:42 -0800 | [diff] [blame] | 141 | ticks_per_sec = 6750000; /* (27 MHz / 4) */ |
Amol Jadi | aeda4e6 | 2011-07-19 18:07:29 -0700 | [diff] [blame] | 142 | } |
| 143 | |
| 144 | /* Returns timer ticks per sec */ |
| 145 | uint32_t platform_tick_rate(void) |
| 146 | { |
| 147 | return ticks_per_sec; |
| 148 | } |
Channagoud Kadabi | 80e776b | 2013-02-15 19:52:12 -0800 | [diff] [blame] | 149 | |
| 150 | /* Return true if the pmic type matches */ |
| 151 | uint8_t platform_pmic_type(uint32_t pmic_type) |
| 152 | { |
| 153 | uint8_t ret = 0; |
| 154 | uint8_t i = 0; |
| 155 | uint8_t num_ent = 0; |
| 156 | struct board_pmic_data pmic_info[SMEM_V7_SMEM_MAX_PMIC_DEVICES]; |
| 157 | |
| 158 | num_ent = board_pmic_info(&pmic_info, SMEM_V7_SMEM_MAX_PMIC_DEVICES); |
| 159 | |
| 160 | for(i = 0; i < num_ent; i++) { |
| 161 | if (pmic_info[i].pmic_type == pmic_type) { |
| 162 | ret = 1; |
| 163 | break; |
| 164 | } |
| 165 | } |
| 166 | |
| 167 | return ret; |
| 168 | } |