Small fixes and cleanups (ov2740 and ccs)
Subsystems (8)
Sakari Ailus
maintainerv2 cover Small fixes and cleanups (ov2740 and ccs)
Hi folks,
This small set contains fixes and cleanups, mainly for the ccs and ov2740 drivers. I wrote these while working on the metadata set, but these could and should be merged earlier.
since v1:
- Add a comment on ov2740 active state patch on serialising sensor access.
- Improved commit message of ov2740 patch enabling runtime PM earlier.
- Added patches for printing and zeroing frame descriptor, (debug) printing of frame descriptor, switching ccs to init_cfg and sub-device state and checking pad flag validity.
Sakari Ailus (12):
media: Documentation: Align numbered list, make it a proper ReST
media: ccs: Fix driver quirk struct documentation
media: ccs: Correctly initialise try compose rectangle
media: ccs: Correct error handling in ccs_register_subdev
media: ccs: Switch to init_cfg
media: ccs: Use sub-device active state
media: ov2740: Enable runtime PM before registering the async subdev
media: ov2740: Use sub-device active state
media: ov2740: Return -EPROBE_DEFER if no endpoint is found
media: v4l: subdev: Clear frame descriptor before get_frame_desc
media: v4l: subdev: Print debug information on frame descriptor
media: mc: Check pad flag validity
.../userspace-api/media/v4l/dev-subdev.rst | 49 ++- drivers/media/i2c/ccs/ccs-core.c | 301 +++++++----------- drivers/media/i2c/ccs/ccs-quirk.h | 4 +- drivers/media/i2c/ccs/ccs.h | 4 +- drivers/media/i2c/ds90ub913.c | 2 - drivers/media/i2c/ds90ub953.c | 2 - drivers/media/i2c/ds90ub960.c | 2 - drivers/media/i2c/ov2740.c | 138 ++++---- drivers/media/mc/mc-entity.c | 20 +- drivers/media/platform/nxp/imx-mipi-csis.c | 2 - drivers/media/v4l2-core/v4l2-subdev.c | 42 +++ 11 files changed, 259 insertions(+), 307 deletions(-)
Signature · 1 line
2.39.2
Sakari Ailus
maintainerPATCH v2 1/12 media: Documentation: Align numbered list, make it a proper ReST
Align lines for numbered list so that Sphinx produces an uniform output for all list entries. Also indent paragraphs of such list entries for consistency.
Also use ReST numbered list syntax for the entries.
--- .../userspace-api/media/v4l/dev-subdev.rst | 49 +++++++++---------- 1 file changed, 24 insertions(+), 25 deletions(-)
Documentation/userspace-api/media/v4l/dev-subdev.rst +24 -25
@@ -579,20 +579,19 @@ is started. There are three steps in configuring the streams: -1) Set up links. Connect the pads between sub-devices using the :ref:`Media -Controller API <media_controller>` +1. Set up links. Connect the pads between sub-devices using the + :ref:`Media Controller API <media_controller>` -2) Streams. Streams are declared and their routing is configured by -setting the routing table for the sub-device using -:ref:`VIDIOC_SUBDEV_S_ROUTING <VIDIOC_SUBDEV_G_ROUTING>` ioctl. Note that -setting the routing table will reset formats and selections in the -sub-device to default values. +2. Streams. Streams are declared and their routing is configured by setting the + routing table for the sub-device using :ref:`VIDIOC_SUBDEV_S_ROUTING + <VIDIOC_SUBDEV_G_ROUTING>` ioctl. Note that setting the routing table will + reset formats and selections in the sub-device to default values. -3) Configure formats and selections. Formats and selections of each stream -are configured separately as documented for plain sub-devices in -:ref:`format-propagation`. The stream ID is set to the same stream ID -associated with either sink or source pads of routes configured using the -:ref:`VIDIOC_SUBDEV_S_ROUTING <VIDIOC_SUBDEV_G_ROUTING>` ioctl. +3. Configure formats and selections. Formats and selections of each stream are + configured separately as documented for plain sub-devices in + :ref:`format-propagation`. The stream ID is set to the same stream ID + associated with either sink or source pads of routes configured using the + :ref:`VIDIOC_SUBDEV_S_ROUTING <VIDIOC_SUBDEV_G_ROUTING>` ioctl. Multiplexed streams setup example ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
@@ -618,11 +617,11 @@ modeled as V4L2 devices, exposed to userspace via /dev/videoX nodes. To configure this pipeline, the userspace must take the following steps: -1) Set up media links between entities: connect the sensors to the bridge, -bridge to the receiver, and the receiver to the DMA engines. This step does -not differ from normal non-multiplexed media controller setup. +1. Set up media links between entities: connect the sensors to the bridge, + bridge to the receiver, and the receiver to the DMA engines. This step does + not differ from normal non-multiplexed media controller setup. -2) Configure routing +2. Configure routing .. flat-table:: Bridge routing table :header-rows: 1
@@ -656,14 +655,14 @@ not differ from normal non-multiplexed media controller setup. - V4L2_SUBDEV_ROUTE_FL_ACTIVE - Pixel data stream from Sensor B -3) Configure formats and selections +3. Configure formats and selections -After configuring routing, the next step is configuring the formats and -selections for the streams. This is similar to performing this step without -streams, with just one exception: the ``stream`` field needs to be assigned -to the value of the stream ID. + After configuring routing, the next step is configuring the formats and + selections for the streams. This is similar to performing this step without + streams, with just one exception: the ``stream`` field needs to be assigned + to the value of the stream ID. -A common way to accomplish this is to start from the sensors and propagate the -configurations along the stream towards the receiver, -using :ref:`VIDIOC_SUBDEV_S_FMT <VIDIOC_SUBDEV_G_FMT>` ioctls to configure each -stream endpoint in each sub-device. + A common way to accomplish this is to start from the sensors and propagate + the configurations along the stream towards the receiver, using + :ref:`VIDIOC_SUBDEV_S_FMT <VIDIOC_SUBDEV_G_FMT>` ioctls to configure each + stream endpoint in each sub-device.
Signature · 1 line
2.39.2
Sakari Ailus
maintainerPATCH v2 2/12 media: ccs: Fix driver quirk struct documentation
In reply to Sakari AilusFix documentation for struct ccs_quirk, a device specific struct for managing deviations from the standard. The flags field was drifted away from where it should have been.
--- drivers/media/i2c/ccs/ccs-quirk.h | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-)
drivers/media/i2c/ccs/ccs-quirk.h +1 -3
@@ -32,12 +32,10 @@ struct ccs_sensor;* @reg: Pointer to the register to access * @value: Register value, set by the caller on write, or * by the quirk on read -* -* @flags: Quirk flags -* * @return: 0 on success, -ENOIOCTLCMD if no register * access may be done by the caller (default read * value is zero), else negative error code on error +* @flags: Quirk flags */ struct ccs_quirk {int (*limits)(struct ccs_sensor *sensor);
Signature · 1 line
2.39.2
Sakari Ailus
maintainerPATCH v2 3/12 media: ccs: Correctly initialise try compose rectangle
In reply to Sakari AilusInitialise the try sink compose rectangle size to the sink compose rectangle for binner and scaler sub-devices. This was missed due to the faulty condition that lead to the compose rectangles to be initialised for the pixel array sub-device where it is not relevant.
--- drivers/media/i2c/ccs/ccs-core.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/media/i2c/ccs/ccs-core.c +1 -1
@@ -3097,7 +3097,7 @@ static int ccs_open(struct v4l2_subdev *sd, struct v4l2_subdev_fh *fh) try_fmt->code = sensor->internal_csi_format->code; try_fmt->field =V4L2_FIELD_NONE ; -if (ssd != sensor->pixel_array) +if (ssd == sensor->pixel_array)continue ; try_comp =v4l2_subdev_get_try_compose (sd, fh->state, i);
Signature · 1 line
2.39.2
Sakari Ailus
maintainerPATCH v2 4/12 media: ccs: Correct error handling in ccs_register_subdev
In reply to Sakari Ailusccs_register_subdev() did not clean up the media entity in error case, do that now. Also switch to goto based error handling.
--- drivers/media/i2c/ccs/ccs-core.c | 13 ++++++++++--- 1 file changed, 10 insertions(+), 3 deletions(-)
drivers/media/i2c/ccs/ccs-core.c +10 -3
@@ -2968,7 +2968,7 @@ static int ccs_register_subdev(struct ccs_sensor *sensor, rval =v4l2_device_register_subdev (sensor->src->sd.v4l2_dev, &ssd->sd);if (rval) {dev_err (&client->dev,"v4l2_device_register_subdev failed\n" ); -return rval; + goto out_media_entity_cleanup; } rval = media_create_pad_link(&ssd->sd.entity, source_pad,
@@ -2976,11 +2976,18 @@ static int ccs_register_subdev(struct ccs_sensor *sensor, link_flags);if (rval) {dev_err (&client->dev,"media_create_pad_link failed\n" ); -v4l2_device_unregister_subdev (&ssd->sd); -return rval; + goto out_v4l2_device_unregister_subdev; }return 0 ; + +out_v4l2_device_unregister_subdev: +v4l2_device_unregister_subdev (&ssd->sd); + +out_media_entity_cleanup: +media_entity_cleanup (&ssd->sd.entity); + +return rval; }static void ccs_unregistered (struct v4l2_subdev *subdev)
Signature · 1 line
2.39.2
Sakari Ailus
maintainerPATCH v2 5/12 media: ccs: Switch to init_cfg
In reply to Sakari AilusUse init_cfg() instead of manually setting up defaults during probe and file handle open.
--- drivers/media/i2c/ccs/ccs-core.c | 16 +++++----------- 1 file changed, 5 insertions(+), 11 deletions(-)
drivers/media/i2c/ccs/ccs-core.c +5 -11
@@ -2945,7 +2945,6 @@ static int ccs_identify_module(struct ccs_sensor *sensor) }static const struct v4l2_subdev_ops ccs_ops; -static const struct v4l2_subdev_internal_ops ccs_internal_ops;static const struct media_entity_operations ccs_entity_ops; static int ccs_register_subdev(struct ccs_sensor *sensor,
@@ -3076,13 +3075,12 @@ static void ccs_create_subdev(struct ccs_sensor *sensor,if (ssd == sensor->src)return ; - ssd->sd.internal_ops = &ccs_internal_ops; ssd->sd.owner =THIS_MODULE ; ssd->sd.dev = &client->dev;v4l2_set_subdevdata (&ssd->sd, client); } -static int ccs_open (struct v4l2_subdev *sd,struct v4l2_subdev_fh *fh) +static int ccs_init_cfg (struct v4l2_subdev *sd,struct v4l2_subdev_state *sd_state) {struct ccs_subdev *ssd =to_ccs_subdev (sd);struct ccs_sensor *sensor = ssd->sensor;
@@ -3092,9 +3090,9 @@ static int ccs_open(struct v4l2_subdev *sd, struct v4l2_subdev_fh *fh)for (i =0 ; i < ssd->npads; i++) {struct v4l2_mbus_framefmt *try_fmt = -v4l2_subdev_get_try_format (sd, fh->state, i); +v4l2_subdev_get_try_format (sd, sd_state, i);struct v4l2_rect *try_crop = -v4l2_subdev_get_try_crop (sd, fh->state, i); +v4l2_subdev_get_try_crop (sd, sd_state, i);struct v4l2_rect *try_comp;ccs_get_native_size (ssd, try_crop);
@@ -3107,7 +3105,7 @@ static int ccs_open(struct v4l2_subdev *sd, struct v4l2_subdev_fh *fh)if (ssd == sensor->pixel_array)continue ; - try_comp =v4l2_subdev_get_try_compose (sd, fh->state, i); + try_comp =v4l2_subdev_get_try_compose (sd, sd_state, i); *try_comp = *try_crop; }
@@ -3123,6 +3121,7 @@ static const struct v4l2_subdev_video_ops ccs_video_ops = { };static const struct v4l2_subdev_pad_ops ccs_pad_ops = { + .init_cfg = ccs_init_cfg, .enum_mbus_code = ccs_enum_mbus_code, .get_fmt = ccs_get_format, .set_fmt = ccs_set_format,
@@ -3148,11 +3147,6 @@ static const struct media_entity_operations ccs_entity_ops = {static const struct v4l2_subdev_internal_ops ccs_internal_src_ops = { .registered = ccs_registered, .unregistered = ccs_unregistered, - .open = ccs_open, -}; - -static const struct v4l2_subdev_internal_ops ccs_internal_ops = { - .open = ccs_open, };/* -----------------------------------------------------------------------------
Signature · 1 line
2.39.2
Re: [PATCH v2 05/12] media: ccs: Switch to init_cfg
Hi Sakari,
Thank you for the patch.
Quoted 2 lines · Sakari Ailus
Use
init_cfg()instead of manually setting up defaults during probe and file handle open.
I don't think you touch probe time in this patch. That's fine, it's addressed in the next patch, so with the commit message updated,
Quoted 74 lines
Signed-off-by Sakari Ailus <[email protected]>--- drivers/media/i2c/ccs/ccs-core.c | 16 +++++----------- 1 file changed, 5 insertions(+), 11 deletions(-)drivers/media/i2c/ccs/ccs-core.c +5
-11@@ -2945,7 +2945,6 @@ static int ccs_identify_module(struct ccs_sensor *sensor) }static const struct v4l2_subdev_ops ccs_ops; -static const struct v4l2_subdev_internal_ops ccs_internal_ops;static const struct media_entity_operations ccs_entity_ops; static int ccs_register_subdev(struct ccs_sensor *sensor,@@ -3076,13 +3075,12 @@ static void ccs_create_subdev(struct ccs_sensor *sensor,if (ssd == sensor->src)return ; - ssd->sd.internal_ops = &ccs_internal_ops; ssd->sd.owner =THIS_MODULE ; ssd->sd.dev = &client->dev;v4l2_set_subdevdata (&ssd->sd, client); } -static int ccs_open (struct v4l2_subdev *sd,struct v4l2_subdev_fh *fh) +static int ccs_init_cfg (struct v4l2_subdev *sd,struct v4l2_subdev_state *sd_state) {struct ccs_subdev *ssd =to_ccs_subdev (sd);struct ccs_sensor *sensor = ssd->sensor;@@ -3092,9 +3090,9 @@ static int ccs_open(struct v4l2_subdev *sd, struct v4l2_subdev_fh *fh)for (i =0 ; i < ssd->npads; i++) {struct v4l2_mbus_framefmt *try_fmt = -v4l2_subdev_get_try_format (sd, fh->state, i); +v4l2_subdev_get_try_format (sd, sd_state, i);struct v4l2_rect *try_crop = -v4l2_subdev_get_try_crop (sd, fh->state, i); +v4l2_subdev_get_try_crop (sd, sd_state, i);struct v4l2_rect *try_comp;ccs_get_native_size (ssd, try_crop);@@ -3107,7 +3105,7 @@ static int ccs_open(struct v4l2_subdev *sd, struct v4l2_subdev_fh *fh)if (ssd == sensor->pixel_array)continue ; - try_comp =v4l2_subdev_get_try_compose (sd, fh->state, i); + try_comp =v4l2_subdev_get_try_compose (sd, sd_state, i); *try_comp = *try_crop; }@@ -3123,6 +3121,7 @@ static const struct v4l2_subdev_video_ops ccs_video_ops = { };static const struct v4l2_subdev_pad_ops ccs_pad_ops = { + .init_cfg = ccs_init_cfg, .enum_mbus_code = ccs_enum_mbus_code, .get_fmt = ccs_get_format, .set_fmt = ccs_set_format,@@ -3148,11 +3147,6 @@ static const struct media_entity_operations ccs_entity_ops = {static const struct v4l2_subdev_internal_ops ccs_internal_src_ops = { .registered = ccs_registered, .unregistered = ccs_unregistered, - .open = ccs_open, -}; - -static const struct v4l2_subdev_internal_ops ccs_internal_ops = { - .open = ccs_open, };/* -----------------------------------------------------------------------------
Signature · 3 lines
Regards, Laurent Pinchart
Sakari Ailus
maintainerPATCH v2 6/12 media: ccs: Use sub-device active state
In reply to Sakari AilusMake use of sub-device active state. In most cases the effect on need for acquiring the mutex is non-existent as access to the driver's core data structure still needs to be serialised.
This still removes a lot of code as the code paths for active and try state are the same in many cases.
--- drivers/media/i2c/ccs/ccs-core.c | 278 ++++++++++++------------------- drivers/media/i2c/ccs/ccs.h | 4 +- 2 files changed, 103 insertions(+), 179 deletions(-)
drivers/media/i2c/ccs/ccs-core.c +102 -176
@@ -508,9 +508,8 @@ static void __ccs_update_exposure_limits(struct ccs_sensor *sensor)struct v4l2_ctrl *ctrl = sensor->exposure;int max; - max = sensor->pixel_array->crop[CCS_PA_PAD_SRC ].height - + sensor->vblank->val - -CCS_LIM (sensor,COARSE_INTEGRATION_TIME_MAX_MARGIN ); + max = sensor->pa_src.height + sensor->vblank->val - +CCS_LIM (sensor,COARSE_INTEGRATION_TIME_MAX_MARGIN );__v4l2_ctrl_modify_range (ctrl, ctrl->minimum, max, ctrl->step, max); }
@@ -728,15 +727,12 @@ static int ccs_set_ctrl(struct v4l2_ctrl *ctrl)break ;case V4L2_CID_VBLANK : rval =ccs_write (sensor,FRAME_LENGTH_LINES , - sensor->pixel_array->crop[ -CCS_PA_PAD_SRC ].height - + ctrl->val); + sensor->pa_src.height + ctrl->val);break ;case V4L2_CID_HBLANK : rval =ccs_write (sensor,LINE_LENGTH_PCK , - sensor->pixel_array->crop[CCS_PA_PAD_SRC ].width - + ctrl->val); + sensor->pa_src.width + ctrl->val);break ;case V4L2_CID_TEST_PATTERN :
@@ -1214,15 +1210,13 @@ static void ccs_update_blanking(struct ccs_sensor *sensor) min =max_t (int,CCS_LIM (sensor,MIN_FRAME_BLANKING_LINES ), - min_fll - sensor->pixel_array->crop[CCS_PA_PAD_SRC ].height); - max = max_fll - sensor->pixel_array->crop[CCS_PA_PAD_SRC ].height; + min_fll - sensor->pa_src.height); + max = max_fll - sensor->pa_src.height;__v4l2_ctrl_modify_range (vblank, min, max, vblank->step, min); - min =max_t (int, - min_llp - sensor->pixel_array->crop[CCS_PA_PAD_SRC ].width, - min_lbp); - max = max_llp - sensor->pixel_array->crop[CCS_PA_PAD_SRC ].width; + min =max_t (int, min_llp - sensor->pa_src.width, min_lbp); + max = max_llp - sensor->pa_src.width;__v4l2_ctrl_modify_range (hblank, min, max, hblank->step, min);
@@ -1246,10 +1240,8 @@ static int ccs_pll_blanking_update(struct ccs_sensor *sensor)dev_dbg (&client->dev,"real timeperframe\t100/%d\n" , sensor->pll.pixel_rate_pixel_array / - ((sensor->pixel_array->crop[CCS_PA_PAD_SRC ].width - + sensor->hblank->val) * - (sensor->pixel_array->crop[CCS_PA_PAD_SRC ].height - + sensor->vblank->val) /100 )); + ((sensor->pa_src.width + sensor->hblank->val) * + (sensor->pa_src.height + sensor->vblank->val) /100 ));return 0 ; }
@@ -1756,28 +1748,22 @@ static int ccs_start_streaming(struct ccs_sensor *sensor) goto out;/* Analog crop start coordinates */ - rval =ccs_write (sensor,X_ADDR_START , - sensor->pixel_array->crop[CCS_PA_PAD_SRC ].left); + rval =ccs_write (sensor,X_ADDR_START , sensor->pa_src.left);if (rval <0 ) goto out; - rval =ccs_write (sensor,Y_ADDR_START , - sensor->pixel_array->crop[CCS_PA_PAD_SRC ].top); + rval =ccs_write (sensor,Y_ADDR_START , sensor->pa_src.top);if (rval <0 ) goto out;/* Analog crop end coordinates */ - rval =ccs_write ( - sensor,X_ADDR_END , - sensor->pixel_array->crop[CCS_PA_PAD_SRC ].left - + sensor->pixel_array->crop[CCS_PA_PAD_SRC ].width -1 ); + rval =ccs_write (sensor,X_ADDR_END , + sensor->pa_src.left + sensor->pa_src.width -1 );if (rval <0 ) goto out; - rval =ccs_write ( - sensor,Y_ADDR_END , - sensor->pixel_array->crop[CCS_PA_PAD_SRC ].top - + sensor->pixel_array->crop[CCS_PA_PAD_SRC ].height -1 ); + rval =ccs_write (sensor,Y_ADDR_END , + sensor->pa_src.top + sensor->pa_src.height -1 );if (rval <0 ) goto out;
@@ -1789,27 +1775,23 @@ static int ccs_start_streaming(struct ccs_sensor *sensor)/* Digital crop */ if (CCS_LIM (sensor,DIGITAL_CROP_CAPABILITY ) ==CCS_DIGITAL_CROP_CAPABILITY_INPUT_CROP ) { - rval =ccs_write ( - sensor,DIGITAL_CROP_X_OFFSET , - sensor->scaler->crop[CCS_PAD_SINK ].left); + rval =ccs_write (sensor,DIGITAL_CROP_X_OFFSET , + sensor->scaler_sink.left);if (rval <0 ) goto out; - rval =ccs_write ( - sensor,DIGITAL_CROP_Y_OFFSET , - sensor->scaler->crop[CCS_PAD_SINK ].top); + rval =ccs_write (sensor,DIGITAL_CROP_Y_OFFSET , + sensor->scaler_sink.top);if (rval <0 ) goto out; - rval =ccs_write ( - sensor,DIGITAL_CROP_IMAGE_WIDTH , - sensor->scaler->crop[CCS_PAD_SINK ].width); + rval =ccs_write (sensor,DIGITAL_CROP_IMAGE_WIDTH , + sensor->scaler_sink.width);if (rval <0 ) goto out; - rval =ccs_write ( - sensor,DIGITAL_CROP_IMAGE_HEIGHT , - sensor->scaler->crop[CCS_PAD_SINK ].height); + rval =ccs_write (sensor,DIGITAL_CROP_IMAGE_HEIGHT , + sensor->scaler_sink.height);if (rval <0 ) goto out; }
@@ -1827,12 +1809,10 @@ static int ccs_start_streaming(struct ccs_sensor *sensor) }/* Output size from sensor */ - rval =ccs_write (sensor,X_OUTPUT_SIZE , - sensor->src->crop[CCS_PAD_SRC ].width); + rval =ccs_write (sensor,X_OUTPUT_SIZE , sensor->src_src.width);if (rval <0 ) goto out; - rval =ccs_write (sensor,Y_OUTPUT_SIZE , - sensor->src->crop[CCS_PAD_SRC ].height); + rval =ccs_write (sensor,Y_OUTPUT_SIZE , sensor->src_src.height);if (rval <0 ) goto out;
@@ -2053,24 +2033,8 @@ static int __ccs_get_format(struct v4l2_subdev *subdev,struct v4l2_subdev_state *sd_state, struct v4l2_subdev_format *fmt) { - struct ccs_subdev *ssd = to_ccs_subdev(subdev); - -if (fmt->which ==V4L2_SUBDEV_FORMAT_TRY ) { - fmt->format = *v4l2_subdev_get_try_format (subdev, sd_state, - fmt->pad); - }else { -struct v4l2_rect *r; - -if (fmt->pad == ssd->source_pad) - r = &ssd->crop[ssd->source_pad]; -else - r = &ssd->sink_fmt; - - fmt->format.code =__ccs_get_mbus_code (subdev, fmt->pad); - fmt->format.width = r->width; - fmt->format.height = r->height; - fmt->format.field =V4L2_FIELD_NONE ; - } + fmt->format = *v4l2_subdev_get_pad_format(subdev, sd_state, fmt->pad); + fmt->format.code =__ccs_get_mbus_code (subdev, fmt->pad);return 0 ; }
@@ -2092,28 +2056,18 @@ static int ccs_get_format(struct v4l2_subdev *subdev,static void ccs_get_crop_compose (struct v4l2_subdev *subdev,struct v4l2_subdev_state *sd_state,struct v4l2_rect **crops, -struct v4l2_rect **comps,int which) +struct v4l2_rect **comps) {struct ccs_subdev *ssd =to_ccs_subdev (subdev);unsigned int i; -if (which ==V4L2_SUBDEV_FORMAT_ACTIVE ) { -if (crops) -for (i =0 ; i < subdev->entity.num_pads; i++) - crops[i] = &ssd->crop[i]; -if (comps) - *comps = &ssd->compose; - }else { -if (crops) { -for (i =0 ; i < subdev->entity.num_pads; i++) - crops[i] =v4l2_subdev_get_try_crop (subdev, - sd_state, - i); - } -if (comps) - *comps =v4l2_subdev_get_try_compose (subdev, sd_state, -CCS_PAD_SINK ); - } +if (crops) +for (i =0 ; i < subdev->entity.num_pads; i++) + crops[i] = +v4l2_subdev_get_pad_crop (subdev, sd_state, i); +if (comps) + *comps =v4l2_subdev_get_pad_compose (subdev, sd_state, + ssd->sink_pad); }/* Changes require propagation only on sink pad. */
@@ -2125,7 +2079,7 @@ static void ccs_propagate(struct v4l2_subdev *subdev,struct ccs_subdev *ssd =to_ccs_subdev (subdev);struct v4l2_rect *comp, *crops[CCS_PADS ]; -ccs_get_crop_compose (subdev, sd_state, crops, &comp, which); +ccs_get_crop_compose (subdev, sd_state, crops, &comp);switch (target) {case V4L2_SEL_TGT_CROP :
@@ -2136,6 +2090,7 @@ static void ccs_propagate(struct v4l2_subdev *subdev, sensor->scale_m =CCS_LIM (sensor,SCALER_N_MIN ); sensor->scaling_mode =CCS_SCALING_MODE_NO_SCALING ; + sensor->scaler_sink = *comp; }else if (ssd == sensor->binner) { sensor->binning_horizontal =1 ; sensor->binning_vertical =1 ;
@@ -2144,6 +2099,8 @@ static void ccs_propagate(struct v4l2_subdev *subdev, fallthrough;case V4L2_SEL_TGT_COMPOSE : *crops[CCS_PAD_SRC ] = *comp; +if (which ==V4L2_SUBDEV_FORMAT_ACTIVE && ssd == sensor->src) + sensor->src_src = *crops[CCS_PAD_SRC ];break ;default :WARN_ON_ONCE (1 );
@@ -2252,14 +2209,12 @@ static int ccs_set_format(struct v4l2_subdev *subdev,CCS_LIM (sensor,MIN_Y_OUTPUT_SIZE ), CCS_LIM(sensor, MAX_Y_OUTPUT_SIZE)); -ccs_get_crop_compose (subdev, sd_state, crops,NULL , fmt->which); +ccs_get_crop_compose (subdev, sd_state, crops,NULL ); crops[ssd->sink_pad]->left =0 ; crops[ssd->sink_pad]->top =0 ; crops[ssd->sink_pad]->width = fmt->format.width; crops[ssd->sink_pad]->height = fmt->format.height; -if (fmt->which ==V4L2_SUBDEV_FORMAT_ACTIVE ) - ssd->sink_fmt = *crops[ssd->sink_pad];ccs_propagate (subdev, sd_state, fmt->which,V4L2_SEL_TGT_CROP );mutex_unlock (&sensor->mutex);
@@ -2482,7 +2437,7 @@ static int ccs_set_compose(struct v4l2_subdev *subdev,struct ccs_subdev *ssd =to_ccs_subdev (subdev);struct v4l2_rect *comp, *crops[CCS_PADS ]; -ccs_get_crop_compose (subdev, sd_state, crops, &comp, sel->which); +ccs_get_crop_compose (subdev, sd_state, crops, &comp); sel->r.top =0 ; sel->r.left =0 ;
@@ -2501,8 +2456,8 @@ static int ccs_set_compose(struct v4l2_subdev *subdev,return 0 ; } -static int __ccs_sel_supported (struct v4l2_subdev *subdev, -struct v4l2_subdev_selection *sel) +static int ccs_sel_supported (struct v4l2_subdev *subdev, +struct v4l2_subdev_selection *sel) {struct ccs_sensor *sensor =to_ccs_sensor (subdev);struct ccs_subdev *ssd =to_ccs_subdev (subdev);
@@ -2545,33 +2500,18 @@ static int ccs_set_crop(struct v4l2_subdev *subdev, {struct ccs_sensor *sensor =to_ccs_sensor (subdev);struct ccs_subdev *ssd =to_ccs_subdev (subdev); -struct v4l2_rect *src_size, *crops[CCS_PADS ]; -struct v4l2_rect _r; +struct v4l2_rect src_size = {0 }, *crops[CCS_PADS ], *comp; -ccs_get_crop_compose (subdev, sd_state, crops,NULL , sel->which); +ccs_get_crop_compose (subdev, sd_state, crops, &comp); -if (sel->which ==V4L2_SUBDEV_FORMAT_ACTIVE ) { -if (sel->pad == ssd->sink_pad) - src_size = &ssd->sink_fmt; -else - src_size = &ssd->compose; +if (sel->pad == ssd->sink_pad) { +struct v4l2_mbus_framefmt *mfmt = +v4l2_subdev_get_pad_format (subdev, sd_state, sel->pad); + + src_size.width = mfmt->width; + src_size.height = mfmt->height; }else { -if (sel->pad == ssd->sink_pad) { - _r.left =0 ; - _r.top =0 ; - _r.width =v4l2_subdev_get_try_format (subdev, - sd_state, - sel->pad) - ->width; - _r.height =v4l2_subdev_get_try_format (subdev, - sd_state, - sel->pad) - ->height; - src_size = &_r; - }else { - src_size =v4l2_subdev_get_try_compose ( - subdev, sd_state, ssd->sink_pad); - } + src_size = *comp; }if (ssd == sensor->src && sel->pad ==CCS_PAD_SRC ) {
@@ -2579,16 +2519,19 @@ static int ccs_set_crop(struct v4l2_subdev *subdev, sel->r.top =0 ; } - sel->r.width =min (sel->r.width, src_size->width); - sel->r.height =min (sel->r.height, src_size->height); + sel->r.width =min (sel->r.width, src_size.width); + sel->r.height =min (sel->r.height, src_size.height); - sel->r.left =min_t (int, sel->r.left, src_size->width - sel->r.width); - sel->r.top =min_t (int, sel->r.top, src_size->height - sel->r.height); + sel->r.left =min_t (int, sel->r.left, src_size.width - sel->r.width); + sel->r.top =min_t (int, sel->r.top, src_size.height - sel->r.height); *crops[sel->pad] = sel->r;if (ssd != sensor->pixel_array && sel->pad ==CCS_PAD_SINK )ccs_propagate (subdev, sd_state, sel->which,V4L2_SEL_TGT_CROP ); +else if (sel->which ==V4L2_SUBDEV_FORMAT_ACTIVE && + ssd == sensor->pixel_array) + sensor->pa_src = sel->r;return 0 ; }
@@ -2601,44 +2544,36 @@ static void ccs_get_native_size(struct ccs_subdev *ssd, struct v4l2_rect *r) r->height =CCS_LIM (ssd->sensor,Y_ADDR_MAX ) +1 ; } -static int __ccs_get_selection (struct v4l2_subdev *subdev, -struct v4l2_subdev_state *sd_state, -struct v4l2_subdev_selection *sel) +static int ccs_get_selection (struct v4l2_subdev *subdev, +struct v4l2_subdev_state *sd_state, +struct v4l2_subdev_selection *sel) {struct ccs_sensor *sensor =to_ccs_sensor (subdev);struct ccs_subdev *ssd =to_ccs_subdev (subdev);struct v4l2_rect *comp, *crops[CCS_PADS ]; -struct v4l2_rect sink_fmt;int ret; - ret =__ccs_sel_supported (subdev, sel); + ret =ccs_sel_supported (subdev, sel);if (ret)return ret; -ccs_get_crop_compose (subdev, sd_state, crops, &comp, sel->which); - -if (sel->which ==V4L2_SUBDEV_FORMAT_ACTIVE ) { - sink_fmt = ssd->sink_fmt; - }else { -struct v4l2_mbus_framefmt *fmt = -v4l2_subdev_get_try_format (subdev, sd_state, - ssd->sink_pad); - - sink_fmt.left =0 ; - sink_fmt.top =0 ; - sink_fmt.width = fmt->width; - sink_fmt.height = fmt->height; - } +ccs_get_crop_compose (subdev, sd_state, crops, &comp);switch (sel->target) {case V4L2_SEL_TGT_CROP_BOUNDS :case V4L2_SEL_TGT_NATIVE_SIZE : -if (ssd == sensor->pixel_array) +if (ssd == sensor->pixel_array) {ccs_get_native_size (ssd, &sel->r); -else if (sel->pad == ssd->sink_pad) - sel->r = sink_fmt; -else + }else if (sel->pad == ssd->sink_pad) { +struct v4l2_mbus_framefmt *sink_fmt = +v4l2_subdev_get_pad_format (subdev, sd_state, + ssd->sink_pad); + sel->r.top = sel->r.left =0 ; + sel->r.width = sink_fmt->width; + sel->r.height = sink_fmt->height; + }else { sel->r = *comp; + }break ;case V4L2_SEL_TGT_CROP :case V4L2_SEL_TGT_COMPOSE_BOUNDS :
@@ -2652,20 +2587,6 @@ static int __ccs_get_selection(struct v4l2_subdev *subdev,return 0 ; } -static int ccs_get_selection (struct v4l2_subdev *subdev, -struct v4l2_subdev_state *sd_state, -struct v4l2_subdev_selection *sel) -{ -struct ccs_sensor *sensor =to_ccs_sensor (subdev); -int rval; - -mutex_lock (&sensor->mutex); - rval =__ccs_get_selection (subdev, sd_state, sel); -mutex_unlock (&sensor->mutex); - -return rval; -} -static int ccs_set_selection (struct v4l2_subdev *subdev,struct v4l2_subdev_state *sd_state,struct v4l2_subdev_selection *sel)
@@ -2673,7 +2594,7 @@ static int ccs_set_selection(struct v4l2_subdev *subdev,struct ccs_sensor *sensor =to_ccs_sensor (subdev);int ret; - ret =__ccs_sel_supported (subdev, sel); + ret =ccs_sel_supported (subdev, sel);if (ret)return ret;
@@ -2964,10 +2885,14 @@ static int ccs_register_subdev(struct ccs_sensor *sensor,return rval; } + rval =v4l2_subdev_init_finalize (&ssd->sd); +if (rval) + goto out_media_entity_cleanup; + rval =v4l2_device_register_subdev (sensor->src->sd.v4l2_dev, &ssd->sd);if (rval) {dev_err (&client->dev,"v4l2_device_register_subdev failed\n" ); - goto out_media_entity_cleanup; + goto out_v4l2_subdev_cleanup; } rval = media_create_pad_link(&ssd->sd.entity, source_pad,
@@ -2983,6 +2908,9 @@ static int ccs_register_subdev(struct ccs_sensor *sensor, out_v4l2_device_unregister_subdev:v4l2_device_unregister_subdev (&ssd->sd); +out_v4l2_subdev_cleanup: +v4l2_subdev_cleanup (&ssd->sd); + out_media_entity_cleanup:media_entity_cleanup (&ssd->sd.entity);
@@ -3059,16 +2987,9 @@ static void ccs_create_subdev(struct ccs_sensor *sensor,v4l2_i2c_subdev_set_name (&ssd->sd, client, sensor->minfo.name, name); -ccs_get_native_size (ssd, &ssd->sink_fmt); - - ssd->compose.width = ssd->sink_fmt.width; - ssd->compose.height = ssd->sink_fmt.height; - ssd->crop[ssd->source_pad] = ssd->compose; ssd->pads[ssd->source_pad].flags =MEDIA_PAD_FL_SOURCE ; -if (ssd != sensor->pixel_array) { - ssd->crop[ssd->sink_pad] = ssd->compose; +if (ssd != sensor->pixel_array) ssd->pads[ssd->sink_pad].flags =MEDIA_PAD_FL_SINK ; - } ssd->sd.entity.ops = &ccs_entity_ops;
@@ -3089,24 +3010,24 @@ static int ccs_init_cfg(struct v4l2_subdev *sd, struct v4l2_subdev_state *sd_stamutex_lock (&sensor->mutex);for (i =0 ; i < ssd->npads; i++) { -struct v4l2_mbus_framefmt *try_fmt = -v4l2_subdev_get_try_format (sd, sd_state, i); -struct v4l2_rect *try_crop = -v4l2_subdev_get_try_crop (sd, sd_state, i); -struct v4l2_rect *try_comp; +struct v4l2_mbus_framefmt *pad_fmt = +v4l2_subdev_get_pad_format (sd, sd_state, i); +struct v4l2_rect *pad_crop = +v4l2_subdev_get_pad_crop (sd, sd_state, i); +struct v4l2_rect *pad_comp; -ccs_get_native_size (ssd, try_crop); +ccs_get_native_size (ssd, pad_crop); - try_fmt->width = try_crop->width; - try_fmt->height = try_crop->height; - try_fmt->code = sensor->internal_csi_format->code; - try_fmt->field =V4L2_FIELD_NONE ; + pad_fmt->width = pad_crop->width; + pad_fmt->height = pad_crop->height; + pad_fmt->code = sensor->internal_csi_format->code; + pad_fmt->field =V4L2_FIELD_NONE ;if (ssd == sensor->pixel_array)continue ; - try_comp =v4l2_subdev_get_try_compose (sd, sd_state, i); - *try_comp = *try_crop; + pad_comp =v4l2_subdev_get_pad_compose (sd, sd_state, i); + *pad_comp = *pad_crop; }mutex_unlock (&sensor->mutex);
@@ -3631,6 +3552,10 @@ static int ccs_probe(struct i2c_client *client)if (rval <0 ) goto out_media_entity_cleanup; + rval =v4l2_subdev_init_finalize (&sensor->src->sd); +if (rval) + goto out_media_entity_cleanup; + rval =ccs_write_msr_regs (sensor);if (rval) goto out_media_entity_cleanup;
@@ -3690,6 +3615,7 @@ static void ccs_remove(struct i2c_client *client)for (i =0 ; i < sensor->ssds_used; i++) {v4l2_device_unregister_subdev (&sensor->ssds[i].sd); +v4l2_subdev_cleanup (subdev);media_entity_cleanup (&sensor->ssds[i].sd.entity); }ccs_cleanup (sensor);
drivers/media/i2c/ccs/ccs.h +1 -3
@@ -182,9 +182,6 @@ struct ccs_binning_subtype {struct ccs_subdev {struct v4l2_subdev sd;struct media_pad pads[CCS_PADS ]; -struct v4l2_rect sink_fmt; -struct v4l2_rect crop[CCS_PADS ]; -struct v4l2_rect compose;/* compose on sink */ unsigned short sink_pad;unsigned short source_pad;int npads;
@@ -220,6 +217,7 @@ struct ccs_sensor {u32 mbus_frame_fmts;const struct ccs_csi_data_format *csi_format;const struct ccs_csi_data_format *internal_csi_format; +struct v4l2_rect pa_src, scaler_sink, src_src;u32 default_mbus_frame_fmts;int default_pixel_order;struct ccs_data_container sdata, mdata;
Signature · 1 line
2.39.2
Laurent Pinchart
maintainerRe: [PATCH v2 06/12] media: ccs: Use sub-device active state
Hi Sakari,
Thank you for the patch.
drivers/media/i2c/ccs/ccs-core.c static int ccs_get_format(struct v4l2_subdev *subdev,
Quoted 194 lines · Sakari Ailus
Make use of sub-device active state. In most cases the effect on need for acquiring the mutex is non-existent as access to the driver's core data structure still needs to be serialised.
This still removes a lot of code as the code paths for active and try state are the same in many cases.
Signed-off-by Sakari Ailus <[email protected]>--- drivers/media/i2c/ccs/ccs-core.c | 278 ++++++++++++------------------- drivers/media/i2c/ccs/ccs.h | 4 +- 2 files changed, 103 insertions(+), 179 deletions(-)drivers/media/i2c/ccs/ccs-core.c +28
-64@@ -508,9 +508,8 @@ static void __ccs_update_exposure_limits(struct ccs_sensor *sensor)struct v4l2_ctrl *ctrl = sensor->exposure;int max; - max = sensor->pixel_array->crop[CCS_PA_PAD_SRC ].height - + sensor->vblank->val - -CCS_LIM (sensor,COARSE_INTEGRATION_TIME_MAX_MARGIN ); + max = sensor->pa_src.height + sensor->vblank->val - +CCS_LIM (sensor,COARSE_INTEGRATION_TIME_MAX_MARGIN );__v4l2_ctrl_modify_range (ctrl, ctrl->minimum, max, ctrl->step, max); }@@ -728,15 +727,12 @@ static int ccs_set_ctrl(struct v4l2_ctrl *ctrl)break ;case V4L2_CID_VBLANK : rval =ccs_write (sensor,FRAME_LENGTH_LINES , - sensor->pixel_array->crop[ -CCS_PA_PAD_SRC ].height - + ctrl->val); + sensor->pa_src.height + ctrl->val);break ;case V4L2_CID_HBLANK : rval =ccs_write (sensor,LINE_LENGTH_PCK , - sensor->pixel_array->crop[CCS_PA_PAD_SRC ].width - + ctrl->val); + sensor->pa_src.width + ctrl->val);break ;case V4L2_CID_TEST_PATTERN :@@ -1214,15 +1210,13 @@ static void ccs_update_blanking(struct ccs_sensor *sensor) min =max_t (int,CCS_LIM (sensor,MIN_FRAME_BLANKING_LINES ), - min_fll - sensor->pixel_array->crop[CCS_PA_PAD_SRC ].height); - max = max_fll - sensor->pixel_array->crop[CCS_PA_PAD_SRC ].height; + min_fll - sensor->pa_src.height); + max = max_fll - sensor->pa_src.height;__v4l2_ctrl_modify_range (vblank, min, max, vblank->step, min); - min =max_t (int, - min_llp - sensor->pixel_array->crop[CCS_PA_PAD_SRC ].width, - min_lbp); - max = max_llp - sensor->pixel_array->crop[CCS_PA_PAD_SRC ].width; + min =max_t (int, min_llp - sensor->pa_src.width, min_lbp); + max = max_llp - sensor->pa_src.width;__v4l2_ctrl_modify_range (hblank, min, max, hblank->step, min);@@ -1246,10 +1240,8 @@ static int ccs_pll_blanking_update(struct ccs_sensor *sensor)dev_dbg (&client->dev,"real timeperframe\t100/%d\n" , sensor->pll.pixel_rate_pixel_array / - ((sensor->pixel_array->crop[CCS_PA_PAD_SRC ].width - + sensor->hblank->val) * - (sensor->pixel_array->crop[CCS_PA_PAD_SRC ].height - + sensor->vblank->val) /100 )); + ((sensor->pa_src.width + sensor->hblank->val) * + (sensor->pa_src.height + sensor->vblank->val) /100 ));return 0 ; }@@ -1756,28 +1748,22 @@ static int ccs_start_streaming(struct ccs_sensor *sensor) goto out;/* Analog crop start coordinates */ - rval =ccs_write (sensor,X_ADDR_START , - sensor->pixel_array->crop[CCS_PA_PAD_SRC ].left); + rval =ccs_write (sensor,X_ADDR_START , sensor->pa_src.left);if (rval <0 ) goto out; - rval =ccs_write (sensor,Y_ADDR_START , - sensor->pixel_array->crop[CCS_PA_PAD_SRC ].top); + rval =ccs_write (sensor,Y_ADDR_START , sensor->pa_src.top);if (rval <0 ) goto out;/* Analog crop end coordinates */ - rval =ccs_write ( - sensor,X_ADDR_END , - sensor->pixel_array->crop[CCS_PA_PAD_SRC ].left - + sensor->pixel_array->crop[CCS_PA_PAD_SRC ].width -1 ); + rval =ccs_write (sensor,X_ADDR_END , + sensor->pa_src.left + sensor->pa_src.width -1 );if (rval <0 ) goto out; - rval =ccs_write ( - sensor,Y_ADDR_END , - sensor->pixel_array->crop[CCS_PA_PAD_SRC ].top - + sensor->pixel_array->crop[CCS_PA_PAD_SRC ].height -1 ); + rval =ccs_write (sensor,Y_ADDR_END , + sensor->pa_src.top + sensor->pa_src.height -1 );if (rval <0 ) goto out;@@ -1789,27 +1775,23 @@ static int ccs_start_streaming(struct ccs_sensor *sensor)/* Digital crop */ if (CCS_LIM (sensor,DIGITAL_CROP_CAPABILITY ) ==CCS_DIGITAL_CROP_CAPABILITY_INPUT_CROP ) { - rval =ccs_write ( - sensor,DIGITAL_CROP_X_OFFSET , - sensor->scaler->crop[CCS_PAD_SINK ].left); + rval =ccs_write (sensor,DIGITAL_CROP_X_OFFSET , + sensor->scaler_sink.left);if (rval <0 ) goto out; - rval =ccs_write ( - sensor,DIGITAL_CROP_Y_OFFSET , - sensor->scaler->crop[CCS_PAD_SINK ].top); + rval =ccs_write (sensor,DIGITAL_CROP_Y_OFFSET , + sensor->scaler_sink.top);if (rval <0 ) goto out; - rval =ccs_write ( - sensor,DIGITAL_CROP_IMAGE_WIDTH , - sensor->scaler->crop[CCS_PAD_SINK ].width); + rval =ccs_write (sensor,DIGITAL_CROP_IMAGE_WIDTH , + sensor->scaler_sink.width);if (rval <0 ) goto out; - rval =ccs_write ( - sensor,DIGITAL_CROP_IMAGE_HEIGHT , - sensor->scaler->crop[CCS_PAD_SINK ].height); + rval =ccs_write (sensor,DIGITAL_CROP_IMAGE_HEIGHT , + sensor->scaler_sink.height);if (rval <0 ) goto out; }@@ -1827,12 +1809,10 @@ static int ccs_start_streaming(struct ccs_sensor *sensor) }/* Output size from sensor */ - rval =ccs_write (sensor,X_OUTPUT_SIZE , - sensor->src->crop[CCS_PAD_SRC ].width); + rval =ccs_write (sensor,X_OUTPUT_SIZE , sensor->src_src.width);if (rval <0 ) goto out; - rval =ccs_write (sensor,Y_OUTPUT_SIZE , - sensor->src->crop[CCS_PAD_SRC ].height); + rval =ccs_write (sensor,Y_OUTPUT_SIZE , sensor->src_src.height);if (rval <0 ) goto out;@@ -2053,24 +2033,8 @@ static int __ccs_get_format(struct v4l2_subdev *subdev,struct v4l2_subdev_state *sd_state, struct v4l2_subdev_format *fmt) { - struct ccs_subdev *ssd = to_ccs_subdev(subdev); - -if (fmt->which ==V4L2_SUBDEV_FORMAT_TRY ) { - fmt->format = *v4l2_subdev_get_try_format (subdev, sd_state, - fmt->pad); - }else { -struct v4l2_rect *r; - -if (fmt->pad == ssd->source_pad) - r = &ssd->crop[ssd->source_pad]; -else - r = &ssd->sink_fmt; - - fmt->format.code =__ccs_get_mbus_code (subdev, fmt->pad); - fmt->format.width = r->width; - fmt->format.height = r->height; - fmt->format.field =V4L2_FIELD_NONE ; - } + fmt->format = *v4l2_subdev_get_pad_format(subdev, sd_state, fmt->pad); + fmt->format.code =__ccs_get_mbus_code (subdev, fmt->pad);return 0 ; }@@ -2092,28 +2056,18 @@ static int ccs_get_format(struct v4l2_subdev *subdev,
Please replace ccs_get_format() with v4l2_subdev_get_fmt(). It's a drop-in replacement for the .get_fmt() operation, you can drop this function. The only remaining caller of __ccs_get_format() can then use v4l2_subdev_get_fmt() too.
Quoted 303 lines
drivers/media/i2c/ccs/ccs-core.c +57
-100static void ccs_get_crop_compose (struct v4l2_subdev *subdev,struct v4l2_subdev_state *sd_state,struct v4l2_rect **crops, -struct v4l2_rect **comps,int which) +struct v4l2_rect **comps) {struct ccs_subdev *ssd =to_ccs_subdev (subdev);unsigned int i; -if (which ==V4L2_SUBDEV_FORMAT_ACTIVE ) { -if (crops) -for (i =0 ; i < subdev->entity.num_pads; i++) - crops[i] = &ssd->crop[i]; -if (comps) - *comps = &ssd->compose; - }else { -if (crops) { -for (i =0 ; i < subdev->entity.num_pads; i++) - crops[i] =v4l2_subdev_get_try_crop (subdev, - sd_state, - i); - } -if (comps) - *comps =v4l2_subdev_get_try_compose (subdev, sd_state, -CCS_PAD_SINK ); - } +if (crops) +for (i =0 ; i < subdev->entity.num_pads; i++) + crops[i] = +v4l2_subdev_get_pad_crop (subdev, sd_state, i); +if (comps) + *comps =v4l2_subdev_get_pad_compose (subdev, sd_state, + ssd->sink_pad); }/* Changes require propagation only on sink pad. */ @@ -2125,7 +2079,7 @@ static void ccs_propagate(struct v4l2_subdev *subdev,struct ccs_subdev *ssd =to_ccs_subdev (subdev);struct v4l2_rect *comp, *crops[CCS_PADS ]; -ccs_get_crop_compose (subdev, sd_state, crops, &comp, which); +ccs_get_crop_compose (subdev, sd_state, crops, &comp);switch (target) {case V4L2_SEL_TGT_CROP :@@ -2136,6 +2090,7 @@ static void ccs_propagate(struct v4l2_subdev *subdev, sensor->scale_m =CCS_LIM (sensor,SCALER_N_MIN ); sensor->scaling_mode =CCS_SCALING_MODE_NO_SCALING ; + sensor->scaler_sink = *comp; }else if (ssd == sensor->binner) { sensor->binning_horizontal =1 ; sensor->binning_vertical =1 ;@@ -2144,6 +2099,8 @@ static void ccs_propagate(struct v4l2_subdev *subdev, fallthrough;case V4L2_SEL_TGT_COMPOSE : *crops[CCS_PAD_SRC ] = *comp; +if (which ==V4L2_SUBDEV_FORMAT_ACTIVE && ssd == sensor->src) + sensor->src_src = *crops[CCS_PAD_SRC ];break ;default :WARN_ON_ONCE (1 );@@ -2252,14 +2209,12 @@ static int ccs_set_format(struct v4l2_subdev *subdev,CCS_LIM (sensor,MIN_Y_OUTPUT_SIZE ), CCS_LIM(sensor, MAX_Y_OUTPUT_SIZE)); -ccs_get_crop_compose (subdev, sd_state, crops,NULL , fmt->which); +ccs_get_crop_compose (subdev, sd_state, crops,NULL ); crops[ssd->sink_pad]->left =0 ; crops[ssd->sink_pad]->top =0 ; crops[ssd->sink_pad]->width = fmt->format.width; crops[ssd->sink_pad]->height = fmt->format.height; -if (fmt->which ==V4L2_SUBDEV_FORMAT_ACTIVE ) - ssd->sink_fmt = *crops[ssd->sink_pad];ccs_propagate (subdev, sd_state, fmt->which,V4L2_SEL_TGT_CROP );mutex_unlock (&sensor->mutex);@@ -2482,7 +2437,7 @@ static int ccs_set_compose(struct v4l2_subdev *subdev,struct ccs_subdev *ssd =to_ccs_subdev (subdev);struct v4l2_rect *comp, *crops[CCS_PADS ]; -ccs_get_crop_compose (subdev, sd_state, crops, &comp, sel->which); +ccs_get_crop_compose (subdev, sd_state, crops, &comp); sel->r.top =0 ; sel->r.left =0 ;@@ -2501,8 +2456,8 @@ static int ccs_set_compose(struct v4l2_subdev *subdev,return 0 ; } -static int __ccs_sel_supported (struct v4l2_subdev *subdev, -struct v4l2_subdev_selection *sel) +static int ccs_sel_supported (struct v4l2_subdev *subdev, +struct v4l2_subdev_selection *sel) {struct ccs_sensor *sensor =to_ccs_sensor (subdev);struct ccs_subdev *ssd =to_ccs_subdev (subdev);@@ -2545,33 +2500,18 @@ static int ccs_set_crop(struct v4l2_subdev *subdev, {struct ccs_sensor *sensor =to_ccs_sensor (subdev);struct ccs_subdev *ssd =to_ccs_subdev (subdev); -struct v4l2_rect *src_size, *crops[CCS_PADS ]; -struct v4l2_rect _r; +struct v4l2_rect src_size = {0 }, *crops[CCS_PADS ], *comp; -ccs_get_crop_compose (subdev, sd_state, crops,NULL , sel->which); +ccs_get_crop_compose (subdev, sd_state, crops, &comp); -if (sel->which ==V4L2_SUBDEV_FORMAT_ACTIVE ) { -if (sel->pad == ssd->sink_pad) - src_size = &ssd->sink_fmt; -else - src_size = &ssd->compose; +if (sel->pad == ssd->sink_pad) { +struct v4l2_mbus_framefmt *mfmt = +v4l2_subdev_get_pad_format (subdev, sd_state, sel->pad); + + src_size.width = mfmt->width; + src_size.height = mfmt->height; }else { -if (sel->pad == ssd->sink_pad) { - _r.left =0 ; - _r.top =0 ; - _r.width =v4l2_subdev_get_try_format (subdev, - sd_state, - sel->pad) - ->width; - _r.height =v4l2_subdev_get_try_format (subdev, - sd_state, - sel->pad) - ->height; - src_size = &_r; - }else { - src_size =v4l2_subdev_get_try_compose ( - subdev, sd_state, ssd->sink_pad); - } + src_size = *comp; }if (ssd == sensor->src && sel->pad ==CCS_PAD_SRC ) {@@ -2579,16 +2519,19 @@ static int ccs_set_crop(struct v4l2_subdev *subdev, sel->r.top =0 ; } - sel->r.width =min (sel->r.width, src_size->width); - sel->r.height =min (sel->r.height, src_size->height); + sel->r.width =min (sel->r.width, src_size.width); + sel->r.height =min (sel->r.height, src_size.height); - sel->r.left =min_t (int, sel->r.left, src_size->width - sel->r.width); - sel->r.top =min_t (int, sel->r.top, src_size->height - sel->r.height); + sel->r.left =min_t (int, sel->r.left, src_size.width - sel->r.width); + sel->r.top =min_t (int, sel->r.top, src_size.height - sel->r.height); *crops[sel->pad] = sel->r;if (ssd != sensor->pixel_array && sel->pad ==CCS_PAD_SINK )ccs_propagate (subdev, sd_state, sel->which,V4L2_SEL_TGT_CROP ); +else if (sel->which ==V4L2_SUBDEV_FORMAT_ACTIVE && + ssd == sensor->pixel_array) + sensor->pa_src = sel->r;return 0 ; }@@ -2601,44 +2544,36 @@ static void ccs_get_native_size(struct ccs_subdev *ssd, struct v4l2_rect *r) r->height =CCS_LIM (ssd->sensor,Y_ADDR_MAX ) +1 ; } -static int __ccs_get_selection (struct v4l2_subdev *subdev, -struct v4l2_subdev_state *sd_state, -struct v4l2_subdev_selection *sel) +static int ccs_get_selection (struct v4l2_subdev *subdev, +struct v4l2_subdev_state *sd_state, +struct v4l2_subdev_selection *sel) {struct ccs_sensor *sensor =to_ccs_sensor (subdev);struct ccs_subdev *ssd =to_ccs_subdev (subdev);struct v4l2_rect *comp, *crops[CCS_PADS ]; -struct v4l2_rect sink_fmt;int ret; - ret =__ccs_sel_supported (subdev, sel); + ret =ccs_sel_supported (subdev, sel);if (ret)return ret; -ccs_get_crop_compose (subdev, sd_state, crops, &comp, sel->which); - -if (sel->which ==V4L2_SUBDEV_FORMAT_ACTIVE ) { - sink_fmt = ssd->sink_fmt; - }else { -struct v4l2_mbus_framefmt *fmt = -v4l2_subdev_get_try_format (subdev, sd_state, - ssd->sink_pad); - - sink_fmt.left =0 ; - sink_fmt.top =0 ; - sink_fmt.width = fmt->width; - sink_fmt.height = fmt->height; - } +ccs_get_crop_compose (subdev, sd_state, crops, &comp);switch (sel->target) {case V4L2_SEL_TGT_CROP_BOUNDS :case V4L2_SEL_TGT_NATIVE_SIZE : -if (ssd == sensor->pixel_array) +if (ssd == sensor->pixel_array) {ccs_get_native_size (ssd, &sel->r); -else if (sel->pad == ssd->sink_pad) - sel->r = sink_fmt; -else + }else if (sel->pad == ssd->sink_pad) { +struct v4l2_mbus_framefmt *sink_fmt = +v4l2_subdev_get_pad_format (subdev, sd_state, + ssd->sink_pad); + sel->r.top = sel->r.left =0 ; + sel->r.width = sink_fmt->width; + sel->r.height = sink_fmt->height; + }else { sel->r = *comp; + }break ;case V4L2_SEL_TGT_CROP :case V4L2_SEL_TGT_COMPOSE_BOUNDS :@@ -2652,20 +2587,6 @@ static int __ccs_get_selection(struct v4l2_subdev *subdev,return 0 ; } -static int ccs_get_selection (struct v4l2_subdev *subdev, -struct v4l2_subdev_state *sd_state, -struct v4l2_subdev_selection *sel) -{ -struct ccs_sensor *sensor =to_ccs_sensor (subdev); -int rval; - -mutex_lock (&sensor->mutex); - rval =__ccs_get_selection (subdev, sd_state, sel); -mutex_unlock (&sensor->mutex); - -return rval; -} -static int ccs_set_selection (struct v4l2_subdev *subdev,struct v4l2_subdev_state *sd_state,struct v4l2_subdev_selection *sel)@@ -2673,7 +2594,7 @@ static int ccs_set_selection(struct v4l2_subdev *subdev,struct ccs_sensor *sensor =to_ccs_sensor (subdev);int ret; - ret =__ccs_sel_supported (subdev, sel); + ret =ccs_sel_supported (subdev, sel);if (ret)return ret;@@ -2964,10 +2885,14 @@ static int ccs_register_subdev(struct ccs_sensor *sensor,return rval; } + rval =v4l2_subdev_init_finalize (&ssd->sd); +if (rval) + goto out_media_entity_cleanup; + rval =v4l2_device_register_subdev (sensor->src->sd.v4l2_dev, &ssd->sd);if (rval) {dev_err (&client->dev,"v4l2_device_register_subdev failed\n" ); - goto out_media_entity_cleanup; + goto out_v4l2_subdev_cleanup; } rval = media_create_pad_link(&ssd->sd.entity, source_pad,@@ -2983,6 +2908,9 @@ static int ccs_register_subdev(struct ccs_sensor *sensor, out_v4l2_device_unregister_subdev:v4l2_device_unregister_subdev (&ssd->sd); +out_v4l2_subdev_cleanup: +v4l2_subdev_cleanup (&ssd->sd); + out_media_entity_cleanup:media_entity_cleanup (&ssd->sd.entity);@@ -3059,16 +2987,9 @@ static void ccs_create_subdev(struct ccs_sensor *sensor,v4l2_i2c_subdev_set_name (&ssd->sd, client, sensor->minfo.name, name); -ccs_get_native_size (ssd, &ssd->sink_fmt); - - ssd->compose.width = ssd->sink_fmt.width; - ssd->compose.height = ssd->sink_fmt.height; - ssd->crop[ssd->source_pad] = ssd->compose; ssd->pads[ssd->source_pad].flags =MEDIA_PAD_FL_SOURCE ; -if (ssd != sensor->pixel_array) { - ssd->crop[ssd->sink_pad] = ssd->compose; +if (ssd != sensor->pixel_array) ssd->pads[ssd->sink_pad].flags =MEDIA_PAD_FL_SINK ; - } ssd->sd.entity.ops = &ccs_entity_ops;@@ -3089,24 +3010,24 @@ static int ccs_init_cfg(struct v4l2_subdev *sd, struct v4l2_subdev_state *sd_stamutex_lock (&sensor->mutex);for (i =0 ; i < ssd->npads; i++) {
drivers/media/i2c/ccs/ccs-core.c static int ccs_init_cfg(struct v4l2_subdev *sd, struct v4l2_subdev_state *sd_sta · line 3017
Quoted 10 lines
drivers/media/i2c/ccs/ccs-core.c +5
-5-struct v4l2_mbus_framefmt *try_fmt = -v4l2_subdev_get_try_format (sd, sd_state, i); -struct v4l2_rect *try_crop = -v4l2_subdev_get_try_crop (sd, sd_state, i); -struct v4l2_rect *try_comp; +struct v4l2_mbus_framefmt *pad_fmt = +v4l2_subdev_get_pad_format (sd, sd_state, i); +struct v4l2_rect *pad_crop = +v4l2_subdev_get_pad_crop (sd, sd_state, i); +struct v4l2_rect *pad_comp;
These can simply be called fmt, crop and comp.
Quoted 57 lines
drivers/media/i2c/ccs/ccs-core.c +12
-7-ccs_get_native_size (ssd, try_crop); +ccs_get_native_size (ssd, pad_crop); - try_fmt->width = try_crop->width; - try_fmt->height = try_crop->height; - try_fmt->code = sensor->internal_csi_format->code; - try_fmt->field =V4L2_FIELD_NONE ; + pad_fmt->width = pad_crop->width; + pad_fmt->height = pad_crop->height; + pad_fmt->code = sensor->internal_csi_format->code; + pad_fmt->field =V4L2_FIELD_NONE ;if (ssd == sensor->pixel_array)continue ; - try_comp =v4l2_subdev_get_try_compose (sd, sd_state, i); - *try_comp = *try_crop; + pad_comp =v4l2_subdev_get_pad_compose (sd, sd_state, i); + *pad_comp = *pad_crop; }mutex_unlock (&sensor->mutex);@@ -3631,6 +3552,10 @@ static int ccs_probe(struct i2c_client *client)if (rval <0 ) goto out_media_entity_cleanup; + rval =v4l2_subdev_init_finalize (&sensor->src->sd); +if (rval) + goto out_media_entity_cleanup; + rval =ccs_write_msr_regs (sensor);if (rval) goto out_media_entity_cleanup;@@ -3690,6 +3615,7 @@ static void ccs_remove(struct i2c_client *client)for (i =0 ; i < sensor->ssds_used; i++) {v4l2_device_unregister_subdev (&sensor->ssds[i].sd); +v4l2_subdev_cleanup (subdev);media_entity_cleanup (&sensor->ssds[i].sd.entity); }ccs_cleanup (sensor);drivers/media/i2c/ccs/ccs.h +0
-3@@ -182,9 +182,6 @@ struct ccs_binning_subtype {struct ccs_subdev {struct v4l2_subdev sd;struct media_pad pads[CCS_PADS ]; -struct v4l2_rect sink_fmt; -struct v4l2_rect crop[CCS_PADS ]; -struct v4l2_rect compose;/* compose on sink */ unsigned short sink_pad;unsigned short source_pad;int npads;
drivers/media/i2c/ccs/ccs.h struct ccs_sensor { · line 220
Quoted 4 lines
drivers/media/i2c/ccs/ccs.h +1
-0@@ -220,6 +217,7 @@ struct ccs_sensor {u32 mbus_frame_fmts;const struct ccs_csi_data_format *csi_format;const struct ccs_csi_data_format *internal_csi_format; +struct v4l2_rect pa_src, scaler_sink, src_src;
The idea of the active state API is to remove all active state from the driver private structure. Why do you need these, can't you get them from the active state where appropriate ?
Quoted 3 lines
drivers/media/i2c/ccs/ccs.h +0
-0u32 default_mbus_frame_fmts;int default_pixel_order;struct ccs_data_container sdata, mdata;
Signature · 3 lines
Regards, Laurent Pinchart
Sakari Ailus
maintainerRe: [PATCH v2 06/12] media: ccs: Use sub-device active state
Hi Laurent,
Quoted 3 lines · Laurent Pinchart
Hi Sakari,
Thank you for the patch.
Thanks for the review!
Quoted 193 lines · Sakari Ailus
Quoted 191 lines
Make use of sub-device active state. In most cases the effect on need for acquiring the mutex is non-existent as access to the driver's core data structure still needs to be serialised.
This still removes a lot of code as the code paths for active and try state are the same in many cases.
Signed-off-by Sakari Ailus <[email protected]>--- drivers/media/i2c/ccs/ccs-core.c | 278 ++++++++++++------------------- drivers/media/i2c/ccs/ccs.h | 4 +- 2 files changed, 103 insertions(+), 179 deletions(-)drivers/media/i2c/ccs/ccs-core.c +28
-64@@ -508,9 +508,8 @@ static void __ccs_update_exposure_limits(struct ccs_sensor *sensor)struct v4l2_ctrl *ctrl = sensor->exposure;int max; - max = sensor->pixel_array->crop[CCS_PA_PAD_SRC ].height - + sensor->vblank->val - -CCS_LIM (sensor,COARSE_INTEGRATION_TIME_MAX_MARGIN ); + max = sensor->pa_src.height + sensor->vblank->val - +CCS_LIM (sensor,COARSE_INTEGRATION_TIME_MAX_MARGIN );__v4l2_ctrl_modify_range (ctrl, ctrl->minimum, max, ctrl->step, max); }@@ -728,15 +727,12 @@ static int ccs_set_ctrl(struct v4l2_ctrl *ctrl)break ;case V4L2_CID_VBLANK : rval =ccs_write (sensor,FRAME_LENGTH_LINES , - sensor->pixel_array->crop[ -CCS_PA_PAD_SRC ].height - + ctrl->val); + sensor->pa_src.height + ctrl->val);break ;case V4L2_CID_HBLANK : rval =ccs_write (sensor,LINE_LENGTH_PCK , - sensor->pixel_array->crop[CCS_PA_PAD_SRC ].width - + ctrl->val); + sensor->pa_src.width + ctrl->val);break ;case V4L2_CID_TEST_PATTERN :@@ -1214,15 +1210,13 @@ static void ccs_update_blanking(struct ccs_sensor *sensor) min =max_t (int,CCS_LIM (sensor,MIN_FRAME_BLANKING_LINES ), - min_fll - sensor->pixel_array->crop[CCS_PA_PAD_SRC ].height); - max = max_fll - sensor->pixel_array->crop[CCS_PA_PAD_SRC ].height; + min_fll - sensor->pa_src.height); + max = max_fll - sensor->pa_src.height;__v4l2_ctrl_modify_range (vblank, min, max, vblank->step, min); - min =max_t (int, - min_llp - sensor->pixel_array->crop[CCS_PA_PAD_SRC ].width, - min_lbp); - max = max_llp - sensor->pixel_array->crop[CCS_PA_PAD_SRC ].width; + min =max_t (int, min_llp - sensor->pa_src.width, min_lbp); + max = max_llp - sensor->pa_src.width;__v4l2_ctrl_modify_range (hblank, min, max, hblank->step, min);@@ -1246,10 +1240,8 @@ static int ccs_pll_blanking_update(struct ccs_sensor *sensor)dev_dbg (&client->dev,"real timeperframe\t100/%d\n" , sensor->pll.pixel_rate_pixel_array / - ((sensor->pixel_array->crop[CCS_PA_PAD_SRC ].width - + sensor->hblank->val) * - (sensor->pixel_array->crop[CCS_PA_PAD_SRC ].height - + sensor->vblank->val) /100 )); + ((sensor->pa_src.width + sensor->hblank->val) * + (sensor->pa_src.height + sensor->vblank->val) /100 ));return 0 ; }@@ -1756,28 +1748,22 @@ static int ccs_start_streaming(struct ccs_sensor *sensor) goto out;/* Analog crop start coordinates */ - rval =ccs_write (sensor,X_ADDR_START , - sensor->pixel_array->crop[CCS_PA_PAD_SRC ].left); + rval =ccs_write (sensor,X_ADDR_START , sensor->pa_src.left);if (rval <0 ) goto out; - rval =ccs_write (sensor,Y_ADDR_START , - sensor->pixel_array->crop[CCS_PA_PAD_SRC ].top); + rval =ccs_write (sensor,Y_ADDR_START , sensor->pa_src.top);if (rval <0 ) goto out;/* Analog crop end coordinates */ - rval =ccs_write ( - sensor,X_ADDR_END , - sensor->pixel_array->crop[CCS_PA_PAD_SRC ].left - + sensor->pixel_array->crop[CCS_PA_PAD_SRC ].width -1 ); + rval =ccs_write (sensor,X_ADDR_END , + sensor->pa_src.left + sensor->pa_src.width -1 );if (rval <0 ) goto out; - rval =ccs_write ( - sensor,Y_ADDR_END , - sensor->pixel_array->crop[CCS_PA_PAD_SRC ].top - + sensor->pixel_array->crop[CCS_PA_PAD_SRC ].height -1 ); + rval =ccs_write (sensor,Y_ADDR_END , + sensor->pa_src.top + sensor->pa_src.height -1 );if (rval <0 ) goto out;@@ -1789,27 +1775,23 @@ static int ccs_start_streaming(struct ccs_sensor *sensor)/* Digital crop */ if (CCS_LIM (sensor,DIGITAL_CROP_CAPABILITY ) ==CCS_DIGITAL_CROP_CAPABILITY_INPUT_CROP ) { - rval =ccs_write ( - sensor,DIGITAL_CROP_X_OFFSET , - sensor->scaler->crop[CCS_PAD_SINK ].left); + rval =ccs_write (sensor,DIGITAL_CROP_X_OFFSET , + sensor->scaler_sink.left);if (rval <0 ) goto out; - rval =ccs_write ( - sensor,DIGITAL_CROP_Y_OFFSET , - sensor->scaler->crop[CCS_PAD_SINK ].top); + rval =ccs_write (sensor,DIGITAL_CROP_Y_OFFSET , + sensor->scaler_sink.top);if (rval <0 ) goto out; - rval =ccs_write ( - sensor,DIGITAL_CROP_IMAGE_WIDTH , - sensor->scaler->crop[CCS_PAD_SINK ].width); + rval =ccs_write (sensor,DIGITAL_CROP_IMAGE_WIDTH , + sensor->scaler_sink.width);if (rval <0 ) goto out; - rval =ccs_write ( - sensor,DIGITAL_CROP_IMAGE_HEIGHT , - sensor->scaler->crop[CCS_PAD_SINK ].height); + rval =ccs_write (sensor,DIGITAL_CROP_IMAGE_HEIGHT , + sensor->scaler_sink.height);if (rval <0 ) goto out; }@@ -1827,12 +1809,10 @@ static int ccs_start_streaming(struct ccs_sensor *sensor) }/* Output size from sensor */ - rval =ccs_write (sensor,X_OUTPUT_SIZE , - sensor->src->crop[CCS_PAD_SRC ].width); + rval =ccs_write (sensor,X_OUTPUT_SIZE , sensor->src_src.width);if (rval <0 ) goto out; - rval =ccs_write (sensor,Y_OUTPUT_SIZE , - sensor->src->crop[CCS_PAD_SRC ].height); + rval =ccs_write (sensor,Y_OUTPUT_SIZE , sensor->src_src.height);if (rval <0 ) goto out;@@ -2053,24 +2033,8 @@ static int __ccs_get_format(struct v4l2_subdev *subdev,struct v4l2_subdev_state *sd_state, struct v4l2_subdev_format *fmt) { - struct ccs_subdev *ssd = to_ccs_subdev(subdev); - -if (fmt->which ==V4L2_SUBDEV_FORMAT_TRY ) { - fmt->format = *v4l2_subdev_get_try_format (subdev, sd_state, - fmt->pad); - }else { -struct v4l2_rect *r; - -if (fmt->pad == ssd->source_pad) - r = &ssd->crop[ssd->source_pad]; -else - r = &ssd->sink_fmt; - - fmt->format.code =__ccs_get_mbus_code (subdev, fmt->pad); - fmt->format.width = r->width; - fmt->format.height = r->height; - fmt->format.field =V4L2_FIELD_NONE ; - } + fmt->format = *v4l2_subdev_get_pad_format(subdev, sd_state, fmt->pad); + fmt->format.code =__ccs_get_mbus_code (subdev, fmt->pad);
Quoted 8 lines
drivers/media/i2c/ccs/ccs-core.c static int ccs_get_format(struct v4l2_subdev *subdev,
Quoted 3 lines
drivers/media/i2c/ccs/ccs-core.c +0
-0return 0 ; }@@ -2092,28 +2056,18 @@ static int ccs_get_format(struct v4l2_subdev *subdev,Please replace
ccs_get_format()withv4l2_subdev_get_fmt(). It's a drop-in replacement for the .get_fmt() operation, you can drop this function. The only remaining caller of__ccs_get_format()can then usev4l2_subdev_get_fmt()too.
That is my goal but the issue is that it (sligthly) changes UAPI behaviour. Currently the flipping controls also affect the try formats.
Quoted 303 lines
Quoted 303 lines
drivers/media/i2c/ccs/ccs-core.c +57
-100static void ccs_get_crop_compose (struct v4l2_subdev *subdev,struct v4l2_subdev_state *sd_state,struct v4l2_rect **crops, -struct v4l2_rect **comps,int which) +struct v4l2_rect **comps) {struct ccs_subdev *ssd =to_ccs_subdev (subdev);unsigned int i; -if (which ==V4L2_SUBDEV_FORMAT_ACTIVE ) { -if (crops) -for (i =0 ; i < subdev->entity.num_pads; i++) - crops[i] = &ssd->crop[i]; -if (comps) - *comps = &ssd->compose; - }else { -if (crops) { -for (i =0 ; i < subdev->entity.num_pads; i++) - crops[i] =v4l2_subdev_get_try_crop (subdev, - sd_state, - i); - } -if (comps) - *comps =v4l2_subdev_get_try_compose (subdev, sd_state, -CCS_PAD_SINK ); - } +if (crops) +for (i =0 ; i < subdev->entity.num_pads; i++) + crops[i] = +v4l2_subdev_get_pad_crop (subdev, sd_state, i); +if (comps) + *comps =v4l2_subdev_get_pad_compose (subdev, sd_state, + ssd->sink_pad); }/* Changes require propagation only on sink pad. */ @@ -2125,7 +2079,7 @@ static void ccs_propagate(struct v4l2_subdev *subdev,struct ccs_subdev *ssd =to_ccs_subdev (subdev);struct v4l2_rect *comp, *crops[CCS_PADS ]; -ccs_get_crop_compose (subdev, sd_state, crops, &comp, which); +ccs_get_crop_compose (subdev, sd_state, crops, &comp);switch (target) {case V4L2_SEL_TGT_CROP :@@ -2136,6 +2090,7 @@ static void ccs_propagate(struct v4l2_subdev *subdev, sensor->scale_m =CCS_LIM (sensor,SCALER_N_MIN ); sensor->scaling_mode =CCS_SCALING_MODE_NO_SCALING ; + sensor->scaler_sink = *comp; }else if (ssd == sensor->binner) { sensor->binning_horizontal =1 ; sensor->binning_vertical =1 ;@@ -2144,6 +2099,8 @@ static void ccs_propagate(struct v4l2_subdev *subdev, fallthrough;case V4L2_SEL_TGT_COMPOSE : *crops[CCS_PAD_SRC ] = *comp; +if (which ==V4L2_SUBDEV_FORMAT_ACTIVE && ssd == sensor->src) + sensor->src_src = *crops[CCS_PAD_SRC ];break ;default :WARN_ON_ONCE (1 );@@ -2252,14 +2209,12 @@ static int ccs_set_format(struct v4l2_subdev *subdev,CCS_LIM (sensor,MIN_Y_OUTPUT_SIZE ), CCS_LIM(sensor, MAX_Y_OUTPUT_SIZE)); -ccs_get_crop_compose (subdev, sd_state, crops,NULL , fmt->which); +ccs_get_crop_compose (subdev, sd_state, crops,NULL ); crops[ssd->sink_pad]->left =0 ; crops[ssd->sink_pad]->top =0 ; crops[ssd->sink_pad]->width = fmt->format.width; crops[ssd->sink_pad]->height = fmt->format.height; -if (fmt->which ==V4L2_SUBDEV_FORMAT_ACTIVE ) - ssd->sink_fmt = *crops[ssd->sink_pad];ccs_propagate (subdev, sd_state, fmt->which,V4L2_SEL_TGT_CROP );mutex_unlock (&sensor->mutex);@@ -2482,7 +2437,7 @@ static int ccs_set_compose(struct v4l2_subdev *subdev,struct ccs_subdev *ssd =to_ccs_subdev (subdev);struct v4l2_rect *comp, *crops[CCS_PADS ]; -ccs_get_crop_compose (subdev, sd_state, crops, &comp, sel->which); +ccs_get_crop_compose (subdev, sd_state, crops, &comp); sel->r.top =0 ; sel->r.left =0 ;@@ -2501,8 +2456,8 @@ static int ccs_set_compose(struct v4l2_subdev *subdev,return 0 ; } -static int __ccs_sel_supported (struct v4l2_subdev *subdev, -struct v4l2_subdev_selection *sel) +static int ccs_sel_supported (struct v4l2_subdev *subdev, +struct v4l2_subdev_selection *sel) {struct ccs_sensor *sensor =to_ccs_sensor (subdev);struct ccs_subdev *ssd =to_ccs_subdev (subdev);@@ -2545,33 +2500,18 @@ static int ccs_set_crop(struct v4l2_subdev *subdev, {struct ccs_sensor *sensor =to_ccs_sensor (subdev);struct ccs_subdev *ssd =to_ccs_subdev (subdev); -struct v4l2_rect *src_size, *crops[CCS_PADS ]; -struct v4l2_rect _r; +struct v4l2_rect src_size = {0 }, *crops[CCS_PADS ], *comp; -ccs_get_crop_compose (subdev, sd_state, crops,NULL , sel->which); +ccs_get_crop_compose (subdev, sd_state, crops, &comp); -if (sel->which ==V4L2_SUBDEV_FORMAT_ACTIVE ) { -if (sel->pad == ssd->sink_pad) - src_size = &ssd->sink_fmt; -else - src_size = &ssd->compose; +if (sel->pad == ssd->sink_pad) { +struct v4l2_mbus_framefmt *mfmt = +v4l2_subdev_get_pad_format (subdev, sd_state, sel->pad); + + src_size.width = mfmt->width; + src_size.height = mfmt->height; }else { -if (sel->pad == ssd->sink_pad) { - _r.left =0 ; - _r.top =0 ; - _r.width =v4l2_subdev_get_try_format (subdev, - sd_state, - sel->pad) - ->width; - _r.height =v4l2_subdev_get_try_format (subdev, - sd_state, - sel->pad) - ->height; - src_size = &_r; - }else { - src_size =v4l2_subdev_get_try_compose ( - subdev, sd_state, ssd->sink_pad); - } + src_size = *comp; }if (ssd == sensor->src && sel->pad ==CCS_PAD_SRC ) {@@ -2579,16 +2519,19 @@ static int ccs_set_crop(struct v4l2_subdev *subdev, sel->r.top =0 ; } - sel->r.width =min (sel->r.width, src_size->width); - sel->r.height =min (sel->r.height, src_size->height); + sel->r.width =min (sel->r.width, src_size.width); + sel->r.height =min (sel->r.height, src_size.height); - sel->r.left =min_t (int, sel->r.left, src_size->width - sel->r.width); - sel->r.top =min_t (int, sel->r.top, src_size->height - sel->r.height); + sel->r.left =min_t (int, sel->r.left, src_size.width - sel->r.width); + sel->r.top =min_t (int, sel->r.top, src_size.height - sel->r.height); *crops[sel->pad] = sel->r;if (ssd != sensor->pixel_array && sel->pad ==CCS_PAD_SINK )ccs_propagate (subdev, sd_state, sel->which,V4L2_SEL_TGT_CROP ); +else if (sel->which ==V4L2_SUBDEV_FORMAT_ACTIVE && + ssd == sensor->pixel_array) + sensor->pa_src = sel->r;return 0 ; }@@ -2601,44 +2544,36 @@ static void ccs_get_native_size(struct ccs_subdev *ssd, struct v4l2_rect *r) r->height =CCS_LIM (ssd->sensor,Y_ADDR_MAX ) +1 ; } -static int __ccs_get_selection (struct v4l2_subdev *subdev, -struct v4l2_subdev_state *sd_state, -struct v4l2_subdev_selection *sel) +static int ccs_get_selection (struct v4l2_subdev *subdev, +struct v4l2_subdev_state *sd_state, +struct v4l2_subdev_selection *sel) {struct ccs_sensor *sensor =to_ccs_sensor (subdev);struct ccs_subdev *ssd =to_ccs_subdev (subdev);struct v4l2_rect *comp, *crops[CCS_PADS ]; -struct v4l2_rect sink_fmt;int ret; - ret =__ccs_sel_supported (subdev, sel); + ret =ccs_sel_supported (subdev, sel);if (ret)return ret; -ccs_get_crop_compose (subdev, sd_state, crops, &comp, sel->which); - -if (sel->which ==V4L2_SUBDEV_FORMAT_ACTIVE ) { - sink_fmt = ssd->sink_fmt; - }else { -struct v4l2_mbus_framefmt *fmt = -v4l2_subdev_get_try_format (subdev, sd_state, - ssd->sink_pad); - - sink_fmt.left =0 ; - sink_fmt.top =0 ; - sink_fmt.width = fmt->width; - sink_fmt.height = fmt->height; - } +ccs_get_crop_compose (subdev, sd_state, crops, &comp);switch (sel->target) {case V4L2_SEL_TGT_CROP_BOUNDS :case V4L2_SEL_TGT_NATIVE_SIZE : -if (ssd == sensor->pixel_array) +if (ssd == sensor->pixel_array) {ccs_get_native_size (ssd, &sel->r); -else if (sel->pad == ssd->sink_pad) - sel->r = sink_fmt; -else + }else if (sel->pad == ssd->sink_pad) { +struct v4l2_mbus_framefmt *sink_fmt = +v4l2_subdev_get_pad_format (subdev, sd_state, + ssd->sink_pad); + sel->r.top = sel->r.left =0 ; + sel->r.width = sink_fmt->width; + sel->r.height = sink_fmt->height; + }else { sel->r = *comp; + }break ;case V4L2_SEL_TGT_CROP :case V4L2_SEL_TGT_COMPOSE_BOUNDS :@@ -2652,20 +2587,6 @@ static int __ccs_get_selection(struct v4l2_subdev *subdev,return 0 ; } -static int ccs_get_selection (struct v4l2_subdev *subdev, -struct v4l2_subdev_state *sd_state, -struct v4l2_subdev_selection *sel) -{ -struct ccs_sensor *sensor =to_ccs_sensor (subdev); -int rval; - -mutex_lock (&sensor->mutex); - rval =__ccs_get_selection (subdev, sd_state, sel); -mutex_unlock (&sensor->mutex); - -return rval; -} -static int ccs_set_selection (struct v4l2_subdev *subdev,struct v4l2_subdev_state *sd_state,struct v4l2_subdev_selection *sel)@@ -2673,7 +2594,7 @@ static int ccs_set_selection(struct v4l2_subdev *subdev,struct ccs_sensor *sensor =to_ccs_sensor (subdev);int ret; - ret =__ccs_sel_supported (subdev, sel); + ret =ccs_sel_supported (subdev, sel);if (ret)return ret;@@ -2964,10 +2885,14 @@ static int ccs_register_subdev(struct ccs_sensor *sensor,return rval; } + rval =v4l2_subdev_init_finalize (&ssd->sd); +if (rval) + goto out_media_entity_cleanup; + rval =v4l2_device_register_subdev (sensor->src->sd.v4l2_dev, &ssd->sd);if (rval) {dev_err (&client->dev,"v4l2_device_register_subdev failed\n" ); - goto out_media_entity_cleanup; + goto out_v4l2_subdev_cleanup; } rval = media_create_pad_link(&ssd->sd.entity, source_pad,@@ -2983,6 +2908,9 @@ static int ccs_register_subdev(struct ccs_sensor *sensor, out_v4l2_device_unregister_subdev:v4l2_device_unregister_subdev (&ssd->sd); +out_v4l2_subdev_cleanup: +v4l2_subdev_cleanup (&ssd->sd); + out_media_entity_cleanup:media_entity_cleanup (&ssd->sd.entity);@@ -3059,16 +2987,9 @@ static void ccs_create_subdev(struct ccs_sensor *sensor,v4l2_i2c_subdev_set_name (&ssd->sd, client, sensor->minfo.name, name); -ccs_get_native_size (ssd, &ssd->sink_fmt); - - ssd->compose.width = ssd->sink_fmt.width; - ssd->compose.height = ssd->sink_fmt.height; - ssd->crop[ssd->source_pad] = ssd->compose; ssd->pads[ssd->source_pad].flags =MEDIA_PAD_FL_SOURCE ; -if (ssd != sensor->pixel_array) { - ssd->crop[ssd->sink_pad] = ssd->compose; +if (ssd != sensor->pixel_array) ssd->pads[ssd->sink_pad].flags =MEDIA_PAD_FL_SINK ; - } ssd->sd.entity.ops = &ccs_entity_ops;@@ -3089,24 +3010,24 @@ static int ccs_init_cfg(struct v4l2_subdev *sd, struct v4l2_subdev_state *sd_stamutex_lock (&sensor->mutex);
Quoted 13 lines
drivers/media/i2c/ccs/ccs-core.c static int ccs_init_cfg(struct v4l2_subdev *sd, struct v4l2_subdev_state *sd_sta · line 3017
Quoted 11 lines
drivers/media/i2c/ccs/ccs-core.c +5
-5for (i =0 ; i < ssd->npads; i++) { -struct v4l2_mbus_framefmt *try_fmt = -v4l2_subdev_get_try_format (sd, sd_state, i); -struct v4l2_rect *try_crop = -v4l2_subdev_get_try_crop (sd, sd_state, i); -struct v4l2_rect *try_comp; +struct v4l2_mbus_framefmt *pad_fmt = +v4l2_subdev_get_pad_format (sd, sd_state, i); +struct v4l2_rect *pad_crop = +v4l2_subdev_get_pad_crop (sd, sd_state, i); +struct v4l2_rect *pad_comp;These can simply be called fmt, crop and comp.
Yes.
Quoted 58 lines
Quoted 58 lines
drivers/media/i2c/ccs/ccs-core.c +12
-7-ccs_get_native_size (ssd, try_crop); +ccs_get_native_size (ssd, pad_crop); - try_fmt->width = try_crop->width; - try_fmt->height = try_crop->height; - try_fmt->code = sensor->internal_csi_format->code; - try_fmt->field =V4L2_FIELD_NONE ; + pad_fmt->width = pad_crop->width; + pad_fmt->height = pad_crop->height; + pad_fmt->code = sensor->internal_csi_format->code; + pad_fmt->field =V4L2_FIELD_NONE ;if (ssd == sensor->pixel_array)continue ; - try_comp =v4l2_subdev_get_try_compose (sd, sd_state, i); - *try_comp = *try_crop; + pad_comp =v4l2_subdev_get_pad_compose (sd, sd_state, i); + *pad_comp = *pad_crop; }mutex_unlock (&sensor->mutex);@@ -3631,6 +3552,10 @@ static int ccs_probe(struct i2c_client *client)if (rval <0 ) goto out_media_entity_cleanup; + rval =v4l2_subdev_init_finalize (&sensor->src->sd); +if (rval) + goto out_media_entity_cleanup; + rval =ccs_write_msr_regs (sensor);if (rval) goto out_media_entity_cleanup;@@ -3690,6 +3615,7 @@ static void ccs_remove(struct i2c_client *client)for (i =0 ; i < sensor->ssds_used; i++) {v4l2_device_unregister_subdev (&sensor->ssds[i].sd); +v4l2_subdev_cleanup (subdev);media_entity_cleanup (&sensor->ssds[i].sd.entity); }ccs_cleanup (sensor);drivers/media/i2c/ccs/ccs.h +0
-3@@ -182,9 +182,6 @@ struct ccs_binning_subtype {struct ccs_subdev {struct v4l2_subdev sd;struct media_pad pads[CCS_PADS ]; -struct v4l2_rect sink_fmt; -struct v4l2_rect crop[CCS_PADS ]; -struct v4l2_rect compose;/* compose on sink */ unsigned short sink_pad;unsigned short source_pad;int npads;@@ -220,6 +217,7 @@ struct ccs_sensor {
Quoted 8 lines
drivers/media/i2c/ccs/ccs.h struct ccs_sensor { · line 220
Quoted 4 lines
drivers/media/i2c/ccs/ccs.h +1
-0u32 mbus_frame_fmts;const struct ccs_csi_data_format *csi_format;const struct ccs_csi_data_format *internal_csi_format; +struct v4l2_rect pa_src, scaler_sink, src_src;The idea of the active state API is to remove all active state from the driver private structure. Why do you need these, can't you get them from the active state where appropriate ?
The issue is the dependency to controls that can't be accessed with the state lock (only) held.
If we can remove that dependency, with a slight change to UAPI, then this can be done.
Quoted 5 lines
Quoted 4 lines
drivers/media/i2c/ccs/ccs.h +0
-0u32 default_mbus_frame_fmts;int default_pixel_order;struct ccs_data_container sdata, mdata;
Signature · 3 lines
Regards, Sakari Ailus
Laurent Pinchart
maintainerRe: [PATCH v2 06/12] media: ccs: Use sub-device active state
Hi Sakari,
Quoted 202 lines · Sakari Ailus
Quoted 192 lines · Laurent Pinchart
Quoted 191 lines · Sakari Ailus
Make use of sub-device active state. In most cases the effect on need for acquiring the mutex is non-existent as access to the driver's core data structure still needs to be serialised.
This still removes a lot of code as the code paths for active and try state are the same in many cases.
Signed-off-by Sakari Ailus <[email protected]>--- drivers/media/i2c/ccs/ccs-core.c | 278 ++++++++++++------------------- drivers/media/i2c/ccs/ccs.h | 4 +- 2 files changed, 103 insertions(+), 179 deletions(-)drivers/media/i2c/ccs/ccs-core.c +28
-64@@ -508,9 +508,8 @@ static void __ccs_update_exposure_limits(struct ccs_sensor *sensor)struct v4l2_ctrl *ctrl = sensor->exposure;int max; - max = sensor->pixel_array->crop[CCS_PA_PAD_SRC ].height - + sensor->vblank->val - -CCS_LIM (sensor,COARSE_INTEGRATION_TIME_MAX_MARGIN ); + max = sensor->pa_src.height + sensor->vblank->val - +CCS_LIM (sensor,COARSE_INTEGRATION_TIME_MAX_MARGIN );__v4l2_ctrl_modify_range (ctrl, ctrl->minimum, max, ctrl->step, max); }@@ -728,15 +727,12 @@ static int ccs_set_ctrl(struct v4l2_ctrl *ctrl)break ;case V4L2_CID_VBLANK : rval =ccs_write (sensor,FRAME_LENGTH_LINES , - sensor->pixel_array->crop[ -CCS_PA_PAD_SRC ].height - + ctrl->val); + sensor->pa_src.height + ctrl->val);break ;case V4L2_CID_HBLANK : rval =ccs_write (sensor,LINE_LENGTH_PCK , - sensor->pixel_array->crop[CCS_PA_PAD_SRC ].width - + ctrl->val); + sensor->pa_src.width + ctrl->val);break ;case V4L2_CID_TEST_PATTERN :@@ -1214,15 +1210,13 @@ static void ccs_update_blanking(struct ccs_sensor *sensor) min =max_t (int,CCS_LIM (sensor,MIN_FRAME_BLANKING_LINES ), - min_fll - sensor->pixel_array->crop[CCS_PA_PAD_SRC ].height); - max = max_fll - sensor->pixel_array->crop[CCS_PA_PAD_SRC ].height; + min_fll - sensor->pa_src.height); + max = max_fll - sensor->pa_src.height;__v4l2_ctrl_modify_range (vblank, min, max, vblank->step, min); - min =max_t (int, - min_llp - sensor->pixel_array->crop[CCS_PA_PAD_SRC ].width, - min_lbp); - max = max_llp - sensor->pixel_array->crop[CCS_PA_PAD_SRC ].width; + min =max_t (int, min_llp - sensor->pa_src.width, min_lbp); + max = max_llp - sensor->pa_src.width;__v4l2_ctrl_modify_range (hblank, min, max, hblank->step, min);@@ -1246,10 +1240,8 @@ static int ccs_pll_blanking_update(struct ccs_sensor *sensor)dev_dbg (&client->dev,"real timeperframe\t100/%d\n" , sensor->pll.pixel_rate_pixel_array / - ((sensor->pixel_array->crop[CCS_PA_PAD_SRC ].width - + sensor->hblank->val) * - (sensor->pixel_array->crop[CCS_PA_PAD_SRC ].height - + sensor->vblank->val) /100 )); + ((sensor->pa_src.width + sensor->hblank->val) * + (sensor->pa_src.height + sensor->vblank->val) /100 ));return 0 ; }@@ -1756,28 +1748,22 @@ static int ccs_start_streaming(struct ccs_sensor *sensor) goto out;/* Analog crop start coordinates */ - rval =ccs_write (sensor,X_ADDR_START , - sensor->pixel_array->crop[CCS_PA_PAD_SRC ].left); + rval =ccs_write (sensor,X_ADDR_START , sensor->pa_src.left);if (rval <0 ) goto out; - rval =ccs_write (sensor,Y_ADDR_START , - sensor->pixel_array->crop[CCS_PA_PAD_SRC ].top); + rval =ccs_write (sensor,Y_ADDR_START , sensor->pa_src.top);if (rval <0 ) goto out;/* Analog crop end coordinates */ - rval =ccs_write ( - sensor,X_ADDR_END , - sensor->pixel_array->crop[CCS_PA_PAD_SRC ].left - + sensor->pixel_array->crop[CCS_PA_PAD_SRC ].width -1 ); + rval =ccs_write (sensor,X_ADDR_END , + sensor->pa_src.left + sensor->pa_src.width -1 );if (rval <0 ) goto out; - rval =ccs_write ( - sensor,Y_ADDR_END , - sensor->pixel_array->crop[CCS_PA_PAD_SRC ].top - + sensor->pixel_array->crop[CCS_PA_PAD_SRC ].height -1 ); + rval =ccs_write (sensor,Y_ADDR_END , + sensor->pa_src.top + sensor->pa_src.height -1 );if (rval <0 ) goto out;@@ -1789,27 +1775,23 @@ static int ccs_start_streaming(struct ccs_sensor *sensor)/* Digital crop */ if (CCS_LIM (sensor,DIGITAL_CROP_CAPABILITY ) ==CCS_DIGITAL_CROP_CAPABILITY_INPUT_CROP ) { - rval =ccs_write ( - sensor,DIGITAL_CROP_X_OFFSET , - sensor->scaler->crop[CCS_PAD_SINK ].left); + rval =ccs_write (sensor,DIGITAL_CROP_X_OFFSET , + sensor->scaler_sink.left);if (rval <0 ) goto out; - rval =ccs_write ( - sensor,DIGITAL_CROP_Y_OFFSET , - sensor->scaler->crop[CCS_PAD_SINK ].top); + rval =ccs_write (sensor,DIGITAL_CROP_Y_OFFSET , + sensor->scaler_sink.top);if (rval <0 ) goto out; - rval =ccs_write ( - sensor,DIGITAL_CROP_IMAGE_WIDTH , - sensor->scaler->crop[CCS_PAD_SINK ].width); + rval =ccs_write (sensor,DIGITAL_CROP_IMAGE_WIDTH , + sensor->scaler_sink.width);if (rval <0 ) goto out; - rval =ccs_write ( - sensor,DIGITAL_CROP_IMAGE_HEIGHT , - sensor->scaler->crop[CCS_PAD_SINK ].height); + rval =ccs_write (sensor,DIGITAL_CROP_IMAGE_HEIGHT , + sensor->scaler_sink.height);if (rval <0 ) goto out; }@@ -1827,12 +1809,10 @@ static int ccs_start_streaming(struct ccs_sensor *sensor) }/* Output size from sensor */ - rval =ccs_write (sensor,X_OUTPUT_SIZE , - sensor->src->crop[CCS_PAD_SRC ].width); + rval =ccs_write (sensor,X_OUTPUT_SIZE , sensor->src_src.width);if (rval <0 ) goto out; - rval =ccs_write (sensor,Y_OUTPUT_SIZE , - sensor->src->crop[CCS_PAD_SRC ].height); + rval =ccs_write (sensor,Y_OUTPUT_SIZE , sensor->src_src.height);if (rval <0 ) goto out;@@ -2053,24 +2033,8 @@ static int __ccs_get_format(struct v4l2_subdev *subdev,struct v4l2_subdev_state *sd_state, struct v4l2_subdev_format *fmt) { - struct ccs_subdev *ssd = to_ccs_subdev(subdev); - -if (fmt->which ==V4L2_SUBDEV_FORMAT_TRY ) { - fmt->format = *v4l2_subdev_get_try_format (subdev, sd_state, - fmt->pad); - }else { -struct v4l2_rect *r; - -if (fmt->pad == ssd->source_pad) - r = &ssd->crop[ssd->source_pad]; -else - r = &ssd->sink_fmt; - - fmt->format.code =__ccs_get_mbus_code (subdev, fmt->pad); - fmt->format.width = r->width; - fmt->format.height = r->height; - fmt->format.field =V4L2_FIELD_NONE ; - } + fmt->format = *v4l2_subdev_get_pad_format(subdev, sd_state, fmt->pad); + fmt->format.code =__ccs_get_mbus_code (subdev, fmt->pad);Quoted 8 lines
drivers/media/i2c/ccs/ccs-core.c static int ccs_get_format(struct v4l2_subdev *subdev,
Quoted 3 lines
drivers/media/i2c/ccs/ccs-core.c +0
-0return 0 ; }@@ -2092,28 +2056,18 @@ static int ccs_get_format(struct v4l2_subdev *subdev,Please replace
ccs_get_format()withv4l2_subdev_get_fmt(). It's a drop-in replacement for the .get_fmt() operation, you can drop this function. The only remaining caller of__ccs_get_format()can then usev4l2_subdev_get_fmt()too.
Quoted 2 lines
That is my goal but the issue is that it (sligthly) changes UAPI behaviour. Currently the flipping controls also affect the try formats.
Let's fix it sooner than later, different behaviours for different sensors is very painful for userspace.
Quoted 384 lines
Quoted 302 lines
Quoted 302 lines
drivers/media/i2c/ccs/ccs-core.c +57
-100static void ccs_get_crop_compose (struct v4l2_subdev *subdev,struct v4l2_subdev_state *sd_state,struct v4l2_rect **crops, -struct v4l2_rect **comps,int which) +struct v4l2_rect **comps) {struct ccs_subdev *ssd =to_ccs_subdev (subdev);unsigned int i; -if (which ==V4L2_SUBDEV_FORMAT_ACTIVE ) { -if (crops) -for (i =0 ; i < subdev->entity.num_pads; i++) - crops[i] = &ssd->crop[i]; -if (comps) - *comps = &ssd->compose; - }else { -if (crops) { -for (i =0 ; i < subdev->entity.num_pads; i++) - crops[i] =v4l2_subdev_get_try_crop (subdev, - sd_state, - i); - } -if (comps) - *comps =v4l2_subdev_get_try_compose (subdev, sd_state, -CCS_PAD_SINK ); - } +if (crops) +for (i =0 ; i < subdev->entity.num_pads; i++) + crops[i] = +v4l2_subdev_get_pad_crop (subdev, sd_state, i); +if (comps) + *comps =v4l2_subdev_get_pad_compose (subdev, sd_state, + ssd->sink_pad); }/* Changes require propagation only on sink pad. */ @@ -2125,7 +2079,7 @@ static void ccs_propagate(struct v4l2_subdev *subdev,struct ccs_subdev *ssd =to_ccs_subdev (subdev);struct v4l2_rect *comp, *crops[CCS_PADS ]; -ccs_get_crop_compose (subdev, sd_state, crops, &comp, which); +ccs_get_crop_compose (subdev, sd_state, crops, &comp);switch (target) {case V4L2_SEL_TGT_CROP :@@ -2136,6 +2090,7 @@ static void ccs_propagate(struct v4l2_subdev *subdev, sensor->scale_m =CCS_LIM (sensor,SCALER_N_MIN ); sensor->scaling_mode =CCS_SCALING_MODE_NO_SCALING ; + sensor->scaler_sink = *comp; }else if (ssd == sensor->binner) { sensor->binning_horizontal =1 ; sensor->binning_vertical =1 ;@@ -2144,6 +2099,8 @@ static void ccs_propagate(struct v4l2_subdev *subdev, fallthrough;case V4L2_SEL_TGT_COMPOSE : *crops[CCS_PAD_SRC ] = *comp; +if (which ==V4L2_SUBDEV_FORMAT_ACTIVE && ssd == sensor->src) + sensor->src_src = *crops[CCS_PAD_SRC ];break ;default :WARN_ON_ONCE (1 );@@ -2252,14 +2209,12 @@ static int ccs_set_format(struct v4l2_subdev *subdev,CCS_LIM (sensor,MIN_Y_OUTPUT_SIZE ), CCS_LIM(sensor, MAX_Y_OUTPUT_SIZE)); -ccs_get_crop_compose (subdev, sd_state, crops,NULL , fmt->which); +ccs_get_crop_compose (subdev, sd_state, crops,NULL ); crops[ssd->sink_pad]->left =0 ; crops[ssd->sink_pad]->top =0 ; crops[ssd->sink_pad]->width = fmt->format.width; crops[ssd->sink_pad]->height = fmt->format.height; -if (fmt->which ==V4L2_SUBDEV_FORMAT_ACTIVE ) - ssd->sink_fmt = *crops[ssd->sink_pad];ccs_propagate (subdev, sd_state, fmt->which,V4L2_SEL_TGT_CROP );mutex_unlock (&sensor->mutex);@@ -2482,7 +2437,7 @@ static int ccs_set_compose(struct v4l2_subdev *subdev,struct ccs_subdev *ssd =to_ccs_subdev (subdev);struct v4l2_rect *comp, *crops[CCS_PADS ]; -ccs_get_crop_compose (subdev, sd_state, crops, &comp, sel->which); +ccs_get_crop_compose (subdev, sd_state, crops, &comp); sel->r.top =0 ; sel->r.left =0 ;@@ -2501,8 +2456,8 @@ static int ccs_set_compose(struct v4l2_subdev *subdev,return 0 ; } -static int __ccs_sel_supported (struct v4l2_subdev *subdev, -struct v4l2_subdev_selection *sel) +static int ccs_sel_supported (struct v4l2_subdev *subdev, +struct v4l2_subdev_selection *sel) {struct ccs_sensor *sensor =to_ccs_sensor (subdev);struct ccs_subdev *ssd =to_ccs_subdev (subdev);@@ -2545,33 +2500,18 @@ static int ccs_set_crop(struct v4l2_subdev *subdev, {struct ccs_sensor *sensor =to_ccs_sensor (subdev);struct ccs_subdev *ssd =to_ccs_subdev (subdev); -struct v4l2_rect *src_size, *crops[CCS_PADS ]; -struct v4l2_rect _r; +struct v4l2_rect src_size = {0 }, *crops[CCS_PADS ], *comp; -ccs_get_crop_compose (subdev, sd_state, crops,NULL , sel->which); +ccs_get_crop_compose (subdev, sd_state, crops, &comp); -if (sel->which ==V4L2_SUBDEV_FORMAT_ACTIVE ) { -if (sel->pad == ssd->sink_pad) - src_size = &ssd->sink_fmt; -else - src_size = &ssd->compose; +if (sel->pad == ssd->sink_pad) { +struct v4l2_mbus_framefmt *mfmt = +v4l2_subdev_get_pad_format (subdev, sd_state, sel->pad); + + src_size.width = mfmt->width; + src_size.height = mfmt->height; }else { -if (sel->pad == ssd->sink_pad) { - _r.left =0 ; - _r.top =0 ; - _r.width =v4l2_subdev_get_try_format (subdev, - sd_state, - sel->pad) - ->width; - _r.height =v4l2_subdev_get_try_format (subdev, - sd_state, - sel->pad) - ->height; - src_size = &_r; - }else { - src_size =v4l2_subdev_get_try_compose ( - subdev, sd_state, ssd->sink_pad); - } + src_size = *comp; }if (ssd == sensor->src && sel->pad ==CCS_PAD_SRC ) {@@ -2579,16 +2519,19 @@ static int ccs_set_crop(struct v4l2_subdev *subdev, sel->r.top =0 ; } - sel->r.width =min (sel->r.width, src_size->width); - sel->r.height =min (sel->r.height, src_size->height); + sel->r.width =min (sel->r.width, src_size.width); + sel->r.height =min (sel->r.height, src_size.height); - sel->r.left =min_t (int, sel->r.left, src_size->width - sel->r.width); - sel->r.top =min_t (int, sel->r.top, src_size->height - sel->r.height); + sel->r.left =min_t (int, sel->r.left, src_size.width - sel->r.width); + sel->r.top =min_t (int, sel->r.top, src_size.height - sel->r.height); *crops[sel->pad] = sel->r;if (ssd != sensor->pixel_array && sel->pad ==CCS_PAD_SINK )ccs_propagate (subdev, sd_state, sel->which,V4L2_SEL_TGT_CROP ); +else if (sel->which ==V4L2_SUBDEV_FORMAT_ACTIVE && + ssd == sensor->pixel_array) + sensor->pa_src = sel->r;return 0 ; }@@ -2601,44 +2544,36 @@ static void ccs_get_native_size(struct ccs_subdev *ssd, struct v4l2_rect *r) r->height =CCS_LIM (ssd->sensor,Y_ADDR_MAX ) +1 ; } -static int __ccs_get_selection (struct v4l2_subdev *subdev, -struct v4l2_subdev_state *sd_state, -struct v4l2_subdev_selection *sel) +static int ccs_get_selection (struct v4l2_subdev *subdev, +struct v4l2_subdev_state *sd_state, +struct v4l2_subdev_selection *sel) {struct ccs_sensor *sensor =to_ccs_sensor (subdev);struct ccs_subdev *ssd =to_ccs_subdev (subdev);struct v4l2_rect *comp, *crops[CCS_PADS ]; -struct v4l2_rect sink_fmt;int ret; - ret =__ccs_sel_supported (subdev, sel); + ret =ccs_sel_supported (subdev, sel);if (ret)return ret; -ccs_get_crop_compose (subdev, sd_state, crops, &comp, sel->which); - -if (sel->which ==V4L2_SUBDEV_FORMAT_ACTIVE ) { - sink_fmt = ssd->sink_fmt; - }else { -struct v4l2_mbus_framefmt *fmt = -v4l2_subdev_get_try_format (subdev, sd_state, - ssd->sink_pad); - - sink_fmt.left =0 ; - sink_fmt.top =0 ; - sink_fmt.width = fmt->width; - sink_fmt.height = fmt->height; - } +ccs_get_crop_compose (subdev, sd_state, crops, &comp);switch (sel->target) {case V4L2_SEL_TGT_CROP_BOUNDS :case V4L2_SEL_TGT_NATIVE_SIZE : -if (ssd == sensor->pixel_array) +if (ssd == sensor->pixel_array) {ccs_get_native_size (ssd, &sel->r); -else if (sel->pad == ssd->sink_pad) - sel->r = sink_fmt; -else + }else if (sel->pad == ssd->sink_pad) { +struct v4l2_mbus_framefmt *sink_fmt = +v4l2_subdev_get_pad_format (subdev, sd_state, + ssd->sink_pad); + sel->r.top = sel->r.left =0 ; + sel->r.width = sink_fmt->width; + sel->r.height = sink_fmt->height; + }else { sel->r = *comp; + }break ;case V4L2_SEL_TGT_CROP :case V4L2_SEL_TGT_COMPOSE_BOUNDS :@@ -2652,20 +2587,6 @@ static int __ccs_get_selection(struct v4l2_subdev *subdev,return 0 ; } -static int ccs_get_selection (struct v4l2_subdev *subdev, -struct v4l2_subdev_state *sd_state, -struct v4l2_subdev_selection *sel) -{ -struct ccs_sensor *sensor =to_ccs_sensor (subdev); -int rval; - -mutex_lock (&sensor->mutex); - rval =__ccs_get_selection (subdev, sd_state, sel); -mutex_unlock (&sensor->mutex); - -return rval; -} -static int ccs_set_selection (struct v4l2_subdev *subdev,struct v4l2_subdev_state *sd_state,struct v4l2_subdev_selection *sel)@@ -2673,7 +2594,7 @@ static int ccs_set_selection(struct v4l2_subdev *subdev,struct ccs_sensor *sensor =to_ccs_sensor (subdev);int ret; - ret =__ccs_sel_supported (subdev, sel); + ret =ccs_sel_supported (subdev, sel);if (ret)return ret;@@ -2964,10 +2885,14 @@ static int ccs_register_subdev(struct ccs_sensor *sensor,return rval; } + rval =v4l2_subdev_init_finalize (&ssd->sd); +if (rval) + goto out_media_entity_cleanup; + rval =v4l2_device_register_subdev (sensor->src->sd.v4l2_dev, &ssd->sd);if (rval) {dev_err (&client->dev,"v4l2_device_register_subdev failed\n" ); - goto out_media_entity_cleanup; + goto out_v4l2_subdev_cleanup; } rval = media_create_pad_link(&ssd->sd.entity, source_pad,@@ -2983,6 +2908,9 @@ static int ccs_register_subdev(struct ccs_sensor *sensor, out_v4l2_device_unregister_subdev:v4l2_device_unregister_subdev (&ssd->sd); +out_v4l2_subdev_cleanup: +v4l2_subdev_cleanup (&ssd->sd); + out_media_entity_cleanup:media_entity_cleanup (&ssd->sd.entity);@@ -3059,16 +2987,9 @@ static void ccs_create_subdev(struct ccs_sensor *sensor,v4l2_i2c_subdev_set_name (&ssd->sd, client, sensor->minfo.name, name); -ccs_get_native_size (ssd, &ssd->sink_fmt); - - ssd->compose.width = ssd->sink_fmt.width; - ssd->compose.height = ssd->sink_fmt.height; - ssd->crop[ssd->source_pad] = ssd->compose; ssd->pads[ssd->source_pad].flags =MEDIA_PAD_FL_SOURCE ; -if (ssd != sensor->pixel_array) { - ssd->crop[ssd->sink_pad] = ssd->compose; +if (ssd != sensor->pixel_array) ssd->pads[ssd->sink_pad].flags =MEDIA_PAD_FL_SINK ; - } ssd->sd.entity.ops = &ccs_entity_ops;@@ -3089,24 +3010,24 @@ static int ccs_init_cfg(struct v4l2_subdev *sd, struct v4l2_subdev_state *sd_stamutex_lock (&sensor->mutex);Quoted 13 lines
drivers/media/i2c/ccs/ccs-core.c static int ccs_init_cfg(struct v4l2_subdev *sd, struct v4l2_subdev_state *sd_sta · line 3017
Quoted 11 lines
drivers/media/i2c/ccs/ccs-core.c +5
-5for (i =0 ; i < ssd->npads; i++) { -struct v4l2_mbus_framefmt *try_fmt = -v4l2_subdev_get_try_format (sd, sd_state, i); -struct v4l2_rect *try_crop = -v4l2_subdev_get_try_crop (sd, sd_state, i); -struct v4l2_rect *try_comp; +struct v4l2_mbus_framefmt *pad_fmt = +v4l2_subdev_get_pad_format (sd, sd_state, i); +struct v4l2_rect *pad_crop = +v4l2_subdev_get_pad_crop (sd, sd_state, i); +struct v4l2_rect *pad_comp;These can simply be called fmt, crop and comp.
Yes.
Quoted 57 lines
Quoted 57 lines
drivers/media/i2c/ccs/ccs-core.c +12
-7-ccs_get_native_size (ssd, try_crop); +ccs_get_native_size (ssd, pad_crop); - try_fmt->width = try_crop->width; - try_fmt->height = try_crop->height; - try_fmt->code = sensor->internal_csi_format->code; - try_fmt->field =V4L2_FIELD_NONE ; + pad_fmt->width = pad_crop->width; + pad_fmt->height = pad_crop->height; + pad_fmt->code = sensor->internal_csi_format->code; + pad_fmt->field =V4L2_FIELD_NONE ;if (ssd == sensor->pixel_array)continue ; - try_comp =v4l2_subdev_get_try_compose (sd, sd_state, i); - *try_comp = *try_crop; + pad_comp =v4l2_subdev_get_pad_compose (sd, sd_state, i); + *pad_comp = *pad_crop; }mutex_unlock (&sensor->mutex);@@ -3631,6 +3552,10 @@ static int ccs_probe(struct i2c_client *client)if (rval <0 ) goto out_media_entity_cleanup; + rval =v4l2_subdev_init_finalize (&sensor->src->sd); +if (rval) + goto out_media_entity_cleanup; + rval =ccs_write_msr_regs (sensor);if (rval) goto out_media_entity_cleanup;@@ -3690,6 +3615,7 @@ static void ccs_remove(struct i2c_client *client)for (i =0 ; i < sensor->ssds_used; i++) {v4l2_device_unregister_subdev (&sensor->ssds[i].sd); +v4l2_subdev_cleanup (subdev);media_entity_cleanup (&sensor->ssds[i].sd.entity); }ccs_cleanup (sensor);drivers/media/i2c/ccs/ccs.h +0
-3@@ -182,9 +182,6 @@ struct ccs_binning_subtype {struct ccs_subdev {struct v4l2_subdev sd;struct media_pad pads[CCS_PADS ]; -struct v4l2_rect sink_fmt; -struct v4l2_rect crop[CCS_PADS ]; -struct v4l2_rect compose;/* compose on sink */ unsigned short sink_pad;unsigned short source_pad;int npads;@@ -220,6 +217,7 @@ struct ccs_sensor {Quoted 8 lines
drivers/media/i2c/ccs/ccs.h struct ccs_sensor { · line 220
Quoted 4 lines
drivers/media/i2c/ccs/ccs.h +1
-0u32 mbus_frame_fmts;const struct ccs_csi_data_format *csi_format;const struct ccs_csi_data_format *internal_csi_format; +struct v4l2_rect pa_src, scaler_sink, src_src;The idea of the active state API is to remove all active state from the driver private structure. Why do you need these, can't you get them from the active state where appropriate ?
Quoted 5 lines
The issue is the dependency to controls that can't be accessed with the state lock (only) held.
If we can remove that dependency, with a slight change to UAPI, then this can be done.
Eagerly waiting for patches :-)
Quoted 3 lines
Quoted 3 lines
Quoted 3 lines
drivers/media/i2c/ccs/ccs.h +0
-0u32 default_mbus_frame_fmts;int default_pixel_order;struct ccs_data_container sdata, mdata;
Signature · 3 lines
Regards, Laurent Pinchart
Sakari Ailus
maintainerPATCH v2 7/12 media: ov2740: Enable runtime PM before registering the async subdev
In reply to Sakari AilusEnable runtime PM before registering the async subdev as the driver UAPI may become accessible immediately after the registration. Runtime PM needs to be enabled by that time.
--- drivers/media/i2c/ov2740.c | 14 ++++++++------ 1 file changed, 8 insertions(+), 6 deletions(-)
drivers/media/i2c/ov2740.c +8 -6
@@ -1172,6 +1172,12 @@ static int ov2740_probe(struct i2c_client *client) goto probe_error_v4l2_ctrl_handler_free; } +/* Set the device's state to active if it's in D0 state. */ +if (full_power) +pm_runtime_set_active (&client->dev); +pm_runtime_enable (&client->dev); +pm_runtime_idle (&client->dev); + ret =v4l2_async_register_subdev_sensor (&ov2740->sd);if (ret <0 ) {dev_err_probe (dev, ret,"failed to register V4L2 subdev\n" );
@@ -1182,16 +1188,12 @@ static int ov2740_probe(struct i2c_client *client)if (ret)dev_warn (&client->dev,"register nvmem failed, ret %d\n" , ret); -/* Set the device's state to active if it's in D0 state. */ -if (full_power) -pm_runtime_set_active (&client->dev); -pm_runtime_enable (&client->dev); -pm_runtime_idle (&client->dev); -return 0 ; probe_error_media_entity_cleanup:media_entity_cleanup (&ov2740->sd.entity); +pm_runtime_disable (&client->dev); +pm_runtime_set_suspended (&client->dev); probe_error_v4l2_ctrl_handler_free:v4l2_ctrl_handler_free (ov2740->sd.ctrl_handler);
Signature · 1 line
2.39.2
Re: [PATCH v2 07/12] media: ov2740: Enable runtime PM before registering the async subdev
Hi Sakari,
Thank you for the patch.
Quoted 5 lines · Sakari Ailus
Enable runtime PM before registering the async subdev as the driver UAPI may become accessible immediately after the registration. Runtime PM needs to be enabled by that time.
Signed-off-by Sakari Ailus <[email protected]>
Quoted 40 lines
--- drivers/media/i2c/ov2740.c | 14 ++++++++------ 1 file changed, 8 insertions(+), 6 deletions(-)drivers/media/i2c/ov2740.c +8
-6@@ -1172,6 +1172,12 @@ static int ov2740_probe(struct i2c_client *client) goto probe_error_v4l2_ctrl_handler_free; } +/* Set the device's state to active if it's in D0 state. */ +if (full_power) +pm_runtime_set_active (&client->dev); +pm_runtime_enable (&client->dev); +pm_runtime_idle (&client->dev); + ret =v4l2_async_register_subdev_sensor (&ov2740->sd);if (ret <0 ) {dev_err_probe (dev, ret,"failed to register V4L2 subdev\n" );@@ -1182,16 +1188,12 @@ static int ov2740_probe(struct i2c_client *client)if (ret)dev_warn (&client->dev,"register nvmem failed, ret %d\n" , ret); -/* Set the device's state to active if it's in D0 state. */ -if (full_power) -pm_runtime_set_active (&client->dev); -pm_runtime_enable (&client->dev); -pm_runtime_idle (&client->dev); -return 0 ; probe_error_media_entity_cleanup:media_entity_cleanup (&ov2740->sd.entity); +pm_runtime_disable (&client->dev); +pm_runtime_set_suspended (&client->dev); probe_error_v4l2_ctrl_handler_free:v4l2_ctrl_handler_free (ov2740->sd.ctrl_handler);
Signature · 3 lines
Regards, Laurent Pinchart
Sakari Ailus
maintainerPATCH v2 8/12 media: ov2740: Use sub-device active state
In reply to Sakari AilusUse sub-device active state. Rely on control handler lock to serialise access to the active state. Also clean up locking on s_stream handler.
--- drivers/media/i2c/ov2740.c | 122 +++++++++++++++---------------------- 1 file changed, 50 insertions(+), 72 deletions(-)
drivers/media/i2c/ov2740.c +50 -72
@@ -336,9 +336,6 @@ struct ov2740 {/* Current mode */ const struct ov2740_mode *cur_mode; -/* To serialize asynchronus callbacks */ -struct mutex mutex; -/* Streaming on/off */ bool streaming;
@@ -582,7 +579,6 @@ static int ov2740_init_controls(struct ov2740 *ov2740)if (ret)return ret; - ctrl_hdlr->lock = &ov2740->mutex; cur_mode = ov2740->cur_mode; size =ARRAY_SIZE (link_freq_menu_items);
@@ -792,18 +788,18 @@ static int ov2740_set_stream(struct v4l2_subdev *sd, int enable) {struct ov2740 *ov2740 =to_ov2740 (sd);struct i2c_client *client =v4l2_get_subdevdata (sd); +struct v4l2_subdev_state *sd_state;int ret =0 ; + sd_state =v4l2_subdev_lock_and_get_active_state (&ov2740->sd); +if (ov2740->streaming == enable) -return 0 ; + goto out_unlock; -mutex_lock (&ov2740->mutex);if (enable) { ret =pm_runtime_resume_and_get (&client->dev); -if (ret <0 ) { -mutex_unlock (&ov2740->mutex); -return ret; - } +if (ret <0 ) + goto out_unlock; ret =ov2740_start_streaming (ov2740);if (ret) {
@@ -817,7 +813,9 @@ static int ov2740_set_stream(struct v4l2_subdev *sd, int enable) } ov2740->streaming = enable; -mutex_unlock (&ov2740->mutex); + +out_unlock: +v4l2_subdev_unlock_state (sd_state);return ret; }
@@ -826,12 +824,13 @@ static int ov2740_suspend(struct device *dev) {struct v4l2_subdev *sd =dev_get_drvdata (dev);struct ov2740 *ov2740 =to_ov2740 (sd); +struct v4l2_subdev_state *sd_state; -mutex_lock (&ov2740->mutex); + sd_state =v4l2_subdev_lock_and_get_active_state (&ov2740->sd);if (ov2740->streaming)ov2740_stop_streaming (ov2740); -mutex_unlock (&ov2740->mutex); +v4l2_subdev_unlock_state (sd_state);return 0 ; }
@@ -840,9 +839,10 @@ static int ov2740_resume(struct device *dev) {struct v4l2_subdev *sd =dev_get_drvdata (dev);struct ov2740 *ov2740 =to_ov2740 (sd); +struct v4l2_subdev_state *sd_state;int ret =0 ; -mutex_lock (&ov2740->mutex); + sd_state =v4l2_subdev_lock_and_get_active_state (&ov2740->sd);if (!ov2740->streaming) goto exit;
@@ -853,7 +853,7 @@ static int ov2740_resume(struct device *dev) } exit: -mutex_unlock (&ov2740->mutex); +v4l2_subdev_unlock_state (sd_state);return ret; }
@@ -870,48 +870,26 @@ static int ov2740_set_format(struct v4l2_subdev *sd, height, fmt->format.width, fmt->format.height); -mutex_lock (&ov2740->mutex);ov2740_update_pad_format (mode, &fmt->format); -if (fmt->which ==V4L2_SUBDEV_FORMAT_TRY ) { - *v4l2_subdev_get_try_format (sd, sd_state, fmt->pad) = fmt->format; - }else { - ov2740->cur_mode = mode; -__v4l2_ctrl_s_ctrl (ov2740->link_freq, mode->link_freq_index); -__v4l2_ctrl_s_ctrl_int64 (ov2740->pixel_rate, -to_pixel_rate (mode->link_freq_index)); - -/* Update limits and set FPS to default */ - vblank_def = mode->vts_def - mode->height; -__v4l2_ctrl_modify_range (ov2740->vblank, - mode->vts_min - mode->height, -OV2740_VTS_MAX - mode->height,1 , - vblank_def); -__v4l2_ctrl_s_ctrl (ov2740->vblank, vblank_def); - h_blank =to_pixels_per_line (mode->hts, mode->link_freq_index) - - mode->width; -__v4l2_ctrl_modify_range (ov2740->hblank, h_blank, h_blank,1 , - h_blank); - } -mutex_unlock (&ov2740->mutex); - -return 0 ; -} + *v4l2_subdev_get_pad_format (sd, sd_state, fmt->pad) = fmt->format; -static int ov2740_get_format (struct v4l2_subdev *sd, -struct v4l2_subdev_state *sd_state, -struct v4l2_subdev_format *fmt) -{ -struct ov2740 *ov2740 =to_ov2740 (sd); - -mutex_lock (&ov2740->mutex);if (fmt->which ==V4L2_SUBDEV_FORMAT_TRY ) - fmt->format = *v4l2_subdev_get_try_format (&ov2740->sd, - sd_state, - fmt->pad); -else -ov2740_update_pad_format (ov2740->cur_mode, &fmt->format); +return 0 ; -mutex_unlock (&ov2740->mutex); + ov2740->cur_mode = mode; +__v4l2_ctrl_s_ctrl (ov2740->link_freq, mode->link_freq_index); +__v4l2_ctrl_s_ctrl_int64 (ov2740->pixel_rate, +to_pixel_rate (mode->link_freq_index)); + +/* Update limits and set FPS to default */ + vblank_def = mode->vts_def - mode->height; +__v4l2_ctrl_modify_range (ov2740->vblank, + mode->vts_min - mode->height, +OV2740_VTS_MAX - mode->height,1 , vblank_def); +__v4l2_ctrl_s_ctrl (ov2740->vblank, vblank_def); + h_blank =to_pixels_per_line (mode->hts, mode->link_freq_index) - + mode->width; +__v4l2_ctrl_modify_range (ov2740->hblank, h_blank, h_blank,1 , h_blank);return 0 ; }
@@ -946,14 +924,11 @@ static int ov2740_enum_frame_size(struct v4l2_subdev *sd,return 0 ; } -static int ov2740_open (struct v4l2_subdev *sd,struct v4l2_subdev_fh *fh) +static int ov2740_init_cfg (struct v4l2_subdev *sd, +struct v4l2_subdev_state *sd_state) { -struct ov2740 *ov2740 =to_ov2740 (sd); - -mutex_lock (&ov2740->mutex);ov2740_update_pad_format (&supported_modes[0 ], -v4l2_subdev_get_try_format (sd, fh->state,0 )); -mutex_unlock (&ov2740->mutex); +v4l2_subdev_get_pad_format (sd, sd_state,0 ));return 0 ; }
@@ -963,10 +938,11 @@ static const struct v4l2_subdev_video_ops ov2740_video_ops = { };static const struct v4l2_subdev_pad_ops ov2740_pad_ops = { + .get_fmt = v4l2_subdev_get_fmt, .set_fmt = ov2740_set_format, - .get_fmt = ov2740_get_format, .enum_mbus_code = ov2740_enum_mbus_code, .enum_frame_size = ov2740_enum_frame_size, + .init_cfg = ov2740_init_cfg, };static const struct v4l2_subdev_ops ov2740_subdev_ops = {
@@ -978,10 +954,6 @@ static const struct media_entity_operations ov2740_subdev_entity_ops = { .link_validate = v4l2_subdev_link_validate, }; -static const struct v4l2_subdev_internal_ops ov2740_internal_ops = { - .open = ov2740_open, -}; -static int ov2740_check_hwcfg (struct device *dev) {struct fwnode_handle *ep;
@@ -1047,13 +1019,12 @@ static int ov2740_check_hwcfg(struct device *dev)static void ov2740_remove (struct i2c_client *client) {struct v4l2_subdev *sd =i2c_get_clientdata (client); -struct ov2740 *ov2740 =to_ov2740 (sd);v4l2_async_unregister_subdev (sd);media_entity_cleanup (&sd->entity); +v4l2_subdev_cleanup (sd);v4l2_ctrl_handler_free (sd->ctrl_handler);pm_runtime_disable (&client->dev); -mutex_destroy (&ov2740->mutex); } static int ov2740_nvmem_read(void *priv, unsigned int off, void *val,
@@ -1062,9 +1033,11 @@ static int ov2740_nvmem_read(void *priv, unsigned int off, void *val,struct nvm_data *nvm = priv;struct device *dev =regmap_get_device (nvm->regmap);struct ov2740 *ov2740 =to_ov2740 (dev_get_drvdata (dev)); +struct v4l2_subdev_state *sd_state;int ret =0 ; -mutex_lock (&ov2740->mutex); +/* Serialise sensor access */ + sd_state =v4l2_subdev_lock_and_get_active_state (&ov2740->sd);if (nvm->nvm_buffer) {memcpy (val, nvm->nvm_buffer + off, count);
@@ -1082,7 +1055,7 @@ static int ov2740_nvmem_read(void *priv, unsigned int off, void *val,pm_runtime_put (dev); exit: -mutex_unlock (&ov2740->mutex); +v4l2_subdev_unlock_state (sd_state);return ret; }
@@ -1153,7 +1126,6 @@ static int ov2740_probe(struct i2c_client *client)return dev_err_probe (dev, ret,"failed to find sensor\n" ); } -mutex_init (&ov2740->mutex); ov2740->cur_mode = &supported_modes[0 ]; ret =ov2740_init_controls (ov2740);if (ret) {
@@ -1161,7 +1133,7 @@ static int ov2740_probe(struct i2c_client *client) goto probe_error_v4l2_ctrl_handler_free; } - ov2740->sd.internal_ops = &ov2740_internal_ops; + ov2740->sd.state_lock = ov2740->ctrl_handler.lock; ov2740->sd.flags |=V4L2_SUBDEV_FL_HAS_DEVNODE ; ov2740->sd.entity.ops = &ov2740_subdev_entity_ops; ov2740->sd.entity.function =MEDIA_ENT_F_CAM_SENSOR ;
@@ -1172,6 +1144,10 @@ static int ov2740_probe(struct i2c_client *client) goto probe_error_v4l2_ctrl_handler_free; } + ret =v4l2_subdev_init_finalize (&ov2740->sd); +if (ret) + goto probe_error_media_entity_cleanup; +/* Set the device's state to active if it's in D0 state. */ if (full_power)pm_runtime_set_active (&client->dev);
@@ -1181,7 +1157,7 @@ static int ov2740_probe(struct i2c_client *client) ret =v4l2_async_register_subdev_sensor (&ov2740->sd);if (ret <0 ) {dev_err_probe (dev, ret,"failed to register V4L2 subdev\n" ); - goto probe_error_media_entity_cleanup; + goto probe_error_v4l2_subdev_cleanup; } ret =ov2740_register_nvmem (client, ov2740);
@@ -1190,6 +1166,9 @@ static int ov2740_probe(struct i2c_client *client)return 0 ; +probe_error_v4l2_subdev_cleanup: +v4l2_subdev_cleanup (&ov2740->sd); + probe_error_media_entity_cleanup:media_entity_cleanup (&ov2740->sd.entity);pm_runtime_disable (&client->dev);
@@ -1197,7 +1176,6 @@ static int ov2740_probe(struct i2c_client *client) probe_error_v4l2_ctrl_handler_free:v4l2_ctrl_handler_free (ov2740->sd.ctrl_handler); -mutex_destroy (&ov2740->mutex);return ret; }
Signature · 1 line
2.39.2
Sakari Ailus
maintainerPATCH v2 9/12 media: ov2740: Return -EPROBE_DEFER if no endpoint is found
In reply to Sakari AilusWith ipu bridge, endpoints may only be created when ipu bridge has initialised. This may happen after the sensor driver has first probed.
--- drivers/media/i2c/ov2740.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/media/i2c/ov2740.c +1 -1
@@ -976,7 +976,7 @@ static int ov2740_check_hwcfg(struct device *dev) ep =fwnode_graph_get_next_endpoint (fwnode,NULL );if (!ep) -return -ENXIO ; +return -EPROBE_DEFER ; ret =v4l2_fwnode_endpoint_alloc_parse (ep, &bus_cfg);fwnode_handle_put (ep);
Signature · 1 line
2.39.2
Re: [PATCH v2 09/12] media: ov2740: Return -EPROBE_DEFER if no endpoint is found
Hi Sakari,
Thank you for the patch.
Quoted 13 lines · Sakari Ailus
With ipu bridge, endpoints may only be created when ipu bridge has initialised. This may happen after the sensor driver has first probed.
Signed-off-by Sakari Ailus <[email protected]>--- drivers/media/i2c/ov2740.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)drivers/media/i2c/ov2740.c +0
-0
drivers/media/i2c/ov2740.c static int ov2740_check_hwcfg(struct device *dev) · line 979
Quoted 5 lines
drivers/media/i2c/ov2740.c +1
-1@@ -976,7 +976,7 @@ static int ov2740_check_hwcfg(struct device *dev) ep =fwnode_graph_get_next_endpoint (fwnode,NULL );if (!ep) -return -ENXIO ; +return -EPROBE_DEFER ;
This is fine as a quick fix, so
but I'm thinking that we need better in the long run, for multiple reasons:
- All sensor drivers that support ACPI should do the same, as they shouldn't be aware of platform-specific integration details. This could be done by mass-patching them, with a documentation update to clearly indicate what error code is appropriate. Another option could be to return an error pointer from fwnode_graph_get_next_endpoint(), with the appropriate error being set depending on the platform. Other solutions may be possible too.
- On OF systems, a DT error will result in probe deferral, which is harder to debug than probe failures. It would be nice to avoid that.
Quoted 3 lines
drivers/media/i2c/ov2740.c +0
-0ret =v4l2_fwnode_endpoint_alloc_parse (ep, &bus_cfg);fwnode_handle_put (ep);
Signature · 3 lines
Regards, Laurent Pinchart
Sakari Ailus
maintainerRe: [PATCH v2 09/12] media: ov2740: Return -EPROBE_DEFER if no endpoint is found
Hi Laurent,
Quoted 19 lines · Laurent Pinchart
Hi Sakari,
Thank you for the patch.
Quoted 14 lines · Sakari Ailus
With ipu bridge, endpoints may only be created when ipu bridge has initialised. This may happen after the sensor driver has first probed.
Signed-off-by Sakari Ailus <[email protected]>--- drivers/media/i2c/ov2740.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)drivers/media/i2c/ov2740.c +0
-0@@ -976,7 +976,7 @@ static int ov2740_check_hwcfg(struct device *dev)
Quoted 8 lines
drivers/media/i2c/ov2740.c static int ov2740_check_hwcfg(struct device *dev) · line 979
Quoted 4 lines
drivers/media/i2c/ov2740.c +1
-1ep =fwnode_graph_get_next_endpoint (fwnode,NULL );if (!ep) -return -ENXIO ; +return -EPROBE_DEFER ;This is fine as a quick fix, so
Reviewed-by Laurent Pinchart <[email protected]>
Thank you.
Quoted 11 lines
but I'm thinking that we need better in the long run, for multiple reasons:
- All sensor drivers that support ACPI should do the same, as they shouldn't be aware of platform-specific integration details. This could be done by mass-patching them, with a documentation update to clearly indicate what error code is appropriate. Another option could be to return an error pointer from
fwnode_graph_get_next_endpoint(), with the appropriate error being set depending on the platform. Other solutions may be possible too.
I'd like to see IPU bridge in the ACPI framework but that won't happen overnight. Then this issue would disappear. The problem with the error is that callers don't expect it and how do you tell if you're expecting something you don't know about to appear.
Quoted 3 lines
- On OF systems, a DT error will result in probe deferral, which is harder to debug than probe failures. It would be nice to avoid that.
Yes.
I change it for this sensor only as I was otherwise working on it.
Signature · 3 lines
Regards, Sakari Ailus
Sakari Ailus
maintainerPATCH v2 10/12 media: v4l: subdev: Clear frame descriptor before get_frame_desc
In reply to Sakari AilusClear frame descriptor before calling transmitter's get_frame_desc() op. Also remove the corresponding memset() calls from drivers.
--- drivers/media/i2c/ds90ub913.c | 2 -- drivers/media/i2c/ds90ub953.c | 2 -- drivers/media/i2c/ds90ub960.c | 2 -- drivers/media/platform/nxp/imx-mipi-csis.c | 2 -- drivers/media/v4l2-core/v4l2-subdev.c | 9 +++++++++ 5 files changed, 9 insertions(+), 8 deletions(-)
drivers/media/i2c/ds90ub913.c +0 -2
@@ -362,8 +362,6 @@ static int ub913_get_frame_desc(struct v4l2_subdev *sd, unsigned int pad,if (ret)return ret; -memset (fd,0 ,sizeof (*fd)); - fd->type =V4L2_MBUS_FRAME_DESC_TYPE_PARALLEL ; state =v4l2_subdev_lock_and_get_active_state (sd);
drivers/media/i2c/ds90ub953.c +0 -2
@@ -499,8 +499,6 @@ static int ub953_get_frame_desc(struct v4l2_subdev *sd, unsigned int pad,if (ret)return ret; -memset (fd,0 ,sizeof (*fd)); - fd->type =V4L2_MBUS_FRAME_DESC_TYPE_CSI2 ; state =v4l2_subdev_lock_and_get_active_state (sd);
drivers/media/i2c/ds90ub960.c +0 -2
@@ -2786,8 +2786,6 @@ static int ub960_get_frame_desc(struct v4l2_subdev *sd, unsigned int pad,if (!ub960_pad_is_source (priv, pad))return -EINVAL ; -memset (fd,0 ,sizeof (*fd)); - fd->type =V4L2_MBUS_FRAME_DESC_TYPE_CSI2 ; state =v4l2_subdev_lock_and_get_active_state (&priv->sd);
drivers/media/platform/nxp/imx-mipi-csis.c +0 -2
@@ -1114,8 +1114,6 @@ static int mipi_csis_get_frame_desc(struct v4l2_subdev *sd, unsigned int pad, fd->type =V4L2_MBUS_FRAME_DESC_TYPE_PARALLEL ; fd->num_entries =1 ; -memset (entry,0 ,sizeof (*entry)); - entry->flags =0 ; entry->pixelcode = csis_fmt->code; entry->bus.csi2.vc =0 ;
drivers/media/v4l2-core/v4l2-subdev.c +9 -0
@@ -306,6 +306,14 @@ static int call_set_selection(struct v4l2_subdev *sd, sd->ops->pad->set_selection (sd, state, sel); } +static int call_get_frame_desc (struct v4l2_subdev *sd,unsigned int pad, +struct v4l2_mbus_frame_desc *fd) +{ +memset (fd,0 ,sizeof (*fd)); + +return sd->ops->pad->get_frame_desc (sd, pad, fd); +} +static inline int check_edid (struct v4l2_subdev *sd,struct v4l2_subdev_edid *edid) {
@@ -431,6 +439,7 @@ static const struct v4l2_subdev_pad_ops v4l2_subdev_call_pad_wrappers = { .set_edid = call_set_edid, .dv_timings_cap = call_dv_timings_cap, .enum_dv_timings = call_enum_dv_timings, + .get_frame_desc = call_get_frame_desc, .get_mbus_config = call_get_mbus_config, };
Signature · 1 line
2.39.2
Re: [PATCH v2 10/12] media: v4l: subdev: Clear frame descriptor before get_frame_desc
Hi Sakari,
Thank you for the patch.
Quoted 69 lines · Sakari Ailus
Clear frame descriptor before calling transmitter's
get_frame_desc()op. Also remove the correspondingmemset()calls from drivers.Signed-off-by Sakari Ailus <[email protected]>--- drivers/media/i2c/ds90ub913.c | 2 -- drivers/media/i2c/ds90ub953.c | 2 -- drivers/media/i2c/ds90ub960.c | 2 -- drivers/media/platform/nxp/imx-mipi-csis.c | 2 -- drivers/media/v4l2-core/v4l2-subdev.c | 9 +++++++++ 5 files changed, 9 insertions(+), 8 deletions(-)drivers/media/i2c/ds90ub913.c +0
-2@@ -362,8 +362,6 @@ static int ub913_get_frame_desc(struct v4l2_subdev *sd, unsigned int pad,if (ret)return ret; -memset (fd,0 ,sizeof (*fd)); - fd->type =V4L2_MBUS_FRAME_DESC_TYPE_PARALLEL ; state =v4l2_subdev_lock_and_get_active_state (sd);drivers/media/i2c/ds90ub953.c +0
-2@@ -499,8 +499,6 @@ static int ub953_get_frame_desc(struct v4l2_subdev *sd, unsigned int pad,if (ret)return ret; -memset (fd,0 ,sizeof (*fd)); - fd->type =V4L2_MBUS_FRAME_DESC_TYPE_CSI2 ; state =v4l2_subdev_lock_and_get_active_state (sd);drivers/media/i2c/ds90ub960.c +0
-2@@ -2786,8 +2786,6 @@ static int ub960_get_frame_desc(struct v4l2_subdev *sd, unsigned int pad,if (!ub960_pad_is_source (priv, pad))return -EINVAL ; -memset (fd,0 ,sizeof (*fd)); - fd->type =V4L2_MBUS_FRAME_DESC_TYPE_CSI2 ; state =v4l2_subdev_lock_and_get_active_state (&priv->sd);drivers/media/platform/nxp/imx-mipi-csis.c +0
-2@@ -1114,8 +1114,6 @@ static int mipi_csis_get_frame_desc(struct v4l2_subdev *sd, unsigned int pad, fd->type =V4L2_MBUS_FRAME_DESC_TYPE_PARALLEL ; fd->num_entries =1 ; -memset (entry,0 ,sizeof (*entry)); - entry->flags =0 ; entry->pixelcode = csis_fmt->code; entry->bus.csi2.vc =0 ;drivers/media/v4l2-core/v4l2-subdev.c +0
-0
drivers/media/v4l2-core/v4l2-subdev.c static int call_set_selection(struct v4l2_subdev *sd, · line 315
Quoted 10 lines
drivers/media/v4l2-core/v4l2-subdev.c +7
-0@@ -306,6 +306,14 @@ static int call_set_selection(struct v4l2_subdev *sd, sd->ops->pad->set_selection (sd, state, sel); } +static int call_get_frame_desc (struct v4l2_subdev *sd,unsigned int pad, +struct v4l2_mbus_frame_desc *fd) +{ +memset (fd,0 ,sizeof (*fd)); + +return sd->ops->pad->get_frame_desc (sd, pad, fd); +}
I like the operation wrappers.
Quoted 12 lines
drivers/media/v4l2-core/v4l2-subdev.c +2
-0+static inline int check_edid (struct v4l2_subdev *sd,struct v4l2_subdev_edid *edid) {@@ -431,6 +439,7 @@ static const struct v4l2_subdev_pad_ops v4l2_subdev_call_pad_wrappers = { .set_edid = call_set_edid, .dv_timings_cap = call_dv_timings_cap, .enum_dv_timings = call_enum_dv_timings, + .get_frame_desc = call_get_frame_desc, .get_mbus_config = call_get_mbus_config, };
Signature · 3 lines
Regards, Laurent Pinchart
Re: [PATCH v2 10/12] media: v4l: subdev: Clear frame descriptor before get_frame_desc
In reply to Sakari AilusQuoted 11 lines · Sakari Ailus
Clear frame descriptor before calling transmitter's
get_frame_desc()op. Also remove the correspondingmemset()calls from drivers.Signed-off-by Sakari Ailus <[email protected]>--- drivers/media/i2c/ds90ub913.c | 2 -- drivers/media/i2c/ds90ub953.c | 2 -- drivers/media/i2c/ds90ub960.c | 2 -- drivers/media/platform/nxp/imx-mipi-csis.c | 2 -- drivers/media/v4l2-core/v4l2-subdev.c | 9 +++++++++ 5 files changed, 9 insertions(+), 8 deletions(-)
Tomi
Quoted 79 lines
drivers/media/i2c/ds90ub913.c +0
-2@@ -362,8 +362,6 @@ static int ub913_get_frame_desc(struct v4l2_subdev *sd, unsigned int pad,if (ret)return ret; -memset (fd,0 ,sizeof (*fd)); - fd->type =V4L2_MBUS_FRAME_DESC_TYPE_PARALLEL ; state =v4l2_subdev_lock_and_get_active_state (sd);drivers/media/i2c/ds90ub953.c +0
-2@@ -499,8 +499,6 @@ static int ub953_get_frame_desc(struct v4l2_subdev *sd, unsigned int pad,if (ret)return ret; -memset (fd,0 ,sizeof (*fd)); - fd->type =V4L2_MBUS_FRAME_DESC_TYPE_CSI2 ; state =v4l2_subdev_lock_and_get_active_state (sd);drivers/media/i2c/ds90ub960.c +0
-2@@ -2786,8 +2786,6 @@ static int ub960_get_frame_desc(struct v4l2_subdev *sd, unsigned int pad,if (!ub960_pad_is_source (priv, pad))return -EINVAL ; -memset (fd,0 ,sizeof (*fd)); - fd->type =V4L2_MBUS_FRAME_DESC_TYPE_CSI2 ; state =v4l2_subdev_lock_and_get_active_state (&priv->sd);drivers/media/platform/nxp/imx-mipi-csis.c +0
-2@@ -1114,8 +1114,6 @@ static int mipi_csis_get_frame_desc(struct v4l2_subdev *sd, unsigned int pad, fd->type =V4L2_MBUS_FRAME_DESC_TYPE_PARALLEL ; fd->num_entries =1 ; -memset (entry,0 ,sizeof (*entry)); - entry->flags =0 ; entry->pixelcode = csis_fmt->code; entry->bus.csi2.vc =0 ;drivers/media/v4l2-core/v4l2-subdev.c +9
-0@@ -306,6 +306,14 @@ static int call_set_selection(struct v4l2_subdev *sd, sd->ops->pad->set_selection (sd, state, sel); } +static int call_get_frame_desc (struct v4l2_subdev *sd,unsigned int pad, +struct v4l2_mbus_frame_desc *fd) +{ +memset (fd,0 ,sizeof (*fd)); + +return sd->ops->pad->get_frame_desc (sd, pad, fd); +} +static inline int check_edid (struct v4l2_subdev *sd,struct v4l2_subdev_edid *edid) {@@ -431,6 +439,7 @@ static const struct v4l2_subdev_pad_ops v4l2_subdev_call_pad_wrappers = { .set_edid = call_set_edid, .dv_timings_cap = call_dv_timings_cap, .enum_dv_timings = call_enum_dv_timings, + .get_frame_desc = call_get_frame_desc, .get_mbus_config = call_get_mbus_config, };
Sakari Ailus
maintainerPATCH v2 11/12 media: v4l: subdev: Print debug information on frame descriptor
In reply to Sakari AilusPrint debug level information on returned frame descriptors.
--- drivers/media/v4l2-core/v4l2-subdev.c | 35 ++++++++++++++++++++++++++- 1 file changed, 34 insertions(+), 1 deletion(-)
drivers/media/v4l2-core/v4l2-subdev.c +34 -1
@@ -309,9 +309,42 @@ static int call_set_selection(struct v4l2_subdev *sd,static int call_get_frame_desc (struct v4l2_subdev *sd,unsigned int pad,struct v4l2_mbus_frame_desc *fd) { +unsigned int i; +int ret; +memset (fd,0 ,sizeof (*fd)); -return sd->ops->pad->get_frame_desc (sd, pad, fd); + ret = sd->ops->pad->get_frame_desc (sd, pad, fd); +if (ret) +return ret; + +dev_dbg (sd->dev,"Frame descriptor\n" ); +dev_dbg (sd->dev,"\ttype %s\n" , + fd->type ==V4L2_MBUS_FRAME_DESC_TYPE_PARALLEL ?"parallel" : + fd->type ==V4L2_MBUS_FRAME_DESC_TYPE_CSI2 ?"CSI-2" : +"unknown" ); +dev_dbg (sd->dev,"\tentries %u\n" , fd->num_entries); + +for (i =0 ; i < fd->num_entries; i++) { +struct v4l2_mbus_frame_desc_entry *entry = &fd->entry[i]; + +dev_dbg (sd->dev,"\tentry %u\n" , i); +dev_dbg (sd->dev,"\tflags%s%s\n" , + entry->flags &V4L2_MBUS_FRAME_DESC_FL_LEN_MAX ? +" LEN_MAX" :"" , + entry->flags &V4L2_MBUS_FRAME_DESC_FL_BLOB ? +" BLOB" :"" ); +dev_dbg (sd->dev,"\t\tstream %u\n" , entry->stream); +dev_dbg (sd->dev,"\t\tpixelcode 0x%4.4x\n" , entry->pixelcode); +dev_dbg (sd->dev,"\t\tlength %u\n" , entry->length); + +if (fd->type ==V4L2_MBUS_FRAME_DESC_TYPE_CSI2 ) { +dev_dbg (sd->dev,"\t\tvc %u\n" , entry->bus.csi2.vc); +dev_dbg (sd->dev,"\t\tdt 0x%2.2x\n" , entry->bus.csi2.dt); + } + } + +return 0 ; } static inline int check_edid(struct v4l2_subdev *sd,
Signature · 1 line
2.39.2
Laurent Pinchart
maintainerRe: [PATCH v2 11/12] media: v4l: subdev: Print debug information on frame descriptor
Hi Sakari,
Thank you for the patch.
Quoted 21 lines · Sakari Ailus
Print debug level information on returned frame descriptors.
Signed-off-by Sakari Ailus <[email protected]>--- drivers/media/v4l2-core/v4l2-subdev.c | 35 ++++++++++++++++++++++++++- 1 file changed, 34 insertions(+), 1 deletion(-)drivers/media/v4l2-core/v4l2-subdev.c +3
-1@@ -309,9 +309,42 @@ static int call_set_selection(struct v4l2_subdev *sd,static int call_get_frame_desc (struct v4l2_subdev *sd,unsigned int pad,struct v4l2_mbus_frame_desc *fd) { +unsigned int i; +int ret; +memset (fd,0 ,sizeof (*fd)); -return sd->ops->pad->get_frame_desc (sd, pad, fd);
drivers/media/v4l2-core/v4l2-subdev.c static int call_set_selection(struct v4l2_subdev *sd, · line 326
Quoted 10 lines
drivers/media/v4l2-core/v4l2-subdev.c +10
-0+ ret = sd->ops->pad->get_frame_desc (sd, pad, fd); +if (ret) +return ret; + +dev_dbg (sd->dev,"Frame descriptor\n" ); +dev_dbg (sd->dev,"\ttype %s\n" , + fd->type ==V4L2_MBUS_FRAME_DESC_TYPE_PARALLEL ?"parallel" : + fd->type ==V4L2_MBUS_FRAME_DESC_TYPE_CSI2 ?"CSI-2" : +"unknown" ); +dev_dbg (sd->dev,"\tentries %u\n" , fd->num_entries);
You could skip this line, it's implied by the entries that you print below.
Quoted 7 lines
drivers/media/v4l2-core/v4l2-subdev.c +7
-0+ +for (i =0 ; i < fd->num_entries; i++) { +struct v4l2_mbus_frame_desc_entry *entry = &fd->entry[i]; + +dev_dbg (sd->dev,"\tentry %u\n" , i); + dev_dbg(sd->dev, "\tflags%s%s\n", + entry->flags & V4L2_MBUS_FRAME_DESC_FL_LEN_MAX ?
drivers/media/v4l2-core/v4l2-subdev.c static int call_set_selection(struct v4l2_subdev *sd, · line 343
Quoted 10 lines
drivers/media/v4l2-core/v4l2-subdev.c +10
-0+ " LEN_MAX" : "", + entry->flags &V4L2_MBUS_FRAME_DESC_FL_BLOB ? + " BLOB" : ""); +dev_dbg (sd->dev,"\t\tstream %u\n" , entry->stream); +dev_dbg (sd->dev,"\t\tpixelcode 0x%4.4x\n" , entry->pixelcode); +dev_dbg (sd->dev,"\t\tlength %u\n" , entry->length); + +if (fd->type ==V4L2_MBUS_FRAME_DESC_TYPE_CSI2 ) { +dev_dbg (sd->dev,"\t\tvc %u\n" , entry->bus.csi2.vc); +dev_dbg (sd->dev,"\t\tdt 0x%2.2x\n" , entry->bus.csi2.dt);
I'd merge those two in a single line.
drivers/media/v4l2-core/v4l2-subdev.c static int call_set_selection(struct v4l2_subdev *sd, · line 345
Quoted 2 lines
drivers/media/v4l2-core/v4l2-subdev.c +2
-0+ } + }
All this is a bit verbose. If it was in a hot path I would be annoyed, but in this case I suppose it can be useful for debugging and won't affect runtime too much.
It would be nice if we could have a single check and return early. That should be possible by using DEFINE_DYNAMIC_DEBUG_METADATA() and DYNAMIC_DEBUG_BRANCH(), like done in alloc_contig_dump_pages() for instance. It has the additional upside of being able to control all the messages with a single flag. I'm not sure it's worth it though, I'll let you decide.
Quoted 5 lines
drivers/media/v4l2-core/v4l2-subdev.c +2
-0+ +return 0 ; } static inline int check_edid(struct v4l2_subdev *sd,
Signature · 3 lines
Regards, Laurent Pinchart
Tomi Valkeinen
maintainerRe: [PATCH v2 11/12] media: v4l: subdev: Print debug information on frame descriptor
Quoted 67 lines · Laurent Pinchart
Hi Sakari,
Thank you for the patch.
Quoted 21 lines · Sakari Ailus
Print debug level information on returned frame descriptors.
Signed-off-by Sakari Ailus <[email protected]>--- drivers/media/v4l2-core/v4l2-subdev.c | 35 ++++++++++++++++++++++++++- 1 file changed, 34 insertions(+), 1 deletion(-)drivers/media/v4l2-core/v4l2-subdev.c +3
-1@@ -309,9 +309,42 @@ static int call_set_selection(struct v4l2_subdev *sd,static int call_get_frame_desc (struct v4l2_subdev *sd,unsigned int pad,struct v4l2_mbus_frame_desc *fd) { +unsigned int i; +int ret; +memset (fd,0 ,sizeof (*fd)); -return sd->ops->pad->get_frame_desc (sd, pad, fd);drivers/media/v4l2-core/v4l2-subdev.c static int call_set_selection(struct v4l2_subdev *sd, · line 326
Quoted 10 lines
drivers/media/v4l2-core/v4l2-subdev.c +10
-0+ ret = sd->ops->pad->get_frame_desc (sd, pad, fd); +if (ret) +return ret; + +dev_dbg (sd->dev,"Frame descriptor\n" ); +dev_dbg (sd->dev,"\ttype %s\n" , + fd->type ==V4L2_MBUS_FRAME_DESC_TYPE_PARALLEL ?"parallel" : + fd->type ==V4L2_MBUS_FRAME_DESC_TYPE_CSI2 ?"CSI-2" : +"unknown" ); +dev_dbg (sd->dev,"\tentries %u\n" , fd->num_entries);You could skip this line, it's implied by the entries that you print below.
Quoted 7 lines
drivers/media/v4l2-core/v4l2-subdev.c +7
-0+ +for (i =0 ; i < fd->num_entries; i++) { +struct v4l2_mbus_frame_desc_entry *entry = &fd->entry[i]; + +dev_dbg (sd->dev,"\tentry %u\n" , i); + dev_dbg(sd->dev, "\tflags%s%s\n", + entry->flags & V4L2_MBUS_FRAME_DESC_FL_LEN_MAX ?drivers/media/v4l2-core/v4l2-subdev.c static int call_set_selection(struct v4l2_subdev *sd, · line 343
Quoted 10 lines
drivers/media/v4l2-core/v4l2-subdev.c +10
-0+ " LEN_MAX" : "", + entry->flags &V4L2_MBUS_FRAME_DESC_FL_BLOB ? + " BLOB" : ""); +dev_dbg (sd->dev,"\t\tstream %u\n" , entry->stream); +dev_dbg (sd->dev,"\t\tpixelcode 0x%4.4x\n" , entry->pixelcode); +dev_dbg (sd->dev,"\t\tlength %u\n" , entry->length); + +if (fd->type ==V4L2_MBUS_FRAME_DESC_TYPE_CSI2 ) { +dev_dbg (sd->dev,"\t\tvc %u\n" , entry->bus.csi2.vc); +dev_dbg (sd->dev,"\t\tdt 0x%2.2x\n" , entry->bus.csi2.dt);I'd merge those two in a single line.
drivers/media/v4l2-core/v4l2-subdev.c static int call_set_selection(struct v4l2_subdev *sd, · line 345
Quoted 2 lines
drivers/media/v4l2-core/v4l2-subdev.c +2
-0+ } + }All this is a bit verbose. If it was in a hot path I would be annoyed, but in this case I suppose it can be useful for debugging and won't affect runtime too much.
Quoted 6 lines
It would be nice if we could have a single check and return early. That should be possible by using
DEFINE_DYNAMIC_DEBUG_METADATA()andDYNAMIC_DEBUG_BRANCH(), like done inalloc_contig_dump_pages()for instance. It has the additional upside of being able to control all the messages with a single flag. I'm not sure it's worth it though, I'll let you decide.
Yes, this is very spammy. Maybe instead of:
Frame descriptor
type CSI-2 entries 2 entry 0 flags LEN_MAX stream 0 pixelcode 0x3012 length 3194400 vc 0 dt 0x2c entry 1 flags LEN_MAX stream 1 pixelcode 0x8003 length 2904 vc 0 dt 0x12
Frame descriptor type CSI-2:
pad 0 stream 0 code 0x3012 len 3194400 vc 0 dt 0x2c LEN_MAX pad 0 stream 1 code 0x8003 len 2904 vc 0 dt 0x12 LEN_MAX
(note: pad is missing in your patch)
Tomi
Sakari Ailus
maintainerRe: [PATCH v2 11/12] media: v4l: subdev: Print debug information on frame descriptor
Hi Tomi, Laurent,
Thanks for the review.
Quoted 31 lines · Tomi Valkeinen
Quoted 30 lines · Laurent Pinchart
Hi Sakari,
Thank you for the patch.
Quoted 25 lines · Sakari Ailus
Print debug level information on returned frame descriptors.
Signed-off-by Sakari Ailus <[email protected]>--- drivers/media/v4l2-core/v4l2-subdev.c | 35 ++++++++++++++++++++++++++- 1 file changed, 34 insertions(+), 1 deletion(-)drivers/media/v4l2-core/v4l2-subdev.c +8
-1@@ -309,9 +309,42 @@ static int call_set_selection(struct v4l2_subdev *sd,static int call_get_frame_desc (struct v4l2_subdev *sd,unsigned int pad,struct v4l2_mbus_frame_desc *fd) { +unsigned int i; +int ret; +memset (fd,0 ,sizeof (*fd)); -return sd->ops->pad->get_frame_desc (sd, pad, fd); + ret = sd->ops->pad->get_frame_desc (sd, pad, fd); +if (ret) +return ret; + +dev_dbg (sd->dev,"Frame descriptor\n" );
Quoted 8 lines
Quoted 8 lines
drivers/media/v4l2-core/v4l2-subdev.c static int call_set_selection(struct v4l2_subdev *sd, · line 326
Quoted 5 lines
drivers/media/v4l2-core/v4l2-subdev.c +5
-0+dev_dbg (sd->dev,"\ttype %s\n" , + fd->type ==V4L2_MBUS_FRAME_DESC_TYPE_PARALLEL ?"parallel" : + fd->type ==V4L2_MBUS_FRAME_DESC_TYPE_CSI2 ?"CSI-2" : +"unknown" ); +dev_dbg (sd->dev,"\tentries %u\n" , fd->num_entries);You could skip this line, it's implied by the entries that you print below.
I guess that's reasonable if I switch to the format Tomi proposed. You'd only need to count lines.
Quoted 56 lines
Quoted 28 lines
Quoted 8 lines
drivers/media/v4l2-core/v4l2-subdev.c +7
-0+ +for (i =0 ; i < fd->num_entries; i++) { +struct v4l2_mbus_frame_desc_entry *entry = &fd->entry[i]; + +dev_dbg (sd->dev,"\tentry %u\n" , i); + dev_dbg(sd->dev, "\tflags%s%s\n", + entry->flags & V4L2_MBUS_FRAME_DESC_FL_LEN_MAX ?drivers/media/v4l2-core/v4l2-subdev.c static int call_set_selection(struct v4l2_subdev *sd, · line 343
Quoted 10 lines
drivers/media/v4l2-core/v4l2-subdev.c +10
-0+ " LEN_MAX" : "", + entry->flags &V4L2_MBUS_FRAME_DESC_FL_BLOB ? + " BLOB" : ""); +dev_dbg (sd->dev,"\t\tstream %u\n" , entry->stream); +dev_dbg (sd->dev,"\t\tpixelcode 0x%4.4x\n" , entry->pixelcode); +dev_dbg (sd->dev,"\t\tlength %u\n" , entry->length); + +if (fd->type ==V4L2_MBUS_FRAME_DESC_TYPE_CSI2 ) { +dev_dbg (sd->dev,"\t\tvc %u\n" , entry->bus.csi2.vc); +dev_dbg (sd->dev,"\t\tdt 0x%2.2x\n" , entry->bus.csi2.dt);I'd merge those two in a single line.
drivers/media/v4l2-core/v4l2-subdev.c static int call_set_selection(struct v4l2_subdev *sd, · line 345
Quoted 2 lines
drivers/media/v4l2-core/v4l2-subdev.c +2
-0+ } + }All this is a bit verbose. If it was in a hot path I would be annoyed, but in this case I suppose it can be useful for debugging and won't affect runtime too much.
Quoted 6 lines
It would be nice if we could have a single check and return early. That should be possible by using
DEFINE_DYNAMIC_DEBUG_METADATA()andDYNAMIC_DEBUG_BRANCH(), like done inalloc_contig_dump_pages()for instance. It has the additional upside of being able to control all the messages with a single flag. I'm not sure it's worth it though, I'll let you decide.Yes, this is very spammy. Maybe instead of:
Frame descriptor
type CSI-2 entries 2 entry 0 flags LEN_MAX stream 0 pixelcode 0x3012 length 3194400 vc 0 dt 0x2c entry 1 flags LEN_MAX stream 1 pixelcode 0x8003 length 2904 vc 0 dt 0x12
Quoted 5 lines
Frame descriptor type CSI-2:
pad 0 stream 0 code0x3012len 3194400 vc 0 dt0x2cLEN_MAXpad 0 stream 1 code0x8003len 2904 vc 0 dt0x12LEN_MAX(note: pad is missing in your patch)
It's indeed much more condensed but still contains all the relevant information. I'll switch to this (or something alike).
Signature · 3 lines
Regards, Sakari Ailus
Sakari Ailus
maintainerPATCH v2 12/12 media: mc: Check pad flag validity
In reply to Sakari AilusCheck the validity of pad flags on entity init. Exactly one of the flags must be set.
--- drivers/media/mc/mc-entity.c | 20 ++++++++++++++++++-- 1 file changed, 18 insertions(+), 2 deletions(-)
drivers/media/mc/mc-entity.c +18 -2
@@ -195,8 +195,9 @@ int media_entity_pads_init(struct media_entity *entity, u16 num_pads, struct media_pad *pads) {struct media_device *mdev = entity->graph_obj.mdev; -struct media_pad *iter; +struct media_pad *iter, *iter2;unsigned int i =0 ; +int ret =0 ;if (num_pads >=MEDIA_ENTITY_MAX_PADS )return -E2BIG ;
@@ -210,15 +211,30 @@ int media_entity_pads_init(struct media_entity *entity, u16 num_pads,media_entity_for_each_pad (entity, iter) { iter->entity = entity; iter->index = i++; + +if (hweight32 (iter->flags & (MEDIA_PAD_FL_SINK | +MEDIA_PAD_FL_SOURCE )) !=1 ) { + ret = -EINVAL ; +break ; + } +if (mdev)media_gobj_create (mdev,MEDIA_GRAPH_PAD , &iter->graph_obj); } +if (ret && mdev) { +media_entity_for_each_pad (entity, iter2) { +if (iter2 == iter) +break ; +media_gobj_destroy (&iter->graph_obj); + } + } +if (mdev)mutex_unlock (&mdev->graph_mutex); -return 0 ; +return ret; }EXPORT_SYMBOL_GPL (media_entity_pads_init);
Signature · 1 line
2.39.2
Laurent Pinchart
maintainerRe: [PATCH v2 12/12] media: mc: Check pad flag validity
Hi Sakari,
Thank you for the patch.
Quoted 34 lines · Sakari Ailus
Check the validity of pad flags on entity init. Exactly one of the flags must be set.
Signed-off-by Sakari Ailus <[email protected]>--- drivers/media/mc/mc-entity.c | 20 ++++++++++++++++++-- 1 file changed, 18 insertions(+), 2 deletions(-)drivers/media/mc/mc-entity.c +9
-1@@ -195,8 +195,9 @@ int media_entity_pads_init(struct media_entity *entity, u16 num_pads, struct media_pad *pads) {struct media_device *mdev = entity->graph_obj.mdev; -struct media_pad *iter; +struct media_pad *iter, *iter2;unsigned int i =0 ; +int ret =0 ;if (num_pads >=MEDIA_ENTITY_MAX_PADS )return -E2BIG ;@@ -210,15 +211,30 @@ int media_entity_pads_init(struct media_entity *entity, u16 num_pads,media_entity_for_each_pad (entity, iter) { iter->entity = entity; iter->index = i++; + +if (hweight32 (iter->flags & (MEDIA_PAD_FL_SINK | +MEDIA_PAD_FL_SOURCE )) !=1 ) { + ret = -EINVAL ; +break ; + } +
drivers/media/mc/mc-entity.c int media_entity_pads_init(struct media_entity *entity, u16 num_pads, · line 230
Quoted 10 lines
drivers/media/mc/mc-entity.c +5
-0if (mdev)media_gobj_create (mdev,MEDIA_GRAPH_PAD , &iter->graph_obj); } +if (ret && mdev) { +media_entity_for_each_pad (entity, iter2) { +if (iter2 == iter) +break ; +media_gobj_destroy (&iter->graph_obj);
Wrong iterator.
Instead of using a second iterator, which can be error-prone as shown here, how about breaking when !iter->graph_obj.mdev, which indicates an uninitialized object ?
Quoted 11 lines
drivers/media/mc/mc-entity.c +4
-1+ } + } +if (mdev)mutex_unlock (&mdev->graph_mutex); -return 0 ; +return ret; }EXPORT_SYMBOL_GPL (media_entity_pads_init);
Signature · 3 lines
Regards, Laurent Pinchart
Sakari Ailus
maintainerRe: [PATCH v2 12/12] media: mc: Check pad flag validity
Hi Laurent,
Thanks for the review.
Quoted 52 lines · Laurent Pinchart
Hi Sakari,
Thank you for the patch.
Quoted 34 lines · Sakari Ailus
Check the validity of pad flags on entity init. Exactly one of the flags must be set.
Signed-off-by Sakari Ailus <[email protected]>--- drivers/media/mc/mc-entity.c | 20 ++++++++++++++++++-- 1 file changed, 18 insertions(+), 2 deletions(-)drivers/media/mc/mc-entity.c +9
-1@@ -195,8 +195,9 @@ int media_entity_pads_init(struct media_entity *entity, u16 num_pads, struct media_pad *pads) {struct media_device *mdev = entity->graph_obj.mdev; -struct media_pad *iter; +struct media_pad *iter, *iter2;unsigned int i =0 ; +int ret =0 ;if (num_pads >=MEDIA_ENTITY_MAX_PADS )return -E2BIG ;@@ -210,15 +211,30 @@ int media_entity_pads_init(struct media_entity *entity, u16 num_pads,media_entity_for_each_pad (entity, iter) { iter->entity = entity; iter->index = i++; + +if (hweight32 (iter->flags & (MEDIA_PAD_FL_SINK | +MEDIA_PAD_FL_SOURCE )) !=1 ) { + ret = -EINVAL ; +break ; + } +drivers/media/mc/mc-entity.c int media_entity_pads_init(struct media_entity *entity, u16 num_pads, · line 230
Quoted 10 lines
drivers/media/mc/mc-entity.c +5
-0if (mdev)media_gobj_create (mdev,MEDIA_GRAPH_PAD , &iter->graph_obj); } +if (ret && mdev) { +media_entity_for_each_pad (entity, iter2) { +if (iter2 == iter) +break ; +media_gobj_destroy (&iter->graph_obj);Wrong iterator.
Quoted 3 lines
Instead of using a second iterator, which can be error-prone as shown here, how about breaking when !iter->graph_obj.mdev, which indicates an uninitialized object ?
media_gobj_destroy() is actually a no-op if it hasn't been initialised (created).
It'd be still cleaner to make the pad flag checks first and only then call media_gobj_create() on them. But if someone needs something more in the future, then that doesn't mix as well anymore.
Both are fine IMO.
Quoted 13 lines
Quoted 12 lines
drivers/media/mc/mc-entity.c +4
-1+ } + } +if (mdev)mutex_unlock (&mdev->graph_mutex); -return 0 ; +return ret; }EXPORT_SYMBOL_GPL (media_entity_pads_init);
Signature · 3 lines
Regards, Sakari Ailus
Laurent Pinchart
maintainerRe: [PATCH v2 12/12] media: mc: Check pad flag validity
Quoted 49 lines · Sakari Ailus
Quoted 48 lines · Laurent Pinchart
Quoted 34 lines · Sakari Ailus
Check the validity of pad flags on entity init. Exactly one of the flags must be set.
Signed-off-by Sakari Ailus <[email protected]>--- drivers/media/mc/mc-entity.c | 20 ++++++++++++++++++-- 1 file changed, 18 insertions(+), 2 deletions(-)drivers/media/mc/mc-entity.c +9
-1@@ -195,8 +195,9 @@ int media_entity_pads_init(struct media_entity *entity, u16 num_pads, struct media_pad *pads) {struct media_device *mdev = entity->graph_obj.mdev; -struct media_pad *iter; +struct media_pad *iter, *iter2;unsigned int i =0 ; +int ret =0 ;if (num_pads >=MEDIA_ENTITY_MAX_PADS )return -E2BIG ;@@ -210,15 +211,30 @@ int media_entity_pads_init(struct media_entity *entity, u16 num_pads,media_entity_for_each_pad (entity, iter) { iter->entity = entity; iter->index = i++; + +if (hweight32 (iter->flags & (MEDIA_PAD_FL_SINK | +MEDIA_PAD_FL_SOURCE )) !=1 ) { + ret = -EINVAL ; +break ; + } +drivers/media/mc/mc-entity.c int media_entity_pads_init(struct media_entity *entity, u16 num_pads, · line 230
Quoted 10 lines
drivers/media/mc/mc-entity.c +5
-0if (mdev)media_gobj_create (mdev,MEDIA_GRAPH_PAD , &iter->graph_obj); } +if (ret && mdev) { +media_entity_for_each_pad (entity, iter2) { +if (iter2 == iter) +break ; +media_gobj_destroy (&iter->graph_obj);Wrong iterator.
Quoted 6 lines
Quoted 3 lines
Instead of using a second iterator, which can be error-prone as shown here, how about breaking when !iter->graph_obj.mdev, which indicates an uninitialized object ?
media_gobj_destroy()is actually a no-op if it hasn't been initialised (created).
I'm fine calling it unconditionally too.
Quoted 17 lines
It'd be still cleaner to make the pad flag checks first and only then call
media_gobj_create()on them. But if someone needs something more in the future, then that doesn't mix as well anymore.Both are fine IMO.
Quoted 11 lines
Quoted 11 lines
drivers/media/mc/mc-entity.c +4
-1+ } + } +if (mdev)mutex_unlock (&mdev->graph_mutex); -return 0 ; +return ret; }EXPORT_SYMBOL_GPL (media_entity_pads_init);
Signature · 3 lines
Regards, Laurent Pinchart