From nobody Thu Sep 24 18:40:56 2026 Received: from mail-106118.protonmail.ch (mail-106118.protonmail.ch [79.135.106.118]) (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 C861138E5DA for ; Mon, 21 Sep 2026 19:25:08 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=79.135.106.118 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1790018710; cv=none; b=HSTFLgWSRwNg7zQ/m9ICrTRIPmNzlZ9I6NbW361TYA+fz3yZTjroQBeHItus5Oa6QMZPTmxv2Kui8vapuEa6om+58kAWqt8yHdNtMkMrhbpphfvRRQjzkZL79LD/N2k8OGv+hysRflOT080L/2o3vPaCoj3vWmiEU0UVnaM2vBg= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1790018710; c=relaxed/simple; bh=CWeNmB1G1T4FfpPmAdc0PU7vtCSMJKCzRLRTwINH16Y=; h=Date:To:From:Cc:Subject:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=DaibdICH/OidMhRX1eQ/AmSJYWVkm+CO1k/KqfNwZR5k+xFwSwjdJnuoU5OvwhboXk6eSWbfYjpeYMZaX2xi9zyThowKKcsCd1Mjx8Tb5h9hKtdktg5FnXi7XFwWs6p0TL/1jXqjpiUfa4c9ox9zZWkYnsZTT+6ei/zhRYy6QQQ= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=pm.me; spf=pass smtp.mailfrom=pm.me; dkim=pass (2048-bit key) header.d=pm.me header.i=@pm.me header.b=h3Yo7OJe; arc=none smtp.client-ip=79.135.106.118 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=pm.me Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=pm.me Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=pm.me header.i=@pm.me header.b="h3Yo7OJe" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=pm.me; s=protonmail3; t=1790018706; x=1790277906; bh=6F7ov9WbdmIaBdnwxxwpg5631cX3gWx45dosU+Bspgk=; h=Date:To:From:Cc:Subject:Message-ID:In-Reply-To:References: Feedback-ID:From:To:Cc:Date:Subject:Reply-To:Feedback-ID: Message-ID:BIMI-Selector; b=h3Yo7OJeBXsUB87v97+cUT9iTEcaRcLLdlp7QY/3zN1VMYgJhvL/oahkowp+Oz7X+ jQf+Lp70EBfECzxpAom3n261o1DXT5Z5DZmXoNiC7/5tK4bwmmE95JyzBdnmYLOL2D udp8AFgRRFjn3q5P0JTtFoHZ4Llb8X+u7WNS6AGPGawpz4M3g0YX+fc1JSuQPCM7iw +yJNlTu1zApvDqxkjr7Harg8E2YBCQjTz2QxIxjHDlcwPx4moNIP5gXaOiBeynhsMh z39GQXf5ZxRjGT5H3IuRlU7HfpwXGsnO9AdWhRgy0KnK7IjpsssRn3Lu3tAVGB7i2M Ngsl6CKD1rpVQ== Date: Mon, 21 Sep 2026 19:25:01 +0000 To: Sakari Ailus , Mauro Carvalho Chehab , Andre Gilerson , Dan Scally From: Sergey Lebedev Cc: Hans de Goede , Rob Herring , Krzysztof Kozlowski , Conor Dooley , German Pablo Lindo , linux-media@vger.kernel.org, devicetree@vger.kernel.org, linux-kernel@vger.kernel.org Subject: [PATCH v5 1/3] dt-bindings: media: Add Sony IMX681 Message-ID: <20260921192450.21811-2-lsa.uz@pm.me> In-Reply-To: <20260921192450.21811-1-lsa.uz@pm.me> References: <20260921192450.21811-1-lsa.uz@pm.me> Feedback-ID: 113843758:user:proton X-Pm-Message-ID: 35bd21bade49e26084294d7add24e24a4642068e Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" The Sony IMX681 is a CMOS image sensor used as the user-facing camera on several Microsoft Surface devices. It operates from analog 2.8 V, digital 1.05 V and interface 1.8 V supplies, is programmable over I2C, and outputs 10-bit Bayer data over a two-lane MIPI CSI-2 D-PHY interface. Signed-off-by: Sergey Lebedev Reviewed-by: Krzysztof Kozlowski --- .../bindings/media/i2c/sony,imx681.yaml | 107 ++++++++++++++++++ 1 file changed, 107 insertions(+) create mode 100644 Documentation/devicetree/bindings/media/i2c/sony,imx681= .yaml diff --git a/Documentation/devicetree/bindings/media/i2c/sony,imx681.yaml b= /Documentation/devicetree/bindings/media/i2c/sony,imx681.yaml new file mode 100644 index 0000000000..6d2e4ddcee --- /dev/null +++ b/Documentation/devicetree/bindings/media/i2c/sony,imx681.yaml @@ -0,0 +1,107 @@ +# SPDX-License-Identifier: (GPL-2.0 OR BSD-2-Clause) +%YAML 1.2 +--- +$id: http://devicetree.org/schemas/media/i2c/sony,imx681.yaml# +$schema: http://devicetree.org/meta-schemas/core.yaml# + +title: Sony IMX681 CMOS Image Sensor + +maintainers: + - Andre Gilerson + +description: + The Sony IMX681 is a CMOS active pixel image sensor with a square pixel + array, used as the user-facing camera on several Microsoft Surface devic= es. + It operates from analog 2.8 V, digital 1.05 V and interface 1.8 V suppli= es, + is programmable over I2C, and outputs 10-bit Bayer data over a two-lane + MIPI CSI-2 D-PHY interface. + +allOf: + - $ref: /schemas/media/video-interface-devices.yaml# + +properties: + compatible: + const: sony,imx681 + + reg: + maxItems: 1 + + clocks: + description: Input clock (19.2 MHz) + maxItems: 1 + + avdd-supply: + description: Analog power supply (2.8 V) + + dvdd-supply: + description: Digital power supply (1.05 V) + + dovdd-supply: + description: Interface power supply (1.8 V) + + reset-gpios: + description: Sensor reset (XCLR) GPIO, active low + maxItems: 1 + + port: + $ref: /schemas/graph.yaml#/$defs/port-base + unevaluatedProperties: 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: + - endpoint + +required: + - compatible + - reg + - clocks + - avdd-supply + - dvdd-supply + - dovdd-supply + - port + +unevaluatedProperties: false + +examples: + - | + #include + + i2c { + #address-cells =3D <1>; + #size-cells =3D <0>; + + camera-sensor@10 { + compatible =3D "sony,imx681"; + reg =3D <0x10>; + clocks =3D <&clock_cam>; + avdd-supply =3D <&vcc2v8_cam>; + dvdd-supply =3D <&vcc1v05_cam>; + dovdd-supply =3D <&vcc1v8_cam>; + reset-gpios =3D <&gpio 4 GPIO_ACTIVE_LOW>; + orientation =3D <0>; + rotation =3D <0>; + + port { + imx681_ep: endpoint { + data-lanes =3D <1 2>; + link-frequencies =3D /bits/ 64 <969600000>; + remote-endpoint =3D <&csi_in>; + }; + }; + }; + }; +... --=20 2.54.0 (Apple Git-157) From nobody Thu Sep 24 18:40:56 2026 Received: from mail-08.mail-europe.com (mail-08.mail-europe.com [57.129.93.249]) (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 A90C83939C9; Mon, 21 Sep 2026 19:25:27 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=57.129.93.249 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1790018730; cv=none; b=q5DRPWKEOQAqX6U727t4SHhwlUnX7V8ZhmJLo+K2mt1DJpjMe+nTCD5TW9iIdqFGH2UdGf5jd12B+fyVfdh0wHvtveTY9i1TbD8jSJrVuQIjhwmWRpdoHhoxO/F/dDIG6jLsWoo+MzQnP/BfCgoUQGkd1xmqbTbpoz28zs7Sw8o= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1790018730; c=relaxed/simple; bh=rWzA0l4XZ8ZFLOywo4JzqQsNJz4x+Z1e0CXWaAYwwtE=; h=Date:To:From:Cc:Subject:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=fgcuOv21ZjDfuvOsHt8zx7TBqBukwMWkKpkJCXAvQK/t3F/d+4hMK0Ppu8lG4+t0C+nuHyYtn5S8BA4If8lbwjdGBwoszgX2Bx5BOPd3Gg3nVnKuyl+oVximkbvEjkZp+DDKgnADi5LabAfrAHuVuLY2yEG2QpfZv0b3NKDkHfk= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=pm.me; spf=pass smtp.mailfrom=pm.me; dkim=pass (2048-bit key) header.d=pm.me header.i=@pm.me header.b=qxJp8/iL; arc=none smtp.client-ip=57.129.93.249 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=pm.me Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=pm.me Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=pm.me header.i=@pm.me header.b="qxJp8/iL" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=pm.me; s=protonmail3; t=1790018710; x=1790277910; bh=pziqJOG4OXRrT6ye7O/4eiicr4v667Pveenjm+rV/VA=; h=Date:To:From:Cc:Subject:Message-ID:In-Reply-To:References: Feedback-ID:From:To:Cc:Date:Subject:Reply-To:Feedback-ID: Message-ID:BIMI-Selector; b=qxJp8/iLPLRp3932aQifT7bozhR0xMR3BJpW0EJgrtSx4iZE4ZN6RNXq8xEcAHFRh 9o7HAu5geGJ0FRd3mhbHYek3ohPdtSvCruEiqWUW9Fx+1oI6udgfA2vObKYxy9lF7a fwsDDJAmJVIcIN3davlB1+VsxPYJ0Iv/zrHNSYQgPcGjg/Mf7+NZ8FQ6B4MzTjJk9q JbRZMBwJ0XBOiuGhHy1uAKmLUdBzPyZgfJSqEOrKs2oKRKeHyvCQIB55rZ1BeuLpc2 WfsbkYETwyLgwNfuZsKPlycm83s0ALwZULIyOM7N2nLxOfGP+W5qS6xIBgwACSpp9i ySec/F0/XTODg== Date: Mon, 21 Sep 2026 19:25:07 +0000 To: Sakari Ailus , Mauro Carvalho Chehab , Andre Gilerson , Dan Scally From: Sergey Lebedev Cc: Hans de Goede , Rob Herring , Krzysztof Kozlowski , Conor Dooley , German Pablo Lindo , linux-media@vger.kernel.org, devicetree@vger.kernel.org, linux-kernel@vger.kernel.org Subject: [PATCH v5 2/3] media: i2c: Add Sony IMX681 sensor driver Message-ID: <20260921192450.21811-3-lsa.uz@pm.me> In-Reply-To: <20260921192450.21811-1-lsa.uz@pm.me> References: <20260921192450.21811-1-lsa.uz@pm.me> Feedback-ID: 113843758:user:proton X-Pm-Message-ID: a9c8509efb8f811490d1eb73e0b1d5f26bdb7405 Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" From: Andre Gilerson The Sony IMX681 is the user-facing camera on the Microsoft Surface Pro 11 for Business (Intel Lunar Lake, IPU7), where it is enumerated as ACPI device SONY0681. Without a driver the camera does not appear at all. There is no public documentation for this sensor. The initialisation sequence and the mode registers were recovered from I2C traces taken under Windows, and the driver does not pretend otherwise: imx681_init_regs[] is 21 register writes whose individual meaning is not known. What is not from the traces is derived and written down. The link frequency comes from the PLL configuration visible in the same traces - 19.2 MHz EXCK, PLL2_MUL 303, PLL2_PRE_DIV 3, giving 1939.2 MHz on the bus and therefore 969.6 MHz per lane - and the pixel rate follows from that, the lane count and the bit depth. The gain law and the black level were measured against the sensor rather than taken from the traces; the numbers are in the cover letter. The driver uses the streams API, v4l2-cci for register access, the subdev state API and runtime PM, and validates the endpoint's lane count and link frequency against what the firmware describes. Signed-off-by: Andre Gilerson Signed-off-by: Sergey Lebedev Tested-by: German Pablo Lindo --- MAINTAINERS | 7 + drivers/media/i2c/Kconfig | 10 + drivers/media/i2c/Makefile | 1 + drivers/media/i2c/imx681.c | 876 +++++++++++++++++++++++++++++++++++++ 4 files changed, 894 insertions(+) create mode 100644 drivers/media/i2c/imx681.c diff --git a/MAINTAINERS b/MAINTAINERS index 4cc4a2dc6d..4479f96d0d 100644 --- a/MAINTAINERS +++ b/MAINTAINERS @@ -25609,6 +25609,13 @@ S: Maintained F: Documentation/devicetree/bindings/media/i2c/sony,imx678.yaml F: drivers/media/i2c/imx678.c =20 +SONY IMX681 SENSOR DRIVER +M: Andre Gilerson +L: linux-media@vger.kernel.org +S: Maintained +F: Documentation/devicetree/bindings/media/i2c/sony,imx681.yaml +F: drivers/media/i2c/imx681.c + SONY MEMORYSTICK SUBSYSTEM M: Maxim Levitsky M: Alex Dubov diff --git a/drivers/media/i2c/Kconfig b/drivers/media/i2c/Kconfig index 4d99464791..c759a2d239 100644 --- a/drivers/media/i2c/Kconfig +++ b/drivers/media/i2c/Kconfig @@ -321,6 +321,16 @@ config VIDEO_IMX678 To compile this driver as a module, choose M here: the module will be called imx678. =20 +config VIDEO_IMX681 + tristate "Sony IMX681 sensor support" + select V4L2_CCI_I2C + help + This is a Video4Linux2 sensor driver for the Sony + IMX681 camera. + + To compile this driver as a module, choose M here: the + module will be called imx681. + config VIDEO_MAX9271_LIB tristate =20 diff --git a/drivers/media/i2c/Makefile b/drivers/media/i2c/Makefile index fd1cb25718..98bcecf0c4 100644 --- a/drivers/media/i2c/Makefile +++ b/drivers/media/i2c/Makefile @@ -64,6 +64,7 @@ obj-$(CONFIG_VIDEO_IMX412) +=3D imx412.o obj-$(CONFIG_VIDEO_IMX415) +=3D imx415.o obj-$(CONFIG_VIDEO_IMX678) +=3D imx678.o obj-$(CONFIG_VIDEO_IMX471) +=3D imx471.o +obj-$(CONFIG_VIDEO_IMX681) +=3D imx681.o obj-$(CONFIG_VIDEO_IR_I2C) +=3D ir-kbd-i2c.o obj-$(CONFIG_VIDEO_ISL7998X) +=3D isl7998x.o obj-$(CONFIG_VIDEO_IT6625) +=3D it6625.o diff --git a/drivers/media/i2c/imx681.c b/drivers/media/i2c/imx681.c new file mode 100644 index 0000000000..825d8c80a2 --- /dev/null +++ b/drivers/media/i2c/imx681.c @@ -0,0 +1,876 @@ +// SPDX-License-Identifier: GPL-2.0 +/* + * Sony IMX681 CMOS Image Sensor Driver + * + * Front camera on Surface Pro 11 Business (Intel/Lunar Lake). + * Register sequences reverse-engineered from Windows I2C traces. + * + * Copyright (C) 2025 + */ + +#include +#include +#include +#include +#include +#include +#include +#include + +#include +#include +#include +#include + +/* Chip ID register and expected value */ +#define IMX681_REG_CHIP_ID CCI_REG16(0x0016) +#define IMX681_CHIP_ID 0x0681 + +/* Mode select */ +#define IMX681_REG_MODE_SELECT CCI_REG8(0x0100) +#define IMX681_MODE_STANDBY 0x00 +#define IMX681_MODE_STREAMING 0x01 + +/* Group parameter hold */ +#define IMX681_REG_GROUP_HOLD CCI_REG8(0x0104) + +/* Exposure (coarse integration time, 24-bit) */ +#define IMX681_REG_EXPOSURE CCI_REG24(0x0229) +#define IMX681_EXPOSURE_MIN 4 +#define IMX681_EXPOSURE_MAX 3173 /* frame_length - 4 */ +#define IMX681_EXPOSURE_OFFSET 4 /* frame_length - exposure_max */ +#define IMX681_EXPOSURE_DEFAULT 1907 /* from Windows trace */ + +/* Analog gain */ +#define IMX681_REG_ANALOG_GAIN CCI_REG16(0x0204) +#define IMX681_ANA_GAIN_MIN 0 +#define IMX681_ANA_GAIN_MAX 960 /* 16x, where the analogue stage ends */ +#define IMX681_ANA_GAIN_DEFAULT 0 + +/* Digital gain */ +#define IMX681_REG_DIGITAL_GAIN CCI_REG16(0x020E) +#define IMX681_DIG_GAIN_MIN 0x0100 /* 1.0x */ +#define IMX681_DIG_GAIN_MAX 0x0FFF +#define IMX681_DIG_GAIN_DEFAULT 0x0100 + +/* Test pattern */ +#define IMX681_REG_TEST_PATTERN CCI_REG16(0x0600) + +/* Frame length (24-bit, for streaming updates) */ +#define IMX681_REG_FRAME_LENGTH CCI_REG24(0x033D) + +/* Image dimensions =E2=80=94 native sensor output */ +#define IMX681_WIDTH 3844 +#define IMX681_HEIGHT 2640 +#define IMX681_LINE_LENGTH_PCK 7552 /* 0x1D80 */ +#define IMX681_FRAME_LENGTH_LINES 3177 /* 0x0C69 */ +#define IMX681_FRAME_LENGTH_MAX 0xFFFF /* 24-bit reg, limit to 16-bit */ + +/* MIPI lanes */ +#define IMX681_NUM_LANES 2 + +/* + * Link frequency derived from PLL settings in Windows trace: + * EXCK=3D19.2MHz, PLL2_MUL=3D303, PLL2_PRE_DIV=3D3 + * OP output =3D 19.2 * 303 / 3 =3D 1939.2 MHz (MIPI bit rate) + * Link freq =3D 1939.2 / 2 (DDR) =3D 969.6 MHz + */ +#define IMX681_LINK_FREQ 969600000LL + +/* Pixel rate =3D link_freq * 2 (DDR) * num_lanes / bpp */ +#define IMX681_PIXEL_RATE (IMX681_LINK_FREQ * 2 * IMX681_NUM_LANES / 10) + +/* Power-on delay after reset deassert */ +#define IMX681_RESET_DELAY_US 1000 +#define IMX681_RESET_DELAY_RANGE_US 1000 + +/* Post-standby-cancel stabilisation delays */ +#define IMX681_INIT_DELAY_US 10000 + +#define IMAGE_PAD 0 + +static const s64 imx681_link_frequencies[] =3D { + IMX681_LINK_FREQ, +}; + +/* + * Sensor init register sequence, captured from Windows I2C traces. + * This configures the sensor for 3844x2640 RAW10 output at ~30fps + * with 2-lane MIPI CSI-2, 19.2MHz input clock. + */ +static const struct cci_reg_sequence imx681_init_regs[] =3D { + /* Software standby */ + { CCI_REG8(0x0100), 0x00 }, + /* External clock frequency =3D 19.2 MHz (encoded as MHz * 256) */ + { CCI_REG16(0x0136), 0x1333 }, + /* Vendor specific configuration */ + { CCI_REG16(0x002C), 0x0505 }, + /* CSI-2 signaling mode */ + { CCI_REG8(0x0111), 0x02 }, + /* Image orientation: H-flip to match Windows AIQB (RGGB native =E2=86=92= GRBG) */ + { CCI_REG8(0x0101), 0x01 }, + /* Vendor access unlock sequence */ + { CCI_REG8(0x30EB), 0x05 }, + { CCI_REG8(0x30EB), 0x0C }, + /* Vendor specific */ + { CCI_REG16(0x300A), 0xFFFF }, + { CCI_REG16(0x3532), 0xFFFF }, + /* LINE_LENGTH_PCK =3D 7552 */ + { CCI_REG16(0x0342), 0x1D80 }, + /* Frame length =3D 3177 */ + { CCI_REG16(0x033E), 0x0C69 }, + /* Crop window start: X_ADD_STA[7:0]=3D100, Y_ADD_STA=3D256 */ + { CCI_REG24(0x0345), 0x640100 }, + /* Crop window end: X_ADD_END[7:0]=3D103, Y_ADD_END=3D2895 */ + { CCI_REG24(0x0349), 0x670B4F }, + /* Digital crop / vendor config */ + { CCI_REG24(0x040D), 0x040A50 }, + /* X_OUTPUT_SIZE=3D3844, Y_OUTPUT_SIZE=3D2640 */ + { CCI_REG32(0x034C), 0x0F040A50 }, + /* PLL multiplier =3D 225 */ + { CCI_REG8(0x0307), 0xE1 }, + /* PLL2: pre_div=3D3, multiplier=3D303 (0x012F) */ + { CCI_REG24(0x030D), 0x03012F }, + /* Frame duration initial */ + { CCI_REG16(0x022A), 0x0C61 }, + /* Vendor specific registers */ + { CCI_REG8(0x7E9B), 0x02 }, + { CCI_REG8(0x0368), 0x00 }, + { CCI_REG8(0xD383), 0x01 }, +}; + +/* + * First exposure settings applied before stream-on. + * Uses group parameter hold to ensure atomic update. + */ +static const struct cci_reg_sequence imx681_first_exposure[] =3D { + { CCI_REG8(0x0104), 0x01 }, /* Group hold ON */ + { CCI_REG24(0x033D), 0x000C69 }, /* Frame length =3D 3177 */ + { CCI_REG24(0x0229), 0x000773 }, /* Exposure =3D 1907 lines */ + { CCI_REG16(0x0204), 0x0000 }, /* Analog gain =3D 0 (1x) */ + { CCI_REG16(0x020E), 0x0100 }, /* Digital gain =3D 1.0x */ + { CCI_REG8(0x0104), 0x00 }, /* Group hold OFF */ +}; + +static const char * const imx681_test_pattern_menu[] =3D { + "Disabled", + "Solid Colour", + "Eight Vertical Colour Bars", + "Colour Bars With Fade to Grey", + "Pseudorandom Sequence (PN9)", +}; + +static const u32 imx681_mbus_codes[] =3D { + MEDIA_BUS_FMT_SGRBG10_1X10, +}; + +/* Regulator supplies */ +static const char * const imx681_supply_names[] =3D { + "avdd", /* Analog 2.8V */ + "dvdd", /* Digital 1.05V */ + "dovdd", /* I/O 1.8V */ +}; + +#define IMX681_NUM_SUPPLIES ARRAY_SIZE(imx681_supply_names) + +struct imx681 { + struct device *dev; + struct regmap *cci; + + struct v4l2_subdev sd; + struct media_pad pad; + + struct clk *xclk; + struct gpio_desc *reset_gpio; + struct regulator_bulk_data supplies[IMX681_NUM_SUPPLIES]; + + /* V4L2 Controls */ + struct v4l2_ctrl_handler ctrl_handler; + struct v4l2_ctrl *exposure; + struct v4l2_ctrl *vblank; + struct v4l2_ctrl *hblank; + + unsigned long link_freq_bitmap; +}; + +static inline struct imx681 *to_imx681(struct v4l2_subdev *sd) +{ + return container_of_const(sd, struct imx681, sd); +} + +static int imx681_set_ctrl(struct v4l2_ctrl *ctrl) +{ + struct imx681 *imx681 =3D container_of(ctrl->handler, struct imx681, + ctrl_handler); + s64 exposure_max; + int pm_status; + int ret =3D 0; + + /* Update exposure max when VBLANK changes (even when not streaming) */ + if (ctrl->id =3D=3D V4L2_CID_VBLANK) { + exposure_max =3D IMX681_HEIGHT + ctrl->val - IMX681_EXPOSURE_OFFSET; + __v4l2_ctrl_modify_range(imx681->exposure, + IMX681_EXPOSURE_MIN, exposure_max, + 1, IMX681_EXPOSURE_DEFAULT); + } + + /* + * 1 with a reference taken, 0 if the device is not active, or -EINVAL + * if runtime PM is unavailable. Only the 0 means there is nothing to + * do: without runtime PM the sensor is powered from probe and never + * suspended, so the write still has to go out - but no reference was + * taken then, and none may be dropped. + */ + pm_status =3D pm_runtime_get_if_active(imx681->dev); + if (!pm_status) + return 0; + + switch (ctrl->id) { + case V4L2_CID_VBLANK: + cci_write(imx681->cci, IMX681_REG_GROUP_HOLD, 0x01, &ret); + cci_write(imx681->cci, IMX681_REG_FRAME_LENGTH, + IMX681_HEIGHT + ctrl->val, &ret); + cci_write(imx681->cci, IMX681_REG_GROUP_HOLD, 0x00, &ret); + dev_dbg(imx681->dev, "set frame_length: %d, ret=3D%d\n", + IMX681_HEIGHT + ctrl->val, ret); + break; + + case V4L2_CID_EXPOSURE: + cci_write(imx681->cci, IMX681_REG_GROUP_HOLD, 0x01, &ret); + cci_write(imx681->cci, IMX681_REG_EXPOSURE, ctrl->val, &ret); + cci_write(imx681->cci, IMX681_REG_GROUP_HOLD, 0x00, &ret); + dev_dbg(imx681->dev, "set exposure: %d, ret=3D%d\n", + ctrl->val, ret); + break; + + case V4L2_CID_ANALOGUE_GAIN: + /* Gain formula: gain =3D 1024/(1024-code); code 960 is 16x. */ + cci_write(imx681->cci, IMX681_REG_GROUP_HOLD, 0x01, &ret); + cci_write(imx681->cci, IMX681_REG_ANALOG_GAIN, ctrl->val, + &ret); + cci_write(imx681->cci, IMX681_REG_GROUP_HOLD, 0x00, &ret); + dev_dbg(imx681->dev, "set analogue gain code %d, ret=3D%d\n", + ctrl->val, ret); + break; + + case V4L2_CID_DIGITAL_GAIN: + cci_write(imx681->cci, IMX681_REG_GROUP_HOLD, 0x01, &ret); + cci_write(imx681->cci, IMX681_REG_DIGITAL_GAIN, ctrl->val, + &ret); + cci_write(imx681->cci, IMX681_REG_GROUP_HOLD, 0x00, &ret); + dev_dbg(imx681->dev, "set digital gain: %d, ret=3D%d\n", + ctrl->val, ret); + break; + + case V4L2_CID_TEST_PATTERN: + ret =3D cci_write(imx681->cci, IMX681_REG_TEST_PATTERN, + ctrl->val, NULL); + break; + + default: + dev_dbg(imx681->dev, "unhandled ctrl id: 0x%x val: 0x%x\n", + ctrl->id, ctrl->val); + break; + } + + if (pm_status > 0) + pm_runtime_put(imx681->dev); + return ret; +} + +static const struct v4l2_ctrl_ops imx681_ctrl_ops =3D { + .s_ctrl =3D imx681_set_ctrl, +}; + +static int imx681_enum_mbus_code(struct v4l2_subdev *sd, + struct v4l2_subdev_state *state, + struct v4l2_subdev_mbus_code_enum *code) +{ + if (code->index >=3D ARRAY_SIZE(imx681_mbus_codes)) + return -EINVAL; + + code->code =3D imx681_mbus_codes[code->index]; + return 0; +} + +static bool imx681_is_valid_mbus_code(u32 code) +{ + unsigned int i; + + for (i =3D 0; i < ARRAY_SIZE(imx681_mbus_codes); i++) + if (imx681_mbus_codes[i] =3D=3D code) + return true; + return false; +} + +static int imx681_enum_frame_size(struct v4l2_subdev *sd, + struct v4l2_subdev_state *state, + struct v4l2_subdev_frame_size_enum *fse) +{ + if (fse->index > 0) + return -EINVAL; + + if (!imx681_is_valid_mbus_code(fse->code)) + return -EINVAL; + + fse->min_width =3D IMX681_WIDTH; + fse->max_width =3D IMX681_WIDTH; + fse->min_height =3D IMX681_HEIGHT; + fse->max_height =3D IMX681_HEIGHT; + + return 0; +} + +static int imx681_init_state(struct v4l2_subdev *sd, + struct v4l2_subdev_state *state) +{ + struct v4l2_mbus_framefmt *format; + + format =3D v4l2_subdev_state_get_format(state, IMAGE_PAD); + format->width =3D IMX681_WIDTH; + format->height =3D IMX681_HEIGHT; + format->code =3D MEDIA_BUS_FMT_SGRBG10_1X10; + format->field =3D V4L2_FIELD_NONE; + format->colorspace =3D V4L2_COLORSPACE_RAW; + format->ycbcr_enc =3D V4L2_YCBCR_ENC_601; + format->quantization =3D V4L2_QUANTIZATION_FULL_RANGE; + format->xfer_func =3D V4L2_XFER_FUNC_NONE; + + return 0; +} + +static int imx681_set_pad_format(struct v4l2_subdev *sd, + const struct v4l2_subdev_client_info *ci, + struct v4l2_subdev_state *state, + struct v4l2_subdev_format *fmt) +{ + struct v4l2_mbus_framefmt *format; + + /* Fixed resolution, fixed Bayer order */ + fmt->format.width =3D IMX681_WIDTH; + fmt->format.height =3D IMX681_HEIGHT; + if (!imx681_is_valid_mbus_code(fmt->format.code)) + fmt->format.code =3D imx681_mbus_codes[0]; + 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; + + format =3D v4l2_subdev_state_get_format(state, fmt->pad); + *format =3D fmt->format; + + return 0; +} + +static int imx681_get_selection(struct v4l2_subdev *sd, + const struct v4l2_subdev_client_info *ci, + struct v4l2_subdev_state *state, + struct v4l2_subdev_selection *sel) +{ + switch (sel->target) { + case V4L2_SEL_TGT_CROP: + case V4L2_SEL_TGT_CROP_DEFAULT: + case V4L2_SEL_TGT_CROP_BOUNDS: + case V4L2_SEL_TGT_NATIVE_SIZE: + sel->r.top =3D 0; + sel->r.left =3D 0; + sel->r.width =3D IMX681_WIDTH; + sel->r.height =3D IMX681_HEIGHT; + return 0; + default: + return -EINVAL; + } +} + +static int imx681_start_streaming(struct imx681 *imx681) +{ + int ret; + + dev_dbg(imx681->dev, "starting stream: %dx%d RAW10 2-lane\n", + IMX681_WIDTH, IMX681_HEIGHT); + + /* Write init register sequence */ + ret =3D cci_multi_reg_write(imx681->cci, imx681_init_regs, + ARRAY_SIZE(imx681_init_regs), NULL); + if (ret) { + dev_err(imx681->dev, "failed to write init regs: %d\n", ret); + return ret; + } + + dev_dbg(imx681->dev, "init registers written successfully\n"); + + /* Wait for sensor to stabilise after configuration */ + usleep_range(IMX681_INIT_DELAY_US, IMX681_INIT_DELAY_US + 1000); + + /* Apply first exposure settings with group hold */ + ret =3D cci_multi_reg_write(imx681->cci, imx681_first_exposure, + ARRAY_SIZE(imx681_first_exposure), NULL); + if (ret) { + dev_err(imx681->dev, "failed to write exposure: %d\n", ret); + return ret; + } + + /* Apply any pending V4L2 control values */ + ret =3D __v4l2_ctrl_handler_setup(imx681->sd.ctrl_handler); + if (ret) { + dev_err(imx681->dev, "failed to apply controls: %d\n", ret); + return ret; + } + + /* Start streaming */ + ret =3D cci_write(imx681->cci, IMX681_REG_MODE_SELECT, + IMX681_MODE_STREAMING, NULL); + if (ret) { + dev_err(imx681->dev, "failed to start streaming: %d\n", ret); + return ret; + } + + dev_dbg(imx681->dev, "streaming started\n"); + return 0; +} + +static int imx681_stop_streaming(struct imx681 *imx681) +{ + int ret; + + ret =3D cci_write(imx681->cci, IMX681_REG_MODE_SELECT, + IMX681_MODE_STANDBY, NULL); + if (ret) + dev_err(imx681->dev, "failed to stop streaming: %d\n", ret); + + return ret; +} + +static int imx681_enable_streams(struct v4l2_subdev *sd, + struct v4l2_subdev_state *state, + u32 pad, u64 streams_mask) +{ + struct imx681 *imx681 =3D to_imx681(sd); + int ret; + + if (pad !=3D IMAGE_PAD) + return -EINVAL; + + ret =3D pm_runtime_get_sync(imx681->dev); + if (ret < 0) { + pm_runtime_put_noidle(imx681->dev); + return ret; + } + + ret =3D imx681_start_streaming(imx681); + if (ret) + pm_runtime_put_autosuspend(imx681->dev); + + return ret; +} + +static int imx681_disable_streams(struct v4l2_subdev *sd, + struct v4l2_subdev_state *state, + u32 pad, u64 streams_mask) +{ + struct imx681 *imx681 =3D to_imx681(sd); + + if (pad !=3D IMAGE_PAD) + return -EINVAL; + + imx681_stop_streaming(imx681); + pm_runtime_put_autosuspend(imx681->dev); + + return 0; +} + +static const struct v4l2_subdev_video_ops imx681_video_ops =3D { + .s_stream =3D v4l2_subdev_s_stream_helper, +}; + +static const struct v4l2_subdev_pad_ops imx681_pad_ops =3D { + .enum_mbus_code =3D imx681_enum_mbus_code, + .get_fmt =3D v4l2_subdev_get_fmt, + .set_fmt =3D imx681_set_pad_format, + .get_selection =3D imx681_get_selection, + .enum_frame_size =3D imx681_enum_frame_size, + .enable_streams =3D imx681_enable_streams, + .disable_streams =3D imx681_disable_streams, +}; + +static const struct v4l2_subdev_ops imx681_subdev_ops =3D { + .video =3D &imx681_video_ops, + .pad =3D &imx681_pad_ops, +}; + +static const struct v4l2_subdev_internal_ops imx681_internal_ops =3D { + .init_state =3D imx681_init_state, +}; + +/* Power management */ +static int imx681_power_on(struct device *dev) +{ + struct v4l2_subdev *sd =3D dev_get_drvdata(dev); + struct imx681 *imx681 =3D to_imx681(sd); + int ret; + + dev_dbg(imx681->dev, "power on\n"); + + ret =3D regulator_bulk_enable(IMX681_NUM_SUPPLIES, imx681->supplies); + if (ret) { + dev_err(imx681->dev, "failed to enable regulators: %d\n", ret); + return ret; + } + + ret =3D clk_prepare_enable(imx681->xclk); + if (ret) { + dev_err(imx681->dev, "failed to enable clock: %d\n", ret); + goto err_reg_disable; + } + + /* Deassert reset (active low) */ + gpiod_set_value_cansleep(imx681->reset_gpio, 0); + + usleep_range(IMX681_RESET_DELAY_US, + IMX681_RESET_DELAY_US + IMX681_RESET_DELAY_RANGE_US); + + return 0; + +err_reg_disable: + regulator_bulk_disable(IMX681_NUM_SUPPLIES, imx681->supplies); + return ret; +} + +static int imx681_power_off(struct device *dev) +{ + struct v4l2_subdev *sd =3D dev_get_drvdata(dev); + struct imx681 *imx681 =3D to_imx681(sd); + + dev_dbg(imx681->dev, "power off\n"); + + /* Assert reset */ + gpiod_set_value_cansleep(imx681->reset_gpio, 1); + clk_disable_unprepare(imx681->xclk); + regulator_bulk_disable(IMX681_NUM_SUPPLIES, imx681->supplies); + + return 0; +} + +static int imx681_identify_module(struct imx681 *imx681) +{ + u64 val; + int ret; + + ret =3D cci_read(imx681->cci, IMX681_REG_CHIP_ID, &val, NULL); + if (ret) + return dev_err_probe(imx681->dev, ret, + "failed to read chip ID register 0x0016\n"); + + if (val !=3D IMX681_CHIP_ID) { + return dev_err_probe(imx681->dev, -EIO, + "chip ID mismatch: 0x%04llx !=3D 0x%04x\n", + val, IMX681_CHIP_ID); + } + + return 0; +} + +static int imx681_init_controls(struct imx681 *imx681) +{ + struct v4l2_ctrl_handler *ctrl_hdlr =3D &imx681->ctrl_handler; + struct v4l2_fwnode_device_properties props; + struct v4l2_ctrl *link_freq; + s64 hblank, vblank; + int ret; + + ret =3D v4l2_ctrl_handler_init(ctrl_hdlr, 9); + if (ret) + return ret; + + /* Pixel rate (read-only) */ + v4l2_ctrl_new_std(ctrl_hdlr, &imx681_ctrl_ops, + V4L2_CID_PIXEL_RATE, IMX681_PIXEL_RATE, + IMX681_PIXEL_RATE, 1, IMX681_PIXEL_RATE); + + /* Link frequency (read-only) */ + link_freq =3D v4l2_ctrl_new_int_menu(ctrl_hdlr, &imx681_ctrl_ops, + V4L2_CID_LINK_FREQ, + __fls(imx681->link_freq_bitmap), + __ffs(imx681->link_freq_bitmap), + imx681_link_frequencies); + if (link_freq) + link_freq->flags |=3D V4L2_CTRL_FLAG_READ_ONLY; + + /* Horizontal blanking (read-only, fixed) */ + hblank =3D IMX681_LINE_LENGTH_PCK - IMX681_WIDTH; + imx681->hblank =3D v4l2_ctrl_new_std(ctrl_hdlr, &imx681_ctrl_ops, + V4L2_CID_HBLANK, hblank, hblank, + 1, hblank); + if (imx681->hblank) + imx681->hblank->flags |=3D V4L2_CTRL_FLAG_READ_ONLY; + + /* Vertical blanking (writable to allow longer exposures) */ + vblank =3D IMX681_FRAME_LENGTH_LINES - IMX681_HEIGHT; + imx681->vblank =3D v4l2_ctrl_new_std(ctrl_hdlr, &imx681_ctrl_ops, + V4L2_CID_VBLANK, vblank, + IMX681_FRAME_LENGTH_MAX - IMX681_HEIGHT, + 1, vblank); + + /* Exposure */ + imx681->exposure =3D v4l2_ctrl_new_std(ctrl_hdlr, &imx681_ctrl_ops, + V4L2_CID_EXPOSURE, + IMX681_EXPOSURE_MIN, + IMX681_EXPOSURE_MAX, 1, + IMX681_EXPOSURE_DEFAULT); + + /* Analog gain */ + v4l2_ctrl_new_std(ctrl_hdlr, &imx681_ctrl_ops, V4L2_CID_ANALOGUE_GAIN, + IMX681_ANA_GAIN_MIN, IMX681_ANA_GAIN_MAX, 1, + IMX681_ANA_GAIN_DEFAULT); + + /* Digital gain */ + v4l2_ctrl_new_std(ctrl_hdlr, &imx681_ctrl_ops, V4L2_CID_DIGITAL_GAIN, + IMX681_DIG_GAIN_MIN, IMX681_DIG_GAIN_MAX, 1, + IMX681_DIG_GAIN_DEFAULT); + + /* Test pattern */ + v4l2_ctrl_new_std_menu_items(ctrl_hdlr, &imx681_ctrl_ops, + V4L2_CID_TEST_PATTERN, + ARRAY_SIZE(imx681_test_pattern_menu) - 1, + 0, 0, imx681_test_pattern_menu); + + if (ctrl_hdlr->error) { + ret =3D ctrl_hdlr->error; + ret =3D dev_err_probe(imx681->dev, ret, "control init failed\n"); + goto error; + } + + ret =3D v4l2_fwnode_device_parse(imx681->dev, &props); + if (ret) + goto error; + + ret =3D v4l2_ctrl_new_fwnode_properties(ctrl_hdlr, &imx681_ctrl_ops, + &props); + if (ret) + goto error; + + imx681->sd.ctrl_handler =3D ctrl_hdlr; + return 0; + +error: + v4l2_ctrl_handler_free(ctrl_hdlr); + return ret; +} + +static int imx681_parse_endpoint(struct imx681 *imx681) +{ + struct fwnode_handle *fwnode =3D dev_fwnode(imx681->dev); + struct v4l2_fwnode_endpoint bus_cfg =3D { + .bus_type =3D V4L2_MBUS_CSI2_DPHY, + }; + struct fwnode_handle *ep; + int ret; + + ep =3D fwnode_graph_get_next_endpoint(fwnode, NULL); + if (!ep) { + return dev_err_probe(imx681->dev, -ENXIO, + "no endpoint found in firmware node\n"); + } + + ret =3D v4l2_fwnode_endpoint_alloc_parse(ep, &bus_cfg); + fwnode_handle_put(ep); + if (ret) + return dev_err_probe(imx681->dev, ret, + "failed to parse endpoint\n"); + + if (bus_cfg.bus.mipi_csi2.num_data_lanes !=3D IMX681_NUM_LANES) { + ret =3D dev_err_probe(imx681->dev, -EINVAL, + "expected %d data lanes, got %d\n", + IMX681_NUM_LANES, + bus_cfg.bus.mipi_csi2.num_data_lanes); + goto done; + } + + ret =3D v4l2_link_freq_to_bitmap(imx681->dev, + bus_cfg.link_frequencies, + bus_cfg.nr_of_link_frequencies, + imx681_link_frequencies, + ARRAY_SIZE(imx681_link_frequencies), + &imx681->link_freq_bitmap); + if (ret) + ret =3D dev_err_probe(imx681->dev, ret, + "link frequency mismatch\n"); + +done: + v4l2_fwnode_endpoint_free(&bus_cfg); + return ret; +} + +static int imx681_probe(struct i2c_client *client) +{ + struct imx681 *imx681; + unsigned int i; + int ret; + + imx681 =3D devm_kzalloc(&client->dev, sizeof(*imx681), GFP_KERNEL); + if (!imx681) + return -ENOMEM; + + imx681->dev =3D &client->dev; + + /* Initialise V4L2 subdev */ + v4l2_i2c_subdev_init(&imx681->sd, client, &imx681_subdev_ops); + + /* Initialise CCI regmap for 16-bit register addresses */ + imx681->cci =3D devm_cci_regmap_init_i2c(client, 16); + if (IS_ERR(imx681->cci)) + return dev_err_probe(imx681->dev, PTR_ERR(imx681->cci), + "failed to init CCI\n"); + + /* Get clock (optional - INT3472 provides it on Surface devices) */ + imx681->xclk =3D devm_clk_get_optional(imx681->dev, NULL); + if (IS_ERR(imx681->xclk)) + return dev_err_probe(imx681->dev, PTR_ERR(imx681->xclk), + "failed to get clock\n"); + + /* Get regulators */ + for (i =3D 0; i < IMX681_NUM_SUPPLIES; i++) + imx681->supplies[i].supply =3D imx681_supply_names[i]; + + ret =3D devm_regulator_bulk_get(imx681->dev, IMX681_NUM_SUPPLIES, + imx681->supplies); + if (ret) + return dev_err_probe(imx681->dev, ret, + "failed to get regulators\n"); + + /* Get reset GPIO (optional) */ + imx681->reset_gpio =3D devm_gpiod_get_optional(imx681->dev, "reset", + GPIOD_OUT_HIGH); + if (IS_ERR(imx681->reset_gpio)) + return dev_err_probe(imx681->dev, + PTR_ERR(imx681->reset_gpio), + "failed to get reset GPIO\n"); + + /* Parse CSI-2 endpoint */ + ret =3D imx681_parse_endpoint(imx681); + if (ret) + return dev_err_probe(imx681->dev, ret, + "endpoint parse failed\n"); + + /* Power on and verify chip ID */ + ret =3D imx681_power_on(imx681->dev); + if (ret) + return dev_err_probe(imx681->dev, ret, "power on failed\n"); + + ret =3D imx681_identify_module(imx681); + if (ret) + goto error_power_off; + + /* Enable runtime PM */ + pm_runtime_set_active(imx681->dev); + pm_runtime_get_noresume(imx681->dev); + pm_runtime_enable(imx681->dev); + pm_runtime_set_autosuspend_delay(imx681->dev, 1000); + pm_runtime_use_autosuspend(imx681->dev); + + /* Init V4L2 controls */ + ret =3D imx681_init_controls(imx681); + if (ret) + goto error_pm; + + /* Setup subdev */ + imx681->sd.flags |=3D V4L2_SUBDEV_FL_HAS_DEVNODE; + imx681->sd.entity.function =3D MEDIA_ENT_F_CAM_SENSOR; + imx681->sd.internal_ops =3D &imx681_internal_ops; + + /* Init media entity */ + imx681->pad.flags =3D MEDIA_PAD_FL_SOURCE; + ret =3D media_entity_pads_init(&imx681->sd.entity, 1, &imx681->pad); + if (ret) { + ret =3D dev_err_probe(imx681->dev, ret, + "media entity init failed\n"); + goto error_handler_free; + } + + imx681->sd.state_lock =3D imx681->ctrl_handler.lock; + ret =3D v4l2_subdev_init_finalize(&imx681->sd); + if (ret < 0) { + ret =3D dev_err_probe(imx681->dev, ret, + "subdev init finalize failed\n"); + goto error_media_entity; + } + + ret =3D v4l2_async_register_subdev_sensor(&imx681->sd); + if (ret < 0) { + ret =3D dev_err_probe(imx681->dev, ret, + "async register subdev failed\n"); + goto error_subdev_cleanup; + } + + pm_runtime_put_autosuspend(imx681->dev); + + dev_info(imx681->dev, + "IMX681 probed successfully: %dx%d @ %lld Hz link freq\n", + IMX681_WIDTH, IMX681_HEIGHT, IMX681_LINK_FREQ); + + return 0; + +error_subdev_cleanup: + v4l2_subdev_cleanup(&imx681->sd); +error_media_entity: + media_entity_cleanup(&imx681->sd.entity); +error_handler_free: + v4l2_ctrl_handler_free(imx681->sd.ctrl_handler); +error_pm: + pm_runtime_disable(imx681->dev); + pm_runtime_put_noidle(imx681->dev); + pm_runtime_set_suspended(imx681->dev); +error_power_off: + imx681_power_off(imx681->dev); + return ret; +} + +static void imx681_remove(struct i2c_client *client) +{ + struct v4l2_subdev *sd =3D i2c_get_clientdata(client); + struct imx681 *imx681 =3D to_imx681(sd); + + v4l2_async_unregister_subdev(sd); + v4l2_subdev_cleanup(&imx681->sd); + media_entity_cleanup(&sd->entity); + v4l2_ctrl_handler_free(imx681->sd.ctrl_handler); + + pm_runtime_disable(imx681->dev); + if (!pm_runtime_status_suspended(imx681->dev)) + imx681_power_off(imx681->dev); + pm_runtime_set_suspended(imx681->dev); +} + +static DEFINE_RUNTIME_DEV_PM_OPS(imx681_pm_ops, imx681_power_off, + imx681_power_on, NULL); + +#ifdef CONFIG_ACPI +static const struct acpi_device_id imx681_acpi_ids[] =3D { + { "SONY0681" }, + { /* sentinel */ } +}; +MODULE_DEVICE_TABLE(acpi, imx681_acpi_ids); +#endif + +static const struct of_device_id imx681_dt_ids[] =3D { + { .compatible =3D "sony,imx681" }, + { /* sentinel */ } +}; +MODULE_DEVICE_TABLE(of, imx681_dt_ids); + +static struct i2c_driver imx681_i2c_driver =3D { + .driver =3D { + .name =3D "imx681", + .pm =3D pm_ptr(&imx681_pm_ops), + .acpi_match_table =3D ACPI_PTR(imx681_acpi_ids), + .of_match_table =3D imx681_dt_ids, + }, + .probe =3D imx681_probe, + .remove =3D imx681_remove, +}; +module_i2c_driver(imx681_i2c_driver); + +MODULE_DESCRIPTION("Sony IMX681 CMOS Image Sensor Driver"); +MODULE_AUTHOR("Andre Gilerson "); +MODULE_LICENSE("GPL"); --=20 2.54.0 (Apple Git-157) From nobody Thu Sep 24 18:40:56 2026 Received: from mail-244122.protonmail.ch (mail-244122.protonmail.ch [109.224.244.122]) (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 A2BCA38DC5D; Mon, 21 Sep 2026 19:25:25 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=109.224.244.122 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1790018727; cv=none; b=XDkRUAAT2FLLXK89TeU4HJAJ7NQ3UiW2/+dsTnF+LAjj4e0/Uu5QsV3/EC3Q3nbUOfoVLwii46SYzbbow8cxneGCwGyINXJxLtYacFMQ3Rsa4twvKGgBZBUtxd6hXel6VHXt8EMpjJPefOWQG9aJMRtf/gzkIptfcEQ/lmJRnt0= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1790018727; c=relaxed/simple; bh=h9Trgpq+IKaW7jFGrhNGqF9VOhmwiuANsQLufQFcwWA=; h=Date:To:From:Cc:Subject:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=X7beeUpQu8q2JpbgSrsjZw5LUOYD8BldJiep3lB9vaHlaY5FRTX0Q2Ht6rsPkSpREGBwKcgKeNIy95oxlQ3iq/cD6mP0ysWtEqULeuwkIGb0cCoyPmyjzp1M4wg7331gL7VBFOfD/qrqZP96z993h2Bc7w9SxGAZY+KYisfa3/o= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=pm.me; spf=pass smtp.mailfrom=pm.me; dkim=pass (2048-bit key) header.d=pm.me header.i=@pm.me header.b=qar9lRDP; arc=none smtp.client-ip=109.224.244.122 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=pm.me Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=pm.me Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=pm.me header.i=@pm.me header.b="qar9lRDP" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=pm.me; s=protonmail3; t=1790018718; x=1790277918; bh=h9Trgpq+IKaW7jFGrhNGqF9VOhmwiuANsQLufQFcwWA=; h=Date:To:From:Cc:Subject:Message-ID:In-Reply-To:References: Feedback-ID:From:To:Cc:Date:Subject:Reply-To:Feedback-ID: Message-ID:BIMI-Selector; b=qar9lRDPkIM0UkiJjfUgrGPCOg8yeVqhCgfKpqaBjP1RZGmz+OBVHhA3WuZgBUMym tUjEPkvS91tJHlZ7SetAlTJUJbwAte6PcyxFlzBp3MaFx4z8F13J9vU4sTnMWvMF9u 14C6LyUQhN5pREgJVm1eskskUt/XTBLLVzZ3QfHc5rs5LAxf5yyPwX2PYq72yss/yW o/C+6iK6QB912iDMt7EuBMMK8voVM2FlK7FSE6tFwCzeAgv64/7ee6SbiNDmX7HDIQ t89DzDepuaDRnHkuwJOsanPNLZybwuo+THm94WigbKn1BeJN2sbnbtbxbA7Ir57jD2 0TtDdacNgsxPg== Date: Mon, 21 Sep 2026 19:25:13 +0000 To: Sakari Ailus , Mauro Carvalho Chehab , Andre Gilerson , Dan Scally From: Sergey Lebedev Cc: Hans de Goede , Rob Herring , Krzysztof Kozlowski , Conor Dooley , German Pablo Lindo , linux-media@vger.kernel.org, devicetree@vger.kernel.org, linux-kernel@vger.kernel.org Subject: [PATCH v5 3/3] media: ipu-bridge: Add Sony IMX681 Message-ID: <20260921192450.21811-4-lsa.uz@pm.me> In-Reply-To: <20260921192450.21811-1-lsa.uz@pm.me> References: <20260921192450.21811-1-lsa.uz@pm.me> Feedback-ID: 113843758:user:proton X-Pm-Message-ID: f8a8323559918e895ce9fbf9f3bb4b6d95af4214 Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" The Microsoft Surface Pro 11 for Business (Intel Lunar Lake, IPU7) carries a Sony IMX681 as its user-facing sensor, enumerated as ACPI device SONY0681. Add it so ipu_bridge_connect_sensors() builds its half of the graph; without the entry the sensor is never connected, whatever driver is present. One link frequency, 969.6 MHz, on two CSI-2 lanes. Signed-off-by: Sergey Lebedev --- drivers/media/pci/intel/ipu-bridge.c | 2 ++ 1 file changed, 2 insertions(+) diff --git a/drivers/media/pci/intel/ipu-bridge.c b/drivers/media/pci/intel= /ipu-bridge.c index 77257311d1..a1a4023f81 100644 --- a/drivers/media/pci/intel/ipu-bridge.c +++ b/drivers/media/pci/intel/ipu-bridge.c @@ -116,6 +116,8 @@ static const struct ipu_sensor_config ipu_supported_sen= sors[] =3D { IPU_SENSOR_CONFIG("OVTI5693", 1, 419200000), /* Omnivision OV8856 */ IPU_SENSOR_CONFIG("OVTI8856", 3, 180000000, 360000000, 720000000), + /* Sony IMX681 */ + IPU_SENSOR_CONFIG("SONY0681", 1, 969600000), /* Sony IMX471 */ IPU_SENSOR_CONFIG("SONY471A", 1, 200000000), /* Sony IMX471 (found on Lenovo X1 Carbon G14) */ --=20 2.54.0 (Apple Git-157)