From patchwork Fri Jul 17 19:15:20 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Sowjanya Komatineni X-Patchwork-Id: 65639 X-Patchwork-Delegate: sakari.ailus@iki.fi Received: from vger.kernel.org ([23.128.96.18]) by www.linuxtv.org with esmtp (Exim 4.92) (envelope-from ) id 1jwVhG-001oSY-Ec; Fri, 17 Jul 2020 19:07:06 +0000 Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1728632AbgGQTL7 (ORCPT + 1 other); Fri, 17 Jul 2020 15:11:59 -0400 Received: from hqnvemgate25.nvidia.com ([216.228.121.64]:1396 "EHLO hqnvemgate25.nvidia.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1728607AbgGQTL6 (ORCPT ); Fri, 17 Jul 2020 15:11:58 -0400 Received: from hqpgpgate102.nvidia.com (Not Verified[216.228.121.13]) by hqnvemgate25.nvidia.com (using TLS: TLSv1.2, DES-CBC3-SHA) id ; Fri, 17 Jul 2020 12:10:58 -0700 Received: from hqmail.nvidia.com ([172.20.161.6]) by hqpgpgate102.nvidia.com (PGP Universal service); Fri, 17 Jul 2020 12:11:57 -0700 X-PGP-Universal: processed; by hqpgpgate102.nvidia.com on Fri, 17 Jul 2020 12:11:57 -0700 Received: from HQMAIL101.nvidia.com (172.20.187.10) by HQMAIL109.nvidia.com (172.20.187.15) with Microsoft SMTP Server (TLS) id 15.0.1473.3; Fri, 17 Jul 2020 19:11:57 +0000 Received: from rnnvemgw01.nvidia.com (10.128.109.123) by HQMAIL101.nvidia.com (172.20.187.10) with Microsoft SMTP Server (TLS) id 15.0.1473.3 via Frontend Transport; Fri, 17 Jul 2020 19:11:57 +0000 Received: from skomatineni-linux.nvidia.com (Not Verified[10.2.163.115]) by rnnvemgw01.nvidia.com with Trustwave SEG (v7,5,8,10121) id ; Fri, 17 Jul 2020 12:11:56 -0700 From: Sowjanya Komatineni To: , , , , , , , , , CC: , , Subject: [PATCH v2 1/3] media: i2c: imx274: Fix Y_OUT_SIZE register setting Date: Fri, 17 Jul 2020 12:15:20 -0700 Message-ID: <1595013322-15077-1-git-send-email-skomatineni@nvidia.com> X-Mailer: git-send-email 2.7.4 X-NVConfidentiality: public MIME-Version: 1.0 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=nvidia.com; s=n1; t=1595013058; bh=DLvQ6chRzbjeKicuQdxuqVcpH3d1W/1R1Kay/NtRj70=; h=X-PGP-Universal:From:To:CC:Subject:Date:Message-ID:X-Mailer: X-NVConfidentiality:MIME-Version:Content-Type; b=dNkIccMwSkcpJVG9TVvN1c8DqptyYAYHC0pojdxtG/ndu8jD1Aqq8KySS2156GZQm yngeqITKvsHwtyC2mPMbgIoU7I6NAAfkIR3cQD8BtywDat7iYArxf0NoScpyi9SlbM pMUY7U4PFSmgDiu39pU9LqEhyukAf2VhxjdYKUi1jFtIlymWLn7Y7HB3wUpYAZWJqk FLVNwWvdAlmJXbXy5zeU63P91/RarxpLqS8hNorSv25iXnI3FefRBmWj3t7FxlFbd4 1wR3HRZfgqhbsY6XDaelo7suvoDrmjeTShv0B0YG9M7chZ5jXhYugVQ6fVhFetF03x lfT3lqnadGRRg== Sender: linux-media-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-media@vger.kernel.org X-LSpam-Score: -2.5 (--) X-LSpam-Report: No, score=-2.5 required=5.0 tests=BAYES_00=-1.9,DKIMWL_WL_HIGH=0.001,DKIM_SIGNED=0.1,DKIM_VALID=-0.1,DKIM_VALID_AU=-0.1,HEADER_FROM_DIFFERENT_DOMAINS=0.5,MAILING_LIST_MULTI=-1 autolearn=ham autolearn_force=no As per Sony IMX274 Y_OUT_SIZE should be the height of effective image output from the sensor which are the actual total lines sent over MIPI CSI to receiver. So, Y_OUT_SIZE should be same as crop height and this patch fixes it. Signed-off-by: Sowjanya Komatineni --- drivers/media/i2c/imx274.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/drivers/media/i2c/imx274.c b/drivers/media/i2c/imx274.c index e6aa9f3..55869ff 100644 --- a/drivers/media/i2c/imx274.c +++ b/drivers/media/i2c/imx274.c @@ -1163,7 +1163,7 @@ static int imx274_apply_trimming(struct stimx274 *imx274) (-imx274->crop.top / 2) : (imx274->crop.top / 2); v_cut = (IMX274_MAX_HEIGHT - imx274->crop.height) / 2; write_v_size = imx274->crop.height + 22; - y_out_size = imx274->crop.height + 14; + y_out_size = imx274->crop.height; err = imx274_write_mbreg(imx274, IMX274_HMAX_REG_LSB, hmax, 2); if (!err) From patchwork Fri Jul 17 19:15:21 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Sowjanya Komatineni X-Patchwork-Id: 65640 Received: from vger.kernel.org ([23.128.96.18]) by www.linuxtv.org with esmtp (Exim 4.92) (envelope-from ) id 1jwVhM-001oSm-8V; Fri, 17 Jul 2020 19:07:09 +0000 Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1728670AbgGQTMD (ORCPT + 1 other); Fri, 17 Jul 2020 15:12:03 -0400 Received: from hqnvemgate26.nvidia.com ([216.228.121.65]:6388 "EHLO hqnvemgate26.nvidia.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1728620AbgGQTL7 (ORCPT ); Fri, 17 Jul 2020 15:11:59 -0400 Received: from hqpgpgate101.nvidia.com (Not Verified[216.228.121.13]) by hqnvemgate26.nvidia.com (using TLS: TLSv1.2, DES-CBC3-SHA) id ; Fri, 17 Jul 2020 12:11:46 -0700 Received: from hqmail.nvidia.com ([172.20.161.6]) by hqpgpgate101.nvidia.com (PGP Universal service); Fri, 17 Jul 2020 12:11:58 -0700 X-PGP-Universal: processed; by hqpgpgate101.nvidia.com on Fri, 17 Jul 2020 12:11:58 -0700 Received: from HQMAIL107.nvidia.com (172.20.187.13) by HQMAIL111.nvidia.com (172.20.187.18) with Microsoft SMTP Server (TLS) id 15.0.1473.3; Fri, 17 Jul 2020 19:11:58 +0000 Received: from rnnvemgw01.nvidia.com (10.128.109.123) by HQMAIL107.nvidia.com (172.20.187.13) with Microsoft SMTP Server (TLS) id 15.0.1473.3 via Frontend Transport; Fri, 17 Jul 2020 19:11:58 +0000 Received: from skomatineni-linux.nvidia.com (Not Verified[10.2.163.115]) by rnnvemgw01.nvidia.com with Trustwave SEG (v7,5,8,10121) id ; Fri, 17 Jul 2020 12:11:57 -0700 From: Sowjanya Komatineni To: , , , , , , , , , CC: , , Subject: [PATCH v2 2/3] dt-bindings: media: imx274: Add optional input clock and supplies Date: Fri, 17 Jul 2020 12:15:21 -0700 Message-ID: <1595013322-15077-2-git-send-email-skomatineni@nvidia.com> X-Mailer: git-send-email 2.7.4 In-Reply-To: <1595013322-15077-1-git-send-email-skomatineni@nvidia.com> References: <1595013322-15077-1-git-send-email-skomatineni@nvidia.com> X-NVConfidentiality: public MIME-Version: 1.0 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=nvidia.com; s=n1; t=1595013106; bh=GFC1LF/7lvAW8gpnTVuP0yCQ7aUNS8pw6xjdqQGCq/s=; h=X-PGP-Universal:From:To:CC:Subject:Date:Message-ID:X-Mailer: In-Reply-To:References:X-NVConfidentiality:MIME-Version: Content-Type; b=J+54t67z4hEeAnjeHc2ks0APmu0OdZJEdPX69TmRi3nt2oU2a+gZqpVQ9s8yzpQfM n4Oiy/ovrAvVEPVQUTDRMKRlrG8OfrijH4f24TUBVcp0gw2nf73UYXfARtSnUDHfP+ UvrsYYzkpKzCCxOX573J2JCVVmGMCkclCMX1JGvG5o8R69WTzrCV/MHpUx+/5B2e6R 4iwcXFa9/6WWR0jdP3invXNMBF6pEvt4nZix0FM2JAujujuDMHTrh9JeBD8Qbb/2Yf w5eVDxKTrd7JPWPuJzLxAfcPdMrAA5SGFIHJRnffmeGC4Q+Lnt+7WgV/xf+rT6dTC+ O/WDy0BfhI35Q== Sender: linux-media-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-media@vger.kernel.org X-LSpam-Score: -2.5 (--) X-LSpam-Report: No, score=-2.5 required=5.0 tests=BAYES_00=-1.9,DKIMWL_WL_HIGH=0.001,DKIM_SIGNED=0.1,DKIM_VALID=-0.1,DKIM_VALID_AU=-0.1,HEADER_FROM_DIFFERENT_DOMAINS=0.5,MAILING_LIST_MULTI=-1 autolearn=ham autolearn_force=no This patch adds IMX274 optional external clock input and voltage supplies to device tree bindings. Signed-off-by: Sowjanya Komatineni Reviewed-by: Luca Ceresoli --- Documentation/devicetree/bindings/media/i2c/imx274.txt | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/Documentation/devicetree/bindings/media/i2c/imx274.txt b/Documentation/devicetree/bindings/media/i2c/imx274.txt index 80f2e89..0727079 100644 --- a/Documentation/devicetree/bindings/media/i2c/imx274.txt +++ b/Documentation/devicetree/bindings/media/i2c/imx274.txt @@ -13,6 +13,11 @@ Required Properties: Optional Properties: - reset-gpios: Sensor reset GPIO +- clocks: Reference to the input clock. +- clock-names: Should be "inck". +- VANA-supply: Sensor 2.8v analog supply. +- VDIG-supply: Sensor 1.8v digital core supply. +- VDDL-supply: Sensor digital IO 1.2v supply. The imx274 device node should contain one 'port' child node with an 'endpoint' subnode. For further reading on port node refer to From patchwork Fri Jul 17 19:15:22 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Sowjanya Komatineni X-Patchwork-Id: 65641 X-Patchwork-Delegate: sakari.ailus@iki.fi Received: from vger.kernel.org ([23.128.96.18]) by www.linuxtv.org with esmtp (Exim 4.92) (envelope-from ) id 1jwVhO-001oSm-6L; Fri, 17 Jul 2020 19:07:10 +0000 Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1728654AbgGQTMC (ORCPT + 1 other); Fri, 17 Jul 2020 15:12:02 -0400 Received: from hqnvemgate25.nvidia.com ([216.228.121.64]:1403 "EHLO hqnvemgate25.nvidia.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1728639AbgGQTMB (ORCPT ); Fri, 17 Jul 2020 15:12:01 -0400 Received: from hqpgpgate101.nvidia.com (Not Verified[216.228.121.13]) by hqnvemgate25.nvidia.com (using TLS: TLSv1.2, DES-CBC3-SHA) id ; Fri, 17 Jul 2020 12:11:00 -0700 Received: from hqmail.nvidia.com ([172.20.161.6]) by hqpgpgate101.nvidia.com (PGP Universal service); Fri, 17 Jul 2020 12:12:00 -0700 X-PGP-Universal: processed; by hqpgpgate101.nvidia.com on Fri, 17 Jul 2020 12:12:00 -0700 Received: from HQMAIL101.nvidia.com (172.20.187.10) by HQMAIL105.nvidia.com (172.20.187.12) with Microsoft SMTP Server (TLS) id 15.0.1473.3; Fri, 17 Jul 2020 19:11:59 +0000 Received: from rnnvemgw01.nvidia.com (10.128.109.123) by HQMAIL101.nvidia.com (172.20.187.10) with Microsoft SMTP Server (TLS) id 15.0.1473.3 via Frontend Transport; Fri, 17 Jul 2020 19:11:59 +0000 Received: from skomatineni-linux.nvidia.com (Not Verified[10.2.163.115]) by rnnvemgw01.nvidia.com with Trustwave SEG (v7,5,8,10121) id ; Fri, 17 Jul 2020 12:11:59 -0700 From: Sowjanya Komatineni To: , , , , , , , , , CC: , , Subject: [PATCH v2 3/3] media: i2c: imx274: Add IMX274 power on and off sequence Date: Fri, 17 Jul 2020 12:15:22 -0700 Message-ID: <1595013322-15077-3-git-send-email-skomatineni@nvidia.com> X-Mailer: git-send-email 2.7.4 In-Reply-To: <1595013322-15077-1-git-send-email-skomatineni@nvidia.com> References: <1595013322-15077-1-git-send-email-skomatineni@nvidia.com> X-NVConfidentiality: public MIME-Version: 1.0 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=nvidia.com; s=n1; t=1595013060; bh=boIvlrIG2qx41G9zjbey4MygAAMCqMjJQzTJ18Zg5mk=; h=X-PGP-Universal:From:To:CC:Subject:Date:Message-ID:X-Mailer: In-Reply-To:References:X-NVConfidentiality:MIME-Version: Content-Type; b=bJS9Y8xb6VvtxfhFTwdZDiBJ6i32INrBvfuyigyXBuwjhoYX2BbDLm1hGxS9hxQve HRfme8lDSqahhvaSrXdkkH4VNEwztHGzi6Q1t8jpW/+TFFQHxkeP4p4FvMt9WGMBWq FqZTgeb0ic02lWjg7rRgDhOl4fSgvaC01ZFV+3GfHwCznUuezQphXSIZGuvLtfPz0P 5dj84UYgvKvQH7SuIItAiBevLel53dEFg9sw9W6CmB73aAz9S9P+MSY/Zv7PWpv7Us Q6nU1i6KyE2kIgdxy6G+tbQEFI3FM7kTGhiLcjMsm75ExF6LsssHx6shIHHtr+SxEH k0WF8SR1E1N4g== Sender: linux-media-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-media@vger.kernel.org X-LSpam-Score: -2.5 (--) X-LSpam-Report: No, score=-2.5 required=5.0 tests=BAYES_00=-1.9,DKIMWL_WL_HIGH=0.001,DKIM_SIGNED=0.1,DKIM_VALID=-0.1,DKIM_VALID_AU=-0.1,HEADER_FROM_DIFFERENT_DOMAINS=0.5,MAILING_LIST_MULTI=-1 autolearn=ham autolearn_force=no IMX274 has VANA analog 2.8V supply, VDIG digital core 1.8V supply, and VDDL digital io 1.2V supply which are optional based on camera module design. IMX274 also need external 24Mhz clock and is optional based on camera module design. This patch adds support for IMX274 power on and off to enable and disable these supplies and external clock. Signed-off-by: Sowjanya Komatineni --- drivers/media/i2c/imx274.c | 135 ++++++++++++++++++++++++++++++++++++++++++++- 1 file changed, 132 insertions(+), 3 deletions(-) diff --git a/drivers/media/i2c/imx274.c b/drivers/media/i2c/imx274.c index 55869ff..c3f7bcd 100644 --- a/drivers/media/i2c/imx274.c +++ b/drivers/media/i2c/imx274.c @@ -19,6 +19,7 @@ #include #include #include +#include #include #include #include @@ -27,6 +28,8 @@ #include #include +#define IMX274_DEFAULT_CLK_FREQ 24000000 + /* * See "SHR, SVR Setting" in datasheet */ @@ -131,6 +134,15 @@ #define IMX274_TABLE_WAIT_MS 0 #define IMX274_TABLE_END 1 +/* regulator supplies */ +static const char * const imx274_supply_names[] = { + "VDDL", /* IF (1.2V) supply */ + "VDIG", /* Digital Core (1.8V) supply */ + "VANA", /* Analog (2.8V) supply */ +}; + +#define IMX274_NUM_SUPPLIES ARRAY_SIZE(imx274_supply_names) + /* * imx274 I2C operation related structure */ @@ -501,6 +513,8 @@ struct imx274_ctrls { * @frame_rate: V4L2 frame rate structure * @regmap: Pointer to regmap structure * @reset_gpio: Pointer to reset gpio + * @supplies: imx274 analog and digital supplies + * @inck: input clock to imx274 * @lock: Mutex structure * @mode: Parameters for the selected readout mode */ @@ -514,6 +528,8 @@ struct stimx274 { struct v4l2_fract frame_interval; struct regmap *regmap; struct gpio_desc *reset_gpio; + struct regulator *supplies[IMX274_NUM_SUPPLIES]; + struct clk *inck; struct mutex lock; /* mutex lock for operations */ const struct imx274_mode *mode; }; @@ -767,6 +783,98 @@ static void imx274_reset(struct stimx274 *priv, int rst) usleep_range(IMX274_RESET_DELAY1, IMX274_RESET_DELAY2); } +/* + * imx274_power_on - Function called to power on the sensor + * @imx274: Pointer to device structure + */ +static int imx274_power_on(struct device *dev) +{ + struct i2c_client *client = to_i2c_client(dev); + struct v4l2_subdev *sd = i2c_get_clientdata(client); + struct stimx274 *imx274 = to_imx274(sd); + int i, ret; + + ret = clk_prepare_enable(imx274->inck); + if (ret) { + dev_err(&imx274->client->dev, "Failed to enable clock\n"); + return ret; + } + + for (i = 0; i < IMX274_NUM_SUPPLIES; i++) { + if (imx274->supplies[i]) { + ret = regulator_enable(imx274->supplies[i]); + if (ret < 0) { + dev_err(&imx274->client->dev, + "Failed to enable %s supply: %d\n", + imx274_supply_names[i], ret); + goto fail_reg; + } + } + } + + usleep_range(1, 2); + imx274_reset(imx274, 1); + + return 0; + +fail_reg: + for (--i; i >= 0; i--) { + if (imx274->supplies[i]) + regulator_disable(imx274->supplies[i]); + } + + clk_disable_unprepare(imx274->inck); + return ret; +} + +/* + * imx274_power_off - Function called to power off the sensor + * @imx274: Pointer to device structure + */ +static int imx274_power_off(struct device *dev) +{ + struct i2c_client *client = to_i2c_client(dev); + struct v4l2_subdev *sd = i2c_get_clientdata(client); + struct stimx274 *imx274 = to_imx274(sd); + int i; + + imx274_reset(imx274, 0); + + for (i = 0; i < IMX274_NUM_SUPPLIES; i++) { + if (imx274->supplies[i]) + regulator_disable(imx274->supplies[i]); + } + + clk_disable_unprepare(imx274->inck); + + return 0; +} + +static int imx274_get_regulators(struct device *dev, struct stimx274 *imx274) +{ + int i, err; + const char *supply; + + for (i = 0; i < IMX274_NUM_SUPPLIES; i++) { + supply = imx274_supply_names[i]; + imx274->supplies[i] = devm_regulator_get_optional(dev, supply); + if (!IS_ERR(imx274->supplies[i])) + continue; + err = PTR_ERR(imx274->supplies[i]); + if (err != -ENODEV) { + if (err != -EPROBE_DEFER) + dev_err(&imx274->client->dev, + "Failed to get %s supply: %d\n", + supply, err); + return err; + } + + imx274->supplies[i] = NULL; + } + + return 0; +} + /** * imx274_s_ctrl - This is used to set the imx274 V4L2 controls * @ctrl: V4L2 control to be set @@ -1836,6 +1944,13 @@ static int imx274_probe(struct i2c_client *client) mutex_init(&imx274->lock); + imx274->inck = devm_clk_get_optional(&client->dev, "inck"); + ret = imx274_get_regulators(&client->dev, imx274); + if (ret) { + dev_err(&client->dev, "Failed to get power regulators, err: %d\n", ret); + return ret; + } + /* initialize format */ imx274->mode = &imx274_modes[IMX274_DEFAULT_BINNING]; imx274->crop.width = IMX274_MAX_WIDTH; @@ -1883,15 +1998,26 @@ static int imx274_probe(struct i2c_client *client) goto err_me; } - /* pull sensor out of reset */ - imx274_reset(imx274, 1); + /* power on the sensor */ + ret = imx274_power_on(&client->dev); + if (ret < 0) { + dev_err(&client->dev, + "%s : imx274 power on failed\n", __func__); + goto err_me; + } + + ret = clk_set_rate(imx274->inck, IMX274_DEFAULT_CLK_FREQ); + if (ret < 0) { + dev_err(&client->dev, "Failed to set INCK clock rate\n"); + return ret; + } /* initialize controls */ ret = v4l2_ctrl_handler_init(&imx274->ctrls.handler, 4); if (ret < 0) { dev_err(&client->dev, "%s : ctrl handler init Failed\n", __func__); - goto err_me; + goto err_power_off; } imx274->ctrls.handler.lock = &imx274->lock; @@ -1958,6 +2084,8 @@ static int imx274_probe(struct i2c_client *client) err_ctrls: v4l2_ctrl_handler_free(&imx274->ctrls.handler); +err_power_off: + imx274_power_off(&client->dev); err_me: media_entity_cleanup(&sd->entity); err_regmap: @@ -1975,6 +2103,7 @@ static int imx274_remove(struct i2c_client *client) v4l2_async_unregister_subdev(sd); v4l2_ctrl_handler_free(&imx274->ctrls.handler); + imx274_power_off(&client->dev); media_entity_cleanup(&sd->entity); mutex_destroy(&imx274->lock); return 0;