static void po188_report_data(int iCurVoltage) { input_report_abs(po188_driver.input_dev, ABS_MISC, iCurVoltage); input_sync(po188_driver.input_dev); //po188_driver.last_voltage = po188_driver.voltage_now; PO188_DMSG(" report light value to HAL (%d)\n", iCurVoltage); }
/* Begin: leyihua modified for Linux Kernel 3.0, begin 2011/11/26 */ static long po188_ioctl(struct file* file, unsigned int cmd, unsigned long param) /* End: leyihua modified for Linux Kernel 3.0, end 2011/11/26 */ { //PO188_DMSG("!!!!!!!!!!!!!!!!!!!!!!!!%s Entry ...\n",__FUNCTION__); int ret = 0; //int mv; static int start_flag = 0; switch (cmd) { case IOCTL_CLOSE_PO188: destroy_workqueue(po188_driver.po188_wq); break; /* begin: added by z00168965 for light sensor HAL */ case LIGHTSENSOR_IOCTL_ENABLE: /* end: added by z00168965 for light sensor HAL */ case SENSORS_GET_LUX_FIR: if(1 == param) { PO188_DMSG(" ************* active enable, close_finished_flag = 1\n"); po188_driver.status_on = true; po188_driver.vol_flag = true; if (start_flag) { mod_timer(&po188_driver.timer, jiffies + SENSOR_POLLING_JIFFIES); } else { mod_timer(&po188_driver.timer, jiffies + START_SENSOR_POLLING_JIFFIES); } } if( 0==param ) { PO188_DMSG(" ************* active disable close_finished_flag = 0\n"); del_timer(&po188_driver.timer); po188_driver.status_on = false; po188_driver.vol_flag = false; } ret = 1; break; case IOCTL_RESET_PO188: if (down_trylock(&po188_driver.run_sem)) { ret = -EBUSY; } up(&po188_driver.run_sem); break; case IOCTL_PO188_SLEEP_TIME: if (down_trylock(&po188_driver.run_sem)) { ret = -EBUSY; } if (param == 0) { up(&po188_driver.run_sem); ret = -EINVAL; } po188_driver.sleep_time = param; printk("set count=%d\n", po188_driver.sleep_time); up(&po188_driver.run_sem); break; /* begin: added by z00168965 for light sensor HAL */ case LIGHTSENSOR_IOCTL_GET_ENABLED: put_user(1, (unsigned long __user *)param); break; /* end: added by z00168965 for light sensor HAL */ default: printk("%s CMD INVALID.\n", __FUNCTION__); ret = -EINVAL; break; } start_flag = 1; return ret; }
static void po188_wait_for_event(struct work_struct *work) { static int voltage[TIMES]; static int i=0; static int j=0; //static int status=0; //static bool autodect=0; int k; int sum=0; mod_timer(&po188_driver.timer, jiffies + SENSOR_POLLING_JIFFIES); po188_get_sensor_status(); /*po188_driver.voltage_now = po188_get_fsr(po188_driver.voltage_now);*/ po188_driver.voltage_now = po188_get_pro_level(po188_driver.voltage_now); voltage[i++%TIMES]=po188_driver.voltage_now; if(j<TIMES) { j++; } if( j<TIMES ) { for(k=0;k<j;k++) { sum += voltage[k]; } po188_driver.current_voltage = sum / k; } else { for(k=0;k<TIMES;k++) { sum += voltage[k]; } po188_driver.current_voltage = sum / TIMES; } if( (po188_driver.last_voltage - po188_driver.current_voltage >= 60) || (po188_driver.current_voltage - po188_driver.last_voltage >= 60) ) { input_report_abs(po188_driver.input_dev, ABS_MISC, po188_driver.voltage_now); input_sync(po188_driver.input_dev); /*status++; if(status == TIMES) { autodect = 0; status = 0; } else { autodect = 1; }*/ po188_driver.last_voltage = po188_driver.voltage_now; PO188_DMSG(" *************inner we can report light info to HAL (%d)\n", po188_driver.voltage_now); } if( po188_driver.vol_flag == true ) { //input_report_rel(po188_driver.input_dev, REL_LIGHT, 10); //input_sync(po188_driver.input_dev); input_report_abs(po188_driver.input_dev, ABS_MISC, po188_driver.voltage_now); input_sync(po188_driver.input_dev); /* begin: z00168965 for debug temporarily */ //po188_driver.vol_flag = false; /* end: z00168965 for debug temporarily */ po188_driver.last_voltage = po188_driver.voltage_now; } //po188_driver.last_voltage = po188_driver.current_voltage; PO188_DMSG(" *************outer we can report light info to HAL (%d)\n", po188_driver.voltage_now); }
static long po188_ioctl(struct file* file, unsigned int cmd, unsigned long param) { int ret = 0; int flags = 0; void __user *argp = (void __user *)param; int iDelayTime = 0; switch (cmd) { case LIGHTSENSOR_IOCTL_ENABLE: if (copy_from_user(&flags, argp, sizeof(flags))) { ret = -EFAULT; } else { if ( 0==flags ) { PO188_DMSG("active disable pol88\n"); spin_lock(&po188_driver.s_lock); po188_driver.status_on = false; spin_unlock(&po188_driver.s_lock); cancel_work_sync(&po188_cb_work); flush_workqueue(po188_driver.po188_wq); del_timer(&po188_driver.timer); ret = k3_adc_close_channal(PO188_ADC_CHANNEL); if (ret < 0) { PO188_ERRMSG("k3_adc_close_channal error\n"); } ret = regulator_disable(gPo188Regulator); if (ret < 0) { PO188_ERRMSG("disable po188 vcc drive error"); } } else if (1 == flags) { PO188_DMSG("active enable pol88\n"); ret = regulator_enable(gPo188Regulator); if (ret < 0) { PO188_ERRMSG("enable po188 vcc drive error"); return ret;//regulator_enable error, return. } ret = k3_adc_open_channel(PO188_ADC_CHANNEL); if (ret < 0) { PO188_ERRMSG("k3_adc_open_channel error\n"); regulator_disable(gPo188Regulator); return ret; } mod_timer(&po188_driver.timer, jiffies + msecs_to_jiffies(po188_driver.delay_time)); spin_lock(&po188_driver.s_lock); po188_driver.status_on = true; spin_unlock(&po188_driver.s_lock); } } break; case LIGHTSENSOR_IOCTL_GET_ENABLED: spin_lock(&po188_driver.s_lock); flags = po188_driver.status_on; spin_unlock(&po188_driver.s_lock); if (copy_to_user(argp, &flags, sizeof(flags))) { ret = -EFAULT; } break; case LIGHTSENSOR_IOCTL_GET_DELAY: spin_lock(&po188_driver.s_lock); iDelayTime = po188_driver.delay_time; spin_unlock(&po188_driver.s_lock); if (copy_to_user(argp, &iDelayTime, sizeof(iDelayTime))) { ret = -EFAULT; } break; case LIGHTSENSOR_IOCTL_SET_DELAY: if (copy_from_user(&iDelayTime, argp, sizeof(iDelayTime))) { ret = -EFAULT; } else { spin_lock(&po188_driver.s_lock); po188_driver.delay_time = iDelayTime; spin_unlock(&po188_driver.s_lock); } break; default: PO188_ERRMSG("CMD INVALID.\n"); ret = -EINVAL; break; } return ret; }