Commit 50e338b9 authored by H Hartley Sweeten's avatar H Hartley Sweeten Committed by Greg Kroah-Hartman

staging: comedi: adv_pci_dio: simplify counter subdevice I/O

Only two of the boards supported by this driver have an 8254 counter/timer.
Both of these boards have a single 8254 device. Currently the counter
subdevice functions are coded to support multiple 8254 devices. This is
unnecessary and just complicates the code.

Simplfy the subdevice functions to work for a single 8254 counter/timer and
refactor the driver (*attach) accordingly.
Signed-off-by: default avatarH Hartley Sweeten <hsweeten@visionengravers.com>
Reviewed-by: default avatarIan Abbott <abbotti@mev.co.uk>
Signed-off-by: default avatarGreg Kroah-Hartman <gregkh@linuxfoundation.org>
parent a6c6c9b1
...@@ -60,12 +60,6 @@ enum hw_io_access { ...@@ -60,12 +60,6 @@ enum hw_io_access {
#define MAX_DO_SUBDEVS 2 /* max number of DO subdevices per card */ #define MAX_DO_SUBDEVS 2 /* max number of DO subdevices per card */
#define MAX_DIO_SUBDEVG 2 /* max number of DIO subdevices group per #define MAX_DIO_SUBDEVG 2 /* max number of DIO subdevices group per
* card */ * card */
#define MAX_8254_SUBDEVS 1 /* max number of 8254 counter subdevs per
* card */
/* (could be more than one 8254 per
* subdevice) */
#define SIZE_8254 4 /* 8254 IO space length */
#define PCIDIO_MAINREG 2 /* main I/O region for all Advantech cards? */ #define PCIDIO_MAINREG 2 /* main I/O region for all Advantech cards? */
...@@ -243,7 +237,7 @@ struct dio_boardtype { ...@@ -243,7 +237,7 @@ struct dio_boardtype {
struct diosubd_data sdo[MAX_DO_SUBDEVS]; /* DO chans */ struct diosubd_data sdo[MAX_DO_SUBDEVS]; /* DO chans */
struct diosubd_data sdio[MAX_DIO_SUBDEVG]; /* DIO 8255 chans */ struct diosubd_data sdio[MAX_DIO_SUBDEVG]; /* DIO 8255 chans */
struct diosubd_data boardid; /* card supports board ID switch */ struct diosubd_data boardid; /* card supports board ID switch */
struct diosubd_data s8254[MAX_8254_SUBDEVS]; /* 8254 subdevices */ struct diosubd_data s8254[1]; /* 8254 subdevices */
enum hw_io_access io_access; enum hw_io_access io_access;
}; };
...@@ -492,15 +486,11 @@ static int pci_8254_insn_read(struct comedi_device *dev, ...@@ -492,15 +486,11 @@ static int pci_8254_insn_read(struct comedi_device *dev,
struct comedi_insn *insn, unsigned int *data) struct comedi_insn *insn, unsigned int *data)
{ {
const struct diosubd_data *d = (const struct diosubd_data *)s->private; const struct diosubd_data *d = (const struct diosubd_data *)s->private;
unsigned int chan, chip, chipchan; unsigned int chan = CR_CHAN(insn->chanspec);
unsigned long flags; unsigned long flags;
chan = CR_CHAN(insn->chanspec); /* channel on subdevice */
chip = chan / 3; /* chip on subdevice */
chipchan = chan - (3 * chip); /* channel on chip on subdevice */
spin_lock_irqsave(&s->spin_lock, flags); spin_lock_irqsave(&s->spin_lock, flags);
data[0] = i8254_read(dev->iobase + d->addr + (SIZE_8254 * chip), data[0] = i8254_read(dev->iobase + d->addr, 0, chan);
0, chipchan);
spin_unlock_irqrestore(&s->spin_lock, flags); spin_unlock_irqrestore(&s->spin_lock, flags);
return 1; return 1;
} }
...@@ -513,15 +503,11 @@ static int pci_8254_insn_write(struct comedi_device *dev, ...@@ -513,15 +503,11 @@ static int pci_8254_insn_write(struct comedi_device *dev,
struct comedi_insn *insn, unsigned int *data) struct comedi_insn *insn, unsigned int *data)
{ {
const struct diosubd_data *d = (const struct diosubd_data *)s->private; const struct diosubd_data *d = (const struct diosubd_data *)s->private;
unsigned int chan, chip, chipchan; unsigned int chan = CR_CHAN(insn->chanspec);
unsigned long flags; unsigned long flags;
chan = CR_CHAN(insn->chanspec); /* channel on subdevice */
chip = chan / 3; /* chip on subdevice */
chipchan = chan - (3 * chip); /* channel on chip on subdevice */
spin_lock_irqsave(&s->spin_lock, flags); spin_lock_irqsave(&s->spin_lock, flags);
i8254_write(dev->iobase + d->addr + (SIZE_8254 * chip), i8254_write(dev->iobase + d->addr, 0, chan, data[0]);
0, chipchan, data[0]);
spin_unlock_irqrestore(&s->spin_lock, flags); spin_unlock_irqrestore(&s->spin_lock, flags);
return 1; return 1;
} }
...@@ -534,24 +520,20 @@ static int pci_8254_insn_config(struct comedi_device *dev, ...@@ -534,24 +520,20 @@ static int pci_8254_insn_config(struct comedi_device *dev,
struct comedi_insn *insn, unsigned int *data) struct comedi_insn *insn, unsigned int *data)
{ {
const struct diosubd_data *d = (const struct diosubd_data *)s->private; const struct diosubd_data *d = (const struct diosubd_data *)s->private;
unsigned int chan, chip, chipchan; unsigned int chan = CR_CHAN(insn->chanspec);
unsigned long iobase; unsigned long iobase = dev->iobase + d->addr;
int ret = 0; int ret = 0;
unsigned long flags; unsigned long flags;
chan = CR_CHAN(insn->chanspec); /* channel on subdevice */
chip = chan / 3; /* chip on subdevice */
chipchan = chan - (3 * chip); /* channel on chip on subdevice */
iobase = dev->iobase + d->addr + (SIZE_8254 * chip);
spin_lock_irqsave(&s->spin_lock, flags); spin_lock_irqsave(&s->spin_lock, flags);
switch (data[0]) { switch (data[0]) {
case INSN_CONFIG_SET_COUNTER_MODE: case INSN_CONFIG_SET_COUNTER_MODE:
ret = i8254_set_mode(iobase, 0, chipchan, data[1]); ret = i8254_set_mode(iobase, 0, chan, data[1]);
if (ret < 0) if (ret < 0)
ret = -EINVAL; ret = -EINVAL;
break; break;
case INSN_CONFIG_8254_READ_STATUS: case INSN_CONFIG_8254_READ_STATUS:
data[1] = i8254_status(iobase, 0, chipchan); data[1] = i8254_status(iobase, 0, chan);
break; break;
default: default:
ret = -EINVAL; ret = -EINVAL;
...@@ -1144,12 +1126,11 @@ static int pci_dio_auto_attach(struct comedi_device *dev, ...@@ -1144,12 +1126,11 @@ static int pci_dio_auto_attach(struct comedi_device *dev,
subdev++; subdev++;
} }
for (i = 0; i < MAX_8254_SUBDEVS; i++) if (this_board->s8254[0].chans) {
if (this_board->s8254[i].chans) { s = &dev->subdevices[subdev];
s = &dev->subdevices[subdev]; pci_dio_add_8254(dev, s, &this_board->s8254[0]);
pci_dio_add_8254(dev, s, &this_board->s8254[i]); subdev++;
subdev++; }
}
if (this_board->cardtype == TYPE_PCI1760) if (this_board->cardtype == TYPE_PCI1760)
pci1760_attach(dev); pci1760_attach(dev);
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment