comedi: amplc_dio200_common: Refactor register access functions
The `dio200_read8()`, `dio200_write8()`, `dio200_read32()` and `dio200_write32()` functions apply a right-shift to the register offset for some devices and then perform the actual register access. Factor the register access part out to new functions `dio200___read8()`, `dio200___write8()`, `dio200___read32()`, and `dio200___write32()`. This will reduce duplicated code in a subsequent patch that will conditionally compile support for port I/O as part of the `HAS_IOPORT` changes. Cc: Arnd Bergmann <arnd@kernel.org> Cc: Niklas Schnelle <schnelle@linux.ibm.com> Signed-off-by: Ian Abbott <abbotti@mev.co.uk> Link: https://lore.kernel.org/r/20230913170712.111719-12-abbotti@mev.co.uk Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
This commit is contained in:
committed by
Greg Kroah-Hartman
parent
772dcada0e
commit
a3f2b80847
@ -86,6 +86,40 @@ struct dio200_subdev_intr {
|
|||||||
unsigned int active:1;
|
unsigned int active:1;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
static unsigned char dio200___read8(struct comedi_device *dev,
|
||||||
|
unsigned int offset)
|
||||||
|
{
|
||||||
|
if (dev->mmio)
|
||||||
|
return readb(dev->mmio + offset);
|
||||||
|
return inb(dev->iobase + offset);
|
||||||
|
}
|
||||||
|
|
||||||
|
static void dio200___write8(struct comedi_device *dev,
|
||||||
|
unsigned int offset, unsigned char val)
|
||||||
|
{
|
||||||
|
if (dev->mmio)
|
||||||
|
writeb(val, dev->mmio + offset);
|
||||||
|
else
|
||||||
|
outb(val, dev->iobase + offset);
|
||||||
|
}
|
||||||
|
|
||||||
|
static unsigned int dio200___read32(struct comedi_device *dev,
|
||||||
|
unsigned int offset)
|
||||||
|
{
|
||||||
|
if (dev->mmio)
|
||||||
|
return readl(dev->mmio + offset);
|
||||||
|
return inl(dev->iobase + offset);
|
||||||
|
}
|
||||||
|
|
||||||
|
static void dio200___write32(struct comedi_device *dev,
|
||||||
|
unsigned int offset, unsigned int val)
|
||||||
|
{
|
||||||
|
if (dev->mmio)
|
||||||
|
writel(val, dev->mmio + offset);
|
||||||
|
else
|
||||||
|
outl(val, dev->iobase + offset);
|
||||||
|
}
|
||||||
|
|
||||||
static unsigned char dio200_read8(struct comedi_device *dev,
|
static unsigned char dio200_read8(struct comedi_device *dev,
|
||||||
unsigned int offset)
|
unsigned int offset)
|
||||||
{
|
{
|
||||||
@ -94,9 +128,7 @@ static unsigned char dio200_read8(struct comedi_device *dev,
|
|||||||
if (board->is_pcie)
|
if (board->is_pcie)
|
||||||
offset <<= 3;
|
offset <<= 3;
|
||||||
|
|
||||||
if (dev->mmio)
|
return dio200___read8(dev, offset);
|
||||||
return readb(dev->mmio + offset);
|
|
||||||
return inb(dev->iobase + offset);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
static void dio200_write8(struct comedi_device *dev,
|
static void dio200_write8(struct comedi_device *dev,
|
||||||
@ -107,10 +139,7 @@ static void dio200_write8(struct comedi_device *dev,
|
|||||||
if (board->is_pcie)
|
if (board->is_pcie)
|
||||||
offset <<= 3;
|
offset <<= 3;
|
||||||
|
|
||||||
if (dev->mmio)
|
dio200___write8(dev, offset, val);
|
||||||
writeb(val, dev->mmio + offset);
|
|
||||||
else
|
|
||||||
outb(val, dev->iobase + offset);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
static unsigned int dio200_read32(struct comedi_device *dev,
|
static unsigned int dio200_read32(struct comedi_device *dev,
|
||||||
@ -121,9 +150,7 @@ static unsigned int dio200_read32(struct comedi_device *dev,
|
|||||||
if (board->is_pcie)
|
if (board->is_pcie)
|
||||||
offset <<= 3;
|
offset <<= 3;
|
||||||
|
|
||||||
if (dev->mmio)
|
return dio200___read32(dev, offset);
|
||||||
return readl(dev->mmio + offset);
|
|
||||||
return inl(dev->iobase + offset);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
static void dio200_write32(struct comedi_device *dev,
|
static void dio200_write32(struct comedi_device *dev,
|
||||||
@ -134,10 +161,7 @@ static void dio200_write32(struct comedi_device *dev,
|
|||||||
if (board->is_pcie)
|
if (board->is_pcie)
|
||||||
offset <<= 3;
|
offset <<= 3;
|
||||||
|
|
||||||
if (dev->mmio)
|
dio200___write32(dev, offset, val);
|
||||||
writel(val, dev->mmio + offset);
|
|
||||||
else
|
|
||||||
outl(val, dev->iobase + offset);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
static unsigned int dio200_subdev_8254_offset(struct comedi_device *dev,
|
static unsigned int dio200_subdev_8254_offset(struct comedi_device *dev,
|
||||||
|
Reference in New Issue
Block a user