From patchwork Wed Jun 19 14:10:54 2013 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Andrzej Hajda X-Patchwork-Id: 2749841 Return-Path: X-Original-To: patchwork-linux-media@patchwork.kernel.org Delivered-To: patchwork-parsemail@patchwork2.web.kernel.org Received: from mail.kernel.org (mail.kernel.org [198.145.19.201]) by patchwork2.web.kernel.org (Postfix) with ESMTP id 57310C0AB1 for ; Wed, 19 Jun 2013 14:11:31 +0000 (UTC) Received: from mail.kernel.org (localhost [127.0.0.1]) by mail.kernel.org (Postfix) with ESMTP id 17CEC20340 for ; Wed, 19 Jun 2013 14:11:30 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id 9804B20101 for ; Wed, 19 Jun 2013 14:11:21 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S934447Ab3FSOLP (ORCPT ); Wed, 19 Jun 2013 10:11:15 -0400 Received: from mailout3.w1.samsung.com ([210.118.77.13]:24030 "EHLO mailout3.w1.samsung.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1756427Ab3FSOLN (ORCPT ); Wed, 19 Jun 2013 10:11:13 -0400 Received: from eucpsbgm2.samsung.com (unknown [203.254.199.245]) by mailout3.w1.samsung.com (Oracle Communications Messaging Server 7u4-24.01(7.0.4.24.0) 64bit (built Nov 17 2011)) with ESMTP id <0MON0071O8QDFEE0@mailout3.w1.samsung.com> for linux-media@vger.kernel.org; Wed, 19 Jun 2013 15:11:10 +0100 (BST) X-AuditID: cbfec7f5-b7f376d000001ec6-62-51c1bbfe3c9f Received: from eusync3.samsung.com ( [203.254.199.213]) by eucpsbgm2.samsung.com (EUCPMTA) with SMTP id 7A.4E.07878.EFBB1C15; Wed, 19 Jun 2013 15:11:10 +0100 (BST) Received: from AMDC1061.digital.local ([106.116.147.88]) by eusync3.samsung.com (Oracle Communications Messaging Server 7u4-23.01 (7.0.4.23.0) 64bit (built Aug 10 2011)) with ESMTPA id <0MON00DE48QEF640@eusync3.samsung.com>; Wed, 19 Jun 2013 15:11:10 +0100 (BST) From: Andrzej Hajda To: laurent.pinchart@ideasonboard.com Cc: Andrzej Hajda , linux-media@vger.kernel.org, Sylwester Nawrocki , Sakari Ailus , Kyungmin Park , hj210.choi@samsung.com, sw0312.kim@samsung.com Subject: [PATCH RFC v4] media: added managed v4l2/i2c subdevice initialization Date: Wed, 19 Jun 2013 16:10:54 +0200 Message-id: <1371651054-28684-1-git-send-email-a.hajda@samsung.com> X-Mailer: git-send-email 1.8.1.2 In-reply-to: <4084534.7DE24ipEqE@avalon> References: <4084534.7DE24ipEqE@avalon> X-Brightmail-Tracker: H4sIAAAAAAAAA+NgFvrGJMWRmVeSWpSXmKPExsVy+t/xq7r/dh8MNJhwUd/i1rpzrBaPN15j tjjb9IbdonPiEnaLng1bWS0Ov2lntTizfyWbxYzJL9kcODxmd8xk9Tj8dSGLR9+WVYwenzfJ BbBEcdmkpOZklqUW6dslcGXcmdDFWPBZvuJ/7wPmBsY26S5GTg4JAROJDUtWMEPYYhIX7q1n 62Lk4hASWMoo8fnCTBYIp49J4vf90+wgVWwCmhJ/N98EquLgEBFQlZh1igmkhlngG6PEvf7J rCA1wgJ+EmeWr2UDsVmAaiYfus0EYvMKOEusOXUZapuCxM/LJ8BqOAU0JJrbVrKA2EIC6hKN y2+xT2DkXcDIsIpRNLU0uaA4KT3XSK84Mbe4NC9dLzk/dxMjJKy+7mBceszqEKMAB6MSD+9M zoOBQqyJZcWVuYcYJTiYlUR4u3YBhXhTEiurUovy44tKc1KLDzEycXBKNTDu+rfBf+dCjv69 ORefsIW7TWoTEP0swPKsvvmcwlGGa1HZP487WXbyJbkKcerdTv+Ve39CUYT4vOhon863V7w0 Wc4JxViE7PvvtvzDBg2dPWVGsc4vE8t7DRYoCPF+3vNpzibHneuYNX//Kec8Uy72/Z4KD99u Md0z11pmelztUbs9Nf2INYcSS3FGoqEWc1FxIgDEyWbiCQIAAA== Sender: linux-media-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-media@vger.kernel.org X-Spam-Status: No, score=-8.2 required=5.0 tests=BAYES_00, RCVD_IN_DNSWL_HI, RP_MATCHES_RCVD, UNPARSEABLE_RELAY autolearn=unavailable version=3.3.1 X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on mail.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP This patch adds managed version of initialization function for v4l2 i2c subdevices. Signed-off-by: Andrzej Hajda Reviewed-by: Sylwester Nawrocki Signed-off-by: Kyungmin Park Acked-by: Hans Verkuil --- v4: - added description to devm_v4l2_subdev_bind v3: - removed devm_v4l2_subdev_(init|free), v2: - changes of v4l2-ctrls.h moved to proper patch --- drivers/media/v4l2-core/v4l2-common.c | 10 ++++++++++ drivers/media/v4l2-core/v4l2-subdev.c | 35 +++++++++++++++++++++++++++++++++++ include/media/v4l2-common.h | 2 ++ include/media/v4l2-subdev.h | 2 ++ 4 files changed, 49 insertions(+) diff --git a/drivers/media/v4l2-core/v4l2-common.c b/drivers/media/v4l2-core/v4l2-common.c index 3fed63f..96aac931 100644 --- a/drivers/media/v4l2-core/v4l2-common.c +++ b/drivers/media/v4l2-core/v4l2-common.c @@ -301,7 +301,17 @@ void v4l2_i2c_subdev_init(struct v4l2_subdev *sd, struct i2c_client *client, } EXPORT_SYMBOL_GPL(v4l2_i2c_subdev_init); +int devm_v4l2_i2c_subdev_init(struct v4l2_subdev *sd, struct i2c_client *client, + const struct v4l2_subdev_ops *ops) +{ + int ret; + ret = devm_v4l2_subdev_bind(&client->dev, sd); + if (!ret) + v4l2_i2c_subdev_init(sd, client, ops); + return ret; +} +EXPORT_SYMBOL_GPL(devm_v4l2_i2c_subdev_init); /* Load an i2c sub-device. */ struct v4l2_subdev *v4l2_i2c_new_subdev_board(struct v4l2_device *v4l2_dev, diff --git a/drivers/media/v4l2-core/v4l2-subdev.c b/drivers/media/v4l2-core/v4l2-subdev.c index 996c248..2242962 100644 --- a/drivers/media/v4l2-core/v4l2-subdev.c +++ b/drivers/media/v4l2-core/v4l2-subdev.c @@ -474,3 +474,38 @@ void v4l2_subdev_init(struct v4l2_subdev *sd, const struct v4l2_subdev_ops *ops) #endif } EXPORT_SYMBOL(v4l2_subdev_init); + +static void devm_v4l2_subdev_release(struct device *dev, void *res) +{ + struct v4l2_subdev **sd = res; + + v4l2_device_unregister_subdev(*sd); +#if defined(CONFIG_MEDIA_CONTROLLER) + media_entity_cleanup(&(*sd)->entity); +#endif +} + +/** + * devm_v4l2_subdev_bind - Add subdevice to device managed resource list + * @dev: Device to bind subdev to + * @sd: Subdevice to bind + * + * Function adds device managed release code to the subdev. + * If the function succeedes then on driver detach subdev will be automatically + * unregistered and the media entity will be cleaned up. Function can be used + * with subdevs not initialized by devm_v4l2_i2c_subdev_init. + */ +int devm_v4l2_subdev_bind(struct device *dev, struct v4l2_subdev *sd) +{ + struct v4l2_subdev **dr; + + dr = devres_alloc(devm_v4l2_subdev_release, sizeof(*dr), GFP_KERNEL); + if (!dr) + return -ENOMEM; + + *dr = sd; + devres_add(dev, dr); + + return 0; +} +EXPORT_SYMBOL(devm_v4l2_subdev_bind); diff --git a/include/media/v4l2-common.h b/include/media/v4l2-common.h index 1d93c48..da62e2b 100644 --- a/include/media/v4l2-common.h +++ b/include/media/v4l2-common.h @@ -136,6 +136,8 @@ struct v4l2_subdev *v4l2_i2c_new_subdev_board(struct v4l2_device *v4l2_dev, /* Initialize a v4l2_subdev with data from an i2c_client struct */ void v4l2_i2c_subdev_init(struct v4l2_subdev *sd, struct i2c_client *client, const struct v4l2_subdev_ops *ops); +int devm_v4l2_i2c_subdev_init(struct v4l2_subdev *sd, struct i2c_client *client, + const struct v4l2_subdev_ops *ops); /* Return i2c client address of v4l2_subdev. */ unsigned short v4l2_i2c_subdev_addr(struct v4l2_subdev *sd); diff --git a/include/media/v4l2-subdev.h b/include/media/v4l2-subdev.h index 5298d67..e086cfe 100644 --- a/include/media/v4l2-subdev.h +++ b/include/media/v4l2-subdev.h @@ -657,6 +657,8 @@ int v4l2_subdev_link_validate(struct media_link *link); void v4l2_subdev_init(struct v4l2_subdev *sd, const struct v4l2_subdev_ops *ops); +int devm_v4l2_subdev_bind(struct device *dev, struct v4l2_subdev *sd); + /* Call an ops of a v4l2_subdev, doing the right checks against NULL pointers.