Path: blob/master/drivers/isdn/hardware/mISDN/iohelper.h
15111 views
/*1* iohelper.h2* helper for define functions to access ISDN hardware3* supported are memory mapped IO4* indirect port IO (one port for address, one for data)5*6* Author Karsten Keil <[email protected]>7*8* Copyright 2009 by Karsten Keil <[email protected]>9*10* This program is free software; you can redistribute it and/or modify11* it under the terms of the GNU General Public License version 2 as12* published by the Free Software Foundation.13*14* This program is distributed in the hope that it will be useful,15* but WITHOUT ANY WARRANTY; without even the implied warranty of16* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the17* GNU General Public License for more details.18*19* You should have received a copy of the GNU General Public License20* along with this program; if not, write to the Free Software21* Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.22*23*/2425#ifndef _IOHELPER_H26#define _IOHELPER_H2728typedef u8 (read_reg_func)(void *hwp, u8 offset);29typedef void (write_reg_func)(void *hwp, u8 offset, u8 value);30typedef void (fifo_func)(void *hwp, u8 offset, u8 *datap, int size);3132struct _ioport {33u32 port;34u32 ale;35};3637#define IOFUNC_IO(name, hws, ap) \38static u8 Read##name##_IO(void *p, u8 off) {\39struct hws *hw = p;\40return inb(hw->ap.port + off);\41} \42static void Write##name##_IO(void *p, u8 off, u8 val) {\43struct hws *hw = p;\44outb(val, hw->ap.port + off);\45} \46static void ReadFiFo##name##_IO(void *p, u8 off, u8 *dp, int size) {\47struct hws *hw = p;\48insb(hw->ap.port + off, dp, size);\49} \50static void WriteFiFo##name##_IO(void *p, u8 off, u8 *dp, int size) {\51struct hws *hw = p;\52outsb(hw->ap.port + off, dp, size);\53}5455#define IOFUNC_IND(name, hws, ap) \56static u8 Read##name##_IND(void *p, u8 off) {\57struct hws *hw = p;\58outb(off, hw->ap.ale);\59return inb(hw->ap.port);\60} \61static void Write##name##_IND(void *p, u8 off, u8 val) {\62struct hws *hw = p;\63outb(off, hw->ap.ale);\64outb(val, hw->ap.port);\65} \66static void ReadFiFo##name##_IND(void *p, u8 off, u8 *dp, int size) {\67struct hws *hw = p;\68outb(off, hw->ap.ale);\69insb(hw->ap.port, dp, size);\70} \71static void WriteFiFo##name##_IND(void *p, u8 off, u8 *dp, int size) {\72struct hws *hw = p;\73outb(off, hw->ap.ale);\74outsb(hw->ap.port, dp, size);\75}7677#define IOFUNC_MEMIO(name, hws, typ, adr) \78static u8 Read##name##_MIO(void *p, u8 off) {\79struct hws *hw = p;\80return readb(((typ *)hw->adr) + off);\81} \82static void Write##name##_MIO(void *p, u8 off, u8 val) {\83struct hws *hw = p;\84writeb(val, ((typ *)hw->adr) + off);\85} \86static void ReadFiFo##name##_MIO(void *p, u8 off, u8 *dp, int size) {\87struct hws *hw = p;\88while (size--)\89*dp++ = readb(((typ *)hw->adr) + off);\90} \91static void WriteFiFo##name##_MIO(void *p, u8 off, u8 *dp, int size) {\92struct hws *hw = p;\93while (size--)\94writeb(*dp++, ((typ *)hw->adr) + off);\95}9697#define ASSIGN_FUNC(typ, name, dest) do {\98dest.read_reg = &Read##name##_##typ;\99dest.write_reg = &Write##name##_##typ;\100dest.read_fifo = &ReadFiFo##name##_##typ;\101dest.write_fifo = &WriteFiFo##name##_##typ;\102} while (0)103#define ASSIGN_FUNC_IPAC(typ, target) do {\104ASSIGN_FUNC(typ, ISAC, target.isac);\105ASSIGN_FUNC(typ, IPAC, target);\106} while (0)107108#endif109110111