Skip to contentSkip to conversation

media: i2c: mlx7502x ToF camera support

PATCH Superseded Volodymyr Kharuk 3 participants 22 messages Nov 25, 2022 – Dec 1, 2022

Subsystems (2)

v3 of 6 Superseded Latest is v6 →

lore
Share & tools
lore
#0 lore raw

v3 cover media: i2c: mlx7502x ToF camera support

Hello,

This series adds support for the Melexis 75026 and 75027 Time of Flight camera sensors, with DT bindings in patch 7/8 and a driver in patch 8/8. In patches 1/8, 2/8 and 3/8, I've add ToF controls as separate ToF control class.

v3:
- move FMOD, TINT, PHASE_SEQ to common V4L2 as ToF common controls
- FMOD and TINT became dynamic arrays
- remove PHASE_NUM, use dynamic_array for PHASE_SEQ, ctrl->new_elems pass number of phases
- remove leden-gpios, will be used gpio explicitly in library for now
- remade probe: use probe_new, no power on during probe
- remove autodetect and wildcard
- make all supplies to be required
- remove trigger ioctl, will add in separate patch series
- remove temperature ioctl, will add in separate patch series
- add documentation about custom ioctl
- style: 80 cols
- minor fixes device tree

v2:
- added external clock to the sensor
- added all regulators required by the sensor
- added posibility to choose sensor type in device tree
- added prefixes to all custom types in device tree and driver as well
- style fixes

Volodymyr Kharuk (8):
media: uapi: ctrls: Add Time of Flight class controls
media: v4l: ctrls: Fill V4L2_CID_TOF_CLASS controls
media: Documentation: v4l: Add TOF class controls
media: v4l: ctrls-api: Allow array update in __v4l2_ctrl_modify_range
media: v4l: ctrls: Add user control base for mlx7502x
media: uapi: Add mlx7502x header file
media: dt-bindings: media: i2c: Add mlx7502x camera sensor
media: i2c: Add driver for mlx7502x ToF sensor

 .../bindings/media/i2c/melexis,mlx7502x.yaml  |  126 ++
 .../userspace-api/media/drivers/index.rst     |    1 +
 .../userspace-api/media/drivers/mlx7502x.rst  |   28 +
 .../userspace-api/media/v4l/common.rst        |    1 +
 .../userspace-api/media/v4l/ext-ctrls-tof.rst |   35 +
 MAINTAINERS                                   |   11 +
 drivers/media/i2c/Kconfig                     |   13 +
 drivers/media/i2c/Makefile                    |    1 +
 drivers/media/i2c/mlx7502x.c                  | 1728 +++++++++++++++++
 drivers/media/v4l2-core/v4l2-ctrls-api.c      |   15 +-
 drivers/media/v4l2-core/v4l2-ctrls-defs.c     |   20 +
 include/uapi/linux/mlx7502x.h                 |   20 +
 include/uapi/linux/v4l2-controls.h            |   14 +
 13 files changed, 2001 insertions(+), 12 deletions(-)
 create mode 100644 Documentation/devicetree/bindings/media/i2c/melexis,mlx7502x.yaml
 create mode 100644 Documentation/userspace-api/media/drivers/mlx7502x.rst
 create mode 100644 Documentation/userspace-api/media/v4l/ext-ctrls-tof.rst
 create mode 100644 drivers/media/i2c/mlx7502x.c
 create mode 100644 include/uapi/linux/mlx7502x.h

base-commit: 1e284ea984d3705e042b6b07469a66f1d43371e3

Signature · 2 lines
BR,
Volodymyr Kharuk
#1 lore raw

PATCH v3 1/8 media: uapi: ctrls: Add Time of Flight class controls

Define Time of Flight class controls.
Also add most common TOF controls:
- phase sequence
- time integration
- frequency modulation

---
 include/uapi/linux/v4l2-controls.h | 8 ++++++++
 1 file changed, 8 insertions(+)
include/uapi/linux/v4l2-controls.h +8 -0
index d27e255ed33b..a9ecfaa4252c 100644
@@ -68,6 +68,7 @@
 #define V4L2_CTRL_CLASS_DETECT		0x00a30000	/* Detection controls */
 #define V4L2_CTRL_CLASS_CODEC_STATELESS 0x00a40000	/* Stateless codecs controls */
 #define V4L2_CTRL_CLASS_COLORIMETRY	0x00a50000	/* Colorimetry controls */
+#define V4L2_CTRL_CLASS_TOF		0x00a60000	/* Time of light camera controls */
 
 /* User-class control IDs */
 
@@ -2782,6 +2783,13 @@ struct v4l2_ctrl_vp9_compressed_hdr {
 	struct v4l2_vp9_mv_probs mv;
 };
 
+#define V4L2_CID_TOF_CLASS_BASE		(V4L2_CTRL_CLASS_TOF | 0x900)
+#define V4L2_CID_TOF_CLASS		(V4L2_CTRL_CLASS_TOF | 1)
+
+#define V4L2_CID_TOF_PHASE_SEQ		(V4L2_CID_TOF_CLASS_BASE + 0)
+#define V4L2_CID_TOF_FMOD		(V4L2_CID_TOF_CLASS_BASE + 1)
+#define V4L2_CID_TOF_TINT		(V4L2_CID_TOF_CLASS_BASE + 2)
+
 /* MPEG-compression definitions kept for backwards compatibility */
 #ifndef __KERNEL__
 #define V4L2_CTRL_CLASS_MPEG            V4L2_CTRL_CLASS_CODEC
Signature · 2 lines
BR,
Volodymyr Kharuk
#4 lore raw

PATCH v3 2/8 media: v4l: ctrls: Fill V4L2_CID_TOF_CLASS controls

In reply to Volodymyr Kharuk

Define names, flags and types of TOF controls. *dims* is driver specific. It also means, that it is not possible to use new_std for arrays.

---
 drivers/media/v4l2-core/v4l2-ctrls-defs.c | 20 ++++++++++++++++++++
 1 file changed, 20 insertions(+)
drivers/media/v4l2-core/v4l2-ctrls-defs.c +20 -0
index 564fedee2c88..1135d33c1baa 100644
@@ -1196,6 +1196,13 @@ const char *v4l2_ctrl_get_name(u32 id)
 	case V4L2_CID_COLORIMETRY_CLASS:	return "Colorimetry Controls";
 	case V4L2_CID_COLORIMETRY_HDR10_CLL_INFO:		return "HDR10 Content Light Info";
 	case V4L2_CID_COLORIMETRY_HDR10_MASTERING_DISPLAY:	return "HDR10 Mastering Display";
+
+	/* Time of light camera controls */
+	/* Keep the order of the 'case's the same as in v4l2-controls.h! */
+	case V4L2_CID_TOF_CLASS:	return "Time of light Camera Controls";
+	case V4L2_CID_TOF_PHASE_SEQ:	return "TOF phase sequence";
+	case V4L2_CID_TOF_FMOD:		return "TOF frequency modulation";
+	case V4L2_CID_TOF_TINT:		return "TOF time integration";
 	default:
 		return NULL;
 	}
@@ -1403,6 +1410,7 @@ void v4l2_ctrl_fill(u32 id, const char **name, enum v4l2_ctrl_type *type,
 	case V4L2_CID_DETECT_CLASS:
 	case V4L2_CID_CODEC_STATELESS_CLASS:
 	case V4L2_CID_COLORIMETRY_CLASS:
+	case V4L2_CID_TOF_CLASS:
 		*type = V4L2_CTRL_TYPE_CTRL_CLASS;
 		/* You can neither read nor write these */
 		*flags |= V4L2_CTRL_FLAG_READ_ONLY | V4L2_CTRL_FLAG_WRITE_ONLY;
@@ -1541,6 +1549,18 @@ void v4l2_ctrl_fill(u32 id, const char **name, enum v4l2_ctrl_type *type,
 	case V4L2_CID_COLORIMETRY_HDR10_MASTERING_DISPLAY:
 		*type = V4L2_CTRL_TYPE_HDR10_MASTERING_DISPLAY;
 		break;
+	case V4L2_CID_TOF_PHASE_SEQ:
+		*type = V4L2_CTRL_TYPE_U16;
+		*flags |= V4L2_CTRL_FLAG_DYNAMIC_ARRAY;
+		break;
+	case V4L2_CID_TOF_FMOD:
+		*type = V4L2_CTRL_TYPE_U8;
+		*flags |= V4L2_CTRL_FLAG_DYNAMIC_ARRAY;
+		break;
+	case V4L2_CID_TOF_TINT:
+		*type = V4L2_CTRL_TYPE_U16;
+		*flags |= V4L2_CTRL_FLAG_DYNAMIC_ARRAY;
+		break;
 	default:
 		*type = V4L2_CTRL_TYPE_INTEGER;
 		break;
Signature · 2 lines
BR,
Volodymyr Kharuk
#7 lore raw

PATCH v3 3/8 media: Documentation: v4l: Add TOF class controls

In reply to Volodymyr Kharuk

Add description about V4L2_CID_TOF_PHASE_SEQ, V4L2_CID_TOF_FMOD and V4L2_CID_TOF_TINT.
Also updated MAINTAINERS with new ext-ctrls-tof file.

---
 .../userspace-api/media/v4l/common.rst        |  1 +
 .../userspace-api/media/v4l/ext-ctrls-tof.rst | 35 +++++++++++++++++++
 MAINTAINERS                                   |  7 ++++
 3 files changed, 43 insertions(+)
 create mode 100644 Documentation/userspace-api/media/v4l/ext-ctrls-tof.rst
Documentation/userspace-api/media/v4l/common.rst +1 -0
index ea0435182e44..1ea79e453066 100644
@@ -52,6 +52,7 @@ applicable to all devices.
     ext-ctrls-fm-rx
     ext-ctrls-detect
     ext-ctrls-colorimetry
+    ext-ctrls-tof
     fourcc
     format
     planar-apis
Documentation/userspace-api/media/v4l/ext-ctrls-tof.rst new file +35 -0
new file mode 100644
index 000000000000..8902cc7cd47b
@@ -0,0 +1,35 @@
+.. SPDX-License-Identifier: GFDL-1.1-no-invariants-or-later
+
+.. _tof-controls:
+
+***************************************
+Time of Flight Camera Control Reference
+***************************************
+
+The Time of Flight class includes controls for digital features
+of TOF camera.
+
+.. _tof-control-id:
+
+Time of Flight Camera Control IDs
+=================================
+
+``V4L2_CID_TOF_CLASS (class)``
+    The TOF class descriptor. Calling :ref:`VIDIOC_QUERYCTRL` for
+    this control will return a description of this control class.
+
+``V4L2_CID_TOF_PHASE_SEQ (dynamic array u16)``
+    Change the shift between illumination and sampling for each phase
+    in degrees. A distance/confidence picture is obtained by merging
+    3..8 captures of the same scene using different phase shifts(some
+    TOF sensors use different frequency modulation).
+
+    The maximum array size is driver specific.
+
+``V4L2_CID_TOF_FMOD (dynamic array u8)``
+    The control sets the modulation frequency(in Mhz) per each phase.
+    The maximum array size is driver specific.
+
+``V4L2_CID_TOF_TINT (dynamic array u16)``
+    The control sets the integration time(in us) per each phase.
+    The maximum array size is driver specific.
MAINTAINERS +7 -0
index aa1974054fce..a2bc2ce53056 100644
@@ -13111,6 +13111,13 @@ S:	Supported
 W:	http://www.melexis.com
 F:	drivers/iio/temperature/mlx90632.c
 
+MELEXIS MLX7502X DRIVER
+M:	Volodymyr Kharuk <[email protected]>
+L:	[email protected]
+S:	Supported
+W:	http://www.melexis.com
+F:	Documentation/userspace-api/media/v4l/ext-ctrls-tof.rst
+
 MELFAS MIP4 TOUCHSCREEN DRIVER
 M:	Sangwon Jee <[email protected]>
 S:	Supported
Signature · 2 lines
BR,
Volodymyr Kharuk
#10 lore raw

PATCH v3 4/8 media: v4l: ctrls-api: Allow array update in __v4l2_ctrl_modify_range

In reply to Volodymyr Kharuk

For V4L2_CID_TOF_TINT, which is dynamic array, it is required to use __v4l2_ctrl_modify_range. So the idea is to use type_ops instead of u64 from union. It will allow to work with any type.

---
 drivers/media/v4l2-core/v4l2-ctrls-api.c | 15 +++------------
 1 file changed, 3 insertions(+), 12 deletions(-)
drivers/media/v4l2-core/v4l2-ctrls-api.c +3 -12
index d0a3aa3806fb..09735644a2f1 100644
@@ -942,8 +942,6 @@ int __v4l2_ctrl_modify_range(struct v4l2_ctrl *ctrl,
 	case V4L2_CTRL_TYPE_U8:
 	case V4L2_CTRL_TYPE_U16:
 	case V4L2_CTRL_TYPE_U32:
-		if (ctrl->is_array)
-			return -EINVAL;
 		ret = check_range(ctrl->type, min, max, step, def);
 		if (ret)
 			return ret;
@@ -960,17 +958,10 @@ int __v4l2_ctrl_modify_range(struct v4l2_ctrl *ctrl,
 		ctrl->default_value = def;
 	}
 	cur_to_new(ctrl);
-	if (validate_new(ctrl, ctrl->p_new)) {
-		if (ctrl->type == V4L2_CTRL_TYPE_INTEGER64)
-			*ctrl->p_new.p_s64 = def;
-		else
-			*ctrl->p_new.p_s32 = def;
-	}
+	if (validate_new(ctrl, ctrl->p_new))
+		ctrl->type_ops->init(ctrl, 0, ctrl->p_new);
 
-	if (ctrl->type == V4L2_CTRL_TYPE_INTEGER64)
-		value_changed = *ctrl->p_new.p_s64 != *ctrl->p_cur.p_s64;
-	else
-		value_changed = *ctrl->p_new.p_s32 != *ctrl->p_cur.p_s32;
+	value_changed = !ctrl->type_ops->equal(ctrl, ctrl->p_cur, ctrl->p_new);
 	if (value_changed)
 		ret = set_ctrl(NULL, ctrl, V4L2_EVENT_CTRL_CH_RANGE);
 	else if (range_changed)
Signature · 2 lines
BR,
Volodymyr Kharuk
#14 lore raw

PATCH v3 5/8 media: v4l: ctrls: Add user control base for mlx7502x

In reply to Volodymyr Kharuk

Add a control base for mlx7502x and reserve 16 controls.

---
 include/uapi/linux/v4l2-controls.h | 6 ++++++
 1 file changed, 6 insertions(+)
include/uapi/linux/v4l2-controls.h +6 -0
index a9ecfaa4252c..086069529842 100644
@@ -232,6 +232,12 @@ enum v4l2_colorfx {
  */
 #define V4L2_CID_USER_DW100_BASE		(V4L2_CID_USER_BASE + 0x1190)
 
+/*
+ * The base for Melexis ToF 7502x driver controls.
+ * We reserve 16 controls for this driver.
+ */
+#define V4L2_CID_USER_MLX7502X_BASE		(V4L2_CID_USER_BASE + 0x11a0)
+
 /* MPEG-class control IDs */
 /* The MPEG controls are applicable to all codec controls
  * and the 'MPEG' part of the define is historical */
Signature · 2 lines
BR,
Volodymyr Kharuk
#15 lore raw

PATCH v3 6/8 media: uapi: Add mlx7502x header file

In reply to Volodymyr Kharuk

Define user controls for mlx7502x driver, add its documentation and update MAINTAINERS

---
 .../userspace-api/media/drivers/index.rst     |  1 +
 .../userspace-api/media/drivers/mlx7502x.rst  | 28 +++++++++++++++++++
 MAINTAINERS                                   |  2 ++
 include/uapi/linux/mlx7502x.h                 | 20 +++++++++++++
 4 files changed, 51 insertions(+)
 create mode 100644 Documentation/userspace-api/media/drivers/mlx7502x.rst
 create mode 100644 include/uapi/linux/mlx7502x.h
Documentation/userspace-api/media/drivers/index.rst +1 -0
index 32f82aed47d9..f49e1b64c256 100644
@@ -37,5 +37,6 @@ For more details see the file COPYING in the source distribution of Linux.
 	imx-uapi
 	max2175
 	meye-uapi
+	mlx7502x
 	omap3isp-uapi
 	uvcvideo
Documentation/userspace-api/media/drivers/mlx7502x.rst new file +28 -0
new file mode 100644
index 000000000000..6f4874ec010d
@@ -0,0 +1,28 @@
+.. SPDX-License-Identifier: GPL-2.0
+
+Melexis mlx7502x ToF camera sensor driver
+=========================================
+
+The mlx7502x driver implements the following driver-specific controls:
+
+``V4L2_CID_MLX7502X_OUTPUT_MODE (menu)``
+----------------------------------------
+	The sensor has two taps, which gather reflected light: A and B.
+	The control sets the way data should be put in a buffer. The most
+	common output mode is A-B which provides the best sunlight robustness.
+
+.. flat-table::
+	:header-rows:  0
+	:stub-columns: 0
+	:widths:       1 4
+
+	* - ``(0)``
+	  - A minus B
+	* - ``(1)``
+	  - A plus B
+	* - ``(2)``
+	  - only A
+	* - ``(3)``
+	  - only B
+	* - ``(4)``
+	  - A and B (this config will change PAD format)
MAINTAINERS +2 -0
index a2bc2ce53056..0a6dda8da6bc 100644
@@ -13116,7 +13116,9 @@ M:	Volodymyr Kharuk <[email protected]>
 L:	[email protected]
 S:	Supported
 W:	http://www.melexis.com
+F:	Documentation/userspace-api/media/drivers/mlx7502x.rst
 F:	Documentation/userspace-api/media/v4l/ext-ctrls-tof.rst
+F:	include/uapi/linux/mlx7502x.h
 
 MELFAS MIP4 TOUCHSCREEN DRIVER
 M:	Sangwon Jee <[email protected]>
include/uapi/linux/mlx7502x.h new file +20 -0
new file mode 100644
index 000000000000..68014f550ed2
@@ -0,0 +1,20 @@
+/* SPDX-License-Identifier: GPL-2.0 WITH Linux-syscall-note */
+/*
+ * Melexis 7502x ToF cameras driver.
+ *
+ * Copyright (C) 2021 Melexis N.V.
+ *
+ */
+
+#ifndef __UAPI_MLX7502X_H_
+#define __UAPI_MLX7502X_H_
+
+#include <linux/v4l2-controls.h>
+
+/*
+ * this is related to the taps in ToF cameras,
+ * usually A minus B is the best option
+ */
+#define V4L2_CID_MLX7502X_OUTPUT_MODE	(V4L2_CID_USER_MLX7502X_BASE + 0)
+
+#endif /* __UAPI_MLX7502X_H_ */
Signature · 2 lines
BR,
Volodymyr Kharuk
#18 lore raw

PATCH v3 7/8 media: dt-bindings: media: i2c: Add mlx7502x camera sensor

In reply to Volodymyr Kharuk

Add device tree binding of the mlx7502x and update MAINTAINERS

---
 .../bindings/media/i2c/melexis,mlx7502x.yaml  | 126 ++++++++++++++++++
 MAINTAINERS                                   |   1 +
 2 files changed, 127 insertions(+)
 create mode 100644 Documentation/devicetree/bindings/media/i2c/melexis,mlx7502x.yaml
Documentation/devicetree/bindings/media/i2c/melexis,mlx7502x.yaml new file +126 -0
new file mode 100644
index 000000000000..7b86b6c5b151
@@ -0,0 +1,126 @@
+# SPDX-License-Identifier: (GPL-2.0 OR BSD-2-Clause)
+%YAML 1.2
+---
+$id: http://devicetree.org/schemas/media/i2c/melexis,mlx7502x.yaml#
+$schema: http://devicetree.org/meta-schemas/core.yaml#
+
+title: Melexis ToF 7502x MIPI CSI-2 Sensor
+
+maintainers:
+  - Volodymyr Kharuk <[email protected]>
+
+description: |-
+  Melexis ToF 7502x sensors has a CSI-2 output. It supports 2 and 4 lanes,
+  and mipi speeds are 300, 600, 704, 800, 904, 960Mbs. Supported format is RAW12.
+  Sensor 75026 is QVGA, while 75027 is VGA sensor.
+
+properties:
+  compatible:
+    enum:
+      - melexis,mlx75026
+      - melexis,mlx75027
+
+  reg:
+    maxItems: 1
+
+  clocks:
+    description: Clock frequency 8MHz
+    maxItems: 1
+
+  vdda-supply:
+    description:
+      Analog power supply(2.7V).
+
+  vddif-supply:
+    description:
+      Interface power supply(1.8V).
+
+  vddd-supply:
+    description:
+      Digital power supply(1.2V).
+
+  vdmix-supply:
+    description:
+      Mixed driver power supply(1.2V).
+
+  reset-gpios:
+    maxItems: 1
+    description: Reset Sensor GPIO Control (active low)
+
+  port:
+    description: MIPI CSI-2 transmitter port
+    $ref: /schemas/graph.yaml#/$defs/port-base
+
+    properties:
+      endpoint:
+        $ref: /schemas/media/video-interfaces.yaml#
+        unevaluatedProperties: false
+
+        properties:
+          data-lanes:
+            oneOf:
+              - items:
+                  - const: 1
+                  - const: 2
+              - items:
+                  - const: 1
+                  - const: 2
+                  - const: 3
+                  - const: 4
+
+        required:
+          - data-lanes
+          - link-frequencies
+
+required:
+  - compatible
+  - reg
+  - clocks
+  - port
+  - vdda-supply
+  - vddif-supply
+  - vddd-supply
+  - vdmix-supply
+
+additionalProperties: false
+
+examples:
+  - |
+    #include <dt-bindings/gpio/gpio.h>
+
+    i2c {
+        #address-cells = <1>;
+        #size-cells = <0>;
+
+        mlx7502x: camera@57 {
+            compatible = "melexis,mlx75027";
+            reg = <0x57>;
+            clocks = <&mlx7502x_clk>;
+
+            assigned-clocks = <&mlx7502x_clk>;
+            assigned-clock-parents = <&mlx7502x_clk_parent>;
+            assigned-clock-rates = <8000000>;
+
+            vdda-supply = <&reg_2v7>;
+            vddif-supply = <&reg_1v8>;
+            vddd-supply = <&reg_1v2>;
+            vdmix-supply = <&reg_1v2>;
+
+            reset-gpios = <&gpio_exp 6 GPIO_ACTIVE_HIGH>;
+
+            port {
+                mlx7502x_out_mipi_csi2: endpoint {
+                    remote-endpoint = <&mipi_csi2_from_mlx7502x>;
+                    data-lanes = <1 2 3 4>;
+                    link-frequencies = /bits/ 64 < 960000000
+                                                   904000000
+                                                   800000000
+                                                   704000000
+                                                   600000000
+                                                   300000000 >;
+                };
+            };
+        };
+    };
+
+...
MAINTAINERS +1 -0
index 0a6dda8da6bc..de7bece020f8 100644
@@ -13116,6 +13116,7 @@ M:	Volodymyr Kharuk <[email protected]>
 L:	[email protected]
 S:	Supported
 W:	http://www.melexis.com
+F:	Documentation/devicetree/bindings/media/i2c/melexis,mlx7502x.yaml
 F:	Documentation/userspace-api/media/drivers/mlx7502x.rst
 F:	Documentation/userspace-api/media/v4l/ext-ctrls-tof.rst
 F:	include/uapi/linux/mlx7502x.h
Signature · 2 lines
BR,
Volodymyr Kharuk
#21 lore raw

PATCH v3 8/8 media: i2c: Add driver for mlx7502x ToF sensor

In reply to Volodymyr Kharuk

Melexis ToF 7502x sensors has a CSI-2 output. It supports 2 and 4 lanes, and mipi speeds are 300, 600, 704, 800, 904, 960Mbs. Supported format is RAW12.
Sensor 75026 is QVGA, while 75027 is VGA sensor.

The driver supports:
- Digital binning and cropping
- Horizontal and vertical flip
- phase shifts(up to 8)
- frequency modulation
- time integration

---
 MAINTAINERS                  |    1 +
 drivers/media/i2c/Kconfig    |   13 +
 drivers/media/i2c/Makefile   |    1 +
 drivers/media/i2c/mlx7502x.c | 1728 ++++++++++++++++++++++++++++++++++
 4 files changed, 1743 insertions(+)
 create mode 100644 drivers/media/i2c/mlx7502x.c
MAINTAINERS +1 -0
index de7bece020f8..82d4c684de6d 100644
@@ -13119,6 +13119,7 @@ W:	http://www.melexis.com
 F:	Documentation/devicetree/bindings/media/i2c/melexis,mlx7502x.yaml
 F:	Documentation/userspace-api/media/drivers/mlx7502x.rst
 F:	Documentation/userspace-api/media/v4l/ext-ctrls-tof.rst
+F:	drivers/media/i2c/mlx7502x.c
 F:	include/uapi/linux/mlx7502x.h
 
 MELFAS MIP4 TOUCHSCREEN DRIVER
drivers/media/i2c/Kconfig +13 -0
index 49c1c27afdc1..ea9d9ecdae77 100644
@@ -231,6 +231,19 @@ config VIDEO_IMX412
 config VIDEO_MAX9271_LIB
 	tristate
 
+config VIDEO_MLX7502X
+	tristate "Melexis ToF 75026 and 75027 sensors support"
+	depends on I2C && VIDEO_DEV
+	select MEDIA_CONTROLLER
+	select VIDEO_V4L2_SUBDEV_API
+	select V4L2_FWNODE
+	help
+	  This is a V4L2 sensor driver for the Melexis 75026 and 75027
+	  ToF sensors.
+
+	  To compile this driver as a module, choose M here: the
+	  module will be called mlx7502x.
+
 config VIDEO_MT9M001
 	tristate "mt9m001 support"
 	depends on I2C && VIDEO_DEV
drivers/media/i2c/Makefile +1 -0
index ba28a8f8a07f..7593ece403e1 100644
@@ -58,6 +58,7 @@ obj-$(CONFIG_VIDEO_M5MOLS) += m5mols/
 obj-$(CONFIG_VIDEO_MAX9271_LIB) += max9271.o
 obj-$(CONFIG_VIDEO_MAX9286) += max9286.o
 obj-$(CONFIG_VIDEO_ML86V7667) += ml86v7667.o
+obj-$(CONFIG_VIDEO_MLX7502X) += mlx7502x.o
 obj-$(CONFIG_VIDEO_MSP3400) += msp3400.o
 obj-$(CONFIG_VIDEO_MT9M001) += mt9m001.o
 obj-$(CONFIG_VIDEO_MT9M032) += mt9m032.o
drivers/media/i2c/mlx7502x.c new file +1728 -0

1,728 lines not on this page · raw message

Signature · 2 lines
BR,
Volodymyr Kharuk
#2 lore raw

Re: [PATCH v3 1/8] media: uapi: ctrls: Add Time of Flight class controls

In reply to Volodymyr Kharuk
Quoted 16 lines · Volodymyr Kharuk

Define Time of Flight class controls.
Also add most common TOF controls:
- phase sequence
- time integration
- frequency modulation

---
 include/uapi/linux/v4l2-controls.h | 8 ++++++++
 1 file changed, 8 insertions(+)
include/uapi/linux/v4l2-controls.h +0 -0
index d27e255ed33b..a9ecfaa4252c 100644

include/uapi/linux/v4l2-controls.h line 71

Quoted 4 lines
include/uapi/linux/v4l2-controls.h +1 -0
@@ -68,6 +68,7 @@
 #define V4L2_CTRL_CLASS_DETECT		0x00a30000	/* Detection controls */
 #define V4L2_CTRL_CLASS_CODEC_STATELESS 0x00a40000	/* Stateless codecs controls */
 #define V4L2_CTRL_CLASS_COLORIMETRY	0x00a50000	/* Colorimetry controls */
+#define V4L2_CTRL_CLASS_TOF		0x00a60000	/* Time of light camera controls */

light -> flight

include/uapi/linux/v4l2-controls.h struct v4l2_ctrl_vp9_compressed_hdr { · line 2790

Quoted 12 lines
include/uapi/linux/v4l2-controls.h +5 -0
 /* User-class control IDs */
 
@@ -2782,6 +2783,13 @@ struct v4l2_ctrl_vp9_compressed_hdr {
 	struct v4l2_vp9_mv_probs mv;
 };
 
+#define V4L2_CID_TOF_CLASS_BASE		(V4L2_CTRL_CLASS_TOF | 0x900)
+#define V4L2_CID_TOF_CLASS		(V4L2_CTRL_CLASS_TOF | 1)
+
+#define V4L2_CID_TOF_PHASE_SEQ		(V4L2_CID_TOF_CLASS_BASE + 0)
+#define V4L2_CID_TOF_FMOD		(V4L2_CID_TOF_CLASS_BASE + 1)

I'd go for _FREQ_MOD

include/uapi/linux/v4l2-controls.h struct v4l2_ctrl_vp9_compressed_hdr { · line 2791

Quoted 1 line
include/uapi/linux/v4l2-controls.h +1 -0
+#define V4L2_CID_TOF_TINT		(V4L2_CID_TOF_CLASS_BASE + 2)

and _TIME_INTEGRATION

Regards,

Hans

Quoted 4 lines
include/uapi/linux/v4l2-controls.h +1 -0
+
 /* MPEG-compression definitions kept for backwards compatibility */
 #ifndef __KERNEL__
 #define V4L2_CTRL_CLASS_MPEG            V4L2_CTRL_CLASS_CODEC
#5 lore raw

Re: [PATCH v3 2/8] media: v4l: ctrls: Fill V4L2_CID_TOF_CLASS controls

In reply to Volodymyr Kharuk
Quoted 13 lines · Volodymyr Kharuk

Define names, flags and types of TOF controls. *dims* is driver specific. It also means, that it is not possible to use new_std for arrays.

---
 drivers/media/v4l2-core/v4l2-ctrls-defs.c | 20 ++++++++++++++++++++
 1 file changed, 20 insertions(+)
drivers/media/v4l2-core/v4l2-ctrls-defs.c +0 -0
index 564fedee2c88..1135d33c1baa 100644

drivers/media/v4l2-core/v4l2-ctrls-defs.c const char *v4l2_ctrl_get_name(u32 id) · line 1202

Quoted 7 lines
drivers/media/v4l2-core/v4l2-ctrls-defs.c +4 -0
@@ -1196,6 +1196,13 @@ const char *v4l2_ctrl_get_name(u32 id)
 	case V4L2_CID_COLORIMETRY_CLASS:	return "Colorimetry Controls";
 	case V4L2_CID_COLORIMETRY_HDR10_CLL_INFO:		return "HDR10 Content Light Info";
 	case V4L2_CID_COLORIMETRY_HDR10_MASTERING_DISPLAY:	return "HDR10 Mastering Display";
+
+	/* Time of light camera controls */
+	/* Keep the order of the 'case's the same as in v4l2-controls.h! */
+	case V4L2_CID_TOF_CLASS:	return "Time of light Camera Controls";

light -> Flight

drivers/media/v4l2-core/v4l2-ctrls-defs.c const char *v4l2_ctrl_get_name(u32 id) · line 1203

Quoted 1 line
drivers/media/v4l2-core/v4l2-ctrls-defs.c +1 -0
+	case V4L2_CID_TOF_PHASE_SEQ:	return "TOF phase sequence";

Capitalize, so: "TOF Phase Sequence"

drivers/media/v4l2-core/v4l2-ctrls-defs.c const char *v4l2_ctrl_get_name(u32 id) · line 1204

Quoted 1 line
drivers/media/v4l2-core/v4l2-ctrls-defs.c +1 -0
+	case V4L2_CID_TOF_FMOD:		return "TOF frequency modulation";

"TOF Frequency Modulation"

drivers/media/v4l2-core/v4l2-ctrls-defs.c const char *v4l2_ctrl_get_name(u32 id) · line 1205

Quoted 1 line
drivers/media/v4l2-core/v4l2-ctrls-defs.c +1 -0
+	case V4L2_CID_TOF_TINT:		return "TOF time integration";

"TOF Time Integration"

Quoted 20 lines
drivers/media/v4l2-core/v4l2-ctrls-defs.c +6 -0
 	default:
 		return NULL;
 	}
@@ -1403,6 +1410,7 @@ void v4l2_ctrl_fill(u32 id, const char **name, enum v4l2_ctrl_type *type,
 	case V4L2_CID_DETECT_CLASS:
 	case V4L2_CID_CODEC_STATELESS_CLASS:
 	case V4L2_CID_COLORIMETRY_CLASS:
+	case V4L2_CID_TOF_CLASS:
 		*type = V4L2_CTRL_TYPE_CTRL_CLASS;
 		/* You can neither read nor write these */
 		*flags |= V4L2_CTRL_FLAG_READ_ONLY | V4L2_CTRL_FLAG_WRITE_ONLY;
@@ -1541,6 +1549,18 @@ void v4l2_ctrl_fill(u32 id, const char **name, enum v4l2_ctrl_type *type,
 	case V4L2_CID_COLORIMETRY_HDR10_MASTERING_DISPLAY:
 		*type = V4L2_CTRL_TYPE_HDR10_MASTERING_DISPLAY;
 		break;
+	case V4L2_CID_TOF_PHASE_SEQ:
+		*type = V4L2_CTRL_TYPE_U16;
+		*flags |= V4L2_CTRL_FLAG_DYNAMIC_ARRAY;
+		break;
+	case V4L2_CID_TOF_FMOD:

drivers/media/v4l2-core/v4l2-ctrls-defs.c void v4l2_ctrl_fill(u32 id, const char **name, enum v4l2_ctrl_type *type, · line 1566

Quoted 10 lines
drivers/media/v4l2-core/v4l2-ctrls-defs.c +7 -0
+		*type = V4L2_CTRL_TYPE_U8;
+		*flags |= V4L2_CTRL_FLAG_DYNAMIC_ARRAY;
+		break;
+	case V4L2_CID_TOF_TINT:
+		*type = V4L2_CTRL_TYPE_U16;
+		*flags |= V4L2_CTRL_FLAG_DYNAMIC_ARRAY;
+		break;
 	default:
 		*type = V4L2_CTRL_TYPE_INTEGER;
 		break;

Regards,

Hans

#8 lore raw

Re: [PATCH v3 3/8] media: Documentation: v4l: Add TOF class controls

In reply to Volodymyr Kharuk
Quoted 30 lines · Volodymyr Kharuk

Add description about V4L2_CID_TOF_PHASE_SEQ, V4L2_CID_TOF_FMOD and V4L2_CID_TOF_TINT.
Also updated MAINTAINERS with new ext-ctrls-tof file.

---
 .../userspace-api/media/v4l/common.rst        |  1 +
 .../userspace-api/media/v4l/ext-ctrls-tof.rst | 35 +++++++++++++++++++
 MAINTAINERS                                   |  7 ++++
 3 files changed, 43 insertions(+)
 create mode 100644 Documentation/userspace-api/media/v4l/ext-ctrls-tof.rst
Documentation/userspace-api/media/v4l/common.rst +1 -0
index ea0435182e44..1ea79e453066 100644
@@ -52,6 +52,7 @@ applicable to all devices.
     ext-ctrls-fm-rx
     ext-ctrls-detect
     ext-ctrls-colorimetry
+    ext-ctrls-tof
     fourcc
     format
     planar-apis
Documentation/userspace-api/media/v4l/ext-ctrls-tof.rst new file +0 -0
new file mode 100644
index 000000000000..8902cc7cd47b

Documentation/userspace-api/media/v4l/ext-ctrls-tof.rst line 10

Quoted 10 lines
Documentation/userspace-api/media/v4l/ext-ctrls-tof.rst new file +10 -0
@@ -0,0 +1,35 @@
+.. SPDX-License-Identifier: GFDL-1.1-no-invariants-or-later
+
+.. _tof-controls:
+
+***************************************
+Time of Flight Camera Control Reference
+***************************************
+
+The Time of Flight class includes controls for digital features
+of TOF camera.

You might want to extend this description a bit and give more info about how they work. Perhaps a link to wikipedia or something might help too.

Quoted 4 lines
Documentation/userspace-api/media/v4l/ext-ctrls-tof.rst new file +4 -0
+
+.. _tof-control-id:
+
+Time of Flight Camera Control IDs

Documentation/userspace-api/media/v4l/ext-ctrls-tof.rst line 24

Quoted 10 lines
Documentation/userspace-api/media/v4l/ext-ctrls-tof.rst new file +10 -0
+=================================
+
+``V4L2_CID_TOF_CLASS (class)``
+    The TOF class descriptor. Calling :ref:`VIDIOC_QUERYCTRL` for
+    this control will return a description of this control class.
+
+``V4L2_CID_TOF_PHASE_SEQ (dynamic array u16)``
+    Change the shift between illumination and sampling for each phase
+    in degrees. A distance/confidence picture is obtained by merging
+    3..8 captures of the same scene using different phase shifts(some

Space before (

Documentation/userspace-api/media/v4l/ext-ctrls-tof.rst line 25

Quoted 1 line
Documentation/userspace-api/media/v4l/ext-ctrls-tof.rst new file +1 -0
+    TOF sensors use different frequency modulation).
Either: use -> use a
Or:     modulation -> modulations

It's not clear right now whether "frequency modulation" is meant to be singular or plural.

Documentation/userspace-api/media/v4l/ext-ctrls-tof.rst line 30

Quoted 5 lines
Documentation/userspace-api/media/v4l/ext-ctrls-tof.rst new file +5 -0
+
+    The maximum array size is driver specific.
+
+``V4L2_CID_TOF_FMOD (dynamic array u8)``
+    The control sets the modulation frequency(in Mhz) per each phase.

Space before (

per each phase -> for each phase

Documentation/userspace-api/media/v4l/ext-ctrls-tof.rst line 31

Quoted 1 line
Documentation/userspace-api/media/v4l/ext-ctrls-tof.rst new file +1 -0
+    The maximum array size is driver specific.

What does the maximum array size signify? The number of phases? It's not clear from the spec (and I have to admit I know very little about TOF sensors).

Documentation/userspace-api/media/v4l/ext-ctrls-tof.rst line 34

Quoted 3 lines
Documentation/userspace-api/media/v4l/ext-ctrls-tof.rst new file +3 -0
+
+``V4L2_CID_TOF_TINT (dynamic array u16)``
+    The control sets the integration time(in us) per each phase.

Add space before (

per each phase -> for each phase

Quoted 9 lines
Documentation/userspace-api/media/v4l/ext-ctrls-tof.rst new file +1 -0
+    The maximum array size is driver specific.
MAINTAINERS +0 -0
index aa1974054fce..a2bc2ce53056 100644
@@ -13111,6 +13111,13 @@ S:	Supported
 W:	http://www.melexis.com
 F:	drivers/iio/temperature/mlx90632.c
 

MAINTAINERS S: Supported · line 13123

Quoted 10 lines
MAINTAINERS +7 -0
+MELEXIS MLX7502X DRIVER
+M:	Volodymyr Kharuk <[email protected]>
+L:	[email protected]
+S:	Supported
+W:	http://www.melexis.com
+F:	Documentation/userspace-api/media/v4l/ext-ctrls-tof.rst
+
 MELFAS MIP4 TOUCHSCREEN DRIVER
 M:	Sangwon Jee <[email protected]>
 S:	Supported

Regards,

Hans

#11 lore raw

Re: [PATCH v3 4/8] media: v4l: ctrls-api: Allow array update in __v4l2_ctrl_modify_range

In reply to Volodymyr Kharuk
Quoted 24 lines · Volodymyr Kharuk

For V4L2_CID_TOF_TINT, which is dynamic array, it is required to use __v4l2_ctrl_modify_range. So the idea is to use type_ops instead of u64 from union. It will allow to work with any type.

---
 drivers/media/v4l2-core/v4l2-ctrls-api.c | 15 +++------------
 1 file changed, 3 insertions(+), 12 deletions(-)
drivers/media/v4l2-core/v4l2-ctrls-api.c +0 -2
index d0a3aa3806fb..09735644a2f1 100644
@@ -942,8 +942,6 @@ int __v4l2_ctrl_modify_range(struct v4l2_ctrl *ctrl,
 	case V4L2_CTRL_TYPE_U8:
 	case V4L2_CTRL_TYPE_U16:
 	case V4L2_CTRL_TYPE_U32:
-		if (ctrl->is_array)
-			return -EINVAL;
 		ret = check_range(ctrl->type, min, max, step, def);
 		if (ret)
 			return ret;
@@ -960,17 +958,10 @@ int __v4l2_ctrl_modify_range(struct v4l2_ctrl *ctrl,
 		ctrl->default_value = def;

drivers/media/v4l2-core/v4l2-ctrls-api.c int __v4l2_ctrl_modify_range(struct v4l2_ctrl *ctrl, · line 962

Quoted 10 lines
drivers/media/v4l2-core/v4l2-ctrls-api.c +2 -6
 	}
 	cur_to_new(ctrl);
-	if (validate_new(ctrl, ctrl->p_new)) {
-		if (ctrl->type == V4L2_CTRL_TYPE_INTEGER64)
-			*ctrl->p_new.p_s64 = def;
-		else
-			*ctrl->p_new.p_s32 = def;
-	}
+	if (validate_new(ctrl, ctrl->p_new))
+		ctrl->type_ops->init(ctrl, 0, ctrl->p_new);

Hmm, this sets *all* elements of the array to the default_value, not just the elements whose value is out of range.

Is that what you want? Should this perhaps depend on the type of control? I.e. in some cases it might make sense to do this, in other cases it makes more sense to only adjust the elements that are out of range.

How does that work for this TINT control?

Regards,

Hans

Quoted 9 lines
drivers/media/v4l2-core/v4l2-ctrls-api.c +1 -4
-	if (ctrl->type == V4L2_CTRL_TYPE_INTEGER64)
-		value_changed = *ctrl->p_new.p_s64 != *ctrl->p_cur.p_s64;
-	else
-		value_changed = *ctrl->p_new.p_s32 != *ctrl->p_cur.p_s32;
+	value_changed = !ctrl->type_ops->equal(ctrl, ctrl->p_cur, ctrl->p_new);
 	if (value_changed)
 		ret = set_ctrl(NULL, ctrl, V4L2_EVENT_CTRL_CH_RANGE);
 	else if (range_changed)
#16 lore raw

Re: [PATCH v3 6/8] media: uapi: Add mlx7502x header file

In reply to Volodymyr Kharuk
Quoted 86 lines · Volodymyr Kharuk

Define user controls for mlx7502x driver, add its documentation and update MAINTAINERS

---
 .../userspace-api/media/drivers/index.rst     |  1 +
 .../userspace-api/media/drivers/mlx7502x.rst  | 28 +++++++++++++++++++
 MAINTAINERS                                   |  2 ++
 include/uapi/linux/mlx7502x.h                 | 20 +++++++++++++
 4 files changed, 51 insertions(+)
 create mode 100644 Documentation/userspace-api/media/drivers/mlx7502x.rst
 create mode 100644 include/uapi/linux/mlx7502x.h
Documentation/userspace-api/media/drivers/index.rst +1 -0
index 32f82aed47d9..f49e1b64c256 100644
@@ -37,5 +37,6 @@ For more details see the file COPYING in the source distribution of Linux.
 	imx-uapi
 	max2175
 	meye-uapi
+	mlx7502x
 	omap3isp-uapi
 	uvcvideo
Documentation/userspace-api/media/drivers/mlx7502x.rst new file +28 -0
new file mode 100644
index 000000000000..6f4874ec010d
@@ -0,0 +1,28 @@
+.. SPDX-License-Identifier: GPL-2.0
+
+Melexis mlx7502x ToF camera sensor driver
+=========================================
+
+The mlx7502x driver implements the following driver-specific controls:
+
+``V4L2_CID_MLX7502X_OUTPUT_MODE (menu)``
+----------------------------------------
+	The sensor has two taps, which gather reflected light: A and B.
+	The control sets the way data should be put in a buffer. The most
+	common output mode is A-B which provides the best sunlight robustness.
+
+.. flat-table::
+	:header-rows:  0
+	:stub-columns: 0
+	:widths:       1 4
+
+	* - ``(0)``
+	  - A minus B
+	* - ``(1)``
+	  - A plus B
+	* - ``(2)``
+	  - only A
+	* - ``(3)``
+	  - only B
+	* - ``(4)``
+	  - A and B (this config will change PAD format)
MAINTAINERS +2 -0
index a2bc2ce53056..0a6dda8da6bc 100644
@@ -13116,7 +13116,9 @@ M:	Volodymyr Kharuk <[email protected]>
 L:	[email protected]
 S:	Supported
 W:	http://www.melexis.com
+F:	Documentation/userspace-api/media/drivers/mlx7502x.rst
 F:	Documentation/userspace-api/media/v4l/ext-ctrls-tof.rst
+F:	include/uapi/linux/mlx7502x.h
 
 MELFAS MIP4 TOUCHSCREEN DRIVER
 M:	Sangwon Jee <[email protected]>
include/uapi/linux/mlx7502x.h new file +8 -0
new file mode 100644
index 000000000000..68014f550ed2
@@ -0,0 +1,20 @@
+/* SPDX-License-Identifier: GPL-2.0 WITH Linux-syscall-note */
+/*
+ * Melexis 7502x ToF cameras driver.
+ *
+ * Copyright (C) 2021 Melexis N.V.
+ *
+ */
+

include/uapi/linux/mlx7502x.h line 18

Quoted 10 lines
include/uapi/linux/mlx7502x.h new file +10 -0
+#ifndef __UAPI_MLX7502X_H_
+#define __UAPI_MLX7502X_H_
+
+#include <linux/v4l2-controls.h>
+
+/*
+ * this is related to the taps in ToF cameras,
+ * usually A minus B is the best option
+ */
+#define V4L2_CID_MLX7502X_OUTPUT_MODE	(V4L2_CID_USER_MLX7502X_BASE + 0)

You need to add an enum with the mode settings. E.g.:

enum v4l2_mlx7502x_output_mode {
        V4L2_MLX7502X_OUTPUT_MODE_A_MINUS_B     = 0,
	...
};

And you can use those enum defines in the documentation.

Regards,

Hans

Quoted 2 lines
include/uapi/linux/mlx7502x.h new file +2 -0
+
+#endif /* __UAPI_MLX7502X_H_ */
#3 lore raw

Re: [PATCH v3 1/8] media: uapi: ctrls: Add Time of Flight class controls

In reply to Hans Verkuil

Hi Hans,

Thanks for your review,

Quoted 12 lines · Hans Verkuil
Quoted 11 lines · Volodymyr Kharuk

Define Time of Flight class controls.
Also add most common TOF controls:
- phase sequence
- time integration
- frequency modulation

---
 include/uapi/linux/v4l2-controls.h | 8 ++++++++
 1 file changed, 8 insertions(+)
Quoted 11 lines

include/uapi/linux/v4l2-controls.h line 71

Quoted 9 lines
include/uapi/linux/v4l2-controls.h +1 -0
index d27e255ed33b..a9ecfaa4252c 100644
@@ -68,6 +68,7 @@
 #define V4L2_CTRL_CLASS_DETECT		0x00a30000	/* Detection controls */
 #define V4L2_CTRL_CLASS_CODEC_STATELESS 0x00a40000	/* Stateless codecs controls */
 #define V4L2_CTRL_CLASS_COLORIMETRY	0x00a50000	/* Colorimetry controls */
+#define V4L2_CTRL_CLASS_TOF		0x00a60000	/* Time of light camera controls */

light -> flight

oh, indeed. Will fix.

Quoted 8 lines
Quoted 8 lines
include/uapi/linux/v4l2-controls.h +0 -0
 /* User-class control IDs */
 
@@ -2782,6 +2783,13 @@ struct v4l2_ctrl_vp9_compressed_hdr {
 	struct v4l2_vp9_mv_probs mv;
 };
 
Quoted 7 lines

include/uapi/linux/v4l2-controls.h struct v4l2_ctrl_vp9_compressed_hdr { · line 2790

Quoted 5 lines
include/uapi/linux/v4l2-controls.h +5 -0
+#define V4L2_CID_TOF_CLASS_BASE		(V4L2_CTRL_CLASS_TOF | 0x900)
+#define V4L2_CID_TOF_CLASS		(V4L2_CTRL_CLASS_TOF | 1)
+
+#define V4L2_CID_TOF_PHASE_SEQ		(V4L2_CID_TOF_CLASS_BASE + 0)
+#define V4L2_CID_TOF_FMOD		(V4L2_CID_TOF_CLASS_BASE + 1)

I'd go for _FREQ_MOD

Ok. Will fix.

Quoted 4 lines

include/uapi/linux/v4l2-controls.h struct v4l2_ctrl_vp9_compressed_hdr { · line 2791

Quoted 2 lines
include/uapi/linux/v4l2-controls.h +1 -0
+#define V4L2_CID_TOF_TINT		(V4L2_CID_TOF_CLASS_BASE + 2)

and _TIME_INTEGRATION

Ok. Will fix.

Quoted 10 lines

Regards,

Hans

Quoted 4 lines
include/uapi/linux/v4l2-controls.h +1 -0
+
 /* MPEG-compression definitions kept for backwards compatibility */
 #ifndef __KERNEL__
 #define V4L2_CTRL_CLASS_MPEG            V4L2_CTRL_CLASS_CODEC
Signature · 3 lines
--
BR,
Volodymyr Kharuk
#6 lore raw

Re: [PATCH v3 2/8] media: v4l: ctrls: Fill V4L2_CID_TOF_CLASS controls

In reply to Hans Verkuil

Thanks for your review.
I'll fix your remarks in next version.

Quoted 70 lines · Hans Verkuil
Quoted 13 lines · Volodymyr Kharuk

Define names, flags and types of TOF controls. *dims* is driver specific. It also means, that it is not possible to use new_std for arrays.

---
 drivers/media/v4l2-core/v4l2-ctrls-defs.c | 20 ++++++++++++++++++++
 1 file changed, 20 insertions(+)
drivers/media/v4l2-core/v4l2-ctrls-defs.c +0 -0
index 564fedee2c88..1135d33c1baa 100644

drivers/media/v4l2-core/v4l2-ctrls-defs.c const char *v4l2_ctrl_get_name(u32 id) · line 1202

Quoted 7 lines
drivers/media/v4l2-core/v4l2-ctrls-defs.c +4 -0
@@ -1196,6 +1196,13 @@ const char *v4l2_ctrl_get_name(u32 id)
 	case V4L2_CID_COLORIMETRY_CLASS:	return "Colorimetry Controls";
 	case V4L2_CID_COLORIMETRY_HDR10_CLL_INFO:		return "HDR10 Content Light Info";
 	case V4L2_CID_COLORIMETRY_HDR10_MASTERING_DISPLAY:	return "HDR10 Mastering Display";
+
+	/* Time of light camera controls */
+	/* Keep the order of the 'case's the same as in v4l2-controls.h! */
+	case V4L2_CID_TOF_CLASS:	return "Time of light Camera Controls";

light -> Flight

drivers/media/v4l2-core/v4l2-ctrls-defs.c const char *v4l2_ctrl_get_name(u32 id) · line 1203

Quoted 1 line
drivers/media/v4l2-core/v4l2-ctrls-defs.c +1 -0
+	case V4L2_CID_TOF_PHASE_SEQ:	return "TOF phase sequence";

Capitalize, so: "TOF Phase Sequence"

drivers/media/v4l2-core/v4l2-ctrls-defs.c const char *v4l2_ctrl_get_name(u32 id) · line 1204

Quoted 1 line
drivers/media/v4l2-core/v4l2-ctrls-defs.c +1 -0
+	case V4L2_CID_TOF_FMOD:		return "TOF frequency modulation";

"TOF Frequency Modulation"

drivers/media/v4l2-core/v4l2-ctrls-defs.c const char *v4l2_ctrl_get_name(u32 id) · line 1205

Quoted 1 line
drivers/media/v4l2-core/v4l2-ctrls-defs.c +1 -0
+	case V4L2_CID_TOF_TINT:		return "TOF time integration";

"TOF Time Integration"

Quoted 20 lines
drivers/media/v4l2-core/v4l2-ctrls-defs.c +6 -0
 	default:
 		return NULL;
 	}
@@ -1403,6 +1410,7 @@ void v4l2_ctrl_fill(u32 id, const char **name, enum v4l2_ctrl_type *type,
 	case V4L2_CID_DETECT_CLASS:
 	case V4L2_CID_CODEC_STATELESS_CLASS:
 	case V4L2_CID_COLORIMETRY_CLASS:
+	case V4L2_CID_TOF_CLASS:
 		*type = V4L2_CTRL_TYPE_CTRL_CLASS;
 		/* You can neither read nor write these */
 		*flags |= V4L2_CTRL_FLAG_READ_ONLY | V4L2_CTRL_FLAG_WRITE_ONLY;
@@ -1541,6 +1549,18 @@ void v4l2_ctrl_fill(u32 id, const char **name, enum v4l2_ctrl_type *type,
 	case V4L2_CID_COLORIMETRY_HDR10_MASTERING_DISPLAY:
 		*type = V4L2_CTRL_TYPE_HDR10_MASTERING_DISPLAY;
 		break;
+	case V4L2_CID_TOF_PHASE_SEQ:
+		*type = V4L2_CTRL_TYPE_U16;
+		*flags |= V4L2_CTRL_FLAG_DYNAMIC_ARRAY;
+		break;
+	case V4L2_CID_TOF_FMOD:

drivers/media/v4l2-core/v4l2-ctrls-defs.c void v4l2_ctrl_fill(u32 id, const char **name, enum v4l2_ctrl_type *type, · line 1566

Quoted 10 lines
drivers/media/v4l2-core/v4l2-ctrls-defs.c +7 -0
+		*type = V4L2_CTRL_TYPE_U8;
+		*flags |= V4L2_CTRL_FLAG_DYNAMIC_ARRAY;
+		break;
+	case V4L2_CID_TOF_TINT:
+		*type = V4L2_CTRL_TYPE_U16;
+		*flags |= V4L2_CTRL_FLAG_DYNAMIC_ARRAY;
+		break;
 	default:
 		*type = V4L2_CTRL_TYPE_INTEGER;
 		break;

Regards,

Hans

Signature · 3 lines
--
BR,
Volodymyr Kharuk
#17 lore raw

Re: [PATCH v3 6/8] media: uapi: Add mlx7502x header file

In reply to Hans Verkuil
Quoted 100 lines · Hans Verkuil
Quoted 86 lines · Volodymyr Kharuk

Define user controls for mlx7502x driver, add its documentation and update MAINTAINERS

---
 .../userspace-api/media/drivers/index.rst     |  1 +
 .../userspace-api/media/drivers/mlx7502x.rst  | 28 +++++++++++++++++++
 MAINTAINERS                                   |  2 ++
 include/uapi/linux/mlx7502x.h                 | 20 +++++++++++++
 4 files changed, 51 insertions(+)
 create mode 100644 Documentation/userspace-api/media/drivers/mlx7502x.rst
 create mode 100644 include/uapi/linux/mlx7502x.h
Documentation/userspace-api/media/drivers/index.rst +1 -0
index 32f82aed47d9..f49e1b64c256 100644
@@ -37,5 +37,6 @@ For more details see the file COPYING in the source distribution of Linux.
 	imx-uapi
 	max2175
 	meye-uapi
+	mlx7502x
 	omap3isp-uapi
 	uvcvideo
Documentation/userspace-api/media/drivers/mlx7502x.rst new file +28 -0
new file mode 100644
index 000000000000..6f4874ec010d
@@ -0,0 +1,28 @@
+.. SPDX-License-Identifier: GPL-2.0
+
+Melexis mlx7502x ToF camera sensor driver
+=========================================
+
+The mlx7502x driver implements the following driver-specific controls:
+
+``V4L2_CID_MLX7502X_OUTPUT_MODE (menu)``
+----------------------------------------
+	The sensor has two taps, which gather reflected light: A and B.
+	The control sets the way data should be put in a buffer. The most
+	common output mode is A-B which provides the best sunlight robustness.
+
+.. flat-table::
+	:header-rows:  0
+	:stub-columns: 0
+	:widths:       1 4
+
+	* - ``(0)``
+	  - A minus B
+	* - ``(1)``
+	  - A plus B
+	* - ``(2)``
+	  - only A
+	* - ``(3)``
+	  - only B
+	* - ``(4)``
+	  - A and B (this config will change PAD format)
MAINTAINERS +2 -0
index a2bc2ce53056..0a6dda8da6bc 100644
@@ -13116,7 +13116,9 @@ M:	Volodymyr Kharuk <[email protected]>
 L:	[email protected]
 S:	Supported
 W:	http://www.melexis.com
+F:	Documentation/userspace-api/media/drivers/mlx7502x.rst
 F:	Documentation/userspace-api/media/v4l/ext-ctrls-tof.rst
+F:	include/uapi/linux/mlx7502x.h
 
 MELFAS MIP4 TOUCHSCREEN DRIVER
 M:	Sangwon Jee <[email protected]>
include/uapi/linux/mlx7502x.h new file +8 -0
new file mode 100644
index 000000000000..68014f550ed2
@@ -0,0 +1,20 @@
+/* SPDX-License-Identifier: GPL-2.0 WITH Linux-syscall-note */
+/*
+ * Melexis 7502x ToF cameras driver.
+ *
+ * Copyright (C) 2021 Melexis N.V.
+ *
+ */
+

include/uapi/linux/mlx7502x.h line 18

Quoted 10 lines
include/uapi/linux/mlx7502x.h new file +10 -0
+#ifndef __UAPI_MLX7502X_H_
+#define __UAPI_MLX7502X_H_
+
+#include <linux/v4l2-controls.h>
+
+/*
+ * this is related to the taps in ToF cameras,
+ * usually A minus B is the best option
+ */
+#define V4L2_CID_MLX7502X_OUTPUT_MODE	(V4L2_CID_USER_MLX7502X_BASE + 0)

You need to add an enum with the mode settings. E.g.:

Quoted 6 lines
enum v4l2_mlx7502x_output_mode {
        V4L2_MLX7502X_OUTPUT_MODE_A_MINUS_B     = 0,
	...
};

And you can use those enum defines in the documentation.

Ok, thanks. That is is interesting. Will fix in next version.

Quoted 8 lines

Regards,

Hans

Quoted 2 lines
include/uapi/linux/mlx7502x.h new file +2 -0
+
+#endif /* __UAPI_MLX7502X_H_ */
Signature · 3 lines
--
BR,
Volodymyr Kharuk
Reviewed-by on v3 7/8
#19 lore raw

Re: [PATCH v3 7/8] media: dt-bindings: media: i2c: Add mlx7502x camera sensor

In reply to Volodymyr Kharuk
Quoted 5 lines · Volodymyr Kharuk

Add device tree binding of the mlx7502x and update MAINTAINERS

---
 .../bindings/media/i2c/melexis,mlx7502x.yaml  | 126 ++++++++++++++++++

I mentioned you have wrong subject prefix. Only one "media" in the subject prefix is needed, so:
"media: dt-bindings: Add melexis,mlx7502x camera sensor"

Quoted 4 lines
 MAINTAINERS                                   |   1 +
 2 files changed, 127 insertions(+)
 create mode 100644 Documentation/devicetree/bindings/media/i2c/melexis,mlx7502x.yaml

Best regards,
Krzysztof

#20 lore raw

Re: [PATCH v3 7/8] media: dt-bindings: media: i2c: Add mlx7502x camera sensor

Quoted 10 lines · Krzysztof Kozlowski
Quoted 5 lines · Volodymyr Kharuk

Add device tree binding of the mlx7502x and update MAINTAINERS

---
 .../bindings/media/i2c/melexis,mlx7502x.yaml  | 126 ++++++++++++++++++

I mentioned you have wrong subject prefix. Only one "media" in the subject prefix is needed, so:
"media: dt-bindings: Add melexis,mlx7502x camera sensor"

Ah, I missed it. Thanks for review.

Quoted 12 lines
Quoted 5 lines
 MAINTAINERS                                   |   1 +
 2 files changed, 127 insertions(+)
 create mode 100644 Documentation/devicetree/bindings/media/i2c/melexis,mlx7502x.yaml

Best regards,
Krzysztof

Signature · 10 lines
--
Volodymyr Kharuk
Embedded Software Engineer
Melexis-Ukraine
Mykhaila Kotel'nykova St, 4, Kyiv
Mobile phone: +38 050 346 5527
www.melexis.com
---
The contents of this e-mail are CONFIDENTIAL AND PROPRIETARY. Please read
our disclaimer at http://www.melexis.com/mailpolicy
#9 lore raw

Re: [PATCH v3 3/8] media: Documentation: v4l: Add TOF class controls

In reply to Hans Verkuil

Thanks for review.

Quoted 37 lines · Hans Verkuil
Quoted 36 lines · Volodymyr Kharuk

Add description about V4L2_CID_TOF_PHASE_SEQ, V4L2_CID_TOF_FMOD and V4L2_CID_TOF_TINT.
Also updated MAINTAINERS with new ext-ctrls-tof file.

---
 .../userspace-api/media/v4l/common.rst        |  1 +
 .../userspace-api/media/v4l/ext-ctrls-tof.rst | 35 +++++++++++++++++++
 MAINTAINERS                                   |  7 ++++
 3 files changed, 43 insertions(+)
 create mode 100644 Documentation/userspace-api/media/v4l/ext-ctrls-tof.rst
Documentation/userspace-api/media/v4l/common.rst +1 -0
index ea0435182e44..1ea79e453066 100644
@@ -52,6 +52,7 @@ applicable to all devices.
     ext-ctrls-fm-rx
     ext-ctrls-detect
     ext-ctrls-colorimetry
+    ext-ctrls-tof
     fourcc
     format
     planar-apis
Documentation/userspace-api/media/v4l/ext-ctrls-tof.rst new file +6 -0
new file mode 100644
index 000000000000..8902cc7cd47b
@@ -0,0 +1,35 @@
+.. SPDX-License-Identifier: GFDL-1.1-no-invariants-or-later
+
+.. _tof-controls:
+
+***************************************
+Time of Flight Camera Control Reference
Quoted 8 lines

Documentation/userspace-api/media/v4l/ext-ctrls-tof.rst line 10

Quoted 4 lines
Documentation/userspace-api/media/v4l/ext-ctrls-tof.rst new file +4 -0
+***************************************
+
+The Time of Flight class includes controls for digital features
+of TOF camera.

You might want to extend this description a bit and give more info about how they work. Perhaps a link to wikipedia or something might help too.

I was not sure what to add here. Ok, I will update.

Quoted 34 lines
Quoted 5 lines
Documentation/userspace-api/media/v4l/ext-ctrls-tof.rst new file +4 -0
+
+.. _tof-control-id:
+
+Time of Flight Camera Control IDs

Documentation/userspace-api/media/v4l/ext-ctrls-tof.rst line 24

Quoted 10 lines
Documentation/userspace-api/media/v4l/ext-ctrls-tof.rst new file +10 -0
+=================================
+
+``V4L2_CID_TOF_CLASS (class)``
+    The TOF class descriptor. Calling :ref:`VIDIOC_QUERYCTRL` for
+    this control will return a description of this control class.
+
+``V4L2_CID_TOF_PHASE_SEQ (dynamic array u16)``
+    Change the shift between illumination and sampling for each phase
+    in degrees. A distance/confidence picture is obtained by merging
+    3..8 captures of the same scene using different phase shifts(some

Space before (

Documentation/userspace-api/media/v4l/ext-ctrls-tof.rst line 25

Quoted 1 line
Documentation/userspace-api/media/v4l/ext-ctrls-tof.rst new file +1 -0
+    TOF sensors use different frequency modulation).
Either: use -> use a
Or:     modulation -> modulations

It's not clear right now whether "frequency modulation" is meant to be singular or plural.

Documentation/userspace-api/media/v4l/ext-ctrls-tof.rst line 30

Quoted 5 lines
Documentation/userspace-api/media/v4l/ext-ctrls-tof.rst new file +5 -0
+
+    The maximum array size is driver specific.
+
+``V4L2_CID_TOF_FMOD (dynamic array u8)``
+    The control sets the modulation frequency(in Mhz) per each phase.

Space before (

Quoted 7 lines

per each phase -> for each phase

Documentation/userspace-api/media/v4l/ext-ctrls-tof.rst line 31

Quoted 1 line
Documentation/userspace-api/media/v4l/ext-ctrls-tof.rst new file +1 -0
+    The maximum array size is driver specific.

What does the maximum array size signify? The number of phases? It's not clear from the spec (and I have to admit I know very little about TOF sensors).

yes, array size defines the number of phases.
But the maximum number of phases can be different and depend on the sensor. I'll update the doc.

Quoted 32 lines

Documentation/userspace-api/media/v4l/ext-ctrls-tof.rst line 34

Quoted 4 lines
Documentation/userspace-api/media/v4l/ext-ctrls-tof.rst new file +3 -0
+
+``V4L2_CID_TOF_TINT (dynamic array u16)``
+    The control sets the integration time(in us) per each phase.

Add space before (

per each phase -> for each phase

Quoted 9 lines
Documentation/userspace-api/media/v4l/ext-ctrls-tof.rst new file +1 -0
+    The maximum array size is driver specific.
MAINTAINERS +0 -0
index aa1974054fce..a2bc2ce53056 100644
@@ -13111,6 +13111,13 @@ S:	Supported
 W:	http://www.melexis.com
 F:	drivers/iio/temperature/mlx90632.c
 

MAINTAINERS S: Supported · line 13123

Quoted 10 lines
MAINTAINERS +7 -0
+MELEXIS MLX7502X DRIVER
+M:	Volodymyr Kharuk <[email protected]>
+L:	[email protected]
+S:	Supported
+W:	http://www.melexis.com
+F:	Documentation/userspace-api/media/v4l/ext-ctrls-tof.rst
+
 MELFAS MIP4 TOUCHSCREEN DRIVER
 M:	Sangwon Jee <[email protected]>
 S:	Supported

Regards,

Hans

Signature · 10 lines
--
Volodymyr Kharuk
Embedded Software Engineer
Melexis-Ukraine
Mykhaila Kotel'nykova St, 4, Kyiv
Mobile phone: +38 050 346 5527
www.melexis.com
---
The contents of this e-mail are CONFIDENTIAL AND PROPRIETARY. Please read
our disclaimer at http://www.melexis.com/mailpolicy
#12 lore raw

Re: [PATCH v3 4/8] media: v4l: ctrls-api: Allow array update in __v4l2_ctrl_modify_range

In reply to Hans Verkuil

Hi Hans,

Quoted 39 lines · Hans Verkuil
Quoted 24 lines · Volodymyr Kharuk

For V4L2_CID_TOF_TINT, which is dynamic array, it is required to use __v4l2_ctrl_modify_range. So the idea is to use type_ops instead of u64 from union. It will allow to work with any type.

---
 drivers/media/v4l2-core/v4l2-ctrls-api.c | 15 +++------------
 1 file changed, 3 insertions(+), 12 deletions(-)
drivers/media/v4l2-core/v4l2-ctrls-api.c +0 -2
index d0a3aa3806fb..09735644a2f1 100644
@@ -942,8 +942,6 @@ int __v4l2_ctrl_modify_range(struct v4l2_ctrl *ctrl,
 	case V4L2_CTRL_TYPE_U8:
 	case V4L2_CTRL_TYPE_U16:
 	case V4L2_CTRL_TYPE_U32:
-		if (ctrl->is_array)
-			return -EINVAL;
 		ret = check_range(ctrl->type, min, max, step, def);
 		if (ret)
 			return ret;
@@ -960,17 +958,10 @@ int __v4l2_ctrl_modify_range(struct v4l2_ctrl *ctrl,
 		ctrl->default_value = def;

drivers/media/v4l2-core/v4l2-ctrls-api.c int __v4l2_ctrl_modify_range(struct v4l2_ctrl *ctrl, · line 962

Quoted 10 lines
drivers/media/v4l2-core/v4l2-ctrls-api.c +2 -6
 	}
 	cur_to_new(ctrl);
-	if (validate_new(ctrl, ctrl->p_new)) {
-		if (ctrl->type == V4L2_CTRL_TYPE_INTEGER64)
-			*ctrl->p_new.p_s64 = def;
-		else
-			*ctrl->p_new.p_s32 = def;
-	}
+	if (validate_new(ctrl, ctrl->p_new))
+		ctrl->type_ops->init(ctrl, 0, ctrl->p_new);

Hmm, this sets *all* elements of the array to the default_value, not just the elements whose value is out of range.

Quoted 6 lines

Is that what you want? Should this perhaps depend on the type of control? I.e. in some cases it might make sense to do this, in other cases it makes more sense to only adjust the elements that are out of range.

How does that work for this TINT control?

Actually for types like INTEGER/U8/U16/U32/BOOLEAN/BUTTON/BITMASK, the function validate_new will return zero always as well as they fix the range on the fly. So that is ok for mlx7502x sensors.

For types like compound/string/menu indeed, it will sets all elements of array to default array. To fix it I propose to fix it by using the functions std_validate_elem to check per element and then set the default manually. But then it means, that __v4l2_ctrl_modify_range will work only for standart v4l2 types, and not if driver use their own implementation.

Is it fine for you? What do you think?

Quoted 15 lines

Regards,

Hans

Quoted 9 lines
drivers/media/v4l2-core/v4l2-ctrls-api.c +1 -4
-	if (ctrl->type == V4L2_CTRL_TYPE_INTEGER64)
-		value_changed = *ctrl->p_new.p_s64 != *ctrl->p_cur.p_s64;
-	else
-		value_changed = *ctrl->p_new.p_s32 != *ctrl->p_cur.p_s32;
+	value_changed = !ctrl->type_ops->equal(ctrl, ctrl->p_cur, ctrl->p_new);
 	if (value_changed)
 		ret = set_ctrl(NULL, ctrl, V4L2_EVENT_CTRL_CH_RANGE);
 	else if (range_changed)
Signature · 3 lines
--
BR,
Volodymyr Kharuk
#13 lore raw

Re: [PATCH v3 4/8] media: v4l: ctrls-api: Allow array update in __v4l2_ctrl_modify_range

Quoted 52 lines · Volodymyr Kharuk

Hi Hans,

Quoted 39 lines · Hans Verkuil
Quoted 24 lines · Volodymyr Kharuk

For V4L2_CID_TOF_TINT, which is dynamic array, it is required to use __v4l2_ctrl_modify_range. So the idea is to use type_ops instead of u64 from union. It will allow to work with any type.

---
 drivers/media/v4l2-core/v4l2-ctrls-api.c | 15 +++------------
 1 file changed, 3 insertions(+), 12 deletions(-)
drivers/media/v4l2-core/v4l2-ctrls-api.c +0 -2
index d0a3aa3806fb..09735644a2f1 100644
@@ -942,8 +942,6 @@ int __v4l2_ctrl_modify_range(struct v4l2_ctrl *ctrl,
 	case V4L2_CTRL_TYPE_U8:
 	case V4L2_CTRL_TYPE_U16:
 	case V4L2_CTRL_TYPE_U32:
-		if (ctrl->is_array)
-			return -EINVAL;
 		ret = check_range(ctrl->type, min, max, step, def);
 		if (ret)
 			return ret;
@@ -960,17 +958,10 @@ int __v4l2_ctrl_modify_range(struct v4l2_ctrl *ctrl,
 		ctrl->default_value = def;

drivers/media/v4l2-core/v4l2-ctrls-api.c int __v4l2_ctrl_modify_range(struct v4l2_ctrl *ctrl, · line 962

Quoted 10 lines
drivers/media/v4l2-core/v4l2-ctrls-api.c +2 -6
 	}
 	cur_to_new(ctrl);
-	if (validate_new(ctrl, ctrl->p_new)) {
-		if (ctrl->type == V4L2_CTRL_TYPE_INTEGER64)
-			*ctrl->p_new.p_s64 = def;
-		else
-			*ctrl->p_new.p_s32 = def;
-	}
+	if (validate_new(ctrl, ctrl->p_new))
+		ctrl->type_ops->init(ctrl, 0, ctrl->p_new);

Hmm, this sets *all* elements of the array to the default_value, not just the elements whose value is out of range.

Quoted 6 lines

Is that what you want? Should this perhaps depend on the type of control? I.e. in some cases it might make sense to do this, in other cases it makes more sense to only adjust the elements that are out of range.

How does that work for this TINT control?

Actually for types like INTEGER/U8/U16/U32/BOOLEAN/BUTTON/BITMASK, the function validate_new will return zero always as well as they fix the range on the fly. So that is ok for mlx7502x sensors.

Quoted 7 lines

For types like compound/string/menu indeed, it will sets all elements of array to default array. To fix it I propose to fix it by using the functions std_validate_elem to check per element and then set the default manually. But then it means, that __v4l2_ctrl_modify_range will work only for standart v4l2 types, and not if driver use their own implementation.

Is it fine for you? What do you think?

I've another idea. If validate_new is fixing on the fly
and we can't modify range for copmound/string types, so we can forbidden array for MENU types. Then validate_new will do the job for the rest types. As for now there are no needs in arrays for MENU types.

What do you think?

Signature · 3 lines
--
BR,
Volodymyr Kharuk