Received: by 2002:a25:4158:0:0:0:0:0 with SMTP id o85csp1822683yba; Sat, 27 Apr 2019 07:53:12 -0700 (PDT) X-Google-Smtp-Source: APXvYqwJeMbS7CLigMgZvvQbGDSWSjGTxbl5aZW8jNR3XczRdZAVL2kM/XnadaRq6ODyHKe0dK+t X-Received: by 2002:aa7:8008:: with SMTP id j8mr24905224pfi.120.1556376791962; Sat, 27 Apr 2019 07:53:11 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1556376791; cv=none; d=google.com; s=arc-20160816; b=oKY08RqK3DHt1TAbJJqGKnCJ7vIx1gx96bNUuYFZ+Hs8oyR5b8Uq4Cn0tkmRI3kQ8k h/G+ZfPoNhUQUEoPgigmqt5FdRznm4xTf9s1654agpfIPJhPH6klb9+FxHJyMBZPpSGF h1V9s+Q4YbJl2dZ37Rf7z039vJmbT/mu6TJbIgafbZvOJ+aRrDSJtpnCS7wm+hcE/KBt uhKXJ0bXqPoBVII7p9NXfs4aQIGHsdDLPohCjPPJXqk7AFJZmKPM1A5XD8LZSVgSYhXF O6ma5A+DlvLKwLp2GSeqwDL1yIDYblhNMkdTVd5aoRsdyulJQxfRoVgLI0r1VjVe8n5M JnMA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from; bh=CREEthRik9L85lISGu4KD9eWBCBm57W5yTXVtO0WkB4=; b=ksASUnr2OjShaGen0PrKTW4anN8VkzcPMLoublCFuJKs9/idC5AH13WPh86DMR5C9/ 30h7sMRk3ZHQg0zOE6r/uaYSi0qBLZMJmEIfpOZef/cHyZhxGQMlwbe1nBb4BvMTSTWp bTEpHt6th7KmQ8yI4YuLhGf7EFZhFZVVz7pPsuc/9+watHQjuuhmL5Evzr3XsI2QyqQX ENEKb9PVUiZHUKpxqEyvfBWVGMw6KllsGJG7f01Fyot/oA3yVHVgNQwMSBzFPgcxt3hB 460i8/GLjE/IXa888sPcYAmfpFPYIbb9ptO4E4vNqAesULklMmXWKL2YpgiGencDHgsL Vh/g== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id f7si9366377plo.204.2019.04.27.07.52.56; Sat, 27 Apr 2019 07:53:11 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726608AbfD0Ouw (ORCPT + 99 others); Sat, 27 Apr 2019 10:50:52 -0400 Received: from vps-vb.mhejs.net ([37.28.154.113]:49388 "EHLO vps-vb.mhejs.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1725942AbfD0Ouu (ORCPT ); Sat, 27 Apr 2019 10:50:50 -0400 Received: from MUA by vps-vb.mhejs.net with esmtps (TLSv1.2:ECDHE-RSA-AES256-GCM-SHA384:256) (Exim 4.90_1) (envelope-from ) id 1hKOf7-0007zU-KA; Sat, 27 Apr 2019 16:50:45 +0200 From: "Maciej S. Szmigiero" To: Michael Krufky , Mauro Carvalho Chehab Cc: Andy Walls , linux-kernel , linux-media@vger.kernel.org, Hans Verkuil Subject: [PATCH v11 1/7] cx25840: don't open-code cx25840_reset() inside cx25840_load_fw() Date: Sat, 27 Apr 2019 16:50:28 +0200 Message-Id: X-Mailer: git-send-email 2.21.0 In-Reply-To: References: MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org cx25840_load_fw() does the same thing as cx25840_reset(), only keeps "is_initialized" flag so any further invocation of this function besides the first one is a NOP. Let's just call cx25840_reset() directly from cx25840_load_fw() instead of open coding it there. While we are at it, let's also improve comments about cx25840_load_fw() so they are current and in the proper style (one of them even referred to a non-existing cx25840 init operation). Signed-off-by: Maciej S. Szmigiero --- drivers/media/i2c/cx25840/cx25840-core.c | 70 ++++++++++++------------ include/media/drv-intf/cx25840.h | 28 ++++++---- 2 files changed, 51 insertions(+), 47 deletions(-) diff --git a/drivers/media/i2c/cx25840/cx25840-core.c b/drivers/media/i2c/cx25840/cx25840-core.c index 8b0b8b5aa531..0bf30222cf93 100644 --- a/drivers/media/i2c/cx25840/cx25840-core.c +++ b/drivers/media/i2c/cx25840/cx25840-core.c @@ -1649,32 +1649,46 @@ static void log_audio_status(struct i2c_client *client) /* ----------------------------------------------------------------------- */ -/* This load_fw operation must be called to load the driver's firmware. - Without this the audio standard detection will fail and you will - only get mono. - - Since loading the firmware is often problematic when the driver is - compiled into the kernel I recommend postponing calling this function - until the first open of the video device. Another reason for - postponing it is that loading this firmware takes a long time (seconds) - due to the slow i2c bus speed. So it will speed up the boot process if - you can avoid loading the fw as long as the video device isn't used. */ -static int cx25840_load_fw(struct v4l2_subdev *sd) +static int cx25840_reset(struct v4l2_subdev *sd, u32 val) { struct cx25840_state *state = to_state(sd); struct i2c_client *client = v4l2_get_subdevdata(sd); + if (is_cx2583x(state)) + cx25836_initialize(client); + else if (is_cx2388x(state)) + cx23885_initialize(client); + else if (is_cx231xx(state)) + cx231xx_initialize(client); + else + cx25840_initialize(client); + + state->is_initialized = 1; + + return 0; +} + +/* + * This load_fw operation must be called to load the driver's firmware. + * This will load the firmware on the first invocation (further ones are NOP). + * Without this the audio standard detection will fail and you will + * only get mono. + * Alternatively, you can call the reset operation instead of this one. + * + * Since loading the firmware is often problematic when the driver is + * compiled into the kernel I recommend postponing calling this function + * until the first open of the video device. Another reason for + * postponing it is that loading this firmware takes a long time (seconds) + * due to the slow i2c bus speed. So it will speed up the boot process if + * you can avoid loading the fw as long as the video device isn't used. + */ +static int cx25840_load_fw(struct v4l2_subdev *sd) +{ + struct cx25840_state *state = to_state(sd); + if (!state->is_initialized) { /* initialize and load firmware */ - state->is_initialized = 1; - if (is_cx2583x(state)) - cx25836_initialize(client); - else if (is_cx2388x(state)) - cx23885_initialize(client); - else if (is_cx231xx(state)) - cx231xx_initialize(client); - else - cx25840_initialize(client); + cx25840_reset(sd, 0); } return 0; } @@ -1937,22 +1951,6 @@ static int cx25840_s_tuner(struct v4l2_subdev *sd, const struct v4l2_tuner *vt) return 0; } -static int cx25840_reset(struct v4l2_subdev *sd, u32 val) -{ - struct cx25840_state *state = to_state(sd); - struct i2c_client *client = v4l2_get_subdevdata(sd); - - if (is_cx2583x(state)) - cx25836_initialize(client); - else if (is_cx2388x(state)) - cx23885_initialize(client); - else if (is_cx231xx(state)) - cx231xx_initialize(client); - else - cx25840_initialize(client); - return 0; -} - static int cx25840_log_status(struct v4l2_subdev *sd) { struct cx25840_state *state = to_state(sd); diff --git a/include/media/drv-intf/cx25840.h b/include/media/drv-intf/cx25840.h index 783c5bdd63eb..ccbfe72b5d6e 100644 --- a/include/media/drv-intf/cx25840.h +++ b/include/media/drv-intf/cx25840.h @@ -21,17 +21,23 @@ #ifndef _CX25840_H_ #define _CX25840_H_ -/* Note that the cx25840 driver requires that the bridge driver calls the - v4l2_subdev's init operation in order to load the driver's firmware. - Without this the audio standard detection will fail and you will - only get mono. - - Since loading the firmware is often problematic when the driver is - compiled into the kernel I recommend postponing calling this function - until the first open of the video device. Another reason for - postponing it is that loading this firmware takes a long time (seconds) - due to the slow i2c bus speed. So it will speed up the boot process if - you can avoid loading the fw as long as the video device isn't used. */ +/* + * Note that the cx25840 driver requires that the bridge driver calls the + * v4l2_subdev's load_fw operation in order to load the driver's firmware. + * This will load the firmware on the first invocation (further ones are NOP). + * Without this the audio standard detection will fail and you will + * only get mono. + * Alternatively, you can call the reset operation (this can be done + * multiple times if needed, each invocation will fully reinitialize + * the device). + * + * Since loading the firmware is often problematic when the driver is + * compiled into the kernel I recommend postponing calling this function + * until the first open of the video device. Another reason for + * postponing it is that loading this firmware takes a long time (seconds) + * due to the slow i2c bus speed. So it will speed up the boot process if + * you can avoid loading the fw as long as the video device isn't used. + */ enum cx25840_video_input { /* Composite video inputs In1-In8 */