blob: 9f4ad32fa0b7ac94928d9cab54b9e48e1f48da24 [file] [log] [blame]
Anmolpreet Kaur7de805b2019-02-21 17:58:18 +05301/* Copyright (c) 2014-2016,2019 The Linux Foundation. All rights reserved.
Sundarajan Srinivasan34bbe072014-03-21 17:27:16 -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#include <debug.h>
29#include <mmc.h>
30#include <ufs.h>
Channagoud Kadabi8fb2ab52015-06-02 16:19:24 -070031#include <board.h>
Sundarajan Srinivasan34bbe072014-03-21 17:27:16 -070032#include <platform/iomap.h>
33#include <boot_device.h>
Smita Ghoshf5431c62014-09-18 14:11:14 -070034#include <qpic_nand.h>
Sundarajan Srinivasan34bbe072014-03-21 17:27:16 -070035
36static uint32_t boot_device;
37
38void platform_read_boot_config()
39{
40 boot_device = BOOT_DEVICE_MASK(readl(BOOT_CONFIG_REG));
Channagoud Kadabi8fb2ab52015-06-02 16:19:24 -070041 board_update_boot_dev(boot_device);
Sundarajan Srinivasan34bbe072014-03-21 17:27:16 -070042}
43
44uint32_t platform_get_boot_dev()
45{
46 return boot_device;
47}
48
49/*
50 * Return 1 if boot from emmc else 0
51 */
52uint32_t platform_boot_dev_isemmc()
53{
54 uint32_t boot_dev_type;
55
56 boot_dev_type = platform_get_boot_dev();
57
Channagoud Kadabic42ea322014-10-10 12:26:54 -070058#if USE_MDM_BOOT_CFG
59 /* For MDM default boot device is NAND */
60 if (boot_dev_type == BOOT_EMMC)
61#else
Sundarajan Srinivasan34bbe072014-03-21 17:27:16 -070062 if (boot_dev_type == BOOT_EMMC || boot_dev_type == BOOT_DEFAULT)
Channagoud Kadabic42ea322014-10-10 12:26:54 -070063#endif
Sundarajan Srinivasan34bbe072014-03-21 17:27:16 -070064 boot_dev_type = 1;
65 else
66 boot_dev_type = 0;
67
68 return boot_dev_type;
69}
70
Anmolpreet Kaur7de805b2019-02-21 17:58:18 +053071/*
72 * Return 1 if boot from NAND else 0
73 * For MDM : If the device is not Emmc,
74 * By default : It is treated as NAND
75 * For non-MDM (MSM) : If the device is neither EMMC nor UFS
76 * It will be treated as NAND.
77 * BOOT_DEFAULT in case of Non-MDM targets is EMMC.
78 */
79uint32_t platform_boot_dev_is_nand()
80{
81 uint32_t val = 0;
82
83 val = platform_get_boot_dev();
84 switch(val)
85 {
86#if USE_MDM_BOOT_CFG
87 case BOOT_EMMC:
88 return 0;
89#else
90 case BOOT_DEFAULT:
91 case BOOT_EMMC:
92 case BOOT_UFS:
93 return 0;
94#endif
95 default:
96 return 1;
97 };
98}
99
Sundarajan Srinivasan34bbe072014-03-21 17:27:16 -0700100void platform_boot_dev_cmdline(char *buf)
101{
102 uint32_t val = 0;
Veera Sundaram Sankaran00181512014-12-09 11:23:39 -0800103 void *dev = target_mmc_device();
Sundarajan Srinivasan34bbe072014-03-21 17:27:16 -0700104
105 val = platform_get_boot_dev();
106 switch(val)
107 {
Channagoud Kadabic42ea322014-10-10 12:26:54 -0700108#if !USE_MDM_BOOT_CFG
Sundarajan Srinivasan34bbe072014-03-21 17:27:16 -0700109 case BOOT_DEFAULT:
Sridhar Parasuramefc133f2015-05-04 13:35:41 -0700110 snprintf(buf, ((sizeof((struct mmc_device *)dev)->host.base)*2) + 7,"%x.sdhci", ((struct mmc_device *)dev)->host.base);
Sundarajan Srinivasan34bbe072014-03-21 17:27:16 -0700111 break;
112 case BOOT_UFS:
Glenn Stroz99291c22016-07-18 11:27:37 -0700113 case BOOT_SD_ELSE_UFS:
Sridhar Parasuramefc133f2015-05-04 13:35:41 -0700114 snprintf(buf, ((sizeof((struct ufs_dev *)dev)->base)*2) + 7, "%x.ufshc", ((struct ufs_dev *)dev)->base);
Sundarajan Srinivasan34bbe072014-03-21 17:27:16 -0700115 break;
Channagoud Kadabic42ea322014-10-10 12:26:54 -0700116#endif
117 case BOOT_EMMC:
Sridhar Parasuramefc133f2015-05-04 13:35:41 -0700118 snprintf(buf, ((sizeof((struct mmc_device *)dev)->host.base)*2) + 7,"%x.sdhci", ((struct mmc_device *)dev)->host.base);
Smita Ghoshf5431c62014-09-18 14:11:14 -0700119 break;
Sundarajan Srinivasan34bbe072014-03-21 17:27:16 -0700120 default:
121 dprintf(CRITICAL,"ERROR: Unexpected boot_device val=%x",val);
122 ASSERT(0);
123 };
124}