From: H Hartley Sweeten Date: Wed, 25 Sep 2013 22:37:43 +0000 (-0700) Subject: staging: comedi: pcl726: tidy up pcl726_attach() X-Git-Url: https://git.karo-electronics.de/?a=commitdiff_plain;h=47825a9b1b37b38cca1891e5393da4b13155f165;p=linux-beck.git staging: comedi: pcl726: tidy up pcl726_attach() For aesthetics, add some whitespace to the subdevice initialization. Only allocate, and initialize, the digital input and output subdevices if the boardinfo indicates that they exist on the board. Signed-off-by: H Hartley Sweeten Reviewed-by: Ian Abbott Signed-off-by: Greg Kroah-Hartman --- diff --git a/drivers/staging/comedi/drivers/pcl726.c b/drivers/staging/comedi/drivers/pcl726.c index 7952d8754449..970d44d87b3a 100644 --- a/drivers/staging/comedi/drivers/pcl726.c +++ b/drivers/staging/comedi/drivers/pcl726.c @@ -253,12 +253,14 @@ static int pcl726_do_insn_bits(struct comedi_device *dev, return insn->n; } -static int pcl726_attach(struct comedi_device *dev, struct comedi_devconfig *it) +static int pcl726_attach(struct comedi_device *dev, + struct comedi_devconfig *it) { const struct pcl726_board *board = comedi_board(dev); struct pcl726_private *devpriv; struct comedi_subdevice *s; - int ret, i; + int ret; + int i; ret = comedi_request_region(dev, it->options[0], board->io_range); if (ret) @@ -291,47 +293,38 @@ static int pcl726_attach(struct comedi_device *dev, struct comedi_devconfig *it) devpriv->rangelist[i] = &range_unknown; } - ret = comedi_alloc_subdevices(dev, 3); + ret = comedi_alloc_subdevices(dev, board->have_dio ? 3 : 1); if (ret) return ret; + /* Analog Output subdevice */ s = &dev->subdevices[0]; - /* ao */ - s->type = COMEDI_SUBD_AO; - s->subdev_flags = SDF_WRITABLE | SDF_GROUND; - s->n_chan = board->n_aochan; - s->maxdata = 0xfff; - s->len_chanlist = 1; - s->insn_write = pcl726_ao_insn_write; - s->insn_read = pcl726_ao_insn_read; + s->type = COMEDI_SUBD_AO; + s->subdev_flags = SDF_WRITABLE | SDF_GROUND; + s->n_chan = board->n_aochan; + s->maxdata = 0x0fff; s->range_table_list = devpriv->rangelist; - - s = &dev->subdevices[1]; - /* di */ - if (!board->have_dio) { - s->type = COMEDI_SUBD_UNUSED; - } else { - s->type = COMEDI_SUBD_DI; - s->subdev_flags = SDF_READABLE | SDF_GROUND; - s->n_chan = 16; - s->maxdata = 1; - s->len_chanlist = 1; - s->insn_bits = pcl726_di_insn_bits; - s->range_table = &range_digital; - } - - s = &dev->subdevices[2]; - /* do */ - if (!board->have_dio) { - s->type = COMEDI_SUBD_UNUSED; - } else { - s->type = COMEDI_SUBD_DO; - s->subdev_flags = SDF_WRITABLE | SDF_GROUND; - s->n_chan = 16; - s->maxdata = 1; - s->len_chanlist = 1; - s->insn_bits = pcl726_do_insn_bits; - s->range_table = &range_digital; + s->insn_write = pcl726_ao_insn_write; + s->insn_read = pcl726_ao_insn_read; + + if (board->have_dio) { + /* Digital Input subdevice */ + s = &dev->subdevices[1]; + s->type = COMEDI_SUBD_DI; + s->subdev_flags = SDF_READABLE; + s->n_chan = 16; + s->maxdata = 1; + s->insn_bits = pcl726_di_insn_bits; + s->range_table = &range_digital; + + /* Digital Output subdevice */ + s = &dev->subdevices[2]; + s->type = COMEDI_SUBD_DO; + s->subdev_flags = SDF_WRITABLE; + s->n_chan = 16; + s->maxdata = 1; + s->insn_bits = pcl726_do_insn_bits; + s->range_table = &range_digital; } return 0;