From patchwork Thu Dec 19 18:22:18 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Manivannan Sadhasivam X-Patchwork-Id: 182148 Delivered-To: patch@linaro.org Received: by 2002:a92:d0a:0:0:0:0:0 with SMTP id 10csp835585iln; Thu, 19 Dec 2019 10:22:59 -0800 (PST) X-Google-Smtp-Source: APXvYqxpIwu4rJMq6LwDDnQDPnu5Cy4rxVPkB7l8IkUqK1wquz+SjoQBm/MgY7bEZf8bfE9zpds3 X-Received: by 2002:a54:488d:: with SMTP id r13mr2733863oic.115.1576779779218; Thu, 19 Dec 2019 10:22:59 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1576779779; cv=none; d=google.com; s=arc-20160816; b=prhch7VPP3VtM0/wMy/hLtlJxaNZjkFSn0M4po73fqOM9iShxeSejN7WUO+KQwKAE/ OdTLmSltIc4lRHE8IwuJCxrxEisb2GqtHwCjhaQRiVJN6HmazoCjD3M1BJ9xSoVW+AXY hUnKfut3ziXrMy/ghSA87+TORnY4T7LJRDAzs8XITrFtgnAyDnIanp44P/xBNZ7K2O2n ZeMiGLPvQt3JVZKkeLuPNbdv227O1TaZ4w1N8TnLup+rGehmYpaZDlATwQuWDG3CqGqL HkIfPTq0H5/TxC+oUEQG7+5Y3yAaRNvcBWlwWqPRHj53SluLZqf9UgK8SbxFnmrl6/fd w+9A== 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=KMxyNKrwFiypU+Za0PvdEdroSKdNRbPMZobhgZUY7nE=; b=n4OvpFh++N8JRROpcurKNdVtTuyi/tUSCWrod1BKnvTQg41z4NmreImtb+cSklp5SL sAa+lwhw0nJHvNs54ZGfp3IaKMoHs87Sa/r8EZYoOway5uLO5aIVTEq3JGmEubf7UH4Y pcU5AkNI2GFbIIr6gMCLwY03TwHC6MlMPn/1c/0GZsGx5/x77mIis4EJCielF+tAIV2P oWjDU0mmQ3yGRFjIKjLfkEcl2Tu6CIiPHbjziCbc/yetrU/xTDJSGyW/v6TXhoFcdFT7 JL0aLVdMZoFokgDHek6em01JgHPj6M3MEUQU5pvGtr4v2yKVTYOE3zVtK8aqgTMpf51U 5JJA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=iyymSRkQ; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 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. [209.132.180.67]) by mx.google.com with ESMTP id e25si638225oie.146.2019.12.19.10.22.58; Thu, 19 Dec 2019 10:22:59 -0800 (PST) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=iyymSRkQ; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 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 S1727063AbfLSSW5 (ORCPT + 27 others); Thu, 19 Dec 2019 13:22:57 -0500 Received: from mail-pf1-f194.google.com ([209.85.210.194]:38269 "EHLO mail-pf1-f194.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726998AbfLSSW4 (ORCPT ); Thu, 19 Dec 2019 13:22:56 -0500 Received: by mail-pf1-f194.google.com with SMTP id x185so3728970pfc.5 for ; Thu, 19 Dec 2019 10:22: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=KMxyNKrwFiypU+Za0PvdEdroSKdNRbPMZobhgZUY7nE=; b=iyymSRkQTNB324vLkBnS7VSoRJkH72UREfXNbeNFSewtHmL0P6PHfBuqx+np20dLqm pJ0UJ/u1YkgyAvj4pYJv/wqfSaOgFM+Qim1/y54eNZ5aso+wYDF5/Nz0PpuuesrXE7/X TTkPdjkg9GSOr/mm75SMnBp0I2RQ+6Xx8l40WBW1aAZMibF19pO8lgqE+TV2gQ1RKP6L FA/F1iSK1BoFbeDtd+/nAVjUuK2CvoU9QsVitgon4SPe7Z+PoCUOz0aAFVLOStTz5g+j 11Ha1A2n2+j/45Zxe76ZG5GIhQFe2FoZvdJZjOnFbMexUGqXshCUAg0v2hzJVXVGZxVC 4cAg== 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=KMxyNKrwFiypU+Za0PvdEdroSKdNRbPMZobhgZUY7nE=; b=oHY0kHi+WBBCwRqn0ma7By3Yn4vkfDEBv5Yzn/nNbKLwJRHy/CWioYhMe/rT/JqU++ E11KtaxUeFIcfKTsaCVP6RTnORlDJex1hyJUvQyZt6gego+EdOClwt1Maqv8XaCGTBGm XS2pL+7vesTBRDpRUmFN4U8ztRQPcxD+OkHJuzMQ9+aU9pXRQiJeLd63dnTe6TxH8tg2 MQqd+AMjmOMDZU1/pIvsZL+h9b5uQVf66qr7+VaNtuevJGyMvb/g6WMCjeQ15xIWHx7n TuMAdtoTSjf/KJylpSmRzJXeA+b0fnj952d/VKxulwnFwkNXCQUth5t7+o4BrRR6AviZ J2PA== X-Gm-Message-State: APjAAAVPZBO7wKw84j+T0RngLnOu0xfOcS9OiUEJ9Yd1Xzx0FMLytX62 nvINiSQwK5TBHb1ZNfucwC1t X-Received: by 2002:a63:f551:: with SMTP id e17mr10230035pgk.162.1576779775598; Thu, 19 Dec 2019 10:22:55 -0800 (PST) Received: from localhost.localdomain ([2409:4072:6010:65a5:a416:e9bd:178a:9286]) by smtp.gmail.com with ESMTPSA id i3sm9085735pfg.94.2019.12.19.10.22.51 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 19 Dec 2019 10:22:55 -0800 (PST) From: Manivannan Sadhasivam To: mchehab@kernel.org, sakari.ailus@iki.fi 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, Manivannan Sadhasivam Subject: [PATCH v2 2/6] media: i2c: imx290: Add support for test pattern generation Date: Thu, 19 Dec 2019 23:52:18 +0530 Message-Id: <20191219182222.18961-3-manivannan.sadhasivam@linaro.org> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20191219182222.18961-1-manivannan.sadhasivam@linaro.org> References: <20191219182222.18961-1-manivannan.sadhasivam@linaro.org> Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Add support for generating following test patterns by IMX290: * Sequence Pattern 1 * Horizontal Color-bar Chart * Vertical Color-bar Chart * Sequence Pattern 2 * Gradation Pattern 1 * Gradation Pattern 2 * 000/555h Toggle Pattern Signed-off-by: Manivannan Sadhasivam --- drivers/media/i2c/imx290.c | 41 +++++++++++++++++++++++++++++++++++++- 1 file changed, 40 insertions(+), 1 deletion(-) -- 2.17.1 diff --git a/drivers/media/i2c/imx290.c b/drivers/media/i2c/imx290.c index 532ad488b801..96eea0aafd3e 100644 --- a/drivers/media/i2c/imx290.c +++ b/drivers/media/i2c/imx290.c @@ -26,12 +26,19 @@ #define IMX290_REGHOLD 0x3001 #define IMX290_XMSTA 0x3002 #define IMX290_FR_FDG_SEL 0x3009 +#define IMX290_BLKLEVEL_LOW 0x300a +#define IMX290_BLKLEVEL_HIGH 0x300b #define IMX290_GAIN 0x3014 #define IMX290_HMAX_LOW 0x301c #define IMX290_HMAX_HIGH 0x301d +#define IMX290_PGCTRL 0x308c #define IMX290_PHY_LANE_NUM 0x3407 #define IMX290_CSI_LANE_MODE 0x3443 +#define IMX290_PGCTRL_REGEN BIT(0) +#define IMX290_PGCTRL_THRU BIT(1) +#define IMX290_PGCTRL_MODE(n) ((n) << 4) + /* HMAX fields */ #define IMX290_HMAX_2_1920 0x1130 #define IMX290_HMAX_4_1920 0x0898 @@ -99,6 +106,17 @@ static const struct regmap_config imx290_regmap_config = { .cache_type = REGCACHE_RBTREE, }; +static const char * const imx290_test_pattern_menu[] = { + "Disabled", + "Sequence Pattern 1", + "Horizontal Color-bar Chart", + "Vertical Color-bar Chart", + "Sequence Pattern 2", + "Gradation Pattern 1", + "Gradation Pattern 2", + "000/555h Toggle Pattern", +}; + static const struct imx290_regval imx290_global_init_settings[] = { { 0x3007, 0x00 }, { 0x3018, 0x65 }, @@ -394,6 +412,22 @@ static int imx290_set_ctrl(struct v4l2_ctrl *ctrl) case V4L2_CID_GAIN: ret = imx290_set_gain(imx290, ctrl->val); break; + case V4L2_CID_TEST_PATTERN: + if (ctrl->val) { + imx290_write_reg(imx290, IMX290_BLKLEVEL_LOW, 0x00); + imx290_write_reg(imx290, IMX290_BLKLEVEL_HIGH, 0x00); + msleep(10); + imx290_write_reg(imx290, IMX290_PGCTRL, + (u8)(IMX290_PGCTRL_REGEN | + IMX290_PGCTRL_THRU | + IMX290_PGCTRL_MODE(ctrl->val))); + } else { + imx290_write_reg(imx290, IMX290_PGCTRL, 0x00); + msleep(10); + imx290_write_reg(imx290, IMX290_BLKLEVEL_LOW, 0x3c); + imx290_write_reg(imx290, IMX290_BLKLEVEL_HIGH, 0x00); + } + break; default: ret = -EINVAL; break; @@ -881,7 +915,7 @@ static int imx290_probe(struct i2c_client *client) mutex_init(&imx290->lock); - v4l2_ctrl_handler_init(&imx290->ctrls, 3); + v4l2_ctrl_handler_init(&imx290->ctrls, 4); v4l2_ctrl_new_std(&imx290->ctrls, &imx290_ctrl_ops, V4L2_CID_GAIN, 0, 72, 1, 0); @@ -899,6 +933,11 @@ static int imx290_probe(struct i2c_client *client) INT_MAX, 1, imx290_modes[0].pixel_rate); + v4l2_ctrl_new_std_menu_items(&imx290->ctrls, &imx290_ctrl_ops, + V4L2_CID_TEST_PATTERN, + ARRAY_SIZE(imx290_test_pattern_menu) - 1, + 0, 0, imx290_test_pattern_menu); + imx290->sd.ctrl_handler = &imx290->ctrls; if (imx290->ctrls.error) { From patchwork Thu Dec 19 18:22:20 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Manivannan Sadhasivam X-Patchwork-Id: 182150 Delivered-To: patch@linaro.org Received: by 2002:a92:d0a:0:0:0:0:0 with SMTP id 10csp835786iln; Thu, 19 Dec 2019 10:23:08 -0800 (PST) X-Google-Smtp-Source: APXvYqxIR+XAJLGzTpuOv5WaUJjci6DSN5UsBiJdYHIS+jHcHD8gZBAtmvqRLjkFTwJQeEy32N8f X-Received: by 2002:a05:6830:2098:: with SMTP id y24mr10435035otq.312.1576779788611; Thu, 19 Dec 2019 10:23:08 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1576779788; cv=none; d=google.com; s=arc-20160816; b=nALXIQoTM1LnFHPBNDto/TKbKSc0KL1lpRaLDfya2dnMW0ZqGTeMbtWYFHan94QChg V7gjjwiN+GFNhPQ0ZCbGVjDyndNkY8ZeGtaogO/MryBgZ73Jdaav9bkIcdpZvnIWUh27 P+kL3/8nCTOUtnguON7qfJnH8Fs6H7toZ0xhOTkSEkDR8gfoSX69WnFOI6H+GClSm+0B urq4VPp/zHGrA4vCt3ZmwYdlEx20UOW2B8FDsVPIG1lYqJzDpoXRCMLjC0s+pJAbKmya 5iIyCDHBCFVIg+J4/vspP/CdMV5vw0fmjqnteRs9zsAu4gr+vSKMBgLLykErVixkb5EI 5lPw== 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=2o+AG3RvUH+GxTzi1IbYJSvnHQRcuO5FLTvuUuElWHc=; b=gAZUcT/xGfFbz2Sv7kQHmwEkl20hY5saaj/z7EuE3qIVT4kB5IeEiRIfJEHolShIXp uR/32UqJSyz0ASfKAXMfMzBWiYjc5F1ab1pQlW2Wy1xD/z4Qfkw/z7q4grItILKUrwyY eebio5qW4Qo8WqkrEKhcxb8zsdDge3Uy1dBCtcEYxljZTCrzjVaFTki4z5eXL4/jfm7M lnjau5mv2qRSfPGxzIUGKmF1UEbDuLiBXt4vmJxhcAGHq4ApZmH+XP/EDQDF4caPKE6X Z78ngTk9f6oXA59Gz+H36y407RJfeK3FA4kVnNRvO0a9MsvsJPY0oUmuyM/2QeeQ1FFm B3kw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=gQ8G1RAe; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 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. [209.132.180.67]) by mx.google.com with ESMTP id e25si638225oie.146.2019.12.19.10.23.08; Thu, 19 Dec 2019 10:23:08 -0800 (PST) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=gQ8G1RAe; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 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 S1727151AbfLSSXH (ORCPT + 27 others); Thu, 19 Dec 2019 13:23:07 -0500 Received: from mail-pl1-f195.google.com ([209.85.214.195]:45025 "EHLO mail-pl1-f195.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727071AbfLSSXG (ORCPT ); Thu, 19 Dec 2019 13:23:06 -0500 Received: by mail-pl1-f195.google.com with SMTP id az3so2915718plb.11 for ; Thu, 19 Dec 2019 10:23:05 -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=2o+AG3RvUH+GxTzi1IbYJSvnHQRcuO5FLTvuUuElWHc=; b=gQ8G1RAeBnSBMUz9vxx63vb4M+B8ZgAkiKSSzFgs7w5UGWiXl6ndClyr3rfdt0ukjV pBwFrlIdO6Lk3XgBiB6b3zA6FNde+Nwrkr2b3+Wxe3nyxUFGxFN7vb0qaA65jtXetc5A p7Dpr8fva+rX4v9D9hpA1+FNcW+sgJk2hFWLQI0Q5oblXjF3DkXyJLYTFOu4VTLS1TQi U0W327PywietOTD3gTTtx8SKJLPVpea8lYTjEBHvs1D7poJhOFEHjkUixb4pz/9MVOv0 UVNTPvJNXkh/jXwXv7JuRsiIUh1cREVBP0c4C6GEjefuJqSC2pOQNG6GfhK6OEy4dAAu sjYw== 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=2o+AG3RvUH+GxTzi1IbYJSvnHQRcuO5FLTvuUuElWHc=; b=Bsxga+YSkDk6ZrFdlZ3SkOUaWALim9fFCvN0UyHDE9CKFGNHc42rS6pjpvdQC7BuiB do5kNXyduaoUwbDV9nEfla1HLk4wZCayeyA3F0/zC3DZCmAK9q5Z8KLXF92XHq7ktxqc 5B5SkGjL0z8SmlNPholoGnlJ2ODLlvclVMBhFnGYfRe0H7qJZ5mjykKwvABh98m4L6jb TuRvPtsEpg7N1CPs1jcyKgGqVpkaGZElDV1Tegn/dR6vRSglTbosdDmFD9t5+qMwqV+G s3jm+LIVwzeR0yDAIitQXiNLjp2MZzxAMFY5WDnYmrIQXcFqbrsjUj08qitwDtjzIpVG deWQ== X-Gm-Message-State: APjAAAVAu+j3jbgSJazO/0EHeCyjlzHegH1xbZzVqA9mPYr1XVcu/CuM 9j+Es3bp14LQgW3thQWhqiTt X-Received: by 2002:a17:902:421:: with SMTP id 30mr10707013ple.324.1576779785449; Thu, 19 Dec 2019 10:23:05 -0800 (PST) Received: from localhost.localdomain ([2409:4072:6010:65a5:a416:e9bd:178a:9286]) by smtp.gmail.com with ESMTPSA id i3sm9085735pfg.94.2019.12.19.10.23.01 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 19 Dec 2019 10:23:04 -0800 (PST) From: Manivannan Sadhasivam To: mchehab@kernel.org, sakari.ailus@iki.fi 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, Manivannan Sadhasivam Subject: [PATCH v2 4/6] media: i2c: imx290: Add support to enumerate all frame sizes Date: Thu, 19 Dec 2019 23:52:20 +0530 Message-Id: <20191219182222.18961-5-manivannan.sadhasivam@linaro.org> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20191219182222.18961-1-manivannan.sadhasivam@linaro.org> References: <20191219182222.18961-1-manivannan.sadhasivam@linaro.org> Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Add support to enumerate all frame sizes supported by IMX290. This is required for using with userspace tools such as libcamera. Signed-off-by: Manivannan Sadhasivam --- drivers/media/i2c/imx290.c | 20 ++++++++++++++++++++ 1 file changed, 20 insertions(+) -- 2.17.1 diff --git a/drivers/media/i2c/imx290.c b/drivers/media/i2c/imx290.c index b6eeca56d3c9..a1974340e6fa 100644 --- a/drivers/media/i2c/imx290.c +++ b/drivers/media/i2c/imx290.c @@ -468,6 +468,25 @@ static int imx290_enum_mbus_code(struct v4l2_subdev *sd, return 0; } +static int imx290_enum_frame_size(struct v4l2_subdev *subdev, + struct v4l2_subdev_pad_config *cfg, + struct v4l2_subdev_frame_size_enum *fse) +{ + if ((fse->code != imx290_formats[0].code) && + (fse->code != imx290_formats[1].code)) + return -EINVAL; + + if (fse->index >= ARRAY_SIZE(imx290_modes)) + return -EINVAL; + + fse->min_width = imx290_modes[fse->index].width; + fse->max_width = imx290_modes[fse->index].width; + fse->min_height = imx290_modes[fse->index].height; + fse->max_height = imx290_modes[fse->index].height; + + return 0; +} + static int imx290_get_fmt(struct v4l2_subdev *sd, struct v4l2_subdev_pad_config *cfg, struct v4l2_subdev_format *fmt) @@ -823,6 +842,7 @@ static const struct v4l2_subdev_video_ops imx290_video_ops = { static const struct v4l2_subdev_pad_ops imx290_pad_ops = { .init_cfg = imx290_entity_init_cfg, .enum_mbus_code = imx290_enum_mbus_code, + .enum_frame_size = imx290_enum_frame_size, .get_fmt = imx290_get_fmt, .set_fmt = imx290_set_fmt, }; From patchwork Thu Dec 19 18:22:21 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Manivannan Sadhasivam X-Patchwork-Id: 182151 Delivered-To: patch@linaro.org Received: by 2002:a92:d0a:0:0:0:0:0 with SMTP id 10csp835984iln; Thu, 19 Dec 2019 10:23:16 -0800 (PST) X-Google-Smtp-Source: APXvYqwkUunmwPUprbeXB8MNZQzNaU6Rdo4LRSLlHUkl0ePEWaDayUSMIQAcK/gOIaUppQv28xM/ X-Received: by 2002:a9d:6396:: with SMTP id w22mr10318142otk.364.1576779796023; Thu, 19 Dec 2019 10:23:16 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1576779795; cv=none; d=google.com; s=arc-20160816; b=KxQfF3C2jfWiUWVfDL/bDI4xqEIIojFEZXbHdMJSs28X6oQeEy3NRlMk26EZHGTx1p wUWkE/vKRrFQLNTqZyCh70YJFr74Iz+xtehzPaOh1aDtaQ8Y4iqdfWHSeUloaMQ+bcTh nFbGxJGl7lwgZyhWhI6t4pbEEbd0DNM56VTeYxEQyAeT1ioL7BUcka9BtM0S9N/a6rjk yaP1H22uoXCY+m/mzEiohKD8vdLGe9ckxEQCM/WQFOiTTOW/HSZHfOX7b6T0Ptxkg4wC PsBmUdzKS92T+7hNd5MMZv1CS85/wp1+rnDbJZGrTLlk5r5P5Dz4owLItEaw+dVuKxRK DU4Q== 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=aaDVa/wefW6dA8diuFKX+4suKAqDWuzG8PZTPRvOWpY=; b=c0F4VVdFWHHWq4ySU21QZhjwJg/OQX1Z5GX1KemaMZbWEOywtC2hiFz3jS2IVWNDAY G0AL4JABC9+Atg83eSHoH/9XbfrX3z85UK24Mjl87TeDmTfL81T075AyePSC/7oHt7R/ NhyuGHZevabI5Re5qYRF+DHj/U+dVtnqMZex8zCudI3M/aqo4rE5WZhiCLc9hEXMBa2L NBSKO9Op2AUb4ZUC7DPGHxQKyrwUbJOuTxErz9z8Uzj0e2JEDE/UEfNK0kwhrMXdpIki DK+jYoVZeiWP5To94uL+ae2E2fnzVb2ykvsTmC2PjbTYn1aSt+QwicbEhCCqQHa2KU3/ azVA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=ktngylax; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 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. [209.132.180.67]) by mx.google.com with ESMTP id w18si3758354otl.54.2019.12.19.10.23.14; Thu, 19 Dec 2019 10:23:15 -0800 (PST) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=ktngylax; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 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 S1727176AbfLSSXN (ORCPT + 27 others); Thu, 19 Dec 2019 13:23:13 -0500 Received: from mail-pg1-f195.google.com ([209.85.215.195]:43267 "EHLO mail-pg1-f195.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727152AbfLSSXM (ORCPT ); Thu, 19 Dec 2019 13:23:12 -0500 Received: by mail-pg1-f195.google.com with SMTP id k197so3542413pga.10 for ; Thu, 19 Dec 2019 10:23:12 -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=aaDVa/wefW6dA8diuFKX+4suKAqDWuzG8PZTPRvOWpY=; b=ktngylaxtKSioChZycCEfiuuOBC8AjMEYRKHWc/M721x2N3gAquly/ClC9d8QYVaQN 9La3xsIMwqbfMPVqbJOXb7kcVAI70ZuSqaxozMic7t/3SxI6KC971hsIG+mZAH3nEu+v /8Nuh0o499INctRWB4mngQ1pfdgNdtBUczImb69bdlr2EFSAZTPWwVWEeYRjKa9vWAWX WVQanIaFSPtKgFcjYNzGwbhNw84vxtApXwN3582KmNAvRLs1BnPag03PnyVkPGFGi+C9 lOjZIzckv6WWQAPIFrh5n1Lxb7wedKgw3TsdZp7SyjIKi23mSBnvIpNkksdLtzmPumco efAQ== 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=aaDVa/wefW6dA8diuFKX+4suKAqDWuzG8PZTPRvOWpY=; b=pO6mzUHT5r8simT5Hc3PMCkNoNnN8dhhtfoxbJoM1fbfmpKKreTIabA7kq6GNja6zM UjIGu6hSVGaFlu55K8t/EvU+FiCwSlNR8BU2674sP+Yx1d9epeXurAW4JvHEzJkKmwXv PRV3Lj90RUHkw6oOobGpMQaeXzuZanAutd7u6TZO2Laq/DvLJzvSipR9svNI+QqKCTA+ dfSoS0zr+Sj8xwXvrtDFqzYiogQmqPW8AFWxCXvJAsh4YBjlqYI6YoXorrw0duSbahKZ dxf81SvEZhxQu6DVEOvcavopxkGQHt8/oNRyeEIC+DLx9kSigv07mZ63ddKLBGe7nV81 fMdg== X-Gm-Message-State: APjAAAVrSaMcpq2VZFSIAEKsiZ8D58f6g7lEQdkM4ydoFuAVpUpCJJN6 uSPVkh/MaY7KpwPaBSCDVxya X-Received: by 2002:a62:a21e:: with SMTP id m30mr3583773pff.56.1576779791625; Thu, 19 Dec 2019 10:23:11 -0800 (PST) Received: from localhost.localdomain ([2409:4072:6010:65a5:a416:e9bd:178a:9286]) by smtp.gmail.com with ESMTPSA id i3sm9085735pfg.94.2019.12.19.10.23.05 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 19 Dec 2019 10:23:11 -0800 (PST) From: Manivannan Sadhasivam To: mchehab@kernel.org, sakari.ailus@iki.fi 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, Manivannan Sadhasivam Subject: [PATCH v2 5/6] media: i2c: imx290: Add configurable link frequency and pixel rate Date: Thu, 19 Dec 2019 23:52:21 +0530 Message-Id: <20191219182222.18961-6-manivannan.sadhasivam@linaro.org> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20191219182222.18961-1-manivannan.sadhasivam@linaro.org> References: <20191219182222.18961-1-manivannan.sadhasivam@linaro.org> Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org 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 --- drivers/media/i2c/imx290.c | 155 +++++++++++++++++++++---------------- 1 file changed, 89 insertions(+), 66 deletions(-) -- 2.17.1 diff --git a/drivers/media/i2c/imx290.c b/drivers/media/i2c/imx290.c index a1974340e6fa..52f1e470b507 100644 --- a/drivers/media/i2c/imx290.c +++ b/drivers/media/i2c/imx290.c @@ -45,8 +45,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", @@ -63,8 +61,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; @@ -281,7 +277,10 @@ static const struct imx290_regval imx290_12bit_settings[] = { /* supported link frequencies */ static const s64 imx290_link_freq[] = { - IMX290_DEFAULT_LINK_FREQ, + 891000000, /* 1920x1080 - 2 lane */ + 445500000, /* 1920x1080 - 4 lane */ + 594000000, /* 1280x720 - 2 lane */ + 297000000, /* 1280x720 - 4 lane */ }; /* Mode configs */ @@ -291,16 +290,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, }, }; @@ -509,6 +504,73 @@ static int imx290_get_fmt(struct v4l2_subdev *sd, return 0; } +static s64 imx290_get_link_freq_index(struct imx290 *imx290) +{ + const struct imx290_mode *cur_mode = imx290->current_mode; + u8 index; + + if (cur_mode->width == 1920) + index = imx290->nlanes / 4; + else + index = (imx290->nlanes / 4) + 2; + + return index; +} + +static s64 imx290_get_link_freq(struct imx290 *imx290) +{ + u8 index = imx290_get_link_freq_index(imx290); + + return imx290_link_freq[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 / imx290->bpp); +} + +static int imx290_write_current_format(struct imx290 *imx290, + struct v4l2_mbus_framefmt *format) +{ + int ret; + + switch (format->code) { + case MEDIA_BUS_FMT_SRGGB10_1X10: + ret = imx290_set_register_array(imx290, imx290_10bit_settings, + ARRAY_SIZE( + imx290_10bit_settings)); + if (ret < 0) { + dev_err(imx290->dev, "Could not set format registers\n"); + return ret; + } + + imx290->bpp = 10; + + break; + case MEDIA_BUS_FMT_SRGGB12_1X12: + ret = imx290_set_register_array(imx290, imx290_12bit_settings, + ARRAY_SIZE( + imx290_12bit_settings)); + if (ret < 0) { + dev_err(imx290->dev, "Could not set format registers\n"); + return ret; + } + + imx290->bpp = 12; + + break; + default: + dev_err(imx290->dev, "Unknown pixel format\n"); + return -EINVAL; + } + + return 0; +} + static int imx290_set_fmt(struct v4l2_subdev *sd, struct v4l2_subdev_pad_config *cfg, struct v4l2_subdev_format *fmt) @@ -517,6 +579,7 @@ static int imx290_set_fmt(struct v4l2_subdev *sd, const struct imx290_mode *mode; struct v4l2_mbus_framefmt *format; unsigned int i; + int ret = 0; mutex_lock(&imx290->lock); @@ -542,17 +605,27 @@ 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; + + /* Set current frame format */ + ret = imx290_write_current_format(imx290, &fmt->format); + if (ret < 0) { + dev_err(imx290->dev, "Could not set frame format\n"); + goto err_out; + } + + __v4l2_ctrl_s_ctrl(imx290->link_freq, + imx290_get_link_freq_index(imx290)); + __v4l2_ctrl_s_ctrl_int64(imx290->pixel_rate, + imx290_calc_pixel_rate(imx290)); } *format = fmt->format; +err_out: mutex_unlock(&imx290->lock); - return 0; + return ret; } static int imx290_entity_init_cfg(struct v4l2_subdev *subdev, @@ -569,44 +642,6 @@ 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) -{ - int ret; - - switch (format->code) { - case MEDIA_BUS_FMT_SRGGB10_1X10: - ret = imx290_set_register_array(imx290, imx290_10bit_settings, - ARRAY_SIZE( - imx290_10bit_settings)); - if (ret < 0) { - dev_err(imx290->dev, "Could not set format registers\n"); - return ret; - } - - imx290->bpp = 10; - - break; - case MEDIA_BUS_FMT_SRGGB12_1X12: - ret = imx290_set_register_array(imx290, imx290_12bit_settings, - ARRAY_SIZE( - imx290_12bit_settings)); - if (ret < 0) { - dev_err(imx290->dev, "Could not set format registers\n"); - return ret; - } - - imx290->bpp = 12; - - break; - default: - dev_err(imx290->dev, "Unknown pixel format\n"); - return -EINVAL; - } - - return 0; -} - static int imx290_set_hmax(struct imx290 *imx290, u32 val) { int ret; @@ -640,13 +675,6 @@ static int imx290_start_streaming(struct imx290 *imx290) return ret; } - /* Set current frame format */ - ret = imx290_write_current_format(imx290, &imx290->current_format); - if (ret < 0) { - dev_err(imx290->dev, "Could not set frame format\n"); - return ret; - } - /* Apply default values of current mode */ ret = imx290_set_register_array(imx290, imx290->current_mode->data, imx290->current_mode->data_size); @@ -904,12 +932,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"); @@ -976,14 +998,15 @@ static int imx290_probe(struct i2c_client *client) &imx290_ctrl_ops, V4L2_CID_LINK_FREQ, ARRAY_SIZE(imx290_link_freq) - 1, - 0, imx290_link_freq); + (imx290->nlanes / 4), + imx290_link_freq); 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)); v4l2_ctrl_new_std_menu_items(&imx290->ctrls, &imx290_ctrl_ops, V4L2_CID_TEST_PATTERN,