Skip to content

Commit

Permalink
staging: comedi: ni_stc.h: add read/write callbacks to struct ni_private
Browse files Browse the repository at this point in the history
The {read,write}[bwl] macros used to access the registers in the ni_atmio,
ni_mio_cs, and ni_pcimio drivers and the included ni_mio_common.c file all
rely on a local variable having a specific name. They also require some of
the ni_mio_common code to need a __maybe_unused tag on the devpriv local
variable.

Remove all the macros by converting them into private functions and storing
the callbacks in the private data.

Signed-off-by: H Hartley Sweeten <[email protected]>
Reviewed-by: Ian Abbott <[email protected]>
Signed-off-by: Greg Kroah-Hartman <[email protected]>
  • Loading branch information
bigguiness authored and gregkh committed Jun 18, 2014
1 parent 9588fa8 commit 9c340ac
Show file tree
Hide file tree
Showing 5 changed files with 384 additions and 237 deletions.
62 changes: 46 additions & 16 deletions drivers/staging/comedi/drivers/ni_atmio.c
Original file line number Diff line number Diff line change
Expand Up @@ -272,12 +272,35 @@ static const int ni_irqpin[] = {

/* How we access registers */

#define ni_writel(a, b) (outl((a), (b)+dev->iobase))
#define ni_readl(a) (inl((a)+dev->iobase))
#define ni_writew(a, b) (outw((a), (b)+dev->iobase))
#define ni_readw(a) (inw((a)+dev->iobase))
#define ni_writeb(a, b) (outb((a), (b)+dev->iobase))
#define ni_readb(a) (inb((a)+dev->iobase))
static uint8_t ni_atmio_inb(struct comedi_device *dev, int reg)
{
return inb(dev->iobase + reg);
}

static uint16_t ni_atmio_inw(struct comedi_device *dev, int reg)
{
return inw(dev->iobase + reg);
}

static uint32_t ni_atmio_inl(struct comedi_device *dev, int reg)
{
return inl(dev->iobase + reg);
}

static void ni_atmio_outb(struct comedi_device *dev, uint8_t val, int reg)
{
outb(val, dev->iobase + reg);
}

static void ni_atmio_outw(struct comedi_device *dev, uint16_t val, int reg)
{
outw(val, dev->iobase + reg);
}

static void ni_atmio_outl(struct comedi_device *dev, uint32_t val, int reg)
{
outl(val, dev->iobase + reg);
}

/* How we access windowed registers */

Expand All @@ -292,10 +315,10 @@ static void ni_atmio_win_out(struct comedi_device *dev, uint16_t data, int addr)

spin_lock_irqsave(&devpriv->window_lock, flags);
if ((addr) < 8) {
ni_writew(data, addr * 2);
devpriv->writew(dev, data, addr * 2);
} else {
ni_writew(addr, Window_Address);
ni_writew(data, Window_Data);
devpriv->writew(dev, addr, Window_Address);
devpriv->writew(dev, data, Window_Data);
}
spin_unlock_irqrestore(&devpriv->window_lock, flags);
}
Expand All @@ -308,10 +331,10 @@ static uint16_t ni_atmio_win_in(struct comedi_device *dev, int addr)

spin_lock_irqsave(&devpriv->window_lock, flags);
if (addr < 8) {
ret = ni_readw(addr * 2);
ret = devpriv->readw(dev, addr * 2);
} else {
ni_writew(addr, Window_Address);
ret = ni_readw(Window_Data);
devpriv->writew(dev, addr, Window_Address);
ret = devpriv->readw(dev, Window_Data);
}
spin_unlock_irqrestore(&devpriv->window_lock, flags);

Expand Down Expand Up @@ -405,10 +428,17 @@ static int ni_atmio_attach(struct comedi_device *dev,
return ret;
devpriv = dev->private;

devpriv->stc_writew = &ni_atmio_win_out;
devpriv->stc_readw = &ni_atmio_win_in;
devpriv->stc_writel = &win_out2;
devpriv->stc_readl = &win_in2;
devpriv->readb = ni_atmio_inb;
devpriv->readw = ni_atmio_inw;
devpriv->readl = ni_atmio_inl;
devpriv->writeb = ni_atmio_outb;
devpriv->writew = ni_atmio_outw;
devpriv->writel = ni_atmio_outl;

devpriv->stc_writew = ni_atmio_win_out;
devpriv->stc_readw = ni_atmio_win_in;
devpriv->stc_writel = win_out2;
devpriv->stc_readl = win_in2;

iobase = it->options[0];
irq = it->options[1];
Expand Down
Loading

0 comments on commit 9c340ac

Please sign in to comment.