linux-stable/drivers/isdn/hardware/mISDN/iohelper.h
Thomas Gleixner 82c298100a treewide: Replace GPLv2 boilerplate/reference with SPDX - rule 176
Based on 1 normalized pattern(s):

  this program is free software you can redistribute it and or modify
  it under the terms of the gnu general public license version 2 as
  published by the free software foundation this program is
  distributed in the hope that it will be useful but without any
  warranty without even the implied warranty of merchantability or
  fitness for a particular purpose see the gnu general public license
  for more details you should have received a copy of the gnu general
  public license along with this program if not write to the free
  software foundation inc 675 mass ave cambridge ma 02139 usa

extracted by the scancode license scanner the SPDX license identifier

  GPL-2.0-only

has been chosen to replace the boilerplate/reference in 44 file(s).

Signed-off-by: Thomas Gleixner <tglx@linutronix.de>
Reviewed-by: Allison Randal <allison@lohutok.net>
Reviewed-by: Steve Winslow <swinslow@gmail.com>
Reviewed-by: Alexios Zavras <alexios.zavras@intel.com>
Cc: linux-spdx@vger.kernel.org
Link: https://lkml.kernel.org/r/20190528170025.980374610@linutronix.de
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
2019-05-30 11:29:19 -07:00

96 lines
3 KiB
C

/* SPDX-License-Identifier: GPL-2.0-only */
/*
* iohelper.h
* helper for define functions to access ISDN hardware
* supported are memory mapped IO
* indirect port IO (one port for address, one for data)
*
* Author Karsten Keil <keil@isdn4linux.de>
*
* Copyright 2009 by Karsten Keil <keil@isdn4linux.de>
*/
#ifndef _IOHELPER_H
#define _IOHELPER_H
typedef u8 (read_reg_func)(void *hwp, u8 offset);
typedef void (write_reg_func)(void *hwp, u8 offset, u8 value);
typedef void (fifo_func)(void *hwp, u8 offset, u8 *datap, int size);
struct _ioport {
u32 port;
u32 ale;
};
#define IOFUNC_IO(name, hws, ap) \
static u8 Read##name##_IO(void *p, u8 off) { \
struct hws *hw = p; \
return inb(hw->ap.port + off); \
} \
static void Write##name##_IO(void *p, u8 off, u8 val) { \
struct hws *hw = p; \
outb(val, hw->ap.port + off); \
} \
static void ReadFiFo##name##_IO(void *p, u8 off, u8 *dp, int size) { \
struct hws *hw = p; \
insb(hw->ap.port + off, dp, size); \
} \
static void WriteFiFo##name##_IO(void *p, u8 off, u8 *dp, int size) { \
struct hws *hw = p; \
outsb(hw->ap.port + off, dp, size); \
}
#define IOFUNC_IND(name, hws, ap) \
static u8 Read##name##_IND(void *p, u8 off) { \
struct hws *hw = p; \
outb(off, hw->ap.ale); \
return inb(hw->ap.port); \
} \
static void Write##name##_IND(void *p, u8 off, u8 val) { \
struct hws *hw = p; \
outb(off, hw->ap.ale); \
outb(val, hw->ap.port); \
} \
static void ReadFiFo##name##_IND(void *p, u8 off, u8 *dp, int size) { \
struct hws *hw = p; \
outb(off, hw->ap.ale); \
insb(hw->ap.port, dp, size); \
} \
static void WriteFiFo##name##_IND(void *p, u8 off, u8 *dp, int size) { \
struct hws *hw = p; \
outb(off, hw->ap.ale); \
outsb(hw->ap.port, dp, size); \
}
#define IOFUNC_MEMIO(name, hws, typ, adr) \
static u8 Read##name##_MIO(void *p, u8 off) { \
struct hws *hw = p; \
return readb(((typ *)hw->adr) + off); \
} \
static void Write##name##_MIO(void *p, u8 off, u8 val) { \
struct hws *hw = p; \
writeb(val, ((typ *)hw->adr) + off); \
} \
static void ReadFiFo##name##_MIO(void *p, u8 off, u8 *dp, int size) { \
struct hws *hw = p; \
while (size--) \
*dp++ = readb(((typ *)hw->adr) + off); \
} \
static void WriteFiFo##name##_MIO(void *p, u8 off, u8 *dp, int size) { \
struct hws *hw = p; \
while (size--) \
writeb(*dp++, ((typ *)hw->adr) + off); \
}
#define ASSIGN_FUNC(typ, name, dest) do { \
dest.read_reg = &Read##name##_##typ; \
dest.write_reg = &Write##name##_##typ; \
dest.read_fifo = &ReadFiFo##name##_##typ; \
dest.write_fifo = &WriteFiFo##name##_##typ; \
} while (0)
#define ASSIGN_FUNC_IPAC(typ, target) do { \
ASSIGN_FUNC(typ, ISAC, target.isac); \
ASSIGN_FUNC(typ, IPAC, target); \
} while (0)
#endif