Skip to content

Commit

Permalink
comedi: amplc_dio200_common: Refactor register access functions
Browse files Browse the repository at this point in the history
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 <[email protected]>
Cc: Niklas Schnelle <[email protected]>
Signed-off-by: Ian Abbott <[email protected]>
Link: https://lore.kernel.org/r/[email protected]
Signed-off-by: Greg Kroah-Hartman <[email protected]>
  • Loading branch information
ian-abbott authored and gregkh committed Oct 5, 2023
1 parent 772dcad commit a3f2b80
Showing 1 changed file with 38 additions and 14 deletions.
52 changes: 38 additions & 14 deletions drivers/comedi/drivers/amplc_dio200_common.c
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,40 @@ struct dio200_subdev_intr {
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,
unsigned int offset)
{
Expand All @@ -94,9 +128,7 @@ static unsigned char dio200_read8(struct comedi_device *dev,
if (board->is_pcie)
offset <<= 3;

if (dev->mmio)
return readb(dev->mmio + offset);
return inb(dev->iobase + offset);
return dio200___read8(dev, offset);
}

static void dio200_write8(struct comedi_device *dev,
Expand All @@ -107,10 +139,7 @@ static void dio200_write8(struct comedi_device *dev,
if (board->is_pcie)
offset <<= 3;

if (dev->mmio)
writeb(val, dev->mmio + offset);
else
outb(val, dev->iobase + offset);
dio200___write8(dev, offset, val);
}

static unsigned int dio200_read32(struct comedi_device *dev,
Expand All @@ -121,9 +150,7 @@ static unsigned int dio200_read32(struct comedi_device *dev,
if (board->is_pcie)
offset <<= 3;

if (dev->mmio)
return readl(dev->mmio + offset);
return inl(dev->iobase + offset);
return dio200___read32(dev, offset);
}

static void dio200_write32(struct comedi_device *dev,
Expand All @@ -134,10 +161,7 @@ static void dio200_write32(struct comedi_device *dev,
if (board->is_pcie)
offset <<= 3;

if (dev->mmio)
writel(val, dev->mmio + offset);
else
outl(val, dev->iobase + offset);
dio200___write32(dev, offset, val);
}

static unsigned int dio200_subdev_8254_offset(struct comedi_device *dev,
Expand Down

0 comments on commit a3f2b80

Please sign in to comment.