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 | 5b41178 | 2013-07-09 13:15:16 -0700 | [diff] [blame] | 57 | /* NANDc BAM pipe groups */ |
| 58 | #define DATA_PRODUCER_PIPE_GRP 0 |
| 59 | #define DATA_CONSUMER_PIPE_GRP 0 |
| 60 | #define CMD_PIPE_GRP 1 |
| 61 | |
Deepa Dinamani | e9ded13 | 2012-11-27 15:03:38 -0800 | [diff] [blame] | 62 | /* NANDc EE */ |
| 63 | #define QPIC_NAND_EE 0 |
| 64 | |
| 65 | /* NANDc max desc length. */ |
| 66 | #define QPIC_NAND_MAX_DESC_LEN 0x7FFF |
| 67 | |
Deepa Dinamani | 8e6b243 | 2012-10-17 17:12:44 -0700 | [diff] [blame] | 68 | #define LAST_NAND_PTN_LEN_PATTERN 0xFFFFFFFF |
| 69 | |
Deepa Dinamani | e4573be | 2012-08-03 16:32:29 -0700 | [diff] [blame] | 70 | struct qpic_nand_init_config config; |
Deepa Dinamani | 28c0ffe | 2012-09-24 11:45:21 -0700 | [diff] [blame] | 71 | |
| 72 | void update_ptable_names(void) |
| 73 | { |
| 74 | uint32_t ptn_index; |
| 75 | struct ptentry *ptentry_ptr = flash_ptable.parts; |
| 76 | struct ptentry *boot_ptn; |
| 77 | unsigned i; |
| 78 | uint32_t len; |
| 79 | |
| 80 | /* Change all names to lower case. */ |
| 81 | for (ptn_index = 0; ptn_index != (uint32_t)flash_ptable.count; ptn_index++) |
| 82 | { |
| 83 | len = strlen(ptentry_ptr[ptn_index].name); |
| 84 | |
| 85 | for (i = 0; i < len; i++) |
| 86 | { |
| 87 | if (isupper(ptentry_ptr[ptn_index].name[i])) |
| 88 | { |
| 89 | ptentry_ptr[ptn_index].name[i] = tolower(ptentry_ptr[ptn_index].name[i]); |
| 90 | } |
| 91 | } |
Deepa Dinamani | 8e6b243 | 2012-10-17 17:12:44 -0700 | [diff] [blame] | 92 | |
| 93 | /* SBL fills in the last partition length as 0xFFFFFFFF. |
| 94 | * Update the length field based on the number of blocks on the flash. |
| 95 | */ |
| 96 | if ((uint32_t)(ptentry_ptr[ptn_index].length) == LAST_NAND_PTN_LEN_PATTERN) |
| 97 | { |
| 98 | ptentry_ptr[ptn_index].length = flash_num_blocks() - ptentry_ptr[ptn_index].start; |
| 99 | } |
Deepa Dinamani | 28c0ffe | 2012-09-24 11:45:21 -0700 | [diff] [blame] | 100 | } |
| 101 | |
| 102 | /* Rename apps ptn to boot. */ |
| 103 | boot_ptn = ptable_find(&flash_ptable, "apps"); |
| 104 | strcpy(boot_ptn->name, "boot"); |
Deepa Dinamani | 2a52751 | 2012-10-09 15:19:29 -0700 | [diff] [blame] | 105 | |
| 106 | /* Rename appsbl ptn to aboot. */ |
| 107 | boot_ptn = ptable_find(&flash_ptable, "appsbl"); |
| 108 | strcpy(boot_ptn->name, "aboot"); |
Deepa Dinamani | 28c0ffe | 2012-09-24 11:45:21 -0700 | [diff] [blame] | 109 | } |
| 110 | |
Deepa Dinamani | dca5c66 | 2012-12-03 14:13:07 -0800 | [diff] [blame] | 111 | void target_early_init(void) |
| 112 | { |
| 113 | #if WITH_DEBUG_UART |
| 114 | uart_dm_init(3, 0, MSM_UART2_BASE); |
| 115 | #endif |
| 116 | } |
| 117 | |
| 118 | |
Amol Jadi | 42d7b5a | 2012-05-04 14:50:32 -0700 | [diff] [blame] | 119 | /* init */ |
| 120 | void target_init(void) |
| 121 | { |
| 122 | dprintf(INFO, "target_init()\n"); |
Deepa Dinamani | e4573be | 2012-08-03 16:32:29 -0700 | [diff] [blame] | 123 | |
Amol Jadi | 62d7bd2 | 2012-10-08 18:15:58 -0700 | [diff] [blame] | 124 | spmi_init(PMIC_ARB_CHANNEL_NUM, PMIC_ARB_OWNER_ID); |
| 125 | |
Deepa Dinamani | e4573be | 2012-08-03 16:32:29 -0700 | [diff] [blame] | 126 | config.pipes.read_pipe = DATA_PRODUCER_PIPE; |
| 127 | config.pipes.write_pipe = DATA_CONSUMER_PIPE; |
| 128 | config.pipes.cmd_pipe = CMD_PIPE; |
| 129 | |
Deepa Dinamani | 5b41178 | 2013-07-09 13:15:16 -0700 | [diff] [blame] | 130 | config.pipes.read_pipe_grp = DATA_PRODUCER_PIPE_GRP; |
| 131 | config.pipes.write_pipe_grp = DATA_CONSUMER_PIPE_GRP; |
| 132 | config.pipes.cmd_pipe_grp = CMD_PIPE_GRP; |
| 133 | |
Deepa Dinamani | e4573be | 2012-08-03 16:32:29 -0700 | [diff] [blame] | 134 | config.bam_base = MSM_NAND_BAM_BASE; |
| 135 | config.nand_base = MSM_NAND_BASE; |
Deepa Dinamani | e9ded13 | 2012-11-27 15:03:38 -0800 | [diff] [blame] | 136 | config.ee = QPIC_NAND_EE; |
| 137 | config.max_desc_len = QPIC_NAND_MAX_DESC_LEN; |
Deepa Dinamani | e4573be | 2012-08-03 16:32:29 -0700 | [diff] [blame] | 138 | |
| 139 | qpic_nand_init(&config); |
| 140 | |
Deepa Dinamani | e4573be | 2012-08-03 16:32:29 -0700 | [diff] [blame] | 141 | ptable_init(&flash_ptable); |
| 142 | |
Deepa Dinamani | 28c0ffe | 2012-09-24 11:45:21 -0700 | [diff] [blame] | 143 | smem_ptable_init(); |
Deepa Dinamani | e4573be | 2012-08-03 16:32:29 -0700 | [diff] [blame] | 144 | |
Deepa Dinamani | 28c0ffe | 2012-09-24 11:45:21 -0700 | [diff] [blame] | 145 | smem_add_modem_partitions(&flash_ptable); |
| 146 | |
| 147 | update_ptable_names(); |
| 148 | |
| 149 | flash_set_ptable(&flash_ptable); |
Amol Jadi | 42d7b5a | 2012-05-04 14:50:32 -0700 | [diff] [blame] | 150 | } |
| 151 | |
| 152 | /* reboot */ |
| 153 | void reboot_device(unsigned reboot_reason) |
| 154 | { |
Abhimanyu Kapur | 002ddf9 | 2013-01-28 17:13:13 -0800 | [diff] [blame] | 155 | uint32_t version = board_soc_version(); |
| 156 | |
Amol Jadi | 62d7bd2 | 2012-10-08 18:15:58 -0700 | [diff] [blame] | 157 | /* Write the reboot reason */ |
Abhimanyu Kapur | 002ddf9 | 2013-01-28 17:13:13 -0800 | [diff] [blame] | 158 | if(version >= 0x20000) |
| 159 | writel(reboot_reason, RESTART_REASON_ADDR_V2); |
| 160 | else |
| 161 | writel(reboot_reason, RESTART_REASON_ADDR); |
Amol Jadi | 62d7bd2 | 2012-10-08 18:15:58 -0700 | [diff] [blame] | 162 | |
| 163 | /* Configure PMIC for warm reset */ |
Deepa Dinamani | 65ac3f1 | 2013-03-11 13:42:10 -0700 | [diff] [blame] | 164 | /* PM 8019 v1 aligns with PM8941 v2. |
| 165 | * This call should be based on the pmic version |
| 166 | * when PM8019 v2 is available. |
| 167 | */ |
| 168 | pm8x41_v2_reset_configure(PON_PSHOLD_WARM_RESET); |
Amol Jadi | 62d7bd2 | 2012-10-08 18:15:58 -0700 | [diff] [blame] | 169 | |
| 170 | /* Drop PS_HOLD for MSM */ |
| 171 | writel(0x00, MPM2_MPM_PS_HOLD); |
| 172 | |
| 173 | mdelay(5000); |
| 174 | |
Amol Jadi | 42d7b5a | 2012-05-04 14:50:32 -0700 | [diff] [blame] | 175 | dprintf(CRITICAL, "Rebooting failed\n"); |
| 176 | return; |
| 177 | } |
| 178 | |
Amol Jadi | 42d7b5a | 2012-05-04 14:50:32 -0700 | [diff] [blame] | 179 | /* Identify the current target */ |
| 180 | void target_detect(struct board_data *board) |
| 181 | { |
Amol Jadi | c12c432 | 2012-10-08 17:24:35 -0700 | [diff] [blame] | 182 | /* Not used. set to unknown */ |
| 183 | board->target = LINUX_MACHTYPE_UNKNOWN; |
Amol Jadi | 42d7b5a | 2012-05-04 14:50:32 -0700 | [diff] [blame] | 184 | } |
| 185 | |
Deepa Dinamani | 28c0ffe | 2012-09-24 11:45:21 -0700 | [diff] [blame] | 186 | unsigned board_machtype(void) |
| 187 | { |
| 188 | return board_target_id(); |
| 189 | } |
| 190 | |
Amol Jadi | 42d7b5a | 2012-05-04 14:50:32 -0700 | [diff] [blame] | 191 | /* Identify the baseband being used */ |
| 192 | void target_baseband_detect(struct board_data *board) |
| 193 | { |
Deepa Dinamani | 28c0ffe | 2012-09-24 11:45:21 -0700 | [diff] [blame] | 194 | /* Check for baseband variants. Default to MSM */ |
Amol Jadi | c12c432 | 2012-10-08 17:24:35 -0700 | [diff] [blame] | 195 | if (board->platform_subtype == HW_PLATFORM_SUBTYPE_UNKNOWN) |
| 196 | { |
| 197 | board->baseband = BASEBAND_MSM; |
| 198 | } |
Deepa Dinamani | 28c0ffe | 2012-09-24 11:45:21 -0700 | [diff] [blame] | 199 | else |
| 200 | { |
Amol Jadi | c12c432 | 2012-10-08 17:24:35 -0700 | [diff] [blame] | 201 | dprintf(CRITICAL, "Could not identify baseband id (%d)\n", |
| 202 | board->platform_subtype); |
Deepa Dinamani | 28c0ffe | 2012-09-24 11:45:21 -0700 | [diff] [blame] | 203 | ASSERT(0); |
| 204 | } |
Amol Jadi | 42d7b5a | 2012-05-04 14:50:32 -0700 | [diff] [blame] | 205 | } |
Deepa Dinamani | 5684770 | 2012-11-12 16:16:58 -0800 | [diff] [blame] | 206 | |
| 207 | unsigned check_reboot_mode(void) |
| 208 | { |
| 209 | unsigned restart_reason = 0; |
Abhimanyu Kapur | 002ddf9 | 2013-01-28 17:13:13 -0800 | [diff] [blame] | 210 | uint32_t version = board_soc_version(); |
Deepa Dinamani | 5684770 | 2012-11-12 16:16:58 -0800 | [diff] [blame] | 211 | |
| 212 | /* Read reboot reason and scrub it */ |
Abhimanyu Kapur | 002ddf9 | 2013-01-28 17:13:13 -0800 | [diff] [blame] | 213 | if(version >= 0x20000) { |
| 214 | restart_reason = readl(RESTART_REASON_ADDR_V2); |
| 215 | writel(0x00, RESTART_REASON_ADDR_V2); |
| 216 | } |
| 217 | else { |
| 218 | restart_reason = readl(RESTART_REASON_ADDR); |
| 219 | writel(0x00, RESTART_REASON_ADDR); |
| 220 | } |
Deepa Dinamani | 5684770 | 2012-11-12 16:16:58 -0800 | [diff] [blame] | 221 | |
| 222 | return restart_reason; |
| 223 | } |
| 224 | |