From: Daniel Scheller <d.scheller@xxxxxxx> 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@xxxxxxxxxxxxxx> Signed-off-by: Daniel Scheller <d.scheller@xxxxxxx> --- drivers/media/dvb-frontends/stv0910.c | 28 ++++++++++++++++++++++++++++ 1 file changed, 28 insertions(+) diff --git a/drivers/media/dvb-frontends/stv0910.c b/drivers/media/dvb-frontends/stv0910.c index 06d2587125dd..5fed22685e28 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 */ -- 2.13.6