From patchwork Wed Mar 3 18:08:14 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Andrey Konovalov X-Patchwork-Id: 392696 Delivered-To: patch@linaro.org Received: by 2002:a17:906:a383:0:0:0:0 with SMTP id k3csp6033035ejz; Thu, 4 Mar 2021 06:30:37 -0800 (PST) X-Google-Smtp-Source: ABdhPJwcfSSsTe9xlmEUmlQYnBQ/VISZVtwLU/QuVitxTma1VrVZNgBzTtem+x+I69C4wFmnob1i X-Received: by 2002:a17:906:2692:: with SMTP id t18mr4423449ejc.16.1614868237310; Thu, 04 Mar 2021 06:30:37 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1614868237; cv=none; d=google.com; s=arc-20160816; b=U9UPlAj8wVGNHiqgX4M/7GjZMrT6czaHK2aCgIfRYuc5IpjorzQLbP44luj4L73JLM cNdPLVSlw0068plDBDR4FweguBnuuII702D7VmIC+h0yCm/l7kcPHRlroSILkoQ6HavK tIKttvmkE0dKlBTqnGOSnu7JJmRlNTDYmfiPExTh/pF8HXycf1Ppc4knCbCJKtTQINs9 ozALlNBo9yNFD5+TrWmvOFAk15luAa+l1IdW5RZpgRyzmYTxJ/Bnt/2lwuwo06GooB9T taXXyHRQtryU4epN0Q/L5KKxyQ1mvwKSgOlVhlqoF3lhMfKy/a8fmUSmqfdlVC32CuVl VMtQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:references:in-reply-to:message-id:date:subject :cc:to:from:dkim-signature; bh=bSsDnS6dbLhvTy+AVlfdF3LogW8QXbBSHC6yrMiBxcc=; b=RmPyKoYsw4nYOA33VBlnkcSXYq2w6NcwciyqDWsXSBVBs7Aiz+dt5zyOvXLKsyRYBv uZyvqCoL0IaD5cBnI9dqMJcP1H5gIbzrV1LIXsXIh+xznOfMF6fpCD7F1Civc8vHlSAx vzWAexpV9vB72FoMTosTgld4t+ZP/6IpnoTuTG5sM0uzn3qlneTx1bUKZ95NyZpmqb94 zg53nKFMh6BWl06u6o1CnBFGEKydx/stqxqZ2Wm6NB5XdCxWg7KlYUziFWcPkpxYEZOc UyTt53Q8VqMvyoFvmJ3PXT6ueI7IpJrSN8OanlwBdRdEQj8YDrWKVo+tgwykOsKunX5z HUCQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=eubOFCkw; spf=pass (google.com: domain of linux-media-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-media-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id o5si17146918ejn.708.2021.03.04.06.30.37; Thu, 04 Mar 2021 06:30:37 -0800 (PST) Received-SPF: pass (google.com: domain of linux-media-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=eubOFCkw; spf=pass (google.com: domain of linux-media-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-media-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1355650AbhCDAcR (ORCPT + 3 others); Wed, 3 Mar 2021 19:32:17 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:53840 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S243233AbhCCSJl (ORCPT ); Wed, 3 Mar 2021 13:09:41 -0500 Received: from mail-lf1-x12f.google.com (mail-lf1-x12f.google.com [IPv6:2a00:1450:4864:20::12f]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 120D8C06175F for ; Wed, 3 Mar 2021 10:08:54 -0800 (PST) Received: by mail-lf1-x12f.google.com with SMTP id v5so38563918lft.13 for ; Wed, 03 Mar 2021 10:08:53 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=from:to:cc:subject:date:message-id:in-reply-to:references; bh=bSsDnS6dbLhvTy+AVlfdF3LogW8QXbBSHC6yrMiBxcc=; b=eubOFCkwtk73peY4EPbEunGR/uk+5JCUWi3g2QGv85tqPZ3PNrVG8gXXANyHv0NmcI K8W/I2nmnxLYCZwal7WUloHZciQ0TZBa+YkM51io8pPygVXfN4iEHPbEIkcloO1M+QdE yp6KZrQ8JJvCWbb+a/iyFgVAQ5h/ZeAAnLpo4Lr8JwiQMJXyqU6ps1S4lYXkoo4SDcbY SU3lDszVeY8JmB96TjpUU9ViKu8ZYRCHJboG9K7JKj5cw1kPbKWkxp/1BL+UUZxD4Mbw w6jJiBjzRM4lnYSLrC05WxSwhXiUNQsQXGBfnFG5Qmgba/+sWnheE9s8JOl+zj6CcTzV sB2g== 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=bSsDnS6dbLhvTy+AVlfdF3LogW8QXbBSHC6yrMiBxcc=; b=Zom6fkbTeYr4bhRrJCyPkzgqIyBsf79qXOndmhxg2Rj/xqP2nGBoDrY4/8r96tX/kn bUvbM8MF03EIcbGNm28r/aSDsQWsY6WsiLbDNCssxc7I5zp4kfsc7OcFLRRA7uYTx6yp jZn3NRQWcj1DpJNM0JRSo+pOYOvQyFO5QnzTUhCIFhzl9OEaTjkGRbcBB8EM3i77/HZM h54XTt+xhTGWhD+QSRSnWFuzleO8CexCIwl+ytDZ/u82aiqVLU57EH1VrYeePO3Z28op 0izSY0P1deEqcOFmdIFbl7qIQKQMDzq42FbKB+gM6ruJ6qRuHuM/mC3sEx+tPRpGbBRV Q6RA== X-Gm-Message-State: AOAM532tf4YSd4J4VfInlM36oTbRrLdIcgej7vysnEON5NZP8QWmi1Lc sQaQumb4lC50fNsTqBrH4lodhQ== X-Received: by 2002:a05:6512:2208:: with SMTP id h8mr16310190lfu.636.1614794932537; Wed, 03 Mar 2021 10:08:52 -0800 (PST) Received: from localhost.localdomain ([85.249.43.69]) by smtp.googlemail.com with ESMTPSA id j15sm2220990lfm.138.2021.03.03.10.08.51 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 03 Mar 2021 10:08:51 -0800 (PST) From: Andrey Konovalov To: sakari.ailus@linux.intel.com, linux-media@vger.kernel.org, laurent.pinchart@ideasonboard.com Cc: mchehab@kernel.org, niklas.soderlund@ragnatech.se, bparrot@ti.com, mickael.guene@st.com, Andrey Konovalov Subject: [RFC PATCH 1/4] media: rcar-vin: use v4l2_get_link_freq() to calculate phypll frequency Date: Wed, 3 Mar 2021 21:08:14 +0300 Message-Id: <20210303180817.12285-2-andrey.konovalov@linaro.org> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20210303180817.12285-1-andrey.konovalov@linaro.org> References: <20210303180817.12285-1-andrey.konovalov@linaro.org> Precedence: bulk List-ID: X-Mailing-List: linux-media@vger.kernel.org To get the link frequency value, or to calculate a parameter depending on it the receiver driver should use V4L2_CID_LINK_FREQ. If V4L2_CID_LINK_FREQ control is not implemented in the remote subdevice, the link frequency can be calculated from V4L2_CID_PIXEL_RATE control value. But the latter may not give the correct link frequency, and should only be used as the last resort. v4l2_get_link_freq() does exactly that, so use it instead of reading V4L2_CID_PIXEL_RATE directly. Signed-off-by: Andrey Konovalov --- drivers/media/platform/rcar-vin/rcar-csi2.c | 18 +++++++----------- 1 file changed, 7 insertions(+), 11 deletions(-) -- 2.17.1 diff --git a/drivers/media/platform/rcar-vin/rcar-csi2.c b/drivers/media/platform/rcar-vin/rcar-csi2.c index e06cd512aba2..eec8f9dd9060 100644 --- a/drivers/media/platform/rcar-vin/rcar-csi2.c +++ b/drivers/media/platform/rcar-vin/rcar-csi2.c @@ -455,29 +455,25 @@ static int rcsi2_calc_mbps(struct rcar_csi2 *priv, unsigned int bpp, unsigned int lanes) { struct v4l2_subdev *source; - struct v4l2_ctrl *ctrl; - u64 mbps; + s64 mbps; if (!priv->remote) return -ENODEV; source = priv->remote; - /* Read the pixel rate control from remote. */ - ctrl = v4l2_ctrl_find(source->ctrl_handler, V4L2_CID_PIXEL_RATE); - if (!ctrl) { - dev_err(priv->dev, "no pixel rate control in subdev %s\n", + /* Read the link frequency from the remote subdev. */ + mbps = v4l2_get_link_freq(source->ctrl_handler, bpp, 2 * lanes); + if (mbps < 0) { + dev_err(priv->dev, "failed to get link rate from subdev %s\n", source->name); - return -EINVAL; + return mbps; } - /* * Calculate the phypll in mbps. - * link_freq = (pixel_rate * bits_per_sample) / (2 * nr_of_lanes) * bps = link_freq * 2 */ - mbps = v4l2_ctrl_g_ctrl_int64(ctrl) * bpp; - do_div(mbps, lanes * 1000000); + do_div(mbps, 1000000 / 2); return mbps; }