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

staging: comedi: usbduxsigma: tidy up usbduxsigma_usb_probe()

For aesthetic reasons, rename some of the variables to the "norm" used
in comedi drivers.

Use a local variable for the pointer to the private data instead of
accessing the static array directly. Also use a local variable to
setup the urbs.
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 eead8c66
...@@ -1955,224 +1955,198 @@ static struct comedi_driver usbduxsigma_driver = { ...@@ -1955,224 +1955,198 @@ static struct comedi_driver usbduxsigma_driver = {
.detach = usbduxsigma_detach, .detach = usbduxsigma_detach,
}; };
static int usbduxsigma_usb_probe(struct usb_interface *uinterf, static int usbduxsigma_usb_probe(struct usb_interface *intf,
const struct usb_device_id *id) const struct usb_device_id *id)
{ {
struct usb_device *udev = interface_to_usbdev(uinterf); struct usb_device *usb = interface_to_usbdev(intf);
struct device *dev = &uinterf->dev; struct device *dev = &intf->dev;
struct usbduxsigma_private *devpriv = NULL;
struct urb *urb;
int i; int i;
int index;
down(&start_stop_sem); down(&start_stop_sem);
/* look for a free place in the usbdux array */
index = -1;
for (i = 0; i < NUMUSBDUX; i++) { for (i = 0; i < NUMUSBDUX; i++) {
if (!(usbduxsub[i].probed)) { if (!usbduxsub[i].probed) {
index = i; devpriv = &usbduxsub[i];
break; break;
} }
} }
/* no more space */ if (!devpriv) {
if (index == -1) {
dev_err(dev, "Too many usbduxsigma-devices connected.\n"); dev_err(dev, "Too many usbduxsigma-devices connected.\n");
up(&start_stop_sem); up(&start_stop_sem);
return -EMFILE; return -EMFILE;
} }
sema_init(&(usbduxsub[index].sem), 1); sema_init(&devpriv->sem, 1);
/* save a pointer to the usb device */ devpriv->usbdev = usb;
usbduxsub[index].usbdev = udev; devpriv->interface = intf;
devpriv->ifnum = intf->altsetting->desc.bInterfaceNumber;
/* save the interface itself */ usb_set_intfdata(intf, devpriv);
usbduxsub[index].interface = uinterf;
/* get the interface number from the interface */
usbduxsub[index].ifnum = uinterf->altsetting->desc.bInterfaceNumber;
/* hand the private data over to the usb subsystem */
/* will be needed for disconnect */
usb_set_intfdata(uinterf, &(usbduxsub[index]));
/* test if it is high speed (USB 2.0) */ /* test if it is high speed (USB 2.0) */
usbduxsub[index].high_speed = devpriv->high_speed = (usb->speed == USB_SPEED_HIGH);
(usbduxsub[index].usbdev->speed == USB_SPEED_HIGH);
/* create space for the commands of the DA converter */ /* create space for the commands of the DA converter */
usbduxsub[index].dac_commands = kzalloc(NUMOUTCHANNELS, GFP_KERNEL); devpriv->dac_commands = kzalloc(NUMOUTCHANNELS, GFP_KERNEL);
if (!usbduxsub[index].dac_commands) { if (!devpriv->dac_commands) {
tidy_up(&(usbduxsub[index])); tidy_up(devpriv);
up(&start_stop_sem); up(&start_stop_sem);
return -ENOMEM; return -ENOMEM;
} }
/* create space for the commands going to the usb device */ /* create space for the commands going to the usb device */
usbduxsub[index].dux_commands = kzalloc(SIZEOFDUXBUFFER, GFP_KERNEL); devpriv->dux_commands = kzalloc(SIZEOFDUXBUFFER, GFP_KERNEL);
if (!usbduxsub[index].dux_commands) { if (!devpriv->dux_commands) {
tidy_up(&(usbduxsub[index])); tidy_up(devpriv);
up(&start_stop_sem); up(&start_stop_sem);
return -ENOMEM; return -ENOMEM;
} }
/* create space for the in buffer and set it to zero */ /* create space for the in buffer and set it to zero */
usbduxsub[index].inBuffer = kzalloc(SIZEINBUF, GFP_KERNEL); devpriv->inBuffer = kzalloc(SIZEINBUF, GFP_KERNEL);
if (!(usbduxsub[index].inBuffer)) { if (!devpriv->inBuffer) {
tidy_up(&(usbduxsub[index])); tidy_up(devpriv);
up(&start_stop_sem); up(&start_stop_sem);
return -ENOMEM; return -ENOMEM;
} }
/* create space of the instruction buffer */ /* create space of the instruction buffer */
usbduxsub[index].insnBuffer = kzalloc(SIZEINSNBUF, GFP_KERNEL); devpriv->insnBuffer = kzalloc(SIZEINSNBUF, GFP_KERNEL);
if (!(usbduxsub[index].insnBuffer)) { if (!devpriv->insnBuffer) {
tidy_up(&(usbduxsub[index])); tidy_up(devpriv);
up(&start_stop_sem); up(&start_stop_sem);
return -ENOMEM; return -ENOMEM;
} }
/* create space for the outbuffer */ /* create space for the outbuffer */
usbduxsub[index].outBuffer = kzalloc(SIZEOUTBUF, GFP_KERNEL); devpriv->outBuffer = kzalloc(SIZEOUTBUF, GFP_KERNEL);
if (!(usbduxsub[index].outBuffer)) { if (!devpriv->outBuffer) {
tidy_up(&(usbduxsub[index])); tidy_up(devpriv);
up(&start_stop_sem); up(&start_stop_sem);
return -ENOMEM; return -ENOMEM;
} }
/* setting to alternate setting 3: enabling iso ep and bulk ep. */ /* setting to alternate setting 3: enabling iso ep and bulk ep. */
i = usb_set_interface(usbduxsub[index].usbdev, i = usb_set_interface(usb, devpriv->ifnum, 3);
usbduxsub[index].ifnum, 3);
if (i < 0) { if (i < 0) {
dev_err(dev, "comedi_: usbduxsigma%d: " dev_err(dev,
"could not set alternate setting 3 in high speed.\n", "could not set alternate setting 3 in high speed\n");
index); tidy_up(devpriv);
tidy_up(&(usbduxsub[index]));
up(&start_stop_sem); up(&start_stop_sem);
return -ENODEV; return -ENODEV;
} }
if (usbduxsub[index].high_speed) if (devpriv->high_speed)
usbduxsub[index].numOfInBuffers = NUMOFINBUFFERSHIGH; devpriv->numOfInBuffers = NUMOFINBUFFERSHIGH;
else else
usbduxsub[index].numOfInBuffers = NUMOFINBUFFERSFULL; devpriv->numOfInBuffers = NUMOFINBUFFERSFULL;
usbduxsub[index].urbIn = kcalloc(usbduxsub[index].numOfInBuffers, devpriv->urbIn = kcalloc(devpriv->numOfInBuffers, sizeof(*urb),
sizeof(struct urb *), GFP_KERNEL);
GFP_KERNEL); if (!devpriv->urbIn) {
if (!(usbduxsub[index].urbIn)) { tidy_up(devpriv);
tidy_up(&(usbduxsub[index]));
up(&start_stop_sem); up(&start_stop_sem);
return -ENOMEM; return -ENOMEM;
} }
for (i = 0; i < usbduxsub[index].numOfInBuffers; i++) { for (i = 0; i < devpriv->numOfInBuffers; i++) {
/* one frame: 1ms */ /* one frame: 1ms */
usbduxsub[index].urbIn[i] = usb_alloc_urb(1, GFP_KERNEL); urb = usb_alloc_urb(1, GFP_KERNEL);
if (usbduxsub[index].urbIn[i] == NULL) { if (!urb) {
dev_err(dev, "comedi_: usbduxsigma%d: " tidy_up(devpriv);
"Could not alloc. urb(%d)\n", index, i);
tidy_up(&(usbduxsub[index]));
up(&start_stop_sem); up(&start_stop_sem);
return -ENOMEM; return -ENOMEM;
} }
usbduxsub[index].urbIn[i]->dev = usbduxsub[index].usbdev; devpriv->urbIn[i] = urb;
urb->dev = usb;
/* will be filled later with a pointer to the comedi-device */ /* will be filled later with a pointer to the comedi-device */
/* and ONLY then the urb should be submitted */ /* and ONLY then the urb should be submitted */
usbduxsub[index].urbIn[i]->context = NULL; urb->context = NULL;
usbduxsub[index].urbIn[i]->pipe = urb->pipe = usb_rcvisocpipe(usb, ISOINEP);
usb_rcvisocpipe(usbduxsub[index].usbdev, ISOINEP); urb->transfer_flags = URB_ISO_ASAP;
usbduxsub[index].urbIn[i]->transfer_flags = URB_ISO_ASAP; urb->transfer_buffer = kzalloc(SIZEINBUF, GFP_KERNEL);
usbduxsub[index].urbIn[i]->transfer_buffer = if (!urb->transfer_buffer) {
kzalloc(SIZEINBUF, GFP_KERNEL); tidy_up(devpriv);
if (!(usbduxsub[index].urbIn[i]->transfer_buffer)) {
tidy_up(&(usbduxsub[index]));
up(&start_stop_sem); up(&start_stop_sem);
return -ENOMEM; return -ENOMEM;
} }
usbduxsub[index].urbIn[i]->complete = usbduxsub_ai_IsocIrq; urb->complete = usbduxsub_ai_IsocIrq;
usbduxsub[index].urbIn[i]->number_of_packets = 1; urb->number_of_packets = 1;
usbduxsub[index].urbIn[i]->transfer_buffer_length = SIZEINBUF; urb->transfer_buffer_length = SIZEINBUF;
usbduxsub[index].urbIn[i]->iso_frame_desc[0].offset = 0; urb->iso_frame_desc[0].offset = 0;
usbduxsub[index].urbIn[i]->iso_frame_desc[0].length = urb->iso_frame_desc[0].length = SIZEINBUF;
SIZEINBUF;
} }
/* out */ /* out */
if (usbduxsub[index].high_speed) if (devpriv->high_speed)
usbduxsub[index].numOfOutBuffers = NUMOFOUTBUFFERSHIGH; devpriv->numOfOutBuffers = NUMOFOUTBUFFERSHIGH;
else else
usbduxsub[index].numOfOutBuffers = NUMOFOUTBUFFERSFULL; devpriv->numOfOutBuffers = NUMOFOUTBUFFERSFULL;
usbduxsub[index].urbOut = kcalloc(usbduxsub[index].numOfOutBuffers, devpriv->urbOut = kcalloc(devpriv->numOfOutBuffers, sizeof(*urb),
sizeof(struct urb *), GFP_KERNEL); GFP_KERNEL);
if (!(usbduxsub[index].urbOut)) { if (!devpriv->urbOut) {
tidy_up(&(usbduxsub[index])); tidy_up(devpriv);
up(&start_stop_sem); up(&start_stop_sem);
return -ENOMEM; return -ENOMEM;
} }
for (i = 0; i < usbduxsub[index].numOfOutBuffers; i++) { for (i = 0; i < devpriv->numOfOutBuffers; i++) {
/* one frame: 1ms */ /* one frame: 1ms */
usbduxsub[index].urbOut[i] = usb_alloc_urb(1, GFP_KERNEL); urb = usb_alloc_urb(1, GFP_KERNEL);
if (usbduxsub[index].urbOut[i] == NULL) { if (!urb) {
dev_err(dev, "comedi_: usbduxsigma%d: " tidy_up(devpriv);
"Could not alloc. urb(%d)\n", index, i);
tidy_up(&(usbduxsub[index]));
up(&start_stop_sem); up(&start_stop_sem);
return -ENOMEM; return -ENOMEM;
} }
usbduxsub[index].urbOut[i]->dev = usbduxsub[index].usbdev; devpriv->urbOut[i] = urb;
urb->dev = usb;
/* will be filled later with a pointer to the comedi-device */ /* will be filled later with a pointer to the comedi-device */
/* and ONLY then the urb should be submitted */ /* and ONLY then the urb should be submitted */
usbduxsub[index].urbOut[i]->context = NULL; urb->context = NULL;
usbduxsub[index].urbOut[i]->pipe = urb->pipe = usb_sndisocpipe(usb, ISOOUTEP);
usb_sndisocpipe(usbduxsub[index].usbdev, ISOOUTEP); urb->transfer_flags = URB_ISO_ASAP;
usbduxsub[index].urbOut[i]->transfer_flags = URB_ISO_ASAP; urb->transfer_buffer = kzalloc(SIZEOUTBUF, GFP_KERNEL);
usbduxsub[index].urbOut[i]->transfer_buffer = if (!urb->transfer_buffer) {
kzalloc(SIZEOUTBUF, GFP_KERNEL); tidy_up(devpriv);
if (!(usbduxsub[index].urbOut[i]->transfer_buffer)) {
tidy_up(&(usbduxsub[index]));
up(&start_stop_sem); up(&start_stop_sem);
return -ENOMEM; return -ENOMEM;
} }
usbduxsub[index].urbOut[i]->complete = usbduxsub_ao_IsocIrq; urb->complete = usbduxsub_ao_IsocIrq;
usbduxsub[index].urbOut[i]->number_of_packets = 1; urb->number_of_packets = 1;
usbduxsub[index].urbOut[i]->transfer_buffer_length = urb->transfer_buffer_length = SIZEOUTBUF;
SIZEOUTBUF; urb->iso_frame_desc[0].offset = 0;
usbduxsub[index].urbOut[i]->iso_frame_desc[0].offset = 0; urb->iso_frame_desc[0].length = SIZEOUTBUF;
usbduxsub[index].urbOut[i]->iso_frame_desc[0].length = if (devpriv->high_speed)
SIZEOUTBUF; urb->interval = 8; /* uframes */
if (usbduxsub[index].high_speed) { else
/* uframes */ urb->interval = 1; /* frames */
usbduxsub[index].urbOut[i]->interval = 8;
} else {
/* frames */
usbduxsub[index].urbOut[i]->interval = 1;
}
} }
/* pwm */ /* pwm */
if (usbduxsub[index].high_speed) { if (devpriv->high_speed) {
/* max bulk ep size in high speed */ /* max bulk ep size in high speed */
usbduxsub[index].sizePwmBuf = 512; devpriv->sizePwmBuf = 512;
usbduxsub[index].urbPwm = usb_alloc_urb(0, GFP_KERNEL); urb = usb_alloc_urb(0, GFP_KERNEL);
if (usbduxsub[index].urbPwm == NULL) { if (!urb) {
dev_err(dev, "comedi_: usbduxsigma%d: " tidy_up(devpriv);
"Could not alloc. pwm urb\n", index);
tidy_up(&(usbduxsub[index]));
up(&start_stop_sem); up(&start_stop_sem);
return -ENOMEM; return -ENOMEM;
} }
usbduxsub[index].urbPwm->transfer_buffer = devpriv->urbPwm = urb;
kzalloc(usbduxsub[index].sizePwmBuf, GFP_KERNEL); urb->transfer_buffer = kzalloc(devpriv->sizePwmBuf, GFP_KERNEL);
if (!(usbduxsub[index].urbPwm->transfer_buffer)) { if (!urb->transfer_buffer) {
tidy_up(&(usbduxsub[index])); tidy_up(devpriv);
up(&start_stop_sem); up(&start_stop_sem);
return -ENOMEM; return -ENOMEM;
} }
} else { } else {
usbduxsub[index].urbPwm = NULL; devpriv->urbPwm = NULL;
usbduxsub[index].sizePwmBuf = 0; devpriv->sizePwmBuf = 0;
} }
usbduxsub[index].ai_cmd_running = 0; devpriv->ai_cmd_running = 0;
usbduxsub[index].ao_cmd_running = 0; devpriv->ao_cmd_running = 0;
usbduxsub[index].pwm_cmd_running = 0; devpriv->pwm_cmd_running = 0;
/* we've reached the bottom of the function */ /* we've reached the bottom of the function */
usbduxsub[index].probed = 1; devpriv->probed = 1;
up(&start_stop_sem); up(&start_stop_sem);
return comedi_usb_auto_config(uinterf, &usbduxsigma_driver, 0);; return comedi_usb_auto_config(intf, &usbduxsigma_driver, 0);;
} }
static void usbduxsigma_usb_disconnect(struct usb_interface *intf) static void usbduxsigma_usb_disconnect(struct usb_interface *intf)
......
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