Commit 98e9f679 authored by H Hartley Sweeten's avatar H Hartley Sweeten Committed by Greg Kroah-Hartman

staging: comedi: ni_65xx: remove the need for the subdevice private data

There is only one member in the subdevice private data, an unsigned value
that is the 'base_port' that the subdevice uses to access the port registers.

Just cast the appropriate value into s->private instead of allocating the
private data for each subdevice. The casts are a bit of a nusance but it
removes the unnecessary allocations.
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 11d892cc
...@@ -274,25 +274,16 @@ struct ni_65xx_private { ...@@ -274,25 +274,16 @@ struct ni_65xx_private {
unsigned short output_bits[NI_65XX_MAX_NUM_PORTS]; unsigned short output_bits[NI_65XX_MAX_NUM_PORTS];
}; };
struct ni_65xx_subdevice_private {
unsigned base_port;
};
static inline struct ni_65xx_subdevice_private *sprivate(struct comedi_subdevice
*subdev)
{
return subdev->private;
}
static int ni_65xx_dio_insn_config(struct comedi_device *dev, static int ni_65xx_dio_insn_config(struct comedi_device *dev,
struct comedi_subdevice *s, struct comedi_subdevice *s,
struct comedi_insn *insn, struct comedi_insn *insn,
unsigned int *data) unsigned int *data)
{ {
struct ni_65xx_private *devpriv = dev->private; struct ni_65xx_private *devpriv = dev->private;
unsigned long base_port = (unsigned long)s->private;
unsigned int chan = CR_CHAN(insn->chanspec); unsigned int chan = CR_CHAN(insn->chanspec);
unsigned int chan_mask = 1 << (chan % ni_65xx_channels_per_port); unsigned int chan_mask = 1 << (chan % ni_65xx_channels_per_port);
unsigned port = sprivate(s)->base_port + ni_65xx_port_by_channel(chan); unsigned port = base_port + ni_65xx_port_by_channel(chan);
unsigned int interval; unsigned int interval;
unsigned int val; unsigned int val;
...@@ -357,6 +348,7 @@ static int ni_65xx_dio_insn_bits(struct comedi_device *dev, ...@@ -357,6 +348,7 @@ static int ni_65xx_dio_insn_bits(struct comedi_device *dev,
struct comedi_insn *insn, unsigned int *data) struct comedi_insn *insn, unsigned int *data)
{ {
const struct ni_65xx_board *board = comedi_board(dev); const struct ni_65xx_board *board = comedi_board(dev);
unsigned long base_port = (unsigned long)s->private;
struct ni_65xx_private *devpriv = dev->private; struct ni_65xx_private *devpriv = dev->private;
int base_bitfield_channel; int base_bitfield_channel;
unsigned read_bits = 0; unsigned read_bits = 0;
...@@ -366,7 +358,7 @@ static int ni_65xx_dio_insn_bits(struct comedi_device *dev, ...@@ -366,7 +358,7 @@ static int ni_65xx_dio_insn_bits(struct comedi_device *dev,
base_bitfield_channel = CR_CHAN(insn->chanspec); base_bitfield_channel = CR_CHAN(insn->chanspec);
for (port_offset = ni_65xx_port_by_channel(base_bitfield_channel); for (port_offset = ni_65xx_port_by_channel(base_bitfield_channel);
port_offset <= last_port_offset; port_offset++) { port_offset <= last_port_offset; port_offset++) {
unsigned port = sprivate(s)->base_port + port_offset; unsigned port = base_port + port_offset;
int base_port_channel = port_offset * ni_65xx_channels_per_port; int base_port_channel = port_offset * ni_65xx_channels_per_port;
unsigned port_mask, port_data, port_read_bits; unsigned port_mask, port_data, port_read_bits;
int bitshift = base_port_channel - base_bitfield_channel; int bitshift = base_port_channel - base_bitfield_channel;
...@@ -563,7 +555,6 @@ static int ni_65xx_auto_attach(struct comedi_device *dev, ...@@ -563,7 +555,6 @@ static int ni_65xx_auto_attach(struct comedi_device *dev,
struct pci_dev *pcidev = comedi_to_pci_dev(dev); struct pci_dev *pcidev = comedi_to_pci_dev(dev);
const struct ni_65xx_board *board = NULL; const struct ni_65xx_board *board = NULL;
struct ni_65xx_private *devpriv; struct ni_65xx_private *devpriv;
struct ni_65xx_subdevice_private *spriv;
struct comedi_subdevice *s; struct comedi_subdevice *s;
unsigned i; unsigned i;
int ret; int ret;
...@@ -609,10 +600,9 @@ static int ni_65xx_auto_attach(struct comedi_device *dev, ...@@ -609,10 +600,9 @@ static int ni_65xx_auto_attach(struct comedi_device *dev,
s->maxdata = 1; s->maxdata = 1;
s->insn_config = ni_65xx_dio_insn_config; s->insn_config = ni_65xx_dio_insn_config;
s->insn_bits = ni_65xx_dio_insn_bits; s->insn_bits = ni_65xx_dio_insn_bits;
spriv = comedi_alloc_spriv(s, sizeof(*spriv));
if (!spriv) /* the input ports always start at port 0 */
return -ENOMEM; s->private = (void *)0;
spriv->base_port = 0;
} else { } else {
s->type = COMEDI_SUBD_UNUSED; s->type = COMEDI_SUBD_UNUSED;
} }
...@@ -626,10 +616,9 @@ static int ni_65xx_auto_attach(struct comedi_device *dev, ...@@ -626,10 +616,9 @@ static int ni_65xx_auto_attach(struct comedi_device *dev,
s->range_table = &range_digital; s->range_table = &range_digital;
s->maxdata = 1; s->maxdata = 1;
s->insn_bits = ni_65xx_dio_insn_bits; s->insn_bits = ni_65xx_dio_insn_bits;
spriv = comedi_alloc_spriv(s, sizeof(*spriv));
if (!spriv) /* the output ports always start after the input ports */
return -ENOMEM; s->private = (void *)(unsigned long)board->num_di_ports;
spriv->base_port = board->num_di_ports;
} else { } else {
s->type = COMEDI_SUBD_UNUSED; s->type = COMEDI_SUBD_UNUSED;
} }
...@@ -644,10 +633,10 @@ static int ni_65xx_auto_attach(struct comedi_device *dev, ...@@ -644,10 +633,10 @@ static int ni_65xx_auto_attach(struct comedi_device *dev,
s->maxdata = 1; s->maxdata = 1;
s->insn_config = ni_65xx_dio_insn_config; s->insn_config = ni_65xx_dio_insn_config;
s->insn_bits = ni_65xx_dio_insn_bits; s->insn_bits = ni_65xx_dio_insn_bits;
spriv = comedi_alloc_spriv(s, sizeof(*spriv));
if (!spriv) /* the input/output ports always start at port 0 */
return -ENOMEM; s->private = (void *)0;
spriv->base_port = 0;
/* configure all ports for input */ /* configure all ports for input */
for (i = 0; i < board->num_dio_ports; ++i) { for (i = 0; i < board->num_dio_ports; ++i) {
writeb(NI_65XX_IO_SEL_INPUT, writeb(NI_65XX_IO_SEL_INPUT,
......
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