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:
parent
9067983867
commit
5c19084bbd
@ -107,6 +107,16 @@ static int subdev_8255_io(struct comedi_device *dev,
|
||||
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,
|
||||
struct comedi_subdevice *s,
|
||||
struct comedi_insn *insn,
|
||||
@ -186,10 +196,12 @@ static int subdev_8255_insn_config(struct comedi_device *dev,
|
||||
return insn->n;
|
||||
}
|
||||
|
||||
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)
|
||||
static 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,
|
||||
bool is_mmio)
|
||||
{
|
||||
struct subdev_8255_private *spriv;
|
||||
|
||||
@ -197,8 +209,13 @@ int subdev_8255_init(struct comedi_device *dev, struct comedi_subdevice *s,
|
||||
if (!spriv)
|
||||
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->io = io ? io : subdev_8255_io;
|
||||
|
||||
s->type = COMEDI_SUBD_DIO;
|
||||
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;
|
||||
}
|
||||
|
||||
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);
|
||||
|
||||
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
|
||||
|
@ -21,9 +21,14 @@
|
||||
|
||||
#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, int, int, unsigned long),
|
||||
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
|
||||
|
@ -190,23 +190,12 @@ static int pci_8255_mite_init(struct pci_dev *pcidev)
|
||||
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,
|
||||
unsigned long context)
|
||||
{
|
||||
struct pci_dev *pcidev = comedi_to_pci_dev(dev);
|
||||
const struct pci_8255_boardinfo *board = NULL;
|
||||
struct comedi_subdevice *s;
|
||||
bool is_mmio;
|
||||
int ret;
|
||||
int i;
|
||||
|
||||
@ -227,9 +216,7 @@ static int pci_8255_auto_attach(struct comedi_device *dev,
|
||||
return ret;
|
||||
}
|
||||
|
||||
is_mmio = (pci_resource_flags(pcidev, board->dio_badr) &
|
||||
IORESOURCE_MEM) != 0;
|
||||
if (is_mmio) {
|
||||
if ((pci_resource_flags(pcidev, board->dio_badr) & IORESOURCE_MEM)) {
|
||||
dev->mmio = pci_ioremap_bar(pcidev, board->dio_badr);
|
||||
if (!dev->mmio)
|
||||
return -ENOMEM;
|
||||
@ -248,8 +235,8 @@ static int pci_8255_auto_attach(struct comedi_device *dev,
|
||||
|
||||
for (i = 0; i < board->n_8255; i++) {
|
||||
s = &dev->subdevices[i];
|
||||
if (is_mmio)
|
||||
ret = subdev_8255_init(dev, s, pci_8255_mmio, i * 4);
|
||||
if (dev->mmio)
|
||||
ret = subdev_8255_mm_init(dev, s, NULL, i * 4);
|
||||
else
|
||||
ret = subdev_8255_init(dev, s, NULL, i * 4);
|
||||
if (ret)
|
||||
|
@ -3369,16 +3369,6 @@ static int ao_cancel(struct comedi_device *dev, struct comedi_subdevice *s)
|
||||
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,
|
||||
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,
|
||||
I8255_4020_REG);
|
||||
} else {
|
||||
ret = subdev_8255_init(dev, s, dio_callback,
|
||||
DIO_8255_OFFSET);
|
||||
ret = subdev_8255_mm_init(dev, s, NULL,
|
||||
DIO_8255_OFFSET);
|
||||
}
|
||||
if (ret)
|
||||
return ret;
|
||||
|
@ -1035,17 +1035,6 @@ static int labpc_ao_insn_read(struct comedi_device *dev,
|
||||
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 */
|
||||
static void labpc_serial_out(struct comedi_device *dev, unsigned int value,
|
||||
unsigned int value_width)
|
||||
@ -1402,8 +1391,7 @@ int labpc_common_attach(struct comedi_device *dev,
|
||||
/* 8255 dio */
|
||||
s = &dev->subdevices[2];
|
||||
if (dev->mmio) {
|
||||
ret = subdev_8255_init(dev, s, labpc_8255_mmio,
|
||||
DIO_BASE_REG);
|
||||
ret = subdev_8255_mm_init(dev, s, NULL, DIO_BASE_REG);
|
||||
} else {
|
||||
ret = subdev_8255_init(dev, s, NULL, DIO_BASE_REG);
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user