From nobody Mon Feb 9 08:32:50 2026 Received: from fhigh-a3-smtp.messagingengine.com (fhigh-a3-smtp.messagingengine.com [103.168.172.154]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id DB9E4328624; Fri, 19 Dec 2025 14:08:32 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=103.168.172.154 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1766153317; cv=none; b=S87zgRrybdWIvmCx43HXbj1EJFO/Ayaij5CeMSgjGz6RVQSJZso7Nw67yGnR4fjzjxvyPFaRuMLjgLOWBd5/t0YiPak7GwtDp1LJQuazFDjh/wuzfONrM9t+6H0dIDnHCY3j33eR1NaLqurRKKrUyTHVDugKfjDnNj3r9R5IaCs= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1766153317; c=relaxed/simple; bh=UaRehn1/rOkl/aL6j5i1dFkeHFNgoTAIpiXnnJHp3bw=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=JUJsmz2D3eMPAGyrgcQY3rL/ehcNMotvzIBx3MTVMIATFu8lg6NV3Zz79DcuZCjDj4Hr/OfHfHRx9ATRq3HuXxKs3OQk8JACaG9+RE6u39WTGIYysJpSY6IjA/iSK4o+c3o2n2YExn4E7wdWIe6BrVdvm63JtY0JPq41MbIOQFk= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=schnwalter.eu; spf=pass smtp.mailfrom=schnwalter.eu; dkim=pass (2048-bit key) header.d=schnwalter.eu header.i=@schnwalter.eu header.b=ovw3Blnr; dkim=pass (2048-bit key) header.d=messagingengine.com header.i=@messagingengine.com header.b=gr8pg5d9; arc=none smtp.client-ip=103.168.172.154 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=schnwalter.eu Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=schnwalter.eu Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=schnwalter.eu header.i=@schnwalter.eu header.b="ovw3Blnr"; dkim=pass (2048-bit key) header.d=messagingengine.com header.i=@messagingengine.com header.b="gr8pg5d9" Received: from phl-compute-05.internal (phl-compute-05.internal [10.202.2.45]) by mailfhigh.phl.internal (Postfix) with ESMTP id D1CFA14000B2; Fri, 19 Dec 2025 09:08:30 -0500 (EST) Received: from phl-frontend-03 ([10.202.2.162]) by phl-compute-05.internal (MEProxy); Fri, 19 Dec 2025 09:08:30 -0500 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=schnwalter.eu; h=cc:cc:content-transfer-encoding:content-type:content-type :date:date:from:from:in-reply-to:in-reply-to:message-id :mime-version:references:reply-to:subject:subject:to:to; s=fm2; t=1766153310; x=1766239710; bh=qb5gVRO9DfUFU0aQRCIg+7QiRU/KOee2 e9hSIVhT7xM=; b=ovw3BlnrGec8dKb6e5e8ibr3ue6gqgXGVHDwMeUjw/ztFMnM q1RCMAv4P/oEL4QMYo4Y1h7U6N4ZBnDSBZl5rvKodhZgIXoiWIQYGhD7tKqItgLq byOp88agOBRXlpbfhaaKecIFtXgr/l4a8Ow793IQYeS8g6tMWQY2EkjhKmaICmNR ivszEL3gzvX2zp4rHQfQ7C+fsO6RRaAuM1XZ/DusFoqPz+WvVMtG+PQpRagJxitQ bdkuE9FzsMnER3T4txKQB6qwJkE9QDQTY9D6yBVSO0OUQEy7V4xNQyoAcyG1/xwV 9tFBD4MKTaBRN4q8N7LPmLX2Y1F8KAmw1JaG5w== DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d= messagingengine.com; h=cc:cc:content-transfer-encoding :content-type:content-type:date:date:feedback-id:feedback-id :from:from:in-reply-to:in-reply-to:message-id:mime-version :references:reply-to:subject:subject:to:to:x-me-proxy :x-me-sender:x-me-sender:x-sasl-enc; s=fm1; t=1766153310; x= 1766239710; bh=qb5gVRO9DfUFU0aQRCIg+7QiRU/KOee2e9hSIVhT7xM=; b=g r8pg5d9fxni3WLVbb96i6m1WU9vvzCFpdS7PYB8lOFTbLOz6Gv1fGDsCB68GEpX5 HuMbEdc6Dxa7b+sEE1b0qD5tkVxdbOp90YXXtJEayqVw2i1byszSGWcPVgYmXHNQ Unx6XRn8W9PReFcRZ+VLr8l61VB2u9bwSIrssrETYaWHky5mDsIRtxwcs7NCpxNm xttUZeXblrBN/n6HPrJPsy11K2orEVFNBIv1eG5A5B+VLTkuF1TEA4KNDkw1z6cK +rsKMSN1QGN/uhr8Ai0s8zZ9CZF5yDypS7eb47WFNafi0a5M46VWG08I/yr7Aqux JZlCqcP/WXVILp/XpCEfA== X-ME-Sender: X-ME-Received: X-ME-Proxy-Cause: gggruggvucftvghtrhhoucdtuddrgeefgedrtddtgdegkeehtdcutefuodetggdotefrod ftvfcurfhrohhfihhlvgemucfhrghsthforghilhdpuffrtefokffrpgfnqfghnecuuegr ihhlohhuthemuceftddtnecusecvtfgvtghiphhivghnthhsucdlqddutddtmdenucfjug hrpefhfffugggtgffkfhgjvfevofesthejredtredtjeenucfhrhhomhephggrlhhtvghr ucghvghrnhgvrhcuufgthhhnvghiuggvrhcuoegtohhnthgrtghtsehstghhnhifrghlth gvrhdrvghuqeenucggtffrrghtthgvrhhnpefhtdehhfegheetjedthfeigeeltdeghfei udeikeeiffekuddtlefffeekheelfeenucffohhmrghinhepuggvvhhitggvthhrvggvrd horhhgpdhlihhnuhigthhvrdhorhhgnecuvehluhhsthgvrhfuihiivgeptdenucfrrghr rghmpehmrghilhhfrhhomheptghonhhtrggtthesshgthhhnfigrlhhtvghrrdgvuhdpnh gspghrtghpthhtohepuddtpdhmohguvgepshhmthhpohhuthdprhgtphhtthhopegtohhn thgrtghtsehstghhnhifrghlthgvrhdrvghupdhrtghpthhtoheprhhosghhsehkvghrnh gvlhdrohhrghdprhgtphhtthhopeguvghvihgtvghtrhgvvgesvhhgvghrrdhkvghrnhgv lhdrohhrghdprhgtphhtthhopegtohhnohhrodgutheskhgvrhhnvghlrdhorhhgpdhrtg hpthhtohepkhhriihkodgutheskhgvrhhnvghlrdhorhhgpdhrtghpthhtohepmhgthhgv hhgrsgeskhgvrhhnvghlrdhorhhgpdhrtghpthhtoheplhhinhhugidqkhgvrhhnvghlse hvghgvrhdrkhgvrhhnvghlrdhorhhgpdhrtghpthhtohepjhgrtghophhordhmohhnughi sehiuggvrghsohhnsghorghrugdrtghomhdprhgtphhtthhopehsrghkrghrihdrrghilh husheslhhinhhugidrihhnthgvlhdrtghomh X-ME-Proxy: Feedback-ID: i455149b6:Fastmail Received: by mail.messagingengine.com (Postfix) with ESMTPA; Fri, 19 Dec 2025 09:08:28 -0500 (EST) From: Walter Werner Schneider Date: Fri, 19 Dec 2025 16:08:08 +0200 Subject: [PATCH v3 1/2] dt-bindings: media: i2c: Add ov2732 image sensor Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable Message-Id: <20251219-ov2732-driver-v3-1-579d175e929e@schnwalter.eu> References: <20251219-ov2732-driver-v3-0-579d175e929e@schnwalter.eu> In-Reply-To: <20251219-ov2732-driver-v3-0-579d175e929e@schnwalter.eu> To: linux-media@vger.kernel.org, Jacopo Mondi , Mauro Carvalho Chehab , Rob Herring , Krzysztof Kozlowski , Conor Dooley , Sakari Ailus Cc: devicetree@vger.kernel.org, linux-kernel@vger.kernel.org, Walter Werner Schneider X-Mailer: b4 0.14.2 X-Developer-Signature: v=1; a=ed25519-sha256; t=1766153306; l=3957; i=contact@schnwalter.eu; s=20251106; h=from:subject:message-id; bh=UaRehn1/rOkl/aL6j5i1dFkeHFNgoTAIpiXnnJHp3bw=; b=UXZKr9qm8jtwGXxox60gd8Dxkf1qTozMU/+a4Y/mmhonqVvlHk+O7VXtx0EYXjGdeiff7YbR6 4RhREpy8fRcDKUCjrFgAAMqe1r1Tr/igQ2dY6HFYv7QYoy8870wsh+S X-Developer-Key: i=contact@schnwalter.eu; a=ed25519; pk=OoafUGtB7zQJLYhKA7ALCjqddXAaem/uP/eb3GGNkTI= Add bindings for OmniVision OV2732 image sensor. Signed-off-by: Walter Werner Schneider Reviewed-by: Krzysztof Kozlowski --- .../devicetree/bindings/media/i2c/ovti,ov2732.yaml | 108 +++++++++++++++++= ++++ MAINTAINERS | 6 ++ 2 files changed, 114 insertions(+) diff --git a/Documentation/devicetree/bindings/media/i2c/ovti,ov2732.yaml b= /Documentation/devicetree/bindings/media/i2c/ovti,ov2732.yaml new file mode 100644 index 0000000000000000000000000000000000000000..57041d1dc012b88db4bf3eefbd3= d1ee96fde777c --- /dev/null +++ b/Documentation/devicetree/bindings/media/i2c/ovti,ov2732.yaml @@ -0,0 +1,108 @@ +# SPDX-License-Identifier: (GPL-2.0 OR BSD-2-Clause) +%YAML 1.2 +--- +$id: http://devicetree.org/schemas/media/i2c/ovti,ov2732.yaml# +$schema: http://devicetree.org/meta-schemas/core.yaml# + +title: OmniVision OV2732 Image Sensor + +maintainers: + - Walter Werner Schneider + +description: + The OmniVision OV2732 is a 2MP (1920x1080) color CMOS image sensor contr= olled + through an I2C-compatible SCCB bus. + +properties: + compatible: + const: ovti,ov2732 + + reg: + maxItems: 1 + + clocks: + items: + - description: XVCLK clock + + clock-names: + const: xvclk + + avdd-supply: + description: Analog Domain Power Supply + + dovdd-supply: + description: I/O Domain Power Supply + + dvdd-supply: + description: Digital Domain Power Supply + + powerdown-gpios: + maxItems: 1 + description: Reference to the GPIO connected to the pwdn pin. Active l= ow. + + reset-gpios: + maxItems: 1 + description: Reference to the GPIO connected to the reset pin. Active = low. + + port: + description: MIPI CSI-2 transmitter port + $ref: /schemas/graph.yaml#/$defs/port-base + additionalProperties: false + + properties: + endpoint: + $ref: /schemas/media/video-interfaces.yaml# + unevaluatedProperties: false + + properties: + data-lanes: + items: + - const: 1 + - const: 2 + + required: + - data-lanes + - link-frequencies + +required: + - compatible + - reg + - clocks + - clock-names + - avdd-supply + - dovdd-supply + - dvdd-supply + - port + +additionalProperties: false + +examples: + - | + #include + + i2c { + #address-cells =3D <1>; + #size-cells =3D <0>; + + ov2732: camera@36 { + compatible =3D "ovti,ov2732"; + reg =3D <0x36>; + clocks =3D <&ov2732_clk>; + clock-names =3D "xvclk"; + + avdd-supply =3D <&ov2732_avdd>; + dovdd-supply =3D <&ov2732_dovdd>; + dvdd-supply =3D <&ov2732_dvdd>; + + powerdown-gpios =3D <&gpio0 13 GPIO_ACTIVE_LOW>; + reset-gpios =3D <&gpio0 8 GPIO_ACTIVE_LOW>; + + port { + camera_out: endpoint { + data-lanes =3D <1 2>; + link-frequencies =3D /bits/ 64 <360000000>; + remote-endpoint =3D <&mipi_in_camera>; + }; + }; + }; + }; diff --git a/MAINTAINERS b/MAINTAINERS index 5b11839cba9de1e9e43f63787578edd8c429ca39..231d5b8df21bc5f3dc6ee5d765e= d4027c9772f9a 100644 --- a/MAINTAINERS +++ b/MAINTAINERS @@ -19308,6 +19308,12 @@ T: git git://linuxtv.org/media.git F: Documentation/devicetree/bindings/media/i2c/ovti,ov2685.yaml F: drivers/media/i2c/ov2685.c =20 +OMNIVISION OV2732 SENSOR DRIVER +M: Walter Werner Schneider +L: linux-media@vger.kernel.org +S: Maintained +F: Documentation/devicetree/bindings/media/i2c/ovti,ov2732.yaml + OMNIVISION OV2735 SENSOR DRIVER M: Hardevsinh Palaniya M: Himanshu Bhavani --=20 2.51.1 From nobody Mon Feb 9 08:32:50 2026 Received: from fhigh-a3-smtp.messagingengine.com (fhigh-a3-smtp.messagingengine.com [103.168.172.154]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 2560B328B5C; Fri, 19 Dec 2025 14:08:34 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=103.168.172.154 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1766153319; cv=none; b=QBPf+tpgqX3QjqfiYsOGDFeAPlIQTfo8cbY4BSHhGAqn3FyHauzdWDSdoxGa80AiSb6qHsG2l/FbtY1CGuQUtfeBFaUgvEYeRPLN0YoIK+AbVCn4gdkY8dB8YhrM1Fy+8ZshX0Xiajeic45QNvlckCaxsXgWBH3LdPJ62X3d4s8= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1766153319; c=relaxed/simple; bh=bY5zJarp6HcDK5w+FWBFQcI83oeVIIZS53ekk05ZJ98=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=srfDq85L9fT40xsKpLDc579wYKjxjbLC8z/yu1OI09I3/iQedsMT0EWoEcM7dlDpZ7tglQ0bLR9qNXZrixQRmSJGU+tGKFsBY9offiVnGkhSZl+WuQu8p0f0oApiEKdRevsLoRAheNXZOnZ3Vlie94H4lI7YRu2G+7ZS10EM+rw= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=schnwalter.eu; spf=pass smtp.mailfrom=schnwalter.eu; dkim=pass (2048-bit key) header.d=schnwalter.eu header.i=@schnwalter.eu header.b=W/nuY7Fc; dkim=pass (2048-bit key) header.d=messagingengine.com header.i=@messagingengine.com header.b=U1R+KoVZ; arc=none smtp.client-ip=103.168.172.154 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=schnwalter.eu Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=schnwalter.eu Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=schnwalter.eu header.i=@schnwalter.eu header.b="W/nuY7Fc"; dkim=pass (2048-bit key) header.d=messagingengine.com header.i=@messagingengine.com header.b="U1R+KoVZ" Received: from phl-compute-01.internal (phl-compute-01.internal [10.202.2.41]) by mailfhigh.phl.internal (Postfix) with ESMTP id 2532514000B3; Fri, 19 Dec 2025 09:08:33 -0500 (EST) Received: from phl-frontend-03 ([10.202.2.162]) by phl-compute-01.internal (MEProxy); Fri, 19 Dec 2025 09:08:33 -0500 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=schnwalter.eu; h=cc:cc:content-transfer-encoding:content-type:content-type :date:date:from:from:in-reply-to:in-reply-to:message-id :mime-version:references:reply-to:subject:subject:to:to; s=fm2; t=1766153313; x=1766239713; bh=wnDsIMt3SnLK2dKHDUSmTCKY+xojhAVq QoegUpGoLVc=; b=W/nuY7FcLEUa68aHpDlp4e0siQEDqeXZC/Vdfj1fGFG/PjfU SK5iw7nd77DqfTensDVdEacg9HFfdEBm6b+dlG8ldMRUuvaPSiWMwg3imiB7BFP3 JkT3nzTmthiILgNXQFA0iPXX6JiEpHTtxM/Wz2aucV+OROrT1NTvx4KH/SgQtsoM 9wSeeVPuwQ50aFLKGmjnWt8ZS+31LPwu22lZpaEvZpUeIoDDOGcGPa7OVKt92U9E 7bq2IEvfzLRvcnYSCE+2cxSNr31Wy3XEzXYV4brBefMwz1hsJxj0l63rqCLL/YVL yWVFC8+m/AEnOq4d7kmUk7T3s9FODib0+97aNw== DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d= messagingengine.com; h=cc:cc:content-transfer-encoding :content-type:content-type:date:date:feedback-id:feedback-id :from:from:in-reply-to:in-reply-to:message-id:mime-version :references:reply-to:subject:subject:to:to:x-me-proxy :x-me-sender:x-me-sender:x-sasl-enc; s=fm1; t=1766153313; x= 1766239713; bh=wnDsIMt3SnLK2dKHDUSmTCKY+xojhAVqQoegUpGoLVc=; b=U 1R+KoVZ7xRPWTLpQozNuqq1b4aIJ2p/XS0C6XYsWj61VyKyBRgitpVK06i/C+muE ib9HJGQ+jbs73buEoNyapEayYs/TQSEwqYyqbn0vQ9ynfZLSqjB8znUd2hvNjFj0 S1jxEm11i5jgyc4IbVaE2NjFjGcEtBM5qUssdsTkvPq0o7XOUiBGGwhUG2WA/py5 q3Vqvtf5CfdAeE4FJW5Rn4maH+IP1pPlQPInLdzfKtPDv3nJDYEO8tqcqoFaPqCr 7hh/qNoa6WnpHg+4IwdpQ/MyojoNhCeiTBRQJA5IDctpzTZ8WrwxdMkRnsOz462W 9/A1zzrszrjBGCDLAdiBA== X-ME-Sender: X-ME-Received: X-ME-Proxy-Cause: gggruggvucftvghtrhhoucdtuddrgeefgedrtddtgdegkeehtdcutefuodetggdotefrod ftvfcurfhrohhfihhlvgemucfhrghsthforghilhdpuffrtefokffrpgfnqfghnecuuegr ihhlohhuthemuceftddtnecusecvtfgvtghiphhivghnthhsucdlqddutddtmdenucfjug hrpefhfffugggtgffkfhgjvfevofesthejredtredtjeenucfhrhhomhephggrlhhtvghr ucghvghrnhgvrhcuufgthhhnvghiuggvrhcuoegtohhnthgrtghtsehstghhnhifrghlth gvrhdrvghuqeenucggtffrrghtthgvrhhnpedtvedtveeuhfeivefhuefhveelheduvdeg hfefffeggfdugeekteelveegvdevveenucevlhhushhtvghrufhiiigvpedtnecurfgrrh grmhepmhgrihhlfhhrohhmpegtohhnthgrtghtsehstghhnhifrghlthgvrhdrvghupdhn sggprhgtphhtthhopedutddpmhhouggvpehsmhhtphhouhhtpdhrtghpthhtoheptghonh htrggtthesshgthhhnfigrlhhtvghrrdgvuhdprhgtphhtthhopehrohgshheskhgvrhhn vghlrdhorhhgpdhrtghpthhtohepuggvvhhitggvthhrvggvsehvghgvrhdrkhgvrhhnvg hlrdhorhhgpdhrtghpthhtoheptghonhhorhdoughtsehkvghrnhgvlhdrohhrghdprhgt phhtthhopehkrhiikhdoughtsehkvghrnhgvlhdrohhrghdprhgtphhtthhopehmtghhvg hhrggssehkvghrnhgvlhdrohhrghdprhgtphhtthhopehlihhnuhigqdhkvghrnhgvlhes vhhgvghrrdhkvghrnhgvlhdrohhrghdprhgtphhtthhopehjrggtohhpohdrmhhonhguih esihguvggrshhonhgsohgrrhgurdgtohhmpdhrtghpthhtohepshgrkhgrrhhirdgrihhl uhhssehlihhnuhigrdhinhhtvghlrdgtohhm X-ME-Proxy: Feedback-ID: i455149b6:Fastmail Received: by mail.messagingengine.com (Postfix) with ESMTPA; Fri, 19 Dec 2025 09:08:30 -0500 (EST) From: Walter Werner Schneider Date: Fri, 19 Dec 2025 16:08:09 +0200 Subject: [PATCH v3 2/2] media: i2c: Add ov2732 image sensor driver Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable Message-Id: <20251219-ov2732-driver-v3-2-579d175e929e@schnwalter.eu> References: <20251219-ov2732-driver-v3-0-579d175e929e@schnwalter.eu> In-Reply-To: <20251219-ov2732-driver-v3-0-579d175e929e@schnwalter.eu> To: linux-media@vger.kernel.org, Jacopo Mondi , Mauro Carvalho Chehab , Rob Herring , Krzysztof Kozlowski , Conor Dooley , Sakari Ailus Cc: devicetree@vger.kernel.org, linux-kernel@vger.kernel.org, Walter Werner Schneider X-Mailer: b4 0.14.2 X-Developer-Signature: v=1; a=ed25519-sha256; t=1766153306; l=25102; i=contact@schnwalter.eu; s=20251106; h=from:subject:message-id; bh=bY5zJarp6HcDK5w+FWBFQcI83oeVIIZS53ekk05ZJ98=; b=ZIXnVmQftzh31CreY72Oe2VwLtjjoroQhlOygws3fasZevRzNAdDVqNb54ubrvv311QR8XCpe 5Savay0/uL7DwJ9xZr28coetMHgYn2BDT5aPShqA1icaH//ZyIiDLnf X-Developer-Key: i=contact@schnwalter.eu; a=ed25519; pk=OoafUGtB7zQJLYhKA7ALCjqddXAaem/uP/eb3GGNkTI= Add a V4L2 subdevice driver for the Omnivision OV2732 sensor. The OV2732 is a 1/4" color CMOS 1080p (1920x1080) HD image sensor with programmable controls like: gain, exposure, frame rate, image and windowing size, horizontal mirror, vertical flip, cropping. Signed-off-by: Walter Werner Schneider Reviewed-by: Jacopo Mondi --- MAINTAINERS | 1 + drivers/media/i2c/Kconfig | 13 + drivers/media/i2c/Makefile | 1 + drivers/media/i2c/ov2732.c | 787 +++++++++++++++++++++++++++++++++++++++++= ++++ 4 files changed, 802 insertions(+) diff --git a/MAINTAINERS b/MAINTAINERS index 231d5b8df21bc5f3dc6ee5d765ed4027c9772f9a..aa94dd27c9457c4f73d28a6c13b= aff929a816a7f 100644 --- a/MAINTAINERS +++ b/MAINTAINERS @@ -19313,6 +19313,7 @@ M: Walter Werner Schneider L: linux-media@vger.kernel.org S: Maintained F: Documentation/devicetree/bindings/media/i2c/ovti,ov2732.yaml +F: drivers/media/i2c/ov2732.c =20 OMNIVISION OV2735 SENSOR DRIVER M: Hardevsinh Palaniya diff --git a/drivers/media/i2c/Kconfig b/drivers/media/i2c/Kconfig index 4b4db8c4f49657e19018535927eb41f7ad2a4f80..9dc60091c99b18d034d78efda4e= ff501dedc5d33 100644 --- a/drivers/media/i2c/Kconfig +++ b/drivers/media/i2c/Kconfig @@ -477,6 +477,19 @@ config VIDEO_OV2685 To compile this driver as a module, choose M here: the module will be called ov2685. =20 +config VIDEO_OV2732 + tristate "OmniVision OV2732 sensor support" + depends on OF + select MEDIA_CONTROLLER + select V4L2_CCI_I2C + select VIDEO_V4L2_SUBDEV_API + help + This is a Video4Linux2 sensor driver for the OmniVision + OV2732 camera. + + To compile this driver as a module, choose M here: the + module will be called ov2732. + config VIDEO_OV2735 tristate "OmniVision OV2735 sensor support" select V4L2_CCI_I2C diff --git a/drivers/media/i2c/Makefile b/drivers/media/i2c/Makefile index c5f17602454ffaa698a925f508244a7ddbb60e0f..d6435ea5cc12fdada181bf3e288= 5ceff4d5a23fa 100644 --- a/drivers/media/i2c/Makefile +++ b/drivers/media/i2c/Makefile @@ -96,6 +96,7 @@ obj-$(CONFIG_VIDEO_OV2640) +=3D ov2640.o obj-$(CONFIG_VIDEO_OV2659) +=3D ov2659.o obj-$(CONFIG_VIDEO_OV2680) +=3D ov2680.o obj-$(CONFIG_VIDEO_OV2685) +=3D ov2685.o +obj-$(CONFIG_VIDEO_OV2732) +=3D ov2732.o obj-$(CONFIG_VIDEO_OV2735) +=3D ov2735.o obj-$(CONFIG_VIDEO_OV2740) +=3D ov2740.o obj-$(CONFIG_VIDEO_OV4689) +=3D ov4689.o diff --git a/drivers/media/i2c/ov2732.c b/drivers/media/i2c/ov2732.c new file mode 100644 index 0000000000000000000000000000000000000000..5029136df2e5768391d3a947022= d7e44aeb55dbc --- /dev/null +++ b/drivers/media/i2c/ov2732.c @@ -0,0 +1,787 @@ +// SPDX-License-Identifier: GPL-2.0 +/* + * ov2732 driver + * + * Copyright (C) 2017 Fuzhou Rockchip Electronics Co., Ltd. + * Copyright (C) 2025 Walter Werner Schneider + */ + +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include + +#define OV2732_LANES 2 +#define OV2732_BITS_PER_SAMPLE 10 +#define OV2732_LINK_FREQ_DEFAULT 360000000 +#define OV2732_XVCLK_FREQ 24000000 +#define OV2732_PIXEL_RATE \ + (OV2732_LINK_FREQ_DEFAULT * 2 * OV2732_LANES / OV2732_BITS_PER_SAMPLE) +#define OV2732_NATIVE_WIDTH 1920U +#define OV2732_NATIVE_HEIGHT 1080U + +/* Delay from power up to the first SCCB transaction. */ +#define OV2732_POWER_UP_DELAY_CYCLES 8192 +/* Delay from the last SCCB transaction to power down. */ +#define OV2732_POWER_DOWN_DELAY_CYCLES 512 +#define OV2732_DELAY_US(cycles) \ + (DIV_ROUND_UP((cycles), OV2732_XVCLK_FREQ / USEC_PER_SEC)) + +#define OV2732_REG_CHIP_ID CCI_REG24(0x300a) +#define OV2732_CHIP_ID 0x002732 + +#define OV2732_REG_MODE_SELECT CCI_REG8(0x0100) +#define OV2732_MODE_STANDBY 0x00 +#define OV2732_MODE_STREAMING 0x01 + +#define OV2732_REG_ANALOGUE_GAIN CCI_REG24(0x3508) +#define OV2732_REG_DIGITAL_GAIN CCI_REG24(0x350a) +#define OV2732_REG_EXPOSURE CCI_REG24(0x3500) +#define OV2732_REG_HTS CCI_REG16(0x380c) +#define OV2732_REG_VTS CCI_REG16(0x380e) +#define OV2732_ANALOGUE_GAIN_MIN 0x80 +#define OV2732_ANALOGUE_GAIN_MAX 0x3fff +#define OV2732_ANALOGUE_GAIN_DEFAULT 0x80 +#define OV2732_DIGITAL_GAIN_MIN 0x00 +#define OV2732_DIGITAL_GAIN_MAX 0x1fff +#define OV2732_DIGITAL_GAIN_DEFAULT 0x0400 +#define OV2732_EXPOSURE_DEFAULT 0x40 +#define OV2732_EXPOSURE_MIN 0x10 +#define OV2732_EXPOSURE_OFFSET 4 +#define OV2732_HBLANK_DEFAULT 0x0068 +#define OV2732_VTS_MAX 0x7fff + +#define OV2732_REG_TEST_PATTERN CCI_REG8(0x5080) +#define OV2732_TEST_PATTERN_DISABLE 0x00 +#define OV2732_TEST_PATTERN_BAR1 0x80 +#define OV2732_TEST_PATTERN_BAR2 0x84 +#define OV2732_TEST_PATTERN_BAR3 0x88 +#define OV2732_TEST_PATTERN_BAR4 0x8c + +static const char * const ov2732_supply_names[] =3D { + "avdd", /* Analog power */ + "dovdd", /* Digital I/O power */ + "dvdd", /* Digital core power */ +}; + +#define OV2732_NUM_SUPPLIES ARRAY_SIZE(ov2732_supply_names) + +static const struct cci_reg_sequence ov2732_common_regs[] =3D { + /* PLL control, reset all registers. */ + { CCI_REG8(0x0103), 0x01 }, + + /* Analog control. */ + { CCI_REG8(0x3600), 0x55 }, + { CCI_REG8(0x3601), 0x52 }, + { CCI_REG8(0x3612), 0xb5 }, + { CCI_REG8(0x3613), 0xb3 }, + { CCI_REG8(0x3616), 0x83 }, + { CCI_REG8(0x3621), 0x00 }, + { CCI_REG8(0x3624), 0x06 }, + { CCI_REG8(0x3642), 0x88 }, + { CCI_REG8(0x3660), 0x00 }, + { CCI_REG8(0x3661), 0x00 }, + { CCI_REG8(0x366a), 0x64 }, + { CCI_REG8(0x366c), 0x00 }, + { CCI_REG8(0x366e), 0xff }, + { CCI_REG8(0x366f), 0xff }, + { CCI_REG8(0x3677), 0x11 }, + { CCI_REG8(0x3678), 0x11 }, + { CCI_REG8(0x3679), 0x0c }, + { CCI_REG8(0x3680), 0xff }, + { CCI_REG8(0x3681), 0x16 }, + { CCI_REG8(0x3682), 0x16 }, + { CCI_REG8(0x3683), 0x90 }, + { CCI_REG8(0x3684), 0x90 }, + + /* ADC sync control. */ + { CCI_REG8(0x4503), 0x00 }, + { CCI_REG8(0x4508), 0x14 }, + { CCI_REG8(0x450a), 0x00 }, + { CCI_REG8(0x450b), 0x40 }, + + /* ISP control, enable: WIN, DPC & ISP. */ + { CCI_REG8(0x5000), 0xa1 }, +}; + +struct ov2732_mode { + u32 width; + u32 height; + u32 vts; +}; + +static const struct ov2732_mode supported_modes[] =3D { + { + .width =3D 1920, + .height =3D 1080, + .vts =3D 1184, + }, +}; + +struct ov2732 { + struct device *dev; + struct regmap *regmap; + + struct media_pad pad; + struct v4l2_subdev sd; + struct v4l2_ctrl_handler ctrl_handler; + struct v4l2_ctrl *hblank; + struct v4l2_ctrl *vblank; + struct v4l2_ctrl *exposure; + + struct clk *xvclk; + u32 xvclk_freq; + struct gpio_desc *powerdown_gpio; + struct gpio_desc *reset_gpio; + struct regulator_bulk_data supplies[OV2732_NUM_SUPPLIES]; +}; + +#define to_ov2732(_sd) container_of(_sd, struct ov2732, sd) + +static const s64 link_freq_menu_items[] =3D { + OV2732_LINK_FREQ_DEFAULT, +}; + +static const char * const ov2732_test_pattern_menu[] =3D { + "Disabled", + "Vertical Color Bar Type 1", + "Vertical Color Bar Type 2", + "Vertical Color Bar Type 3", + "Vertical Color Bar Type 4", +}; + +static const int ov2732_test_pattern_val[] =3D { + OV2732_TEST_PATTERN_DISABLE, + OV2732_TEST_PATTERN_BAR1, + OV2732_TEST_PATTERN_BAR2, + OV2732_TEST_PATTERN_BAR3, + OV2732_TEST_PATTERN_BAR4, +}; + +static int ov2732_power_on(struct device *dev) +{ + struct v4l2_subdev *sd =3D dev_get_drvdata(dev); + struct ov2732 *ov2732 =3D to_ov2732(sd); + int ret; + + ret =3D regulator_bulk_enable(OV2732_NUM_SUPPLIES, ov2732->supplies); + if (ret) { + dev_err(dev, "failed to enable regulators\n"); + return ret; + } + + ret =3D clk_prepare_enable(ov2732->xvclk); + if (ret) { + dev_err(dev, "failed to enable clock\n"); + goto reg_off; + } + + /* Wait 10ms before power up, as per datasheet. */ + fsleep(10 * USEC_PER_MSEC); + + gpiod_set_value_cansleep(ov2732->reset_gpio, 0); + gpiod_set_value_cansleep(ov2732->powerdown_gpio, 0); + + /* Datasheet requires an 8192 cycles wait, but that isn't enough. */ + fsleep(OV2732_DELAY_US(OV2732_POWER_UP_DELAY_CYCLES * 2)); + + return 0; + +reg_off: + regulator_bulk_disable(OV2732_NUM_SUPPLIES, ov2732->supplies); + + return ret; +} + +static int ov2732_power_off(struct device *dev) +{ + struct v4l2_subdev *sd =3D dev_get_drvdata(dev); + struct ov2732 *ov2732 =3D to_ov2732(sd); + + clk_disable_unprepare(ov2732->xvclk); + + /* Wait for 512 cycles as per datasheet. */ + fsleep(OV2732_DELAY_US(OV2732_POWER_DOWN_DELAY_CYCLES)); + + gpiod_set_value_cansleep(ov2732->powerdown_gpio, 1); + gpiod_set_value_cansleep(ov2732->reset_gpio, 1); + + regulator_bulk_disable(OV2732_NUM_SUPPLIES, ov2732->supplies); + + return 0; +} + +static int ov2732_identify_chip(struct ov2732 *ov2732) +{ + struct i2c_client *client =3D v4l2_get_subdevdata(&ov2732->sd); + int ret; + u64 val; + + ret =3D cci_read(ov2732->regmap, OV2732_REG_CHIP_ID, &val, NULL); + if (ret) + return dev_err_probe(&client->dev, ret, + "failed to read chip id\n"); + + if (val !=3D OV2732_CHIP_ID) + return dev_err_probe(&client->dev, -ENODEV, + "chip id mismatch: %x!=3D%llx\n", + OV2732_CHIP_ID, val); + + return 0; +} + +static int ov2732_enum_mbus_code(struct v4l2_subdev *sd, + struct v4l2_subdev_state *state, + struct v4l2_subdev_mbus_code_enum *code) +{ + if (code->index !=3D 0) + return -EINVAL; + + code->code =3D MEDIA_BUS_FMT_SBGGR10_1X10; + + return 0; +} + +static int ov2732_enum_frame_size(struct v4l2_subdev *sd, + struct v4l2_subdev_state *state, + struct v4l2_subdev_frame_size_enum *fse) +{ + if (fse->index >=3D ARRAY_SIZE(supported_modes)) + return -EINVAL; + + fse->min_width =3D supported_modes[fse->index].width; + fse->max_width =3D fse->min_width; + fse->min_height =3D supported_modes[fse->index].height; + fse->max_height =3D fse->min_height; + + return 0; +} + +static int ov2732_set_fmt(struct v4l2_subdev *sd, + struct v4l2_subdev_state *state, + struct v4l2_subdev_format *fmt) +{ + struct ov2732 *ov2732 =3D to_ov2732(sd); + const struct ov2732_mode *mode; + s64 vblank_def; + int ret; + + mode =3D v4l2_find_nearest_size(supported_modes, + ARRAY_SIZE(supported_modes), + width, height, + fmt->format.width, fmt->format.height); + + fmt->format.code =3D MEDIA_BUS_FMT_SBGGR10_1X10; + fmt->format.width =3D mode->width; + fmt->format.height =3D mode->height; + fmt->format.field =3D V4L2_FIELD_NONE; + fmt->format.colorspace =3D V4L2_COLORSPACE_RAW; + fmt->format.ycbcr_enc =3D V4L2_YCBCR_ENC_601; + fmt->format.quantization =3D V4L2_QUANTIZATION_FULL_RANGE; + fmt->format.xfer_func =3D V4L2_XFER_FUNC_NONE; + + *v4l2_subdev_state_get_format(state, fmt->pad) =3D fmt->format; + + if (fmt->which =3D=3D V4L2_SUBDEV_FORMAT_TRY) + return 0; + + vblank_def =3D mode->vts - mode->height; + ret =3D __v4l2_ctrl_modify_range(ov2732->vblank, vblank_def, + OV2732_VTS_MAX - mode->height, 1, + vblank_def); + + return ret; +} + +static int ov2732_get_selection(struct v4l2_subdev *sd, + struct v4l2_subdev_state *state, + struct v4l2_subdev_selection *sel) +{ + switch (sel->target) { + case V4L2_SEL_TGT_CROP: + sel->r =3D *v4l2_subdev_state_get_crop(state, 0); + return 0; + + case V4L2_SEL_TGT_NATIVE_SIZE: + case V4L2_SEL_TGT_CROP_DEFAULT: + case V4L2_SEL_TGT_CROP_BOUNDS: + sel->r.top =3D 0; + sel->r.left =3D 0; + sel->r.width =3D OV2732_NATIVE_WIDTH; + sel->r.height =3D OV2732_NATIVE_HEIGHT; + + return 0; + } + + return -EINVAL; +} + +static int ov2732_enable_streams(struct v4l2_subdev *sd, + struct v4l2_subdev_state *state, u32 pad, + u64 streams_mask) +{ + struct ov2732 *ov2732 =3D to_ov2732(sd); + struct i2c_client *client =3D v4l2_get_subdevdata(&ov2732->sd); + int ret; + + ret =3D pm_runtime_resume_and_get(&client->dev); + if (ret < 0) + return ret; + + /* Set stream off register for PLL changes. */ + ret =3D cci_write(ov2732->regmap, OV2732_REG_MODE_SELECT, + OV2732_MODE_STANDBY, NULL); + if (ret) + goto err_put_autosuspend; + + /* Send all registers that are common to all modes */ + ret =3D cci_multi_reg_write(ov2732->regmap, ov2732_common_regs, + ARRAY_SIZE(ov2732_common_regs), NULL); + if (ret) { + dev_err(&client->dev, "failed to init registers\n"); + goto err_put_autosuspend; + } + + /* Apply customized values from user */ + ret =3D __v4l2_ctrl_handler_setup(ov2732->sd.ctrl_handler); + if (ret) + goto err_put_autosuspend; + + /* Set stream on register */ + ret =3D cci_write(ov2732->regmap, OV2732_REG_MODE_SELECT, + OV2732_MODE_STREAMING, NULL); + if (ret) + goto err_put_autosuspend; + + return 0; + +err_put_autosuspend: + pm_runtime_put_autosuspend(&client->dev); + + return ret; +} + +static int ov2732_disable_streams(struct v4l2_subdev *sd, + struct v4l2_subdev_state *state, u32 pad, + u64 streams_mask) +{ + struct ov2732 *ov2732 =3D to_ov2732(sd); + struct i2c_client *client =3D v4l2_get_subdevdata(&ov2732->sd); + int ret; + + /* set stream off register */ + ret =3D cci_write(ov2732->regmap, OV2732_REG_MODE_SELECT, + OV2732_MODE_STANDBY, NULL); + if (ret) + dev_err(&client->dev, "%s failed to set stream\n", __func__); + + /* Wait for 512 cycles as per datasheet. */ + fsleep(OV2732_DELAY_US(OV2732_POWER_DOWN_DELAY_CYCLES)); + + pm_runtime_put_autosuspend(&client->dev); + + return ret; +} + +static const struct v4l2_subdev_video_ops ov2732_video_ops =3D { + .s_stream =3D v4l2_subdev_s_stream_helper, +}; + +static const struct v4l2_subdev_pad_ops ov2732_pad_ops =3D { + .enum_mbus_code =3D ov2732_enum_mbus_code, + .enum_frame_size =3D ov2732_enum_frame_size, + .get_fmt =3D v4l2_subdev_get_fmt, + .set_fmt =3D ov2732_set_fmt, + .get_selection =3D ov2732_get_selection, + .enable_streams =3D ov2732_enable_streams, + .disable_streams =3D ov2732_disable_streams, +}; + +static const struct v4l2_subdev_ops ov2732_subdev_ops =3D { + .video =3D &ov2732_video_ops, + .pad =3D &ov2732_pad_ops, +}; + +static int ov2732_init_state(struct v4l2_subdev *sd, + struct v4l2_subdev_state *sd_state) +{ + struct v4l2_subdev_format fmt =3D { + .which =3D V4L2_SUBDEV_FORMAT_TRY, + .format =3D { + .width =3D 1920, + .height =3D 1080, + .code =3D MEDIA_BUS_FMT_SBGGR10_1X10, + .colorspace =3D V4L2_COLORSPACE_RAW, + .field =3D V4L2_FIELD_NONE, + .quantization =3D V4L2_QUANTIZATION_FULL_RANGE, + .xfer_func =3D V4L2_XFER_FUNC_NONE, + .ycbcr_enc =3D V4L2_YCBCR_ENC_601, + } + }; + + return ov2732_set_fmt(sd, sd_state, &fmt); +} + +static const struct v4l2_subdev_internal_ops ov2732_internal_ops =3D { + .init_state =3D ov2732_init_state, +}; + +static int ov2732_set_ctrl(struct v4l2_ctrl *ctrl) +{ + struct ov2732 *ov2732 =3D + container_of(ctrl->handler, struct ov2732, ctrl_handler); + struct i2c_client *client =3D v4l2_get_subdevdata(&ov2732->sd); + const struct v4l2_mbus_framefmt *format; + struct v4l2_subdev_state *state; + int ret =3D 0; + + state =3D v4l2_subdev_get_locked_active_state(&ov2732->sd); + format =3D v4l2_subdev_state_get_format(state, 0); + + if (ctrl->id =3D=3D V4L2_CID_VBLANK) { + int exposure_max, exposure_def; + + exposure_max =3D format->height + ctrl->val - + OV2732_EXPOSURE_OFFSET; + exposure_def =3D exposure_max; + ret =3D __v4l2_ctrl_modify_range(ov2732->exposure, + OV2732_EXPOSURE_MIN, + exposure_max, + ov2732->exposure->step, + exposure_def); + if (ret) + return ret; + } + + if (pm_runtime_get_if_in_use(&client->dev) =3D=3D 0) + return 0; + + switch (ctrl->id) { + case V4L2_CID_ANALOGUE_GAIN: + cci_write(ov2732->regmap, OV2732_REG_ANALOGUE_GAIN, + ctrl->val, &ret); + break; + case V4L2_CID_DIGITAL_GAIN: + cci_write(ov2732->regmap, OV2732_REG_DIGITAL_GAIN, + ctrl->val, &ret); + break; + case V4L2_CID_EXPOSURE: + cci_write(ov2732->regmap, OV2732_REG_EXPOSURE, + ctrl->val, &ret); + break; + case V4L2_CID_VBLANK: + cci_write(ov2732->regmap, OV2732_REG_VTS, + (format->height + ctrl->val), &ret); + break; + case V4L2_CID_TEST_PATTERN: + cci_write(ov2732->regmap, OV2732_REG_TEST_PATTERN, + ov2732_test_pattern_val[ctrl->val], &ret); + break; + default: + dev_info(&client->dev, + "ctrl(id:0x%x,val:0x%x) is not handled\n", + ctrl->id, ctrl->val); + ret =3D -EINVAL; + break; + } + + pm_runtime_put(&client->dev); + + return ret; +}; + +static const struct v4l2_ctrl_ops ov2732_ctrl_ops =3D { + .s_ctrl =3D ov2732_set_ctrl, +}; + +static int ov2732_init_controls(struct ov2732 *ov2732) +{ + const struct ov2732_mode *mode =3D &supported_modes[0]; + struct v4l2_ctrl_handler *handler; + struct v4l2_ctrl *ctrl; + struct v4l2_fwnode_device_properties props; + s64 exposure_max, vblank_def, vblank_max; + int ret; + + handler =3D &ov2732->ctrl_handler; + ret =3D v4l2_ctrl_handler_init(handler, 10); + if (ret) + return ret; + + ctrl =3D v4l2_ctrl_new_std(handler, &ov2732_ctrl_ops, V4L2_CID_PIXEL_RATE, + OV2732_PIXEL_RATE, OV2732_PIXEL_RATE, + 1, OV2732_PIXEL_RATE); + + ctrl =3D v4l2_ctrl_new_int_menu(handler, &ov2732_ctrl_ops, + V4L2_CID_LINK_FREQ, 0, 0, + link_freq_menu_items); + if (ctrl) + ctrl->flags |=3D V4L2_CTRL_FLAG_READ_ONLY; + + ov2732->hblank =3D v4l2_ctrl_new_std(handler, &ov2732_ctrl_ops, + V4L2_CID_HBLANK, + OV2732_HBLANK_DEFAULT, + OV2732_HBLANK_DEFAULT, + 1, OV2732_HBLANK_DEFAULT); + if (ov2732->hblank) + ov2732->hblank->flags |=3D V4L2_CTRL_FLAG_READ_ONLY; + + vblank_def =3D mode->vts - mode->height; + vblank_max =3D OV2732_VTS_MAX - mode->height; + ov2732->vblank =3D v4l2_ctrl_new_std(handler, &ov2732_ctrl_ops, + V4L2_CID_VBLANK, + vblank_def, vblank_max, + 1, vblank_def); + + exposure_max =3D mode->vts - OV2732_EXPOSURE_OFFSET; + ov2732->exposure =3D v4l2_ctrl_new_std(handler, &ov2732_ctrl_ops, + V4L2_CID_EXPOSURE, + OV2732_EXPOSURE_MIN, exposure_max, + 1, OV2732_EXPOSURE_DEFAULT); + + v4l2_ctrl_new_std(handler, &ov2732_ctrl_ops, V4L2_CID_ANALOGUE_GAIN, + OV2732_ANALOGUE_GAIN_MIN, OV2732_ANALOGUE_GAIN_MAX, + 1, OV2732_ANALOGUE_GAIN_DEFAULT); + + v4l2_ctrl_new_std(handler, &ov2732_ctrl_ops, V4L2_CID_DIGITAL_GAIN, + OV2732_DIGITAL_GAIN_MIN, OV2732_DIGITAL_GAIN_MAX, + 1, OV2732_DIGITAL_GAIN_DEFAULT); + + v4l2_ctrl_new_std_menu_items(handler, &ov2732_ctrl_ops, + V4L2_CID_TEST_PATTERN, + ARRAY_SIZE(ov2732_test_pattern_menu) - 1, + 0, 0, ov2732_test_pattern_menu); + + if (handler->error) { + ret =3D handler->error; + dev_err_probe(ov2732->dev, ret, "Control init failed\n"); + goto err_handler_free; + } + + ret =3D v4l2_fwnode_device_parse(ov2732->dev, &props); + if (ret) + goto err_handler_free; + + ret =3D v4l2_ctrl_new_fwnode_properties(handler, &ov2732_ctrl_ops, &props= ); + if (ret) + goto err_handler_free; + + ov2732->sd.ctrl_handler =3D handler; + + return 0; + +err_handler_free: + v4l2_ctrl_handler_free(handler); + + return ret; +} + +static int ov2632_probe_dt(struct ov2732 *ov2732) +{ + int ret; + struct fwnode_handle *ep; + struct fwnode_handle *fwnode =3D dev_fwnode(ov2732->dev); + struct v4l2_fwnode_endpoint bus_cfg =3D { + .bus_type =3D V4L2_MBUS_CSI2_DPHY, + }; + + if (!fwnode) + return -ENXIO; + + ep =3D fwnode_graph_get_next_endpoint(fwnode, NULL); + if (!ep) + return dev_err_probe(ov2732->dev, -EPROBE_DEFER, + "waiting for fwnode graph endpoint\n"); + + ret =3D v4l2_fwnode_endpoint_alloc_parse(ep, &bus_cfg); + fwnode_handle_put(ep); + if (ret) { + dev_err_probe(ov2732->dev, -EINVAL, "could not parse endpoint\n"); + goto err_probe_dt; + } + + if (bus_cfg.bus.mipi_csi2.num_data_lanes !=3D OV2732_LANES) { + dev_err(ov2732->dev, "only a 2-lane CSI2 config is supported\n"); + ret =3D -EINVAL; + } + +err_probe_dt: + v4l2_fwnode_endpoint_free(&bus_cfg); + + return ret; +} + +static int ov2732_get_regulators(struct ov2732 *ov2732) +{ + unsigned int i; + + for (i =3D 0; i < OV2732_NUM_SUPPLIES; i++) + ov2732->supplies[i].supply =3D ov2732_supply_names[i]; + + return devm_regulator_bulk_get(ov2732->dev, + OV2732_NUM_SUPPLIES, + ov2732->supplies); +} + +static int ov2732_probe(struct i2c_client *client) +{ + struct ov2732 *ov2732; + int ret; + + ov2732 =3D devm_kzalloc(&client->dev, sizeof(*ov2732), GFP_KERNEL); + if (!ov2732) + return -ENOMEM; + + ov2732->dev =3D &client->dev; + + ret =3D ov2632_probe_dt(ov2732); + if (ret) + return dev_err_probe(ov2732->dev, ret, + "failed to probe device tree\n"); + + ov2732->xvclk =3D devm_v4l2_sensor_clk_get(ov2732->dev, "xvclk"); + if (IS_ERR(ov2732->xvclk)) + return dev_err_probe(ov2732->dev, PTR_ERR(ov2732->xvclk), + "failed to get xvclk\n"); + + ov2732->xvclk_freq =3D clk_get_rate(ov2732->xvclk); + if (ov2732->xvclk_freq !=3D OV2732_XVCLK_FREQ) + return dev_err_probe(ov2732->dev, -EINVAL, + "xvclk frequency not supported: %dHz\n", + ov2732->xvclk_freq); + + ov2732->powerdown_gpio =3D devm_gpiod_get_optional(ov2732->dev, + "powerdown", + GPIOD_OUT_HIGH); + + ov2732->reset_gpio =3D devm_gpiod_get_optional(ov2732->dev, "reset", + GPIOD_OUT_HIGH); + + ov2732->regmap =3D devm_cci_regmap_init_i2c(client, 16); + if (IS_ERR(ov2732->regmap)) + return dev_err_probe(ov2732->dev, PTR_ERR(ov2732->regmap), + "failed to init CCI\n"); + + ret =3D ov2732_get_regulators(ov2732); + if (ret) + return dev_err_probe(ov2732->dev, ret, + "failed to get regulators\n"); + + v4l2_i2c_subdev_init(&ov2732->sd, client, &ov2732_subdev_ops); + + /* Device must be powered on for ov2732_identify_chip(). */ + ret =3D ov2732_power_on(ov2732->dev); + if (ret) + return ret; + + pm_runtime_set_active(ov2732->dev); + pm_runtime_enable(ov2732->dev); + + ret =3D ov2732_identify_chip(ov2732); + if (ret) + goto err_power_off; + + ret =3D ov2732_init_controls(ov2732); + if (ret) + goto err_power_off; + + /* Initialize subdev */ + ov2732->sd.internal_ops =3D &ov2732_internal_ops; + ov2732->sd.flags |=3D V4L2_SUBDEV_FL_HAS_DEVNODE; + ov2732->sd.entity.function =3D MEDIA_ENT_F_CAM_SENSOR; + + /* Initialize source pad */ + ov2732->pad.flags =3D MEDIA_PAD_FL_SOURCE; + + ret =3D media_entity_pads_init(&ov2732->sd.entity, 1, &ov2732->pad); + if (ret) { + dev_err_probe(ov2732->dev, ret, "failed to init entity pads\n"); + goto error_handler_free; + } + + ov2732->sd.state_lock =3D ov2732->ctrl_handler.lock; + ret =3D v4l2_subdev_init_finalize(&ov2732->sd); + if (ret < 0) { + dev_err_probe(ov2732->dev, ret, "subdev init error\n"); + goto err_media_entity; + } + + ret =3D v4l2_async_register_subdev_sensor(&ov2732->sd); + if (ret < 0) { + dev_err_probe(ov2732->dev, ret, + "failed to register sensor sub-device\n"); + goto err_subdev_cleanup; + } + + pm_runtime_set_autosuspend_delay(ov2732->dev, 1000); + pm_runtime_use_autosuspend(ov2732->dev); + pm_runtime_idle(ov2732->dev); + + return 0; + +err_subdev_cleanup: + v4l2_subdev_cleanup(&ov2732->sd); + +err_media_entity: + media_entity_cleanup(&ov2732->sd.entity); + +error_handler_free: + v4l2_ctrl_handler_free(&ov2732->ctrl_handler); + +err_power_off: + pm_runtime_disable(ov2732->dev); + pm_runtime_put_noidle(ov2732->dev); + ov2732_power_off(ov2732->dev); + + return ret; +} + +static void ov2732_remove(struct i2c_client *client) +{ + struct v4l2_subdev *sd =3D i2c_get_clientdata(client); + struct ov2732 *ov2732 =3D to_ov2732(sd); + + v4l2_async_unregister_subdev(sd); + v4l2_subdev_cleanup(sd); + media_entity_cleanup(&sd->entity); + v4l2_ctrl_handler_free(&ov2732->ctrl_handler); + + pm_runtime_disable(ov2732->dev); + if (!pm_runtime_status_suspended(ov2732->dev)) { + ov2732_power_off(ov2732->dev); + pm_runtime_set_suspended(ov2732->dev); + } +} + +static const struct of_device_id ov2732_of_match[] =3D { + { .compatible =3D "ovti,ov2732", }, + { }, +}; +MODULE_DEVICE_TABLE(of, ov2732_of_match); + +static DEFINE_RUNTIME_DEV_PM_OPS(ov2732_pm_ops, ov2732_power_off, + ov2732_power_on, NULL); + +static struct i2c_driver ov2732_i2c_driver =3D { + .driver =3D { + .name =3D "ov2732", + .of_match_table =3D ov2732_of_match, + .pm =3D pm_sleep_ptr(&ov2732_pm_ops), + }, + .probe =3D ov2732_probe, + .remove =3D ov2732_remove, +}; +module_i2c_driver(ov2732_i2c_driver); + +MODULE_DESCRIPTION("OmniVision ov2732 sensor driver"); +MODULE_LICENSE("GPL"); +MODULE_AUTHOR("Walter Werner Schneider "); --=20 2.51.1