1 /* SPDX-License-Identifier: GPL-2.0-only */
2 /*
3 * Copyright (C) 2021-2022 Digiteq Automotive
4 * author: Martin Tuma <martin.tuma@digiteqautomotive.com>
5 */
6
7 #ifndef __MGB4_REGS_H__
8 #define __MGB4_REGS_H__
9
10 #include <linux/io.h>
11
12 struct mgb4_regs {
13 resource_size_t mapbase;
14 resource_size_t mapsize;
15 void __iomem *membase;
16 };
17
18 #define mgb4_write_reg(regs, offset, val) \
19 iowrite32(val, (regs)->membase + (offset))
20 #define mgb4_read_reg(regs, offset) \
21 ioread32((regs)->membase + (offset))
22
mgb4_mask_reg(struct mgb4_regs * regs,u32 reg,u32 mask,u32 val)23 static inline void mgb4_mask_reg(struct mgb4_regs *regs, u32 reg, u32 mask,
24 u32 val)
25 {
26 u32 ret = mgb4_read_reg(regs, reg);
27
28 val |= ret & ~mask;
29 mgb4_write_reg(regs, reg, val);
30 }
31
32 int mgb4_regs_map(struct resource *res, struct mgb4_regs *regs);
33 void mgb4_regs_free(struct mgb4_regs *regs);
34
35 #endif
36