V4L2 sub-device active state helper, CCS fixes
Subsystems (2)
Sakari Ailus
maintainercover V4L2 sub-device active state helper, CCS fixes
Hi folks,
This set includes a helper for working with V4L2 sub-device active state as well as a fix for the CCS driver sub-device state patch.
Sakari Ailus (4):
media: v4l: subdev: Set sub-device active state earlier
media: v4l: subdev: Add a helper to tell if a sub-device state is
active
media: ccs: Rework initialising sub-device state
media: ccs: Fix a (harmless) lockdep warning
drivers/media/i2c/ccs/ccs-core.c | 64 ++++++++++++++++++--------- drivers/media/v4l2-core/v4l2-subdev.c | 14 +++--- include/media/v4l2-subdev.h | 11 ++++- 3 files changed, 61 insertions(+), 28 deletions(-)
Signature · 1 line
2.39.2
Sakari Ailus
maintainerPATCH 1/4 media: v4l: subdev: Set sub-device active state earlier
Set sub-device active state earlier in order to have it available to the sub-device driver when driver's init_cfg operation is called.
--- drivers/media/v4l2-core/v4l2-subdev.c | 14 +++++++++----- include/media/v4l2-subdev.h | 3 ++- 2 files changed, 11 insertions(+), 6 deletions(-)
drivers/media/v4l2-core/v4l2-subdev.c +9 -5
@@ -53,7 +53,7 @@ static int subdev_fh_init(struct v4l2_subdev_fh *fh, struct v4l2_subdev *sd)struct v4l2_subdev_state *state;static struct lock_class_key key; - state =__v4l2_subdev_state_alloc (sd,"fh->state->lock" , &key); + state =__v4l2_subdev_state_alloc (sd,"fh->state->lock" , &key, false);if (IS_ERR (state))return PTR_ERR (state);
@@ -1426,7 +1426,7 @@ EXPORT_SYMBOL_GPL(v4l2_subdev_has_pad_interdep);struct v4l2_subdev_state *__v4l2_subdev_state_alloc (struct v4l2_subdev *sd,const char *lock_name, -struct lock_class_key *lock_key) +struct lock_class_key *lock_key,bool active) {struct v4l2_subdev_state *state;int ret;
@@ -1451,6 +1451,9 @@ __v4l2_subdev_state_alloc(struct v4l2_subdev *sd, const char *lock_name, } } +if (active) + sd->active_state = state; +/* * There can be no race at this point, but we lock the state anyway to * satisfy lockdep checks.
@@ -1470,6 +1473,9 @@ __v4l2_subdev_state_alloc(struct v4l2_subdev *sd, const char *lock_name,kfree (state); +if (active) + sd->active_state =NULL ; +return ERR_PTR (ret); }EXPORT_SYMBOL_GPL (__v4l2_subdev_state_alloc);
@@ -1493,12 +1499,10 @@ int __v4l2_subdev_init_finalize(struct v4l2_subdev *sd, const char *name, {struct v4l2_subdev_state *state; - state =__v4l2_subdev_state_alloc (sd, name, key); + state =__v4l2_subdev_state_alloc (sd, name, key, true);if (IS_ERR (state))return PTR_ERR (state); - sd->active_state = state; -return 0 ; }EXPORT_SYMBOL_GPL (__v4l2_subdev_init_finalize);
include/media/v4l2-subdev.h +2 -1
@@ -1346,7 +1346,8 @@ bool v4l2_subdev_has_pad_interdep(struct media_entity *entity,*/ struct v4l2_subdev_state *__v4l2_subdev_state_alloc (struct v4l2_subdev *sd,const char *lock_name, -struct lock_class_key *key); +struct lock_class_key *key, +bool active);/** * __v4l2_subdev_state_free - free a v4l2_subdev_state
Signature · 1 line
2.39.2
Sakari Ailus
maintainerPATCH 2/4 media: v4l: subdev: Add a helper to tell if a sub-device state is active
In reply to Sakari AilusAdd a helper called v4l2_subdev_state_whence() to return enum v4l2_subdev_format_whence to tell whether a state the driver is dealing with it active or not.
--- include/media/v4l2-subdev.h | 8 ++++++++ 1 file changed, 8 insertions(+)
include/media/v4l2-subdev.h +8 -0
@@ -1645,6 +1645,14 @@ v4l2_subdev_state_get_opposite_stream_format(struct v4l2_subdev_state *state,u64 v4l2_subdev_state_xlate_streams (const struct v4l2_subdev_state *state,u32 pad0,u32 pad1,u64 *streams); +static inline enum v4l2_subdev_format_whence +v4l2_subdev_state_whence (struct v4l2_subdev *sd, +struct v4l2_subdev_state *state) +{ +return sd->active_state == state ? +V4L2_SUBDEV_FORMAT_ACTIVE :V4L2_SUBDEV_FORMAT_TRY ; +} +/** * enum v4l2_subdev_routing_restriction - Subdevice internal routing restrictions *
Signature · 1 line
2.39.2
Sakari Ailus
maintainerPATCH 3/4 media: ccs: Rework initialising sub-device state
In reply to Sakari AilusInitialise sub-device state in init_cfg callback using ccs_propagate() to the extent it covers of the initialisation. This fixes a bug where the driver configuration was incorrectly initialised.
--- drivers/media/i2c/ccs/ccs-core.c | 47 ++++++++++++++++++++------------ 1 file changed, 30 insertions(+), 17 deletions(-)
drivers/media/i2c/ccs/ccs-core.c +30 -17
@@ -2075,6 +2075,7 @@ static void ccs_propagate(struct v4l2_subdev *subdev,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_mbus_framefmt *fmt;ccs_get_crop_compose (subdev, sd_state, crops, &comp);
@@ -2096,6 +2097,9 @@ static void ccs_propagate(struct v4l2_subdev *subdev, fallthrough;case V4L2_SEL_TGT_COMPOSE : *crops[CCS_PAD_SRC ] = *comp; + fmt =v4l2_subdev_get_pad_format (subdev, sd_state,CCS_PAD_SRC ); + fmt->width = comp->width; + fmt->height = comp->height;if (which ==V4L2_SUBDEV_FORMAT_ACTIVE && ssd == sensor->src) sensor->src_src = *crops[CCS_PAD_SRC ];break ;
@@ -3003,31 +3007,40 @@ static int ccs_init_cfg(struct v4l2_subdev *sd, {struct ccs_subdev *ssd =to_ccs_subdev (sd);struct ccs_sensor *sensor = ssd->sensor; -unsigned int i; +unsigned int pad = ssd == sensor->pixel_array ? +CCS_PA_PAD_SRC :CCS_PAD_SINK ; +struct v4l2_mbus_framefmt *fmt = +v4l2_subdev_get_pad_format (sd, sd_state, pad); +struct v4l2_rect *crop = +v4l2_subdev_get_pad_crop (sd, sd_state, pad);mutex_lock (&sensor->mutex); -for (i =0 ; i < ssd->npads; i++) { -struct v4l2_mbus_framefmt *fmt = -v4l2_subdev_get_pad_format (sd, sd_state, i); -struct v4l2_rect *crop = -v4l2_subdev_get_pad_crop (sd, sd_state, i); -struct v4l2_rect *comp; - -ccs_get_native_size (ssd, crop); +ccs_get_native_size (ssd, crop); - fmt->width = crop->width; - fmt->height = crop->height; - fmt->code = sensor->internal_csi_format->code; - fmt->field =V4L2_FIELD_NONE ; + fmt->width = crop->width; + fmt->height = crop->height; + fmt->code = sensor->internal_csi_format->code; + fmt->field =V4L2_FIELD_NONE ; -if (ssd == sensor->pixel_array) -continue ; +if (ssd == sensor->pixel_array) { +if (v4l2_subdev_state_whence (sd, sd_state) == +V4L2_SUBDEV_FORMAT_ACTIVE ) + sensor->pa_src = *crop; - comp =v4l2_subdev_get_pad_compose (sd, sd_state, i); - *comp = *crop; +mutex_unlock (&sensor->mutex); +return 0 ; } + fmt =v4l2_subdev_get_pad_format (sd, sd_state,CCS_PAD_SRC ); + fmt->code = ssd == sensor->src ? + sensor->csi_format->code : sensor->internal_csi_format->code; + fmt->field =V4L2_FIELD_NONE ; + +ccs_propagate (sd, sd_state, +v4l2_subdev_state_whence (sd, sd_state), +V4L2_SEL_TGT_CROP ); +mutex_unlock (&sensor->mutex);return 0 ;
Signature · 1 line
2.39.2
Sakari Ailus
maintainerPATCH 4/4 media: ccs: Fix a (harmless) lockdep warning
In reply to Sakari AilusThe v4l2_subdev_init_finalize() is a macro that creates an unique lockdep key and name. As the CCS driver initialises all three of its sub-devices using the same call site, this creates a lockdep warning. Address it.
--- drivers/media/i2c/ccs/ccs-core.c | 17 ++++++++++++----- 1 file changed, 12 insertions(+), 5 deletions(-)
drivers/media/i2c/ccs/ccs-core.c +12 -5
@@ -2955,7 +2955,9 @@ static void ccs_cleanup(struct ccs_sensor *sensor)static int ccs_init_subdev (struct ccs_sensor *sensor,struct ccs_subdev *ssd,const char *name, -unsigned short num_pads,u32 function) +unsigned short num_pads,u32 function, +const char *lock_name, +struct lock_class_key *lock_key) {struct i2c_client *client =v4l2_get_subdevdata (&sensor->src->sd);int rval;
@@ -2993,7 +2995,7 @@ static int ccs_init_subdev(struct ccs_sensor *sensor,return rval; } - rval =v4l2_subdev_init_finalize (&ssd->sd); + rval =__v4l2_subdev_init_finalize (&ssd->sd, lock_name, lock_key);if (rval) {media_entity_cleanup (&ssd->sd.entity);return rval;
@@ -3208,6 +3210,8 @@ static int ccs_firmware_name(struct i2c_client *client,static int ccs_probe (struct i2c_client *client) { +static struct lock_class_key pixel_array_lock_key, binner_lock_key, + scaler_lock_key;const struct ccs_device *ccsdev =device_get_match_data (&client->dev);struct ccs_sensor *sensor;const struct firmware *fw;
@@ -3491,15 +3495,18 @@ static int ccs_probe(struct i2c_client *client) } rval =ccs_init_subdev (sensor, sensor->scaler," scaler" ,2 , -MEDIA_ENT_F_PROC_VIDEO_SCALER ); +MEDIA_ENT_F_PROC_VIDEO_SCALER , +"ccs scaler mutex" , &scaler_lock_key);if (rval) goto out_cleanup; rval =ccs_init_subdev (sensor, sensor->binner," binner" ,2 , -MEDIA_ENT_F_PROC_VIDEO_SCALER ); +MEDIA_ENT_F_PROC_VIDEO_SCALER , +"ccs binner mutex" , &binner_lock_key);if (rval) goto out_cleanup; rval =ccs_init_subdev (sensor, sensor->pixel_array," pixel_array" ,1 , -MEDIA_ENT_F_CAM_SENSOR ); +MEDIA_ENT_F_CAM_SENSOR ,"ccs pixel array mutex" , + &pixel_array_lock_key);if (rval) goto out_cleanup;
Signature · 1 line
2.39.2