11// SPDX-License-Identifier: GPL-2.0
22/*
3- * Sony IMX290/327 CMOS Image Sensor Driver
3+ * Sony IMX290 & IMX327 CMOS Image Sensor Driver
44 *
55 * The IMX290 and IMX327 are very similar 1920x1080 1/2.8 CMOS image sensors.
6- * IMX327 can support up to 60fps, whilst IMX290 support up to 120fps (only
7- * 10bit and when connected over 4 CSI-2 lanes).
6+ * IMX327 can support up to 60fps, whilst IMX290 can support up to 120fps, but
7+ * only 10bit and when connected over 4 CSI-2 lanes.
8+ * The modules don't appear to have a mechanism to identify whether the mono or
9+ * colour variant is connected, therefore it is done via compatible string.
810 *
911 * Copyright (C) 2019 FRAMOS GmbH.
1012 *
1719#include <linux/gpio/consumer.h>
1820#include <linux/i2c.h>
1921#include <linux/module.h>
22+ #include <linux/of_device.h>
2023#include <linux/pm_runtime.h>
2124#include <linux/regmap.h>
2225#include <linux/regulator/consumer.h>
@@ -95,6 +98,8 @@ struct imx290 {
9598 u8 bpp ;
9699 u16 hmax_min ;
97100
101+ const struct imx290_pixfmt * formats ;
102+
98103 struct v4l2_subdev sd ;
99104 struct media_pad pad ;
100105 struct v4l2_mbus_framefmt current_format ;
@@ -120,11 +125,18 @@ struct imx290_pixfmt {
120125 u8 bpp ;
121126};
122127
123- static const struct imx290_pixfmt imx290_formats [] = {
128+ #define IMX290_NUM_FORMATS 2
129+
130+ static const struct imx290_pixfmt imx290_colour_formats [IMX290_NUM_FORMATS ] = {
124131 { MEDIA_BUS_FMT_SRGGB10_1X10 , 10 },
125132 { MEDIA_BUS_FMT_SRGGB12_1X12 , 12 },
126133};
127134
135+ static const struct imx290_pixfmt imx290_mono_formats [IMX290_NUM_FORMATS ] = {
136+ { MEDIA_BUS_FMT_Y10_1X10 , 10 },
137+ { MEDIA_BUS_FMT_Y12_1X12 , 12 },
138+ };
139+
128140static const struct regmap_config imx290_regmap_config = {
129141 .reg_bits = 16 ,
130142 .val_bits = 8 ,
@@ -671,10 +683,12 @@ static int imx290_enum_mbus_code(struct v4l2_subdev *sd,
671683 struct v4l2_subdev_pad_config * cfg ,
672684 struct v4l2_subdev_mbus_code_enum * code )
673685{
674- if (code -> index >= ARRAY_SIZE (imx290_formats ))
686+ const struct imx290 * imx290 = to_imx290 (sd );
687+
688+ if (code -> index >= IMX290_NUM_FORMATS )
675689 return - EINVAL ;
676690
677- code -> code = imx290_formats [code -> index ].code ;
691+ code -> code = imx290 -> formats [code -> index ].code ;
678692
679693 return 0 ;
680694}
@@ -686,8 +700,8 @@ static int imx290_enum_frame_size(struct v4l2_subdev *sd,
686700 const struct imx290 * imx290 = to_imx290 (sd );
687701 const struct imx290_mode * imx290_modes = imx290_modes_ptr (imx290 );
688702
689- if (( fse -> code != imx290_formats [0 ].code ) &&
690- ( fse -> code != imx290_formats [1 ].code ) )
703+ if (fse -> code != imx290 -> formats [0 ].code &&
704+ fse -> code != imx290 -> formats [1 ].code )
691705 return - EINVAL ;
692706
693707 if (fse -> index >= imx290_modes_num (imx290 ))
@@ -765,22 +779,22 @@ static int imx290_set_fmt(struct v4l2_subdev *sd,
765779 fmt -> format .width = mode -> width ;
766780 fmt -> format .height = mode -> height ;
767781
768- for (i = 0 ; i < ARRAY_SIZE ( imx290_formats ) ; i ++ )
769- if (imx290_formats [i ].code == fmt -> format .code )
782+ for (i = 0 ; i < IMX290_NUM_FORMATS ; i ++ )
783+ if (imx290 -> formats [i ].code == fmt -> format .code )
770784 break ;
771785
772- if (i >= ARRAY_SIZE ( imx290_formats ) )
786+ if (i >= IMX290_NUM_FORMATS )
773787 i = 0 ;
774788
775- fmt -> format .code = imx290_formats [i ].code ;
789+ fmt -> format .code = imx290 -> formats [i ].code ;
776790 fmt -> format .field = V4L2_FIELD_NONE ;
777791
778792 if (fmt -> which == V4L2_SUBDEV_FORMAT_TRY ) {
779793 format = v4l2_subdev_get_try_format (sd , cfg , fmt -> pad );
780794 } else {
781795 format = & imx290 -> current_format ;
782796 imx290 -> current_mode = mode ;
783- imx290 -> bpp = imx290_formats [i ].bpp ;
797+ imx290 -> bpp = imx290 -> formats [i ].bpp ;
784798
785799 if (imx290 -> link_freq )
786800 __v4l2_ctrl_s_ctrl (imx290 -> link_freq ,
@@ -835,6 +849,7 @@ static int imx290_write_current_format(struct imx290 *imx290)
835849
836850 switch (imx290 -> current_format .code ) {
837851 case MEDIA_BUS_FMT_SRGGB10_1X10 :
852+ case MEDIA_BUS_FMT_Y10_1X10 :
838853 ret = imx290_set_register_array (imx290 , imx290_10bit_settings ,
839854 ARRAY_SIZE (
840855 imx290_10bit_settings ));
@@ -844,6 +859,7 @@ static int imx290_write_current_format(struct imx290 *imx290)
844859 }
845860 break ;
846861 case MEDIA_BUS_FMT_SRGGB12_1X12 :
862+ case MEDIA_BUS_FMT_Y12_1X12 :
847863 ret = imx290_set_register_array (imx290 , imx290_12bit_settings ,
848864 ARRAY_SIZE (
849865 imx290_12bit_settings ));
@@ -1091,6 +1107,12 @@ static s64 imx290_check_link_freqs(const struct imx290 *imx290,
10911107 return 0 ;
10921108}
10931109
1110+ static const struct of_device_id imx290_of_match [] = {
1111+ { .compatible = "sony,imx290" , .data = imx290_colour_formats },
1112+ { .compatible = "sony,imx290-mono" , .data = imx290_mono_formats },
1113+ { /* sentinel */ }
1114+ };
1115+
10941116static int imx290_probe (struct i2c_client * client )
10951117{
10961118 struct device * dev = & client -> dev ;
@@ -1099,6 +1121,7 @@ static int imx290_probe(struct i2c_client *client)
10991121 struct v4l2_fwnode_endpoint ep = {
11001122 .bus_type = V4L2_MBUS_CSI2_DPHY
11011123 };
1124+ const struct of_device_id * match ;
11021125 const struct imx290_mode * mode ;
11031126 struct imx290 * imx290 ;
11041127 s64 fq ;
@@ -1115,6 +1138,11 @@ static int imx290_probe(struct i2c_client *client)
11151138 return - ENODEV ;
11161139 }
11171140
1141+ match = of_match_device (imx290_of_match , dev );
1142+ if (!match )
1143+ return - ENODEV ;
1144+ imx290 -> formats = (const struct imx290_pixfmt * )match -> data ;
1145+
11181146 endpoint = fwnode_graph_get_next_endpoint (dev_fwnode (dev ), NULL );
11191147 if (!endpoint ) {
11201148 dev_err (dev , "Endpoint node not found\n" );
@@ -1333,10 +1361,6 @@ static int imx290_remove(struct i2c_client *client)
13331361 return 0 ;
13341362}
13351363
1336- static const struct of_device_id imx290_of_match [] = {
1337- { .compatible = "sony,imx290" },
1338- { /* sentinel */ }
1339- };
13401364MODULE_DEVICE_TABLE (of , imx290_of_match );
13411365
13421366static struct i2c_driver imx290_i2c_driver = {
0 commit comments