From patchwork Tue Jan 13 12:01:13 2015 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Lars-Peter Clausen X-Patchwork-Id: 5619931 Return-Path: X-Original-To: patchwork-linux-media@patchwork.kernel.org Delivered-To: patchwork-parsemail@patchwork2.web.kernel.org Received: from mail.kernel.org (mail.kernel.org [198.145.29.136]) by patchwork2.web.kernel.org (Postfix) with ESMTP id 3DCDCC058E for ; Tue, 13 Jan 2015 12:01:58 +0000 (UTC) Received: from mail.kernel.org (localhost [127.0.0.1]) by mail.kernel.org (Postfix) with ESMTP id 5DEF220620 for ; Tue, 13 Jan 2015 12:01:57 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id 711842061F for ; Tue, 13 Jan 2015 12:01:56 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1752403AbbAMMBv (ORCPT ); Tue, 13 Jan 2015 07:01:51 -0500 Received: from smtp-out-231.synserver.de ([212.40.185.231]:1036 "EHLO smtp-out-227.synserver.de" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S1752328AbbAMMBb (ORCPT ); Tue, 13 Jan 2015 07:01:31 -0500 Received: (qmail 31385 invoked by uid 0); 13 Jan 2015 12:01:29 -0000 X-SynServer-TrustedSrc: 1 X-SynServer-AuthUser: lars@metafoo.de X-SynServer-PPID: 30945 Received: from p4fde6878.dip0.t-ipconnect.de (HELO lars-adi-laptop.analog.com) [79.222.104.120] by 217.119.54.81 with SMTP; 13 Jan 2015 12:01:28 -0000 From: Lars-Peter Clausen To: Hans Verkuil Cc: linux-media@vger.kernel.org, Lars-Peter Clausen Subject: [PATCH 08/16] [media] adv7180: Consolidate video mode setting Date: Tue, 13 Jan 2015 13:01:13 +0100 Message-Id: <1421150481-30230-9-git-send-email-lars@metafoo.de> X-Mailer: git-send-email 1.8.0 In-Reply-To: <1421150481-30230-1-git-send-email-lars@metafoo.de> References: <1421150481-30230-1-git-send-email-lars@metafoo.de> Sender: linux-media-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-media@vger.kernel.org X-Spam-Status: No, score=-6.9 required=5.0 tests=BAYES_00, RCVD_IN_DNSWL_HI, T_RP_MATCHES_RCVD, UNPARSEABLE_RELAY autolearn=unavailable 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 We have basically the same code to set the video standard in init_device() and adv7180_s_std(). Factor this out into a common helper function. Signed-off-by: Lars-Peter Clausen Acked-by: Hans Verkuil --- drivers/media/i2c/adv7180.c | 67 ++++++++++++++++++++++----------------------- 1 file changed, 32 insertions(+), 35 deletions(-) diff --git a/drivers/media/i2c/adv7180.c b/drivers/media/i2c/adv7180.c index 349cae3..4d9bcc8 100644 --- a/drivers/media/i2c/adv7180.c +++ b/drivers/media/i2c/adv7180.c @@ -304,37 +304,54 @@ static int adv7180_g_input_status(struct v4l2_subdev *sd, u32 *status) return ret; } -static int adv7180_s_std(struct v4l2_subdev *sd, v4l2_std_id std) +static int adv7180_program_std(struct adv7180_state *state) { - struct adv7180_state *state = to_state(sd); - int ret = mutex_lock_interruptible(&state->mutex); - if (ret) - return ret; + int ret; - /* all standards -> autodetect */ - if (std == V4L2_STD_ALL) { + if (state->autodetect) { ret = adv7180_write(state, ADV7180_REG_INPUT_CONTROL, ADV7180_INPUT_CONTROL_AD_PAL_BG_NTSC_J_SECAM | state->input); if (ret < 0) - goto out; + return ret; __adv7180_status(state, NULL, &state->curr_norm); - state->autodetect = true; } else { - ret = v4l2_std_to_adv7180(std); + ret = v4l2_std_to_adv7180(state->curr_norm); if (ret < 0) - goto out; + return ret; ret = adv7180_write(state, ADV7180_REG_INPUT_CONTROL, ret | state->input); if (ret < 0) + return ret; + } + + return 0; +} + +static int adv7180_s_std(struct v4l2_subdev *sd, v4l2_std_id std) +{ + struct adv7180_state *state = to_state(sd); + int ret = mutex_lock_interruptible(&state->mutex); + + if (ret) + return ret; + + /* all standards -> autodetect */ + if (std == V4L2_STD_ALL) { + state->autodetect = true; + } else { + /* Make sure we can support this std */ + ret = v4l2_std_to_adv7180(std); + if (ret < 0) goto out; state->curr_norm = std; state->autodetect = false; } - ret = 0; + + ret = adv7180_program_std(state); out: mutex_unlock(&state->mutex); return ret; @@ -547,30 +564,10 @@ static int init_device(struct adv7180_state *state) adv7180_write(state, ADV7180_REG_PWR_MAN, ADV7180_PWR_MAN_RES); usleep_range(2000, 10000); - /* Initialize adv7180 */ - /* Enable autodetection */ - if (state->autodetect) { - ret = adv7180_write(state, ADV7180_REG_INPUT_CONTROL, - ADV7180_INPUT_CONTROL_AD_PAL_BG_NTSC_J_SECAM - | state->input); - if (ret < 0) - goto out_unlock; - - ret = adv7180_write(state, ADV7180_REG_AUTODETECT_ENABLE, - ADV7180_AUTODETECT_DEFAULT); - if (ret < 0) - goto out_unlock; - } else { - ret = v4l2_std_to_adv7180(state->curr_norm); - if (ret < 0) - goto out_unlock; - - ret = adv7180_write(state, ADV7180_REG_INPUT_CONTROL, - ret | state->input); - if (ret < 0) - goto out_unlock; + ret = adv7180_program_std(state); + if (ret) + goto out_unlock; - } /* ITU-R BT.656-4 compatible */ ret = adv7180_write(state, ADV7180_REG_EXTENDED_OUTPUT_CONTROL, ADV7180_EXTENDED_OUTPUT_CONTROL_NTSCDIS);