Commit 90a35c15 authored by H Hartley Sweeten's avatar H Hartley Sweeten Committed by Greg Kroah-Hartman

staging: comedi: store the 'index' for each subdevice

Store the 'index' for each comedi_subdevice when they are initially
allocated by comedi_alloc_subdevice(). This allows removing the
pointer math in comedi_fops.c which is used to figure out the
index that user space uses to access the individual subdevices.

Fix the ni_mio_common driver so it also uses the 'index' instead
of doing the pointer math.

Also, remove a couple unused macros in the pcmda12, pcmmio, and
pcmuio drivers which also do the pointer math to figure out the
index.
Signed-off-by: default avatarH Hartley Sweeten <hsweeten@visionengravers.com>
Cc: Ian Abbott <abbotti@mev.co.uk>
Signed-off-by: default avatarGreg Kroah-Hartman <gregkh@linuxfoundation.org>
parent 71cf6d3e
...@@ -169,7 +169,7 @@ static int resize_async_buffer(struct comedi_device *dev, ...@@ -169,7 +169,7 @@ static int resize_async_buffer(struct comedi_device *dev,
} }
DPRINTK("comedi%i subd %d buffer resized to %i bytes\n", DPRINTK("comedi%i subd %d buffer resized to %i bytes\n",
dev->minor, (int)(s - dev->subdevices), async->prealloc_bufsz); dev->minor, s->index, async->prealloc_bufsz);
return 0; return 0;
} }
...@@ -624,13 +624,13 @@ static int do_devinfo_ioctl(struct comedi_device *dev, ...@@ -624,13 +624,13 @@ static int do_devinfo_ioctl(struct comedi_device *dev,
s = comedi_read_subdevice(info); s = comedi_read_subdevice(info);
if (s) if (s)
devinfo.read_subdevice = s - dev->subdevices; devinfo.read_subdevice = s->index;
else else
devinfo.read_subdevice = -1; devinfo.read_subdevice = -1;
s = comedi_write_subdevice(info); s = comedi_write_subdevice(info);
if (s) if (s)
devinfo.write_subdevice = s - dev->subdevices; devinfo.write_subdevice = s->index;
else else
devinfo.write_subdevice = -1; devinfo.write_subdevice = -1;
...@@ -2398,7 +2398,7 @@ int comedi_alloc_subdevice_minor(struct comedi_device *dev, ...@@ -2398,7 +2398,7 @@ int comedi_alloc_subdevice_minor(struct comedi_device *dev,
s->minor = i; s->minor = i;
csdev = device_create(comedi_class, dev->class_dev, csdev = device_create(comedi_class, dev->class_dev,
MKDEV(COMEDI_MAJOR, i), NULL, "comedi%i_subd%i", MKDEV(COMEDI_MAJOR, i), NULL, "comedi%i_subd%i",
dev->minor, (int)(s - dev->subdevices)); dev->minor, s->index);
if (!IS_ERR(csdev)) if (!IS_ERR(csdev))
s->class_dev = csdev; s->class_dev = csdev;
dev_set_drvdata(csdev, info); dev_set_drvdata(csdev, info);
......
...@@ -77,6 +77,7 @@ ...@@ -77,6 +77,7 @@
struct comedi_subdevice { struct comedi_subdevice {
struct comedi_device *device; struct comedi_device *device;
int index;
int type; int type;
int n_chan; int n_chan;
int subdev_flags; int subdev_flags;
......
...@@ -70,6 +70,7 @@ int comedi_alloc_subdevices(struct comedi_device *dev, int num_subdevices) ...@@ -70,6 +70,7 @@ int comedi_alloc_subdevices(struct comedi_device *dev, int num_subdevices)
for (i = 0; i < num_subdevices; ++i) { for (i = 0; i < num_subdevices; ++i) {
s = &dev->subdevices[i]; s = &dev->subdevices[i];
s->device = dev; s->device = dev;
s->index = i;
s->async_dma_dir = DMA_NONE; s->async_dma_dir = DMA_NONE;
spin_lock_init(&s->spin_lock); spin_lock_init(&s->spin_lock);
s->minor = -1; s->minor = -1;
......
...@@ -986,7 +986,7 @@ static void ni_event(struct comedi_device *dev, struct comedi_subdevice *s) ...@@ -986,7 +986,7 @@ static void ni_event(struct comedi_device *dev, struct comedi_subdevice *s)
if (s-> if (s->
async->events & (COMEDI_CB_ERROR | COMEDI_CB_OVERFLOW | async->events & (COMEDI_CB_ERROR | COMEDI_CB_OVERFLOW |
COMEDI_CB_EOA)) { COMEDI_CB_EOA)) {
switch (s - dev->subdevices) { switch (s->index) {
case NI_AI_SUBDEV: case NI_AI_SUBDEV:
ni_ai_reset(dev, s); ni_ai_reset(dev, s);
break; break;
......
...@@ -55,7 +55,6 @@ Configuration Options: ...@@ -55,7 +55,6 @@ Configuration Options:
#include <linux/pci.h> /* for PCI devices */ #include <linux/pci.h> /* for PCI devices */
#define SDEV_NO ((int)(s - dev->subdevices))
#define CHANS 8 #define CHANS 8
#define IOSIZE 16 #define IOSIZE 16
#define LSB(x) ((unsigned char)((x) & 0xff)) #define LSB(x) ((unsigned char)((x) & 0xff))
......
...@@ -94,7 +94,6 @@ Configuration Options: ...@@ -94,7 +94,6 @@ Configuration Options:
#define INTR_PORTS_PER_SUBDEV (INTR_CHANS_PER_ASIC/CHANS_PER_PORT) #define INTR_PORTS_PER_SUBDEV (INTR_CHANS_PER_ASIC/CHANS_PER_PORT)
#define MAX_DIO_CHANS (PORTS_PER_ASIC*1*CHANS_PER_PORT) #define MAX_DIO_CHANS (PORTS_PER_ASIC*1*CHANS_PER_PORT)
#define MAX_ASICS (MAX_DIO_CHANS/CHANS_PER_ASIC) #define MAX_ASICS (MAX_DIO_CHANS/CHANS_PER_ASIC)
#define SDEV_NO ((int)(s - dev->subdevices))
#define CALC_N_DIO_SUBDEVS(nchans) ((nchans)/MAX_CHANS_PER_SUBDEV + (!!((nchans)%MAX_CHANS_PER_SUBDEV)) /*+ (nchans > INTR_CHANS_PER_ASIC ? 2 : 1)*/) #define CALC_N_DIO_SUBDEVS(nchans) ((nchans)/MAX_CHANS_PER_SUBDEV + (!!((nchans)%MAX_CHANS_PER_SUBDEV)) /*+ (nchans > INTR_CHANS_PER_ASIC ? 2 : 1)*/)
/* IO Memory sizes */ /* IO Memory sizes */
#define ASIC_IOSIZE (0x0B) #define ASIC_IOSIZE (0x0B)
......
...@@ -92,7 +92,6 @@ Configuration Options: ...@@ -92,7 +92,6 @@ Configuration Options:
#define INTR_PORTS_PER_SUBDEV (INTR_CHANS_PER_ASIC/CHANS_PER_PORT) #define INTR_PORTS_PER_SUBDEV (INTR_CHANS_PER_ASIC/CHANS_PER_PORT)
#define MAX_DIO_CHANS (PORTS_PER_ASIC*2*CHANS_PER_PORT) #define MAX_DIO_CHANS (PORTS_PER_ASIC*2*CHANS_PER_PORT)
#define MAX_ASICS (MAX_DIO_CHANS/CHANS_PER_ASIC) #define MAX_ASICS (MAX_DIO_CHANS/CHANS_PER_ASIC)
#define SDEV_NO ((int)(s - dev->subdevices))
#define CALC_N_SUBDEVS(nchans) ((nchans)/MAX_CHANS_PER_SUBDEV + (!!((nchans)%MAX_CHANS_PER_SUBDEV)) /*+ (nchans > INTR_CHANS_PER_ASIC ? 2 : 1)*/) #define CALC_N_SUBDEVS(nchans) ((nchans)/MAX_CHANS_PER_SUBDEV + (!!((nchans)%MAX_CHANS_PER_SUBDEV)) /*+ (nchans > INTR_CHANS_PER_ASIC ? 2 : 1)*/)
/* IO Memory sizes */ /* IO Memory sizes */
#define ASIC_IOSIZE (0x10) #define ASIC_IOSIZE (0x10)
......
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