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> |
| 37 | #include <reg.h> |
Amol Jadi | 6db9fe3 | 2011-04-15 17:19:00 -0700 | [diff] [blame] | 38 | #include <dev/keys.h> |
Amol Jadi | ca4f4c9 | 2011-01-13 20:19:34 -0800 | [diff] [blame] | 39 | |
| 40 | #define LINUX_MACHTYPE_8960_SIM 3230 |
| 41 | #define LINUX_MACHTYPE_8960_RUMI3 3231 |
Shashank Mittal | d67508a | 2011-05-06 19:18:42 -0700 | [diff] [blame^] | 42 | #define LINUX_MACHTYPE_8960_CDP 3396 |
| 43 | #define LINUX_MACHTYPE_8960_MTP 3397 |
| 44 | #define LINUX_MACHTYPE_8960_FLUID 3398 |
| 45 | #define LINUX_MACHTYPE_8960_APQ 3399 |
Amol Jadi | ca4f4c9 | 2011-01-13 20:19:34 -0800 | [diff] [blame] | 46 | |
Amol Jadi | cd43ea0 | 2011-02-15 20:56:04 -0800 | [diff] [blame] | 47 | extern unsigned int mmc_boot_main(unsigned char slot, unsigned int base); |
| 48 | extern void mdelay(unsigned msecs); |
| 49 | extern void dmb(void); |
Amol Jadi | 6db9fe3 | 2011-04-15 17:19:00 -0700 | [diff] [blame] | 50 | extern void keypad_init(void); |
Amol Jadi | cd43ea0 | 2011-02-15 20:56:04 -0800 | [diff] [blame] | 51 | |
Shashank Mittal | da89a68 | 2011-03-14 19:18:38 -0700 | [diff] [blame] | 52 | static unsigned mmc_sdc_base[] = { MSM_SDC1_BASE, MSM_SDC2_BASE, MSM_SDC3_BASE, MSM_SDC4_BASE}; |
| 53 | |
Amol Jadi | ca4f4c9 | 2011-01-13 20:19:34 -0800 | [diff] [blame] | 54 | void target_init(void) |
| 55 | { |
Shashank Mittal | da89a68 | 2011-03-14 19:18:38 -0700 | [diff] [blame] | 56 | unsigned base_addr; |
| 57 | unsigned char slot; |
Amol Jadi | ca4f4c9 | 2011-01-13 20:19:34 -0800 | [diff] [blame] | 58 | dprintf(INFO, "target_init()\n"); |
| 59 | |
Amol Jadi | 6db9fe3 | 2011-04-15 17:19:00 -0700 | [diff] [blame] | 60 | /* Keypad init */ |
| 61 | keys_init(); |
| 62 | keypad_init(); |
| 63 | |
Shashank Mittal | da89a68 | 2011-03-14 19:18:38 -0700 | [diff] [blame] | 64 | /* Trying Slot 1 first */ |
| 65 | slot = 1; |
| 66 | base_addr = mmc_sdc_base[slot-1]; |
| 67 | if(mmc_boot_main(slot, base_addr)) |
Amol Jadi | ca4f4c9 | 2011-01-13 20:19:34 -0800 | [diff] [blame] | 68 | { |
Shashank Mittal | da89a68 | 2011-03-14 19:18:38 -0700 | [diff] [blame] | 69 | /* Trying Slot 3 next */ |
| 70 | slot = 3; |
| 71 | base_addr = mmc_sdc_base[slot-1]; |
| 72 | if(mmc_boot_main(slot, base_addr)) |
| 73 | { |
| 74 | dprintf(CRITICAL, "mmc init failed!"); |
| 75 | ASSERT(0); |
| 76 | } |
Amol Jadi | ca4f4c9 | 2011-01-13 20:19:34 -0800 | [diff] [blame] | 77 | } |
| 78 | } |
| 79 | |
| 80 | unsigned board_machtype(void) |
| 81 | { |
Shashank Mittal | da89a68 | 2011-03-14 19:18:38 -0700 | [diff] [blame] | 82 | struct smem_board_info_v5 board_info_v5; |
| 83 | struct smem_board_info_v6 board_info_v6; |
| 84 | unsigned int board_info_len = 0; |
| 85 | unsigned smem_status = 0; |
| 86 | unsigned format = 0; |
| 87 | unsigned id = 0; |
| 88 | unsigned mach_id = LINUX_MACHTYPE_8960_RUMI3; |
Amol Jadi | ca4f4c9 | 2011-01-13 20:19:34 -0800 | [diff] [blame] | 89 | |
Shashank Mittal | d67508a | 2011-05-06 19:18:42 -0700 | [diff] [blame^] | 90 | /* Until the bootchain is in, return CDP id. */ |
| 91 | return LINUX_MACHTYPE_8960_CDP; |
| 92 | |
Shashank Mittal | da89a68 | 2011-03-14 19:18:38 -0700 | [diff] [blame] | 93 | smem_status = smem_read_alloc_entry_offset(SMEM_BOARD_INFO_LOCATION, |
| 94 | &format, sizeof(format), 0); |
| 95 | if(!smem_status) |
| 96 | { |
| 97 | if (format == 5) |
| 98 | { |
| 99 | board_info_len = sizeof(board_info_v5); |
| 100 | |
| 101 | smem_status = smem_read_alloc_entry(SMEM_BOARD_INFO_LOCATION, |
| 102 | &board_info_v5, board_info_len); |
| 103 | if(!smem_status) |
| 104 | { |
| 105 | id = board_info_v5.board_info_v3.hw_platform; |
| 106 | } |
| 107 | } |
| 108 | else if (format == 6) |
| 109 | { |
| 110 | board_info_len = sizeof(board_info_v6); |
| 111 | |
| 112 | smem_status = smem_read_alloc_entry(SMEM_BOARD_INFO_LOCATION, |
| 113 | &board_info_v6, board_info_len); |
| 114 | if(!smem_status) |
| 115 | { |
| 116 | id = board_info_v6.board_info_v3.hw_platform; |
| 117 | } |
| 118 | } |
| 119 | } |
| 120 | |
| 121 | /* Detect virtio vs rumi */ |
| 122 | switch(id) |
| 123 | { |
| 124 | case HW_PLATFORM_SURF: |
| 125 | mach_id = LINUX_MACHTYPE_8960_RUMI3; |
| 126 | break; |
| 127 | case HW_PLATFORM_FFA: |
| 128 | mach_id = LINUX_MACHTYPE_8960_SIM; |
| 129 | break; |
| 130 | default: |
| 131 | mach_id = LINUX_MACHTYPE_8960_SIM; |
| 132 | }; |
| 133 | |
| 134 | return mach_id; |
Amol Jadi | ca4f4c9 | 2011-01-13 20:19:34 -0800 | [diff] [blame] | 135 | } |
| 136 | |
| 137 | void reboot_device(unsigned reboot_reason) |
| 138 | { |
| 139 | /* Reset WDG0 counter */ |
| 140 | writel(1,MSM_WDT0_RST); |
| 141 | /* Disable WDG0 */ |
| 142 | writel(0,MSM_WDT0_EN); |
| 143 | /* Set WDG0 bark time */ |
| 144 | writel(0x31F3,MSM_WDT0_BT); |
| 145 | /* Enable WDG0 */ |
| 146 | writel(3,MSM_WDT0_EN); |
| 147 | dmb(); |
| 148 | /* Enable WDG output */ |
| 149 | writel(3,MSM_TCSR_BASE + TCSR_WDOG_CFG); |
| 150 | mdelay(10000); |
| 151 | dprintf (CRITICAL, "Rebooting failed\n"); |
| 152 | return; |
| 153 | } |
| 154 | |
| 155 | unsigned check_reboot_mode(void) |
| 156 | { |
| 157 | unsigned restart_reason = 0; |
Amol Jadi | cd43ea0 | 2011-02-15 20:56:04 -0800 | [diff] [blame] | 158 | void *restart_reason_addr = (void*)0x401FFFFC; |
Amol Jadi | ca4f4c9 | 2011-01-13 20:19:34 -0800 | [diff] [blame] | 159 | |
| 160 | /* Read reboot reason and scrub it */ |
| 161 | restart_reason = readl(restart_reason_addr); |
| 162 | writel(0x00, restart_reason_addr); |
| 163 | |
| 164 | return restart_reason; |
| 165 | } |
| 166 | |
| 167 | void target_battery_charging_enable(unsigned enable, unsigned disconnect) |
| 168 | { |
| 169 | } |