Amol Jadi | cd43ea0 | 2011-02-15 20:56:04 -0800 | [diff] [blame] | 1 | /* |
| 2 | * Copyright (c) 2011, Code Aurora Forum. All rights reserved. |
| 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 | 10a3534 | 2011-12-05 19:01:22 -0800 | [diff] [blame] | 39 | #include <partition_parser.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); |
Amol Jadi | cd43ea0 | 2011-02-15 20:56:04 -0800 | [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 | da05574 | 2011-06-14 16:15:12 -0700 | [diff] [blame] | 53 | #define MB (1024*1024) |
| 54 | |
| 55 | #define MSM_IOMAP_SIZE ((MSM_IOMAP_END - MSM_IOMAP_BASE)/MB) |
| 56 | |
| 57 | /* LK memory - cacheable, write through */ |
| 58 | #define LK_MEMORY (MMU_MEMORY_TYPE_NORMAL_WRITE_THROUGH | \ |
| 59 | MMU_MEMORY_AP_READ_WRITE) |
| 60 | |
| 61 | /* Kernel region - cacheable, write through */ |
| 62 | #define KERNEL_MEMORY (MMU_MEMORY_TYPE_NORMAL_WRITE_THROUGH | \ |
Amol Jadi | 0228e9f | 2011-12-19 17:21:36 -0800 | [diff] [blame^] | 63 | MMU_MEMORY_AP_READ_WRITE | MMU_MEMORY_XN) |
Amol Jadi | da05574 | 2011-06-14 16:15:12 -0700 | [diff] [blame] | 64 | |
| 65 | /* Scratch region - cacheable, write through */ |
| 66 | #define SCRATCH_MEMORY (MMU_MEMORY_TYPE_NORMAL_WRITE_THROUGH | \ |
Amol Jadi | 0228e9f | 2011-12-19 17:21:36 -0800 | [diff] [blame^] | 67 | MMU_MEMORY_AP_READ_WRITE | MMU_MEMORY_XN) |
Amol Jadi | da05574 | 2011-06-14 16:15:12 -0700 | [diff] [blame] | 68 | |
| 69 | /* Peripherals - non-shared device */ |
| 70 | #define IOMAP_MEMORY (MMU_MEMORY_TYPE_DEVICE_NON_SHARED | \ |
Amol Jadi | 0228e9f | 2011-12-19 17:21:36 -0800 | [diff] [blame^] | 71 | MMU_MEMORY_AP_READ_WRITE | MMU_MEMORY_XN) |
| 72 | |
| 73 | /* IMEM: Must set execute never bit to avoid instruction prefetch from TZ */ |
| 74 | #define IMEM_MEMORY (MMU_MEMORY_TYPE_STRONGLY_ORDERED | \ |
| 75 | MMU_MEMORY_AP_READ_WRITE | MMU_MEMORY_XN) |
Amol Jadi | da05574 | 2011-06-14 16:15:12 -0700 | [diff] [blame] | 76 | |
Amol Jadi | da05574 | 2011-06-14 16:15:12 -0700 | [diff] [blame] | 77 | mmu_section_t mmu_section_table[] = { |
| 78 | /* Physical addr, Virtual addr, Size (in MB), Flags */ |
Ajay Dudani | b01e506 | 2011-12-03 23:23:42 -0800 | [diff] [blame] | 79 | {MEMBASE, MEMBASE, (MEMSIZE / MB), LK_MEMORY}, |
| 80 | {BASE_ADDR, BASE_ADDR, 44, KERNEL_MEMORY}, |
| 81 | {SCRATCH_ADDR, SCRATCH_ADDR, 128, SCRATCH_MEMORY}, |
| 82 | {MSM_IOMAP_BASE, MSM_IOMAP_BASE, MSM_IOMAP_SIZE, IOMAP_MEMORY}, |
Amol Jadi | 0228e9f | 2011-12-19 17:21:36 -0800 | [diff] [blame^] | 83 | {MSM_IMEM_BASE, MSM_IMEM_BASE, 1, IMEM_MEMORY}, |
Amol Jadi | da05574 | 2011-06-14 16:15:12 -0700 | [diff] [blame] | 84 | }; |
| 85 | |
Amol Jadi | cd43ea0 | 2011-02-15 20:56:04 -0800 | [diff] [blame] | 86 | void platform_early_init(void) |
| 87 | { |
Ajay Dudani | b01e506 | 2011-12-03 23:23:42 -0800 | [diff] [blame] | 88 | qgic_init(); |
| 89 | platform_init_timer(); |
Amol Jadi | cd43ea0 | 2011-02-15 20:56:04 -0800 | [diff] [blame] | 90 | } |
| 91 | |
| 92 | void platform_init(void) |
| 93 | { |
Ajay Dudani | b01e506 | 2011-12-03 23:23:42 -0800 | [diff] [blame] | 94 | dprintf(INFO, "platform_init()\n"); |
Amol Jadi | cd43ea0 | 2011-02-15 20:56:04 -0800 | [diff] [blame] | 95 | } |
Kinson Chik | e5c9343 | 2011-06-17 09:10:29 -0700 | [diff] [blame] | 96 | |
Ajay Dudani | b01e506 | 2011-12-03 23:23:42 -0800 | [diff] [blame] | 97 | void display_init(void) |
| 98 | { |
| 99 | struct fbcon_config *fb_cfg; |
Kinson Chik | e5c9343 | 2011-06-17 09:10:29 -0700 | [diff] [blame] | 100 | |
Ajay Dudani | b01e506 | 2011-12-03 23:23:42 -0800 | [diff] [blame] | 101 | panel_backlight_on(); |
Kinson Chik | c1ad946 | 2011-07-20 17:40:06 -0700 | [diff] [blame] | 102 | |
Ajay Dudani | b01e506 | 2011-12-03 23:23:42 -0800 | [diff] [blame] | 103 | mipi_dsi_panel_power_on(); |
| 104 | mipi_panel_reset(); |
Kinson Chik | e5c9343 | 2011-06-17 09:10:29 -0700 | [diff] [blame] | 105 | |
Ajay Dudani | b01e506 | 2011-12-03 23:23:42 -0800 | [diff] [blame] | 106 | mdp_clock_init(); |
| 107 | mmss_clock_init(); |
Kinson Chik | e5c9343 | 2011-06-17 09:10:29 -0700 | [diff] [blame] | 108 | |
Ajay Dudani | b01e506 | 2011-12-03 23:23:42 -0800 | [diff] [blame] | 109 | fb_cfg = mipi_init(); |
| 110 | fbcon_setup(fb_cfg); |
Kinson Chik | e5c9343 | 2011-06-17 09:10:29 -0700 | [diff] [blame] | 111 | } |
| 112 | |
| 113 | void display_shutdown(void) |
| 114 | { |
Ajay Dudani | b01e506 | 2011-12-03 23:23:42 -0800 | [diff] [blame] | 115 | mipi_dsi_shutdown(); |
Kinson Chik | e5c9343 | 2011-06-17 09:10:29 -0700 | [diff] [blame] | 116 | } |
Amol Jadi | 4421e65 | 2011-06-16 15:00:48 -0700 | [diff] [blame] | 117 | |
Shashank Mittal | 10a3534 | 2011-12-05 19:01:22 -0800 | [diff] [blame] | 118 | /* |
| 119 | * Write-protect partition list. |
| 120 | * |
| 121 | * Partition added in this list should have (size + padding) in multiple of |
| 122 | * mmc write protect group size. Otherwise this can end up write protecting |
| 123 | * some blocks from next partition. |
| 124 | */ |
| 125 | char *wp_list[] = {"fsg", NULL}; |
| 126 | |
| 127 | void platform_wp_paritition(void) |
| 128 | { |
| 129 | int count = 0; |
| 130 | while(wp_list[count] != NULL) |
| 131 | { |
| 132 | paritition_wp_by_name(wp_list[count]); |
| 133 | count++; |
| 134 | } |
| 135 | } |
| 136 | |
Amol Jadi | 4421e65 | 2011-06-16 15:00:48 -0700 | [diff] [blame] | 137 | void platform_uninit(void) |
| 138 | { |
Amol Jadi | 4421e65 | 2011-06-16 15:00:48 -0700 | [diff] [blame] | 139 | #if DISPLAY_SPLASH_SCREEN |
| 140 | display_shutdown(); |
| 141 | #endif |
Shashank Mittal | 10a3534 | 2011-12-05 19:01:22 -0800 | [diff] [blame] | 142 | platform_wp_paritition(); |
Amol Jadi | d7cfc03 | 2012-01-09 16:56:08 -0800 | [diff] [blame] | 143 | platform_uninit_timer(); |
Amol Jadi | 4421e65 | 2011-06-16 15:00:48 -0700 | [diff] [blame] | 144 | } |
| 145 | |
Amol Jadi | da05574 | 2011-06-14 16:15:12 -0700 | [diff] [blame] | 146 | /* Setup memory for this platform */ |
| 147 | void platform_init_mmu_mappings(void) |
| 148 | { |
Ajay Dudani | b01e506 | 2011-12-03 23:23:42 -0800 | [diff] [blame] | 149 | uint32_t i; |
| 150 | uint32_t sections; |
| 151 | uint32_t table_size = ARRAY_SIZE(mmu_section_table); |
Amol Jadi | da05574 | 2011-06-14 16:15:12 -0700 | [diff] [blame] | 152 | |
Ajay Dudani | b01e506 | 2011-12-03 23:23:42 -0800 | [diff] [blame] | 153 | for (i = 0; i < table_size; i++) { |
| 154 | sections = mmu_section_table[i].num_of_sections; |
Amol Jadi | da05574 | 2011-06-14 16:15:12 -0700 | [diff] [blame] | 155 | |
Ajay Dudani | b01e506 | 2011-12-03 23:23:42 -0800 | [diff] [blame] | 156 | while (sections--) { |
| 157 | arm_mmu_map_section(mmu_section_table[i].paddress + |
| 158 | sections * MB, |
| 159 | mmu_section_table[i].vaddress + |
| 160 | sections * MB, |
| 161 | mmu_section_table[i].flags); |
| 162 | } |
| 163 | } |
Amol Jadi | da05574 | 2011-06-14 16:15:12 -0700 | [diff] [blame] | 164 | } |
Amol Jadi | aeda4e6 | 2011-07-19 18:07:29 -0700 | [diff] [blame] | 165 | |
| 166 | /* Initialize DGT timer */ |
| 167 | void platform_init_timer(void) |
| 168 | { |
| 169 | /* disable timer */ |
| 170 | writel(0, DGT_ENABLE); |
| 171 | |
| 172 | /* DGT uses LPXO source which is 27MHz. |
| 173 | * Set clock divider to 4. |
| 174 | */ |
| 175 | writel(3, DGT_CLK_CTL); |
| 176 | |
Ajay Dudani | b01e506 | 2011-12-03 23:23:42 -0800 | [diff] [blame] | 177 | ticks_per_sec = 6750000; /* (27 MHz / 4) */ |
Amol Jadi | aeda4e6 | 2011-07-19 18:07:29 -0700 | [diff] [blame] | 178 | } |
| 179 | |
| 180 | /* Returns timer ticks per sec */ |
| 181 | uint32_t platform_tick_rate(void) |
| 182 | { |
| 183 | return ticks_per_sec; |
| 184 | } |
Shashank Mittal | 10a3534 | 2011-12-05 19:01:22 -0800 | [diff] [blame] | 185 | |