2 * Copyright (C) 2012 Spreadtrum Communications Inc.
4 * This software is licensed under the terms of the GNU General Public
5 * License version 2, as published by the Free Software Foundation, and
6 * may be copied, distributed, and modified under those terms.
8 * This program is distributed in the hope that it will be useful,
9 * but WITHOUT ANY WARRANTY; without even the implied warranty of
10 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11 * GNU General Public License for more details.
14 //#include <linux/kernel.h>
15 //#include <linux/init.h>
16 //#include <linux/io.h>
17 //#include <linux/module.h>
19 //#include <mach/hardware.h>
20 //#include <mach/regs_global.h>
24 #include <asm/arch/regs_global.h>
26 #include "ctl_efuse.h"
28 #define CTL_EFUSE_BASE_PHYS ( 0x89000000 )
29 #define CTL_EFUSE_BASE ( CTL_EFUSE_BASE_PHYS )
30 #define SCI_ADDRESS(_b_, _o_) ( (u32)(_b_) + (_o_) )
32 #define SCI_D(reg) ( *(volatile u32 *)(reg) )
34 //static void __iomem *ctl_efuse_base = 0;
35 void sci_efuse_poweron(void)
37 //ctl_efuse_base = ioremap(CTL_EFUSE_BASE_PHYS, PAGE_SIZE);
38 SCI_D(GR_GEN0) |= GEN0_EFUSE_EN;
39 SCI_D(REG_EFUSE_PGM_PARA) |= BIT_EFUSE_VDD_ON;
40 SCI_D(REG_EFUSE_PGM_PARA) |= BIT_CLK_EFS_EN;
43 void sci_efuse_poweroff(void)
45 SCI_D(REG_EFUSE_PGM_PARA) &= ~BIT_PGM_EN;
46 SCI_D(REG_EFUSE_PGM_PARA) &= ~BIT_CLK_EFS_EN;
47 SCI_D(REG_EFUSE_PGM_PARA) &= ~BIT_EFUSE_VDD_ON;
48 SCI_D(GR_GEN0) &= ~GEN0_EFUSE_EN;
49 //if (ctl_efuse_base) {
50 // iounmap(ctl_efuse_base);
51 // ctl_efuse_base = 0;
55 int sci_efuse_read(unsigned blk)
58 BUG_ON(blk > (MASK_READ_INDEX >> SHIFT_READ_INDEX));
60 SCI_D(REG_EFUSE_BLOCK_INDEX) = BITS_READ_INDEX(blk);
61 SCI_D(REG_EFUSE_MODE_CTRL) |= BIT_RD_START;
65 busy = SCI_D(REG_EFUSE_STATUS) & BIT_READ_BUSY;
68 return SCI_D(REG_EFUSE_DATA_RD);
71 int sci_efuse_program(unsigned blk, int data)
76 int sci_efuse_is_locked(unsigned blk)
82 int sci_efuse_raw_write(unsigned blk, int data, u32 magic)
84 SCI_D(REG_EFUSE_MAGIC_NUMBER) = BITS_MAGIC_NUMBER(magic);
88 int sci_efuse_lock(unsigned blk)
93 #define CAL_DATA_BLK 7
94 #define BASE_ADC_P0 785 //3.6V
95 #define BASE_ADC_P1 917 //4.2V
98 #define ADC_DATA_OFFSET 128
99 int sci_efuse_calibration_get(unsigned int * p_cal_data)
102 unsigned int cal_temp;
103 unsigned short adc_temp;
106 data = sci_efuse_read(CAL_DATA_BLK);
107 sci_efuse_poweroff();
111 // data = (173 |(171 << 8));
112 printf("sci_efuse_calibration data:%d\n",data);
113 if((!data)||(p_cal_data == NULL))
118 adc_temp = ((data>>8) & 0x00FF) + BASE_ADC_P0 - ADC_DATA_OFFSET;
119 p_cal_data[1] = (VOL_P0)|(adc_temp << 16);
122 adc_temp = (data & 0x00FF) + BASE_ADC_P1 - ADC_DATA_OFFSET;
123 p_cal_data[0] = (VOL_P1)|(adc_temp << 16);