1 /* SPDX-License-Identifier: GPL-2.0 */
3 * Copyright (c) 2015 Endless Mobile, Inc.
4 * Author: Carlo Caione <carlo@endlessm.com>
10 #include <linux/bits.h>
11 #include <linux/regmap.h>
13 #define PMASK(width) GENMASK(width - 1, 0)
14 #define SETPMASK(width, shift) GENMASK(shift + width - 1, shift)
15 #define CLRPMASK(width, shift) (~SETPMASK(width, shift))
17 #define PARM_GET(width, shift, reg) \
18 (((reg) & SETPMASK(width, shift)) >> (shift))
19 #define PARM_SET(width, shift, reg, val) \
20 (((reg) & CLRPMASK(width, shift)) | ((val) << (shift)))
22 #define MESON_PARM_APPLICABLE(p) (!!((p)->width))
30 static inline unsigned int meson_parm_read(struct regmap
*map
, struct parm
*p
)
34 regmap_read(map
, p
->reg_off
, &val
);
35 return PARM_GET(p
->width
, p
->shift
, val
);
38 static inline void meson_parm_write(struct regmap
*map
, struct parm
*p
,
41 regmap_update_bits(map
, p
->reg_off
, SETPMASK(p
->width
, p
->shift
),
45 #endif /* __MESON_PARM_H */