blob: 83ce379b61a9fbd31793186e619ea6393695a30b [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 */
Ajay Dudanib01e5062011-12-03 23:23:42 -080055char *apps_ptn_names[] = { "aboot", "boot", "system" };
56
Kinson Chik175e8472011-09-06 17:01:26 -070057/* Partitions should be in this order */
Ajay Dudanib01e5062011-12-03 23:23:42 -080058char *ptable_ptn_names[] = { "APPSBL", "APPS", "EFS2APPS" };
59
Kinson Chik175e8472011-09-06 17:01:26 -070060unsigned ptn_name_count = 3;
61unsigned modem_ptn_count = 7;
62
Kinson Chik18e36332011-08-15 10:07:28 -070063static const uint8_t uart_gsbi_id = GSBI_ID_4;
64
Kinson Chik53f8d322011-08-30 13:39:38 -070065static pm8921_dev_t pmic;
66
Kinson Chik18e36332011-08-15 10:07:28 -070067void smem_ptable_init(void);
Kinson Chik18e36332011-08-15 10:07:28 -070068extern void reboot(unsigned reboot_reason);
Kinson Chik175e8472011-09-06 17:01:26 -070069void update_ptable_apps_partitions(void);
70void update_ptable_modem_partitions(void);
Kinson Chik0b1c8162011-08-31 16:31:57 -070071extern int fake_key_get_state(void);
Kinson Chik18e36332011-08-15 10:07:28 -070072
73void target_init(void)
74{
Kinson Chik18e36332011-08-15 10:07:28 -070075 struct flash_info *flash_info;
Kinson Chik18e36332011-08-15 10:07:28 -070076
77 dprintf(INFO, "target_init()\n");
Kinson Chik53f8d322011-08-30 13:39:38 -070078
79 /* Initialize PMIC driver */
Ajay Dudanib01e5062011-12-03 23:23:42 -080080 pmic.read = (pm8921_read_func) & pa1_ssbi2_read_bytes;
81 pmic.write = (pm8921_write_func) & pa1_ssbi2_write_bytes;
Kinson Chik53f8d322011-08-30 13:39:38 -070082
83 pm8921_init(&pmic);
84
Kinson Chik18e36332011-08-15 10:07:28 -070085 ptable_init(&flash_ptable);
86 smem_ptable_init();
87
88 flash_init();
89 flash_info = flash_get_info();
90 ASSERT(flash_info);
91
Kinson Chik18e36332011-08-15 10:07:28 -070092 smem_add_modem_partitions(&flash_ptable);
93
Kinson Chik175e8472011-09-06 17:01:26 -070094 /* Update the naming for apps partitions and type */
95 update_ptable_apps_partitions();
96
97 /* Update modem partitions to lower case for fastboot */
98 update_ptable_modem_partitions();
99
Kinson Chik18e36332011-08-15 10:07:28 -0700100 ptable_dump(&flash_ptable);
101 flash_set_ptable(&flash_ptable);
102}
103
104void board_info(void)
105{
106 struct smem_board_info_v4 board_info_v4;
107 unsigned int board_info_len = 0;
108 unsigned smem_status;
109 unsigned format = 0;
110 unsigned id = 0;
111
112 if (hw_platform && target_msm_id)
113 return;
114
115 hw_platform = MDM9X15_CDP;
116 target_msm_id = MDM9600;
117
118 smem_status = smem_read_alloc_entry_offset(SMEM_BOARD_INFO_LOCATION,
Ajay Dudanib01e5062011-12-03 23:23:42 -0800119 &format, sizeof(format), 0);
120 if (!smem_status) {
121 if (format == 4) {
Kinson Chik18e36332011-08-15 10:07:28 -0700122 board_info_len = sizeof(board_info_v4);
Ajay Dudanib01e5062011-12-03 23:23:42 -0800123 smem_status =
124 smem_read_alloc_entry(SMEM_BOARD_INFO_LOCATION,
125 &board_info_v4,
126 board_info_len);
127 if (!smem_status) {
Kinson Chik18e36332011-08-15 10:07:28 -0700128 id = board_info_v4.board_info_v3.hw_platform;
129 target_msm_id =
Ajay Dudanib01e5062011-12-03 23:23:42 -0800130 board_info_v4.board_info_v3.msm_id;
Kinson Chik18e36332011-08-15 10:07:28 -0700131 }
132 }
133 }
134 return;
135}
136
137unsigned board_machtype(void)
138{
139 board_info();
140 return hw_platform;
141}
142
143void reboot_device(unsigned reboot_reason)
144{
Kinson Chik53f8d322011-08-30 13:39:38 -0700145 /* Actually reset the chip */
146 pm8921_config_reset_pwr_off(1);
147 writel(0, MSM_PSHOLD_CTL_SU);
148 mdelay(10000);
149
Ajay Dudanib01e5062011-12-03 23:23:42 -0800150 dprintf(CRITICAL, "Rebooting failed\n");
Kinson Chik18e36332011-08-15 10:07:28 -0700151 return;
152}
153
154uint8_t target_uart_gsbi(void)
155{
156 return uart_gsbi_id;
157}
158
Kinson Chik0b1c8162011-08-31 16:31:57 -0700159/*
160 * Return 1 to trigger to fastboot
161 */
Ajay Dudanib01e5062011-12-03 23:23:42 -0800162int fastboot_trigger(void)
163{
Kinson Chik0b1c8162011-08-31 16:31:57 -0700164 int ret;
165 ret = fake_key_get_state();
166 /* Want to trigger when dip switch is off */
167 return (!ret);
Kinson Chik18e36332011-08-15 10:07:28 -0700168}
Kinson Chik175e8472011-09-06 17:01:26 -0700169
170void update_ptable_modem_partitions(void)
171{
172 uint32_t ptn_index, i = 0;
173 uint32_t name_size;
Ajay Dudanib01e5062011-12-03 23:23:42 -0800174 struct ptentry *ptentry_ptr = flash_ptable.parts;
Kinson Chik175e8472011-09-06 17:01:26 -0700175
Ajay Dudanib01e5062011-12-03 23:23:42 -0800176 for (ptn_index = 0; ptn_index < modem_ptn_count; ptn_index++) {
Kinson Chik175e8472011-09-06 17:01:26 -0700177 name_size = strlen(ptentry_ptr[ptn_index].name);
Ajay Dudanib01e5062011-12-03 23:23:42 -0800178 for (i = 0; i < name_size; i++) {
Kinson Chik175e8472011-09-06 17:01:26 -0700179 ptentry_ptr[ptn_index].name[i] =
Ajay Dudanib01e5062011-12-03 23:23:42 -0800180 tolower(ptentry_ptr[ptn_index].name[i]);
Kinson Chik175e8472011-09-06 17:01:26 -0700181 }
182 }
183}
184
185void update_ptable_apps_partitions(void)
186{
187 uint32_t ptn_index, name_index = 0;
188 uint32_t end = 0xffffffff;
189 uint32_t name_size = strlen(ptable_ptn_names[name_index]);
Ajay Dudanib01e5062011-12-03 23:23:42 -0800190 struct ptentry *ptentry_ptr = flash_ptable.parts;
Kinson Chik175e8472011-09-06 17:01:26 -0700191
Ajay Dudanib01e5062011-12-03 23:23:42 -0800192 for (ptn_index = 0; ptentry_ptr[ptn_index].start != end; ptn_index++) {
Kinson Chik175e8472011-09-06 17:01:26 -0700193 if (!(strncmp(ptentry_ptr[ptn_index].name,
Ajay Dudanib01e5062011-12-03 23:23:42 -0800194 ptable_ptn_names[name_index], name_size))) {
Kinson Chik175e8472011-09-06 17:01:26 -0700195 name_size = strlen(apps_ptn_names[name_index]);
Ajay Dudanib01e5062011-12-03 23:23:42 -0800196 name_size++; /* For null termination */
Kinson Chik175e8472011-09-06 17:01:26 -0700197
198 /* Update the partition names to something familiar */
199 if (name_size <= MAX_PTENTRY_NAME)
200 strncpy(ptentry_ptr[ptn_index].name,
201 apps_ptn_names[name_index], name_size);
202
203 /* Aboot uses modem page layout, leave aboot ptn */
204 if (name_index != 0)
205 ptentry_ptr[ptn_index].type =
Ajay Dudanib01e5062011-12-03 23:23:42 -0800206 TYPE_APPS_PARTITION;
Kinson Chik175e8472011-09-06 17:01:26 -0700207
208 /* Don't go out of bounds */
209 name_index++;
210 if (name_index >= ptn_name_count)
211 break;
212 name_size = strlen(ptable_ptn_names[name_index]);
213 }
214 }
Kinson Chik8480e3d2011-10-11 15:07:47 -0700215
216 /* Update the end to be actual end for grow partition */
217 ptn_index--;
Ajay Dudanib01e5062011-12-03 23:23:42 -0800218 for (; ptentry_ptr[ptn_index].length != end; ptn_index++) {
219 };
Kinson Chik8480e3d2011-10-11 15:07:47 -0700220
221 /* If SMEM ptable is updated already then don't manually update this */
222 if (ptentry_ptr[ptn_index].start != end)
223 ptentry_ptr[ptn_index].length =
Ajay Dudanib01e5062011-12-03 23:23:42 -0800224 ((struct flash_info *)flash_get_info())->num_blocks -
225 ptentry_ptr[ptn_index].start;
Kinson Chik175e8472011-09-06 17:01:26 -0700226}