-#define DRIVER_VERSION "v2.1"
+#define DRIVER_VERSION "v2.2"
#define DRIVER_AUTHOR "Bernd Porr, BerndPorr@f2s.com"
#define DRIVER_DESC "Stirling/ITL USB-DUX -- Bernd.Porr@f2s.com"
/*
Description: University of Stirling USB DAQ & INCITE Technology Limited
Devices: [ITL] USB-DUX (usbdux.o)
Author: Bernd Porr <BerndPorr@f2s.com>
-Updated: 25 Nov 2007
-Status: Testing
+Updated: 8 Dec 2008
+Status: Stable
Configuration options:
You have to upload firmware with the -i option. The
firmware is usually installed under /usr/share/usb or
* 0.94: D/A output should work now with any channel list combinations
* 0.95: .owner commented out for kernel vers below 2.4.19
* sanity checks in ai/ao_cmd
- * 0.96: trying to get it working with 2.6, moved all memory alloc to comedi's attach final USB IDs
- * moved memory allocation completely to the corresponding comedi functions
- * firmware upload is by fxload and no longer by comedi (due to enumeration)
+ * 0.96: trying to get it working with 2.6, moved all memory alloc to comedi's
+ * attach final USB IDs
+ * moved memory allocation completely to the corresponding comedi
+ * functions firmware upload is by fxload and no longer by comedi (due to
+ * enumeration)
* 0.97: USB IDs received, adjusted table
* 0.98: SMP, locking, memroy alloc: moved all usb memory alloc
* to the usb subsystem and moved all comedi related memory
* | kernel | registration | usbdux-usb | usbdux-comedi | comedi |
* 0.99: USB 2.0: changed protocol to isochronous transfer
* IRQ transfer is too buggy and too risky in 2.0
- * for the high speed ISO transfer is now a working version available
+ * for the high speed ISO transfer is now a working version
+ * available
* 0.99b: Increased the iso transfer buffer for high sp.to 10 buffers. Some VIA
* chipsets miss out IRQs. Deeper buffering is needed.
- * 1.00: full USB 2.0 support for the A/D converter. Now: max 8kHz sampling rate.
+ * 1.00: full USB 2.0 support for the A/D converter. Now: max 8kHz sampling
+ * rate.
* Firmware vers 1.00 is needed for this.
* Two 16 bit up/down/reset counter with a sampling rate of 1kHz
* And loads of cleaning up, in particular streamlining the
* 1.2: added PWM suport via EP4
* 2.0: PWM seems to be stable and is not interfering with the other functions
* 2.1: changed PWM API
+ * 2.2: added firmware kernel request to fix an udev problem
*
*/
-// generates loads of debug info
-// #define NOISY_DUX_DEBUGBUG
+/* generates loads of debug info */
+/* #define NOISY_DUX_DEBUGBUG */
#include <linux/kernel.h>
#include <linux/module.h>
#include <linux/smp_lock.h>
#include <linux/fcntl.h>
#include <linux/compiler.h>
+#include <linux/firmware.h>
#include "../comedidev.h"
-#include "../usb.h"
#define BOARDNAME "usbdux"
-// timeout for the USB-transfer
+/* timeout for the USB-transfer */
#define EZTIMEOUT 30
-// constants for "firmware" upload and download
+/* constants for "firmware" upload and download */
#define USBDUXSUB_FIRMWARE 0xA0
#define VENDOR_DIR_IN 0xC0
#define VENDOR_DIR_OUT 0x40
-// internal adresses of the 8051 processor
+/* internal adresses of the 8051 processor */
#define USBDUXSUB_CPUCS 0xE600
-// the minor device number, major is 180
-// only for debugging purposes and to
-// upload special firmware (programming the
-// eeprom etc) which is not compatible with
-// the comedi framwork
+/*
+ * the minor device number, major is 180 only for debugging purposes and to
+ * upload special firmware (programming the eeprom etc) which is not compatible
+ * with the comedi framwork
+ */
#define USBDUXSUB_MINOR 32
-// max lenghth of the transfer-buffer for software upload
+/* max lenghth of the transfer-buffer for software upload */
#define TB_LEN 0x2000
-// Input endpoint number: ISO/IRQ
+/* Input endpoint number: ISO/IRQ */
#define ISOINEP 6
-// Output endpoint number: ISO/IRQ
+/* Output endpoint number: ISO/IRQ */
#define ISOOUTEP 2
-// This EP sends DUX commands to USBDUX
+/* This EP sends DUX commands to USBDUX */
#define COMMAND_OUT_EP 1
-// This EP receives the DUX commands from USBDUX
+/* This EP receives the DUX commands from USBDUX */
#define COMMAND_IN_EP 8
-// Output endpoint for PWM
+/* Output endpoint for PWM */
#define PWM_EP 4
-// 300Hz max frequ under PWM
+/* 300Hz max frequ under PWM */
#define MIN_PWM_PERIOD ((long)(1E9/300))
-// Default PWM frequency
+/* Default PWM frequency */
#define PWM_DEFAULT_PERIOD ((long)(1E9/100))
-// Number of channels
+/* Number of channels */
#define NUMCHANNELS 8
-// Size of one A/D value
+/* Size of one A/D value */
#define SIZEADIN ((sizeof(int16_t)))
-// Size of the input-buffer IN BYTES
-// Always multiple of 8 for 8 microframes which is needed in the highspeed mode
+/*
+ * Size of the input-buffer IN BYTES
+ * Always multiple of 8 for 8 microframes which is needed in the highspeed mode
+ */
#define SIZEINBUF ((8*SIZEADIN))
-// 16 bytes.
+/* 16 bytes. */
#define SIZEINSNBUF 16
-// Number of DA channels
+/* Number of DA channels */
#define NUMOUTCHANNELS 8
-// size of one value for the D/A converter: channel and value
+/* size of one value for the D/A converter: channel and value */
#define SIZEDAOUT ((sizeof(int8_t)+sizeof(int16_t)))
-// Size of the output-buffer in bytes
-// Actually only the first 4 triplets are used but for the
-// high speed mode we need to pad it to 8 (microframes).
+/*
+ * Size of the output-buffer in bytes
+ * Actually only the first 4 triplets are used but for the
+ * high speed mode we need to pad it to 8 (microframes).
+ */
#define SIZEOUTBUF ((8*SIZEDAOUT))
-// Size of the buffer for the dux commands: just now max size is determined
-// by the analogue out + command byte + panic bytes...
+/*
+ * Size of the buffer for the dux commands: just now max size is determined
+ * by the analogue out + command byte + panic bytes...
+ */
#define SIZEOFDUXBUFFER ((8*SIZEDAOUT+2))
-// Number of in-URBs which receive the data: min=2
+/* Number of in-URBs which receive the data: min=2 */
#define NUMOFINBUFFERSFULL 5
-// Number of out-URBs which send the data: min=2
+/* Number of out-URBs which send the data: min=2 */
#define NUMOFOUTBUFFERSFULL 5
-// Number of in-URBs which receive the data: min=5
-#define NUMOFINBUFFERSHIGH 10 // must have more buffers due to buggy USB ctr
+/* Number of in-URBs which receive the data: min=5 */
+/* must have more buffers due to buggy USB ctr */
+#define NUMOFINBUFFERSHIGH 10
-// Number of out-URBs which send the data: min=5
-#define NUMOFOUTBUFFERSHIGH 10 // must have more buffers due to buggy USB ctr
+/* Number of out-URBs which send the data: min=5 */
+/* must have more buffers due to buggy USB ctr */
+#define NUMOFOUTBUFFERSHIGH 10
-// Total number of usbdux devices
+/* Total number of usbdux devices */
#define NUMUSBDUX 16
-// Analogue in subdevice
+/* Analogue in subdevice */
#define SUBDEV_AD 0
-// Analogue out subdevice
+/* Analogue out subdevice */
#define SUBDEV_DA 1
-// Digital I/O
+/* Digital I/O */
#define SUBDEV_DIO 2
-// counter
+/* counter */
#define SUBDEV_COUNTER 3
-// timer aka pwm output
+/* timer aka pwm output */
#define SUBDEV_PWM 4
-// number of retries to get the right dux command
+/* number of retries to get the right dux command */
#define RETRIES 10
-/////////////////////////////////////////////
-// comedi constants
-static const comedi_lrange range_usbdux_ai_range = { 4, {
+/**************************************************/
+/* comedi constants */
+static const struct comedi_lrange range_usbdux_ai_range = { 4, {
BIP_RANGE(4.096),
BIP_RANGE(4.096 / 2),
UNI_RANGE(4.096),
}
};
-static const comedi_lrange range_usbdux_ao_range = { 2, {
+static const struct comedi_lrange range_usbdux_ao_range = { 2, {
BIP_RANGE(4.096),
UNI_RANGE(4.096),
}
* private structure of one subdevice
*/
-// This is the structure which holds all the data of this driver
-// one sub device just now: A/D
-typedef struct {
- // attached?
+/*
+ * This is the structure which holds all the data of
+ * this driver one sub device just now: A/D
+ */
+struct usbduxsub {
+ /* attached? */
int attached;
- // is it associated with a subdevice?
+ /* is it associated with a subdevice? */
int probed;
- // pointer to the usb-device
+ /* pointer to the usb-device */
struct usb_device *usbdev;
- // actual number of in-buffers
+ /* actual number of in-buffers */
int numOfInBuffers;
- // actual number of out-buffers
+ /* actual number of out-buffers */
int numOfOutBuffers;
- // ISO-transfer handling: buffers
+ /* ISO-transfer handling: buffers */
struct urb **urbIn;
struct urb **urbOut;
- // pwm-transfer handling
+ /* pwm-transfer handling */
struct urb *urbPwm;
- // PWM period
- lsampl_t pwmPeriod;
- // PWM internal delay for the GPIF in the FX2
+ /* PWM period */
+ unsigned int pwmPeriod;
+ /* PWM internal delay for the GPIF in the FX2 */
int8_t pwmDelay;
- // size of the PWM buffer which holds the bit pattern
+ /* size of the PWM buffer which holds the bit pattern */
int sizePwmBuf;
- // input buffer for the ISO-transfer
+ /* input buffer for the ISO-transfer */
int16_t *inBuffer;
- // input buffer for single insn
+ /* input buffer for single insn */
int16_t *insnBuffer;
- // output buffer for single DA outputs
+ /* output buffer for single DA outputs */
int16_t *outBuffer;
- // interface number
+ /* interface number */
int ifnum;
- // interface structure in 2.6
+ /* interface structure in 2.6 */
struct usb_interface *interface;
- // comedi device for the interrupt context
- comedi_device *comedidev;
- // is it USB_SPEED_HIGH or not?
+ /* comedi device for the interrupt context */
+ struct comedi_device *comedidev;
+ /* is it USB_SPEED_HIGH or not? */
short int high_speed;
- // asynchronous command is running
+ /* asynchronous command is running */
short int ai_cmd_running;
short int ao_cmd_running;
- // pwm is running
+ /* pwm is running */
short int pwm_cmd_running;
- // continous aquisition
+ /* continous aquisition */
short int ai_continous;
short int ao_continous;
- // number of samples to aquire
+ /* number of samples to aquire */
int ai_sample_count;
int ao_sample_count;
- // time between samples in units of the timer
+ /* time between samples in units of the timer */
unsigned int ai_timer;
unsigned int ao_timer;
- // counter between aquisitions
+ /* counter between aquisitions */
unsigned int ai_counter;
unsigned int ao_counter;
- // interval in frames/uframes
+ /* interval in frames/uframes */
unsigned int ai_interval;
- // D/A commands
+ /* D/A commands */
int8_t *dac_commands;
- // commands
+ /* commands */
int8_t *dux_commands;
struct semaphore sem;
-} usbduxsub_t;
+};
-// The pointer to the private usb-data of the driver
-// is also the private data for the comedi-device.
-// This has to be global as the usb subsystem needs
-// global variables. The other reason is that this
-// structure must be there _before_ any comedi
-// command is issued. The usb subsystem must be
-// initialised before comedi can access it.
-static usbduxsub_t usbduxsub[NUMUSBDUX];
+/*
+ * The pointer to the private usb-data of the driver is also the private data
+ * for the comedi-device. This has to be global as the usb subsystem needs
+ * global variables. The other reason is that this structure must be there
+ * _before_ any comedi command is issued. The usb subsystem must be initialised
+ * before comedi can access it.
+ */
+static struct usbduxsub usbduxsub[NUMUSBDUX];
static DECLARE_MUTEX(start_stop_sem);
-// Stops the data acquision
-// It should be safe to call this function from any context
-static int usbduxsub_unlink_InURBs(usbduxsub_t * usbduxsub_tmp)
+/*
+ * Stops the data acquision
+ * It should be safe to call this function from any context
+ */
+static int usbduxsub_unlink_InURBs(struct usbduxsub *usbduxsub_tmp)
{
int i = 0;
int err = 0;
if (usbduxsub_tmp && usbduxsub_tmp->urbIn) {
for (i = 0; i < usbduxsub_tmp->numOfInBuffers; i++) {
if (usbduxsub_tmp->urbIn[i]) {
- // We wait here until all transfers
- // have been cancelled.
+ /* We wait here until all transfers have been
+ * cancelled. */
usb_kill_urb(usbduxsub_tmp->urbIn[i]);
}
-#ifdef NOISY_DUX_DEBUGBUG
- printk("comedi: usbdux: unlinked InURB %d, err=%d\n",
+ dev_dbg(&usbduxsub_tmp->interface->dev,
+ "comedi: usbdux: unlinked InURB %d, err=%d\n",
i, err);
-#endif
}
}
return err;
}
-/* This will stop a running acquisition operation */
-// Is called from within this driver from both the
-// interrupt context and from comedi
-static int usbdux_ai_stop(usbduxsub_t * this_usbduxsub, int do_unlink)
+/*
+ * This will stop a running acquisition operation
+ * Is called from within this driver from both the
+ * interrupt context and from comedi
+ */
+static int usbdux_ai_stop(struct usbduxsub *this_usbduxsub, int do_unlink)
{
int ret = 0;
if (!this_usbduxsub) {
- printk("comedi?: usbdux_ai_stop: this_usbduxsub=NULL!\n");
+ dev_err(&this_usbduxsub->interface->dev,
+ "comedi?: usbdux_ai_stop: this_usbduxsub=NULL!\n");
return -EFAULT;
}
-#ifdef NOISY_DUX_DEBUGBUG
- printk("comedi: usbdux_ai_stop\n");
-#endif
+ dev_dbg(&this_usbduxsub->interface->dev, "comedi: usbdux_ai_stop\n");
if (do_unlink) {
- // stop aquistion
+ /* stop aquistion */
ret = usbduxsub_unlink_InURBs(this_usbduxsub);
}
return ret;
}
-// This will cancel a running acquisition operation.
-// This is called by comedi but never from inside the
-// driver.
-static int usbdux_ai_cancel(comedi_device * dev, comedi_subdevice * s)
+/*
+ * This will cancel a running acquisition operation.
+ * This is called by comedi but never from inside the driver.
+ */
+static int usbdux_ai_cancel(struct comedi_device *dev, struct comedi_subdevice *s)
{
- usbduxsub_t *this_usbduxsub;
+ struct usbduxsub *this_usbduxsub;
int res = 0;
- // force unlink of all urbs
-#ifdef NOISY_DUX_DEBUGBUG
- printk("comedi: usbdux_ai_cancel\n");
-#endif
+ /* force unlink of all urbs */
this_usbduxsub = dev->private;
- if (!this_usbduxsub) {
- printk("comedi: usbdux_ai_cancel: this_usbduxsub=NULL\n");
+ if (!this_usbduxsub)
return -EFAULT;
- }
- // prevent other CPUs from submitting new commands just now
+
+ dev_dbg(&this_usbduxsub->interface->dev, "comedi: usbdux_ai_cancel\n");
+
+ /* prevent other CPUs from submitting new commands just now */
down(&this_usbduxsub->sem);
if (!(this_usbduxsub->probed)) {
up(&this_usbduxsub->sem);
return -ENODEV;
}
- // unlink only if the urb really has been submitted
+ /* unlink only if the urb really has been submitted */
res = usbdux_ai_stop(this_usbduxsub, this_usbduxsub->ai_cmd_running);
up(&this_usbduxsub->sem);
return res;
}
-// analogue IN
-// interrupt service routine
+/* analogue IN - interrupt service routine */
static void usbduxsub_ai_IsocIrq(struct urb *urb)
{
int i, err, n;
- usbduxsub_t *this_usbduxsub;
- comedi_device *this_comedidev;
- comedi_subdevice *s;
-
- // sanity checks
- // is the urb there?
- if (!urb) {
- printk("comedi_: usbdux_: ao int-handler called with urb=NULL!\n");
- return;
- }
- // the context variable points to the subdevice
+ struct usbduxsub *this_usbduxsub;
+ struct comedi_device *this_comedidev;
+ struct comedi_subdevice *s;
+
+ /* the context variable points to the subdevice */
this_comedidev = urb->context;
- if (unlikely(!this_comedidev)) {
- printk("comedi_: usbdux_: BUG! urb context is a NULL pointer!\n");
- return;
- }
- // the private structure of the subdevice is usbduxsub_t
+ /* the private structure of the subdevice is struct usbduxsub */
this_usbduxsub = this_comedidev->private;
- if (unlikely(!this_usbduxsub)) {
- printk("comedi_: usbdux_: BUG! private of comedi subdev is a NULL pointer!\n");
- return;
- }
- // subdevice which is the AD converter
+ /* subdevice which is the AD converter */
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) {
case 0:
- // copy the result in the transfer buffer
+ /* copy the result in the transfer buffer */
memcpy(this_usbduxsub->inBuffer,
urb->transfer_buffer, SIZEINBUF);
break;
case -EILSEQ:
- // error in the ISOchronous data
- // we don't copy the data into the transfer buffer
- // and recycle the last data byte
-#ifdef CONFIG_COMEDI_DEBUG
- printk("comedi%d: usbdux: CRC error in ISO IN stream.\n",
+ /* error in the ISOchronous data */
+ /* we don't copy the data into the transfer buffer */
+ /* and recycle the last data byte */
+ dev_dbg(&urb->dev->dev,
+ "comedi%d: usbdux: CRC error in ISO IN stream.\n",
this_usbduxsub->comedidev->minor);
-#endif
break;
- // happens after an unlink command
case -ECONNRESET:
case -ENOENT:
case -ESHUTDOWN:
case -ECONNABORTED:
+ /* happens after an unlink command */
if (this_usbduxsub->ai_cmd_running) {
- // we are still running a command
- // tell this comedi
+ /* we are still running a command */
+ /* tell this comedi */
s->async->events |= COMEDI_CB_EOA;
s->async->events |= COMEDI_CB_ERROR;
comedi_event(this_usbduxsub->comedidev, s);
- // stop the transfer w/o unlink
+ /* stop the transfer w/o unlink */
usbdux_ai_stop(this_usbduxsub, 0);
}
return;
- // a real error on the bus
default:
- // pass error to comedi if we are really running a command
+ /* a real error on the bus */
+ /* pass error to comedi if we are really running a command */
if (this_usbduxsub->ai_cmd_running) {
- printk("Non-zero urb status received in ai intr context: %d\n", urb->status);
+ dev_err(&urb->dev->dev,
+ "Non-zero urb status received in ai intr "
+ "context: %d\n", urb->status);
s->async->events |= COMEDI_CB_EOA;
s->async->events |= COMEDI_CB_ERROR;
comedi_event(this_usbduxsub->comedidev, s);
- // don't do an unlink here
+ /* don't do an unlink here */
usbdux_ai_stop(this_usbduxsub, 0);
}
return;
}
- // at this point we are reasonably sure that nothing dodgy has happened
- // are we running a command?
+ /*
+ * at this point we are reasonably sure that nothing dodgy has happened
+ * are we running a command?
+ */
if (unlikely((!(this_usbduxsub->ai_cmd_running)))) {
- // not running a command
- // do not continue execution if no asynchronous command is running
- // in particular not resubmit
+ /*
+ * not running a command, do not continue execution if no
+ * asynchronous command is running in particular not resubmit
+ */
return;
}
urb->dev = this_usbduxsub->usbdev;
- // resubmit the urb
- err = USB_SUBMIT_URB(urb);
+ /* resubmit the urb */
+ err = usb_submit_urb(urb, GFP_ATOMIC);
if (unlikely(err < 0)) {
- printk("comedi_: usbdux_: urb resubmit failed in int-context! err=%d ", err);
- if (err == -EL2NSYNC) {
- printk("--> buggy USB host controller or bug in IRQ handler!\n");
- } else {
- printk("\n");
- }
+ dev_err(&urb->dev->dev,
+ "comedi_: urb resubmit failed in int-context! err=%d\n",
+ err);
+ if (err == -EL2NSYNC)
+ dev_err(&urb->dev->dev,
+ "buggy USB host controller or bug in IRQ "
+ "handler!\n");
s->async->events |= COMEDI_CB_EOA;
s->async->events |= COMEDI_CB_ERROR;
comedi_event(this_usbduxsub->comedidev, s);
- // don't do an unlink here
+ /* don't do an unlink here */
usbdux_ai_stop(this_usbduxsub, 0);
return;
}
this_usbduxsub->ai_counter--;
- if (likely(this_usbduxsub->ai_counter > 0)) {
+ if (likely(this_usbduxsub->ai_counter > 0))
return;
- }
- // timer zero, transfer measurements to comedi
+
+ /* timer zero, transfer measurements to comedi */
this_usbduxsub->ai_counter = this_usbduxsub->ai_timer;
- // test, if we transmit only a fixed number of samples
+ /* test, if we transmit only a fixed number of samples */
if (!(this_usbduxsub->ai_continous)) {
- // not continous, fixed number of samples
+ /* not continous, fixed number of samples */
this_usbduxsub->ai_sample_count--;
- // all samples received?
+ /* all samples received? */
if (this_usbduxsub->ai_sample_count < 0) {
- // prevent a resubmit next time
+ /* prevent a resubmit next time */
usbdux_ai_stop(this_usbduxsub, 0);
- // say comedi that the acquistion is over
+ /* say comedi that the acquistion is over */
s->async->events |= COMEDI_CB_EOA;
comedi_event(this_usbduxsub->comedidev, s);
return;
}
}
- // get the data from the USB bus and hand it over
- // to comedi
+ /* get the data from the USB bus and hand it over to comedi */
n = s->async->cmd.chanlist_len;
for (i = 0; i < n; i++) {
- // transfer data
+ /* transfer data */
if (CR_RANGE(s->async->cmd.chanlist[i]) <= 1) {
comedi_buf_put
(s->async,
le16_to_cpu(this_usbduxsub->inBuffer[i]));
}
}
- // tell comedi that data is there
+ /* tell comedi that data is there */
comedi_event(this_usbduxsub->comedidev, s);
}
-static int usbduxsub_unlink_OutURBs(usbduxsub_t * usbduxsub_tmp)
+static int usbduxsub_unlink_OutURBs(struct usbduxsub *usbduxsub_tmp)
{
int i = 0;
-
int err = 0;
if (usbduxsub_tmp && usbduxsub_tmp->urbOut) {
for (i = 0; i < usbduxsub_tmp->numOfOutBuffers; i++) {
- if (usbduxsub_tmp->urbOut[i]) {
+ if (usbduxsub_tmp->urbOut[i])
usb_kill_urb(usbduxsub_tmp->urbOut[i]);
- }
-#ifdef NOISY_DUX_DEBUGBUG
- printk("comedi: usbdux: unlinked OutURB %d: res=%d\n",
+
+ dev_dbg(&usbduxsub_tmp->interface->dev,
+ "comedi: usbdux: unlinked OutURB %d: res=%d\n",
i, err);
-#endif
}
}
return err;
/* This will cancel a running acquisition operation
* in any context.
*/
-static int usbdux_ao_stop(usbduxsub_t * this_usbduxsub, int do_unlink)
+static int usbdux_ao_stop(struct usbduxsub *this_usbduxsub, int do_unlink)
{
int ret = 0;
- if (!this_usbduxsub) {
-#ifdef NOISY_DUX_DEBUGBUG
- printk("comedi?: usbdux_ao_stop: this_usbduxsub=NULL!\n");
-#endif
+ if (!this_usbduxsub)
return -EFAULT;
- }
-#ifdef NOISY_DUX_DEBUGBUG
- printk("comedi: usbdux_ao_cancel\n");
-#endif
- if (do_unlink) {
+ dev_dbg(&this_usbduxsub->interface->dev, "comedi: usbdux_ao_cancel\n");
+
+ if (do_unlink)
ret = usbduxsub_unlink_OutURBs(this_usbduxsub);
- }
this_usbduxsub->ao_cmd_running = 0;
return ret;
}
-// force unlink
-// is called by comedi
-static int usbdux_ao_cancel(comedi_device * dev, comedi_subdevice * s)
+/* force unlink, is called by comedi */
+static int usbdux_ao_cancel(struct comedi_device *dev, struct comedi_subdevice *s)
{
- usbduxsub_t *this_usbduxsub = dev->private;
+ struct usbduxsub *this_usbduxsub = dev->private;
int res = 0;
- if (!this_usbduxsub) {
- printk("comedi: usbdux_ao_cancel: this_usbduxsub=NULL\n");
+ if (!this_usbduxsub)
return -EFAULT;
- }
- // prevent other CPUs from submitting a command just now
+
+ /* prevent other CPUs from submitting a command just now */
down(&this_usbduxsub->sem);
if (!(this_usbduxsub->probed)) {
up(&this_usbduxsub->sem);
return -ENODEV;
}
- // unlink only if it is really running
+ /* unlink only if it is really running */
res = usbdux_ao_stop(this_usbduxsub, this_usbduxsub->ao_cmd_running);
up(&this_usbduxsub->sem);
return res;
{
int i, ret;
int8_t *datap;
- usbduxsub_t *this_usbduxsub;
- comedi_device *this_comedidev;
- comedi_subdevice *s;
+ struct usbduxsub *this_usbduxsub;
+ struct comedi_device *this_comedidev;
+ struct comedi_subdevice *s;
- if (!urb) {
- printk("comedi_: usbdux_: ao urb handler called with NULL ptr.\n");
- return;
- }
- // the context variable points to the subdevice
+ /* the context variable points to the subdevice */
this_comedidev = urb->context;
- if (!this_comedidev) {
- printk("comedi_: usbdux_: ao urb int-context is a NULL pointer.\n");
- return;
- }
- // the private structure of the subdevice is usbduxsub_t
+ /* the private structure of the subdevice is struct usbduxsub */
this_usbduxsub = this_comedidev->private;
- if (!this_usbduxsub) {
- printk("comedi_: usbdux_: private data structure of ao subdev is NULL p.\n");
- return;
- }
s = this_comedidev->subdevices + SUBDEV_DA;
/* success */
break;
- // after an unlink command, unplug, ... etc
- // no unlink needed here. Already shutting down.
case -ECONNRESET:
case -ENOENT:
case -ESHUTDOWN:
case -ECONNABORTED:
+ /* after an unlink command, unplug, ... etc */
+ /* no unlink needed here. Already shutting down. */
if (this_usbduxsub->ao_cmd_running) {
s->async->events |= COMEDI_CB_EOA;
comedi_event(this_usbduxsub->comedidev, s);
}
return;
- // a real error
default:
+ /* a real error */
if (this_usbduxsub->ao_cmd_running) {
- printk("comedi_: usbdux_: Non-zero urb status received in ao intr context: %d\n", urb->status);
+ dev_err(&urb->dev->dev,
+ "comedi_: Non-zero urb status received in ao "
+ "intr context: %d\n", urb->status);
s->async->events |= COMEDI_CB_ERROR;
s->async->events |= COMEDI_CB_EOA;
comedi_event(this_usbduxsub->comedidev, s);
- // we do an unlink if we are in the high speed mode
+ /* we do an unlink if we are in the high speed mode */
usbdux_ao_stop(this_usbduxsub, 0);
}
return;
}
- // are we actually running?
- if (!(this_usbduxsub->ao_cmd_running)) {
+ /* are we actually running? */
+ if (!(this_usbduxsub->ao_cmd_running))
return;
- }
- // normal operation: executing a command in this subdevice
+
+ /* normal operation: executing a command in this subdevice */
this_usbduxsub->ao_counter--;
if (this_usbduxsub->ao_counter <= 0) {
- // timer zero
+ /* timer zero */
this_usbduxsub->ao_counter = this_usbduxsub->ao_timer;
- // handle non continous aquisition
+ /* handle non continous aquisition */
if (!(this_usbduxsub->ao_continous)) {
- // fixed number of samples
+ /* fixed number of samples */
this_usbduxsub->ao_sample_count--;
if (this_usbduxsub->ao_sample_count < 0) {
- // all samples transmitted
+ /* all samples transmitted */
usbdux_ao_stop(this_usbduxsub, 0);
s->async->events |= COMEDI_CB_EOA;
comedi_event(this_usbduxsub->comedidev, s);
- // no resubmit of the urb
+ /* no resubmit of the urb */
return;
}
}
- // transmit data to the USB bus
+ /* transmit data to the USB bus */
((uint8_t *) (urb->transfer_buffer))[0] =
s->async->cmd.chanlist_len;
for (i = 0; i < s->async->cmd.chanlist_len; i++) {
- sampl_t temp;
- if (i >= NUMOUTCHANNELS) {
+ short temp;
+ if (i >= NUMOUTCHANNELS)
break;
- }
- // pointer to the DA
- datap = (&(((int8_t *) urb->transfer_buffer)[i * 3 + 1]));
- // get the data from comedi
+
+ /* pointer to the DA */
+ datap =
+ (&(((int8_t *)urb->transfer_buffer)[i * 3 + 1]));
+ /* get the data from comedi */
ret = comedi_buf_get(s->async, &temp);
datap[0] = temp;
datap[1] = temp >> 8;
datap[2] = this_usbduxsub->dac_commands[i];
- // printk("data[0]=%x, data[1]=%x, data[2]=%x\n",
- // datap[0],datap[1],datap[2]);
+ /* printk("data[0]=%x, data[1]=%x, data[2]=%x\n", */
+ /* datap[0],datap[1],datap[2]); */
if (ret < 0) {
- printk("comedi: usbdux: buffer underflow\n");
+ dev_err(&urb->dev->dev,
+ "comedi: buffer underflow\n");
s->async->events |= COMEDI_CB_EOA;
s->async->events |= COMEDI_CB_OVERFLOW;
}
- // transmit data to comedi
+ /* transmit data to comedi */
s->async->events |= COMEDI_CB_BLOCK;
comedi_event(this_usbduxsub->comedidev, s);
}
urb->status = 0;
if (this_usbduxsub->ao_cmd_running) {
if (this_usbduxsub->high_speed) {
- // uframes
+ /* uframes */
urb->interval = 8;
} else {
- // frames
+ /* frames */
urb->interval = 1;
}
urb->number_of_packets = 1;
urb->iso_frame_desc[0].offset = 0;
urb->iso_frame_desc[0].length = SIZEOUTBUF;
urb->iso_frame_desc[0].status = 0;
- if ((ret = USB_SUBMIT_URB(urb)) < 0) {
- printk("comedi_: usbdux_: ao urb resubm failed in int-cont.");
- printk("ret=%d", ret);
- if (ret == EL2NSYNC) {
- printk("--> buggy USB host controller or bug in IRQ handling!\n");
- } else {
- printk("\n");
- }
+ ret = usb_submit_urb(urb, GFP_ATOMIC);
+ if (ret < 0) {
+ dev_err(&urb->dev->dev,
+ "comedi_: ao urb resubm failed in int-cont. "
+ "ret=%d", ret);
+ if (ret == EL2NSYNC)
+ dev_err(&urb->dev->dev,
+ "buggy USB host controller or bug in "
+ "IRQ handling!\n");
+
s->async->events |= COMEDI_CB_EOA;
s->async->events |= COMEDI_CB_ERROR;
comedi_event(this_usbduxsub->comedidev, s);
- // don't do an unlink here
+ /* don't do an unlink here */
usbdux_ao_stop(this_usbduxsub, 0);
}
}
}
-static int usbduxsub_start(usbduxsub_t * usbduxsub)
+static int usbduxsub_start(struct usbduxsub *usbduxsub)
{
int errcode = 0;
uint8_t local_transfer_buffer[16];
- if (usbduxsub->probed) {
- // 7f92 to zero
- local_transfer_buffer[0] = 0;
- errcode = USB_CONTROL_MSG(usbduxsub->usbdev,
- // create a pipe for a control transfer
- usb_sndctrlpipe(usbduxsub->usbdev, 0),
- // bRequest, "Firmware"
- USBDUXSUB_FIRMWARE,
- // bmRequestType
- VENDOR_DIR_OUT,
- // Value
- USBDUXSUB_CPUCS,
- // Index
- 0x0000,
- // address of the transfer buffer
- local_transfer_buffer,
- // Length
- 1,
- // Timeout
- EZTIMEOUT);
- if (errcode < 0) {
- printk("comedi_: usbdux_: control msg failed (start)\n");
- return errcode;
- }
+ /* 7f92 to zero */
+ local_transfer_buffer[0] = 0;
+ errcode = usb_control_msg(usbduxsub->usbdev,
+ /* create a pipe for a control transfer */
+ usb_sndctrlpipe(usbduxsub->usbdev, 0),
+ /* bRequest, "Firmware" */
+ USBDUXSUB_FIRMWARE,
+ /* bmRequestType */
+ VENDOR_DIR_OUT,
+ /* Value */
+ USBDUXSUB_CPUCS,
+ /* Index */
+ 0x0000,
+ /* address of the transfer buffer */
+ local_transfer_buffer,
+ /* Length */
+ 1,
+ /* Timeout */
+ EZTIMEOUT);
+ if (errcode < 0) {
+ dev_err(&usbduxsub->interface->dev,
+ "comedi_: control msg failed (start)\n");
+ return errcode;
}
return 0;
}
-static int usbduxsub_stop(usbduxsub_t * usbduxsub)
+static int usbduxsub_stop(struct usbduxsub *usbduxsub)
{
int errcode = 0;
uint8_t local_transfer_buffer[16];
- if (usbduxsub->probed) {
- // 7f92 to one
- local_transfer_buffer[0] = 1;
- errcode = USB_CONTROL_MSG
- (usbduxsub->usbdev,
- usb_sndctrlpipe(usbduxsub->usbdev, 0),
- // bRequest, "Firmware"
- USBDUXSUB_FIRMWARE,
- // bmRequestType
- VENDOR_DIR_OUT,
- // Value
- USBDUXSUB_CPUCS,
- // Index
- 0x0000, local_transfer_buffer,
- // Length
- 1,
- // Timeout
- EZTIMEOUT);
- if (errcode < 0) {
- printk("comedi_: usbdux: control msg failed (stop)\n");
- return errcode;
- }
+
+ /* 7f92 to one */
+ local_transfer_buffer[0] = 1;
+ errcode = usb_control_msg(usbduxsub->usbdev,
+ usb_sndctrlpipe(usbduxsub->usbdev, 0),
+ /* bRequest, "Firmware" */
+ USBDUXSUB_FIRMWARE,
+ /* bmRequestType */
+ VENDOR_DIR_OUT,
+ /* Value */
+ USBDUXSUB_CPUCS,
+ /* Index */
+ 0x0000, local_transfer_buffer,
+ /* Length */
+ 1,
+ /* Timeout */
+ EZTIMEOUT);
+ if (errcode < 0) {
+ dev_err(&usbduxsub->interface->dev,
+ "comedi_: control msg failed (stop)\n");
+ return errcode;
}
return 0;
}
-static int usbduxsub_upload(usbduxsub_t * usbduxsub,
- uint8_t * local_transfer_buffer,
- unsigned int startAddr, unsigned int len)
+static int usbduxsub_upload(struct usbduxsub *usbduxsub,
+ uint8_t *local_transfer_buffer,
+ unsigned int startAddr, unsigned int len)
{
int errcode;
- if (usbduxsub->probed) {
-#ifdef CONFIG_COMEDI_DEBUG
- printk("comedi%d: usbdux: uploading %d bytes",
- usbduxsub->comedidev->minor, len);
- printk(" to addr %d, first byte=%d.\n",
- startAddr, local_transfer_buffer[0]);
-#endif
- errcode = USB_CONTROL_MSG
- (usbduxsub->usbdev,
+ errcode = usb_control_msg(usbduxsub->usbdev,
usb_sndctrlpipe(usbduxsub->usbdev, 0),
- // brequest, firmware
+ /* brequest, firmware */
USBDUXSUB_FIRMWARE,
- // bmRequestType
+ /* bmRequestType */
VENDOR_DIR_OUT,
- // value
+ /* value */
startAddr,
- // index
+ /* index */
0x0000,
- // our local safe buffer
+ /* our local safe buffer */
local_transfer_buffer,
- // length
+ /* length */
len,
- // timeout
+ /* timeout */
EZTIMEOUT);
-#ifdef NOISY_DUX_DEBUGBUG
- printk("comedi_: usbdux: result=%d\n", errcode);
-#endif
- if (errcode < 0) {
- printk("comedi_: usbdux: uppload failed\n");
- return errcode;
- }
- } else {
- // no device on the bus for this index
- return -EFAULT;
+ dev_dbg(&usbduxsub->interface->dev,
+ "comedi_: result=%d\n", errcode);
+ if (errcode < 0) {
+ dev_err(&usbduxsub->interface->dev,
+ "comedi_: upload failed\n");
+ return errcode;
}
return 0;
}
-int firmwareUpload(usbduxsub_t * usbduxsub,
- uint8_t * firmwareBinary, int sizeFirmware)
+#define FIRMWARE_MAX_LEN 0x2000
+
+static int firmwareUpload(struct usbduxsub *usbduxsub,
+ const u8 *firmwareBinary,
+ int sizeFirmware)
{
int ret;
+ uint8_t *fwBuf;
- if (!firmwareBinary) {
+ if (!firmwareBinary)
return 0;
+
+ if (sizeFirmware>FIRMWARE_MAX_LEN) {
+ dev_err(&usbduxsub->interface->dev,
+ "comedi_: usbdux firmware binary it too large for FX2.\n");
+ return -ENOMEM;
+ }
+
+ /* we generate a local buffer for the firmware */
+ fwBuf = kzalloc(sizeFirmware, GFP_KERNEL);
+ if (!fwBuf) {
+ dev_err(&usbduxsub->interface->dev,
+ "comedi_: mem alloc for firmware failed\n");
+ return -ENOMEM;
}
+ memcpy(fwBuf,firmwareBinary,sizeFirmware);
+
ret = usbduxsub_stop(usbduxsub);
if (ret < 0) {
- printk("comedi_: usbdux: can not stop firmware\n");
+ dev_err(&usbduxsub->interface->dev,
+ "comedi_: can not stop firmware\n");
+ kfree(fwBuf);
return ret;
}
- ret = usbduxsub_upload(usbduxsub, firmwareBinary, 0, sizeFirmware);
+
+ ret = usbduxsub_upload(usbduxsub, fwBuf, 0, sizeFirmware);
if (ret < 0) {
- printk("comedi_: usbdux: firmware upload failed\n");
+ dev_err(&usbduxsub->interface->dev,
+ "comedi_: firmware upload failed\n");
+ kfree(fwBuf);
return ret;
}
ret = usbduxsub_start(usbduxsub);
if (ret < 0) {
- printk("comedi_: usbdux: can not start firmware\n");
+ dev_err(&usbduxsub->interface->dev,
+ "comedi_: can not start firmware\n");
+ kfree(fwBuf);
return ret;
}
+ kfree(fwBuf);
return 0;
}
-int usbduxsub_submit_InURBs(usbduxsub_t * usbduxsub)
+static int usbduxsub_submit_InURBs(struct usbduxsub *usbduxsub)
{
int i, errFlag;
- if (!usbduxsub) {
+ if (!usbduxsub)
return -EFAULT;
- }
+
/* Submit all URBs and start the transfer on the bus */
for (i = 0; i < usbduxsub->numOfInBuffers; i++) {
- // in case of a resubmission after an unlink...
+ /* in case of a resubmission after an unlink... */
usbduxsub->urbIn[i]->interval = usbduxsub->ai_interval;
usbduxsub->urbIn[i]->context = usbduxsub->comedidev;
usbduxsub->urbIn[i]->dev = usbduxsub->usbdev;
usbduxsub->urbIn[i]->status = 0;
usbduxsub->urbIn[i]->transfer_flags = URB_ISO_ASAP;
-#ifdef NOISY_DUX_DEBUGBUG
- printk("comedi%d: usbdux: submitting in-urb[%d]: %p,%p intv=%d\n", usbduxsub->comedidev->minor, i, (usbduxsub->urbIn[i]->context), (usbduxsub->urbIn[i]->dev), (usbduxsub->urbIn[i]->interval));
-#endif
- errFlag = USB_SUBMIT_URB(usbduxsub->urbIn[i]);
+ dev_dbg(&usbduxsub->interface->dev,
+ "comedi%d: submitting in-urb[%d]: %p,%p intv=%d\n",
+ usbduxsub->comedidev->minor, i,
+ (usbduxsub->urbIn[i]->context),
+ (usbduxsub->urbIn[i]->dev),
+ (usbduxsub->urbIn[i]->interval));
+ errFlag = usb_submit_urb(usbduxsub->urbIn[i], GFP_ATOMIC);
if (errFlag) {
- printk("comedi_: usbdux: ai: ");
- printk("USB_SUBMIT_URB(%d)", i);
- printk(" error %d\n", errFlag);
+ dev_err(&usbduxsub->interface->dev,
+ "comedi_: ai: usb_submit_urb(%d) error %d\n",
+ i, errFlag);
return errFlag;
}
}
return 0;
}
-int usbduxsub_submit_OutURBs(usbduxsub_t * usbduxsub)
+static int usbduxsub_submit_OutURBs(struct usbduxsub *usbduxsub)
{
int i, errFlag;
- if (!usbduxsub) {
+ if (!usbduxsub)
return -EFAULT;
- }
+
for (i = 0; i < usbduxsub->numOfOutBuffers; i++) {
-#ifdef NOISY_DUX_DEBUGBUG
- printk("comedi_: usbdux: submitting out-urb[%d]\n", i);
-#endif
- // in case of a resubmission after an unlink...
+ dev_dbg(&usbduxsub->interface->dev,
+ "comedi_: submitting out-urb[%d]\n", i);
+ /* in case of a resubmission after an unlink... */
usbduxsub->urbOut[i]->context = usbduxsub->comedidev;
usbduxsub->urbOut[i]->dev = usbduxsub->usbdev;
usbduxsub->urbOut[i]->status = 0;
usbduxsub->urbOut[i]->transfer_flags = URB_ISO_ASAP;
- errFlag = USB_SUBMIT_URB(usbduxsub->urbOut[i]);
+ errFlag = usb_submit_urb(usbduxsub->urbOut[i], GFP_ATOMIC);
if (errFlag) {
- printk("comedi_: usbdux: ao: ");
- printk("USB_SUBMIT_URB(%d)", i);
- printk(" error %d\n", errFlag);
+ dev_err(&usbduxsub->interface->dev,
+ "comedi_: ao: usb_submit_urb(%d) error %d\n",
+ i, errFlag);
return errFlag;
}
}
return 0;
}
-static int usbdux_ai_cmdtest(comedi_device * dev,
- comedi_subdevice * s, comedi_cmd * cmd)
+static int usbdux_ai_cmdtest(struct comedi_device *dev, struct comedi_subdevice *s,
+ struct comedi_cmd *cmd)
{
int err = 0, tmp, i;
unsigned int tmpTimer;
- usbduxsub_t *this_usbduxsub = dev->private;
- if (!(this_usbduxsub->probed)) {
+ struct usbduxsub *this_usbduxsub = dev->private;
+
+ if (!(this_usbduxsub->probed))
return -ENODEV;
- }
-#ifdef NOISY_DUX_DEBUGBUG
- printk("comedi%d: usbdux_ai_cmdtest\n", dev->minor);
-#endif
+
+ dev_dbg(&this_usbduxsub->interface->dev,
+ "comedi%d: usbdux_ai_cmdtest\n", dev->minor);
+
/* make sure triggers are valid */
- // Only immediate triggers are allowed
+ /* Only immediate triggers are allowed */
tmp = cmd->start_src;
cmd->start_src &= TRIG_NOW | TRIG_INT;
if (!cmd->start_src || tmp != cmd->start_src)
err++;
- // trigger should happen timed
+ /* trigger should happen timed */
tmp = cmd->scan_begin_src;
- // start a new _scan_ with a timer
+ /* start a new _scan_ with a timer */
cmd->scan_begin_src &= TRIG_TIMER;
if (!cmd->scan_begin_src || tmp != cmd->scan_begin_src)
err++;
- // scanning is continous
+ /* scanning is continous */
tmp = cmd->convert_src;
cmd->convert_src &= TRIG_NOW;
if (!cmd->convert_src || tmp != cmd->convert_src)
err++;
- // issue a trigger when scan is finished and start a new scan
+ /* issue a trigger when scan is finished and start a new scan */
tmp = cmd->scan_end_src;
cmd->scan_end_src &= TRIG_COUNT;
if (!cmd->scan_end_src || tmp != cmd->scan_end_src)
err++;
- // trigger at the end of count events or not, stop condition or not
+ /* trigger at the end of count events or not, stop condition or not */
tmp = cmd->stop_src;
cmd->stop_src &= TRIG_COUNT | TRIG_NONE;
if (!cmd->stop_src || tmp != cmd->stop_src)
if (err)
return 1;
- /* step 2: make sure trigger sources are unique and mutually compatible */
- /* note that mutual compatiblity is not an issue here */
+ /*
+ * step 2: make sure trigger sources are unique and mutually compatible
+ * note that mutual compatiblity is not an issue here
+ */
if (cmd->scan_begin_src != TRIG_FOLLOW &&
cmd->scan_begin_src != TRIG_EXT &&
cmd->scan_begin_src != TRIG_TIMER)
return 2;
/* step 3: make sure arguments are trivially compatible */
-
if (cmd->start_arg != 0) {
cmd->start_arg = 0;
err++;
if (cmd->scan_begin_src == TRIG_TIMER) {
if (this_usbduxsub->high_speed) {
- // In high speed mode microframes are possible.
- // However, during one microframe we can roughly
- // sample one channel. Thus, the more channels
- // are in the channel list the more time we need.
+ /*
+ * In high speed mode microframes are possible.
+ * However, during one microframe we can roughly
+ * sample one channel. Thus, the more channels
+ * are in the channel list the more time we need.
+ */
i = 1;
- // find a power of 2 for the number of channels
- while (i < (cmd->chanlist_len)) {
+ /* find a power of 2 for the number of channels */
+ while (i < (cmd->chanlist_len))
i = i * 2;
- }
+
if (cmd->scan_begin_arg < (1000000 / 8 * i)) {
cmd->scan_begin_arg = 1000000 / 8 * i;
err++;
}
- // now calc the real sampling rate with all the rounding errors
+ /* now calc the real sampling rate with all the
+ * rounding errors */
tmpTimer =
((unsigned int)(cmd->scan_begin_arg / 125000)) *
125000;
cmd->scan_begin_arg = tmpTimer;
err++;
}
- } else { // full speed
- // 1kHz scans every USB frame
+ } else {
+ /* full speed */
+ /* 1kHz scans every USB frame */
if (cmd->scan_begin_arg < 1000000) {
cmd->scan_begin_arg = 1000000;
err++;
}
- // calc the real sampling rate with the rounding errors
- tmpTimer =
- ((unsigned int)(cmd->scan_begin_arg /
+ /*
+ * calc the real sampling rate with the rounding errors
+ */
+ tmpTimer = ((unsigned int)(cmd->scan_begin_arg /
1000000)) * 1000000;
if (cmd->scan_begin_arg != tmpTimer) {
cmd->scan_begin_arg = tmpTimer;
}
}
}
- // the same argument
+ /* the same argument */
if (cmd->scan_end_arg != cmd->chanlist_len) {
cmd->scan_end_arg = cmd->chanlist_len;
err++;
return 0;
}
-// creates the ADC command for the MAX1271
-// range is the range value from comedi
+/*
+ * creates the ADC command for the MAX1271
+ * range is the range value from comedi
+ */
static int8_t create_adc_command(unsigned int chan, int range)
{
int8_t p = (range <= 1);
return (chan << 4) | ((p == 1) << 2) | ((r == 1) << 3);
}
-// bulk transfers to usbdux
+/* bulk transfers to usbdux */
#define SENDADCOMMANDS 0
#define SENDDACOMMANDS 1
#define SENDPWMON 7
#define SENDPWMOFF 8
-static int send_dux_commands(usbduxsub_t * this_usbduxsub, int cmd_type)
+static int send_dux_commands(struct usbduxsub *this_usbduxsub, int cmd_type)
{
int result, nsent;
this_usbduxsub->dux_commands[0] = cmd_type;
#ifdef NOISY_DUX_DEBUGBUG
- printk("comedi%d: usbdux: dux_commands: ",
+ printk(KERN_DEBUG "comedi%d: usbdux: dux_commands: ",
this_usbduxsub->comedidev->minor);
- for (result = 0; result < SIZEOFDUXBUFFER; result++) {
+ for (result = 0; result < SIZEOFDUXBUFFER; result++)
printk(" %02x", this_usbduxsub->dux_commands[result]);
- }
printk("\n");
#endif
- result = USB_BULK_MSG(this_usbduxsub->usbdev,
- usb_sndbulkpipe(this_usbduxsub->usbdev,
- COMMAND_OUT_EP),
- this_usbduxsub->dux_commands, SIZEOFDUXBUFFER, &nsent, 10 * HZ);
- if (result < 0) {
- printk("comedi%d: could not transmit dux_command to the usb-device, err=%d\n", this_usbduxsub->comedidev->minor, result);
- }
+ result = usb_bulk_msg(this_usbduxsub->usbdev,
+ usb_sndbulkpipe(this_usbduxsub->usbdev,
+ COMMAND_OUT_EP),
+ this_usbduxsub->dux_commands, SIZEOFDUXBUFFER,
+ &nsent, 10);
+ if (result < 0)
+ dev_err(&this_usbduxsub->interface->dev, "comedi%d: "
+ "could not transmit dux_command to the usb-device, "
+ "err=%d\n", this_usbduxsub->comedidev->minor, result);
+
return result;
}
-static int receive_dux_commands(usbduxsub_t * this_usbduxsub, int command)
+static int receive_dux_commands(struct usbduxsub *this_usbduxsub, int command)
{
int result = (-EFAULT);
int nrec;
int i;
for (i = 0; i < RETRIES; i++) {
- result = USB_BULK_MSG(this_usbduxsub->usbdev,
- usb_rcvbulkpipe(this_usbduxsub->usbdev,
- COMMAND_IN_EP),
- this_usbduxsub->insnBuffer, SIZEINSNBUF, &nrec, 1 * HZ);
+ result = usb_bulk_msg(this_usbduxsub->usbdev,
+ usb_rcvbulkpipe(this_usbduxsub->usbdev,
+ COMMAND_IN_EP),
+ this_usbduxsub->insnBuffer, SIZEINSNBUF,
+ &nrec, 1);
if (result < 0) {
- printk("comedi%d: insn: USB error %d while receiving DUX command\n", this_usbduxsub->comedidev->minor, result);
+ dev_err(&this_usbduxsub->interface->dev, "comedi%d: "
+ "insn: USB error %d while receiving DUX command"
+ "\n", this_usbduxsub->comedidev->minor, result);
return result;
}
- if (le16_to_cpu(this_usbduxsub->insnBuffer[0]) == command) {
+ if (le16_to_cpu(this_usbduxsub->insnBuffer[0]) == command)
return result;
- }
}
- // this is only reached if the data has been requested a couple of times
- printk("comedi%d: insn: wrong data returned from firmware: want cmd %d, got cmd %d.\n", this_usbduxsub->comedidev->minor, command, le16_to_cpu(this_usbduxsub->insnBuffer[0]));
+ /* this is only reached if the data has been requested a couple of
+ * times */
+ dev_err(&this_usbduxsub->interface->dev, "comedi%d: insn: "
+ "wrong data returned from firmware: want cmd %d, got cmd %d.\n",
+ this_usbduxsub->comedidev->minor, command,
+ le16_to_cpu(this_usbduxsub->insnBuffer[0]));
return -EFAULT;
}
-static int usbdux_ai_inttrig(comedi_device * dev,
- comedi_subdevice * s, unsigned int trignum)
+static int usbdux_ai_inttrig(struct comedi_device *dev, struct comedi_subdevice *s,
+ unsigned int trignum)
{
int ret;
- usbduxsub_t *this_usbduxsub = dev->private;
- if (!this_usbduxsub) {
+ struct usbduxsub *this_usbduxsub = dev->private;
+ if (!this_usbduxsub)
return -EFAULT;
- }
+
down(&this_usbduxsub->sem);
if (!(this_usbduxsub->probed)) {
up(&this_usbduxsub->sem);
return -ENODEV;
}
-#ifdef NOISY_DUX_DEBUGBUG
- printk("comedi%d: usbdux_ai_inttrig\n", dev->minor);
-#endif
+ dev_dbg(&this_usbduxsub->interface->dev,
+ "comedi%d: usbdux_ai_inttrig\n", dev->minor);
if (trignum != 0) {
- printk("comedi%d: usbdux_ai_inttrig: invalid trignum\n",
+ dev_err(&this_usbduxsub->interface->dev,
+ "comedi%d: usbdux_ai_inttrig: invalid trignum\n",
dev->minor);
up(&this_usbduxsub->sem);
return -EINVAL;
this_usbduxsub->ai_cmd_running = 1;
ret = usbduxsub_submit_InURBs(this_usbduxsub);
if (ret < 0) {
- printk("comedi%d: usbdux_ai_inttrig: urbSubmit: err=%d\n", dev->minor, ret);
+ dev_err(&this_usbduxsub->interface->dev,
+ "comedi%d: usbdux_ai_inttrig: "
+ "urbSubmit: err=%d\n", dev->minor, ret);
this_usbduxsub->ai_cmd_running = 0;
up(&this_usbduxsub->sem);
return ret;
}
s->async->inttrig = NULL;
} else {
- printk("comedi%d: ai_inttrig but acqu is already running\n",
+ dev_err(&this_usbduxsub->interface->dev,
+ "comedi%d: ai_inttrig but acqu is already running\n",
dev->minor);
}
up(&this_usbduxsub->sem);
return 1;
}
-static int usbdux_ai_cmd(comedi_device * dev, comedi_subdevice * s)
+static int usbdux_ai_cmd(struct comedi_device *dev, struct comedi_subdevice *s)
{
- comedi_cmd *cmd = &s->async->cmd;
+ struct comedi_cmd *cmd = &s->async->cmd;
unsigned int chan, range;
int i, ret;
- usbduxsub_t *this_usbduxsub = dev->private;
+ struct usbduxsub *this_usbduxsub = dev->private;
int result;
-#ifdef NOISY_DUX_DEBUGBUG
- printk("comedi%d: usbdux_ai_cmd\n", dev->minor);
-#endif
- if (!this_usbduxsub) {
+ if (!this_usbduxsub)
return -EFAULT;
- }
- // block other CPUs from starting an ai_cmd
+
+ dev_dbg(&this_usbduxsub->interface->dev,
+ "comedi%d: usbdux_ai_cmd\n", dev->minor);
+
+ /* block other CPUs from starting an ai_cmd */
down(&this_usbduxsub->sem);
if (!(this_usbduxsub->probed)) {
return -ENODEV;
}
if (this_usbduxsub->ai_cmd_running) {
- printk("comedi%d: ai_cmd not possible. Another ai_cmd is running.\n", dev->minor);
+ dev_err(&this_usbduxsub->interface->dev, "comedi%d: "
+ "ai_cmd not possible. Another ai_cmd is running.\n",
+ dev->minor);
up(&this_usbduxsub->sem);
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;
this_usbduxsub->dux_commands[1] = cmd->chanlist_len;
chan = CR_CHAN(cmd->chanlist[i]);
range = CR_RANGE(cmd->chanlist[i]);
if (i >= NUMCHANNELS) {
- printk("comedi%d: channel list too long\n", dev->minor);
+ dev_err(&this_usbduxsub->interface->dev,
+ "comedi%d: channel list too long\n",
+ dev->minor);
break;
}
this_usbduxsub->dux_commands[i + 2] =
create_adc_command(chan, range);
}
-#ifdef NOISY_DUX_DEBUGBUG
- printk("comedi %d: sending commands to the usb device: ", dev->minor);
- printk("size=%u\n", NUMCHANNELS);
-#endif
- if ((result = send_dux_commands(this_usbduxsub, SENDADCOMMANDS)) < 0) {
+ dev_dbg(&this_usbduxsub->interface->dev,
+ "comedi %d: sending commands to the usb device: size=%u\n",
+ dev->minor, NUMCHANNELS);
+
+ result = send_dux_commands(this_usbduxsub, SENDADCOMMANDS);
+ if (result < 0) {
up(&this_usbduxsub->sem);
return result;
}
if (this_usbduxsub->high_speed) {
- // every channel gets a time window of 125us. Thus, if we
- // sample all 8 channels we need 1ms. If we sample only
- // one channel we need only 125us
+ /*
+ * every channel gets a time window of 125us. Thus, if we
+ * sample all 8 channels we need 1ms. If we sample only one
+ * channel we need only 125us
+ */
this_usbduxsub->ai_interval = 1;
- // find a power of 2 for the interval
+ /* find a power of 2 for the interval */
while ((this_usbduxsub->ai_interval) < (cmd->chanlist_len)) {
this_usbduxsub->ai_interval =
(this_usbduxsub->ai_interval) * 2;
}
- this_usbduxsub->ai_timer =
- cmd->scan_begin_arg / (125000 *
+ this_usbduxsub->ai_timer = cmd->scan_begin_arg / (125000 *
(this_usbduxsub->ai_interval));
} else {
- // interval always 1ms
+ /* interval always 1ms */
this_usbduxsub->ai_interval = 1;
this_usbduxsub->ai_timer = cmd->scan_begin_arg / 1000000;
}
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);
+ dev_err(&this_usbduxsub->interface->dev, "comedi%d: 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);
return -EINVAL;
}
this_usbduxsub->ai_counter = this_usbduxsub->ai_timer;
if (cmd->stop_src == TRIG_COUNT) {
- // data arrives as one packet
+ /* data arrives as one packet */
this_usbduxsub->ai_sample_count = cmd->stop_arg;
this_usbduxsub->ai_continous = 0;
} else {
- // continous aquisition
+ /* continous aquisition */
this_usbduxsub->ai_continous = 1;
this_usbduxsub->ai_sample_count = 0;
}
if (cmd->start_src == TRIG_NOW) {
- // enable this acquisition operation
+ /* enable this acquisition operation */
this_usbduxsub->ai_cmd_running = 1;
ret = usbduxsub_submit_InURBs(this_usbduxsub);
if (ret < 0) {
this_usbduxsub->ai_cmd_running = 0;
- // fixme: unlink here??
+ /* fixme: unlink here?? */
up(&this_usbduxsub->sem);
return ret;
}
s->async->inttrig = NULL;
} else {
/* TRIG_INT */
- // don't enable the acquision operation
- // wait for an internal signal
+ /* don't enable the acquision operation */
+ /* wait for an internal signal */
s->async->inttrig = usbdux_ai_inttrig;
}
up(&this_usbduxsub->sem);
}
/* Mode 0 is used to get a single conversion on demand */
-static int usbdux_ai_insn_read(comedi_device * dev,
- comedi_subdevice * s, comedi_insn * insn, lsampl_t * data)
+static int usbdux_ai_insn_read(struct comedi_device *dev, struct comedi_subdevice *s,
+ struct comedi_insn *insn, unsigned int *data)
{
int i;
- lsampl_t one = 0;
+ unsigned int one = 0;
int chan, range;
int err;
- usbduxsub_t *this_usbduxsub = dev->private;
+ struct usbduxsub *this_usbduxsub = dev->private;
- if (!this_usbduxsub) {
- printk("comedi%d: ai_insn_read: no usb dev.\n", dev->minor);
+ if (!this_usbduxsub)
return 0;
- }
-#ifdef NOISY_DUX_DEBUGBUG
- printk("comedi%d: ai_insn_read, insn->n=%d, insn->subdev=%d\n",
+
+ dev_dbg(&this_usbduxsub->interface->dev,
+ "comedi%d: ai_insn_read, insn->n=%d, insn->subdev=%d\n",
dev->minor, insn->n, insn->subdev);
-#endif
+
down(&this_usbduxsub->sem);
if (!(this_usbduxsub->probed)) {
up(&this_usbduxsub->sem);
return -ENODEV;
}
if (this_usbduxsub->ai_cmd_running) {
- printk("comedi%d: ai_insn_read not possible. Async Command is running.\n", dev->minor);
+ dev_err(&this_usbduxsub->interface->dev,
+ "comedi%d: ai_insn_read not possible. "
+ "Async Command is running.\n", dev->minor);
up(&this_usbduxsub->sem);
return 0;
}
- // sample one channel
+ /* sample one channel */
chan = CR_CHAN(insn->chanspec);
range = CR_RANGE(insn->chanspec);
- // set command for the first channel
+ /* set command for the first channel */
this_usbduxsub->dux_commands[1] = create_adc_command(chan, range);
- // adc commands
- if ((err = send_dux_commands(this_usbduxsub, SENDSINGLEAD)) < 0) {
+ /* adc commands */
+ err = send_dux_commands(this_usbduxsub, SENDSINGLEAD);
+ if (err < 0) {
up(&this_usbduxsub->sem);
return err;
}
for (i = 0; i < insn->n; i++) {
- if ((err = receive_dux_commands(this_usbduxsub,
- SENDSINGLEAD)) < 0) {
+ err = receive_dux_commands(this_usbduxsub, SENDSINGLEAD);
+ if (err < 0) {
up(&this_usbduxsub->sem);
return 0;
}
one = le16_to_cpu(this_usbduxsub->insnBuffer[1]);
- if (CR_RANGE(insn->chanspec) <= 1) {
+ if (CR_RANGE(insn->chanspec) <= 1)
one = one ^ 0x800;
- }
+
data[i] = one;
}
up(&this_usbduxsub->sem);
return i;
}
-//////////////////
-// analog out
+/************************************/
+/* analog out */
-static int usbdux_ao_insn_read(comedi_device * dev, comedi_subdevice * s,
- comedi_insn * insn, lsampl_t * data)
+static int usbdux_ao_insn_read(struct comedi_device *dev, struct comedi_subdevice *s,
+ struct comedi_insn *insn, unsigned int *data)
{
int i;
int chan = CR_CHAN(insn->chanspec);
- usbduxsub_t *this_usbduxsub = dev->private;
+ struct usbduxsub *this_usbduxsub = dev->private;
- if (!this_usbduxsub) {
+ if (!this_usbduxsub)
return -EFAULT;
- }
+
down(&this_usbduxsub->sem);
if (!(this_usbduxsub->probed)) {
up(&this_usbduxsub->sem);
return -ENODEV;
}
- for (i = 0; i < insn->n; i++) {
+ for (i = 0; i < insn->n; i++)
data[i] = this_usbduxsub->outBuffer[chan];
- }
+
up(&this_usbduxsub->sem);
return i;
}
-static int usbdux_ao_insn_write(comedi_device * dev, comedi_subdevice * s,
- comedi_insn * insn, lsampl_t * data)
+static int usbdux_ao_insn_write(struct comedi_device *dev, struct comedi_subdevice *s,
+ struct comedi_insn *insn, unsigned int *data)
{
int i, err;
int chan = CR_CHAN(insn->chanspec);
- usbduxsub_t *this_usbduxsub = dev->private;
+ struct usbduxsub *this_usbduxsub = dev->private;
-#ifdef NOISY_DUX_DEBUGBUG
- printk("comedi%d: ao_insn_write\n", dev->minor);
-#endif
- if (!this_usbduxsub) {
+ if (!this_usbduxsub)
return -EFAULT;
- }
+
+ dev_dbg(&this_usbduxsub->interface->dev,
+ "comedi%d: ao_insn_write\n", dev->minor);
+
down(&this_usbduxsub->sem);
if (!(this_usbduxsub->probed)) {
up(&this_usbduxsub->sem);
return -ENODEV;
}
if (this_usbduxsub->ao_cmd_running) {
- printk("comedi%d: ao_insn_write: ERROR: asynchronous ao_cmd is running\n", dev->minor);
+ dev_err(&this_usbduxsub->interface->dev,
+ "comedi%d: ao_insn_write: "
+ "ERROR: asynchronous ao_cmd is running\n", dev->minor);
up(&this_usbduxsub->sem);
return 0;
}
for (i = 0; i < insn->n; i++) {
-#ifdef NOISY_DUX_DEBUGBUG
- printk("comedi%d: ao_insn_write: data[chan=%d,i=%d]=%d\n",
+ dev_dbg(&this_usbduxsub->interface->dev,
+ "comedi%d: ao_insn_write: data[chan=%d,i=%d]=%d\n",
dev->minor, chan, i, data[i]);
-#endif
- // number of channels: 1
+
+ /* number of channels: 1 */
this_usbduxsub->dux_commands[1] = 1;
- // one 16 bit value
+ /* one 16 bit value */
*((int16_t *) (this_usbduxsub->dux_commands + 2)) =
cpu_to_le16(data[i]);
this_usbduxsub->outBuffer[chan] = data[i];
- // channel number
+ /* channel number */
this_usbduxsub->dux_commands[4] = (chan << 6);
- if ((err = send_dux_commands(this_usbduxsub,
- SENDDACOMMANDS)) < 0) {
+ err = send_dux_commands(this_usbduxsub, SENDDACOMMANDS);
+ if (err < 0) {
up(&this_usbduxsub->sem);
return err;
}
return i;
}
-static int usbdux_ao_inttrig(comedi_device * dev, comedi_subdevice * s,
- unsigned int trignum)
+static int usbdux_ao_inttrig(struct comedi_device *dev, struct comedi_subdevice *s,
+ unsigned int trignum)
{
int ret;
- usbduxsub_t *this_usbduxsub = dev->private;
+ struct usbduxsub *this_usbduxsub = dev->private;
- if (!this_usbduxsub) {
+ if (!this_usbduxsub)
return -EFAULT;
- }
+
down(&this_usbduxsub->sem);
if (!(this_usbduxsub->probed)) {
up(&this_usbduxsub->sem);
return -ENODEV;
}
if (trignum != 0) {
- printk("comedi%d: usbdux_ao_inttrig: invalid trignum\n",
+ dev_err(&this_usbduxsub->interface->dev,
+ "comedi%d: usbdux_ao_inttrig: invalid trignum\n",
dev->minor);
return -EINVAL;
}
this_usbduxsub->ao_cmd_running = 1;
ret = usbduxsub_submit_OutURBs(this_usbduxsub);
if (ret < 0) {
- printk("comedi%d: usbdux_ao_inttrig: submitURB: err=%d\n", dev->minor, ret);
+ dev_err(&this_usbduxsub->interface->dev,
+ "comedi%d: usbdux_ao_inttrig: submitURB: "
+ "err=%d\n", dev->minor, ret);
this_usbduxsub->ao_cmd_running = 0;
up(&this_usbduxsub->sem);
return ret;
}
s->async->inttrig = NULL;
} else {
- printk("comedi%d: ao_inttrig but acqu is already running.\n",
+ dev_err(&this_usbduxsub->interface->dev,
+ "comedi%d: ao_inttrig but acqu is already running.\n",
dev->minor);
}
up(&this_usbduxsub->sem);
return 1;
}
-static int usbdux_ao_cmdtest(comedi_device * dev,
- comedi_subdevice * s, comedi_cmd * cmd)
+static int usbdux_ao_cmdtest(struct comedi_device *dev, struct comedi_subdevice *s,
+ struct comedi_cmd *cmd)
{
int err = 0, tmp;
- usbduxsub_t *this_usbduxsub = dev->private;
+ struct usbduxsub *this_usbduxsub = dev->private;
- if (!this_usbduxsub) {
+ if (!this_usbduxsub)
return -EFAULT;
- }
- if (!(this_usbduxsub->probed)) {
+
+ if (!(this_usbduxsub->probed))
return -ENODEV;
- }
-#ifdef NOISY_DUX_DEBUGBUG
- printk("comedi%d: usbdux_ao_cmdtest\n", dev->minor);
-#endif
+
+ dev_dbg(&this_usbduxsub->interface->dev,
+ "comedi%d: usbdux_ao_cmdtest\n", dev->minor);
+
/* make sure triggers are valid */
- // Only immediate triggers are allowed
+ /* Only immediate triggers are allowed */
tmp = cmd->start_src;
cmd->start_src &= TRIG_NOW | TRIG_INT;
if (!cmd->start_src || tmp != cmd->start_src)
err++;
- // trigger should happen timed
+ /* trigger should happen timed */
tmp = cmd->scan_begin_src;
- // just now we scan also in the high speed mode every frame
- // this is due to ehci driver limitations
+ /* just now we scan also in the high speed mode every frame */
+ /* this is due to ehci driver limitations */
if (0) { /* (this_usbduxsub->high_speed) */
- // start immidiately a new scan
- // the sampling rate is set by the coversion rate
+ /* start immidiately a new scan */
+ /* the sampling rate is set by the coversion rate */
cmd->scan_begin_src &= TRIG_FOLLOW;
} else {
- // start a new scan (output at once) with a timer
+ /* start a new scan (output at once) with a timer */
cmd->scan_begin_src &= TRIG_TIMER;
}
if (!cmd->scan_begin_src || tmp != cmd->scan_begin_src)
err++;
- // scanning is continous
+ /* scanning is continous */
tmp = cmd->convert_src;
- // we always output at 1kHz just now all channels at once
+ /* we always output at 1kHz just now all channels at once */
if (0) { /* (this_usbduxsub->high_speed) */
- // in usb-2.0 only one conversion it tranmitted but with 8kHz/n
+ /*
+ * in usb-2.0 only one conversion it tranmitted but with 8kHz/n
+ */
cmd->convert_src &= TRIG_TIMER;
} else {
- // all conversion events happen simultaneously with a rate of 1kHz/n
+ /* all conversion events happen simultaneously with a rate of
+ * 1kHz/n */
cmd->convert_src &= TRIG_NOW;
}
if (!cmd->convert_src || tmp != cmd->convert_src)
err++;
- // issue a trigger when scan is finished and start a new scan
+ /* issue a trigger when scan is finished and start a new scan */
tmp = cmd->scan_end_src;
cmd->scan_end_src &= TRIG_COUNT;
if (!cmd->scan_end_src || tmp != cmd->scan_end_src)
err++;
- // trigger at the end of count events or not, stop condition or not
+ /* trigger at the end of count events or not, stop condition or not */
tmp = cmd->stop_src;
cmd->stop_src &= TRIG_COUNT | TRIG_NONE;
if (!cmd->stop_src || tmp != cmd->stop_src)
if (err)
return 1;
- /* step 2: make sure trigger sources are unique and mutually compatible */
- /* note that mutual compatiblity is not an issue here */
+ /*
+ * step 2: make sure trigger sources are unique and mutually compatible
+ * note that mutual compatiblity is not an issue here
+ */
if (cmd->scan_begin_src != TRIG_FOLLOW &&
cmd->scan_begin_src != TRIG_EXT &&
cmd->scan_begin_src != TRIG_TIMER)
err++;
}
}
- // not used now, is for later use
+ /* not used now, is for later use */
if (cmd->convert_src == TRIG_TIMER) {
if (cmd->convert_arg < 125000) {
cmd->convert_arg = 125000;
}
}
- // the same argument
+ /* the same argument */
if (cmd->scan_end_arg != cmd->chanlist_len) {
cmd->scan_end_arg = cmd->chanlist_len;
err++;
}
}
-#ifdef NOISY_DUX_DEBUGBUG
- printk("comedi%d: err=%d, scan_begin_src=%d, scan_begin_arg=%d, convert_src=%d, convert_arg=%d\n", dev->minor, err, cmd->scan_begin_src, cmd->scan_begin_arg, cmd->convert_src, cmd->convert_arg);
-#endif
+ dev_dbg(&this_usbduxsub->interface->dev, "comedi%d: err=%d, "
+ "scan_begin_src=%d, scan_begin_arg=%d, convert_src=%d, "
+ "convert_arg=%d\n", dev->minor, err, cmd->scan_begin_src,
+ cmd->scan_begin_arg, cmd->convert_src, cmd->convert_arg);
if (err)
return 3;
return 0;
}
-static int usbdux_ao_cmd(comedi_device * dev, comedi_subdevice * s)
+static int usbdux_ao_cmd(struct comedi_device *dev, struct comedi_subdevice *s)
{
- comedi_cmd *cmd = &s->async->cmd;
+ struct comedi_cmd *cmd = &s->async->cmd;
unsigned int chan, gain;
int i, ret;
- usbduxsub_t *this_usbduxsub = dev->private;
+ struct usbduxsub *this_usbduxsub = dev->private;
- if (!this_usbduxsub) {
+ if (!this_usbduxsub)
return -EFAULT;
- }
+
down(&this_usbduxsub->sem);
if (!(this_usbduxsub->probed)) {
up(&this_usbduxsub->sem);
return -ENODEV;
}
-#ifdef NOISY_DUX_DEBUGBUG
- printk("comedi%d: usbdux_ao_cmd\n", dev->minor);
-#endif
+ dev_dbg(&this_usbduxsub->interface->dev,
+ "comedi%d: %s\n", dev->minor, __func__);
- // set current channel of the running aquisition to zero
+ /* set current channel of the running aquisition to zero */
s->async->cur_chan = 0;
for (i = 0; i < cmd->chanlist_len; ++i) {
chan = CR_CHAN(cmd->chanlist[i]);
gain = CR_RANGE(cmd->chanlist[i]);
if (i >= NUMOUTCHANNELS) {
- printk("comedi%d: usbdux_ao_cmd: channel list too long\n", dev->minor);
+ dev_err(&this_usbduxsub->interface->dev,
+ "comedi%d: %s: channel list too long\n",
+ dev->minor, __func__);
break;
}
this_usbduxsub->dac_commands[i] = (chan << 6);
-#ifdef NOISY_DUX_DEBUGBUG
- printk("comedi%d: dac command for ch %d is %x\n",
+ dev_dbg(&this_usbduxsub->interface->dev,
+ "comedi%d: dac command for ch %d is %x\n",
dev->minor, i, this_usbduxsub->dac_commands[i]);
-#endif
}
- // we count in steps of 1ms (125us)
- // 125us mode not used yet
+ /* we count in steps of 1ms (125us) */
+ /* 125us mode not used yet */
if (0) { /* (this_usbduxsub->high_speed) */
- // 125us
- // timing of the conversion itself: every 125 us
+ /* 125us */
+ /* timing of the conversion itself: every 125 us */
this_usbduxsub->ao_timer = cmd->convert_arg / 125000;
} else {
- // 1ms
- // timing of the scan: we get all channels at once
+ /* 1ms */
+ /* timing of the scan: we get all channels at once */
this_usbduxsub->ao_timer = cmd->scan_begin_arg / 1000000;
-#ifdef NOISY_DUX_DEBUGBUG
- printk("comedi%d: usbdux: scan_begin_src=%d, scan_begin_arg=%d, convert_src=%d, convert_arg=%d\n", dev->minor, cmd->scan_begin_src, cmd->scan_begin_arg, cmd->convert_src, cmd->convert_arg);
- printk("comedi%d: usbdux: ao_timer=%d (ms)\n",
+ dev_dbg(&this_usbduxsub->interface->dev,
+ "comedi%d: scan_begin_src=%d, scan_begin_arg=%d, "
+ "convert_src=%d, convert_arg=%d\n", dev->minor,
+ cmd->scan_begin_src, cmd->scan_begin_arg,
+ cmd->convert_src, cmd->convert_arg);
+ dev_dbg(&this_usbduxsub->interface->dev,
+ "comedi%d: ao_timer=%d (ms)\n",
dev->minor, this_usbduxsub->ao_timer);
-#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);
+ dev_err(&this_usbduxsub->interface->dev,
+ "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);
return -EINVAL;
}
this_usbduxsub->ao_counter = this_usbduxsub->ao_timer;
if (cmd->stop_src == TRIG_COUNT) {
- // not continous
- // counter
- // high speed also scans everything at once
+ /* not continous */
+ /* counter */
+ /* high speed also scans everything at once */
if (0) { /* (this_usbduxsub->high_speed) */
this_usbduxsub->ao_sample_count =
(cmd->stop_arg) * (cmd->scan_end_arg);
} else {
- // there's no scan as the scan has been
- // perf inside the FX2
- // data arrives as one packet
+ /* there's no scan as the scan has been */
+ /* perf inside the FX2 */
+ /* data arrives as one packet */
this_usbduxsub->ao_sample_count = cmd->stop_arg;
}
this_usbduxsub->ao_continous = 0;
} else {
- // continous aquisition
+ /* continous aquisition */
this_usbduxsub->ao_continous = 1;
this_usbduxsub->ao_sample_count = 0;
}
if (cmd->start_src == TRIG_NOW) {
- // enable this acquisition operation
+ /* enable this acquisition operation */
this_usbduxsub->ao_cmd_running = 1;
ret = usbduxsub_submit_OutURBs(this_usbduxsub);
if (ret < 0) {
this_usbduxsub->ao_cmd_running = 0;
- // fixme: unlink here??
+ /* fixme: unlink here?? */
up(&this_usbduxsub->sem);
return ret;
}
s->async->inttrig = NULL;
} else {
/* TRIG_INT */
- // submit the urbs later
- // wait for an internal signal
+ /* submit the urbs later */
+ /* wait for an internal signal */
s->async->inttrig = usbdux_ao_inttrig;
}
return 0;
}
-static int usbdux_dio_insn_config(comedi_device * dev,
- comedi_subdevice * s, comedi_insn * insn, lsampl_t * data)
+static int usbdux_dio_insn_config(struct comedi_device *dev, struct comedi_subdevice *s,
+ struct comedi_insn *insn, unsigned int *data)
{
int chan = CR_CHAN(insn->chanspec);
return -EINVAL;
break;
}
- // we don't tell the firmware here as it would take 8 frames
- // to submit the information. We do it in the insn_bits.
+ /* we don't tell the firmware here as it would take 8 frames */
+ /* to submit the information. We do it in the insn_bits. */
return insn->n;
}
-static int usbdux_dio_insn_bits(comedi_device * dev,
- comedi_subdevice * s, comedi_insn * insn, lsampl_t * data)
+static int usbdux_dio_insn_bits(struct comedi_device *dev, struct comedi_subdevice *s,
+ struct comedi_insn *insn, unsigned int *data)
{
- usbduxsub_t *this_usbduxsub = dev->private;
+ struct usbduxsub *this_usbduxsub = dev->private;
int err;
- if (!this_usbduxsub) {
+ if (!this_usbduxsub)
return -EFAULT;
- }
+
if (insn->n != 2)
return -EINVAL;
this_usbduxsub->dux_commands[1] = s->io_bits;
this_usbduxsub->dux_commands[2] = s->state;
- // This command also tells the firmware to return
- // the digital input lines
- if ((err = send_dux_commands(this_usbduxsub, SENDDIOBITSCOMMAND)) < 0) {
+ /* This command also tells the firmware to return */
+ /* the digital input lines */
+ err = send_dux_commands(this_usbduxsub, SENDDIOBITSCOMMAND);
+ if (err < 0) {
up(&this_usbduxsub->sem);
return err;
}
- if ((err = receive_dux_commands(this_usbduxsub,
- SENDDIOBITSCOMMAND)) < 0) {
+ err = receive_dux_commands(this_usbduxsub, SENDDIOBITSCOMMAND);
+ if (err < 0) {
up(&this_usbduxsub->sem);
return err;
}
return 2;
}
-// reads the 4 counters
-// only two are used just now
-static int usbdux_counter_read(comedi_device * dev, comedi_subdevice * s,
- comedi_insn * insn, lsampl_t * data)
+/* reads the 4 counters, only two are used just now */
+static int usbdux_counter_read(struct comedi_device *dev, struct comedi_subdevice *s,
+ struct comedi_insn *insn, unsigned int *data)
{
- usbduxsub_t *this_usbduxsub = dev->private;
+ struct usbduxsub *this_usbduxsub = dev->private;
int chan = insn->chanspec;
int err;
- if (!this_usbduxsub) {
+ if (!this_usbduxsub)
return -EFAULT;
- }
down(&this_usbduxsub->sem);
return -ENODEV;
}
- if ((err = send_dux_commands(this_usbduxsub, READCOUNTERCOMMAND)) < 0) {
+ err = send_dux_commands(this_usbduxsub, READCOUNTERCOMMAND);
+ if (err < 0) {
up(&this_usbduxsub->sem);
return err;
}
- if ((err = receive_dux_commands(this_usbduxsub,
- READCOUNTERCOMMAND)) < 0) {
+ err = receive_dux_commands(this_usbduxsub, READCOUNTERCOMMAND);
+ if (err < 0) {
up(&this_usbduxsub->sem);
return err;
}
return 1;
}
-static int usbdux_counter_write(comedi_device * dev, comedi_subdevice * s,
- comedi_insn * insn, lsampl_t * data)
+static int usbdux_counter_write(struct comedi_device *dev, struct comedi_subdevice *s,
+ struct comedi_insn *insn, unsigned int *data)
{
- usbduxsub_t *this_usbduxsub = dev->private;
+ struct usbduxsub *this_usbduxsub = dev->private;
int err;
- if (!this_usbduxsub) {
+ if (!this_usbduxsub)
return -EFAULT;
- }
down(&this_usbduxsub->sem);
this_usbduxsub->dux_commands[1] = insn->chanspec;
*((int16_t *) (this_usbduxsub->dux_commands + 2)) = cpu_to_le16(*data);
- if ((err = send_dux_commands(this_usbduxsub, WRITECOUNTERCOMMAND)) < 0) {
+ err = send_dux_commands(this_usbduxsub, WRITECOUNTERCOMMAND);
+ if (err < 0) {
up(&this_usbduxsub->sem);
return err;
}
return 1;
}
-static int usbdux_counter_config(comedi_device * dev, comedi_subdevice * s,
- comedi_insn * insn, lsampl_t * data)
+static int usbdux_counter_config(struct comedi_device *dev, struct comedi_subdevice *s,
+ struct comedi_insn *insn, unsigned int *data)
{
- // nothing to do so far
+ /* nothing to do so far */
return 2;
}
-/////////////////////////////
-// PWM
+/***********************************/
+/* PWM */
-static int usbduxsub_unlink_PwmURBs(usbduxsub_t * usbduxsub_tmp)
+static int usbduxsub_unlink_PwmURBs(struct usbduxsub *usbduxsub_tmp)
{
int err = 0;
if (usbduxsub_tmp && usbduxsub_tmp->urbPwm) {
if (usbduxsub_tmp->urbPwm)
usb_kill_urb(usbduxsub_tmp->urbPwm);
-#ifdef NOISY_DUX_DEBUGBUG
- printk("comedi: usbdux: unlinked PwmURB: res=%d\n", err);
-#endif
+ dev_dbg(&usbduxsub_tmp->interface->dev,
+ "comedi: unlinked PwmURB: res=%d\n", err);
}
return err;
}
/* This cancels a running acquisition operation
* in any context.
*/
-static int usbdux_pwm_stop(usbduxsub_t * this_usbduxsub, int do_unlink)
+static int usbdux_pwm_stop(struct usbduxsub *this_usbduxsub, int do_unlink)
{
int ret = 0;
- if (!this_usbduxsub) {
-#ifdef NOISY_DUX_DEBUGBUG
- printk("comedi?: usbdux_pwm_stop: this_usbduxsub=NULL!\n");
-#endif
+ if (!this_usbduxsub)
return -EFAULT;
- }
-#ifdef NOISY_DUX_DEBUGBUG
- printk("comedi: usbdux_pwm_cancel\n");
-#endif
- if (do_unlink) {
+
+ dev_dbg(&this_usbduxsub->interface->dev, "comedi: %s\n", __func__);
+ if (do_unlink)
ret = usbduxsub_unlink_PwmURBs(this_usbduxsub);
- }
+
this_usbduxsub->pwm_cmd_running = 0;
return ret;
}
-// force unlink
-// is called by comedi
-static int usbdux_pwm_cancel(comedi_device * dev, comedi_subdevice * s)
+/* force unlink - is called by comedi */
+static int usbdux_pwm_cancel(struct comedi_device *dev, struct comedi_subdevice *s)
{
- usbduxsub_t *this_usbduxsub = dev->private;
+ struct usbduxsub *this_usbduxsub = dev->private;
int res = 0;
- // unlink only if it is really running
+ /* unlink only if it is really running */
res = usbdux_pwm_stop(this_usbduxsub, this_usbduxsub->pwm_cmd_running);
-#ifdef NOISY_DUX_DEBUGBUG
- printk("comedi %d: sending pwm off command to the usb device.\n",
+ dev_dbg(&this_usbduxsub->interface->dev,
+ "comedi %d: sending pwm off command to the usb device.\n",
dev->minor);
-#endif
- if ((res = send_dux_commands(this_usbduxsub, SENDPWMOFF)) < 0) {
+ res = send_dux_commands(this_usbduxsub, SENDPWMOFF);
+ if (res < 0)
return res;
- }
return res;
}
static void usbduxsub_pwm_irq(struct urb *urb)
{
int ret;
- usbduxsub_t *this_usbduxsub;
- comedi_device *this_comedidev;
- comedi_subdevice *s;
+ struct usbduxsub *this_usbduxsub;
+ struct comedi_device *this_comedidev;
+ struct comedi_subdevice *s;
- // printk("PWM: IRQ\n");
+ /* printk(KERN_DEBUG "PWM: IRQ\n"); */
- if (!urb) {
- printk("comedi_: usbdux_: pwm urb handler called with NULL ptr.\n");
- return;
- }
- // the context variable points to the subdevice
+ /* the context variable points to the subdevice */
this_comedidev = urb->context;
- if (!this_comedidev) {
- printk("comedi_: usbdux_: pwm urb int-context is a NULL pointer.\n");
- return;
- }
- // the private structure of the subdevice is usbduxsub_t
+ /* the private structure of the subdevice is struct usbduxsub */
this_usbduxsub = this_comedidev->private;
- if (!this_usbduxsub) {
- printk("comedi_: usbdux_: private data structure of pwm subdev is NULL p.\n");
- return;
- }
s = this_comedidev->subdevices + SUBDEV_DA;
/* success */
break;
- // after an unlink command, unplug, ... etc
- // no unlink needed here. Already shutting down.
case -ECONNRESET:
case -ENOENT:
case -ESHUTDOWN:
case -ECONNABORTED:
- if (this_usbduxsub->pwm_cmd_running) {
+ /*
+ * after an unlink command, unplug, ... etc
+ * no unlink needed here. Already shutting down.
+ */
+ if (this_usbduxsub->pwm_cmd_running)
usbdux_pwm_stop(this_usbduxsub, 0);
- }
+
return;
- // a real error
default:
+ /* a real error */
if (this_usbduxsub->pwm_cmd_running) {
- printk("comedi_: usbdux_: Non-zero urb status received in pwm intr context: %d\n", urb->status);
+ dev_err(&this_usbduxsub->interface->dev,
+ "comedi_: Non-zero urb status received in "
+ "pwm intr context: %d\n", urb->status);
usbdux_pwm_stop(this_usbduxsub, 0);
}
return;
}
- // are we actually running?
- if (!(this_usbduxsub->pwm_cmd_running)) {
+ /* are we actually running? */
+ if (!(this_usbduxsub->pwm_cmd_running))
return;
- }
urb->transfer_buffer_length = this_usbduxsub->sizePwmBuf;
urb->dev = this_usbduxsub->usbdev;
urb->status = 0;
if (this_usbduxsub->pwm_cmd_running) {
- if ((ret = USB_SUBMIT_URB(urb)) < 0) {
- printk("comedi_: usbdux_: pwm urb resubm failed in int-cont.");
- printk("ret=%d", ret);
- if (ret == EL2NSYNC) {
- printk("--> buggy USB host controller or bug in IRQ handling!\n");
- } else {
- printk("\n");
- }
- // don't do an unlink here
+ ret = usb_submit_urb(urb, GFP_ATOMIC);
+ if (ret < 0) {
+ dev_err(&this_usbduxsub->interface->dev,
+ "comedi_: pwm urb resubm failed in int-cont. "
+ "ret=%d", ret);
+ if (ret == EL2NSYNC)
+ dev_err(&this_usbduxsub->interface->dev,
+ "buggy USB host controller or bug in "
+ "IRQ handling!\n");
+
+ /* don't do an unlink here */
usbdux_pwm_stop(this_usbduxsub, 0);
}
}
}
-int usbduxsub_submit_PwmURBs(usbduxsub_t * usbduxsub)
+static int usbduxsub_submit_PwmURBs(struct usbduxsub *usbduxsub)
{
int errFlag;
- if (!usbduxsub) {
+ if (!usbduxsub)
return -EFAULT;
- }
-#ifdef NOISY_DUX_DEBUGBUG
- printk("comedi_: usbdux: submitting pwm-urb\n");
-#endif
- // in case of a resubmission after an unlink...
+ dev_dbg(&usbduxsub->interface->dev, "comedi_: submitting pwm-urb\n");
+
+ /* in case of a resubmission after an unlink... */
usb_fill_bulk_urb(usbduxsub->urbPwm,
usbduxsub->usbdev,
usb_sndbulkpipe(usbduxsub->usbdev, PWM_EP),
usbduxsub->urbPwm->transfer_buffer,
usbduxsub->sizePwmBuf, usbduxsub_pwm_irq, usbduxsub->comedidev);
- errFlag = USB_SUBMIT_URB(usbduxsub->urbPwm);
+ errFlag = usb_submit_urb(usbduxsub->urbPwm, GFP_ATOMIC);
if (errFlag) {
- printk("comedi_: usbdux: pwm: ");
- printk("USB_SUBMIT_URB");
- printk(" error %d\n", errFlag);
+ dev_err(&usbduxsub->interface->dev,
+ "comedi_: usbdux: pwm: usb_submit_urb error %d\n",
+ errFlag);
return errFlag;
}
return 0;
}
-static int usbdux_pwm_period(comedi_device * dev, comedi_subdevice * s,
- lsampl_t period)
+static int usbdux_pwm_period(struct comedi_device *dev, struct comedi_subdevice *s,
+ unsigned int period)
{
- usbduxsub_t *this_usbduxsub = dev->private;
- int fx2delay=255;
- if (period < MIN_PWM_PERIOD)
- {
- printk("comedi%d: illegal period setting for pwm.\n", dev->minor);
+ struct usbduxsub *this_usbduxsub = dev->private;
+ int fx2delay = 255;
+
+ if (period < MIN_PWM_PERIOD) {
+ dev_err(&this_usbduxsub->interface->dev,
+ "comedi%d: illegal period setting for pwm.\n",
+ dev->minor);
return -EAGAIN;
} else {
fx2delay = period / ((int)(6*512*(1.0/0.033))) - 6;
if (fx2delay > 255) {
- printk("comedi%d: period %d for pwm is too low.\n",
+ dev_err(&this_usbduxsub->interface->dev,
+ "comedi%d: period %d for pwm is too low.\n",
dev->minor, period);
return -EAGAIN;
}
}
- this_usbduxsub->pwmDelay=fx2delay;
- this_usbduxsub->pwmPeriod=period;
-#ifdef NOISY_DUX_DEBUGBUG
- printk("usbdux_pwm_period: frequ=%d, period=%d\n",period,fx2delay);
-#endif
+ this_usbduxsub->pwmDelay = fx2delay;
+ this_usbduxsub->pwmPeriod = period;
+ dev_dbg(&this_usbduxsub->interface->dev, "%s: frequ=%d, period=%d\n",
+ __func__, period, fx2delay);
return 0;
}
-
-// is called from insn so there's no need to do all the sanity checks
-static int usbdux_pwm_start(comedi_device * dev, comedi_subdevice * s)
+/* is called from insn so there's no need to do all the sanity checks */
+static int usbdux_pwm_start(struct comedi_device *dev, struct comedi_subdevice *s)
{
int ret, i;
- usbduxsub_t *this_usbduxsub = dev->private;
+ struct usbduxsub *this_usbduxsub = dev->private;
+
+ dev_dbg(&this_usbduxsub->interface->dev, "comedi%d: %s\n",
+ dev->minor, __func__);
-#ifdef NOISY_DUX_DEBUGBUG
- printk("comedi%d: usbdux_pwm_start\n", dev->minor);
-#endif
if (this_usbduxsub->pwm_cmd_running) {
- // already running
+ /* already running */
return 0;
}
this_usbduxsub->dux_commands[1] = ((int8_t) this_usbduxsub->pwmDelay);
- if ((ret = send_dux_commands(this_usbduxsub, SENDPWMON)) < 0) {
+ ret = send_dux_commands(this_usbduxsub, SENDPWMON);
+ if (ret < 0)
return ret;
- }
- // initalise the buffer
- for (i = 0; i < this_usbduxsub->sizePwmBuf; i++) {
+
+ /* initalise the buffer */
+ for (i = 0; i < this_usbduxsub->sizePwmBuf; i++)
((char *)(this_usbduxsub->urbPwm->transfer_buffer))[i] = 0;
- }
this_usbduxsub->pwm_cmd_running = 1;
ret = usbduxsub_submit_PwmURBs(this_usbduxsub);
return 0;
}
-
-// generates the bit pattern for PWM with the optional sign bit
-static int usbdux_pwm_pattern(comedi_device * dev, comedi_subdevice * s,
- int channel, lsampl_t value, lsampl_t sign)
+/* generates the bit pattern for PWM with the optional sign bit */
+static int usbdux_pwm_pattern(struct comedi_device *dev, struct comedi_subdevice *s,
+ int channel, unsigned int value, unsigned int sign)
{
- usbduxsub_t *this_usbduxsub = dev->private;
+ struct usbduxsub *this_usbduxsub = dev->private;
int i, szbuf;
char *pBuf;
- char pwm_mask,sgn_mask,c;
+ char pwm_mask;
+ char sgn_mask;
+ char c;
- if (!this_usbduxsub) {
+ if (!this_usbduxsub)
return -EFAULT;
- }
- // this is the DIO bit which carries the PWM data
+
+ /* this is the DIO bit which carries the PWM data */
pwm_mask = (1 << channel);
- // this is the DIO bit which carries the optional direction bit
+ /* this is the DIO bit which carries the optional direction bit */
sgn_mask = (16 << channel);
- // this is the buffer which will be filled with the with bit
- // pattern for one period
+ /* this is the buffer which will be filled with the with bit */
+ /* pattern for one period */
szbuf = this_usbduxsub->sizePwmBuf;
pBuf = (char *)(this_usbduxsub->urbPwm->transfer_buffer);
for (i = 0; i < szbuf; i++) {
c = *pBuf;
- // reset bits
+ /* reset bits */
c = c & (~pwm_mask);
- // set the bit as long as the index is lower than the value
+ /* set the bit as long as the index is lower than the value */
if (i < value)
c = c | pwm_mask;
- // set the optional sign bit for a relay
+ /* set the optional sign bit for a relay */
if (!sign) {
- // positive value
+ /* positive value */
c = c & (~sgn_mask);
} else {
- // negative value
+ /* negative value */
c = c | sgn_mask;
}
*(pBuf++) = c;
return 1;
}
-static int usbdux_pwm_write(comedi_device * dev, comedi_subdevice * s,
- comedi_insn * insn, lsampl_t * data)
+static int usbdux_pwm_write(struct comedi_device *dev, struct comedi_subdevice *s,
+ struct comedi_insn *insn, unsigned int *data)
{
- usbduxsub_t *this_usbduxsub = dev->private;
+ struct usbduxsub *this_usbduxsub = dev->private;
- if (!this_usbduxsub) {
+ if (!this_usbduxsub)
return -EFAULT;
- }
- if ((insn->n)!=1) {
- // doesn't make sense to have more than one value here
- // because it would just overwrite the PWM buffer a couple of times
+ if ((insn->n) != 1) {
+ /*
+ * doesn't make sense to have more than one value here because
+ * it would just overwrite the PWM buffer a couple of times
+ */
return -EINVAL;
}
- // the sign is set via a special INSN only, this gives us 8 bits for
- // normal operation
- return usbdux_pwm_pattern(dev,s,
- CR_CHAN(insn->chanspec),
- data[0],
- 0); // relay sign 0 by default
+ /*
+ * the sign is set via a special INSN only, this gives us 8 bits for
+ * normal operation
+ * relay sign 0 by default
+ */
+ return usbdux_pwm_pattern(dev, s, CR_CHAN(insn->chanspec),
+ data[0], 0);
}
-
-static int usbdux_pwm_read(comedi_device * x1, comedi_subdevice * x2,
- comedi_insn * x3, lsampl_t * x4)
+static int usbdux_pwm_read(struct comedi_device *x1, struct comedi_subdevice *x2,
+ struct comedi_insn *x3, unsigned int *x4)
{
- // not needed
+ /* not needed */
return -EINVAL;
};
-// switches on/off PWM
-static int usbdux_pwm_config(comedi_device * dev, comedi_subdevice * s,
- comedi_insn * insn, lsampl_t * data)
+/* switches on/off PWM */
+static int usbdux_pwm_config(struct comedi_device *dev, struct comedi_subdevice *s,
+ struct comedi_insn *insn, unsigned int *data)
{
- usbduxsub_t *this_usbduxsub = dev->private;
+ struct usbduxsub *this_usbduxsub = dev->private;
switch (data[0]) {
case INSN_CONFIG_ARM:
-#ifdef NOISY_DUX_DEBUGBUG
- // switch it on
- printk("comedi%d: pwm_insn_config: pwm on\n",
- dev->minor);
-#endif
- // if not zero the PWM is limited to a certain time which is
- // not supported here
- if (data[1]!=0) {
+ /* switch it on */
+ dev_dbg(&this_usbduxsub->interface->dev,
+ "comedi%d: %s: pwm on\n", dev->minor, __func__);
+ /*
+ * if not zero the PWM is limited to a certain time which is
+ * not supported here
+ */
+ if (data[1] != 0)
return -EINVAL;
- }
return usbdux_pwm_start(dev, s);
case INSN_CONFIG_DISARM:
-#ifdef NOISY_DUX_DEBUGBUG
- printk("comedi%d: pwm_insn_config: pwm off\n",
- dev->minor);
-#endif
+ dev_dbg(&this_usbduxsub->interface->dev,
+ "comedi%d: %s: pwm off\n", dev->minor, __func__);
return usbdux_pwm_cancel(dev, s);
case INSN_CONFIG_GET_PWM_STATUS:
- // to check if the USB transmission has failed or in case
- // PWM was limited to n cycles to check if it has terminated
+ /*
+ * to check if the USB transmission has failed or in case PWM
+ * was limited to n cycles to check if it has terminated
+ */
data[1] = this_usbduxsub->pwm_cmd_running;
return 0;
case INSN_CONFIG_PWM_SET_PERIOD:
-#ifdef NOISY_DUX_DEBUGBUG
- printk("comedi%d: pwm_insn_config: setting period\n",
- dev->minor);
-#endif
- return usbdux_pwm_period(dev,s,data[1]);
+ dev_dbg(&this_usbduxsub->interface->dev,
+ "comedi%d: %s: setting period\n", dev->minor, __func__);
+ return usbdux_pwm_period(dev, s, data[1]);
case INSN_CONFIG_PWM_GET_PERIOD:
data[1] = this_usbduxsub->pwmPeriod;
return 0;
case INSN_CONFIG_PWM_SET_H_BRIDGE:
- // value in the first byte and the sign in the second for a relay
+ /* value in the first byte and the sign in the second for a
+ relay */
return usbdux_pwm_pattern(dev, s,
- CR_CHAN(insn->chanspec), // the channel number
- data[1], // actual PWM data
- (data[2]!=0)); // just a sign
+ /* the channel number */
+ CR_CHAN(insn->chanspec),
+ /* actual PWM data */
+ data[1],
+ /* just a sign */
+ (data[2] != 0));
case INSN_CONFIG_PWM_GET_H_BRIDGE:
- // values are not kept in this driver, nothing to return here
+ /* values are not kept in this driver, nothing to return here */
return -EINVAL;
}
return -EINVAL;
}
-// end of PWM
-///////////////////////////////////////////////////////////////////
+/* end of PWM */
+/*****************************************************************/
-static void tidy_up(usbduxsub_t * usbduxsub_tmp)
+static void tidy_up(struct usbduxsub *usbduxsub_tmp)
{
int i;
-#ifdef CONFIG_COMEDI_DEBUG
- printk("comedi_: usbdux: tiding up\n");
-#endif
- if (!usbduxsub_tmp) {
+ if (!usbduxsub_tmp)
return;
- }
- // shows the usb subsystem that the driver is down
+ dev_dbg(&usbduxsub_tmp->interface->dev, "comedi_: tiding up\n");
+
+ /* shows the usb subsystem that the driver is down */
if (usbduxsub_tmp->interface)
usb_set_intfdata(usbduxsub_tmp->interface, NULL);
usbduxsub_unlink_InURBs(usbduxsub_tmp);
}
for (i = 0; i < usbduxsub_tmp->numOfInBuffers; i++) {
- if (usbduxsub_tmp->urbIn[i]->transfer_buffer) {
- kfree(usbduxsub_tmp->urbIn[i]->transfer_buffer);
- usbduxsub_tmp->urbIn[i]->transfer_buffer = NULL;
- }
- if (usbduxsub_tmp->urbIn[i]) {
- usb_kill_urb(usbduxsub_tmp->urbIn[i]);
- usb_free_urb(usbduxsub_tmp->urbIn[i]);
- usbduxsub_tmp->urbIn[i] = NULL;
- }
+ kfree(usbduxsub_tmp->urbIn[i]->transfer_buffer);
+ usbduxsub_tmp->urbIn[i]->transfer_buffer = NULL;
+ usb_kill_urb(usbduxsub_tmp->urbIn[i]);
+ usb_free_urb(usbduxsub_tmp->urbIn[i]);
+ usbduxsub_tmp->urbIn[i] = NULL;
}
kfree(usbduxsub_tmp->urbIn);
usbduxsub_tmp->urbIn = NULL;
usbduxsub_tmp->pwm_cmd_running = 0;
usbduxsub_unlink_PwmURBs(usbduxsub_tmp);
}
- if (usbduxsub_tmp->urbPwm->transfer_buffer) {
- kfree(usbduxsub_tmp->urbPwm->transfer_buffer);
- usbduxsub_tmp->urbPwm->transfer_buffer = NULL;
- }
+ kfree(usbduxsub_tmp->urbPwm->transfer_buffer);
+ usbduxsub_tmp->urbPwm->transfer_buffer = NULL;
usb_kill_urb(usbduxsub_tmp->urbPwm);
usb_free_urb(usbduxsub_tmp->urbPwm);
usbduxsub_tmp->urbPwm = NULL;
}
- if (usbduxsub_tmp->inBuffer) {
- kfree(usbduxsub_tmp->inBuffer);
- usbduxsub_tmp->inBuffer = NULL;
- }
- if (usbduxsub_tmp->insnBuffer) {
- kfree(usbduxsub_tmp->insnBuffer);
- usbduxsub_tmp->insnBuffer = NULL;
- }
- if (usbduxsub_tmp->inBuffer) {
- kfree(usbduxsub_tmp->inBuffer);
- usbduxsub_tmp->inBuffer = NULL;
- }
- if (usbduxsub_tmp->dac_commands) {
- kfree(usbduxsub_tmp->dac_commands);
- usbduxsub_tmp->dac_commands = NULL;
- }
- if (usbduxsub_tmp->dux_commands) {
- kfree(usbduxsub_tmp->dux_commands);
- usbduxsub_tmp->dux_commands = NULL;
- }
+ kfree(usbduxsub_tmp->inBuffer);
+ usbduxsub_tmp->inBuffer = NULL;
+ kfree(usbduxsub_tmp->insnBuffer);
+ usbduxsub_tmp->insnBuffer = NULL;
+ kfree(usbduxsub_tmp->inBuffer);
+ usbduxsub_tmp->inBuffer = NULL;
+ kfree(usbduxsub_tmp->dac_commands);
+ usbduxsub_tmp->dac_commands = NULL;
+ kfree(usbduxsub_tmp->dux_commands);
+ usbduxsub_tmp->dux_commands = NULL;
usbduxsub_tmp->ai_cmd_running = 0;
usbduxsub_tmp->ao_cmd_running = 0;
usbduxsub_tmp->pwm_cmd_running = 0;
}
-static unsigned hex2unsigned(char *h)
-{
- unsigned hi, lo;
- if (h[0] > '9') {
- hi = h[0] - 'A' + 0x0a;
- } else {
- hi = h[0] - '0';
- }
- if (h[1] > '9') {
- lo = h[1] - 'A' + 0x0a;
- } else {
- lo = h[1] - '0';
- }
- return hi * 0x10 + lo;
-}
-
-// for FX2
-#define FIRMWARE_MAX_LEN 0x2000
-
-// taken from David Brownell's fxload and adjusted for this driver
-static int read_firmware(usbduxsub_t * usbduxsub, void *firmwarePtr, long size)
+static void usbdux_firmware_request_complete_handler(const struct firmware *fw,
+ void *context)
{
- int i = 0;
- unsigned char *fp = (char *)firmwarePtr;
- unsigned char *firmwareBinary = NULL;
- int res = 0;
- int maxAddr = 0;
+ struct usbduxsub *usbduxsub_tmp = context;
+ struct usb_device *usbdev = usbduxsub_tmp->usbdev;
+ int ret;
- firmwareBinary = kzalloc(FIRMWARE_MAX_LEN, GFP_KERNEL);
- if (!firmwareBinary) {
- printk("comedi_: usbdux: mem alloc for firmware failed\n");
- return -ENOMEM;
+ if (fw == NULL) {
+ dev_err(&usbdev->dev,
+ "Firmware complete handler without firmware!\n");
+ return;
}
- for (;;) {
- char buf[256], *cp;
- char type;
- int len;
- int idx, off;
- int j = 0;
-
- // get one line
- while ((i < size) && (fp[i] != 13) && (fp[i] != 10)) {
- buf[j] = fp[i];
- i++;
- j++;
- if (j >= sizeof(buf)) {
- printk("comedi_: usbdux: bogus firmware file!\n");
- return -1;
- }
- }
- // get rid of LF/CR/...
- while ((i < size) && ((fp[i] == 13) || (fp[i] == 10)
- || (fp[i] == 0))) {
- i++;
- }
-
- buf[j] = 0;
- //printk("comedi_: buf=%s\n",buf);
-
- /* EXTENSION: "# comment-till-end-of-line", for copyrights etc */
- if (buf[0] == '#')
- continue;
-
- if (buf[0] != ':') {
- printk("comedi_: usbdux: upload: not an ihex record: %s", buf);
- return -EFAULT;
- }
-
- /* Read the length field (up to 16 bytes) */
- len = hex2unsigned(buf + 1);
-
- /* Read the target offset */
- off = (hex2unsigned(buf + 3) * 0x0100) + hex2unsigned(buf + 5);
-
- if ((off + len) > maxAddr) {
- maxAddr = off + len;
- }
-
- if (maxAddr >= FIRMWARE_MAX_LEN) {
- printk("comedi_: usbdux: firmware upload goes beyond FX2 RAM boundaries.");
- return -EFAULT;
- }
- //printk("comedi_: usbdux: off=%x, len=%x:",off,len);
-
- /* Read the record type */
- type = hex2unsigned(buf + 7);
-
- /* If this is an EOF record, then make it so. */
- if (type == 1) {
- break;
- }
-
- if (type != 0) {
- printk("comedi_: usbdux: unsupported record type: %u\n",
- type);
- return -EFAULT;
- }
-
- for (idx = 0, cp = buf + 9; idx < len; idx += 1, cp += 2) {
- firmwareBinary[idx + off] = hex2unsigned(cp);
- //printk("%02x ",firmwareBinary[idx+off]);
- }
- //printk("\n");
-
- if (i >= size) {
- printk("comedi_: usbdux: unexpected end of hex file\n");
- break;
- }
+ /*
+ * we need to upload the firmware here because fw will be
+ * freed once we've left this function
+ */
+ ret = firmwareUpload(usbduxsub_tmp, fw->data, fw->size);
+ if (ret) {
+ dev_err(&usbdev->dev,
+ "Could not upload firmware (err=%d)\n",
+ ret);
+ return;
}
- res = firmwareUpload(usbduxsub, firmwareBinary, maxAddr + 1);
- kfree(firmwareBinary);
- return res;
+ comedi_usb_auto_config(usbdev, BOARDNAME);
}
-// allocate memory for the urbs and initialise them
+/* allocate memory for the urbs and initialise them */
static int usbduxsub_probe(struct usb_interface *uinterf,
- const struct usb_device_id *id)
+ const struct usb_device_id *id)
{
struct usb_device *udev = interface_to_usbdev(uinterf);
+ struct device *dev = &uinterf->dev;
int i;
int index;
+ int ret;
+
+ dev_dbg(dev, "comedi_: usbdux_: "
+ "finding a free structure for the usb-device\n");
-#ifdef CONFIG_COMEDI_DEBUG
- printk("comedi_: usbdux_: finding a free structure for the usb-device\n");
-#endif
down(&start_stop_sem);
- // look for a free place in the usbdux array
+ /* look for a free place in the usbdux array */
index = -1;
for (i = 0; i < NUMUSBDUX; i++) {
if (!(usbduxsub[i].probed)) {
}
}
- // no more space
+ /* no more space */
if (index == -1) {
- printk("Too many usbdux-devices connected.\n");
+ dev_err(dev, "Too many usbdux-devices connected.\n");
up(&start_stop_sem);
- return PROBE_ERR_RETURN(-EMFILE);
+ return -EMFILE;
}
-#ifdef CONFIG_COMEDI_DEBUG
- printk("comedi_: usbdux: usbduxsub[%d] is ready to connect to comedi.\n", index);
-#endif
+ dev_dbg(dev, "comedi_: usbdux: "
+ "usbduxsub[%d] is ready to connect to comedi.\n", index);
init_MUTEX(&(usbduxsub[index].sem));
- // save a pointer to the usb device
+ /* save a pointer to the usb device */
usbduxsub[index].usbdev = udev;
- // 2.6: save the interface itself
+ /* 2.6: save the interface itself */
usbduxsub[index].interface = uinterf;
- // get the interface number from the interface
+ /* get the interface number from the interface */
usbduxsub[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, &(usbduxsub[index]));
-#ifdef CONFIG_COMEDI_DEBUG
- printk("comedi_: usbdux: ifnum=%d\n", usbduxsub[index].ifnum);
-#endif
- // test if it is high speed (USB 2.0)
+ dev_dbg(dev, "comedi_: usbdux: ifnum=%d\n", usbduxsub[index].ifnum);
+
+ /* test if it is high speed (USB 2.0) */
usbduxsub[index].high_speed =
(usbduxsub[index].usbdev->speed == USB_SPEED_HIGH);
- // create space for the commands of the DA converter
+ /* create space for the commands of the DA converter */
usbduxsub[index].dac_commands = kzalloc(NUMOUTCHANNELS, GFP_KERNEL);
if (!usbduxsub[index].dac_commands) {
- printk("comedi_: usbdux: error alloc space for dac commands\n");
+ dev_err(dev, "comedi_: usbdux: "
+ "error alloc space for dac commands\n");
tidy_up(&(usbduxsub[index]));
up(&start_stop_sem);
- return PROBE_ERR_RETURN(-ENOMEM);
+ return -ENOMEM;
}
- // create space for the commands going to the usb device
+ /* create space for the commands going to the usb device */
usbduxsub[index].dux_commands = kzalloc(SIZEOFDUXBUFFER, GFP_KERNEL);
if (!usbduxsub[index].dux_commands) {
- printk("comedi_: usbdux: error alloc space for dac commands\n");
+ dev_err(dev, "comedi_: usbdux: "
+ "error alloc space for dac commands\n");
tidy_up(&(usbduxsub[index]));
up(&start_stop_sem);
- return PROBE_ERR_RETURN(-ENOMEM);
+ return -ENOMEM;
}
- // create space for the in buffer and set it to zero
+ /* create space for the in buffer and set it to zero */
usbduxsub[index].inBuffer = kzalloc(SIZEINBUF, GFP_KERNEL);
if (!(usbduxsub[index].inBuffer)) {
- printk("comedi_: usbdux: could not alloc space for inBuffer\n");
+ dev_err(dev, "comedi_: usbdux: "
+ "could not alloc space for inBuffer\n");
tidy_up(&(usbduxsub[index]));
up(&start_stop_sem);
- return PROBE_ERR_RETURN(-ENOMEM);
+ return -ENOMEM;
}
- // create space of the instruction buffer
+ /* create space of the instruction buffer */
usbduxsub[index].insnBuffer = kzalloc(SIZEINSNBUF, GFP_KERNEL);
if (!(usbduxsub[index].insnBuffer)) {
- printk("comedi_: usbdux: could not alloc space for insnBuffer\n");
+ dev_err(dev, "comedi_: usbdux: "
+ "could not alloc space for insnBuffer\n");
tidy_up(&(usbduxsub[index]));
up(&start_stop_sem);
- return PROBE_ERR_RETURN(-ENOMEM);
+ return -ENOMEM;
}
- // create space for the outbuffer
+ /* create space for the outbuffer */
usbduxsub[index].outBuffer = kzalloc(SIZEOUTBUF, GFP_KERNEL);
if (!(usbduxsub[index].outBuffer)) {
- printk("comedi_: usbdux: could not alloc space for outBuffer\n");
+ dev_err(dev, "comedi_: usbdux: "
+ "could not alloc space for outBuffer\n");
tidy_up(&(usbduxsub[index]));
up(&start_stop_sem);
- return PROBE_ERR_RETURN(-ENOMEM);
+ return -ENOMEM;
}
- // setting to alternate setting 3: enabling iso ep and bulk ep.
+ /* setting to alternate setting 3: enabling iso ep and bulk ep. */
i = usb_set_interface(usbduxsub[index].usbdev,
- usbduxsub[index].ifnum, 3);
+ usbduxsub[index].ifnum, 3);
if (i < 0) {
- printk("comedi_: usbdux%d: could not set alternate setting 3 in high speed.\n", index);
+ dev_err(dev, "comedi_: usbdux%d: "
+ "could not set alternate setting 3 in high speed.\n",
+ index);
tidy_up(&(usbduxsub[index]));
up(&start_stop_sem);
- return PROBE_ERR_RETURN(-ENODEV);
+ return -ENODEV;
}
- if (usbduxsub[index].high_speed) {
+ if (usbduxsub[index].high_speed)
usbduxsub[index].numOfInBuffers = NUMOFINBUFFERSHIGH;
- } else {
+ else
usbduxsub[index].numOfInBuffers = NUMOFINBUFFERSFULL;
- }
+
usbduxsub[index].urbIn =
kzalloc(sizeof(struct urb *) * usbduxsub[index].numOfInBuffers,
GFP_KERNEL);
if (!(usbduxsub[index].urbIn)) {
- printk("comedi_: usbdux: Could not alloc. urbIn array\n");
+ dev_err(dev, "comedi_: usbdux: Could not alloc. urbIn array\n");
tidy_up(&(usbduxsub[index]));
up(&start_stop_sem);
- return PROBE_ERR_RETURN(-ENOMEM);
+ return -ENOMEM;
}
for (i = 0; i < usbduxsub[index].numOfInBuffers; i++) {
- // one frame: 1ms
- usbduxsub[index].urbIn[i] = USB_ALLOC_URB(1);
+ /* one frame: 1ms */
+ usbduxsub[index].urbIn[i] = usb_alloc_urb(1, GFP_KERNEL);
if (usbduxsub[index].urbIn[i] == NULL) {
- printk("comedi_: usbdux%d: Could not alloc. urb(%d)\n",
- index, i);
+ dev_err(dev, "comedi_: usbdux%d: "
+ "Could not alloc. urb(%d)\n", index, i);
tidy_up(&(usbduxsub[index]));
up(&start_stop_sem);
- return PROBE_ERR_RETURN(-ENOMEM);
+ return -ENOMEM;
}
usbduxsub[index].urbIn[i]->dev = usbduxsub[index].usbdev;
- // will be filled later with a pointer to the comedi-device
- // and ONLY then the urb should be submitted
+ /* will be filled later with a pointer to the comedi-device */
+ /* and ONLY then the urb should be submitted */
usbduxsub[index].urbIn[i]->context = NULL;
usbduxsub[index].urbIn[i]->pipe =
usb_rcvisocpipe(usbduxsub[index].usbdev, ISOINEP);
usbduxsub[index].urbIn[i]->transfer_buffer =
kzalloc(SIZEINBUF, GFP_KERNEL);
if (!(usbduxsub[index].urbIn[i]->transfer_buffer)) {
- printk("comedi_: usbdux%d: could not alloc. transb.\n",
- index);
+ dev_err(dev, "comedi_: usbdux%d: "
+ "could not alloc. transb.\n", index);
tidy_up(&(usbduxsub[index]));
up(&start_stop_sem);
- return PROBE_ERR_RETURN(-ENOMEM);
+ return -ENOMEM;
}
usbduxsub[index].urbIn[i]->complete = usbduxsub_ai_IsocIrq;
usbduxsub[index].urbIn[i]->number_of_packets = 1;
usbduxsub[index].urbIn[i]->iso_frame_desc[0].length = SIZEINBUF;
}
- // out
- if (usbduxsub[index].high_speed) {
+ /* out */
+ if (usbduxsub[index].high_speed)
usbduxsub[index].numOfOutBuffers = NUMOFOUTBUFFERSHIGH;
- } else {
+ else
usbduxsub[index].numOfOutBuffers = NUMOFOUTBUFFERSFULL;
- }
+
usbduxsub[index].urbOut =
kzalloc(sizeof(struct urb *) * usbduxsub[index].numOfOutBuffers,
GFP_KERNEL);
if (!(usbduxsub[index].urbOut)) {
- printk("comedi_: usbdux: Could not alloc. urbOut array\n");
+ dev_err(dev, "comedi_: usbdux: "
+ "Could not alloc. urbOut array\n");
tidy_up(&(usbduxsub[index]));
up(&start_stop_sem);
- return PROBE_ERR_RETURN(-ENOMEM);
+ return -ENOMEM;
}
for (i = 0; i < usbduxsub[index].numOfOutBuffers; i++) {
- // one frame: 1ms
- usbduxsub[index].urbOut[i] = USB_ALLOC_URB(1);
+ /* one frame: 1ms */
+ usbduxsub[index].urbOut[i] = usb_alloc_urb(1, GFP_KERNEL);
if (usbduxsub[index].urbOut[i] == NULL) {
- printk("comedi_: usbdux%d: Could not alloc. urb(%d)\n",
- index, i);
+ dev_err(dev, "comedi_: usbdux%d: "
+ "Could not alloc. urb(%d)\n", index, i);
tidy_up(&(usbduxsub[index]));
up(&start_stop_sem);
- return PROBE_ERR_RETURN(-ENOMEM);
+ return -ENOMEM;
}
usbduxsub[index].urbOut[i]->dev = usbduxsub[index].usbdev;
- // will be filled later with a pointer to the comedi-device
- // and ONLY then the urb should be submitted
+ /* will be filled later with a pointer to the comedi-device */
+ /* and ONLY then the urb should be submitted */
usbduxsub[index].urbOut[i]->context = NULL;
usbduxsub[index].urbOut[i]->pipe =
usb_sndisocpipe(usbduxsub[index].usbdev, ISOOUTEP);
usbduxsub[index].urbOut[i]->transfer_buffer =
kzalloc(SIZEOUTBUF, GFP_KERNEL);
if (!(usbduxsub[index].urbOut[i]->transfer_buffer)) {
- printk("comedi_: usbdux%d: could not alloc. transb.\n",
- index);
+ dev_err(dev, "comedi_: usbdux%d: "
+ "could not alloc. transb.\n", index);
tidy_up(&(usbduxsub[index]));
up(&start_stop_sem);
- return PROBE_ERR_RETURN(-ENOMEM);
+ return -ENOMEM;
}
usbduxsub[index].urbOut[i]->complete = usbduxsub_ao_IsocIrq;
usbduxsub[index].urbOut[i]->number_of_packets = 1;
usbduxsub[index].urbOut[i]->iso_frame_desc[0].length =
SIZEOUTBUF;
if (usbduxsub[index].high_speed) {
- // uframes
+ /* uframes */
usbduxsub[index].urbOut[i]->interval = 8;
} else {
- // frames
+ /* frames */
usbduxsub[index].urbOut[i]->interval = 1;
}
}
- // pwm
+ /* pwm */
if (usbduxsub[index].high_speed) {
- usbduxsub[index].sizePwmBuf = 512; // max bulk ep size in high speed
- usbduxsub[index].urbPwm = USB_ALLOC_URB(0);
+ /* max bulk ep size in high speed */
+ usbduxsub[index].sizePwmBuf = 512;
+ usbduxsub[index].urbPwm = usb_alloc_urb(0, GFP_KERNEL);
if (usbduxsub[index].urbPwm == NULL) {
- printk("comedi_: usbdux%d: Could not alloc. pwm urb\n",
- index);
+ dev_err(dev, "comedi_: usbdux%d: "
+ "Could not alloc. pwm urb\n", index);
tidy_up(&(usbduxsub[index]));
up(&start_stop_sem);
- return PROBE_ERR_RETURN(-ENOMEM);
+ return -ENOMEM;
}
usbduxsub[index].urbPwm->transfer_buffer =
kzalloc(usbduxsub[index].sizePwmBuf, GFP_KERNEL);
if (!(usbduxsub[index].urbPwm->transfer_buffer)) {
- printk("comedi_: usbdux%d: could not alloc. transb. for pwm\n", index);
+ dev_err(dev, "comedi_: usbdux%d: "
+ "could not alloc. transb. for pwm\n", index);
tidy_up(&(usbduxsub[index]));
up(&start_stop_sem);
- return PROBE_ERR_RETURN(-ENOMEM);
+ return -ENOMEM;
}
} else {
usbduxsub[index].urbPwm = NULL;
usbduxsub[index].ao_cmd_running = 0;
usbduxsub[index].pwm_cmd_running = 0;
- // we've reached the bottom of the function
+ /* we've reached the bottom of the function */
usbduxsub[index].probed = 1;
up(&start_stop_sem);
- printk("comedi_: usbdux%d has been successfully initialised.\n", index);
- // success
+
+ ret = request_firmware_nowait(THIS_MODULE,
+ FW_ACTION_HOTPLUG,
+ "usbdux_firmware.bin",
+ &udev->dev,
+ usbduxsub + index,
+ usbdux_firmware_request_complete_handler);
+
+
+
+ if (ret) {
+ dev_err(dev, "Could not load firmware (err=%d)\n", ret);
+ return ret;
+ }
+
+ dev_info(dev, "comedi_: usbdux%d "
+ "has been successfully initialised.\n", index);
+ /* success */
return 0;
}
static void usbduxsub_disconnect(struct usb_interface *intf)
{
- usbduxsub_t *usbduxsub_tmp = usb_get_intfdata(intf);
+ struct usbduxsub *usbduxsub_tmp = usb_get_intfdata(intf);
struct usb_device *udev = interface_to_usbdev(intf);
if (!usbduxsub_tmp) {
- printk("comedi_: usbdux: disconnect called with null pointer.\n");
+ dev_err(&intf->dev,
+ "comedi_: disconnect called with null pointer.\n");
return;
}
if (usbduxsub_tmp->usbdev != udev) {
- printk("comedi_: usbdux: BUG! called with wrong ptr!!!\n");
+ dev_err(&intf->dev,
+ "comedi_: BUG! called with wrong ptr!!!\n");
return;
}
+ comedi_usb_auto_unconfig(udev);
down(&start_stop_sem);
down(&usbduxsub_tmp->sem);
tidy_up(usbduxsub_tmp);
up(&usbduxsub_tmp->sem);
up(&start_stop_sem);
-#ifdef CONFIG_COMEDI_DEBUG
- printk("comedi_: usbdux: disconnected from the usb\n");
-#endif
+ dev_dbg(&intf->dev, "comedi_: disconnected from the usb\n");
}
-// is called when comedi-config is called
-static int usbdux_attach(comedi_device * dev, comedi_devconfig * it)
+/* is called when comedi-config is called */
+static int usbdux_attach(struct comedi_device *dev, struct comedi_devconfig *it)
{
int ret;
int index;
int i;
- comedi_subdevice *s = NULL;
+ struct usbduxsub *udev;
+
+ struct comedi_subdevice *s = NULL;
dev->private = NULL;
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;
for (i = 0; i < NUMUSBDUX; i++) {
if ((usbduxsub[i].probed) && (!usbduxsub[i].attached)) {
}
if (index < 0) {
- printk("comedi%d: usbdux: error: attach failed, no usbdux devs connected to the usb bus.\n", dev->minor);
+ printk(KERN_ERR "comedi%d: usbdux: error: attach failed, no "
+ "usbdux devs connected to the usb bus.\n", dev->minor);
up(&start_stop_sem);
return -ENODEV;
}
- down(&(usbduxsub[index].sem));
- // pointer back to the corresponding comedi device
- usbduxsub[index].comedidev = dev;
+ udev = &usbduxsub[index];
+ down(&udev->sem);
+ /* pointer back to the corresponding comedi device */
+ udev->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) &&
it->options[COMEDI_DEVCONF_AUX_DATA_LENGTH]) {
- read_firmware(usbduxsub + index,
- comedi_aux_data(it->options, 0),
- it->options[COMEDI_DEVCONF_AUX_DATA_LENGTH]);
+ firmwareUpload(udev, comedi_aux_data(it->options, 0),
+ it->options[COMEDI_DEVCONF_AUX_DATA_LENGTH]);
}
dev->board_name = BOARDNAME;
/* set number of subdevices */
- if (usbduxsub[index].high_speed) {
- // with pwm
+ if (udev->high_speed) {
+ /* with pwm */
dev->n_subdevices = 5;
} else {
- // without pwm
+ /* without pwm */
dev->n_subdevices = 4;
}
- // allocate space for the subdevices
- if ((ret = alloc_subdevices(dev, dev->n_subdevices)) < 0) {
- printk("comedi%d: usbdux: error alloc space for subdev\n",
- dev->minor);
+ /* allocate space for the subdevices */
+ ret = alloc_subdevices(dev, dev->n_subdevices);
+ if (ret < 0) {
+ dev_err(&udev->interface->dev,
+ "comedi%d: error alloc space for subdev\n", dev->minor);
up(&start_stop_sem);
return ret;
}
- printk("comedi%d: usbdux: usb-device %d is attached to comedi.\n",
+ dev_info(&udev->interface->dev,
+ "comedi%d: usb-device %d is attached to comedi.\n",
dev->minor, index);
- // private structure is also simply the usb-structure
- dev->private = usbduxsub + index;
+ /* private structure is also simply the usb-structure */
+ dev->private = udev;
- // the first subdevice is the A/D converter
+ /* the first subdevice is the A/D converter */
s = dev->subdevices + SUBDEV_AD;
- // the URBs get the comedi subdevice
- // which is responsible for reading
- // this is the subdevice which reads data
+ /* the URBs get the comedi subdevice */
+ /* which is responsible for reading */
+ /* this is the subdevice which reads data */
dev->read_subdev = s;
- // the subdevice receives as private structure the
- // usb-structure
+ /* the subdevice receives as private structure the */
+ /* usb-structure */
s->private = NULL;
- // analog input
+ /* analog input */
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;
- // 8 channels
+ /* 8 channels */
s->n_chan = 8;
- // length of the channellist
+ /* length of the channellist */
s->len_chanlist = 8;
- // callback functions
+ /* callback functions */
s->insn_read = usbdux_ai_insn_read;
s->do_cmdtest = usbdux_ai_cmdtest;
s->do_cmd = usbdux_ai_cmd;
s->cancel = usbdux_ai_cancel;
- // max value from the A/D converter (12bit)
+ /* max value from the A/D converter (12bit) */
s->maxdata = 0xfff;
- // range table to convert to physical units
+ /* range table to convert to physical units */
s->range_table = (&range_usbdux_ai_range);
- //
- // analog out
+ /* analog out */
s = dev->subdevices + SUBDEV_DA;
- // analog out
+ /* analog out */
s->type = COMEDI_SUBD_AO;
- // backward pointer
+ /* backward pointer */
dev->write_subdev = s;
- // the subdevice receives as private structure the
- // usb-structure
+ /* the subdevice receives as private structure the */
+ /* usb-structure */
s->private = NULL;
- // are writable
+ /* are writable */
s->subdev_flags = SDF_WRITABLE | SDF_GROUND | SDF_CMD_WRITE;
- // 4 channels
+ /* 4 channels */
s->n_chan = 4;
- // length of the channellist
+ /* length of the channellist */
s->len_chanlist = 4;
- // 12 bit resolution
+ /* 12 bit resolution */
s->maxdata = 0x0fff;
- // bipolar range
+ /* bipolar range */
s->range_table = (&range_usbdux_ao_range);
- // callback
+ /* callback */
s->do_cmdtest = usbdux_ao_cmdtest;
s->do_cmd = usbdux_ao_cmd;
s->cancel = usbdux_ao_cancel;
s->insn_read = usbdux_ao_insn_read;
s->insn_write = usbdux_ao_insn_write;
- // digital I/O
+ /* digital I/O */
s = dev->subdevices + SUBDEV_DIO;
s->type = COMEDI_SUBD_DIO;
s->subdev_flags = SDF_READABLE | SDF_WRITABLE;
s->range_table = (&range_digital);
s->insn_bits = usbdux_dio_insn_bits;
s->insn_config = usbdux_dio_insn_config;
- // we don't use it
+ /* we don't use it */
s->private = NULL;
- //counter
+ /* counter */
s = dev->subdevices + SUBDEV_COUNTER;
s->type = COMEDI_SUBD_COUNTER;
s->subdev_flags = SDF_WRITABLE | SDF_READABLE;
s->insn_write = usbdux_counter_write;
s->insn_config = usbdux_counter_config;
- if (usbduxsub[index].high_speed) {
- //timer / pwm
+ if (udev->high_speed) {
+ /* timer / pwm */
s = dev->subdevices + SUBDEV_PWM;
s->type = COMEDI_SUBD_PWM;
s->subdev_flags = SDF_WRITABLE | SDF_PWM_HBRIDGE;
s->n_chan = 8;
- // this defines the max duty cycle resolution
- s->maxdata = usbduxsub[index].sizePwmBuf;
+ /* this defines the max duty cycle resolution */
+ s->maxdata = udev->sizePwmBuf;
s->insn_write = usbdux_pwm_write;
s->insn_read = usbdux_pwm_read;
s->insn_config = usbdux_pwm_config;
usbdux_pwm_period(dev, s, PWM_DEFAULT_PERIOD);
}
- // finally decide that it's attached
- usbduxsub[index].attached = 1;
+ /* finally decide that it's attached */
+ udev->attached = 1;
- up(&(usbduxsub[index].sem));
+ up(&udev->sem);
up(&start_stop_sem);
- printk("comedi%d: attached to usbdux.\n", dev->minor);
+ dev_info(&udev->interface->dev, "comedi%d: attached to usbdux.\n",
+ dev->minor);
return 0;
}
-static int usbdux_detach(comedi_device * dev)
+static int usbdux_detach(struct comedi_device *dev)
{
- usbduxsub_t *usbduxsub_tmp;
-
-#ifdef CONFIG_COMEDI_DEBUG
- printk("comedi%d: usbdux: detach usb device\n", dev->minor);
-#endif
+ struct usbduxsub *usbduxsub_tmp;
if (!dev) {
- printk("comedi?: usbdux: detach without dev variable...\n");
+ printk(KERN_ERR
+ "comedi?: usbdux: detach without dev variable...\n");
return -EFAULT;
}
usbduxsub_tmp = dev->private;
if (!usbduxsub_tmp) {
- printk("comedi?: usbdux: detach without ptr to usbduxsub[]\n");
+ printk(KERN_ERR
+ "comedi?: usbdux: detach without ptr to usbduxsub[]\n");
return -EFAULT;
}
+ dev_dbg(&usbduxsub_tmp->interface->dev, "comedi%d: detach usb device\n",
+ dev->minor);
+
down(&usbduxsub_tmp->sem);
- // Don't allow detach to free the private structure
- // It's one entry of of usbduxsub[]
+ /* Don't allow detach to free the private structure */
+ /* It's one entry of of usbduxsub[] */
dev->private = NULL;
usbduxsub_tmp->attached = 0;
usbduxsub_tmp->comedidev = NULL;
-#ifdef CONFIG_COMEDI_DEBUG
- printk("comedi%d: usbdux: detach: successfully removed\n", dev->minor);
-#endif
+ dev_dbg(&usbduxsub_tmp->interface->dev,
+ "comedi%d: detach: successfully removed\n", dev->minor);
up(&usbduxsub_tmp->sem);
return 0;
}
/* main driver struct */
-static comedi_driver driver_usbdux = {
- driver_name:"usbdux",
- module:THIS_MODULE,
- attach:usbdux_attach,
- detach:usbdux_detach,
+static struct comedi_driver driver_usbdux = {
+ .driver_name = "usbdux",
+ .module = THIS_MODULE,
+ .attach = usbdux_attach,
+ .detach = usbdux_detach,
};
-static void init_usb_devices(void)
-{
- int index;
-#ifdef CONFIG_COMEDI_DEBUG
- printk("comedi_: usbdux: setting all possible devs to invalid\n");
-#endif
- // all devices entries are invalid to begin with
- // they will become valid by the probe function
- // 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));
- }
-}
-
-// 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 usbduxsub_table[] = {
- {USB_DEVICE(0x13d8, 0x0001),
- },
- {USB_DEVICE(0x13d8, 0x0002)
- },
+ {USB_DEVICE(0x13d8, 0x0001) },
+ {USB_DEVICE(0x13d8, 0x0002) },
{} /* Terminating entry */
};
MODULE_DEVICE_TABLE(usb, usbduxsub_table);
-// The usbduxsub-driver
+/* The usbduxsub-driver */
static struct usb_driver usbduxsub_driver = {
-#ifdef COMEDI_HAVE_USB_DRIVER_OWNER
- owner:THIS_MODULE,
-#endif
- name:BOARDNAME,
- probe:usbduxsub_probe,
- disconnect:usbduxsub_disconnect,
- id_table:usbduxsub_table,
+ .name = BOARDNAME,
+ .probe = usbduxsub_probe,
+ .disconnect = usbduxsub_disconnect,
+ .id_table = usbduxsub_table,
};
-// Can't use the nice macro as I have also to initialise the USB
-// subsystem:
-// registering the usb-system _and_ the comedi-driver
-static int init_usbdux(void)
+/* Can't use the nice macro as I have also to initialise the USB */
+/* subsystem: */
+/* registering the usb-system _and_ the comedi-driver */
+static int __init init_usbdux(void)
{
printk(KERN_INFO KBUILD_MODNAME ": "
DRIVER_VERSION ":" DRIVER_DESC "\n");
- init_usb_devices();
usb_register(&usbduxsub_driver);
comedi_driver_register(&driver_usbdux);
return 0;
}
-// deregistering the comedi driver and the usb-subsystem
-static void exit_usbdux(void)
+/* deregistering the comedi driver and the usb-subsystem */
+static void __exit exit_usbdux(void)
{
comedi_driver_unregister(&driver_usbdux);
usb_deregister(&usbduxsub_driver);