提交 dba89b14 编写于 作者: H H Hartley Sweeten 提交者: Greg Kroah-Hartman

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: NH Hartley Sweeten <hsweeten@visionengravers.com>
Cc: Ian Abbott <abbotti@mev.co.uk>
Cc: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
Signed-off-by: NGreg Kroah-Hartman <gregkh@linuxfoundation.org>
上级 8bee2dea
......@@ -367,24 +367,22 @@ static int unioxx5_insn_config(struct comedi_device *dev,
}
/* initializing subdevice with given address */
static int __unioxx5_subdev_init(struct comedi_subdevice *subdev,
int subdev_iobase, int minor)
static int __unioxx5_subdev_init(struct comedi_device *dev,
struct comedi_subdevice *s,
int iobase)
{
struct unioxx5_subd_priv *usp;
int i, to, ndef_flag = 0;
int ret;
if (!request_region(subdev_iobase, UNIOXX5_SIZE, DRIVER_NAME)) {
dev_err(subdev->class_dev,
"comedi%d: I/O port conflict\n", minor);
return -EIO;
}
ret = __comedi_request_region(dev, iobase, UNIOXX5_SIZE);
if (ret)
return ret;
usp->usp_iobase = iobase;
usp = kzalloc(sizeof(*usp), GFP_KERNEL);
if (usp == NULL)
return -1;
usp->usp_iobase = subdev_iobase;
dev_info(subdev->class_dev, "comedi%d: |", minor);
return -ENOMEM;
/* defining modules types */
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);
/* sends channel number to card */
outb(i + 1, subdev_iobase + 5);
outb('H', subdev_iobase + 6); /* requests EEPROM world */
while (!(inb(subdev_iobase + 0) & TxBE))
outb(i + 1, iobase + 5);
outb('H', iobase + 6); /* requests EEPROM world */
while (!(inb(iobase + 0) & TxBE))
; /* waits while writting will be allowed */
outb(0, subdev_iobase + 6);
outb(0, iobase + 6);
/* waits while reading of two bytes will be allowed */
while (!(inb(subdev_iobase + 0) & Rx2CA)) {
while (!(inb(iobase + 0) & Rx2CA)) {
if (--to <= 0) {
ndef_flag = 1;
break;
......@@ -410,25 +408,22 @@ static int __unioxx5_subdev_init(struct comedi_subdevice *subdev,
usp->usp_module_type[i] = 0;
ndef_flag = 0;
} 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);
}
printk("\n");
/* initial subdevice for digital or analog i/o */
subdev->type = COMEDI_SUBD_DIO;
subdev->private = usp;
subdev->subdev_flags = SDF_READABLE | SDF_WRITABLE;
subdev->n_chan = UNIOXX5_NUM_OF_CHANS;
subdev->maxdata = 0xFFF;
subdev->range_table = &range_digital;
subdev->insn_read = unioxx5_subdev_read;
subdev->insn_write = unioxx5_subdev_write;
s->type = COMEDI_SUBD_DIO;
s->private = usp;
s->subdev_flags = SDF_READABLE | SDF_WRITABLE;
s->n_chan = UNIOXX5_NUM_OF_CHANS;
s->maxdata = 0xFFF;
s->range_table = &range_digital;
s->insn_read = unioxx5_subdev_read;
s->insn_write = unioxx5_subdev_write;
/* for digital modules only!!! */
subdev->insn_config = unioxx5_insn_config;
s->insn_config = unioxx5_insn_config;
return 0;
}
......@@ -436,6 +431,7 @@ static int __unioxx5_subdev_init(struct comedi_subdevice *subdev,
static int unioxx5_attach(struct comedi_device *dev,
struct comedi_devconfig *it)
{
struct comedi_subdevice *s;
int iobase, i, n_subd;
int id, num, ba;
int ret;
......@@ -469,9 +465,10 @@ static int unioxx5_attach(struct comedi_device *dev,
/* initializing each of for same subdevices */
for (i = 0; i < n_subd; i++, iobase += UNIOXX5_SUBDEV_ODDS) {
if (__unioxx5_subdev_init(&dev->subdevices[i], iobase,
dev->minor) < 0)
return -1;
s = &dev->subdevices[i];
ret = __unioxx5_subdev_init(dev, s, iobase);
if (ret)
return ret;
}
return 0;
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册