media: i2c: mlx7502x ToF camera support
Subsystems (2)
v5 cover media: i2c: mlx7502x ToF camera support
Hello all,
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. Also in patch 4/8 there is changes which allow to modify range of control with array type.
v5:
- MHz to Hz for V4L2_CID_TOF_FREQ_MOD
v4:
- fix output mode
- forbid array for menu and warn if validate_new return an error
- add enums to custom control OUTPUT_MODE
- update doc
- minor fixes
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: 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 | 56 + MAINTAINERS | 11 + drivers/media/i2c/Kconfig | 13 + drivers/media/i2c/Makefile | 1 + drivers/media/i2c/mlx7502x.c | 1747 +++++++++++++++++ drivers/media/v4l2-core/v4l2-ctrls-api.c | 25 +- drivers/media/v4l2-core/v4l2-ctrls-defs.c | 20 + include/uapi/linux/mlx7502x.h | 28 + include/uapi/linux/v4l2-controls.h | 14 + 13 files changed, 2059 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: 2c1bae27df787c9535e48cc27bbd11c3c3e0a235
Signature · 2 lines
BR, Volodymyr Kharuk
PATCH v5 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
@@ -30,6 +30,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 flight camera controls */ /* User-class control IDs */
@@ -3479,6 +3480,13 @@ struct v4l2_ctrl_av1_film_grain {__u8 reserved[4 ]; }; +#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_FREQ_MOD (V4L2_CID_TOF_CLASS_BASE + 1) +#define V4L2_CID_TOF_TIME_INTEGRATION (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
PATCH v5 2/8 media: v4l: ctrls: Fill V4L2_CID_TOF_CLASS controls
In reply to Volodymyr KharukDefine 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
@@ -1242,6 +1242,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 Flight Camera Controls" ; +case V4L2_CID_TOF_PHASE_SEQ :return "TOF Phase Sequence" ; +case V4L2_CID_TOF_FREQ_MOD :return "TOF Frequency Modulation" ; +case V4L2_CID_TOF_TIME_INTEGRATION :return "TOF Time Integration" ;default :return NULL ; }
@@ -1451,6 +1458,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 ;
@@ -1602,6 +1610,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_FREQ_MOD : + *type =V4L2_CTRL_TYPE_U32 ; + *flags |=V4L2_CTRL_FLAG_DYNAMIC_ARRAY ; +break ; +case V4L2_CID_TOF_TIME_INTEGRATION : + *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
PATCH v5 3/8 media: Documentation: v4l: Add TOF class controls
In reply to Volodymyr KharukAdd 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 | 56 +++++++++++++++++++ MAINTAINERS | 7 +++ 3 files changed, 64 insertions(+) create mode 100644 Documentation/userspace-api/media/v4l/ext-ctrls-tof.rst
Documentation/userspace-api/media/v4l/common.rst +1 -0
@@ -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 +56 -0
56 lines not on this page · raw message
MAINTAINERS +7 -0
@@ -13557,6 +13557,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
PATCH v5 4/8 media: v4l: ctrls-api: Allow array update in __v4l2_ctrl_modify_range
In reply to Volodymyr KharukFor 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 | 25 ++++++++++++------------ 1 file changed, 13 insertions(+), 12 deletions(-)
drivers/media/v4l2-core/v4l2-ctrls-api.c +13 -12
@@ -934,17 +934,18 @@ int __v4l2_ctrl_modify_range(struct v4l2_ctrl *ctrl,lockdep_assert_held (ctrl->handler->lock);switch (ctrl->type) { +case V4L2_CTRL_TYPE_MENU : +case V4L2_CTRL_TYPE_INTEGER_MENU : +if (ctrl->is_array) +return -EINVAL ; + fallthrough;case V4L2_CTRL_TYPE_INTEGER :case V4L2_CTRL_TYPE_INTEGER64 :case V4L2_CTRL_TYPE_BOOLEAN : -case V4L2_CTRL_TYPE_MENU : -case V4L2_CTRL_TYPE_INTEGER_MENU :case V4L2_CTRL_TYPE_BITMASK :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;
@@ -962,16 +963,16 @@ int __v4l2_ctrl_modify_range(struct v4l2_ctrl *ctrl, }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; +WARN_ON (ctrl->is_array);/* This shouldn't happen, as +* INTEGER/Ux/BOOLEAN/BITMASK will not +* return an error. +* In case it happened, all array will +* set to default value +*/ + 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
PATCH v5 5/8 media: v4l: ctrls: Add user control base for mlx7502x
In reply to Volodymyr KharukAdd 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
@@ -204,6 +204,12 @@ enum v4l2_colorfx {*/ #define V4L2_CID_USER_ASPEED_BASE (V4L2_CID_USER_BASE + 0x11a0) +/* +* 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 + 0x11b0) +/* 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
PATCH v5 6/8 media: uapi: Add mlx7502x header file
In reply to Volodymyr KharukDefine 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 | 28 +++++++++++++++++++ 4 files changed, 59 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
@@ -37,6 +37,7 @@ For more details see the file COPYING in the source distribution of Linux. dw100 imx-uapi max2175 + mlx7502x omap3isp-uapi st-vgxy61 uvcvideo
Documentation/userspace-api/media/drivers/mlx7502x.rst new file +28 -0
@@ -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 + + * - ``V4L2_MLX7502X_OUTPUT_MODE_A_MINUS_B`` + - tap A minus tap B + * - ``V4L2_MLX7502X_OUTPUT_MODE_A_PLUS_B`` + - tap A plus tap B + * - ``V4L2_MLX7502X_OUTPUT_MODE_A`` + - only tap A + * - ``V4L2_MLX7502X_OUTPUT_MODE_B`` + - only tap B + * - ``V4L2_MLX7502X_OUTPUT_MODE_A_AND_B`` + - tap A and tap B (this config will change PAD format)
MAINTAINERS +2 -0
@@ -13562,7 +13562,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 +28 -0
@@ -0,0 +1,28 @@ +/* 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 +*/ +enum v4l2_mlx7502x_output_mode { +V4L2_MLX7502X_OUTPUT_MODE_A_MINUS_B =0 , +V4L2_MLX7502X_OUTPUT_MODE_A_PLUS_B , +V4L2_MLX7502X_OUTPUT_MODE_A , +V4L2_MLX7502X_OUTPUT_MODE_B , +V4L2_MLX7502X_OUTPUT_MODE_A_AND_B ,/* output frame size doubles */ +}; + +#define V4L2_CID_MLX7502X_OUTPUT_MODE (V4L2_CID_USER_MLX7502X_BASE + 0) + +#endif /* __UAPI_MLX7502X_H_ */
Signature · 2 lines
BR, Volodymyr Kharuk
PATCH v5 7/8 media: dt-bindings: Add mlx7502x camera sensor
In reply to Volodymyr KharukAdd 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
@@ -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 = <®_2v7>; + vddif-supply = <®_1v8>; + vddd-supply = <®_1v2>; + vdmix-supply = <®_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
@@ -13562,6 +13562,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
PATCH v5 8/8 media: i2c: Add driver for mlx7502x ToF sensor
In reply to Volodymyr KharukMelexis 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 | 1747 ++++++++++++++++++++++++++++++++++ 4 files changed, 1762 insertions(+) create mode 100644 drivers/media/i2c/mlx7502x.c
MAINTAINERS +1 -0
@@ -13565,6 +13565,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
@@ -203,6 +203,19 @@ config VIDEO_IMX415 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" help
drivers/media/i2c/Makefile +1 -0
@@ -62,6 +62,7 @@ obj-$(CONFIG_VIDEO_M52790) += m52790.o 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_MT9M111) += mt9m111.o
drivers/media/i2c/mlx7502x.c new file +1747 -0
1,747 lines not on this page · raw message
Signature · 2 lines
BR, Volodymyr Kharuk