blob: 43cde245548badbdbe68f49a33e8d2b5df9902e6 [file] [log] [blame]
Deepa Dinamani28c0ffe2012-09-24 11:45:21 -07001/* Copyright (c) 2012, 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 Dinamanie9ded132012-11-27 15:03:38 -080057/* NANDc EE */
58#define QPIC_NAND_EE 0
59
60/* NANDc max desc length. */
61#define QPIC_NAND_MAX_DESC_LEN 0x7FFF
62
Deepa Dinamani8e6b2432012-10-17 17:12:44 -070063#define LAST_NAND_PTN_LEN_PATTERN 0xFFFFFFFF
64
Deepa Dinamanie4573be2012-08-03 16:32:29 -070065struct qpic_nand_init_config config;
Deepa Dinamani28c0ffe2012-09-24 11:45:21 -070066
67void update_ptable_names(void)
68{
69 uint32_t ptn_index;
70 struct ptentry *ptentry_ptr = flash_ptable.parts;
71 struct ptentry *boot_ptn;
72 unsigned i;
73 uint32_t len;
74
75 /* Change all names to lower case. */
76 for (ptn_index = 0; ptn_index != (uint32_t)flash_ptable.count; ptn_index++)
77 {
78 len = strlen(ptentry_ptr[ptn_index].name);
79
80 for (i = 0; i < len; i++)
81 {
82 if (isupper(ptentry_ptr[ptn_index].name[i]))
83 {
84 ptentry_ptr[ptn_index].name[i] = tolower(ptentry_ptr[ptn_index].name[i]);
85 }
86 }
Deepa Dinamani8e6b2432012-10-17 17:12:44 -070087
88 /* SBL fills in the last partition length as 0xFFFFFFFF.
89 * Update the length field based on the number of blocks on the flash.
90 */
91 if ((uint32_t)(ptentry_ptr[ptn_index].length) == LAST_NAND_PTN_LEN_PATTERN)
92 {
93 ptentry_ptr[ptn_index].length = flash_num_blocks() - ptentry_ptr[ptn_index].start;
94 }
Deepa Dinamani28c0ffe2012-09-24 11:45:21 -070095 }
96
97 /* Rename apps ptn to boot. */
98 boot_ptn = ptable_find(&flash_ptable, "apps");
99 strcpy(boot_ptn->name, "boot");
Deepa Dinamani2a527512012-10-09 15:19:29 -0700100
101 /* Rename appsbl ptn to aboot. */
102 boot_ptn = ptable_find(&flash_ptable, "appsbl");
103 strcpy(boot_ptn->name, "aboot");
Deepa Dinamani28c0ffe2012-09-24 11:45:21 -0700104}
105
Amol Jadi42d7b5a2012-05-04 14:50:32 -0700106/* init */
107void target_init(void)
108{
109 dprintf(INFO, "target_init()\n");
Deepa Dinamanie4573be2012-08-03 16:32:29 -0700110
Amol Jadi62d7bd22012-10-08 18:15:58 -0700111 spmi_init(PMIC_ARB_CHANNEL_NUM, PMIC_ARB_OWNER_ID);
112
Deepa Dinamanie4573be2012-08-03 16:32:29 -0700113 config.pipes.read_pipe = DATA_PRODUCER_PIPE;
114 config.pipes.write_pipe = DATA_CONSUMER_PIPE;
115 config.pipes.cmd_pipe = CMD_PIPE;
116
117 config.bam_base = MSM_NAND_BAM_BASE;
118 config.nand_base = MSM_NAND_BASE;
Deepa Dinamanie9ded132012-11-27 15:03:38 -0800119 config.ee = QPIC_NAND_EE;
120 config.max_desc_len = QPIC_NAND_MAX_DESC_LEN;
Deepa Dinamanie4573be2012-08-03 16:32:29 -0700121
122 qpic_nand_init(&config);
123
Deepa Dinamanie4573be2012-08-03 16:32:29 -0700124 ptable_init(&flash_ptable);
125
Deepa Dinamani28c0ffe2012-09-24 11:45:21 -0700126 smem_ptable_init();
Deepa Dinamanie4573be2012-08-03 16:32:29 -0700127
Deepa Dinamani28c0ffe2012-09-24 11:45:21 -0700128 smem_add_modem_partitions(&flash_ptable);
129
130 update_ptable_names();
131
132 flash_set_ptable(&flash_ptable);
Amol Jadi42d7b5a2012-05-04 14:50:32 -0700133}
134
135/* reboot */
136void reboot_device(unsigned reboot_reason)
137{
Amol Jadi62d7bd22012-10-08 18:15:58 -0700138 /* Write the reboot reason */
139 writel(reboot_reason, RESTART_REASON_ADDR);
140
141 /* Configure PMIC for warm reset */
142 pm8x41_reset_configure(PON_PSHOLD_WARM_RESET);
143
144 /* Drop PS_HOLD for MSM */
145 writel(0x00, MPM2_MPM_PS_HOLD);
146
147 mdelay(5000);
148
Amol Jadi42d7b5a2012-05-04 14:50:32 -0700149 dprintf(CRITICAL, "Rebooting failed\n");
150 return;
151}
152
Amol Jadi42d7b5a2012-05-04 14:50:32 -0700153/* Identify the current target */
154void target_detect(struct board_data *board)
155{
Amol Jadic12c4322012-10-08 17:24:35 -0700156 /* Not used. set to unknown */
157 board->target = LINUX_MACHTYPE_UNKNOWN;
Amol Jadi42d7b5a2012-05-04 14:50:32 -0700158}
159
Deepa Dinamani28c0ffe2012-09-24 11:45:21 -0700160unsigned board_machtype(void)
161{
162 return board_target_id();
163}
164
Amol Jadi42d7b5a2012-05-04 14:50:32 -0700165/* Identify the baseband being used */
166void target_baseband_detect(struct board_data *board)
167{
Deepa Dinamani28c0ffe2012-09-24 11:45:21 -0700168 /* Check for baseband variants. Default to MSM */
Amol Jadic12c4322012-10-08 17:24:35 -0700169 if (board->platform_subtype == HW_PLATFORM_SUBTYPE_UNKNOWN)
170 {
171 board->baseband = BASEBAND_MSM;
172 }
Deepa Dinamani28c0ffe2012-09-24 11:45:21 -0700173 else
174 {
Amol Jadic12c4322012-10-08 17:24:35 -0700175 dprintf(CRITICAL, "Could not identify baseband id (%d)\n",
176 board->platform_subtype);
Deepa Dinamani28c0ffe2012-09-24 11:45:21 -0700177 ASSERT(0);
178 }
Amol Jadi42d7b5a2012-05-04 14:50:32 -0700179}
Deepa Dinamani56847702012-11-12 16:16:58 -0800180
181unsigned check_reboot_mode(void)
182{
183 unsigned restart_reason = 0;
184
185 /* Read reboot reason and scrub it */
186 restart_reason = readl(RESTART_REASON_ADDR);
187 writel(0x00, RESTART_REASON_ADDR);
188
189 return restart_reason;
190}
191