Initial commit: Linux kernel 4.19 for Unplugged OS

This commit is contained in:
ziv committed 2025-10-06 13:52:42 +00:00
commit d30235b04c
80519 files changed
+35800681

No files matched your search

+279
View File
@@ -0,0 +1,279 @@
config MTK_LENS
tristate "Mediatek lens driver"
help
This is lens driver for camera
Say Y here if you want to enable lens driver.
If you have any questions about this, say Y here,
only say N if you know exactly what you are doing.
#
# LENS
#
config MTK_LENS_DUMMYLENS_SUPPORT
tristate "Dummy Lens Driver"
depends on MTK_LENS
help
Dummy Lens Driver
This config is used to enable the corresponding
lens driver for the camera sensor module
Set as y if the driver is used in this project
config MTK_LENS_BU63165AF_SUPPORT
tristate "BU63165AF Lens Driver"
depends on MTK_LENS
help
BU63165AF Lens Driver
This config is used to enable the corresponding
lens driver for the camera sensor module
Set as y if the driver is used in this project
config MTK_LENS_BU63169AF_SUPPORT
tristate "BU63169AF Lens Driver"
depends on MTK_LENS
help
BU63169AF Lens Driver
This config is used to enable the corresponding
lens driver for the camera sensor module
Set as y if the driver is used in this project
config MTK_LENS_AD5820AF_SUPPORT
tristate "AD5820AF Lens Driver"
depends on MTK_LENS
help
AD5820AF Lens Driver
This config is used to enable the corresponding
lens driver for the camera sensor module
Set as y if the driver is used in this project
config MTK_LENS_AD5823_SUPPORT
tristate "AD5823 Lens Driver"
depends on MTK_LENS
help
AD5823 Lens Driver
This config is used to enable the corresponding
lens driver for the camera sensor module
Set as y if the driver is used in this project
config MTK_LENS_AD5823AF_SUPPORT
tristate "AD5823AF Lens Driver"
depends on MTK_LENS
help
AD5823AF Lens Driver
This config is used to enable the corresponding
lens driver for the camera sensor module
Set as y if the driver is used in this project
config MTK_LENS_AK7345AF_SUPPORT
tristate "AK7345AF Lens Driver"
depends on MTK_LENS
help
AK7345AF Lens Driver
This config is used to enable the corresponding
lens driver for the camera sensor module
Set as y if the driver is used in this project
config MTK_LENS_AK7371AF_SUPPORT
tristate "AK7371AF Lens Driver"
depends on MTK_LENS
help
AK7371AF Lens Driver
This config is used to enable the corresponding
lens driver for the camera sensor module
Set as y if the driver is used in this project
config MTK_LENS_BU6424AF_SUPPORT
tristate "BU6424AF Lens Driver"
depends on MTK_LENS
help
BU6424AF Lens Driver
This config is used to enable the corresponding
lens driver for the camera sensor module
Set as y if the driver is used in this project
config MTK_LENS_BU6429AF_SUPPORT
tristate "BU6429AF Lens Driver"
depends on MTK_LENS
help
BU6429AF Lens Driver
This config is used to enable the corresponding
lens driver for the camera sensor module
Set as y if the driver is used in this project
config MTK_LENS_BU64745GWZAF_SUPPORT
tristate "BU64745GWZAF Lens Driver"
depends on MTK_LENS
help
BU64745GWZAF Lens Driver
This config is used to enable the corresponding
lens driver for the camera sensor module
Set as y if the driver is used in this project
config MTK_LENS_AK7345AF_SUPPORT
tristate "AK7345AF Lens Driver"
depends on MTK_LENS
help
AK7345AF Lens Driver
This config is used to enable the corresponding
lens driver for the camera sensor module
Set as y if the driver is used in this project
config MTK_LENS_DW9718AF_SUPPORT
tristate "DW9718AF Lens Driver"
depends on MTK_LENS
help
DW9718AF Lens Driver
This config is used to enable the corresponding
lens driver for the camera sensor module
Set as y if the driver is used in this project
config MTK_LENS_DW9718SAF_SUPPORT
tristate "DW9718SAF Lens Driver"
depends on MTK_LENS
help
DW9718SAF Lens Driver
This config is used to enable the corresponding
lens driver for the camera sensor module
Set as y if the driver is used in this project
config MTK_LENS_DW9714AF_SUPPORT
tristate "DW9714AF Lens Driver"
depends on MTK_LENS
help
DW9714AF Lens Driver
This config is used to enable the corresponding
lens driver for the camera sensor module
Set as y if the driver is used in this project
config MTK_LENS_DW9714A_SUPPORT
tristate "DW9714A Lens Driver"
depends on MTK_LENS
help
DW9714A Lens Driver
This config is used to enable the corresponding
lens driver for the camera sensor module
Set as y if the driver is used in this project
config MTK_LENS_DW9814AF_SUPPORT
tristate "DW9814AF Lens Driver"
depends on MTK_LENS
help
DW9814AF Lens Driver
This config is used to enable the corresponding
lens driver for the camera sensor module
Set as y if the driver is used in this project
config MTK_LENS_LC898122AF_SUPPORT
tristate "LC898122AF Lens Driver"
depends on MTK_LENS
help
LC898122AF Lens Driver
This config is used to enable the corresponding
lens driver for the camera sensor module
Set as y if the driver is used in this project
config MTK_LENS_LC898212AF_SUPPORT
tristate "LC898212AF Lens Driver"
depends on MTK_LENS
help
LC898212AF Lens Driver
This config is used to enable the corresponding
lens driver for the camera sensor module
Set as y if the driver is used in this project
config MTK_LENS_LC898212XDAF_SUPPORT
tristate "LC898212XDAF Lens Driver"
depends on MTK_LENS
help
LC898212XDAF Lens Driver
This config is used to enable the corresponding
lens driver for the camera sensor module
Set as y if the driver is used in this project
config MTK_LENS_LC898214AF_SUPPORT
tristate "LC898214AF Lens Driver"
depends on MTK_LENS
help
LC898212AF Lens Driver
This config is used to enable the corresponding
lens driver for the camera sensor module
Set as y if the driver is used in this project
config MTK_LENS_FM50AF_SUPPORT
tristate "FM50AF Lens Driver"
depends on MTK_LENS
help
FM50AF Lens Driver
This config is used to enable the corresponding
lens driver for the camera sensor module
Set as y if the driver is used in this project
config MTK_LENS_FP5510E2AF_SUPPORT
tristate "FP5510E2AF Lens Driver"
depends on MTK_LENS
help
FM50AF Lens Driver
This config is used to enable the corresponding
lens driver for the camera sensor module
Set as y if the driver is used in this project
config MTK_LENS_MT9P017AF_SUPPORT
tristate "MT9P017AF Lens Driver"
help
MT9P017AF Lens Driver
This config is used to enable the corresponding
lens driver for the camera sensor module
Set as y if the driver is used in this project
config MTK_LENS_OV8825AF_SUPPORT
tristate "OV8825AF Lens Driver"
depends on MTK_LENS
help
OV8825AF Lens Driver
This config is used to enable the corresponding
lens driver for the camera sensor module
Set as y if the driver is used in this project
config MTK_LENS_SENSORDRIVE_SUPPORT
tristate "SENSORDRIVE Lens Driver"
depends on MTK_LENS
help
SENSORDRIVE Lens Driver
This config is used to enable the corresponding
lens driver for the camera sensor module
Set as y if the driver is used in this project
config MTK_LENS_GAF001AF_SUPPORT
tristate "GAF001AF Lens Driver"
help
GAF001AF Lens Driver
This config is used to enable the corresponding
lens driver for the camera sensor module
Set as y if the driver is used in this project
config MTK_LENS_GAF002AF_SUPPORT
tristate "GAF002AF Lens Driver"
depends on MTK_LENS
help
GAF002AF Lens Driver
This config is used to enable the corresponding
lens driver for the camera sensor module
Set as y if the driver is used in this project
config MTK_LENS_GAF008AF_SUPPORT
tristate "GAF008AF Lens Driver"
depends on MTK_LENS
help
GAF008AF Lens Driver
This config is used to enable the corresponding
lens driver for the camera sensor module
Set as y if the driver is used in this project
config MTK_LENS_WV511AAF_SUPPORT
tristate "WV511AAF Lens Driver"
depends on MTK_LENS
help
WV511AAF Lens Driver
This config is used to enable the corresponding
lens driver for the camera sensor module
Set as y if the driver is used in this project
+21
View File
@@ -0,0 +1,21 @@
#
# Makefile for misc devices that really don't fit anywhere else.
#
ifdef CONFIG_MTK_V4L2_LENS
obj-$(CONFIG_MTK_V4L2_LENS) += v4l2/
else
obj-$(CONFIG_MTK_LENS) += mtk/main/
obj-$(CONFIG_MTK_LENS) += mtk/main2/
ifeq ($(CONFIG_MACH_MT6761), y)
ifeq ($(CONFIG_EXTREME_LOW_RAM), y)
else
obj-$(CONFIG_MTK_LENS) += mtk/main3/
obj-$(CONFIG_MTK_LENS) += mtk/sub2/
endif
else
obj-$(CONFIG_MTK_LENS) += mtk/main3/
obj-$(CONFIG_MTK_LENS) += mtk/sub2/
endif
obj-$(CONFIG_MTK_LENS) += mtk/sub/
endif
@@ -0,0 +1,78 @@
#
# Copyright (C) 2015 MediaTek Inc.
#
# 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.
#
#
# Makefile for misc devices that really don't fit anywhere else.
#
MTK_PLATFORM := $(subst ",,$(CONFIG_MTK_PLATFORM))
ARCH_MTK_PROJECT := $(subst ",,$(CONFIG_ARCH_MTK_PROJECT))
MTK_CUSTOM_PATH := $(srctree)/drivers/misc/mediatek
subdir-ccflags-y += -I$(MTK_CUSTOM_PATH)/lens/mtk/main/inc
subdir-ccflags-y += -I$(MTK_CUSTOM_PATH)/lens/mtk/main/common/lc898122af
subdir-ccflags-y += -I$(MTK_CUSTOM_PATH)/lens/mtk/main/common/lc898212xdaf/inc
ifeq ($(CONFIG_MTK_LENS_BU63165AF_SUPPORT), y)
subdir-ccflags-y += -I$(MTK_CUSTOM_PATH)/lens/mtk/main/common/bu63165af/inc
else
subdir-ccflags-y += -I$(MTK_CUSTOM_PATH)/lens/mtk/main/common/bu63169af/inc
endif
ifeq ($(CONFIG_MACH_MT6779), y)
ccflags-y += -I$(srctree)/drivers/misc/mediatek/timer/timesync/
endif
obj-$(CONFIG_MTK_LENS) += mainaf.o
mainaf-y += main_lens.o
mainaf-y += common/fp5510e2af/FP5510E2AF.o
mainaf-y += common/bu6424af/BU6424AF.o
mainaf-y += common/bu6429af/BU6429AF.o
mainaf-y += common/bu64748af/bu64748_function.o
mainaf-y += common/bu64748af/bu64748af.o
mainaf-y += common/dw9714af/DW9714AF.o
mainaf-y += common/dw9800waf/DW9800WAF.o
mainaf-y += common/dw9814af/DW9814AF.o
mainaf-y += common/dw9718af/DW9718AF.o
mainaf-y += common/dw9718gaf/DW9718AF.o
mainaf-y += common/dw9718saf/DW9718SAF.o
mainaf-y += common/dw9718taf/DW9718TAF.o
mainaf-y += common/dw9719taf/DW9719TAF.o
mainaf-y += common/dw9763af/DW9763AF.o
mainaf-y += common/dw9839af/DW9839AF.o
mainaf-y += common/gt9764af/GT9764AF.o
mainaf-y += common/lc898212af/LC898212AF.o
mainaf-y += common/lc898212xdaf/LC898212XDAF.o
mainaf-y += common/lc898212xdaf/AfInter.o
mainaf-y += common/lc898212xdaf/AfInit.o
mainaf-y += common/lc898212xdaf/AfSTMV.o
mainaf-y += common/lc898214af/LC898214AF.o
mainaf-y += common/lc898217af/LC898217AF.o
mainaf-y += common/lc898217afa/LC898217AFA.o
mainaf-y += common/lc898217afb/LC898217AFB.o
mainaf-y += common/lc898217afc/LC898217AFC.o
mainaf-y += common/lc898229af/LC898229AF.o
mainaf-y += common/lc898122af/LC898122AF.o
mainaf-y += common/lc898122af/OisCmd.o
mainaf-y += common/lc898122af/OisIni.o
mainaf-y += common/wv511aaf/WV511AAF.o
mainaf-y += common/ak7371af/AK7371AF.o
mainaf-y += common/bu63169af/BU63169AF.o
mainaf-y += common/bu63169af/OIS_func.o
mainaf-y += common/bu63169af/OIS_main.o
mainaf-y += common/bu63169af/OIS_user.o
mainaf-y += common/bu64253gwzaf/BU64253GWZAF.o
mainaf-y += common/gt9768af/GT9768AF.o
mainaf-y += common/gt9772af/GT9772AF.o
@@ -0,0 +1,224 @@
// SPDX-License-Identifier: GPL-2.0
/*
* Copyright (c) 2019 MediaTek Inc.
*/
/*
* AD5820AF voice coil motor driver
*
*
*/
#include <linux/delay.h>
#include <linux/fs.h>
#include <linux/i2c.h>
#include <linux/uaccess.h>
#include "lens_info.h"
#define AF_DRVNAME "AD5820AF_DRV"
#define AF_I2C_SLAVE_ADDR 0x18
#define AF_DEBUG
#ifdef AF_DEBUG
#define LOG_INF(format, args...) \
pr_debug(AF_DRVNAME " [%s] " format, __func__, ##args)
#else
#define LOG_INF(format, args...)
#endif
static struct i2c_client *g_pstAF_I2Cclient;
static int *g_pAF_Opened;
static spinlock_t *g_pAF_SpinLock;
static unsigned long g_u4AF_INF;
static unsigned long g_u4AF_MACRO = 1023;
static unsigned long g_u4CurrPosition;
static int s4AF_WriteReg(u16 a_u2Data)
{
int i4RetValue = 0;
char puSendCmd[2] = {(char)(a_u2Data >> 4),
(char)((a_u2Data & 0xF) << 4)};
g_pstAF_I2Cclient->addr = AF_I2C_SLAVE_ADDR;
g_pstAF_I2Cclient->addr = g_pstAF_I2Cclient->addr >> 1;
i4RetValue = i2c_master_send(g_pstAF_I2Cclient, puSendCmd, 2);
if (i4RetValue < 0) {
LOG_INF("I2C send failed!!\n");
return -1;
}
return 0;
}
static inline int getAFInfo(__user struct stAF_MotorInfo *pstMotorInfo)
{
struct stAF_MotorInfo stMotorInfo;
stMotorInfo.u4MacroPosition = g_u4AF_MACRO;
stMotorInfo.u4InfPosition = g_u4AF_INF;
stMotorInfo.u4CurrentPosition = g_u4CurrPosition;
stMotorInfo.bIsSupportSR = 1;
stMotorInfo.bIsMotorMoving = 1;
if (*g_pAF_Opened >= 1)
stMotorInfo.bIsMotorOpen = 1;
else
stMotorInfo.bIsMotorOpen = 0;
if (copy_to_user(pstMotorInfo, &stMotorInfo,
sizeof(struct stAF_MotorInfo)))
LOG_INF("copy to user failed when getting motor information\n");
return 0;
}
/* initAF include driver initialization and standby mode */
static int initAF(void)
{
LOG_INF("+\n");
if (*g_pAF_Opened == 1) {
spin_lock(g_pAF_SpinLock);
*g_pAF_Opened = 2;
spin_unlock(g_pAF_SpinLock);
}
LOG_INF("-\n");
return 0;
}
/* moveAF only use to control moving the motor */
static inline int moveAF(unsigned long a_u4Position)
{
int ret = 0;
if (s4AF_WriteReg((unsigned short)a_u4Position) == 0) {
g_u4CurrPosition = a_u4Position;
ret = 0;
} else {
LOG_INF("set I2C failed when moving the motor\n");
ret = -1;
}
return ret;
}
static inline int setAFInf(unsigned long a_u4Position)
{
spin_lock(g_pAF_SpinLock);
g_u4AF_INF = a_u4Position;
spin_unlock(g_pAF_SpinLock);
return 0;
}
static inline int setAFMacro(unsigned long a_u4Position)
{
spin_lock(g_pAF_SpinLock);
g_u4AF_MACRO = a_u4Position;
spin_unlock(g_pAF_SpinLock);
return 0;
}
/* ////////////////////////////////////////////////////////////// */
long AD5820AF_Ioctl(struct file *a_pstFile, unsigned int a_u4Command,
unsigned long a_u4Param)
{
long i4RetValue = 0;
switch (a_u4Command) {
case AFIOC_G_MOTORINFO:
i4RetValue =
getAFInfo((__user struct stAF_MotorInfo *)(a_u4Param));
break;
case AFIOC_T_MOVETO:
i4RetValue = moveAF(a_u4Param);
break;
case AFIOC_T_SETINFPOS:
i4RetValue = setAFInf(a_u4Param);
break;
case AFIOC_T_SETMACROPOS:
i4RetValue = setAFMacro(a_u4Param);
break;
default:
LOG_INF("No CMD\n");
i4RetValue = -EPERM;
break;
}
return i4RetValue;
}
/* Main jobs: */
/* 1.Deallocate anything that "open" allocated in private_data. */
/* 2.Shut down the device on last close. */
/* 3.Only called once on last time. */
/* Q1 : Try release multiple times. */
int AD5820AF_Release(struct inode *a_pstInode, struct file *a_pstFile)
{
LOG_INF("Start\n");
if (*g_pAF_Opened == 2) {
LOG_INF("Wait\n");
s4AF_WriteReg(200);
msleep(20);
s4AF_WriteReg(100);
msleep(20);
}
if (*g_pAF_Opened) {
LOG_INF("Free\n");
spin_lock(g_pAF_SpinLock);
*g_pAF_Opened = 0;
spin_unlock(g_pAF_SpinLock);
}
LOG_INF("End\n");
return 0;
}
int AD5820AF_SetI2Cclient(struct i2c_client *pstAF_I2Cclient,
spinlock_t *pAF_SpinLock, int *pAF_Opened)
{
g_pstAF_I2Cclient = pstAF_I2Cclient;
g_pAF_SpinLock = pAF_SpinLock;
g_pAF_Opened = pAF_Opened;
initAF();
return 1;
}
int AD5820AF_GetFileName(unsigned char *pFileName)
{
#if SUPPORT_GETTING_LENS_FOLDER_NAME
char FilePath[256];
char *FileString;
sprintf(FilePath, "%s", __FILE__);
FileString = strrchr(FilePath, '/');
*FileString = '\0';
FileString = (strrchr(FilePath, '/') + 1);
strncpy(pFileName, FileString, AF_MOTOR_NAME);
LOG_INF("FileName : %s\n", pFileName);
#else
pFileName[0] = '\0';
#endif
return 1;
}
@@ -0,0 +1,20 @@
#
# Copyright (C) 2015 MediaTek Inc.
#
# 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.
#
#
# Makefile for misc devices that really don't fit anywhere else.
#
obj-y += AD5820AF.o
@@ -0,0 +1,289 @@
// SPDX-License-Identifier: GPL-2.0
/*
* Copyright (c) 2019 MediaTek Inc.
*/
/*
* AD5823AF voice coil motor driver
*
*
*/
#include <linux/delay.h>
#include <linux/fs.h>
#include <linux/i2c.h>
#include <linux/uaccess.h>
#include "lens_info.h"
#define AF_DRVNAME "AD5823AF_DRV"
#define AF_I2C_SLAVE_ADDR 0x0C
#define AF_DEBUG
#ifdef AF_DEBUG
#define LOG_INF(format, args...) \
pr_debug(AF_DRVNAME " [%s] " format, __func__, ##args)
#else
#define LOG_INF(format, args...)
#endif
static struct i2c_client *g_pstAF_I2Cclient;
static int *g_pAF_Opened;
static spinlock_t *g_pAF_SpinLock;
static unsigned long g_u4AF_INF;
static unsigned long g_u4AF_MACRO = 1023;
static unsigned long g_u4CurrPosition;
static int s4AF_ReadReg(unsigned short *a_pu2Result)
{
int i4RetValue = 0;
char pBuff[2];
char VCMMSB[1] = {(char)(0x04)};
char VCMLSB[1] = {(char)(0x05)};
g_pstAF_I2Cclient->addr = AF_I2C_SLAVE_ADDR;
g_pstAF_I2Cclient->addr = g_pstAF_I2Cclient->addr >> 1;
/* Read MSB */
i4RetValue = i2c_master_send(g_pstAF_I2Cclient, VCMMSB, 1);
if (i4RetValue < 0) {
LOG_INF("I2C read MSB send failed!!\n");
return -1;
}
i4RetValue = i2c_master_recv(g_pstAF_I2Cclient, &pBuff[1], 1);
if (i4RetValue < 0) {
LOG_INF("I2C read MSB recv failed!!\n");
return -1;
}
/* Read LSB */
i4RetValue = i2c_master_send(g_pstAF_I2Cclient, VCMLSB, 1);
if (i4RetValue < 0) {
LOG_INF("I2C read LSB send failed!!\n");
return -1;
}
i4RetValue = i2c_master_recv(g_pstAF_I2Cclient, &pBuff[0], 1);
if (i4RetValue < 0) {
LOG_INF("I2C read LSB recv failed!!\n");
return -1;
}
*a_pu2Result = ((u16)pBuff[0] + (u16)(pBuff[1] << 8));
return 0;
}
static int s4AF_WriteReg(u16 a_u2Data)
{
int i4RetValue = 0;
/* 0x04[1:0] VCM MSB data */
/* 0x05[7:0] VCM LSB data */
char VCMMSB[2] = {(char)(0x04), (char)((a_u2Data >> 8) & 0x03)};
char VCMLSB[2] = {(char)(0x05), (char)(a_u2Data & 0xFF)};
g_pstAF_I2Cclient->addr = AF_I2C_SLAVE_ADDR;
g_pstAF_I2Cclient->addr = g_pstAF_I2Cclient->addr >> 1;
i4RetValue = i2c_master_send(g_pstAF_I2Cclient, VCMMSB, 2);
i4RetValue = i2c_master_send(g_pstAF_I2Cclient, VCMLSB, 2);
if (i4RetValue < 0) {
LOG_INF("I2C send failed!!\n");
return -1;
}
return 0;
}
static inline int getAFInfo(__user struct stAF_MotorInfo *pstMotorInfo)
{
struct stAF_MotorInfo stMotorInfo;
stMotorInfo.u4MacroPosition = g_u4AF_MACRO;
stMotorInfo.u4InfPosition = g_u4AF_INF;
stMotorInfo.u4CurrentPosition = g_u4CurrPosition;
stMotorInfo.bIsSupportSR = 1;
stMotorInfo.bIsMotorMoving = 1;
if (*g_pAF_Opened >= 1)
stMotorInfo.bIsMotorOpen = 1;
else
stMotorInfo.bIsMotorOpen = 0;
if (copy_to_user(pstMotorInfo, &stMotorInfo,
sizeof(struct stAF_MotorInfo)))
LOG_INF("copy to user failed when getting motor information\n");
return 0;
}
/* initAF include driver initialization and standby mode */
static int initAF(void)
{
LOG_INF("+\n");
if (*g_pAF_Opened == 1) {
int i4RetValue = 0;
char Mode[2] = {(char)(0x02), (char)(0x01)};
char MoveTime[2] = {(char)(0x03), (char)(0x4B)};
char VCMMSB[2] = {(char)(0x04), (char)(0x05)};
char VCMLSB[2] = {(char)(0x05), (char)(0x32)};
LOG_INF("mode_init : 0x02\n");
g_pstAF_I2Cclient->addr = AF_I2C_SLAVE_ADDR;
g_pstAF_I2Cclient->addr = g_pstAF_I2Cclient->addr >> 1;
i4RetValue = i2c_master_send(g_pstAF_I2Cclient, Mode, 2);
i4RetValue = i2c_master_send(g_pstAF_I2Cclient, MoveTime, 2);
i4RetValue = i2c_master_send(g_pstAF_I2Cclient, VCMMSB, 2);
i4RetValue = i2c_master_send(g_pstAF_I2Cclient, VCMLSB, 2);
spin_lock(g_pAF_SpinLock);
*g_pAF_Opened = 2;
spin_unlock(g_pAF_SpinLock);
}
LOG_INF("-\n");
return 0;
}
/* moveAF only use to control moving the motor */
static inline int moveAF(unsigned long a_u4Position)
{
int ret = 0;
if (s4AF_WriteReg((unsigned short)a_u4Position) == 0) {
g_u4CurrPosition = a_u4Position;
ret = 0;
} else {
LOG_INF("set I2C failed when moving the motor\n");
ret = -1;
}
return ret;
}
static inline int setAFInf(unsigned long a_u4Position)
{
spin_lock(g_pAF_SpinLock);
g_u4AF_INF = a_u4Position;
spin_unlock(g_pAF_SpinLock);
return 0;
}
static inline int setAFMacro(unsigned long a_u4Position)
{
spin_lock(g_pAF_SpinLock);
g_u4AF_MACRO = a_u4Position;
spin_unlock(g_pAF_SpinLock);
return 0;
}
/* ////////////////////////////////////////////////////////////// */
long AD5823AF_Ioctl(struct file *a_pstFile, unsigned int a_u4Command,
unsigned long a_u4Param)
{
long i4RetValue = 0;
switch (a_u4Command) {
case AFIOC_G_MOTORINFO:
i4RetValue =
getAFInfo((__user struct stAF_MotorInfo *)(a_u4Param));
break;
case AFIOC_T_MOVETO:
i4RetValue = moveAF(a_u4Param);
break;
case AFIOC_T_SETINFPOS:
i4RetValue = setAFInf(a_u4Param);
break;
case AFIOC_T_SETMACROPOS:
i4RetValue = setAFMacro(a_u4Param);
break;
default:
LOG_INF("No CMD\n");
i4RetValue = -EPERM;
break;
}
return i4RetValue;
}
/* Main jobs: */
/* 1.Deallocate anything that "open" allocated in private_data. */
/* 2.Shut down the device on last close. */
/* 3.Only called once on last time. */
/* Q1 : Try release multiple times. */
int AD5823AF_Release(struct inode *a_pstInode, struct file *a_pstFile)
{
LOG_INF("Start\n");
if (*g_pAF_Opened == 2) {
LOG_INF("Wait\n");
s4AF_WriteReg(200);
msleep(20);
s4AF_WriteReg(100);
msleep(20);
}
if (*g_pAF_Opened) {
LOG_INF("Free\n");
spin_lock(g_pAF_SpinLock);
*g_pAF_Opened = 0;
spin_unlock(g_pAF_SpinLock);
}
LOG_INF("End\n");
return 0;
}
int AD5823AF_SetI2Cclient(struct i2c_client *pstAF_I2Cclient,
spinlock_t *pAF_SpinLock, int *pAF_Opened)
{
g_pstAF_I2Cclient = pstAF_I2Cclient;
g_pAF_SpinLock = pAF_SpinLock;
g_pAF_Opened = pAF_Opened;
initAF();
return 1;
}
int AD5823AF_GetFileName(unsigned char *pFileName)
{
#if SUPPORT_GETTING_LENS_FOLDER_NAME
char FilePath[256];
char *FileString;
sprintf(FilePath, "%s", __FILE__);
FileString = strrchr(FilePath, '/');
*FileString = '\0';
FileString = (strrchr(FilePath, '/') + 1);
strncpy(pFileName, FileString, AF_MOTOR_NAME);
LOG_INF("FileName : %s\n", pFileName);
#else
pFileName[0] = '\0';
#endif
return 1;
}
@@ -0,0 +1,7 @@
#
# Makefile for misc devices that really don't fit anywhere else.
#
obj-y += AD5823AF.o
@@ -0,0 +1,255 @@
// SPDX-License-Identifier: GPL-2.0
/*
* Copyright (c) 2019 MediaTek Inc.
*/
/*
* AK7345AF voice coil motor driver
*
*
*/
#include <linux/delay.h>
#include <linux/fs.h>
#include <linux/i2c.h>
#include <linux/uaccess.h>
#include "lens_info.h"
#define AF_DRVNAME "AK7345AF_DRV"
#define AF_I2C_SLAVE_ADDR 0x18
#define AF_DEBUG
#ifdef AF_DEBUG
#define LOG_INF(format, args...) \
pr_debug(AF_DRVNAME " [%s] " format, __func__, ##args)
#else
#define LOG_INF(format, args...)
#endif
static struct i2c_client *g_pstAF_I2Cclient;
static int *g_pAF_Opened;
static spinlock_t *g_pAF_SpinLock;
static unsigned long g_u4AF_INF;
static unsigned long g_u4AF_MACRO = 1023;
static unsigned long g_u4CurrPosition;
static int s4AF_ReadReg(u16 a_u2Addr, u16 *a_pu2Result)
{
int i4RetValue = 0;
char pBuff;
g_pstAF_I2Cclient->addr = AF_I2C_SLAVE_ADDR;
g_pstAF_I2Cclient->addr = g_pstAF_I2Cclient->addr >> 1;
i4RetValue = i2c_master_send(g_pstAF_I2Cclient, &a_u2Addr, 1);
if (i4RetValue < 0) {
LOG_INF("I2C read - send failed!!\n");
return -1;
}
i4RetValue = i2c_master_recv(g_pstAF_I2Cclient, &pBuff, 1);
if (i4RetValue < 0) {
LOG_INF("I2C read - recv failed!!\n");
return -1;
}
*a_pu2Result = pBuff;
return 0;
}
static int s4AF_WriteReg(u16 a_u2Addr, u16 a_u2Data)
{
int i4RetValue = 0;
char puSendCmd[2] = {(char)a_u2Addr, (char)a_u2Data};
g_pstAF_I2Cclient->addr = AF_I2C_SLAVE_ADDR;
g_pstAF_I2Cclient->addr = g_pstAF_I2Cclient->addr >> 1;
i4RetValue = i2c_master_send(g_pstAF_I2Cclient, puSendCmd, 2);
if (i4RetValue < 0) {
LOG_INF("I2C write failed!!\n");
return -1;
}
return 0;
}
static inline int getAFInfo(__user struct stAF_MotorInfo *pstMotorInfo)
{
struct stAF_MotorInfo stMotorInfo;
stMotorInfo.u4MacroPosition = g_u4AF_MACRO;
stMotorInfo.u4InfPosition = g_u4AF_INF;
stMotorInfo.u4CurrentPosition = g_u4CurrPosition;
stMotorInfo.bIsSupportSR = 1;
stMotorInfo.bIsMotorMoving = 1;
if (*g_pAF_Opened >= 1)
stMotorInfo.bIsMotorOpen = 1;
else
stMotorInfo.bIsMotorOpen = 0;
if (copy_to_user(pstMotorInfo, &stMotorInfo,
sizeof(struct stAF_MotorInfo)))
LOG_INF("copy to user failed when getting motor information\n");
return 0;
}
/* initAF include driver initialization and standby mode */
static int initAF(void)
{
LOG_INF("+\n");
if (*g_pAF_Opened == 1) {
int ret = 0;
/* 00:active mode 10:Standby mode x1:Sleep mode */
ret = s4AF_WriteReg(0x02, 0x00);
spin_lock(g_pAF_SpinLock);
*g_pAF_Opened = 2;
spin_unlock(g_pAF_SpinLock);
}
LOG_INF("-\n");
return 0;
}
/* moveAF only use to control moving the motor */
static inline int moveAF(unsigned long a_u4Position)
{
int ret = 0;
s4AF_WriteReg(0x02, 0x00);
if (s4AF_WriteReg(0x0, (u16)((a_u4Position >> 2) & 0xff)) == 0 &&
s4AF_WriteReg(0x1, (u16)(((a_u4Position >> 1) & 1) << 7)) ==
0) {
g_u4CurrPosition = a_u4Position;
ret = 0;
} else {
LOG_INF("set I2C failed when moving the motor\n");
ret = -1;
}
return ret;
}
static inline int setAFInf(unsigned long a_u4Position)
{
spin_lock(g_pAF_SpinLock);
g_u4AF_INF = a_u4Position;
spin_unlock(g_pAF_SpinLock);
return 0;
}
static inline int setAFMacro(unsigned long a_u4Position)
{
spin_lock(g_pAF_SpinLock);
g_u4AF_MACRO = a_u4Position;
spin_unlock(g_pAF_SpinLock);
return 0;
}
/* ////////////////////////////////////////////////////////////// */
long AK7345AF_Ioctl(struct file *a_pstFile, unsigned int a_u4Command,
unsigned long a_u4Param)
{
long i4RetValue = 0;
switch (a_u4Command) {
case AFIOC_G_MOTORINFO:
i4RetValue =
getAFInfo((__user struct stAF_MotorInfo *)(a_u4Param));
break;
case AFIOC_T_MOVETO:
i4RetValue = moveAF(a_u4Param);
break;
case AFIOC_T_SETINFPOS:
i4RetValue = setAFInf(a_u4Param);
break;
case AFIOC_T_SETMACROPOS:
i4RetValue = setAFMacro(a_u4Param);
break;
default:
LOG_INF("No CMD\n");
i4RetValue = -EPERM;
break;
}
return i4RetValue;
}
/* Main jobs: */
/* 1.Deallocate anything that "open" allocated in private_data. */
/* 2.Shut down the device on last close. */
/* 3.Only called once on last time. */
/* Q1 : Try release multiple times. */
int AK7345AF_Release(struct inode *a_pstInode, struct file *a_pstFile)
{
LOG_INF("Start\n");
if (*g_pAF_Opened == 2) {
LOG_INF("Wait\n");
msleep(20);
}
if (*g_pAF_Opened) {
LOG_INF("Free\n");
spin_lock(g_pAF_SpinLock);
*g_pAF_Opened = 0;
spin_unlock(g_pAF_SpinLock);
}
LOG_INF("End\n");
return 0;
}
int AK7345AF_SetI2Cclient(struct i2c_client *pstAF_I2Cclient,
spinlock_t *pAF_SpinLock, int *pAF_Opened)
{
g_pstAF_I2Cclient = pstAF_I2Cclient;
g_pAF_SpinLock = pAF_SpinLock;
g_pAF_Opened = pAF_Opened;
initAF();
return 1;
}
int AK7345AF_GetFileName(unsigned char *pFileName)
{
#if SUPPORT_GETTING_LENS_FOLDER_NAME
char FilePath[256];
char *FileString;
sprintf(FilePath, "%s", __FILE__);
FileString = strrchr(FilePath, '/');
*FileString = '\0';
FileString = (strrchr(FilePath, '/') + 1);
strncpy(pFileName, FileString, AF_MOTOR_NAME);
LOG_INF("FileName : %s\n", pFileName);
#else
pFileName[0] = '\0';
#endif
return 1;
}
@@ -0,0 +1,7 @@
#
# Makefile for misc devices that really don't fit anywhere else.
#
obj-y += AK7345AF.o
@@ -0,0 +1,300 @@
// SPDX-License-Identifier: GPL-2.0
/*
* Copyright (c) 2019 MediaTek Inc.
*/
/*
* AK7371AF voice coil motor driver
*
*
*/
#include <linux/delay.h>
#include <linux/fs.h>
#include <linux/i2c.h>
#include <linux/uaccess.h>
#include "lens_info.h"
#define AF_DRVNAME "AK7371AF_DRV"
#define AF_I2C_SLAVE_ADDR 0x18
#define AF_DEBUG
#ifdef AF_DEBUG
#define LOG_INF(format, args...) \
pr_debug(AF_DRVNAME " [%s] " format, __func__, ##args)
#else
#define LOG_INF(format, args...)
#endif
static struct i2c_client *g_pstAF_I2Cclient;
static int *g_pAF_Opened;
static spinlock_t *g_pAF_SpinLock;
static unsigned long g_u4AF_INF;
static unsigned long g_u4AF_MACRO = 1023;
static unsigned long g_u4CurrPosition;
static int s4AF_ReadReg(u8 a_uAddr, u16 *a_pu2Result)
{
int i4RetValue = 0;
char pBuff;
char puSendCmd[1];
puSendCmd[0] = a_uAddr;
g_pstAF_I2Cclient->addr = AF_I2C_SLAVE_ADDR;
g_pstAF_I2Cclient->addr = g_pstAF_I2Cclient->addr >> 1;
i4RetValue = i2c_master_send(g_pstAF_I2Cclient, puSendCmd, 1);
if (i4RetValue < 0) {
LOG_INF("I2C read - send failed!!\n");
return -1;
}
i4RetValue = i2c_master_recv(g_pstAF_I2Cclient, &pBuff, 1);
if (i4RetValue < 0) {
LOG_INF("I2C read - recv failed!!\n");
return -1;
}
*a_pu2Result = pBuff;
return 0;
}
static int s4AF_WriteReg(u16 a_u2Addr, u16 a_u2Data)
{
int i4RetValue = 0;
char puSendCmd[2] = {(char)a_u2Addr, (char)a_u2Data};
g_pstAF_I2Cclient->addr = AF_I2C_SLAVE_ADDR;
g_pstAF_I2Cclient->addr = g_pstAF_I2Cclient->addr >> 1;
i4RetValue = i2c_master_send(g_pstAF_I2Cclient, puSendCmd, 2);
if (i4RetValue < 0) {
LOG_INF("I2C write failed!!\n");
return -1;
}
return 0;
}
static inline int getAFInfo(__user struct stAF_MotorInfo *pstMotorInfo)
{
struct stAF_MotorInfo stMotorInfo;
stMotorInfo.u4MacroPosition = g_u4AF_MACRO;
stMotorInfo.u4InfPosition = g_u4AF_INF;
stMotorInfo.u4CurrentPosition = g_u4CurrPosition;
stMotorInfo.bIsSupportSR = 1;
stMotorInfo.bIsMotorMoving = 1;
if (*g_pAF_Opened >= 1)
stMotorInfo.bIsMotorOpen = 1;
else
stMotorInfo.bIsMotorOpen = 0;
if (copy_to_user(pstMotorInfo, &stMotorInfo,
sizeof(struct stAF_MotorInfo)))
LOG_INF("copy to user failed when getting motor information\n");
return 0;
}
/* initAF include driver initialization and standby mode */
static int initAF(void)
{
LOG_INF("+\n");
if (*g_pAF_Opened == 1) {
int ret = 0;
/* 00:active mode , 10:Standby mode , x1:Sleep mode */
ret = s4AF_WriteReg(0x02, 0x00);
spin_lock(g_pAF_SpinLock);
*g_pAF_Opened = 2;
spin_unlock(g_pAF_SpinLock);
}
LOG_INF("-\n");
return 0;
}
static inline int setVCMPos(unsigned long a_u4Position)
{
int i4RetValue = 0;
i4RetValue = s4AF_WriteReg(0x0, (u16)((a_u4Position >> 2) & 0xff));
if (i4RetValue < 0)
return -1;
i4RetValue = s4AF_WriteReg(0x1, (u16)((a_u4Position & 0x3) << 6));
return i4RetValue;
}
/* moveAF only use to control moving the motor */
static inline int moveAF(unsigned long a_u4Position)
{
int ret = 0;
if (setVCMPos(a_u4Position) == 0) {
g_u4CurrPosition = a_u4Position;
ret = 0;
} else {
LOG_INF("set I2C failed when moving the motor\n");
ret = -1;
}
return ret;
}
static inline int setAFInf(unsigned long a_u4Position)
{
spin_lock(g_pAF_SpinLock);
g_u4AF_INF = a_u4Position;
spin_unlock(g_pAF_SpinLock);
return 0;
}
static inline int setAFMacro(unsigned long a_u4Position)
{
spin_lock(g_pAF_SpinLock);
g_u4AF_MACRO = a_u4Position;
spin_unlock(g_pAF_SpinLock);
return 0;
}
/* ////////////////////////////////////////////////////////////// */
long AK7371AF_Ioctl(struct file *a_pstFile, unsigned int a_u4Command,
unsigned long a_u4Param)
{
long i4RetValue = 0;
switch (a_u4Command) {
case AFIOC_G_MOTORINFO:
i4RetValue =
getAFInfo((__user struct stAF_MotorInfo *)(a_u4Param));
break;
case AFIOC_T_MOVETO:
i4RetValue = moveAF(a_u4Param);
break;
case AFIOC_T_SETINFPOS:
i4RetValue = setAFInf(a_u4Param);
break;
case AFIOC_T_SETMACROPOS:
i4RetValue = setAFMacro(a_u4Param);
break;
default:
LOG_INF("No CMD\n");
i4RetValue = -EPERM;
break;
}
return i4RetValue;
}
/* Main jobs: */
/* 1.Deallocate anything that "open" allocated in private_data. */
/* 2.Shut down the device on last close. */
/* 3.Only called once on last time. */
/* Q1 : Try release multiple times. */
int AK7371AF_Release(struct inode *a_pstInode, struct file *a_pstFile)
{
LOG_INF("Start\n");
if (*g_pAF_Opened == 2) {
LOG_INF("Wait\n");
s4AF_WriteReg(0x02, 0x20);
msleep(20);
}
if (*g_pAF_Opened) {
LOG_INF("Free\n");
spin_lock(g_pAF_SpinLock);
*g_pAF_Opened = 0;
spin_unlock(g_pAF_SpinLock);
}
LOG_INF("End\n");
return 0;
}
int AK7371AF_PowerDown(struct i2c_client *pstAF_I2Cclient,
int *pAF_Opened)
{
g_pstAF_I2Cclient = pstAF_I2Cclient;
g_pAF_Opened = pAF_Opened;
LOG_INF("+\n");
if (*g_pAF_Opened == 0) {
unsigned short data = 0;
int cnt = 0;
while (1) {
data = 0;
s4AF_WriteReg(0x02, 0x20);
s4AF_ReadReg(0x02, &data);
LOG_INF("Addr : 0x02 , Data : %x\n", data);
if (data == 0x20 || cnt == 1)
break;
cnt++;
}
}
LOG_INF("-\n");
return 0;
}
int AK7371AF_SetI2Cclient(struct i2c_client *pstAF_I2Cclient,
spinlock_t *pAF_SpinLock, int *pAF_Opened)
{
g_pstAF_I2Cclient = pstAF_I2Cclient;
g_pAF_SpinLock = pAF_SpinLock;
g_pAF_Opened = pAF_Opened;
initAF();
return 1;
}
int AK7371AF_GetFileName(unsigned char *pFileName)
{
#if SUPPORT_GETTING_LENS_FOLDER_NAME
char FilePath[256];
char *FileString;
sprintf(FilePath, "%s", __FILE__);
FileString = strrchr(FilePath, '/');
*FileString = '\0';
FileString = (strrchr(FilePath, '/') + 1);
strncpy(pFileName, FileString, AF_MOTOR_NAME);
LOG_INF("FileName : %s\n", pFileName);
#else
pFileName[0] = '\0';
#endif
return 1;
}
@@ -0,0 +1,7 @@
#
# Makefile for misc devices that really don't fit anywhere else.
#
obj-y += AK7371AF.o
@@ -0,0 +1,302 @@
// SPDX-License-Identifier: GPL-2.0
/*
* Copyright (c) 2019 MediaTek Inc.
*/
/*
* BU63165AF voice coil motor driver
*
*
*/
#include <linux/delay.h>
#include <linux/fs.h>
#include <linux/i2c.h>
#include <linux/uaccess.h>
#include "OIS_head.h"
#include "lens_info.h"
#define AF_DRVNAME "BU63165AF_DRV"
#define AF_I2C_SLAVE_ADDR 0x1c
#define EEPROM_I2C_SLAVE_ADDR 0xa0
#define AF_DEBUG
#ifdef AF_DEBUG
#define LOG_INF(format, args...) \
pr_debug(AF_DRVNAME " [%s] " format, __func__, ##args)
#else
#define LOG_INF(format, args...)
#endif
static struct i2c_client *g_pstAF_I2Cclient;
static int *g_pAF_Opened;
static spinlock_t *g_pAF_SpinLock;
static unsigned long g_u4AF_INF;
static unsigned long g_u4AF_MACRO = 1023;
static unsigned long g_u4CurrPosition;
int s4EEPROM_ReadReg_BU63165AF(u16 addr, u16 *data)
{
u8 u8data[2];
u8 pu_send_cmd[2] = {(u8)(addr >> 8), (u8)(addr & 0xFF)};
g_pstAF_I2Cclient->addr = (EEPROM_I2C_SLAVE_ADDR) >> 1;
if (i2c_master_send(g_pstAF_I2Cclient, pu_send_cmd, 2) < 0) {
LOG_INF("read I2C send failed!!\n");
return -1;
}
if (i2c_master_recv(g_pstAF_I2Cclient, u8data, 2) < 0) {
LOG_INF("EEPROM_ReadReg failed!!\n");
return -1;
}
LOG_INF("u8data[0] = 0x%x\n", u8data[0]);
LOG_INF("u8data[1] = 0x%x\n", u8data[1]);
*data = u8data[1] << 8 | u8data[0];
LOG_INF("s4EEPROM_ReadReg2 0x%x, 0x%x\n", addr, *data);
return 0;
}
int s4AF_WriteReg_BU63165AF(u16 i2c_id, u8 *a_pSendData, u16 a_sizeSendData)
{
int i4RetValue = 0;
spin_lock(g_pAF_SpinLock);
g_pstAF_I2Cclient->addr = i2c_id >> 1;
spin_unlock(g_pAF_SpinLock);
i4RetValue =
i2c_master_send(g_pstAF_I2Cclient, a_pSendData, a_sizeSendData);
if (i4RetValue != a_sizeSendData) {
LOG_INF("I2C send failed!!, Addr = 0x%x, Data = 0x%x\n",
a_pSendData[0], a_pSendData[1]);
return -1;
}
return 0;
}
int s4AF_ReadReg_BU63165AF(u16 i2c_id, u8 *a_pSendData, u16 a_sizeSendData,
u8 *a_pRecvData, u16 a_sizeRecvData)
{
int i4RetValue;
struct i2c_msg msg[2];
spin_lock(g_pAF_SpinLock);
g_pstAF_I2Cclient->addr = i2c_id >> 1;
spin_unlock(g_pAF_SpinLock);
msg[0].addr = g_pstAF_I2Cclient->addr;
msg[0].flags = 0;
msg[0].len = a_sizeSendData;
msg[0].buf = a_pSendData;
msg[1].addr = g_pstAF_I2Cclient->addr;
msg[1].flags = I2C_M_RD;
msg[1].len = a_sizeRecvData;
msg[1].buf = a_pRecvData;
i4RetValue =
i2c_transfer(g_pstAF_I2Cclient->adapter, msg, ARRAY_SIZE(msg));
if (i4RetValue != 2) {
LOG_INF("I2C Read failed!!\n");
return -1;
}
return 0;
}
static inline int getAFInfo(__user struct stAF_MotorInfo *pstMotorInfo)
{
struct stAF_MotorInfo stMotorInfo;
stMotorInfo.u4MacroPosition = g_u4AF_MACRO;
stMotorInfo.u4InfPosition = g_u4AF_INF;
stMotorInfo.u4CurrentPosition = g_u4CurrPosition;
stMotorInfo.bIsSupportSR = 1;
stMotorInfo.bIsMotorMoving = 1;
if (*g_pAF_Opened >= 1)
stMotorInfo.bIsMotorOpen = 1;
else
stMotorInfo.bIsMotorOpen = 0;
if (copy_to_user(pstMotorInfo, &stMotorInfo,
sizeof(struct stAF_MotorInfo)))
LOG_INF("copy to user failed when getting motor information\n");
return 0;
}
/* initAF include driver initialization and standby mode */
static int initAF(void)
{
LOG_INF("+\n");
if (*g_pAF_Opened == 1) {
Main_OIS();
spin_lock(g_pAF_SpinLock);
*g_pAF_Opened = 2;
spin_unlock(g_pAF_SpinLock);
}
LOG_INF("-\n");
return 0;
}
/* moveAF only use to control moving the motor */
static inline int moveAF(unsigned long a_u4Position)
{
int ret = 0;
if (setVCMPos((unsigned short)a_u4Position) == 0) {
g_u4CurrPosition = a_u4Position;
ret = 0;
} else {
LOG_INF("set I2C failed when moving the motor\n");
ret = -1;
}
return ret;
}
static inline int setAFInf(unsigned long a_u4Position)
{
spin_lock(g_pAF_SpinLock);
g_u4AF_INF = a_u4Position;
spin_unlock(g_pAF_SpinLock);
return 0;
}
static inline int setAFMacro(unsigned long a_u4Position)
{
spin_lock(g_pAF_SpinLock);
g_u4AF_MACRO = a_u4Position;
spin_unlock(g_pAF_SpinLock);
return 0;
}
static inline int setAFPara(__user struct stAF_MotorCmd *pstMotorCmd)
{
struct stAF_MotorCmd stMotorCmd;
if (copy_from_user(&stMotorCmd, pstMotorCmd, sizeof(stMotorCmd)))
LOG_INF("copy to user failed when getting motor command\n");
LOG_INF("Motor CmdID : %x\n", stMotorCmd.u4CmdID);
LOG_INF("Motor Param : %x\n", stMotorCmd.u4Param);
switch (stMotorCmd.u4CmdID) {
case 1:
setOISMode((int)stMotorCmd.u4Param); /* 1 : disable */
break;
}
return 0;
}
/* ////////////////////////////////////////////////////////////// */
long BU63165AF_Ioctl(struct file *a_pstFile, unsigned int a_u4Command,
unsigned long a_u4Param)
{
long i4RetValue = 0;
switch (a_u4Command) {
case AFIOC_G_MOTORINFO:
i4RetValue =
getAFInfo((__user struct stAF_MotorInfo *)(a_u4Param));
break;
case AFIOC_T_MOVETO:
i4RetValue = moveAF(a_u4Param);
break;
case AFIOC_T_SETINFPOS:
i4RetValue = setAFInf(a_u4Param);
break;
case AFIOC_T_SETMACROPOS:
i4RetValue = setAFMacro(a_u4Param);
break;
case AFIOC_S_SETPARA:
i4RetValue =
setAFPara((__user struct stAF_MotorCmd *)(a_u4Param));
break;
default:
LOG_INF("No CMD\n");
i4RetValue = -EPERM;
break;
}
return i4RetValue;
}
/* Main jobs: */
/* 1.Deallocate anything that "open" allocated in private_data. */
/* 2.Shut down the device on last close. */
/* 3.Only called once on last time. */
/* Q1 : Try release multiple times. */
int BU63165AF_Release(struct inode *a_pstInode, struct file *a_pstFile)
{
LOG_INF("Start\n");
if (*g_pAF_Opened == 2) {
LOG_INF("Wait\n");
OIS_Standby();
msleep(20);
}
if (*g_pAF_Opened) {
LOG_INF("Free\n");
spin_lock(g_pAF_SpinLock);
*g_pAF_Opened = 0;
spin_unlock(g_pAF_SpinLock);
}
LOG_INF("End\n");
return 0;
}
int BU63165AF_SetI2Cclient(struct i2c_client *pstAF_I2Cclient,
spinlock_t *pAF_SpinLock, int *pAF_Opened)
{
g_pstAF_I2Cclient = pstAF_I2Cclient;
g_pAF_SpinLock = pAF_SpinLock;
g_pAF_Opened = pAF_Opened;
LOG_INF("SetI2Cclient\n");
initAF();
return 1;
}
int BU63165AF_GetFileName(unsigned char *pFileName)
{
#if SUPPORT_GETTING_LENS_FOLDER_NAME
char FilePath[256];
char *FileString;
sprintf(FilePath, "%s", __FILE__);
FileString = strrchr(FilePath, '/');
*FileString = '\0';
FileString = (strrchr(FilePath, '/') + 1);
strncpy(pFileName, FileString, AF_MOTOR_NAME);
LOG_INF("FileName : %s\n", pFileName);
#else
pFileName[0] = '\0';
#endif
return 1;
}
@@ -0,0 +1,7 @@
#
# Makefile for misc devices that really don't fit anywhere else.
#
obj-y += BU63165AF.o OIS_func.o OIS_main.o OIS_user.o
@@ -0,0 +1,674 @@
// SPDX-License-Identifier: GPL-2.0
/*
* Copyright (c) 2019 MediaTek Inc.
*/
#define _USE_MATH_DEFINES
#include "OIS_func.h"
#include "OIS_coef.h"
#include "OIS_defi.h"
#include "OIS_head.h"
#include "OIS_prog.h"
/* ***************************************************** */
/* **** Program Download Function */
/* ***************************************************** */
short int func_PROGRAM_DOWNLOAD(void)
{
unsigned short int sts; /* RHM_HT 2013/04/15 Change "typedef". */
download(0, 0); /* Program Download */
sts = I2C_OIS_mem__read(_M_OIS_STS); /* Check Status */
if ((sts & 0x0004) == 0x0004) {
/* ==> RHM_HT 2013/07/10 Added */
unsigned short int u16_dat;
u16_dat = I2C_OIS_mem__read(_M_FIRMVER);
DEBUG_printf(("Firm Ver : %4d\n\n", u16_dat));
/* <== RHM_HT 2013/07/10 Added */
return ADJ_OK;
} else {
return PROG_DL_ERR;
}
}
/* ==> RHM_HT 2013/11/26 Reverted */
/* ***************************************************** */
/* **** COEF Download function */
/* ***************************************************** */
unsigned short int INTG__INPUT; /* Integral Input value szx_2014/12/24_2 */
unsigned short int
KGNTG_VALUE; /* KgxTG / KgyTG szx_2014/12/24_2 */
unsigned short int GYRSNS; /* RHM_HT 2015/01/16 Added */
void func_COEF_DOWNLOAD(unsigned short int u16_coef_type)
{
download(1, u16_coef_type); /* COEF Download */
{
unsigned short int u16_dat;
/* Coef type */
u16_dat = I2C_OIS_mem__read(_M_CEFTYP);
DEBUG_printf(
("COEF M[0x%02x] 0x%04X\n", _M_CEFTYP, u16_dat));
}
/* Get default Integ_input and KgnTG value */
INTG__INPUT = I2C_OIS_mem__read(0x38);
KGNTG_VALUE = I2C_OIS_mem__read(_M_KgxTG);
GYRSNS = I2C_OIS_mem__read(_M_GYRSNS); /* RHM_HT 2015/01/16 Added */
}
/* <== RHM_HT 2013/11/26 Reverted */
/* ***************************************************** */
/* **** Download the data */
/* ***************************************************** */
void download(unsigned short int u16_type, unsigned short int u16_coef_type)
{
/* Data Transfer Size per one I2C access */
#define DWNLD_TRNS_SIZE (7)
unsigned char temp[DWNLD_TRNS_SIZE + 1];
unsigned short int block_cnt;
unsigned short int total_cnt;
unsigned short int lp;
unsigned short int n;
unsigned short int u16_i;
if (u16_type == 0)
n = DOWNLOAD_BIN_LEN;
else
n = DOWNLOAD_COEF_LEN; /* RHM_HT 2013/07/10 Modified */
block_cnt = n / DWNLD_TRNS_SIZE + 1;
total_cnt = block_cnt;
while (1) {
/* Residual Number Check */
if (block_cnt == 1)
lp = n % DWNLD_TRNS_SIZE;
else
lp = DWNLD_TRNS_SIZE;
/* Transfer Data set */
if (lp != 0) {
if (u16_type == 0) {
temp[0] = _OP_FIRM_DWNLD;
for (u16_i = 1; u16_i <= lp; u16_i += 1)
temp[u16_i] = DOWNLOAD_BIN
[(total_cnt - block_cnt) *
DWNLD_TRNS_SIZE +
u16_i - 1];
} else {
temp[0] = _OP_COEF_DWNLD;
for (u16_i = 1; u16_i <= lp; u16_i += 1)
temp[u16_i] = DOWNLOAD_COEF
[(total_cnt - block_cnt) *
DWNLD_TRNS_SIZE +
u16_i - 1];
}
/* Data Transfer */
WR_I2C(_SLV_OIS_, lp + 1, temp);
}
/* Block Counter Decrement */
block_cnt = block_cnt - 1;
if (block_cnt == 0)
break;
}
}
void SET_FADJ_PARAM(const struct _FACT_ADJ *param)
{
/* ********************* */
/* HALL ADJUST */
/* ********************* */
/* Set Hall Current DAC value that is FACTORY ADJUSTED */
I2C_OIS_per_write(_P_30_ADC_CH0, param->gl_CURDAT);
/* Set Hall PreAmp Offset that is FACTORY ADJUSTED */
I2C_OIS_per_write(_P_31_ADC_CH1, param->gl_HALOFS_X);
I2C_OIS_per_write(_P_32_ADC_CH2, param->gl_HALOFS_Y);
/* Set Hall-X/Y PostAmp Offset that is FACTORY ADJUSTED */
I2C_OIS_mem_write(_M_X_H_ofs, param->gl_HX_OFS);
I2C_OIS_mem_write(_M_Y_H_ofs, param->gl_HY_OFS);
/* Set Residual Offset that is FACTORY ADJUSTED */
I2C_OIS_per_write(_P_39_Ch3_VAL_1, param->gl_PSTXOF);
I2C_OIS_per_write(_P_3B_Ch3_VAL_3, param->gl_PSTYOF);
/* ********************* */
/* DIGITAL GYRO OFFSET */
/* ********************* */
I2C_OIS_mem_write(_M_Kgx00, param->gl_GX_OFS);
I2C_OIS_mem_write(_M_Kgy00, param->gl_GY_OFS);
I2C_OIS_mem_write(_M_TMP_X_, param->gl_TMP_X_);
I2C_OIS_mem_write(_M_TMP_Y_, param->gl_TMP_Y_);
/* ********************* */
/* HALL SENSE */
/* ********************* */
/* Set Hall Gain value that is FACTORY ADJUSTED */
I2C_OIS_mem_write(_M_KgxHG, param->gl_KgxHG);
I2C_OIS_mem_write(_M_KgyHG, param->gl_KgyHG);
/* Set Cross Talk Canceller */
I2C_OIS_mem_write(_M_KgxH0, param->gl_KgxH0);
I2C_OIS_mem_write(_M_KgyH0, param->gl_KgyH0);
/* ********************* */
/* LOOPGAIN */
/* ********************* */
I2C_OIS_mem_write(_M_KgxG, param->gl_KGXG);
I2C_OIS_mem_write(_M_KgyG, param->gl_KGYG);
/* Position Servo ON ( OIS OFF ) */
I2C_OIS_mem_write(_M_EQCTL, 0x0C0C);
}
/* ***************************************************** */
/* **** Scence parameter */
/* ***************************************************** */
#define ANGLE_LIMIT \
(unsigned short int)(GYRSNS * 11 / 10) /* GYRSNS * limit[deg] */
#define G_SENSE 131 /* [LSB/dps] */
short int func_SET_SCENE_PARAM(unsigned char u16_scene, unsigned char u16_mode,
unsigned char filter, unsigned char range,
const struct _FACT_ADJ *param)
{
unsigned short int u16_i;
unsigned short int u16_dat;
unsigned short int *u16_dat_SCENE_;
unsigned char size_SCENE_tbl;
/* ==> RHM_HT 2013/11/25 Modified */
unsigned char u16_adr_target[3] = {
_M_Kgxdr, _M_X_LMT, _M_X_TGT,
};
unsigned short int u16_dat_SCENE_NIGHT_1[3] = {
0x7FFE, 0, G_SENSE * 16,
};
unsigned short int u16_dat_SCENE_NIGHT_2[3] = {
0x7FFC, 0, G_SENSE * 16,
};
unsigned short int u16_dat_SCENE_NIGHT_3[3] = {
0x7FFA, 0, G_SENSE * 16,
};
unsigned short int u16_dat_SCENE_D_A_Y_1[3] = {
0x7FFE, 0, G_SENSE * 40,
};
unsigned short int u16_dat_SCENE_D_A_Y_2[3] = {
0x7FFA, 0, G_SENSE * 40,
};
unsigned short int u16_dat_SCENE_D_A_Y_3[3] = {
0x7FF0, 0, G_SENSE * 40,
};
unsigned short int u16_dat_SCENE_SPORT_1[3] = {
0x7FFE, 0, G_SENSE * 60,
};
unsigned short int u16_dat_SCENE_SPORT_2[3] = {
0x7FF0, 0, G_SENSE * 60,
};
unsigned short int u16_dat_SCENE_SPORT_3[3] = {
0x7FE0, 0, G_SENSE * 60,
};
unsigned short int u16_dat_SCENE_TEST___[3] = {
0x7FF0, 0x7FFF, 0x7FFF,
}; /* Limmiter OFF */
/* <== RHM_HT 2013/11/25 Modified */
u16_dat_SCENE_NIGHT_1[1] = ANGLE_LIMIT;
u16_dat_SCENE_NIGHT_2[1] = ANGLE_LIMIT;
u16_dat_SCENE_NIGHT_3[1] = ANGLE_LIMIT;
u16_dat_SCENE_D_A_Y_1[1] = ANGLE_LIMIT;
u16_dat_SCENE_D_A_Y_2[1] = ANGLE_LIMIT;
u16_dat_SCENE_D_A_Y_3[1] = ANGLE_LIMIT;
u16_dat_SCENE_SPORT_1[1] = ANGLE_LIMIT;
u16_dat_SCENE_SPORT_2[1] = ANGLE_LIMIT;
u16_dat_SCENE_SPORT_3[1] = ANGLE_LIMIT;
size_SCENE_tbl =
sizeof(u16_dat_SCENE_NIGHT_1) / sizeof(unsigned short int);
/* Disable OIS ( position Servo is not disable ) */
u16_dat = I2C_OIS_mem__read(_M_EQCTL);
u16_dat = (u16_dat & 0xFEFE);
I2C_OIS_mem_write(_M_EQCTL, u16_dat);
/* Scene parameter select */
switch (u16_scene) {
case _SCENE_NIGHT_1:
u16_dat_SCENE_ = u16_dat_SCENE_NIGHT_1;
break;
case _SCENE_NIGHT_2:
u16_dat_SCENE_ = u16_dat_SCENE_NIGHT_2;
break;
case _SCENE_NIGHT_3:
u16_dat_SCENE_ = u16_dat_SCENE_NIGHT_3;
break;
case _SCENE_D_A_Y_1:
u16_dat_SCENE_ = u16_dat_SCENE_D_A_Y_1;
break;
case _SCENE_D_A_Y_2:
u16_dat_SCENE_ = u16_dat_SCENE_D_A_Y_2;
break;
case _SCENE_D_A_Y_3:
u16_dat_SCENE_ = u16_dat_SCENE_D_A_Y_3;
break;
case _SCENE_SPORT_1:
u16_dat_SCENE_ = u16_dat_SCENE_SPORT_1;
break;
case _SCENE_SPORT_2:
u16_dat_SCENE_ = u16_dat_SCENE_SPORT_2;
break;
case _SCENE_SPORT_3:
u16_dat_SCENE_ = u16_dat_SCENE_SPORT_3;
break;
case _SCENE_TEST___:
u16_dat_SCENE_ = u16_dat_SCENE_TEST___;
break;
default:
u16_dat_SCENE_ = u16_dat_SCENE_TEST___;
break;
}
/* Set parameter to the OIS controller */
for (u16_i = 0; u16_i < size_SCENE_tbl; u16_i += 1)
I2C_OIS_mem_write(u16_adr_target[u16_i], u16_dat_SCENE_[u16_i]);
for (u16_i = 0; u16_i < size_SCENE_tbl; u16_i += 1)
I2C_OIS_mem_write(u16_adr_target[u16_i] + 0x80,
u16_dat_SCENE_[u16_i]);
{
u16_dat = (INTG__INPUT * 16384L) /
ANGLE_LIMIT; /* X2 * 4000h / X1 */
I2C_OIS_mem_write(0x38, u16_dat);
I2C_OIS_mem_write(0xB8, u16_dat);
/* ---------------------------------------------- */
u16_dat = (KGNTG_VALUE * ANGLE_LIMIT) /
16384L; /* X3 * X1 / 4000h */
I2C_OIS_mem_write(0x47, u16_dat);
I2C_OIS_mem_write(0xC7, u16_dat);
}
/* szx_2014/12/24 <=== */
/* Set/Reset Notch filter */
if (filter == 1) { /* Disable Filter */
u16_dat = I2C_OIS_mem__read(_M_EQCTL);
u16_dat |= 0x4000;
I2C_OIS_mem_write(_M_EQCTL, u16_dat);
} else { /* Enable Filter */
u16_dat = I2C_OIS_mem__read(_M_EQCTL);
u16_dat &= 0xBFFF;
I2C_OIS_mem_write(_M_EQCTL, u16_dat);
}
/* Clear the register of the OIS controller */
I2C_OIS_mem_write(_M_wDgx02, 0x0000);
I2C_OIS_mem_write(_M_wDgx03, 0x0000);
I2C_OIS_mem_write(_M_wDgx06, 0x7FFF);
I2C_OIS_mem_write(_M_Kgx15, 0x0000);
I2C_OIS_mem_write(_M_wDgy02, 0x0000);
I2C_OIS_mem_write(_M_wDgy03, 0x0000);
I2C_OIS_mem_write(_M_wDgy06, 0x7FFF);
I2C_OIS_mem_write(_M_Kgy15, 0x0000);
/* Set the pre-Amp offset value (X and Y) */
/* ==> RHM_HT 2013/11/25 Modified */
if (range == 1) {
I2C_OIS_per_write(_P_31_ADC_CH1, param->gl_SFTHAL_X);
I2C_OIS_per_write(_P_32_ADC_CH2, param->gl_SFTHAL_Y);
} else {
I2C_OIS_per_write(_P_31_ADC_CH1, param->gl_HALOFS_X);
I2C_OIS_per_write(_P_32_ADC_CH2, param->gl_HALOFS_Y);
}
/* <== RHM_HT 2013/11/25 Modified */
/* Enable OIS (if u16_mode = 1) */
if ((u16_mode == 1)) {
u16_dat = I2C_OIS_mem__read(_M_EQCTL);
u16_dat = (u16_dat | 0x0101);
I2C_OIS_mem_write(_M_EQCTL, u16_dat);
DEBUG_printf(("SET : EQCTL:%.4x\n", u16_dat));
} else { /* ==> RHM_HT 2013.03.23 Add for OIS control */
u16_dat = I2C_OIS_mem__read(_M_EQCTL);
u16_dat = (u16_dat & 0xFEFE);
I2C_OIS_mem_write(_M_EQCTL, u16_dat);
DEBUG_printf(("SET : EQCTL:%.4x\n", u16_dat));
} /* <== RHM_HT 2013.03.23 Add for OIS control */
return ADJ_OK; /* RHM_HT 2013/04/15 Change return value */
}
short int func_SET_SCENE_PARAM_for_NewGYRO_Fil(unsigned char u16_scene,
unsigned char u16_mode,
unsigned char filter,
unsigned char range,
const struct _FACT_ADJ *param)
{
unsigned short int u16_i;
unsigned short int u16_dat;
unsigned short int *u16_dat_SCENE_;
unsigned char size_SCENE_tbl;
/* szx_2014/09/19 ---> Modified */
/* ==> RHM_HT 2013/11/25 Modified */
unsigned char u16_adr_target[4] = {
_M_Kgxdr, _M_X_LMT, _M_X_TGT, 0x1B,
};
unsigned short int u16_dat_SCENE_NIGHT_1[4] = {
0x7FE0, 0, G_SENSE * 16, 0x0300,
};
unsigned short int u16_dat_SCENE_NIGHT_2[4] = {
0x7FFF, 0, G_SENSE * 16, 0x0080,
};
unsigned short int u16_dat_SCENE_NIGHT_3[4] = {
0x7FF0, 0, G_SENSE * 16, 0x0300,
};
unsigned short int u16_dat_SCENE_D_A_Y_1[4] = {
0x7FE0, 0, G_SENSE * 40, 0x0300,
};
unsigned short int u16_dat_SCENE_D_A_Y_2[4] = {
0x7F80, 0, G_SENSE * 40, 0x0140,
};
unsigned short int u16_dat_SCENE_D_A_Y_3[4] = {
0x7F00, 0, G_SENSE * 40, 0x0300,
};
unsigned short int u16_dat_SCENE_SPORT_1[4] = {
0x7FE0, 0, G_SENSE * 60, 0x0300,
};
/* szx_2014/12/24 ===> */
unsigned short int u16_dat_SCENE_SPORT_2[4] = {
0x7F80, 0, G_SENSE * 60, 0x0000,
};
unsigned short int u16_dat_SCENE_SPORT_3[4] = {
0x7FF0, 0, G_SENSE * 60, 0x0300,
};
/* szx_2014/12/24 <=== */
unsigned short int u16_dat_SCENE_TEST___[4] = {
0x7FFF, 0x7FFF, 0x7FFF, 0x0080,
}; /* Limmiter OFF */
/* <== RHM_HT 2013/11/25 Modified */
/* szx_2014/09/19 <--- */
u16_dat_SCENE_NIGHT_1[1] = ANGLE_LIMIT;
u16_dat_SCENE_NIGHT_2[1] = ANGLE_LIMIT;
u16_dat_SCENE_NIGHT_3[1] = ANGLE_LIMIT;
u16_dat_SCENE_D_A_Y_1[1] = ANGLE_LIMIT;
u16_dat_SCENE_D_A_Y_2[1] = ANGLE_LIMIT;
u16_dat_SCENE_D_A_Y_3[1] = ANGLE_LIMIT;
u16_dat_SCENE_SPORT_1[1] = ANGLE_LIMIT;
u16_dat_SCENE_SPORT_2[1] = ANGLE_LIMIT;
u16_dat_SCENE_SPORT_3[1] = ANGLE_LIMIT;
size_SCENE_tbl =
sizeof(u16_dat_SCENE_NIGHT_1) / sizeof(unsigned short int);
/* Disable OIS ( position Servo is not disable ) */
u16_dat = I2C_OIS_mem__read(_M_EQCTL);
u16_dat = (u16_dat & 0xFEFE);
I2C_OIS_mem_write(_M_EQCTL, u16_dat);
/* Scene parameter select */
switch (u16_scene) {
case _SCENE_NIGHT_1:
u16_dat_SCENE_ = u16_dat_SCENE_NIGHT_1;
break;
case _SCENE_NIGHT_2:
u16_dat_SCENE_ = u16_dat_SCENE_NIGHT_2;
break;
case _SCENE_NIGHT_3:
u16_dat_SCENE_ = u16_dat_SCENE_NIGHT_3;
break;
case _SCENE_D_A_Y_1:
u16_dat_SCENE_ = u16_dat_SCENE_D_A_Y_1;
break;
case _SCENE_D_A_Y_2:
u16_dat_SCENE_ = u16_dat_SCENE_D_A_Y_2;
break;
case _SCENE_D_A_Y_3:
u16_dat_SCENE_ = u16_dat_SCENE_D_A_Y_3;
break;
case _SCENE_SPORT_1:
u16_dat_SCENE_ = u16_dat_SCENE_SPORT_1;
break;
case _SCENE_SPORT_2:
u16_dat_SCENE_ = u16_dat_SCENE_SPORT_2;
break;
case _SCENE_SPORT_3:
u16_dat_SCENE_ = u16_dat_SCENE_SPORT_3;
break;
case _SCENE_TEST___:
u16_dat_SCENE_ = u16_dat_SCENE_TEST___;
break;
default:
u16_dat_SCENE_ = u16_dat_SCENE_TEST___;
break;
}
/* Set parameter to the OIS controller */
for (u16_i = 0; u16_i < size_SCENE_tbl; u16_i += 1)
I2C_OIS_mem_write(u16_adr_target[u16_i], u16_dat_SCENE_[u16_i]);
for (u16_i = 0; u16_i < size_SCENE_tbl; u16_i += 1)
I2C_OIS_mem_write(u16_adr_target[u16_i] + 0x80,
u16_dat_SCENE_[u16_i]);
{
u16_dat = (INTG__INPUT * 16384L) /
ANGLE_LIMIT; /* X2 * 4000h / X1 */
I2C_OIS_mem_write(0x38, u16_dat);
I2C_OIS_mem_write(0xB8, u16_dat);
/* ---------------------------------------------- */
u16_dat = (KGNTG_VALUE * ANGLE_LIMIT) /
16384L; /* X3 * X1 / 4000h */
I2C_OIS_mem_write(0x47, u16_dat);
I2C_OIS_mem_write(0xC7, u16_dat);
}
/* szx_2014/12/24 <=== */
/* Set/Reset Notch filter */
if (filter == 1) { /* Disable Filter */
u16_dat = I2C_OIS_mem__read(_M_EQCTL);
u16_dat |= 0x4000;
I2C_OIS_mem_write(_M_EQCTL, u16_dat);
} else { /* Enable Filter */
u16_dat = I2C_OIS_mem__read(_M_EQCTL);
u16_dat &= 0xBFFF;
I2C_OIS_mem_write(_M_EQCTL, u16_dat);
}
/* Set the pre-Amp offset value (X and Y) */
/* ==> RHM_HT 2013/11/25 Modified */
if (range == 1) {
I2C_OIS_per_write(_P_31_ADC_CH1, param->gl_SFTHAL_X);
I2C_OIS_per_write(_P_32_ADC_CH2, param->gl_SFTHAL_Y);
} else {
I2C_OIS_per_write(_P_31_ADC_CH1, param->gl_HALOFS_X);
I2C_OIS_per_write(_P_32_ADC_CH2, param->gl_HALOFS_Y);
}
/* <== RHM_HT 2013/11/25 Modified */
/* Enable OIS (if u16_mode = 1) */
if ((u16_mode == 1)) { /* OIS ON */
u16_dat = I2C_OIS_mem__read(_M_EQCTL);
u16_dat = (u16_dat & 0xEFFF); /* Clear Halfshutter mode */
u16_dat = (u16_dat | 0x0101);
I2C_OIS_mem_write(_M_EQCTL, u16_dat);
DEBUG_printf(("SET : EQCTL:%.4x\n", u16_dat));
} else if (u16_mode ==
2) { /* Half Shutter // szx_2014/09/19 ---> */
u16_dat = I2C_OIS_mem__read(_M_EQCTL);
u16_dat = (u16_dat | 0x1101);
I2C_OIS_mem_write(_M_EQCTL, u16_dat);
DEBUG_printf(("SET : EQCTL:%.4x\n", u16_dat));
} else { /* ==> RHM_HT 2013.03.23 Add for OIS control */
u16_dat = I2C_OIS_mem__read(_M_EQCTL);
u16_dat = (u16_dat & 0xFEFE);
I2C_OIS_mem_write(_M_EQCTL, u16_dat);
DEBUG_printf(("SET : EQCTL:%.4x\n", u16_dat));
} /* <== RHM_HT 2013.03.23 Add for OIS control */
return ADJ_OK; /* RHM_HT 2013/04/15 Change return value */
}
/* ==> RHM_HT 2014/11/27 Added */
/* ***************************************************** */
/* **** Enable HalfShutter */
/* ***************************************************** */
void HalfShutterOn(void)
{
unsigned short int u16_dat = 0;
u16_dat = I2C_OIS_mem__read(_M_EQCTL);
u16_dat = (u16_dat | 0x1101);
I2C_OIS_mem_write(_M_EQCTL, u16_dat);
DEBUG_printf(("SET : EQCTL:%.4x\n", u16_dat));
}
/* <== RHM_HT 2014/11/27 Added */
/* ***************************************************** */
/* **** Write to the Peripheral register < 82h > */
/* **** ------------------------------------------------ */
/* **** unsigned char adr Peripheral Address */
/* **** unsigned short int dat Write data */
/* ***************************************************** */
void I2C_OIS_per_write(unsigned char u08_adr, unsigned short int u16_dat)
{
unsigned char out[4];
out[0] = _OP_Periphe_RW;
out[1] = u08_adr;
out[2] = (u16_dat)&0xFF;
out[3] = (u16_dat >> 8) & 0xFF;
WR_I2C(_SLV_OIS_, 4, out);
}
/* ***************************************************** */
/* **** Write to the Memory register < 84h > */
/* **** ------------------------------------------------ */
/* **** unsigned char adr Memory Address */
/* **** unsigned short int dat Write data */
/* ***************************************************** */
void I2C_OIS_mem_write(unsigned char u08_adr, unsigned short int u16_dat)
{
unsigned char out[4];
out[0] = _OP_Memory__RW;
out[1] = u08_adr;
out[2] = (u16_dat)&0xFF;
out[3] = (u16_dat >> 8) & 0xFF;
WR_I2C(_SLV_OIS_, 4, out);
}
/* ***************************************************** */
/* **** Read from the Peripheral register < 82h > */
/* **** ------------------------------------------------ */
/* **** unsigned char adr Peripheral Address */
/* **** unsigned short int dat Read data */
/* ***************************************************** */
unsigned short int I2C_OIS_per__read(unsigned char u08_adr)
{
unsigned char u08_dat[2];
u08_dat[0] = _OP_Periphe_RW; /* Op-code */
u08_dat[1] = u08_adr; /* target address */
return RD_I2C(_SLV_OIS_, 2, u08_dat);
}
/* ***************************************************** */
/* **** Read from the Memory register < 84h > */
/* **** ------------------------------------------------ */
/* **** unsigned char adr Memory Address */
/* **** unsigned short int dat Read data */
/* ***************************************************** */
unsigned short int I2C_OIS_mem__read(unsigned char u08_adr)
{
unsigned char u08_dat[2];
u08_dat[0] = _OP_Memory__RW; /* Op-code */
u08_dat[1] = u08_adr; /* target address */
return RD_I2C(_SLV_OIS_, 2, u08_dat);
}
/* ***************************************************** */
/* **** Special Command 8Ah */
/* _cmd_8C_EI 0 // 0x0001 */
/* _cmd_8C_DI 1 // 0x0002 */
/* ***************************************************** */
void I2C_OIS_spcl_cmnd(unsigned char u08_on, unsigned char u08_dat)
{
if ((u08_dat == _cmd_8C_EI) || (u08_dat == _cmd_8C_DI)) {
unsigned char out[2];
out[0] = _OP_SpecialCMD;
out[1] = u08_dat;
WR_I2C(_SLV_OIS_, 2, out);
}
}
/* ***************************************************** */
/* **** F0-F3h Command NonAssertClockStretch Function */
/* ***************************************************** */
void I2C_OIS_F0123_wr_(unsigned char u08_dat0, unsigned char u08_dat1,
unsigned short int u16_dat2)
{
unsigned char out[5];
out[0] = 0xF0;
out[1] = u08_dat0;
out[2] = u08_dat1;
out[3] = u16_dat2 / 256;
out[4] = u16_dat2 % 256;
WR_I2C(_SLV_OIS_, 5, out);
}
unsigned short int I2C_OIS_F0123__rd(void)
{
unsigned char u08_dat;
u08_dat = 0xF0; /* Op-code */
return RD_I2C(_SLV_OIS_, 1, &u08_dat);
}
/* ----------------------------------------------------------- */
/* ----------------------------------------------------------- */
/* ----------------------------------------------------------- */
@@ -0,0 +1,212 @@
// SPDX-License-Identifier: GPL-2.0
/*
* Copyright (c) 2019 MediaTek Inc.
*/
/* #define OIS_DEBUG */
#ifdef OIS_DEBUG
#include <linux/delay.h>
#include <linux/fs.h>
#include <linux/uaccess.h>
#endif
/* #include <stdio.h> */
#include "OIS_head.h"
const struct _FACT_ADJ
FADJ_DEF = {
0x0200, /* gl_CURDAT; */
0x0200, /* gl_HALOFS_X; */
0x0200, /* gl_HALOFS_Y; */
0x0000, /* gl_HX_OFS; */
0x0000, /* gl_HY_OFS; */
0x0080,
0x0080,
0x0000, /* gl_GX_OFS; */
0x0000, /* gl_GY_OFS; */
0x2000,
0x2000,
0x2000,
0x2000,
0x0200,
0x0200,
0x0000,
0x0000,
0x0000,
0x0000,
};
/* FACTORY Adjusted data */
/* These data are stored at the non-vollatile */
/* memory inside of the CMOS sensor. */
/* The Host ( ISP or I2C master ) read these */
/* data from above memory and write to the OIS */
/* controller. */
/* --------------------------------------------- */
struct _FACT_ADJ
FADJ_MEM = {
0x0201, /* gl_CURDAT; */
0x0200, /* gl_HALOFS_X; */
0x0200, /* gl_HALOFS_Y; */
0x0000, /* gl_HX_OFS; */
0x0000, /* gl_HY_OFS; */
0x0080,
0x0080,
0x0000, /* gl_GX_OFS; */
0x0000, /* gl_GY_OFS; */
0x2000,
0x2000,
0x2000,
0x2000,
0x0200,
0x0200,
0x0000,
0x0000,
0x0000,
0x0000,
};
/* Parameters for expanding OIS range */
/* --------------------------------------------- */
double p_x, q_x;
double p_y, q_y;
short int zero_X;
short int zero_Y;
short int PREOUT_X_P, PREOUT_X_N;
short int PREOUT_Y_P, PREOUT_Y_N;
double alfa_X, beta_X;
double alfa_Y, beta_Y;
#ifdef OIS_DEBUG
#define OIS_DRVNAME "BU63165AF_OIS"
#define LOG_INF(format, args...) \
pr_info(OIS_DRVNAME " [%s] " format, __func__, ##args)
#endif
/* GLOBAL variable ( Upper Level Host Set this Global variables ) */
unsigned short int BOOT_MODE = _FACTORY_;
#define AF_REQ 0x8000
#define SCENE_REQ_ON 0x4000
#define SCENE_REQ_OFF 0x2000
#define POWERDOWN 0x1000
#define INITIAL_VAL 0x0000
unsigned short int OIS_SCENE = _SCENE_D_A_Y_1;
unsigned short int OIS_REQUEST = INITIAL_VAL; /* OIS control register. */
/* ==> RHM_HT 2013.03.04 Change type (unsigned short int -> double) */
double OIS_PIXEL[2]; /* Just Only use for factory adjustment. */
/* <== RHM_HT 2013.03.04 */
short int OIS_MAIN_STS = ADJ_ERR;
static struct _FACT_ADJ fadj;
void setOISMode(int Disable)
{
if (Disable == 1)
func_SET_SCENE_PARAM_for_NewGYRO_Fil(_SCENE_SPORT_3, 0, 0, 0,
&fadj);
else
func_SET_SCENE_PARAM_for_NewGYRO_Fil(_SCENE_SPORT_3, 1, 0, 0,
&fadj);
}
int setVCMPos(unsigned short DAC_Val)
{
I2C_OIS_F0123_wr_(0x90, 0x00, DAC_Val); /* AF Control */
return 0;
}
void OIS_Standby(void)
{
I2C_OIS_F0123_wr_(0x90, 0x00, 0x0200);
I2C_OIS_mem_write(0x7F, 0x0080);
I2C_OIS_per_write(0x72, 0x0000);
I2C_OIS_per_write(0x73, 0x0000);
I2C_OIS_per_write(0x18, 0x000F);
I2C_OIS_per_write(0x1B, 0x0B02);
I2C_OIS_per_write(0x1C, 0x0B02);
I2C_OIS_per_write(0x3D, 0x0000);
I2C_OIS_per_write(0x22, 0x0300);
I2C_OIS_per_write(0x59, 0x0000);
}
/* MAIN OIS */
void Main_OIS(void)
{
/* ------------------------------------------------------ */
/* Get Factory adjusted data */
/* ------------------------------------------------------ */
fadj = get_FADJ_MEM_from_non_volatile_memory();
#ifdef OIS_DEBUG
LOG_INF("gl_CURDAT = 0x%04X\n", fadj.gl_CURDAT);
LOG_INF("gl_HALOFS_X = 0x%04X\n", fadj.gl_HALOFS_X);
LOG_INF("gl_HALOFS_Y = 0x%04X\n", fadj.gl_HALOFS_Y);
LOG_INF("gl_PSTXOF = 0x%04X\n", fadj.gl_PSTXOF);
LOG_INF("gl_PSTYOF = 0x%04X\n", fadj.gl_PSTYOF);
LOG_INF("gl_HX_OFS = 0x%04X\n", fadj.gl_HX_OFS);
LOG_INF("gl_HY_OFS = 0x%04X\n", fadj.gl_HY_OFS);
LOG_INF("gl_GX_OFS = 0x%04X\n", fadj.gl_GX_OFS);
LOG_INF("gl_GY_OFS = 0x%04X\n", fadj.gl_GY_OFS);
LOG_INF("gl_KgxHG = 0x%04X\n", fadj.gl_KgxHG);
LOG_INF("gl_KgyHG = 0x%04X\n", fadj.gl_KgyHG);
LOG_INF("gl_KGXG = 0x%04X\n", fadj.gl_KGXG);
LOG_INF("gl_KGYG = 0x%04X\n", fadj.gl_KGYG);
LOG_INF("gl_SFTHAL_X = 0x%04X\n", fadj.gl_SFTHAL_X);
LOG_INF("gl_SFTHAL_Y = 0x%04X\n", fadj.gl_SFTHAL_Y);
LOG_INF("gl_TMP_X_ = 0x%04X\n", fadj.gl_TMP_X_);
LOG_INF("gl_TMP_Y_ = 0x%04X\n", fadj.gl_TMP_Y_);
LOG_INF("gl_KgxH0 = 0x%04X\n", fadj.gl_KgxH0);
LOG_INF("gl_KgyH0 = 0x%04X\n", fadj.gl_KgyH0);
#endif
/* ------------------------------------------------------ */
/* Enable Source Power and Input external clock to CLK/PS pin. */
/* ------------------------------------------------------ */
/* Please write your source code here. */
/* ------------------------------------------------------ */
/* PLL setting to use external CLK */
/* ------------------------------------------------------ */
VCOSET0();
/* ------------------------------------------------------ */
/* Download Program and Coefficient */
/* ------------------------------------------------------ */
OIS_MAIN_STS = func_PROGRAM_DOWNLOAD(); /* Program Download */
if (OIS_MAIN_STS <= ADJ_ERR)
return;
func_COEF_DOWNLOAD(0); /* Download Coefficient */
/* ------------------------------------------------------ */
/* Change Clock to external pin CLK_PS */
/* ------------------------------------------------------ */
VCOSET1();
/* ------------------------------------------------------ */
/* Issue DSP start command. */
/* ------------------------------------------------------ */
I2C_OIS_spcl_cmnd(1, _cmd_8C_EI); /* DSP calculation START */
/* ------------------------------------------------------ */
/* Set calibration data */
/* ------------------------------------------------------ */
SET_FADJ_PARAM(&fadj);
/* ------------------------------------------------------ */
/* Set scene parameter for OIS */
/* ------------------------------------------------------ */
func_SET_SCENE_PARAM_for_NewGYRO_Fil(_SCENE_SPORT_3, 1, 0, 0, &fadj);
}
@@ -0,0 +1,261 @@
// SPDX-License-Identifier: GPL-2.0
/*
* Copyright (c) 2019 MediaTek Inc.
*/
#ifndef OIS_USER_C
#define OIS_USER_C
#endif
#include "OIS_head.h"
unsigned short int FOCUS_VAL = 0x0122;
/* ============================================ */
void VCOSET0(void)
{
unsigned short int CLK_PS = 23880;
unsigned short int FVCO_1 = 36000; /* Target Frequency [kHz] */
/* 27000 for 63163 */
/* 36000 for 63165 */
unsigned short int FREF = 25; /* Reference Clock Frequency [kHz] */
unsigned short int DIV_N = CLK_PS / FREF - 1; /* calc DIV_N */
unsigned short int DIV_M = FVCO_1 / FREF - 1; /* calc DIV_M */
I2C_OIS_per_write(0x62,
DIV_N); /* Divider for internal reference clock */
I2C_OIS_per_write(0x63, DIV_M); /* Divider for internal PLL clock */
I2C_OIS_per_write(0x64, 0x4060); /* Loop Filter */
I2C_OIS_per_write(0x60, 0x3011); /* PLL */
I2C_OIS_per_write(0x65, 0x0080); /* */
I2C_OIS_per_write(0x61, 0x8002); /* VCOON */
I2C_OIS_per_write(0x61, 0x8003); /* Circuit ON */
I2C_OIS_per_write(0x61, 0x8809); /* PLL ON */
}
void VCOSET1(void)
{
I2C_OIS_per_write(0x05,
0x000C); /* Prepare for PLL clock as master clock */
I2C_OIS_per_write(0x05, 0x000D); /* Change to PLL clock */
}
/* ///////////////////////////////////////////////////////// */
/* Write Data to Slave device via I2C master device */
/* --------------------------------------------------------- */
/* <Function> */
/* I2C master send these data to the I2C slave device. */
/* This function relate to your own circuit. */
/* */
/* <Input> */
/* unsigned char slvadr I2C slave adr */
/* unsigned char size Transfer Size */
/* unsigned char *dat data matrix */
/* */
/* <Output> */
/* none */
/* */
/* <Description> */
/* [S][SlaveAdr][W]+[dat[0]]+...+[dat[size-1]][P] */
/* */
/* ========================================================= */
void WR_I2C(unsigned char slvadr, unsigned char size, unsigned char *dat)
{
s4AF_WriteReg_BU63165AF(slvadr << 1, dat, size);
}
/* ********************************************************* */
/* Read Data from Slave device via I2C master device */
/* --------------------------------------------------------- */
/* <Function> */
/* I2C master read data from the I2C slave device. */
/* This function relate to your own circuit. */
/* */
/* <Input> */
/* unsigned char slvadr I2C slave adr */
/* unsigned char size Transfer Size */
/* unsigned char *dat data matrix */
/* */
/* <Output> */
/* unsigned short int 16bit data read from I2C Slave device */
/* */
/* <Description> */
/* if size == 1 */
/* [S][SlaveAdr][W]+[dat[0]]+ [RS][SlaveAdr][R]+[RD_DAT0]+[RD_DAT1][P]
*/
/* if size == 2 */
/* [S][SlaveAdr][W]+[dat[0]]+[dat[1]]+[RS][SlaveAdr][R]+[RD_DAT0]+[RD_DAT1][P]
*/
/* */
/* ********************************************************* */
unsigned short int RD_I2C(unsigned char slvadr, unsigned char size,
unsigned char *dat)
{
unsigned short int read_data = 0;
unsigned short int read_data_h = 0;
if (size == 1) {
dat[1] = 0;
s4AF_ReadReg_BU63165AF(slvadr << 1, dat, 2,
(unsigned char *)&read_data, 2);
} else if (size == 2) {
s4AF_ReadReg_BU63165AF(slvadr << 1, dat, 2,
(unsigned char *)&read_data, 2);
}
read_data_h = read_data >> 8;
read_data = read_data << 8;
read_data = read_data | read_data_h;
return read_data;
}
/* ********************************************************* */
/* Write Factory Adjusted data to the non-volatile memory */
/* --------------------------------------------------------- */
/* <Function> */
/* Factory adjusted data are sotred somewhere */
/* non-volatile memory. */
/* */
/* <Input> */
/* struct _FACT_ADJ Factory Adjusted data */
/* */
/* <Output> */
/* none */
/* */
/* <Description> */
/* You have to port your own system. */
/* */
/* ********************************************************* */
void store_FADJ_MEM_to_non_volatile_memory(struct _FACT_ADJ param)
{
}
/* ********************************************************* */
/* Read Factory Adjusted data from the non-volatile memory */
/* --------------------------------------------------------- */
/* <Function> */
/* Factory adjusted data are sotred somewhere */
/* non-volatile memory. I2C master has to read these */
/* data and store the data to the OIS controller. */
/* */
/* <Input> */
/* none */
/* */
/* <Output> */
/* struct _FACT_ADJ Factory Adjusted data */
/* */
/* <Description> */
/* You have to port your own system. */
/* */
/* ********************************************************* */
struct _FACT_ADJ get_FADJ_MEM_from_non_volatile_memory(void)
{
unsigned short ReadData;
s4EEPROM_ReadReg_BU63165AF(0x0763, &ReadData);
FADJ_MEM.gl_CURDAT = (unsigned short int)ReadData;
s4EEPROM_ReadReg_BU63165AF(0x0765, &ReadData);
FADJ_MEM.gl_HALOFS_X = (unsigned short int)ReadData;
s4EEPROM_ReadReg_BU63165AF(0x0767, &ReadData);
FADJ_MEM.gl_HALOFS_Y = (unsigned short int)ReadData;
s4EEPROM_ReadReg_BU63165AF(0x0769, &ReadData);
FADJ_MEM.gl_HX_OFS = (unsigned short int)ReadData;
s4EEPROM_ReadReg_BU63165AF(0x076B, &ReadData);
FADJ_MEM.gl_HY_OFS = (unsigned short int)ReadData;
s4EEPROM_ReadReg_BU63165AF(0x076D, &ReadData);
FADJ_MEM.gl_PSTXOF = (unsigned short int)ReadData;
s4EEPROM_ReadReg_BU63165AF(0x076F, &ReadData);
FADJ_MEM.gl_PSTYOF = (unsigned short int)ReadData;
s4EEPROM_ReadReg_BU63165AF(0x0771, &ReadData);
FADJ_MEM.gl_GX_OFS = (unsigned short int)ReadData;
s4EEPROM_ReadReg_BU63165AF(0x0773, &ReadData);
FADJ_MEM.gl_GY_OFS = (unsigned short int)ReadData;
s4EEPROM_ReadReg_BU63165AF(0x0775, &ReadData);
FADJ_MEM.gl_KgxHG = (unsigned short int)ReadData;
s4EEPROM_ReadReg_BU63165AF(0x0777, &ReadData);
FADJ_MEM.gl_KgyHG = (unsigned short int)ReadData;
s4EEPROM_ReadReg_BU63165AF(0x0779, &ReadData);
FADJ_MEM.gl_KGXG = (unsigned short int)ReadData;
s4EEPROM_ReadReg_BU63165AF(0x077B, &ReadData);
FADJ_MEM.gl_KGYG = (unsigned short int)ReadData;
s4EEPROM_ReadReg_BU63165AF(0x077D, &ReadData);
FADJ_MEM.gl_SFTHAL_X = (unsigned short int)ReadData;
s4EEPROM_ReadReg_BU63165AF(0x077F, &ReadData);
FADJ_MEM.gl_SFTHAL_Y = (unsigned short int)ReadData;
s4EEPROM_ReadReg_BU63165AF(0x0781, &ReadData);
FADJ_MEM.gl_TMP_X_ = (unsigned short int)ReadData;
s4EEPROM_ReadReg_BU63165AF(0x0783, &ReadData);
FADJ_MEM.gl_TMP_Y_ = (unsigned short int)ReadData;
s4EEPROM_ReadReg_BU63165AF(0x0785, &ReadData);
FADJ_MEM.gl_KgxH0 = (unsigned short int)ReadData;
s4EEPROM_ReadReg_BU63165AF(0x0787, &ReadData);
FADJ_MEM.gl_KgyH0 = (unsigned short int)ReadData;
return FADJ_MEM; /* Note: This return data is for DEBUG. */
}
/* ********************************************************* */
/* Wait */
/* --------------------------------------------------------- */
/* <Function> */
/* */
/* <Input> */
/* unsigned long int time on the micro second time scale */
/* */
/* <Output> */
/* none */
/* */
/* <Description> */
/* */
/* ********************************************************* */
void Wait_usec(unsigned long time)
{
/* Please write your source code here. */
}
#ifdef DEBUG_FADJ
/* ********************************************************* */
/* Printf for DEBUG */
/* --------------------------------------------------------- */
/* <Function> */
/* */
/* <Input> */
/* const char *format, ... */
/* Same as printf */
/* */
/* <Output> */
/* none */
/* */
/* <Description> */
/* */
/* ********************************************************* */
int debug_print(const char *format, ...)
{
return 0;
}
#endif
@@ -0,0 +1,56 @@
/* SPDX-License-Identifier: GPL-2.0 */
/*
* Copyright (c) 2019 MediaTek Inc.
*/
#ifndef OIS_COEF_H
#define OIS_COEF_H
const OIS_UBYTE DOWNLOAD_COEF[] = {
0xef, 0x00, 0x00, 0x00, 0x20, 0x00, 0x18, 0x00, 0x00, 0x00, 0x00, 0xab,
0x0a, 0x00, 0x40, 0x00, 0x40, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x80, 0x00, 0x00, 0x27, 0x83, 0x64, 0x7e, 0xca, 0x00, 0xff, 0x7f, 0xff,
0x7f, 0x5b, 0x7f, 0x76, 0x7e, 0xed, 0x7c, 0x2a, 0x77, 0x68, 0x71, 0x01,
0x6b, 0x18, 0x64, 0x8b, 0x5c, 0x85, 0x2b, 0xd7, 0x23, 0x89, 0x41, 0x89,
0x41, 0x89, 0x41, 0x89, 0x41, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xff,
0x7f, 0xf6, 0x91, 0x14, 0xae, 0x08, 0x58, 0x26, 0x63, 0x7b, 0x19, 0x00,
0x20, 0x00, 0x88, 0x00, 0x40, 0x80, 0x41, 0x00, 0x7f, 0xff, 0x7f, 0xa6,
0x13, 0x00, 0x00, 0xff, 0x7f, 0x00, 0x00, 0x00, 0x00, 0x90, 0xcb, 0x70,
0x74, 0xfe, 0x7f, 0xa4, 0x12, 0x00, 0x00, 0xfe, 0x7f, 0x00, 0x00, 0x00,
0x00, 0x05, 0xf9, 0xb9, 0x1e, 0x00, 0x7f, 0x00, 0x13, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x4e, 0x24, 0x4e, 0x24, 0x00, 0x50, 0xff,
0x7f, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x30, 0x00,
0x30, 0x00, 0x70, 0x00, 0x26, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0xa0, 0x00, 0x00, 0x03, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x20, 0xff, 0x7f, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xff,
0x7f, 0x00, 0x78, 0x00, 0x08, 0x00, 0x00, 0x10, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0xff, 0x7f, 0x00, 0x40, 0x00, 0x40, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0xff, 0x7f, 0xff, 0x7f, 0x1b, 0x1c, 0xc3,
0x09, 0x80, 0x41, 0x42, 0xf0, 0x00, 0x10, 0x10, 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, 0x02, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0xcc, 0x59, 0x00, 0x00, 0x00, 0x40, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x0a, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x08, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0xff, 0x7f, 0xf6, 0x91, 0x14, 0xae, 0x08, 0x58, 0x26,
0x63, 0x7b, 0x19, 0x00, 0x20, 0x00, 0x88, 0x00, 0x40, 0x80, 0x41, 0x00,
0x7f, 0xff, 0x7f, 0xa6, 0x13, 0x00, 0x00, 0xff, 0x7f, 0x00, 0x00, 0x00,
0x00, 0x90, 0xcb, 0x70, 0x74, 0xfe, 0x7f, 0xa4, 0x12, 0x00, 0x00, 0xfe,
0x7f, 0x00, 0x00, 0x00, 0x00, 0x05, 0xf9, 0xb9, 0x1e, 0x00, 0x7f, 0x00,
0x13, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x4e, 0x24, 0x4e,
0x24, 0x00, 0x50, 0xff, 0x7f, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x30, 0x00, 0x30, 0x00, 0x70, 0x00, 0x26, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0xa0, 0x00, 0x00, 0x03, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x20, 0xff, 0x7f, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0xff, 0x7f, 0x00, 0x78, 0x00, 0x08, 0x00, 0x00, 0x10,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xff, 0x7f, 0x00, 0x40, 0x00,
0x40,
};
const unsigned short int DOWNLOAD_COEF_LEN = sizeof(DOWNLOAD_COEF);
#endif
@@ -0,0 +1,704 @@
/* SPDX-License-Identifier: GPL-2.0 */
/*
* Copyright (c) 2019 MediaTek Inc.
*/
#ifndef OIS_DEFINITION_H
#define OIS_DEFINITION_H
/* ================================================================= */
/* Common */
/* ================================================================= */
#define __ON_ 1
#define _OFF_ 0
#define __IN_ 1
#define _MON_ 2
#define _PWM32__ 3
#define _PWM3_1_ 4
#define _PWM3__0 5
#define _PWM_21_ 6
#define _PWM_2_0 7
#define _PWM__10 8
#define _PRN_ 4
#define _m_RSP 1
#define _m_CLK_GEN 2
#define _m_CLK_TRI 3
#define _m_I2C_SLV 4
#define _m_SPI_MAS 5
#define _m_PWM_CNT 6
#define _m_ADA_WRP 7
#define _m_EXT_SIG 8
#define _HIGH_ 1
#define __LOW_ 0
#define _FOCUS_ 1
#define _ZOOM__ 0
#define _FACTORY_ 1
#define _NORMADJ_ 2
#define _NORMAL__ 0
#define _NOT_READY 0
/* ================================================================= */
/* PIC uP port assign */
/* ================================================================= */
#define _PIO_O_L_ 0
#define _PIO_O_H_ 1
#define _PIO_INP_ 2
#define _PIC_RB_0_ 0x00
#define _PIC_RB_1_ 0x01
#define _PIC_RB_2_ 0x02
#define _PIC_RB_3_ 0x03
#define _PIC_RB_4_ 0x04
#define _PIC_RB_5_ 0x05
#define _PIC_RB_6_ 0x06
#define _PIC_RB_7_ 0x07
#define _PIC_RB_8_ 0x08
#define _PIC_RB_9_ 0x09
#define _PIC_RB_A_ 0x0A
#define _PIC_RB_B_ 0x0B
#define _PIC_RB_C_ 0x0C
#define _PIC_RB_D_ 0x0D
#define _PIC_RB_E_ 0x0E
#define _PIC_RB_F_ 0x0F
#define _PIC_RC_0_ 0x10
#define _PIC_RC_1_ 0x11
#define _PIC_RC_2_ 0x12
#define _PIC_RC_3_ 0x13
#define _PIC_RC_4_ 0x14
#define _PIC_RC_5_ 0x15
#define _PIC_RC_6_ 0x16
#define _PIC_RC_7_ 0x17
#define _PIC_RC_8_ 0x18
#define _PIC_RC_9_ 0x19
#define _PIC_RC_A_ 0x1A
#define _PIC_RC_B_ 0x1B
#define _PIC_RC_C_ 0x1C
#define _PIC_RC_D_ 0x1D
#define _PIC_RC_E_ 0x1E
#define _PIC_RC_F_ 0x1F
#define _PIC_RD_0_ 0x20
#define _PIC_RD_1_ 0x21
#define _PIC_RD_2_ 0x22
#define _PIC_RD_3_ 0x23
#define _PIC_RD_4_ 0x24
#define _PIC_RD_5_ 0x25
#define _PIC_RD_6_ 0x26
#define _PIC_RD_7_ 0x27
#define _PIC_RD_8_ 0x28
#define _PIC_RD_9_ 0x29
#define _PIC_RD_A_ 0x2A
#define _PIC_RD_B_ 0x2B
#define _PIC_RD_C_ 0x2C
#define _PIC_RD_D_ 0x2D
#define _PIC_RD_E_ 0x2E
#define _PIC_RD_F_ 0x2F
#define _PIC_RE_0_ 0x30
#define _PIC_RE_1_ 0x31
#define _PIC_RE_2_ 0x32
#define _PIC_RE_3_ 0x33
#define _PIC_RE_4_ 0x34
#define _PIC_RE_5_ 0x35
#define _PIC_RE_6_ 0x36
#define _PIC_RE_7_ 0x37
#define _PIC_RE_8_ 0x38
#define _PIC_RE_9_ 0x39
#define _PIC_RE_A_ 0x3A
#define _PIC_RE_B_ 0x3B
#define _PIC_RE_C_ 0x3C
#define _PIC_RE_D_ 0x3D
#define _PIC_RE_E_ 0x3E
#define _PIC_RE_F_ 0x3F
#define _PIC_RF_0_ 0x40
#define _PIC_RF_1_ 0x41
#define _PIC_RF_2_ 0x42
#define _PIC_RF_3_ 0x43
#define _PIC_RF_4_ 0x44
#define _PIC_RF_5_ 0x45
#define _PIC_RF_6_ 0x46
#define _PIC_RF_7_ 0x47
#define _PIC_RF_8_ 0x48
#define _PIC_RF_9_ 0x49
#define _PIC_RF_A_ 0x4A
#define _PIC_RF_B_ 0x4B
#define _PIC_RF_C_ 0x4C
#define _PIC_RF_D_ 0x4D
#define _PIC_RF_E_ 0x4E
#define _PIC_RF_F_ 0x4F
#define _PIC_RG_6_ 0x56
#define _PIC_AD_0_ 8
#define _PIC_AD_1_ 9
#define _PIC_AD_2_ 10
#define _PIC_AD_3_ 11
#define _PIC_AD_4_ 12
#define _PIC_AD_5_ 13
#define _PIC_AD_6_ 14
/* _picsig_PS_POL = _PIC_RB_8_ */
#define _picsig_PS____ _PIC_RE_5_
#define _picsig_TRIG__ _PIC_RE_4_
#define _picsig_AF____ _PIC_RC_E_
/* _picsig_Shutr_ = _PIC_RD_1_ */
#define _picsig_FPGAcs _PIC_RB_6_
/* _picsig_CRNR_0 = _PIC_RD_2_ */
/* _picsig_CRNR_1 = _PIC_RD_1_ */
/* _picsig_CRNR_2 = _PIC_RC_E_ */
/* _picsig_CRNR_3 = _PIC_RC_D_ */
/* ================================================================= */
/* OIS controller assign */
/* ================================================================= */
/* Slave Address */
#define _SLV_OIS_ 0x0E
/* Packet Command OP code */
#define _OP_FIRM_DWNLD 0x80
#define _OP_Periphe_RW 0x82
#define _OP_Memory__RW 0x84
#define _OP_AD_TRNSFER 0x86
#define _OP_COEF_DWNLD 0x88
#define _OP_PrgMem__RD 0x8A
#define _OP_SpecialCMD 0x8C
#define _cmd_8C_EI 0x0001
#define _cmd_8C_DI 0x0002
#define _cmd_8C_STRB 0x0004
#define _cmd_8C_TRI_SHT 0x0008
#define _cmd_8C_TRI_con 0x0010
#define _OP_FX_Cmnd_0 0xF0
#define _OP_FX_Cmnd_1 0xF1
#define _OP_FX_Cmnd_2 0xF2
#define _OP_FX_Cmnd_3 0xF3
#define _OP_FX_Cmnd_8 0xF8
#define _OP_FX_Cmnd_A 0xFA
/* Peripheral Adr Mapping */
#define _P_00_CLK_CONTRL 0x00
#define _P_01_CLK_PWMCNT 0x01
#define _P_02_CLK_TMRCNT 0x02
#define _P_03_CLK_DWNSMP 0x03
#define _P_04_CLK_CALDIV 0x04
#define _P_05_CLK_CLKSEL 0x05
#define _P_06_CLK_MONITR 0x06
/* _P_07) */
#define _P_08_TRI_CNTRL_ 0x08
#define _P_09_TRI_TARGET 0x09
#define _P_0A_TRI_PHSCNT 0x0A
/* _P_0B) */
/* _P_0C) */
/* _P_0D) */
/* _P_0E) */
/* _P_0F) */
#define _P_10_I2C_SLVADR 0x10
#define _P_11_I2C__DATA_ 0x11
#define _P_12_I2C_STSADR 0x12
#define _P_13_I2C_MONSEL 0x13
#define _P_14_I2C_OFSREG 0x14
/* _P_15) */
/* _P_16) */
/* _P_17) */
#define _P_18_SPI_TRSNUM 0x18
#define _P_19_SPI_CONTRL 0x19
/* _P_1A_SPI_D_000H = 0x1A */
#define _P_1A_SPI_D_HHHL 0x1B
#define _P_1B_SPI_D_LHLL 0x1C
/* _P_1B) */
/* _P_1C) */
/* _P_1D) */
/* _P_1E) */
/* _P_1F) */
#define _P_20_MSC_MONCTL1 0x20
#define _P_21_MSC_MONCTL2 0x21
#define _P_22_MSC_PORTCTL 0x22
#define _P_23_MSC_PORTSTS 0x23
#define _P_24_MSC_PWMREGA 0x24
#define _P_25_MSC_PWMREGB 0x25
#define _P_26_MSC_SIGMON 0x26
/* _P_27) */
#define _P_28_PWM_ENB_SR 0x28
#define _P_29_PWM_FRQSEL 0x29
#define _P_2A_PWM_SFT_YX 0x2A
#define _P_2B_PWM_SFT__Z 0x2B
#define _P_2C_PWM_ChX_DAT 0x2C
#define _P_2D_PWM_ChY_DAT 0x2D
#define _P_2E_PWM_ChZ_DAT 0x2E
#define _P_2F_PWM_SMPLSFT 0x2F
#define _P_30_ADC_CH0 0x30
#define _P_31_ADC_CH1 0x31
#define _P_32_ADC_CH2 0x32
#define _P_33_ADC_CH3 0x33
#define _P_34_ADC_CH4 0x34
#define _P_35_ADC_CH5 0x35
#define _P_36_ADC_CH6 0x36
#define _P_37_ADC_CH7 0x37
#define _P_38_Ch3_VAL_0 0x38
#define _P_39_Ch3_VAL_1 0x39
#define _P_3A_Ch3_VAL_2 0x3A
#define _P_3B_Ch3_VAL_3 0x3B
#define _P_3C_ADC_GAIN 0x3C
#define _P_3D_ADC_CTL 0x3D
/* _P_3E) */
/* _P_3F) */
#define _P_40_OUT_CH 0x40
#define _P_41_OUT_CTL 0x41
#define _P_42_OUT_DAC 0x42
#define _P_43_OUT_SW 0x43
/* _P_44) */
/* _P_45) */
/* _P_46) */
/* _P_47) */
#define _P_48_TOP_00 0x48
/* _P_49) */
/* _P_4A) */
/* _P_4B) */
/* _P_4C) */
/* _P_4D) */
/* _P_4E) */
/* _P_4F) */
#define _P_50_TST_TSTCMD 0x50
#define _P_51_TST_AF_SLP 0x51
#define _P_52_TST_AF_OFS 0x52
#define _P_53_TST_SH_SLP 0x53
#define _P_54_TST_OSC___ 0x54
#define _P_55_TST_VREF__ 0x55
#define _P_56_TST_MUXCRN 0x56
#define _P_57_TST_TSADAC 0x57
#define _P_58_TST_FIXHBR 0x58
#define _P_59_TST_SMPPWR 0x59
#define _P_5A_TST_MPXFIX 0x5A
/* _P_5B_) ,0x5B */
/* _P_5C_) ,0x5C */
/* _P_5D_) ,0x5D */
/* _P_5E_) ,0x5E */
#define _P_5F_TST_INFVER 0x5F
#define _P_F0_I2CnSTR 0xF0
#define _P_F1_I2CnSTR 0xF1
#define _P_F2_I2CnSTR 0xF2
#define _P_F3_I2CnSTR 0xF3
/* Memory Adr Mapping */
#define _M_Kgx01 0x00
#define _M_Kgx02 0x01
#define _M_Kgx03 0x02
#define _M_Kgx04 0x03
#define _M_wDgx00 0x04
#define _M_X_HPF0 0x05
#define _M_Kgx00 0x06
#define _M_wDgxof 0x07
#define _M_Kgx05 0x08
#define _M_Kgx06 0x09
#define _M_Kgx07 0x0A
#define _M_Kgx08 0x0B
#define _M_wDgx01 0x0C
#define _M_X_HPF1 0x0D
#define _M_KgxWv 0x0E
#define _M_KgxG 0x0F
#define _M_Kgx09 0x10
#define _M_Kgx0A 0x11
#define _M_Kgx0B 0x12
#define _M_Kgx0C 0x13
#define _M_wDgx02 0x14
#define _M_X_HPF2 0x15
#define _M_wDgx04 0x16
#define _M_X_TRGT 0x17
#define _M_Kgx0D 0x18
#define _M_Kgx0E 0x19
#define _M_Kgx0F 0x1A
#define _M_Kgx10 0x1B
#define _M_wDgx03 0x1C
#define _M_X_HPF3 0x1D
#define _M_X_H_ofs 0x1E
#define _M_X_wGIN 0x1F
#define _M_Kgx1F 0x20
#define _M_Kgx20 0x21
#define _M_Kgx21 0x22
#define _M_Kgx22 0x23
#define _M_wDgx0B 0x24
#define _M_wDgx_EQL1 0x25
#define _M_X_wGOU 0x26
#define _M_wDgx09 0x27
#define _M_Kgx1B 0x28
#define _M_Kgx1C 0x29
#define _M_Kgx1D 0x2A
#define _M_Kgx1E 0x2B
#define _M_wDgx0A 0x2C
#define _M_wDgx_EQH 0x2D
#define _M_X_wGAS 0x2E
#define _M_X_GYIN 0x2F
#define _M_Kgx23 0x30
#define _M_Kgx24 0x31
#define _M_Kgx25 0x32
#define _M_Kgx26 0x33
#define _M_wDgx0C 0x34
#define _M_wDgx_EQL 0x35
#define _M_Kgxdr 0x36
#define _M_X_axofs 0x37
#define _M_Kgx11 0x38
#define _M_Kgx12 0x39
#define _M_Kgx13 0x3A
#define _M_Kgx14 0x3B
#define _M_Kgx15 0x3C
#define _M_wDgx05 0x3D
#define _M_wDgx06 0x3E
#define _M_X_H_Lmt 0x3F
#define _M_X_LMT 0x40
#define _M_X_LMO 0x41
#define _M_X_DRP 0x42
#define _M_X_TGT 0x43
#define _M_Kgx19 0x44
#define _M_Kgx1A 0x45
#define _M_KgxHG 0x46
#define _M_KgxTG 0x47
#define _M_Kgx01t 0x48
#define _M_Kgx02t 0x49
#define _M_Kgx03t 0x4A
#define _M_Kgx04t 0x4B
#define _M_Kgx05t 0x4C
#define _M_wDgx01t 0x4D
#define _M_wDgx02t 0x4E
#define _M_wDgx_EQ 0x4F
/* #define _M_rsv 0x50 */
/* #define _M_rsv 0x51 */
/* #define _M_rsv 0x52 */
/* #define _M_rsv 0x53 */
/* #define _M_rsv 0x54 */
#define _M_DigGx 0x55
#define _M_DigGy 0x56
#define _M_CURIN 0x57
/* #define _M_rsv 0x58 */
/* #define _M_rsv 0x59 */
/* #define _M_rsv 0x5A */
/* #define _M_rsv 0x5B */
#define _M_wDf00 0x5C
#define _M_FOTRIM 0x5D
#define _M_CUROFS 0x5E
#define _M_Kf0A 0x5F
#define _M_wCRFED 0x60
#define _M_wFTRGT 0x61
#define _M_wFSUB 0x62
/* #define _M_rsv 0x63 */
#define _M_Kf0C 0x64
#define _M_wDf03 0x65
#define _M_rsv 0x66
#define _M_CUROFO 0x67
#define _M_Kf00 0x68
#define _M_Kf01 0x69
#define _M_TMP_X_ 0x6A /* RHM_HT 2013/11/25 Modified */
#define _M_TMP_Y_ 0x6B /* RHM_HT 2013/11/25 Modified */
#define _M_wDf01 0x6C
#define _M_AFLPF 0x6D
/* #define _M_rsv 0x6E */
/* #define _M_rsv 0x6F */
#define _M_KgxH0 0x70 /* RHM_HT 2013/11/25 Modified */
#define _M_X_PEO 0x71
#define _M_KgyH0 0x72 /* RHM_HT 2013/11/25 Modified */
#define _M_Y_PEO 0x73
#define _M_FOC_CNTRL 0x74
/* #define _M_rsv 0x75 */
#define _M_CEFTYP 0x76
#define _M_GYRSNS 0x77
#define _M_SHDAC0 0x78
#define _M_SHDAC1 0x79
#define _M_Ksh0 0x7A
#define _M_Ksh1 0x7B
#define _M_mon0 0x7C
#define _M_mon1 0x7D
#define _M_GLBFLG 0x7E
#define _M_EQCTL 0x7F
#define _M_Kgy01 0x80
#define _M_Kgy02 0x81
#define _M_Kgy03 0x82
#define _M_Kgy04 0x83
#define _M_wDgy00 0x84
#define _M_Y_HPF0 0x85
#define _M_Kgy00 0x86
#define _M_wDgyof 0x87
#define _M_Kgy05 0x88
#define _M_Kgy06 0x89
#define _M_Kgy07 0x8A
#define _M_Kgy08 0x8B
#define _M_wDgy01 0x8C
#define _M_Y_HPF1 0x8D
#define _M_KgyWv 0x8E
#define _M_KgyG 0x8F
#define _M_Kgy09 0x90
#define _M_Kgy0A 0x91
#define _M_Kgy0B 0x92
#define _M_Kgy0C 0x93
#define _M_wDgy02 0x94
#define _M_Y_HPF2 0x95
#define _M_wDgy04 0x96
#define _M_Y_TRGT 0x97
#define _M_Kgy0D 0x98
#define _M_Kgy0E 0x99
#define _M_Kgy0F 0x9A
#define _M_Kgy10 0x9B
#define _M_wDgy03 0x9C
#define _M_Y_HPF3 0x9D
#define _M_Y_H_ofs 0x9E
#define _M_Y_wGIN 0x9F
#define _M_Kgy1F 0xA0
#define _M_Kgy20 0xA1
#define _M_Kgy21 0xA2
#define _M_Kgy22 0xA3
#define _M_wDgy0B 0xA4
#define _M_wDgy_EQL1 0xA5
#define _M_Y_wGOU 0xA6
#define _M_wDgy09 0xA7
#define _M_Kgy1B 0xA8
#define _M_Kgy1C 0xA9
#define _M_Kgy1D 0xAA
#define _M_Kgy1E 0xAB
#define _M_wDgy0A 0xAC
#define _M_wDgy_EQH 0xAD
#define _M_Y_wGAS 0xAE
#define _M_Y_GYIN 0xAF
#define _M_Kgy23 0xB0
#define _M_Kgy24 0xB1
#define _M_Kgy25 0xB2
#define _M_Kgy26 0xB3
#define _M_wDgy0C 0xB4
#define _M_wDgy_EQL 0xB5
#define _M_Kgydr 0xB6
#define _M_Y_axofs 0xB7
#define _M_Kgy11 0xB8
#define _M_Kgy12 0xB9
#define _M_Kgy13 0xBA
#define _M_Kgy14 0xBB
#define _M_Kgy15 0xBC
#define _M_wDgy05 0xBD
#define _M_wDgy06 0xBE
#define _M_Y_H_Lmt 0xBF
#define _M_Y_LMT 0xC0
#define _M_Y_LMO 0xC1
#define _M_Y_DRP 0xC2
#define _M_Y_TGT 0xC3
#define _M_Kgy19 0xC4
#define _M_Kgy1A 0xC5
#define _M_KgyHG 0xC6
#define _M_KgyTG 0xC7
#define _M_Kgy01t 0xC8
#define _M_Kgy02t 0xC9
#define _M_Kgy03t 0xCA
#define _M_Kgy04t 0xCB
#define _M_Kgy05t 0xCC
#define _M_wDgy01t 0xCD
#define _M_wDgy02t 0xCE
#define _M_wDgy_EQ 0xCF
#define _M_ISRC0 0xD0
#define _M_ISRC1 0xD1
#define _M_ISRC2 0xD2
#define _M_ISRC3 0xD3
#define _M_ISRC4 0xD4
#define _M_ISRC5 0xD5
#define _M_ISRC6 0xD6
#define _M_ISRC7 0xD7
#define _M_ISRC8 0xD8
#define _M_ISRC9 0xD9
#define _M_ISRCA 0xDA
#define _M_ISRCB 0xDB
#define _M_ISRCC 0xDC
#define _M_ISRCD 0xDD
#define _M_ISRCE 0xDE
#define _M_ISRCF 0xDF
#define _M_Kgy16 0xE0
#define _M_Kgy17 0xE1
#define _M_Kgy18 0xE2
#define _M_0x0000 0xE3
#define _M_0x8000 0xE4
#define _M_wDgy07 0xE5
#define _M_wDgy08 0xE6
#define _M_VMTRGT 0xE7
#define _M_Kv00 0xE8
#define _M_Kv01 0xE9
#define _M_Kv02 0xEA
#define _M_Kv03 0xEB
#define _M_wDv00 0xEC
#define _M_VMLPF 0xED
#define _M_wDv01 0xEE
#define _M_Kv04 0xEF
#define _M_SHND_sts 0xF0
#define _M_SHND_tim_org 0xF1
#define _M_SHND_tim 0xF2
#define _M_SHND_CWCCW 0xF3
#define _M_BPFOUT 0xF4
#define _M_BPFMON 0xF5
#define _M_FIRMVER 0xF6
#define _M_OIS_STS 0xF7
#define _def_OIS____________BOOT 0x00
#define _def_OIS__while_FWdwnlod 0x01
#define _def_OIS__FW_NG_NG_NG_NG 0x02
#define _def_OIS____________FWOK 0x03
#define _def_OIS_main_______IDLE 0x04
#define _M_I2C_dat 0xF8
#define _M_I2C_cmd 0xF9
#define _M_I2C_STS 0xFA
#define _M____tmp4 0xFB
#define _M____tmp3 0xFC
#define _M____tmp2 0xFD
#define _M____tmp1 0xFE
#define _M____tmp0 0xFF
/* ================================================================= */
/* Another definition */
/* ================================================================= */
/* Scene parameter */
#define _SCENE_NIGHT_1 1
#define _SCENE_NIGHT_2 2
#define _SCENE_NIGHT_3 3
#define _SCENE_D_A_Y_1 4
#define _SCENE_D_A_Y_2 5
#define _SCENE_D_A_Y_3 6
#define _SCENE_SPORT_1 7
#define _SCENE_SPORT_2 8
#define _SCENE_SPORT_3 9
#define _SCENE_TEST___ 10
/* for Factory Adjustment */
#define _CUR100mA 0x00A0
#define _CUR125mA 0x00C8
#define _CUR150mA 0x00F0
#define _CUR175mA 0x0118
#define _CUR200mA 0x0140
#define _CUR225mA 0x0168
#define _CUR250mA 0x0190
#define _CUR275mA 0x01B8
#define _CUR300mA 0x01E0
#define _CUR325mA 0x0208
#define _CUR350mA 0x0230
#define _CUR375mA 0x0258
#define _CUR400mA 0x0280
#define _VHTRGT 0x0BA2
#define _OTHR_IN_HALPX 0x0006
#define _OTHR_IN_HALPY 0x0008
#define _OTHR_HXpreOUT 0x0001
#define _OTHR_HYpreOUT 0x0002
/* Factory Adjustment data */
struct _FACT_ADJ {
unsigned short int gl_CURDAT;
unsigned short int gl_HALOFS_X;
unsigned short int gl_HALOFS_Y;
unsigned short int gl_HX_OFS;
unsigned short int gl_HY_OFS;
unsigned short int gl_PSTXOF;
unsigned short int gl_PSTYOF;
unsigned short int gl_GX_OFS;
unsigned short int gl_GY_OFS;
unsigned short int gl_KgxHG;
unsigned short int gl_KgyHG;
unsigned short int gl_KGXG;
unsigned short int gl_KGYG;
unsigned short int gl_SFTHAL_X; /* RHM_HT 2013/11/25 Added */
unsigned short int gl_SFTHAL_Y; /* RHM_HT 2013/11/25 Added */
unsigned short int gl_TMP_X_; /* RHM_HT 2013/11/25 Added */
unsigned short int gl_TMP_Y_; /* RHM_HT 2013/11/25 Added */
unsigned short int gl_KgxH0; /* RHM_HT 2013/11/25 Added */
unsigned short int gl_KgyH0; /* RHM_HT 2013/11/25 Added */
};
/* Default Parameter of FACTORY Adjust data */
/* --------------------------------------------- */
extern const struct _FACT_ADJ FADJ_DEF
#ifdef OIS_MAIN_C
= {
0x0200, /* gl_CURDAT; */
0x0200, /* gl_HALOFS_X; */
0x0200, /* gl_HALOFS_Y; */
0x0000, /* gl_HX_OFS; */
0x0000, /* gl_HY_OFS; */
0x0080,
0x0080,
0x0000, /* gl_GX_OFS; */
0x0000, /* gl_GY_OFS; */
0x2000,
0x2000,
0x2000,
0x2000,
0x0200,
0x0200,
0x0000,
0x0000,
0x0000,
0x0000,
}
#endif
;
/* FACTORY Adjusted data */
/* These data are stored at the non-vollatile */
/* memory inside of the CMOS sensor. */
/* The Host ( ISP or I2C master ) read these */
/* data from above memory and write to the OIS */
/* controller. */
/* --------------------------------------------- */
extern struct _FACT_ADJ FADJ_MEM
#ifdef OIS_MAIN_C
= {
0x0201, /* gl_CURDAT; */
0x0200, /* gl_HALOFS_X; */
0x0200, /* gl_HALOFS_Y; */
0x0000, /* gl_HX_OFS; */
0x0000, /* gl_HY_OFS; */
0x0080,
0x0080,
0x0000, /* gl_GX_OFS; */
0x0000, /* gl_GY_OFS; */
0x2000,
0x2000,
0x2000,
0x2000,
0x0200,
0x0200,
0x0000,
0x0000,
0x0000,
0x0000,
}
#endif
;
/* Parameters for expanding OIS range */
/* --------------------------------------------- */
extern double p_x, q_x;
extern double p_y, q_y;
extern short int zero_X;
extern short int zero_Y;
extern short int PREOUT_X_P, PREOUT_X_N;
extern short int PREOUT_Y_P, PREOUT_Y_N;
extern double alfa_X, beta_X;
extern double alfa_Y, beta_Y;
#endif /* OIS_DEFINITION_H */
@@ -0,0 +1,35 @@
/* SPDX-License-Identifier: GPL-2.0 */
/*
* Copyright (c) 2019 MediaTek Inc.
*/
#ifndef OIS_FUNC_H
#define OIS_FUNC_H
extern unsigned short int OIS_REQUEST; /* OIS control register. */
/* ==> RHM_HT 2013.03.04 Change type (unsigned short int -> double) */
extern double OIS_PIXEL[2]; /* Just Only use for factory adjustment. */
/* <== RHM_HT 2013.03.04 */
extern short int CROP_X; /* x start position for cropping */
extern short int CROP_Y; /* y start position for cropping */
extern short int CROP_WIDTH; /* cropping width */
extern short int CROP_HEIGHT; /* cropping height */
extern unsigned char SLICE_LEVE; /* slice level of bitmap binalization */
extern double DISTANCE_BETWEEN_CIRCLE;
extern double DISTANCE_TO_CIRCLE; /* distance to the circle [mm] */
extern double D_CF; /* Correction Factor for distance to the circle */
extern unsigned short int ACT_DRV; /* [mV]: Full Scale of OUTPUT DAC. */
extern unsigned short int FOCAL_LENGTH; /* [um]: Focal Length 3.83mm */
extern double MAX_OIS_SENSE;
extern double MIN_OIS_SENSE;
extern unsigned short int MAX_COIL_R; /* [ohm]: Max value of coil resistance */
extern unsigned short int MIN_COIL_R; /* [ohm]: Min value of coil resistance */
/* <== RHM_HT 2013/07/10 Added new user definition variables */
#endif
@@ -0,0 +1,200 @@
/* SPDX-License-Identifier: GPL-2.0 */
/*
* Copyright (c) 2019 MediaTek Inc.
*/
#ifndef OIS_MAIN_H
#define OIS_MAIN_H
/* Compile Switch Purpose */
#define ENABLE_GYRO_DRIFT_COMP /* RHM_HT 2013/11/25 Added */
#define _STR_AREA_ "F:\\DEBUGBMP\\" /* For Image save (Debug purpose) */
/* ==> RHM_HT 2013/04/15 Add to the report for error details */
/* #define OIS_TRUE 0 */
/* #define OIS_FALSE -1 */
/* #define OIS_READY 1 */
#define ADJ_OK 0
#define ADJ_ERR -1
#define PROG_DL_ERR -2
#define COEF_DL_ERR -3
#define CURDAT_FIT_ERR -4
#define CURDAT_ADJ_ERR -5
#define HALOFS_X_ADJ_ERR -6
#define HALOFS_Y_ADJ_ERR -7
#define PSTXOF_FIT_ERR -8
#define PSTYOF_FIT_ERR -9
#define PSTXOF_ADJ_ERR -10
#define PSTYOF_ADJ_ERR -11
#define KGXG_ROUGH_ADJ_ERR -12
#define KGYG_ROUGH_ADJ_ERR -13
#define GX_OFS_ADJ_ERR -14
#define GY_OFS_ADJ_ERR -15
#define TAKE_PICTURE_ERR -20
#define KGXG_FINE_ADJ_ERR -21
#define KGYG_FINE_ADJ_ERR -22
#define KGXG_SENSITIVITY_ERR -23
#define KGYG_SENSITIVITY_ERR -24
#define KGXHG_ADJ_ERR -25
#define KGYHG_ADJ_ERR -26
#define ACGX_ADJ_OVER_P -27
#define ACGY_ADJ_OVER_P -28
#define ACGX_ADJ_OVER_N -29
#define ACGY_ADJ_OVER_N -30
#define ACGX_KGXG_ADJ_ERR -31
#define ACGY_KGYG_ADJ_ERR -32
#define TMP_X_ADJ_ERR -33 /* RHM_HT 2013/11/25 Added */
#define TMP_Y_ADJ_ERR -34 /* RHM_HT 2013/11/25 Added */
#define MALLOC1_ERR -51
#define MALLOC2_ERR -52
#define MALLOC3_ERR -53
#define MALLOC4_ERR -54
/* Error for sub-routine */
#define OIS_NO_ERROR ADJ_OK
#define OIS_INVALID_PARAMETERS -100
#define OIS_FILE_RENAME_ERROR -101
#define OIS_FILE_NOT_FOUND -102
#define OIS_BITMAP_READ_ERROR -103
#define OIS_MATRIX_INV_ERROR -104
#define OIS_SC2_XLIMIT_OVER -105
#define OIS_CHART_ARRAY_OVER -106
#define OIS_DC_GAIN_SENS_OVER -107
#define OIS_MALLOC1_ERROR -111
#define OIS_MALLOC2_ERROR -112
#define OIS_MALLOC3_ERROR -113
#define OIS_MALLOC4_ERROR -114
#define OIS_MALLOC5_ERROR -115
#define OIS_MALLOC6_ERROR -116
#define OIS_MALLOC7_ERROR -117
#define OIS_MALLOC8_ERROR -118
#define OIS_MALLOC9_ERROR -119
#define OIS_MALLOC10_ERROR -120
#define OIS_MALLOC11_ERROR -121
#define OIS_MALLOC12_ERROR -122
#define OIS_MALLOC13_ERROR -123
#define OIS_MALLOC14_ERROR -124 /* RHM_HT 2013/11/25 add */
struct _BMP_GET_POS {
short int x; /* x start position for clipping */
short int y; /* y start position for clipping */
short int width; /* clipping width */
short int height; /* clipping height */
unsigned char slice_level; /* slice level of bitmap binalization */
unsigned char filter; /* median filter enable */
char *direction; /* direction of detection */
};
struct _POS {
float x;
float y;
};
struct _APPROXRESULT {
double a; /* position x */
double b; /* position y */
double r; /* Radius */
};
#include "OIS_defi.h"
/* #include "windef.h" */
#define Wait(a) Wait_usec(a * 1000UL)
short int func_PROGRAM_DOWNLOAD(void);
void func_COEF_DOWNLOAD(unsigned short int u16_coef_type);
void download(unsigned short int u16_type, unsigned short int u16_coef_type);
short int func_SET_SCENE_PARAM(unsigned char u16_scene, unsigned char u16_mode,
unsigned char filter, unsigned char range,
const struct _FACT_ADJ *param);
void SET_FADJ_PARAM(const struct _FACT_ADJ *param);
short int func_SET_SCENE_PARAM_for_NewGYRO_Fil(unsigned char u16_scene,
unsigned char u16_mode,
unsigned char filter,
unsigned char range,
const struct _FACT_ADJ *param);
void HalfShutterOn(void);
void I2C_OIS_per_write(unsigned char u08_adr, unsigned short int u16_dat);
void I2C_OIS_mem_write(unsigned char u08_adr, unsigned short int u16_dat);
unsigned short int I2C_OIS_per__read(unsigned char u08_adr);
unsigned short int I2C_OIS_mem__read(unsigned char u08_adr);
void I2C_OIS_spcl_cmnd(unsigned char u08_on, unsigned char u08_dat);
void I2C_OIS_F0123_wr_(unsigned char u08_dat0, unsigned char u08_dat1,
unsigned short int u16_dat2);
unsigned short int I2C_OIS_F0123__rd(void);
void POWER_UP_AND_PS_DISABLE(void);
void POWER_DOWN_AND_PS_ENABLE(void);
void VCOSET0(void);
void VCOSET1(void);
void WR_I2C(unsigned char slvadr, unsigned char size, unsigned char *dat);
unsigned short int RD_I2C(unsigned char slvadr, unsigned char size,
unsigned char *dat);
void store_FADJ_MEM_to_non_volatile_memory(struct _FACT_ADJ param);
struct _FACT_ADJ get_FADJ_MEM_from_non_volatile_memory(void);
void Wait_usec(unsigned long time);
extern void Main_OIS(void);
extern void OIS_Standby(void);
extern int setVCMPos(unsigned short DAC_Val);
extern void setOISMode(int Disable);
extern int s4EEPROM_ReadReg_BU63165AF(unsigned short addr,
unsigned short *data);
extern int s4AF_WriteReg_BU63165AF(unsigned short i2c_id,
unsigned char *a_pSendData,
unsigned short a_sizeSendData);
extern int s4AF_ReadReg_BU63165AF(unsigned short i2c_id,
unsigned char *a_pSendData,
unsigned short a_sizeSendData,
unsigned char *a_pRecvData,
unsigned short a_sizeRecvData);
/* #define DEBUG_FADJ */
#ifdef DEBUG_FADJ
int debug_print(const char *format,
...); /* RHM_HT 2013/04/15 Add for DEBUG */
#define DEBUG_printf(a) debug_print a
#else
#define DEBUG_printf(a)
#endif
#endif /* OIS_MAIN_H */
@@ -0,0 +1,273 @@
/* SPDX-License-Identifier: GPL-2.0 */
/*
* Copyright (c) 2019 MediaTek Inc.
*/
#ifndef OIS_PROG_H
#define OIS_PROG_H
const unsigned char DOWNLOAD_BIN[] = {
0x00, 0x41, 0x54, 0x00, 0x03, 0xFF, 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, 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, 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,
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, 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, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x03, 0x00, 0x10, 0x7E,
0x84, 0x50, 0x00, 0x08, 0x40, 0x7E, 0xA0, 0x00, 0x03, 0x00, 0x10, 0x7E,
0x84, 0x60, 0x00, 0x08, 0x40, 0x7E, 0xA0, 0x00, 0x03, 0x00, 0x90, 0x00,
0x84, 0x00, 0x10, 0x08, 0x80, 0x00, 0xA0, 0x10, 0x00, 0x08, 0x7F, 0xFF,
0x11, 0x8F, 0x02, 0x07, 0x80, 0x00, 0x11, 0x40, 0xFF, 0xA0, 0x90, 0x01,
0x84, 0x20, 0x8F, 0x08, 0x40, 0xFE, 0x90, 0x40, 0xF5, 0xA0, 0x00, 0x00,
0x08, 0x80, 0x01, 0xA0, 0x00, 0x01, 0x11, 0x8F, 0x02, 0x07, 0xFF, 0xFF,
0x11, 0x08, 0x00, 0x20, 0x50, 0x12, 0x07, 0x00, 0x10, 0x08, 0x80, 0x00,
0xA0, 0x10, 0xFF, 0x84, 0x20, 0x0A, 0x08, 0x7F, 0xFF, 0x21, 0x08, 0xFE,
0x84, 0x00, 0x04, 0x07, 0x20, 0x0C, 0x08, 0x7F, 0xFF, 0x21, 0x08, 0xFE,
0x84, 0x00, 0x03, 0x00, 0x90, 0x17, 0x84, 0x20, 0x1F, 0x08, 0x80, 0x17,
0xA0, 0x10, 0x10, 0x08, 0x7F, 0xFF, 0x21, 0x10, 0x00, 0x08, 0x01, 0x00,
0x11, 0x40, 0x51, 0xA0, 0x90, 0x17, 0x84, 0x20, 0x0F, 0x08, 0x80, 0x47,
0xA0, 0x8D, 0x0C, 0x07, 0x00, 0x00, 0x11, 0x30, 0x03, 0x07, 0x80, 0x41,
0x90, 0x50, 0x00, 0x08, 0x40, 0xFC, 0x90, 0x88, 0x2F, 0x84, 0x00, 0x00,
0x11, 0x30, 0x02, 0x07, 0x40, 0xFF, 0x90, 0x50, 0x00, 0x08, 0x40, 0xFD,
0x90, 0x40, 0x7F, 0xA0, 0x10, 0xFF, 0x84, 0x20, 0x2C, 0x08, 0x7F, 0xFF,
0x11, 0x20, 0x0D, 0x08, 0x80, 0x0F, 0x90, 0x80, 0x26, 0xA0, 0x90, 0x2E,
0x84, 0x00, 0x10, 0x08, 0x90, 0x26, 0x84, 0x00, 0x10, 0x08, 0x80, 0x1F,
0xA0, 0x20, 0x2E, 0x08, 0x40, 0xED, 0x90, 0x20, 0x0F, 0x08, 0x80, 0x0E,
0x90, 0x00, 0x00, 0x21, 0x30, 0x02, 0x07, 0x40, 0xEB, 0xA0, 0x50, 0x00,
0x08, 0x40, 0xFE, 0x90, 0x40, 0x7F, 0xA0, 0x04, 0xEB, 0x84, 0x10, 0x00,
0x20, 0x20, 0x0F, 0x08, 0x80, 0x00, 0x21, 0x60, 0x04, 0x07, 0x40, 0xFF,
0xA0, 0x10, 0x00, 0x08, 0x40, 0xEA, 0x90, 0x10, 0x00, 0x20, 0x20, 0x0F,
0x08, 0x80, 0x00, 0x11, 0x00, 0x0B, 0x07, 0x08, 0x00, 0x20, 0x60, 0x0D,
0x07, 0x10, 0x00, 0x08, 0x40, 0xEA, 0x90, 0x8F, 0x06, 0x07, 0x04, 0xFF,
0x84, 0x20, 0x09, 0x60, 0x10, 0xFC, 0x84, 0x08, 0xFD, 0x84, 0x04, 0xFE,
0x84, 0x00, 0x03, 0x00, 0x00, 0x10, 0x08, 0x80, 0x37, 0xA0, 0x90, 0x69,
0x84, 0x00, 0x10, 0x08, 0x80, 0x69, 0xA0, 0x20, 0x1A, 0x08, 0x40, 0x64,
0xA0, 0x10, 0x10, 0x08, 0x80, 0x4F, 0xA0, 0x20, 0x1D, 0x08, 0x40, 0x5F,
0xA0, 0x20, 0x1E, 0x08, 0x40, 0x5D, 0xA0, 0x10, 0x00, 0x08, 0x80, 0x68,
0x90, 0x40, 0xFE, 0xA0, 0x20, 0x0E, 0x07, 0x50, 0x00, 0x08, 0x40, 0x7F,
0xA0, 0x04, 0xFE, 0x84, 0x00, 0x04, 0x00, 0x10, 0xF0, 0x44, 0x50, 0x00,
0x08, 0x00, 0x7F, 0x11, 0x20, 0xF0, 0x60, 0x04, 0x5C, 0x84, 0x04, 0x61,
0x84, 0x04, 0x57, 0x84, 0x00, 0x00, 0x21, 0x04, 0x74, 0x84, 0x00, 0x40,
0x21, 0x00, 0x0B, 0x07, 0x04, 0x74, 0x84, 0x00, 0x00, 0x21, 0x10, 0x57,
0x84, 0x10, 0x20, 0x08, 0x40, 0x00, 0x11, 0x30, 0x20, 0x08, 0x00, 0x05,
0x11, 0x50, 0x00, 0x08, 0x03, 0xFF, 0x11, 0x20, 0xFA, 0x60, 0x10, 0xF0,
0x44, 0x50, 0x20, 0x08, 0x00, 0x7F, 0x11, 0x60, 0x20, 0x08, 0x40, 0x00,
0x08, 0x00, 0x08, 0x11, 0x30, 0x1C, 0x07, 0x50, 0x00, 0x08, 0x07, 0x00,
0x11, 0x9F, 0x1F, 0x07, 0x8B, 0x20, 0x07, 0x9C, 0x17, 0x07, 0x20, 0xF8,
0x60, 0x10, 0x28, 0x44, 0x60, 0x00, 0x08, 0x01, 0x00, 0x11, 0x20, 0x28,
0x60, 0x87, 0x1D, 0x07, 0x40, 0xF7, 0xA0, 0x81, 0x29, 0x07, 0x20, 0x48,
0x60, 0x10, 0x0A, 0x44, 0x10, 0xF4, 0x84, 0x3B, 0xC2, 0x00, 0xE0, 0x14,
0x43, 0x08, 0x00, 0x20, 0x00, 0x06, 0x07, 0x89, 0x02, 0x07, 0x40, 0xAE,
0x90, 0x81, 0x04, 0x07, 0x40, 0x2E, 0x90, 0x40, 0x7F, 0xA0, 0x10, 0x2E,
0x44, 0x10, 0x2E, 0x44, 0x00, 0x00, 0x08, 0x40, 0x67, 0xA0, 0x00, 0x00,
0x11, 0x84, 0x02, 0x07, 0x20, 0xF0, 0x60, 0x9F, 0x03, 0x07, 0x40, 0x7E,
0xA0, 0x40, 0x65, 0x90, 0x10, 0x62, 0x84, 0x10, 0x10, 0x08, 0x40, 0x61,
0xA0, 0x20, 0x1D, 0x08, 0x40, 0x5F, 0xA0, 0x20, 0x1E, 0x08, 0x40, 0x5D,
0xA0, 0x10, 0x00, 0x08, 0x40, 0x5E, 0x90, 0x20, 0x30, 0x60, 0x10, 0xCF,
0x84, 0x20, 0x1C, 0x08, 0x7F, 0xFF, 0x21, 0x3B, 0xE2, 0x00, 0xC8, 0x14,
0x43, 0x10, 0x00, 0x20, 0x00, 0x00, 0x08, 0x40, 0xB5, 0x90, 0x40, 0xAD,
0xA0, 0x00, 0x0A, 0x07, 0x10, 0x4F, 0x84, 0x20, 0x1C, 0x08, 0x7F, 0xFF,
0x21, 0x3B, 0xEC, 0x00, 0x48, 0x14, 0x43, 0x10, 0x00, 0x20, 0x00, 0x00,
0x08, 0x40, 0x35, 0x90, 0x40, 0x2D, 0xA0, 0x00, 0x14, 0x07, 0x80, 0x0C,
0x07, 0x82, 0x03, 0x07, 0x04, 0x50, 0x84, 0x10, 0x00, 0x20, 0x20, 0x02,
0x07, 0x00, 0x08, 0x21, 0x40, 0x00, 0x08, 0x00, 0x01, 0x11, 0x40, 0x50,
0xA0, 0x00, 0x04, 0x00, 0x20, 0x7E, 0x00, 0x80, 0x14, 0x43, 0x01, 0x00,
0x01, 0x04, 0x00, 0x11, 0x02, 0x00, 0x21, 0x10, 0x9F, 0x84, 0x10, 0x20,
0x08, 0x40, 0x97, 0x90, 0x10, 0xBF, 0x84, 0x20, 0x1D, 0x08, 0x40, 0xC6,
0xA0, 0x20, 0x8E, 0x08, 0x40, 0x72, 0x90, 0x40, 0x16, 0xA0, 0x10, 0x96,
0x84, 0x10, 0x00, 0x08, 0x40, 0x9E, 0x90, 0x20, 0x36, 0x60, 0x20, 0x90,
0x00, 0x00, 0x14, 0x43, 0x00, 0x01, 0x01, 0x00, 0x04, 0x11, 0x00, 0x02,
0x21, 0x10, 0x1F, 0x84, 0x10, 0x20, 0x08, 0x40, 0x17, 0x90, 0x10, 0x3F,
0x84, 0x20, 0x1D, 0x08, 0x40, 0x46, 0xA0, 0x20, 0x8E, 0x08, 0x40, 0x70,
0x90, 0x40, 0x96, 0xA0, 0x10, 0x16, 0x84, 0x10, 0x00, 0x08, 0x40, 0x1E,
0x90, 0x20, 0x34, 0x60, 0x10, 0x65, 0x84, 0x50, 0x10, 0x08, 0x00, 0x00,
0x21, 0x84, 0x03, 0x07, 0x20, 0xF0, 0x60, 0x9F, 0x03, 0x07, 0x40, 0x7E,
0xA0, 0x00, 0x10, 0x08, 0x40, 0x65, 0xA0, 0x20, 0x0D, 0x08, 0x40, 0x64,
0x90, 0x40, 0x62, 0xA0, 0x00, 0x04, 0x00, 0x04, 0x1C, 0x44, 0x04, 0x1B,
0x44, 0xC3, 0xFF, 0x21, 0x87, 0x04, 0x07, 0x40, 0x7F, 0xA0, 0x10, 0x42,
0x84, 0x20, 0x1E, 0x08, 0x7F, 0xFF, 0x21, 0x10, 0x20, 0x08, 0x40, 0x1C,
0x90, 0x10, 0x07, 0x84, 0x10, 0x00, 0x08, 0x40, 0x06, 0x90, 0x40, 0x55,
0xA0, 0x10, 0xC2, 0x84, 0x20, 0x1E, 0x08, 0x7F, 0xFF, 0x21, 0x10, 0x20,
0x08, 0x40, 0x9C, 0x90, 0x10, 0x87, 0x84, 0x10, 0x00, 0x08, 0x40, 0x86,
0x90, 0x40, 0x56, 0xA0, 0x10, 0x56, 0x84, 0x20, 0x0F, 0x08, 0x40, 0x7B,
0x90, 0x22, 0x00, 0x60, 0x40, 0x00, 0x08, 0x40, 0x79, 0xA0, 0x00, 0x08,
0x11, 0x10, 0x55, 0x84, 0x20, 0x0F, 0x08, 0x40, 0x7A, 0x90, 0x22, 0x00,
0x60, 0x50, 0x00, 0x08, 0x40, 0x79, 0xA0, 0x00, 0xFF, 0x11, 0x04, 0x6F,
0x84, 0x00, 0x05, 0x21, 0x21, 0x38, 0x00, 0x04, 0x00, 0x11, 0x10, 0xC1,
0x84, 0x20, 0x0F, 0x08, 0x70, 0x07, 0x07, 0x10, 0x10, 0x08, 0x40, 0xC0,
0xA0, 0x20, 0x0F, 0x08, 0x7F, 0xFF, 0x11, 0x8F, 0x02, 0x07, 0x80, 0x00,
0x11, 0x08, 0x00, 0x20, 0x08, 0xC1, 0x84, 0x40, 0xBD, 0x90, 0x9E, 0x02,
0x07, 0x40, 0x7F, 0xA0, 0x40, 0xEC, 0x90, 0x04, 0x6E, 0x84, 0x00, 0x05,
0x21, 0x21, 0x4B, 0x00, 0x00, 0x04, 0x11, 0x10, 0x41, 0x84, 0x20, 0x0F,
0x08, 0x70, 0x07, 0x07, 0x10, 0x10, 0x08, 0x40, 0x40, 0xA0, 0x20, 0x0F,
0x08, 0x7F, 0xFF, 0x11, 0x8F, 0x02, 0x07, 0x80, 0x00, 0x11, 0x08, 0x00,
0x20, 0x08, 0x41, 0x84, 0x40, 0x3D, 0x90, 0x9E, 0x02, 0x07, 0x40, 0x7F,
0xA0, 0x40, 0x6D, 0x90, 0x10, 0x2D, 0x44, 0x20, 0xE6, 0x00, 0x08, 0x00,
0x11, 0x20, 0x32, 0x60, 0x80, 0x14, 0x43, 0x10, 0x2C, 0x44, 0x20, 0xEB,
0x00, 0x00, 0x08, 0x11, 0x20, 0x31, 0x60, 0x00, 0x14, 0x43, 0x04, 0x34,
0x44, 0x40, 0x5B, 0xA0, 0x00, 0x04, 0x00, 0x21, 0x69, 0x00, 0x80, 0x00,
0x11, 0x21, 0x6F, 0x00, 0x3F, 0xFF, 0x11, 0x08, 0xE8, 0x84, 0x20, 0x32,
0x50, 0x08, 0x68, 0x84, 0x20, 0x31, 0x50, 0x08, 0x5E, 0x84, 0x20, 0x30,
0x50, 0x0F, 0xC4, 0x07, 0x10, 0x34, 0x44, 0x10, 0x5B, 0x84, 0x6F, 0xF3,
0x07, 0x00, 0x00, 0x08, 0x02, 0x00, 0x21, 0x40, 0xFC, 0x90, 0x3D, 0xBF,
0x00, 0x04, 0xFC, 0x84, 0x00, 0x00, 0x21, 0x04, 0xFD, 0x84, 0x00, 0x08,
0x21, 0x00, 0x04, 0x00, 0x21, 0x80, 0x00, 0xC0, 0x00, 0x11, 0x04, 0x5B,
0x84, 0x02, 0x00, 0x21, 0x70, 0x06, 0x07, 0x10, 0xFE, 0x84, 0x30, 0x20,
0x08, 0x00, 0x03, 0x11, 0x10, 0x00, 0x08, 0x40, 0x59, 0x90, 0x04, 0xFF,
0x84, 0x40, 0x58, 0xA0, 0x10, 0x59, 0x84, 0x20, 0x0F, 0x08, 0x40, 0x59,
0xA0, 0x20, 0x00, 0x11, 0x70, 0x1E, 0x07, 0x10, 0x00, 0x08, 0x00, 0x0B,
0x11, 0x0F, 0xE4, 0x07, 0x10, 0x59, 0x84, 0x00, 0x00, 0x08, 0x20, 0x30,
0x50, 0x40, 0x59, 0xA0, 0x70, 0x06, 0x07, 0x10, 0x00, 0x08, 0x00, 0x0A,
0x11, 0x0F, 0xEC, 0x07, 0x08, 0x34, 0x44, 0x02, 0x10, 0x11, 0x10, 0x58,
0x84, 0x20, 0x0F, 0x08, 0x40, 0x58, 0xA0, 0x20, 0x00, 0x11, 0x30, 0x08,
0x07, 0x0F, 0xF4, 0x07, 0x10, 0x58, 0x84, 0x00, 0x00, 0x08, 0x20, 0x30,
0x50, 0x40, 0x58, 0xA0, 0x70, 0x06, 0x07, 0x10, 0x00, 0x08, 0x00, 0x05,
0x11, 0x00, 0x04, 0x00, 0x10, 0x5A, 0x84, 0x00, 0x00, 0x08, 0x00, 0x01,
0x11, 0x40, 0x5A, 0xA0, 0x08, 0x34, 0x44, 0x02, 0x00, 0x11, 0x30, 0x08,
0x07, 0x60, 0x00, 0x08, 0x00, 0x00, 0x11, 0x40, 0x5A, 0xA0, 0x8F, 0x4F,
0x07, 0x40, 0x7E, 0xA0, 0x00, 0x04, 0x00, 0x3C, 0xC8, 0x00, 0x10, 0x00,
0x20, 0xA8, 0x14, 0x43, 0x04, 0xA7, 0x84, 0x20, 0x8E, 0x08, 0x40, 0xC4,
0x90, 0x40, 0xAF, 0xA0, 0x20, 0x0F, 0x08, 0x40, 0xC5, 0x90, 0x40, 0xA7,
0xA0, 0x3C, 0xD2, 0x00, 0x10, 0x00, 0x20, 0x28, 0x14, 0x43, 0x04, 0x27,
0x84, 0x20, 0x8E, 0x08, 0x40, 0x44, 0x90, 0x40, 0x2F, 0xA0, 0x20, 0x0F,
0x08, 0x40, 0x45, 0x90, 0x40, 0x27, 0xA0, 0x00, 0x04, 0x00, 0x10, 0xF0,
0x44, 0x50, 0x00, 0x08, 0xFF, 0xF7, 0x11, 0x93, 0x04, 0x07, 0x20, 0xF0,
0x60, 0x04, 0x61, 0x84, 0x04, 0x5C, 0x84, 0x40, 0x57, 0xA0, 0x00, 0x04,
0x00, 0x10, 0x61, 0x84, 0x00, 0x20, 0x08, 0x20, 0x1F, 0x08, 0x40, 0xFF,
0xA0, 0x10, 0x00, 0x08, 0x40, 0x5C, 0x90, 0x40, 0x57, 0xA0, 0x04, 0x74,
0x84, 0x10, 0x00, 0x20, 0x00, 0x00, 0x08, 0x40, 0x74, 0xA0, 0x00, 0x01,
0x11, 0x20, 0x05, 0x07, 0x00, 0x40, 0x21, 0x70, 0x00, 0x08, 0x7F, 0xFF,
0x21, 0x08, 0xFF, 0x84, 0x42, 0x00, 0x90, 0x85, 0x02, 0x07, 0x20, 0xF0,
0x60, 0x7F, 0xFF, 0x11, 0x60, 0x20, 0x08, 0x00, 0xD0, 0x11, 0x40, 0x00,
0x08, 0x00, 0x02, 0x11, 0x86, 0x1B, 0x07, 0x40, 0x74, 0xA0, 0x08, 0x6F,
0x84, 0x00, 0x00, 0x11, 0x04, 0xF1, 0x84, 0x00, 0x40, 0x21, 0x21, 0xF6,
0x00, 0x02, 0x00, 0x11, 0x60, 0x07, 0x07, 0x10, 0x20, 0x08, 0x40, 0xC3,
0x90, 0x20, 0x2F, 0x08, 0x80, 0x00, 0x11, 0x70, 0x02, 0x07, 0x7F, 0xFF,
0x11, 0x10, 0x00, 0x08, 0x40, 0x8D, 0x90, 0x40, 0x85, 0xA0, 0x08, 0x6E,
0x84, 0x00, 0x00, 0x11, 0x04, 0xF0, 0x84, 0x00, 0x40, 0x21, 0x22, 0x06,
0x00, 0x00, 0x02, 0x11, 0x60, 0x07, 0x07, 0x10, 0x20, 0x08, 0x40, 0x43,
0x90, 0x20, 0x2F, 0x08, 0x80, 0x00, 0x11, 0x70, 0x02, 0x07, 0x7F, 0xFF,
0x11, 0x10, 0x00, 0x08, 0x40, 0x0D, 0x90, 0x40, 0x05, 0xA0, 0x10, 0xEC,
0x84, 0x00, 0x10, 0x08, 0x10, 0xE7, 0x84, 0x40, 0xE7, 0xA0, 0x20, 0x0F,
0x08, 0x40, 0xEF, 0xA0, 0x10, 0x6D, 0x84, 0x00, 0x10, 0x08, 0x10, 0x6C,
0x84, 0x40, 0x6C, 0xA0, 0x20, 0x0F, 0x08, 0x40, 0x7D, 0xA0, 0x7F, 0xFF,
0x11, 0x00, 0x04, 0x00, 0x10, 0xEF, 0x84, 0x00, 0x10, 0x08, 0x10, 0xEE,
0x84, 0x40, 0xEE, 0xA0, 0x20, 0x0F, 0x08, 0x40, 0xBD, 0xA0, 0x10, 0x7D,
0x84, 0x00, 0x10, 0x08, 0x10, 0x7C, 0x84, 0x40, 0x7C, 0xA0, 0x20, 0x0F,
0x08, 0x40, 0x3D, 0xA0, 0x40, 0x00, 0x11, 0x3E, 0x86, 0x00, 0xFB, 0xFF,
0x21, 0x6F, 0x14, 0x43, 0x3E, 0x89, 0x00, 0xFF, 0xFB, 0x21, 0x6E, 0x14,
0x43, 0x3D, 0x42, 0x00, 0x40, 0xAF, 0xA0, 0xA0, 0x14, 0x43, 0x3D, 0x45,
0x00, 0x40, 0x2F, 0xA0, 0x20, 0x14, 0x43, 0x00, 0x04, 0x00, 0x3D, 0x49,
0x00, 0x40, 0xA5, 0xA0, 0xB0, 0x14, 0x43, 0x3D, 0x4C, 0x00, 0x40, 0x25,
0xA0, 0x30, 0x14, 0x43, 0x00, 0x00, 0x00, 0x22, 0x27, 0x00, 0x00, 0x02,
0x07, 0x22, 0x25, 0x00, 0x8A, 0x03, 0x07, 0x89, 0x04, 0x07, 0x40, 0x7E,
0xA0, 0x40, 0xBD, 0x90, 0x98, 0x14, 0x43, 0x10, 0x9C, 0x84, 0x20, 0x8F,
0x08, 0x40, 0x9A, 0x90, 0x40, 0x99, 0xA0, 0x20, 0x2E, 0x08, 0x40, 0xBD,
0x90, 0x00, 0x10, 0x08, 0x40, 0x9B, 0xA0, 0x20, 0x0E, 0x08, 0x7F, 0xFF,
0x21, 0x40, 0xF5, 0x90, 0x00, 0x00, 0x00, 0x22, 0x3B, 0x00, 0x00, 0x02,
0x07, 0x22, 0x39, 0x00, 0x82, 0x03, 0x07, 0x81, 0x04, 0x07, 0x40, 0x7E,
0xA0, 0x40, 0x3D, 0x90, 0x18, 0x14, 0x43, 0x10, 0x1C, 0x84, 0x20, 0x8F,
0x08, 0x40, 0x1A, 0x90, 0x40, 0x19, 0xA0, 0x20, 0x2E, 0x08, 0x40, 0x3D,
0x90, 0x00, 0x10, 0x08, 0x40, 0x1B, 0xA0, 0x20, 0x0E, 0x08, 0x7F, 0xFF,
0x21, 0x40, 0xF5, 0x90, 0x3D, 0x77, 0x00, 0xB8, 0x14, 0x43, 0x40, 0xC2,
0xA0, 0x3D, 0x7A, 0x00, 0x38, 0x14, 0x43, 0x40, 0x42, 0xA0, 0x00, 0x04,
0x00, 0x10, 0x51, 0x84, 0x20, 0x0F, 0x08, 0x7F, 0xC0, 0x11, 0x40, 0x51,
0xA0, 0x08, 0xBB, 0x84, 0x08, 0x3B, 0x84, 0xCB, 0x90, 0x11, 0x9E, 0x02,
0x07, 0xC7, 0x00, 0x11, 0x40, 0x7F, 0xA0, 0x08, 0xBA, 0x84, 0x08, 0x3A,
0x84, 0x74, 0x70, 0x11, 0x9E, 0x02, 0x07, 0x59, 0x00, 0x11, 0x40, 0x7F,
0xA0, 0x3E, 0xD8, 0x00, 0xFD, 0xFF, 0x21, 0xF1, 0x14, 0x43, 0x3E, 0xDB,
0x00, 0xFF, 0xFD, 0x21, 0xF0, 0x14, 0x43, 0x00, 0x04, 0x00, 0x04, 0xB9,
0x84, 0x40, 0xB6, 0xA0, 0x04, 0x39, 0x84, 0x40, 0x36, 0xA0, 0x00, 0x04,
0x00, 0x3E, 0xAE, 0x00, 0x40, 0x87, 0xA0, 0x80, 0x14, 0x43, 0x3E, 0xB1,
0x00, 0x40, 0x07, 0xA0, 0x00, 0x14, 0x43, 0x00, 0x04, 0x00, 0x00, 0x00,
0x00, 0x04, 0xF5, 0x84, 0x00, 0x00, 0x21, 0x70, 0x03, 0x07, 0x10, 0xF5,
0x84, 0x10, 0x00, 0x08, 0x40, 0xF3, 0x90, 0x40, 0xF5, 0xA0, 0x3E, 0xBD,
0x00, 0x40, 0x85, 0xA0, 0x88, 0x14, 0x43, 0x3E, 0xC0, 0x00, 0x40, 0x05,
0xA0, 0x08, 0x14, 0x43, 0x00, 0x04, 0x00, 0x00, 0x01, 0x07, 0x00, 0x02,
0x07, 0x00, 0x03, 0x07, 0x00, 0x04, 0x07, 0x00, 0x06, 0x07, 0x00, 0x16,
0x07, 0x00, 0x1E, 0x07, 0x00, 0x24, 0x07, 0x00, 0x3C, 0x07, 0x00, 0x72,
0x07, 0x00, 0x8D, 0x07, 0x00, 0xE0, 0x07, 0x00, 0xF6, 0x07, 0x01, 0x9F,
0x07, 0x01, 0xD1, 0x07, 0x00, 0x10, 0x07, 0x1F, 0xFF, 0x07, 0x20, 0x03,
0x60, 0x0F, 0x4A, 0x07, 0x08, 0xFA, 0x84, 0x04, 0x11, 0x44, 0xFF, 0x00,
0x11, 0x2F, 0x4E, 0x07, 0x70, 0x10, 0x08, 0x00, 0xF0, 0x21, 0x50, 0x00,
0x08, 0x00, 0xF0, 0x21, 0x40, 0xF9, 0x90, 0x00, 0x08, 0x07, 0x3E, 0x64,
0x00, 0x0F, 0x56, 0x07, 0x04, 0x8C, 0x84, 0x04, 0x84, 0x84, 0x04, 0x99,
0x84, 0x04, 0xBC, 0x84, 0x00, 0x00, 0x21, 0x10, 0x86, 0x84, 0x00, 0x00,
0x08, 0x40, 0x86, 0x90, 0x40, 0x85, 0xA0, 0x04, 0x0C, 0x84, 0x04, 0x04,
0x84, 0x04, 0x19, 0x84, 0x04, 0x3C, 0x84, 0x00, 0x00, 0x21, 0x10, 0x06,
0x84, 0x00, 0x00, 0x08, 0x40, 0x06, 0x90, 0x40, 0x05, 0xA0, 0x04, 0x51,
0x84, 0x02, 0x00, 0x21, 0x9C, 0x15, 0x07, 0x90, 0x16, 0x07, 0x40, 0xF9,
0xA0, 0x3F, 0x6E, 0x07, 0x70, 0x00, 0x08, 0x00, 0x7F, 0x11, 0x40, 0xF8,
0xA0, 0x9D, 0x1C, 0x07, 0x20, 0x12, 0x60, 0x08, 0xFA, 0x84, 0x04, 0x11,
0x44, 0x3E, 0x54, 0x00, 0x00, 0x2B, 0x07, 0x48, 0x80, 0x11, 0x08, 0x09,
0x44, 0x40, 0x75, 0x90, 0x7F, 0xEF, 0x07, 0x10, 0x00, 0x20, 0x00, 0x10,
0x08, 0xFF, 0xFF, 0x21, 0x06, 0x00, 0x84, 0x40, 0xFB, 0xA0, 0x60, 0x00,
0x08, 0x00, 0x00, 0x21, 0x40, 0xFF, 0x90, 0x10, 0xFB, 0x84, 0x60, 0x20,
0x08, 0x40, 0xFB, 0x90, 0x30, 0x00, 0x08, 0x00, 0x08, 0x11, 0x3D, 0xEA,
0x00, 0x04, 0xFB, 0x84, 0x3D, 0xEC, 0x00, 0x04, 0xFF, 0x84, 0x40, 0xF8,
0xA0, 0x04, 0x11, 0x44, 0x8F, 0xFF, 0x07, 0x20, 0x19, 0x60, 0x3E, 0xD2,
0x00, 0x00, 0x46, 0x07, 0x00, 0x01, 0x00, 0x00, 0x48, 0x07, 0x00, 0x02,
0x00, 0x27, 0x18, 0x43, 0x75, 0x00, 0x43, 0x8F, 0xFF, 0x07, 0x20, 0x19,
0x60, 0x04, 0xF5, 0x84, 0x40, 0xF2, 0xA0, 0x04, 0x51, 0x84, 0x7F, 0xFF,
0x21, 0x04, 0xF5, 0x84, 0x00, 0x00, 0x21, 0x04, 0xF3, 0x84, 0x00, 0x10,
0x21, 0x04, 0xF2, 0x84, 0x0C, 0x00, 0x21, 0x04, 0x72, 0x44, 0x07, 0x77,
0x21, 0x3F, 0xFA, 0x07, 0x70, 0x20, 0x08, 0x00, 0x00, 0x11, 0x10, 0x2D,
0x44, 0x10, 0x2C, 0x44, 0x00, 0x20, 0x08, 0x10, 0x00, 0x11, 0x00, 0x00,
0x08, 0x00, 0x00, 0x11, 0x80, 0x00, 0x21, 0x04, 0x73, 0x44, 0x07, 0x07,
0x21, 0x04, 0x72, 0x44, 0x00, 0x07, 0x21, 0x04, 0x73, 0x44, 0x07, 0x77,
0x21, 0x04, 0x73, 0x44, 0x00, 0x70, 0x21, 0x04, 0x2E, 0x44, 0x04, 0x2D,
0x44, 0x04, 0x2C, 0x44, 0x80, 0x00, 0x21, 0x04, 0x1C, 0x44, 0x04, 0x1B,
0x44, 0x0D, 0x00, 0x21, 0x04, 0x1C, 0x44, 0x04, 0x1B, 0x44, 0x0C, 0x80,
0x21, 0x04, 0x1C, 0x44, 0x04, 0x1B, 0x44, 0x1F, 0x08, 0x21, 0x0F, 0x18,
0x43, 0x08, 0x28, 0x44, 0x01, 0x11, 0x11, 0x08, 0x5D, 0x84, 0x10, 0x00,
0x10, 0x10, 0x00, 0x08, 0x40, 0x00, 0x21, 0x30, 0x04, 0x07, 0x40, 0xFF,
0x90, 0x50, 0x20, 0x08, 0xC0, 0x00, 0x11, 0x10, 0xFF, 0x84, 0x00, 0x20,
0x08, 0x00, 0x40, 0x11, 0x40, 0x00, 0x08, 0x00, 0x01, 0x11, 0x20, 0x51,
0x60, 0x10, 0x00, 0x44, 0x60, 0x00, 0x08, 0x40, 0x54, 0x90, 0x20, 0x00,
0x60, 0x00, 0x8E, 0x07, 0x81, 0x48, 0x07, 0x80, 0x03, 0x07, 0x40, 0xF8,
0xA0, 0x48, 0xC0, 0x11, 0x00, 0x8C, 0x07, 0x00, 0x8D, 0x07, 0x00, 0x8E,
0x07, 0x00, 0x04, 0x07, 0x00, 0x90, 0x07, 0x00, 0x91, 0x07, 0x00, 0x92,
0x07, 0x00, 0x55, 0x07, 0x00, 0x94, 0x07, 0x00, 0x95, 0x07, 0x00, 0x96,
0x07, 0x00, 0x74, 0x07, 0x00, 0x98, 0x07, 0x00, 0x97, 0x07, 0x00, 0x9A,
0x07, 0x00, 0x9B, 0x07, 0x0F, 0xEF, 0x07, 0x1F, 0xFF, 0x07, 0xFF, 0x00,
0x11, 0x10, 0x00, 0x20, 0x30, 0x10, 0x08, 0x00, 0x01, 0x21, 0x50, 0x00,
0x08, 0x00, 0x0F, 0x21, 0x40, 0xF9, 0x90, 0x30, 0xA5, 0x07, 0x70, 0x10,
0x08, 0x00, 0x80, 0x21, 0x50, 0x00, 0x08, 0x00, 0xF0, 0x21, 0x08, 0xF9,
0x84, 0x04, 0xF8, 0x84, 0x2F, 0xFF, 0x07, 0x3E, 0x59, 0x00, 0x04, 0xF1,
0x84, 0x04, 0xF0, 0x84, 0x04, 0x5A, 0x84, 0x00, 0x00, 0x21, 0x04, 0xF6,
0x84, 0x00, 0x02, 0x21, 0x04, 0xFA, 0x84, 0x40, 0x00, 0x21, 0x04, 0xF7,
0x84, 0x01, 0x04, 0x21, 0x04, 0x1C, 0x44, 0x04, 0x1B, 0x44, 0x0B, 0x23,
0x21, 0x0F, 0x18, 0x43, 0x04, 0x70, 0x44, 0x06, 0x66, 0x21, 0x04, 0x3B,
0x44, 0x04, 0x39, 0x44, 0x00, 0x80, 0x21, 0x04, 0x3C, 0x44, 0x2A, 0x0A,
0x21, 0x04, 0x2F, 0x44, 0x00, 0x44, 0x21, 0x04, 0x29, 0x44, 0x00, 0x00,
0x21, 0x03, 0x19, 0x42, 0x4E, 0x19, 0x43, 0x0C, 0x59, 0x43, 0x27, 0x18,
0x43, 0x15, 0x00, 0x43, 0x04, 0x22, 0x44, 0x03, 0x07, 0x21, 0x04, 0x21,
0x44, 0x11, 0x11, 0x21, 0x04, 0x20, 0x44, 0x33, 0x33, 0x21, 0x00, 0x00,
0x42, 0xC0, 0x3D, 0x42, 0x80, 0x3D, 0x43, 0x04, 0x35, 0x44, 0x00, 0x00,
0x21, 0x04, 0x05, 0x43, 0x42, 0xE2, 0x00,
};
const unsigned short int DOWNLOAD_BIN_LEN = sizeof(DOWNLOAD_BIN);
#endif
@@ -0,0 +1,524 @@
// SPDX-License-Identifier: GPL-2.0
/*
* Copyright (c) 2019 MediaTek Inc.
*/
/*
* BU63169AF voice coil motor driver
* BU63169 : OIS driver
* AK7372 : VCM driver be the same as AK7371AF
*/
#include <linux/delay.h>
#include <linux/fs.h>
#include <linux/i2c.h>
#include <linux/uaccess.h>
/* kernel standard for PMIC*/
#if !defined(CONFIG_MTK_LEGACY)
#include <linux/regulator/consumer.h>
#endif
#include "OIS_head.h"
#include "lens_info.h"
#define AF_DRVNAME "BU63169AF_DRV"
#define AF_I2C_SLAVE_ADDR 0x1c
#define EEPROM_I2C_SLAVE_ADDR 0xa0
#define AK7372AF_I2C_SLAVE_ADDR 0x18
#define AF_DEBUG
#ifdef AF_DEBUG
#define LOG_INF(format, args...) \
pr_info(AF_DRVNAME " [%s] " format, __func__, ##args)
#else
#define LOG_INF(format, args...)
#endif
static struct i2c_client *g_pstAF_I2Cclient;
static int *g_pAF_Opened;
static spinlock_t *g_pAF_SpinLock;
static unsigned long g_u4AF_INF;
static unsigned long g_u4AF_MACRO = 1023;
static unsigned long g_u4CurrPosition;
/* PMIC */
#if !defined(CONFIG_MTK_LEGACY)
static struct regulator *regVCAMAF;
static struct device *lens_device;
#endif
static void TimeoutHandle(void)
{
LOG_INF("BU63169 Timeout Handle Flow\n");
#if !defined(CONFIG_MTK_LEGACY)
lens_device = &g_pstAF_I2Cclient->dev;
if (regVCAMAF == NULL)
regVCAMAF = regulator_get(lens_device, "vcamaf");
if (regulator_is_enabled(regVCAMAF)) {
LOG_INF("Camera Power enable\n");
if (regulator_is_enabled(regVCAMAF)) {
if (regulator_disable(regVCAMAF) != 0)
LOG_INF("Fail to regulator_disable\n");
if (regulator_disable(regVCAMAF) != 0)
LOG_INF("Fail to regulator_disable\n");
}
msleep(20);
if (!regulator_is_enabled(regVCAMAF)) {
LOG_INF("AF Power off\n");
if (regulator_set_voltage(regVCAMAF, 2800000,
2800000) != 0)
LOG_INF("regulator_set_voltage fail\n");
if (regulator_set_voltage(regVCAMAF, 2800000,
2800000) != 0)
LOG_INF("regulator_set_voltage fail\n");
LOG_INF("AF Power On\n");
if (regulator_enable(regVCAMAF) != 0)
LOG_INF("regulator_enable fail\n");
if (regulator_enable(regVCAMAF) != 0)
LOG_INF("regulator_enable fail\n");
}
} else {
LOG_INF("Camera Power disable\n");
}
#endif
}
static int s4AK7372AF_WriteReg(unsigned short a_u2Addr, unsigned short a_u2Data)
{
int i4RetValue = 0;
char puSendCmd[2] = {(char)a_u2Addr, (char)a_u2Data};
g_pstAF_I2Cclient->addr = AK7372AF_I2C_SLAVE_ADDR;
g_pstAF_I2Cclient->addr = g_pstAF_I2Cclient->addr >> 1;
i4RetValue = i2c_master_send(g_pstAF_I2Cclient, puSendCmd, 2);
if (i4RetValue < 0) {
LOG_INF("I2C write failed!!\n");
return -1;
}
return 0;
}
static int s4AK7372AF_ReadReg(u8 a_uAddr, u16 *a_pu2Result)
{
int i4RetValue = 0;
char pBuff;
char puSendCmd[1];
puSendCmd[0] = a_uAddr;
g_pstAF_I2Cclient->addr = AK7372AF_I2C_SLAVE_ADDR;
g_pstAF_I2Cclient->addr = g_pstAF_I2Cclient->addr >> 1;
i4RetValue = i2c_master_send(g_pstAF_I2Cclient, puSendCmd, 1);
if (i4RetValue < 0) {
LOG_INF("I2C read - send failed!!\n");
return -1;
}
i4RetValue = i2c_master_recv(g_pstAF_I2Cclient, &pBuff, 1);
if (i4RetValue < 0) {
LOG_INF("I2C read - recv failed!!\n");
return -1;
}
*a_pu2Result = pBuff;
return 0;
}
static inline int setAK7372AFPos(unsigned long a_u4Position)
{
int i4RetValue = 0;
i4RetValue = s4AK7372AF_WriteReg(
0x0, (unsigned short)((a_u4Position >> 2) & 0xff));
if (i4RetValue < 0)
return -1;
i4RetValue = s4AK7372AF_WriteReg(
0x1, (unsigned short)((a_u4Position & 0x3) << 6));
return i4RetValue;
}
int s4EEPROM_ReadReg_BU63169AF(unsigned short addr, unsigned short *data)
{
int i4RetValue = 0;
unsigned char u8data[2];
unsigned char pu_send_cmd[2] = {(unsigned char)(addr >> 8),
(unsigned char)(addr & 0xFF)};
*data = 0;
g_pstAF_I2Cclient->addr = (EEPROM_I2C_SLAVE_ADDR) >> 1;
if (i2c_master_send(g_pstAF_I2Cclient, pu_send_cmd, 2) < 0) {
LOG_INF("read I2C send failed!!\n");
return -1;
}
if (i2c_master_recv(g_pstAF_I2Cclient, u8data, 2) < 0) {
LOG_INF("EEPROM_ReadReg failed!!\n");
return -1;
}
LOG_INF("u8data[0] = 0x%x\n", u8data[0]);
LOG_INF("u8data[1] = 0x%x\n", u8data[1]);
*data = u8data[1] << 8 | u8data[0];
LOG_INF("s4EEPROM_ReadReg2 0x%x, 0x%x\n", addr, *data);
return i4RetValue;
}
int s4AF_WriteReg_BU63169AF(unsigned short i2c_id, unsigned char *a_pSendData,
unsigned short a_sizeSendData)
{
int i4RetValue = 0;
spin_lock(g_pAF_SpinLock);
g_pstAF_I2Cclient->addr = i2c_id >> 1;
spin_unlock(g_pAF_SpinLock);
i4RetValue =
i2c_master_send(g_pstAF_I2Cclient, a_pSendData, a_sizeSendData);
if (i4RetValue == -EIO)
TimeoutHandle();
if (i4RetValue != a_sizeSendData) {
LOG_INF("I2C send failed!!, Addr = 0x%x, Data = 0x%x\n",
a_pSendData[0], a_pSendData[1]);
return -1;
}
return 0;
}
int s4AF_ReadReg_BU63169AF(unsigned short i2c_id, unsigned char *a_pSendData,
unsigned short a_sizeSendData,
unsigned char *a_pRecvData,
unsigned short a_sizeRecvData)
{
int i4RetValue;
struct i2c_msg msg[2];
spin_lock(g_pAF_SpinLock);
g_pstAF_I2Cclient->addr = i2c_id >> 1;
spin_unlock(g_pAF_SpinLock);
msg[0].addr = g_pstAF_I2Cclient->addr;
msg[0].flags = 0;
msg[0].len = a_sizeSendData;
msg[0].buf = a_pSendData;
msg[1].addr = g_pstAF_I2Cclient->addr;
msg[1].flags = I2C_M_RD;
msg[1].len = a_sizeRecvData;
msg[1].buf = a_pRecvData;
i4RetValue =
i2c_transfer(g_pstAF_I2Cclient->adapter, msg, ARRAY_SIZE(msg));
if (i4RetValue == -EIO)
TimeoutHandle();
if (i4RetValue != 2) {
LOG_INF("I2C Read failed!!\n");
return -1;
}
return 0;
}
static inline int getAFInfo(__user struct stAF_MotorInfo *pstMotorInfo)
{
struct stAF_MotorInfo stMotorInfo;
stMotorInfo.u4MacroPosition = g_u4AF_MACRO;
stMotorInfo.u4InfPosition = g_u4AF_INF;
stMotorInfo.u4CurrentPosition = g_u4CurrPosition;
stMotorInfo.bIsSupportSR = 1;
stMotorInfo.bIsMotorMoving = 1;
if (*g_pAF_Opened >= 1)
stMotorInfo.bIsMotorOpen = 1;
else
stMotorInfo.bIsMotorOpen = 0;
if (copy_to_user(pstMotorInfo, &stMotorInfo,
sizeof(struct stAF_MotorInfo)))
LOG_INF("copy to user failed when getting motor information\n");
return 0;
}
/* initAF include driver initialization and standby mode */
static int initAF(void)
{
LOG_INF("+\n");
if (*g_pAF_Opened == 1) {
s4AK7372AF_WriteReg(0x02, 0x00);
Main_OIS();
setOISMode(1);
spin_lock(g_pAF_SpinLock);
*g_pAF_Opened = 2;
spin_unlock(g_pAF_SpinLock);
}
LOG_INF("-\n");
return 0;
}
/* moveAF only use to control moving the motor */
static inline int moveAF(unsigned long a_u4Position)
{
int ret = 0;
if (setAK7372AFPos(a_u4Position) == 0) {
g_u4CurrPosition = a_u4Position;
ret = 0;
} else {
LOG_INF("set I2C failed when moving the motor\n");
ret = -1;
}
return ret;
}
static inline int setAFInf(unsigned long a_u4Position)
{
spin_lock(g_pAF_SpinLock);
g_u4AF_INF = a_u4Position;
spin_unlock(g_pAF_SpinLock);
return 0;
}
static inline int setAFMacro(unsigned long a_u4Position)
{
spin_lock(g_pAF_SpinLock);
g_u4AF_MACRO = a_u4Position;
spin_unlock(g_pAF_SpinLock);
return 0;
}
static inline int setAFPara(__user struct stAF_MotorCmd *pstMotorCmd)
{
struct stAF_MotorCmd stMotorCmd;
if (copy_from_user(&stMotorCmd, pstMotorCmd, sizeof(stMotorCmd)))
LOG_INF("copy to user failed when getting motor command\n");
LOG_INF("Motor CmdID : %x\n", stMotorCmd.u4CmdID);
LOG_INF("Motor Param : %x\n", stMotorCmd.u4Param);
switch (stMotorCmd.u4CmdID) {
case 1:
setOISMode(1); /* 1 : disable */
break;
case 2:
if (*g_pAF_Opened == 2 && stMotorCmd.u4Param > 0) {
unsigned short PosX, PosY;
PosX = stMotorCmd.u4Param / 10000;
PosY = stMotorCmd.u4Param - PosX * 10000;
LOG_INF("OIS %x\n", I2C_OIS_mem__read(0x7F));
I2C_OIS_mem_write(0x7F, 0x2C0C);
I2C_OIS_mem_write(0x17, PosX);
I2C_OIS_mem_write(0x97, PosY);
LOG_INF("Targe (%d , %d)\n", PosX, PosY);
}
break;
}
return 0;
}
static inline int getOISInfo(__user struct stAF_MotorOisInfo *pstMotorOisInfo)
{
struct stAF_MotorOisInfo stMotorOisInfo;
if (*g_pAF_Opened == 2) {
stMotorOisInfo.i4OISHallPosXum =
((short)I2C_OIS_mem__read(0x3F)) * 1000;
stMotorOisInfo.i4OISHallPosYum =
((short)I2C_OIS_mem__read(0xBF)) * 1000;
} else {
stMotorOisInfo.i4OISHallPosXum = 0;
stMotorOisInfo.i4OISHallPosYum = 0;
}
stMotorOisInfo.i4OISHallFactorX = 26487; /* 26.487 [LSB/um] */
stMotorOisInfo.i4OISHallFactorY = 26487;
/* Res(um) = HallPosX / 26.487 */
if (copy_to_user(pstMotorOisInfo, &stMotorOisInfo,
sizeof(struct stAF_MotorOisInfo)))
LOG_INF("copy to user failed when getting motor information\n");
return 0;
}
/* ////////////////////////////////////////////////////////////// */
long BU63169AF_Ioctl(struct file *a_pstFile, unsigned int a_u4Command,
unsigned long a_u4Param)
{
long i4RetValue = 0;
switch (a_u4Command) {
case AFIOC_G_MOTORINFO:
i4RetValue =
getAFInfo((__user struct stAF_MotorInfo *)(a_u4Param));
break;
case AFIOC_T_MOVETO:
i4RetValue = moveAF(a_u4Param);
break;
case AFIOC_T_SETINFPOS:
i4RetValue = setAFInf(a_u4Param);
break;
case AFIOC_T_SETMACROPOS:
i4RetValue = setAFMacro(a_u4Param);
break;
case AFIOC_S_SETPARA:
i4RetValue =
setAFPara((__user struct stAF_MotorCmd *)(a_u4Param));
break;
case AFIOC_G_MOTOROISINFO:
i4RetValue = getOISInfo(
(__user struct stAF_MotorOisInfo *)(a_u4Param));
break;
default:
LOG_INF("No CMD\n");
i4RetValue = -EPERM;
break;
}
return i4RetValue;
}
/* Main jobs: */
/* 1.Deallocate anything that "open" allocated in private_data. */
/* 2.Shut down the device on last close. */
/* 3.Only called once on last time. */
/* Q1 : Try release multiple times. */
int BU63169AF_Release(struct inode *a_pstInode, struct file *a_pstFile)
{
LOG_INF("Start\n");
if (*g_pAF_Opened == 2) {
LOG_INF("Wait\n");
OIS_Standby();
msleep(20);
}
if (*g_pAF_Opened) {
LOG_INF("Free\n");
spin_lock(g_pAF_SpinLock);
*g_pAF_Opened = 0;
spin_unlock(g_pAF_SpinLock);
}
LOG_INF("End\n");
return 0;
}
int BU63169AF_PowerDown(struct i2c_client *pstAF_I2Cclient,
int *pAF_Opened)
{
g_pstAF_I2Cclient = pstAF_I2Cclient;
g_pAF_Opened = pAF_Opened;
LOG_INF("+\n");
if (*g_pAF_Opened == 0) {
unsigned short data = 0;
int cnt = 0;
while (1) {
data = 0;
s4AK7372AF_WriteReg(0x02, 0x20);
s4AK7372AF_ReadReg(0x02, &data);
LOG_INF("Addr : 0x02 , Data : %x\n", data);
OIS_Standby();
if (data == 0x20 || cnt == 1)
break;
cnt++;
}
}
LOG_INF("-\n");
return 0;
}
int BU63169AF_SetI2Cclient(struct i2c_client *pstAF_I2Cclient,
spinlock_t *pAF_SpinLock, int *pAF_Opened)
{
g_pstAF_I2Cclient = pstAF_I2Cclient;
g_pAF_SpinLock = pAF_SpinLock;
g_pAF_Opened = pAF_Opened;
#if !defined(CONFIG_MTK_LEGACY)
regVCAMAF = NULL;
lens_device = NULL;
#endif
LOG_INF("SetI2Cclient\n");
initAF();
return 1;
}
int BU63169AF_GetFileName(unsigned char *pFileName)
{
#if SUPPORT_GETTING_LENS_FOLDER_NAME
char FilePath[256];
char *FileString;
sprintf(FilePath, "%s", __FILE__);
FileString = strrchr(FilePath, '/');
*FileString = '\0';
FileString = (strrchr(FilePath, '/') + 1);
strncpy(pFileName, FileString, AF_MOTOR_NAME);
LOG_INF("FileName : %s\n", pFileName);
#else
pFileName[0] = '\0';
#endif
return 1;
}
@@ -0,0 +1,7 @@
#
# Makefile for misc devices that really don't fit anywhere else.
#
obj-y += BU63169AF.o OIS_func.o OIS_main.o OIS_user.o
@@ -0,0 +1,675 @@
// SPDX-License-Identifier: GPL-2.0
/*
* Copyright (c) 2019 MediaTek Inc.
*/
#define _USE_MATH_DEFINES
#include "OIS_func.h"
#include "OIS_coef.h"
#include "OIS_defi.h"
#include "OIS_head.h"
#include "OIS_prog.h"
/* ***************************************************** */
/* **** Program Download Function */
/* ***************************************************** */
short int func_PROGRAM_DOWNLOAD(void)
{
unsigned short int sts; /* RHM_HT 2013/04/15 Change "typedef". */
download(0, 0); /* Program Download */
sts = I2C_OIS_mem__read(_M_OIS_STS); /* Check Status */
if ((sts & 0x0004) == 0x0004) {
/* ==> RHM_HT 2013/07/10 Added */
unsigned short int u16_dat;
u16_dat = I2C_OIS_mem__read(_M_FIRMVER);
DEBUG_printf(("Firm Ver : %4d\n\n", u16_dat));
/* <== RHM_HT 2013/07/10 Added */
return ADJ_OK;
} else {
return PROG_DL_ERR;
}
}
/* ==> RHM_HT 2013/11/26 Reverted */
/* ***************************************************** */
/* **** COEF Download function */
/* ***************************************************** */
unsigned short int INTG__INPUT; /* Integral Input value szx_2014/12/24_2 */
unsigned short int
KGNTG_VALUE; /* KgxTG / KgyTG szx_2014/12/24_2 */
unsigned short int GYRSNS; /* RHM_HT 2015/01/16 Added */
void func_COEF_DOWNLOAD(unsigned short int u16_coef_type)
{
download(1, u16_coef_type); /* COEF Download */
{
unsigned short int u16_dat;
/* Coef type */
u16_dat = I2C_OIS_mem__read(_M_CEFTYP);
DEBUG_printf(
("COEF M[0x%02x] 0x%04X\n", _M_CEFTYP, u16_dat));
}
/* Get default Integ_input and KgnTG value */
INTG__INPUT = I2C_OIS_mem__read(0x38);
KGNTG_VALUE = I2C_OIS_mem__read(_M_KgxTG);
GYRSNS = I2C_OIS_mem__read(_M_GYRSNS); /* RHM_HT 2015/01/16 Added */
}
/* <== RHM_HT 2013/11/26 Reverted */
/* ***************************************************** */
/* **** Download the data */
/* ***************************************************** */
void download(unsigned short int u16_type, unsigned short int u16_coef_type)
{
/* Data Transfer Size per one I2C access */
#define DWNLD_TRNS_SIZE (7)
unsigned char temp[DWNLD_TRNS_SIZE + 1];
unsigned short int block_cnt;
unsigned short int total_cnt;
unsigned short int lp;
unsigned short int n;
unsigned short int u16_i;
if (u16_type == 0)
n = DOWNLOAD_BIN_LEN;
else
n = DOWNLOAD_COEF_LEN; /* RHM_HT 2013/07/10 Modified */
block_cnt = n / DWNLD_TRNS_SIZE + 1;
total_cnt = block_cnt;
while (1) {
/* Residual Number Check */
if (block_cnt == 1)
lp = n % DWNLD_TRNS_SIZE;
else
lp = DWNLD_TRNS_SIZE;
/* Transfer Data set */
if (lp != 0) {
if (u16_type == 0) {
temp[0] = _OP_FIRM_DWNLD;
for (u16_i = 1; u16_i <= lp; u16_i += 1)
temp[u16_i] = DOWNLOAD_BIN
[(total_cnt - block_cnt) *
DWNLD_TRNS_SIZE +
u16_i - 1];
} else {
temp[0] = _OP_COEF_DWNLD;
for (u16_i = 1; u16_i <= lp; u16_i += 1)
temp[u16_i] = DOWNLOAD_COEF
[(total_cnt - block_cnt) *
DWNLD_TRNS_SIZE +
u16_i - 1];
}
/* Data Transfer */
WR_I2C(_SLV_OIS_, lp + 1, temp);
}
/* Block Counter Decrement */
block_cnt = block_cnt - 1;
if (block_cnt == 0)
break;
}
}
void SET_FADJ_PARAM(const struct _FACT_ADJ *param)
{
/* ********************* */
/* HALL ADJUST */
/* ********************* */
/* Set Hall Current DAC value that is FACTORY ADJUSTED */
I2C_OIS_per_write(_P_30_ADC_CH0, param->gl_CURDAT);
/* Set Hall PreAmp Offset that is FACTORY ADJUSTED */
I2C_OIS_per_write(_P_31_ADC_CH1, param->gl_HALOFS_X);
I2C_OIS_per_write(_P_32_ADC_CH2, param->gl_HALOFS_Y);
/* Set Hall-X/Y PostAmp Offset that is FACTORY ADJUSTED */
I2C_OIS_mem_write(_M_X_H_ofs, param->gl_HX_OFS);
I2C_OIS_mem_write(_M_Y_H_ofs, param->gl_HY_OFS);
/* Set Residual Offset that is FACTORY ADJUSTED */
I2C_OIS_per_write(_P_39_Ch3_VAL_1, param->gl_PSTXOF);
I2C_OIS_per_write(_P_3B_Ch3_VAL_3, param->gl_PSTYOF);
/* ********************* */
/* DIGITAL GYRO OFFSET */
/* ********************* */
I2C_OIS_mem_write(_M_Kgx00, param->gl_GX_OFS);
I2C_OIS_mem_write(_M_Kgy00, param->gl_GY_OFS);
I2C_OIS_mem_write(_M_TMP_X_, param->gl_TMP_X_);
I2C_OIS_mem_write(_M_TMP_Y_, param->gl_TMP_Y_);
/* ********************* */
/* HALL SENSE */
/* ********************* */
/* Set Hall Gain value that is FACTORY ADJUSTED */
I2C_OIS_mem_write(_M_KgxHG, param->gl_KgxHG);
I2C_OIS_mem_write(_M_KgyHG, param->gl_KgyHG);
/* Set Cross Talk Canceller */
I2C_OIS_mem_write(_M_KgxH0, param->gl_KgxH0);
I2C_OIS_mem_write(_M_KgyH0, param->gl_KgyH0);
/* ********************* */
/* LOOPGAIN */
/* ********************* */
I2C_OIS_mem_write(_M_KgxG, param->gl_KGXG);
I2C_OIS_mem_write(_M_KgyG, param->gl_KGYG);
/* Position Servo ON ( OIS OFF ) */
I2C_OIS_mem_write(_M_EQCTL, 0x0C0C);
}
/* ***************************************************** */
/* **** Scence parameter */
/* ***************************************************** */
#define ANGLE_LIMIT \
(unsigned short int)(GYRSNS * 11 / 10) /* GYRSNS * limit[deg] */
#define G_SENSE 131 /* [LSB/dps] */
short int func_SET_SCENE_PARAM(unsigned char u16_scene, unsigned char u16_mode,
unsigned char filter, unsigned char range,
const struct _FACT_ADJ *param)
{
unsigned short int u16_i;
unsigned short int u16_dat;
unsigned short int *u16_dat_SCENE_;
unsigned char size_SCENE_tbl;
/* ==> RHM_HT 2013/11/25 Modified */
unsigned char u16_adr_target[3] = {
_M_Kgxdr, _M_X_LMT, _M_X_TGT,
};
unsigned short int u16_dat_SCENE_NIGHT_1[3] = {
0x7FFE, 0, G_SENSE * 16,
};
unsigned short int u16_dat_SCENE_NIGHT_2[3] = {
0x7FFC, 0, G_SENSE * 16,
};
unsigned short int u16_dat_SCENE_NIGHT_3[3] = {
0x7FFA, 0, G_SENSE * 16,
};
unsigned short int u16_dat_SCENE_D_A_Y_1[3] = {
0x7FFE, 0, G_SENSE * 40,
};
unsigned short int u16_dat_SCENE_D_A_Y_2[3] = {
0x7FFA, 0, G_SENSE * 40,
};
unsigned short int u16_dat_SCENE_D_A_Y_3[3] = {
0x7FF0, 0, G_SENSE * 40,
};
unsigned short int u16_dat_SCENE_SPORT_1[3] = {
0x7FFE, 0, G_SENSE * 60,
};
unsigned short int u16_dat_SCENE_SPORT_2[3] = {
0x7FF0, 0, G_SENSE * 60,
};
unsigned short int u16_dat_SCENE_SPORT_3[3] = {
0x7FE0, 0, G_SENSE * 60,
};
unsigned short int u16_dat_SCENE_TEST___[3] = {
0x7FF0, 0x7FFF, 0x7FFF,
}; /* Limmiter OFF */
/* <== RHM_HT 2013/11/25 Modified */
u16_dat_SCENE_NIGHT_1[1] = ANGLE_LIMIT;
u16_dat_SCENE_NIGHT_2[1] = ANGLE_LIMIT;
u16_dat_SCENE_NIGHT_3[1] = ANGLE_LIMIT;
u16_dat_SCENE_D_A_Y_1[1] = ANGLE_LIMIT;
u16_dat_SCENE_D_A_Y_2[1] = ANGLE_LIMIT;
u16_dat_SCENE_D_A_Y_3[1] = ANGLE_LIMIT;
u16_dat_SCENE_SPORT_1[1] = ANGLE_LIMIT;
u16_dat_SCENE_SPORT_2[1] = ANGLE_LIMIT;
u16_dat_SCENE_SPORT_3[1] = ANGLE_LIMIT;
size_SCENE_tbl =
sizeof(u16_dat_SCENE_NIGHT_1) / sizeof(unsigned short int);
/* Disable OIS ( position Servo is not disable ) */
u16_dat = I2C_OIS_mem__read(_M_EQCTL);
u16_dat = (u16_dat & 0xFEFE);
I2C_OIS_mem_write(_M_EQCTL, u16_dat);
/* Scene parameter select */
switch (u16_scene) {
case _SCENE_NIGHT_1:
u16_dat_SCENE_ = u16_dat_SCENE_NIGHT_1;
break;
case _SCENE_NIGHT_2:
u16_dat_SCENE_ = u16_dat_SCENE_NIGHT_2;
break;
case _SCENE_NIGHT_3:
u16_dat_SCENE_ = u16_dat_SCENE_NIGHT_3;
break;
case _SCENE_D_A_Y_1:
u16_dat_SCENE_ = u16_dat_SCENE_D_A_Y_1;
break;
case _SCENE_D_A_Y_2:
u16_dat_SCENE_ = u16_dat_SCENE_D_A_Y_2;
break;
case _SCENE_D_A_Y_3:
u16_dat_SCENE_ = u16_dat_SCENE_D_A_Y_3;
break;
case _SCENE_SPORT_1:
u16_dat_SCENE_ = u16_dat_SCENE_SPORT_1;
break;
case _SCENE_SPORT_2:
u16_dat_SCENE_ = u16_dat_SCENE_SPORT_2;
break;
case _SCENE_SPORT_3:
u16_dat_SCENE_ = u16_dat_SCENE_SPORT_3;
break;
case _SCENE_TEST___:
u16_dat_SCENE_ = u16_dat_SCENE_TEST___;
break;
default:
u16_dat_SCENE_ = u16_dat_SCENE_TEST___;
break;
}
/* Set parameter to the OIS controller */
for (u16_i = 0; u16_i < size_SCENE_tbl; u16_i += 1)
I2C_OIS_mem_write(u16_adr_target[u16_i], u16_dat_SCENE_[u16_i]);
for (u16_i = 0; u16_i < size_SCENE_tbl; u16_i += 1)
I2C_OIS_mem_write(u16_adr_target[u16_i] + 0x80,
u16_dat_SCENE_[u16_i]);
{
u16_dat = (INTG__INPUT * 16384L) /
ANGLE_LIMIT; /* X2 * 4000h / X1 */
I2C_OIS_mem_write(0x38, u16_dat);
I2C_OIS_mem_write(0xB8, u16_dat);
/* ---------------------------------------------- */
u16_dat = (KGNTG_VALUE * ANGLE_LIMIT) /
16384L; /* X3 * X1 / 4000h */
I2C_OIS_mem_write(0x47, u16_dat);
I2C_OIS_mem_write(0xC7, u16_dat);
}
/* szx_2014/12/24 <=== */
/* Set/Reset Notch filter */
if (filter == 1) { /* Disable Filter */
u16_dat = I2C_OIS_mem__read(_M_EQCTL);
u16_dat |= 0x4000;
I2C_OIS_mem_write(_M_EQCTL, u16_dat);
} else { /* Enable Filter */
u16_dat = I2C_OIS_mem__read(_M_EQCTL);
u16_dat &= 0xBFFF;
I2C_OIS_mem_write(_M_EQCTL, u16_dat);
}
/* Clear the register of the OIS controller */
I2C_OIS_mem_write(_M_wDgx02, 0x0000);
I2C_OIS_mem_write(_M_wDgx03, 0x0000);
I2C_OIS_mem_write(_M_wDgx06, 0x7FFF);
I2C_OIS_mem_write(_M_Kgx15, 0x0000);
I2C_OIS_mem_write(_M_wDgy02, 0x0000);
I2C_OIS_mem_write(_M_wDgy03, 0x0000);
I2C_OIS_mem_write(_M_wDgy06, 0x7FFF);
I2C_OIS_mem_write(_M_Kgy15, 0x0000);
/* Set the pre-Amp offset value (X and Y) */
/* ==> RHM_HT 2013/11/25 Modified */
if (range == 1) {
I2C_OIS_per_write(_P_31_ADC_CH1, param->gl_SFTHAL_X);
I2C_OIS_per_write(_P_32_ADC_CH2, param->gl_SFTHAL_Y);
} else {
I2C_OIS_per_write(_P_31_ADC_CH1, param->gl_HALOFS_X);
I2C_OIS_per_write(_P_32_ADC_CH2, param->gl_HALOFS_Y);
}
/* <== RHM_HT 2013/11/25 Modified */
/* Enable OIS (if u16_mode = 1) */
if (u16_mode == 1) {
u16_dat = I2C_OIS_mem__read(_M_EQCTL);
u16_dat = (u16_dat | 0x0101);
I2C_OIS_mem_write(_M_EQCTL, u16_dat);
DEBUG_printf(("SET : EQCTL:%.4x\n", u16_dat));
} else { /* ==> RHM_HT 2013.03.23 Add for OIS control */
u16_dat = I2C_OIS_mem__read(_M_EQCTL);
u16_dat = (u16_dat & 0xFEFE);
I2C_OIS_mem_write(_M_EQCTL, u16_dat);
DEBUG_printf(("SET : EQCTL:%.4x\n", u16_dat));
} /* <== RHM_HT 2013.03.23 Add for OIS control */
return ADJ_OK; /* RHM_HT 2013/04/15 Change return value */
}
short int func_SET_SCENE_PARAM_for_NewGYRO_Fil(unsigned char u16_scene,
unsigned char u16_mode,
unsigned char filter,
unsigned char range,
const struct _FACT_ADJ *param)
{
unsigned short int u16_i;
unsigned short int u16_dat;
unsigned short int *u16_dat_SCENE_;
unsigned char size_SCENE_tbl;
/* szx_2014/09/19 ---> Modified */
/* ==> RHM_HT 2013/11/25 Modified */
unsigned char u16_adr_target[4] = {
_M_Kgxdr, _M_X_LMT, _M_X_TGT, 0x1B,
};
unsigned short int u16_dat_SCENE_NIGHT_1[4] = {
0x7FE0, 0, G_SENSE * 16, 0x0300,
};
unsigned short int u16_dat_SCENE_NIGHT_2[4] = {
0x7FFF, 0, G_SENSE * 16, 0x0080,
};
unsigned short int u16_dat_SCENE_NIGHT_3[4] = {
0x7FF0, 0, G_SENSE * 16, 0x0300,
};
unsigned short int u16_dat_SCENE_D_A_Y_1[4] = {
0x7FE0, 0, G_SENSE * 40, 0x0300,
};
unsigned short int u16_dat_SCENE_D_A_Y_2[4] = {
0x7F80, 0, G_SENSE * 40, 0x0140,
};
unsigned short int u16_dat_SCENE_D_A_Y_3[4] = {
0x7F00, 0, G_SENSE * 40, 0x0300,
};
unsigned short int u16_dat_SCENE_SPORT_1[4] = {
0x7FE0, 0, G_SENSE * 60, 0x0300,
};
/* szx_2014/12/24 ===> */
unsigned short int u16_dat_SCENE_SPORT_2[4] = {
0x7F80, 0, G_SENSE * 60, 0x0000,
};
unsigned short int u16_dat_SCENE_SPORT_3[4] = {
0x7FF0, 0, G_SENSE * 60, 0x0300,
};
/* szx_2014/12/24 <=== */
unsigned short int u16_dat_SCENE_TEST___[4] = {
0x7FFF, 0x7FFF, 0x7FFF, 0x0080,
}; /* Limmiter OFF */
/* <== RHM_HT 2013/11/25 Modified */
/* szx_2014/09/19 <--- */
u16_dat_SCENE_NIGHT_1[1] = ANGLE_LIMIT;
u16_dat_SCENE_NIGHT_2[1] = ANGLE_LIMIT;
u16_dat_SCENE_NIGHT_3[1] = ANGLE_LIMIT;
u16_dat_SCENE_D_A_Y_1[1] = ANGLE_LIMIT;
u16_dat_SCENE_D_A_Y_2[1] = ANGLE_LIMIT;
u16_dat_SCENE_D_A_Y_3[1] = ANGLE_LIMIT;
u16_dat_SCENE_SPORT_1[1] = ANGLE_LIMIT;
u16_dat_SCENE_SPORT_2[1] = ANGLE_LIMIT;
u16_dat_SCENE_SPORT_3[1] = ANGLE_LIMIT;
size_SCENE_tbl =
sizeof(u16_dat_SCENE_NIGHT_1) / sizeof(unsigned short int);
/* Disable OIS ( position Servo is not disable ) */
u16_dat = I2C_OIS_mem__read(_M_EQCTL);
u16_dat = (u16_dat & 0xFEFE);
I2C_OIS_mem_write(_M_EQCTL, u16_dat);
/* Scene parameter select */
switch (u16_scene) {
case _SCENE_NIGHT_1:
u16_dat_SCENE_ = u16_dat_SCENE_NIGHT_1;
break;
case _SCENE_NIGHT_2:
u16_dat_SCENE_ = u16_dat_SCENE_NIGHT_2;
break;
case _SCENE_NIGHT_3:
u16_dat_SCENE_ = u16_dat_SCENE_NIGHT_3;
break;
case _SCENE_D_A_Y_1:
u16_dat_SCENE_ = u16_dat_SCENE_D_A_Y_1;
break;
case _SCENE_D_A_Y_2:
u16_dat_SCENE_ = u16_dat_SCENE_D_A_Y_2;
break;
case _SCENE_D_A_Y_3:
u16_dat_SCENE_ = u16_dat_SCENE_D_A_Y_3;
break;
case _SCENE_SPORT_1:
u16_dat_SCENE_ = u16_dat_SCENE_SPORT_1;
break;
case _SCENE_SPORT_2:
u16_dat_SCENE_ = u16_dat_SCENE_SPORT_2;
break;
case _SCENE_SPORT_3:
u16_dat_SCENE_ = u16_dat_SCENE_SPORT_3;
break;
case _SCENE_TEST___:
u16_dat_SCENE_ = u16_dat_SCENE_TEST___;
break;
default:
u16_dat_SCENE_ = u16_dat_SCENE_TEST___;
break;
}
/* Set parameter to the OIS controller */
for (u16_i = 0; u16_i < size_SCENE_tbl; u16_i += 1)
I2C_OIS_mem_write(u16_adr_target[u16_i], u16_dat_SCENE_[u16_i]);
for (u16_i = 0; u16_i < size_SCENE_tbl; u16_i += 1)
I2C_OIS_mem_write(u16_adr_target[u16_i] + 0x80,
u16_dat_SCENE_[u16_i]);
{
u16_dat = (INTG__INPUT * 16384L) /
ANGLE_LIMIT; /* X2 * 4000h / X1 */
I2C_OIS_mem_write(0x38, u16_dat);
I2C_OIS_mem_write(0xB8, u16_dat);
/* ---------------------------------------------- */
u16_dat = (KGNTG_VALUE * ANGLE_LIMIT) /
16384L; /* X3 * X1 / 4000h */
I2C_OIS_mem_write(0x47, u16_dat);
I2C_OIS_mem_write(0xC7, u16_dat);
}
/* szx_2014/12/24 <=== */
/* Set/Reset Notch filter */
if (filter == 1) { /* Disable Filter */
u16_dat = I2C_OIS_mem__read(_M_EQCTL);
u16_dat |= 0x4000;
I2C_OIS_mem_write(_M_EQCTL, u16_dat);
} else { /* Enable Filter */
u16_dat = I2C_OIS_mem__read(_M_EQCTL);
u16_dat &= 0xBFFF;
I2C_OIS_mem_write(_M_EQCTL, u16_dat);
}
/* Set the pre-Amp offset value (X and Y) */
/* ==> RHM_HT 2013/11/25 Modified */
if (range == 1) {
I2C_OIS_per_write(_P_31_ADC_CH1, param->gl_SFTHAL_X);
I2C_OIS_per_write(_P_32_ADC_CH2, param->gl_SFTHAL_Y);
} else {
I2C_OIS_per_write(_P_31_ADC_CH1, param->gl_HALOFS_X);
I2C_OIS_per_write(_P_32_ADC_CH2, param->gl_HALOFS_Y);
}
/* <== RHM_HT 2013/11/25 Modified */
/* Enable OIS (if u16_mode = 1) */
if (u16_mode == 1) { /* OIS ON */
u16_dat = I2C_OIS_mem__read(_M_EQCTL);
u16_dat = (u16_dat & 0xEFFF); /* Clear Halfshutter mode */
u16_dat = (u16_dat | 0x0101);
I2C_OIS_mem_write(_M_EQCTL, u16_dat);
DEBUG_printf(("SET : EQCTL:%.4x\n", u16_dat));
} else if (u16_mode ==
2) { /* Half Shutter // szx_2014/09/19 ---> */
u16_dat = I2C_OIS_mem__read(_M_EQCTL);
u16_dat = (u16_dat | 0x1101);
I2C_OIS_mem_write(_M_EQCTL, u16_dat);
DEBUG_printf(("SET : EQCTL:%.4x\n", u16_dat));
} else { /* ==> RHM_HT 2013.03.23 Add for OIS control */
u16_dat = I2C_OIS_mem__read(_M_EQCTL);
u16_dat = (u16_dat & 0xFEFE);
I2C_OIS_mem_write(_M_EQCTL, u16_dat);
DEBUG_printf(("SET : EQCTL:%.4x\n", u16_dat));
} /* <== RHM_HT 2013.03.23 Add for OIS control */
return ADJ_OK; /* RHM_HT 2013/04/15 Change return value */
}
/* ==> RHM_HT 2014/11/27 Added */
/* ***************************************************** */
/* **** Enable HalfShutter */
/* ***************************************************** */
void HalfShutterOn(void)
{
unsigned short int u16_dat = 0;
u16_dat = I2C_OIS_mem__read(_M_EQCTL);
u16_dat = (u16_dat | 0x1101);
I2C_OIS_mem_write(_M_EQCTL, u16_dat);
DEBUG_printf(("SET : EQCTL:%.4x\n", u16_dat));
}
/* <== RHM_HT 2014/11/27 Added */
/* ***************************************************** */
/* **** Write to the Peripheral register < 82h > */
/* **** ------------------------------------------------ */
/* **** unsigned char adr Peripheral Address */
/* **** unsigned short int dat Write data */
/* ***************************************************** */
void I2C_OIS_per_write(unsigned char u08_adr, unsigned short int u16_dat)
{
unsigned char out[4];
out[0] = _OP_Periphe_RW;
out[1] = u08_adr;
out[2] = (u16_dat)&0xFF;
out[3] = (u16_dat >> 8) & 0xFF;
WR_I2C(_SLV_OIS_, 4, out);
}
/* ***************************************************** */
/* **** Write to the Memory register < 84h > */
/* **** ------------------------------------------------ */
/* **** unsigned char adr Memory Address */
/* **** unsigned short int dat Write data */
/* ***************************************************** */
void I2C_OIS_mem_write(unsigned char u08_adr, unsigned short int u16_dat)
{
unsigned char out[4];
out[0] = _OP_Memory__RW;
out[1] = u08_adr;
out[2] = (u16_dat)&0xFF;
out[3] = (u16_dat >> 8) & 0xFF;
WR_I2C(_SLV_OIS_, 4, out);
}
/* ***************************************************** */
/* **** Read from the Peripheral register < 82h > */
/* **** ------------------------------------------------ */
/* **** unsigned char adr Peripheral Address */
/* **** unsigned short int dat Read data */
/* ***************************************************** */
unsigned short int I2C_OIS_per__read(unsigned char u08_adr)
{
unsigned char u08_dat[2];
u08_dat[0] = _OP_Periphe_RW; /* Op-code */
u08_dat[1] = u08_adr; /* target address */
return RD_I2C(_SLV_OIS_, 2, u08_dat);
}
/* ***************************************************** */
/* **** Read from the Memory register < 84h > */
/* **** ------------------------------------------------ */
/* **** unsigned char adr Memory Address */
/* **** unsigned short int dat Read data */
/* ***************************************************** */
unsigned short int I2C_OIS_mem__read(unsigned char u08_adr)
{
unsigned char u08_dat[2];
u08_dat[0] = _OP_Memory__RW; /* Op-code */
u08_dat[1] = u08_adr; /* target address */
return RD_I2C(_SLV_OIS_, 2, u08_dat);
}
/* ***************************************************** */
/* **** Special Command 8Ah */
/* _cmd_8C_EI 0 // 0x0001 */
/* _cmd_8C_DI 1 // 0x0002 */
/* ***************************************************** */
void I2C_OIS_spcl_cmnd(unsigned char u08_on, unsigned char u08_dat)
{
if ((u08_dat == _cmd_8C_EI) || (u08_dat == _cmd_8C_DI)) {
unsigned char out[2];
out[0] = _OP_SpecialCMD;
out[1] = u08_dat;
WR_I2C(_SLV_OIS_, 2, out);
}
}
/* ***************************************************** */
/* **** F0-F3h Command NonAssertClockStretch Function */
/* ***************************************************** */
void I2C_OIS_F0123_wr_(unsigned char u08_dat0, unsigned char u08_dat1,
unsigned short int u16_dat2)
{
unsigned char out[5];
out[0] = 0xF0;
out[1] = u08_dat0;
out[2] = u08_dat1;
out[3] = u16_dat2 / 256;
out[4] = u16_dat2 % 256;
WR_I2C(_SLV_OIS_, 5, out);
}
unsigned short int I2C_OIS_F0123__rd(void)
{
unsigned char u08_dat[2];
u08_dat[0] = 0xF0; /* Op-code */
u08_dat[1] = 0;
return RD_I2C(_SLV_OIS_, 2, u08_dat);
}
/* ----------------------------------------------------------- */
/* ----------------------------------------------------------- */
/* ----------------------------------------------------------- */
@@ -0,0 +1,212 @@
// SPDX-License-Identifier: GPL-2.0
/*
* Copyright (c) 2019 MediaTek Inc.
*/
/* #define OIS_DEBUG */
#ifdef OIS_DEBUG
#include <linux/delay.h>
#include <linux/fs.h>
#include <linux/uaccess.h>
#endif
/* #include <stdio.h> */
#include "OIS_head.h"
const struct _FACT_ADJ
FADJ_DEF = {
0x0200, /* gl_CURDAT; */
0x0200, /* gl_HALOFS_X; */
0x0200, /* gl_HALOFS_Y; */
0x0000, /* gl_HX_OFS; */
0x0000, /* gl_HY_OFS; */
0x0080,
0x0080,
0x0000, /* gl_GX_OFS; */
0x0000, /* gl_GY_OFS; */
0x2000,
0x2000,
0x2000,
0x2000,
0x0200,
0x0200,
0x0000,
0x0000,
0x0000,
0x0000,
};
/* FACTORY Adjusted data */
/* These data are stored at the non-vollatile */
/* memory inside of the CMOS sensor. */
/* The Host ( ISP or I2C master ) read these */
/* data from above memory and write to the OIS */
/* controller. */
/* --------------------------------------------- */
struct _FACT_ADJ
FADJ_MEM = {
0x0201, /* gl_CURDAT; */
0x0200, /* gl_HALOFS_X; */
0x0200, /* gl_HALOFS_Y; */
0x0000, /* gl_HX_OFS; */
0x0000, /* gl_HY_OFS; */
0x0080,
0x0080,
0x0000, /* gl_GX_OFS; */
0x0000, /* gl_GY_OFS; */
0x2000,
0x2000,
0x2000,
0x2000,
0x0200,
0x0200,
0x0000,
0x0000,
0x0000,
0x0000,
};
/* Parameters for expanding OIS range */
/* --------------------------------------------- */
double p_x, q_x;
double p_y, q_y;
short int zero_X;
short int zero_Y;
short int PREOUT_X_P, PREOUT_X_N;
short int PREOUT_Y_P, PREOUT_Y_N;
double alfa_X, beta_X;
double alfa_Y, beta_Y;
#ifdef OIS_DEBUG
#define OIS_DRVNAME "BU63165AF_OIS"
#define LOG_INF(format, args...) \
pr_info(OIS_DRVNAME " [%s] " format, __func__, ##args)
#endif
/* GLOBAL variable ( Upper Level Host Set this Global variables ) */
unsigned short int BOOT_MODE = _FACTORY_;
#define AF_REQ 0x8000
#define SCENE_REQ_ON 0x4000
#define SCENE_REQ_OFF 0x2000
#define POWERDOWN 0x1000
#define INITIAL_VAL 0x0000
unsigned short int OIS_SCENE = _SCENE_D_A_Y_1;
unsigned short int OIS_REQUEST = INITIAL_VAL; /* OIS control register. */
/* ==> RHM_HT 2013.03.04 Change type (unsigned short int -> double) */
double OIS_PIXEL[2]; /* Just Only use for factory adjustment. */
/* <== RHM_HT 2013.03.04 */
short int OIS_MAIN_STS = ADJ_ERR;
static struct _FACT_ADJ fadj;
void setOISMode(int Disable)
{
if (Disable == 1)
func_SET_SCENE_PARAM_for_NewGYRO_Fil(_SCENE_SPORT_3, 0, 0, 0,
&fadj);
else
func_SET_SCENE_PARAM_for_NewGYRO_Fil(_SCENE_SPORT_3, 1, 0, 0,
&fadj);
}
int setVCMPos(unsigned short DAC_Val)
{
I2C_OIS_F0123_wr_(0x90, 0x00, DAC_Val); /* AF Control */
return 0;
}
void OIS_Standby(void)
{
I2C_OIS_F0123_wr_(0x90, 0x00, 0x0200);
I2C_OIS_mem_write(0x7F, 0x0080);
I2C_OIS_per_write(0x72, 0x0000);
I2C_OIS_per_write(0x73, 0x0000);
I2C_OIS_per_write(0x18, 0x000F);
I2C_OIS_per_write(0x1B, 0x0B02);
I2C_OIS_per_write(0x1C, 0x0B02);
I2C_OIS_per_write(0x3D, 0x0000);
I2C_OIS_per_write(0x22, 0x0300);
I2C_OIS_per_write(0x59, 0x0000);
}
/* MAIN OIS */
void Main_OIS(void)
{
/* ------------------------------------------------------ */
/* Get Factory adjusted data */
/* ------------------------------------------------------ */
fadj = get_FADJ_MEM_from_non_volatile_memory();
#ifdef OIS_DEBUG
LOG_INF("gl_CURDAT = 0x%04X\n", fadj.gl_CURDAT);
LOG_INF("gl_HALOFS_X = 0x%04X\n", fadj.gl_HALOFS_X);
LOG_INF("gl_HALOFS_Y = 0x%04X\n", fadj.gl_HALOFS_Y);
LOG_INF("gl_PSTXOF = 0x%04X\n", fadj.gl_PSTXOF);
LOG_INF("gl_PSTYOF = 0x%04X\n", fadj.gl_PSTYOF);
LOG_INF("gl_HX_OFS = 0x%04X\n", fadj.gl_HX_OFS);
LOG_INF("gl_HY_OFS = 0x%04X\n", fadj.gl_HY_OFS);
LOG_INF("gl_GX_OFS = 0x%04X\n", fadj.gl_GX_OFS);
LOG_INF("gl_GY_OFS = 0x%04X\n", fadj.gl_GY_OFS);
LOG_INF("gl_KgxHG = 0x%04X\n", fadj.gl_KgxHG);
LOG_INF("gl_KgyHG = 0x%04X\n", fadj.gl_KgyHG);
LOG_INF("gl_KGXG = 0x%04X\n", fadj.gl_KGXG);
LOG_INF("gl_KGYG = 0x%04X\n", fadj.gl_KGYG);
LOG_INF("gl_SFTHAL_X = 0x%04X\n", fadj.gl_SFTHAL_X);
LOG_INF("gl_SFTHAL_Y = 0x%04X\n", fadj.gl_SFTHAL_Y);
LOG_INF("gl_TMP_X_ = 0x%04X\n", fadj.gl_TMP_X_);
LOG_INF("gl_TMP_Y_ = 0x%04X\n", fadj.gl_TMP_Y_);
LOG_INF("gl_KgxH0 = 0x%04X\n", fadj.gl_KgxH0);
LOG_INF("gl_KgyH0 = 0x%04X\n", fadj.gl_KgyH0);
#endif
/* ------------------------------------------------------ */
/* Enable Source Power and Input external clock to CLK/PS pin. */
/* ------------------------------------------------------ */
/* Please write your source code here. */
/* ------------------------------------------------------ */
/* PLL setting to use external CLK */
/* ------------------------------------------------------ */
VCOSET0();
/* ------------------------------------------------------ */
/* Download Program and Coefficient */
/* ------------------------------------------------------ */
OIS_MAIN_STS = func_PROGRAM_DOWNLOAD(); /* Program Download */
if (OIS_MAIN_STS <= ADJ_ERR)
return;
func_COEF_DOWNLOAD(0); /* Download Coefficient */
/* ------------------------------------------------------ */
/* Change Clock to external pin CLK_PS */
/* ------------------------------------------------------ */
VCOSET1();
/* ------------------------------------------------------ */
/* Issue DSP start command. */
/* ------------------------------------------------------ */
I2C_OIS_spcl_cmnd(1, _cmd_8C_EI); /* DSP calculation START */
/* ------------------------------------------------------ */
/* Set calibration data */
/* ------------------------------------------------------ */
SET_FADJ_PARAM(&fadj);
/* ------------------------------------------------------ */
/* Set scene parameter for OIS */
/* ------------------------------------------------------ */
func_SET_SCENE_PARAM_for_NewGYRO_Fil(_SCENE_SPORT_3, 1, 0, 0, &fadj);
}
@@ -0,0 +1,261 @@
// SPDX-License-Identifier: GPL-2.0
/*
* Copyright (c) 2019 MediaTek Inc.
*/
#ifndef OIS_USER_C
#define OIS_USER_C
#endif
#include "OIS_head.h"
unsigned short int FOCUS_VAL = 0x0122;
/* ============================================ */
void VCOSET0(void)
{
unsigned short int CLK_PS = 23880;
unsigned short int FVCO_1 = 36000; /* Target Frequency [kHz] */
/* 27000 for 63163 */
/* 36000 for 63165 */
unsigned short int FREF = 25; /* Reference Clock Frequency [kHz] */
unsigned short int DIV_N = CLK_PS / FREF - 1; /* calc DIV_N */
unsigned short int DIV_M = FVCO_1 / FREF - 1; /* calc DIV_M */
I2C_OIS_per_write(0x62,
DIV_N); /* Divider for internal reference clock */
I2C_OIS_per_write(0x63, DIV_M); /* Divider for internal PLL clock */
I2C_OIS_per_write(0x64, 0x4060); /* Loop Filter */
I2C_OIS_per_write(0x60, 0x3011); /* PLL */
I2C_OIS_per_write(0x65, 0x0080); /* */
I2C_OIS_per_write(0x61, 0x8002); /* VCOON */
I2C_OIS_per_write(0x61, 0x8003); /* Circuit ON */
I2C_OIS_per_write(0x61, 0x8809); /* PLL ON */
}
void VCOSET1(void)
{
I2C_OIS_per_write(0x05,
0x000C); /* Prepare for PLL clock as master clock */
I2C_OIS_per_write(0x05, 0x000D); /* Change to PLL clock */
}
/* ///////////////////////////////////////////////////////// */
/* Write Data to Slave device via I2C master device */
/* --------------------------------------------------------- */
/* <Function> */
/* I2C master send these data to the I2C slave device. */
/* This function relate to your own circuit. */
/* */
/* <Input> */
/* unsigned char slvadr I2C slave adr */
/* unsigned char size Transfer Size */
/* unsigned char *dat data matrix */
/* */
/* <Output> */
/* none */
/* */
/* <Description> */
/* [S][SlaveAdr][W]+[dat[0]]+...+[dat[size-1]][P] */
/* */
/* ========================================================= */
void WR_I2C(unsigned char slvadr, unsigned char size, unsigned char *dat)
{
s4AF_WriteReg_BU63169AF(slvadr << 1, dat, size);
}
/* ********************************************************* */
/* Read Data from Slave device via I2C master device */
/* --------------------------------------------------------- */
/* <Function> */
/* I2C master read data from the I2C slave device. */
/* This function relate to your own circuit. */
/* */
/* <Input> */
/* unsigned char slvadr I2C slave adr */
/* unsigned char size Transfer Size */
/* unsigned char *dat data matrix */
/* */
/* <Output> */
/* unsigned short int 16bit data read from I2C Slave device */
/* */
/* <Description> */
/* if size == 1 */
/* [S][SlaveAdr][W]+[dat[0]]+ [RS][SlaveAdr][R]+[RD_DAT0]+[RD_DAT1][P]
*/
/* if size == 2 */
/* [S][SlaveAdr][W]+[dat[0]]+[dat[1]]+[RS][SlaveAdr][R]+[RD_DAT0]+[RD_DAT1][P]
*/
/* */
/* ********************************************************* */
unsigned short int RD_I2C(unsigned char slvadr, unsigned char size,
unsigned char *dat)
{
unsigned short int read_data = 0;
unsigned short int read_data_h = 0;
if (size == 1) {
dat[1] = 0;
s4AF_ReadReg_BU63169AF(slvadr << 1, dat, 2,
(unsigned char *)&read_data, 2);
} else if (size == 2) {
s4AF_ReadReg_BU63169AF(slvadr << 1, dat, 2,
(unsigned char *)&read_data, 2);
}
read_data_h = read_data >> 8;
read_data = read_data << 8;
read_data = read_data | read_data_h;
return read_data;
}
/* ********************************************************* */
/* Write Factory Adjusted data to the non-volatile memory */
/* --------------------------------------------------------- */
/* <Function> */
/* Factory adjusted data are sotred somewhere */
/* non-volatile memory. */
/* */
/* <Input> */
/* struct _FACT_ADJ Factory Adjusted data */
/* */
/* <Output> */
/* none */
/* */
/* <Description> */
/* You have to port your own system. */
/* */
/* ********************************************************* */
void store_FADJ_MEM_to_non_volatile_memory(struct _FACT_ADJ param)
{
}
/* ********************************************************* */
/* Read Factory Adjusted data from the non-volatile memory */
/* --------------------------------------------------------- */
/* <Function> */
/* Factory adjusted data are sotred somewhere */
/* non-volatile memory. I2C master has to read these */
/* data and store the data to the OIS controller. */
/* */
/* <Input> */
/* none */
/* */
/* <Output> */
/* struct _FACT_ADJ Factory Adjusted data */
/* */
/* <Description> */
/* You have to port your own system. */
/* */
/* ********************************************************* */
struct _FACT_ADJ get_FADJ_MEM_from_non_volatile_memory(void)
{
unsigned short ReadData;
s4EEPROM_ReadReg_BU63169AF(0x0866, &ReadData);
FADJ_MEM.gl_CURDAT = (unsigned short int)ReadData;
s4EEPROM_ReadReg_BU63169AF(0x0868, &ReadData);
FADJ_MEM.gl_HALOFS_X = (unsigned short int)ReadData;
s4EEPROM_ReadReg_BU63169AF(0x086A, &ReadData);
FADJ_MEM.gl_HALOFS_Y = (unsigned short int)ReadData;
s4EEPROM_ReadReg_BU63169AF(0x086C, &ReadData);
FADJ_MEM.gl_HX_OFS = (unsigned short int)ReadData;
s4EEPROM_ReadReg_BU63169AF(0x086E, &ReadData);
FADJ_MEM.gl_HY_OFS = (unsigned short int)ReadData;
s4EEPROM_ReadReg_BU63169AF(0x0870, &ReadData);
FADJ_MEM.gl_PSTXOF = (unsigned short int)ReadData;
s4EEPROM_ReadReg_BU63169AF(0x0872, &ReadData);
FADJ_MEM.gl_PSTYOF = (unsigned short int)ReadData;
s4EEPROM_ReadReg_BU63169AF(0x0874, &ReadData);
FADJ_MEM.gl_GX_OFS = (unsigned short int)ReadData;
s4EEPROM_ReadReg_BU63169AF(0x0876, &ReadData);
FADJ_MEM.gl_GY_OFS = (unsigned short int)ReadData;
s4EEPROM_ReadReg_BU63169AF(0x0878, &ReadData);
FADJ_MEM.gl_KgxHG = (unsigned short int)ReadData;
s4EEPROM_ReadReg_BU63169AF(0x087A, &ReadData);
FADJ_MEM.gl_KgyHG = (unsigned short int)ReadData;
s4EEPROM_ReadReg_BU63169AF(0x087C, &ReadData);
FADJ_MEM.gl_KGXG = (unsigned short int)ReadData;
s4EEPROM_ReadReg_BU63169AF(0x087E, &ReadData);
FADJ_MEM.gl_KGYG = (unsigned short int)ReadData;
s4EEPROM_ReadReg_BU63169AF(0x0880, &ReadData);
FADJ_MEM.gl_SFTHAL_X = (unsigned short int)ReadData;
s4EEPROM_ReadReg_BU63169AF(0x0882, &ReadData);
FADJ_MEM.gl_SFTHAL_Y = (unsigned short int)ReadData;
s4EEPROM_ReadReg_BU63169AF(0x0884, &ReadData);
FADJ_MEM.gl_TMP_X_ = (unsigned short int)ReadData;
s4EEPROM_ReadReg_BU63169AF(0x0886, &ReadData);
FADJ_MEM.gl_TMP_Y_ = (unsigned short int)ReadData;
s4EEPROM_ReadReg_BU63169AF(0x0888, &ReadData);
FADJ_MEM.gl_KgxH0 = (unsigned short int)ReadData;
s4EEPROM_ReadReg_BU63169AF(0x088A, &ReadData);
FADJ_MEM.gl_KgyH0 = (unsigned short int)ReadData;
return FADJ_MEM; /* Note: This return data is for DEBUG. */
}
/* ********************************************************* */
/* Wait */
/* --------------------------------------------------------- */
/* <Function> */
/* */
/* <Input> */
/* unsigned long int time on the micro second time scale */
/* */
/* <Output> */
/* none */
/* */
/* <Description> */
/* */
/* ********************************************************* */
void Wait_usec(unsigned long time)
{
/* Please write your source code here. */
}
#ifdef DEBUG_FADJ
/* ********************************************************* */
/* Printf for DEBUG */
/* --------------------------------------------------------- */
/* <Function> */
/* */
/* <Input> */
/* const char *format, ... */
/* Same as printf */
/* */
/* <Output> */
/* none */
/* */
/* <Description> */
/* */
/* ********************************************************* */
int debug_print(const char *format, ...)
{
return 0;
}
#endif
@@ -0,0 +1,56 @@
/* SPDX-License-Identifier: GPL-2.0 */
/*
* Copyright (c) 2019 MediaTek Inc.
*/
#ifndef OIS_COEF_H
#define OIS_COEF_H
const unsigned char DOWNLOAD_COEF[] = {
0xef, 0x00, 0x00, 0x00, 0x20, 0x00, 0x18, 0x00, 0x00, 0x00, 0x00, 0xab,
0x0a, 0x00, 0x40, 0x00, 0x40, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x80, 0x00, 0x00, 0x9b, 0x82, 0xae, 0x7e, 0xa7, 0x00, 0xff, 0x7f, 0xff,
0x7f, 0xff, 0x7f, 0x7f, 0x7f, 0x7e, 0x7e, 0xfc, 0x7c, 0xf2, 0x72, 0x5e,
0x5e, 0xec, 0x6c, 0x5b, 0x5b, 0x56, 0x56, 0x3f, 0x3f, 0xb0, 0x30, 0x9b,
0x1b, 0xa5, 0x25, 0x3f, 0x3f, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x3a, 0x00, 0xfa, 0x05, 0x1b, 0x00,
0x20, 0x00, 0xc5, 0x00, 0x1f, 0x89, 0x41, 0x00, 0x7f, 0xff, 0x7f, 0xd5,
0x09, 0x00, 0x00, 0xff, 0x7f, 0x00, 0x00, 0x00, 0x00, 0x00, 0xb0, 0x00,
0x70, 0xe0, 0x7f, 0x52, 0x09, 0x00, 0x00, 0xe0, 0x7f, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x0c, 0xff, 0x7f, 0x00, 0x40, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x20, 0xff, 0x7f, 0x00, 0x4c, 0xff,
0x7f, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xff,
0x7f, 0x00, 0x00, 0xff, 0x7f, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x80, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x20, 0xff, 0x7f, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xff,
0x7f, 0x00, 0x60, 0x00, 0x20, 0x00, 0x00, 0x10, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0xff, 0x7f, 0x00, 0x60, 0x00, 0x20, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0xff, 0x7f, 0x00, 0x80, 0x1b, 0x1c, 0x1f,
0x05, 0xc4, 0x20, 0x2d, 0xf0, 0x00, 0x10, 0x10, 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, 0x02, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x2d, 0x68, 0x00, 0x00, 0x00, 0x40, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x0e, 0x01, 0x00, 0x01, 0x00, 0x00, 0x00, 0x08, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x3a, 0x00,
0xfa, 0x05, 0x1b, 0x00, 0x20, 0x00, 0xc6, 0x00, 0x1f, 0x89, 0x41, 0x00,
0x7f, 0xff, 0x7f, 0xd5, 0x09, 0x00, 0x00, 0xff, 0x7f, 0x00, 0x00, 0x00,
0x00, 0x00, 0xb0, 0x00, 0x70, 0xe0, 0x7f, 0x52, 0x09, 0x00, 0x00, 0xe0,
0x7f, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x0a, 0xff, 0x7f, 0x00,
0x40, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x20, 0xff,
0x7f, 0x00, 0x4c, 0xff, 0x7f, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0xff, 0x7f, 0x00, 0x00, 0xff, 0x7f, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x80, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0xf0, 0x21, 0xff, 0x7f, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0xff, 0x7f, 0x00, 0x60, 0x00, 0x20, 0x00, 0x00, 0x10,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xff, 0x7f, 0x00, 0x60, 0x00,
0x20,
};
const unsigned short int DOWNLOAD_COEF_LEN = sizeof(DOWNLOAD_COEF);
#endif /* OIS_COEF_H */
@@ -0,0 +1,703 @@
/* SPDX-License-Identifier: GPL-2.0 */
/*
* Copyright (c) 2019 MediaTek Inc.
*/
#ifndef OIS_DEFINITION_H
#define OIS_DEFINITION_H
/* ================================================================= */
/* Common */
/* ================================================================= */
#define __ON_ 1
#define _OFF_ 0
#define __IN_ 1
#define _MON_ 2
#define _PWM32__ 3
#define _PWM3_1_ 4
#define _PWM3__0 5
#define _PWM_21_ 6
#define _PWM_2_0 7
#define _PWM__10 8
#define _PRN_ 4
#define _m_RSP 1
#define _m_CLK_GEN 2
#define _m_CLK_TRI 3
#define _m_I2C_SLV 4
#define _m_SPI_MAS 5
#define _m_PWM_CNT 6
#define _m_ADA_WRP 7
#define _m_EXT_SIG 8
#define _HIGH_ 1
#define __LOW_ 0
#define _FOCUS_ 1
#define _ZOOM__ 0
#define _FACTORY_ 1
#define _NORMADJ_ 2
#define _NORMAL__ 0
#define _NOT_READY 0
/* ================================================================= */
/* PIC uP port assign */
/* ================================================================= */
#define _PIO_O_L_ 0
#define _PIO_O_H_ 1
#define _PIO_INP_ 2
#define _PIC_RB_0_ 0x00
#define _PIC_RB_1_ 0x01
#define _PIC_RB_2_ 0x02
#define _PIC_RB_3_ 0x03
#define _PIC_RB_4_ 0x04
#define _PIC_RB_5_ 0x05
#define _PIC_RB_6_ 0x06
#define _PIC_RB_7_ 0x07
#define _PIC_RB_8_ 0x08
#define _PIC_RB_9_ 0x09
#define _PIC_RB_A_ 0x0A
#define _PIC_RB_B_ 0x0B
#define _PIC_RB_C_ 0x0C
#define _PIC_RB_D_ 0x0D
#define _PIC_RB_E_ 0x0E
#define _PIC_RB_F_ 0x0F
#define _PIC_RC_0_ 0x10
#define _PIC_RC_1_ 0x11
#define _PIC_RC_2_ 0x12
#define _PIC_RC_3_ 0x13
#define _PIC_RC_4_ 0x14
#define _PIC_RC_5_ 0x15
#define _PIC_RC_6_ 0x16
#define _PIC_RC_7_ 0x17
#define _PIC_RC_8_ 0x18
#define _PIC_RC_9_ 0x19
#define _PIC_RC_A_ 0x1A
#define _PIC_RC_B_ 0x1B
#define _PIC_RC_C_ 0x1C
#define _PIC_RC_D_ 0x1D
#define _PIC_RC_E_ 0x1E
#define _PIC_RC_F_ 0x1F
#define _PIC_RD_0_ 0x20
#define _PIC_RD_1_ 0x21
#define _PIC_RD_2_ 0x22
#define _PIC_RD_3_ 0x23
#define _PIC_RD_4_ 0x24
#define _PIC_RD_5_ 0x25
#define _PIC_RD_6_ 0x26
#define _PIC_RD_7_ 0x27
#define _PIC_RD_8_ 0x28
#define _PIC_RD_9_ 0x29
#define _PIC_RD_A_ 0x2A
#define _PIC_RD_B_ 0x2B
#define _PIC_RD_C_ 0x2C
#define _PIC_RD_D_ 0x2D
#define _PIC_RD_E_ 0x2E
#define _PIC_RD_F_ 0x2F
#define _PIC_RE_0_ 0x30
#define _PIC_RE_1_ 0x31
#define _PIC_RE_2_ 0x32
#define _PIC_RE_3_ 0x33
#define _PIC_RE_4_ 0x34
#define _PIC_RE_5_ 0x35
#define _PIC_RE_6_ 0x36
#define _PIC_RE_7_ 0x37
#define _PIC_RE_8_ 0x38
#define _PIC_RE_9_ 0x39
#define _PIC_RE_A_ 0x3A
#define _PIC_RE_B_ 0x3B
#define _PIC_RE_C_ 0x3C
#define _PIC_RE_D_ 0x3D
#define _PIC_RE_E_ 0x3E
#define _PIC_RE_F_ 0x3F
#define _PIC_RF_0_ 0x40
#define _PIC_RF_1_ 0x41
#define _PIC_RF_2_ 0x42
#define _PIC_RF_3_ 0x43
#define _PIC_RF_4_ 0x44
#define _PIC_RF_5_ 0x45
#define _PIC_RF_6_ 0x46
#define _PIC_RF_7_ 0x47
#define _PIC_RF_8_ 0x48
#define _PIC_RF_9_ 0x49
#define _PIC_RF_A_ 0x4A
#define _PIC_RF_B_ 0x4B
#define _PIC_RF_C_ 0x4C
#define _PIC_RF_D_ 0x4D
#define _PIC_RF_E_ 0x4E
#define _PIC_RF_F_ 0x4F
#define _PIC_RG_6_ 0x56
#define _PIC_AD_0_ 8
#define _PIC_AD_1_ 9
#define _PIC_AD_2_ 10
#define _PIC_AD_3_ 11
#define _PIC_AD_4_ 12
#define _PIC_AD_5_ 13
#define _PIC_AD_6_ 14
/* _picsig_PS_POL = _PIC_RB_8_ */
#define _picsig_PS____ _PIC_RE_5_
#define _picsig_TRIG__ _PIC_RE_4_
#define _picsig_AF____ _PIC_RC_E_
/* _picsig_Shutr_ = _PIC_RD_1_ */
#define _picsig_FPGAcs _PIC_RB_6_
/* _picsig_CRNR_0 = _PIC_RD_2_ */
/* _picsig_CRNR_1 = _PIC_RD_1_ */
/* _picsig_CRNR_2 = _PIC_RC_E_ */
/* _picsig_CRNR_3 = _PIC_RC_D_ */
/* ================================================================= */
/* OIS controller assign */
/* ================================================================= */
/* Slave Address */
#define _SLV_OIS_ 0x0E
/* Packet Command OP code */
#define _OP_FIRM_DWNLD 0x80
#define _OP_Periphe_RW 0x82
#define _OP_Memory__RW 0x84
#define _OP_AD_TRNSFER 0x86
#define _OP_COEF_DWNLD 0x88
#define _OP_PrgMem__RD 0x8A
#define _OP_SpecialCMD 0x8C
#define _cmd_8C_EI 0x0001
#define _cmd_8C_DI 0x0002
#define _cmd_8C_STRB 0x0004
#define _cmd_8C_TRI_SHT 0x0008
#define _cmd_8C_TRI_con 0x0010
#define _OP_FX_Cmnd_0 0xF0
#define _OP_FX_Cmnd_1 0xF1
#define _OP_FX_Cmnd_2 0xF2
#define _OP_FX_Cmnd_3 0xF3
#define _OP_FX_Cmnd_8 0xF8
#define _OP_FX_Cmnd_A 0xFA
/* Peripheral Adr Mapping */
#define _P_00_CLK_CONTRL 0x00
#define _P_01_CLK_PWMCNT 0x01
#define _P_02_CLK_TMRCNT 0x02
#define _P_03_CLK_DWNSMP 0x03
#define _P_04_CLK_CALDIV 0x04
#define _P_05_CLK_CLKSEL 0x05
#define _P_06_CLK_MONITR 0x06
/* _P_07) */
#define _P_08_TRI_CNTRL_ 0x08
#define _P_09_TRI_TARGET 0x09
#define _P_0A_TRI_PHSCNT 0x0A
/* _P_0B) */
/* _P_0C) */
/* _P_0D) */
/* _P_0E) */
/* _P_0F) */
#define _P_10_I2C_SLVADR 0x10
#define _P_11_I2C__DATA_ 0x11
#define _P_12_I2C_STSADR 0x12
#define _P_13_I2C_MONSEL 0x13
#define _P_14_I2C_OFSREG 0x14
/* _P_15) */
/* _P_16) */
/* _P_17) */
#define _P_18_SPI_TRSNUM 0x18
#define _P_19_SPI_CONTRL 0x19
/* _P_1A_SPI_D_000H = 0x1A */
#define _P_1A_SPI_D_HHHL 0x1B
#define _P_1B_SPI_D_LHLL 0x1C
/* _P_1B) */
/* _P_1C) */
/* _P_1D) */
/* _P_1E) */
/* _P_1F) */
#define _P_20_MSC_MONCTL1 0x20
#define _P_21_MSC_MONCTL2 0x21
#define _P_22_MSC_PORTCTL 0x22
#define _P_23_MSC_PORTSTS 0x23
#define _P_24_MSC_PWMREGA 0x24
#define _P_25_MSC_PWMREGB 0x25
#define _P_26_MSC_SIGMON 0x26
/* _P_27) */
#define _P_28_PWM_ENB_SR 0x28
#define _P_29_PWM_FRQSEL 0x29
#define _P_2A_PWM_SFT_YX 0x2A
#define _P_2B_PWM_SFT__Z 0x2B
#define _P_2C_PWM_ChX_DAT 0x2C
#define _P_2D_PWM_ChY_DAT 0x2D
#define _P_2E_PWM_ChZ_DAT 0x2E
#define _P_2F_PWM_SMPLSFT 0x2F
#define _P_30_ADC_CH0 0x30
#define _P_31_ADC_CH1 0x31
#define _P_32_ADC_CH2 0x32
#define _P_33_ADC_CH3 0x33
#define _P_34_ADC_CH4 0x34
#define _P_35_ADC_CH5 0x35
#define _P_36_ADC_CH6 0x36
#define _P_37_ADC_CH7 0x37
#define _P_38_Ch3_VAL_0 0x38
#define _P_39_Ch3_VAL_1 0x39
#define _P_3A_Ch3_VAL_2 0x3A
#define _P_3B_Ch3_VAL_3 0x3B
#define _P_3C_ADC_GAIN 0x3C
#define _P_3D_ADC_CTL 0x3D
/* _P_3E) */
/* _P_3F) */
#define _P_40_OUT_CH 0x40
#define _P_41_OUT_CTL 0x41
#define _P_42_OUT_DAC 0x42
#define _P_43_OUT_SW 0x43
/* _P_44) */
/* _P_45) */
/* _P_46) */
/* _P_47) */
#define _P_48_TOP_00 0x48
/* _P_49) */
/* _P_4A) */
/* _P_4B) */
/* _P_4C) */
/* _P_4D) */
/* _P_4E) */
/* _P_4F) */
#define _P_50_TST_TSTCMD 0x50
#define _P_51_TST_AF_SLP 0x51
#define _P_52_TST_AF_OFS 0x52
#define _P_53_TST_SH_SLP 0x53
#define _P_54_TST_OSC___ 0x54
#define _P_55_TST_VREF__ 0x55
#define _P_56_TST_MUXCRN 0x56
#define _P_57_TST_TSADAC 0x57
#define _P_58_TST_FIXHBR 0x58
#define _P_59_TST_SMPPWR 0x59
#define _P_5A_TST_MPXFIX 0x5A
/* _P_5B_) ,0x5B */
/* _P_5C_) ,0x5C */
/* _P_5D_) ,0x5D */
/* _P_5E_) ,0x5E */
#define _P_5F_TST_INFVER 0x5F
#define _P_F0_I2CnSTR 0xF0
#define _P_F1_I2CnSTR 0xF1
#define _P_F2_I2CnSTR 0xF2
#define _P_F3_I2CnSTR 0xF3
/* Memory Adr Mapping */
#define _M_Kgx01 0x00
#define _M_Kgx02 0x01
#define _M_Kgx03 0x02
#define _M_Kgx04 0x03
#define _M_wDgx00 0x04
#define _M_X_HPF0 0x05
#define _M_Kgx00 0x06
#define _M_wDgxof 0x07
#define _M_Kgx05 0x08
#define _M_Kgx06 0x09
#define _M_Kgx07 0x0A
#define _M_Kgx08 0x0B
#define _M_wDgx01 0x0C
#define _M_X_HPF1 0x0D
#define _M_KgxWv 0x0E
#define _M_KgxG 0x0F
#define _M_Kgx09 0x10
#define _M_Kgx0A 0x11
#define _M_Kgx0B 0x12
#define _M_Kgx0C 0x13
#define _M_wDgx02 0x14
#define _M_X_HPF2 0x15
#define _M_wDgx04 0x16
#define _M_X_TRGT 0x17
#define _M_Kgx0D 0x18
#define _M_Kgx0E 0x19
#define _M_Kgx0F 0x1A
#define _M_Kgx10 0x1B
#define _M_wDgx03 0x1C
#define _M_X_HPF3 0x1D
#define _M_X_H_ofs 0x1E
#define _M_X_wGIN 0x1F
#define _M_Kgx1F 0x20
#define _M_Kgx20 0x21
#define _M_Kgx21 0x22
#define _M_Kgx22 0x23
#define _M_wDgx0B 0x24
#define _M_wDgx_EQL1 0x25
#define _M_X_wGOU 0x26
#define _M_wDgx09 0x27
#define _M_Kgx1B 0x28
#define _M_Kgx1C 0x29
#define _M_Kgx1D 0x2A
#define _M_Kgx1E 0x2B
#define _M_wDgx0A 0x2C
#define _M_wDgx_EQH 0x2D
#define _M_X_wGAS 0x2E
#define _M_X_GYIN 0x2F
#define _M_Kgx23 0x30
#define _M_Kgx24 0x31
#define _M_Kgx25 0x32
#define _M_Kgx26 0x33
#define _M_wDgx0C 0x34
#define _M_wDgx_EQL 0x35
#define _M_Kgxdr 0x36
#define _M_X_axofs 0x37
#define _M_Kgx11 0x38
#define _M_Kgx12 0x39
#define _M_Kgx13 0x3A
#define _M_Kgx14 0x3B
#define _M_Kgx15 0x3C
#define _M_wDgx05 0x3D
#define _M_wDgx06 0x3E
#define _M_X_H_Lmt 0x3F
#define _M_X_LMT 0x40
#define _M_X_LMO 0x41
#define _M_X_DRP 0x42
#define _M_X_TGT 0x43
#define _M_Kgx19 0x44
#define _M_Kgx1A 0x45
#define _M_KgxHG 0x46
#define _M_KgxTG 0x47
#define _M_Kgx01t 0x48
#define _M_Kgx02t 0x49
#define _M_Kgx03t 0x4A
#define _M_Kgx04t 0x4B
#define _M_Kgx05t 0x4C
#define _M_wDgx01t 0x4D
#define _M_wDgx02t 0x4E
#define _M_wDgx_EQ 0x4F
/* #define _M_rsv 0x50 */
/* #define _M_rsv 0x51 */
/* #define _M_rsv 0x52 */
/* #define _M_rsv 0x53 */
/* #define _M_rsv 0x54 */
#define _M_DigGx 0x55
#define _M_DigGy 0x56
#define _M_CURIN 0x57
/* #define _M_rsv 0x58 */
/* #define _M_rsv 0x59 */
/* #define _M_rsv 0x5A */
/* #define _M_rsv 0x5B */
#define _M_wDf00 0x5C
#define _M_FOTRIM 0x5D
#define _M_CUROFS 0x5E
#define _M_Kf0A 0x5F
#define _M_wCRFED 0x60
#define _M_wFTRGT 0x61
#define _M_wFSUB 0x62
/* #define _M_rsv 0x63 */
#define _M_Kf0C 0x64
#define _M_wDf03 0x65
#define _M_rsv 0x66
#define _M_CUROFO 0x67
#define _M_Kf00 0x68
#define _M_Kf01 0x69
#define _M_TMP_X_ 0x6A /* RHM_HT 2013/11/25 Modified */
#define _M_TMP_Y_ 0x6B /* RHM_HT 2013/11/25 Modified */
#define _M_wDf01 0x6C
#define _M_AFLPF 0x6D
/* #define _M_rsv 0x6E */
/* #define _M_rsv 0x6F */
#define _M_KgxH0 0x70 /* RHM_HT 2013/11/25 Modified */
#define _M_X_PEO 0x71
#define _M_KgyH0 0x72 /* RHM_HT 2013/11/25 Modified */
#define _M_Y_PEO 0x73
#define _M_FOC_CNTRL 0x74
/* #define _M_rsv 0x75 */
#define _M_CEFTYP 0x76
#define _M_GYRSNS 0x77
#define _M_SHDAC0 0x78
#define _M_SHDAC1 0x79
#define _M_Ksh0 0x7A
#define _M_Ksh1 0x7B
#define _M_mon0 0x7C
#define _M_mon1 0x7D
#define _M_GLBFLG 0x7E
#define _M_EQCTL 0x7F
#define _M_Kgy01 0x80
#define _M_Kgy02 0x81
#define _M_Kgy03 0x82
#define _M_Kgy04 0x83
#define _M_wDgy00 0x84
#define _M_Y_HPF0 0x85
#define _M_Kgy00 0x86
#define _M_wDgyof 0x87
#define _M_Kgy05 0x88
#define _M_Kgy06 0x89
#define _M_Kgy07 0x8A
#define _M_Kgy08 0x8B
#define _M_wDgy01 0x8C
#define _M_Y_HPF1 0x8D
#define _M_KgyWv 0x8E
#define _M_KgyG 0x8F
#define _M_Kgy09 0x90
#define _M_Kgy0A 0x91
#define _M_Kgy0B 0x92
#define _M_Kgy0C 0x93
#define _M_wDgy02 0x94
#define _M_Y_HPF2 0x95
#define _M_wDgy04 0x96
#define _M_Y_TRGT 0x97
#define _M_Kgy0D 0x98
#define _M_Kgy0E 0x99
#define _M_Kgy0F 0x9A
#define _M_Kgy10 0x9B
#define _M_wDgy03 0x9C
#define _M_Y_HPF3 0x9D
#define _M_Y_H_ofs 0x9E
#define _M_Y_wGIN 0x9F
#define _M_Kgy1F 0xA0
#define _M_Kgy20 0xA1
#define _M_Kgy21 0xA2
#define _M_Kgy22 0xA3
#define _M_wDgy0B 0xA4
#define _M_wDgy_EQL1 0xA5
#define _M_Y_wGOU 0xA6
#define _M_wDgy09 0xA7
#define _M_Kgy1B 0xA8
#define _M_Kgy1C 0xA9
#define _M_Kgy1D 0xAA
#define _M_Kgy1E 0xAB
#define _M_wDgy0A 0xAC
#define _M_wDgy_EQH 0xAD
#define _M_Y_wGAS 0xAE
#define _M_Y_GYIN 0xAF
#define _M_Kgy23 0xB0
#define _M_Kgy24 0xB1
#define _M_Kgy25 0xB2
#define _M_Kgy26 0xB3
#define _M_wDgy0C 0xB4
#define _M_wDgy_EQL 0xB5
#define _M_Kgydr 0xB6
#define _M_Y_axofs 0xB7
#define _M_Kgy11 0xB8
#define _M_Kgy12 0xB9
#define _M_Kgy13 0xBA
#define _M_Kgy14 0xBB
#define _M_Kgy15 0xBC
#define _M_wDgy05 0xBD
#define _M_wDgy06 0xBE
#define _M_Y_H_Lmt 0xBF
#define _M_Y_LMT 0xC0
#define _M_Y_LMO 0xC1
#define _M_Y_DRP 0xC2
#define _M_Y_TGT 0xC3
#define _M_Kgy19 0xC4
#define _M_Kgy1A 0xC5
#define _M_KgyHG 0xC6
#define _M_KgyTG 0xC7
#define _M_Kgy01t 0xC8
#define _M_Kgy02t 0xC9
#define _M_Kgy03t 0xCA
#define _M_Kgy04t 0xCB
#define _M_Kgy05t 0xCC
#define _M_wDgy01t 0xCD
#define _M_wDgy02t 0xCE
#define _M_wDgy_EQ 0xCF
#define _M_ISRC0 0xD0
#define _M_ISRC1 0xD1
#define _M_ISRC2 0xD2
#define _M_ISRC3 0xD3
#define _M_ISRC4 0xD4
#define _M_ISRC5 0xD5
#define _M_ISRC6 0xD6
#define _M_ISRC7 0xD7
#define _M_ISRC8 0xD8
#define _M_ISRC9 0xD9
#define _M_ISRCA 0xDA
#define _M_ISRCB 0xDB
#define _M_ISRCC 0xDC
#define _M_ISRCD 0xDD
#define _M_ISRCE 0xDE
#define _M_ISRCF 0xDF
#define _M_Kgy16 0xE0
#define _M_Kgy17 0xE1
#define _M_Kgy18 0xE2
#define _M_0x0000 0xE3
#define _M_0x8000 0xE4
#define _M_wDgy07 0xE5
#define _M_wDgy08 0xE6
#define _M_VMTRGT 0xE7
#define _M_Kv00 0xE8
#define _M_Kv01 0xE9
#define _M_Kv02 0xEA
#define _M_Kv03 0xEB
#define _M_wDv00 0xEC
#define _M_VMLPF 0xED
#define _M_wDv01 0xEE
#define _M_Kv04 0xEF
#define _M_SHND_sts 0xF0
#define _M_SHND_tim_org 0xF1
#define _M_SHND_tim 0xF2
#define _M_SHND_CWCCW 0xF3
#define _M_BPFOUT 0xF4
#define _M_BPFMON 0xF5
#define _M_FIRMVER 0xF6
#define _M_OIS_STS 0xF7
#define _def_OIS____________BOOT 0x00
#define _def_OIS__while_FWdwnlod 0x01
#define _def_OIS__FW_NG_NG_NG_NG 0x02
#define _def_OIS____________FWOK 0x03
#define _def_OIS_main_______IDLE 0x04
#define _M_I2C_dat 0xF8
#define _M_I2C_cmd 0xF9
#define _M_I2C_STS 0xFA
#define _M____tmp4 0xFB
#define _M____tmp3 0xFC
#define _M____tmp2 0xFD
#define _M____tmp1 0xFE
#define _M____tmp0 0xFF
/* ================================================================= */
/* Another definition */
/* ================================================================= */
/* Scene parameter */
#define _SCENE_NIGHT_1 1
#define _SCENE_NIGHT_2 2
#define _SCENE_NIGHT_3 3
#define _SCENE_D_A_Y_1 4
#define _SCENE_D_A_Y_2 5
#define _SCENE_D_A_Y_3 6
#define _SCENE_SPORT_1 7
#define _SCENE_SPORT_2 8
#define _SCENE_SPORT_3 9
#define _SCENE_TEST___ 10
/* for Factory Adjustment */
#define _CUR100mA 0x00A0
#define _CUR125mA 0x00C8
#define _CUR150mA 0x00F0
#define _CUR175mA 0x0118
#define _CUR200mA 0x0140
#define _CUR225mA 0x0168
#define _CUR250mA 0x0190
#define _CUR275mA 0x01B8
#define _CUR300mA 0x01E0
#define _CUR325mA 0x0208
#define _CUR350mA 0x0230
#define _CUR375mA 0x0258
#define _CUR400mA 0x0280
#define _VHTRGT 0x0BA2
#define _OTHR_IN_HALPX 0x0006
#define _OTHR_IN_HALPY 0x0008
#define _OTHR_HXpreOUT 0x0001
#define _OTHR_HYpreOUT 0x0002
/* Factory Adjustment data */
struct _FACT_ADJ {
unsigned short int gl_CURDAT;
unsigned short int gl_HALOFS_X;
unsigned short int gl_HALOFS_Y;
unsigned short int gl_HX_OFS;
unsigned short int gl_HY_OFS;
unsigned short int gl_PSTXOF;
unsigned short int gl_PSTYOF;
unsigned short int gl_GX_OFS;
unsigned short int gl_GY_OFS;
unsigned short int gl_KgxHG;
unsigned short int gl_KgyHG;
unsigned short int gl_KGXG;
unsigned short int gl_KGYG;
unsigned short int gl_SFTHAL_X; /* RHM_HT 2013/11/25 Added */
unsigned short int gl_SFTHAL_Y; /* RHM_HT 2013/11/25 Added */
unsigned short int gl_TMP_X_; /* RHM_HT 2013/11/25 Added */
unsigned short int gl_TMP_Y_; /* RHM_HT 2013/11/25 Added */
unsigned short int gl_KgxH0; /* RHM_HT 2013/11/25 Added */
unsigned short int gl_KgyH0; /* RHM_HT 2013/11/25 Added */
};
/* Default Parameter of FACTORY Adjust data */
/* --------------------------------------------- */
extern const struct _FACT_ADJ FADJ_DEF
#ifdef OIS_MAIN_C
= {
0x0200, /* gl_CURDAT; */
0x0200, /* gl_HALOFS_X; */
0x0200, /* gl_HALOFS_Y; */
0x0000, /* gl_HX_OFS; */
0x0000, /* gl_HY_OFS; */
0x0080,
0x0080,
0x0000, /* gl_GX_OFS; */
0x0000, /* gl_GY_OFS; */
0x2000,
0x2000,
0x2000,
0x2000,
0x0200,
0x0200,
0x0000,
0x0000,
0x0000,
0x0000,
}
#endif
;
/* FACTORY Adjusted data */
/* These data are stored at the non-vollatile */
/* memory inside of the CMOS sensor. */
/* The Host ( ISP or I2C master ) read these */
/* data from above memory and write to the OIS */
/* controller. */
/* --------------------------------------------- */
extern struct _FACT_ADJ FADJ_MEM
#ifdef OIS_MAIN_C
= {
0x0201, /* gl_CURDAT; */
0x0200, /* gl_HALOFS_X; */
0x0200, /* gl_HALOFS_Y; */
0x0000, /* gl_HX_OFS; */
0x0000, /* gl_HY_OFS; */
0x0080,
0x0080,
0x0000, /* gl_GX_OFS; */
0x0000, /* gl_GY_OFS; */
0x2000,
0x2000,
0x2000,
0x2000,
0x0200,
0x0200,
0x0000,
0x0000,
0x0000,
0x0000,
}
#endif
;
/* Parameters for expanding OIS range */
/* --------------------------------------------- */
extern double p_x, q_x;
extern double p_y, q_y;
extern short int zero_X;
extern short int zero_Y;
extern short int PREOUT_X_P, PREOUT_X_N;
extern short int PREOUT_Y_P, PREOUT_Y_N;
extern double alfa_X, beta_X;
extern double alfa_Y, beta_Y;
#endif /* OIS_DEFINITION_H */
@@ -0,0 +1,35 @@
/* SPDX-License-Identifier: GPL-2.0 */
/*
* Copyright (c) 2019 MediaTek Inc.
*/
#ifndef OIS_FUNC_H
#define OIS_FUNC_H
extern unsigned short int OIS_REQUEST; /* OIS control register. */
/* ==> RHM_HT 2013.03.04 Change type (unsigned short int -> double) */
extern double OIS_PIXEL[2]; /* Just Only use for factory adjustment. */
/* <== RHM_HT 2013.03.04 */
extern short int CROP_X; /* x start position for cropping */
extern short int CROP_Y; /* y start position for cropping */
extern short int CROP_WIDTH; /* cropping width */
extern short int CROP_HEIGHT; /* cropping height */
extern unsigned char SLICE_LEVE; /* slice level of bitmap binalization */
extern double DISTANCE_BETWEEN_CIRCLE;
extern double DISTANCE_TO_CIRCLE; /* distance to the circle [mm] */
extern double D_CF; /* Correction Factor for distance to the circle */
extern unsigned short int ACT_DRV; /* [mV]: Full Scale of OUTPUT DAC. */
extern unsigned short int FOCAL_LENGTH; /* [um]: Focal Length 3.83mm */
extern double MAX_OIS_SENSE;
extern double MIN_OIS_SENSE;
extern unsigned short int MAX_COIL_R; /* [ohm]: Max value of coil resistance */
extern unsigned short int MIN_COIL_R; /* [ohm]: Min value of coil resistance */
/* <== RHM_HT 2013/07/10 Added new user definition variables */
#endif
@@ -0,0 +1,201 @@
/* SPDX-License-Identifier: GPL-2.0 */
/*
* Copyright (c) 2019 MediaTek Inc.
*/
#ifndef OIS_MAIN_H
#define OIS_MAIN_H
/* Compile Switch Purpose */
#define ENABLE_GYRO_DRIFT_COMP /* RHM_HT 2013/11/25 Added */
#define _STR_AREA_ "F:\\DEBUGBMP\\" /* For Image save (Debug purpose) */
/* ==> RHM_HT 2013/04/15 Add to the report for error details */
/* #define OIS_TRUE 0 */
/* #define OIS_FALSE -1 */
/* #define OIS_READY 1 */
#define ADJ_OK 0
#define ADJ_ERR -1
#define PROG_DL_ERR -2
#define COEF_DL_ERR -3
#define CURDAT_FIT_ERR -4
#define CURDAT_ADJ_ERR -5
#define HALOFS_X_ADJ_ERR -6
#define HALOFS_Y_ADJ_ERR -7
#define PSTXOF_FIT_ERR -8
#define PSTYOF_FIT_ERR -9
#define PSTXOF_ADJ_ERR -10
#define PSTYOF_ADJ_ERR -11
#define KGXG_ROUGH_ADJ_ERR -12
#define KGYG_ROUGH_ADJ_ERR -13
#define GX_OFS_ADJ_ERR -14
#define GY_OFS_ADJ_ERR -15
#define TAKE_PICTURE_ERR -20
#define KGXG_FINE_ADJ_ERR -21
#define KGYG_FINE_ADJ_ERR -22
#define KGXG_SENSITIVITY_ERR -23
#define KGYG_SENSITIVITY_ERR -24
#define KGXHG_ADJ_ERR -25
#define KGYHG_ADJ_ERR -26
#define ACGX_ADJ_OVER_P -27
#define ACGY_ADJ_OVER_P -28
#define ACGX_ADJ_OVER_N -29
#define ACGY_ADJ_OVER_N -30
#define ACGX_KGXG_ADJ_ERR -31
#define ACGY_KGYG_ADJ_ERR -32
#define TMP_X_ADJ_ERR -33 /* RHM_HT 2013/11/25 Added */
#define TMP_Y_ADJ_ERR -34 /* RHM_HT 2013/11/25 Added */
#define MALLOC1_ERR -51
#define MALLOC2_ERR -52
#define MALLOC3_ERR -53
#define MALLOC4_ERR -54
/* Error for sub-routine */
#define OIS_NO_ERROR ADJ_OK
#define OIS_INVALID_PARAMETERS -100
#define OIS_FILE_RENAME_ERROR -101
#define OIS_FILE_NOT_FOUND -102
#define OIS_BITMAP_READ_ERROR -103
#define OIS_MATRIX_INV_ERROR -104
#define OIS_SC2_XLIMIT_OVER -105
#define OIS_CHART_ARRAY_OVER -106
#define OIS_DC_GAIN_SENS_OVER -107
#define OIS_MALLOC1_ERROR -111
#define OIS_MALLOC2_ERROR -112
#define OIS_MALLOC3_ERROR -113
#define OIS_MALLOC4_ERROR -114
#define OIS_MALLOC5_ERROR -115
#define OIS_MALLOC6_ERROR -116
#define OIS_MALLOC7_ERROR -117
#define OIS_MALLOC8_ERROR -118
#define OIS_MALLOC9_ERROR -119
#define OIS_MALLOC10_ERROR -120
#define OIS_MALLOC11_ERROR -121
#define OIS_MALLOC12_ERROR -122
#define OIS_MALLOC13_ERROR -123
#define OIS_MALLOC14_ERROR -124 /* RHM_HT 2013/11/25 add */
struct _BMP_GET_POS {
short int x; /* x start position for clipping */
short int y; /* y start position for clipping */
short int width; /* clipping width */
short int height; /* clipping height */
unsigned char slice_level; /* slice level of bitmap binalization */
unsigned char filter; /* median filter enable */
char *direction; /* direction of detection */
};
struct _POS {
float x;
float y;
};
struct _APPROXRESULT {
double a; /* position x */
double b; /* position y */
double r; /* Radius */
};
#include "OIS_defi.h"
/* #include "windef.h" */
#define Wait(a) Wait_usec(a * 1000UL)
short int func_PROGRAM_DOWNLOAD(void);
void func_COEF_DOWNLOAD(unsigned short int u16_coef_type);
void download(unsigned short int u16_type, unsigned short int u16_coef_type);
short int func_SET_SCENE_PARAM(unsigned char u16_scene, unsigned char u16_mode,
unsigned char filter, unsigned char range,
const struct _FACT_ADJ *param);
void SET_FADJ_PARAM(const struct _FACT_ADJ *param);
short int func_SET_SCENE_PARAM_for_NewGYRO_Fil(unsigned char u16_scene,
unsigned char u16_mode,
unsigned char filter,
unsigned char range,
const struct _FACT_ADJ *param);
void HalfShutterOn(void);
void I2C_OIS_per_write(unsigned char u08_adr, unsigned short int u16_dat);
void I2C_OIS_mem_write(unsigned char u08_adr, unsigned short int u16_dat);
unsigned short int I2C_OIS_per__read(unsigned char u08_adr);
unsigned short int I2C_OIS_mem__read(unsigned char u08_adr);
void I2C_OIS_spcl_cmnd(unsigned char u08_on, unsigned char u08_dat);
void I2C_OIS_F0123_wr_(unsigned char u08_dat0, unsigned char u08_dat1,
unsigned short int u16_dat2);
unsigned short int I2C_OIS_F0123__rd(void);
void POWER_UP_AND_PS_DISABLE(void);
void POWER_DOWN_AND_PS_ENABLE(void);
void VCOSET0(void);
void VCOSET1(void);
void WR_I2C(unsigned char slvadr, unsigned char size, unsigned char *dat);
unsigned short int RD_I2C(unsigned char slvadr, unsigned char size,
unsigned char *dat);
void store_FADJ_MEM_to_non_volatile_memory(struct _FACT_ADJ param);
struct _FACT_ADJ get_FADJ_MEM_from_non_volatile_memory(void);
void Wait_usec(unsigned long time);
extern void Main_OIS(void);
extern void OIS_Standby(void);
extern int setVCMPos(unsigned short DAC_Val);
extern void setOISMode(int Disable);
extern int s4EEPROM_ReadReg_BU63169AF(unsigned short addr,
unsigned short *data);
extern int s4AF_WriteReg_BU63169AF(unsigned short i2c_id,
unsigned char *a_pSendData,
unsigned short a_sizeSendData);
extern int s4AF_ReadReg_BU63169AF(unsigned short i2c_id,
unsigned char *a_pSendData,
unsigned short a_sizeSendData,
unsigned char *a_pRecvData,
unsigned short a_sizeRecvData);
/* #define DEBUG_FADJ */
#ifdef DEBUG_FADJ
int debug_print(const char *format,
...); /* RHM_HT 2013/04/15 Add for DEBUG */
#define DEBUG_printf(a) debug_print a
#else
#define DEBUG_printf(a)
#endif
#endif /* OIS_MAIN_H */
@@ -0,0 +1,402 @@
/* SPDX-License-Identifier: GPL-2.0 */
/*
* Copyright (c) 2019 MediaTek Inc.
*/
#ifndef OIS_PROG_H
#define OIS_PROG_H
const unsigned char DOWNLOAD_BIN[] = {
/* DOWNLOAD2d_SEMCO_Xiaomi_C1.bin */
0x00, 0x95, 0x6C, 0x00, 0x05, 0xFF, 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, 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, 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,
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, 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, 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, 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, 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, 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,
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, 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, 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, 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, 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, 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,
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, 0x03, 0x00, 0x90, 0x00,
0x84, 0x00, 0x20, 0x08, 0x10, 0x00, 0x20, 0x10, 0x10, 0x08, 0x40, 0xFF,
0xA0, 0x20, 0x0F, 0x08, 0x40, 0x1D, 0xA0, 0x04, 0xFF, 0x84, 0x80, 0x00,
0x90, 0x00, 0x03, 0x00, 0x04, 0xB6, 0x44, 0x40, 0xFF, 0xA0, 0x10, 0xB9,
0x44, 0x00, 0x10, 0x08, 0x20, 0xB9, 0x60, 0x10, 0x00, 0x08, 0x7F, 0xFF,
0x11, 0x8F, 0x02, 0x07, 0x80, 0x00, 0x11, 0x40, 0xFF, 0xA0, 0x10, 0xBA,
0x44, 0x00, 0x00, 0x08, 0x20, 0xBA, 0x60, 0x00, 0x01, 0x11, 0x8F, 0x02,
0x07, 0x10, 0x00, 0x20, 0xFF, 0xFF, 0x11, 0x50, 0x0F, 0x07, 0x00, 0x20,
0x08, 0x10, 0xFF, 0x84, 0x10, 0x10, 0x08, 0x40, 0xFF, 0xA0, 0x20, 0x8F,
0x08, 0x20, 0xB9, 0x50, 0x20, 0x00, 0x08, 0x20, 0xBA, 0x50, 0x40, 0x1D,
0xA0, 0x04, 0xFF, 0x84, 0x00, 0x03, 0x00, 0x04, 0xB5, 0x44, 0x40, 0xFF,
0xA0, 0x10, 0xB7, 0x44, 0x00, 0x10, 0x08, 0x20, 0xB7, 0x60, 0x10, 0x00,
0x08, 0x7F, 0xFF, 0x11, 0x8F, 0x02, 0x07, 0x80, 0x00, 0x11, 0x40, 0xFF,
0xA0, 0x10, 0xB8, 0x44, 0x00, 0x00, 0x08, 0x20, 0xB8, 0x60, 0x00, 0x01,
0x11, 0x8F, 0x02, 0x07, 0x10, 0x00, 0x20, 0xFF, 0xFF, 0x11, 0x50, 0x0F,
0x07, 0x00, 0x20, 0x08, 0x10, 0xFF, 0x84, 0x10, 0x10, 0x08, 0x40, 0xFF,
0xA0, 0x20, 0x8F, 0x08, 0x20, 0xB7, 0x50, 0x20, 0x00, 0x08, 0x20, 0xB8,
0x50, 0x40, 0x1D, 0xA0, 0x04, 0xFF, 0x84, 0x00, 0x03, 0x00, 0x20, 0x0F,
0x08, 0x40, 0xFB, 0xA0, 0x60, 0x02, 0x07, 0x00, 0x00, 0x21, 0x10, 0x10,
0x08, 0x10, 0xFB, 0x84, 0x40, 0xFB, 0xA0, 0x3F, 0xF1, 0x00, 0x08, 0xFB,
0x84, 0x00, 0x03, 0x00, 0x20, 0x0F, 0x08, 0x40, 0xFB, 0xA0, 0x60, 0x02,
0x07, 0x10, 0x10, 0x08, 0x10, 0xFB, 0x84, 0x40, 0xFB, 0xA0, 0x3F, 0xFA,
0x00, 0x08, 0xFB, 0x84, 0x00, 0x03, 0x00, 0x20, 0x0F, 0x08, 0x7F, 0xFF,
0x11, 0x8F, 0x02, 0x07, 0x80, 0x00, 0x11, 0x00, 0x03, 0x00, 0x8F, 0xFF,
0x07, 0x20, 0x19, 0x60, 0x04, 0x1C, 0x44, 0x04, 0x1B, 0x44, 0x00, 0x03,
0x00, 0x10, 0x7E, 0x84, 0x50, 0x00, 0x08, 0x40, 0x7E, 0xA0, 0x00, 0x03,
0x00, 0x10, 0x7E, 0x84, 0x60, 0x00, 0x08, 0x40, 0x7E, 0xA0, 0x00, 0x03,
0x00, 0x04, 0x6E, 0x84, 0x00, 0x05, 0x21, 0x20, 0x04, 0x00, 0x00, 0x04,
0x11, 0x30, 0x05, 0x07, 0x70, 0x00, 0x08, 0x00, 0x00, 0x11, 0x40, 0xFF,
0xA0, 0x90, 0x01, 0x84, 0x00, 0x10, 0x08, 0x80, 0x01, 0xA0, 0x20, 0x1F,
0x08, 0x40, 0xF5, 0xA0, 0x10, 0xFF, 0x84, 0x20, 0x2B, 0x00, 0x20, 0x8D,
0x50, 0x20, 0x11, 0x07, 0x70, 0x00, 0x08, 0x40, 0xFE, 0xA0, 0x20, 0x14,
0x07, 0x70, 0x00, 0x08, 0x40, 0xF5, 0xA0, 0x00, 0x00, 0x11, 0x90, 0x18,
0x84, 0x00, 0x10, 0x08, 0x80, 0x18, 0xA0, 0x10, 0x00, 0x08, 0x7F, 0xFF,
0x11, 0x8F, 0x02, 0x07, 0x80, 0x00, 0x11, 0x40, 0xFF, 0xA0, 0x90, 0x19,
0x84, 0x20, 0x8C, 0x08, 0x40, 0xFE, 0x90, 0x40, 0xF5, 0xA0, 0x00, 0x00,
0x08, 0x80, 0x19, 0xA0, 0x00, 0x01, 0x11, 0x8F, 0x02, 0x07, 0xFF, 0xFF,
0x11, 0x08, 0x00, 0x20, 0x50, 0x12, 0x07, 0x00, 0x10, 0x08, 0x80, 0x18,
0xA0, 0x10, 0xFF, 0x84, 0x20, 0x1A, 0x08, 0x7F, 0xFF, 0x21, 0x10, 0xFE,
0x84, 0x20, 0x0F, 0x08, 0x80, 0x47, 0xA0, 0x00, 0x06, 0x07, 0x20, 0x1C,
0x08, 0x7F, 0xFF, 0x21, 0x10, 0xFE, 0x84, 0x20, 0x0F, 0x08, 0x80, 0x47,
0xA0, 0x00, 0x03, 0x00, 0x90, 0x17, 0x84, 0x20, 0x1F, 0x08, 0x80, 0x17,
0xA0, 0x10, 0x10, 0x08, 0x7F, 0xFF, 0x21, 0x10, 0x00, 0x08, 0x01, 0x00,
0x11, 0x40, 0x51, 0xA0, 0x90, 0x17, 0x84, 0x20, 0x0F, 0x08, 0x80, 0x47,
0xA0, 0x8D, 0x0C, 0x07, 0x00, 0x00, 0x11, 0x30, 0x03, 0x07, 0x80, 0x41,
0x90, 0x50, 0x00, 0x08, 0x40, 0xFC, 0x90, 0x88, 0x2F, 0x84, 0x00, 0x00,
0x11, 0x30, 0x02, 0x07, 0x40, 0xFF, 0x90, 0x50, 0x00, 0x08, 0x40, 0xFD,
0x90, 0x40, 0x7F, 0xA0, 0x10, 0xFF, 0x84, 0x20, 0x2D, 0x08, 0x7F, 0xFF,
0x11, 0x20, 0x0D, 0x08, 0x80, 0x0F, 0x90, 0x80, 0x26, 0xA0, 0x90, 0x2E,
0x84, 0x00, 0x10, 0x08, 0x90, 0x26, 0x84, 0x00, 0x10, 0x08, 0x80, 0x1F,
0xA0, 0x20, 0x2E, 0x08, 0x40, 0xED, 0x90, 0x20, 0x0F, 0x08, 0x80, 0x0E,
0x90, 0x00, 0x00, 0x21, 0x30, 0x02, 0x07, 0x40, 0xEB, 0xA0, 0x50, 0x00,
0x08, 0x40, 0xFE, 0x90, 0x40, 0x7F, 0xA0, 0x04, 0xEB, 0x84, 0x10, 0x00,
0x20, 0x20, 0x0F, 0x08, 0x80, 0x00, 0x21, 0x60, 0x04, 0x07, 0x40, 0xFF,
0xA0, 0x10, 0x00, 0x08, 0x40, 0xEA, 0x90, 0x10, 0x00, 0x20, 0x20, 0x0F,
0x08, 0x80, 0x00, 0x11, 0x00, 0x0B, 0x07, 0x08, 0x00, 0x20, 0x60, 0x0D,
0x07, 0x10, 0x00, 0x08, 0x40, 0xEA, 0x90, 0x8F, 0x06, 0x07, 0x04, 0xFF,
0x84, 0x20, 0x09, 0x60, 0x10, 0xFC, 0x84, 0x08, 0xFD, 0x84, 0x04, 0xFE,
0x84, 0x00, 0x03, 0x00, 0x00, 0x10, 0x08, 0x80, 0x37, 0xA0, 0x90, 0x69,
0x84, 0x00, 0x10, 0x08, 0x80, 0x69, 0xA0, 0x20, 0x1A, 0x08, 0x40, 0x64,
0xA0, 0x10, 0x10, 0x08, 0x80, 0x4F, 0xA0, 0x20, 0x2E, 0x08, 0x5B, 0xD7,
0x11, 0x20, 0x1D, 0x08, 0x40, 0x5F, 0xA0, 0x20, 0x1E, 0x08, 0x40, 0x5D,
0xA0, 0x10, 0x00, 0x08, 0x80, 0x68, 0x90, 0x40, 0xFE, 0xA0, 0x20, 0x10,
0x07, 0x50, 0x00, 0x08, 0x40, 0x7F, 0xA0, 0x04, 0xFE, 0x84, 0x00, 0x04,
0x00, 0x00, 0x00, 0x00, 0x10, 0x0A, 0x44, 0x10, 0xF4, 0x84, 0x3A, 0xDF,
0x00, 0xE0, 0x14, 0x43, 0x08, 0x00, 0x20, 0x00, 0x06, 0x07, 0x89, 0x02,
0x07, 0x40, 0xAE, 0x90, 0x81, 0x04, 0x07, 0x40, 0x2E, 0x90, 0x40, 0x7F,
0xA0, 0x00, 0x00, 0x00, 0x10, 0xCF, 0x84, 0x20, 0x1A, 0x08, 0x7F, 0xFF,
0x21, 0x10, 0xAE, 0x44, 0x00, 0x10, 0x08, 0x40, 0xFF, 0xA0, 0x04, 0xAF,
0x44, 0x20, 0x8E, 0x08, 0x40, 0xC9, 0x90, 0x20, 0xAE, 0x60, 0x20, 0x0F,
0x08, 0x40, 0xCA, 0x90, 0x20, 0xAF, 0x60, 0x10, 0xFF, 0x84, 0x00, 0x10,
0x08, 0x04, 0xCD, 0x84, 0x40, 0xFF, 0xA0, 0x08, 0xCE, 0x84, 0x20, 0x8E,
0x08, 0x40, 0xCD, 0x90, 0x40, 0xCB, 0xA0, 0x20, 0x0F, 0x08, 0x40, 0xCE,
0x90, 0x40, 0xCC, 0xA0, 0x10, 0xFF, 0x84, 0x20, 0x2F, 0x08, 0x40, 0xC8,
0x90, 0x00, 0x00, 0x08, 0x40, 0xB5, 0x90, 0x40, 0xAD, 0xA0, 0x00, 0x1F,
0x07, 0x10, 0x4F, 0x84, 0x20, 0x1A, 0x08, 0x7F, 0xFF, 0x21, 0x10, 0xAC,
0x44, 0x00, 0x10, 0x08, 0x40, 0xFF, 0xA0, 0x04, 0xAD, 0x44, 0x20, 0x8E,
0x08, 0x40, 0x49, 0x90, 0x20, 0xAC, 0x60, 0x20, 0x0F, 0x08, 0x40, 0x4A,
0x90, 0x20, 0xAD, 0x60, 0x10, 0xFF, 0x84, 0x00, 0x10, 0x08, 0x04, 0x4D,
0x84, 0x40, 0xFF, 0xA0, 0x08, 0x4E, 0x84, 0x20, 0x8E, 0x08, 0x40, 0x4D,
0x90, 0x40, 0x4B, 0xA0, 0x20, 0x0F, 0x08, 0x40, 0x4E, 0x90, 0x40, 0x4C,
0xA0, 0x10, 0xFF, 0x84, 0x20, 0x2F, 0x08, 0x40, 0x48, 0x90, 0x00, 0x00,
0x08, 0x40, 0x35, 0x90, 0x40, 0x2D, 0xA0, 0x00, 0x3E, 0x07, 0x80, 0x21,
0x07, 0x82, 0x03, 0x07, 0x04, 0x50, 0x84, 0x10, 0x00, 0x20, 0x20, 0x02,
0x07, 0x00, 0x08, 0x21, 0x40, 0x00, 0x08, 0x00, 0x01, 0x11, 0x40, 0x50,
0xA0, 0x00, 0x04, 0x00, 0x20, 0x6E, 0x00, 0x80, 0x14, 0x43, 0x01, 0x00,
0x01, 0x04, 0x00, 0x11, 0x02, 0x00, 0x21, 0x08, 0x9F, 0x84, 0x20, 0x94,
0x50, 0x08, 0x93, 0x44, 0x9C, 0x03, 0x07, 0x40, 0x7F, 0xA0, 0x10, 0x00,
0x10, 0x10, 0x20, 0x08, 0x40, 0x97, 0x90, 0x10, 0xBF, 0x84, 0x20, 0x1D,
0x08, 0x40, 0xC6, 0xA0, 0x20, 0x8E, 0x08, 0x40, 0x72, 0x90, 0x40, 0x16,
0xA0, 0x10, 0x96, 0x84, 0x10, 0x00, 0x08, 0x40, 0x9E, 0xA0, 0x20, 0x36,
0x50, 0x20, 0x85, 0x00, 0x00, 0x14, 0x43, 0x00, 0x01, 0x01, 0x00, 0x04,
0x11, 0x00, 0x02, 0x21, 0x08, 0x1F, 0x84, 0x20, 0x94, 0x50, 0x08, 0x93,
0x44, 0x9F, 0x03, 0x07, 0x40, 0x7F, 0xA0, 0x10, 0x00, 0x10, 0x10, 0x20,
0x08, 0x40, 0x17, 0x90, 0x10, 0x3F, 0x84, 0x20, 0x1D, 0x08, 0x40, 0x46,
0xA0, 0x20, 0x8E, 0x08, 0x40, 0x70, 0x90, 0x40, 0x96, 0xA0, 0x10, 0x16,
0x84, 0x10, 0x00, 0x08, 0x40, 0x1E, 0xA0, 0x20, 0x34, 0x50, 0x00, 0x00,
0x00, 0x00, 0x04, 0x00, 0x04, 0x1C, 0x44, 0x04, 0x1B, 0x44, 0x40, 0x52,
0xA0, 0x87, 0x04, 0x07, 0x40, 0x7F, 0xA0, 0x10, 0xC0, 0x44, 0x20, 0x0F,
0x08, 0x20, 0x8F, 0x50, 0x40, 0xFF, 0xA0, 0x10, 0x80, 0x44, 0x20, 0x0F,
0x08, 0x20, 0x8E, 0x50, 0x40, 0xFE, 0xA0, 0x00, 0x09, 0x07, 0x10, 0xC0,
0x44, 0x20, 0x0F, 0x08, 0x20, 0x8F, 0x50, 0x40, 0xFE, 0xA0, 0x10, 0x80,
0x44, 0x20, 0x0F, 0x08, 0x20, 0x8E, 0x50, 0x40, 0xFF, 0xA0, 0x81, 0x0A,
0x07, 0x40, 0x79, 0xA0, 0x10, 0xFE, 0x84, 0x10, 0x00, 0x08, 0x20, 0xC1,
0x50, 0x20, 0x1C, 0x60, 0x10, 0xFF, 0x84, 0x10, 0x00, 0x08, 0x20, 0x81,
0x50, 0x20, 0x1B, 0x60, 0x08, 0x52, 0x84, 0x00, 0x1D, 0x07, 0x10, 0x8C,
0x44, 0x20, 0x0F, 0x08, 0x20, 0x8A, 0x50, 0x20, 0x8B, 0x60, 0x10, 0x42,
0x84, 0x20, 0x1E, 0x08, 0x7F, 0xFF, 0x21, 0x00, 0x20, 0x08, 0x20, 0x8C,
0x50, 0x10, 0x20, 0x08, 0x40, 0x1C, 0x90, 0x10, 0x07, 0x84, 0x20, 0x1E,
0x08, 0x40, 0x10, 0xA0, 0x10, 0x00, 0x08, 0x40, 0x06, 0x90, 0x40, 0x55,
0xA0, 0x10, 0xCC, 0x44, 0x20, 0x0F, 0x08, 0x20, 0xCA, 0x50, 0x20, 0xCB,
0x60, 0x10, 0xC2, 0x84, 0x20, 0x1E, 0x08, 0x7F, 0xFF, 0x21, 0x00, 0x20,
0x08, 0x20, 0xCC, 0x50, 0x10, 0x20, 0x08, 0x40, 0x9C, 0x90, 0x10, 0x87,
0x84, 0x20, 0x1E, 0x08, 0x40, 0x10, 0xA0, 0x10, 0x00, 0x08, 0x40, 0x86,
0x90, 0x40, 0x56, 0xA0, 0x10, 0x56, 0x84, 0x20, 0x0F, 0x08, 0x40, 0x7B,
0x90, 0x22, 0x00, 0x60, 0x40, 0x00, 0x08, 0x40, 0x79, 0xA0, 0x00, 0x08,
0x11, 0x10, 0x55, 0x84, 0x20, 0x0F, 0x08, 0x40, 0x7A, 0x90, 0x22, 0x00,
0x60, 0x50, 0x00, 0x08, 0x40, 0x79, 0xA0, 0x00, 0xFF, 0x11, 0x08, 0x52,
0x84, 0x80, 0xFF, 0x11, 0x30, 0x34, 0x07, 0x70, 0x00, 0x08, 0x88, 0xFF,
0x11, 0x40, 0x52, 0xA0, 0x04, 0x6F, 0x84, 0x00, 0x05, 0x21, 0x21, 0x75,
0x00, 0x04, 0x00, 0x11, 0x10, 0xC1, 0x84, 0x20, 0x0F, 0x08, 0x70, 0x07,
0x07, 0x10, 0x10, 0x08, 0x40, 0xC0, 0xA0, 0x20, 0x0F, 0x08, 0x7F, 0xFF,
0x11, 0x8F, 0x02, 0x07, 0x80, 0x00, 0x11, 0x08, 0x00, 0x20, 0x08, 0xC1,
0x84, 0x10, 0x00, 0x10, 0x20, 0x0E, 0x08, 0x7F, 0xFF, 0x21, 0x40, 0xBD,
0x90, 0x9E, 0x05, 0x07, 0x40, 0x7F, 0xA0, 0x40, 0xEC, 0x90, 0x04, 0x6E,
0x84, 0x00, 0x05, 0x21, 0x21, 0x8B, 0x00, 0x00, 0x04, 0x11, 0x10, 0x41,
0x84, 0x20, 0x0F, 0x08, 0x70, 0x07, 0x07, 0x10, 0x10, 0x08, 0x40, 0x40,
0xA0, 0x20, 0x0F, 0x08, 0x7F, 0xFF, 0x11, 0x8F, 0x02, 0x07, 0x80, 0x00,
0x11, 0x08, 0x00, 0x20, 0x08, 0x41, 0x84, 0x10, 0x00, 0x10, 0x20, 0x0E,
0x08, 0x7F, 0xFF, 0x21, 0x40, 0x3D, 0x90, 0x9E, 0x05, 0x07, 0x40, 0x7F,
0xA0, 0x40, 0x6D, 0x90, 0x10, 0x2D, 0x44, 0x21, 0x0C, 0x00, 0x08, 0x00,
0x11, 0x20, 0x32, 0x60, 0x80, 0x14, 0x43, 0x10, 0x2C, 0x44, 0x21, 0x11,
0x00, 0x00, 0x08, 0x11, 0x20, 0x31, 0x60, 0x00, 0x14, 0x43, 0x04, 0x34,
0x44, 0x40, 0x5B, 0xA0, 0x00, 0x04, 0x00, 0x21, 0xAC, 0x00, 0x80, 0x00,
0x11, 0x21, 0xB2, 0x00, 0x3F, 0xFF, 0x11, 0x08, 0xE8, 0x84, 0x20, 0x32,
0x50, 0x08, 0x68, 0x84, 0x20, 0x31, 0x50, 0x08, 0x5E, 0x84, 0x20, 0x30,
0x50, 0x0F, 0xC4, 0x07, 0x10, 0x34, 0x44, 0x10, 0x5B, 0x84, 0x6F, 0xF3,
0x07, 0x00, 0x00, 0x08, 0x01, 0x08, 0x21, 0x40, 0xFC, 0x90, 0x3D, 0x2B,
0x00, 0x04, 0xFC, 0x84, 0x00, 0x00, 0x21, 0x04, 0xFD, 0x84, 0x00, 0x08,
0x21, 0x00, 0x04, 0x00, 0x21, 0xC3, 0x00, 0xC0, 0x00, 0x11, 0x04, 0x5B,
0x84, 0x01, 0x08, 0x21, 0x70, 0x06, 0x07, 0x10, 0xFE, 0x84, 0x30, 0x20,
0x08, 0x00, 0x03, 0x11, 0x10, 0x00, 0x08, 0x40, 0x59, 0x90, 0x04, 0xFF,
0x84, 0x40, 0x58, 0xA0, 0x10, 0x59, 0x84, 0x20, 0x0F, 0x08, 0x40, 0x59,
0xA0, 0x20, 0x00, 0x11, 0x70, 0x1E, 0x07, 0x10, 0x00, 0x08, 0x00, 0x0B,
0x11, 0x0F, 0xE4, 0x07, 0x10, 0x59, 0x84, 0x00, 0x00, 0x08, 0x20, 0x30,
0x50, 0x40, 0x59, 0xA0, 0x70, 0x06, 0x07, 0x10, 0x00, 0x08, 0x00, 0x0A,
0x11, 0x0F, 0xEC, 0x07, 0x08, 0x34, 0x44, 0x01, 0x18, 0x11, 0x10, 0x58,
0x84, 0x20, 0x0F, 0x08, 0x40, 0x58, 0xA0, 0x20, 0x00, 0x11, 0x30, 0x08,
0x07, 0x0F, 0xF4, 0x07, 0x10, 0x58, 0x84, 0x00, 0x00, 0x08, 0x20, 0x30,
0x50, 0x40, 0x58, 0xA0, 0x70, 0x06, 0x07, 0x10, 0x00, 0x08, 0x00, 0x05,
0x11, 0x00, 0x04, 0x00, 0x10, 0x5A, 0x84, 0x00, 0x00, 0x08, 0x00, 0x01,
0x11, 0x40, 0x5A, 0xA0, 0x08, 0x34, 0x44, 0x01, 0x08, 0x11, 0x30, 0x08,
0x07, 0x60, 0x00, 0x08, 0x00, 0x00, 0x11, 0x40, 0x5A, 0xA0, 0x8F, 0x4F,
0x07, 0x40, 0x7E, 0xA0, 0x00, 0x04, 0x00, 0x00, 0x00, 0x00, 0x10, 0xB4,
0x44, 0x00, 0x00, 0x08, 0x00, 0x01, 0x11, 0x20, 0xB4, 0x60, 0x60, 0x05,
0x07, 0x10, 0x10, 0x08, 0x00, 0x20, 0x21, 0x20, 0x0F, 0x08, 0x7F, 0xFF,
0x11, 0x8F, 0x02, 0x07, 0x80, 0x00, 0x11, 0x20, 0x82, 0x60, 0x3C, 0x41,
0x00, 0x10, 0x00, 0x20, 0xA8, 0x14, 0x43, 0x04, 0xA7, 0x84, 0x20, 0x8E,
0x08, 0x40, 0xC4, 0x90, 0x40, 0xAF, 0xA0, 0x20, 0x0F, 0x08, 0x40, 0xC5,
0x90, 0x40, 0xA7, 0xA0, 0x3C, 0x4B, 0x00, 0x10, 0x00, 0x20, 0x28, 0x14,
0x43, 0x04, 0x27, 0x84, 0x20, 0x8E, 0x08, 0x40, 0x44, 0x90, 0x40, 0x2F,
0xA0, 0x20, 0x0F, 0x08, 0x40, 0x45, 0x90, 0x40, 0x27, 0xA0, 0x00, 0x04,
0x00, 0x08, 0x6F, 0x84, 0x00, 0x00, 0x11, 0x04, 0xF1, 0x84, 0x00, 0x40,
0x21, 0x22, 0x22, 0x00, 0x02, 0x00, 0x11, 0x60, 0x07, 0x07, 0x10, 0x20,
0x08, 0x40, 0xC3, 0x90, 0x20, 0x2F, 0x08, 0x80, 0x00, 0x11, 0x70, 0x02,
0x07, 0x7F, 0xFF, 0x11, 0x10, 0x00, 0x08, 0x40, 0x8D, 0x90, 0x40, 0x85,
0xA0, 0x08, 0x6E, 0x84, 0x00, 0x00, 0x11, 0x04, 0xF0, 0x84, 0x00, 0x40,
0x21, 0x22, 0x32, 0x00, 0x00, 0x02, 0x11, 0x60, 0x07, 0x07, 0x10, 0x20,
0x08, 0x40, 0x43, 0x90, 0x20, 0x2F, 0x08, 0x80, 0x00, 0x11, 0x70, 0x02,
0x07, 0x7F, 0xFF, 0x11, 0x10, 0x00, 0x08, 0x40, 0x0D, 0x90, 0x40, 0x05,
0xA0, 0x10, 0xEC, 0x84, 0x00, 0x10, 0x08, 0x10, 0xE7, 0x84, 0x40, 0xE7,
0xA0, 0x20, 0x0F, 0x08, 0x40, 0xEF, 0xA0, 0x10, 0x6D, 0x84, 0x00, 0x10,
0x08, 0x10, 0x6C, 0x84, 0x40, 0x6C, 0xA0, 0x20, 0x0F, 0x08, 0x40, 0x7D,
0xA0, 0x7F, 0xFF, 0x11, 0x00, 0x04, 0x00, 0x10, 0x51, 0x84, 0x20, 0x0F,
0x08, 0x7F, 0xC0, 0x11, 0x40, 0x51, 0xA0, 0x10, 0xEF, 0x84, 0x00, 0x10,
0x08, 0x10, 0xEE, 0x84, 0x40, 0xEE, 0xA0, 0x20, 0x0F, 0x08, 0x40, 0xBD,
0xA0, 0x10, 0x7D, 0x84, 0x00, 0x10, 0x08, 0x10, 0x7C, 0x84, 0x40, 0x7C,
0xA0, 0x20, 0x0F, 0x08, 0x40, 0x3D, 0xA0, 0x40, 0x00, 0x11, 0x3D, 0xDF,
0x00, 0xFB, 0xFF, 0x21, 0x6F, 0x14, 0x43, 0x3D, 0xE2, 0x00, 0xFF, 0xFB,
0x21, 0x6E, 0x14, 0x43, 0x3C, 0x9B, 0x00, 0x40, 0xAF, 0xA0, 0xA0, 0x14,
0x43, 0x3C, 0x9E, 0x00, 0x40, 0x2F, 0xA0, 0x20, 0x14, 0x43, 0x00, 0x04,
0x00, 0x3C, 0xA2, 0x00, 0x40, 0xA5, 0xA0, 0xB0, 0x14, 0x43, 0x3C, 0xA5,
0x00, 0x40, 0x25, 0xA0, 0x30, 0x14, 0x43, 0x00, 0x00, 0x00, 0x22, 0x3E,
0x00, 0x00, 0x02, 0x07, 0x22, 0x3A, 0x00, 0x89, 0x03, 0x07, 0x40, 0x7E,
0xA0, 0x40, 0xC1, 0x90, 0x80, 0x14, 0x43, 0x10, 0x9C, 0x84, 0x20, 0x8F,
0x08, 0x40, 0x9A, 0x90, 0x40, 0x99, 0xA0, 0x20, 0x2E, 0x08, 0x40, 0xBD,
0x90, 0x00, 0x10, 0x08, 0x40, 0x9B, 0xA0, 0x20, 0x0E, 0x08, 0x7F, 0xFF,
0x21, 0x40, 0xF5, 0x90, 0x00, 0x00, 0x00, 0x22, 0x51, 0x00, 0x00, 0x02,
0x07, 0x22, 0x4D, 0x00, 0x81, 0x03, 0x07, 0x40, 0x7E, 0xA0, 0x40, 0x41,
0x90, 0x00, 0x14, 0x43, 0x10, 0x1C, 0x84, 0x20, 0x8F, 0x08, 0x40, 0x1A,
0x90, 0x40, 0x19, 0xA0, 0x20, 0x2E, 0x08, 0x40, 0x3D, 0x90, 0x00, 0x10,
0x08, 0x40, 0x1B, 0xA0, 0x20, 0x0E, 0x08, 0x7F, 0xFF, 0x21, 0x40, 0xF5,
0x90, 0x3D, 0xE2, 0x00, 0xB8, 0x14, 0x43, 0x40, 0xC2, 0xA0, 0x3D, 0xE5,
0x00, 0x38, 0x14, 0x43, 0x40, 0x42, 0xA0, 0x00, 0x04, 0x00, 0x10, 0xC5,
0x44, 0x00, 0x10, 0x08, 0x20, 0xC5, 0x60, 0x10, 0x00, 0x08, 0x7F, 0xFF,
0x11, 0x8F, 0x02, 0x07, 0x80, 0x00, 0x11, 0x40, 0xFF, 0xA0, 0x10, 0xC9,
0x44, 0x00, 0x10, 0x08, 0x20, 0xC9, 0x60, 0x20, 0x1C, 0x08, 0x20, 0xC8,
0x60, 0x10, 0xC6, 0x44, 0x00, 0x00, 0x08, 0x20, 0xC6, 0x60, 0x00, 0x01,
0x11, 0x8F, 0x02, 0x07, 0xFF, 0xFF, 0x11, 0x50, 0x13, 0x07, 0x00, 0x00,
0x08, 0x20, 0xC5, 0x60, 0x20, 0x0C, 0x08, 0x20, 0xC4, 0x50, 0x7F, 0xFF,
0x21, 0x10, 0xC9, 0x44, 0x20, 0x0F, 0x08, 0x20, 0xC7, 0x50, 0x10, 0x00,
0x20, 0x10, 0xFF, 0x84, 0x10, 0xC4, 0x44, 0x20, 0x1D, 0x08, 0x7F, 0xFF,
0x21, 0x20, 0x8F, 0x08, 0x4F, 0x91, 0x11, 0x20, 0xC3, 0x60, 0x20, 0x0F,
0x08, 0xF0, 0x70, 0x11, 0x10, 0xC3, 0x44, 0x20, 0x8F, 0x08, 0x20, 0xBB,
0x50, 0x20, 0xC3, 0x60, 0x20, 0x1F, 0x08, 0x12, 0xA4, 0x21, 0x10, 0x00,
0x08, 0x20, 0xC9, 0x50, 0x20, 0xC2, 0x60, 0x10, 0x85, 0x44, 0x00, 0x10,
0x08, 0x20, 0x85, 0x60, 0x10, 0x00, 0x08, 0x7F, 0xFF, 0x11, 0x8F, 0x02,
0x07, 0x80, 0x00, 0x11, 0x40, 0xFF, 0xA0, 0x10, 0x89, 0x44, 0x00, 0x10,
0x08, 0x20, 0x89, 0x60, 0x20, 0x1C, 0x08, 0x20, 0x88, 0x60, 0x10, 0x86,
0x44, 0x00, 0x00, 0x08, 0x20, 0x86, 0x60, 0x00, 0x01, 0x11, 0x8F, 0x02,
0x07, 0xFF, 0xFF, 0x11, 0x50, 0x13, 0x07, 0x00, 0x10, 0x08, 0x20, 0x85,
0x60, 0x20, 0x0C, 0x08, 0x20, 0x84, 0x50, 0x7F, 0xFF, 0x21, 0x10, 0x89,
0x44, 0x20, 0x0F, 0x08, 0x20, 0x87, 0x50, 0x10, 0x00, 0x20, 0x10, 0xFF,
0x84, 0x10, 0x84, 0x44, 0x20, 0x1D, 0x08, 0x7F, 0xFF, 0x21, 0x20, 0x8F,
0x08, 0x4F, 0x91, 0x11, 0x20, 0x83, 0x60, 0x20, 0x0F, 0x08, 0xF0, 0x70,
0x11, 0x10, 0x83, 0x44, 0x20, 0x8F, 0x08, 0x20, 0xBB, 0x50, 0x20, 0x83,
0x60, 0x20, 0x1F, 0x08, 0x12, 0xA4, 0x21, 0x10, 0x00, 0x08, 0x20, 0x89,
0x50, 0x20, 0x82, 0x60, 0x3E, 0x7D, 0x00, 0xFD, 0xFF, 0x21, 0xF1, 0x14,
0x43, 0x3E, 0x80, 0x00, 0xFF, 0xFD, 0x21, 0xF0, 0x14, 0x43, 0x00, 0x04,
0x00, 0x04, 0xCA, 0x44, 0x23, 0x62, 0x00, 0x94, 0x14, 0x43, 0x20, 0xC4,
0x60, 0x00, 0x00, 0x00, 0x10, 0xC2, 0x44, 0x00, 0x00, 0x01, 0x20, 0x03,
0x07, 0x50, 0x00, 0x08, 0x7F, 0xFF, 0x11, 0x20, 0xB3, 0x60, 0x10, 0xC2,
0x44, 0x60, 0x00, 0x08, 0x00, 0x1F, 0x11, 0x00, 0x03, 0x07, 0x50, 0x00,
0x08, 0xFF, 0xE0, 0x11, 0x8F, 0x04, 0x07, 0x20, 0xC2, 0x60, 0x98, 0x09,
0x07, 0x40, 0x7E, 0xA0, 0x04, 0xC2, 0x44, 0x23, 0x77, 0x00, 0x93, 0x14,
0x43, 0x10, 0x00, 0x20, 0x20, 0x0D, 0x08, 0x7F, 0xFF, 0x11, 0x23, 0x5F,
0x00, 0x20, 0xC0, 0x60, 0x04, 0x8A, 0x44, 0x23, 0x7F, 0x00, 0x14, 0x14,
0x43, 0x20, 0x84, 0x60, 0x00, 0x00, 0x00, 0x10, 0x82, 0x44, 0x00, 0x00,
0x01, 0x20, 0x03, 0x07, 0x50, 0x00, 0x08, 0x7F, 0xFF, 0x11, 0x20, 0xB3,
0x60, 0x10, 0x82, 0x44, 0x60, 0x00, 0x08, 0x00, 0x1F, 0x11, 0x00, 0x03,
0x07, 0x50, 0x00, 0x08, 0xFF, 0xE0, 0x11, 0x8F, 0x04, 0x07, 0x20, 0x82,
0x60, 0x98, 0x09, 0x07, 0x40, 0x7E, 0xA0, 0x04, 0x82, 0x44, 0x23, 0x94,
0x00, 0x13, 0x14, 0x43, 0x10, 0x00, 0x20, 0x20, 0x0D, 0x08, 0x7F, 0xFF,
0x11, 0x23, 0x5F, 0x00, 0x20, 0x80, 0x60, 0x04, 0xB9, 0x84, 0x40, 0xB6,
0xA0, 0x04, 0x39, 0x84, 0x40, 0x36, 0xA0, 0x00, 0x04, 0x00, 0x3E, 0x8D,
0x00, 0x40, 0x87, 0xA0, 0x80, 0x14, 0x43, 0x3E, 0x90, 0x00, 0x40, 0x07,
0xA0, 0x00, 0x14, 0x43, 0x00, 0x04, 0x00, 0x00, 0x00, 0x00, 0x10, 0xB3,
0x44, 0x10, 0x00, 0x08, 0x00, 0x01, 0x11, 0x20, 0x04, 0x07, 0x50, 0x00,
0x08, 0x7F, 0xFF, 0x11, 0x20, 0xB3, 0x60, 0x00, 0x00, 0x00, 0x04, 0xF5,
0x84, 0x00, 0x00, 0x21, 0x70, 0x03, 0x07, 0x10, 0xF5, 0x84, 0x10, 0x00,
0x08, 0x40, 0xF3, 0x90, 0x40, 0xF5, 0xA0, 0x82, 0x08, 0x07, 0x40, 0x7E,
0xA0, 0x3E, 0xA6, 0x00, 0x40, 0x85, 0xA0, 0x88, 0x14, 0x43, 0x3E, 0xA9,
0x00, 0x40, 0x05, 0xA0, 0x08, 0x14, 0x43, 0x00, 0x04, 0x00, 0x04, 0xB4,
0x44, 0x00, 0x00, 0x21, 0x23, 0x63, 0x00, 0x01, 0x00, 0x11, 0x00, 0x03,
0x07, 0x23, 0x6A, 0x00, 0xFE, 0xFF, 0x11, 0x70, 0x04, 0x07, 0x00, 0x01,
0x11, 0x10, 0x00, 0x08, 0x01, 0xC2, 0x11, 0x20, 0xB4, 0x60, 0x00, 0x04,
0x00, 0x00, 0x01, 0x07, 0x00, 0x02, 0x07, 0x00, 0x04, 0x07, 0x00, 0x04,
0x07, 0x00, 0x13, 0x07, 0x00, 0x2D, 0x07, 0x00, 0x35, 0x07, 0x00, 0x75,
0x07, 0x00, 0xDB, 0x07, 0x01, 0x0F, 0x07, 0x01, 0x2E, 0x07, 0x01, 0x5D,
0x07, 0x01, 0x80, 0x07, 0x02, 0x62, 0x07, 0x02, 0x93, 0x07, 0x00, 0x10,
0x07, 0x1F, 0xFF, 0x07, 0x20, 0x03, 0x60, 0x0F, 0x45, 0x07, 0x08, 0xFA,
0x84, 0x04, 0x11, 0x44, 0xFF, 0x00, 0x11, 0x2F, 0x49, 0x07, 0x70, 0x10,
0x08, 0x00, 0xF0, 0x21, 0x50, 0x00, 0x08, 0x00, 0xF0, 0x21, 0x40, 0xF9,
0x90, 0x00, 0x08, 0x07, 0x3E, 0x5A, 0x00, 0x0F, 0x51, 0x07, 0x90, 0x01,
0x07, 0x40, 0xF9, 0xA0, 0x3F, 0x54, 0x07, 0x70, 0x00, 0x08, 0x00, 0x7F,
0x11, 0x40, 0xF8, 0xA0, 0x9D, 0x07, 0x07, 0x20, 0x12, 0x60, 0x08, 0xFA,
0x84, 0x04, 0x11, 0x44, 0x3E, 0x35, 0x00, 0x00, 0x16, 0x07, 0x48, 0x80,
0x11, 0x08, 0x09, 0x44, 0x40, 0x75, 0x90, 0x7F, 0xEF, 0x07, 0x10, 0x00,
0x20, 0x00, 0x10, 0x08, 0xFF, 0xFF, 0x21, 0x06, 0x00, 0x84, 0x40, 0xFB,
0xA0, 0x60, 0x00, 0x08, 0x00, 0x00, 0x21, 0x40, 0xFF, 0x90, 0x10, 0xFB,
0x84, 0x60, 0x20, 0x08, 0x40, 0xFB, 0x90, 0x30, 0x00, 0x08, 0x00, 0x08,
0x11, 0x3D, 0xCB, 0x00, 0x04, 0xFB, 0x84, 0x3D, 0xCD, 0x00, 0x04, 0xFF,
0x84, 0x40, 0xF8, 0xA0, 0x04, 0x11, 0x44, 0x8F, 0xFF, 0x07, 0x20, 0x19,
0x60, 0x3E, 0xB3, 0x00, 0x00, 0x31, 0x07, 0x00, 0x01, 0x00, 0x00, 0x33,
0x07, 0x00, 0x02, 0x00, 0x04, 0xC1, 0x44, 0x04, 0x81, 0x44, 0x00, 0x00,
0x21, 0x27, 0x18, 0x43, 0x70, 0x00, 0x43, 0x00, 0x00, 0x00, 0x08, 0x8F,
0x44, 0x8F, 0x02, 0x07, 0x40, 0x7A, 0xA0, 0x10, 0x8F, 0x44, 0x10, 0x8E,
0x44, 0x8F, 0x02, 0x07, 0x40, 0x7B, 0xA0, 0x08, 0x8E, 0x44, 0x80, 0x00,
0x01, 0x7F, 0xFF, 0x11, 0x04, 0x8D, 0x44, 0x08, 0x00, 0x21, 0x04, 0xB3,
0x44, 0x00, 0x80, 0x21, 0x04, 0xBB, 0x44, 0x7D, 0xB0, 0x21, 0x04, 0x10,
0x84, 0x40, 0x00, 0x21, 0x04, 0xCB, 0x44, 0x04, 0x8B, 0x44, 0x00, 0x00,
0x21, 0x04, 0x1D, 0x84, 0x01, 0xDA, 0x21, 0x04, 0xC7, 0x44, 0x04, 0x87,
0x44, 0x01, 0x00, 0x21, 0x04, 0xC8, 0x44, 0x04, 0x88, 0x44, 0x02, 0x00,
0x21, 0x04, 0xBA, 0x44, 0x04, 0xB9, 0x44, 0x04, 0xB8, 0x44, 0x04, 0xB7,
0x44, 0x04, 0xB6, 0x44, 0x04, 0xB5, 0x44, 0x04, 0xCC, 0x44, 0x04, 0xCA,
0x44, 0x04, 0xC9, 0x44, 0x04, 0xC6, 0x44, 0x04, 0xC5, 0x44, 0x04, 0xC4,
0x44, 0x04, 0xC3, 0x44, 0x04, 0xC2, 0x44, 0x04, 0x8C, 0x44, 0x04, 0x8A,
0x44, 0x04, 0x89, 0x44, 0x04, 0x86, 0x44, 0x04, 0x85, 0x44, 0x04, 0x84,
0x44, 0x04, 0x83, 0x44, 0x04, 0x82, 0x44, 0x00, 0x00, 0x21, 0x04, 0xF5,
0x84, 0x40, 0xF2, 0xA0, 0x04, 0x51, 0x84, 0x7F, 0xFF, 0x21, 0x04, 0xF5,
0x84, 0x00, 0x00, 0x21, 0x04, 0xF3, 0x84, 0x00, 0x10, 0x21, 0x04, 0xF2,
0x84, 0x06, 0x00, 0x21, 0x04, 0x72, 0x44, 0x00, 0x77, 0x21, 0x04, 0x2E,
0x44, 0x04, 0x2D, 0x44, 0x04, 0x2C, 0x44, 0x00, 0x00, 0x21, 0x08, 0x28,
0x44, 0x01, 0x11, 0x11, 0x08, 0x5D, 0x84, 0x10, 0x00, 0x10, 0x10, 0x00,
0x08, 0x40, 0x00, 0x21, 0x30, 0x04, 0x07, 0x40, 0xFF, 0x90, 0x50, 0x20,
0x08, 0xC0, 0x00, 0x11, 0x10, 0xFF, 0x84, 0x00, 0x20, 0x08, 0x00, 0x40,
0x11, 0x40, 0x00, 0x08, 0x00, 0x01, 0x11, 0x20, 0x51, 0x60, 0x10, 0x00,
0x44, 0x60, 0x00, 0x08, 0x40, 0x54, 0x90, 0x20, 0x00, 0x60, 0x00, 0x93,
0x07, 0x81, 0x62, 0x07, 0x80, 0x03, 0x07, 0x40, 0xF8, 0xA0, 0x48, 0xC0,
0x11, 0x00, 0x91, 0x07, 0x00, 0x92, 0x07, 0x00, 0x93, 0x07, 0x00, 0x04,
0x07, 0x00, 0x95, 0x07, 0x00, 0x96, 0x07, 0x00, 0x97, 0x07, 0x00, 0x6F,
0x07, 0x00, 0x99, 0x07, 0x00, 0x9A, 0x07, 0x00, 0x9B, 0x07, 0x00, 0x8E,
0x07, 0x00, 0x9D, 0x07, 0x00, 0x9C, 0x07, 0x00, 0x9F, 0x07, 0x00, 0xA0,
0x07, 0x0F, 0xEF, 0x07, 0x1F, 0xFF, 0x07, 0xFF, 0x00, 0x11, 0x10, 0x00,
0x20, 0x30, 0x10, 0x08, 0x00, 0x01, 0x21, 0x50, 0x00, 0x08, 0x00, 0x0F,
0x21, 0x40, 0xF9, 0x90, 0x30, 0xAA, 0x07, 0x70, 0x10, 0x08, 0x00, 0x80,
0x21, 0x50, 0x00, 0x08, 0x00, 0xF0, 0x21, 0x08, 0xF9, 0x84, 0x04, 0xF8,
0x84, 0x2F, 0xFF, 0x07, 0x3E, 0x54, 0x00, 0x04, 0xF1, 0x84, 0x04, 0xF0,
0x84, 0x04, 0x5A, 0x84, 0x00, 0x00, 0x21, 0x04, 0xF6, 0x84, 0x00, 0x02,
0x21, 0x04, 0xFA, 0x84, 0x40, 0x00, 0x21, 0x04, 0xF7, 0x84, 0x01, 0x04,
0x21, 0x04, 0x70, 0x44, 0x06, 0x66, 0x21, 0x04, 0x3B, 0x44, 0x04, 0x39,
0x44, 0x00, 0x80, 0x21, 0x04, 0x3C, 0x44, 0x3A, 0x00, 0x21, 0x04, 0x2F,
0x44, 0x00, 0x44, 0x21, 0x04, 0x29, 0x44, 0x00, 0x00, 0x21, 0x03, 0x19,
0x42, 0xCE, 0x19, 0x43, 0x0C, 0x59, 0x43, 0x40, 0x18, 0x42, 0x27, 0x18,
0x43, 0x15, 0x00, 0x43, 0x04, 0x22, 0x44, 0x03, 0x07, 0x21, 0x04, 0x21,
0x44, 0x11, 0x11, 0x21, 0x04, 0x20, 0x44, 0x33, 0x33, 0x21, 0x00, 0x00,
0x42, 0xC0, 0x3D, 0x42, 0x80, 0x3D, 0x43, 0x04, 0x35, 0x44, 0x00, 0x00,
0x21, 0x04, 0x05, 0x43, 0x42, 0xE4, 0x00,
};
const unsigned short int DOWNLOAD_BIN_LEN = sizeof(DOWNLOAD_BIN);
#endif /* OIS_PROG_H */
@@ -0,0 +1,226 @@
// SPDX-License-Identifier: GPL-2.0
/*
* Copyright (c) 2019 MediaTek Inc.
*/
/*
* BU6424AF voice coil motor driver
*
*
*/
#include <linux/delay.h>
#include <linux/fs.h>
#include <linux/i2c.h>
#include <linux/uaccess.h>
#include "lens_info.h"
#define AF_DRVNAME "BU6424AF_DRV"
#define AF_I2C_SLAVE_ADDR 0x18
#define AF_DEBUG
#ifdef AF_DEBUG
#define LOG_INF(format, args...) \
pr_debug(AF_DRVNAME " [%s] " format, __func__, ##args)
#else
#define LOG_INF(format, args...)
#endif
static struct i2c_client *g_pstAF_I2Cclient;
static int *g_pAF_Opened;
static spinlock_t *g_pAF_SpinLock;
static unsigned long g_u4AF_INF;
static unsigned long g_u4AF_MACRO = 1023;
static unsigned long g_u4CurrPosition;
static int s4AF_WriteReg(u16 a_u2Data)
{
int i4RetValue = 0;
char puSendCmd[2] = {(char)(((a_u2Data >> 8) & 0x03) | 0xc0),
(char)(a_u2Data & 0xff)};
g_pstAF_I2Cclient->addr = AF_I2C_SLAVE_ADDR;
g_pstAF_I2Cclient->addr = g_pstAF_I2Cclient->addr >> 1;
i4RetValue = i2c_master_send(g_pstAF_I2Cclient, puSendCmd, 2);
if (i4RetValue < 0) {
LOG_INF("I2C write failed!!\n");
return -1;
}
return 0;
}
static inline int getAFInfo(__user struct stAF_MotorInfo *pstMotorInfo)
{
struct stAF_MotorInfo stMotorInfo;
stMotorInfo.u4MacroPosition = g_u4AF_MACRO;
stMotorInfo.u4InfPosition = g_u4AF_INF;
stMotorInfo.u4CurrentPosition = g_u4CurrPosition;
stMotorInfo.bIsSupportSR = 1;
stMotorInfo.bIsMotorMoving = 1;
if (*g_pAF_Opened >= 1)
stMotorInfo.bIsMotorOpen = 1;
else
stMotorInfo.bIsMotorOpen = 0;
if (copy_to_user(pstMotorInfo, &stMotorInfo,
sizeof(struct stAF_MotorInfo)))
LOG_INF("copy to user failed when getting motor information\n");
return 0;
}
/* initAF include driver initialization and standby mode */
static int initAF(void)
{
LOG_INF("+\n");
if (*g_pAF_Opened == 1) {
spin_lock(g_pAF_SpinLock);
*g_pAF_Opened = 2;
spin_unlock(g_pAF_SpinLock);
}
LOG_INF("-\n");
return 0;
}
/* moveAF only use to control moving the motor */
static inline int moveAF(unsigned long a_u4Position)
{
int ret = 0;
if (s4AF_WriteReg((unsigned short)a_u4Position) == 0) {
g_u4CurrPosition = a_u4Position;
ret = 0;
} else {
LOG_INF("set I2C failed when moving the motor\n");
ret = -1;
}
return ret;
}
static inline int setAFInf(unsigned long a_u4Position)
{
spin_lock(g_pAF_SpinLock);
g_u4AF_INF = a_u4Position;
spin_unlock(g_pAF_SpinLock);
return 0;
}
static inline int setAFMacro(unsigned long a_u4Position)
{
spin_lock(g_pAF_SpinLock);
g_u4AF_MACRO = a_u4Position;
spin_unlock(g_pAF_SpinLock);
return 0;
}
/* ////////////////////////////////////////////////////////////// */
long BU6424AF_Ioctl(struct file *a_pstFile, unsigned int a_u4Command,
unsigned long a_u4Param)
{
long i4RetValue = 0;
switch (a_u4Command) {
case AFIOC_G_MOTORINFO:
i4RetValue =
getAFInfo((__user struct stAF_MotorInfo *)(a_u4Param));
break;
case AFIOC_T_MOVETO:
i4RetValue = moveAF(a_u4Param);
break;
case AFIOC_T_SETINFPOS:
i4RetValue = setAFInf(a_u4Param);
break;
case AFIOC_T_SETMACROPOS:
i4RetValue = setAFMacro(a_u4Param);
break;
default:
LOG_INF("No CMD\n");
i4RetValue = -EPERM;
break;
}
return i4RetValue;
}
/* Main jobs: */
/* 1.Deallocate anything that "open" allocated in private_data. */
/* 2.Shut down the device on last close. */
/* 3.Only called once on last time. */
/* Q1 : Try release multiple times. */
int BU6424AF_Release(struct inode *a_pstInode, struct file *a_pstFile)
{
LOG_INF("Start\n");
if (*g_pAF_Opened == 2) {
char puSendCmd[2];
puSendCmd[0] = (char)(0x00);
puSendCmd[1] = (char)(0x00);
i2c_master_send(g_pstAF_I2Cclient, puSendCmd, 2);
LOG_INF("Wait\n");
}
if (*g_pAF_Opened) {
LOG_INF("Free\n");
spin_lock(g_pAF_SpinLock);
*g_pAF_Opened = 0;
spin_unlock(g_pAF_SpinLock);
}
LOG_INF("End\n");
return 0;
}
int BU6424AF_SetI2Cclient(struct i2c_client *pstAF_I2Cclient,
spinlock_t *pAF_SpinLock, int *pAF_Opened)
{
g_pstAF_I2Cclient = pstAF_I2Cclient;
g_pAF_SpinLock = pAF_SpinLock;
g_pAF_Opened = pAF_Opened;
initAF();
return 1;
}
int BU6424AF_GetFileName(unsigned char *pFileName)
{
#if SUPPORT_GETTING_LENS_FOLDER_NAME
char FilePath[256];
char *FileString;
sprintf(FilePath, "%s", __FILE__);
FileString = strrchr(FilePath, '/');
*FileString = '\0';
FileString = (strrchr(FilePath, '/') + 1);
strncpy(pFileName, FileString, AF_MOTOR_NAME);
LOG_INF("FileName : %s\n", pFileName);
#else
pFileName[0] = '\0';
#endif
return 1;
}
@@ -0,0 +1,20 @@
#
# Copyright (C) 2015 MediaTek Inc.
#
# 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.
#
#
# Makefile for misc devices that really don't fit anywhere else.
#
obj-y += BU6424AF.o
@@ -0,0 +1,258 @@
// SPDX-License-Identifier: GPL-2.0
/*
* Copyright (c) 2019 MediaTek Inc.
*/
/*
* BU64253GWZAF voice coil motor driver
*
*
*/
#include <linux/delay.h>
#include <linux/fs.h>
#include <linux/i2c.h>
#include <linux/uaccess.h>
#include "lens_info.h"
#define AF_DRVNAME "BU64253GWZAF_DRV"
#define AF_I2C_SLAVE_ADDR 0x18
#define AF_DEBUG
#ifdef AF_DEBUG
#define LOG_INF(format, args...) \
pr_info(AF_DRVNAME " [%s] " format, __func__, ##args)
#else
#define LOG_INF(format, args...)
#endif
/* if use ISRC mode, should modify variables in init_setting */
#define USE_ISRC_MODE
static struct i2c_client *g_pstAF_I2Cclient;
static int *g_pAF_Opened;
static spinlock_t *g_pAF_SpinLock;
static unsigned long g_u4AF_INF;
static unsigned long g_u4AF_MACRO = 1023;
static unsigned long g_u4CurrPosition;
static int s4AF_WriteReg(u16 a_u2Data)
{
int i4RetValue = 0;
char puSendCmd[2] = {(char)(((a_u2Data >> 8) & 0x03) | 0xC4),
(char)(a_u2Data & 0xFF)};
g_pstAF_I2Cclient->addr = AF_I2C_SLAVE_ADDR;
g_pstAF_I2Cclient->addr = g_pstAF_I2Cclient->addr >> 1;
i4RetValue = i2c_master_send(g_pstAF_I2Cclient, puSendCmd, 2);
if (i4RetValue < 0) {
LOG_INF("I2C write failed!!\n");
return -1;
}
return 0;
}
static inline int getAFInfo(__user struct stAF_MotorInfo *pstMotorInfo)
{
struct stAF_MotorInfo stMotorInfo;
stMotorInfo.u4MacroPosition = g_u4AF_MACRO;
stMotorInfo.u4InfPosition = g_u4AF_INF;
stMotorInfo.u4CurrentPosition = g_u4CurrPosition;
stMotorInfo.bIsSupportSR = 1;
stMotorInfo.bIsMotorMoving = 1;
if (*g_pAF_Opened >= 1)
stMotorInfo.bIsMotorOpen = 1;
else
stMotorInfo.bIsMotorOpen = 0;
if (copy_to_user(pstMotorInfo, &stMotorInfo,
sizeof(struct stAF_MotorInfo)))
LOG_INF("copy to user failed when getting motor information\n");
return 0;
}
/* initAF include driver initialization and standby mode */
static int initAF(void)
{
LOG_INF("+\n");
if (*g_pAF_Opened == 1) {
char puSendCmd[2];
int ret = 0;
spin_lock(g_pAF_SpinLock);
*g_pAF_Opened = 2;
spin_unlock(g_pAF_SpinLock);
LOG_INF("Enable ISRC\n");
puSendCmd[0] = (char)(0xC2);
puSendCmd[1] = (char)(0x00);
ret = i2c_master_send(g_pstAF_I2Cclient, puSendCmd, 2);
if (ret < 0) {
LOG_INF("I2C write failed!!\n");
return -1;
}
puSendCmd[0] = (char)(0xC8);
puSendCmd[1] = (char)(0x01);
ret = i2c_master_send(g_pstAF_I2Cclient, puSendCmd, 2);
if (ret < 0) {
LOG_INF("I2C write failed!!\n");
return -1;
}
puSendCmd[0] = (char)(0xD0);
puSendCmd[1] = (char)(0x42);
ret = i2c_master_send(g_pstAF_I2Cclient, puSendCmd, 2);
if (ret < 0) {
LOG_INF("I2C write failed!!\n");
return -1;
}
}
LOG_INF("-\n");
return 0;
}
/* moveAF only use to control moving the motor */
static inline int moveAF(unsigned long a_u4Position)
{
int ret = 0;
if (s4AF_WriteReg((unsigned short)a_u4Position) == 0) {
g_u4CurrPosition = a_u4Position;
ret = 0;
} else {
LOG_INF("set I2C failed when moving the motor\n");
ret = -1;
}
return ret;
}
static inline int setAFInf(unsigned long a_u4Position)
{
spin_lock(g_pAF_SpinLock);
g_u4AF_INF = a_u4Position;
spin_unlock(g_pAF_SpinLock);
return 0;
}
static inline int setAFMacro(unsigned long a_u4Position)
{
spin_lock(g_pAF_SpinLock);
g_u4AF_MACRO = a_u4Position;
spin_unlock(g_pAF_SpinLock);
return 0;
}
/* ////////////////////////////////////////////////////////////// */
long BU64253GWZAF_Ioctl(struct file *a_pstFile, unsigned int a_u4Command,
unsigned long a_u4Param)
{
long i4RetValue = 0;
switch (a_u4Command) {
case AFIOC_G_MOTORINFO:
i4RetValue =
getAFInfo((__user struct stAF_MotorInfo *)(a_u4Param));
break;
case AFIOC_T_MOVETO:
i4RetValue = moveAF(a_u4Param);
break;
case AFIOC_T_SETINFPOS:
i4RetValue = setAFInf(a_u4Param);
break;
case AFIOC_T_SETMACROPOS:
i4RetValue = setAFMacro(a_u4Param);
break;
default:
LOG_INF("No CMD\n");
i4RetValue = -EPERM;
break;
}
return i4RetValue;
}
/* Main jobs: */
/* 1.Deallocate anything that "open" allocated in private_data. */
/* 2.Shut down the device on last close. */
/* 3.Only called once on last time. */
/* Q1 : Try release multiple times. */
int BU64253GWZAF_Release(struct inode *a_pstInode, struct file *a_pstFile)
{
LOG_INF("Start\n");
if (*g_pAF_Opened == 2) {
char puSendCmd[2];
puSendCmd[0] = (char)(0x00);
puSendCmd[1] = (char)(0x00);
i2c_master_send(g_pstAF_I2Cclient, puSendCmd, 2);
LOG_INF("Wait\n");
}
if (*g_pAF_Opened) {
LOG_INF("Free\n");
spin_lock(g_pAF_SpinLock);
*g_pAF_Opened = 0;
spin_unlock(g_pAF_SpinLock);
}
LOG_INF("End\n");
return 0;
}
int BU64253GWZAF_SetI2Cclient(struct i2c_client *pstAF_I2Cclient,
spinlock_t *pAF_SpinLock, int *pAF_Opened)
{
g_pstAF_I2Cclient = pstAF_I2Cclient;
g_pAF_SpinLock = pAF_SpinLock;
g_pAF_Opened = pAF_Opened;
initAF();
return 1;
}
int BU64253GWZAF_GetFileName(unsigned char *pFileName)
{
#if SUPPORT_GETTING_LENS_FOLDER_NAME
char FilePath[256];
char *FileString;
sprintf(FilePath, "%s", __FILE__);
FileString = strrchr(FilePath, '/');
*FileString = '\0';
FileString = (strrchr(FilePath, '/') + 1);
strncpy(pFileName, FileString, AF_MOTOR_NAME);
LOG_INF("FileName : %s\n", pFileName);
#else
pFileName[0] = '\0';
#endif
return 1;
}
@@ -0,0 +1,20 @@
#
# Copyright (C) 2015 MediaTek Inc.
#
# 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.
#
#
# Makefile for misc devices that really don't fit anywhere else.
#
obj-y += BU64253GWZAF.o
@@ -0,0 +1,244 @@
// SPDX-License-Identifier: GPL-2.0
/*
* Copyright (c) 2019 MediaTek Inc.
*/
/*
* BU6429AF voice coil motor driver
*
*
*/
#include <linux/delay.h>
#include <linux/fs.h>
#include <linux/i2c.h>
#include <linux/uaccess.h>
#include "lens_info.h"
#define AF_DRVNAME "BU6429AF_DRV"
#define AF_I2C_SLAVE_ADDR 0x18
#define AF_DEBUG
#ifdef AF_DEBUG
#define LOG_INF(format, args...) \
pr_debug(AF_DRVNAME " [%s] " format, __func__, ##args)
#else
#define LOG_INF(format, args...)
#endif
/* if use ISRC mode, should modify variables in init_setting */
#define USE_ISRC_MODE_IMX386_SENSOR
static struct i2c_client *g_pstAF_I2Cclient;
static int *g_pAF_Opened;
static spinlock_t *g_pAF_SpinLock;
static unsigned long g_u4AF_INF;
static unsigned long g_u4AF_MACRO = 1023;
static unsigned long g_u4CurrPosition;
static int s4AF_WriteReg(u16 a_u2Data)
{
int i4RetValue = 0;
char puSendCmd[2] = {(char)(((a_u2Data >> 8) & 0x03) | 0xC4),
(char)(a_u2Data & 0xFF)};
g_pstAF_I2Cclient->addr = AF_I2C_SLAVE_ADDR;
g_pstAF_I2Cclient->addr = g_pstAF_I2Cclient->addr >> 1;
i4RetValue = i2c_master_send(g_pstAF_I2Cclient, puSendCmd, 2);
if (i4RetValue < 0) {
LOG_INF("I2C write failed!!\n");
return -1;
}
return 0;
}
static inline int getAFInfo(__user struct stAF_MotorInfo *pstMotorInfo)
{
struct stAF_MotorInfo stMotorInfo;
stMotorInfo.u4MacroPosition = g_u4AF_MACRO;
stMotorInfo.u4InfPosition = g_u4AF_INF;
stMotorInfo.u4CurrentPosition = g_u4CurrPosition;
stMotorInfo.bIsSupportSR = 1;
stMotorInfo.bIsMotorMoving = 1;
if (*g_pAF_Opened >= 1)
stMotorInfo.bIsMotorOpen = 1;
else
stMotorInfo.bIsMotorOpen = 0;
if (copy_to_user(pstMotorInfo, &stMotorInfo,
sizeof(struct stAF_MotorInfo)))
LOG_INF("copy to user failed when getting motor information\n");
return 0;
}
/* initAF include driver initialization and standby mode */
static int initAF(void)
{
LOG_INF("+\n");
if (*g_pAF_Opened == 1) {
#ifdef USE_ISRC_MODE_IMX386_SENSOR
int ret = 0;
char puSendCmd[2];
puSendCmd[0] = (char)(0xD0);
puSendCmd[1] = (char)(0xC8);
ret = i2c_master_send(g_pstAF_I2Cclient, puSendCmd, 2);
puSendCmd[0] = (char)(0xC8);
puSendCmd[1] = (char)(0x01);
ret = i2c_master_send(g_pstAF_I2Cclient, puSendCmd, 2);
puSendCmd[0] = (char)(0xC6);
puSendCmd[1] = (char)(0x00);
ret = i2c_master_send(g_pstAF_I2Cclient, puSendCmd, 2);
#endif
spin_lock(g_pAF_SpinLock);
*g_pAF_Opened = 2;
spin_unlock(g_pAF_SpinLock);
}
LOG_INF("-\n");
return 0;
}
/* moveAF only use to control moving the motor */
static inline int moveAF(unsigned long a_u4Position)
{
int ret = 0;
if (s4AF_WriteReg((unsigned short)a_u4Position) == 0) {
g_u4CurrPosition = a_u4Position;
ret = 0;
} else {
LOG_INF("set I2C failed when moving the motor\n");
ret = -1;
}
return ret;
}
static inline int setAFInf(unsigned long a_u4Position)
{
spin_lock(g_pAF_SpinLock);
g_u4AF_INF = a_u4Position;
spin_unlock(g_pAF_SpinLock);
return 0;
}
static inline int setAFMacro(unsigned long a_u4Position)
{
spin_lock(g_pAF_SpinLock);
g_u4AF_MACRO = a_u4Position;
spin_unlock(g_pAF_SpinLock);
return 0;
}
/* ////////////////////////////////////////////////////////////// */
long BU6429AF_Ioctl(struct file *a_pstFile, unsigned int a_u4Command,
unsigned long a_u4Param)
{
long i4RetValue = 0;
switch (a_u4Command) {
case AFIOC_G_MOTORINFO:
i4RetValue =
getAFInfo((__user struct stAF_MotorInfo *)(a_u4Param));
break;
case AFIOC_T_MOVETO:
i4RetValue = moveAF(a_u4Param);
break;
case AFIOC_T_SETINFPOS:
i4RetValue = setAFInf(a_u4Param);
break;
case AFIOC_T_SETMACROPOS:
i4RetValue = setAFMacro(a_u4Param);
break;
default:
LOG_INF("No CMD\n");
i4RetValue = -EPERM;
break;
}
return i4RetValue;
}
/* Main jobs: */
/* 1.Deallocate anything that "open" allocated in private_data. */
/* 2.Shut down the device on last close. */
/* 3.Only called once on last time. */
/* Q1 : Try release multiple times. */
int BU6429AF_Release(struct inode *a_pstInode, struct file *a_pstFile)
{
LOG_INF("Start\n");
if (*g_pAF_Opened == 2) {
char puSendCmd[2];
puSendCmd[0] = (char)(0x00);
puSendCmd[1] = (char)(0x00);
i2c_master_send(g_pstAF_I2Cclient, puSendCmd, 2);
LOG_INF("Wait\n");
}
if (*g_pAF_Opened) {
LOG_INF("Free\n");
spin_lock(g_pAF_SpinLock);
*g_pAF_Opened = 0;
spin_unlock(g_pAF_SpinLock);
}
LOG_INF("End\n");
return 0;
}
int BU6429AF_SetI2Cclient(struct i2c_client *pstAF_I2Cclient,
spinlock_t *pAF_SpinLock, int *pAF_Opened)
{
g_pstAF_I2Cclient = pstAF_I2Cclient;
g_pAF_SpinLock = pAF_SpinLock;
g_pAF_Opened = pAF_Opened;
initAF();
return 1;
}
int BU6429AF_GetFileName(unsigned char *pFileName)
{
#if SUPPORT_GETTING_LENS_FOLDER_NAME
char FilePath[256];
char *FileString;
sprintf(FilePath, "%s", __FILE__);
FileString = strrchr(FilePath, '/');
*FileString = '\0';
FileString = (strrchr(FilePath, '/') + 1);
strncpy(pFileName, FileString, AF_MOTOR_NAME);
LOG_INF("FileName : %s\n", pFileName);
#else
pFileName[0] = '\0';
#endif
return 1;
}
@@ -0,0 +1,20 @@
#
# Copyright (C) 2015 MediaTek Inc.
#
# 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.
#
#
# Makefile for misc devices that really don't fit anywhere else.
#
obj-y += BU6429AF.o
@@ -0,0 +1,7 @@
#
# Makefile for misc devices that really don't fit anywhere else.
#
obj-y += bu64748_function.o bu64748af.o
@@ -0,0 +1,57 @@
/* SPDX-License-Identifier: GPL-2.0 */
/*
* Copyright (c) 2019 MediaTek Inc.
*/
#ifndef OIS_COEF_H
#define OIS_COEF_H
const unsigned char MAIN_DOWNLOAD_COEF[] = {
/* MEM_6813d_TDK_TVC689.mem */
0xef, 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, 0x70,
0x01, 0x70, 0x01, 0xea, 0xfa, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x54,
0x00, 0x00, 0x00, 0x21, 0x0a, 0x00, 0x00, 0x00, 0x10, 0x9d, 0x1a, 0x00,
0x00, 0x00, 0x00, 0x00, 0x0c, 0x00, 0x10, 0xa0, 0x05, 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, 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, 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, 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, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x40, 0x00, 0x02, 0x90, 0x3d, 0xa1, 0x36, 0x3f, 0x2c, 0x00, 0x20, 0xc1,
0x13, 0x5f, 0x09, 0x70, 0x02, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x80, 0x01, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x08, 0x00, 0x00, 0x00,
0x00, 0x00, 0x40, 0x00, 0x00, 0x80, 0x86, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x04, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x20, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x40, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0xff, 0x7f, 0x00, 0x80, 0x7b, 0x8c, 0x9a, 0x79, 0x6e,
0x79, 0xaf, 0x49, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xff, 0x7f, 0xff,
0x7f, 0x00, 0x00, 0x00, 0x80, 0x00, 0x00, 0x00, 0x40, 0x00, 0x00, 0x00,
0x00, 0x00, 0x80, 0xff, 0x7f, 0x00, 0x00, 0x00, 0x7c, 0x00, 0x00, 0xab,
0x0a, 0x00, 0x00, 0x00, 0x00, 0x00, 0xb0, 0x00, 0x68, 0xff, 0x7f, 0xff,
0x7f,
};
const int MAIN_DOWNLOAD_COEF_LEN = sizeof(MAIN_DOWNLOAD_COEF);
#endif /* OIS_COEF_H */
@@ -0,0 +1,273 @@
/* SPDX-License-Identifier: GPL-2.0 */
/*
* Copyright (c) 2019 MediaTek Inc.
*/
#ifndef OIS_PROG_H
#define OIS_PROG_H
const unsigned char MAIN_DOWNLOAD_BIN[] = {
/* BIN_2817d_TDK_TVC689.bin */
0x00, 0x48, 0x4F, 0x00, 0x03, 0xFF, 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, 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, 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,
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, 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, 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, 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, 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, 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,
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, 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, 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, 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, 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, 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,
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, 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, 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, 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, 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, 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,
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, 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, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x03, 0x00, 0x10, 0x10, 0x08, 0x40, 0xFF,
0xA0, 0x10, 0xFE, 0x84, 0x00, 0x00, 0x08, 0x00, 0x01, 0x11, 0x40, 0xFE,
0xA0, 0x00, 0x04, 0x00, 0x04, 0xD9, 0x84, 0x40, 0x2C, 0xA0, 0x3C, 0xDF,
0x00, 0x10, 0x30, 0x84, 0x60, 0x00, 0x08, 0x00, 0x01, 0x11, 0x40, 0x30,
0xA0, 0x10, 0x38, 0x84, 0x60, 0x00, 0x08, 0x00, 0x00, 0x11, 0x08, 0x00,
0x20, 0x70, 0x02, 0x07, 0x10, 0x20, 0x08, 0x40, 0xD8, 0x90, 0x10, 0x00,
0x20, 0x00, 0x20, 0x08, 0x40, 0xD7, 0x90, 0x20, 0x26, 0x08, 0x40, 0xDA,
0x90, 0x20, 0x0F, 0x08, 0x7F, 0xFF, 0x11, 0x8F, 0x02, 0x07, 0x80, 0x00,
0x11, 0x10, 0x00, 0x20, 0x04, 0x47, 0x84, 0x20, 0x18, 0x07, 0x10, 0x00,
0x08, 0x40, 0x47, 0x90, 0x08, 0x00, 0x20, 0x60, 0x02, 0x07, 0x10, 0x00,
0x08, 0x03, 0xFF, 0x11, 0x8F, 0x04, 0x07, 0x20, 0xFA, 0x60, 0x00, 0x00,
0x11, 0x81, 0x22, 0x07, 0x20, 0x48, 0x60, 0x10, 0xF5, 0x84, 0x60, 0x00,
0x08, 0x40, 0xF5, 0xA0, 0x80, 0x00, 0x11, 0x70, 0x02, 0x07, 0x00, 0x00,
0x11, 0x10, 0x10, 0x08, 0x40, 0xE0, 0xA0, 0x20, 0x0F, 0x08, 0x7F, 0xFF,
0x11, 0x8F, 0x02, 0x07, 0x80, 0x00, 0x11, 0x10, 0x00, 0x20, 0x10, 0xE1,
0x84, 0x20, 0x8F, 0x08, 0x70, 0x00, 0x11, 0x40, 0xE1, 0xA0, 0x20, 0x2F,
0x08, 0x10, 0x00, 0x11, 0x10, 0x00, 0x08, 0x40, 0x2C, 0x90, 0x40, 0x22,
0xA0, 0x10, 0xF5, 0x84, 0x50, 0x00, 0x08, 0x7F, 0xFF, 0x11, 0x40, 0xF5,
0xA0, 0x00, 0x04, 0x00, 0x10, 0x2C, 0x44, 0x20, 0x2F, 0x08, 0x80, 0x00,
0x11, 0x00, 0x10, 0x08, 0x40, 0x3A, 0xA0, 0x10, 0x2A, 0x84, 0x00, 0x10,
0x08, 0x40, 0x2A, 0xA0, 0x20, 0x1A, 0x08, 0x40, 0x29, 0xA0, 0x10, 0x00,
0x08, 0x40, 0x3B, 0x90, 0x10, 0x00, 0x20, 0x20, 0x0F, 0x08, 0x7F, 0xFF,
0x11, 0x40, 0x0F, 0xA0, 0x20, 0x0B, 0x07, 0x50, 0x00, 0x08, 0x00, 0x04,
0x11, 0x40, 0x30, 0xA0, 0x10, 0x3B, 0x84, 0x20, 0x1D, 0x08, 0x40, 0x17,
0xA0, 0x20, 0x1E, 0x08, 0x40, 0xF3, 0xA0, 0x10, 0x20, 0x08, 0x40, 0x16,
0x90, 0x10, 0xF0, 0x84, 0x20, 0x0F, 0x08, 0x80, 0x00, 0x11, 0x20, 0x31,
0x60, 0x04, 0x0F, 0x84, 0x10, 0x00, 0x20, 0x20, 0x0F, 0x08, 0x80, 0x00,
0x21, 0x60, 0x04, 0x07, 0x40, 0xFF, 0xA0, 0x10, 0x00, 0x08, 0x40, 0x0E,
0x90, 0x10, 0x00, 0x20, 0x20, 0x0F, 0x08, 0x80, 0x00, 0x11, 0x00, 0x0B,
0x07, 0x08, 0x00, 0x20, 0x60, 0x0D, 0x07, 0x10, 0x00, 0x08, 0x40, 0x0E,
0x90, 0x8F, 0x06, 0x07, 0x04, 0xFF, 0x84, 0x08, 0x00, 0x20, 0x40, 0x39,
0x90, 0x83, 0x02, 0x07, 0x40, 0x28, 0x90, 0x40, 0x30, 0xA0, 0x08, 0x26,
0x84, 0x00, 0x00, 0x11, 0x82, 0x02, 0x07, 0x10, 0x00, 0x10, 0x40, 0x30,
0xA0, 0x20, 0x2A, 0x08, 0x40, 0xC8, 0x90, 0x20, 0x0D, 0x08, 0x40, 0x25,
0x90, 0x40, 0x24, 0xA0, 0x10, 0x3E, 0x84, 0x00, 0x10, 0x08, 0x10, 0x24,
0x84, 0x8D, 0x02, 0x07, 0x40, 0x30, 0xA0, 0x00, 0x10, 0x08, 0x40, 0x23,
0xA0, 0x20, 0x2E, 0x08, 0x40, 0x3D, 0x90, 0x20, 0x0F, 0x08, 0x40, 0x07,
0x90, 0x00, 0x00, 0x21, 0x30, 0x02, 0x07, 0x40, 0x3F, 0xA0, 0x50, 0x00,
0x08, 0x00, 0x01, 0x11, 0x40, 0x30, 0xA0, 0x04, 0x3F, 0x84, 0x10, 0x00,
0x20, 0x20, 0x0F, 0x08, 0x80, 0x00, 0x21, 0x60, 0x04, 0x07, 0x40, 0xFF,
0xA0, 0x10, 0x00, 0x08, 0x40, 0x06, 0x90, 0x10, 0x00, 0x20, 0x20, 0x0F,
0x08, 0x80, 0x00, 0x11, 0x00, 0x0B, 0x07, 0x08, 0x00, 0x20, 0x60, 0x0D,
0x07, 0x10, 0x00, 0x08, 0x40, 0x06, 0x90, 0x8F, 0x06, 0x07, 0x04, 0xFF,
0x84, 0x20, 0x09, 0x60, 0x10, 0x23, 0x84, 0x10, 0x20, 0x08, 0x40, 0xD9,
0x90, 0x10, 0x27, 0x84, 0x20, 0x8F, 0x08, 0x40, 0x2E, 0x90, 0x40, 0x27,
0xA0, 0x20, 0x0F, 0x08, 0x40, 0x22, 0xA0, 0x10, 0x2E, 0x84, 0x10, 0x00,
0x08, 0x7F, 0xFF, 0x21, 0x40, 0x38, 0x90, 0x10, 0x2C, 0x84, 0x10, 0xDF,
0x84, 0x20, 0x8F, 0x08, 0x63, 0xD6, 0x11, 0x40, 0xDF, 0xA0, 0x20, 0x2F,
0x08, 0x1C, 0x28, 0x11, 0x00, 0x20, 0x08, 0x40, 0xD4, 0x90, 0x20, 0x1D,
0x08, 0x40, 0x21, 0xA0, 0x10, 0x20, 0x08, 0x40, 0x20, 0x90, 0x10, 0x5F,
0x84, 0x10, 0x00, 0x08, 0x20, 0x34, 0x50, 0x20, 0x35, 0x60, 0x00, 0x04,
0x00, 0x10, 0x28, 0x84, 0x20, 0x1A, 0x08, 0x40, 0xC9, 0xA0, 0x3C, 0x17,
0x00, 0x48, 0x14, 0x43, 0x10, 0x00, 0x20, 0x00, 0x00, 0x08, 0x40, 0x15,
0x90, 0x40, 0x05, 0xA0, 0x3C, 0x0F, 0x00, 0x10, 0x00, 0x20, 0x20, 0x0A,
0x08, 0x40, 0xCA, 0x90, 0x40, 0x0D, 0xA0, 0x10, 0x14, 0x43, 0x3C, 0x15,
0x00, 0x40, 0xD9, 0xA0, 0x08, 0x14, 0x43, 0x3C, 0x18, 0x00, 0x10, 0x00,
0x20, 0x00, 0x14, 0x43, 0x04, 0x2B, 0x84, 0x20, 0x8E, 0x08, 0x40, 0x2F,
0x90, 0x40, 0x26, 0xA0, 0x20, 0x0F, 0x08, 0x40, 0x2D, 0x90, 0x40, 0x2B,
0xA0, 0x00, 0x04, 0x00, 0x10, 0xD4, 0x84, 0x20, 0x8F, 0x08, 0x40, 0xD6,
0x90, 0x40, 0xD5, 0xA0, 0x00, 0x10, 0x08, 0x40, 0xD3, 0xA0, 0x20, 0x02,
0x08, 0x08, 0x00, 0x20, 0x10, 0xD3, 0x84, 0x20, 0x1E, 0x08, 0x40, 0xD1,
0xA0, 0x20, 0x88, 0x08, 0x7F, 0xFF, 0x21, 0x00, 0x02, 0x07, 0x80, 0x00,
0x21, 0x8F, 0x03, 0x07, 0x40, 0xD2, 0x90, 0x10, 0xD1, 0x84, 0x20, 0x2C,
0x08, 0x40, 0xD0, 0x90, 0x10, 0x00, 0x20, 0x10, 0xD5, 0x84, 0x20, 0x8F,
0x08, 0x40, 0xD5, 0x90, 0x78, 0x50, 0x21, 0x20, 0x0F, 0x08, 0x06, 0x6F,
0x11, 0x40, 0x0F, 0xA0, 0x00, 0x04, 0x00, 0x00, 0x01, 0x07, 0x00, 0x02,
0x07, 0x00, 0x03, 0x07, 0x00, 0x04, 0x07, 0x00, 0x05, 0x07, 0x00, 0x06,
0x07, 0x00, 0x07, 0x07, 0x00, 0x08, 0x07, 0x00, 0x09, 0x07, 0x00, 0x0A,
0x07, 0x00, 0x0C, 0x07, 0x00, 0x0C, 0x07, 0x00, 0x2B, 0x07, 0x00, 0x49,
0x07, 0x00, 0xCD, 0x07, 0x00, 0x10, 0x07, 0x1F, 0xFF, 0x07, 0x20, 0x03,
0x60, 0x0E, 0xEF, 0x07, 0x08, 0xFA, 0x84, 0x04, 0x11, 0x44, 0xFF, 0x00,
0x11, 0x2E, 0xF3, 0x07, 0x70, 0x10, 0x08, 0x00, 0xF0, 0x21, 0x50, 0x00,
0x08, 0x00, 0xF0, 0x21, 0x40, 0xF9, 0x90, 0x00, 0x08, 0x07, 0x3C, 0xC9,
0x00, 0x0E, 0xFB, 0x07, 0x08, 0xFA, 0x84, 0x04, 0x11, 0x44, 0x3C, 0x9C,
0x00, 0x00, 0x0E, 0x07, 0x48, 0x80, 0x11, 0x08, 0x09, 0x44, 0x40, 0xCE,
0x90, 0x7F, 0xEF, 0x07, 0x10, 0x00, 0x20, 0x00, 0x10, 0x08, 0xFF, 0xFF,
0x21, 0x06, 0x00, 0x84, 0x40, 0xFB, 0xA0, 0x60, 0x00, 0x08, 0x00, 0x00,
0x21, 0x40, 0xFF, 0x90, 0x10, 0xFB, 0x84, 0x60, 0x20, 0x08, 0x40, 0xFB,
0x90, 0x30, 0x00, 0x08, 0x00, 0x08, 0x11, 0x3C, 0x5D, 0x00, 0x04, 0xFB,
0x84, 0x3C, 0x5F, 0x00, 0x04, 0xFF, 0x84, 0x40, 0xF8, 0xA0, 0x04, 0x11,
0x44, 0x8F, 0xFF, 0x07, 0x20, 0x19, 0x60, 0x00, 0x00, 0x00, 0x00, 0x29,
0x07, 0x00, 0x01, 0x00, 0x00, 0x2B, 0x07, 0x00, 0x02, 0x00, 0x04, 0xD2,
0x84, 0x04, 0xD0, 0x84, 0x00, 0x00, 0x21, 0x20, 0x04, 0x07, 0x50, 0x00,
0x08, 0x00, 0xFC, 0x11, 0x20, 0x5F, 0x60, 0x10, 0x16, 0x84, 0x60, 0x20,
0x08, 0x40, 0x16, 0x90, 0x30, 0x00, 0x08, 0x00, 0x08, 0x11, 0x3E, 0xEF,
0x00, 0x00, 0x8E, 0x21, 0x04, 0x16, 0x84, 0x3E, 0xF2, 0x00, 0x00, 0x8F,
0x21, 0x10, 0x34, 0x44, 0x60, 0x20, 0x08, 0x40, 0xFE, 0x90, 0x30, 0x00,
0x08, 0x00, 0x08, 0x11, 0x3E, 0xF9, 0x00, 0x00, 0x8C, 0x21, 0x04, 0xFE,
0x84, 0x3E, 0xFC, 0x00, 0x00, 0x8D, 0x21, 0x08, 0xF3, 0x84, 0x10, 0x00,
0x10, 0x10, 0x00, 0x08, 0x40, 0x00, 0x21, 0x30, 0x04, 0x07, 0x40, 0xFF,
0x90, 0x50, 0x20, 0x08, 0xC0, 0x00, 0x11, 0x10, 0xFF, 0x84, 0x40, 0x00,
0x08, 0x00, 0x01, 0x11, 0x20, 0x51, 0x60, 0x10, 0x25, 0x84, 0x60, 0x20,
0x08, 0x40, 0x25, 0x90, 0x30, 0x00, 0x08, 0x00, 0x08, 0x11, 0x3F, 0x0F,
0x00, 0x00, 0x88, 0x21, 0x04, 0x25, 0x84, 0x3F, 0x12, 0x00, 0x00, 0x89,
0x21, 0x10, 0x21, 0x84, 0x60, 0x20, 0x08, 0x40, 0x21, 0x90, 0x30, 0x00,
0x08, 0x00, 0x08, 0x11, 0x3F, 0x19, 0x00, 0x00, 0x86, 0x21, 0x04, 0x21,
0x84, 0x3F, 0x1C, 0x00, 0x00, 0x87, 0x21, 0x10, 0x20, 0x84, 0x60, 0x20,
0x08, 0x40, 0x20, 0x90, 0x30, 0x00, 0x08, 0x00, 0x08, 0x11, 0x3F, 0x23,
0x00, 0x00, 0x84, 0x21, 0x04, 0x20, 0x84, 0x3F, 0x26, 0x00, 0x00, 0x85,
0x21, 0x04, 0x39, 0x44, 0x3F, 0x29, 0x00, 0x00, 0x83, 0x21, 0x10, 0x31,
0x44, 0x30, 0x00, 0x08, 0x00, 0x02, 0x11, 0x3F, 0x2E, 0x00, 0x00, 0x82,
0x21, 0x08, 0x3F, 0x44, 0x04, 0x3C, 0x44, 0x83, 0x02, 0x11, 0x00, 0x00,
0x21, 0x00, 0x03, 0x07, 0x83, 0x01, 0x11, 0x00, 0x00, 0x21, 0x00, 0x06,
0x07, 0x83, 0x00, 0x11, 0x00, 0x02, 0x21, 0x00, 0x09, 0x07, 0x83, 0x00,
0x11, 0x00, 0x01, 0x21, 0x00, 0x0C, 0x07, 0x83, 0x03, 0x11, 0x00, 0x00,
0x21, 0x00, 0x0F, 0x07, 0x83, 0x02, 0x11, 0x00, 0x02, 0x21, 0x00, 0x12,
0x07, 0x83, 0x01, 0x11, 0x00, 0x02, 0x21, 0x00, 0x15, 0x07, 0x83, 0x02,
0x11, 0x00, 0x01, 0x21, 0x00, 0x18, 0x07, 0x83, 0x01, 0x11, 0x00, 0x01,
0x21, 0x00, 0x1B, 0x07, 0x83, 0x00, 0x11, 0x00, 0x03, 0x21, 0x00, 0x1E,
0x07, 0x83, 0x03, 0x11, 0x00, 0x02, 0x21, 0x00, 0x21, 0x07, 0x83, 0x03,
0x11, 0x00, 0x01, 0x21, 0x00, 0x24, 0x07, 0x83, 0x82, 0x11, 0x00, 0x00,
0x21, 0x00, 0x27, 0x07, 0x83, 0x02, 0x11, 0x00, 0x03, 0x21, 0x00, 0x2A,
0x07, 0x83, 0x01, 0x11, 0x00, 0x03, 0x21, 0x00, 0x2D, 0x07, 0x00, 0x00,
0x11, 0x00, 0x00, 0x21, 0x20, 0x2E, 0x07, 0x21, 0xBF, 0x00, 0x20, 0x2D,
0x07, 0x21, 0xC1, 0x00, 0x20, 0x2C, 0x07, 0x21, 0xC3, 0x00, 0x20, 0x2B,
0x07, 0x21, 0xC5, 0x00, 0x20, 0x2A, 0x07, 0x21, 0xC7, 0x00, 0x20, 0x29,
0x07, 0x21, 0xC9, 0x00, 0x20, 0x28, 0x07, 0x21, 0xCB, 0x00, 0x20, 0x27,
0x07, 0x21, 0xCD, 0x00, 0x20, 0x26, 0x07, 0x21, 0xCF, 0x00, 0x20, 0x25,
0x07, 0x21, 0xD1, 0x00, 0x20, 0x24, 0x07, 0x21, 0xD3, 0x00, 0x20, 0x23,
0x07, 0x21, 0xD5, 0x00, 0x20, 0x22, 0x07, 0x21, 0xD7, 0x00, 0x20, 0x21,
0x07, 0x21, 0xD9, 0x00, 0x20, 0x20, 0x07, 0x21, 0xDB, 0x00, 0x08, 0xFE,
0x84, 0x04, 0xFF, 0x84, 0x00, 0x0F, 0x11, 0x3F, 0x82, 0x00, 0x00, 0x81,
0x21, 0x20, 0xA2, 0x07, 0x70, 0x00, 0x08, 0x20, 0xA4, 0x07, 0x50, 0x00,
0x08, 0x00, 0xFF, 0x11, 0x3F, 0x89, 0x00, 0x00, 0x80, 0x21, 0x04, 0xA0,
0x44, 0x01, 0x00, 0x21, 0x08, 0xF3, 0x84, 0x10, 0x00, 0x10, 0x10, 0x00,
0x08, 0x40, 0x00, 0x21, 0x30, 0x04, 0x07, 0x40, 0xFF, 0x90, 0x50, 0x20,
0x08, 0xC0, 0x00, 0x11, 0x10, 0xFF, 0x84, 0x00, 0x20, 0x08, 0x00, 0x40,
0x11, 0x40, 0x00, 0x08, 0x00, 0x01, 0x11, 0x20, 0x51, 0x60, 0x10, 0x00,
0x44, 0x60, 0x00, 0x08, 0x40, 0xF4, 0x90, 0x20, 0x00, 0x60, 0x00, 0xE9,
0x07, 0x81, 0xC0, 0x07, 0x80, 0x03, 0x07, 0x40, 0xF8, 0xA0, 0x48, 0xC0,
0x11, 0x00, 0xE7, 0x07, 0x00, 0xE8, 0x07, 0x00, 0xE9, 0x07, 0x00, 0x04,
0x07, 0x00, 0xEB, 0x07, 0x00, 0xEC, 0x07, 0x00, 0xED, 0x07, 0x00, 0xCD,
0x07, 0x00, 0xEF, 0x07, 0x00, 0xF0, 0x07, 0x00, 0xF1, 0x07, 0x00, 0xEC,
0x07, 0x00, 0xF3, 0x07, 0x00, 0xF2, 0x07, 0x00, 0xF5, 0x07, 0x00, 0xF6,
0x07, 0x0F, 0xEF, 0x07, 0x1F, 0xFF, 0x07, 0xFF, 0x00, 0x11, 0x10, 0x00,
0x20, 0x30, 0x10, 0x08, 0x00, 0x01, 0x21, 0x50, 0x00, 0x08, 0x00, 0x0F,
0x21, 0x40, 0xF9, 0x90, 0x31, 0x00, 0x07, 0x70, 0x10, 0x08, 0x00, 0x80,
0x21, 0x50, 0x00, 0x08, 0x00, 0xF0, 0x21, 0x08, 0xF9, 0x84, 0x04, 0xF8,
0x84, 0x2F, 0xFF, 0x07, 0x3D, 0x44, 0x00, 0x04, 0xF6, 0x84, 0x0B, 0x01,
0x21, 0x04, 0xFA, 0x84, 0x40, 0x00, 0x21, 0x04, 0xF7, 0x84, 0x01, 0x04,
0x21, 0x04, 0x72, 0x44, 0x11, 0x11, 0x21, 0x04, 0x73, 0x44, 0x01, 0x00,
0x21, 0x04, 0x41, 0x44, 0x00, 0x33, 0x21, 0x04, 0x30, 0x44, 0x02, 0x80,
0x21, 0x00, 0x3E, 0x43, 0x80, 0x3D, 0x43, 0x04, 0x35, 0x44, 0x00, 0x00,
0x21, 0x04, 0x05, 0x43, 0x45, 0x26, 0x00,
};
const int MAIN_DOWNLOAD_BIN_LEN = sizeof(MAIN_DOWNLOAD_BIN);
#endif /* OIS_PROG_H */
@@ -0,0 +1,263 @@
// SPDX-License-Identifier: GPL-2.0
/*
* Copyright (c) 2019 MediaTek Inc.
*/
#include "bu64748_function.h"
#include "OIS_coef.h"
#include "OIS_prog.h"
#include <linux/delay.h>
#include <linux/fs.h>
static void I2C_func_PER_WRITE(unsigned char u08_adr,
unsigned short u16_dat)
{
unsigned char out[4] = {0};
out[0] = _OP_Periphe_RW;
out[1] = u08_adr;
out[2] = u16_dat & 0xFF;
out[3] = (u16_dat >> 8) & 0xFF;
main_SOutEx(_SLV_FBAF_, out, 4);
}
static unsigned short I2C_func_PER_READ(unsigned char u08_adr)
{
unsigned char in[2] = {0};
unsigned char read[2] = {0};
unsigned short u16_dat;
in[0] = _OP_Periphe_RW;
in[1] = u08_adr;
main_SInEx(_SLV_FBAF_, in, 2, read, 2);
u16_dat = (read[0] * 256) + read[1];
return u16_dat;
}
static void I2C_func_MEM_WRITE(unsigned char u08_adr,
unsigned short u16_dat)
{
unsigned char out[4];
out[0] = _OP_Memory__RW;
out[1] = u08_adr;
out[2] = u16_dat & 0xFF;
out[3] = (u16_dat >> 8 & 0xFF);
main_SOutEx(_SLV_FBAF_, out, 4);
}
static unsigned short I2C_func_MEM_READ(unsigned char u08_adr)
{
unsigned char in[2] = {0};
unsigned char read[2] = {0};
unsigned short u16_dat;
in[0] = _OP_Memory__RW;
in[1] = u08_adr;
main_SInEx(_SLV_FBAF_, in, 2, read, 2);
u16_dat = (read[0] * 256) + read[1];
return u16_dat;
}
static void I2C_func_PON______(void)
{
I2C_func_PER_WRITE(0xEF, 0x0080);
}
static void I2C_func_POFF_____(void)
{
I2C_func_PER_WRITE(0xEF, 0x0000);
}
static void func_CHK_VERSION(void)
{
unsigned short u16_dat = 0;
u16_dat = I2C_func_PER_READ(0x5F);
pr_debug("[bu64748af]IC Version : 0x%x.\n", u16_dat);
}
static void Set_Close_Mode(void)
{
I2C_func_MEM_WRITE(_M_30_EQCTL, 0x000D);
}
static void download(int type)
{
/* Data Transfer Size per one I2C access */
#define DWNLD_TRNS_SIZE (32)
unsigned char temp[DWNLD_TRNS_SIZE + 1];
int block_cnt;
int total_cnt;
int lp;
int n;
int u16_i;
if (type == 0)
n = MAIN_DOWNLOAD_BIN_LEN;
else
n = MAIN_DOWNLOAD_COEF_LEN; /* RHM_HT 2013/07/10 Modified */
block_cnt = n / DWNLD_TRNS_SIZE + 1;
total_cnt = block_cnt;
while (1) {
/* Residual Number Check */
if (block_cnt == 1)
lp = n % DWNLD_TRNS_SIZE;
else
lp = DWNLD_TRNS_SIZE;
/* Transfer Data set */
if (lp != 0) {
if (type == 0) {
temp[0] = _OP_FIRM_DWNLD;
for (u16_i = 1; u16_i <= lp; u16_i += 1)
temp[u16_i] = MAIN_DOWNLOAD_BIN
[(total_cnt - block_cnt) *
DWNLD_TRNS_SIZE +
u16_i - 1];
} else {
temp[0] = _OP_COEF_DWNLD;
for (u16_i = 1; u16_i <= lp; u16_i += 1)
temp[u16_i] = MAIN_DOWNLOAD_COEF
[(total_cnt - block_cnt) *
DWNLD_TRNS_SIZE +
u16_i - 1];
}
/* Data Transfer */
/* WR_I2C(_SLV_OIS_, lp + 1, temp); */
main_SOutEx(_SLV_FBAF_, temp, lp + 1);
}
/* Block Counter Decrement */
block_cnt = block_cnt - 1;
if (block_cnt == 0)
break;
}
}
static int func_PROGRAM_DOWNLOAD(void)
{
int sts = ADJ_OK;
int ver_check = 0;
unsigned short u16_dat;
download(0);
ver_check = I2C_func_MEM_READ(_M_F7_FBAF_STS);
pr_debug("[bu64748af]ver_check : 0x%x\n", ver_check);
if ((ver_check & 0x0004) == 0x0004) {
u16_dat = I2C_func_MEM_READ(_M_FIRMVER);
pr_debug("[bu64748af]FW Ver : %d\n", u16_dat);
pr_debug("[bu64748af]FW Download OK.\n");
} else {
pr_debug("[bu64748af]FW Download NG.\n");
return PROG_DL_ERR;
}
return sts;
}
static int func_COEF_DOWNLOAD(void)
{
int sts = ADJ_OK;
unsigned short u16_dat;
download(1);
u16_dat = I2C_func_MEM_READ(_M_CD_CEFTYP);
pr_debug("[bu64748af]COEF Ver : %d\n", u16_dat);
pr_debug("[bu64748af]COEF Download OK.\n");
return sts;
}
static void I2C_func_DSP_START(void)
{
unsigned char out[2] = {0};
out[0] = _OP_SpecialCMD;
out[1] = _cmd_8C_EI;
main_SOutEx(_SLV_FBAF_, out, 2);
}
void main_AF_TARGET(unsigned short target)
{
unsigned char out[3] = {0};
out[0] = 0xF2;
out[1] = (target >> 8) & 0xFF;
out[2] = target & 0xFF;
main_SOutEx(_SLV_FBAF_, out, 3);
}
int BU64748_main_Initial(void)
{
int str = ADJ_OK;
I2C_func_POFF_____();
I2C_func_PON______();
func_CHK_VERSION();
str = func_PROGRAM_DOWNLOAD();
if (str != ADJ_OK)
return str;
str = func_COEF_DOWNLOAD();
if (str != ADJ_OK)
return str;
I2C_func_DSP_START();
main_AF_TARGET(0x200);
Set_Close_Mode();
return str;
}
unsigned short bu64748_main_af_cur_pos(void)
{
unsigned char in[2] = {0};
unsigned char read[2] = {0};
unsigned short u16_dat;
in[0] = 0x84;
in[1] = 0x23;
main_SInEx(_SLV_FBAF_, in, 2, read, 2);
u16_dat = (read[0] * 256) + read[1];
return u16_dat;
}
void BU64748_main_soft_power_ctrl(int On)
{
if (On) {
I2C_func_MEM_WRITE(0x59, 0x000C);
I2C_func_MEM_WRITE(0x3D, 0x0080);
I2C_func_MEM_WRITE(0x72, 0x1111);
I2C_func_MEM_WRITE(0x30, 0x000D);
} else {
I2C_func_MEM_WRITE(0x30, 0x0000);
I2C_func_MEM_WRITE(0x59, 0x0000);
I2C_func_MEM_WRITE(0x3D, 0x0000);
I2C_func_MEM_WRITE(0x72, 0x0000);
}
}
@@ -0,0 +1,202 @@
/* SPDX-License-Identifier: GPL-2.0 */
/*
* Copyright (c) 2019 MediaTek Inc.
*/
#ifndef __BU64748_FUNCTION_H
#define __BU64748_FUNCTION_H
#define _SLV_FBAF_ 0x76
#define ADJ_OK 0
#define ADJ_ERR -1
#define PROG_DL_ERR -2
#define COEF_DL_ERR -3
#define _OP_FIRM_DWNLD 0x80
#define _OP_Periphe_RW 0x82
#define _OP_Memory__RW 0x84
#define _OP_COEF_DWNLD 0x88
#define _OP_SpecialCMD 0x8C
#define _cmd_8C_EI 0x0001
#define _cmd_8C_DI 0x0002
#define _cmd_8C_STRB 0x0004
#define _cmd_8C_TRI_SHT 0x0008
#define _cmd_8C_TRI_con 0x0010
#define _P_31_CURRENT_ADC__ 0x31
#define _P_37_OTHER___ADC__ 0x37
#define _P_2C_BTL_DAC__DATA 0x2C
#define _P_30_HALL_CurntDAC 0x30
#define _P_31_HALL___PREDAC 0x31
#define _P_34_CURAMP_OFSDAC 0x34
#define _P_39_HALL__POSTDAC 0x39
#define _P_3C_HALL__GAIN__1 0x3C
#define _P_3F_HALL__GAIN__2 0x3F
#define _P_41_ADC_Averaging 0x41
#define _P_51_AF_SLP_Trimng 0x51
#define _P_5A_ADC_MPX_FIX__ 0x5A
#define _P_72_BTL_____RANGE 0x72
#define _P_73_BTL____Enable 0x73
#define _P_75_BTL_ExtendBit 0x75
#define _M_FIRMVER 0xF6
#define _M_00_Kg00 0x00
#define _M_01_Kg01 0x01
#define _M_02_Kg02 0x02
#define _M_03_Kg03 0x03
#define _M_04_wD04 0x04
#define _M_05_wDEQH 0x05
#define _M_06_TRILMT 0x06
#define _M_07_KgWv 0x07
#define _M_08_Kg08 0x08
#define _M_09_Kg09 0x09
#define _M_0A_Kg0A 0x0A
#define _M_0B_Kg0B 0x0B
#define _M_0C_wD0C 0x0C
#define _M_0D_wDEQ1 0x0D
#define _M_0E_C_LMT 0x0E
#define _M_0F_C_LMO 0x0F
#define _M_10_Kg10 0x10
#define _M_11_Kg11 0x11
#define _M_12_Kg12 0x12
#define _M_13_Kg13 0x13
#define _M_14_wD14 0x14
#define _M_15_wDEQL 0x15
#define _M_16_CUROFS 0x16
#define _M_17_Kf0A 0x17
#define _M_18_Kg18 0x18
#define _M_19_Kg19 0x19
#define _M_1A_Kg1A 0x1A
#define _M_1B_Kg1B 0x1B
#define _M_1C_Kg1C 0x1C
#define _M_1D_wD1D 0x1D
#define _M_1E_wD1E 0x1E
#define _M_1F_BPFOUT 0x1F
#define _M_20_HOFS 0x20
#define _M_21_KgHG 0x21
#define _M_22_wTRGT 0x22
#define _M_23_wGIN 0x23
#define _M_24_wGOUT 0x24
#define _M_25_KgLPG 0x25
#define _M_26_wEQIN 0x26
#define _M_27_wGAS 0x27
#define _M_28_wDgEQA 0x28
#define _M_29_Kf0C 0x29
#define _M_2A_wDf0X 0x2A
#define _M_2B_wDg09 0x2B
#define _M_2C_NRMHAL 0x2C
#define _M_2D_Kg2D 0x2D
#define _M_2E__tmp0 0x2E
#define _M_2F_Kg2F 0x2F
#define _M_30_EQCTL 0x30
#define _EQ_ALL_OFF 0x0000
#define _EQ_ALL__ON 0x0004
#define _EQ_CUR_FBK 0x0004
#define _EQ_POS_SRV_SR_fil__O 0x000C
#define _EQ_POS_SRV_SR_fil_of 0x000D
/*-- _EQ_C_FB_CL = 0x0004 */
/*-- _EQ_C_FB_OP = 0x0005 */
/*-- _EQ_C_FBOFF = 0x0014 */
#define _M_31_PRFCNT 0x31
#define _M_32_PRFNUM 0x32
#define _M_33_SO_ADR 0x33
#define _M_34_PRESFT 0x34
#define _M_35_PSTSFT 0x35
#define _M_36_fs_mod 0x36
#define _M_37_CURSFT 0x37
#define _M_38_PRFCEF 0x38
#define _M_39_CURSET 0x39
#define _M_3A_AXSOFS 0x3A
#define _M_3B_CURDET 0x3B
#define _M_3C_STRCNT 0x3C
#define _M_3D_Kwvat 0x3D
#define _M_3E_CNVTRG 0x3E
#define _M_3F_TRIDAT 0x3F
#define _M_40_COEF__00 0x40
#define _M_41_COEF__01 0x41
#define _M_42_COEF__02 0x42
#define _M_43_COEF__03 0x43
#define _M_44_COEF__04 0x44
#define _M_45_COEF__05 0x45
#define _M_46_COEF__06 0x46
#define _M_47_SETTRGT 0x47
#define _M_48_Kg48 0x48
#define _M_49_Kg49 0x49
#define _M_4A_Kg4A 0x4A
#define _M_4B_Kg4B 0x4B
#define _M_4C_Kg4C 0x4C
#define _M_4D_wD4D 0x4D
#define _M_4E_wD4E 0x4E
#define _M_4F_2ndOUT 0x4F
#define _M_50_POS_SFT_1 0x50
#define _M_51_POS_SFT_2 0x51
#define _M_52_POS_SFT_3 0x52
#define _M_53_POS_SFT_4 0x53
#define _M_54_POS_SFT_5 0x54
#define _M_55_POS_SFT_6 0x55
#define _M_56_POS_SFT_7 0x56
#define _M_57_POS_SFT_C 0x57
#define _M_58_POS_SFT11 0x58
#define _M_59_POS_SFT12 0x59
#define _M_5A_POS_SFT13 0x5A
#define _M_5B_POS_SFT14 0x5B
#define _M_5C_POS_SFT15 0x5C
#define _M_5D_POS_SFT16 0x5D
#define _M_5E_POS_SFT17 0x5E
#define _M_5F_HALIN 0x5F
#define _M_CD_CEFTYP 0xCD
#define _M_CF_tmpTRGT 0xCF
#define _M_D0_Hall_0 0xD0
#define _M_D1_Hall_1 0xD1
#define _M_D2_Hall_2 0xD2
#define _M_D3_Hall_3 0xD3
#define _M_D4_Hall_4 0xD4
#define _M_D5_Hall_5 0xD5
#define _M_D6_Hall_6 0xD6
#define _M_D7_Hall_7 0xD7
#define _M_D8_Hall_8 0xD8
#define _M_D9_Hall_9 0xD9
#define _M_DA_Hall_A 0xDA
#define _M_DB_Hall_B 0xDB
#define _M_DC_Hall_C 0xDC
#define _M_DD_Hall_D 0xDD
#define _M_DE_Hall_E 0xDE
#define _M_DF_Hall_F 0xDF
#define _M_E0_Hall10 0xE0
#define _M_E1_Hall11 0xE1
#define _M_E2_Hall12 0xE2
#define _M_E3_Hall13 0xE3
#define _M_E4_Hall14 0xE4
#define _M_E5_Hall15 0xE5
#define _M_E6_Hall16 0xE6
#define _M_E7_Hall17 0xE7
#define _M_E8_Hall18 0xE8
#define _M_E9_Hall19 0xE9
#define _M_EA_Hall1A 0xEA
#define _M_EB_Hall1B 0xEB
#define _M_EC_Hall1C 0xEC
#define _M_ED_Hall1D 0xED
#define _M_EE_Hall1E 0xEE
#define _M_EF_Hall1F 0xEF
#define _M_F0_CUR_IN 0xF0
#define _M_F6_FIRMVER 0xF6
#define _M_F7_FBAF_STS 0xF7
extern int main_SOutEx(unsigned char slaveAddress,
unsigned char *dat, int size);
extern int main_SInEx(unsigned char slaveAddress,
unsigned char *dat, int size,
unsigned char *ret, int ret_size);
void main_AF_TARGET(unsigned short target);
int BU64748_main_Initial(void);
unsigned short bu64748_main_af_cur_pos(void);
void BU64748_main_soft_power_ctrl(int On);
#endif
@@ -0,0 +1,282 @@
// SPDX-License-Identifier: GPL-2.0
/*
* Copyright (c) 2019 MediaTek Inc.
*/
/*
* bu64748af voice coil motor driver
*
*
*/
#include <linux/delay.h>
#include <linux/fs.h>
#include <linux/i2c.h>
#include <linux/uaccess.h>
#include "bu64748_function.h"
#include "lens_info.h"
#define AF_DRVNAME "bu64748af_main_drv"
#define AF_DEBUG
#ifdef AF_DEBUG
#define LOG_INF(format, args...) \
pr_info(AF_DRVNAME " [%s] " format, __func__, ##args)
#else
#define LOG_INF(format, args...)
#endif
static struct i2c_client *g_pstAF_I2Cclient;
static int *g_pAF_Opened;
static spinlock_t *g_pAF_SpinLock;
static unsigned long g_u4AF_INF;
static unsigned long g_u4AF_MACRO = 1023;
static unsigned long g_u4CurrPosition;
int main_SOutEx(unsigned char slaveAddress,
unsigned char *dat, int size)
{
int i4RetValue = 0;
g_pstAF_I2Cclient->addr = slaveAddress;
i4RetValue = i2c_master_send(g_pstAF_I2Cclient, dat, size);
if (i4RetValue < 0) {
LOG_INF("I2C write failed!!\n");
return -1;
}
return 0;
}
int main_SInEx(unsigned char slaveAddress, unsigned char *dat,
int size, unsigned char *ret, int ret_size)
{
int ret_value = 0;
struct i2c_msg msg[2];
struct i2c_adapter *adap = g_pstAF_I2Cclient->adapter;
memset(msg, 0, sizeof(msg));
g_pstAF_I2Cclient->addr = slaveAddress;
msg[0].addr = slaveAddress;
msg[0].flags = 0;
msg[0].len = size;
msg[0].buf = dat;
msg[1].addr = slaveAddress;
msg[1].flags = I2C_M_RD;
msg[1].len = ret_size;
msg[1].buf = ret;
ret_value = i2c_transfer(adap, msg, 2);
if (ret_value < 0) {
LOG_INF("I2C read - recv failed!!\n");
return -1;
}
return 0;
}
static inline int getAFInfo(__user struct stAF_MotorInfo *pstMotorInfo)
{
struct stAF_MotorInfo stMotorInfo;
stMotorInfo.u4MacroPosition = g_u4AF_MACRO;
stMotorInfo.u4InfPosition = g_u4AF_INF;
stMotorInfo.u4CurrentPosition = g_u4CurrPosition;
stMotorInfo.bIsSupportSR = 1;
stMotorInfo.bIsMotorMoving = 1;
if (*g_pAF_Opened >= 1)
stMotorInfo.bIsMotorOpen = 1;
else
stMotorInfo.bIsMotorOpen = 0;
if (copy_to_user(pstMotorInfo, &stMotorInfo,
sizeof(struct stAF_MotorInfo)))
LOG_INF("copy to user failed when getting motor information\n");
return 0;
}
/* initAF include driver initialization and standby mode */
static int initAF(void)
{
LOG_INF("+\n");
if (*g_pAF_Opened == 1) {
int ret = 0;
BU64748_main_soft_power_ctrl(1);
ret = BU64748_main_Initial();
if (ret) {
LOG_INF("bu64748af_main init failed.line:%d.\n",
__LINE__);
return -EINVAL;
}
spin_lock(g_pAF_SpinLock);
*g_pAF_Opened = 2;
spin_unlock(g_pAF_SpinLock);
}
LOG_INF("-\n");
return 0;
}
static inline int moveAF(unsigned long a_u4Position)
{
int ret = 0;
main_AF_TARGET(a_u4Position);
g_u4CurrPosition = a_u4Position;
return ret;
}
static inline int setAFInf(unsigned long a_u4Position)
{
spin_lock(g_pAF_SpinLock);
g_u4AF_INF = a_u4Position;
spin_unlock(g_pAF_SpinLock);
return 0;
}
static inline int setAFMacro(unsigned long a_u4Position)
{
spin_lock(g_pAF_SpinLock);
g_u4AF_MACRO = a_u4Position;
spin_unlock(g_pAF_SpinLock);
return 0;
}
long bu64748af_Ioctl_Main(struct file *a_pstFile, unsigned int a_u4Command,
unsigned long a_u4Param)
{
long i4RetValue = 0;
switch (a_u4Command) {
case AFIOC_G_MOTORINFO:
i4RetValue =
getAFInfo((__user struct stAF_MotorInfo *)(a_u4Param));
break;
case AFIOC_T_MOVETO:
i4RetValue = moveAF(a_u4Param);
break;
case AFIOC_T_SETINFPOS:
i4RetValue = setAFInf(a_u4Param);
break;
case AFIOC_T_SETMACROPOS:
i4RetValue = setAFMacro(a_u4Param);
break;
default:
LOG_INF("No CMD\n");
i4RetValue = -EPERM;
break;
}
return i4RetValue;
}
int bu64748af_Release_Main(struct inode *a_pstInode, struct file *a_pstFile)
{
LOG_INF("Start\n");
if (*g_pAF_Opened == 2) {
LOG_INF("Wait\n");
BU64748_main_soft_power_ctrl(0);
}
if (*g_pAF_Opened) {
LOG_INF("Free\n");
spin_lock(g_pAF_SpinLock);
*g_pAF_Opened = 0;
spin_unlock(g_pAF_SpinLock);
}
LOG_INF("End\n");
return 0;
}
static int PowerDown = 1;
int bu64748af_PowerDown_Main(struct i2c_client *pstAF_I2Cclient,
int *pAF_Opened)
{
g_pstAF_I2Cclient = pstAF_I2Cclient;
g_pAF_Opened = pAF_Opened;
LOG_INF("+\n");
if (PowerDown == 0)
return -1;
if (*g_pAF_Opened == 0) {
BU64748_main_soft_power_ctrl(0);
LOG_INF("apply\n");
}
LOG_INF("-\n");
return 0;
}
int bu64748af_SetI2Cclient_Main(struct i2c_client *pstAF_I2Cclient,
spinlock_t *pAF_SpinLock, int *pAF_Opened)
{
unsigned char out[4] = {0};
int ret;
g_pstAF_I2Cclient = pstAF_I2Cclient;
g_pAF_SpinLock = pAF_SpinLock;
g_pAF_Opened = pAF_Opened;
out[0] = _OP_Periphe_RW;
out[1] = 0xEF;
out[2] = 0;
out[3] = 0;
ret = main_SOutEx(_SLV_FBAF_, out, 4);
if (ret < 0 && *g_pAF_Opened == 0)
PowerDown = 0;
LOG_INF("SetI2Cclient value(0x%x)\n", ret);
initAF();
return (ret == 0);
}
int bu64748af_GetFileName_Main(unsigned char *pFileName)
{
#if SUPPORT_GETTING_LENS_FOLDER_NAME
char FilePath[256];
char *FileString;
sprintf(FilePath, "%s", __FILE__);
FileString = strrchr(FilePath, '/');
*FileString = '\0';
FileString = (strrchr(FilePath, '/') + 1);
strncpy(pFileName, FileString, AF_MOTOR_NAME);
LOG_INF("FileName : %s\n", pFileName);
#else
pFileName[0] = '\0';
#endif
return 1;
}
@@ -0,0 +1,222 @@
// SPDX-License-Identifier: GPL-2.0
/*
* Copyright (c) 2019 MediaTek Inc.
*/
/*
* DW9714AF voice coil motor driver
*
*
*/
#include <linux/delay.h>
#include <linux/fs.h>
#include <linux/i2c.h>
#include <linux/uaccess.h>
#include "lens_info.h"
#define AF_DRVNAME "DW9714AF_DRV"
#define AF_I2C_SLAVE_ADDR 0x18
#define AF_DEBUG
#ifdef AF_DEBUG
#define LOG_INF(format, args...) \
pr_debug(AF_DRVNAME " [%s] " format, __func__, ##args)
#else
#define LOG_INF(format, args...)
#endif
static struct i2c_client *g_pstAF_I2Cclient;
static int *g_pAF_Opened;
static spinlock_t *g_pAF_SpinLock;
static unsigned long g_u4AF_INF;
static unsigned long g_u4AF_MACRO = 1023;
static unsigned long g_u4CurrPosition;
static int s4AF_WriteReg(u16 a_u2Data)
{
int i4RetValue = 0;
char puSendCmd[2] = {(char)(a_u2Data >> 4),
(char)((a_u2Data & 0xF) << 4)};
g_pstAF_I2Cclient->addr = AF_I2C_SLAVE_ADDR;
g_pstAF_I2Cclient->addr = g_pstAF_I2Cclient->addr >> 1;
i4RetValue = i2c_master_send(g_pstAF_I2Cclient, puSendCmd, 2);
if (i4RetValue < 0) {
LOG_INF("I2C send failed!!\n");
return -1;
}
return 0;
}
static inline int getAFInfo(__user struct stAF_MotorInfo *pstMotorInfo)
{
struct stAF_MotorInfo stMotorInfo;
stMotorInfo.u4MacroPosition = g_u4AF_MACRO;
stMotorInfo.u4InfPosition = g_u4AF_INF;
stMotorInfo.u4CurrentPosition = g_u4CurrPosition;
stMotorInfo.bIsSupportSR = 1;
stMotorInfo.bIsMotorMoving = 1;
if (*g_pAF_Opened >= 1)
stMotorInfo.bIsMotorOpen = 1;
else
stMotorInfo.bIsMotorOpen = 0;
if (copy_to_user(pstMotorInfo, &stMotorInfo,
sizeof(struct stAF_MotorInfo)))
LOG_INF("copy to user failed when getting motor information\n");
return 0;
}
/* initAF include driver initialization and standby mode */
static int initAF(void)
{
LOG_INF("+\n");
if (*g_pAF_Opened == 1) {
spin_lock(g_pAF_SpinLock);
*g_pAF_Opened = 2;
spin_unlock(g_pAF_SpinLock);
}
LOG_INF("-\n");
return 0;
}
/* moveAF only use to control moving the motor */
static inline int moveAF(unsigned long a_u4Position)
{
int ret = 0;
if (s4AF_WriteReg((unsigned short)a_u4Position) == 0) {
g_u4CurrPosition = a_u4Position;
ret = 0;
} else {
LOG_INF("set I2C failed when moving the motor\n");
ret = -1;
}
return ret;
}
static inline int setAFInf(unsigned long a_u4Position)
{
spin_lock(g_pAF_SpinLock);
g_u4AF_INF = a_u4Position;
spin_unlock(g_pAF_SpinLock);
return 0;
}
static inline int setAFMacro(unsigned long a_u4Position)
{
spin_lock(g_pAF_SpinLock);
g_u4AF_MACRO = a_u4Position;
spin_unlock(g_pAF_SpinLock);
return 0;
}
/* ////////////////////////////////////////////////////////////// */
long DW9714AF_Ioctl(struct file *a_pstFile, unsigned int a_u4Command,
unsigned long a_u4Param)
{
long i4RetValue = 0;
switch (a_u4Command) {
case AFIOC_G_MOTORINFO:
i4RetValue =
getAFInfo((__user struct stAF_MotorInfo *)(a_u4Param));
break;
case AFIOC_T_MOVETO:
i4RetValue = moveAF(a_u4Param);
break;
case AFIOC_T_SETINFPOS:
i4RetValue = setAFInf(a_u4Param);
break;
case AFIOC_T_SETMACROPOS:
i4RetValue = setAFMacro(a_u4Param);
break;
default:
LOG_INF("No CMD\n");
i4RetValue = -EPERM;
break;
}
return i4RetValue;
}
/* Main jobs: */
/* 1.Deallocate anything that "open" allocated in private_data. */
/* 2.Shut down the device on last close. */
/* 3.Only called once on last time. */
/* Q1 : Try release multiple times. */
int DW9714AF_Release(struct inode *a_pstInode, struct file *a_pstFile)
{
LOG_INF("Start\n");
if (*g_pAF_Opened == 2) {
LOG_INF("Wait\n");
s4AF_WriteReg(0x80); /* Power down mode */
}
if (*g_pAF_Opened) {
LOG_INF("Free\n");
spin_lock(g_pAF_SpinLock);
*g_pAF_Opened = 0;
spin_unlock(g_pAF_SpinLock);
}
LOG_INF("End\n");
return 0;
}
int DW9714AF_SetI2Cclient(struct i2c_client *pstAF_I2Cclient,
spinlock_t *pAF_SpinLock, int *pAF_Opened)
{
g_pstAF_I2Cclient = pstAF_I2Cclient;
g_pAF_SpinLock = pAF_SpinLock;
g_pAF_Opened = pAF_Opened;
initAF();
return 1;
}
int DW9714AF_GetFileName(unsigned char *pFileName)
{
#if SUPPORT_GETTING_LENS_FOLDER_NAME
char FilePath[256];
char *FileString;
sprintf(FilePath, "%s", __FILE__);
FileString = strrchr(FilePath, '/');
*FileString = '\0';
FileString = (strrchr(FilePath, '/') + 1);
strncpy(pFileName, FileString, AF_MOTOR_NAME);
LOG_INF("FileName : %s\n", pFileName);
#else
pFileName[0] = '\0';
#endif
return 1;
}
@@ -0,0 +1,20 @@
#
# Copyright (C) 2015 MediaTek Inc.
#
# 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.
#
#
# Makefile for misc devices that really don't fit anywhere else.
#
obj-y += DW9714AF.o
@@ -0,0 +1,254 @@
// SPDX-License-Identifier: GPL-2.0
/*
* Copyright (c) 2019 MediaTek Inc.
*/
/*
* DW9718AF voice coil motor driver
*
*
*/
#include <linux/delay.h>
#include <linux/fs.h>
#include <linux/i2c.h>
#include <linux/uaccess.h>
#include "lens_info.h"
#define AF_DRVNAME "DW9718AF_DRV"
#define AF_I2C_SLAVE_ADDR 0x18
#define AF_DEBUG
#ifdef AF_DEBUG
#define LOG_INF(format, args...) \
pr_debug(AF_DRVNAME " [%s] " format, __func__, ##args)
#else
#define LOG_INF(format, args...)
#endif
static struct i2c_client *g_pstAF_I2Cclient;
static int *g_pAF_Opened;
static spinlock_t *g_pAF_SpinLock;
static unsigned long g_u4AF_INF;
static unsigned long g_u4AF_MACRO = 1023;
static unsigned long g_u4CurrPosition;
static int s4AF_WriteReg(u16 a_u2Data)
{
int i4RetValue = 0;
char puSendCmd[3] = {0x02, (char)(a_u2Data >> 8),
(char)(a_u2Data & 0xFF)};
g_pstAF_I2Cclient->addr = AF_I2C_SLAVE_ADDR;
g_pstAF_I2Cclient->addr = g_pstAF_I2Cclient->addr >> 1;
i4RetValue = i2c_master_send(g_pstAF_I2Cclient, puSendCmd, 3);
if (i4RetValue < 0) {
LOG_INF("I2C send failed!!\n");
return -1;
}
return 0;
}
static inline int getAFInfo(__user struct stAF_MotorInfo *pstMotorInfo)
{
struct stAF_MotorInfo stMotorInfo;
stMotorInfo.u4MacroPosition = g_u4AF_MACRO;
stMotorInfo.u4InfPosition = g_u4AF_INF;
stMotorInfo.u4CurrentPosition = g_u4CurrPosition;
stMotorInfo.bIsSupportSR = 1;
stMotorInfo.bIsMotorMoving = 1;
if (*g_pAF_Opened >= 1)
stMotorInfo.bIsMotorOpen = 1;
else
stMotorInfo.bIsMotorOpen = 0;
if (copy_to_user(pstMotorInfo, &stMotorInfo,
sizeof(struct stAF_MotorInfo)))
LOG_INF("copy to user failed when getting motor information\n");
return 0;
}
/* initAF include driver initialization and standby mode */
static int initAF(void)
{
LOG_INF("+\n");
if (*g_pAF_Opened == 1) {
int i4RetValue = 0;
char puSendCmd[2] = {0x00, 0x00}; /* soft power on */
char puSendCmd2[2] = {0x01, 0x39};
char puSendCmd3[2] = {0x05, 0x65};
i4RetValue = i2c_master_send(g_pstAF_I2Cclient, puSendCmd, 2);
if (i4RetValue < 0) {
LOG_INF("I2C send 0x00 failed!!\n");
return -1;
}
i4RetValue = i2c_master_send(g_pstAF_I2Cclient, puSendCmd2, 2);
if (i4RetValue < 0) {
LOG_INF("I2C send 0x01 failed!!\n");
return -1;
}
i4RetValue = i2c_master_send(g_pstAF_I2Cclient, puSendCmd3, 2);
if (i4RetValue < 0) {
LOG_INF("I2C send 0x05 failed!!\n");
return -1;
}
LOG_INF("driver init success!!\n");
spin_lock(g_pAF_SpinLock);
*g_pAF_Opened = 2;
spin_unlock(g_pAF_SpinLock);
}
LOG_INF("-\n");
return 0;
}
/* moveAF only use to control moving the motor */
static inline int moveAF(unsigned long a_u4Position)
{
int ret = 0;
if (s4AF_WriteReg((unsigned short)a_u4Position) == 0) {
g_u4CurrPosition = a_u4Position;
ret = 0;
} else {
LOG_INF("set I2C failed when moving the motor\n");
ret = -1;
}
return ret;
}
static inline int setAFInf(unsigned long a_u4Position)
{
spin_lock(g_pAF_SpinLock);
g_u4AF_INF = a_u4Position;
spin_unlock(g_pAF_SpinLock);
return 0;
}
static inline int setAFMacro(unsigned long a_u4Position)
{
spin_lock(g_pAF_SpinLock);
g_u4AF_MACRO = a_u4Position;
spin_unlock(g_pAF_SpinLock);
return 0;
}
/* ////////////////////////////////////////////////////////////// */
long DW9718AF_Ioctl(struct file *a_pstFile, unsigned int a_u4Command,
unsigned long a_u4Param)
{
long i4RetValue = 0;
switch (a_u4Command) {
case AFIOC_G_MOTORINFO:
i4RetValue =
getAFInfo((__user struct stAF_MotorInfo *)(a_u4Param));
break;
case AFIOC_T_MOVETO:
i4RetValue = moveAF(a_u4Param);
break;
case AFIOC_T_SETINFPOS:
i4RetValue = setAFInf(a_u4Param);
break;
case AFIOC_T_SETMACROPOS:
i4RetValue = setAFMacro(a_u4Param);
break;
default:
LOG_INF("No CMD\n");
i4RetValue = -EPERM;
break;
}
return i4RetValue;
}
/* Main jobs: */
/* 1.Deallocate anything that "open" allocated in private_data. */
/* 2.Shut down the device on last close. */
/* 3.Only called once on last time. */
/* Q1 : Try release multiple times. */
int DW9718AF_Release(struct inode *a_pstInode, struct file *a_pstFile)
{
LOG_INF("Start\n");
if (*g_pAF_Opened == 2) {
int i4RetValue = 0;
char puSendCmd[2] = {0x00, 0x01};
LOG_INF("apply\n");
i4RetValue = i2c_master_send(g_pstAF_I2Cclient, puSendCmd, 2);
}
if (*g_pAF_Opened) {
LOG_INF("Free\n");
spin_lock(g_pAF_SpinLock);
*g_pAF_Opened = 0;
spin_unlock(g_pAF_SpinLock);
}
LOG_INF("End\n");
return 0;
}
int DW9718AF_SetI2Cclient(struct i2c_client *pstAF_I2Cclient,
spinlock_t *pAF_SpinLock, int *pAF_Opened)
{
g_pstAF_I2Cclient = pstAF_I2Cclient;
g_pAF_SpinLock = pAF_SpinLock;
g_pAF_Opened = pAF_Opened;
initAF();
return 1;
}
int DW9718AF_GetFileName(unsigned char *pFileName)
{
#if SUPPORT_GETTING_LENS_FOLDER_NAME
char FilePath[256];
char *FileString;
sprintf(FilePath, "%s", __FILE__);
FileString = strrchr(FilePath, '/');
*FileString = '\0';
FileString = (strrchr(FilePath, '/') + 1);
strncpy(pFileName, FileString, AF_MOTOR_NAME);
LOG_INF("FileName : %s\n", pFileName);
#else
pFileName[0] = '\0';
#endif
return 1;
}
@@ -0,0 +1,20 @@
#
# Copyright (C) 2015 MediaTek Inc.
#
# 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.
#
#
# Makefile for misc devices that really don't fit anywhere else.
#
obj-y += DW9718AF.o
@@ -0,0 +1,270 @@
// SPDX-License-Identifier: GPL-2.0
/*
* Copyright (c) 2019 MediaTek Inc.
*/
/*
* DW9718GAF voice coil motor driver
*
*
*/
#include <linux/delay.h>
#include <linux/fs.h>
#include <linux/i2c.h>
#include <linux/uaccess.h>
#include "lens_info.h"
#define AF_DRVNAME "DW9718GAF_DRV"
#define AF_I2C_SLAVE_ADDR 0x18
#define AF_DEBUG
#ifdef AF_DEBUG
#define LOG_INF(format, args...) \
pr_debug(AF_DRVNAME " [%s] " format, __func__, ##args)
#else
#define LOG_INF(format, args...)
#endif
static struct i2c_client *g_pstAF_I2Cclient;
static int *g_pAF_Opened;
static spinlock_t *g_pAF_SpinLock;
static unsigned long g_u4AF_INF;
static unsigned long g_u4AF_MACRO = 1023;
static unsigned long g_u4CurrPosition;
static int s4AF_WriteReg(u16 a_u2Data)
{
int i4RetValue = 0;
char puSendCmd[3] = {0x03, (char)(a_u2Data >> 8),
(char)(a_u2Data & 0xFF)};
g_pstAF_I2Cclient->addr = AF_I2C_SLAVE_ADDR;
g_pstAF_I2Cclient->addr = g_pstAF_I2Cclient->addr >> 1;
i4RetValue = i2c_master_send(g_pstAF_I2Cclient, puSendCmd, 3);
if (i4RetValue < 0) {
LOG_INF("I2C send failed!!\n");
return -1;
}
return 0;
}
static inline int getAFInfo(__user struct stAF_MotorInfo *pstMotorInfo)
{
struct stAF_MotorInfo stMotorInfo;
stMotorInfo.u4MacroPosition = g_u4AF_MACRO;
stMotorInfo.u4InfPosition = g_u4AF_INF;
stMotorInfo.u4CurrentPosition = g_u4CurrPosition;
stMotorInfo.bIsSupportSR = 1;
stMotorInfo.bIsMotorMoving = 1;
if (*g_pAF_Opened >= 1)
stMotorInfo.bIsMotorOpen = 1;
else
stMotorInfo.bIsMotorOpen = 0;
if (copy_to_user(pstMotorInfo, &stMotorInfo,
sizeof(struct stAF_MotorInfo)))
LOG_INF("copy to user failed when getting motor information\n");
return 0;
}
/* initAF include driver initialization and standby mode */
static int initAF(void)
{
LOG_INF("+\n");
if (*g_pAF_Opened == 1) {
int i4RetValue = 0;
char puSendCmd[2] = {0x02, 0x01}; /* soft power on */
char puSendCmd2[2] = {0x02, 0x00};
char puSendCmd3[2] = {0x02, 0x02};
char puSendCmd4[2] = {0x06, 0x40};
char puSendCmd5[2] = {0x07, 0x0f};
i4RetValue = i2c_master_send(g_pstAF_I2Cclient, puSendCmd, 2);
if (i4RetValue < 0) {
LOG_INF("I2C send 0x00 failed!!\n");
return -1;
}
i4RetValue = i2c_master_send(g_pstAF_I2Cclient, puSendCmd2, 2);
if (i4RetValue < 0) {
LOG_INF("I2C send 0x01 failed!!\n");
return -1;
}
i4RetValue = i2c_master_send(g_pstAF_I2Cclient, puSendCmd3, 2);
if (i4RetValue < 0) {
LOG_INF("I2C send 0x05 failed!!\n");
return -1;
}
i4RetValue = i2c_master_send(g_pstAF_I2Cclient, puSendCmd4, 2);
if (i4RetValue < 0) {
LOG_INF("I2C send 0x06 failed!!\n");
return -1;
}
i4RetValue = i2c_master_send(g_pstAF_I2Cclient, puSendCmd5, 2);
if (i4RetValue < 0) {
LOG_INF("I2C send 0x07 failed!!\n");
return -1;
}
LOG_INF("driver init success!!\n");
spin_lock(g_pAF_SpinLock);
*g_pAF_Opened = 2;
spin_unlock(g_pAF_SpinLock);
}
LOG_INF("-\n");
return 0;
}
/* moveAF only use to control moving the motor */
static inline int moveAF(unsigned long a_u4Position)
{
int ret = 0;
if (s4AF_WriteReg((unsigned short)a_u4Position) == 0) {
g_u4CurrPosition = a_u4Position;
ret = 0;
} else {
LOG_INF("set I2C failed when moving the motor\n");
ret = -1;
}
return ret;
}
static inline int setAFInf(unsigned long a_u4Position)
{
spin_lock(g_pAF_SpinLock);
g_u4AF_INF = a_u4Position;
spin_unlock(g_pAF_SpinLock);
return 0;
}
static inline int setAFMacro(unsigned long a_u4Position)
{
spin_lock(g_pAF_SpinLock);
g_u4AF_MACRO = a_u4Position;
spin_unlock(g_pAF_SpinLock);
return 0;
}
/* ////////////////////////////////////////////////////////////// */
long DW9718GAF_Ioctl(struct file *a_pstFile, unsigned int a_u4Command,
unsigned long a_u4Param)
{
long i4RetValue = 0;
switch (a_u4Command) {
case AFIOC_G_MOTORINFO:
i4RetValue =
getAFInfo((__user struct stAF_MotorInfo *)(a_u4Param));
break;
case AFIOC_T_MOVETO:
i4RetValue = moveAF(a_u4Param);
break;
case AFIOC_T_SETINFPOS:
i4RetValue = setAFInf(a_u4Param);
break;
case AFIOC_T_SETMACROPOS:
i4RetValue = setAFMacro(a_u4Param);
break;
default:
LOG_INF("No CMD\n");
i4RetValue = -EPERM;
break;
}
return i4RetValue;
}
/* Main jobs: */
/* 1.Deallocate anything that "open" allocated in private_data. */
/* 2.Shut down the device on last close. */
/* 3.Only called once on last time. */
/* Q1 : Try release multiple times. */
int DW9718GAF_Release(struct inode *a_pstInode, struct file *a_pstFile)
{
LOG_INF("Start\n");
if (*g_pAF_Opened == 2) {
int i4RetValue = 0;
char puSendCmd[2] = {0x00, 0x01};
LOG_INF("apply\n");
i4RetValue = i2c_master_send(g_pstAF_I2Cclient, puSendCmd, 2);
}
if (*g_pAF_Opened) {
LOG_INF("Free\n");
spin_lock(g_pAF_SpinLock);
*g_pAF_Opened = 0;
spin_unlock(g_pAF_SpinLock);
}
LOG_INF("End\n");
return 0;
}
int DW9718GAF_SetI2Cclient(struct i2c_client *pstAF_I2Cclient,
spinlock_t *pAF_SpinLock, int *pAF_Opened)
{
g_pstAF_I2Cclient = pstAF_I2Cclient;
g_pAF_SpinLock = pAF_SpinLock;
g_pAF_Opened = pAF_Opened;
initAF();
return 1;
}
int DW9718GAF_GetFileName(unsigned char *pFileName)
{
#if SUPPORT_GETTING_LENS_FOLDER_NAME
char FilePath[256];
char *FileString;
sprintf(FilePath, "%s", __FILE__);
FileString = strrchr(FilePath, '/');
*FileString = '\0';
FileString = (strrchr(FilePath, '/') + 1);
strncpy(pFileName, FileString, AF_MOTOR_NAME);
LOG_INF("FileName : %s\n", pFileName);
#else
pFileName[0] = '\0';
#endif
return 1;
}
@@ -0,0 +1,20 @@
#
# Copyright (C) 2015 MediaTek Inc.
#
# 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.
#
#
# Makefile for misc devices that really don't fit anywhere else.
#
obj-y += DW9718AF.o
@@ -0,0 +1,349 @@
// SPDX-License-Identifier: GPL-2.0
/*
* Copyright (c) 2019 MediaTek Inc.
*/
/*
* DW9718SAF voice coil motor driver
*
*
*/
#include <linux/delay.h>
#include <linux/fs.h>
#include <linux/i2c.h>
#include <linux/uaccess.h>
#include "lens_info.h"
#define AF_DRVNAME "DW9718SAF_DRV"
#define AF_I2C_SLAVE_ADDR 0x18
#define AF_DEBUG
#ifdef AF_DEBUG
#define LOG_INF(format, args...) \
pr_info(AF_DRVNAME " [%s] " format, __func__, ##args)
#else
#define LOG_INF(format, args...)
#endif
static struct i2c_client *g_pstAF_I2Cclient;
static int *g_pAF_Opened;
static spinlock_t *g_pAF_SpinLock;
static unsigned long g_u4AF_INF;
static unsigned long g_u4AF_MACRO = 1023;
static unsigned long g_u4CurrPosition;
static int i2c_read(u8 a_u2Addr, u8 *a_puBuff)
{
int i4RetValue = 0;
char puReadCmd[1] = {(char)(a_u2Addr)};
g_pstAF_I2Cclient->addr = AF_I2C_SLAVE_ADDR;
g_pstAF_I2Cclient->addr = g_pstAF_I2Cclient->addr >> 1;
i4RetValue = i2c_master_send(g_pstAF_I2Cclient, puReadCmd, 1);
if (i4RetValue < 0) {
LOG_INF(" I2C write failed!!\n");
return -1;
}
i4RetValue = i2c_master_recv(g_pstAF_I2Cclient, (char *)a_puBuff, 1);
if (i4RetValue < 0) {
LOG_INF(" I2C read failed!!\n");
return -1;
}
return 0;
}
static u8 read_data(u8 addr)
{
u8 get_byte = 0xFF;
i2c_read(addr, &get_byte);
return get_byte;
}
static int s4AF_WriteReg(u16 a_u2Data)
{
int i4RetValue = 0;
char puSendCmd[3] = {0x02, (char)(a_u2Data >> 8),
(char)(a_u2Data & 0xFF)};
g_pstAF_I2Cclient->addr = AF_I2C_SLAVE_ADDR;
g_pstAF_I2Cclient->addr = g_pstAF_I2Cclient->addr >> 1;
i4RetValue = i2c_master_send(g_pstAF_I2Cclient, puSendCmd, 3);
if (i4RetValue < 0) {
LOG_INF("I2C send failed!!\n");
return -1;
}
return 0;
}
static inline int getAFInfo(__user struct stAF_MotorInfo *pstMotorInfo)
{
struct stAF_MotorInfo stMotorInfo;
stMotorInfo.u4MacroPosition = g_u4AF_MACRO;
stMotorInfo.u4InfPosition = g_u4AF_INF;
stMotorInfo.u4CurrentPosition = g_u4CurrPosition;
stMotorInfo.bIsSupportSR = 1;
stMotorInfo.bIsMotorMoving = 1;
if (*g_pAF_Opened >= 1)
stMotorInfo.bIsMotorOpen = 1;
else
stMotorInfo.bIsMotorOpen = 0;
if (copy_to_user(pstMotorInfo, &stMotorInfo,
sizeof(struct stAF_MotorInfo)))
LOG_INF("copy to user failed when getting motor information\n");
return 0;
}
/* initAF include driver initialization and standby mode */
static int initAF(void)
{
LOG_INF("+\n");
if (*g_pAF_Opened == 1) {
u8 data = 0xFF;
int i4RetValue = 0;
char puSendCmd0[2] = {0x00, 0x01}; /* Reset */
char puSendCmd1[2] = {0x00, 0x00}; /* Power on */
char puSendCmd2[2] = {0x02, 0x00};
char puSendCmd3[2] = {0x03, 0xD2}; /* Move 210 Code */
char puSendCmd4[2] = {0x01, 0x39}; /* sac3 Mode */
char puSendCmd5[2] = {0x05, 0x7C}; /* SAC period Setting */
g_pstAF_I2Cclient->addr = AF_I2C_SLAVE_ADDR;
g_pstAF_I2Cclient->addr = g_pstAF_I2Cclient->addr >> 1;
i4RetValue = i2c_master_send(g_pstAF_I2Cclient, puSendCmd0, 2);
if (i4RetValue < 0) {
LOG_INF("I2C send 0x00 failed!!\n");
return -1;
}
mdelay(1);
i4RetValue = i2c_master_send(g_pstAF_I2Cclient, puSendCmd1, 2);
if (i4RetValue < 0) {
LOG_INF("I2C send 0x00 failed!!\n");
return -1;
}
data = read_data(0x00);
LOG_INF("Addr:0x00 Data:0x%x\n", data);
if (data != 0x0)
return -1;
mdelay(1);
i4RetValue = i2c_master_send(g_pstAF_I2Cclient, puSendCmd2, 2);
if (i4RetValue < 0) {
LOG_INF("I2C send 0x02 failed!!\n");
return -1;
}
mdelay(1);
i4RetValue = i2c_master_send(g_pstAF_I2Cclient, puSendCmd3, 2);
if (i4RetValue < 0) {
LOG_INF("I2C send 0x03 failed!!\n");
return -1;
}
mdelay(1);
i4RetValue = i2c_master_send(g_pstAF_I2Cclient, puSendCmd4, 2);
if (i4RetValue < 0) {
LOG_INF("I2C send 0x01 failed!!\n");
return -1;
}
mdelay(1);
i4RetValue = i2c_master_send(g_pstAF_I2Cclient, puSendCmd5, 2);
if (i4RetValue < 0) {
LOG_INF("I2C send 0x05 failed!!\n");
return -1;
}
LOG_INF("driver init success!!\n");
spin_lock(g_pAF_SpinLock);
*g_pAF_Opened = 2;
spin_unlock(g_pAF_SpinLock);
}
LOG_INF("-\n");
return 0;
}
/* moveAF only use to control moving the motor */
static inline int moveAF(unsigned long a_u4Position)
{
int ret = 0;
if (s4AF_WriteReg((unsigned short)a_u4Position) == 0) {
g_u4CurrPosition = a_u4Position;
ret = 0;
} else {
LOG_INF("set I2C failed when moving the motor\n");
ret = -1;
}
return ret;
}
static inline int setAFInf(unsigned long a_u4Position)
{
spin_lock(g_pAF_SpinLock);
g_u4AF_INF = a_u4Position;
spin_unlock(g_pAF_SpinLock);
return 0;
}
static inline int setAFMacro(unsigned long a_u4Position)
{
spin_lock(g_pAF_SpinLock);
g_u4AF_MACRO = a_u4Position;
spin_unlock(g_pAF_SpinLock);
return 0;
}
/* ////////////////////////////////////////////////////////////// */
long DW9718SAF_Ioctl(struct file *a_pstFile, unsigned int a_u4Command,
unsigned long a_u4Param)
{
long i4RetValue = 0;
switch (a_u4Command) {
case AFIOC_G_MOTORINFO:
i4RetValue =
getAFInfo((__user struct stAF_MotorInfo *)(a_u4Param));
break;
case AFIOC_T_MOVETO:
i4RetValue = moveAF(a_u4Param);
break;
case AFIOC_T_SETINFPOS:
i4RetValue = setAFInf(a_u4Param);
break;
case AFIOC_T_SETMACROPOS:
i4RetValue = setAFMacro(a_u4Param);
break;
default:
LOG_INF("No CMD\n");
i4RetValue = -EPERM;
break;
}
return i4RetValue;
}
/* Main jobs: */
/* 1.Deallocate anything that "open" allocated in private_data. */
/* 2.Shut down the device on last close. */
/* 3.Only called once on last time. */
/* Q1 : Try release multiple times. */
int DW9718SAF_Release(struct inode *a_pstInode, struct file *a_pstFile)
{
/* power down mode */
char puSendCmd[2] = {0x00, 0x01};
LOG_INF("Start\n");
if (*g_pAF_Opened == 2) {
LOG_INF("apply +\n");
LOG_INF("apply -\n");
}
if (*g_pAF_Opened) {
LOG_INF("Free\n");
spin_lock(g_pAF_SpinLock);
*g_pAF_Opened = 0;
spin_unlock(g_pAF_SpinLock);
}
if (i2c_master_send(g_pstAF_I2Cclient, puSendCmd, 2) < 0)
LOG_INF("DW9718S Power down mode fail!\n");
LOG_INF("End\n");
return 0;
}
int DW9718SAF_PowerDown(struct i2c_client *pstAF_I2Cclient,
int *pAF_Opened)
{
g_pstAF_I2Cclient = pstAF_I2Cclient;
g_pAF_Opened = pAF_Opened;
LOG_INF("+\n");
if (*g_pAF_Opened == 0) {
int i4RetValue = 0;
u8 data = 0x0;
char puSendCmd[2] = {0x00, 0x01};
g_pstAF_I2Cclient->addr = AF_I2C_SLAVE_ADDR;
g_pstAF_I2Cclient->addr = g_pstAF_I2Cclient->addr >> 1;
i4RetValue = i2c_master_send(g_pstAF_I2Cclient, puSendCmd, 2);
data = read_data(0x00);
LOG_INF("Addr:0x00 Data:0x%x\n", data);
LOG_INF("apply - %d\n", i4RetValue);
if (i4RetValue < 0)
return -1;
}
LOG_INF("-\n");
return 0;
}
int DW9718SAF_SetI2Cclient(struct i2c_client *pstAF_I2Cclient,
spinlock_t *pAF_SpinLock, int *pAF_Opened)
{
g_pstAF_I2Cclient = pstAF_I2Cclient;
g_pAF_SpinLock = pAF_SpinLock;
g_pAF_Opened = pAF_Opened;
initAF();
return 1;
}
int DW9718SAF_GetFileName(unsigned char *pFileName)
{
#if SUPPORT_GETTING_LENS_FOLDER_NAME
char FilePath[256];
char *FileString;
sprintf(FilePath, "%s", __FILE__);
FileString = strrchr(FilePath, '/');
*FileString = '\0';
FileString = (strrchr(FilePath, '/') + 1);
strncpy(pFileName, FileString, AF_MOTOR_NAME);
LOG_INF("FileName : %s\n", pFileName);
#else
pFileName[0] = '\0';
#endif
return 1;
}
@@ -0,0 +1,20 @@
#
# Copyright (C) 2015 MediaTek Inc.
#
# 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.
#
#
# Makefile for misc devices that really don't fit anywhere else.
#
obj-y += DW9718SAF.o
@@ -0,0 +1,301 @@
// SPDX-License-Identifier: GPL-2.0
/*
* Copyright (c) 2019 MediaTek Inc.
*/
/*
* DW9718TAF voice coil motor driver
*
*
*/
#include <linux/delay.h>
#include <linux/fs.h>
#include <linux/i2c.h>
#include <linux/uaccess.h>
#include "lens_info.h"
#define AF_DRVNAME "DW9718TAF_DRV"
#define AF_I2C_SLAVE_ADDR 0x18
#define AF_DEBUG
#ifdef AF_DEBUG
#define LOG_INF(format, args...) \
pr_info(AF_DRVNAME " [%s] " format, __func__, ##args)
#else
#define LOG_INF(format, args...)
#endif
static struct i2c_client *g_pstAF_I2Cclient;
static int *g_pAF_Opened;
static spinlock_t *g_pAF_SpinLock;
static unsigned long g_u4AF_INF;
static unsigned long g_u4AF_MACRO = 1023;
static unsigned long g_u4CurrPosition;
static int i2c_read(u8 a_u2Addr, u8 *a_puBuff)
{
int i4RetValue = 0;
char puReadCmd[1] = {(char)(a_u2Addr)};
g_pstAF_I2Cclient->addr = AF_I2C_SLAVE_ADDR;
g_pstAF_I2Cclient->addr = g_pstAF_I2Cclient->addr >> 1;
i4RetValue = i2c_master_send(g_pstAF_I2Cclient, puReadCmd, 1);
if (i4RetValue < 0) {
LOG_INF(" I2C write failed!!\n");
return -1;
}
i4RetValue = i2c_master_recv(g_pstAF_I2Cclient, (char *)a_puBuff, 1);
if (i4RetValue < 0) {
LOG_INF(" I2C read failed!!\n");
return -1;
}
return 0;
}
static u8 read_data(u8 addr)
{
u8 get_byte = 0xFF;
i2c_read(addr, &get_byte);
return get_byte;
}
static int s4AF_WriteReg(u16 a_u2Data)
{
int i4RetValue = 0;
char puSendCmd[3] = {0x02, (char)(a_u2Data >> 8),
(char)(a_u2Data & 0xFF)};
g_pstAF_I2Cclient->addr = AF_I2C_SLAVE_ADDR;
g_pstAF_I2Cclient->addr = g_pstAF_I2Cclient->addr >> 1;
i4RetValue = i2c_master_send(g_pstAF_I2Cclient, puSendCmd, 3);
if (i4RetValue < 0) {
LOG_INF("I2C send failed!!\n");
return -1;
}
return 0;
}
static inline int getAFInfo(__user struct stAF_MotorInfo *pstMotorInfo)
{
struct stAF_MotorInfo stMotorInfo;
stMotorInfo.u4MacroPosition = g_u4AF_MACRO;
stMotorInfo.u4InfPosition = g_u4AF_INF;
stMotorInfo.u4CurrentPosition = g_u4CurrPosition;
stMotorInfo.bIsSupportSR = 1;
stMotorInfo.bIsMotorMoving = 1;
if (*g_pAF_Opened >= 1)
stMotorInfo.bIsMotorOpen = 1;
else
stMotorInfo.bIsMotorOpen = 0;
if (copy_to_user(pstMotorInfo, &stMotorInfo,
sizeof(struct stAF_MotorInfo)))
LOG_INF("copy to user failed when getting motor information\n");
return 0;
}
/* initAF include driver initialization and standby mode */
static int initAF(void)
{
LOG_INF("+\n");
if (*g_pAF_Opened == 1) {
u8 data = 0xFF;
int i4RetValue = 0;
char puSendCmd[2] = {0x00, 0x00}; /* soft power on */
char puSendCmd2[2] = {0x01, 0x39};
char puSendCmd3[2] = {0x05, 0x79};
g_pstAF_I2Cclient->addr = AF_I2C_SLAVE_ADDR;
g_pstAF_I2Cclient->addr = g_pstAF_I2Cclient->addr >> 1;
i4RetValue = i2c_master_send(g_pstAF_I2Cclient, puSendCmd, 2);
if (i4RetValue < 0) {
LOG_INF("I2C send 0x00 failed!!\n");
return -1;
}
data = read_data(0x00);
LOG_INF("Addr:0x00 Data:0x%x\n", data);
if (data != 0x0)
return -1;
i4RetValue = i2c_master_send(g_pstAF_I2Cclient, puSendCmd2, 2);
if (i4RetValue < 0) {
LOG_INF("I2C send 0x01 failed!!\n");
return -1;
}
i4RetValue = i2c_master_send(g_pstAF_I2Cclient, puSendCmd3, 2);
if (i4RetValue < 0) {
LOG_INF("I2C send 0x05 failed!!\n");
return -1;
}
LOG_INF("driver init success!!\n");
spin_lock(g_pAF_SpinLock);
*g_pAF_Opened = 2;
spin_unlock(g_pAF_SpinLock);
}
LOG_INF("-\n");
return 0;
}
/* moveAF only use to control moving the motor */
static inline int moveAF(unsigned long a_u4Position)
{
int ret = 0;
if (s4AF_WriteReg((unsigned short)a_u4Position) == 0) {
g_u4CurrPosition = a_u4Position;
ret = 0;
} else {
LOG_INF("set I2C failed when moving the motor\n");
ret = -1;
}
return ret;
}
static inline int setAFInf(unsigned long a_u4Position)
{
spin_lock(g_pAF_SpinLock);
g_u4AF_INF = a_u4Position;
spin_unlock(g_pAF_SpinLock);
return 0;
}
static inline int setAFMacro(unsigned long a_u4Position)
{
spin_lock(g_pAF_SpinLock);
g_u4AF_MACRO = a_u4Position;
spin_unlock(g_pAF_SpinLock);
return 0;
}
/* ////////////////////////////////////////////////////////////// */
long DW9718TAF_Ioctl(struct file *a_pstFile, unsigned int a_u4Command,
unsigned long a_u4Param)
{
long i4RetValue = 0;
switch (a_u4Command) {
case AFIOC_G_MOTORINFO:
i4RetValue =
getAFInfo((__user struct stAF_MotorInfo *)(a_u4Param));
break;
case AFIOC_T_MOVETO:
i4RetValue = moveAF(a_u4Param);
break;
case AFIOC_T_SETINFPOS:
i4RetValue = setAFInf(a_u4Param);
break;
case AFIOC_T_SETMACROPOS:
i4RetValue = setAFMacro(a_u4Param);
break;
default:
LOG_INF("No CMD\n");
i4RetValue = -EPERM;
break;
}
return i4RetValue;
}
/* Main jobs: */
/* 1.Deallocate anything that "open" allocated in private_data. */
/* 2.Shut down the device on last close. */
/* 3.Only called once on last time. */
/* Q1 : Try release multiple times. */
int DW9718TAF_Release(struct inode *a_pstInode, struct file *a_pstFile)
{
LOG_INF("Start\n");
if (*g_pAF_Opened == 2) {
int i4RetValue = 0;
u8 data = 0x0;
char puSendCmd[2] = {0x00, 0x01};
LOG_INF("apply\n");
g_pstAF_I2Cclient->addr = AF_I2C_SLAVE_ADDR;
g_pstAF_I2Cclient->addr = g_pstAF_I2Cclient->addr >> 1;
i4RetValue = i2c_master_send(g_pstAF_I2Cclient, puSendCmd, 2);
data = read_data(0x00);
LOG_INF("Addr:0x00 Data:0x%x (%d)\n", data, i4RetValue);
}
if (*g_pAF_Opened) {
LOG_INF("Free\n");
spin_lock(g_pAF_SpinLock);
*g_pAF_Opened = 0;
spin_unlock(g_pAF_SpinLock);
}
LOG_INF("End\n");
return 0;
}
int DW9718TAF_SetI2Cclient(struct i2c_client *pstAF_I2Cclient,
spinlock_t *pAF_SpinLock, int *pAF_Opened)
{
g_pstAF_I2Cclient = pstAF_I2Cclient;
g_pAF_SpinLock = pAF_SpinLock;
g_pAF_Opened = pAF_Opened;
initAF();
return 1;
}
int DW9718TAF_GetFileName(unsigned char *pFileName)
{
#if SUPPORT_GETTING_LENS_FOLDER_NAME
char FilePath[256];
char *FileString;
sprintf(FilePath, "%s", __FILE__);
FileString = strrchr(FilePath, '/');
*FileString = '\0';
FileString = (strrchr(FilePath, '/') + 1);
strncpy(pFileName, FileString, AF_MOTOR_NAME);
LOG_INF("FileName : %s\n", pFileName);
#else
pFileName[0] = '\0';
#endif
return 1;
}
@@ -0,0 +1,20 @@
#
# Copyright (C) 2015 MediaTek Inc.
#
# 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.
#
#
# Makefile for misc devices that really don't fit anywhere else.
#
obj-y += DW9718TAF.o
@@ -0,0 +1,246 @@
// SPDX-License-Identifier: GPL-2.0
/*
* Copyright (c) 2019 MediaTek Inc.
*/
/*
* DW9719TAF voice coil motor driver
*
*
*/
#include <linux/delay.h>
#include <linux/fs.h>
#include <linux/i2c.h>
#include <linux/uaccess.h>
#include "lens_info.h"
#define AF_DRVNAME "DW9719TAF_DRV"
#define AF_I2C_SLAVE_ADDR 0x18
#define AF_DEBUG
#ifdef AF_DEBUG
#define LOG_INF(format, args...) \
pr_debug(AF_DRVNAME " [%s] " format, __func__, ##args)
#else
#define LOG_INF(format, args...)
#endif
static struct i2c_client *g_pstAF_I2Cclient;
static int *g_pAF_Opened;
static spinlock_t *g_pAF_SpinLock;
static unsigned long g_u4AF_INF;
static unsigned long g_u4AF_MACRO = 1023;
static unsigned long g_u4CurrPosition;
static int s4AF_WriteReg(u16 a_u2Data)
{
int i4RetValue = 0;
char puSendCmd[3] = {0x03, (char)(a_u2Data >> 8),
(char)(a_u2Data & 0xFF)};
g_pstAF_I2Cclient->addr = AF_I2C_SLAVE_ADDR;
g_pstAF_I2Cclient->addr = g_pstAF_I2Cclient->addr >> 1;
i4RetValue = i2c_master_send(g_pstAF_I2Cclient, puSendCmd, 3);
if (i4RetValue < 0) {
LOG_INF("I2C send failed!!\n");
return -1;
}
return 0;
}
static inline int getAFInfo(__user struct stAF_MotorInfo *pstMotorInfo)
{
struct stAF_MotorInfo stMotorInfo;
stMotorInfo.u4MacroPosition = g_u4AF_MACRO;
stMotorInfo.u4InfPosition = g_u4AF_INF;
stMotorInfo.u4CurrentPosition = g_u4CurrPosition;
stMotorInfo.bIsSupportSR = 1;
stMotorInfo.bIsMotorMoving = 1;
if (*g_pAF_Opened >= 1)
stMotorInfo.bIsMotorOpen = 1;
else
stMotorInfo.bIsMotorOpen = 0;
if (copy_to_user(pstMotorInfo, &stMotorInfo,
sizeof(struct stAF_MotorInfo)))
LOG_INF("copy to user failed when getting motor information\n");
return 0;
}
/* initAF include driver initialization and standby mode */
static int initAF(void)
{
LOG_INF("+\n");
if (*g_pAF_Opened == 1) {
int i4RetValue = 0;
char puSendCmdArray[5][2] = {{0x02, 0x01},
{0xFE, 0xFE},
{0x02, 0x02},
{0x06, 0x40},
{0x07, 0x60} };
unsigned char cmd_number;
LOG_INF("InitDrv[1] %p, %p\n", &(puSendCmdArray[1][0]),
puSendCmdArray[1]);
LOG_INF("InitDrv[2] %p, %p\n", &(puSendCmdArray[2][0]),
puSendCmdArray[2]);
for (cmd_number = 0; cmd_number < 5; cmd_number++) {
if (puSendCmdArray[cmd_number][0] != 0xFE) {
i4RetValue =
i2c_master_send(g_pstAF_I2Cclient,
puSendCmdArray[cmd_number], 2);
if (i4RetValue < 0)
return -1;
} else {
udelay(200);
}
}
spin_lock(g_pAF_SpinLock);
*g_pAF_Opened = 2;
spin_unlock(g_pAF_SpinLock);
}
LOG_INF("-\n");
return 0;
}
/* moveAF only use to control moving the motor */
static inline int moveAF(unsigned long a_u4Position)
{
int ret = 0;
if (s4AF_WriteReg((unsigned short)a_u4Position) == 0) {
g_u4CurrPosition = a_u4Position;
ret = 0;
} else {
LOG_INF("set I2C failed when moving the motor\n");
ret = -1;
}
return ret;
}
static inline int setAFInf(unsigned long a_u4Position)
{
spin_lock(g_pAF_SpinLock);
g_u4AF_INF = a_u4Position;
spin_unlock(g_pAF_SpinLock);
return 0;
}
static inline int setAFMacro(unsigned long a_u4Position)
{
spin_lock(g_pAF_SpinLock);
g_u4AF_MACRO = a_u4Position;
spin_unlock(g_pAF_SpinLock);
return 0;
}
/* ////////////////////////////////////////////////////////////// */
long DW9719TAF_Ioctl(struct file *a_pstFile, unsigned int a_u4Command,
unsigned long a_u4Param)
{
long i4RetValue = 0;
switch (a_u4Command) {
case AFIOC_G_MOTORINFO:
i4RetValue =
getAFInfo((__user struct stAF_MotorInfo *)(a_u4Param));
break;
case AFIOC_T_MOVETO:
i4RetValue = moveAF(a_u4Param);
break;
case AFIOC_T_SETINFPOS:
i4RetValue = setAFInf(a_u4Param);
break;
case AFIOC_T_SETMACROPOS:
i4RetValue = setAFMacro(a_u4Param);
break;
default:
LOG_INF("No CMD\n");
i4RetValue = -EPERM;
break;
}
return i4RetValue;
}
/* Main jobs: */
/* 1.Deallocate anything that "open" allocated in private_data. */
/* 2.Shut down the device on last close. */
/* 3.Only called once on last time. */
/* Q1 : Try release multiple times. */
int DW9719TAF_Release(struct inode *a_pstInode, struct file *a_pstFile)
{
LOG_INF("Start\n");
if (*g_pAF_Opened == 2)
LOG_INF("Wait\n");
if (*g_pAF_Opened) {
LOG_INF("Free\n");
spin_lock(g_pAF_SpinLock);
*g_pAF_Opened = 0;
spin_unlock(g_pAF_SpinLock);
}
LOG_INF("End\n");
return 0;
}
int DW9719TAF_SetI2Cclient(struct i2c_client *pstAF_I2Cclient,
spinlock_t *pAF_SpinLock, int *pAF_Opened)
{
g_pstAF_I2Cclient = pstAF_I2Cclient;
g_pAF_SpinLock = pAF_SpinLock;
g_pAF_Opened = pAF_Opened;
initAF();
return 1;
}
int DW9719TAF_GetFileName(unsigned char *pFileName)
{
#if SUPPORT_GETTING_LENS_FOLDER_NAME
char FilePath[256];
char *FileString;
sprintf(FilePath, "%s", __FILE__);
FileString = strrchr(FilePath, '/');
*FileString = '\0';
FileString = (strrchr(FilePath, '/') + 1);
strncpy(pFileName, FileString, AF_MOTOR_NAME);
LOG_INF("FileName : %s\n", pFileName);
#else
pFileName[0] = '\0';
#endif
return 1;
}
@@ -0,0 +1,20 @@
#
# Copyright (C) 2015 MediaTek Inc.
#
# 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.
#
#
# Makefile for misc devices that really don't fit anywhere else.
#
obj-y += DW9719TAF.o
@@ -0,0 +1,307 @@
// SPDX-License-Identifier: GPL-2.0
/*
* Copyright (c) 2019 MediaTek Inc.
*/
/*
* DW9763AF voice coil motor driver
*
*
*/
#include <linux/delay.h>
#include <linux/fs.h>
#include <linux/i2c.h>
#include <linux/uaccess.h>
#include "lens_info.h"
#define AF_DRVNAME "DW9763AF_DRV"
#define AF_I2C_SLAVE_ADDR 0x18
#define AF_DEBUG
#ifdef AF_DEBUG
#define LOG_INF(format, args...) \
pr_debug(AF_DRVNAME " [%s] " format, __func__, ##args)
#else
#define LOG_INF(format, args...)
#endif
static struct i2c_client *g_pstAF_I2Cclient;
static int *g_pAF_Opened;
static spinlock_t *g_pAF_SpinLock;
static unsigned long g_u4AF_INF;
static unsigned long g_u4AF_MACRO = 1023;
//static unsigned long g_u4TargetPosition;
static unsigned long g_u4CurrPosition;
static int i2c_read(u8 a_u2Addr, u8 *a_puBuff)
{
int i4RetValue = 0;
char puReadCmd[1] = {(char)(a_u2Addr)};
g_pstAF_I2Cclient->addr = AF_I2C_SLAVE_ADDR;
g_pstAF_I2Cclient->addr = g_pstAF_I2Cclient->addr >> 1;
i4RetValue = i2c_master_send(g_pstAF_I2Cclient, puReadCmd, 1);
if (i4RetValue != 2) {
LOG_INF(" I2C write failed!!\n");
return -1;
}
i4RetValue = i2c_master_recv(g_pstAF_I2Cclient, (char *)a_puBuff, 1);
if (i4RetValue != 1) {
LOG_INF(" I2C read failed!!\n");
return -1;
}
return 0;
}
u8 read_data(u8 addr)
{
u8 get_byte = 0;
i2c_read(addr, &get_byte);
return get_byte;
}
static int s4AF_WriteReg(u16 a_u2Data)
{
int i4RetValue = 0;
char puSendCmd[2] = {(char)(0x03), (char)(a_u2Data >> 8)};
char puSendCmd1[2] = {(char)(0x04), (char)(a_u2Data & 0xFF)};
g_pstAF_I2Cclient->addr = AF_I2C_SLAVE_ADDR;
g_pstAF_I2Cclient->addr = g_pstAF_I2Cclient->addr >> 1;
i4RetValue = i2c_master_send(g_pstAF_I2Cclient, puSendCmd, 2);
if (i4RetValue < 0) {
LOG_INF("%s failed.\n", __func__);
return -1;
}
i4RetValue = i2c_master_send(g_pstAF_I2Cclient, puSendCmd1, 2);
if (i4RetValue < 0) {
LOG_INF("%s failed.\n", __func__);
return -1;
}
return 0;
}
static int AF_setconfig(void)
{
int Ret = 0;
char puSendCmd2[2] = {(char)(0x02), (char)(0x02)};
char puSendCmd3[2] = {(char)(0x06), (char)(0x61)};
char puSendCmd4[2] = {(char)(0x07), (char)(0x39)};
LOG_INF("Start\n");
g_pstAF_I2Cclient->addr = AF_I2C_SLAVE_ADDR;
g_pstAF_I2Cclient->addr = g_pstAF_I2Cclient->addr >> 1;
Ret = i2c_master_send(g_pstAF_I2Cclient, puSendCmd2, 2);
if (Ret < 0)
LOG_INF("puSendCmd2 send failed\n");
Ret = i2c_master_send(g_pstAF_I2Cclient, puSendCmd3, 2);
if (Ret < 0)
LOG_INF("puSendCmd3 send failed\n");
Ret = i2c_master_send(g_pstAF_I2Cclient, puSendCmd4, 2);
if (Ret < 0)
LOG_INF("puSendCmd4 send failed\n");
LOG_INF("End\n");
return 0;
}
static inline int getAFInfo(__user struct stAF_MotorInfo *pstMotorInfo)
{
struct stAF_MotorInfo stMotorInfo;
stMotorInfo.u4MacroPosition = g_u4AF_MACRO;
stMotorInfo.u4InfPosition = g_u4AF_INF;
stMotorInfo.u4CurrentPosition = g_u4CurrPosition;
stMotorInfo.bIsSupportSR = 1;
stMotorInfo.bIsMotorMoving = 1;
if (*g_pAF_Opened >= 1)
stMotorInfo.bIsMotorOpen = 1;
else
stMotorInfo.bIsMotorOpen = 0;
if (copy_to_user(pstMotorInfo, &stMotorInfo,
sizeof(struct stAF_MotorInfo)))
LOG_INF("copy to user failed when getting motor information\n");
return 0;
}
#ifdef LensdrvCM3
static inline int getAFMETA(__user stAF_MotorMETAInfo * pstMotorMETAInfo)
{
stAF_MotorMETAInfo stMotorMETAInfo;
stMotorMETAInfo.Aperture = 2.8; //fn
stMotorMETAInfo.Facing = 1;
stMotorMETAInfo.FilterDensity = 1; //X
stMotorMETAInfo.FocalDistance = 1.0; //diopters
stMotorMETAInfo.FocalLength = 34.0; //mm
stMotorMETAInfo.FocusRange = 1.0; //diopters
stMotorMETAInfo.InfoAvalibleApertures = 2.8;
stMotorMETAInfo.InfoAvalibleFilterDensity = 1;
stMotorMETAInfo.InfoAvalibleFocalLength = 34.0;
stMotorMETAInfo.InfoAvalibleHypeDistance = 1.0;
stMotorMETAInfo.InfoAvalibleMinFocusDistance = 1.0;
stMotorMETAInfo.InfoAvalibleOptStabilization = 0;
stMotorMETAInfo.OpticalAxisAng[0] = 0.0;
stMotorMETAInfo.OpticalAxisAng[1] = 0.0;
stMotorMETAInfo.Position[0] = 0.0;
stMotorMETAInfo.Position[1] = 0.0;
stMotorMETAInfo.Position[2] = 0.0;
stMotorMETAInfo.State = 0;
stMotorMETAInfo.u4OIS_Mode = 0;
if (copy_to_user(pstMotorMETAInfo, &stMotorMETAInfo,
sizeof(stAF_MotorMETAInfo)))
LOG_INF("copy to user failed when getting motor information\n");
return 0;
}
#endif
/* initAF include driver initialization and standby mode */
static int initAF(void)
{
LOG_INF("+\n");
if (*g_pAF_Opened == 1) {
AF_setconfig();
spin_lock(g_pAF_SpinLock);
*g_pAF_Opened = 2;
spin_unlock(g_pAF_SpinLock);
}
LOG_INF("-\n");
return 0;
}
/* moveAF only use to control moving the motor */
static inline int moveAF(unsigned long a_u4Position)
{
int ret = 0;
if (s4AF_WriteReg((unsigned short)a_u4Position) == 0) {
g_u4CurrPosition = a_u4Position;
ret = 0;
} else {
LOG_INF("set I2C failed when moving the motor\n");
ret = -1;
}
return ret;
}
static inline int setAFInf(unsigned long a_u4Position)
{
spin_lock(g_pAF_SpinLock);
g_u4AF_INF = a_u4Position;
spin_unlock(g_pAF_SpinLock);
return 0;
}
static inline int setAFMacro(unsigned long a_u4Position)
{
spin_lock(g_pAF_SpinLock);
g_u4AF_MACRO = a_u4Position;
spin_unlock(g_pAF_SpinLock);
return 0;
}
/* ////////////////////////////////////////////////////////////// */
long DW9763AF_Ioctl(struct file *a_pstFile, unsigned int a_u4Command,
unsigned long a_u4Param)
{
long i4RetValue = 0;
switch (a_u4Command) {
case AFIOC_G_MOTORINFO:
i4RetValue =
getAFInfo((__user struct stAF_MotorInfo *)(a_u4Param));
break;
case AFIOC_T_MOVETO:
i4RetValue = moveAF(a_u4Param);
break;
case AFIOC_T_SETINFPOS:
i4RetValue = setAFInf(a_u4Param);
break;
case AFIOC_T_SETMACROPOS:
i4RetValue = setAFMacro(a_u4Param);
break;
default:
LOG_INF("No CMD\n");
i4RetValue = -EPERM;
break;
}
return i4RetValue;
}
/* Main jobs: */
/* 1.Deallocate anything that "open" allocated in private_data. */
/* 2.Shut down the device on last close. */
/* 3.Only called once on last time. */
/* Q1 : Try release multiple times. */
int DW9763AF_Release(struct inode *a_pstInode, struct file *a_pstFile)
{
LOG_INF("Start\n");
if (*g_pAF_Opened == 2) {
LOG_INF("Wait\n");
s4AF_WriteReg(0x80); /* Power down mode */
}
if (*g_pAF_Opened) {
LOG_INF("Free\n");
spin_lock(g_pAF_SpinLock);
*g_pAF_Opened = 0;
spin_unlock(g_pAF_SpinLock);
}
LOG_INF("End\n");
return 0;
}
int DW9763AF_PowerDown(struct i2c_client *pstAF_I2Cclient,
int *pAF_Opened)
{
g_pstAF_I2Cclient = pstAF_I2Cclient;
g_pAF_Opened = pAF_Opened;
LOG_INF("+\n");
if (*g_pAF_Opened == 0) {
int i4RetValue = 0;
u8 data = 0x0;
char puSendCmd[2] = {0x00, 0x01};
g_pstAF_I2Cclient->addr = AF_I2C_SLAVE_ADDR;
g_pstAF_I2Cclient->addr = g_pstAF_I2Cclient->addr >> 1;
i4RetValue = i2c_master_send(g_pstAF_I2Cclient, puSendCmd, 2);
data = read_data(0x00);
LOG_INF("Addr:0x00 Data:0x%x\n", data);
LOG_INF("apply - %d\n", i4RetValue);
if (i4RetValue < 0)
return -1;
}
LOG_INF("-\n");
return 0;
}
int DW9763AF_SetI2Cclient(struct i2c_client *pstAF_I2Cclient,
spinlock_t *pAF_SpinLock, int *pAF_Opened)
{
g_pstAF_I2Cclient = pstAF_I2Cclient;
g_pAF_SpinLock = pAF_SpinLock;
g_pAF_Opened = pAF_Opened;
initAF();
return 1;
}
int DW9763AF_GetFileName(unsigned char *pFileName)
{
#if SUPPORT_GETTING_LENS_FOLDER_NAME
char FilePath[256];
char *FileString;
sprintf(FilePath, "%s", __FILE__);
FileString = strrchr(FilePath, '/');
*FileString = '\0';
FileString = (strrchr(FilePath, '/') + 1);
strncpy(pFileName, FileString, AF_MOTOR_NAME);
LOG_INF("FileName : %s\n", pFileName);
#else
pFileName[0] = '\0';
#endif
return 1;
}
@@ -0,0 +1,20 @@
#
# Copyright (C) 2015 MediaTek Inc.
#
# 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.
#
#
# Makefile for misc devices that really don't fit anywhere else.
#
obj-y += DW9763AF.o
@@ -0,0 +1,306 @@
// SPDX-License-Identifier: GPL-2.0
/*
* Copyright (c) 2019 MediaTek Inc.
*/
/*
* DW9814AF voice coil motor driver
*
*
*/
#include <linux/delay.h>
#include <linux/fs.h>
#include <linux/i2c.h>
#include <linux/uaccess.h>
#include "lens_info.h"
#define AF_DRVNAME "DW9800WAF_DRV"
#define AF_I2C_SLAVE_ADDR 0x18
#define AF_DEBUG
#ifdef AF_DEBUG
#define LOG_INF(format, args...) \
pr_debug(AF_DRVNAME " [%s] " format, __func__, ##args)
#else
#define LOG_INF(format, args...)
#endif
static struct i2c_client *g_pstAF_I2Cclient;
static int *g_pAF_Opened;
static spinlock_t *g_pAF_SpinLock;
static unsigned long g_u4AF_INF;
static unsigned long g_u4AF_MACRO = 1023;
static unsigned long g_u4TargetPosition;
static unsigned long g_u4CurrPosition;
static int i2c_read(u8 a_u2Addr, u8 *a_puBuff)
{
int i4RetValue = 0;
char puReadCmd[1] = { (char)(a_u2Addr) };
i4RetValue = i2c_master_send(g_pstAF_I2Cclient, puReadCmd, 1);
if (i4RetValue != 2) {
LOG_INF(" I2C write failed!!\n");
return -1;
}
i4RetValue = i2c_master_recv(g_pstAF_I2Cclient, (char *)a_puBuff, 1);
if (i4RetValue != 1) {
LOG_INF(" I2C read failed!!\n");
return -1;
}
return 0;
}
static u8 read_data(u8 addr)
{
u8 get_byte = 0;
i2c_read(addr, &get_byte);
return get_byte;
}
static int s4DW9800WAF_ReadReg(unsigned short *a_pu2Result)
{
*a_pu2Result = (read_data(0x03) << 8) + (read_data(0x04) & 0xff);
return 0;
}
static int s4AF_WriteReg(u16 a_u2Data)
{
int i4RetValue = 0;
char puSendCmd[3] = { 0x03, (char)(a_u2Data >> 8),
(char)(a_u2Data & 0xFF) };
g_pstAF_I2Cclient->addr = AF_I2C_SLAVE_ADDR;
g_pstAF_I2Cclient->addr = g_pstAF_I2Cclient->addr >> 1;
i4RetValue = i2c_master_send(g_pstAF_I2Cclient, puSendCmd, 3);
if (i4RetValue < 0) {
LOG_INF("I2C send failed!!\n");
return -1;
}
return 0;
}
static inline int getAFInfo(__user struct stAF_MotorInfo *pstMotorInfo)
{
struct stAF_MotorInfo stMotorInfo;
stMotorInfo.u4MacroPosition = g_u4AF_MACRO;
stMotorInfo.u4InfPosition = g_u4AF_INF;
stMotorInfo.u4CurrentPosition = g_u4CurrPosition;
stMotorInfo.bIsSupportSR = 1;
stMotorInfo.bIsMotorMoving = 1;
if (*g_pAF_Opened >= 1)
stMotorInfo.bIsMotorOpen = 1;
else
stMotorInfo.bIsMotorOpen = 0;
if (copy_to_user(pstMotorInfo, &stMotorInfo,
sizeof(struct stAF_MotorInfo)))
LOG_INF("copy to user failed when getting motor information\n");
return 0;
}
static int initdrv(void)
{
int i4RetValue = 0;
char puSendCmdArray[7][2] = {
{0x02, 0x01}, {0x02, 0x00}, {0xFE, 0xFE},
{0x02, 0x02}, {0x06, 0x40}, {0x07, 0x60}, {0xFE, 0xFE},
};
unsigned char cmd_number;
LOG_INF("InitDrv[1] %p, %p\n", &(puSendCmdArray[1][0]),
puSendCmdArray[1]);
LOG_INF("InitDrv[2] %p, %p\n", &(puSendCmdArray[2][0]),
puSendCmdArray[2]);
for (cmd_number = 0; cmd_number < 7; cmd_number++) {
if (puSendCmdArray[cmd_number][0] != 0xFE) {
i4RetValue = i2c_master_send(g_pstAF_I2Cclient,
puSendCmdArray[cmd_number], 2);
if (i4RetValue < 0)
return -1;
} else {
udelay(100);
}
}
return i4RetValue;
}
static inline int moveAF(unsigned long a_u4Position)
{
int ret = 0;
if ((a_u4Position > g_u4AF_MACRO) || (a_u4Position < g_u4AF_INF)) {
LOG_INF("out of range\n");
return -EINVAL;
}
if (g_u4CurrPosition == a_u4Position)
return 0;
spin_lock(g_pAF_SpinLock);
g_u4TargetPosition = a_u4Position;
spin_unlock(g_pAF_SpinLock);
if (s4AF_WriteReg((unsigned short)g_u4TargetPosition) == 0) {
spin_lock(g_pAF_SpinLock);
g_u4CurrPosition = (unsigned long)g_u4TargetPosition;
spin_unlock(g_pAF_SpinLock);
} else {
LOG_INF("set I2C failed when moving the motor\n");
ret = -1;
}
return ret;
}
static inline int setAFInf(unsigned long a_u4Position)
{
spin_lock(g_pAF_SpinLock);
g_u4AF_INF = a_u4Position;
spin_unlock(g_pAF_SpinLock);
return 0;
}
static inline int setAFMacro(unsigned long a_u4Position)
{
spin_lock(g_pAF_SpinLock);
g_u4AF_MACRO = a_u4Position;
spin_unlock(g_pAF_SpinLock);
return 0;
}
/* ////////////////////////////////////////////////////////////// */
long DW9800WAF_Ioctl(struct file *a_pstFile, unsigned int a_u4Command,
unsigned long a_u4Param)
{
long i4RetValue = 0;
switch (a_u4Command) {
case AFIOC_G_MOTORINFO:
i4RetValue = getAFInfo((__user struct stAF_MotorInfo *)
(a_u4Param));
break;
case AFIOC_T_MOVETO:
i4RetValue = moveAF(a_u4Param);
break;
case AFIOC_T_SETINFPOS:
i4RetValue = setAFInf(a_u4Param);
break;
case AFIOC_T_SETMACROPOS:
i4RetValue = setAFMacro(a_u4Param);
break;
default:
LOG_INF("No CMD\n");
i4RetValue = -EPERM;
break;
}
return i4RetValue;
}
/* Main jobs: */
/* 1.Deallocate anything that "open" allocated in private_data. */
/* 2.Shut down the device on last close. */
/* 3.Only called once on last time. */
/* Q1 : Try release multiple times. */
int DW9800WAF_Release(struct inode *a_pstInode, struct file *a_pstFile)
{
LOG_INF("Start\n");
if (*g_pAF_Opened == 2)
LOG_INF("Wait\n");
if (*g_pAF_Opened) {
LOG_INF("Free\n");
spin_lock(g_pAF_SpinLock);
*g_pAF_Opened = 0;
spin_unlock(g_pAF_SpinLock);
}
LOG_INF("End\n");
return 0;
}
int DW9800WAF_SetI2Cclient(struct i2c_client *pstAF_I2Cclient,
spinlock_t *pAF_SpinLock, int *pAF_Opened)
{
int ret = 0;
unsigned short InitPos = 0;
g_pstAF_I2Cclient = pstAF_I2Cclient;
g_pAF_SpinLock = pAF_SpinLock;
g_pAF_Opened = pAF_Opened;
if (*g_pAF_Opened == 1) {
initdrv();
ret = s4DW9800WAF_ReadReg(&InitPos);
if (ret == 0) {
LOG_INF("Init Pos %6d\n", InitPos);
spin_lock(g_pAF_SpinLock);
g_u4CurrPosition = (unsigned long)InitPos;
spin_unlock(g_pAF_SpinLock);
} else {
spin_lock(g_pAF_SpinLock);
g_u4CurrPosition = 0;
spin_unlock(g_pAF_SpinLock);
}
spin_lock(g_pAF_SpinLock);
*g_pAF_Opened = 2;
spin_unlock(g_pAF_SpinLock);
}
return 1;
}
int DW9800WAF_GetFileName(unsigned char *pFileName)
{
#if SUPPORT_GETTING_LENS_FOLDER_NAME
char FilePath[256];
char *FileString;
sprintf(FilePath, "%s", __FILE__);
FileString = strrchr(FilePath, '/');
*FileString = '\0';
FileString = (strrchr(FilePath, '/') + 1);
strncpy(pFileName, FileString, AF_MOTOR_NAME);
LOG_INF("FileName : %s\n", pFileName);
#else
pFileName[0] = '\0';
#endif
return 1;
}
@@ -0,0 +1,20 @@
#
# Copyright (C) 2015 MediaTek Inc.
#
# 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.
#
#
# Makefile for misc devices that really don't fit anywhere else.
#
obj-y += DW9800WAF.o
@@ -0,0 +1,224 @@
// SPDX-License-Identifier: GPL-2.0
/*
* Copyright (c) 2019 MediaTek Inc.
*/
/*
* DW9814AF voice coil motor driver
*
*
*/
#include <linux/delay.h>
#include <linux/fs.h>
#include <linux/i2c.h>
#include <linux/uaccess.h>
#include "lens_info.h"
#define AF_DRVNAME "DW9814AF_DRV"
#define AF_I2C_SLAVE_ADDR 0x18
#define AF_DEBUG
#ifdef AF_DEBUG
#define LOG_INF(format, args...) \
pr_debug(AF_DRVNAME " [%s] " format, __func__, ##args)
#else
#define LOG_INF(format, args...)
#endif
static struct i2c_client *g_pstAF_I2Cclient;
static int *g_pAF_Opened;
static spinlock_t *g_pAF_SpinLock;
static unsigned long g_u4AF_INF;
static unsigned long g_u4AF_MACRO = 1023;
static unsigned long g_u4CurrPosition;
static int s4AF_WriteReg(u16 a_u2Data)
{
int i4RetValue = 0;
char puSendCmd[2] = {(char)(a_u2Data >> 4),
(char)((a_u2Data & 0xF) << 4)};
g_pstAF_I2Cclient->addr = AF_I2C_SLAVE_ADDR;
g_pstAF_I2Cclient->addr = g_pstAF_I2Cclient->addr >> 1;
i4RetValue = i2c_master_send(g_pstAF_I2Cclient, puSendCmd, 2);
if (i4RetValue < 0) {
LOG_INF("I2C send failed!!\n");
return -1;
}
return 0;
}
static inline int getAFInfo(__user struct stAF_MotorInfo *pstMotorInfo)
{
struct stAF_MotorInfo stMotorInfo;
stMotorInfo.u4MacroPosition = g_u4AF_MACRO;
stMotorInfo.u4InfPosition = g_u4AF_INF;
stMotorInfo.u4CurrentPosition = g_u4CurrPosition;
stMotorInfo.bIsSupportSR = 1;
stMotorInfo.bIsMotorMoving = 1;
if (*g_pAF_Opened >= 1)
stMotorInfo.bIsMotorOpen = 1;
else
stMotorInfo.bIsMotorOpen = 0;
if (copy_to_user(pstMotorInfo, &stMotorInfo,
sizeof(struct stAF_MotorInfo)))
LOG_INF("copy to user failed when getting motor information\n");
return 0;
}
/* initAF include driver initialization and standby mode */
static int initAF(void)
{
LOG_INF("+\n");
if (*g_pAF_Opened == 1) {
spin_lock(g_pAF_SpinLock);
*g_pAF_Opened = 2;
spin_unlock(g_pAF_SpinLock);
}
LOG_INF("-\n");
return 0;
}
/* moveAF only use to control moving the motor */
static inline int moveAF(unsigned long a_u4Position)
{
int ret = 0;
if (s4AF_WriteReg((unsigned short)a_u4Position) == 0) {
g_u4CurrPosition = a_u4Position;
ret = 0;
} else {
LOG_INF("set I2C failed when moving the motor\n");
ret = -1;
}
return ret;
}
static inline int setAFInf(unsigned long a_u4Position)
{
spin_lock(g_pAF_SpinLock);
g_u4AF_INF = a_u4Position;
spin_unlock(g_pAF_SpinLock);
return 0;
}
static inline int setAFMacro(unsigned long a_u4Position)
{
spin_lock(g_pAF_SpinLock);
g_u4AF_MACRO = a_u4Position;
spin_unlock(g_pAF_SpinLock);
return 0;
}
/* ////////////////////////////////////////////////////////////// */
long DW9814AF_Ioctl(struct file *a_pstFile, unsigned int a_u4Command,
unsigned long a_u4Param)
{
long i4RetValue = 0;
switch (a_u4Command) {
case AFIOC_G_MOTORINFO:
i4RetValue =
getAFInfo((__user struct stAF_MotorInfo *)(a_u4Param));
break;
case AFIOC_T_MOVETO:
i4RetValue = moveAF(a_u4Param);
break;
case AFIOC_T_SETINFPOS:
i4RetValue = setAFInf(a_u4Param);
break;
case AFIOC_T_SETMACROPOS:
i4RetValue = setAFMacro(a_u4Param);
break;
default:
LOG_INF("No CMD\n");
i4RetValue = -EPERM;
break;
}
return i4RetValue;
}
/* Main jobs: */
/* 1.Deallocate anything that "open" allocated in private_data. */
/* 2.Shut down the device on last close. */
/* 3.Only called once on last time. */
/* Q1 : Try release multiple times. */
int DW9814AF_Release(struct inode *a_pstInode, struct file *a_pstFile)
{
LOG_INF("Start\n");
if (*g_pAF_Opened == 2) {
LOG_INF("Wait\n");
s4AF_WriteReg(200);
msleep(20);
s4AF_WriteReg(100);
msleep(20);
}
if (*g_pAF_Opened) {
LOG_INF("Free\n");
spin_lock(g_pAF_SpinLock);
*g_pAF_Opened = 0;
spin_unlock(g_pAF_SpinLock);
}
LOG_INF("End\n");
return 0;
}
int DW9814AF_SetI2Cclient(struct i2c_client *pstAF_I2Cclient,
spinlock_t *pAF_SpinLock, int *pAF_Opened)
{
g_pstAF_I2Cclient = pstAF_I2Cclient;
g_pAF_SpinLock = pAF_SpinLock;
g_pAF_Opened = pAF_Opened;
initAF();
return 1;
}
int DW9814AF_GetFileName(unsigned char *pFileName)
{
#if SUPPORT_GETTING_LENS_FOLDER_NAME
char FilePath[256];
char *FileString;
sprintf(FilePath, "%s", __FILE__);
FileString = strrchr(FilePath, '/');
*FileString = '\0';
FileString = (strrchr(FilePath, '/') + 1);
strncpy(pFileName, FileString, AF_MOTOR_NAME);
LOG_INF("FileName : %s\n", pFileName);
#else
pFileName[0] = '\0';
#endif
return 1;
}
@@ -0,0 +1,20 @@
#
# Copyright (C) 2015 MediaTek Inc.
#
# 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.
#
#
# Makefile for misc devices that really don't fit anywhere else.
#
obj-y += DW9814AF.o
@@ -0,0 +1,436 @@
// SPDX-License-Identifier: GPL-2.0
/*
* Copyright (c) 2019 MediaTek Inc.
*/
/*
* DW9839AF voice coil motor driver
*
*
*/
#include <linux/i2c.h>
#include <linux/delay.h>
#include <linux/uaccess.h>
#include <linux/fs.h>
#include "lens_info.h"
#define AF_DRVNAME "DW9839AF_DRV"
#define AF_I2C_SLAVE_ADDR 0x18
#define AF_DEBUG
#ifdef AF_DEBUG
#define LOG_INF(format, args...) pr_debug(AF_DRVNAME " [%s] " \
format, __func__, ##args)
#else
#define LOG_INF(format, args...)
#endif
static struct i2c_client *g_pstAF_I2Cclient;
static int *g_pAF_Opened;
static spinlock_t *g_pAF_SpinLock;
#if defined(CONFIG_MACH_MT6771)
static unsigned int g_ACKErrorCnt = 5;
#else
static unsigned int g_ACKErrorCnt = 100;
#endif
static int check_status;
static unsigned long g_u4AF_INF;
static unsigned long g_u4AF_MACRO = 1023;
static unsigned long g_u4TargetPosition;
static unsigned long g_u4CurrPosition;
static inline void AFI2CSendFormat(struct stAF_MotorI2CSendCmd *pstMotor)
{
pstMotor->Resolution = 10;
pstMotor->SlaveAddr = 0x18;
pstMotor->I2CSendNum = 2;
pstMotor->I2CFmt[0].AddrNum = 1;
pstMotor->I2CFmt[0].DataNum = 1;
/* Addr Format */
pstMotor->I2CFmt[0].Addr[0] = 0x00;
/* Data Format : CtrlData | ( ( Data >> BitRR ) */
/* & Mask1 ) << BitRL ) & Mask2 */
pstMotor->I2CFmt[0].CtrlData[0] = 0x00; /* Control Data */
pstMotor->I2CFmt[0].BitRR[0] = 2;
pstMotor->I2CFmt[0].Mask1[0] = 0xFF;
pstMotor->I2CFmt[0].BitRL[0] = 0;
pstMotor->I2CFmt[0].Mask2[0] = 0xFF;
pstMotor->I2CFmt[1].AddrNum = 1;
pstMotor->I2CFmt[1].DataNum = 1;
/* Addr Format */
pstMotor->I2CFmt[1].Addr[0] = 0x01;
/* Data Format : CtrlData | ( ( Data >> BitRR ) */
/* & Mask1 ) << BitRL ) & Mask2 */
pstMotor->I2CFmt[1].CtrlData[0] = 0x00; /* Control Data */
pstMotor->I2CFmt[1].BitRR[0] = 0;
pstMotor->I2CFmt[1].Mask1[0] = 0x03;
pstMotor->I2CFmt[1].BitRL[0] = 6;
pstMotor->I2CFmt[1].Mask2[0] = 0xC0;
}
static inline int getAFI2CSendFormat(__user struct stAF_MotorI2CSendCmd
*pstMotorI2CSendCmd)
{
struct stAF_MotorI2CSendCmd stMotor;
AFI2CSendFormat(&stMotor);
if (copy_to_user(pstMotorI2CSendCmd, &stMotor, sizeof(struct
stAF_MotorI2CSendCmd)))
LOG_INF("copy to user failed when getting motor information\n");
return 0;
}
static int s4AF_ReadReg(u8 a_uAddr, u16 *a_pu2Result)
{
int i4RetValue = 0;
char pBuff;
char puSendCmd[1];
if (g_ACKErrorCnt == 0)
return 0;
puSendCmd[0] = a_uAddr;
g_pstAF_I2Cclient->addr = AF_I2C_SLAVE_ADDR;
g_pstAF_I2Cclient->addr = g_pstAF_I2Cclient->addr >> 1;
i4RetValue = i2c_master_send(g_pstAF_I2Cclient, puSendCmd, 1);
if (i4RetValue < 0) {
if (g_ACKErrorCnt > 0)
g_ACKErrorCnt--;
LOG_INF("I2C read - send failed!!\n");
return -1;
}
i4RetValue = i2c_master_recv(g_pstAF_I2Cclient, &pBuff, 1);
if (i4RetValue < 0) {
if (g_ACKErrorCnt > 0)
g_ACKErrorCnt--;
LOG_INF("I2C read - recv failed!!\n");
return -1;
}
*a_pu2Result = pBuff;
return 0;
}
static int s4AF_WriteReg(u16 a_u2Addr, u16 a_u2Data)
{
int i4RetValue = 0;
char puSendCmd[2] = { (char)a_u2Addr, (char)a_u2Data };
if (g_ACKErrorCnt == 0)
return 0;
g_pstAF_I2Cclient->addr = AF_I2C_SLAVE_ADDR;
g_pstAF_I2Cclient->addr = g_pstAF_I2Cclient->addr >> 1;
i4RetValue = i2c_master_send(g_pstAF_I2Cclient, puSendCmd, 2);
/* LOG_INF("I2C Addr[0] = 0x%x , Data[0] = 0x%x\n",*/
/*puSendCmd[0], puSendCmd[1]); */
if (i4RetValue < 0) {
if (g_ACKErrorCnt > 0)
g_ACKErrorCnt--;
LOG_INF("I2C write failed!!\n");
return -1;
}
return 0;
}
static inline int getAFInfo(__user struct stAF_MotorInfo *pstMotorInfo)
{
struct stAF_MotorInfo stMotorInfo;
stMotorInfo.u4MacroPosition = g_u4AF_MACRO;
stMotorInfo.u4InfPosition = g_u4AF_INF;
stMotorInfo.u4CurrentPosition = g_u4CurrPosition;
stMotorInfo.bIsSupportSR = 1;
stMotorInfo.bIsMotorMoving = 1;
if (*g_pAF_Opened >= 1)
stMotorInfo.bIsMotorOpen = 1;
else
stMotorInfo.bIsMotorOpen = 0;
if (copy_to_user(pstMotorInfo, &stMotorInfo, sizeof(struct
stAF_MotorInfo)))
LOG_INF("copy to user failed when getting motor information\n");
return 0;
}
static inline int setVCMPos(unsigned long a_u4Position)
{
int i4RetValue = 0;
i4RetValue = s4AF_WriteReg(0x0, (u16) ((a_u4Position >> 2) & 0xff));
if (i4RetValue < 0)
return -1;
i4RetValue = s4AF_WriteReg(0x1, (u16) ((a_u4Position & 0x3) << 6));
return i4RetValue;
}
static inline int initdrv(void)
{
int i4RetValue = 0;
int ret = 0;
unsigned short data = 0;
LOG_INF("check_status=%d\n", check_status);
/* 00:active mode , 10:Standby mode , x1:Sleep mode */
ret = s4AF_WriteReg(0x03, 0x11); /* from Standby mode to Active mode */
msleep(20);
if (ret == 0) {
ret = s4AF_ReadReg(0x03, &data);
if ((ret == 0) && ((data & 0x10) != 0))
i4RetValue = 1;
}
return i4RetValue;
}
static inline int moveAF(unsigned long a_u4Position)
{
int ret = 0;
if ((a_u4Position > g_u4AF_MACRO) || (a_u4Position < g_u4AF_INF)) {
LOG_INF("out of range\n");
return -EINVAL;
}
if (g_u4CurrPosition == a_u4Position)
return 0;
spin_lock(g_pAF_SpinLock);
g_u4TargetPosition = a_u4Position;
spin_unlock(g_pAF_SpinLock);
/* LOG_INF("move [curr] %d [target] %d\n", g_u4CurrPosition,*/
/*g_u4TargetPosition); */
/* s4AF_WriteReg(0x02, 0x00); */
if (setVCMPos(g_u4TargetPosition) == 0) {
spin_lock(g_pAF_SpinLock);
g_u4CurrPosition = (unsigned long)g_u4TargetPosition;
spin_unlock(g_pAF_SpinLock);
} else {
LOG_INF("set I2C failed when moving the motor\n");
ret = -1;
}
return ret;
}
static inline int setAFInf(unsigned long a_u4Position)
{
spin_lock(g_pAF_SpinLock);
g_u4AF_INF = a_u4Position;
spin_unlock(g_pAF_SpinLock);
return 0;
}
static inline int setAFMacro(unsigned long a_u4Position)
{
spin_lock(g_pAF_SpinLock);
g_u4AF_MACRO = a_u4Position;
spin_unlock(g_pAF_SpinLock);
return 0;
}
/* ////////////////////////////////////////////////////////////// */
long DW9839AF_Ioctl(struct file *a_pstFile, unsigned int a_u4Command,
unsigned long a_u4Param)
{
long i4RetValue = 0;
switch (a_u4Command) {
case AFIOC_G_MOTORINFO:
i4RetValue = getAFInfo((__user struct stAF_MotorInfo *)
(a_u4Param));
break;
case AFIOC_T_MOVETO:
i4RetValue = moveAF(a_u4Param);
break;
case AFIOC_T_SETINFPOS:
i4RetValue = setAFInf(a_u4Param);
break;
case AFIOC_T_SETMACROPOS:
i4RetValue = setAFMacro(a_u4Param);
break;
default:
LOG_INF("No CMD\n");
i4RetValue = -EPERM;
break;
}
return i4RetValue;
}
/* Main jobs: */
/* 1.Deallocate anything that "open" allocated in private_data. */
/* 2.Shut down the device on last close. */
/* 3.Only called once on last time. */
/* Q1 : Try release multiple times. */
int DW9839AF_Release(struct inode *a_pstInode, struct file *a_pstFile)
{
LOG_INF("Start\n");
if (*g_pAF_Opened == 2) {
LOG_INF("Wait\n");
s4AF_WriteReg(0x02, 0x20);
msleep(20);
}
if (*g_pAF_Opened) {
LOG_INF("Free\n");
spin_lock(g_pAF_SpinLock);
*g_pAF_Opened = 0;
spin_unlock(g_pAF_SpinLock);
}
LOG_INF("End\n");
return 0;
}
int DW9839AF_PowerDown(struct i2c_client *pstAF_I2Cclient,
int *pAF_Opened)
{
g_pstAF_I2Cclient = pstAF_I2Cclient;
g_pAF_Opened = pAF_Opened;
LOG_INF("+\n");
if (*g_pAF_Opened == 0) {
unsigned short data = 0;
int cnt = 0;
while (1) {
data = 0;
s4AF_WriteReg(0x02, 0x20);
s4AF_ReadReg(0x02, &data);
LOG_INF("Addr : 0x02 , Data : %x\n", data);
if (data == 0x20 || cnt == 1)
break;
cnt++;
}
} else if (*g_pAF_Opened == 2) {
*g_pAF_Opened = 1;
LOG_INF("reopen driver init\n");
}
LOG_INF("-\n");
return 0;
}
int DW9839AF_SetI2Cclient(struct i2c_client *pstAF_I2Cclient, spinlock_t
*pAF_SpinLock, int *pAF_Opened)
{
int ret = 0;
unsigned short InitPos = 0, InitPosM = 0, InitPosL = 0;
g_pstAF_I2Cclient = pstAF_I2Cclient;
g_pAF_SpinLock = pAF_SpinLock;
g_pAF_Opened = pAF_Opened;
#if defined(CONFIG_MACH_MT6771)
g_ACKErrorCnt = 5;
#else
g_ACKErrorCnt = 100;
#endif
if (*g_pAF_Opened == 1) {
if (initdrv() == 1) {
spin_lock(g_pAF_SpinLock);
*g_pAF_Opened = 2;
spin_unlock(g_pAF_SpinLock);
} else {
LOG_INF("InitDrv Fail!! I2C error occurred");
}
s4AF_ReadReg(0x0, &InitPosM);
ret = s4AF_ReadReg(0x1, &InitPosL);
InitPos = ((InitPosM & 0xFF) << 2) + ((InitPosL >> 6) & 0x3);
if (ret == 0) {
LOG_INF("Init Pos %6d\n", InitPos);
spin_lock(g_pAF_SpinLock);
g_u4CurrPosition = (unsigned long)InitPos;
spin_unlock(g_pAF_SpinLock);
} else {
spin_lock(g_pAF_SpinLock);
g_u4CurrPosition = 0;
spin_unlock(g_pAF_SpinLock);
}
}
return 1;
}
int DW9839AF_GetFileName(unsigned char *pFileName)
{
#if SUPPORT_GETTING_LENS_FOLDER_NAME
char FilePath[256];
char *FileString;
sprintf(FilePath, "%s", __FILE__);
FileString = strrchr(FilePath, '/');
*FileString = '\0';
FileString = (strrchr(FilePath, '/') + 1);
strncpy(pFileName, FileString, AF_MOTOR_NAME);
LOG_INF("FileName : %s\n", pFileName);
#else
pFileName[0] = '\0';
#endif
return 1;
}
@@ -0,0 +1,7 @@
#
# Makefile for misc devices that really don't fit anywhere else.
#
obj-y += DW9839AF.o
@@ -0,0 +1,229 @@
// SPDX-License-Identifier: GPL-2.0
/*
* Copyright (c) 2019 MediaTek Inc.
*/
/*
* FM50AF voice coil motor driver
*
*
*/
#include <linux/delay.h>
#include <linux/fs.h>
#include <linux/i2c.h>
#include <linux/uaccess.h>
#include "lens_info.h"
#define AF_DRVNAME "FM50AF_DRV"
#define AF_I2C_SLAVE_ADDR 0x18
#define AF_DEBUG
#ifdef AF_DEBUG
#define LOG_INF(format, args...) \
pr_debug(AF_DRVNAME " [%s] " format, __func__, ##args)
#else
#define LOG_INF(format, args...)
#endif
static struct i2c_client *g_pstAF_I2Cclient;
static int *g_pAF_Opened;
static spinlock_t *g_pAF_SpinLock;
static unsigned long g_u4AF_INF;
static unsigned long g_u4AF_MACRO = 1023;
static unsigned long g_u4CurrPosition;
static int g_SR = 3;
static int s4AF_WriteReg(u16 a_u2Data)
{
int i4RetValue = 0;
char puSendCmd[2] = {(char)(a_u2Data >> 4),
(char)(((a_u2Data & 0xF) << 4) + g_SR)};
g_pstAF_I2Cclient->addr = AF_I2C_SLAVE_ADDR;
g_pstAF_I2Cclient->addr = g_pstAF_I2Cclient->addr >> 1;
i4RetValue = i2c_master_send(g_pstAF_I2Cclient, puSendCmd, 2);
if (i4RetValue < 0) {
LOG_INF("I2C send failed!!\n");
return -1;
}
return 0;
}
static inline int getAFInfo(__user struct stAF_MotorInfo *pstMotorInfo)
{
struct stAF_MotorInfo stMotorInfo;
stMotorInfo.u4MacroPosition = g_u4AF_MACRO;
stMotorInfo.u4InfPosition = g_u4AF_INF;
stMotorInfo.u4CurrentPosition = g_u4CurrPosition;
stMotorInfo.bIsSupportSR = 1;
stMotorInfo.bIsMotorMoving = 1;
if (*g_pAF_Opened >= 1)
stMotorInfo.bIsMotorOpen = 1;
else
stMotorInfo.bIsMotorOpen = 0;
if (copy_to_user(pstMotorInfo, &stMotorInfo,
sizeof(struct stAF_MotorInfo)))
LOG_INF("copy to user failed when getting motor information\n");
return 0;
}
/* initAF include driver initialization and standby mode */
static int initAF(void)
{
LOG_INF("+\n");
if (*g_pAF_Opened == 1) {
g_SR = 3;
spin_lock(g_pAF_SpinLock);
*g_pAF_Opened = 2;
spin_unlock(g_pAF_SpinLock);
}
LOG_INF("-\n");
return 0;
}
/* moveAF only use to control moving the motor */
static inline int moveAF(unsigned long a_u4Position)
{
int ret = 0;
if (s4AF_WriteReg((unsigned short)a_u4Position) == 0) {
g_u4CurrPosition = a_u4Position;
ret = 0;
} else {
LOG_INF("set I2C failed when moving the motor\n");
ret = -1;
}
return ret;
}
static inline int setAFInf(unsigned long a_u4Position)
{
spin_lock(g_pAF_SpinLock);
g_u4AF_INF = a_u4Position;
spin_unlock(g_pAF_SpinLock);
return 0;
}
static inline int setAFMacro(unsigned long a_u4Position)
{
spin_lock(g_pAF_SpinLock);
g_u4AF_MACRO = a_u4Position;
spin_unlock(g_pAF_SpinLock);
return 0;
}
/* ////////////////////////////////////////////////////////////// */
long FM50AF_Ioctl(struct file *a_pstFile, unsigned int a_u4Command,
unsigned long a_u4Param)
{
long i4RetValue = 0;
switch (a_u4Command) {
case AFIOC_G_MOTORINFO:
i4RetValue =
getAFInfo((__user struct stAF_MotorInfo *)(a_u4Param));
break;
case AFIOC_T_MOVETO:
i4RetValue = moveAF(a_u4Param);
break;
case AFIOC_T_SETINFPOS:
i4RetValue = setAFInf(a_u4Param);
break;
case AFIOC_T_SETMACROPOS:
i4RetValue = setAFMacro(a_u4Param);
break;
default:
LOG_INF("No CMD\n");
i4RetValue = -EPERM;
break;
}
return i4RetValue;
}
/* Main jobs: */
/* 1.Deallocate anything that "open" allocated in private_data. */
/* 2.Shut down the device on last close. */
/* 3.Only called once on last time. */
/* Q1 : Try release multiple times. */
int FM50AF_Release(struct inode *a_pstInode, struct file *a_pstFile)
{
LOG_INF("Start\n");
if (*g_pAF_Opened == 2) {
LOG_INF("Wait\n");
g_SR = 5;
s4AF_WriteReg(200);
msleep(20);
s4AF_WriteReg(100);
msleep(20);
}
if (*g_pAF_Opened) {
LOG_INF("Free\n");
spin_lock(g_pAF_SpinLock);
*g_pAF_Opened = 0;
spin_unlock(g_pAF_SpinLock);
}
LOG_INF("End\n");
return 0;
}
int FM50AF_SetI2Cclient(struct i2c_client *pstAF_I2Cclient,
spinlock_t *pAF_SpinLock, int *pAF_Opened)
{
g_pstAF_I2Cclient = pstAF_I2Cclient;
g_pAF_SpinLock = pAF_SpinLock;
g_pAF_Opened = pAF_Opened;
initAF();
return 1;
}
int FM50AF_GetFileName(unsigned char *pFileName)
{
#if SUPPORT_GETTING_LENS_FOLDER_NAME
char FilePath[256];
char *FileString;
sprintf(FilePath, "%s", __FILE__);
FileString = strrchr(FilePath, '/');
*FileString = '\0';
FileString = (strrchr(FilePath, '/') + 1);
strncpy(pFileName, FileString, AF_MOTOR_NAME);
LOG_INF("FileName : %s\n", pFileName);
#else
pFileName[0] = '\0';
#endif
return 1;
}
@@ -0,0 +1,20 @@
#
# Copyright (C) 2015 MediaTek Inc.
#
# 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.
#
#
# Makefile for misc devices that really don't fit anywhere else.
#
obj-y += FM50AF.o
@@ -0,0 +1,258 @@
// SPDX-License-Identifier: GPL-2.0
/*
* Copyright (c) 2019 MediaTek Inc.
*/
/*
* FP5510E2AF voice coil motor driver
*
*
*/
#include <linux/delay.h>
#include <linux/fs.h>
#include <linux/i2c.h>
#include <linux/uaccess.h>
#include "lens_info.h"
#define AF_DRVNAME "FP5510E2AF_DRV"
#define AF_I2C_SLAVE_ADDR 0x18
#define AF_DEBUG
#ifdef AF_DEBUG
#define LOG_INF(format, args...) \
pr_info(AF_DRVNAME " [%s] " format, __func__, ##args)
#else
#define LOG_INF(format, args...)
#endif
static struct i2c_client *g_pstAF_I2Cclient;
static int *g_pAF_Opened;
static spinlock_t *g_pAF_SpinLock;
static unsigned long g_u4AF_INF;
static unsigned long g_u4AF_MACRO = 1023;
static unsigned long g_u4CurrPosition;
static int s4AF_WriteReg(u16 a_u2Data)
{
int i4RetValue = 0;
char puSendCmd[2] = {(char)(a_u2Data >> 4),
(char)((a_u2Data & 0xF) << 4)};
g_pstAF_I2Cclient->addr = AF_I2C_SLAVE_ADDR;
g_pstAF_I2Cclient->addr = g_pstAF_I2Cclient->addr >> 1;
i4RetValue = i2c_master_send(g_pstAF_I2Cclient, puSendCmd, 2);
if (i4RetValue < 0) {
LOG_INF("I2C send failed!!\n");
return -1;
}
return 0;
}
static inline int getAFInfo(__user struct stAF_MotorInfo *pstMotorInfo)
{
struct stAF_MotorInfo stMotorInfo;
stMotorInfo.u4MacroPosition = g_u4AF_MACRO;
stMotorInfo.u4InfPosition = g_u4AF_INF;
stMotorInfo.u4CurrentPosition = g_u4CurrPosition;
stMotorInfo.bIsSupportSR = 1;
stMotorInfo.bIsMotorMoving = 1;
if (*g_pAF_Opened >= 1)
stMotorInfo.bIsMotorOpen = 1;
else
stMotorInfo.bIsMotorOpen = 0;
if (copy_to_user(pstMotorInfo, &stMotorInfo,
sizeof(struct stAF_MotorInfo)))
LOG_INF("copy to user failed when getting motor information\n");
return 0;
}
/* initAF include driver initialization and standby mode */
static int initAF(void)
{
LOG_INF("+\n");
if (*g_pAF_Opened == 1) {
int i4RetValue;
char puSendCmd1[2] = {(char)(0x80), (char)(0x00)};
char puSendCmd2[2] = {(char)(0x00), (char)(0x00)};
char puSendCmd3[2] = {(char)(0xEC), (char)(0xA3)};
char puSendCmd4[2] = {(char)(0xA1), (char)(0x15)};
char puSendCmd5[2] = {(char)(0xF2), (char)(0x00)};
char puSendCmd6[2] = {(char)(0xDC), (char)(0x51)};
/* char puSendCmd7[2] = {(char)(0x3F), (char)(0xF0)}; */
g_pstAF_I2Cclient->addr = AF_I2C_SLAVE_ADDR;
g_pstAF_I2Cclient->addr = g_pstAF_I2Cclient->addr >> 1;
i4RetValue = i2c_master_send(g_pstAF_I2Cclient, puSendCmd1, 2);
if (i4RetValue < 0)
LOG_INF(" puSendCmd1 send failed.\n");
i4RetValue = i2c_master_send(g_pstAF_I2Cclient, puSendCmd2, 2);
if (i4RetValue < 0)
LOG_INF(" puSendCmd2 send failed.\n");
i4RetValue = i2c_master_send(g_pstAF_I2Cclient, puSendCmd3, 2);
if (i4RetValue < 0)
LOG_INF(" puSendCmd3 send failed.\n");
i4RetValue = i2c_master_send(g_pstAF_I2Cclient, puSendCmd4, 2);
if (i4RetValue < 0)
LOG_INF(" puSendCmd4 send failed.\n");
i4RetValue = i2c_master_send(g_pstAF_I2Cclient, puSendCmd5, 2);
if (i4RetValue < 0)
LOG_INF(" puSendCmd5 send failed.\n");
i4RetValue = i2c_master_send(g_pstAF_I2Cclient, puSendCmd6, 2);
if (i4RetValue < 0)
LOG_INF(" puSendCmd6 send failed.\n");
spin_lock(g_pAF_SpinLock);
*g_pAF_Opened = 2;
spin_unlock(g_pAF_SpinLock);
}
LOG_INF("-\n");
return 0;
}
/* moveAF only use to control moving the motor */
static inline int moveAF(unsigned long a_u4Position)
{
int ret = 0;
if (s4AF_WriteReg((unsigned short)a_u4Position) == 0) {
g_u4CurrPosition = a_u4Position;
ret = 0;
} else {
LOG_INF("set I2C failed when moving the motor\n");
ret = -1;
}
return ret;
}
static inline int setAFInf(unsigned long a_u4Position)
{
spin_lock(g_pAF_SpinLock);
g_u4AF_INF = a_u4Position;
spin_unlock(g_pAF_SpinLock);
return 0;
}
static inline int setAFMacro(unsigned long a_u4Position)
{
spin_lock(g_pAF_SpinLock);
g_u4AF_MACRO = a_u4Position;
spin_unlock(g_pAF_SpinLock);
return 0;
}
/* ////////////////////////////////////////////////////////////// */
long FP5510E2AF_Ioctl(struct file *a_pstFile, unsigned int a_u4Command,
unsigned long a_u4Param)
{
long i4RetValue = 0;
switch (a_u4Command) {
case AFIOC_G_MOTORINFO:
i4RetValue =
getAFInfo((__user struct stAF_MotorInfo *)(a_u4Param));
break;
case AFIOC_T_MOVETO:
i4RetValue = moveAF(a_u4Param);
break;
case AFIOC_T_SETINFPOS:
i4RetValue = setAFInf(a_u4Param);
break;
case AFIOC_T_SETMACROPOS:
i4RetValue = setAFMacro(a_u4Param);
break;
default:
LOG_INF("No CMD\n");
i4RetValue = -EPERM;
break;
}
return i4RetValue;
}
/* Main jobs: */
/* 1.Deallocate anything that "open" allocated in private_data. */
/* 2.Shut down the device on last close. */
/* 3.Only called once on last time. */
/* Q1 : Try release multiple times. */
int FP5510E2AF_Release(struct inode *a_pstInode, struct file *a_pstFile)
{
LOG_INF("Start\n");
if (*g_pAF_Opened == 2) {
LOG_INF("Wait\n");
s4AF_WriteReg(0x80); /* Power down mode */
}
if (*g_pAF_Opened) {
LOG_INF("Free\n");
spin_lock(g_pAF_SpinLock);
*g_pAF_Opened = 0;
spin_unlock(g_pAF_SpinLock);
}
LOG_INF("End\n");
return 0;
}
int FP5510E2AF_SetI2Cclient(struct i2c_client *pstAF_I2Cclient,
spinlock_t *pAF_SpinLock, int *pAF_Opened)
{
g_pstAF_I2Cclient = pstAF_I2Cclient;
g_pAF_SpinLock = pAF_SpinLock;
g_pAF_Opened = pAF_Opened;
initAF();
return 1;
}
int FP5510E2AF_GetFileName(unsigned char *pFileName)
{
#if SUPPORT_GETTING_LENS_FOLDER_NAME
char FilePath[256];
char *FileString;
sprintf(FilePath, "%s", __FILE__);
FileString = strrchr(FilePath, '/');
*FileString = '\0';
FileString = (strrchr(FilePath, '/') + 1);
strncpy(pFileName, FileString, AF_MOTOR_NAME);
LOG_INF("FileName : %s\n", pFileName);
#else
pFileName[0] = '\0';
#endif
return 1;
}
@@ -0,0 +1,20 @@
#
# Copyright (C) 2015 MediaTek Inc.
#
# 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.
#
#
# Makefile for misc devices that really don't fit anywhere else.
#
obj-y += FP5510E2AF.o
@@ -0,0 +1,297 @@
// SPDX-License-Identifier: GPL-2.0
/*
* Copyright (c) 2019 MediaTek Inc.
*/
/*
* GT9764AF voice coil motor driver
*
*
*/
#include <linux/delay.h>
#include <linux/fs.h>
#include <linux/i2c.h>
#include <linux/time.h>
#include <linux/uaccess.h>
#include "lens_info.h"
#define AF_DRVNAME "GT9764AF_DRV"
#define AF_I2C_SLAVE_ADDR 0x18
#define AF_DEBUG
#ifdef AF_DEBUG
#define LOG_INF(format, args...) \
pr_info(AF_DRVNAME " [%s] " format, __func__, ##args)
#else
#define LOG_INF(format, args...)
#endif
static struct i2c_client *g_pstAF_I2Cclient;
static int *g_pAF_Opened;
static spinlock_t *g_pAF_SpinLock;
static unsigned long g_u4AF_INF;
static unsigned long g_u4AF_MACRO = 1023;
static unsigned long g_u4CurrPosition;
#define Min_Pos 0
#define Max_Pos 1023
static int s4AF_ReadReg(u8 a_uAddr, u8 *a_uData)
{
g_pstAF_I2Cclient->addr = (AF_I2C_SLAVE_ADDR) >> 1;
if (i2c_master_send(g_pstAF_I2Cclient, &a_uAddr, 1) < 0) {
LOG_INF("ReadI2C send failed!!\n");
return -1;
}
if (i2c_master_recv(g_pstAF_I2Cclient, a_uData, 1) < 0) {
LOG_INF("ReadI2C recv failed!!\n");
return -1;
}
/* LOG_INF("RDI2C 0x%x, 0x%x\n", a_uAddr, *a_uData); */
return 0;
}
static int s4AF_WriteReg(u8 a_uLength, u8 a_uAddr, u16 a_u2Data)
{
u8 puSendCmd[2] = {a_uAddr, (u8)(a_u2Data & 0xFF)};
u8 puSendCmd2[3] = {a_uAddr, (u8)((a_u2Data >> 8) & 0xFF),
(u8)(a_u2Data & 0xFF)};
g_pstAF_I2Cclient->addr = (AF_I2C_SLAVE_ADDR) >> 1;
/* LOG_INF("WRI2C 0x%04x, 0x%x\n", a_uAddr, a_u2Data); */
if (a_uLength == 0) {
if (i2c_master_send(g_pstAF_I2Cclient, puSendCmd, 2) < 0) {
LOG_INF("WriteI2C failed!!\n");
return -1;
}
} else if (a_uLength == 1) {
if (i2c_master_send(g_pstAF_I2Cclient, puSendCmd2, 3) < 0) {
LOG_INF("WriteI2C 2 failed!!\n");
return -1;
}
}
return 0;
}
static int setPosition(unsigned short UsPosition)
{
unsigned short TarPos;
unsigned char UcPosH;
unsigned char UcPosL;
unsigned int i4RetValue = 0;
TarPos = UsPosition;
/* LOG_INF("DAC(%04d) -> %03x\n", UsPosition, TarPos); */
UcPosH = (unsigned char)((TarPos >> 8) & 0x03);
UcPosL = (unsigned char)(TarPos & 0x00FF);
i4RetValue = s4AF_WriteReg(0, 0x03, UcPosH);//VCM_MSB
if (i4RetValue != 0)
return -1;
i4RetValue = s4AF_WriteReg(0, 0x04, UcPosL); //VCM_LSB
return i4RetValue;
}
static inline int getAFInfo(__user struct stAF_MotorInfo *pstMotorInfo)
{
struct stAF_MotorInfo stMotorInfo;
stMotorInfo.u4MacroPosition = g_u4AF_MACRO;
stMotorInfo.u4InfPosition = g_u4AF_INF;
stMotorInfo.u4CurrentPosition = g_u4CurrPosition;
stMotorInfo.bIsSupportSR = 1;
stMotorInfo.bIsMotorMoving = 1;
if (*g_pAF_Opened >= 1)
stMotorInfo.bIsMotorOpen = 1;
else
stMotorInfo.bIsMotorOpen = 0;
if (copy_to_user(pstMotorInfo, &stMotorInfo,
sizeof(struct stAF_MotorInfo)))
LOG_INF("copy to user failed when getting motor information\n");
return 0;
}
/* initAF include driver initialization and standby mode */
static int initAF(void)
{
LOG_INF("+\n");
//wait driver ic ready
mdelay(5);
if (*g_pAF_Opened == 1) {
//int i4RetValue = 0;
int ret = 0;
//int cnt = 0;
unsigned char Temp;
s4AF_ReadReg(0x00, &Temp); //ic info
LOG_INF("Check HW version: 0x00 is %x\n", Temp);
ret = s4AF_WriteReg(0, 0x02, 0x00); //CONTROL
spin_lock(g_pAF_SpinLock);
*g_pAF_Opened = 2;
spin_unlock(g_pAF_SpinLock);
}
LOG_INF("-\n");
return 0;
}
/* moveAF only use to control moving the motor */
static inline int moveAF(unsigned long a_u4Position)
{
int ret = 0;
if (setPosition((unsigned short)a_u4Position) == 0) {
g_u4CurrPosition = a_u4Position;
ret = 0;
} else {
LOG_INF("set I2C failed when moving the motor\n");
ret = -1;
}
return ret;
}
static inline int setAFInf(unsigned long a_u4Position)
{
spin_lock(g_pAF_SpinLock);
g_u4AF_INF = a_u4Position;
spin_unlock(g_pAF_SpinLock);
return 0;
}
static inline int setAFMacro(unsigned long a_u4Position)
{
spin_lock(g_pAF_SpinLock);
g_u4AF_MACRO = a_u4Position;
spin_unlock(g_pAF_SpinLock);
return 0;
}
/* ////////////////////////////////////////////////////////////// */
long GT9764AF_Ioctl(struct file *a_pstFile, unsigned int a_u4Command,
unsigned long a_u4Param)
{
long i4RetValue = 0;
switch (a_u4Command) {
case AFIOC_G_MOTORINFO:
i4RetValue =
getAFInfo((__user struct stAF_MotorInfo *)(a_u4Param));
break;
case AFIOC_T_MOVETO:
i4RetValue = moveAF(a_u4Param);
break;
case AFIOC_T_SETINFPOS:
i4RetValue = setAFInf(a_u4Param);
break;
case AFIOC_T_SETMACROPOS:
i4RetValue = setAFMacro(a_u4Param);
break;
default:
LOG_INF("No CMD\n");
i4RetValue = -EPERM;
break;
}
return i4RetValue;
}
/* Main jobs: */
/* 1.Deallocate anything that "open" allocated in private_data. */
/* 2.Shut down the device on last close. */
/* 3.Only called once on last time. */
/* Q1 : Try release multiple times. */
int GT9764AF_Release(struct inode *a_pstInode, struct file *a_pstFile)
{
int Ret = 0;
LOG_INF("Start\n");
if (*g_pAF_Opened) {
LOG_INF("Free\n");
spin_lock(g_pAF_SpinLock);
*g_pAF_Opened = 0;
spin_unlock(g_pAF_SpinLock);
}
LOG_INF("End\n");
return Ret;
}
int GT9764AF_PowerDown(struct i2c_client *pstAF_I2Cclient,
int *pAF_Opened)
{
g_pstAF_I2Cclient = pstAF_I2Cclient;
g_pAF_Opened = pAF_Opened;
LOG_INF("+\n");
if (*g_pAF_Opened == 0) {
LOG_INF("Set power donw +\n");
LOG_INF("Set power donw -\n");
}
LOG_INF("-\n");
return 0;
}
int GT9764AF_SetI2Cclient(struct i2c_client *pstAF_I2Cclient,
spinlock_t *pAF_SpinLock, int *pAF_Opened)
{
g_pstAF_I2Cclient = pstAF_I2Cclient;
g_pAF_SpinLock = pAF_SpinLock;
g_pAF_Opened = pAF_Opened;
initAF();
return 1;
}
int GT9764AF_GetFileName(unsigned char *pFileName)
{
#if SUPPORT_GETTING_LENS_FOLDER_NAME
char FilePath[256];
char *FileString;
sprintf(FilePath, "%s", __FILE__);
FileString = strrchr(FilePath, '/');
*FileString = '\0';
FileString = (strrchr(FilePath, '/') + 1);
strncpy(pFileName, FileString, AF_MOTOR_NAME);
LOG_INF("FileName : %s\n", pFileName);
#else
pFileName[0] = '\0';
#endif
return 1;
}
@@ -0,0 +1,19 @@
#
# Copyright (C) 2015 MediaTek Inc.
#
# 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.
#
#
# Makefile for misc devices that really don't fit anywhere else.
#
obj-y += GT9764AF.o
@@ -0,0 +1,292 @@
// SPDX-License-Identifier: GPL-2.0
/*
* Copyright (c) 2019 MediaTek Inc.
*/
#include <linux/i2c.h>
#include <linux/delay.h>
#include <linux/uaccess.h>
#include <linux/fs.h>
#include "lens_info.h"
#define AF_DRVNAME "GT9768AF_DRV"
#define AF_I2C_SLAVE_ADDR 0x18 //1C
#define AF_DEBUG
#ifdef AF_DEBUG
#define LOG_INF(format, args...) pr_debug(AF_DRVNAME " [%s] " format, __func__, ##args)
#else
#define LOG_INF(format, args...)
#endif
/* if use ISRC mode, should modify variables in init_setting */
static struct i2c_client *g_pstAF_I2Cclient;
static int *g_pAF_Opened;
static spinlock_t *g_pAF_SpinLock;
static unsigned long g_u4AF_INF;
static unsigned long g_u4AF_MACRO = 1023;
static unsigned long g_u4CurrPosition;
#define Min_Pos 0
#define Max_Pos 1023
static int s4AF_ReadReg(u8 a_uAddr, u8 *a_uData)
{
g_pstAF_I2Cclient->addr = (AF_I2C_SLAVE_ADDR) >> 1;
if (i2c_master_send(g_pstAF_I2Cclient, &a_uAddr, 1) < 0) {
LOG_INF("ReadI2C send failed!!\n");
return -1;
}
if (i2c_master_recv(g_pstAF_I2Cclient, a_uData, 1) < 0) {
LOG_INF("ReadI2C recv failed!!\n");
return -1;
}
/* LOG_INF("RDI2C 0x%x, 0x%x\n", a_uAddr, *a_uData); */
return 0;
}
static int s4AF_WriteReg(u8 a_uLength, u8 a_uAddr, u16 a_u2Data)
{
u8 puSendCmd[2] = {a_uAddr, (u8)(a_u2Data & 0xFF)};
u8 puSendCmd2[3] = {a_uAddr, (u8)((a_u2Data >> 8) & 0xFF),
(u8)(a_u2Data & 0xFF)};
g_pstAF_I2Cclient->addr = (AF_I2C_SLAVE_ADDR) >> 1;
/* LOG_INF("WRI2C 0x%04x, 0x%x\n", a_uAddr, a_u2Data); */
if (a_uLength == 0) {
if (i2c_master_send(g_pstAF_I2Cclient, puSendCmd, 2) < 0) {
LOG_INF("WriteI2C failed!!\n");
return -1;
}
} else if (a_uLength == 1) {
if (i2c_master_send(g_pstAF_I2Cclient, puSendCmd2, 3) < 0) {
LOG_INF("WriteI2C 2 failed!!\n");
return -1;
}
}
return 0;
}
static int setPosition(unsigned short UsPosition)
{
unsigned short TarPos;
unsigned char UcPosH;
unsigned char UcPosL;
unsigned int i4RetValue = 0;
TarPos = UsPosition;
/* LOG_INF("DAC(%04d) -> %03x\n", UsPosition, TarPos); */
UcPosH = (unsigned char)((TarPos >> 8) & 0x03);
UcPosL = (unsigned char)(TarPos & 0x00FF);
i4RetValue = s4AF_WriteReg(0, 0x03, UcPosH);//VCM_MSB
if (i4RetValue != 0)
return -1;
i4RetValue = s4AF_WriteReg(0, 0x04, UcPosL); //VCM_LSB
return i4RetValue;
}
static inline int getAFInfo(__user struct stAF_MotorInfo *pstMotorInfo)
{
struct stAF_MotorInfo stMotorInfo;
stMotorInfo.u4MacroPosition = g_u4AF_MACRO;
stMotorInfo.u4InfPosition = g_u4AF_INF;
stMotorInfo.u4CurrentPosition = g_u4CurrPosition;
stMotorInfo.bIsSupportSR = 1;
stMotorInfo.bIsMotorMoving = 1;
if (*g_pAF_Opened >= 1)
stMotorInfo.bIsMotorOpen = 1;
else
stMotorInfo.bIsMotorOpen = 0;
if (copy_to_user(pstMotorInfo, &stMotorInfo,
sizeof(struct stAF_MotorInfo)))
LOG_INF("copy to user failed when getting motor information\n");
return 0;
}
/* initAF include driver initialization and standby mode */
static int initAF(void)
{
LOG_INF("+\n");
//wait driver ic ready
mdelay(5);
if (*g_pAF_Opened == 1) {
//int i4RetValue = 0;
int ret = 0;
//int cnt = 0;
unsigned char Temp;
s4AF_ReadReg(0x00, &Temp); //ic info
LOG_INF("Check HW version: 0x00 is %x\n", Temp);
ret = s4AF_WriteReg(0, 0x02, 0x00); //CONTROL
spin_lock(g_pAF_SpinLock);
*g_pAF_Opened = 2;
spin_unlock(g_pAF_SpinLock);
}
LOG_INF("-\n");
return 0;
}
/* moveAF only use to control moving the motor */
static inline int moveAF(unsigned long a_u4Position)
{
int ret = 0;
if (setPosition((unsigned short)a_u4Position) == 0) {
g_u4CurrPosition = a_u4Position;
ret = 0;
} else {
LOG_INF("set I2C failed when moving the motor\n");
ret = -1;
}
return ret;
}
static inline int setAFInf(unsigned long a_u4Position)
{
spin_lock(g_pAF_SpinLock);
g_u4AF_INF = a_u4Position;
spin_unlock(g_pAF_SpinLock);
return 0;
}
static inline int setAFMacro(unsigned long a_u4Position)
{
spin_lock(g_pAF_SpinLock);
g_u4AF_MACRO = a_u4Position;
spin_unlock(g_pAF_SpinLock);
return 0;
}
/* ////////////////////////////////////////////////////////////// */
long GT9768AF_Ioctl(struct file *a_pstFile, unsigned int a_u4Command,
unsigned long a_u4Param)
{
long i4RetValue = 0;
switch (a_u4Command) {
case AFIOC_G_MOTORINFO:
i4RetValue =
getAFInfo((__user struct stAF_MotorInfo *)(a_u4Param));
break;
case AFIOC_T_MOVETO:
i4RetValue = moveAF(a_u4Param);
break;
case AFIOC_T_SETINFPOS:
i4RetValue = setAFInf(a_u4Param);
break;
case AFIOC_T_SETMACROPOS:
i4RetValue = setAFMacro(a_u4Param);
break;
default:
LOG_INF("No CMD\n");
i4RetValue = -EPERM;
break;
}
return i4RetValue;
}
/* Main jobs: */
/* 1.Deallocate anything that "open" allocated in private_data. */
/* 2.Shut down the device on last close. */
/* 3.Only called once on last time. */
/* Q1 : Try release multiple times. */
int GT9768AF_Release(struct inode *a_pstInode, struct file *a_pstFile)
{
int Ret = 0;
LOG_INF("Start\n");
if (*g_pAF_Opened) {
LOG_INF("Free\n");
spin_lock(g_pAF_SpinLock);
*g_pAF_Opened = 0;
spin_unlock(g_pAF_SpinLock);
}
LOG_INF("End\n");
return Ret;
}
int GT9768AF_PowerDown(struct i2c_client *pstAF_I2Cclient,
int *pAF_Opened)
{
g_pstAF_I2Cclient = pstAF_I2Cclient;
g_pAF_Opened = pAF_Opened;
LOG_INF("+\n");
if (*g_pAF_Opened == 0) {
LOG_INF("Set power donw +\n");
LOG_INF("Set power donw -\n");
}
LOG_INF("-\n");
return 0;
}
int GT9768AF_SetI2Cclient(struct i2c_client *pstAF_I2Cclient,
spinlock_t *pAF_SpinLock, int *pAF_Opened)
{
g_pstAF_I2Cclient = pstAF_I2Cclient;
g_pAF_SpinLock = pAF_SpinLock;
g_pAF_Opened = pAF_Opened;
initAF();
return 1;
}
int GT9768AF_GetFileName_Main(unsigned char *pFileName)
{
#if SUPPORT_GETTING_LENS_FOLDER_NAME
char FilePath[256];
char *FileString;
sprintf(FilePath, "%s", __FILE__);
FileString = strrchr(FilePath, '/');
*FileString = '\0';
FileString = (strrchr(FilePath, '/') + 1);
strncpy(pFileName, FileString, AF_MOTOR_NAME);
LOG_INF("FileName : %s\n", pFileName);
#else
pFileName[0] = '\0';
#endif
return 1;
}
@@ -0,0 +1,18 @@
#
# Copyright (C) 2015 MediaTek Inc.
#
# 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.
#
#
# Makefile for misc devices that really don't fit anywhere else.
#
obj-y += GT9768AF.o
@@ -0,0 +1,290 @@
// SPDX-License-Identifier: GPL-2.0
/*
* Copyright (c) 2019 MediaTek Inc.
*/
/*
* GT9772AF voice coil motor driver
*
*
*/
#include <linux/delay.h>
#include <linux/fs.h>
#include <linux/i2c.h>
#include <linux/time.h>
#include <linux/uaccess.h>
#include "lens_info.h"
#define AF_DRVNAME "GT9772AF_DRV"
#define AF_I2C_SLAVE_ADDR 0x18
#define AF_DEBUG
#ifdef AF_DEBUG
#define LOG_INF(format, args...) \
pr_info(AF_DRVNAME " [%s] " format, __func__, ##args)
#else
#define LOG_INF(format, args...)
#endif
static struct i2c_client *g_pstAF_I2Cclient;
static int *g_pAF_Opened;
static spinlock_t *g_pAF_SpinLock;
static unsigned long g_u4AF_INF;
static unsigned long g_u4AF_MACRO = 1023;
static unsigned long g_u4CurrPosition;
#define Min_Pos 0
#define Max_Pos 1023
static int s4AF_ReadReg(u8 a_uAddr, u8 *a_uData)
{
g_pstAF_I2Cclient->addr = (AF_I2C_SLAVE_ADDR) >> 1;
if (i2c_master_send(g_pstAF_I2Cclient, &a_uAddr, 1) < 0) {
LOG_INF("ReadI2C send failed!!\n");
return -1;
}
if (i2c_master_recv(g_pstAF_I2Cclient, a_uData, 1) < 0) {
LOG_INF("ReadI2C recv failed!!\n");
return -1;
}
return 0;
}
static int s4AF_WriteReg(u8 a_uLength, u8 a_uAddr, u16 a_u2Data)
{
u8 puSendCmd[2] = {a_uAddr, (u8)(a_u2Data & 0xFF)};
u8 puSendCmd2[3] = {a_uAddr, (u8)((a_u2Data >> 8) & 0xFF),
(u8)(a_u2Data & 0xFF)};
g_pstAF_I2Cclient->addr = (AF_I2C_SLAVE_ADDR) >> 1;
if (a_uLength == 0) {
if (i2c_master_send(g_pstAF_I2Cclient, puSendCmd, 2) < 0) {
LOG_INF("WriteI2C failed!!\n");
return -1;
}
} else if (a_uLength == 1) {
if (i2c_master_send(g_pstAF_I2Cclient, puSendCmd2, 3) < 0) {
LOG_INF("WriteI2C 2 failed!!\n");
return -1;
}
}
return 0;
}
static int setPosition(unsigned short UsPosition)
{
unsigned short TarPos;
unsigned char UcPosH;
unsigned char UcPosL;
unsigned int i4RetValue = 0;
TarPos = UsPosition;
UcPosH = (unsigned char)((TarPos >> 8) & 0x03);
UcPosL = (unsigned char)(TarPos & 0x00FF);
i4RetValue = s4AF_WriteReg(0, 0x03, UcPosH);//VCM_MSB
if (i4RetValue != 0)
return -1;
i4RetValue = s4AF_WriteReg(0, 0x04, UcPosL); //VCM_LSB
return i4RetValue;
}
static inline int getAFInfo(__user struct stAF_MotorInfo *pstMotorInfo)
{
struct stAF_MotorInfo stMotorInfo;
stMotorInfo.u4MacroPosition = g_u4AF_MACRO;
stMotorInfo.u4InfPosition = g_u4AF_INF;
stMotorInfo.u4CurrentPosition = g_u4CurrPosition;
stMotorInfo.bIsSupportSR = 1;
stMotorInfo.bIsMotorMoving = 1;
if (*g_pAF_Opened >= 1)
stMotorInfo.bIsMotorOpen = 1;
else
stMotorInfo.bIsMotorOpen = 0;
if (copy_to_user(pstMotorInfo, &stMotorInfo,
sizeof(struct stAF_MotorInfo)))
LOG_INF("copy to user failed when getting motor information\n");
return 0;
}
/* initAF include driver initialization and standby mode */
static int initAF(void)
{
if (*g_pAF_Opened == 1) {
int ret = 0;
unsigned char Temp;
s4AF_ReadReg(0x00, &Temp); //ic info
LOG_INF("GT Check HW version: %x\n", Temp); //should be 0xF2
ret = s4AF_WriteReg(0, 0xED, 0xAB); //advance mode
LOG_INF("Advance mode ret: %x\n", ret);
spin_lock(g_pAF_SpinLock);
*g_pAF_Opened = 2;
spin_unlock(g_pAF_SpinLock);
}
LOG_INF(" -\n");
return 0;
}
/* moveAF only use to control moving the motor */
static inline int moveAF(unsigned long a_u4Position)
{
int ret = 0;
if (setPosition((unsigned short)a_u4Position) == 0) {
g_u4CurrPosition = a_u4Position;
ret = 0;
} else {
LOG_INF("set I2C failed when moving the motor\n");
ret = -1;
}
return ret;
}
static inline int setAFInf(unsigned long a_u4Position)
{
spin_lock(g_pAF_SpinLock);
g_u4AF_INF = a_u4Position;
spin_unlock(g_pAF_SpinLock);
return 0;
}
static inline int setAFMacro(unsigned long a_u4Position)
{
spin_lock(g_pAF_SpinLock);
g_u4AF_MACRO = a_u4Position;
spin_unlock(g_pAF_SpinLock);
return 0;
}
/* ////////////////////////////////////////////////////////////// */
long GT9772AF_Ioctl(struct file *a_pstFile, unsigned int a_u4Command,
unsigned long a_u4Param)
{
long i4RetValue = 0;
switch (a_u4Command) {
case AFIOC_G_MOTORINFO:
i4RetValue =
getAFInfo((__user struct stAF_MotorInfo *)(a_u4Param));
break;
case AFIOC_T_MOVETO:
i4RetValue = moveAF(a_u4Param);
break;
case AFIOC_T_SETINFPOS:
i4RetValue = setAFInf(a_u4Param);
break;
case AFIOC_T_SETMACROPOS:
i4RetValue = setAFMacro(a_u4Param);
break;
default:
LOG_INF("No CMD\n");
i4RetValue = -EPERM;
break;
}
return i4RetValue;
}
/* Main jobs: */
/* 1.Deallocate anything that "open" allocated in private_data. */
/* 2.Shut down the device on last close. */
/* 3.Only called once on last time. */
/* Q1 : Try release multiple times. */
int GT9772AF_Release(struct inode *a_pstInode, struct file *a_pstFile)
{
int Ret = 0;
LOG_INF("Start\n");
if (*g_pAF_Opened) {
LOG_INF("Free\n");
spin_lock(g_pAF_SpinLock);
*g_pAF_Opened = 0;
spin_unlock(g_pAF_SpinLock);
}
LOG_INF("End\n");
return Ret;
}
int GT9772AF_PowerDown(struct i2c_client *pstAF_I2Cclient,
int *pAF_Opened)
{
g_pstAF_I2Cclient = pstAF_I2Cclient;
g_pAF_Opened = pAF_Opened;
LOG_INF(" +\n");
if (*g_pAF_Opened == 0) {
LOG_INF("Set power donw +\n");
LOG_INF("Set power donw -\n");
}
LOG_INF(" -\n");
return 0;
}
int GT9772AF_SetI2Cclient(struct i2c_client *pstAF_I2Cclient,
spinlock_t *pAF_SpinLock, int *pAF_Opened)
{
g_pstAF_I2Cclient = pstAF_I2Cclient;
g_pAF_SpinLock = pAF_SpinLock;
g_pAF_Opened = pAF_Opened;
initAF();
return 1;
}
int GT9772AF_GetFileName(unsigned char *pFileName)
{
#if SUPPORT_GETTING_LENS_FOLDER_NAME
char FilePath[256];
char *FileString = NULL;
if (snprintf(FilePath, sizeof(FilePath), "%s", __FILE__) < 0)
return 0;
FileString = strrchr(FilePath, '/');
if (FileString == NULL)
return 0;
*FileString = '\0';
FileString = (strrchr(FilePath, '/') + 1);
strncpy(pFileName, FileString, AF_MOTOR_NAME);
LOG_INF("FileName : %s\n", pFileName);
#else
pFileName[0] = '\0';
#endif
return 1;
}
@@ -0,0 +1,19 @@
#
# Copyright (C) 2015 MediaTek Inc.
#
# 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.
#
#
# Makefile for misc devices that really don't fit anywhere else.
#
obj-y += GT9772AF.o
@@ -0,0 +1,352 @@
// SPDX-License-Identifier: GPL-2.0
/*
* Copyright (c) 2019 MediaTek Inc.
*/
/*
* LC898122AF voice coil motor driver
*
*
*/
#include "Ois.h"
#include "OisDef.h"
#include <linux/delay.h>
#include <linux/fs.h>
#include <linux/i2c.h>
#include <linux/uaccess.h>
#include "lens_info.h"
#define AF_DRVNAME "LC898122AF_DRV"
#define AF_I2C_SLAVE_ADDR 0x48
#define AF_DEBUG
#ifdef AF_DEBUG
#define LOG_INF(format, args...) \
pr_debug(AF_DRVNAME " [%s] " format, __func__, ##args)
#else
#define LOG_INF(format, args...)
#endif
static struct i2c_client *g_pstAF_I2Cclient;
static int *g_pAF_Opened;
static spinlock_t *g_pAF_SpinLock;
static unsigned long g_u4AF_INF;
static unsigned long g_u4AF_MACRO = 1023;
static unsigned long g_u4CurrPosition;
void RegWriteA_LC898122AF(unsigned short RegAddr, unsigned char RegData)
{
int i4RetValue = 0;
char puSendCmd[3] = {(char)((RegAddr >> 8) & 0xFF),
(char)(RegAddr & 0xFF), RegData};
/* LOG_INF("I2C w (%x %x)\n", RegAddr, RegData); */
g_pstAF_I2Cclient->addr = (AF_I2C_SLAVE_ADDR >> 1);
i4RetValue = i2c_master_send(g_pstAF_I2Cclient, puSendCmd, 3);
if (i4RetValue < 0) {
LOG_INF("I2C send failed!!\n");
return;
}
}
void RegReadA_LC898122AF(unsigned short RegAddr, unsigned char *RegData)
{
int i4RetValue = 0;
char pBuff[2] = {(char)(RegAddr >> 8), (char)(RegAddr & 0xFF)};
g_pstAF_I2Cclient->addr = (AF_I2C_SLAVE_ADDR >> 1);
i4RetValue = i2c_master_send(g_pstAF_I2Cclient, pBuff, 2);
if (i4RetValue < 0) {
LOG_INF("[CAMERA SENSOR] read I2C send failed!!\n");
return;
}
i4RetValue = i2c_master_recv(g_pstAF_I2Cclient, (u8 *)RegData, 1);
/* LOG_INF("I2C r (%x %x)\n", RegAddr, *RegData); */
if (i4RetValue != 1) {
LOG_INF("[CAMERA SENSOR] I2C read failed!!\n");
return;
}
}
void RamWriteA_LC898122AF(unsigned short RamAddr, unsigned short RamData)
{
int i4RetValue = 0;
char puSendCmd[4] = {
(char)((RamAddr >> 8) & 0xFF), (char)(RamAddr & 0xFF),
(char)((RamData >> 8) & 0xFF), (char)(RamData & 0xFF)};
/* LOG_INF("I2C w2 (%x %x)\n", RamAddr, RamData); */
g_pstAF_I2Cclient->addr = (AF_I2C_SLAVE_ADDR >> 1);
i4RetValue = i2c_master_send(g_pstAF_I2Cclient, puSendCmd, 4);
if (i4RetValue < 0) {
LOG_INF("I2C send failed!!\n");
return;
}
}
void RamReadA_LC898122AF(unsigned short RamAddr, void *ReadData)
{
int i4RetValue = 0;
char pBuff[2] = {(char)(RamAddr >> 8), (char)(RamAddr & 0xFF)};
unsigned short vRcvBuff = 0;
unsigned long *pRcvBuff;
pRcvBuff = (unsigned long *)ReadData;
/* g_pstAF_I2Cclient->addr = (AF_I2C_SLAVE_ADDR >> 1); */
i4RetValue = i2c_master_send(g_pstAF_I2Cclient, pBuff, 2);
if (i4RetValue < 0) {
LOG_INF("[CAMERA SENSOR] read I2C send failed!!\n");
return;
}
i4RetValue = i2c_master_recv(g_pstAF_I2Cclient, (u8 *)&vRcvBuff, 2);
if (i4RetValue != 2) {
LOG_INF("[CAMERA SENSOR] I2C read failed!!\n");
return;
}
*pRcvBuff = ((vRcvBuff & 0xFF) << 8) + ((vRcvBuff >> 8) & 0xFF);
/* LOG_INF("I2C r2 (%x %x)\n", RamAddr, (unsigned int)*pRcvBuff); */
}
void RamWrite32A_LC898122AF(unsigned short RamAddr, unsigned long RamData)
{
int i4RetValue = 0;
char puSendCmd[6] = {
(char)((RamAddr >> 8) & 0xFF), (char)(RamAddr & 0xFF),
(char)((RamData >> 24) & 0xFF), (char)((RamData >> 16) & 0xFF),
(char)((RamData >> 8) & 0xFF), (char)(RamData & 0xFF)};
/* LOG_INF("I2C w4 (%x %x)\n", RamAddr, (unsigned int)RamData); */
g_pstAF_I2Cclient->addr = (AF_I2C_SLAVE_ADDR >> 1);
i4RetValue = i2c_master_send(g_pstAF_I2Cclient, puSendCmd, 6);
if (i4RetValue < 0) {
LOG_INF("I2C send failed!!\n");
return;
}
}
void RamRead32A_LC898122AF(unsigned short RamAddr, void *ReadData)
{
int i4RetValue = 0;
char pBuff[2] = {(char)(RamAddr >> 8), (char)(RamAddr & 0xFF)};
unsigned long *pRcvBuff, vRcvBuff = 0;
pRcvBuff = (unsigned long *)ReadData;
g_pstAF_I2Cclient->addr = (AF_I2C_SLAVE_ADDR >> 1);
i4RetValue = i2c_master_send(g_pstAF_I2Cclient, pBuff, 2);
if (i4RetValue < 0) {
LOG_INF("[CAMERA SENSOR] read I2C send failed!!\n");
return;
}
i4RetValue = i2c_master_recv(g_pstAF_I2Cclient, (u8 *)&vRcvBuff, 4);
if (i4RetValue != 4) {
LOG_INF("[CAMERA SENSOR] I2C read failed!!\n");
return;
}
*pRcvBuff =
((vRcvBuff & 0xFF) << 24) + (((vRcvBuff >> 8) & 0xFF) << 16) +
(((vRcvBuff >> 16) & 0xFF) << 8) + (((vRcvBuff >> 24) & 0xFF));
/* LOG_INF("I2C r4 (%x %x)\n", RamAddr, (unsigned int)*pRcvBuff); */
}
void WitTim_LC898122AF(unsigned short UsWitTim)
{
msleep(UsWitTim);
}
void LC898prtvalue(unsigned short prtvalue)
{
LOG_INF("printvalue ======%x\n", prtvalue);
}
static inline int getAFInfo(__user struct stAF_MotorInfo *pstMotorInfo)
{
struct stAF_MotorInfo stMotorInfo;
stMotorInfo.u4MacroPosition = g_u4AF_MACRO;
stMotorInfo.u4InfPosition = g_u4AF_INF;
stMotorInfo.u4CurrentPosition = g_u4CurrPosition;
stMotorInfo.bIsSupportSR = 1;
stMotorInfo.bIsMotorMoving = 1;
if (*g_pAF_Opened >= 1)
stMotorInfo.bIsMotorOpen = 1;
else
stMotorInfo.bIsMotorOpen = 0;
if (copy_to_user(pstMotorInfo, &stMotorInfo,
sizeof(struct stAF_MotorInfo)))
LOG_INF("copy to user failed when getting motor information\n");
return 0;
}
/* initAF include driver initialization and standby mode */
static int initAF(void)
{
LOG_INF("+\n");
if (*g_pAF_Opened == 1) {
/* unsigned short addrotp; */
/* unsigned long dataotp = 0; */
IniSetAf();
IniSet();
RamAccFixMod(ON); /* 16bit Fix mode */
RamAccFixMod(OFF); /* 32bit Float mode */
RamWriteA_LC898122AF(TCODEH, 100); /* focus position */
RtnCen(0);
msleep(100);
SetPanTiltMode(ON);
msleep(20);
OisEna();
SetH1cMod(MOVMODE); /* movie mode */
/* SetH1cMod(0); //still mode */
spin_lock(g_pAF_SpinLock);
*g_pAF_Opened = 2;
spin_unlock(g_pAF_SpinLock);
}
LOG_INF("-\n");
return 0;
}
/* moveAF only use to control moving the motor */
static inline int moveAF(unsigned long a_u4Position)
{
RamWriteA_LC898122AF(TCODEH, a_u4Position);
g_u4CurrPosition = a_u4Position;
return 0;
}
static inline int setAFInf(unsigned long a_u4Position)
{
spin_lock(g_pAF_SpinLock);
g_u4AF_INF = a_u4Position;
spin_unlock(g_pAF_SpinLock);
return 0;
}
static inline int setAFMacro(unsigned long a_u4Position)
{
spin_lock(g_pAF_SpinLock);
g_u4AF_MACRO = a_u4Position;
spin_unlock(g_pAF_SpinLock);
return 0;
}
/* ////////////////////////////////////////////////////////////// */
long LC898122AF_Ioctl(struct file *a_pstFile, unsigned int a_u4Command,
unsigned long a_u4Param)
{
long i4RetValue = 0;
switch (a_u4Command) {
case AFIOC_G_MOTORINFO:
i4RetValue =
getAFInfo((__user struct stAF_MotorInfo *)(a_u4Param));
break;
case AFIOC_T_MOVETO:
i4RetValue = moveAF(a_u4Param);
break;
case AFIOC_T_SETINFPOS:
i4RetValue = setAFInf(a_u4Param);
break;
case AFIOC_T_SETMACROPOS:
i4RetValue = setAFMacro(a_u4Param);
break;
default:
LOG_INF("No CMD\n");
i4RetValue = -EPERM;
break;
}
return i4RetValue;
}
/* Main jobs: */
/* 1.Deallocate anything that "open" allocated in private_data. */
/* 2.Shut down the device on last close. */
/* 3.Only called once on last time. */
/* Q1 : Try release multiple times. */
int LC898122AF_Release(struct inode *a_pstInode, struct file *a_pstFile)
{
LOG_INF("Start\n");
if (*g_pAF_Opened == 2) {
LOG_INF("Wait\n");
RamWriteA_LC898122AF(TCODEH, 100); /* focus position */
msleep(20);
RamWriteA_LC898122AF(TCODEH, 50); /* focus position */
msleep(20);
RtnCen(0);
SrvCon(X_DIR, OFF);
SrvCon(Y_DIR, OFF);
}
if (*g_pAF_Opened) {
LOG_INF("Free\n");
spin_lock(g_pAF_SpinLock);
*g_pAF_Opened = 0;
spin_unlock(g_pAF_SpinLock);
}
LOG_INF("End\n");
return 0;
}
int LC898122AF_SetI2Cclient(struct i2c_client *pstAF_I2Cclient,
spinlock_t *pAF_SpinLock, int *pAF_Opened)
{
g_pstAF_I2Cclient = pstAF_I2Cclient;
g_pAF_SpinLock = pAF_SpinLock;
g_pAF_Opened = pAF_Opened;
initAF();
return 1;
}
int LC898122AF_GetFileName(unsigned char *pFileName)
{
#if SUPPORT_GETTING_LENS_FOLDER_NAME
char FilePath[256];
char *FileString;
sprintf(FilePath, "%s", __FILE__);
FileString = strrchr(FilePath, '/');
*FileString = '\0';
FileString = (strrchr(FilePath, '/') + 1);
strncpy(pFileName, FileString, AF_MOTOR_NAME);
LOG_INF("FileName : %s\n", pFileName);
#else
pFileName[0] = '\0';
#endif
return 1;
}
@@ -0,0 +1,20 @@
#
# Copyright (C) 2015 MediaTek Inc.
#
# 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.
#
#
# Makefile for misc devices that really don't fit anywhere else.
#
obj-y += LC898122AF.o OisCmd.o OisIni.o
@@ -0,0 +1,521 @@
/* SPDX-License-Identifier: GPL-2.0 */
/*
* Copyright (c) 2019 MediaTek Inc.
*/
/* Define According To Usage */
/**************** Select Gyro Sensor **************/
/* #define USE_3WIRE_DGYRO //for D-Gyro SPI interface */
#define USE_INVENSENSE /* INVENSENSE */
#ifdef USE_INVENSENSE
#define FS_SEL 3 /* �}32.8LSB/?/s */
#endif
/**************** Model name *****************/
#define MN_3BSD05P1
/**************** FW version *****************/
#ifdef MN_3BSD05P1
#define MDL_VER 0x06
#define FW_VER 0x03
#endif
/**************** Select Mode **************/
#define STANDBY_MODE /* STANDBY Mode */
#define GAIN_CONT /* Gain Control Mode */
#define PWM_BREAK /* PWM mode select (disable zero cross) */
#ifdef MN_3BSD05P1
#define ACTREG_10P2OHM /* Use 10.2ohm */
#endif
#define DEF_SET /* default value re-setting */
#define NEUTRAL_CENTER /* Upper Position Current 0mA Measurement */
#define H1COEF_CHANGER /* H1 coef lvl chage */
#define MONITOR_OFF /* default Monitor output */
/* Command Status */
#define EXE_END 0x02 /* Execute End (Adjust OK) */
#define EXE_HXADJ 0x06 /* Adjust NG : X Hall NG (Gain or Offset) */
#define EXE_HYADJ 0x0A /* Adjust NG : Y Hall NG (Gain or Offset) */
#define EXE_LXADJ 0x12 /* Adjust NG : X Loop NG (Gain) */
#define EXE_LYADJ 0x22 /* Adjust NG : Y Loop NG (Gain) */
#define EXE_GXADJ 0x42 /* Adjust NG : X Gyro NG (offset) */
#define EXE_GYADJ 0x82 /* Adjust NG : Y Gyro NG (offset) */
#define EXE_OCADJ 0x402 /* Adjust NG : OSC Clock NG */
#define EXE_ERR 0x99 /* Execute Error End */
/* Common Define */
#define SUCCESS 0x00 /* Success */
#define FAILURE 0x01 /* Failure */
#ifndef ON
#define ON 0x01 /* ON */
#define OFF 0x00 /* OFF */
#endif
#define SPC 0x02 /* Special Mode */
#define X_DIR 0x00 /* X Direction */
#define Y_DIR 0x01 /* Y Direction */
#define X2_DIR 0x10 /* X Direction */
#define Y2_DIR 0x11 /* Y Direction */
#define NOP_TIME 0.00004166F
#ifdef STANDBY_MODE
/* Standby mode */
#define STB1_ON 0x00 /* Standby1 ON */
#define STB1_OFF 0x01 /* Standby1 OFF */
#define STB2_ON 0x02 /* Standby2 ON */
#define STB2_OFF 0x03 /* Standby2 OFF */
#define STB3_ON 0x04 /* Standby3 ON */
#define STB3_OFF 0x05 /* Standby3 OFF */
#define STB4_ON 0x06 /* Standby4 ON for Digital Gyro Read */
#define STB4_OFF 0x07 /* Standby4 OFF */
#define STB2_OISON 0x08 /* Standby2 ON (only OIS) */
#define STB2_OISOFF 0x09 /* Standby2 OFF(only OIS) */
#define STB2_AFON 0x0A /* Standby2 ON (only AF) */
#define STB2_AFOFF 0x0B /* Standby2 OFF(only AF) */
#endif
/* OIS Adjust Parameter */
#define DAHLXO_INI 0x0000
#define DAHLXB_INI 0xE000
#define DAHLYO_INI 0x0000
#define DAHLYB_INI 0xE000
#define SXGAIN_INI 0x3000
#define SYGAIN_INI 0x3000
#define HXOFF0Z_INI 0x0000
#define HYOFF1Z_INI 0x0000
#ifdef ACTREG_6P5OHM /* MTM 9.5 Actuator *************************** */
#define BIAS_CUR_OIS 0x33 /* 2.0mA/2.0mA */
#define AMP_GAIN_X 0x05 /* x150 */
#define AMP_GAIN_Y 0x05 /* x150 */
/* OSC Init */
#define OSC_INI 0x2E /* VDD=2.8V */
/* AF Open para */
#define RWEXD1_L_AF 0x7FFF /* */
#define RWEXD2_L_AF 0x1094 /* */
#define RWEXD3_L_AF 0x72BA /* */
#define FSTCTIME_AF 0xED /* */
#define FSTMODE_AF 0x02 /* */
/* (0.3750114X^3+0.5937681X)*(0.3750114X^3+0.5937681X) 6.5ohm */
#define A3_IEXP3 0x3EC0017F
#define A1_IEXP1 0x3F180130
#endif
#ifdef ACTREG_10P2OHM /* MTM 10.2 Actuator *************************** */
#define BIAS_CUR_OIS 0x33 /* 2.0mA/2.0mA */
#define AMP_GAIN_X 0x05 /* x150 */
#define AMP_GAIN_Y 0x05 /* x150 */
/* OSC Init */
#define OSC_INI 0x2E /* VDD=2.8V */
/* AF Open para */
#define RWEXD1_L_AF 0x7FFF /* */
#define RWEXD2_L_AF 0x75FE /* */
#define RWEXD3_L_AF 0x7F32 /* */
#define FSTCTIME_AF 0xF1 /* */
#define FSTMODE_AF 0x00 /* */
/* (0.3750114X^3+0.55X)*(0.3750114X^3+0.55X) 10.2ohm */
#define A3_IEXP3 0x3EC0017F
#define A1_IEXP1 0x3F0CCCCD
#endif
#ifdef ACTREG_15OHM /* TDK 10.5 Actuator *************************** */
#define BIAS_CUR_OIS 0x22 /* 1.0mA/1.0mA */
#define AMP_GAIN_X 0x04 /* x100 */
#define AMP_GAIN_Y 0x04 /* x100 */
/* OSC Init */
#define OSC_INI 0x2E /* VDD=2.8V */
/* AF Open para */
#define RWEXD1_L_AF 0x7FFF /* */
#define RWEXD2_L_AF 0x5A00 /* */
#define RWEXD3_L_AF 0x7000 /* */
#define FSTCTIME_AF 0x5F /* */
#define FSTMODE_AF 0x00 /* */
/* (0.4531388X^3+0.4531388X)*(0.4531388X^3+0.4531388X) 15ohm */
#define A3_IEXP3 0x3EE801CF
#define A1_IEXP1 0x3EE801CF
#endif
/* AF adjust parameter */
#define DAHLZB_INI 0x9000
#define DAHLZO_INI 0x0000
#define BIAS_CUR_AF 0x00 /* 0.25mA */
#define AMP_GAIN_AF 0x00 /* x6 */
/* Digital Gyro offset Initial value */
#define DGYRO_OFST_XH 0x00
#define DGYRO_OFST_XL 0x00
#define DGYRO_OFST_YH 0x00
#define DGYRO_OFST_YL 0x00
#define SXGAIN_LOP 0x3000
#define SYGAIN_LOP 0x3000
#define TCODEH_ADJ 0x0000
#define GYRLMT1H 0x3DCCCCCD /* 0.1F */
#ifdef CORRECT_1DEG
#define GYRLMT3_S1 0x3F19999A /* 0.60F */
#define GYRLMT3_S2 0x3F19999A /* 0.60F */
#define GYRLMT4_S1 0x40400000 /* 3.0F */
#define GYRLMT4_S2 0x40400000 /* 3.0F */
#define GYRA12_HGH 0x40000000 /* 2.00F */
#define GYRA12_MID 0x3F800000 /* 1.0F */
#define GYRA34_HGH 0x3F000000 /* 0.5F */
#define GYRA34_MID 0x3DCCCCCD /* 0.1F */
#define GYRB12_HGH 0x3E4CCCCD /* 0.20F */
#define GYRB12_MID 0x3CA3D70A /* 0.02F */
#define GYRB34_HGH 0x3CA3D70A /* 0.02F */
#define GYRB34_MID 0x3C23D70A /* 0.001F */
#else
#define GYRLMT3_S1 0x3ECCCCCD /* 0.40F */
#define GYRLMT3_S2 0x3ECCCCCD /* 0.40F */
#define GYRLMT4_S1 0x40000000 /* 2.0F */
#define GYRLMT4_S2 0x40000000 /* 2.0F */
#define GYRA12_HGH 0x3FC00000 /* 1.50F */
#define GYRA12_MID 0x3F800000 /* 1.0F */
#define GYRA34_HGH 0x3F000000 /* 0.5F */
#define GYRA34_MID 0x3DCCCCCD /* 0.1F */
#define GYRB12_HGH 0x3E4CCCCD /* 0.20F */
#define GYRB12_MID 0x3CA3D70A /* 0.02F */
#define GYRB34_HGH 0x3CA3D70A /* 0.02F */
#define GYRB34_MID 0x3C23D70A /* 0.001F */
#endif
/* #define OPTCEN_X 0x0000 */
/* #define OPTCEN_Y 0x0000 */
#ifdef USE_INVENSENSE
#ifdef MN_3BSD05P1
#define SXQ_INI 0x3F800000
#define SYQ_INI 0xBF800000
#define GXGAIN_INI 0xBF147AE1
#define GYGAIN_INI 0xBF147AE1
#define GYROX_INI 0x45
#define GYROY_INI 0x43
#define GXHY_GYHX 1
#endif
#endif
/* Optical Center & Gyro Gain for Mode */
#define VAL_SET 0x00 /* Setting mode */
#define VAL_FIX 0x01 /* Fix Set value */
#define VAL_SPC 0x02 /* Special mode */
struct STFILREG {
unsigned short UsRegAdd;
unsigned char UcRegDat;
}; /* Register Data Table */
struct STFILRAM {
unsigned short UsRamAdd;
unsigned long UlRamDat;
}; /* Filter Coefficient Table */
struct STCMDTBL {
unsigned short Cmd;
unsigned int UiCmdStf;
void (*UcCmdPtr)(void);
};
/*** caution [little-endian] ***/
/* Word Data Union */
union UnWrdVal {
unsigned short UsWrdVal;
unsigned char UcWrkVal[2];
struct {
unsigned char UcLowVal;
unsigned char UcHigVal;
} StWrdVal;
};
union UnDwdVal {
unsigned long UlDwdVal;
unsigned short UsDwdVal[2];
struct {
unsigned short UsLowVal;
unsigned short UsHigVal;
} StDwdVal;
struct {
unsigned char UcRamVa0;
unsigned char UcRamVa1;
unsigned char UcRamVa2;
unsigned char UcRamVa3;
} StCdwVal;
};
/* Float Data Union */
union UnFltVal {
float SfFltVal;
unsigned long UlLngVal;
unsigned short UsDwdVal[2];
struct {
unsigned short UsLowVal;
unsigned short UsHigVal;
} StFltVal;
};
struct stAdjPar {
struct {
unsigned char UcAdjPhs; /* Hall Adjust Phase */
unsigned short
UsHlxCna; /* Hall Center Value after Hall Adjust */
unsigned short UsHlxMax; /* Hall Max Value */
unsigned short UsHlxMxa; /* Hall Max Value after Hall Adjust */
unsigned short UsHlxMin; /* Hall Min Value */
unsigned short UsHlxMna; /* Hall Min Value after Hall Adjust */
unsigned short UsHlxGan; /* Hall Gain Value */
unsigned short UsHlxOff; /* Hall Offset Value */
unsigned short UsAdxOff; /* Hall A/D Offset Value */
unsigned short UsHlxCen; /* Hall Center Value */
unsigned short
UsHlyCna; /* Hall Center Value after Hall Adjust */
unsigned short UsHlyMax; /* Hall Max Value */
unsigned short UsHlyMxa; /* Hall Max Value after Hall Adjust */
unsigned short UsHlyMin; /* Hall Min Value */
unsigned short UsHlyMna; /* Hall Min Value after Hall Adjust */
unsigned short UsHlyGan; /* Hall Gain Value */
unsigned short UsHlyOff; /* Hall Offset Value */
unsigned short UsAdyOff; /* Hall A/D Offset Value */
unsigned short UsHlyCen; /* Hall Center Value */
} StHalAdj;
struct {
unsigned short UsLxgVal; /* Loop Gain X */
unsigned short UsLygVal; /* Loop Gain Y */
unsigned short UsLxgSts; /* Loop Gain X Status */
unsigned short UsLygSts; /* Loop Gain Y Status */
} StLopGan;
struct {
unsigned short UsGxoVal; /* Gyro A/D Offset X */
unsigned short UsGyoVal; /* Gyro A/D Offset Y */
unsigned short UsGxoSts; /* Gyro Offset X Status */
unsigned short UsGyoSts; /* Gyro Offset Y Status */
} StGvcOff;
unsigned char UcOscVal; /* OSC value */
};
extern struct stAdjPar StAdjPar; /* Execute Command Parameter */
extern unsigned char UcOscAdjFlg; /* For Measure trigger */
#define MEASSTR 0x01
#define MEASCNT 0x08
#define MEASFIX 0x80
extern unsigned short UsCntXof; /* OPTICAL Center Xvalue */
extern unsigned short UsCntYof; /* OPTICAL Center Yvalue */
extern unsigned char UcPwmMod; /* PWM MODE */
#define PWMMOD_CVL 0x00 /* CVL PWM MODE */
#define PWMMOD_PWM 0x01 /* PWM MODE */
#define INIT_PWMMODE PWMMOD_CVL /* initial output mode */
extern unsigned char UcCvrCod; /* CverCode */
#define CVER122 0x93 /* LC898122 */
#define CVER122A 0xA1 /* LC898122A */
/* Prottype Declation */
extern void IniSet(void); /* Initial Top Function */
extern void IniSetAf(void); /* Initial Top Function */
extern void ClrGyr(unsigned short D1, unsigned char D2);
#define CLR_FRAM0 0x01
#define CLR_FRAM1 0x02
#define CLR_ALL_RAM 0x03
extern void BsyWit(unsigned short D1, unsigned char D2);
extern void MemClr(unsigned char *D1, unsigned short D2);
extern void GyOutSignal(void);
extern void GyOutSignalCont(void);
#ifdef STANDBY_MODE
extern void AccWit(unsigned char D1);
extern void SelectGySleep(unsigned char D1);
#endif
#ifdef GAIN_CONT
extern void AutoGainControlSw(unsigned char D1);
#endif
extern void DrvSw(unsigned char UcDrvSw);
extern void AfDrvSw(unsigned char UcDrvSw);
extern void RamAccFixMod(unsigned char D1);
extern void IniPtMovMod(unsigned char D1);
extern void ChkCvr(void); /* Check Function */
extern void SrvCon(unsigned char D1, unsigned char D2);
extern unsigned short TneRun(void);
extern unsigned char RtnCen(unsigned char D1);
extern void OisEna(void);
extern void OisEnaLin(void);
extern void TimPro(void);
extern void S2cPro(unsigned char D1);
#ifdef MN_3BSD05P1
#define DIFIL_S2 0x3F7FFE00
#endif
extern void SetSinWavePara(unsigned char D1,
unsigned char D2);
#define SINEWAVE 0
#define XHALWAVE 1
#define YHALWAVE 2
#define CIRCWAVE 255
extern unsigned char TneGvc(void); /* Gyro VC Offset Adjust */
extern void SetZsp(unsigned char D1);
extern void OptCen(unsigned char a, unsigned short b, unsigned short c);
extern void StbOnnN(unsigned char D1,
unsigned char D2);
#ifdef MODULE_CALIBRATION
extern unsigned char LopGan(unsigned char D1);
#endif
#ifdef STANDBY_MODE
extern void SetStandby(unsigned char D1);
#endif
#ifdef MODULE_CALIBRATION
extern unsigned short OscAdj(void); /* OSC clock adjustment */
#endif
#ifdef HALLADJ_HW
#ifdef MODULE_CALIBRATION
extern unsigned char LoopGainAdj(unsigned char D1);
#endif
extern unsigned char BiasOffsetAdj(unsigned char D1, unsigned char D2);
#endif
extern void GyrGan(unsigned char D1, unsigned long D2,
unsigned long D3);
extern void SetPanTiltMode(unsigned char D1);
#ifndef HALLADJ_HW
extern unsigned long TnePtp(unsigned char D1,
unsigned char D2);
#ifdef MN_3BSD05P1
#define HALL_H_VAL 0x3F800000 /* 1.0 */
#endif
extern unsigned char TneCen(unsigned char D1,
union UnDwdVal D2);
#define PTP_BEFORE 0
#define PTP_AFTER 1
#endif
#ifdef GAIN_CONT
extern unsigned char TriSts(void);
#endif
extern unsigned char DrvPwmSw(unsigned char D1);
#define Mlnp 0
#define Mpwm 1
#ifdef NEUTRAL_CENTER
extern unsigned char TneHvc(void);
#endif
extern void SetGcf(unsigned char D1);
extern unsigned long UlH1Coefval;
#ifdef H1COEF_CHANGER
extern unsigned char UcH1LvlMod; /* H1 level coef mode */
extern void SetH1cMod(unsigned char D1);
#define S2MODE 0x40
#define ACTMODE 0x80
#define MOVMODE 0xFF
#endif
extern unsigned short RdFwVr(void);
void RegWriteA_LC898122AF(unsigned short RegAddr, unsigned char RegData);
void RegReadA_LC898122AF(unsigned short RegAddr, unsigned char *RegData);
void RamWriteA_LC898122AF(unsigned short RamAddr, unsigned short RamData);
void RamReadA_LC898122AF(unsigned short RamAddr, void *ReadData);
void RamWrite32A_LC898122AF(unsigned short RamAddr, unsigned long RamData);
void RamRead32A_LC898122AF(unsigned short RamAddr, void *ReadData);
void WitTim_LC898122AF(unsigned short UsWitTim);
void LC898prtvalue(unsigned short value);
/* ************************** */
/* Local Function Prottype */
/* ************************** */
extern void IniClk(void); /* Clock Setting */
extern void IniIop(void); /* I/O Port Initial Setting */
extern void IniMon(void); /* Monitor & Other Initial Setting */
extern void IniSrv(void); /* Servo Register Initial Setting */
extern void IniGyr(void); /* Gyro Filter Register Initial Setting */
extern void IniFil(void); /* Gyro Filter Initial Parameter Setting */
extern void IniAdj(void); /* Adjust Fix Value Setting */
extern void IniCmd(void); /* Command Execute Process Initial */
extern void IniDgy(void); /* Digital Gyro Initial Setting */
extern void IniAf(void); /* Open AF Initial Setting */
extern void IniPtAve(void); /* Average setting */
/* ************************** */
/* Local Function Prottype */
/* ************************** */
extern void MesFil(unsigned char D1);
#ifdef MODULE_CALIBRATION
#ifndef HALLADJ_HW
extern void LopIni(unsigned char D1);
#endif
extern void LopPar(unsigned char D1);
#ifndef HALLADJ_HW
extern void LopSin(unsigned char D1,
unsigned char D2);
extern unsigned char LopAdj(unsigned char D1);
extern void LopMes(void);
#endif
#endif
#ifndef HALLADJ_HW
extern unsigned long GinMes(unsigned char D1);
#endif
extern void GyrCon(unsigned char D1);
extern short GenMes(unsigned short D1, unsigned char D2);
#ifndef HALLADJ_HW
extern unsigned long TneOff(union UnDwdVal D1,
unsigned char D2);
extern unsigned long TneBia(union UnDwdVal D1,
unsigned char D2);
#endif
extern void StbOnn(void); /* Servo ON Slope mode */
extern void SetSineWave(unsigned char D1, unsigned char D2);
extern void StartSineWave(void);
extern void StopSineWave(void);
extern void SetMeasFil(unsigned char D1);
extern void ClrMeasFil(void);
/* Read Fw Version Function */
File diff suppressed because it is too large. Load diff
File diff suppressed because it is too large. Load diff
@@ -0,0 +1,19 @@
/* SPDX-License-Identifier: GPL-2.0 */
/*
* Copyright (c) 2019 MediaTek Inc.
*/
/*Filter Calculator Version 4.02*/
/*the time and date : 2014/1/22 17:22:57*/
/*FC filename : LC898122_V000B_02*/
/*fs,23438Hz*/
/*LSI No.,LC898122*/
/*Comment,*/
/* 8bit */
extern const struct STFILREG CsFilReg[];
/* 32bit */
extern const struct STFILRAM CsFilRam[];
File diff suppressed because it is too large. Load diff
@@ -0,0 +1,398 @@
// SPDX-License-Identifier: GPL-2.0
/*
* Copyright (c) 2019 MediaTek Inc.
*/
/*
* LC898212AF voice coil motor driver
*
*
*/
#include <linux/delay.h>
#include <linux/fs.h>
#include <linux/i2c.h>
#include <linux/uaccess.h>
#include "lens_info.h"
#define AF_DRVNAME "LC898212AF_DRV"
#define AF_I2C_SLAVE_ADDR 0xE4
#define EEPROM_I2C_SLAVE_ADDR 0xA0
#define AF_DEBUG
#ifdef AF_DEBUG
#define LOG_INF(format, args...) \
pr_debug(AF_DRVNAME " [%s] " format, __func__, ##args)
#else
#define LOG_INF(format, args...)
#endif
static struct i2c_client *g_pstAF_I2Cclient;
static int *g_pAF_Opened;
static spinlock_t *g_pAF_SpinLock;
static unsigned long g_u4AF_INF;
static unsigned long g_u4AF_MACRO = 1023;
static unsigned long g_u4CurrPosition;
static int s4EEPROM_ReadReg(u16 addr, u16 *data)
{
u8 u8data = 0;
u8 pu_send_cmd[2] = {(u8)(addr >> 8), (u8)(addr & 0xFF)};
g_pstAF_I2Cclient->addr = (EEPROM_I2C_SLAVE_ADDR) >> 1;
if (i2c_master_send(g_pstAF_I2Cclient, pu_send_cmd, 2) < 0) {
LOG_INF("read I2C send failed!!\n");
return -1;
}
if (i2c_master_recv(g_pstAF_I2Cclient, &u8data, 1) < 0) {
LOG_INF("failed!!\n");
return -1;
}
*data = u8data;
LOG_INF("EEPROM 0x%x, 0x%x\n", addr, *data);
return 0;
}
static int s4AF_ReadReg(u8 length, u8 addr, u16 *data)
{
u8 pBuff[2];
u8 u8data = 0;
g_pstAF_I2Cclient->addr = (AF_I2C_SLAVE_ADDR) >> 1;
if (i2c_master_send(g_pstAF_I2Cclient, &addr, 1) < 0) {
LOG_INF("[CAMERA SENSOR] read I2C send failed!!\n");
return -1;
}
if (length == 0) {
if (i2c_master_recv(g_pstAF_I2Cclient, &u8data, 1) < 0) {
LOG_INF("Read Reg failed!!\n");
return -1;
}
*data = u8data;
} else if (length == 1) {
if (i2c_master_recv(g_pstAF_I2Cclient, pBuff, 2) < 0) {
LOG_INF("Read Reg2 failed!!\n");
return -1;
}
*data = (((u16)pBuff[0]) << 8) + ((u16)pBuff[1]);
}
LOG_INF("Read Reg 0x%x, 0x%x, 0x%x\n", length, addr, *data);
return 0;
}
static int s4AF_WriteReg(u8 length, u8 addr, u16 data)
{
u8 puSendCmd[2] = {addr, (u8)(data & 0xFF)};
u8 puSendCmd2[3] = {addr, (u8)((data >> 8) & 0xFF), (u8)(data & 0xFF)};
LOG_INF("WriteReg 0x%x, 0x%x, 0x%x\n", length, addr, data);
g_pstAF_I2Cclient->addr = (AF_I2C_SLAVE_ADDR) >> 1;
if (length == 0) {
if (i2c_master_send(g_pstAF_I2Cclient, puSendCmd, 2) < 0) {
LOG_INF("WriteReg failed!!\n");
return -1;
}
} else if (length == 1) {
if (i2c_master_send(g_pstAF_I2Cclient, puSendCmd2, 3) < 0) {
LOG_INF("WriteReg 2 failed!!\n");
return -1;
}
}
return 0;
}
static inline int getAFInfo(__user struct stAF_MotorInfo *pstMotorInfo)
{
struct stAF_MotorInfo stMotorInfo;
stMotorInfo.u4MacroPosition = g_u4AF_MACRO;
stMotorInfo.u4InfPosition = g_u4AF_INF;
stMotorInfo.u4CurrentPosition = g_u4CurrPosition;
stMotorInfo.bIsSupportSR = 1;
stMotorInfo.bIsMotorMoving = 1;
if (*g_pAF_Opened >= 1)
stMotorInfo.bIsMotorOpen = 1;
else
stMotorInfo.bIsMotorOpen = 0;
if (copy_to_user(pstMotorInfo, &stMotorInfo,
sizeof(struct stAF_MotorInfo)))
LOG_INF("copy to user failed when getting motor information\n");
return 0;
}
/* initAF include driver initialization and standby mode */
static int initAF(void)
{
LOG_INF("+\n");
if (*g_pAF_Opened == 1) {
u16 Reg_0x85 = 0;
u16 Reg_0x3C = 0;
u16 eepdata1 = 0, eepdata2 = 0;
u16 posh = 0, posl = 0, max_pos = 0, min_pos = 0;
u16 No_eeprom = 0;
s4EEPROM_ReadReg(0x0000, &posl);
s4EEPROM_ReadReg(0x0001, &posh);
min_pos = (posh << 8) + posl;
s4EEPROM_ReadReg(0x0002, &posl);
s4EEPROM_ReadReg(0x0003, &posh);
max_pos = (posh << 8) + posl;
s4EEPROM_ReadReg(0x0004, &eepdata1);
No_eeprom = s4EEPROM_ReadReg(0x0005, &eepdata2);
LOG_INF("min %d, max %x, offset 0x%x, gain 0x%x\n",
min_pos, max_pos, eepdata1, eepdata2);
s4AF_WriteReg(0, 0x80, 0x34);
s4AF_WriteReg(0, 0x81, 0x20);
s4AF_WriteReg(0, 0x84, 0xe0);
s4AF_WriteReg(0, 0x87, 0x05);
s4AF_WriteReg(0, 0xA4, 0x24);
s4AF_WriteReg(1, 0x3a, 0x0000);
s4AF_WriteReg(1, 0x04, 0x0000);
s4AF_WriteReg(1, 0x02, 0x0000);
s4AF_WriteReg(1, 0x18, 0x0000);
s4AF_WriteReg(0, 0x88, 0x70);
if (No_eeprom == 0) {
s4AF_WriteReg(0, 0x28, eepdata1);
s4AF_WriteReg(0, 0x29, eepdata2);
} else {
s4AF_WriteReg(0, 0x28, 0x80);
s4AF_WriteReg(0, 0x29, 0x80);
}
s4AF_WriteReg(1, 0x4c, 0x4000);
s4AF_WriteReg(0, 0x83, 0x2c);
s4AF_WriteReg(0, 0x85, 0xc0);
msleep(20);
s4AF_ReadReg(0, 0x85, &Reg_0x85);
while (Reg_0x85 != 0x00) {
msleep(20);
s4AF_ReadReg(0, 0x85, &Reg_0x85);
}
s4AF_WriteReg(0, 0x84, 0xe3);
s4AF_WriteReg(0, 0x97, 0x00);
s4AF_WriteReg(0, 0x98, 0x42);
s4AF_WriteReg(0, 0x99, 0x00);
s4AF_WriteReg(0, 0x9a, 0x00);
s4AF_WriteReg(0, 0x86, 0x40);
s4AF_WriteReg(1, 0x40, 0x8010);
s4AF_WriteReg(1, 0x42, 0x7570);
s4AF_WriteReg(1, 0x44, 0x8b50);
s4AF_WriteReg(1, 0x46, 0x6a10);
s4AF_WriteReg(1, 0x48, 0x5a90);
s4AF_WriteReg(1, 0x4a, 0x2030);
s4AF_WriteReg(1, 0x4c, 0x32f0);
s4AF_WriteReg(1, 0x4e, 0x7ff0);
s4AF_WriteReg(1, 0x50, 0x04f0);
s4AF_WriteReg(1, 0x52, 0x7610);
s4AF_WriteReg(1, 0x54, 0x1450);
s4AF_WriteReg(1, 0x56, 0x0000);
s4AF_WriteReg(1, 0x58, 0x7ff0);
s4AF_WriteReg(1, 0x5a, 0x0680);
s4AF_WriteReg(1, 0x5c, 0x72f0);
s4AF_WriteReg(1, 0x5e, 0x7f70);
s4AF_WriteReg(1, 0x60, 0x7ed0);
s4AF_WriteReg(1, 0x62, 0x7ff0);
s4AF_WriteReg(1, 0x64, 0x0000);
s4AF_WriteReg(1, 0x66, 0x0000);
s4AF_WriteReg(1, 0x68, 0x5130);
s4AF_WriteReg(1, 0x6a, 0x72f0);
s4AF_WriteReg(1, 0x6c, 0x8010);
s4AF_WriteReg(1, 0x6e, 0x0000);
s4AF_WriteReg(1, 0x70, 0x0000);
s4AF_WriteReg(1, 0x72, 0x18e0);
s4AF_WriteReg(1, 0x74, 0x4e30);
s4AF_WriteReg(1, 0x30, 0x0000);
s4AF_WriteReg(1, 0x76, 0x0c50);
s4AF_WriteReg(1, 0x78, 0x4000);
s4AF_ReadReg(1, 0x3C, &Reg_0x3C);
s4AF_WriteReg(1, 0x04, Reg_0x3C);
s4AF_WriteReg(1, 0x18, Reg_0x3C);
s4AF_WriteReg(1, 0x5A, 0x0800);
s4AF_WriteReg(0, 0x83, 0xAC);
s4AF_WriteReg(0, 0xA0, 0x02);
s4AF_WriteReg(1, 0x7A, 0x7000);
s4AF_WriteReg(1, 0x7E, 0x7E00);
s4AF_WriteReg(0, 0x93, 0x40);
s4AF_WriteReg(0, 0x86, 0x60);
s4AF_WriteReg(0, 0x87, 0x85);
msleep(30);
spin_lock(g_pAF_SpinLock);
*g_pAF_Opened = 2;
spin_unlock(g_pAF_SpinLock);
}
LOG_INF("-\n");
return 0;
}
static int SetVCMPos(u16 _wData)
{
u16 TargetPos;
/* u32 tmpcal=0; */
u16 ExistentPos = 0;
int i2cret = 0;
_wData = _wData << 2;
/* 0~1024 => 0x8010~0x7ff0 */
if (_wData < 0x800)
TargetPos = 0x800 - _wData;
else
TargetPos = (0x1800 - _wData) & 0xFFF;
TargetPos = TargetPos << 4;
s4AF_ReadReg(1, 0x3C, &ExistentPos);
LOG_INF("move pos 0x%x 0x%x\n", TargetPos, ExistentPos);
if (TargetPos > ExistentPos) {
s4AF_WriteReg(1, 0xA1, TargetPos & 0xfff0);
s4AF_WriteReg(1, 0x16, 0x0180);
s4AF_WriteReg(0, 0x8F, 0x01);
i2cret = s4AF_WriteReg(0, 0x8A, 0x8D);
} else if (TargetPos < ExistentPos) {
s4AF_WriteReg(1, 0xA1, TargetPos & 0xfff0);
s4AF_WriteReg(1, 0x16, 0xFE80);
s4AF_WriteReg(0, 0x8F, 0x01);
i2cret = s4AF_WriteReg(0, 0x8A, 0x8D);
}
return i2cret;
}
/* moveAF only use to control moving the motor */
static inline int moveAF(unsigned long a_u4Position)
{
int ret = 0;
if (SetVCMPos((u16)a_u4Position) == 0) {
g_u4CurrPosition = a_u4Position;
ret = 0;
} else {
LOG_INF("set I2C failed when moving the motor\n");
ret = -1;
}
return ret;
}
static inline int setAFInf(unsigned long a_u4Position)
{
spin_lock(g_pAF_SpinLock);
g_u4AF_INF = a_u4Position;
spin_unlock(g_pAF_SpinLock);
return 0;
}
static inline int setAFMacro(unsigned long a_u4Position)
{
spin_lock(g_pAF_SpinLock);
g_u4AF_MACRO = a_u4Position;
spin_unlock(g_pAF_SpinLock);
return 0;
}
/* ////////////////////////////////////////////////////////////// */
long LC898212AF_Ioctl(struct file *a_pstFile, unsigned int a_u4Command,
unsigned long a_u4Param)
{
long i4RetValue = 0;
switch (a_u4Command) {
case AFIOC_G_MOTORINFO:
i4RetValue =
getAFInfo((__user struct stAF_MotorInfo *)(a_u4Param));
break;
case AFIOC_T_MOVETO:
i4RetValue = moveAF(a_u4Param);
break;
case AFIOC_T_SETINFPOS:
i4RetValue = setAFInf(a_u4Param);
break;
case AFIOC_T_SETMACROPOS:
i4RetValue = setAFMacro(a_u4Param);
break;
default:
LOG_INF("No CMD\n");
i4RetValue = -EPERM;
break;
}
return i4RetValue;
}
/* Main jobs: */
/* 1.Deallocate anything that "open" allocated in private_data. */
/* 2.Shut down the device on last close. */
/* 3.Only called once on last time. */
/* Q1 : Try release multiple times. */
int LC898212AF_Release(struct inode *a_pstInode, struct file *a_pstFile)
{
LOG_INF("Start\n");
if (*g_pAF_Opened == 2)
LOG_INF("Wait\n");
if (*g_pAF_Opened) {
LOG_INF("Free\n");
spin_lock(g_pAF_SpinLock);
*g_pAF_Opened = 0;
spin_unlock(g_pAF_SpinLock);
}
LOG_INF("End\n");
return 0;
}
int LC898212AF_SetI2Cclient(struct i2c_client *pstAF_I2Cclient,
spinlock_t *pAF_SpinLock, int *pAF_Opened)
{
g_pstAF_I2Cclient = pstAF_I2Cclient;
g_pAF_SpinLock = pAF_SpinLock;
g_pAF_Opened = pAF_Opened;
initAF();
return 1;
}
int LC898212AF_GetFileName(unsigned char *pFileName)
{
#if SUPPORT_GETTING_LENS_FOLDER_NAME
char FilePath[256];
char *FileString;
sprintf(FilePath, "%s", __FILE__);
FileString = strrchr(FilePath, '/');
*FileString = '\0';
FileString = (strrchr(FilePath, '/') + 1);
strncpy(pFileName, FileString, AF_MOTOR_NAME);
LOG_INF("FileName : %s\n", pFileName);
#else
pFileName[0] = '\0';
#endif
return 1;
}
@@ -0,0 +1,19 @@
#
# Copyright (C) 2015 MediaTek Inc.
#
# 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.
#
#
# Makefile for misc devices that really don't fit anywhere else.
#
obj-y += LC898212AF.o
@@ -0,0 +1,80 @@
// SPDX-License-Identifier: GPL-2.0
/*
* Copyright (c) 2019 MediaTek Inc.
*/
/* ************************** */
/* Include Header File */
/* ************************** */
#include "AfInit.h"
#include "AfData.h"
#define REG_ADDR_START 0x80 /* REG Start address */
void AfInit(unsigned char hall_off, unsigned char hall_bias)
{
unsigned int DataLen;
unsigned short i;
unsigned short pos;
if (g_LC898212_SearchDir == 0) {
/* IMX230, OV23850 */
DataLen = sizeof(Init_Table_TVC820) / sizeof(IniData);
for (i = 0; i < DataLen; i++) {
if (Init_Table_TVC820[i].addr == WAIT) {
WaitTime(Init_Table_TVC820[i].data);
continue;
}
if (Init_Table_TVC820[i].addr >= REG_ADDR_START)
RegWriteA(Init_Table_TVC820[i].addr,
(unsigned char)(Init_Table_TVC820[i]
.data &
0x00ff));
else
RamWriteA(Init_Table_TVC820[i].addr,
(unsigned short)Init_Table_TVC820[i]
.data);
}
} else {
/* IMX214, IMX258 */
DataLen = sizeof(Init_Table_TVC651) / sizeof(IniData);
for (i = 0; i < DataLen; i++) {
if (Init_Table_TVC651[i].addr == WAIT) {
WaitTime(Init_Table_TVC651[i].data);
continue;
}
if (Init_Table_TVC651[i].addr >= REG_ADDR_START)
RegWriteA(Init_Table_TVC651[i].addr,
(unsigned char)(Init_Table_TVC651[i]
.data &
0x00ff));
else
RamWriteA(Init_Table_TVC651[i].addr,
(unsigned short)Init_Table_TVC651[i]
.data);
}
}
RegWriteA(0x28, hall_off); /* Hall Offset */
RegWriteA(0x29, hall_bias); /* Hall Bias */
RamReadA(0x3C, &pos);
RamWriteA(0x04, pos); /* Direct move target position */
RamWriteA(0x18, pos); /* Step move start position */
/* WaitTime(5); */
/* RegWriteA( 0x87, 0x85 ); // Servo ON */
}
void ServoOn(void)
{
RegWriteA(0x85, 0x80); /* Clear PID Ram Data */
WaitTime(1);
RegWriteA(0x87, 0x85); /* Servo ON */
}
@@ -0,0 +1,74 @@
// SPDX-License-Identifier: GPL-2.0
/*
* Copyright (c) 2019 MediaTek Inc.
*/
#ifdef DEBUG_LOG
#include <linux/fs.h>
#endif
#include <linux/delay.h>
#include <linux/i2c.h>
#define DeviceAddr 0xE4
#include "AfSTMV.h"
#ifdef DEBUG_LOG
#define AF_REGDUMP "REGDUMP"
#define LOG_INF(format, args...) pr_info(AF_REGDUMP " " format, ##args)
#endif
void RamWriteA(unsigned short addr, unsigned short data)
{
u8 puSendCmd[3] = {(u8)(addr & 0xFF), (u8)(data >> 8),
(u8)(data & 0xFF)};
s4AF_WriteReg_LC898212XDAF(puSendCmd, sizeof(puSendCmd), DeviceAddr);
#ifdef DEBUG_LOG
LOG_INF("RAMW\t%x\t%x\n", addr, data);
#endif
}
void RamReadA(unsigned short addr, unsigned short *data)
{
u8 buf[2];
u8 puSendCmd[1] = {(u8)(addr & 0xFF)};
s4AF_ReadReg_LC898212XDAF(puSendCmd, sizeof(puSendCmd), buf, 2,
DeviceAddr);
*data = (buf[0] << 8) | (buf[1] & 0x00FF);
#ifdef DEBUG_LOG
LOG_INF("RAMR\t%x\t%x\n", addr, *data);
#endif
}
void RegWriteA(unsigned short addr, unsigned char data)
{
u8 puSendCmd[2] = {(u8)(addr & 0xFF), (u8)(data & 0xFF)};
s4AF_WriteReg_LC898212XDAF(puSendCmd, sizeof(puSendCmd), DeviceAddr);
#ifdef DEBUG_LOG
LOG_INF("REGW\t%x\t%x\n", addr, data);
#endif
}
void RegReadA(unsigned short addr, unsigned char *data)
{
u8 puSendCmd[1] = {(u8)(addr & 0xFF)};
s4AF_ReadReg_LC898212XDAF(puSendCmd, sizeof(puSendCmd), data, 1,
DeviceAddr);
#ifdef DEBUG_LOG
LOG_INF("REGR\t%x\t%x\n", addr, *data);
#endif
}
void WaitTime(unsigned short msec)
{
usleep_range(msec * 1000, (msec + 1) * 1000);
}
@@ -0,0 +1,85 @@
// SPDX-License-Identifier: GPL-2.0
/*
* Copyright (c) 2019 MediaTek Inc.
*/
#include "AfSTMV.h"
#include "AfDef.h"
#define ABS_STMV(x) ((x) < 0 ? -(x) : (x))
#define LC898211_fs 234375
static struct stSmvPar StSmvPar;
void StmvSet(struct stSmvPar StSetSmv)
{
unsigned char UcSetEnb;
unsigned char UcSetSwt;
unsigned short UsParSiz;
unsigned char UcParItv;
short SsParStt; /* StepMove Start Position */
StSmvPar.UsSmvSiz = StSetSmv.UsSmvSiz;
StSmvPar.UcSmvItv = StSetSmv.UcSmvItv;
StSmvPar.UcSmvEnb = StSetSmv.UcSmvEnb;
RegWriteA(AFSEND_211, 0x00); /* StepMove Enable Bit Clear */
RegReadA(ENBL_211, &UcSetEnb);
UcSetEnb &= (unsigned char)0xFD;
RegWriteA(ENBL_211, UcSetEnb); /* Measuremenet Circuit1 Off */
RegReadA(SWTCH_211, &UcSetSwt);
UcSetSwt &= (unsigned char)0x7F;
RegWriteA(SWTCH_211, UcSetSwt); /* RZ1 Switch Cut Off */
RamReadA(RZ_211H, (unsigned short *)&SsParStt); /* Get Start Position */
UsParSiz = StSetSmv.UsSmvSiz; /* Get StepSize */
UcParItv = StSetSmv.UcSmvItv; /* Get StepInterval */
RamWriteA(ms11a_211H, (unsigned short)0x0800);
RamWriteA(MS1Z22_211H,
(unsigned short)SsParStt); /* Set Start Position */
RamWriteA(MS1Z12_211H, UsParSiz); /* Set StepSize */
RegWriteA(STMINT_211, UcParItv); /* Set StepInterval */
UcSetSwt |= (unsigned char)0x80;
RegWriteA(SWTCH_211, UcSetSwt); /* RZ1 Switch ON */
}
unsigned char StmvTo(short SsSmvEnd)
{
unsigned short UsSmvDpl;
short SsParStt; /* StepMove Start Position */
/* PIOA_SetOutput(_PIO_PA29); // Monitor I/O Port */
RamReadA(RZ_211H, (unsigned short *)&SsParStt); /* Get Start Position */
UsSmvDpl = ABS_STMV(SsParStt - SsSmvEnd);
if ((UsSmvDpl <= StSmvPar.UsSmvSiz) &&
((StSmvPar.UcSmvEnb & STMSV_ON) == STMSV_ON)) {
if (StSmvPar.UcSmvEnb & STMCHTG_ON)
RegWriteA(MSSET_211,
INI_MSSET_211 | (unsigned char)0x01);
RamWriteA(MS1Z22_211H,
SsSmvEnd); /* Handling Single Step For ES1 */
StSmvPar.UcSmvEnb |= STMVEN_ON;
} else {
if (SsParStt < SsSmvEnd) { /* Check StepMove Direction */
RamWriteA(MS1Z12_211H, StSmvPar.UsSmvSiz);
} else if (SsParStt > SsSmvEnd) {
RamWriteA(MS1Z12_211H, -StSmvPar.UsSmvSiz);
}
RamWriteA(STMVENDH_211,
SsSmvEnd); /* Set StepMove Target Position */
StSmvPar.UcSmvEnb |= STMVEN_ON;
RegWriteA(STMVEN_211, StSmvPar.UcSmvEnb); /* Start StepMove */
}
return 0;
}
@@ -0,0 +1,793 @@
// SPDX-License-Identifier: GPL-2.0
/*
* Copyright (c) 2019 MediaTek Inc.
*/
/*
* LC898212XDAF voice coil motor driver
*
*
*/
#include <linux/delay.h>
#include <linux/fs.h>
#include <linux/i2c.h>
#include <linux/uaccess.h>
#include "lens_info.h"
#include "AfInit.h"
#include "AfSTMV.h"
#define AF_DRVNAME "LC898212XDAF_DRV"
#define AF_I2C_SLAVE_ADDR 0xE4
#define EEPROM_I2C_SLAVE_ADDR_OV23850 0xA8
#define EEPROM_I2C_SLAVE_ADDR_IMX258 0xA0
#define AF_DEBUG
#ifdef AF_DEBUG
#define LOG_INF(format, args...) \
pr_info(AF_DRVNAME " [%s] " format, __func__, ##args)
#else
#define LOG_INF(format, args...)
#endif
static struct i2c_client *g_pstAF_I2Cclient;
static int *g_pAF_Opened;
static spinlock_t *g_pAF_SpinLock;
static unsigned long g_u4AF_INF;
static unsigned long g_u4AF_MACRO = 1023;
static unsigned long g_u4CurrPosition;
static unsigned int g_SelectEEPROM;
unsigned int g_LC898212_SearchDir;
#define Min_Pos 0
#define Max_Pos 1023
/* LiteOn : Hall calibration range : 0xA800 - 0x5800 */
static signed short Hall_Max =
0x5800; /* Please read INF position from EEPROM or OTP */
static signed short Hall_Min =
0xA800; /* Please read MACRO position from EEPROM or OTP */
int s4AF_ReadReg_LC898212XDAF(u8 *a_pSendData, u16 a_sizeSendData,
u8 *a_pRecvData, u16 a_sizeRecvData, u16 i2cId)
{
int i4RetValue = 0;
g_pstAF_I2Cclient->addr = i2cId >> 1;
i4RetValue =
i2c_master_send(g_pstAF_I2Cclient, a_pSendData, a_sizeSendData);
if (i4RetValue != a_sizeSendData) {
LOG_INF("I2C send failed!!, Addr = 0x%x\n", a_pSendData[0]);
return -1;
}
i4RetValue = i2c_master_recv(g_pstAF_I2Cclient, (u8 *)a_pRecvData,
a_sizeRecvData);
if (i4RetValue != a_sizeRecvData) {
LOG_INF("I2C read failed!!\n");
return -1;
}
return 0;
}
int s4AF_WriteReg_LC898212XDAF(u8 *a_pSendData, u16 a_sizeSendData, u16 i2cId)
{
int i4RetValue = 0;
g_pstAF_I2Cclient->addr = i2cId >> 1;
i4RetValue =
i2c_master_send(g_pstAF_I2Cclient, a_pSendData, a_sizeSendData);
if (i4RetValue < 0) {
LOG_INF("I2C send failed!!, Addr = 0x%x, Data = 0x%x\n",
a_pSendData[0], a_pSendData[1]);
return -1;
}
return 0;
}
static int s4EEPROM_ReadReg_LC898212XDAF_OV23850(u16 addr, u8 *data)
{
int i4RetValue = 0;
u8 puSendCmd[2] = {(u8)(addr >> 8), (u8)(addr & 0xFF)};
i4RetValue =
s4AF_ReadReg_LC898212XDAF(puSendCmd, sizeof(puSendCmd), data, 1,
EEPROM_I2C_SLAVE_ADDR_OV23850);
if (i4RetValue < 0)
LOG_INF("I2C read e2prom failed!!\n");
return i4RetValue;
}
static int s4EEPROM_ReadReg_LC898212XDAF_IMX258(u16 addr, u8 *data)
{
int i4RetValue = 0;
u8 puSendCmd[2] = {(u8)(addr >> 8), (u8)(addr & 0xFF)};
i4RetValue =
s4AF_ReadReg_LC898212XDAF(puSendCmd, sizeof(puSendCmd), data, 1,
EEPROM_I2C_SLAVE_ADDR_IMX258);
if (i4RetValue < 0)
LOG_INF("I2C read e2prom failed!!\n");
return i4RetValue;
}
static void s4AF_WriteReg(unsigned short addr, unsigned char data)
{
u8 puSendCmd[2] = {(u8)(addr & 0xFF), (u8)(data & 0xFF)};
s4AF_WriteReg_LC898212XDAF(puSendCmd, sizeof(puSendCmd),
AF_I2C_SLAVE_ADDR);
}
static int convertAF_DAC(short ReadData)
{
int DacVal = ((ReadData - Hall_Min) * (Max_Pos - Min_Pos)) /
((unsigned short)(Hall_Max - Hall_Min)) +
Min_Pos;
return DacVal;
}
static void LC898212XD_init(void)
{
struct stSmvPar StSmvPar;
u8 val1 = 0, val2 = 0;
int Hall_Off = 0x80; /* Please Read Offset from EEPROM or OTP */
int Hall_Bias = 0x80; /* Please Read Bias from EEPROM or OTP */
unsigned short HallMinCheck = 0;
unsigned short HallMaxCheck = 0;
unsigned short HallCheck = 0;
g_SelectEEPROM = 1;
if (s4EEPROM_ReadReg_LC898212XDAF_OV23850(0x001A, &val1) < 0)
g_SelectEEPROM = 0;
g_LC898212_SearchDir = 1;
if (strcmp(CONFIG_ARCH_MTK_PROJECT, "k55v2_64_stereo") == 0) {
LOG_INF("CONFIG_ARCH_MTK_PROJECT = %s\n",
CONFIG_ARCH_MTK_PROJECT);
/* Ja Stereo IMX258 - Error Version */
s4EEPROM_ReadReg_LC898212XDAF_IMX258(0x0016, &val1);
s4EEPROM_ReadReg_LC898212XDAF_IMX258(0x0015, &val2);
HallMinCheck = ((val1 << 8) | (val2 & 0x00FF)) & 0xFFFF;
s4EEPROM_ReadReg_LC898212XDAF_IMX258(0x0018, &val1);
s4EEPROM_ReadReg_LC898212XDAF_IMX258(0x0017, &val2);
HallMaxCheck = ((val1 << 8) | (val2 & 0x00FF)) & 0xFFFF;
if ((HallMaxCheck >= 0x1FFF && HallMaxCheck <= 0x7FFF) &&
(HallMinCheck >= 0x8001 && HallMinCheck <= 0xEFFF)) {
Hall_Min = HallMinCheck;
Hall_Max = HallMaxCheck;
s4EEPROM_ReadReg_LC898212XDAF_IMX258(0x001A, &val1);
s4EEPROM_ReadReg_LC898212XDAF_IMX258(0x0019, &val2);
Hall_Off = val2;
Hall_Bias = val1;
}
} else if (strncmp(CONFIG_ARCH_MTK_PROJECT, "demo97v1", 6) == 0) {
LOG_INF("CONFIG_ARCH_MTK_PROJECT = %s\n",
CONFIG_ARCH_MTK_PROJECT);
s4EEPROM_ReadReg_LC898212XDAF_IMX258(0x0003, &val1);
LOG_INF("Addr = 0x0003 , Data = %x\n", val1);
s4EEPROM_ReadReg_LC898212XDAF_IMX258(0x0004, &val2);
LOG_INF("Addr = 0x0004 , Data = %x\n", val2);
if (val1 == 0xb && val2 == 0x2) { /* EEPROM Version */
s4EEPROM_ReadReg_LC898212XDAF_IMX258(0x0F33, &val2);
s4EEPROM_ReadReg_LC898212XDAF_IMX258(0x0F34, &val1);
Hall_Min = ((val1 << 8) | (val2 & 0x00FF)) & 0xFFFF;
s4EEPROM_ReadReg_LC898212XDAF_IMX258(0x0F35, &val2);
s4EEPROM_ReadReg_LC898212XDAF_IMX258(0x0F36, &val1);
Hall_Max = ((val1 << 8) | (val2 & 0x00FF)) & 0xFFFF;
s4EEPROM_ReadReg_LC898212XDAF_IMX258(0x0F37, &val1);
Hall_Off = val1;
s4EEPROM_ReadReg_LC898212XDAF_IMX258(0x0F38, &val2);
Hall_Bias = val2;
} else {
s4EEPROM_ReadReg_LC898212XDAF_IMX258(0x0F63, &val2);
s4EEPROM_ReadReg_LC898212XDAF_IMX258(0x0F64, &val1);
HallMinCheck = ((val1 << 8) | (val2 & 0x00FF)) & 0xFFFF;
s4EEPROM_ReadReg_LC898212XDAF_IMX258(0x0F65, &val2);
s4EEPROM_ReadReg_LC898212XDAF_IMX258(0x0F66, &val1);
HallMaxCheck = ((val1 << 8) | (val2 & 0x00FF)) & 0xFFFF;
s4EEPROM_ReadReg_LC898212XDAF_IMX258(0x0F67, &val1);
s4EEPROM_ReadReg_LC898212XDAF_IMX258(0x0F68, &val2);
if ((val1 != 0) && (val2 != 0) &&
(HallMaxCheck >= 0x1FFF &&
HallMaxCheck <= 0x7FFF) &&
(HallMinCheck >= 0x8001 &&
HallMinCheck <= 0xEFFF)) {
Hall_Min = HallMinCheck;
Hall_Max = HallMaxCheck;
Hall_Off = val1;
Hall_Bias = val2;
} else {
s4EEPROM_ReadReg_LC898212XDAF_IMX258(0x0F33,
&val2);
s4EEPROM_ReadReg_LC898212XDAF_IMX258(0x0F34,
&val1);
HallMinCheck = ((val1 << 8) | (val2 & 0x00FF)) &
0xFFFF;
s4EEPROM_ReadReg_LC898212XDAF_IMX258(0x0F35,
&val2);
s4EEPROM_ReadReg_LC898212XDAF_IMX258(0x0F36,
&val1);
HallMaxCheck = ((val1 << 8) | (val2 & 0x00FF)) &
0xFFFF;
s4EEPROM_ReadReg_LC898212XDAF_IMX258(0x0F37,
&val1);
s4EEPROM_ReadReg_LC898212XDAF_IMX258(0x0F38,
&val2);
if ((val1 != 0) && (val2 != 0) &&
(HallMaxCheck >= 0x1FFF &&
HallMaxCheck <= 0x7FFF) &&
(HallMinCheck >= 0x8001 &&
HallMinCheck <= 0xEFFF)) {
Hall_Min = HallMinCheck;
Hall_Max = HallMaxCheck;
Hall_Off = val1;
Hall_Bias = val2;
}
}
}
} else if (strncmp(CONFIG_ARCH_MTK_PROJECT, "k97v1", 5) == 0 ||
strncmp(CONFIG_ARCH_MTK_PROJECT, "evb6797", 7) == 0 ||
strncmp(CONFIG_ARCH_MTK_PROJECT, "muse6797", 8) == 0) {
LOG_INF("CONFIG_ARCH_MTK_PROJECT = %s\n",
CONFIG_ARCH_MTK_PROJECT);
if (g_SelectEEPROM == 0) { /* IMX258 PDAF */
/* Li define format - Ev IMX258 PDAF - remove Koli */
s4EEPROM_ReadReg_LC898212XDAF_IMX258(0x0F67, &val1);
s4EEPROM_ReadReg_LC898212XDAF_IMX258(0x0F68, &val2);
HallMaxCheck = ((val1 << 8) | (val2 & 0x00FF)) & 0xFFFF;
s4EEPROM_ReadReg_LC898212XDAF_IMX258(0x0F69, &val1);
s4EEPROM_ReadReg_LC898212XDAF_IMX258(0x0F70, &val2);
HallMinCheck = ((val1 << 8) | (val2 & 0x00FF)) & 0xFFFF;
s4EEPROM_ReadReg_LC898212XDAF_IMX258(0x0F63, &val1);
HallCheck = val1;
if ((HallCheck == 0) && (HallMaxCheck >= 0x1FFF &&
HallMaxCheck <= 0x7FFF) &&
(HallMinCheck >= 0x8001 &&
HallMinCheck <= 0xEFFF)) {
s4EEPROM_ReadReg_LC898212XDAF_IMX258(0x0F63,
&val1);
s4EEPROM_ReadReg_LC898212XDAF_IMX258(0x0F64,
&val2);
Hall_Bias = ((val1 << 8) | (val2 & 0x00FF)) &
0xFFFF;
s4EEPROM_ReadReg_LC898212XDAF_IMX258(0x0F65,
&val1);
s4EEPROM_ReadReg_LC898212XDAF_IMX258(0x0F66,
&val2);
Hall_Off = ((val1 << 8) | (val2 & 0x00FF)) &
0xFFFF;
Hall_Min = 0x8001; /* HallMinCheck; */
Hall_Max = 0x7FFF; /* HallMaxCheck; */
/* Li define format - Ev IMX258 PDAF - end */
} else {
/* Li define format - Ev MVHDR */
s4EEPROM_ReadReg_LC898212XDAF_IMX258(0x0F33,
&val1);
s4EEPROM_ReadReg_LC898212XDAF_IMX258(0x0F34,
&val2);
Hall_Min = ((val1 << 8) | (val2 & 0x00FF)) &
0xFFFF;
s4EEPROM_ReadReg_LC898212XDAF_IMX258(0x0F35,
&val1);
s4EEPROM_ReadReg_LC898212XDAF_IMX258(0x0F36,
&val2);
Hall_Max = ((val1 << 8) | (val2 & 0x00FF)) &
0xFFFF;
s4EEPROM_ReadReg_LC898212XDAF_IMX258(0x0F37,
&val1);
Hall_Off = val1;
s4EEPROM_ReadReg_LC898212XDAF_IMX258(0x0F38,
&val2);
Hall_Bias = val2;
g_LC898212_SearchDir = 0;
/* Li define format - Ev MVHDR end */
}
} else {
LOG_INF("Select ov23850 e2prom!!\n");
s4EEPROM_ReadReg_LC898212XDAF_OV23850(0x0F63, &val1);
s4EEPROM_ReadReg_LC898212XDAF_OV23850(0x0F64, &val2);
Hall_Bias = ((val1 << 8) | (val2 & 0x00FF)) & 0xFFFF;
s4EEPROM_ReadReg_LC898212XDAF_OV23850(0x0F65, &val1);
s4EEPROM_ReadReg_LC898212XDAF_OV23850(0x0F66, &val2);
Hall_Off = ((val1 << 8) | (val2 & 0x00FF)) & 0xFFFF;
s4EEPROM_ReadReg_LC898212XDAF_OV23850(0x0F67, &val1);
s4EEPROM_ReadReg_LC898212XDAF_OV23850(0x0F68, &val2);
Hall_Min = ((val1 << 8) | (val2 & 0x00FF)) & 0xFFFF;
s4EEPROM_ReadReg_LC898212XDAF_OV23850(0x0F69, &val1);
s4EEPROM_ReadReg_LC898212XDAF_OV23850(0x0F70, &val2);
Hall_Max = ((val1 << 8) | (val2 & 0x00FF)) & 0xFFFF;
g_LC898212_SearchDir = 0;
}
} else if (strncmp(CONFIG_ARCH_MTK_PROJECT, "k57v1", 5) == 0) {
s4EEPROM_ReadReg_LC898212XDAF_IMX258(0x0F63, &val2);
s4EEPROM_ReadReg_LC898212XDAF_IMX258(0x0F64, &val1);
HallMinCheck = ((val1 << 8) | (val2 & 0x00FF)) & 0xFFFF;
s4EEPROM_ReadReg_LC898212XDAF_IMX258(0x0F65, &val2);
s4EEPROM_ReadReg_LC898212XDAF_IMX258(0x0F66, &val1);
HallMaxCheck = ((val1 << 8) | (val2 & 0x00FF)) & 0xFFFF;
s4EEPROM_ReadReg_LC898212XDAF_IMX258(0x0F67, &val1);
s4EEPROM_ReadReg_LC898212XDAF_IMX258(0x0F68, &val2);
if ((val1 != 0) && (val2 != 0) &&
(HallMaxCheck >= 0x1FFF && HallMaxCheck <= 0x7FFF) &&
(HallMinCheck >= 0x8001 && HallMinCheck <= 0xEFFF)) {
Hall_Min = HallMinCheck;
Hall_Max = HallMaxCheck;
Hall_Off = val1;
Hall_Bias = val2;
} else {
s4EEPROM_ReadReg_LC898212XDAF_IMX258(0x0CC1, &val2);
s4EEPROM_ReadReg_LC898212XDAF_IMX258(0x0CC2, &val1);
HallMinCheck = ((val1 << 8) | (val2 & 0x00FF)) & 0xFFFF;
s4EEPROM_ReadReg_LC898212XDAF_IMX258(0x0CC3, &val2);
s4EEPROM_ReadReg_LC898212XDAF_IMX258(0x0CC4, &val1);
HallMaxCheck = ((val1 << 8) | (val2 & 0x00FF)) & 0xFFFF;
s4EEPROM_ReadReg_LC898212XDAF_IMX258(0x0CC5, &val1);
s4EEPROM_ReadReg_LC898212XDAF_IMX258(0x0CC6, &val2);
if ((val1 != 0) && (val2 != 0) &&
(HallMaxCheck >= 0x1FFF &&
HallMaxCheck <= 0x7FFF) &&
(HallMinCheck >= 0x8001 &&
HallMinCheck <= 0xEFFF)) {
Hall_Min = HallMinCheck;
Hall_Max = HallMaxCheck;
Hall_Off = val1;
Hall_Bias = val2;
}
}
} else {
s4EEPROM_ReadReg_LC898212XDAF_IMX258(0x0F63, &val2);
s4EEPROM_ReadReg_LC898212XDAF_IMX258(0x0F64, &val1);
HallMinCheck = ((val1 << 8) | (val2 & 0x00FF)) & 0xFFFF;
s4EEPROM_ReadReg_LC898212XDAF_IMX258(0x0F65, &val2);
s4EEPROM_ReadReg_LC898212XDAF_IMX258(0x0F66, &val1);
HallMaxCheck = ((val1 << 8) | (val2 & 0x00FF)) & 0xFFFF;
s4EEPROM_ReadReg_LC898212XDAF_IMX258(0x0F67, &val1);
s4EEPROM_ReadReg_LC898212XDAF_IMX258(0x0F68, &val2);
if ((val1 != 0) && (val2 != 0) &&
(HallMaxCheck >= 0x1FFF && HallMaxCheck <= 0x7FFF) &&
(HallMinCheck >= 0x8001 && HallMinCheck <= 0xEFFF)) {
Hall_Min = HallMinCheck;
Hall_Max = HallMaxCheck;
Hall_Off = val1;
Hall_Bias = val2;
}
}
/* Range Protection : Min = 0x8001 , Max = 0x7FFF */
if (!(Hall_Max >= 0 && Hall_Max <= 0x7FFF)) {
signed short Temp;
Temp = Hall_Min;
Hall_Min = Hall_Max;
Hall_Max = Temp;
}
LOG_INF("hallmax:0x%x, hallmin:0x%x, halloff:0x%x, hallbias:0x%x\n",
Hall_Max, Hall_Min, Hall_Off, Hall_Bias);
/* Wake up */
s4AF_WriteReg(0x80, 0x68);
s4AF_WriteReg(0x80, 0x64);
s4AF_WriteReg(0x95, 0x00);
AfInit(Hall_Off, Hall_Bias); /* Initialize driver IC */
/* Step move parameter set */
StSmvPar.UsSmvSiz = STMV_SIZE;
StSmvPar.UcSmvItv = STMV_INTERVAL;
StSmvPar.UcSmvEnb = STMCHTG_SET | STMSV_SET | STMLFF_SET;
StmvSet(StSmvPar);
ServoOn(); /* Close loop ON */
}
static unsigned short AF_convert(int position)
{
if (g_LC898212_SearchDir == 0) {
return (((position - Min_Pos) *
(unsigned short)(Hall_Max - Hall_Min) /
(Max_Pos - Min_Pos)) +
Hall_Min) &
0xFFFF;
} else {
return (((Max_Pos - position) *
(unsigned short)(Hall_Max - Hall_Min) /
(Max_Pos - Min_Pos)) +
Hall_Min) &
0xFFFF;
}
}
static inline int getAFInfo(__user struct stAF_MotorInfo *pstMotorInfo)
{
struct stAF_MotorInfo stMotorInfo;
stMotorInfo.u4MacroPosition = g_u4AF_MACRO;
stMotorInfo.u4InfPosition = g_u4AF_INF;
stMotorInfo.u4CurrentPosition = g_u4CurrPosition;
stMotorInfo.bIsSupportSR = 1;
stMotorInfo.bIsMotorMoving = 1;
if (*g_pAF_Opened >= 1)
stMotorInfo.bIsMotorOpen = 1;
else
stMotorInfo.bIsMotorOpen = 0;
if (copy_to_user(pstMotorInfo, &stMotorInfo,
sizeof(struct stAF_MotorInfo)))
LOG_INF("copy to user failed when getting motor information\n");
return 0;
}
/* initAF include driver initialization and standby mode */
static int initAF(void)
{
LOG_INF("+\n");
if (*g_pAF_Opened == 1) {
LC898212XD_init();
spin_lock(g_pAF_SpinLock);
*g_pAF_Opened = 2;
spin_unlock(g_pAF_SpinLock);
}
LOG_INF("-\n");
return 0;
}
/* moveAF only use to control moving the motor */
static inline int moveAF(unsigned long a_u4Position)
{
int ret = 0;
if ((StmvTo(AF_convert((int)a_u4Position)) & 0x1) == 0) {
g_u4CurrPosition = a_u4Position;
ret = 0;
} else {
LOG_INF("set I2C failed when moving the motor\n");
ret = -1;
}
return ret;
}
static inline int setAFInf(unsigned long a_u4Position)
{
spin_lock(g_pAF_SpinLock);
g_u4AF_INF = a_u4Position;
spin_unlock(g_pAF_SpinLock);
return 0;
}
static inline int setAFMacro(unsigned long a_u4Position)
{
spin_lock(g_pAF_SpinLock);
g_u4AF_MACRO = a_u4Position;
spin_unlock(g_pAF_SpinLock);
return 0;
}
static inline int getAFCalPos(__user struct stAF_MotorCalPos *pstMotorCalPos)
{
struct stAF_MotorCalPos stMotorCalPos;
u32 u4AF_CalibData_INF;
u32 u4AF_CalibData_MACRO;
u8 val1;
u4AF_CalibData_INF = 0;
u4AF_CalibData_MACRO = 0;
g_SelectEEPROM = 1;
if (s4EEPROM_ReadReg_LC898212XDAF_OV23850(0x001A, &val1) < 0)
g_SelectEEPROM = 0;
if (g_SelectEEPROM == 1) {
u8 val1 = 0, val2 = 0;
int AF_Infi = 0x00;
int AF_Marco = 0x00;
s4EEPROM_ReadReg_LC898212XDAF_OV23850(0x0011,
&val2); /* low byte */
s4EEPROM_ReadReg_LC898212XDAF_OV23850(0x0012, &val1);
AF_Infi = ((val1 << 8) | (val2 & 0x00FF)) & 0xFFFF;
s4EEPROM_ReadReg_LC898212XDAF_OV23850(0x0013, &val2);
s4EEPROM_ReadReg_LC898212XDAF_OV23850(0x0014, &val1);
AF_Marco = ((val1 << 8) | (val2 & 0x00FF)) & 0xFFFF;
s4EEPROM_ReadReg_LC898212XDAF_OV23850(0x0F67, &val1);
s4EEPROM_ReadReg_LC898212XDAF_OV23850(0x0F68, &val2);
Hall_Min = ((val1 << 8) | (val2 & 0x00FF)) & 0xFFFF;
s4EEPROM_ReadReg_LC898212XDAF_OV23850(0x0F69, &val1);
s4EEPROM_ReadReg_LC898212XDAF_OV23850(0x0F70, &val2);
Hall_Max = ((val1 << 8) | (val2 & 0x00FF)) & 0xFFFF;
if (!(Hall_Max >= 0 && Hall_Max <= 0x7FFF)) {
signed short Temp;
Temp = Hall_Min;
Hall_Min = Hall_Max;
Hall_Max = Temp;
}
if (AF_Marco > 1023 || AF_Infi > 1023 || AF_Infi > AF_Marco) {
u4AF_CalibData_INF = convertAF_DAC(AF_Infi);
u4AF_CalibData_MACRO = convertAF_DAC(AF_Marco);
}
} else {
u8 val1 = 0, val2 = 0;
int AF_Infi = 0x00;
int AF_Marco = 0x00;
s4EEPROM_ReadReg_LC898212XDAF_IMX258(0x0011,
&val2); /* low byte */
s4EEPROM_ReadReg_LC898212XDAF_IMX258(0x0012, &val1);
AF_Infi = ((val1 << 8) | (val2 & 0x00FF)) & 0xFFFF;
s4EEPROM_ReadReg_LC898212XDAF_IMX258(0x0013, &val2);
s4EEPROM_ReadReg_LC898212XDAF_IMX258(0x0014, &val1);
AF_Marco = ((val1 << 8) | (val2 & 0x00FF)) & 0xFFFF;
LOG_INF("AF_Infi : %x\n", AF_Infi);
LOG_INF("AF_Marco : %x\n", AF_Marco);
Hall_Min = 0x8001;
Hall_Max = 0x7FFF;
if (AF_Marco > 1023 || AF_Infi > 1023 || AF_Infi > AF_Marco) {
u4AF_CalibData_INF = convertAF_DAC(AF_Infi);
u4AF_CalibData_MACRO = convertAF_DAC(AF_Marco);
if (u4AF_CalibData_INF > u4AF_CalibData_MACRO) {
u4AF_CalibData_INF = 1023 - u4AF_CalibData_INF;
u4AF_CalibData_MACRO =
1023 - u4AF_CalibData_MACRO;
}
}
}
LOG_INF("AF_CalibData_INF : %d\n", u4AF_CalibData_INF);
LOG_INF("AF_CalibData_MACRO : %d\n", u4AF_CalibData_MACRO);
if (strncmp(CONFIG_ARCH_MTK_PROJECT, "k57v1", 5) == 0) {
u8 val1 = 0, val2 = 0;
unsigned int AF_Infi = 0x00;
unsigned int AF_Marco = 0x00;
s4EEPROM_ReadReg_LC898212XDAF_IMX258(0x0011,
&val2); /* low byte */
s4EEPROM_ReadReg_LC898212XDAF_IMX258(0x0012, &val1);
AF_Infi = ((val1 << 8) | (val2 & 0x00FF)) & 0xFFFF;
LOG_INF("AF_Infi : %x\n", AF_Infi);
s4EEPROM_ReadReg_LC898212XDAF_IMX258(0x0013, &val2);
s4EEPROM_ReadReg_LC898212XDAF_IMX258(0x0014, &val1);
AF_Marco = ((val1 << 8) | (val2 & 0x00FF)) & 0xFFFF;
LOG_INF("AF_Infi : %x\n", AF_Marco);
/* Hall_Min = 0x8001; */
/* Hall_Max = 0x7FFF; */
if (AF_Marco > 1023 || AF_Infi > 1023 || AF_Infi > AF_Marco) {
u4AF_CalibData_INF = convertAF_DAC(AF_Infi);
LOG_INF("u4AF_CalibData_INF : %d\n",
u4AF_CalibData_INF);
u4AF_CalibData_MACRO = convertAF_DAC(AF_Marco);
LOG_INF("u4AF_CalibData_MACRO : %d\n",
u4AF_CalibData_MACRO);
if (u4AF_CalibData_MACRO > 0 &&
u4AF_CalibData_INF < 1024 &&
u4AF_CalibData_INF > u4AF_CalibData_MACRO) {
u4AF_CalibData_INF = 1023 - u4AF_CalibData_INF;
u4AF_CalibData_MACRO =
1023 - u4AF_CalibData_MACRO;
}
}
}
if (u4AF_CalibData_INF > 0 && u4AF_CalibData_MACRO < 1024 &&
u4AF_CalibData_INF < u4AF_CalibData_MACRO) {
stMotorCalPos.u4MacroPos = u4AF_CalibData_MACRO;
stMotorCalPos.u4InfPos = u4AF_CalibData_INF;
} else {
stMotorCalPos.u4MacroPos = 0;
stMotorCalPos.u4InfPos = 0;
}
if (copy_to_user(pstMotorCalPos, &stMotorCalPos, sizeof(stMotorCalPos)))
LOG_INF("copy to user failed when getting motor information\n");
return 0;
}
/* ////////////////////////////////////////////////////////////// */
long LC898212XDAF_Ioctl(struct file *a_pstFile, unsigned int a_u4Command,
unsigned long a_u4Param)
{
long i4RetValue = 0;
switch (a_u4Command) {
case AFIOC_G_MOTORINFO:
i4RetValue =
getAFInfo((__user struct stAF_MotorInfo *)(a_u4Param));
break;
case AFIOC_T_MOVETO:
i4RetValue = moveAF(a_u4Param);
break;
case AFIOC_T_SETINFPOS:
i4RetValue = setAFInf(a_u4Param);
break;
case AFIOC_T_SETMACROPOS:
i4RetValue = setAFMacro(a_u4Param);
break;
case AFIOC_G_MOTORCALPOS:
i4RetValue = getAFCalPos(
(__user struct stAF_MotorCalPos *)(a_u4Param));
break;
default:
LOG_INF("No CMD\n");
i4RetValue = -EPERM;
break;
}
return i4RetValue;
}
/* Main jobs: */
/* 1.Deallocate anything that "open" allocated in private_data. */
/* 2.Shut down the device on last close. */
/* 3.Only called once on last time. */
/* Q1 : Try release multiple times. */
int LC898212XDAF_Release(struct inode *a_pstInode, struct file *a_pstFile)
{
LOG_INF("Start\n");
if (*g_pAF_Opened == 2) {
LOG_INF("Wait\n");
/* Sleep In */
s4AF_WriteReg(0x95, 0x80);
s4AF_WriteReg(0x80, 0x68);
s4AF_WriteReg(0x80, 0x69);
msleep(20);
}
if (*g_pAF_Opened) {
LOG_INF("Free\n");
spin_lock(g_pAF_SpinLock);
*g_pAF_Opened = 0;
spin_unlock(g_pAF_SpinLock);
}
LOG_INF("End\n");
return 0;
}
int LC898212XDAF_SetI2Cclient(struct i2c_client *pstAF_I2Cclient,
spinlock_t *pAF_SpinLock, int *pAF_Opened)
{
g_pstAF_I2Cclient = pstAF_I2Cclient;
g_pAF_SpinLock = pAF_SpinLock;
g_pAF_Opened = pAF_Opened;
initAF();
return 1;
}
int LC898212XDAF_GetFileName(unsigned char *pFileName)
{
#if SUPPORT_GETTING_LENS_FOLDER_NAME
char FilePath[256];
char *FileString;
sprintf(FilePath, "%s", __FILE__);
FileString = strrchr(FilePath, '/');
*FileString = '\0';
FileString = (strrchr(FilePath, '/') + 1);
strncpy(pFileName, FileString, AF_MOTOR_NAME);
LOG_INF("FileName : %s\n", pFileName);
#else
pFileName[0] = '\0';
#endif
return 1;
}
@@ -0,0 +1,6 @@
#
# Makefile for misc devices that really don't fit anywhere else.
#
obj-y += LC898212XDAF.o AfInter.o AfInit.o AfSTMV.o
@@ -0,0 +1,158 @@
/* SPDX-License-Identifier: GPL-2.0 */
/*
* Copyright (c) 2019 MediaTek Inc.
*/
#define WAIT 0xFF /* Wait command */
struct INIDATA {
unsigned short addr;
unsigned short data;
} IniData;
/* Camera Module Big */
/* IMX230 + LC898212XD */
/* OV23850 + LC898212XD */
const struct INIDATA Init_Table_TVC820[] = {
/* Addr, Data */
/* TDK_CL-ACT_ 212_SPtype_Ini_130114 */
{0x0080, 0x34}, /* CLKSEL 1/1, CLKON */
{0x0081, 0x20}, /* AD 4Time */
{0x0084, 0xE0}, /* STBY AD ON,DA ON,OP ON */
{0x0087, 0x05}, /* PIDSW OFF,AF ON,MS2 ON */
{0x00A4, 0x24}, /* Internal OSC Setup (No01=24.18MHz) */
{0x003A, 0x0000}, /* OFFSET Clear */
{0x0004, 0x0000}, /* RZ Clear(Target Value) */
{0x0002, 0x0000}, /* PIDZO Clear */
{0x0018, 0x0000}, /* MS1Z22 Clear(STMV Target Value) */
/* Filter Setting: ST140911-1.h For TVC-820 */
{0x0088, 0x68},
{0x0028, 0x8080},
{0x004C, 0x4000},
{0x0083, 0x2C},
{0x0085, 0xC0},
{WAIT, 1}, /* Wait 1 ms */
{0x0085, 0x00},
{0x0084, 0xE3},
{0x0097, 0x00},
{0x0098, 0x42},
{0x0099, 0x00},
{0x009A, 0x00},
{0x0086, 0x40},
{0x0040, 0x4030},
{0x0042, 0x7150},
{0x0044, 0x8F90},
{0x0046, 0x61B0},
{0x0048, 0x7FF0},
{0x004A, 0x3930},
{0x004C, 0x4030},
/* {0x004E, 0x7FF0}, */
{0x004E, 0x8010},
{0x0050, 0x04f0},
{0x0052, 0x7610},
{0x0054, 0x2030},
{0x0056, 0x0000},
{0x0058, 0x7FF0},
{0x005A, 0x0680},
{0x005C, 0x72f0},
{0x005E, 0x7f70},
{0x0060, 0x7ed0},
{0x0062, 0x7ff0},
{0x0064, 0x0000},
{0x0066, 0x0000},
{0x0068, 0x5130},
{0x006A, 0x72f0},
{0x006C, 0x8010},
{0x006E, 0x0000},
{0x0070, 0x0000},
{0x0072, 0x18e0},
{0x0074, 0x4e30},
{0x0030, 0x0000},
{0x0076, 0x0C50},
{0x0078, 0x4000},
{WAIT, 5}, /* Wait 5 ms */
{0x0086, 0x60},
{0x0087, 0x85}
};
/* Camera Module Small */
/* IMX214 + LC898212XD */
/* IMX258 + LC898212XD */
const struct INIDATA Init_Table_TVC651[] = {
/* Addr, Data */
/* TDK_CL-ACT_ 212_SPtype_Ini_130114 */
{0x0080, 0x34}, /* CLKSEL 1/1, CLKON */
{0x0081, 0x20}, /* AD 4Time */
{0x0084, 0xE0}, /* STBY AD ON,DA ON,OP ON */
{0x0087, 0x05}, /* PIDSW OFF,AF ON,MS2 ON */
{0x00A4, 0x24}, /* Internal OSC Setup (No01=24.18MHz) */
{0x003A, 0x0000}, /* OFFSET Clear */
{0x0004, 0x0000}, /* RZ Clear(Target Value) */
{0x0002, 0x0000}, /* PIDZO Clear */
{0x0018, 0x0000}, /* MS1Z22 Clear(STMV Target Value) */
/* Filter Setting: ST140911-1.h For TVC-651 */
{0x0088, 0x70},
{0x0028, 0x8080},
{0x004C, 0x4000},
{0x0083, 0x2C},
{0x0085, 0xC0},
{WAIT, 1}, /* Wait 1 ms */
{0x0085, 0x00},
{0x0084, 0xE3},
{0x0097, 0x00},
{0x0098, 0x42},
{0x0099, 0x00},
{0x009A, 0x00},
{0x0086, 0x40},
{0x0040, 0x7ff0},
{0x0042, 0x7150},
{0x0044, 0x8F90},
{0x0046, 0x61B0},
{0x0048, 0x3930},
{0x004A, 0x2410},
{0x004C, 0x4030},
{0x004E, 0x7FF0},
/* {0x004E, 0x8010}, */
{0x0050, 0x04f0},
{0x0052, 0x7610},
{0x0054, 0x1450},
{0x0056, 0x0000},
{0x0058, 0x7FF0},
{0x005A, 0x0680},
{0x005C, 0x72f0},
{0x005E, 0x7f70},
{0x0060, 0x7ed0},
{0x0062, 0x7ff0},
{0x0064, 0x0000},
{0x0066, 0x0000},
{0x0068, 0x5130},
{0x006A, 0x72f0},
{0x006C, 0x8010},
{0x006E, 0x0000},
{0x0070, 0x0000},
{0x0072, 0x18e0},
{0x0074, 0x4e30},
{0x0030, 0x0000},
{0x0076, 0x0C50},
{0x0078, 0x4000},
{WAIT, 5}, /* Wait 5 ms */
{0x0086, 0x60},
{0x0087, 0x85}
};
@@ -0,0 +1,176 @@
/* SPDX-License-Identifier: GPL-2.0 */
/*
* Copyright (c) 2019 MediaTek Inc.
*/
/* Delay RAM 00h �` 3‚eh */
#define ADHXI_211H 0x00
#define ADHXI_211L 0x01
#define PIDZO_211H 0x02
#define PIDZO_211L 0x03
#define RZ_211H 0x04
#define RZ_211L 0x05
#define DZ1_211H 0x06
#define DZ1_211L 0x07
#define DZ2_211H 0x08
#define DZ2_211L 0x09
#define UZ1_211H 0x0A
#define UZ1_211L 0x0B
#define UZ2_211H 0x0C
#define UZ2_211L 0x0D
#define IZ1_211H 0x0E
#define IZ1_211L 0x0F
#define IZ2_211H 0x10
#define IZ2_211L 0x11
#define MS1Z01_211H 0x12
#define MS1Z01_211L 0x13
#define MS1Z11_211H 0x14
#define MS1Z11_211L 0x15
#define MS1Z12_211H 0x16
#define MS1Z12_211L 0x17
#define MS1Z22_211H 0x18
#define MS1Z22_211L 0x19
#define MS2Z01_211H 0x1A
#define MS2Z01_211L 0x1B
#define MS2Z11_211H 0x1C
#define MS2Z11_211L 0x1D
#define MS2Z12_211H 0x1E
#define MS2Z12_211L 0x1F
#define MS2Z22_211H 0x20
#define MS2Z22_211L 0x21
#define MS2Z23_211H 0x22
#define MS2Z23_211L 0x23
#define OZ1_211H 0x24
#define OZ1_211L 0x25
#define OZ2_211H 0x26
#define OZ2_211L 0x27
#define DAHLXO_211H 0x28
#define DAHLXO_211L 0x29
#define OZ3_211H 0x2A
#define OZ3_211L 0x2B
#define OZ4_211H 0x2C
#define OZ4_211L 0x2D
#define OZ5_211H 0x2E
#define OZ5_211L 0x2F
#define oe_211H 0x30
#define oe_211L 0x31
#define MSR1CMAX_211H 0x32
#define MSR1CMAX_211L 0x33
#define MSR1CMIN_211H 0x34
#define MSR1CMIN_211L 0x35
#define MSR2CMAX_211H 0x36
#define MSR2CMAX_211L 0x37
#define MSR2CMIN_211H 0x38
#define MSR2CMIN_211L 0x39
#define OFFSET_211H 0x3A
#define OFFSET_211L 0x3B
#define ADOFFSET_211H 0x3C
#define ADOFFSET_211L 0x3D
#define EZ_211H 0x3E
#define EZ_211L 0x3F
/* Coefficient RAM 40h �` 7Fh */
#define ag_211H 0x40
#define ag_211L 0x41
#define da_211H 0x42
#define da_211L 0x43
#define db_211H 0x44
#define db_211L 0x45
#define dc_211H 0x46
#define dc_211L 0x47
#define dg_211H 0x48
#define dg_211L 0x49
#define pg_211H 0x4A
#define pg_211L 0x4B
#define gain1_211H 0x4C
#define gain1_211L 0x4D
#define gain2_211H 0x4E
#define gain2_211L 0x4F
#define ua_211H 0x50
#define ua_211L 0x51
#define uc_211H 0x52
#define uc_211L 0x53
#define ia_211H 0x54
#define ia_211L 0x55
#define ib_211H 0x56
#define ib_211L 0x57
#define ic_211H 0x58
#define ic_211L 0x59
#define ms11a_211H 0x5A
#define ms11a_211L 0x5B
#define ms11c_211H 0x5C
#define ms11c_211L 0x5D
#define ms12a_211H 0x5E
#define ms12a_211L 0x5F
#define ms12c_211H 0x60
#define ms12c_211L 0x61
#define ms21a_211H 0x62
#define ms21a_211L 0x63
#define ms21b_211H 0x64
#define ms21b_211L 0x65
#define ms21c_211H 0x66
#define ms21c_211L 0x67
#define ms22a_211H 0x68
#define ms22a_211L 0x69
#define ms22c_211H 0x6A
#define ms22c_211L 0x6B
#define ms22d_211H 0x6C
#define ms22d_211L 0x6D
#define ms22e_211H 0x6E
#define ms22e_211L 0x6F
#define ms23p_211H 0x70
#define ms23p_211L 0x71
#define oa_211H 0x72
#define oa_211L 0x73
#define oc_211H 0x74
#define oc_211L 0x75
#define PX12_211H 0x76
#define PX12_211L 0x77
#define PX3_211H 0x78
#define PX3_211L 0x79
#define MS2X_211H 0x7A
#define MS2X_211L 0x7B
#define CHTGX_211H 0x7C
#define CHTGX_211L 0x7D
#define CHTGN_211H 0x7E
#define CHTGN_211L 0x7F
/* Register 80h �` 9F */
#define CLKSEL_211 0x80
#define ADSET_211 0x81
#define PWMSEL_211 0x82
#define SWTCH_211 0x83
#define STBY_211 0x84
#define CLR_211 0x85
#define DSSEL_211 0x86
#define ENBL_211 0x87
#define ANA1_211 0x88
#define AFSEND_211 0x8A
#define STMVEN_211 0x8A
#define STPT_211 0x8B
#define SWFC_211 0x8C
#define SWEN_211 0x8D
#define MSNUM_211 0x8E
#define MSSET_211 0x8F
#define DLYMON_211 0x90
#define MONA_211 0x91
#define PWMLIMIT_211 0x92
#define PINSEL_211 0x93
#define PWMSEL2_211 0x94
#define SFTRST_211 0x95
#define TEST_211 0x96
#define PWMZONE2_211 0x97
#define PWMZONE1_211 0x98
#define PWMZONE0_211 0x99
#define ZONE3_211 0x9A
#define ZONE2_211 0x9B
#define ZONE1_211 0x9C
#define ZONE0_211 0x9D
#define GCTIM_211 0x9E
#define GCTIM_211NU 0x9F
#define STMINT_211 0xA0
#define STMVENDH_211 0xA1
#define STMVENDL_211 0xA2
#define MSNUMR_211 0xA3
#define ANA2_211 0xA4
@@ -0,0 +1,27 @@
/* SPDX-License-Identifier: GPL-2.0 */
/*
* Copyright (c) 2019 MediaTek Inc.
*/
#ifndef __AFINIT__
#define __AFINIT__
extern void AfInit(unsigned char hall_bias, unsigned char hall_off);
extern void ServoOn(void);
extern unsigned int g_LC898212_SearchDir;
extern void RamWriteA(unsigned short addr, unsigned short data);
extern void RamReadA(unsigned short addr, unsigned short *data);
extern void RegWriteA(unsigned short addr, unsigned char data);
extern void RegReadA(unsigned short addr, unsigned char *data);
extern void WaitTime(unsigned short msec);
#endif /* __AFINIT__ */
@@ -0,0 +1,64 @@
/* SPDX-License-Identifier: GPL-2.0 */
/*
* Copyright (c) 2019 MediaTek Inc.
*/
#ifndef __AFSTMV__
#define __AFSTMV__
#define INI_MSSET_211 ((unsigned char)0x00)
#define CHTGX_THRESHOLD ((unsigned short)0x0200)
#define CHTGOKN_TIME ((unsigned char)0x80)
#define CHTGOKN_WAIT 3
#define STMV_SIZE ((unsigned short)0x0180)
#define STMV_INTERVAL ((unsigned char)0x01)
#define STMCHTG_ON ((unsigned char)0x08)
#define STMSV_ON ((unsigned char)0x04)
#define STMLFF_ON ((unsigned char)0x02)
#define STMVEN_ON ((unsigned char)0x01)
#define STMCHTG_OFF ((unsigned char)0x00)
#define STMSV_OFF ((unsigned char)0x00)
#define STMLFF_OFF ((unsigned char)0x00)
#define STMVEN_OFF ((unsigned char)0x00)
#define STMCHTG_SET STMCHTG_ON
#define STMSV_SET STMSV_ON
#define STMLFF_SET STMLFF_OFF
struct stSmvPar {
unsigned short UsSmvSiz;
unsigned char UcSmvItv;
unsigned char UcSmvEnb;
};
/* Step Move Parameter Setting Function */
extern void StmvSet(struct stSmvPar D1);
/* Step Move to Target Position Function */
extern unsigned char StmvTo(short D2);
extern void RamWriteA(unsigned short addr, unsigned short data);
extern void RamReadA(unsigned short addr, unsigned short *data);
extern void RegWriteA(unsigned short addr, unsigned char data);
extern void RegReadA(unsigned short addr, unsigned char *data);
extern void WaitTime(unsigned short msec);
extern int s4AF_WriteReg_LC898212XDAF(unsigned char *a_pSendData,
unsigned short a_sizeSendData,
unsigned short i2cId);
extern int s4AF_ReadReg_LC898212XDAF(unsigned char *a_pSendData,
unsigned short a_sizeSendData,
unsigned char *a_pRecvData,
unsigned short a_sizeRecvData,
unsigned short i2cId);
#endif /* __AFSTMV__ */
@@ -0,0 +1,813 @@
// SPDX-License-Identifier: GPL-2.0
/*
* Copyright (c) 2019 MediaTek Inc.
*/
/*
* LC898212XD_TVC700 voice coil motor driver
*
*
*/
#include <linux/delay.h>
#include <linux/fs.h>
#include <linux/i2c.h>
#include <linux/uaccess.h>
#include "lens_info.h"
#define AF_DRVNAME "212XD_TVC700_DRV"
#define AF_I2C_SLAVE_ADDR 0xE4
#define EEPROM_I2C_SLAVE_ADDR 0xA0
#define AF_DEBUG
#ifdef AF_DEBUG
#define LOG_INF(format, args...) \
pr_info(AF_DRVNAME " [%s] " format, __func__, ##args)
#else
#define LOG_INF(format, args...)
#endif
static struct i2c_client *g_pstAF_I2Cclient;
static int *g_pAF_Opened;
static spinlock_t *g_pAF_SpinLock;
static unsigned long g_u4AF_INF;
static unsigned long g_u4AF_MACRO = 1023;
static unsigned long g_u4CurrPosition;
#define Min_Pos 0
#define Max_Pos 1023
/* LiteOn : Hall calibration range : 0xA800 - 0x5800 */
static signed short Hall_Max =
0x5800; /* Please read INF position from EEPROM or OTP */
static signed short Hall_Min =
0xA800; /* Please read MACRO position from EEPROM or OTP */
static int s4AF_ReadReg_LC898212XD_TVC820(u8 *a_pSendData, u16 a_sizeSendData,
u8 *a_pRecvData, u16 a_sizeRecvData,
u16 i2cId)
{
int i4RetValue = 0;
g_pstAF_I2Cclient->addr = i2cId >> 1;
i4RetValue =
i2c_master_send(g_pstAF_I2Cclient, a_pSendData, a_sizeSendData);
if (i4RetValue != a_sizeSendData) {
LOG_INF("I2C send failed!!, Addr = 0x%x\n", a_pSendData[0]);
return -1;
}
i4RetValue = i2c_master_recv(g_pstAF_I2Cclient, (u8 *)a_pRecvData,
a_sizeRecvData);
if (i4RetValue != a_sizeRecvData) {
LOG_INF("I2C read failed!!\n");
return -1;
}
return 0;
}
static int s4AF_WriteReg_LC898212XD_TVC820(u8 *a_pSendData, u16 a_sizeSendData,
u16 i2cId)
{
int i4RetValue = 0;
g_pstAF_I2Cclient->addr = i2cId >> 1;
i4RetValue =
i2c_master_send(g_pstAF_I2Cclient, a_pSendData, a_sizeSendData);
if (i4RetValue < 0) {
LOG_INF("I2C send failed!!, Addr = 0x%x, Data = 0x%x\n",
a_pSendData[0], a_pSendData[1]);
return -1;
}
return 0;
}
/* ////////////////////////////////////////////////////////////// */
#define INI_MSSET_211 ((unsigned char)0x00)
#define CHTGX_THRESHOLD ((unsigned short)0x0200)
#define CHTGOKN_TIME ((unsigned char)0x80)
#define CHTGOKN_WAIT 3
#define STMV_SIZE ((unsigned short)0x0180)
#define STMV_INTERVAL ((unsigned char)0x01)
#define STMCHTG_ON ((unsigned char)0x08)
#define STMSV_ON ((unsigned char)0x04)
#define STMLFF_ON ((unsigned char)0x02)
#define STMVEN_ON ((unsigned char)0x01)
#define STMCHTG_OFF ((unsigned char)0x00)
#define STMSV_OFF ((unsigned char)0x00)
#define STMLFF_OFF ((unsigned char)0x00)
#define STMVEN_OFF ((unsigned char)0x00)
#define STMCHTG_SET STMCHTG_ON
#define STMSV_SET STMSV_ON
#define STMLFF_SET STMLFF_OFF
struct stSmvPar {
unsigned short UsSmvSiz;
unsigned char UcSmvItv;
unsigned char UcSmvEnb;
};
/* *********************************************************** */
/* LC89821x Initialize Data Table */
/* *********************************************************** */
#define WAIT 0xFF /* Wait command */
struct INIDATAT {
unsigned short addr;
unsigned short data;
} IniDataT;
/* Camera Module Big */
/* 2L7 + LC898212XD_TVC700 */
static const struct INIDATAT Init_Table_TVC820[] = {
/* Addr, Data */
/* TDK_CL-ACT_ 212_SPtype_Ini_130114 */
{0x0080, 0x34}, /* CLKSEL 1/1, CLKON */
{0x0081, 0x20}, /* AD 4Time */
{0x0084, 0xE0}, /* STBY AD ON,DA ON,OP ON */
{0x0087, 0x05}, /* PIDSW OFF,AF ON,MS2 ON */
{0x00A4, 0x24}, /* Internal OSC Setup (No01=24.18MHz) */
{0x003A, 0x0000}, /* OFFSET Clear */
{0x0004, 0x0000}, /* RZ Clear(Target Value) */
{0x0002, 0x0000}, /* PIDZO Clear */
{0x0018, 0x0000}, /* MS1Z22 Clear(STMV Target Value) */
/* Filter Setting: ST140911-1.h For TVC-820 */
{0x0088, 0x70},
{0x0028, 0x8080},
{0x004C, 0x4000},
{0x0083, 0x2C},
{0x0085, 0xC0},
{WAIT, 1}, /* Wait 1 ms */
/* {0x0085, 0x00}, */
{0x0084, 0xE3},
{0x0097, 0x00},
{0x0098, 0x42},
{0x0099, 0x00},
{0x009A, 0x00},
{0x0086, 0x40},
{0x0040, 0x4030},
{0x0042, 0x7150},
{0x0044, 0x8F90},
{0x0046, 0x61B0},
{0x0048, 0x7FF0},
{0x004A, 0x3930},
{0x004C, 0x4030},
{0x004E, 0x8010},
{0x0050, 0x04f0},
{0x0052, 0x7610},
{0x0054, 0x2030},
{0x0056, 0x0000},
{0x0058, 0x7FF0},
{0x005A, 0x0680},
{0x005C, 0x72f0},
{0x005E, 0x7f70},
{0x0060, 0x7ed0},
{0x0062, 0x7ff0},
{0x0064, 0x0000},
{0x0066, 0x0000},
{0x0068, 0x5130},
{0x006A, 0x72f0},
{0x006C, 0x8010},
{0x006E, 0x0000},
{0x0070, 0x0000},
{0x0072, 0x18e0},
{0x0074, 0x4e30},
{0x0030, 0x0000},
{0x0076, 0x0C50},
{0x0078, 0x4000},
{WAIT, 5}, /* Wait 5 ms */
{0x0086, 0x60},
{0x0087, 0x85}
};
#define ADHXI_211H 0x00
#define ADHXI_211L 0x01
#define PIDZO_211H 0x02
#define PIDZO_211L 0x03
#define RZ_211H 0x04
#define RZ_211L 0x05
#define DZ1_211H 0x06
#define DZ1_211L 0x07
#define DZ2_211H 0x08
#define DZ2_211L 0x09
#define UZ1_211H 0x0A
#define UZ1_211L 0x0B
#define UZ2_211H 0x0C
#define UZ2_211L 0x0D
#define IZ1_211H 0x0E
#define IZ1_211L 0x0F
#define IZ2_211H 0x10
#define IZ2_211L 0x11
#define MS1Z01_211H 0x12
#define MS1Z01_211L 0x13
#define MS1Z11_211H 0x14
#define MS1Z11_211L 0x15
#define MS1Z12_211H 0x16
#define MS1Z12_211L 0x17
#define MS1Z22_211H 0x18
#define MS1Z22_211L 0x19
#define MS2Z01_211H 0x1A
#define MS2Z01_211L 0x1B
#define MS2Z11_211H 0x1C
#define MS2Z11_211L 0x1D
#define MS2Z12_211H 0x1E
#define MS2Z12_211L 0x1F
#define MS2Z22_211H 0x20
#define MS2Z22_211L 0x21
#define MS2Z23_211H 0x22
#define MS2Z23_211L 0x23
#define OZ1_211H 0x24
#define OZ1_211L 0x25
#define OZ2_211H 0x26
#define OZ2_211L 0x27
#define DAHLXO_211H 0x28
#define DAHLXO_211L 0x29
#define OZ3_211H 0x2A
#define OZ3_211L 0x2B
#define OZ4_211H 0x2C
#define OZ4_211L 0x2D
#define OZ5_211H 0x2E
#define OZ5_211L 0x2F
#define oe_211H 0x30
#define oe_211L 0x31
#define MSR1CMAX_211H 0x32
#define MSR1CMAX_211L 0x33
#define MSR1CMIN_211H 0x34
#define MSR1CMIN_211L 0x35
#define MSR2CMAX_211H 0x36
#define MSR2CMAX_211L 0x37
#define MSR2CMIN_211H 0x38
#define MSR2CMIN_211L 0x39
#define OFFSET_211H 0x3A
#define OFFSET_211L 0x3B
#define ADOFFSET_211H 0x3C
#define ADOFFSET_211L 0x3D
#define EZ_211H 0x3E
#define EZ_211L 0x3F
#define ag_211H 0x40
#define ag_211L 0x41
#define da_211H 0x42
#define da_211L 0x43
#define db_211H 0x44
#define db_211L 0x45
#define dc_211H 0x46
#define dc_211L 0x47
#define dg_211H 0x48
#define dg_211L 0x49
#define pg_211H 0x4A
#define pg_211L 0x4B
#define gain1_211H 0x4C
#define gain1_211L 0x4D
#define gain2_211H 0x4E
#define gain2_211L 0x4F
#define ua_211H 0x50
#define ua_211L 0x51
#define uc_211H 0x52
#define uc_211L 0x53
#define ia_211H 0x54
#define ia_211L 0x55
#define ib_211H 0x56
#define ib_211L 0x57
#define ic_211H 0x58
#define ic_211L 0x59
#define ms11a_211H 0x5A
#define ms11a_211L 0x5B
#define ms11c_211H 0x5C
#define ms11c_211L 0x5D
#define ms12a_211H 0x5E
#define ms12a_211L 0x5F
#define ms12c_211H 0x60
#define ms12c_211L 0x61
#define ms21a_211H 0x62
#define ms21a_211L 0x63
#define ms21b_211H 0x64
#define ms21b_211L 0x65
#define ms21c_211H 0x66
#define ms21c_211L 0x67
#define ms22a_211H 0x68
#define ms22a_211L 0x69
#define ms22c_211H 0x6A
#define ms22c_211L 0x6B
#define ms22d_211H 0x6C
#define ms22d_211L 0x6D
#define ms22e_211H 0x6E
#define ms22e_211L 0x6F
#define ms23p_211H 0x70
#define ms23p_211L 0x71
#define oa_211H 0x72
#define oa_211L 0x73
#define oc_211H 0x74
#define oc_211L 0x75
#define PX12_211H 0x76
#define PX12_211L 0x77
#define PX3_211H 0x78
#define PX3_211L 0x79
#define MS2X_211H 0x7A
#define MS2X_211L 0x7B
#define CHTGX_211H 0x7C
#define CHTGX_211L 0x7D
#define CHTGN_211H 0x7E
#define CHTGN_211L 0x7F
#define CLKSEL_211 0x80
#define ADSET_211 0x81
#define PWMSEL_211 0x82
#define SWTCH_211 0x83
#define STBY_211 0x84
#define CLR_211 0x85
#define DSSEL_211 0x86
#define ENBL_211 0x87
#define ANA1_211 0x88
#define AFSEND_211 0x8A
#define STMVEN_211 0x8A
#define STPT_211 0x8B
#define SWFC_211 0x8C
#define SWEN_211 0x8D
#define MSNUM_211 0x8E
#define MSSET_211 0x8F
#define DLYMON_211 0x90
#define MONA_211 0x91
#define PWMLIMIT_211 0x92
#define PINSEL_211 0x93
#define PWMSEL2_211 0x94
#define SFTRST_211 0x95
#define TEST_211 0x96
#define PWMZONE2_211 0x97
#define PWMZONE1_211 0x98
#define PWMZONE0_211 0x99
#define ZONE3_211 0x9A
#define ZONE2_211 0x9B
#define ZONE1_211 0x9C
#define ZONE0_211 0x9D
#define GCTIM_211 0x9E
#define GCTIM_211NU 0x9F
#define STMINT_211 0xA0
#define STMVENDH_211 0xA1
#define STMVENDL_211 0xA2
#define MSNUMR_211 0xA3
#define ANA2_211 0xA4
/* ////////////////////////////////////////////////////////////// */
/****************************/
/* Definations */
/****************************/
#define ABS_STMV(x) ((x) < 0 ? -(x) : (x))
#define LC898211_fs 234375
#ifdef DEBUG_LOG
#define AF_REGDUMP "REGDUMP"
#define LOG_INF(format, args...) pr_info(AF_REGDUMP " " format, ##args)
#endif
#define REG_ADDR_START 0x80 /* REG Start address */
#define DeviceAddr 0xE4 /* Device address of driver IC */
static struct stSmvPar StSmvPar;
static void RamWriteA(unsigned short addr, unsigned short data)
{
u8 puSendCmd[3] = {(u8)(addr & 0xFF), (u8)(data >> 8),
(u8)(data & 0xFF)};
s4AF_WriteReg_LC898212XD_TVC820(puSendCmd, sizeof(puSendCmd),
DeviceAddr);
#ifdef DEBUG_LOG
LOG_INF("RAMW\t%x\t%x\n", addr, data);
#endif
}
static void RamReadA(unsigned short addr, unsigned short *data)
{
u8 buf[2];
u8 puSendCmd[1] = {(u8)(addr & 0xFF)};
s4AF_ReadReg_LC898212XD_TVC820(puSendCmd, sizeof(puSendCmd), buf, 2,
DeviceAddr);
*data = (buf[0] << 8) | (buf[1] & 0x00FF);
#ifdef DEBUG_LOG
LOG_INF("RAMR\t%x\t%x\n", addr, *data);
#endif
}
static void RegWriteA(unsigned short addr, unsigned char data)
{
u8 puSendCmd[2] = {(u8)(addr & 0xFF), (u8)(data & 0xFF)};
s4AF_WriteReg_LC898212XD_TVC820(puSendCmd, sizeof(puSendCmd),
DeviceAddr);
#ifdef DEBUG_LOG
LOG_INF("REGW\t%x\t%x\n", addr, data);
#endif
}
static void RegReadA(unsigned short addr, unsigned char *data)
{
u8 puSendCmd[1] = {(u8)(addr & 0xFF)};
s4AF_ReadReg_LC898212XD_TVC820(puSendCmd, sizeof(puSendCmd), data, 1,
DeviceAddr);
#ifdef DEBUG_LOG
LOG_INF("REGR\t%x\t%x\n", addr, *data);
#endif
}
static void WaitTime(unsigned short msec)
{
usleep_range(msec * 1000, (msec + 1) * 1000);
}
static void StmvSet(struct stSmvPar StSetSmv)
{
unsigned char UcSetEnb;
unsigned char UcSetSwt;
unsigned short UsParSiz;
unsigned char UcParItv;
short SsParStt; /* StepMove Start Position */
StSmvPar.UsSmvSiz = StSetSmv.UsSmvSiz;
StSmvPar.UcSmvItv = StSetSmv.UcSmvItv;
StSmvPar.UcSmvEnb = StSetSmv.UcSmvEnb;
RegWriteA(AFSEND_211, 0x00); /* StepMove Enable Bit Clear */
RegReadA(ENBL_211, &UcSetEnb);
UcSetEnb &= (unsigned char)0xFD;
RegWriteA(ENBL_211, UcSetEnb); /* Measuremenet Circuit1 Off */
RegReadA(SWTCH_211, &UcSetSwt);
UcSetSwt &= (unsigned char)0x7F;
RegWriteA(SWTCH_211, UcSetSwt); /* RZ1 Switch Cut Off */
RamReadA(RZ_211H, (unsigned short *)&SsParStt); /* Get Start Position */
UsParSiz = StSetSmv.UsSmvSiz; /* Get StepSize */
UcParItv = StSetSmv.UcSmvItv; /* Get StepInterval */
RamWriteA(ms11a_211H, (unsigned short)0x0800);
RamWriteA(MS1Z22_211H,
(unsigned short)SsParStt); /* Set Start Position */
RamWriteA(MS1Z12_211H, UsParSiz); /* Set StepSize */
RegWriteA(STMINT_211, UcParItv); /* Set StepInterval */
UcSetSwt |= (unsigned char)0x80;
RegWriteA(SWTCH_211, UcSetSwt); /* RZ1 Switch ON */
}
static unsigned char StmvTo(short SsSmvEnd)
{
unsigned short UsSmvDpl;
short SsParStt; /* StepMove Start Position */
/* PIOA_SetOutput(_PIO_PA29); // Monitor I/O Port */
RamReadA(RZ_211H, (unsigned short *)&SsParStt); /* Get Start Position */
UsSmvDpl = ABS_STMV(SsParStt - SsSmvEnd);
if ((UsSmvDpl <= StSmvPar.UsSmvSiz) &&
((StSmvPar.UcSmvEnb & STMSV_ON) == STMSV_ON)) {
if (StSmvPar.UcSmvEnb & STMCHTG_ON)
RegWriteA(MSSET_211,
INI_MSSET_211 | (unsigned char)0x01);
RamWriteA(MS1Z22_211H,
SsSmvEnd); /* Handling Single Step For ES1 */
StSmvPar.UcSmvEnb |= STMVEN_ON;
} else {
if (SsParStt < SsSmvEnd) { /* Check StepMove Direction */
RamWriteA(MS1Z12_211H, StSmvPar.UsSmvSiz);
} else if (SsParStt > SsSmvEnd) {
RamWriteA(MS1Z12_211H, -StSmvPar.UsSmvSiz);
}
RamWriteA(STMVENDH_211,
SsSmvEnd); /* Set StepMove Target Position */
StSmvPar.UcSmvEnb |= STMVEN_ON;
RegWriteA(STMVEN_211, StSmvPar.UcSmvEnb); /* Start StepMove */
}
return 0;
}
static void AfInit(unsigned char hall_off, unsigned char hall_bias)
{
unsigned int DataLen;
unsigned short i;
unsigned short pos;
/* IMX318, IMX230, OV23850 */
DataLen = sizeof(Init_Table_TVC820) / sizeof(IniDataT);
for (i = 0; i < DataLen; i++) {
if (Init_Table_TVC820[i].addr == WAIT) {
WaitTime(Init_Table_TVC820[i].data);
continue;
}
if (Init_Table_TVC820[i].addr >= REG_ADDR_START)
RegWriteA(Init_Table_TVC820[i].addr,
(unsigned char)(Init_Table_TVC820[i].data &
0x00ff));
else
RamWriteA(Init_Table_TVC820[i].addr,
(unsigned short)Init_Table_TVC820[i].data);
}
RegWriteA(0x28, hall_off); /* Hall Offset */
RegWriteA(0x29, hall_bias); /* Hall Bias */
RamReadA(0x3C, &pos);
RamWriteA(0x04, pos); /* Direct move target position */
RamWriteA(0x18, pos); /* Step move start position */
/* WaitTime(5); */
/* RegWriteA( 0x87, 0x85 ); // Servo ON */
}
static void ServoOn(void)
{
RegWriteA(0x85, 0x80); /* Clear PID Ram Data */
WaitTime(1);
RegWriteA(0x87, 0x85); /* Servo ON */
}
/* ////////////////////////////////////////////////////////////// */
static int s4EEPROM_ReadReg(u16 addr, u8 *data)
{
int i4RetValue = 0;
u8 puSendCmd[2] = {(u8)(addr >> 8), (u8)(addr & 0xFF)};
i4RetValue = s4AF_ReadReg_LC898212XD_TVC820(
puSendCmd, sizeof(puSendCmd), data, 1, EEPROM_I2C_SLAVE_ADDR);
if (i4RetValue < 0)
LOG_INF("I2C read e2prom failed!!\n");
return i4RetValue;
}
static void s4AF_WriteReg(unsigned short addr, unsigned char data)
{
u8 puSendCmd[2] = {(u8)(addr & 0xFF), (u8)(data & 0xFF)};
s4AF_WriteReg_LC898212XD_TVC820(puSendCmd, sizeof(puSendCmd),
AF_I2C_SLAVE_ADDR);
}
static void LC898212XD_init(void)
{
struct stSmvPar StSmvPar;
u8 val1 = 0, val2 = 0;
int Hall_Off = 0x80; /* Please Read Offset from EEPROM or OTP */
int Hall_Bias = 0x80; /* Please Read Bias from EEPROM or OTP */
s4EEPROM_ReadReg(0xF67, &val1);
s4EEPROM_ReadReg(0xF68, &val2);
Hall_Off = val1;
Hall_Bias = val2;
LOG_INF("hallmax:0x%x, hallmin:0x%x, halloff:0x%x, hallbias:0x%x\n",
Hall_Max, Hall_Min, Hall_Off, Hall_Bias);
/* Wake up */
s4AF_WriteReg(0x80, 0x68);
s4AF_WriteReg(0x80, 0x64);
s4AF_WriteReg(0x95, 0x00);
AfInit(Hall_Off, Hall_Bias); /* Initialize driver IC */
/* Step move parameter set */
StSmvPar.UsSmvSiz = STMV_SIZE;
StSmvPar.UcSmvItv = STMV_INTERVAL;
StSmvPar.UcSmvEnb = STMCHTG_SET | STMSV_SET | STMLFF_SET;
StmvSet(StSmvPar);
ServoOn(); /* Close loop ON */
}
static unsigned short AF_convert(int position)
{
/* 1: INF -> Macro = 0x8001 -> 0x7FFF */
return (((position - Min_Pos) * (unsigned short)(Hall_Max - Hall_Min) /
(Max_Pos - Min_Pos)) +
Hall_Min) &
0xFFFF;
}
static inline int getAFInfo(__user struct stAF_MotorInfo *pstMotorInfo)
{
struct stAF_MotorInfo stMotorInfo;
stMotorInfo.u4MacroPosition = g_u4AF_MACRO;
stMotorInfo.u4InfPosition = g_u4AF_INF;
stMotorInfo.u4CurrentPosition = g_u4CurrPosition;
stMotorInfo.bIsSupportSR = 1;
stMotorInfo.bIsMotorMoving = 1;
if (*g_pAF_Opened >= 1)
stMotorInfo.bIsMotorOpen = 1;
else
stMotorInfo.bIsMotorOpen = 0;
if (copy_to_user(pstMotorInfo, &stMotorInfo,
sizeof(struct stAF_MotorInfo)))
LOG_INF("copy to user failed when getting motor information\n");
return 0;
}
/* initAF include driver initialization and standby mode */
static int initAF(void)
{
LOG_INF("+\n");
if (*g_pAF_Opened == 1) {
LC898212XD_init();
spin_lock(g_pAF_SpinLock);
*g_pAF_Opened = 2;
spin_unlock(g_pAF_SpinLock);
}
LOG_INF("-\n");
return 0;
}
/* moveAF only use to control moving the motor */
static inline int moveAF(unsigned long a_u4Position)
{
int ret = 0;
if ((StmvTo(AF_convert((int)a_u4Position)) & 0x1) == 0) {
g_u4CurrPosition = a_u4Position;
ret = 0;
} else {
LOG_INF("set I2C failed when moving the motor\n");
ret = -1;
}
return ret;
}
static inline int setAFInf(unsigned long a_u4Position)
{
spin_lock(g_pAF_SpinLock);
g_u4AF_INF = a_u4Position;
spin_unlock(g_pAF_SpinLock);
return 0;
}
static inline int setAFMacro(unsigned long a_u4Position)
{
spin_lock(g_pAF_SpinLock);
g_u4AF_MACRO = a_u4Position;
spin_unlock(g_pAF_SpinLock);
return 0;
}
static inline int getAFCalPos(__user struct stAF_MotorCalPos *pstMotorCalPos)
{
struct stAF_MotorCalPos stMotorCalPos;
stMotorCalPos.u4MacroPos = 0;
stMotorCalPos.u4InfPos = 0;
if (copy_to_user(pstMotorCalPos, &stMotorCalPos, sizeof(stMotorCalPos)))
LOG_INF("copy to user failed when getting motor information\n");
return 0;
}
/* ////////////////////////////////////////////////////////////// */
long LC898212XD_TVC700_Ioctl(struct file *a_pstFile, unsigned int a_u4Command,
unsigned long a_u4Param)
{
long i4RetValue = 0;
switch (a_u4Command) {
case AFIOC_G_MOTORINFO:
i4RetValue =
getAFInfo((__user struct stAF_MotorInfo *)(a_u4Param));
break;
case AFIOC_T_MOVETO:
i4RetValue = moveAF(a_u4Param);
break;
case AFIOC_T_SETINFPOS:
i4RetValue = setAFInf(a_u4Param);
break;
case AFIOC_T_SETMACROPOS:
i4RetValue = setAFMacro(a_u4Param);
break;
case AFIOC_G_MOTORCALPOS:
i4RetValue = getAFCalPos(
(__user struct stAF_MotorCalPos *)(a_u4Param));
break;
default:
LOG_INF("No CMD\n");
i4RetValue = -EPERM;
break;
}
return i4RetValue;
}
/* Main jobs: */
/* 1.Deallocate anything that "open" allocated in private_data. */
/* 2.Shut down the device on last close. */
/* 3.Only called once on last time. */
/* Q1 : Try release multiple times. */
int LC898212XD_TVC700_Release(struct inode *a_pstInode, struct file *a_pstFile)
{
LOG_INF("Start\n");
if (*g_pAF_Opened == 2) {
LOG_INF("Wait\n");
/* Sleep In */
s4AF_WriteReg(0x95, 0x80);
s4AF_WriteReg(0x80, 0x68);
s4AF_WriteReg(0x80, 0x69);
msleep(20);
}
if (*g_pAF_Opened) {
LOG_INF("Free\n");
spin_lock(g_pAF_SpinLock);
*g_pAF_Opened = 0;
spin_unlock(g_pAF_SpinLock);
}
LOG_INF("End\n");
return 0;
}
int LC898212XD_TVC700_SetI2Cclient(struct i2c_client *pstAF_I2Cclient,
spinlock_t *pAF_SpinLock, int *pAF_Opened)
{
g_pstAF_I2Cclient = pstAF_I2Cclient;
g_pAF_SpinLock = pAF_SpinLock;
g_pAF_Opened = pAF_Opened;
initAF();
return 1;
}
int LC898212XD_TVC700_GetFileName(unsigned char *pFileName)
{
#if SUPPORT_GETTING_LENS_FOLDER_NAME
char FilePath[256];
char *FileString;
sprintf(FilePath, "%s", __FILE__);
FileString = strrchr(FilePath, '/');
*FileString = '\0';
FileString = (strrchr(FilePath, '/') + 1);
strncpy(pFileName, FileString, AF_MOTOR_NAME);
LOG_INF("FileName : %s\n", pFileName);
#else
pFileName[0] = '\0';
#endif
return 1;
}
@@ -0,0 +1,5 @@
#
# Makefile for misc devices that really don't fit anywhere else.
#
obj-y += LC898212XDAF_TVC700.o
@@ -0,0 +1,315 @@
// SPDX-License-Identifier: GPL-2.0
/*
* Copyright (c) 2019 MediaTek Inc.
*/
/*
* LC898214AF voice coil motor driver
*
*
*/
#include <linux/delay.h>
#include <linux/fs.h>
#include <linux/i2c.h>
#include <linux/uaccess.h>
#include "lens_info.h"
#define AF_DRVNAME "LC898214AF_DRV"
#define AF_I2C_SLAVE_ADDR 0xE4
#define EEPROM_I2C_SLAVE_ADDR 0xA0
#define AF_DEBUG
#ifdef AF_DEBUG
#define LOG_INF(format, args...) \
pr_debug(AF_DRVNAME " [%s] " format, __func__, ##args)
#else
#define LOG_INF(format, args...)
#endif
static struct i2c_client *g_pstAF_I2Cclient;
static int *g_pAF_Opened;
static spinlock_t *g_pAF_SpinLock;
static unsigned long g_u4AF_INF;
static unsigned long g_u4AF_MACRO = 1023;
static unsigned long g_u4CurrPosition;
#define Min_Pos 0
#define Max_Pos 1023
static signed short Hall_Max = 0x4500;
static signed short Hall_Min = 0xBB00;
static int s4EEPROM_ReadReg(u16 addr, u16 *data)
{
u8 u8data[2];
u8 pu_send_cmd[2] = {(u8)(addr >> 8), (u8)(addr & 0xFF)};
g_pstAF_I2Cclient->addr = (EEPROM_I2C_SLAVE_ADDR) >> 1;
if (i2c_master_send(g_pstAF_I2Cclient, pu_send_cmd, 2) < 0) {
LOG_INF("read I2C send failed!!\n");
return -1;
}
if (i2c_master_recv(g_pstAF_I2Cclient, u8data, 2) < 0) {
LOG_INF("EEPROM_ReadReg failed!!\n");
return -1;
}
LOG_INF("u8data[0] = 0x%x\n", u8data[0]);
LOG_INF("u8data[1] = 0x%x\n", u8data[1]);
*data = u8data[1] << 8 | u8data[0];
LOG_INF("EEPROM 0x%x, 0x%x\n", addr, *data);
return 0;
}
static int s4AF_ReadReg(u8 a_uAddr, u8 *a_uData)
{
g_pstAF_I2Cclient->addr = (AF_I2C_SLAVE_ADDR) >> 1;
if (i2c_master_send(g_pstAF_I2Cclient, &a_uAddr, 1) < 0) {
LOG_INF("ReadI2C send failed!!\n");
return -1;
}
if (i2c_master_recv(g_pstAF_I2Cclient, a_uData, 1) < 0) {
LOG_INF("ReadI2C recv failed!!\n");
return -1;
}
/* LOG_INF("ReadI2C 0x%x, 0x%x\n", a_uAddr, *a_uData); */
return 0;
}
static int s4AF_WriteReg(u8 a_uLength, u8 a_uAddr, u16 a_u2Data)
{
u8 puSendCmd[2] = {a_uAddr, (u8)(a_u2Data & 0xFF)};
u8 puSendCmd2[3] = {a_uAddr, (u8)((a_u2Data >> 8) & 0xFF),
(u8)(a_u2Data & 0xFF)};
g_pstAF_I2Cclient->addr = (AF_I2C_SLAVE_ADDR) >> 1;
if (a_uLength == 0) {
if (i2c_master_send(g_pstAF_I2Cclient, puSendCmd, 2) < 0) {
LOG_INF("WriteI2C failed!!\n");
return -1;
}
} else if (a_uLength == 1) {
if (i2c_master_send(g_pstAF_I2Cclient, puSendCmd2, 3) < 0) {
LOG_INF("WriteI2C 2 failed!!\n");
return -1;
}
}
return 0;
}
static unsigned short AF_convert(int position)
{
return (((Max_Pos - position) * (unsigned short)(Hall_Max - Hall_Min) /
(Max_Pos - Min_Pos)) + Hall_Min) & 0xFFFF;
}
static inline int getAFInfo(__user struct stAF_MotorInfo *pstMotorInfo)
{
struct stAF_MotorInfo stMotorInfo;
stMotorInfo.u4MacroPosition = g_u4AF_MACRO;
stMotorInfo.u4InfPosition = g_u4AF_INF;
stMotorInfo.u4CurrentPosition = g_u4CurrPosition;
stMotorInfo.bIsSupportSR = 1;
stMotorInfo.bIsMotorMoving = 1;
if (*g_pAF_Opened >= 1)
stMotorInfo.bIsMotorOpen = 1;
else
stMotorInfo.bIsMotorOpen = 0;
if (copy_to_user(pstMotorInfo, &stMotorInfo,
sizeof(struct stAF_MotorInfo)))
LOG_INF("copy to user failed when getting motor information\n");
return 0;
}
/* initAF include driver initialization and standby mode */
static int initAF(void)
{
LOG_INF("+\n");
if (*g_pAF_Opened == 1) {
unsigned char Temp;
unsigned short Data;
unsigned short Cnt;
s4EEPROM_ReadReg(0x0F63, &Data);
if (Data > 0 && Data < 0xFFFF)
Hall_Max = Data;
s4EEPROM_ReadReg(0x0F65, &Data);
if (Data > 0 && Data < 0xFFFF)
Hall_Min = Data;
s4AF_ReadReg(0xF0, &Temp);
if (Temp != 0x42) {
LOG_INF("Check Read F0h fail\n");
return -1;
}
s4AF_WriteReg(0, 0xE0, 0x1);
Cnt = 0;
while (1) {
msleep(20);
s4AF_ReadReg(0xE0, &Temp);
Cnt++;
if (Temp == 0 || Cnt > 3)
break;
}
spin_lock(g_pAF_SpinLock);
*g_pAF_Opened = 2;
spin_unlock(g_pAF_SpinLock);
}
LOG_INF("-\n");
return 0;
}
/* moveAF only use to control moving the motor */
static inline int moveAF(unsigned long a_u4Position)
{
int ret = 0;
if (s4AF_WriteReg(1, 0xA0, (unsigned short)AF_convert(
a_u4Position)) == 0) {
g_u4CurrPosition = a_u4Position;
ret = 0;
} else {
LOG_INF("set I2C failed when moving the motor\n");
ret = -1;
}
return ret;
}
static inline int setAFInf(unsigned long a_u4Position)
{
spin_lock(g_pAF_SpinLock);
g_u4AF_INF = a_u4Position;
spin_unlock(g_pAF_SpinLock);
return 0;
}
static inline int setAFMacro(unsigned long a_u4Position)
{
spin_lock(g_pAF_SpinLock);
g_u4AF_MACRO = a_u4Position;
spin_unlock(g_pAF_SpinLock);
return 0;
}
/* ////////////////////////////////////////////////////////////// */
long LC898214AF_Ioctl(struct file *a_pstFile, unsigned int a_u4Command,
unsigned long a_u4Param)
{
long i4RetValue = 0;
switch (a_u4Command) {
case AFIOC_G_MOTORINFO:
i4RetValue =
getAFInfo((__user struct stAF_MotorInfo *)(a_u4Param));
break;
case AFIOC_T_MOVETO:
i4RetValue = moveAF(a_u4Param);
break;
case AFIOC_T_SETINFPOS:
i4RetValue = setAFInf(a_u4Param);
break;
case AFIOC_T_SETMACROPOS:
i4RetValue = setAFMacro(a_u4Param);
break;
default:
LOG_INF("No CMD\n");
i4RetValue = -EPERM;
break;
}
return i4RetValue;
}
/* Main jobs: */
/* 1.Deallocate anything that "open" allocated in private_data. */
/* 2.Shut down the device on last close. */
/* 3.Only called once on last time. */
/* Q1 : Try release multiple times. */
int LC898214AF_Release(struct inode *a_pstInode, struct file *a_pstFile)
{
LOG_INF("Start\n");
if (*g_pAF_Opened == 2) {
LOG_INF("Wait\n");
LOG_INF("Close\n");
}
if (*g_pAF_Opened) {
LOG_INF("Free\n");
spin_lock(g_pAF_SpinLock);
*g_pAF_Opened = 0;
spin_unlock(g_pAF_SpinLock);
}
LOG_INF("End\n");
return 0;
}
int LC898214AF_SetI2Cclient(struct i2c_client *pstAF_I2Cclient,
spinlock_t *pAF_SpinLock, int *pAF_Opened)
{
g_pstAF_I2Cclient = pstAF_I2Cclient;
g_pAF_SpinLock = pAF_SpinLock;
g_pAF_Opened = pAF_Opened;
initAF();
return 1;
}
int LC898214AF_GetFileName(unsigned char *pFileName)
{
#if SUPPORT_GETTING_LENS_FOLDER_NAME
char FilePath[256];
char *FileString;
sprintf(FilePath, "%s", __FILE__);
FileString = strrchr(FilePath, '/');
*FileString = '\0';
FileString = (strrchr(FilePath, '/') + 1);
strncpy(pFileName, FileString, AF_MOTOR_NAME);
LOG_INF("FileName : %s\n", pFileName);
#else
pFileName[0] = '\0';
#endif
return 1;
}
@@ -0,0 +1,7 @@
#
# Makefile for misc devices that really don't fit anywhere else.
#
obj-y += LC898214AF.o
@@ -0,0 +1,406 @@
// SPDX-License-Identifier: GPL-2.0
/*
* Copyright (c) 2019 MediaTek Inc.
*/
/*
* LC898217AF voice coil motor driver
*
*
*/
#include <linux/delay.h>
#include <linux/fs.h>
#include <linux/i2c.h>
#include <linux/time.h>
#include <linux/uaccess.h>
#include "lens_info.h"
#define AF_DRVNAME "LC898217AF_DRV"
#define AF_I2C_SLAVE_ADDR 0xE4
#define AF_DEBUG
#ifdef AF_DEBUG
#define LOG_INF(format, args...) \
pr_info(AF_DRVNAME " [%s] " format, __func__, ##args)
#else
#define LOG_INF(format, args...)
#endif
#define POWER_ALWAYS_ON 0
static struct i2c_client *g_pstAF_I2Cclient;
static int *g_pAF_Opened;
static spinlock_t *g_pAF_SpinLock;
static unsigned long g_u4AF_INF;
static unsigned long g_u4AF_MACRO = 1023;
static unsigned long g_u4CurrPosition;
#define Min_Pos 0
#define Max_Pos 1023
#if POWER_ALWAYS_ON
static int g_TimeOutChk;
static unsigned int g_PreTime;
static struct timespec g_TSAFOpen;
static struct timespec g_TSAFClose;
static unsigned int g_SkipAFUninit;
#endif
static int s4AF_ReadReg(u8 a_uAddr, u8 *a_uData)
{
g_pstAF_I2Cclient->addr = (AF_I2C_SLAVE_ADDR) >> 1;
if (i2c_master_send(g_pstAF_I2Cclient, &a_uAddr, 1) < 0) {
LOG_INF("ReadI2C send failed!!\n");
return -1;
}
if (i2c_master_recv(g_pstAF_I2Cclient, a_uData, 1) < 0) {
LOG_INF("ReadI2C recv failed!!\n");
return -1;
}
/* LOG_INF("RDI2C 0x%x, 0x%x\n", a_uAddr, *a_uData); */
return 0;
}
static int s4AF_WriteReg(u8 a_uLength, u8 a_uAddr, u16 a_u2Data)
{
u8 puSendCmd[2] = {a_uAddr, (u8)(a_u2Data & 0xFF)};
u8 puSendCmd2[3] = {a_uAddr, (u8)((a_u2Data >> 8) & 0xFF),
(u8)(a_u2Data & 0xFF)};
g_pstAF_I2Cclient->addr = (AF_I2C_SLAVE_ADDR) >> 1;
/* LOG_INF("WRI2C 0x%04x, 0x%x\n", a_uAddr, a_u2Data); */
if (a_uLength == 0) {
if (i2c_master_send(g_pstAF_I2Cclient, puSendCmd, 2) < 0) {
LOG_INF("WriteI2C failed!!\n");
return -1;
}
} else if (a_uLength == 1) {
if (i2c_master_send(g_pstAF_I2Cclient, puSendCmd2, 3) < 0) {
LOG_INF("WriteI2C 2 failed!!\n");
return -1;
}
}
return 0;
}
static int setPosition(unsigned short UsPosition)
{
unsigned short TarPos;
unsigned char UcPosH;
unsigned char UcPosL;
unsigned int i4RetValue = 0;
UsPosition = 1023 - UsPosition;
TarPos = UsPosition;
/* LOG_INF("DAC(%04d) -> %03x\n", UsPosition, TarPos); */
UcPosH = (unsigned char)(TarPos >> 8);
UcPosL = (unsigned char)(TarPos & 0x00FF);
i4RetValue = s4AF_WriteReg(0, 0x84, UcPosH);
if (i4RetValue != 0)
return -1;
i4RetValue = s4AF_WriteReg(0, 0x85, UcPosL); /* set target position */
return i4RetValue;
}
static inline int getAFInfo(__user struct stAF_MotorInfo *pstMotorInfo)
{
struct stAF_MotorInfo stMotorInfo;
stMotorInfo.u4MacroPosition = g_u4AF_MACRO;
stMotorInfo.u4InfPosition = g_u4AF_INF;
stMotorInfo.u4CurrentPosition = g_u4CurrPosition;
stMotorInfo.bIsSupportSR = 1;
stMotorInfo.bIsMotorMoving = 1;
if (*g_pAF_Opened >= 1)
stMotorInfo.bIsMotorOpen = 1;
else
stMotorInfo.bIsMotorOpen = 0;
if (copy_to_user(pstMotorInfo, &stMotorInfo,
sizeof(struct stAF_MotorInfo)))
LOG_INF("copy to user failed when getting motor information\n");
return 0;
}
/* initAF include driver initialization and standby mode */
static int initAF(void)
{
LOG_INF("+\n");
if (*g_pAF_Opened == 1) {
int i4RetValue = 0;
int ret = 0;
int cnt = 0;
unsigned char Temp;
#if POWER_ALWAYS_ON
if (g_SkipAFUninit == 1) {
LOG_INF("Skip init driver\n");
g_SkipAFUninit = 0;
return 1;
}
#endif
s4AF_WriteReg(0, 0xF6, 0x00);
s4AF_WriteReg(0, 0x96, 0x20);
s4AF_WriteReg(0, 0x98, 0x00);
s4AF_ReadReg(0xF0, &Temp);
if (Temp == 0x72) {
s4AF_WriteReg(0, 0xE0, 0x01);
while (1) {
mdelay(20);
ret = s4AF_ReadReg(0xB3, &Temp);
if (Temp == 0 && ret == 0) {
i4RetValue = 1;
break;
}
if (cnt >= 20)
break;
cnt++;
}
s4AF_WriteReg(0, 0xA1, 0x02);
mdelay(2);
} else {
LOG_INF("Check HW version: %x\n", Temp);
}
spin_lock(g_pAF_SpinLock);
*g_pAF_Opened = 2;
spin_unlock(g_pAF_SpinLock);
}
LOG_INF("-\n");
return 0;
}
/* moveAF only use to control moving the motor */
static inline int moveAF(unsigned long a_u4Position)
{
int ret = 0;
if (setPosition((unsigned short)a_u4Position) == 0) {
g_u4CurrPosition = a_u4Position;
ret = 0;
} else {
LOG_INF("set I2C failed when moving the motor\n");
ret = -1;
}
return ret;
}
static inline int setAFInf(unsigned long a_u4Position)
{
spin_lock(g_pAF_SpinLock);
g_u4AF_INF = a_u4Position;
spin_unlock(g_pAF_SpinLock);
return 0;
}
static inline int setAFMacro(unsigned long a_u4Position)
{
spin_lock(g_pAF_SpinLock);
g_u4AF_MACRO = a_u4Position;
spin_unlock(g_pAF_SpinLock);
return 0;
}
/* ////////////////////////////////////////////////////////////// */
long LC898217AF_Ioctl(struct file *a_pstFile, unsigned int a_u4Command,
unsigned long a_u4Param)
{
long i4RetValue = 0;
switch (a_u4Command) {
case AFIOC_G_MOTORINFO:
i4RetValue =
getAFInfo((__user struct stAF_MotorInfo *)(a_u4Param));
break;
case AFIOC_T_MOVETO:
i4RetValue = moveAF(a_u4Param);
break;
case AFIOC_T_SETINFPOS:
i4RetValue = setAFInf(a_u4Param);
break;
case AFIOC_T_SETMACROPOS:
i4RetValue = setAFMacro(a_u4Param);
break;
default:
LOG_INF("No CMD\n");
i4RetValue = -EPERM;
break;
}
return i4RetValue;
}
/* Main jobs: */
/* 1.Deallocate anything that "open" allocated in private_data. */
/* 2.Shut down the device on last close. */
/* 3.Only called once on last time. */
/* Q1 : Try release multiple times. */
int LC898217AF_Release(struct inode *a_pstInode, struct file *a_pstFile)
{
int Ret = 0;
LOG_INF("Start\n");
if (*g_pAF_Opened == 2) {
#if POWER_ALWAYS_ON
unsigned long long start_ms, end_ms;
unsigned int diff_ms;
g_TSAFClose = CURRENT_TIME;
start_ms = (g_TSAFOpen.tv_sec * NSEC_PER_SEC +
g_TSAFOpen.tv_nsec) / 1000000;
end_ms = (g_TSAFClose.tv_sec * NSEC_PER_SEC +
g_TSAFClose.tv_nsec) / 1000000;
diff_ms = end_ms - start_ms;
LOG_INF("Wait - Excute Time %d\n", diff_ms);
if (diff_ms < 600) {
g_SkipAFUninit = 1;
LOG_INF("Wait - skip uninit\n");
} else {
Ret = s4AF_WriteReg(0, 0x98, 0xC0);
if (Ret == 0)
Ret = s4AF_WriteReg(0, 0x96, 0x28);
if (Ret == 0)
Ret = s4AF_WriteReg(0, 0xF6, 0x80);
LOG_INF("Wait - power down\n");
}
#else
Ret = s4AF_WriteReg(0, 0x98, 0xC0);
if (Ret == 0)
Ret = s4AF_WriteReg(0, 0x96, 0x28);
if (Ret == 0)
Ret = s4AF_WriteReg(0, 0xF6, 0x80);
LOG_INF("Wait - power down\n");
#endif
LOG_INF("Close\n");
}
if (*g_pAF_Opened) {
LOG_INF("Free\n");
spin_lock(g_pAF_SpinLock);
*g_pAF_Opened = 0;
spin_unlock(g_pAF_SpinLock);
}
LOG_INF("End\n");
return Ret;
}
int LC898217AF_PowerDown(struct i2c_client *pstAF_I2Cclient,
int *pAF_Opened)
{
g_pstAF_I2Cclient = pstAF_I2Cclient;
g_pAF_Opened = pAF_Opened;
LOG_INF("+\n");
if (*g_pAF_Opened == 0) {
int Ret = 0;
#if POWER_ALWAYS_ON
struct timespec mTS;
unsigned int CurTime;
mTS = CURRENT_TIME;
CurTime = (unsigned int)mTS.tv_sec;
if (g_TimeOutChk == 0) {
Ret = s4AF_WriteReg(0, 0x98, 0xC0);
if (Ret == 0)
Ret = s4AF_WriteReg(0, 0x96, 0x28);
if (Ret == 0)
Ret = s4AF_WriteReg(0, 0xF6, 0x80);
if (Ret < 0) {
g_PreTime = CurTime;
g_TimeOutChk = 1;
return -1;
}
LOG_INF("LC898217AF Power Down = %d\n", CurTime);
} else {
if (CurTime - g_PreTime > 60) {
g_PreTime = CurTime;
g_TimeOutChk = 0;
}
}
#else
Ret = s4AF_WriteReg(0, 0x98, 0xC0);
if (Ret == 0)
Ret = s4AF_WriteReg(0, 0x96, 0x28);
if (Ret == 0)
Ret = s4AF_WriteReg(0, 0xF6, 0x80);
#endif
}
LOG_INF("-\n");
return 0;
}
int LC898217AF_SetI2Cclient(struct i2c_client *pstAF_I2Cclient,
spinlock_t *pAF_SpinLock, int *pAF_Opened)
{
#if POWER_ALWAYS_ON
g_TSAFOpen = CURRENT_TIME;
#endif
g_pstAF_I2Cclient = pstAF_I2Cclient;
g_pAF_SpinLock = pAF_SpinLock;
g_pAF_Opened = pAF_Opened;
initAF();
return 1;
}
int LC898217AF_GetFileName(unsigned char *pFileName)
{
#if SUPPORT_GETTING_LENS_FOLDER_NAME
char FilePath[256];
char *FileString;
sprintf(FilePath, "%s", __FILE__);
FileString = strrchr(FilePath, '/');
*FileString = '\0';
FileString = (strrchr(FilePath, '/') + 1);
strncpy(pFileName, FileString, AF_MOTOR_NAME);
LOG_INF("FileName : %s\n", pFileName);
#else
pFileName[0] = '\0';
#endif
return 1;
}
@@ -0,0 +1,19 @@
#
# Copyright (C) 2015 MediaTek Inc.
#
# 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.
#
#
# Makefile for misc devices that really don't fit anywhere else.
#
obj-y += LC898217AF.o
@@ -0,0 +1,406 @@
// SPDX-License-Identifier: GPL-2.0
/*
* Copyright (c) 2019 MediaTek Inc.
*/
/*
* LC898217AF voice coil motor driver
*
*
*/
#include <linux/delay.h>
#include <linux/fs.h>
#include <linux/i2c.h>
#include <linux/time.h>
#include <linux/uaccess.h>
#include "lens_info.h"
#define AF_DRVNAME "LC898217AFA_DRV"
#define AF_I2C_SLAVE_ADDR 0xE4
#define AF_DEBUG
#ifdef AF_DEBUG
#define LOG_INF(format, args...) \
pr_info(AF_DRVNAME " [%s] " format, __func__, ##args)
#else
#define LOG_INF(format, args...)
#endif
#define POWER_ALWAYS_ON 0
static struct i2c_client *g_pstAF_I2Cclient;
static int *g_pAF_Opened;
static spinlock_t *g_pAF_SpinLock;
static unsigned long g_u4AF_INF;
static unsigned long g_u4AF_MACRO = 1023;
static unsigned long g_u4CurrPosition;
#define Min_Pos 0
#define Max_Pos 1023
#if POWER_ALWAYS_ON
static int g_TimeOutChk;
static unsigned int g_PreTime;
static struct timespec g_TSAFOpen;
static struct timespec g_TSAFClose;
static unsigned int g_SkipAFUninit;
#endif
static int s4AF_ReadReg(u8 a_uAddr, u8 *a_uData)
{
g_pstAF_I2Cclient->addr = (AF_I2C_SLAVE_ADDR) >> 1;
if (i2c_master_send(g_pstAF_I2Cclient, &a_uAddr, 1) < 0) {
LOG_INF("ReadI2C send failed!!\n");
return -1;
}
if (i2c_master_recv(g_pstAF_I2Cclient, a_uData, 1) < 0) {
LOG_INF("ReadI2C recv failed!!\n");
return -1;
}
/* LOG_INF("RDI2C 0x%x, 0x%x\n", a_uAddr, *a_uData); */
return 0;
}
static int s4AF_WriteReg(u8 a_uLength, u8 a_uAddr, u16 a_u2Data)
{
u8 puSendCmd[2] = {a_uAddr, (u8)(a_u2Data & 0xFF)};
u8 puSendCmd2[3] = {a_uAddr, (u8)((a_u2Data >> 8) & 0xFF),
(u8)(a_u2Data & 0xFF)};
g_pstAF_I2Cclient->addr = (AF_I2C_SLAVE_ADDR) >> 1;
/* LOG_INF("WRI2C 0x%04x, 0x%x\n", a_uAddr, a_u2Data); */
if (a_uLength == 0) {
if (i2c_master_send(g_pstAF_I2Cclient, puSendCmd, 2) < 0) {
LOG_INF("WriteI2C failed!!\n");
return -1;
}
} else if (a_uLength == 1) {
if (i2c_master_send(g_pstAF_I2Cclient, puSendCmd2, 3) < 0) {
LOG_INF("WriteI2C 2 failed!!\n");
return -1;
}
}
return 0;
}
static int setPosition(unsigned short UsPosition)
{
unsigned short TarPos;
unsigned char UcPosH;
unsigned char UcPosL;
unsigned int i4RetValue = 0;
TarPos = UsPosition;
/* LOG_INF("DAC(%04d) -> %03x\n", UsPosition, TarPos); */
UcPosH = (unsigned char)(TarPos >> 8);
UcPosL = (unsigned char)(TarPos & 0x00FF);
i4RetValue = s4AF_WriteReg(0, 0x84, UcPosH);
if (i4RetValue != 0)
return -1;
i4RetValue = s4AF_WriteReg(0, 0x85, UcPosL); /* set target position */
return i4RetValue;
}
static inline int getAFInfo(__user struct stAF_MotorInfo *pstMotorInfo)
{
struct stAF_MotorInfo stMotorInfo;
stMotorInfo.u4MacroPosition = g_u4AF_MACRO;
stMotorInfo.u4InfPosition = g_u4AF_INF;
stMotorInfo.u4CurrentPosition = g_u4CurrPosition;
stMotorInfo.bIsSupportSR = 1;
stMotorInfo.bIsMotorMoving = 1;
if (*g_pAF_Opened >= 1)
stMotorInfo.bIsMotorOpen = 1;
else
stMotorInfo.bIsMotorOpen = 0;
if (copy_to_user(pstMotorInfo, &stMotorInfo,
sizeof(struct stAF_MotorInfo)))
LOG_INF("copy to user failed when getting motor information\n");
return 0;
}
/* initAF include driver initialization and standby mode */
static int initAF(void)
{
LOG_INF("+\n");
if (*g_pAF_Opened == 1) {
int i4RetValue = 0;
int ret = 0;
int cnt = 0;
unsigned char Temp;
#if POWER_ALWAYS_ON
if (g_SkipAFUninit == 1) {
LOG_INF("Skip init driver\n");
g_SkipAFUninit = 0;
return 1;
}
#endif
s4AF_WriteReg(0, 0xF6, 0x00);
s4AF_WriteReg(0, 0x96, 0x20);
s4AF_WriteReg(0, 0x98, 0x00);
s4AF_ReadReg(0xF0, &Temp);
if (Temp == 0x72) {
s4AF_WriteReg(0, 0xE0, 0x01);
while (1) {
mdelay(20);
ret = s4AF_ReadReg(0xB3, &Temp);
if (Temp == 0 && ret == 0) {
i4RetValue = 1;
break;
}
if (cnt >= 20)
break;
cnt++;
}
s4AF_WriteReg(0, 0xA1, 0x02);
mdelay(2);
} else {
LOG_INF("Check HW version: %x\n", Temp);
}
spin_lock(g_pAF_SpinLock);
*g_pAF_Opened = 2;
spin_unlock(g_pAF_SpinLock);
}
LOG_INF("-\n");
return 0;
}
/* moveAF only use to control moving the motor */
static inline int moveAF(unsigned long a_u4Position)
{
int ret = 0;
if (setPosition((unsigned short)a_u4Position) == 0) {
g_u4CurrPosition = a_u4Position;
ret = 0;
} else {
LOG_INF("set I2C failed when moving the motor\n");
ret = -1;
}
return ret;
}
static inline int setAFInf(unsigned long a_u4Position)
{
spin_lock(g_pAF_SpinLock);
g_u4AF_INF = a_u4Position;
spin_unlock(g_pAF_SpinLock);
return 0;
}
static inline int setAFMacro(unsigned long a_u4Position)
{
spin_lock(g_pAF_SpinLock);
g_u4AF_MACRO = a_u4Position;
spin_unlock(g_pAF_SpinLock);
return 0;
}
/* ////////////////////////////////////////////////////////////// */
long LC898217AFA_Ioctl(struct file *a_pstFile, unsigned int a_u4Command,
unsigned long a_u4Param)
{
long i4RetValue = 0;
switch (a_u4Command) {
case AFIOC_G_MOTORINFO:
i4RetValue =
getAFInfo((__user struct stAF_MotorInfo *)(a_u4Param));
break;
case AFIOC_T_MOVETO:
i4RetValue = moveAF(a_u4Param);
break;
case AFIOC_T_SETINFPOS:
i4RetValue = setAFInf(a_u4Param);
break;
case AFIOC_T_SETMACROPOS:
i4RetValue = setAFMacro(a_u4Param);
break;
default:
LOG_INF("No CMD\n");
i4RetValue = -EPERM;
break;
}
return i4RetValue;
}
/* Main jobs: */
/* 1.Deallocate anything that "open" allocated in private_data. */
/* 2.Shut down the device on last close. */
/* 3.Only called once on last time. */
/* Q1 : Try release multiple times. */
int LC898217AFA_Release(struct inode *a_pstInode, struct file *a_pstFile)
{
int Ret = 0;
LOG_INF("Start\n");
if (*g_pAF_Opened == 2) {
#if POWER_ALWAYS_ON
unsigned long long start_ms, end_ms;
unsigned int diff_ms;
g_TSAFClose = CURRENT_TIME;
start_ms = (g_TSAFOpen.tv_sec * NSEC_PER_SEC +
g_TSAFOpen.tv_nsec) / 1000000;
end_ms = (g_TSAFClose.tv_sec * NSEC_PER_SEC +
g_TSAFClose.tv_nsec) / 1000000;
diff_ms = end_ms - start_ms;
LOG_INF("Wait - Excute Time %d\n", diff_ms);
if (diff_ms < 600) {
g_SkipAFUninit = 1;
LOG_INF("Wait - skip uninit\n");
} else {
Ret = s4AF_WriteReg(0, 0x98, 0xC0);
if (Ret == 0)
Ret = s4AF_WriteReg(0, 0x96, 0x28);
if (Ret == 0)
Ret = s4AF_WriteReg(0, 0xF6, 0x80);
LOG_INF("Wait - power down\n");
}
#else
Ret = s4AF_WriteReg(0, 0x98, 0xC0);
if (Ret == 0)
Ret = s4AF_WriteReg(0, 0x96, 0x28);
if (Ret == 0)
Ret = s4AF_WriteReg(0, 0xF6, 0x80);
LOG_INF("Wait - power down\n");
#endif
LOG_INF("Close\n");
}
if (*g_pAF_Opened) {
LOG_INF("Free\n");
spin_lock(g_pAF_SpinLock);
*g_pAF_Opened = 0;
spin_unlock(g_pAF_SpinLock);
}
LOG_INF("End\n");
return Ret;
}
int LC898217AFA_PowerDown(struct i2c_client *pstAF_I2Cclient,
int *pAF_Opened)
{
g_pstAF_I2Cclient = pstAF_I2Cclient;
g_pAF_Opened = pAF_Opened;
LOG_INF("+\n");
if (*g_pAF_Opened == 0) {
int Ret = 0;
#if POWER_ALWAYS_ON
struct timespec mTS;
unsigned int CurTime;
mTS = CURRENT_TIME;
CurTime = (unsigned int)mTS.tv_sec;
if (g_TimeOutChk == 0) {
Ret = s4AF_WriteReg(0, 0x98, 0xC0);
if (Ret == 0)
Ret = s4AF_WriteReg(0, 0x96, 0x28);
if (Ret == 0)
Ret = s4AF_WriteReg(0, 0xF6, 0x80);
if (Ret < 0) {
g_PreTime = CurTime;
g_TimeOutChk = 1;
return -1;
}
LOG_INF("LC898217AF Power Down = %d\n", CurTime);
} else {
if (CurTime - g_PreTime > 60) {
g_PreTime = CurTime;
g_TimeOutChk = 0;
}
}
#else
Ret = s4AF_WriteReg(0, 0x98, 0xC0);
if (Ret == 0)
Ret = s4AF_WriteReg(0, 0x96, 0x28);
if (Ret == 0)
Ret = s4AF_WriteReg(0, 0xF6, 0x80);
#endif
}
LOG_INF("-\n");
return 0;
}
int LC898217AFA_SetI2Cclient(struct i2c_client *pstAF_I2Cclient,
spinlock_t *pAF_SpinLock, int *pAF_Opened)
{
#if POWER_ALWAYS_ON
g_TSAFOpen = CURRENT_TIME;
#endif
g_pstAF_I2Cclient = pstAF_I2Cclient;
g_pAF_SpinLock = pAF_SpinLock;
g_pAF_Opened = pAF_Opened;
initAF();
return 1;
}
int LC898217AFA_GetFileName(unsigned char *pFileName)
{
#if SUPPORT_GETTING_LENS_FOLDER_NAME
char FilePath[256];
char *FileString;
sprintf(FilePath, "%s", __FILE__);
FileString = strrchr(FilePath, '/');
*FileString = '\0';
FileString = (strrchr(FilePath, '/') + 1);
strncpy(pFileName, FileString, AF_MOTOR_NAME);
LOG_INF("FileName : %s\n", pFileName);
#else
pFileName[0] = '\0';
#endif
return 1;
}
@@ -0,0 +1,19 @@
#
# Copyright (C) 2015 MediaTek Inc.
#
# 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.
#
#
# Makefile for misc devices that really don't fit anywhere else.
#
obj-y += LC898217AFA.o
@@ -0,0 +1,411 @@
// SPDX-License-Identifier: GPL-2.0
/*
* Copyright (c) 2019 MediaTek Inc.
*/
/*
* LC898217AF voice coil motor driver
*
*
*/
#include <linux/delay.h>
#include <linux/fs.h>
#include <linux/i2c.h>
#include <linux/time.h>
#include <linux/uaccess.h>
#include "lens_info.h"
#define AF_DRVNAME "LC898217AFB_DRV"
#define AF_I2C_SLAVE_ADDR 0xE4
#define AF_DEBUG
#ifdef AF_DEBUG
#define LOG_INF(format, args...) \
pr_info(AF_DRVNAME " [%s] " format, __func__, ##args)
#else
#define LOG_INF(format, args...)
#endif
#define POWER_ALWAYS_ON 0
static struct i2c_client *g_pstAF_I2Cclient;
static int *g_pAF_Opened;
static spinlock_t *g_pAF_SpinLock;
static unsigned long g_u4AF_INF;
static unsigned long g_u4AF_MACRO = 1023;
static unsigned long g_u4CurrPosition;
#define Min_Pos 0
#define Max_Pos 1023
#if POWER_ALWAYS_ON
static int g_TimeOutChk;
static unsigned int g_PreTime;
static struct timespec g_TSAFOpen;
static struct timespec g_TSAFClose;
static unsigned int g_SkipAFUninit;
#endif
static int s4AF_ReadReg(u8 a_uAddr, u8 *a_uData)
{
g_pstAF_I2Cclient->addr = (AF_I2C_SLAVE_ADDR) >> 1;
if (i2c_master_send(g_pstAF_I2Cclient, &a_uAddr, 1) < 0) {
LOG_INF("ReadI2C send failed!!\n");
return -1;
}
if (i2c_master_recv(g_pstAF_I2Cclient, a_uData, 1) < 0) {
LOG_INF("ReadI2C recv failed!!\n");
return -1;
}
/* LOG_INF("RDI2C 0x%x, 0x%x\n", a_uAddr, *a_uData); */
return 0;
}
static int s4AF_WriteReg(u8 a_uLength, u8 a_uAddr, u16 a_u2Data)
{
u8 puSendCmd[2] = {a_uAddr, (u8)(a_u2Data & 0xFF)};
u8 puSendCmd2[3] = {a_uAddr, (u8)((a_u2Data >> 8) & 0xFF),
(u8)(a_u2Data & 0xFF)};
g_pstAF_I2Cclient->addr = (AF_I2C_SLAVE_ADDR) >> 1;
/* LOG_INF("WRI2C 0x%04x, 0x%x\n", a_uAddr, a_u2Data); */
if (a_uLength == 0) {
if (i2c_master_send(g_pstAF_I2Cclient, puSendCmd, 2) < 0) {
LOG_INF("WriteI2C failed!!\n");
return -1;
}
} else if (a_uLength == 1) {
if (i2c_master_send(g_pstAF_I2Cclient, puSendCmd2, 3) < 0) {
LOG_INF("WriteI2C 2 failed!!\n");
return -1;
}
}
return 0;
}
static int setPosition(unsigned short UsPosition)
{
unsigned short TarPos;
unsigned char UcPosH;
unsigned char UcPosL;
unsigned int i4RetValue = 0;
UsPosition = 1023 - UsPosition;
if (UsPosition < 512)
TarPos = 0x800 + (UsPosition << 2);
else
TarPos = ((UsPosition - 512) << 2);
/* LOG_INF("DAC(%04d) -> %03x\n", UsPosition, TarPos); */
UcPosH = (unsigned char)(TarPos >> 8);
UcPosL = (unsigned char)(TarPos & 0x00FF);
i4RetValue = s4AF_WriteReg(0, 0x84, UcPosH);
if (i4RetValue != 0)
return -1;
i4RetValue = s4AF_WriteReg(0, 0x85, UcPosL); /* set target position */
return i4RetValue;
}
static inline int getAFInfo(__user struct stAF_MotorInfo *pstMotorInfo)
{
struct stAF_MotorInfo stMotorInfo;
stMotorInfo.u4MacroPosition = g_u4AF_MACRO;
stMotorInfo.u4InfPosition = g_u4AF_INF;
stMotorInfo.u4CurrentPosition = g_u4CurrPosition;
stMotorInfo.bIsSupportSR = 1;
stMotorInfo.bIsMotorMoving = 1;
if (*g_pAF_Opened >= 1)
stMotorInfo.bIsMotorOpen = 1;
else
stMotorInfo.bIsMotorOpen = 0;
if (copy_to_user(pstMotorInfo, &stMotorInfo,
sizeof(struct stAF_MotorInfo)))
LOG_INF("copy to user failed when getting motor information\n");
return 0;
}
/* initAF include driver initialization and standby mode */
static int initAF(void)
{
LOG_INF("+\n");
if (*g_pAF_Opened == 1) {
int i4RetValue = 0;
int ret = 0;
int cnt = 0;
unsigned char Temp;
#if POWER_ALWAYS_ON
if (g_SkipAFUninit == 1) {
LOG_INF("Skip init driver\n");
g_SkipAFUninit = 0;
return 1;
}
#endif
s4AF_WriteReg(0, 0xF6, 0x00);
s4AF_WriteReg(0, 0x96, 0x20);
s4AF_WriteReg(0, 0x98, 0x00);
s4AF_ReadReg(0xF0, &Temp);
if (Temp == 0x72) {
s4AF_WriteReg(0, 0xE0, 0x01);
while (1) {
mdelay(20);
ret = s4AF_ReadReg(0xB3, &Temp);
if (Temp == 0 && ret == 0) {
i4RetValue = 1;
break;
}
if (cnt >= 20)
break;
cnt++;
}
s4AF_WriteReg(0, 0xA1, 0x02);
mdelay(2);
} else {
LOG_INF("Check HW version: %x\n", Temp);
}
spin_lock(g_pAF_SpinLock);
*g_pAF_Opened = 2;
spin_unlock(g_pAF_SpinLock);
}
LOG_INF("-\n");
return 0;
}
/* moveAF only use to control moving the motor */
static inline int moveAF(unsigned long a_u4Position)
{
int ret = 0;
if (setPosition((unsigned short)a_u4Position) == 0) {
g_u4CurrPosition = a_u4Position;
ret = 0;
} else {
LOG_INF("set I2C failed when moving the motor\n");
ret = -1;
}
return ret;
}
static inline int setAFInf(unsigned long a_u4Position)
{
spin_lock(g_pAF_SpinLock);
g_u4AF_INF = a_u4Position;
spin_unlock(g_pAF_SpinLock);
return 0;
}
static inline int setAFMacro(unsigned long a_u4Position)
{
spin_lock(g_pAF_SpinLock);
g_u4AF_MACRO = a_u4Position;
spin_unlock(g_pAF_SpinLock);
return 0;
}
/* ////////////////////////////////////////////////////////////// */
long LC898217AFB_Ioctl(struct file *a_pstFile, unsigned int a_u4Command,
unsigned long a_u4Param)
{
long i4RetValue = 0;
switch (a_u4Command) {
case AFIOC_G_MOTORINFO:
i4RetValue =
getAFInfo((__user struct stAF_MotorInfo *)(a_u4Param));
break;
case AFIOC_T_MOVETO:
i4RetValue = moveAF(a_u4Param);
break;
case AFIOC_T_SETINFPOS:
i4RetValue = setAFInf(a_u4Param);
break;
case AFIOC_T_SETMACROPOS:
i4RetValue = setAFMacro(a_u4Param);
break;
default:
LOG_INF("No CMD\n");
i4RetValue = -EPERM;
break;
}
return i4RetValue;
}
/* Main jobs: */
/* 1.Deallocate anything that "open" allocated in private_data. */
/* 2.Shut down the device on last close. */
/* 3.Only called once on last time. */
/* Q1 : Try release multiple times. */
int LC898217AFB_Release(struct inode *a_pstInode, struct file *a_pstFile)
{
int Ret = 0;
LOG_INF("Start\n");
if (*g_pAF_Opened == 2) {
#if POWER_ALWAYS_ON
unsigned long long start_ms, end_ms;
unsigned int diff_ms;
g_TSAFClose = CURRENT_TIME;
start_ms = (g_TSAFOpen.tv_sec * NSEC_PER_SEC +
g_TSAFOpen.tv_nsec) / 1000000;
end_ms = (g_TSAFClose.tv_sec * NSEC_PER_SEC +
g_TSAFClose.tv_nsec) / 1000000;
diff_ms = end_ms - start_ms;
LOG_INF("Wait - Excute Time %d\n", diff_ms);
if (diff_ms < 600) {
g_SkipAFUninit = 1;
LOG_INF("Wait - skip uninit\n");
} else {
Ret = s4AF_WriteReg(0, 0x98, 0xC0);
if (Ret == 0)
Ret = s4AF_WriteReg(0, 0x96, 0x28);
if (Ret == 0)
Ret = s4AF_WriteReg(0, 0xF6, 0x80);
LOG_INF("Wait - power down\n");
}
#else
Ret = s4AF_WriteReg(0, 0x98, 0xC0);
if (Ret == 0)
Ret = s4AF_WriteReg(0, 0x96, 0x28);
if (Ret == 0)
Ret = s4AF_WriteReg(0, 0xF6, 0x80);
LOG_INF("Wait - power down\n");
#endif
LOG_INF("Close\n");
}
if (*g_pAF_Opened) {
LOG_INF("Free\n");
spin_lock(g_pAF_SpinLock);
*g_pAF_Opened = 0;
spin_unlock(g_pAF_SpinLock);
}
LOG_INF("End\n");
return Ret;
}
int LC898217AFB_PowerDown(struct i2c_client *pstAF_I2Cclient,
int *pAF_Opened)
{
g_pstAF_I2Cclient = pstAF_I2Cclient;
g_pAF_Opened = pAF_Opened;
LOG_INF("+\n");
if (*g_pAF_Opened == 0) {
int Ret = 0;
#if POWER_ALWAYS_ON
struct timespec mTS;
unsigned int CurTime;
mTS = CURRENT_TIME;
CurTime = (unsigned int)mTS.tv_sec;
if (g_TimeOutChk == 0) {
Ret = s4AF_WriteReg(0, 0x98, 0xC0);
if (Ret == 0)
Ret = s4AF_WriteReg(0, 0x96, 0x28);
if (Ret == 0)
Ret = s4AF_WriteReg(0, 0xF6, 0x80);
if (Ret < 0) {
g_PreTime = CurTime;
g_TimeOutChk = 1;
return -1;
}
LOG_INF("LC898217AF Power Down = %d\n", CurTime);
} else {
if (CurTime - g_PreTime > 60) {
g_PreTime = CurTime;
g_TimeOutChk = 0;
}
}
#else
Ret = s4AF_WriteReg(0, 0x98, 0xC0);
if (Ret == 0)
Ret = s4AF_WriteReg(0, 0x96, 0x28);
if (Ret == 0)
Ret = s4AF_WriteReg(0, 0xF6, 0x80);
#endif
}
LOG_INF("-\n");
return 0;
}
int LC898217AFB_SetI2Cclient(struct i2c_client *pstAF_I2Cclient,
spinlock_t *pAF_SpinLock, int *pAF_Opened)
{
#if POWER_ALWAYS_ON
g_TSAFOpen = CURRENT_TIME;
#endif
g_pstAF_I2Cclient = pstAF_I2Cclient;
g_pAF_SpinLock = pAF_SpinLock;
g_pAF_Opened = pAF_Opened;
initAF();
return 1;
}
int LC898217AFB_GetFileName(unsigned char *pFileName)
{
#if SUPPORT_GETTING_LENS_FOLDER_NAME
char FilePath[256];
char *FileString;
sprintf(FilePath, "%s", __FILE__);
FileString = strrchr(FilePath, '/');
*FileString = '\0';
FileString = (strrchr(FilePath, '/') + 1);
strncpy(pFileName, FileString, AF_MOTOR_NAME);
LOG_INF("FileName : %s\n", pFileName);
#else
pFileName[0] = '\0';
#endif
return 1;
}
Loaded 100 of 80519 files, more files were not shown because too many files have changed in this diff. Show more