blob: 1a5b31b524942c8dc5d23ac0daa1a03583f7d461 [file] [log] [blame]
Daniel Scheller4771d832018-06-19 14:50:09 -04001/* SPDX-License-Identifier: GPL-2.0 */
Daniel Scheller14e27a12017-08-12 07:55:53 -04002/*
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 * This program is free software; you can redistribute it and/or
10 * modify it under the terms of the GNU General Public License
11 * version 2 only, as published by the Free Software Foundation.
12 *
13 * This program is distributed in the hope that it will be useful,
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 * GNU General Public License for more details.
Daniel Scheller14e27a12017-08-12 07:55:53 -040017 */
18
19#ifndef __DDBRIDGE_IO_H__
20#define __DDBRIDGE_IO_H__
21
22#include <linux/io.h>
23
24#include "ddbridge.h"
25
26/******************************************************************************/
27
28static inline u32 ddblreadl(struct ddb_link *link, u32 adr)
29{
Daniel Schellerb5967862017-08-23 12:10:00 -040030 return readl(link->dev->regs + adr);
Daniel Scheller14e27a12017-08-12 07:55:53 -040031}
32
33static inline void ddblwritel(struct ddb_link *link, u32 val, u32 adr)
34{
Daniel Schellerb5967862017-08-23 12:10:00 -040035 writel(val, link->dev->regs + adr);
Daniel Scheller14e27a12017-08-12 07:55:53 -040036}
37
38static inline u32 ddbreadl(struct ddb *dev, u32 adr)
39{
Daniel Schellerb5967862017-08-23 12:10:00 -040040 return readl(dev->regs + adr);
Daniel Scheller14e27a12017-08-12 07:55:53 -040041}
42
43static inline void ddbwritel(struct ddb *dev, u32 val, u32 adr)
44{
Daniel Schellerb5967862017-08-23 12:10:00 -040045 writel(val, dev->regs + adr);
Daniel Scheller14e27a12017-08-12 07:55:53 -040046}
47
48static inline void ddbcpyto(struct ddb *dev, u32 adr, void *src, long count)
49{
Randy Dunlapf3eff202017-11-06 13:21:06 -050050 memcpy_toio(dev->regs + adr, src, count);
Daniel Scheller14e27a12017-08-12 07:55:53 -040051}
52
53static inline void ddbcpyfrom(struct ddb *dev, void *dst, u32 adr, long count)
54{
Randy Dunlapf3eff202017-11-06 13:21:06 -050055 memcpy_fromio(dst, dev->regs + adr, count);
Daniel Scheller14e27a12017-08-12 07:55:53 -040056}
57
58static inline u32 safe_ddbreadl(struct ddb *dev, u32 adr)
59{
60 u32 val = ddbreadl(dev, adr);
61
62 /* (ddb)readl returns (uint)-1 (all bits set) on failure, catch that */
63 if (val == ~0) {
64 dev_err(&dev->pdev->dev, "ddbreadl failure, adr=%08x\n", adr);
65 return 0;
66 }
67
68 return val;
69}
70
71#endif /* __DDBRIDGE_IO_H__ */