From 953a36c45aa4ba23be687451df6311ad33d89538 Mon Sep 17 00:00:00 2001 From: H Hartley Sweeten Date: Wed, 23 Jan 2013 12:37:16 -0700 Subject: [PATCH] staging: comedi: addi_apci_3501: cleanup the digital output subdevice The board supported by this driver has 2 digital outputs. Remove the conditional and always init the subdevice. Also, move the subdevice insn_bits function pointer as well as the n_chan out of the boardinfo and use them to initialize the subdevice directly. Since devpriv->s_EeParameters for the digital output subdevice are no longer being used, remove initialization of them also. Copy the apci3501_do_insn_bits() function from hwrdv_apci3501.c into the main driver file. Fix the subdev_flags for the subdevice. The only required flag is SDF_WRITEABLE. The SDF_GROUND and SDF_COMMON flags only have meaning for analog subdevices and the SDF_READABLE flag is not required. Fix the maxdata for the subdevice. Digital outputs can only be 1 or 0. Remove the len_chanlist initialization, it only has meaning for subdevices that support commands. Remove the io_bits initialization, it only has meaning for digital i/o subdevices that have configurable outputs. Signed-off-by: H Hartley Sweeten Cc: Ian Abbott Signed-off-by: Greg Kroah-Hartman --- .../comedi/drivers/addi-data/hwdrv_apci3501.c | 22 -------- .../staging/comedi/drivers/addi_apci_3501.c | 55 ++++++++++--------- 2 files changed, 30 insertions(+), 47 deletions(-) diff --git a/drivers/staging/comedi/drivers/addi-data/hwdrv_apci3501.c b/drivers/staging/comedi/drivers/addi-data/hwdrv_apci3501.c index 7a18ce704ba4..c7abe85c59f7 100644 --- a/drivers/staging/comedi/drivers/addi-data/hwdrv_apci3501.c +++ b/drivers/staging/comedi/drivers/addi-data/hwdrv_apci3501.c @@ -96,28 +96,6 @@ static int apci3501_di_insn_bits(struct comedi_device *dev, return insn->n; } -static int apci3501_do_insn_bits(struct comedi_device *dev, - struct comedi_subdevice *s, - struct comedi_insn *insn, - unsigned int *data) -{ - struct addi_private *devpriv = dev->private; - unsigned int mask = data[0]; - unsigned int bits = data[1]; - - s->state = inl(devpriv->iobase + APCI3501_DIGITAL_OP); - if (mask) { - s->state &= ~mask; - s->state |= (bits & mask); - - outl(s->state, devpriv->iobase + APCI3501_DIGITAL_OP); - } - - data[1] = s->state; - - return insn->n; -} - /* +----------------------------------------------------------------------------+ | Function Name : int i_APCI3501_ConfigAnalogOutput | diff --git a/drivers/staging/comedi/drivers/addi_apci_3501.c b/drivers/staging/comedi/drivers/addi_apci_3501.c index 725bfdec4cfb..8ea3838165bf 100644 --- a/drivers/staging/comedi/drivers/addi_apci_3501.c +++ b/drivers/staging/comedi/drivers/addi_apci_3501.c @@ -19,17 +19,36 @@ static const struct addi_board apci3501_boardtypes[] = { .i_AoMaxdata = 16383, .pr_AoRangelist = &range_apci3501_ao, .i_NbrDiChannel = 2, - .i_NbrDoChannel = 2, - .i_DoMaxdata = 0x3, .interrupt = v_APCI3501_Interrupt, .reset = i_APCI3501_Reset, .ao_config = i_APCI3501_ConfigAnalogOutput, .ao_write = i_APCI3501_WriteAnalogOutput, .di_bits = apci3501_di_insn_bits, - .do_bits = apci3501_do_insn_bits, }, }; +static int apci3501_do_insn_bits(struct comedi_device *dev, + struct comedi_subdevice *s, + struct comedi_insn *insn, + unsigned int *data) +{ + struct addi_private *devpriv = dev->private; + unsigned int mask = data[0]; + unsigned int bits = data[1]; + + s->state = inl(devpriv->iobase + APCI3501_DIGITAL_OP); + if (mask) { + s->state &= ~mask; + s->state |= (bits & mask); + + outl(s->state, devpriv->iobase + APCI3501_DIGITAL_OP); + } + + data[1] = s->state; + + return insn->n; +} + static int i_ADDIDATA_InsnReadEeprom(struct comedi_device *dev, struct comedi_subdevice *s, struct comedi_insn *insn, @@ -132,8 +151,6 @@ static int apci3501_auto_attach(struct comedi_device *dev, devpriv->s_EeParameters.i_AiMaxdata = this_board->i_AiMaxdata; devpriv->s_EeParameters.i_AoMaxdata = this_board->i_AoMaxdata; devpriv->s_EeParameters.i_NbrDiChannel = this_board->i_NbrDiChannel; - devpriv->s_EeParameters.i_NbrDoChannel = this_board->i_NbrDoChannel; - devpriv->s_EeParameters.i_DoMaxdata = this_board->i_DoMaxdata; devpriv->s_EeParameters.i_Dma = this_board->i_Dma; devpriv->s_EeParameters.ui_MinAcquisitiontimeNs = this_board->ui_MinAcquisitiontimeNs; @@ -240,27 +257,15 @@ static int apci3501_auto_attach(struct comedi_device *dev, } else { s->type = COMEDI_SUBD_UNUSED; } - /* Allocate and Initialise DO Subdevice Structures */ - s = &dev->subdevices[3]; - if (devpriv->s_EeParameters.i_NbrDoChannel) { - s->type = COMEDI_SUBD_DO; - s->subdev_flags = - SDF_READABLE | SDF_WRITEABLE | SDF_GROUND | SDF_COMMON; - s->n_chan = devpriv->s_EeParameters.i_NbrDoChannel; - s->maxdata = devpriv->s_EeParameters.i_DoMaxdata; - s->len_chanlist = - devpriv->s_EeParameters.i_NbrDoChannel; - s->range_table = &range_digital; - s->io_bits = 0xf; /* all bits output */ - /* insn_config - for digital output memory */ - s->insn_config = this_board->do_config; - s->insn_write = this_board->do_write; - s->insn_bits = this_board->do_bits; - s->insn_read = this_board->do_read; - } else { - s->type = COMEDI_SUBD_UNUSED; - } + /* Initialize the digital output subdevice */ + s = &dev->subdevices[3]; + s->type = COMEDI_SUBD_DO; + s->subdev_flags = SDF_WRITEABLE; + s->n_chan = 2; + s->maxdata = 1; + s->range_table = &range_digital; + s->insn_bits = apci3501_do_insn_bits; /* Allocate and Initialise Timer Subdevice Structures */ s = &dev->subdevices[4];