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

@@ -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,290 @@
// 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,256 @@
// 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,241 @@
// 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_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_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,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,246 @@
// 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,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,248 @@
// 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)
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 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,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,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,399 @@
// 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,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,7 @@
#
# Makefile for misc devices that really don't fit anywhere else.
#
obj-y += WV511AAF.o
@@ -0,0 +1,272 @@
// SPDX-License-Identifier: GPL-2.0
/*
* Copyright (c) 2019 MediaTek Inc.
*/
/*
* MD218A voice coil motor driver
*
*
*/
#include <linux/atomic.h>
#include <linux/cdev.h>
#include <linux/delay.h>
#include <linux/fs.h>
#include <linux/i2c.h>
#include <linux/platform_device.h>
#include <linux/uaccess.h>
#ifdef CONFIG_COMPAT
#include <linux/compat.h>
#endif
#include "lens_info.h"
#define AF_DRVNAME "WV511AAF"
#define I2C_SLAVE_ADDRESS 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 spinlock_t *g_AF_SpinLock;
static struct i2c_client *g_pstAF_I2Cclient;
static int *g_s4AF_Opened;
static int g_sr;
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)};
/* LOG_INF("g_sr %d, write %d\n", g_sr, a_u2Data); */
/* g_pstAF_I2Cclient->ext_flag |= I2C_A_FILTER_MSG; */
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_s4AF_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 stWV511AAF_MotorMETAInfo *pstMotorMETAInfo)
{
stWV511AAF_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(stWV511AAF_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_s4AF_Opened == 1) {
spin_lock(g_AF_SpinLock);
g_sr = 3;
*g_s4AF_Opened = 2;
spin_unlock(g_AF_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_AF_SpinLock);
g_u4AF_INF = a_u4Position;
spin_unlock(g_AF_SpinLock);
return 0;
}
static inline int setAFMacro(unsigned long a_u4Position)
{
spin_lock(g_AF_SpinLock);
g_u4AF_MACRO = a_u4Position;
spin_unlock(g_AF_SpinLock);
return 0;
}
/* ////////////////////////////////////////////////////////////// */
long WV511AAF_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;
#ifdef LensdrvCM3
case WV511AAFIOC_G_MOTORMETAINFO:
i4RetValue =
getAFMETA((__user struct stAF_MotorInfo *)(a_u4Param));
break;
#endif
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 WV511AAF_Release(struct inode *a_pstInode, struct file *a_pstFile)
{
LOG_INF("Start\n");
if (*g_s4AF_Opened == 2) {
spin_lock(g_AF_SpinLock);
g_sr = 5;
spin_unlock(g_AF_SpinLock);
s4AF_WriteReg(200);
msleep(20);
s4AF_WriteReg(100);
msleep(20);
}
if (*g_s4AF_Opened) {
LOG_INF("Free\n");
spin_lock(g_AF_SpinLock);
*g_s4AF_Opened = 0;
spin_unlock(g_AF_SpinLock);
}
LOG_INF("End\n");
return 0;
}
int WV511AAF_SetI2Cclient(struct i2c_client *pstAF_I2Cclient,
spinlock_t *pAF_SpinLock, int *pAF_Opened)
{
g_pstAF_I2Cclient = pstAF_I2Cclient;
g_AF_SpinLock = pAF_SpinLock;
g_s4AF_Opened = pAF_Opened;
initAF();
return 1;
}
int WV511AAF_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;
}