History

media: video-mux: update driver to active state

Drop the open coded pad format array, use subdev active state instead.

Philipp Zabel committed 3 years ago

Commit aafeeaf1 parent 5aa8de71 file · +24 −54Browse files

Unified · Split

drivers/media/platform/video-mux.c+24−54
@@ -24,7 +24,6 @@ struct video_mux { · 23 unmodified lines
2424 struct v4l2_subdev subdev;
2525 struct v4l2_async_notifier notifier;
2626 struct media_pad *pads;
27− struct v4l2_mbus_framefmt *format_mbus;
2827 struct mux_control *mux;
2928 struct mutex lock;
3029 int active;
@@ -71,6 +70,9 @@ static int video_mux_link_setup(struct media_entity *entity, · 40 unmodified lines
7170 mutex_lock(&vmux->lock);
7271
7372 if (flags & MEDIA_LNK_FL_ENABLED) {
73+ struct v4l2_subdev_state *sd_state;
74+ struct v4l2_mbus_framefmt *source_mbusformat;
75+
7476 if (vmux->active == local->index)
7577 goto out;
7678
@@ -86,7 +88,12 @@ static int video_mux_link_setup(struct media_entity *entity, · 9 unmodified lines
8688 vmux->active = local->index;
8789
8890 /* Propagate the active format to the source */
89− vmux->format_mbus[source_pad] = vmux->format_mbus[vmux->active];
91+ sd_state = v4l2_subdev_lock_and_get_active_state(sd);
92+ source_mbusformat = v4l2_subdev_get_pad_format(sd, sd_state,
93+ source_pad);
94+ *source_mbusformat = *v4l2_subdev_get_pad_format(sd, sd_state,
95+ vmux->active);
96+ v4l2_subdev_unlock_state(sd_state);
9097 } else {
9198 if (vmux->active != local->index)
9299 goto out;
@@ -138,40 +145,6 @@ static const struct v4l2_subdev_video_ops video_mux_subdev_video_ops = { · 45 unmodified lines
138145 .s_stream = video_mux_s_stream,
139146 };
140147
141−static struct v4l2_mbus_framefmt *
142−__video_mux_get_pad_format(struct v4l2_subdev *sd,
143− struct v4l2_subdev_state *sd_state,
144− unsigned int pad, u32 which)
145−{
146− struct video_mux *vmux = v4l2_subdev_to_video_mux(sd);
147−
148− switch (which) {
149− case V4L2_SUBDEV_FORMAT_TRY:
150− return v4l2_subdev_get_try_format(sd, sd_state, pad);
151− case V4L2_SUBDEV_FORMAT_ACTIVE:
152− return &vmux->format_mbus[pad];
153− default:
154− return NULL;
155− }
156−}
157−
158−static int video_mux_get_format(struct v4l2_subdev *sd,
159− struct v4l2_subdev_state *sd_state,
160− struct v4l2_subdev_format *sdformat)
161−{
162− struct video_mux *vmux = v4l2_subdev_to_video_mux(sd);
163−
164− mutex_lock(&vmux->lock);
165−
166− sdformat->format = *__video_mux_get_pad_format(sd, sd_state,
167− sdformat->pad,
168− sdformat->which);
169−
170− mutex_unlock(&vmux->lock);
171−
172− return 0;
173−}
174−
175148 static int video_mux_set_format(struct v4l2_subdev *sd,
176149 struct v4l2_subdev_state *sd_state,
177150 struct v4l2_subdev_format *sdformat)
@@ -181,14 +154,11 @@ static int video_mux_set_format(struct v4l2_subdev *sd, · 3 unmodified lines
181154 struct media_pad *pad = &vmux->pads[sdformat->pad];
182155 u16 source_pad = sd->entity.num_pads - 1;
183156
184− mbusformat = __video_mux_get_pad_format(sd, sd_state, sdformat->pad,
185− sdformat->which);
157+ mbusformat = v4l2_subdev_get_pad_format(sd, sd_state, sdformat->pad);
186158 if (!mbusformat)
187159 return -EINVAL;
188160
189− source_mbusformat = __video_mux_get_pad_format(sd, sd_state,
190− source_pad,
191− sdformat->which);
161+ source_mbusformat = v4l2_subdev_get_pad_format(sd, sd_state, source_pad);
192162 if (!source_mbusformat)
193163 return -EINVAL;
194164
@@ -298,7 +268,8 @@ static int video_mux_set_format(struct v4l2_subdev *sd, · 103 unmodified lines
298268
299269 /* Source pad mirrors active sink pad, no limitations on sink pads */
300270 if ((pad->flags & MEDIA_PAD_FL_SOURCE) && vmux->active >= 0)
301− sdformat->format = vmux->format_mbus[vmux->active];
271+ sdformat->format = *v4l2_subdev_get_pad_format(sd, sd_state,
272+ vmux->active);
302273
303274 *mbusformat = sdformat->format;
304275
@@ -321,7 +292,7 @@ static int video_mux_init_cfg(struct v4l2_subdev *sd, · 16 unmodified lines
321292 mutex_lock(&vmux->lock);
322293
323294 for (i = 0; i < sd->entity.num_pads; i++) {
324− mbusformat = v4l2_subdev_get_try_format(sd, sd_state, i);
295+ mbusformat = v4l2_subdev_get_pad_format(sd, sd_state, i);
325296 *mbusformat = video_mux_format_mbus_default;
326297 }
327298
@@ -332,7 +303,7 @@ static int video_mux_init_cfg(struct v4l2_subdev *sd, · 4 unmodified lines
332303
333304 static const struct v4l2_subdev_pad_ops video_mux_pad_ops = {
334305 .init_cfg = video_mux_init_cfg,
335− .get_fmt = video_mux_get_format,
306+ .get_fmt = v4l2_subdev_get_fmt,
336307 .set_fmt = video_mux_set_format,
337308 };
338309
@@ -462,17 +433,9 @@ static int video_mux_probe(struct platform_device *pdev) · 123 unmodified lines
462433 if (!vmux->pads)
463434 return -ENOMEM;
464435
465− vmux->format_mbus = devm_kcalloc(dev, num_pads,
466− sizeof(*vmux->format_mbus),
467− GFP_KERNEL);
468− if (!vmux->format_mbus)
469− return -ENOMEM;
470−
471− for (i = 0; i < num_pads; i++) {
436+ for (i = 0; i < num_pads; i++)
472437 vmux->pads[i].flags = (i < num_pads - 1) ? MEDIA_PAD_FL_SINK
473438 : MEDIA_PAD_FL_SOURCE;
474− vmux->format_mbus[i] = video_mux_format_mbus_default;
475− }
476439
477440 vmux->subdev.entity.function = MEDIA_ENT_F_VID_MUX;
478441 ret = media_entity_pads_init(&vmux->subdev.entity, num_pads,
@@ -482,12 +445,18 @@ static int video_mux_probe(struct platform_device *pdev) · 3 unmodified lines
482445
483446 vmux->subdev.entity.ops = &video_mux_ops;
484447
448+ ret = v4l2_subdev_init_finalize(&vmux->subdev);
449+ if (ret < 0)
450+ goto err_entity_cleanup;
451+
485452 ret = video_mux_async_register(vmux, num_pads - 1);
486453 if (ret)
487− goto err_entity_cleanup;
454+ goto err_subdev_cleanup;
488455
489456 return 0;
490457
458+err_subdev_cleanup:
459+ v4l2_subdev_cleanup(&vmux->subdev);
491460 err_entity_cleanup:
492461 media_entity_cleanup(&vmux->subdev.entity);
493462 return ret;
@@ -501,6 +470,7 @@ static void video_mux_remove(struct platform_device *pdev) · 7 unmodified lines
501470 v4l2_async_nf_unregister(&vmux->notifier);
502471 v4l2_async_nf_cleanup(&vmux->notifier);
503472 v4l2_async_unregister_subdev(sd);
473+ v4l2_subdev_cleanup(sd);
504474 media_entity_cleanup(&sd->entity);
505475 }
506476

Keyboard shortcuts

General

Show keyboard shortcuts
?
Focus the current search
/

Issues and pull requests

Open filters
f

Issues, pull requests and Inbox

Select next item
j↓
Select previous item
k↑
Open selected item
Enter
Dismiss filters or clear selection
Esc

Repository code

Go to file
t