media: dvb-frontends/stv0910: field and register access helpers
authorDaniel Scheller <d.scheller@gmx.net>
Tue, 26 Dec 2017 23:37:58 +0000 (18:37 -0500)
committerMauro Carvalho Chehab <mchehab@s-opensource.com>
Wed, 3 Jan 2018 09:48:07 +0000 (04:48 -0500)
Add a write_field() function that acts as helper to update specific bits
specified in the field defines (FSTV0910_*) in stv0910_regs.h, which was
recently updated to carry the missing offset values. With that, add the
SET_FIELD(), SET_REG() and GET_REG() macros that wrap the write_field(),
write_reg() and read_reg() functions to allow for making all demod
access code cleaner.

The write_field() function is annotated with __maybe_unused temporarily
to silence eventual compile warnings.

Picked up from the dddvb upstream, with the macro names made uppercase
so they are distinguishable as such.

Cc: Ralph Metzler <rjkm@metzlerbros.de>
Signed-off-by: Daniel Scheller <d.scheller@gmx.net>
Signed-off-by: Mauro Carvalho Chehab <mchehab@s-opensource.com>
drivers/media/dvb-frontends/stv0910.c

index fa6bb7436b8617714489482b492fef221423d17d..1a3b65e43a85bec2793549da5e91aad5f61f17a7 100644 (file)
@@ -194,6 +194,34 @@ static int write_shared_reg(struct stv *state, u16 reg, u8 mask, u8 val)
        return status;
 }
 
+static int __maybe_unused write_field(struct stv *state, u32 field, u8 val)
+{
+       int status;
+       u8 shift, mask, old, new;
+
+       status = read_reg(state, field >> 16, &old);
+       if (status)
+               return status;
+       mask = field & 0xff;
+       shift = (field >> 12) & 0xf;
+       new = ((val << shift) & mask) | (old & ~mask);
+       if (new == old)
+               return 0;
+       return write_reg(state, field >> 16, new);
+}
+
+#define SET_FIELD(_reg, _val)                                  \
+       write_field(state, state->nr ? FSTV0910_P2_##_reg :     \
+                   FSTV0910_P1_##_reg, _val)
+
+#define SET_REG(_reg, _val)                                    \
+       write_reg(state, state->nr ? RSTV0910_P2_##_reg :       \
+                 RSTV0910_P1_##_reg, _val)
+
+#define GET_REG(_reg, _val)                                    \
+       read_reg(state, state->nr ? RSTV0910_P2_##_reg :        \
+                RSTV0910_P1_##_reg, _val)
+
 static const struct slookup s1_sn_lookup[] = {
        {   0,    9242  }, /* C/N=   0dB */
        {   5,    9105  }, /* C/N= 0.5dB */