diff options
author | Bill Pemberton <wfp5p@virginia.edu> | 2009-04-26 22:45:12 +0400 |
---|---|---|
committer | Greg Kroah-Hartman <gregkh@suse.de> | 2009-06-19 22:00:34 +0400 |
commit | ba7834b3f335f6bdef95e416d72245f6687cc660 (patch) | |
tree | 36f64993cecc99ae2d718595477389ba08fa47df /drivers/staging/comedi | |
parent | 8605b3aa0c107b5df59e99dbde2e708aa0012efd (diff) | |
download | linux-ba7834b3f335f6bdef95e416d72245f6687cc660.tar.xz |
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 <wfp5p@virginia.edu>
Signed-off-by: Greg Kroah-Hartman <gregkh@suse.de>
Diffstat (limited to 'drivers/staging/comedi')
-rw-r--r-- | drivers/staging/comedi/drivers/adl_pci8164.c | 245 |
1 files changed, 46 insertions, 199 deletions
diff --git a/drivers/staging/comedi/drivers/adl_pci8164.c b/drivers/staging/comedi/drivers/adl_pci8164.c index 2fe577a973af..2d7d68af6b1e 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; } |