Commit da7b18ee authored by H Hartley Sweeten's avatar H Hartley Sweeten Committed by Greg Kroah-Hartman

staging: comedi: vmk80xx: consistently use the same local var names

Rename some of the local variables used in this driver to make the
code easier to maintain and understand.

s/udev/usb	the usb_device that the comedi_driver is attached to
s/dev/devpriv	the private data of the comedi_device
s/cdev/dev	the comedi_device

Also, use some local variables in a couple of the functions to tidy
up the code a bit.
Signed-off-by: default avatarH Hartley Sweeten <hsweeten@visionengravers.com>
Cc: Ian Abbott <abbotti@mev.co.uk>
Signed-off-by: default avatarGreg Kroah-Hartman <gregkh@linuxfoundation.org>
parent dc49cbfc
...@@ -196,7 +196,7 @@ static const struct vmk80xx_board vmk80xx_boardinfo[] = { ...@@ -196,7 +196,7 @@ static const struct vmk80xx_board vmk80xx_boardinfo[] = {
}; };
struct vmk80xx_private { struct vmk80xx_private {
struct usb_device *udev; struct usb_device *usb;
struct usb_interface *intf; struct usb_interface *intf;
struct usb_endpoint_descriptor *ep_rx; struct usb_endpoint_descriptor *ep_rx;
struct usb_endpoint_descriptor *ep_tx; struct usb_endpoint_descriptor *ep_tx;
...@@ -221,7 +221,8 @@ static DEFINE_MUTEX(glb_mutex); ...@@ -221,7 +221,8 @@ static DEFINE_MUTEX(glb_mutex);
static void vmk80xx_tx_callback(struct urb *urb) static void vmk80xx_tx_callback(struct urb *urb)
{ {
struct vmk80xx_private *dev = urb->context; struct vmk80xx_private *devpriv = urb->context;
unsigned long *flags = &devpriv->flags;
int stat = urb->status; int stat = urb->status;
if (stat && !(stat == -ENOENT if (stat && !(stat == -ENOENT
...@@ -229,17 +230,18 @@ static void vmk80xx_tx_callback(struct urb *urb) ...@@ -229,17 +230,18 @@ static void vmk80xx_tx_callback(struct urb *urb)
dbgcm("comedi#: vmk80xx: %s - nonzero urb status (%d)\n", dbgcm("comedi#: vmk80xx: %s - nonzero urb status (%d)\n",
__func__, stat); __func__, stat);
if (!test_bit(TRANS_OUT_BUSY, &dev->flags)) if (!test_bit(TRANS_OUT_BUSY, flags))
return; return;
clear_bit(TRANS_OUT_BUSY, &dev->flags); clear_bit(TRANS_OUT_BUSY, flags);
wake_up_interruptible(&dev->write_wait); wake_up_interruptible(&devpriv->write_wait);
} }
static void vmk80xx_rx_callback(struct urb *urb) static void vmk80xx_rx_callback(struct urb *urb)
{ {
struct vmk80xx_private *dev = urb->context; struct vmk80xx_private *devpriv = urb->context;
unsigned long *flags = &devpriv->flags;
int stat = urb->status; int stat = urb->status;
switch (stat) { switch (stat) {
...@@ -257,8 +259,8 @@ static void vmk80xx_rx_callback(struct urb *urb) ...@@ -257,8 +259,8 @@ static void vmk80xx_rx_callback(struct urb *urb)
goto exit; goto exit;
resubmit: resubmit:
if (test_bit(TRANS_IN_RUNNING, &dev->flags) && dev->intf) { if (test_bit(TRANS_IN_RUNNING, flags) && devpriv->intf) {
usb_anchor_urb(urb, &dev->rx_anchor); usb_anchor_urb(urb, &devpriv->rx_anchor);
if (!usb_submit_urb(urb, GFP_KERNEL)) if (!usb_submit_urb(urb, GFP_KERNEL))
goto exit; goto exit;
...@@ -270,20 +272,21 @@ static void vmk80xx_rx_callback(struct urb *urb) ...@@ -270,20 +272,21 @@ static void vmk80xx_rx_callback(struct urb *urb)
usb_unanchor_urb(urb); usb_unanchor_urb(urb);
} }
exit: exit:
clear_bit(TRANS_IN_BUSY, &dev->flags); clear_bit(TRANS_IN_BUSY, flags);
wake_up_interruptible(&dev->read_wait); wake_up_interruptible(&devpriv->read_wait);
} }
static int vmk80xx_check_data_link(struct vmk80xx_private *dev) static int vmk80xx_check_data_link(struct vmk80xx_private *devpriv)
{ {
struct usb_device *usb = devpriv->usb;
unsigned int tx_pipe; unsigned int tx_pipe;
unsigned int rx_pipe; unsigned int rx_pipe;
unsigned char tx[1]; unsigned char tx[1];
unsigned char rx[2]; unsigned char rx[2];
tx_pipe = usb_sndbulkpipe(dev->udev, 0x01); tx_pipe = usb_sndbulkpipe(usb, 0x01);
rx_pipe = usb_rcvbulkpipe(dev->udev, 0x81); rx_pipe = usb_rcvbulkpipe(usb, 0x81);
tx[0] = VMK8061_CMD_RD_PWR_STAT; tx[0] = VMK8061_CMD_RD_PWR_STAT;
...@@ -292,22 +295,23 @@ static int vmk80xx_check_data_link(struct vmk80xx_private *dev) ...@@ -292,22 +295,23 @@ static int vmk80xx_check_data_link(struct vmk80xx_private *dev)
* running and the data link between IC3 and * running and the data link between IC3 and
* IC6 is working properly * IC6 is working properly
*/ */
usb_bulk_msg(dev->udev, tx_pipe, tx, 1, NULL, dev->ep_tx->bInterval); usb_bulk_msg(usb, tx_pipe, tx, 1, NULL, devpriv->ep_tx->bInterval);
usb_bulk_msg(dev->udev, rx_pipe, rx, 2, NULL, HZ * 10); usb_bulk_msg(usb, rx_pipe, rx, 2, NULL, HZ * 10);
return (int)rx[1]; return (int)rx[1];
} }
static void vmk80xx_read_eeprom(struct vmk80xx_private *dev, int flag) static void vmk80xx_read_eeprom(struct vmk80xx_private *devpriv, int flag)
{ {
struct usb_device *usb = devpriv->usb;
unsigned int tx_pipe; unsigned int tx_pipe;
unsigned int rx_pipe; unsigned int rx_pipe;
unsigned char tx[1]; unsigned char tx[1];
unsigned char rx[64]; unsigned char rx[64];
int cnt; int cnt;
tx_pipe = usb_sndbulkpipe(dev->udev, 0x01); tx_pipe = usb_sndbulkpipe(usb, 0x01);
rx_pipe = usb_rcvbulkpipe(dev->udev, 0x81); rx_pipe = usb_rcvbulkpipe(usb, 0x81);
tx[0] = VMK8061_CMD_RD_VERSION; tx[0] = VMK8061_CMD_RD_VERSION;
...@@ -315,19 +319,21 @@ static void vmk80xx_read_eeprom(struct vmk80xx_private *dev, int flag) ...@@ -315,19 +319,21 @@ static void vmk80xx_read_eeprom(struct vmk80xx_private *dev, int flag)
* Read the firmware version info of IC3 and * Read the firmware version info of IC3 and
* IC6 from the internal EEPROM of the IC * IC6 from the internal EEPROM of the IC
*/ */
usb_bulk_msg(dev->udev, tx_pipe, tx, 1, NULL, dev->ep_tx->bInterval); usb_bulk_msg(usb, tx_pipe, tx, 1, NULL, devpriv->ep_tx->bInterval);
usb_bulk_msg(dev->udev, rx_pipe, rx, 64, &cnt, HZ * 10); usb_bulk_msg(usb, rx_pipe, rx, 64, &cnt, HZ * 10);
rx[cnt] = '\0'; rx[cnt] = '\0';
if (flag & IC3_VERSION) if (flag & IC3_VERSION)
strncpy(dev->fw.ic3_vers, rx + 1, 24); strncpy(devpriv->fw.ic3_vers, rx + 1, 24);
else /* IC6_VERSION */ else /* IC6_VERSION */
strncpy(dev->fw.ic6_vers, rx + 25, 24); strncpy(devpriv->fw.ic6_vers, rx + 25, 24);
} }
static int vmk80xx_reset_device(struct vmk80xx_private *dev) static int vmk80xx_reset_device(struct vmk80xx_private *devpriv)
{ {
struct usb_device *usb = devpriv->usb;
unsigned char *tx_buf = devpriv->usb_tx_buf;
struct urb *urb; struct urb *urb;
unsigned int tx_pipe; unsigned int tx_pipe;
int ival; int ival;
...@@ -337,31 +343,32 @@ static int vmk80xx_reset_device(struct vmk80xx_private *dev) ...@@ -337,31 +343,32 @@ static int vmk80xx_reset_device(struct vmk80xx_private *dev)
if (!urb) if (!urb)
return -ENOMEM; return -ENOMEM;
tx_pipe = usb_sndintpipe(dev->udev, 0x01); tx_pipe = usb_sndintpipe(usb, 0x01);
ival = dev->ep_tx->bInterval; ival = devpriv->ep_tx->bInterval;
size = le16_to_cpu(dev->ep_tx->wMaxPacketSize); size = le16_to_cpu(devpriv->ep_tx->wMaxPacketSize);
dev->usb_tx_buf[0] = VMK8055_CMD_RST; tx_buf[0] = VMK8055_CMD_RST;
dev->usb_tx_buf[1] = 0x00; tx_buf[1] = 0x00;
dev->usb_tx_buf[2] = 0x00; tx_buf[2] = 0x00;
dev->usb_tx_buf[3] = 0x00; tx_buf[3] = 0x00;
dev->usb_tx_buf[4] = 0x00; tx_buf[4] = 0x00;
dev->usb_tx_buf[5] = 0x00; tx_buf[5] = 0x00;
dev->usb_tx_buf[6] = 0x00; tx_buf[6] = 0x00;
dev->usb_tx_buf[7] = 0x00; tx_buf[7] = 0x00;
usb_fill_int_urb(urb, dev->udev, tx_pipe, dev->usb_tx_buf, usb_fill_int_urb(urb, usb, tx_pipe, tx_buf, size,
size, vmk80xx_tx_callback, dev, ival); vmk80xx_tx_callback, devpriv, ival);
usb_anchor_urb(urb, &dev->tx_anchor); usb_anchor_urb(urb, &devpriv->tx_anchor);
return usb_submit_urb(urb, GFP_KERNEL); return usb_submit_urb(urb, GFP_KERNEL);
} }
static void vmk80xx_build_int_urb(struct urb *urb, int flag) static void vmk80xx_build_int_urb(struct urb *urb, int flag)
{ {
struct vmk80xx_private *dev = urb->context; struct vmk80xx_private *devpriv = urb->context;
struct usb_device *usb = devpriv->usb;
__u8 rx_addr; __u8 rx_addr;
__u8 tx_addr; __u8 tx_addr;
unsigned int pipe; unsigned int pipe;
...@@ -371,72 +378,74 @@ static void vmk80xx_build_int_urb(struct urb *urb, int flag) ...@@ -371,72 +378,74 @@ static void vmk80xx_build_int_urb(struct urb *urb, int flag)
int ival; int ival;
if (flag & URB_RCV_FLAG) { if (flag & URB_RCV_FLAG) {
rx_addr = dev->ep_rx->bEndpointAddress; rx_addr = devpriv->ep_rx->bEndpointAddress;
pipe = usb_rcvintpipe(dev->udev, rx_addr); pipe = usb_rcvintpipe(usb, rx_addr);
buf = dev->usb_rx_buf; buf = devpriv->usb_rx_buf;
size = le16_to_cpu(dev->ep_rx->wMaxPacketSize); size = le16_to_cpu(devpriv->ep_rx->wMaxPacketSize);
callback = vmk80xx_rx_callback; callback = vmk80xx_rx_callback;
ival = dev->ep_rx->bInterval; ival = devpriv->ep_rx->bInterval;
} else { /* URB_SND_FLAG */ } else { /* URB_SND_FLAG */
tx_addr = dev->ep_tx->bEndpointAddress; tx_addr = devpriv->ep_tx->bEndpointAddress;
pipe = usb_sndintpipe(dev->udev, tx_addr); pipe = usb_sndintpipe(usb, tx_addr);
buf = dev->usb_tx_buf; buf = devpriv->usb_tx_buf;
size = le16_to_cpu(dev->ep_tx->wMaxPacketSize); size = le16_to_cpu(devpriv->ep_tx->wMaxPacketSize);
callback = vmk80xx_tx_callback; callback = vmk80xx_tx_callback;
ival = dev->ep_tx->bInterval; ival = devpriv->ep_tx->bInterval;
} }
usb_fill_int_urb(urb, dev->udev, pipe, buf, size, callback, dev, ival); usb_fill_int_urb(urb, usb, pipe, buf, size, callback, devpriv, ival);
} }
static void vmk80xx_do_bulk_msg(struct vmk80xx_private *dev) static void vmk80xx_do_bulk_msg(struct vmk80xx_private *devpriv)
{ {
struct usb_device *usb = devpriv->usb;
unsigned long *flags = &devpriv->flags;
__u8 tx_addr; __u8 tx_addr;
__u8 rx_addr; __u8 rx_addr;
unsigned int tx_pipe; unsigned int tx_pipe;
unsigned int rx_pipe; unsigned int rx_pipe;
size_t size; size_t size;
set_bit(TRANS_IN_BUSY, &dev->flags); set_bit(TRANS_IN_BUSY, flags);
set_bit(TRANS_OUT_BUSY, &dev->flags); set_bit(TRANS_OUT_BUSY, flags);
tx_addr = dev->ep_tx->bEndpointAddress; tx_addr = devpriv->ep_tx->bEndpointAddress;
rx_addr = dev->ep_rx->bEndpointAddress; rx_addr = devpriv->ep_rx->bEndpointAddress;
tx_pipe = usb_sndbulkpipe(dev->udev, tx_addr); tx_pipe = usb_sndbulkpipe(usb, tx_addr);
rx_pipe = usb_rcvbulkpipe(dev->udev, rx_addr); rx_pipe = usb_rcvbulkpipe(usb, rx_addr);
/* /*
* The max packet size attributes of the K8061 * The max packet size attributes of the K8061
* input/output endpoints are identical * input/output endpoints are identical
*/ */
size = le16_to_cpu(dev->ep_tx->wMaxPacketSize); size = le16_to_cpu(devpriv->ep_tx->wMaxPacketSize);
usb_bulk_msg(dev->udev, tx_pipe, dev->usb_tx_buf, usb_bulk_msg(usb, tx_pipe, devpriv->usb_tx_buf,
size, NULL, dev->ep_tx->bInterval); size, NULL, devpriv->ep_tx->bInterval);
usb_bulk_msg(dev->udev, rx_pipe, dev->usb_rx_buf, size, NULL, HZ * 10); usb_bulk_msg(usb, rx_pipe, devpriv->usb_rx_buf, size, NULL, HZ * 10);
clear_bit(TRANS_OUT_BUSY, &dev->flags); clear_bit(TRANS_OUT_BUSY, flags);
clear_bit(TRANS_IN_BUSY, &dev->flags); clear_bit(TRANS_IN_BUSY, flags);
} }
static int vmk80xx_read_packet(struct vmk80xx_private *dev) static int vmk80xx_read_packet(struct vmk80xx_private *devpriv)
{ {
const struct vmk80xx_board *boardinfo = dev->board; const struct vmk80xx_board *boardinfo = devpriv->board;
unsigned long *flags = &devpriv->flags;
struct urb *urb; struct urb *urb;
int retval; int retval;
if (!dev->intf) if (!devpriv->intf)
return -ENODEV; return -ENODEV;
/* Only useful for interrupt transfers */ /* Only useful for interrupt transfers */
if (test_bit(TRANS_IN_BUSY, &dev->flags)) if (test_bit(TRANS_IN_BUSY, flags))
if (wait_event_interruptible(dev->read_wait, if (wait_event_interruptible(devpriv->read_wait,
!test_bit(TRANS_IN_BUSY, !test_bit(TRANS_IN_BUSY, flags)))
&dev->flags)))
return -ERESTART; return -ERESTART;
if (boardinfo->model == VMK8061_MODEL) { if (boardinfo->model == VMK8061_MODEL) {
vmk80xx_do_bulk_msg(dev); vmk80xx_do_bulk_msg(devpriv);
return 0; return 0;
} }
...@@ -445,19 +454,19 @@ static int vmk80xx_read_packet(struct vmk80xx_private *dev) ...@@ -445,19 +454,19 @@ static int vmk80xx_read_packet(struct vmk80xx_private *dev)
if (!urb) if (!urb)
return -ENOMEM; return -ENOMEM;
urb->context = dev; urb->context = devpriv;
vmk80xx_build_int_urb(urb, URB_RCV_FLAG); vmk80xx_build_int_urb(urb, URB_RCV_FLAG);
set_bit(TRANS_IN_RUNNING, &dev->flags); set_bit(TRANS_IN_RUNNING, flags);
set_bit(TRANS_IN_BUSY, &dev->flags); set_bit(TRANS_IN_BUSY, flags);
usb_anchor_urb(urb, &dev->rx_anchor); usb_anchor_urb(urb, &devpriv->rx_anchor);
retval = usb_submit_urb(urb, GFP_KERNEL); retval = usb_submit_urb(urb, GFP_KERNEL);
if (!retval) if (!retval)
goto exit; goto exit;
clear_bit(TRANS_IN_RUNNING, &dev->flags); clear_bit(TRANS_IN_RUNNING, flags);
usb_unanchor_urb(urb); usb_unanchor_urb(urb);
exit: exit:
...@@ -466,24 +475,24 @@ static int vmk80xx_read_packet(struct vmk80xx_private *dev) ...@@ -466,24 +475,24 @@ static int vmk80xx_read_packet(struct vmk80xx_private *dev)
return retval; return retval;
} }
static int vmk80xx_write_packet(struct vmk80xx_private *dev, int cmd) static int vmk80xx_write_packet(struct vmk80xx_private *devpriv, int cmd)
{ {
const struct vmk80xx_board *boardinfo = dev->board; const struct vmk80xx_board *boardinfo = devpriv->board;
unsigned long *flags = &devpriv->flags;
struct urb *urb; struct urb *urb;
int retval; int retval;
if (!dev->intf) if (!devpriv->intf)
return -ENODEV; return -ENODEV;
if (test_bit(TRANS_OUT_BUSY, &dev->flags)) if (test_bit(TRANS_OUT_BUSY, flags))
if (wait_event_interruptible(dev->write_wait, if (wait_event_interruptible(devpriv->write_wait,
!test_bit(TRANS_OUT_BUSY, !test_bit(TRANS_OUT_BUSY, flags)))
&dev->flags)))
return -ERESTART; return -ERESTART;
if (boardinfo->model == VMK8061_MODEL) { if (boardinfo->model == VMK8061_MODEL) {
dev->usb_tx_buf[0] = cmd; devpriv->usb_tx_buf[0] = cmd;
vmk80xx_do_bulk_msg(dev); vmk80xx_do_bulk_msg(devpriv);
return 0; return 0;
} }
...@@ -492,20 +501,20 @@ static int vmk80xx_write_packet(struct vmk80xx_private *dev, int cmd) ...@@ -492,20 +501,20 @@ static int vmk80xx_write_packet(struct vmk80xx_private *dev, int cmd)
if (!urb) if (!urb)
return -ENOMEM; return -ENOMEM;
urb->context = dev; urb->context = devpriv;
vmk80xx_build_int_urb(urb, URB_SND_FLAG); vmk80xx_build_int_urb(urb, URB_SND_FLAG);
set_bit(TRANS_OUT_BUSY, &dev->flags); set_bit(TRANS_OUT_BUSY, flags);
usb_anchor_urb(urb, &dev->tx_anchor); usb_anchor_urb(urb, &devpriv->tx_anchor);
dev->usb_tx_buf[0] = cmd; devpriv->usb_tx_buf[0] = cmd;
retval = usb_submit_urb(urb, GFP_KERNEL); retval = usb_submit_urb(urb, GFP_KERNEL);
if (!retval) if (!retval)
goto exit; goto exit;
clear_bit(TRANS_OUT_BUSY, &dev->flags); clear_bit(TRANS_OUT_BUSY, flags);
usb_unanchor_urb(urb); usb_unanchor_urb(urb);
exit: exit:
...@@ -517,41 +526,41 @@ static int vmk80xx_write_packet(struct vmk80xx_private *dev, int cmd) ...@@ -517,41 +526,41 @@ static int vmk80xx_write_packet(struct vmk80xx_private *dev, int cmd)
#define DIR_IN 1 #define DIR_IN 1
#define DIR_OUT 2 #define DIR_OUT 2
static int rudimentary_check(struct vmk80xx_private *dev, int dir) static int rudimentary_check(struct vmk80xx_private *devpriv, int dir)
{ {
if (!dev) if (!devpriv)
return -EFAULT; return -EFAULT;
if (!dev->probed) if (!devpriv->probed)
return -ENODEV; return -ENODEV;
if (!dev->attached) if (!devpriv->attached)
return -ENODEV; return -ENODEV;
if (dir & DIR_IN) { if (dir & DIR_IN) {
if (test_bit(TRANS_IN_BUSY, &dev->flags)) if (test_bit(TRANS_IN_BUSY, &devpriv->flags))
return -EBUSY; return -EBUSY;
} }
if (dir & DIR_OUT) { if (dir & DIR_OUT) {
if (test_bit(TRANS_OUT_BUSY, &dev->flags)) if (test_bit(TRANS_OUT_BUSY, &devpriv->flags))
return -EBUSY; return -EBUSY;
} }
return 0; return 0;
} }
static int vmk80xx_ai_rinsn(struct comedi_device *cdev, static int vmk80xx_ai_rinsn(struct comedi_device *dev,
struct comedi_subdevice *s, struct comedi_subdevice *s,
struct comedi_insn *insn, unsigned int *data) struct comedi_insn *insn, unsigned int *data)
{ {
const struct vmk80xx_board *boardinfo = comedi_board(cdev); const struct vmk80xx_board *boardinfo = comedi_board(dev);
struct vmk80xx_private *dev = cdev->private; struct vmk80xx_private *devpriv = dev->private;
int chan; int chan;
int reg[2]; int reg[2];
int n; int n;
n = rudimentary_check(dev, DIR_IN); n = rudimentary_check(devpriv, DIR_IN);
if (n) if (n)
return n; return n;
down(&dev->limit_sem); down(&devpriv->limit_sem);
chan = CR_CHAN(insn->chanspec); chan = CR_CHAN(insn->chanspec);
switch (boardinfo->model) { switch (boardinfo->model) {
...@@ -565,46 +574,46 @@ static int vmk80xx_ai_rinsn(struct comedi_device *cdev, ...@@ -565,46 +574,46 @@ static int vmk80xx_ai_rinsn(struct comedi_device *cdev,
default: default:
reg[0] = VMK8061_AI_REG1; reg[0] = VMK8061_AI_REG1;
reg[1] = VMK8061_AI_REG2; reg[1] = VMK8061_AI_REG2;
dev->usb_tx_buf[0] = VMK8061_CMD_RD_AI; devpriv->usb_tx_buf[0] = VMK8061_CMD_RD_AI;
dev->usb_tx_buf[VMK8061_CH_REG] = chan; devpriv->usb_tx_buf[VMK8061_CH_REG] = chan;
break; break;
} }
for (n = 0; n < insn->n; n++) { for (n = 0; n < insn->n; n++) {
if (vmk80xx_read_packet(dev)) if (vmk80xx_read_packet(devpriv))
break; break;
if (boardinfo->model == VMK8055_MODEL) { if (boardinfo->model == VMK8055_MODEL) {
data[n] = dev->usb_rx_buf[reg[0]]; data[n] = devpriv->usb_rx_buf[reg[0]];
continue; continue;
} }
/* VMK8061_MODEL */ /* VMK8061_MODEL */
data[n] = dev->usb_rx_buf[reg[0]] + 256 * data[n] = devpriv->usb_rx_buf[reg[0]] + 256 *
dev->usb_rx_buf[reg[1]]; devpriv->usb_rx_buf[reg[1]];
} }
up(&dev->limit_sem); up(&devpriv->limit_sem);
return n; return n;
} }
static int vmk80xx_ao_winsn(struct comedi_device *cdev, static int vmk80xx_ao_winsn(struct comedi_device *dev,
struct comedi_subdevice *s, struct comedi_subdevice *s,
struct comedi_insn *insn, unsigned int *data) struct comedi_insn *insn, unsigned int *data)
{ {
const struct vmk80xx_board *boardinfo = comedi_board(cdev); const struct vmk80xx_board *boardinfo = comedi_board(dev);
struct vmk80xx_private *dev = cdev->private; struct vmk80xx_private *devpriv = dev->private;
int chan; int chan;
int cmd; int cmd;
int reg; int reg;
int n; int n;
n = rudimentary_check(dev, DIR_OUT); n = rudimentary_check(devpriv, DIR_OUT);
if (n) if (n)
return n; return n;
down(&dev->limit_sem); down(&devpriv->limit_sem);
chan = CR_CHAN(insn->chanspec); chan = CR_CHAN(insn->chanspec);
switch (boardinfo->model) { switch (boardinfo->model) {
...@@ -618,80 +627,80 @@ static int vmk80xx_ao_winsn(struct comedi_device *cdev, ...@@ -618,80 +627,80 @@ static int vmk80xx_ao_winsn(struct comedi_device *cdev,
default: /* NOTE: avoid compiler warnings */ default: /* NOTE: avoid compiler warnings */
cmd = VMK8061_CMD_SET_AO; cmd = VMK8061_CMD_SET_AO;
reg = VMK8061_AO_REG; reg = VMK8061_AO_REG;
dev->usb_tx_buf[VMK8061_CH_REG] = chan; devpriv->usb_tx_buf[VMK8061_CH_REG] = chan;
break; break;
} }
for (n = 0; n < insn->n; n++) { for (n = 0; n < insn->n; n++) {
dev->usb_tx_buf[reg] = data[n]; devpriv->usb_tx_buf[reg] = data[n];
if (vmk80xx_write_packet(dev, cmd)) if (vmk80xx_write_packet(devpriv, cmd))
break; break;
} }
up(&dev->limit_sem); up(&devpriv->limit_sem);
return n; return n;
} }
static int vmk80xx_ao_rinsn(struct comedi_device *cdev, static int vmk80xx_ao_rinsn(struct comedi_device *dev,
struct comedi_subdevice *s, struct comedi_subdevice *s,
struct comedi_insn *insn, unsigned int *data) struct comedi_insn *insn, unsigned int *data)
{ {
struct vmk80xx_private *dev = cdev->private; struct vmk80xx_private *devpriv = dev->private;
int chan; int chan;
int reg; int reg;
int n; int n;
n = rudimentary_check(dev, DIR_IN); n = rudimentary_check(devpriv, DIR_IN);
if (n) if (n)
return n; return n;
down(&dev->limit_sem); down(&devpriv->limit_sem);
chan = CR_CHAN(insn->chanspec); chan = CR_CHAN(insn->chanspec);
reg = VMK8061_AO_REG - 1; reg = VMK8061_AO_REG - 1;
dev->usb_tx_buf[0] = VMK8061_CMD_RD_AO; devpriv->usb_tx_buf[0] = VMK8061_CMD_RD_AO;
for (n = 0; n < insn->n; n++) { for (n = 0; n < insn->n; n++) {
if (vmk80xx_read_packet(dev)) if (vmk80xx_read_packet(devpriv))
break; break;
data[n] = dev->usb_rx_buf[reg + chan]; data[n] = devpriv->usb_rx_buf[reg + chan];
} }
up(&dev->limit_sem); up(&devpriv->limit_sem);
return n; return n;
} }
static int vmk80xx_di_bits(struct comedi_device *cdev, static int vmk80xx_di_bits(struct comedi_device *dev,
struct comedi_subdevice *s, struct comedi_subdevice *s,
struct comedi_insn *insn, unsigned int *data) struct comedi_insn *insn, unsigned int *data)
{ {
const struct vmk80xx_board *boardinfo = comedi_board(cdev); const struct vmk80xx_board *boardinfo = comedi_board(dev);
struct vmk80xx_private *dev = cdev->private; struct vmk80xx_private *devpriv = dev->private;
unsigned char *rx_buf; unsigned char *rx_buf;
int reg; int reg;
int retval; int retval;
retval = rudimentary_check(dev, DIR_IN); retval = rudimentary_check(devpriv, DIR_IN);
if (retval) if (retval)
return retval; return retval;
down(&dev->limit_sem); down(&devpriv->limit_sem);
rx_buf = dev->usb_rx_buf; rx_buf = devpriv->usb_rx_buf;
if (boardinfo->model == VMK8061_MODEL) { if (boardinfo->model == VMK8061_MODEL) {
reg = VMK8061_DI_REG; reg = VMK8061_DI_REG;
dev->usb_tx_buf[0] = VMK8061_CMD_RD_DI; devpriv->usb_tx_buf[0] = VMK8061_CMD_RD_DI;
} else { } else {
reg = VMK8055_DI_REG; reg = VMK8055_DI_REG;
} }
retval = vmk80xx_read_packet(dev); retval = vmk80xx_read_packet(devpriv);
if (!retval) { if (!retval) {
if (boardinfo->model == VMK8055_MODEL) if (boardinfo->model == VMK8055_MODEL)
...@@ -704,40 +713,40 @@ static int vmk80xx_di_bits(struct comedi_device *cdev, ...@@ -704,40 +713,40 @@ static int vmk80xx_di_bits(struct comedi_device *cdev,
retval = 2; retval = 2;
} }
up(&dev->limit_sem); up(&devpriv->limit_sem);
return retval; return retval;
} }
static int vmk80xx_di_rinsn(struct comedi_device *cdev, static int vmk80xx_di_rinsn(struct comedi_device *dev,
struct comedi_subdevice *s, struct comedi_subdevice *s,
struct comedi_insn *insn, unsigned int *data) struct comedi_insn *insn, unsigned int *data)
{ {
const struct vmk80xx_board *boardinfo = comedi_board(cdev); const struct vmk80xx_board *boardinfo = comedi_board(dev);
struct vmk80xx_private *dev = cdev->private; struct vmk80xx_private *devpriv = dev->private;
int chan; int chan;
unsigned char *rx_buf; unsigned char *rx_buf;
int reg; int reg;
int inp; int inp;
int n; int n;
n = rudimentary_check(dev, DIR_IN); n = rudimentary_check(devpriv, DIR_IN);
if (n) if (n)
return n; return n;
down(&dev->limit_sem); down(&devpriv->limit_sem);
chan = CR_CHAN(insn->chanspec); chan = CR_CHAN(insn->chanspec);
rx_buf = dev->usb_rx_buf; rx_buf = devpriv->usb_rx_buf;
if (boardinfo->model == VMK8061_MODEL) { if (boardinfo->model == VMK8061_MODEL) {
reg = VMK8061_DI_REG; reg = VMK8061_DI_REG;
dev->usb_tx_buf[0] = VMK8061_CMD_RD_DI; devpriv->usb_tx_buf[0] = VMK8061_CMD_RD_DI;
} else { } else {
reg = VMK8055_DI_REG; reg = VMK8055_DI_REG;
} }
for (n = 0; n < insn->n; n++) { for (n = 0; n < insn->n; n++) {
if (vmk80xx_read_packet(dev)) if (vmk80xx_read_packet(devpriv))
break; break;
if (boardinfo->model == VMK8055_MODEL) if (boardinfo->model == VMK8055_MODEL)
...@@ -750,31 +759,31 @@ static int vmk80xx_di_rinsn(struct comedi_device *cdev, ...@@ -750,31 +759,31 @@ static int vmk80xx_di_rinsn(struct comedi_device *cdev,
data[n] = (inp >> chan) & 1; data[n] = (inp >> chan) & 1;
} }
up(&dev->limit_sem); up(&devpriv->limit_sem);
return n; return n;
} }
static int vmk80xx_do_winsn(struct comedi_device *cdev, static int vmk80xx_do_winsn(struct comedi_device *dev,
struct comedi_subdevice *s, struct comedi_subdevice *s,
struct comedi_insn *insn, unsigned int *data) struct comedi_insn *insn, unsigned int *data)
{ {
const struct vmk80xx_board *boardinfo = comedi_board(cdev); const struct vmk80xx_board *boardinfo = comedi_board(dev);
struct vmk80xx_private *dev = cdev->private; struct vmk80xx_private *devpriv = dev->private;
int chan; int chan;
unsigned char *tx_buf; unsigned char *tx_buf;
int reg; int reg;
int cmd; int cmd;
int n; int n;
n = rudimentary_check(dev, DIR_OUT); n = rudimentary_check(devpriv, DIR_OUT);
if (n) if (n)
return n; return n;
down(&dev->limit_sem); down(&devpriv->limit_sem);
chan = CR_CHAN(insn->chanspec); chan = CR_CHAN(insn->chanspec);
tx_buf = dev->usb_tx_buf; tx_buf = devpriv->usb_tx_buf;
for (n = 0; n < insn->n; n++) { for (n = 0; n < insn->n; n++) {
if (boardinfo->model == VMK8055_MODEL) { if (boardinfo->model == VMK8055_MODEL) {
...@@ -795,53 +804,53 @@ static int vmk80xx_do_winsn(struct comedi_device *cdev, ...@@ -795,53 +804,53 @@ static int vmk80xx_do_winsn(struct comedi_device *cdev,
} }
} }
if (vmk80xx_write_packet(dev, cmd)) if (vmk80xx_write_packet(devpriv, cmd))
break; break;
} }
up(&dev->limit_sem); up(&devpriv->limit_sem);
return n; return n;
} }
static int vmk80xx_do_rinsn(struct comedi_device *cdev, static int vmk80xx_do_rinsn(struct comedi_device *dev,
struct comedi_subdevice *s, struct comedi_subdevice *s,
struct comedi_insn *insn, unsigned int *data) struct comedi_insn *insn, unsigned int *data)
{ {
struct vmk80xx_private *dev = cdev->private; struct vmk80xx_private *devpriv = dev->private;
int chan; int chan;
int reg; int reg;
int n; int n;
n = rudimentary_check(dev, DIR_IN); n = rudimentary_check(devpriv, DIR_IN);
if (n) if (n)
return n; return n;
down(&dev->limit_sem); down(&devpriv->limit_sem);
chan = CR_CHAN(insn->chanspec); chan = CR_CHAN(insn->chanspec);
reg = VMK8061_DO_REG; reg = VMK8061_DO_REG;
dev->usb_tx_buf[0] = VMK8061_CMD_RD_DO; devpriv->usb_tx_buf[0] = VMK8061_CMD_RD_DO;
for (n = 0; n < insn->n; n++) { for (n = 0; n < insn->n; n++) {
if (vmk80xx_read_packet(dev)) if (vmk80xx_read_packet(devpriv))
break; break;
data[n] = (dev->usb_rx_buf[reg] >> chan) & 1; data[n] = (devpriv->usb_rx_buf[reg] >> chan) & 1;
} }
up(&dev->limit_sem); up(&devpriv->limit_sem);
return n; return n;
} }
static int vmk80xx_do_bits(struct comedi_device *cdev, static int vmk80xx_do_bits(struct comedi_device *dev,
struct comedi_subdevice *s, struct comedi_subdevice *s,
struct comedi_insn *insn, unsigned int *data) struct comedi_insn *insn, unsigned int *data)
{ {
const struct vmk80xx_board *boardinfo = comedi_board(cdev); const struct vmk80xx_board *boardinfo = comedi_board(dev);
struct vmk80xx_private *dev = cdev->private; struct vmk80xx_private *devpriv = dev->private;
unsigned char *rx_buf, *tx_buf; unsigned char *rx_buf, *tx_buf;
int dir, reg, cmd; int dir, reg, cmd;
int retval; int retval;
...@@ -854,14 +863,14 @@ static int vmk80xx_do_bits(struct comedi_device *cdev, ...@@ -854,14 +863,14 @@ static int vmk80xx_do_bits(struct comedi_device *cdev,
if (boardinfo->model == VMK8061_MODEL) if (boardinfo->model == VMK8061_MODEL)
dir |= DIR_IN; dir |= DIR_IN;
retval = rudimentary_check(dev, dir); retval = rudimentary_check(devpriv, dir);
if (retval) if (retval)
return retval; return retval;
down(&dev->limit_sem); down(&devpriv->limit_sem);
rx_buf = dev->usb_rx_buf; rx_buf = devpriv->usb_rx_buf;
tx_buf = dev->usb_tx_buf; tx_buf = devpriv->usb_tx_buf;
if (data[0]) { if (data[0]) {
if (boardinfo->model == VMK8055_MODEL) { if (boardinfo->model == VMK8055_MODEL) {
...@@ -875,7 +884,7 @@ static int vmk80xx_do_bits(struct comedi_device *cdev, ...@@ -875,7 +884,7 @@ static int vmk80xx_do_bits(struct comedi_device *cdev,
tx_buf[reg] &= ~data[0]; tx_buf[reg] &= ~data[0];
tx_buf[reg] |= (data[0] & data[1]); tx_buf[reg] |= (data[0] & data[1]);
retval = vmk80xx_write_packet(dev, cmd); retval = vmk80xx_write_packet(devpriv, cmd);
if (retval) if (retval)
goto out; goto out;
...@@ -885,7 +894,7 @@ static int vmk80xx_do_bits(struct comedi_device *cdev, ...@@ -885,7 +894,7 @@ static int vmk80xx_do_bits(struct comedi_device *cdev,
reg = VMK8061_DO_REG; reg = VMK8061_DO_REG;
tx_buf[0] = VMK8061_CMD_RD_DO; tx_buf[0] = VMK8061_CMD_RD_DO;
retval = vmk80xx_read_packet(dev); retval = vmk80xx_read_packet(devpriv);
if (!retval) { if (!retval) {
data[1] = rx_buf[reg]; data[1] = rx_buf[reg];
...@@ -897,26 +906,26 @@ static int vmk80xx_do_bits(struct comedi_device *cdev, ...@@ -897,26 +906,26 @@ static int vmk80xx_do_bits(struct comedi_device *cdev,
} }
out: out:
up(&dev->limit_sem); up(&devpriv->limit_sem);
return retval; return retval;
} }
static int vmk80xx_cnt_rinsn(struct comedi_device *cdev, static int vmk80xx_cnt_rinsn(struct comedi_device *dev,
struct comedi_subdevice *s, struct comedi_subdevice *s,
struct comedi_insn *insn, unsigned int *data) struct comedi_insn *insn, unsigned int *data)
{ {
const struct vmk80xx_board *boardinfo = comedi_board(cdev); const struct vmk80xx_board *boardinfo = comedi_board(dev);
struct vmk80xx_private *dev = cdev->private; struct vmk80xx_private *devpriv = dev->private;
int chan; int chan;
int reg[2]; int reg[2];
int n; int n;
n = rudimentary_check(dev, DIR_IN); n = rudimentary_check(devpriv, DIR_IN);
if (n) if (n)
return n; return n;
down(&dev->limit_sem); down(&devpriv->limit_sem);
chan = CR_CHAN(insn->chanspec); chan = CR_CHAN(insn->chanspec);
switch (boardinfo->model) { switch (boardinfo->model) {
...@@ -930,39 +939,39 @@ static int vmk80xx_cnt_rinsn(struct comedi_device *cdev, ...@@ -930,39 +939,39 @@ static int vmk80xx_cnt_rinsn(struct comedi_device *cdev,
default: default:
reg[0] = VMK8061_CNT_REG; reg[0] = VMK8061_CNT_REG;
reg[1] = VMK8061_CNT_REG; reg[1] = VMK8061_CNT_REG;
dev->usb_tx_buf[0] = VMK8061_CMD_RD_CNT; devpriv->usb_tx_buf[0] = VMK8061_CMD_RD_CNT;
break; break;
} }
for (n = 0; n < insn->n; n++) { for (n = 0; n < insn->n; n++) {
if (vmk80xx_read_packet(dev)) if (vmk80xx_read_packet(devpriv))
break; break;
if (boardinfo->model == VMK8055_MODEL) if (boardinfo->model == VMK8055_MODEL)
data[n] = dev->usb_rx_buf[reg[0]]; data[n] = devpriv->usb_rx_buf[reg[0]];
else /* VMK8061_MODEL */ else /* VMK8061_MODEL */
data[n] = dev->usb_rx_buf[reg[0] * (chan + 1) + 1] data[n] = devpriv->usb_rx_buf[reg[0] * (chan + 1) + 1]
+ 256 * dev->usb_rx_buf[reg[1] * 2 + 2]; + 256 * devpriv->usb_rx_buf[reg[1] * 2 + 2];
} }
up(&dev->limit_sem); up(&devpriv->limit_sem);
return n; return n;
} }
static int vmk80xx_cnt_cinsn(struct comedi_device *cdev, static int vmk80xx_cnt_cinsn(struct comedi_device *dev,
struct comedi_subdevice *s, struct comedi_subdevice *s,
struct comedi_insn *insn, unsigned int *data) struct comedi_insn *insn, unsigned int *data)
{ {
const struct vmk80xx_board *boardinfo = comedi_board(cdev); const struct vmk80xx_board *boardinfo = comedi_board(dev);
struct vmk80xx_private *dev = cdev->private; struct vmk80xx_private *devpriv = dev->private;
unsigned int insn_cmd; unsigned int insn_cmd;
int chan; int chan;
int cmd; int cmd;
int reg; int reg;
int n; int n;
n = rudimentary_check(dev, DIR_OUT); n = rudimentary_check(devpriv, DIR_OUT);
if (n) if (n)
return n; return n;
...@@ -970,7 +979,7 @@ static int vmk80xx_cnt_cinsn(struct comedi_device *cdev, ...@@ -970,7 +979,7 @@ static int vmk80xx_cnt_cinsn(struct comedi_device *cdev,
if (insn_cmd != INSN_CONFIG_RESET && insn_cmd != GPCT_RESET) if (insn_cmd != INSN_CONFIG_RESET && insn_cmd != GPCT_RESET)
return -EINVAL; return -EINVAL;
down(&dev->limit_sem); down(&devpriv->limit_sem);
chan = CR_CHAN(insn->chanspec); chan = CR_CHAN(insn->chanspec);
...@@ -983,36 +992,36 @@ static int vmk80xx_cnt_cinsn(struct comedi_device *cdev, ...@@ -983,36 +992,36 @@ static int vmk80xx_cnt_cinsn(struct comedi_device *cdev,
reg = VMK8055_CNT2_REG; reg = VMK8055_CNT2_REG;
} }
dev->usb_tx_buf[reg] = 0x00; devpriv->usb_tx_buf[reg] = 0x00;
} else { } else {
cmd = VMK8061_CMD_RST_CNT; cmd = VMK8061_CMD_RST_CNT;
} }
for (n = 0; n < insn->n; n++) for (n = 0; n < insn->n; n++)
if (vmk80xx_write_packet(dev, cmd)) if (vmk80xx_write_packet(devpriv, cmd))
break; break;
up(&dev->limit_sem); up(&devpriv->limit_sem);
return n; return n;
} }
static int vmk80xx_cnt_winsn(struct comedi_device *cdev, static int vmk80xx_cnt_winsn(struct comedi_device *dev,
struct comedi_subdevice *s, struct comedi_subdevice *s,
struct comedi_insn *insn, unsigned int *data) struct comedi_insn *insn, unsigned int *data)
{ {
struct vmk80xx_private *dev = cdev->private; struct vmk80xx_private *devpriv = dev->private;
unsigned long debtime; unsigned long debtime;
unsigned long val; unsigned long val;
int chan; int chan;
int cmd; int cmd;
int n; int n;
n = rudimentary_check(dev, DIR_OUT); n = rudimentary_check(devpriv, DIR_OUT);
if (n) if (n)
return n; return n;
down(&dev->limit_sem); down(&devpriv->limit_sem);
chan = CR_CHAN(insn->chanspec); chan = CR_CHAN(insn->chanspec);
if (!chan) if (!chan)
...@@ -1033,65 +1042,70 @@ static int vmk80xx_cnt_winsn(struct comedi_device *cdev, ...@@ -1033,65 +1042,70 @@ static int vmk80xx_cnt_winsn(struct comedi_device *cdev,
if (((val + 1) * val) < debtime * 1000 / 115) if (((val + 1) * val) < debtime * 1000 / 115)
val += 1; val += 1;
dev->usb_tx_buf[6 + chan] = val; devpriv->usb_tx_buf[6 + chan] = val;
if (vmk80xx_write_packet(dev, cmd)) if (vmk80xx_write_packet(devpriv, cmd))
break; break;
} }
up(&dev->limit_sem); up(&devpriv->limit_sem);
return n; return n;
} }
static int vmk80xx_pwm_rinsn(struct comedi_device *cdev, static int vmk80xx_pwm_rinsn(struct comedi_device *dev,
struct comedi_subdevice *s, struct comedi_subdevice *s,
struct comedi_insn *insn, unsigned int *data) struct comedi_insn *insn, unsigned int *data)
{ {
struct vmk80xx_private *dev = cdev->private; struct vmk80xx_private *devpriv = dev->private;
unsigned char *tx_buf;
unsigned char *rx_buf;
int reg[2]; int reg[2];
int n; int n;
n = rudimentary_check(dev, DIR_IN); n = rudimentary_check(devpriv, DIR_IN);
if (n) if (n)
return n; return n;
down(&dev->limit_sem); down(&devpriv->limit_sem);
tx_buf = devpriv->usb_tx_buf;
rx_buf = devpriv->usb_rx_buf;
reg[0] = VMK8061_PWM_REG1; reg[0] = VMK8061_PWM_REG1;
reg[1] = VMK8061_PWM_REG2; reg[1] = VMK8061_PWM_REG2;
dev->usb_tx_buf[0] = VMK8061_CMD_RD_PWM; tx_buf[0] = VMK8061_CMD_RD_PWM;
for (n = 0; n < insn->n; n++) { for (n = 0; n < insn->n; n++) {
if (vmk80xx_read_packet(dev)) if (vmk80xx_read_packet(devpriv))
break; break;
data[n] = dev->usb_rx_buf[reg[0]] + 4 * dev->usb_rx_buf[reg[1]]; data[n] = rx_buf[reg[0]] + 4 * rx_buf[reg[1]];
} }
up(&dev->limit_sem); up(&devpriv->limit_sem);
return n; return n;
} }
static int vmk80xx_pwm_winsn(struct comedi_device *cdev, static int vmk80xx_pwm_winsn(struct comedi_device *dev,
struct comedi_subdevice *s, struct comedi_subdevice *s,
struct comedi_insn *insn, unsigned int *data) struct comedi_insn *insn, unsigned int *data)
{ {
struct vmk80xx_private *dev = cdev->private; struct vmk80xx_private *devpriv = dev->private;
unsigned char *tx_buf; unsigned char *tx_buf;
int reg[2]; int reg[2];
int cmd; int cmd;
int n; int n;
n = rudimentary_check(dev, DIR_OUT); n = rudimentary_check(devpriv, DIR_OUT);
if (n) if (n)
return n; return n;
down(&dev->limit_sem); down(&devpriv->limit_sem);
tx_buf = dev->usb_tx_buf; tx_buf = devpriv->usb_tx_buf;
reg[0] = VMK8061_PWM_REG1; reg[0] = VMK8061_PWM_REG1;
reg[1] = VMK8061_PWM_REG2; reg[1] = VMK8061_PWM_REG2;
...@@ -1115,42 +1129,42 @@ static int vmk80xx_pwm_winsn(struct comedi_device *cdev, ...@@ -1115,42 +1129,42 @@ static int vmk80xx_pwm_winsn(struct comedi_device *cdev,
tx_buf[reg[0]] = (unsigned char)(data[n] & 0x03); tx_buf[reg[0]] = (unsigned char)(data[n] & 0x03);
tx_buf[reg[1]] = (unsigned char)(data[n] >> 2) & 0xff; tx_buf[reg[1]] = (unsigned char)(data[n] >> 2) & 0xff;
if (vmk80xx_write_packet(dev, cmd)) if (vmk80xx_write_packet(devpriv, cmd))
break; break;
} }
up(&dev->limit_sem); up(&devpriv->limit_sem);
return n; return n;
} }
static int vmk80xx_attach_common(struct comedi_device *cdev, static int vmk80xx_attach_common(struct comedi_device *dev,
struct vmk80xx_private *dev) struct vmk80xx_private *devpriv)
{ {
const struct vmk80xx_board *boardinfo; const struct vmk80xx_board *boardinfo;
int n_subd; int n_subd;
struct comedi_subdevice *s; struct comedi_subdevice *s;
int ret; int ret;
down(&dev->limit_sem); down(&devpriv->limit_sem);
boardinfo = dev->board; boardinfo = devpriv->board;
cdev->board_ptr = boardinfo; dev->board_ptr = boardinfo;
cdev->board_name = boardinfo->name; dev->board_name = boardinfo->name;
cdev->private = dev; dev->private = devpriv;
if (boardinfo->model == VMK8055_MODEL) if (boardinfo->model == VMK8055_MODEL)
n_subd = 5; n_subd = 5;
else else
n_subd = 6; n_subd = 6;
ret = comedi_alloc_subdevices(cdev, n_subd); ret = comedi_alloc_subdevices(dev, n_subd);
if (ret) { if (ret) {
up(&dev->limit_sem); up(&devpriv->limit_sem);
return ret; return ret;
} }
/* Analog input subdevice */ /* Analog input subdevice */
s = &cdev->subdevices[0]; s = &dev->subdevices[0];
s->type = COMEDI_SUBD_AI; s->type = COMEDI_SUBD_AI;
s->subdev_flags = SDF_READABLE | SDF_GROUND; s->subdev_flags = SDF_READABLE | SDF_GROUND;
s->n_chan = boardinfo->ai_chans; s->n_chan = boardinfo->ai_chans;
...@@ -1159,7 +1173,7 @@ static int vmk80xx_attach_common(struct comedi_device *cdev, ...@@ -1159,7 +1173,7 @@ static int vmk80xx_attach_common(struct comedi_device *cdev,
s->insn_read = vmk80xx_ai_rinsn; s->insn_read = vmk80xx_ai_rinsn;
/* Analog output subdevice */ /* Analog output subdevice */
s = &cdev->subdevices[1]; s = &dev->subdevices[1];
s->type = COMEDI_SUBD_AO; s->type = COMEDI_SUBD_AO;
s->subdev_flags = SDF_WRITEABLE | SDF_GROUND; s->subdev_flags = SDF_WRITEABLE | SDF_GROUND;
s->n_chan = boardinfo->ao_chans; s->n_chan = boardinfo->ao_chans;
...@@ -1172,7 +1186,7 @@ static int vmk80xx_attach_common(struct comedi_device *cdev, ...@@ -1172,7 +1186,7 @@ static int vmk80xx_attach_common(struct comedi_device *cdev,
} }
/* Digital input subdevice */ /* Digital input subdevice */
s = &cdev->subdevices[2]; s = &dev->subdevices[2];
s->type = COMEDI_SUBD_DI; s->type = COMEDI_SUBD_DI;
s->subdev_flags = SDF_READABLE | SDF_GROUND; s->subdev_flags = SDF_READABLE | SDF_GROUND;
s->n_chan = boardinfo->di_chans; s->n_chan = boardinfo->di_chans;
...@@ -1181,7 +1195,7 @@ static int vmk80xx_attach_common(struct comedi_device *cdev, ...@@ -1181,7 +1195,7 @@ static int vmk80xx_attach_common(struct comedi_device *cdev,
s->insn_bits = vmk80xx_di_bits; s->insn_bits = vmk80xx_di_bits;
/* Digital output subdevice */ /* Digital output subdevice */
s = &cdev->subdevices[3]; s = &dev->subdevices[3];
s->type = COMEDI_SUBD_DO; s->type = COMEDI_SUBD_DO;
s->subdev_flags = SDF_WRITEABLE | SDF_GROUND; s->subdev_flags = SDF_WRITEABLE | SDF_GROUND;
s->n_chan = 8; s->n_chan = 8;
...@@ -1194,7 +1208,7 @@ static int vmk80xx_attach_common(struct comedi_device *cdev, ...@@ -1194,7 +1208,7 @@ static int vmk80xx_attach_common(struct comedi_device *cdev,
} }
/* Counter subdevice */ /* Counter subdevice */
s = &cdev->subdevices[4]; s = &dev->subdevices[4];
s->type = COMEDI_SUBD_COUNTER; s->type = COMEDI_SUBD_COUNTER;
s->subdev_flags = SDF_READABLE; s->subdev_flags = SDF_READABLE;
s->n_chan = 2; s->n_chan = 2;
...@@ -1208,7 +1222,7 @@ static int vmk80xx_attach_common(struct comedi_device *cdev, ...@@ -1208,7 +1222,7 @@ static int vmk80xx_attach_common(struct comedi_device *cdev,
/* PWM subdevice */ /* PWM subdevice */
if (boardinfo->model == VMK8061_MODEL) { if (boardinfo->model == VMK8061_MODEL) {
s = &cdev->subdevices[5]; s = &dev->subdevices[5];
s->type = COMEDI_SUBD_PWM; s->type = COMEDI_SUBD_PWM;
s->subdev_flags = SDF_READABLE | SDF_WRITEABLE; s->subdev_flags = SDF_READABLE | SDF_WRITEABLE;
s->n_chan = boardinfo->pwm_chans; s->n_chan = boardinfo->pwm_chans;
...@@ -1217,19 +1231,19 @@ static int vmk80xx_attach_common(struct comedi_device *cdev, ...@@ -1217,19 +1231,19 @@ static int vmk80xx_attach_common(struct comedi_device *cdev,
s->insn_write = vmk80xx_pwm_winsn; s->insn_write = vmk80xx_pwm_winsn;
} }
dev->attached = 1; devpriv->attached = 1;
dev_info(cdev->class_dev, "vmk80xx: board #%d [%s] attached\n", dev_info(dev->class_dev, "vmk80xx: board #%d [%s] attached\n",
dev->count, boardinfo->name); devpriv->count, boardinfo->name);
up(&dev->limit_sem); up(&devpriv->limit_sem);
return 0; return 0;
} }
static int vmk80xx_auto_attach(struct comedi_device *cdev, static int vmk80xx_auto_attach(struct comedi_device *dev,
unsigned long context_unused) unsigned long context_unused)
{ {
struct usb_interface *intf = comedi_to_usb_interface(cdev); struct usb_interface *intf = comedi_to_usb_interface(dev);
int i; int i;
int ret; int ret;
...@@ -1242,34 +1256,34 @@ static int vmk80xx_auto_attach(struct comedi_device *cdev, ...@@ -1242,34 +1256,34 @@ static int vmk80xx_auto_attach(struct comedi_device *cdev,
else if (vmb[i].attached) else if (vmb[i].attached)
ret = -EBUSY; ret = -EBUSY;
else else
ret = vmk80xx_attach_common(cdev, &vmb[i]); ret = vmk80xx_attach_common(dev, &vmb[i]);
mutex_unlock(&glb_mutex); mutex_unlock(&glb_mutex);
return ret; return ret;
} }
static void vmk80xx_detach(struct comedi_device *dev) static void vmk80xx_detach(struct comedi_device *dev)
{ {
struct vmk80xx_private *usb = dev->private; struct vmk80xx_private *devpriv = dev->private;
if (!usb) if (!devpriv)
return; return;
mutex_lock(&glb_mutex); mutex_lock(&glb_mutex);
down(&usb->limit_sem); down(&devpriv->limit_sem);
dev->private = NULL; dev->private = NULL;
usb->attached = 0; devpriv->attached = 0;
usb->probed = 0; devpriv->probed = 0;
usb_set_intfdata(usb->intf, NULL); usb_set_intfdata(devpriv->intf, NULL);
usb_kill_anchored_urbs(&usb->rx_anchor); usb_kill_anchored_urbs(&devpriv->rx_anchor);
usb_kill_anchored_urbs(&usb->tx_anchor); usb_kill_anchored_urbs(&devpriv->tx_anchor);
kfree(usb->usb_rx_buf); kfree(devpriv->usb_rx_buf);
kfree(usb->usb_tx_buf); kfree(devpriv->usb_tx_buf);
up(&usb->limit_sem); up(&devpriv->limit_sem);
mutex_unlock(&glb_mutex); mutex_unlock(&glb_mutex);
} }
...@@ -1284,11 +1298,11 @@ static int vmk80xx_usb_probe(struct usb_interface *intf, ...@@ -1284,11 +1298,11 @@ static int vmk80xx_usb_probe(struct usb_interface *intf,
const struct usb_device_id *id) const struct usb_device_id *id)
{ {
const struct vmk80xx_board *boardinfo; const struct vmk80xx_board *boardinfo;
int i; struct vmk80xx_private *devpriv;
struct vmk80xx_private *dev;
struct usb_host_interface *iface_desc; struct usb_host_interface *iface_desc;
struct usb_endpoint_descriptor *ep_desc; struct usb_endpoint_descriptor *ep_desc;
size_t size; size_t size;
int i;
mutex_lock(&glb_mutex); mutex_lock(&glb_mutex);
...@@ -1301,10 +1315,10 @@ static int vmk80xx_usb_probe(struct usb_interface *intf, ...@@ -1301,10 +1315,10 @@ static int vmk80xx_usb_probe(struct usb_interface *intf,
return -EMFILE; return -EMFILE;
} }
dev = &vmb[i]; devpriv = &vmb[i];
memset(dev, 0x00, sizeof(*dev)); memset(devpriv, 0x00, sizeof(*devpriv));
dev->count = i; devpriv->count = i;
iface_desc = intf->cur_altsetting; iface_desc = intf->cur_altsetting;
if (iface_desc->desc.bNumEndpoints != 2) if (iface_desc->desc.bNumEndpoints != 2)
...@@ -1314,78 +1328,78 @@ static int vmk80xx_usb_probe(struct usb_interface *intf, ...@@ -1314,78 +1328,78 @@ static int vmk80xx_usb_probe(struct usb_interface *intf,
ep_desc = &iface_desc->endpoint[i].desc; ep_desc = &iface_desc->endpoint[i].desc;
if (usb_endpoint_is_int_in(ep_desc)) { if (usb_endpoint_is_int_in(ep_desc)) {
dev->ep_rx = ep_desc; devpriv->ep_rx = ep_desc;
continue; continue;
} }
if (usb_endpoint_is_int_out(ep_desc)) { if (usb_endpoint_is_int_out(ep_desc)) {
dev->ep_tx = ep_desc; devpriv->ep_tx = ep_desc;
continue; continue;
} }
if (usb_endpoint_is_bulk_in(ep_desc)) { if (usb_endpoint_is_bulk_in(ep_desc)) {
dev->ep_rx = ep_desc; devpriv->ep_rx = ep_desc;
continue; continue;
} }
if (usb_endpoint_is_bulk_out(ep_desc)) { if (usb_endpoint_is_bulk_out(ep_desc)) {
dev->ep_tx = ep_desc; devpriv->ep_tx = ep_desc;
continue; continue;
} }
} }
if (!dev->ep_rx || !dev->ep_tx) if (!devpriv->ep_rx || !devpriv->ep_tx)
goto error; goto error;
size = le16_to_cpu(dev->ep_rx->wMaxPacketSize); size = le16_to_cpu(devpriv->ep_rx->wMaxPacketSize);
dev->usb_rx_buf = kmalloc(size, GFP_KERNEL); devpriv->usb_rx_buf = kmalloc(size, GFP_KERNEL);
if (!dev->usb_rx_buf) { if (!devpriv->usb_rx_buf) {
mutex_unlock(&glb_mutex); mutex_unlock(&glb_mutex);
return -ENOMEM; return -ENOMEM;
} }
size = le16_to_cpu(dev->ep_tx->wMaxPacketSize); size = le16_to_cpu(devpriv->ep_tx->wMaxPacketSize);
dev->usb_tx_buf = kmalloc(size, GFP_KERNEL); devpriv->usb_tx_buf = kmalloc(size, GFP_KERNEL);
if (!dev->usb_tx_buf) { if (!devpriv->usb_tx_buf) {
kfree(dev->usb_rx_buf); kfree(devpriv->usb_rx_buf);
mutex_unlock(&glb_mutex); mutex_unlock(&glb_mutex);
return -ENOMEM; return -ENOMEM;
} }
dev->udev = interface_to_usbdev(intf); devpriv->usb = interface_to_usbdev(intf);
dev->intf = intf; devpriv->intf = intf;
sema_init(&dev->limit_sem, 8); sema_init(&devpriv->limit_sem, 8);
init_waitqueue_head(&dev->read_wait); init_waitqueue_head(&devpriv->read_wait);
init_waitqueue_head(&dev->write_wait); init_waitqueue_head(&devpriv->write_wait);
init_usb_anchor(&dev->rx_anchor); init_usb_anchor(&devpriv->rx_anchor);
init_usb_anchor(&dev->tx_anchor); init_usb_anchor(&devpriv->tx_anchor);
usb_set_intfdata(intf, dev); usb_set_intfdata(intf, devpriv);
boardinfo = &vmk80xx_boardinfo[id->driver_info]; boardinfo = &vmk80xx_boardinfo[id->driver_info];
dev->board = boardinfo; devpriv->board = boardinfo;
if (boardinfo->model == VMK8061_MODEL) { if (boardinfo->model == VMK8061_MODEL) {
vmk80xx_read_eeprom(dev, IC3_VERSION); vmk80xx_read_eeprom(devpriv, IC3_VERSION);
dev_info(&intf->dev, "%s\n", dev->fw.ic3_vers); dev_info(&intf->dev, "%s\n", devpriv->fw.ic3_vers);
if (vmk80xx_check_data_link(dev)) { if (vmk80xx_check_data_link(devpriv)) {
vmk80xx_read_eeprom(dev, IC6_VERSION); vmk80xx_read_eeprom(devpriv, IC6_VERSION);
dev_info(&intf->dev, "%s\n", dev->fw.ic6_vers); dev_info(&intf->dev, "%s\n", devpriv->fw.ic6_vers);
} else { } else {
dbgcm("comedi#: vmk80xx: no conn. to CPU\n"); dbgcm("comedi#: vmk80xx: no conn. to CPU\n");
} }
} }
if (boardinfo->model == VMK8055_MODEL) if (boardinfo->model == VMK8055_MODEL)
vmk80xx_reset_device(dev); vmk80xx_reset_device(devpriv);
dev->probed = 1; devpriv->probed = 1;
dev_info(&intf->dev, "board #%d [%s] now attached\n", dev_info(&intf->dev, "board #%d [%s] now attached\n",
dev->count, boardinfo->name); devpriv->count, boardinfo->name);
mutex_unlock(&glb_mutex); mutex_unlock(&glb_mutex);
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment