blob: 7985a15c660f01900ad30bc67fed808dcee69978 [file] [log] [blame]
Kinson Chik18e36332011-08-15 10:07:28 -07001/*
2 * Copyright (c) 2009, Google Inc.
3 * All rights reserved.
4 *
5 * Copyright (c) 2009-2011, Code Aurora Forum. All rights reserved.
6 *
7 * Redistribution and use in source and binary forms, with or without
8 * modification, are permitted provided that the following conditions
9 * are met:
10 * * Redistributions of source code must retain the above copyright
11 * notice, this list of conditions and the following disclaimer.
12 * * Redistributions in binary form must reproduce the above copyright
13 * notice, this list of conditions and the following disclaimer in
14 * the documentation and/or other materials provided with the
15 * distribution.
16 * * Neither the name of Google, Inc. nor the names of its contributors
17 * may be used to endorse or promote products derived from this
18 * software without specific prior written permission.
19 *
20 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
21 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
22 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
23 * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
24 * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
25 * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
26 * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS
27 * OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
28 * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
29 * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
30 * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
31 * SUCH DAMAGE.
32 */
33
34#include <reg.h>
35#include <debug.h>
36#include <lib/ptable.h>
37#include <dev/flash.h>
Kinson Chik53f8d322011-08-30 13:39:38 -070038#include <dev/pm8921.h>
39#include <dev/ssbi.h>
Kinson Chik175e8472011-09-06 17:01:26 -070040#include <string.h>
Kinson Chik18e36332011-08-15 10:07:28 -070041#include <smem.h>
42#include <gsbi.h>
43#include <platform/iomap.h>
44#include <platform.h>
45
46#define MDM9X15_CDP 3675
47#define MDM9X15_MTP 3681
48#define LINUX_MACHTYPE MDM9X15_CDP
49
Kinson Chik18e36332011-08-15 10:07:28 -070050static struct ptable flash_ptable;
51unsigned hw_platform = 0;
52unsigned target_msm_id = 0;
53
Kinson Chik175e8472011-09-06 17:01:26 -070054/* Partition names for fastboot flash */
Deepa Dinamani13e32c42012-03-12 14:34:17 -070055char *apps_ptn_names[] = { "aboot", "boot", "cache", "misc", "recovery", "fota",
56 "recoveryfs", "system", "userdata" };
Ajay Dudanib01e5062011-12-03 23:23:42 -080057
Kinson Chik175e8472011-09-06 17:01:26 -070058/* Partitions should be in this order */
Deepa Dinamani13e32c42012-03-12 14:34:17 -070059char *ptable_ptn_names[] = { "APPSBL", "APPS", "CACHE", "MISC", "RECOVERY",
60 "FOTA", "RECOVERYFS", "SYSTEM", "USERDATA" };
Ajay Dudanib01e5062011-12-03 23:23:42 -080061
Deepa Dinamani13e32c42012-03-12 14:34:17 -070062unsigned ptn_name_count = 9;
63
64/* Apps partition flags to detect the presence of FOTA partitions.
65 * Initially, assume that the FOTA partitions are absent.
66 */
67unsigned int apps_ptn_flag[] = {1, 1, 0, 0, 0, 0, 0, 1, 1};
68
Deepa Dinamani76f91492011-12-12 13:19:40 -080069unsigned modem_ptn_count = 6;
Kinson Chik175e8472011-09-06 17:01:26 -070070
Kinson Chik18e36332011-08-15 10:07:28 -070071static const uint8_t uart_gsbi_id = GSBI_ID_4;
72
Kinson Chik53f8d322011-08-30 13:39:38 -070073static pm8921_dev_t pmic;
74
Kinson Chik18e36332011-08-15 10:07:28 -070075void smem_ptable_init(void);
Kinson Chik18e36332011-08-15 10:07:28 -070076extern void reboot(unsigned reboot_reason);
Kinson Chik175e8472011-09-06 17:01:26 -070077void update_ptable_apps_partitions(void);
78void update_ptable_modem_partitions(void);
Kinson Chik0b1c8162011-08-31 16:31:57 -070079extern int fake_key_get_state(void);
Kinson Chik18e36332011-08-15 10:07:28 -070080
81void target_init(void)
82{
Kinson Chik18e36332011-08-15 10:07:28 -070083 struct flash_info *flash_info;
Kinson Chik18e36332011-08-15 10:07:28 -070084
85 dprintf(INFO, "target_init()\n");
Kinson Chik53f8d322011-08-30 13:39:38 -070086
87 /* Initialize PMIC driver */
Ajay Dudanib01e5062011-12-03 23:23:42 -080088 pmic.read = (pm8921_read_func) & pa1_ssbi2_read_bytes;
89 pmic.write = (pm8921_write_func) & pa1_ssbi2_write_bytes;
Kinson Chik53f8d322011-08-30 13:39:38 -070090
91 pm8921_init(&pmic);
92
Kinson Chik18e36332011-08-15 10:07:28 -070093 ptable_init(&flash_ptable);
94 smem_ptable_init();
95
96 flash_init();
97 flash_info = flash_get_info();
98 ASSERT(flash_info);
99
Kinson Chik18e36332011-08-15 10:07:28 -0700100 smem_add_modem_partitions(&flash_ptable);
101
Kinson Chik175e8472011-09-06 17:01:26 -0700102 /* Update the naming for apps partitions and type */
103 update_ptable_apps_partitions();
104
105 /* Update modem partitions to lower case for fastboot */
106 update_ptable_modem_partitions();
107
Kinson Chik18e36332011-08-15 10:07:28 -0700108 ptable_dump(&flash_ptable);
109 flash_set_ptable(&flash_ptable);
110}
111
Deepa Dinamani0e372682011-12-19 17:09:00 -0800112unsigned check_reboot_mode(void)
113{
114 unsigned restart_reason = 0;
115
116 /* Read reboot reason and scrub it */
117 restart_reason = readl(RESTART_REASON_ADDR);
118 writel(0x00, RESTART_REASON_ADDR);
119
120 return restart_reason;
121}
122
Kinson Chik18e36332011-08-15 10:07:28 -0700123void board_info(void)
124{
125 struct smem_board_info_v4 board_info_v4;
126 unsigned int board_info_len = 0;
127 unsigned smem_status;
128 unsigned format = 0;
129 unsigned id = 0;
130
131 if (hw_platform && target_msm_id)
132 return;
133
134 hw_platform = MDM9X15_CDP;
135 target_msm_id = MDM9600;
136
137 smem_status = smem_read_alloc_entry_offset(SMEM_BOARD_INFO_LOCATION,
Ajay Dudanib01e5062011-12-03 23:23:42 -0800138 &format, sizeof(format), 0);
139 if (!smem_status) {
140 if (format == 4) {
Kinson Chik18e36332011-08-15 10:07:28 -0700141 board_info_len = sizeof(board_info_v4);
Ajay Dudanib01e5062011-12-03 23:23:42 -0800142 smem_status =
143 smem_read_alloc_entry(SMEM_BOARD_INFO_LOCATION,
144 &board_info_v4,
145 board_info_len);
146 if (!smem_status) {
Kinson Chik18e36332011-08-15 10:07:28 -0700147 id = board_info_v4.board_info_v3.hw_platform;
148 target_msm_id =
Ajay Dudanib01e5062011-12-03 23:23:42 -0800149 board_info_v4.board_info_v3.msm_id;
Kinson Chik18e36332011-08-15 10:07:28 -0700150 }
151 }
152 }
153 return;
154}
155
156unsigned board_machtype(void)
157{
158 board_info();
159 return hw_platform;
160}
161
162void reboot_device(unsigned reboot_reason)
163{
Deepa Dinamani0e372682011-12-19 17:09:00 -0800164 /* Write reboot reason */
165 writel(reboot_reason, RESTART_REASON_ADDR);
166
Kinson Chik53f8d322011-08-30 13:39:38 -0700167 /* Actually reset the chip */
168 pm8921_config_reset_pwr_off(1);
169 writel(0, MSM_PSHOLD_CTL_SU);
170 mdelay(10000);
171
Ajay Dudanib01e5062011-12-03 23:23:42 -0800172 dprintf(CRITICAL, "Rebooting failed\n");
Kinson Chik18e36332011-08-15 10:07:28 -0700173 return;
174}
175
176uint8_t target_uart_gsbi(void)
177{
178 return uart_gsbi_id;
179}
180
Kinson Chik0b1c8162011-08-31 16:31:57 -0700181/*
182 * Return 1 to trigger to fastboot
183 */
Ajay Dudanib01e5062011-12-03 23:23:42 -0800184int fastboot_trigger(void)
185{
Kinson Chik0b1c8162011-08-31 16:31:57 -0700186 int ret;
187 ret = fake_key_get_state();
Deepa Dinamani7519fd52012-02-08 20:32:17 -0800188 /* Want to trigger when dip switch is on */
189 return (ret);
Kinson Chik18e36332011-08-15 10:07:28 -0700190}
Kinson Chik175e8472011-09-06 17:01:26 -0700191
192void update_ptable_modem_partitions(void)
193{
194 uint32_t ptn_index, i = 0;
195 uint32_t name_size;
Ajay Dudanib01e5062011-12-03 23:23:42 -0800196 struct ptentry *ptentry_ptr = flash_ptable.parts;
Kinson Chik175e8472011-09-06 17:01:26 -0700197
Ajay Dudanib01e5062011-12-03 23:23:42 -0800198 for (ptn_index = 0; ptn_index < modem_ptn_count; ptn_index++) {
Kinson Chik175e8472011-09-06 17:01:26 -0700199 name_size = strlen(ptentry_ptr[ptn_index].name);
Ajay Dudanib01e5062011-12-03 23:23:42 -0800200 for (i = 0; i < name_size; i++) {
Kinson Chik175e8472011-09-06 17:01:26 -0700201 ptentry_ptr[ptn_index].name[i] =
Ajay Dudanib01e5062011-12-03 23:23:42 -0800202 tolower(ptentry_ptr[ptn_index].name[i]);
Kinson Chik175e8472011-09-06 17:01:26 -0700203 }
204 }
205}
206
207void update_ptable_apps_partitions(void)
208{
209 uint32_t ptn_index, name_index = 0;
210 uint32_t end = 0xffffffff;
211 uint32_t name_size = strlen(ptable_ptn_names[name_index]);
Ajay Dudanib01e5062011-12-03 23:23:42 -0800212 struct ptentry *ptentry_ptr = flash_ptable.parts;
Deepa Dinamani13e32c42012-03-12 14:34:17 -0700213 struct ptentry *fota_ptn;
214 unsigned int size;
215
216 fota_ptn = ptable_find(&flash_ptable, "FOTA");
217
218 /* Check for FOTA partitions and their size */
219 if (fota_ptn != NULL) {
220 if (fota_ptn->length > 0) {
221 /* FOTA partitions are present */
222 apps_ptn_flag[2] = 1;
223 apps_ptn_flag[3] = 1;
224 apps_ptn_flag[4] = 1;
225 apps_ptn_flag[5] = 1;
226 apps_ptn_flag[6] = 1;
227
228 }
229 }
Kinson Chik175e8472011-09-06 17:01:26 -0700230
Ajay Dudanib01e5062011-12-03 23:23:42 -0800231 for (ptn_index = 0; ptentry_ptr[ptn_index].start != end; ptn_index++) {
Kinson Chik175e8472011-09-06 17:01:26 -0700232 if (!(strncmp(ptentry_ptr[ptn_index].name,
Ajay Dudanib01e5062011-12-03 23:23:42 -0800233 ptable_ptn_names[name_index], name_size))) {
Kinson Chik175e8472011-09-06 17:01:26 -0700234 name_size = strlen(apps_ptn_names[name_index]);
Ajay Dudanib01e5062011-12-03 23:23:42 -0800235 name_size++; /* For null termination */
Kinson Chik175e8472011-09-06 17:01:26 -0700236
237 /* Update the partition names to something familiar */
238 if (name_size <= MAX_PTENTRY_NAME)
239 strncpy(ptentry_ptr[ptn_index].name,
240 apps_ptn_names[name_index], name_size);
241
242 /* Aboot uses modem page layout, leave aboot ptn */
243 if (name_index != 0)
244 ptentry_ptr[ptn_index].type =
Ajay Dudanib01e5062011-12-03 23:23:42 -0800245 TYPE_APPS_PARTITION;
Kinson Chik175e8472011-09-06 17:01:26 -0700246
Deepa Dinamani13e32c42012-03-12 14:34:17 -0700247 /* Check for valid partitions
248 * according to the apps_ptn_flag
249 */
250 do {
251 /* Don't go out of bounds */
252 name_index++;
253 if (name_index >= ptn_name_count)
254 goto ptn_name_update_done;
255 name_size =
256 strlen(ptable_ptn_names[name_index]);
257 } while (!apps_ptn_flag[name_index]);
Kinson Chik175e8472011-09-06 17:01:26 -0700258 }
259 }
Kinson Chik8480e3d2011-10-11 15:07:47 -0700260
Deepa Dinamani13e32c42012-03-12 14:34:17 -0700261ptn_name_update_done:
Kinson Chik8480e3d2011-10-11 15:07:47 -0700262 /* Update the end to be actual end for grow partition */
263 ptn_index--;
Ajay Dudanib01e5062011-12-03 23:23:42 -0800264 for (; ptentry_ptr[ptn_index].length != end; ptn_index++) {
265 };
Kinson Chik8480e3d2011-10-11 15:07:47 -0700266
267 /* If SMEM ptable is updated already then don't manually update this */
268 if (ptentry_ptr[ptn_index].start != end)
269 ptentry_ptr[ptn_index].length =
Ajay Dudanib01e5062011-12-03 23:23:42 -0800270 ((struct flash_info *)flash_get_info())->num_blocks -
271 ptentry_ptr[ptn_index].start;
Kinson Chik175e8472011-09-06 17:01:26 -0700272}