media: i2c: add Sony IMX111 CMOS camera sensor driver
Subsystems (3)
v4 cover media: i2c: add Sony IMX111 CMOS camera sensor driver
Add driver for Sony IMX111 CMOS sensor found in LG Optimus 4X and Vu smartphones.
---
Changes in v2:
- added nvmem-consumer and dropped eeprom
- switched to unevaluatedProperties
- dropped flash-leds, lens-focus, orientation and rotation since they are inherited from video-interface-devices by unevaluatedProperties
- dropped assigned-clock* props
- improved code style
- adjusted colorspace definitions
Changes in v3:
- switched to devm_regulator_bulk_get_const
- set V4L2_MBUS_CSI2_DPHY bus type unconditionaly
- removed pm_runtime_mark_last_busy
- removed properties from port endpoint and bus-type requirement
- removed unused headers
- adjusted register macros
- added vblank and hblank
- swapped register writed with known purpuse with macros
- container_of > container_of_const
- added return check to group write
- adjusted PM similar to imx219
- switched to enable/disable streams
- dropped enum_frame_interval, get_frame_interval and set_frame_interval ops
- devm_clk_get > devm_v4l2_sensor_clk_get
- adjusted default_link_freq calculation
- dropped imx111_id i2c_device_id
- improved code formatting
Changes in v4:
- aligned to 80 symbols per line
- switch > if for V4L2_CID_VBLANK in imx111_set_ctrl
- defined INTEGRATION_TIME_OFFSET
- added check for __v4l2_ctrl_* calls
- removed struct v4l2_subdev *sd from imx111_init_controls
- increased num of controls to 15
- initiated ret values
- added return pointer to most cci operations
---
Svyatoslav Ryhel (2):
dt-bindings: media: i2c: document Sony IMX111 CMOS sensor
media: i2c: add Sony IMX111 CMOS camera sensor driver
.../bindings/media/i2c/sony,imx111.yaml | 105 ++ drivers/media/i2c/Kconfig | 10 + drivers/media/i2c/Makefile | 1 + drivers/media/i2c/imx111.c | 1610 +++++++++++++++++ 4 files changed, 1726 insertions(+) create mode 100644 Documentation/devicetree/bindings/media/i2c/sony,imx111.yaml create mode 100644 drivers/media/i2c/imx111.c
Signature · 1 line
2.51.0
PATCH v4 1/2 dt-bindings: media: i2c: document Sony IMX111 CMOS sensor
Add bindings for Sony IMX111 CMOS Digital Image Sensor found in LG Optimus 4X (P880) and Optimus Vu (P895) smartphones.
--- .../bindings/media/i2c/sony,imx111.yaml | 105 ++++++++++++++++++ 1 file changed, 105 insertions(+) create mode 100644 Documentation/devicetree/bindings/media/i2c/sony,imx111.yaml
Documentation/devicetree/bindings/media/i2c/sony,imx111.yaml new file +105 -0
@@ -0,0 +1,105 @@ +# SPDX-License-Identifier: (GPL-2.0-only OR BSD-2-Clause) +%YAML 1.2 +--- +$id: http://devicetree.org/schemas/media/i2c/sony,imx111.yaml# +$schema: http://devicetree.org/meta-schemas/core.yaml# + +title: Sony IMX111 8MP CMOS Digital Image Sensor + +maintainers: + - Svyatoslav Ryhel <[email protected]> + +description: + IMX111 sensor is a Sony CMOS active pixel digital image sensor with an active + array size of 2464H x 3280V. It is programmable through I2C interface. Image + data is sent through MIPI CSI-2, through 1 or 2 lanes. + +allOf: + - $ref: /schemas/media/video-interface-devices.yaml# + - $ref: /schemas/nvmem/nvmem-consumer.yaml# + +properties: + compatible: + const: sony,imx111 + + reg: + maxItems: 1 + + clocks: + description: EXTCLK with possible frequency from 6 to 54 MHz + maxItems: 1 + + reset-gpios: + maxItems: 1 + + iovdd-supply: + description: Digital IO power supply (1.8V) + + dvdd-supply: + description: Digital power supply (1.2V) + + avdd-supply: + description: Analog power supply (2.7V) + + port: + additionalProperties: false + $ref: /schemas/graph.yaml#/$defs/port-base + + properties: + endpoint: + $ref: /schemas/media/video-interfaces.yaml# + unevaluatedProperties: false + + required: + - data-lanes + - link-frequencies + + required: + - endpoint + +required: + - compatible + - reg + - clocks + - port + +unevaluatedProperties: false + +examples: + - | + #include <dt-bindings/gpio/gpio.h> + #include <dt-bindings/media/video-interfaces.h> + + i2c { + #address-cells = <1>; + #size-cells = <0>; + + camera@10 { + compatible = "sony,imx111"; + reg = <0x10>; + + clocks = <&imx111_clk>; + + iovdd-supply = <&camera_vddio_1v8>; + dvdd-supply = <&camera_vddd_1v2>; + avdd-supply = <&camera_vdda_2v7>; + + orientation = <1>; + rotation = <90>; + + nvmem = <&eeprom>; + flash-leds = <&led>; + lens-focus = <&vcm>; + + reset-gpios = <&gpio 84 GPIO_ACTIVE_LOW>; + + port { + imx111_output: endpoint { + data-lanes = <1 2>; + link-frequencies = /bits/ 64 <542400000>; + remote-endpoint = <&csi_input>; + }; + }; + }; + }; +...
Signature · 1 line
2.51.0
PATCH v4 2/2 media: i2c: add Sony IMX111 CMOS camera sensor driver
In reply to Svyatoslav RyhelAdd a v4l2 sub-device driver for the Sony IMX111 image sensor. This is a camera sensor using the i2c bus for control and the csi-2 bus for data.
The following features are supported:
- manual exposure, digital and analog gain control support
- pixel rate/link freq control support
- supported resolution up to 3280x2464 for single shot capture
- supported resolution up to 1920x1080 @ 30fps for video
- supported bayer order output SGBRG10 and SGBRG8
Camera module seems to be partially compatible with Nokia SMIA but it lacks a few registers required for clock calculations and has different vendor-specific per-mode configurations which makes it incompatible with existing CCS driver.
--- drivers/media/i2c/Kconfig | 10 + drivers/media/i2c/Makefile | 1 + drivers/media/i2c/imx111.c | 1610 ++++++++++++++++++++++++++++++++++++ 3 files changed, 1621 insertions(+) create mode 100644 drivers/media/i2c/imx111.c
drivers/media/i2c/Kconfig +10 -0
@@ -127,6 +127,16 @@ config VIDEO_HI847 To compile this driver as a module, choose M here: the module will be called hi847. +config VIDEO_IMX111 + tristate "Sony IMX111 sensor support" + select V4L2_CCI_I2C + help + This is a V4L2 sensor driver for the Sony IMX111 camera + sensors. + + To compile this driver as a module, choose M here: the + module will be called imx111. + config VIDEO_IMX208 tristate "Sony IMX208 sensor support" help
drivers/media/i2c/Makefile +1 -0
@@ -45,6 +45,7 @@ obj-$(CONFIG_VIDEO_HI556) += hi556.o obj-$(CONFIG_VIDEO_HI846) += hi846.o obj-$(CONFIG_VIDEO_HI847) += hi847.o obj-$(CONFIG_VIDEO_I2C) += video-i2c.o +obj-$(CONFIG_VIDEO_IMX111) += imx111.o obj-$(CONFIG_VIDEO_IMX208) += imx208.o obj-$(CONFIG_VIDEO_IMX214) += imx214.o obj-$(CONFIG_VIDEO_IMX219) += imx219.o
drivers/media/i2c/imx111.c new file +1610 -0
1,610 lines not on this page · raw message
Signature · 1 line
2.51.0
Sakari Ailus
maintainerHi Svyatoslav,
A few comments below...
On Mon, Nov 03, 2025 at 04:56:29PM +0200, Svyatoslav Ryhel wrote:
...
Quoted 4 lines
drivers/media/i2c/imx111.c new file +4
-0+static int imx111_set_format (struct v4l2_subdev *sd, +struct v4l2_subdev_state *state, +struct v4l2_subdev_format *format) +{
drivers/media/i2c/imx111.c line 1137
Quoted 10 lines
drivers/media/i2c/imx111.c new file +10
-0+struct imx111 *sensor =sd_to_imx111 (sd); +struct v4l2_mbus_framefmt *mbus_fmt = &format->format; +struct v4l2_mbus_framefmt *fmt; +const struct imx111_mode *mode; + + mode =v4l2_find_nearest_size (imx111_modes,ARRAY_SIZE (imx111_modes), + width, height, + mbus_fmt->width, mbus_fmt->height); + + fmt =v4l2_subdev_state_get_format (state, format->pad);
You should set the fields below after changing the controls. Albeit... it won't be perfect in that case either, as only some controls may have been applied. How about just moving the lines below after changing the controls?
Quoted 50 lines
drivers/media/i2c/imx111.c new file +50
-0+ + fmt->code =imx111_get_format_code (sensor, mbus_fmt->code, false); + fmt->width = mode->width; + fmt->height = mode->height; + fmt->colorspace =V4L2_COLORSPACE_RAW ; + + *mbus_fmt = *fmt; + +if (format->which ==V4L2_SUBDEV_FORMAT_ACTIVE ) { +int ret; + + sensor->cur_mode = mode; + sensor->data_depth =imx111_get_format_bpp (fmt); + + ret =__v4l2_ctrl_s_ctrl_int64 (sensor->pixel_rate, +div_u64 (sensor->pixel_clk_raw, +2 * + sensor->data_depth)); +if (ret) +return ret; + + ret =__v4l2_ctrl_modify_range (sensor->vblank, +IMX111_VBLANK_MIN , +IMX111_VTL_MAX - mode->height, +1 , + mode->vtl_def - mode->height); +if (ret) +return ret; + + ret =__v4l2_ctrl_s_ctrl (sensor->vblank, mode->vtl_def - + mode->height); +if (ret) +return ret; + + ret =__v4l2_ctrl_modify_range (sensor->hblank, +IMX111_HBLANK_MIN , +IMX111_HTL_MAX - mode->width, +1 , + mode->htl_def - mode->width); +if (ret) +return ret; + + ret =__v4l2_ctrl_s_ctrl (sensor->hblank, mode->htl_def - + mode->width); +if (ret) +return ret; + } + +return 0 ; +}
...
Quoted 70 lines
drivers/media/i2c/imx111.c new file +70
-0+static int imx111_probe (struct i2c_client *client) +{ +struct device *dev = &client->dev; +struct imx111 *sensor; +int ret; + + sensor =devm_kzalloc (dev,sizeof (*sensor),GFP_KERNEL ); +if (!sensor) +return -ENOMEM ; + + sensor->regmap =devm_cci_regmap_init_i2c (client,16 ); +if (IS_ERR (sensor->regmap)) +return dev_err_probe (dev,PTR_ERR (sensor->regmap), +"Failed to allocate register map\n" ); + + sensor->extclk =devm_v4l2_sensor_clk_get (dev,NULL ); +if (IS_ERR (sensor->extclk)) +return dev_err_probe (dev,PTR_ERR (sensor->extclk), +"Failed to get clock\n" ); + + sensor->reset =devm_gpiod_get_optional (dev,"reset" ,GPIOD_OUT_LOW ); +if (IS_ERR (sensor->reset)) +return dev_err_probe (dev,PTR_ERR (sensor->reset), +"Failed to get reset GPIO\n" ); + + ret =devm_regulator_bulk_get_const (dev,ARRAY_SIZE (imx111_supplies), + imx111_supplies, + &sensor->supplies); +if (ret <0 ) +return dev_err_probe (dev, ret,"Failed to get regulators\n" ); + + ret =imx111_parse_dt (sensor); +if (ret <0 ) +return ret; + + ret =imx111_clk_init (sensor); +if (ret <0 ) + goto error_ep_free; + + ret =imx111_power_on (sensor); +if (ret <0 ) { +dev_err_probe (dev, ret,"Could not power on the device\n" ); + goto error_ep_free; + } + + ret =imx111_identify_module (sensor); +if (ret <0 ) { +dev_err_probe (dev, ret,"Could not identify module\n" ); + goto error_power_off; + } + + sensor->cur_mode = &imx111_modes[IMX111_MODE_3280x2464]; + sensor->data_depth =IMX111_DATA_DEPTH_RAW10 ; + + ret =imx111_initialize (sensor); +if (ret <0 ) + goto error_power_off; + + ret =imx111_init_subdev (sensor, client); +if (ret <0 ) { +dev_err (dev,"failed to init controls: %d" , ret); + goto error_v4l2_ctrl_handler_free; + } + + ret =v4l2_subdev_init_finalize (&sensor->sd); +if (ret) + goto error_v4l2_ctrl_handler_free; + +pm_runtime_set_active (dev); +pm_runtime_enable (dev);
drivers/media/i2c/imx111.c line 1547
Quoted 10 lines
drivers/media/i2c/imx111.c new file +10
-0+ + ret =v4l2_async_register_subdev_sensor (&sensor->sd); +if (ret <0 ) { +dev_err (dev,"failed to register V4L2 subdev: %d" , ret); + goto error_pm; + } + +pm_runtime_idle (dev); +pm_runtime_set_autosuspend_delay (dev,1000 ); +pm_runtime_use_autosuspend (dev);
The autosuspend should be set before pm_runtime_idle() call(), shouldn't it?
I can make the two changes before applying, too, if that's ok.
Signature · 3 lines
Regards, Sakari Ailus
вт, 11 лист. 2025 р. о 14:50 Sakari Ailus <[email protected]> пише:
Quoted 165 lines
Hi Svyatoslav,
A few comments below...
On Mon, Nov 03, 2025 at 04:56:29PM +0200, Svyatoslav Ryhel wrote:
...
Quoted 4 lines
drivers/media/i2c/imx111.c new file +4
-0+static int imx111_set_format (struct v4l2_subdev *sd, +struct v4l2_subdev_state *state, +struct v4l2_subdev_format *format) +{drivers/media/i2c/imx111.c line 1137
Quoted 10 lines
drivers/media/i2c/imx111.c new file +10
-0+struct imx111 *sensor =sd_to_imx111 (sd); +struct v4l2_mbus_framefmt *mbus_fmt = &format->format; +struct v4l2_mbus_framefmt *fmt; +const struct imx111_mode *mode; + + mode =v4l2_find_nearest_size (imx111_modes,ARRAY_SIZE (imx111_modes), + width, height, + mbus_fmt->width, mbus_fmt->height); + + fmt =v4l2_subdev_state_get_format (state, format->pad);You should set the fields below after changing the controls. Albeit... it won't be perfect in that case either, as only some controls may have been applied. How about just moving the lines below after changing the controls?
Quoted 50 lines
drivers/media/i2c/imx111.c new file +50
-0+ + fmt->code =imx111_get_format_code (sensor, mbus_fmt->code, false); + fmt->width = mode->width; + fmt->height = mode->height; + fmt->colorspace =V4L2_COLORSPACE_RAW ; + + *mbus_fmt = *fmt; + +if (format->which ==V4L2_SUBDEV_FORMAT_ACTIVE ) { +int ret; + + sensor->cur_mode = mode; + sensor->data_depth =imx111_get_format_bpp (fmt); + + ret =__v4l2_ctrl_s_ctrl_int64 (sensor->pixel_rate, +div_u64 (sensor->pixel_clk_raw, +2 * + sensor->data_depth)); +if (ret) +return ret; + + ret =__v4l2_ctrl_modify_range (sensor->vblank, +IMX111_VBLANK_MIN , +IMX111_VTL_MAX - mode->height, +1 , + mode->vtl_def - mode->height); +if (ret) +return ret; + + ret =__v4l2_ctrl_s_ctrl (sensor->vblank, mode->vtl_def - + mode->height); +if (ret) +return ret; + + ret =__v4l2_ctrl_modify_range (sensor->hblank, +IMX111_HBLANK_MIN , +IMX111_HTL_MAX - mode->width, +1 , + mode->htl_def - mode->width); +if (ret) +return ret; + + ret =__v4l2_ctrl_s_ctrl (sensor->hblank, mode->htl_def - + mode->width); +if (ret) +return ret; + } + +return 0 ; +}...
Quoted 70 lines
drivers/media/i2c/imx111.c new file +70
-0+static int imx111_probe (struct i2c_client *client) +{ +struct device *dev = &client->dev; +struct imx111 *sensor; +int ret; + + sensor =devm_kzalloc (dev,sizeof (*sensor),GFP_KERNEL ); +if (!sensor) +return -ENOMEM ; + + sensor->regmap =devm_cci_regmap_init_i2c (client,16 ); +if (IS_ERR (sensor->regmap)) +return dev_err_probe (dev,PTR_ERR (sensor->regmap), +"Failed to allocate register map\n" ); + + sensor->extclk =devm_v4l2_sensor_clk_get (dev,NULL ); +if (IS_ERR (sensor->extclk)) +return dev_err_probe (dev,PTR_ERR (sensor->extclk), +"Failed to get clock\n" ); + + sensor->reset =devm_gpiod_get_optional (dev,"reset" ,GPIOD_OUT_LOW ); +if (IS_ERR (sensor->reset)) +return dev_err_probe (dev,PTR_ERR (sensor->reset), +"Failed to get reset GPIO\n" ); + + ret =devm_regulator_bulk_get_const (dev,ARRAY_SIZE (imx111_supplies), + imx111_supplies, + &sensor->supplies); +if (ret <0 ) +return dev_err_probe (dev, ret,"Failed to get regulators\n" ); + + ret =imx111_parse_dt (sensor); +if (ret <0 ) +return ret; + + ret =imx111_clk_init (sensor); +if (ret <0 ) + goto error_ep_free; + + ret =imx111_power_on (sensor); +if (ret <0 ) { +dev_err_probe (dev, ret,"Could not power on the device\n" ); + goto error_ep_free; + } + + ret =imx111_identify_module (sensor); +if (ret <0 ) { +dev_err_probe (dev, ret,"Could not identify module\n" ); + goto error_power_off; + } + + sensor->cur_mode = &imx111_modes[IMX111_MODE_3280x2464]; + sensor->data_depth =IMX111_DATA_DEPTH_RAW10 ; + + ret =imx111_initialize (sensor); +if (ret <0 ) + goto error_power_off; + + ret =imx111_init_subdev (sensor, client); +if (ret <0 ) { +dev_err (dev,"failed to init controls: %d" , ret); + goto error_v4l2_ctrl_handler_free; + } + + ret =v4l2_subdev_init_finalize (&sensor->sd); +if (ret) + goto error_v4l2_ctrl_handler_free; + +pm_runtime_set_active (dev); +pm_runtime_enable (dev);drivers/media/i2c/imx111.c line 1547
Quoted 10 lines
drivers/media/i2c/imx111.c new file +10
-0+ + ret =v4l2_async_register_subdev_sensor (&sensor->sd); +if (ret <0 ) { +dev_err (dev,"failed to register V4L2 subdev: %d" , ret); + goto error_pm; + } + +pm_runtime_idle (dev); +pm_runtime_set_autosuspend_delay (dev,1000 ); +pm_runtime_use_autosuspend (dev);The autosuspend should be set before
pm_runtime_idle()call(), shouldn't it?
Quoted 1 line
I can make the two changes before applying, too, if that's ok.
If you don't mind adjusting commit on your own before applying I have no objections. Thank you very much!
Best regards,
Svyatoslav R.
Quoted 5 lines
--
Regards,Sakari Ailus
Sakari Ailus
maintainerQuoted 5 lines · Svyatoslav Ryhel
вт, 11 лист. 2025 р. о 14:50 Sakari Ailus <[email protected]> пише:
Quoted 1 line
I can make the two changes before applying, too, if that's ok.
If you don't mind adjusting commit on your own before applying I have no objections. Thank you very much!
The diff is:
drivers/media/i2c/imx111.c +8 -8
@@ -1136,13 +1136,6 @@ static int imx111_set_format(struct v4l2_subdev *sd, fmt =v4l2_subdev_state_get_format (state, format->pad); - fmt->code =imx111_get_format_code (sensor, mbus_fmt->code, false); - fmt->width = mode->width; - fmt->height = mode->height; - fmt->colorspace =V4L2_COLORSPACE_RAW ; - - *mbus_fmt = *fmt; -if (format->which ==V4L2_SUBDEV_FORMAT_ACTIVE ) {int ret;
@@ -1183,6 +1176,13 @@ static int imx111_set_format(struct v4l2_subdev *sd,return ret; } + fmt->code =imx111_get_format_code (sensor, mbus_fmt->code, false); + fmt->width = mode->width; + fmt->height = mode->height; + fmt->colorspace =V4L2_COLORSPACE_RAW ; + + *mbus_fmt = *fmt; +return 0 ; }
@@ -1542,9 +1542,9 @@ static int imx111_probe(struct i2c_client *client) goto error_pm; } -pm_runtime_idle (dev);pm_runtime_set_autosuspend_delay (dev,1000 );pm_runtime_use_autosuspend (dev); +pm_runtime_idle (dev);return 0 ;
Hopefully that works!
Signature · 3 lines
Regards, Sakari Ailus
вт, 11 лист. 2025 р. о 15:23 Sakari Ailus <[email protected]> пише:
Quoted 53 lines · Svyatoslav Ryhel
Quoted 5 lines
вт, 11 лист. 2025 р. о 14:50 Sakari Ailus <[email protected]> пише:
Quoted 1 line
I can make the two changes before applying, too, if that's ok.
If you don't mind adjusting commit on your own before applying I have no objections. Thank you very much!
The diff is:
drivers/media/i2c/imx111.c +8
-8@@ -1136,13 +1136,6 @@ static int imx111_set_format(struct v4l2_subdev *sd, fmt =v4l2_subdev_state_get_format (state, format->pad); - fmt->code =imx111_get_format_code (sensor, mbus_fmt->code, false); - fmt->width = mode->width; - fmt->height = mode->height; - fmt->colorspace =V4L2_COLORSPACE_RAW ; - - *mbus_fmt = *fmt; -if (format->which ==V4L2_SUBDEV_FORMAT_ACTIVE ) {int ret;@@ -1183,6 +1176,13 @@ static int imx111_set_format(struct v4l2_subdev *sd,return ret; } + fmt->code =imx111_get_format_code (sensor, mbus_fmt->code, false); + fmt->width = mode->width; + fmt->height = mode->height; + fmt->colorspace =V4L2_COLORSPACE_RAW ; + + *mbus_fmt = *fmt; +return 0 ; }@@ -1542,9 +1542,9 @@ static int imx111_probe(struct i2c_client *client) goto error_pm; } -pm_runtime_idle (dev);pm_runtime_set_autosuspend_delay (dev,1000 );pm_runtime_use_autosuspend (dev); +pm_runtime_idle (dev);return 0 ;
Quoted 2 lines
Hopefully that works!
Yes, it seems to work as expected on my device. Thank you.
Quoted 4 lines
--
Regards,Sakari Ailus