Bernd Porr | f47c697 | 2008-11-14 14:49:34 -0800 | [diff] [blame] | 1 | /* |
Bernd Porr | 533de0f | 2014-10-10 20:35:11 +0100 | [diff] [blame] | 2 | * Copyright (C) 2004-2014 Bernd Porr, mail@berndporr.me.uk |
Mariusz Kozlowski | 4e8ad0d | 2009-02-16 21:31:28 +0100 | [diff] [blame] | 3 | * |
| 4 | * This program is free software; you can redistribute it and/or modify |
| 5 | * it under the terms of the GNU General Public License as published by |
| 6 | * the Free Software Foundation; either version 2 of the License, or |
| 7 | * (at your option) any later version. |
| 8 | * |
| 9 | * This program is distributed in the hope that it will be useful, |
| 10 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 11 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 12 | * GNU General Public License for more details. |
Mariusz Kozlowski | 4e8ad0d | 2009-02-16 21:31:28 +0100 | [diff] [blame] | 13 | */ |
Bernd Porr | f47c697 | 2008-11-14 14:49:34 -0800 | [diff] [blame] | 14 | |
| 15 | /* |
Bernd Porr | 533de0f | 2014-10-10 20:35:11 +0100 | [diff] [blame] | 16 | * Driver: usbduxfast |
| 17 | * Description: University of Stirling USB DAQ & INCITE Technology Limited |
Ian Abbott | 504a1aa | 2015-01-05 17:55:11 +0000 | [diff] [blame] | 18 | * Devices: [ITL] USB-DUX-FAST (usbduxfast) |
Bernd Porr | 533de0f | 2014-10-10 20:35:11 +0100 | [diff] [blame] | 19 | * Author: Bernd Porr <mail@berndporr.me.uk> |
| 20 | * Updated: 10 Oct 2014 |
| 21 | * Status: stable |
| 22 | */ |
| 23 | |
| 24 | /* |
Bernd Porr | f47c697 | 2008-11-14 14:49:34 -0800 | [diff] [blame] | 25 | * I must give credit here to Chris Baugher who |
| 26 | * wrote the driver for AT-MIO-16d. I used some parts of this |
| 27 | * driver. I also must give credits to David Brownell |
| 28 | * who supported me with the USB development. |
| 29 | * |
| 30 | * Bernd Porr |
| 31 | * |
| 32 | * |
| 33 | * Revision history: |
| 34 | * 0.9: Dropping the first data packet which seems to be from the last transfer. |
| 35 | * Buffer overflows in the FX2 are handed over to comedi. |
| 36 | * 0.92: Dropping now 4 packets. The quad buffer has to be emptied. |
Mariusz Kozlowski | 4e8ad0d | 2009-02-16 21:31:28 +0100 | [diff] [blame] | 37 | * Added insn command basically for testing. Sample rate is |
| 38 | * 1MHz/16ch=62.5kHz |
Bernd Porr | f47c697 | 2008-11-14 14:49:34 -0800 | [diff] [blame] | 39 | * 0.99: Ian Abbott pointed out a bug which has been corrected. Thanks! |
| 40 | * 0.99a: added external trigger. |
Bernd Porr | 6742c0a | 2008-12-08 23:30:13 +0000 | [diff] [blame] | 41 | * 1.00: added firmware kernel request to the driver which fixed |
| 42 | * udev coldplug problem |
Bernd Porr | f47c697 | 2008-11-14 14:49:34 -0800 | [diff] [blame] | 43 | */ |
| 44 | |
| 45 | #include <linux/kernel.h> |
| 46 | #include <linux/module.h> |
Bernd Porr | f47c697 | 2008-11-14 14:49:34 -0800 | [diff] [blame] | 47 | #include <linux/slab.h> |
| 48 | #include <linux/input.h> |
Bernd Porr | f47c697 | 2008-11-14 14:49:34 -0800 | [diff] [blame] | 49 | #include <linux/fcntl.h> |
| 50 | #include <linux/compiler.h> |
Ian Abbott | d3f8395 | 2015-01-27 17:49:06 +0000 | [diff] [blame] | 51 | #include "../comedi_usb.h" |
Bernd Porr | f47c697 | 2008-11-14 14:49:34 -0800 | [diff] [blame] | 52 | |
Mariusz Kozlowski | 4e8ad0d | 2009-02-16 21:31:28 +0100 | [diff] [blame] | 53 | /* |
| 54 | * timeout for the USB-transfer |
| 55 | */ |
| 56 | #define EZTIMEOUT 30 |
Bernd Porr | f47c697 | 2008-11-14 14:49:34 -0800 | [diff] [blame] | 57 | |
Mariusz Kozlowski | 4e8ad0d | 2009-02-16 21:31:28 +0100 | [diff] [blame] | 58 | /* |
| 59 | * constants for "firmware" upload and download |
| 60 | */ |
Tim Gardner | e74f7fc | 2012-08-16 11:09:28 -0600 | [diff] [blame] | 61 | #define FIRMWARE "usbduxfast_firmware.bin" |
H Hartley Sweeten | dcd29f5 | 2013-05-14 13:40:02 -0700 | [diff] [blame] | 62 | #define FIRMWARE_MAX_LEN 0x2000 |
Mariusz Kozlowski | 4e8ad0d | 2009-02-16 21:31:28 +0100 | [diff] [blame] | 63 | #define USBDUXFASTSUB_FIRMWARE 0xA0 |
| 64 | #define VENDOR_DIR_IN 0xC0 |
| 65 | #define VENDOR_DIR_OUT 0x40 |
Bernd Porr | f47c697 | 2008-11-14 14:49:34 -0800 | [diff] [blame] | 66 | |
Mariusz Kozlowski | 4e8ad0d | 2009-02-16 21:31:28 +0100 | [diff] [blame] | 67 | /* |
Uwe Kleine-König | f69b0d6 | 2010-07-12 17:15:46 +0200 | [diff] [blame] | 68 | * internal addresses of the 8051 processor |
Mariusz Kozlowski | 4e8ad0d | 2009-02-16 21:31:28 +0100 | [diff] [blame] | 69 | */ |
| 70 | #define USBDUXFASTSUB_CPUCS 0xE600 |
Bernd Porr | f47c697 | 2008-11-14 14:49:34 -0800 | [diff] [blame] | 71 | |
Mariusz Kozlowski | 4e8ad0d | 2009-02-16 21:31:28 +0100 | [diff] [blame] | 72 | /* |
| 73 | * max lenghth of the transfer-buffer for software upload |
| 74 | */ |
| 75 | #define TB_LEN 0x2000 |
Bernd Porr | f47c697 | 2008-11-14 14:49:34 -0800 | [diff] [blame] | 76 | |
Mariusz Kozlowski | 4e8ad0d | 2009-02-16 21:31:28 +0100 | [diff] [blame] | 77 | /* |
| 78 | * input endpoint number |
| 79 | */ |
| 80 | #define BULKINEP 6 |
Bernd Porr | f47c697 | 2008-11-14 14:49:34 -0800 | [diff] [blame] | 81 | |
Mariusz Kozlowski | 4e8ad0d | 2009-02-16 21:31:28 +0100 | [diff] [blame] | 82 | /* |
| 83 | * endpoint for the A/D channellist: bulk OUT |
| 84 | */ |
| 85 | #define CHANNELLISTEP 4 |
Bernd Porr | f47c697 | 2008-11-14 14:49:34 -0800 | [diff] [blame] | 86 | |
Mariusz Kozlowski | 4e8ad0d | 2009-02-16 21:31:28 +0100 | [diff] [blame] | 87 | /* |
| 88 | * number of channels |
| 89 | */ |
| 90 | #define NUMCHANNELS 32 |
Bernd Porr | f47c697 | 2008-11-14 14:49:34 -0800 | [diff] [blame] | 91 | |
Mariusz Kozlowski | 4e8ad0d | 2009-02-16 21:31:28 +0100 | [diff] [blame] | 92 | /* |
| 93 | * size of the waveform descriptor |
| 94 | */ |
| 95 | #define WAVESIZE 0x20 |
Bernd Porr | f47c697 | 2008-11-14 14:49:34 -0800 | [diff] [blame] | 96 | |
Mariusz Kozlowski | 4e8ad0d | 2009-02-16 21:31:28 +0100 | [diff] [blame] | 97 | /* |
| 98 | * size of one A/D value |
| 99 | */ |
H Hartley Sweeten | 2696154 | 2015-08-24 10:13:57 -0700 | [diff] [blame] | 100 | #define SIZEADIN (sizeof(s16)) |
Bernd Porr | f47c697 | 2008-11-14 14:49:34 -0800 | [diff] [blame] | 101 | |
Mariusz Kozlowski | 4e8ad0d | 2009-02-16 21:31:28 +0100 | [diff] [blame] | 102 | /* |
| 103 | * size of the input-buffer IN BYTES |
| 104 | */ |
| 105 | #define SIZEINBUF 512 |
Bernd Porr | f47c697 | 2008-11-14 14:49:34 -0800 | [diff] [blame] | 106 | |
Mariusz Kozlowski | 4e8ad0d | 2009-02-16 21:31:28 +0100 | [diff] [blame] | 107 | /* |
| 108 | * 16 bytes |
| 109 | */ |
| 110 | #define SIZEINSNBUF 512 |
Bernd Porr | f47c697 | 2008-11-14 14:49:34 -0800 | [diff] [blame] | 111 | |
Mariusz Kozlowski | 4e8ad0d | 2009-02-16 21:31:28 +0100 | [diff] [blame] | 112 | /* |
| 113 | * size of the buffer for the dux commands in bytes |
| 114 | */ |
H Hartley Sweeten | 5659e24 | 2013-05-14 13:36:47 -0700 | [diff] [blame] | 115 | #define SIZEOFDUXBUF 256 |
Bernd Porr | f47c697 | 2008-11-14 14:49:34 -0800 | [diff] [blame] | 116 | |
Mariusz Kozlowski | 4e8ad0d | 2009-02-16 21:31:28 +0100 | [diff] [blame] | 117 | /* |
| 118 | * number of in-URBs which receive the data: min=5 |
| 119 | */ |
| 120 | #define NUMOFINBUFFERSHIGH 10 |
Bernd Porr | f47c697 | 2008-11-14 14:49:34 -0800 | [diff] [blame] | 121 | |
Mariusz Kozlowski | 4e8ad0d | 2009-02-16 21:31:28 +0100 | [diff] [blame] | 122 | /* |
Mariusz Kozlowski | 4e8ad0d | 2009-02-16 21:31:28 +0100 | [diff] [blame] | 123 | * min delay steps for more than one channel |
| 124 | * basically when the mux gives up ;-) |
| 125 | * |
| 126 | * steps at 30MHz in the FX2 |
| 127 | */ |
| 128 | #define MIN_SAMPLING_PERIOD 9 |
Bernd Porr | f47c697 | 2008-11-14 14:49:34 -0800 | [diff] [blame] | 129 | |
Mariusz Kozlowski | 4e8ad0d | 2009-02-16 21:31:28 +0100 | [diff] [blame] | 130 | /* |
| 131 | * max number of 1/30MHz delay steps |
| 132 | */ |
| 133 | #define MAX_SAMPLING_PERIOD 500 |
Bernd Porr | f47c697 | 2008-11-14 14:49:34 -0800 | [diff] [blame] | 134 | |
Mariusz Kozlowski | 4e8ad0d | 2009-02-16 21:31:28 +0100 | [diff] [blame] | 135 | /* |
| 136 | * number of received packets to ignore before we start handing data |
| 137 | * over to comedi, it's quad buffering and we have to ignore 4 packets |
| 138 | */ |
| 139 | #define PACKETS_TO_IGNORE 4 |
Bernd Porr | f47c697 | 2008-11-14 14:49:34 -0800 | [diff] [blame] | 140 | |
Mariusz Kozlowski | 4e8ad0d | 2009-02-16 21:31:28 +0100 | [diff] [blame] | 141 | /* |
| 142 | * comedi constants |
| 143 | */ |
Bill Pemberton | 9ced1de | 2009-03-16 22:05:31 -0400 | [diff] [blame] | 144 | static const struct comedi_lrange range_usbduxfast_ai_range = { |
H Hartley Sweeten | 67b3b78 | 2013-12-09 17:31:25 -0700 | [diff] [blame] | 145 | 2, { |
| 146 | BIP_RANGE(0.75), |
| 147 | BIP_RANGE(0.5) |
| 148 | } |
Bernd Porr | f47c697 | 2008-11-14 14:49:34 -0800 | [diff] [blame] | 149 | }; |
| 150 | |
| 151 | /* |
| 152 | * private structure of one subdevice |
Mariusz Kozlowski | 4e8ad0d | 2009-02-16 21:31:28 +0100 | [diff] [blame] | 153 | * |
| 154 | * this is the structure which holds all the data of this driver |
| 155 | * one sub device just now: A/D |
Bernd Porr | f47c697 | 2008-11-14 14:49:34 -0800 | [diff] [blame] | 156 | */ |
H Hartley Sweeten | 7aa41c3 | 2013-05-14 13:27:37 -0700 | [diff] [blame] | 157 | struct usbduxfast_private { |
H Hartley Sweeten | da58c26 | 2013-05-14 13:35:40 -0700 | [diff] [blame] | 158 | struct urb *urb; /* BULK-transfer handling: urb */ |
H Hartley Sweeten | 2696154 | 2015-08-24 10:13:57 -0700 | [diff] [blame] | 159 | u8 *duxbuf; |
| 160 | s8 *inbuf; |
Mariusz Kozlowski | 4e8ad0d | 2009-02-16 21:31:28 +0100 | [diff] [blame] | 161 | short int ai_cmd_running; /* asynchronous command is running */ |
H Hartley Sweeten | 24b8378 | 2015-08-24 10:13:58 -0700 | [diff] [blame] | 162 | int ignore; /* counter which ignores the first buffers */ |
Ksenija Stanojevic | 27a9069 | 2015-10-02 22:07:54 +0200 | [diff] [blame] | 163 | struct mutex mut; |
Mariusz Kozlowski | 4e8ad0d | 2009-02-16 21:31:28 +0100 | [diff] [blame] | 164 | }; |
Bernd Porr | f47c697 | 2008-11-14 14:49:34 -0800 | [diff] [blame] | 165 | |
Mariusz Kozlowski | 4e8ad0d | 2009-02-16 21:31:28 +0100 | [diff] [blame] | 166 | /* |
Mariusz Kozlowski | 4e8ad0d | 2009-02-16 21:31:28 +0100 | [diff] [blame] | 167 | * bulk transfers to usbduxfast |
| 168 | */ |
Bernd Porr | f47c697 | 2008-11-14 14:49:34 -0800 | [diff] [blame] | 169 | #define SENDADCOMMANDS 0 |
| 170 | #define SENDINITEP6 1 |
| 171 | |
H Hartley Sweeten | 665ff8d | 2013-05-14 13:37:38 -0700 | [diff] [blame] | 172 | static int usbduxfast_send_cmd(struct comedi_device *dev, int cmd_type) |
Bernd Porr | f47c697 | 2008-11-14 14:49:34 -0800 | [diff] [blame] | 173 | { |
H Hartley Sweeten | 0a92de2 | 2013-05-20 14:20:30 -0700 | [diff] [blame] | 174 | struct usb_device *usb = comedi_to_usb_dev(dev); |
H Hartley Sweeten | da63c39 | 2013-05-14 13:33:13 -0700 | [diff] [blame] | 175 | struct usbduxfast_private *devpriv = dev->private; |
H Hartley Sweeten | 665ff8d | 2013-05-14 13:37:38 -0700 | [diff] [blame] | 176 | int nsent; |
| 177 | int ret; |
Mariusz Kozlowski | 0a3b8b6 | 2009-02-16 21:31:27 +0100 | [diff] [blame] | 178 | |
H Hartley Sweeten | 5659e24 | 2013-05-14 13:36:47 -0700 | [diff] [blame] | 179 | devpriv->duxbuf[0] = cmd_type; |
Mariusz Kozlowski | 0a3b8b6 | 2009-02-16 21:31:27 +0100 | [diff] [blame] | 180 | |
H Hartley Sweeten | 665ff8d | 2013-05-14 13:37:38 -0700 | [diff] [blame] | 181 | ret = usb_bulk_msg(usb, usb_sndbulkpipe(usb, CHANNELLISTEP), |
H Hartley Sweeten | 5659e24 | 2013-05-14 13:36:47 -0700 | [diff] [blame] | 182 | devpriv->duxbuf, SIZEOFDUXBUF, |
| 183 | &nsent, 10000); |
H Hartley Sweeten | 665ff8d | 2013-05-14 13:37:38 -0700 | [diff] [blame] | 184 | if (ret < 0) |
H Hartley Sweeten | 106af99 | 2013-05-14 13:34:31 -0700 | [diff] [blame] | 185 | dev_err(dev->class_dev, |
H Hartley Sweeten | 5659e24 | 2013-05-14 13:36:47 -0700 | [diff] [blame] | 186 | "could not transmit command to the usb-device, err=%d\n", |
H Hartley Sweeten | 665ff8d | 2013-05-14 13:37:38 -0700 | [diff] [blame] | 187 | ret); |
| 188 | return ret; |
Bernd Porr | f47c697 | 2008-11-14 14:49:34 -0800 | [diff] [blame] | 189 | } |
| 190 | |
H Hartley Sweeten | 17fdeba | 2013-05-14 13:41:30 -0700 | [diff] [blame] | 191 | static void usbduxfast_cmd_data(struct comedi_device *dev, int index, |
H Hartley Sweeten | 2696154 | 2015-08-24 10:13:57 -0700 | [diff] [blame] | 192 | u8 len, u8 op, u8 out, u8 log) |
H Hartley Sweeten | 17fdeba | 2013-05-14 13:41:30 -0700 | [diff] [blame] | 193 | { |
| 194 | struct usbduxfast_private *devpriv = dev->private; |
| 195 | |
| 196 | /* Set the GPIF bytes, the first byte is the command byte */ |
| 197 | devpriv->duxbuf[1 + 0x00 + index] = len; |
| 198 | devpriv->duxbuf[1 + 0x08 + index] = op; |
| 199 | devpriv->duxbuf[1 + 0x10 + index] = out; |
| 200 | devpriv->duxbuf[1 + 0x18 + index] = log; |
| 201 | } |
| 202 | |
H Hartley Sweeten | 32fa46b | 2013-05-14 13:38:21 -0700 | [diff] [blame] | 203 | static int usbduxfast_ai_stop(struct comedi_device *dev, int do_unlink) |
Bernd Porr | f47c697 | 2008-11-14 14:49:34 -0800 | [diff] [blame] | 204 | { |
H Hartley Sweeten | da63c39 | 2013-05-14 13:33:13 -0700 | [diff] [blame] | 205 | struct usbduxfast_private *devpriv = dev->private; |
Bernd Porr | f47c697 | 2008-11-14 14:49:34 -0800 | [diff] [blame] | 206 | |
H Hartley Sweeten | 32fa46b | 2013-05-14 13:38:21 -0700 | [diff] [blame] | 207 | /* stop aquistion */ |
H Hartley Sweeten | 7aa41c3 | 2013-05-14 13:27:37 -0700 | [diff] [blame] | 208 | devpriv->ai_cmd_running = 0; |
Bernd Porr | f47c697 | 2008-11-14 14:49:34 -0800 | [diff] [blame] | 209 | |
H Hartley Sweeten | 32fa46b | 2013-05-14 13:38:21 -0700 | [diff] [blame] | 210 | if (do_unlink && devpriv->urb) { |
| 211 | /* kill the running transfer */ |
| 212 | usb_kill_urb(devpriv->urb); |
| 213 | } |
Bernd Porr | f47c697 | 2008-11-14 14:49:34 -0800 | [diff] [blame] | 214 | |
H Hartley Sweeten | 32fa46b | 2013-05-14 13:38:21 -0700 | [diff] [blame] | 215 | return 0; |
Bernd Porr | f47c697 | 2008-11-14 14:49:34 -0800 | [diff] [blame] | 216 | } |
| 217 | |
Mithlesh Thukral | 0a85b6f | 2009-06-08 21:04:41 +0530 | [diff] [blame] | 218 | static int usbduxfast_ai_cancel(struct comedi_device *dev, |
| 219 | struct comedi_subdevice *s) |
Bernd Porr | f47c697 | 2008-11-14 14:49:34 -0800 | [diff] [blame] | 220 | { |
H Hartley Sweeten | 7aa41c3 | 2013-05-14 13:27:37 -0700 | [diff] [blame] | 221 | struct usbduxfast_private *devpriv = dev->private; |
Mariusz Kozlowski | 4e8ad0d | 2009-02-16 21:31:28 +0100 | [diff] [blame] | 222 | int ret; |
Bernd Porr | f47c697 | 2008-11-14 14:49:34 -0800 | [diff] [blame] | 223 | |
Ksenija Stanojevic | 27a9069 | 2015-10-02 22:07:54 +0200 | [diff] [blame] | 224 | mutex_lock(&devpriv->mut); |
H Hartley Sweeten | da63c39 | 2013-05-14 13:33:13 -0700 | [diff] [blame] | 225 | ret = usbduxfast_ai_stop(dev, 1); |
Ksenija Stanojevic | 27a9069 | 2015-10-02 22:07:54 +0200 | [diff] [blame] | 226 | mutex_unlock(&devpriv->mut); |
Bernd Porr | f47c697 | 2008-11-14 14:49:34 -0800 | [diff] [blame] | 227 | |
Mariusz Kozlowski | 4e8ad0d | 2009-02-16 21:31:28 +0100 | [diff] [blame] | 228 | return ret; |
Bernd Porr | f47c697 | 2008-11-14 14:49:34 -0800 | [diff] [blame] | 229 | } |
| 230 | |
H Hartley Sweeten | 7c88f9f | 2014-10-14 12:14:39 -0700 | [diff] [blame] | 231 | static void usbduxfast_ai_handle_urb(struct comedi_device *dev, |
| 232 | struct comedi_subdevice *s, |
| 233 | struct urb *urb) |
| 234 | { |
| 235 | struct usbduxfast_private *devpriv = dev->private; |
| 236 | struct comedi_async *async = s->async; |
| 237 | struct comedi_cmd *cmd = &async->cmd; |
| 238 | int ret; |
| 239 | |
| 240 | if (devpriv->ignore) { |
| 241 | devpriv->ignore--; |
| 242 | } else { |
H Hartley Sweeten | c39e050 | 2014-10-31 12:04:28 -0700 | [diff] [blame] | 243 | unsigned int nsamples; |
H Hartley Sweeten | 7c88f9f | 2014-10-14 12:14:39 -0700 | [diff] [blame] | 244 | |
H Hartley Sweeten | c39e050 | 2014-10-31 12:04:28 -0700 | [diff] [blame] | 245 | nsamples = comedi_bytes_to_samples(s, urb->actual_length); |
H Hartley Sweeten | 979f999 | 2014-11-05 10:31:35 -0700 | [diff] [blame] | 246 | nsamples = comedi_nsamples_left(s, nsamples); |
H Hartley Sweeten | f81ac41 | 2014-10-22 15:36:45 -0700 | [diff] [blame] | 247 | comedi_buf_write_samples(s, urb->transfer_buffer, nsamples); |
H Hartley Sweeten | 979f999 | 2014-11-05 10:31:35 -0700 | [diff] [blame] | 248 | |
| 249 | if (cmd->stop_src == TRIG_COUNT && |
| 250 | async->scans_done >= cmd->stop_arg) |
| 251 | async->events |= COMEDI_CB_EOA; |
H Hartley Sweeten | 7c88f9f | 2014-10-14 12:14:39 -0700 | [diff] [blame] | 252 | } |
| 253 | |
| 254 | /* if command is still running, resubmit urb for BULK transfer */ |
| 255 | if (!(async->events & COMEDI_CB_CANCEL_MASK)) { |
| 256 | urb->dev = comedi_to_usb_dev(dev); |
| 257 | urb->status = 0; |
| 258 | ret = usb_submit_urb(urb, GFP_ATOMIC); |
| 259 | if (ret < 0) { |
| 260 | dev_err(dev->class_dev, "urb resubm failed: %d", ret); |
| 261 | async->events |= COMEDI_CB_ERROR; |
| 262 | } |
| 263 | } |
| 264 | } |
| 265 | |
H Hartley Sweeten | f8eb27e | 2013-05-14 13:29:09 -0700 | [diff] [blame] | 266 | static void usbduxfast_ai_interrupt(struct urb *urb) |
Bernd Porr | f47c697 | 2008-11-14 14:49:34 -0800 | [diff] [blame] | 267 | { |
H Hartley Sweeten | f8eb27e | 2013-05-14 13:29:09 -0700 | [diff] [blame] | 268 | struct comedi_device *dev = urb->context; |
| 269 | struct comedi_subdevice *s = dev->read_subdev; |
| 270 | struct comedi_async *async = s->async; |
| 271 | struct usbduxfast_private *devpriv = dev->private; |
Bernd Porr | f47c697 | 2008-11-14 14:49:34 -0800 | [diff] [blame] | 272 | |
H Hartley Sweeten | 7c88f9f | 2014-10-14 12:14:39 -0700 | [diff] [blame] | 273 | /* exit if not running a command, do not resubmit urb */ |
| 274 | if (!devpriv->ai_cmd_running) |
Bernd Porr | f47c697 | 2008-11-14 14:49:34 -0800 | [diff] [blame] | 275 | return; |
Bernd Porr | f47c697 | 2008-11-14 14:49:34 -0800 | [diff] [blame] | 276 | |
Bernd Porr | f47c697 | 2008-11-14 14:49:34 -0800 | [diff] [blame] | 277 | switch (urb->status) { |
| 278 | case 0: |
H Hartley Sweeten | 7c88f9f | 2014-10-14 12:14:39 -0700 | [diff] [blame] | 279 | usbduxfast_ai_handle_urb(dev, s, urb); |
Bernd Porr | f47c697 | 2008-11-14 14:49:34 -0800 | [diff] [blame] | 280 | break; |
| 281 | |
Bernd Porr | f47c697 | 2008-11-14 14:49:34 -0800 | [diff] [blame] | 282 | case -ECONNRESET: |
| 283 | case -ENOENT: |
| 284 | case -ESHUTDOWN: |
| 285 | case -ECONNABORTED: |
H Hartley Sweeten | 7c88f9f | 2014-10-14 12:14:39 -0700 | [diff] [blame] | 286 | /* after an unlink command, unplug, ... etc */ |
H Hartley Sweeten | f8eb27e | 2013-05-14 13:29:09 -0700 | [diff] [blame] | 287 | async->events |= COMEDI_CB_ERROR; |
H Hartley Sweeten | 7c88f9f | 2014-10-14 12:14:39 -0700 | [diff] [blame] | 288 | break; |
Bernd Porr | f47c697 | 2008-11-14 14:49:34 -0800 | [diff] [blame] | 289 | |
| 290 | default: |
H Hartley Sweeten | 7c88f9f | 2014-10-14 12:14:39 -0700 | [diff] [blame] | 291 | /* a real error */ |
H Hartley Sweeten | 42f4acd | 2014-07-17 12:27:28 -0700 | [diff] [blame] | 292 | dev_err(dev->class_dev, |
| 293 | "non-zero urb status received in ai intr context: %d\n", |
| 294 | urb->status); |
H Hartley Sweeten | f8eb27e | 2013-05-14 13:29:09 -0700 | [diff] [blame] | 295 | async->events |= COMEDI_CB_ERROR; |
H Hartley Sweeten | 7c88f9f | 2014-10-14 12:14:39 -0700 | [diff] [blame] | 296 | break; |
Bernd Porr | f47c697 | 2008-11-14 14:49:34 -0800 | [diff] [blame] | 297 | } |
| 298 | |
Mariusz Kozlowski | 4e8ad0d | 2009-02-16 21:31:28 +0100 | [diff] [blame] | 299 | /* |
H Hartley Sweeten | 7c88f9f | 2014-10-14 12:14:39 -0700 | [diff] [blame] | 300 | * comedi_handle_events() cannot be used in this driver. The (*cancel) |
| 301 | * operation would unlink the urb. |
Mariusz Kozlowski | 4e8ad0d | 2009-02-16 21:31:28 +0100 | [diff] [blame] | 302 | */ |
H Hartley Sweeten | 7c88f9f | 2014-10-14 12:14:39 -0700 | [diff] [blame] | 303 | if (async->events & COMEDI_CB_CANCEL_MASK) |
H Hartley Sweeten | da63c39 | 2013-05-14 13:33:13 -0700 | [diff] [blame] | 304 | usbduxfast_ai_stop(dev, 0); |
H Hartley Sweeten | 7c88f9f | 2014-10-14 12:14:39 -0700 | [diff] [blame] | 305 | |
| 306 | comedi_event(dev, s); |
Bernd Porr | f47c697 | 2008-11-14 14:49:34 -0800 | [diff] [blame] | 307 | } |
| 308 | |
H Hartley Sweeten | ebe9f1c | 2013-05-14 13:41:07 -0700 | [diff] [blame] | 309 | static int usbduxfast_submit_urb(struct comedi_device *dev) |
Bernd Porr | f47c697 | 2008-11-14 14:49:34 -0800 | [diff] [blame] | 310 | { |
H Hartley Sweeten | 0a92de2 | 2013-05-20 14:20:30 -0700 | [diff] [blame] | 311 | struct usb_device *usb = comedi_to_usb_dev(dev); |
H Hartley Sweeten | da63c39 | 2013-05-14 13:33:13 -0700 | [diff] [blame] | 312 | struct usbduxfast_private *devpriv = dev->private; |
Mariusz Kozlowski | 4e8ad0d | 2009-02-16 21:31:28 +0100 | [diff] [blame] | 313 | int ret; |
Bernd Porr | f47c697 | 2008-11-14 14:49:34 -0800 | [diff] [blame] | 314 | |
H Hartley Sweeten | da58c26 | 2013-05-14 13:35:40 -0700 | [diff] [blame] | 315 | usb_fill_bulk_urb(devpriv->urb, usb, usb_rcvbulkpipe(usb, BULKINEP), |
H Hartley Sweeten | ef8e084 | 2013-05-14 13:36:23 -0700 | [diff] [blame] | 316 | devpriv->inbuf, SIZEINBUF, |
H Hartley Sweeten | da63c39 | 2013-05-14 13:33:13 -0700 | [diff] [blame] | 317 | usbduxfast_ai_interrupt, dev); |
Bernd Porr | f47c697 | 2008-11-14 14:49:34 -0800 | [diff] [blame] | 318 | |
H Hartley Sweeten | da58c26 | 2013-05-14 13:35:40 -0700 | [diff] [blame] | 319 | ret = usb_submit_urb(devpriv->urb, GFP_ATOMIC); |
Mariusz Kozlowski | 4e8ad0d | 2009-02-16 21:31:28 +0100 | [diff] [blame] | 320 | if (ret) { |
H Hartley Sweeten | 106af99 | 2013-05-14 13:34:31 -0700 | [diff] [blame] | 321 | dev_err(dev->class_dev, "usb_submit_urb error %d\n", ret); |
Mariusz Kozlowski | 4e8ad0d | 2009-02-16 21:31:28 +0100 | [diff] [blame] | 322 | return ret; |
Bernd Porr | f47c697 | 2008-11-14 14:49:34 -0800 | [diff] [blame] | 323 | } |
| 324 | return 0; |
| 325 | } |
| 326 | |
H Hartley Sweeten | 99555fc | 2015-08-24 10:13:54 -0700 | [diff] [blame] | 327 | static int usbduxfast_ai_check_chanlist(struct comedi_device *dev, |
| 328 | struct comedi_subdevice *s, |
| 329 | struct comedi_cmd *cmd) |
| 330 | { |
| 331 | unsigned int gain0 = CR_RANGE(cmd->chanlist[0]); |
| 332 | int i; |
| 333 | |
H Hartley Sweeten | db1876f | 2015-08-24 10:13:55 -0700 | [diff] [blame] | 334 | if (cmd->chanlist_len > 3 && cmd->chanlist_len != 16) { |
| 335 | dev_err(dev->class_dev, "unsupported combination of channels\n"); |
| 336 | return -EINVAL; |
| 337 | } |
| 338 | |
H Hartley Sweeten | 99555fc | 2015-08-24 10:13:54 -0700 | [diff] [blame] | 339 | for (i = 0; i < cmd->chanlist_len; ++i) { |
| 340 | unsigned int chan = CR_CHAN(cmd->chanlist[i]); |
| 341 | unsigned int gain = CR_RANGE(cmd->chanlist[i]); |
| 342 | |
| 343 | if (chan != i) { |
| 344 | dev_err(dev->class_dev, |
| 345 | "channels are not consecutive\n"); |
| 346 | return -EINVAL; |
| 347 | } |
| 348 | if (gain != gain0 && cmd->chanlist_len > 3) { |
| 349 | dev_err(dev->class_dev, |
| 350 | "gain must be the same for all channels\n"); |
| 351 | return -EINVAL; |
| 352 | } |
| 353 | } |
| 354 | return 0; |
| 355 | } |
| 356 | |
Bill Pemberton | 71b5f4f | 2009-03-16 22:05:08 -0400 | [diff] [blame] | 357 | static int usbduxfast_ai_cmdtest(struct comedi_device *dev, |
Mithlesh Thukral | 0a85b6f | 2009-06-08 21:04:41 +0530 | [diff] [blame] | 358 | struct comedi_subdevice *s, |
| 359 | struct comedi_cmd *cmd) |
Bernd Porr | f47c697 | 2008-11-14 14:49:34 -0800 | [diff] [blame] | 360 | { |
H Hartley Sweeten | 27020ff | 2012-09-26 14:11:10 -0700 | [diff] [blame] | 361 | int err = 0; |
H Hartley Sweeten | c748deb | 2015-08-24 10:14:01 -0700 | [diff] [blame] | 362 | unsigned int steps; |
| 363 | unsigned int arg; |
Mariusz Kozlowski | 4e8ad0d | 2009-02-16 21:31:28 +0100 | [diff] [blame] | 364 | |
H Hartley Sweeten | 27020ff | 2012-09-26 14:11:10 -0700 | [diff] [blame] | 365 | /* Step 1 : check if triggers are trivially valid */ |
Bernd Porr | f47c697 | 2008-11-14 14:49:34 -0800 | [diff] [blame] | 366 | |
Ian Abbott | f53398e | 2015-03-27 19:14:38 +0000 | [diff] [blame] | 367 | err |= comedi_check_trigger_src(&cmd->start_src, |
H Hartley Sweeten | 27020ff | 2012-09-26 14:11:10 -0700 | [diff] [blame] | 368 | TRIG_NOW | TRIG_EXT | TRIG_INT); |
H Hartley Sweeten | fe0d96b | 2015-08-24 10:14:00 -0700 | [diff] [blame] | 369 | err |= comedi_check_trigger_src(&cmd->scan_begin_src, TRIG_FOLLOW); |
| 370 | err |= comedi_check_trigger_src(&cmd->convert_src, TRIG_TIMER); |
Ian Abbott | f53398e | 2015-03-27 19:14:38 +0000 | [diff] [blame] | 371 | err |= comedi_check_trigger_src(&cmd->scan_end_src, TRIG_COUNT); |
| 372 | err |= comedi_check_trigger_src(&cmd->stop_src, TRIG_COUNT | TRIG_NONE); |
Bernd Porr | f47c697 | 2008-11-14 14:49:34 -0800 | [diff] [blame] | 373 | |
| 374 | if (err) |
| 375 | return 1; |
| 376 | |
H Hartley Sweeten | 27020ff | 2012-09-26 14:11:10 -0700 | [diff] [blame] | 377 | /* Step 2a : make sure trigger sources are unique */ |
Bernd Porr | f47c697 | 2008-11-14 14:49:34 -0800 | [diff] [blame] | 378 | |
Ian Abbott | f53398e | 2015-03-27 19:14:38 +0000 | [diff] [blame] | 379 | err |= comedi_check_trigger_is_unique(cmd->start_src); |
Ian Abbott | f53398e | 2015-03-27 19:14:38 +0000 | [diff] [blame] | 380 | err |= comedi_check_trigger_is_unique(cmd->stop_src); |
H Hartley Sweeten | 27020ff | 2012-09-26 14:11:10 -0700 | [diff] [blame] | 381 | |
| 382 | /* Step 2b : and mutually compatible */ |
Bernd Porr | f47c697 | 2008-11-14 14:49:34 -0800 | [diff] [blame] | 383 | |
Bernd Porr | f47c697 | 2008-11-14 14:49:34 -0800 | [diff] [blame] | 384 | if (err) |
| 385 | return 2; |
| 386 | |
H Hartley Sweeten | 9309c47 | 2012-11-13 18:00:06 -0700 | [diff] [blame] | 387 | /* Step 3: check if arguments are trivially valid */ |
Bernd Porr | f47c697 | 2008-11-14 14:49:34 -0800 | [diff] [blame] | 388 | |
Ian Abbott | f53398e | 2015-03-27 19:14:38 +0000 | [diff] [blame] | 389 | err |= comedi_check_trigger_arg_is(&cmd->start_arg, 0); |
Bernd Porr | f47c697 | 2008-11-14 14:49:34 -0800 | [diff] [blame] | 390 | |
Mariusz Kozlowski | 4e8ad0d | 2009-02-16 21:31:28 +0100 | [diff] [blame] | 391 | if (!cmd->chanlist_len) |
H Hartley Sweeten | 9309c47 | 2012-11-13 18:00:06 -0700 | [diff] [blame] | 392 | err |= -EINVAL; |
Mariusz Kozlowski | 4e8ad0d | 2009-02-16 21:31:28 +0100 | [diff] [blame] | 393 | |
H Hartley Sweeten | d636f87 | 2015-08-24 10:13:59 -0700 | [diff] [blame] | 394 | /* external start trigger is only valid for 1 or 16 channels */ |
| 395 | if (cmd->start_src == TRIG_EXT && |
| 396 | cmd->chanlist_len != 1 && cmd->chanlist_len != 16) |
| 397 | err |= -EINVAL; |
| 398 | |
Ian Abbott | f53398e | 2015-03-27 19:14:38 +0000 | [diff] [blame] | 399 | err |= comedi_check_trigger_arg_is(&cmd->scan_end_arg, |
| 400 | cmd->chanlist_len); |
Bernd Porr | f47c697 | 2008-11-14 14:49:34 -0800 | [diff] [blame] | 401 | |
H Hartley Sweeten | c748deb | 2015-08-24 10:14:01 -0700 | [diff] [blame] | 402 | /* |
| 403 | * Validate the conversion timing: |
| 404 | * for 1 channel the timing in 30MHz "steps" is: |
| 405 | * steps <= MAX_SAMPLING_PERIOD |
| 406 | * for all other chanlist_len it is: |
| 407 | * MIN_SAMPLING_PERIOD <= steps <= MAX_SAMPLING_PERIOD |
| 408 | */ |
| 409 | steps = (cmd->convert_arg * 30) / 1000; |
| 410 | if (cmd->chanlist_len != 1) |
| 411 | err |= comedi_check_trigger_arg_min(&steps, |
| 412 | MIN_SAMPLING_PERIOD); |
| 413 | err |= comedi_check_trigger_arg_max(&steps, MAX_SAMPLING_PERIOD); |
| 414 | arg = (steps * 1000) / 30; |
| 415 | err |= comedi_check_trigger_arg_is(&cmd->convert_arg, arg); |
Bernd Porr | f47c697 | 2008-11-14 14:49:34 -0800 | [diff] [blame] | 416 | |
H Hartley Sweeten | fe0d96b | 2015-08-24 10:14:00 -0700 | [diff] [blame] | 417 | if (cmd->stop_src == TRIG_COUNT) |
Ian Abbott | f53398e | 2015-03-27 19:14:38 +0000 | [diff] [blame] | 418 | err |= comedi_check_trigger_arg_min(&cmd->stop_arg, 1); |
H Hartley Sweeten | fe0d96b | 2015-08-24 10:14:00 -0700 | [diff] [blame] | 419 | else /* TRIG_NONE */ |
Ian Abbott | f53398e | 2015-03-27 19:14:38 +0000 | [diff] [blame] | 420 | err |= comedi_check_trigger_arg_is(&cmd->stop_arg, 0); |
Bernd Porr | f47c697 | 2008-11-14 14:49:34 -0800 | [diff] [blame] | 421 | |
| 422 | if (err) |
| 423 | return 3; |
| 424 | |
H Hartley Sweeten | 99555fc | 2015-08-24 10:13:54 -0700 | [diff] [blame] | 425 | /* Step 4: fix up any arguments */ |
| 426 | |
| 427 | /* Step 5: check channel list if it exists */ |
| 428 | if (cmd->chanlist && cmd->chanlist_len > 0) |
| 429 | err |= usbduxfast_ai_check_chanlist(dev, s, cmd); |
| 430 | if (err) |
| 431 | return 5; |
Bernd Porr | f47c697 | 2008-11-14 14:49:34 -0800 | [diff] [blame] | 432 | |
| 433 | return 0; |
Bernd Porr | f47c697 | 2008-11-14 14:49:34 -0800 | [diff] [blame] | 434 | } |
| 435 | |
Bill Pemberton | 71b5f4f | 2009-03-16 22:05:08 -0400 | [diff] [blame] | 436 | static int usbduxfast_ai_inttrig(struct comedi_device *dev, |
Mithlesh Thukral | 0a85b6f | 2009-06-08 21:04:41 +0530 | [diff] [blame] | 437 | struct comedi_subdevice *s, |
H Hartley Sweeten | 9519459 | 2014-04-17 10:08:09 -0700 | [diff] [blame] | 438 | unsigned int trig_num) |
Bernd Porr | f47c697 | 2008-11-14 14:49:34 -0800 | [diff] [blame] | 439 | { |
H Hartley Sweeten | 7aa41c3 | 2013-05-14 13:27:37 -0700 | [diff] [blame] | 440 | struct usbduxfast_private *devpriv = dev->private; |
H Hartley Sweeten | 9519459 | 2014-04-17 10:08:09 -0700 | [diff] [blame] | 441 | struct comedi_cmd *cmd = &s->async->cmd; |
Bernd Porr | f47c697 | 2008-11-14 14:49:34 -0800 | [diff] [blame] | 442 | int ret; |
Mariusz Kozlowski | 4e8ad0d | 2009-02-16 21:31:28 +0100 | [diff] [blame] | 443 | |
H Hartley Sweeten | 9519459 | 2014-04-17 10:08:09 -0700 | [diff] [blame] | 444 | if (trig_num != cmd->start_arg) |
| 445 | return -EINVAL; |
| 446 | |
Ksenija Stanojevic | 27a9069 | 2015-10-02 22:07:54 +0200 | [diff] [blame] | 447 | mutex_lock(&devpriv->mut); |
Bernd Porr | f47c697 | 2008-11-14 14:49:34 -0800 | [diff] [blame] | 448 | |
H Hartley Sweeten | 7aa41c3 | 2013-05-14 13:27:37 -0700 | [diff] [blame] | 449 | if (!devpriv->ai_cmd_running) { |
| 450 | devpriv->ai_cmd_running = 1; |
H Hartley Sweeten | ebe9f1c | 2013-05-14 13:41:07 -0700 | [diff] [blame] | 451 | ret = usbduxfast_submit_urb(dev); |
Bernd Porr | f47c697 | 2008-11-14 14:49:34 -0800 | [diff] [blame] | 452 | if (ret < 0) { |
H Hartley Sweeten | 106af99 | 2013-05-14 13:34:31 -0700 | [diff] [blame] | 453 | dev_err(dev->class_dev, "urbSubmit: err=%d\n", ret); |
H Hartley Sweeten | 7aa41c3 | 2013-05-14 13:27:37 -0700 | [diff] [blame] | 454 | devpriv->ai_cmd_running = 0; |
Ksenija Stanojevic | 27a9069 | 2015-10-02 22:07:54 +0200 | [diff] [blame] | 455 | mutex_unlock(&devpriv->mut); |
Bernd Porr | f47c697 | 2008-11-14 14:49:34 -0800 | [diff] [blame] | 456 | return ret; |
| 457 | } |
| 458 | s->async->inttrig = NULL; |
| 459 | } else { |
H Hartley Sweeten | 106af99 | 2013-05-14 13:34:31 -0700 | [diff] [blame] | 460 | dev_err(dev->class_dev, "ai is already running\n"); |
Bernd Porr | f47c697 | 2008-11-14 14:49:34 -0800 | [diff] [blame] | 461 | } |
Ksenija Stanojevic | 27a9069 | 2015-10-02 22:07:54 +0200 | [diff] [blame] | 462 | mutex_unlock(&devpriv->mut); |
Bernd Porr | f47c697 | 2008-11-14 14:49:34 -0800 | [diff] [blame] | 463 | return 1; |
| 464 | } |
| 465 | |
Mithlesh Thukral | 0a85b6f | 2009-06-08 21:04:41 +0530 | [diff] [blame] | 466 | static int usbduxfast_ai_cmd(struct comedi_device *dev, |
| 467 | struct comedi_subdevice *s) |
Bernd Porr | f47c697 | 2008-11-14 14:49:34 -0800 | [diff] [blame] | 468 | { |
H Hartley Sweeten | 7aa41c3 | 2013-05-14 13:27:37 -0700 | [diff] [blame] | 469 | struct usbduxfast_private *devpriv = dev->private; |
Bill Pemberton | ea6d0d4 | 2009-03-16 22:05:47 -0400 | [diff] [blame] | 470 | struct comedi_cmd *cmd = &s->async->cmd; |
H Hartley Sweeten | 99555fc | 2015-08-24 10:13:54 -0700 | [diff] [blame] | 471 | unsigned int rngmask = 0xff; |
| 472 | int j, ret; |
Bernd Porr | f47c697 | 2008-11-14 14:49:34 -0800 | [diff] [blame] | 473 | long steps, steps_tmp; |
| 474 | |
Ksenija Stanojevic | 27a9069 | 2015-10-02 22:07:54 +0200 | [diff] [blame] | 475 | mutex_lock(&devpriv->mut); |
H Hartley Sweeten | 7aa41c3 | 2013-05-14 13:27:37 -0700 | [diff] [blame] | 476 | if (devpriv->ai_cmd_running) { |
H Hartley Sweeten | 7b0fc5b | 2015-08-24 10:14:02 -0700 | [diff] [blame] | 477 | ret = -EBUSY; |
| 478 | goto cmd_exit; |
Bernd Porr | f47c697 | 2008-11-14 14:49:34 -0800 | [diff] [blame] | 479 | } |
Bernd Porr | f47c697 | 2008-11-14 14:49:34 -0800 | [diff] [blame] | 480 | |
Mariusz Kozlowski | 4e8ad0d | 2009-02-16 21:31:28 +0100 | [diff] [blame] | 481 | /* |
| 482 | * ignore the first buffers from the device if there |
| 483 | * is an error condition |
| 484 | */ |
H Hartley Sweeten | 7aa41c3 | 2013-05-14 13:27:37 -0700 | [diff] [blame] | 485 | devpriv->ignore = PACKETS_TO_IGNORE; |
Bernd Porr | f47c697 | 2008-11-14 14:49:34 -0800 | [diff] [blame] | 486 | |
H Hartley Sweeten | fe0d96b | 2015-08-24 10:14:00 -0700 | [diff] [blame] | 487 | steps = (cmd->convert_arg * 30) / 1000; |
Mariusz Kozlowski | 4e8ad0d | 2009-02-16 21:31:28 +0100 | [diff] [blame] | 488 | |
Bernd Porr | f47c697 | 2008-11-14 14:49:34 -0800 | [diff] [blame] | 489 | switch (cmd->chanlist_len) { |
Bernd Porr | f47c697 | 2008-11-14 14:49:34 -0800 | [diff] [blame] | 490 | case 1: |
Mariusz Kozlowski | 4e8ad0d | 2009-02-16 21:31:28 +0100 | [diff] [blame] | 491 | /* |
| 492 | * one channel |
| 493 | */ |
| 494 | |
Bernd Porr | f47c697 | 2008-11-14 14:49:34 -0800 | [diff] [blame] | 495 | if (CR_RANGE(cmd->chanlist[0]) > 0) |
| 496 | rngmask = 0xff - 0x04; |
| 497 | else |
| 498 | rngmask = 0xff; |
| 499 | |
Mariusz Kozlowski | 4e8ad0d | 2009-02-16 21:31:28 +0100 | [diff] [blame] | 500 | /* |
| 501 | * for external trigger: looping in this state until |
| 502 | * the RDY0 pin becomes zero |
| 503 | */ |
| 504 | |
| 505 | /* we loop here until ready has been set */ |
| 506 | if (cmd->start_src == TRIG_EXT) { |
| 507 | /* branch back to state 0 */ |
Mariusz Kozlowski | 4e8ad0d | 2009-02-16 21:31:28 +0100 | [diff] [blame] | 508 | /* deceision state w/o data */ |
Mariusz Kozlowski | 4e8ad0d | 2009-02-16 21:31:28 +0100 | [diff] [blame] | 509 | /* RDY0 = 0 */ |
H Hartley Sweeten | 17fdeba | 2013-05-14 13:41:30 -0700 | [diff] [blame] | 510 | usbduxfast_cmd_data(dev, 0, 0x01, 0x01, rngmask, 0x00); |
Mariusz Kozlowski | 4e8ad0d | 2009-02-16 21:31:28 +0100 | [diff] [blame] | 511 | } else { /* we just proceed to state 1 */ |
H Hartley Sweeten | 17fdeba | 2013-05-14 13:41:30 -0700 | [diff] [blame] | 512 | usbduxfast_cmd_data(dev, 0, 0x01, 0x00, rngmask, 0x00); |
Bernd Porr | f47c697 | 2008-11-14 14:49:34 -0800 | [diff] [blame] | 513 | } |
| 514 | |
| 515 | if (steps < MIN_SAMPLING_PERIOD) { |
Mariusz Kozlowski | 4e8ad0d | 2009-02-16 21:31:28 +0100 | [diff] [blame] | 516 | /* for fast single channel aqu without mux */ |
Bernd Porr | f47c697 | 2008-11-14 14:49:34 -0800 | [diff] [blame] | 517 | if (steps <= 1) { |
Mariusz Kozlowski | 4e8ad0d | 2009-02-16 21:31:28 +0100 | [diff] [blame] | 518 | /* |
| 519 | * we just stay here at state 1 and rexecute |
| 520 | * the same state this gives us 30MHz sampling |
| 521 | * rate |
| 522 | */ |
Bernd Porr | f47c697 | 2008-11-14 14:49:34 -0800 | [diff] [blame] | 523 | |
Mariusz Kozlowski | 4e8ad0d | 2009-02-16 21:31:28 +0100 | [diff] [blame] | 524 | /* branch back to state 1 */ |
Mariusz Kozlowski | 4e8ad0d | 2009-02-16 21:31:28 +0100 | [diff] [blame] | 525 | /* deceision state with data */ |
Mariusz Kozlowski | 4e8ad0d | 2009-02-16 21:31:28 +0100 | [diff] [blame] | 526 | /* doesn't matter */ |
H Hartley Sweeten | 17fdeba | 2013-05-14 13:41:30 -0700 | [diff] [blame] | 527 | usbduxfast_cmd_data(dev, 1, |
| 528 | 0x89, 0x03, rngmask, 0xff); |
Mariusz Kozlowski | 4e8ad0d | 2009-02-16 21:31:28 +0100 | [diff] [blame] | 529 | } else { |
| 530 | /* |
| 531 | * we loop through two states: data and delay |
| 532 | * max rate is 15MHz |
| 533 | */ |
Mariusz Kozlowski | 4e8ad0d | 2009-02-16 21:31:28 +0100 | [diff] [blame] | 534 | /* data */ |
Mariusz Kozlowski | 4e8ad0d | 2009-02-16 21:31:28 +0100 | [diff] [blame] | 535 | /* doesn't matter */ |
H Hartley Sweeten | 17fdeba | 2013-05-14 13:41:30 -0700 | [diff] [blame] | 536 | usbduxfast_cmd_data(dev, 1, steps - 1, |
| 537 | 0x02, rngmask, 0x00); |
| 538 | |
Mariusz Kozlowski | 4e8ad0d | 2009-02-16 21:31:28 +0100 | [diff] [blame] | 539 | /* branch back to state 1 */ |
Mariusz Kozlowski | 4e8ad0d | 2009-02-16 21:31:28 +0100 | [diff] [blame] | 540 | /* deceision state w/o data */ |
Mariusz Kozlowski | 4e8ad0d | 2009-02-16 21:31:28 +0100 | [diff] [blame] | 541 | /* doesn't matter */ |
H Hartley Sweeten | 17fdeba | 2013-05-14 13:41:30 -0700 | [diff] [blame] | 542 | usbduxfast_cmd_data(dev, 2, |
| 543 | 0x09, 0x01, rngmask, 0xff); |
Bernd Porr | f47c697 | 2008-11-14 14:49:34 -0800 | [diff] [blame] | 544 | } |
| 545 | } else { |
Mariusz Kozlowski | 4e8ad0d | 2009-02-16 21:31:28 +0100 | [diff] [blame] | 546 | /* |
| 547 | * we loop through 3 states: 2x delay and 1x data |
| 548 | * this gives a min sampling rate of 60kHz |
| 549 | */ |
Bernd Porr | f47c697 | 2008-11-14 14:49:34 -0800 | [diff] [blame] | 550 | |
Mariusz Kozlowski | 4e8ad0d | 2009-02-16 21:31:28 +0100 | [diff] [blame] | 551 | /* we have 1 state with duration 1 */ |
Bernd Porr | f47c697 | 2008-11-14 14:49:34 -0800 | [diff] [blame] | 552 | steps = steps - 1; |
| 553 | |
Mariusz Kozlowski | 4e8ad0d | 2009-02-16 21:31:28 +0100 | [diff] [blame] | 554 | /* do the first part of the delay */ |
H Hartley Sweeten | 17fdeba | 2013-05-14 13:41:30 -0700 | [diff] [blame] | 555 | usbduxfast_cmd_data(dev, 1, |
| 556 | steps / 2, 0x00, rngmask, 0x00); |
Bernd Porr | f47c697 | 2008-11-14 14:49:34 -0800 | [diff] [blame] | 557 | |
Mariusz Kozlowski | 4e8ad0d | 2009-02-16 21:31:28 +0100 | [diff] [blame] | 558 | /* and the second part */ |
H Hartley Sweeten | 17fdeba | 2013-05-14 13:41:30 -0700 | [diff] [blame] | 559 | usbduxfast_cmd_data(dev, 2, steps - steps / 2, |
| 560 | 0x00, rngmask, 0x00); |
Bernd Porr | f47c697 | 2008-11-14 14:49:34 -0800 | [diff] [blame] | 561 | |
Mariusz Kozlowski | 4e8ad0d | 2009-02-16 21:31:28 +0100 | [diff] [blame] | 562 | /* get the data and branch back */ |
| 563 | |
| 564 | /* branch back to state 1 */ |
Mariusz Kozlowski | 4e8ad0d | 2009-02-16 21:31:28 +0100 | [diff] [blame] | 565 | /* deceision state w data */ |
Mariusz Kozlowski | 4e8ad0d | 2009-02-16 21:31:28 +0100 | [diff] [blame] | 566 | /* doesn't matter */ |
H Hartley Sweeten | 17fdeba | 2013-05-14 13:41:30 -0700 | [diff] [blame] | 567 | usbduxfast_cmd_data(dev, 3, |
| 568 | 0x09, 0x03, rngmask, 0xff); |
Bernd Porr | f47c697 | 2008-11-14 14:49:34 -0800 | [diff] [blame] | 569 | } |
| 570 | break; |
| 571 | |
| 572 | case 2: |
Mariusz Kozlowski | 4e8ad0d | 2009-02-16 21:31:28 +0100 | [diff] [blame] | 573 | /* |
| 574 | * two channels |
| 575 | * commit data to the FIFO |
| 576 | */ |
| 577 | |
Bernd Porr | f47c697 | 2008-11-14 14:49:34 -0800 | [diff] [blame] | 578 | if (CR_RANGE(cmd->chanlist[0]) > 0) |
| 579 | rngmask = 0xff - 0x04; |
| 580 | else |
| 581 | rngmask = 0xff; |
Bernd Porr | f47c697 | 2008-11-14 14:49:34 -0800 | [diff] [blame] | 582 | |
Mariusz Kozlowski | 4e8ad0d | 2009-02-16 21:31:28 +0100 | [diff] [blame] | 583 | /* data */ |
H Hartley Sweeten | 17fdeba | 2013-05-14 13:41:30 -0700 | [diff] [blame] | 584 | usbduxfast_cmd_data(dev, 0, 0x01, 0x02, rngmask, 0x00); |
Mariusz Kozlowski | 4e8ad0d | 2009-02-16 21:31:28 +0100 | [diff] [blame] | 585 | |
| 586 | /* we have 1 state with duration 1: state 0 */ |
Bernd Porr | f47c697 | 2008-11-14 14:49:34 -0800 | [diff] [blame] | 587 | steps_tmp = steps - 1; |
| 588 | |
| 589 | if (CR_RANGE(cmd->chanlist[1]) > 0) |
| 590 | rngmask = 0xff - 0x04; |
| 591 | else |
| 592 | rngmask = 0xff; |
Bernd Porr | f47c697 | 2008-11-14 14:49:34 -0800 | [diff] [blame] | 593 | |
Mariusz Kozlowski | 4e8ad0d | 2009-02-16 21:31:28 +0100 | [diff] [blame] | 594 | /* do the first part of the delay */ |
Mariusz Kozlowski | 4e8ad0d | 2009-02-16 21:31:28 +0100 | [diff] [blame] | 595 | /* count */ |
H Hartley Sweeten | 17fdeba | 2013-05-14 13:41:30 -0700 | [diff] [blame] | 596 | usbduxfast_cmd_data(dev, 1, steps_tmp / 2, |
| 597 | 0x00, 0xfe & rngmask, 0x00); |
Bernd Porr | f47c697 | 2008-11-14 14:49:34 -0800 | [diff] [blame] | 598 | |
Mariusz Kozlowski | 4e8ad0d | 2009-02-16 21:31:28 +0100 | [diff] [blame] | 599 | /* and the second part */ |
H Hartley Sweeten | 17fdeba | 2013-05-14 13:41:30 -0700 | [diff] [blame] | 600 | usbduxfast_cmd_data(dev, 2, steps_tmp - steps_tmp / 2, |
| 601 | 0x00, rngmask, 0x00); |
Bernd Porr | f47c697 | 2008-11-14 14:49:34 -0800 | [diff] [blame] | 602 | |
Mariusz Kozlowski | 4e8ad0d | 2009-02-16 21:31:28 +0100 | [diff] [blame] | 603 | /* data */ |
H Hartley Sweeten | 17fdeba | 2013-05-14 13:41:30 -0700 | [diff] [blame] | 604 | usbduxfast_cmd_data(dev, 3, 0x01, 0x02, rngmask, 0x00); |
Mariusz Kozlowski | 4e8ad0d | 2009-02-16 21:31:28 +0100 | [diff] [blame] | 605 | |
| 606 | /* |
| 607 | * we have 2 states with duration 1: step 6 and |
| 608 | * the IDLE state |
| 609 | */ |
Bernd Porr | f47c697 | 2008-11-14 14:49:34 -0800 | [diff] [blame] | 610 | steps_tmp = steps - 2; |
| 611 | |
| 612 | if (CR_RANGE(cmd->chanlist[0]) > 0) |
| 613 | rngmask = 0xff - 0x04; |
| 614 | else |
| 615 | rngmask = 0xff; |
Bernd Porr | f47c697 | 2008-11-14 14:49:34 -0800 | [diff] [blame] | 616 | |
Mariusz Kozlowski | 4e8ad0d | 2009-02-16 21:31:28 +0100 | [diff] [blame] | 617 | /* do the first part of the delay */ |
Mariusz Kozlowski | 4e8ad0d | 2009-02-16 21:31:28 +0100 | [diff] [blame] | 618 | /* reset */ |
H Hartley Sweeten | 17fdeba | 2013-05-14 13:41:30 -0700 | [diff] [blame] | 619 | usbduxfast_cmd_data(dev, 4, steps_tmp / 2, |
| 620 | 0x00, (0xff - 0x02) & rngmask, 0x00); |
Bernd Porr | f47c697 | 2008-11-14 14:49:34 -0800 | [diff] [blame] | 621 | |
Mariusz Kozlowski | 4e8ad0d | 2009-02-16 21:31:28 +0100 | [diff] [blame] | 622 | /* and the second part */ |
H Hartley Sweeten | 17fdeba | 2013-05-14 13:41:30 -0700 | [diff] [blame] | 623 | usbduxfast_cmd_data(dev, 5, steps_tmp - steps_tmp / 2, |
| 624 | 0x00, rngmask, 0x00); |
Mariusz Kozlowski | 4e8ad0d | 2009-02-16 21:31:28 +0100 | [diff] [blame] | 625 | |
H Hartley Sweeten | 17fdeba | 2013-05-14 13:41:30 -0700 | [diff] [blame] | 626 | usbduxfast_cmd_data(dev, 6, 0x01, 0x00, rngmask, 0x00); |
Bernd Porr | f47c697 | 2008-11-14 14:49:34 -0800 | [diff] [blame] | 627 | break; |
| 628 | |
| 629 | case 3: |
Mariusz Kozlowski | 4e8ad0d | 2009-02-16 21:31:28 +0100 | [diff] [blame] | 630 | /* |
| 631 | * three channels |
| 632 | */ |
Bernd Porr | f47c697 | 2008-11-14 14:49:34 -0800 | [diff] [blame] | 633 | for (j = 0; j < 1; j++) { |
H Hartley Sweeten | 17fdeba | 2013-05-14 13:41:30 -0700 | [diff] [blame] | 634 | int index = j * 2; |
| 635 | |
Bernd Porr | f47c697 | 2008-11-14 14:49:34 -0800 | [diff] [blame] | 636 | if (CR_RANGE(cmd->chanlist[j]) > 0) |
| 637 | rngmask = 0xff - 0x04; |
| 638 | else |
| 639 | rngmask = 0xff; |
Mariusz Kozlowski | 4e8ad0d | 2009-02-16 21:31:28 +0100 | [diff] [blame] | 640 | /* |
| 641 | * commit data to the FIFO and do the first part |
| 642 | * of the delay |
| 643 | */ |
Mariusz Kozlowski | 4e8ad0d | 2009-02-16 21:31:28 +0100 | [diff] [blame] | 644 | /* data */ |
Mariusz Kozlowski | 4e8ad0d | 2009-02-16 21:31:28 +0100 | [diff] [blame] | 645 | /* no change */ |
H Hartley Sweeten | 17fdeba | 2013-05-14 13:41:30 -0700 | [diff] [blame] | 646 | usbduxfast_cmd_data(dev, index, steps / 2, |
| 647 | 0x02, rngmask, 0x00); |
Bernd Porr | f47c697 | 2008-11-14 14:49:34 -0800 | [diff] [blame] | 648 | |
| 649 | if (CR_RANGE(cmd->chanlist[j + 1]) > 0) |
| 650 | rngmask = 0xff - 0x04; |
| 651 | else |
| 652 | rngmask = 0xff; |
Mariusz Kozlowski | 4e8ad0d | 2009-02-16 21:31:28 +0100 | [diff] [blame] | 653 | |
| 654 | /* do the second part of the delay */ |
Mariusz Kozlowski | 4e8ad0d | 2009-02-16 21:31:28 +0100 | [diff] [blame] | 655 | /* no data */ |
Mariusz Kozlowski | 4e8ad0d | 2009-02-16 21:31:28 +0100 | [diff] [blame] | 656 | /* count */ |
H Hartley Sweeten | 17fdeba | 2013-05-14 13:41:30 -0700 | [diff] [blame] | 657 | usbduxfast_cmd_data(dev, index + 1, steps - steps / 2, |
| 658 | 0x00, 0xfe & rngmask, 0x00); |
Bernd Porr | f47c697 | 2008-11-14 14:49:34 -0800 | [diff] [blame] | 659 | } |
| 660 | |
Mariusz Kozlowski | 4e8ad0d | 2009-02-16 21:31:28 +0100 | [diff] [blame] | 661 | /* 2 steps with duration 1: the idele step and step 6: */ |
Bernd Porr | f47c697 | 2008-11-14 14:49:34 -0800 | [diff] [blame] | 662 | steps_tmp = steps - 2; |
Mariusz Kozlowski | 4e8ad0d | 2009-02-16 21:31:28 +0100 | [diff] [blame] | 663 | |
| 664 | /* commit data to the FIFO and do the first part of the delay */ |
Mariusz Kozlowski | 4e8ad0d | 2009-02-16 21:31:28 +0100 | [diff] [blame] | 665 | /* data */ |
H Hartley Sweeten | 17fdeba | 2013-05-14 13:41:30 -0700 | [diff] [blame] | 666 | usbduxfast_cmd_data(dev, 4, steps_tmp / 2, |
| 667 | 0x02, rngmask, 0x00); |
Bernd Porr | f47c697 | 2008-11-14 14:49:34 -0800 | [diff] [blame] | 668 | |
| 669 | if (CR_RANGE(cmd->chanlist[0]) > 0) |
| 670 | rngmask = 0xff - 0x04; |
| 671 | else |
| 672 | rngmask = 0xff; |
Bernd Porr | f47c697 | 2008-11-14 14:49:34 -0800 | [diff] [blame] | 673 | |
Mariusz Kozlowski | 4e8ad0d | 2009-02-16 21:31:28 +0100 | [diff] [blame] | 674 | /* do the second part of the delay */ |
Mariusz Kozlowski | 4e8ad0d | 2009-02-16 21:31:28 +0100 | [diff] [blame] | 675 | /* no data */ |
Mariusz Kozlowski | 4e8ad0d | 2009-02-16 21:31:28 +0100 | [diff] [blame] | 676 | /* reset */ |
H Hartley Sweeten | 17fdeba | 2013-05-14 13:41:30 -0700 | [diff] [blame] | 677 | usbduxfast_cmd_data(dev, 5, steps_tmp - steps_tmp / 2, |
| 678 | 0x00, (0xff - 0x02) & rngmask, 0x00); |
Mariusz Kozlowski | 4e8ad0d | 2009-02-16 21:31:28 +0100 | [diff] [blame] | 679 | |
H Hartley Sweeten | 17fdeba | 2013-05-14 13:41:30 -0700 | [diff] [blame] | 680 | usbduxfast_cmd_data(dev, 6, 0x01, 0x00, rngmask, 0x00); |
Bernd Porr | 99284f2 | 2014-07-24 14:34:32 +0100 | [diff] [blame] | 681 | break; |
Bernd Porr | f47c697 | 2008-11-14 14:49:34 -0800 | [diff] [blame] | 682 | |
| 683 | case 16: |
| 684 | if (CR_RANGE(cmd->chanlist[0]) > 0) |
| 685 | rngmask = 0xff - 0x04; |
| 686 | else |
| 687 | rngmask = 0xff; |
Mariusz Kozlowski | 4e8ad0d | 2009-02-16 21:31:28 +0100 | [diff] [blame] | 688 | |
| 689 | if (cmd->start_src == TRIG_EXT) { |
| 690 | /* |
| 691 | * we loop here until ready has been set |
| 692 | */ |
| 693 | |
| 694 | /* branch back to state 0 */ |
Mariusz Kozlowski | 4e8ad0d | 2009-02-16 21:31:28 +0100 | [diff] [blame] | 695 | /* deceision state w/o data */ |
Mariusz Kozlowski | 4e8ad0d | 2009-02-16 21:31:28 +0100 | [diff] [blame] | 696 | /* reset */ |
Mariusz Kozlowski | 4e8ad0d | 2009-02-16 21:31:28 +0100 | [diff] [blame] | 697 | /* RDY0 = 0 */ |
H Hartley Sweeten | 17fdeba | 2013-05-14 13:41:30 -0700 | [diff] [blame] | 698 | usbduxfast_cmd_data(dev, 0, 0x01, 0x01, |
| 699 | (0xff - 0x02) & rngmask, 0x00); |
Mariusz Kozlowski | 4e8ad0d | 2009-02-16 21:31:28 +0100 | [diff] [blame] | 700 | } else { |
| 701 | /* |
| 702 | * we just proceed to state 1 |
| 703 | */ |
| 704 | |
| 705 | /* 30us reset pulse */ |
Mariusz Kozlowski | 4e8ad0d | 2009-02-16 21:31:28 +0100 | [diff] [blame] | 706 | /* reset */ |
H Hartley Sweeten | 17fdeba | 2013-05-14 13:41:30 -0700 | [diff] [blame] | 707 | usbduxfast_cmd_data(dev, 0, 0xff, 0x00, |
| 708 | (0xff - 0x02) & rngmask, 0x00); |
Bernd Porr | f47c697 | 2008-11-14 14:49:34 -0800 | [diff] [blame] | 709 | } |
| 710 | |
Mariusz Kozlowski | 4e8ad0d | 2009-02-16 21:31:28 +0100 | [diff] [blame] | 711 | /* commit data to the FIFO */ |
Mariusz Kozlowski | 4e8ad0d | 2009-02-16 21:31:28 +0100 | [diff] [blame] | 712 | /* data */ |
H Hartley Sweeten | 17fdeba | 2013-05-14 13:41:30 -0700 | [diff] [blame] | 713 | usbduxfast_cmd_data(dev, 1, 0x01, 0x02, rngmask, 0x00); |
Bernd Porr | f47c697 | 2008-11-14 14:49:34 -0800 | [diff] [blame] | 714 | |
Mariusz Kozlowski | 4e8ad0d | 2009-02-16 21:31:28 +0100 | [diff] [blame] | 715 | /* we have 2 states with duration 1 */ |
Bernd Porr | f47c697 | 2008-11-14 14:49:34 -0800 | [diff] [blame] | 716 | steps = steps - 2; |
| 717 | |
Mariusz Kozlowski | 4e8ad0d | 2009-02-16 21:31:28 +0100 | [diff] [blame] | 718 | /* do the first part of the delay */ |
H Hartley Sweeten | 17fdeba | 2013-05-14 13:41:30 -0700 | [diff] [blame] | 719 | usbduxfast_cmd_data(dev, 2, steps / 2, |
| 720 | 0x00, 0xfe & rngmask, 0x00); |
Bernd Porr | f47c697 | 2008-11-14 14:49:34 -0800 | [diff] [blame] | 721 | |
Mariusz Kozlowski | 4e8ad0d | 2009-02-16 21:31:28 +0100 | [diff] [blame] | 722 | /* and the second part */ |
H Hartley Sweeten | 17fdeba | 2013-05-14 13:41:30 -0700 | [diff] [blame] | 723 | usbduxfast_cmd_data(dev, 3, steps - steps / 2, |
| 724 | 0x00, rngmask, 0x00); |
Bernd Porr | f47c697 | 2008-11-14 14:49:34 -0800 | [diff] [blame] | 725 | |
Mariusz Kozlowski | 4e8ad0d | 2009-02-16 21:31:28 +0100 | [diff] [blame] | 726 | /* branch back to state 1 */ |
Mariusz Kozlowski | 4e8ad0d | 2009-02-16 21:31:28 +0100 | [diff] [blame] | 727 | /* deceision state w/o data */ |
Mariusz Kozlowski | 4e8ad0d | 2009-02-16 21:31:28 +0100 | [diff] [blame] | 728 | /* doesn't matter */ |
H Hartley Sweeten | 17fdeba | 2013-05-14 13:41:30 -0700 | [diff] [blame] | 729 | usbduxfast_cmd_data(dev, 4, 0x09, 0x01, rngmask, 0xff); |
Bernd Porr | f47c697 | 2008-11-14 14:49:34 -0800 | [diff] [blame] | 730 | |
| 731 | break; |
Bernd Porr | f47c697 | 2008-11-14 14:49:34 -0800 | [diff] [blame] | 732 | } |
| 733 | |
Mariusz Kozlowski | 4e8ad0d | 2009-02-16 21:31:28 +0100 | [diff] [blame] | 734 | /* 0 means that the AD commands are sent */ |
H Hartley Sweeten | 7b0fc5b | 2015-08-24 10:14:02 -0700 | [diff] [blame] | 735 | ret = usbduxfast_send_cmd(dev, SENDADCOMMANDS); |
| 736 | if (ret < 0) |
| 737 | goto cmd_exit; |
H Hartley Sweeten | 71cf2b4 | 2014-05-27 10:31:13 -0700 | [diff] [blame] | 738 | |
Bernd Porr | f47c697 | 2008-11-14 14:49:34 -0800 | [diff] [blame] | 739 | if ((cmd->start_src == TRIG_NOW) || (cmd->start_src == TRIG_EXT)) { |
Mariusz Kozlowski | 4e8ad0d | 2009-02-16 21:31:28 +0100 | [diff] [blame] | 740 | /* enable this acquisition operation */ |
H Hartley Sweeten | 7aa41c3 | 2013-05-14 13:27:37 -0700 | [diff] [blame] | 741 | devpriv->ai_cmd_running = 1; |
H Hartley Sweeten | ebe9f1c | 2013-05-14 13:41:07 -0700 | [diff] [blame] | 742 | ret = usbduxfast_submit_urb(dev); |
Bernd Porr | f47c697 | 2008-11-14 14:49:34 -0800 | [diff] [blame] | 743 | if (ret < 0) { |
H Hartley Sweeten | 7aa41c3 | 2013-05-14 13:27:37 -0700 | [diff] [blame] | 744 | devpriv->ai_cmd_running = 0; |
Mariusz Kozlowski | 4e8ad0d | 2009-02-16 21:31:28 +0100 | [diff] [blame] | 745 | /* fixme: unlink here?? */ |
H Hartley Sweeten | 7b0fc5b | 2015-08-24 10:14:02 -0700 | [diff] [blame] | 746 | goto cmd_exit; |
Bernd Porr | f47c697 | 2008-11-14 14:49:34 -0800 | [diff] [blame] | 747 | } |
| 748 | s->async->inttrig = NULL; |
H Hartley Sweeten | 9519459 | 2014-04-17 10:08:09 -0700 | [diff] [blame] | 749 | } else { /* TRIG_INT */ |
Bernd Porr | f47c697 | 2008-11-14 14:49:34 -0800 | [diff] [blame] | 750 | s->async->inttrig = usbduxfast_ai_inttrig; |
| 751 | } |
H Hartley Sweeten | 7b0fc5b | 2015-08-24 10:14:02 -0700 | [diff] [blame] | 752 | |
| 753 | cmd_exit: |
Ksenija Stanojevic | 27a9069 | 2015-10-02 22:07:54 +0200 | [diff] [blame] | 754 | mutex_unlock(&devpriv->mut); |
Bernd Porr | f47c697 | 2008-11-14 14:49:34 -0800 | [diff] [blame] | 755 | |
H Hartley Sweeten | 7b0fc5b | 2015-08-24 10:14:02 -0700 | [diff] [blame] | 756 | return ret; |
Bernd Porr | f47c697 | 2008-11-14 14:49:34 -0800 | [diff] [blame] | 757 | } |
| 758 | |
Mariusz Kozlowski | 4e8ad0d | 2009-02-16 21:31:28 +0100 | [diff] [blame] | 759 | /* |
| 760 | * Mode 0 is used to get a single conversion on demand. |
| 761 | */ |
Bill Pemberton | 71b5f4f | 2009-03-16 22:05:08 -0400 | [diff] [blame] | 762 | static int usbduxfast_ai_insn_read(struct comedi_device *dev, |
Mithlesh Thukral | 0a85b6f | 2009-06-08 21:04:41 +0530 | [diff] [blame] | 763 | struct comedi_subdevice *s, |
H Hartley Sweeten | dabf2aa | 2013-05-14 13:41:51 -0700 | [diff] [blame] | 764 | struct comedi_insn *insn, |
| 765 | unsigned int *data) |
Bernd Porr | f47c697 | 2008-11-14 14:49:34 -0800 | [diff] [blame] | 766 | { |
H Hartley Sweeten | 0a92de2 | 2013-05-20 14:20:30 -0700 | [diff] [blame] | 767 | struct usb_device *usb = comedi_to_usb_dev(dev); |
H Hartley Sweeten | 7aa41c3 | 2013-05-14 13:27:37 -0700 | [diff] [blame] | 768 | struct usbduxfast_private *devpriv = dev->private; |
H Hartley Sweeten | dabf2aa | 2013-05-14 13:41:51 -0700 | [diff] [blame] | 769 | unsigned int chan = CR_CHAN(insn->chanspec); |
| 770 | unsigned int range = CR_RANGE(insn->chanspec); |
H Hartley Sweeten | 2696154 | 2015-08-24 10:13:57 -0700 | [diff] [blame] | 771 | u8 rngmask = range ? (0xff - 0x04) : 0xff; |
Bernd Porr | f47c697 | 2008-11-14 14:49:34 -0800 | [diff] [blame] | 772 | int i, j, n, actual_length; |
H Hartley Sweeten | dabf2aa | 2013-05-14 13:41:51 -0700 | [diff] [blame] | 773 | int ret; |
H Hartley Sweeten | ba6205d | 2013-05-14 13:28:48 -0700 | [diff] [blame] | 774 | |
Ksenija Stanojevic | 27a9069 | 2015-10-02 22:07:54 +0200 | [diff] [blame] | 775 | mutex_lock(&devpriv->mut); |
H Hartley Sweeten | dabf2aa | 2013-05-14 13:41:51 -0700 | [diff] [blame] | 776 | |
H Hartley Sweeten | 7aa41c3 | 2013-05-14 13:27:37 -0700 | [diff] [blame] | 777 | if (devpriv->ai_cmd_running) { |
YAMANE Toshiaki | 0a00ab9 | 2012-10-24 15:14:46 +0900 | [diff] [blame] | 778 | dev_err(dev->class_dev, |
H Hartley Sweeten | 106af99 | 2013-05-14 13:34:31 -0700 | [diff] [blame] | 779 | "ai_insn_read not possible, async cmd is running\n"); |
Ksenija Stanojevic | 27a9069 | 2015-10-02 22:07:54 +0200 | [diff] [blame] | 780 | mutex_unlock(&devpriv->mut); |
Bernd Porr | f47c697 | 2008-11-14 14:49:34 -0800 | [diff] [blame] | 781 | return -EBUSY; |
| 782 | } |
Bernd Porr | f47c697 | 2008-11-14 14:49:34 -0800 | [diff] [blame] | 783 | |
H Hartley Sweeten | dabf2aa | 2013-05-14 13:41:51 -0700 | [diff] [blame] | 784 | /* set command for the first channel */ |
Bernd Porr | f47c697 | 2008-11-14 14:49:34 -0800 | [diff] [blame] | 785 | |
Mariusz Kozlowski | 4e8ad0d | 2009-02-16 21:31:28 +0100 | [diff] [blame] | 786 | /* commit data to the FIFO */ |
Mariusz Kozlowski | 4e8ad0d | 2009-02-16 21:31:28 +0100 | [diff] [blame] | 787 | /* data */ |
H Hartley Sweeten | 17fdeba | 2013-05-14 13:41:30 -0700 | [diff] [blame] | 788 | usbduxfast_cmd_data(dev, 0, 0x01, 0x02, rngmask, 0x00); |
Bernd Porr | f47c697 | 2008-11-14 14:49:34 -0800 | [diff] [blame] | 789 | |
Mariusz Kozlowski | 4e8ad0d | 2009-02-16 21:31:28 +0100 | [diff] [blame] | 790 | /* do the first part of the delay */ |
H Hartley Sweeten | 17fdeba | 2013-05-14 13:41:30 -0700 | [diff] [blame] | 791 | usbduxfast_cmd_data(dev, 1, 0x0c, 0x00, 0xfe & rngmask, 0x00); |
| 792 | usbduxfast_cmd_data(dev, 2, 0x01, 0x00, 0xfe & rngmask, 0x00); |
| 793 | usbduxfast_cmd_data(dev, 3, 0x01, 0x00, 0xfe & rngmask, 0x00); |
| 794 | usbduxfast_cmd_data(dev, 4, 0x01, 0x00, 0xfe & rngmask, 0x00); |
Bernd Porr | f47c697 | 2008-11-14 14:49:34 -0800 | [diff] [blame] | 795 | |
Mariusz Kozlowski | 4e8ad0d | 2009-02-16 21:31:28 +0100 | [diff] [blame] | 796 | /* second part */ |
H Hartley Sweeten | 17fdeba | 2013-05-14 13:41:30 -0700 | [diff] [blame] | 797 | usbduxfast_cmd_data(dev, 5, 0x0c, 0x00, rngmask, 0x00); |
| 798 | usbduxfast_cmd_data(dev, 6, 0x01, 0x00, rngmask, 0x00); |
Bernd Porr | f47c697 | 2008-11-14 14:49:34 -0800 | [diff] [blame] | 799 | |
H Hartley Sweeten | dabf2aa | 2013-05-14 13:41:51 -0700 | [diff] [blame] | 800 | ret = usbduxfast_send_cmd(dev, SENDADCOMMANDS); |
| 801 | if (ret < 0) { |
Ksenija Stanojevic | 27a9069 | 2015-10-02 22:07:54 +0200 | [diff] [blame] | 802 | mutex_unlock(&devpriv->mut); |
H Hartley Sweeten | dabf2aa | 2013-05-14 13:41:51 -0700 | [diff] [blame] | 803 | return ret; |
Bernd Porr | f47c697 | 2008-11-14 14:49:34 -0800 | [diff] [blame] | 804 | } |
H Hartley Sweeten | ba6205d | 2013-05-14 13:28:48 -0700 | [diff] [blame] | 805 | |
Bernd Porr | f47c697 | 2008-11-14 14:49:34 -0800 | [diff] [blame] | 806 | for (i = 0; i < PACKETS_TO_IGNORE; i++) { |
H Hartley Sweeten | dabf2aa | 2013-05-14 13:41:51 -0700 | [diff] [blame] | 807 | ret = usb_bulk_msg(usb, usb_rcvbulkpipe(usb, BULKINEP), |
H Hartley Sweeten | ef8e084 | 2013-05-14 13:36:23 -0700 | [diff] [blame] | 808 | devpriv->inbuf, SIZEINBUF, |
Greg Kroah-Hartman | 8867635 | 2008-11-18 17:09:23 -0800 | [diff] [blame] | 809 | &actual_length, 10000); |
H Hartley Sweeten | dabf2aa | 2013-05-14 13:41:51 -0700 | [diff] [blame] | 810 | if (ret < 0) { |
H Hartley Sweeten | 106af99 | 2013-05-14 13:34:31 -0700 | [diff] [blame] | 811 | dev_err(dev->class_dev, "insn timeout, no data\n"); |
Ksenija Stanojevic | 27a9069 | 2015-10-02 22:07:54 +0200 | [diff] [blame] | 812 | mutex_unlock(&devpriv->mut); |
H Hartley Sweeten | dabf2aa | 2013-05-14 13:41:51 -0700 | [diff] [blame] | 813 | return ret; |
Bernd Porr | f47c697 | 2008-11-14 14:49:34 -0800 | [diff] [blame] | 814 | } |
| 815 | } |
H Hartley Sweeten | dabf2aa | 2013-05-14 13:41:51 -0700 | [diff] [blame] | 816 | |
Bernd Porr | f47c697 | 2008-11-14 14:49:34 -0800 | [diff] [blame] | 817 | for (i = 0; i < insn->n;) { |
H Hartley Sweeten | dabf2aa | 2013-05-14 13:41:51 -0700 | [diff] [blame] | 818 | ret = usb_bulk_msg(usb, usb_rcvbulkpipe(usb, BULKINEP), |
H Hartley Sweeten | ef8e084 | 2013-05-14 13:36:23 -0700 | [diff] [blame] | 819 | devpriv->inbuf, SIZEINBUF, |
Greg Kroah-Hartman | 8867635 | 2008-11-18 17:09:23 -0800 | [diff] [blame] | 820 | &actual_length, 10000); |
H Hartley Sweeten | dabf2aa | 2013-05-14 13:41:51 -0700 | [diff] [blame] | 821 | if (ret < 0) { |
| 822 | dev_err(dev->class_dev, "insn data error: %d\n", ret); |
Ksenija Stanojevic | 27a9069 | 2015-10-02 22:07:54 +0200 | [diff] [blame] | 823 | mutex_unlock(&devpriv->mut); |
H Hartley Sweeten | dabf2aa | 2013-05-14 13:41:51 -0700 | [diff] [blame] | 824 | return ret; |
Bernd Porr | f47c697 | 2008-11-14 14:49:34 -0800 | [diff] [blame] | 825 | } |
H Hartley Sweeten | 2696154 | 2015-08-24 10:13:57 -0700 | [diff] [blame] | 826 | n = actual_length / sizeof(u16); |
Bernd Porr | f47c697 | 2008-11-14 14:49:34 -0800 | [diff] [blame] | 827 | if ((n % 16) != 0) { |
H Hartley Sweeten | 106af99 | 2013-05-14 13:34:31 -0700 | [diff] [blame] | 828 | dev_err(dev->class_dev, "insn data packet corrupted\n"); |
Ksenija Stanojevic | 27a9069 | 2015-10-02 22:07:54 +0200 | [diff] [blame] | 829 | mutex_unlock(&devpriv->mut); |
Bernd Porr | f47c697 | 2008-11-14 14:49:34 -0800 | [diff] [blame] | 830 | return -EINVAL; |
| 831 | } |
| 832 | for (j = chan; (j < n) && (i < insn->n); j = j + 16) { |
H Hartley Sweeten | 2696154 | 2015-08-24 10:13:57 -0700 | [diff] [blame] | 833 | data[i] = ((u16 *)(devpriv->inbuf))[j]; |
Bernd Porr | f47c697 | 2008-11-14 14:49:34 -0800 | [diff] [blame] | 834 | i++; |
| 835 | } |
| 836 | } |
H Hartley Sweeten | dabf2aa | 2013-05-14 13:41:51 -0700 | [diff] [blame] | 837 | |
Ksenija Stanojevic | 27a9069 | 2015-10-02 22:07:54 +0200 | [diff] [blame] | 838 | mutex_unlock(&devpriv->mut); |
H Hartley Sweeten | dabf2aa | 2013-05-14 13:41:51 -0700 | [diff] [blame] | 839 | |
| 840 | return insn->n; |
Bernd Porr | f47c697 | 2008-11-14 14:49:34 -0800 | [diff] [blame] | 841 | } |
| 842 | |
H Hartley Sweeten | 1b4997e | 2013-05-14 13:39:34 -0700 | [diff] [blame] | 843 | static int usbduxfast_upload_firmware(struct comedi_device *dev, |
H Hartley Sweeten | f9eb8a3 | 2013-05-20 14:28:29 -0700 | [diff] [blame] | 844 | const u8 *data, size_t size, |
| 845 | unsigned long context) |
Bernd Porr | f47c697 | 2008-11-14 14:49:34 -0800 | [diff] [blame] | 846 | { |
H Hartley Sweeten | 0a92de2 | 2013-05-20 14:20:30 -0700 | [diff] [blame] | 847 | struct usb_device *usb = comedi_to_usb_dev(dev); |
H Hartley Sweeten | 2696154 | 2015-08-24 10:13:57 -0700 | [diff] [blame] | 848 | u8 *buf; |
H Hartley Sweeten | fbe38a8b | 2013-05-14 13:40:24 -0700 | [diff] [blame] | 849 | unsigned char *tmp; |
H Hartley Sweeten | 106af99 | 2013-05-14 13:34:31 -0700 | [diff] [blame] | 850 | int ret; |
Bernd Porr | f47c697 | 2008-11-14 14:49:34 -0800 | [diff] [blame] | 851 | |
H Hartley Sweeten | f9eb8a3 | 2013-05-20 14:28:29 -0700 | [diff] [blame] | 852 | if (!data) |
Bernd Porr | 81874ff | 2009-04-17 21:21:46 +0100 | [diff] [blame] | 853 | return 0; |
| 854 | |
H Hartley Sweeten | f9eb8a3 | 2013-05-20 14:28:29 -0700 | [diff] [blame] | 855 | if (size > FIRMWARE_MAX_LEN) { |
H Hartley Sweeten | 106af99 | 2013-05-14 13:34:31 -0700 | [diff] [blame] | 856 | dev_err(dev->class_dev, "firmware binary too large for FX2\n"); |
Bernd Porr | f47c697 | 2008-11-14 14:49:34 -0800 | [diff] [blame] | 857 | return -ENOMEM; |
| 858 | } |
| 859 | |
Bernd Porr | 81874ff | 2009-04-17 21:21:46 +0100 | [diff] [blame] | 860 | /* we generate a local buffer for the firmware */ |
H Hartley Sweeten | f9eb8a3 | 2013-05-20 14:28:29 -0700 | [diff] [blame] | 861 | buf = kmemdup(data, size, GFP_KERNEL); |
H Hartley Sweeten | 1b4997e | 2013-05-14 13:39:34 -0700 | [diff] [blame] | 862 | if (!buf) |
Bernd Porr | 81874ff | 2009-04-17 21:21:46 +0100 | [diff] [blame] | 863 | return -ENOMEM; |
Bernd Porr | 81874ff | 2009-04-17 21:21:46 +0100 | [diff] [blame] | 864 | |
H Hartley Sweeten | fbe38a8b | 2013-05-14 13:40:24 -0700 | [diff] [blame] | 865 | /* we need a malloc'ed buffer for usb_control_msg() */ |
| 866 | tmp = kmalloc(1, GFP_KERNEL); |
| 867 | if (!tmp) { |
| 868 | kfree(buf); |
| 869 | return -ENOMEM; |
| 870 | } |
| 871 | |
| 872 | /* stop the current firmware on the device */ |
| 873 | *tmp = 1; /* 7f92 to one */ |
| 874 | ret = usb_control_msg(usb, usb_sndctrlpipe(usb, 0), |
| 875 | USBDUXFASTSUB_FIRMWARE, |
| 876 | VENDOR_DIR_OUT, |
| 877 | USBDUXFASTSUB_CPUCS, 0x0000, |
| 878 | tmp, 1, |
| 879 | EZTIMEOUT); |
Bernd Porr | 81874ff | 2009-04-17 21:21:46 +0100 | [diff] [blame] | 880 | if (ret < 0) { |
H Hartley Sweeten | 106af99 | 2013-05-14 13:34:31 -0700 | [diff] [blame] | 881 | dev_err(dev->class_dev, "can not stop firmware\n"); |
H Hartley Sweeten | 1b4997e | 2013-05-14 13:39:34 -0700 | [diff] [blame] | 882 | goto done; |
Bernd Porr | 81874ff | 2009-04-17 21:21:46 +0100 | [diff] [blame] | 883 | } |
| 884 | |
H Hartley Sweeten | fbe38a8b | 2013-05-14 13:40:24 -0700 | [diff] [blame] | 885 | /* upload the new firmware to the device */ |
| 886 | ret = usb_control_msg(usb, usb_sndctrlpipe(usb, 0), |
| 887 | USBDUXFASTSUB_FIRMWARE, |
| 888 | VENDOR_DIR_OUT, |
| 889 | 0, 0x0000, |
H Hartley Sweeten | f9eb8a3 | 2013-05-20 14:28:29 -0700 | [diff] [blame] | 890 | buf, size, |
H Hartley Sweeten | fbe38a8b | 2013-05-14 13:40:24 -0700 | [diff] [blame] | 891 | EZTIMEOUT); |
Bernd Porr | 81874ff | 2009-04-17 21:21:46 +0100 | [diff] [blame] | 892 | if (ret < 0) { |
H Hartley Sweeten | 106af99 | 2013-05-14 13:34:31 -0700 | [diff] [blame] | 893 | dev_err(dev->class_dev, "firmware upload failed\n"); |
H Hartley Sweeten | 1b4997e | 2013-05-14 13:39:34 -0700 | [diff] [blame] | 894 | goto done; |
Bernd Porr | 81874ff | 2009-04-17 21:21:46 +0100 | [diff] [blame] | 895 | } |
H Hartley Sweeten | fbe38a8b | 2013-05-14 13:40:24 -0700 | [diff] [blame] | 896 | |
| 897 | /* start the new firmware on the device */ |
| 898 | *tmp = 0; /* 7f92 to zero */ |
| 899 | ret = usb_control_msg(usb, usb_sndctrlpipe(usb, 0), |
| 900 | USBDUXFASTSUB_FIRMWARE, |
| 901 | VENDOR_DIR_OUT, |
| 902 | USBDUXFASTSUB_CPUCS, 0x0000, |
| 903 | tmp, 1, |
| 904 | EZTIMEOUT); |
H Hartley Sweeten | 1b4997e | 2013-05-14 13:39:34 -0700 | [diff] [blame] | 905 | if (ret < 0) |
H Hartley Sweeten | 106af99 | 2013-05-14 13:34:31 -0700 | [diff] [blame] | 906 | dev_err(dev->class_dev, "can not start firmware\n"); |
H Hartley Sweeten | 1b4997e | 2013-05-14 13:39:34 -0700 | [diff] [blame] | 907 | |
| 908 | done: |
H Hartley Sweeten | fbe38a8b | 2013-05-14 13:40:24 -0700 | [diff] [blame] | 909 | kfree(tmp); |
H Hartley Sweeten | 1b4997e | 2013-05-14 13:39:34 -0700 | [diff] [blame] | 910 | kfree(buf); |
| 911 | return ret; |
Bernd Porr | f47c697 | 2008-11-14 14:49:34 -0800 | [diff] [blame] | 912 | } |
| 913 | |
H Hartley Sweeten | 2d719c9 | 2013-05-14 13:30:09 -0700 | [diff] [blame] | 914 | static int usbduxfast_auto_attach(struct comedi_device *dev, |
| 915 | unsigned long context_unused) |
Bernd Porr | f47c697 | 2008-11-14 14:49:34 -0800 | [diff] [blame] | 916 | { |
H Hartley Sweeten | 2d719c9 | 2013-05-14 13:30:09 -0700 | [diff] [blame] | 917 | struct usb_interface *intf = comedi_to_usb_interface(dev); |
H Hartley Sweeten | 0a92de2 | 2013-05-20 14:20:30 -0700 | [diff] [blame] | 918 | struct usb_device *usb = comedi_to_usb_dev(dev); |
H Hartley Sweeten | 2d719c9 | 2013-05-14 13:30:09 -0700 | [diff] [blame] | 919 | struct usbduxfast_private *devpriv; |
H Hartley Sweeten | 42293db | 2015-08-24 10:14:05 -0700 | [diff] [blame] | 920 | struct comedi_subdevice *s; |
Bernd Porr | 6742c0a | 2008-12-08 23:30:13 +0000 | [diff] [blame] | 921 | int ret; |
Bernd Porr | f47c697 | 2008-11-14 14:49:34 -0800 | [diff] [blame] | 922 | |
H Hartley Sweeten | e4a8ecc | 2013-05-14 13:26:38 -0700 | [diff] [blame] | 923 | if (usb->speed != USB_SPEED_HIGH) { |
H Hartley Sweeten | 106af99 | 2013-05-14 13:34:31 -0700 | [diff] [blame] | 924 | dev_err(dev->class_dev, |
YAMANE Toshiaki | 0a00ab9 | 2012-10-24 15:14:46 +0900 | [diff] [blame] | 925 | "This driver needs USB 2.0 to operate. Aborting...\n"); |
Greg Kroah-Hartman | 8867635 | 2008-11-18 17:09:23 -0800 | [diff] [blame] | 926 | return -ENODEV; |
Bernd Porr | f47c697 | 2008-11-14 14:49:34 -0800 | [diff] [blame] | 927 | } |
H Hartley Sweeten | 64bf88bf | 2013-05-14 13:24:41 -0700 | [diff] [blame] | 928 | |
H Hartley Sweeten | 0bdab50 | 2013-06-24 16:55:44 -0700 | [diff] [blame] | 929 | devpriv = comedi_alloc_devpriv(dev, sizeof(*devpriv)); |
H Hartley Sweeten | 2d719c9 | 2013-05-14 13:30:09 -0700 | [diff] [blame] | 930 | if (!devpriv) |
| 931 | return -ENOMEM; |
Bernd Porr | f47c697 | 2008-11-14 14:49:34 -0800 | [diff] [blame] | 932 | |
Ksenija Stanojevic | 27a9069 | 2015-10-02 22:07:54 +0200 | [diff] [blame] | 933 | mutex_init(&devpriv->mut); |
H Hartley Sweeten | a35fd8a | 2013-05-14 13:25:56 -0700 | [diff] [blame] | 934 | usb_set_intfdata(intf, devpriv); |
Bernd Porr | f47c697 | 2008-11-14 14:49:34 -0800 | [diff] [blame] | 935 | |
H Hartley Sweeten | 5659e24 | 2013-05-14 13:36:47 -0700 | [diff] [blame] | 936 | devpriv->duxbuf = kmalloc(SIZEOFDUXBUF, GFP_KERNEL); |
| 937 | if (!devpriv->duxbuf) |
Greg Kroah-Hartman | 8867635 | 2008-11-18 17:09:23 -0800 | [diff] [blame] | 938 | return -ENOMEM; |
H Hartley Sweeten | ca88c09 | 2013-05-14 13:25:22 -0700 | [diff] [blame] | 939 | |
H Hartley Sweeten | a4f2e0f | 2013-05-14 13:35:15 -0700 | [diff] [blame] | 940 | ret = usb_set_interface(usb, |
H Hartley Sweeten | 01245e7 | 2013-05-14 13:32:53 -0700 | [diff] [blame] | 941 | intf->altsetting->desc.bInterfaceNumber, 1); |
H Hartley Sweeten | 2d719c9 | 2013-05-14 13:30:09 -0700 | [diff] [blame] | 942 | if (ret < 0) { |
H Hartley Sweeten | 106af99 | 2013-05-14 13:34:31 -0700 | [diff] [blame] | 943 | dev_err(dev->class_dev, |
H Hartley Sweeten | ca88c09 | 2013-05-14 13:25:22 -0700 | [diff] [blame] | 944 | "could not switch to alternate setting 1\n"); |
Greg Kroah-Hartman | 8867635 | 2008-11-18 17:09:23 -0800 | [diff] [blame] | 945 | return -ENODEV; |
Bernd Porr | f47c697 | 2008-11-14 14:49:34 -0800 | [diff] [blame] | 946 | } |
H Hartley Sweeten | ca88c09 | 2013-05-14 13:25:22 -0700 | [diff] [blame] | 947 | |
H Hartley Sweeten | da58c26 | 2013-05-14 13:35:40 -0700 | [diff] [blame] | 948 | devpriv->urb = usb_alloc_urb(0, GFP_KERNEL); |
| 949 | if (!devpriv->urb) { |
H Hartley Sweeten | 106af99 | 2013-05-14 13:34:31 -0700 | [diff] [blame] | 950 | dev_err(dev->class_dev, "Could not alloc. urb\n"); |
Greg Kroah-Hartman | 8867635 | 2008-11-18 17:09:23 -0800 | [diff] [blame] | 951 | return -ENOMEM; |
Bernd Porr | f47c697 | 2008-11-14 14:49:34 -0800 | [diff] [blame] | 952 | } |
H Hartley Sweeten | ca88c09 | 2013-05-14 13:25:22 -0700 | [diff] [blame] | 953 | |
H Hartley Sweeten | ef8e084 | 2013-05-14 13:36:23 -0700 | [diff] [blame] | 954 | devpriv->inbuf = kmalloc(SIZEINBUF, GFP_KERNEL); |
| 955 | if (!devpriv->inbuf) |
Greg Kroah-Hartman | 8867635 | 2008-11-18 17:09:23 -0800 | [diff] [blame] | 956 | return -ENOMEM; |
H Hartley Sweeten | ca88c09 | 2013-05-14 13:25:22 -0700 | [diff] [blame] | 957 | |
H Hartley Sweeten | f9eb8a3 | 2013-05-20 14:28:29 -0700 | [diff] [blame] | 958 | ret = comedi_load_firmware(dev, &usb->dev, FIRMWARE, |
| 959 | usbduxfast_upload_firmware, 0); |
| 960 | if (ret) |
Bernd Porr | 6742c0a | 2008-12-08 23:30:13 +0000 | [diff] [blame] | 961 | return ret; |
Bernd Porr | 6742c0a | 2008-12-08 23:30:13 +0000 | [diff] [blame] | 962 | |
H Hartley Sweeten | 42293db | 2015-08-24 10:14:05 -0700 | [diff] [blame] | 963 | ret = comedi_alloc_subdevices(dev, 1); |
| 964 | if (ret) |
| 965 | return ret; |
| 966 | |
| 967 | /* Analog Input subdevice */ |
| 968 | s = &dev->subdevices[0]; |
| 969 | dev->read_subdev = s; |
| 970 | s->type = COMEDI_SUBD_AI; |
| 971 | s->subdev_flags = SDF_READABLE | SDF_GROUND | SDF_CMD_READ; |
| 972 | s->n_chan = 16; |
| 973 | s->maxdata = 0x1000; /* 12-bit + 1 overflow bit */ |
| 974 | s->range_table = &range_usbduxfast_ai_range; |
| 975 | s->insn_read = usbduxfast_ai_insn_read; |
| 976 | s->len_chanlist = s->n_chan; |
| 977 | s->do_cmdtest = usbduxfast_ai_cmdtest; |
| 978 | s->do_cmd = usbduxfast_ai_cmd; |
| 979 | s->cancel = usbduxfast_ai_cancel; |
| 980 | |
| 981 | return 0; |
H Hartley Sweeten | 2d719c9 | 2013-05-14 13:30:09 -0700 | [diff] [blame] | 982 | } |
| 983 | |
| 984 | static void usbduxfast_detach(struct comedi_device *dev) |
| 985 | { |
H Hartley Sweeten | a71a65b | 2013-05-14 13:34:54 -0700 | [diff] [blame] | 986 | struct usb_interface *intf = comedi_to_usb_interface(dev); |
H Hartley Sweeten | 2d719c9 | 2013-05-14 13:30:09 -0700 | [diff] [blame] | 987 | struct usbduxfast_private *devpriv = dev->private; |
| 988 | |
H Hartley Sweeten | 38bf7ba | 2013-05-14 13:30:52 -0700 | [diff] [blame] | 989 | if (!devpriv) |
| 990 | return; |
| 991 | |
Ksenija Stanojevic | 27a9069 | 2015-10-02 22:07:54 +0200 | [diff] [blame] | 992 | mutex_lock(&devpriv->mut); |
H Hartley Sweeten | 38bf7ba | 2013-05-14 13:30:52 -0700 | [diff] [blame] | 993 | |
H Hartley Sweeten | a71a65b | 2013-05-14 13:34:54 -0700 | [diff] [blame] | 994 | usb_set_intfdata(intf, NULL); |
H Hartley Sweeten | 38bf7ba | 2013-05-14 13:30:52 -0700 | [diff] [blame] | 995 | |
H Hartley Sweeten | da58c26 | 2013-05-14 13:35:40 -0700 | [diff] [blame] | 996 | if (devpriv->urb) { |
H Hartley Sweeten | 38bf7ba | 2013-05-14 13:30:52 -0700 | [diff] [blame] | 997 | /* waits until a running transfer is over */ |
H Hartley Sweeten | da58c26 | 2013-05-14 13:35:40 -0700 | [diff] [blame] | 998 | usb_kill_urb(devpriv->urb); |
H Hartley Sweeten | 38bf7ba | 2013-05-14 13:30:52 -0700 | [diff] [blame] | 999 | |
H Hartley Sweeten | ef8e084 | 2013-05-14 13:36:23 -0700 | [diff] [blame] | 1000 | kfree(devpriv->inbuf); |
H Hartley Sweeten | da58c26 | 2013-05-14 13:35:40 -0700 | [diff] [blame] | 1001 | usb_free_urb(devpriv->urb); |
H Hartley Sweeten | 2d719c9 | 2013-05-14 13:30:09 -0700 | [diff] [blame] | 1002 | } |
H Hartley Sweeten | 38bf7ba | 2013-05-14 13:30:52 -0700 | [diff] [blame] | 1003 | |
H Hartley Sweeten | 5659e24 | 2013-05-14 13:36:47 -0700 | [diff] [blame] | 1004 | kfree(devpriv->duxbuf); |
H Hartley Sweeten | 38bf7ba | 2013-05-14 13:30:52 -0700 | [diff] [blame] | 1005 | |
Ksenija Stanojevic | 27a9069 | 2015-10-02 22:07:54 +0200 | [diff] [blame] | 1006 | mutex_unlock(&devpriv->mut); |
H Hartley Sweeten | 2d719c9 | 2013-05-14 13:30:09 -0700 | [diff] [blame] | 1007 | } |
| 1008 | |
| 1009 | static struct comedi_driver usbduxfast_driver = { |
| 1010 | .driver_name = "usbduxfast", |
| 1011 | .module = THIS_MODULE, |
| 1012 | .auto_attach = usbduxfast_auto_attach, |
| 1013 | .detach = usbduxfast_detach, |
| 1014 | }; |
| 1015 | |
| 1016 | static int usbduxfast_usb_probe(struct usb_interface *intf, |
| 1017 | const struct usb_device_id *id) |
| 1018 | { |
H Hartley Sweeten | a35fd8a | 2013-05-14 13:25:56 -0700 | [diff] [blame] | 1019 | return comedi_usb_auto_config(intf, &usbduxfast_driver, 0); |
Bernd Porr | f47c697 | 2008-11-14 14:49:34 -0800 | [diff] [blame] | 1020 | } |
| 1021 | |
H Hartley Sweeten | 4c8ba91 | 2012-06-20 12:02:28 -0700 | [diff] [blame] | 1022 | static const struct usb_device_id usbduxfast_usb_table[] = { |
Mariusz Kozlowski | 4e8ad0d | 2009-02-16 21:31:28 +0100 | [diff] [blame] | 1023 | /* { USB_DEVICE(0x4b4, 0x8613) }, testing */ |
H Hartley Sweeten | 4c8ba91 | 2012-06-20 12:02:28 -0700 | [diff] [blame] | 1024 | { USB_DEVICE(0x13d8, 0x0010) }, /* real ID */ |
| 1025 | { USB_DEVICE(0x13d8, 0x0011) }, /* real ID */ |
| 1026 | { } |
Bernd Porr | f47c697 | 2008-11-14 14:49:34 -0800 | [diff] [blame] | 1027 | }; |
H Hartley Sweeten | 4c8ba91 | 2012-06-20 12:02:28 -0700 | [diff] [blame] | 1028 | MODULE_DEVICE_TABLE(usb, usbduxfast_usb_table); |
Bernd Porr | f47c697 | 2008-11-14 14:49:34 -0800 | [diff] [blame] | 1029 | |
H Hartley Sweeten | cb9513a | 2012-06-20 12:01:14 -0700 | [diff] [blame] | 1030 | static struct usb_driver usbduxfast_usb_driver = { |
H Hartley Sweeten | 4c8ba91 | 2012-06-20 12:02:28 -0700 | [diff] [blame] | 1031 | .name = "usbduxfast", |
| 1032 | .probe = usbduxfast_usb_probe, |
H Hartley Sweeten | 0c4ab67 | 2013-05-14 13:29:35 -0700 | [diff] [blame] | 1033 | .disconnect = comedi_usb_auto_unconfig, |
H Hartley Sweeten | 4c8ba91 | 2012-06-20 12:02:28 -0700 | [diff] [blame] | 1034 | .id_table = usbduxfast_usb_table, |
Bernd Porr | f47c697 | 2008-11-14 14:49:34 -0800 | [diff] [blame] | 1035 | }; |
H Hartley Sweeten | cb9513a | 2012-06-20 12:01:14 -0700 | [diff] [blame] | 1036 | module_comedi_usb_driver(usbduxfast_driver, usbduxfast_usb_driver); |
Bernd Porr | f47c697 | 2008-11-14 14:49:34 -0800 | [diff] [blame] | 1037 | |
H Hartley Sweeten | 4c8ba91 | 2012-06-20 12:02:28 -0700 | [diff] [blame] | 1038 | MODULE_AUTHOR("Bernd Porr, BerndPorr@f2s.com"); |
| 1039 | MODULE_DESCRIPTION("USB-DUXfast, BerndPorr@f2s.com"); |
Bernd Porr | f47c697 | 2008-11-14 14:49:34 -0800 | [diff] [blame] | 1040 | MODULE_LICENSE("GPL"); |
Tim Gardner | e74f7fc | 2012-08-16 11:09:28 -0600 | [diff] [blame] | 1041 | MODULE_FIRMWARE(FIRMWARE); |