void pwm_release(struct pwm_device *p) { mutex_lock(&device_list_mutex); if (!test_and_clear_bit(FLAG_REQUESTED, &p->flags)) { pr_debug("%s pwm device is not requested!\n", dev_name(p->dev)); goto done; } pwm_stop(p); pwm_unsynchronize(p, NULL); pwm_set_handler(p, NULL, NULL); p->label = NULL; p->pid = -1; if (p->ops->release) p->ops->release(p); done: mutex_unlock(&device_list_mutex); }
/* IOCTL interface */ static int motor_ioctl (struct inode *in, struct file *fl, unsigned int cmd, \ unsigned long arg) { int retval = 0, id; unsigned long to_end; struct cdev* p = in->i_cdev; id = cdev_to_id (p); switch (cmd) { case MOTOR_ENABLE: if ((int)arg) gpio_set_value (g_enable[id], 0 ^ polarity[id]); else gpio_set_value (g_enable[id], 1 ^ polarity[id]); break; case MOTOR_DIR: if ((int)arg) gpio_set_value (g_dir[id], 1); else gpio_set_value (g_dir[id], 0); break; case MOTOR_PWM_ON: pwm_start (pwmc[id]); break; case MOTOR_PWM_OFF: pwm_stop (pwmc[id]); break; case MOTOR_PWM_SET: //set the pwm period in ms motor_pwm_set (pwmc[id], arg); break; case MOTOR_RESET: steps[id] = 0; /* set the actual position as home */ break; case MOTOR_STEPS: steps_max[id] = arg; /* set the steps limit */ break; case MOTOR_START: if (g_step[id] == 0) { } else { if ((int)arg) retval = pwm_set_handler (pwmc[id], &irq_steps_handler, NULL); else retval = pwm_set_handler (pwmc[id], NULL, NULL); } break; case MOTOR_LOWPWR: if ((int)arg) gpio_set_value (g_lpwr[id], 1 ^ polarity[id]); else gpio_set_value (g_lpwr[id], 0 ^ polarity[id]); break; /* return steps_max-step */ case MOTOR_TO_END: to_end = steps_max[id] - steps[id]; copy_to_user(&arg, &to_end, sizeof(unsigned long)); break; default: retval = -EINVAL; } return retval; }