staging: comedi: 8255: handle memory mapped io

The drivers that use this module with memory mapped io all have the
ioremap'ed base address stored in the comedi_device 'mmio' member.

Introduce a default (*io) function that does 8-bit memory mapped io.

Modify subdev_8255_init() so that it takes a flag parameter indicating
if the io is port or memory mapped. Make the function static and rename
it to __subdev_8255_init().

Introduce two exported wrappers for __subdev_8255_init():

  subdev_8255_init() - for drivers that do 8-bit port io
  subdev_8255_mm_init() - for drivers that do 8-bit memory mapped io

Use subdev_8255_mm_init() in the drivers that do 8-bit memory mapped io
and remove the private (*io) functions.

Signed-off-by: H Hartley Sweeten <hsweeten@visionengravers.com>
Reviewed-by: Ian Abbott <abbotti@mev.co.uk>
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
This commit is contained in:
H Hartley Sweeten 2014-08-12 11:41:28 -07:00 committed by Greg Kroah-Hartman
parent 9067983867
commit 5c19084bbd
5 changed files with 50 additions and 47 deletions

View file

@ -107,6 +107,16 @@ static int subdev_8255_io(struct comedi_device *dev,
return inb(dev->iobase + regbase + port); return inb(dev->iobase + regbase + port);
} }
static int subdev_8255_mmio(struct comedi_device *dev,
int dir, int port, int data, unsigned long regbase)
{
if (dir) {
writeb(data, dev->mmio + regbase + port);
return 0;
}
return readb(dev->mmio + regbase + port);
}
static int subdev_8255_insn(struct comedi_device *dev, static int subdev_8255_insn(struct comedi_device *dev,
struct comedi_subdevice *s, struct comedi_subdevice *s,
struct comedi_insn *insn, struct comedi_insn *insn,
@ -186,10 +196,12 @@ static int subdev_8255_insn_config(struct comedi_device *dev,
return insn->n; return insn->n;
} }
int subdev_8255_init(struct comedi_device *dev, struct comedi_subdevice *s, static int __subdev_8255_init(struct comedi_device *dev,
int (*io)(struct comedi_device *, struct comedi_subdevice *s,
int, int, int, unsigned long), int (*io)(struct comedi_device *,
unsigned long regbase) int, int, int, unsigned long),
unsigned long regbase,
bool is_mmio)
{ {
struct subdev_8255_private *spriv; struct subdev_8255_private *spriv;
@ -197,8 +209,13 @@ int subdev_8255_init(struct comedi_device *dev, struct comedi_subdevice *s,
if (!spriv) if (!spriv)
return -ENOMEM; return -ENOMEM;
if (io)
spriv->io = io;
else if (is_mmio)
spriv->io = subdev_8255_mmio;
else
spriv->io = subdev_8255_io;
spriv->regbase = regbase; spriv->regbase = regbase;
spriv->io = io ? io : subdev_8255_io;
s->type = COMEDI_SUBD_DIO; s->type = COMEDI_SUBD_DIO;
s->subdev_flags = SDF_READABLE | SDF_WRITABLE; s->subdev_flags = SDF_READABLE | SDF_WRITABLE;
@ -212,8 +229,24 @@ int subdev_8255_init(struct comedi_device *dev, struct comedi_subdevice *s,
return 0; return 0;
} }
int subdev_8255_init(struct comedi_device *dev, struct comedi_subdevice *s,
int (*io)(struct comedi_device *,
int, int, int, unsigned long),
unsigned long regbase)
{
return __subdev_8255_init(dev, s, io, regbase, false);
}
EXPORT_SYMBOL_GPL(subdev_8255_init); EXPORT_SYMBOL_GPL(subdev_8255_init);
int subdev_8255_mm_init(struct comedi_device *dev, struct comedi_subdevice *s,
int (*io)(struct comedi_device *,
int, int, int, unsigned long),
unsigned long regbase)
{
return __subdev_8255_init(dev, s, io, regbase, true);
}
EXPORT_SYMBOL_GPL(subdev_8255_mm_init);
/* /*
Start of the 8255 standalone device Start of the 8255 standalone device

View file

@ -21,9 +21,14 @@
#include "../comedidev.h" #include "../comedidev.h"
int subdev_8255_init(struct comedi_device *dev, struct comedi_subdevice *s, int subdev_8255_init(struct comedi_device *, struct comedi_subdevice *,
int (*io)(struct comedi_device *, int (*io)(struct comedi_device *,
int, int, int, unsigned long), int, int, int, unsigned long),
unsigned long regbase); unsigned long regbase);
int subdev_8255_mm_init(struct comedi_device *, struct comedi_subdevice *,
int (*io)(struct comedi_device *,
int, int, int, unsigned long),
unsigned long regbase);
#endif #endif

View file

@ -190,23 +190,12 @@ static int pci_8255_mite_init(struct pci_dev *pcidev)
return 0; return 0;
} }
static int pci_8255_mmio(struct comedi_device *dev,
int dir, int port, int data, unsigned long iobase)
{
if (dir) {
writeb(data, dev->mmio + iobase + port);
return 0;
}
return readb(dev->mmio + iobase + port);
}
static int pci_8255_auto_attach(struct comedi_device *dev, static int pci_8255_auto_attach(struct comedi_device *dev,
unsigned long context) unsigned long context)
{ {
struct pci_dev *pcidev = comedi_to_pci_dev(dev); struct pci_dev *pcidev = comedi_to_pci_dev(dev);
const struct pci_8255_boardinfo *board = NULL; const struct pci_8255_boardinfo *board = NULL;
struct comedi_subdevice *s; struct comedi_subdevice *s;
bool is_mmio;
int ret; int ret;
int i; int i;
@ -227,9 +216,7 @@ static int pci_8255_auto_attach(struct comedi_device *dev,
return ret; return ret;
} }
is_mmio = (pci_resource_flags(pcidev, board->dio_badr) & if ((pci_resource_flags(pcidev, board->dio_badr) & IORESOURCE_MEM)) {
IORESOURCE_MEM) != 0;
if (is_mmio) {
dev->mmio = pci_ioremap_bar(pcidev, board->dio_badr); dev->mmio = pci_ioremap_bar(pcidev, board->dio_badr);
if (!dev->mmio) if (!dev->mmio)
return -ENOMEM; return -ENOMEM;
@ -248,8 +235,8 @@ static int pci_8255_auto_attach(struct comedi_device *dev,
for (i = 0; i < board->n_8255; i++) { for (i = 0; i < board->n_8255; i++) {
s = &dev->subdevices[i]; s = &dev->subdevices[i];
if (is_mmio) if (dev->mmio)
ret = subdev_8255_init(dev, s, pci_8255_mmio, i * 4); ret = subdev_8255_mm_init(dev, s, NULL, i * 4);
else else
ret = subdev_8255_init(dev, s, NULL, i * 4); ret = subdev_8255_init(dev, s, NULL, i * 4);
if (ret) if (ret)

View file

@ -3369,16 +3369,6 @@ static int ao_cancel(struct comedi_device *dev, struct comedi_subdevice *s)
return 0; return 0;
} }
static int dio_callback(struct comedi_device *dev,
int dir, int port, int data, unsigned long iobase)
{
if (dir) {
writeb(data, dev->mmio + iobase + port);
return 0;
}
return readb(dev->mmio + iobase + port);
}
static int dio_callback_4020(struct comedi_device *dev, static int dio_callback_4020(struct comedi_device *dev,
int dir, int port, int data, unsigned long iobase) int dir, int port, int data, unsigned long iobase)
{ {
@ -3842,8 +3832,8 @@ static int setup_subdevices(struct comedi_device *dev)
ret = subdev_8255_init(dev, s, dio_callback_4020, ret = subdev_8255_init(dev, s, dio_callback_4020,
I8255_4020_REG); I8255_4020_REG);
} else { } else {
ret = subdev_8255_init(dev, s, dio_callback, ret = subdev_8255_mm_init(dev, s, NULL,
DIO_8255_OFFSET); DIO_8255_OFFSET);
} }
if (ret) if (ret)
return ret; return ret;

View file

@ -1035,17 +1035,6 @@ static int labpc_ao_insn_read(struct comedi_device *dev,
return 1; return 1;
} }
static int labpc_8255_mmio(struct comedi_device *dev,
int dir, int port, int data, unsigned long iobase)
{
if (dir) {
writeb(data, dev->mmio + iobase + port);
return 0;
}
return readb(dev->mmio + iobase + port);
}
/* lowlevel write to eeprom/dac */ /* lowlevel write to eeprom/dac */
static void labpc_serial_out(struct comedi_device *dev, unsigned int value, static void labpc_serial_out(struct comedi_device *dev, unsigned int value,
unsigned int value_width) unsigned int value_width)
@ -1402,8 +1391,7 @@ int labpc_common_attach(struct comedi_device *dev,
/* 8255 dio */ /* 8255 dio */
s = &dev->subdevices[2]; s = &dev->subdevices[2];
if (dev->mmio) { if (dev->mmio) {
ret = subdev_8255_init(dev, s, labpc_8255_mmio, ret = subdev_8255_mm_init(dev, s, NULL, DIO_BASE_REG);
DIO_BASE_REG);
} else { } else {
ret = subdev_8255_init(dev, s, NULL, DIO_BASE_REG); ret = subdev_8255_init(dev, s, NULL, DIO_BASE_REG);
} }