import PULS_20180308
authorStricted <info@stricted.net>
Tue, 13 Mar 2018 19:30:12 +0000 (20:30 +0100)
committerStricted <info@stricted.net>
Tue, 13 Mar 2018 19:30:12 +0000 (20:30 +0100)
203 files changed:
arch/arm/configs/ttab_debug_defconfig [changed mode: 0755->0644]
arch/arm/configs/ttab_defconfig [changed mode: 0755->0644]
arch/arm/include/asm/thread_info.h
arch/arm/include/asm/tls.h
arch/arm/include/uapi/asm/setup.h
arch/arm/kernel/entry-armv.S
arch/arm/kernel/process.c
arch/arm/kernel/ptrace.c
arch/arm/kernel/traps.c
arch/arm/mach-mt8127/include/mach/nand_device_define.h
arch/arm/mach-mt8127/kr076/camera/camera/kd_camera_hw.c
arch/arm/mach-mt8127/kr076/power/cust_battery_meter_table.h
arch/arm/mach-mt8127/kr076/power/cust_charging.h
arch/arm/mach-mt8127/kr076_nand/camera/camera/kd_camera_hw.c
arch/arm/mach-mt8127/kr076_nand/power/cust_battery_meter.h
arch/arm/mach-mt8127/kr076_nand/power/cust_battery_meter_table.h
arch/arm/mach-mt8127/kr076_nand/power/cust_charging.h
arch/arm/mach-mt8127/mt_cpufreq.c
arch/arm/mach-mt8127/mt_devs.c
arch/arm/mach-mt8127/tcl8127_tb_c_l/power/cust_battery_meter.h
arch/arm/mach-mt8127/tcl8127_tb_c_l/power/cust_charging.h
arch/arm/mach-mt8127/ttab/camera/camera/kd_camera_hw.c
arch/arm/mach-mt8127/ttab/core/board.c
arch/arm/mach-mt8127/ttab/dct/dct/codegen.dws
arch/arm/mach-mt8127/ttab/leds/mt65xx/cust_leds.c
arch/arm/mach-mt8127/ttab/power/cust_battery_meter.h
arch/arm/mach-mt8127/ttab/power/cust_battery_meter_table.h
arch/arm/mach-mt8127/ttab/power/cust_charging.h
arch/arm/mach-mt8127/ttab/touchpanel/gt9xx_driver.c
arch/arm/mach-mt8127/ttab/touchpanel/mtk_tpd.c
arch/arm/mach-mt8127/ttab/touchpanel/tpd_custom_gt9xx.h
arch/arm/mm/dma-mapping.c
arch/arm64/kernel/perf_event.c
arch/arm64/kernel/sys.c
block/genhd.c
crypto/Kconfig
crypto/Makefile
crypto/lz4kc.c [new file with mode: 0644]
drivers/hid/hid-core.c
drivers/input/touchscreen/mediatek/GT910/goodix_tool.c
drivers/input/touchscreen/mediatek/GT911/goodix_tool.c
drivers/input/touchscreen/mediatek/GT9110/goodix_tool.c
drivers/input/touchscreen/mediatek/GT927/goodix_tool.c
drivers/input/touchscreen/mediatek/GT928/goodix_tool.c
drivers/input/touchscreen/mediatek/GT9XX/goodix_tool.c
drivers/input/touchscreen/mediatek/GT9XXTB_hotknot/goodix_tool.c
drivers/input/touchscreen/mediatek/GT9XX_2/goodix_tool.c
drivers/input/touchscreen/mediatek/GT9XX_hotknot/goodix_tool.c
drivers/input/touchscreen/mediatek/GT9XX_hotknot_FLASHLESS/goodix_tool.c
drivers/input/touchscreen/mediatek/GT9XX_hotknot_SCP/goodix_tool.c
drivers/input/touchscreen/mediatek/GT9XX_hotknot_fpga/goodix_tool.c
drivers/media/tuners/tuner-xc2028.c
drivers/misc/mediatek/cmdq/Makefile
drivers/misc/mediatek/cmdq/cmdq_driver.c
drivers/misc/mediatek/cmdq/cmdq_test.c
drivers/misc/mediatek/connectivity/combo/common/core/include/wmt_lib.h
drivers/misc/mediatek/connectivity/combo/common/linux/wmt_dev.c
drivers/misc/mediatek/connectivity/combo/drv_wlan/mt6630/wlan/nic/que_mgt.c
drivers/misc/mediatek/connectivity/combo/drv_wlan/mt6630/wlan/os/linux/gl_wext.c
drivers/misc/mediatek/connectivity/combo/drv_wlan/mt6630/wlan/os/linux/gl_wext_priv.c
drivers/misc/mediatek/connectivity/conn_soc/common/core/include/wmt_lib.h
drivers/misc/mediatek/connectivity/conn_soc/common/linux/pri/wmt_dev.c
drivers/misc/mediatek/connectivity/conn_soc/drv_wlan/mt_wifi/wlan/common/wlan_lib.c
drivers/misc/mediatek/connectivity/conn_soc/drv_wlan/mt_wifi/wlan/include/nic/hif_rx.h
drivers/misc/mediatek/connectivity/conn_soc/drv_wlan/mt_wifi/wlan/nic/que_mgt.c
drivers/misc/mediatek/connectivity/conn_soc/drv_wlan/mt_wifi/wlan/os/linux/gl_cfg80211.c
drivers/misc/mediatek/connectivity/conn_soc/drv_wlan/mt_wifi/wlan/os/linux/gl_init.c
drivers/misc/mediatek/connectivity/conn_soc/drv_wlan/mt_wifi/wlan/os/linux/gl_wext.c
drivers/misc/mediatek/connectivity/conn_soc/drv_wlan/mt_wifi/wlan/os/linux/gl_wext_priv.c
drivers/misc/mediatek/dispsys/mt8127/ddp_bls.c
drivers/misc/mediatek/dispsys/mt8127/ddp_debug.c
drivers/misc/mediatek/ext_disp/mt8127/hdmitx.c
drivers/misc/mediatek/freqhopping/mt_freqhopping_drv.c
drivers/misc/mediatek/gpu/ged/src/ged_main.c
drivers/misc/mediatek/gpu/mt8127/mali/mali/linux/mali_memory_os_alloc.c
drivers/misc/mediatek/hall/hall.c
drivers/misc/mediatek/hwmon/hwmsen/hwmsen_dev.c
drivers/misc/mediatek/i2c/mt8127/i2c_common.c
drivers/misc/mediatek/imgsensor/inc/kd_imgsensor.h
drivers/misc/mediatek/imgsensor/src/mt8127/gc2355_mipi_raw/Makefile [new file with mode: 0644]
drivers/misc/mediatek/imgsensor/src/mt8127/gc2355_mipi_raw/gc2355mipi_CameraCustomized.h [new file with mode: 0644]
drivers/misc/mediatek/imgsensor/src/mt8127/gc2355_mipi_raw/gc2355mipi_Camera_Sensor_para.h [new file with mode: 0644]
drivers/misc/mediatek/imgsensor/src/mt8127/gc2355_mipi_raw/gc2355mipi_Sensor.c [new file with mode: 0644]
drivers/misc/mediatek/imgsensor/src/mt8127/gc2355_mipi_raw/gc2355mipi_Sensor.h [new file with mode: 0644]
drivers/misc/mediatek/imgsensor/src/mt8127/hi708_yuv/hi708yuv_Sensor.c
drivers/misc/mediatek/imgsensor/src/mt8127/kd_sensorlist.h
drivers/misc/mediatek/imgsensor/src/mt8127/ov2680_raw/ov2680mipiraw_Sensor.c
drivers/misc/mediatek/imgsensor/src/mt8127/ov56702nd_mipi_raw/Makefile [new file with mode: 0644]
drivers/misc/mediatek/imgsensor/src/mt8127/ov56702nd_mipi_raw/ov56702ndmipi_Sensor.c [new file with mode: 0644]
drivers/misc/mediatek/imgsensor/src/mt8127/ov56702nd_mipi_raw/ov56702ndmipi_Sensor.h [new file with mode: 0644]
drivers/misc/mediatek/imgsensor/src/mt8127/ov56702nd_mipi_raw/ov56702ndmipiraw_CameraCustomized.h [new file with mode: 0644]
drivers/misc/mediatek/imgsensor/src/mt8127/ov56702nd_mipi_raw/ov56702ndmipiraw_Camera_Sensor_para.h [new file with mode: 0644]
drivers/misc/mediatek/imgsensor/src/mt8127/ov5670_mipi_raw/ov5670mipi_Sensor.c
drivers/misc/mediatek/imgsensor/src/mt8127/ov5670_mipi_raw/ov5670mipi_Sensor.h
drivers/misc/mediatek/lcm/a080ean01_dsi_vdo/a080ean01_dsi_vdo.c
drivers/misc/mediatek/lcm/kr076_ek79007_wsvga_dsi_vdo/kr076_ek79007_wsvga_dsi_vdo.c
drivers/misc/mediatek/lcm/kr076_starry_ek79007_wsvga_dsi_vdo/kr076_starry_ek79007_wsvga_dsi_vdo.c
drivers/misc/mediatek/lcm/ota7291_wxga_dsi_vdo/ota7291_wxga_dsi_vdo.c
drivers/misc/mediatek/lcm/rm72013_wxga_dsi_vdo/Makefile [new file with mode: 0755]
drivers/misc/mediatek/lcm/rm72013_wxga_dsi_vdo/rm72013_wxga_dsi_vdo.c [new file with mode: 0644]
drivers/misc/mediatek/leds/leds_drv.c
drivers/misc/mediatek/leds/mt8127/leds.c
drivers/misc/mediatek/masp/asf/core/sec_mod_core.c
drivers/misc/mediatek/mrdump/mt8127/mrdump_setup.c
drivers/misc/mediatek/mtprof/mt_printk_ctrl.c
drivers/misc/mediatek/nand/mt8127/mtk_nand.c
drivers/misc/mediatek/power/mt8127/charging_hw_fan5405.c
drivers/misc/mediatek/power/mt8127/charging_hw_pmic.c
drivers/misc/mediatek/power/mt8127/fan5405.h
drivers/misc/mediatek/smi/mt8127/smi_debug.c
drivers/misc/mediatek/sound/mt8127/AudDrv_Afe.c
drivers/misc/mediatek/sound/mt8127/AudDrv_Afe.h
drivers/misc/mediatek/sound/mt8127/AudDrv_Ana_6323.c
drivers/misc/mediatek/sound/mt8127/AudDrv_Ana_6323.h
drivers/misc/mediatek/sound/mt8127/AudDrv_Ana_6397.c
drivers/misc/mediatek/sound/mt8127/AudDrv_Ana_6397.h
drivers/misc/mediatek/thermal/Makefile
drivers/misc/mediatek/thermal/mt8127/mtk_cooler_bcct.c
drivers/misc/mediatek/thermal/mt8127/mtk_ts_wmt.c
drivers/misc/mediatek/thermal/mtk_cooler_cam.c
drivers/misc/mediatek/thermal/mtk_cooler_shutdown.c
drivers/misc/mediatek/thermal/mtk_cooler_vrt.c
drivers/misc/mediatek/video/mt8127/debug.c
drivers/misc/mediatek/video/mt8127/disp_drv.c
drivers/misc/mediatek/video/mt8127/mt8127/dsi_drv.c
drivers/misc/mediatek/video/mt8127/mtkfb.c
drivers/misc/mediatek/video/mtkfb.h
drivers/misc/mediatek/videocodec/mt8127/videocodec_kernel_driver.c
drivers/net/ppp/ppp_generic.c
drivers/power/mediatek/battery_common.c
drivers/power/mediatek/battery_meter.c
drivers/power/mediatek/linear_charging.c
drivers/power/mediatek/switch_charging.c
drivers/staging/android/binder.c
drivers/staging/android/ion/ion.c
drivers/staging/android/ion/ion_priv.h
drivers/tty/tty_io.c
drivers/tty/tty_ldisc.c
drivers/usb/core/devio.c
drivers/usb/core/hub.c
drivers/video/adf/adf_client.c
fs/9p/acl.c
fs/aio.c
fs/btrfs/acl.c
fs/ecryptfs/main.c
fs/ext2/acl.c
fs/ext3/acl.c
fs/ext4/acl.c
fs/ext4/ext4_jbd2.c
fs/ext4/inode.c
fs/f2fs/acl.c
fs/generic_acl.c
fs/gfs2/acl.c
fs/ioprio.c
fs/jffs2/acl.c
fs/jfs/xattr.c
fs/ocfs2/acl.c
fs/posix_acl.c
fs/proc/array.c
fs/proc/base.c
fs/reiserfs/xattr_acl.c
fs/ubifs/budget.c
fs/ubifs/sb.c
fs/xfs/xfs_acl.c
include/linux/fs.h
include/linux/mm.h
include/linux/posix_acl.h
include/linux/sysrq.h
include/linux/vcodec/venc_drv_if_public.h
include/net/af_unix.h
include/net/tcp.h
kernel/audit.h
kernel/auditsc.c
kernel/events/core.c
kernel/resource.c
lib/asn1_decoder.c
mm/memory.c
net/core/ethtool.c
net/core/sock.c
net/dccp/input.c
net/ipv4/ip_sockglue.c
net/ipv4/netfilter/arp_tables.c
net/ipv4/netfilter/ip_tables.c
net/ipv4/ping.c
net/ipv4/tcp_input.c
net/ipv4/udp.c
net/ipv6/ndisc.c
net/ipv6/netfilter/ip6_tables.c
net/ipv6/udp.c
net/l2tp/l2tp_ip.c
net/l2tp/l2tp_ip6.c
net/netfilter/nf_conntrack_core.c
net/netfilter/xt_qtaguid.c
net/packet/af_packet.c
net/socket.c
net/unix/af_unix.c
net/xfrm/xfrm_user.c
sound/core/compress_offload.c
sound/core/info.c
sound/core/seq/seq_queue.c
sound/core/timer.c
sound/soc/soc-core.c
tools/dct/MT8173.fig [deleted file]

old mode 100755 (executable)
new mode 100644 (file)
index d6687b7..4a80e6c
@@ -1164,13 +1164,13 @@ CONFIG_MTK_SENSOR_SUPPORT=y
 # CONFIG_MTK_AUTO_DETECT_ALSPS is not set
 CONFIG_CUSTOM_KERNEL_ACCELEROMETER=y
 CONFIG_CUSTOM_KERNEL_GYROSCOPE=y
-CONFIG_CUSTOM_KERNEL_ALSPS=y
+CONFIG_CUSTOM_KERNEL_ALSPS=y
 # CONFIG_CUSTOM_SEC_AUTH_SUPPORT is not set
 CONFIG_CUSTOM_KERNEL_MAGNETOMETER=y
 # CONFIG_CUSTOM_KERNEL_BAROMETER is not set
-CONFIG_CUSTOM_KERNEL_IMGSENSOR="ov2680_raw ov5670_mipi_raw"
+CONFIG_CUSTOM_KERNEL_IMGSENSOR="ov2680_raw gc2355_mipi_raw ov5670_mipi_raw ov56702nd_mipi_raw"
 #CONFIG_CUSTOM_KERNEL_LCM="a080ean01_dsi_vdo"
-CONFIG_CUSTOM_KERNEL_LCM="ota7291_wxga_dsi_vdo a080ean01_dsi_vdo"
+CONFIG_CUSTOM_KERNEL_LCM="ota7291_wxga_dsi_vdo rm72013_wxga_dsi_vdo a080ean01_dsi_vdo"
 CONFIG_CUSTOM_KERNEL_FLASHLIGHT="constant_flashlight"
 CONFIG_CUSTOM_KERNEL_EXTMD=""
 CONFIG_CUSTOM_KERNEL_SSW="ssw_single"
@@ -1351,7 +1351,7 @@ CONFIG_MTK_PMIC_WRAP=y
 # CONFIG_MTK_PMIC_MT6397 is not set
 # CONFIG_POWER_EXT is not set
 # CONFIG_MTK_POWER_EXT_DETECT is not set
-CONFIG_MTK_PUMP_EXPRESS_SUPPORT=y
+# CONFIG_MTK_PUMP_EXPRESS_SUPPORT is not set
 # CONFIG_MTK_PUMP_EXPRESS_PLUS_SUPPORT is not set
 # CONFIG_MTK_VOW_SUPPORT is not set
 # CONFIG_MTK_EXTERNAL_LDO is not set
@@ -1359,7 +1359,7 @@ CONFIG_MTK_PUMP_EXPRESS_SUPPORT=y
 # CONFIG_MTK_BQ24250_SUPPORT is not set
 # CONFIG_MTK_BQ24261_SUPPORT is not set
 # CONFIG_MTK_BQ24196_SUPPORT is not set
-# CONFIG_MTK_FAN5405_SUPPORT is not set
+CONFIG_MTK_FAN5405_SUPPORT=y
 # CONFIG_MTK_FAN5402_SUPPORT is not set
 # CONFIG_MTK_BQ24158_SUPPORT is not set
 # CONFIG_MTK_BQ24296_SUPPORT is not set
@@ -1385,7 +1385,7 @@ CONFIG_MTK_SOUND=y
 # CONFIG_MTK_EPL2182_NEW is not set
 # CONFIG_MTK_STK3X1X is not set
 # CONFIG_MTK_CM36652_NEW is not set
-CONFIG_MTK_APDS9930=y
+# CONFIG_MTK_APDS9930 is not set
 # CONFIG_MTK_CM3232_NEW is not set
 # CONFIG_MTK_APDS9930_NEW is not set
 # CONFIG_MTK_KXTJ2_1009 is not set
@@ -1408,7 +1408,7 @@ CONFIG_MTK_BMA2XX=y
 # CONFIG_MTK_MPU6515G is not set
 # CONFIG_MTK_MPU3050C_NEW is not set
 # CONFIG_MTK_AKM8963 is not set
-CONFIG_MTK_AKM09911=y
+CONFIG_MTK_AKM09911=y
 # CONFIG_MTK_AKM8963_NEW is not set
 # CONFIG_MTK_HSCDTD006 is not set
 # CONFIG_MTK_BMM050 is not set
@@ -1478,7 +1478,9 @@ CONFIG_MTK_SIM2_SOCKET_TYPE="1"
 # CONFIG_MTK_CTP_RESET_CONFIG is not set
 CONFIG_MTK_BICR_SUPPORT=y
 CONFIG_MTK_VIDEO_HEVC_SUPPORT=y
-CONFIG_MTK_AAL_SUPPORT=y
+#[FEATURE]-Mod-BEGIN by TCTSZ.yaohui.zeng, 2015/04/20,disable BL AAL
+#CONFIG_MTK_AAL_SUPPORT=y
+#[FEATURE]-Mod-END by TCTSZ.yaohui.zeng, 2015/04/20
 # CONFIG_MTK_MULTIBRIDGE_SUPPORT is not set
 # CONFIG_NAND_OTP_SUPPORT is not set
 # CONFIG_MTK_OD_SUPPORT is not set
old mode 100755 (executable)
new mode 100644 (file)
index 69aac7c..9a062cb
@@ -1163,13 +1163,13 @@ CONFIG_MTK_SENSOR_SUPPORT=y
 # CONFIG_MTK_AUTO_DETECT_ALSPS is not set
 CONFIG_CUSTOM_KERNEL_ACCELEROMETER=y
 CONFIG_CUSTOM_KERNEL_GYROSCOPE=y
-CONFIG_CUSTOM_KERNEL_ALSPS=y
+CONFIG_CUSTOM_KERNEL_ALSPS=y
 # CONFIG_CUSTOM_SEC_AUTH_SUPPORT is not set
 CONFIG_CUSTOM_KERNEL_MAGNETOMETER=y
 # CONFIG_CUSTOM_KERNEL_BAROMETER is not set
-CONFIG_CUSTOM_KERNEL_IMGSENSOR="ov2680_raw ov5670_mipi_raw"
+CONFIG_CUSTOM_KERNEL_IMGSENSOR="ov2680_raw gc2355_mipi_raw ov5670_mipi_raw ov56702nd_mipi_raw"
 #CONFIG_CUSTOM_KERNEL_LCM="a080ean01_dsi_vdo"
-CONFIG_CUSTOM_KERNEL_LCM="ota7291_wxga_dsi_vdo a080ean01_dsi_vdo"
+CONFIG_CUSTOM_KERNEL_LCM="ota7291_wxga_dsi_vdo rm72013_wxga_dsi_vdo a080ean01_dsi_vdo"
 CONFIG_CUSTOM_KERNEL_FLASHLIGHT="constant_flashlight"
 CONFIG_CUSTOM_KERNEL_EXTMD=""
 CONFIG_CUSTOM_KERNEL_SSW="ssw_single"
@@ -1348,7 +1348,7 @@ CONFIG_MTK_PMIC_WRAP=y
 # CONFIG_MTK_PMIC_MT6397 is not set
 # CONFIG_POWER_EXT is not set
 # CONFIG_MTK_POWER_EXT_DETECT is not set
-CONFIG_MTK_PUMP_EXPRESS_SUPPORT=y
+# CONFIG_MTK_PUMP_EXPRESS_SUPPORT is not set
 # CONFIG_MTK_PUMP_EXPRESS_PLUS_SUPPORT is not set
 # CONFIG_MTK_VOW_SUPPORT is not set
 # CONFIG_MTK_EXTERNAL_LDO is not set
@@ -1356,7 +1356,7 @@ CONFIG_MTK_PUMP_EXPRESS_SUPPORT=y
 # CONFIG_MTK_BQ24250_SUPPORT is not set
 # CONFIG_MTK_BQ24261_SUPPORT is not set
 # CONFIG_MTK_BQ24196_SUPPORT is not set
-# CONFIG_MTK_FAN5405_SUPPORT is not set
+CONFIG_MTK_FAN5405_SUPPORT=y
 # CONFIG_MTK_FAN5402_SUPPORT is not set
 # CONFIG_MTK_BQ24158_SUPPORT is not set
 # CONFIG_MTK_BQ24296_SUPPORT is not set
@@ -1382,7 +1382,7 @@ CONFIG_MTK_SOUND=y
 # CONFIG_MTK_EPL2182_NEW is not set
 # CONFIG_MTK_STK3X1X is not set
 # CONFIG_MTK_CM36652_NEW is not set
-CONFIG_MTK_APDS9930=y
+# CONFIG_MTK_APDS9930 is not set
 # CONFIG_MTK_CM3232_NEW is not set
 # CONFIG_MTK_APDS9930_NEW is not set
 # CONFIG_MTK_KXTJ2_1009 is not set
@@ -1405,7 +1405,7 @@ CONFIG_MTK_BMA2XX=y
 # CONFIG_MTK_MPU6515G is not set
 # CONFIG_MTK_MPU3050C_NEW is not set
 # CONFIG_MTK_AKM8963 is not set
-CONFIG_MTK_AKM09911=y
+# CONFIG_MTK_AKM09911 is not set
 # CONFIG_MTK_AKM8963_NEW is not set
 # CONFIG_MTK_HSCDTD006 is not set
 # CONFIG_MTK_BMM050 is not set
@@ -1475,7 +1475,9 @@ CONFIG_MTK_SIM2_SOCKET_TYPE="1"
 # CONFIG_MTK_CTP_RESET_CONFIG is not set
 CONFIG_MTK_BICR_SUPPORT=y
 CONFIG_MTK_VIDEO_HEVC_SUPPORT=y
-CONFIG_MTK_AAL_SUPPORT=y
+#[FEATURE]-Mod-BEGIN by TCTSZ.yaohui.zeng, 2015/04/20,disable BL AAL
+#CONFIG_MTK_AAL_SUPPORT=y
+#[FEATURE]-Mod-END by TCTSZ.yaohui.zeng, 2015/04/20
 # CONFIG_MTK_MULTIBRIDGE_SUPPORT is not set
 # CONFIG_NAND_OTP_SUPPORT is not set
 # CONFIG_MTK_OD_SUPPORT is not set
index 9b3493a47c471b6d419db1b2bd8baae2a3d74475..a4a95c792985e42bd7e29dc10411652796c46d90 100644 (file)
@@ -58,7 +58,7 @@ struct thread_info {
        struct cpu_context_save cpu_context;    /* cpu context */
        __u32                   syscall;        /* syscall number */
        __u8                    used_cp[16];    /* thread used copro */
-       unsigned long           tp_value;
+       unsigned long           tp_value[2];    /* TLS registers */
 #ifdef CONFIG_CRUNCH
        struct crunch_state     crunchstate;
 #endif
index 73409e6c0251001b5b03f27ae811a523cc605f62..374272202f9fed158d0c614e4584002a48382b50 100644 (file)
@@ -2,27 +2,33 @@
 #define __ASMARM_TLS_H
 
 #ifdef __ASSEMBLY__
-       .macro set_tls_none, tp, tmp1, tmp2
+#include <asm/asm-offsets.h>
+       .macro switch_tls_none, prev, next, tp, tpuser, tmp1, tmp2
        .endm
 
-       .macro set_tls_v6k, tp, tmp1, tmp2
+       .macro switch_tls_v6k, prev, next, tp, tpuser, tmp1, tmp2
+       ldrd    \tp, \tpuser, [\next, #TI_TP_VALUE]     @ get the next TLS and user r/w register
+       mrc     p15, 0, \tmp2, c13, c0, 2       @ get the user r/w register
        mcr     p15, 0, \tp, c13, c0, 3         @ set TLS register
-       mov     \tmp1, #0
-       mcr     p15, 0, \tmp1, c13, c0, 2       @ clear user r/w TLS register
+       mcr     p15, 0, \tpuser, c13, c0, 2     @ and the user r/w register
+       str     \tmp2, [\prev, #TI_TP_VALUE + 4] @ save it
        .endm
 
-       .macro set_tls_v6, tp, tmp1, tmp2
+       .macro switch_tls_v6, prev, next, tp, tpuser, tmp1, tmp2
        ldr     \tmp1, =elf_hwcap
        ldr     \tmp1, [\tmp1, #0]
        mov     \tmp2, #0xffff0fff
+       ldr     \tp, [\next, #TI_TP_VALUE]      @ get the next TLS register
        tst     \tmp1, #HWCAP_TLS               @ hardware TLS available?
-       mcrne   p15, 0, \tp, c13, c0, 3         @ yes, set TLS register
-       movne   \tmp1, #0
-       mcrne   p15, 0, \tmp1, c13, c0, 2       @ clear user r/w TLS register
        streq   \tp, [\tmp2, #-15]              @ set TLS value at 0xffff0ff0
+       mrcne   p15, 0, \tmp2, c13, c0, 2       @ get the previous user r/w register
+       ldrne   \tpuser, [\next, #TI_TP_VALUE + 4]      @ get the next user r/w register
+       mcrne   p15, 0, \tp, c13, c0, 3         @ yes, set TLS register
+       mcrne   p15, 0, \tpuser, c13, c0, 2     @ set user r/w register
+       strne   \tmp2, [\prev, #TI_TP_VALUE + 4] @ save it
        .endm
 
-       .macro set_tls_software, tp, tmp1, tmp2
+       .macro switch_tls_software, prev, next, tp, tpuser, tmp1, tmp2
        mov     \tmp1, #0xffff0fff
        str     \tp, [\tmp1, #-15]              @ set TLS value at 0xffff0ff0
        .endm
 #ifdef CONFIG_TLS_REG_EMUL
 #define tls_emu                1
 #define has_tls_reg            1
-#define set_tls                set_tls_none
+#define switch_tls     switch_tls_none
 #elif defined(CONFIG_CPU_V6)
 #define tls_emu                0
 #define has_tls_reg            (elf_hwcap & HWCAP_TLS)
-#define set_tls                set_tls_v6
+#define switch_tls     switch_tls_v6
 #elif defined(CONFIG_CPU_32v6K)
 #define tls_emu                0
 #define has_tls_reg            1
-#define set_tls                set_tls_v6k
+#define switch_tls     switch_tls_v6k
 #else
 #define tls_emu                0
 #define has_tls_reg            0
-#define set_tls                set_tls_software
+#define switch_tls     switch_tls_software
 #endif
 
+#ifndef __ASSEMBLY__
+static inline unsigned long get_tpuser(void)
+{
+       unsigned long reg = 0;
+
+       if (has_tls_reg && !tls_emu)
+               __asm__("mrc p15, 0, %0, c13, c0, 2" : "=r" (reg));
+
+       return reg;
+}
+#endif
 #endif /* __ASMARM_TLS_H */
index 30cd89ed0bc284481a75e2b05699c4b7839f807f..ab3e3fe5f2d57ff014abdd8bc5adc46973fa2193 100644 (file)
@@ -229,12 +229,14 @@ struct tag {
                 tag_dfo_boot     dfo_data;
                 struct tag_mdinfo_data mdinfo_data;
                mem_desc_t tee_reserved_mem;
+#if 0
 #ifdef PT_ABTC_ATAG
                struct tag_pt_info tag_pt_info;
 #endif
 #ifdef NAND_ABTC_ATAG
                struct tag_nand_number tag_nand_number;
                flashdev_info_t gen_FlashTable_p;
+#endif
 #endif
        } u;
 };
index ea4e710f4774f377ff2e57e2a48720c96d2c9949..925a62e236513082afe62885af4be9cad1565dff 100644 (file)
@@ -708,7 +708,6 @@ ENTRY(__switch_to)
        ldmfa   ip!, {r0, r1, r2, r5, r6, r8, lr}
 #endif
        add     ip, r1, #TI_CPU_SAVE
-       ldr     r3, [r2, #TI_TP_VALUE]
  ARM(  stmia   ip!, {r4 - sl, fp, sp, lr} )    @ Store most regs on stack
  THUMB(        stmia   ip!, {r4 - sl, fp}         )    @ Store most regs on stack
  THUMB(        str     sp, [ip], #4               )
@@ -716,7 +715,7 @@ ENTRY(__switch_to)
 #ifdef CONFIG_CPU_USE_DOMAINS
        ldr     r6, [r2, #TI_CPU_DOMAIN]
 #endif
-       set_tls r3, r4, r5
+       switch_tls r1, r2, r4, r5, r3, r7
 #if defined(CONFIG_CC_STACKPROTECTOR) && !defined(CONFIG_SMP)
        ldr     r7, [r2, #TI_TASK]
        ldr     r8, =__stack_chk_guard
index 8832d3939cc525f3941e2d0e96fb3ff14d90aedf..63f370c5057fd807ace83c9ed6b4b5877ed1ab1d 100644 (file)
@@ -41,6 +41,7 @@
 #include <asm/thread_notify.h>
 #include <asm/stacktrace.h>
 #include <asm/mach/time.h>
+#include <asm/tls.h>
 #include <mach/system.h>
 
 #ifdef CONFIG_CC_STACKPROTECTOR
@@ -60,6 +61,10 @@ static const char *isa_modes[] = {
   "ARM" , "Thumb" , "Jazelle", "ThumbEE"
 };
 
+//[BUGFIX]-Add-BEGIN by SCDTABLET.(fangyou.wang),10/10/2015,1097303,                 
+//auto reboot after power off                                              
+extern void force_enable_uart_log(void);
+//[BUGFIX]-Add-END  by SCDTABLET.(fangyou.wang)
 #ifdef CONFIG_SMP
 void arch_trigger_all_cpu_backtrace(void)
 {
@@ -329,7 +334,11 @@ void machine_power_off(void)
        /* Disable interrupts first */
        local_irq_disable();
        local_fiq_disable();
-       
+//[BUGFIX]-Add-BEGIN by SCDTABLET.(fangyou.wang),10/10/2015,1097303,                 
+//auto reboot after power off                                              
+       force_enable_uart_log();
+//[BUGFIX]-Add-END  by SCDTABLET.(fangyou.wang)
+
        smp_send_stop();        
        if(reboot_pid > 1)
        {
@@ -632,7 +641,8 @@ copy_thread(unsigned long clone_flags, unsigned long stack_start,
        clear_ptrace_hw_breakpoint(p);
 
        if (clone_flags & CLONE_SETTLS)
-               thread->tp_value = childregs->ARM_r3;
+               thread->tp_value[0] = childregs->ARM_r3;
+       thread->tp_value[1] = get_tpuser();
 
        thread_notify(THREAD_NOTIFY_COPY, thread);
 
index 03deeffd9f6d06e6ff380126592e10dbf7bf1a25..2bc1514d6dbe84955d0d070db1ae2ac6e65a5fbd 100644 (file)
@@ -849,7 +849,7 @@ long arch_ptrace(struct task_struct *child, long request,
 #endif
 
                case PTRACE_GET_THREAD_AREA:
-                       ret = put_user(task_thread_info(child)->tp_value,
+                       ret = put_user(task_thread_info(child)->tp_value[0],
                                       datap);
                        break;
 
index a8eada1dba87ae5df0b4e2cf7121cddafeaf718d..536d4c803b85d17bc4a0b406b4634dda46aa80a2 100644 (file)
@@ -662,7 +662,7 @@ asmlinkage int arm_syscall(int no, struct pt_regs *regs)
                return regs->ARM_r0;
 
        case NR(set_tls):
-               thread->tp_value = regs->ARM_r0;
+               thread->tp_value[0] = regs->ARM_r0;
                if (tls_emu)
                        return 0;
                if (has_tls_reg) {
@@ -780,7 +780,7 @@ static int get_tp_trap(struct pt_regs *regs, unsigned int instr)
        int reg = (instr >> 12) & 15;
        if (reg == 15)
                return 1;
-       regs->uregs[reg] = current_thread_info()->tp_value;
+       regs->uregs[reg] = current_thread_info()->tp_value[0];
        regs->ARM_pc += 4;
        return 0;
 }
index a7bd294bc012ede36da8565d6bbdc821b3117105..c038a631b581733331234d19a46440914053b684 100644 (file)
@@ -114,8 +114,8 @@ typedef struct
    u32 advancedmode;
    struct MLC_feature_set feature_set;
 }flashdev_info_t,*pflashdev_info;
-#if 0
-static const flashdev_info gen_FlashTable[]={
+
+static const flashdev_info_t gen_FlashTable_p[]={
        {{0x45,0xDE,0x94,0x93,0x76,0x57}, 6,5,IO_8BIT,8192,4096,16384,1280,0x10804222, 0xC03222,0x101,80,VEND_SANDISK,1024, "SDTNQGAMA008G ",0 ,
                {SANDISK_16K, {0xEF,0xEE,0xFF,16,0x11,0,1,RTYPE_SANDISK_19NM,{0x80, 0x00},{0x80, 0x01}},
                {RAND_TYPE_SAMSUNG,{0x2D2D,1,1,1,1,1}}}},
@@ -147,5 +147,6 @@ static const flashdev_info gen_FlashTable[]={
                {SANDISK_16K, {0xEF,0xEE,0xFF,7,0xFF,7,0,RTYPE_TOSHIBA,{0x80, 0x00},{0x80, 0x01}},
                {RAND_TYPE_SAMSUNG,{0x2D2D,1,1,1,1,1}}}},
 };
-#endif
+
+static unsigned int flash_number = sizeof(gen_FlashTable_p) / sizeof(flashdev_info_t);
 #endif
index d5413b85e025cbdfd230b38431c76cb3de68754d..0a5189d7ef26c7492d8032bc477aa507af84f858 100644 (file)
@@ -50,7 +50,6 @@ int kdCISModulePowerOn(CAMERA_DUAL_CAMERA_SENSOR_ENUM SensorIdx, char *currSenso
 #define IDX_PS_ON   2
 #define IDX_PS_OFF  3
 
-#define IDX_SUB_CAM 1
 
     u32 pinSet[2][8] =
     {
@@ -219,16 +218,6 @@ int kdCISModulePowerOn(CAMERA_DUAL_CAMERA_SENSOR_ENUM SensorIdx, char *currSenso
             //OV5648 Power UP
             //First Power Pin low and Reset Pin Low
             
-       /*[BUGFIX] ADD-BEGIN by sz.chengming.xiang for PR-1021927(pixi3-7-3G) 2015/06/15
-       set front sensor hi708's pwdn to high, make sure it is in Hi-Z state so that 
-       it will not affect i2c comunication on this bus*/
-                       if (GPIO_CAMERA_INVALID != pinSet[IDX_SUB_CAM][IDX_PS_CMPDN]) {
-                               if(mt_set_gpio_mode(pinSet[IDX_SUB_CAM][IDX_PS_CMPDN],pinSet[IDX_SUB_CAM][IDX_PS_CMPDN+IDX_PS_MODE])){PK_DBG("[CAMERA LENS] set gpio mode failed!! \n");}
-                               if(mt_set_gpio_dir(pinSet[IDX_SUB_CAM][IDX_PS_CMPDN],GPIO_DIR_OUT)){PK_DBG("[CAMERA LENS] set gpio dir failed!! \n");}
-                               if(mt_set_gpio_out(pinSet[IDX_SUB_CAM][IDX_PS_CMPDN],pinSet[IDX_SUB_CAM][IDX_PS_CMPDN+IDX_PS_ON])){PK_DBG("[CAMERA LENS] set gpio failed!! \n");} //high == power down lens module
-                       }
-       /*[BUGFIX] ADD-END by sz.chengming.xiang for PR-1021927 2015/06/15*/
-
             if(TRUE != hwPowerOn(CAMERA_POWER_VCAM_D2, VOL_1800, mode_name))
             {
                 PK_DBG("[CAMERA SENSOR] Fail to enable IO power\n");
@@ -269,6 +258,9 @@ int kdCISModulePowerOn(CAMERA_DUAL_CAMERA_SENSOR_ENUM SensorIdx, char *currSenso
             
             // wait power to be stable 
             mdelay(25);
+            
+            
+;
         }
         else if ((pinSetIdx == 0) && currSensorName && (0 == strcmp(SENSOR_DRVNAME_S5K5E2YA_MIPI_RAW,currSensorName))) 
         {
@@ -593,19 +585,9 @@ int kdCISModulePowerOn(CAMERA_DUAL_CAMERA_SENSOR_ENUM SensorIdx, char *currSenso
             if(mt_set_gpio_dir(pinSet[pinSetIdx][IDX_PS_CMRST],GPIO_DIR_OUT)){PK_DBG("[CAMERA SENSOR] set gpio dir failed!! \n");}
             if(mt_set_gpio_dir(pinSet[pinSetIdx][IDX_PS_CMPDN],GPIO_DIR_OUT)){PK_DBG("[CAMERA LENS] set gpio dir failed!! \n");}
             if(mt_set_gpio_out(pinSet[pinSetIdx][IDX_PS_CMRST],pinSet[pinSetIdx][IDX_PS_CMRST+IDX_PS_OFF])){PK_DBG("[CAMERA SENSOR] set gpio failed!! \n");} //low == reset sensor
-             if(mt_set_gpio_out(pinSet[pinSetIdx][IDX_PS_CMPDN],pinSet[pinSetIdx][IDX_PS_CMPDN+IDX_PS_OFF])){PK_DBG("[CAMERA LENS] set gpio failed!! \n");} //high == power down lens module
-        }
-             
-        /*[BUGFIX] ADD-BEGIN by sz.chengming.xiang for PR-1021927(pixi3-7-3G) 2015/06/15
-        as open main camera will set sub cam's pwd to high ,so should set it back when close main camera
-        to prevent current leakage */
-        if ((pinSetIdx != IDX_SUB_CAM) && (GPIO_CAMERA_INVALID != pinSet[IDX_SUB_CAM][IDX_PS_CMPDN])) {
-        {
-               mt_set_gpio_mode(pinSet[IDX_SUB_CAM][IDX_PS_CMPDN],pinSet[IDX_SUB_CAM][IDX_PS_CMPDN+IDX_PS_MODE]);
-               mt_set_gpio_dir(pinSet[IDX_SUB_CAM][IDX_PS_CMPDN],GPIO_DIR_OUT);
-          mt_set_gpio_out(pinSet[IDX_SUB_CAM][IDX_PS_CMPDN],pinSet[IDX_SUB_CAM][IDX_PS_CMPDN+IDX_PS_OFF]);     
+           if(mt_set_gpio_out(pinSet[pinSetIdx][IDX_PS_CMPDN],pinSet[pinSetIdx][IDX_PS_CMPDN+IDX_PS_OFF])){PK_DBG("[CAMERA LENS] set gpio failed!! \n");} //high == power down lens module
         }
-        
+
        if(TRUE != hwPowerDown(CAMERA_POWER_VCAM_A,mode_name)) {
             PK_DBG("[CAMERA SENSOR] Fail to OFF a power\n");
         }
@@ -628,7 +610,7 @@ int kdCISModulePowerOn(CAMERA_DUAL_CAMERA_SENSOR_ENUM SensorIdx, char *currSenso
 _kdCISModulePowerOn_exit_:
     return -EIO;
 }
-}
+
 EXPORT_SYMBOL(kdCISModulePowerOn);
 
 
index 5f3049bd458a8093925140a53d6715f0caa1226a..e4e80ee0c0532966efdc65d0e98e2af05dbee070 100644 (file)
@@ -142,187 +142,122 @@ typedef enum
 // T0 -10C
 BATTERY_PROFILE_STRUC battery_profile_t0[] =
 {
-       {0        ,4174},       
-       {2        ,4153},       
-       {3        ,4136},       
-       {5        ,4120},       
-       {7        ,4105},       
-       {8        ,4090},       
-       {10   ,4076},   
-       {12   ,4062},   
-       {14   ,4049},   
-       {15   ,4035},   
-       {17   ,4022},   
-       {19   ,4009},   
-       {20   ,3997},   
-       {22   ,3986},   
-       {24   ,3975},   
-       {25   ,3965},   
-       {27   ,3955},   
-       {29   ,3944},   
-       {30   ,3935},   
-       {32   ,3926},   
-       {34   ,3917},   
-       {35   ,3908},   
-       {37   ,3898},   
-       {39   ,3885},   
-       {41   ,3872},   
-       {42   ,3860},   
-       {44   ,3855},   
-       {46   ,3848},   
-       {47   ,3842},   
-       {49   ,3836},   
-       {51   ,3830},   
-       {52   ,3823},   
-       {54   ,3818},   
-       {56   ,3806},   
-       {57   ,3803},   
-       {59   ,3798},   
-       {61   ,3790},   
-       {62   ,3789},   
-       {64   ,3784},   
-       {66   ,3780},   
-       {68   ,3778},   
-       {69   ,3777},   
-       {71   ,3776},   
-       {73   ,3772},   
-       {74   ,3769},   
-       {76   ,3761},   
-       {78   ,3752},   
-       {79   ,3748},   
-       {81   ,3742},   
-       {83   ,3735},   
-       {84   ,3732},   
-       {86   ,3710},   
-       {88   ,3700},   
-       {90   ,3680},   
-       {91   ,3665},   
-       {93   ,3655},   
-       {95   ,3642},   
-       {96   ,3626},   
-       {98   ,3575},   
-       {99   ,3505},   
-       {100  ,3448},   
-       {101  ,3330},   
-       {101  , 3309},  
-       {101  , 3300},  
-       {101  , 3295},  
-       {101  , 3293},  
-       {101  , 3291},  
-       {101  , 3291},  
-       {101  , 3291},  
-       {101  , 3290},  
-       {101  , 3289},  
-       {101  , 3289},  
-       {101  , 3287},  
-       {101  , 3288},  
-       {101  , 3286},  
-       {101  , 3286},  
-       {101  , 3285},  
-       {101  , 3284},  
-       {101  , 3283},  
-       {101  , 3281},  
-       {101  , 3281},  
-       {101  , 3279},  
-       {101  , 3278},  
-       {101  , 3276},  
-       {101  , 3275},  
-       {101  , 3275}      
-
-
+       {0  ,4174},          
+       {2  ,4151},     
+       {4  ,4131},     
+       {6  ,4113},     
+       {8  ,4096},     
+       {10 ,4080},     
+       {11 ,4065},     
+       {13 ,4048},     
+       {15 ,4030},     
+       {17 ,4013},     
+       {19 ,3998},     
+       {21 ,3984},     
+       {23 ,3972},     
+       {25 ,3961},     
+       {27 ,3950},     
+       {29 ,3938},     
+       {30 ,3927},     
+       {32 ,3917},     
+       {34 ,3907},     
+       {36 ,3897},     
+       {38 ,3887},     
+       {40 ,3874},     
+       {42 ,3858},     
+       {44 ,3840},     
+       {46 ,3828},     
+       {48 ,3819},     
+       {50 ,3811},     
+       {51 ,3805},     
+       {53 ,3800},     
+       {55 ,3794},     
+       {57 ,3790},     
+       {59 ,3785},     
+       {61 ,3782},     
+       {63 ,3778},     
+       {65 ,3776},
+       {67 ,3775},     
+       {69 ,3773},     
+       {71 ,3770},     
+       {72 ,3767},     
+       {74 ,3763},     
+       {76 ,3757},     
+       {78 ,3748},     
+       {80 ,3740},     
+       {82 ,3729},     
+       {84 ,3713},     
+       {86 ,3695},     
+       {88 ,3687},     
+       {90 ,3684},     
+       {91 ,3681},     
+       {93 ,3677},     
+       {95 ,3662},     
+       {97 ,3594},     
+       {98 ,3481},
+       {99,3450},
+       {100,3420}
 };
       
         
 // T1 0C 
 BATTERY_PROFILE_STRUC battery_profile_t1[] =
 {
-       {0        ,4174},       
-       {2        ,4153},       
-       {3        ,4136},       
-       {5        ,4120},       
-       {7        ,4105},       
-       {8        ,4090},       
-       {10   ,4076},   
-       {12   ,4062},   
-       {14   ,4049},   
-       {15   ,4035},   
-       {17   ,4022},   
-       {19   ,4009},   
-       {20   ,3997},   
-       {22   ,3986},   
-       {24   ,3975},   
-       {25   ,3965},   
-       {27   ,3955},   
-       {29   ,3944},   
-       {30   ,3935},   
-       {32   ,3926},   
-       {34   ,3917},   
-       {35   ,3908},   
-       {37   ,3898},   
-       {39   ,3885},   
-       {41   ,3872},   
-       {42   ,3860},   
-       {44   ,3855},   
-       {46   ,3848},   
-       {47   ,3842},   
-       {49   ,3836},   
-       {51   ,3830},   
-       {52   ,3823},   
-       {54   ,3818},   
-       {56   ,3806},   
-       {57   ,3803},   
-       {59   ,3798},   
-       {61   ,3790},   
-       {62   ,3789},   
-       {64   ,3784},   
-       {66   ,3780},   
-       {68   ,3778},   
-       {69   ,3777},   
-       {71   ,3776},   
-       {73   ,3772},   
-       {74   ,3769},   
-       {76   ,3761},   
-       {78   ,3752},   
-       {79   ,3748},   
-       {81   ,3742},   
-       {83   ,3735},   
-       {84   ,3732},   
-       {86   ,3710},   
-       {88   ,3700},   
-       {90   ,3680},   
-       {91   ,3665},   
-       {93   ,3655},   
-       {95   ,3642},   
-       {96   ,3626},   
-       {98   ,3575},   
-       {99   ,3505},   
-       {100  ,3448},   
-       {101  ,3330},   
-       {101  , 3309},  
-       {101  , 3300},  
-       {101  , 3295},  
-       {101  , 3293},  
-       {101  , 3291},  
-       {101  , 3291},  
-       {101  , 3291},  
-       {101  , 3290},  
-       {101  , 3289},  
-       {101  , 3289},  
-       {101  , 3287},  
-       {101  , 3288},  
-       {101  , 3286},  
-       {101  , 3286},  
-       {101  , 3285},  
-       {101  , 3284},  
-       {101  , 3283},  
-       {101  , 3281},  
-       {101  , 3281},  
-       {101  , 3279},  
-       {101  , 3278},  
-       {101  , 3276},  
-       {101  , 3275},  
-       {101  , 3275}      
-
+       {0  ,4174},          
+       {2  ,4151},     
+       {4  ,4131},     
+       {6  ,4113},     
+       {8  ,4096},     
+       {10 ,4080},     
+       {11 ,4065},     
+       {13 ,4048},     
+       {15 ,4030},     
+       {17 ,4013},     
+       {19 ,3998},     
+       {21 ,3984},     
+       {23 ,3972},     
+       {25 ,3961},     
+       {27 ,3950},     
+       {29 ,3938},     
+       {30 ,3927},     
+       {32 ,3917},     
+       {34 ,3907},     
+       {36 ,3897},     
+       {38 ,3887},     
+       {40 ,3874},     
+       {42 ,3858},     
+       {44 ,3840},     
+       {46 ,3828},     
+       {48 ,3819},     
+       {50 ,3811},     
+       {51 ,3805},     
+       {53 ,3800},     
+       {55 ,3794},     
+       {57 ,3790},     
+       {59 ,3785},     
+       {61 ,3782},     
+       {63 ,3778},     
+       {65 ,3776},
+       {67 ,3775},     
+       {69 ,3773},     
+       {71 ,3770},     
+       {72 ,3767},     
+       {74 ,3763},     
+       {76 ,3757},     
+       {78 ,3748},     
+       {80 ,3740},     
+       {82 ,3729},     
+       {84 ,3713},     
+       {86 ,3695},     
+       {88 ,3687},     
+       {90 ,3684},     
+       {91 ,3681},     
+       {93 ,3677},     
+       {95 ,3662},     
+       {97 ,3594},     
+       {98 ,3481},
+       {99,3450},
+       {100,3420}
 
 };
            
@@ -330,185 +265,122 @@ BATTERY_PROFILE_STRUC battery_profile_t1[] =
 // T2 25C
 BATTERY_PROFILE_STRUC battery_profile_t2[] =
 {
-       {0        ,4174},       
-       {2        ,4153},       
-       {3        ,4136},       
-       {5        ,4120},       
-       {7        ,4105},       
-       {8        ,4090},       
-       {10   ,4076},   
-       {12   ,4062},   
-       {14   ,4049},   
-       {15   ,4035},   
-       {17   ,4022},   
-       {19   ,4009},   
-       {20   ,3997},   
-       {22   ,3986},   
-       {24   ,3975},   
-       {25   ,3965},   
-       {27   ,3955},   
-       {29   ,3944},   
-       {30   ,3935},   
-       {32   ,3926},   
-       {34   ,3917},   
-       {35   ,3908},   
-       {37   ,3898},   
-       {39   ,3885},   
-       {41   ,3872},   
-       {42   ,3860},   
-       {44   ,3855},   
-       {46   ,3848},   
-       {47   ,3842},   
-       {49   ,3836},   
-       {51   ,3830},   
-       {52   ,3823},   
-       {54   ,3818},   
-       {56   ,3806},   
-       {57   ,3803},   
-       {59   ,3798},   
-       {61   ,3790},   
-       {62   ,3789},   
-       {64   ,3784},   
-       {66   ,3780},   
-       {68   ,3778},   
-       {69   ,3777},   
-       {71   ,3776},   
-       {73   ,3772},   
-       {74   ,3769},   
-       {76   ,3761},   
-       {78   ,3752},   
-       {79   ,3748},   
-       {81   ,3742},   
-       {83   ,3735},   
-       {84   ,3732},   
-       {86   ,3710},   
-       {88   ,3700},   
-       {90   ,3680},   
-       {91   ,3665},   
-       {93   ,3655},   
-       {95   ,3642},   
-       {96   ,3626},   
-       {98   ,3575},   
-       {99   ,3505},   
-       {100  ,3448},   
-       {101  ,3330},   
-       {101  , 3309},  
-       {101  , 3300},  
-       {101  , 3295},  
-       {101  , 3293},  
-       {101  , 3291},  
-       {101  , 3291},  
-       {101  , 3291},  
-       {101  , 3290},  
-       {101  , 3289},  
-       {101  , 3289},  
-       {101  , 3287},  
-       {101  , 3288},  
-       {101  , 3286},  
-       {101  , 3286},  
-       {101  , 3285},  
-       {101  , 3284},  
-       {101  , 3283},  
-       {101  , 3281},  
-       {101  , 3281},  
-       {101  , 3279},  
-       {101  , 3278},  
-       {101  , 3276},  
-       {101  , 3275},  
-       {101  , 3275}      
+       {0  ,4174},          
+       {2  ,4151},     
+       {4  ,4131},     
+       {6  ,4113},     
+       {8  ,4096},     
+       {10 ,4080},     
+       {11 ,4065},     
+       {13 ,4048},     
+       {15 ,4030},     
+       {17 ,4013},     
+       {19 ,3998},     
+       {21 ,3984},     
+       {23 ,3972},     
+       {25 ,3961},     
+       {27 ,3950},     
+       {29 ,3938},     
+       {30 ,3927},     
+       {32 ,3917},     
+       {34 ,3907},     
+       {36 ,3897},     
+       {38 ,3887},     
+       {40 ,3874},     
+       {42 ,3858},     
+       {44 ,3840},     
+       {46 ,3828},     
+       {48 ,3819},     
+       {50 ,3811},     
+       {51 ,3805},     
+       {53 ,3800},     
+       {55 ,3794},     
+       {57 ,3790},     
+       {59 ,3785},     
+       {61 ,3782},     
+       {63 ,3778},     
+       {65 ,3776},
+       {67 ,3775},     
+       {69 ,3773},     
+       {71 ,3770},     
+       {72 ,3767},     
+       {74 ,3763},     
+       {76 ,3757},     
+       {78 ,3748},     
+       {80 ,3740},     
+       {82 ,3729},     
+       {84 ,3713},     
+       {86 ,3695},     
+       {88 ,3687},     
+       {90 ,3684},     
+       {91 ,3681},     
+       {93 ,3677},     
+       {95 ,3662},     
+       {97 ,3594},     
+       {98 ,3481},
+       {99,3450},
+       {100,3420}
 
 };     
 
 // T3 50C
 BATTERY_PROFILE_STRUC battery_profile_t3[] =
 {
-       {0        ,4174},       
-       {2        ,4153},       
-       {3        ,4136},       
-       {5        ,4120},       
-       {7        ,4105},       
-       {8        ,4090},       
-       {10   ,4076},   
-       {12   ,4062},   
-       {14   ,4049},   
-       {15   ,4035},   
-       {17   ,4022},   
-       {19   ,4009},   
-       {20   ,3997},   
-       {22   ,3986},   
-       {24   ,3975},   
-       {25   ,3965},   
-       {27   ,3955},   
-       {29   ,3944},   
-       {30   ,3935},   
-       {32   ,3926},   
-       {34   ,3917},   
-       {35   ,3908},   
-       {37   ,3898},   
-       {39   ,3885},   
-       {41   ,3872},   
-       {42   ,3860},   
-       {44   ,3855},   
-       {46   ,3848},   
-       {47   ,3842},   
-       {49   ,3836},   
-       {51   ,3830},   
-       {52   ,3823},   
-       {54   ,3818},   
-       {56   ,3806},   
-       {57   ,3803},   
-       {59   ,3798},   
-       {61   ,3790},   
-       {62   ,3789},   
-       {64   ,3784},   
-       {66   ,3780},   
-       {68   ,3778},   
-       {69   ,3777},   
-       {71   ,3776},   
-       {73   ,3772},   
-       {74   ,3769},   
-       {76   ,3761},   
-       {78   ,3752},   
-       {79   ,3748},   
-       {81   ,3742},   
-       {83   ,3735},   
-       {84   ,3732},   
-       {86   ,3710},   
-       {88   ,3700},   
-       {90   ,3680},   
-       {91   ,3665},   
-       {93   ,3655},   
-       {95   ,3642},   
-       {96   ,3626},   
-       {98   ,3575},   
-       {99   ,3505},   
-       {100  ,3448},   
-       {101  ,3330},   
-       {101  , 3309},  
-       {101  , 3300},  
-       {101  , 3295},  
-       {101  , 3293},  
-       {101  , 3291},  
-       {101  , 3291},  
-       {101  , 3291},  
-       {101  , 3290},  
-       {101  , 3289},  
-       {101  , 3289},  
-       {101  , 3287},  
-       {101  , 3288},  
-       {101  , 3286},  
-       {101  , 3286},  
-       {101  , 3285},  
-       {101  , 3284},  
-       {101  , 3283},  
-       {101  , 3281},  
-       {101  , 3281},  
-       {101  , 3279},  
-       {101  , 3278},  
-       {101  , 3276},  
-       {101  , 3275},  
-       {101  , 3275}      
-
+       {0  ,4174},          
+       {2  ,4151},     
+       {4  ,4131},     
+       {6  ,4113},     
+       {8  ,4096},     
+       {10 ,4080},     
+       {11 ,4065},     
+       {13 ,4048},     
+       {15 ,4030},     
+       {17 ,4013},     
+       {19 ,3998},     
+       {21 ,3984},     
+       {23 ,3972},     
+       {25 ,3961},     
+       {27 ,3950},     
+       {29 ,3938},     
+       {30 ,3927},     
+       {32 ,3917},     
+       {34 ,3907},     
+       {36 ,3897},     
+       {38 ,3887},     
+       {40 ,3874},     
+       {42 ,3858},     
+       {44 ,3840},     
+       {46 ,3828},     
+       {48 ,3819},     
+       {50 ,3811},     
+       {51 ,3805},     
+       {53 ,3800},     
+       {55 ,3794},     
+       {57 ,3790},     
+       {59 ,3785},     
+       {61 ,3782},     
+       {63 ,3778},     
+       {65 ,3776},
+       {67 ,3775},     
+       {69 ,3773},     
+       {71 ,3770},     
+       {72 ,3767},     
+       {74 ,3763},     
+       {76 ,3757},     
+       {78 ,3748},     
+       {80 ,3740},     
+       {82 ,3729},     
+       {84 ,3713},     
+       {86 ,3695},     
+       {88 ,3687},     
+       {90 ,3684},     
+       {91 ,3681},     
+       {93 ,3677},     
+       {95 ,3662},     
+       {97 ,3594},     
+       {98 ,3481},
+       {99,3450},
+       {100,3420}
 
 };           
 
@@ -610,373 +482,365 @@ BATTERY_PROFILE_STRUC battery_profile_temperature[] =
 // T0 -10C
 R_PROFILE_STRUC r_profile_t0[] =
 {
-    {120 , 4174},    
-    {120 , 4153},   
-    {120 , 4136},   
-    {120 , 4120},   
-    {125 , 4105},   
-    {128 , 4090},   
-    {130 , 4076},   
-    {135 , 4062},   
-    {135 , 4049},   
-    {135 , 4035},   
-    {135 , 4022},   
-    {135 , 4009},   
-    {135 , 3997},   
-    {135 , 3986},   
-    {135 , 3975},   
-    {135 , 3965},   
-    {135 , 3955},   
-    {135 , 3944},   
-    {135 , 3935},   
-    {135 , 3926},   
-    {135 , 3917},   
-    {135 , 3908},   
-    {135 , 3899},   
-    {135 , 3887},   
-    {133 , 3869},   
-    {133 , 3852},   
-    {132 , 3839},   
-    {132 , 3830},   
-    {132 , 3823},   
-    {132 , 3817},   
-    {132 , 3812},   
-    {132 , 3806},   
-    {132 , 3801},   
-    {132 , 3797},   
-    {132 , 3793},   
-    {132 , 3789},   
-    {132 , 3786},   
-    {132 , 3782},   
-    {132 , 3778},   
-    {132 , 3777},   
-    {132 , 3774},   
-    {132 , 3772},   
-    {132 , 3770},   
-    {132 , 3767},   
-    {128 , 3763},   
-    {128 , 3759},   
-    {125 , 3752},   
-    {125 , 3746},   
-    {125 , 3739},   
-    {125 , 3728},   
-    {125 , 3714},   
-    {125 , 3700},   
-    {125 , 3687},   
-    {125 , 3684},   
-    {125 , 3682},   
-    {125 , 3680},   
-    {120 , 3676},   
-    {120 , 3658},   
-    {120 , 3580},   
-    {120 , 3448},   
-    {120 , 3330},   
-    {122 , 3309},   
-    {118 , 3300},   
-    {122 , 3295},   
-    {120 , 3293},   
-    {117 , 3291},   
-    {123 , 3291},   
-    {125 , 3291},   
-    {127 , 3290},   
-    {125 , 3289},   
-    {122 , 3289},   
-    {123 , 3287},   
-    {122 , 3288},   
-    {123 , 3286},   
-    {122 , 3286},   
-    {125 , 3285},   
-    {125 , 3284},   
-    {127 , 3283},   
-    {127 , 3281},   
-    {125 , 3281},   
-    {127 , 3279},   
-    {128 , 3278},   
-    {127 , 3276},   
-    {128 , 3275},   
-    {127 , 3275}    
-
-
+       {153,4174},
+       {153,4151},
+       {155,4131},
+       {158,4113},
+       {160,4096},
+       {162,4080},
+       {167,4065},
+       {170,4048},
+       {172,4030},
+       {173,4013},
+       {177,3998},
+       {177,3984},
+       {182,3972},
+       {185,3961},
+       {187,3950},
+       {188,3938},
+       {190,3927},
+       {193,3917},
+       {195,3907},
+       {198,3897},
+       {200,3887},
+       {195,3874},
+       {185,3858},
+       {172,3840},
+       {167,3828},
+       {165,3819},
+       {163,3811},
+       {167,3805},
+       {168,3800},
+       {170,3794},
+       {173,3790},
+       {173,3785},
+       {177,3782},
+       {178,3778},
+       {182,3776},
+       {187,3775},
+       {190,3773},
+       {192,3770},
+       {193,3767},
+       {195,3763},
+       {193,3757},
+       {192,3748},
+       {195,3740},
+       {197,3729},
+       {195,3713},
+       {193,3695},
+       {193,3687},
+       {203,3684},
+       {220,3681},
+       {240,3677},
+       {258,3662},
+       {255,3594},
+       {293,3481},
+       {305,3382},
+       {255,3353},
+       {233,3338},
+       {215,3329},
+       {210,3323},
+       {202,3318},
+       {198,3316},
+       {193,3314},
+       {188,3313},
+       {188,3311},
+       {187,3312},
+       {185,3310},
+       {187,3310},
+       {187,3309},
+       {185,3307},
+       {182,3308},
+       {183,3307},
+       {182,3307},
+       {183,3307},
+       {185,3307},
+       {187,3306},
+       {185,3306},
+       {185,3306},
+       {183,3305},
+       {188,3304},
+       {187,3303},
+       {188,3302},
+       {185,3301},
+       {185,3301},
+       {187,3301},
+       {185,3300},
+       {187,3300},
+       {167,3300}
 };
 
 // T1 0C
 R_PROFILE_STRUC r_profile_t1[] =
 {
-    {120 , 4174},    
-    {120 , 4153},   
-    {120 , 4136},   
-    {120 , 4120},   
-    {125 , 4105},   
-    {128 , 4090},   
-    {130 , 4076},   
-    {135 , 4062},   
-    {135 , 4049},   
-    {135 , 4035},   
-    {135 , 4022},   
-    {135 , 4009},   
-    {135 , 3997},   
-    {135 , 3986},   
-    {135 , 3975},   
-    {135 , 3965},   
-    {135 , 3955},   
-    {135 , 3944},   
-    {135 , 3935},   
-    {135 , 3926},   
-    {135 , 3917},   
-    {135 , 3908},   
-    {135 , 3899},   
-    {135 , 3887},   
-    {133 , 3869},   
-    {133 , 3852},   
-    {132 , 3839},   
-    {132 , 3830},   
-    {132 , 3823},   
-    {132 , 3817},   
-    {132 , 3812},   
-    {132 , 3806},   
-    {132 , 3801},   
-    {132 , 3797},   
-    {132 , 3793},   
-    {132 , 3789},   
-    {132 , 3786},   
-    {132 , 3782},   
-    {132 , 3778},   
-    {132 , 3777},   
-    {132 , 3774},   
-    {132 , 3772},   
-    {132 , 3770},   
-    {132 , 3767},   
-    {128 , 3763},   
-    {128 , 3759},   
-    {125 , 3752},   
-    {125 , 3746},   
-    {125 , 3739},   
-    {125 , 3728},   
-    {125 , 3714},   
-    {125 , 3700},   
-    {125 , 3687},   
-    {125 , 3684},   
-    {125 , 3682},   
-    {125 , 3680},   
-    {120 , 3676},   
-    {120 , 3658},   
-    {120 , 3580},   
-    {120 , 3448},   
-    {120 , 3330},   
-    {122 , 3309},   
-    {118 , 3300},   
-    {122 , 3295},   
-    {120 , 3293},   
-    {117 , 3291},   
-    {123 , 3291},   
-    {125 , 3291},   
-    {127 , 3290},   
-    {125 , 3289},   
-    {122 , 3289},   
-    {123 , 3287},   
-    {122 , 3288},   
-    {123 , 3286},   
-    {122 , 3286},   
-    {125 , 3285},   
-    {125 , 3284},   
-    {127 , 3283},   
-    {127 , 3281},   
-    {125 , 3281},   
-    {127 , 3279},   
-    {128 , 3278},   
-    {127 , 3276},   
-    {128 , 3275},   
-    {127 , 3275}    
-
-
-
+       {153,4174},
+       {153,4151},
+       {155,4131},
+       {158,4113},
+       {160,4096},
+       {162,4080},
+       {167,4065},
+       {170,4048},
+       {172,4030},
+       {173,4013},
+       {177,3998},
+       {177,3984},
+       {182,3972},
+       {185,3961},
+       {187,3950},
+       {188,3938},
+       {190,3927},
+       {193,3917},
+       {195,3907},
+       {198,3897},
+       {200,3887},
+       {195,3874},
+       {185,3858},
+       {172,3840},
+       {167,3828},
+       {165,3819},
+       {163,3811},
+       {167,3805},
+       {168,3800},
+       {170,3794},
+       {173,3790},
+       {173,3785},
+       {177,3782},
+       {178,3778},
+       {182,3776},
+       {187,3775},
+       {190,3773},
+       {192,3770},
+       {193,3767},
+       {195,3763},
+       {193,3757},
+       {192,3748},
+       {195,3740},
+       {197,3729},
+       {195,3713},
+       {193,3695},
+       {193,3687},
+       {203,3684},
+       {220,3681},
+       {240,3677},
+       {258,3662},
+       {255,3594},
+       {293,3481},
+       {305,3382},
+       {255,3353},
+       {233,3338},
+       {215,3329},
+       {210,3323},
+       {202,3318},
+       {198,3316},
+       {193,3314},
+       {188,3313},
+       {188,3311},
+       {187,3312},
+       {185,3310},
+       {187,3310},
+       {187,3309},
+       {185,3307},
+       {182,3308},
+       {183,3307},
+       {182,3307},
+       {183,3307},
+       {185,3307},
+       {187,3306},
+       {185,3306},
+       {185,3306},
+       {183,3305},
+       {188,3304},
+       {187,3303},
+       {188,3302},
+       {185,3301},
+       {185,3301},
+       {187,3301},
+       {185,3300},
+       {187,3300},
+       {167,3300}
 };    
 
 // T2 25C
 R_PROFILE_STRUC r_profile_t2[] =
 {
-    {120 , 4174},    
-    {120 , 4153},   
-    {120 , 4136},   
-    {120 , 4120},   
-    {125 , 4105},   
-    {128 , 4090},   
-    {130 , 4076},   
-    {135 , 4062},   
-    {135 , 4049},   
-    {135 , 4035},   
-    {135 , 4022},   
-    {135 , 4009},   
-    {135 , 3997},   
-    {135 , 3986},   
-    {135 , 3975},   
-    {135 , 3965},   
-    {135 , 3955},   
-    {135 , 3944},   
-    {135 , 3935},   
-    {135 , 3926},   
-    {135 , 3917},   
-    {135 , 3908},   
-    {135 , 3899},   
-    {135 , 3887},   
-    {133 , 3869},   
-    {133 , 3852},   
-    {132 , 3839},   
-    {132 , 3830},   
-    {132 , 3823},   
-    {132 , 3817},   
-    {132 , 3812},   
-    {132 , 3806},   
-    {132 , 3801},   
-    {132 , 3797},   
-    {132 , 3793},   
-    {132 , 3789},   
-    {132 , 3786},   
-    {132 , 3782},   
-    {132 , 3778},   
-    {132 , 3777},   
-    {132 , 3774},   
-    {132 , 3772},   
-    {132 , 3770},   
-    {132 , 3767},   
-    {128 , 3763},   
-    {128 , 3759},   
-    {125 , 3752},   
-    {125 , 3746},   
-    {125 , 3739},   
-    {125 , 3728},   
-    {125 , 3714},   
-    {125 , 3700},   
-    {125 , 3687},   
-    {125 , 3684},   
-    {125 , 3682},   
-    {125 , 3680},   
-    {120 , 3676},   
-    {120 , 3658},   
-    {120 , 3580},   
-    {120 , 3448},   
-    {120 , 3330},   
-    {122 , 3309},   
-    {118 , 3300},   
-    {122 , 3295},   
-    {120 , 3293},   
-    {117 , 3291},   
-    {123 , 3291},   
-    {125 , 3291},   
-    {127 , 3290},   
-    {125 , 3289},   
-    {122 , 3289},   
-    {123 , 3287},   
-    {122 , 3288},   
-    {123 , 3286},   
-    {122 , 3286},   
-    {125 , 3285},   
-    {125 , 3284},   
-    {127 , 3283},   
-    {127 , 3281},   
-    {125 , 3281},   
-    {127 , 3279},   
-    {128 , 3278},   
-    {127 , 3276},   
-    {128 , 3275},   
-    {127 , 3275}    
-
-
-
+       {153,4174},
+       {153,4151},
+       {155,4131},
+       {158,4113},
+       {160,4096},
+       {162,4080},
+       {167,4065},
+       {170,4048},
+       {172,4030},
+       {173,4013},
+       {177,3998},
+       {177,3984},
+       {182,3972},
+       {185,3961},
+       {187,3950},
+       {188,3938},
+       {190,3927},
+       {193,3917},
+       {195,3907},
+       {198,3897},
+       {200,3887},
+       {195,3874},
+       {185,3858},
+       {172,3840},
+       {167,3828},
+       {165,3819},
+       {163,3811},
+       {167,3805},
+       {168,3800},
+       {170,3794},
+       {173,3790},
+       {173,3785},
+       {177,3782},
+       {178,3778},
+       {182,3776},
+       {187,3775},
+       {190,3773},
+       {192,3770},
+       {193,3767},
+       {195,3763},
+       {193,3757},
+       {192,3748},
+       {195,3740},
+       {197,3729},
+       {195,3713},
+       {193,3695},
+       {193,3687},
+       {203,3684},
+       {220,3681},
+       {240,3677},
+       {258,3662},
+       {255,3594},
+       {293,3481},
+       {305,3382},
+       {255,3353},
+       {233,3338},
+       {215,3329},
+       {210,3323},
+       {202,3318},
+       {198,3316},
+       {193,3314},
+       {188,3313},
+       {188,3311},
+       {187,3312},
+       {185,3310},
+       {187,3310},
+       {187,3309},
+       {185,3307},
+       {182,3308},
+       {183,3307},
+       {182,3307},
+       {183,3307},
+       {185,3307},
+       {187,3306},
+       {185,3306},
+       {185,3306},
+       {183,3305},
+       {188,3304},
+       {187,3303},
+       {188,3302},
+       {185,3301},
+       {185,3301},
+       {187,3301},
+       {185,3300},
+       {187,3300},
+       {167,3300}
 };
 
 // T3 50C
 R_PROFILE_STRUC r_profile_t3[] =
 {
-    {120 , 4174},    
-    {120 , 4153},   
-    {120 , 4136},   
-    {120 , 4120},   
-    {125 , 4105},   
-    {128 , 4090},   
-    {130 , 4076},   
-    {135 , 4062},   
-    {135 , 4049},   
-    {135 , 4035},   
-    {135 , 4022},   
-    {135 , 4009},   
-    {135 , 3997},   
-    {135 , 3986},   
-    {135 , 3975},   
-    {135 , 3965},   
-    {135 , 3955},   
-    {135 , 3944},   
-    {135 , 3935},   
-    {135 , 3926},   
-    {135 , 3917},   
-    {135 , 3908},   
-    {135 , 3899},   
-    {135 , 3887},   
-    {133 , 3869},   
-    {133 , 3852},   
-    {132 , 3839},   
-    {132 , 3830},   
-    {132 , 3823},   
-    {132 , 3817},   
-    {132 , 3812},   
-    {132 , 3806},   
-    {132 , 3801},   
-    {132 , 3797},   
-    {132 , 3793},   
-    {132 , 3789},   
-    {132 , 3786},   
-    {132 , 3782},   
-    {132 , 3778},   
-    {132 , 3777},   
-    {132 , 3774},   
-    {132 , 3772},   
-    {132 , 3770},   
-    {132 , 3767},   
-    {128 , 3763},   
-    {128 , 3759},   
-    {125 , 3752},   
-    {125 , 3746},   
-    {125 , 3739},   
-    {125 , 3728},   
-    {125 , 3714},   
-    {125 , 3700},   
-    {125 , 3687},   
-    {125 , 3684},   
-    {125 , 3682},   
-    {125 , 3680},   
-    {120 , 3676},   
-    {120 , 3658},   
-    {120 , 3580},   
-    {120 , 3448},   
-    {120 , 3330},   
-    {122 , 3309},   
-    {118 , 3300},   
-    {122 , 3295},   
-    {120 , 3293},   
-    {117 , 3291},   
-    {123 , 3291},   
-    {125 , 3291},   
-    {127 , 3290},   
-    {125 , 3289},   
-    {122 , 3289},   
-    {123 , 3287},   
-    {122 , 3288},   
-    {123 , 3286},   
-    {122 , 3286},   
-    {125 , 3285},   
-    {125 , 3284},   
-    {127 , 3283},   
-    {127 , 3281},   
-    {125 , 3281},   
-    {127 , 3279},   
-    {128 , 3278},   
-    {127 , 3276},   
-    {128 , 3275},   
-    {127 , 3275}    
-
-
-
-
+       {153,4174},
+       {153,4151},
+       {155,4131},
+       {158,4113},
+       {160,4096},
+       {162,4080},
+       {167,4065},
+       {170,4048},
+       {172,4030},
+       {173,4013},
+       {177,3998},
+       {177,3984},
+       {182,3972},
+       {185,3961},
+       {187,3950},
+       {188,3938},
+       {190,3927},
+       {193,3917},
+       {195,3907},
+       {198,3897},
+       {200,3887},
+       {195,3874},
+       {185,3858},
+       {172,3840},
+       {167,3828},
+       {165,3819},
+       {163,3811},
+       {167,3805},
+       {168,3800},
+       {170,3794},
+       {173,3790},
+       {173,3785},
+       {177,3782},
+       {178,3778},
+       {182,3776},
+       {187,3775},
+       {190,3773},
+       {192,3770},
+       {193,3767},
+       {195,3763},
+       {193,3757},
+       {192,3748},
+       {195,3740},
+       {197,3729},
+       {195,3713},
+       {193,3695},
+       {193,3687},
+       {203,3684},
+       {220,3681},
+       {240,3677},
+       {258,3662},
+       {255,3594},
+       {293,3481},
+       {305,3382},
+       {255,3353},
+       {233,3338},
+       {215,3329},
+       {210,3323},
+       {202,3318},
+       {198,3316},
+       {193,3314},
+       {188,3313},
+       {188,3311},
+       {187,3312},
+       {185,3310},
+       {187,3310},
+       {187,3309},
+       {185,3307},
+       {182,3308},
+       {183,3307},
+       {182,3307},
+       {183,3307},
+       {185,3307},
+       {187,3306},
+       {185,3306},
+       {185,3306},
+       {183,3305},
+       {188,3304},
+       {187,3303},
+       {188,3302},
+       {185,3301},
+       {185,3301},
+       {187,3301},
+       {185,3300},
+       {187,3300},
+       {167,3300}
 };
 
 // r-table profile for actual temperature. The size should be the same as T1, T2 and T3
index e409bb911a649efd12e24e15adef9a0743e20821..1b4b1f01eb00be8418e6f76c61d9e86ec784ce83 100644 (file)
 #define MIN_CHARGE_TEMPERATURE_PLUS_X_DEGREE   4  //6 Fixed to 2 degree accoding to TCL standard
 #define MAX_LIMIT_CHARGE_TEMPERATURE    45
 #define MIN_LIMIT_CHARGE_TEMPERATURE    43
-/* [PLATFORM]-ADD-BEGIN by TCTSZ huichen@tcl.com, 05/21/2015,  BATTERY Notify PR-1007717*/
-#define MAX_RAISING_CHARGE_TEMPERATURE    58
-#define MIN_DROPPING_CHARGE_TEMPERATURE    -18
-/* [PLATFORM]-ADD-END by TCTSZ huichen@tcl.com*/
 #define ERR_CHARGE_TEMPERATURE  0xFF
 
 /* Linear Charging Threshold */
 #define BAT_LOW_TEMP_PROTECT_ENABLE         // stop charging if temp < MIN_CHARGE_TEMPERATURE
 /* [PLATFORM]-Add-END by TCTSZ.leo.guo */
 #define V_CHARGER_ENABLE 0                             // 1:ON , 0:OFF 
-/* [PLATFORM]-MOD-BEGIN by TCTSZ huichen@tcl.com, 05/18/2015,  modify OVP function FR-1005346*/
-//#define V_CHARGER_MAX 6500                           // 6.5 V
-#define V_CHARGER_MAX 6900                             // 6.9 V
-/* [PLATFORM]-MOD-END by TCTSZ huichen@tcl.com, 05/18/2015*/
+#define V_CHARGER_MAX 6500                             // 6.5 V
 #define V_CHARGER_MIN 4400                             // 4.4 V
 
 /* Tracking TIME */
index 01dbb3c5c97efe15ca7c1c4f3b48ff81f9993981..0a5189d7ef26c7492d8032bc477aa507af84f858 100644 (file)
@@ -50,7 +50,6 @@ int kdCISModulePowerOn(CAMERA_DUAL_CAMERA_SENSOR_ENUM SensorIdx, char *currSenso
 #define IDX_PS_ON   2
 #define IDX_PS_OFF  3
 
-#define IDX_SUB_CAM 1
 
     u32 pinSet[2][8] =
     {
@@ -219,16 +218,6 @@ int kdCISModulePowerOn(CAMERA_DUAL_CAMERA_SENSOR_ENUM SensorIdx, char *currSenso
             //OV5648 Power UP
             //First Power Pin low and Reset Pin Low
             
-       /*[BUGFIX] ADD-BEGIN by sz.chengming.xiang for PR-1021927(pixi3-7-3G) 2015/06/15
-       set front sensor hi708's pwdn to high, make sure it is in Hi-Z state so that 
-       it will not affect i2c comunication on this bus*/
-                       if (GPIO_CAMERA_INVALID != pinSet[IDX_SUB_CAM][IDX_PS_CMPDN]) {
-                               if(mt_set_gpio_mode(pinSet[IDX_SUB_CAM][IDX_PS_CMPDN],pinSet[IDX_SUB_CAM][IDX_PS_CMPDN+IDX_PS_MODE])){PK_DBG("[CAMERA LENS] set gpio mode failed!! \n");}
-                               if(mt_set_gpio_dir(pinSet[IDX_SUB_CAM][IDX_PS_CMPDN],GPIO_DIR_OUT)){PK_DBG("[CAMERA LENS] set gpio dir failed!! \n");}
-                               if(mt_set_gpio_out(pinSet[IDX_SUB_CAM][IDX_PS_CMPDN],pinSet[IDX_SUB_CAM][IDX_PS_CMPDN+IDX_PS_ON])){PK_DBG("[CAMERA LENS] set gpio failed!! \n");} //high == power down lens module
-                       }
-       /*[BUGFIX] ADD-END by sz.chengming.xiang for PR-1021927 2015/06/15*/
-
             if(TRUE != hwPowerOn(CAMERA_POWER_VCAM_D2, VOL_1800, mode_name))
             {
                 PK_DBG("[CAMERA SENSOR] Fail to enable IO power\n");
@@ -269,6 +258,9 @@ int kdCISModulePowerOn(CAMERA_DUAL_CAMERA_SENSOR_ENUM SensorIdx, char *currSenso
             
             // wait power to be stable 
             mdelay(25);
+            
+            
+;
         }
         else if ((pinSetIdx == 0) && currSensorName && (0 == strcmp(SENSOR_DRVNAME_S5K5E2YA_MIPI_RAW,currSensorName))) 
         {
@@ -595,17 +587,7 @@ int kdCISModulePowerOn(CAMERA_DUAL_CAMERA_SENSOR_ENUM SensorIdx, char *currSenso
             if(mt_set_gpio_out(pinSet[pinSetIdx][IDX_PS_CMRST],pinSet[pinSetIdx][IDX_PS_CMRST+IDX_PS_OFF])){PK_DBG("[CAMERA SENSOR] set gpio failed!! \n");} //low == reset sensor
            if(mt_set_gpio_out(pinSet[pinSetIdx][IDX_PS_CMPDN],pinSet[pinSetIdx][IDX_PS_CMPDN+IDX_PS_OFF])){PK_DBG("[CAMERA LENS] set gpio failed!! \n");} //high == power down lens module
         }
-        
-        /*[BUGFIX] ADD-BEGIN by sz.chengming.xiang for PR-1021927(pixi3-7-3G) 2015/06/15
-        as open main camera will set sub cam's pwd to high ,so should set it back when close main camera
-        to prevent current leakage */
-        if ((pinSetIdx != IDX_SUB_CAM) && (GPIO_CAMERA_INVALID != pinSet[IDX_SUB_CAM][IDX_PS_CMPDN])) {
-        {
-               mt_set_gpio_mode(pinSet[IDX_SUB_CAM][IDX_PS_CMPDN],pinSet[IDX_SUB_CAM][IDX_PS_CMPDN+IDX_PS_MODE]);
-               mt_set_gpio_dir(pinSet[IDX_SUB_CAM][IDX_PS_CMPDN],GPIO_DIR_OUT);
-          mt_set_gpio_out(pinSet[IDX_SUB_CAM][IDX_PS_CMPDN],pinSet[IDX_SUB_CAM][IDX_PS_CMPDN+IDX_PS_OFF]);     
-        }
-        
+
        if(TRUE != hwPowerDown(CAMERA_POWER_VCAM_A,mode_name)) {
             PK_DBG("[CAMERA SENSOR] Fail to OFF a power\n");
         }
@@ -628,7 +610,7 @@ int kdCISModulePowerOn(CAMERA_DUAL_CAMERA_SENSOR_ENUM SensorIdx, char *currSenso
 _kdCISModulePowerOn_exit_:
     return -EIO;
 }
-}
+
 EXPORT_SYMBOL(kdCISModulePowerOn);
 
 
index 453962ef884a4f91fe71d9206a8ba3d8a90d913f..c2359514566121559c7ad533814f1753389abcbe 100644 (file)
 
 /*[BUGFIX]-Add-BEGIN by TCTSZ.pingao.yang, 4/15/2015,  */
 #define MAX_SUSPEND_CURRENT 420 // 42 mA
-#define MIN_SUSPEND_CURRENT 30  // 3 mA
+#define MIN_SUSPEND_CURRENT 0  // 0 mA
 #define DEFAUL_SUSPEND_CURRENT 120 //12mA
 #define SUSPEND_CURRENT_SETP 30 //3mA
 #define SLEEP_AFTER_FG_DIFF 3  // diff about 3%
index 60044eb820f373f36a51f69f02763f57e4d24658..e4e80ee0c0532966efdc65d0e98e2af05dbee070 100644 (file)
@@ -142,187 +142,122 @@ typedef enum
 // T0 -10C
 BATTERY_PROFILE_STRUC battery_profile_t0[] =
 {
-       {0        ,4174},       
-       {2        ,4153},       
-       {3        ,4136},       
-       {5        ,4120},       
-       {7        ,4105},       
-       {8        ,4090},       
-       {10   ,4076},   
-       {12   ,4062},   
-       {14   ,4049},   
-       {15   ,4035},   
-       {17   ,4022},   
-       {19   ,4009},   
-       {20   ,3997},   
-       {22   ,3986},   
-       {24   ,3975},   
-       {25   ,3965},   
-       {27   ,3955},   
-       {29   ,3944},   
-       {30   ,3935},   
-       {32   ,3926},   
-       {34   ,3917},   
-       {35   ,3908},   
-       {37   ,3898},   
-       {39   ,3885},   
-       {41   ,3872},   
-       {42   ,3860},   
-       {44   ,3855},   
-       {46   ,3848},   
-       {47   ,3842},   
-       {49   ,3836},   
-       {51   ,3830},   
-       {52   ,3823},   
-       {54   ,3818},   
-       {56   ,3806},   
-       {57   ,3803},   
-       {59   ,3798},   
-       {61   ,3790},   
-       {62   ,3789},   
-       {64   ,3784},   
-       {66   ,3780},   
-       {68   ,3778},   
-       {69   ,3777},   
-       {71   ,3776},   
-       {73   ,3772},   
-       {74   ,3769},   
-       {76   ,3761},   
-       {78   ,3752},   
-       {79   ,3748},   
-       {81   ,3742},   
-       {83   ,3735},   
-       {84   ,3732},   
-       {86   ,3710},   
-       {88   ,3700},   
-       {90   ,3680},   
-       {91   ,3665},   
-       {93   ,3655},   
-       {95   ,3642},   
-       {96   ,3626},   
-       {98   ,3575},   
-       {99   ,3505},   
-       {100  ,3448},   
-       {101  ,3330},   
-       {101  , 3309},  
-       {101  , 3300},  
-       {101  , 3295},  
-       {101  , 3293},  
-       {101  , 3291},  
-       {101  , 3291},  
-       {101  , 3291},  
-       {101  , 3290},  
-       {101  , 3289},  
-       {101  , 3289},  
-       {101  , 3287},  
-       {101  , 3288},  
-       {101  , 3286},  
-       {101  , 3286},  
-       {101  , 3285},  
-       {101  , 3284},  
-       {101  , 3283},  
-       {101  , 3281},  
-       {101  , 3281},  
-       {101  , 3279},  
-       {101  , 3278},  
-       {101  , 3276},  
-       {101  , 3275},  
-       {101  , 3275}     
-
-
+       {0  ,4174},          
+       {2  ,4151},     
+       {4  ,4131},     
+       {6  ,4113},     
+       {8  ,4096},     
+       {10 ,4080},     
+       {11 ,4065},     
+       {13 ,4048},     
+       {15 ,4030},     
+       {17 ,4013},     
+       {19 ,3998},     
+       {21 ,3984},     
+       {23 ,3972},     
+       {25 ,3961},     
+       {27 ,3950},     
+       {29 ,3938},     
+       {30 ,3927},     
+       {32 ,3917},     
+       {34 ,3907},     
+       {36 ,3897},     
+       {38 ,3887},     
+       {40 ,3874},     
+       {42 ,3858},     
+       {44 ,3840},     
+       {46 ,3828},     
+       {48 ,3819},     
+       {50 ,3811},     
+       {51 ,3805},     
+       {53 ,3800},     
+       {55 ,3794},     
+       {57 ,3790},     
+       {59 ,3785},     
+       {61 ,3782},     
+       {63 ,3778},     
+       {65 ,3776},
+       {67 ,3775},     
+       {69 ,3773},     
+       {71 ,3770},     
+       {72 ,3767},     
+       {74 ,3763},     
+       {76 ,3757},     
+       {78 ,3748},     
+       {80 ,3740},     
+       {82 ,3729},     
+       {84 ,3713},     
+       {86 ,3695},     
+       {88 ,3687},     
+       {90 ,3684},     
+       {91 ,3681},     
+       {93 ,3677},     
+       {95 ,3662},     
+       {97 ,3594},     
+       {98 ,3481},
+       {99,3450},
+       {100,3420}
 };
       
         
 // T1 0C 
 BATTERY_PROFILE_STRUC battery_profile_t1[] =
 {
-       {0        ,4174},       
-       {2        ,4153},       
-       {3        ,4136},       
-       {5        ,4120},       
-       {7        ,4105},       
-       {8        ,4090},       
-       {10   ,4076},   
-       {12   ,4062},   
-       {14   ,4049},   
-       {15   ,4035},   
-       {17   ,4022},   
-       {19   ,4009},   
-       {20   ,3997},   
-       {22   ,3986},   
-       {24   ,3975},   
-       {25   ,3965},   
-       {27   ,3955},   
-       {29   ,3944},   
-       {30   ,3935},   
-       {32   ,3926},   
-       {34   ,3917},   
-       {35   ,3908},   
-       {37   ,3898},   
-       {39   ,3885},   
-       {41   ,3872},   
-       {42   ,3860},   
-       {44   ,3855},   
-       {46   ,3848},   
-       {47   ,3842},   
-       {49   ,3836},   
-       {51   ,3830},   
-       {52   ,3823},   
-       {54   ,3818},   
-       {56   ,3806},   
-       {57   ,3803},   
-       {59   ,3798},   
-       {61   ,3790},   
-       {62   ,3789},   
-       {64   ,3784},   
-       {66   ,3780},   
-       {68   ,3778},   
-       {69   ,3777},   
-       {71   ,3776},   
-       {73   ,3772},   
-       {74   ,3769},   
-       {76   ,3761},   
-       {78   ,3752},   
-       {79   ,3748},   
-       {81   ,3742},   
-       {83   ,3735},   
-       {84   ,3732},   
-       {86   ,3710},   
-       {88   ,3700},   
-       {90   ,3680},   
-       {91   ,3665},   
-       {93   ,3655},   
-       {95   ,3642},   
-       {96   ,3626},   
-       {98   ,3575},   
-       {99   ,3505},   
-       {100  ,3448},   
-       {101  ,3330},   
-       {101  , 3309},  
-       {101  , 3300},  
-       {101  , 3295},  
-       {101  , 3293},  
-       {101  , 3291},  
-       {101  , 3291},  
-       {101  , 3291},  
-       {101  , 3290},  
-       {101  , 3289},  
-       {101  , 3289},  
-       {101  , 3287},  
-       {101  , 3288},  
-       {101  , 3286},  
-       {101  , 3286},  
-       {101  , 3285},  
-       {101  , 3284},  
-       {101  , 3283},  
-       {101  , 3281},  
-       {101  , 3281},  
-       {101  , 3279},  
-       {101  , 3278},  
-       {101  , 3276},  
-       {101  , 3275},  
-       {101  , 3275}     
-
+       {0  ,4174},          
+       {2  ,4151},     
+       {4  ,4131},     
+       {6  ,4113},     
+       {8  ,4096},     
+       {10 ,4080},     
+       {11 ,4065},     
+       {13 ,4048},     
+       {15 ,4030},     
+       {17 ,4013},     
+       {19 ,3998},     
+       {21 ,3984},     
+       {23 ,3972},     
+       {25 ,3961},     
+       {27 ,3950},     
+       {29 ,3938},     
+       {30 ,3927},     
+       {32 ,3917},     
+       {34 ,3907},     
+       {36 ,3897},     
+       {38 ,3887},     
+       {40 ,3874},     
+       {42 ,3858},     
+       {44 ,3840},     
+       {46 ,3828},     
+       {48 ,3819},     
+       {50 ,3811},     
+       {51 ,3805},     
+       {53 ,3800},     
+       {55 ,3794},     
+       {57 ,3790},     
+       {59 ,3785},     
+       {61 ,3782},     
+       {63 ,3778},     
+       {65 ,3776},
+       {67 ,3775},     
+       {69 ,3773},     
+       {71 ,3770},     
+       {72 ,3767},     
+       {74 ,3763},     
+       {76 ,3757},     
+       {78 ,3748},     
+       {80 ,3740},     
+       {82 ,3729},     
+       {84 ,3713},     
+       {86 ,3695},     
+       {88 ,3687},     
+       {90 ,3684},     
+       {91 ,3681},     
+       {93 ,3677},     
+       {95 ,3662},     
+       {97 ,3594},     
+       {98 ,3481},
+       {99,3450},
+       {100,3420}
 
 };
            
@@ -330,185 +265,122 @@ BATTERY_PROFILE_STRUC battery_profile_t1[] =
 // T2 25C
 BATTERY_PROFILE_STRUC battery_profile_t2[] =
 {
-       {0        ,4174},       
-       {2        ,4153},       
-       {3        ,4136},       
-       {5        ,4120},       
-       {7        ,4105},       
-       {8        ,4090},       
-       {10   ,4076},   
-       {12   ,4062},   
-       {14   ,4049},   
-       {15   ,4035},   
-       {17   ,4022},   
-       {19   ,4009},   
-       {20   ,3997},   
-       {22   ,3986},   
-       {24   ,3975},   
-       {25   ,3965},   
-       {27   ,3955},   
-       {29   ,3944},   
-       {30   ,3935},   
-       {32   ,3926},   
-       {34   ,3917},   
-       {35   ,3908},   
-       {37   ,3898},   
-       {39   ,3885},   
-       {41   ,3872},   
-       {42   ,3860},   
-       {44   ,3855},   
-       {46   ,3848},   
-       {47   ,3842},   
-       {49   ,3836},   
-       {51   ,3830},   
-       {52   ,3823},   
-       {54   ,3818},   
-       {56   ,3806},   
-       {57   ,3803},   
-       {59   ,3798},   
-       {61   ,3790},   
-       {62   ,3789},   
-       {64   ,3784},   
-       {66   ,3780},   
-       {68   ,3778},   
-       {69   ,3777},   
-       {71   ,3776},   
-       {73   ,3772},   
-       {74   ,3769},   
-       {76   ,3761},   
-       {78   ,3752},   
-       {79   ,3748},   
-       {81   ,3742},   
-       {83   ,3735},   
-       {84   ,3732},   
-       {86   ,3710},   
-       {88   ,3700},   
-       {90   ,3680},   
-       {91   ,3665},   
-       {93   ,3655},   
-       {95   ,3642},   
-       {96   ,3626},   
-       {98   ,3575},   
-       {99   ,3505},   
-       {100  ,3448},   
-       {101  ,3330},   
-       {101  , 3309},  
-       {101  , 3300},  
-       {101  , 3295},  
-       {101  , 3293},  
-       {101  , 3291},  
-       {101  , 3291},  
-       {101  , 3291},  
-       {101  , 3290},  
-       {101  , 3289},  
-       {101  , 3289},  
-       {101  , 3287},  
-       {101  , 3288},  
-       {101  , 3286},  
-       {101  , 3286},  
-       {101  , 3285},  
-       {101  , 3284},  
-       {101  , 3283},  
-       {101  , 3281},  
-       {101  , 3281},  
-       {101  , 3279},  
-       {101  , 3278},  
-       {101  , 3276},  
-       {101  , 3275},  
-       {101  , 3275}     
+       {0  ,4174},          
+       {2  ,4151},     
+       {4  ,4131},     
+       {6  ,4113},     
+       {8  ,4096},     
+       {10 ,4080},     
+       {11 ,4065},     
+       {13 ,4048},     
+       {15 ,4030},     
+       {17 ,4013},     
+       {19 ,3998},     
+       {21 ,3984},     
+       {23 ,3972},     
+       {25 ,3961},     
+       {27 ,3950},     
+       {29 ,3938},     
+       {30 ,3927},     
+       {32 ,3917},     
+       {34 ,3907},     
+       {36 ,3897},     
+       {38 ,3887},     
+       {40 ,3874},     
+       {42 ,3858},     
+       {44 ,3840},     
+       {46 ,3828},     
+       {48 ,3819},     
+       {50 ,3811},     
+       {51 ,3805},     
+       {53 ,3800},     
+       {55 ,3794},     
+       {57 ,3790},     
+       {59 ,3785},     
+       {61 ,3782},     
+       {63 ,3778},     
+       {65 ,3776},
+       {67 ,3775},     
+       {69 ,3773},     
+       {71 ,3770},     
+       {72 ,3767},     
+       {74 ,3763},     
+       {76 ,3757},     
+       {78 ,3748},     
+       {80 ,3740},     
+       {82 ,3729},     
+       {84 ,3713},     
+       {86 ,3695},     
+       {88 ,3687},     
+       {90 ,3684},     
+       {91 ,3681},     
+       {93 ,3677},     
+       {95 ,3662},     
+       {97 ,3594},     
+       {98 ,3481},
+       {99,3450},
+       {100,3420}
 
 };     
 
 // T3 50C
 BATTERY_PROFILE_STRUC battery_profile_t3[] =
 {
-       {0        ,4174},       
-       {2        ,4153},       
-       {3        ,4136},       
-       {5        ,4120},       
-       {7        ,4105},       
-       {8        ,4090},       
-       {10   ,4076},   
-       {12   ,4062},   
-       {14   ,4049},   
-       {15   ,4035},   
-       {17   ,4022},   
-       {19   ,4009},   
-       {20   ,3997},   
-       {22   ,3986},   
-       {24   ,3975},   
-       {25   ,3965},   
-       {27   ,3955},   
-       {29   ,3944},   
-       {30   ,3935},   
-       {32   ,3926},   
-       {34   ,3917},   
-       {35   ,3908},   
-       {37   ,3898},   
-       {39   ,3885},   
-       {41   ,3872},   
-       {42   ,3860},   
-       {44   ,3855},   
-       {46   ,3848},   
-       {47   ,3842},   
-       {49   ,3836},   
-       {51   ,3830},   
-       {52   ,3823},   
-       {54   ,3818},   
-       {56   ,3806},   
-       {57   ,3803},   
-       {59   ,3798},   
-       {61   ,3790},   
-       {62   ,3789},   
-       {64   ,3784},   
-       {66   ,3780},   
-       {68   ,3778},   
-       {69   ,3777},   
-       {71   ,3776},   
-       {73   ,3772},   
-       {74   ,3769},   
-       {76   ,3761},   
-       {78   ,3752},   
-       {79   ,3748},   
-       {81   ,3742},   
-       {83   ,3735},   
-       {84   ,3732},   
-       {86   ,3710},   
-       {88   ,3700},   
-       {90   ,3680},   
-       {91   ,3665},   
-       {93   ,3655},   
-       {95   ,3642},   
-       {96   ,3626},   
-       {98   ,3575},   
-       {99   ,3505},   
-       {100  ,3448},   
-       {101  ,3330},   
-       {101  , 3309},  
-       {101  , 3300},  
-       {101  , 3295},  
-       {101  , 3293},  
-       {101  , 3291},  
-       {101  , 3291},  
-       {101  , 3291},  
-       {101  , 3290},  
-       {101  , 3289},  
-       {101  , 3289},  
-       {101  , 3287},  
-       {101  , 3288},  
-       {101  , 3286},  
-       {101  , 3286},  
-       {101  , 3285},  
-       {101  , 3284},  
-       {101  , 3283},  
-       {101  , 3281},  
-       {101  , 3281},  
-       {101  , 3279},  
-       {101  , 3278},  
-       {101  , 3276},  
-       {101  , 3275},  
-       {101  , 3275}     
-
+       {0  ,4174},          
+       {2  ,4151},     
+       {4  ,4131},     
+       {6  ,4113},     
+       {8  ,4096},     
+       {10 ,4080},     
+       {11 ,4065},     
+       {13 ,4048},     
+       {15 ,4030},     
+       {17 ,4013},     
+       {19 ,3998},     
+       {21 ,3984},     
+       {23 ,3972},     
+       {25 ,3961},     
+       {27 ,3950},     
+       {29 ,3938},     
+       {30 ,3927},     
+       {32 ,3917},     
+       {34 ,3907},     
+       {36 ,3897},     
+       {38 ,3887},     
+       {40 ,3874},     
+       {42 ,3858},     
+       {44 ,3840},     
+       {46 ,3828},     
+       {48 ,3819},     
+       {50 ,3811},     
+       {51 ,3805},     
+       {53 ,3800},     
+       {55 ,3794},     
+       {57 ,3790},     
+       {59 ,3785},     
+       {61 ,3782},     
+       {63 ,3778},     
+       {65 ,3776},
+       {67 ,3775},     
+       {69 ,3773},     
+       {71 ,3770},     
+       {72 ,3767},     
+       {74 ,3763},     
+       {76 ,3757},     
+       {78 ,3748},     
+       {80 ,3740},     
+       {82 ,3729},     
+       {84 ,3713},     
+       {86 ,3695},     
+       {88 ,3687},     
+       {90 ,3684},     
+       {91 ,3681},     
+       {93 ,3677},     
+       {95 ,3662},     
+       {97 ,3594},     
+       {98 ,3481},
+       {99,3450},
+       {100,3420}
 
 };           
 
@@ -610,373 +482,365 @@ BATTERY_PROFILE_STRUC battery_profile_temperature[] =
 // T0 -10C
 R_PROFILE_STRUC r_profile_t0[] =
 {
-    {120 , 4174},    
-    {120 , 4153},   
-    {120 , 4136},   
-    {120 , 4120},   
-    {125 , 4105},   
-    {128 , 4090},   
-    {130 , 4076},   
-    {135 , 4062},   
-    {135 , 4049},   
-    {135 , 4035},   
-    {135 , 4022},   
-    {135 , 4009},   
-    {135 , 3997},   
-    {135 , 3986},   
-    {135 , 3975},   
-    {135 , 3965},   
-    {135 , 3955},   
-    {135 , 3944},   
-    {135 , 3935},   
-    {135 , 3926},   
-    {135 , 3917},   
-    {135 , 3908},   
-    {135 , 3899},   
-    {135 , 3887},   
-    {133 , 3869},   
-    {133 , 3852},   
-    {132 , 3839},   
-    {132 , 3830},   
-    {132 , 3823},   
-    {132 , 3817},   
-    {132 , 3812},   
-    {132 , 3806},   
-    {132 , 3801},   
-    {132 , 3797},   
-    {132 , 3793},   
-    {132 , 3789},   
-    {132 , 3786},   
-    {132 , 3782},   
-    {132 , 3778},   
-    {132 , 3777},   
-    {132 , 3774},   
-    {132 , 3772},   
-    {132 , 3770},   
-    {132 , 3767},   
-    {128 , 3763},   
-    {128 , 3759},   
-    {125 , 3752},   
-    {125 , 3746},   
-    {125 , 3739},   
-    {125 , 3728},   
-    {125 , 3714},   
-    {125 , 3700},   
-    {125 , 3687},   
-    {125 , 3684},   
-    {125 , 3682},   
-    {125 , 3680},   
-    {120 , 3676},   
-    {120 , 3658},   
-    {120 , 3580},   
-    {120 , 3448},   
-    {120 , 3330},   
-    {122 , 3309},   
-    {118 , 3300},   
-    {122 , 3295},   
-    {120 , 3293},   
-    {117 , 3291},   
-    {123 , 3291},   
-    {125 , 3291},   
-    {127 , 3290},   
-    {125 , 3289},   
-    {122 , 3289},   
-    {123 , 3287},   
-    {122 , 3288},   
-    {123 , 3286},   
-    {122 , 3286},   
-    {125 , 3285},   
-    {125 , 3284},   
-    {127 , 3283},   
-    {127 , 3281},   
-    {125 , 3281},   
-    {127 , 3279},   
-    {128 , 3278},   
-    {127 , 3276},   
-    {128 , 3275},   
-    {127 , 3275}    
-
-
+       {153,4174},
+       {153,4151},
+       {155,4131},
+       {158,4113},
+       {160,4096},
+       {162,4080},
+       {167,4065},
+       {170,4048},
+       {172,4030},
+       {173,4013},
+       {177,3998},
+       {177,3984},
+       {182,3972},
+       {185,3961},
+       {187,3950},
+       {188,3938},
+       {190,3927},
+       {193,3917},
+       {195,3907},
+       {198,3897},
+       {200,3887},
+       {195,3874},
+       {185,3858},
+       {172,3840},
+       {167,3828},
+       {165,3819},
+       {163,3811},
+       {167,3805},
+       {168,3800},
+       {170,3794},
+       {173,3790},
+       {173,3785},
+       {177,3782},
+       {178,3778},
+       {182,3776},
+       {187,3775},
+       {190,3773},
+       {192,3770},
+       {193,3767},
+       {195,3763},
+       {193,3757},
+       {192,3748},
+       {195,3740},
+       {197,3729},
+       {195,3713},
+       {193,3695},
+       {193,3687},
+       {203,3684},
+       {220,3681},
+       {240,3677},
+       {258,3662},
+       {255,3594},
+       {293,3481},
+       {305,3382},
+       {255,3353},
+       {233,3338},
+       {215,3329},
+       {210,3323},
+       {202,3318},
+       {198,3316},
+       {193,3314},
+       {188,3313},
+       {188,3311},
+       {187,3312},
+       {185,3310},
+       {187,3310},
+       {187,3309},
+       {185,3307},
+       {182,3308},
+       {183,3307},
+       {182,3307},
+       {183,3307},
+       {185,3307},
+       {187,3306},
+       {185,3306},
+       {185,3306},
+       {183,3305},
+       {188,3304},
+       {187,3303},
+       {188,3302},
+       {185,3301},
+       {185,3301},
+       {187,3301},
+       {185,3300},
+       {187,3300},
+       {167,3300}
 };
 
 // T1 0C
 R_PROFILE_STRUC r_profile_t1[] =
 {
-    {120 , 4174},    
-    {120 , 4153},   
-    {120 , 4136},   
-    {120 , 4120},   
-    {125 , 4105},   
-    {128 , 4090},   
-    {130 , 4076},   
-    {135 , 4062},   
-    {135 , 4049},   
-    {135 , 4035},   
-    {135 , 4022},   
-    {135 , 4009},   
-    {135 , 3997},   
-    {135 , 3986},   
-    {135 , 3975},   
-    {135 , 3965},   
-    {135 , 3955},   
-    {135 , 3944},   
-    {135 , 3935},   
-    {135 , 3926},   
-    {135 , 3917},   
-    {135 , 3908},   
-    {135 , 3899},   
-    {135 , 3887},   
-    {133 , 3869},   
-    {133 , 3852},   
-    {132 , 3839},   
-    {132 , 3830},   
-    {132 , 3823},   
-    {132 , 3817},   
-    {132 , 3812},   
-    {132 , 3806},   
-    {132 , 3801},   
-    {132 , 3797},   
-    {132 , 3793},   
-    {132 , 3789},   
-    {132 , 3786},   
-    {132 , 3782},   
-    {132 , 3778},   
-    {132 , 3777},   
-    {132 , 3774},   
-    {132 , 3772},   
-    {132 , 3770},   
-    {132 , 3767},   
-    {128 , 3763},   
-    {128 , 3759},   
-    {125 , 3752},   
-    {125 , 3746},   
-    {125 , 3739},   
-    {125 , 3728},   
-    {125 , 3714},   
-    {125 , 3700},   
-    {125 , 3687},   
-    {125 , 3684},   
-    {125 , 3682},   
-    {125 , 3680},   
-    {120 , 3676},   
-    {120 , 3658},   
-    {120 , 3580},   
-    {120 , 3448},   
-    {120 , 3330},   
-    {122 , 3309},   
-    {118 , 3300},   
-    {122 , 3295},   
-    {120 , 3293},   
-    {117 , 3291},   
-    {123 , 3291},   
-    {125 , 3291},   
-    {127 , 3290},   
-    {125 , 3289},   
-    {122 , 3289},   
-    {123 , 3287},   
-    {122 , 3288},   
-    {123 , 3286},   
-    {122 , 3286},   
-    {125 , 3285},   
-    {125 , 3284},   
-    {127 , 3283},   
-    {127 , 3281},   
-    {125 , 3281},   
-    {127 , 3279},   
-    {128 , 3278},   
-    {127 , 3276},   
-    {128 , 3275},   
-    {127 , 3275}    
-
-
-
+       {153,4174},
+       {153,4151},
+       {155,4131},
+       {158,4113},
+       {160,4096},
+       {162,4080},
+       {167,4065},
+       {170,4048},
+       {172,4030},
+       {173,4013},
+       {177,3998},
+       {177,3984},
+       {182,3972},
+       {185,3961},
+       {187,3950},
+       {188,3938},
+       {190,3927},
+       {193,3917},
+       {195,3907},
+       {198,3897},
+       {200,3887},
+       {195,3874},
+       {185,3858},
+       {172,3840},
+       {167,3828},
+       {165,3819},
+       {163,3811},
+       {167,3805},
+       {168,3800},
+       {170,3794},
+       {173,3790},
+       {173,3785},
+       {177,3782},
+       {178,3778},
+       {182,3776},
+       {187,3775},
+       {190,3773},
+       {192,3770},
+       {193,3767},
+       {195,3763},
+       {193,3757},
+       {192,3748},
+       {195,3740},
+       {197,3729},
+       {195,3713},
+       {193,3695},
+       {193,3687},
+       {203,3684},
+       {220,3681},
+       {240,3677},
+       {258,3662},
+       {255,3594},
+       {293,3481},
+       {305,3382},
+       {255,3353},
+       {233,3338},
+       {215,3329},
+       {210,3323},
+       {202,3318},
+       {198,3316},
+       {193,3314},
+       {188,3313},
+       {188,3311},
+       {187,3312},
+       {185,3310},
+       {187,3310},
+       {187,3309},
+       {185,3307},
+       {182,3308},
+       {183,3307},
+       {182,3307},
+       {183,3307},
+       {185,3307},
+       {187,3306},
+       {185,3306},
+       {185,3306},
+       {183,3305},
+       {188,3304},
+       {187,3303},
+       {188,3302},
+       {185,3301},
+       {185,3301},
+       {187,3301},
+       {185,3300},
+       {187,3300},
+       {167,3300}
 };    
 
 // T2 25C
 R_PROFILE_STRUC r_profile_t2[] =
 {
-    {120 , 4174},    
-    {120 , 4153},   
-    {120 , 4136},   
-    {120 , 4120},   
-    {125 , 4105},   
-    {128 , 4090},   
-    {130 , 4076},   
-    {135 , 4062},   
-    {135 , 4049},   
-    {135 , 4035},   
-    {135 , 4022},   
-    {135 , 4009},   
-    {135 , 3997},   
-    {135 , 3986},   
-    {135 , 3975},   
-    {135 , 3965},   
-    {135 , 3955},   
-    {135 , 3944},   
-    {135 , 3935},   
-    {135 , 3926},   
-    {135 , 3917},   
-    {135 , 3908},   
-    {135 , 3899},   
-    {135 , 3887},   
-    {133 , 3869},   
-    {133 , 3852},   
-    {132 , 3839},   
-    {132 , 3830},   
-    {132 , 3823},   
-    {132 , 3817},   
-    {132 , 3812},   
-    {132 , 3806},   
-    {132 , 3801},   
-    {132 , 3797},   
-    {132 , 3793},   
-    {132 , 3789},   
-    {132 , 3786},   
-    {132 , 3782},   
-    {132 , 3778},   
-    {132 , 3777},   
-    {132 , 3774},   
-    {132 , 3772},   
-    {132 , 3770},   
-    {132 , 3767},   
-    {128 , 3763},   
-    {128 , 3759},   
-    {125 , 3752},   
-    {125 , 3746},   
-    {125 , 3739},   
-    {125 , 3728},   
-    {125 , 3714},   
-    {125 , 3700},   
-    {125 , 3687},   
-    {125 , 3684},   
-    {125 , 3682},   
-    {125 , 3680},   
-    {120 , 3676},   
-    {120 , 3658},   
-    {120 , 3580},   
-    {120 , 3448},   
-    {120 , 3330},   
-    {122 , 3309},   
-    {118 , 3300},   
-    {122 , 3295},   
-    {120 , 3293},   
-    {117 , 3291},   
-    {123 , 3291},   
-    {125 , 3291},   
-    {127 , 3290},   
-    {125 , 3289},   
-    {122 , 3289},   
-    {123 , 3287},   
-    {122 , 3288},   
-    {123 , 3286},   
-    {122 , 3286},   
-    {125 , 3285},   
-    {125 , 3284},   
-    {127 , 3283},   
-    {127 , 3281},   
-    {125 , 3281},   
-    {127 , 3279},   
-    {128 , 3278},   
-    {127 , 3276},   
-    {128 , 3275},   
-    {127 , 3275}    
-
-
-
+       {153,4174},
+       {153,4151},
+       {155,4131},
+       {158,4113},
+       {160,4096},
+       {162,4080},
+       {167,4065},
+       {170,4048},
+       {172,4030},
+       {173,4013},
+       {177,3998},
+       {177,3984},
+       {182,3972},
+       {185,3961},
+       {187,3950},
+       {188,3938},
+       {190,3927},
+       {193,3917},
+       {195,3907},
+       {198,3897},
+       {200,3887},
+       {195,3874},
+       {185,3858},
+       {172,3840},
+       {167,3828},
+       {165,3819},
+       {163,3811},
+       {167,3805},
+       {168,3800},
+       {170,3794},
+       {173,3790},
+       {173,3785},
+       {177,3782},
+       {178,3778},
+       {182,3776},
+       {187,3775},
+       {190,3773},
+       {192,3770},
+       {193,3767},
+       {195,3763},
+       {193,3757},
+       {192,3748},
+       {195,3740},
+       {197,3729},
+       {195,3713},
+       {193,3695},
+       {193,3687},
+       {203,3684},
+       {220,3681},
+       {240,3677},
+       {258,3662},
+       {255,3594},
+       {293,3481},
+       {305,3382},
+       {255,3353},
+       {233,3338},
+       {215,3329},
+       {210,3323},
+       {202,3318},
+       {198,3316},
+       {193,3314},
+       {188,3313},
+       {188,3311},
+       {187,3312},
+       {185,3310},
+       {187,3310},
+       {187,3309},
+       {185,3307},
+       {182,3308},
+       {183,3307},
+       {182,3307},
+       {183,3307},
+       {185,3307},
+       {187,3306},
+       {185,3306},
+       {185,3306},
+       {183,3305},
+       {188,3304},
+       {187,3303},
+       {188,3302},
+       {185,3301},
+       {185,3301},
+       {187,3301},
+       {185,3300},
+       {187,3300},
+       {167,3300}
 };
 
 // T3 50C
 R_PROFILE_STRUC r_profile_t3[] =
 {
-    {120 , 4174},    
-    {120 , 4153},   
-    {120 , 4136},   
-    {120 , 4120},   
-    {125 , 4105},   
-    {128 , 4090},   
-    {130 , 4076},   
-    {135 , 4062},   
-    {135 , 4049},   
-    {135 , 4035},   
-    {135 , 4022},   
-    {135 , 4009},   
-    {135 , 3997},   
-    {135 , 3986},   
-    {135 , 3975},   
-    {135 , 3965},   
-    {135 , 3955},   
-    {135 , 3944},   
-    {135 , 3935},   
-    {135 , 3926},   
-    {135 , 3917},   
-    {135 , 3908},   
-    {135 , 3899},   
-    {135 , 3887},   
-    {133 , 3869},   
-    {133 , 3852},   
-    {132 , 3839},   
-    {132 , 3830},   
-    {132 , 3823},   
-    {132 , 3817},   
-    {132 , 3812},   
-    {132 , 3806},   
-    {132 , 3801},   
-    {132 , 3797},   
-    {132 , 3793},   
-    {132 , 3789},   
-    {132 , 3786},   
-    {132 , 3782},   
-    {132 , 3778},   
-    {132 , 3777},   
-    {132 , 3774},   
-    {132 , 3772},   
-    {132 , 3770},   
-    {132 , 3767},   
-    {128 , 3763},   
-    {128 , 3759},   
-    {125 , 3752},   
-    {125 , 3746},   
-    {125 , 3739},   
-    {125 , 3728},   
-    {125 , 3714},   
-    {125 , 3700},   
-    {125 , 3687},   
-    {125 , 3684},   
-    {125 , 3682},   
-    {125 , 3680},   
-    {120 , 3676},   
-    {120 , 3658},   
-    {120 , 3580},   
-    {120 , 3448},   
-    {120 , 3330},   
-    {122 , 3309},   
-    {118 , 3300},   
-    {122 , 3295},   
-    {120 , 3293},   
-    {117 , 3291},   
-    {123 , 3291},   
-    {125 , 3291},   
-    {127 , 3290},   
-    {125 , 3289},   
-    {122 , 3289},   
-    {123 , 3287},   
-    {122 , 3288},   
-    {123 , 3286},   
-    {122 , 3286},   
-    {125 , 3285},   
-    {125 , 3284},   
-    {127 , 3283},   
-    {127 , 3281},   
-    {125 , 3281},   
-    {127 , 3279},   
-    {128 , 3278},   
-    {127 , 3276},   
-    {128 , 3275},   
-    {127 , 3275}    
-
-
-
-
+       {153,4174},
+       {153,4151},
+       {155,4131},
+       {158,4113},
+       {160,4096},
+       {162,4080},
+       {167,4065},
+       {170,4048},
+       {172,4030},
+       {173,4013},
+       {177,3998},
+       {177,3984},
+       {182,3972},
+       {185,3961},
+       {187,3950},
+       {188,3938},
+       {190,3927},
+       {193,3917},
+       {195,3907},
+       {198,3897},
+       {200,3887},
+       {195,3874},
+       {185,3858},
+       {172,3840},
+       {167,3828},
+       {165,3819},
+       {163,3811},
+       {167,3805},
+       {168,3800},
+       {170,3794},
+       {173,3790},
+       {173,3785},
+       {177,3782},
+       {178,3778},
+       {182,3776},
+       {187,3775},
+       {190,3773},
+       {192,3770},
+       {193,3767},
+       {195,3763},
+       {193,3757},
+       {192,3748},
+       {195,3740},
+       {197,3729},
+       {195,3713},
+       {193,3695},
+       {193,3687},
+       {203,3684},
+       {220,3681},
+       {240,3677},
+       {258,3662},
+       {255,3594},
+       {293,3481},
+       {305,3382},
+       {255,3353},
+       {233,3338},
+       {215,3329},
+       {210,3323},
+       {202,3318},
+       {198,3316},
+       {193,3314},
+       {188,3313},
+       {188,3311},
+       {187,3312},
+       {185,3310},
+       {187,3310},
+       {187,3309},
+       {185,3307},
+       {182,3308},
+       {183,3307},
+       {182,3307},
+       {183,3307},
+       {185,3307},
+       {187,3306},
+       {185,3306},
+       {185,3306},
+       {183,3305},
+       {188,3304},
+       {187,3303},
+       {188,3302},
+       {185,3301},
+       {185,3301},
+       {187,3301},
+       {185,3300},
+       {187,3300},
+       {167,3300}
 };
 
 // r-table profile for actual temperature. The size should be the same as T1, T2 and T3
index e409bb911a649efd12e24e15adef9a0743e20821..1b4b1f01eb00be8418e6f76c61d9e86ec784ce83 100644 (file)
 #define MIN_CHARGE_TEMPERATURE_PLUS_X_DEGREE   4  //6 Fixed to 2 degree accoding to TCL standard
 #define MAX_LIMIT_CHARGE_TEMPERATURE    45
 #define MIN_LIMIT_CHARGE_TEMPERATURE    43
-/* [PLATFORM]-ADD-BEGIN by TCTSZ huichen@tcl.com, 05/21/2015,  BATTERY Notify PR-1007717*/
-#define MAX_RAISING_CHARGE_TEMPERATURE    58
-#define MIN_DROPPING_CHARGE_TEMPERATURE    -18
-/* [PLATFORM]-ADD-END by TCTSZ huichen@tcl.com*/
 #define ERR_CHARGE_TEMPERATURE  0xFF
 
 /* Linear Charging Threshold */
 #define BAT_LOW_TEMP_PROTECT_ENABLE         // stop charging if temp < MIN_CHARGE_TEMPERATURE
 /* [PLATFORM]-Add-END by TCTSZ.leo.guo */
 #define V_CHARGER_ENABLE 0                             // 1:ON , 0:OFF 
-/* [PLATFORM]-MOD-BEGIN by TCTSZ huichen@tcl.com, 05/18/2015,  modify OVP function FR-1005346*/
-//#define V_CHARGER_MAX 6500                           // 6.5 V
-#define V_CHARGER_MAX 6900                             // 6.9 V
-/* [PLATFORM]-MOD-END by TCTSZ huichen@tcl.com, 05/18/2015*/
+#define V_CHARGER_MAX 6500                             // 6.5 V
 #define V_CHARGER_MIN 4400                             // 4.4 V
 
 /* Tracking TIME */
index 326ad7774309207a744d41d0aa512252d8cd497e..8c8d197d9d31a0d4ff2572bfa9b7da98c2c153f2 100644 (file)
@@ -115,23 +115,23 @@ static struct early_suspend mt_cpufreq_early_suspend_handler =
 #define DVFS_F4     ( 598000)   // KHz
 
 #if defined(HQA_LV_1_09V)
-    #define DVFS_V0     (1200)  // mV
+    #define DVFS_V0     (1250)  // mV
     #define DVFS_V1     (1150)  // mV
     #define DVFS_V2     (1090)  // mV
     #define DVFS_V3     (1090)  // mV
 #elif defined(HQA_NV_1_15V)
     #define DVFS_V0     (1260)  // mV
-    #define DVFS_V1     (1200)  // mV
+    #define DVFS_V1     (1250)  // mV
     #define DVFS_V2     (1150)  // mV
     #define DVFS_V3     (1050)  // mV /*Not used */
 #elif defined(HQA_HV_1_21V)
     #define DVFS_V0     (1320)  // mV
-    #define DVFS_V1     (1210)  // mV
+    #define DVFS_V1     (1250)  // mV
     #define DVFS_V2     (1150)  // mV /*Not used */
     #define DVFS_V3     (1050)  // mV /*Not used */
 #else /* Normal case */
     #define DVFS_V0     (1300)  // mV
-    #define DVFS_V1     (1200)  // mV
+    #define DVFS_V1     (1250)  // mV
     #ifdef CPUFREQ_SDIO_TRANSFER
     #define DVFS_V2_0   (1185)  // mV
     #endif
@@ -1207,6 +1207,7 @@ static void mt_cpufreq_set(unsigned int freq_old, unsigned int freq_new, unsigne
         #ifdef MT_CPUFREQ_FHCTL
         if(((freq_new > FHCTL_CHANGE_FREQ) && (freq_old > FHCTL_CHANGE_FREQ)) || ((freq_new < FHCTL_CHANGE_FREQ) && (freq_old < FHCTL_CHANGE_FREQ)))
         {
+            dprintk("Before === FHCTL: freq_new = %d < freq_old = %d ===\n", freq_new, freq_old);            
             mt_dfs_armpll(freq_old, freq_new);
             dprintk("=== FHCTL: freq_new = %d > freq_old = %d ===\n", freq_new, freq_old);
 
@@ -1236,6 +1237,7 @@ static void mt_cpufreq_set(unsigned int freq_old, unsigned int freq_new, unsigne
         #ifdef MT_CPUFREQ_FHCTL
         if(((freq_new > FHCTL_CHANGE_FREQ) && (freq_old > FHCTL_CHANGE_FREQ)) || ((freq_new < FHCTL_CHANGE_FREQ) && (freq_old < FHCTL_CHANGE_FREQ)))
         {
+            dprintk("Before === FHCTL: freq_new = %d < freq_old = %d ===\n", freq_new, freq_old);
             mt_dfs_armpll(freq_old, freq_new);
             dprintk("=== FHCTL: freq_new = %d < freq_old = %d ===\n", freq_new, freq_old);
 
@@ -1547,7 +1549,13 @@ static int mt_cpufreq_target(struct cpufreq_policy *policy, unsigned int target_
     /******************************
     * set to the target freeuency
     *******************************/
-    mt_cpufreq_set(freqs.old, freqs.new, next.cpufreq_volt);
+    /* Get current frequency */
+    freqs.old = g_cur_freq;
+    
+    if (freqs.old != freqs.new)
+        mt_cpufreq_set(freqs.old, freqs.new, next.cpufreq_volt);
+    else
+        dprintk("CPU frequency from %d MHz to %d MHz (skipped) due to same frequency in critical seciton check\n", freqs.old / 1000, freqs.new / 1000);
 
     spin_unlock_irqrestore(&mt_cpufreq_lock, flags);
 
index 4fbd2b3decd48520b330c234229d92f68097b9d7..76b0b8838021f7e94f23eda61b9976325fefca98 100644 (file)
@@ -29,7 +29,7 @@
 #include <mach/dfo_boot_default.h>
 #include <linux/aee.h>
 #include <linux/mrdump.h>
-#ifdef CONFIG_MTK_MTD_NAND
+#if 0//#ifdef CONFIG_MTK_MTD_NAND
 #include <mach/nand_device_define.h>
 #include <mach/mt_partitioninfo.h>
 #endif
@@ -44,7 +44,7 @@ extern void adjust_kernel_cmd_line_setting_for_console(char*, char*);
 unsigned int mtk_get_max_DRAM_size(void);
 resource_size_t get_actual_DRAM_size(void);
 
-#ifdef CONFIG_MTK_MTD_NAND
+#if 0//#ifdef CONFIG_MTK_MTD_NAND
 struct tag_pt_info otp_info;
 struct tag_pt_info bmt_info;
 unsigned int flash_number;
@@ -1170,7 +1170,7 @@ static int __init parse_tag_devinfo_data_fixup(const struct tag *tags)
        return 0;
 }
 
-#ifdef CONFIG_MTK_MTD_NAND
+#if 0//#ifdef CONFIG_MTK_MTD_NAND
 int __init parse_tag_partition_fixup(const struct tag *tags)
 {
        
@@ -1278,7 +1278,7 @@ void mt_fixup(struct tag *tags, char **cmdline, struct meminfo *mi)
           g_meta_com_type = tags->u.meta_com.meta_com_type;
           g_meta_com_id = tags->u.meta_com.meta_com_id;
         } //FIXME_8127
-#ifdef CONFIG_MTK_MTD_NAND
+#if 0//#ifdef CONFIG_MTK_MTD_NAND
         else if(tags->hdr.tag == ATAG_OTP_INFO)
         {
             parse_tag_partition_fixup(tags);
index cfe0b938344c5403e271bd0f73105fdf5112db65..5ef80601aeed59159e3baaa04e7ccd925f6dd791 100644 (file)
 #define LOW_POWER_WAKEUP_PERIOD                300             //5 * 60 = 5 min
 #define CLOSE_POWEROFF_WAKEUP_PERIOD   30      //30 s
 
-#define MAX_SUSPEND_CURRENT 420 // 42 mA
-#define MIN_SUSPEND_CURRENT 30  // 3 mA
-#define DEFAUL_SUSPEND_CURRENT 120 //12mA
-#define SUSPEND_CURRENT_SETP 30 //3mA
-#define SLEEP_AFTER_FG_DIFF 3   // diff about 3%
-#define UI_REDUCE_CURRENT 180 //18mA
-#define SLEEP_REDUCE_CURRENT 60 //6mA
-
 #endif //#ifndef _CUST_BATTERY_METER_H
index 3bfdb2473ef76007d50dc14d6a530611fb6e899f..ca1a98df01cc5e698552c3258ce429fda91000b6 100644 (file)
@@ -14,9 +14,6 @@
 #define MIN_CHARGE_TEMPERATURE_PLUS_X_DEGREE   6
 #define ERR_CHARGE_TEMPERATURE  0xFF
 
-#define MAX_RAISING_CHARGE_TEMPERATURE    58
-#define MIN_DROPPING_CHARGE_TEMPERATURE    -18
-
 /* Linear Charging Threshold */
 #define V_PRE2CC_THRES                 3400    //mV
 #define V_CC2TOPOFF_THRES              4050
index a46116bc37583f6f834248e6ab154537bfb06d5b..5da4200c63c4dbdf3b42e151a76e48390b9a81f2 100644 (file)
@@ -82,116 +82,231 @@ u32 pinSet[2][8] = {
     }
 
     //power ON
-  if (On) {
-               
+       if (On) {
+
                PK_DBG("kdCISModulePowerOn -on:currSensorName=%s;\n",currSensorName);
                PK_DBG("kdCISModulePowerOn -on:pinSetIdx=%d\n",pinSetIdx);
-   
-   if (currSensorName && (0 == strcmp(SENSOR_DRVNAME_OV5670_MIPI_RAW,currSensorName))){
-               
-                 if(TRUE != hwPowerOn(CAMERA_POWER_VCAM_A, VOL_2800,mode_name))
-        {
-            PK_DBG("[CAMERA SENSOR] Fail to enable analog power\n");
-        }
-
-                   mdelay(10);
-                   
-        if(TRUE != hwPowerOn(CAMERA_POWER_VCAM_D, VOL_1800,mode_name))
-        {
-           PK_DBG("[CAMERA SENSOR] Fail to enable digital power\n");
-        }
-                   mdelay(10);
-                   
-        if(TRUE != hwPowerOn(CAMERA_POWER_VCAM_D2, VOL_1800,mode_name))
-        {
-           PK_DBG("[CAMERA SENSOR] Fail to enable digital power\n");
-        }
-                   mdelay(10);
-                   
-        
-                       PK_DBG("SENSOR_DRVNAME_OV5670_MIPI_RAW power!! \n");
-                       if(mt_set_gpio_mode(pinSet[pinSetIdx][IDX_PS_CMRST],pinSet[pinSetIdx][IDX_PS_CMRST+IDX_PS_MODE])){PK_DBG("[CAMERA SENSOR] set gpio mode failed!! \n");}
-                       if(mt_set_gpio_dir(pinSet[pinSetIdx][IDX_PS_CMRST],GPIO_DIR_OUT)){PK_DBG("[CAMERA SENSOR] set gpio dir failed!! \n");}
-                       if(mt_set_gpio_out(pinSet[pinSetIdx][IDX_PS_CMRST],GPIO_OUT_ZERO)){PK_DBG("[CAMERA SENSOR] set gpio failed!! \n");}
-                       mdelay(10);
-                       if(mt_set_gpio_out(pinSet[pinSetIdx][IDX_PS_CMRST],GPIO_OUT_ONE)){PK_DBG("[CAMERA SENSOR] set gpio failed!! \n");}
-                       mdelay(1);
-               
-                       //PDN pin
-                       if(mt_set_gpio_mode(pinSet[pinSetIdx][IDX_PS_CMPDN],pinSet[pinSetIdx][IDX_PS_CMPDN+IDX_PS_MODE])){PK_DBG("[CAMERA LENS] set gpio mode failed!! \n");}
-                       if(mt_set_gpio_dir(pinSet[pinSetIdx][IDX_PS_CMPDN],GPIO_DIR_OUT)){PK_DBG("[CAMERA LENS] set gpio dir failed!! \n");}
-                       if(mt_set_gpio_out(pinSet[pinSetIdx][IDX_PS_CMPDN],GPIO_OUT_ONE)){PK_DBG("[CAMERA LENS] set gpio failed!! \n");}
-                }else if (currSensorName && (0 == strcmp(SENSOR_DRVNAME_OV2680_RAW ,currSensorName))) {
-                       
-            if(TRUE != hwPowerOn(CAMERA_POWER_VCAM_D2, VOL_1800, mode_name))
-            {
-                PK_DBG("[CAMERA SENSOR] Fail to enable IO power\n");
-                goto _kdCISModulePowerOn_exit_;
-            }
-            {
-                //PDN pin
-                if(mt_set_gpio_mode(pinSet[pinSetIdx][IDX_PS_CMPDN], pinSet[pinSetIdx][IDX_PS_CMPDN+IDX_PS_MODE])){PK_DBG("[CAMERA LENS] set gpio mode failed!! \n");}
-                if(mt_set_gpio_dir(pinSet[pinSetIdx][IDX_PS_CMPDN], GPIO_DIR_OUT)){PK_DBG("[CAMERA LENS] set gpio dir failed!! \n");}
-                if(mt_set_gpio_out(pinSet[pinSetIdx][IDX_PS_CMPDN], pinSet[pinSetIdx][IDX_PS_CMPDN+IDX_PS_OFF])){PK_DBG("[CAMERA LENS] set gpio failed!! \n");}
-                                       mdelay(10);
-                                       if(mt_set_gpio_out(pinSet[pinSetIdx][IDX_PS_CMPDN], pinSet[pinSetIdx][IDX_PS_CMPDN+IDX_PS_ON])){PK_DBG("[CAMERA LENS] set gpio failed!! \n");}
-                                       mdelay(5);
-            
-                //RST pin
-                if(mt_set_gpio_mode(pinSet[pinSetIdx][IDX_PS_CMRST], pinSet[pinSetIdx][IDX_PS_CMRST+IDX_PS_MODE])){PK_DBG("[CAMERA SENSOR] set gpio mode failed!! \n");}
-                if(mt_set_gpio_dir(pinSet[pinSetIdx][IDX_PS_CMRST], GPIO_DIR_OUT)){PK_DBG("[CAMERA SENSOR] set gpio dir failed!! \n");}
-                if(mt_set_gpio_out(pinSet[pinSetIdx][IDX_PS_CMRST], pinSet[pinSetIdx][IDX_PS_CMRST+IDX_PS_OFF])){PK_DBG("[CAMERA SENSOR] set gpio failed!! \n");}
-                                       mdelay(10);
-                                       if(mt_set_gpio_out(pinSet[pinSetIdx][IDX_PS_CMRST], pinSet[pinSetIdx][IDX_PS_CMRST+IDX_PS_ON])){PK_DBG("[CAMERA SENSOR] set gpio failed!! \n");}
-                                       mdelay(5);
-            }
-            
-            msleep(20);
-            
-            if(TRUE != hwPowerOn(CAMERA_POWER_VCAM_A, VOL_2800, mode_name))
-            {
-                PK_DBG("[CAMERA SENSOR] Fail to enable analog power\n");
-                goto _kdCISModulePowerOn_exit_;
-            }
-            
-            //if(TRUE != hwPowerOn(PMIC_APP_MAIN_CAMERA_POWER_D, VOL_1500,mode_name))
-           // {
-           //      PK_DBG("[CAMERA SENSOR] Fail to enable digital power\n");
-           //      goto _kdCISModulePowerOn_exit_;
-           // } 
-            
-            
-            // wait power to be stable 
-            mdelay(25);
-
-     }
-  }else {//power OFF
-
-        //PK_DBG("[OFF]sensorIdx:%d \n",SensorIdx);
-        if (GPIO_CAMERA_INVALID != pinSet[pinSetIdx][IDX_PS_CMRST]) {
-            if(mt_set_gpio_mode(pinSet[pinSetIdx][IDX_PS_CMRST],pinSet[pinSetIdx][IDX_PS_CMRST+IDX_PS_MODE])){PK_DBG("[CAMERA SENSOR] set gpio mode failed!! \n");}
-            if(mt_set_gpio_mode(pinSet[pinSetIdx][IDX_PS_CMPDN],pinSet[pinSetIdx][IDX_PS_CMPDN+IDX_PS_MODE])){PK_DBG("[CAMERA LENS] set gpio mode failed!! \n");}
-            if(mt_set_gpio_dir(pinSet[pinSetIdx][IDX_PS_CMRST],GPIO_DIR_OUT)){PK_DBG("[CAMERA SENSOR] set gpio dir failed!! \n");}
-            if(mt_set_gpio_dir(pinSet[pinSetIdx][IDX_PS_CMPDN],GPIO_DIR_OUT)){PK_DBG("[CAMERA LENS] set gpio dir failed!! \n");}
-            if(mt_set_gpio_out(pinSet[pinSetIdx][IDX_PS_CMRST],pinSet[pinSetIdx][IDX_PS_CMRST+IDX_PS_OFF])){PK_DBG("[CAMERA SENSOR] set gpio failed!! \n");} //low == reset sensor
-           if(mt_set_gpio_out(pinSet[pinSetIdx][IDX_PS_CMPDN],pinSet[pinSetIdx][IDX_PS_CMPDN+IDX_PS_OFF])){PK_DBG("[CAMERA LENS] set gpio failed!! \n");} //high == power down lens module
-        }
-
-       if(TRUE != hwPowerDown(CAMERA_POWER_VCAM_A,mode_name)) {
-            PK_DBG("[CAMERA SENSOR] Fail to OFF a power\n");
-        }
-        if(TRUE != hwPowerDown(CAMERA_POWER_VCAM_A2,mode_name)){
-            PK_DBG("[CAMERA SENSOR] Fail to OFF a2 power\n");
-        }
-        if(TRUE != hwPowerDown(CAMERA_POWER_VCAM_D, mode_name)) {
-            PK_DBG("[CAMERA SENSOR] Fail to OFF d digital power\n");
-        }
-        if(TRUE != hwPowerDown(CAMERA_POWER_VCAM_D2,mode_name))
-        {
-            PK_DBG("[CAMERA SENSOR] Fail to OFF d2 digital power\n");
-        }
-    }//
-    
+
+               if (currSensorName && (0 == strcmp(SENSOR_DRVNAME_OV5670_MIPI_RAW,currSensorName)||0 == strcmp(SENSOR_DRVNAME_OV56702ND_MIPI_RAW,currSensorName))){
+
+                       if (pinSetIdx == 0){
+                               //PDN pin
+                               if(mt_set_gpio_mode(pinSet[pinSetIdx][IDX_PS_CMRST],pinSet[pinSetIdx][IDX_PS_CMRST+IDX_PS_MODE])){PK_DBG("[CAMERA SENSOR] set gpio mode failed!! \n");}
+                               if(mt_set_gpio_dir(pinSet[pinSetIdx][IDX_PS_CMRST],GPIO_DIR_OUT)){PK_DBG("[CAMERA SENSOR] set gpio dir failed!! \n");}
+                               if(mt_set_gpio_out(pinSet[pinSetIdx][IDX_PS_CMRST],GPIO_OUT_ZERO)){PK_DBG("[CAMERA SENSOR] set gpio failed!! \n");}
+
+                               if(TRUE != hwPowerOn(CAMERA_POWER_VCAM_A, VOL_2800,mode_name))
+                               {
+                                       PK_DBG("[CAMERA SENSOR] Fail to enable analog power\n");
+                               }
+
+                               mdelay(10);
+
+                               if(mt_set_gpio_mode(pinSet[pinSetIdx][IDX_PS_CMPDN],pinSet[pinSetIdx][IDX_PS_CMPDN+IDX_PS_MODE])){PK_DBG("[CAMERA LENS] set gpio mode failed!! \n");}
+                               if(mt_set_gpio_dir(pinSet[pinSetIdx][IDX_PS_CMPDN],GPIO_DIR_OUT)){PK_DBG("[CAMERA LENS] set gpio dir failed!! \n");}
+                               if(mt_set_gpio_out(pinSet[pinSetIdx][IDX_PS_CMPDN],GPIO_OUT_ONE)){PK_DBG("[CAMERA LENS] set gpio failed!! \n");}        
+
+                               if(TRUE != hwPowerOn(CAMERA_POWER_VCAM_D2, VOL_1800,mode_name))
+                               {
+                                       PK_DBG("[CAMERA SENSOR] Fail to enable digital power\n");
+                               }
+
+                               mdelay(10);
+
+
+                               if(TRUE != hwPowerOn(CAMERA_POWER_VCAM_D, VOL_1200,mode_name))
+                               {
+                                       PK_DBG("[CAMERA SENSOR] Fail to enable digital power\n");
+                               }
+                               mdelay(10);
+
+                               if(mt_set_gpio_out(pinSet[pinSetIdx][IDX_PS_CMRST],GPIO_OUT_ONE)){PK_DBG("[CAMERA SENSOR] set gpio failed!! \n");}
+
+                       }       
+               }else if (currSensorName && (0 == strcmp(SENSOR_DRVNAME_OV2680_RAW ,currSensorName))) {
+
+                       if (pinSetIdx == 1){
+                               {
+                                       //PDN pin
+                                       //     if(mt_set_gpio_mode(pinSet[pinSetIdx][IDX_PS_CMPDN], pinSet[pinSetIdx][IDX_PS_CMPDN+IDX_PS_MODE])){PK_DBG("[CAMERA LENS] set gpio mode failed!! \n");}
+                                       //     if(mt_set_gpio_dir(pinSet[pinSetIdx][IDX_PS_CMPDN], GPIO_DIR_OUT)){PK_DBG("[CAMERA LENS] set gpio dir failed!! \n");}
+                                       //     if(mt_set_gpio_out(pinSet[pinSetIdx][IDX_PS_CMPDN], pinSet[pinSetIdx][IDX_PS_CMPDN+IDX_PS_OFF])){PK_DBG("[CAMERA LENS] set gpio failed!! \n");}
+                                       //     mdelay(10);
+                                       //     if(mt_set_gpio_out(pinSet[pinSetIdx][IDX_PS_CMPDN], pinSet[pinSetIdx][IDX_PS_CMPDN+IDX_PS_ON])){PK_DBG("[CAMERA LENS] set gpio failed!! \n");}
+                                       //     mdelay(5);
+
+                                       //RST pin
+                                       if(mt_set_gpio_mode(pinSet[pinSetIdx][IDX_PS_CMRST], pinSet[pinSetIdx][IDX_PS_CMRST+IDX_PS_MODE])){PK_DBG("[CAMERA SENSOR] set gpio mode failed!! \n");}
+                                       if(mt_set_gpio_dir(pinSet[pinSetIdx][IDX_PS_CMRST], GPIO_DIR_OUT)){PK_DBG("[CAMERA SENSOR] set gpio dir failed!! \n");}
+                                       if(mt_set_gpio_out(pinSet[pinSetIdx][IDX_PS_CMRST], pinSet[pinSetIdx][IDX_PS_CMRST+IDX_PS_OFF])){PK_DBG("[CAMERA SENSOR] set gpio failed!! \n");}
+                                       mdelay(10);
+                               }
+
+                               if(TRUE != hwPowerOn(CAMERA_POWER_VCAM_D2, VOL_1800, mode_name))
+                               {
+                                       PK_DBG("[CAMERA SENSOR] Fail to enable IO power\n");
+                                       goto _kdCISModulePowerOn_exit_;
+                               }
+
+                               msleep(10);
+
+                               if(TRUE != hwPowerOn(CAMERA_POWER_VCAM_A, VOL_2800, mode_name))
+                               {
+                                       PK_DBG("[CAMERA SENSOR] Fail to enable analog power\n");
+                                       goto _kdCISModulePowerOn_exit_;
+                               }
+
+                               //if(TRUE != hwPowerOn(PMIC_APP_MAIN_CAMERA_POWER_D, VOL_1500,mode_name))
+                               // {
+                               //      PK_DBG("[CAMERA SENSOR] Fail to enable digital power\n");
+                               //      goto _kdCISModulePowerOn_exit_;
+                               // } 
+
+                               if(mt_set_gpio_out(pinSet[pinSetIdx][IDX_PS_CMRST], pinSet[pinSetIdx][IDX_PS_CMRST+IDX_PS_ON])){PK_DBG("[CAMERA SENSOR] set gpio failed!! \n");}
+
+                               // wait power to be stable 
+                               mdelay(10);
+                       }
+
+               }else if (currSensorName && (0 == strcmp(SENSOR_DRVNAME_GC2355_MIPI_RAW ,currSensorName))) {
+
+                       if (pinSetIdx == 1){
+                               //PDN pin
+                               if(mt_set_gpio_mode(pinSet[pinSetIdx][IDX_PS_CMPDN], pinSet[pinSetIdx][IDX_PS_CMPDN+IDX_PS_MODE])){PK_DBG("[CAMERA LENS] set gpio mode failed!! \n");}
+                               if(mt_set_gpio_dir(pinSet[pinSetIdx][IDX_PS_CMPDN], GPIO_DIR_OUT)){PK_DBG("[CAMERA LENS] set gpio dir failed!! \n");}
+                               if(mt_set_gpio_out(pinSet[pinSetIdx][IDX_PS_CMPDN], pinSet[pinSetIdx][IDX_PS_CMPDN+IDX_PS_ON])){PK_DBG("[CAMERA LENS] set gpio failed!! \n");}
+
+                               //RST pin
+                               if(mt_set_gpio_mode(pinSet[pinSetIdx][IDX_PS_CMRST], pinSet[pinSetIdx][IDX_PS_CMRST+IDX_PS_MODE])){PK_DBG("[CAMERA SENSOR] set gpio mode failed!! \n");}
+                               if(mt_set_gpio_dir(pinSet[pinSetIdx][IDX_PS_CMRST], GPIO_DIR_OUT)){PK_DBG("[CAMERA SENSOR] set gpio dir failed!! \n");}
+                               if(mt_set_gpio_out(pinSet[pinSetIdx][IDX_PS_CMRST], pinSet[pinSetIdx][IDX_PS_CMRST+IDX_PS_OFF])){PK_DBG("[CAMERA SENSOR] set gpio failed!! \n");}
+                               mdelay(10);
+
+                               if(TRUE != hwPowerOn(CAMERA_POWER_VCAM_D2, VOL_1800, mode_name))
+                               {
+                                       PK_DBG("[CAMERA SENSOR] Fail to enable IO power\n");
+                                       goto _kdCISModulePowerOn_exit_;
+                               }
+
+
+                               if(TRUE != hwPowerOn(CAMERA_POWER_VCAM_D, VOL_1800,mode_name))
+                               {
+                                       PK_DBG("[CAMERA SENSOR] Fail to enable digital power\n");
+                                       goto _kdCISModulePowerOn_exit_;
+                               } 
+
+                               if(TRUE != hwPowerOn(CAMERA_POWER_VCAM_A, VOL_2800, mode_name))
+                               {
+                                       PK_DBG("[CAMERA SENSOR] Fail to enable analog power\n");
+                                       goto _kdCISModulePowerOn_exit_;
+                               }
+
+
+                               mdelay(5);
+                               if(mt_set_gpio_out(pinSet[pinSetIdx][IDX_PS_CMPDN], pinSet[pinSetIdx][IDX_PS_CMPDN+IDX_PS_OFF])){PK_DBG("[CAMERA LENS] set gpio failed!! \n");}
+
+                               mdelay(5);
+
+                               if(mt_set_gpio_out(pinSet[pinSetIdx][IDX_PS_CMRST], pinSet[pinSetIdx][IDX_PS_CMRST+IDX_PS_ON])){PK_DBG("[CAMERA SENSOR] set gpio failed!! \n");}
+
+                               // wait power to be stable 
+                               mdelay(10);
+
+                       }
+
+               }
+
+
+       }else {//power OFF
+
+        if (currSensorName && (0 == strcmp(SENSOR_DRVNAME_OV5670_MIPI_RAW,currSensorName)||0 == strcmp(SENSOR_DRVNAME_OV56702ND_MIPI_RAW,currSensorName))){
+
+                       if (pinSetIdx == 0){
+                               if(mt_set_gpio_mode(pinSet[pinSetIdx][IDX_PS_CMRST],pinSet[pinSetIdx][IDX_PS_CMRST+IDX_PS_MODE])){PK_DBG("[CAMERA SENSOR] set gpio mode failed!! \n");}
+                               if(mt_set_gpio_dir(pinSet[pinSetIdx][IDX_PS_CMRST],GPIO_DIR_OUT)){PK_DBG("[CAMERA SENSOR] set gpio dir failed!! \n");}
+                               if(mt_set_gpio_out(pinSet[pinSetIdx][IDX_PS_CMRST],pinSet[pinSetIdx][IDX_PS_CMRST+IDX_PS_OFF])){PK_DBG("[CAMERA SENSOR] set gpio failed!! \n");} //low == reset sensor
+
+                               mdelay(5);
+                               if(TRUE != hwPowerDown(CAMERA_POWER_VCAM_D, mode_name)) {
+                                       PK_DBG("[CAMERA SENSOR] Fail to OFF d digital power\n");
+                               }
+                               mdelay(5);
+                               if(TRUE != hwPowerDown(CAMERA_POWER_VCAM_D2,mode_name))
+                               {
+                                       PK_DBG("[CAMERA SENSOR] Fail to OFF d2 digital power\n");
+                               }
+
+                               if(mt_set_gpio_mode(pinSet[pinSetIdx][IDX_PS_CMPDN],pinSet[pinSetIdx][IDX_PS_CMPDN+IDX_PS_MODE])){PK_DBG("[CAMERA LENS] set gpio mode failed!! \n");}
+                               if(mt_set_gpio_dir(pinSet[pinSetIdx][IDX_PS_CMPDN],GPIO_DIR_OUT)){PK_DBG("[CAMERA LENS] set gpio dir failed!! \n");}
+                               if(mt_set_gpio_out(pinSet[pinSetIdx][IDX_PS_CMPDN],pinSet[pinSetIdx][IDX_PS_CMPDN+IDX_PS_OFF])){PK_DBG("[CAMERA LENS] set gpio failed!! \n");} //high == power down lens module
+                               mdelay(5);
+
+                               if(TRUE != hwPowerDown(CAMERA_POWER_VCAM_A,mode_name)) {
+                                       PK_DBG("[CAMERA SENSOR] Fail to OFF a power\n");
+                               }
+                       }
+
+
+               } else if (currSensorName && (0 == strcmp(SENSOR_DRVNAME_OV2680_RAW,currSensorName))){
+
+                       if (pinSetIdx == 1){
+                               if (GPIO_CAMERA_INVALID != pinSet[pinSetIdx][IDX_PS_CMRST]) {
+
+                                       if(mt_set_gpio_mode(pinSet[pinSetIdx][IDX_PS_CMRST],pinSet[pinSetIdx][IDX_PS_CMRST+IDX_PS_MODE])){PK_DBG("[CAMERA SENSOR] set gpio mode failed!! \n");}
+                                       if(mt_set_gpio_dir(pinSet[pinSetIdx][IDX_PS_CMRST],GPIO_DIR_OUT)){PK_DBG("[CAMERA SENSOR] set gpio dir failed!! \n");}
+                                       if(mt_set_gpio_out(pinSet[pinSetIdx][IDX_PS_CMRST],pinSet[pinSetIdx][IDX_PS_CMRST+IDX_PS_OFF])){PK_DBG("[CAMERA SENSOR] set gpio failed!! \n");} //low == reset sensor
+
+                               }
+
+                               if(TRUE != hwPowerDown(CAMERA_POWER_VCAM_A,mode_name)) {
+                                       PK_DBG("[CAMERA SENSOR] Fail to OFF a power\n");
+                               }
+                               mdelay(5);
+
+
+                               if(TRUE != hwPowerDown(CAMERA_POWER_VCAM_D2,mode_name))
+                               {
+                                       PK_DBG("[CAMERA SENSOR] Fail to OFF d2 digital power\n");
+                               }
+                       }
+               } else if (currSensorName && (0 == strcmp(SENSOR_DRVNAME_GC2355_MIPI_RAW,currSensorName))){
+
+                       if (pinSetIdx == 1){
+                               if(mt_set_gpio_mode(pinSet[pinSetIdx][IDX_PS_CMPDN], pinSet[pinSetIdx][IDX_PS_CMPDN+IDX_PS_MODE])){PK_DBG("[CAMERA LENS] set gpio mode failed!! \n");}
+                               if(mt_set_gpio_dir(pinSet[pinSetIdx][IDX_PS_CMPDN], GPIO_DIR_OUT)){PK_DBG("[CAMERA LENS] set gpio dir failed!! \n");}
+                               if(mt_set_gpio_out(pinSet[pinSetIdx][IDX_PS_CMPDN], pinSet[pinSetIdx][IDX_PS_CMPDN+IDX_PS_ON])){PK_DBG("[CAMERA LENS] set gpio failed!! \n");}
+
+                               mdelay(5);
+
+                               if (GPIO_CAMERA_INVALID != pinSet[pinSetIdx][IDX_PS_CMRST]) {
+
+                                       if(mt_set_gpio_mode(pinSet[pinSetIdx][IDX_PS_CMRST],pinSet[pinSetIdx][IDX_PS_CMRST+IDX_PS_MODE])){PK_DBG("[CAMERA SENSOR] set gpio mode failed!! \n");}
+                                       if(mt_set_gpio_dir(pinSet[pinSetIdx][IDX_PS_CMRST],GPIO_DIR_OUT)){PK_DBG("[CAMERA SENSOR] set gpio dir failed!! \n");}
+                                       if(mt_set_gpio_out(pinSet[pinSetIdx][IDX_PS_CMRST],pinSet[pinSetIdx][IDX_PS_CMRST+IDX_PS_OFF])){PK_DBG("[CAMERA SENSOR] set gpio failed!! \n");} //low == reset sensor
+
+                               }
+
+                               mdelay(5);
+
+                               if(TRUE != hwPowerDown(CAMERA_POWER_VCAM_A,mode_name)) {
+                                       PK_DBG("[CAMERA SENSOR] Fail to OFF a power\n");
+                               }
+
+                               if(TRUE != hwPowerDown(CAMERA_POWER_VCAM_D,mode_name))
+                               {
+                                       PK_DBG("[CAMERA SENSOR] Fail to OFF d2 digital power\n");
+                               }
+
+                               if(TRUE != hwPowerDown(CAMERA_POWER_VCAM_D2,mode_name))
+                               {
+                                       PK_DBG("[CAMERA SENSOR] Fail to OFF d2 digital power\n");
+                               }
+                       }
+               }
+
+
+       }//
+
 #endif /* end of defined MTK_ALPS_BOX_SUPPORT */
 
        return 0;
index 1ad05f7eec72da70113ed3c1f6f1666801246cb5..f4e384398c65526a03d3dfad6d169754abb5e538 100644 (file)
@@ -619,8 +619,8 @@ struct msdc_hw msdc1_hw = {
     .data_pins      = 4,
     .data_offset    = 0,
 #ifdef CUST_EINT_MSDC1_INS_NUM
-    .flags          = MSDC_SYS_SUSPEND | MSDC_WP_PIN_EN | MSDC_CD_PIN_EN | MSDC_REMOVABLE | MSDC_HIGHSPEED | MSDC_UHS1 |MSDC_DDR |MSDC_SD_NEED_POWER,
-    
+    .flags          = MSDC_SYS_SUSPEND | MSDC_WP_PIN_EN | MSDC_CD_PIN_EN | MSDC_REMOVABLE | MSDC_HIGHSPEED | MSDC_UHS1 |MSDC_DDR, //|MSDC_SD_NEED_POWER,
+    //[BUGFIX]Added-by SZTCT.leo.guo 05.25.2015, Fixed TF card power control issue.
 #else
     .flags          = MSDC_SYS_SUSPEND | MSDC_WP_PIN_EN | MSDC_HIGHSPEED | MSDC_UHS1 |MSDC_DDR,   
 #endif
index c3962044f954689de8de7a33a8c0238f45c2ecbb..4fa177d5220e74f0d2cdf90c2a32d4222b9e1521 100644 (file)
Binary files a/arch/arm/mach-mt8127/ttab/dct/dct/codegen.dws and b/arch/arm/mach-mt8127/ttab/dct/dct/codegen.dws differ
index c152acc299f2c7740ad815e23bed97a439092ab3..885be6ee62e82118cff2d462fc6939575a58d931 100644 (file)
@@ -28,9 +28,12 @@ unsigned int Cust_GetBacklightLevelSupport_byPWM(void)
 unsigned int brightness_mapping(unsigned int level)
 {
     unsigned int mapped_level;
-    
-    mapped_level = level;
-       
+/* [FEATURE]-Mod-BEGIN by TCTSZ.yaohui.zeng, 2015/04/20,set BL min level to 8(PWM 3.14%)*/
+       if((level <= 32)&&(level > 0))
+               mapped_level = 32;
+       else
+               mapped_level = level;
+/* [FEATURE]-Mod-END by TCTSZ.yaohui.zeng, 2015/04/20*/
        return mapped_level;
 }
 /*
index 5ef80601aeed59159e3baaa04e7ccd925f6dd791..cd9e4ccb7ad028d121b60bcdd81199cdc6c95bd2 100644 (file)
@@ -13,6 +13,7 @@
 #define SOC_BY_SW_FG //oam
 #endif
 
+#define CUST_CAPACITY_OCV2CV_TRANSFORM
 //#define CONFIG_DIS_CHECK_BATTERY
 //#define FIXED_TBAT_25
 
 #define FG_METER_RESISTANCE    0
 
 /* Qmax for battery  */
-#define Q_MAX_POS_50   3009
-#define Q_MAX_POS_25   3009
-#define Q_MAX_POS_0            3009
-#define Q_MAX_NEG_10   3009
-
-#define Q_MAX_POS_50_H_CURRENT  2975
-#define Q_MAX_POS_25_H_CURRENT 2975
-#define Q_MAX_POS_0_H_CURRENT  2975
-#define Q_MAX_NEG_10_H_CURRENT 2975
+#define Q_MAX_POS_50   4060
+#define Q_MAX_POS_25   4060
+#define Q_MAX_POS_0            3400
+#define Q_MAX_NEG_10   2950
 
+#define Q_MAX_POS_50_H_CURRENT  4000
+#define Q_MAX_POS_25_H_CURRENT 4020
+#define Q_MAX_POS_0_H_CURRENT  2760
+#define Q_MAX_NEG_10_H_CURRENT 2450
 
+/*[BUGFIX]-Add-BEGIN by TCTSZ.pingao.yang, 4/15/2015,  pr-975290,  change fg integration way */
 /* Discharge Percentage */
-#define OAM_D5          1              //  1 : D5,   0: D2
-
+#define OAM_D5          0              //  1 : D5,   0: D2
+/*[BUGFIX]-Add-end by TCTSZ.pingao.yang, 4/15/2015*/
 
 /* battery meter parameter */
 #define CUST_TRACKING_POINT  14
-#define CUST_R_SENSE         200
+#define CUST_R_SENSE         62  //Fixed sensor resistor according to HW designed.
 #define CUST_HW_CC                 0
 #define AGING_TUNING_VALUE   100
 #define CUST_R_FG_OFFSET    23
 #define LOW_POWER_WAKEUP_PERIOD                300             //5 * 60 = 5 min
 #define CLOSE_POWEROFF_WAKEUP_PERIOD   30      //30 s
 
+/*[BUGFIX]-Add-BEGIN by TCTSZ.pingao.yang, 4/15/2015,  */
+#define MAX_SUSPEND_CURRENT 420 // 42 mA
+#define MIN_SUSPEND_CURRENT 0  // 0 mA
+#define DEFAUL_SUSPEND_CURRENT 120 //12mA
+#define SUSPEND_CURRENT_SETP 30 //3mA
+#define SLEEP_AFTER_FG_DIFF 3  // diff about 3%
+#define UI_REDUCE_CURRENT 180 //18mA
+#define SLEEP_REDUCE_CURRENT 60 //6mA
+/*[BUGFIX]-Add-END by TCTSZ.pingao.yang */
+
 #endif //#ifndef _CUST_BATTERY_METER_H
index 9574fa0095c47a0e000999a9822b7fbe0dc369fb..b0e7df8662bffe129938f174496c1ac312baed54 100644 (file)
@@ -19,7 +19,7 @@
 
 #if (BAT_NTC_10 == 1)
 #define RBAT_PULL_UP_R             16900
-#define RBAT_PULL_DOWN_R           30000
+#define RBAT_PULL_DOWN_R           27000
 #endif
 #if (BAT_NTC_47 == 1)
 #define RBAT_PULL_UP_R             61900
 // ============================================================
 // typedef
 // ============================================================
-typedef struct _BATTERY_PROFILE_STRUC
-{
+typedef struct _BATTERY_PROFILE_STRUC {
     kal_int32 percentage;
     kal_int32 voltage;
 } BATTERY_PROFILE_STRUC, *BATTERY_PROFILE_STRUC_P;
 
-typedef struct _R_PROFILE_STRUC
-{
+typedef struct _R_PROFILE_STRUC {
     kal_int32 resistance; // Ohm
     kal_int32 voltage;
 } R_PROFILE_STRUC, *R_PROFILE_STRUC_P;
 
-typedef enum
-{
+typedef enum {
     T1_0C,
     T2_25C,
     T3_50C
@@ -75,984 +72,972 @@ typedef enum
 // <DOD, Battery_Voltage> Table
 // ============================================================
 #if (BAT_NTC_10 == 1)
-    BATT_TEMPERATURE Batt_Temperature_Table[] = {
-        {-20,76241},
-        {-15,58649},
-        {-10,45569},
-        { -5,35735},
-        {  0,28271},
-        {  5,22551},
-        { 10,18136},
-        { 15,14696},
-        { 20,11997},
-        { 25,10000},
-        { 30,8365},
-        { 35,7011},
-        { 40,5951},
-        { 45,4992},
-        { 50,4217},
-        { 55,3579},
-        { 60,3051}
-    };
+BATT_TEMPERATURE Batt_Temperature_Table[] = {
+    {-20,65170},
+    {-15,52060},
+    {-10,42820},
+    { -5,34420},
+    {  0,27750},
+    {  5,22440},
+    { 10,17926},
+    { 15,14674},
+    { 20,12081},
+    { 25,10000},
+    { 30,8250},
+    { 35,6850},
+    { 40,5823},
+    { 45,4907},
+    { 50,4160},
+    { 55,3538},
+    { 60,3021}
+};
 #endif
 
 #if (BAT_NTC_47 == 1)
-    BATT_TEMPERATURE Batt_Temperature_Table[] = {
-        {-20,483954},
-        {-15,360850},
-        {-10,271697},
-        { -5,206463},
-        {  0,158214},
-        {  5,122259},
-        { 10,95227},
-        { 15,74730},
-        { 20,59065},
-        { 25,47000},
-        { 30,37643},
-        { 35,30334},
-        { 40,24591},
-        { 45,20048},
-        { 50,16433},
-        { 55,13539},
-        { 60,11210}        
-    };
+BATT_TEMPERATURE Batt_Temperature_Table[] = {
+    {-20,483954},
+    {-15,360850},
+    {-10,271697},
+    { -5,206463},
+    {  0,158214},
+    {  5,122259},
+    { 10,95227},
+    { 15,74730},
+    { 20,59065},
+    { 25,47000},
+    { 30,37643},
+    { 35,30334},
+    { 40,24591},
+    { 45,20048},
+    { 50,16433},
+    { 55,13539},
+    { 60,11210}
+};
 #endif
 
 #if (BAT_NTC_100 == 1)
-       BATT_TEMPERATURE Batt_Temperature_Table[] = {
-               {-20,1151037},
-               {-15,846579},
-               {-10,628988},
-               { -5,471632},
-               {  0,357012},
-               {  5,272500},
-               { 10,209710},
-               { 15,162651},
-               { 20,127080},
-               { 25,100000},
-               { 30,79222},
-               { 35,63167},
-               { 40,50677},
-               { 45,40904},
-               { 50,33195},
-               { 55,27091},
-               { 60,22224}
-       };
+BATT_TEMPERATURE Batt_Temperature_Table[] = {
+    {-20,1151037},
+    {-15,846579},
+    {-10,628988},
+    { -5,471632},
+    {  0,357012},
+    {  5,272500},
+    { 10,209710},
+    { 15,162651},
+    { 20,127080},
+    { 25,100000},
+    { 30,79222},
+    { 35,63167},
+    { 40,50677},
+    { 45,40904},
+    { 50,33195},
+    { 55,27091},
+    { 60,22224}
+};
 #endif
 // T0 -10C
-BATTERY_PROFILE_STRUC battery_profile_t0[] =
-{
-               {0,   4175},
-               {2,   4152},
-               {4,   4133},
-               {5,   4115},
-               {7,   4098},
-               {9,   4083},
-               {11,   4069},
-               {13,   4054},
-               {14,   4037},
-               {16,   4020},
-               {18,   4005},
-               {20,   3993},
-               {21,   3981},
-               {23,   3971},
-               {25,   3959},
-               {27,   3948},
-               {29,   3937},
-               {30,   3927},
-               {32,   3917},
-               {34,   3907},
-               {36,   3897},
-               {38,   3886},
-               {39,   3875},
-               {41,   3861},
-               {43,   3848},
-               {45,   3836},
-               {47,   3826},
-               {48,   3818},
-               {50,   3811},
-               {52,   3805},
-               {54,   3800},
-               {55,   3795},
-               {57,   3791},
-               {59,   3788},
-               {61,   3783},
-               {63,   3780},
-               {64,   3777},
-               {66,   3775},
-               {68,   3773},
-               {70,   3771},
-               {72,   3769},
-               {73,   3766},
-               {75,   3762},
-               {77,   3755},
-               {79,   3748},
-               {80,   3741},
-               {82,   3733},
-               {84,   3721},
-               {86,   3710},
-               {88,   3694},
-               {89,   3689},
-               {91,   3686},
-               {93,   3684},
-               {95,   3679},
-               {97,   3638},
-               {98,   3544},
-               {100,   3381},
-               {101,   3312},
-               {101,   3301},
-               {101,   3295},
-               {101,   3293},
-               {101,   3291},
-               {101,   3290},
-               {101,   3288},
-               {101,   3288},
-               {101,   3285},
-               {101,   3285},
-               {101,   3284},
-               {101,   3283},
-               {101,   3282},
-               {101,   3283},
-               {101,   3282},
-               {101,   3281},
-               {101,   3280},
-               {101,   3280},
-               {101,   3280},
-               {101,   3277},
-               {101,   3277},
-               {101,   3278},
-               {101,   3279},
-               {101,   3278},
-               {101,   3276},
-               {101,   3275},
-               {101,   3275},
-               {101,   3274},
-               {101,   3274},
+BATTERY_PROFILE_STRUC battery_profile_t0[] = {
+    {0,   4333},
+    {1,   4314},
+    {3,   4296},
+    {4,   4280},
+    {6,   4263},
+    {7,   4247},
+    {9,   4231},
+    {10,  4215},
+    {12,  4199},
+    {13,  4183},
+    {15,  4168},
+    {16,  4153},
+    {18,  4137},
+    {19,  4123},
+    {20,  4107},
+    {22,  4093},
+    {23,  4079},
+    {25,  4068},
+    {26,  4058},
+    {28,  4040},
+    {29,  4020},
+    {31,  4004},
+    {32,  3993},
+    {34,  3984},
+    {35,  3974},
+    {37,  3963},
+    {38,  3951},
+    {39,  3938},
+    {41,  3923},
+    {42,  3906},
+    {44,  3891},
+    {45,  3879},
+    {47,  3868},
+    {48,  3860},
+    {50,  3851},
+    {51,  3844},
+    {53,  3837},
+    {54,  3830},
+    {56,  3824},
+    {57,  3818},
+    {58,  3812},
+    {60,  3807},
+    {61,  3803},
+    {63,  3797},
+    {64,  3793},
+    {66,  3790},
+    {67,  3786},
+    {69,  3782},
+    {70,  3778},
+    {72,  3774},
+    {73,  3769},
+    {75,  3765},
+    {76,  3760},
+    {77,  3754},
+    {79,  3747},
+    {80,  3742},
+    {82,  3734},
+    {83,  3724},
+    {85,  3715},
+    {86,  3702},
+    {88,  3693},
+    {89,  3691},
+    {91,  3689},
+    {92,  3687},
+    {94,  3685},
+    {95,  3677},
+    {96,  3638},
+    {98,  3567},
+    {99,  3464},
+    {100, 3359},
+    {101, 3333},
+    {101, 3319},
+    {101, 3312},
+    {101, 3307},
+    {101, 3304},
+    {101, 3300},
+    {101, 3295},
+    {101, 3292},
+    {101, 3291},
+    {101, 3290},
+    {101, 3290},
+    {101, 3289},
+    {101, 3288},
+    {101, 3285},
+    {101, 3285},
+    {101, 3284},
 };
-      
-        
-// T1 0C 
-BATTERY_PROFILE_STRUC battery_profile_t1[] =
-{
-               {0,   4175},
-               {2,   4152},
-               {4,   4133},
-               {5,   4115},
-               {7,   4098},
-               {9,   4083},
-               {11,   4069},
-               {13,   4054},
-               {14,   4037},
-               {16,   4020},
-               {18,   4005},
-               {20,   3993},
-               {21,   3981},
-               {23,   3971},
-               {25,   3959},
-               {27,   3948},
-               {29,   3937},
-               {30,   3927},
-               {32,   3917},
-               {34,   3907},
-               {36,   3897},
-               {38,   3886},
-               {39,   3875},
-               {41,   3861},
-               {43,   3848},
-               {45,   3836},
-               {47,   3826},
-               {48,   3818},
-               {50,   3811},
-               {52,   3805},
-               {54,   3800},
-               {55,   3795},
-               {57,   3791},
-               {59,   3788},
-               {61,   3783},
-               {63,   3780},
-               {64,   3777},
-               {66,   3775},
-               {68,   3773},
-               {70,   3771},
-               {72,   3769},
-               {73,   3766},
-               {75,   3762},
-               {77,   3755},
-               {79,   3748},
-               {80,   3741},
-               {82,   3733},
-               {84,   3721},
-               {86,   3710},
-               {88,   3694},
-               {89,   3689},
-               {91,   3686},
-               {93,   3684},
-               {95,   3679},
-               {97,   3638},
-               {98,   3544},
-               {100,   3381},
-               {101,   3312},
-               {101,   3301},
-               {101,   3295},
-               {101,   3293},
-               {101,   3291},
-               {101,   3290},
-               {101,   3288},
-               {101,   3288},
-               {101,   3285},
-               {101,   3285},
-               {101,   3284},
-               {101,   3283},
-               {101,   3282},
-               {101,   3283},
-               {101,   3282},
-               {101,   3281},
-               {101,   3280},
-               {101,   3280},
-               {101,   3280},
-               {101,   3277},
-               {101,   3277},
-               {101,   3278},
-               {101,   3279},
-               {101,   3278},
-               {101,   3276},
-               {101,   3275},
-               {101,   3275},
-               {101,   3274},
-               {101,   3274},
+
+// T1 0C
+BATTERY_PROFILE_STRUC battery_profile_t1[] = {
+    {0,   4333},
+    {1,   4314},
+    {3,   4296},
+    {4,   4280},
+    {6,   4263},
+    {7,   4247},
+    {9,   4231},
+    {10,  4215},
+    {12,  4199},
+    {13,  4183},
+    {15,  4168},
+    {16,  4153},
+    {18,  4137},
+    {19,  4123},
+    {20,  4107},
+    {22,  4093},
+    {23,  4092},
+    {25,  4081},
+    {26,  4072},
+    {28,  4047},
+    {29,  4027},
+    {31,  4005},
+    {32,  3985},
+    {34,  3957},
+    {35,  3948},
+    {37,  3940},
+    {38,  3932},
+    {39,  3923},
+    {41,  3913},
+    {42,  3903},
+    {44,  3886},
+    {45,  3878},
+    {47,  3869},
+    {48,  3862},
+    {50,  3851},
+    {51,  3842},
+    {53,  3837},
+    {54,  3830},
+    {56,  3820},
+    {57,  3815},
+    {58,  3812},
+    {60,  3807},
+    {61,  3803},
+    {63,  3793},
+    {64,  3790},
+    {66,  3786},
+    {67,  3783},
+    {69,  3780},
+    {70,  3778},
+    {72,  3771},
+    {73,  3769},
+    {75,  3766},
+    {76,  3762},
+    {77,  3759},
+    {79,  3751},
+    {80,  3746},
+    {82,  3740},
+    {83,  3732},
+    {85,  3717},
+    {86,  3709},
+    {88,  3703},
+    {89,  3698},
+    {91,  3696},
+    {92,  3693},
+    {94,  3685},
+    {95,  3672},
+    {96,  3643},
+    {98,  3589},
+    {99,  3507},
+    {100, 3384},
+    {101, 3333},
+    {101, 3319},
+    {101, 3312},
+    {101, 3307},
+    {101, 3304},
+    {101, 3300},
+    {101, 3295},
+    {101, 3292},
+    {101, 3291},
+    {101, 3290},
+    {101, 3290},
+    {101, 3289},
+    {101, 3288},
+    {101, 3285},
+    {101, 3285},
+    {101, 3284},
 };
-           
 
 // T2 25C
-BATTERY_PROFILE_STRUC battery_profile_t2[] =
-{
-               {0,   4175},
-               {2,   4152},
-               {4,   4133},
-               {5,   4115},
-               {7,   4098},
-               {9,   4083},
-               {11,   4069},
-               {13,   4054},
-               {14,   4037},
-               {16,   4020},
-               {18,   4005},
-               {20,   3993},
-               {21,   3981},
-               {23,   3971},
-               {25,   3959},
-               {27,   3948},
-               {29,   3937},
-               {30,   3927},
-               {32,   3917},
-               {34,   3907},
-               {36,   3897},
-               {38,   3886},
-               {39,   3875},
-               {41,   3861},
-               {43,   3848},
-               {45,   3836},
-               {47,   3826},
-               {48,   3818},
-               {50,   3811},
-               {52,   3805},
-               {54,   3800},
-               {55,   3795},
-               {57,   3791},
-               {59,   3788},
-               {61,   3783},
-               {63,   3780},
-               {64,   3777},
-               {66,   3775},
-               {68,   3773},
-               {70,   3771},
-               {72,   3769},
-               {73,   3766},
-               {75,   3762},
-               {77,   3755},
-               {79,   3748},
-               {80,   3741},
-               {82,   3733},
-               {84,   3721},
-               {86,   3710},
-               {88,   3694},
-               {89,   3689},
-               {91,   3686},
-               {93,   3684},
-               {95,   3679},
-               {97,   3638},
-               {98,   3544},
-               {100,   3381},
-               {101,   3312},
-               {101,   3301},
-               {101,   3295},
-               {101,   3293},
-               {101,   3291},
-               {101,   3290},
-               {101,   3288},
-               {101,   3288},
-               {101,   3285},
-               {101,   3285},
-               {101,   3284},
-               {101,   3283},
-               {101,   3282},
-               {101,   3283},
-               {101,   3282},
-               {101,   3281},
-               {101,   3280},
-               {101,   3280},
-               {101,   3280},
-               {101,   3277},
-               {101,   3277},
-               {101,   3278},
-               {101,   3279},
-               {101,   3278},
-               {101,   3276},
-               {101,   3275},
-               {101,   3275},
-               {101,   3274},
-               {101,   3274},
-};     
+BATTERY_PROFILE_STRUC battery_profile_t2[] = {
+    {0,   4333},
+    {1,   4328},
+    {3,   4316},
+    {4,   4303},
+    {6,   4274},
+    {7,   4260},
+    {9,   4247},
+    {10,  4232},
+    {12,  4220},
+    {13,  4193},
+    {15,  4182},
+    {16,  4167},
+    {18,  4141},
+    {19,  4130},
+    {20,  4116},
+    {22,  4106},
+    {23,  4091},
+    {25,  4080},
+    {26,  4068},
+    {28,  4051},
+    {29,  4037},
+    {31,  4023},
+    {32,  4006},
+    {34,  3984},
+    {35,  3975},
+    {37,  3965},
+    {38,  3954},
+    {39,  3942},
+    {41,  3940},
+    {42,  3928},
+    {44,  3924},
+    {45,  3920},
+    {47,  3888},
+    {48,  3882},
+    {50,  3880},
+    {51,  3872},
+    {53,  3868},
+    {54,  3862},
+    {56,  3850},
+    {57,  3836},
+    {58,  3832},
+    {60,  3830},
+    {61,  3824},
+    {63,  3818},
+    {64,  3812},
+    {66,  3801},
+    {67,  3791},
+    {69,  3786},
+    {70,  3780},
+    {72,  3779},
+    {73,  3775},
+    {75,  3769},
+    {76,  3765},
+    {77,  3762},
+    {79,  3753},
+    {80,  3745},
+    {82,  3734},
+    {83,  3724},
+    {85,  3720},
+    {86,  3717},
+    {88,  3710},
+    {89,  3704},
+    {91,  3698},
+    {92,  3692},
+    {94,  3692},
+    {95,  3690},
+    {96,  3684},
+    {98,  3655},
+    {99,  3626},
+    {100, 3588},
+    {101, 3582},
+    {101, 3576},
+    {101, 3576},
+    {101, 3574},
+    {101, 3569},
+    {101, 3569},
+    {101, 3569},
+    {101, 3569},
+    {101, 3569},
+    {101, 3576},
+    {101, 3574},
+    {101, 3569},
+    {101, 3569},
+    {101, 3569},
+    {101, 3569},
+    {101, 3569},
+};
 
 // T3 50C
-BATTERY_PROFILE_STRUC battery_profile_t3[] =
-{
-               {0,   4175},
-               {2,   4152},
-               {4,   4133},
-               {5,   4115},
-               {7,   4098},
-               {9,   4083},
-               {11,   4069},
-               {13,   4054},
-               {14,   4037},
-               {16,   4020},
-               {18,   4005},
-               {20,   3993},
-               {21,   3981},
-               {23,   3971},
-               {25,   3959},
-               {27,   3948},
-               {29,   3937},
-               {30,   3927},
-               {32,   3917},
-               {34,   3907},
-               {36,   3897},
-               {38,   3886},
-               {39,   3875},
-               {41,   3861},
-               {43,   3848},
-               {45,   3836},
-               {47,   3826},
-               {48,   3818},
-               {50,   3811},
-               {52,   3805},
-               {54,   3800},
-               {55,   3795},
-               {57,   3791},
-               {59,   3788},
-               {61,   3783},
-               {63,   3780},
-               {64,   3777},
-               {66,   3775},
-               {68,   3773},
-               {70,   3771},
-               {72,   3769},
-               {73,   3766},
-               {75,   3762},
-               {77,   3755},
-               {79,   3748},
-               {80,   3741},
-               {82,   3733},
-               {84,   3721},
-               {86,   3710},
-               {88,   3694},
-               {89,   3689},
-               {91,   3686},
-               {93,   3684},
-               {95,   3679},
-               {97,   3638},
-               {98,   3544},
-               {100,   3381},
-               {101,   3312},
-               {101,   3301},
-               {101,   3295},
-               {101,   3293},
-               {101,   3291},
-               {101,   3290},
-               {101,   3288},
-               {101,   3288},
-               {101,   3285},
-               {101,   3285},
-               {101,   3284},
-               {101,   3283},
-               {101,   3282},
-               {101,   3283},
-               {101,   3282},
-               {101,   3281},
-               {101,   3280},
-               {101,   3280},
-               {101,   3280},
-               {101,   3277},
-               {101,   3277},
-               {101,   3278},
-               {101,   3279},
-               {101,   3278},
-               {101,   3276},
-               {101,   3275},
-               {101,   3275},
-               {101,   3274},
-               {101,   3274},
-};           
+BATTERY_PROFILE_STRUC battery_profile_t3[] = {
+    {0,   4333},
+    {1,   4314},
+    {3,   4296},
+    {4,   4280},
+    {6,   4263},
+    {7,   4247},
+    {9,   4231},
+    {10,   4215},
+    {12,   4199},
+    {13,   4183},
+    {15,   4168},
+    {16,   4153},
+    {18,   4137},
+    {19,   4123},
+    {20,   4107},
+    {22,   4093},
+    {23,   4079},
+    {25,   4068},
+    {26,   4058},
+    {28,   4040},
+    {29,   4020},
+    {31,   4004},
+    {32,   3993},
+    {34,   3984},
+    {35,   3974},
+    {37,   3963},
+    {38,   3951},
+    {39,   3938},
+    {41,   3923},
+    {42,   3906},
+    {44,   3891},
+    {45,   3879},
+    {47,   3868},
+    {48,   3860},
+    {50,   3851},
+    {51,   3844},
+    {53,   3837},
+    {54,   3830},
+    {56,   3824},
+    {57,   3818},
+    {58,   3812},
+    {60,   3807},
+    {61,   3803},
+    {63,   3797},
+    {64,   3793},
+    {66,   3790},
+    {67,   3786},
+    {69,   3782},
+    {70,   3778},
+    {72,   3774},
+    {73,   3769},
+    {75,   3765},
+    {76,   3760},
+    {77,   3754},
+    {79,   3747},
+    {80,   3742},
+    {82,   3734},
+    {83,   3724},
+    {85,   3715},
+    {86,   3702},
+    {88,   3693},
+    {89,   3691},
+    {91,   3689},
+    {92,   3687},
+    {94,   3685},
+    {95,   3677},
+    {96,   3638},
+    {98,   3567},
+    {99,   3464},
+    {100,   3359},
+    {101,   3333},
+    {101,   3319},
+    {101,   3312},
+    {101,   3307},
+    {101,   3304},
+    {101,   3300},
+    {101,   3295},
+    {101,   3292},
+    {101,   3291},
+    {101,   3290},
+    {101,   3290},
+    {101,   3289},
+    {101,   3288},
+    {101,   3285},
+    {101,   3285},
+    {101,   3284},
+};
 
 // battery profile for actual temperature. The size should be the same as T1, T2 and T3
-BATTERY_PROFILE_STRUC battery_profile_temperature[] =
-{
-               {0,   0},
-               {0,   0},
-               {0,   0},
-               {0,   0},
-               {0,   0},
-               {0,   0},
-               {0,   0},
-               {0,   0},
-               {0,   0},
-               {0,   0},
-               {0,   0},
-               {0,   0},
-               {0,   0},
-               {0,   0},
-               {0,   0},
-               {0,   0},
-               {0,   0},
-               {0,   0},
-               {0,   0},
-               {0,   0},
-               {0,   0},
-               {0,   0},
-               {0,   0},
-               {0,   0},
-               {0,   0},
-               {0,   0},
-               {0,   0},
-               {0,   0},
-               {0,   0},
-               {0,   0},
-               {0,   0},
-               {0,   0},
-               {0,   0},
-               {0,   0},
-               {0,   0},
-               {0,   0},
-               {0,   0},
-               {0,   0},
-               {0,   0},
-               {0,   0},
-               {0,   0},
-               {0,   0},
-               {0,   0},
-               {0,   0},
-               {0,   0},
-               {0,   0},
-               {0,   0},
-               {0,   0},
-               {0,   0},
-               {0,   0},
-               {0,   0},
-               {0,   0},
-               {0,   0},
-               {0,   0},
-               {0,   0},
-               {0,   0},
-               {0,   0},
-               {0,   0},
-               {0,   0},
-               {0,   0},
-               {0,   0},
-               {0,   0},
-               {0,   0},
-               {0,   0},
-               {0,   0},
-               {0,   0},
-               {0,   0},
-               {0,   0},
-               {0,   0},
-               {0,   0},
-               {0,   0},
-               {0,   0},
-               {0,   0},
-               {0,   0},
-               {0,   0},
-               {0,   0},
-               {0,   0},
-               {0,   0},
-               {0,   0},
-               {0,   0},
-               {0,   0},
-               {0,   0},
-               {0,   0},
-               {0,   0},
-               {0,   0},
-               {0,   0},
+BATTERY_PROFILE_STRUC battery_profile_temperature[] = {
+    {0,   0},
+    {0,   0},
+    {0,   0},
+    {0,   0},
+    {0,   0},
+    {0,   0},
+    {0,   0},
+    {0,   0},
+    {0,   0},
+    {0,   0},
+    {0,   0},
+    {0,   0},
+    {0,   0},
+    {0,   0},
+    {0,   0},
+    {0,   0},
+    {0,   0},
+    {0,   0},
+    {0,   0},
+    {0,   0},
+    {0,   0},
+    {0,   0},
+    {0,   0},
+    {0,   0},
+    {0,   0},
+    {0,   0},
+    {0,   0},
+    {0,   0},
+    {0,   0},
+    {0,   0},
+    {0,   0},
+    {0,   0},
+    {0,   0},
+    {0,   0},
+    {0,   0},
+    {0,   0},
+    {0,   0},
+    {0,   0},
+    {0,   0},
+    {0,   0},
+    {0,   0},
+    {0,   0},
+    {0,   0},
+    {0,   0},
+    {0,   0},
+    {0,   0},
+    {0,   0},
+    {0,   0},
+    {0,   0},
+    {0,   0},
+    {0,   0},
+    {0,   0},
+    {0,   0},
+    {0,   0},
+    {0,   0},
+    {0,   0},
+    {0,   0},
+    {0,   0},
+    {0,   0},
+    {0,   0},
+    {0,   0},
+    {0,   0},
+    {0,   0},
+    {0,   0},
+    {0,   0},
+    {0,   0},
+    {0,   0},
+    {0,   0},
+    {0,   0},
+    {0,   0},
+    {0,   0},
+    {0,   0},
+    {0,   0},
+    {0,   0},
+    {0,   0},
+    {0,   0},
+    {0,   0},
+    {0,   0},
+    {0,   0},
+    {0,   0},
+    {0,   0},
+    {0,   0},
+    {0,   0},
+    {0,   0},
+    {0,   0},
+    {0,   0},
 };
-    
+
 
 // ============================================================
 // <Rbat, Battery_Voltage> Table
 // ============================================================
 // T0 -10C
-R_PROFILE_STRUC r_profile_t0[] =
-{
-               {145,   4175},
-               {145,   4152},
-               {147,   4133},
-               {147,   4115},
-               {148,   4098},
-               {150,   4083},
-               {153,   4069},
-               {155,   4054},
-               {157,   4037},
-               {157,   4020},
-               {160,   4005},
-               {165,   3993},
-               {165,   3981},
-               {168,   3971},
-               {170,   3959},
-               {172,   3948},
-               {173,   3937},
-               {177,   3927},
-               {177,   3917},
-               {178,   3907},
-               {178,   3897},
-               {177,   3886},
-               {175,   3875},
-               {167,   3861},
-               {160,   3848},
-               {153,   3836},
-               {150,   3826},
-               {150,   3818},
-               {148,   3811},
-               {148,   3805},
-               {148,   3800},
-               {150,   3795},
-               {152,   3791},
-               {153,   3788},
-               {152,   3783},
-               {153,   3780},
-               {155,   3777},
-               {157,   3775},
-               {157,   3773},
-               {157,   3771},
-               {157,   3769},
-               {157,   3766},
-               {155,   3762},
-               {152,   3755},
-               {150,   3748},
-               {148,   3741},
-               {152,   3733},
-               {148,   3721},
-               {152,   3710},
-               {147,   3694},
-               {147,   3689},
-               {148,   3686},
-               {158,   3684},
-               {170,   3679},
-               {162,   3638},
-               {165,   3544},
-               {190,   3381},
-               {188,   3312},
-               {168,   3301},
-               {162,   3295},
-               {155,   3293},
-               {153,   3291},
-               {152,   3290},
-               {152,   3288},
-               {148,   3288},
-               {145,   3285},
-               {147,   3285},
-               {143,   3284},
-               {140,   3283},
-               {138,   3282},
-               {138,   3283},
-               {138,   3282},
-               {138,   3281},
-               {137,   3280},
-               {137,   3280},
-               {137,   3280},
-               {135,   3277},
-               {132,   3277},
-               {133,   3278},
-               {135,   3279},
-               {137,   3278},
-               {132,   3276},
-               {138,   3275},
-               {133,   3275},
-               {133,   3274},
-               {133,   3274},
+R_PROFILE_STRUC r_profile_t0[] = {
+    {813,   4333},
+    {813,   4314},
+    {814,   4296},
+    {806,   4280},
+    {801,   4263},
+    {793,   4247},
+    {788,   4231},
+    {781,   4215},
+    {775,   4199},
+    {771,   4183},
+    {768,   4168},
+    {762,   4153},
+    {761,   4137},
+    {745,   4123},
+    {751,   4107},
+    {745,   4093},
+    {745,   4079},
+    {733,   4068},
+    {732,   4058},
+    {737,   4040},
+    {739,   4020},
+    {736,   4004},
+    {732,   3993},
+    {722,   3984},
+    {718,   3974},
+    {709,   3963},
+    {707,   3951},
+    {708,   3938},
+    {711,   3923},
+    {716,   3906},
+    {718,   3891},
+    {724,   3879},
+    {728,   3868},
+    {733,   3860},
+    {737,   3851},
+    {746,   3844},
+    {748,   3837},
+    {761,   3830},
+    {770,   3824},
+    {783,   3818},
+    {798,   3812},
+    {811,   3807},
+    {823,   3803},
+    {836,   3797},
+    {852,   3793},
+    {869,   3790},
+    {889,   3786},
+    {904,   3782},
+    {921,   3778},
+    {945,   3774},
+    {962,   3769},
+    {986,   3765},
+    {1005,   3760},
+    {1024,   3754},
+    {1049,   3747},
+    {1067,   3742},
+    {1085,   3734},
+    {1110,   3724},
+    {1131,   3715},
+    {1155,   3702},
+    {1182,   3693},
+    {1215,   3691},
+    {1242,   3689},
+    {1277,   3687},
+    {1314,   3685},
+    {1350,   3677},
+    {1397,   3638},
+    {1450,   3567},
+    {1498,   3464},
+    {1552,   3359},
+    {1606,   3333},
+    {1654,   3319},
+    {1699,   3312},
+    {1737,   3307},
+    {1783,   3304},
+    {1826,   3300},
+    {1889,   3295},
+    {1967,   3292},
+    {1968,   3291},
+    {1968,   3290},
+    {1968,   3290},
+    {1970,   3289},
+    {1970,   3288},
+    {1970,   3285},
+    {1970,   3285},
+    {1977,   3284},
 };
 
 // T1 0C
-R_PROFILE_STRUC r_profile_t1[] =
-{
-               {145,   4175},
-               {145,   4152},
-               {147,   4133},
-               {147,   4115},
-               {148,   4098},
-               {150,   4083},
-               {153,   4069},
-               {155,   4054},
-               {157,   4037},
-               {157,   4020},
-               {160,   4005},
-               {165,   3993},
-               {165,   3981},
-               {168,   3971},
-               {170,   3959},
-               {172,   3948},
-               {173,   3937},
-               {177,   3927},
-               {177,   3917},
-               {178,   3907},
-               {178,   3897},
-               {177,   3886},
-               {175,   3875},
-               {167,   3861},
-               {160,   3848},
-               {153,   3836},
-               {150,   3826},
-               {150,   3818},
-               {148,   3811},
-               {148,   3805},
-               {148,   3800},
-               {150,   3795},
-               {152,   3791},
-               {153,   3788},
-               {152,   3783},
-               {153,   3780},
-               {155,   3777},
-               {157,   3775},
-               {157,   3773},
-               {157,   3771},
-               {157,   3769},
-               {157,   3766},
-               {155,   3762},
-               {152,   3755},
-               {150,   3748},
-               {148,   3741},
-               {152,   3733},
-               {148,   3721},
-               {152,   3710},
-               {147,   3694},
-               {147,   3689},
-               {148,   3686},
-               {158,   3684},
-               {170,   3679},
-               {162,   3638},
-               {165,   3544},
-               {190,   3381},
-               {188,   3312},
-               {168,   3301},
-               {162,   3295},
-               {155,   3293},
-               {153,   3291},
-               {152,   3290},
-               {152,   3288},
-               {148,   3288},
-               {145,   3285},
-               {147,   3285},
-               {143,   3284},
-               {140,   3283},
-               {138,   3282},
-               {138,   3283},
-               {138,   3282},
-               {138,   3281},
-               {137,   3280},
-               {137,   3280},
-               {137,   3280},
-               {135,   3277},
-               {132,   3277},
-               {133,   3278},
-               {135,   3279},
-               {137,   3278},
-               {132,   3276},
-               {138,   3275},
-               {133,   3275},
-               {133,   3274},
-               {133,   3274},
-};    
+R_PROFILE_STRUC r_profile_t1[] = {
+    {409,   4333},
+    {409,   4314},
+    {407,   4296},
+    {401,   4280},
+    {404,   4263},
+    {394,   4247},
+    {396,   4231},
+    {390,   4215},
+    {384,   4199},
+    {387,   4183},
+    {384,   4168},
+    {383,   4153},
+    {387,   4137},
+    {383,   4123},
+    {380,   4107},
+    {384,   4093},
+    {379,   4079},
+    {382,   4068},
+    {384,   4058},
+    {384,   4040},
+    {387,   4020},
+    {388,   4004},
+    {393,   3993},
+    {392,   3984},
+    {387,   3974},
+    {373,   3963},
+    {369,   3951},
+    {366,   3938},
+    {360,   3923},
+    {360,   3906},
+    {358,   3891},
+    {357,   3879},
+    {353,   3868},
+    {350,   3860},
+    {346,   3851},
+    {344,   3844},
+    {347,   3837},
+    {350,   3830},
+    {351,   3824},
+    {353,   3818},
+    {354,   3812},
+    {360,   3807},
+    {364,   3803},
+    {367,   3797},
+    {372,   3793},
+    {382,   3790},
+    {388,   3786},
+    {392,   3782},
+    {405,   3778},
+    {407,   3774},
+    {417,   3769},
+    {426,   3765},
+    {432,   3760},
+    {443,   3754},
+    {449,   3747},
+    {462,   3742},
+    {473,   3734},
+    {481,   3724},
+    {485,   3715},
+    {494,   3702},
+    {505,   3693},
+    {519,   3691},
+    {528,   3689},
+    {539,   3687},
+    {553,   3685},
+    {565,   3677},
+    {579,   3638},
+    {597,   3567},
+    {608,   3464},
+    {629,   3359},
+    {654,   3333},
+    {678,   3319},
+    {702,   3312},
+    {734,   3307},
+    {778,   3304},
+    {829,   3300},
+    {896,   3295},
+    {977,   3292},
+    {978,   3291},
+    {978,   3290},
+    {977,   3290},
+    {980,   3289},
+    {980,   3288},
+    {980,   3285},
+    {980,   3285},
+    {981,   3284},
+};
 
 // T2 25C
-R_PROFILE_STRUC r_profile_t2[] =
-{
-               {145,   4175},
-               {145,   4152},
-               {147,   4133},
-               {147,   4115},
-               {148,   4098},
-               {150,   4083},
-               {153,   4069},
-               {155,   4054},
-               {157,   4037},
-               {157,   4020},
-               {160,   4005},
-               {165,   3993},
-               {165,   3981},
-               {168,   3971},
-               {170,   3959},
-               {172,   3948},
-               {173,   3937},
-               {177,   3927},
-               {177,   3917},
-               {178,   3907},
-               {178,   3897},
-               {177,   3886},
-               {175,   3875},
-               {167,   3861},
-               {160,   3848},
-               {153,   3836},
-               {150,   3826},
-               {150,   3818},
-               {148,   3811},
-               {148,   3805},
-               {148,   3800},
-               {150,   3795},
-               {152,   3791},
-               {153,   3788},
-               {152,   3783},
-               {153,   3780},
-               {155,   3777},
-               {157,   3775},
-               {157,   3773},
-               {157,   3771},
-               {157,   3769},
-               {157,   3766},
-               {155,   3762},
-               {152,   3755},
-               {150,   3748},
-               {148,   3741},
-               {152,   3733},
-               {148,   3721},
-               {152,   3710},
-               {147,   3694},
-               {147,   3689},
-               {148,   3686},
-               {158,   3684},
-               {170,   3679},
-               {162,   3638},
-               {165,   3544},
-               {190,   3381},
-               {188,   3312},
-               {168,   3301},
-               {162,   3295},
-               {155,   3293},
-               {153,   3291},
-               {152,   3290},
-               {152,   3288},
-               {148,   3288},
-               {145,   3285},
-               {147,   3285},
-               {143,   3284},
-               {140,   3283},
-               {138,   3282},
-               {138,   3283},
-               {138,   3282},
-               {138,   3281},
-               {137,   3280},
-               {137,   3280},
-               {137,   3280},
-               {135,   3277},
-               {132,   3277},
-               {133,   3278},
-               {135,   3279},
-               {137,   3278},
-               {132,   3276},
-               {138,   3275},
-               {133,   3275},
-               {133,   3274},
-               {133,   3274},
+R_PROFILE_STRUC r_profile_t2[] = {
+    {120,   4333},
+    {120,   4314},
+    {123,   4296},
+    {125,   4280},
+    {125,   4263},
+    {125,   4247},
+    {125,   4231},
+    {125,   4215},
+    {125,   4199},
+    {125,   4183},
+    {127,   4168},
+    {127,   4153},
+    {127,   4137},
+    {130,   4123},
+    {128,   4107},
+    {132,   4093},
+    {132,   4079},
+    {133,   4068},
+    {138,   4058},
+    {138,   4040},
+    {138,   4020},
+    {138,   4004},
+    {142,   3993},
+    {143,   3984},
+    {147,   3974},
+    {147,   3963},
+    {148,   3951},
+    {147,   3938},
+    {143,   3923},
+    {135,   3906},
+    {130,   3891},
+    {125,   3879},
+    {123,   3868},
+    {125,   3860},
+    {123,   3851},
+    {125,   3844},
+    {125,   3837},
+    {127,   3830},
+    {128,   3824},
+    {128,   3818},
+    {130,   3812},
+    {132,   3807},
+    {135,   3803},
+    {135,   3797},
+    {137,   3793},
+    {140,   3790},
+    {148,   3786},
+    {152,   3782},
+    {155,   3778},
+    {157,   3774},
+    {152,   3769},
+    {153,   3765},
+    {153,   3760},
+    {155,   3754},
+    {152,   3747},
+    {155,   3742},
+    {157,   3734},
+    {157,   3724},
+    {162,   3715},
+    {162,   3702},
+    {163,   3693},
+    {163,   3691},
+    {168,   3689},
+    {178,   3687},
+    {188,   3685},
+    {203,   3677},
+    {205,   3638},
+    {228,   3567},
+    {253,   3464},
+    {265,   3359},
+    {223,   3333},
+    {200,   3319},
+    {188,   3312},
+    {182,   3307},
+    {173,   3304},
+    {170,   3300},
+    {160,   3295},
+    {157,   3292},
+    {153,   3291},
+    {153,   3290},
+    {153,   3290},
+    {153,   3289},
+    {152,   3288},
+    {153,   3285},
+    {147,   3285},
+    {145,   3284},
 };
 
 // T3 50C
-R_PROFILE_STRUC r_profile_t3[] =
-{
-               {145,   4175},
-               {145,   4152},
-               {147,   4133},
-               {147,   4115},
-               {148,   4098},
-               {150,   4083},
-               {153,   4069},
-               {155,   4054},
-               {157,   4037},
-               {157,   4020},
-               {160,   4005},
-               {165,   3993},
-               {165,   3981},
-               {168,   3971},
-               {170,   3959},
-               {172,   3948},
-               {173,   3937},
-               {177,   3927},
-               {177,   3917},
-               {178,   3907},
-               {178,   3897},
-               {177,   3886},
-               {175,   3875},
-               {167,   3861},
-               {160,   3848},
-               {153,   3836},
-               {150,   3826},
-               {150,   3818},
-               {148,   3811},
-               {148,   3805},
-               {148,   3800},
-               {150,   3795},
-               {152,   3791},
-               {153,   3788},
-               {152,   3783},
-               {153,   3780},
-               {155,   3777},
-               {157,   3775},
-               {157,   3773},
-               {157,   3771},
-               {157,   3769},
-               {157,   3766},
-               {155,   3762},
-               {152,   3755},
-               {150,   3748},
-               {148,   3741},
-               {152,   3733},
-               {148,   3721},
-               {152,   3710},
-               {147,   3694},
-               {147,   3689},
-               {148,   3686},
-               {158,   3684},
-               {170,   3679},
-               {162,   3638},
-               {165,   3544},
-               {190,   3381},
-               {188,   3312},
-               {168,   3301},
-               {162,   3295},
-               {155,   3293},
-               {153,   3291},
-               {152,   3290},
-               {152,   3288},
-               {148,   3288},
-               {145,   3285},
-               {147,   3285},
-               {143,   3284},
-               {140,   3283},
-               {138,   3282},
-               {138,   3283},
-               {138,   3282},
-               {138,   3281},
-               {137,   3280},
-               {137,   3280},
-               {137,   3280},
-               {135,   3277},
-               {132,   3277},
-               {133,   3278},
-               {135,   3279},
-               {137,   3278},
-               {132,   3276},
-               {138,   3275},
-               {133,   3275},
-               {133,   3274},
-               {133,   3274},
+R_PROFILE_STRUC r_profile_t3[] = {
+    {120,   4333},
+    {120,   4314},
+    {123,   4296},
+    {125,   4280},
+    {125,   4263},
+    {125,   4247},
+    {125,   4231},
+    {125,   4215},
+    {125,   4199},
+    {125,   4183},
+    {127,   4168},
+    {127,   4153},
+    {127,   4137},
+    {130,   4123},
+    {128,   4107},
+    {132,   4093},
+    {132,   4079},
+    {133,   4068},
+    {138,   4058},
+    {138,   4040},
+    {138,   4020},
+    {138,   4004},
+    {142,   3993},
+    {143,   3984},
+    {147,   3974},
+    {147,   3963},
+    {148,   3951},
+    {147,   3938},
+    {143,   3923},
+    {135,   3906},
+    {130,   3891},
+    {125,   3879},
+    {123,   3868},
+    {125,   3860},
+    {123,   3851},
+    {125,   3844},
+    {125,   3837},
+    {127,   3830},
+    {128,   3824},
+    {128,   3818},
+    {130,   3812},
+    {132,   3807},
+    {135,   3803},
+    {135,   3797},
+    {137,   3793},
+    {140,   3790},
+    {148,   3786},
+    {152,   3782},
+    {155,   3778},
+    {157,   3774},
+    {152,   3769},
+    {153,   3765},
+    {153,   3760},
+    {155,   3754},
+    {152,   3747},
+    {155,   3742},
+    {157,   3734},
+    {157,   3724},
+    {162,   3715},
+    {162,   3702},
+    {163,   3693},
+    {163,   3691},
+    {168,   3689},
+    {178,   3687},
+    {188,   3685},
+    {203,   3677},
+    {205,   3638},
+    {228,   3567},
+    {253,   3464},
+    {265,   3359},
+    {223,   3333},
+    {200,   3319},
+    {188,   3312},
+    {182,   3307},
+    {173,   3304},
+    {170,   3300},
+    {160,   3295},
+    {157,   3292},
+    {153,   3291},
+    {153,   3290},
+    {153,   3290},
+    {153,   3289},
+    {152,   3288},
+    {153,   3285},
+    {147,   3285},
+    {145,   3284},
 };
 
 // r-table profile for actual temperature. The size should be the same as T1, T2 and T3
-R_PROFILE_STRUC r_profile_temperature[] =
-{
-               {0,   0},
-               {0,   0},
-               {0,   0},
-               {0,   0},
-               {0,   0},
-               {0,   0},
-               {0,   0},
-               {0,   0},
-               {0,   0},
-               {0,   0},
-               {0,   0},
-               {0,   0},
-               {0,   0},
-               {0,   0},
-               {0,   0},
-               {0,   0},
-               {0,   0},
-               {0,   0},
-               {0,   0},
-               {0,   0},
-               {0,   0},
-               {0,   0},
-               {0,   0},
-               {0,   0},
-               {0,   0},
-               {0,   0},
-               {0,   0},
-               {0,   0},
-               {0,   0},
-               {0,   0},
-               {0,   0},
-               {0,   0},
-               {0,   0},
-               {0,   0},
-               {0,   0},
-               {0,   0},
-               {0,   0},
-               {0,   0},
-               {0,   0},
-               {0,   0},
-               {0,   0},
-               {0,   0},
-               {0,   0},
-               {0,   0},
-               {0,   0},
-               {0,   0},
-               {0,   0},
-               {0,   0},
-               {0,   0},
-               {0,   0},
-               {0,   0},
-               {0,   0},
-               {0,   0},
-               {0,   0},
-               {0,   0},
-               {0,   0},
-               {0,   0},
-               {0,   0},
-               {0,   0},
-               {0,   0},
-               {0,   0},
-               {0,   0},
-               {0,   0},
-               {0,   0},
-               {0,   0},
-               {0,   0},
-               {0,   0},
-               {0,   0},
-               {0,   0},
-               {0,   0},
-               {0,   0},
-               {0,   0},
-               {0,   0},
-               {0,   0},
-               {0,   0},
-               {0,   0},
-               {0,   0},
-               {0,   0},
-               {0,   0},
-               {0,   0},
-               {0,   0},
-               {0,   0},
-               {0,   0},
-               {0,   0},
-               {0,   0},
-               {0,   0},
+R_PROFILE_STRUC r_profile_temperature[] = {
+    {0,   0},
+    {0,   0},
+    {0,   0},
+    {0,   0},
+    {0,   0},
+    {0,   0},
+    {0,   0},
+    {0,   0},
+    {0,   0},
+    {0,   0},
+    {0,   0},
+    {0,   0},
+    {0,   0},
+    {0,   0},
+    {0,   0},
+    {0,   0},
+    {0,   0},
+    {0,   0},
+    {0,   0},
+    {0,   0},
+    {0,   0},
+    {0,   0},
+    {0,   0},
+    {0,   0},
+    {0,   0},
+    {0,   0},
+    {0,   0},
+    {0,   0},
+    {0,   0},
+    {0,   0},
+    {0,   0},
+    {0,   0},
+    {0,   0},
+    {0,   0},
+    {0,   0},
+    {0,   0},
+    {0,   0},
+    {0,   0},
+    {0,   0},
+    {0,   0},
+    {0,   0},
+    {0,   0},
+    {0,   0},
+    {0,   0},
+    {0,   0},
+    {0,   0},
+    {0,   0},
+    {0,   0},
+    {0,   0},
+    {0,   0},
+    {0,   0},
+    {0,   0},
+    {0,   0},
+    {0,   0},
+    {0,   0},
+    {0,   0},
+    {0,   0},
+    {0,   0},
+    {0,   0},
+    {0,   0},
+    {0,   0},
+    {0,   0},
+    {0,   0},
+    {0,   0},
+    {0,   0},
+    {0,   0},
+    {0,   0},
+    {0,   0},
+    {0,   0},
+    {0,   0},
+    {0,   0},
+    {0,   0},
+    {0,   0},
+    {0,   0},
+    {0,   0},
+    {0,   0},
+    {0,   0},
+    {0,   0},
+    {0,   0},
+    {0,   0},
+    {0,   0},
+    {0,   0},
+    {0,   0},
+    {0,   0},
+    {0,   0},
+    {0,   0},
 };
 
 // ============================================================
index ca1a98df01cc5e698552c3258ce429fda91000b6..a0f3764733dbef6e79a6e6c982e9eacb347257f3 100644 (file)
@@ -8,10 +8,16 @@
 
 /* Battery Temperature Protection */
 #define MTK_TEMPERATURE_RECHARGE_SUPPORT
-#define MAX_CHARGE_TEMPERATURE  50
-#define MAX_CHARGE_TEMPERATURE_MINUS_X_DEGREE  47
-#define MIN_CHARGE_TEMPERATURE  0
-#define MIN_CHARGE_TEMPERATURE_PLUS_X_DEGREE   6
+#define MAX_CHARGE_TEMPERATURE  55
+#define MAX_CHARGE_TEMPERATURE_MINUS_X_DEGREE  50 //47 Fixed to 50 degree for according to  standard
+#define MIN_CHARGE_TEMPERATURE  2
+#define MIN_CHARGE_TEMPERATURE_PLUS_X_DEGREE   4  //6 Fixed to 2 degree accoding to TCL standard
+#define MAX_LIMIT_CHARGE_TEMPERATURE    45
+#define MIN_LIMIT_CHARGE_TEMPERATURE    43
+/* [PLATFORM]-ADD-BEGIN by TCTSZ leo.guo, 06/09/2015,  BATTERY Notify for NTC*/
+#define MAX_RAISING_CHARGE_TEMPERATURE    58
+#define MIN_DROPPING_CHARGE_TEMPERATURE   -18
+/* [PLATFORM]-ADD-END by TCTSZ leo.guo*/
 #define ERR_CHARGE_TEMPERATURE  0xFF
 
 /* Linear Charging Threshold */
@@ -27,7 +33,7 @@
 #define USB_CHARGER_CURRENT_CONFIGURED         CHARGE_CURRENT_500_00_MA        // 500mA
 
 #define USB_CHARGER_CURRENT                                    CHARGE_CURRENT_500_00_MA        //500mA
-#define AC_CHARGER_CURRENT                                 CHARGE_CURRENT_800_00_MA
+#define AC_CHARGER_CURRENT                                 CHARGE_CURRENT_1200_00_MA
 #define NON_STD_AC_CHARGER_CURRENT                     CHARGE_CURRENT_500_00_MA
 #define CHARGING_HOST_CHARGER_CURRENT       CHARGE_CURRENT_650_00_MA
 #define APPLE_0_5A_CHARGER_CURRENT          CHARGE_CURRENT_500_00_MA
@@ -40,7 +46,9 @@
 #define BATTERY_AVERAGE_SIZE   30
 
 /* charger error check */
-//#define BAT_LOW_TEMP_PROTECT_ENABLE         // stop charging if temp < MIN_CHARGE_TEMPERATURE
+/* [PLATFORM]-Add-BEGIN by TCTSZ.leo.guo, 04/15/2015,  modify ntc temperature function */
+#define BAT_LOW_TEMP_PROTECT_ENABLE         // stop charging if temp < MIN_CHARGE_TEMPERATURE
+/* [PLATFORM]-Add-END by TCTSZ.leo.guo */
 #define V_CHARGER_ENABLE 0                             // 1:ON , 0:OFF 
 #define V_CHARGER_MAX 6500                             // 6.5 V
 #define V_CHARGER_MIN 4400                             // 4.4 V
 #endif
 
 /* High battery support */
-//#define HIGH_BATTERY_VOLTAGE_SUPPORT
+#define HIGH_BATTERY_VOLTAGE_SUPPORT
 
 /* Disable Battery check for HQA */
 #ifdef MTK_DISABLE_POWER_ON_OFF_VOLTAGE_LIMITATION
 
 
 //#define MTK_WIRELESS_CHARGER_SUPPORT 1
-
+/* [PLATFORM]-Add-BEGIN by TCTSZ.leo.guo, 04/15/2015,  modify ntc temperature function */
+#define MTK_BATTERY_PROTECT_FEATURE
+/* [PLATFORM]-Add-END by TCTSZ.leo.guo */
 /* Pump Express support (fast charging) */
 #ifdef CONFIG_MTK_PUMP_EXPRESS_SUPPORT
 #define TA_START_VCHR_TUNUNG_VOLTAGE   3400
index 365e8ec649c5976e86b4fdbf9c51d0e7075d5794..73adbcfb359e59d70a9d98c7ee7e856fea42fab5 100644 (file)
@@ -93,6 +93,8 @@ extern char tpd_firmware_version_val[5];
 extern int tpd_config_version;
 extern int tpd_x_line;
 extern int tpd_y_line;
+extern u8 tpd_sensor_id;
+
 int gtp_autotool_setting;
 EXPORT_SYMBOL(gtp_autotool_setting);
 extern struct tpd_device *tpd;
@@ -232,8 +234,12 @@ struct input_dev *pen_dev;
 #if GTP_COMPATIBLE_MODE
 u8 driver_num = 0;
 u8 sensor_num = 0;
-u8 gtp_ref_retries = 0;
-u8 gtp_clk_retries = 0;
+/*[PLATFORM]-Add-BEGIN by falin.luo@tcl.com 2015/4/29*/
+/*change counter data type to u16, because GTP_CHK_FS_MNT_MAX is 300 */
+u16 gtp_ref_retries = 0;
+u16 gtp_clk_retries = 0;
+static u16 is_data_mounted = 0;
+/*[PLATFORM]-Add-NED   by falin.luo@tcl.com 2015/4/29*/
 CHIP_TYPE_T gtp_chip_type = CHIP_TYPE_GT9;
 u8 rqst_processing = 0;
 u8 is_950 = 0;
@@ -1220,6 +1226,7 @@ static s32 gtp_init_panel(struct i2c_client *client)
 
     cfg_len = cfg_info_len[sensor_id];
     tpd_config_version= send_cfg_buf[sensor_id][0];
+    tpd_sensor_id = sensor_id;
     GTP_INFO("CTP_CONFIG_GROUP%d used, config length: %d", sensor_id + 1, cfg_len);
 
     if (cfg_len < GTP_CONFIG_MIN_LENGTH)
@@ -1577,11 +1584,12 @@ static u8 gtp_bak_ref_proc(struct i2c_client *client, u8 mode)
 
     //check file-system mounted
     GTP_DEBUG("[gtp_bak_ref_proc]Waiting for FS %d", gtp_ref_retries);
-    if (gup_check_fs_mounted("/data") == FAIL)
+    if (/*gup_check_fs_mounted("/data") == FAIL*/!is_data_mounted)/*[PLATFORM]-MOD by falin.luo@tcl.com 2015/4/29*/
     {
         GTP_DEBUG("[gtp_bak_ref_proc]/data not mounted");
         if(gtp_ref_retries++ < GTP_CHK_FS_MNT_MAX)
         {
+               msleep(100);/*[PLATFORM]-ADD by falin.luo@tcl.com 2015/4/29*/
             return FAIL;
         }
     }
@@ -1811,12 +1819,13 @@ static u8 gtp_main_clk_proc(struct i2c_client *client)
     u8  gtp_clk_buf[6] = {0};
     struct file *flp = NULL;
 
-    GTP_DEBUG("[gtp_main_clk_proc]Waiting for FS %d", gtp_ref_retries);
-    if (gup_check_fs_mounted("/data") == FAIL)
+    GTP_DEBUG("[gtp_main_clk_proc]Waiting for FS %d", gtp_clk_retries);/*[PLATFORM]-MOD by falin.luo@tcl.com 2015/4/29*/
+    if (/*gup_check_fs_mounted("/data") == FAIL*/!is_data_mounted)/*[PLATFORM]-MOD by falin.luo@tcl.com 2015/4/29*/
     {
         GTP_DEBUG("[gtp_main_clk_proc]/data not mounted");
         if(gtp_clk_retries++ < GTP_CHK_FS_MNT_MAX)
         {
+               msleep(100);/*[PLATFORM]-ADD by falin.luo@tcl.com 2015/4/29*/
             return FAIL;
         }
         else
@@ -1951,8 +1960,10 @@ u8 gtp_hopping_proc(struct i2c_client *client, s32 mode)
     s32 ret = 0;
 
     GTP_DEBUG("Store hopping data, wait for /data mounted.");
-
-    ret = gup_check_fs_mounted("/data");
+       /*[PLATFORM]-MOD-BEGIN by falin.luo@tcl.com 2015/4/29*/
+//    ret = gup_check_fs_mounted("/data");
+       ret = is_data_mounted ? SUCCESS : FAIL;
+       /*[PLATFORM]-MOD-END by falin.luo@tcl.com 2015/4/29*/
 
     if (FAIL == ret)
     {
@@ -2495,12 +2506,43 @@ static ssize_t cfg_load_enable_store(struct device *dev,
        return count;
 }
 static ssize_t cfg_load_enable_show(struct device *dev,
+                    struct device_attribute *attr,
+                        char *buf)
+{
+       return 1;
+}
+static  DEVICE_ATTR(cfg_load_enable, S_IRUGO|S_IWUSR, cfg_load_enable_show, cfg_load_enable_store);
+
+/*[PLATFORM]-Add-BEGIN by falin.luo@tcl.com 2015/4/29*/
+/*sys interface to get and set the data partition mount status*/
+#ifdef GTP_COMPATIBLE_MODE
+
+static ssize_t data_is_mount_store(struct device *dev,
                     struct device_attribute *attr,
                         const char *buf, size_t count)
 {
+       GTP_INFO("enter %s", __func__);
+
+       
+       is_data_mounted = ((buf[0] == '1') ? 1 : 0);
+
+       GTP_INFO("is_data_mount = %d, buf = %s", is_data_mounted, buf);
+
        return count;
 }
-static  DEVICE_ATTR(cfg_load_enable, S_IRUGO|S_IWUSR, cfg_load_enable_show, cfg_load_enable_store);
+static ssize_t data_is_mount_show(struct device *dev,
+                    struct device_attribute *attr,
+                        char *buf)
+{
+       return snprintf(buf, PAGE_SIZE, "is_data_mounted = %d\n", is_data_mounted);
+}
+
+static DEVICE_ATTR(data_is_mount, 0644, data_is_mount_show, data_is_mount_store);
+
+#endif
+
+/*[PLATFORM]-Add-END by falin.luo@tcl.com 2015/4/29*/
+
 
 static struct miscdevice cfg_misc_device =
 {
@@ -2525,9 +2567,10 @@ static void buttons_timer_function(unsigned long data)
 static s32 tpd_i2c_probe(struct i2c_client *client, const struct i2c_device_id *id)
 {
     s32 err = 0;
+#if 0
     s32 ret = 0;
-
     u16 version_info;
+#endif
 #if GTP_HAVE_TOUCH_KEY
     s32 idx = 0;
 #endif
@@ -2663,6 +2706,12 @@ static s32 tpd_i2c_probe(struct i2c_client *client, const struct i2c_device_id *
     tpd_load_status = 1;
 #endif
        misc_register(&cfg_misc_device);
+/*[PLATFORM]-Add-BEGIN by falin.luo@tcl.com 2015/4/29*/
+#ifdef GTP_COMPATIBLE_MODE
+       device_create_file(cfg_misc_device.this_device, &dev_attr_data_is_mount);
+#endif
+/*[PLATFORM]-Add-END by falin.luo@tcl.com 2015/4/29*/
+
        device_create_file(cfg_misc_device.this_device, &dev_attr_cfg_load_enable);
     tpd_load_status = 1;
     return 0;
index ccea7b056d7699bd28f5ca7840012609a409c68d..7651b772f69a7f0198e5a2627304bd809f0f04f5 100644 (file)
@@ -38,11 +38,14 @@ char tpd_firmware_version_val[5];
 int tpd_config_version;
 int tpd_x_line;
 int tpd_y_line;
+u8 tpd_sensor_id;
 EXPORT_SYMBOL(gesture_value);
 EXPORT_SYMBOL(tpd_firmware_version_val);
 EXPORT_SYMBOL(tpd_config_version);
 EXPORT_SYMBOL(tpd_x_line);
 EXPORT_SYMBOL(tpd_y_line);
+EXPORT_SYMBOL(tpd_sensor_id);
+
 
 
 
@@ -291,7 +294,7 @@ static ssize_t firmware_version_val_show(struct device* dev, struct device_attri
        return snprintf(buf, PAGE_SIZE, "%s\n", tpd_firmware_version_val);
 
 }
-static ssize_t firmware_version_val_store(struct device* dev, struct device_attribute* attr, char* buf, size_t count) {
+static ssize_t firmware_version_val_store(struct device* dev, struct device_attribute* attr, const char* buf, size_t count) {
         
        return  count;
 
@@ -301,7 +304,7 @@ static ssize_t config_version_val_show(struct device* dev, struct device_attribu
        return snprintf(buf, PAGE_SIZE, "%x\n", tpd_config_version);
 
 }
-static ssize_t config_version_val_store(struct device* dev, struct device_attribute* attr, char* buf,size_t count) {
+static ssize_t config_version_val_store(struct device* dev, struct device_attribute* attr, const char* buf,size_t count) {
         
        return count;
 
@@ -311,7 +314,7 @@ static ssize_t tpd_x_line_val_show(struct device* dev, struct device_attribute*
        return snprintf(buf, PAGE_SIZE, "%d\n", tpd_x_line);
 
 }
-static ssize_t tpd_x_line_val_store(struct device* dev, struct device_attribute* attr, char* buf,size_t count) {
+static ssize_t tpd_x_line_val_store(struct device* dev, struct device_attribute* attr, const char* buf,size_t count) {
         
        return count;
 
@@ -321,18 +324,27 @@ static ssize_t tpd_y_line_val_show(struct device* dev, struct device_attribute*
        return snprintf(buf, PAGE_SIZE, "%d\n", tpd_y_line);
 
 }
-static ssize_t tpd_y_line_val_store(struct device* dev, struct device_attribute* attr, char* buf,size_t count) {
+static ssize_t tpd_y_line_val_store(struct device* dev, struct device_attribute* attr, const char* buf,size_t count) {
         
        return count;
 
 }
 
+static ssize_t sensor_id_val_show(struct device* dev, struct device_attribute* attr, char* buf) {
+       return snprintf(buf, PAGE_SIZE, "%x\n", tpd_sensor_id);
+
+}
+static ssize_t sensor_id_val_store(struct device* dev, struct device_attribute* attr, const char* buf,size_t count) {
+       return count;
+}
+
 
 static DEVICE_ATTR(gesture_val, S_IRUGO | S_IWUSR, hello_val_show, hello_val_store);
 static DEVICE_ATTR(firmware_version, S_IRUGO | S_IWUSR, firmware_version_val_show, firmware_version_val_store);
 static DEVICE_ATTR(cfg_version, S_IRUGO | S_IWUSR, config_version_val_show, config_version_val_store);
 static DEVICE_ATTR(tpd_xline, S_IRUGO | S_IWUSR, tpd_x_line_val_show, tpd_x_line_val_store);
 static DEVICE_ATTR(tpd_yline, S_IRUGO | S_IWUSR, tpd_y_line_val_show, tpd_y_line_val_store);
+static DEVICE_ATTR(sensor_id, S_IRUGO | S_IWUSR, sensor_id_val_show, sensor_id_val_store);
 
 
 
@@ -490,7 +502,9 @@ static int tpd_probe(struct platform_device *pdev) {
      if(device_create_file(&pdev->dev, &dev_attr_tpd_yline) < 0) {
             printk(KERN_ALERT"caoyang creat attribute val.");                           
      }
-
+     if(device_create_file(&pdev->dev, &dev_attr_sensor_id) < 0) {
+         printk(KERN_ERR"create sensor_id sys file failed!\n");
+     }
        
     /* init R-Touch */
     #if 0
index 017e687105519eb135a80623873ef781f82c4202..2b573835dab053e23ad824340f4388a68fc417df 100644 (file)
@@ -165,36 +165,45 @@ extern s32 gtp_i2c_read_dbl_check(struct i2c_client *client, u16 addr, u8 *rxbuf
 \r
 // TODO: define your config for Sensor_ID == 3 here, if needed\r
 #define CTP_CFG_GROUP4 {\\r
-    }\r
+0x45,0x20,0x03,0x00,0x05,0x0A,0x34,0x02,0x01,0x08,0x19,0x0A,0x50,0x41,0x03,0x05,\
+0x00,0x00,0x00,0x00,0x33,0x12,0x04,0x14,0x16,0x1A,0x14,0x8C,0x2E,0x0E,0x3F,0x41,\
+0xD3,0x07,0x00,0x00,0x00,0xBA,0x02,0x11,0x00,0x01,0x00,0x18,0x00,0x00,0x00,0x00,\
+0x00,0x00,0x00,0x1C,0x6C,0x94,0xC5,0x02,0x00,0x00,0x00,0x04,0xE3,0x20,0x00,0xB2,\
+0x2A,0x00,0x8E,0x37,0x00,0x73,0x48,0x00,0x60,0x5F,0x00,0x5F,0x00,0x00,0x00,0x00,\
+0x00,0x00,0x00,0x00,0x00,0x00,0x60,0x40,0x33,0x11,0x03,0x08,0x08,0x0F,0x1F,0x00,\
+0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x14,0x0F,0x0A,0x00,0x00,0x00,0x00,\
+0x02,0x04,0x06,0x08,0x0A,0x0C,0x0E,0x10,0x12,0x14,0x16,0x18,0x1A,0x1C,0x00,0x00,\
+0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x14,0x13,\
+0x12,0x10,0x0F,0x0C,0x0A,0x08,0x06,0x04,0x02,0x00,0x16,0x18,0x1C,0x1D,0x1E,0x1F,\
+0x20,0x21,0x22,0x24,0x26,0x28,0x29,0x2A,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,\
+0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,\
+0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,\
+0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,\
+0x00,0x00,0x0F,0x01\
+}
 \r
 // TODO: define your config for Sensor_ID == 4 here, if needed\r
 #define CTP_CFG_GROUP5 {\\r
 }\r
 \r
 // TODO: define your config for Sensor_ID == 5 here, if needed\r
-#define CTP_CFG_GROUP6 {\\r
-0x41,0x20,0x03,0x00,0x05,0x0A,0x05,0x20,0x01,0x0F,0x1E,\\r
-0x0F,0x50,0x32,0x03,0x05,0x00,0x00,0x00,0x00,0x00,0x00,\\r
-0x00,0x00,0x00,0x00,0x00,0x8C,0x2E,0x0E,0x36,0x38,0xD3,\\r
-0x07,0x00,0x00,0x02,0x9B,0x04,0x1D,0x00,0x01,0x00,0x00,\\r
-0x00,0x03,0x00,0x00,0x00,0x00,0x00,0x1E,0x66,0x94,0xC5,\\r
-0x02,0x08,0x00,0x00,0x04,0xC1,0x22,0x00,0x9C,0x2B,0x00,\\r
-0x7D,0x37,0x00,0x65,0x47,0x00,0x54,0x5A,0x00,0x54,0x00,\\r
-0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,\\r
-0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,\\r
-0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,\\r
-0x00,0x00,0x02,0x04,0x06,0x08,0x0A,0x0C,0x0E,0x10,0x12,\\r
-0x14,0x16,0x18,0x1A,0x1C,0x00,0x00,0x00,0x00,0x00,0x00,\\r
-0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x14,\\r
-0x13,0x12,0x10,0x0F,0x0C,0x0A,0x08,0x06,0x04,0x02,0x00,\\r
-0x16,0x18,0x1C,0x1D,0x1E,0x1F,0x20,0x21,0x22,0x24,0x26,\\r
-0x28,0x29,0x2A,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,\\r
-0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,\\r
-0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,\\r
-0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,\\r
-0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,\\r
-0x00,0x00,0x00,0x00,0x00,0x00,0xB8,0x01 \\r
-}\r
+#define CTP_CFG_GROUP6 {\
+0x49,0x20,0x03,0x00,0x05,0x0A,0x34,0x02,0x01,0x09,0x19,0x0C,0x64,0x3C,0x03,0x05,\
+0x00,0x00,0x00,0x00,0x33,0x12,0x04,0x14,0x16,0x1A,0x14,0x8C,0x2E,0x0E,0x2F,0x31,\
+0xD3,0x07,0x00,0x00,0x01,0xBA,0x02,0x11,0x00,0x09,0x00,0x1F,0x00,0x00,0x00,0x00,\
+0x00,0x00,0x00,0x1C,0x4B,0x94,0xD5,0x03,0x06,0x00,0x00,0x04,0xE7,0x1F,0x00,0xC7,\
+0x25,0x00,0xA6,0x2E,0x00,0x8E,0x38,0x00,0x76,0x44,0x00,0x76,0x00,0x00,0x00,0x00,\
+0x00,0x00,0x00,0x00,0x00,0x00,0x60,0x40,0x33,0x11,0x03,0x08,0x08,0x0F,0x1F,0x00,\
+0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x14,0x0F,0x0A,0x00,0x00,0x00,0x00,\
+0x02,0x04,0x06,0x08,0x0A,0x0C,0x0E,0x10,0x12,0x14,0x16,0x18,0x1A,0x1C,0x00,0x00,\
+0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x14,0x13,\
+0x12,0x10,0x0F,0x0C,0x0A,0x08,0x06,0x04,0x02,0x00,0x16,0x18,0x1C,0x1D,0x1E,0x1F,\
+0x20,0x21,0x22,0x24,0x26,0x28,0x29,0x2A,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,\
+0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,\
+0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,\
+0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,\
+0x00,0x00,0xD4,0x01\
+}
 \r
 // STEP_2(REQUIRED): Customize your I/O ports & I/O operations here\r
 #define TPD_POWER_SOURCE_CUSTOM                        MT6323_POWER_LDO_VGP2// define your power source for tp if needed\r
index 6c9d7054d997a66378d54a8da5057142effc5434..4df2b7834ec8b1c1656af182210329eaa8f1e17c 100644 (file)
@@ -688,7 +688,7 @@ static void *__dma_alloc(struct device *dev, size_t size, dma_addr_t *handle,
 void *arm_dma_alloc(struct device *dev, size_t size, dma_addr_t *handle,
                    gfp_t gfp, struct dma_attrs *attrs)
 {
-       pgprot_t prot = __get_dma_pgprot(attrs, pgprot_kernel);
+       pgprot_t prot = __get_dma_pgprot(attrs, PAGE_KERNEL);
        void *memory;
 
        if (dma_alloc_from_coherent(dev, size, handle, &memory))
@@ -701,7 +701,7 @@ void *arm_dma_alloc(struct device *dev, size_t size, dma_addr_t *handle,
 static void *arm_coherent_dma_alloc(struct device *dev, size_t size,
        dma_addr_t *handle, gfp_t gfp, struct dma_attrs *attrs)
 {
-       pgprot_t prot = __get_dma_pgprot(attrs, pgprot_kernel);
+       pgprot_t prot = __get_dma_pgprot(attrs, PAGE_KERNEL);
        void *memory;
 
        if (dma_alloc_from_coherent(dev, size, handle, &memory))
index cea1594ff933e92e304a6996a4642f18f322487a..47813d562213daf8fb09610368429cbda97c8048 100644 (file)
@@ -315,22 +315,31 @@ out:
 }
 
 static int
-validate_event(struct pmu_hw_events *hw_events,
-              struct perf_event *event)
+validate_event(struct pmu *pmu, struct pmu_hw_events *hw_events,
+                               struct perf_event *event)
 {
-       struct arm_pmu *armpmu = to_arm_pmu(event->pmu);
+       struct arm_pmu *armpmu;
        struct hw_perf_event fake_event = event->hw;
        struct pmu *leader_pmu = event->group_leader->pmu;
 
        if (is_software_event(event))
                return 1;
 
+       /*
+        * Reject groups spanning multiple HW PMUs (e.g. CPU + CCI). The
+        * core perf code won't check that the pmu->ctx == leader->ctx
+        * until after pmu->event_init(event).
+        */
+       if (event->pmu != pmu)
+               return 0;
+
        if (event->pmu != leader_pmu || event->state < PERF_EVENT_STATE_OFF)
                return 1;
 
        if (event->state == PERF_EVENT_STATE_OFF && !event->attr.enable_on_exec)
                return 1;
 
+       armpmu = to_arm_pmu(event->pmu);
        return armpmu->get_event_idx(hw_events, &fake_event) >= 0;
 }
 
@@ -348,15 +357,15 @@ validate_group(struct perf_event *event)
        memset(fake_used_mask, 0, sizeof(fake_used_mask));
        fake_pmu.used_mask = fake_used_mask;
 
-       if (!validate_event(&fake_pmu, leader))
+       if (!validate_event(event->pmu, &fake_pmu, leader))
                return -EINVAL;
 
        list_for_each_entry(sibling, &leader->sibling_list, group_entry) {
-               if (!validate_event(&fake_pmu, sibling))
+               if (!validate_event(event->pmu, &fake_pmu, sibling))
                        return -EINVAL;
        }
 
-       if (!validate_event(&fake_pmu, event))
+       if (!validate_event(event->pmu, &fake_pmu, event))
                return -EINVAL;
 
        return 0;
index 3fa98ff14f0eea5a536dd1bbc159d6161a0c9a0d..95bd98cae19c650cf1600e589473c8accba2d3d3 100644 (file)
@@ -50,7 +50,7 @@ asmlinkage long sys_mmap(unsigned long addr, unsigned long len,
  * The sys_call_table array must be 4K aligned to be accessible from
  * kernel/entry.S.
  */
-void *sys_call_table[__NR_syscalls] __aligned(4096) = {
+void const *sys_call_table[__NR_syscalls] __aligned(4096) = {
        [0 ... __NR_syscalls - 1] = sys_ni_syscall,
 #include <asm/unistd.h>
 };
index 6a21c96c58d17cd23dabd52054b3859dacdfba73..13072bc8b5e76c4bf49e97b032f41b9d0767571c 100644 (file)
@@ -830,6 +830,7 @@ static void disk_seqf_stop(struct seq_file *seqf, void *v)
        if (iter) {
                class_dev_iter_exit(iter);
                kfree(iter);
+               seqf->private = NULL;
        }
 }
 
index 722aa7818c9d34b2c94b313e2faeb2042506a382..16bfc5b80c38d5ad83d5234ed38fc03e13e54b37 100644 (file)
@@ -1364,6 +1364,12 @@ config CRYPTO_LZO
        help
          This is the LZO algorithm.
 
+config CRYPTO_LZ4K
+        tristate "LZ4K compression algorithm"
+        select CRYPTO_ALGAPI
+        help
+          This is the LZ4K algorithm.
+          
 config CRYPTO_842
        tristate "842 compression algorithm"
        depends on CRYPTO_DEV_NX_COMPRESS
index 5d0b869b173f375e849f346d8fad7ae2abf7ab7c..e37954155c133490fadf1dd3999c2c0e895051c1 100644 (file)
@@ -85,6 +85,7 @@ obj-$(CONFIG_CRYPTO_CRC32C) += crc32c.o
 obj-$(CONFIG_CRYPTO_CRC32) += crc32.o
 obj-$(CONFIG_CRYPTO_AUTHENC) += authenc.o authencesn.o
 obj-$(CONFIG_CRYPTO_LZO) += lzo.o
+obj-$(CONFIG_CRYPTO_LZ4K) += lz4kc.o
 obj-$(CONFIG_CRYPTO_842) += 842.o
 obj-$(CONFIG_CRYPTO_RNG2) += rng.o
 obj-$(CONFIG_CRYPTO_RNG2) += krng.o
diff --git a/crypto/lz4kc.c b/crypto/lz4kc.c
new file mode 100644 (file)
index 0000000..219ea2c
--- /dev/null
@@ -0,0 +1,151 @@
+/*
+ * Cryptographic API.
+ *
+ * This program is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU General Public License version 2 as published by
+ * the Free Software Foundation.
+ *
+ * This program is distributed in the hope that it will be useful, but WITHOUT
+ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+ * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License for
+ * more details.
+ *
+ * You should have received a copy of the GNU General Public License along with
+ * this program; if not, write to the Free Software Foundation, Inc., 51
+ * Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
+ *
+ */
+
+#include <linux/init.h>
+#include <linux/module.h>
+#include <linux/crypto.h>
+#include <linux/vmalloc.h>
+#include <linux/lzo.h>
+#include <linux/lz4k.h>
+
+#define malloc(a) kmalloc(a, GFP_KERNEL)
+#define free(a) kfree(a)
+
+#if 0
+
+extern int lz4k_compress_ubifs(const unsigned char *in, size_t in_len, unsigned char *out,
+        size_t *out_len, void *wrkmem);
+
+extern int lz4k_decompress_ubifs(const unsigned char *in, size_t in_len,
+    unsigned char *out, size_t *out_len);
+
+extern int lz4k_compress(const unsigned char *in, size_t in_len, unsigned char *out,
+        size_t *out_len, void *wrkmem);
+#endif
+struct lz4k_ctx {
+       void *lz4k_comp_mem;
+};
+
+static int lz4kc_init(struct crypto_tfm *tfm)
+{
+       struct lz4k_ctx *ctx = crypto_tfm_ctx(tfm);
+
+       ctx->lz4k_comp_mem = vmalloc(LZO1X_MEM_COMPRESS);
+       if (!ctx->lz4k_comp_mem)
+               return -ENOMEM;
+
+       return 0;
+}
+
+static void lz4kc_exit(struct crypto_tfm *tfm)
+{
+       struct lz4k_ctx *ctx = crypto_tfm_ctx(tfm);
+
+       vfree(ctx->lz4k_comp_mem);
+}
+
+static int lz4kc_compress(struct crypto_tfm *tfm, const u8 *src,
+                           unsigned int slen, u8 *dst, unsigned int *dlen)
+{
+
+    struct lz4k_ctx *ctx = crypto_tfm_ctx(tfm);
+    //static size_t in_size = 0, out_size = 0;
+    size_t tmp_len = *dlen; /* size_t(ulong) <-> uint on 64 bit */
+    int err;
+
+      static int count = 0;
+
+    //printk("lz4k_compress 2 count = %d\r\n", count);
+
+       count++;
+       
+
+    err = lz4k_compress(src, slen, dst, &tmp_len, ctx->lz4k_comp_mem);
+       //err = lzo1x_1_compress(src, slen, dst, &tmp_len, ctx->lz4k_comp_mem);
+
+
+    if (err != LZO_E_OK)
+        return -EINVAL;
+#if 0
+    if (count%10 == 0)
+    {
+         in_size += slen;
+         out_size += tmp_len;
+         printk("lz4k_compress_ubifs result in_size = %d, out_size = %d \n", in_size,out_size);
+    }
+#endif 
+    //printk("lz4k_compress result in_size = %d, out_size = %d \n", in_size,out_size);
+    //printk("lz4k_compress result slen = %d, tmp_len = %d \n", slen,tmp_len);
+
+    *dlen = tmp_len;
+    return 0;
+       
+}
+
+static int lz4kc_decompress(struct crypto_tfm *tfm, const u8 *src,
+                             unsigned int slen, u8 *dst, unsigned int *dlen)
+{
+       static int count = 0;
+       int err;
+       size_t tmp_len = *dlen; /* size_t(ulong) <-> uint on 64 bit */
+
+       
+       //printk("lz4k_decompress 2count = %d, *dlen = %d", count,*dlen);
+
+       err = lz4k_decompress_ubifs(src, slen, dst, &tmp_len);
+       //err = lzo1x_decompress_safe(src, slen, dst, &tmp_len);
+
+
+       count++;
+
+       if (err != LZO_E_OK)
+               return -EINVAL;
+
+       *dlen = tmp_len;
+       return 0;       
+
+}
+
+static struct crypto_alg alg = {
+       .cra_name               = "lz4k",
+       .cra_flags              = CRYPTO_ALG_TYPE_COMPRESS,
+       .cra_ctxsize            = sizeof(struct lz4k_ctx),
+       .cra_module             = THIS_MODULE,
+       .cra_list               = LIST_HEAD_INIT(alg.cra_list),
+       .cra_init               = lz4kc_init,
+       .cra_exit               = lz4kc_exit,
+       .cra_u                  = { .compress = {
+       .coa_compress           = lz4kc_compress,
+       .coa_decompress         = lz4kc_decompress } }
+};
+
+static int __init lz4k_mod_init(void)
+{
+       return crypto_register_alg(&alg);
+}
+
+static void __exit lz4k_mod_fini(void)
+{
+       crypto_unregister_alg(&alg);
+}
+
+module_init(lz4k_mod_init);
+module_exit(lz4k_mod_fini);
+
+MODULE_LICENSE("GPL");
+MODULE_DESCRIPTION("LZ77 with 4K Compression Algorithm");
index 81d0e6e1f754101479d95dc5c756498fe3bbc720..8d8f3b68bb90bd5ea592d424acba4db51368562c 100644 (file)
@@ -1148,6 +1148,7 @@ static void hid_input_field(struct hid_device *hid, struct hid_field *field,
                /* Ignore report if ErrorRollOver */
                if (!(field->flags & HID_MAIN_ITEM_VARIABLE) &&
                    value[n] >= min && value[n] <= max &&
+                   value[n] - min < field->maxusage &&
                    field->usage[value[n] - min].hid == HID_UP_KEYBOARD + 1)
                        goto exit;
        }
@@ -1160,11 +1161,13 @@ static void hid_input_field(struct hid_device *hid, struct hid_field *field,
                }
 
                if (field->value[n] >= min && field->value[n] <= max
+                       && field->value[n] - min < field->maxusage
                        && field->usage[field->value[n] - min].hid
                        && search(value, field->value[n], count))
                                hid_process_event(hid, field, &field->usage[field->value[n] - min], 0, interrupt);
 
                if (value[n] >= min && value[n] <= max
+                       && value[n] - min < field->maxusage
                        && field->usage[value[n] - min].hid
                        && search(field->value, value[n], count))
                                hid_process_event(hid, field, &field->usage[value[n] - min], 1, interrupt);
index 18228ad18c73f40201c6b381fbbf3b1ff0f9e756..62a525da9cd3c8d04517c9dea2fc622956dd3740 100644 (file)
@@ -454,6 +454,13 @@ static s32 goodix_tool_write(struct file *filp, const char __user *buff, unsigne
     {
         show_len = 0;
         total_len = 0;
+               if ((cmd_head.data == NULL)
+                   || (cmd_head.data_len >= DATA_LENGTH)
+                   || (cmd_head.data_len >= (len - CMD_HEAD_LENGTH))) {
+                       GTP_ERROR("copy_from_user data out of range.");
+                       return -EINVAL;
+               }
+
         memset(cmd_head.data, 0, cmd_head.data_len + 1);
         memcpy(cmd_head.data, &buff[CMD_HEAD_LENGTH], cmd_head.data_len);
 
index 55ff8656cb578c31b8a47038d181bfedc856d133..70fbd3f6ef2fffeb481bca6a0ce7615d9499dff0 100644 (file)
@@ -508,6 +508,13 @@ static s32 goodix_tool_write(struct file *filp, const char __user *buff, unsigne
     {
         show_len = 0;
         total_len = 0;
+               if ((cmd_head.data == NULL)
+                   || (cmd_head.data_len >= DATA_LENGTH)
+                   || (cmd_head.data_len >= (len - CMD_HEAD_LENGTH))) {
+                       GTP_ERROR("copy_from_user data out of range.");
+                       return -EINVAL;
+               }
+
         memset(cmd_head.data, 0, cmd_head.data_len + 1);
         memcpy(cmd_head.data, &buff[CMD_HEAD_LENGTH], cmd_head.data_len);
         GTP_DEBUG("update firmware, filename: %s", cmd_head.data);
index 55ff8656cb578c31b8a47038d181bfedc856d133..70fbd3f6ef2fffeb481bca6a0ce7615d9499dff0 100644 (file)
@@ -508,6 +508,13 @@ static s32 goodix_tool_write(struct file *filp, const char __user *buff, unsigne
     {
         show_len = 0;
         total_len = 0;
+               if ((cmd_head.data == NULL)
+                   || (cmd_head.data_len >= DATA_LENGTH)
+                   || (cmd_head.data_len >= (len - CMD_HEAD_LENGTH))) {
+                       GTP_ERROR("copy_from_user data out of range.");
+                       return -EINVAL;
+               }
+
         memset(cmd_head.data, 0, cmd_head.data_len + 1);
         memcpy(cmd_head.data, &buff[CMD_HEAD_LENGTH], cmd_head.data_len);
         GTP_DEBUG("update firmware, filename: %s", cmd_head.data);
index 55ff8656cb578c31b8a47038d181bfedc856d133..70fbd3f6ef2fffeb481bca6a0ce7615d9499dff0 100644 (file)
@@ -508,6 +508,13 @@ static s32 goodix_tool_write(struct file *filp, const char __user *buff, unsigne
     {
         show_len = 0;
         total_len = 0;
+               if ((cmd_head.data == NULL)
+                   || (cmd_head.data_len >= DATA_LENGTH)
+                   || (cmd_head.data_len >= (len - CMD_HEAD_LENGTH))) {
+                       GTP_ERROR("copy_from_user data out of range.");
+                       return -EINVAL;
+               }
+
         memset(cmd_head.data, 0, cmd_head.data_len + 1);
         memcpy(cmd_head.data, &buff[CMD_HEAD_LENGTH], cmd_head.data_len);
         GTP_DEBUG("update firmware, filename: %s", cmd_head.data);
index 55ff8656cb578c31b8a47038d181bfedc856d133..70fbd3f6ef2fffeb481bca6a0ce7615d9499dff0 100644 (file)
@@ -508,6 +508,13 @@ static s32 goodix_tool_write(struct file *filp, const char __user *buff, unsigne
     {
         show_len = 0;
         total_len = 0;
+               if ((cmd_head.data == NULL)
+                   || (cmd_head.data_len >= DATA_LENGTH)
+                   || (cmd_head.data_len >= (len - CMD_HEAD_LENGTH))) {
+                       GTP_ERROR("copy_from_user data out of range.");
+                       return -EINVAL;
+               }
+
         memset(cmd_head.data, 0, cmd_head.data_len + 1);
         memcpy(cmd_head.data, &buff[CMD_HEAD_LENGTH], cmd_head.data_len);
         GTP_DEBUG("update firmware, filename: %s", cmd_head.data);
index db9406bd1386a56d24178ff546ff35b6811e28c2..2aa0ad58e7492cd98cb39305162b35809bc247d3 100644 (file)
@@ -474,6 +474,13 @@ static s32 goodix_tool_write(struct file *filp, const char __user *buff, unsigne
        {
                show_len = 0;
                total_len = 0;
+               if ((cmd_head.data == NULL)
+                   || (cmd_head.data_len >= DATA_LENGTH)
+                   || (cmd_head.data_len >= (len - CMD_HEAD_LENGTH))) {
+                       GTP_ERROR("copy_from_user data out of range.");
+                       return -EINVAL;
+               }
+
                memset(cmd_head.data, 0, cmd_head.data_len + 1);
                memcpy(cmd_head.data, &buff[CMD_HEAD_LENGTH], cmd_head.data_len);
                GTP_DEBUG("update firmware, filename: %s", cmd_head.data);
index 7ebef7d3f39022b714ebc97a63938453094085a9..aad1394649dd7acceacc5e7ae52453f5932025db 100644 (file)
@@ -568,6 +568,13 @@ static s32 goodix_tool_write(struct file *filp, const char __user *buff, unsigne
     {
         show_len = 0;
         total_len = 0;
+               if ((cmd_head.data == NULL)
+                   || (cmd_head.data_len >= DATA_LENGTH)
+                   || (cmd_head.data_len >= (len - CMD_HEAD_LENGTH))) {
+                       GTP_ERROR("copy_from_user data out of range.");
+                       return -EINVAL;
+               }
+
         memset(cmd_head.data, 0, cmd_head.data_len + 1);
         ret = copy_from_user(cmd_head.data, &buff[CMD_HEAD_LENGTH], cmd_head.data_len);
         if (ret)
index d1faccce4287c8467d051670915c4b9bb485a21f..ab5ba2d04f6e0a2adc1faeb3d3860ef877db9814 100644 (file)
@@ -503,6 +503,13 @@ static s32 goodix_tool_write(struct file *filp, const char __user *buff, unsigne
     {
         show_len = 0;
         total_len = 0;
+               if ((cmd_head.data == NULL)
+                   || (cmd_head.data_len >= DATA_LENGTH)
+                   || (cmd_head.data_len >= (len - CMD_HEAD_LENGTH))) {
+                       GTP_ERROR("copy_from_user data out of range.");
+                       return -EINVAL;
+               }
+
         memset(cmd_head.data, 0, cmd_head.data_len + 1);
         memcpy(cmd_head.data, &buff[CMD_HEAD_LENGTH], cmd_head.data_len);
         GTP_DEBUG("update firmware, filename: %s", cmd_head.data);
index d04192ac74d78a51320924a6ff8819f20072a7db..5aa2256cc9d5acfcc16bdf5ebbeb03834e6cfcec 100644 (file)
@@ -577,6 +577,13 @@ static s32 goodix_tool_write(struct file *filp, const char __user *buff, unsigne
     {
         show_len = 0;
         total_len = 0;
+               if ((cmd_head.data == NULL)
+                   || (cmd_head.data_len >= DATA_LENGTH)
+                   || (cmd_head.data_len >= (len - CMD_HEAD_LENGTH))) {
+                       GTP_ERROR("copy_from_user data out of range.");
+                       return -EINVAL;
+               }
+
         memset(cmd_head.data, 0, cmd_head.data_len + 1);
         ret = copy_from_user(cmd_head.data, &buff[CMD_HEAD_LENGTH], cmd_head.data_len);
         if (ret)
index c6f819a92d17c2a7989fbf56f13131e8786b6408..7a5827810454b21dcc0e8d01d64290f92f5cef82 100644 (file)
@@ -566,6 +566,13 @@ static s32 goodix_tool_write(struct file *filp, const char __user *buff, unsigne
     {
         show_len = 0;
         total_len = 0;
+               if ((cmd_head.data == NULL)
+                   || (cmd_head.data_len >= DATA_LENGTH)
+                   || (cmd_head.data_len >= (len - CMD_HEAD_LENGTH))) {
+                       GTP_ERROR("copy_from_user data out of range.");
+                       return -EINVAL;
+               }
+
         memset(cmd_head.data, 0, cmd_head.data_len + 1);
         ret = copy_from_user(cmd_head.data, &buff[CMD_HEAD_LENGTH], cmd_head.data_len);
         if (ret)
index d04192ac74d78a51320924a6ff8819f20072a7db..5aa2256cc9d5acfcc16bdf5ebbeb03834e6cfcec 100644 (file)
@@ -577,6 +577,13 @@ static s32 goodix_tool_write(struct file *filp, const char __user *buff, unsigne
     {
         show_len = 0;
         total_len = 0;
+               if ((cmd_head.data == NULL)
+                   || (cmd_head.data_len >= DATA_LENGTH)
+                   || (cmd_head.data_len >= (len - CMD_HEAD_LENGTH))) {
+                       GTP_ERROR("copy_from_user data out of range.");
+                       return -EINVAL;
+               }
+
         memset(cmd_head.data, 0, cmd_head.data_len + 1);
         ret = copy_from_user(cmd_head.data, &buff[CMD_HEAD_LENGTH], cmd_head.data_len);
         if (ret)
index 6ddac638d72f889a4d97368c5be8b800ed9da8b9..550268efdf0bc7c88343a1f757f146780fa547d7 100644 (file)
@@ -566,6 +566,13 @@ static s32 goodix_tool_write(struct file *filp, const char __user *buff, unsigne
     {
         show_len = 0;
         total_len = 0;
+               if ((cmd_head.data == NULL)
+                   || (cmd_head.data_len >= DATA_LENGTH)
+                   || (cmd_head.data_len >= (len - CMD_HEAD_LENGTH))) {
+                       GTP_ERROR("copy_from_user data out of range.");
+                       return -EINVAL;
+               }
+
         memset(cmd_head.data, 0, cmd_head.data_len + 1);
         memcpy(cmd_head.data, &buff[CMD_HEAD_LENGTH], cmd_head.data_len);
         GTP_DEBUG("update firmware, filename: %s", cmd_head.data);
index 9771cd83c06e2a0d0c49666a36402734a1f493ff..38afc54ef3497ba24556c8ccd2e8020bb177b874 100644 (file)
@@ -1385,11 +1385,12 @@ static int xc2028_set_config(struct dvb_frontend *fe, void *priv_cfg)
         * in order to avoid troubles during device release.
         */
        kfree(priv->ctrl.fname);
+       priv->ctrl.fname = NULL;
        memcpy(&priv->ctrl, p, sizeof(priv->ctrl));
        if (p->fname) {
                priv->ctrl.fname = kstrdup(p->fname, GFP_KERNEL);
                if (priv->ctrl.fname == NULL)
-                       rc = -ENOMEM;
+                       return -ENOMEM;
        }
 
        /*
index d07fc23a8704f917d2de560e96a4349a2e28b53a..17d36c982b32324248261e78cf3cac542650909b 100644 (file)
@@ -10,6 +10,10 @@ ccflags-y += -I$(srctree)/drivers/misc/mediatek/cmdq/$(MTK_PLATFORM) \
 # Enable MET
 ccflags-y += -DMET_USER_EVENT_SUPPORT
 
+ifneq ($(TARGET_BUILD_VARIANT),user)
+ccflags-y += -D_CMDQ_TEST_PROC_
+endif
+
 # secure path
 ifeq ($(strip $(MTK_SEC_VIDEO_PATH_SUPPORT)),yes)
 ifeq ($(strip $(TRUSTONIC_TEE_SUPPORT)),yes)
index 312fb55413750d998fc738fa0025cff65aa5f3f8..d0440b06210d40b7554e28666300203dcbefc831 100644 (file)
@@ -41,6 +41,10 @@ static const struct of_device_id cmdq_of_ids[] = {
 };
 #endif
 
+#define CMDQ_MAX_DUMP_REG_COUNT (2048)
+#define CMDQ_MAX_COMMAND_SIZE  (0x10000)
+#define CMDQ_MAX_WRITE_ADDR_COUNT      (PAGE_SIZE / sizeof(u32))
+
 static dev_t gCmdqDevNo;
 static struct cdev *gCmdqCDev;
 static struct class *gCMDQClass;
@@ -185,6 +189,8 @@ static int cmdq_driver_create_reg_address_buffer(cmdqCommandStruct *pCommand)
        }
 
        /* how many register to dump? */
+       if (kernelRegCount > CMDQ_MAX_DUMP_REG_COUNT || userRegCount > CMDQ_MAX_DUMP_REG_COUNT)
+               return -EINVAL;
        totalRegCount = kernelRegCount + userRegCount;
 
        if (0 == totalRegCount) {
@@ -237,6 +243,7 @@ static void cmdq_driver_process_read_address_request(cmdqReadAddressStruct *req_
        do {
                if (NULL == req_user ||
                    0 == req_user->count ||
+                       req_user->count > CMDQ_MAX_DUMP_REG_COUNT ||
                    NULL == req_user->values || NULL == req_user->dmaAddresses) {
                        CMDQ_ERR("[READ_PA] invalid req_user\n");
                        break;
@@ -364,6 +371,9 @@ static long cmdq_driver_process_command_request(cmdqCommandStruct *pCommand)
                return -EFAULT;
        }
 
+       if (pCommand->regRequest.count > CMDQ_MAX_DUMP_REG_COUNT)
+               return -EINVAL;
+
        /* allocate secure medatata */
        status = cmdq_driver_create_secure_medadata(pCommand);
        if (0 != status) {
@@ -458,6 +468,11 @@ static long cmdq_ioctl(struct file *pFile, unsigned int code, unsigned long para
                        return -EFAULT;
                }
 
+               if (command.regRequest.count > CMDQ_MAX_DUMP_REG_COUNT ||
+                       !command.blockSize ||
+                       command.blockSize > CMDQ_MAX_COMMAND_SIZE)
+                       return -EINVAL;
+
                /* insert private_data for resource reclaim */
                command.privateData = (void *)pFile->private_data;
 
@@ -480,6 +495,9 @@ static long cmdq_ioctl(struct file *pFile, unsigned int code, unsigned long para
                        return -EFAULT;
                }
 
+               if (job.command.blockSize > CMDQ_MAX_COMMAND_SIZE)
+                       return -EINVAL;
+
                /* not support secure path for async ioctl yet */
                if (true == job.command.secData.isSecure) {
                        CMDQ_ERR("not support secure path for CMDQ_IOCTL_ASYNC_JOB_EXEC\n");
@@ -537,6 +555,8 @@ static long cmdq_ioctl(struct file *pFile, unsigned int code, unsigned long para
                        return -EFAULT;
                }
                pTask = (TaskStruct *)(unsigned long)jobResult.hJob;
+               if (pTask->regCount > CMDQ_MAX_DUMP_REG_COUNT)
+                       return -EINVAL;
 
                /* utility service, fill the engine flag. */
                /* this is required by MDP. */
@@ -632,6 +652,13 @@ static long cmdq_ioctl(struct file *pFile, unsigned int code, unsigned long para
                                return -EFAULT;
                        }
 
+                       if (!addrReq.count || addrReq.count > CMDQ_MAX_WRITE_ADDR_COUNT) {
+                               CMDQ_ERR(
+                                       "CMDQ_IOCTL_ALLOC_WRITE_ADDRESS invalid alloc write addr count:%u\n",
+                                       addrReq.count);
+                               return -EINVAL;
+                       }
+
                        status = cmdqCoreAllocWriteAddress(addrReq.count, &paStart);
                        if (0 != status) {
                                CMDQ_ERR
index 240a352fe7ed12959c0a275efdc70565ea4b84a6..ce87908df201ea5628a9c924f71546486f7ea87b 100644 (file)
@@ -29,7 +29,9 @@ static bool gCmdqTestSecure = false;
 
 extern unsigned long msleep_interruptible(unsigned int msecs);
 
+#ifdef _CMDQ_TEST_PROC_
 static struct proc_dir_entry *gCmdqTestProcEntry;
+#endif
 
 extern int32_t cmdq_core_suspend_HW_thread(int32_t thread);
 
@@ -2514,6 +2516,7 @@ static struct file_operations cmdq_fops = {
 
 static int __init cmdq_test_init(void)
 {
+#ifdef _CMDQ_TEST_PROC_
        CMDQ_MSG("cmdq_test_init\n");
 
        /* Mout proc entry for debug */
@@ -2523,17 +2526,19 @@ static int __init cmdq_test_init(void)
                        CMDQ_MSG("cmdq_test_init failed\n");
                }
        }
-
+#endif
        return 0;
 }
 
 static void __exit cmdq_test_exit(void)
 {
+#ifdef _CMDQ_TEST_PROC_
        CMDQ_MSG("cmdq_test_exit\n");
        if (NULL != gCmdqTestProcEntry) {
                proc_remove(gCmdqTestProcEntry);
                gCmdqTestProcEntry = NULL;
        }
+#endif
 }
 module_init(cmdq_test_init);
 module_exit(cmdq_test_exit);
index c96b2086bf408b39143cbb314e13372e48b69a98..8fd67d61c3164cd583ef6832101649ac17a0b774 100644 (file)
@@ -80,6 +80,8 @@ when mtk_wcn_wmt_func_on is called by wifi through rfkill)
 
 #define MAX_GPIO_CTRL_TIME (2000)      /* [FixMe][GeorgeKuo] a temp value */
 
+#define MAX_PATCH_NUM 10
+
 /*******************************************************************************
 *                    E X T E R N A L   R E F E R E N C E S
 ********************************************************************************
index 858aef71b762c65b481625daca4aff30850dbf9d..51c8b6796b09b67d725541d308ebffa8bf0bc24a 100644 (file)
@@ -1163,13 +1163,20 @@ long WMT_unlocked_ioctl(struct file *filp, unsigned int cmd, unsigned long arg)
 
        case WMT_IOCTL_SET_PATCH_NUM:{
                        pAtchNum = arg;
-                       WMT_INFO_FUNC(" get patch num from launcher = %d\n", pAtchNum);
-                       wmt_lib_set_patch_num(pAtchNum);
-                       pPatchInfo = kzalloc(sizeof(WMT_PATCH_INFO) *pAtchNum, GFP_ATOMIC);
+                       if (pAtchNum == 0 || pAtchNum > MAX_PATCH_NUM) {
+                                       WMT_ERR_FUNC("patch num(%d) == 0 or > %d!\n", pAtchNum, MAX_PATCH_NUM);
+                                       iRet = -1;
+                                       break;
+                       }
+
+                       pPatchInfo = kzalloc(sizeof(WMT_PATCH_INFO) * pAtchNum, GFP_ATOMIC);
                        if (!pPatchInfo) {
                                WMT_ERR_FUNC("allocate memory fail!\n");
+                               iRet = -EFAULT;
                                break;
                        }
+                       WMT_INFO_FUNC(" get patch num from launcher = %d\n", pAtchNum);
+                       wmt_lib_set_patch_num(pAtchNum);
                }
                break;
 
index 47cb2837674778345cfbd8e6e4936108969fbffe..54d6428279b4617ccfc0780c5659bcd22f67c25f 100644 (file)
@@ -3197,8 +3197,23 @@ P_SW_RFB_T qmHandleRxPackets(IN P_ADAPTER_T prAdapter, IN P_SW_RFB_T prSwRfbList
             }
 
         }
+#if CFG_SUPPORT_WAPI
                /* Todo:: Move the data class error check here */
-
+               if (prCurrSwRfb->u2PacketLen > ETHER_HEADER_LEN) {
+                       PUINT_8 pc = (PUINT_8) prCurrSwRfb->pvHeader;
+                       UINT_16 u2Etype = 0;
+                       u2Etype = (pc[ETHER_TYPE_LEN_OFFSET] << 8) | (pc[ETHER_TYPE_LEN_OFFSET + 1]);
+                       /* for wapi integrity test. WPI_1x packet should be always in non-encrypted mode.
+                               if we received any WPI(0x88b4) packet that is encrypted, drop here. */
+                       if (u2Etype == ETH_WPI_1X &&
+                               HAL_RX_STATUS_GET_SEC_MODE(prRxStatus) != 0) {
+                               DBGLOG(QM, INFO, ("drop wpi packet with sec mode\n"));
+                               prCurrSwRfb->eDst = RX_PKT_DESTINATION_NULL;
+                               QUEUE_INSERT_TAIL(prReturnedQue, (P_QUE_ENTRY_T) prCurrSwRfb);
+                               continue;
+                       }
+               }
+#endif
         if (prCurrSwRfb->fgReorderBuffer && !fgIsBMC && fgIsHTran) {
             /* If this packet should dropped or indicated to the host immediately,
             *  it should be enqueued into the rReturnedQue with specific flags. If
index 6bd7ddaa0bc702cde6ec442818962bacbe923768..7ab78ddf6a7fd0cd979547a56f510d161237b844 100644 (file)
@@ -1783,7 +1783,7 @@ wext_set_mlme(IN struct net_device *prNetDev,
 /*----------------------------------------------------------------------------*/
 static int
 wext_set_scan(IN struct net_device *prNetDev,
-             IN struct iw_request_info *prIwrInfo, IN union iwreq_data *prData, IN char *pcExtra)
+             IN struct iw_request_info *prIwrInfo, IN struct iw_scan_req *prIwScanReq, IN char *pcExtra)
 {
        P_GLUE_INFO_T prGlueInfo = NULL;
        WLAN_STATUS rStatus = WLAN_STATUS_SUCCESS;
@@ -1798,10 +1798,8 @@ wext_set_scan(IN struct net_device *prNetDev,
 
 #if WIRELESS_EXT > 17
        /* retrieve SSID */
-       if (prData) {
-               essid_len =
-                   ((struct iw_scan_req *)(((struct iw_point *)prData)->pointer))->essid_len;
-       }
+       if (prIwScanReq)
+               essid_len = prIwScanReq->essid_len;
 #endif
 
        init_completion(&prGlueInfo->rScanComp);
@@ -3699,6 +3697,7 @@ int wext_support_ioctl(IN struct net_device *prDev, IN struct ifreq *prIfReq, IN
        int ret = 0;
        char *prExtraBuf = NULL;
        UINT_32 u4ExtraSize = 0;
+       struct iw_scan_req * prIwScanReq = NULL;
 
        /* prDev is verified in the caller function wlanDoIOCTL() */
 
@@ -3841,23 +3840,22 @@ int wext_support_ioctl(IN struct net_device *prDev, IN struct ifreq *prIfReq, IN
                }
 #if WIRELESS_EXT > 17
                else if (iwr->u.data.length == sizeof(struct iw_scan_req)) {
-                       prExtraBuf = kalMemAlloc(MAX_SSID_LEN, VIR_MEM_TYPE);
-                       if (!prExtraBuf) {
+                       prIwScanReq = kalMemAlloc(iwr->u.data.length, VIR_MEM_TYPE);
+                       if (!prIwScanReq) {
                                ret = -ENOMEM;
                                break;
                        }
-                       if (copy_from_user
-                           (prExtraBuf, ((struct iw_scan_req *)(iwr->u.data.pointer))->essid,
-                            ((struct iw_scan_req *)(iwr->u.data.pointer))->essid_len)) {
+
+                       if (copy_from_user(prIwScanReq, iwr->u.data.pointer, iwr->u.data.length)) {
                                ret = -EFAULT;
                        } else {
-                               ret =
-                                   wext_set_scan(prDev, NULL, (union iwreq_data *)&(iwr->u.data),
-                                                 prExtraBuf);
+                               if (prIwScanReq->essid_len > IW_ESSID_MAX_SIZE)
+                                       prIwScanReq->essid_len = IW_ESSID_MAX_SIZE;
+                               ret = wext_set_scan(prDev, NULL, prIwScanReq, &(prIwScanReq->essid[0]));
                        }
 
-                       kalMemFree(prExtraBuf, VIR_MEM_TYPE, MAX_SSID_LEN);
-                       prExtraBuf = NULL;
+                       kalMemFree(prIwScanReq, VIR_MEM_TYPE, iwr->u.data.length);
+                       prIwScanReq = NULL;
                }
 #endif
                else {
index e6a333dd21aa3d2144459186127f54449605848a..dd645311f6226c177356ee7bbf1320fb76e46e1e 100644 (file)
@@ -1698,6 +1698,7 @@ priv_get_struct(IN struct net_device *prNetDev,
        UINT_32 u4BufLen = 0;
        PUINT_32 pu4IntBuf = NULL;
        int status = 0;
+    UINT_32 u4CopyDataMax = 0;
 
        kalMemZero(&aucOidBuf[0], sizeof(aucOidBuf));
 
@@ -1763,11 +1764,14 @@ priv_get_struct(IN struct net_device *prNetDev,
                pu4IntBuf = (PUINT_32) prIwReqData->data.pointer;
                prNdisReq = (P_NDIS_TRANSPORT_STRUCT) &aucOidBuf[0];
 
-               if (copy_from_user(&prNdisReq->ndisOidContent[0],
-                                  prIwReqData->data.pointer, prIwReqData->data.length)) {
-                       DBGLOG(REQ, INFO, ("priv_get_struct() copy_from_user oidBuf fail\n"));
-                       return -EFAULT;
-               }
+               u4CopyDataMax = sizeof(aucOidBuf) - OFFSET_OF(NDIS_TRANSPORT_STRUCT, ndisOidContent);
+               if ((prIwReqData->data.length > u4CopyDataMax)
+                       || copy_from_user(&prNdisReq->ndisOidContent[0],
+                                                               prIwReqData->data.pointer,
+                                                               prIwReqData->data.length)) {
+            DBGLOG(REQ, INFO, ("priv_get_struct() copy_from_user oidBuf fail\n"));
+            return -EFAULT;
+        }
 
                prNdisReq->ndisOidCmd = OID_CUSTOM_SW_CTRL;
                prNdisReq->inNdisOidlength = 8;
index 8ba8010f85476e29793951d28644c0330486d3bd..50b778d3be04317526d057768e68653437629c84 100644 (file)
@@ -78,6 +78,8 @@ when mtk_wcn_wmt_func_on is called by wifi through rfkill)
 
 #define MAX_GPIO_CTRL_TIME (2000) /* [FixMe][GeorgeKuo] a temp value */
 
+#define MAX_PATCH_NUM 10
+
 /*******************************************************************************
 *                    E X T E R N A L   R E F E R E N C E S
 ********************************************************************************
index 511cf6dc7cdf63bcbd624ad36d529c367fe1a4c6..9f34bee93e50e2fe62fce0d4b10eb409271c15c1 100644 (file)
@@ -2517,13 +2517,20 @@ WMT_unlocked_ioctl (
                
         case WMT_IOCTL_SET_PATCH_NUM: {
                        pAtchNum = arg;
-                       WMT_INFO_FUNC(" get patch num from launcher = %d\n",pAtchNum);
-                       wmt_lib_set_patch_num(pAtchNum);
-                       pPatchInfo = kzalloc(sizeof(WMT_PATCH_INFO)*pAtchNum,GFP_ATOMIC);
+                       if (pAtchNum == 0 || pAtchNum > MAX_PATCH_NUM) {
+                               WMT_ERR_FUNC("patch num(%d) == 0 or > %d!\n", pAtchNum, MAX_PATCH_NUM);
+                               iRet = -1;
+                               break;
+                       }
+
+                       pPatchInfo = kzalloc(sizeof(WMT_PATCH_INFO) * pAtchNum, GFP_ATOMIC);
                        if (!pPatchInfo) {
                                WMT_ERR_FUNC("allocate memory fail!\n");
+                               iRet = -EFAULT;
                                break;
                        }
+                       WMT_INFO_FUNC(" get patch num from launcher = %d\n",pAtchNum);
+                       wmt_lib_set_patch_num(pAtchNum);
                }
                break;
 
index eeb2c44cc0bd867b58bf6bef5139bc208a41b74b..639b3c37cacf181dbd1c4fd3bb0557717f0d6f7c 100644 (file)
@@ -1242,10 +1242,19 @@ wlanAdapterStart (
     UINT_32 u4SetInfoLen;
 #endif
 
+       enum Adapter_Start_Fail_Reason {
+               ALLOC_ADAPTER_MEM_FAIL,
+               DRIVER_OWN_FAIL,
+               INIT_ADAPTER_FAIL,
+               RAM_CODE_DOWNLOAD_FAIL,
+               WAIT_FIRMWARE_READY_FAIL,
+               FAIL_REASON_MAX
+       } eFailReason;
     ASSERT(prAdapter);
 
     DEBUGFUNC("wlanAdapterStart");
 
+       eFailReason = FAIL_REASON_MAX;
     //4 <0> Reset variables in ADAPTER_T
     prAdapter->fgIsFwOwn = TRUE;
     prAdapter->fgIsEnterD3ReqIssued = FALSE;
@@ -1262,6 +1271,7 @@ wlanAdapterStart (
         if ( (u4Status = nicAllocateAdapterMemory(prAdapter)) != WLAN_STATUS_SUCCESS ) {
             DBGLOG(INIT, ERROR, ("nicAllocateAdapterMemory Error!\n"));
             u4Status = WLAN_STATUS_FAILURE;
+                       eFailReason = ALLOC_ADAPTER_MEM_FAIL;
             break;
         }
 
@@ -1278,6 +1288,7 @@ wlanAdapterStart (
         if(prAdapter->fgIsFwOwn == TRUE) {
             DBGLOG(INIT, ERROR, ("nicpmSetDriverOwn() failed!\n"));
             u4Status = WLAN_STATUS_FAILURE;
+                       eFailReason = DRIVER_OWN_FAIL;
             break;
         }
 
@@ -1285,6 +1296,7 @@ wlanAdapterStart (
         if ( (u4Status = nicInitializeAdapter(prAdapter)) != WLAN_STATUS_SUCCESS ) {
             DBGLOG(INIT, ERROR, ("nicInitializeAdapter failed!\n"));
             u4Status = WLAN_STATUS_FAILURE;
+                       eFailReason = INIT_ADAPTER_FAIL;
             break;
         }
 #endif
@@ -1400,6 +1412,7 @@ wlanAdapterStart (
         #endif
 
             if(u4Status != WLAN_STATUS_SUCCESS) {
+                               eFailReason = RAM_CODE_DOWNLOAD_FAIL;
                 break;
             }
 
@@ -1415,6 +1428,7 @@ wlanAdapterStart (
         else {
             DBGLOG(INIT, ERROR, ("No Firmware found!\n"));
             u4Status = WLAN_STATUS_FAILURE;
+                       eFailReason = RAM_CODE_DOWNLOAD_FAIL;
             break;
         }
 
@@ -1602,6 +1616,7 @@ wlanAdapterStart (
             else if(kalIsCardRemoved(prAdapter->prGlueInfo) == TRUE
                     || fgIsBusAccessFailed == TRUE) {
                 u4Status = WLAN_STATUS_FAILURE;
+                               eFailReason = WAIT_FIRMWARE_READY_FAIL;
                 break;
             }
             else if(i >= CFG_RESPONSE_POLLING_TIMEOUT) {
@@ -1611,6 +1626,7 @@ wlanAdapterStart (
                 DBGLOG(INIT, ERROR, ("Waiting for Ready bit: Timeout, ID=%u\n",
                         (u4MailBox0 & 0x0000FFFF)));
                 u4Status = WLAN_STATUS_FAILURE;
+                               eFailReason = WAIT_FIRMWARE_READY_FAIL;
                 break;
             }
             else {
@@ -1681,6 +1697,7 @@ wlanAdapterStart (
         RECLAIM_POWER_CONTROL_TO_PM(prAdapter, FALSE);
 
         if(u4Status != WLAN_STATUS_SUCCESS) {
+                       eFailReason = WAIT_FIRMWARE_READY_FAIL;
             break;
         }
 
@@ -1862,8 +1879,26 @@ wlanAdapterStart (
     }
     else {
         // release allocated memory
-        nicReleaseAdapterMemory(prAdapter);
-    }
+               switch (eFailReason)
+               {
+               case WAIT_FIRMWARE_READY_FAIL:
+               case RAM_CODE_DOWNLOAD_FAIL:
+                       DBGLOG(INIT, ERROR, ("Wait firmware ready fail or ram code download fail, FailReason: %d\n",
+                                       eFailReason));
+                       KAL_WAKE_LOCK_DESTROY(prAdapter, &prAdapter->rTxThreadWakeLock);
+                       nicRxUninitialize(prAdapter);
+                       nicTxRelease(prAdapter);
+                       /* System Service Uninitialization */
+                   nicUninitSystemService(prAdapter);
+               case INIT_ADAPTER_FAIL:
+               case DRIVER_OWN_FAIL:
+                       nicReleaseAdapterMemory(prAdapter);
+               case ALLOC_ADAPTER_MEM_FAIL:
+                       break;
+               default:
+                       break;
+               }
+       }
 
     return u4Status;
 } /* wlanAdapterStart */
@@ -4534,7 +4569,7 @@ wlanQueryPermanentAddress(
 
     // header checking ..
     prHifRxHdr = (P_HIF_RX_HEADER_T)aucBuffer;
-    if(prHifRxHdr->u2PacketType != HIF_RX_PKT_TYPE_EVENT) {
+       if ((prHifRxHdr->u2PacketType & HIF_RX_HDR_PACKET_TYPE_MASK) != HIF_RX_PKT_TYPE_EVENT) {
         return WLAN_STATUS_FAILURE;
     }
 
@@ -4624,7 +4659,7 @@ wlanQueryNicCapability(
 
     // header checking ..
     prHifRxHdr = (P_HIF_RX_HEADER_T)aucBuffer;
-    if(prHifRxHdr->u2PacketType != HIF_RX_PKT_TYPE_EVENT) {
+       if ((prHifRxHdr->u2PacketType & HIF_RX_HDR_PACKET_TYPE_MASK) != HIF_RX_PKT_TYPE_EVENT) {
         return WLAN_STATUS_FAILURE;
     }
 
@@ -4963,7 +4998,7 @@ wlanQueryPdMcr(
 
     // header checking ..
     prHifRxHdr = (P_HIF_RX_HEADER_T)aucBuffer;
-    if(prHifRxHdr->u2PacketType != HIF_RX_PKT_TYPE_EVENT) {
+       if ((prHifRxHdr->u2PacketType & HIF_RX_HDR_PACKET_TYPE_MASK) != HIF_RX_PKT_TYPE_EVENT) {
         return WLAN_STATUS_FAILURE;
     }
 
index 3895a7c3fc01e210db249dbebb152c7822b96f51..3d7099e377fc92e4c464fb216627dd253b284af9 100644 (file)
@@ -89,6 +89,8 @@
 /*! HIF_RX_HEADER_T */
 // DW 0, Byte 1
 #define HIF_RX_HDR_PACKET_TYPE_MASK      BITS(0,1)
+#define HIF_RX_HDR_SEC_MODE_MASK                BITS(2, 5)
+#define HIF_RX_HDR_SEC_MODE_OFFSET              2
 
 // DW 1, Byte 0
 #define HIF_RX_HDR_HEADER_LEN            BITS(2,7)
@@ -176,6 +178,8 @@ typedef enum _ENUM_HIF_RX_PKT_TYPE_T {
     ((((_prHifRxHdr)->uc80211_Reorder_PAL_TCL) & HIF_RX_HDR_NETWORK_IDX_MASK)\
     >> HIF_RX_HDR_NETWORK_IDX_OFFSET)
 
+#define HIF_RX_HDR_GET_SEC_MODE(_prHifRxHdr) \
+               ((((_prHifRxHdr)->u2PacketType) & HIF_RX_HDR_SEC_MODE_MASK) >> HIF_RX_HDR_SEC_MODE_OFFSET)
 
 #define HIF_RX_HDR_GET_TID(_prHifRxHdr) \
     ((((_prHifRxHdr)->u2SeqNoTid) & HIF_RX_HDR_TID_MASK)\
index 86262fefe7d0532723c0de46e7a207ae49257fb7..28927f070a2c11509dd29028c8575836f789a31d 100644 (file)
@@ -2975,7 +2975,21 @@ qmHandleRxPackets(
             }
 
         }
-
+#if CFG_SUPPORT_WAPI
+               if (prCurrSwRfb->u2PacketLen > ETHER_HEADER_LEN) {
+                       PUINT_8 pc = (PUINT_8) prCurrSwRfb->pvHeader;
+                       UINT_16 u2Etype = 0;
+                       u2Etype = (pc[ETH_TYPE_LEN_OFFSET] << 8) | (pc[ETH_TYPE_LEN_OFFSET + 1]);
+                       /* for wapi integrity test. WPI_1x packet should be always in non-encrypted mode.
+                               if we received any WPI(0x88b4) packet that is encrypted, drop here. */
+                       if (u2Etype == ETH_WPI_1X && HIF_RX_HDR_GET_SEC_MODE(prHifRxHdr) != 0) {
+                               DBGLOG(QM, INFO, ("drop wpi packet with sec mode\n"));
+                               prCurrSwRfb->eDst = RX_PKT_DESTINATION_NULL;
+                               QUEUE_INSERT_TAIL(&rReturnedQue, (P_QUE_ENTRY_T) prCurrSwRfb);
+                               continue;
+                       }
+               }
+#endif
         /* BAR frame */
         if(HIF_RX_HDR_GET_BAR_FLAG(prHifRxHdr)){
             prCurrSwRfb->eDst = RX_PKT_DESTINATION_NULL;
index 729f140fa3a349ecbce48c3d51f55c1baa762dea..7a4d5cf93b5280aaaebaa81c1ca1f002d88bb678 100644 (file)
@@ -1766,7 +1766,8 @@ mtk_cfg80211_mgmt_frame_register (
 
         if (prGlueInfo->prAdapter != NULL){
 
-            prGlueInfo->ulFlag |= GLUE_FLAG_FRAME_FILTER_AIS;
+            /* prGlueInfo->ulFlag |= GLUE_FLAG_FRAME_FILTER_AIS; */
+                       set_bit(GLUE_FLAG_FRAME_FILTER_AIS_BIT, &prGlueInfo->ulFlag);
 
             /* wake up main thread */
             wake_up_interruptible(&prGlueInfo->waitq);
index 48212364c3963f1837b0acfd4b7b79d829a5aa96..014baa737aa93811fe33fb007708fba864246f5f 100644 (file)
@@ -2888,8 +2888,17 @@ wlanProbe(
     P_ADAPTER_T prAdapter = NULL;
     INT_32 i4Status = 0;
     BOOLEAN bRet = FALSE;
-
-
+       enum probe_fail_reason {
+               BUS_INIT_FAIL,
+               NET_CREATE_FAIL,
+               BUS_SET_IRQ_FAIL,
+               ADAPTER_START_FAIL,
+               NET_REGISTER_FAIL,
+               PROC_INIT_FAIL,
+               FAIL_REASON_NUM
+       } eFailReason;
+
+       eFailReason = FAIL_REASON_NUM;
     do {
         //4 <1> Initialize the IO port of the interface
         /*  GeorgeKuo: pData has different meaning for _HIF_XXX:
@@ -2904,6 +2913,7 @@ wlanProbe(
         if (FALSE == bRet) {
             DBGLOG(INIT, ERROR, (KERN_ALERT "wlanProbe: glBusInit() fail\n"));
             i4Status = -EIO;
+                       eFailReason = BUS_INIT_FAIL;
             break;
         }
 
@@ -2911,6 +2921,7 @@ wlanProbe(
         if ((prWdev = wlanNetCreate(pvData)) == NULL) {
             DBGLOG(INIT, ERROR, ("wlanProbe: No memory for dev and its private\n"));
             i4Status = -ENOMEM;
+                       eFailReason = NET_CREATE_FAIL;
             break;
         }
 
@@ -2938,6 +2949,7 @@ wlanProbe(
 
         if (i4Status != WLAN_STATUS_SUCCESS) {
             DBGLOG(INIT, ERROR, ("wlanProbe: Set IRQ error\n"));
+                       eFailReason = BUS_SET_IRQ_FAIL;
             break;
         }
 
@@ -3031,6 +3043,7 @@ bailout:
                 HifRegDump(prGlueInfo->prAdapter);
                 if (prGlueInfo->rHifInfo.DmaOps->DmaRegDump != NULL)
                     prGlueInfo->rHifInfo.DmaOps->DmaRegDump(&prGlueInfo->rHifInfo);
+                               eFailReason = ADAPTER_START_FAIL;
                 break;
             }
         }
@@ -3046,6 +3059,7 @@ bailout:
 
         if (wlanAdapterStart(prAdapter, prRegInfo, NULL, 0) != WLAN_STATUS_SUCCESS) {
             i4Status = -EIO;
+                       eFailReason = ADAPTER_START_FAIL;
             break;
         }
 #endif
@@ -3144,6 +3158,7 @@ bailout:
         if ((i4DevIdx = wlanNetRegister(prWdev)) < 0){
             i4Status = -ENXIO;
             DBGLOG(INIT, ERROR, ("wlanProbe: Cannot register the net_device context to the kernel\n"));
+                       eFailReason = NET_REGISTER_FAIL;
             break;
         }
                
@@ -3153,6 +3168,7 @@ bailout:
         DBGLOG(INIT, TRACE, ("init procfs...\n"));
         if ( (i4Status = procInitProcfs(prDev, NIC_DEVICE_ID_LOW)) < 0) {
             DBGLOG(INIT, ERROR, ("wlanProbe: init procfs failed\n"));
+                       eFailReason = PROC_INIT_FAIL;
             break;
         }
 #endif /* WLAN_INCLUDE_PROC */
@@ -3183,10 +3199,30 @@ bailout:
     while (FALSE);
 
     if (i4Status != WLAN_STATUS_SUCCESS)
-    {
-        KAL_WAKE_LOCK_DESTROY(prGlueInfo->prAdapter, &prGlueInfo->rAhbIsrWakeLock);
-        if (prWdev != NULL)
-            glBusFreeIrq(prWdev->netdev, *((P_GLUE_INFO_T *) netdev_priv(prWdev->netdev)));
+       {
+               switch (eFailReason)
+               {
+               case PROC_INIT_FAIL:
+                       wlanNetUnregister(prWdev);
+               case NET_REGISTER_FAIL:
+                       set_bit(GLUE_FLAG_HALT_BIT, &prGlueInfo->ulFlag);
+                       /* wake up main thread */
+                   wake_up_interruptible(&prGlueInfo->waitq);
+                       /* wait main thread stops */
+                   wait_for_completion_interruptible(&prGlueInfo->rHaltComp);
+               KAL_WAKE_LOCK_DESTROY(prGlueInfo->prAdapter, &prGlueInfo->rAhbIsrWakeLock);
+                       wlanAdapterStop(prAdapter);
+               case ADAPTER_START_FAIL:
+               if (prWdev != NULL)
+               glBusFreeIrq(prWdev->netdev, *((P_GLUE_INFO_T *) netdev_priv(prWdev->netdev)));
+               case BUS_SET_IRQ_FAIL:
+                       KAL_WAKE_LOCK_DESTROY(prAdapter, &prGlueInfo->rAhbIsrWakeLock);
+                       wlanNetDestroy(prWdev);
+               case NET_CREATE_FAIL:
+               case BUS_INIT_FAIL:
+               default:
+                       break;
+               }
     }
 
 #if CFG_ENABLE_WIFI_DIRECT
@@ -3203,14 +3239,28 @@ bailout:
         kalIndicateAgpsNotify(prAdapter, AGPS_EVENT_WLAN_ON, NULL, 0);
 #endif
 #if (CFG_SUPPORT_MET_PROFILING == 1)
-    DBGLOG(INIT, TRACE, ("init MET procfs...\n"));
-    printk("MET_PROF: MET PROCFS init....\n");
-    if ( (i4Status = kalMetInitProcfs(prGlueInfo)) < 0) {
-        DBGLOG(INIT, ERROR, ("wlanProbe: init MET procfs failed\n"));
-    }
+       {
+               int iMetInitRet = WLAN_STATUS_FAILURE;
+               if (i4Status == WLAN_STATUS_SUCCESS)
+               {
+               DBGLOG(INIT, TRACE, ("init MET procfs...\n"));
+                       iMetInitRet = kalMetInitProcfs(prGlueInfo);
+               if (iMetInitRet < 0)
+                       {
+                       DBGLOG(INIT, ERROR, ("wlanProbe: init MET procfs failed\n"));
+                       }
+       }
+       }
 #endif
-    DBGLOG(INIT, TRACE, ("wlanProbe ok\n"));
-    return i4Status;
+       if (i4Status == WLAN_STATUS_SUCCESS) {
+               /* probe ok */
+               DBGLOG(INIT, TRACE, ("wlanProbe ok\n"));
+       } else {
+               /* probe failed */
+               DBGLOG(INIT, ERROR, ("wlanProbe failed\n"));
+       }
+
+       return i4Status;
 } /* end of wlanProbe() */
 
 
index 9bc0d7bc7cc2ba9f6b296df98cd895be3fc07157..6198963997cc969721faa345a14a3ee9f125175f 100644 (file)
@@ -1788,12 +1788,8 @@ wext_set_mlme (
 */
 /*----------------------------------------------------------------------------*/
 static int
-wext_set_scan (
-    IN struct net_device *prNetDev,
-    IN struct iw_request_info *prIwrInfo,
-    IN union iwreq_data *prData,
-    IN char *pcExtra
-    )
+wext_set_scan(IN struct net_device *prNetDev,
+             IN struct iw_request_info *prIwrInfo, IN struct iw_scan_req *prIwScanReq, IN char *pcExtra)
 {
     P_GLUE_INFO_T prGlueInfo = NULL;
     WLAN_STATUS rStatus = WLAN_STATUS_SUCCESS;
@@ -1808,9 +1804,8 @@ wext_set_scan (
 
 #if WIRELESS_EXT > 17
     /* retrieve SSID */
-    if(prData) {
-        essid_len = ((struct iw_scan_req *)(((struct iw_point*)prData)->pointer))->essid_len;
-    }
+       if (prIwScanReq)
+               essid_len = prIwScanReq->essid_len;
 #endif
 
     init_completion(&prGlueInfo->rScanComp);
@@ -3974,6 +3969,7 @@ wext_support_ioctl (
     int ret = 0;
     char *prExtraBuf = NULL;
     UINT_32 u4ExtraSize = 0;
+    struct iw_scan_req * prIwScanReq = NULL;
 
     /* prDev is verified in the caller function wlanDoIOCTL() */
 
@@ -4120,21 +4116,23 @@ wext_support_ioctl (
         }
 #if WIRELESS_EXT > 17
                else if (iwr->u.data.length == sizeof(struct iw_scan_req)) {
-            prExtraBuf = kalMemAlloc(MAX_SSID_LEN, VIR_MEM_TYPE);
-            if (!prExtraBuf) {
-                ret = -ENOMEM;
-                break;
-            }
-            if (copy_from_user(prExtraBuf, ((struct iw_scan_req *) (iwr->u.data.pointer))->essid,
-                ((struct iw_scan_req *) (iwr->u.data.pointer))->essid_len)) {
-                ret = -EFAULT;
-            } else {
-                ret = wext_set_scan(prDev, NULL, (union iwreq_data *)  &(iwr->u.data), prExtraBuf);
-            }
-
-            kalMemFree(prExtraBuf, VIR_MEM_TYPE, MAX_SSID_LEN);
-            prExtraBuf = NULL;
-        }
+                       prIwScanReq = kalMemAlloc(iwr->u.data.length, VIR_MEM_TYPE);
+                       if (!prIwScanReq) {
+                               ret = -ENOMEM;
+                               break;
+                       }
+
+                       if (copy_from_user(prIwScanReq, iwr->u.data.pointer, iwr->u.data.length)) {
+                               ret = -EFAULT;
+                       } else {
+                               if (prIwScanReq->essid_len > IW_ESSID_MAX_SIZE)
+                                       prIwScanReq->essid_len = IW_ESSID_MAX_SIZE;
+                               ret = wext_set_scan(prDev, NULL, prIwScanReq, &(prIwScanReq->essid[0]));
+                       }
+
+                       kalMemFree(prIwScanReq, VIR_MEM_TYPE, iwr->u.data.length);
+                       prIwScanReq = NULL;
+               }
 #endif
                else {
             ret = -EINVAL;
index 4cb19c1b3cef16628f3c6cacc3c2ddb634e76660..11dd7fd568754730f11769fe80e01b1027f3f4b7 100644 (file)
@@ -1334,12 +1334,15 @@ priv_get_int (
         {
                        wlanQueryDebugCode(prGlueInfo->prAdapter);
 
-                               kalMemSet(gucBufDbgCode, '.', sizeof(gucBufDbgCode));
-                if (copy_to_user(prIwReqData->data.pointer, gucBufDbgCode, prIwReqData->data.length)) {
-                     return -EFAULT;
-                }
-                else
-                     return status;
+                       kalMemSet(gucBufDbgCode, '.', sizeof(gucBufDbgCode));
+                       u4BufLen = prIwReqData->data.length;
+                       if (u4BufLen > sizeof(gucBufDbgCode))
+                               u4BufLen = sizeof(gucBufDbgCode);
+            if (copy_to_user(prIwReqData->data.pointer, gucBufDbgCode, u4BufLen)) {
+                 return -EFAULT;
+            }
+            else
+                 return status;
         }
 
     default:
@@ -1769,6 +1772,7 @@ priv_get_struct (
     UINT_32         u4BufLen = 0;
     PUINT_32        pu4IntBuf = NULL;
     int             status = 0;
+    UINT_32         u4CopyDataMax = 0;
 
     kalMemZero(&aucOidBuf[0], sizeof(aucOidBuf));
 
@@ -1839,9 +1843,11 @@ priv_get_struct (
         pu4IntBuf = (PUINT_32)prIwReqData->data.pointer;
         prNdisReq = (P_NDIS_TRANSPORT_STRUCT) &aucOidBuf[0];
 
-        if (copy_from_user(&prNdisReq->ndisOidContent[0],
-                prIwReqData->data.pointer,
-                prIwReqData->data.length)) {
+               u4CopyDataMax = sizeof(aucOidBuf) - OFFSET_OF(NDIS_TRANSPORT_STRUCT, ndisOidContent);
+               if ((prIwReqData->data.length > u4CopyDataMax)
+                       || copy_from_user(&prNdisReq->ndisOidContent[0],
+                                                               prIwReqData->data.pointer,
+                                                               prIwReqData->data.length)) {
             DBGLOG(REQ, INFO, ("priv_get_struct() copy_from_user oidBuf fail\n"));
             return -EFAULT;
         }
index a0acdc423d92649f44949505ec71332a94aae389..e5510bccd404b760506aaf994a819ecaf4b881bc 100644 (file)
@@ -97,7 +97,11 @@ DISPLAY_PWM_T * get_pwm_lut(void)
     return &g_pwm_lut;
 }
 
-static unsigned int brightness_mapping(unsigned int level);
+/* [FEATURE]-Mod-BEGIN by TCTSZ.yaohui.zeng, 2015/04/20,use customized brightness_mapping()*/
+//static unsigned int brightness_mapping(unsigned int level);
+extern unsigned int brightness_mapping(unsigned int level);
+/* [FEATURE]-Mod-END by TCTSZ.yaohui.zeng, 2015/04/20*/
+
 void disp_onConfig_bls(DISP_AAL_PARAM *param)
 {
     unsigned long prevSetting = DISP_REG_GET(DISP_REG_BLS_BLS_SETTING);
@@ -142,7 +146,8 @@ void disp_onConfig_bls(DISP_AAL_PARAM *param)
 
 }
 
-
+/* [FEATURE]-Mod-BEGIN by TCTSZ.yaohui.zeng, 2015/04/20,use customized brightness_mapping()*/
+/*
 static unsigned int brightness_mapping(unsigned int level)
 {
     unsigned int mapped_level;
@@ -154,6 +159,8 @@ static unsigned int brightness_mapping(unsigned int level)
 
        return mapped_level;
 }
+*/
+/* [FEATURE]-Mod-END by TCTSZ.yaohui.zeng, 2015/04/20*/
 
 #if !defined(CONFIG_MTK_AAL_SUPPORT)
 #ifdef USE_DISP_BLS_MUTEX
index 448612492fd04db186e76e4ba3427508a50a2d72..ff1f97373f1a6cf4369fb719b69d7d5255a30ddc 100644 (file)
@@ -186,7 +186,7 @@ static void process_dbg_opt(const char *opt)
         char *p = (char *)opt + 5;
         unsigned int addr = (unsigned int) simple_strtoul(p, &p, 16);
 
-        if (addr
+        if (addr >= 0xf4000000 && addr <= 0xf5000000)
         {
             unsigned int regVal = DISP_REG_GET(addr);
             DISP_MSG("regr: 0x%08X = 0x%08X\n", addr, regVal);
@@ -200,7 +200,7 @@ static void process_dbg_opt(const char *opt)
         char *p = (char *)opt + 5;
         unsigned int addr = (unsigned int) simple_strtoul(p, &p, 16);
         unsigned int val = (unsigned int) simple_strtoul(p + 1, &p, 16);
-        if (addr
+        if (addr >= 0xf4000000 && addr <= 0xf5000000)
         {
             unsigned int regVal;
             DISP_REG_SET(addr, val);
index f1c6784181fbfef7010c5d8442433fc9fd74b680..2f3236910a082489e5a26034f6432f5098d940e9 100644 (file)
@@ -5328,24 +5328,9 @@ static int __init hdmi_init(void)
 {
     int ret = 0;
     int tmp_boot_mode;
-       //[BUGFIX]-Add-BEGIN by SCDTABLET.jinghuang@tcl.com,19/5/2015,
-       //add the function to check if hdmi power is on.
-       int hdmi_power=-1;
-       //[BUGFIX]-Mod-END by SCDTABLET.jinghuang@tcl.com
+
     printk("[hdmi]%s\n", __func__);
-       //[BUGFIX]-Add-BEGIN by SCDTABLET.jinghuang@tcl.com,19/5/2015,
-       //add the function to check if hdmi power is on.
-       mt_set_gpio_mode(GPIO87,GPIO_MODE_00);  // gpio mode   high
-       mt_set_gpio_dir(GPIO87,GPIO_DIR_OUT);   //OUT
-       hdmi_power=mt_get_gpio_out(GPIO87);
-       if(hdmi_power==0)
-               {
-               printk("[hdmi]check: hdmi power is off,power on again \n");
-               mt_set_gpio_out(GPIO87,GPIO_OUT_ONE);//OUT h
-       }else{
-                       printk("[hdmi]check: hdmi power is already on \n");
-       }
-       //[BUGFIX]-Mod-END by SCDTABLET.jinghuang@tcl.com
+
     if (platform_driver_register(&hdmi_driver))
     {
         printk("[hdmi]failed to register hdmitx driver\n");
index dae684e39950aa890d7b1f5e60ef2f404d6aeb60..b7c5b5fbdcf7eb43350e26a0fa7ca2b308e6700b 100644 (file)
@@ -302,6 +302,10 @@ static ssize_t freqhopping_userdefine_proc_write(struct file *file, const char *
        fh_ctl.ssc_setting.dds          = p7;
        fh_ctl.ssc_setting.freq         = 0;
 
+       /* Check validity of PLL ID */
+       if (fh_ctl.pll_id >= FH_PLL_COUNT)
+               return -1;
+
 
        if( p1 == FH_CMD_ENABLE){
                ret = mt_fh_enable_usrdef(&fh_ctl);
@@ -428,6 +432,10 @@ static ssize_t freqhopping_status_proc_write(struct file *file, const char *buff
        fh_ctl.ssc_setting.upbnd= 0;
        fh_ctl.ssc_setting.lowbnd= 0;
 
+       /* Check validity of PLL ID */
+       if (fh_ctl.pll_id >= FH_PLL_COUNT)
+               return -1;
+
        if( p1 == 0){
                mt_freqhopping_ioctl(NULL,FH_CMD_DISABLE,(unsigned long)(&fh_ctl));
        }
@@ -446,7 +454,7 @@ static int freqhopping_debug_proc_read(struct seq_file* m, void* v)
     arg.m = m;
     arg.v = v;
     arg.pll = g_fh_drv_pll;
-    g_p_fh_hal_drv->ioctl(FH_IO_PROC_READ, &arg);
+    //g_p_fh_hal_drv->ioctl(FH_IO_PROC_READ, &arg);
     return 0;
 #else
        FH_MSG("EN: %s",__func__);
@@ -529,6 +537,10 @@ static ssize_t freqhopping_debug_proc_write(struct file *file, const char *buffe
        fh_ctl.ssc_setting.lowbnd       = p7;
        fh_ctl.ssc_setting.freq         = 0;
 
+       /* Check validity of PLL ID */
+       if (fh_ctl.pll_id >= FH_PLL_COUNT)
+               return -1;
+
 
        if (cmd < FH_CMD_INTERNAL_MAX_CMD) {
                mt_freqhopping_ioctl(NULL,cmd,(unsigned long)(&fh_ctl));
@@ -994,7 +1006,7 @@ int mt_freqhopping_devctl(unsigned int cmd, void* args)
         return 1;
     }
     
-       g_p_fh_hal_drv->ioctl(cmd, args);
+       //g_p_fh_hal_drv->ioctl(cmd, args);
     return 0;
     
 }
index 59fe5b84a4de7fee0e03e4cfe403b330bae382ef..bca785bc4c5e0ce22eaccccfbb4f23cd867f7296 100644 (file)
@@ -84,7 +84,15 @@ static long ged_dispatch(GED_BRIDGE_PACKAGE *psBridgePackageKM)
     typedef int (ged_bridge_func_type)(void*, void*);
     ged_bridge_func_type* pFunc = NULL;
     
-    if (psBridgePackageKM->i32InBufferSize + psBridgePackageKM->i32OutBufferSize < GED_IOCTL_PARAM_BUF_SIZE)
+    /* We make sure the both size and the sum of them are GE 0 integer.
+     * The sum will not overflow to zero, because we will get zero from two GE 0 integers
+     * if and only if they are both zero in a 2's complement numeral system.
+     * That is: if overflow happen, the sum will be a negative number.
+     */
+    if (psBridgePackageKM->i32InBufferSize >= 0 && psBridgePackageKM->i32OutBufferSize >= 0
+        && psBridgePackageKM->i32InBufferSize + psBridgePackageKM->i32OutBufferSize >= 0
+        && psBridgePackageKM->i32InBufferSize + psBridgePackageKM->i32OutBufferSize
+        < GED_IOCTL_PARAM_BUF_SIZE)
     {
         pvInt = gvIOCTLParamBuf;
         pvOut = (void*)((char*)pvInt + (uintptr_t)psBridgePackageKM->i32InBufferSize);
index 555f8b8581cb7f7af7884b30a476aa9821ec1c5b..cf4727a8222c7da0c5ea003d5560efacda0ec419 100644 (file)
@@ -427,7 +427,7 @@ static int mali_mem_os_shrink(struct shrinker *shrinker, struct shrink_control *
 #endif
 
        if (0 == nr) {
-               //[BUGFIX]-Mod-BEGIN by SCDTABLET.zhangku.guo@tcl.com,06/09/2015,983716,mtk patch for fix ANR issue when TAT
+               //[BUGFIX]-Mod-BEGIN by SCDTABLET.zhangku.guo@tcl.com,06/09/2015,1017702,mtk patch for fix ANR issue when TAT
                //return mali_mem_os_allocator.pool_count + mali_mem_page_table_page_pool.count;
                return mali_mem_os_allocator.pool_count;
                //[BUGFIX]-Mod-END by SCDTABLET.zhangku.guo@tcl.com
@@ -457,7 +457,7 @@ static int mali_mem_os_shrink(struct shrinker *shrinker, struct shrink_control *
                mali_mem_os_free_page(page);
        }
 
-       //[BUGFIX]-Del-BEGIN by SCDTABLET.zhangku.guo@tcl.com,06/09/2015,983716,mtk patch for fix ANR issue when TAT
+       //[BUGFIX]-Del-BEGIN by SCDTABLET.zhangku.guo@tcl.com,06/09/2015,1017702,mtk patch for fix ANR issue when TAT
        /* Release some pages from page table page pool */
        //mali_mem_os_trim_page_table_page_pool();
        //[BUGFIX]-Del-END by SCDTABLET.zhangku.guo@tcl.com
@@ -468,7 +468,7 @@ static int mali_mem_os_shrink(struct shrinker *shrinker, struct shrink_control *
                cancel_delayed_work(&mali_mem_os_allocator.timed_shrinker);
        }
 
-       //[BUGFIX]-Mod-BEGIN by SCDTABLET.zhangku.guo@tcl.com,06/09/2015,983716,mtk patch for fix ANR issue when TAT
+       //[BUGFIX]-Mod-BEGIN by SCDTABLET.zhangku.guo@tcl.com,06/09/2015,1017702,mtk patch for fix ANR issue when TAT
        //return mali_mem_os_allocator.pool_count + mali_mem_page_table_page_pool.count;
        return mali_mem_os_allocator.pool_count;
        //[BUGFIX]-Mod-END by SCDTABLET.zhangku.guo@tcl.com
index 3d149b639899e8f08fc795e933c7b138dd851b4a..8cbd15be890d9bd520d61be56dd583f69eb54902 100644 (file)
@@ -31,7 +31,7 @@ static struct hall_data *hall = NULL;
 static struct class *hall_class = NULL;
 static struct device *hall_dev = NULL;
 static struct platform_device *hall_pdev = NULL;
-extern unsigned int bl_brightness;
+extern unsigned int bl_brightness_hal;
 
 
 static void do_hall_work(struct work_struct *work)
@@ -46,14 +46,14 @@ static void do_hall_work(struct work_struct *work)
        hall_state = !hall_state;
        pressed = (hall_state == !!CUST_EINT_POLARITY_LOW);
 
-       if((pressed == 1) && (bl_brightness != 0)) {
+       if((pressed == 1) && (bl_brightness_hal != 0)) {
                input_report_key(hall_input, KEY_POWER, pressed);
                input_sync(hall_input);
                input_report_key(hall_input, KEY_POWER, !pressed);
                input_sync(hall_input);
        }
 
-       if((pressed == 0) && (bl_brightness == 0)) {
+       if((pressed == 0) && (bl_brightness_hal == 0)) {
                input_report_key(hall_input, KEY_POWER, !pressed);
                input_sync(hall_input);
                input_report_key(hall_input, KEY_POWER, pressed);
index 7c355ecf102726353eb1442638091f56f70568a4..82ff11f9145089d9b8b8ae3ac8bb4bacc222b269 100644 (file)
@@ -265,7 +265,7 @@ static void hwmsen_work_func(struct work_struct *work)
        
        memset(&sensor_data, 0, sizeof(sensor_data));   
        time.tv_sec = time.tv_nsec = 0;    
-       time = get_monotonic_coarse(); 
+       get_monotonic_boottime(&time);
        nt = time.tv_sec*1000000000LL+time.tv_nsec;
        //mutex_lock(&obj_data.lock);
        for(idx = 0; idx < MAX_ANDROID_SENSOR_NUM; idx++)
@@ -340,7 +340,7 @@ static void hwmsen_work_func(struct work_struct *work)
                                if((sensor_data.values[0] != obj_data.sensors_data[idx].values[0]) 
                                        || (sensor_data.values[1] != obj_data.sensors_data[idx].values[1])
                                        || (sensor_data.values[2] != obj_data.sensors_data[idx].values[2])
-                                       || (idx == ID_MAGNETIC))
+                                       || (idx == ID_MAGNETIC) || (idx == ID_ACCELEROMETER))
                                {       
                                    if( 0 == sensor_data.values[0] && 0==sensor_data.values[1] 
                                                && 0 == sensor_data.values[2])
@@ -443,7 +443,7 @@ int hwmsen_get_interrupt_data(int sensor, hwm_sensor_data *data)
        else
        {               
                time.tv_sec = time.tv_nsec = 0;    
-               time = get_monotonic_coarse(); 
+               get_monotonic_boottime(&time);
                nt = time.tv_sec*1000000000LL+time.tv_nsec;  
                if((sensor == ID_LIGHT) ||(sensor == ID_PRESSURE) 
                        ||(sensor == ID_PROXIMITY) || (sensor == ID_TEMPRERATURE))
@@ -603,6 +603,11 @@ static int hwmsen_enable(struct hwmdev_object *obj, int sensor, int enable)
 
        sensor_type = 1 << sensor;
        
+       if (sensor > MAX_ANDROID_SENSOR_NUM || sensor < 0) {
+               HWM_ERR("handle %d!\n", sensor);
+               return -EINVAL;
+       }
+
        if(!obj)
        {
                HWM_ERR("hwmdev obj pointer is NULL!\n");
@@ -613,7 +618,6 @@ static int hwmsen_enable(struct hwmdev_object *obj, int sensor, int enable)
                HWM_ERR("the sensor (%d) is not attached!!\n", sensor);
                return -ENODEV;
        }
-       
 
        mutex_lock(&obj->dc->lock);
        cxt = obj->dc->cxt[sensor];    
@@ -724,6 +728,11 @@ static int hwmsen_enable_nodata(struct hwmdev_object *obj, int sensor, int enabl
        HWM_FUN(f);
        sensor_type = 1 << sensor;
 
+       if (sensor > MAX_ANDROID_SENSOR_NUM || sensor < 0) {
+               HWM_ERR("handle %d!\n", sensor);
+               return -EINVAL;
+       }
+
        if(NULL == obj)
        {
                HWM_ERR("hwmdev obj pointer is NULL!\n");
@@ -734,7 +743,6 @@ static int hwmsen_enable_nodata(struct hwmdev_object *obj, int sensor, int enabl
                HWM_ERR("the sensor (%d) is not attached!!\n", sensor);
                return -ENODEV;
        }
-       
 
        mutex_lock(&obj->dc->lock);
        cxt = obj->dc->cxt[sensor];
@@ -784,6 +792,10 @@ static int hwmsen_set_delay(int delay, int handle )
        int err = 0;
        struct hwmsen_context *cxt = NULL;
 
+       if (handle > MAX_ANDROID_SENSOR_NUM || handle < 0) {
+               HWM_ERR("handle %d!\n", handle);
+               return -EINVAL;
+       }
        cxt = hwm_obj->dc->cxt[handle];
        if(NULL == cxt ||(cxt->obj.sensor_operate == NULL))
        {
index 317f702b205ece0f86d301c87e8c71cce0253169..490066f92ccc9de0a29a261f8154f40cfb3483c1 100644 (file)
@@ -202,7 +202,7 @@ static ssize_t set_config(struct device *dev, struct device_attribute *attr, con
   unsigned char tmpbuffer[128];
   printk("%s\n", buf);
   //if ( sscanf(buf, "%d %d %d %d %d %d %d %d %d %d %d %d %s", &bus_id, &address, &operation, &trans_mode, &trans_stop, &speed_mode, &pushpull_mode, &query_mode, &timing, &trans_num, &trans_auxlen,&dir, data_buffer) ) {
-  if ( sscanf(buf, "%d %x %d %d %d %d %d %d %d %d %d %s", &bus_id, &address, &operation, &trans_mode, &trans_stop, &speed_mode, &pushpull_mode, &query_mode, &timing, &trans_num, &trans_auxlen,data_buffer) ) {
+  if ( sscanf(buf, "%d %x %d %d %d %d %d %d %d %d %d %1023s", &bus_id, &address, &operation, &trans_mode, &trans_stop, &speed_mode, &pushpull_mode, &query_mode, &timing, &trans_num, &trans_auxlen,data_buffer) ) {
       if((address != 0)&&(operation<=2)){
         length = strlen(data_buffer);
       if (operation == 0){
index 0e3ea2fa4c21fc34ad5b5afb2f89255f3ac086c4..d7200215172e7f1a33d8aa4413ef061940357568 100644 (file)
 #define T8EV5_SENSOR_ID                         0x1011
 #define GC2235_SENSOR_ID        0x2235
 #define OV8865_SENSOR_ID                         0x8865
-#define GC2355_SENSOR_ID                       0x2355
+#define GC2355MIPI_SENSOR_ID                   0x2355
 #define HI551_SENSOR_ID                            0x0551
 
 #define HI841_SENSOR_ID                            0x0841
 
 #define SENSOR_DRVNAME_OV5647_RAW      "ov5647"
 #define SENSOR_DRVNAME_OV5648_MIPI_RAW         "ov5648mipi"
-#define SENSOR_DRVNAME_OV5670_MIPI_RAW         "ov5670mipi"
+#define SENSOR_DRVNAME_OV5670_MIPI_RAW         "ov5670mipiraw"
+#define SENSOR_DRVNAME_OV56702ND_MIPI_RAW      "ov56702ndmipiraw"
 #define SENSOR_DRVNAME_OV5693_MIPI_RAW     "ov5693mipi"
 #define SENSOR_DRVNAME_OV5642_MIPI_YUV    "ov5642mipiyuv"
 #define SENSOR_DRVNAME_OV5642_MIPI_RGB    "ov5642mipirgb"
diff --git a/drivers/misc/mediatek/imgsensor/src/mt8127/gc2355_mipi_raw/Makefile b/drivers/misc/mediatek/imgsensor/src/mt8127/gc2355_mipi_raw/Makefile
new file mode 100644 (file)
index 0000000..62abd01
--- /dev/null
@@ -0,0 +1,4 @@
+include $(srctree)/drivers/misc/mediatek/Makefile.custom
+
+obj-y += gc2355mipi_Sensor.o
+
diff --git a/drivers/misc/mediatek/imgsensor/src/mt8127/gc2355_mipi_raw/gc2355mipi_CameraCustomized.h b/drivers/misc/mediatek/imgsensor/src/mt8127/gc2355_mipi_raw/gc2355mipi_CameraCustomized.h
new file mode 100644 (file)
index 0000000..0139877
--- /dev/null
@@ -0,0 +1,157 @@
+/* Copyright Statement:
+ *
+ * This software/firmware and related documentation ("MediaTek Software") are
+ * protected under relevant copyright laws. The information contained herein
+ * is confidential and proprietary to MediaTek Inc. and/or its licensors.
+ * Without the prior written permission of MediaTek inc. and/or its licensors,
+ * any reproduction, modification, use or disclosure of MediaTek Software,
+ * and information contained herein, in whole or in part, shall be strictly prohibited.
+ */
+/* MediaTek Inc. (C) 2010. All rights reserved.
+ *
+ * BY OPENING THIS FILE, RECEIVER HEREBY UNEQUIVOCALLY ACKNOWLEDGES AND AGREES
+ * THAT THE SOFTWARE/FIRMWARE AND ITS DOCUMENTATIONS ("MEDIATEK SOFTWARE") 
+ * RECEIVED FROM MEDIATEK AND/OR ITS REPRESENTATIVES ARE PROVIDED TO RECEIVER ON
+ * AN "AS-IS" BASIS ONLY. MEDIATEK EXPRESSLY DISCLAIMS ANY AND ALL WARRANTIES,
+ * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE IMPLIED WARRANTIES OF
+ * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE OR NONINFRINGEMENT.
+ * NEITHER DOES MEDIATEK PROVIDE ANY WARRANTY WHATSOEVER WITH RESPECT TO THE
+ * SOFTWARE OF ANY THIRD PARTY WHICH MAY BE USED BY, INCORPORATED IN, OR
+ * SUPPLIED WITH THE MEDIATEK SOFTWARE, AND RECEIVER AGREES TO LOOK ONLY TO SUCH
+ * THIRD PARTY FOR ANY WARRANTY CLAIM RELATING THERETO. RECEIVER EXPRESSLY ACKNOWLEDGES
+ * THAT IT IS RECEIVER'S SOLE RESPONSIBILITY TO OBTAIN FROM ANY THIRD PARTY ALL PROPER LICENSES
+ * CONTAINED IN MEDIATEK SOFTWARE. MEDIATEK SHALL ALSO NOT BE RESPONSIBLE FOR ANY MEDIATEK
+ * SOFTWARE RELEASES MADE TO RECEIVER'S SPECIFICATION OR TO CONFORM TO A PARTICULAR
+ * STANDARD OR OPEN FORUM. RECEIVER'S SOLE AND EXCLUSIVE REMEDY AND MEDIATEK'S ENTIRE AND
+ * CUMULATIVE LIABILITY WITH RESPECT TO THE MEDIATEK SOFTWARE RELEASED HEREUNDER WILL BE,
+ * AT MEDIATEK'S OPTION, TO REVISE OR REPLACE THE MEDIATEK SOFTWARE AT ISSUE,
+ * OR REFUND ANY SOFTWARE LICENSE FEES OR SERVICE CHARGE PAID BY RECEIVER TO
+ * MEDIATEK FOR SUCH MEDIATEK SOFTWARE AT ISSUE.
+ */
+
+/*****************************************************************************
+*  Copyright Statement:
+*  --------------------
+*  This software is protected by Copyright and the information contained
+*  herein is confidential. The software may not be copied and the information
+*  contained herein may not be used or disclosed except with the written
+*  permission of MediaTek Inc. (C) 2008
+*
+*  BY OPENING THIS FILE, BUYER HEREBY UNEQUIVOCALLY ACKNOWLEDGES AND AGREES
+*  THAT THE SOFTWARE/FIRMWARE AND ITS DOCUMENTATIONS ("MEDIATEK SOFTWARE")
+*  RECEIVED FROM MEDIATEK AND/OR ITS REPRESENTATIVES ARE PROVIDED TO BUYER ON
+*  AN "AS-IS" BASIS ONLY. MEDIATEK EXPRESSLY DISCLAIMS ANY AND ALL WARRANTIES,
+*  EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE IMPLIED WARRANTIES OF
+*  MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE OR NONINFRINGEMENT.
+*  NEITHER DOES MEDIATEK PROVIDE ANY WARRANTY WHATSOEVER WITH RESPECT TO THE
+*  SOFTWARE OF ANY THIRD PARTY WHICH MAY BE USED BY, INCORPORATED IN, OR
+*  SUPPLIED WITH THE MEDIATEK SOFTWARE, AND BUYER AGREES TO LOOK ONLY TO SUCH
+*  THIRD PARTY FOR ANY WARRANTY CLAIM RELATING THERETO. MEDIATEK SHALL ALSO
+*  NOT BE RESPONSIBLE FOR ANY MEDIATEK SOFTWARE RELEASES MADE TO BUYER'S
+*  SPECIFICATION OR TO CONFORM TO A PARTICULAR STANDARD OR OPEN FORUM.
+*
+*  BUYER'S SOLE AND EXCLUSIVE REMEDY AND MEDIATEK'S ENTIRE AND CUMULATIVE
+*  LIABILITY WITH RESPECT TO THE MEDIATEK SOFTWARE RELEASED HEREUNDER WILL BE,
+*  AT MEDIATEK'S OPTION, TO REVISE OR REPLACE THE MEDIATEK SOFTWARE AT ISSUE,
+*  OR REFUND ANY SOFTWARE LICENSE FEES OR SERVICE CHARGE PAID BY BUYER TO
+*  MEDIATEK FOR SUCH MEDIATEK SOFTWARE AT ISSUE.
+*
+*  THE TRANSACTION CONTEMPLATED HEREUNDER SHALL BE CONSTRUED IN ACCORDANCE
+*  WITH THE LAWS OF THE STATE OF CALIFORNIA, USA, EXCLUDING ITS CONFLICT OF
+*  LAWS PRINCIPLES.  ANY DISPUTES, CONTROVERSIES OR CLAIMS ARISING THEREOF AND
+*  RELATED THERETO SHALL BE SETTLED BY ARBITRATION IN SAN FRANCISCO, CA, UNDER
+*  THE RULES OF THE INTERNATIONAL CHAMBER OF COMMERCE (ICC).
+*
+*****************************************************************************/
+/*****************************************************************************
+ *
+ * Filename:
+ * ---------
+ *   sensor.h
+ *
+ * Project:
+ * --------
+ *   DUMA
+ *
+ * Description:
+ * ------------
+ *   Header file of camera customized parameters.
+ *
+ *
+ * Author:
+ * -------
+ *   Leo Lee
+ *
+ *============================================================================
+ *             HISTORY
+ *------------------------------------------------------------------------------
+ * $Revision:$
+ * $Modtime:$
+ * $Log:$
+ *
+ * 03 01 2013
+ * First release GC2355MIPI driver Version 1.0
+ *
+ *------------------------------------------------------------------------------
+ *============================================================================
+ ****************************************************************************/
+
+#ifndef __CAMERA_CUSTOMIZED_H
+#define __CAMERA_CUSTOMIZED_H
+
+// the angle between handset and sensor placement in clockwise, should be one of 0, 90, 270
+#define MAIN_SENSOR_ORIENTATION_ANGLE  90
+#define SUB_SENSOR_ORIENTATION_ANGLE   0               // do not care if the sub sensor does not exist
+
+
+// First, we think you hold the cell phone vertical.
+// Second, we suppose the direction of upward is 0
+// Third, it is 90, 180, 270 in clockwise
+// here we define the main sensor and sub sensor angles to deal with the jpeg orientation
+#define MAIN_SENSOR_TO_PHONE_ANGLE     90
+#define SUB_SENSOR_TO_PHONE_ANGLE      0
+
+
+#define CAM_SIZE_QVGA_WIDTH    320
+#define CAM_SIZE_QVGA_HEIGHT   240
+#define CAM_SIZE_VGA_WIDTH             640
+#define CAM_SIZE_VGA_HEIGHT    480
+#define CAM_SIZE_05M_WIDTH             800
+#define CAM_SIZE_05M_HEIGHT    600
+#define CAM_SIZE_1M_WIDTH              1280
+#define CAM_SIZE_1M_HEIGHT             960
+#define CAM_SIZE_2M_WIDTH              1600
+#define CAM_SIZE_2M_HEIGHT             1200
+#define CAM_SIZE_3M_WIDTH              2048
+#define CAM_SIZE_3M_HEIGHT             1536
+#define CAM_SIZE_5M_WIDTH              2592
+#define CAM_SIZE_5M_HEIGHT             1944
+// for main sensor
+#define MAIN_NUM_OF_PREVIEW_RESOLUTION 3
+#define MAIN_NUM_OF_VIDEO_RESOLUTION 4
+#define MAIN_NUM_OF_STILL_RESOLUTION 7
+#define MAIN_VIDEO_RESOLUTION_PROFILE          {{176,144},{320,240},{640,480},{720,480}}
+#define MAIN_PREVIEW_RESOLUTION_PROFILE        {{232,174},{320,240},{240,320}}
+#define MAIN_STILL_RESOLUTION_PROFILE          {{CAM_SIZE_QVGA_WIDTH,CAM_SIZE_QVGA_HEIGHT}, \
+                                                                        {CAM_SIZE_VGA_WIDTH,CAM_SIZE_VGA_HEIGHT}, \
+                                                                        {CAM_SIZE_05M_WIDTH,CAM_SIZE_05M_HEIGHT}, \
+                                                                        {CAM_SIZE_1M_WIDTH,CAM_SIZE_1M_HEIGHT}, \
+                                                                        {CAM_SIZE_2M_WIDTH,CAM_SIZE_2M_HEIGHT}, \
+                                                                        {CAM_SIZE_3M_WIDTH,CAM_SIZE_3M_HEIGHT}, \
+                                                                        {CAM_SIZE_5M_WIDTH,CAM_SIZE_5M_HEIGHT}}
+
+// if sub sensor does not exist, set all the parameters as 0
+#define SUB_NUM_OF_PREVIEW_RESOLUTION 0
+#define SUB_NUM_OF_VIDEO_RESOLUTION 0
+#define SUB_NUM_OF_STILL_RESOLUTION 0
+#define SUB_VIDEO_RESOLUTION_PROFILE           {{0,0}}
+#define SUB_PREVIEW_RESOLUTION_PROFILE         {{0,0}}
+#define SUB_STILL_RESOLUTION_PROFILE           {{0,0}}
+
+//#define NUM_OF_PREVIEW_RESOLUTION    max(MAIN_NUM_OF_PREVIEW_RESOLUTION,SUB_NUM_OF_PREVIEW_RESOLUTION)
+//#define NUM_OF_VIDEO_RESOLUTION      max(MAIN_NUM_OF_VIDEO_RESOLUTION,SUB_NUM_OF_VIDEO_RESOLUTION)
+//#define NUM_OF_STILL_RESOLUTION      max(MAIN_NUM_OF_STILL_RESOLUTION,SUB_NUM_OF_STILL_RESOLUTION)
+
+#define NUM_OF_VIDEO_STREAM_BUFF       8       // Maximun is 8
+#endif
diff --git a/drivers/misc/mediatek/imgsensor/src/mt8127/gc2355_mipi_raw/gc2355mipi_Camera_Sensor_para.h b/drivers/misc/mediatek/imgsensor/src/mt8127/gc2355_mipi_raw/gc2355mipi_Camera_Sensor_para.h
new file mode 100644 (file)
index 0000000..0f75967
--- /dev/null
@@ -0,0 +1,90 @@
+/*****************************************************************************
+*  Copyright Statement:
+*  --------------------
+*  This software is protected by Copyright and the information contained
+*  herein is confidential. The software may not be copied and the information
+*  contained herein may not be used or disclosed except with the written
+*  permission of MediaTek Inc. (C) 2008
+*
+*  BY OPENING THIS FILE, BUYER HEREBY UNEQUIVOCALLY ACKNOWLEDGES AND AGREES
+*  THAT THE SOFTWARE/FIRMWARE AND ITS DOCUMENTATIONS ("MEDIATEK SOFTWARE")
+*  RECEIVED FROM MEDIATEK AND/OR ITS REPRESENTATIVES ARE PROVIDED TO BUYER ON
+*  AN "AS-IS" BASIS ONLY. MEDIATEK EXPRESSLY DISCLAIMS ANY AND ALL WARRANTIES,
+*  EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE IMPLIED WARRANTIES OF
+*  MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE OR NONINFRINGEMENT.
+*  NEITHER DOES MEDIATEK PROVIDE ANY WARRANTY WHATSOEVER WITH RESPECT TO THE 
+*  SOFTWARE OF ANY THIRD PARTY WHICH MAY BE USED BY, INCORPORATED IN, OR
+*  SUPPLIED WITH THE MEDIATEK SOFTWARE, AND BUYER AGREES TO LOOK ONLY TO SUCH
+*  THIRD PARTY FOR ANY WARRANTY CLAIM RELATING THERETO. MEDIATEK SHALL ALSO
+*  NOT BE RESPONSIBLE FOR ANY MEDIATEK SOFTWARE RELEASES MADE TO BUYER'S
+*  SPECIFICATION OR TO CONFORM TO A PARTICULAR STANDARD OR OPEN FORUM.
+*
+*  BUYER'S SOLE AND EXCLUSIVE REMEDY AND MEDIATEK'S ENTIRE AND CUMULATIVE
+*  LIABILITY WITH RESPECT TO THE MEDIATEK SOFTWARE RELEASED HEREUNDER WILL BE,
+*  AT MEDIATEK'S OPTION, TO REVISE OR REPLACE THE MEDIATEK SOFTWARE AT ISSUE,
+*  OR REFUND ANY SOFTWARE LICENSE FEES OR SERVICE CHARGE PAID BY BUYER TO
+*  MEDIATEK FOR SUCH MEDIATEK SOFTWARE AT ISSUE.
+*
+*  THE TRANSACTION CONTEMPLATED HEREUNDER SHALL BE CONSTRUED IN ACCORDANCE
+*  WITH THE LAWS OF THE STATE OF CALIFORNIA, USA, EXCLUDING ITS CONFLICT OF
+*  LAWS PRINCIPLES.  ANY DISPUTES, CONTROVERSIES OR CLAIMS ARISING THEREOF AND
+*  RELATED THERETO SHALL BE SETTLED BY ARBITRATION IN SAN FRANCISCO, CA, UNDER
+*  THE RULES OF THE INTERNATIONAL CHAMBER OF COMMERCE (ICC).
+*
+*****************************************************************************/
+/*****************************************************************************
+ *
+ * Filename:
+ * ---------
+ *   camera_sensor_para.h
+ *
+ * Project:
+ * --------
+ *   DUMA
+ *
+ * Description:
+ * ------------
+ *   Header file of Sensor tuning parameters that should be generated by CCT
+ *
+ *
+ * Author:
+ * -------
+ *   Leo Lee
+ *
+ *============================================================================
+ *             HISTORY
+ *------------------------------------------------------------------------------
+ * $Revision:$
+ * $Modtime:$
+ * $Log:$
+ *
+ * 03 01 2013
+ * First release GC2355MIPI driver Version 1.0
+ *
+ *------------------------------------------------------------------------------
+ *============================================================================
+ ****************************************************************************/
+#ifndef _GC2355MIPI_CAMERA_SENSOR_PARA_H
+#define _GC2355MIPI_CAMERA_SENSOR_PARA_H
+
+#define GC2355MIPI_CAMERA_SENSOR_REG_DEFAULT_VALUE \
+{ \
+  {0xFFFFFFFF,0xFFFFFFFF},{0xFFFFFFFF,0xFFFFFFFF},{0xFFFFFFFF,0xFFFFFFFF},{0xFFFFFFFF,0xFFFFFFFF}, \
+  {0xFFFFFFFF,0xFFFFFFFF},{0xFFFFFFFF,0xFFFFFFFF},{0xFFFFFFFF,0xFFFFFFFF},{0xFFFFFFFF,0xFFFFFFFF}, \
+  {0xFFFFFFFF,0xFFFFFFFF},{0xFFFFFFFF,0xFFFFFFFF},{0xFFFFFFFF,0xFFFFFFFF},{0xFFFFFFFF,0xFFFFFFFF}, \
+  {0xFFFFFFFF,0xFFFFFFFF},{0xFFFFFFFF,0xFFFFFFFF},{0xFFFFFFFF,0xFFFFFFFF},{0xFFFFFFFF,0xFFFFFFFF}, \
+  {0xFFFFFFFF,0xFFFFFFFF},{0xFFFFFFFF,0xFFFFFFFF},{0xFFFFFFFF,0xFFFFFFFF},{0xFFFFFFFF,0xFFFFFFFF}, \
+  {0xFFFFFFFF,0xFFFFFFFF},{0xFFFFFFFF,0xFFFFFFFF},{0xFFFFFFFF,0xFFFFFFFF},{0xFFFFFFFF,0xFFFFFFFF}, \
+  {0xFFFFFFFF,0xFFFFFFFF},{0xFFFFFFFF,0xFFFFFFFF},{0xFFFFFFFF,0xFFFFFFFF},{0xFFFFFFFF,0xFFFFFFFF}, \
+  {0xFFFFFFFF,0xFFFFFFFF},{0xFFFFFFFF,0xFFFFFFFF},{0xFFFFFFFF,0xFFFFFFFF},{0xFFFFFFFF,0xFFFFFFFF}, \
+  {0xFFFFFFFF,0xFFFFFFFF},{0xFFFFFFFF,0xFFFFFFFF},{0xFFFFFFFF,0xFFFFFFFF},{0xFFFFFFFF,0xFFFFFFFF}, \
+  {0xFFFFFFFF,0xFFFFFFFF},{0xFFFFFFFF,0xFFFFFFFF},{0xFFFFFFFF,0xFFFFFFFF},{0xFFFFFFFF,ISP_DRIVING_6MA}, \
+}
+
+#define GC2355MIPI_CAMERA_SENSOR_CCT_DEFAULT_VALUE \
+{ \
+  {0xFFFFFFFF,0x40},{0xFFFFFFFF,0x40},{0xFFFFFFFF,0x40},{0xFFFFFFFF,0x40},{0xFFFFFFFF,0x40}, \
+}
+
+#endif /* __CAMERA_SENSOR_PARA_H */
+/* SENSOR FULL SIZE */
diff --git a/drivers/misc/mediatek/imgsensor/src/mt8127/gc2355_mipi_raw/gc2355mipi_Sensor.c b/drivers/misc/mediatek/imgsensor/src/mt8127/gc2355_mipi_raw/gc2355mipi_Sensor.c
new file mode 100644 (file)
index 0000000..0950de8
--- /dev/null
@@ -0,0 +1,1304 @@
+/*****************************************************************************
+ *
+ * Filename:
+ * ---------
+ *   sensor.c
+ *
+ * Project:
+ * --------
+ *   RAW
+ *
+ * Description:
+ * ------------
+ *   Source code of Sensor driver
+ *
+ *
+ * Author:
+ * -------
+ *   Leo Lee
+ *
+ *============================================================================
+ *             HISTORY
+ *------------------------------------------------------------------------------
+ * $Revision:$
+ * $Modtime:$
+ * $Log:$
+ *
+ * 04 10  2013
+ * First release MT6589 GC2355MIPI driver Version 1.0
+ *
+ *------------------------------------------------------------------------------
+ *============================================================================
+ ****************************************************************************/
+
+#include <linux/videodev2.h>
+#include <linux/i2c.h>
+#include <linux/platform_device.h>
+#include <linux/delay.h>
+#include <linux/cdev.h>
+#include <linux/uaccess.h>
+#include <linux/fs.h>
+#include <asm/atomic.h>
+
+#include "kd_camera_hw.h"
+#include "kd_imgsensor.h"
+#include "kd_imgsensor_define.h"
+#include "kd_imgsensor_errcode.h"
+
+#include "gc2355mipi_Sensor.h"
+#include "gc2355mipi_Camera_Sensor_para.h"
+#include "gc2355mipi_CameraCustomized.h"
+
+#ifdef GC2355MIPI_DEBUG
+#define SENSORDB printk
+#else
+#define SENSORDB(x,...)
+#endif
+
+#define GC2355MIPI_2Lane   //MIPI Lane NUM
+
+#if defined(MT6577)||defined(MT6589)
+static DEFINE_SPINLOCK(gc2355mipi_drv_lock);
+#endif
+//static kal_uint16 Half_iShutter=0;
+static kal_bool b_Enable_Half = false;
+extern int iReadRegI2C(u8 *a_pSendData , u16 a_sizeSendData, u8 * a_pRecvData, u16 a_sizeRecvData, u16 i2cId);
+extern int iWriteRegI2C(u8 *a_pSendData , u16 a_sizeSendData, u16 i2cId);
+
+/* SZ TCT xuejian.zhong add for CTS test*/
+static void GC2355GetAFMaxNumFocusAreas(UINT32 *pFeatureReturnPara32)
+{      
+    *pFeatureReturnPara32 = 0;    
+   // SENSORDB("OV2680GetAFMaxNumFocusAreas *pFeatureReturnPara32 = %d¥n",  *pFeatureReturnPara32);
+}
+
+static void GC2355GetAEMaxNumMeteringAreas(UINT32 *pFeatureReturnPara32)
+{     
+    *pFeatureReturnPara32 = 0;    
+   // SENSORDB("OV2680GetAEMaxNumMeteringAreas *pFeatureReturnPara32 = %d¥n",  *pFeatureReturnPara32);        
+}
+
+static void GC2355GetExifInfo(UINT32 exifAddr)
+{
+    SENSOR_EXIF_INFO_STRUCT* pExifInfo = (SENSOR_EXIF_INFO_STRUCT*)exifAddr;
+    pExifInfo->FNumber = 28;
+    pExifInfo->AEISOSpeed = AE_ISO_100;
+    pExifInfo->AWBMode = AWB_MODE_AUTO;
+    pExifInfo->CapExposureTime = 0;
+    pExifInfo->FlashLightTimeus = 0;
+    pExifInfo->RealISOValue = AE_ISO_100;
+}
+
+/* SZ TCT xuejian.zhong  end */
+
+
+
+static GC2355MIPI_sensor_struct GC2355MIPI_sensor =
+{
+       .eng_info =
+       {
+               .SensorId = 128,
+               .SensorType = CMOS_SENSOR,
+               .SensorOutputDataFormat = GC2355MIPI_COLOR_FORMAT,
+       },
+       .Mirror = GC2355MIPI_IMAGE_H_MIRROR,
+       .shutter = 0x20,  
+       .gain = 0x20,
+       .pclk = GC2355MIPI_PREVIEW_CLK,
+       .frame_height = GC2355MIPI_PV_PERIOD_LINE_NUMS,
+       .line_length = GC2355MIPI_PV_PERIOD_PIXEL_NUMS,
+};
+
+
+/*************************************************************************
+* FUNCTION
+*    GC2355MIPI_write_cmos_sensor
+*
+* DESCRIPTION
+*    This function wirte data to CMOS sensor through I2C
+*
+* PARAMETERS
+*    addr: the 16bit address of register
+*    para: the 8bit value of register
+*
+* RETURNS 
+*    None
+*
+* LOCAL AFFECTED
+*
+*************************************************************************/
+static void GC2355MIPI_write_cmos_sensor(kal_uint8 addr, kal_uint8 para)
+{
+kal_uint8 out_buff[2];
+
+    out_buff[0] = addr;
+    out_buff[1] = para;
+
+    iWriteRegI2C((u8*)out_buff , (u16)sizeof(out_buff), GC2355MIPI_WRITE_ID); 
+}
+
+/*************************************************************************
+* FUNCTION
+*    GC2035_read_cmos_sensor
+*
+* DESCRIPTION
+*    This function read data from CMOS sensor through I2C.
+*
+* PARAMETERS
+*    addr: the 16bit address of register
+*
+* RETURNS
+*    8bit data read through I2C
+*
+* LOCAL AFFECTED
+*
+*************************************************************************/
+static kal_uint8 GC2355MIPI_read_cmos_sensor(kal_uint8 addr)
+{
+  kal_uint8 in_buff[1] = {0xFF};
+  kal_uint8 out_buff[1];
+  
+  out_buff[0] = addr;
+
+    if (0 != iReadRegI2C((u8*)out_buff , (u16) sizeof(out_buff), (u8*)in_buff, (u16) sizeof(in_buff), GC2355MIPI_WRITE_ID)) {
+        SENSORDB("ERROR: GC2355MIPI_read_cmos_sensor \n");
+    }
+  return in_buff[0];
+}
+
+/*************************************************************************
+* FUNCTION
+*      GC2355MIPI_SetShutter
+*
+* DESCRIPTION
+*      This function set e-shutter of GC2355MIPI to change exposure time.
+*
+* PARAMETERS
+*   iShutter : exposured lines
+*
+* RETURNS
+*      None
+*
+* GLOBALS AFFECTED
+*
+*************************************************************************/
+void GC2355MIPI_set_shutter(kal_uint16 iShutter)
+{
+#if defined(MT6577)||defined(MT6589)
+       spin_lock(&gc2355mipi_drv_lock);
+#endif
+       GC2355MIPI_sensor.shutter = iShutter;
+#if defined(MT6577)||defined(MT6589)
+       spin_unlock(&gc2355mipi_drv_lock);
+#endif
+
+       if (!iShutter) iShutter = 1; /* avoid 0 */
+       
+#ifdef GC2355MIPI_DRIVER_TRACE
+       SENSORDB("GC2355MIPI_set_shutter iShutter = %d \n",iShutter);
+#endif
+       if(iShutter < 7) iShutter = 7;
+       if(iShutter > 16383) iShutter = 16383;//2^14
+       //Update Shutter
+       GC2355MIPI_write_cmos_sensor(0x04, (iShutter) & 0xFF);
+       GC2355MIPI_write_cmos_sensor(0x03, (iShutter >> 8) & 0x3F);     
+}   /*  Set_GC2355MIPI_Shutter */
+
+/*************************************************************************
+* FUNCTION
+*      GC2355MIPI_SetGain
+*
+* DESCRIPTION
+*      This function is to set global gain to sensor.
+*
+* PARAMETERS
+*   iGain : sensor global gain(base: 0x40)
+*
+* RETURNS 
+*      the actually gain set to sensor.
+*
+* GLOBALS AFFECTED
+*
+*************************************************************************/
+#define ANALOG_GAIN_1 64  // 1.00x
+#define ANALOG_GAIN_2 88  // 1.375x
+#define ANALOG_GAIN_3 122  // 1.90x
+#define ANALOG_GAIN_4 168  // 2.625x
+#define ANALOG_GAIN_5 239  // 3.738x
+#define ANALOG_GAIN_6 330  // 5.163x
+#define ANALOG_GAIN_7 470  // 7.350x
+
+kal_uint16  GC2355MIPI_SetGain(kal_uint16 iGain)
+{
+               kal_uint16 iReg,temp,temp1,luma_value;
+               
+       #ifdef GC2355MIPI_DRIVER_TRACE
+       SENSORDB("GC2355MIPI_SetGain iGain = %d \n",iGain);
+       #endif
+       GC2355MIPI_write_cmos_sensor(0xb1, 0x01);
+       GC2355MIPI_write_cmos_sensor(0xb2, 0x00);
+
+       iReg = iGain;
+       if(iReg < 0x40)
+               iReg = 0x40;
+       if((ANALOG_GAIN_1<= iReg)&&(iReg < ANALOG_GAIN_2))
+       {
+               //analog gain
+               GC2355MIPI_write_cmos_sensor(0xb6,  0x00);// 
+               temp = iReg;
+               GC2355MIPI_write_cmos_sensor(0xb1, temp>>6);
+               GC2355MIPI_write_cmos_sensor(0xb2, (temp<<2)&0xfc);
+               //SENSORDB("GC2355 analogic gain 1x , add pregain = %d\n",temp);
+       
+       }
+       else if((ANALOG_GAIN_2<= iReg)&&(iReg < ANALOG_GAIN_3))
+       {
+               //analog gain
+               GC2355MIPI_write_cmos_sensor(0xb6,  0x01);// 
+               temp = 64*iReg/ANALOG_GAIN_2;
+               GC2355MIPI_write_cmos_sensor(0xb1, temp>>6);
+               GC2355MIPI_write_cmos_sensor(0xb2, (temp<<2)&0xfc);
+               //SENSORDB("GC2355 analogic gain 1.375x , add pregain = %d\n",temp);
+       }
+
+       else if((ANALOG_GAIN_3<= iReg)&&(iReg < ANALOG_GAIN_4))
+       {
+               //analog gain
+               GC2355MIPI_write_cmos_sensor(0xb6,  0x02);//
+               temp = 64*iReg/ANALOG_GAIN_3;
+               GC2355MIPI_write_cmos_sensor(0xb1, temp>>6);
+               GC2355MIPI_write_cmos_sensor(0xb2, (temp<<2)&0xfc);
+               //SENSORDB("GC2355 analogic gain 1.90x , add pregain = %d\n",temp);
+       }
+
+       else if(ANALOG_GAIN_4<= iReg)
+       {
+               //analog gain
+               GC2355MIPI_write_cmos_sensor(0xb6,  0x03);//
+               temp = 64*iReg/ANALOG_GAIN_4;
+               GC2355MIPI_write_cmos_sensor(0xb1, temp>>6);
+               GC2355MIPI_write_cmos_sensor(0xb2, (temp<<2)&0xfc);
+               //SENSORDB("GC2355 analogic gain 2.625x" , add pregain = %d\n",temp);
+       }
+/*     else if((ANALOG_GAIN_4<= iReg)&&(iReg < ANALOG_GAIN_5))
+       {
+               //analog gain
+               GC2355MIPI_write_cmos_sensor(0xb6,  0x03);//
+               temp = 64*iReg/ANALOG_GAIN_4;
+               GC2355MIPI_write_cmos_sensor(0xb1, temp>>6);
+               GC2355MIPI_write_cmos_sensor(0xb2, (temp<<2)&0xfc);
+               //SENSORDB("GC2355 analogic gain 2.625x , add pregain = %d\n",temp);
+       }
+
+       else if((ANALOG_GAIN_5<= iReg)&&(iReg)&&(iReg < ANALOG_GAIN_6))
+       {
+               //analog gain
+               GC2355MIPI_write_cmos_sensor(0xb6,  0x04);//
+               temp = 64*iReg/ANALOG_GAIN_5;
+               GC2355MIPI_write_cmos_sensor(0xb1, temp>>6);
+               GC2355MIPI_write_cmos_sensor(0xb2, (temp<<2)&0xfc);
+               //SENSORDB("GC2355 analogic gain 3.738x , add pregain = %d\n",temp);
+       }
+
+       else if((ANALOG_GAIN_6<= iReg)&&(iReg < ANALOG_GAIN_7))
+       {
+               //analog gain
+               GC2355MIPI_write_cmos_sensor(0xb6,  0x05);//
+               temp = 64*iReg/ANALOG_GAIN_6;
+               GC2355MIPI_write_cmos_sensor(0xb1, temp>>6);
+               GC2355MIPI_write_cmos_sensor(0xb2, (temp<<2)&0xfc);
+               //SENSORDB("GC2355 analogic gain 5.163x , add pregain = %d\n",temp);
+       }
+       else if(ANALOG_GAIN_7<= iReg)
+       {
+               //analog gain
+               GC2355MIPI_write_cmos_sensor(0xb6,  0x06);//
+               temp = 64*iReg/ANALOG_GAIN_7;
+               GC2355MIPI_write_cmos_sensor(0xb1, temp>>6);
+               GC2355MIPI_write_cmos_sensor(0xb2, (temp<<2)&0xfc);
+               //SENSORDB("GC2355 analogic gain 7.350x" , add pregain = %d\n",temp);
+       }
+#endif*/
+       
+       return iGain;
+}
+/*************************************************************************
+* FUNCTION
+*      GC2355MIPI_NightMode
+*
+* DESCRIPTION
+*      This function night mode of GC2355MIPI.
+*
+* PARAMETERS
+*      bEnable: KAL_TRUE -> enable night mode, otherwise, disable night mode
+*
+* RETURNS
+*      None
+*
+* GLOBALS AFFECTED
+*
+*************************************************************************/
+void GC2355MIPI_night_mode(kal_bool enable)
+{
+/*No Need to implement this function*/
+#if 0 
+       const kal_uint16 dummy_pixel = GC2355MIPI_sensor.line_length - GC2355MIPI_PV_PERIOD_PIXEL_NUMS;
+       const kal_uint16 pv_min_fps =  enable ? GC2355MIPI_sensor.night_fps : GC2355MIPI_sensor.normal_fps;
+       kal_uint16 dummy_line = GC2355MIPI_sensor.frame_height - GC2355MIPI_PV_PERIOD_LINE_NUMS;
+       kal_uint16 max_exposure_lines;
+       
+       printk("[GC2355MIPI_night_mode]enable=%d",enable);
+       if (!GC2355MIPI_sensor.video_mode) return;
+       max_exposure_lines = GC2355MIPI_sensor.pclk * GC2355MIPI_FPS(1) / (pv_min_fps * GC2355MIPI_sensor.line_length);
+       if (max_exposure_lines > GC2355MIPI_sensor.frame_height) /* fix max frame rate, AE table will fix min frame rate */
+//     {
+//       dummy_line = max_exposure_lines - GC2355MIPI_PV_PERIOD_LINE_NUMS;
+//     }
+#endif
+}   /*  GC2355MIPI_NightMode    */
+
+
+/* write camera_para to sensor register */
+static void GC2355MIPI_camera_para_to_sensor(void)
+{
+  kal_uint32 i;
+#ifdef GC2355MIPI_DRIVER_TRACE
+        SENSORDB("GC2355MIPI_camera_para_to_sensor\n");
+#endif
+  for (i = 0; 0xFFFFFFFF != GC2355MIPI_sensor.eng.reg[i].Addr; i++)
+  {
+    GC2355MIPI_write_cmos_sensor(GC2355MIPI_sensor.eng.reg[i].Addr, GC2355MIPI_sensor.eng.reg[i].Para);
+  }
+  for (i = GC2355MIPI_FACTORY_START_ADDR; 0xFFFFFFFF != GC2355MIPI_sensor.eng.reg[i].Addr; i++)
+  {
+    GC2355MIPI_write_cmos_sensor(GC2355MIPI_sensor.eng.reg[i].Addr, GC2355MIPI_sensor.eng.reg[i].Para);
+  }
+  GC2355MIPI_SetGain(GC2355MIPI_sensor.gain); /* update gain */
+}
+
+/* update camera_para from sensor register */
+static void GC2355MIPI_sensor_to_camera_para(void)
+{
+  kal_uint32 i,temp_data;
+#ifdef GC2355MIPI_DRIVER_TRACE
+   SENSORDB("GC2355MIPI_sensor_to_camera_para\n");
+#endif
+  for (i = 0; 0xFFFFFFFF != GC2355MIPI_sensor.eng.reg[i].Addr; i++)
+  {
+       temp_data = GC2355MIPI_read_cmos_sensor(GC2355MIPI_sensor.eng.reg[i].Addr);
+#if defined(MT6577)||defined(MT6589)
+       spin_lock(&gc2355mipi_drv_lock);
+#endif
+    GC2355MIPI_sensor.eng.reg[i].Para = temp_data;
+#if defined(MT6577)||defined(MT6589)
+       spin_unlock(&gc2355mipi_drv_lock);
+#endif
+  }
+  for (i = GC2355MIPI_FACTORY_START_ADDR; 0xFFFFFFFF != GC2355MIPI_sensor.eng.reg[i].Addr; i++)
+  {
+       temp_data = GC2355MIPI_read_cmos_sensor(GC2355MIPI_sensor.eng.reg[i].Addr);
+#if defined(MT6577)||defined(MT6589)
+       spin_lock(&gc2355mipi_drv_lock);
+#endif
+    GC2355MIPI_sensor.eng.reg[i].Para = temp_data;
+#if defined(MT6577)||defined(MT6589)
+       spin_unlock(&gc2355mipi_drv_lock);
+#endif
+  }
+}
+
+/* ------------------------ Engineer mode ------------------------ */
+inline static void GC2355MIPI_get_sensor_group_count(kal_int32 *sensor_count_ptr)
+{
+#ifdef GC2355MIPI_DRIVER_TRACE
+   SENSORDB("GC2355MIPI_get_sensor_group_count\n");
+#endif
+  *sensor_count_ptr = GC2355MIPI_GROUP_TOTAL_NUMS;
+}
+
+inline static void GC2355MIPI_get_sensor_group_info(MSDK_SENSOR_GROUP_INFO_STRUCT *para)
+{
+#ifdef GC2355MIPI_DRIVER_TRACE
+   SENSORDB("GC2355MIPI_get_sensor_group_info\n");
+#endif
+  switch (para->GroupIdx)
+  {
+  case GC2355MIPI_PRE_GAIN:
+    sprintf(para->GroupNamePtr, "CCT");
+    para->ItemCount = 5;
+    break;
+  case GC2355MIPI_CMMCLK_CURRENT:
+    sprintf(para->GroupNamePtr, "CMMCLK Current");
+    para->ItemCount = 1;
+    break;
+  case GC2355MIPI_FRAME_RATE_LIMITATION:
+    sprintf(para->GroupNamePtr, "Frame Rate Limitation");
+    para->ItemCount = 2;
+    break;
+  case GC2355MIPI_REGISTER_EDITOR:
+    sprintf(para->GroupNamePtr, "Register Editor");
+    para->ItemCount = 2;
+    break;
+  default:
+    ASSERT(0);
+  }
+}
+
+inline static void GC2355MIPI_get_sensor_item_info(MSDK_SENSOR_ITEM_INFO_STRUCT *para)
+{
+
+  const static kal_char *cct_item_name[] = {"SENSOR_BASEGAIN", "Pregain-R", "Pregain-Gr", "Pregain-Gb", "Pregain-B"};
+  const static kal_char *editer_item_name[] = {"REG addr", "REG value"};
+  
+#ifdef GC2355MIPI_DRIVER_TRACE
+        SENSORDB("GC2355MIPI_get_sensor_item_info\n");
+#endif
+  switch (para->GroupIdx)
+  {
+  case GC2355MIPI_PRE_GAIN:
+    switch (para->ItemIdx)
+    {
+    case GC2355MIPI_SENSOR_BASEGAIN:
+    case GC2355MIPI_PRE_GAIN_R_INDEX:
+    case GC2355MIPI_PRE_GAIN_Gr_INDEX:
+    case GC2355MIPI_PRE_GAIN_Gb_INDEX:
+    case GC2355MIPI_PRE_GAIN_B_INDEX:
+      break;
+    default:
+      ASSERT(0);
+    }
+    sprintf(para->ItemNamePtr, cct_item_name[para->ItemIdx - GC2355MIPI_SENSOR_BASEGAIN]);
+    para->ItemValue = GC2355MIPI_sensor.eng.cct[para->ItemIdx].Para * 1000 / BASEGAIN;
+    para->IsTrueFalse = para->IsReadOnly = para->IsNeedRestart = KAL_FALSE;
+    para->Min = GC2355MIPI_MIN_ANALOG_GAIN * 1000;
+    para->Max = GC2355MIPI_MAX_ANALOG_GAIN * 1000;
+    break;
+  case GC2355MIPI_CMMCLK_CURRENT:
+    switch (para->ItemIdx)
+    {
+    case 0:
+      sprintf(para->ItemNamePtr, "Drv Cur[2,4,6,8]mA");
+      switch (GC2355MIPI_sensor.eng.reg[GC2355MIPI_CMMCLK_CURRENT_INDEX].Para)
+      {
+      case ISP_DRIVING_2MA:
+        para->ItemValue = 2;
+        break;
+      case ISP_DRIVING_4MA:
+        para->ItemValue = 4;
+        break;
+      case ISP_DRIVING_6MA:
+        para->ItemValue = 6;
+        break;
+      case ISP_DRIVING_8MA:
+        para->ItemValue = 8;
+        break;
+      default:
+        ASSERT(0);
+      }
+      para->IsTrueFalse = para->IsReadOnly = KAL_FALSE;
+      para->IsNeedRestart = KAL_TRUE;
+      para->Min = 2;
+      para->Max = 8;
+      break;
+    default:
+      ASSERT(0);
+    }
+    break;
+  case GC2355MIPI_FRAME_RATE_LIMITATION:
+    switch (para->ItemIdx)
+    {
+    case 0:
+      sprintf(para->ItemNamePtr, "Max Exposure Lines");
+      para->ItemValue = 5998;
+      break;
+    case 1:
+      sprintf(para->ItemNamePtr, "Min Frame Rate");
+      para->ItemValue = 5;
+      break;
+    default:
+      ASSERT(0);
+    }
+    para->IsTrueFalse = para->IsNeedRestart = KAL_FALSE;
+    para->IsReadOnly = KAL_TRUE;
+    para->Min = para->Max = 0;
+    break;
+  case GC2355MIPI_REGISTER_EDITOR:
+    switch (para->ItemIdx)
+    {
+    case 0:
+    case 1:
+      sprintf(para->ItemNamePtr, editer_item_name[para->ItemIdx]);
+      para->ItemValue = 0;
+      para->IsTrueFalse = para->IsReadOnly = para->IsNeedRestart = KAL_FALSE;
+      para->Min = 0;
+      para->Max = (para->ItemIdx == 0 ? 0xFFFF : 0xFF);
+      break;
+    default:
+      ASSERT(0);
+    }
+    break;
+  default:
+    ASSERT(0);
+  }
+}
+
+inline static kal_bool GC2355MIPI_set_sensor_item_info(MSDK_SENSOR_ITEM_INFO_STRUCT *para)
+{
+  kal_uint16 temp_para;
+#ifdef GC2355MIPI_DRIVER_TRACE
+   SENSORDB("GC2355MIPI_set_sensor_item_info\n");
+#endif
+  switch (para->GroupIdx)
+  {
+  case GC2355MIPI_PRE_GAIN:
+    switch (para->ItemIdx)
+    {
+    case GC2355MIPI_SENSOR_BASEGAIN:
+    case GC2355MIPI_PRE_GAIN_R_INDEX:
+    case GC2355MIPI_PRE_GAIN_Gr_INDEX:
+    case GC2355MIPI_PRE_GAIN_Gb_INDEX:
+    case GC2355MIPI_PRE_GAIN_B_INDEX:
+#if defined(MT6577)||defined(MT6589)
+               spin_lock(&gc2355mipi_drv_lock);
+#endif
+      GC2355MIPI_sensor.eng.cct[para->ItemIdx].Para = para->ItemValue * BASEGAIN / 1000;
+#if defined(MT6577)||defined(MT6589)
+         spin_unlock(&gc2355mipi_drv_lock);
+#endif
+      GC2355MIPI_SetGain(GC2355MIPI_sensor.gain); /* update gain */
+      break;
+    default:
+      ASSERT(0);
+    }
+    break;
+  case GC2355MIPI_CMMCLK_CURRENT:
+    switch (para->ItemIdx)
+    {
+    case 0:
+      switch (para->ItemValue)
+      {
+      case 2:
+        temp_para = ISP_DRIVING_2MA;
+        break;
+      case 3:
+      case 4:
+        temp_para = ISP_DRIVING_4MA;
+        break;
+      case 5:
+      case 6:
+        temp_para = ISP_DRIVING_6MA;
+        break;
+      default:
+        temp_para = ISP_DRIVING_8MA;
+        break;
+      }
+      //GC2355MIPI_set_isp_driving_current(temp_para);
+#if defined(MT6577)||defined(MT6589)
+      spin_lock(&gc2355mipi_drv_lock);
+#endif
+      GC2355MIPI_sensor.eng.reg[GC2355MIPI_CMMCLK_CURRENT_INDEX].Para = temp_para;
+#if defined(MT6577)||defined(MT6589)
+         spin_unlock(&gc2355mipi_drv_lock);
+#endif
+      break;
+    default:
+      ASSERT(0);
+    }
+    break;
+  case GC2355MIPI_FRAME_RATE_LIMITATION:
+    ASSERT(0);
+    break;
+  case GC2355MIPI_REGISTER_EDITOR:
+    switch (para->ItemIdx)
+    {
+      static kal_uint32 fac_sensor_reg;
+    case 0:
+      if (para->ItemValue < 0 || para->ItemValue > 0xFFFF) return KAL_FALSE;
+      fac_sensor_reg = para->ItemValue;
+      break;
+    case 1:
+      if (para->ItemValue < 0 || para->ItemValue > 0xFF) return KAL_FALSE;
+      GC2355MIPI_write_cmos_sensor(fac_sensor_reg, para->ItemValue);
+      break;
+    default:
+      ASSERT(0);
+    }
+    break;
+  default:
+    ASSERT(0);
+  }
+  return KAL_TRUE;
+}
+
+void GC2355MIPI_SetMirrorFlip(GC2355MIPI_IMAGE_MIRROR Mirror)
+{
+/*     switch(Mirror)
+       {
+               case GC2355MIPI_IMAGE_NORMAL://IMAGE_NORMAL:
+                  GC2355MIPI_write_cmos_sensor(0x17,0x14);
+                  GC2355MIPI_write_cmos_sensor(0x92,0x01);
+                  GC2355MIPI_write_cmos_sensor(0x94,0x01);
+                   break;
+               case GC2355MIPI_IMAGE_H_MIRROR://IMAGE_H_MIRROR:
+                  GC2355MIPI_write_cmos_sensor(0x17,0x15);
+                  GC2355MIPI_write_cmos_sensor(0x92,0x01);
+                  GC2355MIPI_write_cmos_sensor(0x94,0x00);
+                   break;
+               case GC2355MIPI_IMAGE_V_MIRROR://IMAGE_V_MIRROR:
+                  GC2355MIPI_write_cmos_sensor(0x17,0x16);
+                  GC2355MIPI_write_cmos_sensor(0x92,0x02);
+                  GC2355MIPI_write_cmos_sensor(0x94,0x01);
+                   break;
+               case GC2355MIPI_IMAGE_HV_MIRROR://IMAGE_HV_MIRROR:
+                  GC2355MIPI_write_cmos_sensor(0x17,0x17);
+                  GC2355MIPI_write_cmos_sensor(0x92,0x02);
+                  GC2355MIPI_write_cmos_sensor(0x94,0x00);
+                   break;
+       }*/
+}
+
+static void GC2355MIPI_Sensor_Init(void)
+{
+       /////////////////////////////////////////////////////
+       //////////////////////   SYS   //////////////////////
+       /////////////////////////////////////////////////////
+       GC2355MIPI_write_cmos_sensor(0xfe,0x80);
+       GC2355MIPI_write_cmos_sensor(0xfe,0x80);
+       GC2355MIPI_write_cmos_sensor(0xfe,0x80);
+       GC2355MIPI_write_cmos_sensor(0xf2,0x00); 
+       GC2355MIPI_write_cmos_sensor(0xf6,0x00); 
+#if defined(GC2355MIPI_2Lane)
+       GC2355MIPI_write_cmos_sensor(0xf7,0x31); 
+#else
+       GC2355MIPI_write_cmos_sensor(0xf7,0x19); 
+#endif
+       GC2355MIPI_write_cmos_sensor(0xf8,0x06); 
+       GC2355MIPI_write_cmos_sensor(0xf9,0x0e); 
+       GC2355MIPI_write_cmos_sensor(0xfa,0x00); 
+       GC2355MIPI_write_cmos_sensor(0xfc,0x06); 
+       GC2355MIPI_write_cmos_sensor(0xfe,0x00);
+       
+       /////////////////////////////////////////////////////
+       ///////////////    ANALOG & CISCTL    ///////////////
+       /////////////////////////////////////////////////////
+       GC2355MIPI_write_cmos_sensor(0x03,0x07); 
+       GC2355MIPI_write_cmos_sensor(0x04,0xd0); 
+       GC2355MIPI_write_cmos_sensor(0x05,0x03);
+       GC2355MIPI_write_cmos_sensor(0x06,0x4c);
+       GC2355MIPI_write_cmos_sensor(0x07,0x00);
+       GC2355MIPI_write_cmos_sensor(0x08,0x12);
+       GC2355MIPI_write_cmos_sensor(0x0a,0x00);
+       GC2355MIPI_write_cmos_sensor(0x0c,0x04);
+       GC2355MIPI_write_cmos_sensor(0x0d,0x04);
+       GC2355MIPI_write_cmos_sensor(0x0e,0xc0);
+       GC2355MIPI_write_cmos_sensor(0x0f,0x06);
+       GC2355MIPI_write_cmos_sensor(0x10,0x50);
+       GC2355MIPI_write_cmos_sensor(0x17,0x17);
+       GC2355MIPI_write_cmos_sensor(0x19,0x0b);
+       GC2355MIPI_write_cmos_sensor(0x1b,0x48);
+       GC2355MIPI_write_cmos_sensor(0x1c,0x12);
+       GC2355MIPI_write_cmos_sensor(0x1d,0x10);
+       GC2355MIPI_write_cmos_sensor(0x1e,0xbc);
+       GC2355MIPI_write_cmos_sensor(0x1f,0xc9);
+       GC2355MIPI_write_cmos_sensor(0x20,0x71);
+       GC2355MIPI_write_cmos_sensor(0x21,0x20);
+       GC2355MIPI_write_cmos_sensor(0x22,0xa0);
+       GC2355MIPI_write_cmos_sensor(0x23,0x51);
+       GC2355MIPI_write_cmos_sensor(0x24,0x19);
+       GC2355MIPI_write_cmos_sensor(0x27,0x20);
+       GC2355MIPI_write_cmos_sensor(0x28,0x00);
+       GC2355MIPI_write_cmos_sensor(0x2b,0x80);// 0x81 20140926
+       GC2355MIPI_write_cmos_sensor(0x2c,0x38);
+       GC2355MIPI_write_cmos_sensor(0x2e,0x16);
+       GC2355MIPI_write_cmos_sensor(0x2f,0x14);
+       GC2355MIPI_write_cmos_sensor(0x30,0x00);
+       GC2355MIPI_write_cmos_sensor(0x31,0x01);
+       GC2355MIPI_write_cmos_sensor(0x32,0x02);
+       GC2355MIPI_write_cmos_sensor(0x33,0x03);
+       GC2355MIPI_write_cmos_sensor(0x34,0x07);
+       GC2355MIPI_write_cmos_sensor(0x35,0x0b);
+       GC2355MIPI_write_cmos_sensor(0x36,0x0f);
+       
+    /////////////////////////////////////////////////////
+       //////////////////////   MIPI   /////////////////////
+       /////////////////////////////////////////////////////
+       GC2355MIPI_write_cmos_sensor(0xfe, 0x03);
+#if defined(GC2355MIPI_2Lane)
+       GC2355MIPI_write_cmos_sensor(0x10, 0x81);
+       GC2355MIPI_write_cmos_sensor(0x01, 0x87);
+       GC2355MIPI_write_cmos_sensor(0x22, 0x03);  
+       GC2355MIPI_write_cmos_sensor(0x23, 0x20);
+       GC2355MIPI_write_cmos_sensor(0x25, 0x10);
+       GC2355MIPI_write_cmos_sensor(0x29, 0x02);
+#else
+       GC2355MIPI_write_cmos_sensor(0x10, 0x80);
+       GC2355MIPI_write_cmos_sensor(0x01, 0x83);
+       GC2355MIPI_write_cmos_sensor(0x22, 0x05);  
+       GC2355MIPI_write_cmos_sensor(0x23, 0x30);
+       GC2355MIPI_write_cmos_sensor(0x25, 0x15);
+       GC2355MIPI_write_cmos_sensor(0x29, 0x06);
+#endif
+       GC2355MIPI_write_cmos_sensor(0x02, 0x00);
+       GC2355MIPI_write_cmos_sensor(0x03, 0x90);
+       GC2355MIPI_write_cmos_sensor(0x04, 0x01);
+       GC2355MIPI_write_cmos_sensor(0x05, 0x00);
+       GC2355MIPI_write_cmos_sensor(0x06, 0xa2);
+       GC2355MIPI_write_cmos_sensor(0x11, 0x2b);
+       GC2355MIPI_write_cmos_sensor(0x12, 0xd0); 
+       GC2355MIPI_write_cmos_sensor(0x13, 0x07); 
+       GC2355MIPI_write_cmos_sensor(0x15, 0x60);
+
+       GC2355MIPI_write_cmos_sensor(0x21, 0x10);
+       GC2355MIPI_write_cmos_sensor(0x24, 0x02);
+       GC2355MIPI_write_cmos_sensor(0x26, 0x08);
+       GC2355MIPI_write_cmos_sensor(0x27, 0x06);
+       GC2355MIPI_write_cmos_sensor(0x2a, 0x0a); 
+       GC2355MIPI_write_cmos_sensor(0x2b, 0x08);
+       
+       GC2355MIPI_write_cmos_sensor(0x40, 0x00);
+       GC2355MIPI_write_cmos_sensor(0x41, 0x00);    
+       GC2355MIPI_write_cmos_sensor(0x42, 0x40);
+       GC2355MIPI_write_cmos_sensor(0x43, 0x06);  
+       GC2355MIPI_write_cmos_sensor(0xfe, 0x00);
+
+       /////////////////////////////////////////////////////
+       //////////////////////   gain   /////////////////////
+       /////////////////////////////////////////////////////
+       GC2355MIPI_write_cmos_sensor(0xb0,0x50);
+       GC2355MIPI_write_cmos_sensor(0xb1,0x01);
+       GC2355MIPI_write_cmos_sensor(0xb2,0x00);
+       GC2355MIPI_write_cmos_sensor(0xb3,0x40);
+       GC2355MIPI_write_cmos_sensor(0xb4,0x40);
+       GC2355MIPI_write_cmos_sensor(0xb5,0x40);
+       GC2355MIPI_write_cmos_sensor(0xb6,0x00);
+
+       /////////////////////////////////////////////////////
+       //////////////////////   crop   /////////////////////
+       /////////////////////////////////////////////////////
+       GC2355MIPI_write_cmos_sensor(0x92,0x02);
+       GC2355MIPI_write_cmos_sensor(0x94,0x00);
+       GC2355MIPI_write_cmos_sensor(0x95,0x04);
+       GC2355MIPI_write_cmos_sensor(0x96,0xb0);
+       GC2355MIPI_write_cmos_sensor(0x97,0x06);
+       GC2355MIPI_write_cmos_sensor(0x98,0x40); 
+
+       /////////////////////////////////////////////////////
+       //////////////////////    BLK   /////////////////////
+       /////////////////////////////////////////////////////
+       GC2355MIPI_write_cmos_sensor(0x18,0x02);
+       GC2355MIPI_write_cmos_sensor(0x1a,0x01);
+       GC2355MIPI_write_cmos_sensor(0x40,0x42);
+       GC2355MIPI_write_cmos_sensor(0x41,0x00); 
+       GC2355MIPI_write_cmos_sensor(0x44,0x00); 
+       GC2355MIPI_write_cmos_sensor(0x45,0x00);
+       GC2355MIPI_write_cmos_sensor(0x46,0x00);        
+       GC2355MIPI_write_cmos_sensor(0x47,0x00); 
+       GC2355MIPI_write_cmos_sensor(0x48,0x00); 
+       GC2355MIPI_write_cmos_sensor(0x49,0x00);
+       GC2355MIPI_write_cmos_sensor(0x4a,0x00);        
+       GC2355MIPI_write_cmos_sensor(0x4b,0x00);        
+       GC2355MIPI_write_cmos_sensor(0x4e,0x3c); 
+       GC2355MIPI_write_cmos_sensor(0x4f,0x00); 
+       GC2355MIPI_write_cmos_sensor(0x5e,0x00);
+       GC2355MIPI_write_cmos_sensor(0x66,0x20);
+       GC2355MIPI_write_cmos_sensor(0x6a,0x02);
+       GC2355MIPI_write_cmos_sensor(0x6b,0x02);
+       GC2355MIPI_write_cmos_sensor(0x6c,0x02);
+       GC2355MIPI_write_cmos_sensor(0x6d,0x02);
+       GC2355MIPI_write_cmos_sensor(0x6e,0x02);
+       GC2355MIPI_write_cmos_sensor(0x6f,0x02);
+       GC2355MIPI_write_cmos_sensor(0x70,0x02);
+       GC2355MIPI_write_cmos_sensor(0x71,0x02);
+
+       /////////////////////////////////////////////////////
+       ////////////////////  dark sun  /////////////////////
+       /////////////////////////////////////////////////////
+       GC2355MIPI_write_cmos_sensor(0x87,0x03); 
+       GC2355MIPI_write_cmos_sensor(0xe0,0xe7); 
+       GC2355MIPI_write_cmos_sensor(0xe3,0xc0); 
+
+       /////////////////////////////////////////////////////
+       //////////////////////   MIPI   /////////////////////
+       /////////////////////////////////////////////////////
+       GC2355MIPI_write_cmos_sensor(0xfe, 0x03);
+#if defined(GC2355MIPI_2Lane)
+       GC2355MIPI_write_cmos_sensor(0x10, 0x91);
+#else
+       GC2355MIPI_write_cmos_sensor(0x10, 0x90);
+#endif
+       GC2355MIPI_write_cmos_sensor(0xfe, 0x00);
+
+}   /*  GC2355MIPI_Sensor_Init  */
+
+/*****************************************************************************/
+/* Windows Mobile Sensor Interface */
+/*****************************************************************************/
+/*************************************************************************
+* FUNCTION
+*      GC2355MIPIOpen
+*
+* DESCRIPTION
+*      This function initialize the registers of CMOS sensor
+*
+* PARAMETERS
+*      None
+*
+* RETURNS
+*      None
+*
+* GLOBALS AFFECTED
+*
+*************************************************************************/
+
+UINT32 GC2355MIPIOpen(void)
+{
+       kal_uint16 sensor_id=0; 
+
+       // check if sensor ID correct
+       sensor_id=((GC2355MIPI_read_cmos_sensor(0xf0) << 8) | GC2355MIPI_read_cmos_sensor(0xf1));   
+#ifdef GC2355MIPI_DRIVER_TRACE
+       SENSORDB("GC2355MIPIOpen, sensor_id:%x \n",sensor_id);
+#endif         
+       if (sensor_id != GC2355MIPI_SENSOR_ID)
+               return ERROR_SENSOR_CONNECT_FAIL;
+       
+       /* initail sequence write in  */
+       GC2355MIPI_Sensor_Init();
+
+//     GC2355MIPI_SetMirrorFlip(GC2355MIPI_sensor.Mirror);
+
+       return ERROR_NONE;
+}   /* GC2355MIPIOpen  */
+
+/*************************************************************************
+* FUNCTION
+*   GC2355MIPIGetSensorID
+*
+* DESCRIPTION
+*   This function get the sensor ID 
+*
+* PARAMETERS
+*   *sensorID : return the sensor ID 
+*
+* RETURNS
+*   None
+*
+* GLOBALS AFFECTED
+*
+*************************************************************************/
+UINT32 GC2355MIPIGetSensorID(UINT32 *sensorID) 
+{
+       // check if sensor ID correct
+       *sensorID=((GC2355MIPI_read_cmos_sensor(0xf0) << 8) | GC2355MIPI_read_cmos_sensor(0xf1));       
+#ifdef GC2355MIPI_DRIVER_TRACE
+       SENSORDB("GC2355MIPIGetSensorID:%x \n",*sensorID);
+#endif         
+       if (*sensorID != GC2355MIPI_SENSOR_ID) {                
+               *sensorID = 0xFFFFFFFF;         
+               return ERROR_SENSOR_CONNECT_FAIL;
+       }
+   return ERROR_NONE;
+}
+
+/*************************************************************************
+* FUNCTION
+*      GC2355MIPIClose
+*
+* DESCRIPTION
+*      This function is to turn off sensor module power.
+*
+* PARAMETERS
+*      None
+*
+* RETURNS
+*      None
+*
+* GLOBALS AFFECTED
+*
+*************************************************************************/
+UINT32 GC2355MIPIClose(void)
+{
+#ifdef GC2355MIPI_DRIVER_TRACE
+   SENSORDB("GC2355MIPIClose\n");
+#endif
+  //kdCISModulePowerOn(SensorIdx,currSensorName,0,mode_name);
+//     DRV_I2CClose(GC2355MIPIhDrvI2C);
+       return ERROR_NONE;
+}   /* GC2355MIPIClose */
+
+/*************************************************************************
+* FUNCTION
+* GC2355MIPIPreview
+*
+* DESCRIPTION
+*      This function start the sensor preview.
+*
+* PARAMETERS
+*      *image_window : address pointer of pixel numbers in one period of HSYNC
+*  *sensor_config_data : address pointer of line numbers in one period of VSYNC
+*
+* RETURNS
+*      None
+*
+* GLOBALS AFFECTED
+*
+*************************************************************************/
+UINT32 GC2355MIPIPreview(MSDK_SENSOR_EXPOSURE_WINDOW_STRUCT *image_window,
+                                         MSDK_SENSOR_CONFIG_STRUCT *sensor_config_data)
+{
+       
+#if defined(MT6577)||defined(MT6589)
+       spin_lock(&gc2355mipi_drv_lock);        
+#endif
+       GC2355MIPI_sensor.pv_mode = KAL_TRUE;
+       
+       //GC2355MIPI_set_mirror(sensor_config_data->SensorImageMirror);
+       switch (sensor_config_data->SensorOperationMode)
+       {
+         case MSDK_SENSOR_OPERATION_MODE_VIDEO:                
+               GC2355MIPI_sensor.video_mode = KAL_TRUE;
+         default: /* ISP_PREVIEW_MODE */
+               GC2355MIPI_sensor.video_mode = KAL_FALSE;
+       }
+       GC2355MIPI_sensor.line_length = GC2355MIPI_PV_PERIOD_PIXEL_NUMS;
+       GC2355MIPI_sensor.frame_height = GC2355MIPI_PV_PERIOD_LINE_NUMS;
+       GC2355MIPI_sensor.pclk = GC2355MIPI_PREVIEW_CLK;
+#if defined(MT6577)||defined(MT6589)
+       spin_unlock(&gc2355mipi_drv_lock);
+#endif
+       //GC2355MIPI_Write_Shutter(GC2355MIPI_sensor.shutter);
+       return ERROR_NONE;
+}   /*  GC2355MIPIPreview   */
+
+/*************************************************************************
+* FUNCTION
+*      GC2355MIPICapture
+*
+* DESCRIPTION
+*      This function setup the CMOS sensor in capture MY_OUTPUT mode
+*
+* PARAMETERS
+*
+* RETURNS
+*      None
+*
+* GLOBALS AFFECTED
+*
+*************************************************************************/
+UINT32 GC2355MIPICapture(MSDK_SENSOR_EXPOSURE_WINDOW_STRUCT *image_window,
+                                                 MSDK_SENSOR_CONFIG_STRUCT *sensor_config_data)
+{
+       kal_uint32 shutter = (kal_uint32)GC2355MIPI_sensor.shutter;
+#if defined(MT6577)||defined(MT6589)
+       spin_lock(&gc2355mipi_drv_lock);
+#endif
+       GC2355MIPI_sensor.video_mode = KAL_FALSE;
+               GC2355MIPI_sensor.pv_mode = KAL_FALSE;
+#if defined(MT6577)||defined(MT6589)
+               spin_unlock(&gc2355mipi_drv_lock);
+#endif
+       return ERROR_NONE;
+}   /* GC2355MIPI_Capture() */
+
+UINT32 GC2355MIPIGetResolution(MSDK_SENSOR_RESOLUTION_INFO_STRUCT *pSensorResolution)
+{
+       pSensorResolution->SensorFullWidth=GC2355MIPI_IMAGE_SENSOR_FULL_WIDTH;
+       pSensorResolution->SensorFullHeight=GC2355MIPI_IMAGE_SENSOR_FULL_HEIGHT;
+       pSensorResolution->SensorPreviewWidth=GC2355MIPI_IMAGE_SENSOR_PV_WIDTH;
+       pSensorResolution->SensorPreviewHeight=GC2355MIPI_IMAGE_SENSOR_PV_HEIGHT;
+       pSensorResolution->SensorVideoWidth=GC2355MIPI_IMAGE_SENSOR_VIDEO_WIDTH;
+       pSensorResolution->SensorVideoHeight=GC2355MIPI_IMAGE_SENSOR_VIDEO_HEIGHT;
+       return ERROR_NONE;
+}      /* GC2355MIPIGetResolution() */
+
+UINT32 GC2355MIPIGetInfo(MSDK_SCENARIO_ID_ENUM ScenarioId,
+                                         MSDK_SENSOR_INFO_STRUCT *pSensorInfo,
+                                         MSDK_SENSOR_CONFIG_STRUCT *pSensorConfigData)
+{
+       pSensorInfo->SensorPreviewResolutionX=GC2355MIPI_IMAGE_SENSOR_PV_WIDTH;
+       pSensorInfo->SensorPreviewResolutionY=GC2355MIPI_IMAGE_SENSOR_PV_HEIGHT;
+       pSensorInfo->SensorFullResolutionX=GC2355MIPI_IMAGE_SENSOR_FULL_WIDTH;
+       pSensorInfo->SensorFullResolutionY=GC2355MIPI_IMAGE_SENSOR_FULL_HEIGHT;
+
+       pSensorInfo->SensorCameraPreviewFrameRate=30;
+       pSensorInfo->SensorVideoFrameRate=30;
+       pSensorInfo->SensorStillCaptureFrameRate=10;
+       pSensorInfo->SensorWebCamCaptureFrameRate=15;
+       pSensorInfo->SensorResetActiveHigh=TRUE; //low active
+       pSensorInfo->SensorResetDelayCount=5; 
+       pSensorInfo->SensorOutputDataFormat=GC2355MIPI_COLOR_FORMAT;
+       pSensorInfo->SensorClockPolarity=SENSOR_CLOCK_POLARITY_LOW;     
+       pSensorInfo->SensorClockFallingPolarity=SENSOR_CLOCK_POLARITY_LOW;
+       pSensorInfo->SensorHsyncPolarity = SENSOR_CLOCK_POLARITY_LOW;
+       pSensorInfo->SensorVsyncPolarity = SENSOR_CLOCK_POLARITY_LOW;
+       
+
+       pSensorInfo->CaptureDelayFrame = 2; 
+       pSensorInfo->PreviewDelayFrame = 1;
+       pSensorInfo->VideoDelayFrame = 1;
+
+       pSensorInfo->SensorMasterClockSwitch = 0; 
+       pSensorInfo->SensorDrivingCurrent = ISP_DRIVING_8MA;
+       pSensorInfo->AEShutDelayFrame =0;                  /* The frame of setting shutter default 0 for TG int */
+       pSensorInfo->AESensorGainDelayFrame = 0;   /* The frame of setting sensor gain */
+       pSensorInfo->AEISPGainDelayFrame = 2;  
+
+       pSensorInfo->SensroInterfaceType=SENSOR_INTERFACE_TYPE_MIPI;
+#if defined(GC2355MIPI_2Lane)
+       pSensorInfo->SensorMIPILaneNumber = SENSOR_MIPI_2_LANE;
+       //pSensorInfo->SensorRawType = RAW_TYPE_10BIT;
+#else
+       pSensorInfo->SensorMIPILaneNumber = SENSOR_MIPI_1_LANE;
+#endif
+
+       pSensorInfo->MIPIDataLowPwr2HighSpeedTermDelayCount = 0; 
+       pSensorInfo->MIPIDataLowPwr2HighSpeedSettleDelayCount = 14; 
+       pSensorInfo->MIPICLKLowPwr2HighSpeedTermDelayCount = 0;
+       pSensorInfo->SensorWidthSampling = 0;
+       pSensorInfo->SensorHightSampling = 0;
+       pSensorInfo->SensorPacketECCOrder = 1;
+       switch (ScenarioId)
+       {
+               case MSDK_SCENARIO_ID_CAMERA_PREVIEW:
+                       pSensorInfo->SensorClockFreq=24;
+                       pSensorInfo->SensorClockDividCount=3;
+                       pSensorInfo->SensorClockRisingCount= 0;
+                       pSensorInfo->SensorClockFallingCount= 2;
+                       pSensorInfo->SensorPixelClockCount= 3;
+                       pSensorInfo->SensorDataLatchCount= 2;
+                       pSensorInfo->SensorGrabStartX = GC2355MIPI_PV_X_START; 
+                       pSensorInfo->SensorGrabStartY = GC2355MIPI_PV_Y_START; 
+
+               break;
+               case MSDK_SCENARIO_ID_VIDEO_PREVIEW:
+                       pSensorInfo->SensorClockFreq=24;
+                       pSensorInfo->SensorClockDividCount=3;
+                       pSensorInfo->SensorClockRisingCount= 0;
+                       pSensorInfo->SensorClockFallingCount= 2;
+                       pSensorInfo->SensorPixelClockCount= 3;
+                       pSensorInfo->SensorDataLatchCount= 2;
+                       pSensorInfo->SensorGrabStartX = GC2355MIPI_VIDEO_X_START; 
+                       pSensorInfo->SensorGrabStartY = GC2355MIPI_VIDEO_Y_START; 
+
+               break;
+               case MSDK_SCENARIO_ID_CAMERA_CAPTURE_JPEG:
+               case MSDK_SCENARIO_ID_CAMERA_ZSD:
+                       pSensorInfo->SensorClockFreq=24;
+                       pSensorInfo->SensorClockDividCount= 3;
+                       pSensorInfo->SensorClockRisingCount=0;
+                       pSensorInfo->SensorClockFallingCount=2;
+                       pSensorInfo->SensorPixelClockCount=3;
+                       pSensorInfo->SensorDataLatchCount=2;
+                       pSensorInfo->SensorGrabStartX = GC2355MIPI_FULL_X_START; 
+                       pSensorInfo->SensorGrabStartY = GC2355MIPI_FULL_Y_START; 
+               break;
+               default:
+                       pSensorInfo->SensorClockFreq=24;
+                       pSensorInfo->SensorClockDividCount=3;
+                       pSensorInfo->SensorClockRisingCount=0;
+                       pSensorInfo->SensorClockFallingCount=2;         
+                       pSensorInfo->SensorPixelClockCount=3;
+                       pSensorInfo->SensorDataLatchCount=2;
+                       pSensorInfo->SensorGrabStartX = GC2355MIPI_PV_X_START; 
+                       pSensorInfo->SensorGrabStartY = GC2355MIPI_PV_Y_START; 
+               break;
+       }
+       memcpy(pSensorConfigData, &GC2355MIPI_sensor.cfg_data, sizeof(MSDK_SENSOR_CONFIG_STRUCT));
+  return ERROR_NONE;
+}      /* GC2355MIPIGetInfo() */
+
+
+UINT32 GC2355MIPIControl(MSDK_SCENARIO_ID_ENUM ScenarioId, MSDK_SENSOR_EXPOSURE_WINDOW_STRUCT *pImageWindow,
+                                         MSDK_SENSOR_CONFIG_STRUCT *pSensorConfigData)
+{
+
+#ifdef GC2355_DRIVER_TRACE
+       SENSORDB("GC2355MIPIControl ScenarioId = %d \n",ScenarioId);
+#endif
+       switch (ScenarioId)
+       {
+               case MSDK_SCENARIO_ID_CAMERA_PREVIEW:
+               case MSDK_SCENARIO_ID_VIDEO_PREVIEW:
+                       GC2355MIPIPreview(pImageWindow, pSensorConfigData);
+               break;
+               case MSDK_SCENARIO_ID_CAMERA_CAPTURE_JPEG:
+               case MSDK_SCENARIO_ID_CAMERA_ZSD:
+                       GC2355MIPICapture(pImageWindow, pSensorConfigData);
+               break;          
+        default:
+            return ERROR_INVALID_SCENARIO_ID;
+       }
+       return ERROR_NONE;
+}      /* GC2355MIPIControl() */
+
+
+
+UINT32 GC2355MIPISetVideoMode(UINT16 u2FrameRate)
+{};
+
+UINT32 GC2355MIPIFeatureControl(MSDK_SENSOR_FEATURE_ENUM FeatureId,
+                                                        UINT8 *pFeaturePara,UINT32 *pFeatureParaLen)
+{
+       UINT16 *pFeatureReturnPara16=(UINT16 *) pFeaturePara;
+       UINT16 *pFeatureData16=(UINT16 *) pFeaturePara;
+       UINT32 *pFeatureReturnPara32=(UINT32 *) pFeaturePara;
+       //UINT32 *pFeatureData32=(UINT32 *) pFeaturePara;
+       //UINT32 GC2355MIPISensorRegNumber;
+       //UINT32 i;
+       //PNVRAM_SENSOR_DATA_STRUCT pSensorDefaultData=(PNVRAM_SENSOR_DATA_STRUCT) pFeaturePara;
+       //MSDK_SENSOR_CONFIG_STRUCT *pSensorConfigData=(MSDK_SENSOR_CONFIG_STRUCT *) pFeaturePara;
+       MSDK_SENSOR_REG_INFO_STRUCT *pSensorRegData=(MSDK_SENSOR_REG_INFO_STRUCT *) pFeaturePara;
+       //MSDK_SENSOR_GROUP_INFO_STRUCT *pSensorGroupInfo=(MSDK_SENSOR_GROUP_INFO_STRUCT *) pFeaturePara;
+       //MSDK_SENSOR_ITEM_INFO_STRUCT *pSensorItemInfo=(MSDK_SENSOR_ITEM_INFO_STRUCT *) pFeaturePara;
+       //MSDK_SENSOR_ENG_INFO_STRUCT   *pSensorEngInfo=(MSDK_SENSOR_ENG_INFO_STRUCT *) pFeaturePara;
+
+       switch (FeatureId)
+       {
+               case SENSOR_FEATURE_GET_RESOLUTION:
+                       *pFeatureReturnPara16++=GC2355MIPI_IMAGE_SENSOR_FULL_WIDTH;
+                       *pFeatureReturnPara16=GC2355MIPI_IMAGE_SENSOR_FULL_HEIGHT;
+                       *pFeatureParaLen=4;
+               break;
+               case SENSOR_FEATURE_GET_PERIOD: /* 3 */
+                       *pFeatureReturnPara16++=GC2355MIPI_sensor.line_length;
+                       *pFeatureReturnPara16=GC2355MIPI_sensor.frame_height;
+                       *pFeatureParaLen=4;
+               break;
+               case SENSOR_FEATURE_GET_PIXEL_CLOCK_FREQ:  /* 3 */
+                       *pFeatureReturnPara32 = GC2355MIPI_sensor.pclk;
+                       *pFeatureParaLen=4;
+               break;
+               case SENSOR_FEATURE_SET_ESHUTTER:       /* 4 */
+                       GC2355MIPI_set_shutter(*pFeatureData16);
+               break;
+               case SENSOR_FEATURE_SET_NIGHTMODE:
+                       GC2355MIPI_night_mode((BOOL) *pFeatureData16);
+               break;
+               case SENSOR_FEATURE_SET_GAIN:   /* 6 */                 
+                       GC2355MIPI_SetGain((UINT16) *pFeatureData16);
+               break;
+               case SENSOR_FEATURE_SET_FLASHLIGHT:
+               break;
+               case SENSOR_FEATURE_SET_ISP_MASTER_CLOCK_FREQ:
+               break;
+               case SENSOR_FEATURE_SET_REGISTER:
+                       GC2355MIPI_write_cmos_sensor(pSensorRegData->RegAddr, pSensorRegData->RegData);
+               break;
+               case SENSOR_FEATURE_GET_REGISTER:
+                       pSensorRegData->RegData = GC2355MIPI_read_cmos_sensor(pSensorRegData->RegAddr);
+               break;
+               case SENSOR_FEATURE_SET_CCT_REGISTER:
+                       memcpy(&GC2355MIPI_sensor.eng.cct, pFeaturePara, sizeof(GC2355MIPI_sensor.eng.cct));
+                       break;
+               break;
+               case SENSOR_FEATURE_GET_CCT_REGISTER:   /* 12 */
+                       if (*pFeatureParaLen >= sizeof(GC2355MIPI_sensor.eng.cct) + sizeof(kal_uint32))
+                       {
+                         *((kal_uint32 *)pFeaturePara++) = sizeof(GC2355MIPI_sensor.eng.cct);
+                         memcpy(pFeaturePara, &GC2355MIPI_sensor.eng.cct, sizeof(GC2355MIPI_sensor.eng.cct));
+                       }
+                       break;
+               case SENSOR_FEATURE_SET_ENG_REGISTER:
+                       memcpy(&GC2355MIPI_sensor.eng.reg, pFeaturePara, sizeof(GC2355MIPI_sensor.eng.reg));
+                       break;
+               case SENSOR_FEATURE_GET_ENG_REGISTER:   /* 14 */
+                       if (*pFeatureParaLen >= sizeof(GC2355MIPI_sensor.eng.reg) + sizeof(kal_uint32))
+                       {
+                         *((kal_uint32 *)pFeaturePara++) = sizeof(GC2355MIPI_sensor.eng.reg);
+                         memcpy(pFeaturePara, &GC2355MIPI_sensor.eng.reg, sizeof(GC2355MIPI_sensor.eng.reg));
+                       }
+               case SENSOR_FEATURE_GET_REGISTER_DEFAULT:
+                       ((PNVRAM_SENSOR_DATA_STRUCT)pFeaturePara)->Version = NVRAM_CAMERA_SENSOR_FILE_VERSION;
+                       ((PNVRAM_SENSOR_DATA_STRUCT)pFeaturePara)->SensorId = GC2355MIPI_SENSOR_ID;
+                       memcpy(((PNVRAM_SENSOR_DATA_STRUCT)pFeaturePara)->SensorEngReg, &GC2355MIPI_sensor.eng.reg, sizeof(GC2355MIPI_sensor.eng.reg));
+                       memcpy(((PNVRAM_SENSOR_DATA_STRUCT)pFeaturePara)->SensorCCTReg, &GC2355MIPI_sensor.eng.cct, sizeof(GC2355MIPI_sensor.eng.cct));
+                       *pFeatureParaLen = sizeof(NVRAM_SENSOR_DATA_STRUCT);
+                       break;
+               case SENSOR_FEATURE_GET_CONFIG_PARA:
+                       memcpy(pFeaturePara, &GC2355MIPI_sensor.cfg_data, sizeof(GC2355MIPI_sensor.cfg_data));
+                       *pFeatureParaLen = sizeof(GC2355MIPI_sensor.cfg_data);
+                       break;
+               case SENSOR_FEATURE_CAMERA_PARA_TO_SENSOR:
+                    GC2355MIPI_camera_para_to_sensor();
+                       break;
+               case SENSOR_FEATURE_SENSOR_TO_CAMERA_PARA:
+                       GC2355MIPI_sensor_to_camera_para();
+                       break;                                                  
+               case SENSOR_FEATURE_GET_GROUP_COUNT:
+                       GC2355MIPI_get_sensor_group_count((kal_uint32 *)pFeaturePara);
+                       *pFeatureParaLen = 4;
+                       break;
+               case SENSOR_FEATURE_GET_GROUP_INFO:
+                       GC2355MIPI_get_sensor_group_info((MSDK_SENSOR_GROUP_INFO_STRUCT *)pFeaturePara);
+                       *pFeatureParaLen = sizeof(MSDK_SENSOR_GROUP_INFO_STRUCT);
+                       break;
+               case SENSOR_FEATURE_GET_ITEM_INFO:
+                       GC2355MIPI_get_sensor_item_info((MSDK_SENSOR_ITEM_INFO_STRUCT *)pFeaturePara);
+                       *pFeatureParaLen = sizeof(MSDK_SENSOR_ITEM_INFO_STRUCT);
+                       break;
+               case SENSOR_FEATURE_SET_ITEM_INFO:
+                       GC2355MIPI_set_sensor_item_info((MSDK_SENSOR_ITEM_INFO_STRUCT *)pFeaturePara);
+                       *pFeatureParaLen = sizeof(MSDK_SENSOR_ITEM_INFO_STRUCT);
+                       break;
+               case SENSOR_FEATURE_GET_ENG_INFO:
+                       memcpy(pFeaturePara, &GC2355MIPI_sensor.eng_info, sizeof(GC2355MIPI_sensor.eng_info));
+                       *pFeatureParaLen = sizeof(GC2355MIPI_sensor.eng_info);
+                       break;
+               case SENSOR_FEATURE_GET_LENS_DRIVER_ID:
+                       // get the lens driver ID from EEPROM or just return LENS_DRIVER_ID_DO_NOT_CARE
+                       // if EEPROM does not exist in camera module.
+                       *pFeatureReturnPara32=LENS_DRIVER_ID_DO_NOT_CARE;
+                       *pFeatureParaLen=4;
+               break;
+               case SENSOR_FEATURE_SET_VIDEO_MODE:
+                  //GC2355MIPISetVideoMode(*pFeatureData16);
+                       break; 
+               case SENSOR_FEATURE_CHECK_SENSOR_ID:
+                       GC2355MIPIGetSensorID(pFeatureReturnPara32); 
+                       break; 
+               case SENSOR_FEATURE_SET_AUTO_FLICKER_MODE:
+                       break;
+
+                       /*SZ TCT xuejian.zhong add for CTS test */
+               case SENSOR_FEATURE_GET_AF_MAX_NUM_FOCUS_AREAS:
+                       GC2355GetAFMaxNumFocusAreas(pFeatureReturnPara32);
+
+                       *pFeatureParaLen=4;
+                       break;
+
+               case SENSOR_FEATURE_GET_AE_MAX_NUM_METERING_AREAS:
+                       GC2355GetAEMaxNumMeteringAreas(pFeatureReturnPara32);
+
+                       *pFeatureParaLen=4;
+                       break;
+               case SENSOR_FEATURE_GET_EXIF_INFO:
+
+                       GC2355GetExifInfo(*pFeatureReturnPara32);
+                       break;
+                       /* xuejian.zhong add end */
+
+
+
+               default:
+                       break;
+       }
+       return ERROR_NONE;
+}      /* GC2355MIPIFeatureControl() */
+SENSOR_FUNCTION_STRUCT SensorFuncGC2355MIPI=
+{
+       GC2355MIPIOpen,
+       GC2355MIPIGetInfo,
+       GC2355MIPIGetResolution,
+       GC2355MIPIFeatureControl,
+       GC2355MIPIControl,
+       GC2355MIPIClose
+};
+
+UINT32 GC2355MIPI_RAW_SensorInit(PSENSOR_FUNCTION_STRUCT *pfFunc) 
+{
+       /* To Do : Check Sensor status here */
+       if (pfFunc!=NULL)
+               *pfFunc=&SensorFuncGC2355MIPI;
+
+       return ERROR_NONE;
+}      /* SensorInit() */
diff --git a/drivers/misc/mediatek/imgsensor/src/mt8127/gc2355_mipi_raw/gc2355mipi_Sensor.h b/drivers/misc/mediatek/imgsensor/src/mt8127/gc2355_mipi_raw/gc2355mipi_Sensor.h
new file mode 100644 (file)
index 0000000..8818bfc
--- /dev/null
@@ -0,0 +1,240 @@
+/* Copyright Statement:
+ *
+ * This software/firmware and related documentation ("MediaTek Software") are
+ * protected under relevant copyright laws. The information contained herein
+ * is confidential and proprietary to MediaTek Inc. and/or its licensors.
+ * Without the prior written permission of MediaTek inc. and/or its licensors,
+ * any reproduction, modification, use or disclosure of MediaTek Software,
+ * and information contained herein, in whole or in part, shall be strictly prohibited.
+ */
+/* MediaTek Inc. (C) 2010. All rights reserved.
+ *
+ * BY OPENING THIS FILE, RECEIVER HEREBY UNEQUIVOCALLY ACKNOWLEDGES AND AGREES
+ * THAT THE SOFTWARE/FIRMWARE AND ITS DOCUMENTATIONS ("MEDIATEK SOFTWARE")
+ * RECEIVED FROM MEDIATEK AND/OR ITS REPRESENTATIVES ARE PROVIDED TO RECEIVER ON
+ * AN "AS-IS" BASIS ONLY. MEDIATEK EXPRESSLY DISCLAIMS ANY AND ALL WARRANTIES,
+ * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE IMPLIED WARRANTIES OF
+ * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE OR NONINFRINGEMENT.
+ * NEITHER DOES MEDIATEK PROVIDE ANY WARRANTY WHATSOEVER WITH RESPECT TO THE
+ * SOFTWARE OF ANY THIRD PARTY WHICH MAY BE USED BY, INCORPORATED IN, OR
+ * SUPPLIED WITH THE MEDIATEK SOFTWARE, AND RECEIVER AGREES TO LOOK ONLY TO SUCH
+ * THIRD PARTY FOR ANY WARRANTY CLAIM RELATING THERETO. RECEIVER EXPRESSLY ACKNOWLEDGES
+ * THAT IT IS RECEIVER'S SOLE RESPONSIBILITY TO OBTAIN FROM ANY THIRD PARTY ALL PROPER LICENSES
+ * CONTAINED IN MEDIATEK SOFTWARE. MEDIATEK SHALL ALSO NOT BE RESPONSIBLE FOR ANY MEDIATEK
+ * SOFTWARE RELEASES MADE TO RECEIVER'S SPECIFICATION OR TO CONFORM TO A PARTICULAR
+ * STANDARD OR OPEN FORUM. RECEIVER'S SOLE AND EXCLUSIVE REMEDY AND MEDIATEK'S ENTIRE AND
+ * CUMULATIVE LIABILITY WITH RESPECT TO THE MEDIATEK SOFTWARE RELEASED HEREUNDER WILL BE,
+ * AT MEDIATEK'S OPTION, TO REVISE OR REPLACE THE MEDIATEK SOFTWARE AT ISSUE,
+ * OR REFUND ANY SOFTWARE LICENSE FEES OR SERVICE CHARGE PAID BY RECEIVER TO
+ * MEDIATEK FOR SUCH MEDIATEK SOFTWARE AT ISSUE.
+ */
+
+/*****************************************************************************
+*  Copyright Statement:
+*  --------------------
+*  This software is protected by Copyright and the information contained
+*  herein is confidential. The software may not be copied and the information
+*  contained herein may not be used or disclosed except with the written
+*  permission of MediaTek Inc. (C) 2005
+*
+*  BY OPENING THIS FILE, BUYER HEREBY UNEQUIVOCALLY ACKNOWLEDGES AND AGREES
+*  THAT THE SOFTWARE/FIRMWARE AND ITS DOCUMENTATIONS ("MEDIATEK SOFTWARE")
+*  RECEIVED FROM MEDIATEK AND/OR ITS REPRESENTATIVES ARE PROVIDED TO BUYER ON
+*  AN "AS-IS" BASIS ONLY. MEDIATEK EXPRESSLY DISCLAIMS ANY AND ALL WARRANTIES,
+*  EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE IMPLIED WARRANTIES OF
+*  MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE OR NONINFRINGEMENT.
+*  NEITHER DOES MEDIATEK PROVIDE ANY WARRANTY WHATSOEVER WITH RESPECT TO THE
+*  SOFTWARE OF ANY THIRD PARTY WHICH MAY BE USED BY, INCORPORATED IN, OR
+*  SUPPLIED WITH THE MEDIATEK SOFTWARE, AND BUYER AGREES TO LOOK ONLY TO SUCH
+*  THIRD PARTY FOR ANY WARRANTY CLAIM RELATING THERETO. MEDIATEK SHALL ALSO
+*  NOT BE RESPONSIBLE FOR ANY MEDIATEK SOFTWARE RELEASES MADE TO BUYER'S
+*  SPECIFICATION OR TO CONFORM TO A PARTICULAR STANDARD OR OPEN FORUM.
+*
+*  BUYER'S SOLE AND EXCLUSIVE REMEDY AND MEDIATEK'S ENTIRE AND CUMULATIVE
+*  LIABILITY WITH RESPECT TO THE MEDIATEK SOFTWARE RELEASED HEREUNDER WILL BE,
+*  AT MEDIATEK'S OPTION, TO REVISE OR REPLACE THE MEDIATEK SOFTWARE AT ISSUE,
+*  OR REFUND ANY SOFTWARE LICENSE FEES OR SERVICE CHARGE PAID BY BUYER TO
+*  MEDIATEK FOR SUCH MEDIATEK SOFTWARE AT ISSUE. 
+*
+*  THE TRANSACTION CONTEMPLATED HEREUNDER SHALL BE CONSTRUED IN ACCORDANCE
+*  WITH THE LAWS OF THE STATE OF CALIFORNIA, USA, EXCLUDING ITS CONFLICT OF
+*  LAWS PRINCIPLES.  ANY DISPUTES, CONTROVERSIES OR CLAIMS ARISING THEREOF AND
+*  RELATED THERETO SHALL BE SETTLED BY ARBITRATION IN SAN FRANCISCO, CA, UNDER
+*  THE RULES OF THE INTERNATIONAL CHAMBER OF COMMERCE (ICC).
+*
+*****************************************************************************/
+/*****************************************************************************
+ *
+ * Filename:
+ * ---------
+ *      sensor.c
+ *
+ * Project:
+ * --------
+ *      RAW
+ *
+ * Description:
+ * ------------
+ *      Source code of Sensor driver
+ *
+ *
+ * Author:
+ * -------
+ *   Leo Lee
+ *
+ *============================================================================
+ *             HISTORY
+ *------------------------------------------------------------------------------
+ * $Revision:$
+ * $Modtime:$
+ * $Log:$
+ *
+ * 03 01 2013
+ * First release GC2355MIPI driver Version 1.0
+ *
+ *------------------------------------------------------------------------------
+ *============================================================================
+ ****************************************************************************/
+
+#ifndef _GC2355MIPI_SENSOR_H
+#define _GC2355MIPI_SENSOR_H
+
+#define GC2355MIPI_DEBUG 
+#define GC2355MIPI_DRIVER_TRACE
+//#define GC2355MIPI_TEST_PATTEM
+//#define SENSORDB printk
+//#define SENSORDB(x,...)
+
+#define GC2355MIPI_FACTORY_START_ADDR 0
+#define GC2355MIPI_ENGINEER_START_ADDR 10
+typedef enum GC2355MIPI_group_enum
+{
+  GC2355MIPI_PRE_GAIN = 0,
+  GC2355MIPI_CMMCLK_CURRENT,
+  GC2355MIPI_FRAME_RATE_LIMITATION,
+  GC2355MIPI_REGISTER_EDITOR,
+  GC2355MIPI_GROUP_TOTAL_NUMS
+} GC2355MIPI_FACTORY_GROUP_ENUM;
+
+typedef enum GC2355MIPI_register_index
+{
+  GC2355MIPI_SENSOR_BASEGAIN = GC2355MIPI_FACTORY_START_ADDR,
+  GC2355MIPI_PRE_GAIN_R_INDEX,
+  GC2355MIPI_PRE_GAIN_Gr_INDEX,
+  GC2355MIPI_PRE_GAIN_Gb_INDEX,
+  GC2355MIPI_PRE_GAIN_B_INDEX,
+  GC2355MIPI_FACTORY_END_ADDR
+} GC2355MIPI_FACTORY_REGISTER_INDEX;
+
+typedef enum GC2355MIPI_engineer_index
+{
+  GC2355MIPI_CMMCLK_CURRENT_INDEX = GC2355MIPI_ENGINEER_START_ADDR,
+  GC2355MIPI_ENGINEER_END
+} GC2355MIPI_FACTORY_ENGINEER_INDEX;
+
+typedef struct _sensor_data_struct
+{
+  SENSOR_REG_STRUCT reg[GC2355MIPI_ENGINEER_END];
+  SENSOR_REG_STRUCT cct[GC2355MIPI_FACTORY_END_ADDR];
+} sensor_data_struct;
+
+#define GC2355MIPI_PREVIEW_CLK                   42000000
+#define GC2355MIPI_CAPTURE_CLK                   42000000
+
+#define GC2355MIPI_COLOR_FORMAT                    SENSOR_OUTPUT_FORMAT_RAW_B
+
+
+#define GC2355MIPI_MIN_ANALOG_GAIN                             1       /* 1x */
+#define GC2355MIPI_MAX_ANALOG_GAIN                             4       /* 2.8x */
+
+
+/* FRAME RATE UNIT */
+#define GC2355MIPI_FPS(x)                          (10 * (x))
+
+/* SENSOR PIXEL/LINE NUMBERS IN ONE PERIOD */
+#define GC2355MIPI_FULL_PERIOD_PIXEL_NUMS          1680
+#define GC2355MIPI_FULL_PERIOD_LINE_NUMS           1250
+
+#define GC2355MIPI_VIDEO_PERIOD_PIXEL_NUMS          1680
+#define GC2355MIPI_VIDEO_PERIOD_LINE_NUMS           1250
+
+#define GC2355MIPI_PV_PERIOD_PIXEL_NUMS            1680
+#define GC2355MIPI_PV_PERIOD_LINE_NUMS             1250
+
+/* SENSOR START/END POSITION */
+#define GC2355MIPI_FULL_X_START                    0
+#define GC2355MIPI_FULL_Y_START                    0
+#define GC2355MIPI_IMAGE_SENSOR_FULL_WIDTH         (1600 - 8)
+#define GC2355MIPI_IMAGE_SENSOR_FULL_HEIGHT        (1200 - 6)
+
+#define GC2355MIPI_VIDEO_X_START                      0
+#define GC2355MIPI_VIDEO_Y_START                      0
+#define GC2355MIPI_IMAGE_SENSOR_VIDEO_WIDTH           (1600)
+#define GC2355MIPI_IMAGE_SENSOR_VIDEO_HEIGHT          (1200)
+
+#define GC2355MIPI_PV_X_START                      0
+#define GC2355MIPI_PV_Y_START                      0
+#define GC2355MIPI_IMAGE_SENSOR_PV_WIDTH           (1600 - 8)
+#define GC2355MIPI_IMAGE_SENSOR_PV_HEIGHT          (1200 - 6)
+
+/* SENSOR READ/WRITE ID */
+#define GC2355MIPI_WRITE_ID (0x78)
+#define GC2355MIPI_READ_ID  (0x79)
+
+/* SENSOR ID */
+
+
+/* SENSOR PRIVATE STRUCT */
+typedef enum {
+    SENSOR_MODE_INIT = 0,
+    SENSOR_MODE_PREVIEW,
+    SENSOR_MODE_VIDEO,
+    SENSOR_MODE_CAPTURE
+} GC2355MIPI_SENSOR_MODE;
+
+typedef enum{
+       GC2355MIPI_IMAGE_NORMAL = 0,
+       GC2355MIPI_IMAGE_H_MIRROR,
+       GC2355MIPI_IMAGE_V_MIRROR,
+       GC2355MIPI_IMAGE_HV_MIRROR
+}GC2355MIPI_IMAGE_MIRROR;
+
+typedef struct GC2355MIPI_sensor_STRUCT
+{
+       MSDK_SENSOR_CONFIG_STRUCT cfg_data;
+       sensor_data_struct eng; /* engineer mode */
+       MSDK_SENSOR_ENG_INFO_STRUCT eng_info;
+       GC2355MIPI_SENSOR_MODE sensorMode;
+       GC2355MIPI_IMAGE_MIRROR Mirror;
+       kal_bool pv_mode;
+       kal_bool video_mode;
+       kal_bool NightMode;
+       kal_uint16 normal_fps; /* video normal mode max fps */
+       kal_uint16 night_fps; /* video night mode max fps */
+       kal_uint16 FixedFps;
+       kal_uint16 shutter;
+       kal_uint16 gain;
+       kal_uint32 pclk;
+       kal_uint16 frame_height;
+       kal_uint16 frame_height_BackUp;
+       kal_uint16 line_length;  
+       kal_uint16 Prv_line_length;
+} GC2355MIPI_sensor_struct;
+
+typedef enum GC2355MIPI_GainMode_Index
+{
+       GC2355MIPI_Analogic_Gain = 0,
+       GC2355MIPI_Digital_Gain
+}GC2355MIPI_GainMode_Index;
+//export functions
+UINT32 GC2355MIPIOpen(void);
+UINT32 GC2355MIPIControl(MSDK_SCENARIO_ID_ENUM ScenarioId, MSDK_SENSOR_EXPOSURE_WINDOW_STRUCT *pImageWindow, MSDK_SENSOR_CONFIG_STRUCT *pSensorConfigData);
+UINT32 GC2355MIPIFeatureControl(MSDK_SENSOR_FEATURE_ENUM FeatureId, UINT8 *pFeaturePara,UINT32 *pFeatureParaLen);
+UINT32 GC2355MIPIGetInfo(MSDK_SCENARIO_ID_ENUM ScenarioId, MSDK_SENSOR_INFO_STRUCT *pSensorInfo, MSDK_SENSOR_CONFIG_STRUCT *pSensorConfigData);
+UINT32 GC2355MIPIGetResolution(MSDK_SENSOR_RESOLUTION_INFO_STRUCT *pSensorResolution);
+UINT32 GC2355MIPIClose(void);
+
+#define Sleep(ms) mdelay(ms)
+
+#endif 
index 6e79572e6058dcfe04bb2d4f2503ab790a50c125..0052ed682a49a039a4682981e7e7f7150b01ba4e 100644 (file)
@@ -169,10 +169,6 @@ kal_uint16 HI708_read_cmos_sensor(kal_uint8 addr)
     return get_byte;\r
 }\r
 \r
-static int CAPTURE_FLAG = 0;\r
-static int CAPTUREA_FLAG = 0;\r
-static int CAPTUREB_FLAG = 0;//Add By Jason\r
-\r
 #define HI708_LOAD_FROM_T_FLASH\r
 #ifdef HI708_LOAD_FROM_T_FLASH\r
 \r
@@ -1562,7 +1558,7 @@ static UINT32 HI708Preview(MSDK_SENSOR_EXPOSURE_WINDOW_STRUCT *image_window,
 \r
     SENSORDB("[Exit]:HI708 preview func\n");\r
    \r
-   //HI708_night_mode(HI708_sensor.night_mode);\r
+   HI708_night_mode(HI708_sensor.night_mode);\r
     return TRUE; \r
 }      /* HI708_Preview */\r
 \r
@@ -1586,9 +1582,6 @@ kal_uint32 CapShutter;
   HI708_write_cmos_sensor(0x84, (CapShutter >> 8) & 0xFF);\r
   HI708_write_cmos_sensor(0x85, CapShutter & 0xFF);  \r
   #endif\r
-  CAPTURE_FLAG = 1;\r
-  CAPTUREA_FLAG = 1;\r
-  CAPTUREB_FLAG = 1;//Add By Jason\r
     return ERROR_NONE;\r
 }      /* HM3451Capture() */\r
 \r
@@ -2194,8 +2187,6 @@ UINT32 HI708YUVSensorSetting(FEATURE_ID iCmd, UINT32 iPara)
     switch (iCmd) \r
     {\r
     case FID_SCENE_MODE:           //auto mode or night mode\r
-    if( CAPTURE_FLAG == 0)\r
-       {\r
         if (iPara == SCENE_MODE_OFF)//auto mode\r
         {\r
             HI708_night_mode(FALSE); \r
@@ -2204,11 +2195,6 @@ UINT32 HI708YUVSensorSetting(FEATURE_ID iCmd, UINT32 iPara)
         {\r
             HI708_night_mode(TRUE); \r
         }      \r
-       }\r
-       else\r
-               {\r
-       CAPTURE_FLAG = 0;\r
-               }\r
         break;             \r
     case FID_AWB_MODE:\r
         HI708_set_param_wb(iPara);\r
@@ -2216,18 +2202,11 @@ UINT32 HI708YUVSensorSetting(FEATURE_ID iCmd, UINT32 iPara)
     case FID_COLOR_EFFECT:\r
         HI708_set_param_effect(iPara);\r
         break;\r
-    case FID_AE_EV:            \r
-               if( CAPTUREA_FLAG == 0)\r
+    case FID_AE_EV:                \r
         HI708_set_param_exposure(iPara);\r
-               else\r
-                       CAPTUREA_FLAG = 0;\r
         break;\r
-    case FID_AE_FLICKER:                 \r
-               \r
-                 if( CAPTUREB_FLAG == 0)\r
+    case FID_AE_FLICKER:                           \r
         HI708_set_param_banding(iPara);\r
-                 else\r
-                       CAPTUREB_FLAG = 0;\r
         break;\r
     case FID_ZOOM_FACTOR:\r
         spin_lock(&hi708_yuv_drv_lock);\r
index 8f8e6823342a18314b7545881a039a56ebd74109..db99154cde0b5bb3ac7dcf458209a2a36e0068cb 100644 (file)
@@ -76,6 +76,8 @@ UINT32 HI708_YUV_SensorInit(PSENSOR_FUNCTION_STRUCT *pfFunc);
 UINT32 OV2680MIPISensorInit(PSENSOR_FUNCTION_STRUCT *pfFunc);
 UINT32 S5K5E2YA_MIPI_RAW_SensorInit(PSENSOR_FUNCTION_STRUCT *pfFunc);
 UINT32 OV5670_MIPI_RAW_SensorInit(PSENSOR_FUNCTION_STRUCT *pfFunc);
+UINT32 OV56702ND_MIPI_RAW_SensorInit(PSENSOR_FUNCTION_STRUCT *pfFunc);
+UINT32 GC2355MIPI_RAW_SensorInit(PSENSOR_FUNCTION_STRUCT *pfFunc); 
 
 //! Add Sensor Init function here
 //! Note:
@@ -85,6 +87,15 @@ UINT32 OV5670_MIPI_RAW_SensorInit(PSENSOR_FUNCTION_STRUCT *pfFunc);
 //! 2. This file should be the same as mediatek\custom\common\hal\imgsensor\src\sensorlist.cpp
 ACDK_KD_SENSOR_INIT_FUNCTION_STRUCT kdSensorList[MAX_NUM_OF_SUPPORT_SENSOR+1] =
 {
+
+#if defined(OV5670_MIPI_RAW)
+               {OV5670_SENSOR_ID, SENSOR_DRVNAME_OV5670_MIPI_RAW, OV5670_MIPI_RAW_SensorInit}, 
+#endif
+
+#if defined(OV56702ND_MIPI_RAW)
+                {OV5670_SENSOR_ID+1, SENSOR_DRVNAME_OV56702ND_MIPI_RAW, OV56702ND_MIPI_RAW_SensorInit}, 
+#endif
+
 #if defined(S5K5E2YA_MIPI_RAW)
     {S5K5E2YA_SENSOR_ID, SENSOR_DRVNAME_S5K5E2YA_MIPI_RAW, S5K5E2YA_MIPI_RAW_SensorInit}, 
 #endif
@@ -93,6 +104,10 @@ ACDK_KD_SENSOR_INIT_FUNCTION_STRUCT kdSensorList[MAX_NUM_OF_SUPPORT_SENSOR+1] =
     {OV2680MIPI_SENSOR_ID, SENSOR_DRVNAME_OV2680_RAW, OV2680MIPISensorInit}, 
 #endif
 
+#if defined(GC2355_MIPI_RAW)
+    {GC2355MIPI_SENSOR_ID, SENSOR_DRVNAME_GC2355_MIPI_RAW, GC2355MIPI_RAW_SensorInit}, 
+#endif
+
 #if defined(GC2355_RAW)
     {GC2355_SENSOR_ID, SENSOR_DRVNAME_GC2355_RAW, GC2355_RAW_SensorInit}, 
 #endif
@@ -311,9 +326,6 @@ ACDK_KD_SENSOR_INIT_FUNCTION_STRUCT kdSensorList[MAX_NUM_OF_SUPPORT_SENSOR+1] =
     {S5K4H5YX_2LANE_SENSOR_ID, SENSOR_DRVNAME_S5K4H5YX_2LANE_MIPI_RAW, S5K4H5YX_2LANE_MIPI_RAW_SensorInit},
 #endif
 
-#if defined(OV5670_MIPI_RAW)
-               {OV5670_SENSOR_ID, SENSOR_DRVNAME_OV5670_MIPI_RAW, OV5670_MIPI_RAW_SensorInit}, 
-#endif
 
 /*  ADD sensor driver before this line */
     {0,{0},NULL}, //end of list
index 39e03fd82d431bd0cd99dce5e19acc1175b56795..389350a1332977b330d382f973d9c1ad97d9cbd9 100644 (file)
@@ -99,6 +99,35 @@ extern int iMultiWriteReg(u8 *pData, u16 lens, u16 i2cId);
 
 
 MSDK_SCENARIO_ID_ENUM ov2680CurrentScenarioId = MSDK_SCENARIO_ID_CAMERA_PREVIEW;
+
+/* SZ TCT xuejian.zhong add for CTS test*/
+static void OV2680GetAFMaxNumFocusAreas(UINT32 *pFeatureReturnPara32)
+{      
+    *pFeatureReturnPara32 = 0;    
+    SENSORDB("OV2680GetAFMaxNumFocusAreas *pFeatureReturnPara32 = %d\n",  *pFeatureReturnPara32);
+}
+
+static void OV2680GetAEMaxNumMeteringAreas(UINT32 *pFeatureReturnPara32)
+{     
+    *pFeatureReturnPara32 = 0;    
+    SENSORDB("OV2680GetAEMaxNumMeteringAreas *pFeatureReturnPara32 = %d\n",  *pFeatureReturnPara32);   
+}
+
+static void OV2680GetExifInfo(UINT32 exifAddr)
+{
+    SENSOR_EXIF_INFO_STRUCT* pExifInfo = (SENSOR_EXIF_INFO_STRUCT*)exifAddr;
+    pExifInfo->FNumber = 28;
+    pExifInfo->AEISOSpeed = AE_ISO_100;
+    pExifInfo->AWBMode = AWB_MODE_AUTO;
+    pExifInfo->CapExposureTime = 0;
+    pExifInfo->FlashLightTimeus = 0;
+    pExifInfo->RealISOValue = AE_ISO_100;
+}
+
+/* SZ TCT xuejian.zhong  end */
+
+
+
 static OV2680_sensor_struct OV2680_sensor =
 {
   .eng =
@@ -963,8 +992,8 @@ static void OV2680MIPI_Sensor_preview(void)
        OV2680_write_cmos_sensor(0x3813, 0x08);
        OV2680_write_cmos_sensor(0x3814, 0x11);
        OV2680_write_cmos_sensor(0x3815, 0x11);
-       OV2680_write_cmos_sensor(0x3820, 0xc4);
-       OV2680_write_cmos_sensor(0x3821, 0x04);
+       OV2680_write_cmos_sensor(0x3820, 0xc0);
+       OV2680_write_cmos_sensor(0x3821, 0x00);
        OV2680_write_cmos_sensor(0x4008, 0x02);
        OV2680_write_cmos_sensor(0x4009, 0x09);
        OV2680_write_cmos_sensor(0x4837, 0x18);
@@ -1007,8 +1036,8 @@ static void OV2680MIPI_Sensor_2M_15fps(void)
        OV2680_write_cmos_sensor(0x3813, 0x08);
        OV2680_write_cmos_sensor(0x3814, 0x11);
        OV2680_write_cmos_sensor(0x3815, 0x11);
-       OV2680_write_cmos_sensor(0x3820, 0xc4);
-       OV2680_write_cmos_sensor(0x3821, 0x04);
+       OV2680_write_cmos_sensor(0x3820, 0xc0);//0xc4
+       OV2680_write_cmos_sensor(0x3821, 0x00);//0x04
        OV2680_write_cmos_sensor(0x4008, 0x02);
        OV2680_write_cmos_sensor(0x4009, 0x09);
        OV2680_write_cmos_sensor(0x4837, 0x30);
@@ -1981,6 +2010,29 @@ UINT32 OV2680FeatureControl(MSDK_SENSOR_FEATURE_ENUM FeatureId,
                        *pFeatureReturnPara32=OV2680_TEST_PATTERN_CHECKSUM;               
                        *pFeatureParaLen=4; 
             break;
+
+                       /*SZ TCT xuejian.zhong add for CTS test */
+               case SENSOR_FEATURE_GET_AF_MAX_NUM_FOCUS_AREAS:
+                       OV2680GetAFMaxNumFocusAreas(pFeatureReturnPara32);
+
+                       *pFeatureParaLen=4;
+                       break;
+
+               case SENSOR_FEATURE_GET_AE_MAX_NUM_METERING_AREAS:
+                       OV2680GetAEMaxNumMeteringAreas(pFeatureReturnPara32);
+
+                       *pFeatureParaLen=4;
+                       break;
+               case SENSOR_FEATURE_GET_EXIF_INFO:
+                       SENSORDB("SENSOR_FEATURE_GET_EXIF_INFO\n");
+                       SENSORDB("EXIF addr = 0x%x\n",*pFeatureData32);
+
+                       OV2680GetExifInfo(*pFeatureData32);
+                       break;
+                       /* xuejian.zhong add end */
+
+
+
         default:
             break;
     }
diff --git a/drivers/misc/mediatek/imgsensor/src/mt8127/ov56702nd_mipi_raw/Makefile b/drivers/misc/mediatek/imgsensor/src/mt8127/ov56702nd_mipi_raw/Makefile
new file mode 100644 (file)
index 0000000..84964eb
--- /dev/null
@@ -0,0 +1,4 @@
+include $(srctree)/drivers/misc/mediatek/Makefile.custom
+
+obj-y += ov56702ndmipi_Sensor.o
+
diff --git a/drivers/misc/mediatek/imgsensor/src/mt8127/ov56702nd_mipi_raw/ov56702ndmipi_Sensor.c b/drivers/misc/mediatek/imgsensor/src/mt8127/ov56702nd_mipi_raw/ov56702ndmipi_Sensor.c
new file mode 100644 (file)
index 0000000..c8bbc26
--- /dev/null
@@ -0,0 +1,2140 @@
+/*****************************************************************************
+ *
+ * Filename:
+ * ---------
+ *      OV56702NDmipi_Sensor.c
+ *
+ * Project:
+ * --------
+ *      ALPS
+ *
+ * Description:
+ * ------------
+ *      Source code of Sensor driver
+ *
+ *
+ *------------------------------------------------------------------------------
+ * Upper this line, this part is controlled by CC/CQ. DO NOT MODIFY!!
+ *============================================================================
+ ****************************************************************************/
+
+#include <linux/videodev2.h>
+#include <linux/i2c.h>
+#include <linux/platform_device.h>
+#include <linux/delay.h>
+#include <linux/cdev.h>
+#include <linux/uaccess.h>
+#include <linux/fs.h>
+#include <asm/atomic.h>
+#include <linux/xlog.h>
+#include <asm/system.h>
+
+#include "kd_camera_hw.h"
+#include "kd_imgsensor.h"
+#include "kd_imgsensor_define.h"
+#include "kd_imgsensor_errcode.h"
+
+#include "ov56702ndmipi_Sensor.h"
+
+#include "ov56702ndmipiraw_Camera_Sensor_para.h"
+#include "ov56702ndmipiraw_CameraCustomized.h"
+static DEFINE_SPINLOCK(ov56702ndmipiraw_drv_lock);
+static int module_id = 0;
+
+#define OV56702ND_DEBUG
+#ifdef OV56702ND_DEBUG
+       #define OV56702NDDB(fmt, arg...) xlog_printk(ANDROID_LOG_DEBUG, "[OV56702NDRaw] ",  fmt, ##arg)
+#else
+       #define OV56702NDDB(fmt, arg...)
+#endif
+
+
+kal_uint32 OV56702ND_FeatureControl_PERIOD_PixelNum=OV56702ND_PV_PERIOD_PIXEL_NUMS;
+kal_uint32 OV56702ND_FeatureControl_PERIOD_LineNum=OV56702ND_PV_PERIOD_LINE_NUMS;
+
+UINT16 OV56702ND_VIDEO_MODE_TARGET_FPS = 30;
+
+MSDK_SCENARIO_ID_ENUM OV56702NDCurrentScenarioId = MSDK_SCENARIO_ID_CAMERA_PREVIEW;
+MSDK_SENSOR_CONFIG_STRUCT OV56702NDSensorConfigData;
+static OV56702ND_PARA_STRUCT OV56702ND;
+kal_uint32 OV56702ND_FAC_SENSOR_REG;
+
+
+SENSOR_REG_STRUCT OV56702NDSensorCCT[]=CAMERA_SENSOR_CCT_DEFAULT_VALUE;
+SENSOR_REG_STRUCT OV56702NDSensorReg[ENGINEER_END]=CAMERA_SENSOR_REG_DEFAULT_VALUE;
+
+
+#define OV56702ND_TEST_PATTERN_CHECKSUM 0xca3667da //0x5d8082f0 //0x75bef806 //0xa2230d9f    //0xf5e2f1ce
+kal_bool OV56702ND_During_testpattern = KAL_FALSE;
+
+extern int iReadReg(u16 a_u2Addr , u8 * a_puBuff , u16 i2cId);
+extern int iWriteReg(u16 a_u2Addr , u32 a_u4Data , u32 a_u4Bytes , u16 i2cId);
+
+#define OV56702ND_write_cmos_sensor(addr, para) iWriteReg((u16) addr , (u32) para , 1, OV56702NDMIPI_WRITE_ID)
+
+kal_uint16 OV56702ND_read_cmos_sensor(kal_uint32 addr)
+{
+kal_uint16 get_byte=0;
+    iReadReg((u16) addr ,(u8*)&get_byte,OV56702NDMIPI_WRITE_ID);
+    return get_byte;
+}
+
+
+void OV56702ND_Init_Para(void)
+{
+
+       spin_lock(&ov56702ndmipiraw_drv_lock);
+       OV56702ND.sensorMode = SENSOR_MODE_INIT;
+       OV56702ND.OV56702NDAutoFlickerMode = KAL_FALSE;
+       OV56702ND.OV56702NDVideoMode = KAL_FALSE;
+       OV56702ND.DummyLines= 0;
+       OV56702ND.DummyPixels= 0;
+       OV56702ND.pvPclk =  (10285); 
+       OV56702ND.videoPclk = (10285);
+       OV56702ND.capPclk = (10285);
+
+       OV56702ND.shutter = 0x4C00;
+       OV56702ND.ispBaseGain = BASEGAIN;
+       OV56702ND.sensorGlobalGain = 0x0200;
+       spin_unlock(&ov56702ndmipiraw_drv_lock);
+}
+
+#define RG_Ratio_Typical 264
+#define BG_Ratio_Typical 236
+
+struct otp_struct {
+   int flag; // bit[7]: info, bit[6]:wb
+   int module_integrator_id;
+   int lens_id;
+   int production_year;
+   int production_month;
+   int production_day;
+   int rg_ratio;
+   int bg_ratio;
+};
+
+
+static void otp_i2c_write( uint32_t addr, kal_uint16 data)
+{
+  OV56702ND_write_cmos_sensor(addr, data);
+}
+
+static kal_uint16 otp_i2c_read(uint32_t addr)
+
+{
+       return OV56702ND_read_cmos_sensor(addr);
+}
+
+
+// return value:
+// bit[7]: 0 no otp info, 1 valid otp info
+// bit[6]: 0 no otp wb, 1 valib otp wb
+static int read_otp(struct otp_struct *otp_ptr)
+{
+   int otp_flag, addr, temp, i;
+   //set 0x5002[3] to “0”
+   int temp1;
+   
+   temp1 = otp_i2c_read(0x5002);
+   otp_i2c_write(0x5002, (0x00 & 0x08) | (temp1 & (~0x08)));
+   
+   // read OTP into buffer
+   otp_i2c_write(0x3d84, 0xC0);
+   otp_i2c_write(0x3d88, 0x70); // OTP start address
+   otp_i2c_write(0x3d89, 0x10);
+   otp_i2c_write(0x3d8A, 0x70); // OTP end address
+   otp_i2c_write(0x3d8B, 0x29);
+   otp_i2c_write(0x3d81, 0x01); // load otp into buffer
+   mdelay(5);
+   
+   // OTP into
+   otp_flag = otp_i2c_read(0x7010);
+   addr = 0;
+   
+   if((otp_flag & 0xc0) == 0x40) {
+      addr = 0x7011; // base address of info group 1
+   } else if((otp_flag & 0x30) == 0x10) {
+      addr = 0x7016; // base address of info group 2
+   }else if((otp_flag & 0x0c) == 0x04) {
+      addr = 0x701b; // base address of info group 3
+   }
+   
+   if(addr != 0) {
+        (*otp_ptr).flag = 0x80; // valid base info in OTP
+        (*otp_ptr).module_integrator_id = otp_i2c_read( addr );
+        (*otp_ptr).lens_id = otp_i2c_read( addr + 1);
+        (*otp_ptr).production_year = otp_i2c_read( addr + 2);
+        (*otp_ptr).production_month = otp_i2c_read( addr + 3);
+        (*otp_ptr).production_day = otp_i2c_read( addr + 4);
+   } else {
+        (*otp_ptr).flag = 0x00; // not info in OTP
+        (*otp_ptr).module_integrator_id = 0;
+        (*otp_ptr).lens_id = 0;
+        (*otp_ptr).production_year = 0;
+        (*otp_ptr).production_month = 0;
+        (*otp_ptr).production_day = 0;
+   }
+
+   module_id = (*otp_ptr).module_integrator_id;
+   // OTP WB Calibration
+   otp_flag = otp_i2c_read(0x7020);
+   addr = 0;
+   
+   if((otp_flag & 0xc0) == 0x40) {
+     addr = 0x7021; // base address of WB Calibration group 1
+   }else if((otp_flag & 0x30) == 0x10) {
+     addr = 0x7024; // base address of WB Calibration group 2
+   }else if((otp_flag & 0x0c) == 0x04) {
+     addr = 0x7027; // base address of WB Calibration group 3
+   }
+   
+   if(addr != 0) {
+     (*otp_ptr).flag |= 0x40;
+     temp = otp_i2c_read( addr + 2);
+     (*otp_ptr).rg_ratio = (otp_i2c_read(addr)<<2) + ((temp>>6) & 0x03);
+     (*otp_ptr).bg_ratio = (otp_i2c_read( addr + 1)<<2) + ((temp>>4) & 0x03);
+   }else {
+     (*otp_ptr).rg_ratio = 0;
+     (*otp_ptr).bg_ratio = 0;
+   }
+   
+   for(i=0x7010;i<=0x7029;i++) {
+     otp_i2c_write(i,0); // clear OTP buffer, recommended use continuous write to accelarate
+   }
+   
+   //set 0x5002[3] to “1”
+   temp1 = otp_i2c_read(0x5002);
+   otp_i2c_write(0x5002, (0x02 & 0x08) | (temp1 & (~0x08)));
+   return (*otp_ptr).flag ;
+}
+
+static int apply_otp(struct otp_struct *otp_ptr)
+{
+        int rg, bg, R_gain, G_gain, B_gain, Base_gain;
+
+   // apply OTP WB Calibration
+   if ((*otp_ptr).flag & 0x40) {
+        rg = (*otp_ptr). rg_ratio;
+        bg = (*otp_ptr).bg_ratio;
+        //calculate G gain
+        R_gain = (RG_Ratio_Typical*1000) / rg;
+        B_gain = (BG_Ratio_Typical*1000) / bg;
+        G_gain = 1000;    
+        
+        if (R_gain < 1000 || B_gain < 1000)
+        {
+             if (R_gain < B_gain)
+               Base_gain = R_gain;
+             else
+               Base_gain = B_gain;
+        }
+        else
+        {
+             Base_gain = G_gain;
+        }
+        
+        R_gain = 0x400 * R_gain / (Base_gain);
+        B_gain = 0x400 * B_gain / (Base_gain);
+        G_gain = 0x400 * G_gain / (Base_gain);
+        // update sensor WB gain
+        if (R_gain>0x400) {
+        otp_i2c_write(0x5032, R_gain>>8);
+        otp_i2c_write(0x5033, R_gain & 0x00ff);
+        }
+        if (G_gain>0x400) {
+        otp_i2c_write(0x5034, G_gain>>8);
+        otp_i2c_write(0x5035, G_gain & 0x00ff);
+        }
+        if (B_gain>0x400) {
+        otp_i2c_write(0x5036, B_gain>>8);
+        otp_i2c_write(0x5037, B_gain & 0x00ff);
+        }
+   }
+   return (*otp_ptr).flag ;    
+}
+
+void ov56702nd_otp_config()
+{   
+       struct otp_struct otp_info ;  
+       
+       read_otp(&otp_info);   
+       apply_otp(&otp_info) ;
+}
+kal_uint32 GetOV56702NDLineLength(void)
+{
+       kal_uint32 OV56702ND_line_length = 0;
+       if ( SENSOR_MODE_PREVIEW == OV56702ND.sensorMode )  
+       {
+               OV56702ND_line_length = OV56702ND_PV_PERIOD_PIXEL_NUMS + OV56702ND.DummyPixels;
+       }
+       else if( SENSOR_MODE_VIDEO == OV56702ND.sensorMode ) 
+       {
+               OV56702ND_line_length = OV56702ND_VIDEO_PERIOD_PIXEL_NUMS + OV56702ND.DummyPixels;
+       }
+       else
+       {
+               OV56702ND_line_length = OV56702ND_FULL_PERIOD_PIXEL_NUMS + OV56702ND.DummyPixels;
+       }
+
+    return OV56702ND_line_length;
+
+}
+
+
+kal_uint32 GetOV56702NDFrameLength(void)
+{
+       kal_uint32 OV56702ND_frame_length = 0;
+
+       if ( SENSOR_MODE_PREVIEW == OV56702ND.sensorMode )  
+       {
+               OV56702ND_frame_length = OV56702ND_PV_PERIOD_LINE_NUMS + OV56702ND.DummyLines ;
+       }
+       else if( SENSOR_MODE_VIDEO == OV56702ND.sensorMode ) 
+       {
+               OV56702ND_frame_length = OV56702ND_VIDEO_PERIOD_LINE_NUMS + OV56702ND.DummyLines ;
+       }
+       else
+       {
+               OV56702ND_frame_length = OV56702ND_FULL_PERIOD_LINE_NUMS + OV56702ND.DummyLines ;
+       }
+
+       return OV56702ND_frame_length;
+}
+
+
+kal_uint32 OV56702ND_CalcExtra_For_ShutterMargin(kal_uint32 shutter_value,kal_uint32 shutterLimitation)
+{
+    kal_uint32 extra_lines = 0;
+
+       
+       if (shutter_value <4 ){
+               shutter_value = 4;
+       }
+
+       
+       if (shutter_value > shutterLimitation)
+       {
+               extra_lines = shutter_value - shutterLimitation;
+    }
+       else
+               extra_lines = 0;
+
+    return extra_lines;
+
+}
+
+
+kal_uint32 OV56702ND_CalcFrameLength_For_AutoFlicker(void)
+{
+
+    kal_uint32 AutoFlicker_min_framelength = 0;
+
+       switch(OV56702NDCurrentScenarioId)
+       {
+               case MSDK_SCENARIO_ID_CAMERA_ZSD:
+               case MSDK_SCENARIO_ID_CAMERA_CAPTURE_JPEG:
+                       AutoFlicker_min_framelength = (OV56702ND.capPclk*10000) /(OV56702ND_FULL_PERIOD_PIXEL_NUMS + OV56702ND.DummyPixels)/OV56702ND_AUTOFLICKER_OFFSET_25*10 ;
+                       break;
+               case MSDK_SCENARIO_ID_VIDEO_PREVIEW:
+                       if(OV56702ND_VIDEO_MODE_TARGET_FPS==30)
+                       {
+                               AutoFlicker_min_framelength = (OV56702ND.videoPclk*10000) /(OV56702ND_VIDEO_PERIOD_PIXEL_NUMS + OV56702ND.DummyPixels)/OV56702ND_AUTOFLICKER_OFFSET_30*10 ;
+                       }
+                       else if(OV56702ND_VIDEO_MODE_TARGET_FPS==15)
+                       {
+                               AutoFlicker_min_framelength = (OV56702ND.videoPclk*10000) /(OV56702ND_VIDEO_PERIOD_PIXEL_NUMS + OV56702ND.DummyPixels)/OV56702ND_AUTOFLICKER_OFFSET_15*10 ;
+                       }
+                       else
+                       {
+                               AutoFlicker_min_framelength = OV56702ND_VIDEO_PERIOD_LINE_NUMS + OV56702ND.DummyLines;
+                       }
+                       break;
+                       
+               case MSDK_SCENARIO_ID_CAMERA_PREVIEW:
+               default:
+                       AutoFlicker_min_framelength = (OV56702ND.pvPclk*10000) /(OV56702ND_PV_PERIOD_PIXEL_NUMS + OV56702ND.DummyPixels)/OV56702ND_AUTOFLICKER_OFFSET_30*10 ;
+                       break;
+       }
+
+       OV56702NDDB("AutoFlicker_min_framelength =%d,OV56702NDCurrentScenarioId =%d\n", AutoFlicker_min_framelength,OV56702NDCurrentScenarioId);
+
+       return AutoFlicker_min_framelength;
+
+}
+
+
+void OV56702ND_write_shutter(kal_uint32 shutter)
+{
+       kal_uint32 min_framelength = OV56702ND_PV_PERIOD_PIXEL_NUMS, max_shutter=0;
+       kal_uint32 line_length = 0;
+       kal_uint32 frame_length = 0;
+       unsigned long flags;
+
+       //for test
+       //shutter = 0x7fc;  //issue 
+       
+       
+    line_length  = GetOV56702NDLineLength();
+       frame_length = GetOV56702NDFrameLength();
+       
+       max_shutter  = frame_length-OV56702ND_SHUTTER_MARGIN;
+
+    frame_length = frame_length + OV56702ND_CalcExtra_For_ShutterMargin(shutter,max_shutter);
+       
+
+
+       if(OV56702ND.OV56702NDAutoFlickerMode == KAL_TRUE)
+       {
+        min_framelength = OV56702ND_CalcFrameLength_For_AutoFlicker();
+
+        if(frame_length < min_framelength)
+                       frame_length = min_framelength;
+       }
+       
+
+       spin_lock_irqsave(&ov56702ndmipiraw_drv_lock,flags);
+       OV56702ND_FeatureControl_PERIOD_PixelNum = line_length;
+       OV56702ND_FeatureControl_PERIOD_LineNum = frame_length;
+       spin_unlock_irqrestore(&ov56702ndmipiraw_drv_lock,flags);
+
+       //Set total frame length  //VTS
+       OV56702ND_write_cmos_sensor(0x380e, (frame_length >> 8) & 0xFF);
+       OV56702ND_write_cmos_sensor(0x380f, frame_length & 0xFF);
+
+       //Set shutter 
+       OV56702ND_write_cmos_sensor(0x3500, (shutter>>12) & 0x0F);
+       OV56702ND_write_cmos_sensor(0x3501, (shutter>>4) & 0xFF);
+       OV56702ND_write_cmos_sensor(0x3502, (shutter<<4) & 0xF0);         /* Don't use the fraction part. */
+
+       OV56702NDDB("ov56702nd write shutter=%x, line_length=%x, frame_length=%x\n", shutter, line_length, frame_length);
+
+}
+
+
+static kal_uint16 OV56702NDReg2Gain(const kal_uint16 iReg)
+{
+    kal_uint16 iGain =0; 
+
+       iGain = iReg*BASEGAIN/OV56702ND_GAIN_BASE;
+       return iGain;
+       
+}
+
+static kal_uint16 OV56702NDGain2Reg(const kal_uint16 Gain)
+{
+    kal_uint32 iReg = 0x0000;
+       kal_uint32 TempGain = BASEGAIN;
+
+
+       TempGain = Gain;
+       if(TempGain < BASEGAIN){
+               TempGain = BASEGAIN;
+               //OV56702NDDB("###ov56702nd write gain underflow### Gain =%x\n", Gain);
+       }
+       if(TempGain > 16*BASEGAIN){
+               TempGain = 16*BASEGAIN;
+               //OV56702NDDB("###ov56702nd write gain overflow### Gain =%x\n", Gain);
+       }
+
+       iReg = (TempGain*OV56702ND_GAIN_BASE)/BASEGAIN;
+
+       //iReg = ((TempGain /BASEGAIN)<<7)+((TempGain % BASEGAIN)<<7/BASEGAIN);
+       iReg = iReg & 0xFFFF;
+
+       //OV56702NDDB("###ov56702nd write Reg ### iReg =%x\n", iReg);
+
+    return iReg;
+
+}
+
+void write_OV56702ND_gain(kal_uint16 gain)
+{
+       kal_uint16 iGain =1;
+       kal_uint8 ChangeFlag=0x01;
+
+       kal_uint16 read_gain;
+       
+       iGain=(gain / OV56702ND_GAIN_BASE);
+
+       if(iGain<2){
+               ChangeFlag= 0x00;
+       }
+       else if(iGain<4){
+               ChangeFlag= 0x01;
+       }
+       else if(iGain<8){
+               ChangeFlag= 0x03;
+       }
+       else{
+               ChangeFlag= 0x07;
+       }
+
+       //ChangeFlag= 0x07;
+       
+       OV56702ND_write_cmos_sensor(0x301d, 0xf0);
+       OV56702ND_write_cmos_sensor(0x3209, 0x00);
+       OV56702ND_write_cmos_sensor(0x320a, 0x01);
+       
+       //group write  hold
+       //group 0:delay 0x366a for one frame,then active with gain
+       OV56702ND_write_cmos_sensor(0x3208, 0x00);
+       OV56702ND_write_cmos_sensor(0x366a, ChangeFlag);
+       OV56702ND_write_cmos_sensor(0x3208, 0x10);
+
+       //group 1:all other registers( gain)
+       OV56702ND_write_cmos_sensor(0x3208, 0x01);
+       OV56702ND_write_cmos_sensor(0x3508,(gain>>8));
+    OV56702ND_write_cmos_sensor(0x3509,(gain&0xff));
+       
+       OV56702ND_write_cmos_sensor(0x3208, 0x11);
+
+       //group lanch
+       OV56702ND_write_cmos_sensor(0x320B, 0x15);
+       OV56702ND_write_cmos_sensor(0x3208, 0xA1);
+
+       //read_gain=(((OV56702ND_read_cmos_sensor(0x3508)&0x1F) << 8) | OV56702ND_read_cmos_sensor(0x3509));
+       //OV56702NDDB("[OV56702ND_SetGain]0x3508|0x3509=0x%x \n",read_gain);
+       //OV56702NDDB("[OV56702ND_SetGain]0x366a=%d \n",(OV56702ND_read_cmos_sensor(0x366a)));
+
+       return;
+
+}
+
+void OV56702ND_SetGain(UINT16 iGain)
+{
+       unsigned long flags;
+       spin_lock_irqsave(&ov56702ndmipiraw_drv_lock,flags);
+
+       OV56702NDDB("OV56702ND_SetGain iGain = %d :\n ",iGain);
+       
+       OV56702ND.realGain = iGain;
+       OV56702ND.sensorGlobalGain = OV56702NDGain2Reg(iGain);
+       spin_unlock_irqrestore(&ov56702ndmipiraw_drv_lock,flags);
+
+       write_OV56702ND_gain(OV56702ND.sensorGlobalGain);
+       OV56702NDDB(" [OV56702ND_SetGain]OV56702ND.sensorGlobalGain=0x%x,OV56702ND.realGain =%d",OV56702ND.sensorGlobalGain,
+               OV56702ND.realGain); 
+
+       //temperature test
+       //OV56702ND_write_cmos_sensor(0x4d12,0x01);
+       //OV56702NDDB("Temperature read_reg  0x4d13  =%x \n",OV56702ND_read_cmos_sensor(0x4d13));
+}   
+
+kal_uint16 read_OV56702ND_gain(void)
+{
+       kal_uint16 read_gain=0;
+
+       read_gain=(((OV56702ND_read_cmos_sensor(0x3508)&0x1F) << 8) | OV56702ND_read_cmos_sensor(0x3509));
+
+       spin_lock(&ov56702ndmipiraw_drv_lock);
+       OV56702ND.sensorGlobalGain = read_gain;
+       OV56702ND.realGain = OV56702NDReg2Gain(OV56702ND.sensorGlobalGain);
+       spin_unlock(&ov56702ndmipiraw_drv_lock);
+
+       OV56702NDDB("OV56702ND.sensorGlobalGain=0x%x,OV56702ND.realGain=%d\n",OV56702ND.sensorGlobalGain,OV56702ND.realGain);
+
+       return OV56702ND.sensorGlobalGain;
+}  
+
+
+#if 1
+void OV56702ND_camera_para_to_sensor(void)
+{
+    kal_uint32    i;
+    for(i=0; 0xFFFFFFFF!=OV56702NDSensorReg[i].Addr; i++)
+    {
+        OV56702ND_write_cmos_sensor(OV56702NDSensorReg[i].Addr, OV56702NDSensorReg[i].Para);
+    }
+    for(i=ENGINEER_START_ADDR; 0xFFFFFFFF!=OV56702NDSensorReg[i].Addr; i++)
+    {
+        OV56702ND_write_cmos_sensor(OV56702NDSensorReg[i].Addr, OV56702NDSensorReg[i].Para);
+    }
+    for(i=FACTORY_START_ADDR; i<FACTORY_END_ADDR; i++)
+    {
+        OV56702ND_write_cmos_sensor(OV56702NDSensorCCT[i].Addr, OV56702NDSensorCCT[i].Para);
+    }
+}
+
+void OV56702ND_sensor_to_camera_para(void)
+{
+    kal_uint32    i, temp_data;
+    for(i=0; 0xFFFFFFFF!=OV56702NDSensorReg[i].Addr; i++)
+    {
+         temp_data = OV56702ND_read_cmos_sensor(OV56702NDSensorReg[i].Addr);
+                spin_lock(&ov56702ndmipiraw_drv_lock);
+                OV56702NDSensorReg[i].Para =temp_data;
+                spin_unlock(&ov56702ndmipiraw_drv_lock);
+    }
+    for(i=ENGINEER_START_ADDR; 0xFFFFFFFF!=OV56702NDSensorReg[i].Addr; i++)
+    {
+        temp_data = OV56702ND_read_cmos_sensor(OV56702NDSensorReg[i].Addr);
+               spin_lock(&ov56702ndmipiraw_drv_lock);
+               OV56702NDSensorReg[i].Para = temp_data;
+               spin_unlock(&ov56702ndmipiraw_drv_lock);
+    }
+}
+
+kal_int32  OV56702ND_get_sensor_group_count(void)
+{
+    return GROUP_TOTAL_NUMS;
+}
+
+void OV56702ND_get_sensor_group_info(kal_uint16 group_idx, kal_int8* group_name_ptr, kal_int32* item_count_ptr)
+{
+   switch (group_idx)
+   {
+        case PRE_GAIN:
+            sprintf((char *)group_name_ptr, "CCT");
+            *item_count_ptr = 2;
+            break;
+        case CMMCLK_CURRENT:
+            sprintf((char *)group_name_ptr, "CMMCLK Current");
+            *item_count_ptr = 1;
+            break;
+        case FRAME_RATE_LIMITATION:
+            sprintf((char *)group_name_ptr, "Frame Rate Limitation");
+            *item_count_ptr = 2;
+            break;
+        case REGISTER_EDITOR:
+            sprintf((char *)group_name_ptr, "Register Editor");
+            *item_count_ptr = 2;
+            break;
+        default:
+            ASSERT(0);
+}
+}
+
+void OV56702ND_get_sensor_item_info(kal_uint16 group_idx,kal_uint16 item_idx, MSDK_SENSOR_ITEM_INFO_STRUCT* info_ptr)
+{
+    kal_int16 temp_reg=0;
+    kal_uint16 temp_gain=0, temp_addr=0, temp_para=0;
+
+    switch (group_idx)
+    {
+        case PRE_GAIN:
+           switch (item_idx)
+          {
+              case 0:
+                sprintf((char *)info_ptr->ItemNamePtr,"Pregain-R");
+                  temp_addr = PRE_GAIN_R_INDEX;
+              break;
+              case 1:
+                sprintf((char *)info_ptr->ItemNamePtr,"Pregain-Gr");
+                  temp_addr = PRE_GAIN_Gr_INDEX;
+              break;
+              case 2:
+                sprintf((char *)info_ptr->ItemNamePtr,"Pregain-Gb");
+                  temp_addr = PRE_GAIN_Gb_INDEX;
+              break;
+              case 3:
+                sprintf((char *)info_ptr->ItemNamePtr,"Pregain-B");
+                  temp_addr = PRE_GAIN_B_INDEX;
+              break;
+              case 4:
+                 sprintf((char *)info_ptr->ItemNamePtr,"SENSOR_BASEGAIN");
+                 temp_addr = SENSOR_BASEGAIN;
+              break;
+              default:
+                 ASSERT(0);
+          }
+
+            temp_para= OV56702NDSensorCCT[temp_addr].Para;
+                       //temp_gain= (temp_para/OV56702ND.sensorBaseGain) * 1000;
+
+            info_ptr->ItemValue=temp_gain;
+            info_ptr->IsTrueFalse=KAL_FALSE;
+            info_ptr->IsReadOnly=KAL_FALSE;
+            info_ptr->IsNeedRestart=KAL_FALSE;
+            info_ptr->Min= OV56702ND_MIN_ANALOG_GAIN * 1000;
+            info_ptr->Max= OV56702ND_MAX_ANALOG_GAIN * 1000;
+            break;
+        case CMMCLK_CURRENT:
+            switch (item_idx)
+            {
+                case 0:
+                    sprintf((char *)info_ptr->ItemNamePtr,"Drv Cur[2,4,6,8]mA");
+
+                    //temp_reg=MT9P017SensorReg[CMMCLK_CURRENT_INDEX].Para;
+                    temp_reg = ISP_DRIVING_2MA;
+                    if(temp_reg==ISP_DRIVING_2MA)
+                    {
+                        info_ptr->ItemValue=2;
+                    }
+                    else if(temp_reg==ISP_DRIVING_4MA)
+                    {
+                        info_ptr->ItemValue=4;
+                    }
+                    else if(temp_reg==ISP_DRIVING_6MA)
+                    {
+                        info_ptr->ItemValue=6;
+                    }
+                    else if(temp_reg==ISP_DRIVING_8MA)
+                    {
+                        info_ptr->ItemValue=8;
+                    }
+
+                    info_ptr->IsTrueFalse=KAL_FALSE;
+                    info_ptr->IsReadOnly=KAL_FALSE;
+                    info_ptr->IsNeedRestart=KAL_TRUE;
+                    info_ptr->Min=2;
+                    info_ptr->Max=8;
+                    break;
+                default:
+                    ASSERT(0);
+            }
+            break;
+        case FRAME_RATE_LIMITATION:
+            switch (item_idx)
+            {
+                case 0:
+                    sprintf((char *)info_ptr->ItemNamePtr,"Max Exposure Lines");
+                    info_ptr->ItemValue=    111;  
+                    info_ptr->IsTrueFalse=KAL_FALSE;
+                    info_ptr->IsReadOnly=KAL_TRUE;
+                    info_ptr->IsNeedRestart=KAL_FALSE;
+                    info_ptr->Min=0;
+                    info_ptr->Max=0;
+                    break;
+                case 1:
+                    sprintf((char *)info_ptr->ItemNamePtr,"Min Frame Rate");
+                    info_ptr->ItemValue=12;
+                    info_ptr->IsTrueFalse=KAL_FALSE;
+                    info_ptr->IsReadOnly=KAL_TRUE;
+                    info_ptr->IsNeedRestart=KAL_FALSE;
+                    info_ptr->Min=0;
+                    info_ptr->Max=0;
+                    break;
+                default:
+                    ASSERT(0);
+            }
+            break;
+        case REGISTER_EDITOR:
+            switch (item_idx)
+            {
+                case 0:
+                    sprintf((char *)info_ptr->ItemNamePtr,"REG Addr.");
+                    info_ptr->ItemValue=0;
+                    info_ptr->IsTrueFalse=KAL_FALSE;
+                    info_ptr->IsReadOnly=KAL_FALSE;
+                    info_ptr->IsNeedRestart=KAL_FALSE;
+                    info_ptr->Min=0;
+                    info_ptr->Max=0xFFFF;
+                    break;
+                case 1:
+                    sprintf((char *)info_ptr->ItemNamePtr,"REG Value");
+                    info_ptr->ItemValue=0;
+                    info_ptr->IsTrueFalse=KAL_FALSE;
+                    info_ptr->IsReadOnly=KAL_FALSE;
+                    info_ptr->IsNeedRestart=KAL_FALSE;
+                    info_ptr->Min=0;
+                    info_ptr->Max=0xFFFF;
+                    break;
+                default:
+                ASSERT(0);
+            }
+            break;
+        default:
+            ASSERT(0);
+    }
+}
+
+
+
+kal_bool OV56702ND_set_sensor_item_info(kal_uint16 group_idx, kal_uint16 item_idx, kal_int32 ItemValue)
+{
+   kal_uint16  temp_gain=0,temp_addr=0, temp_para=0;
+
+   switch (group_idx)
+    {
+        case PRE_GAIN:
+            switch (item_idx)
+            {
+              case 0:
+                temp_addr = PRE_GAIN_R_INDEX;
+              break;
+              case 1:
+                temp_addr = PRE_GAIN_Gr_INDEX;
+              break;
+              case 2:
+                temp_addr = PRE_GAIN_Gb_INDEX;
+              break;
+              case 3:
+                temp_addr = PRE_GAIN_B_INDEX;
+              break;
+              case 4:
+                temp_addr = SENSOR_BASEGAIN;
+              break;
+              default:
+                 ASSERT(0);
+          }
+
+                temp_gain=((ItemValue*BASEGAIN+500)/1000);                     //+500:get closed integer value
+
+                 if(temp_gain>=1*BASEGAIN && temp_gain<=16*BASEGAIN)
+          {
+//             temp_para=(temp_gain * OV56702ND.sensorBaseGain + BASEGAIN/2)/BASEGAIN;
+          }
+          else
+                         ASSERT(0);
+
+                 spin_lock(&ov56702ndmipiraw_drv_lock);
+          OV56702NDSensorCCT[temp_addr].Para = temp_para;
+                 spin_unlock(&ov56702ndmipiraw_drv_lock);
+          OV56702ND_write_cmos_sensor(OV56702NDSensorCCT[temp_addr].Addr,temp_para);
+
+            break;
+        case CMMCLK_CURRENT:
+            switch (item_idx)
+            {
+                case 0:
+                    //no need to apply this item for driving current
+                    break;
+                default:
+                    ASSERT(0);
+            }
+            break;
+        case FRAME_RATE_LIMITATION:
+            ASSERT(0);
+            break;
+        case REGISTER_EDITOR:
+            switch (item_idx)
+            {
+                case 0:
+                                       spin_lock(&ov56702ndmipiraw_drv_lock);
+                    OV56702ND_FAC_SENSOR_REG=ItemValue;
+                                       spin_unlock(&ov56702ndmipiraw_drv_lock);
+                    break;
+                case 1:
+                    OV56702ND_write_cmos_sensor(OV56702ND_FAC_SENSOR_REG,ItemValue);
+                    break;
+                default:
+                    ASSERT(0);
+            }
+            break;
+        default:
+            ASSERT(0);
+    }
+    return KAL_TRUE;
+}
+#endif
+
+
+static void OV56702ND_SetDummy( const kal_uint32 iPixels, const kal_uint32 iLines )
+{
+       kal_uint32 line_length = 0;
+       kal_uint32 frame_length = 0;
+
+       if ( SENSOR_MODE_PREVIEW == OV56702ND.sensorMode )
+       {
+               line_length = OV56702ND_PV_PERIOD_PIXEL_NUMS + iPixels;
+               frame_length = OV56702ND_PV_PERIOD_LINE_NUMS + iLines;
+       }
+       else if( SENSOR_MODE_VIDEO== OV56702ND.sensorMode )
+       {
+               line_length = OV56702ND_VIDEO_PERIOD_PIXEL_NUMS + iPixels;
+               frame_length = OV56702ND_VIDEO_PERIOD_LINE_NUMS + iLines;
+       }
+       else
+       {
+               line_length = OV56702ND_FULL_PERIOD_PIXEL_NUMS + iPixels;
+               frame_length = OV56702ND_FULL_PERIOD_LINE_NUMS + iLines;
+       }
+
+       spin_lock(&ov56702ndmipiraw_drv_lock);
+       OV56702ND_FeatureControl_PERIOD_PixelNum = line_length;
+       OV56702ND_FeatureControl_PERIOD_LineNum = frame_length;
+       spin_unlock(&ov56702ndmipiraw_drv_lock);
+
+       //Set total frame length
+       OV56702ND_write_cmos_sensor(0x380e, (frame_length >> 8) & 0xFF);
+       OV56702ND_write_cmos_sensor(0x380f, frame_length & 0xFF);
+       //Set total line length
+       OV56702ND_write_cmos_sensor(0x380c, (line_length >> 8) & 0xFF);
+       OV56702ND_write_cmos_sensor(0x380d, line_length & 0xFF);
+
+}   
+
+
+void OV56702NDPreviewSetting(void)
+{
+       OV56702NDDB(" OV56702NDPreviewSetting_2lane enter\n");
+
+       /*  //
+       
+       //@@PV_Quarter_size_30fps_800Mbps/lane                            
+       //99 1296 960                                                                             
+       //;;102 3601    157c                                                                      
+       //;;PCLK=HTS*VTS*fps=0x68c*0x7fd*30=1676*2045*30=102.85M
+
+               OV56702ND_write_cmos_sensor(0x0100, 0x00);  //
+       
+       OV56702ND_write_cmos_sensor(0x3501, 0x3d);  //
+       OV56702ND_write_cmos_sensor(0x366e, 0x08);  //
+       OV56702ND_write_cmos_sensor(0x370b, 0x1b);  //
+       OV56702ND_write_cmos_sensor(0x3808, 0x05);  //
+       OV56702ND_write_cmos_sensor(0x3809, 0x10);  //
+       OV56702ND_write_cmos_sensor(0x380a, 0x03);  //
+       OV56702ND_write_cmos_sensor(0x380b, 0xc0);  //
+       OV56702ND_write_cmos_sensor(0x380c, 0x06);  //
+       OV56702ND_write_cmos_sensor(0x380d, 0x8c);  //
+       OV56702ND_write_cmos_sensor(0x380e, 0x07);  //;03
+       OV56702ND_write_cmos_sensor(0x380f, 0xfd);  //;e0
+       OV56702ND_write_cmos_sensor(0x3814, 0x03);  //
+       OV56702ND_write_cmos_sensor(0x3820, 0x90);  //
+       OV56702ND_write_cmos_sensor(0x3821, 0x47);  //
+       OV56702ND_write_cmos_sensor(0x382a, 0x03);  //
+       OV56702ND_write_cmos_sensor(0x4009, 0x05);  //
+       OV56702ND_write_cmos_sensor(0x4502, 0x48);  //
+       OV56702ND_write_cmos_sensor(0x4508, 0x55);  //
+       OV56702ND_write_cmos_sensor(0x4509, 0x55);  //
+       OV56702ND_write_cmos_sensor(0x4600, 0x00);  //
+       OV56702ND_write_cmos_sensor(0x4601, 0x81);  //
+       OV56702ND_write_cmos_sensor(0x4017, 0x10);  //; threshold = 4LSB for Binning sum format.
+       OV56702ND_write_cmos_sensor(0x400a, 0x02);  //;
+       OV56702ND_write_cmos_sensor(0x400b, 0x00);  //; 
+       
+       OV56702ND_write_cmos_sensor(0x0100, 0x01);  //
+*/
+
+       //@@PV_Quarter_size_30fps_800Mbps/lane_1296x972                                                   
+       //99 1296 972                                                                                                                     
+       //;;102 3601    157c                                                                                                              
+       //;;PCLK=HTS*VTS*fps=0x68c*0x7fd*30=1676*2045*30=102.85M                                          
+                                                                                                                                                         
+       OV56702ND_write_cmos_sensor(0x0100, 0x00);  //  
+       
+       OV56702ND_write_cmos_sensor(0x3501, 0x73);  //                                                    
+       OV56702ND_write_cmos_sensor(0x3502, 0x00);  //                                                    
+       OV56702ND_write_cmos_sensor(0x3508, 0x01);  //                                                    
+       OV56702ND_write_cmos_sensor(0x3509, 0x80);  //                                                    
+       OV56702ND_write_cmos_sensor(0x366e, 0x08);  //                                                    
+       OV56702ND_write_cmos_sensor(0x370b, 0x1b);  //                                                    
+       OV56702ND_write_cmos_sensor(0x3808, 0x05);  //                                                    
+       OV56702ND_write_cmos_sensor(0x3809, 0x10);  //                                                    
+       OV56702ND_write_cmos_sensor(0x380a, 0x03);  //                                                    
+       OV56702ND_write_cmos_sensor(0x380b, 0xcc);  //;c0                                                         
+       OV56702ND_write_cmos_sensor(0x380c, 0x06);  //                                                    
+       OV56702ND_write_cmos_sensor(0x380d, 0x8c);  //                                                    
+       OV56702ND_write_cmos_sensor(0x380e, 0x07);  //;03                                                         
+       OV56702ND_write_cmos_sensor(0x380f, 0xfd);  //;e0                                                         
+       OV56702ND_write_cmos_sensor(0x3814, 0x03);  //                                                    
+       OV56702ND_write_cmos_sensor(0x3820, 0x90);  //                                                    
+       OV56702ND_write_cmos_sensor(0x3821, 0x47);  //                                                    
+       OV56702ND_write_cmos_sensor(0x382a, 0x03);  //                                                    
+       OV56702ND_write_cmos_sensor(0x3845, 0x02);  //                                                    
+       OV56702ND_write_cmos_sensor(0x4009, 0x05);  //                                                    
+       OV56702ND_write_cmos_sensor(0x4502, 0x48);  //                                                    
+       OV56702ND_write_cmos_sensor(0x4508, 0x55);  //                                                    
+       OV56702ND_write_cmos_sensor(0x4509, 0x55);  //                                                    
+       OV56702ND_write_cmos_sensor(0x4600, 0x00);  //                                                    
+       OV56702ND_write_cmos_sensor(0x4601, 0x81);  //                                                    
+       OV56702ND_write_cmos_sensor(0x4017, 0x10);  //; threshold = 4LSB for Binning 
+       OV56702ND_write_cmos_sensor(0x400a, 0x02);  //;                                                   
+       OV56702ND_write_cmos_sensor(0x400b, 0x00);  //; 
+       
+       OV56702ND_write_cmos_sensor(0x0100, 0x01);  //  
+}
+
+
+void OV56702NDVideoSetting(void)
+{
+       OV56702NDDB(" OV56702NDvideoSetting_2lane enter:video/preview sync\n");
+
+       OV56702NDPreviewSetting();
+}
+
+
+
+void OV56702NDCaptureSetting(void)
+{
+       OV56702NDDB("OV56702NDCaptureSetting_2lane enter\n");
+
+       OV56702ND_write_cmos_sensor(0x0100, 0x00); 
+       
+       OV56702ND_write_cmos_sensor(0x3501, 0x5f); //long exposure
+       OV56702ND_write_cmos_sensor(0x3502, 0xd0);  //long exposure
+       
+       OV56702ND_write_cmos_sensor(0x3508, 0x03);  //gain
+       OV56702ND_write_cmos_sensor(0x3509, 0x00);  //gain
+       
+       OV56702ND_write_cmos_sensor(0x366e, 0x10); 
+       OV56702ND_write_cmos_sensor(0x370b, 0x1b); 
+       OV56702ND_write_cmos_sensor(0x3808, 0x0a); 
+       OV56702ND_write_cmos_sensor(0x3809, 0x20); 
+       OV56702ND_write_cmos_sensor(0x380a, 0x07); 
+       OV56702ND_write_cmos_sensor(0x380b, 0x98); 
+       OV56702ND_write_cmos_sensor(0x380c, 0x07); //;06
+       OV56702ND_write_cmos_sensor(0x380d, 0xdc); //;8c
+       OV56702ND_write_cmos_sensor(0x380e, 0x07); 
+       OV56702ND_write_cmos_sensor(0x380f, 0xfd); 
+       OV56702ND_write_cmos_sensor(0x3814, 0x01); 
+       OV56702ND_write_cmos_sensor(0x3820, 0x80); 
+       OV56702ND_write_cmos_sensor(0x3821, 0x46); 
+       OV56702ND_write_cmos_sensor(0x382a, 0x01);
+       
+       OV56702ND_write_cmos_sensor(0x3845, 0x00);  //v_offset for auto size mode
+       
+       OV56702ND_write_cmos_sensor(0x4009, 0x0d); 
+       OV56702ND_write_cmos_sensor(0x4502, 0x40); 
+       OV56702ND_write_cmos_sensor(0x4508, 0xaa); 
+       OV56702ND_write_cmos_sensor(0x4509, 0xaa); 
+       OV56702ND_write_cmos_sensor(0x4600, 0x01); 
+       OV56702ND_write_cmos_sensor(0x4601, 0x03); 
+       OV56702ND_write_cmos_sensor(0x4017, 0x08); //threshold= 2LSB for full size
+       OV56702ND_write_cmos_sensor(0x400a, 0x02); //
+       OV56702ND_write_cmos_sensor(0x400b, 0x00); //
+       
+       OV56702ND_write_cmos_sensor(0x0100, 0x01); 
+       
+}
+
+
+static void OV56702ND_Sensor_Init(void)
+{
+       OV56702NDDB("OV56702ND_Sensor_Init_2lane enter\n");
+       
+       OV56702ND_write_cmos_sensor(0x0103,0x01);// ; software reset
+       mdelay(10);
+       OV56702ND_write_cmos_sensor(0x0100, 0x00);// ; software standby
+       OV56702ND_write_cmos_sensor(0x0100, 0x00); 
+       OV56702ND_write_cmos_sensor(0x0300, 0x04); 
+       OV56702ND_write_cmos_sensor(0x0301, 0x00); 
+       OV56702ND_write_cmos_sensor(0x0302, 0x64); //;78
+       OV56702ND_write_cmos_sensor(0x0303, 0x00); 
+       OV56702ND_write_cmos_sensor(0x0304, 0x03); 
+       OV56702ND_write_cmos_sensor(0x0305, 0x01); 
+       OV56702ND_write_cmos_sensor(0x0306, 0x01); 
+       OV56702ND_write_cmos_sensor(0x030a, 0x00); 
+       OV56702ND_write_cmos_sensor(0x030b, 0x00); 
+       OV56702ND_write_cmos_sensor(0x030c, 0x00); 
+       OV56702ND_write_cmos_sensor(0x030d, 0x1e); 
+       OV56702ND_write_cmos_sensor(0x030e, 0x00); 
+       OV56702ND_write_cmos_sensor(0x030f, 0x06); 
+       OV56702ND_write_cmos_sensor(0x0312, 0x01); 
+       OV56702ND_write_cmos_sensor(0x3000, 0x00); 
+       OV56702ND_write_cmos_sensor(0x3002, 0x21); 
+       OV56702ND_write_cmos_sensor(0x3005, 0xf0); 
+       OV56702ND_write_cmos_sensor(0x3007, 0x00); 
+       OV56702ND_write_cmos_sensor(0x3015, 0x0f); 
+       OV56702ND_write_cmos_sensor(0x3018, 0x32); 
+       OV56702ND_write_cmos_sensor(0x301a, 0xf0); 
+       OV56702ND_write_cmos_sensor(0x301b, 0xf0); 
+       OV56702ND_write_cmos_sensor(0x301c, 0xf0); 
+       OV56702ND_write_cmos_sensor(0x301d, 0xf0); 
+       OV56702ND_write_cmos_sensor(0x301e, 0xf0); 
+       OV56702ND_write_cmos_sensor(0x3030, 0x00); 
+       OV56702ND_write_cmos_sensor(0x3031, 0x0a); 
+       OV56702ND_write_cmos_sensor(0x303c, 0xff); 
+       OV56702ND_write_cmos_sensor(0x303e, 0xff); 
+       OV56702ND_write_cmos_sensor(0x3040, 0xf0); 
+       OV56702ND_write_cmos_sensor(0x3041, 0x00); 
+       OV56702ND_write_cmos_sensor(0x3042, 0xf0); 
+       OV56702ND_write_cmos_sensor(0x3106, 0x11); 
+       OV56702ND_write_cmos_sensor(0x3500, 0x00); 
+       OV56702ND_write_cmos_sensor(0x3501, 0x7b); 
+       OV56702ND_write_cmos_sensor(0x3502, 0x00); 
+       OV56702ND_write_cmos_sensor(0x3503, 0x04); 
+       OV56702ND_write_cmos_sensor(0x3504, 0x03); 
+       OV56702ND_write_cmos_sensor(0x3505, 0x83); 
+       OV56702ND_write_cmos_sensor(0x3508, 0x07); 
+       OV56702ND_write_cmos_sensor(0x3509, 0x80); 
+       OV56702ND_write_cmos_sensor(0x350e, 0x04); 
+       OV56702ND_write_cmos_sensor(0x350f, 0x00); 
+       OV56702ND_write_cmos_sensor(0x3510, 0x00); 
+       OV56702ND_write_cmos_sensor(0x3511, 0x02); 
+       OV56702ND_write_cmos_sensor(0x3512, 0x00); 
+       OV56702ND_write_cmos_sensor(0x3601, 0xc8); 
+       OV56702ND_write_cmos_sensor(0x3610, 0x88); 
+       OV56702ND_write_cmos_sensor(0x3612, 0x48); 
+       OV56702ND_write_cmos_sensor(0x3614, 0x5b); 
+       OV56702ND_write_cmos_sensor(0x3615, 0x96); 
+       OV56702ND_write_cmos_sensor(0x3621, 0xd0); 
+       OV56702ND_write_cmos_sensor(0x3622, 0x00); 
+       OV56702ND_write_cmos_sensor(0x3623, 0x00); 
+       OV56702ND_write_cmos_sensor(0x3633, 0x13); 
+       OV56702ND_write_cmos_sensor(0x3634, 0x13); 
+       OV56702ND_write_cmos_sensor(0x3635, 0x13); 
+       OV56702ND_write_cmos_sensor(0x3636, 0x13); 
+       OV56702ND_write_cmos_sensor(0x3645, 0x13); 
+       OV56702ND_write_cmos_sensor(0x3646, 0x82); 
+       OV56702ND_write_cmos_sensor(0x3650, 0x00); 
+       OV56702ND_write_cmos_sensor(0x3652, 0xff); 
+       OV56702ND_write_cmos_sensor(0x3655, 0x20); 
+       OV56702ND_write_cmos_sensor(0x3656, 0xff); 
+       OV56702ND_write_cmos_sensor(0x365a, 0xff); 
+       OV56702ND_write_cmos_sensor(0x365e, 0xff); 
+       OV56702ND_write_cmos_sensor(0x3668, 0x00); 
+       OV56702ND_write_cmos_sensor(0x366a, 0x07); 
+       OV56702ND_write_cmos_sensor(0x366e, 0x10); 
+       OV56702ND_write_cmos_sensor(0x366d, 0x00); 
+       OV56702ND_write_cmos_sensor(0x366f, 0x80); 
+       OV56702ND_write_cmos_sensor(0x3700, 0x28); 
+       OV56702ND_write_cmos_sensor(0x3701, 0x10); 
+       OV56702ND_write_cmos_sensor(0x3702, 0x3a); 
+       OV56702ND_write_cmos_sensor(0x3703, 0x19); 
+       OV56702ND_write_cmos_sensor(0x3704, 0x10);
+       OV56702ND_write_cmos_sensor(0x3705, 0x00); 
+       OV56702ND_write_cmos_sensor(0x3706, 0x66); 
+       OV56702ND_write_cmos_sensor(0x3707, 0x08); 
+       OV56702ND_write_cmos_sensor(0x3708, 0x34); 
+       OV56702ND_write_cmos_sensor(0x3709, 0x40); 
+       OV56702ND_write_cmos_sensor(0x370a, 0x01); 
+       OV56702ND_write_cmos_sensor(0x370b, 0x1b); 
+       OV56702ND_write_cmos_sensor(0x3714, 0x24); 
+       OV56702ND_write_cmos_sensor(0x371a, 0x3e); 
+       OV56702ND_write_cmos_sensor(0x3733, 0x00); 
+       OV56702ND_write_cmos_sensor(0x3734, 0x00); 
+       OV56702ND_write_cmos_sensor(0x373a, 0x05); 
+       OV56702ND_write_cmos_sensor(0x373b, 0x06); 
+       OV56702ND_write_cmos_sensor(0x373c, 0x0a); 
+       OV56702ND_write_cmos_sensor(0x373f, 0xa0); 
+       OV56702ND_write_cmos_sensor(0x3755, 0x00); 
+       OV56702ND_write_cmos_sensor(0x3758, 0x00); 
+       OV56702ND_write_cmos_sensor(0x375b, 0x0e);
+       OV56702ND_write_cmos_sensor(0x3766, 0x5f); 
+       OV56702ND_write_cmos_sensor(0x3768, 0x00); 
+       OV56702ND_write_cmos_sensor(0x3769, 0x22); 
+       OV56702ND_write_cmos_sensor(0x3773, 0x08); 
+       OV56702ND_write_cmos_sensor(0x3774, 0x1f); 
+       OV56702ND_write_cmos_sensor(0x3776, 0x06); 
+       OV56702ND_write_cmos_sensor(0x37a0, 0x88); 
+       OV56702ND_write_cmos_sensor(0x37a1, 0x5c); 
+       OV56702ND_write_cmos_sensor(0x37a7, 0x88); 
+       OV56702ND_write_cmos_sensor(0x37a8, 0x70); 
+       OV56702ND_write_cmos_sensor(0x37aa, 0x88); 
+       OV56702ND_write_cmos_sensor(0x37ab, 0x48); 
+       OV56702ND_write_cmos_sensor(0x37b3, 0x66); 
+       OV56702ND_write_cmos_sensor(0x37c2, 0x04); 
+       OV56702ND_write_cmos_sensor(0x37c5, 0x00); 
+       OV56702ND_write_cmos_sensor(0x37c8, 0x00); 
+       OV56702ND_write_cmos_sensor(0x3800, 0x00); 
+       OV56702ND_write_cmos_sensor(0x3801, 0x0c); 
+       OV56702ND_write_cmos_sensor(0x3802, 0x00); 
+       OV56702ND_write_cmos_sensor(0x3803, 0x04); 
+       OV56702ND_write_cmos_sensor(0x3804, 0x0a); 
+       OV56702ND_write_cmos_sensor(0x3805, 0x33); 
+       OV56702ND_write_cmos_sensor(0x3806, 0x07); 
+       OV56702ND_write_cmos_sensor(0x3807, 0xa3); 
+       OV56702ND_write_cmos_sensor(0x3808, 0x0a); 
+       OV56702ND_write_cmos_sensor(0x3809, 0x20); 
+       OV56702ND_write_cmos_sensor(0x380a, 0x07); 
+       OV56702ND_write_cmos_sensor(0x380b, 0x98); 
+       OV56702ND_write_cmos_sensor(0x380c, 0x07); // ;06
+       OV56702ND_write_cmos_sensor(0x380d, 0xdc); // ;8c
+       OV56702ND_write_cmos_sensor(0x380e, 0x07); 
+       OV56702ND_write_cmos_sensor(0x380f, 0xb8); 
+       OV56702ND_write_cmos_sensor(0x3811, 0x04); 
+       OV56702ND_write_cmos_sensor(0x3813, 0x02); 
+       OV56702ND_write_cmos_sensor(0x3814, 0x01); 
+       OV56702ND_write_cmos_sensor(0x3815, 0x01); 
+       OV56702ND_write_cmos_sensor(0x3816, 0x00); 
+       OV56702ND_write_cmos_sensor(0x3817, 0x00); 
+       OV56702ND_write_cmos_sensor(0x3818, 0x00); 
+       OV56702ND_write_cmos_sensor(0x3819, 0x00); 
+       OV56702ND_write_cmos_sensor(0x3820, 0x80); 
+       OV56702ND_write_cmos_sensor(0x3821, 0x46); 
+       OV56702ND_write_cmos_sensor(0x3822, 0x48); 
+       OV56702ND_write_cmos_sensor(0x3826, 0x00); 
+       OV56702ND_write_cmos_sensor(0x3827, 0x08); 
+       OV56702ND_write_cmos_sensor(0x382a, 0x01); 
+       OV56702ND_write_cmos_sensor(0x382b, 0x01); 
+       OV56702ND_write_cmos_sensor(0x3830, 0x08); 
+       OV56702ND_write_cmos_sensor(0x3836, 0x02); 
+       OV56702ND_write_cmos_sensor(0x3837, 0x00); 
+       OV56702ND_write_cmos_sensor(0x3838, 0x10); 
+       OV56702ND_write_cmos_sensor(0x3841, 0xff); 
+       OV56702ND_write_cmos_sensor(0x3846, 0x48); 
+       OV56702ND_write_cmos_sensor(0x3861, 0x00); 
+       OV56702ND_write_cmos_sensor(0x3862, 0x04);//x00); 
+       OV56702ND_write_cmos_sensor(0x3863, 0x06);//0x18); 
+       OV56702ND_write_cmos_sensor(0x3a11, 0x01); 
+       OV56702ND_write_cmos_sensor(0x3a12, 0x78); 
+       OV56702ND_write_cmos_sensor(0x3b00, 0x00); 
+       OV56702ND_write_cmos_sensor(0x3b02, 0x00); 
+       OV56702ND_write_cmos_sensor(0x3b03, 0x00); 
+       OV56702ND_write_cmos_sensor(0x3b04, 0x00); 
+       OV56702ND_write_cmos_sensor(0x3b05, 0x00); 
+       OV56702ND_write_cmos_sensor(0x3c00, 0x89); 
+       OV56702ND_write_cmos_sensor(0x3c01, 0xab); 
+       OV56702ND_write_cmos_sensor(0x3c02, 0x01); 
+       OV56702ND_write_cmos_sensor(0x3c03, 0x00); 
+       OV56702ND_write_cmos_sensor(0x3c04, 0x00); 
+       OV56702ND_write_cmos_sensor(0x3c05, 0x03); 
+       OV56702ND_write_cmos_sensor(0x3c06, 0x00); 
+       OV56702ND_write_cmos_sensor(0x3c07, 0x05); 
+       OV56702ND_write_cmos_sensor(0x3c0c, 0x00); 
+       OV56702ND_write_cmos_sensor(0x3c0d, 0x00); 
+       OV56702ND_write_cmos_sensor(0x3c0e, 0x00); 
+       OV56702ND_write_cmos_sensor(0x3c0f, 0x00); 
+       OV56702ND_write_cmos_sensor(0x3c40, 0x00); 
+       OV56702ND_write_cmos_sensor(0x3c41, 0xa3); 
+       OV56702ND_write_cmos_sensor(0x3c43, 0x7d); 
+       OV56702ND_write_cmos_sensor(0x3c45, 0xd7); 
+       OV56702ND_write_cmos_sensor(0x3c47, 0xfc); 
+       OV56702ND_write_cmos_sensor(0x3c50, 0x05); 
+       OV56702ND_write_cmos_sensor(0x3c52, 0xaa); 
+       OV56702ND_write_cmos_sensor(0x3c54, 0x71); 
+       OV56702ND_write_cmos_sensor(0x3c56, 0x80); 
+       OV56702ND_write_cmos_sensor(0x3d85, 0x17); 
+       OV56702ND_write_cmos_sensor(0x3f03, 0x00); 
+       OV56702ND_write_cmos_sensor(0x3f0a, 0x00); 
+       OV56702ND_write_cmos_sensor(0x3f0b, 0x00); 
+       OV56702ND_write_cmos_sensor(0x4001, 0x60); 
+       OV56702ND_write_cmos_sensor(0x4009, 0x0d); 
+       OV56702ND_write_cmos_sensor(0x4020, 0x00); 
+       OV56702ND_write_cmos_sensor(0x4021, 0x00); 
+       OV56702ND_write_cmos_sensor(0x4022, 0x00); 
+       OV56702ND_write_cmos_sensor(0x4023, 0x00); 
+       OV56702ND_write_cmos_sensor(0x4024, 0x00); 
+       OV56702ND_write_cmos_sensor(0x4025, 0x00); 
+       OV56702ND_write_cmos_sensor(0x4026, 0x00); 
+       OV56702ND_write_cmos_sensor(0x4027, 0x00); 
+       OV56702ND_write_cmos_sensor(0x4028, 0x00); 
+       OV56702ND_write_cmos_sensor(0x4029, 0x00); 
+       OV56702ND_write_cmos_sensor(0x402a, 0x00); 
+       OV56702ND_write_cmos_sensor(0x402b, 0x00); 
+       OV56702ND_write_cmos_sensor(0x402c, 0x00); 
+       OV56702ND_write_cmos_sensor(0x402d, 0x00); 
+       OV56702ND_write_cmos_sensor(0x402e, 0x00); 
+       OV56702ND_write_cmos_sensor(0x402f, 0x00); 
+       OV56702ND_write_cmos_sensor(0x4040, 0x00); 
+       OV56702ND_write_cmos_sensor(0x4041, 0x03);//0x00); 
+       OV56702ND_write_cmos_sensor(0x4042, 0x00); 
+       OV56702ND_write_cmos_sensor(0x4043, 0x7a);//0x80); 
+       OV56702ND_write_cmos_sensor(0x4044, 0x00); 
+       OV56702ND_write_cmos_sensor(0x4045, 0x7a);//0x80); 
+       OV56702ND_write_cmos_sensor(0x4046, 0x00); 
+       OV56702ND_write_cmos_sensor(0x4047, 0x7a);//0x80); 
+       OV56702ND_write_cmos_sensor(0x4048, 0x00); 
+       OV56702ND_write_cmos_sensor(0x4049, 0x7a);//0x80); 
+       OV56702ND_write_cmos_sensor(0x4303, 0x00); 
+       OV56702ND_write_cmos_sensor(0x4307, 0x30); 
+       OV56702ND_write_cmos_sensor(0x4500, 0x58); 
+       OV56702ND_write_cmos_sensor(0x4501, 0x04); 
+       OV56702ND_write_cmos_sensor(0x4502, 0x40); 
+       OV56702ND_write_cmos_sensor(0x4503, 0x10); 
+       OV56702ND_write_cmos_sensor(0x4508, 0xaa); 
+       OV56702ND_write_cmos_sensor(0x4509, 0xaa); 
+       OV56702ND_write_cmos_sensor(0x450a, 0x00); 
+       OV56702ND_write_cmos_sensor(0x450b, 0x00); 
+       OV56702ND_write_cmos_sensor(0x4600, 0x01); 
+       OV56702ND_write_cmos_sensor(0x4601, 0x03); 
+       OV56702ND_write_cmos_sensor(0x4700, 0xa4); 
+       OV56702ND_write_cmos_sensor(0x4800, 0x4c); 
+       OV56702ND_write_cmos_sensor(0x4816, 0x53); 
+       OV56702ND_write_cmos_sensor(0x481f, 0x40); 
+       OV56702ND_write_cmos_sensor(0x4837, 0x14); // ;11
+       OV56702ND_write_cmos_sensor(0x5000, 0x56);//0x16); 
+       OV56702ND_write_cmos_sensor(0x5001, 0x01); 
+       OV56702ND_write_cmos_sensor(0x5002, 0x28);//0xa8); 
+       OV56702ND_write_cmos_sensor(0x5004, 0x0c); 
+       OV56702ND_write_cmos_sensor(0x5006, 0x0c); 
+       OV56702ND_write_cmos_sensor(0x5007, 0xe0); 
+       OV56702ND_write_cmos_sensor(0x5008, 0x01); 
+       OV56702ND_write_cmos_sensor(0x5009, 0xb0); 
+       OV56702ND_write_cmos_sensor(0x5901, 0x00); 
+       OV56702ND_write_cmos_sensor(0x5a01, 0x00); 
+       OV56702ND_write_cmos_sensor(0x5a03, 0x00); 
+       OV56702ND_write_cmos_sensor(0x5a04, 0x0c); 
+       OV56702ND_write_cmos_sensor(0x5a05, 0xe0); 
+       OV56702ND_write_cmos_sensor(0x5a06, 0x09); 
+       OV56702ND_write_cmos_sensor(0x5a07, 0xb0); 
+       OV56702ND_write_cmos_sensor(0x5a08, 0x06); 
+       OV56702ND_write_cmos_sensor(0x5e00, 0x00); 
+       //for BLC
+       OV56702ND_write_cmos_sensor(0x3734, 0x40); 
+       OV56702ND_write_cmos_sensor(0x5b00, 0x01); 
+       OV56702ND_write_cmos_sensor(0x5b01, 0x10); 
+       OV56702ND_write_cmos_sensor(0x5b02, 0x01); 
+       OV56702ND_write_cmos_sensor(0x5b03, 0xdb); 
+       OV56702ND_write_cmos_sensor(0x3d8c, 0x71);
+       OV56702ND_write_cmos_sensor(0x3d8d, 0xea);
+       OV56702ND_write_cmos_sensor(0x4017, 0x08);
+       
+       OV56702ND_write_cmos_sensor(0x3618, 0x2a); 
+                                                                  
+       //;Ally031414                                     
+       OV56702ND_write_cmos_sensor(0x3734, 0x40); //   ;; Improve HFPN
+       OV56702ND_write_cmos_sensor(0x5b00, 0x01);  // ;; [2:0] otp start addr[10:8]
+       OV56702ND_write_cmos_sensor(0x5b01, 0x10);  // ;; [7:0] otp start addr[7:0]
+       OV56702ND_write_cmos_sensor(0x5b02, 0x01);  // ;; [2:0] otp end addr[10:8]
+       OV56702ND_write_cmos_sensor(0x5b03, 0xDB);  // ;; [7:0] otp end addr[7:0]
+       OV56702ND_write_cmos_sensor(0x3d8c, 0x71); //; Header address high byte
+       OV56702ND_write_cmos_sensor(0x3d8d, 0xEA); //; Header address low byte
+       OV56702ND_write_cmos_sensor(0x4017, 0x08); // ; threshold= 2LSB for full size
+                                                                 
+       //;Strong DPC1.53                                
+       OV56702ND_write_cmos_sensor(0x5780, 0x3e); 
+       OV56702ND_write_cmos_sensor(0x5781, 0x0f); 
+       OV56702ND_write_cmos_sensor(0x5782, 0x44); 
+       OV56702ND_write_cmos_sensor(0x5783, 0x02); 
+       OV56702ND_write_cmos_sensor(0x5784, 0x01); 
+       OV56702ND_write_cmos_sensor(0x5785, 0x00); 
+       OV56702ND_write_cmos_sensor(0x5786, 0x00); 
+       OV56702ND_write_cmos_sensor(0x5787, 0x04); 
+       OV56702ND_write_cmos_sensor(0x5788, 0x02); 
+       OV56702ND_write_cmos_sensor(0x5789, 0x0f); 
+       OV56702ND_write_cmos_sensor(0x578a, 0xfd); 
+       OV56702ND_write_cmos_sensor(0x578b, 0xf5); 
+       OV56702ND_write_cmos_sensor(0x578c, 0xf5); 
+       OV56702ND_write_cmos_sensor(0x578d, 0x03); 
+       OV56702ND_write_cmos_sensor(0x578e, 0x08); 
+       OV56702ND_write_cmos_sensor(0x578f, 0x0c); 
+       OV56702ND_write_cmos_sensor(0x5790, 0x08); 
+       OV56702ND_write_cmos_sensor(0x5791, 0x04); 
+       OV56702ND_write_cmos_sensor(0x5792, 0x00); 
+       OV56702ND_write_cmos_sensor(0x5793, 0x52); 
+       OV56702ND_write_cmos_sensor(0x5794, 0xa3); 
+       //;Ping                                           
+       OV56702ND_write_cmos_sensor(0x380e, 0x07); //; fps fine adjustment
+       OV56702ND_write_cmos_sensor(0x380f, 0xfd); //; fps fine adjustment
+       OV56702ND_write_cmos_sensor(0x3503, 0x00); //; real gain [2]   gain no delay, shutter no delay
+       //;added                                         
+       OV56702ND_write_cmos_sensor(0x3d85, 0x17); 
+       OV56702ND_write_cmos_sensor(0x3655, 0x20); 
+                                                                  
+       OV56702ND_write_cmos_sensor(0x0100, 0x01); //;01
+
+  ov56702nd_otp_config();
+}
+
+
+UINT32 OV56702NDOpen(void)
+{
+
+       volatile signed int i;
+       kal_uint16 sensor_id = 0;
+
+       OV56702NDDB("OV56702ND Open enter :\n ");
+       OV56702ND_write_cmos_sensor(0x0103,0x01);// Reset sensor
+  mdelay(2);
+
+       for(i=0;i<2;i++)
+       {
+               sensor_id = (OV56702ND_read_cmos_sensor(0x300B)<<8)|OV56702ND_read_cmos_sensor(0x300C);
+               OV56702NDDB("OV56702ND READ ID :%x",sensor_id);
+               if(sensor_id != OV5670MIPI_SENSOR_ID)
+               {
+                       return ERROR_SENSOR_CONNECT_FAIL;
+               }else
+                       break;
+       }
+       
+       OV56702ND_Sensor_Init();
+  OV56702ND_Init_Para();
+       OV56702NDDB("OV56702NDOpen exit :\n ");
+
+ return ERROR_NONE;
+}
+
+void OV56702NDGetModuleID(void)
+{
+       struct otp_struct otp_info ; 
+       
+       OV56702ND_write_cmos_sensor(0x0100, 0x01); //stream on
+       read_otp(&otp_info);
+       OV56702ND_write_cmos_sensor(0x0100, 0x00); //stream off
+}
+
+UINT32 OV56702NDGetSensorID(UINT32 *sensorID)
+{
+    int  retry = 2;
+
+       OV56702NDDB("OV56702NDGetSensorID enter :\n ");
+    mdelay(5);
+
+    do {
+        *sensorID = (OV56702ND_read_cmos_sensor(0x300B)<<8)|OV56702ND_read_cmos_sensor(0x300C);
+        if (*sensorID == OV56702NDMIPI_SENSOR_ID)
+       {
+               OV56702NDDB("Sensor ID = 0x%04x\n", *sensorID);
+               OV56702NDGetModuleID();
+               break;
+       }
+       OV56702NDDB("Read Sensor ID Fail = 0x%04x\n", *sensorID);
+        retry--;
+    } while (retry > 0);
+
+    if (*sensorID != OV56702NDMIPI_SENSOR_ID) {
+               OV56702NDDB("Read Sensor ID Fail = 0x%04x\n", *sensorID);
+
+               *sensorID = 0xFFFFFFFF;
+               return ERROR_SENSOR_CONNECT_FAIL;
+    } else {
+               OV56702NDDB("alexadd %s module_id=%d", __func__, module_id);
+               if (module_id != 0x44) {
+                       *sensorID = 0xFFFFFFFF;
+                       return ERROR_SENSOR_CONNECT_FAIL;
+               }
+    }
+    return ERROR_NONE;
+}
+
+
+void OV56702ND_SetShutter(kal_uint32 iShutter)
+{
+
+   spin_lock(&ov56702ndmipiraw_drv_lock);
+   OV56702ND.shutter= iShutter;
+   spin_unlock(&ov56702ndmipiraw_drv_lock);
+
+   OV56702ND_write_shutter(iShutter);
+   return;
+}
+
+
+
+UINT32 OV56702ND_read_shutter(void)
+{
+
+       kal_uint16 temp_reg1, temp_reg2 ,temp_reg3;
+       UINT32 shutter =0;
+       temp_reg1 = OV56702ND_read_cmos_sensor(0x3500);    // AEC[b19~b16]
+       temp_reg2 = OV56702ND_read_cmos_sensor(0x3501);    // AEC[b15~b8]
+       temp_reg3 = OV56702ND_read_cmos_sensor(0x3502);    // AEC[b7~b0]
+       
+       shutter  = (temp_reg1 <<12)| (temp_reg2<<4)|(temp_reg3>>4);
+
+       return shutter;
+}
+
+void OV56702ND_NightMode(kal_bool bEnable)
+{
+
+}
+
+UINT32 OV56702NDClose(void)
+{
+
+    return ERROR_NONE;
+}
+
+#if 0
+void OV56702NDSetFlipMirror(kal_int32 imgMirror)
+{
+       kal_int16 mirror=0,flip=0;
+       mirror= OV56702ND_read_cmos_sensor(0x3820);
+       flip  = OV56702ND_read_cmos_sensor(0x3821);
+
+    switch (imgMirror)
+    {
+        case IMAGE_H_MIRROR://IMAGE_NORMAL:
+            OV56702ND_write_cmos_sensor(0x3820, (mirror & (0xF9)));//Set normal
+            OV56702ND_write_cmos_sensor(0x3821, (flip & (0xF9)));      //Set normal
+            break;
+        case IMAGE_NORMAL://IMAGE_V_MIRROR:
+            OV56702ND_write_cmos_sensor(0x3820, (mirror & (0xF9)));//Set flip
+            OV56702ND_write_cmos_sensor(0x3821, (flip | (0x06)));      //Set flip
+            break;
+        case IMAGE_HV_MIRROR://IMAGE_H_MIRROR:
+            OV56702ND_write_cmos_sensor(0x3820, (mirror |(0x06)));     //Set mirror
+            OV56702ND_write_cmos_sensor(0x3821, (flip & (0xF9)));      //Set mirror
+            break;
+        case IMAGE_V_MIRROR://IMAGE_HV_MIRROR:
+            OV56702ND_write_cmos_sensor(0x3820, (mirror |(0x06)));     //Set mirror & flip
+            OV56702ND_write_cmos_sensor(0x3821, (flip |(0x06)));       //Set mirror & flip
+            break;
+    }
+}
+#endif
+
+
+UINT32 OV56702NDPreview(MSDK_SENSOR_EXPOSURE_WINDOW_STRUCT *image_window,
+                                                MSDK_SENSOR_CONFIG_STRUCT *sensor_config_data)
+{
+
+       OV56702NDDB("OV56702NDPreview enter:");
+
+       //OV56702NDPreviewSetting();
+       OV56702NDCaptureSetting();
+       spin_lock(&ov56702ndmipiraw_drv_lock);
+       OV56702ND.sensorMode = SENSOR_MODE_PREVIEW; 
+       OV56702ND.DummyPixels = 0;
+       OV56702ND.DummyLines = 0 ;
+       OV56702ND_FeatureControl_PERIOD_PixelNum=OV56702ND_PV_PERIOD_PIXEL_NUMS+ OV56702ND.DummyPixels;
+       OV56702ND_FeatureControl_PERIOD_LineNum=OV56702ND_PV_PERIOD_LINE_NUMS+OV56702ND.DummyLines;
+       OV56702ND.imgMirror = sensor_config_data->SensorImageMirror;
+       spin_unlock(&ov56702ndmipiraw_drv_lock);
+       
+       //OV56702NDSetFlipMirror(sensor_config_data->SensorImageMirror);
+
+    mdelay(40);//THIS DELAY SHOULD BE NEED BY CTS OR MONKEY
+       OV56702NDDB("OV56702NDPreview exit:\n");
+
+         
+    return ERROR_NONE;
+}
+
+
+UINT32 OV56702NDVideo(MSDK_SENSOR_EXPOSURE_WINDOW_STRUCT *image_window,
+                                                MSDK_SENSOR_CONFIG_STRUCT *sensor_config_data)
+{
+
+       OV56702NDDB("OV56702NDVideo enter:");
+
+       OV56702NDVideoSetting();
+
+       spin_lock(&ov56702ndmipiraw_drv_lock);
+       OV56702ND.sensorMode = SENSOR_MODE_VIDEO;
+       OV56702ND_FeatureControl_PERIOD_PixelNum=OV56702ND_VIDEO_PERIOD_PIXEL_NUMS+ OV56702ND.DummyPixels;
+       OV56702ND_FeatureControl_PERIOD_LineNum=OV56702ND_VIDEO_PERIOD_LINE_NUMS+OV56702ND.DummyLines;
+       OV56702ND.imgMirror = sensor_config_data->SensorImageMirror;
+       spin_unlock(&ov56702ndmipiraw_drv_lock);
+       
+       //OV56702NDSetFlipMirror(sensor_config_data->SensorImageMirror);
+
+    mdelay(40);//THIS DELAY SHOULD BE NEED BY CTS OR MONKEY
+       OV56702NDDB("OV56702NDVideo exit:\n");
+    return ERROR_NONE;
+}
+
+
+UINT32 OV56702NDCapture(MSDK_SENSOR_EXPOSURE_WINDOW_STRUCT *image_window,
+                                                MSDK_SENSOR_CONFIG_STRUCT *sensor_config_data)
+{
+
+       //kal_uint32 shutter = OV56702ND.shutter;
+
+       if( SENSOR_MODE_CAPTURE== OV56702ND.sensorMode)
+       {
+               OV56702NDDB("OV56702NDCapture BusrtShot / ZSD!!!\n");
+       }
+       else
+       {
+               OV56702NDDB("OV56702NDCapture enter:\n");
+
+               OV56702NDCaptureSetting();
+           mdelay(40);//THIS DELAY SHOULD BE NEED BY CTS OR MONKEY
+
+               spin_lock(&ov56702ndmipiraw_drv_lock);
+               OV56702ND.sensorMode = SENSOR_MODE_CAPTURE;
+               OV56702ND.imgMirror = sensor_config_data->SensorImageMirror;
+               OV56702ND.DummyPixels = 0;
+               OV56702ND.DummyLines = 0 ;
+               OV56702ND_FeatureControl_PERIOD_PixelNum = OV56702ND_FULL_PERIOD_PIXEL_NUMS + OV56702ND.DummyPixels;
+               OV56702ND_FeatureControl_PERIOD_LineNum = OV56702ND_FULL_PERIOD_LINE_NUMS + OV56702ND.DummyLines;
+               spin_unlock(&ov56702ndmipiraw_drv_lock);
+
+               //OV56702NDSetFlipMirror(sensor_config_data->SensorImageMirror);
+
+               OV56702NDDB("OV56702NDCapture exit:\n");
+       }
+
+       if(OV56702ND_During_testpattern == KAL_TRUE)
+       {
+               OV56702ND_write_cmos_sensor(0x4303,0x80);
+       }
+
+    return ERROR_NONE;
+}      
+
+
+
+UINT32 OV56702NDGetResolution(MSDK_SENSOR_RESOLUTION_INFO_STRUCT *pSensorResolution)
+{
+
+    OV56702NDDB("OV56702NDGetResolution!!\n");
+
+       pSensorResolution->SensorPreviewWidth   = OV56702ND_IMAGE_SENSOR_FULL_WIDTH;
+    pSensorResolution->SensorPreviewHeight     = OV56702ND_IMAGE_SENSOR_FULL_HEIGHT;
+       
+    pSensorResolution->SensorFullWidth         = OV56702ND_IMAGE_SENSOR_FULL_WIDTH;
+    pSensorResolution->SensorFullHeight                = OV56702ND_IMAGE_SENSOR_FULL_HEIGHT;
+       
+    pSensorResolution->SensorVideoWidth                = OV56702ND_IMAGE_SENSOR_VIDEO_WIDTH;
+    pSensorResolution->SensorVideoHeight    = OV56702ND_IMAGE_SENSOR_VIDEO_HEIGHT;
+    return ERROR_NONE;
+}   
+
+UINT32 OV56702NDGetInfo(MSDK_SCENARIO_ID_ENUM ScenarioId,
+                                                MSDK_SENSOR_INFO_STRUCT *pSensorInfo,
+                                                MSDK_SENSOR_CONFIG_STRUCT *pSensorConfigData)
+{
+
+       spin_lock(&ov56702ndmipiraw_drv_lock);
+       OV56702ND.imgMirror = pSensorConfigData->SensorImageMirror ;
+       spin_unlock(&ov56702ndmipiraw_drv_lock);
+
+    pSensorInfo->SensorOutputDataFormat= SENSOR_OUTPUT_FORMAT_RAW_B;
+   
+    pSensorInfo->SensorClockPolarity =SENSOR_CLOCK_POLARITY_LOW;
+    pSensorInfo->SensorClockFallingPolarity=SENSOR_CLOCK_POLARITY_LOW;
+    pSensorInfo->SensorHsyncPolarity = SENSOR_CLOCK_POLARITY_LOW;
+    pSensorInfo->SensorVsyncPolarity = SENSOR_CLOCK_POLARITY_LOW;
+
+    pSensorInfo->SensroInterfaceType=SENSOR_INTERFACE_TYPE_MIPI;
+
+    pSensorInfo->CaptureDelayFrame = 2;
+    pSensorInfo->PreviewDelayFrame = 2;
+    pSensorInfo->VideoDelayFrame = 2;
+
+    pSensorInfo->SensorDrivingCurrent = ISP_DRIVING_8MA;
+    pSensorInfo->AEShutDelayFrame = 0;     
+    pSensorInfo->AESensorGainDelayFrame = 0;
+    pSensorInfo->AEISPGainDelayFrame = 2;
+
+    switch (ScenarioId)
+    {
+        case MSDK_SCENARIO_ID_CAMERA_PREVIEW:
+            pSensorInfo->SensorClockFreq=24;
+            pSensorInfo->SensorClockRisingCount= 0;
+
+            pSensorInfo->SensorGrabStartX = OV56702ND_PV_X_START;
+            pSensorInfo->SensorGrabStartY = OV56702ND_PV_Y_START;
+
+            pSensorInfo->SensorMIPILaneNumber = SENSOR_MIPI_2_LANE;
+                       
+            pSensorInfo->MIPIDataLowPwr2HighSpeedTermDelayCount = 0;
+               pSensorInfo->MIPIDataLowPwr2HighSpeedSettleDelayCount = 14;
+               pSensorInfo->MIPICLKLowPwr2HighSpeedTermDelayCount = 0;
+            pSensorInfo->SensorPacketECCOrder = 1;
+            break;
+        case MSDK_SCENARIO_ID_VIDEO_PREVIEW:
+            pSensorInfo->SensorClockFreq=24;
+            pSensorInfo->SensorClockRisingCount= 0;
+
+            pSensorInfo->SensorGrabStartX = OV56702ND_VIDEO_X_START;
+            pSensorInfo->SensorGrabStartY = OV56702ND_VIDEO_Y_START;
+
+            pSensorInfo->SensorMIPILaneNumber = SENSOR_MIPI_2_LANE;
+                       
+            pSensorInfo->MIPIDataLowPwr2HighSpeedTermDelayCount = 0;
+               pSensorInfo->MIPIDataLowPwr2HighSpeedSettleDelayCount = 14;
+               pSensorInfo->MIPICLKLowPwr2HighSpeedTermDelayCount = 0;
+            pSensorInfo->SensorPacketECCOrder = 1;
+            break;
+        case MSDK_SCENARIO_ID_CAMERA_CAPTURE_JPEG:
+               case MSDK_SCENARIO_ID_CAMERA_ZSD:
+            pSensorInfo->SensorClockFreq=24;
+            pSensorInfo->SensorClockRisingCount= 0;
+
+            pSensorInfo->SensorGrabStartX = OV56702ND_FULL_X_START;    
+            pSensorInfo->SensorGrabStartY = OV56702ND_FULL_Y_START;    
+
+            pSensorInfo->SensorMIPILaneNumber = SENSOR_MIPI_2_LANE;
+                       
+            pSensorInfo->MIPIDataLowPwr2HighSpeedTermDelayCount = 0;
+            pSensorInfo->MIPIDataLowPwr2HighSpeedSettleDelayCount = 14;
+            pSensorInfo->MIPICLKLowPwr2HighSpeedTermDelayCount = 0;
+            pSensorInfo->SensorPacketECCOrder = 1;
+            break;
+        default:
+                       pSensorInfo->SensorClockFreq=24;
+            pSensorInfo->SensorClockRisingCount= 0;
+
+            pSensorInfo->SensorGrabStartX = OV56702ND_PV_X_START;
+            pSensorInfo->SensorGrabStartY = OV56702ND_PV_Y_START;
+
+            pSensorInfo->SensorMIPILaneNumber = SENSOR_MIPI_2_LANE;
+                       
+            pSensorInfo->MIPIDataLowPwr2HighSpeedTermDelayCount = 0;
+               pSensorInfo->MIPIDataLowPwr2HighSpeedSettleDelayCount = 14;
+               pSensorInfo->MIPICLKLowPwr2HighSpeedTermDelayCount = 0;
+            pSensorInfo->SensorPacketECCOrder = 1;
+            break;
+    }
+
+    memcpy(pSensorConfigData, &OV56702NDSensorConfigData, sizeof(MSDK_SENSOR_CONFIG_STRUCT));
+
+    return ERROR_NONE;
+}   /* OV56702NDGetInfo() */
+
+
+
+UINT32 OV56702NDControl(MSDK_SCENARIO_ID_ENUM ScenarioId, MSDK_SENSOR_EXPOSURE_WINDOW_STRUCT *pImageWindow,
+                                                MSDK_SENSOR_CONFIG_STRUCT *pSensorConfigData)
+{
+               spin_lock(&ov56702ndmipiraw_drv_lock);
+               OV56702NDCurrentScenarioId = ScenarioId;
+               spin_unlock(&ov56702ndmipiraw_drv_lock);
+               
+               OV56702NDDB("OV56702NDCurrentScenarioId=%d\n",OV56702NDCurrentScenarioId);
+
+       switch (ScenarioId)
+    {
+        case MSDK_SCENARIO_ID_CAMERA_PREVIEW:
+            OV56702NDPreview(pImageWindow, pSensorConfigData);
+            break;
+        case MSDK_SCENARIO_ID_VIDEO_PREVIEW:
+                       OV56702NDDB("OV56702ND video_preiew sync\n");
+                       OV56702NDVideo(pImageWindow, pSensorConfigData);
+                       break;
+        case MSDK_SCENARIO_ID_CAMERA_CAPTURE_JPEG:
+               case MSDK_SCENARIO_ID_CAMERA_ZSD:
+            OV56702NDCapture(pImageWindow, pSensorConfigData);
+            break;
+
+        default:
+            return ERROR_INVALID_SCENARIO_ID;
+
+    }
+    return ERROR_NONE;
+} /* OV56702NDControl() */
+
+
+
+kal_uint32 OV56702ND_SET_FrameLength_ByVideoMode(UINT16 Video_TargetFps)
+{
+    UINT32 frameRate = 0;
+       kal_uint32 MIN_FrameLength=0;
+       
+       if(OV56702ND.OV56702NDAutoFlickerMode == KAL_TRUE)
+       {
+               if (Video_TargetFps==30)
+                       frameRate= OV56702ND_AUTOFLICKER_OFFSET_30;
+               else if(Video_TargetFps==15)
+                       frameRate= OV56702ND_AUTOFLICKER_OFFSET_15;
+               else
+                       frameRate=Video_TargetFps*10;
+       
+               MIN_FrameLength = (OV56702ND.videoPclk*10000)/(OV56702ND_VIDEO_PERIOD_PIXEL_NUMS + OV56702ND.DummyPixels)/frameRate*10;
+       }
+       else
+               MIN_FrameLength = (OV56702ND.videoPclk*10000) /(OV56702ND_VIDEO_PERIOD_PIXEL_NUMS + OV56702ND.DummyPixels)/Video_TargetFps;
+
+     return MIN_FrameLength;
+
+}
+
+
+
+UINT32 OV56702NDSetVideoMode(UINT16 u2FrameRate)
+{
+
+    kal_uint32 MIN_Frame_length =0,frameRate=0,extralines=0;
+    OV56702NDDB("[OV56702NDSetVideoMode] frame rate = %d\n", u2FrameRate);
+
+       spin_lock(&ov56702ndmipiraw_drv_lock);
+       OV56702ND_VIDEO_MODE_TARGET_FPS=u2FrameRate;
+       spin_unlock(&ov56702ndmipiraw_drv_lock);
+
+       if(u2FrameRate==0)
+       {
+               OV56702NDDB("Disable Video Mode or dynimac fps\n");
+               return KAL_TRUE;
+       }
+       if(u2FrameRate >30 || u2FrameRate <5)
+           OV56702NDDB("abmornal frame rate seting,pay attention~\n");
+
+    if(OV56702ND.sensorMode == SENSOR_MODE_VIDEO)//video ScenarioId recording
+    {
+
+        MIN_Frame_length = OV56702ND_SET_FrameLength_ByVideoMode(u2FrameRate);
+
+               if((MIN_Frame_length <=OV56702ND_VIDEO_PERIOD_LINE_NUMS))
+               {
+                       MIN_Frame_length = OV56702ND_VIDEO_PERIOD_LINE_NUMS;
+                       OV56702NDDB("[OV56702NDSetVideoMode]current fps = %d\n", (OV56702ND.videoPclk*10000)  /(OV56702ND_VIDEO_PERIOD_PIXEL_NUMS)/OV56702ND_VIDEO_PERIOD_LINE_NUMS);
+               }
+               OV56702NDDB("[OV56702NDSetVideoMode]current fps (10 base)= %d\n", (OV56702ND.videoPclk*10000)*10/(OV56702ND_VIDEO_PERIOD_PIXEL_NUMS + OV56702ND.DummyPixels)/MIN_Frame_length);
+               extralines = MIN_Frame_length - OV56702ND_VIDEO_PERIOD_LINE_NUMS;
+               
+               spin_lock(&ov56702ndmipiraw_drv_lock);
+               OV56702ND.DummyPixels = 0;//define dummy pixels and lines
+               OV56702ND.DummyLines = extralines ;
+               spin_unlock(&ov56702ndmipiraw_drv_lock);
+               
+               OV56702ND_SetDummy(OV56702ND.DummyPixels,extralines);
+    }
+       
+       OV56702NDDB("[OV56702NDSetVideoMode]MIN_Frame_length=%d,OV56702ND.DummyLines=%d\n",MIN_Frame_length,OV56702ND.DummyLines);
+
+    return KAL_TRUE;
+}
+
+
+UINT32 OV56702NDSetAutoFlickerMode(kal_bool bEnable, UINT16 u2FrameRate)
+{
+
+       if(bEnable) {   
+               spin_lock(&ov56702ndmipiraw_drv_lock);
+               OV56702ND.OV56702NDAutoFlickerMode = KAL_TRUE;
+               spin_unlock(&ov56702ndmipiraw_drv_lock);
+        OV56702NDDB("OV56702ND Enable Auto flicker\n");
+    } else {
+       spin_lock(&ov56702ndmipiraw_drv_lock);
+        OV56702ND.OV56702NDAutoFlickerMode = KAL_FALSE;
+               spin_unlock(&ov56702ndmipiraw_drv_lock);
+        OV56702NDDB("OV56702ND Disable Auto flicker\n");
+    }
+
+    return ERROR_NONE;
+}
+
+
+UINT32 OV56702NDSetTestPatternMode(kal_bool bEnable)
+{
+    OV56702NDDB("[OV56702NDSetTestPatternMode] Test pattern enable:%d\n", bEnable);
+    if(bEnable == KAL_TRUE)
+    {
+        OV56702ND_During_testpattern = KAL_TRUE;
+
+               //OV56702ND_write_cmos_sensor(0x5000,0x16);// ; LENC off, MWB on, BPC on, WPC on
+               
+               OV56702ND_write_cmos_sensor(0x4303,0x08);
+    }
+       else
+       {
+        OV56702ND_During_testpattern = KAL_FALSE;
+               //OV56702ND_write_cmos_sensor(0x5000,0x96);// ; LENC on, MWB on, BPC on, WPC on
+               OV56702ND_write_cmos_sensor(0x4303,0x00);
+       }
+
+    return ERROR_NONE;
+}
+
+
+/*************************************************************************
+*
+* DESCRIPTION:
+* INTERFACE FUNCTION, FOR USER TO SET MAX  FRAMERATE;
+* 
+*************************************************************************/
+UINT32 OV56702NDMIPISetMaxFramerateByScenario(MSDK_SCENARIO_ID_ENUM scenarioId, MUINT32 frameRate) {
+       kal_uint32 pclk;
+       kal_int16 dummyLine;
+       kal_uint16 lineLength,frameHeight;
+               
+       OV56702NDDB("OV56702NDMIPISetMaxFramerateByScenario: scenarioId = %d, frame rate = %d\n",scenarioId,frameRate);
+       switch (scenarioId) {
+               case MSDK_SCENARIO_ID_CAMERA_PREVIEW:
+                       pclk = OV56702ND_PREVIEW_PCLK;
+                       lineLength = OV56702ND_PV_PERIOD_PIXEL_NUMS;
+                       frameHeight = (10 * pclk)/frameRate/lineLength;
+                       dummyLine = frameHeight - OV56702ND_PV_PERIOD_LINE_NUMS;
+                       if(dummyLine<0)
+                               dummyLine = 0;
+                       spin_lock(&ov56702ndmipiraw_drv_lock);
+                       OV56702ND.sensorMode = SENSOR_MODE_PREVIEW;
+                       spin_unlock(&ov56702ndmipiraw_drv_lock);
+                       OV56702ND_SetDummy(0, dummyLine);                       
+                       break;                  
+               case MSDK_SCENARIO_ID_VIDEO_PREVIEW:
+                       pclk = OV56702ND_VIDEO_PCLK;
+                       lineLength = OV56702ND_VIDEO_PERIOD_PIXEL_NUMS;
+                       frameHeight = (10 * pclk)/frameRate/lineLength;
+                       dummyLine = frameHeight - OV56702ND_VIDEO_PERIOD_LINE_NUMS;
+                       if(dummyLine<0)
+                               dummyLine = 0;
+                       spin_lock(&ov56702ndmipiraw_drv_lock);
+                       OV56702ND.sensorMode = SENSOR_MODE_VIDEO;
+                       spin_unlock(&ov56702ndmipiraw_drv_lock);
+                       OV56702ND_SetDummy(0, dummyLine);                       
+                       break;                  
+                        break;
+               case MSDK_SCENARIO_ID_CAMERA_CAPTURE_JPEG:
+               case MSDK_SCENARIO_ID_CAMERA_ZSD:                       
+                       pclk = OV56702ND_CAPTURE_PCLK;
+                       lineLength = OV56702ND_FULL_PERIOD_PIXEL_NUMS;
+                       frameHeight = (10 * pclk)/frameRate/lineLength;
+                       dummyLine = frameHeight - OV56702ND_FULL_PERIOD_LINE_NUMS;
+                       if(dummyLine<0)
+                               dummyLine = 0;
+                       spin_lock(&ov56702ndmipiraw_drv_lock);
+                       OV56702ND.sensorMode = SENSOR_MODE_CAPTURE;
+                       spin_unlock(&ov56702ndmipiraw_drv_lock);
+                       OV56702ND_SetDummy(0, dummyLine);                       
+                       break;          
+        case MSDK_SCENARIO_ID_CAMERA_3D_PREVIEW:
+            break;
+        case MSDK_SCENARIO_ID_CAMERA_3D_VIDEO:
+                       break;
+        case MSDK_SCENARIO_ID_CAMERA_3D_CAPTURE:   
+                       break;          
+               default:
+                       break;
+       }       
+       return ERROR_NONE;
+}
+
+
+UINT32 OV56702NDMIPIGetDefaultFramerateByScenario(MSDK_SCENARIO_ID_ENUM scenarioId, MUINT32 *pframeRate) 
+{
+
+       switch (scenarioId) {
+               case MSDK_SCENARIO_ID_CAMERA_PREVIEW:
+               case MSDK_SCENARIO_ID_VIDEO_PREVIEW:
+                        *pframeRate = OV56702ND_MAX_FPS_PREVIEW;
+                        break;
+               case MSDK_SCENARIO_ID_CAMERA_CAPTURE_JPEG:
+               case MSDK_SCENARIO_ID_CAMERA_ZSD:
+                        *pframeRate = OV56702ND_MAX_FPS_CAPTURE;
+                       break;          
+        case MSDK_SCENARIO_ID_CAMERA_3D_PREVIEW: //added
+        case MSDK_SCENARIO_ID_CAMERA_3D_VIDEO:
+        case MSDK_SCENARIO_ID_CAMERA_3D_CAPTURE: //added   
+                        *pframeRate = OV56702ND_MAX_FPS_CAPTURE;
+                       break;          
+               default:
+                       break;
+       }
+
+       return ERROR_NONE;
+}
+
+/* Sensor output window information */
+
+/* SZ TCT xuejian.zhong add for CTS test*/
+
+static void OV56702NDGetAFMaxNumFocusAreas(UINT32 *pFeatureReturnPara32)
+{      
+    *pFeatureReturnPara32 = 0;    
+   // SENSORDB("OV56702NDGetAFMaxNumFocusAreas *pFeatureReturnPara32 = %d¥n",  *pFeatureReturnPara32);
+}
+
+static void OV56702NDGetAEMaxNumMeteringAreas(UINT32 *pFeatureReturnPara32)
+{     
+    *pFeatureReturnPara32 = 0;    
+  //  SENSORDB("OV56702NDGetAEMaxNumMeteringAreas *pFeatureReturnPara32 = %d¥n",  *pFeatureReturnPara32);     
+}
+
+static void OV56702NDGetExifInfo(UINT32 exifAddr)
+{
+    SENSOR_EXIF_INFO_STRUCT* pExifInfo = (SENSOR_EXIF_INFO_STRUCT*)exifAddr;
+    pExifInfo->FNumber = 28;
+    pExifInfo->AEISOSpeed = AE_ISO_100;
+    pExifInfo->AWBMode = AWB_MODE_AUTO;
+    pExifInfo->CapExposureTime = 0;
+    pExifInfo->FlashLightTimeus = 0;
+    pExifInfo->RealISOValue = AE_ISO_100;
+}
+
+/* SZ TCT xuejian.zhong  end */
+
+
+UINT32 OV56702NDFeatureControl(MSDK_SENSOR_FEATURE_ENUM FeatureId,
+                                                                UINT8 *pFeaturePara,UINT32 *pFeatureParaLen)
+{
+    UINT16 *pFeatureReturnPara16=(UINT16 *) pFeaturePara;
+    UINT16 *pFeatureData16=(UINT16 *) pFeaturePara;
+    UINT32 *pFeatureReturnPara32=(UINT32 *) pFeaturePara;
+    UINT32 *pFeatureData32=(UINT32 *) pFeaturePara;
+    UINT32 SensorRegNumber;
+    UINT32 i;
+    PNVRAM_SENSOR_DATA_STRUCT pSensorDefaultData=(PNVRAM_SENSOR_DATA_STRUCT) pFeaturePara;
+    MSDK_SENSOR_CONFIG_STRUCT *pSensorConfigData=(MSDK_SENSOR_CONFIG_STRUCT *) pFeaturePara;
+    MSDK_SENSOR_REG_INFO_STRUCT *pSensorRegData=(MSDK_SENSOR_REG_INFO_STRUCT *) pFeaturePara;
+    MSDK_SENSOR_GROUP_INFO_STRUCT *pSensorGroupInfo=(MSDK_SENSOR_GROUP_INFO_STRUCT *) pFeaturePara;
+    MSDK_SENSOR_ITEM_INFO_STRUCT *pSensorItemInfo=(MSDK_SENSOR_ITEM_INFO_STRUCT *) pFeaturePara;
+    MSDK_SENSOR_ENG_INFO_STRUCT        *pSensorEngInfo=(MSDK_SENSOR_ENG_INFO_STRUCT *) pFeaturePara;
+
+    switch (FeatureId)
+    {
+        case SENSOR_FEATURE_GET_RESOLUTION:
+            *pFeatureReturnPara16++= OV56702ND_IMAGE_SENSOR_FULL_WIDTH;
+            *pFeatureReturnPara16= OV56702ND_IMAGE_SENSOR_FULL_HEIGHT;
+            *pFeatureParaLen=4;
+            break;
+        case SENSOR_FEATURE_GET_PERIOD:
+                               *pFeatureReturnPara16++= OV56702ND_FeatureControl_PERIOD_PixelNum;
+                               *pFeatureReturnPara16= OV56702ND_FeatureControl_PERIOD_LineNum;
+                               *pFeatureParaLen=4;
+                               break;
+        case SENSOR_FEATURE_GET_PIXEL_CLOCK_FREQ:
+                       switch(OV56702NDCurrentScenarioId)
+                       {
+                               case MSDK_SCENARIO_ID_CAMERA_PREVIEW:
+                                       *pFeatureReturnPara32 = OV56702ND_PREVIEW_PCLK;
+                                       *pFeatureParaLen=4;
+                                       break;
+                               case MSDK_SCENARIO_ID_VIDEO_PREVIEW:
+                                       *pFeatureReturnPara32 = OV56702ND_VIDEO_PCLK;
+                                       *pFeatureParaLen=4;
+                                       break;
+                               case MSDK_SCENARIO_ID_CAMERA_CAPTURE_JPEG:
+                               case MSDK_SCENARIO_ID_CAMERA_ZSD:
+                                       *pFeatureReturnPara32 = OV56702ND_CAPTURE_PCLK;
+                                       *pFeatureParaLen=4;
+                                       break;
+                               default:
+                                       *pFeatureReturnPara32 = OV56702ND_PREVIEW_PCLK;
+                                       *pFeatureParaLen=4;
+                                       break;
+                       }
+                   break;
+
+        case SENSOR_FEATURE_SET_ESHUTTER:
+            OV56702ND_SetShutter(*pFeatureData16);
+            break;
+        case SENSOR_FEATURE_SET_NIGHTMODE:
+            OV56702ND_NightMode((BOOL) *pFeatureData16);
+            break;
+        case SENSOR_FEATURE_SET_GAIN:  
+           OV56702ND_SetGain((UINT16) *pFeatureData16);
+            break;
+        case SENSOR_FEATURE_SET_FLASHLIGHT:
+            break;
+        case SENSOR_FEATURE_SET_ISP_MASTER_CLOCK_FREQ:
+            //OV56702ND_isp_master_clock=*pFeatureData32;
+            break;
+        case SENSOR_FEATURE_SET_REGISTER:
+            OV56702ND_write_cmos_sensor(pSensorRegData->RegAddr, pSensorRegData->RegData);
+            break;
+        case SENSOR_FEATURE_GET_REGISTER:
+            pSensorRegData->RegData = OV56702ND_read_cmos_sensor(pSensorRegData->RegAddr);
+            break;
+        case SENSOR_FEATURE_SET_CCT_REGISTER:
+            SensorRegNumber=FACTORY_END_ADDR;
+            for (i=0;i<SensorRegNumber;i++)
+            {
+               spin_lock(&ov56702ndmipiraw_drv_lock);
+                OV56702NDSensorCCT[i].Addr=*pFeatureData32++;
+                OV56702NDSensorCCT[i].Para=*pFeatureData32++;
+                               spin_unlock(&ov56702ndmipiraw_drv_lock);
+            }
+            break;
+        case SENSOR_FEATURE_GET_CCT_REGISTER:
+            SensorRegNumber=FACTORY_END_ADDR;
+            if (*pFeatureParaLen<(SensorRegNumber*sizeof(SENSOR_REG_STRUCT)+4))
+                return FALSE;
+            *pFeatureData32++=SensorRegNumber;
+            for (i=0;i<SensorRegNumber;i++)
+            {
+                *pFeatureData32++=OV56702NDSensorCCT[i].Addr;
+                *pFeatureData32++=OV56702NDSensorCCT[i].Para;
+            }
+            break;
+        case SENSOR_FEATURE_SET_ENG_REGISTER:
+            SensorRegNumber=ENGINEER_END;
+            for (i=0;i<SensorRegNumber;i++)
+            {
+               spin_lock(&ov56702ndmipiraw_drv_lock);
+                OV56702NDSensorReg[i].Addr=*pFeatureData32++;
+                OV56702NDSensorReg[i].Para=*pFeatureData32++;
+                               spin_unlock(&ov56702ndmipiraw_drv_lock);
+            }
+            break;
+        case SENSOR_FEATURE_GET_ENG_REGISTER:
+            SensorRegNumber=ENGINEER_END;
+            if (*pFeatureParaLen<(SensorRegNumber*sizeof(SENSOR_REG_STRUCT)+4))
+                return FALSE;
+            *pFeatureData32++=SensorRegNumber;
+            for (i=0;i<SensorRegNumber;i++)
+            {
+                *pFeatureData32++=OV56702NDSensorReg[i].Addr;
+                *pFeatureData32++=OV56702NDSensorReg[i].Para;
+            }
+            break;
+        case SENSOR_FEATURE_GET_REGISTER_DEFAULT:
+            if (*pFeatureParaLen>=sizeof(NVRAM_SENSOR_DATA_STRUCT))
+            {
+                pSensorDefaultData->Version=NVRAM_CAMERA_SENSOR_FILE_VERSION;
+                pSensorDefaultData->SensorId=OV56702NDMIPI_SENSOR_ID;
+                memcpy(pSensorDefaultData->SensorEngReg, OV56702NDSensorReg, sizeof(SENSOR_REG_STRUCT)*ENGINEER_END);
+                memcpy(pSensorDefaultData->SensorCCTReg, OV56702NDSensorCCT, sizeof(SENSOR_REG_STRUCT)*FACTORY_END_ADDR);
+            }
+            else
+                return FALSE;
+            *pFeatureParaLen=sizeof(NVRAM_SENSOR_DATA_STRUCT);
+            break;
+        case SENSOR_FEATURE_GET_CONFIG_PARA:
+            memcpy(pSensorConfigData, &OV56702NDSensorConfigData, sizeof(MSDK_SENSOR_CONFIG_STRUCT));
+            *pFeatureParaLen=sizeof(MSDK_SENSOR_CONFIG_STRUCT);
+            break;
+        case SENSOR_FEATURE_CAMERA_PARA_TO_SENSOR:
+            OV56702ND_camera_para_to_sensor();
+            break;
+
+        case SENSOR_FEATURE_SENSOR_TO_CAMERA_PARA:
+            OV56702ND_sensor_to_camera_para();
+            break;
+        case SENSOR_FEATURE_GET_GROUP_COUNT:
+            *pFeatureReturnPara32++=OV56702ND_get_sensor_group_count();
+            *pFeatureParaLen=4;
+            break;
+        case SENSOR_FEATURE_GET_GROUP_INFO:
+            OV56702ND_get_sensor_group_info(pSensorGroupInfo->GroupIdx, pSensorGroupInfo->GroupNamePtr, &pSensorGroupInfo->ItemCount);
+            *pFeatureParaLen=sizeof(MSDK_SENSOR_GROUP_INFO_STRUCT);
+            break;
+        case SENSOR_FEATURE_GET_ITEM_INFO:
+            OV56702ND_get_sensor_item_info(pSensorItemInfo->GroupIdx,pSensorItemInfo->ItemIdx, pSensorItemInfo);
+            *pFeatureParaLen=sizeof(MSDK_SENSOR_ITEM_INFO_STRUCT);
+            break;
+
+        case SENSOR_FEATURE_SET_ITEM_INFO:
+            OV56702ND_set_sensor_item_info(pSensorItemInfo->GroupIdx, pSensorItemInfo->ItemIdx, pSensorItemInfo->ItemValue);
+            *pFeatureParaLen=sizeof(MSDK_SENSOR_ITEM_INFO_STRUCT);
+            break;
+
+        case SENSOR_FEATURE_GET_ENG_INFO:
+            pSensorEngInfo->SensorId = 129;
+            pSensorEngInfo->SensorType = CMOS_SENSOR;
+            pSensorEngInfo->SensorOutputDataFormat=SENSOR_OUTPUT_FORMAT_RAW_B;
+            *pFeatureParaLen=sizeof(MSDK_SENSOR_ENG_INFO_STRUCT);
+            break;
+        case SENSOR_FEATURE_GET_LENS_DRIVER_ID:
+            // get the lens driver ID from EEPROM or just return LENS_DRIVER_ID_DO_NOT_CARE
+            // if EEPROM does not exist in camera module.
+            *pFeatureReturnPara32=LENS_DRIVER_ID_DO_NOT_CARE;
+            *pFeatureParaLen=4;
+            break;
+
+        case SENSOR_FEATURE_INITIALIZE_AF:
+            break;
+        case SENSOR_FEATURE_CONSTANT_AF:
+            break;
+        case SENSOR_FEATURE_MOVE_FOCUS_LENS:
+            break;
+        case SENSOR_FEATURE_SET_VIDEO_MODE:
+            OV56702NDSetVideoMode(*pFeatureData16);
+            break;
+        case SENSOR_FEATURE_CHECK_SENSOR_ID:
+            OV56702NDGetSensorID(pFeatureReturnPara32);
+            break;
+        case SENSOR_FEATURE_SET_AUTO_FLICKER_MODE:
+            OV56702NDSetAutoFlickerMode((BOOL)*pFeatureData16, *(pFeatureData16+1));
+               break;
+               case SENSOR_FEATURE_SET_MAX_FRAME_RATE_BY_SCENARIO:
+                       OV56702NDMIPISetMaxFramerateByScenario((MSDK_SCENARIO_ID_ENUM)*pFeatureData32, *(pFeatureData32+1));
+                       break;
+               case SENSOR_FEATURE_GET_DEFAULT_FRAME_RATE_BY_SCENARIO:
+                       OV56702NDMIPIGetDefaultFramerateByScenario((MSDK_SCENARIO_ID_ENUM)*pFeatureData32, (MUINT32 *)(*(pFeatureData32+1)));
+                       break;
+               case SENSOR_FEATURE_SET_TEST_PATTERN:
+                       OV56702NDSetTestPatternMode((BOOL)*pFeatureData16);
+                       break;
+               case SENSOR_FEATURE_GET_TEST_PATTERN_CHECKSUM_VALUE://for factory mode auto testing                     
+                       *pFeatureReturnPara32=OV56702ND_TEST_PATTERN_CHECKSUM;            
+                       *pFeatureParaLen=4;                                                     
+                    break;
+                       /*SZ TCT xuejian.zhong add for CTS test */
+               case SENSOR_FEATURE_GET_AF_MAX_NUM_FOCUS_AREAS:
+                       OV56702NDGetAFMaxNumFocusAreas(pFeatureData32);
+                       *pFeatureParaLen=4;                                                      
+                       break;
+
+               case SENSOR_FEATURE_GET_AE_MAX_NUM_METERING_AREAS:
+                       OV56702NDGetAEMaxNumMeteringAreas(pFeatureData32);
+                       *pFeatureParaLen=4;                                                      
+                       break;
+               case SENSOR_FEATURE_GET_EXIF_INFO:
+               //      SENSORDB("SENSOR_FEATURE_GET_EXIF_INFO¥n");
+               //      SENSORDB("EXIF addr = 0x%x¥n",*pFeatureData32);
+
+                       OV56702NDGetExifInfo(*pFeatureData32);
+                       break;
+                       /* xuejian.zhong add end */
+        default:
+            break;
+    }
+    return ERROR_NONE;
+}      
+
+
+SENSOR_FUNCTION_STRUCT SensorFuncOV56702ND=
+{
+    OV56702NDOpen,
+    OV56702NDGetInfo,
+    OV56702NDGetResolution,
+    OV56702NDFeatureControl,
+    OV56702NDControl,
+    OV56702NDClose
+};
+
+UINT32 OV56702ND_MIPI_RAW_SensorInit(PSENSOR_FUNCTION_STRUCT *pfFunc)
+{
+    if (pfFunc!=NULL)
+        *pfFunc=&SensorFuncOV56702ND;
+
+    return ERROR_NONE;
+}  
diff --git a/drivers/misc/mediatek/imgsensor/src/mt8127/ov56702nd_mipi_raw/ov56702ndmipi_Sensor.h b/drivers/misc/mediatek/imgsensor/src/mt8127/ov56702nd_mipi_raw/ov56702ndmipi_Sensor.h
new file mode 100644 (file)
index 0000000..30caf44
--- /dev/null
@@ -0,0 +1,147 @@
+/*****************************************************************************
+ *
+ * Filename:
+ * ---------
+ *      OV56702NDmipi_Sensor.h
+ *
+ * Project:
+ * --------
+ *      ALPS
+ *
+ * Description:
+ * ------------
+ *      CMOS sensor header file
+ *
+ ****************************************************************************/
+#ifndef _OV56702NDMIPI_SENSOR_H
+#define _OV56702NDMIPI_SENSOR_H
+
+typedef enum group_enum {
+    PRE_GAIN=0,
+    CMMCLK_CURRENT,
+    FRAME_RATE_LIMITATION,
+    REGISTER_EDITOR,
+    GROUP_TOTAL_NUMS
+} FACTORY_GROUP_ENUM;
+
+
+#define ENGINEER_START_ADDR 10
+#define FACTORY_START_ADDR 0
+
+typedef enum engineer_index
+{
+    CMMCLK_CURRENT_INDEX=ENGINEER_START_ADDR,
+    ENGINEER_END
+} FACTORY_ENGINEER_INDEX;
+
+typedef enum register_index
+{
+       SENSOR_BASEGAIN=FACTORY_START_ADDR,
+       PRE_GAIN_R_INDEX,
+       PRE_GAIN_Gr_INDEX,
+       PRE_GAIN_Gb_INDEX,
+       PRE_GAIN_B_INDEX,
+       FACTORY_END_ADDR
+} FACTORY_REGISTER_INDEX;
+
+typedef struct
+{
+    SENSOR_REG_STRUCT  Reg[ENGINEER_END];
+    SENSOR_REG_STRUCT  CCT[FACTORY_END_ADDR];
+} SENSOR_DATA_STRUCT, *PSENSOR_DATA_STRUCT;
+
+typedef enum {
+    SENSOR_MODE_INIT = 0,
+    SENSOR_MODE_PREVIEW,
+    SENSOR_MODE_VIDEO,
+    SENSOR_MODE_CAPTURE
+} OV56702ND_SENSOR_MODE;
+
+
+typedef struct
+{
+       kal_uint32 DummyPixels;
+       kal_uint32 DummyLines;
+       
+       kal_uint32 pvShutter;
+       kal_uint32 pvGain;
+       
+       kal_uint32 pvPclk;  
+       kal_uint32 videoPclk;
+       kal_uint32 capPclk;
+       
+       kal_uint32 shutter;
+
+       kal_uint16 sensorGlobalGain;
+       kal_uint16 ispBaseGain;
+       kal_uint16 realGain;
+
+       kal_int16 imgMirror;
+
+       OV56702ND_SENSOR_MODE sensorMode;
+
+       kal_bool OV56702NDAutoFlickerMode;
+       kal_bool OV56702NDVideoMode;
+       
+}OV56702ND_PARA_STRUCT,*POV56702ND_PARA_STRUCT;
+
+
+    #define OV56702ND_SHUTTER_MARGIN                   (4)
+       #define OV56702ND_GAIN_BASE                             (128)
+       #define OV56702ND_AUTOFLICKER_OFFSET_30         (296)
+       #define OV56702ND_AUTOFLICKER_OFFSET_25         (250)
+       #define OV56702ND_AUTOFLICKER_OFFSET_15         (146)
+       #define OV56702ND_PREVIEW_PCLK                  (102850000)
+       #define OV56702ND_VIDEO_PCLK                            (OV56702ND_PREVIEW_PCLK)
+       #define OV56702ND_CAPTURE_PCLK                  (102850000)
+       
+       #define OV56702ND_MAX_FPS_PREVIEW                       (300)
+       #define OV56702ND_MAX_FPS_VIDEO                 (300)
+       #define OV56702ND_MAX_FPS_CAPTURE                       (250)
+       //#define OV56702ND_MAX_FPS_N3D                         (300)
+
+
+       //grab window
+       #define OV56702ND_IMAGE_SENSOR_PV_WIDTH                                 (1296)
+       #define OV56702ND_IMAGE_SENSOR_PV_HEIGHT                                        (972) //(960)
+       #define OV56702ND_IMAGE_SENSOR_VIDEO_WIDTH                              (OV56702ND_IMAGE_SENSOR_PV_WIDTH)
+       #define OV56702ND_IMAGE_SENSOR_VIDEO_HEIGHT                             (OV56702ND_IMAGE_SENSOR_PV_HEIGHT)
+       #define OV56702ND_IMAGE_SENSOR_FULL_WIDTH                                       (2592)  
+       #define OV56702ND_IMAGE_SENSOR_FULL_HEIGHT                              (1944)
+
+       #define OV56702ND_FULL_X_START                                                          (0)
+       #define OV56702ND_FULL_Y_START                                                          (0)
+       #define OV56702ND_PV_X_START                                                            (0)
+       #define OV56702ND_PV_Y_START                                                            (0)
+       #define OV56702ND_VIDEO_X_START                                                         (0)
+       #define OV56702ND_VIDEO_Y_START                                                         (0)
+
+       #define OV56702ND_MAX_ANALOG_GAIN                                       (8)
+       #define OV56702ND_MIN_ANALOG_GAIN                                       (1)
+
+
+       /* SENSOR PIXEL/LINE NUMBERS IN ONE PERIOD */
+       #define OV56702ND_PV_PERIOD_PIXEL_NUMS                          0x068C  //1676*2=>3352
+       #define OV56702ND_PV_PERIOD_LINE_NUMS                                   0x07FD  //2045
+
+       #define OV56702ND_VIDEO_PERIOD_PIXEL_NUMS                               OV56702ND_PV_PERIOD_PIXEL_NUMS
+       #define OV56702ND_VIDEO_PERIOD_LINE_NUMS                                OV56702ND_PV_PERIOD_LINE_NUMS
+
+       #define OV56702ND_FULL_PERIOD_PIXEL_NUMS                                        0x07DC  //2012*2   25fps
+       #define OV56702ND_FULL_PERIOD_LINE_NUMS                                 0x07FD  //2045
+       
+       #define OV56702NDMIPI_WRITE_ID  (0x6c)
+       #define OV56702NDMIPI_READ_ID   (0x6d)
+
+       #define OV56702NDMIPI_SENSOR_ID            OV5670_SENSOR_ID
+
+
+       UINT32 OV56702NDMIPIOpen(void);
+       UINT32 OV56702NDMIPIGetResolution(MSDK_SENSOR_RESOLUTION_INFO_STRUCT *pSensorResolution);
+       UINT32 OV56702NDMIPIGetInfo(MSDK_SCENARIO_ID_ENUM ScenarioId, MSDK_SENSOR_INFO_STRUCT *pSensorInfo, MSDK_SENSOR_CONFIG_STRUCT *pSensorConfigData);
+       UINT32 OV56702NDMIPIControl(MSDK_SCENARIO_ID_ENUM ScenarioId, MSDK_SENSOR_EXPOSURE_WINDOW_STRUCT *pImageWindow, MSDK_SENSOR_CONFIG_STRUCT *pSensorConfigData);
+       UINT32 OV56702NDMIPIFeatureControl(MSDK_SENSOR_FEATURE_ENUM FeatureId, UINT8 *pFeaturePara,UINT32 *pFeatureParaLen);
+       UINT32 OV56702NDMIPIClose(void);
+
+#endif 
+
diff --git a/drivers/misc/mediatek/imgsensor/src/mt8127/ov56702nd_mipi_raw/ov56702ndmipiraw_CameraCustomized.h b/drivers/misc/mediatek/imgsensor/src/mt8127/ov56702nd_mipi_raw/ov56702ndmipiraw_CameraCustomized.h
new file mode 100644 (file)
index 0000000..94af62c
--- /dev/null
@@ -0,0 +1,65 @@
+/*******************************************************************************************/
+
+
+/*******************************************************************************************/
+
+
+#ifndef __CAMERA_CUSTOMIZED_H
+#define __CAMERA_CUSTOMIZED_H
+
+// the angle between handset and sensor placement in clockwise, should be one of 0, 90, 270
+#define MAIN_SENSOR_ORIENTATION_ANGLE    90
+#define SUB_SENSOR_ORIENTATION_ANGLE      0                  // do not care if the sub sensor does not exist
+
+
+// First, we think you hold the cell phone vertical.
+// Second, we suppose the direction of upward is 0
+// Third, it is 90, 180, 270 in clockwise
+// here we define the main sensor and sub sensor angles to deal with the jpeg orientation
+#define MAIN_SENSOR_TO_PHONE_ANGLE        90
+#define SUB_SENSOR_TO_PHONE_ANGLE           0
+
+
+#define CAM_SIZE_QVGA_WIDTH         320
+#define CAM_SIZE_QVGA_HEIGHT        240
+#define CAM_SIZE_VGA_WIDTH            640
+#define CAM_SIZE_VGA_HEIGHT           480
+#define CAM_SIZE_05M_WIDTH            800
+#define CAM_SIZE_05M_HEIGHT           600
+#define CAM_SIZE_1M_WIDTH              1280
+#define CAM_SIZE_1M_HEIGHT             960
+#define CAM_SIZE_2M_WIDTH              1600
+#define CAM_SIZE_2M_HEIGHT             1200
+#define CAM_SIZE_3M_WIDTH              2048
+#define CAM_SIZE_3M_HEIGHT             1536
+#define CAM_SIZE_5M_WIDTH              2592
+#define CAM_SIZE_5M_HEIGHT             1944
+
+// for main sensor
+#define MAIN_NUM_OF_PREVIEW_RESOLUTION 3
+#define MAIN_NUM_OF_VIDEO_RESOLUTION 4
+#define MAIN_NUM_OF_STILL_RESOLUTION 7
+#define MAIN_VIDEO_RESOLUTION_PROFILE           {{176,144},{320,240},{640,480},{720,480}}
+#define MAIN_PREVIEW_RESOLUTION_PROFILE      {{232,174},{320,240},{240,320}}
+#define MAIN_STILL_RESOLUTION_PROFILE            {{CAM_SIZE_QVGA_WIDTH,CAM_SIZE_QVGA_HEIGHT}, \
+                                                                         {CAM_SIZE_VGA_WIDTH,CAM_SIZE_VGA_HEIGHT}, \
+                                                                         {CAM_SIZE_05M_WIDTH,CAM_SIZE_05M_HEIGHT}, \
+                                                                         {CAM_SIZE_1M_WIDTH,CAM_SIZE_1M_HEIGHT}, \
+                                                                         {CAM_SIZE_2M_WIDTH,CAM_SIZE_2M_HEIGHT}, \
+                                                                         {CAM_SIZE_3M_WIDTH,CAM_SIZE_3M_HEIGHT}, \
+                                                                         {CAM_SIZE_5M_WIDTH,CAM_SIZE_5M_HEIGHT}}
+
+// if sub sensor does not exist, set all the parameters as 0
+#define SUB_NUM_OF_PREVIEW_RESOLUTION           0
+#define SUB_NUM_OF_VIDEO_RESOLUTION                0
+#define SUB_NUM_OF_STILL_RESOLUTION                 0
+#define SUB_VIDEO_RESOLUTION_PROFILE                {{0,0}}
+#define SUB_PREVIEW_RESOLUTION_PROFILE           {{0,0}}
+#define SUB_STILL_RESOLUTION_PROFILE                 {{0,0}}
+
+//#define NUM_OF_PREVIEW_RESOLUTION    max(MAIN_NUM_OF_PREVIEW_RESOLUTION,SUB_NUM_OF_PREVIEW_RESOLUTION)
+//#define NUM_OF_VIDEO_RESOLUTION      max(MAIN_NUM_OF_VIDEO_RESOLUTION,SUB_NUM_OF_VIDEO_RESOLUTION)
+//#define NUM_OF_STILL_RESOLUTION      max(MAIN_NUM_OF_STILL_RESOLUTION,SUB_NUM_OF_STILL_RESOLUTION)
+
+#define NUM_OF_VIDEO_STREAM_BUFF            8           // Maximun is 8
+#endif
diff --git a/drivers/misc/mediatek/imgsensor/src/mt8127/ov56702nd_mipi_raw/ov56702ndmipiraw_Camera_Sensor_para.h b/drivers/misc/mediatek/imgsensor/src/mt8127/ov56702nd_mipi_raw/ov56702ndmipiraw_Camera_Sensor_para.h
new file mode 100644 (file)
index 0000000..41a406f
--- /dev/null
@@ -0,0 +1,60 @@
+/*******************************************************************************************/
+
+
+/*******************************************************************************************/
+
+/* SENSOR FULL SIZE */
+#ifndef __CAMERA_SENSOR_PARA_H
+#define __CAMERA_SENSOR_PARA_H
+
+#define CAMERA_SENSOR_REG_DEFAULT_VALUE  \
+    /* ARRAY: SENSOR.reg[11] */\
+    {\
+        /* STRUCT: SENSOR.reg[0] */\
+        {\
+            /* SENSOR.reg[0].addr */ 0x00000304, /* SENSOR.reg[0].para */ 0x00000000\
+        },\
+        /* STRUCT: SENSOR.reg[1] */\
+        {\
+            /* SENSOR.reg[1].addr */ 0x00000305, /* SENSOR.reg[1].para */ 0x0000000D\
+        },\
+        /* STRUCT: SENSOR.reg[2] */\
+        {\
+            /* SENSOR.reg[2].addr */ 0x00000306, /* SENSOR.reg[2].para */ 0x00000000\
+        },\
+        /* STRUCT: SENSOR.reg[3] */\
+        {\
+            /* SENSOR.reg[3].addr */ 0x00000307, /* SENSOR.reg[3].para */ 0x000000C0\
+        },\
+        /* STRUCT: SENSOR.reg[4] */\
+        {\
+            /* SENSOR.reg[4].addr */ 0x00000300, /* SENSOR.reg[4].para */ 0x00000000\
+        },\
+        /* STRUCT: SENSOR.reg[5] */\
+        {\
+            /* SENSOR.reg[5].addr */ 0x00000301, /* SENSOR.reg[5].para */ 0x00000004\
+        },\
+        /* STRUCT: SENSOR.reg[6] */\
+        {\
+            /* SENSOR.reg[6].addr */ 0x0000030A, /* SENSOR.reg[6].para */ 0x00000000\
+        },\
+        /* STRUCT: SENSOR.reg[7] */\
+        {\
+            /* SENSOR.reg[7].addr */ 0x0000030B, /* SENSOR.reg[7].para */ 0x00000002\
+        },\
+        /* STRUCT: SENSOR.reg[8] */\
+        {\
+            /* SENSOR.reg[8].addr */ 0x00000308, /* SENSOR.reg[8].para */ 0x00000000\
+        },\
+        /* STRUCT: SENSOR.reg[9] */\
+        {\
+            /* SENSOR.reg[9].addr */ 0x00000309, /* SENSOR.reg[9].para */ 0x00000008\
+        },\
+        /* STRUCT: SENSOR.reg[10] */\
+        {\
+            /* SENSOR.reg[10].addr */ 0xFFFFFFFF, /* SENSOR.reg[10].para */ 0x00000001\
+        }\
+}
+
+#define CAMERA_SENSOR_CCT_DEFAULT_VALUE {{ 0xFFFFFFFF, 0x08 } ,{ 0x0205, 0x20 } ,{ 0x020e, 0x01 } ,{ 0x0210, 0x01 } ,{ 0x0212, 0x01 }}
+#endif /* __CAMERA_SENSOR_PARA_H */
index 1dd3b5444930cd7775629c979443ab2c00bdb5f7..ea77182bd7ebcd151f2ad1259542e17cbdd613f9 100644 (file)
@@ -26,8 +26,8 @@
 #include <linux/uaccess.h>
 #include <linux/fs.h>
 #include <asm/atomic.h>
-#include <asm/system.h>
 #include <linux/xlog.h>
+#include <asm/system.h>
 
 #include "kd_camera_hw.h"
 #include "kd_imgsensor.h"
 
 #include "ov5670mipi_Sensor.h"
 
-#define PFX "ov5670_camera_sensor"
-//#define LOG_WRN(format, args...) xlog_printk(ANDROID_LOG_WARN ,PFX, "[%S] " format, __FUNCTION__, ##args)
-//#defineLOG_INF(format, args...) xlog_printk(ANDROID_LOG_INFO ,PFX, "[%s] " format, __FUNCTION__, ##args)
-//#define LOG_DBG(format, args...) xlog_printk(ANDROID_LOG_DEBUG ,PFX, "[%S] " format, __FUNCTION__, ##args)
-#define LOG_INF(format, args...)       xlog_printk(ANDROID_LOG_INFO   , PFX, "[%s] " format, __FUNCTION__, ##args)
+#include "ov5670mipiraw_Camera_Sensor_para.h"
+#include "ov5670mipiraw_CameraCustomized.h"
+static DEFINE_SPINLOCK(ov5670mipiraw_drv_lock);
+static int module_id = 0;
 
-static DEFINE_SPINLOCK(imgsensor_drv_lock);
+#define OV5670_DEBUG
+#ifdef OV5670_DEBUG
+       #define OV5670DB(fmt, arg...) xlog_printk(ANDROID_LOG_DEBUG, "[OV5670Raw] ",  fmt, ##arg)
+#else
+       #define OV5670DB(fmt, arg...)
+#endif
 
-   
-static imgsensor_info_struct imgsensor_info = { 
-       .sensor_id = OV5670_SENSOR_ID,          //record sensor id defined in Kd_imgsensor.h
-       
-       .checksum_value = 0x523c51f6,           //checksum value for Camera Auto Test
-       
-       .pre = {
-               .pclk = 102850000,                              //record different mode's pclk
-               .linelength = 1676,                             //record different mode's linelength
-               .framelength = 2045,                    //record different mode's framelength
-               .startx = 1,                                    //record different mode's startx of grabwindow
-               .starty = 0,                                    //record different mode's starty of grabwindow
-               .grabwindow_width = 1280,               //record different mode's width of grabwindow
-               .grabwindow_height = 960,               //record different mode's height of grabwindow
-               /*       following for MIPIDataLowPwr2HighSpeedSettleDelayCount by different scenario   */
-               .mipi_data_lp2hs_settle_dc = 14,//unit , ns
-               /*       following for GetDefaultFramerateByScenario()  */
-               .max_framerate = 300,   
-       },
-       .cap = {
-               .pclk = 102850000,
-               .linelength = 1676,
-               .framelength = 2045,
-               .startx = 1,
-               .starty = 0,
-               .grabwindow_width = 2560,
-               .grabwindow_height = 1920,
-               .mipi_data_lp2hs_settle_dc = 14,//unit , ns
-               .max_framerate = 300,
-       },
-       .normal_video = {
-               .pclk = 102850000,
-               .linelength = 1676,
-               .framelength = 2045,
-               .startx = 1,
-               .starty = 0,
-               .grabwindow_width = 1280,
-               .grabwindow_height = 960,
-               .mipi_data_lp2hs_settle_dc = 14,//unit , ns
-               .max_framerate = 300,
-       },
-       .margin = 4,                    //sensor framelength & shutter margin
-       .min_shutter = 4,               //min shutter
-       .max_frame_length = 0x7fff,//max framelength by sensor register's limitation
-       .ae_shut_delay_frame = 0,       //shutter delay frame for AE cycle, 2 frame with ispGain_delay-shut_delay=2-0=2
-       .ae_sensor_gain_delay_frame = 0,//sensor gain delay frame for AE cycle,2 frame with ispGain_delay-sensor_gain_delay=2-0=2
-       .ae_ispGain_delay_frame = 2,//isp gain delay frame for AE cycle
-       .sensor_mode_num = 5,     //support sensor mode num
-       
-       .cap_delay_frame = 3,           //enter capture delay frame num
-       .pre_delay_frame = 3,           //enter preview delay frame num
-       .video_delay_frame = 3,         //enter video delay frame num
-       .isp_driving_current = ISP_DRIVING_8MA, //mclk driving current
-    .sensor_interface_type = SENSOR_INTERFACE_TYPE_MIPI,//sensor_interface_type
-       //.mipi_sensor_type = MIPI_OPHY_NCSI2; //0,MIPI_OPHY_NCSI2;  1,MIPI_OPHY_CSI2
-       //.mipi_settle_delay_mode = MIPI_SETTLEDELAY_AUTO; //0,MIPI_SETTLEDELAY_AUTO; 1,MIPI_SETTLEDELAY_MANNUAL
-       .sensor_output_dataformat = SENSOR_OUTPUT_FORMAT_RAW_Gb,//sensor output first pixel color
-       .mclk = 24,//mclk value, suggest 24 or 26 for 24Mhz or 26Mhz
-       .mipi_lane_num = SENSOR_MIPI_2_LANE,//mipi lane num
-       .i2c_addr_table = {0x6c, 0x20, 0xff},//record sensor support all write id addr, only supprt 4must end with 0xff
-};
 
+kal_uint32 OV5670_FeatureControl_PERIOD_PixelNum=OV5670_PV_PERIOD_PIXEL_NUMS;
+kal_uint32 OV5670_FeatureControl_PERIOD_LineNum=OV5670_PV_PERIOD_LINE_NUMS;
+
+UINT16 OV5670_VIDEO_MODE_TARGET_FPS = 30;
+
+MSDK_SCENARIO_ID_ENUM OV5670CurrentScenarioId = MSDK_SCENARIO_ID_CAMERA_PREVIEW;
+MSDK_SENSOR_CONFIG_STRUCT OV5670SensorConfigData;
+static OV5670_PARA_STRUCT OV5670;
+kal_uint32 OV5670_FAC_SENSOR_REG;
+
+
+SENSOR_REG_STRUCT OV5670SensorCCT[]=CAMERA_SENSOR_CCT_DEFAULT_VALUE;
+SENSOR_REG_STRUCT OV5670SensorReg[ENGINEER_END]=CAMERA_SENSOR_REG_DEFAULT_VALUE;
+
+
+#define OV5670_TEST_PATTERN_CHECKSUM 0xca3667da //0x5d8082f0 //0x75bef806 //0xa2230d9f    //0xf5e2f1ce
+kal_bool OV5670_During_testpattern = KAL_FALSE;
+
+extern int iReadReg(u16 a_u2Addr , u8 * a_puBuff , u16 i2cId);
+extern int iWriteReg(u16 a_u2Addr , u32 a_u4Data , u32 a_u4Bytes , u16 i2cId);
+
+#define OV5670_write_cmos_sensor(addr, para) iWriteReg((u16) addr , (u32) para , 1, OV5670MIPI_WRITE_ID)
 
-static imgsensor_struct imgsensor = {
-       .mirror = IMAGE_NORMAL,                         //mirrorflip information
-       .sensor_mode = IMGSENSOR_MODE_INIT, //IMGSENSOR_MODE enum value,record current sensor mode,such as: INIT, Preview, Capture, Video,High Speed Video, Slim Video
-       .shutter = 0x4C00,                                      //current shutter
-       .gain = 0x0200,                                         //current gain
-       .dummy_pixel = 0,                                       //current dummypixel
-       .dummy_line = 0,                                        //current dummyline
-       .current_fps = 0,  //full size current fps : 24fps for PIP, 30fps for Normal or ZSD
-       .autoflicker_en = KAL_FALSE,  //auto flicker enable: KAL_FALSE for disable auto flicker, KAL_TRUE for enable auto flicker
-       .test_pattern = KAL_FALSE,              //test pattern mode or not. KAL_FALSE for in test pattern mode, KAL_TRUE for normal output
-       .current_scenario_id = MSDK_SCENARIO_ID_CAMERA_PREVIEW,//current scenario id
-       .i2c_write_id = 0x6c,//record current sensor's i2c write id
+kal_uint16 OV5670_read_cmos_sensor(kal_uint32 addr)
+{
+kal_uint16 get_byte=0;
+    iReadReg((u16) addr ,(u8*)&get_byte,OV5670MIPI_WRITE_ID);
+    return get_byte;
+}
+
+
+void OV5670_Init_Para(void)
+{
+
+       spin_lock(&ov5670mipiraw_drv_lock);
+       OV5670.sensorMode = SENSOR_MODE_INIT;
+       OV5670.OV5670AutoFlickerMode = KAL_FALSE;
+       OV5670.OV5670VideoMode = KAL_FALSE;
+       OV5670.DummyLines= 0;
+       OV5670.DummyPixels= 0;
+       OV5670.pvPclk =  (10285); 
+       OV5670.videoPclk = (10285);
+       OV5670.capPclk = (10285);
+
+       OV5670.shutter = 0x4C00;
+       OV5670.ispBaseGain = BASEGAIN;
+       OV5670.sensorGlobalGain = 0x0200;
+       spin_unlock(&ov5670mipiraw_drv_lock);
+}
+
+#define RG_Ratio_Typical 0x264
+#define BG_Ratio_Typical 0x236
+
+struct otp_struct {
+   int flag; // bit[7]: info, bit[6]:wb
+   int module_integrator_id;
+   int lens_id;
+   int production_year;
+   int production_month;
+   int production_day;
+   int rg_ratio;
+   int bg_ratio;
+   int g_gain;
+   int ob_data;
+   int golden_RG;
+   int golden_BG;
+   int golden_G;
 };
 
 
-/* Sensor output window information */
+static void otp_i2c_write( uint32_t addr, kal_uint16 data)
+{
+  OV5670_write_cmos_sensor(addr, data);
+}
+
+static kal_uint16 otp_i2c_read(uint32_t addr)
 
-static kal_uint16 read_cmos_sensor(kal_uint32 addr)
 {
-       kal_uint16 get_byte=0;
+       return OV5670_read_cmos_sensor(addr);
+}
 
-       char pu_send_cmd[2] = {(char)(addr >> 8), (char)(addr & 0xFF) };
-       iReadRegI2C(pu_send_cmd, 2, (u8*)&get_byte, 1, imgsensor.i2c_write_id);
 
-       return get_byte;
+// return value:
+// bit[7]: 0 no otp info, 1 valid otp info
+// bit[6]: 0 no otp wb, 1 valib otp wb
+static int read_otp(struct otp_struct *otp_ptr)
+{
+   int otp_flag, addr, temp, i;
+   //set 0x5002[3] to “0”
+   int temp1;
+   
+   temp1 = otp_i2c_read(0x5002);
+   otp_i2c_write(0x5002, (0x00 & 0x08) | (temp1 & (~0x08)));
+   
+   // read OTP into buffer
+   otp_i2c_write(0x3d84, 0xC0);
+   otp_i2c_write(0x3d88, 0x70); // OTP start address
+   otp_i2c_write(0x3d89, 0x10);
+   otp_i2c_write(0x3d8A, 0x70); // OTP end address
+   otp_i2c_write(0x3d8B, 0x29);
+   otp_i2c_write(0x3d81, 0x01); // load otp into buffer
+   mdelay(5);
+   
+   // OTP into
+   otp_flag = otp_i2c_read(0x7010);
+   addr = 0;
+   
+   if((otp_flag & 0xc0) == 0x40) {
+      addr = 0x7011; // base address of info group 1
+   } else if((otp_flag & 0x30) == 0x10) {
+      addr = 0x7018; // base address of info group 2
+   }else if((otp_flag & 0x0c) == 0x04) {
+      addr = 0x701f; // base address of info group 3
+   }
+   
+   if(addr != 0) {
+        (*otp_ptr).flag = 0x80; // valid base info in OTP
+        (*otp_ptr).module_integrator_id = otp_i2c_read( addr );
+        (*otp_ptr).lens_id = otp_i2c_read( addr + 1);
+        (*otp_ptr).production_year = otp_i2c_read( addr + 4);
+        (*otp_ptr).production_month = otp_i2c_read( addr + 5);
+        (*otp_ptr).production_day = otp_i2c_read( addr + 6);
+   } else {
+        (*otp_ptr).flag = 0x00; // not info in OTP
+        (*otp_ptr).module_integrator_id = 0;
+        (*otp_ptr).lens_id = 0;
+        (*otp_ptr).production_year = 0;
+        (*otp_ptr).production_month = 0;
+        (*otp_ptr).production_day = 0;
+   }
+
+   module_id = (*otp_ptr).module_integrator_id;
+   // OTP WB Calibration
+   otp_flag = otp_i2c_read(0x7026);
+   addr = 0;
+   
+   if((otp_flag & 0xc0) == 0x40) {
+     addr = 0x7028; // base address of WB Calibration group 1
+   }else if((otp_flag & 0x30) == 0x10) {
+     addr = 0x7031; // base address of WB Calibration group 2
+   }else if((otp_flag & 0x0c) == 0x04) {
+     addr = 0x703a; // base address of WB Calibration group 3
+   }
+   
+   if(addr != 0) {
+     (*otp_ptr).flag |= 0x40;
+     (*otp_ptr).ob_data = otp_i2c_read(addr-1);
+
+     temp = otp_i2c_read( addr + 3);
+     (*otp_ptr).rg_ratio = (otp_i2c_read(addr)<<2) + ((temp>>6) & 0x03);
+     (*otp_ptr).bg_ratio = (otp_i2c_read( addr + 1)<<2) + ((temp>>4) & 0x03);
+
+     temp = otp_i2c_read(addr + 7);
+     (*otp_ptr).golden_RG = (otp_i2c_read(addr + 4) << 2) + ((temp >> 6) & 0x03);
+     (*otp_ptr).golden_BG = (otp_i2c_read(addr + 5) << 2) + ((temp >> 4) & 0x03);
+     (*otp_ptr).golden_G = otp_i2c_read(addr + 6);
+
+     OV5670DB("ob_data=%d rg_ratio=%d bg_ratio=%d golden_RG=%d golden_BG=%d golden_G=%d\n",
+               (*otp_ptr).ob_data, (*otp_ptr).rg_ratio, (*otp_ptr).bg_ratio, (*otp_ptr).golden_RG, (*otp_ptr).golden_BG, (*otp_ptr).golden_G);
+
+   }else {
+     (*otp_ptr).rg_ratio = 0;
+     (*otp_ptr).bg_ratio = 0;
+   }
+   
+   for(i=0x7010;i<=0x7041;i++) {
+     otp_i2c_write(i,0); // clear OTP buffer, recommended use continuous write to accelarate
+   }
+   
+   //set 0x5002[3] to “1”
+   temp1 = otp_i2c_read(0x5002);
+   otp_i2c_write(0x5002, (0x02 & 0x08) | (temp1 & (~0x08)));
+   return (*otp_ptr).flag ;
 }
 
-static void write_cmos_sensor(kal_uint32 addr, kal_uint32 para)
+static int apply_otp(struct otp_struct *otp_ptr)
 {
-       char pu_send_cmd[3] = {(char)(addr >> 8), (char)(addr & 0xFF), (char)(para & 0xFF)};
-       iWriteRegI2C(pu_send_cmd, 3, imgsensor.i2c_write_id);
+        int rg, bg, R_gain, G_gain, B_gain, Base_gain;
+
+   // apply OTP WB Calibration
+   if ((*otp_ptr).flag & 0x40) {
+        rg = (*otp_ptr). rg_ratio;
+        bg = (*otp_ptr).bg_ratio;
+        //calculate G gain
+        R_gain = (RG_Ratio_Typical*1000) / rg;
+        B_gain = (BG_Ratio_Typical*1000) / bg;
+        G_gain = 1000;    
+         OV5670DB("before calibration R_gain=%d B_gain=%d G_gain=%d rg=%d bg=%d\n", R_gain, B_gain, G_gain, rg, bg);
+        if (R_gain < 1000 || B_gain < 1000)
+        {
+             if (R_gain < B_gain)
+               Base_gain = R_gain;
+             else
+               Base_gain = B_gain;
+        }
+        else
+        {
+             Base_gain = G_gain;
+        }
+        
+        R_gain = 0x400 * R_gain / (Base_gain);
+        B_gain = 0x400 * B_gain / (Base_gain);
+        G_gain = 0x400 * G_gain / (Base_gain);
+        OV5670DB("after calibration R_gain=%d B_gain=%d G_gain=%d \n", R_gain, B_gain, G_gain);
+
+        // update sensor WB gain
+        if (R_gain>0x400) {
+        otp_i2c_write(0x5032, R_gain>>8);
+        otp_i2c_write(0x5033, R_gain & 0x00ff);
+        }
+        if (G_gain>0x400) {
+        otp_i2c_write(0x5034, G_gain>>8);
+        otp_i2c_write(0x5035, G_gain & 0x00ff);
+        }
+        if (B_gain>0x400) {
+        otp_i2c_write(0x5036, B_gain>>8);
+        otp_i2c_write(0x5037, B_gain & 0x00ff);
+        }
+   }
+   return (*otp_ptr).flag ;    
 }
 
-static void set_dummy()
+void ov5670_otp_config()
+{   
+       struct otp_struct otp_info ;  
+       
+       read_otp(&otp_info);   
+       apply_otp(&otp_info) ;
+}
+kal_uint32 GetOV5670LineLength(void)
 {
-       LOG_INF("dummyline = %d, dummypixels = %d \n", imgsensor.dummy_line, imgsensor.dummy_pixel);
-       /* you can set dummy by imgsensor.dummy_line and imgsensor.dummy_pixel, or you can set dummy by imgsensor.frame_length and imgsensor.line_length */
-       write_cmos_sensor(0x380e, (imgsensor.frame_length >> 8) & 0xFF);
-       write_cmos_sensor(0x380f, imgsensor.frame_length & 0xFF);         
-       write_cmos_sensor(0x380c, (imgsensor.line_length >> 8) & 0xFF);
-       write_cmos_sensor(0x380d, imgsensor.line_length & 0xFF);
-  
-}      /*      set_dummy  */
+       kal_uint32 OV5670_line_length = 0;
+       if ( SENSOR_MODE_PREVIEW == OV5670.sensorMode )  
+       {
+               OV5670_line_length = OV5670_PV_PERIOD_PIXEL_NUMS + OV5670.DummyPixels;
+       }
+       else if( SENSOR_MODE_VIDEO == OV5670.sensorMode ) 
+       {
+               OV5670_line_length = OV5670_VIDEO_PERIOD_PIXEL_NUMS + OV5670.DummyPixels;
+       }
+       else
+       {
+               OV5670_line_length = OV5670_FULL_PERIOD_PIXEL_NUMS + OV5670.DummyPixels;
+       }
 
+    return OV5670_line_length;
 
-static void set_max_framerate(UINT16 framerate,kal_bool min_framelength_en)
+}
+
+
+kal_uint32 GetOV5670FrameLength(void)
 {
-       kal_int16 dummy_line;
-       kal_uint32 frame_length = imgsensor.frame_length;
-       //unsigned long flags;
+       kal_uint32 OV5670_frame_length = 0;
 
-       LOG_INF("framerate = %d, min framelength should enable? \n", framerate,min_framelength_en);
-   
-       frame_length = imgsensor.pclk / framerate * 10 / imgsensor.line_length;
-       spin_lock(&imgsensor_drv_lock);
-       imgsensor.frame_length = (frame_length > imgsensor.min_frame_length) ? frame_length : imgsensor.min_frame_length; 
-       imgsensor.dummy_line = imgsensor.frame_length - imgsensor.min_frame_length;
-       //dummy_line = frame_length - imgsensor.min_frame_length;
-       //if (dummy_line < 0)
-               //imgsensor.dummy_line = 0;
-       //else
-               //imgsensor.dummy_line = dummy_line;
-       //imgsensor.frame_length = frame_length + imgsensor.dummy_line;
-       if (imgsensor.frame_length > imgsensor_info.max_frame_length)
+       if ( SENSOR_MODE_PREVIEW == OV5670.sensorMode )  
+       {
+               OV5670_frame_length = OV5670_PV_PERIOD_LINE_NUMS + OV5670.DummyLines ;
+       }
+       else if( SENSOR_MODE_VIDEO == OV5670.sensorMode ) 
+       {
+               OV5670_frame_length = OV5670_VIDEO_PERIOD_LINE_NUMS + OV5670.DummyLines ;
+       }
+       else
        {
-               imgsensor.frame_length = imgsensor_info.max_frame_length;
-               imgsensor.dummy_line = imgsensor.frame_length - imgsensor.min_frame_length;
+               OV5670_frame_length = OV5670_FULL_PERIOD_LINE_NUMS + OV5670.DummyLines ;
        }
-       if (min_framelength_en)
-               imgsensor.min_frame_length = imgsensor.frame_length;
-       spin_unlock(&imgsensor_drv_lock);
-       set_dummy();
-}      /*      set_max_framerate  */
+
+       return OV5670_frame_length;
+}
 
 
-static void write_shutter(kal_uint16 shutter)
+kal_uint32 OV5670_CalcExtra_For_ShutterMargin(kal_uint32 shutter_value,kal_uint32 shutterLimitation)
 {
-    unsigned long flags;
-       kal_uint16 realtime_fps = 0;
-       kal_uint32 frame_length = 0;
-    spin_lock_irqsave(&imgsensor_drv_lock, flags);
-    imgsensor.shutter = shutter;
-    spin_unlock_irqrestore(&imgsensor_drv_lock, flags);
+    kal_uint32 extra_lines = 0;
 
-       /* 0x3500, 0x3501, 0x3502 will increase VBLANK to get exposure larger than frame exposure */
-       /* AE doesn't update sensor gain at capture mode, thus extra exposure lines must be updated here. */
        
-       // OV Recommend Solution
-       // if shutter bigger than frame_length, should extend frame length first
-       spin_lock(&imgsensor_drv_lock);
-       if (shutter > imgsensor.min_frame_length - imgsensor_info.margin)               
-               imgsensor.frame_length = shutter + imgsensor_info.margin;
-       else
-               imgsensor.frame_length = imgsensor.min_frame_length;
-       if (imgsensor.frame_length > imgsensor_info.max_frame_length)
-               imgsensor.frame_length = imgsensor_info.max_frame_length;
-       imgsensor.frame_length = (imgsensor.frame_length>>1)<<1;
-       spin_unlock(&imgsensor_drv_lock);
-       shutter = (shutter < imgsensor_info.min_shutter) ? imgsensor_info.min_shutter : shutter;
-       shutter = (shutter > (imgsensor_info.max_frame_length - imgsensor_info.margin)) ? (imgsensor_info.max_frame_length - imgsensor_info.margin) : shutter;
-       shutter = (shutter >> 1) << 1;
+       if (shutter_value <4 ){
+               shutter_value = 4;
+       }
+
        
-       if (imgsensor.autoflicker_en) { 
-               realtime_fps = imgsensor.pclk / imgsensor.line_length * 10 / imgsensor.frame_length;
-               if(realtime_fps >= 297 && realtime_fps <= 305)
-                       set_max_framerate(296,0);
-               else if(realtime_fps >= 147 && realtime_fps <= 150)
-                       set_max_framerate(146,0);       
-        else {
-        // Extend frame length
-        write_cmos_sensor(0x380e, imgsensor.frame_length >> 8);
-        write_cmos_sensor(0x380f, imgsensor.frame_length & 0xFF);
-        }
-       } else {
-               // Extend frame length
-               write_cmos_sensor(0x380e, (imgsensor.frame_length >> 8)& 0xFF);
-               write_cmos_sensor(0x380f, imgsensor.frame_length & 0xFF);
+       if (shutter_value > shutterLimitation)
+       {
+               extra_lines = shutter_value - shutterLimitation;
+    }
+       else
+               extra_lines = 0;
+
+    return extra_lines;
+
+}
+
+
+kal_uint32 OV5670_CalcFrameLength_For_AutoFlicker(void)
+{
+
+    kal_uint32 AutoFlicker_min_framelength = 0;
+
+       switch(OV5670CurrentScenarioId)
+       {
+               case MSDK_SCENARIO_ID_CAMERA_ZSD:
+               case MSDK_SCENARIO_ID_CAMERA_CAPTURE_JPEG:
+                       AutoFlicker_min_framelength = (OV5670.capPclk*10000) /(OV5670_FULL_PERIOD_PIXEL_NUMS + OV5670.DummyPixels)/OV5670_AUTOFLICKER_OFFSET_25*10 ;
+                       break;
+               case MSDK_SCENARIO_ID_VIDEO_PREVIEW:
+                       if(OV5670_VIDEO_MODE_TARGET_FPS==30)
+                       {
+                               AutoFlicker_min_framelength = (OV5670.videoPclk*10000) /(OV5670_VIDEO_PERIOD_PIXEL_NUMS + OV5670.DummyPixels)/OV5670_AUTOFLICKER_OFFSET_30*10 ;
+                       }
+                       else if(OV5670_VIDEO_MODE_TARGET_FPS==15)
+                       {
+                               AutoFlicker_min_framelength = (OV5670.videoPclk*10000) /(OV5670_VIDEO_PERIOD_PIXEL_NUMS + OV5670.DummyPixels)/OV5670_AUTOFLICKER_OFFSET_15*10 ;
+                       }
+                       else
+                       {
+                               AutoFlicker_min_framelength = OV5670_VIDEO_PERIOD_LINE_NUMS + OV5670.DummyLines;
+                       }
+                       break;
+                       
+               case MSDK_SCENARIO_ID_CAMERA_PREVIEW:
+               default:
+                       AutoFlicker_min_framelength = (OV5670.pvPclk*10000) /(OV5670_PV_PERIOD_PIXEL_NUMS + OV5670.DummyPixels)/OV5670_AUTOFLICKER_OFFSET_30*10 ;
+                       break;
        }
 
-       // Update Shutter
-       write_cmos_sensor(0x3502, (shutter << 4) & 0xF0);
-       write_cmos_sensor(0x3501, (shutter >> 4) & 0xFF);         
-       write_cmos_sensor(0x3500, (shutter >> 12) & 0x0F);      
-       LOG_INF("Exit! shutter =%d, framelength =%d\n", shutter,imgsensor.frame_length);
+       OV5670DB("AutoFlicker_min_framelength =%d,OV5670CurrentScenarioId =%d\n", AutoFlicker_min_framelength,OV5670CurrentScenarioId);
 
-       //LOG_INF("frame_length = %d ", frame_length);
-       
-}      /*      write_shutter  */
+       return AutoFlicker_min_framelength;
 
+}
 
 
-/*************************************************************************
-* FUNCTION
-*      set_shutter
-*
-* DESCRIPTION
-*      This function set e-shutter of sensor to change exposure time.
-*
-* PARAMETERS
-*      iShutter : exposured lines
-*
-* RETURNS
-*      None
-*
-* GLOBALS AFFECTED
-*
-*************************************************************************/
-static void set_shutter(kal_uint16 shutter)
+void OV5670_write_shutter(kal_uint32 shutter)
 {
+       kal_uint32 min_framelength = OV5670_PV_PERIOD_PIXEL_NUMS, max_shutter=0;
+       kal_uint32 line_length = 0;
+       kal_uint32 frame_length = 0;
        unsigned long flags;
-       spin_lock_irqsave(&imgsensor_drv_lock, flags);
-       imgsensor.shutter = shutter;
-       spin_unlock_irqrestore(&imgsensor_drv_lock, flags);
+
+       //for test
+       //shutter = 0x7fc;  //issue 
+       
        
-       write_shutter(shutter);
-}      /*      set_shutter */
+    line_length  = GetOV5670LineLength();
+       frame_length = GetOV5670FrameLength();
+       
+       max_shutter  = frame_length-OV5670_SHUTTER_MARGIN;
 
+    frame_length = frame_length + OV5670_CalcExtra_For_ShutterMargin(shutter,max_shutter);
+       
 
 
-static kal_uint16 gain2reg(const kal_uint16 gain)
-{
-       kal_uint16 reg_gain = 0x0000;
+       if(OV5670.OV5670AutoFlickerMode == KAL_TRUE)
+       {
+        min_framelength = OV5670_CalcFrameLength_For_AutoFlicker();
+
+        if(frame_length < min_framelength)
+                       frame_length = min_framelength;
+       }
        
-       reg_gain = ((gain * 128)/BASEGAIN);
-       //reg_gain = ((gain /BASEGAIN)<<7)+((gain % BASEGAIN)<<7/BASEGAIN);
-       reg_gain = reg_gain & 0xFFFF;
-       return (kal_uint16)reg_gain;
+
+       spin_lock_irqsave(&ov5670mipiraw_drv_lock,flags);
+       OV5670_FeatureControl_PERIOD_PixelNum = line_length;
+       OV5670_FeatureControl_PERIOD_LineNum = frame_length;
+       spin_unlock_irqrestore(&ov5670mipiraw_drv_lock,flags);
+
+       //Set total frame length  //VTS
+       OV5670_write_cmos_sensor(0x380e, (frame_length >> 8) & 0xFF);
+       OV5670_write_cmos_sensor(0x380f, frame_length & 0xFF);
+
+       //Set shutter 
+       OV5670_write_cmos_sensor(0x3500, (shutter>>12) & 0x0F);
+       OV5670_write_cmos_sensor(0x3501, (shutter>>4) & 0xFF);
+       OV5670_write_cmos_sensor(0x3502, (shutter<<4) & 0xF0);    /* Don't use the fraction part. */
+
+       OV5670DB("ov5670 write shutter=%x, line_length=%x, frame_length=%x\n", shutter, line_length, frame_length);
+
 }
 
-/*************************************************************************
-* FUNCTION
-*      set_gain
-*
-* DESCRIPTION
-*      This function is to set global gain to sensor.
-*
-* PARAMETERS
-*      iGain : sensor global gain(base: 0x40)
-*
-* RETURNS
-*      the actually gain set to sensor.
-*
-* GLOBALS AFFECTED
-*
-*************************************************************************/
-static kal_uint16 set_gain(kal_uint16 gain)
+
+static kal_uint16 OV5670Reg2Gain(const kal_uint16 iReg)
 {
-       kal_uint16 reg_gain;
-       kal_uint16 iGain =1;
-       kal_uint8 ChangeFlag=0x07;
+    kal_uint16 iGain =0; 
+
+       iGain = iReg*BASEGAIN/OV5670_GAIN_BASE;
+       return iGain;
        
+}
 
-       /* 0x350A[0:1], 0x350B[0:7] AGC real gain */
-       /* [0:3] = N meams N /16 X      */
-       /* [4:9] = M meams M X           */
-       /* Total gain = M + N /16 X   */
+static kal_uint16 OV5670Gain2Reg(const kal_uint16 Gain)
+{
+    kal_uint32 iReg = 0x0000;
+       kal_uint32 TempGain = BASEGAIN;
 
 
-       //
-       if (gain < BASEGAIN || gain > 8 * BASEGAIN) {
-               LOG_INF("Error gain setting");
+       TempGain = Gain;
+       if(TempGain < BASEGAIN){
+               TempGain = BASEGAIN;
+               //OV5670DB("###ov5670 write gain underflow### Gain =%x\n", Gain);
+       }
+       if(TempGain > 16*BASEGAIN){
+               TempGain = 16*BASEGAIN;
+               //OV5670DB("###ov5670 write gain overflow### Gain =%x\n", Gain);
+       }
 
-               if (gain < BASEGAIN)
-                       gain = BASEGAIN;
-               else if (gain > 8 * BASEGAIN)
-                       gain = 8 * BASEGAIN;             
-               }
+       iReg = (TempGain*OV5670_GAIN_BASE)/BASEGAIN;
 
-               iGain = gain/BASEGAIN;
-               
-               if(iGain<2){
-                       ChangeFlag= 0x00;
-               }
-               else if(iGain<4){
-                       ChangeFlag= 0x01;
-               }
-               else if(iGain<8){
-                       ChangeFlag= 0x03;
-               }
-               else{
-                       ChangeFlag= 0x07;
-               }
-       reg_gain = gain2reg(gain);
-       spin_lock(&imgsensor_drv_lock);
-       imgsensor.gain = reg_gain; 
-       spin_unlock(&imgsensor_drv_lock);
-       LOG_INF("gain = %d ,reg[0x366a]= %d, reg_gain = 0x%x\n ", gain, ChangeFlag, reg_gain);
-
-       write_cmos_sensor(0x301d, 0xf0);
-       write_cmos_sensor(0x3209, 0x00);
-       write_cmos_sensor(0x320a, 0x01);
+       //iReg = ((TempGain /BASEGAIN)<<7)+((TempGain % BASEGAIN)<<7/BASEGAIN);
+       iReg = iReg & 0xFFFF;
+
+       //OV5670DB("###ov5670 write Reg ### iReg =%x\n", iReg);
+
+    return iReg;
+
+}
+
+void write_OV5670_gain(kal_uint16 gain)
+{
+       kal_uint16 iGain =1;
+       kal_uint8 ChangeFlag=0x01;
+
+       kal_uint16 read_gain;
+       
+       iGain=(gain / OV5670_GAIN_BASE);
+
+       if(iGain<2){
+               ChangeFlag= 0x00;
+       }
+       else if(iGain<4){
+               ChangeFlag= 0x01;
+       }
+       else if(iGain<8){
+               ChangeFlag= 0x03;
+       }
+       else{
+               ChangeFlag= 0x07;
+       }
+
+       //ChangeFlag= 0x07;
+       
+       OV5670_write_cmos_sensor(0x301d, 0xf0);
+       OV5670_write_cmos_sensor(0x3209, 0x00);
+       OV5670_write_cmos_sensor(0x320a, 0x01);
        
        //group write  hold
-       //group 0:delay 0x366a for one frame
-       write_cmos_sensor(0x3208, 0x00);
-       write_cmos_sensor(0x366a, ChangeFlag);
-       write_cmos_sensor(0x3208, 0x10);
+       //group 0:delay 0x366a for one frame,then active with gain
+       OV5670_write_cmos_sensor(0x3208, 0x00);
+       OV5670_write_cmos_sensor(0x366a, ChangeFlag);
+       OV5670_write_cmos_sensor(0x3208, 0x10);
 
        //group 1:all other registers( gain)
-       write_cmos_sensor(0x3208, 0x01);
-       write_cmos_sensor(0x3508, reg_gain >> 8);
-       write_cmos_sensor(0x3509, reg_gain & 0xFF);    
-
-       write_cmos_sensor(0x3208, 0x11);
+       OV5670_write_cmos_sensor(0x3208, 0x01);
+       OV5670_write_cmos_sensor(0x3508,(gain>>8));
+    OV5670_write_cmos_sensor(0x3509,(gain&0xff));
+       
+       OV5670_write_cmos_sensor(0x3208, 0x11);
 
        //group lanch
-       write_cmos_sensor(0x320B, 0x15);
-       write_cmos_sensor(0x3208, 0xA1);
+       OV5670_write_cmos_sensor(0x320B, 0x15);
+       OV5670_write_cmos_sensor(0x3208, 0xA1);
+
+       //read_gain=(((OV5670_read_cmos_sensor(0x3508)&0x1F) << 8) | OV5670_read_cmos_sensor(0x3509));
+       //OV5670DB("[OV5670_SetGain]0x3508|0x3509=0x%x \n",read_gain);
+       //OV5670DB("[OV5670_SetGain]0x366a=%d \n",(OV5670_read_cmos_sensor(0x366a)));
+
+       return;
+
+}
+
+void OV5670_SetGain(UINT16 iGain)
+{
+       unsigned long flags;
+       spin_lock_irqsave(&ov5670mipiraw_drv_lock,flags);
+
+       OV5670DB("OV5670_SetGain iGain = %d :\n ",iGain);
        
-       return gain;
-}      /*      set_gain  */
+       OV5670.realGain = iGain;
+       OV5670.sensorGlobalGain = OV5670Gain2Reg(iGain);
+       spin_unlock_irqrestore(&ov5670mipiraw_drv_lock,flags);
 
+       write_OV5670_gain(OV5670.sensorGlobalGain);
+       OV5670DB(" [OV5670_SetGain]OV5670.sensorGlobalGain=0x%x,OV5670.realGain =%d",OV5670.sensorGlobalGain,
+               OV5670.realGain); 
 
+       //temperature test
+       //OV5670_write_cmos_sensor(0x4d12,0x01);
+       //OV5670DB("Temperature read_reg  0x4d13  =%x \n",OV5670_read_cmos_sensor(0x4d13));
+}   
 
+kal_uint16 read_OV5670_gain(void)
+{
+       kal_uint16 read_gain=0;
+
+       read_gain=(((OV5670_read_cmos_sensor(0x3508)&0x1F) << 8) | OV5670_read_cmos_sensor(0x3509));
+
+       spin_lock(&ov5670mipiraw_drv_lock);
+       OV5670.sensorGlobalGain = read_gain;
+       OV5670.realGain = OV5670Reg2Gain(OV5670.sensorGlobalGain);
+       spin_unlock(&ov5670mipiraw_drv_lock);
+
+       OV5670DB("OV5670.sensorGlobalGain=0x%x,OV5670.realGain=%d\n",OV5670.sensorGlobalGain,OV5670.realGain);
 
+       return OV5670.sensorGlobalGain;
+}  
 
-static void set_mirror_flip(kal_uint8 image_mirror)
+
+#if 1
+void OV5670_camera_para_to_sensor(void)
 {
-       LOG_INF("image_mirror = %d\n", image_mirror);
-
-       /********************************************************
-          *
-          *   0x3820[2] ISP Vertical flip
-          *   0x3820[1] Sensor Vertical flip
-          *
-          *   0x3821[2] ISP Horizontal mirror
-          *   0x3821[1] Sensor Horizontal mirror
-          *
-          *   ISP and Sensor flip or mirror register bit should be the same!!
-          *
-          ********************************************************/
-       
-       switch (image_mirror) {
-               case IMAGE_NORMAL:
-                       write_cmos_sensor(0x3820,((read_cmos_sensor(0x3820) & 0xF9) | 0x00));
-                       write_cmos_sensor(0x3821,((read_cmos_sensor(0x3821) & 0xF9) | 0x06));
-                       break;
-               case IMAGE_H_MIRROR:
-                       write_cmos_sensor(0x3820,((read_cmos_sensor(0x3820) & 0xF9) | 0x00));
-                       write_cmos_sensor(0x3821,((read_cmos_sensor(0x3821) & 0xF9) | 0x00));
-                       break;
-               case IMAGE_V_MIRROR:
-                       write_cmos_sensor(0x3820,((read_cmos_sensor(0x3820) & 0xF9) | 0x06));
-                       write_cmos_sensor(0x3821,((read_cmos_sensor(0x3821) & 0xF9) | 0x06));           
-                       break;
-               case IMAGE_HV_MIRROR:
-                       write_cmos_sensor(0x3820,((read_cmos_sensor(0x3820) & 0xF9) | 0x06));
-                       write_cmos_sensor(0x3821,((read_cmos_sensor(0x3821) & 0xF9) | 0x00));
-                       break;
-               default:
-                       LOG_INF("Error image_mirror setting\n");
-       }
+    kal_uint32    i;
+    for(i=0; 0xFFFFFFFF!=OV5670SensorReg[i].Addr; i++)
+    {
+        OV5670_write_cmos_sensor(OV5670SensorReg[i].Addr, OV5670SensorReg[i].Para);
+    }
+    for(i=ENGINEER_START_ADDR; 0xFFFFFFFF!=OV5670SensorReg[i].Addr; i++)
+    {
+        OV5670_write_cmos_sensor(OV5670SensorReg[i].Addr, OV5670SensorReg[i].Para);
+    }
+    for(i=FACTORY_START_ADDR; i<FACTORY_END_ADDR; i++)
+    {
+        OV5670_write_cmos_sensor(OV5670SensorCCT[i].Addr, OV5670SensorCCT[i].Para);
+    }
+}
 
+void OV5670_sensor_to_camera_para(void)
+{
+    kal_uint32    i, temp_data;
+    for(i=0; 0xFFFFFFFF!=OV5670SensorReg[i].Addr; i++)
+    {
+         temp_data = OV5670_read_cmos_sensor(OV5670SensorReg[i].Addr);
+                spin_lock(&ov5670mipiraw_drv_lock);
+                OV5670SensorReg[i].Para =temp_data;
+                spin_unlock(&ov5670mipiraw_drv_lock);
+    }
+    for(i=ENGINEER_START_ADDR; 0xFFFFFFFF!=OV5670SensorReg[i].Addr; i++)
+    {
+        temp_data = OV5670_read_cmos_sensor(OV5670SensorReg[i].Addr);
+               spin_lock(&ov5670mipiraw_drv_lock);
+               OV5670SensorReg[i].Para = temp_data;
+               spin_unlock(&ov5670mipiraw_drv_lock);
+    }
 }
 
-/*************************************************************************
-* FUNCTION
-*      night_mode
-*
-* DESCRIPTION
-*      This function night mode of sensor.
-*
-* PARAMETERS
-*      bEnable: KAL_TRUE -> enable night mode, otherwise, disable night mode
-*
-* RETURNS
-*      None
-*
-* GLOBALS AFFECTED
-*
-*************************************************************************/
-static void night_mode(kal_bool enable)
+kal_int32  OV5670_get_sensor_group_count(void)
 {
-/*No Need to implement this function*/ 
-}      /*      night_mode      */
+    return GROUP_TOTAL_NUMS;
+}
 
-static void sensor_init(void)
+void OV5670_get_sensor_group_info(kal_uint16 group_idx, kal_int8* group_name_ptr, kal_int32* item_count_ptr)
 {
-       LOG_INF("OV5670_Sensor_Init_2lane E\n");
-       
-       write_cmos_sensor(0x0103,0x01);// ; software reset
-       mDELAY(10);
-       write_cmos_sensor(0x0100, 0x00);// ; software standby
-       write_cmos_sensor(0x0300, 0x04); 
-       write_cmos_sensor(0x0301, 0x00); 
-       write_cmos_sensor(0x0302, 0x69); //;78 MIPI datarate 960 -> 840
-       write_cmos_sensor(0x0303, 0x00); 
-       write_cmos_sensor(0x0304, 0x03); 
-       write_cmos_sensor(0x0305, 0x01); 
-       write_cmos_sensor(0x0306, 0x01); 
-       write_cmos_sensor(0x030a, 0x00); 
-       write_cmos_sensor(0x030b, 0x00); 
-       write_cmos_sensor(0x030c, 0x00); 
-       write_cmos_sensor(0x030d, 0x1e); 
-       write_cmos_sensor(0x030e, 0x00); 
-       write_cmos_sensor(0x030f, 0x06); 
-       write_cmos_sensor(0x0312, 0x01); 
-       write_cmos_sensor(0x3000, 0x00); 
-       write_cmos_sensor(0x3002, 0x61); 
-       write_cmos_sensor(0x3005, 0xf0); 
-       write_cmos_sensor(0x3007, 0x00); 
-       write_cmos_sensor(0x300d, 0x00); 
-       write_cmos_sensor(0x3010, 0x40); 
-       write_cmos_sensor(0x3015, 0x0f); 
-       write_cmos_sensor(0x3018, 0x32); 
-       write_cmos_sensor(0x301a, 0xf0); 
-       write_cmos_sensor(0x301b, 0xf0); 
-       write_cmos_sensor(0x301c, 0xf0); 
-       write_cmos_sensor(0x301d, 0xf0); 
-       write_cmos_sensor(0x301e, 0xf0); 
-       write_cmos_sensor(0x3030, 0x00); 
-       write_cmos_sensor(0x3031, 0x0a); 
-       write_cmos_sensor(0x303c, 0xff); 
-       write_cmos_sensor(0x303e, 0xff); 
-       write_cmos_sensor(0x3040, 0xf0); 
-       write_cmos_sensor(0x3041, 0x00); 
-       write_cmos_sensor(0x3042, 0xf0); 
-       write_cmos_sensor(0x3106, 0x11); 
-       write_cmos_sensor(0x3500, 0x00); 
-       write_cmos_sensor(0x3501, 0x7b); 
-       write_cmos_sensor(0x3502, 0x00); 
-       write_cmos_sensor(0x3503, 0x04); 
-       write_cmos_sensor(0x3504, 0x03); 
-       write_cmos_sensor(0x3505, 0x83); 
-       write_cmos_sensor(0x3508, 0x07); 
-       write_cmos_sensor(0x3509, 0x80); 
-       write_cmos_sensor(0x350e, 0x04); 
-       write_cmos_sensor(0x350f, 0x00); 
-       write_cmos_sensor(0x3510, 0x00); 
-       write_cmos_sensor(0x3511, 0x02); 
-       write_cmos_sensor(0x3512, 0x00); 
-       write_cmos_sensor(0x3601, 0xc8); 
-       write_cmos_sensor(0x3610, 0x88); 
-       write_cmos_sensor(0x3612, 0x48); 
-       write_cmos_sensor(0x3614, 0x5b); 
-       write_cmos_sensor(0x3615, 0x96); 
-       write_cmos_sensor(0x3621, 0xd0); 
-       write_cmos_sensor(0x3622, 0x00); 
-       write_cmos_sensor(0x3623, 0x00);  
-       write_cmos_sensor(0x3633, 0x13); 
-       write_cmos_sensor(0x3634, 0x13); 
-       write_cmos_sensor(0x3635, 0x13); 
-       write_cmos_sensor(0x3636, 0x13); 
-       write_cmos_sensor(0x3645, 0x13); 
-       write_cmos_sensor(0x3646, 0x82); 
-       write_cmos_sensor(0x3650, 0x00); 
-       write_cmos_sensor(0x3652, 0xff); 
-       write_cmos_sensor(0x3655, 0x20); 
-       write_cmos_sensor(0x3656, 0xff); 
-       write_cmos_sensor(0x365a, 0xff); 
-       write_cmos_sensor(0x365e, 0xff); 
-       write_cmos_sensor(0x3668, 0x00); 
-       write_cmos_sensor(0x366a, 0x07); 
-       write_cmos_sensor(0x366e, 0x10); 
-       write_cmos_sensor(0x366d, 0x00); 
-       write_cmos_sensor(0x366f, 0x80); 
-       write_cmos_sensor(0x3700, 0x28); 
-       write_cmos_sensor(0x3701, 0x10); 
-       write_cmos_sensor(0x3702, 0x3a); 
-       write_cmos_sensor(0x3703, 0x19); 
-       write_cmos_sensor(0x3704, 0x10); 
-       write_cmos_sensor(0x3705, 0x00); 
-       write_cmos_sensor(0x3706, 0x66); 
-       write_cmos_sensor(0x3707, 0x08); 
-       write_cmos_sensor(0x3708, 0x34); 
-       write_cmos_sensor(0x3709, 0x40); 
-       write_cmos_sensor(0x370a, 0x01); 
-       write_cmos_sensor(0x370b, 0x1b); 
-       write_cmos_sensor(0x3714, 0x24); 
-       write_cmos_sensor(0x371a, 0x3e); 
-       write_cmos_sensor(0x3733, 0x00); 
-       write_cmos_sensor(0x3734, 0x00); 
-       write_cmos_sensor(0x373a, 0x05); 
-       write_cmos_sensor(0x373b, 0x06); 
-       write_cmos_sensor(0x373c, 0x0a); 
-       write_cmos_sensor(0x373f, 0xa0); 
-       write_cmos_sensor(0x3755, 0x00); 
-       write_cmos_sensor(0x3758, 0x00); 
-       write_cmos_sensor(0x375b, 0x0e);
-       write_cmos_sensor(0x3766, 0x5f); 
-       write_cmos_sensor(0x3768, 0x00); 
-       write_cmos_sensor(0x3769, 0x22); 
-       write_cmos_sensor(0x3773, 0x08); 
-       write_cmos_sensor(0x3774, 0x1f); 
-       write_cmos_sensor(0x3776, 0x06); 
-       write_cmos_sensor(0x37a0, 0x88); 
-       write_cmos_sensor(0x37a1, 0x5c); 
-       write_cmos_sensor(0x37a7, 0x88); 
-       write_cmos_sensor(0x37a8, 0x70); 
-       write_cmos_sensor(0x37aa, 0x88); 
-       write_cmos_sensor(0x37ab, 0x48); 
-       write_cmos_sensor(0x37b3, 0x66); 
-       write_cmos_sensor(0x37c2, 0x04); 
-       write_cmos_sensor(0x37c5, 0x00); 
-       write_cmos_sensor(0x37c8, 0x00); 
-       write_cmos_sensor(0x3800, 0x00); 
-       write_cmos_sensor(0x3801, 0x0c); 
-       write_cmos_sensor(0x3802, 0x00); 
-       write_cmos_sensor(0x3803, 0x04); 
-       write_cmos_sensor(0x3804, 0x0a); 
-       write_cmos_sensor(0x3805, 0x33); 
-       write_cmos_sensor(0x3806, 0x07); 
-       write_cmos_sensor(0x3807, 0xa3); 
-       write_cmos_sensor(0x3808, 0x0a); 
-       write_cmos_sensor(0x3809, 0x20); 
-       write_cmos_sensor(0x380a, 0x07); 
-       write_cmos_sensor(0x380b, 0x98); 
-       write_cmos_sensor(0x380c, 0x06); // ;06
-       write_cmos_sensor(0x380d, 0x8c); // ;8c
-       write_cmos_sensor(0x380e, 0x07); 
-       write_cmos_sensor(0x380f, 0xb8); 
-       write_cmos_sensor(0x3811, 0x04); 
-       write_cmos_sensor(0x3813, 0x02); 
-       write_cmos_sensor(0x3814, 0x01); 
-       write_cmos_sensor(0x3815, 0x01); 
-       write_cmos_sensor(0x3816, 0x00); 
-       write_cmos_sensor(0x3817, 0x00); 
-       write_cmos_sensor(0x3818, 0x00); 
-       write_cmos_sensor(0x3819, 0x00); 
-       write_cmos_sensor(0x3820, 0x80); 
-       write_cmos_sensor(0x3821, 0x46); 
-       write_cmos_sensor(0x3822, 0x48); 
-       write_cmos_sensor(0x3826, 0x00); 
-       write_cmos_sensor(0x3827, 0x08); 
-       write_cmos_sensor(0x382a, 0x01); 
-       write_cmos_sensor(0x382b, 0x01); 
-       write_cmos_sensor(0x3830, 0x08); 
-       write_cmos_sensor(0x3836, 0x02); 
-       write_cmos_sensor(0x3837, 0x00); 
-       write_cmos_sensor(0x3838, 0x10); 
-       write_cmos_sensor(0x3841, 0xff); 
-       write_cmos_sensor(0x3846, 0x48); 
-       write_cmos_sensor(0x3861, 0x00); 
-       write_cmos_sensor(0x3862, 0x04); 
-       write_cmos_sensor(0x3863, 0x06); 
-       write_cmos_sensor(0x3a11, 0x01); 
-       write_cmos_sensor(0x3a12, 0x78); 
-       write_cmos_sensor(0x3b00, 0x00); 
-       write_cmos_sensor(0x3b02, 0x00); 
-       write_cmos_sensor(0x3b03, 0x00); 
-       write_cmos_sensor(0x3b04, 0x00); 
-       write_cmos_sensor(0x3b05, 0x00); 
-       write_cmos_sensor(0x3c00, 0x89); 
-       write_cmos_sensor(0x3c01, 0xab); 
-       write_cmos_sensor(0x3c02, 0x01); 
-       write_cmos_sensor(0x3c03, 0x00); 
-       write_cmos_sensor(0x3c04, 0x00); 
-       write_cmos_sensor(0x3c05, 0x03); 
-       write_cmos_sensor(0x3c06, 0x00); 
-       write_cmos_sensor(0x3c07, 0x05); 
-       write_cmos_sensor(0x3c0c, 0x00); 
-       write_cmos_sensor(0x3c0d, 0x00); 
-       write_cmos_sensor(0x3c0e, 0x00); 
-       write_cmos_sensor(0x3c0f, 0x00); 
-       write_cmos_sensor(0x3c40, 0x00); 
-       write_cmos_sensor(0x3c41, 0xa3); 
-       write_cmos_sensor(0x3c43, 0x7d); 
-       write_cmos_sensor(0x3c45, 0xd7); 
-       write_cmos_sensor(0x3c47, 0xfc); 
-       write_cmos_sensor(0x3c50, 0x05); 
-       write_cmos_sensor(0x3c52, 0xaa); 
-       write_cmos_sensor(0x3c54, 0x71); 
-       write_cmos_sensor(0x3c56, 0x80); 
-       write_cmos_sensor(0x3d85, 0x17); 
-       write_cmos_sensor(0x3f03, 0x00); 
-       write_cmos_sensor(0x3f0a, 0x00); 
-       write_cmos_sensor(0x3f0b, 0x00); 
-       write_cmos_sensor(0x4001, 0x60); 
-       write_cmos_sensor(0x4009, 0x0d); 
-       write_cmos_sensor(0x4020, 0x00); 
-       write_cmos_sensor(0x4021, 0x00); 
-       write_cmos_sensor(0x4022, 0x00); 
-       write_cmos_sensor(0x4023, 0x00); 
-       write_cmos_sensor(0x4024, 0x00); 
-       write_cmos_sensor(0x4025, 0x00); 
-       write_cmos_sensor(0x4026, 0x00); 
-       write_cmos_sensor(0x4027, 0x00); 
-       write_cmos_sensor(0x4028, 0x00); 
-       write_cmos_sensor(0x4029, 0x00); 
-       write_cmos_sensor(0x402a, 0x00); 
-       write_cmos_sensor(0x402b, 0x00); 
-       write_cmos_sensor(0x402c, 0x00); 
-       write_cmos_sensor(0x402d, 0x00); 
-       write_cmos_sensor(0x402e, 0x00); 
-       write_cmos_sensor(0x402f, 0x00); 
-       write_cmos_sensor(0x4040, 0x00); 
-       write_cmos_sensor(0x4041, 0x03); 
-       write_cmos_sensor(0x4042, 0x00); 
-       write_cmos_sensor(0x4043, 0x7a); 
-       write_cmos_sensor(0x4044, 0x00); 
-       write_cmos_sensor(0x4045, 0x7a); 
-       write_cmos_sensor(0x4046, 0x00); 
-       write_cmos_sensor(0x4047, 0x7a); 
-       write_cmos_sensor(0x4048, 0x00); 
-       write_cmos_sensor(0x4049, 0x7a); 
-       write_cmos_sensor(0x4303, 0x00); 
-       write_cmos_sensor(0x4307, 0x30); 
-       write_cmos_sensor(0x4500, 0x58); 
-       write_cmos_sensor(0x4501, 0x04); 
-       write_cmos_sensor(0x4502, 0x40); 
-       write_cmos_sensor(0x4503, 0x10); 
-       write_cmos_sensor(0x4508, 0xaa); 
-       write_cmos_sensor(0x4509, 0xaa); 
-       write_cmos_sensor(0x450a, 0x00); 
-       write_cmos_sensor(0x450b, 0x00); 
-       write_cmos_sensor(0x4600, 0x01); 
-       write_cmos_sensor(0x4601, 0x03); 
-       write_cmos_sensor(0x4700, 0xa4); 
-       write_cmos_sensor(0x4800, 0x6c); 
-       write_cmos_sensor(0x4816, 0x53); 
-       write_cmos_sensor(0x481f, 0x40); 
-       write_cmos_sensor(0x4837, 0x13); // ;11 mipi global timing datarate 940 -> 840
-       write_cmos_sensor(0x5000, 0x56); 
-       write_cmos_sensor(0x5001, 0x01); 
-       write_cmos_sensor(0x5002, 0x28); 
-       write_cmos_sensor(0x5004, 0x0c); 
-       write_cmos_sensor(0x5006, 0x0c); 
-       write_cmos_sensor(0x5007, 0xe0); 
-       write_cmos_sensor(0x5008, 0x01); 
-       write_cmos_sensor(0x5009, 0xb0); 
-       write_cmos_sensor(0x5901, 0x00); 
-       write_cmos_sensor(0x5a01, 0x00); 
-       write_cmos_sensor(0x5a03, 0x00); 
-       write_cmos_sensor(0x5a04, 0x0c); 
-       write_cmos_sensor(0x5a05, 0xe0); 
-       write_cmos_sensor(0x5a06, 0x09); 
-       write_cmos_sensor(0x5a07, 0xb0); 
-       write_cmos_sensor(0x5a08, 0x06); 
-       write_cmos_sensor(0x5e00, 0x00); 
-       write_cmos_sensor(0x3618, 0x2a); 
-                                                                  
-       //;Ally031414                                     
-       write_cmos_sensor(0x3734, 0x40); //     ;; Improve HFPN
-       write_cmos_sensor(0x5b00, 0x01);  // ;; [2:0] otp start addr[10:8]
-       write_cmos_sensor(0x5b01, 0x10);  // ;; [7:0] otp start addr[7:0]
-       write_cmos_sensor(0x5b02, 0x01);  // ;; [2:0] otp end addr[10:8]
-       write_cmos_sensor(0x5b03, 0xDB);  // ;; [7:0] otp end addr[7:0]
-       write_cmos_sensor(0x3d8c, 0x71); //; Header address high byte
-       write_cmos_sensor(0x3d8d, 0xEA); //; Header address low byte
-       write_cmos_sensor(0x4017, 0x08); // ; threshold= 2LSB for full size
-                                                                 
-       //;Strong DPC1.53                                
-       write_cmos_sensor(0x5780, 0x3e); 
-       write_cmos_sensor(0x5781, 0x0f); 
-       write_cmos_sensor(0x5782, 0x44); 
-       write_cmos_sensor(0x5783, 0x02); 
-       write_cmos_sensor(0x5784, 0x01); 
-       write_cmos_sensor(0x5785, 0x00); 
-       write_cmos_sensor(0x5786, 0x00); 
-       write_cmos_sensor(0x5787, 0x04); 
-       write_cmos_sensor(0x5788, 0x02); 
-       write_cmos_sensor(0x5789, 0x0f); 
-       write_cmos_sensor(0x578a, 0xfd); 
-       write_cmos_sensor(0x578b, 0xf5); 
-       write_cmos_sensor(0x578c, 0xf5); 
-       write_cmos_sensor(0x578d, 0x03); 
-       write_cmos_sensor(0x578e, 0x08); 
-       write_cmos_sensor(0x578f, 0x0c); 
-       write_cmos_sensor(0x5790, 0x08); 
-       write_cmos_sensor(0x5791, 0x04); 
-       write_cmos_sensor(0x5792, 0x00); 
-       write_cmos_sensor(0x5793, 0x52); 
-       write_cmos_sensor(0x5794, 0xa3); 
-       //;Ping                                           
-       write_cmos_sensor(0x380e, 0x07); //; fps fine adjustment
-       write_cmos_sensor(0x380f, 0xfd); //; fps fine adjustment
-       write_cmos_sensor(0x3503, 0x00); //; real gain [2]   gain no delay, shutter no delay
-       //;added                                         
+   switch (group_idx)
+   {
+        case PRE_GAIN:
+            sprintf((char *)group_name_ptr, "CCT");
+            *item_count_ptr = 2;
+            break;
+        case CMMCLK_CURRENT:
+            sprintf((char *)group_name_ptr, "CMMCLK Current");
+            *item_count_ptr = 1;
+            break;
+        case FRAME_RATE_LIMITATION:
+            sprintf((char *)group_name_ptr, "Frame Rate Limitation");
+            *item_count_ptr = 2;
+            break;
+        case REGISTER_EDITOR:
+            sprintf((char *)group_name_ptr, "Register Editor");
+            *item_count_ptr = 2;
+            break;
+        default:
+            ASSERT(0);
+}
+}
+
+void OV5670_get_sensor_item_info(kal_uint16 group_idx,kal_uint16 item_idx, MSDK_SENSOR_ITEM_INFO_STRUCT* info_ptr)
+{
+    kal_int16 temp_reg=0;
+    kal_uint16 temp_gain=0, temp_addr=0, temp_para=0;
+
+    switch (group_idx)
+    {
+        case PRE_GAIN:
+           switch (item_idx)
+          {
+              case 0:
+                sprintf((char *)info_ptr->ItemNamePtr,"Pregain-R");
+                  temp_addr = PRE_GAIN_R_INDEX;
+              break;
+              case 1:
+                sprintf((char *)info_ptr->ItemNamePtr,"Pregain-Gr");
+                  temp_addr = PRE_GAIN_Gr_INDEX;
+              break;
+              case 2:
+                sprintf((char *)info_ptr->ItemNamePtr,"Pregain-Gb");
+                  temp_addr = PRE_GAIN_Gb_INDEX;
+              break;
+              case 3:
+                sprintf((char *)info_ptr->ItemNamePtr,"Pregain-B");
+                  temp_addr = PRE_GAIN_B_INDEX;
+              break;
+              case 4:
+                 sprintf((char *)info_ptr->ItemNamePtr,"SENSOR_BASEGAIN");
+                 temp_addr = SENSOR_BASEGAIN;
+              break;
+              default:
+                 ASSERT(0);
+          }
+
+            temp_para= OV5670SensorCCT[temp_addr].Para;
+                       //temp_gain= (temp_para/OV5670.sensorBaseGain) * 1000;
+
+            info_ptr->ItemValue=temp_gain;
+            info_ptr->IsTrueFalse=KAL_FALSE;
+            info_ptr->IsReadOnly=KAL_FALSE;
+            info_ptr->IsNeedRestart=KAL_FALSE;
+            info_ptr->Min= OV5670_MIN_ANALOG_GAIN * 1000;
+            info_ptr->Max= OV5670_MAX_ANALOG_GAIN * 1000;
+            break;
+        case CMMCLK_CURRENT:
+            switch (item_idx)
+            {
+                case 0:
+                    sprintf((char *)info_ptr->ItemNamePtr,"Drv Cur[2,4,6,8]mA");
+
+                    //temp_reg=MT9P017SensorReg[CMMCLK_CURRENT_INDEX].Para;
+                    temp_reg = ISP_DRIVING_2MA;
+                    if(temp_reg==ISP_DRIVING_2MA)
+                    {
+                        info_ptr->ItemValue=2;
+                    }
+                    else if(temp_reg==ISP_DRIVING_4MA)
+                    {
+                        info_ptr->ItemValue=4;
+                    }
+                    else if(temp_reg==ISP_DRIVING_6MA)
+                    {
+                        info_ptr->ItemValue=6;
+                    }
+                    else if(temp_reg==ISP_DRIVING_8MA)
+                    {
+                        info_ptr->ItemValue=8;
+                    }
+
+                    info_ptr->IsTrueFalse=KAL_FALSE;
+                    info_ptr->IsReadOnly=KAL_FALSE;
+                    info_ptr->IsNeedRestart=KAL_TRUE;
+                    info_ptr->Min=2;
+                    info_ptr->Max=8;
+                    break;
+                default:
+                    ASSERT(0);
+            }
+            break;
+        case FRAME_RATE_LIMITATION:
+            switch (item_idx)
+            {
+                case 0:
+                    sprintf((char *)info_ptr->ItemNamePtr,"Max Exposure Lines");
+                    info_ptr->ItemValue=    111;  
+                    info_ptr->IsTrueFalse=KAL_FALSE;
+                    info_ptr->IsReadOnly=KAL_TRUE;
+                    info_ptr->IsNeedRestart=KAL_FALSE;
+                    info_ptr->Min=0;
+                    info_ptr->Max=0;
+                    break;
+                case 1:
+                    sprintf((char *)info_ptr->ItemNamePtr,"Min Frame Rate");
+                    info_ptr->ItemValue=12;
+                    info_ptr->IsTrueFalse=KAL_FALSE;
+                    info_ptr->IsReadOnly=KAL_TRUE;
+                    info_ptr->IsNeedRestart=KAL_FALSE;
+                    info_ptr->Min=0;
+                    info_ptr->Max=0;
+                    break;
+                default:
+                    ASSERT(0);
+            }
+            break;
+        case REGISTER_EDITOR:
+            switch (item_idx)
+            {
+                case 0:
+                    sprintf((char *)info_ptr->ItemNamePtr,"REG Addr.");
+                    info_ptr->ItemValue=0;
+                    info_ptr->IsTrueFalse=KAL_FALSE;
+                    info_ptr->IsReadOnly=KAL_FALSE;
+                    info_ptr->IsNeedRestart=KAL_FALSE;
+                    info_ptr->Min=0;
+                    info_ptr->Max=0xFFFF;
+                    break;
+                case 1:
+                    sprintf((char *)info_ptr->ItemNamePtr,"REG Value");
+                    info_ptr->ItemValue=0;
+                    info_ptr->IsTrueFalse=KAL_FALSE;
+                    info_ptr->IsReadOnly=KAL_FALSE;
+                    info_ptr->IsNeedRestart=KAL_FALSE;
+                    info_ptr->Min=0;
+                    info_ptr->Max=0xFFFF;
+                    break;
+                default:
+                ASSERT(0);
+            }
+            break;
+        default:
+            ASSERT(0);
+    }
+}
+
+
+
+kal_bool OV5670_set_sensor_item_info(kal_uint16 group_idx, kal_uint16 item_idx, kal_int32 ItemValue)
+{
+   kal_uint16  temp_gain=0,temp_addr=0, temp_para=0;
+
+   switch (group_idx)
+    {
+        case PRE_GAIN:
+            switch (item_idx)
+            {
+              case 0:
+                temp_addr = PRE_GAIN_R_INDEX;
+              break;
+              case 1:
+                temp_addr = PRE_GAIN_Gr_INDEX;
+              break;
+              case 2:
+                temp_addr = PRE_GAIN_Gb_INDEX;
+              break;
+              case 3:
+                temp_addr = PRE_GAIN_B_INDEX;
+              break;
+              case 4:
+                temp_addr = SENSOR_BASEGAIN;
+              break;
+              default:
+                 ASSERT(0);
+          }
+
+                temp_gain=((ItemValue*BASEGAIN+500)/1000);                     //+500:get closed integer value
+
+                 if(temp_gain>=1*BASEGAIN && temp_gain<=16*BASEGAIN)
+          {
+//             temp_para=(temp_gain * OV5670.sensorBaseGain + BASEGAIN/2)/BASEGAIN;
+          }
+          else
+                         ASSERT(0);
+
+                 spin_lock(&ov5670mipiraw_drv_lock);
+          OV5670SensorCCT[temp_addr].Para = temp_para;
+                 spin_unlock(&ov5670mipiraw_drv_lock);
+          OV5670_write_cmos_sensor(OV5670SensorCCT[temp_addr].Addr,temp_para);
+
+            break;
+        case CMMCLK_CURRENT:
+            switch (item_idx)
+            {
+                case 0:
+                    //no need to apply this item for driving current
+                    break;
+                default:
+                    ASSERT(0);
+            }
+            break;
+        case FRAME_RATE_LIMITATION:
+            ASSERT(0);
+            break;
+        case REGISTER_EDITOR:
+            switch (item_idx)
+            {
+                case 0:
+                                       spin_lock(&ov5670mipiraw_drv_lock);
+                    OV5670_FAC_SENSOR_REG=ItemValue;
+                                       spin_unlock(&ov5670mipiraw_drv_lock);
+                    break;
+                case 1:
+                    OV5670_write_cmos_sensor(OV5670_FAC_SENSOR_REG,ItemValue);
+                    break;
+                default:
+                    ASSERT(0);
+            }
+            break;
+        default:
+            ASSERT(0);
+    }
+    return KAL_TRUE;
+}
+#endif
+
+
+static void OV5670_SetDummy( const kal_uint32 iPixels, const kal_uint32 iLines )
+{
+       kal_uint32 line_length = 0;
+       kal_uint32 frame_length = 0;
+
+       if ( SENSOR_MODE_PREVIEW == OV5670.sensorMode )
+       {
+               line_length = OV5670_PV_PERIOD_PIXEL_NUMS + iPixels;
+               frame_length = OV5670_PV_PERIOD_LINE_NUMS + iLines;
+       }
+       else if( SENSOR_MODE_VIDEO== OV5670.sensorMode )
+       {
+               line_length = OV5670_VIDEO_PERIOD_PIXEL_NUMS + iPixels;
+               frame_length = OV5670_VIDEO_PERIOD_LINE_NUMS + iLines;
+       }
+       else
+       {
+               line_length = OV5670_FULL_PERIOD_PIXEL_NUMS + iPixels;
+               frame_length = OV5670_FULL_PERIOD_LINE_NUMS + iLines;
+       }
 
-       write_cmos_sensor(0x0100, 0x00); //;01
+       spin_lock(&ov5670mipiraw_drv_lock);
+       OV5670_FeatureControl_PERIOD_PixelNum = line_length;
+       OV5670_FeatureControl_PERIOD_LineNum = frame_length;
+       spin_unlock(&ov5670mipiraw_drv_lock);
 
+       //Set total frame length
+       OV5670_write_cmos_sensor(0x380e, (frame_length >> 8) & 0xFF);
+       OV5670_write_cmos_sensor(0x380f, frame_length & 0xFF);
+       //Set total line length
+       OV5670_write_cmos_sensor(0x380c, (line_length >> 8) & 0xFF);
+       OV5670_write_cmos_sensor(0x380d, line_length & 0xFF);
 
-}      /*      sensor_init  */
+}   
 
 
-static void preview_setting(void)
+void OV5670PreviewSetting(void)
 {
-       LOG_INF(" OV5670PreviewSetting_2lane enter\n");
+       OV5670DB(" OV5670PreviewSetting_2lane enter\n");
+
+       /*  //
+       
+       //@@PV_Quarter_size_30fps_800Mbps/lane                            
+       //99 1296 960                                                                             
+       //;;102 3601    157c                                                                      
+       //;;PCLK=HTS*VTS*fps=0x68c*0x7fd*30=1676*2045*30=102.85M
+
+               OV5670_write_cmos_sensor(0x0100, 0x00);  //
+       
+       OV5670_write_cmos_sensor(0x3501, 0x3d);  //
+       OV5670_write_cmos_sensor(0x366e, 0x08);  //
+       OV5670_write_cmos_sensor(0x370b, 0x1b);  //
+       OV5670_write_cmos_sensor(0x3808, 0x05);  //
+       OV5670_write_cmos_sensor(0x3809, 0x10);  //
+       OV5670_write_cmos_sensor(0x380a, 0x03);  //
+       OV5670_write_cmos_sensor(0x380b, 0xc0);  //
+       OV5670_write_cmos_sensor(0x380c, 0x06);  //
+       OV5670_write_cmos_sensor(0x380d, 0x8c);  //
+       OV5670_write_cmos_sensor(0x380e, 0x07);  //;03
+       OV5670_write_cmos_sensor(0x380f, 0xfd);  //;e0
+       OV5670_write_cmos_sensor(0x3814, 0x03);  //
+       OV5670_write_cmos_sensor(0x3820, 0x90);  //
+       OV5670_write_cmos_sensor(0x3821, 0x47);  //
+       OV5670_write_cmos_sensor(0x382a, 0x03);  //
+       OV5670_write_cmos_sensor(0x4009, 0x05);  //
+       OV5670_write_cmos_sensor(0x4502, 0x48);  //
+       OV5670_write_cmos_sensor(0x4508, 0x55);  //
+       OV5670_write_cmos_sensor(0x4509, 0x55);  //
+       OV5670_write_cmos_sensor(0x4600, 0x00);  //
+       OV5670_write_cmos_sensor(0x4601, 0x81);  //
+       OV5670_write_cmos_sensor(0x4017, 0x10);  //; threshold = 4LSB for Binning sum format.
+       OV5670_write_cmos_sensor(0x400a, 0x02);  //;
+       OV5670_write_cmos_sensor(0x400b, 0x00);  //; 
+       
+       OV5670_write_cmos_sensor(0x0100, 0x01);  //
+*/
 
        //@@PV_Quarter_size_30fps_800Mbps/lane_1296x972                                                   
        //99 1296 972                                                                                                                     
        //;;102 3601    157c                                                                                                              
        //;;PCLK=HTS*VTS*fps=0x68c*0x7fd*30=1676*2045*30=102.85M                                          
                                                                                                                                                          
-       write_cmos_sensor(0x0100, 0x00);  //    
+       OV5670_write_cmos_sensor(0x0100, 0x00);  //     
+       
+       OV5670_write_cmos_sensor(0x3501, 0x73);  //                                                       
+       OV5670_write_cmos_sensor(0x3502, 0x00);  //                                                       
+       OV5670_write_cmos_sensor(0x3508, 0x01);  //                                                       
+       OV5670_write_cmos_sensor(0x3509, 0x80);  //                                                       
+       OV5670_write_cmos_sensor(0x366e, 0x08);  //                                                       
+       OV5670_write_cmos_sensor(0x370b, 0x1b);  //                                                       
+       OV5670_write_cmos_sensor(0x3808, 0x05);  //                                                       
+       OV5670_write_cmos_sensor(0x3809, 0x10);  //                                                       
+       OV5670_write_cmos_sensor(0x380a, 0x03);  //                                                       
+       OV5670_write_cmos_sensor(0x380b, 0xcc);  //;c0                                                    
+       OV5670_write_cmos_sensor(0x380c, 0x06);  //                                                       
+       OV5670_write_cmos_sensor(0x380d, 0x8c);  //                                                       
+       OV5670_write_cmos_sensor(0x380e, 0x07);  //;03                                                    
+       OV5670_write_cmos_sensor(0x380f, 0xfd);  //;e0                                                    
+       OV5670_write_cmos_sensor(0x3814, 0x03);  //                                                       
+       OV5670_write_cmos_sensor(0x3820, 0x90);  //                                                       
+       OV5670_write_cmos_sensor(0x3821, 0x47);  //                                                       
+       OV5670_write_cmos_sensor(0x382a, 0x03);  //                                                       
+       OV5670_write_cmos_sensor(0x3845, 0x02);  //                                                       
+       OV5670_write_cmos_sensor(0x4009, 0x05);  //                                                       
+       OV5670_write_cmos_sensor(0x4502, 0x48);  //                                                       
+       OV5670_write_cmos_sensor(0x4508, 0x55);  //                                                       
+       OV5670_write_cmos_sensor(0x4509, 0x55);  //                                                       
+       OV5670_write_cmos_sensor(0x4600, 0x00);  //                                                       
+       OV5670_write_cmos_sensor(0x4601, 0x81);  //                                                       
+       OV5670_write_cmos_sensor(0x4017, 0x10);  //; threshold = 4LSB for Binning 
+       OV5670_write_cmos_sensor(0x400a, 0x02);  //;                                                      
+       OV5670_write_cmos_sensor(0x400b, 0x00);  //;    
        
-       write_cmos_sensor(0x3501, 0x73);  //                                                      
-       write_cmos_sensor(0x3502, 0x00);  //                                                      
-       write_cmos_sensor(0x3508, 0x03);  //                                                      
-       write_cmos_sensor(0x3509, 0x00);  //    
-       write_cmos_sensor(0x3623, 0x00);        
-       write_cmos_sensor(0x366e, 0x08);  //                                                      
-       write_cmos_sensor(0x370b, 0x1b);  //                                                      
-       write_cmos_sensor(0x3808, 0x05);  //                                                      
-       write_cmos_sensor(0x3809, 0x10);  //                                                      
-       write_cmos_sensor(0x380a, 0x03);  //                                                      
-       write_cmos_sensor(0x380b, 0xcc);  //;c0                                                   
-       write_cmos_sensor(0x380c, 0x06);  //                                                      
-       write_cmos_sensor(0x380d, 0x8c);  //                                                      
-       write_cmos_sensor(0x380e, 0x07);  //;03                                                   
-       write_cmos_sensor(0x380f, 0xfd);  //;e0 
+       OV5670_write_cmos_sensor(0x0100, 0x01);  //     
+}
 
 
-       
-       write_cmos_sensor(0x3814, 0x03);  //                                                      
-       write_cmos_sensor(0x3820, 0x90);  //                                                      
-       write_cmos_sensor(0x3821, 0x47);  //                                                      
-       write_cmos_sensor(0x382a, 0x03);  //    
-       
+void OV5670VideoSetting(void)
+{
+       OV5670DB(" OV5670videoSetting_2lane enter:video/preview sync\n");
+
+       OV5670PreviewSetting();
+}
 
-       write_cmos_sensor(0x3845, 0x02);  //                                                      
-       write_cmos_sensor(0x4009, 0x05);  //                                                      
-       write_cmos_sensor(0x4502, 0x44);  //                                                      
-       write_cmos_sensor(0x4508, 0x55);  //                                                      
-       write_cmos_sensor(0x4509, 0x55);  //    
-       write_cmos_sensor(0x450a, 0x00);  //    
-       write_cmos_sensor(0x4600, 0x00);  //                                                      
-       write_cmos_sensor(0x4601, 0x81);  //                                                      
-       write_cmos_sensor(0x4017, 0x10);  //; threshold = 4LSB for Binning 
-       write_cmos_sensor(0x400a, 0x02);  //;                                                     
-       write_cmos_sensor(0x400b, 0x00);  //;   
-       
-       write_cmos_sensor(0x0100, 0x01);  // 
 
-       
-}      /*      preview_setting  */
 
-static void capture_setting(kal_uint16 currefps)
+void OV5670CaptureSetting(void)
 {
-       LOG_INF("OV5670CaptureSetting_2lane enter! currefps:%d\n",currefps);
-               write_cmos_sensor(0x0100, 0x00); 
-               
-               write_cmos_sensor(0x3501, 0x5f); //long exposure
-               write_cmos_sensor(0x3502, 0xd0);  //long exposure
-               
-               write_cmos_sensor(0x3508, 0x03);  //gain
-               write_cmos_sensor(0x3509, 0x00);  //gain
-
-               write_cmos_sensor(0x3623, 0x00);  //gain
-               write_cmos_sensor(0x366e, 0x10); 
-               write_cmos_sensor(0x370b, 0x1b); 
-               write_cmos_sensor(0x3808, 0x0a); 
-               write_cmos_sensor(0x3809, 0x20); 
-               write_cmos_sensor(0x380a, 0x07); 
-               write_cmos_sensor(0x380b, 0x98); 
-               write_cmos_sensor(0x380c, 0x06); // hts 
-               write_cmos_sensor(0x380d, 0x8c);           // hts
-               write_cmos_sensor(0x380e, 0x07);  // vts 
-               write_cmos_sensor(0x380f, 0xfd);                 // vts 
+       OV5670DB("OV5670CaptureSetting_2lane enter\n");
 
-               
-               write_cmos_sensor(0x3814, 0x01); 
-               write_cmos_sensor(0x3820, 0x80); 
-               write_cmos_sensor(0x3821, 0x46); 
-               write_cmos_sensor(0x382a, 0x01);
-               
-               write_cmos_sensor(0x3845, 0x00);  //v_offset for auto size mode
-               
-               write_cmos_sensor(0x4009, 0x0d); 
-               write_cmos_sensor(0x4502, 0x40); 
-               write_cmos_sensor(0x4508, 0xaa); 
-               write_cmos_sensor(0x4509, 0xaa); 
-               write_cmos_sensor(0x450a, 0x00);  // 
-               write_cmos_sensor(0x4600, 0x01); 
-               write_cmos_sensor(0x4601, 0x03); 
-               write_cmos_sensor(0x4017, 0x08); //threshold= 2LSB for full size
-               write_cmos_sensor(0x400a, 0x02); //
-               write_cmos_sensor(0x400b, 0x00); //
-               
-               write_cmos_sensor(0x0100, 0x01);
-               
+       OV5670_write_cmos_sensor(0x0100, 0x00); 
+       
+       OV5670_write_cmos_sensor(0x3501, 0x5f); //long exposure
+       OV5670_write_cmos_sensor(0x3502, 0xd0);  //long exposure
+       
+       OV5670_write_cmos_sensor(0x3508, 0x03);  //gain
+       OV5670_write_cmos_sensor(0x3509, 0x00);  //gain
+       
+       OV5670_write_cmos_sensor(0x366e, 0x10); 
+       OV5670_write_cmos_sensor(0x370b, 0x1b); 
+       OV5670_write_cmos_sensor(0x3808, 0x0a); 
+       OV5670_write_cmos_sensor(0x3809, 0x20); 
+       OV5670_write_cmos_sensor(0x380a, 0x07); 
+       OV5670_write_cmos_sensor(0x380b, 0x98); 
+       OV5670_write_cmos_sensor(0x380c, 0x07); //;06
+       OV5670_write_cmos_sensor(0x380d, 0xdc); //;8c
+       OV5670_write_cmos_sensor(0x380e, 0x07); 
+       OV5670_write_cmos_sensor(0x380f, 0xfd); 
+       OV5670_write_cmos_sensor(0x3814, 0x01); 
+       OV5670_write_cmos_sensor(0x3820, 0x80); 
+       OV5670_write_cmos_sensor(0x3821, 0x46); 
+       OV5670_write_cmos_sensor(0x382a, 0x01);
+       
+       OV5670_write_cmos_sensor(0x3845, 0x00);  //v_offset for auto size mode
+       
+       OV5670_write_cmos_sensor(0x4009, 0x0d); 
+       OV5670_write_cmos_sensor(0x4502, 0x40); 
+       OV5670_write_cmos_sensor(0x4508, 0xaa); 
+       OV5670_write_cmos_sensor(0x4509, 0xaa); 
+       OV5670_write_cmos_sensor(0x4600, 0x01); 
+       OV5670_write_cmos_sensor(0x4601, 0x03); 
+       OV5670_write_cmos_sensor(0x4017, 0x08); //threshold= 2LSB for full size
+       OV5670_write_cmos_sensor(0x400a, 0x02); //
+       OV5670_write_cmos_sensor(0x400b, 0x00); //
+       
+       OV5670_write_cmos_sensor(0x0100, 0x01); 
        
-               
 }
 
-static void normal_video_setting(kal_uint16 currefps)
+
+static void OV5670_Sensor_Init(void)
 {
-       LOG_INF("normal_video_setting Enter! currefps:%d\n",currefps);
+       OV5670DB("OV5670_Sensor_Init_2lane enter\n");
        
-               //@@PV_Quarter_size_30fps_800Mbps/lane_1296x972                                                   
-       //99 1296 972                                                                                                                     
-       //;;102 3601    157c                                                                                                              
-       //;;PCLK=HTS*VTS*fps=0x68c*0x7fd*30=1676*2045*30=102.85M                                          
-                                                                                                                                                         
-       write_cmos_sensor(0x0100, 0x00);  //    
+       OV5670_write_cmos_sensor(0x0103,0x01);// ; software reset
+       mdelay(10);
+       OV5670_write_cmos_sensor(0x0100, 0x00);// ; software standby
+       OV5670_write_cmos_sensor(0x0100, 0x00); 
+       OV5670_write_cmos_sensor(0x0300, 0x04); 
+       OV5670_write_cmos_sensor(0x0301, 0x00); 
+       OV5670_write_cmos_sensor(0x0302, 0x64); //;78
+       OV5670_write_cmos_sensor(0x0303, 0x00); 
+       OV5670_write_cmos_sensor(0x0304, 0x03); 
+       OV5670_write_cmos_sensor(0x0305, 0x01); 
+       OV5670_write_cmos_sensor(0x0306, 0x01); 
+       OV5670_write_cmos_sensor(0x030a, 0x00); 
+       OV5670_write_cmos_sensor(0x030b, 0x00); 
+       OV5670_write_cmos_sensor(0x030c, 0x00); 
+       OV5670_write_cmos_sensor(0x030d, 0x1e); 
+       OV5670_write_cmos_sensor(0x030e, 0x00); 
+       OV5670_write_cmos_sensor(0x030f, 0x06); 
+       OV5670_write_cmos_sensor(0x0312, 0x01); 
+       OV5670_write_cmos_sensor(0x3000, 0x00); 
+       OV5670_write_cmos_sensor(0x3002, 0x21); 
+       OV5670_write_cmos_sensor(0x3005, 0xf0); 
+       OV5670_write_cmos_sensor(0x3007, 0x00); 
+       OV5670_write_cmos_sensor(0x3015, 0x0f); 
+       OV5670_write_cmos_sensor(0x3018, 0x32); 
+       OV5670_write_cmos_sensor(0x301a, 0xf0); 
+       OV5670_write_cmos_sensor(0x301b, 0xf0); 
+       OV5670_write_cmos_sensor(0x301c, 0xf0); 
+       OV5670_write_cmos_sensor(0x301d, 0xf0); 
+       OV5670_write_cmos_sensor(0x301e, 0xf0); 
+       OV5670_write_cmos_sensor(0x3030, 0x00); 
+       OV5670_write_cmos_sensor(0x3031, 0x0a); 
+       OV5670_write_cmos_sensor(0x303c, 0xff); 
+       OV5670_write_cmos_sensor(0x303e, 0xff); 
+       OV5670_write_cmos_sensor(0x3040, 0xf0); 
+       OV5670_write_cmos_sensor(0x3041, 0x00); 
+       OV5670_write_cmos_sensor(0x3042, 0xf0); 
+       OV5670_write_cmos_sensor(0x3106, 0x11); 
+       OV5670_write_cmos_sensor(0x3500, 0x00); 
+       OV5670_write_cmos_sensor(0x3501, 0x7b); 
+       OV5670_write_cmos_sensor(0x3502, 0x00); 
+       OV5670_write_cmos_sensor(0x3503, 0x04); 
+       OV5670_write_cmos_sensor(0x3504, 0x03); 
+       OV5670_write_cmos_sensor(0x3505, 0x83); 
+       OV5670_write_cmos_sensor(0x3508, 0x07); 
+       OV5670_write_cmos_sensor(0x3509, 0x80); 
+       OV5670_write_cmos_sensor(0x350e, 0x04); 
+       OV5670_write_cmos_sensor(0x350f, 0x00); 
+       OV5670_write_cmos_sensor(0x3510, 0x00); 
+       OV5670_write_cmos_sensor(0x3511, 0x02); 
+       OV5670_write_cmos_sensor(0x3512, 0x00); 
+       OV5670_write_cmos_sensor(0x3601, 0xc8); 
+       OV5670_write_cmos_sensor(0x3610, 0x88); 
+       OV5670_write_cmos_sensor(0x3612, 0x48); 
+       OV5670_write_cmos_sensor(0x3614, 0x5b); 
+       OV5670_write_cmos_sensor(0x3615, 0x96); 
+       OV5670_write_cmos_sensor(0x3621, 0xd0); 
+       OV5670_write_cmos_sensor(0x3622, 0x00); 
+       OV5670_write_cmos_sensor(0x3623, 0x00); 
+       OV5670_write_cmos_sensor(0x3633, 0x13); 
+       OV5670_write_cmos_sensor(0x3634, 0x13); 
+       OV5670_write_cmos_sensor(0x3635, 0x13); 
+       OV5670_write_cmos_sensor(0x3636, 0x13); 
+       OV5670_write_cmos_sensor(0x3645, 0x13); 
+       OV5670_write_cmos_sensor(0x3646, 0x82); 
+       OV5670_write_cmos_sensor(0x3650, 0x00); 
+       OV5670_write_cmos_sensor(0x3652, 0xff); 
+       OV5670_write_cmos_sensor(0x3655, 0x20); 
+       OV5670_write_cmos_sensor(0x3656, 0xff); 
+       OV5670_write_cmos_sensor(0x365a, 0xff); 
+       OV5670_write_cmos_sensor(0x365e, 0xff); 
+       OV5670_write_cmos_sensor(0x3668, 0x00); 
+       OV5670_write_cmos_sensor(0x366a, 0x07); 
+       OV5670_write_cmos_sensor(0x366e, 0x10); 
+       OV5670_write_cmos_sensor(0x366d, 0x00); 
+       OV5670_write_cmos_sensor(0x366f, 0x80); 
+       OV5670_write_cmos_sensor(0x3700, 0x28); 
+       OV5670_write_cmos_sensor(0x3701, 0x10); 
+       OV5670_write_cmos_sensor(0x3702, 0x3a); 
+       OV5670_write_cmos_sensor(0x3703, 0x19); 
+       OV5670_write_cmos_sensor(0x3704, 0x10);
+       OV5670_write_cmos_sensor(0x3705, 0x00); 
+       OV5670_write_cmos_sensor(0x3706, 0x66); 
+       OV5670_write_cmos_sensor(0x3707, 0x08); 
+       OV5670_write_cmos_sensor(0x3708, 0x34); 
+       OV5670_write_cmos_sensor(0x3709, 0x40); 
+       OV5670_write_cmos_sensor(0x370a, 0x01); 
+       OV5670_write_cmos_sensor(0x370b, 0x1b); 
+       OV5670_write_cmos_sensor(0x3714, 0x24); 
+       OV5670_write_cmos_sensor(0x371a, 0x3e); 
+       OV5670_write_cmos_sensor(0x3733, 0x00); 
+       OV5670_write_cmos_sensor(0x3734, 0x00); 
+       OV5670_write_cmos_sensor(0x373a, 0x05); 
+       OV5670_write_cmos_sensor(0x373b, 0x06); 
+       OV5670_write_cmos_sensor(0x373c, 0x0a); 
+       OV5670_write_cmos_sensor(0x373f, 0xa0); 
+       OV5670_write_cmos_sensor(0x3755, 0x00); 
+       OV5670_write_cmos_sensor(0x3758, 0x00); 
+       OV5670_write_cmos_sensor(0x375b, 0x0e);
+       OV5670_write_cmos_sensor(0x3766, 0x5f); 
+       OV5670_write_cmos_sensor(0x3768, 0x00); 
+       OV5670_write_cmos_sensor(0x3769, 0x22); 
+       OV5670_write_cmos_sensor(0x3773, 0x08); 
+       OV5670_write_cmos_sensor(0x3774, 0x1f); 
+       OV5670_write_cmos_sensor(0x3776, 0x06); 
+       OV5670_write_cmos_sensor(0x37a0, 0x88); 
+       OV5670_write_cmos_sensor(0x37a1, 0x5c); 
+       OV5670_write_cmos_sensor(0x37a7, 0x88); 
+       OV5670_write_cmos_sensor(0x37a8, 0x70); 
+       OV5670_write_cmos_sensor(0x37aa, 0x88); 
+       OV5670_write_cmos_sensor(0x37ab, 0x48); 
+       OV5670_write_cmos_sensor(0x37b3, 0x66); 
+       OV5670_write_cmos_sensor(0x37c2, 0x04); 
+       OV5670_write_cmos_sensor(0x37c5, 0x00); 
+       OV5670_write_cmos_sensor(0x37c8, 0x00); 
+       OV5670_write_cmos_sensor(0x3800, 0x00); 
+       OV5670_write_cmos_sensor(0x3801, 0x0c); 
+       OV5670_write_cmos_sensor(0x3802, 0x00); 
+       OV5670_write_cmos_sensor(0x3803, 0x04); 
+       OV5670_write_cmos_sensor(0x3804, 0x0a); 
+       OV5670_write_cmos_sensor(0x3805, 0x33); 
+       OV5670_write_cmos_sensor(0x3806, 0x07); 
+       OV5670_write_cmos_sensor(0x3807, 0xa3); 
+       OV5670_write_cmos_sensor(0x3808, 0x0a); 
+       OV5670_write_cmos_sensor(0x3809, 0x20); 
+       OV5670_write_cmos_sensor(0x380a, 0x07); 
+       OV5670_write_cmos_sensor(0x380b, 0x98); 
+       OV5670_write_cmos_sensor(0x380c, 0x07); // ;06
+       OV5670_write_cmos_sensor(0x380d, 0xdc); // ;8c
+       OV5670_write_cmos_sensor(0x380e, 0x07); 
+       OV5670_write_cmos_sensor(0x380f, 0xb8); 
+       OV5670_write_cmos_sensor(0x3811, 0x04); 
+       OV5670_write_cmos_sensor(0x3813, 0x02); 
+       OV5670_write_cmos_sensor(0x3814, 0x01); 
+       OV5670_write_cmos_sensor(0x3815, 0x01); 
+       OV5670_write_cmos_sensor(0x3816, 0x00); 
+       OV5670_write_cmos_sensor(0x3817, 0x00); 
+       OV5670_write_cmos_sensor(0x3818, 0x00); 
+       OV5670_write_cmos_sensor(0x3819, 0x00); 
+       OV5670_write_cmos_sensor(0x3820, 0x80); 
+       OV5670_write_cmos_sensor(0x3821, 0x46); 
+       OV5670_write_cmos_sensor(0x3822, 0x48); 
+       OV5670_write_cmos_sensor(0x3826, 0x00); 
+       OV5670_write_cmos_sensor(0x3827, 0x08); 
+       OV5670_write_cmos_sensor(0x382a, 0x01); 
+       OV5670_write_cmos_sensor(0x382b, 0x01); 
+       OV5670_write_cmos_sensor(0x3830, 0x08); 
+       OV5670_write_cmos_sensor(0x3836, 0x02); 
+       OV5670_write_cmos_sensor(0x3837, 0x00); 
+       OV5670_write_cmos_sensor(0x3838, 0x10); 
+       OV5670_write_cmos_sensor(0x3841, 0xff); 
+       OV5670_write_cmos_sensor(0x3846, 0x48); 
+       OV5670_write_cmos_sensor(0x3861, 0x00); 
+       OV5670_write_cmos_sensor(0x3862, 0x04);//x00); 
+       OV5670_write_cmos_sensor(0x3863, 0x06);//0x18); 
+       OV5670_write_cmos_sensor(0x3a11, 0x01); 
+       OV5670_write_cmos_sensor(0x3a12, 0x78); 
+       OV5670_write_cmos_sensor(0x3b00, 0x00); 
+       OV5670_write_cmos_sensor(0x3b02, 0x00); 
+       OV5670_write_cmos_sensor(0x3b03, 0x00); 
+       OV5670_write_cmos_sensor(0x3b04, 0x00); 
+       OV5670_write_cmos_sensor(0x3b05, 0x00); 
+       OV5670_write_cmos_sensor(0x3c00, 0x89); 
+       OV5670_write_cmos_sensor(0x3c01, 0xab); 
+       OV5670_write_cmos_sensor(0x3c02, 0x01); 
+       OV5670_write_cmos_sensor(0x3c03, 0x00); 
+       OV5670_write_cmos_sensor(0x3c04, 0x00); 
+       OV5670_write_cmos_sensor(0x3c05, 0x03); 
+       OV5670_write_cmos_sensor(0x3c06, 0x00); 
+       OV5670_write_cmos_sensor(0x3c07, 0x05); 
+       OV5670_write_cmos_sensor(0x3c0c, 0x00); 
+       OV5670_write_cmos_sensor(0x3c0d, 0x00); 
+       OV5670_write_cmos_sensor(0x3c0e, 0x00); 
+       OV5670_write_cmos_sensor(0x3c0f, 0x00); 
+       OV5670_write_cmos_sensor(0x3c40, 0x00); 
+       OV5670_write_cmos_sensor(0x3c41, 0xa3); 
+       OV5670_write_cmos_sensor(0x3c43, 0x7d); 
+       OV5670_write_cmos_sensor(0x3c45, 0xd7); 
+       OV5670_write_cmos_sensor(0x3c47, 0xfc); 
+       OV5670_write_cmos_sensor(0x3c50, 0x05); 
+       OV5670_write_cmos_sensor(0x3c52, 0xaa); 
+       OV5670_write_cmos_sensor(0x3c54, 0x71); 
+       OV5670_write_cmos_sensor(0x3c56, 0x80); 
+       OV5670_write_cmos_sensor(0x3d85, 0x17); 
+       OV5670_write_cmos_sensor(0x3f03, 0x00); 
+       OV5670_write_cmos_sensor(0x3f0a, 0x00); 
+       OV5670_write_cmos_sensor(0x3f0b, 0x00); 
+       OV5670_write_cmos_sensor(0x4001, 0x60); 
+       OV5670_write_cmos_sensor(0x4009, 0x0d); 
+       OV5670_write_cmos_sensor(0x4020, 0x00); 
+       OV5670_write_cmos_sensor(0x4021, 0x00); 
+       OV5670_write_cmos_sensor(0x4022, 0x00); 
+       OV5670_write_cmos_sensor(0x4023, 0x00); 
+       OV5670_write_cmos_sensor(0x4024, 0x00); 
+       OV5670_write_cmos_sensor(0x4025, 0x00); 
+       OV5670_write_cmos_sensor(0x4026, 0x00); 
+       OV5670_write_cmos_sensor(0x4027, 0x00); 
+       OV5670_write_cmos_sensor(0x4028, 0x00); 
+       OV5670_write_cmos_sensor(0x4029, 0x00); 
+       OV5670_write_cmos_sensor(0x402a, 0x00); 
+       OV5670_write_cmos_sensor(0x402b, 0x00); 
+       OV5670_write_cmos_sensor(0x402c, 0x00); 
+       OV5670_write_cmos_sensor(0x402d, 0x00); 
+       OV5670_write_cmos_sensor(0x402e, 0x00); 
+       OV5670_write_cmos_sensor(0x402f, 0x00); 
+       OV5670_write_cmos_sensor(0x4040, 0x00); 
+       OV5670_write_cmos_sensor(0x4041, 0x03);//0x00); 
+       OV5670_write_cmos_sensor(0x4042, 0x00); 
+       OV5670_write_cmos_sensor(0x4043, 0x7a);//0x80); 
+       OV5670_write_cmos_sensor(0x4044, 0x00); 
+       OV5670_write_cmos_sensor(0x4045, 0x7a);//0x80); 
+       OV5670_write_cmos_sensor(0x4046, 0x00); 
+       OV5670_write_cmos_sensor(0x4047, 0x7a);//0x80); 
+       OV5670_write_cmos_sensor(0x4048, 0x00); 
+       OV5670_write_cmos_sensor(0x4049, 0x7a);//0x80); 
+       OV5670_write_cmos_sensor(0x4303, 0x00); 
+       OV5670_write_cmos_sensor(0x4307, 0x30); 
+       OV5670_write_cmos_sensor(0x4500, 0x58); 
+       OV5670_write_cmos_sensor(0x4501, 0x04); 
+       OV5670_write_cmos_sensor(0x4502, 0x40); 
+       OV5670_write_cmos_sensor(0x4503, 0x10); 
+       OV5670_write_cmos_sensor(0x4508, 0xaa); 
+       OV5670_write_cmos_sensor(0x4509, 0xaa); 
+       OV5670_write_cmos_sensor(0x450a, 0x00); 
+       OV5670_write_cmos_sensor(0x450b, 0x00); 
+       OV5670_write_cmos_sensor(0x4600, 0x01); 
+       OV5670_write_cmos_sensor(0x4601, 0x03); 
+       OV5670_write_cmos_sensor(0x4700, 0xa4); 
+       OV5670_write_cmos_sensor(0x4800, 0x4c); 
+       OV5670_write_cmos_sensor(0x4816, 0x53); 
+       OV5670_write_cmos_sensor(0x481f, 0x40); 
+       OV5670_write_cmos_sensor(0x4837, 0x14); // ;11
+       OV5670_write_cmos_sensor(0x5000, 0x56);//0x16); 
+       OV5670_write_cmos_sensor(0x5001, 0x01); 
+       OV5670_write_cmos_sensor(0x5002, 0x28);//0xa8); 
+       OV5670_write_cmos_sensor(0x5004, 0x0c); 
+       OV5670_write_cmos_sensor(0x5006, 0x0c); 
+       OV5670_write_cmos_sensor(0x5007, 0xe0); 
+       OV5670_write_cmos_sensor(0x5008, 0x01); 
+       OV5670_write_cmos_sensor(0x5009, 0xb0); 
+       OV5670_write_cmos_sensor(0x5901, 0x00); 
+       OV5670_write_cmos_sensor(0x5a01, 0x00); 
+       OV5670_write_cmos_sensor(0x5a03, 0x00); 
+       OV5670_write_cmos_sensor(0x5a04, 0x0c); 
+       OV5670_write_cmos_sensor(0x5a05, 0xe0); 
+       OV5670_write_cmos_sensor(0x5a06, 0x09); 
+       OV5670_write_cmos_sensor(0x5a07, 0xb0); 
+       OV5670_write_cmos_sensor(0x5a08, 0x06); 
+       OV5670_write_cmos_sensor(0x5e00, 0x00); 
+       //for BLC
+       OV5670_write_cmos_sensor(0x3734, 0x40); 
+       OV5670_write_cmos_sensor(0x5b00, 0x01); 
+       OV5670_write_cmos_sensor(0x5b01, 0x10); 
+       OV5670_write_cmos_sensor(0x5b02, 0x01); 
+       OV5670_write_cmos_sensor(0x5b03, 0xdb); 
+       OV5670_write_cmos_sensor(0x3d8c, 0x71);
+       OV5670_write_cmos_sensor(0x3d8d, 0xea);
+       OV5670_write_cmos_sensor(0x4017, 0x08);
        
-       write_cmos_sensor(0x3501, 0x73);  //                                                      
-       write_cmos_sensor(0x3502, 0x00);  //                                                      
-       write_cmos_sensor(0x3508, 0x01);  //                                                      
-       write_cmos_sensor(0x3509, 0x80);  // 
-       write_cmos_sensor(0x3623, 0x00);  //gain
-       write_cmos_sensor(0x366e, 0x08);  //                                                      
-       write_cmos_sensor(0x370b, 0x1b);  //                                                      
-       write_cmos_sensor(0x3808, 0x05);  //                                                      
-       write_cmos_sensor(0x3809, 0x10);  //                                                      
-       write_cmos_sensor(0x380a, 0x03);  //                                                      
-       write_cmos_sensor(0x380b, 0xcc);  //;c0                                                   
-       write_cmos_sensor(0x380c, ((imgsensor_info.normal_video.linelength >> 8) & 0xFF)); // hts
-       write_cmos_sensor(0x380d, (imgsensor_info.normal_video.linelength & 0xFF));        // hts
-       write_cmos_sensor(0x380e, ((imgsensor_info.normal_video.framelength >> 8) & 0xFF));  // vts 
-       write_cmos_sensor(0x380f, (imgsensor_info.normal_video.framelength & 0xFF));             // vts                                                   
-       write_cmos_sensor(0x3814, 0x03);  //                                                      
-       write_cmos_sensor(0x3820, 0x90);  //                                                      
-       write_cmos_sensor(0x3821, 0x47);  //                                                      
-       write_cmos_sensor(0x382a, 0x03);  //                                                      
-       write_cmos_sensor(0x3845, 0x02);  //                                                      
-       write_cmos_sensor(0x4009, 0x05);  //                                                      
-       write_cmos_sensor(0x4502, 0x44);  //                                                      
-       write_cmos_sensor(0x4508, 0x55);  //                                                      
-       write_cmos_sensor(0x4509, 0x55);  // 
-       write_cmos_sensor(0x450a, 0x00);  // 
-       write_cmos_sensor(0x4600, 0x00);  //                                                      
-       write_cmos_sensor(0x4601, 0x81);  //                                                      
-       write_cmos_sensor(0x4017, 0x10);  //; threshold = 4LSB for Binning 
-       write_cmos_sensor(0x400a, 0x02);  //;                                                     
-       write_cmos_sensor(0x400b, 0x00);  //;   
-       
-       write_cmos_sensor(0x0100, 0x01);  //    
+       OV5670_write_cmos_sensor(0x3618, 0x2a); 
+                                                                  
+       //;Ally031414                                     
+       OV5670_write_cmos_sensor(0x3734, 0x40); //      ;; Improve HFPN
+       OV5670_write_cmos_sensor(0x5b00, 0x01);  // ;; [2:0] otp start addr[10:8]
+       OV5670_write_cmos_sensor(0x5b01, 0x10);  // ;; [7:0] otp start addr[7:0]
+       OV5670_write_cmos_sensor(0x5b02, 0x01);  // ;; [2:0] otp end addr[10:8]
+       OV5670_write_cmos_sensor(0x5b03, 0xDB);  // ;; [7:0] otp end addr[7:0]
+       OV5670_write_cmos_sensor(0x3d8c, 0x71); //; Header address high byte
+       OV5670_write_cmos_sensor(0x3d8d, 0xEA); //; Header address low byte
+       OV5670_write_cmos_sensor(0x4017, 0x08); // ; threshold= 2LSB for full size
+                                                                 
+       //;Strong DPC1.53                                
+       OV5670_write_cmos_sensor(0x5780, 0x3e); 
+       OV5670_write_cmos_sensor(0x5781, 0x0f); 
+       OV5670_write_cmos_sensor(0x5782, 0x44); 
+       OV5670_write_cmos_sensor(0x5783, 0x02); 
+       OV5670_write_cmos_sensor(0x5784, 0x01); 
+       OV5670_write_cmos_sensor(0x5785, 0x00); 
+       OV5670_write_cmos_sensor(0x5786, 0x00); 
+       OV5670_write_cmos_sensor(0x5787, 0x04); 
+       OV5670_write_cmos_sensor(0x5788, 0x02); 
+       OV5670_write_cmos_sensor(0x5789, 0x0f); 
+       OV5670_write_cmos_sensor(0x578a, 0xfd); 
+       OV5670_write_cmos_sensor(0x578b, 0xf5); 
+       OV5670_write_cmos_sensor(0x578c, 0xf5); 
+       OV5670_write_cmos_sensor(0x578d, 0x03); 
+       OV5670_write_cmos_sensor(0x578e, 0x08); 
+       OV5670_write_cmos_sensor(0x578f, 0x0c); 
+       OV5670_write_cmos_sensor(0x5790, 0x08); 
+       OV5670_write_cmos_sensor(0x5791, 0x04); 
+       OV5670_write_cmos_sensor(0x5792, 0x00); 
+       OV5670_write_cmos_sensor(0x5793, 0x52); 
+       OV5670_write_cmos_sensor(0x5794, 0xa3); 
+       //;Ping                                           
+       OV5670_write_cmos_sensor(0x380e, 0x07); //; fps fine adjustment
+       OV5670_write_cmos_sensor(0x380f, 0xfd); //; fps fine adjustment
+       OV5670_write_cmos_sensor(0x3503, 0x00); //; real gain [2]   gain no delay, shutter no delay
+       //;added                                         
+       OV5670_write_cmos_sensor(0x3d85, 0x17); 
+       OV5670_write_cmos_sensor(0x3655, 0x20); 
+                                                                  
+       OV5670_write_cmos_sensor(0x0100, 0x01); //;01
+
+  ov5670_otp_config();
 }
 
-       
 
+UINT32 OV5670Open(void)
+{
 
+       volatile signed int i;
+       kal_uint16 sensor_id = 0;
 
+       OV5670DB("OV5670 Open enter :\n ");
+       OV5670_write_cmos_sensor(0x0103,0x01);// Reset sensor
+  mdelay(2);
 
+       for(i=0;i<2;i++)
+       {
+               sensor_id = (OV5670_read_cmos_sensor(0x300B)<<8)|OV5670_read_cmos_sensor(0x300C);
+               OV5670DB("OV5670 READ ID :%x",sensor_id);
+               if(sensor_id != OV5670MIPI_SENSOR_ID)
+               {
+                       return ERROR_SENSOR_CONNECT_FAIL;
+               }else
+                       break;
+       }
+       
+       OV5670_Sensor_Init();
+  OV5670_Init_Para();
+       OV5670DB("OV5670Open exit :\n ");
 
+ return ERROR_NONE;
+}
 
-/*************************************************************************
-* FUNCTION
-*      get_imgsensor_id
-*
-* DESCRIPTION
-*      This function get the sensor ID 
-*
-* PARAMETERS
-*      *sensorID : return the sensor ID 
-*
-* RETURNS
-*      None
-*
-* GLOBALS AFFECTED
-*
-*************************************************************************/
-static kal_uint32 get_imgsensor_id(UINT32 *sensor_id) 
+void OV5670GetModuleID(void)
 {
-       kal_uint8 i = 0;
-       kal_uint8 retry = 5;
-       //sensor have two i2c address 0x6c 0x6d & 0x21 0x20, we should detect the module used i2c address
-       while (imgsensor_info.i2c_addr_table[i] != 0xff) {
-               spin_lock(&imgsensor_drv_lock);
-               imgsensor.i2c_write_id = imgsensor_info.i2c_addr_table[i];
-               spin_unlock(&imgsensor_drv_lock);
-               do {
-                       *sensor_id = ((read_cmos_sensor(0x300B) << 8) | read_cmos_sensor(0x300C));
-                       if (*sensor_id == imgsensor_info.sensor_id) {                           
-                               printk("alphaxiang i2c write id: 0x%x, sensor id: 0x%x\n", imgsensor.i2c_write_id,*sensor_id);    
-                               return ERROR_NONE;
-                       }       
-                       LOG_INF("Read sensor id fail, id: 0x%x\n", imgsensor.i2c_write_id,*sensor_id);
-                       retry--;
-               } while(retry > 0);
-               i++;
-               retry = 2;
+       struct otp_struct otp_info ; 
+       
+       OV5670_write_cmos_sensor(0x0100, 0x01); //stream on
+       read_otp(&otp_info);
+       OV5670_write_cmos_sensor(0x0100, 0x00); //stream off
+}
+
+UINT32 OV5670GetSensorID(UINT32 *sensorID)
+{
+    int  retry = 2;
+
+       OV5670DB("OV5670GetSensorID enter :\n ");
+    mdelay(5);
+
+    do {
+        *sensorID = (OV5670_read_cmos_sensor(0x300B)<<8)|OV5670_read_cmos_sensor(0x300C);
+        if (*sensorID == OV5670MIPI_SENSOR_ID)
+       {
+               OV5670DB("Sensor ID = 0x%04x\n", *sensorID);
+               OV5670GetModuleID();
+               break;
        }
-       if (*sensor_id != imgsensor_info.sensor_id) {
-               // if Sensor ID is not correct, Must set *sensor_id to 0xFFFFFFFF 
-               *sensor_id = 0xFFFFFFFF;
+       OV5670DB("Read Sensor ID Fail = 0x%04x\n", *sensorID);
+        retry--;
+    } while (retry > 0);
+
+    if (*sensorID != OV5670MIPI_SENSOR_ID) {
+               OV5670DB("Read Sensor ID Fail = 0x%04x\n", *sensorID);
+
+               *sensorID = 0xFFFFFFFF;
                return ERROR_SENSOR_CONNECT_FAIL;
-       }
-       return ERROR_NONE;
+    } else {
+               OV5670DB("alexadd %s module_id=%d", __func__, module_id);
+               if (module_id == 0x0c ||module_id != 0x44) return ERROR_NONE;
+    }
+
+    *sensorID = 0xFFFFFFFF;
+    return ERROR_SENSOR_CONNECT_FAIL;
 }
 
 
-/*************************************************************************
-* FUNCTION
-*      open
-*
-* DESCRIPTION
-*      This function initialize the registers of CMOS sensor
-*
-* PARAMETERS
-*      None
-*
-* RETURNS
-*      None
-*
-* GLOBALS AFFECTED
-*
-*************************************************************************/
-static kal_uint32 open(void)
+void OV5670_SetShutter(kal_uint32 iShutter)
 {
-       //const kal_uint8 i2c_addr[] = {IMGSENSOR_WRITE_ID_1, IMGSENSOR_WRITE_ID_2};
-       kal_uint8 i = 0;
-       kal_uint8 retry = 2;
-       kal_uint16 sensor_id = 0; 
-       LOG_INF("preview 1280*960@30fps,864Mbps/lane; video 1280*960@30fps,864Mbps/lane; capture 5M@30fps,864Mbps/lane\n");
-       
-       //sensor have two i2c address 0x6c 0x6d & 0x21 0x20, we should detect the module used i2c address
-       while (imgsensor_info.i2c_addr_table[i] != 0xff) {
-               spin_lock(&imgsensor_drv_lock);
-               imgsensor.i2c_write_id = imgsensor_info.i2c_addr_table[i];
-               spin_unlock(&imgsensor_drv_lock);
-               do {
-                       sensor_id = ((read_cmos_sensor(0x300B) << 8) | read_cmos_sensor(0x300C));
-                       if (sensor_id == imgsensor_info.sensor_id) {                            
-                               LOG_INF("i2c write id: 0x%x, sensor id: 0x%x\n", imgsensor.i2c_write_id,sensor_id);       
-                               break;
-                       }       
-                       LOG_INF("Read sensor id fail, id: 0x%x\n", imgsensor.i2c_write_id,sensor_id);
-                       retry--;
-               } while(retry > 0);
-               i++;
-               if (sensor_id == imgsensor_info.sensor_id)
-                       break;
-               retry = 2;
-       }                
-       if (imgsensor_info.sensor_id != sensor_id)
-               return ERROR_SENSOR_CONNECT_FAIL;
-       
-       /* initail sequence write in  */
-       sensor_init();
-
-       spin_lock(&imgsensor_drv_lock);
-
-       imgsensor.autoflicker_en= KAL_FALSE;
-       imgsensor.sensor_mode = IMGSENSOR_MODE_INIT;
-       imgsensor.shutter = 0x4C00;
-       imgsensor.gain = 0x0200;
-       imgsensor.pclk = imgsensor_info.pre.pclk;
-       imgsensor.frame_length = imgsensor_info.pre.framelength;
-       imgsensor.line_length = imgsensor_info.pre.linelength;
-       imgsensor.min_frame_length = imgsensor_info.pre.framelength;
-       imgsensor.dummy_pixel = 0;
-       imgsensor.dummy_line = 0;
-       imgsensor.ihdr_en = 0;
-       imgsensor.test_pattern = KAL_FALSE;
-       imgsensor.current_fps = imgsensor_info.pre.max_framerate;
-       spin_unlock(&imgsensor_drv_lock);
 
-       return ERROR_NONE;
-}      /*      open  */
+   spin_lock(&ov5670mipiraw_drv_lock);
+   OV5670.shutter= iShutter;
+   spin_unlock(&ov5670mipiraw_drv_lock);
 
+   OV5670_write_shutter(iShutter);
+   return;
+}
 
 
-/*************************************************************************
-* FUNCTION
-*      close
-*
-* DESCRIPTION
-*      
-*
-* PARAMETERS
-*      None
-*
-* RETURNS
-*      None
-*
-* GLOBALS AFFECTED
-*
-*************************************************************************/
-static kal_uint32 close(void)
+
+UINT32 OV5670_read_shutter(void)
 {
-       LOG_INF("E\n");
 
-       /*No Need to implement this function*/ 
+       kal_uint16 temp_reg1, temp_reg2 ,temp_reg3;
+       UINT32 shutter =0;
+       temp_reg1 = OV5670_read_cmos_sensor(0x3500);    // AEC[b19~b16]
+       temp_reg2 = OV5670_read_cmos_sensor(0x3501);    // AEC[b15~b8]
+       temp_reg3 = OV5670_read_cmos_sensor(0x3502);    // AEC[b7~b0]
        
-       return ERROR_NONE;
-}      /*      close  */
+       shutter  = (temp_reg1 <<12)| (temp_reg2<<4)|(temp_reg3>>4);
 
+       return shutter;
+}
 
-/*************************************************************************
-* FUNCTION
-* preview
-*
-* DESCRIPTION
-*      This function start the sensor preview.
-*
-* PARAMETERS
-*      *image_window : address pointer of pixel numbers in one period of HSYNC
-*  *sensor_config_data : address pointer of line numbers in one period of VSYNC
-*
-* RETURNS
-*      None
-*
-* GLOBALS AFFECTED
-*
-*************************************************************************/
-static kal_uint32 preview(MSDK_SENSOR_EXPOSURE_WINDOW_STRUCT *image_window,
-                                         MSDK_SENSOR_CONFIG_STRUCT *sensor_config_data)
+void OV5670_NightMode(kal_bool bEnable)
 {
-       LOG_INF("E\n");
-
-       spin_lock(&imgsensor_drv_lock);
-       imgsensor.sensor_mode = IMGSENSOR_MODE_PREVIEW;
-       imgsensor.pclk = imgsensor_info.pre.pclk;
-       //imgsensor.video_mode = KAL_FALSE;
-       imgsensor.line_length = imgsensor_info.pre.linelength;
-       imgsensor.frame_length = imgsensor_info.pre.framelength; 
-       imgsensor.min_frame_length = imgsensor_info.pre.framelength;
-       imgsensor.autoflicker_en = KAL_FALSE;
-       spin_unlock(&imgsensor_drv_lock);
-       preview_setting();
-       return ERROR_NONE;
-}      /*      preview   */
 
-/*************************************************************************
-* FUNCTION
-*      capture
-*
-* DESCRIPTION
-*      This function setup the CMOS sensor in capture MY_OUTPUT mode
-*
-* PARAMETERS
-*
-* RETURNS
-*      None
-*
-* GLOBALS AFFECTED
-*
-*************************************************************************/
-static kal_uint32 capture(MSDK_SENSOR_EXPOSURE_WINDOW_STRUCT *image_window,
-                                                 MSDK_SENSOR_CONFIG_STRUCT *sensor_config_data)
+}
+
+UINT32 OV5670Close(void)
 {
-       LOG_INF("E\n");
-       spin_lock(&imgsensor_drv_lock);
-       imgsensor.sensor_mode = IMGSENSOR_MODE_CAPTURE;
-       imgsensor.current_fps = 300;
-               imgsensor.pclk = imgsensor_info.cap.pclk;
-               imgsensor.line_length = imgsensor_info.cap.linelength;
-               imgsensor.frame_length = imgsensor_info.cap.framelength;  
-               imgsensor.min_frame_length = imgsensor_info.cap.framelength;
-               imgsensor.current_fps = imgsensor_info.cap.max_framerate;
-               imgsensor.autoflicker_en = KAL_FALSE;
-
-       spin_unlock(&imgsensor_drv_lock);
-
-       capture_setting(imgsensor.current_fps); 
-       
-       
-       return ERROR_NONE;
-}      /* capture() */
-static kal_uint32 normal_video(MSDK_SENSOR_EXPOSURE_WINDOW_STRUCT *image_window,
-                                         MSDK_SENSOR_CONFIG_STRUCT *sensor_config_data)
+
+    return ERROR_NONE;
+}
+
+#if 0
+void OV5670SetFlipMirror(kal_int32 imgMirror)
 {
-       LOG_INF("E\n");
-       
-       spin_lock(&imgsensor_drv_lock);
-       imgsensor.sensor_mode = IMGSENSOR_MODE_VIDEO;
-       imgsensor.pclk = imgsensor_info.normal_video.pclk;
-       imgsensor.line_length = imgsensor_info.normal_video.linelength;
-       imgsensor.frame_length = imgsensor_info.normal_video.framelength;  
-       imgsensor.min_frame_length = imgsensor_info.normal_video.framelength;
-       //imgsensor.current_fps = 300;
-       imgsensor.autoflicker_en = KAL_FALSE;
-       spin_unlock(&imgsensor_drv_lock);
-       normal_video_setting(imgsensor.current_fps);
-       
+       kal_int16 mirror=0,flip=0;
+       mirror= OV5670_read_cmos_sensor(0x3820);
+       flip  = OV5670_read_cmos_sensor(0x3821);
+
+    switch (imgMirror)
+    {
+        case IMAGE_H_MIRROR://IMAGE_NORMAL:
+            OV5670_write_cmos_sensor(0x3820, (mirror & (0xF9)));//Set normal
+            OV5670_write_cmos_sensor(0x3821, (flip & (0xF9))); //Set normal
+            break;
+        case IMAGE_NORMAL://IMAGE_V_MIRROR:
+            OV5670_write_cmos_sensor(0x3820, (mirror & (0xF9)));//Set flip
+            OV5670_write_cmos_sensor(0x3821, (flip | (0x06))); //Set flip
+            break;
+        case IMAGE_HV_MIRROR://IMAGE_H_MIRROR:
+            OV5670_write_cmos_sensor(0x3820, (mirror |(0x06)));        //Set mirror
+            OV5670_write_cmos_sensor(0x3821, (flip & (0xF9))); //Set mirror
+            break;
+        case IMAGE_V_MIRROR://IMAGE_HV_MIRROR:
+            OV5670_write_cmos_sensor(0x3820, (mirror |(0x06)));        //Set mirror & flip
+            OV5670_write_cmos_sensor(0x3821, (flip |(0x06)));  //Set mirror & flip
+            break;
+    }
+}
+#endif
+
+
+UINT32 OV5670Preview(MSDK_SENSOR_EXPOSURE_WINDOW_STRUCT *image_window,
+                                                MSDK_SENSOR_CONFIG_STRUCT *sensor_config_data)
+{
+
+       OV5670DB("OV5670Preview enter:");
+
+       //OV5670PreviewSetting();
+       OV5670CaptureSetting();
+       spin_lock(&ov5670mipiraw_drv_lock);
+       OV5670.sensorMode = SENSOR_MODE_PREVIEW; 
+       OV5670.DummyPixels = 0;
+       OV5670.DummyLines = 0 ;
+       OV5670_FeatureControl_PERIOD_PixelNum=OV5670_PV_PERIOD_PIXEL_NUMS+ OV5670.DummyPixels;
+       OV5670_FeatureControl_PERIOD_LineNum=OV5670_PV_PERIOD_LINE_NUMS+OV5670.DummyLines;
+       OV5670.imgMirror = sensor_config_data->SensorImageMirror;
+       spin_unlock(&ov5670mipiraw_drv_lock);
        
-       return ERROR_NONE;
-}      /*      normal_video   */
+       //OV5670SetFlipMirror(sensor_config_data->SensorImageMirror);
 
+    mdelay(20);//THIS DELAY SHOULD BE NEED BY CTS OR MONKEY
+       OV5670DB("OV5670Preview exit:\n");
 
+         
+    return ERROR_NONE;
+}
 
 
-static kal_uint32 get_resolution(MSDK_SENSOR_RESOLUTION_INFO_STRUCT *sensor_resolution)
+UINT32 OV5670Video(MSDK_SENSOR_EXPOSURE_WINDOW_STRUCT *image_window,
+                                                MSDK_SENSOR_CONFIG_STRUCT *sensor_config_data)
 {
-       LOG_INF("E\n");
-       sensor_resolution->SensorFullWidth = imgsensor_info.cap.grabwindow_width;
-       sensor_resolution->SensorFullHeight = imgsensor_info.cap.grabwindow_height;
-       
-       sensor_resolution->SensorPreviewWidth = imgsensor_info.pre.grabwindow_width;
-       sensor_resolution->SensorPreviewHeight = imgsensor_info.pre.grabwindow_height;
 
-       sensor_resolution->SensorVideoWidth = imgsensor_info.normal_video.grabwindow_width;
-       sensor_resolution->SensorVideoHeight = imgsensor_info.normal_video.grabwindow_height;           
+       OV5670DB("OV5670Video enter:");
+
+       OV5670VideoSetting();
 
+       spin_lock(&ov5670mipiraw_drv_lock);
+       OV5670.sensorMode = SENSOR_MODE_VIDEO;
+       OV5670_FeatureControl_PERIOD_PixelNum=OV5670_VIDEO_PERIOD_PIXEL_NUMS+ OV5670.DummyPixels;
+       OV5670_FeatureControl_PERIOD_LineNum=OV5670_VIDEO_PERIOD_LINE_NUMS+OV5670.DummyLines;
+       OV5670.imgMirror = sensor_config_data->SensorImageMirror;
+       spin_unlock(&ov5670mipiraw_drv_lock);
        
-       return ERROR_NONE;
-}      /*      get_resolution  */
+       //OV5670SetFlipMirror(sensor_config_data->SensorImageMirror);
+
+    mdelay(40);//THIS DELAY SHOULD BE NEED BY CTS OR MONKEY
+       OV5670DB("OV5670Video exit:\n");
+    return ERROR_NONE;
+}
+
 
-static kal_uint32 get_info(MSDK_SCENARIO_ID_ENUM scenario_id,
-                                         MSDK_SENSOR_INFO_STRUCT *sensor_info,
-                                         MSDK_SENSOR_CONFIG_STRUCT *sensor_config_data)
+UINT32 OV5670Capture(MSDK_SENSOR_EXPOSURE_WINDOW_STRUCT *image_window,
+                                                MSDK_SENSOR_CONFIG_STRUCT *sensor_config_data)
 {
-       LOG_INF("scenario_id = %d\n", scenario_id);
 
+       //kal_uint32 shutter = OV5670.shutter;
+
+       if( SENSOR_MODE_CAPTURE== OV5670.sensorMode)
+       {
+               OV5670DB("OV5670Capture BusrtShot / ZSD!!!\n");
+       }
+       else
+       {
+               OV5670DB("OV5670Capture enter:\n");
+
+               OV5670CaptureSetting();
+           mdelay(40);//THIS DELAY SHOULD BE NEED BY CTS OR MONKEY
+
+               spin_lock(&ov5670mipiraw_drv_lock);
+               OV5670.sensorMode = SENSOR_MODE_CAPTURE;
+               OV5670.imgMirror = sensor_config_data->SensorImageMirror;
+               OV5670.DummyPixels = 0;
+               OV5670.DummyLines = 0 ;
+               OV5670_FeatureControl_PERIOD_PixelNum = OV5670_FULL_PERIOD_PIXEL_NUMS + OV5670.DummyPixels;
+               OV5670_FeatureControl_PERIOD_LineNum = OV5670_FULL_PERIOD_LINE_NUMS + OV5670.DummyLines;
+               spin_unlock(&ov5670mipiraw_drv_lock);
+
+               //OV5670SetFlipMirror(sensor_config_data->SensorImageMirror);
+
+               OV5670DB("OV5670Capture exit:\n");
+       }
+
+       if(OV5670_During_testpattern == KAL_TRUE)
+       {
+               OV5670_write_cmos_sensor(0x4303,0x80);
+       }
+
+    return ERROR_NONE;
+}      
+
+
+
+UINT32 OV5670GetResolution(MSDK_SENSOR_RESOLUTION_INFO_STRUCT *pSensorResolution)
+{
+
+    OV5670DB("OV5670GetResolution!!\n");
+
+       pSensorResolution->SensorPreviewWidth   = OV5670_IMAGE_SENSOR_FULL_WIDTH;
+    pSensorResolution->SensorPreviewHeight     = OV5670_IMAGE_SENSOR_FULL_HEIGHT;
        
-       //sensor_info->SensorVideoFrameRate = imgsensor_info.normal_video.max_framerate/10; /* not use */
-       //sensor_info->SensorStillCaptureFrameRate= imgsensor_info.cap.max_framerate/10; /* not use */
-    //imgsensor_info->SensorWebCamCaptureFrameRate= imgsensor_info.v.max_framerate; /* not use */
-
-    sensor_info->SensorClockPolarity = SENSOR_CLOCK_POLARITY_LOW;
-    sensor_info->SensorClockFallingPolarity = SENSOR_CLOCK_POLARITY_LOW; /* not use */
-    sensor_info->SensorHsyncPolarity = SENSOR_CLOCK_POLARITY_LOW; // inverse with datasheet
-    sensor_info->SensorVsyncPolarity = SENSOR_CLOCK_POLARITY_LOW;
-    sensor_info->SensorInterruptDelayLines = 4; /* not use */
-    sensor_info->SensorResetActiveHigh = FALSE; /* not use */
-    sensor_info->SensorResetDelayCount = 5; /* not use */
-
-    sensor_info->SensroInterfaceType = imgsensor_info.sensor_interface_type;
-
-       sensor_info->SensorOutputDataFormat = imgsensor_info.sensor_output_dataformat;
-       sensor_info->CaptureDelayFrame = imgsensor_info.cap_delay_frame; 
-       sensor_info->PreviewDelayFrame = imgsensor_info.pre_delay_frame; 
-       sensor_info->VideoDelayFrame = imgsensor_info.video_delay_frame;
-
-       sensor_info->SensorMasterClockSwitch = 0; /* not use */
-       sensor_info->SensorDrivingCurrent = imgsensor_info.isp_driving_current;
-       
-       sensor_info->AEShutDelayFrame = imgsensor_info.ae_shut_delay_frame;              /* The frame of setting shutter default 0 for TG int */
-       sensor_info->AESensorGainDelayFrame = imgsensor_info.ae_sensor_gain_delay_frame;        /* The frame of setting sensor gain */
-       sensor_info->AEISPGainDelayFrame = imgsensor_info.ae_ispGain_delay_frame;       
-       
-       sensor_info->SensorMIPILaneNumber = imgsensor_info.mipi_lane_num; 
-       sensor_info->SensorClockFreq = imgsensor_info.mclk;
-       sensor_info->SensorClockDividCount = 3; /* not use */
-       sensor_info->SensorClockRisingCount = 0;
-       sensor_info->SensorClockFallingCount = 2; /* not use */
-       sensor_info->SensorPixelClockCount = 3; /* not use */
-       sensor_info->SensorDataLatchCount = 2; /* not use */
+    pSensorResolution->SensorFullWidth         = OV5670_IMAGE_SENSOR_FULL_WIDTH;
+    pSensorResolution->SensorFullHeight                = OV5670_IMAGE_SENSOR_FULL_HEIGHT;
        
-       sensor_info->MIPIDataLowPwr2HighSpeedTermDelayCount = 0; 
-       sensor_info->MIPICLKLowPwr2HighSpeedTermDelayCount = 0;
-       sensor_info->SensorWidthSampling = 0;  // 0 is default 1x
-       sensor_info->SensorHightSampling = 0;   // 0 is default 1x 
-       sensor_info->SensorPacketECCOrder = 1;
+    pSensorResolution->SensorVideoWidth                = OV5670_IMAGE_SENSOR_VIDEO_WIDTH;
+    pSensorResolution->SensorVideoHeight    = OV5670_IMAGE_SENSOR_VIDEO_HEIGHT;
+    return ERROR_NONE;
+}   
+
+UINT32 OV5670GetInfo(MSDK_SCENARIO_ID_ENUM ScenarioId,
+                                                MSDK_SENSOR_INFO_STRUCT *pSensorInfo,
+                                                MSDK_SENSOR_CONFIG_STRUCT *pSensorConfigData)
+{
 
-       switch (scenario_id) {
-               case MSDK_SCENARIO_ID_CAMERA_PREVIEW:
-                       sensor_info->SensorGrabStartX = imgsensor_info.pre.startx; 
-                       sensor_info->SensorGrabStartY = imgsensor_info.pre.starty;              
+       spin_lock(&ov5670mipiraw_drv_lock);
+       OV5670.imgMirror = pSensorConfigData->SensorImageMirror ;
+       spin_unlock(&ov5670mipiraw_drv_lock);
+
+    pSensorInfo->SensorOutputDataFormat= SENSOR_OUTPUT_FORMAT_RAW_B;
+   
+    pSensorInfo->SensorClockPolarity =SENSOR_CLOCK_POLARITY_LOW;
+    pSensorInfo->SensorClockFallingPolarity=SENSOR_CLOCK_POLARITY_LOW;
+    pSensorInfo->SensorHsyncPolarity = SENSOR_CLOCK_POLARITY_LOW;
+    pSensorInfo->SensorVsyncPolarity = SENSOR_CLOCK_POLARITY_LOW;
+
+    pSensorInfo->SensroInterfaceType=SENSOR_INTERFACE_TYPE_MIPI;
+
+    pSensorInfo->CaptureDelayFrame = 2;
+    pSensorInfo->PreviewDelayFrame = 1;
+    pSensorInfo->VideoDelayFrame = 2;
+
+    pSensorInfo->SensorDrivingCurrent = ISP_DRIVING_8MA;
+    pSensorInfo->AEShutDelayFrame = 0;     
+    pSensorInfo->AESensorGainDelayFrame = 0;
+    pSensorInfo->AEISPGainDelayFrame = 2;
+
+    switch (ScenarioId)
+    {
+        case MSDK_SCENARIO_ID_CAMERA_PREVIEW:
+            pSensorInfo->SensorClockFreq=24;
+            pSensorInfo->SensorClockRisingCount= 0;
+
+            pSensorInfo->SensorGrabStartX = OV5670_PV_X_START;
+            pSensorInfo->SensorGrabStartY = OV5670_PV_Y_START;
+
+            pSensorInfo->SensorMIPILaneNumber = SENSOR_MIPI_2_LANE;
                        
-                       sensor_info->MIPIDataLowPwr2HighSpeedSettleDelayCount = imgsensor_info.pre.mipi_data_lp2hs_settle_dc;
+            pSensorInfo->MIPIDataLowPwr2HighSpeedTermDelayCount = 0;
+               pSensorInfo->MIPIDataLowPwr2HighSpeedSettleDelayCount = 14;
+               pSensorInfo->MIPICLKLowPwr2HighSpeedTermDelayCount = 0;
+            pSensorInfo->SensorPacketECCOrder = 1;
+            break;
+        case MSDK_SCENARIO_ID_VIDEO_PREVIEW:
+            pSensorInfo->SensorClockFreq=24;
+            pSensorInfo->SensorClockRisingCount= 0;
+
+            pSensorInfo->SensorGrabStartX = OV5670_VIDEO_X_START;
+            pSensorInfo->SensorGrabStartY = OV5670_VIDEO_Y_START;
+
+            pSensorInfo->SensorMIPILaneNumber = SENSOR_MIPI_2_LANE;
                        
-                       break;
-               case MSDK_SCENARIO_ID_CAMERA_CAPTURE_JPEG:
-                       case MSDK_SCENARIO_ID_CAMERA_ZSD:
-                       sensor_info->SensorGrabStartX = imgsensor_info.cap.startx; 
-                       sensor_info->SensorGrabStartY = imgsensor_info.cap.starty;
-                                 
-                       sensor_info->MIPIDataLowPwr2HighSpeedSettleDelayCount = imgsensor_info.cap.mipi_data_lp2hs_settle_dc; 
-
-                       break;   
-               case MSDK_SCENARIO_ID_VIDEO_PREVIEW:
+            pSensorInfo->MIPIDataLowPwr2HighSpeedTermDelayCount = 0;
+               pSensorInfo->MIPIDataLowPwr2HighSpeedSettleDelayCount = 14;
+               pSensorInfo->MIPICLKLowPwr2HighSpeedTermDelayCount = 0;
+            pSensorInfo->SensorPacketECCOrder = 1;
+            break;
+        case MSDK_SCENARIO_ID_CAMERA_CAPTURE_JPEG:
+               case MSDK_SCENARIO_ID_CAMERA_ZSD:
+            pSensorInfo->SensorClockFreq=24;
+            pSensorInfo->SensorClockRisingCount= 0;
+
+            pSensorInfo->SensorGrabStartX = OV5670_FULL_X_START;       
+            pSensorInfo->SensorGrabStartY = OV5670_FULL_Y_START;       
+
+            pSensorInfo->SensorMIPILaneNumber = SENSOR_MIPI_2_LANE;
                        
-                       sensor_info->SensorGrabStartX = imgsensor_info.normal_video.startx; 
-                       sensor_info->SensorGrabStartY = imgsensor_info.normal_video.starty;
-          
-                       sensor_info->MIPIDataLowPwr2HighSpeedSettleDelayCount = imgsensor_info.normal_video.mipi_data_lp2hs_settle_dc; 
-                       break;
-               default:                        
-                       sensor_info->SensorGrabStartX = imgsensor_info.pre.startx; 
-                       sensor_info->SensorGrabStartY = imgsensor_info.pre.starty;              
+            pSensorInfo->MIPIDataLowPwr2HighSpeedTermDelayCount = 0;
+            pSensorInfo->MIPIDataLowPwr2HighSpeedSettleDelayCount = 14;
+            pSensorInfo->MIPICLKLowPwr2HighSpeedTermDelayCount = 0;
+            pSensorInfo->SensorPacketECCOrder = 1;
+            break;
+        default:
+                       pSensorInfo->SensorClockFreq=24;
+            pSensorInfo->SensorClockRisingCount= 0;
+
+            pSensorInfo->SensorGrabStartX = OV5670_PV_X_START;
+            pSensorInfo->SensorGrabStartY = OV5670_PV_Y_START;
+
+            pSensorInfo->SensorMIPILaneNumber = SENSOR_MIPI_2_LANE;
                        
-                       sensor_info->MIPIDataLowPwr2HighSpeedSettleDelayCount = imgsensor_info.pre.mipi_data_lp2hs_settle_dc;
-                       break;
-       }
-       
-       return ERROR_NONE;
-}      /*      get_info  */
+            pSensorInfo->MIPIDataLowPwr2HighSpeedTermDelayCount = 0;
+               pSensorInfo->MIPIDataLowPwr2HighSpeedSettleDelayCount = 14;
+               pSensorInfo->MIPICLKLowPwr2HighSpeedTermDelayCount = 0;
+            pSensorInfo->SensorPacketECCOrder = 1;
+            break;
+    }
+
+    memcpy(pSensorConfigData, &OV5670SensorConfigData, sizeof(MSDK_SENSOR_CONFIG_STRUCT));
+
+    return ERROR_NONE;
+}   /* OV5670GetInfo() */
+
 
 
-static kal_uint32 control(MSDK_SCENARIO_ID_ENUM scenario_id, MSDK_SENSOR_EXPOSURE_WINDOW_STRUCT *image_window,
-                                         MSDK_SENSOR_CONFIG_STRUCT *sensor_config_data)
+UINT32 OV5670Control(MSDK_SCENARIO_ID_ENUM ScenarioId, MSDK_SENSOR_EXPOSURE_WINDOW_STRUCT *pImageWindow,
+                                                MSDK_SENSOR_CONFIG_STRUCT *pSensorConfigData)
 {
-       LOG_INF("scenario_id = %d\n", scenario_id);
-       spin_lock(&imgsensor_drv_lock);
-       imgsensor.current_scenario_id = scenario_id;
-       spin_unlock(&imgsensor_drv_lock);
-       switch (scenario_id) {
-               case MSDK_SCENARIO_ID_CAMERA_PREVIEW:
-                       preview(image_window, sensor_config_data);
+               spin_lock(&ov5670mipiraw_drv_lock);
+               OV5670CurrentScenarioId = ScenarioId;
+               spin_unlock(&ov5670mipiraw_drv_lock);
+               
+               OV5670DB("OV5670CurrentScenarioId=%d\n",OV5670CurrentScenarioId);
+
+       switch (ScenarioId)
+    {
+        case MSDK_SCENARIO_ID_CAMERA_PREVIEW:
+            OV5670Preview(pImageWindow, pSensorConfigData);
+            break;
+        case MSDK_SCENARIO_ID_VIDEO_PREVIEW:
+                       OV5670DB("OV5670 video_preiew sync\n");
+                       OV5670Video(pImageWindow, pSensorConfigData);
                        break;
-               case MSDK_SCENARIO_ID_CAMERA_CAPTURE_JPEG:
-                       case MSDK_SCENARIO_ID_CAMERA_ZSD:
-                       capture(image_window, sensor_config_data);
-                       break;  
-               case MSDK_SCENARIO_ID_VIDEO_PREVIEW:
-                       normal_video(image_window, sensor_config_data);
-                       break;    
-               default:
-                       LOG_INF("Error ScenarioId setting");
-                       preview(image_window, sensor_config_data);
-                       return ERROR_INVALID_SCENARIO_ID;
-       }
-       return ERROR_NONE;
-}      /* control() */
+        case MSDK_SCENARIO_ID_CAMERA_CAPTURE_JPEG:
+               case MSDK_SCENARIO_ID_CAMERA_ZSD:
+            OV5670Capture(pImageWindow, pSensorConfigData);
+            break;
 
+        default:
+            return ERROR_INVALID_SCENARIO_ID;
 
+    }
+    return ERROR_NONE;
+} /* OV5670Control() */
 
-static kal_uint32 set_video_mode(UINT16 framerate)
+
+
+kal_uint32 OV5670_SET_FrameLength_ByVideoMode(UINT16 Video_TargetFps)
 {
-       LOG_INF("framerate = %d\n ", framerate);
-       // SetVideoMode Function should fix framerate
-       if (framerate == 0)
-               // Dynamic frame rate
-               return ERROR_NONE;
-       spin_lock(&imgsensor_drv_lock);
-       if ((framerate == 30) && (imgsensor.autoflicker_en == KAL_TRUE))
-       {
-               imgsensor.current_fps = 296;
-               }
-       else if ((framerate == 15) && (imgsensor.autoflicker_en == KAL_TRUE))
+    UINT32 frameRate = 0;
+       kal_uint32 MIN_FrameLength=0;
+       
+       if(OV5670.OV5670AutoFlickerMode == KAL_TRUE)
        {
-               imgsensor.current_fps = 146;
-               }
+               if (Video_TargetFps==30)
+                       frameRate= OV5670_AUTOFLICKER_OFFSET_30;
+               else if(Video_TargetFps==15)
+                       frameRate= OV5670_AUTOFLICKER_OFFSET_15;
+               else
+                       frameRate=Video_TargetFps*10;
+       
+               MIN_FrameLength = (OV5670.videoPclk*10000)/(OV5670_VIDEO_PERIOD_PIXEL_NUMS + OV5670.DummyPixels)/frameRate*10;
+       }
        else
+               MIN_FrameLength = (OV5670.videoPclk*10000) /(OV5670_VIDEO_PERIOD_PIXEL_NUMS + OV5670.DummyPixels)/Video_TargetFps;
+
+     return MIN_FrameLength;
+
+}
+
+
+
+UINT32 OV5670SetVideoMode(UINT16 u2FrameRate)
+{
+
+    kal_uint32 MIN_Frame_length =0,frameRate=0,extralines=0;
+    OV5670DB("[OV5670SetVideoMode] frame rate = %d\n", u2FrameRate);
+
+       spin_lock(&ov5670mipiraw_drv_lock);
+       OV5670_VIDEO_MODE_TARGET_FPS=u2FrameRate;
+       spin_unlock(&ov5670mipiraw_drv_lock);
+
+       if(u2FrameRate==0)
        {
-               imgsensor.current_fps = framerate*10;
+               OV5670DB("Disable Video Mode or dynimac fps\n");
+               return KAL_TRUE;
        }
-       spin_unlock(&imgsensor_drv_lock);
-       LOG_INF("current framerate = %d\n ", imgsensor.current_fps);
-       set_max_framerate(imgsensor.current_fps,1);
+       if(u2FrameRate >30 || u2FrameRate <5)
+           OV5670DB("abmornal frame rate seting,pay attention~\n");
 
-       return ERROR_NONE;
+    if(OV5670.sensorMode == SENSOR_MODE_VIDEO)//video ScenarioId recording
+    {
+
+        MIN_Frame_length = OV5670_SET_FrameLength_ByVideoMode(u2FrameRate);
+
+               if((MIN_Frame_length <=OV5670_VIDEO_PERIOD_LINE_NUMS))
+               {
+                       MIN_Frame_length = OV5670_VIDEO_PERIOD_LINE_NUMS;
+                       OV5670DB("[OV5670SetVideoMode]current fps = %d\n", (OV5670.videoPclk*10000)  /(OV5670_VIDEO_PERIOD_PIXEL_NUMS)/OV5670_VIDEO_PERIOD_LINE_NUMS);
+               }
+               OV5670DB("[OV5670SetVideoMode]current fps (10 base)= %d\n", (OV5670.videoPclk*10000)*10/(OV5670_VIDEO_PERIOD_PIXEL_NUMS + OV5670.DummyPixels)/MIN_Frame_length);
+               extralines = MIN_Frame_length - OV5670_VIDEO_PERIOD_LINE_NUMS;
+               
+               spin_lock(&ov5670mipiraw_drv_lock);
+               OV5670.DummyPixels = 0;//define dummy pixels and lines
+               OV5670.DummyLines = extralines ;
+               spin_unlock(&ov5670mipiraw_drv_lock);
+               
+               OV5670_SetDummy(OV5670.DummyPixels,extralines);
+    }
+       
+       OV5670DB("[OV5670SetVideoMode]MIN_Frame_length=%d,OV5670.DummyLines=%d\n",MIN_Frame_length,OV5670.DummyLines);
+
+    return KAL_TRUE;
 }
 
-static kal_uint32 set_auto_flicker_mode(kal_bool enable, UINT16 framerate)
+
+UINT32 OV5670SetAutoFlickerMode(kal_bool bEnable, UINT16 u2FrameRate)
 {
-       LOG_INF("enable = %d, framerate = %d \n", enable, framerate);
-       spin_lock(&imgsensor_drv_lock);
-       if (enable) //enable auto flicker         
-               imgsensor.autoflicker_en = KAL_TRUE;
-       else //Cancel Auto flick
-               imgsensor.autoflicker_en = KAL_FALSE;
-       spin_unlock(&imgsensor_drv_lock);
-       return ERROR_NONE;
+
+       if(bEnable) {   
+               spin_lock(&ov5670mipiraw_drv_lock);
+               OV5670.OV5670AutoFlickerMode = KAL_TRUE;
+               spin_unlock(&ov5670mipiraw_drv_lock);
+        OV5670DB("OV5670 Enable Auto flicker\n");
+    } else {
+       spin_lock(&ov5670mipiraw_drv_lock);
+        OV5670.OV5670AutoFlickerMode = KAL_FALSE;
+               spin_unlock(&ov5670mipiraw_drv_lock);
+        OV5670DB("OV5670 Disable Auto flicker\n");
+    }
+
+    return ERROR_NONE;
 }
 
 
-static kal_uint32 set_max_framerate_by_scenario(MSDK_SCENARIO_ID_ENUM scenario_id, MUINT32 framerate) 
+UINT32 OV5670SetTestPatternMode(kal_bool bEnable)
 {
-       kal_uint32 frame_length;
-  
-       LOG_INF("scenario_id = %d, framerate = %d\n", scenario_id, framerate);
+    OV5670DB("[OV5670SetTestPatternMode] Test pattern enable:%d\n", bEnable);
+    if(bEnable == KAL_TRUE)
+    {
+        OV5670_During_testpattern = KAL_TRUE;
 
-       switch (scenario_id) {
+               //OV5670_write_cmos_sensor(0x5000,0x16);// ; LENC off, MWB on, BPC on, WPC on
+               
+               OV5670_write_cmos_sensor(0x4303,0x08);
+    }
+       else
+       {
+        OV5670_During_testpattern = KAL_FALSE;
+               //OV5670_write_cmos_sensor(0x5000,0x96);// ; LENC on, MWB on, BPC on, WPC on
+               OV5670_write_cmos_sensor(0x4303,0x00);
+       }
+
+    return ERROR_NONE;
+}
+
+
+/*************************************************************************
+*
+* DESCRIPTION:
+* INTERFACE FUNCTION, FOR USER TO SET MAX  FRAMERATE;
+* 
+*************************************************************************/
+UINT32 OV5670MIPISetMaxFramerateByScenario(MSDK_SCENARIO_ID_ENUM scenarioId, MUINT32 frameRate) {
+       kal_uint32 pclk;
+       kal_int16 dummyLine;
+       kal_uint16 lineLength,frameHeight;
+               
+       OV5670DB("OV5670MIPISetMaxFramerateByScenario: scenarioId = %d, frame rate = %d\n",scenarioId,frameRate);
+       switch (scenarioId) {
                case MSDK_SCENARIO_ID_CAMERA_PREVIEW:
-                       frame_length = imgsensor_info.pre.pclk / framerate * 10 / imgsensor_info.pre.linelength;
-                       spin_lock(&imgsensor_drv_lock);
-                       imgsensor.dummy_line = (frame_length > imgsensor_info.pre.framelength) ? (frame_length - imgsensor_info.pre.framelength) : 0;
-                       imgsensor.frame_length = imgsensor_info.pre.framelength + imgsensor.dummy_line;
-                       imgsensor.min_frame_length = imgsensor.frame_length;
-                       spin_unlock(&imgsensor_drv_lock);
-                       set_dummy();                    
+                       pclk = OV5670_PREVIEW_PCLK;
+                       lineLength = OV5670_PV_PERIOD_PIXEL_NUMS;
+                       frameHeight = (10 * pclk)/frameRate/lineLength;
+                       dummyLine = frameHeight - OV5670_PV_PERIOD_LINE_NUMS;
+                       if(dummyLine<0)
+                               dummyLine = 0;
+                       spin_lock(&ov5670mipiraw_drv_lock);
+                       OV5670.sensorMode = SENSOR_MODE_PREVIEW;
+                       spin_unlock(&ov5670mipiraw_drv_lock);
+                       OV5670_SetDummy(0, dummyLine);                  
                        break;                  
                case MSDK_SCENARIO_ID_VIDEO_PREVIEW:
-                       if(framerate == 0)
-                               return ERROR_NONE;
-                       frame_length = imgsensor_info.normal_video.pclk / framerate * 10 / imgsensor_info.normal_video.linelength;
-                       spin_lock(&imgsensor_drv_lock);
-                       imgsensor.dummy_line = (frame_length > imgsensor_info.normal_video.framelength) ? (frame_length - imgsensor_info.normal_video.framelength) : 0;                 
-                       imgsensor.frame_length = imgsensor_info.normal_video.framelength + imgsensor.dummy_line;
-                       imgsensor.min_frame_length = imgsensor.frame_length;
-                       spin_unlock(&imgsensor_drv_lock);
-                       set_dummy();                    
+                       pclk = OV5670_VIDEO_PCLK;
+                       lineLength = OV5670_VIDEO_PERIOD_PIXEL_NUMS;
+                       frameHeight = (10 * pclk)/frameRate/lineLength;
+                       dummyLine = frameHeight - OV5670_VIDEO_PERIOD_LINE_NUMS;
+                       if(dummyLine<0)
+                               dummyLine = 0;
+                       spin_lock(&ov5670mipiraw_drv_lock);
+                       OV5670.sensorMode = SENSOR_MODE_VIDEO;
+                       spin_unlock(&ov5670mipiraw_drv_lock);
+                       OV5670_SetDummy(0, dummyLine);                  
+                       break;                  
+                        break;
+               case MSDK_SCENARIO_ID_CAMERA_CAPTURE_JPEG:
+               case MSDK_SCENARIO_ID_CAMERA_ZSD:                       
+                       pclk = OV5670_CAPTURE_PCLK;
+                       lineLength = OV5670_FULL_PERIOD_PIXEL_NUMS;
+                       frameHeight = (10 * pclk)/frameRate/lineLength;
+                       dummyLine = frameHeight - OV5670_FULL_PERIOD_LINE_NUMS;
+                       if(dummyLine<0)
+                               dummyLine = 0;
+                       spin_lock(&ov5670mipiraw_drv_lock);
+                       OV5670.sensorMode = SENSOR_MODE_CAPTURE;
+                       spin_unlock(&ov5670mipiraw_drv_lock);
+                       OV5670_SetDummy(0, dummyLine);                  
+                       break;          
+        case MSDK_SCENARIO_ID_CAMERA_3D_PREVIEW:
+            break;
+        case MSDK_SCENARIO_ID_CAMERA_3D_VIDEO:
                        break;
-               case MSDK_SCENARIO_ID_CAMERA_CAPTURE_JPEG:              
-                       case MSDK_SCENARIO_ID_CAMERA_ZSD:
-                frame_length = imgsensor_info.cap.pclk / framerate * 10 / imgsensor_info.cap.linelength;
-                       spin_lock(&imgsensor_drv_lock);
-                       imgsensor.dummy_line = (frame_length > imgsensor_info.cap.framelength) ? (frame_length - imgsensor_info.cap.framelength) : 0;
-                       imgsensor.frame_length = imgsensor_info.cap.framelength + imgsensor.dummy_line;
-                       imgsensor.min_frame_length = imgsensor.frame_length;
-                       spin_unlock(&imgsensor_drv_lock);
-                       set_dummy();    
+        case MSDK_SCENARIO_ID_CAMERA_3D_CAPTURE:   
                        break;          
-               default:  //coding with  preview scenario by default
-                       frame_length = imgsensor_info.pre.pclk / framerate * 10 / imgsensor_info.pre.linelength;
-                       spin_lock(&imgsensor_drv_lock);
-                       imgsensor.dummy_line = (frame_length > imgsensor_info.pre.framelength) ? (frame_length - imgsensor_info.pre.framelength) : 0;
-                       imgsensor.frame_length = imgsensor_info.pre.framelength + imgsensor.dummy_line;
-                       imgsensor.min_frame_length = imgsensor.frame_length;
-                       spin_unlock(&imgsensor_drv_lock);
-                       set_dummy();    
-                       LOG_INF("error scenario_id = %d, we use preview scenario \n", scenario_id);
+               default:
                        break;
        }       
        return ERROR_NONE;
 }
 
 
-static kal_uint32 get_default_framerate_by_scenario(MSDK_SCENARIO_ID_ENUM scenario_id, MUINT32 *framerate) 
+UINT32 OV5670MIPIGetDefaultFramerateByScenario(MSDK_SCENARIO_ID_ENUM scenarioId, MUINT32 *pframeRate) 
 {
-       LOG_INF("scenario_id = %d\n", scenario_id);
 
-       switch (scenario_id) {
+       switch (scenarioId) {
                case MSDK_SCENARIO_ID_CAMERA_PREVIEW:
-                       *framerate = imgsensor_info.pre.max_framerate;
-                       break;
                case MSDK_SCENARIO_ID_VIDEO_PREVIEW:
-                       *framerate = imgsensor_info.normal_video.max_framerate;
-                       break;
+                        *pframeRate = OV5670_MAX_FPS_PREVIEW;
+                        break;
                case MSDK_SCENARIO_ID_CAMERA_CAPTURE_JPEG:
-                       case MSDK_SCENARIO_ID_CAMERA_ZSD:
-                       *framerate = imgsensor_info.cap.max_framerate;
-                       break;
+               case MSDK_SCENARIO_ID_CAMERA_ZSD:
+                        *pframeRate = OV5670_MAX_FPS_CAPTURE;
+                       break;          
+        case MSDK_SCENARIO_ID_CAMERA_3D_PREVIEW: //added
+        case MSDK_SCENARIO_ID_CAMERA_3D_VIDEO:
+        case MSDK_SCENARIO_ID_CAMERA_3D_CAPTURE: //added   
+                        *pframeRate = OV5670_MAX_FPS_CAPTURE;
+                       break;          
                default:
                        break;
        }
@@ -1352,113 +1889,269 @@ static kal_uint32 get_default_framerate_by_scenario(MSDK_SCENARIO_ID_ENUM scenar
        return ERROR_NONE;
 }
 
-static kal_uint32 set_test_pattern_mode(kal_bool enable)
+/* Sensor output window information */
+
+/* SZ TCT xuejian.zhong add for CTS test*/
+
+static void OV5670GetAFMaxNumFocusAreas(UINT32 *pFeatureReturnPara32)
+{      
+    *pFeatureReturnPara32 = 0;    
+   // SENSORDB("OV5670GetAFMaxNumFocusAreas *pFeatureReturnPara32 = %d¥n",  *pFeatureReturnPara32);
+}
+
+static void OV5670GetAEMaxNumMeteringAreas(UINT32 *pFeatureReturnPara32)
+{     
+    *pFeatureReturnPara32 = 0;    
+  //  SENSORDB("OV5670GetAEMaxNumMeteringAreas *pFeatureReturnPara32 = %d¥n",  *pFeatureReturnPara32);        
+}
+
+static void OV5670GetExifInfo(UINT32 exifAddr)
 {
-       LOG_INF("enable: %d\n", enable);
-
-       if (enable) {
-               // 0x4303[3]: 1 enable,  0 disable
-               // only supports a special color bar test pattern
-               write_cmos_sensor(0x4303,0x08);
-       } else {
-               // 0x4303[3]: 1 enable,  0 disable
-               // only supports a special color bar test pattern
-               write_cmos_sensor(0x4303,0x00);
-       }        
-       spin_lock(&imgsensor_drv_lock);
-       imgsensor.test_pattern = enable;
-       spin_unlock(&imgsensor_drv_lock);
-       return ERROR_NONE;
+    SENSOR_EXIF_INFO_STRUCT* pExifInfo = (SENSOR_EXIF_INFO_STRUCT*)exifAddr;
+    pExifInfo->FNumber = 28;
+    pExifInfo->AEISOSpeed = AE_ISO_100;
+    pExifInfo->AWBMode = AWB_MODE_AUTO;
+    pExifInfo->CapExposureTime = 0;
+    pExifInfo->FlashLightTimeus = 0;
+    pExifInfo->RealISOValue = AE_ISO_100;
 }
 
-static kal_uint32 feature_control(MSDK_SENSOR_FEATURE_ENUM feature_id,
-                                                        UINT8 *feature_para,UINT32 *feature_para_len)
+/* SZ TCT xuejian.zhong  end */
+
+
+UINT32 OV5670FeatureControl(MSDK_SENSOR_FEATURE_ENUM FeatureId,
+                                                                UINT8 *pFeaturePara,UINT32 *pFeatureParaLen)
 {
-       UINT16 *feature_return_para_16=(UINT16 *) feature_para;
-       UINT16 *feature_data_16=(UINT16 *) feature_para;
-       UINT32 *feature_return_para_32=(UINT32 *) feature_para;
-       UINT32 *feature_data_32=(UINT32 *) feature_para;
-       
-       MSDK_SENSOR_REG_INFO_STRUCT *sensor_reg_data=(MSDK_SENSOR_REG_INFO_STRUCT *) feature_para;
-       LOG_INF("feature_id = %d\n", feature_id);
-       switch (feature_id) {
-               case SENSOR_FEATURE_GET_PERIOD:
-                       *feature_return_para_16++ = imgsensor.line_length;
-                       *feature_return_para_16 = imgsensor.frame_length;
-                       *feature_para_len=4;
-                       break;
-               case SENSOR_FEATURE_GET_PIXEL_CLOCK_FREQ:        
-                       *feature_return_para_32 = imgsensor.pclk;
-                       *feature_para_len=4;
-                       break;             
-               case SENSOR_FEATURE_SET_ESHUTTER:
-                       set_shutter(*feature_data_16);
-                       break;
-               case SENSOR_FEATURE_SET_NIGHTMODE:
-                       night_mode((BOOL) *feature_data_16);
-                       break;
-               case SENSOR_FEATURE_SET_GAIN:           
-                       set_gain((UINT16) *feature_data_16);
-                       break;
-               case SENSOR_FEATURE_SET_FLASHLIGHT:
-                       break;
-               case SENSOR_FEATURE_SET_ISP_MASTER_CLOCK_FREQ:
-                       break;
-               case SENSOR_FEATURE_SET_REGISTER:
-                       write_cmos_sensor(sensor_reg_data->RegAddr, sensor_reg_data->RegData);
-                       break;
-               case SENSOR_FEATURE_GET_REGISTER:
-                       sensor_reg_data->RegData = read_cmos_sensor(sensor_reg_data->RegAddr);
-                       break;
-               case SENSOR_FEATURE_GET_LENS_DRIVER_ID:
-                       // get the lens driver ID from EEPROM or just return LENS_DRIVER_ID_DO_NOT_CARE
-                       // if EEPROM does not exist in camera module.
-                       *feature_return_para_32=LENS_DRIVER_ID_DO_NOT_CARE;
-                       *feature_para_len=4;
-                       break;
-               case SENSOR_FEATURE_SET_VIDEO_MODE:
-                       set_video_mode(*feature_data_16);
-                       break; 
-               case SENSOR_FEATURE_CHECK_SENSOR_ID:
-                       get_imgsensor_id(feature_return_para_32); 
-                       break; 
-               case SENSOR_FEATURE_SET_AUTO_FLICKER_MODE:
-                       set_auto_flicker_mode((BOOL)*feature_data_16,*(feature_data_16+1));
-                       break;
+    UINT16 *pFeatureReturnPara16=(UINT16 *) pFeaturePara;
+    UINT16 *pFeatureData16=(UINT16 *) pFeaturePara;
+    UINT32 *pFeatureReturnPara32=(UINT32 *) pFeaturePara;
+    UINT32 *pFeatureData32=(UINT32 *) pFeaturePara;
+    UINT32 SensorRegNumber;
+    UINT32 i;
+    PNVRAM_SENSOR_DATA_STRUCT pSensorDefaultData=(PNVRAM_SENSOR_DATA_STRUCT) pFeaturePara;
+    MSDK_SENSOR_CONFIG_STRUCT *pSensorConfigData=(MSDK_SENSOR_CONFIG_STRUCT *) pFeaturePara;
+    MSDK_SENSOR_REG_INFO_STRUCT *pSensorRegData=(MSDK_SENSOR_REG_INFO_STRUCT *) pFeaturePara;
+    MSDK_SENSOR_GROUP_INFO_STRUCT *pSensorGroupInfo=(MSDK_SENSOR_GROUP_INFO_STRUCT *) pFeaturePara;
+    MSDK_SENSOR_ITEM_INFO_STRUCT *pSensorItemInfo=(MSDK_SENSOR_ITEM_INFO_STRUCT *) pFeaturePara;
+    MSDK_SENSOR_ENG_INFO_STRUCT        *pSensorEngInfo=(MSDK_SENSOR_ENG_INFO_STRUCT *) pFeaturePara;
+
+    switch (FeatureId)
+    {
+        case SENSOR_FEATURE_GET_RESOLUTION:
+            *pFeatureReturnPara16++= OV5670_IMAGE_SENSOR_FULL_WIDTH;
+            *pFeatureReturnPara16= OV5670_IMAGE_SENSOR_FULL_HEIGHT;
+            *pFeatureParaLen=4;
+            break;
+        case SENSOR_FEATURE_GET_PERIOD:
+                               *pFeatureReturnPara16++= OV5670_FeatureControl_PERIOD_PixelNum;
+                               *pFeatureReturnPara16= OV5670_FeatureControl_PERIOD_LineNum;
+                               *pFeatureParaLen=4;
+                               break;
+        case SENSOR_FEATURE_GET_PIXEL_CLOCK_FREQ:
+                       switch(OV5670CurrentScenarioId)
+                       {
+                               case MSDK_SCENARIO_ID_CAMERA_PREVIEW:
+                                       *pFeatureReturnPara32 = OV5670_PREVIEW_PCLK;
+                                       *pFeatureParaLen=4;
+                                       break;
+                               case MSDK_SCENARIO_ID_VIDEO_PREVIEW:
+                                       *pFeatureReturnPara32 = OV5670_VIDEO_PCLK;
+                                       *pFeatureParaLen=4;
+                                       break;
+                               case MSDK_SCENARIO_ID_CAMERA_CAPTURE_JPEG:
+                               case MSDK_SCENARIO_ID_CAMERA_ZSD:
+                                       *pFeatureReturnPara32 = OV5670_CAPTURE_PCLK;
+                                       *pFeatureParaLen=4;
+                                       break;
+                               default:
+                                       *pFeatureReturnPara32 = OV5670_PREVIEW_PCLK;
+                                       *pFeatureParaLen=4;
+                                       break;
+                       }
+                   break;
+
+        case SENSOR_FEATURE_SET_ESHUTTER:
+            OV5670_SetShutter(*pFeatureData16);
+            break;
+        case SENSOR_FEATURE_SET_NIGHTMODE:
+            OV5670_NightMode((BOOL) *pFeatureData16);
+            break;
+        case SENSOR_FEATURE_SET_GAIN:  
+           OV5670_SetGain((UINT16) *pFeatureData16);
+            break;
+        case SENSOR_FEATURE_SET_FLASHLIGHT:
+            break;
+        case SENSOR_FEATURE_SET_ISP_MASTER_CLOCK_FREQ:
+            //OV5670_isp_master_clock=*pFeatureData32;
+            break;
+        case SENSOR_FEATURE_SET_REGISTER:
+            OV5670_write_cmos_sensor(pSensorRegData->RegAddr, pSensorRegData->RegData);
+            break;
+        case SENSOR_FEATURE_GET_REGISTER:
+            pSensorRegData->RegData = OV5670_read_cmos_sensor(pSensorRegData->RegAddr);
+            break;
+        case SENSOR_FEATURE_SET_CCT_REGISTER:
+            SensorRegNumber=FACTORY_END_ADDR;
+            for (i=0;i<SensorRegNumber;i++)
+            {
+               spin_lock(&ov5670mipiraw_drv_lock);
+                OV5670SensorCCT[i].Addr=*pFeatureData32++;
+                OV5670SensorCCT[i].Para=*pFeatureData32++;
+                               spin_unlock(&ov5670mipiraw_drv_lock);
+            }
+            break;
+        case SENSOR_FEATURE_GET_CCT_REGISTER:
+            SensorRegNumber=FACTORY_END_ADDR;
+            if (*pFeatureParaLen<(SensorRegNumber*sizeof(SENSOR_REG_STRUCT)+4))
+                return FALSE;
+            *pFeatureData32++=SensorRegNumber;
+            for (i=0;i<SensorRegNumber;i++)
+            {
+                *pFeatureData32++=OV5670SensorCCT[i].Addr;
+                *pFeatureData32++=OV5670SensorCCT[i].Para;
+            }
+            break;
+        case SENSOR_FEATURE_SET_ENG_REGISTER:
+            SensorRegNumber=ENGINEER_END;
+            for (i=0;i<SensorRegNumber;i++)
+            {
+               spin_lock(&ov5670mipiraw_drv_lock);
+                OV5670SensorReg[i].Addr=*pFeatureData32++;
+                OV5670SensorReg[i].Para=*pFeatureData32++;
+                               spin_unlock(&ov5670mipiraw_drv_lock);
+            }
+            break;
+        case SENSOR_FEATURE_GET_ENG_REGISTER:
+            SensorRegNumber=ENGINEER_END;
+            if (*pFeatureParaLen<(SensorRegNumber*sizeof(SENSOR_REG_STRUCT)+4))
+                return FALSE;
+            *pFeatureData32++=SensorRegNumber;
+            for (i=0;i<SensorRegNumber;i++)
+            {
+                *pFeatureData32++=OV5670SensorReg[i].Addr;
+                *pFeatureData32++=OV5670SensorReg[i].Para;
+            }
+            break;
+        case SENSOR_FEATURE_GET_REGISTER_DEFAULT:
+            if (*pFeatureParaLen>=sizeof(NVRAM_SENSOR_DATA_STRUCT))
+            {
+                pSensorDefaultData->Version=NVRAM_CAMERA_SENSOR_FILE_VERSION;
+                pSensorDefaultData->SensorId=OV5670MIPI_SENSOR_ID;
+                memcpy(pSensorDefaultData->SensorEngReg, OV5670SensorReg, sizeof(SENSOR_REG_STRUCT)*ENGINEER_END);
+                memcpy(pSensorDefaultData->SensorCCTReg, OV5670SensorCCT, sizeof(SENSOR_REG_STRUCT)*FACTORY_END_ADDR);
+            }
+            else
+                return FALSE;
+            *pFeatureParaLen=sizeof(NVRAM_SENSOR_DATA_STRUCT);
+            break;
+        case SENSOR_FEATURE_GET_CONFIG_PARA:
+            memcpy(pSensorConfigData, &OV5670SensorConfigData, sizeof(MSDK_SENSOR_CONFIG_STRUCT));
+            *pFeatureParaLen=sizeof(MSDK_SENSOR_CONFIG_STRUCT);
+            break;
+        case SENSOR_FEATURE_CAMERA_PARA_TO_SENSOR:
+            OV5670_camera_para_to_sensor();
+            break;
+
+        case SENSOR_FEATURE_SENSOR_TO_CAMERA_PARA:
+            OV5670_sensor_to_camera_para();
+            break;
+        case SENSOR_FEATURE_GET_GROUP_COUNT:
+            *pFeatureReturnPara32++=OV5670_get_sensor_group_count();
+            *pFeatureParaLen=4;
+            break;
+        case SENSOR_FEATURE_GET_GROUP_INFO:
+            OV5670_get_sensor_group_info(pSensorGroupInfo->GroupIdx, pSensorGroupInfo->GroupNamePtr, &pSensorGroupInfo->ItemCount);
+            *pFeatureParaLen=sizeof(MSDK_SENSOR_GROUP_INFO_STRUCT);
+            break;
+        case SENSOR_FEATURE_GET_ITEM_INFO:
+            OV5670_get_sensor_item_info(pSensorItemInfo->GroupIdx,pSensorItemInfo->ItemIdx, pSensorItemInfo);
+            *pFeatureParaLen=sizeof(MSDK_SENSOR_ITEM_INFO_STRUCT);
+            break;
+
+        case SENSOR_FEATURE_SET_ITEM_INFO:
+            OV5670_set_sensor_item_info(pSensorItemInfo->GroupIdx, pSensorItemInfo->ItemIdx, pSensorItemInfo->ItemValue);
+            *pFeatureParaLen=sizeof(MSDK_SENSOR_ITEM_INFO_STRUCT);
+            break;
+
+        case SENSOR_FEATURE_GET_ENG_INFO:
+            pSensorEngInfo->SensorId = 129;
+            pSensorEngInfo->SensorType = CMOS_SENSOR;
+            pSensorEngInfo->SensorOutputDataFormat=SENSOR_OUTPUT_FORMAT_RAW_B;
+            *pFeatureParaLen=sizeof(MSDK_SENSOR_ENG_INFO_STRUCT);
+            break;
+        case SENSOR_FEATURE_GET_LENS_DRIVER_ID:
+            // get the lens driver ID from EEPROM or just return LENS_DRIVER_ID_DO_NOT_CARE
+            // if EEPROM does not exist in camera module.
+            *pFeatureReturnPara32=LENS_DRIVER_ID_DO_NOT_CARE;
+            *pFeatureParaLen=4;
+            break;
+
+        case SENSOR_FEATURE_INITIALIZE_AF:
+            break;
+        case SENSOR_FEATURE_CONSTANT_AF:
+            break;
+        case SENSOR_FEATURE_MOVE_FOCUS_LENS:
+            break;
+        case SENSOR_FEATURE_SET_VIDEO_MODE:
+            OV5670SetVideoMode(*pFeatureData16);
+            break;
+        case SENSOR_FEATURE_CHECK_SENSOR_ID:
+            OV5670GetSensorID(pFeatureReturnPara32);
+            break;
+        case SENSOR_FEATURE_SET_AUTO_FLICKER_MODE:
+            OV5670SetAutoFlickerMode((BOOL)*pFeatureData16, *(pFeatureData16+1));
+               break;
                case SENSOR_FEATURE_SET_MAX_FRAME_RATE_BY_SCENARIO:
-                       set_max_framerate_by_scenario((MSDK_SCENARIO_ID_ENUM)*feature_data_32, *(feature_data_32+1));
+                       OV5670MIPISetMaxFramerateByScenario((MSDK_SCENARIO_ID_ENUM)*pFeatureData32, *(pFeatureData32+1));
                        break;
                case SENSOR_FEATURE_GET_DEFAULT_FRAME_RATE_BY_SCENARIO:
-                       get_default_framerate_by_scenario((MSDK_SCENARIO_ID_ENUM)*feature_data_32, (MUINT32 *)(*(feature_data_32+1)));
+                       OV5670MIPIGetDefaultFramerateByScenario((MSDK_SCENARIO_ID_ENUM)*pFeatureData32, (MUINT32 *)(*(pFeatureData32+1)));
                        break;
                case SENSOR_FEATURE_SET_TEST_PATTERN:
-                       set_test_pattern_mode((BOOL)*feature_data_16);
+                       OV5670SetTestPatternMode((BOOL)*pFeatureData16);
                        break;
-               case SENSOR_FEATURE_GET_TEST_PATTERN_CHECKSUM_VALUE: //for factory mode auto testing                     
-                       *feature_return_para_32 = imgsensor_info.checksum_value;
-                       *feature_para_len=4;                                                     
-                       break;                          
-               default:
+               case SENSOR_FEATURE_GET_TEST_PATTERN_CHECKSUM_VALUE://for factory mode auto testing                     
+                       *pFeatureReturnPara32=OV5670_TEST_PATTERN_CHECKSUM;               
+                       *pFeatureParaLen=4;                                                     
+                    break;
+                       /*SZ TCT xuejian.zhong add for CTS test */
+               case SENSOR_FEATURE_GET_AF_MAX_NUM_FOCUS_AREAS:
+                       OV5670GetAFMaxNumFocusAreas(pFeatureData32);
+                       *pFeatureParaLen=4;                                                      
                        break;
-       }
-  
-       return ERROR_NONE;
-}      /*      feature_control()  */
-
-static SENSOR_FUNCTION_STRUCT sensor_func = {
-       open,
-       get_info,
-       get_resolution,
-       feature_control,
-       control,
-       close
+
+               case SENSOR_FEATURE_GET_AE_MAX_NUM_METERING_AREAS:
+                       OV5670GetAEMaxNumMeteringAreas(pFeatureData32);
+                       *pFeatureParaLen=4;                                                      
+                       break;
+               case SENSOR_FEATURE_GET_EXIF_INFO:
+               //      SENSORDB("SENSOR_FEATURE_GET_EXIF_INFO¥n");
+               //      SENSORDB("EXIF addr = 0x%x¥n",*pFeatureData32);
+
+                       OV5670GetExifInfo(*pFeatureData32);
+                       break;
+                       /* xuejian.zhong add end */
+        default:
+            break;
+    }
+    return ERROR_NONE;
+}      
+
+
+SENSOR_FUNCTION_STRUCT SensorFuncOV5670=
+{
+    OV5670Open,
+    OV5670GetInfo,
+    OV5670GetResolution,
+    OV5670FeatureControl,
+    OV5670Control,
+    OV5670Close
 };
 
 UINT32 OV5670_MIPI_RAW_SensorInit(PSENSOR_FUNCTION_STRUCT *pfFunc)
 {
-       /* To Do : Check Sensor status here */
-       if (pfFunc!=NULL)
-               *pfFunc=&sensor_func;
-       return ERROR_NONE;
-}      /*      OV5670_MIPI_RAW_SensorInit      */
+    if (pfFunc!=NULL)
+        *pfFunc=&SensorFuncOV5670;
+
+    return ERROR_NONE;
+}  
index 785b1c38586fcfa0fed68090b406fb27d51e2427..7d76a0155887b1206fd4cf0422d715cb0601321e 100644 (file)
 #ifndef _OV5670MIPI_SENSOR_H
 #define _OV5670MIPI_SENSOR_H
 
+typedef enum group_enum {
+    PRE_GAIN=0,
+    CMMCLK_CURRENT,
+    FRAME_RATE_LIMITATION,
+    REGISTER_EDITOR,
+    GROUP_TOTAL_NUMS
+} FACTORY_GROUP_ENUM;
+
+
+#define ENGINEER_START_ADDR 10
+#define FACTORY_START_ADDR 0
+
+typedef enum engineer_index
+{
+    CMMCLK_CURRENT_INDEX=ENGINEER_START_ADDR,
+    ENGINEER_END
+} FACTORY_ENGINEER_INDEX;
+
+typedef enum register_index
+{
+       SENSOR_BASEGAIN=FACTORY_START_ADDR,
+       PRE_GAIN_R_INDEX,
+       PRE_GAIN_Gr_INDEX,
+       PRE_GAIN_Gb_INDEX,
+       PRE_GAIN_B_INDEX,
+       FACTORY_END_ADDR
+} FACTORY_REGISTER_INDEX;
+
+typedef struct
+{
+    SENSOR_REG_STRUCT  Reg[ENGINEER_END];
+    SENSOR_REG_STRUCT  CCT[FACTORY_END_ADDR];
+} SENSOR_DATA_STRUCT, *PSENSOR_DATA_STRUCT;
+
+typedef enum {
+    SENSOR_MODE_INIT = 0,
+    SENSOR_MODE_PREVIEW,
+    SENSOR_MODE_VIDEO,
+    SENSOR_MODE_CAPTURE
+} OV5670_SENSOR_MODE;
+
+
+typedef struct
+{
+       kal_uint32 DummyPixels;
+       kal_uint32 DummyLines;
+       
+       kal_uint32 pvShutter;
+       kal_uint32 pvGain;
+       
+       kal_uint32 pvPclk;  
+       kal_uint32 videoPclk;
+       kal_uint32 capPclk;
+       
+       kal_uint32 shutter;
 
-typedef enum{
-       IMGSENSOR_MODE_INIT,
-       IMGSENSOR_MODE_PREVIEW,
-       IMGSENSOR_MODE_CAPTURE,
-       IMGSENSOR_MODE_VIDEO,
-} IMGSENSOR_MODE;
+       kal_uint16 sensorGlobalGain;
+       kal_uint16 ispBaseGain;
+       kal_uint16 realGain;
 
-typedef struct imgsensor_mode_struct {
-       kal_uint32 pclk;                                //record different mode's pclk
-       kal_uint32 linelength;                  //record different mode's linelength
-       kal_uint32 framelength;                 //record different mode's framelength
+       kal_int16 imgMirror;
 
-       kal_uint8 startx;                               //record different mode's startx of grabwindow
-       kal_uint8 starty;                               //record different mode's startx of grabwindow
+       OV5670_SENSOR_MODE sensorMode;
 
-       kal_uint16 grabwindow_width;    //record different mode's width of grabwindow
-       kal_uint16 grabwindow_height;   //record different mode's height of grabwindow
+       kal_bool OV5670AutoFlickerMode;
+       kal_bool OV5670VideoMode;
+       
+}OV5670_PARA_STRUCT,*POV5670_PARA_STRUCT;
 
-       /*       following for MIPIDataLowPwr2HighSpeedSettleDelayCount by different scenario   */
-       kal_uint8 mipi_data_lp2hs_settle_dc;
 
-       /*       following for GetDefaultFramerateByScenario()  */
-       kal_uint16 max_framerate;
+    #define OV5670_SHUTTER_MARGIN                      (4)
+       #define OV5670_GAIN_BASE                                (128)
+       #define OV5670_AUTOFLICKER_OFFSET_30    (296)
+       #define OV5670_AUTOFLICKER_OFFSET_25    (250)
+       #define OV5670_AUTOFLICKER_OFFSET_15    (146)
+       #define OV5670_PREVIEW_PCLK                     (102850000)
+       #define OV5670_VIDEO_PCLK                               (OV5670_PREVIEW_PCLK)
+       #define OV5670_CAPTURE_PCLK                     (102850000)
        
-} imgsensor_mode_struct;
+       #define OV5670_MAX_FPS_PREVIEW                  (300)
+       #define OV5670_MAX_FPS_VIDEO                    (300)
+       #define OV5670_MAX_FPS_CAPTURE                  (250)
+       //#define OV5670_MAX_FPS_N3D                            (300)
 
-/* SENSOR PRIVATE STRUCT FOR VARIABLES*/
-typedef struct imgsensor_struct {
-       kal_uint8 mirror;                               //mirrorflip information
 
-       kal_uint8 sensor_mode;                  //record IMGSENSOR_MODE enum value
+       //grab window
+       #define OV5670_IMAGE_SENSOR_PV_WIDTH                                    (1296)
+       #define OV5670_IMAGE_SENSOR_PV_HEIGHT                                   (972) //(960)
+       #define OV5670_IMAGE_SENSOR_VIDEO_WIDTH                                 (OV5670_IMAGE_SENSOR_PV_WIDTH)
+       #define OV5670_IMAGE_SENSOR_VIDEO_HEIGHT                                (OV5670_IMAGE_SENSOR_PV_HEIGHT)
+       #define OV5670_IMAGE_SENSOR_FULL_WIDTH                                  (2592)  
+       #define OV5670_IMAGE_SENSOR_FULL_HEIGHT                                 (1944)
 
-       kal_uint32 shutter;                             //current shutter
-       kal_uint16 gain;                                //current gain
-       
-       kal_uint32 pclk;                                //current pclk
+       #define OV5670_FULL_X_START                                                             (0)
+       #define OV5670_FULL_Y_START                                                             (0)
+       #define OV5670_PV_X_START                                                               (0)
+       #define OV5670_PV_Y_START                                                               (0)
+       #define OV5670_VIDEO_X_START                                                            (0)
+       #define OV5670_VIDEO_Y_START                                                            (0)
 
-       kal_uint32 frame_length;                //current framelength
-       kal_uint32 line_length;                 //current linelength
+       #define OV5670_MAX_ANALOG_GAIN                                  (8)
+       #define OV5670_MIN_ANALOG_GAIN                                  (1)
 
-       kal_uint32 min_frame_length;    //current min  framelength to max framerate
-       kal_uint16 dummy_pixel;                 //current dummypixel
-       kal_uint16 dummy_line;                  //current dummline
-       
-       kal_uint16 current_fps;                 //current max fps
-       kal_bool   autoflicker_en;              //record autoflicker enable or disable
-       kal_bool test_pattern;                  //record test pattern mode or not
-       MSDK_SCENARIO_ID_ENUM current_scenario_id;//current scenario id
-       kal_uint8  ihdr_en;                             //ihdr enable or disable
-       
-       kal_uint8 i2c_write_id;                 //record current sensor's i2c write id
-} imgsensor_struct;
-
-/* SENSOR PRIVATE STRUCT FOR CONSTANT*/
-typedef struct imgsensor_info_struct { 
-       kal_uint32 sensor_id;                   //record sensor id defined in Kd_imgsensor.h
-       kal_uint32 checksum_value;              //checksum value for Camera Auto Test
-       imgsensor_mode_struct pre;              //preview scenario relative information
-       imgsensor_mode_struct cap;              //capture scenario relative information
-       imgsensor_mode_struct normal_video;//normal video  scenario relative information
-       
-       kal_uint8  ae_shut_delay_frame; //shutter delay frame for AE cycle
-       kal_uint8  ae_sensor_gain_delay_frame;  //sensor gain delay frame for AE cycle
-       kal_uint8  ae_ispGain_delay_frame;      //isp gain delay frame for AE cycle
-       kal_uint8  sensor_mode_num;             //support sensor mode num
-       
-       kal_uint8  cap_delay_frame;             //enter capture delay frame num
-       kal_uint8  pre_delay_frame;             //enter preview delay frame num
-       kal_uint8  video_delay_frame;   //enter video delay frame num
-       kal_uint8  margin;                              //sensor framelength & shutter margin 
-       kal_uint32 min_shutter;                 //min shutter
-       kal_uint32 max_frame_length;    //max framelength by sensor register's limitation
-
-       kal_uint8  isp_driving_current; //mclk driving current
-       kal_uint8  sensor_interface_type;//sensor_interface_type
-       kal_uint8  mipi_sensor_type; //0,MIPI_OPHY_NCSI2; 1,MIPI_OPHY_CSI2, default is NCSI2, don't modify this para
-       kal_uint8  mipi_settle_delay_mode; //0, high speed signal auto detect; 1, use settle delay,unit is ns, default is auto detect, don't modify this para
-       kal_uint8  sensor_output_dataformat;//sensor output first pixel color
-       kal_uint8  mclk;                                //mclk value, suggest 24 or 26 for 24Mhz or 26Mhz
+
+       /* SENSOR PIXEL/LINE NUMBERS IN ONE PERIOD */
+       #define OV5670_PV_PERIOD_PIXEL_NUMS                             0x068C  //1676*2=>3352
+       #define OV5670_PV_PERIOD_LINE_NUMS                                      0x07FD  //2045
+
+       #define OV5670_VIDEO_PERIOD_PIXEL_NUMS                          OV5670_PV_PERIOD_PIXEL_NUMS
+       #define OV5670_VIDEO_PERIOD_LINE_NUMS                           OV5670_PV_PERIOD_LINE_NUMS
+
+       #define OV5670_FULL_PERIOD_PIXEL_NUMS                                   0x07DC  //2012*2   25fps
+       #define OV5670_FULL_PERIOD_LINE_NUMS                                    0x07FD  //2045
        
-       kal_uint8  mipi_lane_num;               //mipi lane num
-       kal_uint8  i2c_addr_table[5];   //record sensor support all write id addr, only supprt 4must end with 0xff
-} imgsensor_info_struct;
-
-/* SENSOR READ/WRITE ID */
-//#define IMGSENSOR_WRITE_ID_1 (0x6c)
-//#define IMGSENSOR_READ_ID_1  (0x6d)
-//#define IMGSENSOR_WRITE_ID_2 (0x20)
-//#define IMGSENSOR_READ_ID_2  (0x21)
-
-extern int iReadRegI2C(u8 *a_pSendData , u16 a_sizeSendData, u8 * a_pRecvData, u16 a_sizeRecvData, u16 i2cId);
-extern int iWriteRegI2C(u8 *a_pSendData , u16 a_sizeSendData, u16 i2cId);
+       #define OV5670MIPI_WRITE_ID     (0x6c)
+       #define OV5670MIPI_READ_ID      (0x6d)
+
+       #define OV5670MIPI_SENSOR_ID            OV5670_SENSOR_ID
+
+
+       UINT32 OV5670MIPIOpen(void);
+       UINT32 OV5670MIPIGetResolution(MSDK_SENSOR_RESOLUTION_INFO_STRUCT *pSensorResolution);
+       UINT32 OV5670MIPIGetInfo(MSDK_SCENARIO_ID_ENUM ScenarioId, MSDK_SENSOR_INFO_STRUCT *pSensorInfo, MSDK_SENSOR_CONFIG_STRUCT *pSensorConfigData);
+       UINT32 OV5670MIPIControl(MSDK_SCENARIO_ID_ENUM ScenarioId, MSDK_SENSOR_EXPOSURE_WINDOW_STRUCT *pImageWindow, MSDK_SENSOR_CONFIG_STRUCT *pSensorConfigData);
+       UINT32 OV5670MIPIFeatureControl(MSDK_SENSOR_FEATURE_ENUM FeatureId, UINT8 *pFeaturePara,UINT32 *pFeatureParaLen);
+       UINT32 OV5670MIPIClose(void);
 
 #endif 
 
index f4095e73916ee86ef3dd0cbbb1ef2ea7c718d520..80b793860d8ada153ad30a0ee2229325dc383384 100644 (file)
@@ -643,7 +643,7 @@ static void lcm_resume(void)
 #endif
        lcm_init();
 }
-/*
+
 static unsigned int lcm_esd_test = FALSE;
 
 static unsigned int lcm_esd_check(void)
@@ -654,7 +654,7 @@ static unsigned int lcm_esd_check(void)
        char  buffer[1];
        int   array[4];
        int ret = 0;
-       
+
        if(lcm_esd_test)
        {
                lcm_esd_test = FALSE;
@@ -694,7 +694,7 @@ static unsigned int lcm_esd_recover(void)
        lcm_init();
        return TRUE;
 }
-*/
+
 static unsigned int lcm_compare_id(void)
 {
     unsigned int id1 = 0, id2 = 0, id = 0;
@@ -742,8 +742,8 @@ LCM_DRIVER a080ean01_dsi_vdo_lcm_drv =
     .init           = lcm_init,
     .suspend        = lcm_suspend,
     .resume         = lcm_resume,
-    //.esd_check       = lcm_esd_check,
-   // .esd_recover    = lcm_esd_recover,
+    .esd_check         = lcm_esd_check,
+       .esd_recover    = lcm_esd_recover,
        .compare_id    = lcm_compare_id,
 };
 
index c8530171084318a34d92de29dd3513485ad6716d..e1aafa2ac6c749b458520145f196b3b00097a308 100644 (file)
@@ -142,31 +142,28 @@ static void init_lcm_registers(void)
 #else    
        //printk("[IND][K] y_____1%s\n", __func__);
 #endif
-       //[BUGFIX]-Mod-BEGIN by SCDTABLET.jinghuang@tcl.com,05/21/2015,1008656£¬
-       //import gamma2.2 V1 parameters.
-       data_array[0] = 0x77801500;     
+
+       data_array[0] = 0x47801500;     
        dsi_set_cmdq(&data_array, 1, 1);        
        MDELAY(1);      
-       data_array[0] = 0x77811500;     
+       data_array[0] = 0x40811500;     
        dsi_set_cmdq(&data_array, 1, 1);        
        MDELAY(1);      
-       data_array[0] = 0xa8821500;     
+       data_array[0] = 0x04821500;     
        dsi_set_cmdq(&data_array, 1, 1);        
        MDELAY(1);      
-       data_array[0] = 0xfe831500;     
+       data_array[0] = 0x77831500;     
        dsi_set_cmdq(&data_array, 1, 1);        
        MDELAY(1);      
-       data_array[0] = 0xb0841500;     
+       data_array[0] = 0x0F841500;     
        dsi_set_cmdq(&data_array, 1, 1);        
        MDELAY(1);      
-       data_array[0] = 0x77851500;     
+       data_array[0] = 0x70851500;     
        dsi_set_cmdq(&data_array, 1, 1);        
        MDELAY(1);      
-       data_array[0] = 0x77861500;     
+       data_array[0] = 0x70861500;     
        dsi_set_cmdq(&data_array, 1, 1);        
        MDELAY(1);
-       //[BUGFIX]-Mod-END by SCDTABLET.jinghuang@tcl.com
-
        
 }
 
@@ -321,7 +318,7 @@ static unsigned int lcm_esd_check(void)
        read_reg_v2(0x81, buffer, 1);
        //printk("\n ZERO] [0x81]=0x%02x\n", buffer[0]);
 
-       if(buffer[0] != 0x77)
+       if(buffer[0] != 0x40)
        {
                printk("[LCM ERROR] [0x81]=0x%02x\n", buffer[0]);
                return TRUE;
index c03d30ff2c8c2aab40528fd6ff2e224bb24d91d4..c4c8d418e52ead77024443ed31a68ac3e550e2d7 100644 (file)
@@ -142,30 +142,29 @@ static void init_lcm_registers(void)
 #else    
        //printk("[IND][K] y_____1%s\n", __func__);
 #endif
-       //[BUGFIX]-Mod-BEGIN by SCDTABLET.jinghuang@tcl.com,05/21/2015,1008656£¬
-       //import gamma2.2 V1 parameters.
-       data_array[0] = 0x77801500;     
+
+       data_array[0] = 0x47801500;     
        dsi_set_cmdq(&data_array, 1, 1);        
        MDELAY(1);      
-       data_array[0] = 0x77811500;     
+       data_array[0] = 0x40811500;     
        dsi_set_cmdq(&data_array, 1, 1);        
        MDELAY(1);      
-       data_array[0] = 0xa8821500;     
+       data_array[0] = 0x04821500;     
        dsi_set_cmdq(&data_array, 1, 1);        
        MDELAY(1);      
-       data_array[0] = 0xfe831500;     
+       data_array[0] = 0x77831500;     
        dsi_set_cmdq(&data_array, 1, 1);        
        MDELAY(1);      
-       data_array[0] = 0xb0841500;     
+       data_array[0] = 0x0F841500;     
        dsi_set_cmdq(&data_array, 1, 1);        
        MDELAY(1);      
-       data_array[0] = 0x77851500;     
+       data_array[0] = 0x70851500;     
        dsi_set_cmdq(&data_array, 1, 1);        
        MDELAY(1);      
-       data_array[0] = 0x77861500;     
+       data_array[0] = 0x70861500;     
        dsi_set_cmdq(&data_array, 1, 1);        
        MDELAY(1);
-       //[BUGFIX]-Mod-END by SCDTABLET.jinghuang@tcl.com
+       
 }
 
 
@@ -316,7 +315,7 @@ static unsigned int lcm_esd_check(void)
        read_reg_v2(0x81, buffer, 1);
        //printk("\n ZERO] [0x81]=0x%02x\n", buffer[0]);
 
-       if(buffer[0] != 0x77)
+       if(buffer[0] != 0x40)
        {
                printk("[LCM ERROR] [0x81]=0x%02x\n", buffer[0]);
                return TRUE;
index e420a6034117cd44a780d664cb1ffd5aa94b5623..d40d1733791e2d35ca65e73bad7ed27222c80b9a 100644 (file)
@@ -300,20 +300,15 @@ static void lcm_init(void)
     lcd_reset(0);
     lcd_power_en(0);
     lcd_power_en(1);
+    MDELAY(5);
+       mt_set_gpio_out(GPIO_LCM_PWR_EN, GPIO_OUT_ONE);//iml8881 bias
     MDELAY(50);
     lcd_reset(1);
-       MDELAY(20);
+       MDELAY(15);
        lcd_reset(0);
-       MDELAY(20);
+       MDELAY(15);
        lcd_reset(1);
-    MDELAY(20);
-       
-    mt_set_gpio_out(GPIO_LCM_PWR_EN, GPIO_OUT_ONE);//iml8881 bias
-    MDELAY(50);
-#ifdef BUILD_LK
-       //extern int tps65640_e2prom_data_check(void);
-       //tps65640_e2prom_data_check(); 
-#endif
+    MDELAY(15);
 
        push_table(lcm_initialization_setting, sizeof(lcm_initialization_setting) / sizeof(struct LCM_setting_table), 1);
 }
@@ -329,9 +324,9 @@ static void lcm_suspend(void)
     printk("%s, kernel", __func__);
 #endif
        
+       lcd_reset(0);
+       MDELAY(5);
        mt_set_gpio_out(GPIO_LCM_PWR_EN, GPIO_OUT_ZERO);//iml8881 bias
-       MDELAY(10);
-    lcd_reset(0);
     lcd_power_en(0);
     MDELAY(10);
 }
diff --git a/drivers/misc/mediatek/lcm/rm72013_wxga_dsi_vdo/Makefile b/drivers/misc/mediatek/lcm/rm72013_wxga_dsi_vdo/Makefile
new file mode 100755 (executable)
index 0000000..be2a341
--- /dev/null
@@ -0,0 +1,9 @@
+#
+# Makefile for misc devices that really don't fit anywhere else.
+#
+include $(srctree)/drivers/misc/mediatek/Makefile.custom
+
+obj-y += rm72013_wxga_dsi_vdo.o
+
+
+
diff --git a/drivers/misc/mediatek/lcm/rm72013_wxga_dsi_vdo/rm72013_wxga_dsi_vdo.c b/drivers/misc/mediatek/lcm/rm72013_wxga_dsi_vdo/rm72013_wxga_dsi_vdo.c
new file mode 100644 (file)
index 0000000..09da4f5
--- /dev/null
@@ -0,0 +1,350 @@
+#ifdef BUILD_LK
+#include <string.h>
+//Evan add
+#include <debug.h>
+#include <sys/types.h>
+#include <platform/mt_i2c.h>
+//Evan add end
+#else
+#include <linux/string.h>
+#endif
+
+#ifdef BUILD_LK
+#include <platform/mt_gpio.h>
+#include <platform/mt_pmic.h>
+#else
+#include <mach/mt_gpio.h>
+#include <mach/mt_pm_ldo.h>
+#include <mach/upmu_common.h>
+#endif
+#include "lcm_drv.h"
+
+// ---------------------------------------------------------------------------
+//  Local Constants
+// ---------------------------------------------------------------------------
+#define FRAME_WIDTH  (800)
+#define FRAME_HEIGHT (1280)
+
+#define REGFLAG_DELAY                                                                  0XFE
+#define REGFLAG_END_OF_TABLE                                                           0xFF   // END OF REGISTERS MARKER
+
+#define LCM_DSI_CMD_MODE    0
+#define LCM_ID 0x03  //DPT+AUO+Rm72013
+
+// ---------------------------------------------------------------------------
+//  Local Variables
+// ---------------------------------------------------------------------------
+static LCM_UTIL_FUNCS lcm_util = {
+    .set_gpio_out = NULL,
+};
+
+#define SET_RESET_PIN(v)                                                               (lcm_util.set_reset_pin((v)))
+#define UDELAY(n)                                                                                      (lcm_util.udelay(n))
+#define MDELAY(n)                                                                                      (lcm_util.mdelay(n))
+
+// ---------------------------------------------------------------------------
+//  Local Functions
+// ---------------------------------------------------------------------------
+#define dsi_set_cmdq_V2(cmd, count, ppara, force_update)    lcm_util.dsi_set_cmdq_V2(cmd, count, ppara, force_update)
+#define dsi_set_cmdq(pdata, queue_size, force_update)          lcm_util.dsi_set_cmdq(pdata, queue_size, force_update)
+#define wrtie_cmd(cmd)                                                                         lcm_util.dsi_write_cmd(cmd)
+#define write_regs(addr, pdata, byte_nums)                                     lcm_util.dsi_write_regs(addr, pdata, byte_nums)
+#define read_reg                                                                                       lcm_util.dsi_read_reg()
+#define read_reg_v2(cmd, buffer, buffer_size)               lcm_util.dsi_dcs_read_lcm_reg_v2(cmd, buffer, buffer_size)    
+
+struct LCM_setting_table {
+    unsigned cmd;
+    unsigned char count;
+    unsigned char para_list[64];
+};
+
+static struct LCM_setting_table lcm_initialization_setting[] = {
+       {0x50,1,{0x77}},
+       {0xE1,1,{0x66}},
+       {0xDC,1,{0x67}},
+       {0xD3,1,{0xC8}},
+       {0x50,1,{0x00}},
+       {0xF0,2,{0x5A,0x5A}},
+       {0xF5,1,{0x96}},
+       {0xC3,3,{0x40,0x00,0x28}},
+       {REGFLAG_DELAY, 6, {}},
+       {0x11,1,{}},
+       {0x29,1,{}},
+       {REGFLAG_DELAY, 200, {}},
+       {REGFLAG_END_OF_TABLE, 0x00, {}}
+};
+
+static struct LCM_setting_table lcm_power_off_setting[] = {
+       {0x28,1,{}},
+       {0x10,1,{}},
+       {REGFLAG_DELAY, 5, {}},
+       {0xF0,2,{0x5A,0x5A}},
+       {0xC3,3,{0x40,0x00,0x20}},
+       {REGFLAG_END_OF_TABLE, 0x00, {}}
+};
+
+static void lcd_power_en(unsigned char enabled)
+{
+    if (enabled) {      
+#ifdef BUILD_LK
+               upmu_set_rg_vgp1_vosel(0x7);//3.3V
+               upmu_set_rg_vgp1_en(0x1);
+               upmu_set_rg_vgp3_vosel(0x3);//1.8V
+               upmu_set_rg_vgp3_en(0x1);
+#else
+               upmu_set_rg_vgp1_vosel(0x7);//3.3V
+               upmu_set_rg_vgp1_en(0x1);
+               upmu_set_rg_vgp3_vosel(0x3);//1.8V
+               upmu_set_rg_vgp3_en(0x1);
+#endif
+    } else {      
+#ifdef BUILD_LK
+               upmu_set_rg_vgp1_en(0);
+               upmu_set_rg_vgp1_vosel(0);
+               upmu_set_rg_vgp3_en(0);
+               upmu_set_rg_vgp3_vosel(0);
+#else
+               upmu_set_rg_vgp1_en(0);
+               upmu_set_rg_vgp1_vosel(0);
+               upmu_set_rg_vgp3_en(0);
+               upmu_set_rg_vgp3_vosel(0);
+#endif
+    }
+}
+
+
+static void lcd_reset(unsigned char enabled)
+{
+    if (enabled) {
+        mt_set_gpio_out(GPIO_LCM_RST, GPIO_OUT_ONE);
+    } else {   
+        mt_set_gpio_out(GPIO_LCM_RST, GPIO_OUT_ZERO);          
+    }
+}
+
+// ---------------------------------------------------------------------------
+//  LCM Driver Implementations
+// ---------------------------------------------------------------------------
+static void lcm_set_util_funcs(const LCM_UTIL_FUNCS *util)
+{
+    memcpy(&lcm_util, util, sizeof(LCM_UTIL_FUNCS));
+}
+
+
+static void lcm_get_params(LCM_PARAMS *params)
+{
+    memset(params, 0, sizeof(LCM_PARAMS));
+
+    params->type     = LCM_TYPE_DSI;
+    params->width    = FRAME_WIDTH;
+    params->height   = FRAME_HEIGHT;
+    params->dsi.mode = SYNC_EVENT_VDO_MODE; //BURST_VDO_MODE;BURST_VDO_MODE;
+
+    // DSI
+    /* Command mode setting */
+    params->dsi.LANE_NUM                               = LCM_FOUR_LANE;
+    //The following defined the fomat for data coming from LCD engine.
+    params->dsi.data_format.format             = LCM_DSI_FORMAT_RGB888;  //LCM_DSI_FORMAT_RGB666;
+
+    // Video mode setting              
+    params->dsi.PS = LCM_PACKED_PS_24BIT_RGB888;  //LCM_PACKED_PS_18BIT_RGB666;
+
+    params->dsi.vertical_sync_active                           = 4;//0;
+    params->dsi.vertical_backporch                                     = 8;//23;
+    params->dsi.vertical_frontporch                            = 8;
+    params->dsi.vertical_active_line                           = FRAME_HEIGHT; 
+
+    params->dsi.horizontal_sync_active                         = 4;//0;
+    params->dsi.horizontal_backporch                           = 132;//160;
+    params->dsi.horizontal_frontporch                          = 24; //100;//160;
+    params->dsi.horizontal_active_pixel                        = FRAME_WIDTH;
+
+    params->dsi.PLL_CLOCK = 250;//148;
+}
+
+static void push_table(struct LCM_setting_table *table, unsigned int count, unsigned char force_update)
+{
+       unsigned int i;
+
+    for(i = 0; i < count; i++) {
+        unsigned cmd;
+        cmd = table[i].cmd;
+               
+        switch (cmd) {
+            case REGFLAG_DELAY :
+                MDELAY(table[i].count);
+                break;
+                               
+            case REGFLAG_END_OF_TABLE :
+                break;
+                               
+            default:
+                               dsi_set_cmdq_V2(cmd, table[i].count, table[i].para_list, force_update);
+               }
+    }
+       
+}
+
+static void lcm_init(void)
+{
+    unsigned int data_array[16];
+       
+#ifdef BUILD_LK
+    printf("%s, LK \n", __func__);
+#else
+    printk("%s, kernel", __func__);
+#endif
+
+    lcd_reset(0);
+    lcd_power_en(0);
+    lcd_power_en(1);
+    MDELAY(5);
+       mt_set_gpio_out(GPIO_LCM_PWR_EN, GPIO_OUT_ONE);//iml8881 bias
+       MDELAY(50);
+    lcd_reset(1);
+       MDELAY(15);
+       lcd_reset(0);
+       MDELAY(15);
+       lcd_reset(1);
+    MDELAY(15);
+
+       push_table(lcm_initialization_setting, sizeof(lcm_initialization_setting) / sizeof(struct LCM_setting_table), 1);
+}
+
+
+static void lcm_suspend(void)
+{
+    unsigned int data_array[16];
+
+#ifdef BUILD_LK
+    printf("%s, LK \n", __func__);
+#else
+    printk("%s, kernel", __func__);
+#endif
+
+       push_table(lcm_power_off_setting, sizeof(lcm_power_off_setting) / sizeof(struct LCM_setting_table), 1);
+
+    lcd_reset(0);
+       mt_set_gpio_out(GPIO_LCM_PWR_EN, GPIO_OUT_ZERO);//iml8881 bias
+    lcd_power_en(0);
+    MDELAY(10);
+}
+
+
+static void lcm_resume(void)
+{
+    unsigned int data_array[16];
+
+#ifdef BUILD_LK
+    printf("%s, LK \n", __func__);
+#else
+    printk("%s, kernel", __func__);
+#endif
+       
+       lcm_init();
+}
+/*
+static unsigned int lcm_esd_test = FALSE;
+
+static unsigned int lcm_esd_check(void)
+{
+
+  #ifndef BUILD_LK
+
+       char  buffer[1];
+       int   array[4];
+       int ret = 0;
+
+       if(lcm_esd_test)
+       {
+               lcm_esd_test = FALSE;
+               return TRUE;
+       }
+
+       array[0] = 0x00013700;
+       dsi_set_cmdq(array, 1, 1);
+       read_reg_v2(0x0A, buffer, 1);
+       //printk("[LCM ERROR] [0x0A]=0x%02x\n", buffer[0]);
+       if(buffer[0] != 0x9C)
+       {
+       //      printk("[LCM ERROR] [0x0A]=0x%02x\n", buffer[0]);
+               ret++;
+       }
+
+       // return TRUE: need recovery
+       // return FALSE: No need recovery
+       if(ret)
+       {
+               return TRUE;
+       }
+       else
+       {
+               return FALSE;
+       }
+ #endif
+}
+
+static unsigned int lcm_esd_recover(void)
+{
+#ifdef BUILD_LK
+    printf("%s, LK \n", __func__);
+#else
+    printk("%s, KERNEL \n", __func__);
+#endif
+       lcm_init();
+       return TRUE;
+}
+*/
+static unsigned int lcm_compare_id(void)
+{
+    unsigned int id1 = 0, id2 = 0, id = 0;
+
+#ifdef BUILD_LK
+       printf("%s, LK \n", __func__);
+#endif
+    lcd_reset(0);
+    lcd_power_en(0);
+    lcd_power_en(1);
+    lcd_reset(1);
+    MDELAY(20);
+       lcd_reset(0);
+       MDELAY(20);
+       lcd_reset(1);
+       MDELAY(20);
+
+       mt_set_gpio_mode(GPIO_HALL_2_PIN, GPIO_HALL_2_PIN_M_GPIO);      
+       mt_set_gpio_dir(GPIO_HALL_2_PIN, GPIO_DIR_IN);
+       mt_set_gpio_pull_enable(GPIO_HALL_2_PIN, GPIO_PULL_DISABLE);
+       mt_set_gpio_mode(GPIO_HALL_1_PIN, GPIO_HALL_1_PIN_M_GPIO);      
+       mt_set_gpio_dir(GPIO_HALL_1_PIN, GPIO_DIR_IN);
+       mt_set_gpio_pull_enable(GPIO_HALL_1_PIN, GPIO_PULL_DISABLE);
+       MDELAY(2);
+
+       id1 = mt_get_gpio_in(GPIO_HALL_1_PIN);
+    id2 = mt_get_gpio_in(GPIO_HALL_2_PIN);
+       id = (id1<<1)|(id2);
+#ifdef BUILD_LK
+    printf("DPT+AUO id1=%d,id2=%d,id=0x%x\n",id1,id2,id);
+#else
+    printk("DPT+AUO id1=%d,id2=%d,id=0x%x\n",id1,id2,id);
+#endif
+       lcd_reset(0);
+    lcd_power_en(0);
+    MDELAY(10);
+    return (LCM_ID == id)?1:0;
+}
+
+LCM_DRIVER rm72013_wxga_dsi_vdo_lcm_drv = 
+{
+    .name           = "rm72013_wxga_dsi_vdo",
+    .set_util_funcs = lcm_set_util_funcs,
+    .get_params     = lcm_get_params,
+    .init           = lcm_init,
+    .suspend        = lcm_suspend,
+    .resume         = lcm_resume,
+       //.esd_check            = lcm_esd_check,
+       //.esd_recover  = lcm_esd_recover,
+    .compare_id    = lcm_compare_id,
+};
+
+
index 6f6142ba581613df475d4cdd7ea7012ba4c5634f..6e1fd7a64aa15d7b6035d88e0a8167f9d3cf6d10 100644 (file)
  * variables
  ***************************************************************************/
 struct cust_mt65xx_led *bl_setting = NULL;
-/*[PLATFORM]-ADD-BEIGIN by falin.luo 2015.4.17*/
-/*hall sensor use bl brighrness to detect system status*/
-#ifdef CONFIG_MTK_HALL
-unsigned int bl_brightness = 102;
-#else
 static unsigned int bl_brightness = 102;
-#endif
-/*[PLATFORM]-ADD-END by falin.luo 2015.4.17*/
 static unsigned int bl_duty = 21;
 static unsigned int bl_div = CLK_DIV1;
 static unsigned int bl_frequency = 32000;
index 27cde7780bfa19bd21d8abca4ec05592dcd62ef9..21e4798a6532842ee066cb9b346a34acbb0cfe6b 100644 (file)
@@ -45,7 +45,15 @@ static DEFINE_MUTEX(leds_pmic_mutex);
  * variables
  ***************************************************************************/
 //struct cust_mt65xx_led* bl_setting_hal = NULL;
+
+ /*[PLATFORM]-ADD-BEIGIN by falin.luo 2015/6/15*/
+ /*hall sensor use bl_brightness_hal to detect system status*/
+#ifdef CONFIG_MTK_HALL
+unsigned int bl_brightness_hal = 102;
+#else
  static unsigned int bl_brightness_hal = 102;
+#endif
+/*[PLATFORM]-ADD-END by falin.luo 2015/6/15*/
 static unsigned int bl_duty_hal = 21;
 static unsigned int bl_div_hal = CLK_DIV1;
 static unsigned int bl_frequency_hal = 32000;
index 922be8189b624c2a295ec9acf4e74c1104994201..de6152670cc8d0d50ba17c2cefebc7cfa9bac469 100644 (file)
@@ -262,7 +262,12 @@ long sec_core_ioctl(struct file *file, unsigned int cmd, unsigned long arg)
             {
                 return -EFAULT;
             }
-            
+
+            if (hevc_blk.len > HEVC_BLK_LEN) {
+                SMSG(TRUE, "[%s] eop block size is too large!", MOD);
+                return -EFAULT;
+            }
+
             if ((hevc_blk.len % CI_BLK_SIZE) == 0)
             {
                 cipher_len = hevc_blk.len;
@@ -290,6 +295,11 @@ long sec_core_ioctl(struct file *file, unsigned int cmd, unsigned long arg)
                 return -EFAULT;
             }
 
+            if (hevc_blk.len > HEVC_BLK_LEN) {
+                SMSG(TRUE, "[%s] dop block size is too large!", MOD);
+                return -EFAULT;
+            }
+
             if ((hevc_blk.len % CI_BLK_SIZE) == 0)
             {
                 cipher_len = hevc_blk.len;
index 3d7847695246eabed584a07ce4deb3347f25b6f4..d3edebb1b2772268d6f5ea65cee58831b5ddccfc 100644 (file)
@@ -33,7 +33,7 @@ void mrdump_reserve_memory(void)
        /* We must reserved the lk block, can we pass it from lk? */    
        memblock_reserve(LK_LOAD_ADDR, LK_LOAD_SIZE);
 
-       memblock_reserve(MRDUMP_CB_ADDR, MRDUMP_CB_SIZE);
+       memblock_reserve(MRDUMP_CB_ADDR, PAGE_ALIGN(sizeof(struct mrdump_control_block)));
        cblock = (struct mrdump_control_block *)__va(MRDUMP_CB_ADDR);
 
        mrdump_platform_init(cblock, &mrdump_mt6582_platform);
index 086be7480078e5feb853e661ed5b714567c114c7..f2acc302f3f5f4874201486a8436a4709d7f7924 100644 (file)
@@ -115,6 +115,22 @@ static ssize_t mt_printk_ctrl_write(struct file *filp, const char *ubuf, ssize_t
        return cnt;
 }
 
+//[BUGFIX]-Add-BEGIN by SCDTABLET.(fangyou.wang),10/10/2015,1097303,                 
+//auto reboot after power off                                              
+void force_enable_uart_log(void)
+{
+       if(mt_need_uart_console){
+                pr_err("uart log alrady opened!!!!\n");
+               return;
+       }
+
+       mt_need_uart_console = 1;
+       mt_enable_uart();
+       pr_err("--------------need uart log,force open uart log now-------------\n");
+
+}
+//[BUGFIX]-Add-END by SCDTABLET.(fangyou.wang)
+
 static int __init init_mt_printk_ctrl(void)
 {
        struct proc_dir_entry *pe;
index 2fc4760d0a5151eae644a14cb6483553f2ae0ed0..6e4484e732851f215cfe82371e86510a501d1a7b 100644 (file)
@@ -343,8 +343,8 @@ static int g_block_size;
 static u32 PAGES_PER_BLOCK = 255;
 static bool g_bSyncOrToggle = false;
 static int g_iNFI2X_CLKSRC = ARMPLL;
-extern unsigned int flash_number;
-extern flashdev_info_t gen_FlashTable_p[MAX_FLASH];
+//extern unsigned int flash_number;
+//extern flashdev_info_t gen_FlashTable_p[MAX_FLASH];
 extern int part_num;
 
 #if CFG_2CS_NAND
index c8f9fff56077c0d02673896364559bb70180e364..b5748cf402134ca880cf76915c0945514154762d 100644 (file)
@@ -564,7 +564,7 @@ static void hw_bc11_dump_register(void)
        upmu_set_rg_usbdl_rst(1);               //force leave USBDL mode
    
        #if defined(HIGH_BATTERY_VOLTAGE_SUPPORT)
-       fan5405_reg_config_interface(0x06,0x77); // ISAFE = 1250mA, VSAFE = 4.34V
+       fan5405_reg_config_interface(0x06,0x78); // ISAFE = 1250mA, VSAFE = 4.36V
        #else
        fan5405_reg_config_interface(0x06,0x70);
        #endif
@@ -631,6 +631,7 @@ static void hw_bc11_dump_register(void)
        kal_uint16 register_value;
 
        register_value = charging_parameter_to_value(VBAT_CV_VTH, GETARRAYNUM(VBAT_CV_VTH) ,*(kal_uint32 *)(data));
+
        fan5405_set_oreg(register_value); 
 
        return status;
index 7f5cb9acc7417321f5d82aa63318684b844f423e..ed5a2658266beed2e0932fc7fce9626b33ace12c 100644 (file)
@@ -568,6 +568,7 @@ static void hw_bc11_dump_register(void)
 
        upmu_set_rg_vcdt_mode(0);       //VCDT_MODE
        upmu_set_rg_vcdt_hv_en(1);      //VCDT_HV_EN    
+
        upmu_set_rg_usbdl_set(0);       //force leave USBDL mode
        upmu_set_rg_usbdl_rst(1);               //force leave USBDL mode
 
index 320feed4122b2c85abcdf483c3a189a4dc9e5d71..5cb2d7e6c7a3892497e2c7c2afcd74dbeaf8a9af 100644 (file)
@@ -20,7 +20,7 @@
 #ifndef _fan5405_SW_H_
 #define _fan5405_SW_H_
 
-//#define HIGH_BATTERY_VOLTAGE_SUPPORT
+#define HIGH_BATTERY_VOLTAGE_SUPPORT
 
 #define fan5405_CON0      0x00
 #define fan5405_CON1      0x01
index 4960c5cdbb0447a1765ac8bad06cbd727a0b27c6..eeb2a323f14a89113cfd23b24847c05947cd4605 100644 (file)
 
 static char debug_buffer[4096];
 
-
-static char STR_HELP[] =
-    "\n"
-    "USAGE\n"
-    "        echo [ACTION]... > mau_dbg\n"
-    "\n"
-    "ACTION\n"
-    "        module1|module2?R/W/RW(startPhyAddr,endPhyAddr)@MAU_Enty_ID\n"
-    "             MAU will monitor specified module whether R/W specified range of memory\n"
-    "             example: echo tvc|lcd_r?R(0,0x1000)@1 > mau_dbg\n"
-    "             you can use [all] to specify all modules\n"
-    "             example: echo all?W(0x2000,0x9000)@2 > mau_dbg\n"
-    "\n"
-    "        module1|module2@MAU_Enty_ID:off\n"
-    "             Turn off specified module on specified MAU Entry\n"
-    "             example: echo tvc|lcd_r@1:off > mau_dbg\n"
-    "\n"
-    "\n"
-    "        all:off\n"
-    "             Turn off all of modules\n"
-    "             example: echo all:off > mau_dbg\n"
-    "\n"
-    "        list modules\n"
-    "             list all module names MAU could monitor\n"
-    "\n"
-    "        reg:[MPU|MAU1|MAU2]\n"
-    "             dump hw register values\n"
-    "\n"
-    "        regw:addr=val\n"
-    "             write hw register\n"
-    "\n"
-    "        regr:addr\n"
-    "             read hw register\n"
-    "\n"
-    "        m4u_log:on\n"
-    "             start to print m4u translate miss rate every second \n"
-    "\n"
-    "        m4u_log:off\n"
-    "             stop to print m4u translate miss rate every second \n"
-    "\n"
-    "        m4u_debug:[command] \n"
-    "             input a command, used for debug \n"
-    "\n"
-    "        m4u_monitor:on\n"
-    "             start to print m4u translate miss rate every second \n"
-    "\n"
-    "        m4u_monitor:off\n"
-    "             stop to print m4u translate miss rate every second \n";
-
-
-static void process_dbg_opt(const char *opt)
-{
-    //m4u log
-    if (0 == strncmp(opt, "m4u_log:", 8))
-    {
-        if (0 == strncmp(opt + 8, "on", 2))
-            m4u_log_on();
-        else if (0 == strncmp(opt + 8, "off", 3))
-            m4u_log_off();
-        else
-            goto Error;
-    }
-    //m4u debug
-    if (0 == strncmp(opt, "m4u_debug:", 10))
-    {
-        unsigned int command;
-        char *p = (char *)opt + 10;
-        command = (unsigned int) simple_strtoul(p, &p, 10);
-        SMIMSG("m4u_debug_command, command=%d ", command);
-        m4u_debug_command(command);
-    }
-
-#ifdef __MAU_SPC_ENABLE__
-    //mau dump
-    if (0 == strncmp(opt, "mau_stat:", 9))
-    {
-               char *p = (char *)opt + 9;
-        unsigned int larb=(unsigned int)simple_strtoul(p, &p, 16);
-        if(larb>SMI_LARB_NR)
-            SMIERR("debug error: larb=%d\n", larb);
-        mau_dump_status(larb);
-    }
-
-    if (0 == strncmp(opt, "mau_config:", 11 ))
-    {
-        MTK_MAU_CONFIG MauConf;
-               unsigned int larb,entry, rd, wt, vir, start, end, port_msk;
-               char *p = (char *)opt + 11;
-               larb = (unsigned int) simple_strtoul(p, &p, 16);
-               p++;
-               entry = (unsigned int) simple_strtoul(p, &p, 16);
-               p++;
-               rd = (unsigned int) simple_strtoul(p, &p, 16);
-               p++;
-               wt = (unsigned int) simple_strtoul(p, &p, 16);
-               p++;
-               vir = (unsigned int) simple_strtoul(p, &p, 16);
-               p++;
-               start = (unsigned int) simple_strtoul(p, &p, 16);
-        p++;
-               end = (unsigned int) simple_strtoul(p, &p, 16);
-               p++;
-               port_msk = (unsigned int) simple_strtoul(p, &p, 16);
-
-               SMIMSG("larb=%d,entry=%d,rd=%d wt=%d vir=%d \n"
-            "start=0x%x end=0x%x msk=0x%x \n",
-            larb, entry, rd, wt, vir, start, end, port_msk);
-
-        MauConf.larb = larb;
-        MauConf.entry = entry;
-        MauConf.monitor_read = rd;
-        MauConf.monitor_write = wt;
-        MauConf.virt = vir;
-        MauConf.start = start;
-        MauConf.end = end;
-        MauConf.port_msk = port_msk;
-        mau_config(&MauConf);
-
-    }
-
-
-    if (0 == strncmp(opt, "spc_config:", 11 ))
-    {
-        MTK_SPC_CONFIG pCfg;
-               char *p = (char *)opt + 11;
-
-        SMIMSG("%s", p);
-        //0-no protect; 1-sec rw; 2-sec_rw nonsec_r; 3-no access
-               pCfg.domain_0_prot = (unsigned int) simple_strtoul(p, &p, 16);
-
-        SMIMSG("%d,%s", pCfg.domain_0_prot, p);
-               p++;
-               pCfg.domain_1_prot = (unsigned int) simple_strtoul(p, &p, 16);
-               p++;
-        SMIMSG("%d", pCfg.domain_1_prot);
-               pCfg.domain_2_prot = (unsigned int) simple_strtoul(p, &p, 16);
-               p++;
-        SMIMSG("%d", pCfg.domain_2_prot);
-               pCfg.domain_3_prot = (unsigned int) simple_strtoul(p, &p, 16);
-               p++;
-        SMIMSG("%d", pCfg.domain_3_prot);
-               pCfg.start = (unsigned int) simple_strtoul(p, &p, 16);
-               p++;
-        SMIMSG("%d", pCfg.domain_0_prot);
-               pCfg.end = (unsigned int) simple_strtoul(p, &p, 16);
-
-               SMIMSG("prot=(%d,%d,%d,%d), start=0x%x, end=0x%x\n",
-            pCfg.domain_0_prot,pCfg.domain_1_prot,
-            pCfg.domain_2_prot,pCfg.domain_3_prot,
-            pCfg.start,pCfg.end);
-
-        spc_config(&pCfg);
-
-    }
-
-    if (0 == strncmp(opt, "spc_status", 10 ))
-    {
-        spc_status_check();
-    }
-
-    if (0 == strncmp(opt, "spc_dump_reg", 12 ))
-    {
-        spc_dump_reg();
-    }
-#endif
-
-    if (0 == strncmp(opt, "touch_sysram", 10 ))
-    {
-        volatile unsigned int *va;
-        unsigned int i;
-
-        //va = ioremap_nocache(0x1200C000, 1024*80);
-        va=(volatile unsigned int *)0xf2000000;
-
-        for(i=0; i<1024*80/4; i++)
-        {
-            va[i] = i;
-        }
-
-        SMIMSG("cpu read sysram: 0x%x,0x%x,0x%x,0x%x,0x%x,0x%x,0x%x",
-            va[0],va[1],va[2],va[3],va[100],va[222],va[444]);
-
-    }
-
-    if (0 == strncmp(opt, "set_reg:", 8 ))
-    {
-        unsigned int addr, val;
-               char *p = (char *)opt + 8;
-
-               addr = (unsigned int) simple_strtoul(p, &p, 16);
-               p++;
-               val = (unsigned int) simple_strtoul(p, &p, 16);
-
-               SMIMSG("set register: 0x%x = 0x%x\n", addr, val);
-
-        COM_WriteReg32(addr, val);
-    }
-    if (0 == strncmp(opt, "get_reg:", 8 ))
-    {
-        unsigned int addr;
-               char *p = (char *)opt + 8;
-
-               addr = (unsigned int) simple_strtoul(p, &p, 16);
-
-               SMIMSG("get register: 0x%x = 0x%x \n", addr, COM_ReadReg32(addr));
-    }
-
-
-
-    return;
-Error:
-    SMIERR("parse command error!\n");
-    SMIMSG("%s", STR_HELP);
-}
-
-
-static void process_dbg_cmd(char *cmd)
-{
-    char *tok;
-    while ((tok = strsep(&cmd, " ")) != NULL)
-    {
-        process_dbg_opt(tok);
-    }
-}
-
-
 // ---------------------------------------------------------------------------
 //  Debug FileSystem Routines
 // ---------------------------------------------------------------------------
@@ -286,32 +60,8 @@ static ssize_t debug_read(struct file *file,
     return simple_read_from_buffer(ubuf, count, ppos, debug_buffer, n);
 }
 
-
-static ssize_t debug_write(struct file *file,
-                           const char __user *ubuf, size_t count, loff_t *ppos)
-{
-    const int debug_bufmax = sizeof(debug_buffer) - 1;
-       size_t ret;
-
-       ret = count;
-
-       if (count > debug_bufmax)
-        count = debug_bufmax;
-
-       if (copy_from_user(&debug_buffer, ubuf, count))
-               return -EFAULT;
-
-       debug_buffer[count] = 0;
-
-    process_dbg_cmd(debug_buffer);
-
-    return ret;
-}
-
-
 static struct file_operations debug_fops = {
        .read  = debug_read,
-    .write = debug_write,
        .open  = debug_open,
 };
 
index 3cba68360668f9c1f48c5b58ed65fbc597e7e8b5..9953d83d221143a41b3c2cfb5b18c4d125521fd8 100644 (file)
@@ -83,7 +83,10 @@ void Afe_Set_Reg(uint32 offset, uint32 value, uint32 mask)
     volatile uint32 *AFE_Register = (volatile uint32 *)address;
     volatile uint32 val_tmp;
 
-    //PRINTK_AFE_REG("Afe_Set_Reg offset=%x, value=%x, mask=%x \n",offset,value,mask);
+       if (offset > AFE_MAX_ADDR_OFFSET)
+               return;
+
+
     val_tmp = Afe_Get_Reg(offset);
     val_tmp &= (~mask);
     val_tmp |= (value & mask);
@@ -100,7 +103,11 @@ uint32 Afe_Get_Reg(uint32 offset)
     volatile uint32 address = (AFE_BASE + offset);
 #endif
     volatile uint32 *value;
-    //PRINTK_AFE_REG("Afe_Get_Reg offset=%x address = %x \n",offset,address);
+
+       if (offset > AFE_MAX_ADDR_OFFSET)
+               return 0;
+
+
     value = (volatile uint32 *)(address);
     return *value;
 }
index 216c51b1309370c4b24c3ca4370fd533e1a5e73e..cadacdaa7180d58e1d2874a0c4d1415b99d44180 100644 (file)
@@ -917,6 +917,8 @@ typedef struct
 #define AUDPLL_TUNER_EN_LEN      1
 #define AUDPLL_TUNER_EN_MASK     0x80000000
 
+/* The maximum address offset of Audio Front End */
+#define AFE_MAX_ADDR_OFFSET    (0x570)
 #define CLK_APLL_SEL_POS     16
 #define CLK_APLL_SEL_LEN     3
 #define CLKSQ_MUX_CK     0
index 063964b85ab4e74c7c99de53a1e521d22a58e091..bc28a956cfe06041544cef9d29b32fd7d22136bf 100644 (file)
@@ -70,6 +70,11 @@ void Ana_Set_Reg(uint32 offset, uint32 value, uint32 mask)
     int ret = 0;
 #ifdef AUDIO_USING_WRAP_DRIVER
     uint32 Reg_Value = Ana_Get_Reg(offset);
+
+       if (!(offset <= AUDTOP_MAX_ADDR_OFFSET ||
+               (offset >= ABB_AFE_ADDR_START && offset <= ABB_AFE_ADDR_END)))
+               return;
+
     Reg_Value &= (~mask);
     Reg_Value |= (value & mask);
     ret = pwrap_write(offset, Reg_Value);
@@ -86,6 +91,11 @@ uint32 Ana_Get_Reg(uint32 offset)
     // get pmic register
     int ret = 0;
     uint32 Rdata = 0;
+
+       if (!(offset <= AUDTOP_MAX_ADDR_OFFSET ||
+               (offset >= ABB_AFE_ADDR_START && offset <= ABB_AFE_ADDR_END)))
+               return 0;
+
 #ifdef AUDIO_USING_WRAP_DRIVER
     ret = pwrap_read(offset, &Rdata);
 #endif
index d20f9f7220c0c8703975d710e61eb9456ab963b2..59b16cb1b682431ba6f32e1d07bb94ec9bea673f 100644 (file)
 #define ABB_AFE_PMIC_NEWIF_CFG3 (PMIC_ABB_AFE_REG_BASE+0x002A)
 #define ABB_AFE_TOP_CON0    (PMIC_ABB_AFE_REG_BASE+0x002C)
 #define ABB_AFE_MON_DEBUG0  (PMIC_ABB_AFE_REG_BASE+0x002E)
+
+
+/* The valid range of audio digital hardware in PMIC */
+#define ABB_AFE_ADDR_START     ABB_AFE_CON0
+#define ABB_AFE_ADDR_END               ABB_AFE_MON_DEBUG0
+
 //---------------digital pmic  register define -------------------------------------------
 #if 0//
 #define AFE_PMICDIG_AUDIO_BASE        (0x4000)
 #include <mach/upmu_hw.h>
 #endif
 
+/* The valid range of audio analog hardware in PMIC */
+#define AUDTOP_MAX_ADDR_OFFSET         (0x079A)
 typedef struct
 {
     volatile uint16 Suspend_Ana_ABB_AFE_CON0;
index 7fb596e95ff10532fdbb4991bee1527f8edfaf25..ce7fb58974960439ef4b52238eb7517547010889 100644 (file)
@@ -71,6 +71,11 @@ void Ana_Set_Reg(uint32 offset, uint32 value, uint32 mask)
     int ret = 0;
 #ifdef AUDIO_USING_WRAP_DRIVER
     uint32 Reg_Value = Ana_Get_Reg(offset);
+
+       if (!(offset <= AUDTOP_MAX_ADDR_OFFSET ||
+               (offset >= AFE_ADDR_START && offset <= AFE_ADDR_END)))
+               return;
+
     Reg_Value &= (~mask);
     Reg_Value |= (value & mask);
     ret = pwrap_write(offset, Reg_Value);
@@ -87,6 +92,11 @@ uint32 Ana_Get_Reg(uint32 offset)
     // get pmic register
     int ret = 0;
     uint32 Rdata = 0;
+
+       if (!(offset <= AUDTOP_MAX_ADDR_OFFSET ||
+               (offset >= AFE_ADDR_START && offset <= AFE_ADDR_END)))
+               return 0;
+
 #ifdef AUDIO_USING_WRAP_DRIVER
     ret = pwrap_read(offset, &Rdata);
 #endif
index 387d7fcb81ef794d043f11d6678562fa10b0537e..5a5ae83bb0319f55083e72cd36f741797bbe8aa5 100644 (file)
@@ -69,7 +69,7 @@
 /*****************************************************************************
  *                  R E G I S T E R       D E F I N I T I O N
  *****************************************************************************/
-
 //---------------digital pmic register define start -------------------------------------------
 #define AFE_PMICDIG_AUDIO_BASE        (0x4000)
 #define AFE_UL_DL_CON0               (AFE_PMICDIG_AUDIO_BASE+0x0000)
 #define AFE_SGEN_CFG1               (AFE_PMICDIG_AUDIO_BASE + 0x0042)
 //---------------digital pmic  register define end ---------------------------------------
 
+/* The valid range of audio digital hardware in PMIC */
+#define AFE_ADDR_START AFE_UL_DL_CON0
+#define AFE_ADDR_END           AFE_SGEN_CFG1
+
 //---------------analog pmic  register define start --------------------------------------
 #if 0
 #define AFE_PMICANA_AUDIO_BASE        (0x0)
 #include <mach/upmu_hw.h>
 #endif
 
+/* The valid range of audio analog hardware in PMIC */
+#define AUDTOP_MAX_ADDR_OFFSET         (0x079A)
 //---------------analog pmic register define end ---------------------------------------
 
 typedef struct
index f083d6a12675d994bc7f32bdf23ad6b2c5bf4b5a..ce3bc28435efaed44cbda80b8907b49978518d1a 100755 (executable)
@@ -9,7 +9,7 @@ obj-$(CONFIG_THERMAL) += mtk_cooler_kshutdown.o
 #obj-$(CONFIG_THERMAL) += mtk_cooler_spkrvol.o
 #obj-$(CONFIG_THERMAL) += mtk_cooler_dropcall.o
 obj-$(CONFIG_THERMAL) += mtk_cooler_cam.o
-obj-$(CONFIG_THERMAL) += mtk_cooler_vrt.o
+#obj-$(CONFIG_THERMAL) += mtk_cooler_vrt.o
 
 obj-y += $(subst ",,$(CONFIG_MTK_PLATFORM))/
 
index efa8bd08edadb337e058dd69ca533bd749d52d96..ba1e5727b89fc44b078e98c7a293c6e393015011 100644 (file)
@@ -290,6 +290,7 @@ static ssize_t _cl_bcct_write(struct file *filp, const char __user *buf, size_t
        char tmp[128] = { 0 };
        int klog_on, limit0, limit1, limit2;
 
+       len = (len < 127) ? len : 127;
        /* write data to the buffer */
        if (copy_from_user(tmp, buf, len)) {
                return -EFAULT;
index 857c31e1c6914cade895b962011b34de04e71d26..a2833aa122ba221f628f9fe5e52b218aa0bee546 100644 (file)
@@ -969,6 +969,7 @@ ssize_t wmt_tm_wfd_write(struct file *filp, const char __user *buf, size_t len,
        int ret = 0;
        char tmp[MAX_LEN] = {0};
 
+       len = (len < (MAX_LEN-1)) ? len : (MAX_LEN-1);
        /* write data to the buffer */
        if (copy_from_user(tmp, buf, len)) {
                return -EFAULT;
@@ -1011,6 +1012,7 @@ ssize_t wmt_tm_pid_write(struct file *filp, const char __user *buf, size_t len,
        int ret = 0;
        char tmp[MAX_LEN] = {0};
 
+       len = (len < (MAX_LEN-1)) ? len : (MAX_LEN-1);
        /* write data to the buffer */
        if ( copy_from_user(tmp, buf, len) ) {
                return -EFAULT;
index d7f5b0b218ec8352102d016cb61975861d177bc5..4af8fee2ae865a25cd8a54d1631c7b512c08022a 100644 (file)
@@ -38,6 +38,7 @@ static ssize_t _cl_cam_write(struct file *filp, const char __user *buf, size_t l
        int ret = 0;
        char tmp[MAX_LEN] = { 0 };
 
+       len = (len < (MAX_LEN-1)) ? len : (MAX_LEN-1);
        /* write data to the buffer */
        if (copy_from_user(tmp, buf, len)) {
                return -EFAULT;
index 7f5beb898298aa5f8100af86bb796c5fd61442e4..17fee69c8e5457bb8b85cbc715b6e30e301eae5d 100644 (file)
@@ -64,6 +64,7 @@ static ssize_t _mtk_cl_sd_rst_write(struct file *filp, const char __user *buf, s
        int ret = 0;
        char tmp[MAX_LEN] = { 0 };
 
+       len = (len < (MAX_LEN-1)) ? len : (MAX_LEN-1);
        /* write data to the buffer */
        if (copy_from_user(tmp, buf, len)) {
                return -EFAULT;
@@ -118,6 +119,7 @@ static ssize_t _mtk_cl_sd_pid_write(struct file *filp, const char __user *buf, s
        int ret = 0;
        char tmp[MAX_LEN] = { 0 };
 
+       len = (len < (MAX_LEN-1)) ? len : (MAX_LEN-1);
        /* write data to the buffer */
        if (copy_from_user(tmp, buf, len)) {
                return -EFAULT;
@@ -163,6 +165,7 @@ static ssize_t _mtk_cl_sd_debouncet_write(struct file *filp, const char __user *
        char desc[MAX_LEN] = {0};
        int tmp_dbt = -1;
 
+       len = (len < (MAX_LEN-1)) ? len : (MAX_LEN-1);
        /* write data to the buffer */
        if (copy_from_user(desc, buf, len)) {
                return -EFAULT;
index d5d348b3d4a8e5a4da04df5aff54a0c9088447fc..ea6e459d61ff82d7b39fdb7b59ac1f77fea3ac7a 100644 (file)
@@ -35,6 +35,7 @@ static ssize_t _cl_vrt_write(struct file *filp, const char __user *buf, size_t l
        int ret = 0;
        char tmp[MAX_LEN] = { 0 };
 
+       len = (len < (MAX_LEN-1)) ? len : (MAX_LEN-1);
        /* write data to the buffer */
        if (copy_from_user(tmp, buf, len)) {
                return -EFAULT;
index 34cf50e3a7cc09d6e159a5cf1b51e86295e392f1..0efa990c63835978a329494df8928ee50bee03f9 100644 (file)
@@ -150,12 +150,6 @@ static char STR_HELP[] =
     "        reg:[lcd|dpi|dsi|tvc|tve]\n"
     "             dump hw register values\n"
     "\n"
-    "        regw:addr=val\n"
-    "             write hw register\n"
-    "\n"
-    "        regr:addr\n"
-    "             read hw register\n"
-    "\n"     
     "       cpfbonly:[on|off]\n"
     "             capture UI layer only on/off\n"
     "\n"     
@@ -603,29 +597,6 @@ static void process_dbg_opt(const char *opt)
     {
         dump_layer_info();
     }
-    else if (0 == strncmp(opt, "regw:", 5))
-    {
-        char *p = (char *)opt + 5;
-        unsigned long addr = simple_strtoul(p, &p, 16);
-        unsigned long val  = simple_strtoul(p + 1, &p, 16);
-
-        if (addr) {
-            OUTREG32(addr, val);
-        } else {
-            goto Error;
-        }
-    }
-    else if (0 == strncmp(opt, "regr:", 5))
-    {
-        char *p = (char *)opt + 5;
-        unsigned int addr = (unsigned int) simple_strtoul(p, &p, 16);
-
-        if (addr) {
-            DISP_LOG_PRINT(ANDROID_LOG_INFO, "DBG", "Read register 0x%08x: 0x%08x\n", addr, INREG32(addr));
-        } else {
-            goto Error;
-        }
-    }
     else if(0 == strncmp(opt, "bkl:", 4))
     {
         char *p = (char *)opt + 4;
index 87263144b3d645286a194df1deaf2858bfefaa52..833dc9f822d1afadcc4da00f2b804163d7e4ab11 100644 (file)
@@ -1003,7 +1003,10 @@ static int _DISP_ESD_Check(int* dirty)
                        {
                            break;
                        }
-                       esd_check_count++;
+/* [PLATFORM]-Mod-BEGIN by TCTSZ.yaohui.zeng, 2015/05/04, modify for ESD fast shoot*/
+                       //esd_check_count++;
+                       esd_check_count=1;
+/* [PLATFORM]-Mod-END by TCTSZ.yaohui.zeng, 2015/05/04*/
         }
         if (esd_check_count >= LCM_ESD_CHECK_MAX_COUNT)
         {
index 3af5987574bb83622d5f09f813b0078202cfe44d..54e97a654208ea344db1c9026bbda0aee6532a4e 100644 (file)
@@ -470,7 +470,8 @@ static void _WaitForEngineNotBusy(void)
 {
     int timeOut;
 #if ENABLE_DSI_INTERRUPT
-    long int time;
+   
+ long int time;
     static const long WAIT_TIMEOUT = 2 * HZ;    // 2 sec
 #endif
 
index fc40accc019b21e63fb67dd34d0f7b2ae27c85b4..f8f4c8f6d74a5b335b3eb9325519e6f349bd654c 100644 (file)
@@ -851,15 +851,18 @@ static int mtkfb_pan_display_impl(struct fb_var_screeninfo *var, struct fb_info
         pr_info("[mtkfb] pan display set va=0x%x, pa=0x%x \n",(unsigned int)vaStart,paStart);
         Disp_Ovl_Engine_Set_layer_info(mtkfb_instance, &layerInfo);
 
-        layerInfo.layer_id = 1;
-        layerInfo.layer_enable = FALSE;
-        Disp_Ovl_Engine_Set_layer_info(mtkfb_instance, &layerInfo);
-        layerInfo.layer_id = 2;
-        layerInfo.layer_enable = FALSE;
-        Disp_Ovl_Engine_Set_layer_info(mtkfb_instance, &layerInfo);
-        layerInfo.layer_id = 3;
-        layerInfo.layer_enable = FALSE;
-        Disp_Ovl_Engine_Set_layer_info(mtkfb_instance, &layerInfo);
+        if(get_boot_mode() != FACTORY_BOOT)
+        {
+               layerInfo.layer_id = 1;
+               layerInfo.layer_enable = FALSE;
+               Disp_Ovl_Engine_Set_layer_info(mtkfb_instance, &layerInfo);
+               layerInfo.layer_id = 2;
+               layerInfo.layer_enable = FALSE;
+               Disp_Ovl_Engine_Set_layer_info(mtkfb_instance, &layerInfo);
+               layerInfo.layer_id = 3;
+               layerInfo.layer_enable = FALSE;
+               Disp_Ovl_Engine_Set_layer_info(mtkfb_instance, &layerInfo);
+        }
     }
     #else
     mutex_lock(&OverlaySettingMutex);
@@ -1625,6 +1628,14 @@ static int mtkfb_set_overlay_layer(struct mtkfb_device *fbdev, struct fb_overlay
     MSG_FUNC_ENTER();
     MMProfileLogEx(MTKFB_MMP_Events.SetOverlayLayer, MMProfileFlagStart, (id<<16)|enable, (unsigned int)layerInfo->src_phy_addr);
 
+    // Check id is valid
+    if ((id < 0) || (id >= DDP_OVL_LAYER_MUN))
+    {
+        MTKFB_LOG("Invalid layer id:%d\n", id);
+        ret = -EFAULT;
+        goto LeaveOverlayMode;
+    }
+
     //BUG: check layer 3 format
     if((layerInfo->layer_id == 3) && (layerInfo->src_fmt != MTK_FB_FORMAT_ARGB8888))
     {
@@ -1982,7 +1993,7 @@ LeaveOverlayMode:
 static int mtkfb_get_overlay_layer_info(struct fb_overlay_layer_info* layerInfo)
 {
     DISP_LAYER_INFO layer;
-    if (layerInfo->layer_id >= DDP_OVL_LAYER_MUN)
+    if ((layerInfo->layer_id < 0) || (layerInfo->layer_id >= DDP_OVL_LAYER_MUN))
     {
          return 0;
     }
@@ -2422,7 +2433,7 @@ static int mtkfb_ioctl(struct file *file, struct fb_info *info, unsigned int cmd
             return -EFAULT;
         }
         MTKFB_LOG("MTKFB_GET_DISPLAY_IF_INFORMATION display_id=%d\n", displayid);
-        if (displayid > MTKFB_MAX_DISPLAY_COUNT) {
+        if ((displayid < 0) || (displayid >= MTKFB_MAX_DISPLAY_COUNT)) {
             MTKFB_LOG("[FB]: invalid display id:%d \n", displayid);
             return -EFAULT;
         }
@@ -3431,13 +3442,13 @@ static void mtkfb_shutdown(struct device *pdev)
     sem_early_suspend_cnt--;
 
     is_early_suspended = TRUE;
+
+    /* [FIXBUG]-Mod-BEGIN by TCTSZ.leo.guo, PR#1000254 2015/05/18, Fix FB suspend/resume DSI cause recovery reboot failed issue*/
     DISP_PrepareSuspend();
+    if(wait_event_interruptible_timeout(_dsi_wait_vm_done_queue, !_IsEngineBusy(), HZ/10) == 0)
+               pr_err("[FB Driver] Wait disp finished timeout in early_suspend\n");
+    /* [FIXBUG]-Mod-END by TCTSZ.leo.guo, 2015/05/18*/
 
-    // Wait for disp finished.
-    if (wait_event_interruptible_timeout(_dsi_wait_vm_done_queue, !_IsEngineBusy(), HZ/10) == 0)
-    {
-        pr_info("[FB Driver] Wait disp finished timeout in early_suspend\n");
-    }
     DISP_CHECK_RET(DISP_PanelEnable(FALSE));
     DISP_CHECK_RET(DISP_PowerEnable(FALSE));
 
index a796339e5fb30931c3f127e79cc583188a0aef9e..c68894e0e6b066852eea6b6a6e43ef8f87239f3e 100644 (file)
@@ -206,7 +206,7 @@ struct fb_overlay_decouple {
 };
 struct fb_overlay_buffer {
        /* Input */
-       int layer_id;
+       unsigned int layer_id;
        unsigned int layer_en;
        int ion_fd;
        unsigned int cache_sync;
index fbe7ef2ea1f77d03a16c8bb14fd7a46e24897e45..1faedf8e670cc2af6fa6a1f8b495d8c76772659b 100644 (file)
@@ -1169,7 +1169,7 @@ static long vcodec_unlocked_ioctl(struct file *file, unsigned int cmd, unsigned
         case VCODEC_GET_CPU_LOADING_INFO:
         {
             VAL_UINT8_T *user_data_addr, cpu_id;
-            VAL_VCODEC_CPU_LOADING_INFO_T _temp;
+            VAL_VCODEC_CPU_LOADING_INFO_T _temp = {0};
 
             MFV_LOGD("[MT8127] VCODEC_GET_CPU_LOADING_INFO +\n");
             user_data_addr = (VAL_UINT8_T *)arg;
index 72ff14b811c621c3a6694a2e4941d2a4c41651ed..eaef679e29107fb36d4fdc77cdb8d6c31e25ca6d 100644 (file)
@@ -2222,7 +2222,7 @@ int ppp_register_net_channel(struct net *net, struct ppp_channel *chan)
 
        pch->ppp = NULL;
        pch->chan = chan;
-       pch->chan_net = net;
+       pch->chan_net = get_net(net);
        chan->ppp = pch;
        init_ppp_file(&pch->file, CHANNEL);
        pch->file.hdrlen = chan->hdrlen;
@@ -2319,6 +2319,8 @@ ppp_unregister_channel(struct ppp_channel *chan)
        spin_lock_bh(&pn->all_channels_lock);
        list_del(&pch->list);
        spin_unlock_bh(&pn->all_channels_lock);
+       put_net(pch->chan_net);
+       pch->chan_net = NULL;
 
        pch->file.dead = 1;
        wake_up_interruptible(&pch->file.rwait);
index 7cbed207af25e5a5d34b7b36c36b1bd4f88ff7aa..192fd6b634b02836f2a16924611abcc1ee6af21e 100644 (file)
@@ -69,6 +69,7 @@
 #include <cust_charging.h>
 #include <mach/upmu_common.h>
 #include <mach/upmu_hw.h>
+#include <mach/upmu_sw.h>
 #include <mach/charging.h>
 #include <mach/battery_common.h>
 #include <mach/battery_meter.h>
@@ -88,8 +89,6 @@
 /* Battery Logging Entry */
 /* ////////////////////////////////////////////////////////////////////////////// */
 int Enable_BATDRV_LOG = BAT_LOG_CRTI;
-/* static struct proc_dir_entry *proc_entry; */
-char proc_bat_data[32];
 
 /* ///////////////////////////////////////////////////////////////////////////////////////// */
 /* // Smart Battery Structure */
@@ -437,15 +436,17 @@ EXPORT_SYMBOL(wake_up_bat);
 
 static ssize_t bat_log_write(struct file *filp, const char __user *buff, size_t len, loff_t *data)
 {
-       if (copy_from_user(&proc_bat_data, buff, len)) {
+       char proc_bat_data;
+
+       if ((len <= 0) || copy_from_user(&proc_bat_data, buff, 1)) {
                battery_xlog_printk(BAT_LOG_FULL, "bat_log_write error.\n");
                return -EFAULT;
        }
 
-       if (proc_bat_data[0] == '1') {
+       if (proc_bat_data == '1') {
                battery_xlog_printk(BAT_LOG_CRTI, "enable battery driver log system\n");
                Enable_BATDRV_LOG = 1;
-       } else if (proc_bat_data[0] == '2') {
+       } else if (proc_bat_data == '2') {
                battery_xlog_printk(BAT_LOG_CRTI, "enable battery driver log system:2\n");
                Enable_BATDRV_LOG = 2;
        } else {
@@ -1828,8 +1829,11 @@ static void battery_update(struct battery_data *bat_data)
 
        battery_xlog_printk(BAT_LOG_CRTI, "UI_SOC=(%d), resetBatteryMeter=(%d)\n",
                            BMT_status.UI_SOC, resetBatteryMeter);
-                           
-  #ifdef CUST_CAPACITY_OCV2CV_TRANSFORM
+
+/*[BUGFIX]-Add-BEGIN by TCTSZ.pingao.yang, 4/15/2015,  pr-975290,  add standby current */
+       pre_timer_counter = cur_timer_counter;
+/*[BUGFIX]-Add-END by TCTSZ.pingao.yang */
+#ifdef CUST_CAPACITY_OCV2CV_TRANSFORM
     //restore battery UI capacity to rtc
     if (battery_meter_get_battery_soc() <= 1) {
         set_rtc_spare_fg_value(1);
@@ -1839,10 +1843,6 @@ static void battery_update(struct battery_data *bat_data)
     }
 #else
 
-/*[BUGFIX]-Add-BEGIN by TCTSZ.pingao.yang, 4/15/2015,  pr-975290,  add standby current */
-       pre_timer_counter = cur_timer_counter;
-/*[BUGFIX]-Add-END by TCTSZ.pingao.yang */
-
        /* set RTC SOC to 1 to avoid SOC jump in charger boot. */
        if (BMT_status.UI_SOC <= 1) {
                set_rtc_spare_fg_value(1);
@@ -2436,7 +2436,7 @@ static void mt_battery_CheckBatteryStatus(void)
                BMT_status.bat_charging_state = CHR_ERROR;
                return;
        }
-       battery_xlog_printk(BAT_LOG_CRTI, "[BATTERY]BMT_status.charger_vol = %d\r\n",BMT_status.charger_vol );
+
        if (mt_battery_CheckChargerVoltage() != PMU_STATUS_OK) {
                BMT_status.bat_charging_state = CHR_ERROR;
                return;
@@ -2522,35 +2522,35 @@ static void mt_battery_notify_VBatTemp_check(void)
 #if defined(BATTERY_NOTIFY_CASE_0002_VBATTEMP)
 
        if (BMT_status.temperature >= MAX_CHARGE_TEMPERATURE) {
-               /* [PLATFORM]-ADD-BEGIN by TCTSZ huichen@tcl.com, 05/21/2015,  BATTERY Notify PR-1007717*/
+               /* [PLATFORM]-ADD-BEGIN by TCTSZ leo.guo, 06/09/2015,  BATTERY Notify PR-1018754*/
                if(BMT_status.temperature >= MAX_RAISING_CHARGE_TEMPERATURE)
-                       g_BatteryNotifyCode |= 0x0040;
+                       g_BatteryNotifyCode |= (0x0040 | (!!BMT_status.charger_exist) << 8);
                else
-               g_BatteryNotifyCode |= 0x0002;
-               /* [PLATFORM]-ADD-END by TCTSZ huichen@tcl.com*/
+                       g_BatteryNotifyCode |= (0x0002 | (!!BMT_status.charger_exist) << 8);
+               /* [PLATFORM]-ADD-END by TCTSZ leo.guo*/
                battery_xlog_printk(BAT_LOG_CRTI, "[BATTERY] bat_temp(%d) out of range(too high)\n",
                                    BMT_status.temperature);
        }
 #if defined(CONFIG_MTK_JEITA_STANDARD_SUPPORT)
        else if (BMT_status.temperature < TEMP_NEG_10_THRESHOLD) {
-               /* [PLATFORM]-ADD-BEGIN by TCTSZ huichen@tcl.com, 05/21/2015,  BATTERY Notify PR-1007717*/
+               /* [PLATFORM]-ADD-BEGIN by TCTSZ leo.guo, 06/09/2015,  BATTERY Notify PR-1018754*/
                if(BMT_status.temperature <= MIN_DROPPING_CHARGE_TEMPERATURE)
-                       g_BatteryNotifyCode |= 0x0080;
+                       g_BatteryNotifyCode |= (0x0080 | (!!BMT_status.charger_exist) << 8);
                else
-                       g_BatteryNotifyCode |= 0x0020;
-               /* [PLATFORM]-ADD-END by TCTSZ huichen@tcl.com*/
+                       g_BatteryNotifyCode |= (0x0020 | (!!BMT_status.charger_exist) << 8);
+               /* [PLATFORM]-ADD-END by TCTSZ leo.guo*/
                battery_xlog_printk(BAT_LOG_CRTI, "[BATTERY] bat_temp(%d) out of range(too low)\n",
                                    BMT_status.temperature);
        }
 #else
 #ifdef BAT_LOW_TEMP_PROTECT_ENABLE
        else if (BMT_status.temperature < MIN_CHARGE_TEMPERATURE) {
-               /* [PLATFORM]-ADD-BEGIN by TCTSZ huichen@tcl.com, 05/21/2015,  BATTERY Notify PR-1007717*/
+               /* [PLATFORM]-ADD-BEGIN by TCTSZ leo.guo, 06/09/2015,  BATTERY Notify PR-1018754*/
                if(BMT_status.temperature <= MIN_DROPPING_CHARGE_TEMPERATURE)
-                       g_BatteryNotifyCode |= 0x0080;
+                       g_BatteryNotifyCode |= (0x0080 | (!!BMT_status.charger_exist) << 8);
                else
-                       g_BatteryNotifyCode |= 0x0020;
-               /* [PLATFORM]-ADD-END by TCTSZ huichen@tcl.com*/
+                       g_BatteryNotifyCode |= (0x0020 | (!!BMT_status.charger_exist) << 8);
+               /* [PLATFORM]-ADD-END by TCTSZ leo.guo*/
                battery_xlog_printk(BAT_LOG_CRTI, "[BATTERY] bat_temp(%d) out of range(too low)\n",
                                    BMT_status.temperature);
        }
@@ -2679,22 +2679,12 @@ static void mt_battery_thermal_check(void)
 
                                        if (BMT_status.charger_exist == KAL_TRUE) {
                                                /* can not power down due to charger exist, so need reset system */
-/* [PLATFORM]-MOD-BEGIN by TCTSZ huichen@tcl.com, 05/19/2015,  modify NTC shutdown mode*/
-                                               //shutdown by system
-                                               #if 0
                                                battery_charging_control
                                                    (CHARGING_CMD_SET_PLATFORM_RESET, NULL);
-                                               #endif
                                        }
                                        /* avoid SW no feedback */
-//                                     battery_charging_control(CHARGING_CMD_SET_POWER_OFF, NULL);
+                                       battery_charging_control(CHARGING_CMD_SET_POWER_OFF, NULL);
                                        /* mt_power_off(); */
-                                       if((g_platform_boot_mode==KERNEL_POWER_OFF_CHARGING_BOOT) || g_platform_boot_mode==LOW_POWER_OFF_CHARGING_BOOT)
-                                               {
-                                               //in KPOC mode ,shutdown by kernel
-                                               battery_charging_control(CHARGING_CMD_SET_POWER_OFF, NULL);
-                                               }
-/* [PLATFORM]-MOD-BEGIN by TCTSZ huichen@tcl.com, 05/19/2015*/
                                }
                        }
 #endif
@@ -2987,6 +2977,7 @@ void BAT_thread(void)
        /*[BUGFIX]-Add-END by TCTSZ.pingao.yang */
 
        }
+
        mt_battery_charger_detect_check();
        mt_battery_GetBatteryData();
        if (BMT_status.charger_exist == KAL_TRUE) {
@@ -3007,10 +2998,27 @@ void BAT_thread(void)
 /* ///////////////////////////////////////////////////////////////////////////////////////// */
 /* // Internal API */
 /* ///////////////////////////////////////////////////////////////////////////////////////// */
+
+#ifdef BATTERY_CDP_WORKAROUND
+extern kal_bool is_charger_detection_rdy(void);
+#endif
+
 int bat_thread_kthread(void *x)
 {
        ktime_t ktime = ktime_set(3, 0);        /* 10s, 10* 1000 ms */
 
+       
+#ifdef BATTERY_CDP_WORKAROUND
+               if(is_charger_detection_rdy()==KAL_FALSE){
+                       printk("xiaohu_cdp:CDP, block\n");
+                       wait_event(bat_thread_wq, (is_charger_detection_rdy()==KAL_TRUE));
+                       printk("xiaohu_cdp:CDP, free\n");
+               }else{
+                       printk("xiaohu_cdp:CDP, PASS\n");
+               }
+#endif
+
+
        /* Run on a process content */
        while (1) {
                mutex_lock(&bat_mutex);
index 972cd47f0e4fcffa1cd708fc89e8949826b99d7f..73e16b323162c63daeebfdf93b2849016f1f3b66 100644 (file)
@@ -55,9 +55,6 @@ int Enable_FGADC_LOG = 1;
 /* ============================================================ // */
 BATTERY_METER_CONTROL battery_meter_ctrl = NULL;
 
-/* static struct proc_dir_entry *proc_entry_fgadc; */
-static char proc_fgadc_data[32];
-
 kal_bool gFG_Is_Charging = KAL_FALSE;
 kal_int32 g_auxadc_solution = 0;
 U32 g_spm_timer = 600;
@@ -1536,8 +1533,8 @@ void oam_init(void)
        printk("zero----in function ====%s\n",__func__);
        printk("zero---gFG_voltage=%d,g_booting_vbat = %d\n",gFG_voltage,g_booting_vbat);
        
-        if(bat_is_charger_exist() == KAL_TRUE)
-        {
+       if(bat_is_charger_exist() == KAL_TRUE)
+       {
                #ifdef CONFIG_USB_PLUS_DC
               printk("zero---BMT_status.charger_type = %d\n",dc_in_state());  
                if (dc_in_state() == 0)
@@ -1565,20 +1562,17 @@ void oam_init(void)
                                gFG_voltage = gFG_voltage - 20;
                        else if(gFG_voltage >= 4100 && gFG_voltage < 4190)
                                gFG_voltage = gFG_voltage - 10;
-             #endif
-        }
-        else
-        {
-        #if 0
-               if(gFG_voltage > 3600 && gFG_voltage < 3700)
-                       gFG_voltage = gFG_voltage - 5;
-               else if(gFG_voltage >= 3700 && gFG_voltage < 4000)
-                       gFG_voltage = gFG_voltage - 10;
-               else if(gFG_voltage >= 4000 && gFG_voltage < 4150)
-                       gFG_voltage = gFG_voltage - 5;
-       #endif
-        }
-        printk("zero---gFG_voltage=%d\n",gFG_voltage);
+           #endif
+       }
+       else
+       {
+/* [BUGFIX]-Add-BEGIN by TCTSZ.leo.guo, 05/26/2015, Fixed voltage calculate to report soc.*/
+               printk("Fixed voltage calculate to report soc.");
+               if(gFG_voltage <= 3500)
+                       gFG_voltage = gFG_voltage - 50;
+/* [BUGFIX]-Add-END by TCTSZ.leo.guo, 05/26/2015*/
+       }
+       printk("zero---gFG_voltage=%d\n",gFG_voltage);
         /************add by zero ************************/
        gFG_capacity_by_v = fgauge_read_capacity_by_v(gFG_voltage);
        vbat_capacity = fgauge_read_capacity_by_v(g_booting_vbat);
@@ -2096,6 +2090,13 @@ kal_int32 fgauge_read_capacity(kal_int32 type)
        kal_int32 voltage;
        kal_int32 temperature;
        kal_int32 dvalue = 0;
+
+#ifndef CUST_DISABLE_CAPACITY_OCV2CV_TRANSFORM
+       kal_int32 C_0mA = 0;
+       kal_int32 C_400mA = 0;
+       kal_int32 dvalue_new = 0;
+#endif
+
        kal_int32 temp_val = 0;
 
        if (type == 0)          /* for initialization */
@@ -2110,6 +2111,20 @@ kal_int32 fgauge_read_capacity(kal_int32 type)
        }
 
        gFG_DOD1 = dvalue;
+
+#ifndef CUST_DISABLE_CAPACITY_OCV2CV_TRANSFORM
+       /* User View on HT~LT---------------------------------------------------------- */
+       gFG_temp = force_get_tbat(KAL_FALSE);
+       C_0mA = fgauge_get_Q_max(gFG_temp);
+       C_400mA = fgauge_get_Q_max_high_current(gFG_temp);
+       if (C_0mA > C_400mA) {
+               dvalue_new = (100 - dvalue) - (((C_0mA - C_400mA) * (dvalue)) / C_400mA);
+               dvalue = 100 - dvalue_new;
+       }
+       bm_print(BM_LOG_FULL, "[fgauge_read_capacity] %d,%d,%d,%d,%d,D1=%d,D0=%d\r\n",
+                gFG_temp, C_0mA, C_400mA, dvalue, dvalue_new, gFG_DOD1, gFG_DOD0);
+       /* ---------------------------------------------------------------------------- */
+#endif                         /* CUST_DISABLE_CAPACITY_OCV2CV_TRANSFORM */
        temp_val = dvalue;
        dvalue = 100 - temp_val;
 
@@ -2640,7 +2655,8 @@ kal_int32 battery_meter_get_charging_current(void)
 {
 #ifdef DISABLE_CHARGING_CURRENT_MEASURE
        return 0;
-#elif !defined (EXTERNAL_SWCHR_SUPPORT)
+/* [PLATFORM]-Add-BEGIN by TCTSZ.leo.guo, 2015.06.10, Added measure current feature */
+#else
        kal_int32 ADC_BAT_SENSE_tmp[10] =
            { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 };
        kal_int32 ADC_BAT_SENSE_sum = 0;
@@ -2726,9 +2742,8 @@ kal_int32 battery_meter_get_charging_current(void)
        }
 
        return ICharging;
-#else
-    return 0;
 #endif
+/* [PLATFORM]-Add-END by TCTSZ.leo.guo, 2015.06.10 */
 }
 
 kal_int32 battery_meter_get_battery_current(void)
@@ -2833,7 +2848,10 @@ kal_int32 battery_meter_trans_battery_percentage(kal_int32 d_val)
     d_val_temp = d_val;
     temp_val = battery_meter_get_battery_temperature();
     C_0mA = fgauge_get_Q_max(temp_val);
-
+/* [BUGFIX]-Add-BEGIN by TCTSZ.leo.guo, 06/25/2015, Fixed voltage calculate to report error soc. */
+       if(gFG_Is_Charging == KAL_TRUE)
+               return d_val;
+/* [BUGFIX]-Add-BEGIN by TCTSZ.leo.guo, 06/25/2015 */
     // discharging and current > 600ma
     i_avg_current = g_currentfactor * 6000/100;
     if(KAL_FALSE == gFG_Is_Charging && g_currentfactor > 100)
@@ -2843,8 +2861,10 @@ kal_int32 battery_meter_trans_battery_percentage(kal_int32 d_val)
 
     if(C_0mA > C_400mA)
     {
-        d_val_new = (100-d_val) - ( ( (C_0mA-C_400mA) * (d_val) ) / C_400mA );
-        d_val = 100 - d_val_new;
+        d_val_new = (100 - d_val) - (((C_0mA-C_400mA) * (d_val)) / C_400mA);
+/* [BUGFIX]-Add-BEGIN by TCTSZ.leo.guo, 06/25/2015, Fixed voltage calculate to report error soc. */
+           if(d_val_new > 0) d_val = 100 - d_val_new;
+/* [BUGFIX]-Add-BEGIN by TCTSZ.leo.guo, 06/25/2015 */
     }
     bm_print(BM_LOG_FULL, "[battery_meter_trans_battery_percentage] %d,%d,%d,%d,%d,%d,%d\r\n", 
             temp_val, C_0mA, C_400mA, d_val_temp, d_val_new, d_val, g_currentfactor);
@@ -3122,15 +3142,18 @@ kal_int32 battery_meter_get_VSense(void)
 static ssize_t fgadc_log_write(struct file *filp, const char __user *buff,
                               size_t len, loff_t *data)
 {
-       if (copy_from_user(&proc_fgadc_data, buff, len)) {
+
+       char proc_fgadc_data;
+
+       if ((len <= 0) || copy_from_user(&proc_fgadc_data, buff, 1)) {
                bm_print(BM_LOG_CRTI, "fgadc_log_write error.\n");
                return -EFAULT;
        }
 
-       if (proc_fgadc_data[0] == '1') {
+       if (proc_fgadc_data == '1') {
                bm_print(BM_LOG_CRTI, "enable FGADC driver log system\n");
                Enable_FGADC_LOG = 1;
-       } else if (proc_fgadc_data[0] == '2') {
+       } else if (proc_fgadc_data == '2') {
                bm_print(BM_LOG_CRTI, "enable FGADC driver log system:2\n");
                Enable_FGADC_LOG = 2;
        } else {
index 8f8551d1b8405b47ce3abfae4b357944c47cbfb5..5a16b86dddb4856efde4e005782bc379df268e08 100644 (file)
@@ -37,7 +37,6 @@
 #include <linux/mutex.h>
 #include <linux/wakelock.h>
 
-
  /* ============================================================ // */
  /* define */
  /* ============================================================ // */
@@ -62,8 +61,8 @@ CHR_CURRENT_ENUM      g_temp_CC_value = CHARGE_CURRENT_0_00_MA;
 kal_uint32             g_usb_state = USB_UNCONFIGURED;
 kal_uint32             charging_full_current = CHARGING_FULL_CURRENT;  /* mA */
 kal_uint32             v_cc2topoff_threshold = V_CC2TOPOFF_THRES;
- CHR_CURRENT_ENUM      ulc_cv_charging_current = AC_CHARGER_CURRENT;   
- kal_bool              ulc_cv_charging_current_flag = KAL_FALSE;
+CHR_CURRENT_ENUM       ulc_cv_charging_current = AC_CHARGER_CURRENT;
+kal_bool               ulc_cv_charging_current_flag = KAL_FALSE;
 static bool            usb_unlimited=false;
 
 /* [PLATFORM]-Add-BEGIN by TCTSZ.leo.guo, 04/15/2015,  modify ntc temperature function */
@@ -1036,36 +1035,16 @@ PMU_STATUS BAT_PreChargeModeAction(void)
 #else
        {
                kal_bool charging_enable = KAL_FALSE;
-/* [PLATFORM]-MOD-BEGIN by TCTSZ huichen@tcl.com, 06/18/2015,  disable PWM charge mode FR-1027565*/
-#if 0
-
-               {
-               int int_CHR_CON1;
-               int ret;
-               ret=pmic_config_interface(CHR_CON0,0x0,0x1,0x0);
-               ret=pmic_read_interface(CHR_CON0,(&int_CHR_CON1),0x1,0x0);
-               printk("BAT_PreChargeModeAction OVP  Reg[0x%x]=0x%x\n", CHR_CON0, int_CHR_CON1);
-
 
                /*Charging 9s and discharging 1s : start */
                battery_charging_control(CHARGING_CMD_ENABLE, &charging_enable);
                msleep(1000);
-               ret=pmic_read_interface(CHR_CON0,(&int_CHR_CON1),0x1,0x0);
-               printk("BAT_PreChargeModeAction OVP  Reg[0x%x]=0x%x\n", CHR_CON0, int_CHR_CON1);
-       }
-#endif
-/* [PLATFORM]-MOD-END by TCTSZ huichen@tcl.com, 06/18/2015*/
        }
 #endif
 
        charging_current_calibration();
        pchr_turn_on_charging();
-/* [PLATFORM]-MOD-BEGIN by TCTSZ huichen@tcl.com, 05/18/2015,  modify OVP function FR-1005346*/
-#if 0
-       msleep(50);//need sleep
-       pmic_config_interface(CHR_CON0,0x1,0x1,0x0);
-#endif
-/* [PLATFORM]-MOD-END by TCTSZ huichen@tcl.com, 05/18/2015*/
+
        return PMU_STATUS_OK;
 }
 
@@ -1091,40 +1070,18 @@ PMU_STATUS BAT_ConstantCurrentModeAction(void)
        // no disable charging#else
 #else
        {
-
-
                kal_bool charging_enable = KAL_FALSE;
-/* [PLATFORM]-MOD-BEGIN by TCTSZ huichen@tcl.com, 06/18/2015,  disable PWM charge mode FR-1027565*/
-#if 0
-               {
-               int int_CHR_CON1;
-               int ret;
-               ret=pmic_config_interface(CHR_CON0,0x0,0x1,0x0);
-               ret=pmic_read_interface(CHR_CON0,(&int_CHR_CON1),0x1,0x0);
-               printk("BAT_PreChargeModeAction OVP  Reg[0x%x]=0x%x\n", CHR_CON0, int_CHR_CON1);
 
                /* Charging 9s and discharging 1s : start */
                battery_charging_control(CHARGING_CMD_ENABLE, &charging_enable);
                msleep(1000);
-               ret=pmic_read_interface(CHR_CON0,(&int_CHR_CON1),0x1,0x0);
-               printk("BAT_PreChargeModeAction OVP  Reg[0x%x]=0x%x\n", CHR_CON0, int_CHR_CON1);
-       }
-#endif
-/* [PLATFORM]-MOD-END by TCTSZ huichen@tcl.com, 06/18/2015*/
-
-
        }       
 #endif
 
        charging_current_calibration();
 
        pchr_turn_on_charging();
-/* [PLATFORM]-MOD-BEGIN by TCTSZ huichen@tcl.com, 05/18/2015,  modify OVP function FR-1005346*/
-#if 0
-       msleep(50);
-       pmic_config_interface(CHR_CON0,0x1,0x1,0x0);
-#endif
-/* [PLATFORM]-MOD-END by TCTSZ huichen@tcl.com, 05/18/2015*/
+
        return PMU_STATUS_OK;
 }
 
index 1aa99f72c8bc6a171f3385838288a884391a12de..6084a16f1e8c07cdbf962d3dacbaab1e70dcfcc6 100644 (file)
@@ -76,6 +76,11 @@ kal_bool is_ta_connect = KAL_FALSE;
 kal_bool ta_vchr_tuning = KAL_TRUE;
 int ta_v_chr_org = 0;
 #endif
+/* [PLATFORM]-Add-BEGIN by TCTSZ.leo.guo, 04/15/2015,  modify ntc temperature function */
+#ifdef MTK_BATTERY_PROTECT_FEATURE
+kal_bool high_temp_stop_charge = KAL_FALSE;
+#endif
+/* [PLATFORM]-Add-END by TCTSZ.leo.guo */
 
   /* ///////////////////////////////////////////////////////////////////////////////////////// */
   /* // JEITA */
@@ -314,7 +319,7 @@ static BATTERY_VOLTAGE_ENUM select_jeita_cv(void)
                cv_voltage = JEITA_TEMP_POS_45_TO_POS_60_CV_VOLTAGE;
        } else if (g_temp_status == TEMP_POS_10_TO_POS_45) {
 #ifdef HIGH_BATTERY_VOLTAGE_SUPPORT
-               cv_voltage = BATTERY_VOLT_04_340000_V;
+               cv_voltage = BATTERY_VOLT_04_360000_V;
 #else
                cv_voltage = JEITA_TEMP_POS_10_TO_POS_45_CV_VOLTAGE;
 #endif
@@ -655,15 +660,30 @@ void select_charging_curret(void)
 
 static kal_uint32 charging_full_check(void)
 {
-       kal_uint32 status;
+       kal_uint32 status = KAL_FALSE;
 
        battery_charging_control(CHARGING_CMD_GET_CHARGING_STATUS, &status);
        if (status == KAL_TRUE) {
                g_full_check_count++;
-               if (g_full_check_count >= FULL_CHECK_TIMES) {
+               if (g_full_check_count >= FULL_CHECK_TIMES){
+/* [PLATFORM]-Add-BEGIN by TCTSZ.leo.guo, 04/15/2015,  modify ntc temperature function */
+#ifdef MTK_BATTERY_PROTECT_FEATURE
+                       if (BMT_status.temperature < MAX_LIMIT_CHARGE_TEMPERATURE) {
+                               return KAL_TRUE;
+                       }
+                       else {
+                               high_temp_stop_charge = KAL_TRUE;
+                               return KAL_FALSE;
+                       }
+#else
                        return KAL_TRUE;
-               } else
+
+#endif
+/* [PLATFORM]-Add-END by TCTSZ.leo.guo */
+               }
+               else{
                        return KAL_FALSE;
+               }
        } else {
                g_full_check_count = 0;
                return status;
@@ -738,10 +758,21 @@ static void pchr_turn_on_charging(void)
                        /*Set CV Voltage */
 #if !defined(CONFIG_MTK_JEITA_STANDARD_SUPPORT)
 #ifdef HIGH_BATTERY_VOLTAGE_SUPPORT
-                       cv_voltage = BATTERY_VOLT_04_340000_V;
+                       cv_voltage = BATTERY_VOLT_04_360000_V;
 #else
                        cv_voltage = BATTERY_VOLT_04_200000_V;
 #endif
+/* [PLATFORM]-Add-BEGIN by TCTSZ.leo.guo, 05/28/2015,  modify ntc temperature function */
+#ifdef MTK_BATTERY_PROTECT_FEATURE
+/*Battery temperature more than 45 degree or less than 55 degree, try to limit max voltage*/
+                       if((BMT_status.temperature >= MAX_LIMIT_CHARGE_TEMPERATURE) && (BMT_status.temperature <= MAX_CHARGE_TEMPERATURE) )
+                       {
+                               cv_voltage = BATTERY_VOLT_04_100000_V;
+                               battery_xlog_printk(BAT_LOG_CRTI,
+                                       "[BATTERY] temperature more than 45 degree or less than 55 degree, try to limit max voltage !\r\n");
+                       }
+#endif
+/* [PLATFORM]-Add-END by TCTSZ.leo.guo */
                        battery_charging_control(CHARGING_CMD_SET_CV_VOLTAGE, &cv_voltage);
 #endif
                }
index 78c87d5a6adfa65b249b067636e77d40025185fa..b27287ebc0393c7ce2ff921eecfa2df38b0c626b 100644 (file)
@@ -1486,7 +1486,7 @@ static void binder_insert_free_buffer(struct binder_proc *proc,
        new_buffer_size = binder_buffer_size(proc, new_buffer);
 
        binder_debug(BINDER_DEBUG_BUFFER_ALLOC,
-                    "%d: add free buffer, size %zd, at %p\n",
+                    "%d: add free buffer, size %zd, at %pK\n",
                      proc->pid, new_buffer_size, new_buffer);
 
        while (*p) {
@@ -1565,7 +1565,7 @@ static int binder_update_page_range(struct binder_proc *proc, int allocate,
        struct mm_struct *mm;
 
        binder_debug(BINDER_DEBUG_BUFFER_ALLOC,
-                    "%d: %s pages %p-%p\n", proc->pid,
+                    "%d: %s pages %pK-%pK\n", proc->pid,
                     allocate ? "allocate" : "free", start, end);
 
        if (end <= start)
@@ -1605,7 +1605,7 @@ static int binder_update_page_range(struct binder_proc *proc, int allocate,
                BUG_ON(*page);
                *page = alloc_page(GFP_KERNEL | __GFP_HIGHMEM | __GFP_ZERO);
                if (*page == NULL) {
-                       pr_err("%d: binder_alloc_buf failed for page at %p\n",
+                       pr_err("%d: binder_alloc_buf failed for page at %pK\n",
                                proc->pid, page_addr);
                        goto err_alloc_page_failed;
                }
@@ -1622,7 +1622,7 @@ static int binder_update_page_range(struct binder_proc *proc, int allocate,
                page_array_ptr = page;
                ret = map_vm_area(&tmp_area, PAGE_KERNEL, &page_array_ptr);
                if (ret) {
-                       pr_err("%d: binder_alloc_buf failed to map page at %p in kernel\n",
+                       pr_err("%d: binder_alloc_buf failed to map page at %pK in kernel\n",
                               proc->pid, page_addr);
                        goto err_map_kernel_failed;
                }
@@ -1768,7 +1768,7 @@ static struct binder_buffer *binder_alloc_buf(struct binder_proc *proc,
        }
 
        binder_debug(BINDER_DEBUG_BUFFER_ALLOC,
-                    "%d: binder_alloc_buf size %zd got buffer %p size %zd\n",
+                    "%d: binder_alloc_buf size %zd got buffer %pK size %zd\n",
                      proc->pid, size, buffer, buffer_size);
 
        has_page_addr =
@@ -1797,7 +1797,7 @@ static struct binder_buffer *binder_alloc_buf(struct binder_proc *proc,
                binder_insert_free_buffer(proc, new_buffer);
        }
        binder_debug(BINDER_DEBUG_BUFFER_ALLOC,
-                    "%d: binder_alloc_buf size %zd got %p\n",
+                    "%d: binder_alloc_buf size %zd got %pK\n",
                      proc->pid, size, buffer);
        buffer->data_size = data_size;
        buffer->offsets_size = offsets_size;
@@ -1837,7 +1837,7 @@ static void binder_delete_free_buffer(struct binder_proc *proc,
                if (buffer_end_page(prev) == buffer_end_page(buffer))
                        free_page_end = 0;
                binder_debug(BINDER_DEBUG_BUFFER_ALLOC,
-                            "%d: merge free, buffer %p share page with %p\n",
+                            "%d: merge free, buffer %pK share page with %pK\n",
                              proc->pid, buffer, prev);
        }
 
@@ -1850,14 +1850,14 @@ static void binder_delete_free_buffer(struct binder_proc *proc,
                            buffer_start_page(buffer))
                                free_page_start = 0;
                        binder_debug(BINDER_DEBUG_BUFFER_ALLOC,
-                                    "%d: merge free, buffer %p share page with %p\n",
+                                    "%d: merge free, buffer %pK share page with %pK\n",
                                      proc->pid, buffer, prev);
                }
        }
        list_del(&buffer->entry);
        if (free_page_start || free_page_end) {
                binder_debug(BINDER_DEBUG_BUFFER_ALLOC,
-                            "%d: merge free, buffer %p do not share page%s%s with %p or %p\n",
+                            "%d: merge free, buffer %pK do not share page%s%s with %pK or %pK\n",
                             proc->pid, buffer, free_page_start ? "" : " end",
                             free_page_end ? "" : " start", prev, next);
                binder_update_page_range(proc, 0, free_page_start ?
@@ -1878,7 +1878,7 @@ static void binder_free_buf(struct binder_proc *proc,
                ALIGN(buffer->offsets_size, sizeof(void *));
 
        binder_debug(BINDER_DEBUG_BUFFER_ALLOC,
-                    "%d: binder_free_buf %p size %zd buffer_size %zd\n",
+                    "%d: binder_free_buf %pK size %zd buffer_size %zd\n",
                      proc->pid, buffer, size, buffer_size);
 
        BUG_ON(buffer->free);
@@ -2063,7 +2063,7 @@ static int binder_dec_node(struct binder_node *node, int strong, int internal)
 
 
 static struct binder_ref *binder_get_ref(struct binder_proc *proc,
-                                        uint32_t desc)
+                                        uint32_t desc, bool need_strong_ref)
 {
        struct rb_node *n = proc->refs_by_desc.rb_node;
        struct binder_ref *ref;
@@ -2071,12 +2071,16 @@ static struct binder_ref *binder_get_ref(struct binder_proc *proc,
        while (n) {
                ref = rb_entry(n, struct binder_ref, rb_node_desc);
 
-               if (desc < ref->desc)
+               if (desc < ref->desc) {
                        n = n->rb_left;
-               else if (desc > ref->desc)
+               } else if (desc > ref->desc) {
                        n = n->rb_right;
-               else
+               } else if (need_strong_ref && !ref->strong) {
+                       binder_user_error("tried to use weak ref as strong ref\n");
+                       return NULL;
+               } else {
                        return ref;
+               }
        }
        return NULL;
 }
@@ -2304,7 +2308,7 @@ static void binder_transaction_buffer_release(struct binder_proc *proc,
        int debug_id = buffer->debug_id;
 
        binder_debug(BINDER_DEBUG_TRANSACTION,
-                    "%d buffer release %d, size %zd-%zd, failed at %p\n",
+                    "%d buffer release %d, size %zd-%zd, failed at %pK\n",
                     proc->pid, buffer->debug_id,
                     buffer->data_size, buffer->offsets_size, failed_at);
 
@@ -2343,7 +2347,8 @@ static void binder_transaction_buffer_release(struct binder_proc *proc,
                } break;
                case BINDER_TYPE_HANDLE:
                case BINDER_TYPE_WEAK_HANDLE: {
-                       struct binder_ref *ref = binder_get_ref(proc, fp->handle);
+                       struct binder_ref *ref = binder_get_ref(proc, fp->handle,
+                                               fp->type == BINDER_TYPE_HANDLE);
                        if (ref == NULL) {
                                pr_err("transaction release %d bad handle %d\n",
                                 debug_id, fp->handle);
@@ -2559,7 +2564,7 @@ static void binder_transaction(struct binder_proc *proc,
        } else {
                if (tr->target.handle) {
                        struct binder_ref *ref;
-                       ref = binder_get_ref(proc, tr->target.handle);
+                       ref = binder_get_ref(proc, tr->target.handle, true);
                        if (ref == NULL) {
                                binder_user_error("%d:%d got transaction to invalid handle\n",
                                        proc->pid, thread->pid);
@@ -2904,7 +2909,9 @@ out_err:
                                fp->type = BINDER_TYPE_HANDLE;
                        else
                                fp->type = BINDER_TYPE_WEAK_HANDLE;
+                       fp->binder = 0;
                        fp->handle = ref->desc;
+                       fp->cookie = 0;
                        binder_inc_ref(ref, fp->type == BINDER_TYPE_HANDLE,
                                       &thread->todo);
 
@@ -2916,7 +2923,8 @@ out_err:
                } break;
                case BINDER_TYPE_HANDLE:
                case BINDER_TYPE_WEAK_HANDLE: {
-                       struct binder_ref *ref = binder_get_ref(proc, fp->handle);
+                       struct binder_ref *ref = binder_get_ref(proc, fp->handle,
+                                               fp->type == BINDER_TYPE_HANDLE);
                        if (ref == NULL) {
                                binder_user_error("%d:%d got transaction with invalid handle, %d\n",
                                                proc->pid,
@@ -2952,7 +2960,9 @@ out_err:
                                        return_error = BR_FAILED_REPLY;
                                        goto err_binder_get_ref_for_node_failed;
                                }
+                               fp->binder = 0;
                                fp->handle = new_ref->desc;
+                               fp->cookie = 0;
                                binder_inc_ref(new_ref, fp->type == BINDER_TYPE_HANDLE, NULL);
                                trace_binder_transaction_ref_to_ref(t, ref,
                                                                    new_ref);
@@ -3011,6 +3021,7 @@ out_err:
                        binder_debug(BINDER_DEBUG_TRANSACTION,
                                     "        fd %d -> %d\n", fp->handle, target_fd);
                        /* TODO: fput? */
+                       fp->binder = 0;
                        fp->handle = target_fd;
 #ifdef BINDER_MONITOR
                        e->fd = target_fd;
@@ -3199,7 +3210,9 @@ int binder_thread_write(struct binder_proc *proc, struct binder_thread *thread,
                                                ref->desc);
                                }
                        } else
-                               ref = binder_get_ref(proc, target);
+                               ref = binder_get_ref(proc, target,
+                                               cmd == BC_ACQUIRE ||
+                                               cmd == BC_RELEASE);
                        if (ref == NULL) {
                                binder_user_error("%d:%d refcount change on invalid ref %d\n",
                                        proc->pid, thread->pid, target);
@@ -3408,7 +3421,7 @@ int binder_thread_write(struct binder_proc *proc, struct binder_thread *thread,
                        if (get_user(cookie, (binder_uintptr_t __user *)ptr))
                                return -EFAULT;
                        ptr += sizeof(binder_uintptr_t);
-                       ref = binder_get_ref(proc, target);
+                       ref = binder_get_ref(proc, target, false);
                        if (ref == NULL) {
                                binder_user_error("%d:%d %s invalid ref %d\n",
                                        proc->pid, thread->pid,
@@ -3520,7 +3533,7 @@ int binder_thread_write(struct binder_proc *proc, struct binder_thread *thread,
                                }
                        }
                        binder_debug(BINDER_DEBUG_DEAD_BINDER,
-                                    "%d:%d BC_DEAD_BINDER_DONE %016llx found %p\n",
+                                    "%d:%d BC_DEAD_BINDER_DONE %016llx found %pK\n",
                                     proc->pid, thread->pid, (u64)cookie, death);
                        if (death == NULL) {
                                binder_user_error("%d:%d BC_DEAD_BINDER_DONE %016llx not found\n",
@@ -4431,7 +4444,7 @@ static int binder_mmap(struct file *filp, struct vm_area_struct *vma)
 #ifdef CONFIG_CPU_CACHE_VIPT
        if (cache_is_vipt_aliasing()) {
                while (CACHE_COLOUR((vma->vm_start ^ (uint32_t)proc->buffer))) {
-                       pr_info("binder_mmap: %d %lx-%lx maps %p bad alignment\n", proc->pid, vma->vm_start, vma->vm_end, proc->buffer);
+                       pr_info("binder_mmap: %d %lx-%lx maps %pK bad alignment\n", proc->pid, vma->vm_start, vma->vm_end, proc->buffer);
                        vma->vm_start += PAGE_SIZE;
                }
        }
@@ -4463,7 +4476,7 @@ static int binder_mmap(struct file *filp, struct vm_area_struct *vma)
        proc->vma = vma;
        proc->vma_vm_mm = vma->vm_mm;
 
-       /*pr_info("binder_mmap: %d %lx-%lx maps %p\n",
+       /*pr_info("binder_mmap: %d %lx-%lx maps %pK\n",
                 proc->pid, vma->vm_start, vma->vm_end, proc->buffer);*/
        return 0;
 
@@ -4747,7 +4760,7 @@ static void binder_deferred_release(struct binder_proc *proc)
 
                        page_addr = proc->buffer + i * PAGE_SIZE;
                        binder_debug(BINDER_DEBUG_BUFFER_ALLOC,
-                                    "%s: %d: page %d at %p not freed\n",
+                                    "%s: %d: page %d at %pK not freed\n",
                                     __func__, proc->pid, i, page_addr);
                        unmap_kernel_range((unsigned long)page_addr, PAGE_SIZE);
                        __free_page(proc->pages[i]);
@@ -4848,7 +4861,7 @@ static void print_binder_transaction(struct seq_file *m, const char *prefix,
        rtc_time_to_tm(t->tv.tv_sec, &tm);
 #endif
        seq_printf(m,
-                  "%s %d: %p from %d:%d to %d:%d code %x flags %x pri %ld r%d",
+                  "%s %d: %pK from %d:%d to %d:%d code %x flags %x pri %ld r%d",
                   prefix, t->debug_id, t,
                   t->from ? t->from->proc->pid : 0,
                   t->from ? t->from->pid : 0,
@@ -4873,7 +4886,7 @@ static void print_binder_transaction(struct seq_file *m, const char *prefix,
                seq_printf(m, " node %d",
                           t->buffer->target_node->debug_id);
 #ifdef BINDER_MONITOR
-       seq_printf(m, " size %zd:%zd data %p auf %d start %lu.%06lu"
+       seq_printf(m, " size %zd:%zd data %pK auf %d start %lu.%06lu"
                   " android %d-%02d-%02d %02d:%02d:%02d.%03lu\n",
                   t->buffer->data_size, t->buffer->offsets_size,
                   t->buffer->data, t->buffer->allow_user_free,
@@ -4892,7 +4905,7 @@ static void print_binder_transaction(struct seq_file *m, const char *prefix,
 static void print_binder_buffer(struct seq_file *m, const char *prefix,
                                struct binder_buffer *buffer)
 {
-       seq_printf(m, "%s %d: %p size %zd:%zd %s\n",
+       seq_printf(m, "%s %d: %pK size %zd:%zd %s\n",
                   prefix, buffer->debug_id, buffer->data,
                   buffer->data_size, buffer->offsets_size,
                   buffer->transaction ? "active" : "delivered");
@@ -5007,7 +5020,7 @@ static void print_binder_node(struct seq_file *m, struct binder_node *node)
 
 static void print_binder_ref(struct seq_file *m, struct binder_ref *ref)
 {
-       seq_printf(m, "  ref %d: desc %d %snode %d s %d w %d d %p\n",
+       seq_printf(m, "  ref %d: desc %d %snode %d s %d w %d d %pK\n",
                   ref->debug_id, ref->desc, ref->node->proc ? "" : "dead ",
                   ref->node->debug_id, ref->strong, ref->weak, ref->death);
 }
index a59d14bb5aea2ec56002a7b5e50133418f05ef34..c6551ffa068a2ca9146b73c21fb27d5db3f1f796 100644 (file)
@@ -16,6 +16,8 @@
  */
 
 #include <linux/device.h>
+#include <linux/err.h>
+#include <linux/atomic.h>
 #include <linux/file.h>
 #include <linux/freezer.h>
 #include <linux/fs.h>
@@ -455,18 +457,76 @@ static void ion_handle_get(struct ion_handle *handle)
        kref_get(&handle->ref);
 }
 
-static int ion_handle_put(struct ion_handle *handle)
+/* Must hold the client lock */
+static struct ion_handle* ion_handle_get_check_overflow(struct ion_handle *handle)
+{
+       if (atomic_read(&handle->ref.refcount) + 1 == 0)
+               return ERR_PTR(-EOVERFLOW);
+       ion_handle_get(handle);
+       return handle;
+}
+
+static int ion_handle_put_nolock(struct ion_handle *handle)
+{
+       int ret;
+
+       ret = kref_put(&handle->ref, ion_handle_destroy);
+
+       return ret;
+}
+
+int ion_handle_put(struct ion_handle *handle)
 {
        struct ion_client *client = handle->client;
        int ret;
 
        mutex_lock(&client->lock);
-       ret = kref_put(&handle->ref, ion_handle_destroy);
+       ret = ion_handle_put_nolock(handle);
        mutex_unlock(&client->lock);
 
        return ret;
 }
 
+/* Must hold the client lock */
+static void user_ion_handle_get(struct ion_handle *handle)
+{
+       if (handle->user_ref_count++ == 0)
+               kref_get(&handle->ref);
+
+}
+
+/* Must hold the client lock */
+static struct ion_handle *user_ion_handle_get_check_overflow(struct ion_handle *handle)
+{
+       if (handle->user_ref_count + 1 == 0)
+               return ERR_PTR(-EOVERFLOW);
+       user_ion_handle_get(handle);
+       return handle;
+}
+/* passes a kref to the user ref count.
+ * We know we're holding a kref to the object before and
+ * after this call, so no need to reverify handle.
+ */
+static struct ion_handle *pass_to_user(struct ion_handle *handle)
+{
+       struct ion_client *client = handle->client;
+       struct ion_handle *ret;
+       mutex_lock(&client->lock);
+       ret = user_ion_handle_get_check_overflow(handle);
+       ion_handle_put_nolock(handle);
+       mutex_unlock(&client->lock);
+       return ret;
+}
+
+/* Must hold the client lock */
+static int user_ion_handle_put_nolock(struct ion_handle *handle)
+{
+       int ret;
+       if (--handle->user_ref_count == 0)
+               ret = ion_handle_put_nolock(handle);
+
+       return ret;
+}
 static struct ion_handle *ion_handle_lookup(struct ion_client *client,
                                            struct ion_buffer *buffer)
 {
@@ -484,20 +544,31 @@ static struct ion_handle *ion_handle_lookup(struct ion_client *client,
        return ERR_PTR(-EINVAL);
 }
 
-static struct ion_handle *ion_handle_get_by_id(struct ion_client *client,
+static struct ion_handle *ion_handle_get_by_id_nolock(struct ion_client *client,
                                                int id)
 {
        struct ion_handle *handle;
 
-       mutex_lock(&client->lock);
        handle = idr_find(&client->idr, id);
        if (handle)
-               ion_handle_get(handle);
+               return ion_handle_get_check_overflow(handle);
+
+       return ERR_PTR(-EINVAL);
+}
+
+struct ion_handle *ion_handle_get_by_id(struct ion_client *client,
+                                               int id)
+{
+       struct ion_handle *handle;
+
+       mutex_lock(&client->lock);
+       handle = ion_handle_get_by_id_nolock(client, id);
        mutex_unlock(&client->lock);
 
-       return handle ? handle : ERR_PTR(-EINVAL);
+       return handle;
 }
 
+
 static bool ion_handle_validate(struct ion_client *client,
                                struct ion_handle *handle)
 {
@@ -540,7 +611,7 @@ static int ion_handle_add(struct ion_client *client, struct ion_handle *handle)
 
 struct ion_handle *__ion_alloc(struct ion_client *client, size_t len,
                             size_t align, unsigned int heap_id_mask,
-                            unsigned int flags)
+                            unsigned int flags, bool grab_handle)
 {
        struct ion_handle *handle;
        struct ion_device *dev = client->dev;
@@ -606,6 +677,8 @@ struct ion_handle *__ion_alloc(struct ion_client *client, size_t len,
         }
 
        mutex_lock(&client->lock);
+       if (grab_handle)
+               ion_handle_get(handle);
        ret = ion_handle_add(client, handle);
        mutex_unlock(&client->lock);
        if (ret) {
@@ -623,44 +696,49 @@ struct ion_handle *ion_alloc(struct ion_client *client, size_t len,
                              size_t align, unsigned int heap_id_mask,
                              unsigned int flags)
 {
-    struct ion_handle * handle;
-    handle = __ion_alloc(client, len, align, heap_id_mask, flags);
-    if(IS_ERR_OR_NULL(handle)) {
-        IONMSG("%s handle is error 0x%p", __func__, handle);
-       return handle;
-    }
-    
-    ion_debug_kern_rec(client, handle->buffer, handle, ION_FUNCTION_ALLOC, 0, 0, 0, 0);
-
-    return handle;
+    return __ion_alloc(client, len, align, heap_id_mask, flags, false);
 }
 EXPORT_SYMBOL(ion_alloc);
 
-void __ion_free(struct ion_client *client, struct ion_handle *handle, int from_kern)
+static void user_ion_free_nolock(struct ion_client *client, struct ion_handle *handle)
+{
+       bool valid_handle;
+       BUG_ON(client != handle->client);
+       valid_handle = ion_handle_validate(client, handle);
+       if (!valid_handle) {
+               WARN(1, "%s: invalid handle passed to free.\n", __func__);
+               return;
+       }
+       if (!handle->user_ref_count > 0) {
+               WARN(1, "%s: User does not have access!\n", __func__);
+               return;
+       }
+       user_ion_handle_put_nolock(handle);
+}
+static void ion_free_nolock(struct ion_client *client, struct ion_handle *handle)
 {
        bool valid_handle;
 
        BUG_ON(client != handle->client);
 
-       mutex_lock(&client->lock);
        valid_handle = ion_handle_validate(client, handle);
 
        if (!valid_handle) {
                WARN(1, "%s: invalid handle passed to free.\n", __func__);
-               mutex_unlock(&client->lock);
                return;
        }
-       mutex_unlock(&client->lock);
-
-       if(from_kern)
-               ion_debug_kern_rec(client, handle->buffer, NULL, ION_FUNCTION_FREE, 0, 0, 0, 0);
-
-       ion_handle_put(handle);
+       ion_handle_put_nolock(handle);
 }
 
 void ion_free(struct ion_client *client, struct ion_handle *handle)
 {
-       return __ion_free(client, handle, 1);
+       BUG_ON(client != handle->client);
+
+       mutex_lock(&client->lock);
+       ion_free_nolock(client, handle);
+       mutex_unlock(&client->lock);
+
+       ion_debug_kern_rec(client, handle->buffer, NULL, ION_FUNCTION_FREE, 0, 0, 0, 0);
 }
 EXPORT_SYMBOL(ion_free);
 
@@ -1355,7 +1433,7 @@ struct ion_handle *__ion_import_dma_buf(struct ion_client *client, int fd, int f
        /* if a handle exists for this buffer just take a reference to it */
        handle = ion_handle_lookup(client, buffer);
        if (!IS_ERR(handle)) {
-               ion_handle_get(handle);
+               handle = ion_handle_get_check_overflow(handle);
                mutex_unlock(&client->lock);
                goto end;
        }
@@ -1471,13 +1549,13 @@ static long ion_ioctl(struct file *filp, unsigned int cmd, unsigned long arg)
                handle = __ion_alloc(client, data.allocation.len,
                                                data.allocation.align,
                                                data.allocation.heap_id_mask,
-                                               data.allocation.flags);
+                                               data.allocation.flags, true);
                if (IS_ERR(handle)) {
                         ret = PTR_ERR(handle);
                         IONMSG("ION_IOC_ALLOC handle is invalid. ret = %d.\n", ret);
                        return ret;
                 }
-
+               pass_to_user(handle);
                data.allocation.handle = handle->id;
 
                cleanup_handle = handle;
@@ -1487,14 +1565,16 @@ static long ion_ioctl(struct file *filp, unsigned int cmd, unsigned long arg)
        {
                struct ion_handle *handle;
 
-               handle = ion_handle_get_by_id(client, data.handle.handle);
+               mutex_lock(&client->lock);
+               handle = ion_handle_get_by_id_nolock(client, data.handle.handle);
                if (IS_ERR(handle)) {
-                        ret = PTR_ERR(handle);
-                        IONMSG("ION_IOC_FREE handle is invalid. handle = %d, ret = %d.\n", data.handle.handle, ret);
-                       return ret;
-                }
-               __ion_free(client, handle, 0);
-               ion_handle_put(handle);
+                       mutex_unlock(&client->lock);
+                       IONMSG("ION_IOC_FREE handle is invalid. handle = %d, ret = %d.\n", data.handle.handle, ret);
+                       return PTR_ERR(handle);
+               }
+               user_ion_free_nolock(client, handle);
+               ion_handle_put_nolock(handle);
+               mutex_unlock(&client->lock);
                break;
        }
        case ION_IOC_SHARE:
@@ -1524,10 +1604,13 @@ static long ion_ioctl(struct file *filp, unsigned int cmd, unsigned long arg)
                {
                        ret = PTR_ERR(handle);
                        IONMSG("ion_import fail: fd=%d, ret=%d\n", data.fd.fd, ret);
-               }
-               else
-                       data.handle.handle = handle->id;
-               break;
+               } else {
+                       handle = pass_to_user(handle);
+                       if (IS_ERR(handle))
+                               ret = PTR_ERR(handle);
+                       else
+                               data.handle.handle = handle->id;
+               }               break;
        }
        case ION_IOC_SYNC:
        {
@@ -1552,12 +1635,18 @@ static long ion_ioctl(struct file *filp, unsigned int cmd, unsigned long arg)
 
        if (dir & _IOC_READ) {
                if (copy_to_user((void __user *)arg, &data, _IOC_SIZE(cmd))) {
-                       if (cleanup_handle) 
-                               ion_free(client, cleanup_handle);
+                       if (cleanup_handle) {
+                               mutex_lock(&client->lock);
+                               user_ion_free_nolock(client, cleanup_handle);
+                               ion_handle_put_nolock(cleanup_handle);
+                               mutex_unlock(&client->lock);
+                       }
                         IONMSG("ion_ioctl copy_to_user fail! cmd = %d, n = %d.\n", cmd, _IOC_SIZE(cmd));
                        return -EFAULT;
                }
        }
+       if (cleanup_handle)
+               ion_handle_put(cleanup_handle);
        return ret;
 }
 
index d5cee8f6eceb5507074b226227f65b720c92ddc9..f9d6cfded7df5ba95d84e76645ba0c21bebf4b11 100644 (file)
@@ -107,6 +107,7 @@ struct ion_handle_debug {
  */
 struct ion_handle {
        struct kref ref;
+       unsigned int user_ref_count;
        struct ion_client *client;
        struct ion_buffer *buffer;
        struct rb_node node;
index 28b667fe8b71d75dda31bd8d649a0aa76dbd86e5..e7f8163953e57ce6b9ec0824cdf4aa3427c477f8 100644 (file)
@@ -992,8 +992,8 @@ EXPORT_SYMBOL(start_tty);
 /* We limit tty time update visibility to every 8 seconds or so. */
 static void tty_update_time(struct timespec *time)
 {
-       unsigned long sec = get_seconds() & ~7;
-       if ((long)(sec - time->tv_sec) > 0)
+       unsigned long sec = get_seconds();
+       if (abs(sec - time->tv_sec) & ~7)
                time->tv_sec = sec;
 }
 
@@ -2569,6 +2569,28 @@ static int tiocsetd(struct tty_struct *tty, int __user *p)
        return ret;
 }
 
+/**
+ *     tiocgetd        -       get line discipline
+ *     @tty: tty device
+ *     @p: pointer to user data
+ *
+ *     Retrieves the line discipline id directly from the ldisc.
+ *
+ *     Locking: waits for ldisc reference (in case the line discipline
+ *             is changing or the tty is being hungup)
+ */
+
+static int tiocgetd(struct tty_struct *tty, int __user *p)
+{
+       struct tty_ldisc *ld;
+       int ret;
+
+       ld = tty_ldisc_ref_wait(tty);
+       ret = put_user(ld->ops->num, p);
+       tty_ldisc_deref(ld);
+       return ret;
+}
+
 /**
  *     send_break      -       performed time break
  *     @tty: device to break on
@@ -2783,7 +2805,7 @@ long tty_ioctl(struct file *file, unsigned int cmd, unsigned long arg)
        case TIOCGSID:
                return tiocgsid(tty, real_tty, p);
        case TIOCGETD:
-               return put_user(tty->ldisc->ops->num, (int __user *)p);
+               return tiocgetd(tty, p);
        case TIOCSETD:
                return tiocsetd(tty, p);
        case TIOCVHANGUP:
index b7b8048f12539e2e672d902ce123056693a5a748..420dd6e52a2794439c52638503a5bf5c09ae5578 100644 (file)
@@ -415,6 +415,10 @@ EXPORT_SYMBOL_GPL(tty_ldisc_flush);
  *     they are not on hot paths so a little discipline won't do
  *     any harm.
  *
+ *     The line discipline-related tty_struct fields are reset to
+ *     prevent the ldisc driver from re-using stale information for
+ *     the new ldisc instance.
+ *
  *     Locking: takes termios_mutex
  */
 
@@ -423,6 +427,9 @@ static void tty_set_termios_ldisc(struct tty_struct *tty, int num)
        mutex_lock(&tty->termios_mutex);
        tty->termios.c_line = num;
        mutex_unlock(&tty->termios_mutex);
+
+       tty->disc_data = NULL;
+       tty->receive_room = 0;
 }
 
 /**
index 39901aca9abcc32b314ac3d15e9ed5b7a3edc95a..5297a199e41d7e7f970976d8461020a5bfa88a98 100644 (file)
@@ -1109,10 +1109,11 @@ static int proc_getdriver(struct dev_state *ps, void __user *arg)
 
 static int proc_connectinfo(struct dev_state *ps, void __user *arg)
 {
-       struct usbdevfs_connectinfo ci = {
-               .devnum = ps->dev->devnum,
-               .slow = ps->dev->speed == USB_SPEED_LOW
-       };
+       struct usbdevfs_connectinfo ci;
+
+       memset(&ci, 0, sizeof(ci));
+       ci.devnum = ps->dev->devnum;
+       ci.slow = ps->dev->speed == USB_SPEED_LOW;
 
        if (copy_to_user(arg, &ci, sizeof(ci)))
                return -EFAULT;
index ca8b4c22ba6961bcb94e46b217a841ec3dfd9ce1..c3d87b81a47ecc186afedb3e40563d07ea7e045d 100644 (file)
@@ -233,6 +233,7 @@ EXPORT_SYMBOL_GPL(ehci_cf_port_reset_rwsem);
 #define HUB_DEBOUNCE_STEP        25
 #define HUB_DEBOUNCE_STABLE     100
 
+static void hub_release(struct kref *kref);
 static int usb_reset_and_verify_device(struct usb_device *udev);
 
 #define usb_sndaddr0pipe()     (PIPE_CONTROL << 30)
@@ -1145,10 +1146,21 @@ static void hub_activate(struct usb_hub *hub, enum hub_activation_type type)
        unsigned delay;
 
        /* Continue a partial initialization */
-       if (type == HUB_INIT2)
-               goto init2;
-       if (type == HUB_INIT3)
+       if (type == HUB_INIT2 || type == HUB_INIT3) {
+               device_lock(hub->intfdev);
+
+               /* Was the hub disconnected while we were waiting? */
+               if (hub->disconnected) {
+                       device_unlock(hub->intfdev);
+                       kref_put(&hub->kref, hub_release);
+                       return;
+               }
+               if (type == HUB_INIT2)
+                       goto init2;
+
                goto init3;
+       }
+       kref_get(&hub->kref);
 
        /* The superspeed hub except for root hub has to use Hub Depth
         * value as an offset into the route string to locate the bits
@@ -1344,6 +1356,7 @@ static void hub_activate(struct usb_hub *hub, enum hub_activation_type type)
                        PREPARE_DELAYED_WORK(&hub->init_work, hub_init_func3);
                        schedule_delayed_work(&hub->init_work,
                                        msecs_to_jiffies(delay));
+                       device_unlock(hub->intfdev);
                        return;         /* Continues at init3: below */
                } else {
                        msleep(delay);
@@ -1364,6 +1377,11 @@ static void hub_activate(struct usb_hub *hub, enum hub_activation_type type)
        /* Allow autosuspend if it was suppressed */
        if (type <= HUB_INIT3)
                usb_autopm_put_interface_async(to_usb_interface(hub->intfdev));
+
+       if (type == HUB_INIT2 || type == HUB_INIT3)
+               device_unlock(hub->intfdev);
+
+       kref_put(&hub->kref, hub_release);
 }
 
 /* Implement the continuations for the delays above */
@@ -2291,7 +2309,7 @@ void usb_disconnect(struct usb_device **pdev)
        put_device(&udev->dev);
 
 #ifdef CONFIG_MTK_ICUSB_SUPPORT
-       if(is_icusb_rh)
+       if (is_icusb_rh)
        {
                set_icusb_sts_disconnect_done();
                MYDBG("ICUSB Disconnect\n");
index 8061d8e6b9fbde97ef9e4e90838dcd4b3321cda7..75b2f0b18522ec6bd840888aada064767bd7d782 100644 (file)
@@ -305,8 +305,10 @@ static int adf_buffer_map(struct adf_device *dev, struct adf_buffer *buf,
        }
 
 done:
-       if (ret < 0)
+       if (ret < 0) {
                adf_buffer_mapping_cleanup(mapping, buf);
+               memset(mapping, 0, sizeof(*mapping));
+       }
 
        return ret;
 }
index 7af425f53beef91a6d21dc86b76e161ff7ed1696..142180cd805531987812088630111a88416724a5 100644 (file)
@@ -320,32 +320,26 @@ static int v9fs_xattr_set_acl(struct dentry *dentry, const char *name,
        case ACL_TYPE_ACCESS:
                name = POSIX_ACL_XATTR_ACCESS;
                if (acl) {
-                       umode_t mode = inode->i_mode;
-                       retval = posix_acl_equiv_mode(acl, &mode);
-                       if (retval < 0)
+                       struct iattr iattr;
+
+                       retval = posix_acl_update_mode(inode, &iattr.ia_mode, &acl);
+                       if (retval)
                                goto err_out;
-                       else {
-                               struct iattr iattr;
-                               if (retval == 0) {
-                                       /*
-                                        * ACL can be represented
-                                        * by the mode bits. So don't
-                                        * update ACL.
-                                        */
-                                       acl = NULL;
-                                       value = NULL;
-                                       size = 0;
-                               }
-                               /* Updte the mode bits */
-                               iattr.ia_mode = ((mode & S_IALLUGO) |
-                                                (inode->i_mode & ~S_IALLUGO));
+                       if (!acl) {
+                               /*
+                                * ACL can be represented
+                                * by the mode bits. So don't
+                                * update ACL.
+                                */
+                               value = NULL;
+                               size = 0;
+                       }
                                iattr.ia_valid = ATTR_MODE;
                                /* FIXME should we update ctime ?
                                 * What is the following setxattr update the
                                 * mode ?
                                 */
                                v9fs_vfs_setattr_dotl(dentry, &iattr);
-                       }
                }
                break;
        case ACL_TYPE_DEFAULT:
index ded94c4fa30d31a6997625d007548d119c2aa75d..e6483800c73433a0ce4b7485be1f64f70f6d56cf 100644 (file)
--- a/fs/aio.c
+++ b/fs/aio.c
@@ -35,6 +35,7 @@
 #include <linux/eventfd.h>
 #include <linux/blkdev.h>
 #include <linux/compat.h>
+#include <linux/personality.h>
 
 #include <asm/kmap_types.h>
 #include <asm/uaccess.h>
@@ -153,6 +154,9 @@ static int aio_setup_ring(struct kioctx *ctx)
        unsigned long size, populate;
        int nr_pages;
 
+       if (current->personality & READ_IMPLIES_EXEC)
+               return -EPERM;
+
        /* Compensate for the ring buffer's head/tail overlap entry */
        nr_events += 2; /* 1 is required, 2 for good luck */
 
@@ -977,12 +981,17 @@ static ssize_t aio_setup_vectored_rw(int rw, struct kiocb *kiocb, bool compat)
 
 static ssize_t aio_setup_single_vector(int rw, struct kiocb *kiocb)
 {
-       if (unlikely(!access_ok(!rw, kiocb->ki_buf, kiocb->ki_nbytes)))
+       size_t len = kiocb->ki_nbytes;
+
+       if (len > MAX_RW_COUNT)
+               len = MAX_RW_COUNT;
+
+       if (unlikely(!access_ok(!rw, kiocb->ki_buf, len)))
                return -EFAULT;
 
        kiocb->ki_iovec = &kiocb->ki_inline_vec;
        kiocb->ki_iovec->iov_base = kiocb->ki_buf;
-       kiocb->ki_iovec->iov_len = kiocb->ki_nbytes;
+       kiocb->ki_iovec->iov_len = len;
        kiocb->ki_nr_segs = 1;
        return 0;
 }
index 0890c83643e944f69e43a22f4151e381e7503f04..d6d53e5e7945db193e1fec7cdfbb6b230b916542 100644 (file)
@@ -118,11 +118,9 @@ static int btrfs_set_acl(struct btrfs_trans_handle *trans,
        case ACL_TYPE_ACCESS:
                name = POSIX_ACL_XATTR_ACCESS;
                if (acl) {
-                       ret = posix_acl_equiv_mode(acl, &inode->i_mode);
-                       if (ret < 0)
+                       ret = posix_acl_update_mode(inode, &inode->i_mode, &acl);
+                       if (ret)
                                return ret;
-                       if (ret == 0)
-                               acl = NULL;
                }
                ret = 0;
                break;
index e924cf45aad9559533214814cccbb05aa7a06b44..753b99301a7aa6013e4ac007f9c3b756672494d8 100644 (file)
@@ -567,6 +567,13 @@ static struct dentry *ecryptfs_mount(struct file_system_type *fs_type, int flags
        s->s_maxbytes = path.dentry->d_sb->s_maxbytes;
        s->s_blocksize = path.dentry->d_sb->s_blocksize;
        s->s_magic = ECRYPTFS_SUPER_MAGIC;
+       s->s_magic = path.dentry->d_sb->s_stack_depth + 1;
+
+       rc = -EINVAL;
+       if (s->s_stack_depth > FILESYSTEM_MAX_STACK_DEPTH) {
+               pr_err("eCryptfs: maximum fs stacking depth exceeded\n");
+               goto out_free;
+       }
 
        inode = ecryptfs_get_inode(path.dentry->d_inode, s);
        rc = PTR_ERR(inode);
index 110b6b371a4edc353fc1904bcc79299580087184..48c3c2d7d2619e4c27121de46d9d8dc8c9dbb391 100644 (file)
@@ -206,15 +206,11 @@ ext2_set_acl(struct inode *inode, int type, struct posix_acl *acl)
                case ACL_TYPE_ACCESS:
                        name_index = EXT2_XATTR_INDEX_POSIX_ACL_ACCESS;
                        if (acl) {
-                               error = posix_acl_equiv_mode(acl, &inode->i_mode);
-                               if (error < 0)
+                               error = posix_acl_update_mode(inode, &inode->i_mode, &acl);
+                               if (error)
                                        return error;
-                               else {
-                                       inode->i_ctime = CURRENT_TIME_SEC;
-                                       mark_inode_dirty(inode);
-                                       if (error == 0)
-                                               acl = NULL;
-                               }
+                               inode->i_ctime = CURRENT_TIME_SEC;
+                               mark_inode_dirty(inode);
                        }
                        break;
 
index dbb5ad59a7fc3c22380ce30b9034f8942bec967b..bb2f60a62d82ad42f8659e858a360a9231631957 100644 (file)
@@ -205,15 +205,11 @@ ext3_set_acl(handle_t *handle, struct inode *inode, int type,
                case ACL_TYPE_ACCESS:
                        name_index = EXT3_XATTR_INDEX_POSIX_ACL_ACCESS;
                        if (acl) {
-                               error = posix_acl_equiv_mode(acl, &inode->i_mode);
-                               if (error < 0)
+                               error = posix_acl_update_mode(inode, &inode->i_mode, &acl);
+                               if (error)
                                        return error;
-                               else {
-                                       inode->i_ctime = CURRENT_TIME_SEC;
-                                       ext3_mark_inode_dirty(handle, inode);
-                                       if (error == 0)
-                                               acl = NULL;
-                               }
+                               inode->i_ctime = CURRENT_TIME_SEC;
+                               ext3_mark_inode_dirty(handle, inode);
                        }
                        break;
 
index 39a54a0e9fe4a9a6290f75b961cde9ccea06f669..78d08c4d4de35b78a232c20235bbc2e1327feb7d 100644 (file)
@@ -211,15 +211,11 @@ ext4_set_acl(handle_t *handle, struct inode *inode, int type,
        case ACL_TYPE_ACCESS:
                name_index = EXT4_XATTR_INDEX_POSIX_ACL_ACCESS;
                if (acl) {
-                       error = posix_acl_equiv_mode(acl, &inode->i_mode);
+                       error = posix_acl_update_mode(inode, &inode->i_mode, &acl);
                        if (error < 0)
                                return error;
-                       else {
-                               inode->i_ctime = ext4_current_time(inode);
-                               ext4_mark_inode_dirty(handle, inode);
-                               if (error == 0)
-                                       acl = NULL;
-                       }
+                       inode->i_ctime = ext4_current_time(inode);
+                       ext4_mark_inode_dirty(handle, inode);
                }
                break;
 
index 1be3996b5942f7c4dd6706bf93e3bac69cc36123..3517d5af257437c2033c15d536301e1b499c0206 100644 (file)
@@ -75,8 +75,14 @@ int __ext4_journal_stop(const char *where, unsigned int line, handle_t *handle)
                ext4_put_nojournal(handle);
                return 0;
        }
-       sb = handle->h_transaction->t_journal->j_private;
+
        err = handle->h_err;
+       if (!handle->h_transaction) {
+               rc = jbd2_journal_stop(handle);
+               return err ? err : rc;
+       }
+
+       sb = handle->h_transaction->t_journal->j_private;
        rc = jbd2_journal_stop(handle);
 
        if (!err)
index 5f00ddfe3d9b08c42a5b99df5bfd9768a876b57f..88bcf078ffb52d5d3705df2d499c7bda79e3b2ea 100644 (file)
@@ -3600,6 +3600,7 @@ int ext4_can_truncate(struct inode *inode)
 
 int ext4_punch_hole(struct file *file, loff_t offset, loff_t length)
 {
+#if 0
        struct inode *inode = file_inode(file);
        struct super_block *sb = inode->i_sb;
        ext4_lblk_t first_block, stop_block;
@@ -3785,6 +3786,12 @@ out_dio:
 out_mutex:
        mutex_unlock(&inode->i_mutex);
        return ret;
+#else
+       /*
+        * Disabled as per b/28760453
+        */
+       return -EOPNOTSUPP;
+#endif
 }
 
 /*
index 44abc2f286e00ad4ecff03e0293f80ab8d3d19fd..9c4f3c732bce4a3a6773c848c1a05eb25c7cb1d1 100644 (file)
@@ -223,12 +223,10 @@ static int f2fs_set_acl(struct inode *inode, int type, struct posix_acl *acl)
        case ACL_TYPE_ACCESS:
                name_index = F2FS_XATTR_INDEX_POSIX_ACL_ACCESS;
                if (acl) {
-                       error = posix_acl_equiv_mode(acl, &inode->i_mode);
-                       if (error < 0)
+                       error = posix_acl_update_mode(inode, &inode->i_mode, &acl);
+                       if (error)
                                return error;
                        set_acl_inode(fi, inode->i_mode);
-                       if (error == 0)
-                               acl = NULL;
                }
                break;
 
index b3f3676796d31a6870a771ed6952977cfc16d448..21408084c3b34c9fb51d706fc69480a9fd2915a2 100644 (file)
@@ -87,14 +87,10 @@ generic_acl_set(struct dentry *dentry, const char *name, const void *value,
                        goto failed;
                switch (type) {
                case ACL_TYPE_ACCESS:
-                       error = posix_acl_equiv_mode(acl, &inode->i_mode);
-                       if (error < 0)
+                       error = posix_acl_update_mode(inode, &inode->i_mode, &acl);
+                       if (error)
                                goto failed;
                        inode->i_ctime = CURRENT_TIME;
-                       if (error == 0) {
-                               posix_acl_release(acl);
-                               acl = NULL;
-                       }
                        break;
                case ACL_TYPE_DEFAULT:
                        if (!S_ISDIR(inode->i_mode)) {
index f69ac0af5496cd456bf6df4d0c932747b6767779..a4813c36842c81b166dc2e6bcea683b41ecf7605 100644 (file)
@@ -268,15 +268,11 @@ static int gfs2_xattr_system_set(struct dentry *dentry, const char *name,
 
        if (type == ACL_TYPE_ACCESS) {
                umode_t mode = inode->i_mode;
-               error = posix_acl_equiv_mode(acl, &mode);
 
-               if (error <= 0) {
-                       posix_acl_release(acl);
-                       acl = NULL;
+               error = posix_acl_update_mode(inode, &inode->i_mode, &acl);
 
-                       if (error < 0)
-                               return error;
-               }
+               if (error)
+                       goto out_release;
 
                error = gfs2_set_mode(inode, mode);
                if (error)
index e50170ca7c33f446acc16e29a0d0097828919c30..46f0e24f43e99cc0a7efd71a1130797fbf032637 100644 (file)
@@ -149,8 +149,10 @@ static int get_task_ioprio(struct task_struct *p)
        if (ret)
                goto out;
        ret = IOPRIO_PRIO_VALUE(IOPRIO_CLASS_NONE, IOPRIO_NORM);
+       task_lock(p);
        if (p->io_context)
                ret = p->io_context->ioprio;
+       task_unlock(p);
 out:
        return ret;
 }
index 223283c301116f3d8d88cb70cf30aa030a54c456..9335b8d3cf5212cede3093af48bf37567400623d 100644 (file)
@@ -243,9 +243,10 @@ static int jffs2_set_acl(struct inode *inode, int type, struct posix_acl *acl)
        case ACL_TYPE_ACCESS:
                xprefix = JFFS2_XPREFIX_ACL_ACCESS;
                if (acl) {
-                       umode_t mode = inode->i_mode;
-                       rc = posix_acl_equiv_mode(acl, &mode);
-                       if (rc < 0)
+                       umode_t mode;
+
+                       rc = posix_acl_update_mode(inode, &mode, &acl);
+                       if (rc)
                                return rc;
                        if (inode->i_mode != mode) {
                                struct iattr attr;
@@ -257,8 +258,6 @@ static int jffs2_set_acl(struct inode *inode, int type, struct posix_acl *acl)
                                if (rc < 0)
                                        return rc;
                        }
-                       if (rc == 0)
-                               acl = NULL;
                }
                break;
        case ACL_TYPE_DEFAULT:
index 42d67f9757bf641d316b07e78a3fb1a698f76409..c79b1d7a53e24be8c918313318b325b949997954 100644 (file)
@@ -693,11 +693,11 @@ static int can_set_system_xattr(struct inode *inode, const char *name,
                        return rc;
                }
                if (acl) {
-                       rc = posix_acl_equiv_mode(acl, &inode->i_mode);
+                       rc = posix_acl_update_mode(inode, &inode->i_mode, &acl);
                        posix_acl_release(acl);
-                       if (rc < 0) {
+                       if (rc) {
                                printk(KERN_ERR
-                                      "posix_acl_equiv_mode returned %d\n",
+                                      "posix_acl_update_mode returned %d\n",
                                       rc);
                                return rc;
                        }
index 8a404576fb26557eb8578e21f66d0277a94a9e76..aae4a2311f07b7025389c92bb514f45ef6b4d652 100644 (file)
@@ -275,19 +275,13 @@ static int ocfs2_set_acl(handle_t *handle,
                name_index = OCFS2_XATTR_INDEX_POSIX_ACL_ACCESS;
                if (acl) {
                        umode_t mode = inode->i_mode;
-                       ret = posix_acl_equiv_mode(acl, &mode);
-                       if (ret < 0)
+                       ret = posix_acl_update_mode(inode, &mode, &acl);
+                       if (ret)
+                               return ret;
+                       ret = ocfs2_acl_set_mode(inode, di_bh,
+                                               handle, mode);
+                       if (ret)
                                return ret;
-                       else {
-                               if (ret == 0)
-                                       acl = NULL;
-
-                               ret = ocfs2_acl_set_mode(inode, di_bh,
-                                                        handle, mode);
-                               if (ret)
-                                       return ret;
-
-                       }
                }
                break;
        case ACL_TYPE_DEFAULT:
index 3542f1f814e2a966d33429f61e9f78ab5404a18c..35cc1f40b82df52a0aa14ccb1830b7726c36463a 100644 (file)
@@ -341,6 +341,37 @@ static int posix_acl_create_masq(struct posix_acl *acl, umode_t *mode_p)
         return not_equiv;
 }
 
+/**
+ * posix_acl_update_mode  -  update mode in set_acl
+ *
+ * Update the file mode when setting an ACL: compute the new file permission
+ * bits based on the ACL.  In addition, if the ACL is equivalent to the new
+ * file mode, set *acl to NULL to indicate that no ACL should be set.
+ *
+ * As with chmod, clear the setgit bit if the caller is not in the owning group
+ * or capable of CAP_FSETID (see inode_change_ok).
+ *
+ * Called from set_acl inode operations.
+ */
+int posix_acl_update_mode(struct inode *inode, umode_t *mode_p,
+                         struct posix_acl **acl)
+{
+       umode_t mode = inode->i_mode;
+       int error;
+
+       error = posix_acl_equiv_mode(*acl, &mode);
+       if (error < 0)
+               return error;
+       if (error == 0)
+               *acl = NULL;
+       if (!in_group_p(inode->i_gid) &&
+           !capable_wrt_inode_uidgid(inode, CAP_FSETID))
+               mode &= ~S_ISGID;
+       *mode_p = mode;
+       return 0;
+}
+EXPORT_SYMBOL(posix_acl_update_mode);
+
 /*
  * Modify the ACL for the chmod syscall.
  */
index cbd0f1b324b972b96f036139fcd96bf53a03fb01..05dff1cbd5ede27c66da2b5caacad39703d29a6b 100644 (file)
@@ -168,16 +168,16 @@ static inline void task_state(struct seq_file *m, struct pid_namespace *ns,
        int g;
        struct fdtable *fdt = NULL;
        const struct cred *cred;
-       pid_t ppid, tpid;
+       pid_t ppid = 0, tpid = 0;
+       struct task_struct *leader = NULL;
 
        rcu_read_lock();
-       ppid = pid_alive(p) ?
-               task_tgid_nr_ns(rcu_dereference(p->real_parent), ns) : 0;
-       tpid = 0;
        if (pid_alive(p)) {
                struct task_struct *tracer = ptrace_parent(p);
                if (tracer)
                        tpid = task_pid_nr_ns(tracer, ns);
+               ppid = task_tgid_nr_ns(rcu_dereference(p->real_parent), ns);
+               leader = p->group_leader;
        }
        cred = get_task_cred(p);
        seq_printf(m,
@@ -189,7 +189,7 @@ static inline void task_state(struct seq_file *m, struct pid_namespace *ns,
                "Uid:\t%d\t%d\t%d\t%d\n"
                "Gid:\t%d\t%d\t%d\t%d\n",
                get_task_state(p),
-               task_tgid_nr_ns(p, ns),
+               leader ? task_pid_nr_ns(leader, ns) : 0,
                pid_nr_ns(pid, ns),
                ppid, tpid,
                from_kuid_munged(user_ns, cred->uid),
index 361b02119902da4656197c222047a06b113912c8..1caa60e5271e76f687f88faae669ad74b0198169 100644 (file)
@@ -850,7 +850,8 @@ static ssize_t environ_read(struct file *file, char __user *buf,
        int ret = 0;
        struct mm_struct *mm = file->private_data;
 
-       if (!mm)
+       /* Ensure the process spawned far enough to have an environment. */
+       if (!mm || !mm->env_end)
                return 0;
 
        page = (char *)__get_free_page(GFP_TEMPORARY);
index 6c8767fdfc6a287b0a9d201b4048d89b06fecaad..2d73589f37d643fe2a38ab76188cc92e2c4c91d6 100644 (file)
@@ -286,13 +286,9 @@ reiserfs_set_acl(struct reiserfs_transaction_handle *th, struct inode *inode,
        case ACL_TYPE_ACCESS:
                name = POSIX_ACL_XATTR_ACCESS;
                if (acl) {
-                       error = posix_acl_equiv_mode(acl, &inode->i_mode);
-                       if (error < 0)
+                       error = posix_acl_update_mode(inode, &inode->i_mode, &acl);
+                       if (error)
                                return error;
-                       else {
-                               if (error == 0)
-                                       acl = NULL;
-                       }
                }
                break;
        case ACL_TYPE_DEFAULT:
index 0f7398b89ed199436773e49b6d84294d5dc82371..e342c573074fe2ef78edd4256af97a402c5320ce 100644 (file)
@@ -272,7 +272,7 @@ long long ubifs_calc_available(const struct ubifs_info *c, int min_idx_lebs)
  */
 static int can_use_rp(struct ubifs_info *c)
 {
-       if (uid_eq(current_fsuid(), c->rp_uid) || capable(CAP_SYS_RESOURCE) ||
+       if (uid_lte(current_fsuid(), c->rp_uid) || capable(CAP_SYS_RESOURCE) ||
            (!gid_eq(c->rp_gid, GLOBAL_ROOT_GID) && in_group_p(c->rp_gid)))
                return 1;
        return 0;
index 4aa095b6736abcd966bdd74e6b4f7956b0f23374..20771ddbc79be302e915d3218b63674e8f246ad8 100644 (file)
@@ -58,7 +58,9 @@
 #define DEFAULT_RP_PERCENT 5
 
 /* The default maximum size of reserved pool in bytes */
-#define DEFAULT_MAX_RP_SIZE (512*1024)
+#define DEFAULT_MAX_RP_SIZE (16*1024*1024)
+
+#define UBIFS_ONE_GIGA 1024*1024*1024
 
 /* Default time granularity in nanoseconds */
 #define DEFAULT_TIME_GRAN 1000000000
@@ -193,11 +195,15 @@ static int create_default_filesystem(struct ubifs_info *c)
        generate_random_uuid(sup->uuid);
 
        main_bytes = (long long)main_lebs * c->leb_size;
-       tmp64 = div_u64(main_bytes * DEFAULT_RP_PERCENT, 100);
-       if (tmp64 > DEFAULT_MAX_RP_SIZE)
+
+       /*If the size of a volume is bigger than 1G, set rp_size to DEFAULT_MAX_RP_SIZE(16M).*/
+       if (main_bytes >= UBIFS_ONE_GIGA)
                tmp64 = DEFAULT_MAX_RP_SIZE;
+       else
+               tmp64 = 0;
+
        sup->rp_size = cpu_to_le64(tmp64);
-       sup->rp_uid = 9996; //VID_CCCI
+       sup->rp_uid = 10010; //VID_CCCI
        sup->ro_compat_version = cpu_to_le32(UBIFS_RO_COMPAT_VERSION);
 
        err = ubifs_write_node(c, sup, UBIFS_SB_NODE_SZ, 0, 0);
index 306d883d89bc7d6420ca4b5b8c5f848e573249bf..ac7d7b3fb0bc023c5c774b53c55857910925aeb9 100644 (file)
@@ -389,15 +389,10 @@ xfs_xattr_acl_set(struct dentry *dentry, const char *name,
 
        if (type == ACL_TYPE_ACCESS) {
                umode_t mode = inode->i_mode;
-               error = posix_acl_equiv_mode(acl, &mode);
+               error = posix_acl_update_mode(inode, &mode, &acl);
 
-               if (error <= 0) {
-                       posix_acl_release(acl);
-                       acl = NULL;
-
-                       if (error < 0)
-                               return error;
-               }
+               if (error)
+                       goto out_release;
 
                error = xfs_set_mode(inode, mode);
                if (error)
index c585451da0ec208a8a620ba41a872cee913eb832..3b70fb0cb5b3b7342c3c5fc73eb6e78e2abba4f6 100644 (file)
@@ -244,6 +244,12 @@ struct iattr {
  */
 #include <linux/quota.h>
 
+/*
+ * Maximum number of layers of fs stack. Needs to be limited to
+ * prevent kernel stack overflow
+ */
+#define FILESYSTEM_MAX_STACK_DEPTH 2
+
 /** 
  * enum positive_aop_returns - aop return codes with specific semantics
  *
@@ -1322,6 +1328,11 @@ struct super_block {
 
        /* Being remounted read-only */
        int s_readonly_remount;
+
+       /*
+        * Indicates how deep in a filesystem stack this SB is
+        */
+       int s_stack_depth;
 };
 
 /* superblock cache pruning functions */
index 69d54fd6007503e0bd643bd382113a0c45bbd7c4..05c558ee8e5ab279b910cd37614b07c8916a3651 100644 (file)
@@ -1716,6 +1716,7 @@ static inline struct page *follow_page(struct vm_area_struct *vma,
 #define FOLL_HWPOISON  0x100   /* check page is hwpoisoned */
 #define FOLL_NUMA      0x200   /* force NUMA hinting page fault */
 #define FOLL_MIGRATION 0x400   /* wait for page to replace migration entry */
+#define FOLL_COW       0x4000  /* internal GUP flag */
 
 typedef int (*pte_fn_t)(pte_t *pte, pgtable_t token, unsigned long addr,
                        void *data);
index 7931efe7117553d00a920cfd4aef757f72578658..2ae0bba45f12478feab0808b5cf2442e6a6e4165 100644 (file)
@@ -90,6 +90,7 @@ extern struct posix_acl *posix_acl_from_mode(umode_t, gfp_t);
 extern int posix_acl_equiv_mode(const struct posix_acl *, umode_t *);
 extern int posix_acl_create(struct posix_acl **, gfp_t, umode_t *);
 extern int posix_acl_chmod(struct posix_acl **, gfp_t, umode_t);
+extern int posix_acl_update_mode(struct inode *, umode_t *, struct posix_acl **);
 
 extern struct posix_acl *get_posix_acl(struct inode *, int);
 extern int set_posix_acl(struct inode *, int, struct posix_acl *);
index 7faf933cced7018657d2212d543530484ce17ec9..386032aecb46f555abe784dee76a7b6e2d593f42 100644 (file)
@@ -18,7 +18,7 @@
 #include <linux/types.h>
 
 /* Enable/disable SYSRQ support by default (0==no, 1==yes). */
-#define SYSRQ_DEFAULT_ENABLE   1
+#define SYSRQ_DEFAULT_ENABLE   0
 
 /* Possible values of bitmask for enabling sysrq functions */
 /* 0x0001 is reserved for enable everything */
index 83adc1ee6b26450d5c69f9db0a6ceec1ffb429f6..c5a16f0f3a3d41e617a9cfc7f78c2e49bfda04e5 100644 (file)
@@ -299,6 +299,8 @@ typedef enum __VENC_DRV_VIDEO_LEVEL_T
     VENC_DRV_VIDEO_LEVEL_MEDIUM,            ///< VC1, MPEG2
     VENC_DRV_VIDEO_LEVEL_HIGH1440,          ///< MPEG2
     VENC_DRV_VIDEO_LEVEL_HIGH,              ///< VC1, MPEG2
+    VENC_DRV_VIDEO_LEVEL_6,                 ///< H263
+    VENC_DRV_VIDEO_LEVEL_7,               ///< H263
     VENC_DRV_VIDEO_LEVEL_MAX = 0xFFFFFFFF   ///< Max VENC_DRV_VIDEO_LEVEL_T value
 } VENC_DRV_VIDEO_LEVEL_T;
 
index dbdfd2b0f3b3dbe0a4470d83e19052db4ba3aa04..9120783132e71c5d653e85c6b300507b579457b7 100644 (file)
@@ -62,6 +62,7 @@ struct unix_sock {
 #define UNIX_GC_CANDIDATE      0
 #define UNIX_GC_MAYBE_CYCLE    1
        struct socket_wq        peer_wq;
+       wait_queue_t            peer_wake;
 };
 #define unix_sk(__sk) ((struct unix_sock *)__sk)
 
index ef12d718f7a3eef4187babbe4a21f44444862204..18af925cef1ff8da3a5253cb9e22f8c6095a7d45 100644 (file)
@@ -1394,6 +1394,8 @@ static inline void tcp_check_send_head(struct sock *sk, struct sk_buff *skb_unli
 {
        if (sk->sk_send_head == skb_unlinked)
                sk->sk_send_head = NULL;
+       if (tcp_sk(sk)->highest_sack == skb_unlinked)
+               tcp_sk(sk)->highest_sack = NULL;
 }
 
 static inline void tcp_init_send_head(struct sock *sk)
index 123c9b7c39795975e2ce18cf913aad6b1fbe5b85..b779642b29af9401fd15246816c376ec86e4fcab 100644 (file)
@@ -197,6 +197,9 @@ struct audit_context {
                        int                     fd;
                        int                     flags;
                } mmap;
+               struct {
+                       int                     argc;
+               } execve;
        };
        int fds[2];
 
index 03a3af8538bdd4e60bf514b52d23b7153fa8b638..138cce22ec9ad0507bde7504ad2aa32225960f8d 100644 (file)
@@ -68,7 +68,7 @@
 #include <linux/capability.h>
 #include <linux/fs_struct.h>
 #include <linux/compat.h>
-
+#include <linux/uaccess.h>
 #include "audit.h"
 
 /* flags stating the success for a syscall */
@@ -76,7 +76,8 @@
 #define AUDITSC_SUCCESS 1
 #define AUDITSC_FAILURE 2
 
-/* no execve audit message should be longer than this (userspace limits) */
+/* no execve audit message should be longer than this (userspace limits),
+ * see the note near the top of audit_log_execve_info() about this value */
 #define MAX_EXECVE_AUDIT_LEN 7500
 
 /* number of audit rules */
@@ -1010,189 +1011,180 @@ static int audit_log_pid_context(struct audit_context *context, pid_t pid,
        return rc;
 }
 
-/*
- * to_send and len_sent accounting are very loose estimates.  We aren't
- * really worried about a hard cap to MAX_EXECVE_AUDIT_LEN so much as being
- * within about 500 bytes (next page boundary)
- *
- * why snprintf?  an int is up to 12 digits long.  if we just assumed when
- * logging that a[%d]= was going to be 16 characters long we would be wasting
- * space in every audit message.  In one 7500 byte message we can log up to
- * about 1000 min size arguments.  That comes down to about 50% waste of space
- * if we didn't do the snprintf to find out how long arg_num_len was.
- */
-static int audit_log_single_execve_arg(struct audit_context *context,
-                                       struct audit_buffer **ab,
-                                       int arg_num,
-                                       size_t *len_sent,
-                                       const char __user *p,
-                                       char *buf)
+static void audit_log_execve_info(struct audit_context *context,
+                                struct audit_buffer **ab)
 {
-       char arg_num_len_buf[12];
-       const char __user *tmp_p = p;
-       /* how many digits are in arg_num? 5 is the length of ' a=""' */
-       size_t arg_num_len = snprintf(arg_num_len_buf, 12, "%d", arg_num) + 5;
-       size_t len, len_left, to_send;
-       size_t max_execve_audit_len = MAX_EXECVE_AUDIT_LEN;
-       unsigned int i, has_cntl = 0, too_long = 0;
-       int ret;
-
-       /* strnlen_user includes the null we don't want to send */
-       len_left = len = strnlen_user(p, MAX_ARG_STRLEN) - 1;
-
-       /*
-        * We just created this mm, if we can't find the strings
-        * we just copied into it something is _very_ wrong. Similar
-        * for strings that are too long, we should not have created
-        * any.
-        */
-       if (unlikely((len == -1) || len > MAX_ARG_STRLEN - 1)) {
-               WARN_ON(1);
-               send_sig(SIGKILL, current, 0);
-               return -1;
+       long len_max;
+       long len_rem;
+       long len_full;
+       long len_buf;
+       long len_abuf;
+       long len_tmp;
+       bool require_data;
+       bool encode;
+       unsigned int iter;
+       unsigned int arg;
+       char *buf_head;
+       char *buf;
+       const char __user *p = (const char __user *)current->mm->arg_start;
+
+       /* NOTE: this buffer needs to be large enough to hold all the non-arg
+        *       data we put in the audit record for this argument (see the
+        *       code below) ... at this point in time 96 is plenty */
+       char abuf[96];
+
+       /* NOTE: we set MAX_EXECVE_AUDIT_LEN to a rather arbitrary limit, the
+        *       current value of 7500 is not as important as the fact that it
+        *       is less than 8k, a setting of 7500 gives us plenty of wiggle
+        *       room if we go over a little bit in the logging below */
+       WARN_ON_ONCE(MAX_EXECVE_AUDIT_LEN > 7500);
+       len_max = MAX_EXECVE_AUDIT_LEN;
+
+       /* scratch buffer to hold the userspace args */
+       buf_head = kmalloc(MAX_EXECVE_AUDIT_LEN + 1, GFP_KERNEL);
+       if (!buf_head) {
+               audit_panic("out of memory for argv string");
+               return;
        }
+       buf = buf_head;
+
+       audit_log_format(*ab, "argc=%d", context->execve.argc);
+
+       len_rem = len_max;
+       len_buf = 0;
+       len_full = 0;
+       require_data = true;
+       encode = false;
+       iter = 0;
+       arg = 0;
 
-       /* walk the whole argument looking for non-ascii chars */
        do {
-               if (len_left > MAX_EXECVE_AUDIT_LEN)
-                       to_send = MAX_EXECVE_AUDIT_LEN;
-               else
-                       to_send = len_left;
-               ret = copy_from_user(buf, tmp_p, to_send);
-               /*
-                * There is no reason for this copy to be short. We just
-                * copied them here, and the mm hasn't been exposed to user-
-                * space yet.
-                */
-               if (ret) {
-                       WARN_ON(1);
-                       send_sig(SIGKILL, current, 0);
-                       return -1;
-               }
-               buf[to_send] = '\0';
-               has_cntl = audit_string_contains_control(buf, to_send);
-               if (has_cntl) {
-                       /*
-                        * hex messages get logged as 2 bytes, so we can only
-                        * send half as much in each message
-                        */
-                       max_execve_audit_len = MAX_EXECVE_AUDIT_LEN / 2;
-                       break;
-               }
-               len_left -= to_send;
-               tmp_p += to_send;
-       } while (len_left > 0);
-
-       len_left = len;
-
-       if (len > max_execve_audit_len)
-               too_long = 1;
-
-       /* rewalk the argument actually logging the message */
-       for (i = 0; len_left > 0; i++) {
-               int room_left;
-
-               if (len_left > max_execve_audit_len)
-                       to_send = max_execve_audit_len;
-               else
-                       to_send = len_left;
-
-               /* do we have space left to send this argument in this ab? */
-               room_left = MAX_EXECVE_AUDIT_LEN - arg_num_len - *len_sent;
-               if (has_cntl)
-                       room_left -= (to_send * 2);
-               else
-                       room_left -= to_send;
-               if (room_left < 0) {
-                       *len_sent = 0;
-                       audit_log_end(*ab);
-                       *ab = audit_log_start(context, GFP_KERNEL, AUDIT_EXECVE);
-                       if (!*ab)
-                               return 0;
-               }
+               /* NOTE: we don't ever want to trust this value for anything
+                *       serious, but the audit record format insists we
+                *       provide an argument length for really long arguments,
+                *       e.g. > MAX_EXECVE_AUDIT_LEN, so we have no choice but
+                *       to use strncpy_from_user() to obtain this value for
+                *       recording in the log, although we don't use it
+                *       anywhere here to avoid a double-fetch problem */
+               if (len_full == 0)
+                       len_full = strnlen_user(p, MAX_ARG_STRLEN) - 1;
+
+               /* read more data from userspace */
+               if (require_data) {
+                       /* can we make more room in the buffer? */
+                       if (buf != buf_head) {
+                               memmove(buf_head, buf, len_buf);
+                               buf = buf_head;
+                       }
 
-               /*
-                * first record needs to say how long the original string was
-                * so we can be sure nothing was lost.
-                */
-               if ((i == 0) && (too_long))
-                       audit_log_format(*ab, " a%d_len=%zu", arg_num,
-                                        has_cntl ? 2*len : len);
-
-               /*
-                * normally arguments are small enough to fit and we already
-                * filled buf above when we checked for control characters
-                * so don't bother with another copy_from_user
-                */
-               if (len >= max_execve_audit_len)
-                       ret = copy_from_user(buf, p, to_send);
-               else
-                       ret = 0;
-               if (ret) {
-                       WARN_ON(1);
-                       send_sig(SIGKILL, current, 0);
-                       return -1;
-               }
-               buf[to_send] = '\0';
-
-               /* actually log it */
-               audit_log_format(*ab, " a%d", arg_num);
-               if (too_long)
-                       audit_log_format(*ab, "[%d]", i);
-               audit_log_format(*ab, "=");
-               if (has_cntl)
-                       audit_log_n_hex(*ab, buf, to_send);
-               else
-                       audit_log_string(*ab, buf);
-
-               p += to_send;
-               len_left -= to_send;
-               *len_sent += arg_num_len;
-               if (has_cntl)
-                       *len_sent += to_send * 2;
-               else
-                       *len_sent += to_send;
-       }
-       /* include the null we didn't log */
-       return len + 1;
-}
+                       /* fetch as much as we can of the argument */
+                       len_tmp = strncpy_from_user(&buf_head[len_buf], p,
+                                                   len_max - len_buf);
+                       if (len_tmp == -EFAULT) {
+                               /* unable to copy from userspace */
+                               send_sig(SIGKILL, current, 0);
+                               goto out;
+                       } else if (len_tmp == (len_max - len_buf)) {
+                               /* buffer is not large enough */
+                               require_data = true;
+                               /* NOTE: if we are going to span multiple
+                                *       buffers force the encoding so we stand
+                                *       a chance at a sane len_full value and
+                                *       consistent record encoding */
+                               encode = true;
+                               len_full = len_full * 2;
+                               p += len_tmp;
+                       } else {
+                               require_data = false;
+                               if (!encode)
+                                       encode = audit_string_contains_control(
+                                                               buf, len_tmp);
+                               /* try to use a trusted value for len_full */
+                               if (len_full < len_max)
+                                       len_full = (encode ?
+                                                   len_tmp * 2 : len_tmp);
+                               p += len_tmp + 1;
+                       }
+                       len_buf += len_tmp;
+                       buf_head[len_buf] = '\0';
 
-static void audit_log_execve_info(struct audit_context *context,
-                                 struct audit_buffer **ab,
-                                 struct audit_aux_data_execve *axi)
-{
-       int i, len;
-       size_t len_sent = 0;
-       const char __user *p;
-       char *buf;
+                       /* length of the buffer in the audit record? */
+                       len_abuf = (encode ? len_buf * 2 : len_buf + 2);
 
-       if (axi->mm != current->mm)
-               return; /* execve failed, no additional info */
+               }
+
+               /* write as much as we can to the audit log */
+               if (len_buf > 0) {
+                       /* NOTE: some magic numbers here - basically if we
+                        *       can't fit a reasonable amount of data into the
+                        *       existing audit buffer, flush it and start with
+                        *       a new buffer */
+                       if ((sizeof(abuf) + 8) > len_rem) {
+                               len_rem = len_max;
+                               audit_log_end(*ab);
+                               *ab = audit_log_start(context,
+                                                     GFP_KERNEL, AUDIT_EXECVE);
+                               if (!*ab)
+                                       goto out;
+                       }
 
-       p = (const char __user *)axi->mm->arg_start;
+                       /* create the non-arg portion of the arg record */
+                       len_tmp = 0;
+                       if (require_data || (iter > 0) ||
+                           ((len_abuf + sizeof(abuf)) > len_rem)) {
+                               if (iter == 0) {
+                                       len_tmp += snprintf(&abuf[len_tmp],
+                                                       sizeof(abuf) - len_tmp,
+                                                       " a%d_len=%lu",
+                                                       arg, len_full);
+                               }
+                               len_tmp += snprintf(&abuf[len_tmp],
+                                                   sizeof(abuf) - len_tmp,
+                                                   " a%d[%d]=", arg, iter++);
+                       } else
+                               len_tmp += snprintf(&abuf[len_tmp],
+                                                   sizeof(abuf) - len_tmp,
+                                                   " a%d=", arg);
+                       WARN_ON(len_tmp >= sizeof(abuf));
+                       abuf[sizeof(abuf) - 1] = '\0';
+
+                       /* log the arg in the audit record */
+                       audit_log_format(*ab, "%s", abuf);
+                       len_rem -= len_tmp;
+                       len_tmp = len_buf;
+                       if (encode) {
+                               if (len_abuf > len_rem)
+                                       len_tmp = len_rem / 2; /* encoding */
+                               audit_log_n_hex(*ab, buf, len_tmp);
+                               len_rem -= len_tmp * 2;
+                               len_abuf -= len_tmp * 2;
+                       } else {
+                               if (len_abuf > len_rem)
+                                       len_tmp = len_rem - 2; /* quotes */
+                               audit_log_n_string(*ab, buf, len_tmp);
+                               len_rem -= len_tmp + 2;
+                               /* don't subtract the "2" because we still need
+                                * to add quotes to the remaining string */
+                               len_abuf -= len_tmp;
+                       }
+                       len_buf -= len_tmp;
+                       buf += len_tmp;
+               }
 
-       audit_log_format(*ab, "argc=%d", axi->argc);
+               /* ready to move to the next argument? */
+               if ((len_buf == 0) && !require_data) {
+                       arg++;
+                       iter = 0;
+                       len_full = 0;
+                       require_data = true;
+                       encode = false;
+               }
+       } while (arg < context->execve.argc);
 
-       /*
-        * we need some kernel buffer to hold the userspace args.  Just
-        * allocate one big one rather than allocating one of the right size
-        * for every single argument inside audit_log_single_execve_arg()
-        * should be <8k allocation so should be pretty safe.
-        */
-       buf = kmalloc(MAX_EXECVE_AUDIT_LEN + 1, GFP_KERNEL);
-       if (!buf) {
-               audit_panic("out of memory for argv string\n");
-               return;
-       }
+       /* NOTE: the caller handles the final audit_log_end() call */
 
-       for (i = 0; i < axi->argc; i++) {
-               len = audit_log_single_execve_arg(context, ab, i,
-                                                 &len_sent, p, buf);
-               if (len <= 0)
-                       break;
-               p += len;
-       }
-       kfree(buf);
+out:
+       kfree(buf_head);
 }
 
 static void show_special(struct audit_context *context, int *call_panic)
@@ -1335,8 +1327,7 @@ static void audit_log_exit(struct audit_context *context, struct task_struct *ts
                switch (aux->type) {
 
                case AUDIT_EXECVE: {
-                       struct audit_aux_data_execve *axi = (void *)aux;
-                       audit_log_execve_info(context, &ab, axi);
+                       audit_log_execve_info(context, &ab);
                        break; }
 
                case AUDIT_BPRM_FCAPS: {
index 459b94c9472140e1ea2160f070594887d2de60f2..05b402ee5884043249cde2e710c6000641e7c73e 100644 (file)
@@ -1236,10 +1236,17 @@ static void perf_group_detach(struct perf_event *event)
         * If this was a group event with sibling events then
         * upgrade the siblings to singleton events by adding them
         * to whatever list we are on.
+        * If this isn't on a list, make sure we still remove the sibling's
+        * group_entry from this sibling_list; otherwise, when that sibling
+        * is later deallocated, it will try to remove itself from this
+        * sibling_list, which may well have been deallocated already,
+        * resulting in a use-after-free.
         */
        list_for_each_entry_safe(sibling, tmp, &event->sibling_list, group_entry) {
                if (list)
                        list_move_tail(&sibling->group_entry, list);
+               else
+                       list_del_init(&sibling->group_entry);
                sibling->group_leader = sibling;
 
                /* Inherit group flags from the previous leader */
@@ -5139,9 +5146,6 @@ struct swevent_htable {
 
        /* Recursion avoidance in each contexts */
        int                             recursion[PERF_NR_CONTEXTS];
-
-       /* Keeps track of cpu being initialized/exited */
-       bool                            online;
 };
 
 static DEFINE_PER_CPU(struct swevent_htable, swevent_htable);
@@ -5388,14 +5392,8 @@ static int perf_swevent_add(struct perf_event *event, int flags)
        hwc->state = !(flags & PERF_EF_START);
 
        head = find_swevent_head(swhash, event);
-       if (!head) {
-               /*
-                * We can race with cpu hotplug code. Do not
-                * WARN if the cpu just got unplugged.
-                */
-               WARN_ON_ONCE(swhash->online);
+       if (WARN_ON_ONCE(!head))
                return -EINVAL;
-       }
 
        hlist_add_head_rcu(&event->hlist_entry, head);
 
@@ -5467,7 +5465,6 @@ static int swevent_hlist_get_cpu(struct perf_event *event, int cpu)
        int err = 0;
 
        mutex_lock(&swhash->hlist_mutex);
-
        if (!swevent_hlist_deref(swhash) && cpu_online(cpu)) {
                struct swevent_hlist *hlist;
 
@@ -7496,7 +7493,6 @@ static void __cpuinit perf_event_init_cpu(int cpu)
        struct swevent_htable *swhash = &per_cpu(swevent_htable, cpu);
 
        mutex_lock(&swhash->hlist_mutex);
-       swhash->online = true;
        if (swhash->hlist_refcount > 0) {
                struct swevent_hlist *hlist;
 
@@ -7549,14 +7545,7 @@ static void perf_event_exit_cpu_context(int cpu)
 
 static void perf_event_exit_cpu(int cpu)
 {
-       struct swevent_htable *swhash = &per_cpu(swevent_htable, cpu);
-
        perf_event_exit_cpu_context(cpu);
-
-       mutex_lock(&swhash->hlist_mutex);
-       swhash->online = false;
-       swevent_hlist_release(swhash);
-       mutex_unlock(&swhash->hlist_mutex);
 }
 #else
 static inline void perf_event_exit_cpu(int cpu) { }
index d7386986e10e31edda59fcb15c4b83b236d52993..ffda5adb71c5c05cd877a4d1c631157edfad1d40 100644 (file)
@@ -153,7 +153,7 @@ static const struct file_operations proc_iomem_operations = {
 static int __init ioresources_init(void)
 {
        proc_create("ioports", 0, NULL, &proc_ioports_operations);
-       proc_create("iomem", 0, NULL, &proc_iomem_operations);
+       proc_create("iomem", S_IRUSR, NULL, &proc_iomem_operations);
        return 0;
 }
 __initcall(ioresources_init);
index 11b9b01fda6b67303db4a7df22c19e2c35c4c095..b1c885297113f7d42a6f300f396dd77b2543e6e9 100644 (file)
@@ -69,7 +69,7 @@ next_tag:
 
        /* Extract a tag from the data */
        tag = data[dp++];
-       if (tag == 0) {
+       if (tag == ASN1_EOC) {
                /* It appears to be an EOC. */
                if (data[dp++] != 0)
                        goto invalid_eoc;
@@ -91,10 +91,8 @@ next_tag:
 
        /* Extract the length */
        len = data[dp++];
-       if (len <= 0x7f) {
-               dp += len;
-               goto next_tag;
-       }
+       if (len <= 0x7f)
+               goto check_length;
 
        if (unlikely(len == ASN1_INDEFINITE_LENGTH)) {
                /* Indefinite length */
@@ -105,14 +103,18 @@ next_tag:
        }
 
        n = len - 0x80;
-       if (unlikely(n > sizeof(size_t) - 1))
+       if (unlikely(n > sizeof(len) - 1))
                goto length_too_long;
        if (unlikely(n > datalen - dp))
                goto data_overrun_error;
-       for (len = 0; n > 0; n--) {
+       len = 0;
+       for (; n > 0; n--) {
                len <<= 8;
                len |= data[dp++];
        }
+check_length:
+       if (len > datalen - dp)
+               goto data_overrun_error;
        dp += len;
        goto next_tag;
 
@@ -208,9 +210,8 @@ next_op:
                unsigned char tmp;
 
                /* Skip conditional matches if possible */
-               if ((op & ASN1_OP_MATCH__COND &&
-                    flags & FLAG_MATCHED) ||
-                   dp == datalen) {
+               if ((op & ASN1_OP_MATCH__COND && flags & FLAG_MATCHED) ||
+                   (op & ASN1_OP_MATCH__SKIP && dp == datalen)) {
                        pc += asn1_op_lengths[op];
                        goto next_op;
                }
index 12df1500c4c153ea84f9f424484ca416018a3710..4cafab7d55d033f2da89313474fd3bcc6850cf15 100644 (file)
@@ -1467,6 +1467,16 @@ int zap_vma_ptes(struct vm_area_struct *vma, unsigned long address,
 }
 EXPORT_SYMBOL_GPL(zap_vma_ptes);
 
+/*
+ * FOLL_FORCE can write to even unwritable pte's, but only
+ * after we've gone through a COW cycle and they are dirty.
+ */
+static inline bool can_follow_write_pte(pte_t pte, unsigned int flags)
+{
+       return pte_write(pte) ||
+               ((flags & FOLL_FORCE) && (flags & FOLL_COW) && pte_dirty(pte));
+}
+
 /**
  * follow_page_mask - look up a page descriptor from a user-virtual address
  * @vma: vm_area_struct mapping @address
@@ -1574,7 +1584,7 @@ split_fallthrough:
        }
        if ((flags & FOLL_NUMA) && pte_numa(pte))
                goto no_page;
-       if ((flags & FOLL_WRITE) && !pte_write(pte))
+       if ((flags & FOLL_WRITE) && !can_follow_write_pte(pte, flags))
                goto unlock;
 
        page = vm_normal_page(vma, address, pte);
@@ -1895,7 +1905,7 @@ long __get_user_pages(struct task_struct *tsk, struct mm_struct *mm,
                                 */
                                if ((ret & VM_FAULT_WRITE) &&
                                    !(vma->vm_flags & VM_WRITE))
-                                       foll_flags &= ~FOLL_WRITE;
+                                       foll_flags |= FOLL_COW;
 
                                cond_resched();
                        }
@@ -3254,6 +3264,10 @@ static int do_anonymous_page(struct mm_struct *mm, struct vm_area_struct *vma,
 
        pte_unmap(page_table);
 
+       /* File mapping without ->vm_ops ? */
+       if (vma->vm_flags & VM_SHARED)
+               return VM_FAULT_SIGBUS;
+
        /* Check if we need to add a guard page to the stack */
        if (check_stack_guard_page(vma, address) < 0)
                return VM_FAULT_SIGBUS;
@@ -3518,6 +3532,10 @@ static int do_linear_fault(struct mm_struct *mm, struct vm_area_struct *vma,
        pgoff_t pgoff = (((address & PAGE_MASK)
                        - vma->vm_start) >> PAGE_SHIFT) + vma->vm_pgoff;
 
+       /* The VMA was not fully populated on mmap() or missing VM_DONTEXPAND */
+       if (!vma->vm_ops->fault)
+               return VM_FAULT_SIGBUS;
+
        pte_unmap(page_table);
        return __do_fault(mm, vma, address, pmd, pgoff, flags, orig_pte);
 }
@@ -3731,9 +3749,8 @@ int handle_pte_fault(struct mm_struct *mm,
        if (!pte_present(entry)) {
                if (pte_none(entry)) {
                        if (vma->vm_ops) {
-                               if (likely(vma->vm_ops->fault))
-                                       return do_linear_fault(mm, vma, address,
-                                               pte, pmd, flags, entry);
+                               return do_linear_fault(mm, vma, address,
+                                       pte, pmd, flags, entry);
                        }
                        return do_anonymous_page(mm, vma, address,
                                                 pte, pmd, flags);
index ce91766eeca90efc1a64b39997b0990b339b16cb..900a05fd90d2e39338dcdcecab5c28cf01d48107 100644 (file)
@@ -711,11 +711,13 @@ static int ethtool_reset(struct net_device *dev, char __user *useraddr)
 
 static int ethtool_get_wol(struct net_device *dev, char __user *useraddr)
 {
-       struct ethtool_wolinfo wol = { .cmd = ETHTOOL_GWOL };
+       struct ethtool_wolinfo wol;
 
        if (!dev->ethtool_ops->get_wol)
                return -EOPNOTSUPP;
 
+       memset(&wol, 0, sizeof(struct ethtool_wolinfo));
+       wol.cmd = ETHTOOL_GWOL;
        dev->ethtool_ops->get_wol(dev, &wol);
 
        if (copy_to_user(useraddr, &wol, sizeof(wol)))
index d19cf53dff1651fae5faf063a8520bae7cb73cce..8471951938623f553a86047048b548bc2fdacf79 100644 (file)
@@ -731,7 +731,7 @@ int sock_setsockopt(struct socket *sock, int level, int optname,
                val = min_t(u32, val, sysctl_wmem_max);
 set_sndbuf:
                sk->sk_userlocks |= SOCK_SNDBUF_LOCK;
-               sk->sk_sndbuf = max_t(u32, val * 2, SOCK_MIN_SNDBUF);
+               sk->sk_sndbuf = max_t(int, val * 2, SOCK_MIN_SNDBUF);
                /* Wake up sending tasks if we upped the value. */
                sk->sk_write_space(sk);
                break;
@@ -767,7 +767,7 @@ set_rcvbuf:
                 * returning the value we actually used in getsockopt
                 * is the most desirable behavior.
                 */
-               sk->sk_rcvbuf = max_t(u32, val * 2, SOCK_MIN_RCVBUF);
+               sk->sk_rcvbuf = max_t(int, val * 2, SOCK_MIN_RCVBUF);
                break;
 
        case SO_RCVBUFFORCE:
index 14cdafad7a90218d91ad135e3703c21401883e05..e511ccc74a0782fa26b8aa9a98de23931485c601 100644 (file)
@@ -606,7 +606,8 @@ int dccp_rcv_state_process(struct sock *sk, struct sk_buff *skb,
                        if (inet_csk(sk)->icsk_af_ops->conn_request(sk,
                                                                    skb) < 0)
                                return 1;
-                       goto discard;
+                       consume_skb(skb);
+                       return 0;
                }
                if (dh->dccph_type == DCCP_PKT_RESET)
                        goto discard;
index 23e6ab0a2dc0ea070b6a86548b7761f7dbda00d4..1c688f7403f709f35b8b96e9393d34c9df51eaa5 100644 (file)
@@ -1046,6 +1046,13 @@ void ipv4_pktinfo_prepare(struct sk_buff *skb)
                pktinfo->ipi_ifindex = 0;
                pktinfo->ipi_spec_dst.s_addr = 0;
        }
+       /* We need to keep the dst for __ip_options_echo()
+        * We could restrict the test to opt.ts_needtime || opt.srr,
+        * but the following is good enough as IP options are not often used.
+        */
+       if (unlikely(IPCB(skb)->opt.optlen))
+               skb_dst_force(skb);
+       else
        skb_dst_drop(skb);
 }
 
index c8abe31961eda38c087a0057c53d678998ecc09a..e4717743316e39f88aeac5f32a97bae61b0e3439 100644 (file)
@@ -350,11 +350,12 @@ unsigned int arpt_do_table(struct sk_buff *skb,
 }
 
 /* All zeroes == unconditional rule. */
-static inline bool unconditional(const struct arpt_arp *arp)
+static inline bool unconditional(const struct arpt_entry *e)
 {
        static const struct arpt_arp uncond;
 
-       return memcmp(arp, &uncond, sizeof(uncond)) == 0;
+       return e->target_offset == sizeof(struct arpt_entry) &&
+               memcmp(&e->arp, &uncond, sizeof(uncond)) == 0;
 }
 
 /* Figures out from what hook each rule can be called: returns 0 if
@@ -393,11 +394,10 @@ static int mark_source_chains(const struct xt_table_info *newinfo,
                                |= ((1 << hook) | (1 << NF_ARP_NUMHOOKS));
 
                        /* Unconditional return/END. */
-                       if ((e->target_offset == sizeof(struct arpt_entry) &&
+                       if ((unconditional(e) &&
                             (strcmp(t->target.u.user.name,
                                     XT_STANDARD_TARGET) == 0) &&
-                            t->verdict < 0 && unconditional(&e->arp)) ||
-                           visited) {
+                            t->verdict < 0) || visited) {
                                unsigned int oldpos, size;
 
                                if ((strcmp(t->target.u.user.name,
@@ -465,14 +465,12 @@ static int mark_source_chains(const struct xt_table_info *newinfo,
        return 1;
 }
 
-static inline int check_entry(const struct arpt_entry *e, const char *name)
+static inline int check_entry(const struct arpt_entry *e)
 {
        const struct xt_entry_target *t;
 
-       if (!arp_checkentry(&e->arp)) {
-               duprintf("arp_tables: arp check failed %p %s.\n", e, name);
+       if (!arp_checkentry(&e->arp))
                return -EINVAL;
-       }
 
        if (e->target_offset + sizeof(struct xt_entry_target) > e->next_offset)
                return -EINVAL;
@@ -484,6 +482,7 @@ static inline int check_entry(const struct arpt_entry *e, const char *name)
        return 0;
 }
 
+
 static inline int check_target(struct arpt_entry *e, const char *name)
 {
        struct xt_entry_target *t = arpt_get_target(e);
@@ -513,10 +512,6 @@ find_check_entry(struct arpt_entry *e, const char *name, unsigned int size)
        struct xt_target *target;
        int ret;
 
-       ret = check_entry(e, name);
-       if (ret)
-               return ret;
-
        t = arpt_get_target(e);
        target = xt_request_find_target(NFPROTO_ARP, t->u.user.name,
                                        t->u.user.revision);
@@ -542,7 +537,7 @@ static bool check_underflow(const struct arpt_entry *e)
        const struct xt_entry_target *t;
        unsigned int verdict;
 
-       if (!unconditional(&e->arp))
+       if (!unconditional(e))
                return false;
        t = arpt_get_target_c(e);
        if (strcmp(t->u.user.name, XT_STANDARD_TARGET) != 0)
@@ -561,9 +556,11 @@ static inline int check_entry_size_and_hooks(struct arpt_entry *e,
                                             unsigned int valid_hooks)
 {
        unsigned int h;
+       int err;
 
        if ((unsigned long)e % __alignof__(struct arpt_entry) != 0 ||
-           (unsigned char *)e + sizeof(struct arpt_entry) >= limit) {
+           (unsigned char *)e + sizeof(struct arpt_entry) >= limit ||
+           (unsigned char *)e + e->next_offset > limit) {
                duprintf("Bad offset %p\n", e);
                return -EINVAL;
        }
@@ -575,6 +572,10 @@ static inline int check_entry_size_and_hooks(struct arpt_entry *e,
                return -EINVAL;
        }
 
+       err = check_entry(e);
+       if (err)
+               return err;
+
        /* Check hooks & underflows */
        for (h = 0; h < NF_ARP_NUMHOOKS; h++) {
                if (!(valid_hooks & (1 << h)))
@@ -1219,7 +1220,8 @@ check_compat_entry_size_and_hooks(struct compat_arpt_entry *e,
 
        duprintf("check_compat_entry_size_and_hooks %p\n", e);
        if ((unsigned long)e % __alignof__(struct compat_arpt_entry) != 0 ||
-           (unsigned char *)e + sizeof(struct compat_arpt_entry) >= limit) {
+           (unsigned char *)e + sizeof(struct compat_arpt_entry) >= limit ||
+           (unsigned char *)e + e->next_offset > limit) {
                duprintf("Bad offset %p, limit = %p\n", e, limit);
                return -EINVAL;
        }
@@ -1232,7 +1234,7 @@ check_compat_entry_size_and_hooks(struct compat_arpt_entry *e,
        }
 
        /* For purposes of check_entry casting the compat entry is fine */
-       ret = check_entry((struct arpt_entry *)e, name);
+       ret = check_entry((struct arpt_entry *)e);
        if (ret)
                return ret;
 
index 651c10774d588c2484d4e140f79fb30d29d7b4df..e6cd22262ed18fe77920c1bdbdfbf346db9d8656 100644 (file)
@@ -168,11 +168,12 @@ get_entry(const void *base, unsigned int offset)
 
 /* All zeroes == unconditional rule. */
 /* Mildly perf critical (only if packet tracing is on) */
-static inline bool unconditional(const struct ipt_ip *ip)
+static inline bool unconditional(const struct ipt_entry *e)
 {
        static const struct ipt_ip uncond;
 
-       return memcmp(ip, &uncond, sizeof(uncond)) == 0;
+       return e->target_offset == sizeof(struct ipt_entry) &&
+               memcmp(&e->ip, &uncond, sizeof(uncond)) == 0;
 #undef FWINV
 }
 
@@ -229,11 +230,10 @@ get_chainname_rulenum(const struct ipt_entry *s, const struct ipt_entry *e,
        } else if (s == e) {
                (*rulenum)++;
 
-               if (s->target_offset == sizeof(struct ipt_entry) &&
+               if (unconditional(s) &&
                    strcmp(t->target.u.kernel.target->name,
                           XT_STANDARD_TARGET) == 0 &&
-                  t->verdict < 0 &&
-                  unconditional(&s->ip)) {
+                  t->verdict < 0) {
                        /* Tail of chains: STANDARD target (return/policy) */
                        *comment = *chainname == hookname
                                ? comments[NF_IP_TRACE_COMMENT_POLICY]
@@ -467,11 +467,10 @@ mark_source_chains(const struct xt_table_info *newinfo,
                        e->comefrom |= ((1 << hook) | (1 << NF_INET_NUMHOOKS));
 
                        /* Unconditional return/END. */
-                       if ((e->target_offset == sizeof(struct ipt_entry) &&
+                       if ((unconditional(e) &&
                             (strcmp(t->target.u.user.name,
                                     XT_STANDARD_TARGET) == 0) &&
-                            t->verdict < 0 && unconditional(&e->ip)) ||
-                           visited) {
+                            t->verdict < 0) || visited) {
                                unsigned int oldpos, size;
 
                                if ((strcmp(t->target.u.user.name,
@@ -560,14 +559,12 @@ static void cleanup_match(struct xt_entry_match *m, struct net *net)
 }
 
 static int
-check_entry(const struct ipt_entry *e, const char *name)
+check_entry(const struct ipt_entry *e)
 {
        const struct xt_entry_target *t;
 
-       if (!ip_checkentry(&e->ip)) {
-               duprintf("ip check failed %p %s.\n", e, name);
+       if (!ip_checkentry(&e->ip))
                return -EINVAL;
-       }
 
        if (e->target_offset + sizeof(struct xt_entry_target) >
            e->next_offset)
@@ -580,6 +577,7 @@ check_entry(const struct ipt_entry *e, const char *name)
        return 0;
 }
 
+
 static int
 check_match(struct xt_entry_match *m, struct xt_mtchk_param *par)
 {
@@ -657,10 +655,6 @@ find_check_entry(struct ipt_entry *e, struct net *net, const char *name,
        struct xt_mtchk_param mtpar;
        struct xt_entry_match *ematch;
 
-       ret = check_entry(e, name);
-       if (ret)
-               return ret;
-
        j = 0;
        mtpar.net       = net;
        mtpar.table     = name;
@@ -704,7 +698,7 @@ static bool check_underflow(const struct ipt_entry *e)
        const struct xt_entry_target *t;
        unsigned int verdict;
 
-       if (!unconditional(&e->ip))
+       if (!unconditional(e))
                return false;
        t = ipt_get_target_c(e);
        if (strcmp(t->u.user.name, XT_STANDARD_TARGET) != 0)
@@ -724,9 +718,11 @@ check_entry_size_and_hooks(struct ipt_entry *e,
                           unsigned int valid_hooks)
 {
        unsigned int h;
+       int err;
 
        if ((unsigned long)e % __alignof__(struct ipt_entry) != 0 ||
-           (unsigned char *)e + sizeof(struct ipt_entry) >= limit) {
+           (unsigned char *)e + sizeof(struct ipt_entry) >= limit ||
+           (unsigned char *)e + e->next_offset > limit) {
                duprintf("Bad offset %p\n", e);
                return -EINVAL;
        }
@@ -738,6 +734,10 @@ check_entry_size_and_hooks(struct ipt_entry *e,
                return -EINVAL;
        }
 
+       err = check_entry(e);
+       if (err)
+               return err;
+
        /* Check hooks & underflows */
        for (h = 0; h < NF_INET_NUMHOOKS; h++) {
                if (!(valid_hooks & (1 << h)))
@@ -1485,7 +1485,8 @@ check_compat_entry_size_and_hooks(struct compat_ipt_entry *e,
 
        duprintf("check_compat_entry_size_and_hooks %p\n", e);
        if ((unsigned long)e % __alignof__(struct compat_ipt_entry) != 0 ||
-           (unsigned char *)e + sizeof(struct compat_ipt_entry) >= limit) {
+           (unsigned char *)e + sizeof(struct compat_ipt_entry) >= limit ||
+           (unsigned char *)e + e->next_offset > limit) {
                duprintf("Bad offset %p, limit = %p\n", e, limit);
                return -EINVAL;
        }
@@ -1498,7 +1499,7 @@ check_compat_entry_size_and_hooks(struct compat_ipt_entry *e,
        }
 
        /* For purposes of check_entry casting the compat entry is fine */
-       ret = check_entry((struct ipt_entry *)e, name);
+       ret = check_entry((struct ipt_entry *)e);
        if (ret)
                return ret;
 
index 79d11850ef2f300e33636621e263e7b0f3790ef4..01189884976e94640b29139a9471bf9680f5f0d7 100644 (file)
@@ -154,6 +154,7 @@ void ping_unhash(struct sock *sk)
        if (sk_hashed(sk)) {
                write_lock_bh(&ping_table.lock);
                hlist_nulls_del(&sk->sk_nulls_node);
+               sk_nulls_node_init(&sk->sk_nulls_node);
                sock_put(sk);
                isk->inet_num = 0;
                isk->inet_sport = 0;
@@ -639,7 +640,7 @@ int ping_common_sendmsg(int family, struct msghdr *msg, size_t len,
                        void *user_icmph, size_t icmph_len) {
        u8 type, code;
 
-       if (len > 0xFFFF)
+       if (len > 0xFFFF || len < icmph_len)
                return -EMSGSIZE;
 
        /*
index 0d94fd91d988a377635d477d14db3e1a0bd2cdf4..f9dff6427a0be7af2c8be24d90bc7cfc311693e8 100644 (file)
@@ -68,6 +68,7 @@
 #include <linux/module.h>
 #include <linux/sysctl.h>
 #include <linux/kernel.h>
+#include <linux/reciprocal_div.h>
 #include <net/dst.h>
 #include <net/tcp.h>
 #include <net/inet_common.h>
@@ -87,7 +88,7 @@ int sysctl_tcp_adv_win_scale __read_mostly = 1;
 EXPORT_SYMBOL(sysctl_tcp_adv_win_scale);
 
 /* rfc5961 challenge ack rate limiting */
-int sysctl_tcp_challenge_ack_limit = 100;
+int sysctl_tcp_challenge_ack_limit = 1000;
 
 int sysctl_tcp_stdurg __read_mostly;
 int sysctl_tcp_rfc1337 __read_mostly;
@@ -3322,12 +3323,19 @@ static void tcp_send_challenge_ack(struct sock *sk)
        static u32 challenge_timestamp;
        static unsigned int challenge_count;
        u32 now = jiffies / HZ;
+       u32 count;
 
        if (now != challenge_timestamp) {
+               u32 half = (sysctl_tcp_challenge_ack_limit + 1) >> 1;
+
                challenge_timestamp = now;
-               challenge_count = 0;
+               ACCESS_ONCE(challenge_count) = half +
+                                       reciprocal_divide(prandom_u32(),
+                                                       sysctl_tcp_challenge_ack_limit);
        }
-       if (++challenge_count <= sysctl_tcp_challenge_ack_limit) {
+       count = ACCESS_ONCE(challenge_count);
+       if (count > 0) {
+               ACCESS_ONCE(challenge_count) = count - 1;
                NET_INC_STATS_BH(sock_net(sk), LINUX_MIB_TCPCHALLENGEACK);
                tcp_send_ack(sk);
        }
index dee369889093ebbb0b1ad7b799d52c14a814f2e7..68a1a9617e99117d01cf7b4a0b8c20fdfbed30f8 100644 (file)
@@ -1249,6 +1249,7 @@ int udp_recvmsg(struct kiocb *iocb, struct sock *sk, struct msghdr *msg,
        int peeked, off = 0;
        int err;
        int is_udplite = IS_UDPLITE(sk);
+       bool checksum_valid = false;
        bool slow;
 
        if (flags & MSG_ERRQUEUE)
@@ -1274,11 +1275,12 @@ try_again:
         */
 
        if (copied < ulen || UDP_SKB_CB(skb)->partial_cov) {
-               if (udp_lib_checksum_complete(skb))
+               checksum_valid = !udp_lib_checksum_complete(skb);
+               if (!checksum_valid)
                        goto csum_copy_err;
        }
 
-       if (skb_csum_unnecessary(skb))
+       if (checksum_valid || skb_csum_unnecessary(skb))
                err = skb_copy_datagram_iovec(skb, sizeof(struct udphdr),
                                              msg->msg_iov, copied);
        else {
@@ -1334,10 +1336,8 @@ csum_copy_err:
        }
        unlock_sock_fast(sk, slow);
 
-       if (noblock)
-               return -EAGAIN;
-
-       /* starting over for a new packet */
+       /* starting over for a new packet, but check if we need to yield */
+       cond_resched();
        msg->msg_flags &= ~MSG_TRUNC;
        goto try_again;
 }
index 5aab1acc3d2a163d5760d4c90b22e4556a769c8d..d1bc9987b8dc2c7e1647aa71e9173a110c041ed7 100644 (file)
@@ -1193,7 +1193,13 @@ static void ndisc_router_discovery(struct sk_buff *skb)
        if (rt)
                rt6_set_expires(rt, jiffies + (HZ * lifetime));
        if (ra_msg->icmph.icmp6_hop_limit) {
-               in6_dev->cnf.hop_limit = ra_msg->icmph.icmp6_hop_limit;
+               /* Only set hop_limit on the interface if it is higher than
+                * the current hop_limit.
+                */
+               if (in6_dev->cnf.hop_limit < ra_msg->icmph.icmp6_hop_limit)
+                       in6_dev->cnf.hop_limit = ra_msg->icmph.icmp6_hop_limit;
+               else
+                       ND_PRINTK(2, warn, "RA: Got route advertisement with lower hop_limit than current\n");
                if (rt)
                        dst_metric_set(&rt->dst, RTAX_HOPLIMIT,
                                       ra_msg->icmph.icmp6_hop_limit);
index 89a4e4ddd8bbeede5ee4d0a610652779e9684394..2b3c29b2c5a3b878bbfe5100ef67938945a68ea5 100644 (file)
@@ -195,13 +195,15 @@ get_entry(const void *base, unsigned int offset)
 
 /* All zeroes == unconditional rule. */
 /* Mildly perf critical (only if packet tracing is on) */
-static inline bool unconditional(const struct ip6t_ip6 *ipv6)
+static inline bool unconditional(const struct ip6t_entry *e)
 {
        static const struct ip6t_ip6 uncond;
 
-       return memcmp(ipv6, &uncond, sizeof(uncond)) == 0;
+       return e->target_offset == sizeof(struct ip6t_entry) &&
+               memcmp(&e->ipv6, &uncond, sizeof(uncond)) == 0;
 }
 
+
 static inline const struct xt_entry_target *
 ip6t_get_target_c(const struct ip6t_entry *e)
 {
@@ -255,11 +257,10 @@ get_chainname_rulenum(const struct ip6t_entry *s, const struct ip6t_entry *e,
        } else if (s == e) {
                (*rulenum)++;
 
-               if (s->target_offset == sizeof(struct ip6t_entry) &&
+               if (unconditional(s) &&
                    strcmp(t->target.u.kernel.target->name,
                           XT_STANDARD_TARGET) == 0 &&
-                   t->verdict < 0 &&
-                   unconditional(&s->ipv6)) {
+                   t->verdict < 0) {
                        /* Tail of chains: STANDARD target (return/policy) */
                        *comment = *chainname == hookname
                                ? comments[NF_IP6_TRACE_COMMENT_POLICY]
@@ -477,11 +478,10 @@ mark_source_chains(const struct xt_table_info *newinfo,
                        e->comefrom |= ((1 << hook) | (1 << NF_INET_NUMHOOKS));
 
                        /* Unconditional return/END. */
-                       if ((e->target_offset == sizeof(struct ip6t_entry) &&
+                       if ((unconditional(e) &&
                             (strcmp(t->target.u.user.name,
                                     XT_STANDARD_TARGET) == 0) &&
-                            t->verdict < 0 &&
-                            unconditional(&e->ipv6)) || visited) {
+                            t->verdict < 0) || visited) {
                                unsigned int oldpos, size;
 
                                if ((strcmp(t->target.u.user.name,
@@ -570,14 +570,12 @@ static void cleanup_match(struct xt_entry_match *m, struct net *net)
 }
 
 static int
-check_entry(const struct ip6t_entry *e, const char *name)
+check_entry(const struct ip6t_entry *e)
 {
        const struct xt_entry_target *t;
 
-       if (!ip6_checkentry(&e->ipv6)) {
-               duprintf("ip_tables: ip check failed %p %s.\n", e, name);
+       if (!ip6_checkentry(&e->ipv6))
                return -EINVAL;
-       }
 
        if (e->target_offset + sizeof(struct xt_entry_target) >
            e->next_offset)
@@ -590,6 +588,7 @@ check_entry(const struct ip6t_entry *e, const char *name)
        return 0;
 }
 
+
 static int check_match(struct xt_entry_match *m, struct xt_mtchk_param *par)
 {
        const struct ip6t_ip6 *ipv6 = par->entryinfo;
@@ -668,10 +667,6 @@ find_check_entry(struct ip6t_entry *e, struct net *net, const char *name,
        struct xt_mtchk_param mtpar;
        struct xt_entry_match *ematch;
 
-       ret = check_entry(e, name);
-       if (ret)
-               return ret;
-
        j = 0;
        mtpar.net       = net;
        mtpar.table     = name;
@@ -715,7 +710,7 @@ static bool check_underflow(const struct ip6t_entry *e)
        const struct xt_entry_target *t;
        unsigned int verdict;
 
-       if (!unconditional(&e->ipv6))
+       if (!unconditional(e))
                return false;
        t = ip6t_get_target_c(e);
        if (strcmp(t->u.user.name, XT_STANDARD_TARGET) != 0)
@@ -735,9 +730,11 @@ check_entry_size_and_hooks(struct ip6t_entry *e,
                           unsigned int valid_hooks)
 {
        unsigned int h;
+       int err;
 
        if ((unsigned long)e % __alignof__(struct ip6t_entry) != 0 ||
-           (unsigned char *)e + sizeof(struct ip6t_entry) >= limit) {
+           (unsigned char *)e + sizeof(struct ip6t_entry) >= limit ||
+           (unsigned char *)e + e->next_offset > limit) {
                duprintf("Bad offset %p\n", e);
                return -EINVAL;
        }
@@ -749,6 +746,10 @@ check_entry_size_and_hooks(struct ip6t_entry *e,
                return -EINVAL;
        }
 
+       err = check_entry(e);
+       if (err)
+               return err;
+
        /* Check hooks & underflows */
        for (h = 0; h < NF_INET_NUMHOOKS; h++) {
                if (!(valid_hooks & (1 << h)))
@@ -1497,7 +1498,8 @@ check_compat_entry_size_and_hooks(struct compat_ip6t_entry *e,
 
        duprintf("check_compat_entry_size_and_hooks %p\n", e);
        if ((unsigned long)e % __alignof__(struct compat_ip6t_entry) != 0 ||
-           (unsigned char *)e + sizeof(struct compat_ip6t_entry) >= limit) {
+           (unsigned char *)e + sizeof(struct compat_ip6t_entry) >= limit ||
+           (unsigned char *)e + e->next_offset > limit) {
                duprintf("Bad offset %p, limit = %p\n", e, limit);
                return -EINVAL;
        }
@@ -1510,7 +1512,7 @@ check_compat_entry_size_and_hooks(struct compat_ip6t_entry *e,
        }
 
        /* For purposes of check_entry casting the compat entry is fine */
-       ret = check_entry((struct ip6t_entry *)e, name);
+       ret = check_entry((struct ip6t_entry *)e);
        if (ret)
                return ret;
 
index d84a8c7890c23cf4f9b1bf350a31771842860eac..ed574c5e7a75138b7105ac988c851b76620bddcd 100644 (file)
@@ -370,6 +370,7 @@ int udpv6_recvmsg(struct kiocb *iocb, struct sock *sk,
        int peeked, off = 0;
        int err;
        int is_udplite = IS_UDPLITE(sk);
+       bool checksum_valid = false;
        int is_udp4;
        bool slow;
 
@@ -401,11 +402,12 @@ try_again:
         */
 
        if (copied < ulen || UDP_SKB_CB(skb)->partial_cov) {
-               if (udp_lib_checksum_complete(skb))
+               checksum_valid = !udp_lib_checksum_complete(skb);
+               if (!checksum_valid)
                        goto csum_copy_err;
        }
 
-       if (skb_csum_unnecessary(skb))
+       if (checksum_valid || skb_csum_unnecessary(skb))
                err = skb_copy_datagram_iovec(skb, sizeof(struct udphdr),
                                              msg->msg_iov, copied);
        else {
@@ -494,10 +496,8 @@ csum_copy_err:
        }
        unlock_sock_fast(sk, slow);
 
-       if (noblock)
-               return -EAGAIN;
-
-       /* starting over for a new packet */
+       /* starting over for a new packet, but check if we need to yield */
+       cond_resched();
        msg->msg_flags &= ~MSG_TRUNC;
        goto try_again;
 }
index da1a1cee1a088e39816d565e99975bbc69a392d3..31317f0d6a5a780f209ebc556c59f669f98928c6 100644 (file)
@@ -249,8 +249,6 @@ static int l2tp_ip_bind(struct sock *sk, struct sockaddr *uaddr, int addr_len)
        int ret;
        int chk_addr_ret;
 
-       if (!sock_flag(sk, SOCK_ZAPPED))
-               return -EINVAL;
        if (addr_len < sizeof(struct sockaddr_l2tpip))
                return -EINVAL;
        if (addr->l2tp_family != AF_INET)
@@ -265,6 +263,9 @@ static int l2tp_ip_bind(struct sock *sk, struct sockaddr *uaddr, int addr_len)
        read_unlock_bh(&l2tp_ip_lock);
 
        lock_sock(sk);
+       if (!sock_flag(sk, SOCK_ZAPPED))
+               goto out;
+
        if (sk->sk_state != TCP_CLOSE || addr_len < sizeof(struct sockaddr_l2tpip))
                goto out;
 
index e6e8408c9e3670b2303625e96a1154f34b07ef1b..2ea0fe7e20ccb17ecdeb18a9c093d212a5a676e4 100644 (file)
@@ -264,8 +264,6 @@ static int l2tp_ip6_bind(struct sock *sk, struct sockaddr *uaddr, int addr_len)
        int addr_type;
        int err;
 
-       if (!sock_flag(sk, SOCK_ZAPPED))
-               return -EINVAL;
        if (addr->l2tp_family != AF_INET6)
                return -EINVAL;
        if (addr_len < sizeof(*addr))
@@ -291,6 +289,9 @@ static int l2tp_ip6_bind(struct sock *sk, struct sockaddr *uaddr, int addr_len)
        lock_sock(sk);
 
        err = -EINVAL;
+       if (!sock_flag(sk, SOCK_ZAPPED))
+               goto out_unlock;
+
        if (sk->sk_state != TCP_CLOSE)
                goto out_unlock;
 
index 0283baedcdfb5b48627002607731dabb992e15ae..fae881e8b8ef0e0d3e51a2456712c11ee3b05b02 100644 (file)
@@ -188,7 +188,7 @@ EXPORT_SYMBOL_GPL(nf_ct_invert_tuple);
 static void
 clean_from_lists(struct nf_conn *ct)
 {
-       pr_debug("clean_from_lists(%p)\n", ct);
+       pr_debug("clean_from_lists(%pK)\n", ct);
        hlist_nulls_del_rcu(&ct->tuplehash[IP_CT_DIR_ORIGINAL].hnnode);
        hlist_nulls_del_rcu(&ct->tuplehash[IP_CT_DIR_REPLY].hnnode);
 
@@ -203,7 +203,7 @@ destroy_conntrack(struct nf_conntrack *nfct)
        struct net *net = nf_ct_net(ct);
        struct nf_conntrack_l4proto *l4proto;
 
-       pr_debug("destroy_conntrack(%p)\n", ct);
+       pr_debug("destroy_conntrack(%pK)\n", ct);
        NF_CT_ASSERT(atomic_read(&nfct->use) == 0);
        NF_CT_ASSERT(!timer_pending(&ct->timeout));
 
@@ -234,7 +234,7 @@ destroy_conntrack(struct nf_conntrack *nfct)
        if (ct->master)
                nf_ct_put(ct->master);
 
-       pr_debug("destroy_conntrack: returning ct=%p to slab\n", ct);
+       pr_debug("destroy_conntrack: returning ct=%pK to slab\n", ct);
        nf_conntrack_free(ct);
 }
 
@@ -496,7 +496,7 @@ __nf_conntrack_confirm(struct sk_buff *skb)
        /* No external references means no one else could have
           confirmed us. */
        NF_CT_ASSERT(!nf_ct_is_confirmed(ct));
-       pr_debug("Confirming conntrack %p\n", ct);
+       pr_debug("Confirming conntrack %pK\n", ct);
 
        spin_lock_bh(&nf_conntrack_lock);
 
@@ -823,7 +823,7 @@ init_conntrack(struct net *net, struct nf_conn *tmpl,
        spin_lock_bh(&nf_conntrack_lock);
        exp = nf_ct_find_expectation(net, zone, tuple);
        if (exp) {
-               pr_debug("conntrack: expectation arrives ct=%p exp=%p\n",
+               pr_debug("conntrack: expectation arrives ct=%pK exp=%pK\n",
                         ct, exp);
                /* Welcome, Mr. Bond.  We've been expecting you... */
                __set_bit(IPS_EXPECTED_BIT, &ct->status);
@@ -909,14 +909,14 @@ resolve_normal_ct(struct net *net, struct nf_conn *tmpl,
        } else {
                /* Once we've had two way comms, always ESTABLISHED. */
                if (test_bit(IPS_SEEN_REPLY_BIT, &ct->status)) {
-                       pr_debug("nf_conntrack_in: normal packet for %p\n", ct);
+                       pr_debug("nf_conntrack_in: normal packet for %pK\n", ct);
                        *ctinfo = IP_CT_ESTABLISHED;
                } else if (test_bit(IPS_EXPECTED_BIT, &ct->status)) {
-                       pr_debug("nf_conntrack_in: related packet for %p\n",
+                       pr_debug("nf_conntrack_in: related packet for %pK\n",
                                 ct);
                        *ctinfo = IP_CT_RELATED;
                } else {
-                       pr_debug("nf_conntrack_in: new packet for %p\n", ct);
+                       pr_debug("nf_conntrack_in: new packet for %pK\n", ct);
                        *ctinfo = IP_CT_NEW;
                }
                *set_reply = 0;
@@ -1058,7 +1058,7 @@ void nf_conntrack_alter_reply(struct nf_conn *ct,
        /* Should be unconfirmed, so not in hash table yet */
        NF_CT_ASSERT(!nf_ct_is_confirmed(ct));
 
-       pr_debug("Altering reply tuple of %p to ", ct);
+       pr_debug("Altering reply tuple of %pK to ", ct);
        nf_ct_dump_tuple(newreply);
 
        ct->tuplehash[IP_CT_DIR_REPLY].tuple = *newreply;
@@ -1628,7 +1628,7 @@ int nf_conntrack_init_net(struct net *net)
                goto err_stat;
        }
 
-       net->ct.slabname = kasprintf(GFP_KERNEL, "nf_conntrack_%p", net);
+       net->ct.slabname = kasprintf(GFP_KERNEL, "nf_conntrack_%pK", net);
        if (!net->ct.slabname) {
                ret = -ENOMEM;
                goto err_slabname;
index 0644de8fd261138b8711f98e84cb158ce75279c0..8e5476172fbc459d39e0485db37dbebd4a6e68da 100644 (file)
@@ -1934,7 +1934,7 @@ static int qtaguid_ctrl_proc_show(struct seq_file *m, void *v)
                        );
                f_count = atomic_long_read(
                        &sock_tag_entry->socket->file->f_count);
-               seq_printf(m, "sock=%p tag=0x%llx (uid=%u) pid=%u "
+               seq_printf(m, "sock=%pK tag=0x%llx (uid=%u) pid=%u "
                           "f_count=%lu\n",
                           sock_tag_entry->sk,
                           sock_tag_entry->tag, uid,
index e8b5a0dfca21bc4920d9272db57c95174dc153e3..b16a7b83014d755213d231a8b73de07c3c1b3413 100644 (file)
@@ -3135,19 +3135,25 @@ packet_setsockopt(struct socket *sock, int level, int optname, char __user *optv
 
                if (optlen != sizeof(val))
                        return -EINVAL;
-               if (po->rx_ring.pg_vec || po->tx_ring.pg_vec)
-                       return -EBUSY;
                if (copy_from_user(&val, optval, sizeof(val)))
                        return -EFAULT;
                switch (val) {
                case TPACKET_V1:
                case TPACKET_V2:
                case TPACKET_V3:
-                       po->tp_version = val;
-                       return 0;
+                       break;
                default:
                        return -EINVAL;
                }
+               lock_sock(sk);
+               if (po->rx_ring.pg_vec || po->tx_ring.pg_vec) {
+                       ret = -EBUSY;
+               } else {
+                       po->tp_version = val;
+                       ret = 0;
+               }
+               release_sock(sk);
+               return ret;
        }
        case PACKET_RESERVE:
        {
@@ -3159,6 +3165,8 @@ packet_setsockopt(struct socket *sock, int level, int optname, char __user *optv
                        return -EBUSY;
                if (copy_from_user(&val, optval, sizeof(val)))
                        return -EFAULT;
+               if (val > INT_MAX)
+                       return -EINVAL;
                po->tp_reserve = val;
                return 0;
        }
@@ -3602,6 +3610,7 @@ static int packet_set_ring(struct sock *sk, union tpacket_req_u *req_u,
        /* Added to avoid minimal code churn */
        struct tpacket_req *req = &req_u->req;
 
+       lock_sock(sk);
        /* Opening a Tx-ring is NOT supported in TPACKET_V3 */
        if (!closing && tx_ring && (po->tp_version > TPACKET_V2)) {
                WARN(1, "Tx-ring is not supported.\n");
@@ -3642,6 +3651,10 @@ static int packet_set_ring(struct sock *sk, union tpacket_req_u *req_u,
                        goto out;
                if (unlikely(req->tp_block_size & (PAGE_SIZE - 1)))
                        goto out;
+               if (po->tp_version >= TPACKET_V3 &&
+                   req->tp_block_size <=
+                                               BLK_PLUS_PRIV((u64)req_u->req3.tp_sizeof_priv))
+                       goto out;
                if (unlikely(req->tp_frame_size < po->tp_hdrlen +
                                        po->tp_reserve))
                        goto out;
@@ -3651,6 +3664,8 @@ static int packet_set_ring(struct sock *sk, union tpacket_req_u *req_u,
                rb->frames_per_block = req->tp_block_size/req->tp_frame_size;
                if (unlikely(rb->frames_per_block <= 0))
                        goto out;
+               if (unlikely(req->tp_block_size > UINT_MAX / req->tp_block_nr))
+                       goto out;
                if (unlikely((rb->frames_per_block * req->tp_block_nr) !=
                                        req->tp_frame_nr))
                        goto out;
@@ -3679,7 +3694,6 @@ static int packet_set_ring(struct sock *sk, union tpacket_req_u *req_u,
                        goto out;
        }
 
-       lock_sock(sk);
 
        /* Detach socket from network */
        spin_lock(&po->bind_lock);
@@ -3728,11 +3742,11 @@ static int packet_set_ring(struct sock *sk, union tpacket_req_u *req_u,
                if (!tx_ring)
                        prb_shutdown_retire_blk_timer(po, tx_ring, rb_queue);
        }
-       release_sock(sk);
 
        if (pg_vec)
                free_pg_vec(pg_vec, order, req->tp_block_nr);
 out:
+       release_sock(sk);
        return err;
 }
 
index 86363611c821411cc58ae5b51022258795084886..0d716c943918334ae7ba285265f47ee138b76d55 100644 (file)
@@ -1823,6 +1823,8 @@ SYSCALL_DEFINE6(sendto, int, fd, void __user *, buff, size_t, len,
 
        if (len > INT_MAX)
                len = INT_MAX;
+       if (unlikely(!access_ok(VERIFY_READ, buff, len)))
+               return -EFAULT;
        sock = sockfd_lookup_light(fd, &err, &fput_needed);
        if (!sock)
                goto out;
@@ -1882,6 +1884,8 @@ SYSCALL_DEFINE6(recvfrom, int, fd, void __user *, ubuf, size_t, size,
 
        if (size > INT_MAX)
                size = INT_MAX;
+       if (unlikely(!access_ok(VERIFY_WRITE, ubuf, size)))
+               return -EFAULT;
        sock = sockfd_lookup_light(fd, &err, &fput_needed);
        if (!sock)
                goto out;
@@ -2444,13 +2448,14 @@ int __sys_recvmmsg(int fd, struct mmsghdr __user *mmsg, unsigned int vlen,
                        break;
        }
 
-out_put:
-       fput_light(sock->file, fput_needed);
-
        if (err == 0)
-               return datagrams;
+               goto out_put;           
+
+       if (datagrams == 0) {
+               datagrams = err;
+               goto out_put;
+       }
 
-       if (datagrams != 0) {
                /*
                 * We may return less entries than requested (vlen) if the
                 * sock is non block and there aren't enough datagrams...
@@ -2465,10 +2470,10 @@ out_put:
                        sock->sk->sk_err = -err;
                }
 
-               return datagrams;
-       }
+out_put:
+       fput_light(sock->file, fput_needed);
 
-       return err;
+       return datagrams;
 }
 
 SYSCALL_DEFINE5(recvmmsg, int, fd, struct mmsghdr __user *, mmsg,
index b7ac90644bfae5b166298ca1440f079e05b930bc..9b13da4e644d487f2475d4313563f73ddef47646 100644 (file)
@@ -334,6 +334,118 @@ found:
        return s;
 }
 
+/* Support code for asymmetrically connected dgram sockets
+ *
+ * If a datagram socket is connected to a socket not itself connected
+ * to the first socket (eg, /dev/log), clients may only enqueue more
+ * messages if the present receive queue of the server socket is not
+ * "too large". This means there's a second writeability condition
+ * poll and sendmsg need to test. The dgram recv code will do a wake
+ * up on the peer_wait wait queue of a socket upon reception of a
+ * datagram which needs to be propagated to sleeping would-be writers
+ * since these might not have sent anything so far. This can't be
+ * accomplished via poll_wait because the lifetime of the server
+ * socket might be less than that of its clients if these break their
+ * association with it or if the server socket is closed while clients
+ * are still connected to it and there's no way to inform "a polling
+ * implementation" that it should let go of a certain wait queue
+ *
+ * In order to propagate a wake up, a wait_queue_t of the client
+ * socket is enqueued on the peer_wait queue of the server socket
+ * whose wake function does a wake_up on the ordinary client socket
+ * wait queue. This connection is established whenever a write (or
+ * poll for write) hit the flow control condition and broken when the
+ * association to the server socket is dissolved or after a wake up
+ * was relayed.
+ */
+
+static int unix_dgram_peer_wake_relay(wait_queue_t *q, unsigned mode, int flags,
+                                     void *key)
+{
+       struct unix_sock *u;
+       wait_queue_head_t *u_sleep;
+
+       u = container_of(q, struct unix_sock, peer_wake);
+
+       __remove_wait_queue(&unix_sk(u->peer_wake.private)->peer_wait,
+                           q);
+       u->peer_wake.private = NULL;
+
+       /* relaying can only happen while the wq still exists */
+       u_sleep = sk_sleep(&u->sk);
+       if (u_sleep)
+               wake_up_interruptible_poll(u_sleep, key);
+
+       return 0;
+}
+
+static int unix_dgram_peer_wake_connect(struct sock *sk, struct sock *other)
+{
+       struct unix_sock *u, *u_other;
+       int rc;
+
+       u = unix_sk(sk);
+       u_other = unix_sk(other);
+       rc = 0;
+       spin_lock(&u_other->peer_wait.lock);
+
+       if (!u->peer_wake.private) {
+               u->peer_wake.private = other;
+               __add_wait_queue(&u_other->peer_wait, &u->peer_wake);
+
+               rc = 1;
+       }
+
+       spin_unlock(&u_other->peer_wait.lock);
+       return rc;
+}
+
+static void unix_dgram_peer_wake_disconnect(struct sock *sk,
+                                           struct sock *other)
+{
+       struct unix_sock *u, *u_other;
+
+       u = unix_sk(sk);
+       u_other = unix_sk(other);
+       spin_lock(&u_other->peer_wait.lock);
+
+       if (u->peer_wake.private == other) {
+               __remove_wait_queue(&u_other->peer_wait, &u->peer_wake);
+               u->peer_wake.private = NULL;
+       }
+
+       spin_unlock(&u_other->peer_wait.lock);
+}
+
+static void unix_dgram_peer_wake_disconnect_wakeup(struct sock *sk,
+                                                  struct sock *other)
+{
+       unix_dgram_peer_wake_disconnect(sk, other);
+       wake_up_interruptible_poll(sk_sleep(sk),
+                                  POLLOUT |
+                                  POLLWRNORM |
+                                  POLLWRBAND);
+}
+
+/* preconditions:
+ *     - unix_peer(sk) == other
+ *     - association is stable
+ */
+static int unix_dgram_peer_wake_me(struct sock *sk, struct sock *other)
+{
+       int connected;
+
+       connected = unix_dgram_peer_wake_connect(sk, other);
+
+       if (unix_recvq_full(other))
+               return 1;
+
+       if (connected)
+               unix_dgram_peer_wake_disconnect(sk, other);
+
+       return 0;
+}
+
 static inline int unix_writable(struct sock *sk)
 {
        return (atomic_read(&sk->sk_wmem_alloc) << 2) <= sk->sk_sndbuf;
@@ -440,6 +552,8 @@ static void unix_release_sock(struct sock *sk, int embrion)
                        skpair->sk_state_change(skpair);
                        sk_wake_async(skpair, SOCK_WAKE_WAITD, POLL_HUP);
                }
+
+               unix_dgram_peer_wake_disconnect(sk, skpair);
                sock_put(skpair); /* It may now die */
                unix_peer(sk) = NULL;
        }
@@ -674,6 +788,7 @@ static struct sock *unix_create1(struct net *net, struct socket *sock)
        INIT_LIST_HEAD(&u->link);
        mutex_init(&u->readlock); /* single task reading lock */
        init_waitqueue_head(&u->peer_wait);
+       init_waitqueue_func_entry(&u->peer_wake, unix_dgram_peer_wake_relay);
        unix_insert_socket(unix_sockets_unbound(sk), sk);
 out:
        if (sk == NULL)
@@ -1044,6 +1159,8 @@ restart:
        if (unix_peer(sk)) {
                struct sock *old_peer = unix_peer(sk);
                unix_peer(sk) = other;
+               unix_dgram_peer_wake_disconnect_wakeup(sk, old_peer);
+
                unix_state_double_unlock(sk, other);
 
                if (other != old_peer)
@@ -1504,6 +1621,7 @@ static int unix_dgram_sendmsg(struct kiocb *kiocb, struct socket *sock,
        struct scm_cookie tmp_scm;
        int max_level;
        int data_len = 0;
+       int sk_locked;
         
        if (NULL == siocb->scm)
                siocb->scm = &tmp_scm;
@@ -1580,12 +1698,14 @@ restart:
                goto out_free;
        }
 
+       sk_locked = 0;
        unix_state_lock(other);
+restart_locked:
        err = -EPERM;
        if (!unix_may_send(sk, other))
                goto out_unlock;
 
-       if (sock_flag(other, SOCK_DEAD)) {
+       if (unlikely(sock_flag(other, SOCK_DEAD))) {
                /*
                 *      Check with 1003.1g - what should
                 *      datagram error
@@ -1593,10 +1713,12 @@ restart:
                unix_state_unlock(other);
                sock_put(other);
 
-               err = 0;
+               if (!sk_locked)
                unix_state_lock(sk);
                if (unix_peer(sk) == other) {
                        unix_peer(sk) = NULL;
+                       unix_dgram_peer_wake_disconnect_wakeup(sk, other);
+
                        unix_state_unlock(sk);
 
                        unix_dgram_disconnected(sk, other);
@@ -1622,21 +1744,43 @@ restart:
                        goto out_unlock;
        }
 
-       if (unix_peer(other) != sk && unix_recvq_full(other)) {
-               if (!timeo) {
-                       err = -EAGAIN;
-                       goto out_unlock;
+       /* other == sk && unix_peer(other) != sk if
+        * - unix_peer(sk) == NULL, destination address bound to sk
+        * - unix_peer(sk) == sk by time of get but disconnected before lock
+        */
+       if (other != sk &&
+           unlikely(unix_peer(other) != sk && unix_recvq_full(other))) {
+               if (timeo) {
+                       timeo = unix_wait_for_peer(other, timeo);
+
+                       err = sock_intr_errno(timeo);
+                       if (signal_pending(current))
+                               goto out_free;
+
+                       goto restart;
                }
 
-               timeo = unix_wait_for_peer(other, timeo);
+               if (!sk_locked) {
+                       unix_state_unlock(other);
+                       unix_state_double_lock(sk, other);
+               }
 
-               err = sock_intr_errno(timeo);
-               if (signal_pending(current))
-                       goto out_free;
+               if (unix_peer(sk) != other ||
+                   unix_dgram_peer_wake_me(sk, other)) {
+                       err = -EAGAIN;
+                       sk_locked = 1;
+                       goto out_unlock;
+               }
 
-               goto restart;
+               if (!sk_locked) {
+                       sk_locked = 1;
+                       goto restart_locked;
+               }
        }
 
+       if (unlikely(sk_locked))
+               unix_state_unlock(sk);
+
        if (sock_flag(other, SOCK_RCVTSTAMP))
                __net_timestamp(skb);
        maybe_add_creds(skb, sock, other);
@@ -1651,6 +1795,8 @@ restart:
        return len;
 
 out_unlock:
+       if (sk_locked)
+               unix_state_unlock(sk);
        unix_state_unlock(other);
 out_free:
        kfree_skb(skb);
@@ -2368,14 +2514,16 @@ static unsigned int unix_dgram_poll(struct file *file, struct socket *sock,
   }
 
        writable = unix_writable(sk);
-       other = unix_peer_get(sk);
-       if (other) {
-               if (unix_peer(other) != sk) {
-                       sock_poll_wait(file, &unix_sk(other)->peer_wait, wait);
-                       if (unix_recvq_full(other))
-                               writable = 0;
-               }
-               sock_put(other);
+       if (writable) {
+               unix_state_lock(sk);
+
+               other = unix_peer(sk);
+               if (other && unix_peer(other) != sk &&
+                   unix_recvq_full(other) &&
+                   unix_dgram_peer_wake_me(sk, other))
+                       writable = 0;
+
+               unix_state_unlock(sk);
        }
 
        if (writable)
index 7a70a5a5671aa1c592446e3794ccd5b53e59fc1c..91a6a2903e8de045aa6145ad4f09af042cda2636 100644 (file)
@@ -390,7 +390,14 @@ static inline int xfrm_replay_verify_len(struct xfrm_replay_state_esn *replay_es
        up = nla_data(rp);
        ulen = xfrm_replay_state_esn_len(up);
 
-       if (nla_len(rp) < ulen || xfrm_replay_state_esn_len(replay_esn) != ulen)
+       /* Check the overall length and the internal bitmap length to avoid
+        * potential overflow. */
+       if (nla_len(rp) < ulen ||
+           xfrm_replay_state_esn_len(replay_esn) != ulen ||
+           replay_esn->bmp_len != up->bmp_len)
+               return -EINVAL;
+
+       if (up->replay_window > up->bmp_len * sizeof(__u32) * 8)
                return -EINVAL;
 
        return 0;
index 3fdf998ad0576d864ffca38691832aec3ff7e659..90f98ce3ee870d483fea312de8d81195f42436d8 100644 (file)
@@ -480,7 +480,7 @@ static int snd_compress_check_input(struct snd_compr_params *params)
 {
        /* first let's check the buffer parameter's */
        if (params->buffer.fragment_size == 0 ||
-                       params->buffer.fragments > SIZE_MAX / params->buffer.fragment_size)
+           params->buffer.fragments > INT_MAX / params->buffer.fragment_size)
                return -EINVAL;
 
        /* now codec parameters */
index e79baa11b60eb15526ba3679537720b2f29d0de6..f94708590e6170992988ea2adad4aaf80a81fa20 100644 (file)
@@ -253,6 +253,7 @@ static ssize_t snd_info_entry_write(struct file *file, const char __user *buffer
        struct snd_info_buffer *buf;
        ssize_t size = 0;
        loff_t pos;
+       unsigned long realloc_size;
 
        data = file->private_data;
        if (snd_BUG_ON(!data))
@@ -261,7 +262,8 @@ static ssize_t snd_info_entry_write(struct file *file, const char __user *buffer
        pos = *offset;
        if (pos < 0 || (long) pos != pos || (ssize_t) count < 0)
                return -EIO;
-       if ((unsigned long) pos + (unsigned long) count < (unsigned long) pos)
+       realloc_size = (unsigned long) pos + (unsigned long) count;
+       if (realloc_size < (unsigned long) pos || realloc_size > UINT_MAX)
                return -EIO;
        switch (entry->content) {
        case SNDRV_INFO_CONTENT_TEXT:
index f9077361c119d1a4a5eed6135a3d2e4042c812e5..4c9aa462de9b111336e164142784b8a013f24a53 100644 (file)
@@ -144,8 +144,10 @@ static struct snd_seq_queue *queue_new(int owner, int locked)
 static void queue_delete(struct snd_seq_queue *q)
 {
        /* stop and release the timer */
+       mutex_lock(&q->timer_mutex);
        snd_seq_timer_stop(q->timer);
        snd_seq_timer_close(q);
+       mutex_unlock(&q->timer_mutex);
        /* wait until access free */
        snd_use_lock_sync(&q->use_lock);
        /* release resources... */
index 6ddcf06f52f9a0c710cfbd65157915e5d90b14a4..ee81c947c24bb9fb08e67b8c8db050a082a291ed 100644 (file)
@@ -73,7 +73,7 @@ struct snd_timer_user {
        struct timespec tstamp;         /* trigger tstamp */
        wait_queue_head_t qchange_sleep;
        struct fasync_struct *fasync;
-       struct mutex tread_sem;
+       struct mutex ioctl_lock;
 };
 
 /* list of timers */
@@ -1174,6 +1174,7 @@ static void snd_timer_user_ccallback(struct snd_timer_instance *timeri,
                tu->tstamp = *tstamp;
        if ((tu->filter & (1 << event)) == 0 || !tu->tread)
                return;
+       memset(&r1, 0, sizeof(r1));
        r1.event = event;
        r1.tstamp = *tstamp;
        r1.val = resolution;
@@ -1208,6 +1209,7 @@ static void snd_timer_user_tinterrupt(struct snd_timer_instance *timeri,
        }
        if ((tu->filter & (1 << SNDRV_TIMER_EVENT_RESOLUTION)) &&
            tu->last_resolution != resolution) {
+               memset(&r1, 0, sizeof(r1));
                r1.event = SNDRV_TIMER_EVENT_RESOLUTION;
                r1.tstamp = tstamp;
                r1.val = resolution;
@@ -1256,7 +1258,7 @@ static int snd_timer_user_open(struct inode *inode, struct file *file)
                return -ENOMEM;
        spin_lock_init(&tu->qlock);
        init_waitqueue_head(&tu->qchange_sleep);
-       mutex_init(&tu->tread_sem);
+       mutex_init(&tu->ioctl_lock);
        tu->ticks = 1;
        tu->queue_size = 128;
        tu->queue = kmalloc(tu->queue_size * sizeof(struct snd_timer_read),
@@ -1276,8 +1278,10 @@ static int snd_timer_user_release(struct inode *inode, struct file *file)
        if (file->private_data) {
                tu = file->private_data;
                file->private_data = NULL;
+               mutex_lock(&tu->ioctl_lock);
                if (tu->timeri)
                        snd_timer_close(tu->timeri);
+               mutex_unlock(&tu->ioctl_lock);
                kfree(tu->queue);
                kfree(tu->tqueue);
                kfree(tu);
@@ -1515,7 +1519,6 @@ static int snd_timer_user_tselect(struct file *file,
        int err = 0;
 
        tu = file->private_data;
-       mutex_lock(&tu->tread_sem);
        if (tu->timeri) {
                snd_timer_close(tu->timeri);
                tu->timeri = NULL;
@@ -1559,7 +1562,6 @@ static int snd_timer_user_tselect(struct file *file,
        }
 
       __err:
-       mutex_unlock(&tu->tread_sem);
        return err;
 }
 
@@ -1673,6 +1675,7 @@ static int snd_timer_user_params(struct file *file,
        if (tu->timeri->flags & SNDRV_TIMER_IFLG_EARLY_EVENT) {
                if (tu->tread) {
                        struct snd_timer_tread tread;
+                       memset(&tread, 0, sizeof(tread));
                        tread.event = SNDRV_TIMER_EVENT_EARLY;
                        tread.tstamp.tv_sec = 0;
                        tread.tstamp.tv_nsec = 0;
@@ -1772,7 +1775,7 @@ enum {
        SNDRV_TIMER_IOCTL_PAUSE_OLD = _IO('T', 0x23),
 };
 
-static long snd_timer_user_ioctl(struct file *file, unsigned int cmd,
+static long __snd_timer_user_ioctl(struct file *file, unsigned int cmd,
                                 unsigned long arg)
 {
        struct snd_timer_user *tu;
@@ -1789,17 +1792,11 @@ static long snd_timer_user_ioctl(struct file *file, unsigned int cmd,
        {
                int xarg;
 
-               mutex_lock(&tu->tread_sem);
-               if (tu->timeri) {       /* too late */
-                       mutex_unlock(&tu->tread_sem);
+               if (tu->timeri) /* too late */
                        return -EBUSY;
-               }
-               if (get_user(xarg, p)) {
-                       mutex_unlock(&tu->tread_sem);
+               if (get_user(xarg, p))
                        return -EFAULT;
-               }
                tu->tread = xarg ? 1 : 0;
-               mutex_unlock(&tu->tread_sem);
                return 0;
        }
        case SNDRV_TIMER_IOCTL_GINFO:
@@ -1832,6 +1829,18 @@ static long snd_timer_user_ioctl(struct file *file, unsigned int cmd,
        return -ENOTTY;
 }
 
+static long snd_timer_user_ioctl(struct file *file, unsigned int cmd,
+                                unsigned long arg)
+{
+       struct snd_timer_user *tu = file->private_data;
+       long ret;
+
+       mutex_lock(&tu->ioctl_lock);
+       ret = __snd_timer_user_ioctl(file, cmd, arg);
+       mutex_unlock(&tu->ioctl_lock);
+       return ret;
+}
+
 static int snd_timer_user_fasync(int fd, struct file * file, int on)
 {
        struct snd_timer_user *tu;
index d56bbea6e75e60158405f45b1cf280f4d0fb9ac1..a0943cca1bc72bc58a7bec0a619bc19830ea1339 100644 (file)
@@ -2103,9 +2103,13 @@ unsigned int snd_soc_read(struct snd_soc_codec *codec, unsigned int reg)
 {
        unsigned int ret;
 
-       ret = codec->read(codec, reg);
-       dev_dbg(codec->dev, "read %x => %x\n", reg, ret);
-       trace_snd_soc_reg_read(codec, reg, ret);
+       if (codec->read) {
+               ret = codec->read(codec, reg);
+               dev_dbg(codec->dev, "read %x => %x\n", reg, ret);
+               trace_snd_soc_reg_read(codec, reg, ret);
+       }
+       else
+               ret = -EIO;
 
        return ret;
 }
@@ -2114,9 +2118,13 @@ EXPORT_SYMBOL_GPL(snd_soc_read);
 unsigned int snd_soc_write(struct snd_soc_codec *codec,
                           unsigned int reg, unsigned int val)
 {
-       dev_dbg(codec->dev, "write %x = %x\n", reg, val);
-       trace_snd_soc_reg_write(codec, reg, val);
-       return codec->write(codec, reg, val);
+       if (codec->write) {
+               dev_dbg(codec->dev, "write %x = %x\n", reg, val);
+               trace_snd_soc_reg_write(codec, reg, val);
+               return codec->write(codec, reg, val);
+       }
+       else
+               return -EIO;
 }
 EXPORT_SYMBOL_GPL(snd_soc_write);
 
diff --git a/tools/dct/MT8173.fig b/tools/dct/MT8173.fig
deleted file mode 100644 (file)
index b25e276..0000000
+++ /dev/null
@@ -1,453 +0,0 @@
-[Chip Type] 
-Chip = MT8173
-GPIO_Pull_Sel = 1 
-PMIC_Config = 1 
-PMIC_GPIO_Config = 1
-PMIC_ON_OFF_CONFIG = 1
-EINT_EXT_Config = 1
-POWER_Config = 1
-POWER_COUNT = 55
-GPIO_ModeNum = 8 
-AndroidPhone = 1  
-SpecialKey_Config = 1
-I2C_Config = 1
-CLOCK_BUFFER_CONFIG = 1
-PMIC_APP_Ver = 2
-PMIC_APP_COUNT = 6
-
-[GPIO] 
-GPIO0   = MODE0(GPIO0)            MODE1(IRDA_PDN)         MODE2(I2S1_WS)          MODE3(AUD_SPDIF)        MODE4(UTXD0)            MODE5()                 MODE6()                 MODE7(DBG_MON_A_20_)    PD     SMT_GROUP(1)    -
-GPIO1   = MODE0(GPIO1)            MODE1(IRDA_RXD)         MODE2(I2S1_BCK)         MODE3(SDA5)             MODE4(URXD0)            MODE5()                 MODE6()                 MODE7(DBG_MON_A_21_)    PD     SMT_GROUP(1)    -
-GPIO2   = MODE0(GPIO2)            MODE1(IRDA_TXD)         MODE2(I2S1_MCK)         MODE3(SCL5)             MODE4(UTXD3)            MODE5()                 MODE6()                 MODE7(DBG_MON_A_22_)    PD     SMT_GROUP(1)    -
-GPIO3   = MODE0(GPIO3)            MODE1(DSI1_TE)          MODE2(I2S1_DO_1)        MODE3(SDA3)             MODE4(URXD3)            MODE5()                 MODE6()                 MODE7(DBG_MON_A_23_)    PD     SMT_GROUP(1)    -
-GPIO4   = MODE0(GPIO4)            MODE1(DISP_PWM1)        MODE2(I2S1_DO_2)        MODE3(SCL3)             MODE4(UCTS3)            MODE5()                 MODE6(SFWP_B)           MODE7()                 PD     SMT_GROUP(1)    -
-GPIO5   = MODE0(GPIO5)            MODE1(PCM1_CLK)         MODE2(I2S2_WS)          MODE3(SPI_CK_3_)        MODE4(URTS3)            MODE5(AP_MD32_JTAG_TMS) MODE6(SFOUT)            MODE7()                 PD     SMT_GROUP(2)    -
-GPIO6   = MODE0(GPIO6)            MODE1(PCM1_SYNC)        MODE2(I2S2_BCK)         MODE3(SPI_MI_3_)        MODE4()                 MODE5(AP_MD32_JTAG_TCK) MODE6(SFCS0)            MODE7()                 PU     SMT_GROUP(2)    -
-GPIO7   = MODE0(GPIO7)            MODE1(PCM1_DI)          MODE2(I2S2_DI_1)        MODE3(SPI_MO_3_)        MODE4()                 MODE5(AP_MD32_JTAG_TDI) MODE6(SFHOLD)           MODE7()                 PD     SMT_GROUP(2)    -
-GPIO8   = MODE0(GPIO8)            MODE1(PCM1_DO)          MODE2(I2S2_DI_2)        MODE3(SPI_CS_3_)        MODE4(AUD_SPDIF)        MODE5(AP_MD32_JTAG_TDO) MODE6(SFIN)             MODE7()                 PD     SMT_GROUP(2)    -
-GPIO9   = MODE0(GPIO9)            MODE1(USB_DRVVBUS_P0)   MODE2(I2S2_MCK)         MODE3()                 MODE4(USB_DRVVBUS_P1)   MODE5(AP_MD32_JTAG_TRST) MODE6(SFCK)            MODE7()                 PD     SMT_GROUP(2)    -
-GPIO10  = MODE0(GPIO10)           MODE1(CLKM0)            MODE2(DSI1_TE)          MODE3(DISP_PWM1)        MODE4(PWM4)             MODE5(IRDA_RXD)         MODE6()                 MODE7()                 PD     SMT_GROUP(10)   - 
-GPIO11  = MODE0(GPIO11)           MODE1(CLKM1)            MODE2(I2S3_WS)          MODE3(USB_DRVVBUS_P0)   MODE4(PWM5)             MODE5(IRDA_TXD)         MODE6(USB_DRVVBUS_P1)   MODE7(DBG_MON_B_30_)    PD     SMT_GROUP(10)   - 
-GPIO12  = MODE0(GPIO12)           MODE1(CLKM2)            MODE2(I2S3_BCK)         MODE3(SRCLKENA0)        MODE4()                 MODE5(I2S2_WS)          MODE6()                 MODE7(DBG_MON_B_32_)    PD     SMT_GROUP(10)   - 
-GPIO13  = MODE0(GPIO13)           MODE1(CLKM3)            MODE2(I2S3_MCK)         MODE3(SRCLKENA0)        MODE4()                 MODE5(I2S2_BCK)         MODE6()                 MODE7(DBG_MON_A_32_)    PD     SMT_GROUP(10)   - 
-GPIO14  = MODE0(GPIO14)           MODE1(CMDAT0)           MODE2(CMCSD0)           MODE3()                 MODE4(CLKM2)            MODE5()                 MODE6()                 MODE7(DBG_MON_B_6_)     PD     SMT_GROUP(26)   - 
-GPIO15  = MODE0(GPIO15)           MODE1(CMDAT1)           MODE2(CMCSD1)           MODE3(CMFLASH)          MODE4(CLKM3)            MODE5()                 MODE6()                 MODE7(DBG_MON_B_29_)    PD     SMT_GROUP(26)   - 
-GPIO16  = MODE0(GPIO16)           MODE1(IDDIG)            MODE2(CMFLASH)          MODE3()                 MODE4(PWM5)             MODE5()                 MODE6()                 MODE7()                 PU     SMT_GROUP(0)    -
-GPIO17  = MODE0(GPIO17)           MODE1(WATCHDOG_AO)      MODE2()                 MODE3()                 MODE4()                 MODE5()                 MODE6()                 MODE7()                 PD     SMT_GROUP(34)   - 
-GPIO18  = MODE0(GPIO18)           MODE1(CEC)              MODE2()                 MODE3()                 MODE4()                 MODE5()                 MODE6()                 MODE7()                 PU     SMT_GROUP(19)   open-drain 
-GPIO19  = MODE0(GPIO19)           MODE1(HDMISCK)          MODE2(HDCP_SCL)         MODE3()                 MODE4()                 MODE5()                 MODE6()                 MODE7()                 PU     SMT_GROUP(19)   open-drain 
-GPIO20  = MODE0(GPIO20)           MODE1(HDMISD)           MODE2(HDCP_SDA)         MODE3()                 MODE4()                 MODE5()                 MODE6()                 MODE7()                 PU     SMT_GROUP(19)   open-drain 
-GPIO21  = MODE0(GPIO21)           MODE1(HTPLG)            MODE2()                 MODE3()                 MODE4()                 MODE5()                 MODE6()                 MODE7()                 PU     SMT_GROUP(19)   open-drain 
-GPIO22  = MODE0(GPIO22)           MODE1(MSDC3_DAT0)       MODE2()                 MODE3()                 MODE4()                 MODE5()                 MODE6()                 MODE7()                 PU     msdc3da_smt     -
-GPIO23  = MODE0(GPIO23)           MODE1(MSDC3_DAT1)       MODE2()                 MODE3()                 MODE4()                 MODE5()                 MODE6()                 MODE7()                 PU     msdc3da_smt     -
-GPIO24  = MODE0(GPIO24)           MODE1(MSDC3_DAT2)       MODE2()                 MODE3()                 MODE4()                 MODE5()                 MODE6()                 MODE7()                 PU     msdc3da_smt     -
-GPIO25  = MODE0(GPIO25)           MODE1(MSDC3_DAT3)       MODE2()                 MODE3()                 MODE4()                 MODE5()                 MODE6()                 MODE7()                 PU     msdc3da_smt     -
-GPIO26  = MODE0(GPIO26)           MODE1(MSDC3_CLK)        MODE2()                 MODE3()                 MODE4()                 MODE5()                 MODE6()                 MODE7()                 PD     msdc3ck_smt     -
-GPIO27  = MODE0(GPIO27)           MODE1(MSDC3_CMD)        MODE2()                 MODE3()                 MODE4()                 MODE5()                 MODE6()                 MODE7()                 PU     msdc3cm_smt     -
-GPIO28  = MODE0(GPIO28)           MODE1(MSDC3_DSL)        MODE2()                 MODE3()                 MODE4()                 MODE5()                 MODE6()                 MODE7()                 PD     msdc3ds_smt     -
-GPIO29  = MODE0(GPIO29)           MODE1(UCTS2)            MODE2()                 MODE3()                 MODE4()                 MODE5()                 MODE6()                 MODE7()                 PD     SMT_GROUP(3)    -
-GPIO30  = MODE0(GPIO30)           MODE1(URTS2)            MODE2()                 MODE3()                 MODE4()                 MODE5()                 MODE6()                 MODE7()                 PD     SMT_GROUP(3)    -
-GPIO31  = MODE0(GPIO31)           MODE1(URXD2)            MODE2(UTXD2)            MODE3()                 MODE4()                 MODE5()                 MODE6()                 MODE7()                 PD     SMT_GROUP(3)    -
-GPIO32  = MODE0(GPIO32)           MODE1(UTXD2)            MODE2(URXD2)            MODE3()                 MODE4()                 MODE5()                 MODE6()                 MODE7()                 PD     SMT_GROUP(3)    -
-GPIO33  = MODE0(GPIO33)           MODE1(MRG_CLK)          MODE2(PCM0_CLK)         MODE3()                 MODE4()                 MODE5()                 MODE6()                 MODE7()                 PD     SMT_GROUP(4)    -
-GPIO34  = MODE0(GPIO34)           MODE1(MRG_DI)           MODE2(PCM0_DI)          MODE3()                 MODE4()                 MODE5()                 MODE6()                 MODE7()                 PD     SMT_GROUP(5)    -
-GPIO35  = MODE0(GPIO35)           MODE1(MRG_DO)           MODE2(PCM0_DO)          MODE3()                 MODE4()                 MODE5()                 MODE6()                 MODE7()                 PD     SMT_GROUP(5)    -
-GPIO36  = MODE0(GPIO36)           MODE1(MRG_SYNC)         MODE2(PCM0_SYNC)        MODE3()                 MODE4()                 MODE5()                 MODE6()                 MODE7()                 PD     SMT_GROUP(5)    -
-GPIO37  = MODE0(GPIO37)           MODE1(USB_DRVVBUS_P0)   MODE2(USB_DRVVBUS_P1)   MODE3(PWM0)             MODE4(PWM1)             MODE5(PWM2)             MODE6(CLKM0)            MODE7()                 PD     SMT_GROUP(6)    -
-GPIO38  = MODE0(GPIO38)           MODE1(USB_DRVVBUS_P0)   MODE2(USB_DRVVBUS_P1)   MODE3()                 MODE4()                 MODE5()                 MODE6(CLKM1)            MODE7()                 PD     SMT_GROUP(6)    -
-GPIO39  = MODE0(GPIO39)           MODE1(CM2MCLK)          MODE2(CMCSD0)           MODE3()                 MODE4()                 MODE5()                 MODE6()                 MODE7(DBG_MON_A_17_)    PD     SMT_GROUP(7)    -
-GPIO40  = MODE0(GPIO40)           MODE1(CMPCLK)           MODE2(CMCSK)            MODE3(CMCSD2)           MODE4()                 MODE5()                 MODE6()                 MODE7(DBG_MON_A_18_)    PD     SMT_GROUP(9)    -
-GPIO41  = MODE0(GPIO41)           MODE1(CMMCLK)           MODE2()                 MODE3()                 MODE4()                 MODE5()                 MODE6()                 MODE7(DBG_MON_A_19_)    PD     SMT_GROUP(9)    -
-GPIO42  = MODE0(GPIO42)           MODE1(DSI_TE)           MODE2()                 MODE3()                 MODE4()                 MODE5()                 MODE6()                 MODE7()                 PD     SMT_GROUP(16)   - 
-GPIO43  = MODE0(GPIO43)           MODE1(SDA2)             MODE2()                 MODE3()                 MODE4()                 MODE5()                 MODE6()                 MODE7()                 PU     SMT_GROUP(11)   open-drain   
-GPIO44  = MODE0(GPIO44)           MODE1(SCL2)             MODE2()                 MODE3()                 MODE4()                 MODE5()                 MODE6()                 MODE7()                 PU     SMT_GROUP(11)   open-drain
-GPIO45  = MODE0(GPIO45)           MODE1(SDA0)             MODE2()                 MODE3()                 MODE4()                 MODE5()                 MODE6()                 MODE7()                 PU     SMT_GROUP(12)   open-drain
-GPIO46  = MODE0(GPIO46)           MODE1(SCL0)             MODE2()                 MODE3()                 MODE4()                 MODE5()                 MODE6()                 MODE7()                 PU     SMT_GROUP(12)   open-drain
-GPIO47  = MODE0(GPIO47)           MODE1(CMDAT2)           MODE2()                 MODE3()                 MODE4()                 MODE5()                 MODE6()                 MODE7()                 -     -     -
-GPIO48  = MODE0(GPIO48)           MODE1(CMDAT3)           MODE2()                 MODE3()                 MODE4()                 MODE5()                 MODE6()                 MODE7()                 -     -     -
-GPIO49  = MODE0(GPIO49)           MODE1(CMDAT4)           MODE2()                 MODE3()                 MODE4()                 MODE5()                 MODE6()                 MODE7()                 -     -     -
-GPIO50  = MODE0(GPIO50)           MODE1(CMDAT5)           MODE2()                 MODE3()                 MODE4()                 MODE5()                 MODE6()                 MODE7()                 -     -     -
-GPIO51  = MODE0(GPIO51)           MODE1(CMDAT6)           MODE2()                 MODE3()                 MODE4()                 MODE5()                 MODE6()                 MODE7()                 -     -     -
-GPIO52  = MODE0(GPIO52)           MODE1(CMDAT7)           MODE2()                 MODE3()                 MODE4()                 MODE5()                 MODE6()                 MODE7()                 -     -     -
-GPIO53  = MODE0(GPIO53)           MODE1(CMDAT8)           MODE2(CMCSD3)           MODE3()                 MODE4()                 MODE5()                 MODE6()                 MODE7()                 -     -     -
-GPIO54  = MODE0(GPIO54)           MODE1(CMDAT9)           MODE2(CMCSD2)           MODE3()                 MODE4()                 MODE5()                 MODE6()                 MODE7()                 -     -     -
-GPIO55  = MODE0(GPIO55)           MODE1(CMHSYNC)          MODE2(CMCSD1)           MODE3()                 MODE4()                 MODE5()                 MODE6()                 MODE7()                 -     -     -
-GPIO56  = MODE0(GPIO56)           MODE1(CMVSYNC)          MODE2(CMCSD0)           MODE3()                 MODE4()                 MODE5()                 MODE6()                 MODE7()                 -     -     -
-GPIO57  = MODE0(GPIO57)           MODE1(MSDC0_DAT0)       MODE2(I2S1_WS)          MODE3()                 MODE4()                 MODE5()                 MODE6()                 MODE7(DBG_MON_B_7_)     PU     msdc0da_smt           -          
-GPIO58  = MODE0(GPIO58)           MODE1(MSDC0_DAT1)       MODE2(I2S1_BCK)         MODE3()                 MODE4()                 MODE5()                 MODE6()                 MODE7(DBG_MON_B_8_)     PU     msdc0da_smt           -
-GPIO59  = MODE0(GPIO59)           MODE1(MSDC0_DAT2)       MODE2(I2S1_MCK)         MODE3()                 MODE4()                 MODE5()                 MODE6()                 MODE7(DBG_MON_B_9_)     PU     msdc0da_smt           -
-GPIO60  = MODE0(GPIO60)           MODE1(MSDC0_DAT3)       MODE2(I2S1_DO_1)        MODE3()                 MODE4()                 MODE5()                 MODE6()                 MODE7(DBG_MON_B_10_)    PU     msdc0da_smt           - 
-GPIO61  = MODE0(GPIO61)           MODE1(MSDC0_DAT4)       MODE2(I2S1_DO_2)        MODE3()                 MODE4()                 MODE5()                 MODE6()                 MODE7(DBG_MON_B_11_)    PU     msdc0da_smt           -
-GPIO62  = MODE0(GPIO62)           MODE1(MSDC0_DAT5)       MODE2(I2S2_WS)          MODE3()                 MODE4()                 MODE5()                 MODE6()                 MODE7(DBG_MON_B_12_)    PU     msdc0da_smt           -
-GPIO63  = MODE0(GPIO63)           MODE1(MSDC0_DAT6)       MODE2(I2S2_BCK)         MODE3()                 MODE4()                 MODE5()                 MODE6()                 MODE7(DBG_MON_B_13_)    PU     msdc0da_smt           -
-GPIO64  = MODE0(GPIO64)           MODE1(MSDC0_DAT7)       MODE2(I2S2_DI_1)        MODE3()                 MODE4()                 MODE5()                 MODE6()                 MODE7(DBG_MON_B_14_)    PU     msdc0da_smt                   -
-GPIO65  = MODE0(GPIO65)           MODE1(MSDC0_CLK)        MODE2()                 MODE3()                 MODE4()                 MODE5()                 MODE6()                 MODE7(DBG_MON_B_16_)    PD     msdc0ck_smt           -
-GPIO66  = MODE0(GPIO66)           MODE1(MSDC0_CMD)        MODE2(I2S2_DI_2)        MODE3()                 MODE4()                 MODE5()                 MODE6()                 MODE7(DBG_MON_B_15_)    PU     msdc0cm_smt           -
-GPIO67  = MODE0(GPIO67)           MODE1(MSDC0_DSL)        MODE2()                 MODE3()                 MODE4()                 MODE5()                 MODE6()                 MODE7(DBG_MON_B_17_)    PD     msdc0ds_smt           -
-GPIO68  = MODE0(GPIO68)           MODE1(MSDC0_RSTB)       MODE2(I2S2_MCK)         MODE3()                 MODE4()                 MODE5()                 MODE6()                 MODE7(DBG_MON_B_18_)    PU     msdc0rs_smt           -
-GPIO69  = MODE0(GPIO69)           MODE1(SPI_CK_0_)        MODE2(I2S3_DO_1)        MODE3(PWM0)             MODE4(PWM5)             MODE5(I2S2_MCK)         MODE6()                 MODE7(DBG_MON_B_19_)    PD     SMT_GROUP(30)         -  
-GPIO70  = MODE0(GPIO70)           MODE1(SPI_MI_0_)        MODE2(I2S3_DO_2)        MODE3(PWM1)             MODE4(SPI_MO_0_)        MODE5(I2S2_DI_1)        MODE6(DSI1_TE)          MODE7(DBG_MON_B_20_)    PD     SMT_GROUP(30)         -  
-GPIO71  = MODE0(GPIO71)           MODE1(SPI_MO_0_)        MODE2(I2S3_DO_3)        MODE3(PWM2)             MODE4(SPI_MI_0_)        MODE5(I2S2_DI_2)        MODE6()                 MODE7(DBG_MON_B_21_)    PD     SMT_GROUP(30)         -  
-GPIO72  = MODE0(GPIO72)           MODE1(SPI_CS_0_)        MODE2(I2S3_DO_4)        MODE3(PWM3)             MODE4(PWM6)             MODE5(DISP_PWM1)        MODE6()                 MODE7(DBG_MON_B_22_)    PD     SMT_GROUP(30)         -  
-GPIO73  = MODE0(GPIO73)           MODE1(MSDC1_DAT0)       MODE2()                 MODE3()                 MODE4()                 MODE5()                 MODE6()                 MODE7(DBG_MON_B_24_)    PU     msdc1da_smt           -
-GPIO74  = MODE0(GPIO74)           MODE1(MSDC1_DAT1)       MODE2()                 MODE3()                 MODE4()                 MODE5()                 MODE6()                 MODE7(DBG_MON_B_25_)    PU     msdc1da_smt           -
-GPIO75  = MODE0(GPIO75)           MODE1(MSDC1_DAT2)       MODE2()                 MODE3()                 MODE4()                 MODE5()                 MODE6()                 MODE7(DBG_MON_B_26_)    PU     msdc1da_smt           -
-GPIO76  = MODE0(GPIO76)           MODE1(MSDC1_DAT3)       MODE2()                 MODE3()                 MODE4()                 MODE5()                 MODE6()                 MODE7(DBG_MON_B_27_)    PU     msdc1da_smt           -
-GPIO77  = MODE0(GPIO77)           MODE1(MSDC1_CLK)        MODE2()                 MODE3()                 MODE4()                 MODE5()                 MODE6()                 MODE7(DBG_MON_B_28_)    PD     msdc1ck_smt           -
-GPIO78  = MODE0(GPIO78)           MODE1(MSDC1_CMD)        MODE2()                 MODE3()                 MODE4()                 MODE5()                 MODE6()                 MODE7(DBG_MON_B_23_)    PU     msdc1cm_smt           -
-GPIO79  = MODE0(GPIO79)           MODE1(PWRAP_SPIMI)      MODE2(PWRAP_SPIMO)      MODE3()                 MODE4()                 MODE5()                 MODE6()                 MODE7()                 PD     SMT_GROUP(31)         -  
-GPIO80  = MODE0(GPIO80)           MODE1(PWRAP_SPIMO)      MODE2(PWRAP_SPIMI)      MODE3()                 MODE4()                 MODE5()                 MODE6()                 MODE7()                 PD     SMT_GROUP(31)    -  
-GPIO81  = MODE0(GPIO81)           MODE1(PWRAP_SPICK)      MODE2()                 MODE3()                 MODE4()                 MODE5()                 MODE6()                 MODE7()                 PD     SMT_GROUP(31)    -
-GPIO82  = MODE0(GPIO82)           MODE1(PWRAP_SPICS)      MODE2()                 MODE3()                 MODE4()                 MODE5()                 MODE6()                 MODE7()                 PU     SMT_GROUP(31)    -
-GPIO83  = MODE0(GPIO83)           MODE1(AUD_CLK_MOSI)     MODE2()                 MODE3()                 MODE4()                 MODE5()                 MODE6()                 MODE7()                 PD     SMT_GROUP(32)    -
-GPIO84  = MODE0(GPIO84)           MODE1(AUD_DAT_MISO)     MODE2(AUD_DAT_MOSI)     MODE3()                 MODE4()                 MODE5()                 MODE6()                 MODE7()                 PD     SMT_GROUP(33)    -
-GPIO85  = MODE0(GPIO85)           MODE1(AUD_DAT_MOSI)     MODE2(AUD_DAT_MISO)     MODE3()                 MODE4()                 MODE5()                 MODE6()                 MODE7()                 PD     SMT_GROUP(33)    -
-GPIO86  = MODE0(GPIO86)           MODE1(RTC32K_CK)        MODE2()                 MODE3()                 MODE4()                 MODE5()                 MODE6()                 MODE7()                 PD     SMT_GROUP(34)    -
-GPIO87  = MODE0(GPIO87)           MODE1(DISP_PWM0)        MODE2(DISP_PWM1)        MODE3()                 MODE4()                 MODE5()                 MODE6()                 MODE7(DBG_MON_B_31_)    PD     SMT_GROUP(34)    -
-GPIO88  = MODE0(GPIO88)           MODE1(SRCLKENAI)        MODE2()                 MODE3()                 MODE4()                 MODE5()                 MODE6()                 MODE7()                 PD     SMT_GROUP(34)    -
-GPIO89  = MODE0(GPIO89)           MODE1(SRCLKENAI2)       MODE2()                 MODE3()                 MODE4()                 MODE5()                 MODE6()                 MODE7()                 PD     SMT_GROUP(34)    -
-GPIO90  = MODE0(GPIO90)           MODE1(SRCLKENA0)        MODE2()                 MODE3()                 MODE4()                 MODE5()                 MODE6()                 MODE7()                 PU     SMT_GROUP(34)    -
-GPIO91  = MODE0(GPIO91)           MODE1(SRCLKENA1)        MODE2()                 MODE3()                 MODE4()                 MODE5()                 MODE6()                 MODE7()                 PU     SMT_GROUP(34)    -
-GPIO92  = MODE0(GPIO92)           MODE1(PCM1_CLK)         MODE2(I2S0_BCK)         MODE3()                 MODE4()                 MODE5()                 MODE6()                 MODE7(DBG_MON_A_24_)    PD     SMT_GROUP(13)    -
-GPIO93  = MODE0(GPIO93)           MODE1(PCM1_SYNC)        MODE2(I2S0_WS)          MODE3()                 MODE4()                 MODE5()                 MODE6()                 MODE7(DBG_MON_A_25_)    PD     SMT_GROUP(14)    -
-GPIO94  = MODE0(GPIO94)           MODE1(PCM1_DI)          MODE2(I2S0_DI)          MODE3()                 MODE4()                 MODE5()                 MODE6()                 MODE7(DBG_MON_A_26_)    PD     SMT_GROUP(14)    -
-GPIO95  = MODE0(GPIO95)           MODE1(PCM1_DO)          MODE2(I2S0_DO)          MODE3()                 MODE4()                 MODE5()                 MODE6()                 MODE7(DBG_MON_A_27_)    PD     SMT_GROUP(14)    -
-GPIO96  = MODE0(GPIO96)           MODE1(URXD1)            MODE2(UTXD1)            MODE3()                 MODE4()                 MODE5()                 MODE6()                 MODE7(DBG_MON_A_28_)    PD     SMT_GROUP(15)    -
-GPIO97  = MODE0(GPIO97)           MODE1(UTXD1)            MODE2(URXD1)            MODE3()                 MODE4()                 MODE5()                 MODE6()                 MODE7(DBG_MON_A_29_)    PU     SMT_GROUP(15)    -
-GPIO98  = MODE0(GPIO98)           MODE1(URTS1)            MODE2(UCTS1)            MODE3()                 MODE4()                 MODE5()                 MODE6()                 MODE7(DBG_MON_A_30_)    PD     SMT_GROUP(15)    -
-GPIO99  = MODE0(GPIO99)           MODE1(UCTS1)            MODE2(URTS1)            MODE3()                 MODE4()                 MODE5()                 MODE6()                 MODE7(DBG_MON_A_31_)    PD     SMT_GROUP(15)    -
-GPIO100 = MODE0(GPIO100)          MODE1(MSDC2_DAT0)       MODE2()                 MODE3(USB_DRVVBUS_P0)   MODE4(SDA5)             MODE5(USB_DRVVBUS_P1)   MODE6()                 MODE7(DBG_MON_B_0_)     PD     msdc2da_smt      -
-GPIO101 = MODE0(GPIO101)          MODE1(MSDC2_DAT1)       MODE2()                 MODE3(AUD_SPDIF)        MODE4(SCL5)             MODE5()                 MODE6()                 MODE7(DBG_MON_B_1_)     PD     msdc2da_smt      -
-GPIO102 = MODE0(GPIO102)          MODE1(MSDC2_DAT2)       MODE2()                 MODE3(UTXD0)            MODE4()                 MODE5(PWM0)             MODE6(SPI_CK_1_)        MODE7(DBG_MON_B_2_)     PD     msdc2da_smt      -
-GPIO103 = MODE0(GPIO103)          MODE1(MSDC2_DAT3)       MODE2()                 MODE3(URXD0)            MODE4()                 MODE5(PWM1)             MODE6(SPI_MI_1_)        MODE7(DBG_MON_B_3_)     PD     msdc2da_smt           -
-GPIO104 = MODE0(GPIO104)          MODE1(MSDC2_CLK)        MODE2()                 MODE3(UTXD3)            MODE4(SDA3)             MODE5(PWM2)             MODE6(SPI_MO_1_)        MODE7(DBG_MON_B_4_)     PD     msdc2ck_smt           -
-GPIO105 = MODE0(GPIO105)          MODE1(MSDC2_CMD)        MODE2()                 MODE3(URXD3)            MODE4(SCL3)             MODE5(PWM3)             MODE6(SPI_CS_1_)        MODE7(DBG_MON_B_5_)     PD     msdc2cm_smt           -
-GPIO106 = MODE0(GPIO106)          MODE1(SDA3)             MODE2()                 MODE3()                 MODE4()                 MODE5()                 MODE6()                 MODE7()                 PU     SMT_GROUP(20)    open-drain   
-GPIO107 = MODE0(GPIO107)          MODE1(SCL3)             MODE2()                 MODE3()                 MODE4()                 MODE5()                 MODE6()                 MODE7()                 PU     SMT_GROUP(20)    open-drain 
-GPIO108 = MODE0(GPIO108)          MODE1(JTMS)             MODE2(MFG_JTAG_TMS)     MODE3()                 MODE4()                 MODE5(AP_MD32_JTAG_TMS) MODE6(DFD_TMS)          MODE7()                 PU     SMT_GROUP(17)    -
-GPIO109 = MODE0(GPIO109)          MODE1(JTCK)             MODE2(MFG_JTAG_TCK)     MODE3()                 MODE4()                 MODE5(AP_MD32_JTAG_TCK) MODE6(DFD_TCK)          MODE7()                 PU     SMT_GROUP(17)    -
-GPIO110 = MODE0(GPIO110)          MODE1(JTDI)             MODE2(MFG_JTAG_TDI)     MODE3()                 MODE4()                 MODE5(AP_MD32_JTAG_TDI) MODE6(DFD_TDI)          MODE7()                 PU     SMT_GROUP(17)    -
-GPIO111 = MODE0(GPIO111)          MODE1(JTDO)             MODE2(MFG_JTAG_TDO)     MODE3()                 MODE4()                 MODE5(AP_MD32_JTAG_TDO) MODE6(DFD_TDO)          MODE7()                 PU     SMT_GROUP(17)    -
-GPIO112 = MODE0(GPIO112)          MODE1(JTRST_B)          MODE2(MFG_JTAG_TRSTN)   MODE3()                 MODE4()                 MODE5(AP_MD32_JTAG_TRST) MODE6(DFD_NTRST)       MODE7()                 PD     SMT_GROUP(17)    -
-GPIO113 = MODE0(GPIO113)          MODE1(URXD0)            MODE2(UTXD0)            MODE3()                 MODE4()                 MODE5()                 MODE6(I2S2_WS)          MODE7(DBG_MON_A_0_)     PU     SMT_GROUP(18)    -
-GPIO114 = MODE0(GPIO114)          MODE1(UTXD0)            MODE2(URXD0)            MODE3()                 MODE4()                 MODE5()                 MODE6(I2S2_BCK)         MODE7(DBG_MON_A_1_)     PU     SMT_GROUP(18)    -
-GPIO115 = MODE0(GPIO115)          MODE1(URTS0)            MODE2(UCTS0)            MODE3()                 MODE4()                 MODE5()                 MODE6(I2S2_MCK)         MODE7(DBG_MON_A_2_)     PD     SMT_GROUP(18)    -
-GPIO116 = MODE0(GPIO116)          MODE1(UCTS0)            MODE2(URTS0)            MODE3()                 MODE4()                 MODE5()                 MODE6(I2S2_DI_1)        MODE7(DBG_MON_A_3_)     PD     SMT_GROUP(18)    -
-GPIO117 = MODE0(GPIO117)          MODE1(URXD3)            MODE2(UTXD3)            MODE3()                 MODE4()                 MODE5()                 MODE6()                 MODE7(DBG_MON_A_9_)     PD     SMT_GROUP(21)    -
-GPIO118 = MODE0(GPIO118)          MODE1(UTXD3)            MODE2(URXD3)            MODE3()                 MODE4()                 MODE5()                 MODE6()                 MODE7(DBG_MON_A_10_)    PD     SMT_GROUP(21)    -
-GPIO119 = MODE0(GPIO119)          MODE1(KROW0)            MODE2()                 MODE3()                 MODE4()                 MODE5()                 MODE6()                 MODE7(DBG_MON_A_11_)    PD     SMT_GROUP(22)    -
-GPIO120 = MODE0(GPIO120)          MODE1(KROW1)            MODE2()                 MODE3(PWM6)             MODE4()                 MODE5()                 MODE6()                 MODE7(DBG_MON_A_12_)    PD     SMT_GROUP(22)    -
-GPIO121 = MODE0(GPIO121)          MODE1(KROW2)            MODE2(IRDA_PDN)         MODE3(USB_DRVVBUS_P0)   MODE4(PWM4)             MODE5(USB_DRVVBUS_P1)   MODE6()                 MODE7(DBG_MON_A_13_)    PD     SMT_GROUP(22)    -
-GPIO122 = MODE0(GPIO122)          MODE1(KCOL0)            MODE2()                 MODE3()                 MODE4()                 MODE5()                 MODE6()                 MODE7(DBG_MON_A_14_)    PU     SMT_GROUP(22)    -
-GPIO123 = MODE0(GPIO123)          MODE1(KCOL1)            MODE2(IRDA_RXD)         MODE3(PWM5)             MODE4()                 MODE5()                 MODE6()                 MODE7(DBG_MON_A_15_)    PD     SMT_GROUP(22)    -
-GPIO124 = MODE0(GPIO124)          MODE1(KCOL2)            MODE2(IRDA_TXD)         MODE3(USB_DRVVBUS_P0)   MODE4(PWM3)             MODE5(USB_DRVVBUS_P1)   MODE6()                 MODE7(DBG_MON_A_16_)    PD     SMT_GROUP(22)    -
-GPIO125 = MODE0(GPIO125)          MODE1(SDA1)             MODE2()                 MODE3()                 MODE4()                 MODE5()                 MODE6()                 MODE7()                 PU     SMT_GROUP(23)    -
-GPIO126 = MODE0(GPIO126)          MODE1(SCL1)             MODE2()                 MODE3()                 MODE4()                 MODE5()                 MODE6()                 MODE7()                 PU     SMT_GROUP(23)    -
-GPIO127 = MODE0(GPIO127)          MODE1(LCM_RST)          MODE2()                 MODE3()                 MODE4()                 MODE5()                 MODE6()                 MODE7()                 PD     SMT_GROUP(16)    -
-GPIO128 = MODE0(GPIO128)          MODE1(I2S0_WS)          MODE2(I2S1_WS)          MODE3(I2S2_WS)          MODE4()                 MODE5(SPI_CK_2_)        MODE6()                 MODE7(DBG_MON_A_4_)     PU     SMT_GROUP(40)    -
-GPIO129 = MODE0(GPIO129)          MODE1(I2S0_BCK)         MODE2(I2S1_BCK)         MODE3(I2S2_BCK)         MODE4()                 MODE5(SPI_MI_2_)        MODE6()                 MODE7(DBG_MON_A_5_)     PD     SMT_GROUP(41)    -
-GPIO130 = MODE0(GPIO130)          MODE1(I2S0_MCK)         MODE2(I2S1_MCK)         MODE3(I2S2_MCK)         MODE4()                 MODE5(SPI_MO_2_)        MODE6()                 MODE7(DBG_MON_A_6_)     PD     SMT_GROUP(41)    -
-GPIO131 = MODE0(GPIO131)          MODE1(I2S0_DO)          MODE2(I2S1_DO_1)        MODE3(I2S2_DI_1)        MODE4()                 MODE5(SPI_CS_2_)        MODE6()                 MODE7(DBG_MON_A_7_)     PD     SMT_GROUP(40)    -
-GPIO132 = MODE0(GPIO132)          MODE1(I2S0_DI)          MODE2(I2S1_DO_2)        MODE3(I2S2_DI_2)        MODE4()                 MODE5()                 MODE6()                 MODE7(DBG_MON_A_8_)     PD     SMT_GROUP(40)    -
-GPIO133 = MODE0(GPIO133)          MODE1(SDA4)             MODE2()                 MODE3()                 MODE4()                 MODE5()                 MODE6()                 MODE7()                 PU     SMT_GROUP(24)    -
-GPIO134 = MODE0(GPIO134)          MODE1(SCL4)             MODE2()                 MODE3()                 MODE4()                 MODE5()                 MODE6()                 MODE7()                 PU     SMT_GROUP(24)    -
-
-[GPIOEXT]
-GPIOEXT0   = MODE0(GPIO0)           MODE1(INT)                    MODE2()                  MODE3()                  MODE4()                       MODE5()                 MODE6()                 MODE7()                 PD                            
-GPIOEXT1   = MODE0(GPIO1)           MODE1(SRCVOLTEN)              MODE2()                  MODE3()                  MODE4()                       MODE5()                 MODE6(TEST_CK1)         MODE7()                 PD                            
-GPIOEXT2   = MODE0(GPIO2)           MODE1(SRCLKEN_PERI)           MODE2()                  MODE3()                  MODE4()                       MODE5()                 MODE6(TEST_CK2)         MODE7()                 PD                            
-GPIOEXT3   = MODE0(GPIO3)           MODE1(RTC_32K1V8)             MODE2()                  MODE3()                  MODE4()                       MODE5()                 MODE6(TEST_CK3)         MODE7()                 PU/PD                         
-GPIOEXT4   = MODE0(GPIO4)           MODE1(WRAP_EVENT)             MODE2()                  MODE3()                  MODE4()                       MODE5()                 MODE6()                 MODE7()                 PD                            
-GPIOEXT5   = MODE0(GPIO5)           MODE1(SPI_CLK)                MODE2()                  MODE3()                  MODE4()                       MODE5()                 MODE6()                 MODE7()                 PD                            
-GPIOEXT6   = MODE0(GPIO6)           MODE1(SPI_CSN)                MODE2()                  MODE3()                  MODE4()                       MODE5()                 MODE6()                 MODE7()                 PU                            
-GPIOEXT7   = MODE0(GPIO7)           MODE1(SPI_MOSI)               MODE2()                  MODE3()                  MODE4()                       MODE5()                 MODE6()                 MODE7()                 PD                            
-GPIOEXT8   = MODE0(GPIO8)           MODE1(SPI_MISO)               MODE2()                  MODE3()                  MODE4()                       MODE5()                 MODE6()                 MODE7()                 PD                            
-GPIOEXT9   = MODE0(GPIO9)           MODE1(AUD_CLK)                MODE2()                  MODE3()                  MODE4()                       MODE5()                 MODE6(TEST_IN0)         MODE7(TEST_IN0)         PD                            
-GPIOEXT10  = MODE0(GPIO10)          MODE1(AUD_MISO)               MODE2()                  MODE3()                  MODE4()                       MODE5()                 MODE6(TEST_IN1)         MODE7(TEST_OUT1)        PD                            
-GPIOEXT11  = MODE0(GPIO11)          MODE1(AUD_MOSI)               MODE2()                  MODE3()                  MODE4()                       MODE5()                 MODE6(TEST_IN2)         MODE7(TSET_OUT2)        PD                            
-GPIOEXT12  = MODE0(GPIO12)          MODE1(COL0_USBDL)             MODE2(EINT10_1X)         MODE3(PWM1_3X)           MODE4()                       MODE5()                 MODE6(TEST_IN3)         MODE7(TEST_OUT3)        PU                       
-GPIOEXT13  = MODE0(GPIO13)          MODE1(COL1)                   MODE2(EINT11_1X)         MODE3(SCL0_2X)           MODE4()                       MODE5()                 MODE6(TEST_IN4)         MODE7(TEST_OUT4)        PD                       
-GPIOEXT14  = MODE0(GPIO14)          MODE1(COL2)                   MODE2(EINT12_1X)         MODE3(SDA0_2X)           MODE4()                       MODE5()                 MODE6(TEST_IN5)         MODE7(TEST_OUT5)        PD                       
-GPIOEXT15  = MODE0(GPIO15)          MODE1(COL3)                   MODE2(EINT13_1X)         MODE3(SCL1_2X)           MODE4()                       MODE5()                 MODE6(TEST_IN6)         MODE7(TEST_OUT6)        PD                       
-GPIOEXT16  = MODE0(GPIO16)          MODE1(COL4)                   MODE2(EINT14_1X)         MODE3(SDA1_2X)           MODE4()                       MODE5()                 MODE6(TEST_IN7)         MODE7(TEST_OUT7)        PD                       
-GPIOEXT17  = MODE0(GPIO17)          MODE1(COL5)                   MODE2(EINT15_1X)         MODE3(SCL2_2X)           MODE4()                       MODE5()                 MODE6(TEST_IN8)         MODE7(TEST_OUT8)        PD                       
-GPIOEXT18  = MODE0(GPIO18)          MODE1(COL6)                   MODE2(EINT16_1X)         MODE3(SDA2_2X)           MODE4(GPIO32K_0)              MODE5(GPIO26M_0)        MODE6(TEST_IN9)         MODE7(TEST_OUT9)        PD                       
-GPIOEXT19  = MODE0(GPIO19)          MODE1(COL7)                   MODE2(EINT17_1X)         MODE3(PWM2_3X)           MODE4(GPIO32K_1)              MODE5(GPIO26M_1)        MODE6(TEST_IN10)        MODE7(TEST_OUT10)       PD                       
-GPIOEXT20  = MODE0(GPIO20)          MODE1(ROW0)                   MODE2(EINT18_1X)         MODE3(SCL0_3X)           MODE4()                       MODE5()                 MODE6(TEST_IN11)        MODE7(TEST_OUT11)       PD                       
-GPIOEXT21  = MODE0(GPIO21)          MODE1(ROW1)                   MODE2(EINT19_1X)         MODE3(SDA0_3X)           MODE4(AUD_TSTCK)              MODE5()                 MODE6(TEST_IN12)        MODE7(TEST_OUT12)       PD                       
-GPIOEXT22  = MODE0(GPIO22)          MODE1(ROW2)                   MODE2(EINT20_1X)         MODE3(SCL1_3X)           MODE4()                       MODE5()                 MODE6(TEST_IN13)        MODE7(TEST_OUT13)       PD                       
-GPIOEXT23  = MODE0(GPIO23)          MODE1(ROW3)                   MODE2(EINT21_1X)         MODE3(SDA1_3X)           MODE4()                       MODE5()                 MODE6(TEST_IN14)        MODE7(TEST_OUT14)       PD                       
-GPIOEXT24  = MODE0(GPIO24)          MODE1(ROW4)                   MODE2(EINT22_1X)         MODE3(SCL2_3X)           MODE4()                       MODE5()                 MODE6(TEST_IN15)        MODE7(TEST_OUT15)       PD                       
-GPIOEXT25  = MODE0(GPIO25)          MODE1(ROW5)                   MODE2(EINT23_1X)         MODE3(SDA2_3X)           MODE4()                       MODE5()                 MODE6(TEST_IN16)        MODE7(TEST_OUT16)       PD                       
-GPIOEXT26  = MODE0(GPIO26)          MODE1(ROW6)                   MODE2(EINT24_1X)         MODE3(PWM3_3X)           MODE4(GPIO32K_2)              MODE5(GPIO26M_2)        MODE6(TEST_IN17)        MODE7(TEST_OUT17)       PD                       
-GPIOEXT27  = MODE0(GPIO27)          MODE1(ROW7)                   MODE2(EINT3_1X)          MODE3(CBUS)              MODE4(GPIO32K_3)              MODE5(GPIO26M_3)        MODE6(TEST_IN18)        MODE7(TEST_OUT18)       PD                       
-GPIOEXT28  = MODE0(GPIO28)          MODE1(PWM1)                   MODE2(EINT4_1X)          MODE3()                  MODE4(GPIO32K_4)              MODE5(GPIO26M_4)        MODE6(TEST_IN19)        MODE7(TEST_OUT19)       PD                       
-GPIOEXT29  = MODE0(GPIO29)          MODE1(PWM2)                   MODE2(EINT5_1X)          MODE3()                  MODE4(GPIO32K_5)              MODE5(GPIO26M_5)        MODE6(TEST_IN20)        MODE7(TEST_OUT20)       PD                       
-GPIOEXT30  = MODE0(GPIO30)          MODE1(PWM3)                   MODE2(EINT6_1X)          MODE3(COL0)              MODE4(GPIO32K_6)              MODE5(GPIO26M_6)        MODE6(TEST_IN21)        MODE7(TEST_OUT21)       PD                       
-GPIOEXT31  = MODE0(GPIO31)          MODE1(SCL0)                   MODE2(EINT7_1X)          MODE3(PWM1_2X)           MODE4()                           MODE5()                 MODE6(TEST_IN22)        MODE7(TEST_OUT22)       PU                       
-GPIOEXT32  = MODE0(GPIO32)          MODE1(SDA0)                   MODE2(EINT8_1X)          MODE3()                  MODE4()                       MODE5()                 MODE6(TEST_IN23)        MODE7(TEST_OUT23)       PU                       
-GPIOEXT33  = MODE0(GPIO33)          MODE1(SCL1)                   MODE2(EINT9_1X)          MODE3(PWM2_2X)           MODE4()                       MODE5()                 MODE6(TEST_IN24)        MODE7(TEST_OUT24)       PU                       
-GPIOEXT34  = MODE0(GPIO34)          MODE1(SDA1)                   MODE2(EINT0_1X)          MODE3()                  MODE4()                       MODE5()                 MODE6(TEST_IN25)        MODE7(TEST_OUT25)       PU                       
-GPIOEXT35  = MODE0(GPIO35)          MODE1(SCL2)                   MODE2(EINT1_1X)          MODE3(PWM3_2X)           MODE4()                       MODE5()                 MODE6(TEST_IN26)        MODE7(TEST_OUT26)       PU                       
-GPIOEXT36  = MODE0(GPIO36)          MODE1(SDA2)                   MODE2(EINT2_1X)          MODE3()                  MODE4()                       MODE5()                 MODE6(TEST_IN27)        MODE7(TEST_OUT27)       PU                       
-GPIOEXT37  = MODE0(GPIO37)          MODE1(HDMISD)                 MODE2()                  MODE3()                  MODE4()                       MODE5()                 MODE6(TEST_IN28)        MODE7(TEST_OUT28)       PU/PD                    
-GPIOEXT38  = MODE0(GPIO38)          MODE1(HDMISCK)                MODE2()                  MODE3()                  MODE4()                       MODE5()                 MODE6(TEST_IN29)        MODE7(TEST_OUT29)       PU/PD                    
-GPIOEXT39  = MODE0(GPIO39)          MODE1(HTPLG)                  MODE2()                  MODE3()                  MODE4()                       MODE5()                 MODE6(TEST_IN30)        MODE7(TEST_OUT30)       PU/PD                    
-GPIOEXT40  = MODE0(GPIO40)          MODE1(CEC)                    MODE2()                  MODE3()                  MODE4()                       MODE5()                 MODE6(TEST_IN31)        MODE7(TEST_OUT31)       PU/PD                    
-
-[GPO]  
-
-[EINT] 
-EINT_COUNT = 133
-EINT_DEBOUNCE_TIME_COUNT = 12 
-[EINT_EXT]
-EINT_EXT_COUNT = 25
-EINT_EXT_DEBOUNCE_TIME_COUNT = 12
-
-[ADC]
-ADC_COUNT = 6
-
-[ADC_EX_PIN]
-0
-1
-12
-13
-14
-15
-
-[ADC_EX_PIN]  
-
-[KEYPAD] 
-KEY_ROW = 8
-KEY_COLUMN = 9
-
-[I2C]
-I2C_COUNT = 32
-CHANNEL_COUNT = 6
-
-[CLK_BUF]
-CLK_BUF_COUNT = 4
-
-[POWER]
-AVDD10_SSUSB
-AVDD18_AP
-AVDD18_ARMPLL
-AVDD18_HDMITX
-AVDD18_MEMPLL_A
-AVDD18_MEMPLL_B
-AVDD18_MIPIRX0
-AVDD18_MIPIRX1
-AVDD18_MIPITX1
-AVDD18_MIPITX2
-AVDD18_PLLGP
-AVDD18_SSUSB
-AVDD18_USB_P0
-AVDD18_USB_P1
-AVDD33_USB_P0
-AVDD33_USB_P1
-DDRV_A_1
-DDRV_A_2
-DDRV_A_3
-DDRV_A_4
-DDRV_B_1
-DDRV_B_2
-DDRV_B_3
-DDRV_B_4
-DVDD_CORE
-DVDD_CORE_1
-DVDD_CORE_2
-DVDD_CORE_3
-DVDD_CORE_4
-DVDD_CORE_5
-DVDD_CORE_6
-DVDD_CORE_7
-DVDD_CORE_8
-DVDD_CORE_9
-DVDD_DVFS1
-DVDD_DVFS2
-DVDD_GPU
-DVDD_SRAM1
-DVDD_SRAM2
-DVDD18_EFUSE
-VCC12IO_HSIC
-VCC18IO_0
-VCC18IO_0_CONN
-VCC18IO_0_MSDC3
-VCC18IO_2
-VCC18IO_4
-VCC18IO_5
-VCC18IO_6
-VCC18IO_8
-VCC18IO_EINT
-VCC18IO_MC1
-VCC18IO_MC2
-VCC33IO_MC1
-VCC33IO_MC2
-VCC33IO_NAND
-
-[AVDD10_SSUSB]
-VCC1V0
-
-[AVDD18_AP]
-VIO18
-
-[AVDD18_ARMPLL]
-VIO18
-
-[AVDD18_HDMITX]
-VIO18
-
-[AVDD18_MEMPLL_A]
-VIO18
-
-[AVDD18_MEMPLL_B]
-VIO18
-
-[AVDD18_MIPIRX0]
-VIO18
-
-[AVDD18_MIPIRX1]
-VIO18
-
-[AVDD18_MIPITX1]
-VIO18
-
-[AVDD18_MIPITX2]
-VIO18
-
-[AVDD18_PLLGP]
-VIO18
-
-[AVDD18_SSUSB]
-VIO18
-
-[AVDD18_USB_P0]
-VIO18
-
-[AVDD18_USB_P1]
-VIO18
-
-[AVDD33_USB_P0]
-VUSB
-
-[AVDD33_USB_P1]
-VUSB
-
-[DDRV_A_1]
-VM
-
-[DDRV_A_2]
-VM
-
-[DDRV_A_3]
-VM
-
-[DDRV_A_4]
-VM
-
-[DDRV_B_1]
-VM
-
-[DDRV_B_2]
-VM
-
-[DDRV_B_3]
-VM
-
-[DDRV_B_4]
-VM
-
-[DVDD_CORE]
-VCORE
-
-[DVDD_CORE_1]
-VCORE
-
-[DVDD_CORE_2]
-VCORE
-
-[DVDD_CORE_3]
-VCORE
-
-[DVDD_CORE_4]
-VCORE
-
-[DVDD_CORE_5]
-VCORE
-
-[DVDD_CORE_6]
-VCORE
-
-[DVDD_CORE_7]
-VCORE
-
-[DVDD_CORE_8]
-VCORE
-
-[DVDD_CORE_9]
-VCORE
-
-[DVDD_DVFS1]
-VDVFS1
-
-[DVDD_DVFS2]
-VDVFS2
-
-[DVDD_GPU]
-VGPU
-
-[DVDD_SRAM1]
-VSRAMCA15
-
-[DVDD_SRAM2]
-VSRAMCA7
-
-[DVDD18_EFUSE]
-VIO18
-
-[VCC12IO_HSIC]
-VGP4
-
-[VCC18IO_0]
-VIO18
-
-[VCC18IO_0_CONN]
-VIO18
-
-[VCC18IO_0_MSDC3]
-VIO18
-
-[VCC18IO_2]
-VIO18
-
-[VCC18IO_4]
-VIO18
-
-[VCC18IO_5]
-VIO18
-
-[VCC18IO_6]
-VIO18
-
-[VCC18IO_8]
-VIO18
-
-[VCC18IO_EINT]
-VIO18
-
-[VCC18IO_MC1]
-VIO18
-
-[VCC18IO_MC2]
-VIO18
-
-[VCC33IO_MC1]
-VMC
-
-[VCC33IO_MC2]
-VMC
-
-[VCC33IO_NAND]
-VMC
-