From patchwork Mon Apr 16 02:51:50 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Akinobu Mita X-Patchwork-Id: 10342075 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 79297601C2 for ; Mon, 16 Apr 2018 02:52:43 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 69D0A201CB for ; Mon, 16 Apr 2018 02:52:43 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 5EDC52228E; Mon, 16 Apr 2018 02:52:43 +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 E2C37201CB for ; Mon, 16 Apr 2018 02:52:42 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1752921AbeDPCwl (ORCPT ); Sun, 15 Apr 2018 22:52:41 -0400 Received: from mail-pg0-f65.google.com ([74.125.83.65]:32844 "EHLO mail-pg0-f65.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1752888AbeDPCwi (ORCPT ); Sun, 15 Apr 2018 22:52:38 -0400 Received: by mail-pg0-f65.google.com with SMTP id i194so3141677pgd.0; Sun, 15 Apr 2018 19:52:38 -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=Su6pwpIlmeAyXgKjNcyqR0ixW7H7C6gGOwKUcwDoN04=; b=h+xuh2nW3XFIAliVRcpx8RCP3iBmv2C3UYBI7lL5wDx0mXSA9P81Ep7UHDlJC1dTOn qsFdlcl5jo88rpRe/8x23H1w9+pLYzqfT6waNPFzaOWGRofcFRBoBNsVHeErOSRiMQ8J d4ugxak2QY9TsXF4e0Ia4wOHfqYIeGbQZG/XVChMhWxwoVT9/DPHXS9WNd9h886ap64H pAxpg4x94BvNFb06vg3UlIAG7dMTqYwPX5w5ACTqan3fnqk4IoAh+uHmlkno3nXkiyRR PdwCnP2+ZyP3WNeUR+ivcfE+6s9K/RjfqB/j3z/TI6SYrmAj/j7r2J5oTrZsr3zybHAN A70w== 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=Su6pwpIlmeAyXgKjNcyqR0ixW7H7C6gGOwKUcwDoN04=; b=dswhcREzfsVNN68ScA+kErTXlQqeop4vlGOLQMfP8H403HRCAUUl+6L7CIhSwhS0ZE nB9e4cwq71QXTfLJ9j72mk8ic9UDmCMo3v7nlIFHQz++3DDJYltoPcQonkwl4QhJgXTK RGkF8BYK22fcgk3cXJ5+HsSrA7ZT7EbBgYQIj5omu/JKjkrov0xxFgjQ8QQr6ty1s/4C BrXLC+d1knc5U/xNWFB+WjqTD4tluhrf/AoHiw3YN4rZHzcNiHBE68uQdyGJv7UteXQB 5m5TUT+k98cp9FXg3Kv5VvygGFZcQadMAr8HB97/t40IaJ/3dU+ky7jV0ZOhH1Oq3MMu BMwg== X-Gm-Message-State: ALQs6tDJT1jd0Gp7zuFBtSGjILzsrTrQueBDO8zS1nirEjGBLOHxLeAj p+I3fFILPdwWTSCmhXnuyK1lUw== X-Google-Smtp-Source: AIpwx48IuNT4C/NfZ2S28E5CVlfPt/4uee5j2z+bavlnpPFYduJx3wc7dFZEHAZpFlkwZrd4HKqB/Q== X-Received: by 10.98.30.4 with SMTP id e4mr5186182pfe.212.1523847158172; Sun, 15 Apr 2018 19:52:38 -0700 (PDT) Received: from localhost.localdomain ([240f:4:c2bc:1:3df1:9c88:51ad:c027]) by smtp.gmail.com with ESMTPSA id e1sm3694274pgt.49.2018.04.15.19.52.35 (version=TLS1_2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Sun, 15 Apr 2018 19:52:37 -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 v2 09/10] media: ov772x: reconstruct s_frame_interval() Date: Mon, 16 Apr 2018 11:51:50 +0900 Message-Id: <1523847111-12986-10-git-send-email-akinobu.mita@gmail.com> X-Mailer: git-send-email 2.7.4 In-Reply-To: <1523847111-12986-1-git-send-email-akinobu.mita@gmail.com> References: <1523847111-12986-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 --- * v2 - New patch 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 2cd6e85..1297a21 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 fsize; + unsigned int pclk; + unsigned int best_diff; + 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) @@ -992,7 +1009,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; @@ -1074,9 +1090,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;