From: H Hartley Sweeten Date: Mon, 10 Mar 2014 21:07:31 +0000 (-0700) Subject: staging: comedi: c6xdigio: introduce c6xdigio_write_data() X-Git-Url: http://git.lede-project.org./?a=commitdiff_plain;h=6d758307ee8929e86e2da09826c525ba4af05f1e;p=openwrt%2Fstaging%2Fblogic.git staging: comedi: c6xdigio: introduce c6xdigio_write_data() All writes to the hardware involve writing the the data register then checking the status register. Introduce a helper function to handle this. Signed-off-by: H Hartley Sweeten Reviewed-by: Ian Abbott Signed-off-by: Greg Kroah-Hartman --- diff --git a/drivers/staging/comedi/drivers/c6xdigio.c b/drivers/staging/comedi/drivers/c6xdigio.c index d1860f67d63a..2189e5bc316f 100644 --- a/drivers/staging/comedi/drivers/c6xdigio.c +++ b/drivers/staging/comedi/drivers/c6xdigio.c @@ -92,19 +92,19 @@ static int c6xdigio_chk_status(struct comedi_device *dev, unsigned long context) return -EBUSY; } -static void c6xdigio_pwm_init(struct comedi_device *dev) +static int c6xdigio_write_data(struct comedi_device *dev, + unsigned int val, unsigned int status) { - outb_p(0x70, dev->iobase); - c6xdigio_chk_status(dev, 0x00); - - outb_p(0x74, dev->iobase); - c6xdigio_chk_status(dev, 0x80); - - outb_p(0x70, dev->iobase); - c6xdigio_chk_status(dev, 0x00); + outb_p(val, dev->iobase); + return c6xdigio_chk_status(dev, status); +} - outb_p(0x0, dev->iobase); - c6xdigio_chk_status(dev, 0x80); +static void c6xdigio_pwm_init(struct comedi_device *dev) +{ + c6xdigio_write_data(dev, 0x70, 0x00); + c6xdigio_write_data(dev, 0x74, 0x80); + c6xdigio_write_data(dev, 0x70, 0x00); + c6xdigio_write_data(dev, 0x00, 0x80); } static void c6xdigio_pwm_write(struct comedi_device *dev, @@ -124,23 +124,12 @@ static void c6xdigio_pwm_write(struct comedi_device *dev, else ppcmd = 0x30; - outb_p(ppcmd + pwm.bits.sb0, dev->iobase); - c6xdigio_chk_status(dev, 0x00); - - outb_p(ppcmd + pwm.bits.sb1 + 0x4, dev->iobase); - c6xdigio_chk_status(dev, 0x80); - - outb_p(ppcmd + pwm.bits.sb2, dev->iobase); - c6xdigio_chk_status(dev, 0x00); - - outb_p(ppcmd + pwm.bits.sb3 + 0x4, dev->iobase); - c6xdigio_chk_status(dev, 0x80); - - outb_p(ppcmd + pwm.bits.sb4, dev->iobase); - c6xdigio_chk_status(dev, 0x00); - - outb_p(0x0, dev->iobase); - c6xdigio_chk_status(dev, 0x80); + c6xdigio_write_data(dev, ppcmd + pwm.bits.sb0, 0x00); + c6xdigio_write_data(dev, ppcmd + pwm.bits.sb1 + 0x4, 0x80); + c6xdigio_write_data(dev, ppcmd + pwm.bits.sb2, 0x00); + c6xdigio_write_data(dev, ppcmd + pwm.bits.sb3 + 0x4, 0x80); + c6xdigio_write_data(dev, ppcmd + pwm.bits.sb4, 0x00); + c6xdigio_write_data(dev, 0x00, 0x80); } static int c6xdigio_encoder_read(struct comedi_device *dev, @@ -155,60 +144,43 @@ static int c6xdigio_encoder_read(struct comedi_device *dev, else ppcmd = 0x50; - outb_p(ppcmd, dev->iobase); - c6xdigio_chk_status(dev, 0x00); + c6xdigio_write_data(dev, ppcmd, 0x00); enc.bits.sb0 = ((inb(dev->iobase + 1) >> 3) & 0x7); - outb_p(ppcmd + 0x4, dev->iobase); - c6xdigio_chk_status(dev, 0x80); + c6xdigio_write_data(dev, ppcmd + 0x4, 0x80); enc.bits.sb1 = ((inb(dev->iobase + 1) >> 3) & 0x7); - outb_p(ppcmd, dev->iobase); - c6xdigio_chk_status(dev, 0x00); + c6xdigio_write_data(dev, ppcmd, 0x00); enc.bits.sb2 = ((inb(dev->iobase + 1) >> 3) & 0x7); - outb_p(ppcmd + 0x4, dev->iobase); - c6xdigio_chk_status(dev, 0x80); + c6xdigio_write_data(dev, ppcmd + 0x4, 0x80); enc.bits.sb3 = ((inb(dev->iobase + 1) >> 3) & 0x7); - outb_p(ppcmd, dev->iobase); - c6xdigio_chk_status(dev, 0x00); + c6xdigio_write_data(dev, ppcmd, 0x00); enc.bits.sb4 = ((inb(dev->iobase + 1) >> 3) & 0x7); - outb_p(ppcmd + 0x4, dev->iobase); - c6xdigio_chk_status(dev, 0x80); + c6xdigio_write_data(dev, ppcmd + 0x4, 0x80); enc.bits.sb5 = ((inb(dev->iobase + 1) >> 3) & 0x7); - outb_p(ppcmd, dev->iobase); - c6xdigio_chk_status(dev, 0x00); + c6xdigio_write_data(dev, ppcmd, 0x00); enc.bits.sb6 = ((inb(dev->iobase + 1) >> 3) & 0x7); - outb_p(ppcmd + 0x4, dev->iobase); - c6xdigio_chk_status(dev, 0x80); + c6xdigio_write_data(dev, ppcmd + 0x4, 0x80); enc.bits.sb7 = ((inb(dev->iobase + 1) >> 3) & 0x7); - outb_p(ppcmd, dev->iobase); - c6xdigio_chk_status(dev, 0x00); + c6xdigio_write_data(dev, ppcmd, 0x00); - outb_p(0x0, dev->iobase); - c6xdigio_chk_status(dev, 0x80); + c6xdigio_write_data(dev, 0x00, 0x80); return enc.value ^ 0x800000; } static void c6xdigio_encoder_reset(struct comedi_device *dev) { - outb_p(0x68, dev->iobase); - c6xdigio_chk_status(dev, 0x00); - - outb_p(0x6c, dev->iobase); - c6xdigio_chk_status(dev, 0x80); - - outb_p(0x68, dev->iobase); - c6xdigio_chk_status(dev, 0x00); - - outb_p(0x0, dev->iobase); - c6xdigio_chk_status(dev, 0x80); + c6xdigio_write_data(dev, 0x68, 0x00); + c6xdigio_write_data(dev, 0x6c, 0x80); + c6xdigio_write_data(dev, 0x68, 0x00); + c6xdigio_write_data(dev, 0x00, 0x80); } static int c6xdigio_pwmo_insn_write(struct comedi_device *dev,