mirror of
https://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
synced 2026-05-06 00:47:56 -04:00
staging: comedi: usbduxsigma: use attach_usb() hook
Change the usbduxsigma driver to use the new attach_usb() hook in struct comedi_driver to auto-configure probed USB devices after the firmware is loaded. Move the release of the driver's static 'start_stop_sem' semaphore in usbduxsigma_attach() to occur a bit later for convenience, otherwise the new usbduxsigma_attach_common() would need to be split in two. I don't think the slight delay in releasing the semaphore matters too much; it's only used in the USB probe and disconnect functions and when attaching and detaching comedi devices. Signed-off-by: Ian Abbott <abbotti@mev.co.uk> Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
This commit is contained in:
committed by
Greg Kroah-Hartman
parent
f7d4d3bc0c
commit
60ff461067
@@ -2634,72 +2634,35 @@ static void usbduxsigma_disconnect(struct usb_interface *intf)
|
|||||||
dev_info(&intf->dev, "comedi_: disconnected from the usb\n");
|
dev_info(&intf->dev, "comedi_: disconnected from the usb\n");
|
||||||
}
|
}
|
||||||
|
|
||||||
/* is called when comedi-config is called */
|
/* common part of attach and attach_usb */
|
||||||
static int usbduxsigma_attach(struct comedi_device *dev,
|
static int usbduxsigma_attach_common(struct comedi_device *dev,
|
||||||
struct comedi_devconfig *it)
|
struct usbduxsub *uds,
|
||||||
|
void *aux_data, int aux_len)
|
||||||
{
|
{
|
||||||
int ret;
|
int ret;
|
||||||
int index;
|
struct comedi_subdevice *s;
|
||||||
int i;
|
|
||||||
struct usbduxsub *udev;
|
|
||||||
int n_subdevs;
|
int n_subdevs;
|
||||||
|
|
||||||
int offset;
|
int offset;
|
||||||
|
|
||||||
struct comedi_subdevice *s = NULL;
|
down(&uds->sem);
|
||||||
dev->private = NULL;
|
|
||||||
|
|
||||||
down(&start_stop_sem);
|
|
||||||
/* find a valid device which has been detected by the probe function of
|
|
||||||
* the usb */
|
|
||||||
index = -1;
|
|
||||||
for (i = 0; i < NUMUSBDUX; i++) {
|
|
||||||
if ((usbduxsub[i].probed) && (!usbduxsub[i].attached)) {
|
|
||||||
index = i;
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
if (index < 0) {
|
|
||||||
printk(KERN_ERR "comedi%d: usbduxsigma: error: attach failed,"
|
|
||||||
"dev not connected to the usb bus.\n", dev->minor);
|
|
||||||
up(&start_stop_sem);
|
|
||||||
return -ENODEV;
|
|
||||||
}
|
|
||||||
|
|
||||||
udev = &usbduxsub[index];
|
|
||||||
down(&udev->sem);
|
|
||||||
/* pointer back to the corresponding comedi device */
|
/* pointer back to the corresponding comedi device */
|
||||||
udev->comedidev = dev;
|
uds->comedidev = dev;
|
||||||
|
|
||||||
/* trying to upload the firmware into the FX2 */
|
/* trying to upload the firmware into the FX2 */
|
||||||
if (comedi_aux_data(it->options, 0) &&
|
if (aux_data)
|
||||||
it->options[COMEDI_DEVCONF_AUX_DATA_LENGTH]) {
|
firmwareUpload(uds, aux_data, aux_len);
|
||||||
firmwareUpload(udev, comedi_aux_data(it->options, 0),
|
|
||||||
it->options[COMEDI_DEVCONF_AUX_DATA_LENGTH]);
|
|
||||||
}
|
|
||||||
|
|
||||||
dev->board_name = BOARDNAME;
|
dev->board_name = BOARDNAME;
|
||||||
|
|
||||||
/* set number of subdevices */
|
/* set number of subdevices */
|
||||||
if (udev->high_speed) {
|
if (uds->high_speed)
|
||||||
/* with pwm */
|
n_subdevs = 4; /* with pwm */
|
||||||
n_subdevs = 4;
|
else
|
||||||
} else {
|
n_subdevs = 3; /* without pwm */
|
||||||
/* without pwm */
|
|
||||||
n_subdevs = 3;
|
|
||||||
}
|
|
||||||
|
|
||||||
ret = comedi_alloc_subdevices(dev, n_subdevs);
|
ret = comedi_alloc_subdevices(dev, n_subdevs);
|
||||||
if (ret) {
|
if (ret) {
|
||||||
up(&udev->sem);
|
up(&uds->sem);
|
||||||
up(&start_stop_sem);
|
|
||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* private structure is also simply the usb-structure */
|
/* private structure is also simply the usb-structure */
|
||||||
dev->private = udev;
|
dev->private = uds;
|
||||||
|
|
||||||
/* the first subdevice is the A/D converter */
|
/* the first subdevice is the A/D converter */
|
||||||
s = dev->subdevices + SUBDEV_AD;
|
s = dev->subdevices + SUBDEV_AD;
|
||||||
/* the URBs get the comedi subdevice */
|
/* the URBs get the comedi subdevice */
|
||||||
@@ -2727,8 +2690,7 @@ static int usbduxsigma_attach(struct comedi_device *dev,
|
|||||||
s->maxdata = 0x00FFFFFF;
|
s->maxdata = 0x00FFFFFF;
|
||||||
/* range table to convert to physical units */
|
/* range table to convert to physical units */
|
||||||
s->range_table = (&range_usbdux_ai_range);
|
s->range_table = (&range_usbdux_ai_range);
|
||||||
|
/* analog output subdevice */
|
||||||
/* analog out */
|
|
||||||
s = dev->subdevices + SUBDEV_DA;
|
s = dev->subdevices + SUBDEV_DA;
|
||||||
/* analog out */
|
/* analog out */
|
||||||
s->type = COMEDI_SUBD_AO;
|
s->type = COMEDI_SUBD_AO;
|
||||||
@@ -2753,8 +2715,7 @@ static int usbduxsigma_attach(struct comedi_device *dev,
|
|||||||
s->cancel = usbdux_ao_cancel;
|
s->cancel = usbdux_ao_cancel;
|
||||||
s->insn_read = usbdux_ao_insn_read;
|
s->insn_read = usbdux_ao_insn_read;
|
||||||
s->insn_write = usbdux_ao_insn_write;
|
s->insn_write = usbdux_ao_insn_write;
|
||||||
|
/* digital I/O subdevice */
|
||||||
/* digital I/O */
|
|
||||||
s = dev->subdevices + SUBDEV_DIO;
|
s = dev->subdevices + SUBDEV_DIO;
|
||||||
s->type = COMEDI_SUBD_DIO;
|
s->type = COMEDI_SUBD_DIO;
|
||||||
s->subdev_flags = SDF_READABLE | SDF_WRITABLE;
|
s->subdev_flags = SDF_READABLE | SDF_WRITABLE;
|
||||||
@@ -2766,39 +2727,96 @@ static int usbduxsigma_attach(struct comedi_device *dev,
|
|||||||
s->insn_config = usbdux_dio_insn_config;
|
s->insn_config = usbdux_dio_insn_config;
|
||||||
/* we don't use it */
|
/* we don't use it */
|
||||||
s->private = NULL;
|
s->private = NULL;
|
||||||
|
if (uds->high_speed) {
|
||||||
if (udev->high_speed) {
|
/* timer / pwm subdevice */
|
||||||
/* timer / pwm */
|
|
||||||
s = dev->subdevices + SUBDEV_PWM;
|
s = dev->subdevices + SUBDEV_PWM;
|
||||||
s->type = COMEDI_SUBD_PWM;
|
s->type = COMEDI_SUBD_PWM;
|
||||||
s->subdev_flags = SDF_WRITABLE | SDF_PWM_HBRIDGE;
|
s->subdev_flags = SDF_WRITABLE | SDF_PWM_HBRIDGE;
|
||||||
s->n_chan = 8;
|
s->n_chan = 8;
|
||||||
/* this defines the max duty cycle resolution */
|
/* this defines the max duty cycle resolution */
|
||||||
s->maxdata = udev->sizePwmBuf;
|
s->maxdata = uds->sizePwmBuf;
|
||||||
s->insn_write = usbdux_pwm_write;
|
s->insn_write = usbdux_pwm_write;
|
||||||
s->insn_read = usbdux_pwm_read;
|
s->insn_read = usbdux_pwm_read;
|
||||||
s->insn_config = usbdux_pwm_config;
|
s->insn_config = usbdux_pwm_config;
|
||||||
usbdux_pwm_period(dev, s, PWM_DEFAULT_PERIOD);
|
usbdux_pwm_period(dev, s, PWM_DEFAULT_PERIOD);
|
||||||
}
|
}
|
||||||
/* finally decide that it's attached */
|
/* finally decide that it's attached */
|
||||||
udev->attached = 1;
|
uds->attached = 1;
|
||||||
|
up(&uds->sem);
|
||||||
up(&udev->sem);
|
|
||||||
|
|
||||||
up(&start_stop_sem);
|
|
||||||
|
|
||||||
offset = usbdux_getstatusinfo(dev, 0);
|
offset = usbdux_getstatusinfo(dev, 0);
|
||||||
if (offset < 0)
|
if (offset < 0)
|
||||||
dev_err(&udev->interface->dev,
|
dev_err(&uds->interface->dev,
|
||||||
"Communication to USBDUXSIGMA failed!"
|
"Communication to USBDUXSIGMA failed! Check firmware and cabling.");
|
||||||
"Check firmware and cabling.");
|
dev_info(&uds->interface->dev,
|
||||||
|
"comedi%d: attached, ADC_zero = %x\n", dev->minor, offset);
|
||||||
dev_info(&udev->interface->dev,
|
|
||||||
"comedi%d: attached, ADC_zero = %x", dev->minor, offset);
|
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/* is called for COMEDI_DEVCONFIG ioctl (when comedi_config is run) */
|
||||||
|
static int usbduxsigma_attach(struct comedi_device *dev,
|
||||||
|
struct comedi_devconfig *it)
|
||||||
|
{
|
||||||
|
int ret;
|
||||||
|
int index;
|
||||||
|
int i;
|
||||||
|
void *aux_data;
|
||||||
|
int aux_len;
|
||||||
|
|
||||||
|
dev->private = NULL;
|
||||||
|
|
||||||
|
aux_data = comedi_aux_data(it->options, 0);
|
||||||
|
aux_len = it->options[COMEDI_DEVCONF_AUX_DATA_LENGTH];
|
||||||
|
if (aux_data == NULL)
|
||||||
|
aux_len = 0;
|
||||||
|
else if (aux_len == 0)
|
||||||
|
aux_data = NULL;
|
||||||
|
|
||||||
|
down(&start_stop_sem);
|
||||||
|
/* find a valid device which has been detected by the probe function of
|
||||||
|
* the usb */
|
||||||
|
index = -1;
|
||||||
|
for (i = 0; i < NUMUSBDUX; i++) {
|
||||||
|
if ((usbduxsub[i].probed) && (!usbduxsub[i].attached)) {
|
||||||
|
index = i;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if (index < 0) {
|
||||||
|
dev_err(dev->class_dev,
|
||||||
|
"usbduxsigma: error: attach failed, dev not connected to the usb bus.\n");
|
||||||
|
up(&start_stop_sem);
|
||||||
|
ret = -ENODEV;
|
||||||
|
} else
|
||||||
|
ret = usbduxsigma_attach_common(dev, &usbduxsub[index],
|
||||||
|
aux_data, aux_len);
|
||||||
|
up(&start_stop_sem);
|
||||||
|
return ret;
|
||||||
|
}
|
||||||
|
|
||||||
|
/* is called from comedi_usb_auto_config() */
|
||||||
|
static int usbduxsigma_attach_usb(struct comedi_device *dev,
|
||||||
|
struct usb_interface *uinterf)
|
||||||
|
{
|
||||||
|
int ret;
|
||||||
|
struct usbduxsub *uds;
|
||||||
|
|
||||||
|
dev->private = NULL;
|
||||||
|
down(&start_stop_sem);
|
||||||
|
uds = usb_get_intfdata(uinterf);
|
||||||
|
if (!uds || !uds->probed) {
|
||||||
|
dev_err(dev->class_dev,
|
||||||
|
"usbduxsigma: error: attach_usb failed, not connected\n");
|
||||||
|
ret = -ENODEV;
|
||||||
|
} else if (uds->attached) {
|
||||||
|
dev_err(dev->class_dev,
|
||||||
|
"usbduxsigma: error: attach_usb failed, already attached\n");
|
||||||
|
ret = -ENODEV;
|
||||||
|
} else
|
||||||
|
ret = usbduxsigma_attach_common(dev, uds, NULL, 0);
|
||||||
|
up(&start_stop_sem);
|
||||||
|
return ret;
|
||||||
|
}
|
||||||
|
|
||||||
static void usbduxsigma_detach(struct comedi_device *dev)
|
static void usbduxsigma_detach(struct comedi_device *dev)
|
||||||
{
|
{
|
||||||
struct usbduxsub *usb = dev->private;
|
struct usbduxsub *usb = dev->private;
|
||||||
@@ -2818,6 +2836,7 @@ static struct comedi_driver driver_usbduxsigma = {
|
|||||||
.module = THIS_MODULE,
|
.module = THIS_MODULE,
|
||||||
.attach = usbduxsigma_attach,
|
.attach = usbduxsigma_attach,
|
||||||
.detach = usbduxsigma_detach,
|
.detach = usbduxsigma_detach,
|
||||||
|
.attach_usb = usbduxsigma_attach_usb,
|
||||||
};
|
};
|
||||||
|
|
||||||
/* Table with the USB-devices */
|
/* Table with the USB-devices */
|
||||||
|
|||||||
Reference in New Issue
Block a user