diff mbox

[v2,1/2] media: new media controller API for device resource support

Message ID 155108c510e84206d3e5140e2e9a96336413f375.1433298842.git.shuahkh@osg.samsung.com (mailing list archive)
State New, archived
Headers show

Commit Message

Shuah Khan June 3, 2015, 3:12 p.m. UTC
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 <shuahkh@osg.samsung.com>
---
 drivers/media/media-device.c | 33 +++++++++++++++++++++++++++++++++
 include/media/media-device.h |  2 ++
 2 files changed, 35 insertions(+)

Comments

Mauro Carvalho Chehab June 3, 2015, 5:42 p.m. UTC | #1
Em Wed, 03 Jun 2015 09:12:53 -0600
Shuah Khan <shuahkh@osg.samsung.com> escreveu:

> 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 <shuahkh@osg.samsung.com>
> ---
>  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);

Hmm... what happens if the Kernel is compiled without MC controller
support?

I think that the best would be to add a #ifdef at the header file and
provide an alternate dummy method to avoid the need of testing for it
everywhere.

>  
>  /* Iterate over all entities. */
>  #define media_device_for_each_entity(entity, mdev)			\
--
To unsubscribe from this list: send the line "unsubscribe linux-media" in
the body of a message to majordomo@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Shuah Khan June 3, 2015, 6:14 p.m. UTC | #2
On 06/03/2015 11:42 AM, Mauro Carvalho Chehab wrote:
> Em Wed, 03 Jun 2015 09:12:53 -0600
> Shuah Khan <shuahkh@osg.samsung.com> escreveu:
> 
>> 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 <shuahkh@osg.samsung.com>
>> ---
>>  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);
> 
> Hmm... what happens if the Kernel is compiled without MC controller
> support?

Yeah. I noticed media controller api users have the code in ifdef
CONFIG_MEDIA_CONTROLLER.

> 
> I think that the best would be to add a #ifdef at the header file and
> provide an alternate dummy method to avoid the need of testing for it
> everywhere.
> 

I agree with you that a better way to do it would be defining media
controller api in ifdef CONFIG_MEDIA_CONTROLLER and provide stubs for
else case, similar to what I did in sound/usb/media.c

I followed the existing code to add new interfaces. Do you want to see
all media controller interfaces in ifdef clause with stubs or just the
two new interfaces I added? Or is this something that should be done as
a separate change to catch all media controller interfaces?

thanks,
-- Shuah
Mauro Carvalho Chehab June 3, 2015, 6:55 p.m. UTC | #3
Em Wed, 03 Jun 2015 12:14:09 -0600
Shuah Khan <shuahkh@osg.samsung.com> escreveu:

> On 06/03/2015 11:42 AM, Mauro Carvalho Chehab wrote:
> > Em Wed, 03 Jun 2015 09:12:53 -0600
> > Shuah Khan <shuahkh@osg.samsung.com> escreveu:
> > 
> >> 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 <shuahkh@osg.samsung.com>
> >> ---
> >>  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);
> > 
> > Hmm... what happens if the Kernel is compiled without MC controller
> > support?
> 
> Yeah. I noticed media controller api users have the code in ifdef
> CONFIG_MEDIA_CONTROLLER.
> 
> > 
> > I think that the best would be to add a #ifdef at the header file and
> > provide an alternate dummy method to avoid the need of testing for it
> > everywhere.
> > 
> 
> I agree with you that a better way to do it would be defining media
> controller api in ifdef CONFIG_MEDIA_CONTROLLER and provide stubs for
> else case, similar to what I did in sound/usb/media.c
> 
> I followed the existing code to add new interfaces. Do you want to see
> all media controller interfaces in ifdef clause with stubs or just the
> two new interfaces I added? Or is this something that should be done as
> a separate change to catch all media controller interfaces?

It could be on a separate patch. IMHO, the best is to put all defines
on stubs.

> 
> thanks,
> -- Shuah
> 
--
To unsubscribe from this list: send the line "unsubscribe linux-media" in
the body of a message to majordomo@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
diff mbox

Patch

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)			\