From ba7834b3f335f6bdef95e416d72245f6687cc660 Mon Sep 17 00:00:00 2001 From: Bill Pemberton Date: Sun, 26 Apr 2009 14:45:12 -0400 Subject: [PATCH] Staging: comedi: simply read and write functions in adl_pci8164 There are several read and write functions in adl_pci8164 that are essentially the same thing. They were created with a cut and paste. Change them to use a common function. Signed-off-by: Bill Pemberton Signed-off-by: Greg Kroah-Hartman --- drivers/staging/comedi/drivers/adl_pci8164.c | 245 ++++--------------- 1 file changed, 46 insertions(+), 199 deletions(-) diff --git a/drivers/staging/comedi/drivers/adl_pci8164.c b/drivers/staging/comedi/drivers/adl_pci8164.c index 2fe577a973a..2d7d68af6b1 100644 --- a/drivers/staging/comedi/drivers/adl_pci8164.c +++ b/drivers/staging/comedi/drivers/adl_pci8164.c @@ -208,8 +208,16 @@ static int adl_pci8164_detach(struct comedi_device *dev) return 0; } -static int adl_pci8164_insn_read_msts(struct comedi_device *dev, struct comedi_subdevice *s, - struct comedi_insn *insn, unsigned int *data) +/* + all the read commands are the same except for the addition a constant + * const to the data for inw() + */ +static void adl_pci8164_insn_read(struct comedi_device *dev, + struct comedi_subdevice *s, + struct comedi_insn *insn, + unsigned int *data, + char *action, + unsigned short offset) { int axis, axis_reg; char *axisname; @@ -238,127 +246,51 @@ static int adl_pci8164_insn_read_msts(struct comedi_device *dev, struct comedi_s axisname = "X"; } - data[0] = inw(dev->iobase + axis_reg + PCI8164_MSTS); - printk("comedi: pci8164 MSTS read -> %04X:%04X on axis %s\n", data[0], + data[0] = inw(dev->iobase + axis_reg + offset); + printk("comedi: pci8164 %s read -> %04X:%04X on axis %s\n", action, data[0], data[1], axisname); +} +static int adl_pci8164_insn_read_msts(struct comedi_device *dev, + struct comedi_subdevice *s, + struct comedi_insn *insn, + unsigned int *data) +{ + adl_pci8164_insn_read(dev, s, insn, data, "MSTS", PCI8164_MSTS); return 2; } static int adl_pci8164_insn_read_ssts(struct comedi_device *dev, struct comedi_subdevice *s, struct comedi_insn *insn, unsigned int *data) { - int axis, axis_reg; - char *axisname; - - axis = CR_CHAN(insn->chanspec); - - switch (axis) { - case 0: - axis_reg = PCI8164_AXIS_X; - axisname = "X"; - break; - case 1: - axis_reg = PCI8164_AXIS_Y; - axisname = "Y"; - break; - case 2: - axis_reg = PCI8164_AXIS_Z; - axisname = "Z"; - break; - case 3: - axis_reg = PCI8164_AXIS_U; - axisname = "U"; - break; - default: - axis_reg = PCI8164_AXIS_X; - axisname = "X"; - } - - data[0] = inw(dev->iobase + axis_reg + PCI8164_SSTS); - printk("comedi: pci8164 SSTS read -> %04X:%04X on axis %s\n", data[0], - data[1], axisname); - + adl_pci8164_insn_read(dev, s, insn, data, "SSTS", PCI8164_SSTS); return 2; } static int adl_pci8164_insn_read_buf0(struct comedi_device *dev, struct comedi_subdevice *s, struct comedi_insn *insn, unsigned int *data) { - int axis, axis_reg; - char *axisname; - - axis = CR_CHAN(insn->chanspec); - - switch (axis) { - case 0: - axis_reg = PCI8164_AXIS_X; - axisname = "X"; - break; - case 1: - axis_reg = PCI8164_AXIS_Y; - axisname = "Y"; - break; - case 2: - axis_reg = PCI8164_AXIS_Z; - axisname = "Z"; - break; - case 3: - axis_reg = PCI8164_AXIS_U; - axisname = "U"; - break; - default: - axis_reg = PCI8164_AXIS_X; - axisname = "X"; - } - - data[0] = inw(dev->iobase + axis_reg + PCI8164_BUF0); - printk("comedi: pci8164 BUF0 read -> %04X:%04X on axis %s\n", data[0], - data[1], axisname); - + adl_pci8164_insn_read(dev, s, insn, data, "BUF0", PCI8164_BUF0); return 2; } static int adl_pci8164_insn_read_buf1(struct comedi_device *dev, struct comedi_subdevice *s, struct comedi_insn *insn, unsigned int *data) { - int axis, axis_reg; - - char *axisname; - - axis = CR_CHAN(insn->chanspec); - - switch (axis) { - case 0: - axis_reg = PCI8164_AXIS_X; - axisname = "X"; - break; - case 1: - axis_reg = PCI8164_AXIS_Y; - axisname = "Y"; - break; - case 2: - axis_reg = PCI8164_AXIS_Z; - axisname = "Z"; - break; - case 3: - axis_reg = PCI8164_AXIS_U; - axisname = "U"; - break; - default: - axis_reg = PCI8164_AXIS_X; - axisname = "X"; - } - - data[0] = inw(dev->iobase + axis_reg + PCI8164_BUF1); - printk("comedi: pci8164 BUF1 read -> %04X:%04X on axis %s\n", data[0], - data[1], axisname); - + adl_pci8164_insn_read(dev, s, insn, data, "BUF1", PCI8164_BUF1); return 2; } -static int adl_pci8164_insn_write_cmd(struct comedi_device *dev, struct comedi_subdevice *s, - struct comedi_insn *insn, unsigned int *data) +/* + all the write commands are the same except for the addition a constant + * const to the data for outw() + */ +static void adl_pci8164_insn_out(struct comedi_device *dev, + struct comedi_subdevice *s, + struct comedi_insn *insn, + unsigned int *data, + char *action, + unsigned short offset) { unsigned int axis, axis_reg; @@ -388,124 +320,39 @@ static int adl_pci8164_insn_write_cmd(struct comedi_device *dev, struct comedi_s axisname = "X"; } - outw(data[0], dev->iobase + axis_reg + PCI8164_CMD); - printk("comedi: pci8164 CMD write -> %04X:%04X on axis %s\n", data[0], - data[1], axisname); + outw(data[0], dev->iobase + axis_reg + offset); + printk("comedi: pci8164 %s write -> %04X:%04X on axis %s\n", action, + data[0], data[1], axisname); + +} + + +static int adl_pci8164_insn_write_cmd(struct comedi_device *dev, struct comedi_subdevice *s, + struct comedi_insn *insn, unsigned int *data) +{ + adl_pci8164_insn_out(dev, s, insn, data, "CMD", PCI8164_CMD); return 2; } static int adl_pci8164_insn_write_otp(struct comedi_device *dev, struct comedi_subdevice *s, struct comedi_insn *insn, unsigned int *data) { - int axis, axis_reg; - - char *axisname; - - axis = CR_CHAN(insn->chanspec); - - switch (axis) { - case 0: - axis_reg = PCI8164_AXIS_X; - axisname = "X"; - break; - case 1: - axis_reg = PCI8164_AXIS_Y; - axisname = "Y"; - break; - case 2: - axis_reg = PCI8164_AXIS_Z; - axisname = "Z"; - break; - case 3: - axis_reg = PCI8164_AXIS_U; - axisname = "U"; - break; - default: - axis_reg = PCI8164_AXIS_X; - axisname = "X"; - } - - outw(data[0], dev->iobase + axis_reg + PCI8164_OTP); - printk("comedi: pci8164 OTP write -> %04X:%04X on axis %s\n", data[0], - data[1], axisname); - + adl_pci8164_insn_out(dev, s, insn, data, "OTP", PCI8164_OTP); return 2; } static int adl_pci8164_insn_write_buf0(struct comedi_device *dev, struct comedi_subdevice *s, struct comedi_insn *insn, unsigned int *data) { - int axis, axis_reg; - - char *axisname; - - axis = CR_CHAN(insn->chanspec); - - switch (axis) { - case 0: - axis_reg = PCI8164_AXIS_X; - axisname = "X"; - break; - case 1: - axis_reg = PCI8164_AXIS_Y; - axisname = "Y"; - break; - case 2: - axis_reg = PCI8164_AXIS_Z; - axisname = "Z"; - break; - case 3: - axis_reg = PCI8164_AXIS_U; - axisname = "U"; - break; - default: - axis_reg = PCI8164_AXIS_X; - axisname = "X"; - } - - outw(data[0], dev->iobase + axis_reg + PCI8164_BUF0); - printk("comedi: pci8164 BUF0 write -> %04X:%04X on axis %s\n", data[0], - data[1], axisname); - + adl_pci8164_insn_out(dev, s, insn, data, "BUF0", PCI8164_BUF0); return 2; } static int adl_pci8164_insn_write_buf1(struct comedi_device *dev, struct comedi_subdevice *s, struct comedi_insn *insn, unsigned int *data) { - int axis, axis_reg; - - char *axisname; - - axis = CR_CHAN(insn->chanspec); - - switch (axis) { - case 0: - axis_reg = PCI8164_AXIS_X; - axisname = "X"; - break; - case 1: - axis_reg = PCI8164_AXIS_Y; - axisname = "Y"; - break; - case 2: - axis_reg = PCI8164_AXIS_Z; - axisname = "Z"; - break; - case 3: - axis_reg = PCI8164_AXIS_U; - axisname = "U"; - break; - default: - axis_reg = PCI8164_AXIS_X; - axisname = "X"; - } - - outw(data[0], dev->iobase + axis_reg + PCI8164_BUF1); - printk("comedi: pci8164 BUF1 write -> %04X:%04X on axis %s\n", data[0], - data[1], axisname); - + adl_pci8164_insn_out(dev, s, insn, data, "BUF1", PCI8164_BUF1); return 2; } -- 2.32.0.93.g670b81a890