Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

[media] staging: v4l: omap4iss: Use V4L2 graph PM operations

Power on devices represented by entities in the graph through the pipeline
state using V4L2 graph PM operations instead of what was in the omap3isp
driver.

Signed-off-by: Sakari Ailus <sakari.ailus@linux.intel.com>
Cc: Laurent Pinchart <laurent.pinchart@ideasonboard.com>
Signed-off-by: Mauro Carvalho Chehab <mchehab@osg.samsung.com>

authored by

Sakari Ailus and committed by
Mauro Carvalho Chehab
a288b78b 506a47eb

+7 -226
+1 -210
drivers/staging/media/omap4iss/iss.c
··· 363 363 } 364 364 365 365 /* ----------------------------------------------------------------------------- 366 - * Pipeline power management 367 - * 368 - * Entities must be powered up when part of a pipeline that contains at least 369 - * one open video device node. 370 - * 371 - * To achieve this use the entity use_count field to track the number of users. 372 - * For entities corresponding to video device nodes the use_count field stores 373 - * the users count of the node. For entities corresponding to subdevs the 374 - * use_count field stores the total number of users of all video device nodes 375 - * in the pipeline. 376 - * 377 - * The omap4iss_pipeline_pm_use() function must be called in the open() and 378 - * close() handlers of video device nodes. It increments or decrements the use 379 - * count of all subdev entities in the pipeline. 380 - * 381 - * To react to link management on powered pipelines, the link setup notification 382 - * callback updates the use count of all entities in the source and sink sides 383 - * of the link. 384 - */ 385 - 386 - /* 387 - * iss_pipeline_pm_use_count - Count the number of users of a pipeline 388 - * @entity: The entity 389 - * 390 - * Return the total number of users of all video device nodes in the pipeline. 391 - */ 392 - static int iss_pipeline_pm_use_count(struct media_entity *entity, 393 - struct media_entity_graph *graph) 394 - { 395 - int use = 0; 396 - 397 - media_entity_graph_walk_start(graph, entity); 398 - 399 - while ((entity = media_entity_graph_walk_next(graph))) { 400 - if (is_media_entity_v4l2_io(entity)) 401 - use += entity->use_count; 402 - } 403 - 404 - return use; 405 - } 406 - 407 - /* 408 - * iss_pipeline_pm_power_one - Apply power change to an entity 409 - * @entity: The entity 410 - * @change: Use count change 411 - * 412 - * Change the entity use count by @change. If the entity is a subdev update its 413 - * power state by calling the core::s_power operation when the use count goes 414 - * from 0 to != 0 or from != 0 to 0. 415 - * 416 - * Return 0 on success or a negative error code on failure. 417 - */ 418 - static int iss_pipeline_pm_power_one(struct media_entity *entity, int change) 419 - { 420 - struct v4l2_subdev *subdev; 421 - 422 - subdev = is_media_entity_v4l2_subdev(entity) 423 - ? media_entity_to_v4l2_subdev(entity) : NULL; 424 - 425 - if (entity->use_count == 0 && change > 0 && subdev) { 426 - int ret; 427 - 428 - ret = v4l2_subdev_call(subdev, core, s_power, 1); 429 - if (ret < 0 && ret != -ENOIOCTLCMD) 430 - return ret; 431 - } 432 - 433 - entity->use_count += change; 434 - WARN_ON(entity->use_count < 0); 435 - 436 - if (entity->use_count == 0 && change < 0 && subdev) 437 - v4l2_subdev_call(subdev, core, s_power, 0); 438 - 439 - return 0; 440 - } 441 - 442 - /* 443 - * iss_pipeline_pm_power - Apply power change to all entities in a pipeline 444 - * @entity: The entity 445 - * @change: Use count change 446 - * 447 - * Walk the pipeline to update the use count and the power state of all non-node 448 - * entities. 449 - * 450 - * Return 0 on success or a negative error code on failure. 451 - */ 452 - static int iss_pipeline_pm_power(struct media_entity *entity, int change, 453 - struct media_entity_graph *graph) 454 - { 455 - struct media_entity *first = entity; 456 - int ret = 0; 457 - 458 - if (!change) 459 - return 0; 460 - 461 - media_entity_graph_walk_start(graph, entity); 462 - 463 - while (!ret && (entity = media_entity_graph_walk_next(graph))) 464 - if (is_media_entity_v4l2_subdev(entity)) 465 - ret = iss_pipeline_pm_power_one(entity, change); 466 - 467 - if (!ret) 468 - return 0; 469 - 470 - media_entity_graph_walk_start(graph, first); 471 - 472 - while ((first = media_entity_graph_walk_next(graph)) && 473 - first != entity) 474 - if (is_media_entity_v4l2_subdev(first)) 475 - iss_pipeline_pm_power_one(first, -change); 476 - 477 - return ret; 478 - } 479 - 480 - /* 481 - * omap4iss_pipeline_pm_use - Update the use count of an entity 482 - * @entity: The entity 483 - * @use: Use (1) or stop using (0) the entity 484 - * 485 - * Update the use count of all entities in the pipeline and power entities on or 486 - * off accordingly. 487 - * 488 - * Return 0 on success or a negative error code on failure. Powering entities 489 - * off is assumed to never fail. No failure can occur when the use parameter is 490 - * set to 0. 491 - */ 492 - int omap4iss_pipeline_pm_use(struct media_entity *entity, int use, 493 - struct media_entity_graph *graph) 494 - { 495 - int change = use ? 1 : -1; 496 - int ret; 497 - 498 - mutex_lock(&entity->graph_obj.mdev->graph_mutex); 499 - 500 - /* Apply use count to node. */ 501 - entity->use_count += change; 502 - WARN_ON(entity->use_count < 0); 503 - 504 - /* Apply power change to connected non-nodes. */ 505 - ret = iss_pipeline_pm_power(entity, change, graph); 506 - if (ret < 0) 507 - entity->use_count -= change; 508 - 509 - mutex_unlock(&entity->graph_obj.mdev->graph_mutex); 510 - 511 - return ret; 512 - } 513 - 514 - /* 515 - * iss_pipeline_link_notify - Link management notification callback 516 - * @link: The link 517 - * @flags: New link flags that will be applied 518 - * 519 - * React to link management on powered pipelines by updating the use count of 520 - * all entities in the source and sink sides of the link. Entities are powered 521 - * on or off accordingly. 522 - * 523 - * Return 0 on success or a negative error code on failure. Powering entities 524 - * off is assumed to never fail. This function will not fail for disconnection 525 - * events. 526 - */ 527 - static int iss_pipeline_link_notify(struct media_link *link, u32 flags, 528 - unsigned int notification) 529 - { 530 - struct media_entity_graph *graph = 531 - &container_of(link->graph_obj.mdev, struct iss_device, 532 - media_dev)->pm_count_graph; 533 - struct media_entity *source = link->source->entity; 534 - struct media_entity *sink = link->sink->entity; 535 - int source_use; 536 - int sink_use; 537 - int ret; 538 - 539 - if (notification == MEDIA_DEV_NOTIFY_PRE_LINK_CH) { 540 - ret = media_entity_graph_walk_init(graph, 541 - link->graph_obj.mdev); 542 - if (ret) 543 - return ret; 544 - } 545 - 546 - source_use = iss_pipeline_pm_use_count(source, graph); 547 - sink_use = iss_pipeline_pm_use_count(sink, graph); 548 - 549 - if (notification == MEDIA_DEV_NOTIFY_POST_LINK_CH && 550 - !(flags & MEDIA_LNK_FL_ENABLED)) { 551 - /* Powering off entities is assumed to never fail. */ 552 - iss_pipeline_pm_power(source, -sink_use, graph); 553 - iss_pipeline_pm_power(sink, -source_use, graph); 554 - return 0; 555 - } 556 - 557 - if (notification == MEDIA_DEV_NOTIFY_PRE_LINK_CH && 558 - (flags & MEDIA_LNK_FL_ENABLED)) { 559 - ret = iss_pipeline_pm_power(source, sink_use, graph); 560 - if (ret < 0) 561 - return ret; 562 - 563 - ret = iss_pipeline_pm_power(sink, source_use, graph); 564 - if (ret < 0) 565 - iss_pipeline_pm_power(source, -sink_use, graph); 566 - } 567 - 568 - if (notification == MEDIA_DEV_NOTIFY_POST_LINK_CH) 569 - media_entity_graph_walk_cleanup(graph); 570 - 571 - return ret; 572 - } 573 - 574 - /* ----------------------------------------------------------------------------- 575 366 * Pipeline stream management 576 367 */ 577 368 ··· 988 1197 strlcpy(iss->media_dev.model, "TI OMAP4 ISS", 989 1198 sizeof(iss->media_dev.model)); 990 1199 iss->media_dev.hw_revision = iss->revision; 991 - iss->media_dev.link_notify = iss_pipeline_link_notify; 1200 + iss->media_dev.link_notify = v4l2_pipeline_link_notify; 992 1201 ret = media_device_register(&iss->media_dev); 993 1202 if (ret < 0) { 994 1203 dev_err(iss->dev, "Media device registration failed (%d)\n",
+2 -4
drivers/staging/media/omap4iss/iss.h
··· 15 15 #define _OMAP4_ISS_H_ 16 16 17 17 #include <media/v4l2-device.h> 18 + #include <media/v4l2-mc.h> 19 + 18 20 #include <linux/device.h> 19 21 #include <linux/io.h> 20 22 #include <linux/platform_device.h> ··· 89 87 struct iss_device { 90 88 struct v4l2_device v4l2_dev; 91 89 struct media_device media_dev; 92 - struct media_entity_graph pm_count_graph; 93 90 struct device *dev; 94 91 u32 revision; 95 92 ··· 152 151 enum iss_isp_subclk_resource res); 153 152 void omap4iss_isp_subclk_disable(struct iss_device *iss, 154 153 enum iss_isp_subclk_resource res); 155 - 156 - int omap4iss_pipeline_pm_use(struct media_entity *entity, int use, 157 - struct media_entity_graph *graph); 158 154 159 155 int omap4iss_register_entities(struct platform_device *pdev, 160 156 struct v4l2_device *v4l2_dev);
+4 -11
drivers/staging/media/omap4iss/iss_video.c
··· 19 19 #include <linux/slab.h> 20 20 #include <linux/vmalloc.h> 21 21 #include <linux/module.h> 22 + 22 23 #include <media/v4l2-dev.h> 23 24 #include <media/v4l2-ioctl.h> 25 + #include <media/v4l2-mc.h> 24 26 25 27 #include "iss_video.h" 26 28 #include "iss.h" ··· 1011 1009 goto done; 1012 1010 } 1013 1011 1014 - ret = media_entity_graph_walk_init(&handle->graph, 1015 - &video->iss->media_dev); 1016 - if (ret) 1017 - goto done; 1018 - 1019 - ret = omap4iss_pipeline_pm_use(&video->video.entity, 1, 1020 - &handle->graph); 1012 + ret = v4l2_pipeline_pm_use(&video->video.entity, 1); 1021 1013 if (ret < 0) { 1022 1014 omap4iss_put(video->iss); 1023 1015 goto done; ··· 1050 1054 done: 1051 1055 if (ret < 0) { 1052 1056 v4l2_fh_del(&handle->vfh); 1053 - media_entity_graph_walk_cleanup(&handle->graph); 1054 1057 kfree(handle); 1055 1058 } 1056 1059 ··· 1065 1070 /* Disable streaming and free the buffers queue resources. */ 1066 1071 iss_video_streamoff(file, vfh, video->type); 1067 1072 1068 - omap4iss_pipeline_pm_use(&video->video.entity, 0, &handle->graph); 1073 + v4l2_pipeline_pm_use(&video->video.entity, 0); 1069 1074 1070 1075 /* Release the videobuf2 queue */ 1071 1076 vb2_queue_release(&handle->queue); 1072 1077 1073 - /* Release the file handle. */ 1074 - media_entity_graph_walk_cleanup(&handle->graph); 1075 1078 v4l2_fh_del(vfh); 1076 1079 kfree(handle); 1077 1080 file->private_data = NULL;
-1
drivers/staging/media/omap4iss/iss_video.h
··· 183 183 struct vb2_queue queue; 184 184 struct v4l2_format format; 185 185 struct v4l2_fract timeperframe; 186 - struct media_entity_graph graph; 187 186 }; 188 187 189 188 #define to_iss_video_fh(fh) container_of(fh, struct iss_video_fh, vfh)