From patchwork Mon May 13 08:34:46 2013 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Andrzej Hajda X-Patchwork-Id: 2557021 Return-Path: X-Original-To: patchwork-linux-media@patchwork.kernel.org Delivered-To: patchwork-process-083081@patchwork1.kernel.org Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by patchwork1.kernel.org (Postfix) with ESMTP id D80AF3FC5A for ; Mon, 13 May 2013 08:35:16 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1754289Ab3EMIfN (ORCPT ); Mon, 13 May 2013 04:35:13 -0400 Received: from mailout2.w1.samsung.com ([210.118.77.12]:29911 "EHLO mailout2.w1.samsung.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1754272Ab3EMIfH (ORCPT ); Mon, 13 May 2013 04:35:07 -0400 Received: from eucpsbgm1.samsung.com (unknown [203.254.199.244]) by mailout2.w1.samsung.com (Oracle Communications Messaging Server 7u4-24.01(7.0.4.24.0) 64bit (built Nov 17 2011)) with ESMTP id <0MMQ00GKVAHC0O70@mailout2.w1.samsung.com> for linux-media@vger.kernel.org; Mon, 13 May 2013 09:35:05 +0100 (BST) X-AuditID: cbfec7f4-b7fd76d0000035e1-ed-5190a5b94ae8 Received: from eusync2.samsung.com ( [203.254.199.212]) by eucpsbgm1.samsung.com (EUCPMTA) with SMTP id 00.B7.13793.9B5A0915; Mon, 13 May 2013 09:35:05 +0100 (BST) Received: from AMDC1061.digital.local ([106.116.147.88]) by eusync2.samsung.com (Oracle Communications Messaging Server 7u4-23.01 (7.0.4.23.0) 64bit (built Aug 10 2011)) with ESMTPA id <0MMQ005DPAIAQNB0@eusync2.samsung.com>; Mon, 13 May 2013 09:35:04 +0100 (BST) From: Andrzej Hajda To: linux-media@vger.kernel.org Cc: Laurent Pinchart , Sylwester Nawrocki , Sakari Ailus , Kyungmin Park , hj210.choi@samsung.com, sw0312.kim@samsung.com, Andrzej Hajda Subject: [PATCH RFC v2 3/3] media: added managed v4l2 subdevice initialization Date: Mon, 13 May 2013 10:34:46 +0200 Message-id: <1368434086-9027-4-git-send-email-a.hajda@samsung.com> X-Mailer: git-send-email 1.7.10.4 In-reply-to: <1368434086-9027-1-git-send-email-a.hajda@samsung.com> References: <1368434086-9027-1-git-send-email-a.hajda@samsung.com> X-Brightmail-Tracker: H4sIAAAAAAAAA+NgFvrGJMWRmVeSWpSXmKPExsVy+t/xK7o7l04INLj4l9Hi1rpzrBaPN15j tjjb9IbdonPiEnaLng1bWS0Ov2lntTizfyWbxYzJL9kcODxmd8xk9Tj8dSGLR9+WVYwenzfJ BbBEcdmkpOZklqUW6dslcGVsvLySvWCfUsXaxRfYGxjnynYxcnJICJhInHnxnRHCFpO4cG89 WxcjF4eQwFJGiSdNR1kgnD4midZpG5hBqtgENCX+br7JBmKLCMhLPOm9AdbBLDCRSeLq32VA DgeHsICfxPnFciA1LAKqEu1NF9lBbF4BJ4kZr28wQWxTlOh+NgFsDqeAs8SBLQ/AbCGgmrMf 7jJOYORdwMiwilE0tTS5oDgpPddQrzgxt7g0L10vOT93EyMkrL7sYFx8zOoQowAHoxIPr6fi hEAh1sSy4srcQ4wSHMxKIrxJ84FCvCmJlVWpRfnxRaU5qcWHGJk4OKUaGKtanj4/xzNL2vVZ VYOT3U6/CdlLz0avfZq4YKrTggqbadlq0r9EtTkeFp+aGt8mYfv4+taPJ2ZcWPi5MNP0essd njP3LKzqQhLORFkc5s93bTO6ce5lVvdPLtvPT4O5kpQ8N7i/tzePdLkiImPzKqTZQVeASdXO 4uCGJH++uKhNdr6L7N4HKbEUZyQaajEXFScCAI5drCMJAgAA Sender: linux-media-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-media@vger.kernel.org This patch adds managed versions of initialization functions for v4l2 subdevices. Signed-off-by: Andrzej Hajda Reviewed-by: Sylwester Nawrocki Signed-off-by: Kyungmin Park --- 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 | 52 +++++++++++++++++++++++++++++++++ include/media/v4l2-common.h | 2 ++ include/media/v4l2-subdev.h | 5 ++++ 4 files changed, 69 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..87ce2f6 100644 --- a/drivers/media/v4l2-core/v4l2-subdev.c +++ b/drivers/media/v4l2-core/v4l2-subdev.c @@ -474,3 +474,55 @@ 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 +} + +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); + +int devm_v4l2_subdev_init(struct device *dev, struct v4l2_subdev *sd, + const struct v4l2_subdev_ops *ops) +{ + int ret; + + ret = devm_v4l2_subdev_bind(dev, sd); + if (!ret) + v4l2_subdev_init(sd, ops); + return ret; +} +EXPORT_SYMBOL(devm_v4l2_subdev_init); + +static int devm_v4l2_subdev_match(struct device *dev, void *res, + void *data) +{ + struct v4l2_subdev **this = res, **sd = data; + + return *this == *sd; +} + +void devm_v4l2_subdev_free(struct device *dev, struct v4l2_subdev *sd) +{ + WARN_ON(devres_release(dev, devm_v4l2_subdev_release, + devm_v4l2_subdev_match, &sd)); +} +EXPORT_SYMBOL_GPL(devm_v4l2_subdev_free); 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..881abdd 100644 --- a/include/media/v4l2-subdev.h +++ b/include/media/v4l2-subdev.h @@ -657,6 +657,11 @@ 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); +int devm_v4l2_subdev_init(struct device *dev, struct v4l2_subdev *sd, + const struct v4l2_subdev_ops *ops); +void devm_v4l2_subdev_free(struct device *dev, struct v4l2_subdev *sd); + /* Call an ops of a v4l2_subdev, doing the right checks against NULL pointers.