Example #1
0
static ssize_t
proximity_enable_store(struct device *dev,
        struct device_attribute *attr,
        const char *buf,
        size_t count)
{
    struct input_dev *input_data = to_input_dev(dev);
    struct gp2a_data *data = input_get_drvdata(input_data);
    int value = simple_strtoul(buf, NULL, 10);

    if (value != 0 && value != 1) {
        return count;
    }

    if (data->enabled && !value) { 			/* Proximity power off */
        disable_irq(IRQ_GP2A_INT);
		proximity_onoff(0);
    }
    if (!data->enabled && value) {			/* proximity power on */
		proximity_onoff(1);
        enable_irq(IRQ_GP2A_INT);
    }
    data->enabled = value;

    input_report_abs(input_data, ABS_CONTROL_REPORT, (value<<16) | data->delay);

    return count;
}
static ssize_t
proximity_enable_store(struct device *dev,
			struct device_attribute *attr,
			const char *buf, size_t count)
{
	struct gp2a_data *data = dev_get_drvdata(dev);

	int value = 0;
	int err = 0;
	int16_t thrd;
	u8 reg;

	err = kstrtoint(buf, 10, &value);

	if (err) {
		pr_err("%s, kstrtoint failed.", __func__);
		goto done;
	}
	if (value != 0 && value != 1)
		goto done;

        printk(KERN_INFO "[GP2A] proximity_enable_store : value=%d, offset=%d\n", value, data->offset_value);

	if (data->proximity_enabled && !value) {	/* Prox power off */
		data->proximity_enabled = value;
		disable_irq(data->irq);

		proximity_onoff(0, data);
		if (data->pdata->led_on)
			data->pdata->led_on(0);
	}
	if (!data->proximity_enabled && value) {	/* prox power on */
		data->proximity_enabled = value;
		if (data->pdata->led_on)
			data->pdata->led_on(1);
		msleep(5);
		proximity_onoff(1, data);

		thrd = gp2a_reg[3][1]+(data->offset_value);
		THR_REG_LSB(thrd, reg);
		gp2a_i2c_write(gp2a_reg[3][0], &reg);
		THR_REG_MSB(thrd, reg);
		gp2a_i2c_write(gp2a_reg[4][0], &reg);

		thrd = gp2a_reg[5][1]+(data->offset_value);
		THR_REG_LSB(thrd, reg);
		gp2a_i2c_write(gp2a_reg[5][0], &reg);
		THR_REG_MSB(thrd, reg);
		gp2a_i2c_write(gp2a_reg[6][0], &reg);

		input_report_abs(data->proximity_input_dev, ABS_DISTANCE, 1);
		input_sync(data->proximity_input_dev);

		enable_irq(data->irq);
	}
done:
	return count;
}
Example #3
0
static ssize_t
proximity_enable_store(struct device *dev,
                       struct device_attribute *attr, const char *buf, size_t count)
{
    struct input_dev *input_data = to_input_dev(dev);
    struct gp2a_data *data = input_get_drvdata(input_data);
    int value = simple_strtoul(buf, NULL, 10);
    char input;
    unsigned long flags;

    if (value != 0 && value != 1)
        return count;

    /* Proximity power off */
    if (data->enabled && !value) {
        disable_irq(data->irq);

        proximity_onoff(0);
        disable_irq_wake(data->irq);
        if (data->gp2a_led_on)
            data->gp2a_led_on(0);
        if (data->power_on)
            data->power_on(0);
    }
    /* proximity power on */
    if (!data->enabled && value) {
        if (data->power_on)
            data->power_on(1);
        if (data->gp2a_led_on)
            data->gp2a_led_on(1);
        msleep(1);
        proximity_onoff(1);

        input = 0x01;
        opt_i2c_write((u8)(REGS_OPMOD), &input);

        msleep(50);
        enable_irq_wake(data->irq);
        input = gpio_get_value_cansleep(data->ps_status);
        input_report_abs(data->input_dev, ABS_DISTANCE,  input);

        input_sync(data->input_dev);
        gprintk("[PROX] Start proximity = %d\n", input);
        spin_lock_irqsave(&data->prox_lock, flags);
        input = 0x03;
        opt_i2c_write((u8)(REGS_OPMOD), &input);

        enable_irq(data->irq);

        spin_unlock_irqrestore(&data->prox_lock, flags);
    }

    data->enabled = value;
    input_report_abs(input_data, ABS_CONTROL_REPORT,
                     (value<<16) | data->delay);
    return count;
}
Example #4
0
static ssize_t
proximity_enable_store(struct device *dev,
		       struct device_attribute *attr,
		       const char *buf, size_t count)
{
	struct gp2a_data *data = dev_get_drvdata(dev);
	int value = 0;
	char input;
	int err = 0;

	err = kstrtoint(buf, 10, &value);

	if (err)
		pr_err("%s, kstrtoint failed.", __func__);

	if (value != 0 && value != 1)
		return count;

	gprintk("value = %d\n", value);

	if (data->enabled && !value) {	/* Proximity power off */
		disable_irq(data->irq);

		proximity_enable = value;
		proximity_onoff(0);
		disable_irq_wake(data->irq);
		data->pdata->gp2a_led_on(false);
	} else if (!data->enabled && value) {	/* proximity power on */
		data->pdata->gp2a_led_on(true);
		/*msleep(1); */
#ifdef GP2A_CALIBRATION
		/* open cancelation data */
		err = proximity_open_calibration(data);
		if (err < 0 && err != -ENOENT)
			pr_err("%s: proximity_open_calibration() failed\n",
				__func__);
#endif
		proximity_enable = value;
		proximity_onoff(1);
		enable_irq_wake(data->irq);

		input = gpio_get_value(data->pdata->p_out);
		input_report_abs(data->input_dev, ABS_DISTANCE, input);
		input_sync(data->input_dev);

		enable_irq(data->irq);
	}
	data->enabled = value;

	return count;
}
static ssize_t
proximity_enable_store(struct device *dev,
		       struct device_attribute *attr,
		       const char *buf, size_t count)
{
	struct gp2a_data *data = dev_get_drvdata(dev);

	int value = 0;
	int err = 0;

	err = kstrtoint(buf, 10, &value);

	if (err)
		pr_err("%s, kstrtoint failed.", __func__);

	if (value != 0 && value != 1)
		return count;

        printk(KERN_INFO "[GP2A] proximity_enable_store : value=%d, offset=%d\n", value, data->offset_value);

	if (data->proximity_enabled && !value) {	/* Prox power off */
		disable_irq_wake(data->irq);
		disable_irq(data->irq);

		proximity_onoff(0, data);
		#if defined (CONFIG_MACH_HENNESSY_DUOS_CTC)
		if (data->pdata->gp2a_led_on && data->light_enabled!=1)
		#else
		if (data->pdata->gp2a_led_on)
		#endif
			data->pdata->gp2a_led_on(0);
	}
	if (!data->proximity_enabled && value) {	/* prox power on */
		if (data->pdata->gp2a_led_on) {
			data->pdata->gp2a_led_on(1);
                        msleep(5);
		}
		proximity_onoff(1, data);

		input_report_abs(data->proximity_input_dev, ABS_DISTANCE, 1);
		input_sync(data->proximity_input_dev);

		enable_irq_wake(data->irq);
		enable_irq(data->irq);
	}
	data->proximity_enabled = value;

	return count;
}
Example #6
0
static ssize_t
proximity_enable_store(struct device *dev,
		       struct device_attribute *attr,
		       const char *buf, size_t count)
{
	struct gp2a_data *data = dev_get_drvdata(dev);

	int value = 0;
	char input;
	int err = 0;

	err = kstrtoint(buf, 10, &value);

	if (err)
		pr_err("%s, kstrtoint failed.", __func__);

	if (value != 0 && value != 1)
		return count;

	pr_info("%s, %d value = %d\n", __func__, __LINE__, value);

	if (data->proximity_enabled && !value) {	/* Prox power off */
		disable_irq(data->irq);

		proximity_onoff(0, data);
		disable_irq_wake(data->irq);
		if (data->pdata->gp2a_led_on)
			data->pdata->gp2a_led_on(0);
	}
	if (!data->proximity_enabled && value) {	/* prox power on */
		if (data->pdata->gp2a_led_on)
			data->pdata->gp2a_led_on(1);
		usleep(1000);
		proximity_onoff(1, data);
		enable_irq_wake(data->irq);
		msleep(160);

		input = gpio_get_value_cansleep(data->pdata->p_out);
		input_report_abs(data->proximity_input_dev,
			ABS_DISTANCE, input);
		input_sync(data->proximity_input_dev);

		enable_irq(data->irq);
	}
	data->proximity_enabled = value;

	return count;
}
static ssize_t
proximity_enable_store(struct device *dev,
		       struct device_attribute *attr,
		       const char *buf, size_t count)
{
	struct gp2a_data *data = dev_get_drvdata(dev);
	int value = 0;
	char input;
	int err = 0;

	err = kstrtoint(buf, 10, &value);

	if (err)
		printk(KERN_ERR "%s, kstrtoint failed.", __func__);

	if (value != 0 && value != 1)
		return count;

	gprintk("value = %d\n", value);

	if (data->enabled && !value) {	/* Proximity power off */
		disable_irq(data->irq);

		proximity_enable = value;
		proximity_onoff(0);
		disable_irq_wake(data->irq);
#ifndef CONFIG_MACH_MIDAS_02_BD
		data->pdata->gp2a_led_on(false);
#endif
	} else if (!data->enabled && value) {	/* proximity power on */
		data->pdata->gp2a_led_on(true);
		/*msleep(1); */

		proximity_enable = value;
		proximity_onoff(1);
		enable_irq_wake(data->irq);
		msleep(160);

		input = gpio_get_value(data->pdata->p_out);
		input_report_abs(data->input_dev, ABS_DISTANCE, input);
		input_sync(data->input_dev);

		enable_irq(data->irq);
	}
	data->enabled = value;

	return count;
}
static int gp2a_i2c_resume(struct device *dev)
{
	struct i2c_client *client = to_i2c_client(dev);
	struct gp2a_data *gp2a = i2c_get_clientdata(client);

	int ret = 0;

	if (!gp2a->proximity_enabled) {
		ret = gpio_request(gp2a->pdata->p_out, "gpio_proximity_out");
		if (ret)
			pr_err("%s gpio request %d err\n", __func__, gp2a->irq);
		if (gp2a->pdata->power_on)
			gp2a->pdata->power_on(1);
		proximity_onoff(1,gp2a);
	}

	mutex_lock(&gp2a->light_mutex);

	if (gp2a->light_enabled)
		schedule_delayed_work(&gp2a->light_work, msecs_to_jiffies(100));

	mutex_unlock(&gp2a->light_mutex);

	return 0;
}
Example #9
0
static int gp2a_opt_remove(struct platform_device *pdev)
{
	struct gp2a_data *gp2a = platform_get_drvdata(pdev);

	if (gp2a == NULL) {
		pr_err("%s, gp2a_data is NULL!!!!!\n", __func__);
		return -1;
	}

	if (gp2a->enabled) {
		disable_irq(gp2a->irq);
		proximity_enable = 0;
		proximity_onoff(0);
		disable_irq_wake(gp2a->irq);
#ifndef CONFIG_MACH_MIDAS_02_BD
		gp2a->pdata->gp2a_led_on(false);
#endif
		gp2a->enabled = 0;
	}

	hrtimer_cancel(&gp2a->prox_timer);
	cancel_work_sync(&gp2a->work_prox);
	destroy_workqueue(gp2a->prox_wq);
#ifdef CONFIG_SLP
	device_init_wakeup(gp2a->proximity_dev, false);
#endif
	device_remove_file(gp2a->proximity_dev, &dev_attr_prox_thresh);
	device_remove_file(gp2a->proximity_dev, &dev_attr_prox_avg);
	device_remove_file(gp2a->proximity_dev, &dev_attr_state);
	device_remove_file(gp2a->proximity_dev, &dev_attr_vendor);
	device_remove_file(gp2a->proximity_dev, &dev_attr_name);
	device_remove_file(gp2a->proximity_dev, &dev_attr_raw_data);
#ifdef GP2A_CALIBRATION
	device_remove_file(gp2a->proximity_dev, &dev_attr_prox_cal);
	device_remove_file(gp2a->proximity_dev, &dev_attr_prox_diff);
#endif
	sensors_classdev_unregister(gp2a->proximity_dev);

	if (gp2a->input_dev != NULL) {
		sysfs_remove_group(&gp2a->input_dev->dev.kobj,
				   &proximity_attribute_group);
		input_unregister_device(gp2a->input_dev);
		if (gp2a->input_dev != NULL)
			kfree(gp2a->input_dev);
	}

	wake_lock_destroy(&gp2a->prx_wake_lock);
	device_init_wakeup(&pdev->dev, 0);
	free_irq(gp2a->irq, gp2a);
	gpio_free(gp2a->pdata->p_out);
	mutex_destroy(&gp2a->data_mutex);
	kfree(gp2a);

	return 0;
}
static ssize_t proximity_avg_store(struct device *dev,
				   struct device_attribute *attr,
				   const char *buf, size_t size)
{
	struct gp2a_data *data = dev_get_drvdata(dev);
	bool new_value;

	if (sysfs_streq(buf, "1"))
		new_value = true;
	else if (sysfs_streq(buf, "0"))
		new_value = false;
	else {
		pr_err("%s: invalid value %d\n", __func__, *buf);
		return -EINVAL;
	}

	if (new_value && !proximity_avg_on) {
		if (!(proximity_enable)) {
			/*data->pdata->gp2a_led_on(true);*/
			proximity_onoff(1);
		}
		hrtimer_start(&data->prox_timer, data->prox_poll_delay,
							HRTIMER_MODE_REL);
		proximity_avg_on = 1;
	} else if (!new_value && proximity_avg_on) {
		int i;

		cancel_work_sync(&data->work_prox);
		hrtimer_cancel(&data->prox_timer);
		proximity_avg_on = 0;

		if (!(proximity_enable)) {
			proximity_onoff(0);
			/*data->pdata->gp2a_led_on(false);*/
		}

		for (i = 0 ; i < 3 ; i++)
			data->average[i] = 0;
	}

	return size;
}
Example #11
0
static int gp2a_opt_resume( struct platform_device* pdev )
{

	struct gp2a_data *gp2a = platform_get_drvdata(pdev);

	gprintk("\n");

#if 0
	if(gp2a->enabled) //calling
	{
      if (device_may_wakeup(&pdev->dev))
        disable_irq_wake(IRQ_GP2A_INT);

      gprintk("The timer is cancled.\n");
	}
	gpio_set_value_cansleep(PM8058_GPIO_PM_TO_SYS(PMIC_GPIO_PROX_EN), 1);
	proximity_onoff(1);  // when proximity 0 , enter suspend and than resume proximity does not work issue

#endif
    return 0;
}
static ssize_t
proximity_enable_store(struct device *dev,
			struct device_attribute *attr,
			const char *buf, size_t count)
{
	struct gp2a_data *data = dev_get_drvdata(dev);

	int value = 0;
	char input;
	int err = 0;
	int16_t thrd;
	u8 reg;

	err = kstrtoint(buf, 10, &value);

	if (err) {
		pr_err("%s, kstrtoint failed.", __func__);
		goto done;
	}
	if (value != 0 && value != 1)
		goto done;

	pr_info("%s, %d value = %d\n", __func__, __LINE__, value);

	if (data->proximity_enabled && !value) {	/* Prox power off */
		disable_irq(data->irq);

		proximity_onoff(0, data);
		disable_irq_wake(data->irq);
		if (data->pdata->led_on)
			data->pdata->led_on(false);
	}
	if (!data->proximity_enabled && value) {	/* prox power on */
		if (data->pdata->led_on)
			data->pdata->led_on(true);
		usleep_range(1000, 1100);
		proximity_onoff(1, data);

		err = proximity_open_calibration(data);
		if (err < 0 && err != -ENOENT)
			pr_err("%s: proximity_open_offset() failed\n",
				__func__);
		else {
			thrd = gp2a_reg[3][1]+(data->offset_value);
			THR_REG_LSB(thrd, reg);
			gp2a_i2c_write(data, gp2a_reg[3][0], &reg);
			THR_REG_MSB(thrd, reg);
			gp2a_i2c_write(data, gp2a_reg[4][0], &reg);

			thrd = gp2a_reg[5][1]+(data->offset_value);
			THR_REG_LSB(thrd, reg);
			gp2a_i2c_write(data, gp2a_reg[5][0], &reg);
			THR_REG_MSB(thrd, reg);
			gp2a_i2c_write(data, gp2a_reg[6][0], &reg);
		}

		enable_irq_wake(data->irq);
		msleep(160);

		input = gpio_get_value_cansleep(data->pdata->p_out);
		if (input == 0) {
			input_report_abs(data->proximity_input_dev,
					ABS_DISTANCE, 1);
			input_sync(data->proximity_input_dev);
		}

		enable_irq(data->irq);
	}
	data->proximity_enabled = value;
done:
	return count;
}
Example #13
0
static ssize_t
proximity_enable_store(struct device *dev,
        struct device_attribute *attr,
        const char *buf,
        size_t count)
{
    struct input_dev *input_data = to_input_dev(dev);
    struct gp2a_data *data = input_get_drvdata(input_data);
    int value = simple_strtoul(buf, NULL, 10);
    int err = 0;
    
    struct file *fp_sd 	 = NULL;
	mm_segment_t old_fs;
	
	if( external_sd_status_read==0 )
	{
	//For Hardware detected	
	printk(KERN_INFO "SD card Hardware detected\n");
	fp_sd = filp_open( "/persist/sd_det.bin", O_RDWR , 0666);

	if(IS_ERR(fp_sd)||(fp_sd==NULL))
	{
		printk(KERN_ERR "[SDCard] %s: File open error\n", "persist/sd_det.bin");
	}
	else
	{
		
		old_fs = get_fs();
       	set_fs(KERNEL_DS);
        	
		char buffer[2]	 = {1};
		if(fp_sd->f_mode & FMODE_WRITE)
		{
			sprintf(buffer,"0\n");
			printk(KERN_INFO "[SDCard] external_sd_status = 0\n");
			fp_sd->f_op->write(fp_sd, (const char *)buffer, sizeof(buffer), &fp_sd->f_pos);
		}

		if( fp_sd != NULL ) {
 		filp_close(fp_sd, NULL);
 		fp_sd = NULL;
 		}
		external_sd_status_read = 1;
 		set_fs(old_fs);
 	
		}
	}

    gprintk("\n");



    if (value != 0 && value != 1) {
        return count;
    }

    if (data->enabled && !value) { 			/* Proximity power off */

	//register irq to wakeup source
	err = irq_set_irq_wake(IRQ_GP2A_INT, 0);	// enable : 1, disable : 0
	printk("[TAEKS] register wakeup source = %d\n",err);
	if (err) 
		printk("[TAEKS] register wakeup source failed\n");
		
       disable_irq(IRQ_GP2A_INT);
	proximity_onoff(0);
    }
    if (!data->enabled && value) {			/* proximity power on */
	proximity_onoff(1);

	//register irq to wakeup source
	err = irq_set_irq_wake(IRQ_GP2A_INT, 1);	// enable : 1, disable : 0
	printk("[TAEKS] register wakeup source = %d\n",err);
	if (err) 
		printk("[TAEKS] register wakeup source failed\n");
		
        enable_irq(IRQ_GP2A_INT);
    }
    data->enabled = value;

        printk("[HSS] [%s] enable = %d\n", __FUNCTION__, value);

    input_report_abs(input_data, ABS_CONTROL_REPORT, (value<<16) | data->delay);

    return count;
}