#define DT9812_NUM_SLOTS 16
-static DECLARE_MUTEX(dt9812_mutex);
+static DEFINE_MUTEX(dt9812_mutex);
static struct usb_device_id dt9812_table[] = {
{USB_DEVICE(0x0867, 0x9812)},
} comedi_dt9812_t;
typedef struct slot_dt9812 {
- struct semaphore mutex;
+ struct mutex mutex;
u32 serial;
usb_dt9812_t *usb;
comedi_dt9812_t *comedi;
{
int result = -ENODEV;
- down(&slot->mutex);
+ mutex_lock(&slot->mutex);
if (slot->usb) {
u8 reg[2] = { F020_SFR_P3, F020_SFR_P1 };
u8 value[2];
// printk("%2.2x, %2.2x -> %2.2x\n", value[0], value[1], *bits);
}
}
- up(&slot->mutex);
+ mutex_unlock(&slot->mutex);
return result;
}
{
int result = -ENODEV;
- down(&slot->mutex);
+ mutex_lock(&slot->mutex);
if (slot->usb) {
u8 reg[1];
u8 value[1];
value);
slot->usb->digital_out_shadow = bits;
}
- up(&slot->mutex);
+ mutex_unlock(&slot->mutex);
return result;
}
{
int result = -ENODEV;
- down(&slot->mutex);
+ mutex_lock(&slot->mutex);
if (slot->usb) {
*bits = slot->usb->digital_out_shadow;
result = 0;
}
- up(&slot->mutex);
+ mutex_unlock(&slot->mutex);
return result;
}
{
int result = -ENODEV;
- down(&slot->mutex);
+ mutex_lock(&slot->mutex);
if (slot->usb) {
dt9812_rmw_byte_t rmw[3];
}
}
}
- up(&slot->mutex);
+ mutex_unlock(&slot->mutex);
return result;
}
{
int result = -ENODEV;
- down(&slot->mutex);
+ mutex_lock(&slot->mutex);
if (slot->usb) {
*value = slot->usb->analog_out_shadow[channel];
result = 0;
}
- up(&slot->mutex);
+ mutex_unlock(&slot->mutex);
return result;
}
{
int result = -ENODEV;
- down(&slot->mutex);
+ mutex_lock(&slot->mutex);
if (slot->usb) {
dt9812_rmw_byte_t rmw[3];
result = dt9812_rmw_multiple_registers(slot->usb, 3, rmw);
slot->usb->analog_out_shadow[channel] = value;
}
- up(&slot->mutex);
+ mutex_unlock(&slot->mutex);
return result;
}
dev_info(&interface->dev, "USB DT9812 (%4.4x.%4.4x.%4.4x) #0x%8.8x\n",
dev->vendor, dev->product, dev->device, dev->serial);
- down(&dt9812_mutex);
+ mutex_lock(&dt9812_mutex);
{
// Find a slot for the USB device
slot_dt9812_t *first = NULL;
}
if (best) {
- down(&best->mutex);
+ mutex_lock(&best->mutex);
best->usb = dev;
dev->slot = best;
- up(&best->mutex);
+ mutex_unlock(&best->mutex);
}
}
- up(&dt9812_mutex);
+ mutex_unlock(&dt9812_mutex);
return 0;
usb_dt9812_t *dev;
int minor = interface->minor;
- down(&dt9812_mutex);
+ mutex_lock(&dt9812_mutex);
dev = usb_get_intfdata(interface);
if (dev->slot) {
- down(&dev->slot->mutex);
+ mutex_lock(&dev->slot->mutex);
dev->slot->usb = NULL;
- up(&dev->slot->mutex);
+ mutex_unlock(&dev->slot->mutex);
dev->slot = NULL;
}
usb_set_intfdata(interface, NULL);
- up(&dt9812_mutex);
+ mutex_unlock(&dt9812_mutex);
/* queue final destruction */
kref_put(&dev->kref, dt9812_delete);
{
int result = -ENODEV;
- down(&devpriv->slot->mutex);
+ mutex_lock(&devpriv->slot->mutex);
if (devpriv->slot->usb) {
// We have an attached device, fill in current range info
comedi_subdevice *s;
}
result = 0;
}
- up(&devpriv->slot->mutex);
+ mutex_unlock(&devpriv->slot->mutex);
return result;
}
printk("comedi%d: successfully attached to dt9812.\n", dev->minor);
- down(&dt9812_mutex);
+ mutex_lock(&dt9812_mutex);
// Find a slot for the comedi device
{
slot_dt9812_t *first = NULL;
best = first;
}
if (best) {
- down(&best->mutex);
+ mutex_lock(&best->mutex);
best->comedi = devpriv;
best->serial = devpriv->serial;
devpriv->slot = best;
- up(&best->mutex);
+ mutex_unlock(&best->mutex);
}
}
- up(&dt9812_mutex);
+ mutex_unlock(&dt9812_mutex);
return 0;
}
// Initialize all driver slots
for (i = 0; i < DT9812_NUM_SLOTS; i++) {
- init_MUTEX(&dt9812[i].mutex);
+ mutex_init(&dt9812[i].mutex);
dt9812[i].serial = 0;
dt9812[i].usb = NULL;
dt9812[i].comedi = NULL;
static void __exit usb_dt9812_exit(void)
{
+ int i;
+
// unregister with comedi
comedi_driver_unregister(&dt9812_comedi_driver);
/* deregister this driver with the USB subsystem */
usb_deregister(&dt9812_usb_driver);
+
+ /* destroy mutexes (for mutex debugging) */
+ for (i = 0; i < DT9812_NUM_SLOTS; i++) {
+ mutex_destroy(&dt9812[i].mutex);
+ }
}
module_init(usb_dt9812_init);
int8_t *dac_commands;
// commands
int8_t *dux_commands;
- struct semaphore sem;
+ struct mutex mutex;
} usbduxsub_t;
// The pointer to the private usb-data of the driver
// initialised before comedi can access it.
static usbduxsub_t usbduxsub[NUMUSBDUX];
-static DECLARE_MUTEX(start_stop_sem);
+static DEFINE_MUTEX(start_stop_mutex);
// Stops the data acquision
// It should be safe to call this function from any context
return -EFAULT;
}
// prevent other CPUs from submitting new commands just now
- down(&this_usbduxsub->sem);
+ mutex_lock(&this_usbduxsub->mutex);
if (!(this_usbduxsub->probed)) {
- up(&this_usbduxsub->sem);
+ mutex_unlock(&this_usbduxsub->mutex);
return -ENODEV;
}
// unlink only if the urb really has been submitted
res = usbdux_ai_stop(this_usbduxsub, this_usbduxsub->ai_cmd_running);
- up(&this_usbduxsub->sem);
+ mutex_unlock(&this_usbduxsub->mutex);
return res;
}
return -EFAULT;
}
// prevent other CPUs from submitting a command just now
- down(&this_usbduxsub->sem);
+ mutex_lock(&this_usbduxsub->mutex);
if (!(this_usbduxsub->probed)) {
- up(&this_usbduxsub->sem);
+ mutex_unlock(&this_usbduxsub->mutex);
return -ENODEV;
}
// unlink only if it is really running
res = usbdux_ao_stop(this_usbduxsub, this_usbduxsub->ao_cmd_running);
- up(&this_usbduxsub->sem);
+ mutex_unlock(&this_usbduxsub->mutex);
return res;
}
if (!this_usbduxsub) {
return -EFAULT;
}
- down(&this_usbduxsub->sem);
+ mutex_lock(&this_usbduxsub->mutex);
if (!(this_usbduxsub->probed)) {
- up(&this_usbduxsub->sem);
+ mutex_unlock(&this_usbduxsub->mutex);
return -ENODEV;
}
#ifdef NOISY_DUX_DEBUGBUG
if (trignum != 0) {
printk("comedi%d: usbdux_ai_inttrig: invalid trignum\n",
dev->minor);
- up(&this_usbduxsub->sem);
+ mutex_unlock(&this_usbduxsub->mutex);
return -EINVAL;
}
if (!(this_usbduxsub->ai_cmd_running)) {
if (ret < 0) {
printk("comedi%d: usbdux_ai_inttrig: urbSubmit: err=%d\n", dev->minor, ret);
this_usbduxsub->ai_cmd_running = 0;
- up(&this_usbduxsub->sem);
+ mutex_unlock(&this_usbduxsub->mutex);
return ret;
}
s->async->inttrig = NULL;
printk("comedi%d: ai_inttrig but acqu is already running\n",
dev->minor);
}
- up(&this_usbduxsub->sem);
+ mutex_unlock(&this_usbduxsub->mutex);
return 1;
}
return -EFAULT;
}
// block other CPUs from starting an ai_cmd
- down(&this_usbduxsub->sem);
+ mutex_lock(&this_usbduxsub->mutex);
if (!(this_usbduxsub->probed)) {
- up(&this_usbduxsub->sem);
+ mutex_unlock(&this_usbduxsub->mutex);
return -ENODEV;
}
if (this_usbduxsub->ai_cmd_running) {
printk("comedi%d: ai_cmd not possible. Another ai_cmd is running.\n", dev->minor);
- up(&this_usbduxsub->sem);
+ mutex_unlock(&this_usbduxsub->mutex);
return -EBUSY;
}
// set current channel of the running aquisition to zero
printk("size=%u\n", NUMCHANNELS);
#endif
if ((result = send_dux_commands(this_usbduxsub, SENDADCOMMANDS)) < 0) {
- up(&this_usbduxsub->sem);
+ mutex_unlock(&this_usbduxsub->mutex);
return result;
}
}
if (this_usbduxsub->ai_timer < 1) {
printk("comedi%d: usbdux: ai_cmd: timer=%d, scan_begin_arg=%d. Not properly tested by cmdtest?\n", dev->minor, this_usbduxsub->ai_timer, cmd->scan_begin_arg);
- up(&this_usbduxsub->sem);
+ mutex_unlock(&this_usbduxsub->mutex);
return -EINVAL;
}
this_usbduxsub->ai_counter = this_usbduxsub->ai_timer;
if (ret < 0) {
this_usbduxsub->ai_cmd_running = 0;
// fixme: unlink here??
- up(&this_usbduxsub->sem);
+ mutex_unlock(&this_usbduxsub->mutex);
return ret;
}
s->async->inttrig = NULL;
// wait for an internal signal
s->async->inttrig = usbdux_ai_inttrig;
}
- up(&this_usbduxsub->sem);
+ mutex_unlock(&this_usbduxsub->mutex);
return 0;
}
printk("comedi%d: ai_insn_read, insn->n=%d, insn->subdev=%d\n",
dev->minor, insn->n, insn->subdev);
#endif
- down(&this_usbduxsub->sem);
+ mutex_lock(&this_usbduxsub->mutex);
if (!(this_usbduxsub->probed)) {
- up(&this_usbduxsub->sem);
+ mutex_unlock(&this_usbduxsub->mutex);
return -ENODEV;
}
if (this_usbduxsub->ai_cmd_running) {
printk("comedi%d: ai_insn_read not possible. Async Command is running.\n", dev->minor);
- up(&this_usbduxsub->sem);
+ mutex_unlock(&this_usbduxsub->mutex);
return 0;
}
// adc commands
if ((err = send_dux_commands(this_usbduxsub, SENDSINGLEAD)) < 0) {
- up(&this_usbduxsub->sem);
+ mutex_unlock(&this_usbduxsub->mutex);
return err;
}
for (i = 0; i < insn->n; i++) {
if ((err = receive_dux_commands(this_usbduxsub,
SENDSINGLEAD)) < 0) {
- up(&this_usbduxsub->sem);
+ mutex_unlock(&this_usbduxsub->mutex);
return 0;
}
one = le16_to_cpu(this_usbduxsub->insnBuffer[1]);
}
data[i] = one;
}
- up(&this_usbduxsub->sem);
+ mutex_unlock(&this_usbduxsub->mutex);
return i;
}
if (!this_usbduxsub) {
return -EFAULT;
}
- down(&this_usbduxsub->sem);
+ mutex_lock(&this_usbduxsub->mutex);
if (!(this_usbduxsub->probed)) {
- up(&this_usbduxsub->sem);
+ mutex_unlock(&this_usbduxsub->mutex);
return -ENODEV;
}
for (i = 0; i < insn->n; i++) {
data[i] = this_usbduxsub->outBuffer[chan];
}
- up(&this_usbduxsub->sem);
+ mutex_unlock(&this_usbduxsub->mutex);
return i;
}
if (!this_usbduxsub) {
return -EFAULT;
}
- down(&this_usbduxsub->sem);
+ mutex_lock(&this_usbduxsub->mutex);
if (!(this_usbduxsub->probed)) {
- up(&this_usbduxsub->sem);
+ mutex_unlock(&this_usbduxsub->mutex);
return -ENODEV;
}
if (this_usbduxsub->ao_cmd_running) {
printk("comedi%d: ao_insn_write: ERROR: asynchronous ao_cmd is running\n", dev->minor);
- up(&this_usbduxsub->sem);
+ mutex_unlock(&this_usbduxsub->mutex);
return 0;
}
this_usbduxsub->dux_commands[4] = (chan << 6);
if ((err = send_dux_commands(this_usbduxsub,
SENDDACOMMANDS)) < 0) {
- up(&this_usbduxsub->sem);
+ mutex_unlock(&this_usbduxsub->mutex);
return err;
}
}
- up(&this_usbduxsub->sem);
+ mutex_unlock(&this_usbduxsub->mutex);
return i;
}
if (!this_usbduxsub) {
return -EFAULT;
}
- down(&this_usbduxsub->sem);
+ mutex_lock(&this_usbduxsub->mutex);
if (!(this_usbduxsub->probed)) {
- up(&this_usbduxsub->sem);
+ mutex_unlock(&this_usbduxsub->mutex);
return -ENODEV;
}
if (trignum != 0) {
if (ret < 0) {
printk("comedi%d: usbdux_ao_inttrig: submitURB: err=%d\n", dev->minor, ret);
this_usbduxsub->ao_cmd_running = 0;
- up(&this_usbduxsub->sem);
+ mutex_unlock(&this_usbduxsub->mutex);
return ret;
}
s->async->inttrig = NULL;
printk("comedi%d: ao_inttrig but acqu is already running.\n",
dev->minor);
}
- up(&this_usbduxsub->sem);
+ mutex_unlock(&this_usbduxsub->mutex);
return 1;
}
if (!this_usbduxsub) {
return -EFAULT;
}
- down(&this_usbduxsub->sem);
+ mutex_lock(&this_usbduxsub->mutex);
if (!(this_usbduxsub->probed)) {
- up(&this_usbduxsub->sem);
+ mutex_unlock(&this_usbduxsub->mutex);
return -ENODEV;
}
#ifdef NOISY_DUX_DEBUGBUG
#endif
if (this_usbduxsub->ao_timer < 1) {
printk("comedi%d: usbdux: ao_timer=%d, scan_begin_arg=%d. Not properly tested by cmdtest?\n", dev->minor, this_usbduxsub->ao_timer, cmd->scan_begin_arg);
- up(&this_usbduxsub->sem);
+ mutex_unlock(&this_usbduxsub->mutex);
return -EINVAL;
}
}
if (ret < 0) {
this_usbduxsub->ao_cmd_running = 0;
// fixme: unlink here??
- up(&this_usbduxsub->sem);
+ mutex_unlock(&this_usbduxsub->mutex);
return ret;
}
s->async->inttrig = NULL;
s->async->inttrig = usbdux_ao_inttrig;
}
- up(&this_usbduxsub->sem);
+ mutex_unlock(&this_usbduxsub->mutex);
return 0;
}
if (insn->n != 2)
return -EINVAL;
- down(&this_usbduxsub->sem);
+ mutex_lock(&this_usbduxsub->mutex);
if (!(this_usbduxsub->probed)) {
- up(&this_usbduxsub->sem);
+ mutex_unlock(&this_usbduxsub->mutex);
return -ENODEV;
}
// This command also tells the firmware to return
// the digital input lines
if ((err = send_dux_commands(this_usbduxsub, SENDDIOBITSCOMMAND)) < 0) {
- up(&this_usbduxsub->sem);
+ mutex_unlock(&this_usbduxsub->mutex);
return err;
}
if ((err = receive_dux_commands(this_usbduxsub,
SENDDIOBITSCOMMAND)) < 0) {
- up(&this_usbduxsub->sem);
+ mutex_unlock(&this_usbduxsub->mutex);
return err;
}
data[1] = le16_to_cpu(this_usbduxsub->insnBuffer[1]);
- up(&this_usbduxsub->sem);
+ mutex_unlock(&this_usbduxsub->mutex);
return 2;
}
return -EFAULT;
}
- down(&this_usbduxsub->sem);
+ mutex_lock(&this_usbduxsub->mutex);
if (!(this_usbduxsub->probed)) {
- up(&this_usbduxsub->sem);
+ mutex_unlock(&this_usbduxsub->mutex);
return -ENODEV;
}
if ((err = send_dux_commands(this_usbduxsub, READCOUNTERCOMMAND)) < 0) {
- up(&this_usbduxsub->sem);
+ mutex_unlock(&this_usbduxsub->mutex);
return err;
}
if ((err = receive_dux_commands(this_usbduxsub,
READCOUNTERCOMMAND)) < 0) {
- up(&this_usbduxsub->sem);
+ mutex_unlock(&this_usbduxsub->mutex);
return err;
}
data[0] = le16_to_cpu(this_usbduxsub->insnBuffer[chan + 1]);
- up(&this_usbduxsub->sem);
+ mutex_unlock(&this_usbduxsub->mutex);
return 1;
}
return -EFAULT;
}
- down(&this_usbduxsub->sem);
+ mutex_lock(&this_usbduxsub->mutex);
if (!(this_usbduxsub->probed)) {
- up(&this_usbduxsub->sem);
+ mutex_unlock(&this_usbduxsub->mutex);
return -ENODEV;
}
*((int16_t *) (this_usbduxsub->dux_commands + 2)) = cpu_to_le16(*data);
if ((err = send_dux_commands(this_usbduxsub, WRITECOUNTERCOMMAND)) < 0) {
- up(&this_usbduxsub->sem);
+ mutex_unlock(&this_usbduxsub->mutex);
return err;
}
- up(&this_usbduxsub->sem);
+ mutex_unlock(&this_usbduxsub->mutex);
return 1;
}
#ifdef CONFIG_COMEDI_DEBUG
printk("comedi_: usbdux_: finding a free structure for the usb-device\n");
#endif
- down(&start_stop_sem);
+ mutex_lock(&start_stop_mutex);
// look for a free place in the usbdux array
index = -1;
for (i = 0; i < NUMUSBDUX; i++) {
// no more space
if (index == -1) {
printk("Too many usbdux-devices connected.\n");
- up(&start_stop_sem);
+ mutex_unlock(&start_stop_mutex);
return PROBE_ERR_RETURN(-EMFILE);
}
#ifdef CONFIG_COMEDI_DEBUG
printk("comedi_: usbdux: usbduxsub[%d] is ready to connect to comedi.\n", index);
#endif
- init_MUTEX(&(usbduxsub[index].sem));
+ mutex_init(&(usbduxsub[index].mutex));
// save a pointer to the usb device
usbduxsub[index].usbdev = udev;
if (!usbduxsub[index].dac_commands) {
printk("comedi_: usbdux: error alloc space for dac commands\n");
tidy_up(&(usbduxsub[index]));
- up(&start_stop_sem);
+ mutex_unlock(&start_stop_mutex);
return PROBE_ERR_RETURN(-ENOMEM);
}
// create space for the commands going to the usb device
if (!usbduxsub[index].dux_commands) {
printk("comedi_: usbdux: error alloc space for dac commands\n");
tidy_up(&(usbduxsub[index]));
- up(&start_stop_sem);
+ mutex_unlock(&start_stop_mutex);
return PROBE_ERR_RETURN(-ENOMEM);
}
// create space for the in buffer and set it to zero
if (!(usbduxsub[index].inBuffer)) {
printk("comedi_: usbdux: could not alloc space for inBuffer\n");
tidy_up(&(usbduxsub[index]));
- up(&start_stop_sem);
+ mutex_unlock(&start_stop_mutex);
return PROBE_ERR_RETURN(-ENOMEM);
}
// create space of the instruction buffer
if (!(usbduxsub[index].insnBuffer)) {
printk("comedi_: usbdux: could not alloc space for insnBuffer\n");
tidy_up(&(usbduxsub[index]));
- up(&start_stop_sem);
+ mutex_unlock(&start_stop_mutex);
return PROBE_ERR_RETURN(-ENOMEM);
}
// create space for the outbuffer
if (!(usbduxsub[index].outBuffer)) {
printk("comedi_: usbdux: could not alloc space for outBuffer\n");
tidy_up(&(usbduxsub[index]));
- up(&start_stop_sem);
+ mutex_unlock(&start_stop_mutex);
return PROBE_ERR_RETURN(-ENOMEM);
}
// setting to alternate setting 3: enabling iso ep and bulk ep.
if (i < 0) {
printk("comedi_: usbdux%d: could not set alternate setting 3 in high speed.\n", index);
tidy_up(&(usbduxsub[index]));
- up(&start_stop_sem);
+ mutex_unlock(&start_stop_mutex);
return PROBE_ERR_RETURN(-ENODEV);
}
if (usbduxsub[index].high_speed) {
if (!(usbduxsub[index].urbIn)) {
printk("comedi_: usbdux: Could not alloc. urbIn array\n");
tidy_up(&(usbduxsub[index]));
- up(&start_stop_sem);
+ mutex_unlock(&start_stop_mutex);
return PROBE_ERR_RETURN(-ENOMEM);
}
for (i = 0; i < usbduxsub[index].numOfInBuffers; i++) {
printk("comedi_: usbdux%d: Could not alloc. urb(%d)\n",
index, i);
tidy_up(&(usbduxsub[index]));
- up(&start_stop_sem);
+ mutex_unlock(&start_stop_mutex);
return PROBE_ERR_RETURN(-ENOMEM);
}
usbduxsub[index].urbIn[i]->dev = usbduxsub[index].usbdev;
printk("comedi_: usbdux%d: could not alloc. transb.\n",
index);
tidy_up(&(usbduxsub[index]));
- up(&start_stop_sem);
+ mutex_unlock(&start_stop_mutex);
return PROBE_ERR_RETURN(-ENOMEM);
}
usbduxsub[index].urbIn[i]->complete = usbduxsub_ai_IsocIrq;
if (!(usbduxsub[index].urbOut)) {
printk("comedi_: usbdux: Could not alloc. urbOut array\n");
tidy_up(&(usbduxsub[index]));
- up(&start_stop_sem);
+ mutex_unlock(&start_stop_mutex);
return PROBE_ERR_RETURN(-ENOMEM);
}
for (i = 0; i < usbduxsub[index].numOfOutBuffers; i++) {
printk("comedi_: usbdux%d: Could not alloc. urb(%d)\n",
index, i);
tidy_up(&(usbduxsub[index]));
- up(&start_stop_sem);
+ mutex_unlock(&start_stop_mutex);
return PROBE_ERR_RETURN(-ENOMEM);
}
usbduxsub[index].urbOut[i]->dev = usbduxsub[index].usbdev;
printk("comedi_: usbdux%d: could not alloc. transb.\n",
index);
tidy_up(&(usbduxsub[index]));
- up(&start_stop_sem);
+ mutex_unlock(&start_stop_mutex);
return PROBE_ERR_RETURN(-ENOMEM);
}
usbduxsub[index].urbOut[i]->complete = usbduxsub_ao_IsocIrq;
printk("comedi_: usbdux%d: Could not alloc. pwm urb\n",
index);
tidy_up(&(usbduxsub[index]));
- up(&start_stop_sem);
+ mutex_unlock(&start_stop_mutex);
return PROBE_ERR_RETURN(-ENOMEM);
}
usbduxsub[index].urbPwm->transfer_buffer =
if (!(usbduxsub[index].urbPwm->transfer_buffer)) {
printk("comedi_: usbdux%d: could not alloc. transb. for pwm\n", index);
tidy_up(&(usbduxsub[index]));
- up(&start_stop_sem);
+ mutex_unlock(&start_stop_mutex);
return PROBE_ERR_RETURN(-ENOMEM);
}
} else {
// we've reached the bottom of the function
usbduxsub[index].probed = 1;
- up(&start_stop_sem);
+ mutex_unlock(&start_stop_mutex);
ret = request_firmware_nowait(THIS_MODULE,
FW_ACTION_HOTPLUG,
return;
}
comedi_usb_auto_unconfig(udev);
- down(&start_stop_sem);
- down(&usbduxsub_tmp->sem);
+ mutex_lock(&start_stop_mutex);
+ mutex_lock(&usbduxsub_tmp->mutex);
tidy_up(usbduxsub_tmp);
- up(&usbduxsub_tmp->sem);
- up(&start_stop_sem);
+ mutex_unlock(&usbduxsub_tmp->mutex);
+ mutex_unlock(&start_stop_mutex);
#ifdef CONFIG_COMEDI_DEBUG
printk("comedi_: usbdux: disconnected from the usb\n");
#endif
comedi_subdevice *s = NULL;
dev->private = NULL;
- down(&start_stop_sem);
+ mutex_lock(&start_stop_mutex);
// find a valid device which has been detected by the probe function of the usb
index = -1;
for (i = 0; i < NUMUSBDUX; i++) {
if (index < 0) {
printk("comedi%d: usbdux: error: attach failed, no usbdux devs connected to the usb bus.\n", dev->minor);
- up(&start_stop_sem);
+ mutex_unlock(&start_stop_mutex);
return -ENODEV;
}
- down(&(usbduxsub[index].sem));
+ mutex_lock(&(usbduxsub[index].mutex));
// pointer back to the corresponding comedi device
usbduxsub[index].comedidev = dev;
if ((ret = alloc_subdevices(dev, dev->n_subdevices)) < 0) {
printk("comedi%d: usbdux: error alloc space for subdev\n",
dev->minor);
- up(&start_stop_sem);
+ mutex_unlock(&start_stop_mutex);
return ret;
}
// finally decide that it's attached
usbduxsub[index].attached = 1;
- up(&(usbduxsub[index].sem));
+ mutex_unlock(&(usbduxsub[index].mutex));
- up(&start_stop_sem);
+ mutex_unlock(&start_stop_mutex);
printk("comedi%d: attached to usbdux.\n", dev->minor);
return -EFAULT;
}
- down(&usbduxsub_tmp->sem);
+ mutex_lock(&usbduxsub_tmp->mutex);
// Don't allow detach to free the private structure
// It's one entry of of usbduxsub[]
dev->private = NULL;
#ifdef CONFIG_COMEDI_DEBUG
printk("comedi%d: usbdux: detach: successfully removed\n", dev->minor);
#endif
- up(&usbduxsub_tmp->sem);
+ mutex_unlock(&usbduxsub_tmp->mutex);
return 0;
}
// and then finally by the attach-function
for (index = 0; index < NUMUSBDUX; index++) {
memset(&(usbduxsub[index]), 0x00, sizeof(usbduxsub[index]));
- init_MUTEX(&(usbduxsub[index].sem));
+ mutex_init(&(usbduxsub[index].mutex));
+ }
+}
+
+static void uninit_usb_devices(void)
+{
+ int index;
+
+ for (index = 0; index < NUMUSBDUX; index++) {
+ mutex_destroy(&(usbduxsub[index].mutex));
}
}
{
comedi_driver_unregister(&driver_usbdux);
usb_deregister(&usbduxsub_driver);
+ uninit_usb_devices();
}
module_init(init_usbdux);
uint8_t *dux_commands;
// counter which ignores the first buffers
int ignore;
- struct semaphore sem;
+ struct mutex mutex;
} usbduxfastsub_t;
// The pointer to the private usb-data of the driver
// initialised before comedi can access it.
static usbduxfastsub_t usbduxfastsub[NUMUSBDUXFAST];
-static DECLARE_MUTEX(start_stop_sem);
+static DEFINE_MUTEX(start_stop_mutex);
// bulk transfers to usbduxfast
printk("comedi: usbduxfast_ai_cancel: this_usbduxfastsub=NULL\n");
return -EFAULT;
}
- down(&this_usbduxfastsub->sem);
+ mutex_lock(&this_usbduxfastsub->mutex);
if (!(this_usbduxfastsub->probed)) {
- up(&this_usbduxfastsub->sem);
+ mutex_unlock(&this_usbduxfastsub->mutex);
return -ENODEV;
}
// unlink
res = usbduxfast_ai_stop(this_usbduxfastsub, 1);
- up(&this_usbduxfastsub->sem);
+ mutex_unlock(&this_usbduxfastsub->mutex);
return res;
}
if (!this_usbduxfastsub) {
return -EFAULT;
}
- down(&this_usbduxfastsub->sem);
+ mutex_lock(&this_usbduxfastsub->mutex);
if (!(this_usbduxfastsub->probed)) {
- up(&this_usbduxfastsub->sem);
+ mutex_unlock(&this_usbduxfastsub->mutex);
return -ENODEV;
}
#ifdef CONFIG_COMEDI_DEBUG
if (trignum != 0) {
printk("comedi%d: usbduxfast_ai_inttrig: invalid trignum\n",
dev->minor);
- up(&this_usbduxfastsub->sem);
+ mutex_unlock(&this_usbduxfastsub->mutex);
return -EINVAL;
}
if (!(this_usbduxfastsub->ai_cmd_running)) {
if (ret < 0) {
printk("comedi%d: usbduxfast_ai_inttrig: urbSubmit: err=%d\n", dev->minor, ret);
this_usbduxfastsub->ai_cmd_running = 0;
- up(&this_usbduxfastsub->sem);
+ mutex_unlock(&this_usbduxfastsub->mutex);
return ret;
}
s->async->inttrig = NULL;
printk("comedi%d: ai_inttrig but acqu is already running\n",
dev->minor);
}
- up(&this_usbduxfastsub->sem);
+ mutex_unlock(&this_usbduxfastsub->mutex);
return 1;
}
if (!this_usbduxfastsub) {
return -EFAULT;
}
- down(&this_usbduxfastsub->sem);
+ mutex_lock(&this_usbduxfastsub->mutex);
if (!(this_usbduxfastsub->probed)) {
- up(&this_usbduxfastsub->sem);
+ mutex_unlock(&this_usbduxfastsub->mutex);
return -ENODEV;
}
if (this_usbduxfastsub->ai_cmd_running) {
printk("comedi%d: ai_cmd not possible. Another ai_cmd is running.\n", dev->minor);
- up(&this_usbduxfastsub->sem);
+ mutex_unlock(&this_usbduxfastsub->mutex);
return -EBUSY;
}
// set current channel of the running aquisition to zero
chan = CR_CHAN(cmd->chanlist[i]);
if (chan != i) {
printk("comedi%d: cmd is accepting only consecutive channels.\n", dev->minor);
- up(&this_usbduxfastsub->sem);
+ mutex_unlock(&this_usbduxfastsub->mutex);
return -EINVAL;
}
if ((gain != CR_RANGE(cmd->chanlist[i]))
&& (cmd->chanlist_len > 3)) {
printk("comedi%d: the gain must be the same for all channels.\n", dev->minor);
- up(&this_usbduxfastsub->sem);
+ mutex_unlock(&this_usbduxfastsub->mutex);
return -EINVAL;
}
if (i >= NUMCHANNELS) {
steps = 0;
if (cmd->scan_begin_src == TRIG_TIMER) {
printk("comedi%d: usbduxfast: scan_begin_src==TRIG_TIMER not valid.\n", dev->minor);
- up(&this_usbduxfastsub->sem);
+ mutex_unlock(&this_usbduxfastsub->mutex);
return -EINVAL;
}
if (cmd->convert_src == TRIG_TIMER) {
}
if ((steps < MIN_SAMPLING_PERIOD) && (cmd->chanlist_len != 1)) {
printk("comedi%d: usbduxfast: ai_cmd: steps=%ld, scan_begin_arg=%d. Not properly tested by cmdtest?\n", dev->minor, steps, cmd->scan_begin_arg);
- up(&this_usbduxfastsub->sem);
+ mutex_unlock(&this_usbduxfastsub->mutex);
return -EINVAL;
}
if (steps > MAX_SAMPLING_PERIOD) {
printk("comedi%d: usbduxfast: ai_cmd: sampling rate too low.\n",
dev->minor);
- up(&this_usbduxfastsub->sem);
+ mutex_unlock(&this_usbduxfastsub->mutex);
return -EINVAL;
}
if ((cmd->start_src == TRIG_EXT) && (cmd->chanlist_len != 1)
&& (cmd->chanlist_len != 16)) {
printk("comedi%d: usbduxfast: ai_cmd: TRIG_EXT only with 1 or 16 channels possible.\n", dev->minor);
- up(&this_usbduxfastsub->sem);
+ mutex_unlock(&this_usbduxfastsub->mutex);
return -EINVAL;
}
#ifdef CONFIG_COMEDI_DEBUG
default:
printk("comedi %d: unsupported combination of channels\n",
dev->minor);
- up(&this_usbduxfastsub->sem);
+ mutex_unlock(&this_usbduxfastsub->mutex);
return -EFAULT;
}
result = send_dux_commands(this_usbduxfastsub, SENDADCOMMANDS);
if (result < 0) {
printk("comedi%d: adc command could not be submitted. Aborting...\n", dev->minor);
- up(&this_usbduxfastsub->sem);
+ mutex_unlock(&this_usbduxfastsub->mutex);
return result;
}
if (cmd->stop_src == TRIG_COUNT) {
(cmd->stop_arg) * (cmd->scan_end_arg);
if (usbduxfastsub->ai_sample_count < 1) {
printk("comedi%d: (cmd->stop_arg)*(cmd->scan_end_arg)<1, aborting.\n", dev->minor);
- up(&this_usbduxfastsub->sem);
+ mutex_unlock(&this_usbduxfastsub->mutex);
return -EFAULT;
}
this_usbduxfastsub->ai_continous = 0;
if (ret < 0) {
this_usbduxfastsub->ai_cmd_running = 0;
// fixme: unlink here??
- up(&this_usbduxfastsub->sem);
+ mutex_unlock(&this_usbduxfastsub->mutex);
return ret;
}
s->async->inttrig = NULL;
// wait for an internal signal
s->async->inttrig = usbduxfast_ai_inttrig;
}
- up(&this_usbduxfastsub->sem);
+ mutex_unlock(&this_usbduxfastsub->mutex);
return 0;
}
printk("comedi%d: ai_insn_read, insn->n=%d, insn->subdev=%d\n",
dev->minor, insn->n, insn->subdev);
#endif
- down(&usbduxfastsub->sem);
+ mutex_lock(&usbduxfastsub->mutex);
if (!(usbduxfastsub->probed)) {
- up(&usbduxfastsub->sem);
+ mutex_unlock(&usbduxfastsub->mutex);
return -ENODEV;
}
if (usbduxfastsub->ai_cmd_running) {
printk("comedi%d: ai_insn_read not possible. Async Command is running.\n", dev->minor);
- up(&usbduxfastsub->sem);
+ mutex_unlock(&usbduxfastsub->mutex);
return -EBUSY;
}
// sample one channel
err = send_dux_commands(usbduxfastsub, SENDADCOMMANDS);
if (err < 0) {
printk("comedi%d: adc command could not be submitted. Aborting...\n", dev->minor);
- up(&usbduxfastsub->sem);
+ mutex_unlock(&usbduxfastsub->mutex);
return err;
}
#ifdef CONFIG_COMEDI_DEBUG
if (err < 0) {
printk("comedi%d: insn timeout. No data.\n",
dev->minor);
- up(&usbduxfastsub->sem);
+ mutex_unlock(&usbduxfastsub->mutex);
return err;
}
}
if (err < 0) {
printk("comedi%d: insn data error: %d\n",
dev->minor, err);
- up(&usbduxfastsub->sem);
+ mutex_unlock(&usbduxfastsub->mutex);
return err;
}
n = actual_length / sizeof(uint16_t);
if ((n % 16) != 0) {
printk("comedi%d: insn data packet corrupted.\n",
dev->minor);
- up(&usbduxfastsub->sem);
+ mutex_unlock(&usbduxfastsub->mutex);
return -EINVAL;
}
for (j = chan; (j < n) && (i < insn->n); j = j + 16) {
i++;
}
}
- up(&usbduxfastsub->sem);
+ mutex_unlock(&usbduxfastsub->mutex);
return i;
}
#ifdef CONFIG_COMEDI_DEBUG
printk("comedi_: usbduxfast_: finding a free structure for the usb-device\n");
#endif
- down(&start_stop_sem);
+ mutex_lock(&start_stop_mutex);
// look for a free place in the usbduxfast array
index = -1;
for (i = 0; i < NUMUSBDUXFAST; i++) {
// no more space
if (index == -1) {
printk("Too many usbduxfast-devices connected.\n");
- up(&start_stop_sem);
+ mutex_unlock(&start_stop_mutex);
return PROBE_ERR_RETURN(-EMFILE);
}
#ifdef CONFIG_COMEDI_DEBUG
printk("comedi_: usbduxfast: usbduxfastsub[%d] is ready to connect to comedi.\n", index);
#endif
- init_MUTEX(&(usbduxfastsub[index].sem));
+ mutex_init(&(usbduxfastsub[index].mutex));
// save a pointer to the usb device
usbduxfastsub[index].usbdev = udev;
if (!usbduxfastsub[index].dux_commands) {
printk("comedi_: usbduxfast: error alloc space for dac commands\n");
tidy_up(&(usbduxfastsub[index]));
- up(&start_stop_sem);
+ mutex_unlock(&start_stop_mutex);
return PROBE_ERR_RETURN(-ENOMEM);
}
// create space of the instruction buffer
if (!(usbduxfastsub[index].insnBuffer)) {
printk("comedi_: usbduxfast: could not alloc space for insnBuffer\n");
tidy_up(&(usbduxfastsub[index]));
- up(&start_stop_sem);
+ mutex_unlock(&start_stop_mutex);
return PROBE_ERR_RETURN(-ENOMEM);
}
// setting to alternate setting 1: enabling bulk ep
if (i < 0) {
printk("comedi_: usbduxfast%d: could not switch to alternate setting 1.\n", index);
tidy_up(&(usbduxfastsub[index]));
- up(&start_stop_sem);
+ mutex_unlock(&start_stop_mutex);
return PROBE_ERR_RETURN(-ENODEV);
}
usbduxfastsub[index].urbIn = USB_ALLOC_URB(0);
if (usbduxfastsub[index].urbIn == NULL) {
printk("comedi_: usbduxfast%d: Could not alloc. urb\n", index);
tidy_up(&(usbduxfastsub[index]));
- up(&start_stop_sem);
+ mutex_unlock(&start_stop_mutex);
return PROBE_ERR_RETURN(-ENOMEM);
}
usbduxfastsub[index].transfer_buffer = kmalloc(SIZEINBUF, GFP_KERNEL);
printk("comedi_: usbduxfast%d: could not alloc. transb.\n",
index);
tidy_up(&(usbduxfastsub[index]));
- up(&start_stop_sem);
+ mutex_unlock(&start_stop_mutex);
return PROBE_ERR_RETURN(-ENOMEM);
}
// we've reached the bottom of the function
usbduxfastsub[index].probed = 1;
- up(&start_stop_sem);
+ mutex_unlock(&start_stop_mutex);
ret = request_firmware_nowait(THIS_MODULE,
FW_ACTION_HOTPLUG,
comedi_usb_auto_unconfig(udev);
- down(&start_stop_sem);
- down(&usbduxfastsub_tmp->sem);
+ mutex_lock(&start_stop_mutex);
+ mutex_lock(&usbduxfastsub_tmp->mutex);
tidy_up(usbduxfastsub_tmp);
- up(&usbduxfastsub_tmp->sem);
- up(&start_stop_sem);
+ mutex_unlock(&usbduxfastsub_tmp->mutex);
+ mutex_unlock(&start_stop_mutex);
#ifdef CONFIG_COMEDI_DEBUG
printk("comedi_: usbduxfast: disconnected from the usb\n");
#endif
comedi_subdevice *s = NULL;
dev->private = NULL;
- down(&start_stop_sem);
+ mutex_lock(&start_stop_mutex);
// find a valid device which has been detected by the probe function of the usb
index = -1;
for (i = 0; i < NUMUSBDUXFAST; i++) {
if (index < 0) {
printk("comedi%d: usbduxfast: error: attach failed, no usbduxfast devs connected to the usb bus.\n", dev->minor);
- up(&start_stop_sem);
+ mutex_unlock(&start_stop_mutex);
return -ENODEV;
}
- down(&(usbduxfastsub[index].sem));
+ mutex_lock(&(usbduxfastsub[index].mutex));
// pointer back to the corresponding comedi device
usbduxfastsub[index].comedidev = dev;
if ((ret = alloc_subdevices(dev, N_SUBDEVICES)) < 0) {
printk("comedi%d: usbduxfast: error alloc space for subdev\n",
dev->minor);
- up(&start_stop_sem);
+ mutex_unlock(&start_stop_mutex);
return ret;
}
// finally decide that it's attached
usbduxfastsub[index].attached = 1;
- up(&(usbduxfastsub[index].sem));
+ mutex_unlock(&(usbduxfastsub[index].mutex));
- up(&start_stop_sem);
+ mutex_unlock(&start_stop_mutex);
printk("comedi%d: successfully attached to usbduxfast.\n", dev->minor);
return -EFAULT;
}
- down(&usbduxfastsub_tmp->sem);
- down(&start_stop_sem);
+ mutex_lock(&usbduxfastsub_tmp->mutex);
+ mutex_lock(&start_stop_mutex);
// Don't allow detach to free the private structure
// It's one entry of of usbduxfastsub[]
dev->private = NULL;
printk("comedi%d: usbduxfast: detach: successfully removed\n",
dev->minor);
#endif
- up(&start_stop_sem);
- up(&usbduxfastsub_tmp->sem);
+ mutex_unlock(&start_stop_mutex);
+ mutex_unlock(&usbduxfastsub_tmp->mutex);
return 0;
}
for (index = 0; index < NUMUSBDUXFAST; index++) {
memset(&(usbduxfastsub[index]), 0x00,
sizeof(usbduxfastsub[index]));
- init_MUTEX(&(usbduxfastsub[index].sem));
+ mutex_init(&(usbduxfastsub[index].mutex));
+ }
+}
+
+static void uninit_usb_devices(void)
+{
+ int index;
+
+ for (index = 0; index < NUMUSBDUXFAST; index++) {
+ mutex_destroy(&(usbduxfastsub[index].mutex));
}
}
{
comedi_driver_unregister(&driver_usbduxfast);
usb_deregister(&usbduxfastsub_driver);
+ uninit_usb_devices();
}
module_init(init_usbduxfast);