blob: 77f73318c47226f9aff64eb88997defdb9d29980 [file] [log] [blame]
Abhimanyu Kapur002ddf92013-01-28 17:13:13 -08001/* Copyright (c) 2012-2013, The Linux Foundation. All rights reserved.
Amol Jadi42d7b5a2012-05-04 14:50:32 -07002 *
3 * Redistribution and use in source and binary forms, with or without
4 * modification, are permitted provided that the following conditions are
5 * met:
6 * * Redistributions of source code must retain the above copyright
7 * notice, this list of conditions and the following disclaimer.
8 * * Redistributions in binary form must reproduce the above
9 * copyright notice, this list of conditions and the following
10 * disclaimer in the documentation and/or other materials provided
11 * with the distribution.
Deepa Dinamani28c0ffe2012-09-24 11:45:21 -070012 * * Neither the name of The Linux Foundation nor the names of its
Amol Jadi42d7b5a2012-05-04 14:50:32 -070013 * contributors may be used to endorse or promote products derived
14 * from this software without specific prior written permission.
15 *
16 * THIS SOFTWARE IS PROVIDED "AS IS" AND ANY EXPRESS OR IMPLIED
17 * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
18 * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT
19 * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS
20 * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
21 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
22 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR
23 * BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
24 * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE
25 * OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN
26 * IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
27 */
Deepa Dinamani28c0ffe2012-09-24 11:45:21 -070028
Amol Jadi42d7b5a2012-05-04 14:50:32 -070029#include <debug.h>
30#include <board.h>
31#include <platform.h>
32#include <target.h>
33#include <smem.h>
34#include <baseband.h>
Deepa Dinamanie4573be2012-08-03 16:32:29 -070035#include <lib/ptable.h>
36#include <qpic_nand.h>
Deepa Dinamani28c0ffe2012-09-24 11:45:21 -070037#include <ctype.h>
38#include <string.h>
Amol Jadi62d7bd22012-10-08 18:15:58 -070039#include <pm8x41.h>
40#include <reg.h>
41#include <platform/timer.h>
Deepa Dinamani28c0ffe2012-09-24 11:45:21 -070042
43extern void smem_ptable_init(void);
44extern void smem_add_modem_partitions(struct ptable *flash_ptable);
Amol Jadi42d7b5a2012-05-04 14:50:32 -070045
Deepa Dinamanie4573be2012-08-03 16:32:29 -070046static struct ptable flash_ptable;
47
Amol Jadi62d7bd22012-10-08 18:15:58 -070048/* PMIC config data */
Deepa Dinamanie9ded132012-11-27 15:03:38 -080049#define PMIC_ARB_CHANNEL_NUM 0
50#define PMIC_ARB_OWNER_ID 0
Amol Jadi62d7bd22012-10-08 18:15:58 -070051
Deepa Dinamanie4573be2012-08-03 16:32:29 -070052/* NANDc BAM pipe numbers */
53#define DATA_CONSUMER_PIPE 0
54#define DATA_PRODUCER_PIPE 1
55#define CMD_PIPE 2
56
Deepa Dinamani5b411782013-07-09 13:15:16 -070057/* NANDc BAM pipe groups */
58#define DATA_PRODUCER_PIPE_GRP 0
59#define DATA_CONSUMER_PIPE_GRP 0
60#define CMD_PIPE_GRP 1
61
Deepa Dinamanie9ded132012-11-27 15:03:38 -080062/* NANDc EE */
63#define QPIC_NAND_EE 0
64
65/* NANDc max desc length. */
66#define QPIC_NAND_MAX_DESC_LEN 0x7FFF
67
Deepa Dinamani8e6b2432012-10-17 17:12:44 -070068#define LAST_NAND_PTN_LEN_PATTERN 0xFFFFFFFF
69
Deepa Dinamanie4573be2012-08-03 16:32:29 -070070struct qpic_nand_init_config config;
Deepa Dinamani28c0ffe2012-09-24 11:45:21 -070071
72void update_ptable_names(void)
73{
74 uint32_t ptn_index;
75 struct ptentry *ptentry_ptr = flash_ptable.parts;
76 struct ptentry *boot_ptn;
77 unsigned i;
78 uint32_t len;
79
80 /* Change all names to lower case. */
81 for (ptn_index = 0; ptn_index != (uint32_t)flash_ptable.count; ptn_index++)
82 {
83 len = strlen(ptentry_ptr[ptn_index].name);
84
85 for (i = 0; i < len; i++)
86 {
87 if (isupper(ptentry_ptr[ptn_index].name[i]))
88 {
89 ptentry_ptr[ptn_index].name[i] = tolower(ptentry_ptr[ptn_index].name[i]);
90 }
91 }
Deepa Dinamani8e6b2432012-10-17 17:12:44 -070092
93 /* SBL fills in the last partition length as 0xFFFFFFFF.
94 * Update the length field based on the number of blocks on the flash.
95 */
96 if ((uint32_t)(ptentry_ptr[ptn_index].length) == LAST_NAND_PTN_LEN_PATTERN)
97 {
98 ptentry_ptr[ptn_index].length = flash_num_blocks() - ptentry_ptr[ptn_index].start;
99 }
Deepa Dinamani28c0ffe2012-09-24 11:45:21 -0700100 }
101
102 /* Rename apps ptn to boot. */
103 boot_ptn = ptable_find(&flash_ptable, "apps");
104 strcpy(boot_ptn->name, "boot");
Deepa Dinamani2a527512012-10-09 15:19:29 -0700105
106 /* Rename appsbl ptn to aboot. */
107 boot_ptn = ptable_find(&flash_ptable, "appsbl");
108 strcpy(boot_ptn->name, "aboot");
Deepa Dinamani28c0ffe2012-09-24 11:45:21 -0700109}
110
Deepa Dinamanidca5c662012-12-03 14:13:07 -0800111void target_early_init(void)
112{
113#if WITH_DEBUG_UART
114 uart_dm_init(3, 0, MSM_UART2_BASE);
115#endif
116}
117
118
Amol Jadi42d7b5a2012-05-04 14:50:32 -0700119/* init */
120void target_init(void)
121{
122 dprintf(INFO, "target_init()\n");
Deepa Dinamanie4573be2012-08-03 16:32:29 -0700123
Amol Jadi62d7bd22012-10-08 18:15:58 -0700124 spmi_init(PMIC_ARB_CHANNEL_NUM, PMIC_ARB_OWNER_ID);
125
Deepa Dinamanie4573be2012-08-03 16:32:29 -0700126 config.pipes.read_pipe = DATA_PRODUCER_PIPE;
127 config.pipes.write_pipe = DATA_CONSUMER_PIPE;
128 config.pipes.cmd_pipe = CMD_PIPE;
129
Deepa Dinamani5b411782013-07-09 13:15:16 -0700130 config.pipes.read_pipe_grp = DATA_PRODUCER_PIPE_GRP;
131 config.pipes.write_pipe_grp = DATA_CONSUMER_PIPE_GRP;
132 config.pipes.cmd_pipe_grp = CMD_PIPE_GRP;
133
Deepa Dinamanie4573be2012-08-03 16:32:29 -0700134 config.bam_base = MSM_NAND_BAM_BASE;
135 config.nand_base = MSM_NAND_BASE;
Deepa Dinamanie9ded132012-11-27 15:03:38 -0800136 config.ee = QPIC_NAND_EE;
137 config.max_desc_len = QPIC_NAND_MAX_DESC_LEN;
Deepa Dinamanie4573be2012-08-03 16:32:29 -0700138
139 qpic_nand_init(&config);
140
Deepa Dinamanie4573be2012-08-03 16:32:29 -0700141 ptable_init(&flash_ptable);
142
Deepa Dinamani28c0ffe2012-09-24 11:45:21 -0700143 smem_ptable_init();
Deepa Dinamanie4573be2012-08-03 16:32:29 -0700144
Deepa Dinamani28c0ffe2012-09-24 11:45:21 -0700145 smem_add_modem_partitions(&flash_ptable);
146
147 update_ptable_names();
148
149 flash_set_ptable(&flash_ptable);
Amol Jadi42d7b5a2012-05-04 14:50:32 -0700150}
151
152/* reboot */
153void reboot_device(unsigned reboot_reason)
154{
Abhimanyu Kapur002ddf92013-01-28 17:13:13 -0800155 uint32_t version = board_soc_version();
156
Amol Jadi62d7bd22012-10-08 18:15:58 -0700157 /* Write the reboot reason */
Abhimanyu Kapur002ddf92013-01-28 17:13:13 -0800158 if(version >= 0x20000)
159 writel(reboot_reason, RESTART_REASON_ADDR_V2);
160 else
161 writel(reboot_reason, RESTART_REASON_ADDR);
Amol Jadi62d7bd22012-10-08 18:15:58 -0700162
163 /* Configure PMIC for warm reset */
Deepa Dinamani65ac3f12013-03-11 13:42:10 -0700164 /* PM 8019 v1 aligns with PM8941 v2.
165 * This call should be based on the pmic version
166 * when PM8019 v2 is available.
167 */
168 pm8x41_v2_reset_configure(PON_PSHOLD_WARM_RESET);
Amol Jadi62d7bd22012-10-08 18:15:58 -0700169
170 /* Drop PS_HOLD for MSM */
171 writel(0x00, MPM2_MPM_PS_HOLD);
172
173 mdelay(5000);
174
Amol Jadi42d7b5a2012-05-04 14:50:32 -0700175 dprintf(CRITICAL, "Rebooting failed\n");
176 return;
177}
178
Amol Jadi42d7b5a2012-05-04 14:50:32 -0700179/* Identify the current target */
180void target_detect(struct board_data *board)
181{
Amol Jadic12c4322012-10-08 17:24:35 -0700182 /* Not used. set to unknown */
183 board->target = LINUX_MACHTYPE_UNKNOWN;
Amol Jadi42d7b5a2012-05-04 14:50:32 -0700184}
185
Deepa Dinamani28c0ffe2012-09-24 11:45:21 -0700186unsigned board_machtype(void)
187{
188 return board_target_id();
189}
190
Amol Jadi42d7b5a2012-05-04 14:50:32 -0700191/* Identify the baseband being used */
192void target_baseband_detect(struct board_data *board)
193{
Deepa Dinamani28c0ffe2012-09-24 11:45:21 -0700194 /* Check for baseband variants. Default to MSM */
Amol Jadic12c4322012-10-08 17:24:35 -0700195 if (board->platform_subtype == HW_PLATFORM_SUBTYPE_UNKNOWN)
196 {
197 board->baseband = BASEBAND_MSM;
198 }
Deepa Dinamani28c0ffe2012-09-24 11:45:21 -0700199 else
200 {
Amol Jadic12c4322012-10-08 17:24:35 -0700201 dprintf(CRITICAL, "Could not identify baseband id (%d)\n",
202 board->platform_subtype);
Deepa Dinamani28c0ffe2012-09-24 11:45:21 -0700203 ASSERT(0);
204 }
Amol Jadi42d7b5a2012-05-04 14:50:32 -0700205}
Deepa Dinamani56847702012-11-12 16:16:58 -0800206
207unsigned check_reboot_mode(void)
208{
209 unsigned restart_reason = 0;
Abhimanyu Kapur002ddf92013-01-28 17:13:13 -0800210 uint32_t version = board_soc_version();
Deepa Dinamani56847702012-11-12 16:16:58 -0800211
212 /* Read reboot reason and scrub it */
Abhimanyu Kapur002ddf92013-01-28 17:13:13 -0800213 if(version >= 0x20000) {
214 restart_reason = readl(RESTART_REASON_ADDR_V2);
215 writel(0x00, RESTART_REASON_ADDR_V2);
216 }
217 else {
218 restart_reason = readl(RESTART_REASON_ADDR);
219 writel(0x00, RESTART_REASON_ADDR);
220 }
Deepa Dinamani56847702012-11-12 16:16:58 -0800221
222 return restart_reason;
223}
224