static long proximity_ioctl(struct file *filp, unsigned int cmd, unsigned long arg) { struct gp2a_data *gp2a = dev_get_drvdata(switch_cmd_dev); int ret=0; switch(cmd) { case SHARP_GP2AP_OPEN: { printk(KERN_INFO "[PROXIMITY] %s : case OPEN\n", __FUNCTION__); gp2a_on(gp2a,PROXIMITY); proximity_enable =1; } break; case SHARP_GP2AP_CLOSE: { printk(KERN_INFO "[PROXIMITY] %s : case CLOSE\n", __FUNCTION__); gp2a_off(gp2a,PROXIMITY); proximity_enable=0; } break; default: printk(KERN_INFO "[PROXIMITY] unknown ioctl %d\n", cmd); ret = -1; break; } return ret; }
static int light_release(struct inode *ip, struct file *fp) { struct gp2a_data *gp2a = dev_get_drvdata(switch_cmd_dev); gp2a_off(gp2a,LIGHT); gprintk("[%s] \n",__func__); return 0; }
static ssize_t lightsensor_file_cmd_store(struct device *dev, struct device_attribute *attr, const char *buf, size_t size) { struct gp2a_data *gp2a = dev_get_drvdata(dev); int value; sscanf(buf, "%d", &value); printk(KERN_INFO "[LIGHT_SENSOR] in lightsensor_file_cmd_store, input value = %d \n",value); if(value==1 && light_enable == OFF) { light_init_period = 4; gp2a_on(gp2a,LIGHT); value = ON; } else if(value==0 && light_enable ==ON) { gp2a_off(gp2a,LIGHT); value = OFF; } /* temporary test code for proximity sensor */ else if(value==3 && proximity_enable == OFF) { gp2a_on(gp2a,PROXIMITY); printk("[PROXIMITY] Temporary : Power ON\n"); } else if(value==2 && proximity_enable == ON) { gp2a_off(gp2a,PROXIMITY); printk("[PROXIMITY] Temporary : Power OFF\n"); } /* for factory simple test mode */ if(value==7 && light_enable == OFF) { light_init_period = 2; gp2a_on(gp2a,LIGHT); value = 7; } return size; }
static ssize_t gp2a_onoff_store(struct device *dev, struct device_attribute *attr, const char *buf, size_t size) { unsigned long value = simple_strtoul(buf, NULL, 10); struct gp2a_data *gp2a = dev_get_drvdata(dev); value?gp2a_on(gp2a):gp2a_off(gp2a); return size; }
static long proximity_ioctl(struct file *filp, unsigned int cmd, unsigned long arg) { struct gp2a_data *gp2a = dev_get_drvdata(switch_cmd_dev); int ret=0; switch(cmd) { case SHARP_GP2AP_OPEN: { if(!proximity_enable) { printk(KERN_INFO "[PROXIMITY] %s : case OPEN\n", __FUNCTION__); gp2a_on(gp2a,PROXIMITY); } else printk(KERN_INFO "[PROXIMITY] Warning!! Proximity is already power on\n"); } break; case SHARP_GP2AP_CLOSE: { if(proximity_enable) { printk(KERN_INFO "[PROXIMITY] %s : case CLOSE\n", __FUNCTION__); gp2a_off(gp2a,PROXIMITY); wake_lock_timeout(&prx_wake_lock,3 * HZ); } else printk(KERN_INFO "[PROXIMITY] Warning!! Proximity is already power off\n"); } break; default: printk(KERN_INFO "[PROXIMITY] unknown ioctl %d\n", cmd); ret = -1; break; } return ret; }
static ssize_t proxsensor_onoff_ctrl_store(struct device *dev, struct device_attribute *attr, char *buf, size_t size) { struct gp2a_data *gp2a = dev_get_drvdata(switch_cmd_dev); unsigned int onoff; int ret = 0; sscanf(buf,"%d\n",&onoff); printk("Set Proximity Sensor OnOff : %d\n",onoff); if(onoff == 1) { ret = gp2a_on(gp2a,PROXIMITY); if(ret == 0) proximity_enable =1; } else { ret = gp2a_off(gp2a,PROXIMITY); if(ret == 0) proximity_enable =0; } return size; }
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; }
//------------------------------------------------------------------------------------ static int gp2a_opt_probe(struct i2c_client *client, const struct i2c_device_id *id) { int err = -1; int i; u8 value; #if USE_INTERRUPT int irq; #endif int ret; struct gp2a_data *gp2a; printk("GP2A PROBE!\n"); if(!i2c_check_functionality(client->adapter, I2C_FUNC_I2C)) return err; /* 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; } i2c_set_clientdata(client, gp2a); opt_i2c_client = client; if(opt_i2c_client == NULL) { pr_err("opt_probe failed : i2c_client is NULL\n"); return -ENODEV; } else printk("opt_i2c_client : (%s)\n",opt_i2c_client->name); printk("[%s] slave addr = %x\n", __func__, client->addr); #ifdef LIGHT_SENSOR_ENABLED /* hrtimer Settings */ hrtimer_init(&gp2a->timer, CLOCK_MONOTONIC, HRTIMER_MODE_REL); gp2a->timer.function = gp2a_timer_func; gp2a_wq = create_singlethread_workqueue("gp2a_wq"); if (!gp2a_wq) { printk("create_singlethread_workqueue error \r\n"); return -ENOMEM; } INIT_WORK(&gp2a->work_light, gp2a_work_func_light); err = misc_register(&light_device); if(err) { pr_err(KERN_ERR "misc_register failed - light\n"); } /* set sysfs for light sensor */ lightsensor_class = class_create(THIS_MODULE, "lightsensor"); if (IS_ERR(lightsensor_class)) pr_err("Failed to create class(lightsensor)!\n"); switch_cmd_dev = device_create(lightsensor_class, NULL, 0, NULL, "switch_cmd"); if (IS_ERR(switch_cmd_dev)) pr_err("Failed to create device(switch_cmd_dev)!\n"); if (device_create_file(switch_cmd_dev, &dev_attr_lightsensor_file_cmd) < 0) pr_err("Failed to create device file(%s)!\n", dev_attr_lightsensor_file_cmd.attr.name); if (device_create_file(switch_cmd_dev, &dev_attr_lightsensor_file_state) < 0) pr_err("Failed to create device file(%s)!\n", dev_attr_lightsensor_file_state.attr.name); dev_set_drvdata(switch_cmd_dev,gp2a); gp2a_off(gp2a,LIGHT); #endif /* 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"; 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 */ INIT_DELAYED_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"); //#if !defined(CONFIG_MACH_RANT3) wake_lock_init(&prx_irq_wake_lock, WAKE_LOCK_SUSPEND, "prx_irq_wake_lock"); //#endif /* 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); #if defined(CONFIG_MACH_RANT3) if (device_create_file(switch_cmd_dev, &dev_attr_proxsensor_onoff_ctrl) < 0) pr_err("Failed to create device file(%s)!\n", dev_attr_proxsensor_onoff_ctrl.attr.name); #endif dev_set_drvdata(switch_cmd_dev,gp2a); /* ktime init */ timeA = ktime_set(0,0); timeB = ktime_set(0,0); /* GP2A Regs INIT SETTINGS */ value = 0x00; err = opt_i2c_write((u8)(REGS_OPMOD),&value); if(err == -EIO) // NC gp2a goto exit_kfree; /* 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_PS_VOUT); gp2a->irq = -1; set_irq_type(irq, IRQ_TYPE_EDGE_FALLING); 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 ret = gp2a_off(gp2a,ALL); #if !defined(CONFIG_MACH_RANT3) if(ret==0) proximity_enable = 0; #endif printk("gp2a_opt_probe is OK!!\n"); return 0; exit_kfree: printk("gp2a_opt_probe is exit_kfree!!\n"); kfree(gp2a); exit: return err; }
static ssize_t lightsensor_file_cmd_store(struct device *dev, struct device_attribute *attr, const char *buf, size_t size) { struct gp2a_data *gp2a = dev_get_drvdata(dev); int value; sscanf(buf, "%d", &value); int ret; printk(KERN_INFO "[LIGHT_SENSOR] in lightsensor_file_cmd_store, input value = %d, light_enable = %d \n",value, light_enable); switch(value){ // iamaj add case 8, 9 for enable light sensor without autobrightness #ifdef LIGHT_SENSOR_ENABLED case 0 : { if(light_enable == ON) { gp2a_off(gp2a,LIGHT); //Light sensor is always on } lightsensor_test = 0; value = OFF; printk(KERN_INFO "[LIGHT_SENSOR] *#0589# test end, input value = %d \n",value); break; } case 1 : { if(light_enable == OFF) { gp2a_on(gp2a,LIGHT); //Light sensor is always on } lightsensor_test = 1; value = ON; printk(KERN_INFO "[LIGHT_SENSOR] *#0589# test start, input value = %d \n",value); break; } #endif /* temporary test code for proximity sensor */ case 2 : { if(proximity_enable == ON) { ret = gp2a_off(gp2a,PROXIMITY); if(ret==0) proximity_enable =0; printk("[PROXIMITY] Temporary : Power OFF\n"); } break; } case 3 : { if(proximity_enable == OFF){ ret = gp2a_on(gp2a,PROXIMITY); if(ret==0) proximity_enable =1; printk("[PROXIMITY] Temporary : Power ON\n"); } break; } #ifdef LIGHT_SENSOR_ENABLED case 7 : { if(light_enable == OFF) { light_init_period = 2; gp2a_on(gp2a,LIGHT); value = 7; } break; } #endif default : break; } return size; }
static int gp2a_opt_probe( struct platform_device* pdev ) { struct gp2a_data *gp2a; int irq; int i; int ret; /* allocate driver_data */ gp2a = kzalloc(sizeof(struct gp2a_data),GFP_KERNEL); if(!gp2a) { pr_err("kzalloc error\n"); return -ENOMEM; } gprintk("in %s \n",__func__); /* init i2c */ opt_i2c_init(); if(opt_i2c_client == NULL) { pr_err("opt_probe failed : i2c_client is NULL\n"); return -ENODEV; } /* hrtimer Settings */ hrtimer_init(&gp2a->timer, CLOCK_MONOTONIC, HRTIMER_MODE_REL); gp2a->timer.function = gp2a_timer_func; /* 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"; 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); ret = input_register_device(gp2a->input_dev); if (ret) { pr_err("Unable to register %s input device\n", gp2a->input_dev->name); input_free_device(gp2a->input_dev); kfree(gp2a); return -1; } } /* WORK QUEUE Settings */ gp2a_wq = create_singlethread_workqueue("gp2a_wq"); if (!gp2a_wq) return -ENOMEM; INIT_WORK(&gp2a->work_prox, gp2a_work_func_prox); INIT_WORK(&gp2a->work_light, gp2a_work_func_light); gprintk("Workqueue Settings complete\n"); /* misc device Settings */ ret = misc_register(&proximity_device); if(ret) { pr_err(KERN_ERR "misc_register failed \n"); } /* wake lock init */ wake_lock_init(&prx_wake_lock, WAKE_LOCK_SUSPEND, "prx_wake_lock"); /* set platdata */ platform_set_drvdata(pdev, gp2a); /* set sysfs for light sensor */ lightsensor_class = class_create(THIS_MODULE, "lightsensor"); if (IS_ERR(lightsensor_class)) pr_err("Failed to create class(lightsensor)!\n"); switch_cmd_dev = device_create_drvdata(lightsensor_class, NULL, 0, NULL, "switch_cmd"); if (IS_ERR(switch_cmd_dev)) pr_err("Failed to create device(switch_cmd_dev)!\n"); if (device_create_file(switch_cmd_dev, &dev_attr_lightsensor_file_cmd) < 0) pr_err("Failed to create device file(%s)!\n", dev_attr_lightsensor_file_cmd.attr.name); if (device_create_file(switch_cmd_dev, &dev_attr_lightsensor_file_state) < 0) pr_err("Failed to create device file(%s)!\n", dev_attr_lightsensor_file_state.attr.name); dev_set_drvdata(switch_cmd_dev,gp2a); /* ktime init */ timeA = ktime_set(0,0); timeB = ktime_set(0,0); /* POWER On */ gpio_set_value(GPIO_LUM_PWM,GPIO_LEVEL_HIGH); mdelay(100); /* GP2A Regs INIT SETTINGS */ for(i=1;i<5;i++) { opt_i2c_write((u8)(i),&gp2a_original_image[i]); } mdelay(2); /* INT Settings */ irq = IRQ_GP2A_INT; gp2a->irq = -1; ret = request_irq(irq, gp2a_irq_handler, 0, "gp2a_int", gp2a); if (ret) { pr_err("unable to request irq %d\n", irq); return ret; } gp2a->irq = irq; gprintk("INT Settings complete\n"); /* maintain power-down mode before using sensor */ gp2a_off(gp2a,ALL); return 0; }