media: i2c: Add Samsung S5K5E8 camera sensor driver
Subsystems (3)
v4 cover media: i2c: Add Samsung S5K5E8 camera sensor driver
This is v4 of the Samsung S5K5E8 sensor driver, previously posted as [PATCH v3 0/2] on 2026-11-22:
v1 and v2 were posted on 2026-11-21:
(v1 had no cover letter; the first link is to its 1/2 patch.)
A note on the competing series first, because it matters more than the changelog: Hikmah Gumelar posted a separate samsung,s5k5e8 series for the Xiaomi Mi A1 (tissot) a day later, on 2026-11-23, and it is now at v5 ([PATCH v5 0/7], 2026-11-27). Both series claim the same compatible ("samsung,s5k5e8"), the same binding file, the same driver file and the same Kconfig symbol, and neither series mentions the other. I only became aware of the overlap when a reviewer pointed me at it, and I would rather coordinate than race: I am happy to rebase this series onto a single shared driver, or to carry Hikmah's driver forward with the pieces below merged in -- whichever base the maintainers prefer. For the record, where the two stand:
- This series is ahead on: HFLIP/VFLIP controls, a 1304x980 59.81 fps binned mode, a tested device-tree node for the Redmi Note 4X (mido) in the local downstream tree, an in-flight libcamera sensor properties and helper series on libcamera-devel (v2 sent 2026-11-29, v3 to follow), hardware verification on mido, and test-pattern colour controls (registers 0x0602-0x0608, verified on mido). It also already uses the V4L2 CCI helpers, the active subdev state with the state lock as the control-handler lock, enable_streams/disable_streams with the s_stream helper, and v4l2_link_freq_to_bitmap() -- all things the Nov 27 reviews of Hikmah's v5 asked Hikmah to adopt (Sakari Ailus on the state lock, enable_streams and the link-frequency bitmap; Vladimir Zapolskiy on CCI).
- Hikmah's series is ahead on: human review (v5 was reviewed on Nov 27 by Sakari Ailus, Vladimir Zapolskiy and Bryan O'Donoghue, and Krzysztof Kozlowski reviewed the cover and DT binding on Dec 1), and a device-tree node plus rear-camera (OV12A10) and clock-fix support for tissot. Hikmah has also had the camera path running on 7.1.3, and on Nov 28 reported a physical Mi A1 booting 7.4.0-rc1 and validating the camera pipeline (CAMSS, OV12A10, S5K5E8) on the device; no camera results have been reported yet. Hikmah is splitting the series and addressing the review feedback before v6.
One more incompatibility between the series, in the binding itself:
"the same binding file" above is true only as a filename. Hikmah's binding (v5 2/7) requires avdd/dvdd/dovdd supplies and defines reset-gpios as its only GPIO, while this series requires vdda/vddd/vddio and adds optional powerdown-gpios, so no single device-tree node can satisfy both bindings at once. This series follows the supply naming of the upstream Samsung bindings (samsung,s5kjn1.yaml and samsung,s5k3m5.yaml both use vdda/vddd/vddio), but that is a precedent, not a ruling: if the two series are merged, the maintainer will have to pick one naming, and I am happy to rename to whichever is chosen.
One difference between the series I want to flag rather than silently
adopt: Hikmah's driver declares a 418 MHz link frequency. The mode tables program 0x0820/0x0821 = 0x0344, which we read as 836 Mbps/lane, i.e. 418 MHz -- but Hikmah never states that derivation, so it is our inference, not his claim. I tried that value and measured the result on mido hardware: with the PLL/timing tables unchanged, the sensor streams at 29.89 fps at 2592x1944 and ~59.8 fps at 1304x980, which proves a 168.0 Mpix/s VT pixel clock -- but that is all it proves. The D-PHY lane clock was not measured, and 168 Mpix/s does not by itself settle the lane rate either way: the pixel data of a 2592-pixel RAW10 line is transmitted only during the active 15.43 us of the 17.0 us line time, so the peak lane rate is 12,960 bits/lane / 15.43 us = 840 Mbps/lane, i.e. 420 MHz -- exactly the driver's pixel-rate formula (420 MHz x 2 lanes x 2 bits / 10). Spreading the same bits over the whole 17.0 us line time would need only 762.4 Mbps/lane, i.e. 381.2 MHz, so that is a lower bound on the lane rate, not the rate itself. Note V4L2_CID_PIXEL_RATE is derived from LINK_FREQ, so the 0.48% figure below is the error 418 MHz would introduce against the measured 168.0 Mpix/s VT clock, not an independent measurement. This version keeps 420 MHz because it avoids a 0.48% error in V4L2_CID_PIXEL_RATE (168.0 vs 167.2 Mpix/s at 418 MHz), not because the lane rate was measured. The meaning of 0x0820/0x0821 = 0x0344 is evidently not settled by that register alone; I would welcome a datasheet reference either way.
On the driver name: v3 renamed s5k5e8yx to s5k5e8. The sensor reports chip ID 0x5e80 and I have found no evidence of a distinct YX variant, so the plain S5K5E8 name is used throughout.
Changes in v4 (all in 2/2; 1/2 is unchanged from v3):
- Add test pattern mode 4, PN9. Verified on the Redmi Note 4X: mode 4 captures a deterministic pseudo-random 10-bit frame (mean 512.5, std 295.0, mid-row lag-1 autocorrelation 0.004 at 1304x980, whole-frame -0.006, two frames byte-identical), distinct from modes 0-3, which were re-checked and still work. v4l2-compliance still passes 46/46. (Hikmah's v5 already has PN9 at index 4, so this is parity between the series, not an advantage.)
- Use the 16-bit test-pattern register 0x0600 instead of the 8-bit 0x0601, and add test-pattern colour controls for registers 0x0602-0x0608. Verified on mido: writing 0x03ff to 0x0602 with the others at 0x0000 turned the solid-colour frame red, and the inverse turned it green/blue; defaults are 0x200, the sensor reset value, so reset behaviour is unchanged.
- Fix the pm_runtime handling in set_ctrl: proceed unless pm_runtime_get_if_active() returns zero (device not active), and only drop the reference when one was actually taken.
- CROP_DEFAULT stays the constant modes[0] crop, (8,8)/2592x1944: it is the suggested crop covering the whole picture, not the crop of the currently selected mode.
- The extra stream-on sequence from the Hikmah driver (msleep 80 plus 0x3c16/0x3c0d/0x0100/0x3c22 writes) was evaluated and is not adopted:
the sensor streamed without it before, and hardware testing on mido after removing it (stream start/stop cycles at both modes, fps and test patterns re-checked) shows no regression, so v4 keeps the plain MODE_SELECT write.
- Two small cleanups: the s5k5e8_subdev_entity_ops struct (which only set link_validate) is removed, and S5K5E8_NUM_SUPPLIES is replaced by ARRAY_SIZE(s5k5e8_supply_names) at the use sites.
- Link frequency stays at 420 MHz, for the reason above.
Changes in v3:
- Renamed s5k5e8yx to s5k5e8 throughout (driver, binding, Kconfig symbol, compatible, MAINTAINERS); renamed standby-gpios to powerdown-gpios; sequential regulator enable (vddio -> vdda -> vddd) with powerdown-then-reset deassertion.
- Adopted full V4L2 subdev active state; RUNTIME_PM_OPS() with pm_ptr(); HFLIP/VFLIP handling with active-pad Bayer update; aligned the binned mode's MIPI link PLL registers (0x0306, 0x0308, 0x0820/21 = 0x0344) with the Samsung OEM binned preview.
- Binding now requires vdda/vddd/vddio supplies and endpoint data-lanes; binding maintainer added.
Changes in v2:
- Rebased onto linux-media/media-committers next; updated .set_fmt and .get_selection for const struct v4l2_subdev_client_info *ci; converted PM ops to DEFINE_RUNTIME_DEV_PM_OPS() with pm_ptr(); checkpatch --strict fixes; DT binding MAINTAINERS entry moved into 1/2.
One open question from downstream review, for the maintainers: a reviewer of the downstream mido branch mentioned a work-in-progress generic CCS driver covering "almost all s5kxxx sensors" and I asked for a link to it, which was never supplied. I could not locate a CCS driver covering the S5K5E8 (the mainline CCS driver lists no Samsung sensor). Dedicated Samsung sensor drivers (s5kjn1, s5k3m5) have been accepted upstream, so I proceeded with a dedicated driver, but please say if CCS coverage is expected for this sensor instead.
Andrii Cherniavskyi (2):
dt-bindings: media: i2c: Add Samsung S5K5E8 image sensor
media: i2c: Add Samsung S5K5E8 camera sensor driver
.../bindings/media/i2c/samsung,s5k5e8.yaml | 109 ++ MAINTAINERS | 9 + drivers/media/i2c/Kconfig | 10 + drivers/media/i2c/Makefile | 1 + drivers/media/i2c/s5k5e8.c | 1108 ++++++++++++++++++++ 5 files changed, 1237 insertions(+) create mode 100644 Documentation/devicetree/bindings/media/i2c/samsung,s5k5e8.yaml create mode 100644 drivers/media/i2c/s5k5e8.c
base-commit: ccf78740d
Signature · 1 line
2.43.0
PATCH v4 1/2 dt-bindings: media: i2c: Add Samsung S5K5E8 image sensor
From: Andrii Cherniavskyi <[email protected]>
Add Device Tree bindings for the Samsung S5K5E8 5MP RAW10 CMOS image sensor, including required regulators, optional reset/powerdown GPIOs, and 2-lane MIPI CSI-2 endpoint properties.
--- .../bindings/media/i2c/samsung,s5k5e8.yaml | 109 ++++++++++++++++++ MAINTAINERS | 8 ++ 2 files changed, 117 insertions(+) create mode 100644 Documentation/devicetree/bindings/media/i2c/samsung,s5k5e8.yaml
Documentation/devicetree/bindings/media/i2c/samsung,s5k5e8.yaml new file +109 -0
@@ -0,0 +1,109 @@ +# SPDX-License-Identifier: (GPL-2.0-only OR BSD-2-Clause) +%YAML 1.2 +--- +$id: http://devicetree.org/schemas/media/i2c/samsung,s5k5e8.yaml# +$schema: http://devicetree.org/meta-schemas/core.yaml# + +title: Samsung S5K5E8 Image Sensor + +description: + Samsung S5K5E8 is a 5MP CMOS image sensor controlled over an I2C-compatible + serial interface, outputting RAW10 image data over a 2-lane MIPI D-PHY + interface. + +maintainers: + - Andrii Cherniavskyi <[email protected]> + - Tuan Kiet Huynh <[email protected]> + +allOf: + - $ref: /schemas/media/video-interface-devices.yaml# + +properties: + compatible: + const: samsung,s5k5e8 + + reg: + maxItems: 1 + + clocks: + description: MCLK supply clock. + maxItems: 1 + + reset-gpios: + description: Active low GPIO connected to RESET pad of the sensor. + maxItems: 1 + + powerdown-gpios: + description: + Active low GPIO connected to the XSHUTDN (powerdown) pad of the sensor. + maxItems: 1 + + vdda-supply: + description: Analogue voltage supply, 2.8 volts. + + vddd-supply: + description: Digital core voltage supply, 1.2 volts. + + vddio-supply: + description: Digital I/O voltage supply, 1.8 or 2.8 volts. + + 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 + - vdda-supply + - vddd-supply + - vddio-supply + - port + +unevaluatedProperties: false + +examples: + - | + #include <dt-bindings/gpio/gpio.h> + + i2c { + #address-cells = <1>; + #size-cells = <0>; + + camera@2d { + compatible = "samsung,s5k5e8"; + reg = <0x2d>; + clocks = <&camera_mclk 0>; + assigned-clocks = <&camera_mclk 0>; + assigned-clock-rates = <24000000>; + reset-gpios = <&gpio1 10 GPIO_ACTIVE_LOW>; + powerdown-gpios = <&gpio1 11 GPIO_ACTIVE_LOW>; + vdda-supply = <&vreg_2p8>; + vddd-supply = <&vreg_1p2>; + vddio-supply = <&vreg_1p8>; + + port { + endpoint { + data-lanes = <1 2>; + link-frequencies = /bits/ 64 <420000000>; + remote-endpoint = <&mipi_csi2_ep>; + }; + }; + }; + }; +...
MAINTAINERS +8 -0
@@ -25013,6 +25013,14 @@ M: Andrzej Hajda <[email protected]> S: Supported F: drivers/media/i2c/s5k5baf.c +SAMSUNG S5K5E8 CAMERA DRIVER +M: Andrii Cherniavskyi <[email protected]> +M: Tuan Kiet Huynh <[email protected]> +L: [email protected] +S: Maintained +T: git git://linuxtv.org/media_tree.git +F: Documentation/devicetree/bindings/media/i2c/samsung,s5k5e8.yaml + SAMSUNG S5KJN1 CAMERA DRIVER M: Vladimir Zapolskiy <[email protected]> S: Maintained
base-commit: ccf78740d63813c452c035b57d17a650492562fa
Signature · 1 line
2.43.0
Re: [PATCH v4 1/2] dt-bindings: media: i2c: Add Samsung S5K5E8 image sensor
Quoted 6 lines · Tuan Kiet Huynh
From: Andrii Cherniavskyi <[email protected]>
Add Device Tree bindings for the Samsung S5K5E8 5MP RAW10 CMOS image sensor, including required regulators, optional reset/powerdown GPIOs, and 2-lane MIPI CSI-2 endpoint properties.
Quoted 9 lines
Signed-off-by Andrii Cherniavskyi <[email protected]>Co-developed-by Tuan Kiet Huynh <[email protected]>Signed-off-by Tuan Kiet Huynh <[email protected]>--- .../bindings/media/i2c/samsung,s5k5e8.yaml | 109 ++++++++++++++++++ MAINTAINERS | 8 ++ 2 files changed, 117 insertions(+) create mode 100644 Documentation/devicetree/bindings/media/i2c/samsung,s5k5e8.yaml
Re: [PATCH v4 1/2] dt-bindings: media: i2c: Add Samsung S5K5E8 image sensor
In reply to Tuan Kiet HuynhHi Tuan Kiet and Andrii,
I tested the full v4 series (both patch 1/2 dt-bindings and patch 2/2 driver) on a Xiaomi Mi A1 (tissot, qcom-msm8953) running v7.4.0-rc1 with the CAMSS pipeline.
The sensor probes cleanly via CCI/I2C and successfully captures full-resolution frames (2584x1944) through libcamera:
$ cat /proc/device-tree/model; echo ""; uname -a Xiaomi Mi A1 Linux maple-box 7.4.0-rc1-msm8953+ #4 SMP PREEMPT Sat Nov 28 22:42:18 WIB 2026 aarch64 GNU/Linux
$ cam -l [0:06:17.184274101] [1688] INFO Camera camera_manager.cpp:327 libcamera v0.4.0 [0:06:17.259942818] [1692] WARN CameraSensorProperties camera_sensor_properties.cpp:458 No static properties available for 's5k5e8' [0:06:17.260069990] [1692] WARN CameraSensorProperties camera_sensor_properties.cpp:460 Please consider updating the camera sensor properties database [0:06:17.265982488] [1692] WARN CameraSensorProperties camera_sensor_properties.cpp:458 No static properties available for 'ov12a10' [0:06:17.266042064] [1692] WARN CameraSensorProperties camera_sensor_properties.cpp:460 Please consider updating the camera sensor properties database [0:06:17.278319400] [1692] WARN IPAProxy ipa_proxy.cpp:160 Configuration file 's5k5e8.yaml' not found for IPA module 'simple', falling back to 'uncalibrated.yaml' [0:06:17.278449904] [1692] WARN IPASoft soft_simple.cpp:96 IPASoft: Failed to create camera sensor helper for s5k5e8 [0:06:17.281595974] [1692] WARN IPAProxy ipa_proxy.cpp:160 Configuration file 'ov12a10.yaml' not found for IPA module 'simple', falling back to 'uncalibrated.yaml' [0:06:17.281699399] [1692] WARN IPASoft soft_simple.cpp:96 IPASoft: Failed to create camera sensor helper for ov12a10 Available cameras: 1: Internal front camera (/base/soc@0/cci@1b0c000/i2c-bus@1/camera@2d) 2: Internal back camera (/base/soc@0/cci@1b0c000/i2c-bus@0/camera@10)
$ cam -c 1 --capture=5 [0:06:35.395518653] [1693] INFO Camera camera_manager.cpp:327 libcamera v0.4.0 [0:06:35.474926338] [1696] WARN CameraSensorProperties camera_sensor_properties.cpp:458 No static properties available for 's5k5e8' [0:06:35.475027580] [1696] WARN CameraSensorProperties camera_sensor_properties.cpp:460 Please consider updating the camera sensor properties database [0:06:35.481332511] [1696] WARN CameraSensorProperties camera_sensor_properties.cpp:458 No static properties available for 'ov12a10' [0:06:35.481424170] [1696] WARN CameraSensorProperties camera_sensor_properties.cpp:460 Please consider updating the camera sensor properties database [0:06:35.494173709] [1696] WARN IPAProxy ipa_proxy.cpp:160 Configuration file 's5k5e8.yaml' not found for IPA module 'simple', falling back to 'uncalibrated.yaml' [0:06:35.494338019] [1696] WARN IPASoft soft_simple.cpp:96 IPASoft: Failed to create camera sensor helper for s5k5e8 [0:06:35.497772754] [1696] WARN IPAProxy ipa_proxy.cpp:160 Configuration file 'ov12a10.yaml' not found for IPA module 'simple', falling back to 'uncalibrated.yaml' [0:06:35.497915556] [1696] WARN IPASoft soft_simple.cpp:96 IPASoft: Failed to create camera sensor helper for ov12a10 Using camera /base/soc@0/cci@1b0c000/i2c-bus@1/camera@2d as cam0 [0:06:35.499929099] [1693] INFO Camera camera.cpp:1202 configuring streams: (0) 2584x1944-ABGR8888 [0:06:35.500690030] [1696] WARN CameraSensor camera_sensor_legacy.cpp:501 's5k5e8 3-002d': No sensor delays found in static properties. Assuming unverified defaults. [0:06:35.501002089] [1696] INFO IPASoft soft_simple.cpp:251 IPASoft: Exposure 4-1964, gain 0-512 (1) cam0: Capture 5 frames 395.707603 (0.00 fps) cam0-stream0 seq: 000000 bytesused: 20093184 395.741053 (29.90 fps) cam0-stream0 seq: 000001 bytesused: 20093184 395.774507 (29.89 fps) cam0-stream0 seq: 000002 bytesused: 20093184 396.008681 (4.27 fps) cam0-stream0 seq: 000003 bytesused: 20093184 396.276308 (3.74 fps) cam0-stream0 seq: 000004 bytesused: 20093184
Note: Since libcamera does not yet include a dedicated tuning file for s5k5e8 (falling back to uncalibrated.yaml), the sample image shows raw uncalibrated colors/exposure, while frame capture and streaming over MIPI CSI-2 work reliably.
Sample captured image (Xiaomi Mi A1 front camera, S5K5E8):
https://github.com/hikmahgumelar/xiaomi-tissot-mainline-notes/blob/main/7.4.0-rc1/s5k5e8-front-test.jpg
Best regards,
Hikmah Gumelar
Pada Sel, 1 Des 2026 pukul 18.02 Tuan Kiet Huynh
<[email protected]> menulis:
Quoted 155 lines
From: Andrii Cherniavskyi <[email protected]>
Add Device Tree bindings for the Samsung S5K5E8 5MP RAW10 CMOS image sensor, including required regulators, optional reset/powerdown GPIOs, and 2-lane MIPI CSI-2 endpoint properties.
Signed-off-by Andrii Cherniavskyi <[email protected]>Co-developed-by Tuan Kiet Huynh <[email protected]>Signed-off-by Tuan Kiet Huynh <[email protected]>--- .../bindings/media/i2c/samsung,s5k5e8.yaml | 109 ++++++++++++++++++ MAINTAINERS | 8 ++ 2 files changed, 117 insertions(+) create mode 100644 Documentation/devicetree/bindings/media/i2c/samsung,s5k5e8.yamlDocumentation/devicetree/bindings/media/i2c/samsung,s5k5e8.yaml new file +109
-0@@ -0,0 +1,109 @@ +# SPDX-License-Identifier: (GPL-2.0-only OR BSD-2-Clause) +%YAML 1.2 +--- +$id: http://devicetree.org/schemas/media/i2c/samsung,s5k5e8.yaml# +$schema: http://devicetree.org/meta-schemas/core.yaml# + +title: Samsung S5K5E8 Image Sensor + +description: + Samsung S5K5E8 is a 5MP CMOS image sensor controlled over an I2C-compatible + serial interface, outputting RAW10 image data over a 2-lane MIPI D-PHY + interface. + +maintainers: + - Andrii Cherniavskyi <[email protected]> + - Tuan Kiet Huynh <[email protected]> + +allOf: + - $ref: /schemas/media/video-interface-devices.yaml# + +properties: + compatible: + const: samsung,s5k5e8 + + reg: + maxItems: 1 + + clocks: + description: MCLK supply clock. + maxItems: 1 + + reset-gpios: + description: Active low GPIO connected to RESET pad of the sensor. + maxItems: 1 + + powerdown-gpios: + description: + Active low GPIO connected to the XSHUTDN (powerdown) pad of the sensor. + maxItems: 1 + + vdda-supply: + description: Analogue voltage supply, 2.8 volts. + + vddd-supply: + description: Digital core voltage supply, 1.2 volts. + + vddio-supply: + description: Digital I/O voltage supply, 1.8 or 2.8 volts. + + 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 + - vdda-supply + - vddd-supply + - vddio-supply + - port + +unevaluatedProperties: false + +examples: + - | + #include <dt-bindings/gpio/gpio.h> + + i2c { + #address-cells = <1>; + #size-cells = <0>; + + camera@2d { + compatible = "samsung,s5k5e8"; + reg = <0x2d>; + clocks = <&camera_mclk 0>; + assigned-clocks = <&camera_mclk 0>; + assigned-clock-rates = <24000000>; + reset-gpios = <&gpio1 10 GPIO_ACTIVE_LOW>; + powerdown-gpios = <&gpio1 11 GPIO_ACTIVE_LOW>; + vdda-supply = <&vreg_2p8>; + vddd-supply = <&vreg_1p2>; + vddio-supply = <&vreg_1p8>; + + port { + endpoint { + data-lanes = <1 2>; + link-frequencies = /bits/ 64 <420000000>; + remote-endpoint = <&mipi_csi2_ep>; + }; + }; + }; + }; +...MAINTAINERS +8
-0@@ -25013,6 +25013,14 @@ M: Andrzej Hajda <[email protected]> S: Supported F: drivers/media/i2c/s5k5baf.c +SAMSUNG S5K5E8 CAMERA DRIVER +M: Andrii Cherniavskyi <[email protected]> +M: Tuan Kiet Huynh <[email protected]> +L: [email protected] +S: Maintained +T: git git://linuxtv.org/media_tree.git +F: Documentation/devicetree/bindings/media/i2c/samsung,s5k5e8.yaml + SAMSUNG S5KJN1 CAMERA DRIVER M: Vladimir Zapolskiy <[email protected]> S: Maintainedbase-commit:
ccf78740d63813c452c035b57d17a650492562fa--
2.43.0
Signature · 2 lines
Best regards, Hikmah Gumelar
PATCH v4 2/2 media: i2c: Add Samsung S5K5E8 camera sensor driver
In reply to Tuan Kiet HuynhFrom: Andrii Cherniavskyi <[email protected]>
Add a driver for the Samsung S5K5E8 5-megapixel image sensor, as found in the front camera of the Xiaomi Redmi Note 4X (mido).
Two modes are supported: 2592x1944 at 29.89 fps and 2x2-binned 1304x980 at 59.81 fps, both verified on mido hardware. The driver uses the CCI regmap, runtime PM with a 1000 ms autosuspend delay, and the standard V4L2 control set (exposure, analogue gain, vblank, hflip/vflip, test pattern).
Test patterns cover modes 0-4. Mode 4 is the sensor's PN9 pattern, programmed through the 16-bit test-pattern register 0x0600. Verified on
mido: mode 4 captures a deterministic pseudo-random 10-bit frame (mean 512.5, std 295.0, mid-row lag-1 autocorrelation 0.004 and whole-frame -0.006, both at 1304x980, two frames byte-identical), distinct from modes 0-3, which were re-checked and still work. It is not claimed to be a bit-exact textbook PN9 m-sequence: analysis of the captured bitstream finds a degree-360 LFSR (40 interleaved primitive degree-9 sequences), not the degree-9 x^9+x^4+1 sequence, so the pattern is described only as the sensor's PN9 mode. The solid-colour test-pattern value is programmable per Bayer channel through registers 0x0602 (red), 0x0604 (greenR), 0x0606 (blue) and 0x0608 (greenB), 10 bits each, exposed as V4L2_CID_TEST_PATTERN_RED / GREENR / BLUE / GREENB defaulting to 0x200, the sensor reset value. Verified on mido: writing 0x03ff to 0x0602 with the others at 0x0000 turned the solid-colour frame red, and the inverse turned it green/blue.
s_ctrl only writes the sensor when it is powered: it proceeds unless pm_runtime_get_if_active() returns zero (device not active), and drops the reference with pm_runtime_put_autosuspend() only when one was actually taken, following the ov64a40 pattern. This keeps the autosuspend delay honoured and avoids returning -EINVAL when runtime PM is disabled, proceeding to access the device as ov64a40 does.
V4L2_SEL_TGT_CROP_DEFAULT returns the constant active pixel array, (8,8)/2592x1944, in both modes -- the active array, while CROP_BOUNDS is the native (0,0)/2608x1960 array, which it must be because the binned mode's crop already covers the full array; the per-mode crop is reported through V4L2_SEL_TGT_CROP instead. (imx219, imx258 and ov64a40 return CROP_DEFAULT equal to CROP_BOUNDS, and s5kjn5 returns a single constant rect for all selection targets; none of them returns a default rect distinct from CROP_BOUNDS.)
Link frequency is 420 MHz. Only the frame rate, and therefore the 168 Mpix/s VT pixel clock (2856 * 1968 @ 29.89 fps, 2784 * 1009 @ 59.81 fps), was measured on hardware; the D-PHY lane clock was not. Keeping 420 MHz avoids a 0.48% error in V4L2_CID_PIXEL_RATE (168.0 vs 167.2 Mpix/s at 418 MHz), and the 0x0820/0x0821 value of 0x0344 alone does not settle the lane rate either way.
Fixes from blind review of the v4 submission: drop the !ep -EINVAL check in s5k5e8_check_hwcfg() so a missing endpoint defers probe (v4l2_fwnode_endpoint_alloc_parse() already returns -EPROBE_DEFER); name the standard SMIA/CCS registers in the mode tables and drop the redundant VTS/exposure writes there; update the mbus code only after the orientation write succeeds; pass NULL ops for the read-only fwnode properties; configure autosuspend before registering the sub-device; and roll back the pad format and control ranges if a mode-switch control update fails.
--- MAINTAINERS | 1 + drivers/media/i2c/Kconfig | 10 + drivers/media/i2c/Makefile | 1 + drivers/media/i2c/s5k5e8.c | 1108 ++++++++++++++++++++++++++++++++++++ 4 files changed, 1120 insertions(+) create mode 100644 drivers/media/i2c/s5k5e8.c
MAINTAINERS +1 -0
@@ -25020,6 +25020,7 @@ L: [email protected] S: Maintained T: git git://linuxtv.org/media_tree.git F: Documentation/devicetree/bindings/media/i2c/samsung,s5k5e8.yaml +F: drivers/media/i2c/s5k5e8.c SAMSUNG S5KJN1 CAMERA DRIVER M: Vladimir Zapolskiy <[email protected]>
drivers/media/i2c/Kconfig +10 -0
@@ -885,6 +885,16 @@ config VIDEO_S5K5BAF This is a V4L2 sensor driver for Samsung S5K5BAF 2M camera sensor with an embedded SoC image signal processor. +config VIDEO_S5K5E8 + tristate "Samsung S5K5E8 sensor support" + select V4L2_CCI_I2C + help + This is a V4L2 sensor driver for Samsung S5K5E8 5MP raw + camera sensor. + + To compile this driver as a module, choose M here: the + module will be called s5k5e8. + config VIDEO_S5K6A3 tristate "Samsung S5K6A3 sensor support" help
drivers/media/i2c/Makefile +1 -0
@@ -137,6 +137,7 @@ obj-$(CONFIG_VIDEO_RJ54N1) += rj54n1cb0c.o obj-$(CONFIG_VIDEO_S5C73M3) += s5c73m3/ obj-$(CONFIG_VIDEO_S5K3M5) += s5k3m5.o obj-$(CONFIG_VIDEO_S5K5BAF) += s5k5baf.o +obj-$(CONFIG_VIDEO_S5K5E8) += s5k5e8.o obj-$(CONFIG_VIDEO_S5K6A3) += s5k6a3.o obj-$(CONFIG_VIDEO_S5KJN1) += s5kjn1.o obj-$(CONFIG_VIDEO_S5KJN5) += s5kjn5.o
drivers/media/i2c/s5k5e8.c new file +1108 -0
1,108 lines not on this page · raw message
Signature · 1 line
2.43.0
[email protected]
AI reviewThank you for your contribution! Sashiko AI review found 3 potential issues to consider: - [Medium] media: i2c: s5k5e8: stale pad format code on flip in s5k5e8_set_ctrl() - [Medium] media: i2c…
Thank you for your contribution! Sashiko AI review found 3 potential issues to consider:
- [Medium] media: i2c: s5k5e8: stale pad format code on flip in s5k5e8_set_ctrl()
- [Medium] media: i2c: s5k5e8: skipped exposure range update in s5k5e8_set_pad_format()
- [Medium] media: i2c: s5k5e8: double power-off on error in s5k5e8_probe()
--
commit 80073db7588e5bb612eb448a1a6e71dcce3b2a95
Author: Andrii Cherniavskyi <[email protected]>
media: i2c: Add Samsung S5K5E8 camera sensor driver
This commit adds a V4L2 subdevice driver for the Samsung S5K5E8 5-megapixel MIPI CSI-2 image sensor.
Quoted 6 lines
drivers/media/i2c/s5k5e8.c new file +0
-0@@ -0,0 +1,1108 @@
[ ... ]
Quoted 53 lines
drivers/media/i2c/s5k5e8.c new file +53
-0+static int s5k5e8_set_ctrl (struct v4l2_ctrl *ctrl) +{ +struct s5k5e8 *s5k5e8 = + container_of(ctrl->handler, struct s5k5e8, ctrl_handler); +struct v4l2_subdev_state *state; +const struct s5k5e8_mode *mode; +s64 exposure_max, exposure_def; +int pm_status; +int ret; + + state =v4l2_subdev_get_locked_active_state (&s5k5e8->sd); +if (WARN_ON_ONCE (!state)) +return -EINVAL ; + + mode =s5k5e8_get_mode_from_state (state); + +/* Propagate change of current control to all related controls */ +switch (ctrl->id) { +case V4L2_CID_VBLANK : +/* Update max exposure while meeting expected vblanking */ + exposure_max = + mode->height + ctrl->val -S5K5E8_EXPOSURE_MARGIN ; + exposure_def =min_t (s64, mode->exposure, exposure_max); + ret =__v4l2_ctrl_modify_range (s5k5e8->exposure, + s5k5e8->exposure->minimum, + exposure_max, + s5k5e8->exposure->step, + exposure_def); +if (ret) +return ret; +break ; + } + +/* V4L2 controls are applied when sensor is powered up for streaming */ + pm_status =pm_runtime_get_if_active (s5k5e8->dev); +if (!pm_status) +return 0 ; + +switch (ctrl->id) { +case V4L2_CID_ANALOGUE_GAIN : + ret =cci_write (s5k5e8->regmap,S5K5E8_REG_AGAIN , ctrl->val, +NULL ); +break ; +case V4L2_CID_EXPOSURE : + ret =cci_write (s5k5e8->regmap,S5K5E8_REG_EXPOSURE , + ctrl->val,NULL ); +break ; +case V4L2_CID_VBLANK : + ret =cci_write (s5k5e8->regmap,S5K5E8_REG_VTS , + ctrl->val + mode->height,NULL ); +break ; +case V4L2_CID_VFLIP : +case V4L2_CID_HFLIP :
drivers/media/i2c/s5k5e8.c line 408
Quoted 10 lines
drivers/media/i2c/s5k5e8.c new file +10
-0+ ret =cci_write (s5k5e8->regmap,S5K5E8_REG_ORIENTATION , + (s5k5e8->vflip->val ?S5K5E8_VFLIP :0 ) | + (s5k5e8->hflip->val ?S5K5E8_HFLIP :0 ), +NULL ); +/* Only report the flipped Bayer order once the sensor has it. */ +if (!ret) +v4l2_subdev_state_get_format (state,0 )->code = +s5k5e8_get_format_code (s5k5e8->hflip->val, + s5k5e8->vflip->val); +break ;
[Severity: Medium]
Does changing V4L2_CID_HFLIP or V4L2_CID_VFLIP while the sensor is runtime-suspended leave the active pad format's media bus code stale?
Because s5k5e8_enable_streams() grabs hflip and vflip while streaming, userspace normally modifies them when the device is idle and suspended. In that state pm_runtime_get_if_active() returns 0, so the V4L2 core commits the new flip values to cur.val while v4l2_subdev_state_get_format(state, 0)->code stays unflipped. s5k5e8_enum_mbus_code() and s5k5e8_enum_frame_size() then report the new flipped Bayer code from cur.val, whereas VIDIOC_SUBDEV_G_FMT and pipeline link validation before streaming see the old code.
[ ... ]
Quoted 5 lines
drivers/media/i2c/s5k5e8.c new file +5
-0+static int s5k5e8_set_pad_format (struct v4l2_subdev *sd, +const struct v4l2_subdev_client_info *ci, +struct v4l2_subdev_state *state, +struct v4l2_subdev_format *fmt) +{
[ ... ]
Quoted 35 lines
drivers/media/i2c/s5k5e8.c new file +35
-0+if (fmt->which ==V4L2_SUBDEV_FORMAT_ACTIVE && mode_changed) { + hblank = mode->hts - mode->width; + ret =__v4l2_ctrl_modify_range (s5k5e8->hblank, hblank, hblank, +1 , hblank); +if (ret) + goto restore; + + vblank = mode->vts - mode->height; + ret =__v4l2_ctrl_modify_range (s5k5e8->vblank, vblank, +S5K5E8_VTS_MAX - mode->height, +1 , vblank); +if (ret) + goto restore; + + ret =__v4l2_ctrl_s_ctrl (s5k5e8->vblank, vblank); +if (ret) + goto restore; + +/* +* No explicit exposure range update here: setting VBLANK +* above already updated the exposure range through +* s5k5e8_set_ctrl(). +*/ + ret =__v4l2_ctrl_s_ctrl (s5k5e8->exposure, mode->exposure); +if (ret) + goto restore; + } + +return 0 ; + +restore: + *format = old_format; + *crop = old_crop; + +/* Best effort: restore the control ranges of the old mode. */
drivers/media/i2c/s5k5e8.c line 717
Quoted 10 lines
drivers/media/i2c/s5k5e8.c new file +10
-0+ hblank = old_mode->hts - old_mode->width; +__v4l2_ctrl_modify_range (s5k5e8->hblank, hblank, hblank,1 , hblank); + vblank = old_mode->vts - old_mode->height; +__v4l2_ctrl_modify_range (s5k5e8->vblank, vblank, +S5K5E8_VTS_MAX - old_mode->height,1 , vblank); +__v4l2_ctrl_s_ctrl (s5k5e8->vblank, vblank); +__v4l2_ctrl_s_ctrl (s5k5e8->exposure, old_mode->exposure); + +return ret; +}
[Severity: Medium]
Can relying on __v4l2_ctrl_s_ctrl(s5k5e8->vblank, vblank) skip the s5k5e8->exposure range update when switching modes?
Both __v4l2_ctrl_modify_range() and __v4l2_ctrl_s_ctrl() only invoke s5k5e8_set_ctrl() when the control value actually changes from cur.val. If userspace sets V4L2_CID_VBLANK to 29 in the 2592x1944 mode and then switches to the 1304x980 mode (where the default vblank is also 1009 - 980 = 29), s5k5e8_set_ctrl() is not called, leaving s5k5e8->exposure->maximum at 1969 instead of 1005 (and skipping the S5K5E8_REG_VTS write if the sensor is runtime-active). For the same reason, if __v4l2_ctrl_s_ctrl(s5k5e8->vblank, vblank) fails during cci_write() after modifying the exposure range, vblank->cur.val is still the old mode's vblank, so the restore path will not roll back the exposure range either.
[ ... ]
Quoted 23 lines
drivers/media/i2c/s5k5e8.c new file +23
-0+pm_runtime_set_active (s5k5e8->dev); +pm_runtime_set_autosuspend_delay (s5k5e8->dev,1000 ); +pm_runtime_use_autosuspend (s5k5e8->dev); +pm_runtime_enable (s5k5e8->dev); + + ret =v4l2_async_register_subdev_sensor (&s5k5e8->sd); +if (ret <0 ) { + ret =dev_err_probe (s5k5e8->dev, ret, +"failed to register V4L2 subdev\n" ); + goto subdev_cleanup; + } + +pm_runtime_idle (s5k5e8->dev); + +return 0 ; + +subdev_cleanup: +pm_runtime_dont_use_autosuspend (s5k5e8->dev); +pm_runtime_disable (s5k5e8->dev); +pm_runtime_set_suspended (s5k5e8->dev); +v4l2_subdev_cleanup (&s5k5e8->sd); + +media_entity_cleanup:
drivers/media/i2c/s5k5e8.c line 1063
Quoted 10 lines
drivers/media/i2c/s5k5e8.c new file +10
-0+media_entity_cleanup (&s5k5e8->sd.entity); + +v4l2_ctrl_handler_free: +v4l2_ctrl_handler_free (s5k5e8->sd.ctrl_handler); + +power_off: +s5k5e8_power_off (s5k5e8->dev); + +return ret; +}
[Severity: Medium]
Does the subdev_cleanup error path call s5k5e8_power_off() twice if v4l2_async_register_subdev_sensor() fails?
Runtime PM is enabled with the device active and usage_count == 0, so calling pm_runtime_dont_use_autosuspend() before pm_runtime_disable() triggers an immediate rpm_idle() -> rpm_suspend() that runs s5k5e8_power_off(). Falling through to the power_off label then calls s5k5e8_power_off() a second time, causing unbalanced clk_disable_unprepare() and regulator_disable() calls.
Signature · 1 line
Sashiko AI review · https://sashiko.dev/#/patchset/[email protected]?part=2
Hi Tuan,
Thank you for reaching out and for your willingness to coordinate.
I'm still testing the camera driver on the Xiaomi Mi A1 (tissot) with kernel v7.4.0-rc1 to validate the driver and its integration before sending the next patch revision.
I'm happy to follow your preferred approach for combining our work, whether that means rebasing your series onto my driver or integrating your improvements into a common implementation.
I'd be glad to collaborate on the integration and testing, particularly for the MSM8953 platform.
I'm also happy to follow the maintainers' preference on the common implementation.
Best regards,
Hikmah Gumelar
Hi Hikmah,
Thanks for the reply and for being open to collaborating on the S5K5E8 driver.
To avoid duplicating maintainer review across two competing submissions, we will step aside and let your series lead as the upstream base for samsung,s5k5e8, and we will not send a competing v5. Please feel free to mark our [PATCH v4 0/2] series as Superseded / Withdrawn on Patchwork.
Once your base series lands (or during your next revision if helpful), I would be glad to help test on mido and send follow-up patches on top for any remaining items such as the 1304x980 @ 60 fps binned mode, PN9 / solid-colour test-pattern controls, or runtime PM / control-range corner cases.
Good luck with your v7.4.0-rc1 validation on tissot!
Best regards,
Tuan Kiet Huynh
Hi Tuan,
Thank you for your understanding and for offering to support the development and testing.
I appreciate your decision to let my series serve as the upstream base. I’m happy to continue coordinating with you on the remaining improvements.
At the moment, I’m still validating the driver on tissot to ensure that it works reliably and remains stable. I haven’t settled on a timeline for the next revision yet, especially with the upcoming Linux 7.4 release.
I would prefer to take the time needed to ensure the driver is properly tested rather than rush the next submission.
Your offer to test on mido and contribute follow-up improvements would be very helpful. I’ll keep you updated as the validation progresses.
Thanks again for your willingness to collaborate.
Best regards,
Hikmah Gumelar
Pada Rab, 2 Des 2026 pukul 09.35 Tuan Kiet Huynh <[email protected]> menulis:
Quoted 22 lines
Hi Hikmah,
Thanks for the reply and for being open to collaborating on the S5K5E8 driver.
To avoid duplicating maintainer review across two competing submissions, we will step aside and let your series lead as the upstream base for samsung,s5k5e8, and we will not send a competing v5. Please feel free to mark our [PATCH v4 0/2] series as Superseded / Withdrawn on Patchwork.
Once your base series lands (or during your next revision if helpful), I would be glad to help test on mido and send follow-up patches on top for any remaining items such as the 1304x980 @ 60 fps binned mode, PN9 / solid-colour test-pattern controls, or runtime PM / control-range corner cases.
Good luck with your v7.4.0-rc1 validation on tissot!
Best regards,
Tuan Kiet Huynh
Signature · 2 lines
Best regards, Hikmah Gumelar