Ejemplo n.º 1
0
/* Q1 : Try release multiple times. */
static int DW9718AF_Release(struct inode *a_pstInode, struct file *a_pstFile)
{
//                                                                              
#if defined(TARGET_MT6732_C90)
	if (af_current_on == 0)
		return 0;
#endif
//                                                                              

	DW9718AFDB("[DW9718AF] DW9718AF_Release - Start\n");

	if (g_s4DW9718AF_Opened) {
		DW9718AFDB("[DW9718AF] feee\n");
		g_sr = 5;
//                                                                  
		s4DW9718AF_WriteReg(200);
		msleep(10);
		s4DW9718AF_WriteReg(100);
		msleep(10);
//                                                                  
		spin_lock(&g_DW9718AF_SpinLock);
		g_s4DW9718AF_Opened = 0;
		spin_unlock(&g_DW9718AF_SpinLock);

	}
	DW9718AFDB("[DW9718AF] DW9718AF_Release - End\n");

	return 0;
}
Ejemplo n.º 2
0
static int breakDownSteps(int max_step, int interval, int CurrentPos, int TargetPos)
{
    unsigned short tmpTargetPos;

    DW9718AFDB("[DW9718AF] break down steps from=%d, to=%d \n", CurrentPos, TargetPos);
    if(TargetPos >= CurrentPos){
        return 0;
    }
    while( max_step >= THRESHOLD )
    {
        while( abs(CurrentPos - TargetPos) > max_step ){
            if(TargetPos >= CurrentPos){
                DW9718AFDB("Inverse!!\n");
                return 0;
            }
            tmpTargetPos = CurrentPos - max_step;
            DW9718AFDB("tmpTargetPos=%d\n", tmpTargetPos);
            if(s4DW9718AF_WriteReg(tmpTargetPos) == 0)
            {
                CurrentPos = tmpTargetPos;
                DW9718AFDB("CurrentPos=%d\n", CurrentPos);
            }
            else
            {
                DW9718AFDB("[DW9718AF] set I2C failed when moving the motor \n");
                g_i4MotorStatus = -1;
            }
            //Delay for few milli-second
            //DW9718AFDB("start delay \n");
            //msleep(interval);
            udelay(800);
            //DW9718AFDB("after delay \n");
        }
        max_step = (THRESHOLD < max_step)? THRESHOLD : 0;
    }

    //DW9718AFDB("Last step from=%d, to=%d \n", CurrentPos, TargetPos);

    if(s4DW9718AF_WriteReg(TargetPos) == 0)
    {
        CurrentPos = TargetPos;
    }
    else
    {
        DW9718AFDB("[DW9718AF] set I2C failed when moving the motor \n");
        g_i4MotorStatus = -1;
    }

    g_u4CurrPosition = CurrentPos;
    DW9718AFDB("Leave breakdown\n");
    return 0;
}
Ejemplo n.º 3
0
/* Q1 : Try release multiple times. */
static int DW9718AF_Release(struct inode *a_pstInode, struct file *a_pstFile)
{
//LGE_UPDATE_S [[email protected]] 2015/1/12, remove af i2c error during booting
#if defined(TARGET_MT6732_C90)
	if (af_current_on == 0)
		return 0;
#endif
//LGE_UPDATE_E [[email protected]] 2015/1/12, remove af i2c error during booting

	DW9718AFDB("[DW9718AF] DW9718AF_Release - Start\n");

    if (g_s4DW9718AF_Opened == 2) 
    {
		g_sr = 5;
	}

	if (g_s4DW9718AF_Opened) {
		DW9718AFDB("[DW9718AF] feee\n");
		g_sr = 5;
//LGE_UPDATE_S [[email protected]] 2015/1/27, add steps to reduce tick noise
		s4DW9718AF_WriteReg(200);
		msleep(10);
		s4DW9718AF_WriteReg(100);
		msleep(10);
		s4DW9718AF_WriteReg(50);
		msleep(5);
		s4DW9718AF_WriteReg(25);
		msleep(5);
		s4DW9718AF_WriteReg(10);
		msleep(5);
//LGE_UPDATE_E [[email protected]] 2015/1/27, add steps to reduce tick noise
		spin_lock(&g_DW9718AF_SpinLock);
		g_s4DW9718AF_Opened = 0;
		spin_unlock(&g_DW9718AF_SpinLock);

	}
    
	DW9718AFDB("[DW9718AF] DW9718AF_Release - End\n");

	return 0;
}
Ejemplo n.º 4
0
//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.
static int DW9718AF_Release(struct inode * a_pstInode, struct file * a_pstFile)
{
    DW9718AFDB("[DW9718AF] DW9718AF_Release - Start\n");
//[LGE_UPDATE_S] [[email protected]] [2014-12-13] Y50 Y70 Booting I2C Error Delete
#if defined (TARGET_MT6582_Y50)|| defined (TARGET_MT6582_Y70) || defined (TARGET_MT6582_L80)
	if(dw9718_af_current_on==0)
	{
	DW9718AFDB("[DW9718AF] POPO af_current_on DW9718AF_Release \n");
	return 0;
	}
 #endif  
//[LGE_UPDATE_ES] [[email protected]] [2014-12-13] Y50 Y70 Booting I2C Error Delete 
    if (g_s4DW9718AF_Opened)
    {
        DW9718AFDB("[DW9718AF] feee \n");
        g_sr = 5;
	    s4DW9718AF_WriteReg(200);
        msleep(10);
	    s4DW9718AF_WriteReg(100);
        msleep(10);
//[LGE_UPDATE_S] [[email protected]] [2015-01-22] Decrease_Af_Tic_Noise	
		s4DW9718AF_WriteReg(50);
        msleep(5);
	    s4DW9718AF_WriteReg(25);
        msleep(5);
		s4DW9718AF_WriteReg(10);
        msleep(5);
//[LGE_UPDATE_E] [[email protected]] [2015-01-22] Decrease_Af_Tic_Noise
            	            	    	    
        spin_lock(&g_DW9718AF_SpinLock);
        g_s4DW9718AF_Opened = 0;
        spin_unlock(&g_DW9718AF_SpinLock);

    }

    DW9718AFDB("[DW9718AF] DW9718AF_Release - End\n");

    return 0;
}
//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.
static int DW9718AF_Release(struct inode * a_pstInode, struct file * a_pstFile)
{
    DW9718AFDB("[DW9718AF] DW9718AF_Release - Start\n");

    if (g_s4DW9718AF_Opened)
    {
        DW9718AFDB("[DW9718AF] feee \n");
        g_sr = 5;
	    s4DW9718AF_WriteReg(200);
        msleep(10);
	    s4DW9718AF_WriteReg(100);
        msleep(10);
            	            	    	    
        spin_lock(&g_DW9718AF_SpinLock);
        g_s4DW9718AF_Opened = 0;
        spin_unlock(&g_DW9718AF_SpinLock);

    }

    DW9718AFDB("[DW9718AF] DW9718AF_Release - End\n");

    return 0;
}
inline static int moveDW9718AF(unsigned long a_u4Position)
{
    int ret = 0;
    
    if((a_u4Position > g_u4DW9718AF_MACRO) || (a_u4Position < g_u4DW9718AF_INF))
    {
        DW9718AFDB("[DW9718AF] out of range \n");
        return -EINVAL;
    }

    if (g_s4DW9718AF_Opened == 1)
    {
        unsigned short InitPos;
        ret = s4DW9718AF_ReadReg(&InitPos);
	    
        spin_lock(&g_DW9718AF_SpinLock);
        if(ret == 0)
        {
            DW9718AFDB("[DW9718AF] Init Pos %6d \n", InitPos);
			
            g_u4CurrPosition = (unsigned long)InitPos;
        }
        else
        {		
            g_u4CurrPosition = 0;
        }
		
        g_s4DW9718AF_Opened = 2;
        spin_unlock(&g_DW9718AF_SpinLock);
		
    }

    if (g_u4CurrPosition < a_u4Position)
    {
        spin_lock(&g_DW9718AF_SpinLock);	
        g_i4Dir = 1;
        spin_unlock(&g_DW9718AF_SpinLock);	
    }
    else if (g_u4CurrPosition > a_u4Position)
    {
        spin_lock(&g_DW9718AF_SpinLock);	
        g_i4Dir = -1;
        spin_unlock(&g_DW9718AF_SpinLock);			
    }
    else	
	{return 0;}

    spin_lock(&g_DW9718AF_SpinLock);    
    g_u4TargetPosition = a_u4Position;
    spin_unlock(&g_DW9718AF_SpinLock);	

    //DW9718AFDB("[DW9718AF] move [curr] %d [target] %d\n", g_u4CurrPosition, g_u4TargetPosition);

            spin_lock(&g_DW9718AF_SpinLock);
            g_sr = 3;
            g_i4MotorStatus = 0;
            spin_unlock(&g_DW9718AF_SpinLock);	
		
            if(s4DW9718AF_WriteReg((unsigned short)g_u4TargetPosition) == 0)
            {
                spin_lock(&g_DW9718AF_SpinLock);		
                g_u4CurrPosition = (unsigned long)g_u4TargetPosition;
                spin_unlock(&g_DW9718AF_SpinLock);				
            }
            else
            {
                DW9718AFDB("[DW9718AF] set I2C failed when moving the motor \n");			
                spin_lock(&g_DW9718AF_SpinLock);
                g_i4MotorStatus = -1;
                spin_unlock(&g_DW9718AF_SpinLock);				
            }

    return 0;
}