tizen 2.4 release
[kernel/u-boot-tm1.git] / arch / arm / cpu / armv7 / sc8830 / otp-helper.c
1 /*
2  * Copyright (C) 2014 Spreadtrum Communications Inc.
3  *
4  * This program is free software; you can redistribute it and/or
5  * modify it under the terms of the GNU General Public License
6  * as published by the Free Software Foundation; either version 2
7  * of the License, or (at your option) any later version.
8  *
9  * This program is distributed in the hope that it will be useful,
10  * but WITHOUT ANY WARRANTY; without even the implied warranty of
11  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
12  * GNU General Public License for more details.
13  *
14  */
15
16 /* IMPORTANT:
17  *
18  * TODO:
19  */
20
21 #include <common.h>
22 #include <asm/arch-sc8830/otp_help.h>
23
24 #define BLK_WIDTH_OTP_EMEMORY                   ( 8 ) /* bit counts */
25 #if defined(CONFIG_SPX35L)
26 #define BLK_ADC_DETA_ABC_OTP                    ( 7 ) /* start block for ADC otp delta */
27 #else
28 #define BLK_ADC_DETA_ABC_OTP                    ( 8 ) /* start block for ADC otp delta */
29 #endif
30
31 #define BLK_ADC_DETA                    ( 7 )
32 #define BASE_ADC_P0                             711     //3.6V
33 #define BASE_ADC_P1                             830     //4.2V
34 #define VOL_P0                                  3600
35 #define VOL_P1                                  4200
36 #define ADC_DATA_OFFSET                 128
37
38 u32 efuse_read(int id,int blk_index)
39 {
40         return __ddie_efuse_read(blk_index);
41 }
42 int efuse_prog(int id,int blk_index,u32 val)
43 {
44         return __ddie_efuse_prog(blk_index,val);
45
46 }
47 int sci_efuse_calibration_get(unsigned int *p_cal_data)
48 {
49         unsigned int deta;
50         unsigned short adc_temp;
51
52 #if defined(CONFIG_ADIE_SC2723) || defined(CONFIG_ADIE_SC2723S)
53         //__adie_efuse_block_dump(); /* dump a-die efuse */
54
55         /* verify to write otp data or not */
56         adc_temp = (__adie_efuse_read(0) & (1 << 7));
57         if (adc_temp)
58                 return 0;
59
60         deta = __adie_efuse_read_bits(BLK_ADC_DETA_ABC_OTP * BLK_WIDTH_OTP_EMEMORY, 16);
61 #elif defined(CONFIG_SPX30G)
62         __ddie_efuse_block_dump(); /* dump d-die efuse */
63
64         deta = __ddie_efuse_read(BLK_ADC_DETA);
65 #else
66         #warning "AuxADC CAL DETA need fixing"
67 #endif
68
69         printf("%s() get efuse block %u, deta: 0x%08x\n", __func__, BLK_ADC_DETA, deta);
70
71         deta &= 0xFFFFFF;
72
73         if ((!deta) || (p_cal_data == NULL)) {
74                 return 0;
75         }
76
77         //adc 3.6V
78         adc_temp = ((deta >> 8) & 0x00FF) + BASE_ADC_P0 - ADC_DATA_OFFSET;
79         p_cal_data[1] = (VOL_P0) | ((adc_temp << 2) << 16);
80
81         //adc 4.2V
82         adc_temp = (deta & 0x00FF) + BASE_ADC_P1 - ADC_DATA_OFFSET;
83         p_cal_data[0] = (VOL_P1) | ((adc_temp << 2) << 16);
84
85         return 1;
86 }