Back to home page

OSCL-LXR

 
 

    


0001 /* SPDX-License-Identifier: GPL-2.0 */
0002 /*
0003  * Copyright (c) 2015 Endless Mobile, Inc.
0004  * Author: Carlo Caione <carlo@endlessm.com>
0005  */
0006 
0007 #ifndef __MESON_PARM_H
0008 #define __MESON_PARM_H
0009 
0010 #include <linux/bits.h>
0011 #include <linux/regmap.h>
0012 
0013 #define PMASK(width)            GENMASK(width - 1, 0)
0014 #define SETPMASK(width, shift)      GENMASK(shift + width - 1, shift)
0015 #define CLRPMASK(width, shift)      (~SETPMASK(width, shift))
0016 
0017 #define PARM_GET(width, shift, reg)                 \
0018     (((reg) & SETPMASK(width, shift)) >> (shift))
0019 #define PARM_SET(width, shift, reg, val)                \
0020     (((reg) & CLRPMASK(width, shift)) | ((val) << (shift)))
0021 
0022 #define MESON_PARM_APPLICABLE(p)        (!!((p)->width))
0023 
0024 struct parm {
0025     u16 reg_off;
0026     u8  shift;
0027     u8  width;
0028 };
0029 
0030 static inline unsigned int meson_parm_read(struct regmap *map, struct parm *p)
0031 {
0032     unsigned int val;
0033 
0034     regmap_read(map, p->reg_off, &val);
0035     return PARM_GET(p->width, p->shift, val);
0036 }
0037 
0038 static inline void meson_parm_write(struct regmap *map, struct parm *p,
0039                     unsigned int val)
0040 {
0041     regmap_update_bits(map, p->reg_off, SETPMASK(p->width, p->shift),
0042                val << p->shift);
0043 }
0044 
0045 #endif /* __MESON_PARM_H */
0046