89 #include <linux/kernel.h>
90 #include <linux/module.h>
92 #include <linux/slab.h>
93 #include <linux/input.h>
95 #include <linux/fcntl.h>
96 #include <linux/compiler.h>
99 #include "../comedidev.h"
104 #define BULK_TIMEOUT 1000
107 #define FIRMWARE "usbdux_firmware.bin"
108 #define USBDUXSUB_FIRMWARE 0xA0
109 #define VENDOR_DIR_IN 0xC0
110 #define VENDOR_DIR_OUT 0x40
113 #define USBDUXSUB_CPUCS 0xE600
120 #define USBDUXSUB_MINOR 32
123 #define TB_LEN 0x2000
132 #define COMMAND_OUT_EP 1
135 #define COMMAND_IN_EP 8
141 #define MIN_PWM_PERIOD ((long)(1E9/300))
144 #define PWM_DEFAULT_PERIOD ((long)(1E9/100))
147 #define NUMCHANNELS 8
150 #define SIZEADIN ((sizeof(int16_t)))
156 #define SIZEINBUF ((8*SIZEADIN))
159 #define SIZEINSNBUF 16
162 #define NUMOUTCHANNELS 8
165 #define SIZEDAOUT ((sizeof(int8_t)+sizeof(int16_t)))
172 #define SIZEOUTBUF ((8*SIZEDAOUT))
178 #define SIZEOFDUXBUFFER ((8*SIZEDAOUT+2))
181 #define NUMOFINBUFFERSFULL 5
184 #define NUMOFOUTBUFFERSFULL 5
188 #define NUMOFINBUFFERSHIGH 10
192 #define NUMOFOUTBUFFERSHIGH 10
207 #define SUBDEV_COUNTER 3
217 static const struct comedi_lrange range_usbdux_ai_range = { 4, {
229 static const struct comedi_lrange range_usbdux_ao_range = { 2, {
322 static int usbduxsub_unlink_InURBs(
struct usbduxsub *usbduxsub_tmp)
327 if (usbduxsub_tmp && usbduxsub_tmp->
urbIn) {
329 if (usbduxsub_tmp->
urbIn[i]) {
335 "comedi: usbdux: unlinked InURB %d, err=%d\n",
347 static int usbdux_ai_stop(
struct usbduxsub *this_usbduxsub,
int do_unlink)
351 if (!this_usbduxsub) {
352 pr_err(
"comedi?: usbdux_ai_stop: this_usbduxsub=NULL!\n");
359 ret = usbduxsub_unlink_InURBs(this_usbduxsub);
386 if (!(this_usbduxsub->
probed)) {
387 up(&this_usbduxsub->
sem);
391 res = usbdux_ai_stop(this_usbduxsub, this_usbduxsub->
ai_cmd_running);
392 up(&this_usbduxsub->
sem);
397 static void usbduxsub_ai_IsocIrq(
struct urb *
urb)
405 this_comedidev = urb->context;
407 this_usbduxsub = this_comedidev->
private;
412 switch (urb->status) {
423 "comedi%d: usbdux: CRC error in ISO IN stream.\n",
440 usbdux_ai_stop(this_usbduxsub, 0);
449 "Non-zero urb status received in ai intr "
450 "context: %d\n", urb->status);
455 usbdux_ai_stop(this_usbduxsub, 0);
472 urb->dev = this_usbduxsub->
usbdev;
478 "comedi_: urb resubmit failed in int-context! err=%d\n",
482 "buggy USB host controller or bug in IRQ "
488 usbdux_ai_stop(this_usbduxsub, 0);
506 usbdux_ai_stop(this_usbduxsub, 0);
514 n = s->
async->cmd.chanlist_len;
515 for (i = 0; i <
n; i++) {
528 usbdux_ai_stop(this_usbduxsub, 0);
537 static int usbduxsub_unlink_OutURBs(
struct usbduxsub *usbduxsub_tmp)
542 if (usbduxsub_tmp && usbduxsub_tmp->
urbOut) {
544 if (usbduxsub_tmp->
urbOut[i])
548 "comedi: usbdux: unlinked OutURB %d: res=%d\n",
558 static int usbdux_ao_stop(
struct usbduxsub *this_usbduxsub,
int do_unlink)
567 ret = usbduxsub_unlink_OutURBs(this_usbduxsub);
586 if (!(this_usbduxsub->
probed)) {
587 up(&this_usbduxsub->
sem);
591 res = usbdux_ao_stop(this_usbduxsub, this_usbduxsub->
ao_cmd_running);
592 up(&this_usbduxsub->
sem);
596 static void usbduxsub_ao_IsocIrq(
struct urb *urb)
605 this_comedidev = urb->context;
607 this_usbduxsub = this_comedidev->
private;
611 switch (urb->status) {
625 usbdux_ao_stop(this_usbduxsub, 0);
633 "comedi_: Non-zero urb status received in ao "
634 "intr context: %d\n", urb->status);
639 usbdux_ao_stop(this_usbduxsub, 0);
660 usbdux_ao_stop(this_usbduxsub, 0);
668 ((
uint8_t *) (urb->transfer_buffer))[0] =
669 s->
async->cmd.chanlist_len;
670 for (i = 0; i < s->
async->cmd.chanlist_len; i++) {
677 (&(((
int8_t *) urb->transfer_buffer)[i * 3 + 1]));
681 datap[1] = temp >> 8;
687 "comedi: buffer underflow\n");
697 urb->dev = this_usbduxsub->
usbdev;
707 urb->number_of_packets = 1;
708 urb->iso_frame_desc[0].offset = 0;
710 urb->iso_frame_desc[0].status = 0;
714 "comedi_: ao urb resubm failed in int-cont. "
718 "buggy USB host controller or bug in "
725 usbdux_ao_stop(this_usbduxsub, 0);
733 uint8_t local_transfer_buffer[16];
736 local_transfer_buffer[0] = 0;
739 usb_sndctrlpipe(usbduxsub->
usbdev, 0),
749 local_transfer_buffer,
756 "comedi_: control msg failed (start)\n");
762 static int usbduxsub_stop(
struct usbduxsub *usbduxsub)
766 uint8_t local_transfer_buffer[16];
769 local_transfer_buffer[0] = 1;
771 usb_sndctrlpipe(usbduxsub->
usbdev, 0),
779 0x0000, local_transfer_buffer,
786 "comedi_: control msg failed (stop)\n");
792 static int usbduxsub_upload(
struct usbduxsub *usbduxsub,
793 uint8_t *local_transfer_buffer,
794 unsigned int startAddr,
unsigned int len)
799 usb_sndctrlpipe(usbduxsub->
usbdev, 0),
809 local_transfer_buffer,
822 #define FIRMWARE_MAX_LEN 0x2000
824 static int firmwareUpload(
struct usbduxsub *usbduxsub,
825 const u8 *firmwareBinary,
int sizeFirmware)
835 "usbdux firmware binary it too large for FX2.\n");
843 "comedi_: mem alloc for firmware failed\n");
847 ret = usbduxsub_stop(usbduxsub);
850 "comedi_: can not stop firmware\n");
855 ret = usbduxsub_upload(usbduxsub, fwBuf, 0, sizeFirmware);
858 "comedi_: firmware upload failed\n");
862 ret = usbduxsub_start(usbduxsub);
865 "comedi_: can not start firmware\n");
873 static int usbduxsub_submit_InURBs(
struct usbduxsub *usbduxsub)
886 usbduxsub->
urbIn[
i]->status = 0;
887 usbduxsub->
urbIn[
i]->transfer_flags = URB_ISO_ASAP;
889 "comedi%d: submitting in-urb[%d]: %p,%p intv=%d\n",
891 (usbduxsub->
urbIn[i]->context),
892 (usbduxsub->
urbIn[i]->dev),
893 (usbduxsub->
urbIn[i]->interval));
897 "comedi_: ai: usb_submit_urb(%d) error %d\n",
905 static int usbduxsub_submit_OutURBs(
struct usbduxsub *usbduxsub)
914 "comedi_: submitting out-urb[%d]\n", i);
918 usbduxsub->
urbOut[
i]->status = 0;
919 usbduxsub->
urbOut[
i]->transfer_flags = URB_ISO_ASAP;
923 "comedi_: ao: usb_submit_urb(%d) error %d\n",
934 struct usbduxsub *this_usbduxsub = dev->
private;
936 unsigned int tmpTimer;
938 if (!(this_usbduxsub->
probed))
942 "comedi%d: usbdux_ai_cmdtest\n", dev->
minor);
957 err |= cfc_check_trigger_is_unique(cmd->
start_src);
958 err |= cfc_check_trigger_is_unique(cmd->
stop_src);
1016 1000000)) * 1000000;
1052 int8_t r = ((range % 2) == 0);
1053 return (chan << 4) | ((p == 1) << 2) | ((r == 1) << 3);
1058 #define SENDADCOMMANDS 0
1059 #define SENDDACOMMANDS 1
1060 #define SENDDIOCONFIGCOMMAND 2
1061 #define SENDDIOBITSCOMMAND 3
1062 #define SENDSINGLEAD 4
1063 #define READCOUNTERCOMMAND 5
1064 #define WRITECOUNTERCOMMAND 6
1066 #define SENDPWMOFF 8
1068 static int send_dux_commands(
struct usbduxsub *this_usbduxsub,
int cmd_type)
1073 #ifdef NOISY_DUX_DEBUGBUG
1081 usb_sndbulkpipe(this_usbduxsub->
usbdev,
1087 "could not transmit dux_command to the usb-device, "
1088 "err=%d\n", this_usbduxsub->
comedidev->minor, result);
1093 static int receive_dux_commands(
struct usbduxsub *this_usbduxsub,
int command)
1099 for (i = 0; i <
RETRIES; i++) {
1101 usb_rcvbulkpipe(this_usbduxsub->
usbdev,
1107 "insn: USB error %d while receiving DUX command"
1108 "\n", this_usbduxsub->
comedidev->minor, result);
1117 "wrong data returned from firmware: want cmd %d, got cmd %d.\n",
1118 this_usbduxsub->
comedidev->minor, command,
1127 struct usbduxsub *this_usbduxsub = dev->
private;
1128 if (!this_usbduxsub)
1132 if (!(this_usbduxsub->
probed)) {
1133 up(&this_usbduxsub->
sem);
1137 "comedi%d: usbdux_ai_inttrig\n", dev->
minor);
1141 "comedi%d: usbdux_ai_inttrig: invalid trignum\n",
1143 up(&this_usbduxsub->
sem);
1148 ret = usbduxsub_submit_InURBs(this_usbduxsub);
1151 "comedi%d: usbdux_ai_inttrig: "
1152 "urbSubmit: err=%d\n", dev->
minor, ret);
1154 up(&this_usbduxsub->
sem);
1160 "comedi%d: ai_inttrig but acqu is already running\n",
1163 up(&this_usbduxsub->
sem);
1170 unsigned int chan,
range;
1172 struct usbduxsub *this_usbduxsub = dev->
private;
1175 if (!this_usbduxsub)
1179 "comedi%d: usbdux_ai_cmd\n", dev->
minor);
1184 if (!(this_usbduxsub->
probed)) {
1185 up(&this_usbduxsub->
sem);
1190 "ai_cmd not possible. Another ai_cmd is running.\n",
1192 up(&this_usbduxsub->
sem);
1196 s->
async->cur_chan = 0;
1204 "comedi%d: channel list too long\n",
1209 create_adc_command(chan, range);
1213 "comedi %d: sending commands to the usb device: size=%u\n",
1218 up(&this_usbduxsub->
sem);
1242 if (this_usbduxsub->
ai_timer < 1) {
1244 "timer=%d, scan_begin_arg=%d. "
1245 "Not properly tested by cmdtest?\n", dev->
minor,
1247 up(&this_usbduxsub->
sem);
1265 ret = usbduxsub_submit_InURBs(this_usbduxsub);
1269 up(&this_usbduxsub->
sem);
1277 s->
async->inttrig = usbdux_ai_inttrig;
1279 up(&this_usbduxsub->
sem);
1289 unsigned int one = 0;
1292 struct usbduxsub *this_usbduxsub = dev->
private;
1294 if (!this_usbduxsub)
1298 "comedi%d: ai_insn_read, insn->n=%d, insn->subdev=%d\n",
1302 if (!(this_usbduxsub->
probed)) {
1303 up(&this_usbduxsub->
sem);
1308 "comedi%d: ai_insn_read not possible. "
1309 "Async Command is running.\n", dev->
minor);
1310 up(&this_usbduxsub->
sem);
1318 this_usbduxsub->
dux_commands[1] = create_adc_command(chan, range);
1323 up(&this_usbduxsub->
sem);
1327 for (i = 0; i < insn->
n; i++) {
1328 err = receive_dux_commands(this_usbduxsub,
SENDSINGLEAD);
1330 up(&this_usbduxsub->
sem);
1339 up(&this_usbduxsub->
sem);
1352 struct usbduxsub *this_usbduxsub = dev->
private;
1354 if (!this_usbduxsub)
1358 if (!(this_usbduxsub->
probed)) {
1359 up(&this_usbduxsub->
sem);
1362 for (i = 0; i < insn->
n; i++)
1363 data[i] = this_usbduxsub->
outBuffer[chan];
1365 up(&this_usbduxsub->
sem);
1375 struct usbduxsub *this_usbduxsub = dev->
private;
1377 if (!this_usbduxsub)
1381 "comedi%d: ao_insn_write\n", dev->
minor);
1384 if (!(this_usbduxsub->
probed)) {
1385 up(&this_usbduxsub->
sem);
1390 "comedi%d: ao_insn_write: "
1391 "ERROR: asynchronous ao_cmd is running\n", dev->
minor);
1392 up(&this_usbduxsub->
sem);
1396 for (i = 0; i < insn->
n; i++) {
1398 "comedi%d: ao_insn_write: data[chan=%d,i=%d]=%d\n",
1399 dev->
minor, chan, i, data[i]);
1411 up(&this_usbduxsub->
sem);
1415 up(&this_usbduxsub->
sem);
1424 struct usbduxsub *this_usbduxsub = dev->
private;
1426 if (!this_usbduxsub)
1430 if (!(this_usbduxsub->
probed)) {
1431 up(&this_usbduxsub->
sem);
1436 "comedi%d: usbdux_ao_inttrig: invalid trignum\n",
1438 up(&this_usbduxsub->
sem);
1443 ret = usbduxsub_submit_OutURBs(this_usbduxsub);
1446 "comedi%d: usbdux_ao_inttrig: submitURB: "
1447 "err=%d\n", dev->
minor, ret);
1449 up(&this_usbduxsub->
sem);
1455 "comedi%d: ao_inttrig but acqu is already running.\n",
1458 up(&this_usbduxsub->
sem);
1465 struct usbduxsub *this_usbduxsub = dev->
private;
1469 if (!this_usbduxsub)
1472 if (!(this_usbduxsub->
probed))
1476 "comedi%d: usbdux_ao_cmdtest\n", dev->
minor);
1504 err |= cfc_check_trigger_src(&cmd->
convert_src, flags);
1514 err |= cfc_check_trigger_is_unique(cmd->
start_src);
1515 err |= cfc_check_trigger_is_unique(cmd->
stop_src);
1569 "scan_begin_src=%d, scan_begin_arg=%d, convert_src=%d, "
1582 unsigned int chan,
gain;
1584 struct usbduxsub *this_usbduxsub = dev->
private;
1586 if (!this_usbduxsub)
1590 if (!(this_usbduxsub->
probed)) {
1591 up(&this_usbduxsub->
sem);
1595 "comedi%d: %s\n", dev->
minor, __func__);
1598 s->
async->cur_chan = 0;
1604 "comedi%d: %s: channel list too long\n",
1605 dev->
minor, __func__);
1610 "comedi%d: dac command for ch %d is %x\n",
1625 "comedi%d: scan_begin_src=%d, scan_begin_arg=%d, "
1626 "convert_src=%d, convert_arg=%d\n", dev->
minor,
1630 "comedi%d: ao_timer=%d (ms)\n",
1632 if (this_usbduxsub->
ao_timer < 1) {
1634 "comedi%d: usbdux: ao_timer=%d, "
1635 "scan_begin_arg=%d. "
1636 "Not properly tested by cmdtest?\n",
1639 up(&this_usbduxsub->
sem);
1668 ret = usbduxsub_submit_OutURBs(this_usbduxsub);
1672 up(&this_usbduxsub->
sem);
1680 s->
async->inttrig = usbdux_ao_inttrig;
1683 up(&this_usbduxsub->
sem);
1687 static int usbdux_dio_insn_config(
struct comedi_device *dev,
1723 struct usbduxsub *this_usbduxsub = dev->
private;
1726 if (!this_usbduxsub)
1731 if (!(this_usbduxsub->
probed)) {
1732 up(&this_usbduxsub->
sem);
1738 s->
state &= ~data[0];
1739 s->
state |= data[0] & data[1];
1747 up(&this_usbduxsub->
sem);
1752 up(&this_usbduxsub->
sem);
1757 up(&this_usbduxsub->
sem);
1766 struct usbduxsub *this_usbduxsub = dev->
private;
1770 if (!this_usbduxsub)
1775 if (!(this_usbduxsub->
probed)) {
1776 up(&this_usbduxsub->
sem);
1782 up(&this_usbduxsub->
sem);
1788 up(&this_usbduxsub->
sem);
1793 up(&this_usbduxsub->
sem);
1801 struct usbduxsub *this_usbduxsub = dev->
private;
1804 if (!this_usbduxsub)
1809 if (!(this_usbduxsub->
probed)) {
1810 up(&this_usbduxsub->
sem);
1819 up(&this_usbduxsub->
sem);
1823 up(&this_usbduxsub->
sem);
1839 static int usbduxsub_unlink_PwmURBs(
struct usbduxsub *usbduxsub_tmp)
1843 if (usbduxsub_tmp && usbduxsub_tmp->
urbPwm) {
1844 if (usbduxsub_tmp->
urbPwm)
1847 "comedi: unlinked PwmURB: res=%d\n", err);
1855 static int usbdux_pwm_stop(
struct usbduxsub *this_usbduxsub,
int do_unlink)
1859 if (!this_usbduxsub)
1864 ret = usbduxsub_unlink_PwmURBs(this_usbduxsub);
1875 struct usbduxsub *this_usbduxsub = dev->
private;
1879 res = usbdux_pwm_stop(this_usbduxsub, this_usbduxsub->
pwm_cmd_running);
1882 "comedi %d: sending pwm off command to the usb device.\n",
1885 return send_dux_commands(this_usbduxsub,
SENDPWMOFF);
1888 static void usbduxsub_pwm_irq(
struct urb *urb)
1891 struct usbduxsub *this_usbduxsub;
1898 this_comedidev = urb->context;
1900 this_usbduxsub = this_comedidev->
private;
1904 switch (urb->status) {
1918 usbdux_pwm_stop(this_usbduxsub, 0);
1926 "comedi_: Non-zero urb status received in "
1927 "pwm intr context: %d\n", urb->status);
1928 usbdux_pwm_stop(this_usbduxsub, 0);
1937 urb->transfer_buffer_length = this_usbduxsub->
sizePwmBuf;
1938 urb->dev = this_usbduxsub->
usbdev;
1944 "comedi_: pwm urb resubm failed in int-cont. "
1948 "buggy USB host controller or bug in "
1952 usbdux_pwm_stop(this_usbduxsub, 0);
1957 static int usbduxsub_submit_PwmURBs(
struct usbduxsub *usbduxsub)
1967 usb_fill_bulk_urb(usbduxsub->
urbPwm,
1970 usbduxsub->
urbPwm->transfer_buffer,
1977 "comedi_: usbdux: pwm: usb_submit_urb error %d\n",
1987 struct usbduxsub *this_usbduxsub = dev->
private;
1992 "comedi%d: illegal period setting for pwm.\n",
1996 fx2delay = period / ((
int)(6 * 512 * (1.0 / 0.033))) - 6;
1997 if (fx2delay > 255) {
1999 "comedi%d: period %d for pwm is too low.\n",
2000 dev->
minor, period);
2004 this_usbduxsub->
pwmDelay = fx2delay;
2007 __func__, period, fx2delay);
2016 struct usbduxsub *this_usbduxsub = dev->
private;
2019 dev->
minor, __func__);
2027 ret = send_dux_commands(this_usbduxsub,
SENDPWMON);
2032 for (i = 0; i < this_usbduxsub->
sizePwmBuf; i++)
2033 ((
char *)(this_usbduxsub->
urbPwm->transfer_buffer))[
i] = 0;
2036 ret = usbduxsub_submit_PwmURBs(this_usbduxsub);
2049 struct usbduxsub *this_usbduxsub = dev->
private;
2056 if (!this_usbduxsub)
2066 pBuf = (
char *)(this_usbduxsub->
urbPwm->transfer_buffer);
2067 for (i = 0; i < szbuf; i++) {
2070 c = c & (~pwm_mask);
2077 c = c & (~sgn_mask);
2091 struct usbduxsub *this_usbduxsub = dev->
private;
2093 if (!this_usbduxsub)
2096 if ((insn->
n) != 1) {
2109 return usbdux_pwm_pattern(dev, s,
CR_CHAN(insn->
chanspec), data[0], 0);
2125 struct usbduxsub *this_usbduxsub = dev->
private;
2130 "comedi%d: %s: pwm on\n", dev->
minor, __func__);
2137 return usbdux_pwm_start(dev, s);
2140 "comedi%d: %s: pwm off\n", dev->
minor, __func__);
2141 return usbdux_pwm_cancel(dev, s);
2151 "comedi%d: %s: setting period\n", dev->
minor, __func__);
2152 return usbdux_pwm_period(dev, s, data[1]);
2159 return usbdux_pwm_pattern(dev, s,
2176 static void tidy_up(
struct usbduxsub *usbduxsub_tmp)
2188 usbduxsub_tmp->
probed = 0;
2190 if (usbduxsub_tmp->
urbIn) {
2193 usbduxsub_unlink_InURBs(usbduxsub_tmp);
2196 kfree(usbduxsub_tmp->
urbIn[i]->transfer_buffer);
2197 usbduxsub_tmp->
urbIn[
i]->transfer_buffer =
NULL;
2205 if (usbduxsub_tmp->
urbOut) {
2208 usbduxsub_unlink_OutURBs(usbduxsub_tmp);
2213 if (usbduxsub_tmp->
urbOut[i]) {
2222 if (usbduxsub_tmp->
urbPwm) {
2225 usbduxsub_unlink_PwmURBs(usbduxsub_tmp);
2228 usbduxsub_tmp->
urbPwm->transfer_buffer =
NULL;
2249 struct usbduxsub *
udev)
2299 s->
do_cmd = usbdux_ai_cmd;
2300 s->
cancel = usbdux_ai_cancel;
2327 s->
do_cmd = usbdux_ao_cmd;
2328 s->
cancel = usbdux_ao_cancel;
2382 struct usbduxsub *this_usbduxsub;
2386 down(&start_stop_sem);
2387 this_usbduxsub = usb_get_intfdata(uinterf);
2388 if (!this_usbduxsub || !this_usbduxsub->
probed) {
2390 "comedi%d: usbdux: error: attach_usb failed, not connected\n",
2393 }
else if (this_usbduxsub->
attached) {
2395 "comedi%d: usbdux: error: attach_usb failed, already attached\n",
2399 ret = usbdux_attach_common(dev, this_usbduxsub);
2400 up(&start_stop_sem);
2418 .driver_name =
"usbdux",
2420 .attach_usb = usbdux_attach_usb,
2421 .detach = usbdux_detach,
2424 static void usbdux_firmware_request_complete_handler(
const struct firmware *
fw,
2427 struct usbduxsub *usbduxsub_tmp =
context;
2433 "Firmware complete handler without firmware!\n");
2441 ret = firmwareUpload(usbduxsub_tmp, fw->
data, fw->
size);
2445 "Could not upload firmware (err=%d)\n", ret);
2456 struct usb_device *udev = interface_to_usbdev(uinterf);
2457 struct device *dev = &uinterf->dev;
2462 dev_dbg(dev,
"comedi_: usbdux_: "
2463 "finding a free structure for the usb-device\n");
2465 down(&start_stop_sem);
2469 if (!(usbduxsub[i].probed)) {
2477 dev_err(dev,
"Too many usbdux-devices connected.\n");
2478 up(&start_stop_sem);
2481 dev_dbg(dev,
"comedi_: usbdux: "
2482 "usbduxsub[%d] is ready to connect to comedi.\n", index);
2484 sema_init(&(usbduxsub[index].
sem), 1);
2491 usbduxsub[
index].
ifnum = uinterf->altsetting->desc.bInterfaceNumber;
2494 usb_set_intfdata(uinterf, &(usbduxsub[index]));
2496 dev_dbg(dev,
"comedi_: usbdux: ifnum=%d\n", usbduxsub[index].ifnum);
2504 if (!usbduxsub[index].dac_commands) {
2505 dev_err(dev,
"comedi_: usbdux: "
2506 "error alloc space for dac commands\n");
2507 tidy_up(&(usbduxsub[index]));
2508 up(&start_stop_sem);
2513 if (!usbduxsub[index].dux_commands) {
2514 dev_err(dev,
"comedi_: usbdux: "
2515 "error alloc space for dux commands\n");
2516 tidy_up(&(usbduxsub[index]));
2517 up(&start_stop_sem);
2522 if (!(usbduxsub[index].inBuffer)) {
2523 dev_err(dev,
"comedi_: usbdux: "
2524 "could not alloc space for inBuffer\n");
2525 tidy_up(&(usbduxsub[index]));
2526 up(&start_stop_sem);
2531 if (!(usbduxsub[index].insnBuffer)) {
2532 dev_err(dev,
"comedi_: usbdux: "
2533 "could not alloc space for insnBuffer\n");
2534 tidy_up(&(usbduxsub[index]));
2535 up(&start_stop_sem);
2540 if (!(usbduxsub[index].outBuffer)) {
2541 dev_err(dev,
"comedi_: usbdux: "
2542 "could not alloc space for outBuffer\n");
2543 tidy_up(&(usbduxsub[index]));
2544 up(&start_stop_sem);
2549 usbduxsub[index].ifnum, 3);
2551 dev_err(dev,
"comedi_: usbdux%d: "
2552 "could not set alternate setting 3 in high speed.\n",
2554 tidy_up(&(usbduxsub[index]));
2555 up(&start_stop_sem);
2558 if (usbduxsub[index].high_speed)
2564 kzalloc(
sizeof(
struct urb *) * usbduxsub[index].numOfInBuffers,
2566 if (!(usbduxsub[index].urbIn)) {
2567 dev_err(dev,
"comedi_: usbdux: Could not alloc. urbIn array\n");
2568 tidy_up(&(usbduxsub[index]));
2569 up(&start_stop_sem);
2575 if (usbduxsub[index].urbIn[i] ==
NULL) {
2576 dev_err(dev,
"comedi_: usbdux%d: "
2577 "Could not alloc. urb(%d)\n", index, i);
2578 tidy_up(&(usbduxsub[index]));
2579 up(&start_stop_sem);
2587 usb_rcvisocpipe(usbduxsub[index].usbdev,
ISOINEP);
2588 usbduxsub[
index].
urbIn[
i]->transfer_flags = URB_ISO_ASAP;
2592 dev_err(dev,
"comedi_: usbdux%d: "
2593 "could not alloc. transb.\n", index);
2594 tidy_up(&(usbduxsub[index]));
2595 up(&start_stop_sem);
2598 usbduxsub[
index].
urbIn[
i]->complete = usbduxsub_ai_IsocIrq;
2601 usbduxsub[
index].
urbIn[
i]->iso_frame_desc[0].offset = 0;
2606 if (usbduxsub[index].high_speed)
2612 kzalloc(
sizeof(
struct urb *) * usbduxsub[index].numOfOutBuffers,
2614 if (!(usbduxsub[index].urbOut)) {
2615 dev_err(dev,
"comedi_: usbdux: "
2616 "Could not alloc. urbOut array\n");
2617 tidy_up(&(usbduxsub[index]));
2618 up(&start_stop_sem);
2624 if (usbduxsub[index].urbOut[i] ==
NULL) {
2625 dev_err(dev,
"comedi_: usbdux%d: "
2626 "Could not alloc. urb(%d)\n", index, i);
2627 tidy_up(&(usbduxsub[index]));
2628 up(&start_stop_sem);
2636 usb_sndisocpipe(usbduxsub[index].usbdev,
ISOOUTEP);
2637 usbduxsub[
index].
urbOut[
i]->transfer_flags = URB_ISO_ASAP;
2641 dev_err(dev,
"comedi_: usbdux%d: "
2642 "could not alloc. transb.\n", index);
2643 tidy_up(&(usbduxsub[index]));
2644 up(&start_stop_sem);
2647 usbduxsub[
index].
urbOut[
i]->complete = usbduxsub_ao_IsocIrq;
2650 usbduxsub[
index].
urbOut[
i]->iso_frame_desc[0].offset = 0;
2653 if (usbduxsub[index].high_speed) {
2663 if (usbduxsub[index].high_speed) {
2667 if (usbduxsub[index].urbPwm ==
NULL) {
2668 dev_err(dev,
"comedi_: usbdux%d: "
2669 "Could not alloc. pwm urb\n", index);
2670 tidy_up(&(usbduxsub[index]));
2671 up(&start_stop_sem);
2675 kzalloc(usbduxsub[index].sizePwmBuf,
GFP_KERNEL);
2676 if (!(usbduxsub[index].urbPwm->transfer_buffer)) {
2677 dev_err(dev,
"comedi_: usbdux%d: "
2678 "could not alloc. transb. for pwm\n", index);
2679 tidy_up(&(usbduxsub[index]));
2680 up(&start_stop_sem);
2694 up(&start_stop_sem);
2702 usbdux_firmware_request_complete_handler);
2705 dev_err(dev,
"Could not load firmware (err=%d)\n", ret);
2710 "has been successfully initialised.\n", index);
2717 struct usbduxsub *usbduxsub_tmp = usb_get_intfdata(intf);
2718 struct usb_device *udev = interface_to_usbdev(intf);
2720 if (!usbduxsub_tmp) {
2722 "comedi_: disconnect called with null pointer.\n");
2725 if (usbduxsub_tmp->
usbdev != udev) {
2726 dev_err(&intf->dev,
"comedi_: BUG! called with wrong ptr!!!\n");
2730 down(&start_stop_sem);
2732 tidy_up(usbduxsub_tmp);
2733 up(&usbduxsub_tmp->
sem);
2734 up(&start_stop_sem);
2735 dev_dbg(&intf->dev,
"comedi_: disconnected from the usb\n");
2739 { USB_DEVICE(0x13d8, 0x0001) },
2740 { USB_DEVICE(0x13d8, 0x0002) },
2746 static struct usb_driver usbdux_usb_driver = {
2748 .probe = usbdux_usb_probe,
2749 .disconnect = usbdux_usb_disconnect,
2750 .id_table = usbdux_usb_table,