blob: 1761780e8fe8b05f7a13f051ad59c117f3de6732 [file] [log] [blame]
Chandan Uddaraju8adde5a2009-11-17 11:31:28 -08001/*
2 * Copyright (c) 2009, Google Inc.
3 * All rights reserved.
Shashank Mittal8e49dec2010-03-01 15:19:04 -08004 * Copyright (c) 2009-2010, Code Aurora Forum. All rights reserved.
Chandan Uddaraju8adde5a2009-11-17 11:31:28 -08005 *
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 <dev/keys.h>
35#include <dev/gpio_keypad.h>
36#include <lib/ptable.h>
37#include <dev/flash.h>
Chandan Uddaraju885e4db2009-12-03 22:45:26 -080038#include <smem.h>
39
Chandan Uddarajud0864592010-05-21 18:22:00 -070040#define LINUX_MACHTYPE_7x30_SURF 1007016
41#define LINUX_MACHTYPE_7x30_FFA 1007017
42#define LINUX_MACHTYPE_7x30_FLUID 1007018
43#define LINUX_MACHTYPE_8x55_SURF 2768
44#define LINUX_MACHTYPE_8x55_FFA 2769
45#define LINUX_MACHTYPE_8x55_SVLTE_FFA 2863
46#define LINUX_MACHTYPE_8x55_SVLTE_SURF 2864
Chandan Uddarajuf759be32010-03-17 19:04:16 -070047
48#define MSM8255_ID 74
49#define MSM8655_ID 75
Chandan Uddaraju885e4db2009-12-03 22:45:26 -080050
51//Enum values for 7x30 target platforms.
52enum platform
53{
54 HW_PLATFORM_UNKNOWN = 0,
55 HW_PLATFORM_SURF = 1,
56 HW_PLATFORM_FFA = 2,
57 HW_PLATFORM_FLUID = 3,
Chandan Uddarajud0864592010-05-21 18:22:00 -070058 HW_PLATFORM_SVLTE = 4,
Chandan Uddaraju885e4db2009-12-03 22:45:26 -080059 HW_PLATFORM_32BITS = 0x7FFFFFFF
60};
Chandan Uddaraju8adde5a2009-11-17 11:31:28 -080061
Chandan Uddaraju9e5ab962010-01-21 15:36:37 -080062#define VARIABLE_LENGTH 0x10101010
63#define DIFF_START_ADDR 0xF0F0F0F0
64#define NUM_PAGES_PER_BLOCK 0x40
65
Chandan Uddaraju8adde5a2009-11-17 11:31:28 -080066static struct ptable flash_ptable;
Chandan Uddaraju1434a602010-03-08 17:13:38 -080067static int hw_platform_type = -1;
Chandan Uddaraju8adde5a2009-11-17 11:31:28 -080068
69/* for these partitions, start will be offset by either what we get from
70 * smem, or from the above offset if smem is not useful. Also, we should
71 * probably have smem_ptable code populate our flash_ptable.
72 *
73 * When smem provides us with a full partition table, we can get rid of
74 * this altogether.
75 *
76 */
77static struct ptentry board_part_list[] = {
78 {
79 .start = 0,
Chandan Uddarajud56669f2010-04-19 22:15:06 -070080 .length = 5 /* In MB */,
Chandan Uddaraju8adde5a2009-11-17 11:31:28 -080081 .name = "boot",
82 },
83 {
Chandan Uddarajud56669f2010-04-19 22:15:06 -070084 .start = DIFF_START_ADDR,
85 .length = 105 /* In MB */,
Chandan Uddaraju8adde5a2009-11-17 11:31:28 -080086 .name = "system",
87 },
88 {
Chandan Uddarajud56669f2010-04-19 22:15:06 -070089 .start = DIFF_START_ADDR,
90 .length = 5 /* In MB */,
Chandan Uddaraju9e5ab962010-01-21 15:36:37 -080091 .name = "cache",
Chandan Uddaraju94183c02010-01-15 15:13:59 -080092 },
93 {
Chandan Uddarajud56669f2010-04-19 22:15:06 -070094 .start = DIFF_START_ADDR,
Chandan Uddaraju9e5ab962010-01-21 15:36:37 -080095 .length = VARIABLE_LENGTH,
Chandan Uddaraju8adde5a2009-11-17 11:31:28 -080096 .name = "userdata",
97 },
Chandan Uddaraju9e5ab962010-01-21 15:36:37 -080098 {
99 .start = DIFF_START_ADDR,
Chandan Uddarajud56669f2010-04-19 22:15:06 -0700100 .length = 3 /* In MB */,
Chandan Uddaraju9e5ab962010-01-21 15:36:37 -0800101 .name = "persist",
102 },
103 {
104 .start = DIFF_START_ADDR,
Chandan Uddarajud56669f2010-04-19 22:15:06 -0700105 .length = 5 /* In MB */,
Chandan Uddaraju9e5ab962010-01-21 15:36:37 -0800106 .name = "recovery",
107 },
Chandan Uddaraju8adde5a2009-11-17 11:31:28 -0800108};
109static int num_parts = sizeof(board_part_list)/sizeof(struct ptentry);
110
111void smem_ptable_init(void);
112unsigned smem_get_apps_flash_start(void);
113
114void keypad_init(void);
115
David Ng183a7422009-12-07 14:55:21 -0800116static int emmc_boot = -1; /* set to uninitialized */
117int target_is_emmc_boot(void);
Chandan Uddaraju1434a602010-03-08 17:13:38 -0800118static int platform_version = -1;
Chandan Uddarajuf759be32010-03-17 19:04:16 -0700119static int target_msm_id = -1;
David Ng183a7422009-12-07 14:55:21 -0800120
Chandan Uddaraju8adde5a2009-11-17 11:31:28 -0800121void target_init(void)
122{
123 unsigned offset;
124 struct flash_info *flash_info;
Chandan Uddaraju9e5ab962010-01-21 15:36:37 -0800125 unsigned total_num_of_blocks;
Chandan Uddaraju9e5ab962010-01-21 15:36:37 -0800126 unsigned next_ptr_start_adr = 0;
Chandan Uddarajud56669f2010-04-19 22:15:06 -0700127 unsigned blocks_per_1MB = 8; /* Default value of 2k page size on 256MB flash drive*/
Chandan Uddaraju8adde5a2009-11-17 11:31:28 -0800128 int i;
129
130 dprintf(INFO, "target_init()\n");
131
Chandan Uddarajua0d26dd2009-12-13 01:04:38 -0800132#if (!ENABLE_NANDWRITE)
Chandan Uddaraju5fa471a2009-12-02 17:31:34 -0800133 keys_init();
134 keypad_init();
Chandan Uddarajua0d26dd2009-12-13 01:04:38 -0800135#endif
Chandan Uddaraju8adde5a2009-11-17 11:31:28 -0800136
David Ng183a7422009-12-07 14:55:21 -0800137 if (target_is_emmc_boot())
138 return;
139
Chandan Uddaraju8adde5a2009-11-17 11:31:28 -0800140 ptable_init(&flash_ptable);
141 smem_ptable_init();
142
143 flash_init();
144 flash_info = flash_get_info();
145 ASSERT(flash_info);
146
147 offset = smem_get_apps_flash_start();
148 if (offset == 0xffffffff)
149 while(1);
150
Chandan Uddaraju9e5ab962010-01-21 15:36:37 -0800151 total_num_of_blocks = (flash_info->block_size)/NUM_PAGES_PER_BLOCK;
Chandan Uddarajud56669f2010-04-19 22:15:06 -0700152 blocks_per_1MB = total_num_of_blocks /
153 (((flash_info->block_size) * (flash_info->page_size)) >> 20);
Chandan Uddaraju9e5ab962010-01-21 15:36:37 -0800154
Chandan Uddaraju8adde5a2009-11-17 11:31:28 -0800155 for (i = 0; i < num_parts; i++) {
156 struct ptentry *ptn = &board_part_list[i];
Chandan Uddarajud56669f2010-04-19 22:15:06 -0700157 unsigned len = ((ptn->length) * blocks_per_1MB);
Chandan Uddaraju8adde5a2009-11-17 11:31:28 -0800158
Chandan Uddarajud56669f2010-04-19 22:15:06 -0700159 if(ptn->start != 0)
160 ASSERT(ptn->start == DIFF_START_ADDR);
161
162 ptn->start = next_ptr_start_adr;
163
164 if(ptn->length == VARIABLE_LENGTH)
Chandan Uddaraju9e5ab962010-01-21 15:36:37 -0800165 {
Chandan Uddaraju9e5ab962010-01-21 15:36:37 -0800166 unsigned length_for_prt = 0;
167 unsigned j;
168 for (j = i+1; j < num_parts; j++)
169 {
170 struct ptentry *temp_ptn = &board_part_list[j];
171 ASSERT(temp_ptn->length != VARIABLE_LENGTH);
Chandan Uddarajud56669f2010-04-19 22:15:06 -0700172 length_for_prt += ((temp_ptn->length) * blocks_per_1MB);
Chandan Uddaraju9e5ab962010-01-21 15:36:37 -0800173 }
174 len = (total_num_of_blocks - 1) - (offset + ptn->start + length_for_prt);
175 ASSERT(len >= 0);
Chandan Uddaraju9e5ab962010-01-21 15:36:37 -0800176 }
Chandan Uddarajud56669f2010-04-19 22:15:06 -0700177 next_ptr_start_adr = ptn->start + len;
Chandan Uddaraju8adde5a2009-11-17 11:31:28 -0800178 ptable_add(&flash_ptable, ptn->name, offset + ptn->start,
Shashank Mittal8e49dec2010-03-01 15:19:04 -0800179 len, ptn->flags, TYPE_APPS_PARTITION, PERM_WRITEABLE);
Chandan Uddaraju8adde5a2009-11-17 11:31:28 -0800180 }
181
Shashank Mittal8e49dec2010-03-01 15:19:04 -0800182 smem_add_modem_partitions(&flash_ptable);
183
Chandan Uddaraju8adde5a2009-11-17 11:31:28 -0800184 ptable_dump(&flash_ptable);
185 flash_set_ptable(&flash_ptable);
186}
Chandan Uddaraju885e4db2009-12-03 22:45:26 -0800187
Chandan Uddaraju1434a602010-03-08 17:13:38 -0800188int target_platform_version(void)
189{
190 return platform_version;
191}
192
Chandan Uddarajuf759be32010-03-17 19:04:16 -0700193int target_is_msm8x55(void)
194{
195 if ((target_msm_id == MSM8255_ID) ||
196 (target_msm_id == MSM8655_ID))
197 return 1;
198 else
199 return 0;
200}
201
Chandan Uddaraju885e4db2009-12-03 22:45:26 -0800202unsigned board_machtype(void)
203{
Chandan Uddaraju1434a602010-03-08 17:13:38 -0800204 struct smem_board_info_v4 board_info_v4;
205 unsigned int board_info_len = 0;
Chandan Uddaraju885e4db2009-12-03 22:45:26 -0800206 enum platform platform_type = 0;
207 unsigned smem_status;
Chandan Uddaraju1434a602010-03-08 17:13:38 -0800208 unsigned format = 0;
209 if(hw_platform_type != -1)
210 return hw_platform_type;
Chandan Uddaraju885e4db2009-12-03 22:45:26 -0800211
Chandan Uddaraju1434a602010-03-08 17:13:38 -0800212 smem_status = smem_read_alloc_entry_offset(SMEM_BOARD_INFO_LOCATION,
213 &format, sizeof(format), 0);
Chandan Uddarajuf759be32010-03-17 19:04:16 -0700214 if(!smem_status)
Chandan Uddaraju885e4db2009-12-03 22:45:26 -0800215 {
Chandan Uddarajuf759be32010-03-17 19:04:16 -0700216 if ((format == 3) || (format == 4))
Chandan Uddaraju885e4db2009-12-03 22:45:26 -0800217 {
Chandan Uddarajuf759be32010-03-17 19:04:16 -0700218 if (format == 4)
219 board_info_len = sizeof(board_info_v4);
220 else
221 board_info_len = sizeof(board_info_v4.board_info_v3);
Chandan Uddaraju1434a602010-03-08 17:13:38 -0800222
Chandan Uddarajuf759be32010-03-17 19:04:16 -0700223 smem_status = smem_read_alloc_entry(SMEM_BOARD_INFO_LOCATION,
224 &board_info_v4, board_info_len);
225 if(!smem_status)
226 {
227 if(format == 4)
228 platform_version = board_info_v4.platform_version;
229
230 platform_type = board_info_v4.board_info_v3.hw_platform;
231 target_msm_id = board_info_v4.board_info_v3.msm_id;
232 switch (platform_type)
233 {
234 case HW_PLATFORM_SURF:
235 hw_platform_type = ((target_is_msm8x55()) ?
236 LINUX_MACHTYPE_8x55_SURF : LINUX_MACHTYPE_7x30_SURF); break;
237 case HW_PLATFORM_FFA:
238 hw_platform_type = ((target_is_msm8x55()) ?
239 LINUX_MACHTYPE_8x55_FFA : LINUX_MACHTYPE_7x30_FFA); break;
240 case HW_PLATFORM_FLUID:
241 hw_platform_type = LINUX_MACHTYPE_7x30_FLUID; break;
Chandan Uddarajud0864592010-05-21 18:22:00 -0700242 case HW_PLATFORM_SVLTE:
243 hw_platform_type = LINUX_MACHTYPE_8x55_SVLTE_FFA; break;
Chandan Uddarajuf759be32010-03-17 19:04:16 -0700244 default:
245 hw_platform_type = ((target_is_msm8x55()) ?
246 LINUX_MACHTYPE_8x55_SURF : LINUX_MACHTYPE_7x30_SURF); break;
247 }
248 return hw_platform_type;
249 }
250 }
251 }
252 hw_platform_type = LINUX_MACHTYPE_7x30_SURF;
Chandan Uddaraju1434a602010-03-08 17:13:38 -0800253 return hw_platform_type;
Chandan Uddaraju885e4db2009-12-03 22:45:26 -0800254}
David Ng183a7422009-12-07 14:55:21 -0800255
Chandan Uddaraju94183c02010-01-15 15:13:59 -0800256void reboot_device(unsigned reboot_reason)
257{
258 reboot(reboot_reason);
259}
260
Chandan Uddarajude85d3f2010-01-05 16:32:33 -0800261unsigned check_reboot_mode(void)
262{
Chandan Uddaraju94183c02010-01-15 15:13:59 -0800263 unsigned mode[2] = {0, 0};
264 unsigned int mode_len = sizeof(mode);
265 unsigned smem_status;
266
267 smem_status = smem_read_alloc_entry(SMEM_APPS_BOOT_MODE,
268 &mode, mode_len );
269 if(smem_status)
270 {
271 dprintf(CRITICAL, "ERROR: unable to read shared memory for reboot mode\n");
272 return 0;
273 }
274 return mode[0];
Chandan Uddarajude85d3f2010-01-05 16:32:33 -0800275}
Chandan Uddaraju7f5b9012010-02-06 16:37:48 -0800276
277void target_battery_charging_enable(unsigned enable, unsigned disconnect)
278{
279}