From patchwork Sun May 6 14:19:25 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Akinobu Mita X-Patchwork-Id: 10382831 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork.web.codeaurora.org (Postfix) with ESMTP id ED9676054B for ; Sun, 6 May 2018 14:20:30 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id DB9CB2892B for ; Sun, 6 May 2018 14:20:30 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id C53B628B87; Sun, 6 May 2018 14:20:30 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-8.0 required=2.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, FREEMAIL_FROM, MAILING_LIST_MULTI, RCVD_IN_DNSWL_HI autolearn=ham version=3.3.1 Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id EAB7428A09 for ; Sun, 6 May 2018 14:20:26 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1751817AbeEFOUQ (ORCPT ); Sun, 6 May 2018 10:20:16 -0400 Received: from mail-pg0-f67.google.com ([74.125.83.67]:46614 "EHLO mail-pg0-f67.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751777AbeEFOUO (ORCPT ); Sun, 6 May 2018 10:20:14 -0400 Received: by mail-pg0-f67.google.com with SMTP id z4-v6so18436698pgu.13; Sun, 06 May 2018 07:20:14 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id:in-reply-to:references; bh=c4LIw2LS+6n7pUG/aBVrAJleQroy3gumuZ0Igheqpq0=; b=K65d+87qBuEEo4hvvY9nh8cHUsvmbwdc2Ak66t8f+P2VLdq7p6qZbQDuywRL13LIFh 6V+qNsZrtGq8o8emjns+H/M6tgMcN3feE9fvb8GX/sI0DvgpkrdUjvsgcr2t34U2hLPo byNSN2BPBUI8Kg4HQeAYRL2n8XygwsSI7cC0Jnwn5iMAlKRvw1CKWUwUtdo8v+Ys8x9X YhSgaVPJCT2MoLcOLlA5LSkqp7iYTc+Jb6VVEuAxNhhhPZrLcs3ZNDIUoUPBgDH5jioK dY/xxUJiRifW9OVJXA/nK37ZmqizDzQrOdgLUbf8P7+NWGM8sZ995fF4wRi7tRP+dWkt GFVw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references; bh=c4LIw2LS+6n7pUG/aBVrAJleQroy3gumuZ0Igheqpq0=; b=mWcB4ZUuIURdHJkcPX3iHTshLDVKu9ImDO8FQsebPOBouCEdY55Nw4dndlxkuf1a0O f9vh32K35BA0ei/IhKnY0m+eJfWix6LUe3IgFybQp/JufAWbF1/CbQd1ayowrRC3AQVW IZs9EmsYVoSHvQdkcbX3u78mVa4m7uY4jYV17XhCTA2SwtZAwMNcfpNWv+miXaIfxULq xH5V33xOg+g4DnaOF3N2iMBl9sJ2dpmn0KSx7S5c5qKcqwFCVzzur8Q0HVUvG56A0jOt XQkHAFA7jQYg0HG7wYPBCeqqgHF+TDNNmFfPTnO2Vm6E2wviOx84eNu34UlIB1cGVfLW +s8Q== X-Gm-Message-State: ALQs6tBrHkWZlZvT98lDwd/Xsyv0mXrwac56EJ3yx1M4Rhm5/W2axOKZ r0BmCyxlq88kIWWMIUfUpR9/HQ== X-Google-Smtp-Source: AB8JxZrgTqe0bTwuTrZj4JHtA5t/73JyTqWfDxdYS1AUYFgcVIXgUpzqSTA08Vv4wlPPQHqdaI8FVQ== X-Received: by 2002:a17:902:aa04:: with SMTP id be4-v6mr34805302plb.20.1525616414123; Sun, 06 May 2018 07:20:14 -0700 (PDT) Received: from localhost.localdomain ([240f:4:c2bc:1:141a:15e1:5268:11ce]) by smtp.gmail.com with ESMTPSA id s88sm58766771pfe.43.2018.05.06.07.20.11 (version=TLS1_2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Sun, 06 May 2018 07:20:13 -0700 (PDT) From: Akinobu Mita To: linux-media@vger.kernel.org, devicetree@vger.kernel.org Cc: Akinobu Mita , Jacopo Mondi , Laurent Pinchart , Hans Verkuil , Sakari Ailus , Mauro Carvalho Chehab Subject: [PATCH v5 10/14] media: ov772x: reconstruct s_frame_interval() Date: Sun, 6 May 2018 23:19:25 +0900 Message-Id: <1525616369-8843-11-git-send-email-akinobu.mita@gmail.com> X-Mailer: git-send-email 2.7.4 In-Reply-To: <1525616369-8843-1-git-send-email-akinobu.mita@gmail.com> References: <1525616369-8843-1-git-send-email-akinobu.mita@gmail.com> Sender: linux-media-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-media@vger.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP This splits the s_frame_interval() in subdev video ops into selecting the frame interval and setting up the registers. This is a preparatory change to avoid accessing registers under power saving mode. Cc: Jacopo Mondi Cc: Laurent Pinchart Cc: Hans Verkuil Cc: Sakari Ailus Cc: Mauro Carvalho Chehab Signed-off-by: Akinobu Mita Reviewed-by: Jacopo Mondi --- * v5 - Align arguments to open parenthesis - Sort variable declarations drivers/media/i2c/ov772x.c | 56 +++++++++++++++++++++++++++++----------------- 1 file changed, 35 insertions(+), 21 deletions(-) diff --git a/drivers/media/i2c/ov772x.c b/drivers/media/i2c/ov772x.c index 6c0c792..92ad13f 100644 --- a/drivers/media/i2c/ov772x.c +++ b/drivers/media/i2c/ov772x.c @@ -617,25 +617,16 @@ static int ov772x_s_stream(struct v4l2_subdev *sd, int enable) return 0; } -static int ov772x_set_frame_rate(struct ov772x_priv *priv, - struct v4l2_fract *tpf, - const struct ov772x_color_format *cfmt, - const struct ov772x_win_size *win) +static unsigned int ov772x_select_fps(struct ov772x_priv *priv, + struct v4l2_fract *tpf) { - struct i2c_client *client = v4l2_get_subdevdata(&priv->subdev); - unsigned long fin = clk_get_rate(priv->clk); unsigned int fps = tpf->numerator ? tpf->denominator / tpf->numerator : tpf->denominator; unsigned int best_diff; - unsigned int fsize; - unsigned int pclk; unsigned int diff; unsigned int idx; unsigned int i; - u8 clkrc = 0; - u8 com4 = 0; - int ret; /* Approximate to the closest supported frame interval. */ best_diff = ~0L; @@ -646,7 +637,25 @@ static int ov772x_set_frame_rate(struct ov772x_priv *priv, best_diff = diff; } } - fps = ov772x_frame_intervals[idx]; + + return ov772x_frame_intervals[idx]; +} + +static int ov772x_set_frame_rate(struct ov772x_priv *priv, + unsigned int fps, + const struct ov772x_color_format *cfmt, + const struct ov772x_win_size *win) +{ + struct i2c_client *client = v4l2_get_subdevdata(&priv->subdev); + unsigned long fin = clk_get_rate(priv->clk); + unsigned int best_diff; + unsigned int fsize; + unsigned int pclk; + unsigned int diff; + unsigned int i; + u8 clkrc = 0; + u8 com4 = 0; + int ret; /* Use image size (with blankings) to calculate desired pixel clock. */ switch (cfmt->com7 & OFMT_MASK) { @@ -711,10 +720,6 @@ static int ov772x_set_frame_rate(struct ov772x_priv *priv, if (ret < 0) return ret; - tpf->numerator = 1; - tpf->denominator = fps; - priv->fps = tpf->denominator; - return 0; } @@ -735,8 +740,20 @@ static int ov772x_s_frame_interval(struct v4l2_subdev *sd, { struct ov772x_priv *priv = to_ov772x(sd); struct v4l2_fract *tpf = &ival->interval; + unsigned int fps; + int ret; + + fps = ov772x_select_fps(priv, tpf); + + ret = ov772x_set_frame_rate(priv, fps, priv->cfmt, priv->win); + if (ret) + return ret; - return ov772x_set_frame_rate(priv, tpf, priv->cfmt, priv->win); + tpf->numerator = 1; + tpf->denominator = fps; + priv->fps = fps; + + return 0; } static int ov772x_s_ctrl(struct v4l2_ctrl *ctrl) @@ -993,7 +1010,6 @@ static int ov772x_set_params(struct ov772x_priv *priv, const struct ov772x_win_size *win) { struct i2c_client *client = v4l2_get_subdevdata(&priv->subdev); - struct v4l2_fract tpf; int ret; u8 val; @@ -1075,9 +1091,7 @@ static int ov772x_set_params(struct ov772x_priv *priv, goto ov772x_set_fmt_error; /* COM4, CLKRC: Set pixel clock and framerate. */ - tpf.numerator = 1; - tpf.denominator = priv->fps; - ret = ov772x_set_frame_rate(priv, &tpf, cfmt, win); + ret = ov772x_set_frame_rate(priv, priv->fps, cfmt, win); if (ret < 0) goto ov772x_set_fmt_error;