From patchwork Wed Jun 3 15:12:53 2015 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Shuah Khan X-Patchwork-Id: 6539221 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.29.136]) by patchwork2.web.kernel.org (Postfix) with ESMTP id 2583CC0020 for ; Wed, 3 Jun 2015 15:13:14 +0000 (UTC) Received: from mail.kernel.org (localhost [127.0.0.1]) by mail.kernel.org (Postfix) with ESMTP id 4CCF920690 for ; Wed, 3 Jun 2015 15:13:13 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id 48CA82069A for ; Wed, 3 Jun 2015 15:13:11 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S964823AbbFCPNI (ORCPT ); Wed, 3 Jun 2015 11:13:08 -0400 Received: from resqmta-po-12v.sys.comcast.net ([96.114.154.171]:34652 "EHLO resqmta-po-12v.sys.comcast.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S933298AbbFCPNH (ORCPT ); Wed, 3 Jun 2015 11:13:07 -0400 Received: from resomta-po-04v.sys.comcast.net ([96.114.154.228]) by resqmta-po-12v.sys.comcast.net with comcast id brCa1q00B4vw8ds01rD6Fd; Wed, 03 Jun 2015 15:13:06 +0000 Received: from mail.gonehiking.org ([73.181.52.62]) by resomta-po-04v.sys.comcast.net with comcast id brD41q00f1LXgTt01rD5Fo; Wed, 03 Jun 2015 15:13:06 +0000 Received: from lorien.internal (lorien-wl.internal [192.168.1.40]) by mail.gonehiking.org (Postfix) with ESMTP id A996D3FEB9; Wed, 3 Jun 2015 09:13:04 -0600 (MDT) From: Shuah Khan To: mchehab@osg.samsung.com, hans.verkuil@cisco.com, laurent.pinchart@ideasonboard.com, tiwai@suse.de, perex@perex.cz, agoode@google.com, pierre-louis.bossart@linux.intel.com, gtmkramer@xs4all.nl, clemens@ladisch.de, vladcatoi@gmail.com, damien@zamaudio.com, chris.j.arges@canonical.com, takamichiho@gmail.com, misterpib@gmail.com, daniel@zonque.org, pmatilai@laiskiainen.org, jussi@sonarnerd.net, normalperson@yhbt.net, fisch602@gmail.com, joe@oampo.co.uk Cc: Shuah Khan , linux-media@vger.kernel.org, alsa-devel@alsa-project.org Subject: [PATCH v2 1/2] media: new media controller API for device resource support Date: Wed, 3 Jun 2015 09:12:53 -0600 Message-Id: <155108c510e84206d3e5140e2e9a96336413f375.1433298842.git.shuahkh@osg.samsung.com> X-Mailer: git-send-email 2.1.4 In-Reply-To: References: In-Reply-To: References: DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=comcast.net; s=q20140121; t=1433344386; bh=S66tWN5I6ylUnCZa0R5i9tSm5A07DvCCTxGK6CejClk=; h=Received:Received:Received:From:To:Subject:Date:Message-Id; b=SQyCR/4ZX/D44DCVUPEuFCskylyjXgiyBfw9CplkSb7cLGBlu8pBt5w6JJI0ioK2F gSAM3Gxxeocn12ynlWj2tITGYN9C0Yl2xtQr7sjB4nzTkfax5Rqu/LBYyC3L5TOF70 SWHwf98STKLYk9VcuiTMr3HK9oxDkTqzKb0O9s1HHYheQ8j+GeLVY+VmxVq00/1TzV 1z29I7OlxIzqVZT5u6P37W+BbtdYS9Kw05rgHBH9D5dyAbw5yHSzFUbxwb6OqR/eAa uh1VR/nbCPm6Q2YdsRzKhh5S022Ftd9tobLBC6umQfFqm9DNU/EaeGVnfYF25xv/lt NXAldWIYLnkaQ== Sender: linux-media-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-media@vger.kernel.org X-Spam-Status: No, score=-6.8 required=5.0 tests=BAYES_00,DKIM_SIGNED, RCVD_IN_DNSWL_HI,T_DKIM_INVALID,T_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 Add new media controller API to allocate media device as a device resource. When a media device is created on the main struct device which is the parent device for the interface device, it will be available to all drivers associated with that interface. For example, if a usb media device driver creates the media device on the main struct device which is common for all the drivers that control the media device, including the non-media ALSA driver, media controller API can be used to share access to the resources on the media device. This new interface provides the above described feature. A second interface that finds and returns the media device is added to allow drivers to find the media device created by any of the drivers associated with the device. Signed-off-by: Shuah Khan --- drivers/media/media-device.c | 33 +++++++++++++++++++++++++++++++++ include/media/media-device.h | 2 ++ 2 files changed, 35 insertions(+) diff --git a/drivers/media/media-device.c b/drivers/media/media-device.c index 7b39440..a4d5b24 100644 --- a/drivers/media/media-device.c +++ b/drivers/media/media-device.c @@ -462,3 +462,36 @@ void media_device_unregister_entity(struct media_entity *entity) entity->parent = NULL; } EXPORT_SYMBOL_GPL(media_device_unregister_entity); + +static void media_device_release_devres(struct device *dev, void *res) +{ +} + +/* + * media_device_get_devres() - get media device as device resource + * creates if one doesn't exist +*/ +struct media_device *media_device_get_devres(struct device *dev) +{ + struct media_device *mdev; + + mdev = devres_find(dev, media_device_release_devres, NULL, NULL); + if (mdev) + return mdev; + + mdev = devres_alloc(media_device_release_devres, + sizeof(struct media_device), GFP_KERNEL); + if (!mdev) + return NULL; + return devres_get(dev, mdev, NULL, NULL); +} +EXPORT_SYMBOL_GPL(media_device_get_devres); + +/* + * media_device_find_devres() - find media device as device resource +*/ +struct media_device *media_device_find_devres(struct device *dev) +{ + return devres_find(dev, media_device_release_devres, NULL, NULL); +} +EXPORT_SYMBOL_GPL(media_device_find_devres); diff --git a/include/media/media-device.h b/include/media/media-device.h index 6e6db78..22792cd 100644 --- a/include/media/media-device.h +++ b/include/media/media-device.h @@ -95,6 +95,8 @@ void media_device_unregister(struct media_device *mdev); int __must_check media_device_register_entity(struct media_device *mdev, struct media_entity *entity); void media_device_unregister_entity(struct media_entity *entity); +struct media_device *media_device_get_devres(struct device *dev); +struct media_device *media_device_find_devres(struct device *dev); /* Iterate over all entities. */ #define media_device_for_each_entity(entity, mdev) \