/* ioctl - I/O control */ static long light_dev_ioctl(struct file *file, unsigned int cmd, unsigned long arg) { struct sensor_private_data *sensor = g_sensor[SENSOR_TYPE_LIGHT]; struct i2c_client *client = sensor->client; unsigned int *argp = (unsigned int *)arg; int result = 0; switch(cmd) { case LIGHTSENSOR_IOCTL_GET_ENABLED: *argp = sensor->status_cur; break; case LIGHTSENSOR_IOCTL_ENABLE: DBG("%s:LIGHTSENSOR_IOCTL_ENABLE start\n", __func__); mutex_lock(&sensor->operation_mutex); if(*(unsigned int *)argp) { if(sensor->status_cur == SENSOR_OFF) { if ( (result = sensor->ops->active(client, SENSOR_ON, 0) ) < 0 ) { mutex_unlock(&sensor->operation_mutex); printk("%s:fail to active sensor,ret=%d\n",__func__,result); goto error; } if(!sensor->pdata->irq_enable) { PREPARE_DELAYED_WORK(&sensor->delaywork, sensor_delaywork_func); schedule_delayed_work(&sensor->delaywork, msecs_to_jiffies(sensor->pdata->poll_delay_ms)); } sensor->status_cur = SENSOR_ON; } } else { if(sensor->status_cur == SENSOR_ON) { if ( (result = sensor->ops->active(client, SENSOR_OFF, 0) ) < 0 ) { mutex_unlock(&sensor->operation_mutex); goto error; } if(!sensor->pdata->irq_enable) cancel_delayed_work_sync(&sensor->delaywork); sensor->status_cur = SENSOR_OFF; } } mutex_unlock(&sensor->operation_mutex); DBG("%s:LIGHTSENSOR_IOCTL_ENABLE OK\n", __func__); break; default: break; } error: return result; }
static int bp_resume(struct bp_private_data *bp) { bp->suspend_status = 0; PREPARE_DELAYED_WORK(&bp->wakeup_work, ap_wake_bp_work); schedule_delayed_work(&bp->wakeup_work, 0); return 0; }
static int h3_transceiver_mode(struct device *dev, int mode) { struct omap_irda_config *irda_config = dev->platform_data; irda_config->mode = mode; cancel_delayed_work(&irda_config->gpio_expa); PREPARE_DELAYED_WORK(&irda_config->gpio_expa, set_trans_mode); schedule_delayed_work(&irda_config->gpio_expa, 0); return 0; }
irqreturn_t irq_handler(int irq, void *dev_id,struct pt_regs *regs) { static int initialized=0; struct proc_hello_data *usrsp=hello_data; int *id=(int *)dev_id; if (*id!=128) { printk(KERN_INFO "interrupt id=%d irq=%d\n",*id,irq); return IRQ_HANDLED; } mb(); // INIT_DELAYED_WORK anyways calls INIT_WORK internally if (!initialized++) INIT_DELAYED_WORK(hello_data->wk, write_hello_wk); else PREPARE_DELAYED_WORK(hello_data->wk, write_hello_wk); queue_delayed_work(usrsp->proc_hello_wkq, usrsp->wk, thisDELAY); printk(KERN_ALERT "2470:10.6a: workqueue scheduled!\n"); return IRQ_HANDLED; }
/* ioctl - I/O control */ static long gsensor_dev_ioctl(struct file *file, unsigned int cmd, unsigned long arg) { struct sensor_private_data *sensor = g_sensor[SENSOR_TYPE_ACCEL]; struct i2c_client *client = sensor->client; void __user *argp = (void __user *)arg; struct sensor_axis axis = {0}; char rate; int result = 0; switch (cmd) { case GSENSOR_IOCTL_APP_SET_RATE: if (copy_from_user(&rate, argp, sizeof(rate))) { result = -EFAULT; goto error; } break; default: break; } switch (cmd) { case GSENSOR_IOCTL_START: DBG("%s:GSENSOR_IOCTL_START start,status=%d\n", __func__,sensor->status_cur); mutex_lock(&sensor->operation_mutex); if(++sensor->start_count == 1) { if(sensor->status_cur == SENSOR_OFF) { atomic_set(&(sensor->data_ready), 0); if ( (result = sensor->ops->active(client, 1, 0) ) < 0 ) { mutex_unlock(&sensor->operation_mutex); printk("%s:fail to active sensor,ret=%d\n",__func__,result); goto error; } if(sensor->pdata->irq_enable) { DBG("%s:enable irq,irq=%d\n",__func__,client->irq); enable_irq(client->irq); //enable irq } else { PREPARE_DELAYED_WORK(&sensor->delaywork, sensor_delaywork_func); schedule_delayed_work(&sensor->delaywork, msecs_to_jiffies(sensor->pdata->poll_delay_ms)); } sensor->status_cur = SENSOR_ON; } } mutex_unlock(&sensor->operation_mutex); DBG("%s:GSENSOR_IOCTL_START OK\n", __func__); break; case GSENSOR_IOCTL_CLOSE: DBG("%s:GSENSOR_IOCTL_CLOSE start,status=%d\n", __func__,sensor->status_cur); mutex_lock(&sensor->operation_mutex); if(--sensor->start_count == 0) { if(sensor->status_cur == SENSOR_ON) { atomic_set(&(sensor->data_ready), 0); if ( (result = sensor->ops->active(client, 0, 0) ) < 0 ) { mutex_unlock(&sensor->operation_mutex); goto error; } if(sensor->pdata->irq_enable) { DBG("%s:disable irq,irq=%d\n",__func__,client->irq); disable_irq_nosync(client->irq);//disable irq } else cancel_delayed_work_sync(&sensor->delaywork); sensor->status_cur = SENSOR_OFF; } DBG("%s:GSENSOR_IOCTL_CLOSE OK\n", __func__); } mutex_unlock(&sensor->operation_mutex); break; case GSENSOR_IOCTL_APP_SET_RATE: DBG("%s:GSENSOR_IOCTL_APP_SET_RATE start\n", __func__); mutex_lock(&sensor->operation_mutex); result = sensor_reset_rate(client, rate); if (result < 0){ mutex_unlock(&sensor->operation_mutex); goto error; } sensor->status_cur = SENSOR_ON; mutex_unlock(&sensor->operation_mutex); DBG("%s:GSENSOR_IOCTL_APP_SET_RATE OK\n", __func__); break; case GSENSOR_IOCTL_GETDATA: mutex_lock(&sensor->data_mutex); memcpy(&axis, &sensor->axis, sizeof(sensor->axis)); //get data from buffer mutex_unlock(&sensor->data_mutex); break; default: result = -ENOTTY; goto error; } switch (cmd) { case GSENSOR_IOCTL_GETDATA: if ( copy_to_user(argp, &axis, sizeof(axis) ) ) { printk("failed to copy sense data to user space."); result = -EFAULT; goto error; } DBG("%s:GSENSOR_IOCTL_GETDATA OK\n", __func__); break; default: break; } error: return result; }
/* ioctl - I/O control */ static long gyro_dev_ioctl(struct file *file, unsigned int cmd, unsigned long arg) { struct sensor_private_data *sensor = g_sensor[SENSOR_TYPE_GYROSCOPE]; struct i2c_client *client = sensor->client; void __user *argp = (void __user *)arg; int result = 0; char rate; switch (cmd) { case L3G4200D_IOCTL_GET_ENABLE: result = !sensor->status_cur; if (copy_to_user(argp, &result, sizeof(result))) { printk("%s:failed to copy status to user space.\n",__FUNCTION__); return -EFAULT; } DBG("%s :L3G4200D_IOCTL_GET_ENABLE,status=%d\n",__FUNCTION__,result); break; case L3G4200D_IOCTL_SET_ENABLE: DBG("%s :L3G4200D_IOCTL_SET_ENABLE,flag=%d\n",__FUNCTION__,*(unsigned int *)argp); mutex_lock(&sensor->operation_mutex); if(*(unsigned int *)argp) { if(sensor->status_cur == SENSOR_OFF) { if ( (result = sensor->ops->active(client, 1, ODR100_BW12_5) ) < 0 ) { mutex_unlock(&sensor->operation_mutex); printk("%s:fail to active sensor,ret=%d\n",__func__,result); goto error; } if(sensor->pdata->irq_enable) { DBG("%s:enable irq,irq=%d\n",__func__,client->irq); enable_irq(client->irq); //enable irq } else { PREPARE_DELAYED_WORK(&sensor->delaywork, sensor_delaywork_func); schedule_delayed_work(&sensor->delaywork, msecs_to_jiffies(sensor->pdata->poll_delay_ms)); } sensor->status_cur = SENSOR_ON; } } else { if(sensor->status_cur == SENSOR_ON) { if ( (result = sensor->ops->active(client, 0, 0) ) < 0 ) { mutex_unlock(&sensor->operation_mutex); goto error; } if(sensor->pdata->irq_enable) { DBG("%s:disable irq,irq=%d\n",__func__,client->irq); disable_irq_nosync(client->irq);//disable irq } else cancel_delayed_work_sync(&sensor->delaywork); sensor->status_cur = SENSOR_OFF; } } result = sensor->status_cur; if (copy_to_user(argp, &result, sizeof(result))) { printk("%s:failed to copy sense data to user space.\n",__FUNCTION__); return -EFAULT; } mutex_unlock(&sensor->operation_mutex); DBG("%s:L3G4200D_IOCTL_SET_ENABLE OK\n", __func__); break; case L3G4200D_IOCTL_SET_DELAY: mutex_lock(&sensor->operation_mutex); if (copy_from_user(&rate, argp, sizeof(rate))) return -EFAULT; if(sensor->status_cur == SENSOR_OFF) { if ( (result = sensor->ops->active(client, 1, rate) ) < 0 ) { mutex_unlock(&sensor->operation_mutex); printk("%s:fail to active sensor,ret=%d\n",__func__,result); goto error; } if(sensor->pdata->irq_enable) { DBG("%s:enable irq,irq=%d\n",__func__,client->irq); enable_irq(client->irq); //enable irq } else { PREPARE_DELAYED_WORK(&sensor->delaywork, sensor_delaywork_func); schedule_delayed_work(&sensor->delaywork, msecs_to_jiffies(sensor->pdata->poll_delay_ms)); } sensor->status_cur = SENSOR_ON; } mutex_unlock(&sensor->operation_mutex); DBG("%s :L3G4200D_IOCTL_SET_DELAY,rate=%d\n",__FUNCTION__,rate); break; default: printk("%s:error,cmd=0x%x\n",__func__,cmd); return -ENOTTY; } DBG("%s:line=%d,cmd=0x%x\n",__func__,__LINE__,cmd); error: return result; }
int hea_eq0_alloc(struct rhea_eq0 *eq0, struct hea_adapter *ap) { int rc; struct hea_eq_context context_eq; struct hea_process process = { 0 }; if (NULL == eq0) { rhea_error("Invalid parameters passed in"); return -EINVAL; } rhea_debug("Create EQ0 for hypervisor"); context_eq.cfg.eqe_count = 16; context_eq.cfg.coalesing2_delay = HEA_EQ_COALESING_DELAY_0; context_eq.cfg.generate_completion_events = HEA_EQ_GEN_COM_EVENT_DISABLE; context_eq.cfg.irq_type = HEA_IRQ_COALESING_2; /* make sure we create a real EQ0 */ process.lpar = 0xFF; eq0->eq = rhea_eq_create(&process, &context_eq.cfg); if (NULL == eq0->eq) { rhea_error("Was not able to allocate EQ0"); return -ENOMEM; } /* make sure that this EQ is released again */ if (0 != eq0->eq->id) { rhea_error("Was not able to get EQ0"); rhea_eq_destroy(eq0->eq); return -EPERM; } /* set base information */ eq0->q.q_begin = (unsigned char *) eq0->eq->q.va; eq0->q.qe_size = sizeof(struct hea_eqe); eq0->q.qe_count = eq0->eq->q.size / sizeof(struct hea_eqe); /* initialise rest */ heaq_init(&eq0->q); eq0->irq_workqueue = create_singlethread_workqueue("EQ0"); if (NULL == eq0->irq_workqueue) { rhea_error("Was not able to allocate workqueue"); return -ENOMEM; } /* prepare work queue */ INIT_DELAYED_WORK(&eq0->irq_work, &eq0_scan_eq); PREPARE_DELAYED_WORK(&eq0->irq_work, &eq0_scan_eq); INIT_WORK(&eq0->timer_work, &hea_eq0_timer_pport_event); PREPARE_WORK(&eq0->timer_work, &hea_eq0_timer_pport_event); /* timer */ setup_timer(&eq0->timer, hea_eq0_timer_callback, (ulong) eq0); rc = mod_timer(&eq0->timer, jiffies + msecs_to_jiffies(CONFIG_POWEREN_RHEA_TIMER_MS)); if (rc) { rhea_error("Error in mod_timer"); goto out; } rc = rhea_interrupts_setup(eq0->eq, ap->name, ap->hwirq_base, ap->hwirq_count, eq0_irq_handler, eq0); if (rc) { rhea_error("Was not able to register interupt " "handler for EQ0"); goto out; } spin_lock_init(&eq0->lock); return 0; out: if (eq0->eq) rhea_eq_destroy(eq0->eq); if (eq0->irq_workqueue) destroy_workqueue(eq0->irq_workqueue); del_timer(&eq0->timer); return rc; }