From patchwork Sun Feb 14 21:34:03 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Andrey Konovalov X-Patchwork-Id: 382765 Delivered-To: patch@linaro.org Received: by 2002:a02:c80e:0:0:0:0:0 with SMTP id p14csp602292jao; Sun, 14 Feb 2021 13:36:31 -0800 (PST) X-Google-Smtp-Source: ABdhPJxpJ5KNXBqfe68DEq35vzYrN+6I6ICz4Ykb0czXsLsEe4Akbt243eA7+/uwCKicv35NqOkj X-Received: by 2002:aa7:d2c7:: with SMTP id k7mr12991023edr.374.1613338591508; Sun, 14 Feb 2021 13:36:31 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1613338591; cv=none; d=google.com; s=arc-20160816; b=vbUIrhhDmaGNuwEFESbWNdVtB8Kdsi5gDHRMrZHFCdYLg4pCE66OCo41Pw2+XvnUKc dKcMqUFJVml0XxmVYc85RcHP9QJHHRn/VAes5AxkiHamrs/TlVTX+hk7ycYlC5SK1rvD yLqlPAE3/Q5cfKmFg8gX/qdzSHfgkTz6C1Nc+u2d2LUWC03mbTZU2G/wgTJ3mVUMD1tr hTWCc3F1db93A0juUZJEmUCnYi4ndo87YBiDsvtW4bBHE/788dF9nAf2ROU9gXOANthE I03aZ1TpG4SX07O83sm0C/8BmOFW7iHXuUjQwp+LlXIoSdrnPhH1uWdhvXa3b+/FrIEO SCgQ== 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=OwyxdPW+uQz2PvRHiCbUYlb0g+l7nvI7gFsM94M5ULk=; b=gADgk62nCOkHLQluw+H2+nIiaADY6k41ZV76fvMa/RxEB9PN11ig5Zd6sTHcBmHIpq iHuThpqVek2ZIXUkGSnfIZGT5z4M5ZeC+YpX8cifq0gcEIKg/OdpFDU6OaoFKTsnVpUK 4hvnN8i2L6859uRTlX9L3JWR+utjCAzrac//l3VMrcOEE9OvZEXa1y5eSQykn52no0SR Xmpw4RdIlFoBdDv92jw7I5fb0agUYZNb27iOUj18DY3vzFgktVVtwxtP9WONo4wKLw3X mSmneRTMclguQQS/nZDt9iXkfZP5Jak4PnYsLUHBVm/H77iobonlaMZbuA31zKoT8oca ZGmQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=A0WmuAgO; spf=pass (google.com: domain of linux-arm-msm-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-arm-msm-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 11si14106858edw.195.2021.02.14.13.36.31; Sun, 14 Feb 2021 13:36:31 -0800 (PST) Received-SPF: pass (google.com: domain of linux-arm-msm-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=A0WmuAgO; spf=pass (google.com: domain of linux-arm-msm-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-arm-msm-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 S230056AbhBNVfZ (ORCPT + 16 others); Sun, 14 Feb 2021 16:35:25 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:35262 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229993AbhBNVfW (ORCPT ); Sun, 14 Feb 2021 16:35:22 -0500 Received: from mail-lf1-x132.google.com (mail-lf1-x132.google.com [IPv6:2a00:1450:4864:20::132]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id C741FC061756 for ; Sun, 14 Feb 2021 13:34:41 -0800 (PST) Received: by mail-lf1-x132.google.com with SMTP id w36so7403260lfu.4 for ; Sun, 14 Feb 2021 13:34:41 -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=OwyxdPW+uQz2PvRHiCbUYlb0g+l7nvI7gFsM94M5ULk=; b=A0WmuAgO29F+8WDHdWonhF2R7ZzCfcahZdbrWvn3dUi/LzW7h88MpzUpYPeVpvh9yZ cYjgZmNZz3mbFM+t/rNKKtqNX8HyQMdHhODAwDaCzCqw5/4DGw2enmbOBIJ7wqsJ/TvY uZY82rgwDPYPjPl5Z9jgD5SDWsELs0Fr98Fb7WOjIUS5/U7u+KJt4gzS3p8kD4rPUHqn x15MFsPSXpvJCkABEOh0VQ7Kz2t8kRFGmhthwf7PfTVGc0HkFftGI7pcXkKa3TZRfnaK 70vG1RWnX6hLOYMfbVqe1m7us59nnosPNQVI0/msziBMR3NtD2fZ14757wGbvWgfZpKT g7oQ== 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=OwyxdPW+uQz2PvRHiCbUYlb0g+l7nvI7gFsM94M5ULk=; b=ulS/kLchLQRS8xcGEWSo4kjR8q64k+g/iUtnfIw7XHmu3lKEchJQm3dUZjfbXpQ4ZP A09a8rbDOXvLSDXuMUMZx1XUuGn5A0zExOzZmehGtul9bszNj8vfCpibh5yeNVK8aFkE 5Js1h7T4ydJqnvPjPegAUOBQVBP8a6L93vsUGOAtBZlba660FtN6AgOPjueZSH7aSm2p wt+Eq/NxCSL/OvnkKqptZ4KGgPrVlwDKo/HQvn9AnHvPTUhUDaoi0IRhkjzY9Qz/B2VF GbVs6t9P2vHUTdxv+PYceW0O/yIP2Q3tJo520EVhO850XDGsWiBOf+gl7xOohGFKIa73 8T2A== X-Gm-Message-State: AOAM530thU1t/Edqcmdd3pINQjdp9K0odNaJkQAQ80xDdzTKTXsjhZ/D xXB0Vg2P4FJU0t6ES9b5G7piUQ== X-Received: by 2002:a05:6512:3081:: with SMTP id z1mr7087127lfd.257.1613338480275; Sun, 14 Feb 2021 13:34:40 -0800 (PST) Received: from localhost.localdomain ([85.249.43.69]) by smtp.googlemail.com with ESMTPSA id h11sm2500066lfd.243.2021.02.14.13.34.39 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 14 Feb 2021 13:34:39 -0800 (PST) From: Andrey Konovalov To: junak.pub@gmail.com, robert.foss@linaro.org, sakari.ailus@linux.intel.com Cc: todor.too@gmail.com, agross@kernel.org, bjorn.andersson@linaro.org, mchehab@kernel.org, laurent.pinchart@ideasonboard.com, jacopo@jmondi.org, linux-media@vger.kernel.org, linux-arm-msm@vger.kernel.org, linux-kernel@vger.kernel.org, Andrey Konovalov Subject: [PATCH 1/2] media: camss: use v4l2_get_link_freq() to calculate the relevant clocks Date: Mon, 15 Feb 2021 00:34:03 +0300 Message-Id: <20210214213404.8373-2-andrey.konovalov@linaro.org> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20210214213404.8373-1-andrey.konovalov@linaro.org> References: <20210214213404.8373-1-andrey.konovalov@linaro.org> Precedence: bulk List-ID: X-Mailing-List: linux-arm-msm@vger.kernel.org There are places in the camss driver where camss_get_pixel_clock() is called to get the pixel rate (using V4L2_CID_PIXEL_RATE control) and to calculate the link frequency from it. There is a case when this would not work: when V4L2_CID_PIXEL_RATE gets the rate at which the pixels are read (sampled) from the sensor's pixel array, and this rate is different from the pixel transmission rate over the CSI link, the link frequency value can't be calculated from the pixel rate. One needs to use V4L2_CID_LINK_FREQ to get the link frequency in this case. Replace such calls to camss_get_pixel_clock() with calls to a wrapper around v4l2_get_link_freq(). v4l2_get_link_freq() tries V4L2_CID_LINK_FREQ first, and if it is not implemented by the camera sensor driver, falls back to V4L2_CID_PIXEL_RATE to calculate the link frequency value from. Calls to camss_get_pixel_clock() from vfe_[check,set]_clock_rates() are left intact as it looks like this VFE clock does depend on the rate the pixel samples comes out of the camera sensor, not on the frequency at which the link between the sensor and the CSI receiver operates. Signed-off-by: Andrey Konovalov --- .../media/platform/qcom/camss/camss-csid.c | 22 ++++++------ .../qcom/camss/camss-csiphy-2ph-1-0.c | 22 ++++++------ .../qcom/camss/camss-csiphy-3ph-1-0.c | 22 ++++++------ .../media/platform/qcom/camss/camss-csiphy.c | 36 +++++++++---------- .../media/platform/qcom/camss/camss-csiphy.h | 2 +- drivers/media/platform/qcom/camss/camss.c | 23 ++++++++++++ drivers/media/platform/qcom/camss/camss.h | 2 ++ 7 files changed, 73 insertions(+), 56 deletions(-) -- 2.17.1 Reviewed-by: Robert Foss Acked-by: Robert Foss diff --git a/drivers/media/platform/qcom/camss/camss-csid.c b/drivers/media/platform/qcom/camss/camss-csid.c index be3fe76f3dc3..b2cbf4b65949 100644 --- a/drivers/media/platform/qcom/camss/camss-csid.c +++ b/drivers/media/platform/qcom/camss/camss-csid.c @@ -462,13 +462,19 @@ static irqreturn_t csid_isr(int irq, void *dev) static int csid_set_clock_rates(struct csid_device *csid) { struct device *dev = csid->camss->dev; - u32 pixel_clock; + s64 link_freq; int i, j; int ret; - ret = camss_get_pixel_clock(&csid->subdev.entity, &pixel_clock); - if (ret) - pixel_clock = 0; + const struct csid_format *f = csid_get_fmt_entry( + csid->formats, + csid->nformats, + csid->fmt[MSM_CSIPHY_PAD_SINK].code); + u8 num_lanes = csid->phy.lane_cnt; + link_freq = camss_get_link_freq(&csid->subdev.entity, f->bpp, + 2 * num_lanes); + if (link_freq < 0) + link_freq = 0; for (i = 0; i < csid->nclocks; i++) { struct camss_clock *clock = &csid->clock[i]; @@ -477,13 +483,7 @@ static int csid_set_clock_rates(struct csid_device *csid) !strcmp(clock->name, "csi1") || !strcmp(clock->name, "csi2") || !strcmp(clock->name, "csi3")) { - const struct csid_format *f = csid_get_fmt_entry( - csid->formats, - csid->nformats, - csid->fmt[MSM_CSIPHY_PAD_SINK].code); - u8 num_lanes = csid->phy.lane_cnt; - u64 min_rate = pixel_clock * f->bpp / - (2 * num_lanes * 4); + u64 min_rate = link_freq / 4; long rate; camss_add_clock_margin(&min_rate); diff --git a/drivers/media/platform/qcom/camss/camss-csiphy-2ph-1-0.c b/drivers/media/platform/qcom/camss/camss-csiphy-2ph-1-0.c index 12bce391d71f..30b454c369ab 100644 --- a/drivers/media/platform/qcom/camss/camss-csiphy-2ph-1-0.c +++ b/drivers/media/platform/qcom/camss/camss-csiphy-2ph-1-0.c @@ -51,16 +51,13 @@ static void csiphy_reset(struct csiphy_device *csiphy) * * Helper function to calculate settle count value. This is * based on the CSI2 T_hs_settle parameter which in turn - * is calculated based on the CSI2 transmitter pixel clock - * frequency. + * is calculated based on the CSI2 transmitter link frequency. * - * Return settle count value or 0 if the CSI2 pixel clock - * frequency is not available + * Return settle count value or 0 if the CSI2 link frequency + * is not available */ -static u8 csiphy_settle_cnt_calc(u32 pixel_clock, u8 bpp, u8 num_lanes, - u32 timer_clk_rate) +static u8 csiphy_settle_cnt_calc(s64 link_freq, u32 timer_clk_rate) { - u32 mipi_clock; /* Hz */ u32 ui; /* ps */ u32 timer_period; /* ps */ u32 t_hs_prepare_max; /* ps */ @@ -68,8 +65,10 @@ static u8 csiphy_settle_cnt_calc(u32 pixel_clock, u8 bpp, u8 num_lanes, u32 t_hs_settle; /* ps */ u8 settle_cnt; - mipi_clock = pixel_clock * bpp / (2 * num_lanes); - ui = div_u64(1000000000000LL, mipi_clock); + if (link_freq <= 0) + return 0; + + ui = div_u64(1000000000000LL, link_freq); ui /= 2; t_hs_prepare_max = 85000 + 6 * ui; t_hs_prepare_zero_min = 145000 + 10 * ui; @@ -83,15 +82,14 @@ static u8 csiphy_settle_cnt_calc(u32 pixel_clock, u8 bpp, u8 num_lanes, static void csiphy_lanes_enable(struct csiphy_device *csiphy, struct csiphy_config *cfg, - u32 pixel_clock, u8 bpp, u8 lane_mask) + s64 link_freq, u8 lane_mask) { struct csiphy_lanes_cfg *c = &cfg->csi2->lane_cfg; u8 settle_cnt; u8 val, l = 0; int i = 0; - settle_cnt = csiphy_settle_cnt_calc(pixel_clock, bpp, c->num_data, - csiphy->timer_clk_rate); + settle_cnt = csiphy_settle_cnt_calc(link_freq, csiphy->timer_clk_rate); writel_relaxed(0x1, csiphy->base + CAMSS_CSI_PHY_GLBL_T_INIT_CFG0); diff --git a/drivers/media/platform/qcom/camss/camss-csiphy-3ph-1-0.c b/drivers/media/platform/qcom/camss/camss-csiphy-3ph-1-0.c index 97cb9de85031..da7c3d3f9a10 100644 --- a/drivers/media/platform/qcom/camss/camss-csiphy-3ph-1-0.c +++ b/drivers/media/platform/qcom/camss/camss-csiphy-3ph-1-0.c @@ -107,24 +107,23 @@ static irqreturn_t csiphy_isr(int irq, void *dev) * * Helper function to calculate settle count value. This is * based on the CSI2 T_hs_settle parameter which in turn - * is calculated based on the CSI2 transmitter pixel clock - * frequency. + * is calculated based on the CSI2 transmitter link frequency. * - * Return settle count value or 0 if the CSI2 pixel clock - * frequency is not available + * Return settle count value or 0 if the CSI2 link frequency + * is not available */ -static u8 csiphy_settle_cnt_calc(u32 pixel_clock, u8 bpp, u8 num_lanes, - u32 timer_clk_rate) +static u8 csiphy_settle_cnt_calc(s64 link_freq, u32 timer_clk_rate) { - u32 mipi_clock; /* Hz */ u32 ui; /* ps */ u32 timer_period; /* ps */ u32 t_hs_prepare_max; /* ps */ u32 t_hs_settle; /* ps */ u8 settle_cnt; - mipi_clock = pixel_clock * bpp / (2 * num_lanes); - ui = div_u64(1000000000000LL, mipi_clock); + if (link_freq <= 0) + return 0; + + ui = div_u64(1000000000000LL, link_freq); ui /= 2; t_hs_prepare_max = 85000 + 6 * ui; t_hs_settle = t_hs_prepare_max; @@ -137,15 +136,14 @@ static u8 csiphy_settle_cnt_calc(u32 pixel_clock, u8 bpp, u8 num_lanes, static void csiphy_lanes_enable(struct csiphy_device *csiphy, struct csiphy_config *cfg, - u32 pixel_clock, u8 bpp, u8 lane_mask) + s64 link_freq, u8 lane_mask) { struct csiphy_lanes_cfg *c = &cfg->csi2->lane_cfg; u8 settle_cnt; u8 val, l = 0; int i; - settle_cnt = csiphy_settle_cnt_calc(pixel_clock, bpp, c->num_data, - csiphy->timer_clk_rate); + settle_cnt = csiphy_settle_cnt_calc(link_freq, csiphy->timer_clk_rate); val = BIT(c->clk.pos); for (i = 0; i < c->num_data; i++) diff --git a/drivers/media/platform/qcom/camss/camss-csiphy.c b/drivers/media/platform/qcom/camss/camss-csiphy.c index 509c9a59c09c..9b5fe6fc7664 100644 --- a/drivers/media/platform/qcom/camss/camss-csiphy.c +++ b/drivers/media/platform/qcom/camss/camss-csiphy.c @@ -102,23 +102,23 @@ static u8 csiphy_get_bpp(const struct csiphy_format *formats, static int csiphy_set_clock_rates(struct csiphy_device *csiphy) { struct device *dev = csiphy->camss->dev; - u32 pixel_clock; + s64 link_freq; int i, j; int ret; - ret = camss_get_pixel_clock(&csiphy->subdev.entity, &pixel_clock); - if (ret) - pixel_clock = 0; + u8 bpp = csiphy_get_bpp(csiphy->formats, csiphy->nformats, + csiphy->fmt[MSM_CSIPHY_PAD_SINK].code); + u8 num_lanes = csiphy->cfg.csi2->lane_cfg.num_data; + link_freq = camss_get_link_freq(&csiphy->subdev.entity, bpp, + 2 * num_lanes); + if (link_freq < 0) + link_freq = 0; for (i = 0; i < csiphy->nclocks; i++) { struct camss_clock *clock = &csiphy->clock[i]; if (csiphy->rate_set[i]) { - u8 bpp = csiphy_get_bpp(csiphy->formats, - csiphy->nformats, - csiphy->fmt[MSM_CSIPHY_PAD_SINK].code); - u8 num_lanes = csiphy->cfg.csi2->lane_cfg.num_data; - u64 min_rate = pixel_clock * bpp / (2 * num_lanes * 4); + u64 min_rate = link_freq / 4; long round_rate; camss_add_clock_margin(&min_rate); @@ -238,22 +238,18 @@ static u8 csiphy_get_lane_mask(struct csiphy_lanes_cfg *lane_cfg) static int csiphy_stream_on(struct csiphy_device *csiphy) { struct csiphy_config *cfg = &csiphy->cfg; - u32 pixel_clock; + s64 link_freq; u8 lane_mask = csiphy_get_lane_mask(&cfg->csi2->lane_cfg); u8 bpp = csiphy_get_bpp(csiphy->formats, csiphy->nformats, csiphy->fmt[MSM_CSIPHY_PAD_SINK].code); + u8 num_lanes = csiphy->cfg.csi2->lane_cfg.num_data; u8 val; - int ret; - ret = camss_get_pixel_clock(&csiphy->subdev.entity, &pixel_clock); - if (ret) { - dev_err(csiphy->camss->dev, - "Cannot get CSI2 transmitter's pixel clock\n"); - return -EINVAL; - } - if (!pixel_clock) { + link_freq = camss_get_link_freq(&csiphy->subdev.entity, bpp, + 2 * num_lanes); + if (link_freq < 0) { dev_err(csiphy->camss->dev, - "Got pixel clock == 0, cannot continue\n"); + "Cannot get CSI2 transmitter's link frequency\n"); return -EINVAL; } @@ -268,7 +264,7 @@ static int csiphy_stream_on(struct csiphy_device *csiphy) writel_relaxed(val, csiphy->base_clk_mux); wmb(); - csiphy->ops->lanes_enable(csiphy, cfg, pixel_clock, bpp, lane_mask); + csiphy->ops->lanes_enable(csiphy, cfg, link_freq, lane_mask); return 0; } diff --git a/drivers/media/platform/qcom/camss/camss-csiphy.h b/drivers/media/platform/qcom/camss/camss-csiphy.h index f7967ef836dc..d71b8bc6ec00 100644 --- a/drivers/media/platform/qcom/camss/camss-csiphy.h +++ b/drivers/media/platform/qcom/camss/camss-csiphy.h @@ -50,7 +50,7 @@ struct csiphy_hw_ops { void (*reset)(struct csiphy_device *csiphy); void (*lanes_enable)(struct csiphy_device *csiphy, struct csiphy_config *cfg, - u32 pixel_clock, u8 bpp, u8 lane_mask); + s64 link_freq, u8 lane_mask); void (*lanes_disable)(struct csiphy_device *csiphy, struct csiphy_config *cfg); irqreturn_t (*isr)(int irq, void *dev); diff --git a/drivers/media/platform/qcom/camss/camss.c b/drivers/media/platform/qcom/camss/camss.c index 7c0f669f8aa6..2888c7ef2303 100644 --- a/drivers/media/platform/qcom/camss/camss.c +++ b/drivers/media/platform/qcom/camss/camss.c @@ -548,6 +548,29 @@ struct media_entity *camss_find_sensor(struct media_entity *entity) } } +/** + * camss_get_link_freq - Get link frequency from sensor + * @entity: Media entity in the current pipeline + * @bpp: Number of bits per pixel for the current format + * @lanes: Number of lanes in the link to the sensor + * + * Return link frequency on success or a negative error code otherwise + */ +s64 camss_get_link_freq(struct media_entity *entity, unsigned int bpp, + unsigned int lanes) +{ + struct media_entity *sensor; + struct v4l2_subdev *subdev; + + sensor = camss_find_sensor(entity); + if (!sensor) + return -ENODEV; + + subdev = media_entity_to_v4l2_subdev(sensor); + + return v4l2_get_link_freq(subdev->ctrl_handler, bpp, lanes); +} + /* * camss_get_pixel_clock - Get pixel clock rate from sensor * @entity: Media entity in the current pipeline diff --git a/drivers/media/platform/qcom/camss/camss.h b/drivers/media/platform/qcom/camss/camss.h index 3a0484683cd6..86cdc25189eb 100644 --- a/drivers/media/platform/qcom/camss/camss.h +++ b/drivers/media/platform/qcom/camss/camss.h @@ -108,6 +108,8 @@ int camss_enable_clocks(int nclocks, struct camss_clock *clock, struct device *dev); void camss_disable_clocks(int nclocks, struct camss_clock *clock); struct media_entity *camss_find_sensor(struct media_entity *entity); +s64 camss_get_link_freq(struct media_entity *entity, unsigned int bpp, + unsigned int lanes); int camss_get_pixel_clock(struct media_entity *entity, u32 *pixel_clock); int camss_pm_domain_on(struct camss *camss, int id); void camss_pm_domain_off(struct camss *camss, int id); From patchwork Sun Feb 14 21:34:04 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Andrey Konovalov X-Patchwork-Id: 382766 Delivered-To: patch@linaro.org Received: by 2002:a02:c80e:0:0:0:0:0 with SMTP id p14csp602338jao; Sun, 14 Feb 2021 13:36:37 -0800 (PST) X-Google-Smtp-Source: ABdhPJyX3nhDPO2lbSPrRFzctrho+4VOkcayI7hueJiLVyvTcHLpVbFVorQGe3dELIZNiHXL5dDd X-Received: by 2002:a05:6402:26c7:: with SMTP id x7mr13065115edd.24.1613338597106; Sun, 14 Feb 2021 13:36:37 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1613338597; cv=none; d=google.com; s=arc-20160816; b=UbWffurc0mcu2hIs3yffsE4oYqN/RlapJSvPIpZ6XW8EyvspZxdh9kCQ7fQW/LRguY MdML1ezKq5wYURtq2xCX+GYhFe32IMMVbswvcJMiOr65DCJ4uMzxTKqxZAy8lovMWjjB hQL8DGpI7DcdQmfZ6Wd1l1i809qdPzlohrvfZaW17hNOdaxI65FQFUpfuoGWnWKAPYWh IvLaqiQQLD4rHjmG1npeSWNN5SrM2qTJ6LdDyHAKuRdk9hMF00FGDD5PQM+1JOxedMov RcrMLlaK448D+BnfndNGRLGgTE39lSMg/sTEt0LGFf8QWWRVaVUOwVpOM2mAmWGVLc2E tAnw== 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=X3oQlK034EEXzVHV9w/Hp4W7yC/z0cpwLLXOmsVzkLI=; b=aYsHRcM9xT2aW5HbP7/3kvLHY36kvuiqIGCHbo9okMEo3thMWYFn+Up7xAY1zUeaQC +WPq8ciBk1RFF5ngkGDwZV16G/xSC4pzD4Ns377jwqR6Fux2QQndCGlJCnus4nF+zOtR y+PBl9GvtvhWFoogzEtiCTAPJCZpK0w0J1hgRib3Db0MGiSDhx9Ufua3F9fHijzo0U6m 8CCt4a8GqGUedZ3mbsQiJRWg+6+bKP+Jr7EJvnSq/1zcWftgk5Ydwv1CZn+xDnD1pzUT 2qaOB9fJxq2oF5U1HCFQryEVk03IYJ83qZumucLCEDhAs1q1p0LAL/KE4WE4uWG+WBbQ gmwg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=BT87Egep; spf=pass (google.com: domain of linux-arm-msm-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-arm-msm-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 11si14106858edw.195.2021.02.14.13.36.36; Sun, 14 Feb 2021 13:36:37 -0800 (PST) Received-SPF: pass (google.com: domain of linux-arm-msm-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=BT87Egep; spf=pass (google.com: domain of linux-arm-msm-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-arm-msm-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 S230015AbhBNVgO (ORCPT + 16 others); Sun, 14 Feb 2021 16:36:14 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:35396 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230052AbhBNVf4 (ORCPT ); Sun, 14 Feb 2021 16:35:56 -0500 Received: from mail-lj1-x22f.google.com (mail-lj1-x22f.google.com [IPv6:2a00:1450:4864:20::22f]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 7D7DFC06178C for ; Sun, 14 Feb 2021 13:34:44 -0800 (PST) Received: by mail-lj1-x22f.google.com with SMTP id a17so5593044ljq.2 for ; Sun, 14 Feb 2021 13:34:44 -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=X3oQlK034EEXzVHV9w/Hp4W7yC/z0cpwLLXOmsVzkLI=; b=BT87EgepeeF5OxT3DLWBnraFAXWBUJw+XsAhozM0jPI1+hOKYBATXfvW5DpTFyT2QW 8JcNrdCYRRJX7sBZVBiBdiOmSG1DdfDcLTl0Fw2cnJrz4xbw3uu7FQ2D2lHK6evp9Gif sOM1dsOtUxw5YwsFtXQS/4KfyOKh6H78Cdm5WQB+h+wS0aX58JCUt+i3co59QOv5vprO dTXJjN+XlR2RdzjFZ5rDjfLldzLxtimRoAnY1EK+MFfSn7O3xgv5Kx3rnFyMzt3ugsFC s6VqqcopcUGZIELFepM6U577xkzabQcuP9+9aPw+2EvnB/lmg11iy8DYUHiH1Z/f09vk NrBQ== 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=X3oQlK034EEXzVHV9w/Hp4W7yC/z0cpwLLXOmsVzkLI=; b=e30JpTdN69h0rOstNdSjwYKptR8cJE0csHvtxHdJnYw/axEJO9txCsFOvIcwvDb4i+ Ysa9GCPvBnPT4xU1LXKckdY2uBkx+rfcTTJV+rS+NRSHZVsZYZnasVfe8umkEvJyYiG8 dcIsFi4wanPFN6rMM+LXRMmK8LJ+l/SlLT2XvhHb4JiO+nYZO7rQZIDyPdDjtdHHF7Jm o8dN6yqT4gnc8nb7Jie2tsyVwn7A7OT2ZWJreVPwspDXcWlCdz47ByTHEDMg/K/+dWEU VWebNANSktMJ+c/trEotNZT/ERmZvo1aNNKSq0ifOmg92qQd7xjmLuDNVcQc/GCm9R1S y9Uw== X-Gm-Message-State: AOAM531lNecneSy45EB187FoY1+EGNp9wrEh2/IPnJss48M0JXWft8lW WZXQITskGL9uqiM0er7IiCkiIg== X-Received: by 2002:a05:651c:1386:: with SMTP id k6mr7286329ljb.51.1613338482946; Sun, 14 Feb 2021 13:34:42 -0800 (PST) Received: from localhost.localdomain ([85.249.43.69]) by smtp.googlemail.com with ESMTPSA id h11sm2500066lfd.243.2021.02.14.13.34.41 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 14 Feb 2021 13:34:42 -0800 (PST) From: Andrey Konovalov To: junak.pub@gmail.com, robert.foss@linaro.org, sakari.ailus@linux.intel.com Cc: todor.too@gmail.com, agross@kernel.org, bjorn.andersson@linaro.org, mchehab@kernel.org, laurent.pinchart@ideasonboard.com, jacopo@jmondi.org, linux-media@vger.kernel.org, linux-arm-msm@vger.kernel.org, linux-kernel@vger.kernel.org, Andrey Konovalov Subject: [PATCH 2/2] media: qcom: camss: Fix overflows in clock rate calculations Date: Mon, 15 Feb 2021 00:34:04 +0300 Message-Id: <20210214213404.8373-3-andrey.konovalov@linaro.org> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20210214213404.8373-1-andrey.konovalov@linaro.org> References: <20210214213404.8373-1-andrey.konovalov@linaro.org> Precedence: bulk List-ID: X-Mailing-List: linux-arm-msm@vger.kernel.org From: Vladimir Lypak Because of u32 type being used to store pixel clock rate, expression used to calculate pipeline clocks (pixel_clock * bpp) produces wrong value due to integer overflow. This patch changes data type used to store, pass and retrieve pixel_clock from u32 to u64 to make this mistake less likely to be repeated in the future. Signed-off-by: Vladimir Lypak Acked-by: Robert Foss Signed-off-by: Andrey Konovalov --- drivers/media/platform/qcom/camss/camss-vfe.c | 4 ++-- drivers/media/platform/qcom/camss/camss.c | 2 +- drivers/media/platform/qcom/camss/camss.h | 2 +- 3 files changed, 4 insertions(+), 4 deletions(-) -- 2.17.1 diff --git a/drivers/media/platform/qcom/camss/camss-vfe.c b/drivers/media/platform/qcom/camss/camss-vfe.c index fae2b513b2f9..b2c95b46ce66 100644 --- a/drivers/media/platform/qcom/camss/camss-vfe.c +++ b/drivers/media/platform/qcom/camss/camss-vfe.c @@ -1112,7 +1112,7 @@ static inline void vfe_isr_halt_ack(struct vfe_device *vfe) static int vfe_set_clock_rates(struct vfe_device *vfe) { struct device *dev = vfe->camss->dev; - u32 pixel_clock[MSM_VFE_LINE_NUM]; + u64 pixel_clock[MSM_VFE_LINE_NUM]; int i, j; int ret; @@ -1194,7 +1194,7 @@ static int vfe_set_clock_rates(struct vfe_device *vfe) */ static int vfe_check_clock_rates(struct vfe_device *vfe) { - u32 pixel_clock[MSM_VFE_LINE_NUM]; + u64 pixel_clock[MSM_VFE_LINE_NUM]; int i, j; int ret; diff --git a/drivers/media/platform/qcom/camss/camss.c b/drivers/media/platform/qcom/camss/camss.c index 2888c7ef2303..ea17f5997dc6 100644 --- a/drivers/media/platform/qcom/camss/camss.c +++ b/drivers/media/platform/qcom/camss/camss.c @@ -578,7 +578,7 @@ s64 camss_get_link_freq(struct media_entity *entity, unsigned int bpp, * * Return 0 on success or a negative error code otherwise */ -int camss_get_pixel_clock(struct media_entity *entity, u32 *pixel_clock) +int camss_get_pixel_clock(struct media_entity *entity, u64 *pixel_clock) { struct media_entity *sensor; struct v4l2_subdev *subdev; diff --git a/drivers/media/platform/qcom/camss/camss.h b/drivers/media/platform/qcom/camss/camss.h index 86cdc25189eb..e29466d07ad2 100644 --- a/drivers/media/platform/qcom/camss/camss.h +++ b/drivers/media/platform/qcom/camss/camss.h @@ -110,7 +110,7 @@ void camss_disable_clocks(int nclocks, struct camss_clock *clock); struct media_entity *camss_find_sensor(struct media_entity *entity); s64 camss_get_link_freq(struct media_entity *entity, unsigned int bpp, unsigned int lanes); -int camss_get_pixel_clock(struct media_entity *entity, u32 *pixel_clock); +int camss_get_pixel_clock(struct media_entity *entity, u64 *pixel_clock); int camss_pm_domain_on(struct camss *camss, int id); void camss_pm_domain_off(struct camss *camss, int id); void camss_delete(struct camss *camss);