*/

static int apds9130_init_client(struct i2c_client *client)
{
	struct apds9130_data *data = i2c_get_clientdata(client);
	int err;
	int id;

	err = apds9130_set_enable(client, 0);
	if (err < 0)
		return err;

	data->pDrive = APDS9130_PDRVIE_100MA;

	id = i2c_smbus_read_byte_data(client, CMD_BYTE|APDS9130_ID_REG);
	if (id == 0x39) {
		printk(KERN_INFO"APDS-9130\n");
	}
	else {
		printk(KERN_INFO"Not APDS-9130 %x\n", id);
		return -EIO;
	}

	err = apds9130_set_ptime(client, 0xFF);	// 2.72ms Prox integration time
	if (err < 0) return err;

	err = apds9130_set_wtime(client, 0xDC);	// 100ms Wait time for POLL_MEDIUM
	if (err < 0) return err;

	err = apds9130_set_ppcount(client, APDS9130_PS_PULSE_NUMBER);
	if (err < 0) return err;

	err = apds9130_set_config(client, 0);		// no long wait
	if (err < 0) return err;

	err = apds9130_set_control(client, APDS9130_PDRVIE_100MA|APDS9130_PRX_IR_DIOD|APDS9130_PGAIN_2X);	// 2012.10.10 PGAIN 4x-> 2x chkim.
	if (err < 0) return err;

	err = apds9130_set_pilt(client, 0);		// init threshold for proximity
	if (err < 0) return err;

	err = apds9130_set_piht(client, APDS9130_PS_DETECTION_THRESHOLD);
	if (err < 0) return err;

	err = apds9130_set_pers(client, APDS9130_PPERS_2);	// 2 consecutive Interrupt persistence
	if (err < 0) return err;

	// sensor is in disabled mode but all the configurations are preset
/* Temp block the below code as no need to set cross talk threshold during proximity OFF state [LGSI_SP4_BSP][[email protected]]
#if defined(APDS9130_PROXIMITY_CAL)
	err = apds9130_set_enable(client,0);
	if(err < 0){
		printk(KERN_INFO "%s, enable set Fail\n",__func__);
		return err;
	}
#endif
*/
Exemple #2
0
 */

static int apds9130_init_client(struct i2c_client *client)
{
	struct apds9130_data *data = i2c_get_clientdata(client);
	int err;
	int id;

	err = apds9130_set_enable(client, 0);
	if (err < 0)
		return err;

	data->pDrive = APDS9130_PDRVIE_100MA;

	id = i2c_smbus_read_byte_data(client, CMD_BYTE|APDS9130_ID_REG);
	if (id == 0x39) {
		printk(KERN_INFO"APDS-9130\n");
	}
	else {
		printk(KERN_INFO"Not APDS-9130 %x\n", id);
		return -EIO;
	}

	err = apds9130_set_ptime(client, 0xFF);	// 2.72ms Prox integration time
	if (err < 0) return err;

	err = apds9130_set_wtime(client, 0xDC);	// 100ms Wait time for POLL_MEDIUM
	if (err < 0) return err;

	err = apds9130_set_ppcount(client, APDS9130_PS_PULSE_NUMBER);
	if (err < 0) return err;

	err = apds9130_set_config(client, 0);		// no long wait
	if (err < 0) return err;

	err = apds9130_set_control(client, APDS9130_PDRVIE_100MA|APDS9130_PRX_IR_DIOD|APDS9130_PGAIN_2X);	// 2012.10.10 PGAIN 4x-> 2x chkim.
	if (err < 0) return err;

	err = apds9130_set_pilt(client, 0);		// init threshold for proximity
	if (err < 0) return err;

	err = apds9130_set_piht(client, APDS9130_PS_DETECTION_THRESHOLD);
	if (err < 0) return err;

	err = apds9130_set_pers(client, APDS9130_PPERS_2);	// 2 consecutive Interrupt persistence
	if (err < 0) return err;

	// sensor is in disabled mode but all the configurations are preset
/*                                                                                                                                  
                                   
                                     
             
                                                     
             
  
      
*/
/*
 * Initialization function
 */
static int apds9130_init_client(struct i2c_client *client)
{
	int err;
	int id;

	err = apds9130_set_enable(client, 0);
	if (err < 0)
		return err;
	
	id = i2c_smbus_read_byte_data(client, CMD_BYTE|APDS9130_ID_REG);
	if (id == 0x39) {
		printk("[ProximitySensor] APDS-9130\n");
	} else {
		printk("[ProximitySensor_E] Not APDS-9130 %x\n", id);
		return -EIO;
	}

	err = apds9130_set_ptime(client, 0xFF);	// 2.72ms Prox integration time
	if (err < 0) return err;

	err = apds9130_set_wtime(client, 0xDC);	// 100ms Wait time for POLL_MEDIUM
	if (err < 0) return err;

	err = apds9130_set_ppcount(client, APDS9130_PS_PULSE_NUMBER);
	if (err < 0) return err;

	err = apds9130_set_config(client, 0);   // no long wait
	if (err < 0) return err;

#if defined(CONFIG_MACH_LGE_L9II_OPEN_EU)
	err = apds9130_set_control(client, APDS9130_PDRVIE_100MA|APDS9130_PRX_IR_DIOD|APDS9130_PGAIN_2X);
#else
	err = apds9130_set_control(client, APDS9130_PDRVIE_100MA|APDS9130_PRX_IR_DIOD|APDS9130_PGAIN_4X);
#endif
	if (err < 0) return err;

	err = apds9130_set_pilt(client, 1023);		// to force first Near-to-Far interrupt
	if (err < 0) return err;

	err = apds9130_set_piht(client, 0);
	if (err < 0) return err;

	err = apds9130_set_pers(client, APDS9130_PPERS_2);	// 2 consecutive Interrupt persistence
	if (err < 0) return err;

	// sensor is in disabled mode but all the configurations are preset

	return 0;
}
static int apds9130_enable_ps_sensor(struct i2c_client *client, int val)
{
	struct apds9130_data *data = i2c_get_clientdata(client);

	printk("[ProximitySensor] %s(%d)\n", __func__, val);

	if ((val != APDS9130_DISABLE_PS) && (val != APDS9130_ENABLE_PS_WITH_INT) && (val != APDS9130_ENABLE_PS_NO_INT)) {
		printk("[ProximitySensor_E] %s : invalid value(%d)\n", __func__, val);
		return -1;
	}

	/* APDS9130_DISABLE_PS (0) = Disable PS */
	/* APDS9130_ENABLE_PS_WITH_INT (1) = Enable PS with interrupt enabled */
	/* APDS9130_ENABLE_PS_NO_INT (2) = Enable PS without interrupt enabled */

	if(val == APDS9130_ENABLE_PS_WITH_INT || val == APDS9130_ENABLE_PS_NO_INT) {
		//turn on p sensor
		data->enable_ps_sensor = val;

		apds9130_set_enable(client,0); /* Power Off */

		apds9130_set_pilt(client, 1023);		// to force first Near-to-Far interrupt
		apds9130_set_piht(client, 0);

		/*                                               
                                       
                                                                                         
                                         
   */
		apds9130_set_pers(client, APDS9130_PPERS_0);

		if (val == APDS9130_ENABLE_PS_WITH_INT) {
			apds9130_set_enable(client, 0x2D);	 /* enable PS interrupt */

			/*
			 * If work is already scheduled then subsequent schedules will not
			 * change the scheduled time that's why we have to cancel it first.
			 */
			__cancel_delayed_work(&data->ps_dwork);
			flush_delayed_work(&data->ps_dwork);
		}
		else {
			apds9130_set_enable(client, 0x0D);	 /* no PS interrupt */

			/*
			 * If work is already scheduled then subsequent schedules will not
			 * change the scheduled time that's why we have to cancel it first.
			 */
			__cancel_delayed_work(&data->ps_dwork);
			flush_delayed_work(&data->ps_dwork);
			schedule_delayed_work(&data->ps_dwork, msecs_to_jiffies(data->ps_poll_delay));
        }
	}
	else {
		apds9130_set_enable(client, 0);
		data->enable_ps_sensor = 0;

		/*
		 * If work is already scheduled then subsequent schedules will not
		 * change the scheduled time that's why we have to cancel it first.
		 */
		__cancel_delayed_work(&data->ps_dwork);
		flush_delayed_work(&data->ps_dwork);
	}

	return 0;
}
static void apds9130_change_ps_threshold(struct i2c_client *client)
{
	struct apds9130_data *data = i2c_get_clientdata(client);

	data->ps_data =	i2c_smbus_read_word_data(client, CMD_WORD|APDS9130_PDATAL_REG);

	/*                                               
                                      
                                                                                        
                                           
  */
	apds9130_set_pers(client, APDS9130_PPERS_2);

	if(wake_lock_active(&data->wakelock))
		wake_unlock(&data->wakelock);

	wake_lock_timeout(&data->wakelock, 2*HZ);

	if ( (data->ps_data > data->pilt) && (data->ps_data >= data->piht) ) {
		/* far-to-near detected */
		data->ps_detection = 1;

		input_report_abs(data->input_dev_ps, ABS_DISTANCE, 0);/* FAR-to-NEAR detection */
		input_sync(data->input_dev_ps);

		i2c_smbus_write_word_data(client, CMD_WORD|APDS9130_PILTL_REG, data->ps_hysteresis_threshold);
		i2c_smbus_write_word_data(client, CMD_WORD|APDS9130_PIHTL_REG, 1023);

		data->pilt = data->ps_hysteresis_threshold;
		data->piht = 1023;

		printk("[ProximitySensor] far-to-NEAR\n");
	}
	else if ( (data->ps_data <= data->pilt) && (data->ps_data < data->piht) ) {
		/* near-to-far detected */
		data->ps_detection = 0;

		input_report_abs(data->input_dev_ps, ABS_DISTANCE, 1);/* NEAR-to-FAR detection */
		input_sync(data->input_dev_ps);

		i2c_smbus_write_word_data(client, CMD_WORD|APDS9130_PILTL_REG, 0);
		i2c_smbus_write_word_data(client, CMD_WORD|APDS9130_PIHTL_REG, data->ps_threshold);

		data->pilt = 0;
		data->piht = data->ps_threshold;

		printk("[ProximitySensor] near-to-FAR\n");
	}
	else if ( (data->pilt == 1023) && (data->piht == 0) ) {
		printk("[ProximitySensor] near-to-FAR with [pilt][piht] = [%d][%d]\n", data->pilt, data->piht);
		/* near-to-far detected */
		data->ps_detection = 0;

		input_report_abs(data->input_dev_ps, ABS_DISTANCE, 1);/* NEAR-to-FAR detection */
		input_sync(data->input_dev_ps);

		i2c_smbus_write_word_data(client, CMD_WORD|APDS9130_PILTL_REG, 0);
		i2c_smbus_write_word_data(client, CMD_WORD|APDS9130_PIHTL_REG, data->ps_threshold);

		data->pilt = 0;
		data->piht = data->ps_threshold;
	}

}