blob: 75ac7492420f893869472f4606ecd8386e6698f1 [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
40#define LINUX_MACHTYPE_SURF 1007016
41#define LINUX_MACHTYPE_FFA 1007017
42#define LINUX_MACHTYPE_FLUID 1007018
43
44//Enum values for 7x30 target platforms.
45enum platform
46{
47 HW_PLATFORM_UNKNOWN = 0,
48 HW_PLATFORM_SURF = 1,
49 HW_PLATFORM_FFA = 2,
50 HW_PLATFORM_FLUID = 3,
51 HW_PLATFORM_32BITS = 0x7FFFFFFF
52};
Chandan Uddaraju8adde5a2009-11-17 11:31:28 -080053
Chandan Uddaraju9e5ab962010-01-21 15:36:37 -080054#define VARIABLE_LENGTH 0x10101010
55#define DIFF_START_ADDR 0xF0F0F0F0
56#define NUM_PAGES_PER_BLOCK 0x40
57
Chandan Uddaraju8adde5a2009-11-17 11:31:28 -080058static struct ptable flash_ptable;
59
60/* for these partitions, start will be offset by either what we get from
61 * smem, or from the above offset if smem is not useful. Also, we should
62 * probably have smem_ptable code populate our flash_ptable.
63 *
64 * When smem provides us with a full partition table, we can get rid of
65 * this altogether.
66 *
67 */
68static struct ptentry board_part_list[] = {
69 {
70 .start = 0,
Chandan Uddaraju2e2908f2010-01-12 13:30:59 -080071 .length = 20 /* 5MB */,
Chandan Uddaraju8adde5a2009-11-17 11:31:28 -080072 .name = "boot",
73 },
74 {
Chandan Uddaraju2e2908f2010-01-12 13:30:59 -080075 .start = 20,
Ajay Dudanid43419e2010-02-10 13:17:39 -080076 .length = 420 /* 105MB */,
Chandan Uddaraju8adde5a2009-11-17 11:31:28 -080077 .name = "system",
78 },
79 {
Ajay Dudanid43419e2010-02-10 13:17:39 -080080 .start = 440,
Chandan Uddaraju94183c02010-01-15 15:13:59 -080081 .length = 20 /* 5MB */,
Chandan Uddaraju9e5ab962010-01-21 15:36:37 -080082 .name = "cache",
Chandan Uddaraju94183c02010-01-15 15:13:59 -080083 },
84 {
Ajay Dudanid43419e2010-02-10 13:17:39 -080085 .start = 460,
Chandan Uddaraju9e5ab962010-01-21 15:36:37 -080086 .length = VARIABLE_LENGTH,
Chandan Uddaraju8adde5a2009-11-17 11:31:28 -080087 .name = "userdata",
88 },
Chandan Uddaraju9e5ab962010-01-21 15:36:37 -080089 {
90 .start = DIFF_START_ADDR,
Chandan Uddaraju535fa092010-01-26 19:14:48 -080091 .length = 12 /* 3MB */,
Chandan Uddaraju9e5ab962010-01-21 15:36:37 -080092 .name = "persist",
93 },
94 {
95 .start = DIFF_START_ADDR,
96 .length = 20 /* 5MB */,
97 .name = "recovery",
98 },
Chandan Uddaraju8adde5a2009-11-17 11:31:28 -080099};
100static int num_parts = sizeof(board_part_list)/sizeof(struct ptentry);
101
102void smem_ptable_init(void);
103unsigned smem_get_apps_flash_start(void);
104
105void keypad_init(void);
106
David Ng183a7422009-12-07 14:55:21 -0800107static int emmc_boot = -1; /* set to uninitialized */
108int target_is_emmc_boot(void);
109
Chandan Uddaraju8adde5a2009-11-17 11:31:28 -0800110void target_init(void)
111{
112 unsigned offset;
113 struct flash_info *flash_info;
Chandan Uddaraju9e5ab962010-01-21 15:36:37 -0800114 unsigned total_num_of_blocks;
115 bool start_addr_changed = false;
116 unsigned next_ptr_start_adr = 0;
Chandan Uddaraju8adde5a2009-11-17 11:31:28 -0800117 int i;
118
119 dprintf(INFO, "target_init()\n");
120
Chandan Uddarajua0d26dd2009-12-13 01:04:38 -0800121#if (!ENABLE_NANDWRITE)
Chandan Uddaraju5fa471a2009-12-02 17:31:34 -0800122 keys_init();
123 keypad_init();
Chandan Uddarajua0d26dd2009-12-13 01:04:38 -0800124#endif
Chandan Uddaraju8adde5a2009-11-17 11:31:28 -0800125
David Ng183a7422009-12-07 14:55:21 -0800126 if (target_is_emmc_boot())
127 return;
128
Chandan Uddaraju8adde5a2009-11-17 11:31:28 -0800129 ptable_init(&flash_ptable);
130 smem_ptable_init();
131
132 flash_init();
133 flash_info = flash_get_info();
134 ASSERT(flash_info);
135
136 offset = smem_get_apps_flash_start();
137 if (offset == 0xffffffff)
138 while(1);
139
Chandan Uddaraju9e5ab962010-01-21 15:36:37 -0800140 total_num_of_blocks = (flash_info->block_size)/NUM_PAGES_PER_BLOCK;
141
Chandan Uddaraju8adde5a2009-11-17 11:31:28 -0800142 for (i = 0; i < num_parts; i++) {
143 struct ptentry *ptn = &board_part_list[i];
144 unsigned len = ptn->length;
145
Chandan Uddaraju9e5ab962010-01-21 15:36:37 -0800146 if(len == VARIABLE_LENGTH)
147 {
148 start_addr_changed = true;
149 unsigned length_for_prt = 0;
150 unsigned j;
151 for (j = i+1; j < num_parts; j++)
152 {
153 struct ptentry *temp_ptn = &board_part_list[j];
154 ASSERT(temp_ptn->length != VARIABLE_LENGTH);
155 length_for_prt += temp_ptn->length;
156 }
157 len = (total_num_of_blocks - 1) - (offset + ptn->start + length_for_prt);
158 ASSERT(len >= 0);
159 next_ptr_start_adr = ptn->start + len;
160 }
161 if((ptn->start == DIFF_START_ADDR) && (start_addr_changed))
162 {
163 ASSERT(next_ptr_start_adr);
164 ptn->start = next_ptr_start_adr;
165 next_ptr_start_adr = ptn->start + ptn->length;
166 }
Chandan Uddaraju8adde5a2009-11-17 11:31:28 -0800167 ptable_add(&flash_ptable, ptn->name, offset + ptn->start,
Shashank Mittal8e49dec2010-03-01 15:19:04 -0800168 len, ptn->flags, TYPE_APPS_PARTITION, PERM_WRITEABLE);
Chandan Uddaraju8adde5a2009-11-17 11:31:28 -0800169 }
170
Shashank Mittal8e49dec2010-03-01 15:19:04 -0800171 smem_add_modem_partitions(&flash_ptable);
172
Chandan Uddaraju8adde5a2009-11-17 11:31:28 -0800173 ptable_dump(&flash_ptable);
174 flash_set_ptable(&flash_ptable);
175}
Chandan Uddaraju885e4db2009-12-03 22:45:26 -0800176
177unsigned board_machtype(void)
178{
179 struct smem_board_info board_info;
180 unsigned int board_info_struct_len = sizeof(board_info);
181 enum platform platform_type = 0;
182 unsigned smem_status;
183
184 smem_status = smem_read_alloc_entry(SMEM_BOARD_INFO_LOCATION,
185 &board_info, board_info_struct_len );
186 if(smem_status)
187 {
188 dprintf(CRITICAL, "ERROR: unable to read shared memory for Hardware Platform\n");
189 }
190
191 if (board_info.format == 3)
192 {
193 platform_type = board_info.hw_platform;
194 switch (platform_type)
195 {
196 case HW_PLATFORM_SURF:
197 return LINUX_MACHTYPE_SURF;
198 case HW_PLATFORM_FFA:
199 return LINUX_MACHTYPE_FFA;
200 case HW_PLATFORM_FLUID:
201 return LINUX_MACHTYPE_FLUID;
202 default:
203 return LINUX_MACHTYPE_SURF;
204 }
205 }
206 return LINUX_MACHTYPE_SURF;
207}
David Ng183a7422009-12-07 14:55:21 -0800208
Chandan Uddaraju94183c02010-01-15 15:13:59 -0800209void reboot_device(unsigned reboot_reason)
210{
211 reboot(reboot_reason);
212}
213
Chandan Uddarajude85d3f2010-01-05 16:32:33 -0800214unsigned check_reboot_mode(void)
215{
Chandan Uddaraju94183c02010-01-15 15:13:59 -0800216 unsigned mode[2] = {0, 0};
217 unsigned int mode_len = sizeof(mode);
218 unsigned smem_status;
219
220 smem_status = smem_read_alloc_entry(SMEM_APPS_BOOT_MODE,
221 &mode, mode_len );
222 if(smem_status)
223 {
224 dprintf(CRITICAL, "ERROR: unable to read shared memory for reboot mode\n");
225 return 0;
226 }
227 return mode[0];
Chandan Uddarajude85d3f2010-01-05 16:32:33 -0800228}
Chandan Uddaraju7f5b9012010-02-06 16:37:48 -0800229
230void target_battery_charging_enable(unsigned enable, unsigned disconnect)
231{
232}