From patchwork Sun Apr 22 15:56:14 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Akinobu Mita X-Patchwork-Id: 10355635 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 1E74060388 for ; Sun, 22 Apr 2018 15:57:13 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 0D8B12893D for ; Sun, 22 Apr 2018 15:57:13 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 026272897A; Sun, 22 Apr 2018 15:57:12 +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=-6.5 required=2.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, FREEMAIL_FROM, MAILING_LIST_MULTI, RCVD_IN_DNSWL_HI, URIBL_RHS_DOB 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 781DE2893D for ; Sun, 22 Apr 2018 15:57:12 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1754353AbeDVP5J (ORCPT ); Sun, 22 Apr 2018 11:57:09 -0400 Received: from mail-pf0-f193.google.com ([209.85.192.193]:34850 "EHLO mail-pf0-f193.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1754473AbeDVP5B (ORCPT ); Sun, 22 Apr 2018 11:57:01 -0400 Received: by mail-pf0-f193.google.com with SMTP id j5so7224415pfh.2; Sun, 22 Apr 2018 08:57:01 -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=j9kpioJvE5lS/hqYwVRjWYws6QpHDwLpyDgclEfcvE0=; b=QhjIi7sipmxoheXI0sl+fxb3w5Oi1b2z4k2D2gpNsCmTi9x3TqbcO37VCU2uc2oIrO Y5Fb34rxWRH2/pLj4R85ArAmMuzX0b8kAeh2bF1Z0RWdC0gvmWHrgVcQwZIeS7pxL8Vo PtaH8Pvge8lvThPhUJ7urcZPbxlE8olZ/dm3dgWU0qdRHE5t86/NxmRG2vtag9IN5T1Q I6z6YlI8MMya2YZPTY2tlHvX8z1A2oGVPrRAkfEHDG76nj8l2k+2BPU0NUy2CHtBRyjF gT/UcubTI4STN1bvuYlgSfZyp1YqIwBcTws22qRiatSeksGT4l9DABkvPIAdd2ou85Ye tnZA== 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=j9kpioJvE5lS/hqYwVRjWYws6QpHDwLpyDgclEfcvE0=; b=o89Nv2AiGIBagFmQ6l2S9aZ2xCSjwVlKaV1dhC0155vfOxpKwF7rRIBqMNyk+V7Ozb ZSPpitZ3GJIa9W9jcrYOM7GmXXZA1m3ig4xTBWO4uvBawPK2uWDNP2qjAlaN01xcDzZd rESDJB+8PDLmG6+bYKR0RGPwm8cFhdkEmvzQaaLatutQSLauLR4rOWyNhBUD8rLQw0BM J6ieH8ou2qEoIT4hjvac1fdFirX03QEZAQSgu5HN6hDS03zXs/3t0g2P8CBX9rDjlCaN 8U78kEOW2KnbbZtITUZWIZCnySDLmH5GK0HEN6nQThlz3pL8GvtXBQrX7A9G41/wFgEX PToA== X-Gm-Message-State: ALQs6tAaOYRgU1WsVUuSrV3UOM2Wngm2hGZbsgJNXCi1pQJwfP6g+sQ6 pNqdXOPiipZzyTrXKqpDIuGpfg== X-Google-Smtp-Source: AIpwx48rAq28OwGExSengfkB7qNnty5uh+SnIk7czTcSP9rrfTRvItQaOrGiPDcf94R6hrF4xLrPzQ== X-Received: by 10.101.100.132 with SMTP id e4mr9332325pgv.102.1524412620077; Sun, 22 Apr 2018 08:57:00 -0700 (PDT) Received: from localhost.localdomain ([240f:4:c2bc:1:a9a1:96f3:29de:6e47]) by smtp.gmail.com with ESMTPSA id y29sm255461pff.42.2018.04.22.08.56.57 (version=TLS1_2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Sun, 22 Apr 2018 08:56:59 -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 v3 08/11] media: ov772x: reconstruct s_frame_interval() Date: Mon, 23 Apr 2018 00:56:14 +0900 Message-Id: <1524412577-14419-9-git-send-email-akinobu.mita@gmail.com> X-Mailer: git-send-email 2.7.4 In-Reply-To: <1524412577-14419-1-git-send-email-akinobu.mita@gmail.com> References: <1524412577-14419-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 --- * v3 - No changes 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 8c0b850..452406c 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) @@ -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;