linux-media.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Daniel Scheller <d.scheller.oss@gmail.com>
To: linux-media@vger.kernel.org, mchehab@kernel.org,
	mchehab@s-opensource.com
Cc: Ralph Metzler <rjkm@metzlerbros.de>
Subject: [PATCH 3/4] [media] dvb-frontends/stv0910: field and register access helpers
Date: Wed, 27 Dec 2017 00:37:58 +0100	[thread overview]
Message-ID: <20171226233759.16116-4-d.scheller.oss@gmail.com> (raw)
In-Reply-To: <20171226233759.16116-1-d.scheller.oss@gmail.com>

From: Daniel Scheller <d.scheller@gmx.net>

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>
---
 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

  parent reply	other threads:[~2017-12-26 23:38 UTC|newest]

Thread overview: 5+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2017-12-26 23:37 [PATCH 0/4] stv0910: upstream changes and PLS support Daniel Scheller
2017-12-26 23:37 ` [PATCH 1/4] [media] dvb-frontends/stv0910: deduplicate writes in enable_puncture_rate() Daniel Scheller
2017-12-26 23:37 ` [PATCH 2/4] [media] dvb-frontends/stv0910: cleanup I2C access functions Daniel Scheller
2017-12-26 23:37 ` Daniel Scheller [this message]
2017-12-26 23:37 ` [PATCH 4/4] [media] dvb-frontends/stv0910: cleanup init_search_param() and enable PLS Daniel Scheller

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20171226233759.16116-4-d.scheller.oss@gmail.com \
    --to=d.scheller.oss@gmail.com \
    --cc=linux-media@vger.kernel.org \
    --cc=mchehab@kernel.org \
    --cc=mchehab@s-opensource.com \
    --cc=rjkm@metzlerbros.de \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).