blob: 1d67c697466ae826bd82006fc9b21496470cd232 [file] [log] [blame]
Travis Geiselbrecht1d0df692008-09-01 02:26:09 -07001/*
Casey Pipera277d882013-10-21 10:11:04 -07002 * Copyright (c) 2008 Travis Geiselbrecht
Travis Geiselbrecht1d0df692008-09-01 02:26:09 -07003 *
lijuangc518f5d2015-02-10 10:22:53 +08004 * Copyright (c) 2015, The Linux Foundation. All rights reserved.
5 *
Travis Geiselbrecht1d0df692008-09-01 02:26:09 -07006 * Permission is hereby granted, free of charge, to any person obtaining
7 * a copy of this software and associated documentation files
8 * (the "Software"), to deal in the Software without restriction,
9 * including without limitation the rights to use, copy, modify, merge,
10 * publish, distribute, sublicense, and/or sell copies of the Software,
11 * and to permit persons to whom the Software is furnished to do so,
12 * subject to the following conditions:
13 *
14 * The above copyright notice and this permission notice shall be
15 * included in all copies or substantial portions of the Software.
16 *
17 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
18 * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
19 * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
20 * IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
21 * CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
22 * TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
23 * SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
24 */
25#include <err.h>
26#include <debug.h>
27#include <target.h>
28#include <compiler.h>
Pavel Nedeva4c9d3a2013-05-15 14:42:34 +030029#include <dload_util.h>
Channagoud Kadabi41c81a62014-10-08 19:55:30 -070030#include <sdhci_msm.h>
Wufeng Jiang71246c22015-08-06 19:07:09 +080031#if PON_VIB_SUPPORT
Wufeng Jiang1ce072f2015-08-06 19:07:09 +080032#include <smem.h>
Wufeng Jiang71246c22015-08-06 19:07:09 +080033#include <vibrator.h>
34#include <board.h>
35#endif
Travis Geiselbrecht1d0df692008-09-01 02:26:09 -070036
lijuang3606df82015-09-02 21:14:43 +080037#include <smem.h>
38#include <pm8x41_adc.h>
39#include <pm8x41_hw.h>
40
41#if CHECK_BAT_VOLTAGE
42#include <pm_fg_adc_usr.h>
43#endif
44
Subbaraman Narayanamurthyf17b4ae2011-02-16 20:19:56 -080045#define EXPAND(NAME) #NAME
46#define TARGET(NAME) EXPAND(NAME)
lijuang3606df82015-09-02 21:14:43 +080047
lijuang66192212015-09-22 10:25:48 +080048#define BATTERY_MIN_VOLTAGE 3200000 //uv
lijuang3606df82015-09-02 21:14:43 +080049#define PMIC_SLAVE_ID 0x20000
50#define BAT_IF_BAT_PRES_STATUS 0x1208
51
Amol Jadi57abe4c2011-05-24 15:47:27 -070052/*
Travis Geiselbrecht1d0df692008-09-01 02:26:09 -070053 * default implementations of these routines, if the target code
54 * chooses not to implement.
55 */
56
57__WEAK void target_early_init(void)
58{
59}
60
61__WEAK void target_init(void)
62{
63}
64
David Ng3679bc52010-02-09 15:43:43 -080065__WEAK void *target_get_scratch_address(void)
66{
67 return (void *)(SCRATCH_ADDR);
68}
69
Vivek Mehta5f1c9d42011-04-01 20:11:59 -070070__WEAK unsigned target_get_max_flash_size(void)
71{
72 return (120 * 1024 * 1024);
73}
74
Tanya Brokhman1c94f1a2015-02-15 09:05:03 +020075__WEAK int flash_ubi_img(void)
76{
77 return 0;
78}
79
Tanya Brokhman84eaaf62015-02-24 21:57:06 +020080__WEAK int update_ubi_vol(void)
81{
82 return 0;
83}
84
David Ng183a7422009-12-07 14:55:21 -080085__WEAK int target_is_emmc_boot(void)
86{
David Ng025c1d92009-12-09 23:46:00 -080087#if _EMMC_BOOT
88 return 1;
89#else
David Ng183a7422009-12-07 14:55:21 -080090 return 0;
David Ng025c1d92009-12-09 23:46:00 -080091#endif
David Ng183a7422009-12-07 14:55:21 -080092}
Chandan Uddarajude85d3f2010-01-05 16:32:33 -080093
94__WEAK unsigned check_reboot_mode(void)
95{
96 return 0;
97}
Chandan Uddaraju94183c02010-01-15 15:13:59 -080098
lijuangc518f5d2015-02-10 10:22:53 +080099__WEAK unsigned check_hard_reboot_mode(void)
100{
101 return 0;
102}
103
Chandan Uddaraju94183c02010-01-15 15:13:59 -0800104__WEAK void reboot_device(unsigned reboot_reason)
105{
106}
Chandan Uddaraju7f5b9012010-02-06 16:37:48 -0800107
Matthew Qindefd5562014-07-11 18:02:40 +0800108__WEAK uint32_t is_user_force_reset(void)
109{
110 return 0;
111}
112
Pavel Nedeva4c9d3a2013-05-15 14:42:34 +0300113__WEAK int set_download_mode(enum dload_mode mode)
Pavel Nedev76a3e212013-05-09 10:37:21 +0300114{
115 return -1;
116}
117
David Ngf773dde2010-07-26 19:55:08 -0700118__WEAK unsigned target_pause_for_battery_charge(void)
119{
120 return 0;
121}
Ajay Dudanid04110c2011-01-17 23:55:07 -0800122
123__WEAK unsigned target_baseband()
124{
125 return 0;
126}
Subbaraman Narayanamurthyf17b4ae2011-02-16 20:19:56 -0800127
128__WEAK void target_serialno(unsigned char *buf)
129{
Ajay Dudanif63d02f2011-10-01 08:29:53 -0700130 snprintf((char *) buf, 13, "%s",TARGET(BOARD));
Subbaraman Narayanamurthyf17b4ae2011-02-16 20:19:56 -0800131}
Amol Jadi57abe4c2011-05-24 15:47:27 -0700132
133__WEAK void target_fastboot_init()
134{
135}
Subbaraman Narayanamurthy0e445b02011-06-19 21:34:46 -0700136
137__WEAK int emmc_recovery_init(void)
138{
139 return 0;
140}
Shashank Mittalcd98d472011-08-02 14:29:24 -0700141
142__WEAK bool target_use_signed_kernel(void)
143{
144#if _SIGNED_KERNEL
145 return 1;
146#else
147 return 0;
148#endif
149}
Amol Jadi6834f1a2012-06-29 14:42:59 -0700150
Stanimir Varbanov8bc68c72013-07-08 18:22:04 +0300151__WEAK bool target_is_ssd_enabled(void)
152{
153#ifdef SSD_ENABLE
154 return 1;
155#else
156 return 0;
157#endif
158}
159
Stanimir Varbanov677001e2013-07-18 18:16:39 +0300160__WEAK void target_load_ssd_keystore(void)
161{
162}
Amol Jadi6834f1a2012-06-29 14:42:59 -0700163
164/* Default target does not support continuous splash screen feature. */
165__WEAK int target_cont_splash_screen()
166{
167 return 0;
168}
Amol Jadida118b92012-07-06 19:53:18 -0700169
170/* Default target specific initialization before using USB */
171__WEAK void target_usb_init(void)
172{
173}
174
175/* Default target specific usb shutdown */
176__WEAK void target_usb_stop(void)
177{
178}
Channagoud Kadabifa6179e2013-06-18 18:35:14 -0700179
180/* Default target specific target uninit */
181__WEAK void target_uninit(void)
182{
183}
Dhaval Patelcdcb6462013-07-18 14:46:57 -0700184
Padmanabhan Komandurubccbcdc2015-06-30 16:19:24 +0530185__WEAK bool target_display_panel_node(char *pbuf, uint16_t buf_size)
Dhaval Patelcdcb6462013-07-18 14:46:57 -0700186{
187 return false;
188}
Channagoud Kadabi9fbdcdf2013-09-19 16:24:16 -0700189
Aravind Venkateswaran6385f7e2014-02-25 16:45:11 -0800190__WEAK void target_display_init(const char *panel_name)
Aravind Venkateswarandd50c1a2014-02-25 14:42:43 -0800191{
192}
193
194__WEAK void target_display_shutdown(void)
195{
196}
197
Casey Piperf8cebb62013-09-11 15:56:17 -0700198__WEAK uint8_t target_panel_auto_detect_enabled()
199{
200 return 0;
201}
202
Casey Piper48bfc0d2013-11-18 13:24:35 -0800203__WEAK uint8_t target_is_edp()
204{
205 return 0;
206}
207
Amol Jadi417c7f22013-10-07 12:52:21 -0700208/* default usb controller to be used. */
209__WEAK const char * target_usb_controller()
210{
211 return "ci";
212}
Amol Jadi9ff7bb52013-10-11 14:11:45 -0700213
214/* override for target specific usb phy reset. */
215__WEAK void target_usb_phy_reset(void)
216{
217}
Hanumant Singh8e1ac232014-01-29 13:41:51 -0800218
219/* determine if target is in warm boot. */
220__WEAK bool target_warm_boot(void)
221{
222 return false;
223}
Aparna Mallavarapu373d38b2014-05-23 14:47:19 +0530224
225/* Determine the HLOS subtype of the target */
226__WEAK uint32_t target_get_hlos_subtype(void)
227{
228 return 0;
229}
Channagoud Kadabi82cf5c62014-08-24 22:17:34 -0700230
231/* Initialize crypto parameters */
232__WEAK void target_crypto_init_params()
233{
234}
Channagoud Kadabi41c81a62014-10-08 19:55:30 -0700235
236/* Default CFG delay value */
237__WEAK uint32_t target_ddr_cfg_val()
238{
239 return DDR_CONFIG_VAL;
240}
Channagoud Kadabi2021cef2015-02-25 12:08:32 -0800241
Wufeng Jiang71246c22015-08-06 19:07:09 +0800242#if PON_VIB_SUPPORT
243uint32_t get_vibration_type()
244{
245 uint32_t ret = VIB_ERM_TYPE;
246 uint32_t hw_id = board_hardware_id();
247 uint32_t platform = board_platform_id();
248 switch(hw_id){
249 case HW_PLATFORM_MTP:
250 switch(platform){
251 case MSM8952:
252 ret = VIB_ERM_TYPE;
253 break;
254 case MSM8976:
vijay kumare9287242015-09-04 18:40:15 +0530255 case MSM8956:
256 case APQ8056:
Wufeng Jiang71246c22015-08-06 19:07:09 +0800257 ret = VIB_LRA_TYPE;
258 break;
vijay kumare9287242015-09-04 18:40:15 +0530259 default:
260 dprintf(CRITICAL,"Unsupported platform id\n");
261 break;
Wufeng Jiang71246c22015-08-06 19:07:09 +0800262 }
263 break;
264 case HW_PLATFORM_QRD:
265 ret = VIB_ERM_TYPE;
266 break;
vijay kumare9287242015-09-04 18:40:15 +0530267 default:
268 dprintf(CRITICAL,"Unsupported platform id\n");
269 break;
Wufeng Jiang71246c22015-08-06 19:07:09 +0800270 }
271 return ret;
272}
273#endif
274
Channagoud Kadabi2021cef2015-02-25 12:08:32 -0800275/* Return Build variant */
276__WEAK bool target_build_variant_user()
277{
278#if USER_BUILD_VARIANT
279 return true;
280#else
281 return false;
282#endif
283}
lijuang3606df82015-09-02 21:14:43 +0800284
285__WEAK uint32_t target_get_pmic()
286{
287 return PMIC_IS_UNKNOWN;
288}
289
290/* Check battery if it's exist */
291bool target_battery_is_present()
292{
293 bool batt_is_exist;
294 uint8_t value = 0;
295 uint32_t pmic;
296
297 pmic = target_get_pmic();
298
299 switch(pmic)
300 {
301 case PMIC_IS_PM8909:
302 case PMIC_IS_PM8916:
303 case PMIC_IS_PM8941:
304 value = REG_READ(BAT_IF_BAT_PRES_STATUS);
305 break;
306 case PMIC_IS_PMI8950:
307 case PMIC_IS_PMI8994:
308 case PMIC_IS_PMI8996:
309 value = REG_READ(PMIC_SLAVE_ID|
310 BAT_IF_BAT_PRES_STATUS);
311 break;
312 default:
313 dprintf(CRITICAL, "ERROR: Couldn't get the pmic type\n");
314 break;
315 }
316
317 batt_is_exist = value >> 7;
318
319 return batt_is_exist;
320
321}
322
323#if CHECK_BAT_VOLTAGE
324/* Return battery voltage */
325uint32_t target_get_battery_voltage()
326{
327 uint32_t pmic;
328 uint32_t vbat = 0;
329
330 pmic = target_get_pmic();
331
332 switch(pmic)
333 {
334 case PMIC_IS_PM8909:
335 case PMIC_IS_PM8916:
336 case PMIC_IS_PM8941:
337 vbat = pm8x41_get_batt_voltage(); //uv
338 break;
339 case PMIC_IS_PMI8950:
340 case PMIC_IS_PMI8994:
341 case PMIC_IS_PMI8996:
342 if (!pm_fg_usr_get_vbat(1, &vbat)) {
343 vbat = vbat*1000; //uv
344 } else {
345 dprintf(CRITICAL, "ERROR: Get battery voltage failed!!!\n");
346 }
347 break;
348 default:
349 dprintf(CRITICAL, "ERROR: Couldn't get the pmic type\n");
350 break;
351 }
352
353 return vbat;
354}
355
356/* Add safeguards such as refusing to flash if minimum battery levels
357 * are not present or be bypass if the device doesn't have a battery
358 */
359bool target_battery_soc_ok()
360{
361 if (!target_battery_is_present()) {
362 dprintf(INFO, "battery is not present\n");
363 return true;
364 }
365
366 if (target_get_battery_voltage() >= BATTERY_MIN_VOLTAGE)
367 return true;
368
369 return false;
370}
371#endif