blob: a11e23b79c7a58b8c93fe940492250f1001ef075 [file] [log] [blame]
Deepa Dinamani7d6c8972011-12-14 15:16:56 -08001/*
Amol Jadi29f95032012-06-22 12:52:54 -07002 * Copyright (c) 2012, Code Aurora Forum. All rights reserved.
Deepa Dinamani7d6c8972011-12-14 15:16:56 -08003 *
4 * Redistribution and use in source and binary forms, with or without
5 * modification, are permitted provided that the following conditions
6 * are met:
7 * * Redistributions of source code must retain the above copyright
8 * notice, this list of conditions and the following disclaimer.
9 * * Redistributions in binary form must reproduce the above copyright
10 * notice, this list of conditions and the following disclaimer in
11 * the documentation and/or other materials provided with the
12 * distribution.
13 * * Neither the name of Google, Inc. nor the names of its contributors
14 * may be used to endorse or promote products derived from this
15 * software without specific prior written permission.
16 *
17 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
18 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
19 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
20 * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
21 * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
22 * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
23 * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS
24 * OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
25 * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
26 * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
27 * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
28 * SUCH DAMAGE.
29 */
30
31#include <debug.h>
32#include <platform/iomap.h>
33#include <reg.h>
34#include <target.h>
35#include <platform.h>
Deepa Dinamani26e93262012-05-21 17:35:14 -070036#include <uart_dm.h>
Amol Jadi29f95032012-06-22 12:52:54 -070037#include <mmc.h>
Deepa Dinamanic2a9b362012-02-23 15:15:54 -080038#include <spmi.h>
Neeti Desai465491e2012-07-31 12:53:35 -070039#include <board.h>
40#include <smem.h>
41#include <baseband.h>
Deepa Dinamani9a612932012-08-14 16:15:03 -070042#include <dev/keys.h>
43#include <pm8x41.h>
Deepa Dinamani7d6c8972011-12-14 15:16:56 -080044
45static unsigned int target_id;
Deepa Dinamani7d6c8972011-12-14 15:16:56 -080046
Deepa Dinamanic2a9b362012-02-23 15:15:54 -080047#define PMIC_ARB_CHANNEL_NUM 0
48#define PMIC_ARB_OWNER_ID 0
49
Deepa Dinamani7d6c8972011-12-14 15:16:56 -080050
Deepa Dinamanica5ad852012-05-07 18:19:47 -070051static uint32_t mmc_sdc_base[] =
52 { MSM_SDC1_BASE, MSM_SDC2_BASE, MSM_SDC3_BASE, MSM_SDC4_BASE };
53
Deepa Dinamani7d6c8972011-12-14 15:16:56 -080054void target_early_init(void)
55{
Deepa Dinamanib073ba22012-08-10 11:06:41 -070056#if WITH_DEBUG_UART
Amol Jadi29f95032012-06-22 12:52:54 -070057 uart_dm_init(0, 0, BLSP1_UART0_BASE);
Deepa Dinamanib073ba22012-08-10 11:06:41 -070058#endif
Deepa Dinamani7d6c8972011-12-14 15:16:56 -080059}
60
Deepa Dinamani9a612932012-08-14 16:15:03 -070061/* Return 1 if vol_up pressed */
62static int target_volume_up()
63{
64 uint8_t status = 0;
65 struct pm8x41_gpio gpio;
66
67 /* CDP vol_up seems to be always grounded. So gpio status is read as 0,
68 * whether key is pressed or not.
69 * Ignore volume_up key on CDP for now.
70 */
71 if (board_hardware_id() == HW_PLATFORM_SURF)
72 return 0;
73
74 /* Configure the GPIO */
75 gpio.direction = PM_GPIO_DIR_IN;
76 gpio.function = 0;
77 gpio.pull = PM_GPIO_PULL_UP_30;
78 gpio.vin_sel = 0;
79
80 pm8x41_gpio_config(5, &gpio);
81
82 /* Get status of P_GPIO_5 */
83 pm8x41_gpio_get(5, &status);
84
85 return !status; /* active low */
86}
87
88/* Return 1 if vol_down pressed */
89int target_volume_down()
90{
91 return pm8x41_vol_down_key_status();
92}
93
94static void target_keystatus()
95{
96 keys_init();
97
98 if(target_volume_down())
99 keys_post_event(KEY_VOLUMEDOWN, 1);
100
101 if(target_volume_up())
102 keys_post_event(KEY_VOLUMEUP, 1);
103}
104
Deepa Dinamani7d6c8972011-12-14 15:16:56 -0800105void target_init(void)
106{
Deepa Dinamanica5ad852012-05-07 18:19:47 -0700107 uint32_t base_addr;
108 uint8_t slot;
Deepa Dinamani7d6c8972011-12-14 15:16:56 -0800109
Deepa Dinamani26e93262012-05-21 17:35:14 -0700110
Deepa Dinamani7d6c8972011-12-14 15:16:56 -0800111 dprintf(INFO, "target_init()\n");
112
Deepa Dinamanic2a9b362012-02-23 15:15:54 -0800113 spmi_init(PMIC_ARB_CHANNEL_NUM, PMIC_ARB_OWNER_ID);
Deepa Dinamani7d6c8972011-12-14 15:16:56 -0800114
Deepa Dinamani9a612932012-08-14 16:15:03 -0700115 target_keystatus();
116
Deepa Dinamanica5ad852012-05-07 18:19:47 -0700117 /* Trying Slot 1*/
118 slot = 1;
119 base_addr = mmc_sdc_base[slot - 1];
120 if (mmc_boot_main(slot, base_addr))
121 {
Deepa Dinamanid18b47a2012-06-27 13:06:03 -0700122
123 /* Trying Slot 2 next */
124 slot = 2;
125 base_addr = mmc_sdc_base[slot - 1];
126 if (mmc_boot_main(slot, base_addr)) {
127 dprintf(CRITICAL, "mmc init failed!");
128 ASSERT(0);
129 }
Deepa Dinamanica5ad852012-05-07 18:19:47 -0700130 }
Deepa Dinamani7d6c8972011-12-14 15:16:56 -0800131}
132
133unsigned board_machtype(void)
134{
135 return target_id;
136}
137
138/* Do any target specific intialization needed before entering fastboot mode */
139void target_fastboot_init(void)
140{
Deepa Dinamani9a612932012-08-14 16:15:03 -0700141 /* Set the BOOT_DONE flag in PM8921 */
142 pm8x41_set_boot_done();
Deepa Dinamani7d6c8972011-12-14 15:16:56 -0800143}
Neeti Desai465491e2012-07-31 12:53:35 -0700144
145/* Detect the target type */
146void target_detect(struct board_data *board)
147{
148 board->target = LINUX_MACHTYPE_UNKNOWN;
149}
150
151/* Detect the modem type */
152void target_baseband_detect(struct board_data *board)
153{
154 /* Check for baseband variants. Default to MSM */
155 if (board->platform_subtype == HW_PLATFORM_SUBTYPE_MDM)
156 board->baseband = BASEBAND_MDM;
157 else
158 board->baseband = BASEBAND_MSM;
159}
Deepa Dinamani9a612932012-08-14 16:15:03 -0700160
161void target_serialno(unsigned char *buf)
162{
163 unsigned int serialno;
164 if (target_is_emmc_boot()) {
165 serialno = mmc_get_psn();
166 snprintf((char *)buf, 13, "%x", serialno);
167 }
168}