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; } From patchwork Wed Mar 3 18:08:15 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Andrey Konovalov X-Patchwork-Id: 392694 Delivered-To: patch@linaro.org Received: by 2002:a17:906:a383:0:0:0:0 with SMTP id k3csp6030014ejz; Thu, 4 Mar 2021 06:26:49 -0800 (PST) X-Google-Smtp-Source: ABdhPJxGCLBw7kG3Z89OX0HB3eCbyuFr5OEXnrTUxp7nW9U7QJPlgdc3Y+rErKzLQkjkt534cmkc X-Received: by 2002:a17:907:216a:: with SMTP id rl10mr675340ejb.365.1614868009364; Thu, 04 Mar 2021 06:26:49 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1614868009; cv=none; d=google.com; s=arc-20160816; b=hUl7DnidUqMqZvPv+DeXrcwtGpntTe07aYiJOnSxpczls7tClloq7WKPxRWuQtapz+ hbwlArqiZZrRaUSWNQcQa+mm2b6rNpiE9MdwawioRy3ji1I+cZ0ngBFc54bCFYaGOGYb tnQS5WJCzNii1ewZ1VJYeeH0r2xgkdc3mzDXhY4LSbWIxufED+yofvTO46cvTBX8gSsk +bbox0apydYMaellNssCJgtkyW6/MgYsE628gLm3RFi/SvRlYhHmLFHz17b+D06snSk2 nM5PfXeY7F5TVWhwWqtQ0261Skyiwkxd2QxEdOjxqttrE7398+GmhWfMP9Xj6bw/xIiS WalA== 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=1IYGjcV64ZDmP6/oFTMyIZJ2q3HMCbj9wNdpmV4JDRE=; b=V8054MpVQBlycY497XbzQ2mEkqxT33LprdzHEIpsooCOHqXmFAk+HFpbSG6udOzy8E DYttxrTQFT+LOZ+RVjuVvNQ+MCqHc+TiOfXqwohHhJVaihhbXgT9hMu3HZisBDh3NFWI 3bsOFeP7MZefFRdCQTePob0vkp8nhkVC+4GJgvJz8KayUS1P3DD7NZwZmJx4QgVg+C5K FW9KIiUpOHO5t7XARY5XwF99+S/WxGA9+H8ZMgyZt5d1tNKAhOr/Vqy95MZWtuRfhmDc DzVmFcOjzw7BDWuGu5SorjRLFeVSQyzHc+HeJeW2yBbuo1+T2rS2ELLrU8kXYrHkAMOm 6B7w== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b="VQ/YuyhI"; 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 s10si17848508edj.416.2021.03.04.06.26.49; Thu, 04 Mar 2021 06:26:49 -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="VQ/YuyhI"; 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 S1348233AbhCDAcQ (ORCPT + 3 others); Wed, 3 Mar 2021 19:32:16 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:53854 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S243239AbhCCSJl (ORCPT ); Wed, 3 Mar 2021 13:09:41 -0500 Received: from mail-lf1-x136.google.com (mail-lf1-x136.google.com [IPv6:2a00:1450:4864:20::136]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 988F5C061760 for ; Wed, 3 Mar 2021 10:08:56 -0800 (PST) Received: by mail-lf1-x136.google.com with SMTP id n16so21664971lfb.4 for ; Wed, 03 Mar 2021 10:08:56 -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=1IYGjcV64ZDmP6/oFTMyIZJ2q3HMCbj9wNdpmV4JDRE=; b=VQ/YuyhIZqmF1yC8GPojGmr9NebO70jd2OK0VyIxjrG3rLVITW+Zfkx7tKCB96x2nF e5SKdQX+3IVNh4LMsXs5o15PZKOChmr/yM9fKIx3iefGrIAXI5afFNas4ZQ71NY0rC5N 9v+drrLoEiVoVOICt3FPW7PMBe96YfbZsNBtw6fw0oYlcmqb38piC8y81HwaJ58vqD9N PB93/qqBC9Ar8Vh6TiekXSFkT8/vRhJIGtP7fgWc+WF3bppNHwZ56Uvy0W8Pe4BOx5lG j/tU9t8+JR7XIZ5qwkrCHqYouMNzBuIPPDLmbNHdMndm93Lvj2Bo7AYH6qiXq/Tp09Pa zjvw== 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=1IYGjcV64ZDmP6/oFTMyIZJ2q3HMCbj9wNdpmV4JDRE=; b=OQGxYf++6m+Nn0XBAi3w+3tcKyVZzc1WehkJUGJ0u5nCSWlAGnkm7npCm5HdlRqEUp UmVZpFCMSgbwnfNM7v+4LFPZiizKROm/PFlc2XwN3/nOpAtecGBhjHvhsRxTO4fHPGg+ KdNypyRTSGlZyamz0LykxVmQOhRMMomAcQAXHldKe51GWOgrrbyqCDLO/I0uwfYg4lyu sjLn5UhLqHiHT5809cdcLqMLa732jnZS9toEiMHueEYZGm4je6ij7hUqZsjL6AnQlo+Y 3Su7BwQcxbtJCJEc/XkNsBVam2peSMApgVQODaQrPe3F8Ef68Bwot50ebuspDZaGO5eS Z19Q== X-Gm-Message-State: AOAM531gC0+vh881245SrLfPBqBUHQXK32d3/nLRzSmf/U9MPIzDbi0P 5XZPA4vWVG/j5uTl4jPRSfPmaA== X-Received: by 2002:a05:6512:3188:: with SMTP id i8mr15911438lfe.121.1614794935020; Wed, 03 Mar 2021 10:08:55 -0800 (PST) Received: from localhost.localdomain ([85.249.43.69]) by smtp.googlemail.com with ESMTPSA id j15sm2220990lfm.138.2021.03.03.10.08.54 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 03 Mar 2021 10:08:54 -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 2/4] media: ti-vpe: cal: use v4l2_get_link_freq() for DPHY timing configuration Date: Wed, 3 Mar 2021 21:08:15 +0300 Message-Id: <20210303180817.12285-3-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 configure DPHY properly the driver needs to know CSI-2 link frequency. Instead of calculating it from the value of V4L2_CID_PIXEL_RATE control (which can give wrong link frequency value for some sensors) call v4l2_get_link_freq(). It uses V4L2_CID_LINK_FREQ if this control is implemented in the sensor driver, and falls back to calculating it from V4L2_CID_PIXEL_RATE otherwise. Signed-off-by: Andrey Konovalov --- drivers/media/platform/ti-vpe/cal-camerarx.c | 47 +++++++------------- 1 file changed, 17 insertions(+), 30 deletions(-) -- 2.17.1 diff --git a/drivers/media/platform/ti-vpe/cal-camerarx.c b/drivers/media/platform/ti-vpe/cal-camerarx.c index dd48017859cd..0c1046a1fea4 100644 --- a/drivers/media/platform/ti-vpe/cal-camerarx.c +++ b/drivers/media/platform/ti-vpe/cal-camerarx.c @@ -45,22 +45,20 @@ static inline void camerarx_write(struct cal_camerarx *phy, u32 offset, u32 val) * ------------------------------------------------------------------ */ -static s64 cal_camerarx_get_external_rate(struct cal_camerarx *phy) +static s64 cal_camerarx_get_link_freq(struct cal_camerarx *phy) { - struct v4l2_ctrl *ctrl; - s64 rate; + u32 num_lanes = phy->endpoint.bus.mipi_csi2.num_data_lanes; + s64 freq; - ctrl = v4l2_ctrl_find(phy->sensor->ctrl_handler, V4L2_CID_PIXEL_RATE); - if (!ctrl) { - phy_err(phy, "no pixel rate control in subdev: %s\n", + freq = v4l2_get_link_freq(phy->sensor->ctrl_handler, phy->fmtinfo->bpp, + num_lanes * 2); + if (freq < 0) + phy_err(phy, "failed to get link frequency from subdev: %s\n", phy->sensor->name); - return -EPIPE; - } - - rate = v4l2_ctrl_g_ctrl_int64(ctrl); - phy_dbg(3, phy, "sensor Pixel Rate: %llu\n", rate); + else + phy_dbg(3, phy, "sensor link frequency: %lld\n", freq); - return rate; + return freq; } static void cal_camerarx_lane_config(struct cal_camerarx *phy) @@ -116,25 +114,14 @@ void cal_camerarx_disable(struct cal_camerarx *phy) #define TCLK_MISS 1 #define TCLK_SETTLE 14 -static void cal_camerarx_config(struct cal_camerarx *phy, s64 external_rate) +static void cal_camerarx_config(struct cal_camerarx *phy, s64 link_freq) { unsigned int reg0, reg1; unsigned int ths_term, ths_settle; unsigned int csi2_ddrclk_khz; - struct v4l2_fwnode_bus_mipi_csi2 *mipi_csi2 = - &phy->endpoint.bus.mipi_csi2; - u32 num_lanes = mipi_csi2->num_data_lanes; /* DPHY timing configuration */ - - /* - * CSI-2 is DDR and we only count used lanes. - * - * csi2_ddrclk_khz = external_rate / 1000 - * / (2 * num_lanes) * phy->fmtinfo->bpp; - */ - csi2_ddrclk_khz = div_s64(external_rate * phy->fmtinfo->bpp, - 2 * num_lanes * 1000); + csi2_ddrclk_khz = div_s64(link_freq, 1000); phy_dbg(1, phy, "csi2_ddrclk_khz: %d\n", csi2_ddrclk_khz); @@ -270,14 +257,14 @@ static void cal_camerarx_ppi_disable(struct cal_camerarx *phy) static int cal_camerarx_start(struct cal_camerarx *phy) { - s64 external_rate; + s64 link_freq; u32 sscounter; u32 val; int ret; - external_rate = cal_camerarx_get_external_rate(phy); - if (external_rate < 0) - return external_rate; + link_freq = cal_camerarx_get_link_freq(phy); + if (link_freq < 0) + return link_freq; ret = v4l2_subdev_call(phy->sensor, core, s_power, 1); if (ret < 0 && ret != -ENOIOCTLCMD && ret != -ENODEV) { @@ -325,7 +312,7 @@ static int cal_camerarx_start(struct cal_camerarx *phy) camerarx_read(phy, CAL_CSI2_PHY_REG0); /* Program the PHY timing parameters. */ - cal_camerarx_config(phy, external_rate); + cal_camerarx_config(phy, link_freq); /* * b. Assert the FORCERXMODE signal. From patchwork Wed Mar 3 18:08:16 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Andrey Konovalov X-Patchwork-Id: 393124 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-18.8 required=3.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, HEADER_FROM_DIFFERENT_DOMAINS, INCLUDES_CR_TRAILER, INCLUDES_PATCH, MAILING_LIST_MULTI, SPF_HELO_NONE, SPF_PASS, URIBL_BLOCKED, USER_AGENT_GIT autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 3CA10C433E6 for ; Thu, 4 Mar 2021 00:32:16 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 1071864E62 for ; Thu, 4 Mar 2021 00:32:16 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1355639AbhCDAcO (ORCPT ); Wed, 3 Mar 2021 19:32:14 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:53866 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S243240AbhCCSJl (ORCPT ); Wed, 3 Mar 2021 13:09:41 -0500 Received: from mail-lj1-x22c.google.com (mail-lj1-x22c.google.com [IPv6:2a00:1450:4864:20::22c]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 773CBC061761 for ; Wed, 3 Mar 2021 10:08:59 -0800 (PST) Received: by mail-lj1-x22c.google.com with SMTP id t9so724521ljt.8 for ; Wed, 03 Mar 2021 10:08:59 -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=rajw6Rc14+kU1U/M5vuMXcyz2slrUjYDEUD7gAw/A7Y=; b=wreU8Pqrg6IthBMBO/NrKTNm6ncKPxUvJadDselrtmsC8ITvSa8AuXWhAgGoU2U5iK twfCqHOO3VkzBCKTTsZC51ZKdTG2sMWzneNLK+GXUvh6fxgHFQssuUgs1CWNLFCmL1bW tOBoohgUqGANK8FsAWk4Gxmg+RK3wNf7/YvxXYq0Xm0zRgya9KPYlcs1935d1K4D2ZEs cuNDPvpBY6dv9WEnXgfp4HCj7LCX5aPE9CLyLREckzwwnyrpXwY2BzMvRmSg1jrwIAZW hvLDTAN17vuvCZe/tde3u+jNOZMHsfbD4XvLC46BKMyhKiqfs1k/liBgH0TBU1zSveBQ TXyg== 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=rajw6Rc14+kU1U/M5vuMXcyz2slrUjYDEUD7gAw/A7Y=; b=JCwg05ogL0h3Kbd64XxAGNzl8mIrOYDE41knNRWl3bCSCdEmSbfY3m2Yvi/WmgnOdv St2UwN2X07m9I53Mp4bgCMr9jkeO6iPbkprADS+nYYT40gMcmYiaCgjlKNGdveWiXQDL MRbDlJ+58aQCXnUOPCScVRuIBTK6ZviZpdbv+h4li8oX+b60Pur7pG0Y9FV9q87iI1y/ 1L9NWJl+S3A9tO98fL25zO8CwzrIVScjydypd0UsOWFaaT/EyZYlptLNkbAPzG8ZSo+y d7pp6b5XSeh0V2jQXMqRtdU1zdIIHy5g3la00CP2v8k0G4Tks+y4+mmX6l/zY9IecWGa gyew== X-Gm-Message-State: AOAM5315ArowSwdXQa13cgZOX1kfJ3ARbTlRGHO/w0AMMPaWWRCWtStP qCUacU9yTj7dMPcLMBcw+h2bTQ== X-Google-Smtp-Source: ABdhPJxjekwmLVJEyZm4XcmULgzqSWlDhf10XGc910LCQLhzx8O2MmWVf1OGHO+jNgTU4NEAnjQBJQ== X-Received: by 2002:a2e:b5a5:: with SMTP id f5mr93837ljn.336.1614794937981; Wed, 03 Mar 2021 10:08:57 -0800 (PST) Received: from localhost.localdomain ([85.249.43.69]) by smtp.googlemail.com with ESMTPSA id j15sm2220990lfm.138.2021.03.03.10.08.56 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 03 Mar 2021 10:08:56 -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 3/4] media: st-mipid02: use v4l2_get_link_freq() instead of the custom code Date: Wed, 3 Mar 2021 21:08:16 +0300 Message-Id: <20210303180817.12285-4-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 v4l2_get_link_freq() uses the same approach as the one implemented in the current driver with mipid02_get_link_freq_from_cid_link_freq() and mipid02_get_link_freq_from_cid_pixel_rate(). Signed-off-by: Andrey Konovalov --- drivers/media/i2c/st-mipid02.c | 58 ++++++---------------------------- 1 file changed, 10 insertions(+), 48 deletions(-) diff --git a/drivers/media/i2c/st-mipid02.c b/drivers/media/i2c/st-mipid02.c index 7f07ef56fbbd..38bb18c48ac7 100644 --- a/drivers/media/i2c/st-mipid02.c +++ b/drivers/media/i2c/st-mipid02.c @@ -343,41 +343,6 @@ static int mipid02_detect(struct mipid02_dev *bridge) return mipid02_read_reg(bridge, MIPID02_CLK_LANE_WR_REG1, ®); } -static u32 mipid02_get_link_freq_from_cid_link_freq(struct mipid02_dev *bridge, - struct v4l2_subdev *subdev) -{ - struct v4l2_querymenu qm = {.id = V4L2_CID_LINK_FREQ, }; - struct v4l2_ctrl *ctrl; - int ret; - - ctrl = v4l2_ctrl_find(subdev->ctrl_handler, V4L2_CID_LINK_FREQ); - if (!ctrl) - return 0; - qm.index = v4l2_ctrl_g_ctrl(ctrl); - - ret = v4l2_querymenu(subdev->ctrl_handler, &qm); - if (ret) - return 0; - - return qm.value; -} - -static u32 mipid02_get_link_freq_from_cid_pixel_rate(struct mipid02_dev *bridge, - struct v4l2_subdev *subdev) -{ - struct v4l2_fwnode_endpoint *ep = &bridge->rx; - struct v4l2_ctrl *ctrl; - u32 pixel_clock; - u32 bpp = bpp_from_code(bridge->fmt.code); - - ctrl = v4l2_ctrl_find(subdev->ctrl_handler, V4L2_CID_PIXEL_RATE); - if (!ctrl) - return 0; - pixel_clock = v4l2_ctrl_g_ctrl_int64(ctrl); - - return pixel_clock * bpp / (2 * ep->bus.mipi_csi2.num_data_lanes); -} - /* * We need to know link frequency to setup clk_lane_reg1 timings. Link frequency * will be computed using connected device V4L2_CID_PIXEL_RATE, bit per pixel @@ -386,21 +351,18 @@ static u32 mipid02_get_link_freq_from_cid_pixel_rate(struct mipid02_dev *bridge, static int mipid02_configure_from_rx_speed(struct mipid02_dev *bridge) { struct i2c_client *client = bridge->i2c_client; - struct v4l2_subdev *subdev = bridge->s_subdev; - u32 link_freq; - - link_freq = mipid02_get_link_freq_from_cid_link_freq(bridge, subdev); - if (!link_freq) { - link_freq = mipid02_get_link_freq_from_cid_pixel_rate(bridge, - subdev); - if (!link_freq) { - dev_err(&client->dev, "Failed to get link frequency"); - return -EINVAL; - } + s64 freq; + + freq = v4l2_get_link_freq(bridge->s_subdev->ctrl_handler, + bpp_from_code(bridge->fmt.code), + 2 * bridge->rx.bus.mipi_csi2.num_data_lanes); + if (freq < 0) { + dev_err(&client->dev, "Failed to get link frequency"); + return -EINVAL; } - dev_dbg(&client->dev, "detect link_freq = %d Hz", link_freq); - bridge->r.clk_lane_reg1 |= (2000000000 / link_freq) << 2; + dev_dbg(&client->dev, "detect link_freq = %lld Hz", freq); + bridge->r.clk_lane_reg1 |= (2000000000 / (u32)freq) << 2; return 0; } From patchwork Wed Mar 3 18:08:17 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Andrey Konovalov X-Patchwork-Id: 392697 Delivered-To: patch@linaro.org Received: by 2002:a17:906:a383:0:0:0:0 with SMTP id k3csp6037693ejz; Thu, 4 Mar 2021 06:35:41 -0800 (PST) X-Google-Smtp-Source: ABdhPJxSv90LkFDtu1PmjD8qWkpnOvqnt6qTiVNcZJT+ac5cVaS3yoiuQswUrCxkIQZWT5w208Hj X-Received: by 2002:a50:bc15:: with SMTP id j21mr4590324edh.187.1614868541050; Thu, 04 Mar 2021 06:35:41 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1614868541; cv=none; d=google.com; s=arc-20160816; b=rn/r1sEGjRAdhcvjMoJngLTuWgSRtuQAwgLosxwtU3I4PQCTlSV9YEyZ+z8Lpzf0y1 d1scVe8KmHJtbdpgQny2bnWlWPgB6MI+1RAnwHOPXeFCI4How/f5hODFSUyoOi7f1c31 TOQ9TfVYHu7QRZ9ed39aCtrunM//cxyz5C/T/4p9arEGyLzEGWyi0/mA9K1zeaCWpqQT Yf1UDZtNUFd7Ak+Ozyezs61croGmyg3ejxP3deLTPCBcNPM/EuQcOJIPGQJI5rDyDQJ2 1rERGAW3Vwar8wOoXsRQUMqQnHV3uH3uBzgEGAz3yql41GMDM8/YIdtU09kYDTum4oLt M+dA== 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=xxk8JtWsPIvnPUa+voyuwfGcQ4VnLMHJ8+rTKyv165c=; b=Yp1MvAo2oAZALiHuaMs2jE9aGjYK87HO3uCr0ZkXpbxsvK0VpZmw9jmSyDZze7CjJW bN5ODFkbHz+XlNb4EpAj+ZnwcfQjGDyWD2oUkQdTxQQQJ0JLXxk4/6LK3XcJ7pgZ7pdd SDc7zJMuK089rkEhZQoX/DhNjImKCzr/RIKgUQs9U7HDarE3mkh2jgkmbDT4Ct16tT9g ZmiM6Q6+ZfJqqpNH+KztMfzpNebbVvSIGImSrTk288kWCSuestmYzkg4mvrb2lNb9ogW rr1o3o7RLITpeJohsTnZEi3Jx/raHBG7QtlV0zTsRTIoPaU8RZBMHttNjrNkDCmMldUs MNGQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=UadRMHZr; 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 z9si2773695ejr.490.2021.03.04.06.35.40; Thu, 04 Mar 2021 06:35:41 -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=UadRMHZr; 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 S1355652AbhCDAcT (ORCPT + 3 others); Wed, 3 Mar 2021 19:32:19 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:53874 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S243248AbhCCSJx (ORCPT ); Wed, 3 Mar 2021 13:09:53 -0500 Received: from mail-lj1-x22d.google.com (mail-lj1-x22d.google.com [IPv6:2a00:1450:4864:20::22d]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 0DF29C061762 for ; Wed, 3 Mar 2021 10:09:02 -0800 (PST) Received: by mail-lj1-x22d.google.com with SMTP id m11so29029911lji.10 for ; Wed, 03 Mar 2021 10:09:01 -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=xxk8JtWsPIvnPUa+voyuwfGcQ4VnLMHJ8+rTKyv165c=; b=UadRMHZr2fw5MNl2lDFD/4n6o8LOE//f5BH71a2PiMAVc7ozfKsIHIS3GLGXyRLD/5 gNBqhUyNONiASCfkjfHtg0D9z+pXtapqqzzH0iq4C88c1GiB2WamvUwyDxiPQmHl6ntK 2ET0pd4uQwvREl9xCPsR8k9N3pn9AAcnEoPb0ff6DLSYraYgLp//FoAlPnybg7HjObWs aM0eFqXLnPZn5sh8pdWwp1W1Z3mBZC9RXlijs+f0MDivhejOCRFbTaW2LdcQLZPBasgY yvWPWUrvMm/ntzg0y2duTEeRmeuQeWOL+dWmVTdUgB1a6p/E6z96xUDYnaISNCDR6OQJ NTPA== 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=xxk8JtWsPIvnPUa+voyuwfGcQ4VnLMHJ8+rTKyv165c=; b=rjPuWk7ZP9CuZFQtsIf7G5z3UN5evnTiOgqdcqx2VM8uj2yXWhsX7RzAxQnxLrOGHE clRz9X68bfhJRGSf29syk5Uk32e9FFd3i2vREz3CGMH+rKVg49ptTBuaYNJtH+9CWQro FdR7X7cEgvRQK8ZYwfWHopDBD2L+wUQcWRuEdrusFCBpl8dcxjX+bPpZ4QM3pmWzcany IE2XWD8R3HwmnJr8dtyt+X6hqA+chslGKtiGLD26yN5bBj+HlPu0TnvIhz37GOhwJy7W dXdlobsUGef4Jmzo70HgQyE3xx9QjJLLqSVgHNiyIUafMF3j/GDScBagVdm+GLw+3Kmr lGwA== X-Gm-Message-State: AOAM533fZuW7JbqPyva3eEJPzOR8Lx+Su5mgHm6pLc09v5VBOeWXWThJ uKj36j0Z2Hrp4yoChoBGAMSjJw== X-Received: by 2002:a2e:509:: with SMTP id 9mr104342ljf.170.1614794940579; Wed, 03 Mar 2021 10:09:00 -0800 (PST) Received: from localhost.localdomain ([85.249.43.69]) by smtp.googlemail.com with ESMTPSA id j15sm2220990lfm.138.2021.03.03.10.08.59 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 03 Mar 2021 10:08:59 -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 4/4] staging: media: omap4iss: use v4l2_get_link_freq() to get the external rate Date: Wed, 3 Mar 2021 21:08:17 +0300 Message-Id: <20210303180817.12285-5-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 This driver uses V4L2_CID_PIXEL_RATE to calculate the CSI2 link frequency, but this may give incorrect result in some cases. Use v4l2_get_link_freq() instead. Also the driver used the external_rate field in struct iss_pipeline as a flag to prevent excessive v4l2_subdev_call's when processing the frames in single-shot mode. Replace the external_rate with external_lfreq, and use external_bpp and external_lfreq to call v4l2_subdev_call(get_fmt) and v4l2_get_link_freq() respectively only once per iss_video_streamon(). Signed-off-by: Andrey Konovalov --- drivers/staging/media/omap4iss/iss.c | 12 +----------- drivers/staging/media/omap4iss/iss_csiphy.c | 19 ++++++++++++++++--- drivers/staging/media/omap4iss/iss_video.c | 2 +- drivers/staging/media/omap4iss/iss_video.h | 2 +- 4 files changed, 19 insertions(+), 16 deletions(-) -- 2.17.1 diff --git a/drivers/staging/media/omap4iss/iss.c b/drivers/staging/media/omap4iss/iss.c index dae9073e7d3c..0eb7b1b5dcc4 100644 --- a/drivers/staging/media/omap4iss/iss.c +++ b/drivers/staging/media/omap4iss/iss.c @@ -131,7 +131,7 @@ int omap4iss_get_external_info(struct iss_pipeline *pipe, if (!pipe->external) return 0; - if (pipe->external_rate) + if (pipe->external_bpp) return 0; memset(&fmt, 0, sizeof(fmt)); @@ -145,16 +145,6 @@ int omap4iss_get_external_info(struct iss_pipeline *pipe, pipe->external_bpp = omap4iss_video_format_info(fmt.format.code)->bpp; - ctrl = v4l2_ctrl_find(pipe->external->ctrl_handler, - V4L2_CID_PIXEL_RATE); - if (!ctrl) { - dev_warn(iss->dev, "no pixel rate control in subdev %s\n", - pipe->external->name); - return -EPIPE; - } - - pipe->external_rate = v4l2_ctrl_g_ctrl_int64(ctrl); - return 0; } diff --git a/drivers/staging/media/omap4iss/iss_csiphy.c b/drivers/staging/media/omap4iss/iss_csiphy.c index 96f2ce045138..cec0cd21f7e0 100644 --- a/drivers/staging/media/omap4iss/iss_csiphy.c +++ b/drivers/staging/media/omap4iss/iss_csiphy.c @@ -119,6 +119,7 @@ int omap4iss_csiphy_config(struct iss_device *iss, struct iss_pipeline *pipe = to_iss_pipeline(&csi2_subdev->entity); struct iss_v4l2_subdevs_group *subdevs = pipe->external->host_priv; struct iss_csiphy_dphy_cfg csi2phy; + s64 link_freq; int csi2_ddrclk_khz; struct iss_csiphy_lanes_cfg *lanes; unsigned int used_lanes = 0; @@ -193,9 +194,21 @@ int omap4iss_csiphy_config(struct iss_device *iss, if (lanes->clk.pos == 0 || used_lanes & (1 << lanes->clk.pos)) return -EINVAL; - csi2_ddrclk_khz = pipe->external_rate / 1000 - / (2 * csi2->phy->used_data_lanes) - * pipe->external_bpp; + if (!pipe->external_lfreq) { + link_freq = v4l2_get_link_freq(pipe->external->ctrl_handler, + pipe->external_bpp, + 2 * csi2->phy->used_data_lanes); + if (link_freq < 0) { + dev_warn(iss->dev, + "failed to read the link frequency fromn subdev %s\n", + pipe->external->name); + return -EINVAL; + } + + pipe->external_lfreq = link_freq; + } + + csi2_ddrclk_khz = div_s64(pipe->external_lfreq, 1000); /* * THS_TERM: Programmed value = ceil(12.5 ns/DDRClk period) - 1. diff --git a/drivers/staging/media/omap4iss/iss_video.c b/drivers/staging/media/omap4iss/iss_video.c index 66975a37dc85..a654c8d18bbc 100644 --- a/drivers/staging/media/omap4iss/iss_video.c +++ b/drivers/staging/media/omap4iss/iss_video.c @@ -872,7 +872,7 @@ iss_video_streamon(struct file *file, void *fh, enum v4l2_buf_type type) pipe = entity->pipe ? to_iss_pipeline(entity) : &video->pipe; pipe->external = NULL; - pipe->external_rate = 0; + pipe->external_lfreq = 0; pipe->external_bpp = 0; ret = media_entity_enum_init(&pipe->ent_enum, entity->graph_obj.mdev); diff --git a/drivers/staging/media/omap4iss/iss_video.h b/drivers/staging/media/omap4iss/iss_video.h index 526281bf0051..2ad5c8483958 100644 --- a/drivers/staging/media/omap4iss/iss_video.h +++ b/drivers/staging/media/omap4iss/iss_video.h @@ -86,7 +86,7 @@ struct iss_pipeline { bool error; struct v4l2_fract max_timeperframe; struct v4l2_subdev *external; - unsigned int external_rate; + s64 external_lfreq; int external_bpp; };