From patchwork Mon Feb 8 11:51:16 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Antti Palosaari X-Patchwork-Id: 8249001 Return-Path: X-Original-To: patchwork-linux-media@patchwork.kernel.org Delivered-To: patchwork-parsemail@patchwork1.web.kernel.org Received: from mail.kernel.org (mail.kernel.org [198.145.29.136]) by patchwork1.web.kernel.org (Postfix) with ESMTP id C9F149F3CD for ; Mon, 8 Feb 2016 11:51:47 +0000 (UTC) Received: from mail.kernel.org (localhost [127.0.0.1]) by mail.kernel.org (Postfix) with ESMTP id D620B203AE for ; Mon, 8 Feb 2016 11:51:46 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id E96E9203B0 for ; Mon, 8 Feb 2016 11:51:45 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1751293AbcBHLvm (ORCPT ); Mon, 8 Feb 2016 06:51:42 -0500 Received: from mail.kapsi.fi ([217.30.184.167]:35224 "EHLO mail.kapsi.fi" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751240AbcBHLvl (ORCPT ); Mon, 8 Feb 2016 06:51:41 -0500 Received: from dyn3-82-128-191-80.psoas.suomi.net ([82.128.191.80] helo=localhost.localdomain.localdomain) by mail.kapsi.fi with esmtpsa (TLS1.2:DHE_RSA_AES_256_CBC_SHA256:256) (Exim 4.80) (envelope-from ) id 1aSkM0-0000YF-7F; Mon, 08 Feb 2016 13:51:40 +0200 From: Antti Palosaari To: linux-media@vger.kernel.org Cc: Russel Winder , Rune Petersen , Olli Salonen , Antti Palosaari Subject: [PATCH] si2157: detect if firmware is running Date: Mon, 8 Feb 2016 13:51:16 +0200 Message-Id: <1454932276-15780-2-git-send-email-crope@iki.fi> X-Mailer: git-send-email 2.4.3 In-Reply-To: <1454932276-15780-1-git-send-email-crope@iki.fi> References: <1454932276-15780-1-git-send-email-crope@iki.fi> X-SA-Exim-Connect-IP: 82.128.191.80 X-SA-Exim-Mail-From: crope@iki.fi X-SA-Exim-Scanned: No (on mail.kapsi.fi); SAEximRunCond expanded to false Sender: linux-media-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-media@vger.kernel.org X-Spam-Status: No, score=-7.2 required=5.0 tests=BAYES_00, RCVD_IN_DNSWL_HI, RP_MATCHES_RCVD, UNPARSEABLE_RELAY autolearn=ham version=3.3.1 X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on mail.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP Detect if firmware is running run-time and download / start it only when needed. Detection is done by reading IF frequency value. Garbage value is returned by firmware when it is not running, otherwise correct value is returned. Signed-off-by: Antti Palosaari --- drivers/media/tuners/si2157.c | 19 +++++++++++++------ drivers/media/tuners/si2157_priv.h | 1 - 2 files changed, 13 insertions(+), 7 deletions(-) diff --git a/drivers/media/tuners/si2157.c b/drivers/media/tuners/si2157.c index 3450dfb..8cd2bb3 100644 --- a/drivers/media/tuners/si2157.c +++ b/drivers/media/tuners/si2157.c @@ -84,11 +84,22 @@ static int si2157_init(struct dvb_frontend *fe) struct si2157_cmd cmd; const struct firmware *fw; const char *fw_name; - unsigned int chip_id; + unsigned int uitmp, chip_id; dev_dbg(&client->dev, "\n"); - if (dev->fw_loaded) + /* Returned IF frequency is garbage when firmware is not running */ + memcpy(cmd.args, "\x15\x00\x06\x07", 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); + + if (uitmp == dev->if_frequency / 1000) goto warm; /* power up */ @@ -203,9 +214,6 @@ skip_fw_download: dev_info(&client->dev, "firmware version: %c.%c.%d\n", cmd.args[6], cmd.args[7], cmd.args[8]); - - dev->fw_loaded = true; - warm: /* init statistics in order signal app which are supported */ c->strength.len = 1; @@ -422,7 +430,6 @@ static int si2157_probe(struct i2c_client *client, dev->fe = cfg->fe; dev->inversion = cfg->inversion; dev->if_port = cfg->if_port; - dev->fw_loaded = false; dev->chiptype = (u8)id->driver_data; dev->if_frequency = 5000000; /* default value of property 0x0706 */ mutex_init(&dev->i2c_mutex); diff --git a/drivers/media/tuners/si2157_priv.h b/drivers/media/tuners/si2157_priv.h index ecc463d..e801acc 100644 --- a/drivers/media/tuners/si2157_priv.h +++ b/drivers/media/tuners/si2157_priv.h @@ -25,7 +25,6 @@ struct si2157_dev { struct mutex i2c_mutex; struct dvb_frontend *fe; bool active; - bool fw_loaded; bool inversion; u8 chiptype; u8 if_port;