static int lightsensor_enable(struct ltr558_info *lpi)
{
    int ret = 0;
    
    if(!lpi)
        return -1;
    mutex_lock(&als_enable_mutex);
	  D("[ltr558] %s by pid[%d] thread [%s]\n", __func__,current->pid,current->comm);

    if (lpi->gainrange == 1)
         ret = ltr558_i2c_write_reg(LTR558_ALS_CONTR, MODE_ALS_ON_Range1);
    else if (lpi->gainrange == 2)
        ret = ltr558_i2c_write_reg(LTR558_ALS_CONTR, MODE_ALS_ON_Range2);
    else
		    ret = -1;
    msleep(10);
		/* report an invalid value first to ensure we
		* trigger an event when adc_level is zero.
		*/
    lpi->als_enable = 1;

    input_report_abs(lpi->ls_input_dev, ABS_MISC, -1);
    input_sync(lpi->ls_input_dev);
    report_lsensor_input_event(lpi);/*resume, IOCTL and DEVICE_ATTR*/
    mutex_unlock(&als_enable_mutex);

#ifdef POLLING_PROXIMITY
    //if(!lpi->ps_enable)
    queue_delayed_work(lpi->lp_wq, &polling_work,
		msecs_to_jiffies(POLLING_DELAY));
	/* settng command code(0x01) = 0x03*/
#endif

    return ret;
}
Beispiel #2
0
/*******************************************
function:choose the range for L-sensor to detect interrupt
parameter: 
	@l_range:the range we want to set.
		L_RANGE_1: detect ch0 range 0~3000
		L_RANGE_NULL: do not detect
return:
	-1:wrong parameter
********************************************/
static int ltr558_set_l_range(int l_range){
	int result =0;

	switch(l_range){
		case L_RANGE_1:
			result = ltr558_i2c_write_reg(LTR558_ALS_THRES_UP_0, 0xB8);		
			result = ltr558_i2c_write_reg(LTR558_ALS_THRES_UP_1, 0x0B);
			LTRDBG("0x97 = [%x], 0x98 = [%x]\n", 
				ltr558_i2c_read_reg(LTR558_ALS_THRES_UP_0), 
				ltr558_i2c_read_reg(LTR558_ALS_THRES_UP_1));
			result = ltr558_i2c_write_reg(LTR558_ALS_THRES_LOW_0, 0xff);
			result = ltr558_i2c_write_reg(LTR558_ALS_THRES_LOW_1, 0xff);
			LTRDBG("0x99 = [%x], 0x9a = [%x]\n", 
				ltr558_i2c_read_reg(LTR558_ALS_THRES_LOW_0), 
				ltr558_i2c_read_reg(LTR558_ALS_THRES_LOW_1));
			break;
		case L_RANGE_NULL:
			result = ltr558_i2c_write_reg(LTR558_ALS_THRES_UP_0, 0xff);		
			result = ltr558_i2c_write_reg(LTR558_ALS_THRES_UP_1, 0xff);
			LTRDBG("0x97 = [%x], 0x98 = [%x]\n", 
				ltr558_i2c_read_reg(LTR558_ALS_THRES_UP_0), 
				ltr558_i2c_read_reg(LTR558_ALS_THRES_UP_1));

			result = ltr558_i2c_write_reg(LTR558_ALS_THRES_LOW_0, 0x00);
			result = ltr558_i2c_write_reg(LTR558_ALS_THRES_LOW_1, 0x00);
			LTRDBG("0x99 = [%x], 0x9a = [%x]\n", 
				ltr558_i2c_read_reg(LTR558_ALS_THRES_LOW_0), 
				ltr558_i2c_read_reg(LTR558_ALS_THRES_LOW_1));
			break;
		default:
			return -1;
	}
	return result;
}
Beispiel #3
0
static int ltr558_als_enable(struct i2c_client *client, int gainrange)
{
	int error = -1;

	if (gainrange == ALS_RANGE1_320)
		error = ltr558_i2c_write_reg(client, LTR558_ALS_CONTR,
				MODE_ALS_ON_Range1);
	else if (gainrange == ALS_RANGE2_64K)
		error = ltr558_i2c_write_reg(client, LTR558_ALS_CONTR,
				MODE_ALS_ON_Range2);

	msleep(WAKEUP_DELAY);
	return error;
}
Beispiel #4
0
/*******************************************
function:enable L-sensor
parameter: 
	@gainrange: select the gain range
return:
	This executes the SMBus "write byte" protocol, returning
	negative errno else zero on success.
inportant:
	Other settings like timing and threshold to be set BEFORE here, 
	if required. Not set and kept as device default for now.
********************************************/
static int ltr558_als_enable(int gainrange){
	int error;

	if (gainrange == ALS_RANGE1_320)
		error = ltr558_i2c_write_reg(LTR558_ALS_CONTR, MODE_ALS_ON_Range1);
	else if (gainrange == ALS_RANGE2_64K)
		error = ltr558_i2c_write_reg(LTR558_ALS_CONTR, MODE_ALS_ON_Range2);
	else
		error = -1;

	ltr558_i2c_read_reg(0x80);
	LTRDBG("0x80 = [%x]\n", ltr558_i2c_read_reg(0x80));
	mdelay(WAKEUP_DELAY);

	return error;
}
Beispiel #5
0
/*******************************************
function:enable P-sensor
parameter: 
	@gainrange: select the gain range
return:
	This executes the SMBus "write byte" protocol, returning
	negative errno else zero on success.
inportant:
	Other settings like timing and threshold to be set BEFORE here, 
	if required. Not set and kept as device default for now.
********************************************/
static int ltr558_ps_enable(int gainrange){
	int error;
	int setgain;

	switch (gainrange) {
		case PS_RANGE1:
			setgain = MODE_PS_ON_Gain1;
			break;

		case PS_RANGE4:
			setgain = MODE_PS_ON_Gain4;
			break;

		case PS_RANGE8:
			setgain = MODE_PS_ON_Gain8;
			break;

		case PS_RANGE16:
			setgain = MODE_PS_ON_Gain16;
			break;

		default:
			setgain = MODE_PS_ON_Gain1;
			break;
	}

	error = ltr558_i2c_write_reg(LTR558_PS_CONTR, setgain); 
	ltr558_i2c_read_reg(0x81);
	LTRDBG("0x81 = [%x]\n", ltr558_i2c_read_reg(0x81));
	mdelay(WAKEUP_DELAY);
	
	return error;
}
Beispiel #6
0
/*******************************************
function:Put L-sensor into Standby mode
parameter: 
	none
return:
	This executes the SMBus "write byte" protocol, returning
	negative errno else zero on success.
********************************************/
static int ltr558_als_disable(void){
	int error;
	
	error = ltr558_i2c_write_reg(LTR558_ALS_CONTR, MODE_ALS_StdBy); 
	LTRDBG("0x80 = [%x]\n", ltr558_i2c_read_reg(0x80));
	
	return error;
}
Beispiel #7
0
static int ltr558_ps_enable(struct i2c_client *client, int gainrange)
{
	int error;
	int setgain;

	switch (gainrange) {
		case PS_RANGE4:
			setgain = MODE_PS_ON_Gain4;
			break;

		case PS_RANGE8:
			setgain = MODE_PS_ON_Gain8;
			break;

		case PS_RANGE16:
			setgain = MODE_PS_ON_Gain16;
			break;

		case PS_RANGE1:
		default:
			setgain = MODE_PS_ON_Gain1;
			break;
	}

	/*
	 * Per HW Suggestion, LED Current: 100mA, Duty Cycle: 100%, PMF: 30KHz
	 * LED Pulse Count: 5, Measurement Repeat Rate: 200ms
	 */
	error = ltr558_i2c_write_reg(client, LTR558_PS_LED,
			PS_LED_PMF_30KHZ | PS_LED_CUR_DUTY_100 |
			PS_LED_CUR_LEVEL_100);
	if (!error)
		error = ltr558_i2c_write_reg(client, LTR558_PS_N_PULSES,
				PS_N_PULSES_5);
	if (!error)
		error = ltr558_i2c_write_reg(client, LTR558_PS_MEAS_RATE,
				PS_MEAS_RATE_200MS);
	if (!error) {
		error = ltr558_i2c_write_reg(client,
					     LTR558_PS_CONTR, BIT(5) | setgain);
		mdelay(WAKEUP_DELAY);
	}
	return error;
}
Beispiel #8
0
static bool ltr558_set_als_low_threshold(struct i2c_client *client, u32 thresh)
{
	bool st;
	st = ltr558_i2c_write_reg(client, LTR558_ALS_THRES_LOW_0,
			thresh & 0xFF);
	if (!st)
		st = ltr558_i2c_write_reg(client, LTR558_ALS_THRES_LOW_1,
				((thresh >> 8) & 0xFF));
	return st;
}
Beispiel #9
0
static bool ltr558_set_proxim_high_threshold(struct i2c_client *client,
		u32 thresh)
{
	bool st;
	st = ltr558_i2c_write_reg(client, LTR558_PS_THRES_UP_0,
			thresh & 0xFF);
	if (!st)
		st = ltr558_i2c_write_reg(client, LTR558_PS_THRES_UP_1,
				(thresh >> 8) & 0x07);
	return st;
}
static int ltr558_als_enable(int gainrange)
{
        int error;

        if (gainrange == 1)
                error = ltr558_i2c_write_reg(LTR558_ALS_CONTR, MODE_ALS_ON_Range1);
        else if (gainrange == 2)
                error = ltr558_i2c_write_reg(LTR558_ALS_CONTR, MODE_ALS_ON_Range2);
        else
                error = -1;

        mdelay(WAKEUP_DELAY);

        /* =============== 
         * ** IMPORTANT **
         * ===============
         * Other settings like timing and threshold to be set here, if required.
         * Not set and kept as device default for now.
         */

        return error;
}
static int psensor_disable(struct ltr558_info *lpi)
{
    int ret = -EIO;

    D("[LTR558] %s by pid[%d] thread [%s]\n", __func__,current->pid,current->comm); 
    ret = ltr558_i2c_write_reg(LTR558_PS_CONTR, MODE_PS_StdBy); 
    lpi->ps_enable = 0;

#ifdef POLLING_PROXIMITY
    if(!lpi->als_enable)
	      cancel_delayed_work(&polling_work);
#endif
	  return ret;
}
static int psensor_enable(struct ltr558_info *lpi)
{
    int ret = 0;
    int error;
	  int setgain;

	  D("[LTR558] %s by pid[%d] thread [%s]\n", __func__,current->pid,current->comm);
	  /* dummy report */
	  input_report_abs(lpi->ps_input_dev, ABS_DISTANCE, -1);
	  input_sync(lpi->ps_input_dev);

    switch (lpi->gainrange) {
		    case PS_RANGE1:
			      setgain = MODE_PS_ON_Gain1;
			      break;

		    case PS_RANGE2:
			      setgain = MODE_PS_ON_Gain2;
			      break;

		    case PS_RANGE4:
			      setgain = MODE_PS_ON_Gain4;
			      break;

		    case PS_RANGE8:
			      setgain = MODE_PS_ON_Gain8;
			      break;

		    default:
			      setgain = MODE_PS_ON_Gain1;
			      break;
    }

	  error = ltr558_i2c_write_reg(LTR558_PS_CONTR, setgain);

  
	  msleep(15);
	  report_psensor_input_event(lpi);
    lpi->ps_enable = 1;

  //if(!lpi->als_enable)
	 // queue_delayed_work(lpi->lp_wq, &polling_work,msecs_to_jiffies(POLLING_DELAY));

	  return ret;
}
static int lightsensor_disable(struct ltr558_info *lpi)
{
    int ret = 0;

    if(!lpi)
            return -1;

	  mutex_lock(&als_disable_mutex);
    ltr558_i2c_write_reg(LTR558_ALS_CONTR, MODE_ALS_StdBy);
	  D("[ltr558] %s by pid[%d] thread [%s]\n", __func__,current->pid,current->comm);
	  lpi->als_enable = 0;
	  mutex_unlock(&als_disable_mutex);

#ifdef POLLING_PROXIMITY
    if(!lpi->ps_enable)
	      cancel_delayed_work(&polling_work);
#endif
	  return ret;
}
static int ltr558_ps_enable(int gainrange)
{
        int error;
        int setgain;

        switch (gainrange) {
                case PS_RANGE1:
                        setgain = MODE_PS_ON_Gain1;
                        break;

                case PS_RANGE2:
                        setgain = MODE_PS_ON_Gain2;
                        break;

                case PS_RANGE4:
                        setgain = MODE_PS_ON_Gain4;
                        break;

                case PS_RANGE8:
                        setgain = MODE_PS_ON_Gain8;
                        break;

                default:
                        setgain = MODE_PS_ON_Gain1;
                        break;
        }

        error = ltr558_i2c_write_reg(LTR558_PS_CONTR, setgain);
        mdelay(WAKEUP_DELAY);

        /* =============== 
         * ** IMPORTANT **
         * ===============
         * Other settings like timing and threshold to be set here, if required.
         * Not set and kept as device default for now.
         */

        return error;
}
Beispiel #15
0
static int ltr558_config(void){
	int error = 0;
	
	error = ltr558_i2c_write_reg(LTR558_PS_LED, PS_LED_SETTING);				//0x7B
	if (error){
		LTRERR("write LTR558_PS_LED fail\n");
		return error;
	}
	
	error = ltr558_i2c_write_reg(LTR558_PS_N_PULSES, PS_N_PULSE_SETTING);		//0x0F
	if (error){
		LTRERR("write LTR558_PS_N_PULSES fail\n");
		return error;
	}
	
	error = ltr558_i2c_write_reg(LTR558_PS_MEAS_RATE, PS_MEAS_RATE_SETING);		//0x00
	if (error){
		LTRERR("write LTR558_PS_MEAS_RATE fail\n");
		return error;
	}
	
	error = ltr558_i2c_write_reg(LTR558_ALS_MEAS_RATE, ALS_MEAS_RATE_SETTING);	//0x03
	if (error){
		LTRERR("write LTR558_ALS_MEAS_RATE fail\n");
		return error;
	}
	
	error = ltr558_i2c_write_reg(LTR558_INTERRUPT, INTERRUPT_SETTING);			//0x03
	if (error){
		LTRERR("write LTR558_INTERRUPT fail\n");
		return error;
	}
	
	error = ltr558_i2c_write_reg(LTR558_INTERRUPT_PERSIST, INTE_PERSIST_SETTING);	//0x00
	if (error){
		LTRERR("write LTR558_INTERRUPT_PERSIST fail\n");
		return error;
	}

	return 0;
}
Beispiel #16
0
/*******************************************
function:choose the range for P-sensor to detect interrupt
parameter: 
	@p_range:the range we want to set.
		P_RANGE_1: detect range 200~max
		P_RANGE_2: detect range 0~128
		P_RANGE_NULL: do not detect
return:
	-1:wrong parameter
********************************************/
static int ltr558_set_p_range(int p_range){
	int result = 0;
	
	switch(p_range){
		case P_RANGE_1:
			result = ltr558_i2c_write_reg(LTR558_PS_THRES_UP_0, 0x14); ///d4		//0x2C		
			result = ltr558_i2c_write_reg(LTR558_PS_THRES_UP_1, 0x02);		//0x01
			LTRDBG("0x90 = [%x], 0x91 = [%x]\n", 
			ltr558_i2c_read_reg(LTR558_PS_THRES_UP_0), 
				ltr558_i2c_read_reg(LTR558_PS_THRES_UP_1));

			result = ltr558_i2c_write_reg(LTR558_PS_THRES_LOW_0, 0x00);
			result = ltr558_i2c_write_reg(LTR558_PS_THRES_LOW_1, 0x00);
			LTRDBG("0x92 = [%x], 0x93 = [%x]\n", 
				ltr558_i2c_read_reg(LTR558_PS_THRES_LOW_0),
				ltr558_i2c_read_reg(LTR558_PS_THRES_LOW_1));
			break;
		case P_RANGE_2:
			result = ltr558_i2c_write_reg(LTR558_PS_THRES_UP_0, 0xff);
			result = ltr558_i2c_write_reg(LTR558_PS_THRES_UP_1, 0x07);
			LTRDBG("0x90 = [%x], 0x91 = [%x]\n", 
				ltr558_i2c_read_reg(LTR558_PS_THRES_UP_0), 
				ltr558_i2c_read_reg(LTR558_PS_THRES_UP_1));

			result = ltr558_i2c_write_reg(LTR558_PS_THRES_LOW_0, 0x14);
			result = ltr558_i2c_write_reg(LTR558_PS_THRES_LOW_1, 0x02);
			LTRDBG("0x92 = [%x], 0x93 = [%x]\n", 
				ltr558_i2c_read_reg(LTR558_PS_THRES_LOW_0), 
				ltr558_i2c_read_reg(LTR558_PS_THRES_LOW_1));
			break;
		case P_RANGE_NULL:
			result = ltr558_i2c_write_reg(LTR558_PS_THRES_UP_0, 0xff);		
			result = ltr558_i2c_write_reg(LTR558_PS_THRES_UP_1, 0x07);
			LTRDBG("0x90 = [%x], 0x91 = [%x]\n", 
				ltr558_i2c_read_reg(LTR558_PS_THRES_UP_0), 
				ltr558_i2c_read_reg(LTR558_PS_THRES_UP_1));

			result = ltr558_i2c_write_reg(LTR558_PS_THRES_LOW_0, 0x00);
			result = ltr558_i2c_write_reg(LTR558_PS_THRES_LOW_1, 0x00);
			LTRDBG("0x92 = [%x], 0x93 = [%x]\n", 
				ltr558_i2c_read_reg(LTR558_PS_THRES_LOW_0), 
				ltr558_i2c_read_reg(LTR558_PS_THRES_LOW_1));
			break;
		default:
			return -1;
	}
	return result;
}
// Put ALS into Standby mode
static int ltr558_als_disable(void)
{
        int error;
        error = ltr558_i2c_write_reg(LTR558_ALS_CONTR, MODE_ALS_StdBy);
        return error;
}
Beispiel #18
0
static int ltr558_als_disable(struct i2c_client *client)
{
	return ltr558_i2c_write_reg(client, LTR558_ALS_CONTR, MODE_ALS_StdBy);
}