The Linux Kernel Mailing List
 help / color / mirror / Atom feed
From: Punnay299 <punnaysharma805@gmail.com>
To: gregkh@linuxfoundation.org, mchehab@kernel.org
Cc: linux-media@vger.kernel.org, linux-staging@lists.linux.dev,
	linux-kernel@vger.kernel.org,
	Punnay299 <punnaysharma805@gmail.com>
Subject: [PATCH] staging: media: av7110: fix sp8870 initialization and hardware communication
Date: Fri,  7 Aug 2026 21:31:49 +0530	[thread overview]
Message-ID: <20260807160149.41580-1-punnaysharma805@gmail.com> (raw)

Address multiple correctness issues in the sp8870 demodulator:
- Fix BER reporting in sp8870_read_ber() by correctly ORing the upper bits.
- Set state->initialised only after successful firmware upload in sp8870_init() to allow recovery from transient I2C failures.
- Catch partial I2C transfers (err == 0) in sp8870_firmware_upload() and return -EREMOTEIO to prevent silent firmware corruption.

Signed-off-by: Punnay299 <punnaysharma805@gmail.com>
---
 drivers/staging/media/av7110/sp8870.c | 16 ++++++++++------
 1 file changed, 10 insertions(+), 6 deletions(-)

diff --git a/drivers/staging/media/av7110/sp8870.c b/drivers/staging/media/av7110/sp8870.c
index 29fb4934c..def2a7f0c 100644
--- a/drivers/staging/media/av7110/sp8870.c
+++ b/drivers/staging/media/av7110/sp8870.c
@@ -68,7 +68,8 @@ static int sp8870_writereg(struct sp8870_state *state, u16 reg, u16 data)
 
 	err = i2c_transfer(state->i2c, &msg, 1);
 	if (err != 1) {
-		dprintk("writereg error (err == %i, reg == 0x%02x, data == 0x%02x)\n", err, reg, data);
+		dprintk("writereg error (err == %i, reg == 0x%02x, data == 0x%02x)\n",
+			err, reg, data);
 		return -EREMOTEIO;
 	}
 
@@ -135,7 +136,7 @@ static int sp8870_firmware_upload(struct sp8870_state *state, const struct firmw
 		if (err != 1) {
 			pr_err("%s(): firmware upload failed!\n", __func__);
 			pr_err("%s(): i2c error (err == %i)\n", __func__, err);
-			return err;
+			return err < 0 ? err : -EREMOTEIO;
 		}
 		fw_pos += tx_len;
 	}
@@ -315,7 +316,6 @@ static int sp8870_init(struct dvb_frontend *fe)
 	sp8870_wake_up(state);
 	if (state->initialised)
 		return 0;
-	state->initialised = 1;
 
 	dprintk("initialising frontend...\n");
 
@@ -353,6 +353,8 @@ static int sp8870_init(struct dvb_frontend *fe)
 	sp8870_writereg(state, 0x0D00, 0x010);
 	sp8870_writereg(state, 0x0D01, 0x000);
 
+	state->initialised = 1;
+
 	return 0;
 }
 
@@ -401,7 +403,7 @@ static int sp8870_read_ber(struct dvb_frontend *fe, u32 *ber)
 	if (ret < 0)
 		return -EIO;
 
-	tmp = ret << 6;
+	tmp |= ret << 6;
 	if (tmp >= 0x3FFF0)
 		tmp = ~0;
 
@@ -511,7 +513,8 @@ static int sp8870_set_frontend(struct dvb_frontend *fe)
 		if (valid) {
 			if (trials > 1) {
 				pr_info("%s(): firmware lockup!!!\n", __func__);
-				pr_info("%s(): recovered after %i trial(s))\n",  __func__, trials - 1);
+				pr_info("%s(): recovered after %i trial(s))\n",
+					__func__, trials - 1);
 				lockups++;
 			}
 		}
@@ -530,7 +533,8 @@ static int sp8870_sleep(struct dvb_frontend *fe)
 	return sp8870_writereg(state, 0xC18, 0x000);
 }
 
-static int sp8870_get_tune_settings(struct dvb_frontend *fe, struct dvb_frontend_tune_settings *fesettings)
+static int sp8870_get_tune_settings(struct dvb_frontend *fe,
+				    struct dvb_frontend_tune_settings *fesettings)
 {
 	fesettings->min_delay_ms = 350;
 	fesettings->step_size = 0;
-- 
2.55.0


             reply	other threads:[~2026-08-07 16:02 UTC|newest]

Thread overview: 2+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-08-07 16:01 Punnay299 [this message]
2026-08-07 17:07 ` [PATCH] staging: media: av7110: fix sp8870 initialization and hardware communication Dan Carpenter

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=20260807160149.41580-1-punnaysharma805@gmail.com \
    --to=punnaysharma805@gmail.com \
    --cc=gregkh@linuxfoundation.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-media@vger.kernel.org \
    --cc=linux-staging@lists.linux.dev \
    --cc=mchehab@kernel.org \
    /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