14771d831SDaniel Scheller /* SPDX-License-Identifier: GPL-2.0 */
214e27a10SDaniel Scheller /*
314e27a10SDaniel Scheller * ddbridge-io.h: Digital Devices bridge I/O inline functions
414e27a10SDaniel Scheller *
514e27a10SDaniel Scheller * Copyright (C) 2010-2017 Digital Devices GmbH
614e27a10SDaniel Scheller * Ralph Metzler <rjkm@metzlerbros.de>
714e27a10SDaniel Scheller * Marcus Metzler <mocm@metzlerbros.de>
814e27a10SDaniel Scheller */
914e27a10SDaniel Scheller
1014e27a10SDaniel Scheller #ifndef __DDBRIDGE_IO_H__
1114e27a10SDaniel Scheller #define __DDBRIDGE_IO_H__
1214e27a10SDaniel Scheller
1314e27a10SDaniel Scheller #include <linux/io.h>
1414e27a10SDaniel Scheller
1514e27a10SDaniel Scheller #include "ddbridge.h"
1614e27a10SDaniel Scheller
1714e27a10SDaniel Scheller /******************************************************************************/
1814e27a10SDaniel Scheller
ddblreadl(struct ddb_link * link,u32 adr)1914e27a10SDaniel Scheller static inline u32 ddblreadl(struct ddb_link *link, u32 adr)
2014e27a10SDaniel Scheller {
21b5967860SDaniel Scheller return readl(link->dev->regs + adr);
2214e27a10SDaniel Scheller }
2314e27a10SDaniel Scheller
ddblwritel(struct ddb_link * link,u32 val,u32 adr)2414e27a10SDaniel Scheller static inline void ddblwritel(struct ddb_link *link, u32 val, u32 adr)
2514e27a10SDaniel Scheller {
26b5967860SDaniel Scheller writel(val, link->dev->regs + adr);
2714e27a10SDaniel Scheller }
2814e27a10SDaniel Scheller
ddbreadl(struct ddb * dev,u32 adr)2914e27a10SDaniel Scheller static inline u32 ddbreadl(struct ddb *dev, u32 adr)
3014e27a10SDaniel Scheller {
31b5967860SDaniel Scheller return readl(dev->regs + adr);
3214e27a10SDaniel Scheller }
3314e27a10SDaniel Scheller
ddbwritel(struct ddb * dev,u32 val,u32 adr)3414e27a10SDaniel Scheller static inline void ddbwritel(struct ddb *dev, u32 val, u32 adr)
3514e27a10SDaniel Scheller {
36b5967860SDaniel Scheller writel(val, dev->regs + adr);
3714e27a10SDaniel Scheller }
3814e27a10SDaniel Scheller
ddbcpyto(struct ddb * dev,u32 adr,void * src,long count)3914e27a10SDaniel Scheller static inline void ddbcpyto(struct ddb *dev, u32 adr, void *src, long count)
4014e27a10SDaniel Scheller {
41f3eff209SRandy Dunlap memcpy_toio(dev->regs + adr, src, count);
4214e27a10SDaniel Scheller }
4314e27a10SDaniel Scheller
ddbcpyfrom(struct ddb * dev,void * dst,u32 adr,long count)4414e27a10SDaniel Scheller static inline void ddbcpyfrom(struct ddb *dev, void *dst, u32 adr, long count)
4514e27a10SDaniel Scheller {
46f3eff209SRandy Dunlap memcpy_fromio(dst, dev->regs + adr, count);
4714e27a10SDaniel Scheller }
4814e27a10SDaniel Scheller
safe_ddbreadl(struct ddb * dev,u32 adr)4914e27a10SDaniel Scheller static inline u32 safe_ddbreadl(struct ddb *dev, u32 adr)
5014e27a10SDaniel Scheller {
5114e27a10SDaniel Scheller u32 val = ddbreadl(dev, adr);
5214e27a10SDaniel Scheller
5314e27a10SDaniel Scheller /* (ddb)readl returns (uint)-1 (all bits set) on failure, catch that */
5414e27a10SDaniel Scheller if (val == ~0) {
5514e27a10SDaniel Scheller dev_err(&dev->pdev->dev, "ddbreadl failure, adr=%08x\n", adr);
5614e27a10SDaniel Scheller return 0;
5714e27a10SDaniel Scheller }
5814e27a10SDaniel Scheller
5914e27a10SDaniel Scheller return val;
6014e27a10SDaniel Scheller }
6114e27a10SDaniel Scheller
6214e27a10SDaniel Scheller #endif /* __DDBRIDGE_IO_H__ */
63