blob: 22dcd51a91dc796972a4b074cc42ef84aa054850 [file] [log] [blame]
Shashank Mittal246f8d02011-01-21 17:12:27 -08001/*
2 * Copyright (c) 2009, Google Inc.
3 * All rights reserved.
4 * Copyright (c) 2009-2011, Code Aurora Forum. All rights reserved.
5 *
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>
38#include <smem.h>
39#include <platform/iomap.h>
40
41#define MSM7X27A_FFA 3351
42#define MSM7X27A_SURF 3352
43#define MSM7X27A_RUMI3 3353
44#define LINUX_MACHTYPE MSM7X27A_RUMI3
45
46#define VARIABLE_LENGTH 0x10101010
47#define DIFF_START_ADDR 0xF0F0F0F0
48#define NUM_PAGES_PER_BLOCK 0x40
49
50static struct ptable flash_ptable;
51
52/* for these partitions, start will be offset by either what we get from
53 * smem, or from the above offset if smem is not useful. Also, we should
54 * probably have smem_ptable code populate our flash_ptable.
55 *
56 * When smem provides us with a full partition table, we can get rid of
57 * this altogether.
58 *
59 */
60static struct ptentry board_part_list[] = {
61 {
62 .start = 0,
63 .length = 10 /* In MB */,
64 .name = "boot",
65 },
66 {
67 .start = DIFF_START_ADDR,
68 .length = 105 /* In MB */,
69 .name = "system",
70 },
71 {
72 .start = DIFF_START_ADDR,
73 .length = 1 /* In MB */,
74 .name = "cache",
75 },
76 {
77 .start = DIFF_START_ADDR,
78 .length = 1 /* In MB */,
79 .name = "misc",
80 },
81 {
82 .start = DIFF_START_ADDR,
83 .length = VARIABLE_LENGTH,
84 .name = "userdata",
85 },
86 {
87 .start = DIFF_START_ADDR,
88 .length = 2 /* In MB */,
89 .name = "persist",
90 },
91 {
92 .start = DIFF_START_ADDR,
93 .length = 5 /* In MB */,
94 .name = "recovery",
95 },
96};
97static int num_parts = sizeof(board_part_list)/sizeof(struct ptentry);
98
99void smem_ptable_init(void);
100unsigned smem_get_apps_flash_start(void);
101
102void keypad_init(void);
103
104int target_is_emmc_boot(void);
105
106void target_init(void)
107{
108 unsigned offset;
109 struct flash_info *flash_info;
110 unsigned total_num_of_blocks;
111 unsigned next_ptr_start_adr = 0;
112 unsigned blocks_per_1MB = 8; /* Default value of 2k page size on 256MB flash drive*/
113 int i;
114
115 dprintf(INFO, "target_init()\n");
116
117/* TODO: Enable keypad support */
118#if 0
119#if (!ENABLE_NANDWRITE)
120 keys_init();
121 keypad_init();
122#endif
123#endif
124
125 if (target_is_emmc_boot())
126 {
127 if(mmc_boot_main(MMC_SLOT, MSM_SDC1_BASE))
128 {
129 dprintf(CRITICAL, "mmc init failed!");
130 ASSERT(0);
131 }
132 return;
133 }
134
135 ptable_init(&flash_ptable);
136 smem_ptable_init();
137
138 flash_init();
139 flash_info = flash_get_info();
140 ASSERT(flash_info);
141
142 offset = smem_get_apps_flash_start();
143 if (offset == 0xffffffff)
144 while(1);
145
146 total_num_of_blocks = flash_info->num_blocks;
147 blocks_per_1MB = (1 << 20) / (flash_info->block_size);
148
149 for (i = 0; i < num_parts; i++) {
150 struct ptentry *ptn = &board_part_list[i];
151 unsigned len = ((ptn->length) * blocks_per_1MB);
152
153 if(ptn->start != 0)
154 ASSERT(ptn->start == DIFF_START_ADDR);
155
156 ptn->start = next_ptr_start_adr;
157
158 if(ptn->length == VARIABLE_LENGTH)
159 {
160 unsigned length_for_prt = 0;
161 unsigned j;
162 for (j = i+1; j < num_parts; j++)
163 {
164 struct ptentry *temp_ptn = &board_part_list[j];
165 ASSERT(temp_ptn->length != VARIABLE_LENGTH);
166 length_for_prt += ((temp_ptn->length) * blocks_per_1MB);
167 }
168 len = (total_num_of_blocks - 1) - (offset + ptn->start + length_for_prt);
169 ASSERT(len >= 0);
170 }
171 next_ptr_start_adr = ptn->start + len;
172 ptable_add(&flash_ptable, ptn->name, offset + ptn->start,
173 len, ptn->flags, TYPE_APPS_PARTITION, PERM_WRITEABLE);
174 }
175
176 smem_add_modem_partitions(&flash_ptable);
177
178 ptable_dump(&flash_ptable);
179 flash_set_ptable(&flash_ptable);
180}
181
182unsigned board_machtype(void)
183{
184 return LINUX_MACHTYPE;
185}
186
187void reboot_device(unsigned reboot_reason)
188{
189 reboot(reboot_reason);
190}
191
192unsigned check_reboot_mode(void)
193{
194 unsigned mode[2] = {0, 0};
195 unsigned int mode_len = sizeof(mode);
196 unsigned smem_status;
197
198 smem_status = smem_read_alloc_entry(SMEM_APPS_BOOT_MODE,
199 &mode, mode_len );
200 if(smem_status)
201 {
202 dprintf(CRITICAL, "ERROR: unable to read shared memory for reboot mode\n");
203 return 0;
204 }
205 return mode[0];
206}
207
208static unsigned target_check_power_on_reason(void)
209{
210 unsigned power_on_status = 0;
211 unsigned int status_len = sizeof(power_on_status);
212 unsigned smem_status;
213
214 smem_status = smem_read_alloc_entry(SMEM_POWER_ON_STATUS_INFO,
215 &power_on_status, status_len);
216 if (!smem_status)
217 {
218 dprintf(CRITICAL, "ERROR: unable to read shared memory for power on reason\n");
219 }
220
221 return power_on_status;
222}
223
224unsigned target_pause_for_battery_charge(void)
225{
226 if (target_check_power_on_reason() == PWR_ON_EVENT_USB_CHG)
227 return 1;
228 return 0;
229}
230
231void target_battery_charging_enable(unsigned enable, unsigned disconnect)
232{
233}