From: H Hartley Sweeten Date: Mon, 17 Feb 2014 21:27:57 +0000 (-0700) Subject: staging: comedi: pcl818: tidy up pcl818_check() X-Git-Tag: firefly_0821_release~176^2~4193^2~932 X-Git-Url: http://demsky.eecs.uci.edu/git/?a=commitdiff_plain;h=243e7146c8ed16cbda71126168fe73acab7c62d2;p=firefly-linux-kernel-4.4.55.git staging: comedi: pcl818: tidy up pcl818_check() This function probes a number of the boards registers during the (*attach) to verify that it is actually a PCL-818 compatible board. For aesthetics, move the function closer to the (*attach). Refactor the function to return an errno if fails. Change the errno from -EIO to -ENODEV and remove the unnecessary comedi_error() noise. Make sure the CONTROL register is reset to a known state after the check. The 0x18 value actually defines an invalid interrupt selection and sets an undefined bit. Add a couple comments to clarify the magic values. Signed-off-by: H Hartley Sweeten Reviewed-by: Ian Abbott Signed-off-by: Greg Kroah-Hartman --- diff --git a/drivers/staging/comedi/drivers/pcl818.c b/drivers/staging/comedi/drivers/pcl818.c index 65101970f99e..56a5de712e87 100644 --- a/drivers/staging/comedi/drivers/pcl818.c +++ b/drivers/staging/comedi/drivers/pcl818.c @@ -1082,25 +1082,6 @@ end: return 0; } -static int pcl818_check(unsigned long iobase) -{ - outb(0x00, iobase + PCL818_MUX); - udelay(1); - if (inb(iobase + PCL818_MUX) != 0x00) - return 1; /* there isn't card */ - outb(0x55, iobase + PCL818_MUX); - udelay(1); - if (inb(iobase + PCL818_MUX) != 0x55) - return 1; /* there isn't card */ - outb(0x00, iobase + PCL818_MUX); - udelay(1); - outb(0x18, iobase + PCL818_CONTROL); - udelay(1); - if (inb(iobase + PCL818_CONTROL) != 0x18) - return 1; /* there isn't card */ - return 0; /* ok, card exist */ -} - static void pcl818_reset(struct comedi_device *dev) { const struct pcl818_board *board = comedi_board(dev); @@ -1187,6 +1168,30 @@ static void pcl818_set_ai_range_table(struct comedi_device *dev, } } +static int pcl818_check(struct comedi_device *dev) +{ + /* the MUX register should return the same value written */ + outb(0x00, dev->iobase + PCL818_MUX); + if (inb(dev->iobase + PCL818_MUX) != 0x00) + return -ENODEV; + outb(0x55, dev->iobase + PCL818_MUX); + if (inb(dev->iobase + PCL818_MUX) != 0x55) + return -ENODEV; + + /* reset the MUX register to a known state */ + outb(0x00, dev->iobase + PCL818_MUX); + + /* the CONTROL register should return the same value written */ + outb(0x18, dev->iobase + PCL818_CONTROL); + if (inb(dev->iobase + PCL818_CONTROL) != 0x18) + return -ENODEV; + + /* reset the CONTROL register to a known state */ + outb(0x00, dev->iobase + PCL818_CONTROL); + + return 0; +} + static int pcl818_attach(struct comedi_device *dev, struct comedi_devconfig *it) { const struct pcl818_board *board = comedi_board(dev); @@ -1208,10 +1213,9 @@ static int pcl818_attach(struct comedi_device *dev, struct comedi_devconfig *it) if (ret) return ret; - if (pcl818_check(dev->iobase)) { - comedi_error(dev, "I can't detect board. FAIL!\n"); - return -EIO; - } + ret = pcl818_check(dev); + if (ret) + return ret; /* we can use IRQ 2-7 for async command support */ if (it->options[1] >= 2 && it->options[1] <= 7) {