blob: 4267381ba21000de46ec357033b86e2dbd5dd3d8 [file] [log] [blame]
Amol Jadica4f4c92011-01-13 20:19:34 -08001/*
2 * Copyright (c) 2009, Google Inc.
3 * All rights reserved.
4 * Copyright (c) 2009-2011, Code Aurora Forum. All rights reserved.
5 *
6 * Redistribution and use in source and binary forms, with or without
7 * modification, are permitted provided that the following conditions
8 * are met:
9 * * Redistributions of source code must retain the above copyright
10 * notice, this list of conditions and the following disclaimer.
11 * * Redistributions in binary form must reproduce the above copyright
12 * notice, this list of conditions and the following disclaimer in
13 * the documentation and/or other materials provided with the
14 * distribution.
15 * * Neither the name of Google, Inc. nor the names of its contributors
16 * may be used to endorse or promote products derived from this
17 * software without specific prior written permission.
18 *
19 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
20 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
21 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
22 * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
23 * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
24 * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
25 * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS
26 * OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
27 * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
28 * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
29 * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
30 * SUCH DAMAGE.
31 */
32
33#include <debug.h>
34#include <lib/ptable.h>
35#include <smem.h>
36#include <platform/iomap.h>
Greg Griscod6250552011-06-29 14:40:23 -070037#include <mmc.h>
38#include <platform/timer.h>
Amol Jadica4f4c92011-01-13 20:19:34 -080039#include <reg.h>
Amol Jadi6db9fe32011-04-15 17:19:00 -070040#include <dev/keys.h>
Amol Jadi57abe4c2011-05-24 15:47:27 -070041#include <dev/pm8921.h>
42#include <dev/gpio_keypad.h>
Amol Jadic52c8a32011-07-12 11:27:04 -070043#include <gsbi.h>
Greg Griscod2471ef2011-07-14 13:00:42 -070044#include <target.h>
Greg Grisco1073a5e2011-07-28 18:59:18 -070045#include <platform.h>
Amol Jadica4f4c92011-01-13 20:19:34 -080046
47#define LINUX_MACHTYPE_8960_SIM 3230
48#define LINUX_MACHTYPE_8960_RUMI3 3231
Shashank Mittald67508a2011-05-06 19:18:42 -070049#define LINUX_MACHTYPE_8960_CDP 3396
50#define LINUX_MACHTYPE_8960_MTP 3397
51#define LINUX_MACHTYPE_8960_FLUID 3398
52#define LINUX_MACHTYPE_8960_APQ 3399
Amir Samuelov6a9871b2011-07-31 14:38:05 +030053#define LINUX_MACHTYPE_8960_LIQUID 3535
Amol Jadica4f4c92011-01-13 20:19:34 -080054
Greg Griscod2471ef2011-07-14 13:00:42 -070055
Amol Jadicd43ea02011-02-15 20:56:04 -080056extern void dmb(void);
Amol Jadi6db9fe32011-04-15 17:19:00 -070057extern void keypad_init(void);
Greg Griscod2471ef2011-07-14 13:00:42 -070058extern void panel_backlight_on(void);
Amol Jadicd43ea02011-02-15 20:56:04 -080059
Shashank Mittalda89a682011-03-14 19:18:38 -070060static unsigned mmc_sdc_base[] = { MSM_SDC1_BASE, MSM_SDC2_BASE, MSM_SDC3_BASE, MSM_SDC4_BASE};
61
Amol Jadi57abe4c2011-05-24 15:47:27 -070062static pm8921_dev_t pmic;
63
Amol Jadic52c8a32011-07-12 11:27:04 -070064static const uint8_t uart_gsbi_id = GSBI_ID_5;
65
Shashank Mittal39503262011-07-19 11:41:35 -070066void shutdown_device(void)
67{
68 dprintf(CRITICAL, "Shutdown system.\n");
69 pm8921_config_reset_pwr_off(0);
70
71 /* Actually reset the chip */
72 writel(0, MSM_PSHOLD_CTL_SU);
73 mdelay(5000);
74
75 dprintf (CRITICAL, "Shutdown failed.\n");
76}
77
Amol Jadica4f4c92011-01-13 20:19:34 -080078void target_init(void)
79{
Shashank Mittalda89a682011-03-14 19:18:38 -070080 unsigned base_addr;
81 unsigned char slot;
Amol Jadica4f4c92011-01-13 20:19:34 -080082 dprintf(INFO, "target_init()\n");
83
Amol Jadi57abe4c2011-05-24 15:47:27 -070084 /* Initialize PMIC driver */
Greg Griscod2471ef2011-07-14 13:00:42 -070085 pmic.read = (pm8921_read_func) &pa1_ssbi2_read_bytes;
86 pmic.write = (pm8921_write_func) &pa1_ssbi2_write_bytes;
Amol Jadi57abe4c2011-05-24 15:47:27 -070087
88 pm8921_init(&pmic);
Amol Jadi6db9fe32011-04-15 17:19:00 -070089 /* Keypad init */
90 keys_init();
91 keypad_init();
92
Kinson Chikce306ff2011-07-08 15:23:33 -070093 /* Display splash screen if enabled */
94#if DISPLAY_SPLASH_SCREEN
95 panel_backlight_on();
96 display_init();
97 dprintf(SPEW, "Diplay initialized\n");
98 display_image_on_screen();
99#endif
100
Shashank Mittalda89a682011-03-14 19:18:38 -0700101 /* Trying Slot 1 first */
102 slot = 1;
103 base_addr = mmc_sdc_base[slot-1];
104 if(mmc_boot_main(slot, base_addr))
Amol Jadica4f4c92011-01-13 20:19:34 -0800105 {
Shashank Mittalda89a682011-03-14 19:18:38 -0700106 /* Trying Slot 3 next */
107 slot = 3;
108 base_addr = mmc_sdc_base[slot-1];
109 if(mmc_boot_main(slot, base_addr))
110 {
111 dprintf(CRITICAL, "mmc init failed!");
112 ASSERT(0);
113 }
Amol Jadica4f4c92011-01-13 20:19:34 -0800114 }
115}
116
117unsigned board_machtype(void)
118{
Shashank Mittalda89a682011-03-14 19:18:38 -0700119 struct smem_board_info_v6 board_info_v6;
120 unsigned int board_info_len = 0;
121 unsigned smem_status = 0;
122 unsigned format = 0;
Amol Jadi64c58c12011-05-11 13:40:25 -0700123 unsigned id = HW_PLATFORM_UNKNOWN;
124 unsigned mach_id;
Amol Jadica4f4c92011-01-13 20:19:34 -0800125
Shashank Mittald67508a2011-05-06 19:18:42 -0700126
Shashank Mittalda89a682011-03-14 19:18:38 -0700127 smem_status = smem_read_alloc_entry_offset(SMEM_BOARD_INFO_LOCATION,
128 &format, sizeof(format), 0);
129 if(!smem_status)
130 {
Amol Jadi64c58c12011-05-11 13:40:25 -0700131 if (format == 6)
Shashank Mittalda89a682011-03-14 19:18:38 -0700132 {
133 board_info_len = sizeof(board_info_v6);
134
135 smem_status = smem_read_alloc_entry(SMEM_BOARD_INFO_LOCATION,
136 &board_info_v6, board_info_len);
137 if(!smem_status)
138 {
139 id = board_info_v6.board_info_v3.hw_platform;
140 }
141 }
142 }
143
Amol Jadi64c58c12011-05-11 13:40:25 -0700144 /* Detect the board we are running on */
Shashank Mittalda89a682011-03-14 19:18:38 -0700145 switch(id)
146 {
147 case HW_PLATFORM_SURF:
Amol Jadi64c58c12011-05-11 13:40:25 -0700148 mach_id = LINUX_MACHTYPE_8960_CDP;
Shashank Mittalda89a682011-03-14 19:18:38 -0700149 break;
Trevor Bourget0c109372011-08-03 12:11:08 -0700150 case HW_PLATFORM_MTP:
Amol Jadi64c58c12011-05-11 13:40:25 -0700151 mach_id = LINUX_MACHTYPE_8960_MTP;
152 break;
153 case HW_PLATFORM_FLUID:
154 mach_id = LINUX_MACHTYPE_8960_FLUID;
Shashank Mittalda89a682011-03-14 19:18:38 -0700155 break;
Amir Samuelov6a9871b2011-07-31 14:38:05 +0300156 case HW_PLATFORM_LIQUID:
157 mach_id = LINUX_MACHTYPE_8960_LIQUID;
158 break;
Shashank Mittalda89a682011-03-14 19:18:38 -0700159 default:
Amol Jadi64c58c12011-05-11 13:40:25 -0700160 mach_id = LINUX_MACHTYPE_8960_CDP;
Shashank Mittalda89a682011-03-14 19:18:38 -0700161 };
162
163 return mach_id;
Amol Jadica4f4c92011-01-13 20:19:34 -0800164}
165
166void reboot_device(unsigned reboot_reason)
167{
Shashank Mittal6239b162011-06-28 17:59:33 -0700168 /* Actually reset the chip */
Shashank Mittal39503262011-07-19 11:41:35 -0700169 pm8921_config_reset_pwr_off(1);
Shashank Mittal6239b162011-06-28 17:59:33 -0700170 writel(0, MSM_PSHOLD_CTL_SU);
Amol Jadica4f4c92011-01-13 20:19:34 -0800171 mdelay(10000);
Shashank Mittal39503262011-07-19 11:41:35 -0700172
Amol Jadica4f4c92011-01-13 20:19:34 -0800173 dprintf (CRITICAL, "Rebooting failed\n");
174 return;
175}
176
177unsigned check_reboot_mode(void)
178{
179 unsigned restart_reason = 0;
Amol Jadica4f4c92011-01-13 20:19:34 -0800180
181 /* Read reboot reason and scrub it */
Shashank Mittal0207df72011-06-15 15:20:43 -0700182 restart_reason = readl(RESTART_REASON_ADDR);
183 writel(0x00, RESTART_REASON_ADDR);
Amol Jadica4f4c92011-01-13 20:19:34 -0800184
185 return restart_reason;
186}
187
Ajay Dudani12091e22011-05-06 17:13:23 -0700188void target_serialno(unsigned char *buf)
189{
190 unsigned int serialno;
191 if(target_is_emmc_boot())
192 {
193 serialno = mmc_get_psn();
Greg Griscod6250552011-06-29 14:40:23 -0700194 sprintf((char *) buf,"%x",serialno);
Ajay Dudani12091e22011-05-06 17:13:23 -0700195 }
196}
197
Amol Jadica4f4c92011-01-13 20:19:34 -0800198void target_battery_charging_enable(unsigned enable, unsigned disconnect)
199{
200}
Amol Jadi57abe4c2011-05-24 15:47:27 -0700201
202/* Do any target specific intialization needed before entering fastboot mode */
203void target_fastboot_init(void)
204{
205 /* Set the BOOT_DONE flag in PM8921 */
206 pm8921_boot_done();
207}
Amol Jadic52c8a32011-07-12 11:27:04 -0700208
209uint8_t target_uart_gsbi(void)
210{
211 return uart_gsbi_id;
212}