summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDaniel Scheller <d.scheller@gmx.net>2017-12-26 18:37:58 -0500
committerMauro Carvalho Chehab <mchehab@s-opensource.com>2018-01-03 04:48:07 -0500
commitbdd7682b16988a0fac07f9cf630e4fddb73e161c (patch)
tree4c18e0ce99b35012b9a70b2d9f681109630c81f8
parent8042e98c387b02fc4239eee0075d0f318efcf1d7 (diff)
media: dvb-frontends/stv0910: field and register access helpers
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>
-rw-r--r--drivers/media/dvb-frontends/stv0910.c28
1 files changed, 28 insertions, 0 deletions
diff --git a/drivers/media/dvb-frontends/stv0910.c b/drivers/media/dvb-frontends/stv0910.c
index fa6bb7436b86..1a3b65e43a85 100644
--- a/drivers/media/dvb-frontends/stv0910.c
+++ b/drivers/media/dvb-frontends/stv0910.c
@@ -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 */