blob: e17f796897c2277fcf8ef1a49a97130fd46909ac [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
Deepa Dinamanidca5c662012-12-03 14:13:07 -0800106void target_early_init(void)
107{
108#if WITH_DEBUG_UART
109 uart_dm_init(3, 0, MSM_UART2_BASE);
110#endif
111}
112
113
Amol Jadi42d7b5a2012-05-04 14:50:32 -0700114/* init */
115void target_init(void)
116{
117 dprintf(INFO, "target_init()\n");
Deepa Dinamanie4573be2012-08-03 16:32:29 -0700118
Amol Jadi62d7bd22012-10-08 18:15:58 -0700119 spmi_init(PMIC_ARB_CHANNEL_NUM, PMIC_ARB_OWNER_ID);
120
Deepa Dinamanie4573be2012-08-03 16:32:29 -0700121 config.pipes.read_pipe = DATA_PRODUCER_PIPE;
122 config.pipes.write_pipe = DATA_CONSUMER_PIPE;
123 config.pipes.cmd_pipe = CMD_PIPE;
124
125 config.bam_base = MSM_NAND_BAM_BASE;
126 config.nand_base = MSM_NAND_BASE;
Deepa Dinamanie9ded132012-11-27 15:03:38 -0800127 config.ee = QPIC_NAND_EE;
128 config.max_desc_len = QPIC_NAND_MAX_DESC_LEN;
Deepa Dinamanie4573be2012-08-03 16:32:29 -0700129
130 qpic_nand_init(&config);
131
Deepa Dinamanie4573be2012-08-03 16:32:29 -0700132 ptable_init(&flash_ptable);
133
Deepa Dinamani28c0ffe2012-09-24 11:45:21 -0700134 smem_ptable_init();
Deepa Dinamanie4573be2012-08-03 16:32:29 -0700135
Deepa Dinamani28c0ffe2012-09-24 11:45:21 -0700136 smem_add_modem_partitions(&flash_ptable);
137
138 update_ptable_names();
139
140 flash_set_ptable(&flash_ptable);
Amol Jadi42d7b5a2012-05-04 14:50:32 -0700141}
142
143/* reboot */
144void reboot_device(unsigned reboot_reason)
145{
Amol Jadi62d7bd22012-10-08 18:15:58 -0700146 /* Write the reboot reason */
147 writel(reboot_reason, RESTART_REASON_ADDR);
148
149 /* Configure PMIC for warm reset */
150 pm8x41_reset_configure(PON_PSHOLD_WARM_RESET);
151
152 /* Drop PS_HOLD for MSM */
153 writel(0x00, MPM2_MPM_PS_HOLD);
154
155 mdelay(5000);
156
Amol Jadi42d7b5a2012-05-04 14:50:32 -0700157 dprintf(CRITICAL, "Rebooting failed\n");
158 return;
159}
160
Amol Jadi42d7b5a2012-05-04 14:50:32 -0700161/* Identify the current target */
162void target_detect(struct board_data *board)
163{
Amol Jadic12c4322012-10-08 17:24:35 -0700164 /* Not used. set to unknown */
165 board->target = LINUX_MACHTYPE_UNKNOWN;
Amol Jadi42d7b5a2012-05-04 14:50:32 -0700166}
167
Deepa Dinamani28c0ffe2012-09-24 11:45:21 -0700168unsigned board_machtype(void)
169{
170 return board_target_id();
171}
172
Amol Jadi42d7b5a2012-05-04 14:50:32 -0700173/* Identify the baseband being used */
174void target_baseband_detect(struct board_data *board)
175{
Deepa Dinamani28c0ffe2012-09-24 11:45:21 -0700176 /* Check for baseband variants. Default to MSM */
Amol Jadic12c4322012-10-08 17:24:35 -0700177 if (board->platform_subtype == HW_PLATFORM_SUBTYPE_UNKNOWN)
178 {
179 board->baseband = BASEBAND_MSM;
180 }
Deepa Dinamani28c0ffe2012-09-24 11:45:21 -0700181 else
182 {
Amol Jadic12c4322012-10-08 17:24:35 -0700183 dprintf(CRITICAL, "Could not identify baseband id (%d)\n",
184 board->platform_subtype);
Deepa Dinamani28c0ffe2012-09-24 11:45:21 -0700185 ASSERT(0);
186 }
Amol Jadi42d7b5a2012-05-04 14:50:32 -0700187}
Deepa Dinamani56847702012-11-12 16:16:58 -0800188
189unsigned check_reboot_mode(void)
190{
191 unsigned restart_reason = 0;
192
193 /* Read reboot reason and scrub it */
194 restart_reason = readl(RESTART_REASON_ADDR);
195 writel(0x00, RESTART_REASON_ADDR);
196
197 return restart_reason;
198}
199