From patchwork Thu Dec 19 18:22:17 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Manivannan Sadhasivam X-Patchwork-Id: 11304227 Return-Path: Received: from mail.kernel.org (pdx-korg-mail-1.web.codeaurora.org [172.30.200.123]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id BCD9D14F6 for ; Thu, 19 Dec 2019 18:22:55 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id 90FD424679 for ; Thu, 19 Dec 2019 18:22:55 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=linaro.org header.i=@linaro.org header.b="LkFxJRzp" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726963AbfLSSWw (ORCPT ); Thu, 19 Dec 2019 13:22:52 -0500 Received: from mail-pl1-f195.google.com ([209.85.214.195]:40153 "EHLO mail-pl1-f195.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726840AbfLSSWw (ORCPT ); Thu, 19 Dec 2019 13:22:52 -0500 Received: by mail-pl1-f195.google.com with SMTP id s21so184771plr.7 for ; Thu, 19 Dec 2019 10:22:51 -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=zwGoLngI+NuehCxqLPOV9F/7m9EMr7gKWrCKtqW4Jcw=; b=LkFxJRzpxgrqWkDu9NIq14PtAkP7KD2Ey8PxhUOdqF3q1prp7GYNBZmv8MSO/qEczZ 2u9Kg15va+H8l5/rAO/6/yc9XvNmBHw23WDrKmXwASTEOPCYS9BJXNNc49UoVjdF/f/9 WDmz+ZLfwMnyUgxinx7JSl2NztqCZoYDQxIdElK2CJxoQd5ES0NyFZttBLxQdxKgVEEn iBbngNy+1we0hSM0CN0Bmss0lX3gKOtDzIiynlVWFUAS2o0RtcJWB0MA5utzG8J5F80g nQHh6BelnPRRBNkJE7Bk0EduSn/Lfn3bWiLMUxXvH/XrkIB/KZaFSkKB62LX00h1pjjf pdLg== 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=zwGoLngI+NuehCxqLPOV9F/7m9EMr7gKWrCKtqW4Jcw=; b=MrSQuNrvQC20doinFhMhnaUklVlJpnMV3/BbeytMtSyMz2sw3YS+ZXh9sfrljn11X1 8vdwmx+1PQXt8YnICwgjOuco7si+K96v6QdMTaHCtFj54Vsa6N4Xhla5buYydi2CckZ5 jyUdnGyTO+WBxLBdUvGeC6PyJx3IorbEckRulcRtBp7Obh8n7u45D50Izao8GKSmZYhm 7DdgTV/3G+MQzSK36LQdk3fzFnkHVmIU/U6RtFFRGONsrJBEv8pRdDNoMRblD+zhRoLD THQ2jn4qXA0Y5KUnnJibd/Y0sas7P3V3ECzitWQ3zzE6FloF7eVAEHSD+5vsoOz+fcuV dq/Q== X-Gm-Message-State: APjAAAX/RdTyIc1DN+jIojUesobmBbF9gl7s1Y6lShfqW+0Ct6/noCoo fb3rQkzVxqaAqWY3nJNV9AWp X-Google-Smtp-Source: APXvYqyb7xWtO84LNcduE9P+8gbPVmoywmz8cPKNB4mh63fy6fYYi3B2jHmXFEVxxjscDbCAGjClTQ== X-Received: by 2002:a17:902:409:: with SMTP id 9mr10523602ple.245.1576779770781; Thu, 19 Dec 2019 10:22:50 -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.46 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 19 Dec 2019 10:22:50 -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 1/6] media: i2c: imx290: Add support for 2 data lanes Date: Thu, 19 Dec 2019 23:52:17 +0530 Message-Id: <20191219182222.18961-2-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-media-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-media@vger.kernel.org The IMX290 sensor can output frames with 2/4 CSI2 data lanes. This commit adds support for 2 lane mode in addition to the 4 lane and also configuring the data lane settings in the driver based on system configuration. Signed-off-by: Manivannan Sadhasivam --- drivers/media/i2c/imx290.c | 133 ++++++++++++++++++++++++++++++++++--- 1 file changed, 124 insertions(+), 9 deletions(-) diff --git a/drivers/media/i2c/imx290.c b/drivers/media/i2c/imx290.c index f7678e5a5d87..532ad488b801 100644 --- a/drivers/media/i2c/imx290.c +++ b/drivers/media/i2c/imx290.c @@ -25,7 +25,18 @@ #define IMX290_STANDBY 0x3000 #define IMX290_REGHOLD 0x3001 #define IMX290_XMSTA 0x3002 +#define IMX290_FR_FDG_SEL 0x3009 #define IMX290_GAIN 0x3014 +#define IMX290_HMAX_LOW 0x301c +#define IMX290_HMAX_HIGH 0x301d +#define IMX290_PHY_LANE_NUM 0x3407 +#define IMX290_CSI_LANE_MODE 0x3443 + +/* HMAX fields */ +#define IMX290_HMAX_2_1920 0x1130 +#define IMX290_HMAX_4_1920 0x0898 +#define IMX290_HMAX_2_720 0x19C8 +#define IMX290_HMAX_4_720 0x0CE4 #define IMX290_DEFAULT_LINK_FREQ 445500000 @@ -56,6 +67,7 @@ struct imx290 { struct device *dev; struct clk *xclk; struct regmap *regmap; + u8 nlanes; struct v4l2_subdev sd; struct v4l2_fwnode_endpoint ep; @@ -89,14 +101,11 @@ static const struct regmap_config imx290_regmap_config = { static const struct imx290_regval imx290_global_init_settings[] = { { 0x3007, 0x00 }, - { 0x3009, 0x00 }, { 0x3018, 0x65 }, { 0x3019, 0x04 }, { 0x301a, 0x00 }, - { 0x3443, 0x03 }, { 0x3444, 0x20 }, { 0x3445, 0x25 }, - { 0x3407, 0x03 }, { 0x303a, 0x0c }, { 0x3040, 0x00 }, { 0x3041, 0x00 }, @@ -169,7 +178,6 @@ static const struct imx290_regval imx290_1080p_settings[] = { { 0x3164, 0x1a }, { 0x3480, 0x49 }, /* data rate settings */ - { 0x3009, 0x01 }, { 0x3405, 0x10 }, { 0x3446, 0x57 }, { 0x3447, 0x00 }, @@ -187,8 +195,6 @@ static const struct imx290_regval imx290_1080p_settings[] = { { 0x3453, 0x00 }, { 0x3454, 0x17 }, { 0x3455, 0x00 }, - { 0x301c, 0x98 }, - { 0x301d, 0x08 }, }; static const struct imx290_regval imx290_720p_settings[] = { @@ -210,7 +216,6 @@ static const struct imx290_regval imx290_720p_settings[] = { { 0x3164, 0x1a }, { 0x3480, 0x49 }, /* data rate settings */ - { 0x3009, 0x01 }, { 0x3405, 0x10 }, { 0x3446, 0x4f }, { 0x3447, 0x00 }, @@ -228,8 +233,6 @@ static const struct imx290_regval imx290_720p_settings[] = { { 0x3453, 0x00 }, { 0x3454, 0x17 }, { 0x3455, 0x00 }, - { 0x301c, 0xe4 }, - { 0x301d, 0x0c }, }; static const struct imx290_regval imx290_10bit_settings[] = { @@ -522,6 +525,25 @@ static int imx290_write_current_format(struct imx290 *imx290, return 0; } +static int imx290_set_hmax(struct imx290 *imx290, u32 val) +{ + int ret; + + ret = imx290_write_reg(imx290, IMX290_HMAX_LOW, (val & 0xff)); + if (ret) { + dev_err(imx290->dev, "Error setting HMAX register\n"); + return ret; + } + + ret = imx290_write_reg(imx290, IMX290_HMAX_HIGH, ((val >> 8) & 0xff)); + if (ret) { + dev_err(imx290->dev, "Error setting HMAX register\n"); + return ret; + } + + return 0; +} + /* Start streaming */ static int imx290_start_streaming(struct imx290 *imx290) { @@ -551,6 +573,40 @@ static int imx290_start_streaming(struct imx290 *imx290) return ret; } + switch (imx290->nlanes) { + case 2: + if (imx290->current_mode->width == 1920) { + ret = imx290_set_hmax(imx290, IMX290_HMAX_2_1920); + if (ret < 0) + return ret; + } else { + ret = imx290_set_hmax(imx290, IMX290_HMAX_2_720); + if (ret < 0) + return ret; + } + + break; + case 4: + if (imx290->current_mode->width == 1920) { + ret = imx290_set_hmax(imx290, IMX290_HMAX_4_1920); + if (ret < 0) + return ret; + } else { + ret = imx290_set_hmax(imx290, IMX290_HMAX_4_720); + if (ret < 0) + return ret; + } + + break; + default: + /* + * We should never hit this since the data lane count is + * validated in probe itself + */ + dev_err(imx290->dev, "Lane configuration not supported\n"); + return -EINVAL; + } + /* Apply customized values from user */ ret = v4l2_ctrl_handler_setup(imx290->sd.ctrl_handler); if (ret) { @@ -607,6 +663,49 @@ static int imx290_get_regulators(struct device *dev, struct imx290 *imx290) imx290->supplies); } +static int imx290_set_data_lanes(struct imx290 *imx290) +{ + int ret = 0, laneval, frsel; + + switch (imx290->nlanes) { + case 2: + laneval = 0x01; + frsel = 0x02; + break; + case 4: + laneval = 0x03; + frsel = 0x01; + break; + default: + /* + * We should never hit this since the data lane count is + * validated in probe itself + */ + dev_err(imx290->dev, "Lane configuration not supported\n"); + ret = -EINVAL; + goto exit; + } + + ret = imx290_write_reg(imx290, IMX290_PHY_LANE_NUM, laneval); + if (ret) { + dev_err(imx290->dev, "Error setting Physical Lane number register\n"); + goto exit; + } + + ret = imx290_write_reg(imx290, IMX290_CSI_LANE_MODE, laneval); + if (ret) { + dev_err(imx290->dev, "Error setting CSI Lane mode register\n"); + goto exit; + } + + ret = imx290_write_reg(imx290, IMX290_FR_FDG_SEL, frsel); + if (ret) + dev_err(imx290->dev, "Error setting FR/FDG SEL register\n"); + +exit: + return ret; +} + static int imx290_power_on(struct device *dev) { struct i2c_client *client = to_i2c_client(dev); @@ -631,6 +730,9 @@ static int imx290_power_on(struct device *dev) gpiod_set_value_cansleep(imx290->rst_gpio, 1); usleep_range(30000, 31000); + /* Set data lane count */ + imx290_set_data_lanes(imx290); + return 0; } @@ -703,6 +805,16 @@ static int imx290_probe(struct i2c_client *client) goto free_err; } + /* Get number of data lanes */ + imx290->nlanes = imx290->ep.bus.mipi_csi2.num_data_lanes; + if (imx290->nlanes != 2 && imx290->nlanes != 4) { + dev_err(dev, "Invalid data lanes: %d\n", imx290->nlanes); + ret = -EINVAL; + goto free_err; + } + + dev_dbg(dev, "Using %u data lanes\n", imx290->nlanes); + if (!imx290->ep.nr_of_link_frequencies) { dev_err(dev, "link-frequency property not found in DT\n"); ret = -EINVAL; @@ -822,6 +934,9 @@ static int imx290_probe(struct i2c_client *client) goto free_entity; } + /* Set data lane count */ + imx290_set_data_lanes(imx290); + pm_runtime_set_active(dev); pm_runtime_enable(dev); pm_runtime_idle(dev); 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: 11304231 Return-Path: Received: from mail.kernel.org (pdx-korg-mail-1.web.codeaurora.org [172.30.200.123]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 8F9EA921 for ; Thu, 19 Dec 2019 18:23:01 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id 6D79A24679 for ; Thu, 19 Dec 2019 18:23:01 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=linaro.org header.i=@linaro.org header.b="iyymSRkQ" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727020AbfLSSW5 (ORCPT ); Thu, 19 Dec 2019 13:22:57 -0500 Received: from mail-pg1-f193.google.com ([209.85.215.193]:40657 "EHLO mail-pg1-f193.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726936AbfLSSW4 (ORCPT ); Thu, 19 Dec 2019 13:22:56 -0500 Received: by mail-pg1-f193.google.com with SMTP id k25so3546135pgt.7 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=DcHye2gcMiSLHa3ndWJSvAVi0ePZqRIWKo1qT91U0pYOlN88UFvDXBp0onXCDA45G5 lvYWcqLQTGL53rrpxXt29VAQ1zUcSc5QlootDqz/s7QuPlujEeiDaryNDh4pfA39T0yd SMuNgwgMC/VNP5luTugs11R+iM9WPSH1SYKTR8AQqVCcbpIUq3ewItsm/o+SXNveYeXJ iEkdBevuiQN1L8JunSRlftb/lfcpzMG9RlEAzMxEID4l1dL9+otjRrLtNpmiehVjCti5 bjbVw4neNV5hGEGHRDFY1oQ6kxQVhzOOkgNbg3seExNMLmvRQ3N/DVg3QBrv3oKcLXR6 YE4g== X-Gm-Message-State: APjAAAUcI+S6ptQZQbaFA7YdvrbmMNn5xs0F3NqGiJ0dzAoOYd+27oHy Ea3xdboBsyDqhwRMtAdPuSHV X-Google-Smtp-Source: APXvYqzG1vcXDyCDAjAHlqsGirk7Ni9aKqXLQ+RzNVSCFt0yvdRP9IcU/BWFVEohbUy0NUYg5RcGmA== 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-media-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-media@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(-) 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:19 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Manivannan Sadhasivam X-Patchwork-Id: 11304233 Return-Path: Received: from mail.kernel.org (pdx-korg-mail-1.web.codeaurora.org [172.30.200.123]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 3F8DC14F6 for ; Thu, 19 Dec 2019 18:23:03 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id 1CC6A24684 for ; Thu, 19 Dec 2019 18:23:03 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=linaro.org header.i=@linaro.org header.b="kmDLD54W" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726998AbfLSSXB (ORCPT ); Thu, 19 Dec 2019 13:23:01 -0500 Received: from mail-pj1-f68.google.com ([209.85.216.68]:56137 "EHLO mail-pj1-f68.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727070AbfLSSXB (ORCPT ); Thu, 19 Dec 2019 13:23:01 -0500 Received: by mail-pj1-f68.google.com with SMTP id d5so2899919pjz.5 for ; Thu, 19 Dec 2019 10:23: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=AFvgHo+YGqFoje0Tn82GYQJ1a/RGDe/xy+Kyh3iTfBI=; b=kmDLD54Wg3ujI/AZ5o82fQsFYrDiuccUSsctI4Y7S7mXX6MyEfNbDjjW9+s6zcVUKS nygmXBu+d+VM9XCAAmQ3nbV9d3I72uZUIsjZ2SF8TFVUHPw9QRjNM6Jw+1BRPLeBXvp1 cBNCRZIY/A1kpYJfHUDMOI8ai1nkGnezL24ODwAzUUPH7TiHct5j6i/A08jdpjRE3R5J pQvdnIciCIRAL3pDWcp2YfwuPzLAraQHzAVxWEuuc2oUYwHjmUQ7vD7F4aLl++6gwKFt mqL2MxBLFXllu3VhBGuTZzEB+Xzt4jE5lsgOpSSCUES1bflOqdaIw4CudFV4w25Q/kpG sIbA== 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=AFvgHo+YGqFoje0Tn82GYQJ1a/RGDe/xy+Kyh3iTfBI=; b=I++f9caFukBX1bF8VMHv91MZ1cH6hSrSHI2czxhQLHWBbyrs4836k5UdFncvwP2/Q/ f57y/s3/Yh3cYAROH93ZsUL+vHuQsfuJissbIx6B0ZTTyz5LMcKI9c5Fpbw9lZ7Iegr5 Mi6JajLIrDMbqWUM4j8idRCBznmOjHZu02xaEYQNrKftml73EKVJRBxHWYdUJp5qNCPU 6WLQd0KZpMolXMOghBG8K0rHAloLOuIMllgDpRKJZQzcD2enorHZ0nYBxeZclVi7DOrV HerfoDAXIaTpqJaZ6T5IDaegArU7pTmcvZwa5lTX8e2lloV7dORbu+iQv3hBkw8mvInM 3okg== X-Gm-Message-State: APjAAAWlOt30gb8iddOz9sfEpk7Y8BIliLSDEGR0c5ytDoAy0o9I7lkA tJ+kPMBQGd8OxyaDr+103SZCJGjj0w== X-Google-Smtp-Source: APXvYqzXfMn0kZmuBjpUAbmkAgP2/fMJH486K6UgeYhEJzoLI3sQVo78zCN+SN0jVd3rtq83ZuxG7Q== X-Received: by 2002:a17:902:bd93:: with SMTP id q19mr8338103pls.134.1576779780558; Thu, 19 Dec 2019 10:23:00 -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.56 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 19 Dec 2019 10:23:00 -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 3/6] media: i2c: imx290: Add RAW12 mode support Date: Thu, 19 Dec 2019 23:52:19 +0530 Message-Id: <20191219182222.18961-4-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-media-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-media@vger.kernel.org IMX290 is capable of outputting frames in both Raw Bayer (packed) 10 and 12 bit formats. Since the driver already supports RAW10 mode, let's add the missing RAW12 mode as well. Signed-off-by: Manivannan Sadhasivam --- drivers/media/i2c/imx290.c | 32 ++++++++++++++++++++++++++++++++ 1 file changed, 32 insertions(+) diff --git a/drivers/media/i2c/imx290.c b/drivers/media/i2c/imx290.c index 96eea0aafd3e..b6eeca56d3c9 100644 --- a/drivers/media/i2c/imx290.c +++ b/drivers/media/i2c/imx290.c @@ -75,6 +75,7 @@ struct imx290 { struct clk *xclk; struct regmap *regmap; u8 nlanes; + u8 bpp; struct v4l2_subdev sd; struct v4l2_fwnode_endpoint ep; @@ -98,6 +99,7 @@ struct imx290_pixfmt { static const struct imx290_pixfmt imx290_formats[] = { { MEDIA_BUS_FMT_SRGGB10_1X10 }, + { MEDIA_BUS_FMT_SRGGB12_1X12 }, }; static const struct regmap_config imx290_regmap_config = { @@ -265,6 +267,18 @@ static const struct imx290_regval imx290_10bit_settings[] = { { 0x300b, 0x00}, }; +static const struct imx290_regval imx290_12bit_settings[] = { + { 0x3005, 0x01 }, + { 0x3046, 0x01 }, + { 0x3129, 0x00 }, + { 0x317c, 0x00 }, + { 0x31ec, 0x0e }, + { 0x3441, 0x0c }, + { 0x3442, 0x0c }, + { 0x300a, 0xf0 }, + { 0x300b, 0x00 }, +}; + /* supported link frequencies */ static const s64 imx290_link_freq[] = { IMX290_DEFAULT_LINK_FREQ, @@ -550,6 +564,21 @@ static int imx290_write_current_format(struct imx290 *imx290, 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"); @@ -913,6 +942,9 @@ static int imx290_probe(struct i2c_client *client) goto free_err; } + /* Default bits per pixel value */ + imx290->bpp = 10; + mutex_init(&imx290->lock); v4l2_ctrl_handler_init(&imx290->ctrls, 4); 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: 11304235 Return-Path: Received: from mail.kernel.org (pdx-korg-mail-1.web.codeaurora.org [172.30.200.123]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 1255114F6 for ; Thu, 19 Dec 2019 18:23:11 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id E460824676 for ; Thu, 19 Dec 2019 18:23:10 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=linaro.org header.i=@linaro.org header.b="gQ8G1RAe" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727135AbfLSSXG (ORCPT ); Thu, 19 Dec 2019 13:23:06 -0500 Received: from mail-pj1-f66.google.com ([209.85.216.66]:35753 "EHLO mail-pj1-f66.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727128AbfLSSXG (ORCPT ); Thu, 19 Dec 2019 13:23:06 -0500 Received: by mail-pj1-f66.google.com with SMTP id s7so2922140pjc.0 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=EoZzJwSNFtqAzapkAEnkfo/Z891mUcIpcxpcOUDs/T4rB9LRJqPD+vnACGV/jWCPzS nZp4jd7P00QzQqdBlXmAU7B3HcP9JZTSkZNNytLyU1LFKWk3d0nnhZPlFHgfTKnL1ti0 HeXin2L4OeHtCeuxYGzUvpev+Crt2YdKFN2u2y0trMXn/6V23pfMHs981vZ1rgdwbjOe jZJJD+rSwy9jgMevDxvO2VCnDm7hwtikjAX3kGY6COW+V5xK6RVClK4WxJfLQxoyUIC7 2a5jNt37zox2QYBgAW5IP17H5VWSTDiv22xYAATDkxQwevEDng0wz0lMnEirT6xmJufe RNgQ== X-Gm-Message-State: APjAAAVaYBcsPAJGM7BaTti0xTwzoR9p6ViB+Xn4FwBlVBwpp7RRK4Ol ENCP8E5CszzVcOlKftTGjaej X-Google-Smtp-Source: APXvYqyzVnZODv06yR3mjE0LzOn3l+hcZpCkDYMSSVHn9s9fFrnBf0tRvxzqCDRbMLZlsMAYZMYNuw== 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-media-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-media@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(+) 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: 11304239 Return-Path: Received: from mail.kernel.org (pdx-korg-mail-1.web.codeaurora.org [172.30.200.123]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 2CEA0921 for ; Thu, 19 Dec 2019 18:23:17 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id EADF624672 for ; Thu, 19 Dec 2019 18:23:16 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=linaro.org header.i=@linaro.org header.b="ktngylax" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726905AbfLSSXN (ORCPT ); Thu, 19 Dec 2019 13:23:13 -0500 Received: from mail-pf1-f194.google.com ([209.85.210.194]:43553 "EHLO mail-pf1-f194.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727071AbfLSSXM (ORCPT ); Thu, 19 Dec 2019 13:23:12 -0500 Received: by mail-pf1-f194.google.com with SMTP id x6so2637268pfo.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=po3DlXDG+AiauYFT4VHKEv1AOskH44YFg3jQe/jZeGUNCXU4cOf7o18yFlnaBtvRPL YTHQrm6dfdM6yjLW24DKzlPKcXWDBg2B8Rto3MRxxrnpqHO9mJcn+I5GciwZYdiFfK/0 jfWYOH5ipfaMoIyAe7mJfGOcp4Ww1tkCvsOEWgs9Wh0vNWH/A3N6bEHwubL6aILGXz8J eQC3JRjSdHdsSJ9b/jljsVaXLiXEFJz/NMZJZlca01rvChQcEu8oKxYfUDzLLeUqZ5uo 0vpYaxAY0T/Dp/XVwpCXquvsCGH8Da8bJXqIb875BdBxHa3vXKDzyQ4WsUlnjzdagXgj mJkQ== X-Gm-Message-State: APjAAAXfu3i9gVCWIFWlU1izNCMxZbegOR7Ox5smNi12DKJJCE2jgOjw /g+wfgHcVibnswfPm7+xqJpFy+fUnw== X-Google-Smtp-Source: APXvYqxSiczLugu1KuiupJ4vitxISwQqt0DMQ8ArRRicC1ia4IvZgJNuHOUDYf7f2qkxhXxIvXIiyg== 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-media-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-media@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(-) 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, From patchwork Thu Dec 19 18:22:22 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Manivannan Sadhasivam X-Patchwork-Id: 11304241 Return-Path: Received: from mail.kernel.org (pdx-korg-mail-1.web.codeaurora.org [172.30.200.123]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 8239E921 for ; Thu, 19 Dec 2019 18:23:18 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id 5F75A24676 for ; Thu, 19 Dec 2019 18:23:18 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=linaro.org header.i=@linaro.org header.b="gUtZSwI5" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727181AbfLSSXR (ORCPT ); Thu, 19 Dec 2019 13:23:17 -0500 Received: from mail-pj1-f65.google.com ([209.85.216.65]:35765 "EHLO mail-pj1-f65.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727177AbfLSSXR (ORCPT ); Thu, 19 Dec 2019 13:23:17 -0500 Received: by mail-pj1-f65.google.com with SMTP id s7so2922370pjc.0 for ; Thu, 19 Dec 2019 10:23:16 -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=gPMrMi1zLN6OA6/X7P7gnmwAhoOj6bYlyFbNpwO69Qo=; b=gUtZSwI5Ulzsmc54LykF+cv8X0Jm7Kfs0WesiUq0DuTQnyoBmI/riCz285oek9SAJG p8V+AqewtM6MuinpONWRY9UqrOZCI3wcAp7DBhj8JS4DQTdiSrOLwRGRj/mQuohbSG83 vYk2w01/bsKxzy+QiBpNlxXiTNiUGUlNAPiB5xnDFX90vcVlcMlFZVmZYkr5TYtHjQP3 MQheafVzi8xnyP8NoAbWCD0ZxYh6PnvPmBgSvwYRvyFzE0wZDwrlyD1q3KpDplaTs90i TVGECp5NmtJo22/ecbdc1F3qfAk4oDAz2LFAXQmLNCdtQSmvn9SxirD0PyOhFISwXhKN t3xA== 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=gPMrMi1zLN6OA6/X7P7gnmwAhoOj6bYlyFbNpwO69Qo=; b=QM+B1IBzTJT4QFc2/t++sXQP1sXDGTSHVJM+S4uCIbmNag9bkEz8AzeMpOysKyXOoP 0Ded8eYU8KPB7Obh/do7FeVhv2pGsqmeJlNSklBEzMnqNHp60P+XKolqMYeqxoPKh90c B38YBqTWHBRQlmPdzfRpcJr0lkhjT4Y0x8AL5YxxvS50xVV+3uCkK9PYfedj32W6r/h5 y2dBelKuZPFdlnocJKbQpEn4iGUN591tLzwP9JqiOoq6DhJTUb4gtuIN02TtFSOzbd1l vaFphU87RuI0Xd22OrGDFXlRJYFMFf4r6H9ZSLnD8x33xI0CLIEl9OMN9imeySLa8444 l0SQ== X-Gm-Message-State: APjAAAXBousdHPvMtUgqgQ83g4hZeAJqFRpY+PYNkGF98pOz23wbbt3A JJsBNYOV1+7UdMstZT/SaG2m X-Google-Smtp-Source: APXvYqxh/cPkFck6sf3vfEQMX1np7F99b/uUWokTEajJPRHT+C0oBMl9tibCAQmI8m6PYTrdepN4Vw== X-Received: by 2002:a17:90a:9f04:: with SMTP id n4mr11080250pjp.76.1576779796548; Thu, 19 Dec 2019 10:23:16 -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.12 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 19 Dec 2019 10:23:16 -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 6/6] media: i2c: imx290: Move the settle time delay out of loop Date: Thu, 19 Dec 2019 23:52:22 +0530 Message-Id: <20191219182222.18961-7-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-media-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-media@vger.kernel.org The 10ms settle time is needed only at the end of all consecutive register writes. So move the delay to outside of the for loop of imx290_set_register_array(). Signed-off-by: Manivannan Sadhasivam --- drivers/media/i2c/imx290.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/drivers/media/i2c/imx290.c b/drivers/media/i2c/imx290.c index 52f1e470b507..fb6d3f649a5a 100644 --- a/drivers/media/i2c/imx290.c +++ b/drivers/media/i2c/imx290.c @@ -344,11 +344,11 @@ static int imx290_set_register_array(struct imx290 *imx290, ret = imx290_write_reg(imx290, settings->reg, settings->val); if (ret < 0) return ret; - - /* Settle time is 10ms for all registers */ - msleep(10); } + /* Provide 10ms settle time */ + msleep(10); + return 0; }