Skip to contentSkip to conversation

media: Add GalaxyCore GC5035 and GC8034 sensor drivers

PATCH Superseded Nicola Fiorillo 4 participants 16 messages Oct 9 – Oct 12

Subsystems (2)
lore
Share & tools
lore
#0 lore raw

cover media: Add GalaxyCore GC5035 and GC8034 sensor drivers

This series adds drivers for the GalaxyCore GC5035 and GC8034 raw Bayer sensors, and the ipu-bridge entries needed to use them on Intel IPU6. Both are found on the CHUWI Hi10 X1, an Intel N100 (Alder Lake-N) tablet:

GC5035, 5 Mpixel, front, 2 CSI-2 lanes, ACPI HID GCTI5035 GC8034, 8 Mpixel, rear, 4 CSI-2 lanes, ACPI HID GCTI8034

The drivers are ACPI only. I have no device tree system with either sensor, so I have not added bindings I cannot test.

Link frequencies
----------------

Both drivers accept only the 19.2 MHz external clock they have been tested with. The link frequencies in the vendor code are for a 24 MHz clock:

- GC5035: Intel's 438 MHz is correct with a 24 MHz clock. For 19.2 MHz Intel changed the PLL but not the constant. With the new PLL the link frequency is 422.4 MHz, which matches the measurement.
- GC8034: the vendor code declares 336 MHz for a 24 MHz clock. At 19.2 MHz everything scales by 0.8: 268.8 MHz, and 24 fps instead of 30.

The same values are used in the ipu-bridge entries in patch 3.

Gain, power sequencing and geometry
-----------------------------------

V4L2_CID_ANALOGUE_GAIN is the index of the analogue gain step, 17 steps on the GC5035 and 7 on the GC8034, and the digital gain is left at the 1.0x the register tables program. The vendor drivers fill the gap between two steps with digital gain; that is left to userspace.

No datasheet is available for either sensor. The GC5035 power sequence follows the one Tomasz Figa described in the 2020 series (IOVDD first, MCLK cycles before the first I2C transaction and after streaming stops), the GC8034 one follows the Rockchip driver. On this machine only AVDD is a real, GPIO switched regulator: DVDD and DOVDD are dummies, and the GC8034 has no reset or powerdown GPIO.

The register tables read out a window slightly larger than the output size and crop it: 2608x1960 cropped at (8, 8) on the GC5035, 3284x2464 cropped at (9, 8) on the GC8034. The size of the full pixel arrays is not documented, so the readout windows are reported as the native sizes.

The GC8034 blanking register holds the frame length minus the height and 36 lines. The 36 lines value comes from the Rockchip driver, and is confirmed by the measurement with VBLANK set to 2000: the difference is less than one line.

Provenance
----------

The GC5035 register tables come from the Alder Lake-M driver in intel/ipu6-drivers, which derives from the ChromeOS driver posted in 2020 by Tomasz Figa [1]. That series got as far as v4 and was not merged. The GC8034 register tables come from the Rockchip BSP driver (rockchip-linux kernel, develop-5.10). The copyright lines of the original authors are kept in both files. The register tables have been shortened: the GC5035 one from 323 to 160 writes, the GC8034 one from 233 to 182. Registers written twice and those already written by the controls have been removed. The final register state is identical to the one of the original tables. There is no public documentation for the PLL and CSI-2 settings.

The driver code follows gc05a2.c and gc08a3.c: CCI helpers, subdev active state, enable_streams/disable_streams and runtime PM with autosuspend.

Use of an LLM
-------------

I speak Italian and I use Claude to translate.

I used an LLM (Claude Opus 5.5) to collect the main points of the sensor driver reviews posted to this list recently. Claude wrote the driver code and updated it based on those points, and wrote the test scripts. I ran the tests on the tablet with the hardware, and the results are listed below. The code, the measurements and the notes (in Italian) are at
https://github.com/nic-fio/chuwi-hi10x1-cameras

The use of LLMs follows Documentation/process/coding-assistants.rst and generated-content.rst.

Not covered
-----------

- One mode per sensor: 2592x1944 on the GC5035, 3264x2448 on the GC8034. The binned modes of the vendor drivers have not been tested and were left out.
- The sensor OTP is not read. On the GC5035 it holds factory register settings and defect pixel tables, which the 2020 series applied.
- The GC8034 module has a dw9714 VCM, instantiated by ipu-bridge; focus has not been tested.
- Tested on one machine, with one sample of each sensor.

Testing
-------

Based on media-committers next, commit 8e26d4c20ed2 ("media: hantro:
disable runtime PM before hardware teardown"), and tested on the CHUWI Hi10 X1 with that kernel and these patches:

- both sensors stream at full resolution
- frame rate: the frame rates expected from the driver match the

    measured ones: 28.82 fps on the GC5035, 24.01 fps against 24.00 on
    the GC8034. They also match with VBLANK set to 2000: 14.67 fps on
    the GC5035 and 13.47 fps on the GC8034.
  - analogue gain, from the first to the last step: 15.6x requested and
    15.35x measured on the GC5035, 7.66x requested and 7.74x measured on
    the GC8034.

- GC5035 test pattern: two consecutive frames are 100% identical.
- v4l2-compliance from git (1616bf9e3c81), run with -z on the media
device: 54 out of 54 tests pass on both sensors, with 2 warnings on S_SELECTION. The warnings are there because the crop is fixed; imx219, gc05a2 and gc08a3 do the same. Output below.

[1] https://lore.kernel.org/linux-media/[email protected]/

GC5035:

v4l2-compliance 1.33.0-5515, 64 bits, 64-bit time_t v4l2-compliance SHA: 1616bf9e3c81 2026-10-06 07:30:20

Compliance test for intel-ipu6 device /dev/v4l-subdev4:

Driver Info:

	Driver version   : 7.3.0
	Capabilities     : 0x00000000
	Client Capabilities: 0x0000000000000002
interval-uses-which Media Driver Info:
	Driver name      : intel-ipu6
	Model            : ipu6
	Serial           :
	Bus info         : PCI:0000:00:05.0
	Media version    : 7.3.0
	Hardware revision: 0x00000000 (0)
	Driver version   : 7.3.0
Interface Info:
	ID               : 0x030000f5
	Type             : V4L Sub-Device
Entity Info:
	ID               : 0x000000e9 (233)
	Name             : gc5035 2-003f
	Function         : Camera Sensor
	Pad 0x010000ea   : 0: Source
	  Link 0x020000eb: to remote pad 0x1000096 of entity 'Intel IPU6 CSI2 2' (Video Interface Bridge): Data, Enabled, Immutable

Required ioctls:
test MC information (see 'Media Driver Info' above): OK test VIDIOC_SUDBEV_QUERYCAP: OK
test invalid ioctls: OK

Allow for multiple opens:
test second /dev/v4l-subdev4 open: OK
test VIDIOC_SUBDEV_QUERYCAP: OK
test for unlimited opens: OK

Debug ioctls:
test VIDIOC_LOG_STATUS: OK (Not Supported)

Input ioctls:
test VIDIOC_G/S_TUNER/ENUM_FREQ_BANDS: OK (Not Supported) test VIDIOC_G/S_FREQUENCY: OK (Not Supported) test VIDIOC_S_HW_FREQ_SEEK: OK (Not Supported) test VIDIOC_ENUMAUDIO: OK (Not Supported)
test VIDIOC_G/S/ENUMINPUT: OK (Not Supported) test VIDIOC_G/S_AUDIO: OK (Not Supported)
Inputs: 0 Audio Inputs: 0 Tuners: 0

Output ioctls:
test VIDIOC_G/S_MODULATOR: OK (Not Supported) test VIDIOC_G/S_FREQUENCY: OK (Not Supported) test VIDIOC_ENUMAUDOUT: OK (Not Supported) test VIDIOC_G/S/ENUMOUTPUT: OK (Not Supported) test VIDIOC_G/S_AUDOUT: OK (Not Supported)
Outputs: 0 Audio Outputs: 0 Modulators: 0

Input/Output configuration ioctls:
test VIDIOC_ENUM/G/S/QUERY_STD: OK (Not Supported) test VIDIOC_ENUM/G/S/QUERY_DV_TIMINGS: OK (Not Supported) test VIDIOC_DV_TIMINGS_CAP: OK (Not Supported) test VIDIOC_G/S_EDID: OK (Not Supported)

Sub-Device ioctls (Source Pad 0):
Try Stream 0
test Try VIDIOC_SUBDEV_ENUM_MBUS_CODE/FRAME_SIZE/FRAME_INTERVAL: OK
test Try VIDIOC_SUBDEV_G/S_FMT: OK
warn: v4l2-test-subdevs.cpp(566): VIDIOC_SUBDEV_G_SELECTION is supported for target 0 but not VIDIOC_SUBDEV_S_SELECTION
test Try VIDIOC_SUBDEV_G/S_SELECTION/CROP: OK
Active Stream 0
test Active VIDIOC_SUBDEV_ENUM_MBUS_CODE/FRAME_SIZE/FRAME_INTERVAL: OK
test Active VIDIOC_SUBDEV_G/S_FMT: OK
warn: v4l2-test-subdevs.cpp(566): VIDIOC_SUBDEV_G_SELECTION is supported for target 0 but not VIDIOC_SUBDEV_S_SELECTION
test Active VIDIOC_SUBDEV_G/S_SELECTION/CROP: OK
test Active VIDIOC_SUBDEV_G/S_FRAME_INTERVAL: OK (Not Supported)

Control ioctls:
test VIDIOC_QUERY_EXT_CTRL/QUERYMENU: OK test VIDIOC_QUERYCTRL: OK
test VIDIOC_G/S_CTRL: OK
test VIDIOC_G/S/TRY_EXT_CTRLS: OK test VIDIOC_(UN)SUBSCRIBE_EVENT/DQEVENT: OK test VIDIOC_G/S_JPEGCOMP: OK (Not Supported) Standard Controls: 13 Private Controls: 0

Format ioctls:
test VIDIOC_ENUM_FMT/FRAMESIZES/FRAMEINTERVALS: OK (Not Supported) test VIDIOC_G/S_PARM: OK (Not Supported)
test VIDIOC_G_FBUF: OK (Not Supported)
test VIDIOC_G_FMT: OK (Not Supported)
test VIDIOC_TRY_FMT: OK (Not Supported)
test VIDIOC_S_FMT: OK (Not Supported)
test VIDIOC_G_SLICED_VBI_CAP: OK (Not Supported)
test Cropping: OK (Not Supported)
test Composing: OK (Not Supported)
test Scaling: OK (Not Supported)

Codec ioctls:
test VIDIOC_(TRY_)ENCODER_CMD: OK (Not Supported) test VIDIOC_G_ENC_INDEX: OK (Not Supported) test VIDIOC_(TRY_)DECODER_CMD: OK (Not Supported)

Buffer ioctls:
test VIDIOC_REQBUFS/CREATE_BUFS/QUERYBUF: OK (Not Supported) test CREATE_BUFS maximum buffers: OK
test VIDIOC_REMOVE_BUFS: OK
test VIDIOC_EXPBUF: OK (Not Supported)
test Requests: OK (Not Supported)
test blocking wait: OK (Not Supported)

Total for intel-ipu6 device /dev/v4l-subdev4: 54, Succeeded: 54, Failed: 0, Warnings: 2

GC8034:

v4l2-compliance 1.33.0-5515, 64 bits, 64-bit time_t v4l2-compliance SHA: 1616bf9e3c81 2026-10-06 07:30:20

Compliance test for intel-ipu6 device /dev/v4l-subdev5:

Driver Info:

	Driver version   : 7.3.0
	Capabilities     : 0x00000000
	Client Capabilities: 0x0000000000000002
interval-uses-which Media Driver Info:
	Driver name      : intel-ipu6
	Model            : ipu6
	Serial           :
	Bus info         : PCI:0000:00:05.0
	Media version    : 7.3.0
	Hardware revision: 0x00000000 (0)
	Driver version   : 7.3.0
Interface Info:
	ID               : 0x030000fb
	Type             : V4L Sub-Device
Entity Info:
	ID               : 0x000000f7 (247)
	Name             : gc8034 1-0037
	Function         : Camera Sensor
	Pad 0x010000f8   : 0: Source
	  Link 0x020000f9: to remote pad 0x100008c of entity 'Intel IPU6 CSI2 1' (Video Interface Bridge): Data, Enabled, Immutable

Required ioctls:
test MC information (see 'Media Driver Info' above): OK test VIDIOC_SUDBEV_QUERYCAP: OK
test invalid ioctls: OK

Allow for multiple opens:
test second /dev/v4l-subdev5 open: OK
test VIDIOC_SUBDEV_QUERYCAP: OK
test for unlimited opens: OK

Debug ioctls:
test VIDIOC_LOG_STATUS: OK (Not Supported)

Input ioctls:
test VIDIOC_G/S_TUNER/ENUM_FREQ_BANDS: OK (Not Supported) test VIDIOC_G/S_FREQUENCY: OK (Not Supported) test VIDIOC_S_HW_FREQ_SEEK: OK (Not Supported) test VIDIOC_ENUMAUDIO: OK (Not Supported)
test VIDIOC_G/S/ENUMINPUT: OK (Not Supported) test VIDIOC_G/S_AUDIO: OK (Not Supported)
Inputs: 0 Audio Inputs: 0 Tuners: 0

Output ioctls:
test VIDIOC_G/S_MODULATOR: OK (Not Supported) test VIDIOC_G/S_FREQUENCY: OK (Not Supported) test VIDIOC_ENUMAUDOUT: OK (Not Supported) test VIDIOC_G/S/ENUMOUTPUT: OK (Not Supported) test VIDIOC_G/S_AUDOUT: OK (Not Supported)
Outputs: 0 Audio Outputs: 0 Modulators: 0

Input/Output configuration ioctls:
test VIDIOC_ENUM/G/S/QUERY_STD: OK (Not Supported) test VIDIOC_ENUM/G/S/QUERY_DV_TIMINGS: OK (Not Supported) test VIDIOC_DV_TIMINGS_CAP: OK (Not Supported) test VIDIOC_G/S_EDID: OK (Not Supported)

Sub-Device ioctls (Source Pad 0):
Try Stream 0
test Try VIDIOC_SUBDEV_ENUM_MBUS_CODE/FRAME_SIZE/FRAME_INTERVAL: OK
test Try VIDIOC_SUBDEV_G/S_FMT: OK
warn: v4l2-test-subdevs.cpp(566): VIDIOC_SUBDEV_G_SELECTION is supported for target 0 but not VIDIOC_SUBDEV_S_SELECTION
test Try VIDIOC_SUBDEV_G/S_SELECTION/CROP: OK
Active Stream 0
test Active VIDIOC_SUBDEV_ENUM_MBUS_CODE/FRAME_SIZE/FRAME_INTERVAL: OK
test Active VIDIOC_SUBDEV_G/S_FMT: OK
warn: v4l2-test-subdevs.cpp(566): VIDIOC_SUBDEV_G_SELECTION is supported for target 0 but not VIDIOC_SUBDEV_S_SELECTION
test Active VIDIOC_SUBDEV_G/S_SELECTION/CROP: OK
test Active VIDIOC_SUBDEV_G/S_FRAME_INTERVAL: OK (Not Supported)

Control ioctls:
test VIDIOC_QUERY_EXT_CTRL/QUERYMENU: OK test VIDIOC_QUERYCTRL: OK
test VIDIOC_G/S_CTRL: OK
test VIDIOC_G/S/TRY_EXT_CTRLS: OK test VIDIOC_(UN)SUBSCRIBE_EVENT/DQEVENT: OK test VIDIOC_G/S_JPEGCOMP: OK (Not Supported) Standard Controls: 12 Private Controls: 0

Format ioctls:
test VIDIOC_ENUM_FMT/FRAMESIZES/FRAMEINTERVALS: OK (Not Supported) test VIDIOC_G/S_PARM: OK (Not Supported)
test VIDIOC_G_FBUF: OK (Not Supported)
test VIDIOC_G_FMT: OK (Not Supported)
test VIDIOC_TRY_FMT: OK (Not Supported)
test VIDIOC_S_FMT: OK (Not Supported)
test VIDIOC_G_SLICED_VBI_CAP: OK (Not Supported)
test Cropping: OK (Not Supported)
test Composing: OK (Not Supported)
test Scaling: OK (Not Supported)

Codec ioctls:
test VIDIOC_(TRY_)ENCODER_CMD: OK (Not Supported) test VIDIOC_G_ENC_INDEX: OK (Not Supported) test VIDIOC_(TRY_)DECODER_CMD: OK (Not Supported)

Buffer ioctls:
test VIDIOC_REQBUFS/CREATE_BUFS/QUERYBUF: OK (Not Supported) test CREATE_BUFS maximum buffers: OK
test VIDIOC_REMOVE_BUFS: OK
test VIDIOC_EXPBUF: OK (Not Supported)
test Requests: OK (Not Supported)
test blocking wait: OK (Not Supported)

Total for intel-ipu6 device /dev/v4l-subdev5: 54, Succeeded: 54, Failed: 0, Warnings: 2

Nicola Fiorillo (3):
media: i2c: Add GC5035 image sensor driver
media: i2c: Add GC8034 image sensor driver
media: ipu-bridge: Add GalaxyCore GC5035 and GC8034

 MAINTAINERS                          |  12 +
 drivers/media/i2c/Kconfig            |  20 +
 drivers/media/i2c/Makefile           |   2 +
 drivers/media/i2c/gc5035.c           | 953 ++++++++++++++++++++++++++
 drivers/media/i2c/gc8034.c           | 969 +++++++++++++++++++++++++++
 drivers/media/pci/intel/ipu-bridge.c |   4 +
 6 files changed, 1960 insertions(+)
 create mode 100644 drivers/media/i2c/gc5035.c
 create mode 100644 drivers/media/i2c/gc8034.c

base-commit: 8e26d4c20ed218db6c3123480a4a4e2545680566

Signature · 1 line
2.47.3
#1 lore raw

PATCH 1/3 media: i2c: Add GC5035 image sensor driver

Add a driver for the GalaxyCore GC5035, a 5 Mpixel raw Bayer sensor with a two lane MIPI CSI-2 interface. The driver supports a single 2592x1944 mode, and the exposure, analogue gain, vertical blanking and test pattern controls.

The register tables come from the Alder Lake-M driver in intel/ipu6-drivers, which derives from the ChromeOS driver posted in 2020.

Assisted-by claude-opus-5-5 coccinelle sparse smatch
---
 MAINTAINERS                |   6 +
 drivers/media/i2c/Kconfig  |  10 +
 drivers/media/i2c/Makefile |   1 +
 drivers/media/i2c/gc5035.c | 953 +++++++++++++++++++++++++++++++++++++
 4 files changed, 970 insertions(+)
 create mode 100644 drivers/media/i2c/gc5035.c
MAINTAINERS +6 -0
index 6bdc32e7c..c4d5f81f4 100644
@@ -10875,6 +10875,12 @@ T:	git git://linuxtv.org/media.git
 F:	Documentation/devicetree/bindings/media/i2c/galaxycore,gc2145.yaml
 F:	drivers/media/i2c/gc2145.c
 
+GALAXYCORE GC5035 CAMERA SENSOR DRIVER
+M:	Nicola Fiorillo <[email protected]>
+L:	[email protected]
+S:	Maintained
+F:	drivers/media/i2c/gc5035.c
+
 GATEWORKS SYSTEM CONTROLLER (GSC) DRIVER
 M:	Tim Harvey <[email protected]>
 S:	Maintained
drivers/media/i2c/Kconfig +10 -0
index b9961f77f..bde998fca 100644
@@ -110,6 +110,16 @@ config VIDEO_GC2145
 	  To compile this driver as a module, choose M here: the
 	  module will be called gc2145.
 
+config VIDEO_GC5035
+	tristate "GalaxyCore GC5035 sensor support"
+	select V4L2_CCI_I2C
+	help
+	  This is a Video4Linux2 sensor driver for the GalaxyCore GC5035
+	  5 Mpixel camera.
+
+	  To compile this driver as a module, choose M here: the
+	  module will be called gc5035.
+
 config VIDEO_HI556
 	tristate "Hynix Hi-556 sensor support"
 	help
drivers/media/i2c/Makefile +1 -0
index 351c41ef2..c3a7f39bd 100644
@@ -42,6 +42,7 @@ obj-$(CONFIG_VIDEO_GC0310) += gc0310.o
 obj-$(CONFIG_VIDEO_GC05A2) += gc05a2.o
 obj-$(CONFIG_VIDEO_GC08A3) += gc08a3.o
 obj-$(CONFIG_VIDEO_GC2145) += gc2145.o
+obj-$(CONFIG_VIDEO_GC5035) += gc5035.o
 obj-$(CONFIG_VIDEO_HI556) += hi556.o
 obj-$(CONFIG_VIDEO_HI846) += hi846.o
 obj-$(CONFIG_VIDEO_HI847) += hi847.o
drivers/media/i2c/gc5035.c new file +953 -0

953 lines not on this page · raw message

Signature · 1 line
2.47.3
#2 lore raw

Re: [PATCH 1/3] media: i2c: Add GC5035 image sensor driver

Quoted 4 lines · Nicola Fiorillo

Add a driver for the GalaxyCore GC5035, a 5 Mpixel raw Bayer sensor with a two lane MIPI CSI-2 interface. The driver supports a single 2592x1944 mode, and the exposure, analogue gain, vertical blanking and test pattern controls.

Please make the driver freely configurable, with support for analog crop (and binning if supported by the device).

Quoted 12 lines

The register tables come from the Alder Lake-M driver in intel/ipu6-drivers, which derives from the ChromeOS driver posted in 2020.

Assisted-by claude-opus-5-5 coccinelle sparse smatch
---
 MAINTAINERS                |   6 +
 drivers/media/i2c/Kconfig  |  10 +
 drivers/media/i2c/Makefile |   1 +
 drivers/media/i2c/gc5035.c | 953 +++++++++++++++++++++++++++++++++++++
 4 files changed, 970 insertions(+)
 create mode 100644 drivers/media/i2c/gc5035.c
Signature · 3 lines
Regards,

Laurent Pinchart
#3 lore raw

Re: [PATCH 1/3] media: i2c: Add GC5035 image sensor driver

In reply to Nicola Fiorillo
Quoted 1 line · Nicola Fiorillo

+#include <linux/mod_devicetable.h>

Please don't use linux/mod_devicetable.h, the needed *_device_id structures are already provided by the respective subsystem headers.

drivers/media/i2c/gc5035.c line 935

Quoted 2 lines
drivers/media/i2c/gc5035.c new file +2 -0
+static const struct acpi_device_id gc5035_acpi_ids[] = {
+	{ "GCTI5035" },
	{ .id = "GCTI5035" },

drivers/media/i2c/gc5035.c line 938

Quoted 3 lines
drivers/media/i2c/gc5035.c new file +3 -0
+	{ }
+};
+MODULE_DEVICE_TABLE(acpi, gc5035_acpi_ids);

Best regards
Uwe

#4 lore raw

PATCH 2/3 media: i2c: Add GC8034 image sensor driver

In reply to Nicola Fiorillo

Add a driver for the GalaxyCore GC8034, an 8 Mpixel raw Bayer sensor with a four lane MIPI CSI-2 interface. The driver supports a single 3264x2448 mode, and the exposure, analogue gain and vertical blanking controls.

The register tables come from the Rockchip BSP driver.

Assisted-by claude-opus-5-5 coccinelle sparse smatch
---
 MAINTAINERS                |   6 +
 drivers/media/i2c/Kconfig  |  10 +
 drivers/media/i2c/Makefile |   1 +
 drivers/media/i2c/gc8034.c | 969 +++++++++++++++++++++++++++++++++++++
 4 files changed, 986 insertions(+)
 create mode 100644 drivers/media/i2c/gc8034.c
MAINTAINERS +6 -0
index c4d5f81f4..ba60329a2 100644
@@ -10881,6 +10881,12 @@ L:	[email protected]
 S:	Maintained
 F:	drivers/media/i2c/gc5035.c
 
+GALAXYCORE GC8034 CAMERA SENSOR DRIVER
+M:	Nicola Fiorillo <[email protected]>
+L:	[email protected]
+S:	Maintained
+F:	drivers/media/i2c/gc8034.c
+
 GATEWORKS SYSTEM CONTROLLER (GSC) DRIVER
 M:	Tim Harvey <[email protected]>
 S:	Maintained
drivers/media/i2c/Kconfig +10 -0
index bde998fca..80e0d1428 100644
@@ -120,6 +120,16 @@ config VIDEO_GC5035
 	  To compile this driver as a module, choose M here: the
 	  module will be called gc5035.
 
+config VIDEO_GC8034
+	tristate "GalaxyCore GC8034 sensor support"
+	select V4L2_CCI_I2C
+	help
+	  This is a Video4Linux2 sensor driver for the GalaxyCore GC8034
+	  8 Mpixel camera.
+
+	  To compile this driver as a module, choose M here: the
+	  module will be called gc8034.
+
 config VIDEO_HI556
 	tristate "Hynix Hi-556 sensor support"
 	help
drivers/media/i2c/Makefile +1 -0
index c3a7f39bd..2c00dc96d 100644
@@ -43,6 +43,7 @@ obj-$(CONFIG_VIDEO_GC05A2) += gc05a2.o
 obj-$(CONFIG_VIDEO_GC08A3) += gc08a3.o
 obj-$(CONFIG_VIDEO_GC2145) += gc2145.o
 obj-$(CONFIG_VIDEO_GC5035) += gc5035.o
+obj-$(CONFIG_VIDEO_GC8034) += gc8034.o
 obj-$(CONFIG_VIDEO_HI556) += hi556.o
 obj-$(CONFIG_VIDEO_HI846) += hi846.o
 obj-$(CONFIG_VIDEO_HI847) += hi847.o
drivers/media/i2c/gc8034.c new file +969 -0

969 lines not on this page · raw message

Signature · 1 line
2.47.3
#5 lore raw

PATCH 3/3 media: ipu-bridge: Add GalaxyCore GC5035 and GC8034

In reply to Nicola Fiorillo

Add the GC5035 and GC8034 ACPI HIDs, with the link frequencies the two sensors use with a 19.2 MHz external clock. Both are found on the CHUWI Hi10 X1.

Assisted-by claude-opus-5-5
---
 drivers/media/pci/intel/ipu-bridge.c | 4 ++++
 1 file changed, 4 insertions(+)
drivers/media/pci/intel/ipu-bridge.c +4 -0
index 3739c4a2a..851096d7d 100644
@@ -59,6 +59,10 @@ static const u16 ipu6_ov5693_ncont_clk[] = {
 };
 
 static const struct ipu_sensor_config ipu_supported_sensors[] = {
+	/* GalaxyCore GC5035 */
+	IPU_SENSOR_CONFIG("GCTI5035", 1, 422400000),
+	/* GalaxyCore GC8034 */
+	IPU_SENSOR_CONFIG("GCTI8034", 1, 268800000),
 	/* Himax HM1092 */
 	IPU_SENSOR_CONFIG("HIMX1092", 2, 180000000, 180480000),
 	/* Himax HM11B1 */
Signature · 1 line
2.47.3
Reviewed-by on v1 3/3
#6 lore raw

Re: [PATCH 3/3] media: ipu-bridge: Add GalaxyCore GC5035 and GC8034

Morning Nicola

Quoted 15 lines · Nicola Fiorillo

Add the GC5035 and GC8034 ACPI HIDs, with the link frequencies the two sensors use with a 19.2 MHz external clock. Both are found on the CHUWI Hi10 X1.

Assisted-by claude-opus-5-5
---
  drivers/media/pci/intel/ipu-bridge.c | 4 ++++
  1 file changed, 4 insertions(+)
drivers/media/pci/intel/ipu-bridge.c +0 -0
index 3739c4a2a..851096d7d 100644

drivers/media/pci/intel/ipu-bridge.c static const u16 ipu6_ov5693_ncont_clk[] = { · line 65

Quoted 7 lines
drivers/media/pci/intel/ipu-bridge.c +4 -0
@@ -59,6 +59,10 @@ static const u16 ipu6_ov5693_ncont_clk[] = {
  };
 
  static const struct ipu_sensor_config ipu_supported_sensors[] = {
+	/* GalaxyCore GC5035 */
+	IPU_SENSOR_CONFIG("GCTI5035", 1, 422400000),
+	/* GalaxyCore GC8034 */
+	IPU_SENSOR_CONFIG("GCTI8034", 1, 268800000),

These entries look ok:

Quoted 3 lines
drivers/media/pci/intel/ipu-bridge.c +0 -0
  	/* Himax HM1092 */
  	IPU_SENSOR_CONFIG("HIMX1092", 2, 180000000, 180480000),
  	/* Himax HM11B1 */
#7 lore raw

v2 cover media: Add GalaxyCore GC5035 and GC8034 sensor drivers

In reply to Nicola Fiorillo

Hi all,

this is v2 of the drivers for the GalaxyCore GC5035 (front camera, 2 lanes) and GC8034 (back camera, 4 lanes) sensors of the Chuwi Hi10 X1 tablet, with IPU6.

Laurent, on v1 you asked to make the drivers configurable, with analog crop and binning if the sensor supports it.

This version does the following:

- No more mode tables for the geometry: the readout window and the sensor output crop are computed from the crop rectangle every time streaming starts (patches 1 and 2).
- The crop is set with the CROP selection on the source pad (patches 4 and 5). Vertically it is an analog crop: the readout window gets smaller and the frame gets shorter (the GC5035 at 640x480 runs at up to 106 fps). Horizontally it is the sensor internal output crop instead: narrowing the readout window horizontally gives black images on the GC5035, and on the GC8034 it goes through a column register that gives corrupted images at many values.
- 2x2 binning is there on the GC5035 (patches 6 and 7): the 1296x972 format gives the average of four samples of the same colour, with the same field of view as the default crop. The vendor sequence changes the PLL, so I measured the link frequency in that mode: 176.3 +/- 0.9 MHz, against the 175.2 MHz given by the PLL registers (with the same method, at full resolution, 420.7 +/- 1.5 against 422.4). Patch 6 adds this frequency to ipu-bridge. On the GC8034 binning only exists in the 2-lane vendor sequences; with 4 lanes it breaks the CSI-2 stream, so it isn't there.

I kept the crop in patches 4 and 5 and the binning in 6 and 7, separate, because I saw that for the IMX908 you decided to postpone the crop until the common raw sensor model (<[email protected]>). If you want to do the same here, patches 1-3 work on their own, at a fixed resolution like v1, and I'll redo crop and binning on the common model when it lands.

Some choices you may disagree with, and that I'm happy to change:

- set_fmt changes the crop: for userspace that does not set the crop first, it centres it on the default crop, as ov01a10 does. And 1296x972 selects binning and sets the default crop back, unless the crop is already 1296x972: libcamera first sets the largest size and then the one it wants, and with binning tied to the current crop it never got it. If you prefer binning through COMPOSE, or waiting for the common model, I'll change it.
- In binning the timings are in sensor lines (the sensor reads one row of the array per line and outputs one every two lines): exposure and VBLANK keep the register unit, with a one line step, and the frame period computed from HBLANK and VBLANK is the measured one. This is why PIXEL_RATE is 70.08 MHz, HBLANK 164 and VBLANK at least 1024.
- enum_frame_size lists 1296x972 separately, although it is within the full mode range, so that libcamera sees the binned mode.
- The GC8034 PIXEL_RATE (256 MHz) is the one that gives the measured frame periods with the sensor line length; it is more than the 4-lane link carries (215 Mpixel/s), but over a whole line, blanking included, the average is about 196 Mpixel/s.
- The analogue gain is the index of the sensor gain steps, which are not linear, as in the vendor code.

I don't have the datasheets: I measured the geometry, the limits and the timings on the tablet, and the comments in the code say what is measured. In short:

- The sizes reported as NATIVE_SIZE and CROP_BOUNDS (2608x1964 and 3282x2500) are the largest area that gives image data; around it there are constant rows and columns. They are not the physical array, which is not documented.
- CROP_DEFAULT is the image of the vendor sequence, the same as v1: at the default crop v2 produces the same image as v1.
- The timings follow a model that matches the measurements from 64 lines to the full height; for the GC8034 this corrected PIXEL_RATE to 256 MHz (v1 declared 255.9 MHz).
- The size limits (GC8034 at least 512 and at most 3280 wide, at most 2448 high; GC5035 at least 64x64) come from tests where outside those limits the stream breaks or the timings leave the model.

The series is based on media next (d7e7bca71). I tested it on the tablet, with a 7.3-rc1 kernel and the modules built from these patches:
- v4l2-compliance from git (1616bf9e3c81) with -z: 54/54, no warnings, on both, and on the GC5035 both at full resolution and in binning; full output below.
- A set of crop tests (default, bounds, centre, corners, minimum, requests to be rounded or outside the area): rectangle applied, measured frame period, complete frames and position to the pixel, all as expected, in two runs per sensor.
- Binning: controls, frame period (also with a long VBLANK and at the maximum exposure), signal doubling with double exposure, output equal to the per-colour 2x2 average of a full resolution frame with no offset, 20 starts and stops in a row, and switching from the full mode to binning.
- libcamera (simple pipeline): 60 frames out of 60 in three configurations per camera; on the GC5035 at 1280x960 it picks binning.
- W=1, sparse, smatch, checkpatch --strict and coccinelle clean on every patch; i386 build clean.

Changes since v1:
- Patches 1 and 2: geometry removed from the register table and computed from the crop, all written as 16-bit values; NATIVE_SIZE and CROP_BOUNDS are the measured area instead of the vendor readout window; the default exposure no longer exceeds the maximum when VBLANK is reduced; GC8034:
PIXEL_RATE set to 256 MHz and the blanking register computed from VBLANK; dropped linux/mod_devicetable.h and used a designated initializer in the ACPI table, as Uwe asked.
- Added Dan's Reviewed-by to patch 3.
- Patches 4, 5, 6 and 7: new.

I used a frontier LLM (Claude) to write the code and to do the measurements; I stated it in the Assisted-by tags. The English of this letter is a translation from my Italian.

Nicola

v4l2-compliance (git 1616bf9e3c81, -z PCI:0000:00:05.0 -u <subdev>):

GC5035 (2592x1944):

v4l2-compliance 1.33.0-5515, 64 bits, 64-bit time_t v4l2-compliance SHA: 1616bf9e3c81 2026-10-06 07:30:20

Compliance test for intel-ipu6 device /dev/v4l-subdev4:

Driver Info:

	Driver version   : 7.3.0
	Capabilities     : 0x00000000
	Client Capabilities: 0x0000000000000002
interval-uses-which Media Driver Info:
	Driver name      : intel-ipu6
	Model            : ipu6
	Serial           : 
	Bus info         : PCI:0000:00:05.0
	Media version    : 7.3.0
	Hardware revision: 0x00000000 (0)
	Driver version   : 7.3.0
Interface Info:
	ID               : 0x030001fd
	Type             : V4L Sub-Device
Entity Info:
	ID               : 0x000001f9 (505)
	Name             : gc5035 2-003f
	Function         : Camera Sensor
	Pad 0x010001fa   : 0: Source
	  Link 0x020001fb: to remote pad 0x1000096 of entity 'Intel IPU6 CSI2 2' (Video Interface Bridge): Data, Enabled, Immutable

Required ioctls:
test MC information (see 'Media Driver Info' above): OK test VIDIOC_SUDBEV_QUERYCAP: OK
test invalid ioctls: OK

Allow for multiple opens:
test second /dev/v4l-subdev4 open: OK
test VIDIOC_SUBDEV_QUERYCAP: OK
test for unlimited opens: OK

Debug ioctls:
test VIDIOC_LOG_STATUS: OK (Not Supported)

Input ioctls:
test VIDIOC_G/S_TUNER/ENUM_FREQ_BANDS: OK (Not Supported) test VIDIOC_G/S_FREQUENCY: OK (Not Supported) test VIDIOC_S_HW_FREQ_SEEK: OK (Not Supported) test VIDIOC_ENUMAUDIO: OK (Not Supported)
test VIDIOC_G/S/ENUMINPUT: OK (Not Supported) test VIDIOC_G/S_AUDIO: OK (Not Supported)
Inputs: 0 Audio Inputs: 0 Tuners: 0

Output ioctls:
test VIDIOC_G/S_MODULATOR: OK (Not Supported) test VIDIOC_G/S_FREQUENCY: OK (Not Supported) test VIDIOC_ENUMAUDOUT: OK (Not Supported) test VIDIOC_G/S/ENUMOUTPUT: OK (Not Supported) test VIDIOC_G/S_AUDOUT: OK (Not Supported)
Outputs: 0 Audio Outputs: 0 Modulators: 0

Input/Output configuration ioctls:
test VIDIOC_ENUM/G/S/QUERY_STD: OK (Not Supported) test VIDIOC_ENUM/G/S/QUERY_DV_TIMINGS: OK (Not Supported) test VIDIOC_DV_TIMINGS_CAP: OK (Not Supported) test VIDIOC_G/S_EDID: OK (Not Supported)

Sub-Device ioctls (Source Pad 0):
Try Stream 0
test Try VIDIOC_SUBDEV_ENUM_MBUS_CODE/FRAME_SIZE/FRAME_INTERVAL: OK test Try VIDIOC_SUBDEV_G/S_FMT: OK
test Try VIDIOC_SUBDEV_G/S_SELECTION/CROP: OK
Active Stream 0
test Active VIDIOC_SUBDEV_ENUM_MBUS_CODE/FRAME_SIZE/FRAME_INTERVAL: OK test Active VIDIOC_SUBDEV_G/S_FMT: OK
test Active VIDIOC_SUBDEV_G/S_SELECTION/CROP: OK
test Active VIDIOC_SUBDEV_G/S_FRAME_INTERVAL: OK (Not Supported)

Control ioctls:
test VIDIOC_QUERY_EXT_CTRL/QUERYMENU: OK test VIDIOC_QUERYCTRL: OK
test VIDIOC_G/S_CTRL: OK
test VIDIOC_G/S/TRY_EXT_CTRLS: OK test VIDIOC_(UN)SUBSCRIBE_EVENT/DQEVENT: OK test VIDIOC_G/S_JPEGCOMP: OK (Not Supported) Standard Controls: 13 Private Controls: 0

Format ioctls:
test VIDIOC_ENUM_FMT/FRAMESIZES/FRAMEINTERVALS: OK (Not Supported) test VIDIOC_G/S_PARM: OK (Not Supported)
test VIDIOC_G_FBUF: OK (Not Supported)
test VIDIOC_G_FMT: OK (Not Supported)
test VIDIOC_TRY_FMT: OK (Not Supported)
test VIDIOC_S_FMT: OK (Not Supported)
test VIDIOC_G_SLICED_VBI_CAP: OK (Not Supported)
test Cropping: OK (Not Supported)
test Composing: OK (Not Supported)
test Scaling: OK (Not Supported)

Codec ioctls:
test VIDIOC_(TRY_)ENCODER_CMD: OK (Not Supported) test VIDIOC_G_ENC_INDEX: OK (Not Supported) test VIDIOC_(TRY_)DECODER_CMD: OK (Not Supported)

Buffer ioctls:
test VIDIOC_REQBUFS/CREATE_BUFS/QUERYBUF: OK (Not Supported) test CREATE_BUFS maximum buffers: OK
test VIDIOC_REMOVE_BUFS: OK
test VIDIOC_EXPBUF: OK (Not Supported)
test Requests: OK (Not Supported)
test blocking wait: OK (Not Supported)

Total for intel-ipu6 device /dev/v4l-subdev4: 54, Succeeded: 54, Failed: 0, Warnings: 0

GC5035 in binning (1296x972), same output except:

Total for intel-ipu6 device /dev/v4l-subdev4: 54, Succeeded: 54, Failed: 0, Warnings: 0

GC8034:

v4l2-compliance 1.33.0-5515, 64 bits, 64-bit time_t v4l2-compliance SHA: 1616bf9e3c81 2026-10-06 07:30:20

Compliance test for intel-ipu6 device /dev/v4l-subdev5:

Driver Info:

	Driver version   : 7.3.0
	Capabilities     : 0x00000000
	Client Capabilities: 0x0000000000000002
interval-uses-which Media Driver Info:
	Driver name      : intel-ipu6
	Model            : ipu6
	Serial           : 
	Bus info         : PCI:0000:00:05.0
	Media version    : 7.3.0
	Hardware revision: 0x00000000 (0)
	Driver version   : 7.3.0
Interface Info:
	ID               : 0x03000203
	Type             : V4L Sub-Device
Entity Info:
	ID               : 0x000001ff (511)
	Name             : gc8034 1-0037
	Function         : Camera Sensor
	Pad 0x01000200   : 0: Source
	  Link 0x02000201: to remote pad 0x100008c of entity 'Intel IPU6 CSI2 1' (Video Interface Bridge): Data, Enabled, Immutable

Required ioctls:
test MC information (see 'Media Driver Info' above): OK test VIDIOC_SUDBEV_QUERYCAP: OK
test invalid ioctls: OK

Allow for multiple opens:
test second /dev/v4l-subdev5 open: OK
test VIDIOC_SUBDEV_QUERYCAP: OK
test for unlimited opens: OK

Debug ioctls:
test VIDIOC_LOG_STATUS: OK (Not Supported)

Input ioctls:
test VIDIOC_G/S_TUNER/ENUM_FREQ_BANDS: OK (Not Supported) test VIDIOC_G/S_FREQUENCY: OK (Not Supported) test VIDIOC_S_HW_FREQ_SEEK: OK (Not Supported) test VIDIOC_ENUMAUDIO: OK (Not Supported)
test VIDIOC_G/S/ENUMINPUT: OK (Not Supported) test VIDIOC_G/S_AUDIO: OK (Not Supported)
Inputs: 0 Audio Inputs: 0 Tuners: 0

Output ioctls:
test VIDIOC_G/S_MODULATOR: OK (Not Supported) test VIDIOC_G/S_FREQUENCY: OK (Not Supported) test VIDIOC_ENUMAUDOUT: OK (Not Supported) test VIDIOC_G/S/ENUMOUTPUT: OK (Not Supported) test VIDIOC_G/S_AUDOUT: OK (Not Supported)
Outputs: 0 Audio Outputs: 0 Modulators: 0

Input/Output configuration ioctls:
test VIDIOC_ENUM/G/S/QUERY_STD: OK (Not Supported) test VIDIOC_ENUM/G/S/QUERY_DV_TIMINGS: OK (Not Supported) test VIDIOC_DV_TIMINGS_CAP: OK (Not Supported) test VIDIOC_G/S_EDID: OK (Not Supported)

Sub-Device ioctls (Source Pad 0):
Try Stream 0
test Try VIDIOC_SUBDEV_ENUM_MBUS_CODE/FRAME_SIZE/FRAME_INTERVAL: OK test Try VIDIOC_SUBDEV_G/S_FMT: OK
test Try VIDIOC_SUBDEV_G/S_SELECTION/CROP: OK
Active Stream 0
test Active VIDIOC_SUBDEV_ENUM_MBUS_CODE/FRAME_SIZE/FRAME_INTERVAL: OK test Active VIDIOC_SUBDEV_G/S_FMT: OK
test Active VIDIOC_SUBDEV_G/S_SELECTION/CROP: OK
test Active VIDIOC_SUBDEV_G/S_FRAME_INTERVAL: OK (Not Supported)

Control ioctls:
test VIDIOC_QUERY_EXT_CTRL/QUERYMENU: OK test VIDIOC_QUERYCTRL: OK
test VIDIOC_G/S_CTRL: OK
test VIDIOC_G/S/TRY_EXT_CTRLS: OK test VIDIOC_(UN)SUBSCRIBE_EVENT/DQEVENT: OK test VIDIOC_G/S_JPEGCOMP: OK (Not Supported) Standard Controls: 12 Private Controls: 0

Format ioctls:
test VIDIOC_ENUM_FMT/FRAMESIZES/FRAMEINTERVALS: OK (Not Supported) test VIDIOC_G/S_PARM: OK (Not Supported)
test VIDIOC_G_FBUF: OK (Not Supported)
test VIDIOC_G_FMT: OK (Not Supported)
test VIDIOC_TRY_FMT: OK (Not Supported)
test VIDIOC_S_FMT: OK (Not Supported)
test VIDIOC_G_SLICED_VBI_CAP: OK (Not Supported)
test Cropping: OK (Not Supported)
test Composing: OK (Not Supported)
test Scaling: OK (Not Supported)

Codec ioctls:
test VIDIOC_(TRY_)ENCODER_CMD: OK (Not Supported) test VIDIOC_G_ENC_INDEX: OK (Not Supported) test VIDIOC_(TRY_)DECODER_CMD: OK (Not Supported)

Buffer ioctls:
test VIDIOC_REQBUFS/CREATE_BUFS/QUERYBUF: OK (Not Supported) test CREATE_BUFS maximum buffers: OK
test VIDIOC_REMOVE_BUFS: OK
test VIDIOC_EXPBUF: OK (Not Supported)
test Requests: OK (Not Supported)
test blocking wait: OK (Not Supported)

Total for intel-ipu6 device /dev/v4l-subdev5: 54, Succeeded: 54, Failed: 0, Warnings: 0

Nicola Fiorillo (7):
media: i2c: Add GC5035 image sensor driver
media: i2c: Add GC8034 image sensor driver
media: ipu-bridge: Add GalaxyCore GC5035 and GC8034
media: i2c: gc5035: Add crop support
media: i2c: gc8034: Add crop support
media: ipu-bridge: Add the GC5035 binning link frequency
media: i2c: gc5035: Add 2x2 binning support

 MAINTAINERS                          |   12 +
 drivers/media/i2c/Kconfig            |   20 +
 drivers/media/i2c/Makefile           |    2 +
 drivers/media/i2c/gc5035.c           | 1351 ++++++++++++++++++++++++++
 drivers/media/i2c/gc8034.c           | 1175 ++++++++++++++++++++++
 drivers/media/pci/intel/ipu-bridge.c |    4 +
 6 files changed, 2564 insertions(+)
 create mode 100644 drivers/media/i2c/gc5035.c
 create mode 100644 drivers/media/i2c/gc8034.c

base-commit: d7e7bca7169873b46e857c025c10f3336c1258d8

Signature · 1 line
2.47.3
#8 lore raw

PATCH v2 1/7 media: i2c: Add GC5035 image sensor driver

Add a driver for the GalaxyCore GC5035, a 5 Mpixel raw Bayer sensor with a two lane MIPI CSI-2 interface. The driver supports the exposure, analogue gain, vertical blanking and test pattern controls, and outputs 2592x1944 RAW10.

I don't have a datasheet for the sensor. The initialisation sequence comes from the Alder Lake-M driver in intel/ipu6-drivers, which derives from the ChromeOS driver posted in 2020. The readout window and the output crop are not part of the sequence: they are computed from the crop rectangle, in the coordinates of the largest area measured to give image data (2608x1964). The driver reports that area as the native size and the crop bounds; it is not the physical pixel array. The default crop rectangle gives the same image as the vendor sequence. The frame period, (height + vblank) * 2920 / 168.96 MHz, matches the measurements.

Assisted-by claude-opus-5-5 coccinelle sparse smatch
---
 MAINTAINERS                |    6 +
 drivers/media/i2c/Kconfig  |   10 +
 drivers/media/i2c/Makefile |    1 +
 drivers/media/i2c/gc5035.c | 1002 ++++++++++++++++++++++++++++++++++++
 4 files changed, 1019 insertions(+)
 create mode 100644 drivers/media/i2c/gc5035.c
MAINTAINERS +6 -0
index 760791e36..ca264ceef 100644
@@ -10875,6 +10875,12 @@ T:	git git://linuxtv.org/media.git
 F:	Documentation/devicetree/bindings/media/i2c/galaxycore,gc2145.yaml
 F:	drivers/media/i2c/gc2145.c
 
+GALAXYCORE GC5035 CAMERA SENSOR DRIVER
+M:	Nicola Fiorillo <[email protected]>
+L:	[email protected]
+S:	Maintained
+F:	drivers/media/i2c/gc5035.c
+
 GATEWORKS SYSTEM CONTROLLER (GSC) DRIVER
 M:	Tim Harvey <[email protected]>
 S:	Maintained
drivers/media/i2c/Kconfig +10 -0
index 7de2d095c..fca5bcf98 100644
@@ -110,6 +110,16 @@ config VIDEO_GC2145
 	  To compile this driver as a module, choose M here: the
 	  module will be called gc2145.
 
+config VIDEO_GC5035
+	tristate "GalaxyCore GC5035 sensor support"
+	select V4L2_CCI_I2C
+	help
+	  This is a Video4Linux2 sensor driver for the GalaxyCore GC5035
+	  5 Mpixel camera.
+
+	  To compile this driver as a module, choose M here: the
+	  module will be called gc5035.
+
 config VIDEO_HI556
 	tristate "Hynix Hi-556 sensor support"
 	help
drivers/media/i2c/Makefile +1 -0
index 59e31af45..bb8552bbd 100644
@@ -42,6 +42,7 @@ obj-$(CONFIG_VIDEO_GC0310) += gc0310.o
 obj-$(CONFIG_VIDEO_GC05A2) += gc05a2.o
 obj-$(CONFIG_VIDEO_GC08A3) += gc08a3.o
 obj-$(CONFIG_VIDEO_GC2145) += gc2145.o
+obj-$(CONFIG_VIDEO_GC5035) += gc5035.o
 obj-$(CONFIG_VIDEO_HI556) += hi556.o
 obj-$(CONFIG_VIDEO_HI846) += hi846.o
 obj-$(CONFIG_VIDEO_HI847) += hi847.o
drivers/media/i2c/gc5035.c new file +1002 -0

1,002 lines not on this page · raw message

Signature · 1 line
2.47.3
#9 lore raw

PATCH v2 2/7 media: i2c: Add GC8034 image sensor driver

In reply to Nicola Fiorillo

Add a driver for the GalaxyCore GC8034, an 8 Mpixel raw Bayer sensor with a four lane MIPI CSI-2 interface. The driver supports the exposure, analogue gain and vertical blanking controls, and outputs 3264x2448 RAW10.

I don't have a datasheet for the sensor. The initialisation sequence comes from the Rockchip BSP driver. The readout window, the output crop and the CSI-2 line length are computed from the crop rectangle, in the coordinates of a 3282x2500 area measured to contain image data. The driver reports that area as the native size and the crop bounds; it is not the physical pixel array. The default crop rectangle gives the same image as the vendor sequence. A frame lasts the readout window plus 20 lines plus the blanking register, which therefore holds vblank minus 36. The pixel rate, 256 MHz, is the one that gives the measured frame periods, from 1.869 ms for 112 frame lines to 41.653 ms for 2496 frame lines.

Assisted-by claude-opus-5-5 coccinelle sparse smatch
---
 MAINTAINERS                |    6 +
 drivers/media/i2c/Kconfig  |   10 +
 drivers/media/i2c/Makefile |    1 +
 drivers/media/i2c/gc8034.c | 1021 ++++++++++++++++++++++++++++++++++++
 4 files changed, 1038 insertions(+)
 create mode 100644 drivers/media/i2c/gc8034.c
MAINTAINERS +6 -0
index ca264ceef..a51768324 100644
@@ -10881,6 +10881,12 @@ L:	[email protected]
 S:	Maintained
 F:	drivers/media/i2c/gc5035.c
 
+GALAXYCORE GC8034 CAMERA SENSOR DRIVER
+M:	Nicola Fiorillo <[email protected]>
+L:	[email protected]
+S:	Maintained
+F:	drivers/media/i2c/gc8034.c
+
 GATEWORKS SYSTEM CONTROLLER (GSC) DRIVER
 M:	Tim Harvey <[email protected]>
 S:	Maintained
drivers/media/i2c/Kconfig +10 -0
index fca5bcf98..f9fdb7b51 100644
@@ -120,6 +120,16 @@ config VIDEO_GC5035
 	  To compile this driver as a module, choose M here: the
 	  module will be called gc5035.
 
+config VIDEO_GC8034
+	tristate "GalaxyCore GC8034 sensor support"
+	select V4L2_CCI_I2C
+	help
+	  This is a Video4Linux2 sensor driver for the GalaxyCore GC8034
+	  8 Mpixel camera.
+
+	  To compile this driver as a module, choose M here: the
+	  module will be called gc8034.
+
 config VIDEO_HI556
 	tristate "Hynix Hi-556 sensor support"
 	help
drivers/media/i2c/Makefile +1 -0
index bb8552bbd..d177cc3d6 100644
@@ -43,6 +43,7 @@ obj-$(CONFIG_VIDEO_GC05A2) += gc05a2.o
 obj-$(CONFIG_VIDEO_GC08A3) += gc08a3.o
 obj-$(CONFIG_VIDEO_GC2145) += gc2145.o
 obj-$(CONFIG_VIDEO_GC5035) += gc5035.o
+obj-$(CONFIG_VIDEO_GC8034) += gc8034.o
 obj-$(CONFIG_VIDEO_HI556) += hi556.o
 obj-$(CONFIG_VIDEO_HI846) += hi846.o
 obj-$(CONFIG_VIDEO_HI847) += hi847.o
drivers/media/i2c/gc8034.c new file +1021 -0

1,021 lines not on this page · raw message

Signature · 1 line
2.47.3
#10 lore raw

PATCH v2 3/7 media: ipu-bridge: Add GalaxyCore GC5035 and GC8034

In reply to Nicola Fiorillo

Add the GC5035 and GC8034 ACPI HIDs, with the link frequencies the two sensors use with a 19.2 MHz external clock. Both are found on the CHUWI Hi10 X1.

Assisted-by claude-opus-5-5
---
 drivers/media/pci/intel/ipu-bridge.c | 4 ++++
 1 file changed, 4 insertions(+)
drivers/media/pci/intel/ipu-bridge.c +4 -0
index 3739c4a2a..851096d7d 100644
@@ -59,6 +59,10 @@ static const u16 ipu6_ov5693_ncont_clk[] = {
 };
 
 static const struct ipu_sensor_config ipu_supported_sensors[] = {
+	/* GalaxyCore GC5035 */
+	IPU_SENSOR_CONFIG("GCTI5035", 1, 422400000),
+	/* GalaxyCore GC8034 */
+	IPU_SENSOR_CONFIG("GCTI8034", 1, 268800000),
 	/* Himax HM1092 */
 	IPU_SENSOR_CONFIG("HIMX1092", 2, 180000000, 180480000),
 	/* Himax HM11B1 */
Signature · 1 line
2.47.3
#11 lore raw

PATCH v2 4/7 media: i2c: gc5035: Add crop support

In reply to Nicola Fiorillo

Implement the crop selection on the source pad. The vertical crop is done by the readout window, which shortens the frame: 640x480 runs at up to 106 fps with the minimum vertical blanking. The horizontal crop is done by the sensor output crop, as a narrower readout window gives black images and the column start register only moves in steps of four columns, with even values giving corrupted images. Crop offsets are even, to keep the GRBG order, and sizes are multiples of 4, from 64x64 to 2608x1964.

Without binning or scaling, the format size is the crop size. As in ov01a10, set_fmt centres the crop rectangle on CROP_DEFAULT for userspace that does not set the crop first, and setting the format or the crop rectangle resets the vertical blanking to its default. The crop and the format can't be changed while streaming.

Tested with v4l2-compliance (54/54, no warning) and with crop rectangles at the bounds, in the corners, at the minimum size and in the centre: the position was checked to the pixel and the frame period is the computed one.

Assisted-by claude-opus-5-5 coccinelle sparse smatch
---
 drivers/media/i2c/gc5035.c | 167 ++++++++++++++++++++++++++++++++++---
 1 file changed, 157 insertions(+), 10 deletions(-)
drivers/media/i2c/gc5035.c +157 -10
index 87c3742f1..b7190aa52 100644
@@ -11,6 +11,7 @@
  * Liang Wang <[email protected]>, derived from the ChromeOS series by
  * Tomasz Figa <[email protected]>.
  */
+#include <linux/align.h>
 #include <linux/array_size.h>
 #include <linux/clk.h>
 #include <linux/container_of.h>
@@ -20,6 +21,7 @@
 #include <linux/gpio/consumer.h>
 #include <linux/i2c.h>
 #include <linux/math.h>
+#include <linux/minmax.h>
 #include <linux/module.h>
 #include <linux/pm_runtime.h>
 #include <linux/property.h>
@@ -106,6 +108,8 @@
 #define GC5035_CROP_TOP			8
 #define GC5035_WIDTH			2592
 #define GC5035_HEIGHT			1944
+#define GC5035_MIN_WIDTH		64
+#define GC5035_MIN_HEIGHT		64
 
 /*
  * The line length register counts units of 4 pixels. The frame length is the
@@ -207,6 +211,7 @@ struct gc5035 {
 
 	struct v4l2_ctrl_handler ctrls;
 	struct v4l2_ctrl *exposure;
+	struct v4l2_ctrl *vblank;
 	struct v4l2_ctrl *hblank;
 
 	struct regmap *regmap;
@@ -463,14 +468,58 @@ static int gc5035_enum_frame_size(struct v4l2_subdev *sd,
 	if (fse->index > 0)
 		return -EINVAL;
 
-	fse->min_width = GC5035_WIDTH;
-	fse->max_width = GC5035_WIDTH;
-	fse->min_height = GC5035_HEIGHT;
-	fse->max_height = GC5035_HEIGHT;
+	/* The output size is the size of the crop rectangle. */
+	fse->min_width = GC5035_MIN_WIDTH;
+	fse->max_width = GC5035_AREA_WIDTH;
+	fse->min_height = GC5035_MIN_HEIGHT;
+	fse->max_height = GC5035_AREA_HEIGHT;
 
 	return 0;
 }
 
+/*
+ * Update the controls that depend on the output size. Called with the state
+ * lock held, which is also the control handler lock.
+ */
+static int gc5035_update_ctrls(struct gc5035 *gc5035,
+			       const struct v4l2_mbus_framefmt *format)
+{
+	s64 vblank_max, exposure_max;
+	int ret;
+
+	ret = __v4l2_ctrl_modify_range(gc5035->hblank,
+				       GC5035_HTS - format->width,
+				       GC5035_HTS - format->width, 1,
+				       GC5035_HTS - format->width);
+	if (ret)
+		return ret;
+
+	vblank_max = GC5035_VBLANK_MIN +
+		     round_down(GC5035_VTS_MAX - format->height -
+				GC5035_VBLANK_MIN, GC5035_VBLANK_STEP);
+	/*
+	 * As in ov01a10, setting the format or the crop rectangle resets the
+	 * vertical blanking.
+	 */
+	ret = __v4l2_ctrl_modify_range(gc5035->vblank, GC5035_VBLANK_MIN,
+				       vblank_max, GC5035_VBLANK_STEP,
+				       GC5035_VBLANK_MIN);
+	if (ret)
+		return ret;
+
+	ret = __v4l2_ctrl_s_ctrl(gc5035->vblank, GC5035_VBLANK_MIN);
+	if (ret)
+		return ret;
+
+	exposure_max = format->height + gc5035->vblank->val -
+		       GC5035_EXP_MARGIN;
+
+	return __v4l2_ctrl_modify_range(gc5035->exposure, GC5035_EXP_MIN,
+					exposure_max, GC5035_EXP_STEP,
+					min_t(s64, GC5035_EXP_DEF,
+					      exposure_max));
+}
+
 static void gc5035_fill_format(struct v4l2_mbus_framefmt *fmt,
 			       const struct v4l2_rect *crop)
 {
@@ -513,6 +562,98 @@ static int gc5035_get_selection(struct v4l2_subdev *sd,
 	return 0;
 }
 
+static int gc5035_set_selection(struct v4l2_subdev *sd,
+				const struct v4l2_subdev_client_info *ci,
+				struct v4l2_subdev_state *state,
+				struct v4l2_subdev_selection *sel)
+{
+	struct gc5035 *gc5035 = to_gc5035(sd);
+	struct v4l2_mbus_framefmt *format;
+	struct v4l2_rect rect;
+
+	if (sel->target != V4L2_SEL_TGT_CROP)
+		return -EINVAL;
+
+	if (sel->which == V4L2_SUBDEV_FORMAT_ACTIVE &&
+	    v4l2_subdev_is_streaming(sd))
+		return -EBUSY;
+
+	/*
+	 * Even offsets keep the GRBG order. The sizes are multiples of 4: the
+	 * sensor rounds the frame length to a multiple of 4 lines.
+	 */
+	rect.left = ALIGN_DOWN(clamp(sel->r.left, 0,
+				     GC5035_AREA_WIDTH - GC5035_MIN_WIDTH), 2);
+	rect.top = ALIGN_DOWN(clamp(sel->r.top, 0,
+				    GC5035_AREA_HEIGHT - GC5035_MIN_HEIGHT), 2);
+	rect.width = ALIGN_DOWN(clamp_t(u32, sel->r.width, GC5035_MIN_WIDTH,
+					GC5035_AREA_WIDTH - rect.left), 4);
+	rect.height = ALIGN_DOWN(clamp_t(u32, sel->r.height, GC5035_MIN_HEIGHT,
+					 GC5035_AREA_HEIGHT - rect.top), 4);
+
+	*v4l2_subdev_state_get_crop(state, 0) = rect;
+	sel->r = rect;
+
+	/* No binning or scaling: the output size is the crop size. */
+	format = v4l2_subdev_state_get_format(state, 0);
+	gc5035_fill_format(format, &rect);
+
+	if (sel->which == V4L2_SUBDEV_FORMAT_ACTIVE)
+		return gc5035_update_ctrls(gc5035, format);
+
+	return 0;
+}
+
+/*
+ * No binning or scaling: the output size is the size of the crop rectangle. A
+ * new width or height centres the crop rectangle on the default crop
+ * rectangle along that axis, within the area, for userspace that does not set
+ * the crop rectangle first. The default size gives the default rectangle back.
+ */
+static int gc5035_set_fmt(struct v4l2_subdev *sd,
+			  const struct v4l2_subdev_client_info *ci,
+			  struct v4l2_subdev_state *state,
+			  struct v4l2_subdev_format *fmt)
+{
+	struct gc5035 *gc5035 = to_gc5035(sd);
+	struct v4l2_mbus_framefmt *format;
+	struct v4l2_rect *crop;
+	u32 width, height;
+	int pos;
+
+	if (fmt->which == V4L2_SUBDEV_FORMAT_ACTIVE &&
+	    v4l2_subdev_is_streaming(sd))
+		return -EBUSY;
+
+	width = ALIGN_DOWN(clamp_t(u32, fmt->format.width, GC5035_MIN_WIDTH,
+				   GC5035_AREA_WIDTH), 4);
+	height = ALIGN_DOWN(clamp_t(u32, fmt->format.height, GC5035_MIN_HEIGHT,
+				    GC5035_AREA_HEIGHT), 4);
+
+	crop = v4l2_subdev_state_get_crop(state, 0);
+	if (width != crop->width) {
+		pos = GC5035_CROP_LEFT + (GC5035_WIDTH - (int)width) / 2;
+		pos = clamp(pos, 0, GC5035_AREA_WIDTH - (int)width);
+		crop->left = ALIGN_DOWN(pos, 2);
+		crop->width = width;
+	}
+	if (height != crop->height) {
+		pos = GC5035_CROP_TOP + (GC5035_HEIGHT - (int)height) / 2;
+		pos = clamp(pos, 0, GC5035_AREA_HEIGHT - (int)height);
+		crop->top = ALIGN_DOWN(pos, 2);
+		crop->height = height;
+	}
+
+	format = v4l2_subdev_state_get_format(state, 0);
+	gc5035_fill_format(format, crop);
+	fmt->format = *format;
+
+	if (fmt->which == V4L2_SUBDEV_FORMAT_ACTIVE)
+		return gc5035_update_ctrls(gc5035, format);
+
+	return 0;
+}
+
 static int gc5035_init_state(struct v4l2_subdev *sd,
 			     struct v4l2_subdev_state *state)
 {
@@ -724,7 +865,9 @@ static const struct v4l2_subdev_pad_ops gc5035_pad_ops = {
 	.enum_mbus_code = gc5035_enum_mbus_code,
 	.enum_frame_size = gc5035_enum_frame_size,
 	.get_fmt = v4l2_subdev_get_fmt,
+	.set_fmt = gc5035_set_fmt,
 	.get_selection = gc5035_get_selection,
+	.set_selection = gc5035_set_selection,
 	.get_frame_desc = gc5035_get_frame_desc,
 	.enable_streams = gc5035_enable_streams,
 	.disable_streams = gc5035_disable_streams,
@@ -799,12 +942,16 @@ static int gc5035_init_controls(struct gc5035 *gc5035)
 			  GC5035_PIXEL_RATE, GC5035_PIXEL_RATE, 1,
 			  GC5035_PIXEL_RATE);
 
-	v4l2_ctrl_new_std(ctrl_hdlr, &gc5035_ctrl_ops, V4L2_CID_VBLANK,
-			  GC5035_VBLANK_MIN,
-			  GC5035_VBLANK_MIN +
-			  round_down(GC5035_VTS_MAX - GC5035_HEIGHT -
-				     GC5035_VBLANK_MIN, GC5035_VBLANK_STEP),
-			  GC5035_VBLANK_STEP, GC5035_VBLANK_MIN);
+	/* Ranges for the default crop rectangle, see gc5035_update_ctrls(). */
+	gc5035->vblank = v4l2_ctrl_new_std(ctrl_hdlr, &gc5035_ctrl_ops,
+					   V4L2_CID_VBLANK, GC5035_VBLANK_MIN,
+					   GC5035_VBLANK_MIN +
+					   round_down(GC5035_VTS_MAX -
+						      GC5035_HEIGHT -
+						      GC5035_VBLANK_MIN,
+						      GC5035_VBLANK_STEP),
+					   GC5035_VBLANK_STEP,
+					   GC5035_VBLANK_MIN);
 
 	gc5035->hblank = v4l2_ctrl_new_std(ctrl_hdlr, NULL, V4L2_CID_HBLANK,
 					   GC5035_HTS - GC5035_WIDTH,
Signature · 1 line
2.47.3
#12 lore raw

PATCH v2 5/7 media: i2c: gc8034: Add crop support

In reply to Nicola Fiorillo

Implement the crop selection on the source pad, as for the GC5035: the vertical crop is done by the readout window, the horizontal crop by the sensor output crop, as the column start register only gives valid images at some values. Crop offsets are even, to keep the RGGB order, and sizes are multiples of 4. The width ranges from 512 to 3280: up to 384 columns the CSI-2 receiver gets corrupted frames, 448 worked and 512 is kept as a conservative minimum; an output as wide as the readout window causes CSI-2 errors. The height ranges from 64 to 2448: with readout windows taller than the vendor one (2464 rows) the frames get longer than computed.

set_fmt and the vertical blanking behave as in the GC5035 driver.

Tested in the same way as the GC5035: v4l2-compliance and crop rectangles at the bounds, in the corners, at the minimum size and in the centre.

Assisted-by claude-opus-5-5 coccinelle sparse smatch
---
 drivers/media/i2c/gc8034.c | 168 +++++++++++++++++++++++++++++++++++--
 1 file changed, 161 insertions(+), 7 deletions(-)
drivers/media/i2c/gc8034.c +161 -7
index c21fb8510..732ee6c78 100644
@@ -8,6 +8,7 @@
  * The registers and sequences come from the Rockchip BSP driver,
  * rockchip-linux/kernel, branch develop-5.10.
  */
+#include <linux/align.h>
 #include <linux/array_size.h>
 #include <linux/clk.h>
 #include <linux/container_of.h>
@@ -17,6 +18,7 @@
 #include <linux/gpio/consumer.h>
 #include <linux/i2c.h>
 #include <linux/math.h>
+#include <linux/minmax.h>
 #include <linux/module.h>
 #include <linux/pm_runtime.h>
 #include <linux/property.h>
@@ -89,6 +91,12 @@
  *
  * The default crop rectangle is the 3264x2448 image of the vendor register
  * sequence, at (8, 52) in the area.
+ *
+ * Output widths up to 384 pixels gave corrupted frames on the CSI-2 receiver,
+ * 448 pixels and above worked; 512 is kept as the minimum. With a readout
+ * window taller than the 2464 rows of the vendor sequence, the frames were
+ * longer than the timing model below by the extra rows, so the output height
+ * is limited to 2448.
  */
 #define GC8034_AREA_WIDTH		3282
 #define GC8034_AREA_HEIGHT		2500
@@ -102,6 +110,10 @@
 #define GC8034_CROP_TOP			52
 #define GC8034_WIDTH			3264
 #define GC8034_HEIGHT			2448
+#define GC8034_MIN_WIDTH		512
+#define GC8034_MIN_HEIGHT		64
+#define GC8034_MAX_WIDTH		(GC8034_WIN_WIDTH - 4)
+#define GC8034_MAX_HEIGHT		2448
 
 /*
  * The frame is the readout window plus 20 lines plus the blanking register.
@@ -210,6 +222,7 @@ struct gc8034 {
 
 	struct v4l2_ctrl_handler ctrls;
 	struct v4l2_ctrl *exposure;
+	struct v4l2_ctrl *vblank;
 	struct v4l2_ctrl *hblank;
 
 	struct regmap *regmap;
@@ -487,14 +500,55 @@ static int gc8034_enum_frame_size(struct v4l2_subdev *sd,
 	if (fse->index > 0)
 		return -EINVAL;
 
-	fse->min_width = GC8034_WIDTH;
-	fse->max_width = GC8034_WIDTH;
-	fse->min_height = GC8034_HEIGHT;
-	fse->max_height = GC8034_HEIGHT;
+	/* The output size is the size of the crop rectangle. */
+	fse->min_width = GC8034_MIN_WIDTH;
+	fse->max_width = GC8034_MAX_WIDTH;
+	fse->min_height = GC8034_MIN_HEIGHT;
+	fse->max_height = GC8034_MAX_HEIGHT;
 
 	return 0;
 }
 
+/*
+ * Update the controls that depend on the output size. Called with the state
+ * lock held, which is also the control handler lock.
+ */
+static int gc8034_update_ctrls(struct gc8034 *gc8034,
+			       const struct v4l2_mbus_framefmt *format)
+{
+	s64 exposure_max;
+	int ret;
+
+	ret = __v4l2_ctrl_modify_range(gc8034->hblank,
+				       GC8034_HTS - format->width,
+				       GC8034_HTS - format->width, 1,
+				       GC8034_HTS - format->width);
+	if (ret)
+		return ret;
+
+	/*
+	 * As in ov01a10, setting the format or the crop rectangle resets the
+	 * vertical blanking.
+	 */
+	ret = __v4l2_ctrl_modify_range(gc8034->vblank, GC8034_VBLANK_MIN,
+				       GC8034_VTS_MAX - format->height, 1,
+				       GC8034_VBLANK_MIN);
+	if (ret)
+		return ret;
+
+	ret = __v4l2_ctrl_s_ctrl(gc8034->vblank, GC8034_VBLANK_MIN);
+	if (ret)
+		return ret;
+
+	exposure_max = round_down(format->height + gc8034->vblank->val -
+				  GC8034_EXP_MARGIN, GC8034_EXP_STEP);
+
+	return __v4l2_ctrl_modify_range(gc8034->exposure, GC8034_EXP_MIN,
+					exposure_max, GC8034_EXP_STEP,
+					min_t(s64, GC8034_EXP_DEF,
+					      exposure_max));
+}
+
 static void gc8034_fill_format(struct v4l2_mbus_framefmt *fmt,
 			       const struct v4l2_rect *crop)
 {
@@ -537,6 +591,102 @@ static int gc8034_get_selection(struct v4l2_subdev *sd,
 	return 0;
 }
 
+static int gc8034_set_selection(struct v4l2_subdev *sd,
+				const struct v4l2_subdev_client_info *ci,
+				struct v4l2_subdev_state *state,
+				struct v4l2_subdev_selection *sel)
+{
+	struct gc8034 *gc8034 = to_gc8034(sd);
+	struct v4l2_mbus_framefmt *format;
+	struct v4l2_rect rect;
+	u32 max_width, max_height;
+
+	if (sel->target != V4L2_SEL_TGT_CROP)
+		return -EINVAL;
+
+	if (sel->which == V4L2_SUBDEV_FORMAT_ACTIVE &&
+	    v4l2_subdev_is_streaming(sd))
+		return -EBUSY;
+
+	/*
+	 * Even offsets keep the RGGB order. The width is a multiple of 4 so
+	 * that RAW10 lines are a whole number of bytes; only heights that are
+	 * multiples of 4 have been tested.
+	 */
+	rect.left = ALIGN_DOWN(clamp(sel->r.left, 0,
+				     GC8034_AREA_WIDTH - GC8034_MIN_WIDTH), 2);
+	rect.top = ALIGN_DOWN(clamp(sel->r.top, 0,
+				    GC8034_AREA_HEIGHT - GC8034_MIN_HEIGHT), 2);
+	max_width = min(GC8034_MAX_WIDTH, GC8034_AREA_WIDTH - rect.left);
+	max_height = min(GC8034_MAX_HEIGHT, GC8034_AREA_HEIGHT - rect.top);
+	rect.width = ALIGN_DOWN(clamp_t(u32, sel->r.width, GC8034_MIN_WIDTH,
+					max_width), 4);
+	rect.height = ALIGN_DOWN(clamp_t(u32, sel->r.height, GC8034_MIN_HEIGHT,
+					 max_height), 4);
+
+	*v4l2_subdev_state_get_crop(state, 0) = rect;
+	sel->r = rect;
+
+	/* No binning or scaling: the output size is the crop size. */
+	format = v4l2_subdev_state_get_format(state, 0);
+	gc8034_fill_format(format, &rect);
+
+	if (sel->which == V4L2_SUBDEV_FORMAT_ACTIVE)
+		return gc8034_update_ctrls(gc8034, format);
+
+	return 0;
+}
+
+/*
+ * No binning or scaling: the output size is the size of the crop rectangle. A
+ * new width or height centres the crop rectangle on the default crop
+ * rectangle along that axis, within the area, for userspace that does not set
+ * the crop rectangle first. The default size gives the default rectangle back.
+ */
+static int gc8034_set_fmt(struct v4l2_subdev *sd,
+			  const struct v4l2_subdev_client_info *ci,
+			  struct v4l2_subdev_state *state,
+			  struct v4l2_subdev_format *fmt)
+{
+	struct gc8034 *gc8034 = to_gc8034(sd);
+	struct v4l2_mbus_framefmt *format;
+	struct v4l2_rect *crop;
+	u32 width, height;
+	int pos;
+
+	if (fmt->which == V4L2_SUBDEV_FORMAT_ACTIVE &&
+	    v4l2_subdev_is_streaming(sd))
+		return -EBUSY;
+
+	width = ALIGN_DOWN(clamp_t(u32, fmt->format.width, GC8034_MIN_WIDTH,
+				   GC8034_MAX_WIDTH), 4);
+	height = ALIGN_DOWN(clamp_t(u32, fmt->format.height, GC8034_MIN_HEIGHT,
+				    GC8034_MAX_HEIGHT), 4);
+
+	crop = v4l2_subdev_state_get_crop(state, 0);
+	if (width != crop->width) {
+		pos = GC8034_CROP_LEFT + (GC8034_WIDTH - (int)width) / 2;
+		pos = clamp(pos, 0, GC8034_AREA_WIDTH - (int)width);
+		crop->left = ALIGN_DOWN(pos, 2);
+		crop->width = width;
+	}
+	if (height != crop->height) {
+		pos = GC8034_CROP_TOP + (GC8034_HEIGHT - (int)height) / 2;
+		pos = clamp(pos, 0, GC8034_AREA_HEIGHT - (int)height);
+		crop->top = ALIGN_DOWN(pos, 2);
+		crop->height = height;
+	}
+
+	format = v4l2_subdev_state_get_format(state, 0);
+	gc8034_fill_format(format, crop);
+	fmt->format = *format;
+
+	if (fmt->which == V4L2_SUBDEV_FORMAT_ACTIVE)
+		return gc8034_update_ctrls(gc8034, format);
+
+	return 0;
+}
+
 static int gc8034_init_state(struct v4l2_subdev *sd,
 			     struct v4l2_subdev_state *state)
 {
@@ -750,7 +900,9 @@ static const struct v4l2_subdev_pad_ops gc8034_pad_ops = {
 	.enum_mbus_code = gc8034_enum_mbus_code,
 	.enum_frame_size = gc8034_enum_frame_size,
 	.get_fmt = v4l2_subdev_get_fmt,
+	.set_fmt = gc8034_set_fmt,
 	.get_selection = gc8034_get_selection,
+	.set_selection = gc8034_set_selection,
 	.get_frame_desc = gc8034_get_frame_desc,
 	.enable_streams = gc8034_enable_streams,
 	.disable_streams = gc8034_disable_streams,
@@ -825,9 +977,11 @@ static int gc8034_init_controls(struct gc8034 *gc8034)
 			  GC8034_PIXEL_RATE, GC8034_PIXEL_RATE, 1,
 			  GC8034_PIXEL_RATE);
 
-	v4l2_ctrl_new_std(ctrl_hdlr, &gc8034_ctrl_ops, V4L2_CID_VBLANK,
-			  GC8034_VBLANK_MIN, GC8034_VTS_MAX - GC8034_HEIGHT, 1,
-			  GC8034_VBLANK_MIN);
+	/* Ranges for the default crop rectangle, see gc8034_update_ctrls(). */
+	gc8034->vblank = v4l2_ctrl_new_std(ctrl_hdlr, &gc8034_ctrl_ops,
+					   V4L2_CID_VBLANK, GC8034_VBLANK_MIN,
+					   GC8034_VTS_MAX - GC8034_HEIGHT, 1,
+					   GC8034_VBLANK_MIN);
 
 	gc8034->hblank = v4l2_ctrl_new_std(ctrl_hdlr, NULL, V4L2_CID_HBLANK,
 					   GC8034_HTS - GC8034_WIDTH,
Signature · 1 line
2.47.3
#13 lore raw

PATCH v2 6/7 media: ipu-bridge: Add the GC5035 binning link frequency

In reply to Nicola Fiorillo

In its 2x2 binned mode the GC5035 uses a 175.2 MHz link frequency, set by the PLL of the vendor register sequence for that mode. List it, so that the driver can offer binning.

Assisted-by claude-opus-5-5
---
 drivers/media/pci/intel/ipu-bridge.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/media/pci/intel/ipu-bridge.c +1 -1
index 851096d7d..3caa07529 100644
@@ -60,7 +60,7 @@ static const u16 ipu6_ov5693_ncont_clk[] = {
 
 static const struct ipu_sensor_config ipu_supported_sensors[] = {
 	/* GalaxyCore GC5035 */
-	IPU_SENSOR_CONFIG("GCTI5035", 1, 422400000),
+	IPU_SENSOR_CONFIG("GCTI5035", 2, 175200000, 422400000),
 	/* GalaxyCore GC8034 */
 	IPU_SENSOR_CONFIG("GCTI8034", 1, 268800000),
 	/* Himax HM1092 */
Signature · 1 line
2.47.3
#14 lore raw

PATCH v2 7/7 media: i2c: gc5035: Add 2x2 binning support

In reply to Nicola Fiorillo

Setting the format to half the size of the default crop rectangle selects 2x2 binning of that rectangle: 1296x972 with the same field of view as 2592x1944, averaging four pixels of the same colour. The crop rectangle goes back to the default one, so that the size alone selects the mode, whatever crop rectangle earlier calls left; only a crop rectangle of that size, set first, keeps 1296x972 unbinned. The register settings are the ones of the vendor sequence for that mode, which only work as a whole. Any other format, or a new crop rectangle, gives the unbinned output as before. enum_frame_size lists 1296x972 as a second, discrete size.

The vendor sequence changes the PLL. The link frequency in this mode is 175.2 MHz: the time needed to send a line of a given width, found from the shortest line length that gives complete frames, gives 176.3 +/- 0.9 MHz (and 420.7 +/- 1.5 MHz at full resolution, where it is 422.4 MHz). LINK_FREQ and PIXEL_RATE follow the mode. The timings are expressed in sensor lines, as at full resolution: the sensor reads one row of the pixel array per line and outputs one row every two lines. This keeps the frame length and exposure registers in their own unit, with a one line exposure step, and the frame period computed from HBLANK and VBLANK is the measured one. With the vendor readout window a frame lasts at least 1996 lines, so binning runs at up to 24 fps, against 28.8 fps at 2592x1944: it is meant for lower noise and bandwidth, not for speed.

Binning is only offered when the firmware lists the 175.2 MHz link frequency.

Tested with v4l2-compliance (54/54, no warning, in both modes) and libcamera, which picks the mode for 1280x960 at 24 fps: the frame period is the computed one, also with a longer VBLANK and at the maximum exposure, the signal doubles with the exposure in sensor lines, and the output matches the 2x2 average per colour of a full resolution frame, with no offset.

Assisted-by claude-opus-5-5 coccinelle sparse smatch
---
 drivers/media/i2c/gc5035.c | 296 +++++++++++++++++++++++++++++++------
 1 file changed, 249 insertions(+), 47 deletions(-)
drivers/media/i2c/gc5035.c +249 -47
index b7190aa52..f8cd56a46 100644
@@ -13,6 +13,7 @@
  */
 #include <linux/align.h>
 #include <linux/array_size.h>
+#include <linux/bits.h>
 #include <linux/clk.h>
 #include <linux/container_of.h>
 #include <linux/delay.h>
@@ -142,6 +143,36 @@
 #define GC5035_PIXEL_RATE		(GC5035_LINK_FREQ * 2 * \
 					 GC5035_DATA_LANES / GC5035_RGB_DEPTH)
 
+/*
+ * 2x2 binning, with the vendor register sequence for 1296x972. It sets the
+ * PLL multiplier to 0x49 and adds a divider by 2 (register 0xfa), which
+ * gives a 175.2 MHz link frequency. The frame period scales with the PLL
+ * setting as expected, and the bandwidth limit of the link was measured at
+ * 176.3 +/- 0.9 MHz in this mode (420.7 +/- 1.5 MHz at full resolution with
+ * the same method): the time needed to send a line of a given width was
+ * found from the shortest line length that gives complete frames.
+ *
+ * The sensor reads one row of the pixel array per line and outputs one row
+ * every two lines. Expressing the timings in sensor lines keeps the frame
+ * length, vertical blanking and exposure registers in the same units as at
+ * full resolution: the line length is 1460 pixels at 70.08 MHz, and the
+ * vendor readout window, which is used in this mode, needs at least 1996
+ * lines per frame. Binning is only available on the default crop rectangle,
+ * and the output starts at (4, 4) in binned coordinates, which is (8, 8) in
+ * the area: GRBG, like the default rectangle.
+ */
+#define GC5035_PLL_MULT_BIN		0x49
+#define GC5035_LINK_FREQ_BIN		(GC5035_XCLK_FREQ * \
+					 GC5035_PLL_MULT_BIN / 8)
+#define GC5035_PIXEL_RATE_BIN		(GC5035_LINK_FREQ_BIN * 2 * \
+					 GC5035_DATA_LANES / GC5035_RGB_DEPTH)
+#define GC5035_HTS_BIN			1460
+#define GC5035_VTS_MIN_BIN		1996
+#define GC5035_WIN_TOP_BIN		GC5035_ROW_START_OFFSET
+#define GC5035_WIN_LEFT_BIN		3
+#define GC5035_WIN_HEIGHT_BIN		1960
+#define GC5035_WIN_WIDTH_BIN		2608
+
 /*
  * No datasheet is available. From the GC5035 driver posted by Tomasz Figa in
  * 2020: IOVDD at least 50 us before AVDD and DVDD, at least 1200 MCLK cycles
@@ -158,8 +189,14 @@
 
 #define GC5035_MBUS_CODE		MEDIA_BUS_FMT_SGRBG10_1X10
 
+enum {
+	GC5035_LINK_FREQ_FULL_INDEX,
+	GC5035_LINK_FREQ_BIN_INDEX,
+};
+
 static const s64 gc5035_link_freq_menu[] = {
-	GC5035_LINK_FREQ,
+	[GC5035_LINK_FREQ_FULL_INDEX] = GC5035_LINK_FREQ,
+	[GC5035_LINK_FREQ_BIN_INDEX] = GC5035_LINK_FREQ_BIN,
 };
 
 static const char * const gc5035_test_pattern_menu[] = {
@@ -210,11 +247,16 @@ struct gc5035 {
 	struct gpio_desc *powerdown_gpio;
 
 	struct v4l2_ctrl_handler ctrls;
+	struct v4l2_ctrl *link_freq;
+	struct v4l2_ctrl *pixel_rate;
 	struct v4l2_ctrl *exposure;
 	struct v4l2_ctrl *vblank;
 	struct v4l2_ctrl *hblank;
 
 	struct regmap *regmap;
+
+	/* The firmware lists the link frequency of the binned mode. */
+	bool binning;
 };
 
 /*
@@ -376,6 +418,56 @@ static const struct cci_reg_sequence gc5035_regs[] = {
 	{ GC5035_REG_STREAM, GC5035_STREAM_OFF },
 };
 
+/*
+ * Written after gc5035_regs for 2x2 binning: the registers that the vendor
+ * sequence for 1296x972 sets differently, in its order, without the geometry.
+ * The sequence only works as a whole: without the PLL settings the image is
+ * saturated, without the MIPI ones (page 3) the CSI-2 receiver gets errors,
+ * and without the analog ones the four pixels are not averaged.
+ */
+static const struct cci_reg_sequence gc5035_bin_regs[] = {
+	{ GC5035_REG_PAGE_SELECT, 0x00 },
+	{ CCI_REG8(0xf5), 0xe4 },
+	{ GC5035_REG_PLL_MULT, GC5035_PLL_MULT_BIN },
+	{ CCI_REG8(0xf9), 0x12 },
+	{ CCI_REG8(0xfa), 0x01 },
+	{ CCI_REG8(0x33), 0x20 },
+	{ GC5035_REG_PAGE_SELECT, 0x03 },
+	{ CCI_REG8(0x01), 0x87 },
+	{ CCI_REG8(0xf7), 0x11 },
+	{ GC5035_REG_PAGE_SELECT, 0x00 },
+	{ CCI_REG8(0x9d), 0x0c },
+	{ CCI_REG8(0x21), 0x60 },
+	{ CCI_REG8(0x29), 0x30 },
+	{ CCI_REG8(0x44), 0x18 },
+	{ CCI_REG8(0x4e), 0x20 },
+	{ CCI_REG8(0x8c), 0x20 },
+	{ CCI_REG8(0x91), 0x15 },
+	{ CCI_REG8(0x92), 0x3a },
+	{ CCI_REG8(0x95), 0x45 },
+	{ CCI_REG8(0x96), 0x35 },
+	{ CCI_REG8(0xd5), 0xf0 },
+	{ CCI_REG8(0x97), 0x20 },
+	{ CCI_REG8(0x1f), 0x19 },
+	{ CCI_REG8(0xd0), 0xb3 },
+	{ GC5035_REG_PAGE_SELECT, 0x02 },
+	{ CCI_REG8(0x14), 0x02 },
+	{ CCI_REG8(0x15), 0x00 },
+	{ GC5035_REG_PAGE_SELECT, 0x01 },
+	{ CCI_REG8(0x49), 0x00 },
+	{ CCI_REG8(0x4a), 0x01 },
+	{ CCI_REG8(0x4b), 0xf8 },
+	{ CCI_REG8(0x4e), 0x06 },
+	{ CCI_REG8(0x44), 0x02 },
+	{ GC5035_REG_PAGE_SELECT, 0x03 },
+	{ CCI_REG8(0x02), 0x58 },
+	{ CCI_REG8(0x22), 0x03 },
+	{ CCI_REG8(0x26), 0x06 },
+	{ CCI_REG8(0x29), 0x03 },
+	{ CCI_REG8(0x2b), 0x06 },
+	{ GC5035_REG_PAGE_SELECT, 0x00 },
+};
+
 static inline struct gc5035 *to_gc5035(struct v4l2_subdev *sd)
 {
 	return container_of(sd, struct gc5035, sd);
@@ -462,52 +554,89 @@ static int gc5035_enum_frame_size(struct v4l2_subdev *sd,
 				  struct v4l2_subdev_state *sd_state,
 				  struct v4l2_subdev_frame_size_enum *fse)
 {
+	struct gc5035 *gc5035 = to_gc5035(sd);
+
 	if (fse->code != GC5035_MBUS_CODE)
 		return -EINVAL;
 
-	if (fse->index > 0)
+	switch (fse->index) {
+	case 0:
+		/* Without binning, the output size is the crop size. */
+		fse->min_width = GC5035_MIN_WIDTH;
+		fse->max_width = GC5035_AREA_WIDTH;
+		fse->min_height = GC5035_MIN_HEIGHT;
+		fse->max_height = GC5035_AREA_HEIGHT;
+		break;
+	case 1:
+		/* 2x2 binning of the default crop rectangle. */
+		if (!gc5035->binning)
+			return -EINVAL;
+		fse->min_width = GC5035_WIDTH / 2;
+		fse->max_width = GC5035_WIDTH / 2;
+		fse->min_height = GC5035_HEIGHT / 2;
+		fse->max_height = GC5035_HEIGHT / 2;
+		break;
+	default:
 		return -EINVAL;
-
-	/* The output size is the size of the crop rectangle. */
-	fse->min_width = GC5035_MIN_WIDTH;
-	fse->max_width = GC5035_AREA_WIDTH;
-	fse->min_height = GC5035_MIN_HEIGHT;
-	fse->max_height = GC5035_AREA_HEIGHT;
+	}
 
 	return 0;
 }
 
+/* Binning is the only case where the output is smaller than the crop. */
+static bool gc5035_is_binned(const struct v4l2_rect *crop,
+			     const struct v4l2_mbus_framefmt *format)
+{
+	return format->width < crop->width;
+}
+
 /*
- * Update the controls that depend on the output size. Called with the state
- * lock held, which is also the control handler lock.
+ * Update the controls that depend on the output size and on binning. Called
+ * with the state lock held, which is also the control handler lock.
  */
 static int gc5035_update_ctrls(struct gc5035 *gc5035,
+			       const struct v4l2_rect *crop,
 			       const struct v4l2_mbus_framefmt *format)
 {
-	s64 vblank_max, exposure_max;
+	bool binned = gc5035_is_binned(crop, format);
+	s64 vblank_min, vblank_max, exposure_max;
+	u32 hts;
 	int ret;
 
-	ret = __v4l2_ctrl_modify_range(gc5035->hblank,
-				       GC5035_HTS - format->width,
-				       GC5035_HTS - format->width, 1,
-				       GC5035_HTS - format->width);
+	ret = __v4l2_ctrl_s_ctrl(gc5035->link_freq,
+				 binned ? GC5035_LINK_FREQ_BIN_INDEX :
+					  GC5035_LINK_FREQ_FULL_INDEX);
+	if (ret)
+		return ret;
+
+	ret = __v4l2_ctrl_s_ctrl_int64(gc5035->pixel_rate,
+				       binned ? GC5035_PIXEL_RATE_BIN :
+						GC5035_PIXEL_RATE);
+	if (ret)
+		return ret;
+
+	hts = binned ? GC5035_HTS_BIN : GC5035_HTS;
+	ret = __v4l2_ctrl_modify_range(gc5035->hblank, hts - format->width,
+				       hts - format->width, 1,
+				       hts - format->width);
 	if (ret)
 		return ret;
 
-	vblank_max = GC5035_VBLANK_MIN +
-		     round_down(GC5035_VTS_MAX - format->height -
-				GC5035_VBLANK_MIN, GC5035_VBLANK_STEP);
+	vblank_min = binned ? GC5035_VTS_MIN_BIN - format->height :
+			      GC5035_VBLANK_MIN;
+	vblank_max = vblank_min +
+		     round_down(GC5035_VTS_MAX - format->height - vblank_min,
+				GC5035_VBLANK_STEP);
 	/*
 	 * As in ov01a10, setting the format or the crop rectangle resets the
 	 * vertical blanking.
 	 */
-	ret = __v4l2_ctrl_modify_range(gc5035->vblank, GC5035_VBLANK_MIN,
-				       vblank_max, GC5035_VBLANK_STEP,
-				       GC5035_VBLANK_MIN);
+	ret = __v4l2_ctrl_modify_range(gc5035->vblank, vblank_min, vblank_max,
+				       GC5035_VBLANK_STEP, vblank_min);
 	if (ret)
 		return ret;
 
-	ret = __v4l2_ctrl_s_ctrl(gc5035->vblank, GC5035_VBLANK_MIN);
+	ret = __v4l2_ctrl_s_ctrl(gc5035->vblank, vblank_min);
 	if (ret)
 		return ret;
 
@@ -521,10 +650,10 @@ static int gc5035_update_ctrls(struct gc5035 *gc5035,
 }
 
 static void gc5035_fill_format(struct v4l2_mbus_framefmt *fmt,
-			       const struct v4l2_rect *crop)
+			       const struct v4l2_rect *crop, unsigned int bin)
 {
-	fmt->width = crop->width;
-	fmt->height = crop->height;
+	fmt->width = crop->width / bin;
+	fmt->height = crop->height / bin;
 	fmt->code = GC5035_MBUS_CODE;
 	fmt->field = V4L2_FIELD_NONE;
 	fmt->colorspace = V4L2_COLORSPACE_RAW;
@@ -594,31 +723,42 @@ static int gc5035_set_selection(struct v4l2_subdev *sd,
 	*v4l2_subdev_state_get_crop(state, 0) = rect;
 	sel->r = rect;
 
-	/* No binning or scaling: the output size is the crop size. */
+	/* A new crop rectangle disables binning: the output is its size. */
 	format = v4l2_subdev_state_get_format(state, 0);
-	gc5035_fill_format(format, &rect);
+	gc5035_fill_format(format, &rect, 1);
 
 	if (sel->which == V4L2_SUBDEV_FORMAT_ACTIVE)
-		return gc5035_update_ctrls(gc5035, format);
+		return gc5035_update_ctrls(gc5035, &rect, format);
 
 	return 0;
 }
 
 /*
- * No binning or scaling: the output size is the size of the crop rectangle. A
- * new width or height centres the crop rectangle on the default crop
- * rectangle along that axis, within the area, for userspace that does not set
- * the crop rectangle first. The default size gives the default rectangle back.
+ * Half the size of the default crop rectangle selects 2x2 binning and sets
+ * the default crop rectangle back, unless the crop rectangle already has
+ * that size: the size alone selects the binned mode, with the full field of
+ * view, and a crop rectangle of that size set first stays unbinned.
+ * Otherwise the output size is the size of the crop rectangle: a new width
+ * or height centres the crop rectangle on the default crop rectangle along
+ * that axis, within the area, for userspace that does not set the crop
+ * rectangle first. The default size gives the default rectangle back.
  */
 static int gc5035_set_fmt(struct v4l2_subdev *sd,
 			  const struct v4l2_subdev_client_info *ci,
 			  struct v4l2_subdev_state *state,
 			  struct v4l2_subdev_format *fmt)
 {
+	static const struct v4l2_rect crop_default = {
+		.left = GC5035_CROP_LEFT,
+		.top = GC5035_CROP_TOP,
+		.width = GC5035_WIDTH,
+		.height = GC5035_HEIGHT,
+	};
 	struct gc5035 *gc5035 = to_gc5035(sd);
 	struct v4l2_mbus_framefmt *format;
 	struct v4l2_rect *crop;
 	u32 width, height;
+	unsigned int bin;
 	int pos;
 
 	if (fmt->which == V4L2_SUBDEV_FORMAT_ACTIVE &&
@@ -631,13 +771,18 @@ static int gc5035_set_fmt(struct v4l2_subdev *sd,
 				    GC5035_AREA_HEIGHT), 4);
 
 	crop = v4l2_subdev_state_get_crop(state, 0);
-	if (width != crop->width) {
+	bin = gc5035->binning && width == GC5035_WIDTH / 2 &&
+	      height == GC5035_HEIGHT / 2 &&
+	      (width != crop->width || height != crop->height) ? 2 : 1;
+	if (bin == 2)
+		*crop = crop_default;
+	if (bin == 1 && width != crop->width) {
 		pos = GC5035_CROP_LEFT + (GC5035_WIDTH - (int)width) / 2;
 		pos = clamp(pos, 0, GC5035_AREA_WIDTH - (int)width);
 		crop->left = ALIGN_DOWN(pos, 2);
 		crop->width = width;
 	}
-	if (height != crop->height) {
+	if (bin == 1 && height != crop->height) {
 		pos = GC5035_CROP_TOP + (GC5035_HEIGHT - (int)height) / 2;
 		pos = clamp(pos, 0, GC5035_AREA_HEIGHT - (int)height);
 		crop->top = ALIGN_DOWN(pos, 2);
@@ -645,11 +790,11 @@ static int gc5035_set_fmt(struct v4l2_subdev *sd,
 	}
 
 	format = v4l2_subdev_state_get_format(state, 0);
-	gc5035_fill_format(format, crop);
+	gc5035_fill_format(format, crop, bin);
 	fmt->format = *format;
 
 	if (fmt->which == V4L2_SUBDEV_FORMAT_ACTIVE)
-		return gc5035_update_ctrls(gc5035, format);
+		return gc5035_update_ctrls(gc5035, crop, format);
 
 	return 0;
 }
@@ -664,7 +809,7 @@ static int gc5035_init_state(struct v4l2_subdev *sd,
 	crop->width = GC5035_WIDTH;
 	crop->height = GC5035_HEIGHT;
 
-	gc5035_fill_format(v4l2_subdev_state_get_format(state, 0), crop);
+	gc5035_fill_format(v4l2_subdev_state_get_format(state, 0), crop, 1);
 
 	return 0;
 }
@@ -803,11 +948,42 @@ static int gc5035_write_geometry(struct gc5035 *gc5035,
 	return ret;
 }
 
+/*
+ * Binning: the vendor readout window, which starts at the first row and
+ * column of the area, and the output crop in binned coordinates.
+ */
+static int gc5035_write_geometry_bin(struct gc5035 *gc5035,
+				     const struct v4l2_rect *crop,
+				     const struct v4l2_mbus_framefmt *format)
+{
+	int ret = 0;
+
+	cci_write(gc5035->regmap, GC5035_REG_PAGE_SELECT, GC5035_PAGE_0, &ret);
+	cci_write(gc5035->regmap, GC5035_REG_WIN_TOP, GC5035_WIN_TOP_BIN, &ret);
+	cci_write(gc5035->regmap, GC5035_REG_WIN_LEFT, GC5035_WIN_LEFT_BIN,
+		  &ret);
+	cci_write(gc5035->regmap, GC5035_REG_WIN_HEIGHT, GC5035_WIN_HEIGHT_BIN,
+		  &ret);
+	cci_write(gc5035->regmap, GC5035_REG_WIN_WIDTH, GC5035_WIN_WIDTH_BIN,
+		  &ret);
+
+	cci_write(gc5035->regmap, GC5035_REG_PAGE_SELECT, GC5035_PAGE_1, &ret);
+	cci_write(gc5035->regmap, GC5035_REG_CROP_TOP, crop->top / 2, &ret);
+	cci_write(gc5035->regmap, GC5035_REG_CROP_LEFT, crop->left / 2, &ret);
+	cci_write(gc5035->regmap, GC5035_REG_OUT_HEIGHT, format->height, &ret);
+	cci_write(gc5035->regmap, GC5035_REG_OUT_WIDTH, format->width, &ret);
+	cci_write(gc5035->regmap, GC5035_REG_PAGE_SELECT, GC5035_PAGE_0, &ret);
+
+	return ret;
+}
+
 static int gc5035_enable_streams(struct v4l2_subdev *sd,
 				 struct v4l2_subdev_state *state,
 				 u32 pad, u64 streams_mask)
 {
 	struct gc5035 *gc5035 = to_gc5035(sd);
+	const struct v4l2_mbus_framefmt *format;
+	const struct v4l2_rect *crop;
 	int ret;
 
 	ret = pm_runtime_resume_and_get(gc5035->dev);
@@ -819,8 +995,18 @@ static int gc5035_enable_streams(struct v4l2_subdev *sd,
 	if (ret)
 		goto err_rpm_put;
 
-	ret = gc5035_write_geometry(gc5035,
-				    v4l2_subdev_state_get_crop(state, 0));
+	crop = v4l2_subdev_state_get_crop(state, 0);
+	format = v4l2_subdev_state_get_format(state, 0);
+	if (gc5035_is_binned(crop, format)) {
+		ret = cci_multi_reg_write(gc5035->regmap, gc5035_bin_regs,
+					  ARRAY_SIZE(gc5035_bin_regs), NULL);
+		if (ret)
+			goto err_rpm_put;
+
+		ret = gc5035_write_geometry_bin(gc5035, crop, format);
+	} else {
+		ret = gc5035_write_geometry(gc5035, crop);
+	}
 	if (ret)
 		goto err_rpm_put;
 
@@ -912,6 +1098,17 @@ static int gc5035_parse_fwnode(struct gc5035 *gc5035)
 				       gc5035_link_freq_menu,
 				       ARRAY_SIZE(gc5035_link_freq_menu),
 				       &link_freq_bitmap);
+	if (ret)
+		goto done;
+
+	if (!(link_freq_bitmap & BIT(GC5035_LINK_FREQ_FULL_INDEX))) {
+		ret = dev_err_probe(dev, -EINVAL,
+				    "link frequency %lu Hz not supported\n",
+				    GC5035_LINK_FREQ);
+		goto done;
+	}
+
+	gc5035->binning = link_freq_bitmap & BIT(GC5035_LINK_FREQ_BIN_INDEX);
 
 done:
 	v4l2_fwnode_endpoint_free(&bus_cfg);
@@ -923,7 +1120,6 @@ static int gc5035_init_controls(struct gc5035 *gc5035)
 {
 	struct v4l2_fwnode_device_properties props;
 	struct v4l2_ctrl_handler *ctrl_hdlr;
-	struct v4l2_ctrl *link_freq;
 	s64 exposure_max;
 	int ret;
 
@@ -934,13 +1130,19 @@ static int gc5035_init_controls(struct gc5035 *gc5035)
 	ctrl_hdlr = &gc5035->ctrls;
 	v4l2_ctrl_handler_init(ctrl_hdlr, 9);
 
-	link_freq = v4l2_ctrl_new_int_menu(ctrl_hdlr, NULL, V4L2_CID_LINK_FREQ,
-					   ARRAY_SIZE(gc5035_link_freq_menu) -
-					   1, 0, gc5035_link_freq_menu);
+	/* The binned mode frequency is only listed when the firmware has it. */
+	gc5035->link_freq =
+		v4l2_ctrl_new_int_menu(ctrl_hdlr, NULL, V4L2_CID_LINK_FREQ,
+				       gc5035->binning ?
+				       GC5035_LINK_FREQ_BIN_INDEX :
+				       GC5035_LINK_FREQ_FULL_INDEX,
+				       GC5035_LINK_FREQ_FULL_INDEX,
+				       gc5035_link_freq_menu);
 
-	v4l2_ctrl_new_std(ctrl_hdlr, NULL, V4L2_CID_PIXEL_RATE,
-			  GC5035_PIXEL_RATE, GC5035_PIXEL_RATE, 1,
-			  GC5035_PIXEL_RATE);
+	gc5035->pixel_rate =
+		v4l2_ctrl_new_std(ctrl_hdlr, NULL, V4L2_CID_PIXEL_RATE,
+				  GC5035_PIXEL_RATE_BIN, GC5035_PIXEL_RATE, 1,
+				  GC5035_PIXEL_RATE);
 
 	/* Ranges for the default crop rectangle, see gc5035_update_ctrls(). */
 	gc5035->vblank = v4l2_ctrl_new_std(ctrl_hdlr, &gc5035_ctrl_ops,
@@ -977,7 +1179,7 @@ static int gc5035_init_controls(struct gc5035 *gc5035)
 	if (ctrl_hdlr->error)
 		return v4l2_ctrl_handler_free(ctrl_hdlr);
 
-	link_freq->flags |= V4L2_CTRL_FLAG_READ_ONLY;
+	gc5035->link_freq->flags |= V4L2_CTRL_FLAG_READ_ONLY;
 	gc5035->hblank->flags |= V4L2_CTRL_FLAG_READ_ONLY;
 
 	gc5035->sd.ctrl_handler = ctrl_hdlr;
Signature · 1 line
2.47.3
#15 lore raw
In reply to Nicola Fiorillo
Quoted 10 lines · Nicola Fiorillo

Hi all,

this is v2 of the drivers for the GalaxyCore GC5035 (front camera, 2 lanes) and GC8034 (back camera, 4 lanes) sensors of the Chuwi Hi10 X1 tablet, with IPU6.

Laurent, on v1 you asked to make the drivers configurable, with analog crop and binning if the sensor supports it.

This version does the following:

Sorry, this cover letter is too long. Please ditch the LLM and rewrite it manually, only including the important information. The series isn't reviewable as-is, it gives me no confidence you're understanding what you're doing. Same for commit messages and comments in the drivers, please rewrite them manually.

Quoted 354 lines

- No more mode tables for the geometry: the readout window and the sensor output crop are computed from the crop rectangle every time streaming starts (patches 1 and 2).
- The crop is set with the CROP selection on the source pad (patches 4 and 5). Vertically it is an analog crop: the readout window gets smaller and the frame gets shorter (the GC5035 at 640x480 runs at up to 106 fps). Horizontally it is the sensor internal output crop instead: narrowing the readout window horizontally gives black images on the GC5035, and on the GC8034 it goes through a column register that gives corrupted images at many values.
- 2x2 binning is there on the GC5035 (patches 6 and 7): the 1296x972 format gives the average of four samples of the same colour, with the same field of view as the default crop. The vendor sequence changes the PLL, so I measured the link frequency in that mode: 176.3 +/- 0.9 MHz, against the 175.2 MHz given by the PLL registers (with the same method, at full resolution, 420.7 +/- 1.5 against 422.4). Patch 6 adds this frequency to ipu-bridge. On the GC8034 binning only exists in the 2-lane vendor sequences; with 4 lanes it breaks the CSI-2 stream, so it isn't there.

I kept the crop in patches 4 and 5 and the binning in 6 and 7, separate, because I saw that for the IMX908 you decided to postpone the crop until the common raw sensor model (<[email protected]>). If you want to do the same here, patches 1-3 work on their own, at a fixed resolution like v1, and I'll redo crop and binning on the common model when it lands.

Some choices you may disagree with, and that I'm happy to change:

- set_fmt changes the crop: for userspace that does not set the crop first, it centres it on the default crop, as ov01a10 does. And 1296x972 selects binning and sets the default crop back, unless the crop is already 1296x972: libcamera first sets the largest size and then the one it wants, and with binning tied to the current crop it never got it. If you prefer binning through COMPOSE, or waiting for the common model, I'll change it.
- In binning the timings are in sensor lines (the sensor reads one row of the array per line and outputs one every two lines): exposure and VBLANK keep the register unit, with a one line step, and the frame period computed from HBLANK and VBLANK is the measured one. This is why PIXEL_RATE is 70.08 MHz, HBLANK 164 and VBLANK at least 1024.
- enum_frame_size lists 1296x972 separately, although it is within the full mode range, so that libcamera sees the binned mode.
- The GC8034 PIXEL_RATE (256 MHz) is the one that gives the measured frame periods with the sensor line length; it is more than the 4-lane link carries (215 Mpixel/s), but over a whole line, blanking included, the average is about 196 Mpixel/s.
- The analogue gain is the index of the sensor gain steps, which are not linear, as in the vendor code.

I don't have the datasheets: I measured the geometry, the limits and the timings on the tablet, and the comments in the code say what is measured. In short:

- The sizes reported as NATIVE_SIZE and CROP_BOUNDS (2608x1964 and 3282x2500) are the largest area that gives image data; around it there are constant rows and columns. They are not the physical array, which is not documented.
- CROP_DEFAULT is the image of the vendor sequence, the same as v1: at the default crop v2 produces the same image as v1.
- The timings follow a model that matches the measurements from 64 lines to the full height; for the GC8034 this corrected PIXEL_RATE to 256 MHz (v1 declared 255.9 MHz).
- The size limits (GC8034 at least 512 and at most 3280 wide, at most 2448 high; GC5035 at least 64x64) come from tests where outside those limits the stream breaks or the timings leave the model.

The series is based on media next (d7e7bca71). I tested it on the tablet, with a 7.3-rc1 kernel and the modules built from these patches:
- v4l2-compliance from git (1616bf9e3c81) with -z: 54/54, no warnings, on both, and on the GC5035 both at full resolution and in binning; full output below.
- A set of crop tests (default, bounds, centre, corners, minimum, requests to be rounded or outside the area): rectangle applied, measured frame period, complete frames and position to the pixel, all as expected, in two runs per sensor.
- Binning: controls, frame period (also with a long VBLANK and at the maximum exposure), signal doubling with double exposure, output equal to the per-colour 2x2 average of a full resolution frame with no offset, 20 starts and stops in a row, and switching from the full mode to binning.
- libcamera (simple pipeline): 60 frames out of 60 in three configurations per camera; on the GC5035 at 1280x960 it picks binning.
- W=1, sparse, smatch, checkpatch --strict and coccinelle clean on every patch; i386 build clean.

Changes since v1:
- Patches 1 and 2: geometry removed from the register table and computed from the crop, all written as 16-bit values; NATIVE_SIZE and CROP_BOUNDS are the measured area instead of the vendor readout window; the default exposure no longer exceeds the maximum when VBLANK is reduced; GC8034:
PIXEL_RATE set to 256 MHz and the blanking register computed from VBLANK; dropped linux/mod_devicetable.h and used a designated initializer in the ACPI table, as Uwe asked.
- Added Dan's Reviewed-by to patch 3.
- Patches 4, 5, 6 and 7: new.

I used a frontier LLM (Claude) to write the code and to do the measurements; I stated it in the Assisted-by tags. The English of this letter is a translation from my Italian.

Nicola

v4l2-compliance (git 1616bf9e3c81, -z PCI:0000:00:05.0 -u <subdev>):

GC5035 (2592x1944):

v4l2-compliance 1.33.0-5515, 64 bits, 64-bit time_t v4l2-compliance SHA: 1616bf9e3c81 2026-10-06 07:30:20

Compliance test for intel-ipu6 device /dev/v4l-subdev4:

Driver Info:

	Driver version   : 7.3.0
	Capabilities     : 0x00000000
	Client Capabilities: 0x0000000000000002
interval-uses-which Media Driver Info:
	Driver name      : intel-ipu6
	Model            : ipu6
	Serial           : 
	Bus info         : PCI:0000:00:05.0
	Media version    : 7.3.0
	Hardware revision: 0x00000000 (0)
	Driver version   : 7.3.0
Interface Info:
	ID               : 0x030001fd
	Type             : V4L Sub-Device
Entity Info:
	ID               : 0x000001f9 (505)
	Name             : gc5035 2-003f
	Function         : Camera Sensor
	Pad 0x010001fa   : 0: Source
	  Link 0x020001fb: to remote pad 0x1000096 of entity 'Intel IPU6 CSI2 2' (Video Interface Bridge): Data, Enabled, Immutable

Required ioctls:
test MC information (see 'Media Driver Info' above): OK test VIDIOC_SUDBEV_QUERYCAP: OK
test invalid ioctls: OK

Allow for multiple opens:
test second /dev/v4l-subdev4 open: OK
test VIDIOC_SUBDEV_QUERYCAP: OK
test for unlimited opens: OK

Debug ioctls:
test VIDIOC_LOG_STATUS: OK (Not Supported)

Input ioctls:
test VIDIOC_G/S_TUNER/ENUM_FREQ_BANDS: OK (Not Supported) test VIDIOC_G/S_FREQUENCY: OK (Not Supported) test VIDIOC_S_HW_FREQ_SEEK: OK (Not Supported) test VIDIOC_ENUMAUDIO: OK (Not Supported)
test VIDIOC_G/S/ENUMINPUT: OK (Not Supported) test VIDIOC_G/S_AUDIO: OK (Not Supported)
Inputs: 0 Audio Inputs: 0 Tuners: 0

Output ioctls:
test VIDIOC_G/S_MODULATOR: OK (Not Supported) test VIDIOC_G/S_FREQUENCY: OK (Not Supported) test VIDIOC_ENUMAUDOUT: OK (Not Supported) test VIDIOC_G/S/ENUMOUTPUT: OK (Not Supported) test VIDIOC_G/S_AUDOUT: OK (Not Supported)
Outputs: 0 Audio Outputs: 0 Modulators: 0

Input/Output configuration ioctls:
test VIDIOC_ENUM/G/S/QUERY_STD: OK (Not Supported) test VIDIOC_ENUM/G/S/QUERY_DV_TIMINGS: OK (Not Supported) test VIDIOC_DV_TIMINGS_CAP: OK (Not Supported) test VIDIOC_G/S_EDID: OK (Not Supported)

Sub-Device ioctls (Source Pad 0):
Try Stream 0
test Try VIDIOC_SUBDEV_ENUM_MBUS_CODE/FRAME_SIZE/FRAME_INTERVAL: OK test Try VIDIOC_SUBDEV_G/S_FMT: OK
test Try VIDIOC_SUBDEV_G/S_SELECTION/CROP: OK
Active Stream 0
test Active VIDIOC_SUBDEV_ENUM_MBUS_CODE/FRAME_SIZE/FRAME_INTERVAL: OK test Active VIDIOC_SUBDEV_G/S_FMT: OK
test Active VIDIOC_SUBDEV_G/S_SELECTION/CROP: OK
test Active VIDIOC_SUBDEV_G/S_FRAME_INTERVAL: OK (Not Supported)

Control ioctls:
test VIDIOC_QUERY_EXT_CTRL/QUERYMENU: OK test VIDIOC_QUERYCTRL: OK
test VIDIOC_G/S_CTRL: OK
test VIDIOC_G/S/TRY_EXT_CTRLS: OK test VIDIOC_(UN)SUBSCRIBE_EVENT/DQEVENT: OK test VIDIOC_G/S_JPEGCOMP: OK (Not Supported) Standard Controls: 13 Private Controls: 0

Format ioctls:
test VIDIOC_ENUM_FMT/FRAMESIZES/FRAMEINTERVALS: OK (Not Supported) test VIDIOC_G/S_PARM: OK (Not Supported)
test VIDIOC_G_FBUF: OK (Not Supported)
test VIDIOC_G_FMT: OK (Not Supported)
test VIDIOC_TRY_FMT: OK (Not Supported)
test VIDIOC_S_FMT: OK (Not Supported)
test VIDIOC_G_SLICED_VBI_CAP: OK (Not Supported)
test Cropping: OK (Not Supported)
test Composing: OK (Not Supported)
test Scaling: OK (Not Supported)

Codec ioctls:
test VIDIOC_(TRY_)ENCODER_CMD: OK (Not Supported) test VIDIOC_G_ENC_INDEX: OK (Not Supported) test VIDIOC_(TRY_)DECODER_CMD: OK (Not Supported)

Buffer ioctls:
test VIDIOC_REQBUFS/CREATE_BUFS/QUERYBUF: OK (Not Supported) test CREATE_BUFS maximum buffers: OK
test VIDIOC_REMOVE_BUFS: OK
test VIDIOC_EXPBUF: OK (Not Supported)
test Requests: OK (Not Supported)
test blocking wait: OK (Not Supported)

Total for intel-ipu6 device /dev/v4l-subdev4: 54, Succeeded: 54, Failed: 0, Warnings: 0

GC5035 in binning (1296x972), same output except:

Total for intel-ipu6 device /dev/v4l-subdev4: 54, Succeeded: 54, Failed: 0, Warnings: 0

GC8034:

v4l2-compliance 1.33.0-5515, 64 bits, 64-bit time_t v4l2-compliance SHA: 1616bf9e3c81 2026-10-06 07:30:20

Compliance test for intel-ipu6 device /dev/v4l-subdev5:

Driver Info:

	Driver version   : 7.3.0
	Capabilities     : 0x00000000
	Client Capabilities: 0x0000000000000002
interval-uses-which Media Driver Info:
	Driver name      : intel-ipu6
	Model            : ipu6
	Serial           : 
	Bus info         : PCI:0000:00:05.0
	Media version    : 7.3.0
	Hardware revision: 0x00000000 (0)
	Driver version   : 7.3.0
Interface Info:
	ID               : 0x03000203
	Type             : V4L Sub-Device
Entity Info:
	ID               : 0x000001ff (511)
	Name             : gc8034 1-0037
	Function         : Camera Sensor
	Pad 0x01000200   : 0: Source
	  Link 0x02000201: to remote pad 0x100008c of entity 'Intel IPU6 CSI2 1' (Video Interface Bridge): Data, Enabled, Immutable

Required ioctls:
test MC information (see 'Media Driver Info' above): OK test VIDIOC_SUDBEV_QUERYCAP: OK
test invalid ioctls: OK

Allow for multiple opens:
test second /dev/v4l-subdev5 open: OK
test VIDIOC_SUBDEV_QUERYCAP: OK
test for unlimited opens: OK

Debug ioctls:
test VIDIOC_LOG_STATUS: OK (Not Supported)

Input ioctls:
test VIDIOC_G/S_TUNER/ENUM_FREQ_BANDS: OK (Not Supported) test VIDIOC_G/S_FREQUENCY: OK (Not Supported) test VIDIOC_S_HW_FREQ_SEEK: OK (Not Supported) test VIDIOC_ENUMAUDIO: OK (Not Supported)
test VIDIOC_G/S/ENUMINPUT: OK (Not Supported) test VIDIOC_G/S_AUDIO: OK (Not Supported)
Inputs: 0 Audio Inputs: 0 Tuners: 0

Output ioctls:
test VIDIOC_G/S_MODULATOR: OK (Not Supported) test VIDIOC_G/S_FREQUENCY: OK (Not Supported) test VIDIOC_ENUMAUDOUT: OK (Not Supported) test VIDIOC_G/S/ENUMOUTPUT: OK (Not Supported) test VIDIOC_G/S_AUDOUT: OK (Not Supported)
Outputs: 0 Audio Outputs: 0 Modulators: 0

Input/Output configuration ioctls:
test VIDIOC_ENUM/G/S/QUERY_STD: OK (Not Supported) test VIDIOC_ENUM/G/S/QUERY_DV_TIMINGS: OK (Not Supported) test VIDIOC_DV_TIMINGS_CAP: OK (Not Supported) test VIDIOC_G/S_EDID: OK (Not Supported)

Sub-Device ioctls (Source Pad 0):
Try Stream 0
test Try VIDIOC_SUBDEV_ENUM_MBUS_CODE/FRAME_SIZE/FRAME_INTERVAL: OK test Try VIDIOC_SUBDEV_G/S_FMT: OK
test Try VIDIOC_SUBDEV_G/S_SELECTION/CROP: OK
Active Stream 0
test Active VIDIOC_SUBDEV_ENUM_MBUS_CODE/FRAME_SIZE/FRAME_INTERVAL: OK test Active VIDIOC_SUBDEV_G/S_FMT: OK
test Active VIDIOC_SUBDEV_G/S_SELECTION/CROP: OK
test Active VIDIOC_SUBDEV_G/S_FRAME_INTERVAL: OK (Not Supported)

Control ioctls:
test VIDIOC_QUERY_EXT_CTRL/QUERYMENU: OK test VIDIOC_QUERYCTRL: OK
test VIDIOC_G/S_CTRL: OK
test VIDIOC_G/S/TRY_EXT_CTRLS: OK test VIDIOC_(UN)SUBSCRIBE_EVENT/DQEVENT: OK test VIDIOC_G/S_JPEGCOMP: OK (Not Supported) Standard Controls: 12 Private Controls: 0

Format ioctls:
test VIDIOC_ENUM_FMT/FRAMESIZES/FRAMEINTERVALS: OK (Not Supported) test VIDIOC_G/S_PARM: OK (Not Supported)
test VIDIOC_G_FBUF: OK (Not Supported)
test VIDIOC_G_FMT: OK (Not Supported)
test VIDIOC_TRY_FMT: OK (Not Supported)
test VIDIOC_S_FMT: OK (Not Supported)
test VIDIOC_G_SLICED_VBI_CAP: OK (Not Supported)
test Cropping: OK (Not Supported)
test Composing: OK (Not Supported)
test Scaling: OK (Not Supported)

Codec ioctls:
test VIDIOC_(TRY_)ENCODER_CMD: OK (Not Supported) test VIDIOC_G_ENC_INDEX: OK (Not Supported) test VIDIOC_(TRY_)DECODER_CMD: OK (Not Supported)

Buffer ioctls:
test VIDIOC_REQBUFS/CREATE_BUFS/QUERYBUF: OK (Not Supported) test CREATE_BUFS maximum buffers: OK
test VIDIOC_REMOVE_BUFS: OK
test VIDIOC_EXPBUF: OK (Not Supported)
test Requests: OK (Not Supported)
test blocking wait: OK (Not Supported)

Total for intel-ipu6 device /dev/v4l-subdev5: 54, Succeeded: 54, Failed: 0, Warnings: 0

Nicola Fiorillo (7):
media: i2c: Add GC5035 image sensor driver
media: i2c: Add GC8034 image sensor driver
media: ipu-bridge: Add GalaxyCore GC5035 and GC8034
media: i2c: gc5035: Add crop support
media: i2c: gc8034: Add crop support
media: ipu-bridge: Add the GC5035 binning link frequency
media: i2c: gc5035: Add 2x2 binning support

 MAINTAINERS                          |   12 +
 drivers/media/i2c/Kconfig            |   20 +
 drivers/media/i2c/Makefile           |    2 +
 drivers/media/i2c/gc5035.c           | 1351 ++++++++++++++++++++++++++
 drivers/media/i2c/gc8034.c           | 1175 ++++++++++++++++++++++
 drivers/media/pci/intel/ipu-bridge.c |    4 +
 6 files changed, 2564 insertions(+)
 create mode 100644 drivers/media/i2c/gc5035.c
 create mode 100644 drivers/media/i2c/gc8034.c

base-commit: d7e7bca7169873b46e857c025c10f3336c1258d8

Signature · 3 lines
Regards,

Laurent Pinchart