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,
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;
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;
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
#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
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;
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;
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)
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)
{
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;
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)
/* 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);
}