1 /* SPDX-License-Identifier: GPL-2.0 */
2 /*
3  * ddbridge-io.h: Digital Devices bridge I/O inline functions
4  *
5  * Copyright (C) 2010-2017 Digital Devices GmbH
6  *                         Ralph Metzler <rjkm@metzlerbros.de>
7  *                         Marcus Metzler <mocm@metzlerbros.de>
8  */
9 
10 #ifndef __DDBRIDGE_IO_H__
11 #define __DDBRIDGE_IO_H__
12 
13 #include <linux/io.h>
14 
15 #include "ddbridge.h"
16 
17 /******************************************************************************/
18 
ddblreadl(struct ddb_link * link,u32 adr)19 static inline u32 ddblreadl(struct ddb_link *link, u32 adr)
20 {
21 	return readl(link->dev->regs + adr);
22 }
23 
ddblwritel(struct ddb_link * link,u32 val,u32 adr)24 static inline void ddblwritel(struct ddb_link *link, u32 val, u32 adr)
25 {
26 	writel(val, link->dev->regs + adr);
27 }
28 
ddbreadl(struct ddb * dev,u32 adr)29 static inline u32 ddbreadl(struct ddb *dev, u32 adr)
30 {
31 	return readl(dev->regs + adr);
32 }
33 
ddbwritel(struct ddb * dev,u32 val,u32 adr)34 static inline void ddbwritel(struct ddb *dev, u32 val, u32 adr)
35 {
36 	writel(val, dev->regs + adr);
37 }
38 
ddbcpyto(struct ddb * dev,u32 adr,void * src,long count)39 static inline void ddbcpyto(struct ddb *dev, u32 adr, void *src, long count)
40 {
41 	memcpy_toio(dev->regs + adr, src, count);
42 }
43 
ddbcpyfrom(struct ddb * dev,void * dst,u32 adr,long count)44 static inline void ddbcpyfrom(struct ddb *dev, void *dst, u32 adr, long count)
45 {
46 	memcpy_fromio(dst, dev->regs + adr, count);
47 }
48 
safe_ddbreadl(struct ddb * dev,u32 adr)49 static inline u32 safe_ddbreadl(struct ddb *dev, u32 adr)
50 {
51 	u32 val = ddbreadl(dev, adr);
52 
53 	/* (ddb)readl returns (uint)-1 (all bits set) on failure, catch that */
54 	if (val == ~0) {
55 		dev_err(&dev->pdev->dev, "ddbreadl failure, adr=%08x\n", adr);
56 		return 0;
57 	}
58 
59 	return val;
60 }
61 
62 #endif /* __DDBRIDGE_IO_H__ */
63