Add support for mono version of Sony IMX290 sensor
Subsystems (4)
v2 cover Add support for mono version of Sony IMX290 sensor
The IMX290 comes in both mono and colour variants, but has no runtime way of determining which is connected.
These patches adds support for either option.
Changes from v1:
- Renamed compatible from "sony,imx290-mono" to "sony,imx290llr" which is the actual model number for the mono sensor.
- Added an additional sony,imx290lqr as a synonym for the existing colour "sony,imx290".
- Broken description into paragraphs.
- Reworked the driver to take a struct for each compatible, rather than just the mono/colour status.
Dave Stevenson (2):
media: dt-bindings: media: i2c: Add mono version to IMX290 bindings
media: i2c: imx290: Add support for the mono sensor variant.
.../bindings/media/i2c/sony,imx290.yaml | 16 +++- drivers/media/i2c/imx290.c | 81 +++++++++++++++---- 2 files changed, 76 insertions(+), 21 deletions(-)
Signature · 1 line
2.34.1
PATCH v2 1/2 media: dt-bindings: media: i2c: Add mono version to IMX290 bindings
The IMX290 module is available as either monochrome or colour and the variant is not detectable at runtime.
Add a new compatible string for the monochrome version.
--- .../bindings/media/i2c/sony,imx290.yaml | 16 ++++++++++++---- 1 file changed, 12 insertions(+), 4 deletions(-)
Documentation/devicetree/bindings/media/i2c/sony,imx290.yaml +12 -4
@@ -12,15 +12,23 @@ maintainers: description: |- The Sony IMX290 is a 1/2.8-Inch CMOS Solid-state image sensor with Square - Pixel for Color Cameras. It is programmable through I2C and 4-wire - interfaces. The sensor output is available via CMOS logic parallel SDR - output, Low voltage LVDS DDR output and CSI-2 serial data output. The CSI-2 - bus is the default. No bindings have been defined for the other busses. + Pixel, available in either mono or colour variants. + It is programmable through I2C and 4-wire interfaces. + + The sensor output is available via CMOS logic parallel SDR output, Low voltage + LVDS DDR output and CSI-2 serial data output. The CSI-2 bus is the default. + No bindings have been defined for the other busses. + + imx290lqr is the full model identifier for the colour variant. "sony,imx290" + is treated the same as this as it was the original compatible string. + imx290llr is the mono version of the sensor. properties: compatible: enum: - sony,imx290 + - sony,imx290lqr + - sony,imx290llr reg: maxItems: 1
Signature · 1 line
2.34.1
Re: [PATCH v2 1/2] media: dt-bindings: media: i2c: Add mono version to IMX290 bindings
Hi Dave,
Thank you for the patch.
Quoted 30 lines · Dave Stevenson
The IMX290 module is available as either monochrome or colour and the variant is not detectable at runtime.
Add a new compatible string for the monochrome version.
Signed-off-by Dave Stevenson <[email protected]>Acked-by Rob Herring <[email protected]>--- .../bindings/media/i2c/sony,imx290.yaml | 16 ++++++++++++---- 1 file changed, 12 insertions(+), 4 deletions(-)Documentation/devicetree/bindings/media/i2c/sony,imx290.yaml +7
-4@@ -12,15 +12,23 @@ maintainers: description: |- The Sony IMX290 is a 1/2.8-Inch CMOS Solid-state image sensor with Square - Pixel for Color Cameras. It is programmable through I2C and 4-wire - interfaces. The sensor output is available via CMOS logic parallel SDR - output, Low voltage LVDS DDR output and CSI-2 serial data output. The CSI-2 - bus is the default. No bindings have been defined for the other busses. + Pixel, available in either mono or colour variants. + It is programmable through I2C and 4-wire interfaces. + + The sensor output is available via CMOS logic parallel SDR output, Low voltage + LVDS DDR output and CSI-2 serial data output. The CSI-2 bus is the default. + No bindings have been defined for the other busses. +
Documentation/devicetree/bindings/media/i2c/sony,imx290.yaml maintainers: · line 31
Quoted 10 lines
Documentation/devicetree/bindings/media/i2c/sony,imx290.yaml +5
-0+ imx290lqr is the full model identifier for the colour variant. "sony,imx290" + is treated the same as this as it was the original compatible string. + imx290llr is the mono version of the sensor. properties: compatible: enum: - sony,imx290 + - sony,imx290lqr + - sony,imx290llr
Let's mark the first one as deprecated:
properties:
compatible:
oneOf:
- enum:
- sony,imx290lqr # Colour
- sony,imx290llr # Monochrome
- const: sony,imx290
deprecated: true
and update the example. I would then update the commit message to
The IMX290 module is available as either monochrome or colour and the variant is not detectable at runtime.
Add a new compatible string for the monochrome version, based on the full device name IMX290LLR. For consistency, add a new compatible string for the colour version based on the IMX290LQR full device name, and deprecate the current ambiguous compatible string.
With this,
Quoted 3 lines
Documentation/devicetree/bindings/media/i2c/sony,imx290.yaml +0
-0reg: maxItems: 1
Signature · 3 lines
Regards, Laurent Pinchart
PATCH v2 2/2 media: i2c: imx290: Add support for the mono sensor variant.
In reply to Dave StevensonThe IMX290 module is available as either mono or colour (Bayer).
Update the driver so that it can advertise the correct mono formats instead of the colour ones.
--- drivers/media/i2c/imx290.c | 81 ++++++++++++++++++++++++++++++-------- 1 file changed, 64 insertions(+), 17 deletions(-)
drivers/media/i2c/imx290.c +64 -17
@@ -13,6 +13,7 @@#include <linux/gpio/consumer.h> #include <linux/i2c.h> #include <linux/module.h> +#include <linux/of_device.h> #include <linux/pm_runtime.h> #include <linux/regmap.h> #include <linux/regulator/consumer.h>
@@ -157,6 +158,21 @@#define IMX290_NUM_SUPPLIES 3 +enum imx290_colour_variant { +IMX290_VARIANT_COLOUR , +IMX290_VARIANT_MONO , +IMX290_VARIANT_MAX +}; + +enum imx290_model { +IMX290_MODEL_IMX290LQR , +IMX290_MODEL_IMX290LLR , +}; + +struct imx290_model_info { +enum imx290_colour_variant colour_variant; +}; +struct imx290_regval {u32 reg;u32 val;
@@ -177,6 +193,7 @@ struct imx290 {struct clk *xclk;struct regmap *regmap;u8 nlanes; +const struct imx290_model_info *model;struct v4l2_subdev sd;struct media_pad pad;
@@ -414,7 +431,7 @@ static inline int imx290_modes_num(const struct imx290 *imx290) }struct imx290_format_info { -u32 code; +u32 code[IMX290_VARIANT_MAX ];u8 bpp;const struct imx290_regval *regs;unsigned int num_regs;
@@ -422,26 +439,33 @@ struct imx290_format_info {static const struct imx290_format_info imx290_formats[] = { { - .code =MEDIA_BUS_FMT_SRGGB10_1X10 , + .code = { + [IMX290_VARIANT_COLOUR ] =MEDIA_BUS_FMT_SRGGB10_1X10 , + [IMX290_VARIANT_MONO ] =MEDIA_BUS_FMT_Y10_1X10 + }, .bpp =10 , .regs = imx290_10bit_settings, .num_regs =ARRAY_SIZE (imx290_10bit_settings), }, { - .code =MEDIA_BUS_FMT_SRGGB12_1X12 , + .code = { + [IMX290_VARIANT_COLOUR ] =MEDIA_BUS_FMT_SRGGB12_1X12 , + [IMX290_VARIANT_MONO ] =MEDIA_BUS_FMT_Y12_1X12 + }, .bpp =12 , .regs = imx290_12bit_settings, .num_regs =ARRAY_SIZE (imx290_12bit_settings), } }; -static const struct imx290_format_info *imx290_format_info (u32 code) +static const struct imx290_format_info * +imx290_format_info (const struct imx290 *imx290,u32 code) {unsigned int i;for (i =0 ; i <ARRAY_SIZE (imx290_formats); ++i) {const struct imx290_format_info *info = &imx290_formats[i]; -if (info->code == code) +if (info->code[imx290->model->colour_variant] == code)return info; }
@@ -536,7 +560,7 @@ static int imx290_set_black_level(struct imx290 *imx290,const struct v4l2_mbus_framefmt *format, unsigned int black_level, int *err) { - unsigned int bpp = imx290_format_info(format->code)->bpp; + unsigned int bpp = imx290_format_info(imx290, format->code)->bpp;return imx290_write (imx290,IMX290_BLKLEVEL , black_level >> (16 - bpp), err);
@@ -548,7 +572,7 @@ static int imx290_setup_format(struct imx290 *imx290,const struct imx290_format_info *info;int ret; - info =imx290_format_info (format->code); + info =imx290_format_info (imx290, format->code); ret =imx290_set_register_array (imx290, info->regs, info->num_regs);if (ret <0 ) {
@@ -844,10 +868,12 @@ static int imx290_enum_mbus_code(struct v4l2_subdev *sd,struct v4l2_subdev_state *sd_state, struct v4l2_subdev_mbus_code_enum *code) { + const struct imx290 *imx290 = to_imx290(sd); +if (code->index >=ARRAY_SIZE (imx290_formats))return -EINVAL ; - code->code = imx290_formats[code->index].code; + code->code = imx290_formats[code->index].code[imx290->model->colour_variant];return 0 ; }
@@ -859,7 +885,7 @@ static int imx290_enum_frame_size(struct v4l2_subdev *sd,const struct imx290 *imx290 =to_imx290 (sd);const struct imx290_mode *imx290_modes =imx290_modes_ptr (imx290); -if (!imx290_format_info (fse->code)) +if (!imx290_format_info (imx290, fse->code))return -EINVAL ;if (fse->index >=imx290_modes_num (imx290))
@@ -888,8 +914,8 @@ static int imx290_set_fmt(struct v4l2_subdev *sd, fmt->format.width = mode->width; fmt->format.height = mode->height; -if (!imx290_format_info (fmt->format.code)) - fmt->format.code = imx290_formats[0 ].code; +if (!imx290_format_info (imx290, fmt->format.code)) + fmt->format.code = imx290_formats[0 ].code[imx290->model->colour_variant]; fmt->format.field =V4L2_FIELD_NONE ;
@@ -1177,6 +1203,31 @@ static s64 imx290_check_link_freqs(const struct imx290 *imx290,return 0 ; } +static const struct imx290_model_info imx290_models[] = { + [IMX290_MODEL_IMX290LQR ] = { + .colour_variant =IMX290_VARIANT_COLOUR , + }, + [IMX290_MODEL_IMX290LLR ] = { + .colour_variant =IMX290_VARIANT_MONO , + }, +}; + +static const struct of_device_id imx290_of_match[] = { + { +/* Deprecated - synonym for "sony,imx290lqr" */ + .compatible ="sony,imx290" , + .data = &imx290_models[IMX290_MODEL_IMX290LQR ], + }, { + .compatible ="sony,imx290lqr" , + .data = &imx290_models[IMX290_MODEL_IMX290LQR ], + }, { + .compatible ="sony,imx290llr" , + .data = &imx290_models[IMX290_MODEL_IMX290LLR ], + }, + {/* sentinel */ }, +}; +MODULE_DEVICE_TABLE (of, imx290_of_match); +static int imx290_parse_dt (struct imx290 *imx290) {/* Only CSI2 is supported for now: */
@@ -1187,6 +1238,8 @@ static int imx290_parse_dt(struct imx290 *imx290)int ret;s64 fq; + imx290->model = (const struct imx290_model_info *)of_device_get_match_data (imx290->dev); + endpoint =fwnode_graph_get_next_endpoint (dev_fwnode (imx290->dev),NULL );if (!endpoint) {dev_err (imx290->dev,"Endpoint node not found\n" );
@@ -1351,12 +1404,6 @@ static void imx290_remove(struct i2c_client *client)pm_runtime_set_suspended (imx290->dev); } -static const struct of_device_id imx290_of_match[] = { - { .compatible ="sony,imx290" }, - {/* sentinel */ } -}; -MODULE_DEVICE_TABLE (of, imx290_of_match); -static struct i2c_driver imx290_i2c_driver = { .probe_new = imx290_probe, .remove = imx290_remove,
Signature · 1 line
2.34.1
Re: [PATCH v2 2/2] media: i2c: imx290: Add support for the mono sensor variant.
Hi Dave,
Thank you for the patch.
Quoted 4 lines · Dave Stevenson
The IMX290 module is available as either mono or colour (Bayer).
Update the driver so that it can advertise the correct mono formats instead of the colour ones.
The patch fails to compile when based on the latest media tree, due to an unconverted imx290_format_info() call. I suppose it was due to a conflict. It's easy to fix.
Quoted 179 lines
Signed-off-by Dave Stevenson <[email protected]>--- drivers/media/i2c/imx290.c | 81 ++++++++++++++++++++++++++++++-------- 1 file changed, 64 insertions(+), 17 deletions(-)drivers/media/i2c/imx290.c +62
-11@@ -13,6 +13,7 @@#include <linux/gpio/consumer.h> #include <linux/i2c.h> #include <linux/module.h> +#include <linux/of_device.h> #include <linux/pm_runtime.h> #include <linux/regmap.h> #include <linux/regulator/consumer.h> @@ -157,6 +158,21 @@#define IMX290_NUM_SUPPLIES 3 +enum imx290_colour_variant { +IMX290_VARIANT_COLOUR , +IMX290_VARIANT_MONO , +IMX290_VARIANT_MAX +}; + +enum imx290_model { +IMX290_MODEL_IMX290LQR , +IMX290_MODEL_IMX290LLR , +}; + +struct imx290_model_info { +enum imx290_colour_variant colour_variant; +}; +struct imx290_regval {u32 reg;u32 val;@@ -177,6 +193,7 @@ struct imx290 {struct clk *xclk;struct regmap *regmap;u8 nlanes; +const struct imx290_model_info *model;struct v4l2_subdev sd;struct media_pad pad;@@ -414,7 +431,7 @@ static inline int imx290_modes_num(const struct imx290 *imx290) }struct imx290_format_info { -u32 code; +u32 code[IMX290_VARIANT_MAX ];u8 bpp;const struct imx290_regval *regs;unsigned int num_regs;@@ -422,26 +439,33 @@ struct imx290_format_info {static const struct imx290_format_info imx290_formats[] = { { - .code =MEDIA_BUS_FMT_SRGGB10_1X10 , + .code = { + [IMX290_VARIANT_COLOUR ] =MEDIA_BUS_FMT_SRGGB10_1X10 , + [IMX290_VARIANT_MONO ] =MEDIA_BUS_FMT_Y10_1X10 + }, .bpp =10 , .regs = imx290_10bit_settings, .num_regs =ARRAY_SIZE (imx290_10bit_settings), }, { - .code =MEDIA_BUS_FMT_SRGGB12_1X12 , + .code = { + [IMX290_VARIANT_COLOUR ] =MEDIA_BUS_FMT_SRGGB12_1X12 , + [IMX290_VARIANT_MONO ] =MEDIA_BUS_FMT_Y12_1X12 + }, .bpp =12 , .regs = imx290_12bit_settings, .num_regs =ARRAY_SIZE (imx290_12bit_settings), } }; -static const struct imx290_format_info *imx290_format_info (u32 code) +static const struct imx290_format_info * +imx290_format_info (const struct imx290 *imx290,u32 code) {unsigned int i;for (i =0 ; i <ARRAY_SIZE (imx290_formats); ++i) {const struct imx290_format_info *info = &imx290_formats[i]; -if (info->code == code) +if (info->code[imx290->model->colour_variant] == code)return info; }@@ -536,7 +560,7 @@ static int imx290_set_black_level(struct imx290 *imx290,const struct v4l2_mbus_framefmt *format, unsigned int black_level, int *err) { - unsigned int bpp = imx290_format_info(format->code)->bpp; + unsigned int bpp = imx290_format_info(imx290, format->code)->bpp;return imx290_write (imx290,IMX290_BLKLEVEL , black_level >> (16 - bpp), err);@@ -548,7 +572,7 @@ static int imx290_setup_format(struct imx290 *imx290,const struct imx290_format_info *info;int ret; - info =imx290_format_info (format->code); + info =imx290_format_info (imx290, format->code); ret =imx290_set_register_array (imx290, info->regs, info->num_regs);if (ret <0 ) {@@ -844,10 +868,12 @@ static int imx290_enum_mbus_code(struct v4l2_subdev *sd,struct v4l2_subdev_state *sd_state, struct v4l2_subdev_mbus_code_enum *code) { + const struct imx290 *imx290 = to_imx290(sd); +if (code->index >=ARRAY_SIZE (imx290_formats))return -EINVAL ; - code->code = imx290_formats[code->index].code; + code->code = imx290_formats[code->index].code[imx290->model->colour_variant];return 0 ; }@@ -859,7 +885,7 @@ static int imx290_enum_frame_size(struct v4l2_subdev *sd,const struct imx290 *imx290 =to_imx290 (sd);const struct imx290_mode *imx290_modes =imx290_modes_ptr (imx290); -if (!imx290_format_info (fse->code)) +if (!imx290_format_info (imx290, fse->code))return -EINVAL ;if (fse->index >=imx290_modes_num (imx290))@@ -888,8 +914,8 @@ static int imx290_set_fmt(struct v4l2_subdev *sd, fmt->format.width = mode->width; fmt->format.height = mode->height; -if (!imx290_format_info (fmt->format.code)) - fmt->format.code = imx290_formats[0 ].code; +if (!imx290_format_info (imx290, fmt->format.code)) + fmt->format.code = imx290_formats[0 ].code[imx290->model->colour_variant]; fmt->format.field =V4L2_FIELD_NONE ;@@ -1177,6 +1203,31 @@ static s64 imx290_check_link_freqs(const struct imx290 *imx290,return 0 ; } +static const struct imx290_model_info imx290_models[] = { + [IMX290_MODEL_IMX290LQR ] = { + .colour_variant =IMX290_VARIANT_COLOUR , + }, + [IMX290_MODEL_IMX290LLR ] = { + .colour_variant =IMX290_VARIANT_MONO , + }, +}; + +static const struct of_device_id imx290_of_match[] = { + { +/* Deprecated - synonym for "sony,imx290lqr" */ + .compatible ="sony,imx290" , + .data = &imx290_models[IMX290_MODEL_IMX290LQR ], + }, { + .compatible ="sony,imx290lqr" , + .data = &imx290_models[IMX290_MODEL_IMX290LQR ], + }, { + .compatible ="sony,imx290llr" , + .data = &imx290_models[IMX290_MODEL_IMX290LLR ], + }, + {/* sentinel */ }, +}; +MODULE_DEVICE_TABLE (of, imx290_of_match); +static int imx290_parse_dt (struct imx290 *imx290) {/* Only CSI2 is supported for now: */
drivers/media/i2c/imx290.c static int imx290_parse_dt(struct imx290 *imx290) · line 1241
Quoted 4 lines
drivers/media/i2c/imx290.c +1
-0@@ -1187,6 +1238,8 @@ static int imx290_parse_dt(struct imx290 *imx290)int ret;s64 fq; + imx290->model = (const struct imx290_model_info *)of_device_get_match_data (imx290->dev);
No need for a cast.
drivers/media/i2c/imx290.c static void imx290_remove(struct i2c_client *client) · line 1358
Quoted 13 lines
drivers/media/i2c/imx290.c +1
-5+ endpoint =fwnode_graph_get_next_endpoint (dev_fwnode (imx290->dev),NULL );if (!endpoint) {dev_err (imx290->dev,"Endpoint node not found\n" );@@ -1351,12 +1404,6 @@ static void imx290_remove(struct i2c_client *client)pm_runtime_set_suspended (imx290->dev); } -static const struct of_device_id imx290_of_match[] = { - { .compatible ="sony,imx290" }, - {/* sentinel */ } -}; -MODULE_DEVICE_TABLE (of, imx290_of_match);
You don't have to move the table up anymore.
I've taken the series in my tree for testing, with the comments on both patches addressed, so I can send a v3 after testing. It will have to wait until the end of the week thoug, as I lack access to the hardware right now. Feel free to beat me to it :-)
Quoted 4 lines
drivers/media/i2c/imx290.c +0
-1-static struct i2c_driver imx290_i2c_driver = { .probe_new = imx290_probe, .remove = imx290_remove,
Signature · 3 lines
Regards, Laurent Pinchart