Amol Jadi | ca4f4c9 | 2011-01-13 20:19:34 -0800 | [diff] [blame] | 1 | /* |
| 2 | * Copyright (c) 2009, Google Inc. |
| 3 | * All rights reserved. |
| 4 | * Copyright (c) 2009-2011, Code Aurora Forum. All rights reserved. |
| 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 <lib/ptable.h> |
| 35 | #include <smem.h> |
| 36 | #include <platform/iomap.h> |
Greg Grisco | d625055 | 2011-06-29 14:40:23 -0700 | [diff] [blame] | 37 | #include <mmc.h> |
| 38 | #include <platform/timer.h> |
Amol Jadi | ca4f4c9 | 2011-01-13 20:19:34 -0800 | [diff] [blame] | 39 | #include <reg.h> |
Amol Jadi | 6db9fe3 | 2011-04-15 17:19:00 -0700 | [diff] [blame] | 40 | #include <dev/keys.h> |
Amol Jadi | 57abe4c | 2011-05-24 15:47:27 -0700 | [diff] [blame] | 41 | #include <dev/pm8921.h> |
Kinson Chik | ea64624 | 2011-09-01 13:53:16 -0700 | [diff] [blame] | 42 | #include <dev/ssbi.h> |
Amol Jadi | c52c8a3 | 2011-07-12 11:27:04 -0700 | [diff] [blame] | 43 | #include <gsbi.h> |
Greg Grisco | d2471ef | 2011-07-14 13:00:42 -0700 | [diff] [blame] | 44 | #include <target.h> |
Greg Grisco | 1073a5e | 2011-07-28 18:59:18 -0700 | [diff] [blame] | 45 | #include <platform.h> |
Amol Jadi | ca4f4c9 | 2011-01-13 20:19:34 -0800 | [diff] [blame] | 46 | |
| 47 | #define LINUX_MACHTYPE_8960_SIM 3230 |
| 48 | #define LINUX_MACHTYPE_8960_RUMI3 3231 |
Shashank Mittal | d67508a | 2011-05-06 19:18:42 -0700 | [diff] [blame] | 49 | #define LINUX_MACHTYPE_8960_CDP 3396 |
| 50 | #define LINUX_MACHTYPE_8960_MTP 3397 |
| 51 | #define LINUX_MACHTYPE_8960_FLUID 3398 |
| 52 | #define LINUX_MACHTYPE_8960_APQ 3399 |
Amir Samuelov | 6a9871b | 2011-07-31 14:38:05 +0300 | [diff] [blame] | 53 | #define LINUX_MACHTYPE_8960_LIQUID 3535 |
Ajay Dudani | 8decb50 | 2011-09-12 13:39:32 -0700 | [diff] [blame] | 54 | #define LINUX_MACHTYPE_8930_CDP 3727 |
| 55 | #define LINUX_MACHTYPE_8930_MTP 3728 |
| 56 | #define LINUX_MACHTYPE_8930_FLUID 3729 |
Greg Grisco | d2471ef | 2011-07-14 13:00:42 -0700 | [diff] [blame] | 57 | |
Amol Jadi | cd43ea0 | 2011-02-15 20:56:04 -0800 | [diff] [blame] | 58 | extern void dmb(void); |
Amol Jadi | 6db9fe3 | 2011-04-15 17:19:00 -0700 | [diff] [blame] | 59 | extern void keypad_init(void); |
Greg Grisco | d2471ef | 2011-07-14 13:00:42 -0700 | [diff] [blame] | 60 | extern void panel_backlight_on(void); |
Amol Jadi | cd43ea0 | 2011-02-15 20:56:04 -0800 | [diff] [blame] | 61 | |
Shashank Mittal | da89a68 | 2011-03-14 19:18:38 -0700 | [diff] [blame] | 62 | static unsigned mmc_sdc_base[] = { MSM_SDC1_BASE, MSM_SDC2_BASE, MSM_SDC3_BASE, MSM_SDC4_BASE}; |
| 63 | |
Amol Jadi | 57abe4c | 2011-05-24 15:47:27 -0700 | [diff] [blame] | 64 | static pm8921_dev_t pmic; |
| 65 | |
Amol Jadi | c52c8a3 | 2011-07-12 11:27:04 -0700 | [diff] [blame] | 66 | static const uint8_t uart_gsbi_id = GSBI_ID_5; |
| 67 | |
Shashank Mittal | 3950326 | 2011-07-19 11:41:35 -0700 | [diff] [blame] | 68 | void shutdown_device(void) |
| 69 | { |
| 70 | dprintf(CRITICAL, "Shutdown system.\n"); |
| 71 | pm8921_config_reset_pwr_off(0); |
| 72 | |
| 73 | /* Actually reset the chip */ |
| 74 | writel(0, MSM_PSHOLD_CTL_SU); |
| 75 | mdelay(5000); |
| 76 | |
| 77 | dprintf (CRITICAL, "Shutdown failed.\n"); |
| 78 | } |
| 79 | |
Amol Jadi | ca4f4c9 | 2011-01-13 20:19:34 -0800 | [diff] [blame] | 80 | void target_init(void) |
| 81 | { |
Shashank Mittal | da89a68 | 2011-03-14 19:18:38 -0700 | [diff] [blame] | 82 | unsigned base_addr; |
| 83 | unsigned char slot; |
Amol Jadi | ca4f4c9 | 2011-01-13 20:19:34 -0800 | [diff] [blame] | 84 | dprintf(INFO, "target_init()\n"); |
| 85 | |
Amol Jadi | 57abe4c | 2011-05-24 15:47:27 -0700 | [diff] [blame] | 86 | /* Initialize PMIC driver */ |
Greg Grisco | d2471ef | 2011-07-14 13:00:42 -0700 | [diff] [blame] | 87 | pmic.read = (pm8921_read_func) &pa1_ssbi2_read_bytes; |
| 88 | pmic.write = (pm8921_write_func) &pa1_ssbi2_write_bytes; |
Amol Jadi | 57abe4c | 2011-05-24 15:47:27 -0700 | [diff] [blame] | 89 | |
| 90 | pm8921_init(&pmic); |
Amol Jadi | 6db9fe3 | 2011-04-15 17:19:00 -0700 | [diff] [blame] | 91 | /* Keypad init */ |
| 92 | keys_init(); |
| 93 | keypad_init(); |
| 94 | |
Kinson Chik | ce306ff | 2011-07-08 15:23:33 -0700 | [diff] [blame] | 95 | /* Display splash screen if enabled */ |
| 96 | #if DISPLAY_SPLASH_SCREEN |
| 97 | panel_backlight_on(); |
| 98 | display_init(); |
| 99 | dprintf(SPEW, "Diplay initialized\n"); |
| 100 | display_image_on_screen(); |
| 101 | #endif |
| 102 | |
Shashank Mittal | da89a68 | 2011-03-14 19:18:38 -0700 | [diff] [blame] | 103 | /* Trying Slot 1 first */ |
| 104 | slot = 1; |
| 105 | base_addr = mmc_sdc_base[slot-1]; |
| 106 | if(mmc_boot_main(slot, base_addr)) |
Amol Jadi | ca4f4c9 | 2011-01-13 20:19:34 -0800 | [diff] [blame] | 107 | { |
Shashank Mittal | da89a68 | 2011-03-14 19:18:38 -0700 | [diff] [blame] | 108 | /* Trying Slot 3 next */ |
| 109 | slot = 3; |
| 110 | base_addr = mmc_sdc_base[slot-1]; |
| 111 | if(mmc_boot_main(slot, base_addr)) |
| 112 | { |
| 113 | dprintf(CRITICAL, "mmc init failed!"); |
| 114 | ASSERT(0); |
| 115 | } |
Amol Jadi | ca4f4c9 | 2011-01-13 20:19:34 -0800 | [diff] [blame] | 116 | } |
| 117 | } |
| 118 | |
| 119 | unsigned board_machtype(void) |
| 120 | { |
Shashank Mittal | da89a68 | 2011-03-14 19:18:38 -0700 | [diff] [blame] | 121 | struct smem_board_info_v6 board_info_v6; |
| 122 | unsigned int board_info_len = 0; |
| 123 | unsigned smem_status = 0; |
| 124 | unsigned format = 0; |
Amol Jadi | 64c58c1 | 2011-05-11 13:40:25 -0700 | [diff] [blame] | 125 | unsigned id = HW_PLATFORM_UNKNOWN; |
| 126 | unsigned mach_id; |
Amol Jadi | ca4f4c9 | 2011-01-13 20:19:34 -0800 | [diff] [blame] | 127 | |
Shashank Mittal | d67508a | 2011-05-06 19:18:42 -0700 | [diff] [blame] | 128 | |
Shashank Mittal | da89a68 | 2011-03-14 19:18:38 -0700 | [diff] [blame] | 129 | smem_status = smem_read_alloc_entry_offset(SMEM_BOARD_INFO_LOCATION, |
| 130 | &format, sizeof(format), 0); |
| 131 | if(!smem_status) |
| 132 | { |
Amol Jadi | 64c58c1 | 2011-05-11 13:40:25 -0700 | [diff] [blame] | 133 | if (format == 6) |
Shashank Mittal | da89a68 | 2011-03-14 19:18:38 -0700 | [diff] [blame] | 134 | { |
| 135 | board_info_len = sizeof(board_info_v6); |
| 136 | |
| 137 | smem_status = smem_read_alloc_entry(SMEM_BOARD_INFO_LOCATION, |
| 138 | &board_info_v6, board_info_len); |
| 139 | if(!smem_status) |
| 140 | { |
| 141 | id = board_info_v6.board_info_v3.hw_platform; |
| 142 | } |
| 143 | } |
| 144 | } |
| 145 | |
Amol Jadi | 64c58c1 | 2011-05-11 13:40:25 -0700 | [diff] [blame] | 146 | /* Detect the board we are running on */ |
Ajay Dudani | 8decb50 | 2011-09-12 13:39:32 -0700 | [diff] [blame] | 147 | if (board_info_v6.board_info_v3.msm_id == MSM8960) |
Shashank Mittal | da89a68 | 2011-03-14 19:18:38 -0700 | [diff] [blame] | 148 | { |
Ajay Dudani | 8decb50 | 2011-09-12 13:39:32 -0700 | [diff] [blame] | 149 | switch(id) |
| 150 | { |
| 151 | case HW_PLATFORM_SURF: |
| 152 | mach_id = LINUX_MACHTYPE_8960_CDP; |
| 153 | break; |
| 154 | case HW_PLATFORM_MTP: |
| 155 | mach_id = LINUX_MACHTYPE_8960_MTP; |
| 156 | break; |
| 157 | case HW_PLATFORM_FLUID: |
| 158 | mach_id = LINUX_MACHTYPE_8960_FLUID; |
| 159 | break; |
| 160 | case HW_PLATFORM_LIQUID: |
| 161 | mach_id = LINUX_MACHTYPE_8960_LIQUID; |
| 162 | break; |
| 163 | default: |
| 164 | mach_id = LINUX_MACHTYPE_8960_CDP; |
| 165 | } |
| 166 | } |
| 167 | else if (board_info_v6.board_info_v3.msm_id == MSM8930) |
| 168 | { |
| 169 | switch(id) |
| 170 | { |
| 171 | case HW_PLATFORM_SURF: |
| 172 | mach_id = LINUX_MACHTYPE_8930_CDP; |
| 173 | break; |
| 174 | case HW_PLATFORM_MTP: |
| 175 | mach_id = LINUX_MACHTYPE_8930_MTP; |
| 176 | break; |
| 177 | case HW_PLATFORM_FLUID: |
| 178 | mach_id = LINUX_MACHTYPE_8930_FLUID; |
| 179 | break; |
| 180 | default: |
| 181 | mach_id = LINUX_MACHTYPE_8930_CDP; |
| 182 | } |
| 183 | } |
Shashank Mittal | da89a68 | 2011-03-14 19:18:38 -0700 | [diff] [blame] | 184 | |
| 185 | return mach_id; |
Amol Jadi | ca4f4c9 | 2011-01-13 20:19:34 -0800 | [diff] [blame] | 186 | } |
| 187 | |
| 188 | void reboot_device(unsigned reboot_reason) |
| 189 | { |
Shashank Mittal | 6239b16 | 2011-06-28 17:59:33 -0700 | [diff] [blame] | 190 | /* Actually reset the chip */ |
Shashank Mittal | 3950326 | 2011-07-19 11:41:35 -0700 | [diff] [blame] | 191 | pm8921_config_reset_pwr_off(1); |
Shashank Mittal | 6239b16 | 2011-06-28 17:59:33 -0700 | [diff] [blame] | 192 | writel(0, MSM_PSHOLD_CTL_SU); |
Amol Jadi | ca4f4c9 | 2011-01-13 20:19:34 -0800 | [diff] [blame] | 193 | mdelay(10000); |
Shashank Mittal | 3950326 | 2011-07-19 11:41:35 -0700 | [diff] [blame] | 194 | |
Amol Jadi | ca4f4c9 | 2011-01-13 20:19:34 -0800 | [diff] [blame] | 195 | dprintf (CRITICAL, "Rebooting failed\n"); |
| 196 | return; |
| 197 | } |
| 198 | |
| 199 | unsigned check_reboot_mode(void) |
| 200 | { |
| 201 | unsigned restart_reason = 0; |
Amol Jadi | ca4f4c9 | 2011-01-13 20:19:34 -0800 | [diff] [blame] | 202 | |
| 203 | /* Read reboot reason and scrub it */ |
Shashank Mittal | 0207df7 | 2011-06-15 15:20:43 -0700 | [diff] [blame] | 204 | restart_reason = readl(RESTART_REASON_ADDR); |
| 205 | writel(0x00, RESTART_REASON_ADDR); |
Amol Jadi | ca4f4c9 | 2011-01-13 20:19:34 -0800 | [diff] [blame] | 206 | |
| 207 | return restart_reason; |
| 208 | } |
| 209 | |
Ajay Dudani | 12091e2 | 2011-05-06 17:13:23 -0700 | [diff] [blame] | 210 | void target_serialno(unsigned char *buf) |
| 211 | { |
| 212 | unsigned int serialno; |
| 213 | if(target_is_emmc_boot()) |
| 214 | { |
| 215 | serialno = mmc_get_psn(); |
Ajay Dudani | f63d02f | 2011-10-01 08:29:53 -0700 | [diff] [blame] | 216 | snprintf((char *) buf, 13, "%x", serialno); |
Ajay Dudani | 12091e2 | 2011-05-06 17:13:23 -0700 | [diff] [blame] | 217 | } |
| 218 | } |
| 219 | |
Amol Jadi | ca4f4c9 | 2011-01-13 20:19:34 -0800 | [diff] [blame] | 220 | void target_battery_charging_enable(unsigned enable, unsigned disconnect) |
| 221 | { |
| 222 | } |
Amol Jadi | 57abe4c | 2011-05-24 15:47:27 -0700 | [diff] [blame] | 223 | |
| 224 | /* Do any target specific intialization needed before entering fastboot mode */ |
| 225 | void target_fastboot_init(void) |
| 226 | { |
| 227 | /* Set the BOOT_DONE flag in PM8921 */ |
| 228 | pm8921_boot_done(); |
| 229 | } |
Amol Jadi | c52c8a3 | 2011-07-12 11:27:04 -0700 | [diff] [blame] | 230 | |
| 231 | uint8_t target_uart_gsbi(void) |
| 232 | { |
| 233 | return uart_gsbi_id; |
| 234 | } |