Abhimanyu Kapur | 002ddf9 | 2013-01-28 17:13:13 -0800 | [diff] [blame] | 1 | /* Copyright (c) 2012-2013, The Linux Foundation. All rights reserved. |
Amol Jadi | 42d7b5a | 2012-05-04 14:50:32 -0700 | [diff] [blame] | 2 | * |
| 3 | * Redistribution and use in source and binary forms, with or without |
| 4 | * modification, are permitted provided that the following conditions are |
| 5 | * met: |
| 6 | * * Redistributions of source code must retain the above copyright |
| 7 | * notice, this list of conditions and the following disclaimer. |
| 8 | * * Redistributions in binary form must reproduce the above |
| 9 | * copyright notice, this list of conditions and the following |
| 10 | * disclaimer in the documentation and/or other materials provided |
| 11 | * with the distribution. |
Deepa Dinamani | 28c0ffe | 2012-09-24 11:45:21 -0700 | [diff] [blame] | 12 | * * Neither the name of The Linux Foundation nor the names of its |
Amol Jadi | 42d7b5a | 2012-05-04 14:50:32 -0700 | [diff] [blame] | 13 | * contributors may be used to endorse or promote products derived |
| 14 | * from this software without specific prior written permission. |
| 15 | * |
| 16 | * THIS SOFTWARE IS PROVIDED "AS IS" AND ANY EXPRESS OR IMPLIED |
| 17 | * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF |
| 18 | * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT |
| 19 | * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS |
| 20 | * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR |
| 21 | * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF |
| 22 | * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR |
| 23 | * BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, |
| 24 | * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE |
| 25 | * OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN |
| 26 | * IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
| 27 | */ |
Deepa Dinamani | 28c0ffe | 2012-09-24 11:45:21 -0700 | [diff] [blame] | 28 | |
Amol Jadi | 42d7b5a | 2012-05-04 14:50:32 -0700 | [diff] [blame] | 29 | #include <debug.h> |
| 30 | #include <board.h> |
| 31 | #include <platform.h> |
| 32 | #include <target.h> |
| 33 | #include <smem.h> |
| 34 | #include <baseband.h> |
Deepa Dinamani | e4573be | 2012-08-03 16:32:29 -0700 | [diff] [blame] | 35 | #include <lib/ptable.h> |
| 36 | #include <qpic_nand.h> |
Deepa Dinamani | 28c0ffe | 2012-09-24 11:45:21 -0700 | [diff] [blame] | 37 | #include <ctype.h> |
| 38 | #include <string.h> |
Amol Jadi | 62d7bd2 | 2012-10-08 18:15:58 -0700 | [diff] [blame] | 39 | #include <pm8x41.h> |
| 40 | #include <reg.h> |
| 41 | #include <platform/timer.h> |
Deepa Dinamani | 28c0ffe | 2012-09-24 11:45:21 -0700 | [diff] [blame] | 42 | |
| 43 | extern void smem_ptable_init(void); |
| 44 | extern void smem_add_modem_partitions(struct ptable *flash_ptable); |
Amol Jadi | 42d7b5a | 2012-05-04 14:50:32 -0700 | [diff] [blame] | 45 | |
Deepa Dinamani | e4573be | 2012-08-03 16:32:29 -0700 | [diff] [blame] | 46 | static struct ptable flash_ptable; |
| 47 | |
Amol Jadi | 62d7bd2 | 2012-10-08 18:15:58 -0700 | [diff] [blame] | 48 | /* PMIC config data */ |
Deepa Dinamani | e9ded13 | 2012-11-27 15:03:38 -0800 | [diff] [blame] | 49 | #define PMIC_ARB_CHANNEL_NUM 0 |
| 50 | #define PMIC_ARB_OWNER_ID 0 |
Amol Jadi | 62d7bd2 | 2012-10-08 18:15:58 -0700 | [diff] [blame] | 51 | |
Deepa Dinamani | e4573be | 2012-08-03 16:32:29 -0700 | [diff] [blame] | 52 | /* NANDc BAM pipe numbers */ |
| 53 | #define DATA_CONSUMER_PIPE 0 |
| 54 | #define DATA_PRODUCER_PIPE 1 |
| 55 | #define CMD_PIPE 2 |
| 56 | |
Deepa Dinamani | e9ded13 | 2012-11-27 15:03:38 -0800 | [diff] [blame] | 57 | /* NANDc EE */ |
| 58 | #define QPIC_NAND_EE 0 |
| 59 | |
| 60 | /* NANDc max desc length. */ |
| 61 | #define QPIC_NAND_MAX_DESC_LEN 0x7FFF |
| 62 | |
Deepa Dinamani | 8e6b243 | 2012-10-17 17:12:44 -0700 | [diff] [blame] | 63 | #define LAST_NAND_PTN_LEN_PATTERN 0xFFFFFFFF |
| 64 | |
Deepa Dinamani | e4573be | 2012-08-03 16:32:29 -0700 | [diff] [blame] | 65 | struct qpic_nand_init_config config; |
Deepa Dinamani | 28c0ffe | 2012-09-24 11:45:21 -0700 | [diff] [blame] | 66 | |
| 67 | void update_ptable_names(void) |
| 68 | { |
| 69 | uint32_t ptn_index; |
| 70 | struct ptentry *ptentry_ptr = flash_ptable.parts; |
| 71 | struct ptentry *boot_ptn; |
| 72 | unsigned i; |
| 73 | uint32_t len; |
| 74 | |
| 75 | /* Change all names to lower case. */ |
| 76 | for (ptn_index = 0; ptn_index != (uint32_t)flash_ptable.count; ptn_index++) |
| 77 | { |
| 78 | len = strlen(ptentry_ptr[ptn_index].name); |
| 79 | |
| 80 | for (i = 0; i < len; i++) |
| 81 | { |
| 82 | if (isupper(ptentry_ptr[ptn_index].name[i])) |
| 83 | { |
| 84 | ptentry_ptr[ptn_index].name[i] = tolower(ptentry_ptr[ptn_index].name[i]); |
| 85 | } |
| 86 | } |
Deepa Dinamani | 8e6b243 | 2012-10-17 17:12:44 -0700 | [diff] [blame] | 87 | |
| 88 | /* SBL fills in the last partition length as 0xFFFFFFFF. |
| 89 | * Update the length field based on the number of blocks on the flash. |
| 90 | */ |
| 91 | if ((uint32_t)(ptentry_ptr[ptn_index].length) == LAST_NAND_PTN_LEN_PATTERN) |
| 92 | { |
| 93 | ptentry_ptr[ptn_index].length = flash_num_blocks() - ptentry_ptr[ptn_index].start; |
| 94 | } |
Deepa Dinamani | 28c0ffe | 2012-09-24 11:45:21 -0700 | [diff] [blame] | 95 | } |
| 96 | |
| 97 | /* Rename apps ptn to boot. */ |
| 98 | boot_ptn = ptable_find(&flash_ptable, "apps"); |
| 99 | strcpy(boot_ptn->name, "boot"); |
Deepa Dinamani | 2a52751 | 2012-10-09 15:19:29 -0700 | [diff] [blame] | 100 | |
| 101 | /* Rename appsbl ptn to aboot. */ |
| 102 | boot_ptn = ptable_find(&flash_ptable, "appsbl"); |
| 103 | strcpy(boot_ptn->name, "aboot"); |
Deepa Dinamani | 28c0ffe | 2012-09-24 11:45:21 -0700 | [diff] [blame] | 104 | } |
| 105 | |
Deepa Dinamani | dca5c66 | 2012-12-03 14:13:07 -0800 | [diff] [blame] | 106 | void target_early_init(void) |
| 107 | { |
| 108 | #if WITH_DEBUG_UART |
| 109 | uart_dm_init(3, 0, MSM_UART2_BASE); |
| 110 | #endif |
| 111 | } |
| 112 | |
| 113 | |
Amol Jadi | 42d7b5a | 2012-05-04 14:50:32 -0700 | [diff] [blame] | 114 | /* init */ |
| 115 | void target_init(void) |
| 116 | { |
| 117 | dprintf(INFO, "target_init()\n"); |
Deepa Dinamani | e4573be | 2012-08-03 16:32:29 -0700 | [diff] [blame] | 118 | |
Amol Jadi | 62d7bd2 | 2012-10-08 18:15:58 -0700 | [diff] [blame] | 119 | spmi_init(PMIC_ARB_CHANNEL_NUM, PMIC_ARB_OWNER_ID); |
| 120 | |
Deepa Dinamani | e4573be | 2012-08-03 16:32:29 -0700 | [diff] [blame] | 121 | config.pipes.read_pipe = DATA_PRODUCER_PIPE; |
| 122 | config.pipes.write_pipe = DATA_CONSUMER_PIPE; |
| 123 | config.pipes.cmd_pipe = CMD_PIPE; |
| 124 | |
| 125 | config.bam_base = MSM_NAND_BAM_BASE; |
| 126 | config.nand_base = MSM_NAND_BASE; |
Deepa Dinamani | e9ded13 | 2012-11-27 15:03:38 -0800 | [diff] [blame] | 127 | config.ee = QPIC_NAND_EE; |
| 128 | config.max_desc_len = QPIC_NAND_MAX_DESC_LEN; |
Deepa Dinamani | e4573be | 2012-08-03 16:32:29 -0700 | [diff] [blame] | 129 | |
| 130 | qpic_nand_init(&config); |
| 131 | |
Deepa Dinamani | e4573be | 2012-08-03 16:32:29 -0700 | [diff] [blame] | 132 | ptable_init(&flash_ptable); |
| 133 | |
Deepa Dinamani | 28c0ffe | 2012-09-24 11:45:21 -0700 | [diff] [blame] | 134 | smem_ptable_init(); |
Deepa Dinamani | e4573be | 2012-08-03 16:32:29 -0700 | [diff] [blame] | 135 | |
Deepa Dinamani | 28c0ffe | 2012-09-24 11:45:21 -0700 | [diff] [blame] | 136 | smem_add_modem_partitions(&flash_ptable); |
| 137 | |
| 138 | update_ptable_names(); |
| 139 | |
| 140 | flash_set_ptable(&flash_ptable); |
Amol Jadi | 42d7b5a | 2012-05-04 14:50:32 -0700 | [diff] [blame] | 141 | } |
| 142 | |
| 143 | /* reboot */ |
| 144 | void reboot_device(unsigned reboot_reason) |
| 145 | { |
Abhimanyu Kapur | 002ddf9 | 2013-01-28 17:13:13 -0800 | [diff] [blame] | 146 | uint32_t version = board_soc_version(); |
| 147 | |
Amol Jadi | 62d7bd2 | 2012-10-08 18:15:58 -0700 | [diff] [blame] | 148 | /* Write the reboot reason */ |
Abhimanyu Kapur | 002ddf9 | 2013-01-28 17:13:13 -0800 | [diff] [blame] | 149 | if(version >= 0x20000) |
| 150 | writel(reboot_reason, RESTART_REASON_ADDR_V2); |
| 151 | else |
| 152 | writel(reboot_reason, RESTART_REASON_ADDR); |
Amol Jadi | 62d7bd2 | 2012-10-08 18:15:58 -0700 | [diff] [blame] | 153 | |
| 154 | /* Configure PMIC for warm reset */ |
| 155 | pm8x41_reset_configure(PON_PSHOLD_WARM_RESET); |
| 156 | |
| 157 | /* Drop PS_HOLD for MSM */ |
| 158 | writel(0x00, MPM2_MPM_PS_HOLD); |
| 159 | |
| 160 | mdelay(5000); |
| 161 | |
Amol Jadi | 42d7b5a | 2012-05-04 14:50:32 -0700 | [diff] [blame] | 162 | dprintf(CRITICAL, "Rebooting failed\n"); |
| 163 | return; |
| 164 | } |
| 165 | |
Amol Jadi | 42d7b5a | 2012-05-04 14:50:32 -0700 | [diff] [blame] | 166 | /* Identify the current target */ |
| 167 | void target_detect(struct board_data *board) |
| 168 | { |
Amol Jadi | c12c432 | 2012-10-08 17:24:35 -0700 | [diff] [blame] | 169 | /* Not used. set to unknown */ |
| 170 | board->target = LINUX_MACHTYPE_UNKNOWN; |
Amol Jadi | 42d7b5a | 2012-05-04 14:50:32 -0700 | [diff] [blame] | 171 | } |
| 172 | |
Deepa Dinamani | 28c0ffe | 2012-09-24 11:45:21 -0700 | [diff] [blame] | 173 | unsigned board_machtype(void) |
| 174 | { |
| 175 | return board_target_id(); |
| 176 | } |
| 177 | |
Amol Jadi | 42d7b5a | 2012-05-04 14:50:32 -0700 | [diff] [blame] | 178 | /* Identify the baseband being used */ |
| 179 | void target_baseband_detect(struct board_data *board) |
| 180 | { |
Deepa Dinamani | 28c0ffe | 2012-09-24 11:45:21 -0700 | [diff] [blame] | 181 | /* Check for baseband variants. Default to MSM */ |
Amol Jadi | c12c432 | 2012-10-08 17:24:35 -0700 | [diff] [blame] | 182 | if (board->platform_subtype == HW_PLATFORM_SUBTYPE_UNKNOWN) |
| 183 | { |
| 184 | board->baseband = BASEBAND_MSM; |
| 185 | } |
Deepa Dinamani | 28c0ffe | 2012-09-24 11:45:21 -0700 | [diff] [blame] | 186 | else |
| 187 | { |
Amol Jadi | c12c432 | 2012-10-08 17:24:35 -0700 | [diff] [blame] | 188 | dprintf(CRITICAL, "Could not identify baseband id (%d)\n", |
| 189 | board->platform_subtype); |
Deepa Dinamani | 28c0ffe | 2012-09-24 11:45:21 -0700 | [diff] [blame] | 190 | ASSERT(0); |
| 191 | } |
Amol Jadi | 42d7b5a | 2012-05-04 14:50:32 -0700 | [diff] [blame] | 192 | } |
Deepa Dinamani | 5684770 | 2012-11-12 16:16:58 -0800 | [diff] [blame] | 193 | |
| 194 | unsigned check_reboot_mode(void) |
| 195 | { |
| 196 | unsigned restart_reason = 0; |
Abhimanyu Kapur | 002ddf9 | 2013-01-28 17:13:13 -0800 | [diff] [blame] | 197 | uint32_t version = board_soc_version(); |
Deepa Dinamani | 5684770 | 2012-11-12 16:16:58 -0800 | [diff] [blame] | 198 | |
| 199 | /* Read reboot reason and scrub it */ |
Abhimanyu Kapur | 002ddf9 | 2013-01-28 17:13:13 -0800 | [diff] [blame] | 200 | if(version >= 0x20000) { |
| 201 | restart_reason = readl(RESTART_REASON_ADDR_V2); |
| 202 | writel(0x00, RESTART_REASON_ADDR_V2); |
| 203 | } |
| 204 | else { |
| 205 | restart_reason = readl(RESTART_REASON_ADDR); |
| 206 | writel(0x00, RESTART_REASON_ADDR); |
| 207 | } |
Deepa Dinamani | 5684770 | 2012-11-12 16:16:58 -0800 | [diff] [blame] | 208 | |
| 209 | return restart_reason; |
| 210 | } |
| 211 | |