It seems like the vmk80xx driver differs from CodingStyle quite a bit, so I guess the first step is to try and bridge that gap... >From c820e58802fd54fa728933111cfdfe99e155be71 Mon Sep 17 00:00:00 2001 From: J. Ali Harlow <ali@xxxxxxxxxxxxxxx> Date: Thu, 12 May 2011 15:17:19 +0100 Subject: [PATCH] Fix vmk80xx comedi driver to conform to CodingStyle Fix vmk80xx comedi driver to conform to CodingStyle Signed-off-by: J. Ali Harlow <ali@xxxxxxxxxxxxxxx> --- drivers/staging/comedi/drivers/vmk80xx.c | 439 +++++++++--------------------- 1 files changed, 124 insertions(+), 315 deletions(-) diff --git a/drivers/staging/comedi/drivers/vmk80xx.c b/drivers/staging/comedi/drivers/vmk80xx.c index 6479c38..9d81c19 100644 --- a/drivers/staging/comedi/drivers/vmk80xx.c +++ b/drivers/staging/comedi/drivers/vmk80xx.c @@ -249,19 +249,14 @@ static void vmk80xx_tx_callback(struct urb *urb) { struct vmk80xx_usb *dev = urb->context; int stat = urb->status; - dbgvm("vmk80xx: %s\n", __func__); - if (stat && !(stat == -ENOENT || stat == -ECONNRESET || stat == -ESHUTDOWN)) dbgcm("comedi#: vmk80xx: %s - nonzero urb status (%d)\n", __func__, stat); - if (!test_bit(TRANS_OUT_BUSY, &dev->flags)) return; - clear_bit(TRANS_OUT_BUSY, &dev->flags); - wake_up_interruptible(&dev->write_wait); } @@ -269,9 +264,7 @@ static void vmk80xx_rx_callback(struct urb *urb) { struct vmk80xx_usb *dev = urb->context; int stat = urb->status; - dbgvm("vmk80xx: %s\n", __func__); - switch (stat) { case 0: break; @@ -284,66 +277,58 @@ static void vmk80xx_rx_callback(struct urb *urb) __func__, stat); goto resubmit; } - goto exit; resubmit: if (test_bit(TRANS_IN_RUNNING, &dev->flags) && dev->intf) { usb_anchor_urb(urb, &dev->rx_anchor); - if (!usb_submit_urb(urb, GFP_KERNEL)) goto exit; - err("comedi#: vmk80xx: %s - submit urb failed\n", __func__); - usb_unanchor_urb(urb); } exit: clear_bit(TRANS_IN_BUSY, &dev->flags); - wake_up_interruptible(&dev->read_wait); } static int vmk80xx_check_data_link(struct vmk80xx_usb *dev) { - unsigned int tx_pipe, rx_pipe; - unsigned char tx[1], rx[2]; - + unsigned int tx_pipe; + unsigned int rx_pipe; + unsigned char tx[1]; + unsigned char rx[2]; dbgvm("vmk80xx: %s\n", __func__); - tx_pipe = usb_sndbulkpipe(dev->udev, 0x01); rx_pipe = usb_rcvbulkpipe(dev->udev, 0x81); - tx[0] = VMK8061_CMD_RD_PWR_STAT; - - /* Check that IC6 (PIC16F871) is powered and + /* + * Check that IC6 (PIC16F871) is powered 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(dev->udev, rx_pipe, rx, 2, NULL, HZ * 10); - return (int)rx[1]; } static void vmk80xx_read_eeprom(struct vmk80xx_usb *dev, int flag) { - unsigned int tx_pipe, rx_pipe; - unsigned char tx[1], rx[64]; + unsigned int tx_pipe; + unsigned int rx_pipe; + unsigned char tx[1]; + unsigned char rx[64]; int cnt; - dbgvm("vmk80xx: %s\n", __func__); - tx_pipe = usb_sndbulkpipe(dev->udev, 0x01); rx_pipe = usb_rcvbulkpipe(dev->udev, 0x81); - tx[0] = VMK8061_CMD_RD_VERSION; - - /* Read the firmware version info of IC3 and - * IC6 from the internal EEPROM of the IC */ + /* + * Read the firmware version info of IC3 and + * 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(dev->udev, rx_pipe, rx, 64, &cnt, HZ * 10); - rx[cnt] = '\0'; - if (flag & IC3_VERSION) strncpy(dev->fw.ic3_vers, rx + 1, 24); else /* IC6_VERSION */ @@ -356,18 +341,13 @@ static int vmk80xx_reset_device(struct vmk80xx_usb *dev) unsigned int tx_pipe; int ival; size_t size; - dbgvm("vmk80xx: %s\n", __func__); - urb = usb_alloc_urb(0, GFP_KERNEL); if (!urb) return -ENOMEM; - tx_pipe = usb_sndintpipe(dev->udev, 0x01); - ival = dev->ep_tx->bInterval; size = le16_to_cpu(dev->ep_tx->wMaxPacketSize); - dev->usb_tx_buf[0] = VMK8055_CMD_RST; dev->usb_tx_buf[1] = 0x00; dev->usb_tx_buf[2] = 0x00; @@ -376,27 +356,23 @@ static int vmk80xx_reset_device(struct vmk80xx_usb *dev) dev->usb_tx_buf[5] = 0x00; dev->usb_tx_buf[6] = 0x00; dev->usb_tx_buf[7] = 0x00; - usb_fill_int_urb(urb, dev->udev, tx_pipe, dev->usb_tx_buf, size, vmk80xx_tx_callback, dev, ival); - usb_anchor_urb(urb, &dev->tx_anchor); - return usb_submit_urb(urb, GFP_KERNEL); } static void vmk80xx_build_int_urb(struct urb *urb, int flag) { struct vmk80xx_usb *dev = urb->context; - __u8 rx_addr, tx_addr; + __u8 rx_addr; + __u8 tx_addr; unsigned int pipe; unsigned char *buf; size_t size; void (*callback) (struct urb *); int ival; - dbgvm("vmk80xx: %s\n", __func__); - if (flag & URB_RCV_FLAG) { rx_addr = dev->ep_rx->bEndpointAddress; pipe = usb_rcvintpipe(dev->udev, rx_addr); @@ -412,34 +388,31 @@ static void vmk80xx_build_int_urb(struct urb *urb, int flag) callback = vmk80xx_tx_callback; ival = dev->ep_tx->bInterval; } - usb_fill_int_urb(urb, dev->udev, pipe, buf, size, callback, dev, ival); } static void vmk80xx_do_bulk_msg(struct vmk80xx_usb *dev) { - __u8 tx_addr, rx_addr; - unsigned int tx_pipe, rx_pipe; + __u8 tx_addr; + __u8 rx_addr; + unsigned int tx_pipe; + unsigned int rx_pipe; size_t size; - dbgvm("vmk80xx: %s\n", __func__); - set_bit(TRANS_IN_BUSY, &dev->flags); set_bit(TRANS_OUT_BUSY, &dev->flags); - tx_addr = dev->ep_tx->bEndpointAddress; rx_addr = dev->ep_rx->bEndpointAddress; tx_pipe = usb_sndbulkpipe(dev->udev, tx_addr); rx_pipe = usb_rcvbulkpipe(dev->udev, rx_addr); - - /* The max packet size attributes of the K8061 - * input/output endpoints are identical */ + /* + * The max packet size attributes of the K8061 + * input/output endpoints are identical + */ size = le16_to_cpu(dev->ep_tx->wMaxPacketSize); - usb_bulk_msg(dev->udev, tx_pipe, dev->usb_tx_buf, size, NULL, dev->ep_tx->bInterval); usb_bulk_msg(dev->udev, rx_pipe, dev->usb_rx_buf, size, NULL, HZ * 10); - clear_bit(TRANS_OUT_BUSY, &dev->flags); clear_bit(TRANS_IN_BUSY, &dev->flags); } @@ -448,47 +421,34 @@ static int vmk80xx_read_packet(struct vmk80xx_usb *dev) { struct urb *urb; int retval; - dbgvm("vmk80xx: %s\n", __func__); - if (!dev->intf) return -ENODEV; - /* Only useful for interrupt transfers */ if (test_bit(TRANS_IN_BUSY, &dev->flags)) if (wait_event_interruptible(dev->read_wait, !test_bit(TRANS_IN_BUSY, &dev->flags))) return -ERESTART; - if (dev->board.model == VMK8061_MODEL) { vmk80xx_do_bulk_msg(dev); - return 0; } - urb = usb_alloc_urb(0, GFP_KERNEL); if (!urb) return -ENOMEM; - urb->context = dev; vmk80xx_build_int_urb(urb, URB_RCV_FLAG); - set_bit(TRANS_IN_RUNNING, &dev->flags); set_bit(TRANS_IN_BUSY, &dev->flags); - usb_anchor_urb(urb, &dev->rx_anchor); - retval = usb_submit_urb(urb, GFP_KERNEL); if (!retval) goto exit; - clear_bit(TRANS_IN_RUNNING, &dev->flags); usb_unanchor_urb(urb); - exit: usb_free_urb(urb); - return retval; } @@ -496,86 +456,72 @@ static int vmk80xx_write_packet(struct vmk80xx_usb *dev, int cmd) { struct urb *urb; int retval; - dbgvm("vmk80xx: %s\n", __func__); - if (!dev->intf) return -ENODEV; - if (test_bit(TRANS_OUT_BUSY, &dev->flags)) if (wait_event_interruptible(dev->write_wait, !test_bit(TRANS_OUT_BUSY, &dev->flags))) return -ERESTART; - if (dev->board.model == VMK8061_MODEL) { dev->usb_tx_buf[0] = cmd; vmk80xx_do_bulk_msg(dev); - return 0; } - urb = usb_alloc_urb(0, GFP_KERNEL); if (!urb) return -ENOMEM; - urb->context = dev; vmk80xx_build_int_urb(urb, URB_SND_FLAG); - set_bit(TRANS_OUT_BUSY, &dev->flags); - usb_anchor_urb(urb, &dev->tx_anchor); - dev->usb_tx_buf[0] = cmd; - retval = usb_submit_urb(urb, GFP_KERNEL); if (!retval) goto exit; - clear_bit(TRANS_OUT_BUSY, &dev->flags); usb_unanchor_urb(urb); - exit: usb_free_urb(urb); - return retval; } #define DIR_IN 1 #define DIR_OUT 2 -#define rudimentary_check(dir) \ -do { \ - if (!dev) \ - return -EFAULT; \ - if (!dev->probed) \ - return -ENODEV; \ - if (!dev->attached) \ - return -ENODEV; \ - if ((dir) & DIR_IN) { \ - if (test_bit(TRANS_IN_BUSY, &dev->flags)) \ - return -EBUSY; \ - } else { /* DIR_OUT */ \ - if (test_bit(TRANS_OUT_BUSY, &dev->flags)) \ - return -EBUSY; \ - } \ -} while (0) +static int rudimentary_check(struct vmk80xx_usb *dev, int dir) +{ + if (!dev) + return -EFAULT; + if (!dev->probed) + return -ENODEV; + if (!dev->attached) + return -ENODEV; + if (dir & DIR_IN) { + if (test_bit(TRANS_IN_BUSY, &dev->flags)) + return -EBUSY; + } else { /* DIR_OUT */ + if (test_bit(TRANS_OUT_BUSY, &dev->flags)) + return -EBUSY; + } + return 0; +} static int vmk80xx_ai_rinsn(struct comedi_device *cdev, struct comedi_subdevice *s, struct comedi_insn *insn, unsigned int *data) { struct vmk80xx_usb *dev = cdev->private; - int chan, reg[2]; + int chan; + int reg[2]; int n; - dbgvm("vmk80xx: %s\n", __func__); - - rudimentary_check(DIR_IN); - + n = rudimentary_check(dev, DIR_IN); + if (n) + return n; down(&dev->limit_sem); chan = CR_CHAN(insn->chanspec); - switch (dev->board.model) { case VMK8055_MODEL: if (!chan) @@ -590,23 +536,18 @@ static int vmk80xx_ai_rinsn(struct comedi_device *cdev, dev->usb_tx_buf[VMK8061_CH_REG] = chan; break; } - for (n = 0; n < insn->n; n++) { if (vmk80xx_read_packet(dev)) break; - if (dev->board.model == VMK8055_MODEL) { data[n] = dev->usb_rx_buf[reg[0]]; continue; } - /* VMK8061_MODEL */ data[n] = dev->usb_rx_buf[reg[0]] + 256 * dev->usb_rx_buf[reg[1]]; } - up(&dev->limit_sem); - return n; } @@ -615,16 +556,16 @@ static int vmk80xx_ao_winsn(struct comedi_device *cdev, struct comedi_insn *insn, unsigned int *data) { struct vmk80xx_usb *dev = cdev->private; - int chan, cmd, reg; + int chan; + int cmd; + int reg; int n; - dbgvm("vmk80xx: %s\n", __func__); - - rudimentary_check(DIR_OUT); - + n = rudimentary_check(dev, DIR_OUT); + if (n) + return n; down(&dev->limit_sem); chan = CR_CHAN(insn->chanspec); - switch (dev->board.model) { case VMK8055_MODEL: cmd = VMK8055_CMD_WRT_AD; @@ -639,16 +580,12 @@ static int vmk80xx_ao_winsn(struct comedi_device *cdev, dev->usb_tx_buf[VMK8061_CH_REG] = chan; break; } - for (n = 0; n < insn->n; n++) { dev->usb_tx_buf[reg] = data[n]; - if (vmk80xx_write_packet(dev, cmd)) break; } - up(&dev->limit_sem); - return n; } @@ -657,29 +594,23 @@ static int vmk80xx_ao_rinsn(struct comedi_device *cdev, struct comedi_insn *insn, unsigned int *data) { struct vmk80xx_usb *dev = cdev->private; - int chan, reg; + int chan; + int reg; int n; - dbgvm("vmk80xx: %s\n", __func__); - - rudimentary_check(DIR_IN); - + n = rudimentary_check(dev, DIR_IN); + if (n) + return n; down(&dev->limit_sem); chan = CR_CHAN(insn->chanspec); - reg = VMK8061_AO_REG - 1; - dev->usb_tx_buf[0] = VMK8061_CMD_RD_AO; - for (n = 0; n < insn->n; n++) { if (vmk80xx_read_packet(dev)) break; - data[n] = dev->usb_rx_buf[reg + chan]; } - up(&dev->limit_sem); - return n; } @@ -690,40 +621,34 @@ static int vmk80xx_di_rinsn(struct comedi_device *cdev, struct vmk80xx_usb *dev = cdev->private; int chan; unsigned char *rx_buf; - int reg, inp; + int reg; + int inp; int n; - dbgvm("vmk80xx: %s\n", __func__); - - rudimentary_check(DIR_IN); - + n = rudimentary_check(dev, DIR_IN); + if (n) + return n; down(&dev->limit_sem); chan = CR_CHAN(insn->chanspec); - rx_buf = dev->usb_rx_buf; - if (dev->board.model == VMK8061_MODEL) { reg = VMK8061_DI_REG; dev->usb_tx_buf[0] = VMK8061_CMD_RD_DI; - } else + } else { reg = VMK8055_DI_REG; - + } for (n = 0; n < insn->n; n++) { if (vmk80xx_read_packet(dev)) break; - if (dev->board.model == VMK8055_MODEL) inp = (((rx_buf[reg] >> 4) & 0x03) | ((rx_buf[reg] << 2) & 0x04) | ((rx_buf[reg] >> 3) & 0x18)); else inp = rx_buf[reg]; - data[n] = ((inp & (1 << chan)) > 0); } - up(&dev->limit_sem); - return n; } @@ -731,22 +656,19 @@ static int vmk80xx_do_winsn(struct comedi_device *cdev, struct comedi_subdevice *s, struct comedi_insn *insn, unsigned int *data) { - struct vmk80xx_usb *dev = cdev->private; int chan; unsigned char *tx_buf; - int reg, cmd; + int reg; + int cmd; int n; - dbgvm("vmk80xx: %s\n", __func__); - - rudimentary_check(DIR_OUT); - + n = rudimentary_check(dev, DIR_OUT); + if (n) + return n; down(&dev->limit_sem); chan = CR_CHAN(insn->chanspec); - tx_buf = dev->usb_tx_buf; - for (n = 0; n < insn->n; n++) { if (dev->board.model == VMK8055_MODEL) { reg = VMK8055_DO_REG; @@ -755,27 +677,20 @@ static int vmk80xx_do_winsn(struct comedi_device *cdev, tx_buf[reg] |= (1 << chan); else tx_buf[reg] ^= (1 << chan); - - goto write_packet; - } - - /* VMK8061_MODEL */ - reg = VMK8061_DO_REG; - if (data[n] == 1) { - cmd = VMK8061_CMD_SET_DO; - tx_buf[reg] = 1 << chan; - } else { - cmd = VMK8061_CMD_CLR_DO; - tx_buf[reg] = 0xff - (1 << chan); + } else { /* VMK8061_MODEL */ + reg = VMK8061_DO_REG; + if (data[n] == 1) { + cmd = VMK8061_CMD_SET_DO; + tx_buf[reg] = 1 << chan; + } else { + cmd = VMK8061_CMD_CLR_DO; + tx_buf[reg] = 0xff - (1 << chan); + } } - -write_packet: if (vmk80xx_write_packet(dev, cmd)) break; } - up(&dev->limit_sem); - return n; } @@ -784,30 +699,25 @@ static int vmk80xx_do_rinsn(struct comedi_device *cdev, struct comedi_insn *insn, unsigned int *data) { struct vmk80xx_usb *dev = cdev->private; - int chan, reg, mask; + int chan; + int reg; + int mask; int n; - dbgvm("vmk80xx: %s\n", __func__); - - rudimentary_check(DIR_IN); - + n = rudimentary_check(dev, DIR_IN); + if (n) + return n; down(&dev->limit_sem); chan = CR_CHAN(insn->chanspec); - reg = VMK8061_DO_REG; mask = 1 << chan; - dev->usb_tx_buf[0] = VMK8061_CMD_RD_DO; - for (n = 0; n < insn->n; n++) { if (vmk80xx_read_packet(dev)) break; - data[n] = (dev->usb_rx_buf[reg] & mask) >> chan; } - up(&dev->limit_sem); - return n; } @@ -816,16 +726,15 @@ static int vmk80xx_cnt_rinsn(struct comedi_device *cdev, struct comedi_insn *insn, unsigned int *data) { struct vmk80xx_usb *dev = cdev->private; - int chan, reg[2]; + int chan; + int reg[2]; int n; - dbgvm("vmk80xx: %s\n", __func__); - - rudimentary_check(DIR_IN); - + n = rudimentary_check(dev, DIR_IN); + if (n) + return n; down(&dev->limit_sem); chan = CR_CHAN(insn->chanspec); - switch (dev->board.model) { case VMK8055_MODEL: if (!chan) @@ -839,23 +748,16 @@ static int vmk80xx_cnt_rinsn(struct comedi_device *cdev, dev->usb_tx_buf[0] = VMK8061_CMD_RD_CNT; break; } - for (n = 0; n < insn->n; n++) { if (vmk80xx_read_packet(dev)) break; - - if (dev->board.model == VMK8055_MODEL) { + if (dev->board.model == VMK8055_MODEL) data[n] = dev->usb_rx_buf[reg[0]]; - continue; - } - - /* VMK8061_MODEL */ - data[n] = dev->usb_rx_buf[reg[0] * (chan + 1) + 1] - + 256 * dev->usb_rx_buf[reg[1] * 2 + 2]; + else /* VMK8061_MODEL */ + data[n] = dev->usb_rx_buf[reg[0] * (chan + 1) + 1] + + 256 * dev->usb_rx_buf[reg[1] * 2 + 2]; } - up(&dev->limit_sem); - return n; } @@ -865,21 +767,19 @@ static int vmk80xx_cnt_cinsn(struct comedi_device *cdev, { struct vmk80xx_usb *dev = cdev->private; unsigned int insn_cmd; - int chan, cmd, reg; + int chan; + int cmd; + int reg; int n; - dbgvm("vmk80xx: %s\n", __func__); - - rudimentary_check(DIR_OUT); - + n = rudimentary_check(dev, DIR_OUT); + if (n) + return n; down(&dev->limit_sem); - insn_cmd = data[0]; if (insn_cmd != INSN_CONFIG_RESET && insn_cmd != GPCT_RESET) return -EINVAL; - chan = CR_CHAN(insn->chanspec); - if (dev->board.model == VMK8055_MODEL) { if (!chan) { cmd = VMK8055_CMD_RST_CNT1; @@ -888,17 +788,14 @@ static int vmk80xx_cnt_cinsn(struct comedi_device *cdev, cmd = VMK8055_CMD_RST_CNT2; reg = VMK8055_CNT2_REG; } - dev->usb_tx_buf[reg] = 0x00; - } else + } else { cmd = VMK8061_CMD_RST_CNT; - + } for (n = 0; n < insn->n; n++) if (vmk80xx_write_packet(dev, cmd)) break; - up(&dev->limit_sem); - return n; } @@ -907,43 +804,36 @@ static int vmk80xx_cnt_winsn(struct comedi_device *cdev, struct comedi_insn *insn, unsigned int *data) { struct vmk80xx_usb *dev = cdev->private; - unsigned long debtime, val; - int chan, cmd; + unsigned long debtime; + unsigned long val; + int chan; + int cmd; int n; - dbgvm("vmk80xx: %s\n", __func__); - - rudimentary_check(DIR_OUT); - + n = rudimentary_check(dev, DIR_OUT); + if (n) + return n; down(&dev->limit_sem); chan = CR_CHAN(insn->chanspec); - if (!chan) cmd = VMK8055_CMD_DEB1_TIME; else cmd = VMK8055_CMD_DEB2_TIME; - for (n = 0; n < insn->n; n++) { debtime = data[n]; if (debtime == 0) debtime = 1; - /* TODO: Prevent overflows */ if (debtime > 7450) debtime = 7450; - val = int_sqrt(debtime * 1000 / 115); if (((val + 1) * val) < debtime * 1000 / 115) val += 1; - dev->usb_tx_buf[6 + chan] = val; - if (vmk80xx_write_packet(dev, cmd)) break; } - up(&dev->limit_sem); - return n; } @@ -954,27 +844,20 @@ static int vmk80xx_pwm_rinsn(struct comedi_device *cdev, struct vmk80xx_usb *dev = cdev->private; int reg[2]; int n; - dbgvm("vmk80xx: %s\n", __func__); - - rudimentary_check(DIR_IN); - + n = rudimentary_check(dev, DIR_IN); + if (n) + return n; down(&dev->limit_sem); - reg[0] = VMK8061_PWM_REG1; reg[1] = VMK8061_PWM_REG2; - dev->usb_tx_buf[0] = VMK8061_CMD_RD_PWM; - for (n = 0; n < insn->n; n++) { if (vmk80xx_read_packet(dev)) break; - data[n] = dev->usb_rx_buf[reg[0]] + 4 * dev->usb_rx_buf[reg[1]]; } - up(&dev->limit_sem); - return n; } @@ -984,22 +867,18 @@ static int vmk80xx_pwm_winsn(struct comedi_device *cdev, { struct vmk80xx_usb *dev = cdev->private; unsigned char *tx_buf; - int reg[2], cmd; + int reg[2]; + int cmd; int n; - dbgvm("vmk80xx: %s\n", __func__); - - rudimentary_check(DIR_OUT); - + n = rudimentary_check(dev, DIR_OUT); + if (n) + return n; down(&dev->limit_sem); - tx_buf = dev->usb_tx_buf; - reg[0] = VMK8061_PWM_REG1; reg[1] = VMK8061_PWM_REG2; - cmd = VMK8061_CMD_OUT_PWM; - /* * The followin piece of code was translated from the inline * assembler code in the DLL source code. @@ -1016,56 +895,43 @@ static int vmk80xx_pwm_winsn(struct comedi_device *cdev, for (n = 0; n < insn->n; n++) { tx_buf[reg[0]] = (unsigned char)(data[n] & 0x03); tx_buf[reg[1]] = (unsigned char)(data[n] >> 2) & 0xff; - if (vmk80xx_write_packet(dev, cmd)) break; } - up(&dev->limit_sem); - return n; } -static int -vmk80xx_attach(struct comedi_device *cdev, struct comedi_devconfig *it) +static int vmk80xx_attach(struct comedi_device *cdev, + struct comedi_devconfig *it) { int i; struct vmk80xx_usb *dev; int n_subd; struct comedi_subdevice *s; int minor; - dbgvm("vmk80xx: %s\n", __func__); - mutex_lock(&glb_mutex); - for (i = 0; i < VMK80XX_MAX_BOARDS; i++) if (vmb[i].probed && !vmb[i].attached) break; - if (i == VMK80XX_MAX_BOARDS) { mutex_unlock(&glb_mutex); return -ENODEV; } - dev = &vmb[i]; - down(&dev->limit_sem); - cdev->board_name = dev->board.name; cdev->private = dev; - if (dev->board.model == VMK8055_MODEL) n_subd = 5; else n_subd = 6; - if (alloc_subdevices(cdev, n_subd) < 0) { up(&dev->limit_sem); mutex_unlock(&glb_mutex); return -ENOMEM; } - /* Analog input subdevice */ s = cdev->subdevices + VMK80XX_SUBD_AI; s->type = COMEDI_SUBD_AI; @@ -1074,7 +940,6 @@ vmk80xx_attach(struct comedi_device *cdev, struct comedi_devconfig *it) s->maxdata = (1 << dev->board.ai_bits) - 1; s->range_table = dev->board.range; s->insn_read = vmk80xx_ai_rinsn; - /* Analog output subdevice */ s = cdev->subdevices + VMK80XX_SUBD_AO; s->type = COMEDI_SUBD_AO; @@ -1083,12 +948,10 @@ vmk80xx_attach(struct comedi_device *cdev, struct comedi_devconfig *it) s->maxdata = (1 << dev->board.ao_bits) - 1; s->range_table = dev->board.range; s->insn_write = vmk80xx_ao_winsn; - if (dev->board.model == VMK8061_MODEL) { s->subdev_flags |= SDF_READABLE; s->insn_read = vmk80xx_ao_rinsn; } - /* Digital input subdevice */ s = cdev->subdevices + VMK80XX_SUBD_DI; s->type = COMEDI_SUBD_DI; @@ -1096,7 +959,6 @@ vmk80xx_attach(struct comedi_device *cdev, struct comedi_devconfig *it) s->n_chan = dev->board.di_chans; s->maxdata = (1 << dev->board.di_bits) - 1; s->insn_read = vmk80xx_di_rinsn; - /* Digital output subdevice */ s = cdev->subdevices + VMK80XX_SUBD_DO; s->type = COMEDI_SUBD_DO; @@ -1104,12 +966,10 @@ vmk80xx_attach(struct comedi_device *cdev, struct comedi_devconfig *it) s->n_chan = dev->board.do_chans; s->maxdata = (1 << dev->board.do_bits) - 1; s->insn_write = vmk80xx_do_winsn; - if (dev->board.model == VMK8061_MODEL) { s->subdev_flags |= SDF_READABLE; s->insn_read = vmk80xx_do_rinsn; } - /* Counter subdevice */ s = cdev->subdevices + VMK80XX_SUBD_CNT; s->type = COMEDI_SUBD_COUNTER; @@ -1117,13 +977,11 @@ vmk80xx_attach(struct comedi_device *cdev, struct comedi_devconfig *it) s->n_chan = dev->board.cnt_chans; s->insn_read = vmk80xx_cnt_rinsn; s->insn_config = vmk80xx_cnt_cinsn; - if (dev->board.model == VMK8055_MODEL) { s->subdev_flags |= SDF_WRITEABLE; s->maxdata = (1 << dev->board.cnt_bits) - 1; s->insn_write = vmk80xx_cnt_winsn; } - /* PWM subdevice */ if (dev->board.model == VMK8061_MODEL) { s = cdev->subdevices + VMK80XX_SUBD_PWM; @@ -1134,18 +992,13 @@ vmk80xx_attach(struct comedi_device *cdev, struct comedi_devconfig *it) s->insn_read = vmk80xx_pwm_rinsn; s->insn_write = vmk80xx_pwm_winsn; } - dev->attached = 1; - minor = cdev->minor; - printk(KERN_INFO "comedi%d: vmk80xx: board #%d [%s] attached to comedi\n", minor, dev->count, dev->board.name); - up(&dev->limit_sem); mutex_unlock(&glb_mutex); - return 0; } @@ -1153,97 +1006,73 @@ static int vmk80xx_detach(struct comedi_device *cdev) { struct vmk80xx_usb *dev; int minor; - dbgvm("vmk80xx: %s\n", __func__); - if (!cdev) return -EFAULT; - dev = cdev->private; if (!dev) return -EFAULT; - down(&dev->limit_sem); - cdev->private = NULL; dev->attached = 0; - minor = cdev->minor; - printk(KERN_INFO "comedi%d: vmk80xx: board #%d [%s] detached from comedi\n", minor, dev->count, dev->board.name); - up(&dev->limit_sem); - return 0; } -static int -vmk80xx_probe(struct usb_interface *intf, const struct usb_device_id *id) +static int vmk80xx_probe(struct usb_interface *intf, + const struct usb_device_id *id) { int i; struct vmk80xx_usb *dev; struct usb_host_interface *iface_desc; struct usb_endpoint_descriptor *ep_desc; size_t size; - dbgvm("vmk80xx: %s\n", __func__); - mutex_lock(&glb_mutex); - for (i = 0; i < VMK80XX_MAX_BOARDS; i++) if (!vmb[i].probed) break; - if (i == VMK80XX_MAX_BOARDS) { mutex_unlock(&glb_mutex); return -EMFILE; } - dev = &vmb[i]; - memset(dev, 0x00, sizeof(struct vmk80xx_usb)); dev->count = i; - iface_desc = intf->cur_altsetting; if (iface_desc->desc.bNumEndpoints != 2) goto error; - for (i = 0; i < iface_desc->desc.bNumEndpoints; i++) { ep_desc = &iface_desc->endpoint[i].desc; - if (usb_endpoint_is_int_in(ep_desc)) { dev->ep_rx = ep_desc; continue; } - if (usb_endpoint_is_int_out(ep_desc)) { dev->ep_tx = ep_desc; continue; } - if (usb_endpoint_is_bulk_in(ep_desc)) { dev->ep_rx = ep_desc; continue; } - if (usb_endpoint_is_bulk_out(ep_desc)) { dev->ep_tx = ep_desc; continue; } } - if (!dev->ep_rx || !dev->ep_tx) goto error; - size = le16_to_cpu(dev->ep_rx->wMaxPacketSize); dev->usb_rx_buf = kmalloc(size, GFP_KERNEL); if (!dev->usb_rx_buf) { mutex_unlock(&glb_mutex); return -ENOMEM; } - size = le16_to_cpu(dev->ep_tx->wMaxPacketSize); dev->usb_tx_buf = kmalloc(size, GFP_KERNEL); if (!dev->usb_tx_buf) { @@ -1251,19 +1080,14 @@ vmk80xx_probe(struct usb_interface *intf, const struct usb_device_id *id) mutex_unlock(&glb_mutex); return -ENOMEM; } - dev->udev = interface_to_usbdev(intf); dev->intf = intf; - sema_init(&dev->limit_sem, 8); init_waitqueue_head(&dev->read_wait); init_waitqueue_head(&dev->write_wait); - init_usb_anchor(&dev->rx_anchor); init_usb_anchor(&dev->tx_anchor); - usb_set_intfdata(intf, dev); - switch (id->driver_info) { case DEVICE_VMK8055: dev->board.name = "K8055 (VM110)"; @@ -1300,60 +1124,45 @@ vmk80xx_probe(struct usb_interface *intf, const struct usb_device_id *id) dev->board.pwm_bits = 10; break; } - if (dev->board.model == VMK8061_MODEL) { vmk80xx_read_eeprom(dev, IC3_VERSION); printk(KERN_INFO "comedi#: vmk80xx: %s\n", dev->fw.ic3_vers); - if (vmk80xx_check_data_link(dev)) { vmk80xx_read_eeprom(dev, IC6_VERSION); printk(KERN_INFO "comedi#: vmk80xx: %s\n", dev->fw.ic6_vers); - } else + } else { dbgcm("comedi#: vmk80xx: no conn. to CPU\n"); + } } - if (dev->board.model == VMK8055_MODEL) vmk80xx_reset_device(dev); - dev->probed = 1; - printk(KERN_INFO "comedi#: vmk80xx: board #%d [%s] now attached\n", dev->count, dev->board.name); - mutex_unlock(&glb_mutex); - return 0; error: mutex_unlock(&glb_mutex); - return -ENODEV; } static void vmk80xx_disconnect(struct usb_interface *intf) { struct vmk80xx_usb *dev = usb_get_intfdata(intf); - dbgvm("vmk80xx: %s\n", __func__); - if (!dev) return; - mutex_lock(&glb_mutex); down(&dev->limit_sem); - dev->probed = 0; usb_set_intfdata(dev->intf, NULL); - usb_kill_anchored_urbs(&dev->rx_anchor); usb_kill_anchored_urbs(&dev->tx_anchor); - kfree(dev->usb_rx_buf); kfree(dev->usb_tx_buf); - printk(KERN_INFO "comedi#: vmk80xx: board #%d [%s] now detached\n", dev->count, dev->board.name); - up(&dev->limit_sem); mutex_unlock(&glb_mutex); } -- 1.7.2.3 _______________________________________________ devel mailing list devel@xxxxxxxxxxxxxxxxxxxxxx http://driverdev.linuxdriverproject.org/mailman/listinfo/devel