Drop the open coded pad format array, use subdev active state instead.
Unified · Split
| @@ -24,7 +24,6 @@ struct video_mux { · 23 unmodified lines | |||
| 24 | struct v4l2_subdev subdev; | 24 | struct v4l2_subdev subdev; |
| 25 | struct v4l2_async_notifier notifier; | 25 | struct v4l2_async_notifier notifier; |
| 26 | struct media_pad *pads; | 26 | struct media_pad *pads; |
| 27 | struct v4l2_mbus_framefmt *format_mbus; | ||
| 28 | struct mux_control *mux; | 27 | struct mux_control *mux; |
| 29 | struct mutex lock; | 28 | struct mutex lock; |
| 30 | int active; | 29 | int active; |
| @@ -71,6 +70,9 @@ static int video_mux_link_setup(struct media_entity *entity, · 40 unmodified lines | |||
| 71 | mutex_lock(&vmux->lock); | 70 | mutex_lock(&vmux->lock); |
| 72 | 71 | ||
| 73 | if (flags & MEDIA_LNK_FL_ENABLED) { | 72 | if (flags & MEDIA_LNK_FL_ENABLED) { |
| 73 | struct v4l2_subdev_state *sd_state; | ||
| 74 | struct v4l2_mbus_framefmt *source_mbusformat; | ||
| 75 | |||
| 74 | if (vmux->active == local->index) | 76 | if (vmux->active == local->index) |
| 75 | goto out; | 77 | goto out; |
| 76 | 78 | ||
| @@ -86,7 +88,12 @@ static int video_mux_link_setup(struct media_entity *entity, · 9 unmodified lines | |||
| 86 | vmux->active = local->index; | 88 | vmux->active = local->index; |
| 87 | 89 | ||
| 88 | /* Propagate the active format to the source */ | 90 | /* 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); | ||
| 90 | } else { | 97 | } else { |
| 91 | if (vmux->active != local->index) | 98 | if (vmux->active != local->index) |
| 92 | goto out; | 99 | goto out; |
| @@ -138,40 +145,6 @@ static const struct v4l2_subdev_video_ops video_mux_subdev_video_ops = { · 45 unmodified lines | |||
| 138 | .s_stream = video_mux_s_stream, | 145 | .s_stream = video_mux_s_stream, |
| 139 | }; | 146 | }; |
| 140 | 147 | ||
| 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 | |||
| 175 | static int video_mux_set_format(struct v4l2_subdev *sd, | 148 | static int video_mux_set_format(struct v4l2_subdev *sd, |
| 176 | struct v4l2_subdev_state *sd_state, | 149 | struct v4l2_subdev_state *sd_state, |
| 177 | struct v4l2_subdev_format *sdformat) | 150 | struct v4l2_subdev_format *sdformat) |
| @@ -181,14 +154,11 @@ static int video_mux_set_format(struct v4l2_subdev *sd, · 3 unmodified lines | |||
| 181 | struct media_pad *pad = &vmux->pads[sdformat->pad]; | 154 | struct media_pad *pad = &vmux->pads[sdformat->pad]; |
| 182 | u16 source_pad = sd->entity.num_pads - 1; | 155 | u16 source_pad = sd->entity.num_pads - 1; |
| 183 | 156 | ||
| 184 | mbusformat = __video_mux_get_pad_format(sd, sd_state, sdformat->pad, | 157 | mbusformat = v4l2_subdev_get_pad_format(sd, sd_state, sdformat->pad); |
| 185 | sdformat->which); | ||
| 186 | if (!mbusformat) | 158 | if (!mbusformat) |
| 187 | return -EINVAL; | 159 | return -EINVAL; |
| 188 | 160 | ||
| 189 | source_mbusformat = __video_mux_get_pad_format(sd, sd_state, | 161 | source_mbusformat = v4l2_subdev_get_pad_format(sd, sd_state, source_pad); |
| 190 | source_pad, | ||
| 191 | sdformat->which); | ||
| 192 | if (!source_mbusformat) | 162 | if (!source_mbusformat) |
| 193 | return -EINVAL; | 163 | return -EINVAL; |
| 194 | 164 | ||
| @@ -298,7 +268,8 @@ static int video_mux_set_format(struct v4l2_subdev *sd, · 103 unmodified lines | |||
| 298 | 268 | ||
| 299 | /* Source pad mirrors active sink pad, no limitations on sink pads */ | 269 | /* Source pad mirrors active sink pad, no limitations on sink pads */ |
| 300 | if ((pad->flags & MEDIA_PAD_FL_SOURCE) && vmux->active >= 0) | 270 | 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); | ||
| 302 | 273 | ||
| 303 | *mbusformat = sdformat->format; | 274 | *mbusformat = sdformat->format; |
| 304 | 275 | ||
| @@ -321,7 +292,7 @@ static int video_mux_init_cfg(struct v4l2_subdev *sd, · 16 unmodified lines | |||
| 321 | mutex_lock(&vmux->lock); | 292 | mutex_lock(&vmux->lock); |
| 322 | 293 | ||
| 323 | for (i = 0; i < sd->entity.num_pads; i++) { | 294 | 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); |
| 325 | *mbusformat = video_mux_format_mbus_default; | 296 | *mbusformat = video_mux_format_mbus_default; |
| 326 | } | 297 | } |
| 327 | 298 | ||
| @@ -332,7 +303,7 @@ static int video_mux_init_cfg(struct v4l2_subdev *sd, · 4 unmodified lines | |||
| 332 | 303 | ||
| 333 | static const struct v4l2_subdev_pad_ops video_mux_pad_ops = { | 304 | static const struct v4l2_subdev_pad_ops video_mux_pad_ops = { |
| 334 | .init_cfg = video_mux_init_cfg, | 305 | .init_cfg = video_mux_init_cfg, |
| 335 | .get_fmt = video_mux_get_format, | 306 | .get_fmt = v4l2_subdev_get_fmt, |
| 336 | .set_fmt = video_mux_set_format, | 307 | .set_fmt = video_mux_set_format, |
| 337 | }; | 308 | }; |
| 338 | 309 | ||
| @@ -462,17 +433,9 @@ static int video_mux_probe(struct platform_device *pdev) · 123 unmodified lines | |||
| 462 | if (!vmux->pads) | 433 | if (!vmux->pads) |
| 463 | return -ENOMEM; | 434 | return -ENOMEM; |
| 464 | 435 | ||
| 465 | vmux->format_mbus = devm_kcalloc(dev, num_pads, | 436 | for (i = 0; i < num_pads; i++) |
| 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++) { | ||
| 472 | vmux->pads[i].flags = (i < num_pads - 1) ? MEDIA_PAD_FL_SINK | 437 | vmux->pads[i].flags = (i < num_pads - 1) ? MEDIA_PAD_FL_SINK |
| 473 | : MEDIA_PAD_FL_SOURCE; | 438 | : MEDIA_PAD_FL_SOURCE; |
| 474 | vmux->format_mbus[i] = video_mux_format_mbus_default; | ||
| 475 | } | ||
| 476 | 439 | ||
| 477 | vmux->subdev.entity.function = MEDIA_ENT_F_VID_MUX; | 440 | vmux->subdev.entity.function = MEDIA_ENT_F_VID_MUX; |
| 478 | ret = media_entity_pads_init(&vmux->subdev.entity, num_pads, | 441 | 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 | |||
| 482 | 445 | ||
| 483 | vmux->subdev.entity.ops = &video_mux_ops; | 446 | vmux->subdev.entity.ops = &video_mux_ops; |
| 484 | 447 | ||
| 448 | ret = v4l2_subdev_init_finalize(&vmux->subdev); | ||
| 449 | if (ret < 0) | ||
| 450 | goto err_entity_cleanup; | ||
| 451 | |||
| 485 | ret = video_mux_async_register(vmux, num_pads - 1); | 452 | ret = video_mux_async_register(vmux, num_pads - 1); |
| 486 | if (ret) | 453 | if (ret) |
| 487 | goto err_entity_cleanup; | 454 | goto err_subdev_cleanup; |
| 488 | 455 | ||
| 489 | return 0; | 456 | return 0; |
| 490 | 457 | ||
| 458 | err_subdev_cleanup: | ||
| 459 | v4l2_subdev_cleanup(&vmux->subdev); | ||
| 491 | err_entity_cleanup: | 460 | err_entity_cleanup: |
| 492 | media_entity_cleanup(&vmux->subdev.entity); | 461 | media_entity_cleanup(&vmux->subdev.entity); |
| 493 | return ret; | 462 | return ret; |
| @@ -501,6 +470,7 @@ static void video_mux_remove(struct platform_device *pdev) · 7 unmodified lines | |||
| 501 | v4l2_async_nf_unregister(&vmux->notifier); | 470 | v4l2_async_nf_unregister(&vmux->notifier); |
| 502 | v4l2_async_nf_cleanup(&vmux->notifier); | 471 | v4l2_async_nf_cleanup(&vmux->notifier); |
| 503 | v4l2_async_unregister_subdev(sd); | 472 | v4l2_async_unregister_subdev(sd); |
| 473 | v4l2_subdev_cleanup(sd); | ||
| 504 | media_entity_cleanup(&sd->entity); | 474 | media_entity_cleanup(&sd->entity); |
| 505 | } | 475 | } |
| 506 | 476 | ||