From: H Hartley Sweeten Date: Fri, 20 Sep 2013 23:40:01 +0000 (-0700) Subject: staging: comedi: pcl711: fix pcl711_set_changain() X-Git-Url: https://git.karo-electronics.de/?a=commitdiff_plain;h=fe4489a5b2047c94ce0ce80b21e2aa3d4b657c0a;p=linux-beck.git staging: comedi: pcl711: fix pcl711_set_changain() Currently the board->is_8112 handling in this function does not write the value to the mux register. Also, the value for channels >= 8 is calculated incorrectly. Define the magic numbers used with the mux register and fix the function so 8112 boards work correctly. Signed-off-by: H Hartley Sweeten Reviewed-by: Ian Abbott Signed-off-by: Greg Kroah-Hartman --- diff --git a/drivers/staging/comedi/drivers/pcl711.c b/drivers/staging/comedi/drivers/pcl711.c index aab3d731faa2..8aa3d9264c12 100644 --- a/drivers/staging/comedi/drivers/pcl711.c +++ b/drivers/staging/comedi/drivers/pcl711.c @@ -78,7 +78,10 @@ supported. #define PCL711_DI_HI 0x07 #define PCL711_CLRINTR 0x08 #define PCL711_GAIN 0x09 -#define PCL711_MUX 0x0a +#define PCL711_MUX_REG 0x0a +#define PCL711_MUX_CHAN(x) (((x) & 0xf) << 0) +#define PCL711_MUX_CS0 (1 << 4) +#define PCL711_MUX_CS1 (1 << 5) #define PCL711_MODE 0x0b #define PCL711_SOFTTRIG 0x0c #define PCL711_DO_LO 0x0d @@ -220,32 +223,24 @@ static irqreturn_t pcl711_interrupt(int irq, void *d) return IRQ_HANDLED; } -static void pcl711_set_changain(struct comedi_device *dev, int chan) +static void pcl711_set_changain(struct comedi_device *dev, + unsigned int chanspec) { const struct pcl711_board *board = comedi_board(dev); - int chan_register; + unsigned int chan = CR_CHAN(chanspec); + unsigned int range = CR_RANGE(chanspec); + unsigned int mux = 0; - outb(CR_RANGE(chan), dev->iobase + PCL711_GAIN); - - chan_register = CR_CHAN(chan); + outb(range, dev->iobase + PCL711_GAIN); if (board->is_8112) { - - /* - * Set the correct channel. The two channel banks are switched - * using the mask value. - * NB: To use differential channels, you should use - * mask = 0x30, but I haven't written the support for this - * yet. /JJ - */ - - if (chan_register >= 8) - chan_register = 0x20 | (chan_register & 0x7); + /* Select the correct MPC508A chip */ + if (chan < 8) + mux |= PCL711_MUX_CS0; else - chan_register |= 0x10; - } else { - outb(chan_register, dev->iobase + PCL711_MUX); + mux |= PCL711_MUX_CS1; } + outb(mux | PCL711_MUX_CHAN(chan), dev->iobase + PCL711_MUX_REG); } static int pcl711_ai_wait_for_eoc(struct comedi_device *dev,