blob: 3788bc3d4d7d6552d2588f1f3ac7fe6626e5c5e2 [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 */
55char *apps_ptn_names[] = {"aboot", "boot", "system"};
56/* Partitions should be in this order */
57char *ptable_ptn_names[] = {"APPSBL", "APPS", "EFS2APPS"};
58unsigned ptn_name_count = 3;
59unsigned modem_ptn_count = 7;
60
Kinson Chik18e36332011-08-15 10:07:28 -070061static const uint8_t uart_gsbi_id = GSBI_ID_4;
62
Kinson Chik53f8d322011-08-30 13:39:38 -070063static pm8921_dev_t pmic;
64
Kinson Chik18e36332011-08-15 10:07:28 -070065void smem_ptable_init(void);
Kinson Chik18e36332011-08-15 10:07:28 -070066extern void reboot(unsigned reboot_reason);
Kinson Chik175e8472011-09-06 17:01:26 -070067void update_ptable_apps_partitions(void);
68void update_ptable_modem_partitions(void);
Kinson Chik0b1c8162011-08-31 16:31:57 -070069extern int fake_key_get_state(void);
Kinson Chik18e36332011-08-15 10:07:28 -070070
71void target_init(void)
72{
Kinson Chik18e36332011-08-15 10:07:28 -070073 struct flash_info *flash_info;
Kinson Chik18e36332011-08-15 10:07:28 -070074
75 dprintf(INFO, "target_init()\n");
Kinson Chik53f8d322011-08-30 13:39:38 -070076
77 /* Initialize PMIC driver */
78 pmic.read = (pm8921_read_func) &pa1_ssbi2_read_bytes;
79 pmic.write = (pm8921_write_func) &pa1_ssbi2_write_bytes;
80
81 pm8921_init(&pmic);
82
Kinson Chik18e36332011-08-15 10:07:28 -070083 ptable_init(&flash_ptable);
84 smem_ptable_init();
85
86 flash_init();
87 flash_info = flash_get_info();
88 ASSERT(flash_info);
89
Kinson Chik18e36332011-08-15 10:07:28 -070090 smem_add_modem_partitions(&flash_ptable);
91
Kinson Chik175e8472011-09-06 17:01:26 -070092 /* Update the naming for apps partitions and type */
93 update_ptable_apps_partitions();
94
95 /* Update modem partitions to lower case for fastboot */
96 update_ptable_modem_partitions();
97
Kinson Chik18e36332011-08-15 10:07:28 -070098 ptable_dump(&flash_ptable);
99 flash_set_ptable(&flash_ptable);
100}
101
102void board_info(void)
103{
104 struct smem_board_info_v4 board_info_v4;
105 unsigned int board_info_len = 0;
106 unsigned smem_status;
107 unsigned format = 0;
108 unsigned id = 0;
109
110 if (hw_platform && target_msm_id)
111 return;
112
113 hw_platform = MDM9X15_CDP;
114 target_msm_id = MDM9600;
115
116 smem_status = smem_read_alloc_entry_offset(SMEM_BOARD_INFO_LOCATION,
117 &format, sizeof(format), 0);
118 if(!smem_status)
119 {
120 if(format == 4)
121 {
122 board_info_len = sizeof(board_info_v4);
123 smem_status = smem_read_alloc_entry(
124 SMEM_BOARD_INFO_LOCATION,
125 &board_info_v4, board_info_len);
126 if(!smem_status)
127 {
128 id = board_info_v4.board_info_v3.hw_platform;
129 target_msm_id =
130 board_info_v4.board_info_v3.msm_id;
131 }
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
150 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 */
162int fastboot_trigger(void) {
163 int ret;
164 ret = fake_key_get_state();
165 /* Want to trigger when dip switch is off */
166 return (!ret);
Kinson Chik18e36332011-08-15 10:07:28 -0700167}
Kinson Chik175e8472011-09-06 17:01:26 -0700168
169void update_ptable_modem_partitions(void)
170{
171 uint32_t ptn_index, i = 0;
172 uint32_t name_size;
173 struct ptentry * ptentry_ptr = flash_ptable.parts;
174
175 for(ptn_index=0; ptn_index < modem_ptn_count; ptn_index++)
176 {
177 name_size = strlen(ptentry_ptr[ptn_index].name);
178 for(i=0; i < name_size; i++)
179 {
180 ptentry_ptr[ptn_index].name[i] =
181 tolower(ptentry_ptr[ptn_index].name[i]);
182 }
183 }
184}
185
186void update_ptable_apps_partitions(void)
187{
188 uint32_t ptn_index, name_index = 0;
189 uint32_t end = 0xffffffff;
190 uint32_t name_size = strlen(ptable_ptn_names[name_index]);
191 struct ptentry * ptentry_ptr = flash_ptable.parts;
192
193 for(ptn_index=0; ptentry_ptr[ptn_index].start != end; ptn_index++)
194 {
195 if (!(strncmp(ptentry_ptr[ptn_index].name,
196 ptable_ptn_names[name_index], name_size)))
197 {
198 name_size = strlen(apps_ptn_names[name_index]);
199 name_size++; /* For null termination */
200
201 /* Update the partition names to something familiar */
202 if (name_size <= MAX_PTENTRY_NAME)
203 strncpy(ptentry_ptr[ptn_index].name,
204 apps_ptn_names[name_index], name_size);
205
206 /* Aboot uses modem page layout, leave aboot ptn */
207 if (name_index != 0)
208 ptentry_ptr[ptn_index].type =
209 TYPE_APPS_PARTITION;
210
211 /* Don't go out of bounds */
212 name_index++;
213 if (name_index >= ptn_name_count)
214 break;
215 name_size = strlen(ptable_ptn_names[name_index]);
216 }
217 }
218}