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;
}
Exemplo n.º 2
0
static int pollux_rtc_set_mmss(struct device *dev, unsigned long secs)
{
    int             tout = 0x10000;	// TODO:  must redefine for oem over 2 clock of 32768Hz rtc clock
	
	pollux_rtc_set_write_enable(1);
	pollux_rtc_set_counter( secs );
	while( pollux_rtc_check_busy_rtc() && tout--);
	if( tout == 0)
	{
		gprintk("RTC write timeout\n");
		return -EIO;
	}
	pollux_rtc_set_write_enable(0);
	
	return 0;
}
Exemplo n.º 3
0
static irqreturn_t optjoy_spi_irq_handler(int irq, void *dev_id)
{
	struct optjoy_drv_data *optjoy_data = dev_id;
	gprintk(" -> work_func \n");
	
	disable_irq(irq);

#if 0
	schedule_work(&optjoy_data->work);
#else
	// puts a job into the workqueue
	queue_work(optjoy_workqueue, &optjoy_data->work);
#endif

	return IRQ_HANDLED;
}
Exemplo n.º 4
0
static int lightsensor_suspend(struct platform_device *pdev, pm_message_t state)
{
	struct sensor_data *data = platform_get_drvdata(pdev);
	int rt = 0;

	mutex_lock(&data->mutex);

	if (data->enabled) {
		rt = cancel_delayed_work_sync(&data->work);
		gprintk(": The timer is cancled.\n");
	}

	mutex_unlock(&data->mutex);

	return rt;
}
Exemplo n.º 5
0
static void rebis_keyint_callback(ulong data)
{
    //struct rebis_key_detection *gd = (struct rebis_key_detection *)data;
    //int state = gd->last_state;

	//int key_base[5] = {KEY_MATRIX_BASE5, KEY_MATRIX_BASE4, KEY_MATRIX_BASE3, KEY_MATRIX_BASE2, KEY_MATRIX_BASE1};
	int i;

	gprintk("tasklet callback call\n");

	//for key scan
	#if 0
	cur_key = 0;
	s3c2410_gpio_cfgpin(S3C2410_GPF3, S3C2410_GPF3_INP);
	for(i=4; i>=0; i--)
	{
		writel(readl(S3C2410_GPBDAT) | (0x1f), S3C2410_GPBDAT);
		writel(readl(S3C2410_GPBDAT) & (~(0x1 << i)), S3C2410_GPBDAT);
		
		cur_key = scan_input();
		if(cur_key)
		//cur_key = scan_input();
		{
			cur_key += (4-i);//key_base[i];
			if(cur_key == old_key)
				goto SameValue;
			old_key = cur_key;
			printk("cur_key = %d \n\n", cur_key);
			//put_user(cur_key,(char *)buff);
			break;
		}
	}
SameValue:
	old_key = 0;
	flag = 0;

	// set GPBDAT 0
	s3c2410_gpio_setpin(S3C2410_GPB0, 0);
	s3c2410_gpio_setpin(S3C2410_GPB1, 0);
	s3c2410_gpio_setpin(S3C2410_GPB2, 0);
	s3c2410_gpio_setpin(S3C2410_GPB3, 0);
	s3c2410_gpio_setpin(S3C2410_GPB4, 0);
	
	// change External Interrupts
	s3c2410_gpio_cfgpin(S3C2410_GPF3, S3C2410_GPF3_EINT3);
	#endif
}
Exemplo n.º 6
0
static void update_brightness(struct s5p_lcd *lcd)
{
//	struct s5p_panel_data *pdata = lcd->data;	
	int brightness =  lcd->bl;
	
#if defined (LCD_TUNNING_VALUE)
	int tunned_brightness = 0;
	tunned_brightness = s5p_bl_convert_to_tuned_value(brightness);
	pwm_config(lcd->backlight_pwm_dev, (bl_freq_count * tunned_brightness)/MAX_BL, bl_freq_count);
	pwm_enable(lcd->backlight_pwm_dev);
#else
	pwm_config(lcd->backlight_pwm_dev, (bl_freq_count * brightness)/255, bl_freq_count);
	pwm_enable(lcd->backlight_pwm_dev);
	/* gprintk("## brightness = [%ld], (bl_freq_count * brightness)/255 =[%ld], ret_val_pwm_config=[%ld] \n", brightness, (bl_freq_count * brightness)/255, ret_val_pwm_config ); */
#endif
	gprintk("Update status brightness[0~255]:(%d) \n", lcd->bl);
}
Exemplo n.º 7
0
static int s5p_bl_convert_to_tuned_value(int intensity)
{
	int tune_value;

	if(intensity >= LOW_BRIGHTNESS_LEVEL)
		tune_value = (intensity - LOW_BRIGHTNESS_LEVEL) * (MAX_BACKLIGHT_VALUE-LOW_BACKLIGHT_VALUE) / (MAX_BRIGHTNESS_LEVEL-LOW_BRIGHTNESS_LEVEL) + LOW_BACKLIGHT_VALUE;
	else if(intensity >= DIM_BACKLIGHT_LEVEL)
		tune_value = (intensity - DIM_BACKLIGHT_LEVEL) * (LOW_BACKLIGHT_VALUE-DIM_BACKLIGHT_VALUE) / (LOW_BRIGHTNESS_LEVEL-DIM_BACKLIGHT_LEVEL) + DIM_BACKLIGHT_VALUE;
	else if(intensity > 0)
		tune_value = (intensity) * (DIM_BACKLIGHT_VALUE) / (DIM_BACKLIGHT_LEVEL);
	else
		tune_value = intensity;

	gprintk("Passed value : [%d], Converted value : [%d]\n", intensity, tune_value);

	return tune_value;
}
static int gp2a_opt_resume(struct platform_device *pdev)
{
	struct gp2a_data *gp2a = platform_get_drvdata(pdev);

	gprintk("\n");

	if (gp2a->enabled) {
		if (device_may_wakeup(&pdev->dev))
			enable_irq_wake(gp2a->irq);
	}

	if (proximity_avg_on)
		hrtimer_start(&gp2a->prox_timer, gp2a->prox_poll_delay,
							HRTIMER_MODE_REL);

	return 0;
}
Exemplo n.º 9
0
static int lightsensor_resume(struct platform_device *pdev)
{
	struct sensor_data *data = platform_get_drvdata(pdev);
	int rt = 0;

	first_value = true;

	mutex_lock(&data->mutex);

	if (data->enabled) {
		rt = queue_delayed_work(data->wq, &data->work, 0);
		gprintk(": The timer is started.\n");
	}

	mutex_unlock(&data->mutex);

	return rt;
}
Exemplo n.º 10
0
static int
_instance_validate(unsigned int inst_id, unsigned int dmasize)
{
    int i;
    bde_inst_resource_t *res;

    for (i = 0; i < user_bde->num_devices(BDE_ALL_DEVICES); i++) {
        res = &_bde_inst_resource[i];
        if (res->inst_id == inst_id) {
            if (res->dma_size != dmasize) {
                gprintk("ERROR: dma_size mismatch\n");
                return LUBDE_FAIL;
            }
            return (1);
        }
    }
    return LUBDE_SUCCESS;
}
static int gp2a_opt_suspend(struct platform_device *pdev, pm_message_t state)
{
	struct gp2a_data *gp2a = platform_get_drvdata(pdev);

	gprintk("\n");

	if (gp2a->enabled) {
		if (device_may_wakeup(&pdev->dev))
			enable_irq_wake(gp2a->irq);
	}

	if (proximity_avg_on) {
		cancel_work_sync(&gp2a->work_prox);
		hrtimer_cancel(&gp2a->prox_timer);
	}

	return 0;
}
Exemplo n.º 12
0
/*****************************************************************************************
 *  
 *  function    : gp2a_work_func_prox 
 *  description : This function is for proximity sensor (using B-1 Mode ). 
 *                when INT signal is occured , it gets value from VO register.   
 *
 *                 
 */
static void gp2a_work_func_prox(struct work_struct *work)
{
	struct gp2a_data *gp2a = container_of((struct work_struct *)work,
							struct gp2a_data, work);
	
	char value;
#ifdef PROX_MODE_B
    u8 reg = 0;
#endif

    disable_irq(IRQ_GP2A_INT);

    value = get_ps_vout_value(); 

    input_report_abs(gp2a->input_dev, ABS_X,  value);
    input_sync(gp2a->input_dev);

	gp2a->prox_data= value;
	gprintk("proximity = %d\n",value); //Temp

#ifdef PROX_MODE_B
    if(value == 1) //VO == 0
    {
      reg = 0x40;
      opt_i2c_write(NOT_INT_CLR(REGS_HYS), &reg);
    }
    else
    {
      reg = 0x20;
      opt_i2c_write(NOT_INT_CLR(REGS_HYS), &reg);
    }

    reg = 0x18;
    opt_i2c_write(NOT_INT_CLR(REGS_CON), &reg);
#endif //PROX_MODE_B

    enable_irq(IRQ_GP2A_INT);

#ifdef PROX_MODE_B
    reg = 0x00;
    opt_i2c_write(INT_CLR(REGS_CON), &reg);
#endif //PROX_MODE_B

}
Exemplo n.º 13
0
void gp2a_opt_early_suspend(struct early_suspend *h)
{
	int config = 0;
	int err=0;
	u8 value;
#ifdef LIGHT_SENSOR_ENABLED
        struct gp2a_data *gp2a = i2c_get_clientdata(opt_i2c_client);
#endif
	printk("[%s] proximity_enable : %d, proximity_value : %d\n", __func__, proximity_enable, proximity_value);
	if(!proximity_enable)
	{
		config = GPIO_CFG(GPIO_PS_VOUT, 0, GPIO_CFG_INPUT, GPIO_CFG_NO_PULL, GPIO_CFG_2MA);
		err = gpio_tlmm_config(config, GPIO_CFG_ENABLE);
		if (err) 
			printk(KERN_ERR "%s: gpio_tlmm_config(%#x)=%d\n", __func__, GPIO_PS_VOUT, err);
	}
	else
	{
	      is_suspend = 1;
//        	value = 0x02;
//        	opt_i2c_write((u8)(REGS_OPMOD),&value);
	}

#ifdef LIGHT_SENSOR_ENABLED
        if(light_enable)
        {
                gprintk("[%s] : hrtimer_cancle \n",__func__);
                hrtimer_cancel(&gp2a->timer);
        }
#endif

#if !defined(CONFIG_MACH_RANT3) //&& !defined(CONFIG_MACH_ESCAPE)	koh82.kwon	11.06.09	For sleep current
	if(!proximity_enable)
	{
	err = vreg_disable(vreg_als); // MBjgnoh 11.01.17 For sleep current
	if(err)
	    printk(KERN_ERR,"can not enable ldo9\n");

			err = vreg_disable(vreg_led);
	if(err)
	    printk(KERN_ERR,"can not enable ldo18\n");
	}
#endif
}
Exemplo n.º 14
0
static int __devexit optjoy_spi_remove(struct platform_device *pdev)
{
	struct optjoy_drv_data *optjoy_data = platform_get_drvdata(pdev);
#ifdef CONFIG_HAS_EARLYSUSPEND
	unregister_early_suspend(&optjoy_data->early_suspend);
#endif	/* CONFIG_HAS_EARLYSUSPEND */
	gprintk("...\n");

	if (optjoy_workqueue)
		destroy_workqueue(optjoy_workqueue);  // moved to here
	
	free_irq(IRQ_OJT_INT, optjoy_data);
	input_unregister_device(optjoy_data->input_dev);

	kfree(optjoy_data);
	platform_set_drvdata(pdev, NULL);
	
	return 0;
}
Exemplo n.º 15
0
static irqreturn_t gp2a_irq_handler(int irq, void *dev_id)
{
	struct gp2a_data *gp2a = dev_id;

	printk("[HSIL] %s\n", __func__);

	if(gp2a->irq !=-1)
	{
		disable_irq_nosync(gp2a->irq);
		gprintk("[PROXIMITY] disable_irq \n");

		queue_work(gp2a_wq, &gp2a->work_prox);

	}
	
	printk("[PROXIMITY] IRQ_HANDLED \n");

	return IRQ_HANDLED;
}
static int proximity_onoff(u8 onoff)
{
	u8 value;
	int i;
	int err = 0;

#ifdef DEBUG
	gprintk("proximity turn on/off = %d\n", onoff);
#endif

	/* already on light sensor, so must simultaneously
	   turn on light sensor and proximity sensor */
	if (onoff) {
		for (i = 0; i < COL; i++) {
			if (is_gp2a030a())
				err =
				    opt_i2c_write(gp2a_original_image_030a[i][0]
					, &gp2a_original_image_030a[i][1]);
			else
				err =
				    opt_i2c_write(gp2a_original_image[i][0],
						  &gp2a_original_image[i][1]);
			if (err < 0)
				printk(KERN_ERR
				      "%s : turnning on error i = %d, err=%d\n",
				       __func__, i, err);
			lightsensor_mode = 0;
		}
	} else { /* light sensor turn on and proximity turn off */
		if (lightsensor_mode)
			value = 0x67; /*resolution :16bit, range: *8(HIGH) */
		else
			value = 0x63; /* resolution :16bit, range: *128(LOW) */
		opt_i2c_write(COMMAND2, &value);
		/* OP3 : 1(operating mode)
		   OP2 :1(coutinuous operating mode) OP1 : 01(ALS mode) */
		value = 0xD0;
		opt_i2c_write(COMMAND1, &value);
	}

	return 0;
}
Exemplo n.º 17
0
static void __exit gp2a_opt_exit(void)
{

#ifdef LIGHT_SENSOR_ENABLED
	struct gp2a_data *gp2a = dev_get_drvdata(switch_cmd_dev);
	
    if (gp2a_wq)
		destroy_workqueue(gp2a_wq);

	kfree(gp2a);
#endif	
	
#ifdef CONFIG_HAS_EARLYSUSPEND
	unregister_early_suspend(&optsens_earlysuspend);
#endif

	i2c_del_driver(&gp2a_opt_driver);

	gprintk("%s\n",__FUNCTION__);
}
Exemplo n.º 18
0
void mDNIe_Mode_Change(mDNIe_data_type *mode)
{

	if(mDNIe_Tuning_Mode == TRUE)
	{
		printk("mDNIe_Mode_Change [mDNIe_Tuning_Mode = TRUE, API is Return] \n");
		return;
	}
	else
	{
		s3c_mdnie_mask();
		while ( mode->addr != END_SEQ)
		{
			s3c_mdnie_writel(mode->data, mode->addr);
			gprintk(KERN_INFO "[mDNIe] mDNIe_tuning_initialize: addr(0x%x), data(0x%x)  \n",mode->addr, mode->data);	
			mode++;
		}
		s3c_mdnie_unmask();
	}
}
Exemplo n.º 19
0
static int s6e63m0_spi_write_driver(struct s5p_lcd *lcd, u16 reg)
{
    u16 buf[1];
    int ret;
    struct spi_message msg;

    struct spi_transfer xfer = {
        .len	= 2,
        .tx_buf	= buf,
    };

    buf[0] = reg;

    spi_message_init(&msg);
    spi_message_add_tail(&xfer, &msg);

    ret = spi_sync(lcd->g_spi, &msg);

    if (ret < 0)
        pr_err("%s error\n", __func__);

    return ret ;
}

static void print_decoded_commands(short unsigned int commands_record[], int i)
{
    gprintk("Super AMOLED commands decoding:\n");
    if (i == 23)
    {
        gprintk("Brightness gains: Red = %3d, Green = %3d, Blue = %3d\n",
                 commands_record[18]-256, commands_record[20]-256, commands_record[22]-256);
        gprintk("Gamma 0: Red = %3d, Green = %3d, Blue = %3d\n",
                 commands_record[2]-256, commands_record[3]-256, commands_record[4]-256);
        gprintk("Gamma 1: Red = %3d, Green = %3d, Blue = %3d\n",
                 commands_record[5]-256, commands_record[6]-256, commands_record[7]-256);
        gprintk("Gamma 2: Red = %3d, Green = %3d, Blue = %3d\n",
                 commands_record[8]-256, commands_record[9]-256, commands_record[10]-256);
        gprintk("Gamma 3: Red = %3d, Green = %3d, Blue = %3d\n",
                 commands_record[11]-256, commands_record[12]-256, commands_record[13]-256);
        gprintk("Gamma 4: Red = %3d, Green = %3d, Blue = %3d\n",
                 commands_record[14]-256, commands_record[15]-256, commands_record[16]-256);
    }
}
Exemplo n.º 20
0
static int AdcToLux_Testmode(int adc)
{
	unsigned int lux = 0;

    gprintk("[%s] adc:%d\n",__func__,adc);

	/*temporary code start*/
	
	if(adc >= 1800)
		lux = 100000;
	
	else if(adc >= 800 && adc < 1800){
		lux = 5000;
	}
	else if(adc < 800){
		lux = 10;
	}
	/*temporary code end*/
	
	return lux;
}
Exemplo n.º 21
0
irqreturn_t gp2a_irq_handler(int irq, void *dev_id)
{

	struct gp2a_data *gp2a = dev_id;

	printk("[PROXIMITY] gp2a->irq = %d\n",gp2a->irq);

	if(gp2a->irq !=-1)
	{
		disable_irq(gp2a->irq);
		gprintk("[PROXIMITY] disable_irq \n");

		queue_work(gp2a_wq, &gp2a->work_prox);

	}
	
	printk("[PROXIMITY] IRQ_HANDLED \n");
	return IRQ_HANDLED;


}
Exemplo n.º 22
0
static int
lightsensor_resume(struct platform_device *pdev)
{
	struct sensor_data *data = input_get_drvdata(this_data);
	int rt = 0;

	data->light_count = 0;
	data->light_buffer = 0;
	data->light_first_level =true;

	mutex_lock(&data->mutex);

	if (data->enabled) {
		rt = queue_delayed_work(light_workqueue,&data->work,0);
		gprintk(": The timer is started.\n");
	}

	mutex_unlock(&data->mutex);

	return rt;
}
Exemplo n.º 23
0
static int gp2a_opt_suspend(struct i2c_client *client, pm_message_t state) {
	struct gp2a_data *gp2a = i2c_get_clientdata(client);

	gprintk("suspend, proximity_enable:%d\n", proximity_enable);

//20110702 [email protected] nothing [S]
#if defined(CONFIG_LU6500) || defined(CONFIG_KS1001) || defined(CONFIG_KS1103) || defined (CONFIG_SU880) || defined (CONFIG_KU8800) || defined (CONFIG_LU8800)
	// nothing
#else
	if(proximity_enable) {
		//20111001 [email protected] : Set Operation mode B1 for X2 New HW Revision [S]
		//Operation Mode(0x03) -> Shutdown Mode(0x02)
		disable_irq_nosync(gp2a->irq);
		opt_i2c_write(gp2a, (u8)(REGS_OPMOD), 0x02);
		//20111001 [email protected] : Set Operation mode B1 for X2 New HW Revision [E]
		proximity_enable = OFF;
	}
#endif
//20110702 [email protected] nothing [E]

	return 0;
}
Exemplo n.º 24
0
static int opt_i2c_probe(struct i2c_client *client,  const struct i2c_device_id *id)
{
	struct opt_state *opt;

    gprintk("\n");
	opt = kzalloc(sizeof(struct opt_state), GFP_KERNEL);
	if (opt == NULL) {		
		printk("failed to allocate memory \n");
		return -ENOMEM;
	}
	
	opt->client = client;
	i2c_set_clientdata(client, opt);
	
	/* rest of the initialisation goes here. */
	
	printk("GP2A opt i2c attach success!!!\n");

	opt_i2c_client = client;

	return 0;
}
Exemplo n.º 25
0
static ssize_t
light_delay_store(struct device *dev, struct device_attribute *attr,
		  const char *buf, size_t count)
{
	struct sensor_data *data = dev_get_drvdata(dev);
	int delay;
	int err = 0;

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

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

	if (delay < 0)
		return count;

	delay = delay / 1000000;	/* ns to msec */

	gprintk("new_delay = %d, old_delay = %d", delay, data->delay);

	if (SENSOR_MAX_DELAY < delay)
		delay = SENSOR_MAX_DELAY;

	data->delay = delay;

	mutex_lock(&data->mutex);

	if (data->enabled) {
		cancel_delayed_work_sync(&data->work);
		queue_delayed_work(data->wq, &data->work,
				   msecs_to_jiffies(delay));
	}

	mutex_unlock(&data->mutex);

	return count;
}
Exemplo n.º 26
0
void gp2a_on(struct gp2a_data *gp2a) {
	int i;

	if(proximity_enable == OFF) {
		gprintk("gp2a power on\n");
#if defined(CONFIG_LU6500) || defined(CONFIG_KS1001)
		gp2a_power_control(ON);
		msleep(5);	
#endif
		proximity_enable = ON;
		//20111001 [email protected] : Set Operation mode B1 for X2 New HW Revision [S]
		//Shutdown Mode(0x02) -> Operation Mode(ox03) Procedure 1~5
		opt_i2c_write(gp2a, (u8)(REGS_CON),  0x18);//1
		opt_i2c_write(gp2a, (u8)(REGS_HYS),  0x40);//2
		opt_i2c_write(gp2a, (u8)(REGS_OPMOD),  0x03);//3

		enable_irq(gp2a->irq);//4
		msleep(2);
		opt_i2c_write(gp2a, (u8)(REGS_CON),  0x00);//5
		//20111001 [email protected] : Set Operation mode B1 for X2 New HW Revision [E]
		
		gp2a_read_forcely(gp2a);
	}
}
Exemplo n.º 27
0
int opt_i2c_read(u8 reg, u8 *val, unsigned int len )
{

	int err;
	u8 buf[1];
	struct i2c_msg msg[2];

	buf[0] = reg; 

	msg[0].addr = opt_i2c_client->addr;
	msg[0].flags = 1;
	
	msg[0].len = len;
	msg[0].buf = buf;
	err = i2c_transfer(opt_i2c_client->adapter, msg, 1);

	*val = buf[1];

    gprintk(": 0x%x, 0x%x \n", reg, *val);
    if (err >= 0) return 0;

    printk("%s %d i2c transfer error\n", __func__, __LINE__);
    return err;
}
Exemplo n.º 28
0
static int gp2a_opt_probe(struct i2c_client *client,
			 const struct i2c_device_id *id)
{
	int err = 0;
	int i;
#if USE_INTERRUPT
	int irq;
#endif
	int config;

	struct gp2a_data *gp2a;
#ifdef STM_DEBUG
	printk(KERN_INFO "%s\n",__FUNCTION__);
#endif

#if defined(CONFIG_MACH_TOTORO_CTC) && (CONFIG_BOARD_REVISION >= 0x02) //twkim add proximity sensor driver to totoro_ctc
    {
		vreg_proximity = vreg_get(0, "ldo9"); //twkim fixed pmic set
		if (IS_ERR(vreg_proximity))
		{	
			printk("===== [PROXIMITY] proximity IS_ERR TEST =====\n");
			return PTR_ERR(vreg_proximity);
		}
	
#if defined(CONFIG_MACH_TOTORO_CTC) && (CONFIG_BOARD_REVISION >= 0x02) //twkim add proximity sensor driver to totoro_ctc
             vreg_set_level(vreg_proximity, OUT2800mV); // set to 3.0V voltage twkim 12 -> 10 to set 2.85V -> 2.6v
             gp2a_gpio_set(ENABLE);
#else
	vreg_set_level(vreg_proximity, OUT2850mV); // set to 3.0V voltage twkim 12 -> 10 to set 2.85V
#endif
		vreg_enable(vreg_proximity); // voltage 
	}
#else
	if( board_hw_revision < 3 )
	{
		vreg_proximity = vreg_get(0, "ldo19");
		if (IS_ERR(vreg_proximity))
		{	
			printk("===== [PROXIMITY] proximity IS_ERR TEST =====\n");
			return PTR_ERR(vreg_proximity);
		}
	
	vreg_set_level(vreg_proximity, 12); // set to 3.0V voltage 
		vreg_enable(vreg_proximity); // voltage 
	}
	else
	{
		gpio_set_value(VIR_LED_EN, 1);
	}
#endif    
	
	if (!i2c_check_functionality(client->adapter, I2C_FUNC_I2C))
	{
		printk(KERN_INFO "[GP2A] i2c_check_functionality error\n");
		err = -ENODEV;
		goto exit;
	}
	if ( !i2c_check_functionality(client->adapter,I2C_FUNC_SMBUS_BYTE_DATA) ) {
		printk(KERN_INFO "[GP2A] byte op is not permited.\n");
		goto exit;
	}

	/* OK. For now, we presume we have a valid client. We now create the
	client structure, even though we cannot fill it completely yet. */
	if (!(gp2a = kzalloc(sizeof(struct gp2a_data), GFP_KERNEL)))
	{
		err = -ENOMEM;
		goto exit;
	}
	memset(gp2a, 0, sizeof(struct gp2a_data));
	gp2a->client = client;
	i2c_set_clientdata(client, gp2a);

	opt_i2c_client = client;

	if (i2c_smbus_read_byte(client) < 0)
	{
		printk(KERN_ERR "[GP2A] i2c_smbus_read_byte error!!\n");
		goto exit_kfree;
	}
	else
	{
		printk("GP2A Device detected!\n");
	}

	printk("[%s] slave addr = %x\n", __func__, client->addr);
	
	/* Input device Settings */
	if(USE_INPUT_DEVICE)
	{
		gp2a->input_dev = input_allocate_device();
		if (gp2a->input_dev == NULL) 
		{
			pr_err("Failed to allocate input device\n");
			return -ENOMEM;
		}
		gp2a->input_dev->name = "proximity_sensor";
	
		set_bit(EV_SYN,gp2a->input_dev->evbit);
		set_bit(EV_ABS,gp2a->input_dev->evbit);
		
 	       input_set_abs_params(gp2a->input_dev, ABS_DISTANCE, 0, 1, 0, 0);
		
	
		err = input_register_device(gp2a->input_dev);
		if (err) 
		{
			pr_err("Unable to register %s input device\n", gp2a->input_dev->name);
			input_free_device(gp2a->input_dev);
			kfree(gp2a);
			return -1;
		}

	}

#if USE_INTERRUPT
	/* WORK QUEUE Settings */
	gp2a_wq = create_singlethread_workqueue("gp2a_wq");
	if (!gp2a_wq)
		return -ENOMEM;
	INIT_WORK(&gp2a->work_prox, gp2a_work_func_prox);
	gprintk("Workqueue Settings complete\n");
#endif

	/* misc device Settings */
	err = misc_register(&proximity_device);
	if(err) {
		pr_err(KERN_ERR "misc_register failed - prox \n");
	}

	/* wake lock init */
	wake_lock_init(&prx_wake_lock, WAKE_LOCK_SUSPEND, "prx_wake_lock");

	/* set sysfs for light sensor */
	proxsensor_class = class_create(THIS_MODULE, "proxsensor");
	if (IS_ERR(proxsensor_class))
		pr_err("Failed to create class(proxsensor)!\n");

	switch_cmd_dev = device_create(proxsensor_class, NULL, 0, NULL, "switch_cmd");	
	if (device_create_file(switch_cmd_dev, &dev_attr_proxsensor_file_state) < 0)
		pr_err("Failed to create device file(%s)!\n", dev_attr_proxsensor_file_state.attr.name);
	
	dev_set_drvdata(switch_cmd_dev,gp2a);
	
	/* ktime init */

	timeA = ktime_set(0,0);
	timeB = ktime_set(0,0);
	
	/* gpio config */
	config = GPIO_CFG(GPIO_SENSE_OUT, 0, GPIO_CFG_INPUT, GPIO_CFG_NO_PULL, GPIO_CFG_2MA);
	err = gpio_tlmm_config(config, GPIO_CFG_ENABLE);
	if (err) 
		printk(KERN_ERR "%s: gpio_tlmm_config(%#x)=%d\n", __func__, GPIO_SENSE_OUT, err);

	/* GP2A Regs INIT SETTINGS */
	for(i=1;i<5;i++)
	{
		opt_i2c_write((u8)(i),&gp2a_original_image[i]);
	}

	mdelay(2);
#if USE_INTERRUPT
	/* INT Settings */	
	irq = gpio_to_irq(GPIO_SENSE_OUT);
	gp2a->irq = -1;
	set_irq_type(irq, IRQ_TYPE_EDGE_BOTH);

	err = request_irq(irq, gp2a_irq_handler, IRQF_DISABLED, "gp2a_int", gp2a);
	if (err)
	{
		printk("[GP2A] request_irq failed for gp2a\n");
		goto exit_kfree;
	}

	printk("[GP2A] register irq = %d\n",irq);
	err = set_irq_wake(irq, 1);
	printk("[GP2A] register wakeup source = %d\n",err);
	if (err) 
		printk("[GP2A] register wakeup source failed\n");
	
	gp2a->irq = irq;
	gprintk("INT Settings complete\n");
#endif
	
	// maintain power-down mode before using sensor
	gp2a_off(gp2a,ALL);
	
//++	// test for sensor 

/*
	printk("[GP2A] curr prox value = %d\n", gpio_get_value(GPIO_SENSE_OUT));
	gp2a_on(gp2a,PROXIMITY);
	printk("[GP2A] curr prox value = %d\n", gpio_get_value(GPIO_SENSE_OUT));
	
//--

	// maintain power-down mode before using sensor
	//ESD test sleep
	gp2a_off(gp2a,ALL);
*/

	printk("gp2a_opt_probe is OK!!\n");
	return 0;
	
exit_kfree:
	kfree(gp2a);
exit:
	return err;
}
Exemplo n.º 29
0
void gp2a_on(struct gp2a_data *gp2a, int type)
{
	u8 value;
	int err = 0;
	
	gprintk("gp2a_on(%d)\n",type);
	gprintk("gp2a power on voltage up \n");
#if defined(CONFIG_MACH_TOTORO_CTC) && (CONFIG_BOARD_REVISION >= 0x02) //twkim add proximity sensor driver to totoro_ctc
        gp2a_gpio_set(ENABLE);
        vreg_enable(vreg_proximity); // voltage 
#else        
	if( board_hw_revision < 3 )
	{
		vreg_enable(vreg_proximity); // voltage 
	}
	else
	{
		gpio_set_value(VIR_LED_EN, 1);
	}
#endif    

	//register irq to wakeup source
	printk("[GP2A] register irq = %d\n",gp2a ->irq);
	err = set_irq_wake(gp2a ->irq, 1);  // enable : 1, disable : 0
	printk("[GP2A] register wakeup source = %d\n",err);
	if (err) 
		printk("[GP2A] register wakeup source failed\n");
	

	// ASD : Select switch for analog sleep function ( 0:ineffective, 1:effective )
	// OCON[1:0] : Select switches for enabling/disabling VOUT terminal 
	//             ( 00:enable, 11:force to go High, 10:forcr to go Low )
	value = 0x18;	// 11:force to go High
	opt_i2c_write((u8)(REGS_CON),&value);

#if (SENSOR_MODE == SENSOR_MODE_B1)
	value = 0x40;	// HYSD enable
#elif (SENSOR_MODE == SENSOR_MODE_B15)
	value = 0x2F;	// HYSD enable
#elif (SENSOR_MODE == SENSOR_MODE_B2)
	value = 0x20;	// HYSD enable
#endif
	
	opt_i2c_write((u8)(REGS_HYS),&value);

	// VCON : VOUT terminal output method control ( 0:normal mode, 1:interrupt mode )
	// SSD : Software shutdown function ( 0:shutdown mode, 1:opteration mode )
	value = 0x03;	// VCON enable, SSD enable
	opt_i2c_write((u8)(REGS_OPMOD),&value);

	if(type == PROXIMITY)
	{
		gprintk("enable irq for proximity\n");
		enable_irq(gp2a ->irq);
	}

	// OCON[1:0] : Select switches for enabling/disabling VOUT terminal 
	//             ( 00:enable, 11:force to go High, 10:forcr to go Low )
	value = 0x00;	// 00:enable
	opt_i2c_write((u8)(REGS_CON),&value);
}
Exemplo n.º 30
0
static void gp2a_work_func_prox(struct work_struct *work)
{
	struct gp2a_data *gp2a = container_of(work, struct gp2a_data, work_prox);
	
	unsigned char value;
	unsigned char int_val=REGS_PROX;
	unsigned char vout=0;

	/* Read VO & INT Clear */
	
	gprintk("[PROXIMITY] %s : \n",__func__);

	if(INT_CLEAR)
	{
		//int_val = REGS_PROX | (1 <<7);
	}
	opt_i2c_read((u8)(int_val),&value,1);
	vout = value & 0x01;
	printk(KERN_INFO "[PROXIMITY] value = %d \n",vout);



	/* Report proximity information */
	proximity_value = vout;

	
	if(proximity_value ==0)
	{
		timeB = ktime_get();
		
		timeSub = ktime_sub(timeB,timeA);
		printk(KERN_INFO "[PROXIMITY] timeSub sec = %d, timeSub nsec = %d \n",timeSub.tv.sec,timeSub.tv.nsec);
		
		if (timeSub.tv.sec>=3 )
		{
		    wake_lock_timeout(&prx_wake_lock,HZ/2);
			printk(KERN_INFO "[PROXIMITY] wake_lock_timeout : HZ/2 \n");
		}
		else
			printk(KERN_INFO "[PROXIMITY] wake_lock is already set \n");

	}

	if(USE_INPUT_DEVICE)
	{
		input_report_abs(gp2a->input_dev,ABS_DISTANCE,(int)vout);
		input_sync(gp2a->input_dev);
		mdelay(1);
	}

	/* Write HYS Register */

#if (SENSOR_MODE == SENSOR_MODE_B1)
	if(!vout)
	{
		value = 0x40;


	}
	else
	{
		value = 0x20;

	}
#elif (SENSOR_MODE == SENSOR_MODE_B15)
	if(!vout)
	{
		value = 0x2F;


	}
	else
	{
		value = 0x0F;

	}
#elif (SENSOR_MODE == SENSOR_MODE_B2)
	if(!vout)
	{
		value = 0x20;


	}
	else
	{
		value = 0x00;

	}
#endif
    
	
	opt_i2c_write((u8)(REGS_HYS),&value);

	/* Forcing vout terminal to go high */

	value = 0x18;
	opt_i2c_write((u8)(REGS_CON),&value);


	/* enabling VOUT terminal in nomal operation */

	value = 0x00;

	opt_i2c_write((u8)(REGS_CON),&value);

	
	/* enable INT */

	enable_irq(gp2a->irq);
}