Commit 4e8ad0dc authored by Mariusz Kozlowski's avatar Mariusz Kozlowski Committed by Greg Kroah-Hartman

Staging: comedi: usbduxfast: fix checkpatch issues plus some style cleanups etc.

This patch is a major code rewrite to make checkpatch.pl happy and also
other minor things are fixed.
Signed-off-by: default avatarMariusz Kozlowski <m.kozlowski@tuxland.pl>
Cc: Bernd Porr <BerndPorr@f2s.com>
Cc: David Schleef <ds@schleef.org>
Cc: Frank Mori Hess <fmhess@users.sourceforge.net>
Cc: Ian Abbott <abbotti@mev.co.uk>
Signed-off-by: default avatarGreg Kroah-Hartman <gregkh@suse.de>
parent 0a3b8b64
#define DRIVER_VERSION "v0.99a"
#define DRIVER_AUTHOR "Bernd Porr, BerndPorr@f2s.com"
#define DRIVER_DESC "USB-DUXfast, BerndPorr@f2s.com"
/* /*
comedi/drivers/usbduxfast.c * Copyright (C) 2004 Bernd Porr, Bernd.Porr@f2s.com
Copyright (C) 2004 Bernd Porr, Bernd.Porr@f2s.com *
* This program is free software; you can redistribute it and/or modify
This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by
it under the terms of the GNU General Public License as published by * the Free Software Foundation; either version 2 of the License, or
the Free Software Foundation; either version 2 of the License, or * (at your option) any later version.
(at your option) any later version. *
* This program is distributed in the hope that it will be useful,
This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of
but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details.
GNU General Public License for more details. *
* You should have received a copy of the GNU General Public License
You should have received a copy of the GNU General Public License * along with this program; if not, write to the Free Software
along with this program; if not, write to the Free Software * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. */
*/
/*
Driver: usbduxfast
Description: ITL USB-DUXfast
Devices: [ITL] USB-DUX (usbduxfast.o)
Author: Bernd Porr <BerndPorr@f2s.com>
Updated: 04 Dec 2006
Status: testing
*/
/* /*
* I must give credit here to Chris Baugher who * I must give credit here to Chris Baugher who
...@@ -42,7 +29,8 @@ Status: testing ...@@ -42,7 +29,8 @@ Status: testing
* 0.9: Dropping the first data packet which seems to be from the last transfer. * 0.9: Dropping the first data packet which seems to be from the last transfer.
* Buffer overflows in the FX2 are handed over to comedi. * Buffer overflows in the FX2 are handed over to comedi.
* 0.92: Dropping now 4 packets. The quad buffer has to be emptied. * 0.92: Dropping now 4 packets. The quad buffer has to be emptied.
* Added insn command basically for testing. Sample rate is 1MHz/16ch=62.5kHz * Added insn command basically for testing. Sample rate is
* 1MHz/16ch=62.5kHz
* 0.99: Ian Abbott pointed out a bug which has been corrected. Thanks! * 0.99: Ian Abbott pointed out a bug which has been corrected. Thanks!
* 0.99a: added external trigger. * 0.99a: added external trigger.
*/ */
...@@ -59,522 +47,560 @@ Status: testing ...@@ -59,522 +47,560 @@ Status: testing
#include "comedi_fc.h" #include "comedi_fc.h"
#include "../comedidev.h" #include "../comedidev.h"
#define DRIVER_VERSION "v0.99a"
#define DRIVER_AUTHOR "Bernd Porr, BerndPorr@f2s.com"
#define DRIVER_DESC "USB-DUXfast, BerndPorr@f2s.com"
#define BOARDNAME "usbduxfast" #define BOARDNAME "usbduxfast"
// timeout for the USB-transfer /*
#define EZTIMEOUT 30 * timeout for the USB-transfer
*/
#define EZTIMEOUT 30
// constants for "firmware" upload and download /*
#define USBDUXFASTSUB_FIRMWARE 0xA0 * constants for "firmware" upload and download
#define VENDOR_DIR_IN 0xC0 */
#define VENDOR_DIR_OUT 0x40 #define USBDUXFASTSUB_FIRMWARE 0xA0
#define VENDOR_DIR_IN 0xC0
#define VENDOR_DIR_OUT 0x40
// internal adresses of the 8051 processor /*
#define USBDUXFASTSUB_CPUCS 0xE600 * internal adresses of the 8051 processor
*/
#define USBDUXFASTSUB_CPUCS 0xE600
// max lenghth of the transfer-buffer for software upload /*
#define TB_LEN 0x2000 * max lenghth of the transfer-buffer for software upload
*/
#define TB_LEN 0x2000
// Input endpoint number /*
#define BULKINEP 6 * input endpoint number
*/
#define BULKINEP 6
// Endpoint for the A/D channellist: bulk OUT /*
#define CHANNELLISTEP 4 * endpoint for the A/D channellist: bulk OUT
*/
#define CHANNELLISTEP 4
// Number of channels /*
#define NUMCHANNELS 32 * number of channels
*/
#define NUMCHANNELS 32
// size of the waveform descriptor /*
#define WAVESIZE 0x20 * size of the waveform descriptor
*/
#define WAVESIZE 0x20
// Size of one A/D value /*
#define SIZEADIN ((sizeof(int16_t))) * size of one A/D value
*/
#define SIZEADIN (sizeof(int16_t))
// Size of the input-buffer IN BYTES /*
#define SIZEINBUF 512 * size of the input-buffer IN BYTES
*/
#define SIZEINBUF 512
// 16 bytes. /*
#define SIZEINSNBUF 512 * 16 bytes
*/
#define SIZEINSNBUF 512
// Size of the buffer for the dux commands /*
#define SIZEOFDUXBUFFER 256 // bytes * size of the buffer for the dux commands in bytes
*/
#define SIZEOFDUXBUFFER 256
// Number of in-URBs which receive the data: min=5 /*
#define NUMOFINBUFFERSHIGH 10 * number of in-URBs which receive the data: min=5
*/
#define NUMOFINBUFFERSHIGH 10
// Total number of usbduxfast devices /*
#define NUMUSBDUXFAST 16 * total number of usbduxfast devices
*/
#define NUMUSBDUXFAST 16
// Number of subdevices /*
#define N_SUBDEVICES 1 * number of subdevices
*/
#define N_SUBDEVICES 1
// Analogue in subdevice /*
#define SUBDEV_AD 0 * analogue in subdevice
*/
#define SUBDEV_AD 0
// min delay steps for more than one channel /*
// basically when the mux gives up. ;-) * min delay steps for more than one channel
#define MIN_SAMPLING_PERIOD 9 // steps at 30MHz in the FX2 * basically when the mux gives up ;-)
*
* steps at 30MHz in the FX2
*/
#define MIN_SAMPLING_PERIOD 9
// Max number of 1/30MHz delay steps: /*
#define MAX_SAMPLING_PERIOD 500 * max number of 1/30MHz delay steps
*/
#define MAX_SAMPLING_PERIOD 500
// Number of received packets to ignore before we start handing data over to comedi. /*
// It's quad buffering and we have to ignore 4 packets. * number of received packets to ignore before we start handing data
#define PACKETS_TO_IGNORE 4 * over to comedi, it's quad buffering and we have to ignore 4 packets
*/
#define PACKETS_TO_IGNORE 4
///////////////////////////////////////////// /*
// comedi constants * comedi constants
static const comedi_lrange range_usbduxfast_ai_range = { 2, { */
BIP_RANGE(0.75), static const comedi_lrange range_usbduxfast_ai_range = {
BIP_RANGE(0.5), 2, { BIP_RANGE(0.75), BIP_RANGE(0.5) }
}
}; };
/* /*
* private structure of one subdevice * private structure of one subdevice
*
* this is the structure which holds all the data of this driver
* one sub device just now: A/D
*/ */
struct usbduxfastsub_s {
// This is the structure which holds all the data of this driver int attached; /* is attached? */
// one sub device just now: A/D int probed; /* is it associated with a subdevice? */
typedef struct { struct usb_device *usbdev; /* pointer to the usb-device */
// attached? struct urb *urbIn; /* BULK-transfer handling: urb */
int attached;
// is it associated with a subdevice?
int probed;
// pointer to the usb-device
struct usb_device *usbdev;
// BULK-transfer handling: urb
struct urb *urbIn;
int8_t *transfer_buffer; int8_t *transfer_buffer;
// input buffer for single insn int16_t *insnBuffer; /* input buffer for single insn */
int16_t *insnBuffer; int ifnum; /* interface number */
// interface number struct usb_interface *interface; /* interface structure */
int ifnum; comedi_device *comedidev; /* comedi device for the interrupt
// interface structure context */
struct usb_interface *interface; short int ai_cmd_running; /* asynchronous command is running */
// comedi device for the interrupt context short int ai_continous; /* continous aquisition */
comedi_device *comedidev; long int ai_sample_count; /* number of samples to aquire */
// asynchronous command is running uint8_t *dux_commands; /* commands */
short int ai_cmd_running; int ignore; /* counter which ignores the first
// continous aquisition buffers */
short int ai_continous;
// number of samples to aquire
long int ai_sample_count;
// commands
uint8_t *dux_commands;
// counter which ignores the first buffers
int ignore;
struct semaphore sem; struct semaphore sem;
} usbduxfastsub_t; };
// The pointer to the private usb-data of the driver /*
// is also the private data for the comedi-device. * The pointer to the private usb-data of the driver
// This has to be global as the usb subsystem needs * is also the private data for the comedi-device.
// global variables. The other reason is that this * This has to be global as the usb subsystem needs
// structure must be there _before_ any comedi * global variables. The other reason is that this
// command is issued. The usb subsystem must be * structure must be there _before_ any comedi
// initialised before comedi can access it. * command is issued. The usb subsystem must be
static usbduxfastsub_t usbduxfastsub[NUMUSBDUXFAST]; * initialised before comedi can access it.
*/
static struct usbduxfastsub_s usbduxfastsub[NUMUSBDUXFAST];
static DECLARE_MUTEX(start_stop_sem); static DECLARE_MUTEX(start_stop_sem);
// bulk transfers to usbduxfast /*
* bulk transfers to usbduxfast
*/
#define SENDADCOMMANDS 0 #define SENDADCOMMANDS 0
#define SENDINITEP6 1 #define SENDINITEP6 1
static int send_dux_commands(usbduxfastsub_t * this_usbduxfastsub, int cmd_type) static int send_dux_commands(struct usbduxfastsub_s *udfs, int cmd_type)
{ {
int tmp, nsent; int tmp, nsent;
this_usbduxfastsub->dux_commands[0] = cmd_type; udfs->dux_commands[0] = cmd_type;
#ifdef CONFIG_COMEDI_DEBUG #ifdef CONFIG_COMEDI_DEBUG
printk(KERN_DEBUG "comedi%d: usbduxfast: dux_commands: ", printk(KERN_DEBUG "comedi%d: usbduxfast: dux_commands: ",
this_usbduxfastsub->comedidev->minor); udfs->comedidev->minor);
for (tmp = 0; tmp < SIZEOFDUXBUFFER; tmp++) for (tmp = 0; tmp < SIZEOFDUXBUFFER; tmp++)
printk(" %02x", this_usbduxfastsub->dux_commands[tmp]); printk(" %02x", udfs->dux_commands[tmp]);
printk("\n"); printk("\n");
#endif #endif
tmp = usb_bulk_msg(this_usbduxfastsub->usbdev, tmp = usb_bulk_msg(udfs->usbdev,
usb_sndbulkpipe(this_usbduxfastsub->usbdev, usb_sndbulkpipe(udfs->usbdev, CHANNELLISTEP),
CHANNELLISTEP), udfs->dux_commands, SIZEOFDUXBUFFER, &nsent, 10000);
this_usbduxfastsub->dux_commands, SIZEOFDUXBUFFER,
&nsent, 10000);
if (tmp < 0) if (tmp < 0)
printk(KERN_ERR "comedi%d: could not transmit dux_commands to" printk(KERN_ERR "comedi%d: could not transmit dux_commands to"
"the usb-device, err=%d\n", "the usb-device, err=%d\n", udfs->comedidev->minor, tmp);
this_usbduxfastsub->comedidev->minor, tmp);
return tmp; return tmp;
} }
// Stops the data acquision /*
// It should be safe to call this function from any context * Stops the data acquision.
static int usbduxfastsub_unlink_InURBs(usbduxfastsub_t * usbduxfastsub_tmp) * It should be safe to call this function from any context.
*/
static int usbduxfastsub_unlink_InURBs(struct usbduxfastsub_s *udfs)
{ {
int j = 0; int j = 0;
int err = 0; int err = 0;
if (usbduxfastsub_tmp && usbduxfastsub_tmp->urbIn) { if (udfs && udfs->urbIn) {
usbduxfastsub_tmp->ai_cmd_running = 0; udfs->ai_cmd_running = 0;
// waits until a running transfer is over /* waits until a running transfer is over */
usb_kill_urb(usbduxfastsub_tmp->urbIn); usb_kill_urb(udfs->urbIn);
j = 0; j = 0;
} }
#ifdef CONFIG_COMEDI_DEBUG #ifdef CONFIG_COMEDI_DEBUG
printk("comedi: usbduxfast: unlinked InURB: res=%d\n", j); printk(KERN_DEBUG "comedi: usbduxfast: unlinked InURB: res=%d\n", j);
#endif #endif
return err; return err;
} }
/* This will stop a running acquisition operation */ /*
// Is called from within this driver from both the * This will stop a running acquisition operation.
// interrupt context and from comedi * Is called from within this driver from both the
static int usbduxfast_ai_stop(usbduxfastsub_t * this_usbduxfastsub, * interrupt context and from comedi.
*/
static int usbduxfast_ai_stop(struct usbduxfastsub_s *udfs,
int do_unlink) int do_unlink)
{ {
int ret = 0; int ret = 0;
if (!this_usbduxfastsub) { if (!udfs) {
printk("comedi?: usbduxfast_ai_stop: this_usbduxfastsub=NULL!\n"); printk(KERN_ERR "comedi?: usbduxfast_ai_stop: udfs=NULL!\n");
return -EFAULT; return -EFAULT;
} }
#ifdef CONFIG_COMEDI_DEBUG #ifdef CONFIG_COMEDI_DEBUG
printk("comedi: usbduxfast_ai_stop\n"); printk(KERN_DEBUG "comedi: usbduxfast_ai_stop\n");
#endif #endif
this_usbduxfastsub->ai_cmd_running = 0; udfs->ai_cmd_running = 0;
if (do_unlink) { if (do_unlink)
// stop aquistion ret = usbduxfastsub_unlink_InURBs(udfs); /* stop aquistion */
ret = usbduxfastsub_unlink_InURBs(this_usbduxfastsub);
}
return ret; return ret;
} }
// This will cancel a running acquisition operation. /*
// This is called by comedi but never from inside the * This will cancel a running acquisition operation.
// driver. * This is called by comedi but never from inside the driver.
static int usbduxfast_ai_cancel(comedi_device * dev, comedi_subdevice * s) */
static int usbduxfast_ai_cancel(comedi_device *dev, comedi_subdevice *s)
{ {
usbduxfastsub_t *this_usbduxfastsub; struct usbduxfastsub_s *udfs;
int res = 0; int ret;
// force unlink of all urbs /* force unlink of all urbs */
#ifdef CONFIG_COMEDI_DEBUG #ifdef CONFIG_COMEDI_DEBUG
printk("comedi: usbduxfast_ai_cancel\n"); printk(KERN_DEBUG "comedi: usbduxfast_ai_cancel\n");
#endif #endif
this_usbduxfastsub = dev->private; udfs = dev->private;
if (!this_usbduxfastsub) { if (!udfs) {
printk("comedi: usbduxfast_ai_cancel: this_usbduxfastsub=NULL\n"); printk(KERN_ERR "comedi: usbduxfast_ai_cancel: udfs=NULL\n");
return -EFAULT; return -EFAULT;
} }
down(&this_usbduxfastsub->sem); down(&udfs->sem);
if (!(this_usbduxfastsub->probed)) { if (!udfs->probed) {
up(&this_usbduxfastsub->sem); up(&udfs->sem);
return -ENODEV; return -ENODEV;
} }
// unlink /* unlink */
res = usbduxfast_ai_stop(this_usbduxfastsub, 1); ret = usbduxfast_ai_stop(udfs, 1);
up(&this_usbduxfastsub->sem); up(&udfs->sem);
return res; return ret;
} }
// analogue IN /*
// interrupt service routine * analogue IN
* interrupt service routine
*/
static void usbduxfastsub_ai_Irq(struct urb *urb PT_REGS_ARG) static void usbduxfastsub_ai_Irq(struct urb *urb PT_REGS_ARG)
{ {
int n, err; int n, err;
usbduxfastsub_t *this_usbduxfastsub; struct usbduxfastsub_s *udfs;
comedi_device *this_comedidev; comedi_device *this_comedidev;
comedi_subdevice *s; comedi_subdevice *s;
uint16_t *p; uint16_t *p;
// sanity checks /* sanity checks - is the urb there? */
// is the urb there?
if (!urb) { if (!urb) {
printk("comedi_: usbduxfast_: ao int-handler called with urb=NULL!\n"); printk(KERN_ERR "comedi_: usbduxfast_: ao int-handler called "
"with urb=NULL!\n");
return; return;
} }
// the context variable points to the subdevice /* the context variable points to the subdevice */
this_comedidev = urb->context; this_comedidev = urb->context;
if (!this_comedidev) { if (!this_comedidev) {
printk("comedi_: usbduxfast_: urb context is a NULL pointer!\n"); printk(KERN_ERR "comedi_: usbduxfast_: urb context is a NULL "
"pointer!\n");
return; return;
} }
// the private structure of the subdevice is usbduxfastsub_t /* the private structure of the subdevice is usbduxfastsub_s */
this_usbduxfastsub = this_comedidev->private; udfs = this_comedidev->private;
if (!this_usbduxfastsub) { if (!udfs) {
printk("comedi_: usbduxfast_: private of comedi subdev is a NULL pointer!\n"); printk(KERN_ERR "comedi_: usbduxfast_: private of comedi "
"subdev is a NULL pointer!\n");
return; return;
} }
// are we running a command? /* are we running a command? */
if (unlikely(!(this_usbduxfastsub->ai_cmd_running))) { if (unlikely(!udfs->ai_cmd_running)) {
// not running a command /*
// do not continue execution if no asynchronous command is running * not running a command
// in particular not resubmit * do not continue execution if no asynchronous command
* is running in particular not resubmit
*/
return; return;
} }
if (unlikely(!(this_usbduxfastsub->attached))) { if (unlikely(!udfs->attached)) {
// no comedi device there /* no comedi device there */
return; return;
} }
// subdevice which is the AD converter /* subdevice which is the AD converter */
s = this_comedidev->subdevices + SUBDEV_AD; s = this_comedidev->subdevices + SUBDEV_AD;
// first we test if something unusual has just happened /* first we test if something unusual has just happened */
switch (urb->status) { switch (urb->status) {
case 0: case 0:
break; break;
// happens after an unlink command or when the device is plugged out /*
* happens after an unlink command or when the device
* is plugged out
*/
case -ECONNRESET: case -ECONNRESET:
case -ENOENT: case -ENOENT:
case -ESHUTDOWN: case -ESHUTDOWN:
case -ECONNABORTED: case -ECONNABORTED:
// tell this comedi /* tell this comedi */
s->async->events |= COMEDI_CB_EOA; s->async->events |= COMEDI_CB_EOA;
s->async->events |= COMEDI_CB_ERROR; s->async->events |= COMEDI_CB_ERROR;
comedi_event(this_usbduxfastsub->comedidev, s); comedi_event(udfs->comedidev, s);
// stop the transfer w/o unlink /* stop the transfer w/o unlink */
usbduxfast_ai_stop(this_usbduxfastsub, 0); usbduxfast_ai_stop(udfs, 0);
return; return;
default: default:
printk("comedi%d: usbduxfast: non-zero urb status received in ai intr context: %d\n", this_usbduxfastsub->comedidev->minor, urb->status); printk("comedi%d: usbduxfast: non-zero urb status received in "
"ai intr context: %d\n",
udfs->comedidev->minor, urb->status);
s->async->events |= COMEDI_CB_EOA; s->async->events |= COMEDI_CB_EOA;
s->async->events |= COMEDI_CB_ERROR; s->async->events |= COMEDI_CB_ERROR;
comedi_event(this_usbduxfastsub->comedidev, s); comedi_event(udfs->comedidev, s);
usbduxfast_ai_stop(this_usbduxfastsub, 0); usbduxfast_ai_stop(udfs, 0);
return; return;
} }
p = urb->transfer_buffer; p = urb->transfer_buffer;
if (!this_usbduxfastsub->ignore) { if (!udfs->ignore) {
if (!(this_usbduxfastsub->ai_continous)) { if (!udfs->ai_continous) {
// not continous, fixed number of samples /* not continous, fixed number of samples */
n = urb->actual_length / sizeof(uint16_t); n = urb->actual_length / sizeof(uint16_t);
if (unlikely(this_usbduxfastsub->ai_sample_count < n)) { if (unlikely(udfs->ai_sample_count < n)) {
// we have send only a fraction of the bytes received /*
* we have send only a fraction of the bytes
* received
*/
cfc_write_array_to_buffer(s, cfc_write_array_to_buffer(s,
urb->transfer_buffer, urb->transfer_buffer,
this_usbduxfastsub->ai_sample_count * udfs->ai_sample_count
sizeof(uint16_t)); * sizeof(uint16_t));
usbduxfast_ai_stop(this_usbduxfastsub, 0); usbduxfast_ai_stop(udfs, 0);
// say comedi that the acquistion is over /* say comedi that the acquistion is over */
s->async->events |= COMEDI_CB_EOA; s->async->events |= COMEDI_CB_EOA;
comedi_event(this_usbduxfastsub->comedidev, s); comedi_event(udfs->comedidev, s);
return; return;
} }
this_usbduxfastsub->ai_sample_count -= n; udfs->ai_sample_count -= n;
} }
// write the full buffer to comedi /* write the full buffer to comedi */
cfc_write_array_to_buffer(s, cfc_write_array_to_buffer(s, urb->transfer_buffer,
urb->transfer_buffer, urb->actual_length); urb->actual_length);
// tell comedi that data is there /* tell comedi that data is there */
comedi_event(this_usbduxfastsub->comedidev, s); comedi_event(udfs->comedidev, s);
} else { } else {
// ignore this packet /* ignore this packet */
this_usbduxfastsub->ignore--; udfs->ignore--;
} }
// command is still running /*
// resubmit urb for BULK transfer * command is still running
urb->dev = this_usbduxfastsub->usbdev; * resubmit urb for BULK transfer
*/
urb->dev = udfs->usbdev;
urb->status = 0; urb->status = 0;
err = usb_submit_urb(urb, GFP_ATOMIC); err = usb_submit_urb(urb, GFP_ATOMIC);
if (err < 0) { if (err < 0) {
printk("comedi%d: usbduxfast: urb resubm failed: %d", printk(KERN_ERR "comedi%d: usbduxfast: urb resubm failed: %d",
this_usbduxfastsub->comedidev->minor, err); udfs->comedidev->minor, err);
s->async->events |= COMEDI_CB_EOA; s->async->events |= COMEDI_CB_EOA;
s->async->events |= COMEDI_CB_ERROR; s->async->events |= COMEDI_CB_ERROR;
comedi_event(this_usbduxfastsub->comedidev, s); comedi_event(udfs->comedidev, s);
usbduxfast_ai_stop(this_usbduxfastsub, 0); usbduxfast_ai_stop(udfs, 0);
} }
} }
static int usbduxfastsub_start(usbduxfastsub_t * usbduxfastsub) static int usbduxfastsub_start(struct usbduxfastsub_s *udfs)
{ {
int errcode = 0; int ret;
unsigned char local_transfer_buffer[16]; unsigned char local_transfer_buffer[16];
if (usbduxfastsub->probed) { if (!udfs->probed)
// 7f92 to zero return 0;
local_transfer_buffer[0] = 0;
errcode = usb_control_msg(usbduxfastsub->usbdev, /* 7f92 to zero */
// create a pipe for a control transfer local_transfer_buffer[0] = 0;
usb_sndctrlpipe(usbduxfastsub->usbdev, 0), ret = usb_control_msg(udfs->usbdev,
// bRequest, "Firmware" usb_sndctrlpipe(udfs->usbdev, 0),
USBDUXFASTSUB_FIRMWARE, USBDUXFASTSUB_FIRMWARE, /* bRequest, "Firmware" */
// bmRequestType VENDOR_DIR_OUT, /* bmRequestType */
VENDOR_DIR_OUT, USBDUXFASTSUB_CPUCS, /* Value */
// Value 0x0000, /* Index */
USBDUXFASTSUB_CPUCS, local_transfer_buffer, /* address of the transfer buffer */
// Index 1, /* Length */
0x0000, EZTIMEOUT); /* Timeout */
// address of the transfer buffer if (ret < 0) {
local_transfer_buffer, printk("comedi_: usbduxfast_: control msg failed (start)\n");
// Length return ret;
1,
// Timeout
EZTIMEOUT);
if (errcode < 0) {
printk("comedi_: usbduxfast_: control msg failed (start)\n");
return errcode;
}
} }
return 0; return 0;
} }
static int usbduxfastsub_stop(usbduxfastsub_t * usbduxfastsub) static int usbduxfastsub_stop(struct usbduxfastsub_s *udfs)
{ {
int errcode = 0; int ret;
unsigned char local_transfer_buffer[16]; unsigned char local_transfer_buffer[16];
if (usbduxfastsub->probed) {
// 7f92 to one if (!udfs->probed)
local_transfer_buffer[0] = 1; return 0;
errcode = usb_control_msg(usbduxfastsub->usbdev,
usb_sndctrlpipe(usbduxfastsub->usbdev, 0), /* 7f92 to one */
// bRequest, "Firmware" local_transfer_buffer[0] = 1;
USBDUXFASTSUB_FIRMWARE, ret = usb_control_msg(udfs->usbdev,
// bmRequestType usb_sndctrlpipe(udfs->usbdev, 0),
VENDOR_DIR_OUT, USBDUXFASTSUB_FIRMWARE, /* bRequest, "Firmware" */
// Value VENDOR_DIR_OUT, /* bmRequestType */
USBDUXFASTSUB_CPUCS, USBDUXFASTSUB_CPUCS, /* Value */
// Index 0x0000, /* Index */
0x0000, local_transfer_buffer, local_transfer_buffer,
// Length 1, /* Length */
1, EZTIMEOUT); /* Timeout */
// Timeout if (ret < 0) {
EZTIMEOUT); printk(KERN_ERR "comedi_: usbduxfast: control msg failed "
if (errcode < 0) { "(stop)\n");
printk("comedi_: usbduxfast: control msg failed (stop)\n"); return ret;
return errcode;
}
} }
return 0; return 0;
} }
static int usbduxfastsub_upload(usbduxfastsub_t * usbduxfastsub, static int usbduxfastsub_upload(struct usbduxfastsub_s *udfs,
unsigned char *local_transfer_buffer, unsigned char *local_transfer_buffer,
unsigned int startAddr, unsigned int len) unsigned int startAddr, unsigned int len)
{ {
int errcode; int ret;
if (!udfs->probed)
/* no device on the bus for this index */
return -EFAULT;
if (usbduxfastsub->probed) {
#ifdef CONFIG_COMEDI_DEBUG #ifdef CONFIG_COMEDI_DEBUG
printk("comedi%d: usbduxfast: uploading %d bytes", printk(KERN_DEBUG "comedi%d: usbduxfast: uploading %d bytes",
usbduxfastsub->comedidev->minor, len); udfs->comedidev->minor, len);
printk(" to addr %d, first byte=%d.\n", printk(KERN_DEBUG " to addr %d, first byte=%d.\n",
startAddr, local_transfer_buffer[0]); startAddr, local_transfer_buffer[0]);
#endif #endif
errcode = usb_control_msg(usbduxfastsub->usbdev, ret = usb_control_msg(udfs->usbdev,
usb_sndctrlpipe(usbduxfastsub->usbdev, 0), usb_sndctrlpipe(udfs->usbdev, 0),
// brequest, firmware USBDUXFASTSUB_FIRMWARE, /* brequest, firmware */
USBDUXFASTSUB_FIRMWARE, VENDOR_DIR_OUT, /* bmRequestType */
// bmRequestType startAddr, /* value */
VENDOR_DIR_OUT, 0x0000, /* index */
// value local_transfer_buffer, /* our local safe buffer */
startAddr, len, /* length */
// index EZTIMEOUT); /* timeout */
0x0000,
// our local safe buffer
local_transfer_buffer,
// length
len,
// timeout
EZTIMEOUT);
#ifdef CONFIG_COMEDI_DEBUG #ifdef CONFIG_COMEDI_DEBUG
printk("comedi_: usbduxfast: result=%d\n", errcode); printk(KERN_DEBUG "comedi_: usbduxfast: result=%d\n", ret);
#endif #endif
if (errcode < 0) {
printk("comedi_: usbduxfast: uppload failed\n"); if (ret < 0) {
return errcode; printk(KERN_ERR "comedi_: usbduxfast: uppload failed\n");
} return ret;
} else {
// no device on the bus for this index
return -EFAULT;
} }
return 0; return 0;
} }
int firmwareUpload(usbduxfastsub_t * usbduxfastsub, int firmwareUpload(struct usbduxfastsub_s *udfs, unsigned char *firmwareBinary,
unsigned char *firmwareBinary, int sizeFirmware) int sizeFirmware)
{ {
int ret; int ret;
if (!firmwareBinary) { if (!firmwareBinary)
return 0; return 0;
}
ret = usbduxfastsub_stop(usbduxfastsub); ret = usbduxfastsub_stop(udfs);
if (ret < 0) { if (ret < 0) {
printk("comedi_: usbduxfast: can not stop firmware\n"); printk(KERN_ERR "comedi_: usbduxfast: can not stop firmware\n");
return ret; return ret;
} }
ret = usbduxfastsub_upload(usbduxfastsub, ret = usbduxfastsub_upload(udfs, firmwareBinary, 0, sizeFirmware);
firmwareBinary, 0, sizeFirmware);
if (ret < 0) { if (ret < 0) {
printk("comedi_: usbduxfast: firmware upload failed\n"); printk(KERN_ERR "comedi_: usbduxfast: firmware upload failed\n");
return ret; return ret;
} }
ret = usbduxfastsub_start(usbduxfastsub); ret = usbduxfastsub_start(udfs);
if (ret < 0) { if (ret < 0) {
printk("comedi_: usbduxfast: can not start firmware\n"); printk(KERN_ERR "comedi_: usbduxfast: can not start firmware\n");
return ret; return ret;
} }
return 0; return 0;
} }
int usbduxfastsub_submit_InURBs(usbduxfastsub_t * usbduxfastsub) int usbduxfastsub_submit_InURBs(struct usbduxfastsub_s *udfs)
{ {
int errFlag; int ret;
if (!usbduxfastsub) { if (!udfs)
return -EFAULT; return -EFAULT;
}
usb_fill_bulk_urb(usbduxfastsub->urbIn, usb_fill_bulk_urb(udfs->urbIn, udfs->usbdev,
usbduxfastsub->usbdev, usb_rcvbulkpipe(udfs->usbdev, BULKINEP),
usb_rcvbulkpipe(usbduxfastsub->usbdev, BULKINEP), udfs->transfer_buffer,
usbduxfastsub->transfer_buffer, SIZEINBUF, usbduxfastsub_ai_Irq, udfs->comedidev);
SIZEINBUF, usbduxfastsub_ai_Irq, usbduxfastsub->comedidev);
#ifdef CONFIG_COMEDI_DEBUG #ifdef CONFIG_COMEDI_DEBUG
printk("comedi%d: usbduxfast: submitting in-urb: 0x%p,0x%p\n", printk(KERN_DEBUG "comedi%d: usbduxfast: submitting in-urb: "
usbduxfastsub->comedidev->minor, "0x%p,0x%p\n", udfs->comedidev->minor, udfs->urbIn->context,
usbduxfastsub->urbIn->context, udfs->urbIn->dev);
usbduxfastsub->urbIn->dev);
#endif #endif
errFlag = usb_submit_urb(usbduxfastsub->urbIn, GFP_ATOMIC); ret = usb_submit_urb(udfs->urbIn, GFP_ATOMIC);
if (errFlag) { if (ret) {
printk("comedi_: usbduxfast: ai: usb_submit_urb error %d\n", printk(KERN_ERR "comedi_: usbduxfast: ai: usb_submit_urb error"
errFlag); " %d\n", ret);
return errFlag; return ret;
} }
return 0; return 0;
} }
static int usbduxfast_ai_cmdtest(comedi_device * dev, static int usbduxfast_ai_cmdtest(comedi_device *dev,
comedi_subdevice * s, comedi_cmd * cmd) comedi_subdevice *s, comedi_cmd *cmd)
{ {
int err = 0, stop_mask = 0; int err = 0, stop_mask = 0;
long int steps, tmp = 0; long int steps, tmp;
int minSamplPer; int minSamplPer;
usbduxfastsub_t *this_usbduxfastsub = dev->private; struct usbduxfastsub_s *udfs = dev->private;
if (!(this_usbduxfastsub->probed)) {
if (!udfs->probed)
return -ENODEV; return -ENODEV;
}
#ifdef CONFIG_COMEDI_DEBUG #ifdef CONFIG_COMEDI_DEBUG
printk("comedi%d: usbduxfast_ai_cmdtest\n", dev->minor); printk(KERN_DEBUG "comedi%d: usbduxfast_ai_cmdtest\n", dev->minor);
printk("comedi%d: usbduxfast: convert_arg=%u scan_begin_arg=%u\n", printk(KERN_DEBUG "comedi%d: usbduxfast: convert_arg=%u "
dev->minor, cmd->convert_arg, cmd->scan_begin_arg); "scan_begin_arg=%u\n",
dev->minor, cmd->convert_arg, cmd->scan_begin_arg);
#endif #endif
/* step 1: make sure trigger sources are trivially valid */ /* step 1: make sure trigger sources are trivially valid */
...@@ -607,7 +633,9 @@ static int usbduxfast_ai_cmdtest(comedi_device * dev, ...@@ -607,7 +633,9 @@ static int usbduxfast_ai_cmdtest(comedi_device * dev,
if (err) if (err)
return 1; return 1;
/* step 2: make sure trigger sources are unique and mutually compatible */ /*
* step 2: make sure trigger sources are unique and mutually compatible
*/
if (cmd->start_src != TRIG_NOW && if (cmd->start_src != TRIG_NOW &&
cmd->start_src != TRIG_EXT && cmd->start_src != TRIG_INT) cmd->start_src != TRIG_EXT && cmd->start_src != TRIG_INT)
...@@ -622,7 +650,7 @@ static int usbduxfast_ai_cmdtest(comedi_device * dev, ...@@ -622,7 +650,7 @@ static int usbduxfast_ai_cmdtest(comedi_device * dev,
cmd->stop_src != TRIG_EXT && cmd->stop_src != TRIG_NONE) cmd->stop_src != TRIG_EXT && cmd->stop_src != TRIG_NONE)
err++; err++;
// can't have external stop and start triggers at once /* can't have external stop and start triggers at once */
if (cmd->start_src == TRIG_EXT && cmd->stop_src == TRIG_EXT) if (cmd->start_src == TRIG_EXT && cmd->stop_src == TRIG_EXT)
err++; err++;
...@@ -636,29 +664,28 @@ static int usbduxfast_ai_cmdtest(comedi_device * dev, ...@@ -636,29 +664,28 @@ static int usbduxfast_ai_cmdtest(comedi_device * dev,
err++; err++;
} }
if (!cmd->chanlist_len) { if (!cmd->chanlist_len)
err++; err++;
}
if (cmd->scan_end_arg != cmd->chanlist_len) { if (cmd->scan_end_arg != cmd->chanlist_len) {
cmd->scan_end_arg = cmd->chanlist_len; cmd->scan_end_arg = cmd->chanlist_len;
err++; err++;
} }
if (cmd->chanlist_len == 1) { if (cmd->chanlist_len == 1)
minSamplPer = 1; minSamplPer = 1;
} else { else
minSamplPer = MIN_SAMPLING_PERIOD; minSamplPer = MIN_SAMPLING_PERIOD;
}
if (cmd->convert_src == TRIG_TIMER) { if (cmd->convert_src == TRIG_TIMER) {
steps = cmd->convert_arg * 30; steps = cmd->convert_arg * 30;
if (steps < (minSamplPer * 1000)) { if (steps < (minSamplPer * 1000))
steps = minSamplPer * 1000; steps = minSamplPer * 1000;
}
if (steps > (MAX_SAMPLING_PERIOD * 1000)) { if (steps > (MAX_SAMPLING_PERIOD * 1000))
steps = MAX_SAMPLING_PERIOD * 1000; steps = MAX_SAMPLING_PERIOD * 1000;
}
// calc arg again /* calc arg again */
tmp = steps / 30; tmp = steps / 30;
if (cmd->convert_arg != tmp) { if (cmd->convert_arg != tmp) {
cmd->convert_arg = tmp; cmd->convert_arg = tmp;
...@@ -666,10 +693,10 @@ static int usbduxfast_ai_cmdtest(comedi_device * dev, ...@@ -666,10 +693,10 @@ static int usbduxfast_ai_cmdtest(comedi_device * dev,
} }
} }
if (cmd->scan_begin_src == TRIG_TIMER) { if (cmd->scan_begin_src == TRIG_TIMER)
err++; err++;
}
// stop source /* stop source */
switch (cmd->stop_src) { switch (cmd->stop_src) {
case TRIG_COUNT: case TRIG_COUNT:
if (!cmd->stop_arg) { if (!cmd->stop_arg) {
...@@ -683,7 +710,10 @@ static int usbduxfast_ai_cmdtest(comedi_device * dev, ...@@ -683,7 +710,10 @@ static int usbduxfast_ai_cmdtest(comedi_device * dev,
err++; err++;
} }
break; break;
// TRIG_EXT doesn't care since it doesn't trigger off a numbered channel /*
* TRIG_EXT doesn't care since it doesn't trigger
* off a numbered channel
*/
default: default:
break; break;
} }
...@@ -697,588 +727,676 @@ static int usbduxfast_ai_cmdtest(comedi_device * dev, ...@@ -697,588 +727,676 @@ static int usbduxfast_ai_cmdtest(comedi_device * dev,
} }
static int usbduxfast_ai_inttrig(comedi_device * dev, static int usbduxfast_ai_inttrig(comedi_device *dev,
comedi_subdevice * s, unsigned int trignum) comedi_subdevice *s, unsigned int trignum)
{ {
int ret; int ret;
usbduxfastsub_t *this_usbduxfastsub = dev->private; struct usbduxfastsub_s *udfs = dev->private;
if (!this_usbduxfastsub) {
if (!udfs)
return -EFAULT; return -EFAULT;
}
down(&this_usbduxfastsub->sem); down(&udfs->sem);
if (!(this_usbduxfastsub->probed)) { if (!udfs->probed) {
up(&this_usbduxfastsub->sem); up(&udfs->sem);
return -ENODEV; return -ENODEV;
} }
#ifdef CONFIG_COMEDI_DEBUG #ifdef CONFIG_COMEDI_DEBUG
printk("comedi%d: usbduxfast_ai_inttrig\n", dev->minor); printk(KERN_DEBUG "comedi%d: usbduxfast_ai_inttrig\n", dev->minor);
#endif #endif
if (trignum != 0) { if (trignum != 0) {
printk("comedi%d: usbduxfast_ai_inttrig: invalid trignum\n", printk(KERN_ERR "comedi%d: usbduxfast_ai_inttrig: invalid"
dev->minor); " trignum\n", dev->minor);
up(&this_usbduxfastsub->sem); up(&udfs->sem);
return -EINVAL; return -EINVAL;
} }
if (!(this_usbduxfastsub->ai_cmd_running)) { if (!udfs->ai_cmd_running) {
this_usbduxfastsub->ai_cmd_running = 1; udfs->ai_cmd_running = 1;
ret = usbduxfastsub_submit_InURBs(this_usbduxfastsub); ret = usbduxfastsub_submit_InURBs(udfs);
if (ret < 0) { if (ret < 0) {
printk("comedi%d: usbduxfast_ai_inttrig: urbSubmit: err=%d\n", dev->minor, ret); printk(KERN_ERR "comedi%d: usbduxfast_ai_inttrig: "
this_usbduxfastsub->ai_cmd_running = 0; "urbSubmit: err=%d\n", dev->minor, ret);
up(&this_usbduxfastsub->sem); udfs->ai_cmd_running = 0;
up(&udfs->sem);
return ret; return ret;
} }
s->async->inttrig = NULL; s->async->inttrig = NULL;
} else { } else {
printk("comedi%d: ai_inttrig but acqu is already running\n", printk(KERN_ERR "comedi%d: ai_inttrig but acqu is already"
dev->minor); " running\n", dev->minor);
} }
up(&this_usbduxfastsub->sem); up(&udfs->sem);
return 1; return 1;
} }
// offsets for the GPIF bytes /*
// the first byte is the command byte * offsets for the GPIF bytes
#define LENBASE 1+0x00 * the first byte is the command byte
#define OPBASE 1+0x08 */
#define OUTBASE 1+0x10 #define LENBASE (1+0x00)
#define LOGBASE 1+0x18 #define OPBASE (1+0x08)
#define OUTBASE (1+0x10)
#define LOGBASE (1+0x18)
static int usbduxfast_ai_cmd(comedi_device * dev, comedi_subdevice * s) static int usbduxfast_ai_cmd(comedi_device *dev, comedi_subdevice *s)
{ {
comedi_cmd *cmd = &s->async->cmd; comedi_cmd *cmd = &s->async->cmd;
unsigned int chan, gain, rngmask = 0xff; unsigned int chan, gain, rngmask = 0xff;
int i, j, ret; int i, j, ret;
usbduxfastsub_t *this_usbduxfastsub = dev->private; struct usbduxfastsub_s *udfs;
int result; int result;
long steps, steps_tmp; long steps, steps_tmp;
#ifdef CONFIG_COMEDI_DEBUG #ifdef CONFIG_COMEDI_DEBUG
printk("comedi%d: usbduxfast_ai_cmd\n", dev->minor); printk(KERN_DEBUG "comedi%d: usbduxfast_ai_cmd\n", dev->minor);
#endif #endif
if (!this_usbduxfastsub) { udfs = dev->private;
if (!udfs)
return -EFAULT; return -EFAULT;
}
down(&this_usbduxfastsub->sem); down(&udfs->sem);
if (!(this_usbduxfastsub->probed)) { if (!udfs->probed) {
up(&this_usbduxfastsub->sem); up(&udfs->sem);
return -ENODEV; return -ENODEV;
} }
if (this_usbduxfastsub->ai_cmd_running) { if (udfs->ai_cmd_running) {
printk("comedi%d: ai_cmd not possible. Another ai_cmd is running.\n", dev->minor); printk(KERN_ERR "comedi%d: ai_cmd not possible. Another ai_cmd"
up(&this_usbduxfastsub->sem); " is running.\n", dev->minor);
up(&udfs->sem);
return -EBUSY; return -EBUSY;
} }
// set current channel of the running aquisition to zero /* set current channel of the running aquisition to zero */
s->async->cur_chan = 0; s->async->cur_chan = 0;
// ignore the first buffers from the device if there is an error condition /*
this_usbduxfastsub->ignore = PACKETS_TO_IGNORE; * ignore the first buffers from the device if there
* is an error condition
*/
udfs->ignore = PACKETS_TO_IGNORE;
if (cmd->chanlist_len > 0) { if (cmd->chanlist_len > 0) {
gain = CR_RANGE(cmd->chanlist[0]); gain = CR_RANGE(cmd->chanlist[0]);
for (i = 0; i < cmd->chanlist_len; ++i) { for (i = 0; i < cmd->chanlist_len; ++i) {
chan = CR_CHAN(cmd->chanlist[i]); chan = CR_CHAN(cmd->chanlist[i]);
if (chan != i) { if (chan != i) {
printk("comedi%d: cmd is accepting only consecutive channels.\n", dev->minor); printk(KERN_ERR "comedi%d: cmd is accepting "
up(&this_usbduxfastsub->sem); "only consecutive channels.\n",
dev->minor);
up(&udfs->sem);
return -EINVAL; return -EINVAL;
} }
if ((gain != CR_RANGE(cmd->chanlist[i])) if ((gain != CR_RANGE(cmd->chanlist[i]))
&& (cmd->chanlist_len > 3)) { && (cmd->chanlist_len > 3)) {
printk("comedi%d: the gain must be the same for all channels.\n", dev->minor); printk(KERN_ERR "comedi%d: the gain must be"
up(&this_usbduxfastsub->sem); " the same for all channels.\n",
dev->minor);
up(&udfs->sem);
return -EINVAL; return -EINVAL;
} }
if (i >= NUMCHANNELS) { if (i >= NUMCHANNELS) {
printk("comedi%d: channel list too long\n", printk(KERN_ERR "comedi%d: channel list too"
dev->minor); " long\n", dev->minor);
break; break;
} }
} }
} }
steps = 0; steps = 0;
if (cmd->scan_begin_src == TRIG_TIMER) { if (cmd->scan_begin_src == TRIG_TIMER) {
printk("comedi%d: usbduxfast: scan_begin_src==TRIG_TIMER not valid.\n", dev->minor); printk(KERN_ERR "comedi%d: usbduxfast: "
up(&this_usbduxfastsub->sem); "scan_begin_src==TRIG_TIMER not valid.\n", dev->minor);
up(&udfs->sem);
return -EINVAL; return -EINVAL;
} }
if (cmd->convert_src == TRIG_TIMER) { if (cmd->convert_src == TRIG_TIMER)
steps = (cmd->convert_arg * 30) / 1000; steps = (cmd->convert_arg * 30) / 1000;
}
if ((steps < MIN_SAMPLING_PERIOD) && (cmd->chanlist_len != 1)) { 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); printk(KERN_ERR "comedi%d: usbduxfast: ai_cmd: steps=%ld, "
up(&this_usbduxfastsub->sem); "scan_begin_arg=%d. Not properly tested by cmdtest?\n",
dev->minor, steps, cmd->scan_begin_arg);
up(&udfs->sem);
return -EINVAL; return -EINVAL;
} }
if (steps > MAX_SAMPLING_PERIOD) { if (steps > MAX_SAMPLING_PERIOD) {
printk("comedi%d: usbduxfast: ai_cmd: sampling rate too low.\n", printk(KERN_ERR "comedi%d: usbduxfast: ai_cmd: sampling rate "
dev->minor); "too low.\n", dev->minor);
up(&this_usbduxfastsub->sem); up(&udfs->sem);
return -EINVAL; return -EINVAL;
} }
if ((cmd->start_src == TRIG_EXT) && (cmd->chanlist_len != 1) if ((cmd->start_src == TRIG_EXT) && (cmd->chanlist_len != 1)
&& (cmd->chanlist_len != 16)) { && (cmd->chanlist_len != 16)) {
printk("comedi%d: usbduxfast: ai_cmd: TRIG_EXT only with 1 or 16 channels possible.\n", dev->minor); printk(KERN_ERR "comedi%d: usbduxfast: ai_cmd: TRIG_EXT only"
up(&this_usbduxfastsub->sem); " with 1 or 16 channels possible.\n", dev->minor);
up(&udfs->sem);
return -EINVAL; return -EINVAL;
} }
#ifdef CONFIG_COMEDI_DEBUG #ifdef CONFIG_COMEDI_DEBUG
printk("comedi%d: usbduxfast: steps=%ld, convert_arg=%u\n", printk(KERN_DEBUG "comedi%d: usbduxfast: steps=%ld, convert_arg=%u\n",
dev->minor, steps, cmd->convert_arg); dev->minor, steps, cmd->convert_arg);
#endif #endif
switch (cmd->chanlist_len) { switch (cmd->chanlist_len) {
// one channel
case 1: case 1:
/*
* one channel
*/
if (CR_RANGE(cmd->chanlist[0]) > 0) if (CR_RANGE(cmd->chanlist[0]) > 0)
rngmask = 0xff - 0x04; rngmask = 0xff - 0x04;
else else
rngmask = 0xff; rngmask = 0xff;
// for external trigger: looping in this state until the RDY0 pin /*
// becomes zero * for external trigger: looping in this state until
if (cmd->start_src == TRIG_EXT) { // we loop here until ready has been set * the RDY0 pin becomes zero
this_usbduxfastsub->dux_commands[LENBASE + 0] = 0x01; // branch back to state 0 */
this_usbduxfastsub->dux_commands[OPBASE + 0] = 0x01; // deceision state w/o data
this_usbduxfastsub->dux_commands[OUTBASE + 0] = /* we loop here until ready has been set */
0xFF & rngmask; if (cmd->start_src == TRIG_EXT) {
this_usbduxfastsub->dux_commands[LOGBASE + 0] = 0x00; // RDY0 = 0 /* branch back to state 0 */
} else { // we just proceed to state 1 udfs->dux_commands[LENBASE+0] = 0x01;
this_usbduxfastsub->dux_commands[LENBASE + 0] = 1; /* deceision state w/o data */
this_usbduxfastsub->dux_commands[OPBASE + 0] = 0; udfs->dux_commands[OPBASE+0] = 0x01;
this_usbduxfastsub->dux_commands[OUTBASE + 0] = udfs->dux_commands[OUTBASE+0] = 0xFF & rngmask;
0xFF & rngmask; /* RDY0 = 0 */
this_usbduxfastsub->dux_commands[LOGBASE + 0] = 0; udfs->dux_commands[LOGBASE+0] = 0x00;
} else { /* we just proceed to state 1 */
udfs->dux_commands[LENBASE+0] = 1;
udfs->dux_commands[OPBASE+0] = 0;
udfs->dux_commands[OUTBASE+0] = 0xFF & rngmask;
udfs->dux_commands[LOGBASE+0] = 0;
} }
if (steps < MIN_SAMPLING_PERIOD) { if (steps < MIN_SAMPLING_PERIOD) {
// for fast single channel aqu without mux /* for fast single channel aqu without mux */
if (steps <= 1) { if (steps <= 1) {
// we just stay here at state 1 and rexecute the same state /*
// this gives us 30MHz sampling rate * we just stay here at state 1 and rexecute
this_usbduxfastsub->dux_commands[LENBASE + 1] = 0x89; // branch back to state 1 * the same state this gives us 30MHz sampling
this_usbduxfastsub->dux_commands[OPBASE + 1] = 0x03; // deceision state with data * rate
this_usbduxfastsub->dux_commands[OUTBASE + 1] = */
0xFF & rngmask;
this_usbduxfastsub->dux_commands[LOGBASE + 1] = 0xFF; // doesn't matter /* branch back to state 1 */
udfs->dux_commands[LENBASE+1] = 0x89;
/* deceision state with data */
udfs->dux_commands[OPBASE+1] = 0x03;
udfs->dux_commands[OUTBASE+1] = 0xFF & rngmask;
/* doesn't matter */
udfs->dux_commands[LOGBASE+1] = 0xFF;
} else { } else {
// we loop through two states: data and delay: max rate is 15Mhz /*
this_usbduxfastsub->dux_commands[LENBASE + 1] = * we loop through two states: data and delay
steps - 1; * max rate is 15MHz
this_usbduxfastsub->dux_commands[OPBASE + 1] = 0x02; // data */
this_usbduxfastsub->dux_commands[OUTBASE + 1] = udfs->dux_commands[LENBASE+1] = steps - 1;
0xFF & rngmask; /* data */
this_usbduxfastsub->dux_commands[LOGBASE + 1] = 0; // doesn't matter udfs->dux_commands[OPBASE+1] = 0x02;
udfs->dux_commands[OUTBASE+1] = 0xFF & rngmask;
this_usbduxfastsub->dux_commands[LENBASE + 2] = 0x09; // branch back to state 1 /* doesn't matter */
this_usbduxfastsub->dux_commands[OPBASE + 2] = 0x01; // deceision state w/o data udfs->dux_commands[LOGBASE+1] = 0;
this_usbduxfastsub->dux_commands[OUTBASE + 2] = /* branch back to state 1 */
0xFF & rngmask; udfs->dux_commands[LENBASE+2] = 0x09;
this_usbduxfastsub->dux_commands[LOGBASE + 2] = 0xFF; // doesn't matter /* deceision state w/o data */
udfs->dux_commands[OPBASE+2] = 0x01;
udfs->dux_commands[OUTBASE+2] = 0xFF & rngmask;
/* doesn't matter */
udfs->dux_commands[LOGBASE+2] = 0xFF;
} }
} else { } else {
// we loop through 3 states: 2x delay and 1x data. This gives a min /*
// sampling rate of 60kHz. * we loop through 3 states: 2x delay and 1x data
* this gives a min sampling rate of 60kHz
*/
// we have 1 state with duration 1 /* we have 1 state with duration 1 */
steps = steps - 1; steps = steps - 1;
// do the first part of the delay /* do the first part of the delay */
this_usbduxfastsub->dux_commands[LENBASE + 1] = udfs->dux_commands[LENBASE+1] = steps / 2;
steps / 2; udfs->dux_commands[OPBASE+1] = 0;
this_usbduxfastsub->dux_commands[OPBASE + 1] = 0; udfs->dux_commands[OUTBASE+1] = 0xFF & rngmask;
this_usbduxfastsub->dux_commands[OUTBASE + 1] = udfs->dux_commands[LOGBASE+1] = 0;
0xFF & rngmask;
this_usbduxfastsub->dux_commands[LOGBASE + 1] = 0; /* and the second part */
udfs->dux_commands[LENBASE+2] = steps - steps / 2;
// and the second part udfs->dux_commands[OPBASE+2] = 0;
this_usbduxfastsub->dux_commands[LENBASE + 2] = udfs->dux_commands[OUTBASE+2] = 0xFF & rngmask;
steps - steps / 2; udfs->dux_commands[LOGBASE+2] = 0;
this_usbduxfastsub->dux_commands[OPBASE + 2] = 0;
this_usbduxfastsub->dux_commands[OUTBASE + 2] = /* get the data and branch back */
0xFF & rngmask;
this_usbduxfastsub->dux_commands[LOGBASE + 2] = 0; /* branch back to state 1 */
udfs->dux_commands[LENBASE+3] = 0x09;
// get the data and branch back /* deceision state w data */
this_usbduxfastsub->dux_commands[LENBASE + 3] = 0x09; // branch back to state 1 udfs->dux_commands[OPBASE+3] = 0x03;
this_usbduxfastsub->dux_commands[OPBASE + 3] = 0x03; // deceision state w data udfs->dux_commands[OUTBASE+3] = 0xFF & rngmask;
this_usbduxfastsub->dux_commands[OUTBASE + 3] = /* doesn't matter */
0xFF & rngmask; udfs->dux_commands[LOGBASE+3] = 0xFF;
this_usbduxfastsub->dux_commands[LOGBASE + 3] = 0xFF; // doesn't matter
} }
break; break;
case 2: case 2:
// two channels /*
// commit data to the FIFO * two channels
* commit data to the FIFO
*/
if (CR_RANGE(cmd->chanlist[0]) > 0) if (CR_RANGE(cmd->chanlist[0]) > 0)
rngmask = 0xff - 0x04; rngmask = 0xff - 0x04;
else else
rngmask = 0xff; rngmask = 0xff;
this_usbduxfastsub->dux_commands[LENBASE + 0] = 1;
this_usbduxfastsub->dux_commands[OPBASE + 0] = 0x02; // data
this_usbduxfastsub->dux_commands[OUTBASE + 0] = 0xFF & rngmask;
this_usbduxfastsub->dux_commands[LOGBASE + 0] = 0;
// we have 1 state with duration 1: state 0 udfs->dux_commands[LENBASE+0] = 1;
/* data */
udfs->dux_commands[OPBASE+0] = 0x02;
udfs->dux_commands[OUTBASE+0] = 0xFF & rngmask;
udfs->dux_commands[LOGBASE+0] = 0;
/* we have 1 state with duration 1: state 0 */
steps_tmp = steps - 1; steps_tmp = steps - 1;
if (CR_RANGE(cmd->chanlist[1]) > 0) if (CR_RANGE(cmd->chanlist[1]) > 0)
rngmask = 0xff - 0x04; rngmask = 0xff - 0x04;
else else
rngmask = 0xff; rngmask = 0xff;
// do the first part of the delay
this_usbduxfastsub->dux_commands[LENBASE + 1] = steps_tmp / 2; /* do the first part of the delay */
this_usbduxfastsub->dux_commands[OPBASE + 1] = 0; udfs->dux_commands[LENBASE+1] = steps_tmp / 2;
this_usbduxfastsub->dux_commands[OUTBASE + 1] = 0xFE & rngmask; //count udfs->dux_commands[OPBASE+1] = 0;
this_usbduxfastsub->dux_commands[LOGBASE + 1] = 0; /* count */
udfs->dux_commands[OUTBASE+1] = 0xFE & rngmask;
// and the second part udfs->dux_commands[LOGBASE+1] = 0;
this_usbduxfastsub->dux_commands[LENBASE + 2] =
steps_tmp - steps_tmp / 2; /* and the second part */
this_usbduxfastsub->dux_commands[OPBASE + 2] = 0; udfs->dux_commands[LENBASE+2] = steps_tmp - steps_tmp / 2;
this_usbduxfastsub->dux_commands[OUTBASE + 2] = 0xFF & rngmask; udfs->dux_commands[OPBASE+2] = 0;
this_usbduxfastsub->dux_commands[LOGBASE + 2] = 0; udfs->dux_commands[OUTBASE+2] = 0xFF & rngmask;
udfs->dux_commands[LOGBASE+2] = 0;
this_usbduxfastsub->dux_commands[LENBASE + 3] = 1;
this_usbduxfastsub->dux_commands[OPBASE + 3] = 0x02; // data udfs->dux_commands[LENBASE+3] = 1;
this_usbduxfastsub->dux_commands[OUTBASE + 3] = 0xFF & rngmask; /* data */
this_usbduxfastsub->dux_commands[LOGBASE + 3] = 0; udfs->dux_commands[OPBASE+3] = 0x02;
udfs->dux_commands[OUTBASE+3] = 0xFF & rngmask;
// we have 2 states with duration 1: step 6 and the IDLE state udfs->dux_commands[LOGBASE+3] = 0;
/*
* we have 2 states with duration 1: step 6 and
* the IDLE state
*/
steps_tmp = steps - 2; steps_tmp = steps - 2;
if (CR_RANGE(cmd->chanlist[0]) > 0) if (CR_RANGE(cmd->chanlist[0]) > 0)
rngmask = 0xff - 0x04; rngmask = 0xff - 0x04;
else else
rngmask = 0xff; rngmask = 0xff;
// do the first part of the delay
this_usbduxfastsub->dux_commands[LENBASE + 4] = steps_tmp / 2; /* do the first part of the delay */
this_usbduxfastsub->dux_commands[OPBASE + 4] = 0; udfs->dux_commands[LENBASE+4] = steps_tmp / 2;
this_usbduxfastsub->dux_commands[OUTBASE + 4] = (0xFF - 0x02) & rngmask; //reset udfs->dux_commands[OPBASE+4] = 0;
this_usbduxfastsub->dux_commands[LOGBASE + 4] = 0; /* reset */
udfs->dux_commands[OUTBASE+4] = (0xFF - 0x02) & rngmask;
// and the second part udfs->dux_commands[LOGBASE+4] = 0;
this_usbduxfastsub->dux_commands[LENBASE + 5] =
steps_tmp - steps_tmp / 2; /* and the second part */
this_usbduxfastsub->dux_commands[OPBASE + 5] = 0; udfs->dux_commands[LENBASE+5] = steps_tmp - steps_tmp / 2;
this_usbduxfastsub->dux_commands[OUTBASE + 5] = 0xFF & rngmask; udfs->dux_commands[OPBASE+5] = 0;
this_usbduxfastsub->dux_commands[LOGBASE + 5] = 0; udfs->dux_commands[OUTBASE+5] = 0xFF & rngmask;
udfs->dux_commands[LOGBASE+5] = 0;
this_usbduxfastsub->dux_commands[LENBASE + 6] = 1;
this_usbduxfastsub->dux_commands[OPBASE + 6] = 0; udfs->dux_commands[LENBASE+6] = 1;
this_usbduxfastsub->dux_commands[OUTBASE + 6] = 0xFF & rngmask; udfs->dux_commands[OPBASE+6] = 0;
this_usbduxfastsub->dux_commands[LOGBASE + 6] = 0; udfs->dux_commands[OUTBASE+6] = 0xFF & rngmask;
udfs->dux_commands[LOGBASE+6] = 0;
break; break;
case 3: case 3:
// three channels /*
* three channels
*/
for (j = 0; j < 1; j++) { for (j = 0; j < 1; j++) {
if (CR_RANGE(cmd->chanlist[j]) > 0) if (CR_RANGE(cmd->chanlist[j]) > 0)
rngmask = 0xff - 0x04; rngmask = 0xff - 0x04;
else else
rngmask = 0xff; rngmask = 0xff;
// commit data to the FIFO and do the first part of the delay /*
this_usbduxfastsub->dux_commands[LENBASE + j * 2] = * commit data to the FIFO and do the first part
steps / 2; * of the delay
this_usbduxfastsub->dux_commands[OPBASE + j * 2] = 0x02; // data */
this_usbduxfastsub->dux_commands[OUTBASE + j * 2] = 0xFF & rngmask; // no change udfs->dux_commands[LENBASE+j*2] = steps / 2;
this_usbduxfastsub->dux_commands[LOGBASE + j * 2] = 0; /* data */
udfs->dux_commands[OPBASE+j*2] = 0x02;
/* no change */
udfs->dux_commands[OUTBASE+j*2] = 0xFF & rngmask;
udfs->dux_commands[LOGBASE+j*2] = 0;
if (CR_RANGE(cmd->chanlist[j + 1]) > 0) if (CR_RANGE(cmd->chanlist[j + 1]) > 0)
rngmask = 0xff - 0x04; rngmask = 0xff - 0x04;
else else
rngmask = 0xff; rngmask = 0xff;
// do the second part of the delay
this_usbduxfastsub->dux_commands[LENBASE + j * 2 + 1] = /* do the second part of the delay */
steps - steps / 2; udfs->dux_commands[LENBASE+j*2+1] = steps - steps / 2;
this_usbduxfastsub->dux_commands[OPBASE + j * 2 + 1] = 0; // no data /* no data */
this_usbduxfastsub->dux_commands[OUTBASE + j * 2 + 1] = 0xFE & rngmask; //count udfs->dux_commands[OPBASE+j*2+1] = 0;
this_usbduxfastsub->dux_commands[LOGBASE + j * 2 + 1] = /* count */
0; udfs->dux_commands[OUTBASE+j*2+1] = 0xFE & rngmask;
udfs->dux_commands[LOGBASE+j*2+1] = 0;
} }
// 2 steps with duration 1: the idele step and step 6: /* 2 steps with duration 1: the idele step and step 6: */
steps_tmp = steps - 2; steps_tmp = steps - 2;
// commit data to the FIFO and do the first part of the delay
this_usbduxfastsub->dux_commands[LENBASE + 4] = steps_tmp / 2; /* commit data to the FIFO and do the first part of the delay */
this_usbduxfastsub->dux_commands[OPBASE + 4] = 0x02; // data udfs->dux_commands[LENBASE+4] = steps_tmp / 2;
this_usbduxfastsub->dux_commands[OUTBASE + 4] = 0xFF & rngmask; // no change /* data */
this_usbduxfastsub->dux_commands[LOGBASE + 4] = 0; udfs->dux_commands[OPBASE+4] = 0x02;
udfs->dux_commands[OUTBASE+4] = 0xFF & rngmask;
udfs->dux_commands[LOGBASE+4] = 0;
if (CR_RANGE(cmd->chanlist[0]) > 0) if (CR_RANGE(cmd->chanlist[0]) > 0)
rngmask = 0xff - 0x04; rngmask = 0xff - 0x04;
else else
rngmask = 0xff; rngmask = 0xff;
// do the second part of the delay
this_usbduxfastsub->dux_commands[LENBASE + 5] = /* do the second part of the delay */
steps_tmp - steps_tmp / 2; udfs->dux_commands[LENBASE+5] = steps_tmp - steps_tmp / 2;
this_usbduxfastsub->dux_commands[OPBASE + 5] = 0; // no data /* no data */
this_usbduxfastsub->dux_commands[OUTBASE + 5] = (0xFF - 0x02) & rngmask; // reset udfs->dux_commands[OPBASE+5] = 0;
this_usbduxfastsub->dux_commands[LOGBASE + 5] = 0; /* reset */
udfs->dux_commands[OUTBASE+5] = (0xFF - 0x02) & rngmask;
this_usbduxfastsub->dux_commands[LENBASE + 6] = 1; udfs->dux_commands[LOGBASE+5] = 0;
this_usbduxfastsub->dux_commands[OPBASE + 6] = 0;
this_usbduxfastsub->dux_commands[OUTBASE + 6] = 0xFF & rngmask; udfs->dux_commands[LENBASE+6] = 1;
this_usbduxfastsub->dux_commands[LOGBASE + 6] = 0; udfs->dux_commands[OPBASE+6] = 0;
udfs->dux_commands[OUTBASE+6] = 0xFF & rngmask;
udfs->dux_commands[LOGBASE+6] = 0;
case 16: case 16:
if (CR_RANGE(cmd->chanlist[0]) > 0) if (CR_RANGE(cmd->chanlist[0]) > 0)
rngmask = 0xff - 0x04; rngmask = 0xff - 0x04;
else else
rngmask = 0xff; rngmask = 0xff;
if (cmd->start_src == TRIG_EXT) { // we loop here until ready has been set
this_usbduxfastsub->dux_commands[LENBASE + 0] = 0x01; // branch back to state 0 if (cmd->start_src == TRIG_EXT) {
this_usbduxfastsub->dux_commands[OPBASE + 0] = 0x01; // deceision state w/o data /*
this_usbduxfastsub->dux_commands[OUTBASE + 0] = (0xFF - 0x02) & rngmask; // reset * we loop here until ready has been set
this_usbduxfastsub->dux_commands[LOGBASE + 0] = 0x00; // RDY0 = 0 */
} else { // we just proceed to state 1
this_usbduxfastsub->dux_commands[LENBASE + 0] = 255; // 30us reset pulse /* branch back to state 0 */
this_usbduxfastsub->dux_commands[OPBASE + 0] = 0; udfs->dux_commands[LENBASE+0] = 0x01;
this_usbduxfastsub->dux_commands[OUTBASE + 0] = (0xFF - 0x02) & rngmask; // reset /* deceision state w/o data */
this_usbduxfastsub->dux_commands[LOGBASE + 0] = 0; udfs->dux_commands[OPBASE+0] = 0x01;
/* reset */
udfs->dux_commands[OUTBASE+0] = (0xFF-0x02) & rngmask;
/* RDY0 = 0 */
udfs->dux_commands[LOGBASE+0] = 0x00;
} else {
/*
* we just proceed to state 1
*/
/* 30us reset pulse */
udfs->dux_commands[LENBASE+0] = 255;
udfs->dux_commands[OPBASE+0] = 0;
/* reset */
udfs->dux_commands[OUTBASE+0] = (0xFF-0x02) & rngmask;
udfs->dux_commands[LOGBASE+0] = 0;
} }
// commit data to the FIFO /* commit data to the FIFO */
this_usbduxfastsub->dux_commands[LENBASE + 1] = 1; udfs->dux_commands[LENBASE+1] = 1;
this_usbduxfastsub->dux_commands[OPBASE + 1] = 0x02; // data /* data */
this_usbduxfastsub->dux_commands[OUTBASE + 1] = 0xFF & rngmask; udfs->dux_commands[OPBASE+1] = 0x02;
this_usbduxfastsub->dux_commands[LOGBASE + 1] = 0; udfs->dux_commands[OUTBASE+1] = 0xFF & rngmask;
udfs->dux_commands[LOGBASE+1] = 0;
// we have 2 states with duration 1 /* we have 2 states with duration 1 */
steps = steps - 2; steps = steps - 2;
// do the first part of the delay /* do the first part of the delay */
this_usbduxfastsub->dux_commands[LENBASE + 2] = steps / 2; udfs->dux_commands[LENBASE+2] = steps / 2;
this_usbduxfastsub->dux_commands[OPBASE + 2] = 0; udfs->dux_commands[OPBASE+2] = 0;
this_usbduxfastsub->dux_commands[OUTBASE + 2] = 0xFE & rngmask; udfs->dux_commands[OUTBASE+2] = 0xFE & rngmask;
this_usbduxfastsub->dux_commands[LOGBASE + 2] = 0; udfs->dux_commands[LOGBASE+2] = 0;
// and the second part /* and the second part */
this_usbduxfastsub->dux_commands[LENBASE + 3] = udfs->dux_commands[LENBASE+3] = steps - steps / 2;
steps - steps / 2; udfs->dux_commands[OPBASE+3] = 0;
this_usbduxfastsub->dux_commands[OPBASE + 3] = 0; udfs->dux_commands[OUTBASE+3] = 0xFF & rngmask;
this_usbduxfastsub->dux_commands[OUTBASE + 3] = 0xFF & rngmask; udfs->dux_commands[LOGBASE+3] = 0;
this_usbduxfastsub->dux_commands[LOGBASE + 3] = 0;
/* branch back to state 1 */
this_usbduxfastsub->dux_commands[LENBASE + 4] = 0x09; // branch back to state 1 udfs->dux_commands[LENBASE+4] = 0x09;
this_usbduxfastsub->dux_commands[OPBASE + 4] = 0x01; // deceision state w/o data /* deceision state w/o data */
this_usbduxfastsub->dux_commands[OUTBASE + 4] = 0xFF & rngmask; udfs->dux_commands[OPBASE+4] = 0x01;
this_usbduxfastsub->dux_commands[LOGBASE + 4] = 0xFF; // doesn't matter udfs->dux_commands[OUTBASE+4] = 0xFF & rngmask;
/* doesn't matter */
udfs->dux_commands[LOGBASE+4] = 0xFF;
break; break;
default: default:
printk("comedi %d: unsupported combination of channels\n", printk(KERN_ERR "comedi %d: unsupported combination of "
dev->minor); "channels\n", dev->minor);
up(&this_usbduxfastsub->sem); up(&udfs->sem);
return -EFAULT; return -EFAULT;
} }
#ifdef CONFIG_COMEDI_DEBUG #ifdef CONFIG_COMEDI_DEBUG
printk("comedi %d: sending commands to the usb device\n", dev->minor); printk(KERN_DEBUG "comedi %d: sending commands to the usb device\n",
dev->minor);
#endif #endif
// 0 means that the AD commands are sent /* 0 means that the AD commands are sent */
result = send_dux_commands(this_usbduxfastsub, SENDADCOMMANDS); result = send_dux_commands(udfs, SENDADCOMMANDS);
if (result < 0) { if (result < 0) {
printk("comedi%d: adc command could not be submitted. Aborting...\n", dev->minor); printk(KERN_ERR "comedi%d: adc command could not be submitted."
up(&this_usbduxfastsub->sem); "Aborting...\n", dev->minor);
up(&udfs->sem);
return result; return result;
} }
if (cmd->stop_src == TRIG_COUNT) { if (cmd->stop_src == TRIG_COUNT) {
this_usbduxfastsub->ai_sample_count = udfs->ai_sample_count = cmd->stop_arg * cmd->scan_end_arg;
(cmd->stop_arg) * (cmd->scan_end_arg); if (udfs->ai_sample_count < 1) {
if (usbduxfastsub->ai_sample_count < 1) { printk(KERN_ERR "comedi%d: "
printk("comedi%d: (cmd->stop_arg)*(cmd->scan_end_arg)<1, aborting.\n", dev->minor); "(cmd->stop_arg)*(cmd->scan_end_arg)<1, "
up(&this_usbduxfastsub->sem); "aborting.\n", dev->minor);
up(&udfs->sem);
return -EFAULT; return -EFAULT;
} }
this_usbduxfastsub->ai_continous = 0; udfs->ai_continous = 0;
} else { } else {
// continous aquisition /* continous aquisition */
this_usbduxfastsub->ai_continous = 1; udfs->ai_continous = 1;
this_usbduxfastsub->ai_sample_count = 0; udfs->ai_sample_count = 0;
} }
if ((cmd->start_src == TRIG_NOW) || (cmd->start_src == TRIG_EXT)) { if ((cmd->start_src == TRIG_NOW) || (cmd->start_src == TRIG_EXT)) {
// enable this acquisition operation /* enable this acquisition operation */
this_usbduxfastsub->ai_cmd_running = 1; udfs->ai_cmd_running = 1;
ret = usbduxfastsub_submit_InURBs(this_usbduxfastsub); ret = usbduxfastsub_submit_InURBs(udfs);
if (ret < 0) { if (ret < 0) {
this_usbduxfastsub->ai_cmd_running = 0; udfs->ai_cmd_running = 0;
// fixme: unlink here?? /* fixme: unlink here?? */
up(&this_usbduxfastsub->sem); up(&udfs->sem);
return ret; return ret;
} }
s->async->inttrig = NULL; s->async->inttrig = NULL;
} else { } else {
/* TRIG_INT */ /*
// don't enable the acquision operation * TRIG_INT
// wait for an internal signal * don't enable the acquision operation
* wait for an internal signal
*/
s->async->inttrig = usbduxfast_ai_inttrig; s->async->inttrig = usbduxfast_ai_inttrig;
} }
up(&this_usbduxfastsub->sem); up(&udfs->sem);
return 0; return 0;
} }
/* Mode 0 is used to get a single conversion on demand */ /*
static int usbduxfast_ai_insn_read(comedi_device * dev, * Mode 0 is used to get a single conversion on demand.
comedi_subdevice * s, comedi_insn * insn, lsampl_t * data) */
static int usbduxfast_ai_insn_read(comedi_device *dev,
comedi_subdevice *s, comedi_insn *insn, lsampl_t *data)
{ {
int i, j, n, actual_length; int i, j, n, actual_length;
int chan, range, rngmask; int chan, range, rngmask;
int err; int err;
usbduxfastsub_t *usbduxfastsub = dev->private; struct usbduxfastsub_s *udfs;
if (!usbduxfastsub) { udfs = dev->private;
printk("comedi%d: ai_insn_read: no usb dev.\n", dev->minor); if (!udfs) {
printk(KERN_ERR "comedi%d: ai_insn_read: no usb dev.\n",
dev->minor);
return -ENODEV; return -ENODEV;
} }
#ifdef CONFIG_COMEDI_DEBUG #ifdef CONFIG_COMEDI_DEBUG
printk("comedi%d: ai_insn_read, insn->n=%d, insn->subdev=%d\n", printk(KERN_DEBUG "comedi%d: ai_insn_read, insn->n=%d, "
dev->minor, insn->n, insn->subdev); "insn->subdev=%d\n", dev->minor, insn->n, insn->subdev);
#endif #endif
down(&usbduxfastsub->sem); down(&udfs->sem);
if (!(usbduxfastsub->probed)) { if (!udfs->probed) {
up(&usbduxfastsub->sem); up(&udfs->sem);
return -ENODEV; return -ENODEV;
} }
if (usbduxfastsub->ai_cmd_running) { if (udfs->ai_cmd_running) {
printk("comedi%d: ai_insn_read not possible. Async Command is running.\n", dev->minor); printk(KERN_ERR "comedi%d: ai_insn_read not possible. Async "
up(&usbduxfastsub->sem); "Command is running.\n", dev->minor);
up(&udfs->sem);
return -EBUSY; return -EBUSY;
} }
// sample one channel /* sample one channel */
chan = CR_CHAN(insn->chanspec); chan = CR_CHAN(insn->chanspec);
range = CR_RANGE(insn->chanspec); range = CR_RANGE(insn->chanspec);
// set command for the first channel /* set command for the first channel */
if (range > 0) if (range > 0)
rngmask = 0xff - 0x04; rngmask = 0xff - 0x04;
else else
rngmask = 0xff; rngmask = 0xff;
// commit data to the FIFO
usbduxfastsub->dux_commands[LENBASE + 0] = 1; /* commit data to the FIFO */
usbduxfastsub->dux_commands[OPBASE + 0] = 0x02; // data udfs->dux_commands[LENBASE+0] = 1;
usbduxfastsub->dux_commands[OUTBASE + 0] = 0xFF & rngmask; /* data */
usbduxfastsub->dux_commands[LOGBASE + 0] = 0; udfs->dux_commands[OPBASE+0] = 0x02;
udfs->dux_commands[OUTBASE+0] = 0xFF & rngmask;
// do the first part of the delay udfs->dux_commands[LOGBASE+0] = 0;
usbduxfastsub->dux_commands[LENBASE + 1] = 12;
usbduxfastsub->dux_commands[OPBASE + 1] = 0; /* do the first part of the delay */
usbduxfastsub->dux_commands[OUTBASE + 1] = 0xFE & rngmask; udfs->dux_commands[LENBASE+1] = 12;
usbduxfastsub->dux_commands[LOGBASE + 1] = 0; udfs->dux_commands[OPBASE+1] = 0;
udfs->dux_commands[OUTBASE+1] = 0xFE & rngmask;
usbduxfastsub->dux_commands[LENBASE + 2] = 1; udfs->dux_commands[LOGBASE+1] = 0;
usbduxfastsub->dux_commands[OPBASE + 2] = 0;
usbduxfastsub->dux_commands[OUTBASE + 2] = 0xFE & rngmask; udfs->dux_commands[LENBASE+2] = 1;
usbduxfastsub->dux_commands[LOGBASE + 2] = 0; udfs->dux_commands[OPBASE+2] = 0;
udfs->dux_commands[OUTBASE+2] = 0xFE & rngmask;
usbduxfastsub->dux_commands[LENBASE + 3] = 1; udfs->dux_commands[LOGBASE+2] = 0;
usbduxfastsub->dux_commands[OPBASE + 3] = 0;
usbduxfastsub->dux_commands[OUTBASE + 3] = 0xFE & rngmask; udfs->dux_commands[LENBASE+3] = 1;
usbduxfastsub->dux_commands[LOGBASE + 3] = 0; udfs->dux_commands[OPBASE+3] = 0;
udfs->dux_commands[OUTBASE+3] = 0xFE & rngmask;
usbduxfastsub->dux_commands[LENBASE + 4] = 1; udfs->dux_commands[LOGBASE+3] = 0;
usbduxfastsub->dux_commands[OPBASE + 4] = 0;
usbduxfastsub->dux_commands[OUTBASE + 4] = 0xFE & rngmask; udfs->dux_commands[LENBASE+4] = 1;
usbduxfastsub->dux_commands[LOGBASE + 4] = 0; udfs->dux_commands[OPBASE+4] = 0;
udfs->dux_commands[OUTBASE+4] = 0xFE & rngmask;
// second part udfs->dux_commands[LOGBASE+4] = 0;
usbduxfastsub->dux_commands[LENBASE + 5] = 12;
usbduxfastsub->dux_commands[OPBASE + 5] = 0; /* second part */
usbduxfastsub->dux_commands[OUTBASE + 5] = 0xFF & rngmask; udfs->dux_commands[LENBASE+5] = 12;
usbduxfastsub->dux_commands[LOGBASE + 5] = 0; udfs->dux_commands[OPBASE+5] = 0;
udfs->dux_commands[OUTBASE+5] = 0xFF & rngmask;
usbduxfastsub->dux_commands[LENBASE + 6] = 1; udfs->dux_commands[LOGBASE+5] = 0;
usbduxfastsub->dux_commands[OPBASE + 6] = 0;
usbduxfastsub->dux_commands[OUTBASE + 6] = 0xFF & rngmask; udfs->dux_commands[LENBASE+6] = 1;
usbduxfastsub->dux_commands[LOGBASE + 0] = 0; udfs->dux_commands[OPBASE+6] = 0;
udfs->dux_commands[OUTBASE+6] = 0xFF & rngmask;
udfs->dux_commands[LOGBASE+0] = 0;
#ifdef CONFIG_COMEDI_DEBUG #ifdef CONFIG_COMEDI_DEBUG
printk("comedi %d: sending commands to the usb device\n", dev->minor); printk(KERN_DEBUG "comedi %d: sending commands to the usb device\n",
dev->minor);
#endif #endif
// 0 means that the AD commands are sent /* 0 means that the AD commands are sent */
err = send_dux_commands(usbduxfastsub, SENDADCOMMANDS); err = send_dux_commands(udfs, SENDADCOMMANDS);
if (err < 0) { if (err < 0) {
printk("comedi%d: adc command could not be submitted. Aborting...\n", dev->minor); printk(KERN_ERR "comedi%d: adc command could not be submitted."
up(&usbduxfastsub->sem); "Aborting...\n", dev->minor);
up(&udfs->sem);
return err; return err;
} }
#ifdef CONFIG_COMEDI_DEBUG #ifdef CONFIG_COMEDI_DEBUG
printk("comedi%d: usbduxfast: submitting in-urb: 0x%p,0x%p\n", printk(KERN_DEBUG "comedi%d: usbduxfast: submitting in-urb: "
usbduxfastsub->comedidev->minor, "0x%p,0x%p\n", udfs->comedidev->minor, udfs->urbIn->context,
usbduxfastsub->urbIn->context, udfs->urbIn->dev);
usbduxfastsub->urbIn->dev);
#endif #endif
for (i = 0; i < PACKETS_TO_IGNORE; i++) { for (i = 0; i < PACKETS_TO_IGNORE; i++) {
err = usb_bulk_msg(usbduxfastsub->usbdev, err = usb_bulk_msg(udfs->usbdev,
usb_rcvbulkpipe(usbduxfastsub->usbdev, usb_rcvbulkpipe(udfs->usbdev, BULKINEP),
BULKINEP), udfs->transfer_buffer, SIZEINBUF,
usbduxfastsub->transfer_buffer, SIZEINBUF,
&actual_length, 10000); &actual_length, 10000);
if (err < 0) { if (err < 0) {
printk("comedi%d: insn timeout. No data.\n", printk(KERN_ERR "comedi%d: insn timeout. No data.\n",
dev->minor); dev->minor);
up(&usbduxfastsub->sem); up(&udfs->sem);
return err; return err;
} }
} }
// data points /* data points */
for (i = 0; i < insn->n;) { for (i = 0; i < insn->n;) {
err = usb_bulk_msg(usbduxfastsub->usbdev, err = usb_bulk_msg(udfs->usbdev,
usb_rcvbulkpipe(usbduxfastsub->usbdev, usb_rcvbulkpipe(udfs->usbdev, BULKINEP),
BULKINEP), udfs->transfer_buffer, SIZEINBUF,
usbduxfastsub->transfer_buffer, SIZEINBUF,
&actual_length, 10000); &actual_length, 10000);
if (err < 0) { if (err < 0) {
printk("comedi%d: insn data error: %d\n", printk(KERN_ERR "comedi%d: insn data error: %d\n",
dev->minor, err); dev->minor, err);
up(&usbduxfastsub->sem); up(&udfs->sem);
return err; return err;
} }
n = actual_length / sizeof(uint16_t); n = actual_length / sizeof(uint16_t);
if ((n % 16) != 0) { if ((n % 16) != 0) {
printk("comedi%d: insn data packet corrupted.\n", printk(KERN_ERR "comedi%d: insn data packet "
dev->minor); "corrupted.\n", dev->minor);
up(&usbduxfastsub->sem); up(&udfs->sem);
return -EINVAL; return -EINVAL;
} }
for (j = chan; (j < n) && (i < insn->n); j = j + 16) { for (j = chan; (j < n) && (i < insn->n); j = j + 16) {
data[i] = data[i] = ((uint16_t *) (udfs->transfer_buffer))[j];
((uint16_t *) (usbduxfastsub->
transfer_buffer))[j];
i++; i++;
} }
} }
up(&usbduxfastsub->sem); up(&udfs->sem);
return i; return i;
} }
static unsigned hex2unsigned(char *h) static unsigned hex2unsigned(char *h)
{ {
unsigned hi, lo; unsigned hi, lo;
if (h[0] > '9') {
if (h[0] > '9')
hi = h[0] - 'A' + 0x0a; hi = h[0] - 'A' + 0x0a;
} else { else
hi = h[0] - '0'; hi = h[0] - '0';
}
if (h[1] > '9') { if (h[1] > '9')
lo = h[1] - 'A' + 0x0a; lo = h[1] - 'A' + 0x0a;
} else { else
lo = h[1] - '0'; lo = h[1] - '0';
}
return hi * 0x10 + lo; return hi * 0x10 + lo;
} }
// for FX2 /* for FX2 */
#define FIRMWARE_MAX_LEN 0x2000 #define FIRMWARE_MAX_LEN 0x2000
// taken from David Brownell's fxload and adjusted for this driver /*
static int read_firmware(usbduxfastsub_t * usbduxfastsub, void *firmwarePtr, * taken from David Brownell's fxload and adjusted for this driver
*/
static int read_firmware(struct usbduxfastsub_s *udfs, void *firmwarePtr,
long size) long size)
{ {
int i = 0; int i = 0;
...@@ -1289,7 +1407,8 @@ static int read_firmware(usbduxfastsub_t * usbduxfastsub, void *firmwarePtr, ...@@ -1289,7 +1407,8 @@ static int read_firmware(usbduxfastsub_t * usbduxfastsub, void *firmwarePtr,
firmwareBinary = kmalloc(FIRMWARE_MAX_LEN, GFP_KERNEL); firmwareBinary = kmalloc(FIRMWARE_MAX_LEN, GFP_KERNEL);
if (!firmwareBinary) { if (!firmwareBinary) {
printk("comedi_: usbduxfast: mem alloc for firmware failed\n"); printk(KERN_ERR "comedi_: usbduxfast: mem alloc for firmware "
" failed\n");
return -ENOMEM; return -ENOMEM;
} }
...@@ -1300,32 +1419,36 @@ static int read_firmware(usbduxfastsub_t * usbduxfastsub, void *firmwarePtr, ...@@ -1300,32 +1419,36 @@ static int read_firmware(usbduxfastsub_t * usbduxfastsub, void *firmwarePtr,
int idx, off; int idx, off;
int j = 0; int j = 0;
// get one line /* get one line */
while ((i < size) && (fp[i] != 13) && (fp[i] != 10)) { while ((i < size) && (fp[i] != 13) && (fp[i] != 10)) {
buf[j] = fp[i]; buf[j] = fp[i];
i++; i++;
j++; j++;
if (j >= sizeof(buf)) { if (j >= sizeof(buf)) {
printk("comedi_: usbduxfast: bogus firmware file!\n"); printk(KERN_ERR "comedi_: usbduxfast: bogus "
"firmware file!\n");
kfree(firmwareBinary); kfree(firmwareBinary);
return -1; return -1;
} }
} }
// get rid of LF/CR/... /* get rid of LF/CR/... */
while ((i < size) && ((fp[i] == 13) || (fp[i] == 10) while ((i < size) && ((fp[i] == 13) || (fp[i] == 10)
|| (fp[i] == 0))) { || (fp[i] == 0)))
i++; i++;
}
buf[j] = 0; buf[j] = 0;
//printk("comedi_: buf=%s\n",buf); /* printk("comedi_: buf=%s\n",buf); */
/* EXTENSION: "# comment-till-end-of-line", for copyrights etc */ /*
* EXTENSION: "# comment-till-end-of-line",
* for copyrights etc
*/
if (buf[0] == '#') if (buf[0] == '#')
continue; continue;
if (buf[0] != ':') { if (buf[0] != ':') {
printk("comedi_: usbduxfast: upload: not an ihex record: %s", buf); printk(KERN_ERR "comedi_: usbduxfast: upload: not an "
"ihex record: %s", buf);
kfree(firmwareBinary); kfree(firmwareBinary);
return -EFAULT; return -EFAULT;
} }
...@@ -1336,86 +1459,88 @@ static int read_firmware(usbduxfastsub_t * usbduxfastsub, void *firmwarePtr, ...@@ -1336,86 +1459,88 @@ static int read_firmware(usbduxfastsub_t * usbduxfastsub, void *firmwarePtr,
/* Read the target offset */ /* Read the target offset */
off = (hex2unsigned(buf + 3) * 0x0100) + hex2unsigned(buf + 5); off = (hex2unsigned(buf + 3) * 0x0100) + hex2unsigned(buf + 5);
if ((off + len) > maxAddr) { if ((off + len) > maxAddr)
maxAddr = off + len; maxAddr = off + len;
}
if (maxAddr >= FIRMWARE_MAX_LEN) { if (maxAddr >= FIRMWARE_MAX_LEN) {
printk("comedi_: usbduxfast: firmware upload goes beyond FX2 RAM boundaries."); printk(KERN_ERR "comedi_: usbduxfast: firmware upload "
"goes beyond FX2 RAM boundaries.");
kfree(firmwareBinary); kfree(firmwareBinary);
return -EFAULT; return -EFAULT;
} }
//printk("comedi_: usbduxfast: off=%x, len=%x:",off,len); /* printk("comedi_: usbduxfast: off=%x, len=%x:",off,len); */
/* Read the record type */ /* Read the record type */
type = hex2unsigned(buf + 7); type = hex2unsigned(buf + 7);
/* If this is an EOF record, then make it so. */ /* If this is an EOF record, then make it so. */
if (type == 1) { if (type == 1)
break; break;
}
if (type != 0) { if (type != 0) {
printk("comedi_: usbduxfast: unsupported record type: %u\n", type); printk(KERN_ERR "comedi_: usbduxfast: unsupported "
"record type: %u\n", type);
kfree(firmwareBinary); kfree(firmwareBinary);
return -EFAULT; return -EFAULT;
} }
for (idx = 0, cp = buf + 9; idx < len; idx += 1, cp += 2) { for (idx = 0, cp = buf + 9; idx < len; idx += 1, cp += 2) {
firmwareBinary[idx + off] = hex2unsigned(cp); firmwareBinary[idx + off] = hex2unsigned(cp);
//printk("%02x ",firmwareBinary[idx+off]); /* printk("%02x ",firmwareBinary[idx+off]); */
} }
//printk("\n");
/* printk("\n"); */
if (i >= size) { if (i >= size) {
printk("comedi_: usbduxfast: unexpected end of hex file\n"); printk(KERN_ERR "comedi_: usbduxfast: unexpected end "
"of hex file\n");
break; break;
} }
} }
res = firmwareUpload(usbduxfastsub, firmwareBinary, maxAddr + 1); res = firmwareUpload(udfs, firmwareBinary, maxAddr + 1);
kfree(firmwareBinary); kfree(firmwareBinary);
return res; return res;
} }
static void tidy_up(usbduxfastsub_t * usbduxfastsub_tmp) static void tidy_up(struct usbduxfastsub_s *udfs)
{ {
#ifdef CONFIG_COMEDI_DEBUG #ifdef CONFIG_COMEDI_DEBUG
printk("comedi_: usbduxfast: tiding up\n"); printk(KERN_DEBUG "comedi_: usbduxfast: tiding up\n");
#endif #endif
if (!usbduxfastsub_tmp) {
if (!udfs)
return; return;
}
// shows the usb subsystem that the driver is down /* shows the usb subsystem that the driver is down */
if (usbduxfastsub_tmp->interface) { if (udfs->interface)
usb_set_intfdata(usbduxfastsub_tmp->interface, NULL); usb_set_intfdata(udfs->interface, NULL);
}
usbduxfastsub_tmp->probed = 0; udfs->probed = 0;
if (usbduxfastsub_tmp->urbIn) { if (udfs->urbIn) {
// waits until a running transfer is over /* waits until a running transfer is over */
usb_kill_urb(usbduxfastsub_tmp->urbIn); usb_kill_urb(udfs->urbIn);
if (usbduxfastsub_tmp->transfer_buffer) {
kfree(usbduxfastsub_tmp->transfer_buffer); kfree(udfs->transfer_buffer);
usbduxfastsub_tmp->transfer_buffer = NULL; udfs->transfer_buffer = NULL;
}
usb_free_urb(usbduxfastsub_tmp->urbIn); usb_free_urb(udfs->urbIn);
usbduxfastsub_tmp->urbIn = NULL; udfs->urbIn = NULL;
}
if (usbduxfastsub_tmp->insnBuffer) {
kfree(usbduxfastsub_tmp->insnBuffer);
usbduxfastsub_tmp->insnBuffer = NULL;
}
if (usbduxfastsub_tmp->dux_commands) {
kfree(usbduxfastsub_tmp->dux_commands);
usbduxfastsub_tmp->dux_commands = NULL;
} }
usbduxfastsub_tmp->ai_cmd_running = 0;
kfree(udfs->insnBuffer);
udfs->insnBuffer = NULL;
kfree(udfs->dux_commands);
udfs->dux_commands = NULL;
udfs->ai_cmd_running = 0;
} }
// allocate memory for the urbs and initialise them /*
* allocate memory for the urbs and initialise them
*/
static int usbduxfastsub_probe(struct usb_interface *uinterf, static int usbduxfastsub_probe(struct usb_interface *uinterf,
const struct usb_device_id *id) const struct usb_device_id *id)
{ {
...@@ -1424,122 +1549,137 @@ static int usbduxfastsub_probe(struct usb_interface *uinterf, ...@@ -1424,122 +1549,137 @@ static int usbduxfastsub_probe(struct usb_interface *uinterf,
int index; int index;
if (udev->speed != USB_SPEED_HIGH) { if (udev->speed != USB_SPEED_HIGH) {
printk("comedi_: usbduxfast_: This driver needs USB 2.0 to operate. Aborting...\n"); printk(KERN_ERR "comedi_: usbduxfast_: This driver needs"
"USB 2.0 to operate. Aborting...\n");
return -ENODEV; return -ENODEV;
} }
#ifdef CONFIG_COMEDI_DEBUG #ifdef CONFIG_COMEDI_DEBUG
printk("comedi_: usbduxfast_: finding a free structure for the usb-device\n"); printk(KERN_DEBUG "comedi_: usbduxfast_: finding a free structure for "
"the usb-device\n");
#endif #endif
down(&start_stop_sem); down(&start_stop_sem);
// look for a free place in the usbduxfast array /* look for a free place in the usbduxfast array */
index = -1; index = -1;
for (i = 0; i < NUMUSBDUXFAST; i++) { for (i = 0; i < NUMUSBDUXFAST; i++) {
if (!(usbduxfastsub[i].probed)) { if (!usbduxfastsub[i].probed) {
index = i; index = i;
break; break;
} }
} }
// no more space /* no more space */
if (index == -1) { if (index == -1) {
printk("Too many usbduxfast-devices connected.\n"); printk(KERN_ERR "Too many usbduxfast-devices connected.\n");
up(&start_stop_sem); up(&start_stop_sem);
return -EMFILE; return -EMFILE;
} }
#ifdef CONFIG_COMEDI_DEBUG #ifdef CONFIG_COMEDI_DEBUG
printk("comedi_: usbduxfast: usbduxfastsub[%d] is ready to connect to comedi.\n", index); printk(KERN_DEBUG "comedi_: usbduxfast: usbduxfastsub[%d] is ready to "
"connect to comedi.\n", index);
#endif #endif
init_MUTEX(&(usbduxfastsub[index].sem)); init_MUTEX(&(usbduxfastsub[index].sem));
// save a pointer to the usb device /* save a pointer to the usb device */
usbduxfastsub[index].usbdev = udev; usbduxfastsub[index].usbdev = udev;
// save the interface itself /* save the interface itself */
usbduxfastsub[index].interface = uinterf; usbduxfastsub[index].interface = uinterf;
// get the interface number from the interface /* get the interface number from the interface */
usbduxfastsub[index].ifnum = uinterf->altsetting->desc.bInterfaceNumber; usbduxfastsub[index].ifnum = uinterf->altsetting->desc.bInterfaceNumber;
// hand the private data over to the usb subsystem /*
// will be needed for disconnect * hand the private data over to the usb subsystem
* will be needed for disconnect
*/
usb_set_intfdata(uinterf, &(usbduxfastsub[index])); usb_set_intfdata(uinterf, &(usbduxfastsub[index]));
#ifdef CONFIG_COMEDI_DEBUG #ifdef CONFIG_COMEDI_DEBUG
printk("comedi_: usbduxfast: ifnum=%d\n", usbduxfastsub[index].ifnum); printk(KERN_DEBUG "comedi_: usbduxfast: ifnum=%d\n",
usbduxfastsub[index].ifnum);
#endif #endif
// create space for the commands going to the usb device /* create space for the commands going to the usb device */
usbduxfastsub[index].dux_commands = kmalloc(SIZEOFDUXBUFFER, usbduxfastsub[index].dux_commands = kmalloc(SIZEOFDUXBUFFER,
GFP_KERNEL); GFP_KERNEL);
if (!usbduxfastsub[index].dux_commands) { if (!usbduxfastsub[index].dux_commands) {
printk("comedi_: usbduxfast: error alloc space for dac commands\n"); printk(KERN_ERR "comedi_: usbduxfast: error alloc space for "
"dac commands\n");
tidy_up(&(usbduxfastsub[index])); tidy_up(&(usbduxfastsub[index]));
up(&start_stop_sem); up(&start_stop_sem);
return -ENOMEM; return -ENOMEM;
} }
// create space of the instruction buffer /* create space of the instruction buffer */
usbduxfastsub[index].insnBuffer = kmalloc(SIZEINSNBUF, GFP_KERNEL); usbduxfastsub[index].insnBuffer = kmalloc(SIZEINSNBUF, GFP_KERNEL);
if (!(usbduxfastsub[index].insnBuffer)) { if (!usbduxfastsub[index].insnBuffer) {
printk("comedi_: usbduxfast: could not alloc space for insnBuffer\n"); printk(KERN_ERR "comedi_: usbduxfast: could not alloc space "
"for insnBuffer\n");
tidy_up(&(usbduxfastsub[index])); tidy_up(&(usbduxfastsub[index]));
up(&start_stop_sem); up(&start_stop_sem);
return -ENOMEM; return -ENOMEM;
} }
// setting to alternate setting 1: enabling bulk ep /* setting to alternate setting 1: enabling bulk ep */
i = usb_set_interface(usbduxfastsub[index].usbdev, i = usb_set_interface(usbduxfastsub[index].usbdev,
usbduxfastsub[index].ifnum, 1); usbduxfastsub[index].ifnum, 1);
if (i < 0) { if (i < 0) {
printk("comedi_: usbduxfast%d: could not switch to alternate setting 1.\n", index); printk(KERN_ERR "comedi_: usbduxfast%d: could not switch to "
"alternate setting 1.\n", index);
tidy_up(&(usbduxfastsub[index])); tidy_up(&(usbduxfastsub[index]));
up(&start_stop_sem); up(&start_stop_sem);
return -ENODEV; return -ENODEV;
} }
usbduxfastsub[index].urbIn = usb_alloc_urb(0, GFP_KERNEL); usbduxfastsub[index].urbIn = usb_alloc_urb(0, GFP_KERNEL);
if (usbduxfastsub[index].urbIn == NULL) { if (!usbduxfastsub[index].urbIn) {
printk("comedi_: usbduxfast%d: Could not alloc. urb\n", index); printk(KERN_ERR "comedi_: usbduxfast%d: Could not alloc."
"urb\n", index);
tidy_up(&(usbduxfastsub[index])); tidy_up(&(usbduxfastsub[index]));
up(&start_stop_sem); up(&start_stop_sem);
return -ENOMEM; return -ENOMEM;
} }
usbduxfastsub[index].transfer_buffer = kmalloc(SIZEINBUF, GFP_KERNEL); usbduxfastsub[index].transfer_buffer = kmalloc(SIZEINBUF, GFP_KERNEL);
if (!(usbduxfastsub[index].transfer_buffer)) { if (!usbduxfastsub[index].transfer_buffer) {
printk("comedi_: usbduxfast%d: could not alloc. transb.\n", printk(KERN_ERR "comedi_: usbduxfast%d: could not alloc. "
index); "transb.\n", index);
tidy_up(&(usbduxfastsub[index])); tidy_up(&(usbduxfastsub[index]));
up(&start_stop_sem); up(&start_stop_sem);
return -ENOMEM; return -ENOMEM;
} }
// we've reached the bottom of the function /* we've reached the bottom of the function */
usbduxfastsub[index].probed = 1; usbduxfastsub[index].probed = 1;
up(&start_stop_sem); up(&start_stop_sem);
printk("comedi_: usbduxfast%d has been successfully initialized.\n", printk(KERN_INFO "comedi_: usbduxfast%d has been successfully "
index); "initialized.\n", index);
// success /* success */
return 0; return 0;
} }
static void usbduxfastsub_disconnect(struct usb_interface *intf) static void usbduxfastsub_disconnect(struct usb_interface *intf)
{ {
usbduxfastsub_t *usbduxfastsub_tmp = usb_get_intfdata(intf); struct usbduxfastsub_s *udfs = usb_get_intfdata(intf);
struct usb_device *udev = interface_to_usbdev(intf); struct usb_device *udev = interface_to_usbdev(intf);
if (!usbduxfastsub_tmp) { if (!udfs) {
printk("comedi_: usbduxfast: disconnect called with null pointer.\n"); printk(KERN_ERR "comedi_: usbduxfast: disconnect called with "
"null pointer.\n");
return; return;
} }
if (usbduxfastsub_tmp->usbdev != udev) { if (udfs->usbdev != udev) {
printk("comedi_: usbduxfast: BUG! called with wrong ptr!!!\n"); printk(KERN_ERR "comedi_: usbduxfast: BUG! called with wrong "
"ptr!!!\n");
return; return;
} }
down(&start_stop_sem); down(&start_stop_sem);
down(&usbduxfastsub_tmp->sem); down(&udfs->sem);
tidy_up(usbduxfastsub_tmp); tidy_up(udfs);
up(&usbduxfastsub_tmp->sem); up(&udfs->sem);
up(&start_stop_sem); up(&start_stop_sem);
#ifdef CONFIG_COMEDI_DEBUG #ifdef CONFIG_COMEDI_DEBUG
printk("comedi_: usbduxfast: disconnected from the usb\n"); printk(KERN_DEBUG "comedi_: usbduxfast: disconnected from the usb\n");
#endif #endif
} }
// is called when comedi-config is called /*
static int usbduxfast_attach(comedi_device * dev, comedi_devconfig * it) * is called when comedi-config is called
*/
static int usbduxfast_attach(comedi_device *dev, comedi_devconfig *it)
{ {
int ret; int ret;
int index; int index;
...@@ -1548,26 +1688,31 @@ static int usbduxfast_attach(comedi_device * dev, comedi_devconfig * it) ...@@ -1548,26 +1688,31 @@ static int usbduxfast_attach(comedi_device * dev, comedi_devconfig * it)
dev->private = NULL; dev->private = NULL;
down(&start_stop_sem); down(&start_stop_sem);
// find a valid device which has been detected by the probe function of the usb /*
* find a valid device which has been detected by the
* probe function of the usb
*/
index = -1; index = -1;
for (i = 0; i < NUMUSBDUXFAST; i++) { for (i = 0; i < NUMUSBDUXFAST; i++) {
if ((usbduxfastsub[i].probed) && (!usbduxfastsub[i].attached)) { if (usbduxfastsub[i].probed && !usbduxfastsub[i].attached) {
index = i; index = i;
break; break;
} }
} }
if (index < 0) { if (index < 0) {
printk("comedi%d: usbduxfast: error: attach failed, no usbduxfast devs connected to the usb bus.\n", dev->minor); printk(KERN_ERR "comedi%d: usbduxfast: error: attach failed, "
"no usbduxfast devs connected to the usb bus.\n",
dev->minor);
up(&start_stop_sem); up(&start_stop_sem);
return -ENODEV; return -ENODEV;
} }
down(&(usbduxfastsub[index].sem)); down(&(usbduxfastsub[index].sem));
// pointer back to the corresponding comedi device /* pointer back to the corresponding comedi device */
usbduxfastsub[index].comedidev = dev; usbduxfastsub[index].comedidev = dev;
// trying to upload the firmware into the chip /* trying to upload the firmware into the chip */
if (comedi_aux_data(it->options, 0) && if (comedi_aux_data(it->options, 0) &&
it->options[COMEDI_DEVCONF_AUX_DATA_LENGTH]) { it->options[COMEDI_DEVCONF_AUX_DATA_LENGTH]) {
read_firmware(usbduxfastsub, read_firmware(usbduxfastsub,
...@@ -1580,109 +1725,120 @@ static int usbduxfast_attach(comedi_device * dev, comedi_devconfig * it) ...@@ -1580,109 +1725,120 @@ static int usbduxfast_attach(comedi_device * dev, comedi_devconfig * it)
/* set number of subdevices */ /* set number of subdevices */
dev->n_subdevices = N_SUBDEVICES; dev->n_subdevices = N_SUBDEVICES;
// allocate space for the subdevices /* allocate space for the subdevices */
if ((ret = alloc_subdevices(dev, N_SUBDEVICES)) < 0) { ret = alloc_subdevices(dev, N_SUBDEVICES);
printk("comedi%d: usbduxfast: error alloc space for subdev\n", if (ret < 0) {
dev->minor); printk(KERN_ERR "comedi%d: usbduxfast: error alloc space for "
"subdev\n", dev->minor);
up(&start_stop_sem); up(&start_stop_sem);
return ret; return ret;
} }
printk("comedi%d: usbduxfast: usb-device %d is attached to comedi.\n", printk(KERN_INFO "comedi%d: usbduxfast: usb-device %d is attached to "
dev->minor, index); "comedi.\n", dev->minor, index);
// private structure is also simply the usb-structure /* private structure is also simply the usb-structure */
dev->private = usbduxfastsub + index; dev->private = usbduxfastsub + index;
// the first subdevice is the A/D converter /* the first subdevice is the A/D converter */
s = dev->subdevices + SUBDEV_AD; s = dev->subdevices + SUBDEV_AD;
// the URBs get the comedi subdevice /*
// which is responsible for reading * the URBs get the comedi subdevice which is responsible for reading
// this is the subdevice which reads data * this is the subdevice which reads data
*/
dev->read_subdev = s; dev->read_subdev = s;
// the subdevice receives as private structure the /* the subdevice receives as private structure the usb-structure */
// usb-structure
s->private = NULL; s->private = NULL;
// analog input /* analog input */
s->type = COMEDI_SUBD_AI; s->type = COMEDI_SUBD_AI;
// readable and ref is to ground /* readable and ref is to ground */
s->subdev_flags = SDF_READABLE | SDF_GROUND | SDF_CMD_READ; s->subdev_flags = SDF_READABLE | SDF_GROUND | SDF_CMD_READ;
// 16 channels /* 16 channels */
s->n_chan = 16; s->n_chan = 16;
// length of the channellist /* length of the channellist */
s->len_chanlist = 16; s->len_chanlist = 16;
// callback functions /* callback functions */
s->insn_read = usbduxfast_ai_insn_read; s->insn_read = usbduxfast_ai_insn_read;
s->do_cmdtest = usbduxfast_ai_cmdtest; s->do_cmdtest = usbduxfast_ai_cmdtest;
s->do_cmd = usbduxfast_ai_cmd; s->do_cmd = usbduxfast_ai_cmd;
s->cancel = usbduxfast_ai_cancel; s->cancel = usbduxfast_ai_cancel;
// max value from the A/D converter (12bit+1 bit for overflow) /* max value from the A/D converter (12bit+1 bit for overflow) */
s->maxdata = 0x1000; s->maxdata = 0x1000;
// range table to convert to physical units /* range table to convert to physical units */
s->range_table = &range_usbduxfast_ai_range; s->range_table = &range_usbduxfast_ai_range;
// finally decide that it's attached /* finally decide that it's attached */
usbduxfastsub[index].attached = 1; usbduxfastsub[index].attached = 1;
up(&(usbduxfastsub[index].sem)); up(&(usbduxfastsub[index].sem));
up(&start_stop_sem); up(&start_stop_sem);
printk(KERN_INFO "comedi%d: successfully attached to usbduxfast.\n",
printk("comedi%d: successfully attached to usbduxfast.\n", dev->minor); dev->minor);
return 0; return 0;
} }
static int usbduxfast_detach(comedi_device * dev) static int usbduxfast_detach(comedi_device *dev)
{ {
usbduxfastsub_t *usbduxfastsub_tmp; struct usbduxfastsub_s *udfs;
if (!dev) { if (!dev) {
printk("comedi?: usbduxfast: detach without dev variable...\n"); printk(KERN_ERR "comedi?: usbduxfast: detach without dev "
"variable...\n");
return -EFAULT; return -EFAULT;
} }
#ifdef CONFIG_COMEDI_DEBUG #ifdef CONFIG_COMEDI_DEBUG
printk("comedi%d: usbduxfast: detach usb device\n", dev->minor); printk(KERN_DEBUG "comedi%d: usbduxfast: detach usb device\n",
dev->minor);
#endif #endif
usbduxfastsub_tmp = dev->private; udfs = dev->private;
if (!usbduxfastsub_tmp) { if (!udfs) {
printk("comedi?: usbduxfast: detach without ptr to usbduxfastsub[]\n"); printk(KERN_ERR "comedi?: usbduxfast: detach without ptr to "
"usbduxfastsub[]\n");
return -EFAULT; return -EFAULT;
} }
down(&usbduxfastsub_tmp->sem); down(&udfs->sem);
down(&start_stop_sem); down(&start_stop_sem);
// Don't allow detach to free the private structure /*
// It's one entry of of usbduxfastsub[] * Don't allow detach to free the private structure
* It's one entry of of usbduxfastsub[]
*/
dev->private = NULL; dev->private = NULL;
usbduxfastsub_tmp->attached = 0; udfs->attached = 0;
usbduxfastsub_tmp->comedidev = NULL; udfs->comedidev = NULL;
#ifdef CONFIG_COMEDI_DEBUG #ifdef CONFIG_COMEDI_DEBUG
printk("comedi%d: usbduxfast: detach: successfully removed\n", printk(KERN_DEBUG "comedi%d: usbduxfast: detach: successfully "
dev->minor); "removed\n", dev->minor);
#endif #endif
up(&start_stop_sem); up(&start_stop_sem);
up(&usbduxfastsub_tmp->sem); up(&udfs->sem);
return 0; return 0;
} }
/* main driver struct */ /*
* main driver struct
*/
static comedi_driver driver_usbduxfast = { static comedi_driver driver_usbduxfast = {
driver_name:"usbduxfast", .driver_name = "usbduxfast",
module:THIS_MODULE, .module = THIS_MODULE,
attach:usbduxfast_attach, .attach = usbduxfast_attach,
detach:usbduxfast_detach, .detach = usbduxfast_detach
}; };
static void init_usb_devices(void) static void init_usb_devices(void)
{ {
int index; int index;
#ifdef CONFIG_COMEDI_DEBUG #ifdef CONFIG_COMEDI_DEBUG
printk("comedi_: usbduxfast: setting all possible devs to invalid\n"); printk(KERN_DEBUG "comedi_: usbduxfast: setting all possible devs to "
"invalid\n");
#endif #endif
// all devices entries are invalid to begin with /*
// they will become valid by the probe function * all devices entries are invalid to begin with
// and then finally by the attach-function * they will become valid by the probe function
* and then finally by the attach-function
*/
for (index = 0; index < NUMUSBDUXFAST; index++) { for (index = 0; index < NUMUSBDUXFAST; index++) {
memset(&(usbduxfastsub[index]), 0x00, memset(&(usbduxfastsub[index]), 0x00,
sizeof(usbduxfastsub[index])); sizeof(usbduxfastsub[index]));
...@@ -1690,44 +1846,48 @@ static void init_usb_devices(void) ...@@ -1690,44 +1846,48 @@ static void init_usb_devices(void)
} }
} }
// Table with the USB-devices: just now only testing IDs /*
* Table with the USB-devices: just now only testing IDs
*/
static struct usb_device_id usbduxfastsub_table[] = { static struct usb_device_id usbduxfastsub_table[] = {
// { USB_DEVICE(0x4b4, 0x8613), //testing /* { USB_DEVICE(0x4b4, 0x8613) }, testing */
// }, { USB_DEVICE(0x13d8, 0x0010) }, /* real ID */
{USB_DEVICE(0x13d8, 0x0010) //real ID { USB_DEVICE(0x13d8, 0x0011) }, /* real ID */
}, { } /* Terminating entry */
{USB_DEVICE(0x13d8, 0x0011) //real ID
},
{} /* Terminating entry */
}; };
MODULE_DEVICE_TABLE(usb, usbduxfastsub_table); MODULE_DEVICE_TABLE(usb, usbduxfastsub_table);
// The usbduxfastsub-driver /*
* The usbduxfastsub-driver
*/
static struct usb_driver usbduxfastsub_driver = { static struct usb_driver usbduxfastsub_driver = {
#ifdef COMEDI_HAVE_USB_DRIVER_OWNER #ifdef COMEDI_HAVE_USB_DRIVER_OWNER
owner:THIS_MODULE, .owner = THIS_MODULE,
#endif #endif
name:BOARDNAME, .name = BOARDNAME,
probe:usbduxfastsub_probe, .probe = usbduxfastsub_probe,
disconnect:usbduxfastsub_disconnect, .disconnect = usbduxfastsub_disconnect,
id_table:usbduxfastsub_table, .id_table = usbduxfastsub_table
}; };
// Can't use the nice macro as I have also to initialise the USB /*
// subsystem: * Can't use the nice macro as I have also to initialise the USB subsystem:
// registering the usb-system _and_ the comedi-driver * registering the usb-system _and_ the comedi-driver
*/
static int init_usbduxfast(void) static int init_usbduxfast(void)
{ {
printk(KERN_INFO KBUILD_MODNAME ": " printk(KERN_INFO
DRIVER_VERSION ":" DRIVER_DESC "\n"); KBUILD_MODNAME ": " DRIVER_VERSION ":" DRIVER_DESC "\n");
init_usb_devices(); init_usb_devices();
usb_register(&usbduxfastsub_driver); usb_register(&usbduxfastsub_driver);
comedi_driver_register(&driver_usbduxfast); comedi_driver_register(&driver_usbduxfast);
return 0; return 0;
} }
// deregistering the comedi driver and the usb-subsystem /*
* deregistering the comedi driver and the usb-subsystem
*/
static void exit_usbduxfast(void) static void exit_usbduxfast(void)
{ {
comedi_driver_unregister(&driver_usbduxfast); comedi_driver_unregister(&driver_usbduxfast);
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment