aboutsummaryrefslogtreecommitdiff
path: root/drivers/staging/comedi/drivers/adl_pci8164.c
diff options
context:
space:
mode:
Diffstat (limited to 'drivers/staging/comedi/drivers/adl_pci8164.c')
-rw-r--r--drivers/staging/comedi/drivers/adl_pci8164.c325
1 files changed, 86 insertions, 239 deletions
diff --git a/drivers/staging/comedi/drivers/adl_pci8164.c b/drivers/staging/comedi/drivers/adl_pci8164.c
index adf90be7998..2d7d68af6b1 100644
--- a/drivers/staging/comedi/drivers/adl_pci8164.c
+++ b/drivers/staging/comedi/drivers/adl_pci8164.c
@@ -70,40 +70,40 @@ struct adl_pci8164_private {
#define devpriv ((struct adl_pci8164_private *)dev->private)
-static int adl_pci8164_attach(struct comedi_device * dev, struct comedi_devconfig * it);
-static int adl_pci8164_detach(struct comedi_device * dev);
+static int adl_pci8164_attach(struct comedi_device *dev, struct comedi_devconfig *it);
+static int adl_pci8164_detach(struct comedi_device *dev);
static struct comedi_driver driver_adl_pci8164 = {
- driver_name:"adl_pci8164",
- module:THIS_MODULE,
- attach:adl_pci8164_attach,
- detach:adl_pci8164_detach,
+ .driver_name = "adl_pci8164",
+ .module = THIS_MODULE,
+ .attach = adl_pci8164_attach,
+ .detach = adl_pci8164_detach,
};
-static int adl_pci8164_insn_read_msts(struct comedi_device * dev, struct comedi_subdevice * s,
- struct comedi_insn * insn, unsigned int * data);
+static int adl_pci8164_insn_read_msts(struct comedi_device *dev, struct comedi_subdevice *s,
+ struct comedi_insn *insn, unsigned int *data);
-static int adl_pci8164_insn_read_ssts(struct comedi_device * dev, struct comedi_subdevice * s,
- struct comedi_insn * insn, unsigned int * data);
+static int adl_pci8164_insn_read_ssts(struct comedi_device *dev, struct comedi_subdevice *s,
+ struct comedi_insn *insn, unsigned int *data);
-static int adl_pci8164_insn_read_buf0(struct comedi_device * dev, struct comedi_subdevice * s,
- struct comedi_insn * insn, unsigned int * data);
+static int adl_pci8164_insn_read_buf0(struct comedi_device *dev, struct comedi_subdevice *s,
+ struct comedi_insn *insn, unsigned int *data);
-static int adl_pci8164_insn_read_buf1(struct comedi_device * dev, struct comedi_subdevice * s,
- struct comedi_insn * insn, unsigned int * data);
+static int adl_pci8164_insn_read_buf1(struct comedi_device *dev, struct comedi_subdevice *s,
+ struct comedi_insn *insn, unsigned int *data);
-static int adl_pci8164_insn_write_cmd(struct comedi_device * dev, struct comedi_subdevice * s,
- struct comedi_insn * insn, unsigned int * data);
+static int adl_pci8164_insn_write_cmd(struct comedi_device *dev, struct comedi_subdevice *s,
+ struct comedi_insn *insn, unsigned int *data);
-static int adl_pci8164_insn_write_otp(struct comedi_device * dev, struct comedi_subdevice * s,
- struct comedi_insn * insn, unsigned int * data);
+static int adl_pci8164_insn_write_otp(struct comedi_device *dev, struct comedi_subdevice *s,
+ struct comedi_insn *insn, unsigned int *data);
-static int adl_pci8164_insn_write_buf0(struct comedi_device * dev,
- struct comedi_subdevice * s, struct comedi_insn * insn, unsigned int * data);
+static int adl_pci8164_insn_write_buf0(struct comedi_device *dev,
+ struct comedi_subdevice *s, struct comedi_insn *insn, unsigned int *data);
-static int adl_pci8164_insn_write_buf1(struct comedi_device * dev,
- struct comedi_subdevice * s, struct comedi_insn * insn, unsigned int * data);
+static int adl_pci8164_insn_write_buf1(struct comedi_device *dev,
+ struct comedi_subdevice *s, struct comedi_insn *insn, unsigned int *data);
-static int adl_pci8164_attach(struct comedi_device * dev, struct comedi_devconfig * it)
+static int adl_pci8164_attach(struct comedi_device *dev, struct comedi_devconfig *it)
{
struct pci_dev *pcidev;
struct comedi_subdevice *s;
@@ -149,7 +149,7 @@ static int adl_pci8164_attach(struct comedi_device * dev, struct comedi_devconfi
s->n_chan = 4;
s->maxdata = 0xffff;
s->len_chanlist = 4;
- //s->range_table = &range_axis;
+ /* s->range_table = &range_axis; */
s->insn_read = adl_pci8164_insn_read_msts;
s->insn_write = adl_pci8164_insn_write_cmd;
@@ -159,7 +159,7 @@ static int adl_pci8164_attach(struct comedi_device * dev, struct comedi_devconfi
s->n_chan = 4;
s->maxdata = 0xffff;
s->len_chanlist = 4;
- //s->range_table = &range_axis;
+ /* s->range_table = &range_axis; */
s->insn_read = adl_pci8164_insn_read_ssts;
s->insn_write = adl_pci8164_insn_write_otp;
@@ -169,7 +169,7 @@ static int adl_pci8164_attach(struct comedi_device * dev, struct comedi_devconfi
s->n_chan = 4;
s->maxdata = 0xffff;
s->len_chanlist = 4;
- //s->range_table = &range_axis;
+ /* s->range_table = &range_axis; */
s->insn_read = adl_pci8164_insn_read_buf0;
s->insn_write = adl_pci8164_insn_write_buf0;
@@ -179,7 +179,7 @@ static int adl_pci8164_attach(struct comedi_device * dev, struct comedi_devconfi
s->n_chan = 4;
s->maxdata = 0xffff;
s->len_chanlist = 4;
- //s->range_table = &range_axis;
+ /* s->range_table = &range_axis; */
s->insn_read = adl_pci8164_insn_read_buf1;
s->insn_write = adl_pci8164_insn_write_buf1;
@@ -194,7 +194,7 @@ static int adl_pci8164_attach(struct comedi_device * dev, struct comedi_devconfi
return -EIO;
}
-static int adl_pci8164_detach(struct comedi_device * dev)
+static int adl_pci8164_detach(struct comedi_device *dev)
{
printk("comedi%d: pci8164: remove\n", dev->minor);
@@ -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_
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)
+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)
+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)
+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_
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);
-
- 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;
+ outw(data[0], dev->iobase + axis_reg + offset);
- axis = CR_CHAN(insn->chanspec);
+ printk("comedi: pci8164 %s write -> %04X:%04X on axis %s\n", action,
+ data[0], data[1], axisname);
- 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);
+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_buf0(struct comedi_device * dev,
- struct comedi_subdevice * s, struct comedi_insn * insn, unsigned int * data)
+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_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, "OTP", PCI8164_OTP);
return 2;
}
-static int adl_pci8164_insn_write_buf1(struct comedi_device * dev,
- struct comedi_subdevice * s, struct comedi_insn * insn, unsigned int * data)
+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_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, "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)
+{
+ adl_pci8164_insn_out(dev, s, insn, data, "BUF1", PCI8164_BUF1);
return 2;
}