staging: comedi: unionxx5: refactor subdevice init
Change the parameters passed to __unioxx5_subdev_init(), we need the comedi_device pointer to call __comedi_request_region() and the 'minor' is only used in some kernel noise so remove it. Rename the parameters 'subdev' and 'subdev_iobase' to simply 's' and 'iobase'. Use __comedi_request_region() to request the I/O region needed by the subdevice. Remove the attach noise as well as the error message when the request_region() fails, comedi_request_reqion() will output the error message if necessary. Return -ENOMEM is the kzalloc fails instead of -1. Fix unioxx5_attach() to use the new parameters to __unioxx5_subdev_init(). Pass on any error codes instead of -1. Signed-off-by: H Hartley Sweeten <hsweeten@visionengravers.com> Cc: Ian Abbott <abbotti@mev.co.uk> Cc: Greg Kroah-Hartman <gregkh@linuxfoundation.org> Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
This commit is contained in:
parent
8bee2dead8
commit
dba89b14d4
1 changed files with 29 additions and 32 deletions
|
@ -367,24 +367,22 @@ static int unioxx5_insn_config(struct comedi_device *dev,
|
||||||
}
|
}
|
||||||
|
|
||||||
/* initializing subdevice with given address */
|
/* initializing subdevice with given address */
|
||||||
static int __unioxx5_subdev_init(struct comedi_subdevice *subdev,
|
static int __unioxx5_subdev_init(struct comedi_device *dev,
|
||||||
int subdev_iobase, int minor)
|
struct comedi_subdevice *s,
|
||||||
|
int iobase)
|
||||||
{
|
{
|
||||||
struct unioxx5_subd_priv *usp;
|
struct unioxx5_subd_priv *usp;
|
||||||
int i, to, ndef_flag = 0;
|
int i, to, ndef_flag = 0;
|
||||||
|
int ret;
|
||||||
|
|
||||||
if (!request_region(subdev_iobase, UNIOXX5_SIZE, DRIVER_NAME)) {
|
ret = __comedi_request_region(dev, iobase, UNIOXX5_SIZE);
|
||||||
dev_err(subdev->class_dev,
|
if (ret)
|
||||||
"comedi%d: I/O port conflict\n", minor);
|
return ret;
|
||||||
return -EIO;
|
usp->usp_iobase = iobase;
|
||||||
}
|
|
||||||
|
|
||||||
usp = kzalloc(sizeof(*usp), GFP_KERNEL);
|
usp = kzalloc(sizeof(*usp), GFP_KERNEL);
|
||||||
if (usp == NULL)
|
if (usp == NULL)
|
||||||
return -1;
|
return -ENOMEM;
|
||||||
|
|
||||||
usp->usp_iobase = subdev_iobase;
|
|
||||||
dev_info(subdev->class_dev, "comedi%d: |", minor);
|
|
||||||
|
|
||||||
/* defining modules types */
|
/* defining modules types */
|
||||||
for (i = 0; i < 12; i++) {
|
for (i = 0; i < 12; i++) {
|
||||||
|
@ -392,14 +390,14 @@ static int __unioxx5_subdev_init(struct comedi_subdevice *subdev,
|
||||||
|
|
||||||
__unioxx5_analog_config(usp, i * 2);
|
__unioxx5_analog_config(usp, i * 2);
|
||||||
/* sends channel number to card */
|
/* sends channel number to card */
|
||||||
outb(i + 1, subdev_iobase + 5);
|
outb(i + 1, iobase + 5);
|
||||||
outb('H', subdev_iobase + 6); /* requests EEPROM world */
|
outb('H', iobase + 6); /* requests EEPROM world */
|
||||||
while (!(inb(subdev_iobase + 0) & TxBE))
|
while (!(inb(iobase + 0) & TxBE))
|
||||||
; /* waits while writting will be allowed */
|
; /* waits while writting will be allowed */
|
||||||
outb(0, subdev_iobase + 6);
|
outb(0, iobase + 6);
|
||||||
|
|
||||||
/* waits while reading of two bytes will be allowed */
|
/* waits while reading of two bytes will be allowed */
|
||||||
while (!(inb(subdev_iobase + 0) & Rx2CA)) {
|
while (!(inb(iobase + 0) & Rx2CA)) {
|
||||||
if (--to <= 0) {
|
if (--to <= 0) {
|
||||||
ndef_flag = 1;
|
ndef_flag = 1;
|
||||||
break;
|
break;
|
||||||
|
@ -410,25 +408,22 @@ static int __unioxx5_subdev_init(struct comedi_subdevice *subdev,
|
||||||
usp->usp_module_type[i] = 0;
|
usp->usp_module_type[i] = 0;
|
||||||
ndef_flag = 0;
|
ndef_flag = 0;
|
||||||
} else
|
} else
|
||||||
usp->usp_module_type[i] = inb(subdev_iobase + 6);
|
usp->usp_module_type[i] = inb(iobase + 6);
|
||||||
|
|
||||||
printk(" [%d] 0x%02x |", i, usp->usp_module_type[i]);
|
|
||||||
udelay(1);
|
udelay(1);
|
||||||
}
|
}
|
||||||
|
|
||||||
printk("\n");
|
|
||||||
|
|
||||||
/* initial subdevice for digital or analog i/o */
|
/* initial subdevice for digital or analog i/o */
|
||||||
subdev->type = COMEDI_SUBD_DIO;
|
s->type = COMEDI_SUBD_DIO;
|
||||||
subdev->private = usp;
|
s->private = usp;
|
||||||
subdev->subdev_flags = SDF_READABLE | SDF_WRITABLE;
|
s->subdev_flags = SDF_READABLE | SDF_WRITABLE;
|
||||||
subdev->n_chan = UNIOXX5_NUM_OF_CHANS;
|
s->n_chan = UNIOXX5_NUM_OF_CHANS;
|
||||||
subdev->maxdata = 0xFFF;
|
s->maxdata = 0xFFF;
|
||||||
subdev->range_table = &range_digital;
|
s->range_table = &range_digital;
|
||||||
subdev->insn_read = unioxx5_subdev_read;
|
s->insn_read = unioxx5_subdev_read;
|
||||||
subdev->insn_write = unioxx5_subdev_write;
|
s->insn_write = unioxx5_subdev_write;
|
||||||
/* for digital modules only!!! */
|
/* for digital modules only!!! */
|
||||||
subdev->insn_config = unioxx5_insn_config;
|
s->insn_config = unioxx5_insn_config;
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
@ -436,6 +431,7 @@ static int __unioxx5_subdev_init(struct comedi_subdevice *subdev,
|
||||||
static int unioxx5_attach(struct comedi_device *dev,
|
static int unioxx5_attach(struct comedi_device *dev,
|
||||||
struct comedi_devconfig *it)
|
struct comedi_devconfig *it)
|
||||||
{
|
{
|
||||||
|
struct comedi_subdevice *s;
|
||||||
int iobase, i, n_subd;
|
int iobase, i, n_subd;
|
||||||
int id, num, ba;
|
int id, num, ba;
|
||||||
int ret;
|
int ret;
|
||||||
|
@ -469,9 +465,10 @@ static int unioxx5_attach(struct comedi_device *dev,
|
||||||
|
|
||||||
/* initializing each of for same subdevices */
|
/* initializing each of for same subdevices */
|
||||||
for (i = 0; i < n_subd; i++, iobase += UNIOXX5_SUBDEV_ODDS) {
|
for (i = 0; i < n_subd; i++, iobase += UNIOXX5_SUBDEV_ODDS) {
|
||||||
if (__unioxx5_subdev_init(&dev->subdevices[i], iobase,
|
s = &dev->subdevices[i];
|
||||||
dev->minor) < 0)
|
ret = __unioxx5_subdev_init(dev, s, iobase);
|
||||||
return -1;
|
if (ret)
|
||||||
|
return ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
|
|
Loading…
Add table
Reference in a new issue