media: i2c: add Sony IMX111 CMOS camera sensor driver
Subsystems (3)
v3 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
---
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 | 1548 +++++++++++++++++ 4 files changed, 1664 insertions(+) create mode 100644 Documentation/devicetree/bindings/media/i2c/sony,imx111.yaml create mode 100644 drivers/media/i2c/imx111.c
Signature · 1 line
2.48.1
PATCH v3 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.48.1
Re: [PATCH v3 1/2] dt-bindings: media: i2c: document Sony IMX111 CMOS sensor
Quoted 4 lines · Svyatoslav Ryhel
Add bindings for Sony IMX111 CMOS Digital Image Sensor found in LG Optimus 4X (P880) and Optimus Vu (P895) smartphones.
Signed-off-by Svyatoslav Ryhel <[email protected]>
pw-bot: not-applicable
PATCH v3 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 | 1548 ++++++++++++++++++++++++++++++++++++ 3 files changed, 1559 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 +1548 -0
1,548 lines not on this page · raw message
Signature · 1 line
2.48.1
Hi Svyatoslav,
Quoted 15 lines
Add 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.
Quoted 1 line
Signed-off-by Svyatoslav Ryhel <[email protected]>
---
drivers/media/i2c/imx111.c line 762
Quoted 9 lines
drivers/media/i2c/imx111.c new file +9
-0+static int imx111_set_ctrl (struct v4l2_ctrl *ctrl) +{ + struct imx111 *sensor = ctrl_to_imx111(ctrl); + struct device *dev = regmap_get_device(sensor->regmap); + s64 max; + int ret = 0; + + /* Propagate change of current control to all related controls */ + switch (ctrl->id) {
Do we need the switch statement, since only one case is present? You can use an 'if' instead.
Quoted 3 lines
+ case
V4L2_CID_VBLANK:
+ /* Update max exposure while meeting expected vblanking */ + max =sensor->cur_mode->height+ctrl->val- 5;
You can define a macro for the value 5 to improve readability. Also, make this change in the init_control function.
Quoted 3 lines
+ __v4l2_ctrl_modify_range(sensor->exposure, +
sensor->exposure->minimum, + max,sensor->exposure->step, max);
This may fail; consider adding an error check.
Quoted 76 lines
+ break;
+ }drivers/media/i2c/imx111.c new file +74
-0+ + /* + * Applying V4L2 control value only happens + * when power is up for streaming + */ + if (!pm_runtime_get_if_in_use(dev)) + return 0; + + switch (ctrl->id) { + case V4L2_CID_ANALOGUE_GAIN: + cci_write(sensor->regmap, IMX111_REG_ANALOG_GAIN, ctrl->val, &ret); + break; + case V4L2_CID_DIGITAL_GAIN: + ret = imx111_update_digital_gain(sensor, ctrl->val); + break; + case V4L2_CID_EXPOSURE: + cci_update_bits(sensor->regmap, IMX111_GROUP_WRITE, IMX111_GROUP_WRITE_ON, + IMX111_GROUP_WRITE_ON, &ret); + cci_write(sensor->regmap, IMX111_INTEGRATION_TIME, ctrl->val, &ret); + cci_update_bits(sensor->regmap, IMX111_GROUP_WRITE, IMX111_GROUP_WRITE_ON, + 0, &ret); + break; + case V4L2_CID_HBLANK: + cci_update_bits(sensor->regmap, IMX111_GROUP_WRITE, IMX111_GROUP_WRITE_ON, + IMX111_GROUP_WRITE_ON, &ret); + dev_err(dev, "writing 0x%x to HTL\n", sensor->cur_mode->width + ctrl->val); + cci_write(sensor->regmap, IMX111_HORIZONTAL_TOTAL_LENGTH, + sensor->cur_mode->width + ctrl->val, &ret); + cci_update_bits(sensor->regmap, IMX111_GROUP_WRITE, IMX111_GROUP_WRITE_ON, + 0, &ret); + break; + case V4L2_CID_VBLANK: + cci_update_bits(sensor->regmap, IMX111_GROUP_WRITE, IMX111_GROUP_WRITE_ON, + IMX111_GROUP_WRITE_ON, &ret); + dev_err(dev, "writing 0x%x to VTL\n", sensor->cur_mode->height + ctrl->val); + cci_write(sensor->regmap, IMX111_VERTICAL_TOTAL_LENGTH, + sensor->cur_mode->height + ctrl->val, &ret); + cci_update_bits(sensor->regmap, IMX111_GROUP_WRITE, IMX111_GROUP_WRITE_ON, + 0, &ret); + break; + case V4L2_CID_HFLIP: + case V4L2_CID_VFLIP: + cci_write(sensor->regmap, IMX111_IMAGE_ORIENTATION, + sensor->hflip->val | sensor->vflip->val << 1, &ret); + break; + case V4L2_CID_TEST_PATTERN: + cci_write(sensor->regmap, IMX111_TEST_PATTERN, ctrl->val, &ret); + break; + case V4L2_CID_TEST_PATTERN_RED: + cci_update_bits(sensor->regmap, IMX111_GROUP_WRITE, IMX111_GROUP_WRITE_ON, + IMX111_GROUP_WRITE_ON, &ret); + cci_write(sensor->regmap, IMX111_SOLID_COLOR_RED, ctrl->val, &ret); + cci_update_bits(sensor->regmap, IMX111_GROUP_WRITE, IMX111_GROUP_WRITE_ON, + 0, &ret); + break; + case V4L2_CID_TEST_PATTERN_GREENR: + cci_update_bits(sensor->regmap, IMX111_GROUP_WRITE, IMX111_GROUP_WRITE_ON, + IMX111_GROUP_WRITE_ON, &ret); + cci_write(sensor->regmap, IMX111_SOLID_COLOR_GR, ctrl->val, &ret); + cci_update_bits(sensor->regmap, IMX111_GROUP_WRITE, IMX111_GROUP_WRITE_ON, + 0, &ret); + break; + case V4L2_CID_TEST_PATTERN_BLUE: + cci_update_bits(sensor->regmap, IMX111_GROUP_WRITE, IMX111_GROUP_WRITE_ON, + IMX111_GROUP_WRITE_ON, &ret); + cci_write(sensor->regmap, IMX111_SOLID_COLOR_BLUE, ctrl->val, &ret); + cci_update_bits(sensor->regmap, IMX111_GROUP_WRITE, IMX111_GROUP_WRITE_ON, + 0, &ret); + break; + case V4L2_CID_TEST_PATTERN_GREENB: + cci_update_bits(sensor->regmap, IMX111_GROUP_WRITE, IMX111_GROUP_WRITE_ON, + IMX111_GROUP_WRITE_ON, &ret); + cci_write(sensor->regmap, IMX111_SOLID_COLOR_GB, ctrl->val, &ret); + cci_update_bits(sensor->regmap, IMX111_GROUP_WRITE, IMX111_GROUP_WRITE_ON,
drivers/media/i2c/imx111.c line 854
Quoted 10 lines
drivers/media/i2c/imx111.c new file +10
-0+ 0, &ret); + break; + default: + ret = -EINVAL; + } + + pm_runtime_put(dev); + + return ret; +}
---
drivers/media/i2c/imx111.c line 874
Quoted 7 lines
drivers/media/i2c/imx111.c new file +7
-0+static int imx111_init_controls (struct imx111 *sensor) +{ + const struct v4l2_ctrl_ops *ops = &imx111_ctrl_ops; + struct device *dev = regmap_get_device(sensor->regmap); + const struct imx111_mode *mode = sensor->cur_mode; + struct v4l2_fwnode_device_properties props; + struct v4l2_subdev *sd = &sensor->sd;
No need for a new variable; there is only one user in the function.
drivers/media/i2c/imx111.c line 883
Quoted 9 lines
+ struct
v4l2_ctrl_handler*hdl =&sensor->hdl;
+ s64pixel_rate_min,pixel_rate_max;
+ int i, ret;drivers/media/i2c/imx111.c new file +6
-0+ + ret = v4l2_fwnode_device_parse(dev, &props); + if (ret < 0) + return ret; + + ret = v4l2_ctrl_handler_init(hdl, 13);
Now there are 15 controls.
No need for explicit error checking; you can omit the error check if you'd like.
Quoted 63 lines
+ if (ret)
+ return ret;drivers/media/i2c/imx111.c new file +61
-0+ + pixel_rate_min = div_u64(sensor->pixel_clk_raw, 2 * IMX111_DATA_DEPTH_RAW10); + pixel_rate_max = div_u64(sensor->pixel_clk_raw, 2 * IMX111_DATA_DEPTH_RAW8); + sensor->pixel_rate = v4l2_ctrl_new_std(hdl, NULL, V4L2_CID_PIXEL_RATE, + pixel_rate_min, pixel_rate_max, + 1, div_u64(sensor->pixel_clk_raw, + 2 * sensor->data_depth)); + + sensor->link_freq = v4l2_ctrl_new_int_menu(hdl, NULL, V4L2_CID_LINK_FREQ, + 0, 0, &sensor->default_link_freq); + if (sensor->link_freq) + sensor->link_freq->flags |= V4L2_CTRL_FLAG_READ_ONLY; + + v4l2_ctrl_new_std(hdl, ops, V4L2_CID_ANALOGUE_GAIN, + IMX111_ANA_GAIN_MIN, IMX111_ANA_GAIN_MAX, + IMX111_ANA_GAIN_STEP, IMX111_ANA_GAIN_DEFAULT); + + v4l2_ctrl_new_std(hdl, ops, V4L2_CID_DIGITAL_GAIN, + IMX111_DGTL_GAIN_MIN, IMX111_DGTL_GAIN_MAX, + IMX111_DGTL_GAIN_STEP, IMX111_DGTL_GAIN_DEFAULT); + + sensor->hflip = v4l2_ctrl_new_std(hdl, ops, V4L2_CID_HFLIP, 0, 1, 1, 0); + if (sensor->hflip) + sensor->hflip->flags |= V4L2_CTRL_FLAG_MODIFY_LAYOUT; + + sensor->vflip = v4l2_ctrl_new_std(hdl, ops, V4L2_CID_VFLIP, 0, 1, 1, 0); + if (sensor->vflip) + sensor->vflip->flags |= V4L2_CTRL_FLAG_MODIFY_LAYOUT; + + sensor->vblank = v4l2_ctrl_new_std(hdl, ops, V4L2_CID_VBLANK, IMX111_VBLANK_MIN, + IMX111_VTL_MAX - mode->height, 1, + mode->vtl_def - mode->height); + sensor->hblank = v4l2_ctrl_new_std(hdl, ops, V4L2_CID_HBLANK, IMX111_HBLANK_MIN, + IMX111_HTL_MAX - mode->width, 1, + mode->htl_def - mode->width); + + /* + * The maximum coarse integration time is the frame length in lines + * minus five. + */ + sensor->exposure = v4l2_ctrl_new_std(hdl, ops, V4L2_CID_EXPOSURE, + IMX111_INTEGRATION_TIME_MIN, + IMX111_PIXEL_ARRAY_HEIGHT - 5, + IMX111_INTEGRATION_TIME_STEP, + IMX111_PIXEL_ARRAY_HEIGHT - 5); + + v4l2_ctrl_new_fwnode_properties(hdl, ops, &props); + + v4l2_ctrl_new_std_menu_items(hdl, ops, V4L2_CID_TEST_PATTERN, + ARRAY_SIZE(test_pattern_menu) - 1, 0, 0, + test_pattern_menu); + for (i = 0; i < 4; i++) { + /* + * The assumption is that + * V4L2_CID_TEST_PATTERN_GREENR == V4L2_CID_TEST_PATTERN_RED + 1 + * V4L2_CID_TEST_PATTERN_BLUE == V4L2_CID_TEST_PATTERN_RED + 2 + * V4L2_CID_TEST_PATTERN_GREENB == V4L2_CID_TEST_PATTERN_RED + 3 + */ + v4l2_ctrl_new_std(hdl, ops, V4L2_CID_TEST_PATTERN_RED + i, + IMX111_TESTP_COLOUR_MIN, IMX111_TESTP_COLOUR_MAX, + IMX111_TESTP_COLOUR_STEP, IMX111_TESTP_COLOUR_MAX);
drivers/media/i2c/imx111.c line 956
Quoted 10 lines
drivers/media/i2c/imx111.c new file +10
-0+ /* The "Solid color" pattern is white by default */ + } + + if (hdl->error) + return hdl->error; + + sd->ctrl_handler = hdl; + + return 0; +};
---
drivers/media/i2c/imx111.c line 1034
Quoted 4 lines
drivers/media/i2c/imx111.c new file +4
-0+static int imx111_initialize (struct imx111 *sensor) +{ + struct device *dev = regmap_get_device(sensor->regmap); + int ret;
ret = 0;
drivers/media/i2c/imx111.c line 1045
Quoted 11 lines
drivers/media/i2c/imx111.c new file +11
-0+ + /* Configure the PLL. */ + cci_write(sensor->regmap, IMX111_PRE_PLL_CLK_DIVIDER_PLL1, + sensor->pll->pre_div, &ret); + cci_write(sensor->regmap, IMX111_PLL_MULTIPLIER_PLL1, sensor->pll->mult, &ret); + cci_write(sensor->regmap, IMX111_POST_DIVIDER, IMX111_POST_DIVIDER_DIV1, &ret); + cci_write(sensor->regmap, IMX111_PLL_SETTLING_TIME, + to_settle_delay(sensor->pll->extclk_rate), &ret); + + ret = cci_multi_reg_write(sensor->regmap, imx111_global_init, + ARRAY_SIZE(imx111_global_init), NULL);
You are overwriting the previous errors.
please use ret |=
drivers/media/i2c/imx111.c line 977
Quoted 7 lines
+ if (ret < 0) {
+ dev_err(dev, "Failed to initialize the sensor\n"); + return ret;
+ }drivers/media/i2c/imx111.c new file +3
-0+ + return 0; +}
---
Quoted 27 lines
drivers/media/i2c/imx111.c new file +27
-0+static int imx111_set_format (struct v4l2_subdev *sd, + struct v4l2_subdev_state *state, + struct v4l2_subdev_format *format) +{ + 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); + + 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) { + sensor->cur_mode = mode; + sensor->data_depth = imx111_get_format_bpp(fmt); + __v4l2_ctrl_s_ctrl_int64(sensor->pixel_rate, + div_u64(sensor->pixel_clk_raw, 2 * sensor->data_depth));
drivers/media/i2c/imx111.c line 1129
Quoted 10 lines
drivers/media/i2c/imx111.c new file +10
-0+ + __v4l2_ctrl_modify_range(sensor->vblank, IMX111_VBLANK_MIN, + IMX111_VTL_MAX - mode->height, 1, + mode->vtl_def - mode->height); + __v4l2_ctrl_s_ctrl(sensor->vblank, mode->vtl_def - mode->height); + + __v4l2_ctrl_modify_range(sensor->hblank, IMX111_HBLANK_MIN, + IMX111_HTL_MAX - mode->width, 1, + mode->htl_def - mode->width); + __v4l2_ctrl_s_ctrl(sensor->hblank, mode->htl_def - mode->width);
All the above V4L2 operations need to check for errors.
drivers/media/i2c/imx111.c line 977
Quoted 4 lines
+ }
drivers/media/i2c/imx111.c new file +3
-0+ + return 0; +}
---
Quoted 7 lines
drivers/media/i2c/imx111.c new file +7
-0+static int imx111_identify_module (struct imx111 *sensor) +{ + struct device *dev = regmap_get_device(sensor->regmap); + u64 value, revision, manufacturer; + int ret; + + ret = cci_read(sensor->regmap, IMX111_PRODUCT_ID, &value, NULL);
drivers/media/i2c/imx111.c line 1319
Quoted 10 lines
drivers/media/i2c/imx111.c new file +10
-0+ if (ret) + return ret; + + if (value != IMX111_CHIP_ID) { + dev_err(dev, "chip id mismatch: %x!=%04llx", IMX111_CHIP_ID, value); + return -ENXIO; + } + + cci_read(sensor->regmap, IMX111_REVISION, &revision, NULL); + cci_read(sensor->regmap, IMX111_MANUFACTURER_ID, &manufacturer, NULL);
Instead of NULL, pass ret for the error code, and return ret at the end.
Quoted 16 lines
drivers/media/i2c/imx111.c new file +16
-0+ + dev_dbg(dev, "module IMX%03llx rev. %llu manufacturer %llu\n", + value, revision, manufacturer); + + return 0; +} + +static int imx111_clk_init (struct imx111 *sensor) +{ + struct device *dev = regmap_get_device(sensor->regmap); + u32 ndata_lanes = sensor->bus_cfg.bus.mipi_csi2.num_data_lanes; + u64 extclk_rate, system_clk; + unsigned int i; + + extclk_rate = clk_get_rate(sensor->extclk); + if (!extclk_rate)
drivers/media/i2c/imx111.c line 1345
Quoted 10 lines
drivers/media/i2c/imx111.c new file +10
-0+ return dev_err_probe(dev, -EINVAL, "EXTCLK rate unknown\n"); + + for (i = 0; i < ARRAY_SIZE(imx111_pll); i++) { + if (clk_get_rate(sensor->extclk) == imx111_pll[i].extclk_rate) { + sensor->pll = &imx111_pll[i]; + break; + } + } + if (!sensor->pll) + return dev_err_probe(dev, -EINVAL, "Unsupported EXTCLK rate %llu\n", extclk_rate);
Max line length should be 80 columns. This applies everywhere the line length exceeds 80 characters.
Quoted 16 lines
drivers/media/i2c/imx111.c new file +16
-0+ + system_clk = div_u64(extclk_rate, sensor->pll->pre_div) * sensor->pll->mult; + + /* + * Pixel clock or Logic clock is used for internal image processing is + * generated by dividing into 1/10 or 1/8 frequency according to the + * word length of the CSI2 interface. This clock is designating the pixel + * rate and used as the base of integration time, frame rate etc. + */ + sensor->pixel_clk_raw = system_clk * ndata_lanes; + + /* + * The CSI-2 bus is clocked for 16-bit per pixel, transmitted in DDR over n lanes + * for RAW10 default format. + */ + sensor->default_link_freq = div_u64(sensor->pixel_clk_raw * 8,
drivers/media/i2c/imx111.c line 1371
Quoted 10 lines
drivers/media/i2c/imx111.c new file +10
-0+ 2 * IMX111_DATA_DEPTH_RAW10); + + if (sensor->bus_cfg.nr_of_link_frequencies != 1 || + sensor->bus_cfg.link_frequencies[0] != sensor->default_link_freq) + return dev_err_probe(dev, -EINVAL, + "Unsupported DT link-frequencies, expected %llu\n", + sensor->default_link_freq); + + return 0; +}
---
Quoted 10 lines
drivers/media/i2c/imx111.c new file +10
-0+static const struct of_device_id imx111_of_match[] = { + { .compatible = "sony,imx111" }, + { /* sentinel */ } +}; +MODULE_DEVICE_TABLE (of, imx111_of_match); + +static struct i2c_driver imx111_i2c_driver = { + .driver = { + .name = "imx111", + .of_match_table = imx111_of_match,
drivers/media/i2c/imx111.c line 1548
Quoted 10 lines
drivers/media/i2c/imx111.c new file +10
-0+ .pm = &imx111_pm_ops, + }, + .probe = imx111_probe, + .remove = imx111_remove, +}; +module_i2c_driver (imx111_i2c_driver); + +MODULE_AUTHOR ("Svyatoslav Ryhel <[email protected]>" ); +MODULE_DESCRIPTION ("Sony IMX111 CMOS Image Sensor driver" ); +MODULE_LICENSE ("GPL" );
Best Regards,
Tarang
чт, 30 жовт. 2025 р. о 16:55 Tarang Raval <[email protected]> пише:
Quoted 358 lines
Hi Svyatoslav,
Quoted 10 lines
Add 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 SGBRG8Quoted 6 lines
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.
Signed-off-by Svyatoslav Ryhel <[email protected]>---
drivers/media/i2c/imx111.c line 762
Quoted 9 lines
drivers/media/i2c/imx111.c new file +9
-0+static int imx111_set_ctrl (struct v4l2_ctrl *ctrl) +{ + struct imx111 *sensor = ctrl_to_imx111(ctrl); + struct device *dev = regmap_get_device(sensor->regmap); + s64 max; + int ret = 0; + + /* Propagate change of current control to all related controls */ + switch (ctrl->id) {Do we need the switch statement, since only one case is present? You can use an 'if' instead.
Quoted 3 lines
+ case
V4L2_CID_VBLANK:
+ /* Update max exposure while meeting expected vblanking */ + max =sensor->cur_mode->height+ctrl->val- 5;You can define a macro for the value 5 to improve readability. Also, make this change in the
init_controlfunction.Quoted 3 lines
+ __v4l2_ctrl_modify_range(sensor->exposure, +
sensor->exposure->minimum, + max,sensor->exposure->step, max);This may fail; consider adding an error check.
Quoted 76 lines
+ break;
+ }drivers/media/i2c/imx111.c new file +74
-0+ + /* + * Applying V4L2 control value only happens + * when power is up for streaming + */ + if (!pm_runtime_get_if_in_use(dev)) + return 0; + + switch (ctrl->id) { + case V4L2_CID_ANALOGUE_GAIN: + cci_write(sensor->regmap, IMX111_REG_ANALOG_GAIN, ctrl->val, &ret); + break; + case V4L2_CID_DIGITAL_GAIN: + ret = imx111_update_digital_gain(sensor, ctrl->val); + break; + case V4L2_CID_EXPOSURE: + cci_update_bits(sensor->regmap, IMX111_GROUP_WRITE, IMX111_GROUP_WRITE_ON, + IMX111_GROUP_WRITE_ON, &ret); + cci_write(sensor->regmap, IMX111_INTEGRATION_TIME, ctrl->val, &ret); + cci_update_bits(sensor->regmap, IMX111_GROUP_WRITE, IMX111_GROUP_WRITE_ON, + 0, &ret); + break; + case V4L2_CID_HBLANK: + cci_update_bits(sensor->regmap, IMX111_GROUP_WRITE, IMX111_GROUP_WRITE_ON, + IMX111_GROUP_WRITE_ON, &ret); + dev_err(dev, "writing 0x%x to HTL\n", sensor->cur_mode->width + ctrl->val); + cci_write(sensor->regmap, IMX111_HORIZONTAL_TOTAL_LENGTH, + sensor->cur_mode->width + ctrl->val, &ret); + cci_update_bits(sensor->regmap, IMX111_GROUP_WRITE, IMX111_GROUP_WRITE_ON, + 0, &ret); + break; + case V4L2_CID_VBLANK: + cci_update_bits(sensor->regmap, IMX111_GROUP_WRITE, IMX111_GROUP_WRITE_ON, + IMX111_GROUP_WRITE_ON, &ret); + dev_err(dev, "writing 0x%x to VTL\n", sensor->cur_mode->height + ctrl->val); + cci_write(sensor->regmap, IMX111_VERTICAL_TOTAL_LENGTH, + sensor->cur_mode->height + ctrl->val, &ret); + cci_update_bits(sensor->regmap, IMX111_GROUP_WRITE, IMX111_GROUP_WRITE_ON, + 0, &ret); + break; + case V4L2_CID_HFLIP: + case V4L2_CID_VFLIP: + cci_write(sensor->regmap, IMX111_IMAGE_ORIENTATION, + sensor->hflip->val | sensor->vflip->val << 1, &ret); + break; + case V4L2_CID_TEST_PATTERN: + cci_write(sensor->regmap, IMX111_TEST_PATTERN, ctrl->val, &ret); + break; + case V4L2_CID_TEST_PATTERN_RED: + cci_update_bits(sensor->regmap, IMX111_GROUP_WRITE, IMX111_GROUP_WRITE_ON, + IMX111_GROUP_WRITE_ON, &ret); + cci_write(sensor->regmap, IMX111_SOLID_COLOR_RED, ctrl->val, &ret); + cci_update_bits(sensor->regmap, IMX111_GROUP_WRITE, IMX111_GROUP_WRITE_ON, + 0, &ret); + break; + case V4L2_CID_TEST_PATTERN_GREENR: + cci_update_bits(sensor->regmap, IMX111_GROUP_WRITE, IMX111_GROUP_WRITE_ON, + IMX111_GROUP_WRITE_ON, &ret); + cci_write(sensor->regmap, IMX111_SOLID_COLOR_GR, ctrl->val, &ret); + cci_update_bits(sensor->regmap, IMX111_GROUP_WRITE, IMX111_GROUP_WRITE_ON, + 0, &ret); + break; + case V4L2_CID_TEST_PATTERN_BLUE: + cci_update_bits(sensor->regmap, IMX111_GROUP_WRITE, IMX111_GROUP_WRITE_ON, + IMX111_GROUP_WRITE_ON, &ret); + cci_write(sensor->regmap, IMX111_SOLID_COLOR_BLUE, ctrl->val, &ret); + cci_update_bits(sensor->regmap, IMX111_GROUP_WRITE, IMX111_GROUP_WRITE_ON, + 0, &ret); + break; + case V4L2_CID_TEST_PATTERN_GREENB: + cci_update_bits(sensor->regmap, IMX111_GROUP_WRITE, IMX111_GROUP_WRITE_ON, + IMX111_GROUP_WRITE_ON, &ret); + cci_write(sensor->regmap, IMX111_SOLID_COLOR_GB, ctrl->val, &ret); + cci_update_bits(sensor->regmap, IMX111_GROUP_WRITE, IMX111_GROUP_WRITE_ON,drivers/media/i2c/imx111.c line 854
Quoted 10 lines
drivers/media/i2c/imx111.c new file +10
-0+ 0, &ret); + break; + default: + ret = -EINVAL; + } + + pm_runtime_put(dev); + + return ret; +}---
drivers/media/i2c/imx111.c line 874
Quoted 7 lines
drivers/media/i2c/imx111.c new file +7
-0+static int imx111_init_controls (struct imx111 *sensor) +{ + const struct v4l2_ctrl_ops *ops = &imx111_ctrl_ops; + struct device *dev = regmap_get_device(sensor->regmap); + const struct imx111_mode *mode = sensor->cur_mode; + struct v4l2_fwnode_device_properties props; + struct v4l2_subdev *sd = &sensor->sd;No need for a new variable; there is only one user in the function.
drivers/media/i2c/imx111.c line 883
Quoted 9 lines
+ struct
v4l2_ctrl_handler*hdl =&sensor->hdl;
+ s64pixel_rate_min,pixel_rate_max;
+ int i, ret;drivers/media/i2c/imx111.c new file +6
-0+ + ret = v4l2_fwnode_device_parse(dev, &props); + if (ret < 0) + return ret; + + ret = v4l2_ctrl_handler_init(hdl, 13);Now there are 15 controls.
No need for explicit error checking; you can omit the error check if you'd like.
Quoted 63 lines
+ if (ret)
+ return ret;drivers/media/i2c/imx111.c new file +61
-0+ + pixel_rate_min = div_u64(sensor->pixel_clk_raw, 2 * IMX111_DATA_DEPTH_RAW10); + pixel_rate_max = div_u64(sensor->pixel_clk_raw, 2 * IMX111_DATA_DEPTH_RAW8); + sensor->pixel_rate = v4l2_ctrl_new_std(hdl, NULL, V4L2_CID_PIXEL_RATE, + pixel_rate_min, pixel_rate_max, + 1, div_u64(sensor->pixel_clk_raw, + 2 * sensor->data_depth)); + + sensor->link_freq = v4l2_ctrl_new_int_menu(hdl, NULL, V4L2_CID_LINK_FREQ, + 0, 0, &sensor->default_link_freq); + if (sensor->link_freq) + sensor->link_freq->flags |= V4L2_CTRL_FLAG_READ_ONLY; + + v4l2_ctrl_new_std(hdl, ops, V4L2_CID_ANALOGUE_GAIN, + IMX111_ANA_GAIN_MIN, IMX111_ANA_GAIN_MAX, + IMX111_ANA_GAIN_STEP, IMX111_ANA_GAIN_DEFAULT); + + v4l2_ctrl_new_std(hdl, ops, V4L2_CID_DIGITAL_GAIN, + IMX111_DGTL_GAIN_MIN, IMX111_DGTL_GAIN_MAX, + IMX111_DGTL_GAIN_STEP, IMX111_DGTL_GAIN_DEFAULT); + + sensor->hflip = v4l2_ctrl_new_std(hdl, ops, V4L2_CID_HFLIP, 0, 1, 1, 0); + if (sensor->hflip) + sensor->hflip->flags |= V4L2_CTRL_FLAG_MODIFY_LAYOUT; + + sensor->vflip = v4l2_ctrl_new_std(hdl, ops, V4L2_CID_VFLIP, 0, 1, 1, 0); + if (sensor->vflip) + sensor->vflip->flags |= V4L2_CTRL_FLAG_MODIFY_LAYOUT; + + sensor->vblank = v4l2_ctrl_new_std(hdl, ops, V4L2_CID_VBLANK, IMX111_VBLANK_MIN, + IMX111_VTL_MAX - mode->height, 1, + mode->vtl_def - mode->height); + sensor->hblank = v4l2_ctrl_new_std(hdl, ops, V4L2_CID_HBLANK, IMX111_HBLANK_MIN, + IMX111_HTL_MAX - mode->width, 1, + mode->htl_def - mode->width); + + /* + * The maximum coarse integration time is the frame length in lines + * minus five. + */ + sensor->exposure = v4l2_ctrl_new_std(hdl, ops, V4L2_CID_EXPOSURE, + IMX111_INTEGRATION_TIME_MIN, + IMX111_PIXEL_ARRAY_HEIGHT - 5, + IMX111_INTEGRATION_TIME_STEP, + IMX111_PIXEL_ARRAY_HEIGHT - 5); + + v4l2_ctrl_new_fwnode_properties(hdl, ops, &props); + + v4l2_ctrl_new_std_menu_items(hdl, ops, V4L2_CID_TEST_PATTERN, + ARRAY_SIZE(test_pattern_menu) - 1, 0, 0, + test_pattern_menu); + for (i = 0; i < 4; i++) { + /* + * The assumption is that + * V4L2_CID_TEST_PATTERN_GREENR == V4L2_CID_TEST_PATTERN_RED + 1 + * V4L2_CID_TEST_PATTERN_BLUE == V4L2_CID_TEST_PATTERN_RED + 2 + * V4L2_CID_TEST_PATTERN_GREENB == V4L2_CID_TEST_PATTERN_RED + 3 + */ + v4l2_ctrl_new_std(hdl, ops, V4L2_CID_TEST_PATTERN_RED + i, + IMX111_TESTP_COLOUR_MIN, IMX111_TESTP_COLOUR_MAX, + IMX111_TESTP_COLOUR_STEP, IMX111_TESTP_COLOUR_MAX);drivers/media/i2c/imx111.c line 956
Quoted 10 lines
drivers/media/i2c/imx111.c new file +10
-0+ /* The "Solid color" pattern is white by default */ + } + + if (hdl->error) + return hdl->error; + + sd->ctrl_handler = hdl; + + return 0; +};---
drivers/media/i2c/imx111.c line 1034
Quoted 4 lines
drivers/media/i2c/imx111.c new file +4
-0+static int imx111_initialize (struct imx111 *sensor) +{ + struct device *dev = regmap_get_device(sensor->regmap); + int ret;ret = 0;
drivers/media/i2c/imx111.c line 1045
Quoted 11 lines
drivers/media/i2c/imx111.c new file +11
-0+ + /* Configure the PLL. */ + cci_write(sensor->regmap, IMX111_PRE_PLL_CLK_DIVIDER_PLL1, + sensor->pll->pre_div, &ret); + cci_write(sensor->regmap, IMX111_PLL_MULTIPLIER_PLL1, sensor->pll->mult, &ret); + cci_write(sensor->regmap, IMX111_POST_DIVIDER, IMX111_POST_DIVIDER_DIV1, &ret); + cci_write(sensor->regmap, IMX111_PLL_SETTLING_TIME, + to_settle_delay(sensor->pll->extclk_rate), &ret); + + ret = cci_multi_reg_write(sensor->regmap, imx111_global_init, + ARRAY_SIZE(imx111_global_init), NULL);You are overwriting the previous errors.
please use ret |=
drivers/media/i2c/imx111.c line 977
Quoted 7 lines
+ if (ret < 0) {
+ dev_err(dev, "Failed to initialize the sensor\n"); + return ret;
+ }drivers/media/i2c/imx111.c new file +3
-0+ + return 0; +}---
Quoted 27 lines
drivers/media/i2c/imx111.c new file +27
-0+static int imx111_set_format (struct v4l2_subdev *sd, + struct v4l2_subdev_state *state, + struct v4l2_subdev_format *format) +{ + 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); + + 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) { + sensor->cur_mode = mode; + sensor->data_depth = imx111_get_format_bpp(fmt); + __v4l2_ctrl_s_ctrl_int64(sensor->pixel_rate, + div_u64(sensor->pixel_clk_raw, 2 * sensor->data_depth));drivers/media/i2c/imx111.c line 1129
Quoted 10 lines
drivers/media/i2c/imx111.c new file +10
-0+ + __v4l2_ctrl_modify_range(sensor->vblank, IMX111_VBLANK_MIN, + IMX111_VTL_MAX - mode->height, 1, + mode->vtl_def - mode->height); + __v4l2_ctrl_s_ctrl(sensor->vblank, mode->vtl_def - mode->height); + + __v4l2_ctrl_modify_range(sensor->hblank, IMX111_HBLANK_MIN, + IMX111_HTL_MAX - mode->width, 1, + mode->htl_def - mode->width); + __v4l2_ctrl_s_ctrl(sensor->hblank, mode->htl_def - mode->width);All the above V4L2 operations need to check for errors.
drivers/media/i2c/imx111.c line 977
Quoted 4 lines
+ }
drivers/media/i2c/imx111.c new file +3
-0+ + return 0; +}---
Quoted 7 lines
drivers/media/i2c/imx111.c new file +7
-0+static int imx111_identify_module (struct imx111 *sensor) +{ + struct device *dev = regmap_get_device(sensor->regmap); + u64 value, revision, manufacturer; + int ret; + + ret = cci_read(sensor->regmap, IMX111_PRODUCT_ID, &value, NULL);drivers/media/i2c/imx111.c line 1319
Quoted 10 lines
drivers/media/i2c/imx111.c new file +10
-0+ if (ret) + return ret; + + if (value != IMX111_CHIP_ID) { + dev_err(dev, "chip id mismatch: %x!=%04llx", IMX111_CHIP_ID, value); + return -ENXIO; + } + + cci_read(sensor->regmap, IMX111_REVISION, &revision, NULL); + cci_read(sensor->regmap, IMX111_MANUFACTURER_ID, &manufacturer, NULL);Instead of NULL, pass ret for the error code, and return ret at the end.
Quoted 21 lines
drivers/media/i2c/imx111.c new file +21
-0+ + dev_dbg(dev, "module IMX%03llx rev. %llu manufacturer %llu\n", + value, revision, manufacturer); + + return 0; +} + +static int imx111_clk_init (struct imx111 *sensor) +{ + struct device *dev = regmap_get_device(sensor->regmap); + u32 ndata_lanes = sensor->bus_cfg.bus.mipi_csi2.num_data_lanes; + u64 extclk_rate, system_clk; + unsigned int i; + + extclk_rate = clk_get_rate(sensor->extclk); + if (!extclk_rate) + return dev_err_probe(dev, -EINVAL, "EXTCLK rate unknown\n"); + + for (i = 0; i < ARRAY_SIZE(imx111_pll); i++) { + if (clk_get_rate(sensor->extclk) == imx111_pll[i].extclk_rate) { + sensor->pll = &imx111_pll[i];
Quoted 9 lines
Quoted 5 lines
+ break;
+ }
+ }
+ if (!sensor->pll)
+ returndev_err_probe(dev, -EINVAL, "Unsupported EXTCLK rate %llu\n", extclk_rate);Max line length should be 80 columns. This applies everywhere the line length exceeds 80 characters.
80 character line is not enforced, checkpatch.pl does not complain. Consider sending patch to checkpatch.pl if you don't like this.
Quoted 52 lines
Quoted 16 lines
drivers/media/i2c/imx111.c new file +16
-0+ + system_clk = div_u64(extclk_rate, sensor->pll->pre_div) * sensor->pll->mult; + + /* + * Pixel clock or Logic clock is used for internal image processing is + * generated by dividing into 1/10 or 1/8 frequency according to the + * word length of the CSI2 interface. This clock is designating the pixel + * rate and used as the base of integration time, frame rate etc. + */ + sensor->pixel_clk_raw = system_clk * ndata_lanes; + + /* + * The CSI-2 bus is clocked for 16-bit per pixel, transmitted in DDR over n lanes + * for RAW10 default format. + */ + sensor->default_link_freq = div_u64(sensor->pixel_clk_raw * 8,drivers/media/i2c/imx111.c line 1371
Quoted 10 lines
drivers/media/i2c/imx111.c new file +10
-0+ 2 * IMX111_DATA_DEPTH_RAW10); + + if (sensor->bus_cfg.nr_of_link_frequencies != 1 || + sensor->bus_cfg.link_frequencies[0] != sensor->default_link_freq) + return dev_err_probe(dev, -EINVAL, + "Unsupported DT link-frequencies, expected %llu\n", + sensor->default_link_freq); + + return 0; +}---
Quoted 10 lines
drivers/media/i2c/imx111.c new file +10
-0+static const struct of_device_id imx111_of_match[] = { + { .compatible = "sony,imx111" }, + { /* sentinel */ } +}; +MODULE_DEVICE_TABLE (of, imx111_of_match); + +static struct i2c_driver imx111_i2c_driver = { + .driver = { + .name = "imx111", + .of_match_table = imx111_of_match,drivers/media/i2c/imx111.c line 1548
Quoted 10 lines
drivers/media/i2c/imx111.c new file +10
-0+ .pm = &imx111_pm_ops, + }, + .probe = imx111_probe, + .remove = imx111_remove, +}; +module_i2c_driver (imx111_i2c_driver); + +MODULE_AUTHOR ("Svyatoslav Ryhel <[email protected]>" ); +MODULE_DESCRIPTION ("Sony IMX111 CMOS Image Sensor driver" ); +MODULE_LICENSE ("GPL" );Best Regards,
Tarang
чт, 30 жовт. 2025 р. о 16:55 Tarang Raval <[email protected]> пише:
Quoted 22 lines
Hi Svyatoslav,
Quoted 10 lines
Add 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 SGBRG8Quoted 6 lines
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.
Signed-off-by Svyatoslav Ryhel <[email protected]>---
Quoted 13 lines
drivers/media/i2c/imx111.c line 762
Quoted 9 lines
drivers/media/i2c/imx111.c new file +9
-0+static int imx111_set_ctrl (struct v4l2_ctrl *ctrl) +{ + struct imx111 *sensor = ctrl_to_imx111(ctrl); + struct device *dev = regmap_get_device(sensor->regmap); + s64 max; + int ret = 0; + + /* Propagate change of current control to all related controls */ + switch (ctrl->id) {Do we need the switch statement, since only one case is present? You can use an 'if' instead.
imx219 and imx319 which are recommended references use switch, and it seems that media maintainters are particularly picky to code style, I have copied it from there.
Quoted 7 lines
Quoted 3 lines
+ case
V4L2_CID_VBLANK:
+ /* Update max exposure while meeting expected vblanking */ + max =sensor->cur_mode->height+ctrl->val- 5;You can define a macro for the value 5 to improve readability. Also, make this change in the
init_controlfunction.
imx219 does not specifies this as a define
Quoted 6 lines
Quoted 3 lines
+ __v4l2_ctrl_modify_range(sensor->exposure, +
sensor->exposure->minimum, + max,sensor->exposure->step, max);This may fail; consider adding an error check.
imx219 does not return error here too
Quoted 89 lines
Quoted 76 lines
+ break;
+ }drivers/media/i2c/imx111.c new file +74
-0+ + /* + * Applying V4L2 control value only happens + * when power is up for streaming + */ + if (!pm_runtime_get_if_in_use(dev)) + return 0; + + switch (ctrl->id) { + case V4L2_CID_ANALOGUE_GAIN: + cci_write(sensor->regmap, IMX111_REG_ANALOG_GAIN, ctrl->val, &ret); + break; + case V4L2_CID_DIGITAL_GAIN: + ret = imx111_update_digital_gain(sensor, ctrl->val); + break; + case V4L2_CID_EXPOSURE: + cci_update_bits(sensor->regmap, IMX111_GROUP_WRITE, IMX111_GROUP_WRITE_ON, + IMX111_GROUP_WRITE_ON, &ret); + cci_write(sensor->regmap, IMX111_INTEGRATION_TIME, ctrl->val, &ret); + cci_update_bits(sensor->regmap, IMX111_GROUP_WRITE, IMX111_GROUP_WRITE_ON, + 0, &ret); + break; + case V4L2_CID_HBLANK: + cci_update_bits(sensor->regmap, IMX111_GROUP_WRITE, IMX111_GROUP_WRITE_ON, + IMX111_GROUP_WRITE_ON, &ret); + dev_err(dev, "writing 0x%x to HTL\n", sensor->cur_mode->width + ctrl->val); + cci_write(sensor->regmap, IMX111_HORIZONTAL_TOTAL_LENGTH, + sensor->cur_mode->width + ctrl->val, &ret); + cci_update_bits(sensor->regmap, IMX111_GROUP_WRITE, IMX111_GROUP_WRITE_ON, + 0, &ret); + break; + case V4L2_CID_VBLANK: + cci_update_bits(sensor->regmap, IMX111_GROUP_WRITE, IMX111_GROUP_WRITE_ON, + IMX111_GROUP_WRITE_ON, &ret); + dev_err(dev, "writing 0x%x to VTL\n", sensor->cur_mode->height + ctrl->val); + cci_write(sensor->regmap, IMX111_VERTICAL_TOTAL_LENGTH, + sensor->cur_mode->height + ctrl->val, &ret); + cci_update_bits(sensor->regmap, IMX111_GROUP_WRITE, IMX111_GROUP_WRITE_ON, + 0, &ret); + break; + case V4L2_CID_HFLIP: + case V4L2_CID_VFLIP: + cci_write(sensor->regmap, IMX111_IMAGE_ORIENTATION, + sensor->hflip->val | sensor->vflip->val << 1, &ret); + break; + case V4L2_CID_TEST_PATTERN: + cci_write(sensor->regmap, IMX111_TEST_PATTERN, ctrl->val, &ret); + break; + case V4L2_CID_TEST_PATTERN_RED: + cci_update_bits(sensor->regmap, IMX111_GROUP_WRITE, IMX111_GROUP_WRITE_ON, + IMX111_GROUP_WRITE_ON, &ret); + cci_write(sensor->regmap, IMX111_SOLID_COLOR_RED, ctrl->val, &ret); + cci_update_bits(sensor->regmap, IMX111_GROUP_WRITE, IMX111_GROUP_WRITE_ON, + 0, &ret); + break; + case V4L2_CID_TEST_PATTERN_GREENR: + cci_update_bits(sensor->regmap, IMX111_GROUP_WRITE, IMX111_GROUP_WRITE_ON, + IMX111_GROUP_WRITE_ON, &ret); + cci_write(sensor->regmap, IMX111_SOLID_COLOR_GR, ctrl->val, &ret); + cci_update_bits(sensor->regmap, IMX111_GROUP_WRITE, IMX111_GROUP_WRITE_ON, + 0, &ret); + break; + case V4L2_CID_TEST_PATTERN_BLUE: + cci_update_bits(sensor->regmap, IMX111_GROUP_WRITE, IMX111_GROUP_WRITE_ON, + IMX111_GROUP_WRITE_ON, &ret); + cci_write(sensor->regmap, IMX111_SOLID_COLOR_BLUE, ctrl->val, &ret); + cci_update_bits(sensor->regmap, IMX111_GROUP_WRITE, IMX111_GROUP_WRITE_ON, + 0, &ret); + break; + case V4L2_CID_TEST_PATTERN_GREENB: + cci_update_bits(sensor->regmap, IMX111_GROUP_WRITE, IMX111_GROUP_WRITE_ON, + IMX111_GROUP_WRITE_ON, &ret); + cci_write(sensor->regmap, IMX111_SOLID_COLOR_GB, ctrl->val, &ret); + cci_update_bits(sensor->regmap, IMX111_GROUP_WRITE, IMX111_GROUP_WRITE_ON,drivers/media/i2c/imx111.c line 854
Quoted 10 lines
drivers/media/i2c/imx111.c new file +10
-0+ 0, &ret); + break; + default: + ret = -EINVAL; + } + + pm_runtime_put(dev); + + return ret; +}---
Quoted 10 lines
drivers/media/i2c/imx111.c line 874
Quoted 7 lines
drivers/media/i2c/imx111.c new file +7
-0+static int imx111_init_controls (struct imx111 *sensor) +{ + const struct v4l2_ctrl_ops *ops = &imx111_ctrl_ops; + struct device *dev = regmap_get_device(sensor->regmap); + const struct imx111_mode *mode = sensor->cur_mode; + struct v4l2_fwnode_device_properties props; + struct v4l2_subdev *sd = &sensor->sd;No need for a new variable; there is only one user in the function.
This make code reading cleaner, no?
Quoted 90 lines
drivers/media/i2c/imx111.c line 883
Quoted 9 lines
+ struct
v4l2_ctrl_handler*hdl =&sensor->hdl;
+ s64pixel_rate_min,pixel_rate_max;
+ int i, ret;drivers/media/i2c/imx111.c new file +6
-0+ + ret = v4l2_fwnode_device_parse(dev, &props); + if (ret < 0) + return ret; + + ret = v4l2_ctrl_handler_init(hdl, 13);Now there are 15 controls.
No need for explicit error checking; you can omit the error check if you'd like.
Quoted 63 lines
+ if (ret)
+ return ret;drivers/media/i2c/imx111.c new file +61
-0+ + pixel_rate_min = div_u64(sensor->pixel_clk_raw, 2 * IMX111_DATA_DEPTH_RAW10); + pixel_rate_max = div_u64(sensor->pixel_clk_raw, 2 * IMX111_DATA_DEPTH_RAW8); + sensor->pixel_rate = v4l2_ctrl_new_std(hdl, NULL, V4L2_CID_PIXEL_RATE, + pixel_rate_min, pixel_rate_max, + 1, div_u64(sensor->pixel_clk_raw, + 2 * sensor->data_depth)); + + sensor->link_freq = v4l2_ctrl_new_int_menu(hdl, NULL, V4L2_CID_LINK_FREQ, + 0, 0, &sensor->default_link_freq); + if (sensor->link_freq) + sensor->link_freq->flags |= V4L2_CTRL_FLAG_READ_ONLY; + + v4l2_ctrl_new_std(hdl, ops, V4L2_CID_ANALOGUE_GAIN, + IMX111_ANA_GAIN_MIN, IMX111_ANA_GAIN_MAX, + IMX111_ANA_GAIN_STEP, IMX111_ANA_GAIN_DEFAULT); + + v4l2_ctrl_new_std(hdl, ops, V4L2_CID_DIGITAL_GAIN, + IMX111_DGTL_GAIN_MIN, IMX111_DGTL_GAIN_MAX, + IMX111_DGTL_GAIN_STEP, IMX111_DGTL_GAIN_DEFAULT); + + sensor->hflip = v4l2_ctrl_new_std(hdl, ops, V4L2_CID_HFLIP, 0, 1, 1, 0); + if (sensor->hflip) + sensor->hflip->flags |= V4L2_CTRL_FLAG_MODIFY_LAYOUT; + + sensor->vflip = v4l2_ctrl_new_std(hdl, ops, V4L2_CID_VFLIP, 0, 1, 1, 0); + if (sensor->vflip) + sensor->vflip->flags |= V4L2_CTRL_FLAG_MODIFY_LAYOUT; + + sensor->vblank = v4l2_ctrl_new_std(hdl, ops, V4L2_CID_VBLANK, IMX111_VBLANK_MIN, + IMX111_VTL_MAX - mode->height, 1, + mode->vtl_def - mode->height); + sensor->hblank = v4l2_ctrl_new_std(hdl, ops, V4L2_CID_HBLANK, IMX111_HBLANK_MIN, + IMX111_HTL_MAX - mode->width, 1, + mode->htl_def - mode->width); + + /* + * The maximum coarse integration time is the frame length in lines + * minus five. + */ + sensor->exposure = v4l2_ctrl_new_std(hdl, ops, V4L2_CID_EXPOSURE, + IMX111_INTEGRATION_TIME_MIN, + IMX111_PIXEL_ARRAY_HEIGHT - 5, + IMX111_INTEGRATION_TIME_STEP, + IMX111_PIXEL_ARRAY_HEIGHT - 5); + + v4l2_ctrl_new_fwnode_properties(hdl, ops, &props); + + v4l2_ctrl_new_std_menu_items(hdl, ops, V4L2_CID_TEST_PATTERN, + ARRAY_SIZE(test_pattern_menu) - 1, 0, 0, + test_pattern_menu); + for (i = 0; i < 4; i++) { + /* + * The assumption is that + * V4L2_CID_TEST_PATTERN_GREENR == V4L2_CID_TEST_PATTERN_RED + 1 + * V4L2_CID_TEST_PATTERN_BLUE == V4L2_CID_TEST_PATTERN_RED + 2 + * V4L2_CID_TEST_PATTERN_GREENB == V4L2_CID_TEST_PATTERN_RED + 3 + */ + v4l2_ctrl_new_std(hdl, ops, V4L2_CID_TEST_PATTERN_RED + i, + IMX111_TESTP_COLOUR_MIN, IMX111_TESTP_COLOUR_MAX, + IMX111_TESTP_COLOUR_STEP, IMX111_TESTP_COLOUR_MAX);drivers/media/i2c/imx111.c line 956
Quoted 10 lines
drivers/media/i2c/imx111.c new file +10
-0+ /* The "Solid color" pattern is white by default */ + } + + if (hdl->error) + return hdl->error; + + sd->ctrl_handler = hdl; + + return 0; +};---
Quoted 7 lines
drivers/media/i2c/imx111.c line 1034
Quoted 4 lines
drivers/media/i2c/imx111.c new file +4
-0+static int imx111_initialize (struct imx111 *sensor) +{ + struct device *dev = regmap_get_device(sensor->regmap); + int ret;ret = 0;
cci_write does not state that ret must be initiated.
Quoted 57 lines
drivers/media/i2c/imx111.c line 1045
Quoted 11 lines
drivers/media/i2c/imx111.c new file +11
-0+ + /* Configure the PLL. */ + cci_write(sensor->regmap, IMX111_PRE_PLL_CLK_DIVIDER_PLL1, + sensor->pll->pre_div, &ret); + cci_write(sensor->regmap, IMX111_PLL_MULTIPLIER_PLL1, sensor->pll->mult, &ret); + cci_write(sensor->regmap, IMX111_POST_DIVIDER, IMX111_POST_DIVIDER_DIV1, &ret); + cci_write(sensor->regmap, IMX111_PLL_SETTLING_TIME, + to_settle_delay(sensor->pll->extclk_rate), &ret); + + ret = cci_multi_reg_write(sensor->regmap, imx111_global_init, + ARRAY_SIZE(imx111_global_init), NULL);You are overwriting the previous errors.
please use ret |=
drivers/media/i2c/imx111.c line 977
Quoted 7 lines
+ if (ret < 0) {
+ dev_err(dev, "Failed to initialize the sensor\n"); + return ret;
+ }drivers/media/i2c/imx111.c new file +3
-0+ + return 0; +}---
Quoted 31 lines
drivers/media/i2c/imx111.c new file +31
-0+static int imx111_set_format (struct v4l2_subdev *sd, + struct v4l2_subdev_state *state, + struct v4l2_subdev_format *format) +{ + 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); + + 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) { + sensor->cur_mode = mode; + sensor->data_depth = imx111_get_format_bpp(fmt); + __v4l2_ctrl_s_ctrl_int64(sensor->pixel_rate, + div_u64(sensor->pixel_clk_raw, 2 * sensor->data_depth)); + + __v4l2_ctrl_modify_range(sensor->vblank, IMX111_VBLANK_MIN, + IMX111_VTL_MAX - mode->height, 1, + mode->vtl_def - mode->height);
Quoted 9 lines
Quoted 6 lines
+ __v4l2_ctrl_s_ctrl(sensor->vblank,
mode->vtl_def-mode->height); +
+ __v4l2_ctrl_modify_range(sensor->hblank,IMX111_HBLANK_MIN, +IMX111_HTL_MAX-mode->width, 1,
+mode->htl_def-mode->width);
+ __v4l2_ctrl_s_ctrl(sensor->hblank,mode->htl_def-mode->width);All the above V4L2 operations need to check for errors.
yet again imx219 and imx319 do not check any of those
Quoted 109 lines
drivers/media/i2c/imx111.c line 977
Quoted 4 lines
+ }
drivers/media/i2c/imx111.c new file +3
-0+ + return 0; +}---
Quoted 7 lines
drivers/media/i2c/imx111.c new file +7
-0+static int imx111_identify_module (struct imx111 *sensor) +{ + struct device *dev = regmap_get_device(sensor->regmap); + u64 value, revision, manufacturer; + int ret; + + ret = cci_read(sensor->regmap, IMX111_PRODUCT_ID, &value, NULL);drivers/media/i2c/imx111.c line 1319
Quoted 10 lines
drivers/media/i2c/imx111.c new file +10
-0+ if (ret) + return ret; + + if (value != IMX111_CHIP_ID) { + dev_err(dev, "chip id mismatch: %x!=%04llx", IMX111_CHIP_ID, value); + return -ENXIO; + } + + cci_read(sensor->regmap, IMX111_REVISION, &revision, NULL); + cci_read(sensor->regmap, IMX111_MANUFACTURER_ID, &manufacturer, NULL);Instead of NULL, pass ret for the error code, and return ret at the end.
Quoted 16 lines
drivers/media/i2c/imx111.c new file +16
-0+ + dev_dbg(dev, "module IMX%03llx rev. %llu manufacturer %llu\n", + value, revision, manufacturer); + + return 0; +} + +static int imx111_clk_init (struct imx111 *sensor) +{ + struct device *dev = regmap_get_device(sensor->regmap); + u32 ndata_lanes = sensor->bus_cfg.bus.mipi_csi2.num_data_lanes; + u64 extclk_rate, system_clk; + unsigned int i; + + extclk_rate = clk_get_rate(sensor->extclk); + if (!extclk_rate)drivers/media/i2c/imx111.c line 1345
Quoted 10 lines
drivers/media/i2c/imx111.c new file +10
-0+ return dev_err_probe(dev, -EINVAL, "EXTCLK rate unknown\n"); + + for (i = 0; i < ARRAY_SIZE(imx111_pll); i++) { + if (clk_get_rate(sensor->extclk) == imx111_pll[i].extclk_rate) { + sensor->pll = &imx111_pll[i]; + break; + } + } + if (!sensor->pll) + return dev_err_probe(dev, -EINVAL, "Unsupported EXTCLK rate %llu\n", extclk_rate);Max line length should be 80 columns. This applies everywhere the line length exceeds 80 characters.
Quoted 16 lines
drivers/media/i2c/imx111.c new file +16
-0+ + system_clk = div_u64(extclk_rate, sensor->pll->pre_div) * sensor->pll->mult; + + /* + * Pixel clock or Logic clock is used for internal image processing is + * generated by dividing into 1/10 or 1/8 frequency according to the + * word length of the CSI2 interface. This clock is designating the pixel + * rate and used as the base of integration time, frame rate etc. + */ + sensor->pixel_clk_raw = system_clk * ndata_lanes; + + /* + * The CSI-2 bus is clocked for 16-bit per pixel, transmitted in DDR over n lanes + * for RAW10 default format. + */ + sensor->default_link_freq = div_u64(sensor->pixel_clk_raw * 8,drivers/media/i2c/imx111.c line 1371
Quoted 10 lines
drivers/media/i2c/imx111.c new file +10
-0+ 2 * IMX111_DATA_DEPTH_RAW10); + + if (sensor->bus_cfg.nr_of_link_frequencies != 1 || + sensor->bus_cfg.link_frequencies[0] != sensor->default_link_freq) + return dev_err_probe(dev, -EINVAL, + "Unsupported DT link-frequencies, expected %llu\n", + sensor->default_link_freq); + + return 0; +}---
Quoted 10 lines
drivers/media/i2c/imx111.c new file +10
-0+static const struct of_device_id imx111_of_match[] = { + { .compatible = "sony,imx111" }, + { /* sentinel */ } +}; +MODULE_DEVICE_TABLE (of, imx111_of_match); + +static struct i2c_driver imx111_i2c_driver = { + .driver = { + .name = "imx111", + .of_match_table = imx111_of_match,drivers/media/i2c/imx111.c line 1548
Quoted 10 lines
drivers/media/i2c/imx111.c new file +10
-0+ .pm = &imx111_pm_ops, + }, + .probe = imx111_probe, + .remove = imx111_remove, +}; +module_i2c_driver (imx111_i2c_driver); + +MODULE_AUTHOR ("Svyatoslav Ryhel <[email protected]>" ); +MODULE_DESCRIPTION ("Sony IMX111 CMOS Image Sensor driver" ); +MODULE_LICENSE ("GPL" );Best Regards,
Tarang
Hello,
sorry for entering the conversation
Quoted 37 lines · Svyatoslav Ryhel
чт, 30 жовт. 2025 р. о 16:55 Tarang Raval <[email protected]> пише:
Quoted 22 lines
Hi Svyatoslav,
Quoted 10 lines
Add 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 SGBRG8Quoted 6 lines
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.
Signed-off-by Svyatoslav Ryhel <[email protected]>---
Quoted 13 lines
drivers/media/i2c/imx111.c line 762
Quoted 9 lines
drivers/media/i2c/imx111.c new file +9
-0+static int imx111_set_ctrl (struct v4l2_ctrl *ctrl) +{ + struct imx111 *sensor = ctrl_to_imx111(ctrl); + struct device *dev = regmap_get_device(sensor->regmap); + s64 max; + int ret = 0; + + /* Propagate change of current control to all related controls */ + switch (ctrl->id) {Do we need the switch statement, since only one case is present? You can use an 'if' instead.
Quoted 4 lines
imx219 and imx319 which are recommended references use switch, and it seems that media maintainters are particularly picky to code style, I have copied it from there.
Personally, whenever doing reviews, receiving a reply that ignores the merit of the comment and simply refers to the existing code base as an excuse for not caring, it's what put me off the most.
Please respect the time reviewers have invested in looking at your code by at least considering their comment instead of dismissing them. In this specific case you could have easily said "I like it more this way and it's consistent with what other drivers do". The same cannot be said for other comments that you have decided to ignore.
Quoted 10 lines
Quoted 7 lines
Quoted 3 lines
+ case
V4L2_CID_VBLANK:
+ /* Update max exposure while meeting expected vblanking */ + max =sensor->cur_mode->height+ctrl->val- 5;You can define a macro for the value 5 to improve readability. Also, make this change in the
init_controlfunction.imx219 does not specifies this as a define
It doesn't but it should, like 90% of other drivers in mainline do
Quoted 9 lines
Quoted 6 lines
Quoted 3 lines
+ __v4l2_ctrl_modify_range(sensor->exposure, +
sensor->exposure->minimum, + max,sensor->exposure->step, max);This may fail; consider adding an error check.
imx219 does not return error here too
so ?
Quoted 200 lines
Quoted 89 lines
Quoted 76 lines
+ break;
+ }drivers/media/i2c/imx111.c new file +74
-0+ + /* + * Applying V4L2 control value only happens + * when power is up for streaming + */ + if (!pm_runtime_get_if_in_use(dev)) + return 0; + + switch (ctrl->id) { + case V4L2_CID_ANALOGUE_GAIN: + cci_write(sensor->regmap, IMX111_REG_ANALOG_GAIN, ctrl->val, &ret); + break; + case V4L2_CID_DIGITAL_GAIN: + ret = imx111_update_digital_gain(sensor, ctrl->val); + break; + case V4L2_CID_EXPOSURE: + cci_update_bits(sensor->regmap, IMX111_GROUP_WRITE, IMX111_GROUP_WRITE_ON, + IMX111_GROUP_WRITE_ON, &ret); + cci_write(sensor->regmap, IMX111_INTEGRATION_TIME, ctrl->val, &ret); + cci_update_bits(sensor->regmap, IMX111_GROUP_WRITE, IMX111_GROUP_WRITE_ON, + 0, &ret); + break; + case V4L2_CID_HBLANK: + cci_update_bits(sensor->regmap, IMX111_GROUP_WRITE, IMX111_GROUP_WRITE_ON, + IMX111_GROUP_WRITE_ON, &ret); + dev_err(dev, "writing 0x%x to HTL\n", sensor->cur_mode->width + ctrl->val); + cci_write(sensor->regmap, IMX111_HORIZONTAL_TOTAL_LENGTH, + sensor->cur_mode->width + ctrl->val, &ret); + cci_update_bits(sensor->regmap, IMX111_GROUP_WRITE, IMX111_GROUP_WRITE_ON, + 0, &ret); + break; + case V4L2_CID_VBLANK: + cci_update_bits(sensor->regmap, IMX111_GROUP_WRITE, IMX111_GROUP_WRITE_ON, + IMX111_GROUP_WRITE_ON, &ret); + dev_err(dev, "writing 0x%x to VTL\n", sensor->cur_mode->height + ctrl->val); + cci_write(sensor->regmap, IMX111_VERTICAL_TOTAL_LENGTH, + sensor->cur_mode->height + ctrl->val, &ret); + cci_update_bits(sensor->regmap, IMX111_GROUP_WRITE, IMX111_GROUP_WRITE_ON, + 0, &ret); + break; + case V4L2_CID_HFLIP: + case V4L2_CID_VFLIP: + cci_write(sensor->regmap, IMX111_IMAGE_ORIENTATION, + sensor->hflip->val | sensor->vflip->val << 1, &ret); + break; + case V4L2_CID_TEST_PATTERN: + cci_write(sensor->regmap, IMX111_TEST_PATTERN, ctrl->val, &ret); + break; + case V4L2_CID_TEST_PATTERN_RED: + cci_update_bits(sensor->regmap, IMX111_GROUP_WRITE, IMX111_GROUP_WRITE_ON, + IMX111_GROUP_WRITE_ON, &ret); + cci_write(sensor->regmap, IMX111_SOLID_COLOR_RED, ctrl->val, &ret); + cci_update_bits(sensor->regmap, IMX111_GROUP_WRITE, IMX111_GROUP_WRITE_ON, + 0, &ret); + break; + case V4L2_CID_TEST_PATTERN_GREENR: + cci_update_bits(sensor->regmap, IMX111_GROUP_WRITE, IMX111_GROUP_WRITE_ON, + IMX111_GROUP_WRITE_ON, &ret); + cci_write(sensor->regmap, IMX111_SOLID_COLOR_GR, ctrl->val, &ret); + cci_update_bits(sensor->regmap, IMX111_GROUP_WRITE, IMX111_GROUP_WRITE_ON, + 0, &ret); + break; + case V4L2_CID_TEST_PATTERN_BLUE: + cci_update_bits(sensor->regmap, IMX111_GROUP_WRITE, IMX111_GROUP_WRITE_ON, + IMX111_GROUP_WRITE_ON, &ret); + cci_write(sensor->regmap, IMX111_SOLID_COLOR_BLUE, ctrl->val, &ret); + cci_update_bits(sensor->regmap, IMX111_GROUP_WRITE, IMX111_GROUP_WRITE_ON, + 0, &ret); + break; + case V4L2_CID_TEST_PATTERN_GREENB: + cci_update_bits(sensor->regmap, IMX111_GROUP_WRITE, IMX111_GROUP_WRITE_ON, + IMX111_GROUP_WRITE_ON, &ret); + cci_write(sensor->regmap, IMX111_SOLID_COLOR_GB, ctrl->val, &ret); + cci_update_bits(sensor->regmap, IMX111_GROUP_WRITE, IMX111_GROUP_WRITE_ON,drivers/media/i2c/imx111.c line 854
Quoted 10 lines
drivers/media/i2c/imx111.c new file +10
-0+ 0, &ret); + break; + default: + ret = -EINVAL; + } + + pm_runtime_put(dev); + + return ret; +}---
Quoted 10 lines
drivers/media/i2c/imx111.c line 874
Quoted 7 lines
drivers/media/i2c/imx111.c new file +7
-0+static int imx111_init_controls (struct imx111 *sensor) +{ + const struct v4l2_ctrl_ops *ops = &imx111_ctrl_ops; + struct device *dev = regmap_get_device(sensor->regmap); + const struct imx111_mode *mode = sensor->cur_mode; + struct v4l2_fwnode_device_properties props; + struct v4l2_subdev *sd = &sensor->sd;No need for a new variable; there is only one user in the function.
This make code reading cleaner, no?
Quoted 90 lines
drivers/media/i2c/imx111.c line 883
Quoted 9 lines
+ struct
v4l2_ctrl_handler*hdl =&sensor->hdl;
+ s64pixel_rate_min,pixel_rate_max;
+ int i, ret;drivers/media/i2c/imx111.c new file +6
-0+ + ret = v4l2_fwnode_device_parse(dev, &props); + if (ret < 0) + return ret; + + ret = v4l2_ctrl_handler_init(hdl, 13);Now there are 15 controls.
No need for explicit error checking; you can omit the error check if you'd like.
Quoted 63 lines
+ if (ret)
+ return ret;drivers/media/i2c/imx111.c new file +61
-0+ + pixel_rate_min = div_u64(sensor->pixel_clk_raw, 2 * IMX111_DATA_DEPTH_RAW10); + pixel_rate_max = div_u64(sensor->pixel_clk_raw, 2 * IMX111_DATA_DEPTH_RAW8); + sensor->pixel_rate = v4l2_ctrl_new_std(hdl, NULL, V4L2_CID_PIXEL_RATE, + pixel_rate_min, pixel_rate_max, + 1, div_u64(sensor->pixel_clk_raw, + 2 * sensor->data_depth)); + + sensor->link_freq = v4l2_ctrl_new_int_menu(hdl, NULL, V4L2_CID_LINK_FREQ, + 0, 0, &sensor->default_link_freq); + if (sensor->link_freq) + sensor->link_freq->flags |= V4L2_CTRL_FLAG_READ_ONLY; + + v4l2_ctrl_new_std(hdl, ops, V4L2_CID_ANALOGUE_GAIN, + IMX111_ANA_GAIN_MIN, IMX111_ANA_GAIN_MAX, + IMX111_ANA_GAIN_STEP, IMX111_ANA_GAIN_DEFAULT); + + v4l2_ctrl_new_std(hdl, ops, V4L2_CID_DIGITAL_GAIN, + IMX111_DGTL_GAIN_MIN, IMX111_DGTL_GAIN_MAX, + IMX111_DGTL_GAIN_STEP, IMX111_DGTL_GAIN_DEFAULT); + + sensor->hflip = v4l2_ctrl_new_std(hdl, ops, V4L2_CID_HFLIP, 0, 1, 1, 0); + if (sensor->hflip) + sensor->hflip->flags |= V4L2_CTRL_FLAG_MODIFY_LAYOUT; + + sensor->vflip = v4l2_ctrl_new_std(hdl, ops, V4L2_CID_VFLIP, 0, 1, 1, 0); + if (sensor->vflip) + sensor->vflip->flags |= V4L2_CTRL_FLAG_MODIFY_LAYOUT; + + sensor->vblank = v4l2_ctrl_new_std(hdl, ops, V4L2_CID_VBLANK, IMX111_VBLANK_MIN, + IMX111_VTL_MAX - mode->height, 1, + mode->vtl_def - mode->height); + sensor->hblank = v4l2_ctrl_new_std(hdl, ops, V4L2_CID_HBLANK, IMX111_HBLANK_MIN, + IMX111_HTL_MAX - mode->width, 1, + mode->htl_def - mode->width); + + /* + * The maximum coarse integration time is the frame length in lines + * minus five. + */ + sensor->exposure = v4l2_ctrl_new_std(hdl, ops, V4L2_CID_EXPOSURE, + IMX111_INTEGRATION_TIME_MIN, + IMX111_PIXEL_ARRAY_HEIGHT - 5, + IMX111_INTEGRATION_TIME_STEP, + IMX111_PIXEL_ARRAY_HEIGHT - 5); + + v4l2_ctrl_new_fwnode_properties(hdl, ops, &props); + + v4l2_ctrl_new_std_menu_items(hdl, ops, V4L2_CID_TEST_PATTERN, + ARRAY_SIZE(test_pattern_menu) - 1, 0, 0, + test_pattern_menu); + for (i = 0; i < 4; i++) { + /* + * The assumption is that + * V4L2_CID_TEST_PATTERN_GREENR == V4L2_CID_TEST_PATTERN_RED + 1 + * V4L2_CID_TEST_PATTERN_BLUE == V4L2_CID_TEST_PATTERN_RED + 2 + * V4L2_CID_TEST_PATTERN_GREENB == V4L2_CID_TEST_PATTERN_RED + 3 + */ + v4l2_ctrl_new_std(hdl, ops, V4L2_CID_TEST_PATTERN_RED + i, + IMX111_TESTP_COLOUR_MIN, IMX111_TESTP_COLOUR_MAX, + IMX111_TESTP_COLOUR_STEP, IMX111_TESTP_COLOUR_MAX);drivers/media/i2c/imx111.c line 956
Quoted 10 lines
drivers/media/i2c/imx111.c new file +10
-0+ /* The "Solid color" pattern is white by default */ + } + + if (hdl->error) + return hdl->error; + + sd->ctrl_handler = hdl; + + return 0; +};---
Quoted 7 lines
drivers/media/i2c/imx111.c line 1034
Quoted 4 lines
drivers/media/i2c/imx111.c new file +4
-0+static int imx111_initialize (struct imx111 *sensor) +{ + struct device *dev = regmap_get_device(sensor->regmap); + int ret;ret = 0;
Quoted 1 line
cci_writedoes not state that ret must be initiated.
Could you at least take the time to read the code ?
int cci_write(struct regmap *map, u32 reg, u64 val, int *err)
{
bool little_endian;
unsigned int len;
u8 buf[8];
int ret;
if (err && *err)
return *err;And by the way, the documentation says:
/**
* cci_write() - Write a value to a single CCI register
*
* @map: Register map to write to
* @reg: Register address to write, use CCI_REG#() macros to encode reg width
* @val: Value to be written
* @err: Optional pointer to store errors, if a previous error is set
* then the write will be skipped
*
* Return: %0 on success or a negative error code on failure.
*/
int cci_write(struct regmap *map, u32 reg, u64 val, int *err);
Quoted 5 lines
Quoted 5 lines
Quoted 5 lines
+
+ /* Configure the PLL. */
+ cci_write(sensor->regmap,IMX111_PRE_PLL_CLK_DIVIDER_PLL1, +sensor->pll->pre_div, &ret);
I'm very surprised this doesn't sometimes fail as ret is not initialized
Quoted 11 lines
Quoted 11 lines
Quoted 7 lines
+ cci_write(sensor->regmap,
IMX111_PLL_MULTIPLIER_PLL1,sensor->pll->mult, &ret); + cci_write(sensor->regmap,IMX111_POST_DIVIDER,IMX111_POST_DIVIDER_DIV1, &ret); + cci_write(sensor->regmap,IMX111_PLL_SETTLING_TIME,
+to_settle_delay(sensor->pll->extclk_rate), &ret);
+
+ ret = cci_multi_reg_write(sensor->regmap,imx111_global_init,
+ARRAY_SIZE(imx111_global_init), NULL);You are overwriting the previous errors.
please use ret |=
or you can pass ret to cci_multi_reg_write() as well
Maybe that's why you don't see errors causes by uninitialized ret ?
Quoted 52 lines
Quoted 42 lines
drivers/media/i2c/imx111.c line 977
Quoted 8 lines
+ if (ret < 0) {
+ dev_err(dev, "Failed to initialize the sensor\n"); + return ret;
+ }drivers/media/i2c/imx111.c new file +3
-0+ + return 0; +}---
Quoted 31 lines
drivers/media/i2c/imx111.c new file +31
-0+static int imx111_set_format (struct v4l2_subdev *sd, + struct v4l2_subdev_state *state, + struct v4l2_subdev_format *format) +{ + 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); + + 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) { + sensor->cur_mode = mode; + sensor->data_depth = imx111_get_format_bpp(fmt); + __v4l2_ctrl_s_ctrl_int64(sensor->pixel_rate, + div_u64(sensor->pixel_clk_raw, 2 * sensor->data_depth)); + + __v4l2_ctrl_modify_range(sensor->vblank, IMX111_VBLANK_MIN, + IMX111_VTL_MAX - mode->height, 1, + mode->vtl_def - mode->height);Quoted 9 lines
Quoted 6 lines
+ __v4l2_ctrl_s_ctrl(sensor->vblank,
mode->vtl_def-mode->height); +
+ __v4l2_ctrl_modify_range(sensor->hblank,IMX111_HBLANK_MIN, +IMX111_HTL_MAX-mode->width, 1,
+mode->htl_def-mode->width);
+ __v4l2_ctrl_s_ctrl(sensor->hblank,mode->htl_def-mode->width);All the above V4L2 operations need to check for errors.
Quoted 2 lines
yet again imx219 and imx319 do not check any of those
And we recently got an error on imx219 controls update that went unnoticed because of this and I'm now fixing 40+ drivers because this has been copied over and over. Want to make them 41 ?
Quoted 48 lines
Quoted 48 lines
drivers/media/i2c/imx111.c line 977
Quoted 4 lines
+ }
drivers/media/i2c/imx111.c new file +3
-0+ + return 0; +}---
Quoted 7 lines
drivers/media/i2c/imx111.c new file +7
-0+static int imx111_identify_module (struct imx111 *sensor) +{ + struct device *dev = regmap_get_device(sensor->regmap); + u64 value, revision, manufacturer; + int ret; + + ret = cci_read(sensor->regmap, IMX111_PRODUCT_ID, &value, NULL);drivers/media/i2c/imx111.c line 1319
Quoted 10 lines
drivers/media/i2c/imx111.c new file +10
-0+ if (ret) + return ret; + + if (value != IMX111_CHIP_ID) { + dev_err(dev, "chip id mismatch: %x!=%04llx", IMX111_CHIP_ID, value); + return -ENXIO; + } + + cci_read(sensor->regmap, IMX111_REVISION, &revision, NULL); + cci_read(sensor->regmap, IMX111_MANUFACTURER_ID, &manufacturer, NULL);Instead of NULL, pass ret for the error code, and return ret at the end.
Quoted 21 lines
drivers/media/i2c/imx111.c new file +21
-0+ + dev_dbg(dev, "module IMX%03llx rev. %llu manufacturer %llu\n", + value, revision, manufacturer); + + return 0; +} + +static int imx111_clk_init (struct imx111 *sensor) +{ + struct device *dev = regmap_get_device(sensor->regmap); + u32 ndata_lanes = sensor->bus_cfg.bus.mipi_csi2.num_data_lanes; + u64 extclk_rate, system_clk; + unsigned int i; + + extclk_rate = clk_get_rate(sensor->extclk); + if (!extclk_rate) + return dev_err_probe(dev, -EINVAL, "EXTCLK rate unknown\n"); + + for (i = 0; i < ARRAY_SIZE(imx111_pll); i++) { + if (clk_get_rate(sensor->extclk) == imx111_pll[i].extclk_rate) { + sensor->pll = &imx111_pll[i];
Quoted 8 lines
Quoted 8 lines
Quoted 5 lines
+ break;
+ }
+ }
+ if (!sensor->pll)
+ returndev_err_probe(dev, -EINVAL, "Unsupported EXTCLK rate %llu\n", extclk_rate);Max line length should be 80 columns. This applies everywhere the line length exceeds 80 characters.
In response to your reply in a separate email:
https://www.kernel.org/doc/html/latest/driver-api/media/maintainer-entry-profile.html#coding-style-addendum
Media development uses checkpatch.pl on strict mode to verify the code style, e.g.:
$ ./scripts/checkpatch.pl --strict --max-line-length=80
I don't like being that strict too. Feel free to send a patch, you'll have my ack
Quoted 53 lines
Quoted 53 lines
Quoted 17 lines
drivers/media/i2c/imx111.c new file +16
-0+ + system_clk = div_u64(extclk_rate, sensor->pll->pre_div) * sensor->pll->mult; + + /* + * Pixel clock or Logic clock is used for internal image processing is + * generated by dividing into 1/10 or 1/8 frequency according to the + * word length of the CSI2 interface. This clock is designating the pixel + * rate and used as the base of integration time, frame rate etc. + */ + sensor->pixel_clk_raw = system_clk * ndata_lanes; + + /* + * The CSI-2 bus is clocked for 16-bit per pixel, transmitted in DDR over n lanes + * for RAW10 default format. + */ + sensor->default_link_freq = div_u64(sensor->pixel_clk_raw * 8,drivers/media/i2c/imx111.c line 1371
Quoted 10 lines
drivers/media/i2c/imx111.c new file +10
-0+ 2 * IMX111_DATA_DEPTH_RAW10); + + if (sensor->bus_cfg.nr_of_link_frequencies != 1 || + sensor->bus_cfg.link_frequencies[0] != sensor->default_link_freq) + return dev_err_probe(dev, -EINVAL, + "Unsupported DT link-frequencies, expected %llu\n", + sensor->default_link_freq); + + return 0; +}---
Quoted 10 lines
drivers/media/i2c/imx111.c new file +10
-0+static const struct of_device_id imx111_of_match[] = { + { .compatible = "sony,imx111" }, + { /* sentinel */ } +}; +MODULE_DEVICE_TABLE (of, imx111_of_match); + +static struct i2c_driver imx111_i2c_driver = { + .driver = { + .name = "imx111", + .of_match_table = imx111_of_match,drivers/media/i2c/imx111.c line 1548
Quoted 10 lines
drivers/media/i2c/imx111.c new file +10
-0+ .pm = &imx111_pm_ops, + }, + .probe = imx111_probe, + .remove = imx111_remove, +}; +module_i2c_driver (imx111_i2c_driver); + +MODULE_AUTHOR ("Svyatoslav Ryhel <[email protected]>" ); +MODULE_DESCRIPTION ("Sony IMX111 CMOS Image Sensor driver" ); +MODULE_LICENSE ("GPL" );Best Regards,
Tarang
чт, 30 жовт. 2025 р. о 17:50 Jacopo Mondi <[email protected]> пише:
Quoted 51 lines
Hello,
sorry for entering the conversationQuoted 37 lines · Svyatoslav Ryhel
чт, 30 жовт. 2025 р. о 16:55 Tarang Raval <[email protected]> пише:
Quoted 22 lines
Hi Svyatoslav,
Quoted 10 lines
Add 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 SGBRG8Quoted 6 lines
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.
Signed-off-by Svyatoslav Ryhel <[email protected]>---
Quoted 13 lines
drivers/media/i2c/imx111.c line 762
Quoted 9 lines
drivers/media/i2c/imx111.c new file +9
-0+static int imx111_set_ctrl (struct v4l2_ctrl *ctrl) +{ + struct imx111 *sensor = ctrl_to_imx111(ctrl); + struct device *dev = regmap_get_device(sensor->regmap); + s64 max; + int ret = 0; + + /* Propagate change of current control to all related controls */ + switch (ctrl->id) {Do we need the switch statement, since only one case is present? You can use an 'if' instead.
Quoted 4 lines
imx219 and imx319 which are recommended references use switch, and it seems that media maintainters are particularly picky to code style, I have copied it from there.
Personally, whenever doing reviews, receiving a reply that ignores the merit of the comment and simply refers to the existing code base as an excuse for not caring, it's what put me off the most.
Quoted 6 lines
Please respect the time reviewers have invested in looking at your code by at least considering their comment instead of dismissing them. In this specific case you could have easily said "I like it more this way and it's consistent with what other drivers do". The same cannot be said for other comments that you have decided to ignore.
I did not state that I will ignore all the comments. Contrary, I will be applying most/all of them. My point is that Linux kernel documentation, which Sakari Ailus (not an offence or blaming) pointed in v2 clearly pointed to imx219 and imx319 as an valid reference drivers, while they seem to be outdated. So by using those as reference I wasted both my time and maintainers time. You say "Please respect the time reviewers" but no one respects my time.
Quoted 334 lines
Quoted 11 lines
Quoted 8 lines
Quoted 4 lines
+ case
V4L2_CID_VBLANK:
+ /* Update max exposure while meeting expected vblanking */ + max =sensor->cur_mode->height+ctrl->val- 5;You can define a macro for the value 5 to improve readability. Also, make this change in the
init_controlfunction.imx219 does not specifies this as a define
It doesn't but it should, like 90% of other drivers in mainline do
Quoted 9 lines
Quoted 6 lines
Quoted 3 lines
+ __v4l2_ctrl_modify_range(sensor->exposure, +
sensor->exposure->minimum, + max,sensor->exposure->step, max);This may fail; consider adding an error check.
imx219 does not return error here too
so ?
Quoted 200 lines
Quoted 89 lines
Quoted 76 lines
+ break;
+ }drivers/media/i2c/imx111.c new file +74
-0+ + /* + * Applying V4L2 control value only happens + * when power is up for streaming + */ + if (!pm_runtime_get_if_in_use(dev)) + return 0; + + switch (ctrl->id) { + case V4L2_CID_ANALOGUE_GAIN: + cci_write(sensor->regmap, IMX111_REG_ANALOG_GAIN, ctrl->val, &ret); + break; + case V4L2_CID_DIGITAL_GAIN: + ret = imx111_update_digital_gain(sensor, ctrl->val); + break; + case V4L2_CID_EXPOSURE: + cci_update_bits(sensor->regmap, IMX111_GROUP_WRITE, IMX111_GROUP_WRITE_ON, + IMX111_GROUP_WRITE_ON, &ret); + cci_write(sensor->regmap, IMX111_INTEGRATION_TIME, ctrl->val, &ret); + cci_update_bits(sensor->regmap, IMX111_GROUP_WRITE, IMX111_GROUP_WRITE_ON, + 0, &ret); + break; + case V4L2_CID_HBLANK: + cci_update_bits(sensor->regmap, IMX111_GROUP_WRITE, IMX111_GROUP_WRITE_ON, + IMX111_GROUP_WRITE_ON, &ret); + dev_err(dev, "writing 0x%x to HTL\n", sensor->cur_mode->width + ctrl->val); + cci_write(sensor->regmap, IMX111_HORIZONTAL_TOTAL_LENGTH, + sensor->cur_mode->width + ctrl->val, &ret); + cci_update_bits(sensor->regmap, IMX111_GROUP_WRITE, IMX111_GROUP_WRITE_ON, + 0, &ret); + break; + case V4L2_CID_VBLANK: + cci_update_bits(sensor->regmap, IMX111_GROUP_WRITE, IMX111_GROUP_WRITE_ON, + IMX111_GROUP_WRITE_ON, &ret); + dev_err(dev, "writing 0x%x to VTL\n", sensor->cur_mode->height + ctrl->val); + cci_write(sensor->regmap, IMX111_VERTICAL_TOTAL_LENGTH, + sensor->cur_mode->height + ctrl->val, &ret); + cci_update_bits(sensor->regmap, IMX111_GROUP_WRITE, IMX111_GROUP_WRITE_ON, + 0, &ret); + break; + case V4L2_CID_HFLIP: + case V4L2_CID_VFLIP: + cci_write(sensor->regmap, IMX111_IMAGE_ORIENTATION, + sensor->hflip->val | sensor->vflip->val << 1, &ret); + break; + case V4L2_CID_TEST_PATTERN: + cci_write(sensor->regmap, IMX111_TEST_PATTERN, ctrl->val, &ret); + break; + case V4L2_CID_TEST_PATTERN_RED: + cci_update_bits(sensor->regmap, IMX111_GROUP_WRITE, IMX111_GROUP_WRITE_ON, + IMX111_GROUP_WRITE_ON, &ret); + cci_write(sensor->regmap, IMX111_SOLID_COLOR_RED, ctrl->val, &ret); + cci_update_bits(sensor->regmap, IMX111_GROUP_WRITE, IMX111_GROUP_WRITE_ON, + 0, &ret); + break; + case V4L2_CID_TEST_PATTERN_GREENR: + cci_update_bits(sensor->regmap, IMX111_GROUP_WRITE, IMX111_GROUP_WRITE_ON, + IMX111_GROUP_WRITE_ON, &ret); + cci_write(sensor->regmap, IMX111_SOLID_COLOR_GR, ctrl->val, &ret); + cci_update_bits(sensor->regmap, IMX111_GROUP_WRITE, IMX111_GROUP_WRITE_ON, + 0, &ret); + break; + case V4L2_CID_TEST_PATTERN_BLUE: + cci_update_bits(sensor->regmap, IMX111_GROUP_WRITE, IMX111_GROUP_WRITE_ON, + IMX111_GROUP_WRITE_ON, &ret); + cci_write(sensor->regmap, IMX111_SOLID_COLOR_BLUE, ctrl->val, &ret); + cci_update_bits(sensor->regmap, IMX111_GROUP_WRITE, IMX111_GROUP_WRITE_ON, + 0, &ret); + break; + case V4L2_CID_TEST_PATTERN_GREENB: + cci_update_bits(sensor->regmap, IMX111_GROUP_WRITE, IMX111_GROUP_WRITE_ON, + IMX111_GROUP_WRITE_ON, &ret); + cci_write(sensor->regmap, IMX111_SOLID_COLOR_GB, ctrl->val, &ret); + cci_update_bits(sensor->regmap, IMX111_GROUP_WRITE, IMX111_GROUP_WRITE_ON,drivers/media/i2c/imx111.c line 854
Quoted 10 lines
drivers/media/i2c/imx111.c new file +10
-0+ 0, &ret); + break; + default: + ret = -EINVAL; + } + + pm_runtime_put(dev); + + return ret; +}---
Quoted 10 lines
drivers/media/i2c/imx111.c line 874
Quoted 7 lines
drivers/media/i2c/imx111.c new file +7
-0+static int imx111_init_controls (struct imx111 *sensor) +{ + const struct v4l2_ctrl_ops *ops = &imx111_ctrl_ops; + struct device *dev = regmap_get_device(sensor->regmap); + const struct imx111_mode *mode = sensor->cur_mode; + struct v4l2_fwnode_device_properties props; + struct v4l2_subdev *sd = &sensor->sd;No need for a new variable; there is only one user in the function.
This make code reading cleaner, no?
Quoted 90 lines
drivers/media/i2c/imx111.c line 883
Quoted 9 lines
+ struct
v4l2_ctrl_handler*hdl =&sensor->hdl;
+ s64pixel_rate_min,pixel_rate_max;
+ int i, ret;drivers/media/i2c/imx111.c new file +6
-0+ + ret = v4l2_fwnode_device_parse(dev, &props); + if (ret < 0) + return ret; + + ret = v4l2_ctrl_handler_init(hdl, 13);Now there are 15 controls.
No need for explicit error checking; you can omit the error check if you'd like.
Quoted 63 lines
+ if (ret)
+ return ret;drivers/media/i2c/imx111.c new file +61
-0+ + pixel_rate_min = div_u64(sensor->pixel_clk_raw, 2 * IMX111_DATA_DEPTH_RAW10); + pixel_rate_max = div_u64(sensor->pixel_clk_raw, 2 * IMX111_DATA_DEPTH_RAW8); + sensor->pixel_rate = v4l2_ctrl_new_std(hdl, NULL, V4L2_CID_PIXEL_RATE, + pixel_rate_min, pixel_rate_max, + 1, div_u64(sensor->pixel_clk_raw, + 2 * sensor->data_depth)); + + sensor->link_freq = v4l2_ctrl_new_int_menu(hdl, NULL, V4L2_CID_LINK_FREQ, + 0, 0, &sensor->default_link_freq); + if (sensor->link_freq) + sensor->link_freq->flags |= V4L2_CTRL_FLAG_READ_ONLY; + + v4l2_ctrl_new_std(hdl, ops, V4L2_CID_ANALOGUE_GAIN, + IMX111_ANA_GAIN_MIN, IMX111_ANA_GAIN_MAX, + IMX111_ANA_GAIN_STEP, IMX111_ANA_GAIN_DEFAULT); + + v4l2_ctrl_new_std(hdl, ops, V4L2_CID_DIGITAL_GAIN, + IMX111_DGTL_GAIN_MIN, IMX111_DGTL_GAIN_MAX, + IMX111_DGTL_GAIN_STEP, IMX111_DGTL_GAIN_DEFAULT); + + sensor->hflip = v4l2_ctrl_new_std(hdl, ops, V4L2_CID_HFLIP, 0, 1, 1, 0); + if (sensor->hflip) + sensor->hflip->flags |= V4L2_CTRL_FLAG_MODIFY_LAYOUT; + + sensor->vflip = v4l2_ctrl_new_std(hdl, ops, V4L2_CID_VFLIP, 0, 1, 1, 0); + if (sensor->vflip) + sensor->vflip->flags |= V4L2_CTRL_FLAG_MODIFY_LAYOUT; + + sensor->vblank = v4l2_ctrl_new_std(hdl, ops, V4L2_CID_VBLANK, IMX111_VBLANK_MIN, + IMX111_VTL_MAX - mode->height, 1, + mode->vtl_def - mode->height); + sensor->hblank = v4l2_ctrl_new_std(hdl, ops, V4L2_CID_HBLANK, IMX111_HBLANK_MIN, + IMX111_HTL_MAX - mode->width, 1, + mode->htl_def - mode->width); + + /* + * The maximum coarse integration time is the frame length in lines + * minus five. + */ + sensor->exposure = v4l2_ctrl_new_std(hdl, ops, V4L2_CID_EXPOSURE, + IMX111_INTEGRATION_TIME_MIN, + IMX111_PIXEL_ARRAY_HEIGHT - 5, + IMX111_INTEGRATION_TIME_STEP, + IMX111_PIXEL_ARRAY_HEIGHT - 5); + + v4l2_ctrl_new_fwnode_properties(hdl, ops, &props); + + v4l2_ctrl_new_std_menu_items(hdl, ops, V4L2_CID_TEST_PATTERN, + ARRAY_SIZE(test_pattern_menu) - 1, 0, 0, + test_pattern_menu); + for (i = 0; i < 4; i++) { + /* + * The assumption is that + * V4L2_CID_TEST_PATTERN_GREENR == V4L2_CID_TEST_PATTERN_RED + 1 + * V4L2_CID_TEST_PATTERN_BLUE == V4L2_CID_TEST_PATTERN_RED + 2 + * V4L2_CID_TEST_PATTERN_GREENB == V4L2_CID_TEST_PATTERN_RED + 3 + */ + v4l2_ctrl_new_std(hdl, ops, V4L2_CID_TEST_PATTERN_RED + i, + IMX111_TESTP_COLOUR_MIN, IMX111_TESTP_COLOUR_MAX, + IMX111_TESTP_COLOUR_STEP, IMX111_TESTP_COLOUR_MAX);drivers/media/i2c/imx111.c line 956
Quoted 10 lines
drivers/media/i2c/imx111.c new file +10
-0+ /* The "Solid color" pattern is white by default */ + } + + if (hdl->error) + return hdl->error; + + sd->ctrl_handler = hdl; + + return 0; +};---
Quoted 7 lines
drivers/media/i2c/imx111.c line 1034
Quoted 4 lines
drivers/media/i2c/imx111.c new file +4
-0+static int imx111_initialize (struct imx111 *sensor) +{ + struct device *dev = regmap_get_device(sensor->regmap); + int ret;ret = 0;
Quoted 1 line
cci_writedoes not state that ret must be initiated.Could you at least take the time to read the code ?
int
cci_write(struct regmap *map, u32 reg, u64 val, int *err){ bool little_endian; unsigned int len; u8 buf[8]; int ret; if (err && *err) return *err;And by the way, the documentation says:
/**
*cci_write()- Write a value to a single CCI register
*
* @map: Register map to write to
* @reg: Register address to write, use CCI_REG#() macros to encode reg width
* @val: Value to be written
* @err: Optional pointer to store errors, if a previous error is set
* then the write will be skipped
*
* Return: %0 on success or a negative error code on failure.
*/
intcci_write(struct regmap *map, u32 reg, u64 val, int *err);Quoted 5 lines
Quoted 5 lines
Quoted 5 lines
+
+ /* Configure the PLL. */
+ cci_write(sensor->regmap,IMX111_PRE_PLL_CLK_DIVIDER_PLL1, +sensor->pll->pre_div, &ret);I'm very surprised this doesn't sometimes fail as ret is not initialized
Quoted 11 lines
Quoted 11 lines
Quoted 7 lines
+ cci_write(sensor->regmap,
IMX111_PLL_MULTIPLIER_PLL1,sensor->pll->mult, &ret); + cci_write(sensor->regmap,IMX111_POST_DIVIDER,IMX111_POST_DIVIDER_DIV1, &ret); + cci_write(sensor->regmap,IMX111_PLL_SETTLING_TIME,
+to_settle_delay(sensor->pll->extclk_rate), &ret);
+
+ ret = cci_multi_reg_write(sensor->regmap,imx111_global_init,
+ARRAY_SIZE(imx111_global_init), NULL);You are overwriting the previous errors.
please use ret |=
or you can pass ret to
cci_multi_reg_write()as wellMaybe that's why you don't see errors causes by uninitialized ret ?
Quoted 52 lines
Quoted 51 lines
drivers/media/i2c/imx111.c line 977
Quoted 8 lines
+ if (ret < 0) {
+ dev_err(dev, "Failed to initialize the sensor\n"); + return ret;
+ }drivers/media/i2c/imx111.c new file +3
-0+ + return 0; +}---
Quoted 27 lines
drivers/media/i2c/imx111.c new file +27
-0+static int imx111_set_format (struct v4l2_subdev *sd, + struct v4l2_subdev_state *state, + struct v4l2_subdev_format *format) +{ + 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); + + 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) { + sensor->cur_mode = mode; + sensor->data_depth = imx111_get_format_bpp(fmt); + __v4l2_ctrl_s_ctrl_int64(sensor->pixel_rate, + div_u64(sensor->pixel_clk_raw, 2 * sensor->data_depth));drivers/media/i2c/imx111.c line 1129
Quoted 10 lines
drivers/media/i2c/imx111.c new file +10
-0+ + __v4l2_ctrl_modify_range(sensor->vblank, IMX111_VBLANK_MIN, + IMX111_VTL_MAX - mode->height, 1, + mode->vtl_def - mode->height); + __v4l2_ctrl_s_ctrl(sensor->vblank, mode->vtl_def - mode->height); + + __v4l2_ctrl_modify_range(sensor->hblank, IMX111_HBLANK_MIN, + IMX111_HTL_MAX - mode->width, 1, + mode->htl_def - mode->width); + __v4l2_ctrl_s_ctrl(sensor->hblank, mode->htl_def - mode->width);All the above V4L2 operations need to check for errors.
Quoted 7 lines
Quoted 2 lines
yet again imx219 and imx319 do not check any of those
And we recently got an error on imx219 controls update that went unnoticed because of this and I'm now fixing 40+ drivers because this has been copied over and over. Want to make them 41 ?
There will pop 41 - 42 - 43 if documentation continues pointing to outdated driver as a reference.
Quoted 57 lines
Quoted 48 lines
Quoted 48 lines
drivers/media/i2c/imx111.c line 977
Quoted 4 lines
+ }
drivers/media/i2c/imx111.c new file +3
-0+ + return 0; +}---
Quoted 7 lines
drivers/media/i2c/imx111.c new file +7
-0+static int imx111_identify_module (struct imx111 *sensor) +{ + struct device *dev = regmap_get_device(sensor->regmap); + u64 value, revision, manufacturer; + int ret; + + ret = cci_read(sensor->regmap, IMX111_PRODUCT_ID, &value, NULL);drivers/media/i2c/imx111.c line 1319
Quoted 10 lines
drivers/media/i2c/imx111.c new file +10
-0+ if (ret) + return ret; + + if (value != IMX111_CHIP_ID) { + dev_err(dev, "chip id mismatch: %x!=%04llx", IMX111_CHIP_ID, value); + return -ENXIO; + } + + cci_read(sensor->regmap, IMX111_REVISION, &revision, NULL); + cci_read(sensor->regmap, IMX111_MANUFACTURER_ID, &manufacturer, NULL);Instead of NULL, pass ret for the error code, and return ret at the end.
Quoted 21 lines
drivers/media/i2c/imx111.c new file +21
-0+ + dev_dbg(dev, "module IMX%03llx rev. %llu manufacturer %llu\n", + value, revision, manufacturer); + + return 0; +} + +static int imx111_clk_init (struct imx111 *sensor) +{ + struct device *dev = regmap_get_device(sensor->regmap); + u32 ndata_lanes = sensor->bus_cfg.bus.mipi_csi2.num_data_lanes; + u64 extclk_rate, system_clk; + unsigned int i; + + extclk_rate = clk_get_rate(sensor->extclk); + if (!extclk_rate) + return dev_err_probe(dev, -EINVAL, "EXTCLK rate unknown\n"); + + for (i = 0; i < ARRAY_SIZE(imx111_pll); i++) { + if (clk_get_rate(sensor->extclk) == imx111_pll[i].extclk_rate) { + sensor->pll = &imx111_pll[i];Quoted 8 lines
Quoted 8 lines
Quoted 5 lines
+ break;
+ }
+ }
+ if (!sensor->pll)
+ returndev_err_probe(dev, -EINVAL, "Unsupported EXTCLK rate %llu\n", extclk_rate);Max line length should be 80 columns. This applies everywhere the line length exceeds 80 characters.
Quoted 9 lines
In response to your reply in a separate email:
https://www.kernel.org/doc/html/latest/driver-api/media/maintainer-entry-profile.html#coding-style-addendum
Media development uses checkpatch.pl on strict mode to verify the code style, e.g.:$ ./scripts/checkpatch.pl --strict --max-line-length=80I don't like being that strict too. Feel free to send a patch, you'll have my ack
Oh God, I would like to but I don't want to touch this more than I need to. I have not faced such restrictiveness in any other kernel subsystem so far.
"People with restrictive hardware shouldn't make it more inconvenient for people who have better resources. Yes, we'll accommodate things to within reasonable limits. But no, 80-column terminals in 2020 isn't "reasonable" any more as far as I'm concerned. People commonly used 132-column terminals even back in the 80's, for chrissake, don't try to make 80 columns some immovable standard."
Quoted 53 lines
Quoted 53 lines
Quoted 53 lines
Quoted 17 lines
drivers/media/i2c/imx111.c new file +16
-0+ + system_clk = div_u64(extclk_rate, sensor->pll->pre_div) * sensor->pll->mult; + + /* + * Pixel clock or Logic clock is used for internal image processing is + * generated by dividing into 1/10 or 1/8 frequency according to the + * word length of the CSI2 interface. This clock is designating the pixel + * rate and used as the base of integration time, frame rate etc. + */ + sensor->pixel_clk_raw = system_clk * ndata_lanes; + + /* + * The CSI-2 bus is clocked for 16-bit per pixel, transmitted in DDR over n lanes + * for RAW10 default format. + */ + sensor->default_link_freq = div_u64(sensor->pixel_clk_raw * 8,drivers/media/i2c/imx111.c line 1371
Quoted 10 lines
drivers/media/i2c/imx111.c new file +10
-0+ 2 * IMX111_DATA_DEPTH_RAW10); + + if (sensor->bus_cfg.nr_of_link_frequencies != 1 || + sensor->bus_cfg.link_frequencies[0] != sensor->default_link_freq) + return dev_err_probe(dev, -EINVAL, + "Unsupported DT link-frequencies, expected %llu\n", + sensor->default_link_freq); + + return 0; +}---
Quoted 10 lines
drivers/media/i2c/imx111.c new file +10
-0+static const struct of_device_id imx111_of_match[] = { + { .compatible = "sony,imx111" }, + { /* sentinel */ } +}; +MODULE_DEVICE_TABLE (of, imx111_of_match); + +static struct i2c_driver imx111_i2c_driver = { + .driver = { + .name = "imx111", + .of_match_table = imx111_of_match,drivers/media/i2c/imx111.c line 1548
Quoted 10 lines
drivers/media/i2c/imx111.c new file +10
-0+ .pm = &imx111_pm_ops, + }, + .probe = imx111_probe, + .remove = imx111_remove, +}; +module_i2c_driver (imx111_i2c_driver); + +MODULE_AUTHOR ("Svyatoslav Ryhel <[email protected]>" ); +MODULE_DESCRIPTION ("Sony IMX111 CMOS Image Sensor driver" ); +MODULE_LICENSE ("GPL" );Best Regards,
Tarang
Hi Svyatoslav
Quoted 59 lines · Svyatoslav Ryhel
чт, 30 жовт. 2025 р. о 17:50 Jacopo Mondi <[email protected]> пише:
Quoted 51 lines
Hello,
sorry for entering the conversationQuoted 37 lines · Svyatoslav Ryhel
чт, 30 жовт. 2025 р. о 16:55 Tarang Raval <[email protected]> пише:
Quoted 22 lines
Hi Svyatoslav,
Quoted 10 lines
Add 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 SGBRG8Quoted 6 lines
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.
Signed-off-by Svyatoslav Ryhel <[email protected]>---
Quoted 13 lines
drivers/media/i2c/imx111.c line 762
Quoted 9 lines
drivers/media/i2c/imx111.c new file +9
-0+static int imx111_set_ctrl (struct v4l2_ctrl *ctrl) +{ + struct imx111 *sensor = ctrl_to_imx111(ctrl); + struct device *dev = regmap_get_device(sensor->regmap); + s64 max; + int ret = 0; + + /* Propagate change of current control to all related controls */ + switch (ctrl->id) {Do we need the switch statement, since only one case is present? You can use an 'if' instead.
Quoted 4 lines
imx219 and imx319 which are recommended references use switch, and it seems that media maintainters are particularly picky to code style, I have copied it from there.
Personally, whenever doing reviews, receiving a reply that ignores the merit of the comment and simply refers to the existing code base as an excuse for not caring, it's what put me off the most.
Quoted 6 lines
Please respect the time reviewers have invested in looking at your code by at least considering their comment instead of dismissing them. In this specific case you could have easily said "I like it more this way and it's consistent with what other drivers do". The same cannot be said for other comments that you have decided to ignore.
Quoted 4 lines
I did not state that I will ignore all the comments. Contrary, I will be applying most/all of them. My point is that Linux kernel documentation, which Sakari Ailus (not an offence or blaming) pointed in v2 clearly pointed to imx219 and imx319 as an valid reference
I don't think imx219 is outdated, it's actually one of the most developed one and is a very good reference. Simply, it's not perfect, and we keep finding bugs that you could avoid from the very beginning if you take the time to look into comments you receive.
Quoted 4 lines
drivers, while they seem to be outdated. So by using those as reference I wasted both my time and maintainers time. You say "Please respect the time reviewers" but no one respects my time.
I'm sorry if you feel disrispected but I think you have been pointed to the best reference we have that simply happens not to be perfect ?
And you might ask "if they got a pass for broken code, why didn't I get one" ? This is not what's happening though, nobody got a pass, simply changing code that is already mainline takes more effort and motivation and if we can avoid bugs from the very beginning we should do so (otherwise someone will have to fix it later on).
Quoted 227 lines
Quoted 227 lines
Quoted 11 lines
Quoted 8 lines
Quoted 4 lines
+ case
V4L2_CID_VBLANK:
+ /* Update max exposure while meeting expected vblanking */ + max =sensor->cur_mode->height+ctrl->val- 5;You can define a macro for the value 5 to improve readability. Also, make this change in the
init_controlfunction.imx219 does not specifies this as a define
It doesn't but it should, like 90% of other drivers in mainline do
Quoted 9 lines
Quoted 6 lines
Quoted 3 lines
+ __v4l2_ctrl_modify_range(sensor->exposure, +
sensor->exposure->minimum, + max,sensor->exposure->step, max);This may fail; consider adding an error check.
imx219 does not return error here too
so ?
Quoted 200 lines
Quoted 89 lines
Quoted 76 lines
+ break;
+ }drivers/media/i2c/imx111.c new file +74
-0+ + /* + * Applying V4L2 control value only happens + * when power is up for streaming + */ + if (!pm_runtime_get_if_in_use(dev)) + return 0; + + switch (ctrl->id) { + case V4L2_CID_ANALOGUE_GAIN: + cci_write(sensor->regmap, IMX111_REG_ANALOG_GAIN, ctrl->val, &ret); + break; + case V4L2_CID_DIGITAL_GAIN: + ret = imx111_update_digital_gain(sensor, ctrl->val); + break; + case V4L2_CID_EXPOSURE: + cci_update_bits(sensor->regmap, IMX111_GROUP_WRITE, IMX111_GROUP_WRITE_ON, + IMX111_GROUP_WRITE_ON, &ret); + cci_write(sensor->regmap, IMX111_INTEGRATION_TIME, ctrl->val, &ret); + cci_update_bits(sensor->regmap, IMX111_GROUP_WRITE, IMX111_GROUP_WRITE_ON, + 0, &ret); + break; + case V4L2_CID_HBLANK: + cci_update_bits(sensor->regmap, IMX111_GROUP_WRITE, IMX111_GROUP_WRITE_ON, + IMX111_GROUP_WRITE_ON, &ret); + dev_err(dev, "writing 0x%x to HTL\n", sensor->cur_mode->width + ctrl->val); + cci_write(sensor->regmap, IMX111_HORIZONTAL_TOTAL_LENGTH, + sensor->cur_mode->width + ctrl->val, &ret); + cci_update_bits(sensor->regmap, IMX111_GROUP_WRITE, IMX111_GROUP_WRITE_ON, + 0, &ret); + break; + case V4L2_CID_VBLANK: + cci_update_bits(sensor->regmap, IMX111_GROUP_WRITE, IMX111_GROUP_WRITE_ON, + IMX111_GROUP_WRITE_ON, &ret); + dev_err(dev, "writing 0x%x to VTL\n", sensor->cur_mode->height + ctrl->val); + cci_write(sensor->regmap, IMX111_VERTICAL_TOTAL_LENGTH, + sensor->cur_mode->height + ctrl->val, &ret); + cci_update_bits(sensor->regmap, IMX111_GROUP_WRITE, IMX111_GROUP_WRITE_ON, + 0, &ret); + break; + case V4L2_CID_HFLIP: + case V4L2_CID_VFLIP: + cci_write(sensor->regmap, IMX111_IMAGE_ORIENTATION, + sensor->hflip->val | sensor->vflip->val << 1, &ret); + break; + case V4L2_CID_TEST_PATTERN: + cci_write(sensor->regmap, IMX111_TEST_PATTERN, ctrl->val, &ret); + break; + case V4L2_CID_TEST_PATTERN_RED: + cci_update_bits(sensor->regmap, IMX111_GROUP_WRITE, IMX111_GROUP_WRITE_ON, + IMX111_GROUP_WRITE_ON, &ret); + cci_write(sensor->regmap, IMX111_SOLID_COLOR_RED, ctrl->val, &ret); + cci_update_bits(sensor->regmap, IMX111_GROUP_WRITE, IMX111_GROUP_WRITE_ON, + 0, &ret); + break; + case V4L2_CID_TEST_PATTERN_GREENR: + cci_update_bits(sensor->regmap, IMX111_GROUP_WRITE, IMX111_GROUP_WRITE_ON, + IMX111_GROUP_WRITE_ON, &ret); + cci_write(sensor->regmap, IMX111_SOLID_COLOR_GR, ctrl->val, &ret); + cci_update_bits(sensor->regmap, IMX111_GROUP_WRITE, IMX111_GROUP_WRITE_ON, + 0, &ret); + break; + case V4L2_CID_TEST_PATTERN_BLUE: + cci_update_bits(sensor->regmap, IMX111_GROUP_WRITE, IMX111_GROUP_WRITE_ON, + IMX111_GROUP_WRITE_ON, &ret); + cci_write(sensor->regmap, IMX111_SOLID_COLOR_BLUE, ctrl->val, &ret); + cci_update_bits(sensor->regmap, IMX111_GROUP_WRITE, IMX111_GROUP_WRITE_ON, + 0, &ret); + break; + case V4L2_CID_TEST_PATTERN_GREENB: + cci_update_bits(sensor->regmap, IMX111_GROUP_WRITE, IMX111_GROUP_WRITE_ON, + IMX111_GROUP_WRITE_ON, &ret); + cci_write(sensor->regmap, IMX111_SOLID_COLOR_GB, ctrl->val, &ret); + cci_update_bits(sensor->regmap, IMX111_GROUP_WRITE, IMX111_GROUP_WRITE_ON,drivers/media/i2c/imx111.c line 854
Quoted 10 lines
drivers/media/i2c/imx111.c new file +10
-0+ 0, &ret); + break; + default: + ret = -EINVAL; + } + + pm_runtime_put(dev); + + return ret; +}---
Quoted 10 lines
drivers/media/i2c/imx111.c line 874
Quoted 7 lines
drivers/media/i2c/imx111.c new file +7
-0+static int imx111_init_controls (struct imx111 *sensor) +{ + const struct v4l2_ctrl_ops *ops = &imx111_ctrl_ops; + struct device *dev = regmap_get_device(sensor->regmap); + const struct imx111_mode *mode = sensor->cur_mode; + struct v4l2_fwnode_device_properties props; + struct v4l2_subdev *sd = &sensor->sd;No need for a new variable; there is only one user in the function.
This make code reading cleaner, no?
Quoted 97 lines
drivers/media/i2c/imx111.c line 883
Quoted 9 lines
+ struct
v4l2_ctrl_handler*hdl =&sensor->hdl;
+ s64pixel_rate_min,pixel_rate_max;
+ int i, ret;drivers/media/i2c/imx111.c new file +6
-0+ + ret = v4l2_fwnode_device_parse(dev, &props); + if (ret < 0) + return ret; + + ret = v4l2_ctrl_handler_init(hdl, 13);Now there are 15 controls.
No need for explicit error checking; you can omit the error check if you'd like.
Quoted 63 lines
+ if (ret)
+ return ret;drivers/media/i2c/imx111.c new file +61
-0+ + pixel_rate_min = div_u64(sensor->pixel_clk_raw, 2 * IMX111_DATA_DEPTH_RAW10); + pixel_rate_max = div_u64(sensor->pixel_clk_raw, 2 * IMX111_DATA_DEPTH_RAW8); + sensor->pixel_rate = v4l2_ctrl_new_std(hdl, NULL, V4L2_CID_PIXEL_RATE, + pixel_rate_min, pixel_rate_max, + 1, div_u64(sensor->pixel_clk_raw, + 2 * sensor->data_depth)); + + sensor->link_freq = v4l2_ctrl_new_int_menu(hdl, NULL, V4L2_CID_LINK_FREQ, + 0, 0, &sensor->default_link_freq); + if (sensor->link_freq) + sensor->link_freq->flags |= V4L2_CTRL_FLAG_READ_ONLY; + + v4l2_ctrl_new_std(hdl, ops, V4L2_CID_ANALOGUE_GAIN, + IMX111_ANA_GAIN_MIN, IMX111_ANA_GAIN_MAX, + IMX111_ANA_GAIN_STEP, IMX111_ANA_GAIN_DEFAULT); + + v4l2_ctrl_new_std(hdl, ops, V4L2_CID_DIGITAL_GAIN, + IMX111_DGTL_GAIN_MIN, IMX111_DGTL_GAIN_MAX, + IMX111_DGTL_GAIN_STEP, IMX111_DGTL_GAIN_DEFAULT); + + sensor->hflip = v4l2_ctrl_new_std(hdl, ops, V4L2_CID_HFLIP, 0, 1, 1, 0); + if (sensor->hflip) + sensor->hflip->flags |= V4L2_CTRL_FLAG_MODIFY_LAYOUT; + + sensor->vflip = v4l2_ctrl_new_std(hdl, ops, V4L2_CID_VFLIP, 0, 1, 1, 0); + if (sensor->vflip) + sensor->vflip->flags |= V4L2_CTRL_FLAG_MODIFY_LAYOUT; + + sensor->vblank = v4l2_ctrl_new_std(hdl, ops, V4L2_CID_VBLANK, IMX111_VBLANK_MIN, + IMX111_VTL_MAX - mode->height, 1, + mode->vtl_def - mode->height); + sensor->hblank = v4l2_ctrl_new_std(hdl, ops, V4L2_CID_HBLANK, IMX111_HBLANK_MIN, + IMX111_HTL_MAX - mode->width, 1, + mode->htl_def - mode->width); + + /* + * The maximum coarse integration time is the frame length in lines + * minus five. + */ + sensor->exposure = v4l2_ctrl_new_std(hdl, ops, V4L2_CID_EXPOSURE, + IMX111_INTEGRATION_TIME_MIN, + IMX111_PIXEL_ARRAY_HEIGHT - 5, + IMX111_INTEGRATION_TIME_STEP, + IMX111_PIXEL_ARRAY_HEIGHT - 5); + + v4l2_ctrl_new_fwnode_properties(hdl, ops, &props); + + v4l2_ctrl_new_std_menu_items(hdl, ops, V4L2_CID_TEST_PATTERN, + ARRAY_SIZE(test_pattern_menu) - 1, 0, 0, + test_pattern_menu); + for (i = 0; i < 4; i++) { + /* + * The assumption is that + * V4L2_CID_TEST_PATTERN_GREENR == V4L2_CID_TEST_PATTERN_RED + 1 + * V4L2_CID_TEST_PATTERN_BLUE == V4L2_CID_TEST_PATTERN_RED + 2 + * V4L2_CID_TEST_PATTERN_GREENB == V4L2_CID_TEST_PATTERN_RED + 3 + */ + v4l2_ctrl_new_std(hdl, ops, V4L2_CID_TEST_PATTERN_RED + i, + IMX111_TESTP_COLOUR_MIN, IMX111_TESTP_COLOUR_MAX, + IMX111_TESTP_COLOUR_STEP, IMX111_TESTP_COLOUR_MAX);drivers/media/i2c/imx111.c line 956
Quoted 10 lines
drivers/media/i2c/imx111.c new file +10
-0+ /* The "Solid color" pattern is white by default */ + } + + if (hdl->error) + return hdl->error; + + sd->ctrl_handler = hdl; + + return 0; +};---
drivers/media/i2c/imx111.c line 1034
Quoted 4 lines
drivers/media/i2c/imx111.c new file +4
-0+static int imx111_initialize (struct imx111 *sensor) +{ + struct device *dev = regmap_get_device(sensor->regmap); + int ret;ret = 0;
Quoted 4 lines
Quoted 4 lines
Quoted 1 line
cci_writedoes not state that ret must be initiated.Could you at least take the time to read the code ?
To be honest, this is what had me jump into this conversation as an indication you had not really put attention to the comments you received.
Quoted 177 lines
Quoted 103 lines
int
cci_write(struct regmap *map, u32 reg, u64 val, int *err){ bool little_endian; unsigned int len; u8 buf[8]; int ret; if (err && *err) return *err;And by the way, the documentation says:
/**
*cci_write()- Write a value to a single CCI register
*
* @map: Register map to write to
* @reg: Register address to write, use CCI_REG#() macros to encode reg width
* @val: Value to be written
* @err: Optional pointer to store errors, if a previous error is set
* then the write will be skipped
*
* Return: %0 on success or a negative error code on failure.
*/
intcci_write(struct regmap *map, u32 reg, u64 val, int *err);Quoted 5 lines
Quoted 5 lines
Quoted 5 lines
+
+ /* Configure the PLL. */
+ cci_write(sensor->regmap,IMX111_PRE_PLL_CLK_DIVIDER_PLL1, +sensor->pll->pre_div, &ret);I'm very surprised this doesn't sometimes fail as ret is not initialized
Quoted 11 lines
Quoted 11 lines
Quoted 7 lines
+ cci_write(sensor->regmap,
IMX111_PLL_MULTIPLIER_PLL1,sensor->pll->mult, &ret); + cci_write(sensor->regmap,IMX111_POST_DIVIDER,IMX111_POST_DIVIDER_DIV1, &ret); + cci_write(sensor->regmap,IMX111_PLL_SETTLING_TIME,
+to_settle_delay(sensor->pll->extclk_rate), &ret);
+
+ ret = cci_multi_reg_write(sensor->regmap,imx111_global_init,
+ARRAY_SIZE(imx111_global_init), NULL);You are overwriting the previous errors.
please use ret |=
or you can pass ret to
cci_multi_reg_write()as wellMaybe that's why you don't see errors causes by uninitialized ret ?
Quoted 52 lines
Quoted 51 lines
drivers/media/i2c/imx111.c line 977
Quoted 8 lines
+ if (ret < 0) {
+ dev_err(dev, "Failed to initialize the sensor\n"); + return ret;
+ }drivers/media/i2c/imx111.c new file +3
-0+ + return 0; +}---
Quoted 27 lines
drivers/media/i2c/imx111.c new file +27
-0+static int imx111_set_format (struct v4l2_subdev *sd, + struct v4l2_subdev_state *state, + struct v4l2_subdev_format *format) +{ + 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); + + 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) { + sensor->cur_mode = mode; + sensor->data_depth = imx111_get_format_bpp(fmt); + __v4l2_ctrl_s_ctrl_int64(sensor->pixel_rate, + div_u64(sensor->pixel_clk_raw, 2 * sensor->data_depth));drivers/media/i2c/imx111.c line 1129
Quoted 10 lines
drivers/media/i2c/imx111.c new file +10
-0+ + __v4l2_ctrl_modify_range(sensor->vblank, IMX111_VBLANK_MIN, + IMX111_VTL_MAX - mode->height, 1, + mode->vtl_def - mode->height); + __v4l2_ctrl_s_ctrl(sensor->vblank, mode->vtl_def - mode->height); + + __v4l2_ctrl_modify_range(sensor->hblank, IMX111_HBLANK_MIN, + IMX111_HTL_MAX - mode->width, 1, + mode->htl_def - mode->width); + __v4l2_ctrl_s_ctrl(sensor->hblank, mode->htl_def - mode->width);All the above V4L2 operations need to check for errors.
Quoted 7 lines
Quoted 2 lines
yet again imx219 and imx319 do not check any of those
And we recently got an error on imx219 controls update that went unnoticed because of this and I'm now fixing 40+ drivers because this has been copied over and over. Want to make them 41 ?
There will pop 41 - 42 - 43 if documentation continues pointing to outdated driver as a reference.
Quoted 63 lines
Quoted 48 lines
Quoted 48 lines
drivers/media/i2c/imx111.c line 977
Quoted 4 lines
+ }
drivers/media/i2c/imx111.c new file +3
-0+ + return 0; +}---
Quoted 7 lines
drivers/media/i2c/imx111.c new file +7
-0+static int imx111_identify_module (struct imx111 *sensor) +{ + struct device *dev = regmap_get_device(sensor->regmap); + u64 value, revision, manufacturer; + int ret; + + ret = cci_read(sensor->regmap, IMX111_PRODUCT_ID, &value, NULL);drivers/media/i2c/imx111.c line 1319
Quoted 10 lines
drivers/media/i2c/imx111.c new file +10
-0+ if (ret) + return ret; + + if (value != IMX111_CHIP_ID) { + dev_err(dev, "chip id mismatch: %x!=%04llx", IMX111_CHIP_ID, value); + return -ENXIO; + } + + cci_read(sensor->regmap, IMX111_REVISION, &revision, NULL); + cci_read(sensor->regmap, IMX111_MANUFACTURER_ID, &manufacturer, NULL);Instead of NULL, pass ret for the error code, and return ret at the end.
Quoted 21 lines
drivers/media/i2c/imx111.c new file +21
-0+ + dev_dbg(dev, "module IMX%03llx rev. %llu manufacturer %llu\n", + value, revision, manufacturer); + + return 0; +} + +static int imx111_clk_init (struct imx111 *sensor) +{ + struct device *dev = regmap_get_device(sensor->regmap); + u32 ndata_lanes = sensor->bus_cfg.bus.mipi_csi2.num_data_lanes; + u64 extclk_rate, system_clk; + unsigned int i; + + extclk_rate = clk_get_rate(sensor->extclk); + if (!extclk_rate) + return dev_err_probe(dev, -EINVAL, "EXTCLK rate unknown\n"); + + for (i = 0; i < ARRAY_SIZE(imx111_pll); i++) { + if (clk_get_rate(sensor->extclk) == imx111_pll[i].extclk_rate) { + sensor->pll = &imx111_pll[i];Quoted 8 lines
Quoted 8 lines
Quoted 5 lines
+ break;
+ }
+ }
+ if (!sensor->pll)
+ returndev_err_probe(dev, -EINVAL, "Unsupported EXTCLK rate %llu\n", extclk_rate);Max line length should be 80 columns. This applies everywhere the line length exceeds 80 characters.
In response to your reply in a separate email:
https://www.kernel.org/doc/html/latest/driver-api/media/maintainer-entry-profile.html#coding-style-addendum
Media development uses checkpatch.pl on strict mode to verify the code style, e.g.:$ ./scripts/checkpatch.pl --strict --max-line-length=80
Quoted 8 lines
Quoted 3 lines
I don't like being that strict too. Feel free to send a patch, you'll have my ack
Oh God, I would like to but I don't want to touch this more than I need to. I have not faced such restrictiveness in any other kernel subsystem so far.
I agree we should move over 80 cols, it's a discussion we already had many times but if rules have to be changed they have to be changed at the subsystem level, not because you and me dislike them.
I'll ignore the following as it doesn't add anything to the conversation.
Quoted 60 lines
"People with restrictive hardware shouldn't make it more inconvenient for people who have better resources. Yes, we'll accommodate things to within reasonable limits. But no, 80-column terminals in 2020 isn't "reasonable" any more as far as I'm concerned. People commonly used 132-column terminals even back in the 80's, for chrissake, don't try to make 80 columns some immovable standard."
Quoted 53 lines
Quoted 53 lines
Quoted 53 lines
Quoted 17 lines
drivers/media/i2c/imx111.c new file +16
-0+ + system_clk = div_u64(extclk_rate, sensor->pll->pre_div) * sensor->pll->mult; + + /* + * Pixel clock or Logic clock is used for internal image processing is + * generated by dividing into 1/10 or 1/8 frequency according to the + * word length of the CSI2 interface. This clock is designating the pixel + * rate and used as the base of integration time, frame rate etc. + */ + sensor->pixel_clk_raw = system_clk * ndata_lanes; + + /* + * The CSI-2 bus is clocked for 16-bit per pixel, transmitted in DDR over n lanes + * for RAW10 default format. + */ + sensor->default_link_freq = div_u64(sensor->pixel_clk_raw * 8,drivers/media/i2c/imx111.c line 1371
Quoted 10 lines
drivers/media/i2c/imx111.c new file +10
-0+ 2 * IMX111_DATA_DEPTH_RAW10); + + if (sensor->bus_cfg.nr_of_link_frequencies != 1 || + sensor->bus_cfg.link_frequencies[0] != sensor->default_link_freq) + return dev_err_probe(dev, -EINVAL, + "Unsupported DT link-frequencies, expected %llu\n", + sensor->default_link_freq); + + return 0; +}---
Quoted 10 lines
drivers/media/i2c/imx111.c new file +10
-0+static const struct of_device_id imx111_of_match[] = { + { .compatible = "sony,imx111" }, + { /* sentinel */ } +}; +MODULE_DEVICE_TABLE (of, imx111_of_match); + +static struct i2c_driver imx111_i2c_driver = { + .driver = { + .name = "imx111", + .of_match_table = imx111_of_match,drivers/media/i2c/imx111.c line 1548
Quoted 10 lines
drivers/media/i2c/imx111.c new file +10
-0+ .pm = &imx111_pm_ops, + }, + .probe = imx111_probe, + .remove = imx111_remove, +}; +module_i2c_driver (imx111_i2c_driver); + +MODULE_AUTHOR ("Svyatoslav Ryhel <[email protected]>" ); +MODULE_DESCRIPTION ("Sony IMX111 CMOS Image Sensor driver" ); +MODULE_LICENSE ("GPL" );Best Regards,
Tarang
Hi Svyatoslav,
Quoted 60 lines · Svyatoslav Ryhel
Quoted 59 lines
чт, 30 жовт. 2025 р. о 17:50 Jacopo Mondi <[email protected]> пише:
Quoted 57 lines
Hello,
sorry for entering the conversationQuoted 37 lines · Svyatoslav Ryhel
чт, 30 жовт. 2025 р. о 16:55 Tarang Raval <[email protected]> пише:
Quoted 22 lines
Hi Svyatoslav,
Quoted 10 lines
Add 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 SGBRG8Quoted 6 lines
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.
Signed-off-by Svyatoslav Ryhel <[email protected]>---
Quoted 13 lines
drivers/media/i2c/imx111.c line 762
Quoted 9 lines
drivers/media/i2c/imx111.c new file +9
-0+static int imx111_set_ctrl (struct v4l2_ctrl *ctrl) +{ + struct imx111 *sensor = ctrl_to_imx111(ctrl); + struct device *dev = regmap_get_device(sensor->regmap); + s64 max; + int ret = 0; + + /* Propagate change of current control to all related controls */ + switch (ctrl->id) {Do we need the switch statement, since only one case is present? You can use an 'if' instead.
Quoted 4 lines
imx219 and imx319 which are recommended references use switch, and it seems that media maintainters are particularly picky to code style, I have copied it from there.
Personally, whenever doing reviews, receiving a reply that ignores the merit of the comment and simply refers to the existing code base as an excuse for not caring, it's what put me off the most.
Please respect the time reviewers have invested in looking at your code by at least considering their comment instead of dismissing them. In this specific case you could have easily said "I like it more this way and it's consistent with what other drivers do". The same cannot be said for other comments that you have decided to ignore.
Quoted 4 lines
Quoted 4 lines
I did not state that I will ignore all the comments. Contrary, I will be applying most/all of them. My point is that Linux kernel documentation, which Sakari Ailus (not an offence or blaming) pointed in v2 clearly pointed to imx219 and imx319 as an valid reference
I believe you can refer to any recently merged camera sensor driver, as it will likely cover the necessary points.
Quoted 9 lines
I don't think imx219 is outdated, it's actually one of the most developed one and is a very good reference. Simply, it's not perfect, and we keep finding bugs that you could avoid from the very beginning if you take the time to look into comments you receive.
Quoted 3 lines
drivers, while they seem to be outdated. So by using those as reference I wasted both my time and maintainers time. You say "Please respect the time reviewers" but no one respects my time.
Quoted 239 lines
I'm sorry if you feel disrispected but I think you have been pointed to the best reference we have that simply happens not to be perfect ?
And you might ask "if they got a pass for broken code, why didn't I get one" ? This is not what's happening though, nobody got a pass, simply changing code that is already mainline takes more effort and motivation and if we can avoid bugs from the very beginning we should do so (otherwise someone will have to fix it later on).Quoted 229 lines
Quoted 229 lines
Quoted 11 lines
Quoted 8 lines
Quoted 4 lines
+ case
V4L2_CID_VBLANK:
+ /* Update max exposure while meeting expected vblanking */ + max =sensor->cur_mode->height+ctrl->val- 5;You can define a macro for the value 5 to improve readability. Also, make this change in the
init_controlfunction.imx219 does not specifies this as a define
It doesn't but it should, like 90% of other drivers in mainline do
Quoted 9 lines
Quoted 6 lines
Quoted 3 lines
+ __v4l2_ctrl_modify_range(sensor->exposure, +
sensor->exposure->minimum, + max,sensor->exposure->step, max);This may fail; consider adding an error check.
imx219 does not return error here too
so ?
Quoted 201 lines
Quoted 89 lines
Quoted 76 lines
+ break;
+ }drivers/media/i2c/imx111.c new file +74
-0+ + /* + * Applying V4L2 control value only happens + * when power is up for streaming + */ + if (!pm_runtime_get_if_in_use(dev)) + return 0; + + switch (ctrl->id) { + case V4L2_CID_ANALOGUE_GAIN: + cci_write(sensor->regmap, IMX111_REG_ANALOG_GAIN, ctrl->val, &ret); + break; + case V4L2_CID_DIGITAL_GAIN: + ret = imx111_update_digital_gain(sensor, ctrl->val); + break; + case V4L2_CID_EXPOSURE: + cci_update_bits(sensor->regmap, IMX111_GROUP_WRITE, IMX111_GROUP_WRITE_ON, + IMX111_GROUP_WRITE_ON, &ret); + cci_write(sensor->regmap, IMX111_INTEGRATION_TIME, ctrl->val, &ret); + cci_update_bits(sensor->regmap, IMX111_GROUP_WRITE, IMX111_GROUP_WRITE_ON, + 0, &ret); + break; + case V4L2_CID_HBLANK: + cci_update_bits(sensor->regmap, IMX111_GROUP_WRITE, IMX111_GROUP_WRITE_ON, + IMX111_GROUP_WRITE_ON, &ret); + dev_err(dev, "writing 0x%x to HTL\n", sensor->cur_mode->width + ctrl->val); + cci_write(sensor->regmap, IMX111_HORIZONTAL_TOTAL_LENGTH, + sensor->cur_mode->width + ctrl->val, &ret); + cci_update_bits(sensor->regmap, IMX111_GROUP_WRITE, IMX111_GROUP_WRITE_ON, + 0, &ret); + break; + case V4L2_CID_VBLANK: + cci_update_bits(sensor->regmap, IMX111_GROUP_WRITE, IMX111_GROUP_WRITE_ON, + IMX111_GROUP_WRITE_ON, &ret); + dev_err(dev, "writing 0x%x to VTL\n", sensor->cur_mode->height + ctrl->val); + cci_write(sensor->regmap, IMX111_VERTICAL_TOTAL_LENGTH, + sensor->cur_mode->height + ctrl->val, &ret); + cci_update_bits(sensor->regmap, IMX111_GROUP_WRITE, IMX111_GROUP_WRITE_ON, + 0, &ret); + break; + case V4L2_CID_HFLIP: + case V4L2_CID_VFLIP: + cci_write(sensor->regmap, IMX111_IMAGE_ORIENTATION, + sensor->hflip->val | sensor->vflip->val << 1, &ret); + break; + case V4L2_CID_TEST_PATTERN: + cci_write(sensor->regmap, IMX111_TEST_PATTERN, ctrl->val, &ret); + break; + case V4L2_CID_TEST_PATTERN_RED: + cci_update_bits(sensor->regmap, IMX111_GROUP_WRITE, IMX111_GROUP_WRITE_ON, + IMX111_GROUP_WRITE_ON, &ret); + cci_write(sensor->regmap, IMX111_SOLID_COLOR_RED, ctrl->val, &ret); + cci_update_bits(sensor->regmap, IMX111_GROUP_WRITE, IMX111_GROUP_WRITE_ON, + 0, &ret); + break; + case V4L2_CID_TEST_PATTERN_GREENR: + cci_update_bits(sensor->regmap, IMX111_GROUP_WRITE, IMX111_GROUP_WRITE_ON, + IMX111_GROUP_WRITE_ON, &ret); + cci_write(sensor->regmap, IMX111_SOLID_COLOR_GR, ctrl->val, &ret); + cci_update_bits(sensor->regmap, IMX111_GROUP_WRITE, IMX111_GROUP_WRITE_ON, + 0, &ret); + break; + case V4L2_CID_TEST_PATTERN_BLUE: + cci_update_bits(sensor->regmap, IMX111_GROUP_WRITE, IMX111_GROUP_WRITE_ON, + IMX111_GROUP_WRITE_ON, &ret); + cci_write(sensor->regmap, IMX111_SOLID_COLOR_BLUE, ctrl->val, &ret); + cci_update_bits(sensor->regmap, IMX111_GROUP_WRITE, IMX111_GROUP_WRITE_ON, + 0, &ret); + break; + case V4L2_CID_TEST_PATTERN_GREENB: + cci_update_bits(sensor->regmap, IMX111_GROUP_WRITE, IMX111_GROUP_WRITE_ON, + IMX111_GROUP_WRITE_ON, &ret); + cci_write(sensor->regmap, IMX111_SOLID_COLOR_GB, ctrl->val, &ret); + cci_update_bits(sensor->regmap, IMX111_GROUP_WRITE, IMX111_GROUP_WRITE_ON,drivers/media/i2c/imx111.c line 854
Quoted 10 lines
drivers/media/i2c/imx111.c new file +10
-0+ 0, &ret); + break; + default: + ret = -EINVAL; + } + + pm_runtime_put(dev); + + return ret; +}---
Quoted 10 lines
drivers/media/i2c/imx111.c line 874
Quoted 7 lines
drivers/media/i2c/imx111.c new file +7
-0+static int imx111_init_controls (struct imx111 *sensor) +{ + const struct v4l2_ctrl_ops *ops = &imx111_ctrl_ops; + struct device *dev = regmap_get_device(sensor->regmap); + const struct imx111_mode *mode = sensor->cur_mode; + struct v4l2_fwnode_device_properties props; + struct v4l2_subdev *sd = &sensor->sd;No need for a new variable; there is only one user in the function.
This make code reading cleaner, no?
Quoted 90 lines
drivers/media/i2c/imx111.c line 883
Quoted 9 lines
+ struct
v4l2_ctrl_handler*hdl =&sensor->hdl;
+ s64pixel_rate_min,pixel_rate_max;
+ int i, ret;drivers/media/i2c/imx111.c new file +6
-0+ + ret = v4l2_fwnode_device_parse(dev, &props); + if (ret < 0) + return ret; + + ret = v4l2_ctrl_handler_init(hdl, 13);Now there are 15 controls.
No need for explicit error checking; you can omit the error check if you'd like.
Quoted 63 lines
+ if (ret)
+ return ret;drivers/media/i2c/imx111.c new file +61
-0+ + pixel_rate_min = div_u64(sensor->pixel_clk_raw, 2 * IMX111_DATA_DEPTH_RAW10); + pixel_rate_max = div_u64(sensor->pixel_clk_raw, 2 * IMX111_DATA_DEPTH_RAW8); + sensor->pixel_rate = v4l2_ctrl_new_std(hdl, NULL, V4L2_CID_PIXEL_RATE, + pixel_rate_min, pixel_rate_max, + 1, div_u64(sensor->pixel_clk_raw, + 2 * sensor->data_depth)); + + sensor->link_freq = v4l2_ctrl_new_int_menu(hdl, NULL, V4L2_CID_LINK_FREQ, + 0, 0, &sensor->default_link_freq); + if (sensor->link_freq) + sensor->link_freq->flags |= V4L2_CTRL_FLAG_READ_ONLY; + + v4l2_ctrl_new_std(hdl, ops, V4L2_CID_ANALOGUE_GAIN, + IMX111_ANA_GAIN_MIN, IMX111_ANA_GAIN_MAX, + IMX111_ANA_GAIN_STEP, IMX111_ANA_GAIN_DEFAULT); + + v4l2_ctrl_new_std(hdl, ops, V4L2_CID_DIGITAL_GAIN, + IMX111_DGTL_GAIN_MIN, IMX111_DGTL_GAIN_MAX, + IMX111_DGTL_GAIN_STEP, IMX111_DGTL_GAIN_DEFAULT); + + sensor->hflip = v4l2_ctrl_new_std(hdl, ops, V4L2_CID_HFLIP, 0, 1, 1, 0); + if (sensor->hflip) + sensor->hflip->flags |= V4L2_CTRL_FLAG_MODIFY_LAYOUT; + + sensor->vflip = v4l2_ctrl_new_std(hdl, ops, V4L2_CID_VFLIP, 0, 1, 1, 0); + if (sensor->vflip) + sensor->vflip->flags |= V4L2_CTRL_FLAG_MODIFY_LAYOUT; + + sensor->vblank = v4l2_ctrl_new_std(hdl, ops, V4L2_CID_VBLANK, IMX111_VBLANK_MIN, + IMX111_VTL_MAX - mode->height, 1, + mode->vtl_def - mode->height); + sensor->hblank = v4l2_ctrl_new_std(hdl, ops, V4L2_CID_HBLANK, IMX111_HBLANK_MIN, + IMX111_HTL_MAX - mode->width, 1, + mode->htl_def - mode->width); + + /* + * The maximum coarse integration time is the frame length in lines + * minus five. + */ + sensor->exposure = v4l2_ctrl_new_std(hdl, ops, V4L2_CID_EXPOSURE, + IMX111_INTEGRATION_TIME_MIN, + IMX111_PIXEL_ARRAY_HEIGHT - 5, + IMX111_INTEGRATION_TIME_STEP, + IMX111_PIXEL_ARRAY_HEIGHT - 5); + + v4l2_ctrl_new_fwnode_properties(hdl, ops, &props); + + v4l2_ctrl_new_std_menu_items(hdl, ops, V4L2_CID_TEST_PATTERN, + ARRAY_SIZE(test_pattern_menu) - 1, 0, 0, + test_pattern_menu); + for (i = 0; i < 4; i++) { + /* + * The assumption is that + * V4L2_CID_TEST_PATTERN_GREENR == V4L2_CID_TEST_PATTERN_RED + 1 + * V4L2_CID_TEST_PATTERN_BLUE == V4L2_CID_TEST_PATTERN_RED + 2 + * V4L2_CID_TEST_PATTERN_GREENB == V4L2_CID_TEST_PATTERN_RED + 3 + */ + v4l2_ctrl_new_std(hdl, ops, V4L2_CID_TEST_PATTERN_RED + i, + IMX111_TESTP_COLOUR_MIN, IMX111_TESTP_COLOUR_MAX, + IMX111_TESTP_COLOUR_STEP, IMX111_TESTP_COLOUR_MAX);drivers/media/i2c/imx111.c line 956
Quoted 10 lines
drivers/media/i2c/imx111.c new file +10
-0+ /* The "Solid color" pattern is white by default */ + } + + if (hdl->error) + return hdl->error; + + sd->ctrl_handler = hdl; + + return 0; +};---
Quoted 7 lines
drivers/media/i2c/imx111.c line 1034
Quoted 4 lines
drivers/media/i2c/imx111.c new file +4
-0+static int imx111_initialize (struct imx111 *sensor) +{ + struct device *dev = regmap_get_device(sensor->regmap); + int ret;ret = 0;
cci_writedoes not state that ret must be initiated.
I think I should have explained the reasoning behind the change instead of providing a direct modification. I'll make sure to provide more context next time.
Best Regards,
Tarang
Quoting Svyatoslav Ryhel (2025-10-30 15:13:31)
...
Quoted 9 lines
Quoted 8 lines
drivers/media/i2c/imx111.c line 1034
Quoted 5 lines
drivers/media/i2c/imx111.c new file +4
-0+static int imx111_initialize (struct imx111 *sensor) +{ + struct device *dev = regmap_get_device(sensor->regmap); + int ret;ret = 0;
Quoted 6 lines
cci_writedoes not state that ret must be initiated.Quoted 4 lines
Quoted 4 lines
+
+ /* Configure the PLL. */
+ cci_write(sensor->regmap,IMX111_PRE_PLL_CLK_DIVIDER_PLL1, +sensor->pll->pre_div, &ret);
You definitely need to initialise ret = 0 or this line above will probably fail because cci_write uses 'ret' to decide to do anything or not.
- https://docs.kernel.org/driver-api/media/v4l2-cci.html
===============================================================================
int cci_write(struct regmap *map, u32 reg, u64 val, int *err)
Write a value to a single CCI register
Parameters
struct regmap *map
Register map to write to
u32 reg
Register address to write, use CCI_REG#() macros to encode reg width
u64 val
Value to be written
int *err
Optional pointer to store errors, if a previous error is set then the write will be skipped
Return
0 on success or a negative error code on failure.
===============================================================================
So it should be initialised in a good state *or* you use NULL on this first call and assign it - but init to ret = 0 is cleaner here I think.
Quoted 11 lines
Quoted 11 lines
Quoted 7 lines
+ cci_write(sensor->regmap,
IMX111_PLL_MULTIPLIER_PLL1,sensor->pll->mult, &ret); + cci_write(sensor->regmap,IMX111_POST_DIVIDER,IMX111_POST_DIVIDER_DIV1, &ret); + cci_write(sensor->regmap,IMX111_PLL_SETTLING_TIME,
+to_settle_delay(sensor->pll->extclk_rate), &ret);
+
+ ret = cci_multi_reg_write(sensor->regmap,imx111_global_init,
+ARRAY_SIZE(imx111_global_init), NULL);You are overwriting the previous errors.
please use ret |=
No - just continue with the same pattern:
cci_multi_reg_write(sensor->regmap, imx111_global_init, ARRAY_SIZE(imx111_global_init), &ret);
Quoted 8 lines
Quoted 8 lines
Quoted 8 lines
+ if (ret < 0) {
+ dev_err(dev, "Failed to initialize the sensor\n"); + return ret;
+ }drivers/media/i2c/imx111.c new file +3
-0+ + return 0; +}
Sakari Ailus
maintainerHi Svyatoslav,
Quoted 37 lines · Svyatoslav Ryhel
чт, 30 жовт. 2025 р. о 16:55 Tarang Raval <[email protected]> пише:
Quoted 22 lines
Hi Svyatoslav,
Quoted 10 lines
Add 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 SGBRG8Quoted 6 lines
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.
Signed-off-by Svyatoslav Ryhel <[email protected]>---
Quoted 13 lines
drivers/media/i2c/imx111.c line 762
Quoted 9 lines
drivers/media/i2c/imx111.c new file +9
-0+static int imx111_set_ctrl (struct v4l2_ctrl *ctrl) +{ + struct imx111 *sensor = ctrl_to_imx111(ctrl); + struct device *dev = regmap_get_device(sensor->regmap); + s64 max; + int ret = 0; + + /* Propagate change of current control to all related controls */ + switch (ctrl->id) {Do we need the switch statement, since only one case is present? You can use an 'if' instead.
Quoted 3 lines
imx219 and imx319 which are recommended references use switch, and it seems that media maintainters are particularly picky to code style, I have copied it from there.
The documentation lists areas where the mentioned drivers serve as good examples, it does not say everything in those drivers is done the way it is best. Common sense indeed should prevail.
The reason why we mention these these drivers as examples is that there are things that have been notoriously hard to get right (such as runtime PM usage in sensor drivers).
...
Quoted 9 lines
Quoted 7 lines
drivers/media/i2c/imx111.c line 1034
Quoted 4 lines
drivers/media/i2c/imx111.c new file +4
-0+static int imx111_initialize (struct imx111 *sensor) +{ + struct device *dev = regmap_get_device(sensor->regmap); + int ret;ret = 0;
cci_writedoes not state that ret must be initiated.
It does not explicitly use that wording but the documentation is clear enough IMO.
Signature · 3 lines
Kind regards, Sakari Ailus