Skip to contentSkip to conversation

media: i2c: Add OX05B1S camera sensor driver

PATCH Superseded Mirela Rabulea 5 participants 14 messages Jan 24, 2025 – Feb 3, 2025

Subsystems (2)

v3 of 4 Superseded Latest is v4 →

lore
Share & tools
lore
#0 lore raw

v3 cover media: i2c: Add OX05B1S camera sensor driver

Add a v4l2 subdevice driver for the Omnivision OX05B1S RGB-IR sensor

The Omnivision OX05B1S is a 1/2.5-Inch CMOS image sensor with an active array size of 2592 x 1944.

The following features are supported for OX05B1S:
- Manual exposure an gain control support
- vblank/hblank control support
- Supported resolution:
- 2592 x 1944 @ 30fps (SGRBG10)

Support for another sensor, OS08A20, is added as a separate patch, using another compatible.
For OS08a20, HDR mode control is supported, with one HDR mode: staggered HDR with 2 exposures on separate virtual channels. However, for now, only one exposure (VC 0) is accessible via get_frame_desc.

Supported resolutions:
- 1920 x 1080 @ 60fps (SBGGR10, no HDR)
- 1920 x 1080 @ 30fps (SBGGR10, HDR)
- 3840 x 2160 @ 30fps (SBGGR12, no HDR)
- 3840 x 2160 @ 15fps (SBGGR12, HDR)
- 3840 x 2160 @ 30fps (SBGGR10, no HDR)
- 3840 x 2160 @ 15fps (SBGGR10, HDR)

The driver was tested on upstream 6.13-rc7 on imx8mp-evk, but also on nxp tree based on 6.12 on imx95-19x19-evk.

The results of v4l2-compliance test:

root@imx8mpevk:/unit_tests# ./v4l2-compliance -d /dev/video0
v4l2-compliance 1.29.0-5304, 64 bits, 64-bit time_t
v4l2-compliance SHA: 8fb667bc4ec2 2025-01-22 12:37:43

Compliance test for mxc-isi device /dev/video0:

Driver Info:

	Driver name      : mxc-isi
	Card type        : mxc-isi-cap
	Bus info         : platform:32e00000.isi
	Driver version   : 6.13.0
	Capabilities     : 0xa4201000

Video Capture Multiplanar
I/O MC
Streaming
Extended Pix Format
Device Capabilities
Device Caps : 0x24201000
Video Capture Multiplanar
I/O MC
Streaming
Extended Pix Format
Media Driver Info:

	Driver name      : mxc-isi
	Model            : FSL Capture Media Device
	Serial           : 
	Bus info         : platform:32e00000.isi
	Media version    : 6.13.0
	Hardware revision: 0x00000000 (0)
	Driver version   : 6.13.0
Interface Info:
	ID               : 0x0300000c
	Type             : V4L Video
Entity Info:
	ID               : 0x0000000a (10)
	Name             : mxc_isi.0.capture
	Function         : V4L2 I/O
	Pad 0x0100000b   : 0: Sink
	  Link 0x0200000e: from remote pad 0x1000009 of entity 'mxc_isi.0' (Video Pixel Formatter): Data, Enabled, Immutable

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

Allow for multiple opens:
test second /dev/video0 open: OK
test VIDIOC_QUERYCAP: OK
test VIDIOC_G/S_PRIORITY: OK
test for unlimited opens: OK

Debug ioctls:
test VIDIOC_DBG_G/S_REGISTER: OK (Not Supported) 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
test VIDIOC_G/S_AUDIO: OK (Not Supported)
Inputs: 1 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)

Control ioctls (Input 0):
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: 4 Private Controls: 0

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

Codec ioctls (Input 0):
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 (Input 0):
test VIDIOC_REQBUFS/CREATE_BUFS/QUERYBUF: OK test CREATE_BUFS maximum buffers: OK test VIDIOC_REMOVE_BUFS: OK
test VIDIOC_EXPBUF: OK
test Requests: OK (Not Supported) test blocking wait: OK

Total for mxc-isi device /dev/video0: 49, Succeeded: 49, Failed: 0, Warnings: 0

Mirela Rabulea (4):
dt-bindings: media: i2c: Add OX05B1S sensor
media: ox05b1s: Add omnivision OX05B1S raw sensor driver
MAINTAINERS: Add entry for OX05B1S sensor driver
media: ox05b1s: Add support for Omnivision OS08A20 raw sensor

 .../bindings/media/i2c/ovti,ox05b1s.yaml      |  119 ++
 MAINTAINERS                                   |   10 +
 drivers/media/i2c/Kconfig                     |    1 +
 drivers/media/i2c/Makefile                    |    1 +
 drivers/media/i2c/ox05b1s/Kconfig             |   10 +
 drivers/media/i2c/ox05b1s/Makefile            |    2 +
 drivers/media/i2c/ox05b1s/ox05b1s.h           |   26 +
 drivers/media/i2c/ox05b1s/ox05b1s_mipi.c      | 1123 +++++++++++++++++
 drivers/media/i2c/ox05b1s/ox05b1s_modes.c     |  159 +++
 9 files changed, 1451 insertions(+)
 create mode 100644 Documentation/devicetree/bindings/media/i2c/ovti,ox05b1s.yaml
 create mode 100644 drivers/media/i2c/ox05b1s/Kconfig
 create mode 100644 drivers/media/i2c/ox05b1s/Makefile
 create mode 100644 drivers/media/i2c/ox05b1s/ox05b1s.h
 create mode 100644 drivers/media/i2c/ox05b1s/ox05b1s_mipi.c
 create mode 100644 drivers/media/i2c/ox05b1s/ox05b1s_modes.c
Signature · 1 line
2.25.1
#1 lore raw

PATCH v3 1/4 dt-bindings: media: i2c: Add OX05B1S sensor

Add bindings for Omnivision OX05B1S sensor. Also add compatible for Omnivision OS08A20 sensor.

---

Changes in v3:
Use unevaluatedProperties: false and drop orientation/rotation Drop items and keep alphabetical order in compatible property Shorten the description for reset_gpio
Make the supplies required.
Use generic node name (camera instead of ox05b1s)

Changes in v2:
Small updates on description
Update subject, drop "bindings" and "driver"
Just one binding patch (squash os08a20 bindings)
Re-flow to 80 columns.
Drop clock name (not needed in case of single clock)
Make the clock required property, strictly from sensor module point of view, it is mandatory (will use a fixed clock for nxp board)
Add regulators: avdd, dvdd, dovdd
Add $ref: /schemas/media/video-interface-devices.yaml
Drop assigned-clock* properties (defined in clocks.yaml)
Keep "additionalProperties : false" and orientation/rotation (unevaluatedProperties: false was suggested, but only orientation/rotation are needed from video-interface-devices.yaml) Include assigned-clock* in the example, for completeness sake (although it was also suggested to omit them)

 .../bindings/media/i2c/ovti,ox05b1s.yaml      | 119 ++++++++++++++++++
 1 file changed, 119 insertions(+)
 create mode 100644 Documentation/devicetree/bindings/media/i2c/ovti,ox05b1s.yaml
Documentation/devicetree/bindings/media/i2c/ovti,ox05b1s.yaml new file +119 -0
new file mode 100644
index 000000000000..9f35b4e67bea
@@ -0,0 +1,119 @@
+# SPDX-License-Identifier: (GPL-2.0-only OR BSD-2-Clause)
+# Copyright (C) 2024 NXP
+%YAML 1.2
+---
+$id: http://devicetree.org/schemas/media/i2c/ovti,ox05b1s.yaml#
+$schema: http://devicetree.org/meta-schemas/core.yaml#
+
+title: Omnivision OX05B1S Image Sensor
+
+maintainers:
+  - Mirela Rabulea <[email protected]>
+
+description:
+  The Omnivision OX05B1S is a 1/2.5-Inch CMOS image sensor with an active
+  array size of 2592 x 1944. It is programmable through I2C interface.
+  Image data is available via MIPI CSI-2 serial data output.
+
+allOf:
+  - $ref: /schemas/media/video-interface-devices.yaml#
+
+properties:
+  compatible:
+    enum:
+      - ovti,os08a20
+      - ovti,ox05b1s
+
+  reg:
+    maxItems: 1
+
+  clocks:
+    description: Input clock (24 MHz)
+    maxItems: 1
+
+  reset-gpios:
+    description: Active low XSHUTDOWN pin
+    maxItems: 1
+
+  avdd-supply:
+    description: Power for analog circuit (2.8V)
+
+  dovdd-supply:
+    description: Power for I/O circuit (1.8V)
+
+  dvdd-supply:
+    description: Power for digital circuit (1.2V)
+
+  port:
+    $ref: /schemas/graph.yaml#/$defs/port-base
+    additionalProperties: false
+    description: MIPI CSI-2 transmitter port
+
+    properties:
+      endpoint:
+        $ref: /schemas/media/video-interfaces.yaml#
+        unevaluatedProperties: false
+
+        properties:
+          data-lanes:
+            anyOf:
+              - items:
+                  - const: 1
+                  - const: 2
+              - items:
+                  - const: 1
+                  - const: 2
+                  - const: 3
+                  - const: 4
+        required:
+          - data-lanes
+
+    required:
+      - endpoint
+
+required:
+  - compatible
+  - reg
+  - clocks
+  - port
+  - avdd-supply
+  - dovdd-supply
+  - dvdd-supply
+
+unevaluatedProperties: false
+
+examples:
+  - |
+    #include <dt-bindings/gpio/gpio.h>
+
+    i2c {
+        #address-cells = <1>;
+        #size-cells = <0>;
+
+        camera@36 {
+            compatible = "ovti,ox05b1s";
+            reg = <0x36>;
+            clocks = <&ox05b1s_clk>;
+
+            assigned-clocks = <&ox05b1s_clk>;
+            assigned-clock-parents = <&ox05b1s_clk_parent>;
+            assigned-clock-rates = <24000000>;
+
+            reset-gpios = <&gpio1 6 GPIO_ACTIVE_LOW>;
+
+            avdd-supply = <&camera_avdd_2v8>;
+            dovdd-supply = <&camera_dovdd_1v8>;
+            dvdd-supply = <&camera_dvdd_1v2>;
+
+            orientation = <2>;
+            rotation = <0>;
+
+            port {
+                ox05b1s_mipi_0_ep: endpoint {
+                    remote-endpoint = <&mipi_csi0_ep>;
+                    data-lanes = <1 2 3 4>;
+                };
+            };
+        };
+    };
+...
Signature · 1 line
2.25.1
#3 lore raw

PATCH v3 2/4 media: ox05b1s: Add omnivision OX05B1S raw sensor driver

In reply to Mirela Rabulea

Add a v4l2 subdevice driver for the Omnivision OX05B1S RGB-IR sensor.

The Omnivision OX05B1S is a 1/2.5-Inch CMOS image sensor with an active array size of 2592 x 1944.

The following features are supported for OX05B1S:
- Manual exposure an gain control support
- vblank/hblank control support
- Supported resolution: 2592 x 1944 @ 30fps (SGRBG10)

---

Changes in v3:
Use helpers from v4l2-cci.h (drop ox05b1s_write_reg, ox05b1s_read_reg, ox05b1s_set_hts/vts/exp/analog_gain, ox05b1s_regmap_config) Don't hardcode timing registers: remove timing registers x_output_size/y_output_size from register configuration list, add them to ox05b1s_apply_current_mode Remove HTS,VTS from register config list as they are written by HBLANK and VBLANK controls through __v4l2_ctrl_handler_setup ox05b1s register config cleaning (remove all registers that were at their default value, and more, keep only what seems mandatory to be able to stream) Use const for ox05b1s_supported_modes
Device should be silent on success, use dev_dbg.
Drop unneeded {}
Fixed an error introduced in v2 in ox05b1s_nearest_size (set_fmt for 4k BGGR12 mode was stuck)
Fix an issue in ox05b1s_set_fmt, the format was saved in subdev state only for _TRY, save it also for _ACTIVE

Changes in v2:
Use dev_err_probe for missing clock, since it is now required property, and use NULL for devm_clk_get (no name for single clock), remove check for non NULL sensor->sensor_clk Remove dev_err message for devm_regmap_init_i2c allocation error
Added spaces inside brackets, wrap lines to 80
Remove some redundant initializations
Add regulators
Make "sizes" a pointer
Use struct v4l2_area instead of u32[2] array
Remove the count for supported_modes[] and supported_codes[], instead use sentinel element at the end
Consequently, update ox05b1s_enum_mbus_code, ox05b1s_enum_frame_size, ox05b1s_nearest_size, ox05b1s_find_code, to not use the count
Remove .h files for modes, however did not move this code in the driver file but added a separate c file for all supported modes
Refactor register lists to allow multiple register arrays per mode
Use GPL-2.0-only instead of GPL-2.0

 drivers/media/i2c/Kconfig                 |   1 +
 drivers/media/i2c/Makefile                |   1 +
 drivers/media/i2c/ox05b1s/Kconfig         |  10 +
 drivers/media/i2c/ox05b1s/Makefile        |   2 +
 drivers/media/i2c/ox05b1s/ox05b1s.h       |  22 +
 drivers/media/i2c/ox05b1s/ox05b1s_mipi.c  | 939 ++++++++++++++++++++++
 drivers/media/i2c/ox05b1s/ox05b1s_modes.c |  63 ++
 7 files changed, 1038 insertions(+)
 create mode 100644 drivers/media/i2c/ox05b1s/Kconfig
 create mode 100644 drivers/media/i2c/ox05b1s/Makefile
 create mode 100644 drivers/media/i2c/ox05b1s/ox05b1s.h
 create mode 100644 drivers/media/i2c/ox05b1s/ox05b1s_mipi.c
 create mode 100644 drivers/media/i2c/ox05b1s/ox05b1s_modes.c
drivers/media/i2c/Kconfig +1 -0
index 8ba096b8ebca..5cda062c0463 100644
@@ -700,6 +700,7 @@ config VIDEO_VGXY61
 
 source "drivers/media/i2c/ccs/Kconfig"
 source "drivers/media/i2c/et8ek8/Kconfig"
+source "drivers/media/i2c/ox05b1s/Kconfig"
 
 endif
 
drivers/media/i2c/Makefile +1 -0
index fbb988bd067a..028eb08e648c 100644
@@ -114,6 +114,7 @@ obj-$(CONFIG_VIDEO_OV9282) += ov9282.o
 obj-$(CONFIG_VIDEO_OV9640) += ov9640.o
 obj-$(CONFIG_VIDEO_OV9650) += ov9650.o
 obj-$(CONFIG_VIDEO_OV9734) += ov9734.o
+obj-$(CONFIG_VIDEO_OX05B1S) += ox05b1s/
 obj-$(CONFIG_VIDEO_RDACM20) += rdacm20.o
 obj-$(CONFIG_VIDEO_RDACM21) += rdacm21.o
 obj-$(CONFIG_VIDEO_RJ54N1) += rj54n1cb0c.o
drivers/media/i2c/ox05b1s/Kconfig new file +10 -0
new file mode 100644
index 000000000000..48fcd04b20d5
@@ -0,0 +1,10 @@
+config VIDEO_OX05B1S
+	tristate "OmniVision raw sensor support OX05B1S"
+	depends on OF
+	depends on GPIOLIB
+	select REGMAP_I2C
+	help
+	  This is a Video4Linux2 sensor driver for the Omnivision OX05B1S RGB-IR sensor.
+	  This is a 1/2.5-Inch CMOS image sensor with an active array size of 2592 x 1944.
+	  It is programmable through I2C interface.
+	  The output is on MIPI CSI-2 interface.
drivers/media/i2c/ox05b1s/Makefile new file +2 -0
new file mode 100644
index 000000000000..0b38dbf98bcd
@@ -0,0 +1,2 @@
+ox05b1s-objs := ox05b1s_modes.o ox05b1s_mipi.o
+obj-$(CONFIG_VIDEO_OX05B1S) += ox05b1s.o
drivers/media/i2c/ox05b1s/ox05b1s.h new file +22 -0
new file mode 100644
index 000000000000..a893c65894f3
@@ -0,0 +1,22 @@
+/* SPDX-License-Identifier: GPL-2.0-only */
+/*
+ * Copyright (C) 2024, NXP
+ */
+
+#ifndef OX05B1S_H
+#define OX05B1S_H
+
+#include <linux/types.h>
+
+struct ox05b1s_reg {
+	u32 addr;
+	u32 data;
+};
+
+struct ox05b1s_reglist {
+	struct ox05b1s_reg *regs;
+};
+
+extern struct ox05b1s_reglist ox05b1s_reglist_2592x1944[];
+
+#endif /* OX05B1S_H */
drivers/media/i2c/ox05b1s/ox05b1s_mipi.c new file +939 -0

939 lines not on this page · raw message

drivers/media/i2c/ox05b1s/ox05b1s_modes.c new file +63 -0

63 lines not on this page · raw message

Signature · 1 line
2.25.1
#4 lore raw

Re: [PATCH v3 2/4] media: ox05b1s: Add omnivision OX05B1S raw sensor driver

Le 24/01/2025 à 01:12, Mirela Rabulea a écrit :

Quoted 12 lines

Add a v4l2 subdevice driver for the Omnivision OX05B1S RGB-IR sensor.

The Omnivision OX05B1S is a 1/2.5-Inch CMOS image sensor with an active array size of 2592 x 1944.

The following features are supported for OX05B1S:
- Manual exposure an gain control support
- vblank/hblank control support
- Supported resolution: 2592 x 1944 @ 30fps (SGRBG10)

---

...

drivers/media/i2c/ox05b1s/ox05b1s_mipi.c line 145

Quoted 4 lines
drivers/media/i2c/ox05b1s/ox05b1s_mipi.c new file +4 -0
+static int ox05b1s_power_on(struct ox05b1s *sensor)
+{
+	struct device *dev = &sensor->i2c_client->dev;
+	int ret = 0;

No need to init.

Quoted 10 lines
drivers/media/i2c/ox05b1s/ox05b1s_mipi.c new file +10 -0
+
+	ret = regulator_bulk_enable(OX05B1S_NUM_SUPPLIES, sensor->supplies);
+	if (ret) {
+		dev_err(dev, "Failed to enable regulators\n");
+		return ret;
+	}
+
+	/* get out of powerdown and reset */
+	gpiod_set_value_cansleep(sensor->rst_gpio, 0);
+

drivers/media/i2c/ox05b1s/ox05b1s_mipi.c line 165

Quoted 10 lines
drivers/media/i2c/ox05b1s/ox05b1s_mipi.c new file +10 -0
+	ret = clk_prepare_enable(sensor->sensor_clk);
+	if (ret < 0) {
+		dev_err(dev, "Enable sensor clk fail ret=%d\n", ret);
+		goto reg_off;
+	}
+
+	/* with XVCLK@24MHz, t2 = 6ms required delay for ox05b1s before first SCCB transaction */
+	fsleep(6000);
+
+	return ret;

return 0;

Quoted 6 lines
drivers/media/i2c/ox05b1s/ox05b1s_mipi.c new file +6 -0
+
+reg_off:
+	regulator_bulk_disable(OX05B1S_NUM_SUPPLIES, sensor->supplies);
+
+	return ret;
+}

...

Quoted 15 lines
drivers/media/i2c/ox05b1s/ox05b1s_mipi.c new file +15 -0
+/* needs sensor lock and power on */
+static int ox05b1s_apply_current_mode(struct ox05b1s *sensor)
+{
+	struct device *dev = &sensor->i2c_client->dev;
+	struct ox05b1s_reglist *reg_data = sensor->mode->reg_data;
+	u32 w = sensor->mode->width;
+	u32 h = sensor->mode->height;
+	int ret = 0;
+
+	cci_write(sensor->regmap, OX05B1S_REG_SW_RST, 0x01, NULL);
+
+	while (reg_data->regs) {
+		ret = ox05b1s_write_reg_array(sensor, reg_data->regs);
+		if (ret)
+			goto out;

drivers/media/i2c/ox05b1s/ox05b1s_mipi.c line 553

Quoted 10 lines
drivers/media/i2c/ox05b1s/ox05b1s_mipi.c new file +10 -0
+		reg_data++;
+	}
+
+	cci_write(sensor->regmap, OX05B1S_REG_X_OUTPUT_SIZE, w, &ret);
+	cci_write(sensor->regmap, OX05B1S_REG_Y_OUTPUT_SIZE, h, &ret);
+	if (ret)
+		goto out;
+
+	/* setup handler will write actual controls into sensor registers */
+	ret =  __v4l2_ctrl_handler_setup(&sensor->ctrls.handler);

2 spaces after '='

Quoted 8 lines
drivers/media/i2c/ox05b1s/ox05b1s_mipi.c new file +8 -0
+
+out:
+	if (ret < 0)
+		dev_err(dev, "Failed to apply mode %dx%d,bpp=%d\n", w, h,
+			sensor->mode->bpp);
+
+	return ret;
+}

...

drivers/media/i2c/ox05b1s/ox05b1s_mipi.c line 666

Quoted 10 lines
drivers/media/i2c/ox05b1s/ox05b1s_mipi.c new file +10 -0
+static int ox05b1s_get_frame_desc(struct v4l2_subdev *sd, unsigned int pad,
+				  struct v4l2_mbus_frame_desc *fd)
+{
+	struct i2c_client *client = v4l2_get_subdevdata(sd);
+	struct ox05b1s *sensor = client_to_ox05b1s(client);
+
+	fd->type = V4L2_MBUS_FRAME_DESC_TYPE_CSI2;
+	fd->num_entries = 1;
+
+	/* get sensor current code*/

Missing space before */

Quoted 9 lines
drivers/media/i2c/ox05b1s/ox05b1s_mipi.c new file +9 -0
+	mutex_lock(&sensor->lock);
+	fd->entry[0].pixelcode = sensor->mode->code;
+	mutex_unlock(&sensor->lock);
+
+	fd->entry[0].bus.csi2.vc = 0;
+	fd->entry[0].bus.csi2.dt = ox05b1s_code2dt(fd->entry[0].pixelcode);
+
+	return 0;
+}

...

drivers/media/i2c/ox05b1s/ox05b1s_mipi.c line 733

Quoted 8 lines
drivers/media/i2c/ox05b1s/ox05b1s_mipi.c new file +8 -0
+static void ox05b1s_get_gpios(struct ox05b1s *sensor)
+{
+	struct device *dev = &sensor->i2c_client->dev;
+
+	sensor->rst_gpio = devm_gpiod_get_optional(dev, "reset",
+						   GPIOD_OUT_HIGH);
+	if (IS_ERR(sensor->rst_gpio))
+		dev_warn(dev, "No sensor reset pin available");

Missing ending \n

Quoted 9 lines
drivers/media/i2c/ox05b1s/ox05b1s_mipi.c new file +9 -0
+}
+
+static int ox05b1s_get_regulators(struct ox05b1s *sensor)
+{
+	struct device *dev = &sensor->i2c_client->dev;
+	unsigned int i;
+
+	for (i = 0; i < OX05B1S_NUM_SUPPLIES; i++)
+		sensor->supplies[i].supply = ox05b1s_supply_name[i];

drivers/media/i2c/ox05b1s/ox05b1s_mipi.c line 752

Quoted 10 lines
drivers/media/i2c/ox05b1s/ox05b1s_mipi.c new file +10 -0
+
+	return devm_regulator_bulk_get(dev, OX05B1S_NUM_SUPPLIES, sensor->supplies);
+}
+
+static int ox05b1s_read_chip_id(struct ox05b1s *sensor)
+{
+	struct device *dev = &sensor->i2c_client->dev;
+	u64 chip_id = 0;
+	char *camera_name;
+	int ret = 0;

No need to init.

Quoted 12 lines
drivers/media/i2c/ox05b1s/ox05b1s_mipi.c new file +12 -0
+
+	ret = cci_read(sensor->regmap, OX05B1S_REG_CHIP_ID, &chip_id, NULL);
+	if (ret) {
+		dev_err(dev, "Camera chip_id read error\n");
+		return -ENODEV;
+	}
+
+	switch (chip_id) {
+	case 0x580542:
+		camera_name = "ox05b1s";
+		break;
+	default:

drivers/media/i2c/ox05b1s/ox05b1s_mipi.c line 774

Quoted 10 lines
drivers/media/i2c/ox05b1s/ox05b1s_mipi.c new file +10 -0
+		camera_name = "unknown";
+		break;
+	}
+
+	if (chip_id == sensor->model->chip_id) {
+		dev_dbg(dev, "Camera %s detected, chip_id=%llx\n", camera_name, chip_id);
+	} else {
+		dev_err(dev, "Detected %s camera (chip_id=%llx), but expected %s (chip_id=%x)\n",
+			camera_name, chip_id, sensor->model->name, sensor->model->chip_id);
+		ret = -ENODEV;

Could be return -ENODEV;
and return 0; below, to ease reading.

drivers/media/i2c/ox05b1s/ox05b1s_mipi.c line 782

Quoted 8 lines
drivers/media/i2c/ox05b1s/ox05b1s_mipi.c new file +8 -0
+	}
+
+	return ret;
+}
+
+static int ox05b1s_probe(struct i2c_client *client)
+{
+	int retval;

Using just 'ret' would be slighly shorter and more consistent with other functions above.

Quoted 31 lines
drivers/media/i2c/ox05b1s/ox05b1s_mipi.c new file +31 -0
+	struct device *dev = &client->dev;
+	struct v4l2_subdev *sd;
+	struct ox05b1s *sensor;
+
+	sensor = devm_kzalloc(dev, sizeof(*sensor), GFP_KERNEL);
+	if (!sensor)
+		return -ENOMEM;
+
+	sensor->regmap = devm_cci_regmap_init_i2c(client, 16);
+	if (IS_ERR(sensor->regmap))
+		return PTR_ERR(sensor->regmap);
+
+	sensor->i2c_client = client;
+
+	sensor->model = of_device_get_match_data(dev);
+
+	ox05b1s_get_gpios(sensor);
+
+	/* Get system clock, xvclk */
+	sensor->sensor_clk = devm_clk_get(dev, NULL);
+	if (IS_ERR(sensor->sensor_clk))
+		return dev_err_probe(dev, PTR_ERR(sensor->sensor_clk),
+				     "Failed to get xvclk\n");
+
+	retval = ox05b1s_get_regulators(sensor);
+	if (retval)
+		return dev_err_probe(dev, retval, "Failed to get regulators\n");
+
+	sd = &sensor->subdev;
+	v4l2_i2c_subdev_init(sd, client, &ox05b1s_subdev_ops);
+	sd->internal_ops = &ox05b1s_internal_ops;

drivers/media/i2c/ox05b1s/ox05b1s_mipi.c line 823

Quoted 10 lines
drivers/media/i2c/ox05b1s/ox05b1s_mipi.c new file +10 -0
+	sd->flags |= V4L2_SUBDEV_FL_HAS_DEVNODE;
+	sd->dev = &client->dev;
+	sd->entity.function = MEDIA_ENT_F_CAM_SENSOR;
+	sensor->pads[OX05B1S_SENS_PAD_SOURCE].flags = MEDIA_PAD_FL_SOURCE;
+	retval = media_entity_pads_init(&sd->entity, OX05B1S_SENS_PADS_NUM,
+					sensor->pads);
+	if (retval)
+		goto probe_out;
+
+	mutex_init(&sensor->lock);

This could be devm_mutex_init().
This would slighlty simplify the remove function.
Otherwise, a mutex_destroy() is potentialy missing in the error handling of the probe.

drivers/media/i2c/ox05b1s/ox05b1s_mipi.c line 832

Quoted 9 lines
drivers/media/i2c/ox05b1s/ox05b1s_mipi.c new file +9 -0
+
+	retval = ox05b1s_init_controls(sensor);
+	if (retval)
+		goto probe_err_entity_cleanup;
+
+	/* power on manually */
+	retval = ox05b1s_power_on(sensor);
+	if (retval) {
+		dev_err(dev, "Failed to power on\n");

dev_err_probe() can still be used to be consistent with other error path above.

Quoted 8 lines
drivers/media/i2c/ox05b1s/ox05b1s_mipi.c new file +8 -0
+		goto probe_err_free_ctrls;
+	}
+
+	pm_runtime_set_active(dev);
+	pm_runtime_get_noresume(dev);
+	pm_runtime_enable(dev);
+
+	retval = ox05b1s_read_chip_id(sensor);

drivers/media/i2c/ox05b1s/ox05b1s_mipi.c line 850

Quoted 10 lines
drivers/media/i2c/ox05b1s/ox05b1s_mipi.c new file +10 -0
+	if (retval)
+		goto probe_err_pm_runtime;
+
+	v4l2_i2c_subdev_set_name(sd, client, sensor->model->name, NULL);
+
+	/* Centrally managed subdev active state */
+	sd->state_lock = &sensor->lock;
+	retval = v4l2_subdev_init_finalize(sd);
+	if (retval < 0) {
+		dev_err(dev, "Subdev init error: %d\n", retval);

Same

drivers/media/i2c/ox05b1s/ox05b1s_mipi.c line 856

Quoted 6 lines
drivers/media/i2c/ox05b1s/ox05b1s_mipi.c new file +6 -0
+		goto probe_err_pm_runtime;
+	}
+
+	retval = v4l2_async_register_subdev_sensor(sd);
+	if (retval < 0) {
+		dev_err(&client->dev, "Async register failed, ret=%d\n", retval);

Same

Quoted 25 lines
drivers/media/i2c/ox05b1s/ox05b1s_mipi.c new file +25 -0
+		goto probe_err_subdev_cleanup;
+	}
+
+	sensor->mode = &sensor->model->supported_modes[0];
+	ox05b1s_update_controls(sensor);
+
+	pm_runtime_set_autosuspend_delay(dev, 1000);
+	pm_runtime_use_autosuspend(dev);
+	pm_runtime_put_autosuspend(dev);
+
+	return 0;
+
+probe_err_subdev_cleanup:
+	v4l2_subdev_cleanup(sd);
+probe_err_pm_runtime:
+	pm_runtime_put_noidle(dev);
+	pm_runtime_disable(dev);
+	ox05b1s_runtime_suspend(dev);
+probe_err_free_ctrls:
+	v4l2_ctrl_handler_free(&sensor->ctrls.handler);
+probe_err_entity_cleanup:
+	media_entity_cleanup(&sd->entity);
+probe_out:
+	return retval;
+}

...

drivers/media/i2c/ox05b1s/ox05b1s_mipi.c line 928

Quoted 3 lines
drivers/media/i2c/ox05b1s/ox05b1s_mipi.c new file +3 -0
+static struct i2c_driver ox05b1s_i2c_driver = {
+	.driver = {
+		.name  = "ox05b1s",

2 spaces after .name.

Quoted 23 lines
drivers/media/i2c/ox05b1s/ox05b1s_mipi.c new file +11 -0
+		.pm = pm_ptr(&ox05b1s_pm_ops),
+		.of_match_table	= ox05b1s_of_match,
+	},
+	.probe	= ox05b1s_probe,
+	.remove = ox05b1s_remove,
+};
+
+module_i2c_driver(ox05b1s_i2c_driver);
+MODULE_DESCRIPTION("Omnivision OX05B1S MIPI Camera Subdev Driver");
+MODULE_AUTHOR("Mirela Rabulea <[email protected]>");
+MODULE_LICENSE("GPL");
drivers/media/i2c/ox05b1s/ox05b1s_modes.c new file +6 -0
new file mode 100644
index 000000000000..1f3b822d4482
@@ -0,0 +1,63 @@
+// SPDX-License-Identifier: GPL-2.0-only
+/*
+ * Register configurations for all sensor supported modes
+ * Copyright (C) 2024, NXP
+ * Copyright (C) 2024, Omnivision
+ * Copyright (C) 2024, Verisilicon

drivers/media/i2c/ox05b1s/ox05b1s_modes.c line 16

Quoted 10 lines
drivers/media/i2c/ox05b1s/ox05b1s_modes.c new file +10 -0
+ *
+ */
+
+#include "ox05b1s.h"
+
+/*
+ * Register configuration for Omnivision OX05B1S raw camera
+ * 2592X1944_30FPS_FULL_RGBIr 2592 1944
+ */
+struct ox05b1s_reg ovx5b_init_setting_2592x1944[] = {

I think this could easily be made a const struct.

Quoted 28 lines
drivers/media/i2c/ox05b1s/ox05b1s_modes.c new file +28 -0
+	{ 0x0107, 0x01 },
+	{ 0x0307, 0x02 },
+	{ 0x034a, 0x05 },
+	{ 0x040b, 0x5c },
+	{ 0x040c, 0xcd },
+	{ 0x3009, 0x2e },
+	{ 0x3219, 0x08 },
+	{ 0x3684, 0x6d },
+	{ 0x3685, 0x6d },
+	{ 0x3686, 0x6d },
+	{ 0x3687, 0x6d },
+	{ 0x368c, 0x07 },
+	{ 0x368d, 0x07 },
+	{ 0x368e, 0x07 },
+	{ 0x368f, 0x00 },
+	{ 0x3690, 0x04 },
+	{ 0x3691, 0x04 },
+	{ 0x3692, 0x04 },
+	{ 0x3693, 0x04 },
+	{ 0x3698, 0x00 },
+	{ 0x36a0, 0x05 },
+	{ 0x36a2, 0x16 },
+	{ 0x36a3, 0x03 },
+	{ 0x36a4, 0x07 },
+	{ 0x36a5, 0x24 },
+	{ 0x36e3, 0x09 },
+	{ 0x3702, 0x0a },
+	{ 0x3821, 0x04 }, /* mirror */

drivers/media/i2c/ox05b1s/ox05b1s_modes.c line 54

Quoted 10 lines
drivers/media/i2c/ox05b1s/ox05b1s_modes.c new file +10 -0
+	{ 0x3822, 0x10 },
+	{ 0x382b, 0x03 },
+	{ 0x3866, 0x10 },
+	{ 0x386c, 0x46 },
+	{ 0x386d, 0x08 },
+	{ 0x386e, 0x7b },
+	{ 0x4802, 0x00 },
+	{ 0x481b, 0x3c },
+	{ 0x4837, 0x19 },
+	{ /* sentinel*/ },

Nitpick: no need for ending comma after a terminator.

drivers/media/i2c/ox05b1s/ox05b1s_modes.c line 57

Quoted 3 lines
drivers/media/i2c/ox05b1s/ox05b1s_modes.c new file +3 -0
+};
+
+struct ox05b1s_reglist ox05b1s_reglist_2592x1944[] = {

I think this could easily be made a const struct.

Quoted 6 lines
drivers/media/i2c/ox05b1s/ox05b1s_modes.c new file +6 -0
+	{
+		.regs = ovx5b_init_setting_2592x1944
+	}, {
+		/* sentinel */
+	}
+};
#5 lore raw

Re: [PATCH v3 2/4] media: ox05b1s: Add omnivision OX05B1S raw sensor driver

In reply to Mirela Rabulea

drivers/media/i2c/ox05b1s/ox05b1s_mipi.c line 754

Quoted 9 lines · Mirela Rabulea
drivers/media/i2c/ox05b1s/ox05b1s_mipi.c new file +9 -0
+
+static int ox05b1s_read_chip_id(struct ox05b1s *sensor)
+{
+	struct device *dev = &sensor->i2c_client->dev;
+	u64 chip_id = 0;
+	char *camera_name;
+	int ret = 0;
+
+	ret = cci_read(sensor->regmap, OX05B1S_REG_CHIP_ID, &chip_id, NULL);

This suggests these are compatible devices. But in the binding you said they are not... so your binding is not correct. Express compatibility with proper fallback.

Quoted 24 lines
drivers/media/i2c/ox05b1s/ox05b1s_mipi.c new file +24 -0
+	if (ret) {
+		dev_err(dev, "Camera chip_id read error\n");
+		return -ENODEV;
+	}
+
+	switch (chip_id) {
+	case 0x580542:
+		camera_name = "ox05b1s";
+		break;
+	default:
+		camera_name = "unknown";
+		break;
+	}
+
+	if (chip_id == sensor->model->chip_id) {
+		dev_dbg(dev, "Camera %s detected, chip_id=%llx\n", camera_name, chip_id);
+	} else {
+		dev_err(dev, "Detected %s camera (chip_id=%llx), but expected %s (chip_id=%x)\n",
+			camera_name, chip_id, sensor->model->name, sensor->model->chip_id);
+		ret = -ENODEV;
+	}
+
+	return ret;
+}

...

drivers/media/i2c/ox05b1s/ox05b1s_mipi.c line 919

Quoted 4 lines
drivers/media/i2c/ox05b1s/ox05b1s_mipi.c new file +4 -0
+
+static const struct of_device_id ox05b1s_of_match[] = {
+	{
+		.compatible = "ovti,ox05b1s",

And this is incomplete, according to current binding, so it seems you wanted to make them compatible just did not write the binding like that?

Confusing.

Quoted 32 lines
drivers/media/i2c/ox05b1s/ox05b1s_mipi.c new file +20 -0
+		.data = &ox05b1s_data,
+	},
+	{ /* sentinel */ }
+};
+MODULE_DEVICE_TABLE(of, ox05b1s_of_match);
+
+static struct i2c_driver ox05b1s_i2c_driver = {
+	.driver = {
+		.name  = "ox05b1s",
+		.pm = pm_ptr(&ox05b1s_pm_ops),
+		.of_match_table	= ox05b1s_of_match,
+	},
+	.probe	= ox05b1s_probe,
+	.remove = ox05b1s_remove,
+};
+
+module_i2c_driver(ox05b1s_i2c_driver);
+MODULE_DESCRIPTION("Omnivision OX05B1S MIPI Camera Subdev Driver");
+MODULE_AUTHOR("Mirela Rabulea <[email protected]>");
+MODULE_LICENSE("GPL");
drivers/media/i2c/ox05b1s/ox05b1s_modes.c new file +6 -0
new file mode 100644
index 000000000000..1f3b822d4482
@@ -0,0 +1,63 @@
+// SPDX-License-Identifier: GPL-2.0-only
+/*
+ * Register configurations for all sensor supported modes
+ * Copyright (C) 2024, NXP
+ * Copyright (C) 2024, Omnivision
+ * Copyright (C) 2024, Verisilicon

drivers/media/i2c/ox05b1s/ox05b1s_modes.c line 16

Quoted 10 lines
drivers/media/i2c/ox05b1s/ox05b1s_modes.c new file +10 -0
+ *
+ */
+
+#include "ox05b1s.h"
+
+/*
+ * Register configuration for Omnivision OX05B1S raw camera
+ * 2592X1944_30FPS_FULL_RGBIr 2592 1944
+ */
+struct ox05b1s_reg ovx5b_init_setting_2592x1944[] = {

Why this is not const? I commented last time with the same.

Quoted 31 lines
drivers/media/i2c/ox05b1s/ox05b1s_modes.c new file +31 -0
+	{ 0x0107, 0x01 },
+	{ 0x0307, 0x02 },
+	{ 0x034a, 0x05 },
+	{ 0x040b, 0x5c },
+	{ 0x040c, 0xcd },
+	{ 0x3009, 0x2e },
+	{ 0x3219, 0x08 },
+	{ 0x3684, 0x6d },
+	{ 0x3685, 0x6d },
+	{ 0x3686, 0x6d },
+	{ 0x3687, 0x6d },
+	{ 0x368c, 0x07 },
+	{ 0x368d, 0x07 },
+	{ 0x368e, 0x07 },
+	{ 0x368f, 0x00 },
+	{ 0x3690, 0x04 },
+	{ 0x3691, 0x04 },
+	{ 0x3692, 0x04 },
+	{ 0x3693, 0x04 },
+	{ 0x3698, 0x00 },
+	{ 0x36a0, 0x05 },
+	{ 0x36a2, 0x16 },
+	{ 0x36a3, 0x03 },
+	{ 0x36a4, 0x07 },
+	{ 0x36a5, 0x24 },
+	{ 0x36e3, 0x09 },
+	{ 0x3702, 0x0a },
+	{ 0x3821, 0x04 }, /* mirror */
+	{ 0x3822, 0x10 },
+	{ 0x382b, 0x03 },
+	{ 0x3866, 0x10 },

drivers/media/i2c/ox05b1s/ox05b1s_modes.c line 57

Quoted 10 lines
drivers/media/i2c/ox05b1s/ox05b1s_modes.c new file +10 -0
+	{ 0x386c, 0x46 },
+	{ 0x386d, 0x08 },
+	{ 0x386e, 0x7b },
+	{ 0x4802, 0x00 },
+	{ 0x481b, 0x3c },
+	{ 0x4837, 0x19 },
+	{ /* sentinel*/ },
+};
+
+struct ox05b1s_reglist ox05b1s_reglist_2592x1944[] = {

Why not const?

Best regards,
Krzysztof

#6 lore raw

Re: [PATCH v3 2/4] media: ox05b1s: Add omnivision OX05B1S raw sensor driver

Quoted 14 lines · Krzysztof Kozlowski

drivers/media/i2c/ox05b1s/ox05b1s_mipi.c line 754

Quoted 9 lines · Mirela Rabulea
drivers/media/i2c/ox05b1s/ox05b1s_mipi.c new file +9 -0
+
+static int ox05b1s_read_chip_id(struct ox05b1s *sensor)
+{
+	struct device *dev = &sensor->i2c_client->dev;
+	u64 chip_id = 0;
+	char *camera_name;
+	int ret = 0;
+
+	ret = cci_read(sensor->regmap, OX05B1S_REG_CHIP_ID, &chip_id, NULL);

This suggests these are compatible devices. But in the binding you said they are not... so your binding is not correct. Express compatibility with proper fallback.

Unfortunately we can't do that for camera sensors. It's important for drivers to be able to identify the camera sensor model without having to power up the device at probe time, depending on what device the sensor is integrated in. For instance, with camera sensors found in laptops, the privacy LED is often connected to the sensor power supply, and a flashing privacy light when booting scares users.

Reading the ID register at probe time is fine when running on a platform where the sensor can be powered up when probing, so the driver isn't wrong doing so. It's also fine for drivers to not implement the no-power probe right away. DT bindings however need to be ready for this, so a fallback string can't be used.

Quoted 129 lines
Quoted 24 lines
drivers/media/i2c/ox05b1s/ox05b1s_mipi.c new file +24 -0
+	if (ret) {
+		dev_err(dev, "Camera chip_id read error\n");
+		return -ENODEV;
+	}
+
+	switch (chip_id) {
+	case 0x580542:
+		camera_name = "ox05b1s";
+		break;
+	default:
+		camera_name = "unknown";
+		break;
+	}
+
+	if (chip_id == sensor->model->chip_id) {
+		dev_dbg(dev, "Camera %s detected, chip_id=%llx\n", camera_name, chip_id);
+	} else {
+		dev_err(dev, "Detected %s camera (chip_id=%llx), but expected %s (chip_id=%x)\n",
+			camera_name, chip_id, sensor->model->name, sensor->model->chip_id);
+		ret = -ENODEV;
+	}
+
+	return ret;
+}

...

drivers/media/i2c/ox05b1s/ox05b1s_mipi.c line 919

Quoted 4 lines
drivers/media/i2c/ox05b1s/ox05b1s_mipi.c new file +4 -0
+
+static const struct of_device_id ox05b1s_of_match[] = {
+	{
+		.compatible = "ovti,ox05b1s",

And this is incomplete, according to current binding, so it seems you wanted to make them compatible just did not write the binding like that?

Confusing.

Quoted 32 lines
drivers/media/i2c/ox05b1s/ox05b1s_mipi.c new file +20 -0
+		.data = &ox05b1s_data,
+	},
+	{ /* sentinel */ }
+};
+MODULE_DEVICE_TABLE(of, ox05b1s_of_match);
+
+static struct i2c_driver ox05b1s_i2c_driver = {
+	.driver = {
+		.name  = "ox05b1s",
+		.pm = pm_ptr(&ox05b1s_pm_ops),
+		.of_match_table	= ox05b1s_of_match,
+	},
+	.probe	= ox05b1s_probe,
+	.remove = ox05b1s_remove,
+};
+
+module_i2c_driver(ox05b1s_i2c_driver);
+MODULE_DESCRIPTION("Omnivision OX05B1S MIPI Camera Subdev Driver");
+MODULE_AUTHOR("Mirela Rabulea <[email protected]>");
+MODULE_LICENSE("GPL");
drivers/media/i2c/ox05b1s/ox05b1s_modes.c new file +6 -0
new file mode 100644
index 000000000000..1f3b822d4482
@@ -0,0 +1,63 @@
+// SPDX-License-Identifier: GPL-2.0-only
+/*
+ * Register configurations for all sensor supported modes
+ * Copyright (C) 2024, NXP
+ * Copyright (C) 2024, Omnivision
+ * Copyright (C) 2024, Verisilicon

drivers/media/i2c/ox05b1s/ox05b1s_modes.c line 16

Quoted 10 lines
drivers/media/i2c/ox05b1s/ox05b1s_modes.c new file +10 -0
+ *
+ */
+
+#include "ox05b1s.h"
+
+/*
+ * Register configuration for Omnivision OX05B1S raw camera
+ * 2592X1944_30FPS_FULL_RGBIr 2592 1944
+ */
+struct ox05b1s_reg ovx5b_init_setting_2592x1944[] = {

Why this is not const? I commented last time with the same.

Quoted 31 lines
drivers/media/i2c/ox05b1s/ox05b1s_modes.c new file +31 -0
+	{ 0x0107, 0x01 },
+	{ 0x0307, 0x02 },
+	{ 0x034a, 0x05 },
+	{ 0x040b, 0x5c },
+	{ 0x040c, 0xcd },
+	{ 0x3009, 0x2e },
+	{ 0x3219, 0x08 },
+	{ 0x3684, 0x6d },
+	{ 0x3685, 0x6d },
+	{ 0x3686, 0x6d },
+	{ 0x3687, 0x6d },
+	{ 0x368c, 0x07 },
+	{ 0x368d, 0x07 },
+	{ 0x368e, 0x07 },
+	{ 0x368f, 0x00 },
+	{ 0x3690, 0x04 },
+	{ 0x3691, 0x04 },
+	{ 0x3692, 0x04 },
+	{ 0x3693, 0x04 },
+	{ 0x3698, 0x00 },
+	{ 0x36a0, 0x05 },
+	{ 0x36a2, 0x16 },
+	{ 0x36a3, 0x03 },
+	{ 0x36a4, 0x07 },
+	{ 0x36a5, 0x24 },
+	{ 0x36e3, 0x09 },
+	{ 0x3702, 0x0a },
+	{ 0x3821, 0x04 }, /* mirror */
+	{ 0x3822, 0x10 },
+	{ 0x382b, 0x03 },
+	{ 0x3866, 0x10 },

drivers/media/i2c/ox05b1s/ox05b1s_modes.c line 57

Quoted 10 lines
drivers/media/i2c/ox05b1s/ox05b1s_modes.c new file +10 -0
+	{ 0x386c, 0x46 },
+	{ 0x386d, 0x08 },
+	{ 0x386e, 0x7b },
+	{ 0x4802, 0x00 },
+	{ 0x481b, 0x3c },
+	{ 0x4837, 0x19 },
+	{ /* sentinel*/ },
+};
+
+struct ox05b1s_reglist ox05b1s_reglist_2592x1944[] = {

Why not const?

Best regards,
Krzysztof

Signature · 3 lines
Regards,

Laurent Pinchart
#7 lore raw

Re: [PATCH v3 2/4] media: ox05b1s: Add omnivision OX05B1S raw sensor driver

In reply to Mirela Rabulea

…

Quoted 2 lines

+++ b/drivers/media/i2c/ox05b1s/ox05b1s_mipi.c

(quoted diff) +0 -0
@@ -0,0 +1,939 @@

…

Quoted 3 lines
drivers/media/i2c/ox05b1s/ox05b1s_mipi.c new file +3 -0
+static int ox05b1s_get_frame_desc(struct v4l2_subdev *sd, unsigned int pad,
+				  struct v4l2_mbus_frame_desc *fd)
+{

…

drivers/media/i2c/ox05b1s/ox05b1s_mipi.c line 669

Quoted 4 lines
drivers/media/i2c/ox05b1s/ox05b1s_mipi.c new file +4 -0
+	/* get sensor current code*/
+	mutex_lock(&sensor->lock);
+	fd->entry[0].pixelcode = sensor->mode->code;
+	mutex_unlock(&sensor->lock);

…

Under which circumstances would you become interested to apply a statement like “guard(mutex)(&sensor->lock);”?
https://elixir.bootlin.com/linux/v6.13.1/source/include/linux/mutex.h#L201

Regards,
Markus

#8 lore raw

PATCH v3 3/4 MAINTAINERS: Add entry for OX05B1S sensor driver

In reply to Mirela Rabulea

Add maintainer for Omnivision OX05B1S sensor driver.

---

Changes in v3:
None

Changes in v2:
None

 MAINTAINERS | 10 ++++++++++
 1 file changed, 10 insertions(+)
MAINTAINERS +10 -0
index 6ff0565d874f..fca5f3f2f2bf 100644
@@ -17570,6 +17570,16 @@ S:	Maintained
 T:	git git://linuxtv.org/media.git
 F:	drivers/media/i2c/ov9734.c
 
+OMNIVISION OX05B1S SENSOR DRIVER
+M:	Mirela Rabulea <[email protected]>
+R:	Laurentiu Palcu <[email protected]>
+R:	Robert Chiras <[email protected]>
+L:	[email protected]
+S:	Maintained
+T:	git git://linuxtv.org/media_tree.git
+F:	Documentation/devicetree/bindings/media/i2c/ovti,ox05b1s.yaml
+F:	drivers/media/i2c/ox05b1s/*
+
 ONBOARD USB HUB DRIVER
 M:	Matthias Kaehlcke <[email protected]>
 L:	[email protected]
Signature · 1 line
2.25.1
#9 lore raw

PATCH v3 4/4 media: ox05b1s: Add support for Omnivision OS08A20 raw sensor

In reply to Mirela Rabulea

This is an 8 megapixel raw10/raw12 sensor with HDR capabilities. HDR mode control is supported, with one HDR mode: staggered HDR with 2 exposures on separate virtual channels. However, for now, only one exposure (VC 0) is accessible via get_frame_desc.

Supported resolutions:
- 1920 x 1080 @ 60fps (SBGGR10, no HDR)
- 1920 x 1080 @ 30fps (SBGGR10, HDR)
- 3840 x 2160 @ 30fps (SBGGR12, no HDR)
- 3840 x 2160 @ 15fps (SBGGR12, HDR)
- 3840 x 2160 @ 30fps (SBGGR10, no HDR)
- 3840 x 2160 @ 15fps (SBGGR10, HDR)

---

Changes in v3:
Don't hardcode timing registers: remove timing registers x_output_size/y_output_size from register configuration list, add them to ox05b1s_apply_current_mode Remove HTS,VTS from register config list as they are written by HBLANK and VBLANK controls through __v4l2_ctrl_handler_setup
Use const for os08a20_supported_modes
os08a20 register config cleaning (remove all registers that were at their default value, and more, keep only what seems mandatory to be able to stream) Let the 4k 10bit mode by default without hdr, all 3 modes are now by default without hdr, staggered hdr may be enabled via v4l2-ctl for any of them. Separate the 10/12 bit register settings into separate lists: os08a20_init_setting_10bit, os08a20_init_setting_12bit
Update commit description: rearrange supported resolutions and remove 1 duplicate line, state HDR limitation
Increase a bit the default vts for 1080p, to get exactly 60fps, it was 62.61
Use regmap_update_bits() directly and remove ox05b1s_regmap_update_bits()

Changes in v2:
Add spaces inside brackets, wrap lines to 80
Remove some redundant initialization
Use a loop in os08a20_enable_staggered_hdr/os08a20_disable_staggered_hdr, for that, add a register settings array for HDR enabling/disabling Make "sizes" a pointer
Remove mode headers, add supported modes in the dedicated c file, ox05b1s_modes.c
Refactor register lists, for os08a20 use a common list for all modes, and also specific lists per mode

 drivers/media/i2c/ox05b1s/ox05b1s.h       |   4 +
 drivers/media/i2c/ox05b1s/ox05b1s_mipi.c  | 184 ++++++++++++++++++++++
 drivers/media/i2c/ox05b1s/ox05b1s_modes.c |  96 +++++++++++
 3 files changed, 284 insertions(+)
drivers/media/i2c/ox05b1s/ox05b1s.h +4 -0
index a893c65894f3..5115060e23cb 100644
@@ -17,6 +17,10 @@ struct ox05b1s_reglist {
 	struct ox05b1s_reg *regs;
 };
 
+extern struct ox05b1s_reglist os08a20_reglist_4k_10b[];
+extern struct ox05b1s_reglist os08a20_reglist_4k_12b[];
+extern struct ox05b1s_reglist os08a20_reglist_1080p_10b[];
+
 extern struct ox05b1s_reglist ox05b1s_reglist_2592x1944[];
 
 #endif /* OX05B1S_H */
drivers/media/i2c/ox05b1s/ox05b1s_mipi.c +184 -0

254 lines not on this page · raw message

drivers/media/i2c/ox05b1s/ox05b1s_modes.c +96 -0

102 lines not on this page · raw message

Signature · 1 line
2.25.1
#10 lore raw

Re: [PATCH v3 4/4] media: ox05b1s: Add support for Omnivision OS08A20 raw sensor

Le 24/01/2025 à 01:12, Mirela Rabulea a écrit :

Quoted 14 lines

This is an 8 megapixel raw10/raw12 sensor with HDR capabilities. HDR mode control is supported, with one HDR mode: staggered HDR with 2 exposures on separate virtual channels. However, for now, only one exposure (VC 0) is accessible via get_frame_desc.

Supported resolutions:
- 1920 x 1080 @ 60fps (SBGGR10, no HDR)
- 1920 x 1080 @ 30fps (SBGGR10, HDR)
- 3840 x 2160 @ 30fps (SBGGR12, no HDR)
- 3840 x 2160 @ 15fps (SBGGR12, HDR)
- 3840 x 2160 @ 30fps (SBGGR10, no HDR)
- 3840 x 2160 @ 15fps (SBGGR10, HDR)

...

drivers/media/i2c/ox05b1s/ox05b1s_modes.c line 19

Quoted 8 lines
drivers/media/i2c/ox05b1s/ox05b1s_modes.c +8 -0
+/* Common register configuration for Omnivision OS08A20 raw camera */
+struct ox05b1s_reg os08a20_init_setting_common[] = {
+	{ 0x3605, 0x50 },
+	{ 0x3610, 0x39 },
+	{ 0x375e, 0x0b },
+	{ 0x5001, 0x42 },
+	{ 0x5005, 0x00 },
+	{ /* sentinel*/ },

No need for ending comma.
The struct could maybe be const.

drivers/media/i2c/ox05b1s/ox05b1s_modes.c line 31

Quoted 12 lines
drivers/media/i2c/ox05b1s/ox05b1s_modes.c +12 -0
+};
+
+/* Common register configuration for Omnivision OS08A20 10 bit */
+struct ox05b1s_reg os08a20_init_setting_10bit[] = {
+	{ 0x031e, 0x09 },
+	{ 0x3609, 0xb5 },
+	{ 0x3660, 0x43 },
+	{ 0x3706, 0x35 },
+	{ 0x370a, 0x00 },
+	{ 0x370b, 0x98 },
+	{ 0x3709, 0x49 },
+	{ /* sentinel*/ },

No need for ending comma.
The struct could maybe be const.

drivers/media/i2c/ox05b1s/ox05b1s_modes.c line 43

Quoted 12 lines
drivers/media/i2c/ox05b1s/ox05b1s_modes.c +12 -0
+};
+
+/* Common register configuration for Omnivision OS08A20 12 bit */
+struct ox05b1s_reg os08a20_init_setting_12bit[] = {
+	{ 0x031e, 0x0a },
+	{ 0x3609, 0xdb },
+	{ 0x3660, 0xd3 },
+	{ 0x3706, 0x6a },
+	{ 0x370a, 0x01 },
+	{ 0x370b, 0x30 },
+	{ 0x3709, 0x48 },
+	{ /* sentinel*/ },

No need for ending comma.
The struct could maybe be const.

drivers/media/i2c/ox05b1s/ox05b1s_modes.c line 52

Quoted 9 lines
drivers/media/i2c/ox05b1s/ox05b1s_modes.c +9 -0
+};
+
+/* Mode specific register configurations for Omnivision OS08A20 raw camera */
+
+/* OS08A20 3840 x 2160 @30fps BGGR10 no more HDR */
+struct ox05b1s_reg os08a20_init_setting_4k_10b[] = {
+	{ 0x3821, 0x04 }, /* mirror */
+	{ 0x4837, 0x10 }, /* PCLK PERIOD */
+	{ /* sentinel*/ },

No need for ending comma.
The struct could maybe be const.

drivers/media/i2c/ox05b1s/ox05b1s_modes.c line 59

Quoted 7 lines
drivers/media/i2c/ox05b1s/ox05b1s_modes.c +7 -0
+};
+
+/* OS08A20 3840 x 2160 @30fps BGGR12 */
+struct ox05b1s_reg os08a20_init_setting_4k_12b[] = {
+	{ 0x3821, 0x04 }, /* mirror */
+	{ 0x4837, 0x10 }, /* PCLK PERIOD */
+	{ /* sentinel*/ },

No need for ending comma.
The struct could maybe be const.

drivers/media/i2c/ox05b1s/ox05b1s_modes.c line 69

Quoted 10 lines
drivers/media/i2c/ox05b1s/ox05b1s_modes.c +10 -0
+};
+
+/* OS08A20 1920 x 1080 @60fps BGGR10 */
+struct ox05b1s_reg os08a20_init_setting_1080p_10b[] = {
+	{ 0x3814, 0x03 }, /* X INC ODD */
+	{ 0x3816, 0x03 }, /* Y INC ODD */
+	{ 0x3820, 0x01 }, /* vertical bining */
+	{ 0x3821, 0x05 }, /* mirror, horizontal bining */
+	{ 0x4837, 0x16 }, /* PCLK PERIOD */
+	{ /* sentinel*/ },

No need for ending comma.
The struct could maybe be const.

drivers/media/i2c/ox05b1s/ox05b1s_modes.c line 84

Quoted 3 lines
drivers/media/i2c/ox05b1s/ox05b1s_modes.c +3 -0
+};
+
+struct ox05b1s_reglist os08a20_reglist_4k_12b[] = {

The struct could maybe be const.

drivers/media/i2c/ox05b1s/ox05b1s_modes.c line 96

Quoted 12 lines
drivers/media/i2c/ox05b1s/ox05b1s_modes.c +12 -0
+	{
+		.regs = os08a20_init_setting_common
+	}, {
+		.regs = os08a20_init_setting_12bit
+	}, {
+		.regs = os08a20_init_setting_4k_12b
+	}, {
+		/* sentinel */
+	}
+};
+
+struct ox05b1s_reglist os08a20_reglist_1080p_10b[] = {

The struct could maybe be const.

Quoted 4 lines
drivers/media/i2c/ox05b1s/ox05b1s_modes.c +4 -0
+	{
+		.regs = os08a20_init_setting_common
+	}, {
+		.regs = os08a20_init_setting_10bit

drivers/media/i2c/ox05b1s/ox05b1s_modes.c line 110

Quoted 10 lines
drivers/media/i2c/ox05b1s/ox05b1s_modes.c +7 -0
+	}, {
+		.regs = os08a20_init_setting_1080p_10b
+	}, {
+		/* sentinel */
+	}
+};
+
  /*
   * Register configuration for Omnivision OX05B1S raw camera
   * 2592X1944_30FPS_FULL_RGBIr 2592 1944

CJ

#11 lore raw

Re: [PATCH v3 4/4] media: ox05b1s: Add support for Omnivision OS08A20 raw sensor

In reply to Mirela Rabulea

drivers/media/i2c/ox05b1s/ox05b1s_mipi.c static int ox05b1s_read_chip_id(struct ox05b1s *sensor) · line 919

Quoted 7 lines · Mirela Rabulea
drivers/media/i2c/ox05b1s/ox05b1s_mipi.c +3 -0
@@ -758,6 +914,9 @@ static int ox05b1s_read_chip_id(struct ox05b1s *sensor)
 	}
 
 	switch (chip_id) {
+	case 0x530841:
+		camera_name = "os08a20";
+		break;

Ah, so here I see missing second device support.

It is still confusing to see that you use here some sort of autodetection, but in the same time not.

Quoted 31 lines
drivers/media/i2c/ox05b1s/ox05b1s_mipi.c +18 -0
 	case 0x580542:
 		camera_name = "ox05b1s";
 		break;
@@ -900,6 +1059,24 @@ static void ox05b1s_remove(struct i2c_client *client)
 static DEFINE_RUNTIME_DEV_PM_OPS(ox05b1s_pm_ops, ox05b1s_runtime_suspend,
 				 ox05b1s_runtime_resume, NULL);
 
+static const struct ox05b1s_plat_data os08a20_data = {
+	.name			= "os08a20",
+	.chip_id		= 0x530841,
+	.native_width		= 3872, /* 16 dummy + 3840 active pixels + 16 dummy */
+	.native_height		= 2192, /* 16 dummy + 2160 active lines + 16 dummy */
+	.active_top		= 16,
+	.active_left		= 16,
+	.active_width		= 3840,
+	.active_height		= 2160,
+	.supported_modes	= os08a20_supported_modes,
+	.default_mode_index	= 0,
+	.supported_codes	= os08a20_supported_codes,
+	.hdr_modes		= os08a20_hdr_modes,
+	.hdr_modes_count	= ARRAY_SIZE(os08a20_hdr_modes),
+	.set_hdr_mode		= os08a20_set_hdr_mode,
+
+};
+
 static const struct ox05b1s_plat_data ox05b1s_data = {
 	.name			= "ox05b1s",
 	.chip_id		= 0x580542,
@@ -912,9 +1089,16 @@ static const struct ox05b1s_plat_data ox05b1s_data = {
 	.supported_modes	= ox05b1s_supported_modes,
 	.default_mode_index	= 0,

drivers/media/i2c/ox05b1s/ox05b1s_mipi.c static const struct ox05b1s_plat_data ox05b1s_data = { · line 1100

Quoted 10 lines
drivers/media/i2c/ox05b1s/ox05b1s_mipi.c +6 -0
 	.supported_codes	= ox05b1s_supported_codes,
+	.hdr_modes		= NULL,
+	.hdr_modes_count	= 0,
+	.set_hdr_mode		= NULL,
 };
 
 static const struct of_device_id ox05b1s_of_match[] = {
+	{
+		.compatible = "ovti,os08a20",
+		.data = &os08a20_data,

And here static configuration of model, not autodetection.

Best regards,
Krzysztof

#12 lore raw

Re: Re: [PATCH v3 4/4] media: ox05b1s: Add support for Omnivision OS08A20 raw sensor

Hi Krzysztof,

thanks again for feedback.

Quoted 4 lines · Krzysztof Kozlowski
Quoted 3 lines · Mirela Rabulea
(quoted diff) +0 -0
@@ -758,6 +914,9 @@ static int ox05b1s_read_chip_id(struct ox05b1s *sensor)
       }
 
Quoted 8 lines

drivers/media/i2c/ox05b1s/ox05b1s_mipi.c static int ox05b1s_read_chip_id(struct ox05b1s *sensor) · line 919

Quoted 4 lines
drivers/media/i2c/ox05b1s/ox05b1s_mipi.c +3 -0
       switch (chip_id) {
+     case 0x530841:
+             camera_name = "os08a20";
+             break;

Ah, so here I see missing second device support.

It is still confusing to see that you use here some sort of autodetection, but in the same time not.

The two sensors that I included in this driver have some similarities, but also differences, for which I used the platform data. I made separate patches for the two sensors, such that it is visible how much is common/different.  The chip_id reading is for validating that the sensor that is actually attached matches the device tree. It happens to me sometimes, that I switch the sensors, but forget to switch the dtb, and it helps to see which sensor is actually attached. Also, it helps a lot when the evaluation board is in some remote lab and I am unsure what sensor is attached to it.

I saw most sensor drivers have some kind of identification of the sensor module by the means of reading the chip_id register. Some examples with multiple compatibles supported and chip_id validation: imx296, ov9650, ov772x.

Please let me know what you suggest further.

For your other comments, I did prepare more structures to become const, hope I did not miss any, it will be in the next version.

Thanks,

Mirela

Quoted 49 lines
Quoted 33 lines
drivers/media/i2c/ox05b1s/ox05b1s_mipi.c +18 -0
       case 0x580542:
               camera_name = "ox05b1s";
               break;
@@ -900,6 +1059,24 @@ static void ox05b1s_remove(struct i2c_client *client)
  static DEFINE_RUNTIME_DEV_PM_OPS(ox05b1s_pm_ops, ox05b1s_runtime_suspend,
                                ox05b1s_runtime_resume, NULL);
 
+static const struct ox05b1s_plat_data os08a20_data = {
+     .name                   = "os08a20",
+     .chip_id                = 0x530841,
+     .native_width           = 3872, /* 16 dummy + 3840 active pixels + 16 dummy */
+     .native_height          = 2192, /* 16 dummy + 2160 active lines + 16 dummy */
+     .active_top             = 16,
+     .active_left            = 16,
+     .active_width           = 3840,
+     .active_height          = 2160,
+     .supported_modes        = os08a20_supported_modes,
+     .default_mode_index     = 0,
+     .supported_codes        = os08a20_supported_codes,
+     .hdr_modes              = os08a20_hdr_modes,
+     .hdr_modes_count        = ARRAY_SIZE(os08a20_hdr_modes),
+     .set_hdr_mode           = os08a20_set_hdr_mode,
+
+};
+
  static const struct ox05b1s_plat_data ox05b1s_data = {
       .name                   = "ox05b1s",
       .chip_id                = 0x580542,
@@ -912,9 +1089,16 @@ static const struct ox05b1s_plat_data ox05b1s_data = {
       .supported_modes        = ox05b1s_supported_modes,
       .default_mode_index     = 0,

drivers/media/i2c/ox05b1s/ox05b1s_mipi.c static const struct ox05b1s_plat_data ox05b1s_data = { · line 1100

Quoted 10 lines
drivers/media/i2c/ox05b1s/ox05b1s_mipi.c +6 -0
       .supported_codes        = ox05b1s_supported_codes,
+     .hdr_modes              = NULL,
+     .hdr_modes_count        = 0,
+     .set_hdr_mode           = NULL,
  };
 
  static const struct of_device_id ox05b1s_of_match[] = {
+     {
+             .compatible = "ovti,os08a20",
+             .data = &os08a20_data,

And here static configuration of model, not autodetection.

Best regards,
Krzysztof

#13 lore raw

Re: [PATCH v3 4/4] media: ox05b1s: Add support for Omnivision OS08A20 raw sensor

Quoted 28 lines · Mirela Rabulea

Hi Krzysztof,

thanks again for feedback.

Quoted 4 lines · Krzysztof Kozlowski
Quoted 3 lines · Mirela Rabulea
(quoted diff) +0 -0
@@ -758,6 +914,9 @@ static int ox05b1s_read_chip_id(struct ox05b1s *sensor)
       }
 
Quoted 8 lines

drivers/media/i2c/ox05b1s/ox05b1s_mipi.c static int ox05b1s_read_chip_id(struct ox05b1s *sensor) · line 919

Quoted 4 lines
drivers/media/i2c/ox05b1s/ox05b1s_mipi.c +3 -0
       switch (chip_id) {
+     case 0x530841:
+             camera_name = "os08a20";
+             break;

Ah, so here I see missing second device support.

It is still confusing to see that you use here some sort of autodetection, but in the same time not.

The two sensors that I included in this driver have some similarities, but also differences, for which I used the platform data. I made separate patches for the two sensors, such that it is visible how much is common/different.  The chip_id reading is for validating that the sensor that is actually attached matches the device tree. It happens to me sometimes, that I switch the sensors, but forget to switch the dtb, and it helps to see which sensor is actually attached. Also, it helps a lot when the evaluation board is in some remote lab and I am unsure what sensor is attached to it.

Quoted 6 lines

I saw most sensor drivers have some kind of identification of the sensor module by the means of reading the chip_id register. Some examples with multiple compatibles supported and chip_id validation: imx296, ov9650, ov772x.

Please let me know what you suggest further.

If devices are from the same family and support reliable autodetection, they should be made compatible. At least that's generic approach.

Best regards,
Krzysztof