114e27a10SDaniel Scheller /* 214e27a10SDaniel Scheller * ddbridge-io.h: Digital Devices bridge I/O inline functions 314e27a10SDaniel Scheller * 414e27a10SDaniel Scheller * Copyright (C) 2010-2017 Digital Devices GmbH 514e27a10SDaniel Scheller * Ralph Metzler <rjkm@metzlerbros.de> 614e27a10SDaniel Scheller * Marcus Metzler <mocm@metzlerbros.de> 714e27a10SDaniel Scheller * 814e27a10SDaniel Scheller * This program is free software; you can redistribute it and/or 914e27a10SDaniel Scheller * modify it under the terms of the GNU General Public License 1014e27a10SDaniel Scheller * version 2 only, as published by the Free Software Foundation. 1114e27a10SDaniel Scheller * 1214e27a10SDaniel Scheller * This program is distributed in the hope that it will be useful, 1314e27a10SDaniel Scheller * but WITHOUT ANY WARRANTY; without even the implied warranty of 1414e27a10SDaniel Scheller * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 1514e27a10SDaniel Scheller * GNU General Public License for more details. 1614e27a10SDaniel Scheller * 1714e27a10SDaniel Scheller */ 1814e27a10SDaniel Scheller 1914e27a10SDaniel Scheller #ifndef __DDBRIDGE_IO_H__ 2014e27a10SDaniel Scheller #define __DDBRIDGE_IO_H__ 2114e27a10SDaniel Scheller 2214e27a10SDaniel Scheller #include <linux/io.h> 2314e27a10SDaniel Scheller 2414e27a10SDaniel Scheller #include "ddbridge.h" 2514e27a10SDaniel Scheller 2614e27a10SDaniel Scheller /******************************************************************************/ 2714e27a10SDaniel Scheller 2814e27a10SDaniel Scheller static inline u32 ddblreadl(struct ddb_link *link, u32 adr) 2914e27a10SDaniel Scheller { 3014e27a10SDaniel Scheller return readl((char *) (link->dev->regs + (adr))); 3114e27a10SDaniel Scheller } 3214e27a10SDaniel Scheller 3314e27a10SDaniel Scheller static inline void ddblwritel(struct ddb_link *link, u32 val, u32 adr) 3414e27a10SDaniel Scheller { 3514e27a10SDaniel Scheller writel(val, (char *) (link->dev->regs + (adr))); 3614e27a10SDaniel Scheller } 3714e27a10SDaniel Scheller 3814e27a10SDaniel Scheller static inline u32 ddbreadl(struct ddb *dev, u32 adr) 3914e27a10SDaniel Scheller { 4014e27a10SDaniel Scheller return readl((char *) (dev->regs + (adr))); 4114e27a10SDaniel Scheller } 4214e27a10SDaniel Scheller 4314e27a10SDaniel Scheller static inline void ddbwritel(struct ddb *dev, u32 val, u32 adr) 4414e27a10SDaniel Scheller { 4514e27a10SDaniel Scheller writel(val, (char *) (dev->regs + (adr))); 4614e27a10SDaniel Scheller } 4714e27a10SDaniel Scheller 4814e27a10SDaniel Scheller static inline void ddbcpyto(struct ddb *dev, u32 adr, void *src, long count) 4914e27a10SDaniel Scheller { 5014e27a10SDaniel Scheller return memcpy_toio((char *) (dev->regs + adr), src, count); 5114e27a10SDaniel Scheller } 5214e27a10SDaniel Scheller 5314e27a10SDaniel Scheller static inline void ddbcpyfrom(struct ddb *dev, void *dst, u32 adr, long count) 5414e27a10SDaniel Scheller { 5514e27a10SDaniel Scheller return memcpy_fromio(dst, (char *) (dev->regs + adr), count); 5614e27a10SDaniel Scheller } 5714e27a10SDaniel Scheller 5814e27a10SDaniel Scheller static inline u32 safe_ddbreadl(struct ddb *dev, u32 adr) 5914e27a10SDaniel Scheller { 6014e27a10SDaniel Scheller u32 val = ddbreadl(dev, adr); 6114e27a10SDaniel Scheller 6214e27a10SDaniel Scheller /* (ddb)readl returns (uint)-1 (all bits set) on failure, catch that */ 6314e27a10SDaniel Scheller if (val == ~0) { 6414e27a10SDaniel Scheller dev_err(&dev->pdev->dev, "ddbreadl failure, adr=%08x\n", adr); 6514e27a10SDaniel Scheller return 0; 6614e27a10SDaniel Scheller } 6714e27a10SDaniel Scheller 6814e27a10SDaniel Scheller return val; 6914e27a10SDaniel Scheller } 7014e27a10SDaniel Scheller 7114e27a10SDaniel Scheller #endif /* __DDBRIDGE_IO_H__ */ 72