diff mbox series

[v3,03/14] si2157: Better check for running tuner in init

Message ID 20191114200408.28883-4-brad@nextdimension.cc (mailing list archive)
State New, archived
Headers show
Series si2157: Analog tuning and optimizations | expand

Commit Message

Brad Love Nov. 14, 2019, 8:03 p.m. UTC
Getting the Xtal trim property to check if running is less error prone.
Reset if_frequency if state is unknown.

Replaces the previous "garbage check".

Signed-off-by: Brad Love <brad@nextdimension.cc>
---
No changes

 drivers/media/tuners/si2157.c | 15 +++++++--------
 1 file changed, 7 insertions(+), 8 deletions(-)

Comments

Antti Palosaari Nov. 15, 2019, 11:16 a.m. UTC | #1
On 11/14/19 10:03 PM, Brad Love wrote:
> Getting the Xtal trim property to check if running is less error prone.
> Reset if_frequency if state is unknown.
> 
> Replaces the previous "garbage check".
> 
> Signed-off-by: Brad Love <brad@nextdimension.cc>
> ---
> No changes
> 
>   drivers/media/tuners/si2157.c | 15 +++++++--------
>   1 file changed, 7 insertions(+), 8 deletions(-)
> 
> diff --git a/drivers/media/tuners/si2157.c b/drivers/media/tuners/si2157.c
> index 69c625eaee25..e1e23e78fd19 100644
> --- a/drivers/media/tuners/si2157.c
> +++ b/drivers/media/tuners/si2157.c
> @@ -81,24 +81,23 @@ static int si2157_init(struct dvb_frontend *fe)
>   	struct si2157_cmd cmd;
>   	const struct firmware *fw;
>   	const char *fw_name;
> -	unsigned int uitmp, chip_id;
> +	unsigned int chip_id, xtal_trim;
>   
>   	dev_dbg(&client->dev, "\n");
>   
> -	/* Returned IF frequency is garbage when firmware is not running */
> -	memcpy(cmd.args, "\x15\x00\x06\x07", 4);
> +	/* Try to get Xtal trim property, to verify tuner still running */
> +	memcpy(cmd.args, "\x15\x00\x04\x02", 4);
>   	cmd.wlen = 4;
>   	cmd.rlen = 4;
>   	ret = si2157_cmd_execute(client, &cmd);
> -	if (ret)
> -		goto err;
>   
> -	uitmp = cmd.args[2] << 0 | cmd.args[3] << 8;
> -	dev_dbg(&client->dev, "if_frequency kHz=%u\n", uitmp);
> +	xtal_trim = cmd.args[2] | (cmd.args[3] << 8);
>   
> -	if (uitmp == dev->if_frequency / 1000)
> +	if (ret == 0 && xtal_trim < 16)
>   		goto warm;

Defining new variable does not make code clearer, uitmp used earlier was 
just fine as value was used just next line or so. You just need to 
change two or three line or so here.

Checking xtal trim sounds still a bit elegant than old method.

>   
> +	dev->if_frequency = 0; /* we no longer know current tuner state */
> +

hmmm, what is idea of that?

>   	/* power up */
>   	if (dev->chiptype == SI2157_CHIPTYPE_SI2146) {
>   		memcpy(cmd.args, "\xc0\x05\x01\x00\x00\x0b\x00\x00\x01", 9);
>
diff mbox series

Patch

diff --git a/drivers/media/tuners/si2157.c b/drivers/media/tuners/si2157.c
index 69c625eaee25..e1e23e78fd19 100644
--- a/drivers/media/tuners/si2157.c
+++ b/drivers/media/tuners/si2157.c
@@ -81,24 +81,23 @@  static int si2157_init(struct dvb_frontend *fe)
 	struct si2157_cmd cmd;
 	const struct firmware *fw;
 	const char *fw_name;
-	unsigned int uitmp, chip_id;
+	unsigned int chip_id, xtal_trim;
 
 	dev_dbg(&client->dev, "\n");
 
-	/* Returned IF frequency is garbage when firmware is not running */
-	memcpy(cmd.args, "\x15\x00\x06\x07", 4);
+	/* Try to get Xtal trim property, to verify tuner still running */
+	memcpy(cmd.args, "\x15\x00\x04\x02", 4);
 	cmd.wlen = 4;
 	cmd.rlen = 4;
 	ret = si2157_cmd_execute(client, &cmd);
-	if (ret)
-		goto err;
 
-	uitmp = cmd.args[2] << 0 | cmd.args[3] << 8;
-	dev_dbg(&client->dev, "if_frequency kHz=%u\n", uitmp);
+	xtal_trim = cmd.args[2] | (cmd.args[3] << 8);
 
-	if (uitmp == dev->if_frequency / 1000)
+	if (ret == 0 && xtal_trim < 16)
 		goto warm;
 
+	dev->if_frequency = 0; /* we no longer know current tuner state */
+
 	/* power up */
 	if (dev->chiptype == SI2157_CHIPTYPE_SI2146) {
 		memcpy(cmd.args, "\xc0\x05\x01\x00\x00\x0b\x00\x00\x01", 9);