David Brazdil | 0f672f6 | 2019-12-10 10:32:29 +0000 | [diff] [blame^] | 1 | /* SPDX-License-Identifier: GPL-2.0 */ |
Andrew Scull | b4b6d4a | 2019-01-02 15:54:55 +0000 | [diff] [blame] | 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 | * 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. |
Andrew Scull | b4b6d4a | 2019-01-02 15:54:55 +0000 | [diff] [blame] | 17 | */ |
| 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 | |
| 28 | static inline u32 ddblreadl(struct ddb_link *link, u32 adr) |
| 29 | { |
| 30 | return readl(link->dev->regs + adr); |
| 31 | } |
| 32 | |
| 33 | static inline void ddblwritel(struct ddb_link *link, u32 val, u32 adr) |
| 34 | { |
| 35 | writel(val, link->dev->regs + adr); |
| 36 | } |
| 37 | |
| 38 | static inline u32 ddbreadl(struct ddb *dev, u32 adr) |
| 39 | { |
| 40 | return readl(dev->regs + adr); |
| 41 | } |
| 42 | |
| 43 | static inline void ddbwritel(struct ddb *dev, u32 val, u32 adr) |
| 44 | { |
| 45 | writel(val, dev->regs + adr); |
| 46 | } |
| 47 | |
| 48 | static inline void ddbcpyto(struct ddb *dev, u32 adr, void *src, long count) |
| 49 | { |
| 50 | memcpy_toio(dev->regs + adr, src, count); |
| 51 | } |
| 52 | |
| 53 | static inline void ddbcpyfrom(struct ddb *dev, void *dst, u32 adr, long count) |
| 54 | { |
| 55 | memcpy_fromio(dst, dev->regs + adr, count); |
| 56 | } |
| 57 | |
| 58 | static 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__ */ |