From patchwork Mon Aug 31 19:52:35 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Sowjanya Komatineni X-Patchwork-Id: 11746925 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 CC2E6109B for ; Mon, 31 Aug 2020 19:52:52 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id A546D2137B for ; Mon, 31 Aug 2020 19:52:52 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=nvidia.com header.i=@nvidia.com header.b="FnR1bS7e" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1729824AbgHaTwv (ORCPT ); Mon, 31 Aug 2020 15:52:51 -0400 Received: from hqnvemgate26.nvidia.com ([216.228.121.65]:14835 "EHLO hqnvemgate26.nvidia.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1729810AbgHaTwu (ORCPT ); Mon, 31 Aug 2020 15:52:50 -0400 Received: from hqpgpgate101.nvidia.com (Not Verified[216.228.121.13]) by hqnvemgate26.nvidia.com (using TLS: TLSv1.2, DES-CBC3-SHA) id ; Mon, 31 Aug 2020 12:52:36 -0700 Received: from hqmail.nvidia.com ([172.20.161.6]) by hqpgpgate101.nvidia.com (PGP Universal service); Mon, 31 Aug 2020 12:52:49 -0700 X-PGP-Universal: processed; by hqpgpgate101.nvidia.com on Mon, 31 Aug 2020 12:52:49 -0700 Received: from HQMAIL111.nvidia.com (172.20.187.18) by HQMAIL101.nvidia.com (172.20.187.10) with Microsoft SMTP Server (TLS) id 15.0.1473.3; Mon, 31 Aug 2020 19:52:49 +0000 Received: from hqnvemgw03.nvidia.com (10.124.88.68) by HQMAIL111.nvidia.com (172.20.187.18) with Microsoft SMTP Server (TLS) id 15.0.1473.3 via Frontend Transport; Mon, 31 Aug 2020 19:52:49 +0000 Received: from skomatineni-linux.nvidia.com (Not Verified[10.2.173.243]) by hqnvemgw03.nvidia.com with Trustwave SEG (v7,5,8,10121) id ; Mon, 31 Aug 2020 12:52:49 -0700 From: Sowjanya Komatineni To: , , , , , , , , , CC: , , Subject: [PATCH v4 1/4] media: i2c: imx274: Fix Y_OUT_SIZE register setting Date: Mon, 31 Aug 2020 12:52:35 -0700 Message-ID: <1598903558-9691-2-git-send-email-skomatineni@nvidia.com> X-Mailer: git-send-email 2.7.4 In-Reply-To: <1598903558-9691-1-git-send-email-skomatineni@nvidia.com> References: <1598903558-9691-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=1598903556; bh=7eG8er5DakEQLU4K41aXrq57p9hJvRNjoRAVrC46VL0=; h=X-PGP-Universal:From:To:CC:Subject:Date:Message-ID:X-Mailer: In-Reply-To:References:X-NVConfidentiality:MIME-Version: Content-Type; b=FnR1bS7erlxqJsX6qB/2TMIfCH6KAQc49FTc1yRdKVnjW+TPFijVT0GBCp5y2mYs6 3IJtX29q7B1OPZUP8iozX6bHugQ07yXnjArrkOxjyINoO3b/tzQBZeC0xFKTY3mC9y Tclh6muEbkAhV1urqwnwleD44gicwLSqXN3Qd4x2mPszcUoCh01I1B00BK6uQQFg65 nRQT+ah4p7QA6pqOJDVt6/F+8wjHBxv7I3ayIwiJxLNEDcmFFiu/l0BA+x8fV1nB8B HXa2wOqS7rFbgyqCIJNOryeIjDDSp37q+y1GR1UZ7rrAvhOwc9xsPCBmo650+CAG4z izC2zd0MVTmgw== Sender: linux-media-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-media@vger.kernel.org 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 6011cec..a4b9dfd 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 Mon Aug 31 19:52:36 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Sowjanya Komatineni X-Patchwork-Id: 11746931 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 9BC3A138A for ; Mon, 31 Aug 2020 19:53:13 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 8406D20FC3 for ; Mon, 31 Aug 2020 19:53:13 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=nvidia.com header.i=@nvidia.com header.b="nufgvQyu" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1729874AbgHaTxL (ORCPT ); Mon, 31 Aug 2020 15:53:11 -0400 Received: from hqnvemgate26.nvidia.com ([216.228.121.65]:14842 "EHLO hqnvemgate26.nvidia.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1729816AbgHaTwu (ORCPT ); Mon, 31 Aug 2020 15:52:50 -0400 Received: from hqpgpgate102.nvidia.com (Not Verified[216.228.121.13]) by hqnvemgate26.nvidia.com (using TLS: TLSv1.2, DES-CBC3-SHA) id ; Mon, 31 Aug 2020 12:52:36 -0700 Received: from hqmail.nvidia.com ([172.20.161.6]) by hqpgpgate102.nvidia.com (PGP Universal service); Mon, 31 Aug 2020 12:52:50 -0700 X-PGP-Universal: processed; by hqpgpgate102.nvidia.com on Mon, 31 Aug 2020 12:52:50 -0700 Received: from HQMAIL109.nvidia.com (172.20.187.15) by HQMAIL105.nvidia.com (172.20.187.12) with Microsoft SMTP Server (TLS) id 15.0.1473.3; Mon, 31 Aug 2020 19:52:50 +0000 Received: from hqnvemgw03.nvidia.com (10.124.88.68) by HQMAIL109.nvidia.com (172.20.187.15) with Microsoft SMTP Server (TLS) id 15.0.1473.3 via Frontend Transport; Mon, 31 Aug 2020 19:52:50 +0000 Received: from skomatineni-linux.nvidia.com (Not Verified[10.2.173.243]) by hqnvemgw03.nvidia.com with Trustwave SEG (v7,5,8,10121) id ; Mon, 31 Aug 2020 12:52:49 -0700 From: Sowjanya Komatineni To: , , , , , , , , , CC: , , Subject: [PATCH v4 2/4] dt-bindings: media: imx274: Use lower case for supply names Date: Mon, 31 Aug 2020 12:52:36 -0700 Message-ID: <1598903558-9691-3-git-send-email-skomatineni@nvidia.com> X-Mailer: git-send-email 2.7.4 In-Reply-To: <1598903558-9691-1-git-send-email-skomatineni@nvidia.com> References: <1598903558-9691-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=1598903556; bh=ySzum52tCISvSDqWynIx+cn7v/qn33wbCu7y8hGm7XQ=; h=X-PGP-Universal:From:To:CC:Subject:Date:Message-ID:X-Mailer: In-Reply-To:References:X-NVConfidentiality:MIME-Version: Content-Type; b=nufgvQyutBdVMTJl7UiqVZMgPSKYIX84fX3enTtbUqHBbB+QllvIEqNKdRSamy7T5 IgKD0soBJQikeZdTcQnE67/tBxHZh/5I/C+g4UIsbOwuJVjoMdzhNf0GKx0zCwxEsq Pirjy85sHv933LyJlWY/8lDi/Ey7Cm4yz46zPHv6JBBHJuyYzqM17GX5+XsKunA0QY 7/NWGOozeLB/YxukFaTf9azyYUg9S3YsCxa1mTOkee1iqOwn/gKyJExi7HB7nnSqkQ XlFy572kq8M6i4AiFRQJXKNcG5pzXFou0rzexV1BXIYoHclCkr0tpzGYUdXUm9KsTc 7WhUTDsCAwkQw== Sender: linux-media-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-media@vger.kernel.org This patch updates dt-binding to use lower case for supply names. Signed-off-by: Sowjanya Komatineni --- Documentation/devicetree/bindings/media/i2c/imx274.txt | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/Documentation/devicetree/bindings/media/i2c/imx274.txt b/Documentation/devicetree/bindings/media/i2c/imx274.txt index 0727079..d0a5c899 100644 --- a/Documentation/devicetree/bindings/media/i2c/imx274.txt +++ b/Documentation/devicetree/bindings/media/i2c/imx274.txt @@ -15,9 +15,9 @@ 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. +- 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 Mon Aug 31 19:52:37 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Sowjanya Komatineni X-Patchwork-Id: 11746927 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 EF822109B for ; Mon, 31 Aug 2020 19:53:03 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id D36002083E for ; Mon, 31 Aug 2020 19:53:03 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=nvidia.com header.i=@nvidia.com header.b="CBMLBDtR" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1729840AbgHaTwx (ORCPT ); Mon, 31 Aug 2020 15:52:53 -0400 Received: from hqnvemgate25.nvidia.com ([216.228.121.64]:8287 "EHLO hqnvemgate25.nvidia.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1728671AbgHaTwv (ORCPT ); Mon, 31 Aug 2020 15:52:51 -0400 Received: from hqpgpgate102.nvidia.com (Not Verified[216.228.121.13]) by hqnvemgate25.nvidia.com (using TLS: TLSv1.2, DES-CBC3-SHA) id ; Mon, 31 Aug 2020 12:52:05 -0700 Received: from hqmail.nvidia.com ([172.20.161.6]) by hqpgpgate102.nvidia.com (PGP Universal service); Mon, 31 Aug 2020 12:52:50 -0700 X-PGP-Universal: processed; by hqpgpgate102.nvidia.com on Mon, 31 Aug 2020 12:52:50 -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; Mon, 31 Aug 2020 19:52:50 +0000 Received: from hqnvemgw03.nvidia.com (10.124.88.68) by HQMAIL101.nvidia.com (172.20.187.10) with Microsoft SMTP Server (TLS) id 15.0.1473.3 via Frontend Transport; Mon, 31 Aug 2020 19:52:50 +0000 Received: from skomatineni-linux.nvidia.com (Not Verified[10.2.173.243]) by hqnvemgw03.nvidia.com with Trustwave SEG (v7,5,8,10121) id ; Mon, 31 Aug 2020 12:52:50 -0700 From: Sowjanya Komatineni To: , , , , , , , , , CC: , , Subject: [PATCH v4 3/4] dt-bindings: media: imx274: Move clock and supplies to required properties Date: Mon, 31 Aug 2020 12:52:37 -0700 Message-ID: <1598903558-9691-4-git-send-email-skomatineni@nvidia.com> X-Mailer: git-send-email 2.7.4 In-Reply-To: <1598903558-9691-1-git-send-email-skomatineni@nvidia.com> References: <1598903558-9691-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=1598903525; bh=cI9qXzcPGqGdkxaGFBpZnNBvnOVWFpZQPxddtvK1mz4=; h=X-PGP-Universal:From:To:CC:Subject:Date:Message-ID:X-Mailer: In-Reply-To:References:X-NVConfidentiality:MIME-Version: Content-Type; b=CBMLBDtRBqmu3/996GUca0WoNJxJcwYYW44ay7eQwiYIzMp4S5UPvJv9zJB+ujJ0o xYanmKZEWSi280To38pclJenulIOdJAOwD7UmQJFzeNb1r7DSzKQnaGtrvoFRylX9l 4012zwHHVUIIecCdf9rv28Y7M2rXMx8Q5qMzqTyjzk9UawbcyVZx0ZuTud+2yqn5dP orTy92MOCIN3k0hG8FlaXUHlR6uM8QTLFx2ktksXHVVbGqXXTTxdp1W2BiToi14dF+ SD2TRSxUvBGbdI3lUP5M819ENZqxWTWBo29+qUBT4d/lY62HMb7CZuvsXX/ZJsukVa 8uj/yKNqDjTaw== Sender: linux-media-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-media@vger.kernel.org Clock and supplies are external to IMX274 sensor and are dependent on camera module design. So, this patch moves them to required properties. Signed-off-by: Sowjanya Komatineni --- Documentation/devicetree/bindings/media/i2c/imx274.txt | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/Documentation/devicetree/bindings/media/i2c/imx274.txt b/Documentation/devicetree/bindings/media/i2c/imx274.txt index d0a5c899..b43bed6 100644 --- a/Documentation/devicetree/bindings/media/i2c/imx274.txt +++ b/Documentation/devicetree/bindings/media/i2c/imx274.txt @@ -10,15 +10,15 @@ at 1440 Mbps. Required Properties: - compatible: value should be "sony,imx274" for imx274 sensor - reg: I2C bus address of the device - -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. +Optional Properties: +- reset-gpios: Sensor reset GPIO + The imx274 device node should contain one 'port' child node with an 'endpoint' subnode. For further reading on port node refer to Documentation/devicetree/bindings/media/video-interfaces.txt. From patchwork Mon Aug 31 19:52:38 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Sowjanya Komatineni X-Patchwork-Id: 11746929 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 A1B16109B for ; Mon, 31 Aug 2020 19:53:10 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 8421E20FC3 for ; Mon, 31 Aug 2020 19:53:10 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=nvidia.com header.i=@nvidia.com header.b="WkneU/+8" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1729864AbgHaTxG (ORCPT ); Mon, 31 Aug 2020 15:53:06 -0400 Received: from hqnvemgate24.nvidia.com ([216.228.121.143]:2974 "EHLO hqnvemgate24.nvidia.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1729833AbgHaTww (ORCPT ); Mon, 31 Aug 2020 15:52:52 -0400 Received: from hqpgpgate101.nvidia.com (Not Verified[216.228.121.13]) by hqnvemgate24.nvidia.com (using TLS: TLSv1.2, DES-CBC3-SHA) id ; Mon, 31 Aug 2020 12:50:45 -0700 Received: from hqmail.nvidia.com ([172.20.161.6]) by hqpgpgate101.nvidia.com (PGP Universal service); Mon, 31 Aug 2020 12:52:51 -0700 X-PGP-Universal: processed; by hqpgpgate101.nvidia.com on Mon, 31 Aug 2020 12:52:51 -0700 Received: from HQMAIL111.nvidia.com (172.20.187.18) by HQMAIL109.nvidia.com (172.20.187.15) with Microsoft SMTP Server (TLS) id 15.0.1473.3; Mon, 31 Aug 2020 19:52:51 +0000 Received: from hqnvemgw03.nvidia.com (10.124.88.68) by HQMAIL111.nvidia.com (172.20.187.18) with Microsoft SMTP Server (TLS) id 15.0.1473.3 via Frontend Transport; Mon, 31 Aug 2020 19:52:51 +0000 Received: from skomatineni-linux.nvidia.com (Not Verified[10.2.173.243]) by hqnvemgw03.nvidia.com with Trustwave SEG (v7,5,8,10121) id ; Mon, 31 Aug 2020 12:52:51 -0700 From: Sowjanya Komatineni To: , , , , , , , , , CC: , , Subject: [PATCH v4 4/4] media: i2c: imx274: Add IMX274 power on and off sequence Date: Mon, 31 Aug 2020 12:52:38 -0700 Message-ID: <1598903558-9691-5-git-send-email-skomatineni@nvidia.com> X-Mailer: git-send-email 2.7.4 In-Reply-To: <1598903558-9691-1-git-send-email-skomatineni@nvidia.com> References: <1598903558-9691-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=1598903445; bh=lP1zhiAy94Lt2N8VXq4yZb/bmC1XQ1c+uwH/BIDJqd8=; h=X-PGP-Universal:From:To:CC:Subject:Date:Message-ID:X-Mailer: In-Reply-To:References:X-NVConfidentiality:MIME-Version: Content-Type; b=WkneU/+8H0TRxL7R3LjZ4xADK1bfCpq/647GSFvSF1bodE7Qg4Xbd0Ioj3Z6ZkzkO W2HP1DpgQoYO3MiFtecQO6Hs0jZ0l9t8kXM9Kip+R5aFfsxaI+T53MjHeeAPGWdPxV nCDVEjD8yKJFtiuZwbe3Dovz/fb/ZVGmMXMtntPB6Is4cQv9Qr3Gq6B2HTnWc8qGvR qjgQV+20+RMGOFUrc920KYDr8NQObzsw9mYlYOPLbuw8VP6Y9DU8p9Gwg94UBiQmqk wwklZIe7Em868tL3ACKR630WlXenQI4O+9ZP0xa7oF70OnQFyqBq1WGOTYnaptq4Xo u1HNokKGco/Ow== Sender: linux-media-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-media@vger.kernel.org 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. Reviewed-by: Luca Ceresoli Signed-off-by: Sowjanya Komatineni --- drivers/media/i2c/imx274.c | 151 ++++++++++++++++++++++++++++++++++++++++++++- 1 file changed, 148 insertions(+), 3 deletions(-) diff --git a/drivers/media/i2c/imx274.c b/drivers/media/i2c/imx274.c index a4b9dfd..18a1e87 100644 --- a/drivers/media/i2c/imx274.c +++ b/drivers/media/i2c/imx274.c @@ -18,7 +18,9 @@ #include #include #include +#include #include +#include #include #include #include @@ -131,6 +133,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 +512,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 +527,8 @@ struct stimx274 { struct v4l2_fract frame_interval; struct regmap *regmap; struct gpio_desc *reset_gpio; + struct regulator_bulk_data supplies[IMX274_NUM_SUPPLIES]; + struct clk *inck; struct mutex lock; /* mutex lock for operations */ const struct imx274_mode *mode; }; @@ -767,6 +782,75 @@ 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 ret; + + /* keep sensor in reset before power on */ + imx274_reset(imx274, 0); + + ret = clk_prepare_enable(imx274->inck); + if (ret) { + dev_err(&imx274->client->dev, + "Failed to enable input clock: %d\n", ret); + return ret; + } + + ret = regulator_bulk_enable(IMX274_NUM_SUPPLIES, imx274->supplies); + if (ret) { + dev_err(&imx274->client->dev, + "Failed to enable regulators: %d\n", ret); + goto fail_reg; + } + + usleep_range(1, 2); + imx274_reset(imx274, 1); + + return 0; + +fail_reg: + regulator_bulk_disable(IMX274_NUM_SUPPLIES, imx274->supplies); + 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); + + imx274_reset(imx274, 0); + + regulator_bulk_disable(IMX274_NUM_SUPPLIES, imx274->supplies); + + clk_disable_unprepare(imx274->inck); + + return 0; +} + +static int imx274_get_regulators(struct device *dev, struct stimx274 *imx274) +{ + int i; + + for (i = 0; i < IMX274_NUM_SUPPLIES; i++) + imx274->supplies[i].supply = imx274_supply_names[i]; + + return devm_regulator_bulk_get(dev, IMX274_NUM_SUPPLIES, + imx274->supplies); +} + /** * imx274_s_ctrl - This is used to set the imx274 V4L2 controls * @ctrl: V4L2 control to be set @@ -781,6 +865,9 @@ static int imx274_s_ctrl(struct v4l2_ctrl *ctrl) struct stimx274 *imx274 = to_imx274(sd); int ret = -EINVAL; + if (!pm_runtime_get_if_in_use(&imx274->client->dev)) + return 0; + dev_dbg(&imx274->client->dev, "%s : s_ctrl: %s, value: %d\n", __func__, ctrl->name, ctrl->val); @@ -811,6 +898,8 @@ static int imx274_s_ctrl(struct v4l2_ctrl *ctrl) break; } + pm_runtime_put(&imx274->client->dev); + return ret; } @@ -1327,6 +1416,13 @@ static int imx274_s_stream(struct v4l2_subdev *sd, int on) mutex_lock(&imx274->lock); if (on) { + ret = pm_runtime_get_sync(&imx274->client->dev); + if (ret < 0) { + pm_runtime_put_noidle(&imx274->client->dev); + mutex_unlock(&imx274->lock); + return ret; + } + /* load mode registers */ ret = imx274_mode_regs(imx274); if (ret) @@ -1362,6 +1458,7 @@ static int imx274_s_stream(struct v4l2_subdev *sd, int on) ret = imx274_write_table(imx274, imx274_stop); if (ret) goto fail; + pm_runtime_put(&imx274->client->dev); } mutex_unlock(&imx274->lock); @@ -1369,6 +1466,7 @@ static int imx274_s_stream(struct v4l2_subdev *sd, int on) return 0; fail: + pm_runtime_put(&imx274->client->dev); mutex_unlock(&imx274->lock); dev_err(&imx274->client->dev, "s_stream failed\n"); return ret; @@ -1834,6 +1932,14 @@ 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; @@ -1881,15 +1987,23 @@ 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; + } + + pm_runtime_set_active(&client->dev); + pm_runtime_enable(&client->dev); /* 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_disable_rpm; } imx274->ctrls.handler.lock = &imx274->lock; @@ -1951,11 +2065,16 @@ static int imx274_probe(struct i2c_client *client) goto err_ctrls; } + pm_runtime_idle(&client->dev); + dev_info(&client->dev, "imx274 : imx274 probe success !\n"); return 0; err_ctrls: v4l2_ctrl_handler_free(&imx274->ctrls.handler); +err_disable_rpm: + pm_runtime_disable(&client->dev); + pm_runtime_set_suspended(&client->dev); err_me: media_entity_cleanup(&sd->entity); err_regmap: @@ -1968,19 +2087,45 @@ static int imx274_remove(struct i2c_client *client) struct v4l2_subdev *sd = i2c_get_clientdata(client); struct stimx274 *imx274 = to_imx274(sd); + pm_runtime_get_sync(&imx274->client->dev); + /* stop stream */ imx274_write_table(imx274, imx274_stop); v4l2_async_unregister_subdev(sd); v4l2_ctrl_handler_free(&imx274->ctrls.handler); + + pm_runtime_put(&client->dev); + pm_runtime_disable(&client->dev); + pm_runtime_set_suspended(&client->dev); + media_entity_cleanup(&sd->entity); mutex_destroy(&imx274->lock); return 0; } +static int __maybe_unused imx274_runtime_suspend(struct device *dev) +{ + struct i2c_client *client = to_i2c_client(dev); + + return imx274_power_off(&client->dev); +} + +static int __maybe_unused imx274_runtime_resume(struct device *dev) +{ + struct i2c_client *client = to_i2c_client(dev); + + return imx274_power_on(&client->dev); +} + +static const struct dev_pm_ops imx274_pm_ops = { + SET_RUNTIME_PM_OPS(imx274_runtime_suspend, imx274_runtime_resume, NULL) +}; + static struct i2c_driver imx274_i2c_driver = { .driver = { .name = DRIVER_NAME, + .pm = &imx274_pm_ops, .of_match_table = imx274_of_id_table, }, .probe_new = imx274_probe,