From patchwork Mon Feb 14 12:21:19 2011 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Laurent Pinchart X-Patchwork-Id: 554821 Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by demeter1.kernel.org (8.14.4/8.14.3) with ESMTP id p1ECM9Sd028887 for ; Mon, 14 Feb 2011 12:22:10 GMT Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1754213Ab1BNMVd (ORCPT ); Mon, 14 Feb 2011 07:21:33 -0500 Received: from perceval.ideasonboard.com ([95.142.166.194]:58186 "EHLO perceval.ideasonboard.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1753855Ab1BNMV1 (ORCPT ); Mon, 14 Feb 2011 07:21:27 -0500 Received: from localhost.localdomain (unknown [91.178.218.226]) by perceval.ideasonboard.com (Postfix) with ESMTPSA id 0E3C335A13; Mon, 14 Feb 2011 12:21:22 +0000 (UTC) From: Laurent Pinchart To: linux-media@vger.kernel.org Cc: sakari.ailus@maxwell.research.nokia.com Subject: [PATCH v7 06/11] v4l: subdev: Add new file operations Date: Mon, 14 Feb 2011 13:21:19 +0100 Message-Id: <1297686084-9715-7-git-send-email-laurent.pinchart@ideasonboard.com> X-Mailer: git-send-email 1.7.3.4 In-Reply-To: <1297686084-9715-1-git-send-email-laurent.pinchart@ideasonboard.com> References: <1297686084-9715-1-git-send-email-laurent.pinchart@ideasonboard.com> Sender: linux-media-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-media@vger.kernel.org X-Greylist: IP, sender and recipient auto-whitelisted, not delayed by milter-greylist-4.2.6 (demeter1.kernel.org [140.211.167.41]); Mon, 14 Feb 2011 12:22:10 +0000 (UTC) diff --git a/drivers/media/video/v4l2-subdev.c b/drivers/media/video/v4l2-subdev.c index ebf7f97..cee7993 100644 --- a/drivers/media/video/v4l2-subdev.c +++ b/drivers/media/video/v4l2-subdev.c @@ -61,7 +61,7 @@ static int subdev_open(struct file *file) struct v4l2_subdev *sd = vdev_to_v4l2_subdev(vdev); struct v4l2_subdev_fh *subdev_fh; #if defined(CONFIG_MEDIA_CONTROLLER) - struct media_entity *entity; + struct media_entity *entity = NULL; #endif int ret; @@ -101,9 +101,19 @@ static int subdev_open(struct file *file) } #endif + if (sd->internal_ops && sd->internal_ops->open) { + ret = sd->internal_ops->open(sd, subdev_fh); + if (ret < 0) + goto err; + } + return 0; err: +#if defined(CONFIG_MEDIA_CONTROLLER) + if (entity) + media_entity_put(entity); +#endif v4l2_fh_del(&subdev_fh->vfh); v4l2_fh_exit(&subdev_fh->vfh); subdev_fh_free(subdev_fh); @@ -114,13 +124,13 @@ err: static int subdev_close(struct file *file) { -#if defined(CONFIG_MEDIA_CONTROLLER) struct video_device *vdev = video_devdata(file); struct v4l2_subdev *sd = vdev_to_v4l2_subdev(vdev); -#endif struct v4l2_fh *vfh = file->private_data; struct v4l2_subdev_fh *subdev_fh = to_v4l2_subdev_fh(vfh); + if (sd->internal_ops && sd->internal_ops->close) + sd->internal_ops->close(sd, subdev_fh); #if defined(CONFIG_MEDIA_CONTROLLER) if (sd->v4l2_dev->mdev) media_entity_put(&sd->entity); diff --git a/include/media/v4l2-subdev.h b/include/media/v4l2-subdev.h index d64438d..ff42cc4 100644 --- a/include/media/v4l2-subdev.h +++ b/include/media/v4l2-subdev.h @@ -42,6 +42,7 @@ struct v4l2_ctrl_handler; struct v4l2_event_subscription; struct v4l2_fh; struct v4l2_subdev; +struct v4l2_subdev_fh; struct tuner_setup; /* decode_vbi_line */ @@ -429,10 +430,16 @@ struct v4l2_subdev_ops { * * unregistered: called when this subdev is unregistered. When called the * v4l2_dev field is still set to the correct v4l2_device. + * + * open: called when the subdev device node is opened by an application. + * + * close: called when the subdev device node is closed. */ struct v4l2_subdev_internal_ops { int (*registered)(struct v4l2_subdev *sd); void (*unregistered)(struct v4l2_subdev *sd); + int (*open)(struct v4l2_subdev *sd, struct v4l2_subdev_fh *fh); + int (*close)(struct v4l2_subdev *sd, struct v4l2_subdev_fh *fh); }; #define V4L2_SUBDEV_NAME_SIZE 32