Received: by 2002:a25:2c96:0:0:0:0:0 with SMTP id s144csp521022ybs; Sun, 24 May 2020 12:31:00 -0700 (PDT) X-Google-Smtp-Source: ABdhPJzuhVES1gcTURMggUH+eXU70u2X2WDLE/HVT+15zvH5Utkat0qvyRHXnCiLgZhn0XmNWzx8 X-Received: by 2002:aa7:cb4f:: with SMTP id w15mr12273348edt.239.1590348660498; Sun, 24 May 2020 12:31:00 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1590348660; cv=none; d=google.com; s=arc-20160816; b=jDkkussLEKwIE5gKUNVdOrmKzeDRYZAmz9OYFHOuXF3WYX/RH/remm7A2ddbMWvu37 4/2VpBVISL9GxSomf3Ux29qKBFf2w8FFk8mNMNaaTZJ7Pgl4zd+rSkqQ2Mqsnoj+G8z/ kXQs6ic+S9mdJhv4vUrak4uK2MFxq1lm5L00Xs8KE/UjBLrs5Fr3RHC2a2sc8C0YyTHz XmVjh6x4IjlJrdlypRw0ZnLLQrThPWyT4hNoBlgNCQxsNOtryRBVq7gtNE9C5wnzz3Z8 6RhicK3auTB8WwICnNs5YjhPT8GwXrChbqpF1mll8JloBrw6GaoE4yMU3KrT2l5jmzEH rekA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:references:in-reply-to:message-id:date :subject:cc:to:from:dkim-signature; bh=yVilPSB28wiJ3qo4ENpoTa0U9qIpxtxzCgolTCdGKWo=; b=BI5FNHXTFcROdVgBk1vGb78249L1uJeNHu/1LJg0qfLM9b5MRTQexhV12Y0GmY7lTO 3ECQyNfR3HLIhwKX4P1nSmi3xfP7JAY3WufMMkbDpodSNzPxTwF9my1ZaMvy9AXuqz3M 4WlhIh7+ZL7YZ1gEZJoFpYQE5+ROS4Dn4M4fMHuHfq8VmEJoe5ttM4IeeNScdG3+IIpu MK+XURjyRh8fybCGPN4K/PaZLRSU4kJ9WCrmj9Iv4RiILjxEVfaYbx5HB5EtzitjemDz 89Rx7dGCHRvmcyripRUpkqEfj/v+8txA25v01z2Ej6DE3uD5RN5IJ5fH9Pz/OsnE5dh0 zp6Q== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=O0iGA+nk; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-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 q6si8421459edj.601.2020.05.24.12.30.37; Sun, 24 May 2020 12:31:00 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-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=O0iGA+nk; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-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 S2388419AbgEXT0Z (ORCPT + 99 others); Sun, 24 May 2020 15:26:25 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:37546 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S2388301AbgEXTZs (ORCPT ); Sun, 24 May 2020 15:25:48 -0400 Received: from mail-lj1-x244.google.com (mail-lj1-x244.google.com [IPv6:2a00:1450:4864:20::244]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id D6AF3C05BD43 for ; Sun, 24 May 2020 12:25:47 -0700 (PDT) Received: by mail-lj1-x244.google.com with SMTP id a25so6899438ljp.3 for ; Sun, 24 May 2020 12:25:47 -0700 (PDT) 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=yVilPSB28wiJ3qo4ENpoTa0U9qIpxtxzCgolTCdGKWo=; b=O0iGA+nkmPxFQkUtW87EE7yoXxMEW/Ado6yrzVZAqtOQY6BVLyUFkDEmDdcu3qVbI+ 1I27ZyzQ6+cMuIQAPPeaHvj0P4jefWb64qeDvTmjo+G1oLcIsJNCMtxDUyOIe746mAWH yvRs21NMkAv0LdYSHRH8Cv54DNnGYGPP1+hBSkFOOMem77gEXH86HXPVZIvxSgfgzHCF a2dKMJPvLBuIMHipKUpQuS/0AI/qszvz6cSHzfYym9Lrq9yymUytNzwNBk05KY8oX9ky a13DSnz9LagIBECnsqBxA3zFWqe8hdvqNqPLC7U9VmFfQaHZ5K1SR9U6fHHR2U6kcykX ckJw== 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=yVilPSB28wiJ3qo4ENpoTa0U9qIpxtxzCgolTCdGKWo=; b=BCI0LLuPb0CTPA4QRtC3eWLi5hDh2iec+gKNQP+bisB+SjKjDlds4B7voBH4PqtoHz ua/+Y2Jd60BxgnTvr3KwkRAQkcnVojb38Z/P4Q7SoevYTYeYgqkuD4tfU/Y+6JMsw4Bu dXs360r0Hhj9hBlXuAvFHVl/1T9Xwlm0SZxpGanUo5mF6s0rF+4e2FKaOBiR1gulz2Ll QZeI6YANiYuNwjKmeZkvFGQE2IyEYJvbW8XLgNgGqr7+oHBla/JNGXEqV25geJPXK+jf clkH09POV/UfyEGJN7soNC9MpgAcjY/Fd5i3WuGq8dyvsEkVs07zyuWnj3r0R3JvZMWp S3EQ== X-Gm-Message-State: AOAM533FSnNtYJSVWF36iAsvC1JDgd3FdeLKY6yH0Thrd3uDhCGz8QxK bPymyrw5OPPPWI67qC88cx8pfQXbIfGAOA== X-Received: by 2002:a2e:9787:: with SMTP id y7mr5167301lji.107.1590348346340; Sun, 24 May 2020 12:25:46 -0700 (PDT) Received: from localhost.localdomain (37-144-159-139.broadband.corbina.ru. [37.144.159.139]) by smtp.googlemail.com with ESMTPSA id v10sm3878137lja.23.2020.05.24.12.25.45 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 24 May 2020 12:25:45 -0700 (PDT) From: Andrey Konovalov To: mchehab@kernel.org, sakari.ailus@iki.fi, manivannan.sadhasivam@linaro.org Cc: linux-media@vger.kernel.org, linux-kernel@vger.kernel.org, devicetree@vger.kernel.org, linux-arm-kernel@lists.infradead.org, c.barrett@framos.com, a.brela@framos.com, peter.griffin@linaro.org, Andrey Konovalov Subject: [PATCH v3 05/10] media: i2c: imx290: Add configurable link frequency and pixel rate Date: Sun, 24 May 2020 22:25:00 +0300 Message-Id: <20200524192505.20682-6-andrey.konovalov@linaro.org> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20200524192505.20682-1-andrey.konovalov@linaro.org> References: <20200524192505.20682-1-andrey.konovalov@linaro.org> Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: Manivannan Sadhasivam IMX290 operates with multiple link frequency and pixel rate combinations. The initial driver used a single setting for both but since we now have the lane count support in place, let's add configurable link frequency and pixel rate. Signed-off-by: Manivannan Sadhasivam Signed-off-by: Andrey Konovalov --- drivers/media/i2c/imx290.c | 100 ++++++++++++++++++++++++------------- 1 file changed, 66 insertions(+), 34 deletions(-) diff --git a/drivers/media/i2c/imx290.c b/drivers/media/i2c/imx290.c index a361c9ac8bd5..e800557cf423 100644 --- a/drivers/media/i2c/imx290.c +++ b/drivers/media/i2c/imx290.c @@ -38,8 +38,6 @@ #define IMX290_HMAX_2_720 0x19C8 #define IMX290_HMAX_4_720 0x0CE4 -#define IMX290_DEFAULT_LINK_FREQ 445500000 - static const char * const imx290_supply_name[] = { "vdda", "vddd", @@ -56,8 +54,6 @@ struct imx290_regval { struct imx290_mode { u32 width; u32 height; - u32 pixel_rate; - u32 link_freq_index; const struct imx290_regval *data; u32 data_size; @@ -248,8 +244,13 @@ static const struct imx290_regval imx290_10bit_settings[] = { }; /* supported link frequencies */ -static const s64 imx290_link_freq[] = { - IMX290_DEFAULT_LINK_FREQ, +static const s64 imx290_link_freq_2lanes[] = { + 891000000, /* 1920x1080 - 2 lane */ + 594000000, /* 1280x720 - 2 lane */ +}; +static const s64 imx290_link_freq_4lanes[] = { + 445500000, /* 1920x1080 - 4 lane */ + 297000000, /* 1280x720 - 4 lane */ }; /* Mode configs */ @@ -259,16 +260,12 @@ static const struct imx290_mode imx290_modes[] = { .height = 1080, .data = imx290_1080p_settings, .data_size = ARRAY_SIZE(imx290_1080p_settings), - .pixel_rate = 178200000, - .link_freq_index = 0, }, { .width = 1280, .height = 720, .data = imx290_720p_settings, .data_size = ARRAY_SIZE(imx290_720p_settings), - .pixel_rate = 178200000, - .link_freq_index = 0, }, }; @@ -442,6 +439,32 @@ static int imx290_get_fmt(struct v4l2_subdev *sd, return 0; } +static u8 imx290_get_link_freq_index(struct imx290 *imx290) +{ + const struct imx290_mode *cur_mode = imx290->current_mode; + + return (cur_mode->width == 1920) ? 0 : 1; +} + +static s64 imx290_get_link_freq(struct imx290 *imx290) +{ + u8 index = imx290_get_link_freq_index(imx290); + + if (imx290->nlanes == 4) + return imx290_link_freq_4lanes[index]; + else + return imx290_link_freq_2lanes[index]; +} + +static u64 imx290_calc_pixel_rate(struct imx290 *imx290) +{ + s64 link_freq = imx290_get_link_freq(imx290); + u8 nlanes = imx290->nlanes; + + /* pixel rate = link_freq * 2 * nr_of_lanes / bits_per_sample */ + return (link_freq * 2 * nlanes / 10); +} + static int imx290_set_fmt(struct v4l2_subdev *sd, struct v4l2_subdev_pad_config *cfg, struct v4l2_subdev_format *fmt) @@ -475,10 +498,14 @@ static int imx290_set_fmt(struct v4l2_subdev *sd, format = v4l2_subdev_get_try_format(sd, cfg, fmt->pad); } else { format = &imx290->current_format; - __v4l2_ctrl_s_ctrl(imx290->link_freq, mode->link_freq_index); - __v4l2_ctrl_s_ctrl_int64(imx290->pixel_rate, mode->pixel_rate); - imx290->current_mode = mode; + + if (imx290->link_freq) + __v4l2_ctrl_s_ctrl(imx290->link_freq, + imx290_get_link_freq_index(imx290)); + if (imx290->pixel_rate) + __v4l2_ctrl_s_ctrl_int64(imx290->pixel_rate, + imx290_calc_pixel_rate(imx290)); } *format = fmt->format; @@ -502,12 +529,11 @@ static int imx290_entity_init_cfg(struct v4l2_subdev *subdev, return 0; } -static int imx290_write_current_format(struct imx290 *imx290, - struct v4l2_mbus_framefmt *format) +static int imx290_write_current_format(struct imx290 *imx290) { int ret; - switch (format->code) { + switch (imx290->current_format.code) { case MEDIA_BUS_FMT_SRGGB10_1X10: ret = imx290_set_register_array(imx290, imx290_10bit_settings, ARRAY_SIZE( @@ -558,8 +584,8 @@ static int imx290_start_streaming(struct imx290 *imx290) return ret; } - /* Set current frame format */ - ret = imx290_write_current_format(imx290, &imx290->current_format); + /* Apply the register values related to current frame format */ + ret = imx290_write_current_format(imx290); if (ret < 0) { dev_err(imx290->dev, "Could not set frame format\n"); return ret; @@ -821,12 +847,6 @@ static int imx290_probe(struct i2c_client *client) goto free_err; } - if (imx290->ep.link_frequencies[0] != IMX290_DEFAULT_LINK_FREQ) { - dev_err(dev, "Unsupported link frequency\n"); - ret = -EINVAL; - goto free_err; - } - /* Only CSI2 is supported for now */ if (imx290->ep.bus_type != V4L2_MBUS_CSI2_DPHY) { dev_err(dev, "Unsupported bus type, should be CSI2\n"); @@ -879,23 +899,38 @@ static int imx290_probe(struct i2c_client *client) mutex_init(&imx290->lock); + /* + * Initialize the frame format. In particular, imx290->current_mode + * and imx290->bpp are set to defaults: imx290_calc_pixel_rate() call + * below relies on these fields. + */ + imx290_entity_init_cfg(&imx290->sd, NULL); + v4l2_ctrl_handler_init(&imx290->ctrls, 3); v4l2_ctrl_new_std(&imx290->ctrls, &imx290_ctrl_ops, V4L2_CID_GAIN, 0, 72, 1, 0); - imx290->link_freq = - v4l2_ctrl_new_int_menu(&imx290->ctrls, - &imx290_ctrl_ops, - V4L2_CID_LINK_FREQ, - ARRAY_SIZE(imx290_link_freq) - 1, - 0, imx290_link_freq); + if (imx290->nlanes == 4) + imx290->link_freq = + v4l2_ctrl_new_int_menu(&imx290->ctrls, + &imx290_ctrl_ops, + V4L2_CID_LINK_FREQ, + ARRAY_SIZE(imx290_link_freq_4lanes) - 1, + 0, imx290_link_freq_4lanes); + else + imx290->link_freq = + v4l2_ctrl_new_int_menu(&imx290->ctrls, + &imx290_ctrl_ops, + V4L2_CID_LINK_FREQ, + ARRAY_SIZE(imx290_link_freq_2lanes) - 1, + 0, imx290_link_freq_2lanes); if (imx290->link_freq) imx290->link_freq->flags |= V4L2_CTRL_FLAG_READ_ONLY; imx290->pixel_rate = v4l2_ctrl_new_std(&imx290->ctrls, &imx290_ctrl_ops, V4L2_CID_PIXEL_RATE, 1, INT_MAX, 1, - imx290_modes[0].pixel_rate); + imx290_calc_pixel_rate(imx290)); imx290->sd.ctrl_handler = &imx290->ctrls; @@ -919,9 +954,6 @@ static int imx290_probe(struct i2c_client *client) goto free_ctrl; } - /* Initialize the frame format (this also sets imx290->current_mode) */ - imx290_entity_init_cfg(&imx290->sd, NULL); - ret = v4l2_async_register_subdev(&imx290->sd); if (ret < 0) { dev_err(dev, "Could not register v4l2 device\n"); -- 2.17.1