blob: 6be1df5c37825aa215135430f0ce8e2fb745dd3d [file] [log] [blame]
Channagoud Kadabif8ad8e72015-01-06 15:10:13 -08001/* Copyright (c) 2014-2015 The Linux Foundation. All rights reserved.
Channagoud Kadabied60a8b2014-06-27 15:35:09 -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.
12 * * Neither the name of The Linux Foundation nor the names of its
13 * 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 */
28
29#include <debug.h>
30#include <platform/iomap.h>
31#include <platform/irqs.h>
32#include <platform/gpio.h>
33#include <reg.h>
34#include <target.h>
35#include <platform.h>
36#include <dload_util.h>
37#include <uart_dm.h>
38#include <mmc.h>
39#include <spmi.h>
40#include <board.h>
41#include <smem.h>
42#include <baseband.h>
43#include <dev/keys.h>
44#include <pm8x41.h>
45#include <crypto5_wrapper.h>
46#include <clock.h>
47#include <partition_parser.h>
48#include <scm.h>
49#include <platform/clock.h>
50#include <platform/gpio.h>
51#include <platform/timer.h>
52#include <stdlib.h>
53#include <ufs.h>
54#include <boot_device.h>
55#include <qmp_phy.h>
Channagoud Kadabi7d308202014-12-22 12:07:04 -080056#include <sdhci_msm.h>
57#include <qusb2_phy.h>
Channagoud Kadabied60a8b2014-06-27 15:35:09 -070058
59#define PMIC_ARB_CHANNEL_NUM 0
60#define PMIC_ARB_OWNER_ID 0
61
62static void set_sdc_power_ctrl(void);
63static uint32_t mmc_pwrctl_base[] =
64 { MSM_SDC1_BASE, MSM_SDC2_BASE };
65
66static uint32_t mmc_sdhci_base[] =
67 { MSM_SDC1_SDHCI_BASE, MSM_SDC2_SDHCI_BASE };
68
69static uint32_t mmc_sdc_pwrctl_irq[] =
70 { SDCC1_PWRCTL_IRQ, SDCC2_PWRCTL_IRQ };
71
72struct mmc_device *dev;
73struct ufs_dev ufs_device;
74
75extern void ulpi_write(unsigned val, unsigned reg);
76
77void target_early_init(void)
78{
79#if WITH_DEBUG_UART
Channagoud Kadabi35503c42014-11-14 16:22:43 -080080 uart_dm_init(8, 0, BLSP2_UART1_BASE);
Channagoud Kadabied60a8b2014-06-27 15:35:09 -070081#endif
82}
83
84/* Return 1 if vol_up pressed */
85static int target_volume_up()
86{
87 uint8_t status = 0;
88 struct pm8x41_gpio gpio;
89
90 /* Configure the GPIO */
91 gpio.direction = PM_GPIO_DIR_IN;
92 gpio.function = 0;
93 gpio.pull = PM_GPIO_PULL_UP_30;
94 gpio.vin_sel = 2;
95
96 pm8x41_gpio_config(2, &gpio);
97
98 /* Wait for the pmic gpio config to take effect */
99 thread_sleep(1);
100
101 /* Get status of P_GPIO_5 */
102 pm8x41_gpio_get(3, &status);
103
104 return !status; /* active low */
105}
106
107/* Return 1 if vol_down pressed */
108uint32_t target_volume_down()
109{
110 return pm8x41_resin_status();
111}
112
113static void target_keystatus()
114{
115 keys_init();
116
117 if(target_volume_down())
118 keys_post_event(KEY_VOLUMEDOWN, 1);
119
120 if(target_volume_up())
121 keys_post_event(KEY_VOLUMEUP, 1);
122}
123
124void target_uninit(void)
125{
126 if (platform_boot_dev_isemmc())
127 {
128 mmc_put_card_to_sleep(dev);
129 /* Disable HC mode before jumping to kernel */
130 sdhci_mode_disable(&dev->host);
131 }
132}
133
134static void set_sdc_power_ctrl()
135{
136 /* Drive strength configs for sdc pins */
137 struct tlmm_cfgs sdc1_hdrv_cfg[] =
138 {
139 { SDC1_CLK_HDRV_CTL_OFF, TLMM_CUR_VAL_16MA, TLMM_HDRV_MASK, SDC1_HDRV_PULL_CTL },
140 { SDC1_CMD_HDRV_CTL_OFF, TLMM_CUR_VAL_10MA, TLMM_HDRV_MASK, SDC1_HDRV_PULL_CTL },
141 { SDC1_DATA_HDRV_CTL_OFF, TLMM_CUR_VAL_10MA, TLMM_HDRV_MASK, SDC1_HDRV_PULL_CTL },
142 };
143
144 /* Pull configs for sdc pins */
145 struct tlmm_cfgs sdc1_pull_cfg[] =
146 {
147 { SDC1_CLK_PULL_CTL_OFF, TLMM_NO_PULL, TLMM_PULL_MASK, SDC1_HDRV_PULL_CTL },
148 { SDC1_CMD_PULL_CTL_OFF, TLMM_PULL_UP, TLMM_PULL_MASK, SDC1_HDRV_PULL_CTL },
149 { SDC1_DATA_PULL_CTL_OFF, TLMM_PULL_UP, TLMM_PULL_MASK, SDC1_HDRV_PULL_CTL },
150 };
151
152 struct tlmm_cfgs sdc1_rclk_cfg[] =
153 {
154 { SDC1_RCLK_PULL_CTL_OFF, TLMM_PULL_DOWN, TLMM_PULL_MASK, SDC1_HDRV_PULL_CTL },
155 };
156
157 /* Set the drive strength & pull control values */
158 tlmm_set_hdrive_ctrl(sdc1_hdrv_cfg, ARRAY_SIZE(sdc1_hdrv_cfg));
159 tlmm_set_pull_ctrl(sdc1_pull_cfg, ARRAY_SIZE(sdc1_pull_cfg));
160 tlmm_set_pull_ctrl(sdc1_rclk_cfg, ARRAY_SIZE(sdc1_rclk_cfg));
161}
162
163void target_sdc_init()
164{
165 struct mmc_config_data config = {0};
166
167 /* Set drive strength & pull ctrl values */
168 set_sdc_power_ctrl();
169
170 config.bus_width = DATA_BUS_WIDTH_8BIT;
171 config.max_clk_rate = MMC_CLK_192MHZ;
172
173 /* Try slot 1*/
174 config.slot = 1;
175 config.sdhc_base = mmc_sdhci_base[config.slot - 1];
176 config.pwrctl_base = mmc_pwrctl_base[config.slot - 1];
177 config.pwr_irq = mmc_sdc_pwrctl_irq[config.slot - 1];
178
179 if (!(dev = mmc_init(&config)))
180 {
181 /* Try slot 2 */
182 config.slot = 2;
183 config.max_clk_rate = MMC_CLK_200MHZ;
184 config.sdhc_base = mmc_sdhci_base[config.slot - 1];
185 config.pwrctl_base = mmc_pwrctl_base[config.slot - 1];
186 config.pwr_irq = mmc_sdc_pwrctl_irq[config.slot - 1];
187
188 if (!(dev = mmc_init(&config)))
189 {
190 dprintf(CRITICAL, "mmc init failed!");
191 ASSERT(0);
192 }
193 }
194}
195
196void *target_mmc_device()
197{
198 if (platform_boot_dev_isemmc())
199 return (void *) dev;
200 else
201 return (void *) &ufs_device;
202}
203
204void target_init(void)
205{
206 dprintf(INFO, "target_init()\n");
207
208 spmi_init(PMIC_ARB_CHANNEL_NUM, PMIC_ARB_OWNER_ID);
209
210 target_keystatus();
211
212 if (target_use_signed_kernel())
213 target_crypto_init_params();
214
215 platform_read_boot_config();
216
217 if (platform_boot_dev_isemmc())
218 {
219 target_sdc_init();
220 }
221 else
222 {
223 ufs_device.base = UFS_BASE;
224 ufs_init(&ufs_device);
225 }
226
227 /* Storage initialization is complete, read the partition table info */
228 if (partition_read_table())
229 {
230 dprintf(CRITICAL, "Error reading the partition table info\n");
231 ASSERT(0);
232 }
233}
234
235unsigned board_machtype(void)
236{
237 return LINUX_MACHTYPE_UNKNOWN;
238}
239
240/* Detect the target type */
241void target_detect(struct board_data *board)
242{
243 /* This is filled from board.c */
244}
245
246/* Detect the modem type */
247void target_baseband_detect(struct board_data *board)
248{
249 uint32_t platform;
250
251 platform = board->platform;
252
253 switch(platform) {
254 case MSMTHULIUM:
255 board->baseband = BASEBAND_MSM;
256 break;
257 default:
258 dprintf(CRITICAL, "Platform type: %u is not supported\n",platform);
259 ASSERT(0);
260 };
261}
262unsigned target_baseband()
263{
264 return board_baseband();
265}
266
267void target_serialno(unsigned char *buf)
268{
269 unsigned int serialno;
270 if (target_is_emmc_boot()) {
271 serialno = mmc_get_psn();
272 snprintf((char *)buf, 13, "%x", serialno);
273 }
274}
275
276unsigned check_reboot_mode(void)
277{
278 uint32_t restart_reason = 0;
279 uint32_t restart_reason_addr;
280
281 restart_reason_addr = RESTART_REASON_ADDR;
282
283 /* Read reboot reason and scrub it */
284 restart_reason = readl(restart_reason_addr);
285 writel(0x00, restart_reason_addr);
286
287 return restart_reason;
288}
289
290void reboot_device(unsigned reboot_reason)
291{
292 uint8_t reset_type = 0;
293
294 /* Write the reboot reason */
295 writel(reboot_reason, RESTART_REASON_ADDR);
296
297 if(reboot_reason)
298 reset_type = PON_PSHOLD_WARM_RESET;
299 else
300 reset_type = PON_PSHOLD_HARD_RESET;
301
302 pm8x41_reset_configure(reset_type);
303
304 /* Drop PS_HOLD for MSM */
305 writel(0x00, MPM2_MPM_PS_HOLD);
306
307 mdelay(5000);
308
309 dprintf(CRITICAL, "Rebooting failed\n");
310}
311
312int emmc_recovery_init(void)
313{
314 return _emmc_recovery_init();
315}
316
317void target_usb_phy_reset()
318{
Channagoud Kadabif8ad8e72015-01-06 15:10:13 -0800319#ifndef USE_HSONLY_MODE
Channagoud Kadabied60a8b2014-06-27 15:35:09 -0700320 usb30_qmp_phy_reset();
Channagoud Kadabif8ad8e72015-01-06 15:10:13 -0800321#endif
Channagoud Kadabied60a8b2014-06-27 15:35:09 -0700322 qusb2_phy_reset();
323}
324
325target_usb_iface_t* target_usb30_init()
326{
327 target_usb_iface_t *t_usb_iface;
328
329 t_usb_iface = calloc(1, sizeof(target_usb_iface_t));
330 ASSERT(t_usb_iface);
331
Channagoud Kadabif8ad8e72015-01-06 15:10:13 -0800332#ifndef USE_HSONLY_MODE
Channagoud Kadabied60a8b2014-06-27 15:35:09 -0700333 t_usb_iface->phy_init = usb30_qmp_phy_init;
Channagoud Kadabif8ad8e72015-01-06 15:10:13 -0800334#endif
335
Channagoud Kadabied60a8b2014-06-27 15:35:09 -0700336 t_usb_iface->phy_reset = target_usb_phy_reset;
337 t_usb_iface->clock_init = clock_usb30_init;
338 t_usb_iface->vbus_override = 1;
339
340 return t_usb_iface;
341}
342
343/* identify the usb controller to be used for the target */
344const char * target_usb_controller()
345{
346 return "dwc";
347}
348
349uint32_t target_override_pll()
350{
351 return 1;
352}
353
354void target_fastboot_init(void)
355{
356 /* We are entering fastboot mode, so read partition table */
357 mmc_read_partition_table(1);
358}