Re: Call for help: em28xx: new board id [1f4d:1abe]

2015-09-06 Thread Ronald Tallent
Hey Mauro,

Thanks for the reply. Relieved to know I'm not invisible. =)

I'm a total noob to linux driver issues, so if I'm  posting this in the
wrong area, please forgive me. I only posted here because this is where
linuxtv.org said to go to ask for help. Until now all my hardware has
just worked. So big thanks to all the people who made that happen! But
this EasyCap board is kind of kicking my butt.

You are correct, when I plug this USB device in video capture device is
not detected and so does not work. As I understand it, all the drivers
needed to make this Easycap work in linux already exist and are used by
various forms of Easycap devices already.

The em2860 USB video bridge chip should be supported by the "em28xx"
kernel modules, and the Trident SAA7115H chip should be supported by the
"saa7115" module. My best guess is that the card vendor:product id
[1f4d:1abe] is simply not "attached" to those drivers or known by those
drivers so when I plug this USB device in, video drivers are not loaded.
But my assessment of the situation might be completely off here.

Couple questions...

First, if nobody know what to do with the information I've posted, why
does linuxtv.org/wiki instruct me to post this information here, exactly
this way? Not a big issue really, just quite confusing.

Secondly, if all the drivers already exist, what do I need to do to get
them to "attach" to my hardware? Is there some place I can go to learn
how to do that fairly quickly? Is anyone in this board knowledgeable
about how that can easily be done? I am competent enough with linux that
I can perform the steps necessary if I know what those steps are. This
is new territory for me though.

Any help anyone can offer would be greatly appreciated! =)

Thanks,
--Ronald



On Sun, 2015-09-06 at 16:53 -0300, Mauro Carvalho Chehab wrote:
> Hi Ronald,
> 
> Well, probably nobody knows what to do with that ;)
> 
> If I understood well your post, video didn't work, right?
> 
> So, either you or someone else with the same hardware as you have would
> need to make it work and send a patch to the mailing list adding support
> for this new ID.
> 
> Probably, it is just either a GPIO or the video input that it is wrong.
> In order to fix it, you would either need some help from the manufacturer
> or to sniff the USB message exchanges from the original driver and check
> the settings for saa7113 and em28xx. The wiki has some info about how
> to do it.
> 
> Regards,
> Mauro
> 
> 
> Em Sun, 06 Sep 2015 14:16:48 -0500
> Ronald Tallent  escreveu:
> 
> > Hi, 
> > 
> > This is my third attempt to post this information to mailing list in a
> > little over a week. Am I invisible? Can nobody see my messages? I have
> > precisely followed the instructions posted on
> > linuxtv.org/wiki/index.php/Em28xx_devices#How_to_validate_my_vendor.2Fproduct_id_at_upstream_kernel.3F
> > trying to get my hardware validated. What else do I need to do?  Can
> > someone answer please and help me. 
> > 
> > Thanks,
> > --Ronald
> > 
> > 
> > I've tested my USB easycap device (Geniatech iGrabber) in Ubuntu
> > 14.04.
> > 
> > Make: Geniatech
> > Model: iGrabber for MAC
> > Vendor/Product ID: [1f4d:1abe]
> > Product website: www.geniatech.com/pa/igrabber.asp
> > 
> > Tests Made:
> > - Audio Capture [worked]
> > - Video Capture [device not detected]
> > - DVB [does not have DVB]
> > 
> > Tested by:
> > r...@tallent.ws
> > 
> > 
> > Detailed information on device and system below for reference:
> > 
> > uname -a:
> > 3.13.0-62-generic #102-Ubuntu SMP Tue Aug 11 14:29:36 UTC 2015 x86_64 
> > x86_64 x86_64 GNU/Linux
> > 
> > dmesg:
> > [] usb 3-3.3: new high-speed USB device number 8 using xhci_hcd
> > [] usb 3-3.3: New USB device found, idVendor=1f4d, idProduct=1abe
> > [] usb 3-3.3: New USB device strings: Mfr=0, Product=1, SerialNumber=0
> > [] usb 3-3.3: Product: USB Device
> > [] usbcore: registered new interface driver snd-usb-audio
> > 
> > lsusb:
> > Bus 003 Device 008: ID 1f4d:1abe G-Tek Electronics Group 
> > 
> > Hardware: 
> > Opened the case and found the following text printed on the board:
> >HandyCap
> >v1.51
> >2007-4-24
> > 
> > Three chips on board are:
> > 1: empia
> >EM2860
> >P8367-010
> >201036-01AG
> > 
> > 2: Trident
> >SAA7113H
> >C2P409.00 02
> >A5G11152
> > 
> > 3: eMPIA
> >Technology
> >EMP202
> >UT11958
> >1027
> > 
> > 
> > --
> > To unsubscribe from this list: send the line "unsubscribe linux-media" in
> > the body of a message to majord...@vger.kernel.org
> > More majordomo info at  http://vger.kernel.org/majordomo-info.html
> --
> To unsubscribe from this list: send the line "unsubscribe linux-media" in
> the body of a message to majord...@vger.kernel.org
> More majordomo info at  http://vger.kernel.org/majordomo-info.html


--
To unsubscribe from this list: send the line "unsubscribe linux-media" in
the body of a message to majord...@vger.kernel.org
More majordomo info at  

cron job: media_tree daily build: OK

2015-09-06 Thread Hans Verkuil
This message is generated daily by a cron job that builds media_tree for
the kernels and architectures in the list below.

Results of the daily build of media_tree:

date:   Mon Sep  7 04:00:16 CEST 2015
git branch: test
git hash:   50ef28a6ac216fd8b796257a3768fef8f57b917d
gcc version:i686-linux-gcc (GCC) 5.1.0
sparse version: v0.5.0-51-ga53cea2
smatch version: 0.4.1-3153-g7d56ab3
host hardware:  x86_64
host os:4.0.0-3.slh.1-amd64

linux-git-arm-at91: OK
linux-git-arm-davinci: OK
linux-git-arm-exynos: OK
linux-git-arm-mx: OK
linux-git-arm-omap: OK
linux-git-arm-omap1: OK
linux-git-arm-pxa: OK
linux-git-blackfin-bf561: OK
linux-git-i686: OK
linux-git-m32r: OK
linux-git-mips: OK
linux-git-powerpc64: OK
linux-git-sh: OK
linux-git-x86_64: OK
linux-2.6.32.27-i686: OK
linux-2.6.33.7-i686: OK
linux-2.6.34.7-i686: OK
linux-2.6.35.9-i686: OK
linux-2.6.36.4-i686: OK
linux-2.6.37.6-i686: OK
linux-2.6.38.8-i686: OK
linux-2.6.39.4-i686: OK
linux-3.0.60-i686: OK
linux-3.1.10-i686: OK
linux-3.2.37-i686: OK
linux-3.3.8-i686: OK
linux-3.4.27-i686: OK
linux-3.5.7-i686: OK
linux-3.6.11-i686: OK
linux-3.7.4-i686: OK
linux-3.8-i686: OK
linux-3.9.2-i686: OK
linux-3.10.1-i686: OK
linux-3.11.1-i686: OK
linux-3.12.23-i686: OK
linux-3.13.11-i686: OK
linux-3.14.9-i686: OK
linux-3.15.2-i686: OK
linux-3.16.7-i686: OK
linux-3.17.8-i686: OK
linux-3.18.7-i686: OK
linux-3.19-i686: OK
linux-4.0-i686: OK
linux-4.1.1-i686: OK
linux-4.2-i686: OK
linux-2.6.32.27-x86_64: OK
linux-2.6.33.7-x86_64: OK
linux-2.6.34.7-x86_64: OK
linux-2.6.35.9-x86_64: OK
linux-2.6.36.4-x86_64: OK
linux-2.6.37.6-x86_64: OK
linux-2.6.38.8-x86_64: OK
linux-2.6.39.4-x86_64: OK
linux-3.0.60-x86_64: OK
linux-3.1.10-x86_64: OK
linux-3.2.37-x86_64: OK
linux-3.3.8-x86_64: OK
linux-3.4.27-x86_64: OK
linux-3.5.7-x86_64: OK
linux-3.6.11-x86_64: OK
linux-3.7.4-x86_64: OK
linux-3.8-x86_64: OK
linux-3.9.2-x86_64: OK
linux-3.10.1-x86_64: OK
linux-3.11.1-x86_64: OK
linux-3.12.23-x86_64: OK
linux-3.13.11-x86_64: OK
linux-3.14.9-x86_64: OK
linux-3.15.2-x86_64: OK
linux-3.16.7-x86_64: OK
linux-3.17.8-x86_64: OK
linux-3.18.7-x86_64: OK
linux-3.19-x86_64: OK
linux-4.0-x86_64: OK
linux-4.1.1-x86_64: OK
linux-4.2-x86_64: OK
apps: OK
spec-git: OK
sparse: WARNINGS
smatch: ERRORS

Detailed results are available here:

http://www.xs4all.nl/~hverkuil/logs/Monday.log

Full logs are available here:

http://www.xs4all.nl/~hverkuil/logs/Monday.tar.bz2

The Media Infrastructure API from this daily build is here:

http://www.xs4all.nl/~hverkuil/spec/media.html
--
To unsubscribe from this list: send the line "unsubscribe linux-media" in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html


Re: 3rd posting: em28xx: new board id [1f4d:1abe]

2015-09-06 Thread Mauro Carvalho Chehab
Hi Ronald,

Well, probably nobody knows what to do with that ;)

If I understood well your post, video didn't work, right?

So, either you or someone else with the same hardware as you have would
need to make it work and send a patch to the mailing list adding support
for this new ID.

Probably, it is just either a GPIO or the video input that it is wrong.
In order to fix it, you would either need some help from the manufacturer
or to sniff the USB message exchanges from the original driver and check
the settings for saa7113 and em28xx. The wiki has some info about how
to do it.

Regards,
Mauro


Em Sun, 06 Sep 2015 14:16:48 -0500
Ronald Tallent  escreveu:

> Hi, 
> 
> This is my third attempt to post this information to mailing list in a
> little over a week. Am I invisible? Can nobody see my messages? I have
> precisely followed the instructions posted on
> linuxtv.org/wiki/index.php/Em28xx_devices#How_to_validate_my_vendor.2Fproduct_id_at_upstream_kernel.3F
> trying to get my hardware validated. What else do I need to do?  Can
> someone answer please and help me. 
> 
> Thanks,
> --Ronald
> 
> 
> I've tested my USB easycap device (Geniatech iGrabber) in Ubuntu
> 14.04.
> 
> Make: Geniatech
> Model: iGrabber for MAC
> Vendor/Product ID: [1f4d:1abe]
> Product website: www.geniatech.com/pa/igrabber.asp
> 
> Tests Made:
> - Audio Capture [worked]
> - Video Capture [device not detected]
> - DVB [does not have DVB]
> 
> Tested by:
> r...@tallent.ws
> 
> 
> Detailed information on device and system below for reference:
> 
> uname -a:
> 3.13.0-62-generic #102-Ubuntu SMP Tue Aug 11 14:29:36 UTC 2015 x86_64 
> x86_64 x86_64 GNU/Linux
> 
> dmesg:
> [] usb 3-3.3: new high-speed USB device number 8 using xhci_hcd
> [] usb 3-3.3: New USB device found, idVendor=1f4d, idProduct=1abe
> [] usb 3-3.3: New USB device strings: Mfr=0, Product=1, SerialNumber=0
> [] usb 3-3.3: Product: USB Device
> [] usbcore: registered new interface driver snd-usb-audio
> 
> lsusb:
> Bus 003 Device 008: ID 1f4d:1abe G-Tek Electronics Group 
> 
> Hardware: 
> Opened the case and found the following text printed on the board:
>HandyCap
>v1.51
>2007-4-24
> 
> Three chips on board are:
> 1: empia
>EM2860
>P8367-010
>201036-01AG
> 
> 2: Trident
>SAA7113H
>C2P409.00 02
>A5G11152
> 
> 3: eMPIA
>Technology
>EMP202
>UT11958
>1027
> 
> 
> --
> To unsubscribe from this list: send the line "unsubscribe linux-media" in
> the body of a message to majord...@vger.kernel.org
> More majordomo info at  http://vger.kernel.org/majordomo-info.html
--
To unsubscribe from this list: send the line "unsubscribe linux-media" in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html


Re: [PATCH] [media] atmel-isi: Protect PM-only functions to kill warning

2015-09-06 Thread Josh Wu

Hi, Geert Uytterhoeven

Thanks for the patch.

On 9/6/2015 6:08 PM, Geert Uytterhoeven wrote:

If CONFIG_PM=n:

 drivers/media/platform/soc_camera/atmel-isi.c:1044: warning: 
‘atmel_isi_runtime_suspend’ defined but not used
 drivers/media/platform/soc_camera/atmel-isi.c:1054: warning: 
‘atmel_isi_runtime_resume’ defined but not used

Protect the unused functions by #ifdef CONFIG_PM to fix this.

Signed-off-by: Geert Uytterhoeven 


Acked-by: Josh Wu 

Best Regards,
Josh Wu


---
Resend with correct suject
---
  drivers/media/platform/soc_camera/atmel-isi.c | 2 ++
  1 file changed, 2 insertions(+)

diff --git a/drivers/media/platform/soc_camera/atmel-isi.c 
b/drivers/media/platform/soc_camera/atmel-isi.c
index 90701726a06a2e5c..ccf30ccbe389233f 100644
--- a/drivers/media/platform/soc_camera/atmel-isi.c
+++ b/drivers/media/platform/soc_camera/atmel-isi.c
@@ -1040,6 +1040,7 @@ err_alloc_ctx:
return ret;
  }
  
+#ifdef CONFIG_PM

  static int atmel_isi_runtime_suspend(struct device *dev)
  {
struct soc_camera_host *soc_host = to_soc_camera_host(dev);
@@ -1058,6 +1059,7 @@ static int atmel_isi_runtime_resume(struct device *dev)
  
  	return clk_prepare_enable(isi->pclk);

  }
+#endif /* CONFIG_PM */
  
  static const struct dev_pm_ops atmel_isi_dev_pm_ops = {

SET_RUNTIME_PM_OPS(atmel_isi_runtime_suspend,


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


[PATCH] [media] atmel-isi: Protect PM-only functions to kill warning

2015-09-06 Thread Geert Uytterhoeven
If CONFIG_PM=n:

drivers/media/platform/soc_camera/atmel-isi.c:1044: warning: 
‘atmel_isi_runtime_suspend’ defined but not used
drivers/media/platform/soc_camera/atmel-isi.c:1054: warning: 
‘atmel_isi_runtime_resume’ defined but not used

Protect the unused functions by #ifdef CONFIG_PM to fix this.

Signed-off-by: Geert Uytterhoeven 
---
Resend with correct suject
---
 drivers/media/platform/soc_camera/atmel-isi.c | 2 ++
 1 file changed, 2 insertions(+)

diff --git a/drivers/media/platform/soc_camera/atmel-isi.c 
b/drivers/media/platform/soc_camera/atmel-isi.c
index 90701726a06a2e5c..ccf30ccbe389233f 100644
--- a/drivers/media/platform/soc_camera/atmel-isi.c
+++ b/drivers/media/platform/soc_camera/atmel-isi.c
@@ -1040,6 +1040,7 @@ err_alloc_ctx:
return ret;
 }
 
+#ifdef CONFIG_PM
 static int atmel_isi_runtime_suspend(struct device *dev)
 {
struct soc_camera_host *soc_host = to_soc_camera_host(dev);
@@ -1058,6 +1059,7 @@ static int atmel_isi_runtime_resume(struct device *dev)
 
return clk_prepare_enable(isi->pclk);
 }
+#endif /* CONFIG_PM */
 
 static const struct dev_pm_ops atmel_isi_dev_pm_ops = {
SET_RUNTIME_PM_OPS(atmel_isi_runtime_suspend,
-- 
1.9.1

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


Re: [PATCH v8 21/55] [media] media: make media_link more generic to handle interace links

2015-09-06 Thread Mauro Carvalho Chehab
By adding an union at media_link, we get for free a way to
represent interface->entity links.

No need to change anything at the code, just at the internal
header file.

Signed-off-by: Mauro Carvalho Chehab 
Acked-by: Hans Verkuil 

diff --git a/include/media/media-entity.h b/include/media/media-entity.h
index 7016f0619415..6015e996f213 100644
--- a/include/media/media-entity.h
+++ b/include/media/media-entity.h
@@ -75,14 +75,20 @@ struct media_pipeline {
 struct media_link {
struct media_gobj graph_obj;
struct list_head list;
-   struct media_pad *source;   /* Source pad */
-   struct media_pad *sink; /* Sink pad  */
+   union {
+   struct media_gobj *gobj0;
+   struct media_pad *source;
+   };
+   union {
+   struct media_gobj *gobj1;
+   struct media_pad *sink;
+   };
struct media_link *reverse; /* Link in the reverse direction */
unsigned long flags;/* Link flags (MEDIA_LNK_FL_*) */
 };
 
 struct media_pad {
-   struct media_gobj graph_obj;
+   struct media_gobj graph_obj;/* must be first field in struct */
struct media_entity *entity;/* Entity this pad belongs to */
u16 index;  /* Pad index in the entity pads array */
unsigned long flags;/* Pad flags (MEDIA_PAD_FL_*) */
@@ -105,7 +111,7 @@ struct media_entity_operations {
 };
 
 struct media_entity {
-   struct media_gobj graph_obj;
+   struct media_gobj graph_obj;/* must be first field in struct */
struct list_head list;
const char *name;   /* Entity name */
u32 type;   /* Entity type (MEDIA_ENT_T_*) */
@@ -119,7 +125,7 @@ struct media_entity {
u16 num_backlinks;  /* Number of backlinks */
 
struct media_pad *pads; /* Pads array (num_pads objects) */
-   struct list_head links; /* Links list */
+   struct list_head links; /* Pad-to-pad links list */
 
const struct media_entity_operations *ops;  /* Entity operations */
 
-- 
2.4.3


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


Re: [PATCH v8 20/55] [media] media: make add link more generic

2015-09-06 Thread Mauro Carvalho Chehab
The media_entity_add_link() function takes an entity
as an argument just to get the list head.

Make it more generic by changing the function argument
to list_head.

No functional changes.

Signed-off-by: Mauro Carvalho Chehab 
Acked-by: Hans Verkuil 

diff --git a/drivers/media/media-entity.c b/drivers/media/media-entity.c
index d5efa0e2c88c..625b505e8496 100644
--- a/drivers/media/media-entity.c
+++ b/drivers/media/media-entity.c
@@ -580,7 +580,7 @@ EXPORT_SYMBOL_GPL(media_entity_put);
  * Links management
  */
 
-static struct media_link *media_entity_add_link(struct media_entity *entity)
+static struct media_link *media_add_link(struct list_head *head)
 {
struct media_link *link;
 
@@ -588,7 +588,7 @@ static struct media_link *media_entity_add_link(struct 
media_entity *entity)
if (link == NULL)
return NULL;
 
-   list_add_tail(>list, >links);
+   list_add_tail(>list, head);
 
return link;
 }
@@ -607,7 +607,7 @@ media_create_pad_link(struct media_entity *source, u16 
source_pad,
BUG_ON(source_pad >= source->num_pads);
BUG_ON(sink_pad >= sink->num_pads);
 
-   link = media_entity_add_link(source);
+   link = media_add_link(>links);
if (link == NULL)
return -ENOMEM;
 
@@ -622,7 +622,7 @@ media_create_pad_link(struct media_entity *source, u16 
source_pad,
/* Create the backlink. Backlinks are used to help graph traversal and
 * are not reported to userspace.
 */
-   backlink = media_entity_add_link(sink);
+   backlink = media_add_link(>links);
if (backlink == NULL) {
__media_entity_remove_link(source, link);
return -ENOMEM;
-- 
2.4.3


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


Re: [PATCH v8 22/55] [media] media: make link debug printk more generic

2015-09-06 Thread Mauro Carvalho Chehab
Remove entity name from the link as this exists only if the object
type is PAD on both link ends.

Signed-off-by: Mauro Carvalho Chehab 
Acked-by: Hans Verkuil 
Signed-off-by: Mauro Carvalho Chehab 

diff --git a/drivers/media/media-entity.c b/drivers/media/media-entity.c
index 625b505e8496..f9c6c2a81903 100644
--- a/drivers/media/media-entity.c
+++ b/drivers/media/media-entity.c
@@ -106,16 +106,14 @@ static void dev_dbg_obj(const char *event_name,  struct 
media_gobj *gobj)
struct media_link *link = gobj_to_link(gobj);
 
dev_dbg(gobj->mdev->dev,
-   "%s: id 0x%08x link#%d: '%s' %s#%d ==> '%s' %s#%d\n",
+   "%s: id 0x%08x link#%d: %s#%d ==> %s#%d\n",
event_name, gobj->id, media_localid(gobj),
 
-   link->source->entity->name,
-   gobj_type(media_type(>source->graph_obj)),
-   media_localid(>source->graph_obj),
+   gobj_type(media_type(link->gobj0)),
+   media_localid(link->gobj0),
 
-   link->sink->entity->name,
-   gobj_type(media_type(>sink->graph_obj)),
-   media_localid(>sink->graph_obj));
+   gobj_type(media_type(link->gobj1)),
+   media_localid(link->gobj1));
break;
}
case MEDIA_GRAPH_PAD:
-- 
2.4.3


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


Re: [PATCH v8 16/55] [media] media: Don't accept early-created links

2015-09-06 Thread Mauro Carvalho Chehab
Links are graph objects that represent the links of two already
existing objects in the graph.

While with the current implementation, it is possible to create
the links earlier, It doesn't make any sense to allow linking
two objects when they are not both created.

So, remove the code that would be handling those early-created
links and add a BUG_ON() to ensure that.

Signed-off-by: Mauro Carvalho Chehab 
Acked-by: Hans Verkuil 

diff --git a/drivers/media/media-device.c b/drivers/media/media-device.c
index 138b18416460..0d85c6c28004 100644
--- a/drivers/media/media-device.c
+++ b/drivers/media/media-device.c
@@ -443,13 +443,6 @@ int __must_check media_device_register_entity(struct 
media_device *mdev,
media_gobj_init(mdev, MEDIA_GRAPH_ENTITY, >graph_obj);
list_add_tail(>list, >entities);
 
-   /*
-* Initialize objects at the links
-* in the case where links got created before entity register
-*/
-   for (i = 0; i < entity->num_links; i++)
-   media_gobj_init(mdev, MEDIA_GRAPH_LINK,
-   >links[i].graph_obj);
/* Initialize objects at the pads */
for (i = 0; i < entity->num_pads; i++)
media_gobj_init(mdev, MEDIA_GRAPH_PAD,
diff --git a/drivers/media/media-entity.c b/drivers/media/media-entity.c
index 27fce6224972..0926f08be981 100644
--- a/drivers/media/media-entity.c
+++ b/drivers/media/media-entity.c
@@ -161,6 +161,8 @@ void media_gobj_init(struct media_device *mdev,
   enum media_gobj_type type,
   struct media_gobj *gobj)
 {
+   BUG_ON(!mdev);
+
gobj->mdev = mdev;
 
/* Create a per-type unique object ID */
-- 
2.4.3


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


Re: [PATCH v8 26/55] [media] media: add a linked list to track interfaces by mdev

2015-09-06 Thread Mauro Carvalho Chehab
The media device should list the interface objects, so add a linked list
for those interfaces in struct media_device.

Signed-off-by: Mauro Carvalho Chehab 
Acked-by: Hans Verkuil 

diff --git a/drivers/media/media-device.c b/drivers/media/media-device.c
index 3e649cacfc07..659507bce63f 100644
--- a/drivers/media/media-device.c
+++ b/drivers/media/media-device.c
@@ -381,6 +381,7 @@ int __must_check __media_device_register(struct 
media_device *mdev,
return -EINVAL;
 
INIT_LIST_HEAD(>entities);
+   INIT_LIST_HEAD(>interfaces);
spin_lock_init(>lock);
mutex_init(>graph_mutex);
 
diff --git a/drivers/media/media-entity.c b/drivers/media/media-entity.c
index 74aaa5a5d5bc..d8038a53f945 100644
--- a/drivers/media/media-entity.c
+++ b/drivers/media/media-entity.c
@@ -861,6 +861,8 @@ static void media_interface_init(struct media_device *mdev,
INIT_LIST_HEAD(>links);
 
media_gobj_init(mdev, gobj_type, >graph_obj);
+
+   list_add_tail(>list, >interfaces);
 }
 
 /* Functions related to the media interface via device nodes */
@@ -889,6 +891,7 @@ EXPORT_SYMBOL_GPL(media_devnode_create);
 void media_devnode_remove(struct media_intf_devnode *devnode)
 {
media_gobj_remove(>intf.graph_obj);
+   list_del(>intf.list);
kfree(devnode);
 }
 EXPORT_SYMBOL_GPL(media_devnode_remove);
diff --git a/include/media/media-device.h b/include/media/media-device.h
index 3b14394d5701..51807efa505b 100644
--- a/include/media/media-device.h
+++ b/include/media/media-device.h
@@ -46,6 +46,7 @@ struct device;
  * @link_id:   Unique ID used on the last link registered
  * @intf_devnode_id: Unique ID used on the last interface devnode registered
  * @entities:  List of registered entities
+ * @interfaces:List of registered interfaces
  * @lock:  Entities list lock
  * @graph_mutex: Entities graph operation lock
  * @link_notify: Link state change notification callback
@@ -77,6 +78,7 @@ struct media_device {
u32 intf_devnode_id;
 
struct list_head entities;
+   struct list_head interfaces;
 
/* Protects the entities list */
spinlock_t lock;
diff --git a/include/media/media-entity.h b/include/media/media-entity.h
index f67c01419268..4e36b1f2b2d7 100644
--- a/include/media/media-entity.h
+++ b/include/media/media-entity.h
@@ -156,6 +156,8 @@ struct media_entity {
  * struct media_intf_devnode - Define a Kernel API interface
  *
  * @graph_obj: embedded graph object
+ * @list:  Linked list used to find other interfaces that belong
+ * to the same media controller
  * @links: List of links pointing to graph entities
  * @type:  Type of the interface as defined at the
  * uapi/media/media.h header, e. g.
@@ -164,6 +166,7 @@ struct media_entity {
  */
 struct media_interface {
struct media_gobj   graph_obj;
+   struct list_headlist;
struct list_headlinks;
u32 type;
u32 flags;
-- 
2.4.3


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


Re: [PATCH v8 47/55] [media] media-device: add pads and links to media_device

2015-09-06 Thread Mauro Carvalho Chehab
The MC next gen API sends objects to userspace grouped by
their types.

In the case of pads and links, in order to improve performance
and have a simpler code, the best is to store them also on
separate linked lists at MC.

If we don't do that, we would need this kind of interaction
to send data to userspace (code is in structured english):

for each entity:
for each pad:
store pads

for each entity:
for each link:
store link

for each interface:
for each link:
store link

With would require one nexted loop for pads and two nested
loops for links. By using  separate linked lists for them,
just one loop would be enough.

Signed-off-by: Mauro Carvalho Chehab 
Acked-by: Hans Verkuil 

diff --git a/drivers/media/media-device.c b/drivers/media/media-device.c
index ec98595b8a7a..5b2c9f7fcd45 100644
--- a/drivers/media/media-device.c
+++ b/drivers/media/media-device.c
@@ -382,6 +382,8 @@ int __must_check __media_device_register(struct 
media_device *mdev,
 
INIT_LIST_HEAD(>entities);
INIT_LIST_HEAD(>interfaces);
+   INIT_LIST_HEAD(>pads);
+   INIT_LIST_HEAD(>links);
spin_lock_init(>lock);
mutex_init(>graph_mutex);
 
diff --git a/drivers/media/media-entity.c b/drivers/media/media-entity.c
index cbb0604e81c1..568553d41f5d 100644
--- a/drivers/media/media-entity.c
+++ b/drivers/media/media-entity.c
@@ -174,13 +174,15 @@ void media_gobj_init(struct media_device *mdev,
break;
case MEDIA_GRAPH_PAD:
gobj->id = media_gobj_gen_id(type, ++mdev->pad_id);
+   list_add_tail(>list, >pads);
break;
case MEDIA_GRAPH_LINK:
gobj->id = media_gobj_gen_id(type, ++mdev->link_id);
+   list_add_tail(>list, >links);
break;
case MEDIA_GRAPH_INTF_DEVNODE:
-   list_add_tail(>list, >interfaces);
gobj->id = media_gobj_gen_id(type, ++mdev->intf_devnode_id);
+   list_add_tail(>list, >interfaces);
break;
}
dev_dbg_obj(__func__, gobj);
@@ -195,17 +197,10 @@ void media_gobj_init(struct media_device *mdev,
  */
 void media_gobj_remove(struct media_gobj *gobj)
 {
+   dev_dbg_obj(__func__, gobj);
+
/* Remove the object from mdev list */
-   switch (media_type(gobj)) {
-   case MEDIA_GRAPH_ENTITY:
-   case MEDIA_GRAPH_INTF_DEVNODE:
-   list_del(>list);
-   break;
-   default:
-   break;
-   }
-
-   dev_dbg_obj(__func__, gobj);
+   list_del(>list);
 }
 
 /**
diff --git a/include/media/media-device.h b/include/media/media-device.h
index 85fa302047bd..0d1b9c687454 100644
--- a/include/media/media-device.h
+++ b/include/media/media-device.h
@@ -47,6 +47,8 @@ struct device;
  * @intf_devnode_id: Unique ID used on the last interface devnode registered
  * @entities:  List of registered entities
  * @interfaces:List of registered interfaces
+ * @pads:  List of registered pads
+ * @links: List of registered links
  * @lock:  Entities list lock
  * @graph_mutex: Entities graph operation lock
  * @link_notify: Link state change notification callback
@@ -79,6 +81,8 @@ struct media_device {
 
struct list_head entities;
struct list_head interfaces;
+   struct list_head pads;
+   struct list_head links;
 
/* Protects the entities list */
spinlock_t lock;
@@ -117,6 +121,14 @@ struct media_device *media_device_find_devres(struct 
device *dev);
 #define media_device_for_each_intf(intf, mdev) \
list_for_each_entry(intf, &(mdev)->interfaces, graph_obj.list)
 
+/* Iterate over all pads. */
+#define media_device_for_each_pad(pad, mdev)   \
+   list_for_each_entry(pad, &(mdev)->pads, graph_obj.list)
+
+/* Iterate over all links. */
+#define media_device_for_each_link(link, mdev) \
+   list_for_each_entry(link, &(mdev)->links, graph_obj.list)
+
 
 #else
 static inline int media_device_register(struct media_device *mdev)
-- 
2.4.3


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


Re: [PATCH v8 24/55] [media] media-entity: add a helper function to create interface

2015-09-06 Thread Mauro Carvalho Chehab
As we'll be adding other interface types in the future, put the
common interface create code on a separate function.

Suggested-by: Hans Verkuil 
Signed-off-by: Mauro Carvalho Chehab 
Acked-by: Hans Verkuil 

diff --git a/drivers/media/media-entity.c b/drivers/media/media-entity.c
index 8e17272936c9..74aaa5a5d5bc 100644
--- a/drivers/media/media-entity.c
+++ b/drivers/media/media-entity.c
@@ -851,6 +851,18 @@ struct media_pad *media_entity_remote_pad(struct media_pad 
*pad)
 EXPORT_SYMBOL_GPL(media_entity_remote_pad);
 
 
+static void media_interface_init(struct media_device *mdev,
+struct media_interface *intf,
+u32 gobj_type,
+u32 intf_type, u32 flags)
+{
+   intf->type = intf_type;
+   intf->flags = flags;
+   INIT_LIST_HEAD(>links);
+
+   media_gobj_init(mdev, gobj_type, >graph_obj);
+}
+
 /* Functions related to the media interface via device nodes */
 
 struct media_intf_devnode *media_devnode_create(struct media_device *mdev,
@@ -859,23 +871,16 @@ struct media_intf_devnode *media_devnode_create(struct 
media_device *mdev,
gfp_t gfp_flags)
 {
struct media_intf_devnode *devnode;
-   struct media_interface *intf;
 
devnode = kzalloc(sizeof(*devnode), gfp_flags);
if (!devnode)
return NULL;
 
-   intf = >intf;
-
-   intf->type = type;
-   intf->flags = flags;
-   INIT_LIST_HEAD(>links);
-
devnode->major = major;
devnode->minor = minor;
 
-   media_gobj_init(mdev, MEDIA_GRAPH_INTF_DEVNODE,
-  >intf.graph_obj);
+   media_interface_init(mdev, >intf, MEDIA_GRAPH_INTF_DEVNODE,
+type, flags);
 
return devnode;
 }
-- 
2.4.3


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


[PATCH] [media] atmel-isi:

2015-09-06 Thread Geert Uytterhoeven
If CONFIG_PM=n:

drivers/media/platform/soc_camera/atmel-isi.c:1044: warning: 
‘atmel_isi_runtime_suspend’ defined but not used
drivers/media/platform/soc_camera/atmel-isi.c:1054: warning: 
‘atmel_isi_runtime_resume’ defined but not used

Protect the unused functions by #ifdef CONFIG_PM to fix this.

Signed-off-by: Geert Uytterhoeven 
---
 drivers/media/platform/soc_camera/atmel-isi.c | 2 ++
 1 file changed, 2 insertions(+)

diff --git a/drivers/media/platform/soc_camera/atmel-isi.c 
b/drivers/media/platform/soc_camera/atmel-isi.c
index 90701726a06a2e5c..ccf30ccbe389233f 100644
--- a/drivers/media/platform/soc_camera/atmel-isi.c
+++ b/drivers/media/platform/soc_camera/atmel-isi.c
@@ -1040,6 +1040,7 @@ err_alloc_ctx:
return ret;
 }
 
+#ifdef CONFIG_PM
 static int atmel_isi_runtime_suspend(struct device *dev)
 {
struct soc_camera_host *soc_host = to_soc_camera_host(dev);
@@ -1058,6 +1059,7 @@ static int atmel_isi_runtime_resume(struct device *dev)
 
return clk_prepare_enable(isi->pclk);
 }
+#endif /* CONFIG_PM */
 
 static const struct dev_pm_ops atmel_isi_dev_pm_ops = {
SET_RUNTIME_PM_OPS(atmel_isi_runtime_suspend,
-- 
1.9.1

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


[PATCH v5 4/4] media: pxa_camera: conversion to dmaengine

2015-09-06 Thread Robert Jarzmik
Convert pxa_camera to dmaengine. This removes all DMA registers
manipulation in favor of the more generic dmaengine API.

The functional level should be the same as before. The biggest change is
in the videobuf_sg_splice() function, which splits a videobuf-dma into
several scatterlists for 3 planes captures (Y, U, V).

Signed-off-by: Robert Jarzmik 
---
Since v1: Guennadi's fixes
  dma tasklet functions prototypes change (trivial move)
Since v2: sglist cut revamped with Guennadi's comments
Since v3: sglist split removed after Andrew's merge in -mm tree in lib/
  taken into account Vinod's change to DMA_CTRL_REUSE
Since v4: x_dma_irq() prototypes change
---
 drivers/media/platform/soc_camera/Kconfig  |   1 +
 drivers/media/platform/soc_camera/pxa_camera.c | 400 +++--
 2 files changed, 173 insertions(+), 228 deletions(-)

diff --git a/drivers/media/platform/soc_camera/Kconfig 
b/drivers/media/platform/soc_camera/Kconfig
index f2776cd415ca..e5e2d6cf6638 100644
--- a/drivers/media/platform/soc_camera/Kconfig
+++ b/drivers/media/platform/soc_camera/Kconfig
@@ -30,6 +30,7 @@ config VIDEO_PXA27x
tristate "PXA27x Quick Capture Interface driver"
depends on VIDEO_DEV && PXA27x && SOC_CAMERA
select VIDEOBUF_DMA_SG
+   select SG_SPLIT
---help---
  This is a v4l2 driver for the PXA27x Quick Capture Interface
 
diff --git a/drivers/media/platform/soc_camera/pxa_camera.c 
b/drivers/media/platform/soc_camera/pxa_camera.c
index bb7054221a86..47c93278a1e6 100644
--- a/drivers/media/platform/soc_camera/pxa_camera.c
+++ b/drivers/media/platform/soc_camera/pxa_camera.c
@@ -28,6 +28,9 @@
 #include 
 #include 
 #include 
+#include 
+#include 
+#include 
 
 #include 
 #include 
@@ -38,7 +41,6 @@
 
 #include 
 
-#include 
 #include 
 
 #define PXA_CAM_VERSION "0.0.6"
@@ -175,21 +177,16 @@ enum pxa_camera_active_dma {
DMA_V = 0x4,
 };
 
-/* descriptor needed for the PXA DMA engine */
-struct pxa_cam_dma {
-   dma_addr_t  sg_dma;
-   struct pxa_dma_desc *sg_cpu;
-   size_t  sg_size;
-   int sglen;
-};
-
 /* buffer for one video frame */
 struct pxa_buffer {
/* common v4l buffer stuff -- must be first */
struct videobuf_buffer  vb;
u32 code;
/* our descriptor lists for Y, U and V channels */
-   struct pxa_cam_dma  dmas[3];
+   struct dma_async_tx_descriptor  *descs[3];
+   dma_cookie_tcookie[3];
+   struct scatterlist  *sg[3];
+   int sg_len[3];
int inwork;
enum pxa_camera_active_dma  active_dma;
 };
@@ -207,7 +204,7 @@ struct pxa_camera_dev {
void __iomem*base;
 
int channels;
-   unsigned intdma_chans[3];
+   struct dma_chan *dma_chans[3];
 
struct pxacamera_platform_data *pdata;
struct resource *res;
@@ -222,7 +219,6 @@ struct pxa_camera_dev {
spinlock_t  lock;
 
struct pxa_buffer   *active;
-   struct pxa_dma_desc *sg_tail[3];
struct tasklet_struct   task_eof;
 
u32 save_cicr[5];
@@ -259,7 +255,6 @@ static int pxa_videobuf_setup(struct videobuf_queue *vq, 
unsigned int *count,
 static void free_buffer(struct videobuf_queue *vq, struct pxa_buffer *buf)
 {
struct soc_camera_device *icd = vq->priv_data;
-   struct soc_camera_host *ici = to_soc_camera_host(icd->parent);
struct videobuf_dmabuf *dma = videobuf_to_dma(>vb);
int i;
 
@@ -274,65 +269,44 @@ static void free_buffer(struct videobuf_queue *vq, struct 
pxa_buffer *buf)
 */
videobuf_waiton(vq, >vb, 0, 0);
 
-   for (i = 0; i < ARRAY_SIZE(buf->dmas); i++) {
-   if (buf->dmas[i].sg_cpu)
-   dma_free_coherent(ici->v4l2_dev.dev,
- buf->dmas[i].sg_size,
- buf->dmas[i].sg_cpu,
- buf->dmas[i].sg_dma);
-   buf->dmas[i].sg_cpu = NULL;
+   for (i = 0; i < 3 && buf->descs[i]; i++) {
+   dmaengine_desc_free(buf->descs[i]);
+   kfree(buf->sg[i]);
+   buf->descs[i] = NULL;
+   buf->sg[i] = NULL;
+   buf->sg_len[i] = 0;
}
videobuf_dma_unmap(vq->dev, dma);
videobuf_dma_free(dma);
 
buf->vb.state = VIDEOBUF_NEEDS_INIT;
-}
-
-static int calculate_dma_sglen(struct scatterlist *sglist, int sglen,
-  int sg_first_ofs, int size)
-{
-   int i, offset, dma_len, xfer_len;
-   struct scatterlist *sg;
-
-   offset = sg_first_ofs;
-   for_each_sg(sglist, sg, sglen, i) {
-   dma_len = sg_dma_len(sg);
-
-   

[PATCH v5 1/4] media: pxa_camera: fix the buffer free path

2015-09-06 Thread Robert Jarzmik
Fix the error path where the video buffer wasn't allocated nor
mapped. In this case, in the driver free path don't try to unmap memory
which was not mapped in the first place.

Signed-off-by: Robert Jarzmik 
---
Since v3: take into account the 2 paths possibilities to free_buffer()
---
 drivers/media/platform/soc_camera/pxa_camera.c | 16 +---
 1 file changed, 5 insertions(+), 11 deletions(-)

diff --git a/drivers/media/platform/soc_camera/pxa_camera.c 
b/drivers/media/platform/soc_camera/pxa_camera.c
index fcb942de0c7f..d4e887841372 100644
--- a/drivers/media/platform/soc_camera/pxa_camera.c
+++ b/drivers/media/platform/soc_camera/pxa_camera.c
@@ -272,8 +272,6 @@ static void free_buffer(struct videobuf_queue *vq, struct 
pxa_buffer *buf)
 * longer in STATE_QUEUED or STATE_ACTIVE
 */
videobuf_waiton(vq, >vb, 0, 0);
-   videobuf_dma_unmap(vq->dev, dma);
-   videobuf_dma_free(dma);
 
for (i = 0; i < ARRAY_SIZE(buf->dmas); i++) {
if (buf->dmas[i].sg_cpu)
@@ -283,6 +281,8 @@ static void free_buffer(struct videobuf_queue *vq, struct 
pxa_buffer *buf)
  buf->dmas[i].sg_dma);
buf->dmas[i].sg_cpu = NULL;
}
+   videobuf_dma_unmap(vq->dev, dma);
+   videobuf_dma_free(dma);
 
buf->vb.state = VIDEOBUF_NEEDS_INIT;
 }
@@ -479,7 +479,7 @@ static int pxa_videobuf_prepare(struct videobuf_queue *vq,
 
ret = videobuf_iolock(vq, vb, NULL);
if (ret)
-   goto fail;
+   goto out;
 
if (pcdev->channels == 3) {
size_y = size / 2;
@@ -504,7 +504,7 @@ static int pxa_videobuf_prepare(struct videobuf_queue *vq,
   size_u, , _ofs);
if (ret) {
dev_err(dev, "DMA initialization for U failed\n");
-   goto fail_u;
+   goto fail;
}
 
/* init DMA for V channel */
@@ -513,7 +513,7 @@ static int pxa_videobuf_prepare(struct videobuf_queue *vq,
   size_v, , _ofs);
if (ret) {
dev_err(dev, "DMA initialization for V failed\n");
-   goto fail_v;
+   goto fail;
}
 
vb->state = VIDEOBUF_PREPARED;
@@ -524,12 +524,6 @@ static int pxa_videobuf_prepare(struct videobuf_queue *vq,
 
return 0;
 
-fail_v:
-   dma_free_coherent(dev, buf->dmas[1].sg_size,
- buf->dmas[1].sg_cpu, buf->dmas[1].sg_dma);
-fail_u:
-   dma_free_coherent(dev, buf->dmas[0].sg_size,
- buf->dmas[0].sg_cpu, buf->dmas[0].sg_dma);
 fail:
free_buffer(vq, buf);
 out:
-- 
2.1.4

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


[PATCH v5 3/4] media: pxa_camera: trivial move of dma irq functions

2015-09-06 Thread Robert Jarzmik
This moves the dma irq handling functions up in the source file, so that
they are available before DMA preparation functions. It prepares the
conversion to DMA engine, where the descriptors are populated with these
functions as callbacks.

Signed-off-by: Robert Jarzmik 
---
Since v1: fixed prototypes change
Since v4: refixed prototypes change
---
 drivers/media/platform/soc_camera/pxa_camera.c | 42 +++---
 1 file changed, 24 insertions(+), 18 deletions(-)

diff --git a/drivers/media/platform/soc_camera/pxa_camera.c 
b/drivers/media/platform/soc_camera/pxa_camera.c
index db041a5ed444..bb7054221a86 100644
--- a/drivers/media/platform/soc_camera/pxa_camera.c
+++ b/drivers/media/platform/soc_camera/pxa_camera.c
@@ -311,6 +311,30 @@ static int calculate_dma_sglen(struct scatterlist *sglist, 
int sglen,
return i + 1;
 }
 
+static void pxa_camera_dma_irq(struct pxa_camera_dev *pcdev,
+  enum pxa_camera_active_dma act_dma);
+
+static void pxa_camera_dma_irq_y(int channel, void *data)
+{
+   struct pxa_camera_dev *pcdev = data;
+
+   pxa_camera_dma_irq(channel, pcdev, DMA_Y);
+}
+
+static void pxa_camera_dma_irq_u(int channel, void *data)
+{
+   struct pxa_camera_dev *pcdev = data;
+
+   pxa_camera_dma_irq(channel, pcdev, DMA_U);
+}
+
+static void pxa_camera_dma_irq_v(int channel, void *data)
+{
+   struct pxa_camera_dev *pcdev = data;
+
+   pxa_camera_dma_irq(channel, pcdev, DMA_V);
+}
+
 /**
  * pxa_init_dma_channel - init dma descriptors
  * @pcdev: pxa camera device
@@ -802,24 +826,6 @@ out:
spin_unlock_irqrestore(>lock, flags);
 }
 
-static void pxa_camera_dma_irq_y(int channel, void *data)
-{
-   struct pxa_camera_dev *pcdev = data;
-   pxa_camera_dma_irq(channel, pcdev, DMA_Y);
-}
-
-static void pxa_camera_dma_irq_u(int channel, void *data)
-{
-   struct pxa_camera_dev *pcdev = data;
-   pxa_camera_dma_irq(channel, pcdev, DMA_U);
-}
-
-static void pxa_camera_dma_irq_v(int channel, void *data)
-{
-   struct pxa_camera_dev *pcdev = data;
-   pxa_camera_dma_irq(channel, pcdev, DMA_V);
-}
-
 static struct videobuf_queue_ops pxa_videobuf_ops = {
.buf_setup  = pxa_videobuf_setup,
.buf_prepare= pxa_videobuf_prepare,
-- 
2.1.4

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


Re: [PATCH v8 55/55] [media] media-entity.h: document all the structs

2015-09-06 Thread Mauro Carvalho Chehab
Only a few structs are documented on kernel-doc-nano format
(the ones added by the MC next gen patches).

Add a documentation for all structs, and ensure that they'll
be producing the documentation at the Kernel's device driver
DocBook.

Signed-off-by: Mauro Carvalho Chehab 

diff --git a/include/media/media-entity.h b/include/media/media-entity.h
index fb5f0e21f137..e1a89899deef 100644
--- a/include/media/media-entity.h
+++ b/include/media/media-entity.h
@@ -55,11 +55,13 @@ enum media_gobj_type {
 /**
  * struct media_gobj - Define a graph object.
  *
+ * @mdev:  Pointer to the struct media_device that owns the object
  * @id:Non-zero object ID identifier. The ID should be unique
  * inside a media_device, as it is composed by
  * MEDIA_BITS_PER_TYPE to store the type plus
  * MEDIA_BITS_PER_LOCAL_ID to store a per-type ID
  * (called as "local ID").
+ * @list:  Linked list associated to one of the per-type mdev object lists
  *
  * All objects on the media graph should have this struct embedded
  */
@@ -73,6 +75,28 @@ struct media_gobj {
 struct media_pipeline {
 };
 
+/**
+ * struct media_link - Define a media link graph object.
+ *
+ * @graph_obj: Embedded structure containing the media object common data
+ * @list:  Linked list associated with an entity or an interface that
+ * owns the link.
+ * @gobj0: Part of an union. Used to get the pointer for the first
+ * graph_object of the link.
+ * @source:Part of an union. Used only if the first object (gobj0) is
+ * a pad. On such case, it represents the source pad.
+ * @intf:  Part of an union. Used only if the first object (gobj0) is
+ * an interface.
+ * @gobj1: Part of an union. Used to get the pointer for the second
+ * graph_object of the link.
+ * @source:Part of an union. Used only if the second object (gobj0) is
+ * a pad. On such case, it represents the sink pad.
+ * @entity:Part of an union. Used only if the second object (gobj0) is
+ * an entity.
+ * @reverse:   Pointer to the link for the reverse direction of a pad to pad
+ * link.
+ * @flags: Link flags, as defined at uapi/media.h (MEDIA_LNK_FL_*)
+ */
 struct media_link {
struct media_gobj graph_obj;
struct list_head list;
@@ -86,15 +110,23 @@ struct media_link {
struct media_pad *sink;
struct media_entity *entity;
};
-   struct media_link *reverse; /* Link in the reverse direction */
-   unsigned long flags;/* Link flags (MEDIA_LNK_FL_*) */
+   struct media_link *reverse;
+   unsigned long flags;
 };
 
+/**
+ * struct media_pad - Define a media pad graph object.
+ *
+ * @graph_obj: Embedded structure containing the media object common data
+ * @entity:Entity where this object belongs
+ * @index: Pad index in the entity pads array, numbered from 0 to n
+ * @flags: Pad flags, as defined at uapi/media.h (MEDIA_PAD_FL_*)
+ */
 struct media_pad {
struct media_gobj graph_obj;/* must be first field in struct */
-   struct media_entity *entity;/* Entity this pad belongs to */
-   u16 index;  /* Pad index in the entity pads array */
-   unsigned long flags;/* Pad flags (MEDIA_PAD_FL_*) */
+   struct media_entity *entity;
+   u16 index;
+   unsigned long flags;
 };
 
 /**
@@ -113,51 +145,73 @@ struct media_entity_operations {
int (*link_validate)(struct media_link *link);
 };
 
+/**
+ * struct media_entity - Define a media entity graph object.
+ *
+ * @graph_obj: Embedded structure containing the media object common data.
+ * @name:  Entity name.
+ * @type:  Entity type, as defined at uapi/media.h (MEDIA_ENT_T_*)
+ * @revision:  Entity revision - OBSOLETE - should be removed soon.
+ * @flags: Entity flags, as defined at uapi/media.h (MEDIA_ENT_FL_*)
+ * @group_id:  Entity group ID - OBSOLETE - should be removed soon.
+ * @num_pads:  Number of sink and source pads.
+ * @num_links: Number of existing links, both enabled and disabled.
+ * @num_backlinks: Number of backlinks
+ * @pads:  Pads array with the size defined by @num_pads.
+ * @links: Linked list for the data links.
+ * @ops:   Entity operations.
+ * @stream_count: Stream count for the entity.
+ * @use_count: Use count for the entity.
+ * @pipe:  Pipeline this entity belongs to.
+ * @info:  Union with devnode information.  Kept just for backward
+ * compatibility.
+ * @major: Devnode major number (zero if not applicable). Kept just
+ * for backward compatibility.
+ * @minor: Devnode minor number (zero if not applicable). Kept just
+ * for backward compatibility.
+ *
+ * NOTE: @stream_count and @use_count reference counts must never be
+ * negative, but are signed 

Re: [PATCH v8 39/55] [media] media controller: get rid of entity subtype on Kernel

2015-09-06 Thread Mauro Carvalho Chehab
Don't use anymore the type/subtype entity data/macros
inside the Kernel.

Signed-off-by: Mauro Carvalho Chehab 

diff --git a/include/media/media-entity.h b/include/media/media-entity.h
index 220864319d21..7320cdc45833 100644
--- a/include/media/media-entity.h
+++ b/include/media/media-entity.h
@@ -185,16 +185,6 @@ struct media_intf_devnode {
u32 minor;
 };
 
-static inline u32 media_entity_type(struct media_entity *entity)
-{
-   return entity->type & MEDIA_ENT_TYPE_MASK;
-}
-
-static inline u32 media_entity_subtype(struct media_entity *entity)
-{
-   return entity->type & MEDIA_ENT_SUBTYPE_MASK;
-}
-
 static inline u32 media_entity_id(struct media_entity *entity)
 {
return entity->graph_obj.id;
diff --git a/include/uapi/linux/media.h b/include/uapi/linux/media.h
index 3d6210095336..f90147cb9b57 100644
--- a/include/uapi/linux/media.h
+++ b/include/uapi/linux/media.h
@@ -42,8 +42,6 @@ struct media_device_info {
 
 #define MEDIA_ENT_ID_FLAG_NEXT (1 << 31)
 
-/* Used values for media_entity_desc::type */
-
 /*
  * Initial value to be used when a new entity is created
  * Drivers should change it to something useful
-- 
2.4.3


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


Re: [PATCH v8.2 19/55] [media] media: convert links from array to list

2015-09-06 Thread Mauro Carvalho Chehab
The entire logic that represent graph links were developed on a
time where there were no needs to dynamic remove links. So,
although links are created/removed one by one via some
functions, they're stored as an array inside the entity struct.

As the array may grow, there's a logic inside the code that
checks if the amount of space is not enough to store
the needed links. If it isn't the core uses krealloc()
to change the size of the link, with is bad, as it
leaves the memory fragmented.

So, convert links into a list.

Also, currently,  both source and sink entities need the link
at the graph traversal logic inside media_entity. So there's
a logic duplicating all links. That makes it to spend
twice the memory needed. This is not a big deal for today's
usage, where the number of links are not big.

Yet, if during the MC workshop discussions, it was said that
IIO graphs could have up to 4,000 entities. So, we may
want to remove the duplication on some future. The problem
is that it would require a separate linked list to store
the backlinks inside the entity, or to use a more complex
algorithm to do graph backlink traversal, with is something
that the current graph traversal inside the core can't cope
with. So, let's postpone a such change if/when it is actually
needed.

Signed-off-by: Mauro Carvalho Chehab 

diff --git a/drivers/media/dvb-core/dvb_frontend.c 
b/drivers/media/dvb-core/dvb_frontend.c
index c38ef1a72b4a..2d06bcff0946 100644
--- a/drivers/media/dvb-core/dvb_frontend.c
+++ b/drivers/media/dvb-core/dvb_frontend.c
@@ -622,7 +622,7 @@ static int dvb_enable_media_tuner(struct dvb_frontend *fe)
struct media_device *mdev = adapter->mdev;
struct media_entity  *entity, *source;
struct media_link *link, *found_link = NULL;
-   int i, ret, n_links = 0, active_links = 0;
+   int ret, n_links = 0, active_links = 0;
 
fepriv->pipe_start_entity = NULL;
 
@@ -632,8 +632,7 @@ static int dvb_enable_media_tuner(struct dvb_frontend *fe)
entity = fepriv->dvbdev->entity;
fepriv->pipe_start_entity = entity;
 
-   for (i = 0; i < entity->num_links; i++) {
-   link = >links[i];
+   list_for_each_entry(link, >links, list) {
if (link->sink->entity == entity) {
found_link = link;
n_links++;
@@ -659,13 +658,11 @@ static int dvb_enable_media_tuner(struct dvb_frontend *fe)
 
source = found_link->source->entity;
fepriv->pipe_start_entity = source;
-   for (i = 0; i < source->num_links; i++) {
+   list_for_each_entry(link, >links, list) {
struct media_entity *sink;
int flags = 0;
 
-   link = >links[i];
sink = link->sink->entity;
-
if (sink == entity)
flags = MEDIA_LNK_FL_ENABLED;
 
diff --git a/drivers/media/media-device.c b/drivers/media/media-device.c
index 0d85c6c28004..3e649cacfc07 100644
--- a/drivers/media/media-device.c
+++ b/drivers/media/media-device.c
@@ -25,6 +25,7 @@
 #include 
 #include 
 #include 
+#include 
 
 #include 
 #include 
@@ -150,22 +151,21 @@ static long __media_device_enum_links(struct media_device 
*mdev,
}
 
if (links->links) {
-   struct media_link_desc __user *ulink;
-   unsigned int l;
+   struct media_link *ent_link;
+   struct media_link_desc __user *ulink = links->links;
 
-   for (l = 0, ulink = links->links; l < entity->num_links; l++) {
+   list_for_each_entry(ent_link, >links, list) {
struct media_link_desc link;
 
/* Ignore backlinks. */
-   if (entity->links[l].source->entity != entity)
+   if (ent_link->source->entity != entity)
continue;
-
memset(, 0, sizeof(link));
-   media_device_kpad_to_upad(entity->links[l].source,
+   media_device_kpad_to_upad(ent_link->source,
  );
-   media_device_kpad_to_upad(entity->links[l].sink,
+   media_device_kpad_to_upad(ent_link->sink,
  );
-   link.flags = entity->links[l].flags;
+   link.flags = ent_link->flags;
if (copy_to_user(ulink, , sizeof(*ulink)))
return -EFAULT;
ulink++;
@@ -437,6 +437,7 @@ int __must_check media_device_register_entity(struct 
media_device *mdev,
/* Warn if we apparently re-register an entity */
WARN_ON(entity->graph_obj.mdev != NULL);
entity->graph_obj.mdev = mdev;
+   INIT_LIST_HEAD(>links);
 
spin_lock(>lock);
/* Initialize media_gobj embedded at the entity */
@@ -465,13 

Re: [PATCH v8 46/55] [media] media: move mdev list init to gobj

2015-09-06 Thread Mauro Carvalho Chehab
Let's control the topology changes inside the graph_object. So, move the
addition and removal of interfaces/entities from the mdev lists to
media_gobj_init() and media_gobj_remove().

The main reason is that mdev should have lists for all object types, as
the new MC api will require to store objects in separate places.

Signed-off-by: Mauro Carvalho Chehab 

diff --git a/drivers/media/media-device.c b/drivers/media/media-device.c
index 134fe7510195..ec98595b8a7a 100644
--- a/drivers/media/media-device.c
+++ b/drivers/media/media-device.c
@@ -415,7 +415,7 @@ void media_device_unregister(struct media_device *mdev)
struct media_entity *entity;
struct media_entity *next;
 
-   list_for_each_entry_safe(entity, next, >entities, list)
+   list_for_each_entry_safe(entity, next, >entities, graph_obj.list)
media_device_unregister_entity(entity);
 
device_remove_file(>devnode.dev, _attr_model);
@@ -449,7 +449,6 @@ int __must_check media_device_register_entity(struct 
media_device *mdev,
spin_lock(>lock);
/* Initialize media_gobj embedded at the entity */
media_gobj_init(mdev, MEDIA_GRAPH_ENTITY, >graph_obj);
-   list_add_tail(>list, >entities);
 
/* Initialize objects at the pads */
for (i = 0; i < entity->num_pads; i++)
@@ -487,7 +486,6 @@ void media_device_unregister_entity(struct media_entity 
*entity)
for (i = 0; i < entity->num_pads; i++)
media_gobj_remove(>pads[i].graph_obj);
media_gobj_remove(>graph_obj);
-   list_del(>list);
spin_unlock(>lock);
entity->graph_obj.mdev = NULL;
 }
diff --git a/drivers/media/media-entity.c b/drivers/media/media-entity.c
index 6ed5eef88593..cbb0604e81c1 100644
--- a/drivers/media/media-entity.c
+++ b/drivers/media/media-entity.c
@@ -170,6 +170,7 @@ void media_gobj_init(struct media_device *mdev,
switch (type) {
case MEDIA_GRAPH_ENTITY:
gobj->id = media_gobj_gen_id(type, ++mdev->entity_id);
+   list_add_tail(>list, >entities);
break;
case MEDIA_GRAPH_PAD:
gobj->id = media_gobj_gen_id(type, ++mdev->pad_id);
@@ -178,6 +179,7 @@ void media_gobj_init(struct media_device *mdev,
gobj->id = media_gobj_gen_id(type, ++mdev->link_id);
break;
case MEDIA_GRAPH_INTF_DEVNODE:
+   list_add_tail(>list, >interfaces);
gobj->id = media_gobj_gen_id(type, ++mdev->intf_devnode_id);
break;
}
@@ -193,6 +195,16 @@ void media_gobj_init(struct media_device *mdev,
  */
 void media_gobj_remove(struct media_gobj *gobj)
 {
+   /* Remove the object from mdev list */
+   switch (media_type(gobj)) {
+   case MEDIA_GRAPH_ENTITY:
+   case MEDIA_GRAPH_INTF_DEVNODE:
+   list_del(>list);
+   break;
+   default:
+   break;
+   }
+
dev_dbg_obj(__func__, gobj);
 }
 
@@ -864,8 +876,6 @@ static void media_interface_init(struct media_device *mdev,
INIT_LIST_HEAD(>links);
 
media_gobj_init(mdev, gobj_type, >graph_obj);
-
-   list_add_tail(>list, >interfaces);
 }
 
 /* Functions related to the media interface via device nodes */
@@ -894,7 +904,6 @@ EXPORT_SYMBOL_GPL(media_devnode_create);
 void media_devnode_remove(struct media_intf_devnode *devnode)
 {
media_gobj_remove(>intf.graph_obj);
-   list_del(>intf.list);
kfree(devnode);
 }
 EXPORT_SYMBOL_GPL(media_devnode_remove);
diff --git a/include/media/media-device.h b/include/media/media-device.h
index f23d686aaac6..85fa302047bd 100644
--- a/include/media/media-device.h
+++ b/include/media/media-device.h
@@ -111,11 +111,11 @@ struct media_device *media_device_find_devres(struct 
device *dev);
 
 /* Iterate over all entities. */
 #define media_device_for_each_entity(entity, mdev) \
-   list_for_each_entry(entity, &(mdev)->entities, list)
+   list_for_each_entry(entity, &(mdev)->entities, graph_obj.list)
 
 /* Iterate over all interfaces. */
 #define media_device_for_each_intf(intf, mdev) \
-   list_for_each_entry(intf, &(mdev)->interfaces, list)
+   list_for_each_entry(intf, &(mdev)->interfaces, graph_obj.list)
 
 
 #else
diff --git a/include/media/media-entity.h b/include/media/media-entity.h
index 2d5ad40254b7..bc7eb6240795 100644
--- a/include/media/media-entity.h
+++ b/include/media/media-entity.h
@@ -66,6 +66,7 @@ enum media_gobj_type {
 struct media_gobj {
struct media_device *mdev;
u32 id;
+   struct list_headlist;
 };
 
 
@@ -114,7 +115,6 @@ struct media_entity_operations {
 
 struct media_entity {
struct media_gobj graph_obj;/* must be first field in struct */
-   struct list_head list;
const char *name;   /* Entity name */
u32 type;   /* Entity type 

Re: [PATCH v8 45/55] [media] media: Use a macro to interate between all interfaces

2015-09-06 Thread Mauro Carvalho Chehab
Just like we do with entities, use a similar macro for the
interfaces loop.

Signed-off-by: Mauro Carvalho Chehab 
Acked-by: Hans Verkuil 

diff --git a/drivers/media/dvb-core/dvbdev.c b/drivers/media/dvb-core/dvbdev.c
index 6babc688801b..f00f1a5f279c 100644
--- a/drivers/media/dvb-core/dvbdev.c
+++ b/drivers/media/dvb-core/dvbdev.c
@@ -578,9 +578,10 @@ void dvb_create_media_graph(struct dvb_adapter *adap)
}
 
/* Create indirect interface links for FE->tuner, DVR->demux and CA->ca 
*/
-   list_for_each_entry(intf, >interfaces, list) {
+   media_device_for_each_intf(intf, mdev) {
if (intf->type == MEDIA_INTF_T_DVB_CA && ca)
media_create_intf_link(ca, intf, 0);
+
if (intf->type == MEDIA_INTF_T_DVB_FE && tuner)
media_create_intf_link(tuner, intf, 0);
 
diff --git a/include/media/media-device.h b/include/media/media-device.h
index 51807efa505b..f23d686aaac6 100644
--- a/include/media/media-device.h
+++ b/include/media/media-device.h
@@ -113,6 +113,11 @@ struct media_device *media_device_find_devres(struct 
device *dev);
 #define media_device_for_each_entity(entity, mdev) \
list_for_each_entry(entity, &(mdev)->entities, list)
 
+/* Iterate over all interfaces. */
+#define media_device_for_each_intf(intf, mdev) \
+   list_for_each_entry(intf, &(mdev)->interfaces, list)
+
+
 #else
 static inline int media_device_register(struct media_device *mdev)
 {
-- 
2.4.3


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


Re: [PATCH v8 51/55] [media] remove interface links at media_entity_unregister()

2015-09-06 Thread Mauro Carvalho Chehab
Interface links connected to an entity should be removed
before being able of removing the entity.

Signed-off-by: Mauro Carvalho Chehab 

diff --git a/drivers/media/media-device.c b/drivers/media/media-device.c
index 96a476eeb16e..7c37aeab05bb 100644
--- a/drivers/media/media-device.c
+++ b/drivers/media/media-device.c
@@ -638,14 +638,30 @@ void media_device_unregister_entity(struct media_entity 
*entity)
return;
 
spin_lock(>lock);
+
+   /* Remove interface links with this entity on it */
+   list_for_each_entry_safe(link, tmp, >links, graph_obj.list) {
+   if (media_type(link->gobj1) == MEDIA_GRAPH_ENTITY
+   && link->entity == entity) {
+   media_gobj_remove(>graph_obj);
+   kfree(link);
+   }
+   }
+
+   /* Remove all data links that belong to this entity */
list_for_each_entry_safe(link, tmp, >links, list) {
media_gobj_remove(>graph_obj);
list_del(>list);
kfree(link);
}
+
+   /* Remove all pads that belong to this entity */
for (i = 0; i < entity->num_pads; i++)
media_gobj_remove(>pads[i].graph_obj);
+
+   /* Remove the entity */
media_gobj_remove(>graph_obj);
+
spin_unlock(>lock);
entity->graph_obj.mdev = NULL;
 }
-- 
2.4.3


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


Re: [PATCH v8 14/55] [media] media: add functions to allow creating interfaces

2015-09-06 Thread Mauro Carvalho Chehab
Interfaces are different than entities: they represent a
Kernel<->userspace interaction, while entities represent a
piece of hardware/firmware/software that executes a function.

Let's distinguish them by creating a separate structure to
store the interfaces.

Later patches should change the existing drivers and logic
to split the current interface embedded inside the entity
structure (device nodes) into a separate object of the graph.

Signed-off-by: Mauro Carvalho Chehab 

diff --git a/drivers/media/media-entity.c b/drivers/media/media-entity.c
index a23c93369a04..dc679dfe8ade 100644
--- a/drivers/media/media-entity.c
+++ b/drivers/media/media-entity.c
@@ -44,11 +44,41 @@ static inline const char *gobj_type(enum media_gobj_type 
type)
return "pad";
case MEDIA_GRAPH_LINK:
return "link";
+   case MEDIA_GRAPH_INTF_DEVNODE:
+   return "intf-devnode";
default:
return "unknown";
}
 }
 
+static inline const char *intf_type(struct media_interface *intf)
+{
+   switch (intf->type) {
+   case MEDIA_INTF_T_DVB_FE:
+   return "frontend";
+   case MEDIA_INTF_T_DVB_DEMUX:
+   return "demux";
+   case MEDIA_INTF_T_DVB_DVR:
+   return "DVR";
+   case MEDIA_INTF_T_DVB_CA:
+   return  "CA";
+   case MEDIA_INTF_T_DVB_NET:
+   return "dvbnet";
+   case MEDIA_INTF_T_V4L_VIDEO:
+   return "video";
+   case MEDIA_INTF_T_V4L_VBI:
+   return "vbi";
+   case MEDIA_INTF_T_V4L_RADIO:
+   return "radio";
+   case MEDIA_INTF_T_V4L_SUBDEV:
+   return "v4l2-subdev";
+   case MEDIA_INTF_T_V4L_SWRADIO:
+   return "swradio";
+   default:
+   return "unknown-intf";
+   }
+};
+
 static void dev_dbg_obj(const char *event_name,  struct media_gobj *gobj)
 {
 #if defined(DEBUG) || defined (CONFIG_DYNAMIC_DEBUG)
@@ -84,6 +114,19 @@ static void dev_dbg_obj(const char *event_name,  struct 
media_gobj *gobj)
"%s: id 0x%08x pad#%d: '%s':%d\n",
event_name, gobj->id, media_localid(gobj),
pad->entity->name, pad->index);
+   break;
+   }
+   case MEDIA_GRAPH_INTF_DEVNODE:
+   {
+   struct media_interface *intf = gobj_to_intf(gobj);
+   struct media_intf_devnode *devnode = intf_to_devnode(intf);
+
+   dev_dbg(gobj->mdev->dev,
+   "%s: id 0x%08x intf_devnode#%d: %s - major: %d, minor: 
%d\n",
+   event_name, gobj->id, media_localid(gobj),
+   intf_type(intf),
+   devnode->major, devnode->minor);
+   break;
}
}
 #endif
@@ -119,6 +162,9 @@ void media_gobj_init(struct media_device *mdev,
case MEDIA_GRAPH_LINK:
gobj->id = media_gobj_gen_id(type, ++mdev->link_id);
break;
+   case MEDIA_GRAPH_INTF_DEVNODE:
+   gobj->id = media_gobj_gen_id(type, ++mdev->intf_devnode_id);
+   break;
}
dev_dbg_obj(__func__, gobj);
 }
@@ -793,3 +839,40 @@ struct media_pad *media_entity_remote_pad(struct media_pad 
*pad)
 
 }
 EXPORT_SYMBOL_GPL(media_entity_remote_pad);
+
+
+/* Functions related to the media interface via device nodes */
+
+struct media_intf_devnode *media_devnode_create(struct media_device *mdev,
+   u32 type, u32 flags,
+   u32 major, u32 minor,
+   gfp_t gfp_flags)
+{
+   struct media_intf_devnode *devnode;
+   struct media_interface *intf;
+
+   devnode = kzalloc(sizeof(*devnode), gfp_flags);
+   if (!devnode)
+   return NULL;
+
+   intf = >intf;
+
+   intf->type = type;
+   intf->flags = flags;
+
+   devnode->major = major;
+   devnode->minor = minor;
+
+   media_gobj_init(mdev, MEDIA_GRAPH_INTF_DEVNODE,
+  >intf.graph_obj);
+
+   return devnode;
+}
+EXPORT_SYMBOL_GPL(media_devnode_create);
+
+void media_devnode_remove(struct media_intf_devnode *devnode)
+{
+   media_gobj_remove(>intf.graph_obj);
+   kfree(devnode);
+}
+EXPORT_SYMBOL_GPL(media_devnode_remove);
diff --git a/include/media/media-device.h b/include/media/media-device.h
index 05414e351f8e..3b14394d5701 100644
--- a/include/media/media-device.h
+++ b/include/media/media-device.h
@@ -44,6 +44,7 @@ struct device;
  * @entity_id: Unique ID used on the last entity registered
  * @pad_id:Unique ID used on the last pad registered
  * @link_id:   Unique ID used on the last link registered
+ * @intf_devnode_id: Unique ID used on the last interface devnode registered
  * @entities:  List of registered entities
  * @lock:  Entities list lock
  * @graph_mutex: Entities graph 

Re: [PATCH v8 48/55] [media] media_device: add a topology version field

2015-09-06 Thread Mauro Carvalho Chehab
Every time a graph object is added or removed, the version
of the topology changes. That's a requirement for the new
MEDIA_IOC_G_TOPOLOGY, in order to allow userspace to know
that the topology has changed after a previous call to it.

Signed-off-by: Mauro Carvalho Chehab 

diff --git a/drivers/media/media-entity.c b/drivers/media/media-entity.c
index 568553d41f5d..064515f2ba9b 100644
--- a/drivers/media/media-entity.c
+++ b/drivers/media/media-entity.c
@@ -185,6 +185,9 @@ void media_gobj_init(struct media_device *mdev,
list_add_tail(>list, >interfaces);
break;
}
+
+   mdev->topology_version++;
+
dev_dbg_obj(__func__, gobj);
 }
 
@@ -199,6 +202,8 @@ void media_gobj_remove(struct media_gobj *gobj)
 {
dev_dbg_obj(__func__, gobj);
 
+   gobj->mdev->topology_version++;
+
/* Remove the object from mdev list */
list_del(>list);
 }
diff --git a/include/media/media-device.h b/include/media/media-device.h
index 0d1b9c687454..1b12774a9ab4 100644
--- a/include/media/media-device.h
+++ b/include/media/media-device.h
@@ -41,6 +41,8 @@ struct device;
  * @bus_info:  Unique and stable device location identifier
  * @hw_revision: Hardware device revision
  * @driver_version: Device driver version
+ * @topology_version: Monotonic counter for storing the version of the graph
+ * topology. Should be incremented each time the topology changes.
  * @entity_id: Unique ID used on the last entity registered
  * @pad_id:Unique ID used on the last pad registered
  * @link_id:   Unique ID used on the last link registered
@@ -74,6 +76,8 @@ struct media_device {
u32 hw_revision;
u32 driver_version;
 
+   u32 topology_version;
+
u32 entity_id;
u32 pad_id;
u32 link_id;
-- 
2.4.3


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


Re: [PATCH v8 31/55] [media] media: add macros to check if subdev or V4L2 DMA

2015-09-06 Thread Mauro Carvalho Chehab
As we'll be removing entity subtypes from the Kernel, we need
to provide a way for drivers and core to check if a given
entity is represented by a V4L2 subdev or if it is an V4L2
I/O entity (typically with DMA).

Signed-off-by: Mauro Carvalho Chehab 

diff --git a/include/media/media-entity.h b/include/media/media-entity.h
index 4e36b1f2b2d7..220864319d21 100644
--- a/include/media/media-entity.h
+++ b/include/media/media-entity.h
@@ -220,6 +220,39 @@ static inline u32 media_gobj_gen_id(enum media_gobj_type 
type, u32 local_id)
return id;
 }
 
+static inline bool is_media_entity_v4l2_io(struct media_entity *entity)
+{
+   if (!entity)
+   return false;
+
+   switch (entity->type) {
+   case MEDIA_ENT_T_V4L2_VIDEO:
+   case MEDIA_ENT_T_V4L2_VBI:
+   case MEDIA_ENT_T_V4L2_SWRADIO:
+   return true;
+   default:
+   return false;
+   }
+}
+
+static inline bool is_media_entity_v4l2_subdev(struct media_entity *entity)
+{
+   if (!entity)
+   return false;
+
+   switch (entity->type) {
+   case MEDIA_ENT_T_V4L2_SUBDEV_SENSOR:
+   case MEDIA_ENT_T_V4L2_SUBDEV_FLASH:
+   case MEDIA_ENT_T_V4L2_SUBDEV_LENS:
+   case MEDIA_ENT_T_V4L2_SUBDEV_DECODER:
+   case MEDIA_ENT_T_V4L2_SUBDEV_TUNER:
+   return true;
+
+   default:
+   return false;
+   }
+}
+
 #define MEDIA_ENTITY_ENUM_MAX_DEPTH16
 #define MEDIA_ENTITY_ENUM_MAX_ID   64
 
-- 
2.4.3


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


Re: [PATCH v8 40/55] [media] media.h: don't use legacy entity macros at Kernel

2015-09-06 Thread Mauro Carvalho Chehab
Put the legacy MEDIA_ENT_* macros under a #ifndef __KERNEL__,
in order to be sure that none of those old symbols are used
inside the Kernel.

Signed-off-by: Mauro Carvalho Chehab 
Acked-by: Hans Verkuil 

diff --git a/include/uapi/linux/media.h b/include/uapi/linux/media.h
index f90147cb9b57..a1bd7afba110 100644
--- a/include/uapi/linux/media.h
+++ b/include/uapi/linux/media.h
@@ -105,6 +105,7 @@ struct media_device_info {
 #define MEDIA_ENT_T_DVB_CA (MEDIA_ENT_T_DVB_BASE + 4)
 #define MEDIA_ENT_T_DVB_NET_DECAP  (MEDIA_ENT_T_DVB_BASE + 5)
 
+#ifndef __KERNEL__
 /* Legacy symbols used to avoid userspace compilation breakages */
 #define MEDIA_ENT_TYPE_SHIFT   16
 #define MEDIA_ENT_TYPE_MASK0x00ff
@@ -118,6 +119,7 @@ struct media_device_info {
 #define MEDIA_ENT_T_DEVNODE_FB (MEDIA_ENT_T_DEVNODE + 2)
 #define MEDIA_ENT_T_DEVNODE_ALSA   (MEDIA_ENT_T_DEVNODE + 3)
 #define MEDIA_ENT_T_DEVNODE_DVB(MEDIA_ENT_T_DEVNODE + 4)
+#endif
 
 /* Entity types */
 
-- 
2.4.3


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


Re: [PATCH v8 44/55] [media] uapi/media.h: Add MEDIA_IOC_G_TOPOLOGY ioctl

2015-09-06 Thread Mauro Carvalho Chehab
Add a new ioctl that will report the entire topology on
one go.

Signed-off-by: Mauro Carvalho Chehab 

diff --git a/include/media/media-entity.h b/include/media/media-entity.h
index 7320cdc45833..2d5ad40254b7 100644
--- a/include/media/media-entity.h
+++ b/include/media/media-entity.h
@@ -181,6 +181,8 @@ struct media_interface {
  */
 struct media_intf_devnode {
struct media_interface  intf;
+
+   /* Should match the fields at media_v2_intf_devnode */
u32 major;
u32 minor;
 };
diff --git a/include/uapi/linux/media.h b/include/uapi/linux/media.h
index a1bd7afba110..b17f6763aff4 100644
--- a/include/uapi/linux/media.h
+++ b/include/uapi/linux/media.h
@@ -206,6 +206,10 @@ struct media_pad_desc {
 #define MEDIA_LNK_FL_IMMUTABLE (1 << 1)
 #define MEDIA_LNK_FL_DYNAMIC   (1 << 2)
 
+#define MEDIA_LNK_FL_LINK_TYPE (0xf << 28)
+#  define MEDIA_LNK_FL_DATA_LINK   (0 << 28)
+#  define MEDIA_LNK_FL_INTERFACE_LINK  (1 << 28)
+
 struct media_link_desc {
struct media_pad_desc source;
struct media_pad_desc sink;
@@ -249,11 +253,93 @@ struct media_links_enum {
 #define MEDIA_INTF_T_ALSA_RAWMIDI   (MEDIA_INTF_T_ALSA_BASE + 4)
 #define MEDIA_INTF_T_ALSA_HWDEP (MEDIA_INTF_T_ALSA_BASE + 5)
 
-/* TBD: declare the structs needed for the new G_TOPOLOGY ioctl */
+/*
+ * MC next gen API definitions
+ *
+ * NOTE: The declarations below are close to the MC RFC for the Media
+ *  Controller, the next generation. Yet, there are a few adjustments
+ *  to do, as we want to be able to have a functional API before
+ *  the MC properties change. Those will be properly marked below.
+ *  Please also notice that I removed "num_pads", "num_links",
+ *  from the proposal, as a proper userspace application will likely
+ *  use lists for pads/links, just as we intend to do in Kernelspace.
+ *  The API definition should be freed from fields that are bound to
+ *  some specific data structure.
+ *
+ * FIXME: Currently, I opted to name the new types as "media_v2", as this
+ *   won't cause any conflict with the Kernelspace namespace, nor with
+ *   the previous kAPI media_*_desc namespace. This can be changed
+ *   later, before the adding this API upstream.
+ */
+
+
+struct media_v2_entity {
+   __u32 id;
+   char name[64];  /* FIXME: move to a property? (RFC says so) */
+   __u16 reserved[14];
+};
+
+/* Should match the specific fields at media_intf_devnode */
+struct media_v2_intf_devnode {
+   __u32 major;
+   __u32 minor;
+};
+
+struct media_v2_interface {
+   __u32 id;
+   __u32 intf_type;
+   __u32 flags;
+   __u32 reserved[9];
+
+   union {
+   struct media_v2_intf_devnode devnode;
+   __u32 raw[16];
+   };
+};
+
+struct media_v2_pad {
+   __u32 id;
+   __u32 entity_id;
+   __u32 flags;
+   __u16 reserved[9];
+};
+
+struct media_v2_link {
+__u32 id;
+__u32 source_id;
+__u32 sink_id;
+__u32 flags;
+__u32 reserved[5];
+};
+
+struct media_v2_topology {
+   __u32 topology_version;
+
+   __u32 num_entities;
+   struct media_v2_entity *entities;
+
+   __u32 num_interfaces;
+   struct media_v2_interface *interfaces;
+
+   __u32 num_pads;
+   struct media_v2_pad *pads;
+
+   __u32 num_links;
+   struct media_v2_link *links;
+
+   struct {
+   __u32 reserved_num;
+   void *reserved_ptr;
+   } reserved_types[16];
+   __u32 reserved[8];
+};
+
+/* ioctls */
 
 #define MEDIA_IOC_DEVICE_INFO  _IOWR('|', 0x00, struct 
media_device_info)
 #define MEDIA_IOC_ENUM_ENTITIES_IOWR('|', 0x01, struct 
media_entity_desc)
 #define MEDIA_IOC_ENUM_LINKS   _IOWR('|', 0x02, struct 
media_links_enum)
 #define MEDIA_IOC_SETUP_LINK   _IOWR('|', 0x03, struct media_link_desc)
+#define MEDIA_IOC_G_TOPOLOGY   _IOWR('|', 0x04, struct 
media_v2_topology)
 
 #endif /* __LINUX_MEDIA_H */
-- 
2.4.3


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


Re: [PATCH v8 52/55] [media] media-device: remove interfaces and interface links

2015-09-06 Thread Mauro Carvalho Chehab
Just like what's done with entities, when the media controller is
unregistered, release any interface and interface links that
might still be there.

Signed-off-by: Mauro Carvalho Chehab 

diff --git a/drivers/media/media-device.c b/drivers/media/media-device.c
index 7c37aeab05bb..0238885fcc74 100644
--- a/drivers/media/media-device.c
+++ b/drivers/media/media-device.c
@@ -574,6 +574,22 @@ void media_device_unregister(struct media_device *mdev)
 {
struct media_entity *entity;
struct media_entity *next;
+   struct media_link *link, *tmp_link;
+   struct media_interface *intf, *tmp_intf;
+
+   /* Remove interface links from the media device */
+   list_for_each_entry_safe(link, tmp_link, >links,
+graph_obj.list) {
+   media_gobj_remove(>graph_obj);
+   kfree(link);
+   }
+
+   /* Remove all interfaces from the media device */
+   list_for_each_entry_safe(intf, tmp_intf, >interfaces,
+graph_obj.list) {
+   media_gobj_remove(>graph_obj);
+   kfree(intf);
+   }
 
list_for_each_entry_safe(entity, next, >entities, graph_obj.list)
media_device_unregister_entity(entity);
@@ -651,7 +667,6 @@ void media_device_unregister_entity(struct media_entity 
*entity)
/* Remove all data links that belong to this entity */
list_for_each_entry_safe(link, tmp, >links, list) {
media_gobj_remove(>graph_obj);
-   list_del(>list);
kfree(link);
}
 
diff --git a/drivers/media/media-entity.c b/drivers/media/media-entity.c
index a37ccd2edfd5..cd4d767644df 100644
--- a/drivers/media/media-entity.c
+++ b/drivers/media/media-entity.c
@@ -206,6 +206,10 @@ void media_gobj_remove(struct media_gobj *gobj)
 
/* Remove the object from mdev list */
list_del(>list);
+
+   /* Links have their own list - we need to drop them there too */
+   if (media_type(gobj) == MEDIA_GRAPH_LINK)
+   list_del(_to_link(gobj)->list);
 }
 
 /**
diff --git a/include/media/media-entity.h b/include/media/media-entity.h
index ca4a4f23362f..fb5f0e21f137 100644
--- a/include/media/media-entity.h
+++ b/include/media/media-entity.h
@@ -153,7 +153,7 @@ struct media_entity {
 };
 
 /**
- * struct media_intf_devnode - Define a Kernel API interface
+ * struct media_interface - Define a Kernel API interface
  *
  * @graph_obj: embedded graph object
  * @list:  Linked list used to find other interfaces that belong
@@ -163,6 +163,11 @@ struct media_entity {
  * uapi/media/media.h header, e. g.
  * MEDIA_INTF_T_*
  * @flags: Interface flags as defined at uapi/media/media.h
+ *
+ * NOTE: As media_device_unregister() will free the address of the
+ *  media_interface, this structure should be embedded as the first
+ *  element of the derived functions, in order for the address to be
+ *  the same.
  */
 struct media_interface {
struct media_gobj   graph_obj;
@@ -179,11 +184,11 @@ struct media_interface {
  * @minor: Minor number of a device node
  */
 struct media_intf_devnode {
-   struct media_interface  intf;
+   struct media_interface  intf; /* must be first field in struct */
 
/* Should match the fields at media_v2_intf_devnode */
-   u32 major;
-   u32 minor;
+   u32 major;
+   u32 minor;
 };
 
 static inline u32 media_entity_id(struct media_entity *entity)
-- 
2.4.3


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


Re: [PATCH v8 28/55] [media] uapi/media.h: Fix entity namespace

2015-09-06 Thread Mauro Carvalho Chehab
Now that interfaces got created, we need to fix the entity
namespace.

So, let's create a consistent new namespace and add backward
compatibility macros to keep the old namespace preserved.

Signed-off-by: Mauro Carvalho Chehab 

diff --git a/drivers/media/dvb-core/dvbdev.c b/drivers/media/dvb-core/dvbdev.c
index ada0738d26f2..dadcf1655070 100644
--- a/drivers/media/dvb-core/dvbdev.c
+++ b/drivers/media/dvb-core/dvbdev.c
@@ -230,17 +230,17 @@ static void dvb_create_media_entity(struct dvb_device 
*dvbdev,
 
switch (type) {
case DVB_DEVICE_FRONTEND:
-   dvbdev->entity->type = MEDIA_ENT_T_DEVNODE_DVB_FE;
+   dvbdev->entity->type = MEDIA_ENT_T_DVB_DEMOD;
dvbdev->pads[0].flags = MEDIA_PAD_FL_SINK;
dvbdev->pads[1].flags = MEDIA_PAD_FL_SOURCE;
break;
case DVB_DEVICE_DEMUX:
-   dvbdev->entity->type = MEDIA_ENT_T_DEVNODE_DVB_DEMUX;
+   dvbdev->entity->type = MEDIA_ENT_T_DVB_DEMUX;
dvbdev->pads[0].flags = MEDIA_PAD_FL_SINK;
dvbdev->pads[1].flags = MEDIA_PAD_FL_SOURCE;
break;
case DVB_DEVICE_CA:
-   dvbdev->entity->type = MEDIA_ENT_T_DEVNODE_DVB_CA;
+   dvbdev->entity->type = MEDIA_ENT_T_DVB_CA;
dvbdev->pads[0].flags = MEDIA_PAD_FL_SINK;
dvbdev->pads[1].flags = MEDIA_PAD_FL_SOURCE;
break;
@@ -439,7 +439,7 @@ EXPORT_SYMBOL(dvb_unregister_device);
 void dvb_create_media_graph(struct dvb_adapter *adap)
 {
struct media_device *mdev = adap->mdev;
-   struct media_entity *entity, *tuner = NULL, *fe = NULL;
+   struct media_entity *entity, *tuner = NULL, *demod = NULL;
struct media_entity *demux = NULL, *dvr = NULL, *ca = NULL;
struct media_interface *intf;
 
@@ -451,26 +451,26 @@ void dvb_create_media_graph(struct dvb_adapter *adap)
case MEDIA_ENT_T_V4L2_SUBDEV_TUNER:
tuner = entity;
break;
-   case MEDIA_ENT_T_DEVNODE_DVB_FE:
-   fe = entity;
+   case MEDIA_ENT_T_DVB_DEMOD:
+   demod = entity;
break;
-   case MEDIA_ENT_T_DEVNODE_DVB_DEMUX:
+   case MEDIA_ENT_T_DVB_DEMUX:
demux = entity;
break;
-   case MEDIA_ENT_T_DEVNODE_DVB_DVR:
+   case MEDIA_ENT_T_DVB_TSOUT:
dvr = entity;
break;
-   case MEDIA_ENT_T_DEVNODE_DVB_CA:
+   case MEDIA_ENT_T_DVB_CA:
ca = entity;
break;
}
}
 
-   if (tuner && fe)
-   media_create_pad_link(tuner, 0, fe, 0, 0);
+   if (tuner && demod)
+   media_create_pad_link(tuner, 0, demod, 0, 0);
 
-   if (fe && demux)
-   media_create_pad_link(fe, 1, demux, 0, MEDIA_LNK_FL_ENABLED);
+   if (demod && demux)
+   media_create_pad_link(demod, 1, demux, 0, MEDIA_LNK_FL_ENABLED);
 
if (demux && dvr)
media_create_pad_link(demux, 1, dvr, 0, MEDIA_LNK_FL_ENABLED);
diff --git a/include/uapi/linux/media.h b/include/uapi/linux/media.h
index aca828709bad..f8725b881a1d 100644
--- a/include/uapi/linux/media.h
+++ b/include/uapi/linux/media.h
@@ -42,31 +42,69 @@ struct media_device_info {
 
 #define MEDIA_ENT_ID_FLAG_NEXT (1 << 31)
 
+/*
+ * Base numbers for entity types
+ *
+ * Please notice that the huge gap of 16 bits for each base is overkill!
+ * 8 bits is more than enough to avoid starving entity types for each
+ * subsystem.
+ *
+ * However, It is kept this way just to avoid binary breakages with the
+ * namespace provided on legacy versions of this header.
+ */
+#define MEDIA_ENT_T_DVB_BASE   0x
+#define MEDIA_ENT_T_V4L2_BASE  0x0001
+#define MEDIA_ENT_T_V4L2_SUBDEV_BASE   0x0002
+
+/*
+ * V4L2 entities - Those are used for DMA (mmap/DMABUF) and
+ * read()/write() data I/O associated with the V4L2 devnodes.
+ */
+#define MEDIA_ENT_T_V4L2_VIDEO (MEDIA_ENT_T_V4L2_BASE + 1)
+   /*
+* Please notice that numbers between MEDIA_ENT_T_V4L2_BASE + 2 and
+* MEDIA_ENT_T_V4L2_BASE + 4 can't be used, as those values used
+* to be declared for FB, ALSA and DVB entities.
+* As those values were never actually used in practice, we're just
+* adding them as backward compatibility macros and keeping the
+* numberspace clean here. This way, we avoid breaking compilation,
+* in the case of having some userspace application using the old
+* symbols.
+*/
+#define MEDIA_ENT_T_V4L2_VBI   (MEDIA_ENT_T_V4L2_BASE + 5)
+#define MEDIA_ENT_T_V4L2_SWRADIO   (MEDIA_ENT_T_V4L2_BASE + 6)
+
+/* V4L2 Sub-device entities */
+#define 

Re: [PATCH v8 23/55] [media] media: add support to link interfaces and entities

2015-09-06 Thread Mauro Carvalho Chehab
Now that we have a new graph object called "interfaces", we
need to be able to link them to the entities.

Add a linked list to the interfaces to allow them to be
linked to the entities.

Signed-off-by: Mauro Carvalho Chehab 
Acked-by: Hans Verkuil 

diff --git a/drivers/media/media-entity.c b/drivers/media/media-entity.c
index f9c6c2a81903..8e17272936c9 100644
--- a/drivers/media/media-entity.c
+++ b/drivers/media/media-entity.c
@@ -869,6 +869,7 @@ struct media_intf_devnode *media_devnode_create(struct 
media_device *mdev,
 
intf->type = type;
intf->flags = flags;
+   INIT_LIST_HEAD(>links);
 
devnode->major = major;
devnode->minor = minor;
@@ -886,3 +887,40 @@ void media_devnode_remove(struct media_intf_devnode 
*devnode)
kfree(devnode);
 }
 EXPORT_SYMBOL_GPL(media_devnode_remove);
+
+struct media_link *media_create_intf_link(struct media_entity *entity,
+   struct media_interface *intf,
+   u32 flags)
+{
+   struct media_link *link;
+
+   link = media_add_link(>links);
+   if (link == NULL)
+   return NULL;
+
+   link->intf = intf;
+   link->entity = entity;
+   link->flags = flags;
+
+   /* Initialize graph object embedded at the new link */
+   media_gobj_init(intf->graph_obj.mdev, MEDIA_GRAPH_LINK,
+   >graph_obj);
+
+   return link;
+}
+EXPORT_SYMBOL_GPL(media_create_intf_link);
+
+
+static void __media_remove_intf_link(struct media_link *link)
+{
+   media_gobj_remove(>graph_obj);
+   kfree(link);
+}
+
+void media_remove_intf_link(struct media_link *link)
+{
+   mutex_lock(>graph_obj.mdev->graph_mutex);
+   __media_remove_intf_link(link);
+   mutex_unlock(>graph_obj.mdev->graph_mutex);
+}
+EXPORT_SYMBOL_GPL(media_remove_intf_link);
diff --git a/include/media/media-entity.h b/include/media/media-entity.h
index 6015e996f213..f67c01419268 100644
--- a/include/media/media-entity.h
+++ b/include/media/media-entity.h
@@ -78,10 +78,12 @@ struct media_link {
union {
struct media_gobj *gobj0;
struct media_pad *source;
+   struct media_interface *intf;
};
union {
struct media_gobj *gobj1;
struct media_pad *sink;
+   struct media_entity *entity;
};
struct media_link *reverse; /* Link in the reverse direction */
unsigned long flags;/* Link flags (MEDIA_LNK_FL_*) */
@@ -154,6 +156,7 @@ struct media_entity {
  * struct media_intf_devnode - Define a Kernel API interface
  *
  * @graph_obj: embedded graph object
+ * @links: List of links pointing to graph entities
  * @type:  Type of the interface as defined at the
  * uapi/media/media.h header, e. g.
  * MEDIA_INTF_T_*
@@ -161,6 +164,7 @@ struct media_entity {
  */
 struct media_interface {
struct media_gobj   graph_obj;
+   struct list_headlinks;
u32 type;
u32 flags;
 };
@@ -283,6 +287,11 @@ struct media_intf_devnode *media_devnode_create(struct 
media_device *mdev,
u32 major, u32 minor,
gfp_t gfp_flags);
 void media_devnode_remove(struct media_intf_devnode *devnode);
+struct media_link *media_create_intf_link(struct media_entity *entity,
+   struct media_interface *intf,
+   u32 flags);
+void media_remove_intf_link(struct media_link *link);
+
 #define media_entity_call(entity, operation, args...)  \
(((entity)->ops && (entity)->ops->operation) ?  \
 (entity)->ops->operation((entity) , ##args) : -ENOIOCTLCMD)
-- 
2.4.3


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


Re: [PATCH v8 41/55] [media] DocBook: update descriptions for the media controller entities

2015-09-06 Thread Mauro Carvalho Chehab
Cleanup the media controller entities description:
- remove MEDIA_ENT_T_DEVNODE and MEDIA_ENT_T_V4L2_SUBDEV entity
  types, as they don't mean anything;
- add MEDIA_ENT_T_UNKNOWN with a proper description;
- remove ALSA and FB entity types. Those should not be used, as
  the types are deprecated. We'll soon be adidng ALSA, but with
  a different entity namespace;
- improve the description of some entities.

Signed-off-by: Mauro Carvalho Chehab 

diff --git a/Documentation/DocBook/media/v4l/media-ioc-enum-entities.xml 
b/Documentation/DocBook/media/v4l/media-ioc-enum-entities.xml
index 32a783635649..bc101516e372 100644
--- a/Documentation/DocBook/media/v4l/media-ioc-enum-entities.xml
+++ b/Documentation/DocBook/media/v4l/media-ioc-enum-entities.xml
@@ -179,70 +179,65 @@
 

  
-   MEDIA_ENT_T_DEVNODE
-   Unknown device node
+   MEDIA_ENT_T_UNKNOWN and 
MEDIA_ENT_T_V4L2_SUBDEV_UNKNOWN
+   Unknown entity. That generally indicates that
+   a driver didn't initialize properly the entity, with is a Kernel 
bug
  
  
MEDIA_ENT_T_V4L2_VIDEO
-   V4L video, radio or vbi device node
+   V4L video streaming input or output entity
  
- 
-   MEDIA_ENT_T_DEVNODE_FB
-   Frame buffer device node
+   MEDIA_ENT_T_V4L2_VBI
+   V4L VBI streaming input or output entity
  
- 
-   MEDIA_ENT_T_DEVNODE_ALSA
-   ALSA card
+   MEDIA_ENT_T_V4L2_SWRADIO
+   V4L Sofware Digital Radio (SDR) streaming input or output 
entity
  
  
MEDIA_ENT_T_DVB_DEMOD
-   DVB frontend devnode
+   DVB demodulator entity
  
  
MEDIA_ENT_T_DVB_DEMUX
-   DVB demux devnode
+   DVB demux entity. Could be implemented on hardware or in 
Kernelspace
  
  
MEDIA_ENT_T_DVB_TSOUT
-   DVB DVR devnode
+   DVB Transport Stream output entity
  
  
MEDIA_ENT_T_DVB_CA
-   DVB CAM devnode
+   DVB Conditional Access module (CAM) entity
  
  
MEDIA_ENT_T_DVB_DEMOD_NET_DECAP
-   DVB network devnode
- 
- 
-   MEDIA_ENT_T_V4L2_SUBDEV
-   Unknown V4L sub-device
+   DVB network ULE/MLE desencapsulation entity. Could be 
implemented on hardware or in Kernelspace
  
  
MEDIA_ENT_T_V4L2_SUBDEV_SENSOR
-   Video sensor
+   Camera video sensor entity
  
  
MEDIA_ENT_T_V4L2_SUBDEV_FLASH
-   Flash controller
+   Flash controller entity
  
  
MEDIA_ENT_T_V4L2_SUBDEV_LENS
-   Lens controller
+   Lens controller entity
  
  
MEDIA_ENT_T_V4L2_SUBDEV_DECODER
-   Video decoder, the basic function of the video decoder is to
-   accept analogue video from a wide variety of sources such as
+   Analog video decoder, the basic function of the video decoder
+   is to accept analogue video from a wide variety of sources such as
broadcast, DVD players, cameras and video cassette recorders, in
-   either NTSC, PAL or HD format and still occasionally SECAM, separate
-   it into its component parts, luminance and chrominance, and output
+   either NTSC, PAL, SECAM or HD format, separating the stream
+   into its component parts, luminance and chrominance, and output
it in some digital video standard, with appropriate embedded timing
signals.
  
  
MEDIA_ENT_T_V4L2_SUBDEV_TUNER
-   TV and/or radio tuner
+   Digital TV, analog TV, radio and/or software radio 
tuner
  

   
-- 
2.4.3


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


Re: [PATCH v8 50/55] [media] media-entity: unregister entity links

2015-09-06 Thread Mauro Carvalho Chehab
Add functions to explicitly unregister all entity links.
This function is called automatically when an entity
link is destroyed.

Signed-off-by: Mauro Carvalho Chehab 
Acked-by: Hans Verkuil 

diff --git a/drivers/media/media-entity.c b/drivers/media/media-entity.c
index 064515f2ba9b..a37ccd2edfd5 100644
--- a/drivers/media/media-entity.c
+++ b/drivers/media/media-entity.c
@@ -903,6 +903,7 @@ EXPORT_SYMBOL_GPL(media_devnode_create);
 
 void media_devnode_remove(struct media_intf_devnode *devnode)
 {
+   media_remove_intf_links(>intf);
media_gobj_remove(>intf.graph_obj);
kfree(devnode);
 }
@@ -944,3 +945,25 @@ void media_remove_intf_link(struct media_link *link)
mutex_unlock(>graph_obj.mdev->graph_mutex);
 }
 EXPORT_SYMBOL_GPL(media_remove_intf_link);
+
+void __media_remove_intf_links(struct media_interface *intf)
+{
+   struct media_link *link, *tmp;
+
+   list_for_each_entry_safe(link, tmp, >links, list)
+   __media_remove_intf_link(link);
+
+}
+EXPORT_SYMBOL_GPL(__media_remove_intf_links);
+
+void media_remove_intf_links(struct media_interface *intf)
+{
+   /* Do nothing if the intf is not registered. */
+   if (intf->graph_obj.mdev == NULL)
+   return;
+
+   mutex_lock(>graph_obj.mdev->graph_mutex);
+   __media_remove_intf_links(intf);
+   mutex_unlock(>graph_obj.mdev->graph_mutex);
+}
+EXPORT_SYMBOL_GPL(media_remove_intf_links);
diff --git a/include/media/media-entity.h b/include/media/media-entity.h
index bc7eb6240795..ca4a4f23362f 100644
--- a/include/media/media-entity.h
+++ b/include/media/media-entity.h
@@ -318,6 +318,9 @@ struct media_link *media_create_intf_link(struct 
media_entity *entity,
struct media_interface *intf,
u32 flags);
 void media_remove_intf_link(struct media_link *link);
+void __media_remove_intf_links(struct media_interface *intf);
+void media_remove_intf_links(struct media_interface *intf);
+
 
 #define media_entity_call(entity, operation, args...)  \
(((entity)->ops && (entity)->ops->operation) ?  \
-- 
2.4.3


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


Re: [PATCH v8 42/55] [media] dvb: modify core to implement interfaces/entities at MC new gen

2015-09-06 Thread Mauro Carvalho Chehab
The Media Controller New Generation redefines the types for both
interfaces and entities to be used on DVB. Make the needed
changes at the DVB core for all interfaces, entities and
data and interface links to appear in the graph.

Signed-off-by: Mauro Carvalho Chehab 

diff --git a/drivers/media/dvb-core/dmxdev.c b/drivers/media/dvb-core/dmxdev.c
index d0e3f9d85f34..baaed28ee975 100644
--- a/drivers/media/dvb-core/dmxdev.c
+++ b/drivers/media/dvb-core/dmxdev.c
@@ -1242,9 +1242,9 @@ int dvb_dmxdev_init(struct dmxdev *dmxdev, struct 
dvb_adapter *dvb_adapter)
}
 
dvb_register_device(dvb_adapter, >dvbdev, _demux, dmxdev,
-   DVB_DEVICE_DEMUX);
+   DVB_DEVICE_DEMUX, dmxdev->filternum);
dvb_register_device(dvb_adapter, >dvr_dvbdev, _dvr,
-   dmxdev, DVB_DEVICE_DVR);
+   dmxdev, DVB_DEVICE_DVR, dmxdev->filternum);
 
dvb_ringbuffer_init(>dvr_buffer, NULL, 8192);
 
diff --git a/drivers/media/dvb-core/dvb_ca_en50221.c 
b/drivers/media/dvb-core/dvb_ca_en50221.c
index fb66184dc9b6..f82cd1ff4f3a 100644
--- a/drivers/media/dvb-core/dvb_ca_en50221.c
+++ b/drivers/media/dvb-core/dvb_ca_en50221.c
@@ -1695,7 +1695,7 @@ int dvb_ca_en50221_init(struct dvb_adapter *dvb_adapter,
pubca->private = ca;
 
/* register the DVB device */
-   ret = dvb_register_device(dvb_adapter, >dvbdev, _ca, ca, 
DVB_DEVICE_CA);
+   ret = dvb_register_device(dvb_adapter, >dvbdev, _ca, ca, 
DVB_DEVICE_CA, 0);
if (ret)
goto free_slot_info;
 
diff --git a/drivers/media/dvb-core/dvb_frontend.c 
b/drivers/media/dvb-core/dvb_frontend.c
index 2d06bcff0946..58601bfe0b8d 100644
--- a/drivers/media/dvb-core/dvb_frontend.c
+++ b/drivers/media/dvb-core/dvb_frontend.c
@@ -2754,7 +2754,7 @@ int dvb_register_frontend(struct dvb_adapter* dvb,
fe->dvb->num, fe->id, fe->ops.info.name);
 
dvb_register_device (fe->dvb, >dvbdev, _template,
-fe, DVB_DEVICE_FRONTEND);
+fe, DVB_DEVICE_FRONTEND, 0);
 
/*
 * Initialize the cache to the proper values according with the
diff --git a/drivers/media/dvb-core/dvb_net.c b/drivers/media/dvb-core/dvb_net.c
index b81e026edab3..14f51b68f4fe 100644
--- a/drivers/media/dvb-core/dvb_net.c
+++ b/drivers/media/dvb-core/dvb_net.c
@@ -1503,6 +1503,6 @@ int dvb_net_init (struct dvb_adapter *adap, struct 
dvb_net *dvbnet,
dvbnet->state[i] = 0;
 
return dvb_register_device(adap, >dvbdev, _net,
-dvbnet, DVB_DEVICE_NET);
+dvbnet, DVB_DEVICE_NET, 0);
 }
 EXPORT_SYMBOL(dvb_net_init);
diff --git a/drivers/media/dvb-core/dvbdev.c b/drivers/media/dvb-core/dvbdev.c
index dadcf1655070..6babc688801b 100644
--- a/drivers/media/dvb-core/dvbdev.c
+++ b/drivers/media/dvb-core/dvbdev.c
@@ -180,18 +180,86 @@ skip:
return -ENFILE;
 }
 
+static void dvb_create_tsout_entity(struct dvb_device *dvbdev,
+   const char *name, int npads)
+{
+#if defined(CONFIG_MEDIA_CONTROLLER_DVB)
+   int i, ret = 0;
+
+   dvbdev->tsout_pads = kcalloc(npads, sizeof(*dvbdev->tsout_pads),
+GFP_KERNEL);
+   if (!dvbdev->tsout_pads)
+   return;
+   dvbdev->tsout_entity = kcalloc(npads, sizeof(*dvbdev->tsout_entity),
+  GFP_KERNEL);
+   if (!dvbdev->tsout_entity) {
+   kfree(dvbdev->tsout_pads);
+   dvbdev->tsout_pads = NULL;
+   return;
+   }
+   for (i = 0; i < npads; i++) {
+   struct media_pad *pads = >tsout_pads[i];
+   struct media_entity *entity = >tsout_entity[i];
+
+   entity->name = kasprintf(GFP_KERNEL, "%s #%d", name, i);
+   if (!entity->name) {
+   ret = -ENOMEM;
+   break;
+   }
+
+   entity->type = MEDIA_ENT_T_DVB_TSOUT;
+   pads->flags = MEDIA_PAD_FL_SINK;
+
+   ret = media_entity_init(entity, 1, pads);
+   if (ret < 0)
+   break;
+
+   ret = media_device_register_entity(dvbdev->adapter->mdev,
+  entity);
+   if (ret < 0)
+   break;
+   }
+
+   if (!ret) {
+   dvbdev->tsout_num_entities = npads;
+   return;
+   }
+
+   for (i--; i >= 0; i--) {
+   media_device_unregister_entity(>tsout_entity[i]);
+   kfree(dvbdev->tsout_entity[i].name);
+   }
+
+   printk(KERN_ERR
+   "%s: media_device_register_entity failed for %s\n",
+   __func__, name);
+
+   kfree(dvbdev->tsout_entity);
+   kfree(dvbdev->tsout_pads);
+   dvbdev->tsout_entity = NULL;
+   

Re: [PATCH v8 53/55] [media] v4l2-core: create MC interfaces for devnodes

2015-09-06 Thread Mauro Carvalho Chehab
V4L2 device (and subdevice) nodes should create an interface, if the
Media Controller support is enabled.

Please notice that radio devices should not create an entity, as radio
input/output is either via wires or via ALSA.

Signed-off-by: Mauro Carvalho Chehab 

diff --git a/drivers/media/v4l2-core/v4l2-dev.c 
b/drivers/media/v4l2-core/v4l2-dev.c
index 44b330589787..07123dd569c4 100644
--- a/drivers/media/v4l2-core/v4l2-dev.c
+++ b/drivers/media/v4l2-core/v4l2-dev.c
@@ -194,9 +194,12 @@ static void v4l2_device_release(struct device *cd)
mutex_unlock(_lock);
 
 #if defined(CONFIG_MEDIA_CONTROLLER)
-   if (v4l2_dev->mdev &&
-   vdev->vfl_type != VFL_TYPE_SUBDEV)
-   media_device_unregister_entity(>entity);
+   if (v4l2_dev->mdev) {
+   /* Remove interfaces and interface links */
+   media_devnode_remove(vdev->intf_devnode);
+   if (vdev->entity.type != MEDIA_ENT_T_UNKNOWN)
+   media_device_unregister_entity(>entity);
+   }
 #endif
 
/* Do not call v4l2_device_put if there is no release callback set.
@@ -713,6 +716,92 @@ static void determine_valid_ioctls(struct video_device 
*vdev)
BASE_VIDIOC_PRIVATE);
 }
 
+
+static int video_register_media_controller(struct video_device *vdev, int type)
+{
+#if defined(CONFIG_MEDIA_CONTROLLER)
+   u32 intf_type;
+   int ret;
+
+   if (!vdev->v4l2_dev->mdev)
+   return 0;
+
+   vdev->entity.type = MEDIA_ENT_T_UNKNOWN;
+
+   switch (type) {
+   case VFL_TYPE_GRABBER:
+   intf_type = MEDIA_INTF_T_V4L_VIDEO;
+   vdev->entity.type = MEDIA_ENT_T_V4L2_VIDEO;
+   break;
+   case VFL_TYPE_VBI:
+   intf_type = MEDIA_INTF_T_V4L_VBI;
+   vdev->entity.type = MEDIA_ENT_T_V4L2_VBI;
+   break;
+   case VFL_TYPE_SDR:
+   intf_type = MEDIA_INTF_T_V4L_SWRADIO;
+   vdev->entity.type = MEDIA_ENT_T_V4L2_SWRADIO;
+   break;
+   case VFL_TYPE_RADIO:
+   intf_type = MEDIA_INTF_T_V4L_RADIO;
+   /*
+* Radio doesn't have an entity at the V4L2 side to represent
+* radio input or output. Instead, the audio input/output goes
+* via either physical wires or ALSA.
+*/
+   break;
+   case VFL_TYPE_SUBDEV:
+   intf_type = MEDIA_INTF_T_V4L_SUBDEV;
+   /* Entity will be created via v4l2_device_register_subdev() */
+   break;
+   default:
+   return 0;
+   }
+
+   if (vdev->entity.type != MEDIA_ENT_T_UNKNOWN) {
+   vdev->entity.name = vdev->name;
+
+   /* Needed just for backward compatibility with legacy MC API */
+   vdev->entity.info.dev.major = VIDEO_MAJOR;
+   vdev->entity.info.dev.minor = vdev->minor;
+
+   ret = media_device_register_entity(vdev->v4l2_dev->mdev,
+  >entity);
+   if (ret < 0) {
+   printk(KERN_WARNING
+   "%s: media_device_register_entity failed\n",
+   __func__);
+   return ret;
+   }
+   }
+
+   vdev->intf_devnode = media_devnode_create(vdev->v4l2_dev->mdev,
+ intf_type,
+ 0, VIDEO_MAJOR,
+ vdev->minor,
+ GFP_KERNEL);
+   if (!vdev->intf_devnode) {
+   media_device_unregister_entity(>entity);
+   return -ENOMEM;
+   }
+
+   if (vdev->entity.type != MEDIA_ENT_T_UNKNOWN) {
+   struct media_link *link;
+
+   link = media_create_intf_link(>entity,
+ >intf_devnode->intf, 0);
+   if (!link) {
+   media_devnode_remove(vdev->intf_devnode);
+   media_device_unregister_entity(>entity);
+   return -ENOMEM;
+   }
+   }
+
+   /* FIXME: how to create the other interface links? */
+
+#endif
+   return 0;
+}
+
 /**
  * __video_register_device - register video4linux devices
  * @vdev: video device structure we want to register
@@ -908,22 +997,9 @@ int __video_register_device(struct video_device *vdev, int 
type, int nr,
/* Increase v4l2_device refcount */
v4l2_device_get(vdev->v4l2_dev);
 
-#if defined(CONFIG_MEDIA_CONTROLLER)
/* Part 5: Register the entity. */
-   if (vdev->v4l2_dev->mdev &&
-   vdev->vfl_type != VFL_TYPE_SUBDEV) {
-   vdev->entity.type = MEDIA_ENT_T_V4L2_VIDEO;
-   vdev->entity.name = vdev->name;
-   

Re: [PATCH v8 38/55] [media] v4l2-subdev: use MEDIA_ENT_T_UNKNOWN for new subdevs

2015-09-06 Thread Mauro Carvalho Chehab
Instead of abusing MEDIA_ENT_T_V4L2_SUBDEV, initialize
new subdev entities as MEDIA_ENT_T_UNKNOWN.

Signed-off-by: Mauro Carvalho Chehab 
Acked-by: Hans Verkuil 

diff --git a/drivers/media/media-device.c b/drivers/media/media-device.c
index 659507bce63f..134fe7510195 100644
--- a/drivers/media/media-device.c
+++ b/drivers/media/media-device.c
@@ -435,6 +435,12 @@ int __must_check media_device_register_entity(struct 
media_device *mdev,
 {
int i;
 
+   if (entity->type == MEDIA_ENT_T_V4L2_SUBDEV_UNKNOWN ||
+   entity->type == MEDIA_ENT_T_UNKNOWN)
+   dev_warn(mdev->dev,
+"Entity type for entity %s was not initialized!\n",
+entity->name);
+
/* Warn if we apparently re-register an entity */
WARN_ON(entity->graph_obj.mdev != NULL);
entity->graph_obj.mdev = mdev;
diff --git a/drivers/media/v4l2-core/v4l2-subdev.c 
b/drivers/media/v4l2-core/v4l2-subdev.c
index 60da43772de9..b3bcc8253182 100644
--- a/drivers/media/v4l2-core/v4l2-subdev.c
+++ b/drivers/media/v4l2-core/v4l2-subdev.c
@@ -584,7 +584,7 @@ void v4l2_subdev_init(struct v4l2_subdev *sd, const struct 
v4l2_subdev_ops *ops)
sd->host_priv = NULL;
 #if defined(CONFIG_MEDIA_CONTROLLER)
sd->entity.name = sd->name;
-   sd->entity.type = MEDIA_ENT_T_V4L2_SUBDEV;
+   sd->entity.type = MEDIA_ENT_T_V4L2_SUBDEV_UNKNOWN;
 #endif
 }
 EXPORT_SYMBOL(v4l2_subdev_init);
diff --git a/include/uapi/linux/media.h b/include/uapi/linux/media.h
index f8725b881a1d..3d6210095336 100644
--- a/include/uapi/linux/media.h
+++ b/include/uapi/linux/media.h
@@ -42,6 +42,14 @@ struct media_device_info {
 
 #define MEDIA_ENT_ID_FLAG_NEXT (1 << 31)
 
+/* Used values for media_entity_desc::type */
+
+/*
+ * Initial value to be used when a new entity is created
+ * Drivers should change it to something useful
+ */
+#define MEDIA_ENT_T_UNKNOWN0x
+
 /*
  * Base numbers for entity types
  *
@@ -75,6 +83,15 @@ struct media_device_info {
 #define MEDIA_ENT_T_V4L2_SWRADIO   (MEDIA_ENT_T_V4L2_BASE + 6)
 
 /* V4L2 Sub-device entities */
+
+   /*
+* Subdevs are initialized with MEDIA_ENT_T_V4L2_SUBDEV_UNKNOWN,
+* in order to preserve backward compatibility.
+* Drivers should change to the proper subdev type before
+* registering the entity.
+*/
+#define MEDIA_ENT_T_V4L2_SUBDEV_UNKNOWNMEDIA_ENT_T_V4L2_SUBDEV_BASE
+
 #define MEDIA_ENT_T_V4L2_SUBDEV_SENSOR (MEDIA_ENT_T_V4L2_SUBDEV_BASE + 1)
 #define MEDIA_ENT_T_V4L2_SUBDEV_FLASH  (MEDIA_ENT_T_V4L2_SUBDEV_BASE + 2)
 #define MEDIA_ENT_T_V4L2_SUBDEV_LENS   (MEDIA_ENT_T_V4L2_SUBDEV_BASE + 3)
-- 
2.4.3


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


Re: [PATCH v8 49/55] [media] media-device: add support for MEDIA_IOC_G_TOPOLOGY ioctl

2015-09-06 Thread Mauro Carvalho Chehab
Add support for the new MEDIA_IOC_G_TOPOLOGY ioctl, according
with the RFC for the MC next generation.

Signed-off-by: Mauro Carvalho Chehab 

diff --git a/drivers/media/media-device.c b/drivers/media/media-device.c
index 5b2c9f7fcd45..96a476eeb16e 100644
--- a/drivers/media/media-device.c
+++ b/drivers/media/media-device.c
@@ -232,6 +232,156 @@ static long media_device_setup_link(struct media_device 
*mdev,
return ret;
 }
 
+static long __media_device_get_topology(struct media_device *mdev,
+ struct media_v2_topology *topo)
+{
+   struct media_entity *entity;
+   struct media_interface *intf;
+   struct media_pad *pad;
+   struct media_link *link;
+   struct media_v2_entity uentity;
+   struct media_v2_interface uintf;
+   struct media_v2_pad upad;
+   struct media_v2_link ulink;
+   int ret = 0, i;
+
+   topo->topology_version = mdev->topology_version;
+
+   /* Get entities and number of entities */
+   i = 0;
+   media_device_for_each_entity(entity, mdev) {
+   i++;
+
+   if (ret || !topo->entities)
+   continue;
+
+   if (i > topo->num_entities) {
+   ret = -ENOSPC;
+   continue;
+   }
+
+   /* Copy fields to userspace struct if not error */
+   memset(, 0, sizeof(uentity));
+   uentity.id = entity->graph_obj.id;
+   strncpy(uentity.name, entity->name,
+   sizeof(uentity.name));
+
+   if (copy_to_user(>entities[i - 1], , 
sizeof(uentity)))
+   ret = -EFAULT;
+   }
+   topo->num_entities = i;
+
+   /* Get interfaces and number of interfaces */
+   i = 0;
+   media_device_for_each_intf(intf, mdev) {
+   i++;
+
+   if (ret || !topo->interfaces)
+   continue;
+
+   if (i > topo->num_interfaces) {
+   ret = -ENOSPC;
+   continue;
+   }
+
+   memset(, 0, sizeof(uintf));
+
+   /* Copy intf fields to userspace struct */
+   uintf.id = intf->graph_obj.id;
+   uintf.intf_type = intf->type;
+   uintf.flags = intf->flags;
+
+   if (media_type(>graph_obj) == MEDIA_GRAPH_INTF_DEVNODE) {
+   struct media_intf_devnode *devnode;
+
+   devnode = intf_to_devnode(intf);
+
+   uintf.devnode.major = devnode->major;
+   uintf.devnode.minor = devnode->minor;
+   }
+
+   if (copy_to_user(>interfaces[i - 1], , 
sizeof(uintf)))
+   ret = -EFAULT;
+   }
+   topo->num_interfaces = i;
+
+   /* Get pads and number of pads */
+   i = 0;
+   media_device_for_each_pad(pad, mdev) {
+   i++;
+
+   if (ret || !topo->pads)
+   continue;
+
+   if (i > topo->num_pads) {
+   ret = -ENOSPC;
+   continue;
+   }
+
+   memset(, 0, sizeof(upad));
+
+   /* Copy pad fields to userspace struct */
+   upad.id = pad->graph_obj.id;
+   upad.entity_id = pad->entity->graph_obj.id;
+   upad.flags = pad->flags;
+
+   if (copy_to_user(>pads[i - 1], , sizeof(upad)))
+   ret = -EFAULT;
+   }
+   topo->num_pads = i;
+
+   /* Get links and number of links */
+   i = 0;
+   media_device_for_each_link(link, mdev) {
+   i++;
+
+   if (ret || !topo->links)
+   continue;
+
+   if (i > topo->num_links) {
+   ret = -ENOSPC;
+   continue;
+   }
+
+   memset(, 0, sizeof(ulink));
+
+   /* Copy link fields to userspace struct */
+   ulink.id = link->graph_obj.id;
+   ulink.source_id = link->gobj0->id;
+   ulink.sink_id = link->gobj1->id;
+   ulink.flags = link->flags;
+
+   if (media_type(link->gobj0) != MEDIA_GRAPH_PAD)
+   ulink.flags |= MEDIA_LNK_FL_INTERFACE_LINK;
+
+   if (copy_to_user(>links[i - 1], , sizeof(ulink)))
+   ret = -EFAULT;
+   }
+   topo->num_links = i;
+
+   return ret;
+}
+
+static long media_device_get_topology(struct media_device *mdev,
+ struct media_v2_topology __user *utopo)
+{
+   struct media_v2_topology ktopo;
+   int ret;
+
+   ret = copy_from_user(, utopo, sizeof(ktopo));
+
+   if (ret < 0)
+   return ret;
+
+   ret = __media_device_get_topology(mdev, );
+   if (ret < 0)
+   return ret;
+
+   ret = copy_to_user(utopo, , 

Re: [PATCH v8 27/55] [media] dvbdev: add support for indirect interface links

2015-09-06 Thread Mauro Carvalho Chehab
Some interfaces indirectly control multiple entities.
Add support for those.

Signed-off-by: Mauro Carvalho Chehab 
Acked-by: Hans Verkuil 

diff --git a/drivers/media/dvb-core/dvbdev.c b/drivers/media/dvb-core/dvbdev.c
index 6bf61d42c017..ada0738d26f2 100644
--- a/drivers/media/dvb-core/dvbdev.c
+++ b/drivers/media/dvb-core/dvbdev.c
@@ -441,6 +441,7 @@ void dvb_create_media_graph(struct dvb_adapter *adap)
struct media_device *mdev = adap->mdev;
struct media_entity *entity, *tuner = NULL, *fe = NULL;
struct media_entity *demux = NULL, *dvr = NULL, *ca = NULL;
+   struct media_interface *intf;
 
if (!mdev)
return;
@@ -476,6 +477,16 @@ void dvb_create_media_graph(struct dvb_adapter *adap)
 
if (demux && ca)
media_create_pad_link(demux, 1, ca, 0, MEDIA_LNK_FL_ENABLED);
+
+   /* Create indirect interface links for FE->tuner, DVR->demux and CA->ca 
*/
+   list_for_each_entry(intf, >interfaces, list) {
+   if (intf->type == MEDIA_INTF_T_DVB_CA && ca)
+   media_create_intf_link(ca, intf, 0);
+   if (intf->type == MEDIA_INTF_T_DVB_FE && tuner)
+   media_create_intf_link(tuner, intf, 0);
+   if (intf->type == MEDIA_INTF_T_DVB_DVR && demux)
+   media_create_intf_link(demux, intf, 0);
+   }
 }
 EXPORT_SYMBOL_GPL(dvb_create_media_graph);
 #endif
-- 
2.4.3


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


Re: [PATCH v8 43/55] [media] media: report if a pad is sink or source at debug msg

2015-09-06 Thread Mauro Carvalho Chehab
Sometimes, it is important to see if the created pad is
sink or source. Add info to track that.

Signed-off-by: Mauro Carvalho Chehab 

diff --git a/drivers/media/media-entity.c b/drivers/media/media-entity.c
index d8038a53f945..6ed5eef88593 100644
--- a/drivers/media/media-entity.c
+++ b/drivers/media/media-entity.c
@@ -121,8 +121,11 @@ static void dev_dbg_obj(const char *event_name,  struct 
media_gobj *gobj)
struct media_pad *pad = gobj_to_pad(gobj);
 
dev_dbg(gobj->mdev->dev,
-   "%s: id 0x%08x pad#%d: '%s':%d\n",
-   event_name, gobj->id, media_localid(gobj),
+   "%s: id 0x%08x %s%spad#%d: '%s':%d\n",
+   event_name, gobj->id,
+   pad->flags & MEDIA_PAD_FL_SINK   ? "  sink " : "",
+   pad->flags & MEDIA_PAD_FL_SOURCE ? "source " : "",
+   media_localid(gobj),
pad->entity->name, pad->index);
break;
}
-- 
2.4.3


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


Re: [PATCH v8 15/55] [media] uapi/media.h: Declare interface types for ALSA

2015-09-06 Thread Mauro Carvalho Chehab
Declare the interface types to be used on alsa for the new
G_TOPOLOGY ioctl.

Signed-off-by: Mauro Carvalho Chehab 

diff --git a/drivers/media/media-entity.c b/drivers/media/media-entity.c
index dc679dfe8ade..27fce6224972 100644
--- a/drivers/media/media-entity.c
+++ b/drivers/media/media-entity.c
@@ -74,6 +74,18 @@ static inline const char *intf_type(struct media_interface 
*intf)
return "v4l2-subdev";
case MEDIA_INTF_T_V4L_SWRADIO:
return "swradio";
+   case MEDIA_INTF_T_ALSA_PCM_CAPTURE:
+   return "pcm-capture";
+   case MEDIA_INTF_T_ALSA_PCM_PLAYBACK:
+   return "pcm-playback";
+   case MEDIA_INTF_T_ALSA_CONTROL:
+   return "alsa-control";
+   case MEDIA_INTF_T_ALSA_COMPRESS:
+   return "compress";
+   case MEDIA_INTF_T_ALSA_RAWMIDI:
+   return "rawmidi";
+   case MEDIA_INTF_T_ALSA_HWDEP:
+   return "hwdep";
default:
return "unknown-intf";
}
diff --git a/include/uapi/linux/media.h b/include/uapi/linux/media.h
index 3ad3d6be293f..aca828709bad 100644
--- a/include/uapi/linux/media.h
+++ b/include/uapi/linux/media.h
@@ -171,6 +171,7 @@ struct media_links_enum {
 
 #define MEDIA_INTF_T_DVB_BASE  0x0100
 #define MEDIA_INTF_T_V4L_BASE  0x0200
+#define MEDIA_INTF_T_ALSA_BASE 0x0300
 
 /* Interface types */
 
@@ -186,6 +187,13 @@ struct media_links_enum {
 #define MEDIA_INTF_T_V4L_SUBDEV (MEDIA_INTF_T_V4L_BASE + 3)
 #define MEDIA_INTF_T_V4L_SWRADIO (MEDIA_INTF_T_V4L_BASE + 4)
 
+#define MEDIA_INTF_T_ALSA_PCM_CAPTURE   (MEDIA_INTF_T_ALSA_BASE)
+#define MEDIA_INTF_T_ALSA_PCM_PLAYBACK  (MEDIA_INTF_T_ALSA_BASE + 1)
+#define MEDIA_INTF_T_ALSA_CONTROL   (MEDIA_INTF_T_ALSA_BASE + 2)
+#define MEDIA_INTF_T_ALSA_COMPRESS  (MEDIA_INTF_T_ALSA_BASE + 3)
+#define MEDIA_INTF_T_ALSA_RAWMIDI   (MEDIA_INTF_T_ALSA_BASE + 4)
+#define MEDIA_INTF_T_ALSA_HWDEP (MEDIA_INTF_T_ALSA_BASE + 5)
+
 /* TBD: declare the structs needed for the new G_TOPOLOGY ioctl */
 
 #define MEDIA_IOC_DEVICE_INFO  _IOWR('|', 0x00, struct 
media_device_info)
-- 
2.4.3


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


[PATCH] [media] VIDEO_RENESAS_JPU should depend on HAS_DMA

2015-09-06 Thread Geert Uytterhoeven
If NO_DMA=y:

warning: (VIDEO_STI_BDISP && VIDEO_RENESAS_JPU && VIDEO_DM365_VPFE && 
VIDEO_OMAP4) selects VIDEOBUF2_DMA_CONTIG which has unmet direct dependencies 
(MEDIA_SUPPORT && HAS_DMA)

drivers/media/v4l2-core/videobuf2-dma-contig.c: In function ‘vb2_dc_mmap’:
drivers/media/v4l2-core/videobuf2-dma-contig.c:207: error: implicit 
declaration of function ‘dma_mmap_coherent’
drivers/media/v4l2-core/videobuf2-dma-contig.c: In function 
‘vb2_dc_get_base_sgt’:
drivers/media/v4l2-core/videobuf2-dma-contig.c:390: error: implicit 
declaration of function ‘dma_get_sgtable’

VIDEO_RENESAS_JPU selects VIDEOBUF2_DMA_CONTIG, which bypasses its
dependency on HAS_DMA.  Make VIDEO_RENESAS_JPU depend on HAS_DMA to fix
this.

Signed-off-by: Geert Uytterhoeven 
---
 drivers/media/platform/Kconfig | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/drivers/media/platform/Kconfig b/drivers/media/platform/Kconfig
index dc75694ac12d2d57..ccbc9742cb7aeca4 100644
--- a/drivers/media/platform/Kconfig
+++ b/drivers/media/platform/Kconfig
@@ -233,7 +233,7 @@ config VIDEO_SH_VEU
 
 config VIDEO_RENESAS_JPU
tristate "Renesas JPEG Processing Unit"
-   depends on VIDEO_DEV && VIDEO_V4L2
+   depends on VIDEO_DEV && VIDEO_V4L2 && HAS_DMA
depends on ARCH_SHMOBILE || COMPILE_TEST
select VIDEOBUF2_DMA_CONTIG
select V4L2_MEM2MEM_DEV
-- 
1.9.1

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


[PATCH v5 2/4] media: pxa_camera: move interrupt to tasklet

2015-09-06 Thread Robert Jarzmik
In preparation for dmaengine conversion, move the camera interrupt
handling into a tasklet. This won't change the global flow, as this
interrupt is only used to detect the end of frame and activate DMA fifos
handling.

Signed-off-by: Robert Jarzmik 
---
 drivers/media/platform/soc_camera/pxa_camera.c | 44 +-
 1 file changed, 29 insertions(+), 15 deletions(-)

diff --git a/drivers/media/platform/soc_camera/pxa_camera.c 
b/drivers/media/platform/soc_camera/pxa_camera.c
index d4e887841372..db041a5ed444 100644
--- a/drivers/media/platform/soc_camera/pxa_camera.c
+++ b/drivers/media/platform/soc_camera/pxa_camera.c
@@ -223,6 +223,7 @@ struct pxa_camera_dev {
 
struct pxa_buffer   *active;
struct pxa_dma_desc *sg_tail[3];
+   struct tasklet_struct   task_eof;
 
u32 save_cicr[5];
 };
@@ -597,6 +598,7 @@ static void pxa_camera_start_capture(struct pxa_camera_dev 
*pcdev)
unsigned long cicr0;
 
dev_dbg(pcdev->soc_host.v4l2_dev.dev, "%s\n", __func__);
+   __raw_writel(__raw_readl(pcdev->base + CISR), pcdev->base + CISR);
/* Enable End-Of-Frame Interrupt */
cicr0 = __raw_readl(pcdev->base + CICR0) | CICR0_ENB;
cicr0 &= ~CICR0_EOFM;
@@ -914,13 +916,35 @@ static void pxa_camera_deactivate(struct pxa_camera_dev 
*pcdev)
clk_disable_unprepare(pcdev->clk);
 }
 
-static irqreturn_t pxa_camera_irq(int irq, void *data)
+static void pxa_camera_eof(unsigned long arg)
 {
-   struct pxa_camera_dev *pcdev = data;
-   unsigned long status, cifr, cicr0;
+   struct pxa_camera_dev *pcdev = (struct pxa_camera_dev *)arg;
+   unsigned long cifr;
struct pxa_buffer *buf;
struct videobuf_buffer *vb;
 
+   dev_dbg(pcdev->soc_host.v4l2_dev.dev,
+   "Camera interrupt status 0x%x\n",
+   __raw_readl(pcdev->base + CISR));
+
+   /* Reset the FIFOs */
+   cifr = __raw_readl(pcdev->base + CIFR) | CIFR_RESET_F;
+   __raw_writel(cifr, pcdev->base + CIFR);
+
+   pcdev->active = list_first_entry(>capture,
+struct pxa_buffer, vb.queue);
+   vb = >active->vb;
+   buf = container_of(vb, struct pxa_buffer, vb);
+   pxa_videobuf_set_actdma(pcdev, buf);
+
+   pxa_dma_start_channels(pcdev);
+}
+
+static irqreturn_t pxa_camera_irq(int irq, void *data)
+{
+   struct pxa_camera_dev *pcdev = data;
+   unsigned long status, cicr0;
+
status = __raw_readl(pcdev->base + CISR);
dev_dbg(pcdev->soc_host.v4l2_dev.dev,
"Camera interrupt status 0x%lx\n", status);
@@ -931,20 +955,9 @@ static irqreturn_t pxa_camera_irq(int irq, void *data)
__raw_writel(status, pcdev->base + CISR);
 
if (status & CISR_EOF) {
-   /* Reset the FIFOs */
-   cifr = __raw_readl(pcdev->base + CIFR) | CIFR_RESET_F;
-   __raw_writel(cifr, pcdev->base + CIFR);
-
-   pcdev->active = list_first_entry(>capture,
-  struct pxa_buffer, vb.queue);
-   vb = >active->vb;
-   buf = container_of(vb, struct pxa_buffer, vb);
-   pxa_videobuf_set_actdma(pcdev, buf);
-
-   pxa_dma_start_channels(pcdev);
-
cicr0 = __raw_readl(pcdev->base + CICR0) | CICR0_EOFM;
__raw_writel(cicr0, pcdev->base + CICR0);
+   tasklet_schedule(>task_eof);
}
 
return IRQ_HANDLED;
@@ -1839,6 +1852,7 @@ static int pxa_camera_probe(struct platform_device *pdev)
pcdev->soc_host.priv= pcdev;
pcdev->soc_host.v4l2_dev.dev= >dev;
pcdev->soc_host.nr  = pdev->id;
+   tasklet_init(>task_eof, pxa_camera_eof, (unsigned long)pcdev);
 
err = soc_camera_host_register(>soc_host);
if (err)
-- 
2.1.4

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


Charity Project Worth $1,000,000.00 Dollars

2015-09-06 Thread Bill William And Andrea Groner


My wife and I have awarded you with a donation of 1 million Dollars from 
part of our Jackpot Lottery of 50 Million Dollars, respond with your details 
for claims.

http://www.huffingtonpost.ca/2014/07/22/50-million-edmonton-lotto_n_5610890.html

We await your earliest response and God Bless you.

Best of luck.

Bill And Andrea Groner
--
To unsubscribe from this list: send the line "unsubscribe linux-media" in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html


Charity Project Worth $1,000,000.00 Dollars

2015-09-06 Thread Bill William And Andrea Groner


My wife and I have awarded you with a donation of 1 million Dollars from 
part of our Jackpot Lottery of 50 Million Dollars, respond with your details 
for claims.

http://www.huffingtonpost.ca/2014/07/22/50-million-edmonton-lotto_n_5610890.html

We await your earliest response and God Bless you.

Best of luck.

Bill And Andrea Groner
--
To unsubscribe from this list: send the line "unsubscribe linux-media" in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html


[PATCH 07/18] [media] dvbdev: returns error if graph object creation fails

2015-09-06 Thread Mauro Carvalho Chehab
Right now, if something gets wrong at dvb_create_media_entity()
or at dvb_create_media_graph(), the device will still be
registered.

Change the logic to properly handle it and free all media graph
objects if something goes wrong at dvb_register_device().

Also, change the logic at dvb_create_media_graph() to return
an error code if something goes wrong. It is up to the
caller to implement the right logic and to call
dvb_unregister_device() to unregister the already-created
objects.

While here, add a missing logic to unregister the created
interfaces.

Signed-off-by: Mauro Carvalho Chehab 

diff --git a/drivers/media/dvb-core/dvbdev.c b/drivers/media/dvb-core/dvbdev.c
index 5c4fb41060b4..5c51084a331a 100644
--- a/drivers/media/dvb-core/dvbdev.c
+++ b/drivers/media/dvb-core/dvbdev.c
@@ -183,7 +183,29 @@ skip:
return -ENFILE;
 }
 
-static void dvb_create_tsout_entity(struct dvb_device *dvbdev,
+static void dvb_media_device_free(struct dvb_device *dvbdev)
+{
+#if defined(CONFIG_MEDIA_CONTROLLER_DVB)
+   if (dvbdev->entity) {
+   int i;
+
+   for (i = 0; i < dvbdev->tsout_num_entities; i++) {
+   
media_device_unregister_entity(>tsout_entity[i]);
+   kfree(dvbdev->tsout_entity[i].name);
+   }
+   media_device_unregister_entity(dvbdev->entity);
+
+   kfree(dvbdev->entity);
+   kfree(dvbdev->pads);
+   kfree(dvbdev->tsout_entity);
+   kfree(dvbdev->tsout_pads);
+   }
+   if (dvbdev->intf_devnode)
+   media_devnode_remove(dvbdev->intf_devnode);
+#endif
+}
+
+static int dvb_create_tsout_entity(struct dvb_device *dvbdev,
const char *name, int npads)
 {
 #if defined(CONFIG_MEDIA_CONTROLLER_DVB)
@@ -192,77 +214,60 @@ static void dvb_create_tsout_entity(struct dvb_device 
*dvbdev,
dvbdev->tsout_pads = kcalloc(npads, sizeof(*dvbdev->tsout_pads),
 GFP_KERNEL);
if (!dvbdev->tsout_pads)
-   return;
+   return -ENOMEM;
+
dvbdev->tsout_entity = kcalloc(npads, sizeof(*dvbdev->tsout_entity),
   GFP_KERNEL);
-   if (!dvbdev->tsout_entity) {
-   kfree(dvbdev->tsout_pads);
-   dvbdev->tsout_pads = NULL;
-   return;
-   }
+   if (!dvbdev->tsout_entity)
+   return -ENOMEM;
+
for (i = 0; i < npads; i++) {
struct media_pad *pads = >tsout_pads[i];
struct media_entity *entity = >tsout_entity[i];
 
entity->name = kasprintf(GFP_KERNEL, "%s #%d", name, i);
-   if (!entity->name) {
-   ret = -ENOMEM;
-   break;
-   }
+   if (!entity->name)
+   return ret;
 
entity->type = MEDIA_ENT_T_DVB_TSOUT;
pads->flags = MEDIA_PAD_FL_SINK;
 
ret = media_entity_init(entity, 1, pads);
if (ret < 0)
-   break;
+   return ret;
 
ret = media_device_register_entity(dvbdev->adapter->mdev,
   entity);
if (ret < 0)
-   break;
+   return ret;
}
-
-   if (!ret) {
-   dvbdev->tsout_num_entities = npads;
-   return;
-   }
-
-   for (i--; i >= 0; i--) {
-   media_device_unregister_entity(>tsout_entity[i]);
-   kfree(dvbdev->tsout_entity[i].name);
-   }
-
-   printk(KERN_ERR
-   "%s: media_device_register_entity failed for %s\n",
-   __func__, name);
-
-   kfree(dvbdev->tsout_entity);
-   kfree(dvbdev->tsout_pads);
-   dvbdev->tsout_entity = NULL;
-   dvbdev->tsout_pads = NULL;
 #endif
+   return 0;
 }
 
 #define DEMUX_TSOUT"demux-tsout"
 #define DVR_TSOUT  "dvr-tsout"
 
-static void dvb_create_media_entity(struct dvb_device *dvbdev,
-   int type, int demux_sink_pads)
+static int dvb_create_media_entity(struct dvb_device *dvbdev,
+  int type, int demux_sink_pads)
 {
 #if defined(CONFIG_MEDIA_CONTROLLER_DVB)
-   int i, ret = 0, npads;
+   int i, ret, npads;
 
switch (type) {
case DVB_DEVICE_FRONTEND:
npads = 2;
break;
case DVB_DEVICE_DVR:
-   dvb_create_tsout_entity(dvbdev, DVR_TSOUT, demux_sink_pads);
-   return;
+   ret = dvb_create_tsout_entity(dvbdev, DVR_TSOUT,
+ demux_sink_pads);
+   return ret;
case DVB_DEVICE_DEMUX:
npads = 1 + demux_sink_pads;
-   dvb_create_tsout_entity(dvbdev, DEMUX_TSOUT, demux_sink_pads);
+ 

[PATCH 17/18] [media] dvbdev: move indirect links on dvr/demux to a separate function

2015-09-06 Thread Mauro Carvalho Chehab
Cleanup the code a little bit by moving the routine that creates
links between DVR and demux to the I/O entitis into a separate
function.

While here, fix the code to use strncmp() instead of strcmp().

Signed-off-by: Mauro Carvalho Chehab 

diff --git a/drivers/media/dvb-core/dvbdev.c b/drivers/media/dvb-core/dvbdev.c
index 8527fc40e6a0..ea76fe54e0e4 100644
--- a/drivers/media/dvb-core/dvbdev.c
+++ b/drivers/media/dvb-core/dvbdev.c
@@ -522,6 +522,28 @@ EXPORT_SYMBOL(dvb_unregister_device);
 
 
 #ifdef CONFIG_MEDIA_CONTROLLER_DVB
+
+static int dvb_create_io_intf_links(struct dvb_adapter *adap,
+   struct media_interface *intf,
+   char *name)
+{
+   struct media_device *mdev = adap->mdev;
+   struct media_entity *entity;
+   struct media_link *link;
+
+   media_device_for_each_entity(entity, mdev) {
+   if (entity->function == MEDIA_ENT_F_IO) {
+   if (strncmp(entity->name, name, strlen(name)))
+   continue;
+   link = media_create_intf_link(entity, intf,
+ MEDIA_LNK_FL_ENABLED);
+   if (!link)
+   return -ENOMEM;
+   }
+   }
+   return 0;
+}
+
 int dvb_create_media_graph(struct dvb_adapter *adap)
 {
struct media_device *mdev = adap->mdev;
@@ -619,25 +641,15 @@ int dvb_create_media_graph(struct dvb_adapter *adap)
if (!link)
return -ENOMEM;
}
-
-   media_device_for_each_entity(entity, mdev) {
-   if (entity->function == MEDIA_ENT_F_IO) {
-   if (!strcmp(entity->name, DVR_TSOUT)) {
-   link = media_create_intf_link(entity,
-   intf,
-   MEDIA_LNK_FL_ENABLED);
-   if (!link)
-   return -ENOMEM;
-   }
-   if (!strcmp(entity->name, DEMUX_TSOUT)) {
-   link = media_create_intf_link(entity,
-   intf,
-   MEDIA_LNK_FL_ENABLED);
-   if (!link)
-   return -ENOMEM;
-   }
-   break;
-   }
+   if (intf->type == MEDIA_INTF_T_DVB_DVR) {
+   ret = dvb_create_io_intf_links(adap, intf, DVR_TSOUT);
+   if (ret)
+   return ret;
+   }
+   if (intf->type == MEDIA_INTF_T_DVB_DEMUX) {
+   ret = dvb_create_io_intf_links(adap, intf, DEMUX_TSOUT);
+   if (ret)
+   return ret;
}
}
return 0;
-- 
2.4.3


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


[PATCH 06/18] [media] media.h: create connector entities for hybrid TV devices

2015-09-06 Thread Mauro Carvalho Chehab
Add entities to represent the connectors that exists inside a
hybrid TV device.

Signed-off-by: Mauro Carvalho Chehab 

diff --git a/include/uapi/linux/media.h b/include/uapi/linux/media.h
index b17f6763aff4..69433405aec2 100644
--- a/include/uapi/linux/media.h
+++ b/include/uapi/linux/media.h
@@ -61,6 +61,7 @@ struct media_device_info {
 #define MEDIA_ENT_T_DVB_BASE   0x
 #define MEDIA_ENT_T_V4L2_BASE  0x0001
 #define MEDIA_ENT_T_V4L2_SUBDEV_BASE   0x0002
+#define MEDIA_ENT_T_CONNECTOR_BASE 0x0003
 
 /*
  * V4L2 entities - Those are used for DMA (mmap/DMABUF) and
@@ -105,6 +106,13 @@ struct media_device_info {
 #define MEDIA_ENT_T_DVB_CA (MEDIA_ENT_T_DVB_BASE + 4)
 #define MEDIA_ENT_T_DVB_NET_DECAP  (MEDIA_ENT_T_DVB_BASE + 5)
 
+/* Connectors */
+#define MEDIA_ENT_T_CONN_RF(MEDIA_ENT_T_CONNECTOR_BASE)
+#define MEDIA_ENT_T_CONN_SVIDEO(MEDIA_ENT_T_CONNECTOR_BASE + 1)
+#define MEDIA_ENT_T_CONN_COMPOSITE (MEDIA_ENT_T_CONNECTOR_BASE + 2)
+   /* For internal test signal generators and other debug connectors */
+#define MEDIA_ENT_T_CONN_TEST  (MEDIA_ENT_T_CONNECTOR_BASE + 3)
+
 #ifndef __KERNEL__
 /* Legacy symbols used to avoid userspace compilation breakages */
 #define MEDIA_ENT_TYPE_SHIFT   16
@@ -121,9 +129,9 @@ struct media_device_info {
 #define MEDIA_ENT_T_DEVNODE_DVB(MEDIA_ENT_T_DEVNODE + 4)
 #endif
 
-/* Entity types */
-
+/* Entity flags */
 #define MEDIA_ENT_FL_DEFAULT   (1 << 0)
+#define MEDIA_ENT_FL_CONNECTOR (1 << 1)
 
 struct media_entity_desc {
__u32 id;
-- 
2.4.3


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


[PATCH 18/18] [media] dvbdev: Don't create indirect links

2015-09-06 Thread Mauro Carvalho Chehab
Indirect links are those whose the interface indirectly controls
other functions.

There are two interfaces that have indirect controls at the DVB
side:
- the network interface, with also controls the demux;
- the DVR interface with also controls the demux.

One could argue that the frontend control to the tuner is indirect.
Well, that's debateable. There's no way to create subdef interfaces
for tuner and demod, as those devices are tightly coupled. So, it
was decided that just one interface is the best to control both
entities, and there's no plan (or easy way) to decouple both. So,
the DVB frontend interface should link to both entities.

Signed-off-by: Mauro Carvalho Chehab 

diff --git a/drivers/media/dvb-core/dvbdev.c b/drivers/media/dvb-core/dvbdev.c
index ea76fe54e0e4..e9f24c1479dd 100644
--- a/drivers/media/dvb-core/dvbdev.c
+++ b/drivers/media/dvb-core/dvbdev.c
@@ -619,7 +619,7 @@ int dvb_create_media_graph(struct dvb_adapter *adap)
}
}
 
-   /* Create indirect interface links for FE->tuner, DVR->demux and CA->ca 
*/
+   /* Create interface links for FE->tuner, DVR->demux and CA->ca */
media_device_for_each_intf(intf, mdev) {
if (intf->type == MEDIA_INTF_T_DVB_CA && ca) {
link = media_create_intf_link(ca, intf,
@@ -634,13 +634,19 @@ int dvb_create_media_graph(struct dvb_adapter *adap)
if (!link)
return -ENOMEM;
}
-
+#if 0
+   /*
+* Indirect link - let's not create yet, as we don't know how
+* to handle indirect links, nor if this will
+* actually be needed.
+*/
if (intf->type == MEDIA_INTF_T_DVB_DVR && demux) {
link = media_create_intf_link(demux, intf,
  MEDIA_LNK_FL_ENABLED);
if (!link)
return -ENOMEM;
}
+#endif
if (intf->type == MEDIA_INTF_T_DVB_DVR) {
ret = dvb_create_io_intf_links(adap, intf, DVR_TSOUT);
if (ret)
-- 
2.4.3


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


[PATCH 13/18] [media] media-entity.h: rename entity.type to entity.function

2015-09-06 Thread Mauro Carvalho Chehab
Entities should have one or more functions. Calling it as a
type proofed to not be correct, as an entity could eventually
have more than one type.

So, rename the field as function.

Please notice that this patch doesn't extend support for
multiple function entities. Such change will happen when
we have real case drivers using it.

No functional changes.

Signed-off-by: Mauro Carvalho Chehab 

diff --git a/Documentation/video4linux/v4l2-framework.txt 
b/Documentation/video4linux/v4l2-framework.txt
index 109cc3792534..2e0fc28fa12f 100644
--- a/Documentation/video4linux/v4l2-framework.txt
+++ b/Documentation/video4linux/v4l2-framework.txt
@@ -303,8 +303,8 @@ calling media_entity_init():
err = media_entity_init(>entity, npads, pads);
 
 The pads array must have been previously initialized. There is no need to
-manually set the struct media_entity type and name fields, but the revision
-field must be initialized if needed.
+manually set the struct media_entity function and name fields, but the
+revision field must be initialized if needed.
 
 A reference to the entity will be automatically acquired/released when the
 subdev device node (if any) is opened/closed.
diff --git a/drivers/media/dvb-core/dvbdev.c b/drivers/media/dvb-core/dvbdev.c
index df2fe4cc2d47..e925909bc99e 100644
--- a/drivers/media/dvb-core/dvbdev.c
+++ b/drivers/media/dvb-core/dvbdev.c
@@ -229,7 +229,7 @@ static int dvb_create_tsout_entity(struct dvb_device 
*dvbdev,
if (!entity->name)
return ret;
 
-   entity->type = MEDIA_ENT_T_DVB_TSOUT;
+   entity->function = MEDIA_ENT_T_DVB_TSOUT;
pads->flags = MEDIA_PAD_FL_SINK;
 
ret = media_entity_init(entity, 1, pads);
@@ -302,18 +302,18 @@ static int dvb_create_media_entity(struct dvb_device 
*dvbdev,
 
switch (type) {
case DVB_DEVICE_FRONTEND:
-   dvbdev->entity->type = MEDIA_ENT_T_DVB_DEMOD;
+   dvbdev->entity->function = MEDIA_ENT_T_DVB_DEMOD;
dvbdev->pads[0].flags = MEDIA_PAD_FL_SINK;
dvbdev->pads[1].flags = MEDIA_PAD_FL_SOURCE;
break;
case DVB_DEVICE_DEMUX:
-   dvbdev->entity->type = MEDIA_ENT_T_DVB_DEMUX;
+   dvbdev->entity->function = MEDIA_ENT_T_DVB_DEMUX;
dvbdev->pads[0].flags = MEDIA_PAD_FL_SINK;
for (i = 1; i < npads; i++)
dvbdev->pads[i].flags = MEDIA_PAD_FL_SOURCE;
break;
case DVB_DEVICE_CA:
-   dvbdev->entity->type = MEDIA_ENT_T_DVB_CA;
+   dvbdev->entity->function = MEDIA_ENT_T_DVB_CA;
dvbdev->pads[0].flags = MEDIA_PAD_FL_SINK;
dvbdev->pads[1].flags = MEDIA_PAD_FL_SOURCE;
break;
@@ -537,7 +537,7 @@ int dvb_create_media_graph(struct dvb_adapter *adap)
return 0;
 
media_device_for_each_entity(entity, mdev) {
-   switch (entity->type) {
+   switch (entity->function) {
case MEDIA_ENT_T_V4L2_SUBDEV_TUNER:
tuner = entity;
break;
@@ -576,7 +576,7 @@ int dvb_create_media_graph(struct dvb_adapter *adap)
/* Create demux links for each ringbuffer/pad */
if (demux) {
media_device_for_each_entity(entity, mdev) {
-   if (entity->type == MEDIA_ENT_T_DVB_TSOUT) {
+   if (entity->function == MEDIA_ENT_T_DVB_TSOUT) {
if (!strncmp(entity->name, DVR_TSOUT,
strlen(DVR_TSOUT))) {
ret = media_create_pad_link(demux,
@@ -621,7 +621,7 @@ int dvb_create_media_graph(struct dvb_adapter *adap)
}
 
media_device_for_each_entity(entity, mdev) {
-   if (entity->type == MEDIA_ENT_T_DVB_TSOUT) {
+   if (entity->function == MEDIA_ENT_T_DVB_TSOUT) {
if (!strcmp(entity->name, DVR_TSOUT)) {
link = media_create_intf_link(entity,
intf,
diff --git a/drivers/media/dvb-frontends/au8522_decoder.c 
b/drivers/media/dvb-frontends/au8522_decoder.c
index 55cd42a584a5..a6fbe78a70e3 100644
--- a/drivers/media/dvb-frontends/au8522_decoder.c
+++ b/drivers/media/dvb-frontends/au8522_decoder.c
@@ -775,7 +775,7 @@ static int au8522_probe(struct i2c_client *client,
state->pads[AU8522_PAD_INPUT].flags = MEDIA_PAD_FL_SINK;
state->pads[AU8522_PAD_VID_OUT].flags = MEDIA_PAD_FL_SOURCE;
state->pads[AU8522_PAD_VBI_OUT].flags = MEDIA_PAD_FL_SOURCE;
-   sd->entity.type = MEDIA_ENT_T_V4L2_SUBDEV_DECODER;
+   sd->entity.function = MEDIA_ENT_T_V4L2_SUBDEV_DECODER;
 
ret = media_entity_init(>entity, ARRAY_SIZE(state->pads),

[PATCH 03/18] [media] au0828: Create connector links

2015-09-06 Thread Mauro Carvalho Chehab
Now that connectors are entities, we need to represent the
connector links.

Signed-off-by: Mauro Carvalho Chehab 

diff --git a/drivers/media/usb/au0828/au0828-core.c 
b/drivers/media/usb/au0828/au0828-core.c
index fe9a60484343..35c607c35155 100644
--- a/drivers/media/usb/au0828/au0828-core.c
+++ b/drivers/media/usb/au0828/au0828-core.c
@@ -257,6 +257,7 @@ static void au0828_create_media_graph(struct au0828_dev 
*dev)
struct media_device *mdev = dev->media_dev;
struct media_entity *entity;
struct media_entity *tuner = NULL, *decoder = NULL;
+   int i;
 
if (!mdev)
return;
@@ -274,6 +275,7 @@ static void au0828_create_media_graph(struct au0828_dev 
*dev)
 
/* Analog setup, using tuner as a link */
 
+   /* Something bad happened! */
if (!decoder)
return;
 
@@ -284,6 +286,30 @@ static void au0828_create_media_graph(struct au0828_dev 
*dev)
  MEDIA_LNK_FL_ENABLED);
media_create_pad_link(decoder, 2, >vbi_dev.entity, 0,
  MEDIA_LNK_FL_ENABLED);
+
+   for (i = 0; i < AU0828_MAX_INPUT; i++) {
+   struct media_entity *ent = >input_ent[i];
+
+   if (AUVI_INPUT(i).type == AU0828_VMUX_UNDEFINED)
+   break;
+
+   switch(AUVI_INPUT(i).type) {
+   case AU0828_VMUX_CABLE:
+   case AU0828_VMUX_TELEVISION:
+   case AU0828_VMUX_DVB:
+   if (tuner)
+   media_create_pad_link(ent, 0, tuner,
+ TUNER_PAD_RF_INPUT,
+ MEDIA_LNK_FL_ENABLED);
+   break;
+   case AU0828_VMUX_COMPOSITE:
+   case AU0828_VMUX_SVIDEO:
+   default: /* AU0828_VMUX_DEBUG */
+   /* FIXME: fix the decoder PAD */
+   media_create_pad_link(ent, 0, decoder, 0, 0);
+   break;
+   }
+   }
 #endif
 }
 
-- 
2.4.3


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


[PATCH 05/18] [media] media-controller: enable all interface links at init

2015-09-06 Thread Mauro Carvalho Chehab
Interface links are normally enabled, meaning that the interfaces are
bound to the entities. So, any ioctl send to the interface are reflected
at the entities managed by the interface.

However, when a device is usage, other interfaces for the same hardware
could be decoupled from the entities linked to them, because the
hardware may have some parts busy.

That's for example, what happens when an hybrid TV device is in usage.
If it is streaming analog TV or capturing signals from S-Video/Composite
connectors, typically the digital part of the hardware can't be used and
vice-versa.

This is generally due to some internal hardware or firmware limitation,
that it is not easily mapped via data pipelines.

What the Kernel drivers do internally is that they decouple the hardware
from the interface. So, all changes, if allowed, are done only at some
interface cache, but not physically changed at the hardware.

The usage is similar to the usage of the MEDIA_LNK_FL_ENABLED on data
links. So, let's use the same flag to indicate if ether the interface
to entity link is bound/enabled or not.

Signed-off-by: Mauro Carvalho Chehab 

diff --git a/drivers/media/dvb-core/dvbdev.c b/drivers/media/dvb-core/dvbdev.c
index a8e7e2398f7a..5c4fb41060b4 100644
--- a/drivers/media/dvb-core/dvbdev.c
+++ b/drivers/media/dvb-core/dvbdev.c
@@ -396,7 +396,8 @@ static void dvb_register_media_device(struct dvb_device 
*dvbdev,
if (!dvbdev->entity || !dvbdev->intf_devnode)
return;
 
-   media_create_intf_link(dvbdev->entity, >intf_devnode->intf, 0);
+   media_create_intf_link(dvbdev->entity, >intf_devnode->intf,
+  MEDIA_LNK_FL_ENABLED);
 
 #endif
 }
@@ -583,20 +584,24 @@ void dvb_create_media_graph(struct dvb_adapter *adap)
/* Create indirect interface links for FE->tuner, DVR->demux and CA->ca 
*/
media_device_for_each_intf(intf, mdev) {
if (intf->type == MEDIA_INTF_T_DVB_CA && ca)
-   media_create_intf_link(ca, intf, 0);
+   media_create_intf_link(ca, intf, MEDIA_LNK_FL_ENABLED);
 
if (intf->type == MEDIA_INTF_T_DVB_FE && tuner)
-   media_create_intf_link(tuner, intf, 0);
+   media_create_intf_link(tuner, intf,
+  MEDIA_LNK_FL_ENABLED);
 
if (intf->type == MEDIA_INTF_T_DVB_DVR && demux)
-   media_create_intf_link(demux, intf, 0);
+   media_create_intf_link(demux, intf,
+  MEDIA_LNK_FL_ENABLED);
 
media_device_for_each_entity(entity, mdev) {
if (entity->type == MEDIA_ENT_T_DVB_TSOUT) {
if (!strcmp(entity->name, DVR_TSOUT))
-   media_create_intf_link(entity, intf, 0);
+   media_create_intf_link(entity, intf,
+  
MEDIA_LNK_FL_ENABLED);
if (!strcmp(entity->name, DEMUX_TSOUT))
-   media_create_intf_link(entity, intf, 0);
+   media_create_intf_link(entity, intf,
+  
MEDIA_LNK_FL_ENABLED);
break;
}
}
diff --git a/drivers/media/v4l2-core/v4l2-dev.c 
b/drivers/media/v4l2-core/v4l2-dev.c
index 07123dd569c4..8429da66754a 100644
--- a/drivers/media/v4l2-core/v4l2-dev.c
+++ b/drivers/media/v4l2-core/v4l2-dev.c
@@ -788,7 +788,8 @@ static int video_register_media_controller(struct 
video_device *vdev, int type)
struct media_link *link;
 
link = media_create_intf_link(>entity,
- >intf_devnode->intf, 0);
+ >intf_devnode->intf,
+ MEDIA_LNK_FL_ENABLED);
if (!link) {
media_devnode_remove(vdev->intf_devnode);
media_device_unregister_entity(>entity);
diff --git a/drivers/media/v4l2-core/v4l2-device.c 
b/drivers/media/v4l2-core/v4l2-device.c
index e788a085ba96..bb58d90fde5e 100644
--- a/drivers/media/v4l2-core/v4l2-device.c
+++ b/drivers/media/v4l2-core/v4l2-device.c
@@ -256,7 +256,7 @@ int v4l2_device_register_subdev_nodes(struct v4l2_device 
*v4l2_dev)
 
link = media_create_intf_link(>entity,
  >intf_devnode->intf,
- 0);
+ MEDIA_LNK_FL_ENABLED);
if (!link)
goto clean_up;
}
-- 
2.4.3


--
To unsubscribe 

[PATCH 02/18] [media] au0828: add support for the connectors

2015-09-06 Thread Mauro Carvalho Chehab
Depending on the input, an au0828 may have a different
number of connectors. add entities to represent them.

Signed-off-by: Mauro Carvalho Chehab 

diff --git a/drivers/media/usb/au0828/au0828-core.c 
b/drivers/media/usb/au0828/au0828-core.c
index f54c7d10f350..fe9a60484343 100644
--- a/drivers/media/usb/au0828/au0828-core.c
+++ b/drivers/media/usb/au0828/au0828-core.c
@@ -153,11 +153,26 @@ static void au0828_usb_release(struct au0828_dev *dev)
 }
 
 #ifdef CONFIG_VIDEO_AU0828_V4L2
+
+static void au0828_usb_v4l2_media_release(struct au0828_dev *dev)
+{
+#ifdef CONFIG_MEDIA_CONTROLLER
+   int i;
+
+   for (i = 0; i < AU0828_MAX_INPUT; i++) {
+   if (AUVI_INPUT(i).type == AU0828_VMUX_UNDEFINED)
+   return;
+   media_device_unregister_entity(>input_ent[i]);
+   }
+#endif
+}
+
 static void au0828_usb_v4l2_release(struct v4l2_device *v4l2_dev)
 {
struct au0828_dev *dev =
container_of(v4l2_dev, struct au0828_dev, v4l2_dev);
 
+   au0828_usb_v4l2_media_release(dev);
v4l2_ctrl_handler_free(>v4l2_ctrl_hdl);
v4l2_device_unregister(>v4l2_dev);
au0828_usb_release(dev);
diff --git a/drivers/media/usb/au0828/au0828-video.c 
b/drivers/media/usb/au0828/au0828-video.c
index 4511e2893282..806b8d320bae 100644
--- a/drivers/media/usb/au0828/au0828-video.c
+++ b/drivers/media/usb/au0828/au0828-video.c
@@ -1793,6 +1793,69 @@ static int au0828_vb2_setup(struct au0828_dev *dev)
return 0;
 }
 
+static void au0828_analog_create_entities(struct au0828_dev *dev)
+{
+#if defined(CONFIG_MEDIA_CONTROLLER)
+   static const char *inames[] = {
+   [AU0828_VMUX_COMPOSITE] = "Composite",
+   [AU0828_VMUX_SVIDEO] = "S-Video",
+   [AU0828_VMUX_CABLE] = "Cable TV",
+   [AU0828_VMUX_TELEVISION] = "Television",
+   [AU0828_VMUX_DVB] = "DVB",
+   [AU0828_VMUX_DEBUG] = "tv debug"
+   };
+   int ret, i;
+
+   /* Initialize Video and VBI pads */
+   dev->video_pad.flags = MEDIA_PAD_FL_SINK;
+   ret = media_entity_init(>vdev.entity, 1, >video_pad);
+   if (ret < 0)
+   pr_err("failed to initialize video media entity!\n");
+
+   dev->vbi_pad.flags = MEDIA_PAD_FL_SINK;
+   ret = media_entity_init(>vbi_dev.entity, 1, >vbi_pad);
+   if (ret < 0)
+   pr_err("failed to initialize vbi media entity!\n");
+
+   /* Create entities for each input connector */
+   for (i = 0; i < AU0828_MAX_INPUT; i++) {
+   struct media_entity *ent = >input_ent[i];
+
+   if (AUVI_INPUT(i).type == AU0828_VMUX_UNDEFINED)
+   break;
+
+   ent->name = inames[AUVI_INPUT(i).type];
+   ent->flags = MEDIA_ENT_FL_CONNECTOR;
+   dev->input_pad[i].flags = MEDIA_PAD_FL_SOURCE;
+
+   switch(AUVI_INPUT(i).type) {
+   case AU0828_VMUX_COMPOSITE:
+   ent->type = MEDIA_ENT_T_CONN_COMPOSITE;
+   break;
+   case AU0828_VMUX_SVIDEO:
+   ent->type = MEDIA_ENT_T_CONN_SVIDEO;
+   break;
+   case AU0828_VMUX_CABLE:
+   case AU0828_VMUX_TELEVISION:
+   case AU0828_VMUX_DVB:
+   ent->type = MEDIA_ENT_T_CONN_RF;
+   break;
+   default: /* AU0828_VMUX_DEBUG */
+   ent->type = MEDIA_ENT_T_CONN_TEST;
+   break;
+   }
+
+   ret = media_entity_init(ent, 1, >input_pad[i]);
+   if (ret < 0)
+   pr_err("failed to initialize input pad[%d]!\n", i);
+
+   ret = media_device_register_entity(dev->media_dev, ent);
+   if (ret < 0)
+   pr_err("failed to register input entity %d!\n", i);
+   }
+#endif
+}
+
 /**/
 
 int au0828_analog_register(struct au0828_dev *dev,
@@ -1881,17 +1944,8 @@ int au0828_analog_register(struct au0828_dev *dev,
dev->vbi_dev.queue->lock = >vb_vbi_queue_lock;
strcpy(dev->vbi_dev.name, "au0828a vbi");
 
-#if defined(CONFIG_MEDIA_CONTROLLER)
-   dev->video_pad.flags = MEDIA_PAD_FL_SINK;
-   ret = media_entity_init(>vdev.entity, 1, >video_pad);
-   if (ret < 0)
-   pr_err("failed to initialize video media entity!\n");
-
-   dev->vbi_pad.flags = MEDIA_PAD_FL_SINK;
-   ret = media_entity_init(>vbi_dev.entity, 1, >vbi_pad);
-   if (ret < 0)
-   pr_err("failed to initialize vbi media entity!\n");
-#endif
+   /* Init entities at the Media Controller */
+   au0828_analog_create_entities(dev);
 
/* initialize videobuf2 stuff */
retval = au0828_vb2_setup(dev);
diff --git a/drivers/media/usb/au0828/au0828.h 
b/drivers/media/usb/au0828/au0828.h
index 

[PATCH 15/18] [media] uapi/media.h: Rename entities types to functions

2015-09-06 Thread Mauro Carvalho Chehab
Rename the userspace types from MEDIA_ENT_T_ to MEDIA_ENT_F_
and add the backward compatibility bits.

The changes at the .c files was generated by the following
coccinelle script:

@@
@@
-MEDIA_ENT_T_UNKNOWN
+MEDIA_ENT_F_UNKNOWN
@@
@@
-MEDIA_ENT_T_DVB_BASE
+MEDIA_ENT_F_DVB_BASE
@@
@@
-MEDIA_ENT_T_V4L2_BASE
+MEDIA_ENT_F_V4L2_BASE
@@
@@
-MEDIA_ENT_T_V4L2_SUBDEV_BASE
+MEDIA_ENT_F_V4L2_SUBDEV_BASE
@@
@@
-MEDIA_ENT_T_CONNECTOR_BASE
+MEDIA_ENT_F_CONNECTOR_BASE
@@
@@
-MEDIA_ENT_T_V4L2_VIDEO
+MEDIA_ENT_F_IO
@@
@@
-MEDIA_ENT_T_V4L2_VBI
+MEDIA_ENT_F_V4L2_VBI
@@
@@
-MEDIA_ENT_T_V4L2_SWRADIO
+MEDIA_ENT_F_V4L2_SWRADIO
@@
@@
-MEDIA_ENT_T_V4L2_SUBDEV_UNKNOWN
+MEDIA_ENT_F_V4L2_SUBDEV_UNKNOWN
@@
@@
-MEDIA_ENT_T_CONN_RF
+MEDIA_ENT_F_CONN_RF
@@
@@
-MEDIA_ENT_T_CONN_SVIDEO
+MEDIA_ENT_F_CONN_SVIDEO
@@
@@
-MEDIA_ENT_T_CONN_COMPOSITE
+MEDIA_ENT_F_CONN_COMPOSITE
@@
@@
-MEDIA_ENT_T_CONN_TEST
+MEDIA_ENT_F_CONN_TEST
@@
@@
-MEDIA_ENT_T_V4L2_SUBDEV_SENSOR
+MEDIA_ENT_F_CAM_SENSOR
@@
@@
-MEDIA_ENT_T_V4L2_SUBDEV_FLASH
+MEDIA_ENT_F_FLASH
@@
@@
-MEDIA_ENT_T_V4L2_SUBDEV_LENS
+MEDIA_ENT_F_LENS
@@
@@
-MEDIA_ENT_T_V4L2_SUBDEV_DECODER
+MEDIA_ENT_F_ATV_DECODER
@@
@@
-MEDIA_ENT_T_V4L2_SUBDEV_TUNER
+MEDIA_ENT_F_TUNER
@@
@@
-MEDIA_ENT_T_DVB_DEMOD
+MEDIA_ENT_F_DTV_DEMOD
@@
@@
-MEDIA_ENT_T_DVB_DEMUX
+MEDIA_ENT_F_MPEG_TS_DEMUX
@@
@@
-MEDIA_ENT_T_DVB_TSOUT
+MEDIA_ENT_F_DTV_TSOUT
@@
@@
-MEDIA_ENT_T_DVB_CA
+MEDIA_ENT_F_DTV_CA
@@
@@
-MEDIA_ENT_T_DVB_NET_DECAP
+MEDIA_ENT_F_DTV_NET_DECAP

Signed-off-by: Mauro Carvalho Chehab 

diff --git a/drivers/media/dvb-core/dvbdev.c b/drivers/media/dvb-core/dvbdev.c
index e925909bc99e..8527fc40e6a0 100644
--- a/drivers/media/dvb-core/dvbdev.c
+++ b/drivers/media/dvb-core/dvbdev.c
@@ -229,7 +229,7 @@ static int dvb_create_tsout_entity(struct dvb_device 
*dvbdev,
if (!entity->name)
return ret;
 
-   entity->function = MEDIA_ENT_T_DVB_TSOUT;
+   entity->function = MEDIA_ENT_F_IO;
pads->flags = MEDIA_PAD_FL_SINK;
 
ret = media_entity_init(entity, 1, pads);
@@ -302,18 +302,18 @@ static int dvb_create_media_entity(struct dvb_device 
*dvbdev,
 
switch (type) {
case DVB_DEVICE_FRONTEND:
-   dvbdev->entity->function = MEDIA_ENT_T_DVB_DEMOD;
+   dvbdev->entity->function = MEDIA_ENT_F_DTV_DEMOD;
dvbdev->pads[0].flags = MEDIA_PAD_FL_SINK;
dvbdev->pads[1].flags = MEDIA_PAD_FL_SOURCE;
break;
case DVB_DEVICE_DEMUX:
-   dvbdev->entity->function = MEDIA_ENT_T_DVB_DEMUX;
+   dvbdev->entity->function = MEDIA_ENT_F_MPEG_TS_DEMUX;
dvbdev->pads[0].flags = MEDIA_PAD_FL_SINK;
for (i = 1; i < npads; i++)
dvbdev->pads[i].flags = MEDIA_PAD_FL_SOURCE;
break;
case DVB_DEVICE_CA:
-   dvbdev->entity->function = MEDIA_ENT_T_DVB_CA;
+   dvbdev->entity->function = MEDIA_ENT_F_DTV_CA;
dvbdev->pads[0].flags = MEDIA_PAD_FL_SINK;
dvbdev->pads[1].flags = MEDIA_PAD_FL_SOURCE;
break;
@@ -538,16 +538,16 @@ int dvb_create_media_graph(struct dvb_adapter *adap)
 
media_device_for_each_entity(entity, mdev) {
switch (entity->function) {
-   case MEDIA_ENT_T_V4L2_SUBDEV_TUNER:
+   case MEDIA_ENT_F_TUNER:
tuner = entity;
break;
-   case MEDIA_ENT_T_DVB_DEMOD:
+   case MEDIA_ENT_F_DTV_DEMOD:
demod = entity;
break;
-   case MEDIA_ENT_T_DVB_DEMUX:
+   case MEDIA_ENT_F_MPEG_TS_DEMUX:
demux = entity;
break;
-   case MEDIA_ENT_T_DVB_CA:
+   case MEDIA_ENT_F_DTV_CA:
ca = entity;
break;
}
@@ -576,7 +576,7 @@ int dvb_create_media_graph(struct dvb_adapter *adap)
/* Create demux links for each ringbuffer/pad */
if (demux) {
media_device_for_each_entity(entity, mdev) {
-   if (entity->function == MEDIA_ENT_T_DVB_TSOUT) {
+   if (entity->function == MEDIA_ENT_F_IO) {
if (!strncmp(entity->name, DVR_TSOUT,
strlen(DVR_TSOUT))) {
ret = media_create_pad_link(demux,
@@ -621,7 +621,7 @@ int dvb_create_media_graph(struct dvb_adapter *adap)
}
 
media_device_for_each_entity(entity, mdev) {
-   if (entity->function == MEDIA_ENT_T_DVB_TSOUT) {
+   if (entity->function == MEDIA_ENT_F_IO) {
if (!strcmp(entity->name, DVR_TSOUT)) {
link = media_create_intf_link(entity,

[PATCH 12/18] [media] media-entity: must check media_create_pad_link()

2015-09-06 Thread Mauro Carvalho Chehab
Drivers should check if media_create_pad_link() actually
worked.

Signed-off-by: Mauro Carvalho Chehab 

diff --git a/include/media/media-entity.h b/include/media/media-entity.h
index 62f882d872b1..8bdc10dcc5e7 100644
--- a/include/media/media-entity.h
+++ b/include/media/media-entity.h
@@ -348,8 +348,9 @@ int media_entity_init(struct media_entity *entity, u16 
num_pads,
  struct media_pad *pads);
 void media_entity_cleanup(struct media_entity *entity);
 
-int media_create_pad_link(struct media_entity *source, u16 source_pad,
-   struct media_entity *sink, u16 sink_pad, u32 flags);
+__must_check int media_create_pad_link(struct media_entity *source,
+   u16 source_pad, struct media_entity *sink,
+   u16 sink_pad, u32 flags);
 void __media_entity_remove_links(struct media_entity *entity);
 void media_entity_remove_links(struct media_entity *entity);
 
-- 
2.4.3


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


[PATCH 00/18] MC fixes, improvements and cleanups

2015-09-06 Thread Mauro Carvalho Chehab
This patch series go after the previous series:
"MC next generation patches"
http://www.spinics.net/lists/linux-media/msg93108.html

It contains a series of fixes and cleanup the MC  Next gen.

The first patches add connector entities to represent RF, S-Video and Composite
interfaces on an analog device and fixes some bugs:
  [media] tuner-core: add an input pad
  [media] au0828: add support for the connectors
  [media] au0828: Create connector links
  [media] media-device: supress backlinks at G_TOPOLOGY ioctl
  [media] media-controller: enable all interface links at init
  [media] media.h: create connector entities for hybrid TV devices

The next sequence of patches enforce __must_check to pads and links creation,
as requested by Hans Verkuil:
  [media] dvbdev: returns error if graph object creation fails
  [media] dvb core: must check dvb_create_media_graph()
  [media] media-entity: enforce check of interface and links creation
  [media] cx231xx: enforce check for graph creation
  [media] au0828:: enforce check for graph creation
  [media] media-entity: must check media_create_pad_link()

The next patches do the entity function rename as agreed at the meeting we had 
on
IRC last Wednesday, and exposes it via G_TOPOLOGY:
  [media] media-entity.h: rename entity.type to entity.function
  [media] media-device: export the entity function via new ioctl
  [media] uapi/media.h: Rename entities types to functions
  [media] DocBook: update entities documentation

The final patches are some cleanups at the dvbdev link creation:
  [media] dvbdev: move indirect links on dvr/demux to a separate function
  [media] dvbdev: Don't create indirect links

The last patch deserves a better explanation: entities may direct or indirect 
control
a device, on non-v4l2-subdev-centric devices. We're not creating the indirect
interface control links at V4L2 side. I decided to remove it also from the 
dvbdev
side. Implementing support for it is not hard, but let's do it only when we 
have some
usecases.

There aren't much things to be done for the merge of the MC next gen series on
(scheduled for Kernel 4.4). On my  my lists, the remaining items are:

TODO for next Kernel version (goal: Kernel version 4.4):
=

- Add Javier's fixup patches with fixes for some platform drivers
  and uvc;

- Find entities that belong to V4L2 or DVB via the interfaces,
  in order to enable/disable the inteface links when the device
  gets busy;

TODO for a next versions:
=

- Remove unused fields from media_entity (like major, minor, revision,
  group_id, num_links, num_backlinks, num_pads)

- dynamic entity/interface/link creation and removal;

- SETUP_LINK_V2 with dynamic support;

- dynamic pad creation and removal (needed?);

- multiple function per entity support;

- indirect interface links support;

- MC properties API.

Userspace:
==

- Create a library with v2 API;

- Use the v2 API library on qv4l2/libdvbv5/xawtv/libv4l;

- Add the libudev/libsysfs logic at mc_nextgen_test to convert
  a devnode major/minor into a /dev/* name;


Mauro Carvalho Chehab (18):
  [media] tuner-core: add an input pad
  [media] au0828: add support for the connectors
  [media] au0828: Create connector links
  [media] media-device: supress backlinks at G_TOPOLOGY ioctl
  [media] media-controller: enable all interface links at init
  [media] media.h: create connector entities for hybrid TV devices
  [media] dvbdev: returns error if graph object creation fails
  [media] dvb core: must check dvb_create_media_graph()
  [media] media-entity: enforce check of interface and links creation
  [media] cx231xx: enforce check for graph creation
  [media] au0828:: enforce check for graph creation
  [media] media-entity: must check media_create_pad_link()
  [media] media-entity.h: rename entity.type to entity.function
  [media] media-device: export the entity function via new ioctl
  [media] uapi/media.h: Rename entities types to functions
  [media] DocBook: update entities documentation
  [media] dvbdev: move indirect links on dvr/demux to a separate
function
  [media] dvbdev: Don't create indirect links

 .../DocBook/media/v4l/media-ioc-enum-entities.xml  |  58 ++--
 Documentation/video4linux/v4l2-framework.txt   |   4 +-
 drivers/media/common/siano/smsdvb-main.c   |   6 +-
 drivers/media/dvb-core/dvbdev.c| 343 -
 drivers/media/dvb-core/dvbdev.h|   7 +-
 drivers/media/dvb-frontends/au8522_decoder.c   |   2 +-
 drivers/media/i2c/adp1653.c|   2 +-
 drivers/media/i2c/adv7180.c|   2 +-
 drivers/media/i2c/as3645a.c|   2 +-
 drivers/media/i2c/cx25840/cx25840-core.c   |   2 +-
 drivers/media/i2c/lm3560.c |   2 +-
 drivers/media/i2c/lm3646.c |   2 +-
 

[PATCH 09/18] [media] media-entity: enforce check of interface and links creation

2015-09-06 Thread Mauro Carvalho Chehab
Drivers should check if interfaces and interface links were
created. Add a must_check for them.

Signed-off-by: Mauro Carvalho Chehab 

diff --git a/include/media/media-entity.h b/include/media/media-entity.h
index 3d389f142a1d..62f882d872b1 100644
--- a/include/media/media-entity.h
+++ b/include/media/media-entity.h
@@ -370,14 +370,16 @@ __must_check int media_entity_pipeline_start(struct 
media_entity *entity,
 struct media_pipeline *pipe);
 void media_entity_pipeline_stop(struct media_entity *entity);
 
-struct media_intf_devnode *media_devnode_create(struct media_device *mdev,
-   u32 type, u32 flags,
-   u32 major, u32 minor,
-   gfp_t gfp_flags);
+struct media_intf_devnode *
+__must_check media_devnode_create(struct media_device *mdev,
+ u32 type, u32 flags,
+ u32 major, u32 minor,
+ gfp_t gfp_flags);
 void media_devnode_remove(struct media_intf_devnode *devnode);
-struct media_link *media_create_intf_link(struct media_entity *entity,
-   struct media_interface *intf,
-   u32 flags);
+struct media_link *
+__must_check media_create_intf_link(struct media_entity *entity,
+   struct media_interface *intf,
+   u32 flags);
 void media_remove_intf_link(struct media_link *link);
 void __media_remove_intf_links(struct media_interface *intf);
 void media_remove_intf_links(struct media_interface *intf);
-- 
2.4.3


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


[PATCH 04/18] [media] media-device: supress backlinks at G_TOPOLOGY ioctl

2015-09-06 Thread Mauro Carvalho Chehab
Due to the graph traversal algorithm currently in usage, we
need a copy of all data links. Those backlinks should not be
send to userspace, as otherwise, all links there will be
duplicated.

Signed-off-by: Mauro Carvalho Chehab 

diff --git a/drivers/media/media-device.c b/drivers/media/media-device.c
index 0238885fcc74..97eb97d9b662 100644
--- a/drivers/media/media-device.c
+++ b/drivers/media/media-device.c
@@ -333,6 +333,9 @@ static long __media_device_get_topology(struct media_device 
*mdev,
/* Get links and number of links */
i = 0;
media_device_for_each_link(link, mdev) {
+   if (link->is_backlink)
+   continue;
+
i++;
 
if (ret || !topo->links)
diff --git a/drivers/media/media-entity.c b/drivers/media/media-entity.c
index cd4d767644df..4868b8269204 100644
--- a/drivers/media/media-entity.c
+++ b/drivers/media/media-entity.c
@@ -648,6 +648,7 @@ media_create_pad_link(struct media_entity *source, u16 
source_pad,
backlink->source = >pads[source_pad];
backlink->sink = >pads[sink_pad];
backlink->flags = flags;
+   backlink->is_backlink = true;
 
/* Initialize graph object embedded at the new link */
media_gobj_init(sink->graph_obj.mdev, MEDIA_GRAPH_LINK,
diff --git a/include/media/media-entity.h b/include/media/media-entity.h
index e1a89899deef..3d389f142a1d 100644
--- a/include/media/media-entity.h
+++ b/include/media/media-entity.h
@@ -96,6 +96,7 @@ struct media_pipeline {
  * @reverse:   Pointer to the link for the reverse direction of a pad to pad
  * link.
  * @flags: Link flags, as defined at uapi/media.h (MEDIA_LNK_FL_*)
+ * @is_backlink: Indicate if the link is a backlink.
  */
 struct media_link {
struct media_gobj graph_obj;
@@ -112,6 +113,7 @@ struct media_link {
};
struct media_link *reverse;
unsigned long flags;
+   bool is_backlink;
 };
 
 /**
-- 
2.4.3


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


[PATCH 10/18] [media] cx231xx: enforce check for graph creation

2015-09-06 Thread Mauro Carvalho Chehab
If the graph creation fails, don't register the device.

Signed-off-by: Mauro Carvalho Chehab 

diff --git a/drivers/media/usb/cx231xx/cx231xx-cards.c 
b/drivers/media/usb/cx231xx/cx231xx-cards.c
index 1070d87efc65..c05aaef85491 100644
--- a/drivers/media/usb/cx231xx/cx231xx-cards.c
+++ b/drivers/media/usb/cx231xx/cx231xx-cards.c
@@ -1185,8 +1185,6 @@ static void cx231xx_unregister_media_device(struct 
cx231xx *dev)
 */
 void cx231xx_release_resources(struct cx231xx *dev)
 {
-   cx231xx_unregister_media_device(dev);
-
cx231xx_release_analog_resources(dev);
 
cx231xx_remove_from_devlist(dev);
@@ -1199,6 +1197,8 @@ void cx231xx_release_resources(struct cx231xx *dev)
/* delete v4l2 device */
v4l2_device_unregister(>v4l2_dev);
 
+   cx231xx_unregister_media_device(dev);
+
usb_put_dev(dev->udev);
 
/* Mark device as unused */
@@ -1237,15 +1237,16 @@ static void cx231xx_media_device_register(struct 
cx231xx *dev,
 #endif
 }
 
-static void cx231xx_create_media_graph(struct cx231xx *dev)
+static int cx231xx_create_media_graph(struct cx231xx *dev)
 {
 #ifdef CONFIG_MEDIA_CONTROLLER
struct media_device *mdev = dev->media_dev;
struct media_entity *entity;
struct media_entity *tuner = NULL, *decoder = NULL;
+   int ret;
 
if (!mdev)
-   return;
+   return 0;
 
media_device_for_each_entity(entity, mdev) {
switch (entity->type) {
@@ -1261,16 +1262,24 @@ static void cx231xx_create_media_graph(struct cx231xx 
*dev)
/* Analog setup, using tuner as a link */
 
if (!decoder)
-   return;
+   return 0;
 
-   if (tuner)
-   media_create_pad_link(tuner, TUNER_PAD_IF_OUTPUT, decoder, 0,
-MEDIA_LNK_FL_ENABLED);
-   media_create_pad_link(decoder, 1, >vdev.entity, 0,
-MEDIA_LNK_FL_ENABLED);
-   media_create_pad_link(decoder, 2, >vbi_dev.entity, 0,
-MEDIA_LNK_FL_ENABLED);
+   if (tuner) {
+   ret = media_create_pad_link(tuner, TUNER_PAD_IF_OUTPUT, 
decoder, 0,
+   MEDIA_LNK_FL_ENABLED);
+   if (ret < 0)
+   return ret;
+   }
+   ret = media_create_pad_link(decoder, 1, >vdev.entity, 0,
+   MEDIA_LNK_FL_ENABLED);
+   if (ret < 0)
+   return ret;
+   ret = media_create_pad_link(decoder, 2, >vbi_dev.entity, 0,
+   MEDIA_LNK_FL_ENABLED);
+   if (ret < 0)
+   return ret;
 #endif
+   return 0;
 }
 
 /*
@@ -1732,9 +1741,12 @@ static int cx231xx_usb_probe(struct usb_interface 
*interface,
/* load other modules required */
request_modules(dev);
 
-   cx231xx_create_media_graph(dev);
+   retval = cx231xx_create_media_graph(dev);
+   if (retval < 0) {
+   cx231xx_release_resources(dev);
+   }
 
-   return 0;
+   return retval;
 err_video_alt:
/* cx231xx_uninit_dev: */
cx231xx_close_extension(dev);
-- 
2.4.3


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


[PATCH 01/18] [media] tuner-core: add an input pad

2015-09-06 Thread Mauro Carvalho Chehab
Tuners actually have at least one connector on its
input.

Add a PAD to connect it.

Signed-off-by: Mauro Carvalho Chehab 

diff --git a/drivers/media/dvb-core/dvbdev.c b/drivers/media/dvb-core/dvbdev.c
index f00f1a5f279c..a8e7e2398f7a 100644
--- a/drivers/media/dvb-core/dvbdev.c
+++ b/drivers/media/dvb-core/dvbdev.c
@@ -34,6 +34,9 @@
 #include 
 #include "dvbdev.h"
 
+/* Due to enum tuner_pad_index */
+#include 
+
 static DEFINE_MUTEX(dvbdev_mutex);
 static int dvbdev_debug;
 
@@ -552,7 +555,7 @@ void dvb_create_media_graph(struct dvb_adapter *adap)
}
 
if (tuner && demod)
-   media_create_pad_link(tuner, 0, demod, 0, 0);
+   media_create_pad_link(tuner, TUNER_PAD_IF_OUTPUT, demod, 0, 0);
 
if (demod && demux)
media_create_pad_link(demod, 1, demux, 0, MEDIA_LNK_FL_ENABLED);
diff --git a/drivers/media/usb/au0828/au0828-core.c 
b/drivers/media/usb/au0828/au0828-core.c
index e28cabe65934..f54c7d10f350 100644
--- a/drivers/media/usb/au0828/au0828-core.c
+++ b/drivers/media/usb/au0828/au0828-core.c
@@ -27,6 +27,9 @@
 #include 
 #include 
 
+/* Due to enum tuner_pad_index */
+#include 
+
 /*
  * 1 = General debug messages
  * 2 = USB handling
@@ -260,7 +263,7 @@ static void au0828_create_media_graph(struct au0828_dev 
*dev)
return;
 
if (tuner)
-   media_create_pad_link(tuner, 0, decoder, 0,
+   media_create_pad_link(tuner, TUNER_PAD_IF_OUTPUT, decoder, 0,
  MEDIA_LNK_FL_ENABLED);
media_create_pad_link(decoder, 1, >vdev.entity, 0,
  MEDIA_LNK_FL_ENABLED);
diff --git a/drivers/media/usb/cx231xx/cx231xx-cards.c 
b/drivers/media/usb/cx231xx/cx231xx-cards.c
index 3b5c9ae39ad3..1070d87efc65 100644
--- a/drivers/media/usb/cx231xx/cx231xx-cards.c
+++ b/drivers/media/usb/cx231xx/cx231xx-cards.c
@@ -1264,7 +1264,7 @@ static void cx231xx_create_media_graph(struct cx231xx 
*dev)
return;
 
if (tuner)
-   media_create_pad_link(tuner, 0, decoder, 0,
+   media_create_pad_link(tuner, TUNER_PAD_IF_OUTPUT, decoder, 0,
 MEDIA_LNK_FL_ENABLED);
media_create_pad_link(decoder, 1, >vdev.entity, 0,
 MEDIA_LNK_FL_ENABLED);
diff --git a/drivers/media/v4l2-core/tuner-core.c 
b/drivers/media/v4l2-core/tuner-core.c
index 100b8f069640..b90f2a52db96 100644
--- a/drivers/media/v4l2-core/tuner-core.c
+++ b/drivers/media/v4l2-core/tuner-core.c
@@ -134,8 +134,9 @@ struct tuner {
unsigned inttype; /* chip type id */
void*config;
const char  *name;
+
 #if defined(CONFIG_MEDIA_CONTROLLER)
-   struct media_padpad;
+   struct media_padpad[TUNER_NUM_PADS];
 #endif
 };
 
@@ -695,11 +696,12 @@ static int tuner_probe(struct i2c_client *client,
/* Should be just before return */
 register_client:
 #if defined(CONFIG_MEDIA_CONTROLLER)
-   t->pad.flags = MEDIA_PAD_FL_SOURCE;
+   t->pad[TUNER_PAD_RF_INPUT].flags = MEDIA_PAD_FL_SINK;
+   t->pad[TUNER_PAD_IF_OUTPUT].flags = MEDIA_PAD_FL_SOURCE;
t->sd.entity.type = MEDIA_ENT_T_V4L2_SUBDEV_TUNER;
t->sd.entity.name = t->name;
 
-   ret = media_entity_init(>sd.entity, 1, >pad);
+   ret = media_entity_init(>sd.entity, TUNER_NUM_PADS, >pad[0]);
if (ret < 0) {
tuner_err("failed to initialize media entity!\n");
kfree(t);
diff --git a/include/media/tuner.h b/include/media/tuner.h
index b46ebb48fe74..95835c8069dd 100644
--- a/include/media/tuner.h
+++ b/include/media/tuner.h
@@ -25,6 +25,14 @@
 
 #include 
 
+/* Tuner PADs */
+/* FIXME: is this the right place for it? */
+enum tuner_pad_index {
+   TUNER_PAD_RF_INPUT,
+   TUNER_PAD_IF_OUTPUT,
+   TUNER_NUM_PADS
+};
+
 #define ADDR_UNSET (255)
 
 #define TUNER_TEMIC_PAL0/* 4002 FH5 (3X 7756, 
9483) */
-- 
2.4.3


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


[PATCH 16/18] [media] DocBook: update entities documentation

2015-09-06 Thread Mauro Carvalho Chehab
Due to the rename, the documentation became outdated.

Update it to reflect what's there at media.h.

Signed-off-by: Mauro Carvalho Chehab 

diff --git a/Documentation/DocBook/media/v4l/media-ioc-enum-entities.xml 
b/Documentation/DocBook/media/v4l/media-ioc-enum-entities.xml
index bc101516e372..f9bfe8094d6d 100644
--- a/Documentation/DocBook/media/v4l/media-ioc-enum-entities.xml
+++ b/Documentation/DocBook/media/v4l/media-ioc-enum-entities.xml
@@ -179,54 +179,60 @@
 

  
-   MEDIA_ENT_T_UNKNOWN and 
MEDIA_ENT_T_V4L2_SUBDEV_UNKNOWN
+   MEDIA_ENT_F_UNKNOWN and 
MEDIA_ENT_F_V4L2_SUBDEV_UNKNOWN
Unknown entity. That generally indicates that
a driver didn't initialize properly the entity, with is a Kernel 
bug
  
  
-   MEDIA_ENT_T_V4L2_VIDEO
-   V4L video streaming input or output entity
+   MEDIA_ENT_F_IO
+   Data streaming input and/or output entity.
  
-   MEDIA_ENT_T_V4L2_VBI
-   V4L VBI streaming input or output entity
+ 
+   MEDIA_ENT_F_DTV_DEMOD
+   Digital TV demodulator entity.
+ 
+ 
+   MEDIA_ENT_F_MPEG_TS_DEMUX
+   MPEG Transport stream demux entity. Could be implemented on 
hardware or in Kernelspace by the Linux DVB subsystem.
  
-   MEDIA_ENT_T_V4L2_SWRADIO
-   V4L Sofware Digital Radio (SDR) streaming input or output 
entity
+ 
+   MEDIA_ENT_F_DTV_CA
+   Digital TV Conditional Access module (CAM) entity
  
  
-   MEDIA_ENT_T_DVB_DEMOD
-   DVB demodulator entity
+   MEDIA_ENT_F_DTV_NET_DECAP
+   Digital TV network ULE/MLE desencapsulation entity. Could be 
implemented on hardware or in Kernelspace
  
  
-   MEDIA_ENT_T_DVB_DEMUX
-   DVB demux entity. Could be implemented on hardware or in 
Kernelspace
+   MEDIA_ENT_F_CONN_RF
+   Connector for a Radio Frequency (RF) signal.
  
  
-   MEDIA_ENT_T_DVB_TSOUT
-   DVB Transport Stream output entity
+   MEDIA_ENT_F_CONN_SVIDEO
+   Connector for a S-Video signal.
  
  
-   MEDIA_ENT_T_DVB_CA
-   DVB Conditional Access module (CAM) entity
+   MEDIA_ENT_F_CONN_COMPOSITE
+   Connector for a RGB composite signal.
  
  
-   MEDIA_ENT_T_DVB_DEMOD_NET_DECAP
-   DVB network ULE/MLE desencapsulation entity. Could be 
implemented on hardware or in Kernelspace
+   MEDIA_ENT_F_CONN_TEST
+   Connector for a test generator.
  
  
-   MEDIA_ENT_T_V4L2_SUBDEV_SENSOR
-   Camera video sensor entity
+   MEDIA_ENT_F_CAM_SENSOR
+   Camera video sensor entity.
  
  
-   MEDIA_ENT_T_V4L2_SUBDEV_FLASH
-   Flash controller entity
+   MEDIA_ENT_F_FLASH
+   Flash controller entity.
  
  
-   MEDIA_ENT_T_V4L2_SUBDEV_LENS
-   Lens controller entity
+   MEDIA_ENT_F_LENS
+   Lens controller entity.
  
  
-   MEDIA_ENT_T_V4L2_SUBDEV_DECODER
+   MEDIA_ENT_F_ATV_DECODER
Analog video decoder, the basic function of the video decoder
is to accept analogue video from a wide variety of sources such as
broadcast, DVD players, cameras and video cassette recorders, in
@@ -236,8 +242,8 @@
signals.
  
  
-   MEDIA_ENT_T_V4L2_SUBDEV_TUNER
-   Digital TV, analog TV, radio and/or software radio 
tuner
+   MEDIA_ENT_F_TUNER
+   Digital TV, analog TV, radio and/or software radio 
tuner.
  

   
-- 
2.4.3


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


[PATCH 08/18] [media] dvb core: must check dvb_create_media_graph()

2015-09-06 Thread Mauro Carvalho Chehab
If media controller is enabled and mdev is filled, it should
ensure that the media graph will be properly initialized.

Enforce that.

Signed-off-by: Mauro Carvalho Chehab 

diff --git a/drivers/media/common/siano/smsdvb-main.c 
b/drivers/media/common/siano/smsdvb-main.c
index f4305ae800f4..ab345490a43a 100644
--- a/drivers/media/common/siano/smsdvb-main.c
+++ b/drivers/media/common/siano/smsdvb-main.c
@@ -1183,7 +1183,11 @@ static int smsdvb_hotplug(struct smscore_device_t 
*coredev,
if (smsdvb_debugfs_create(client) < 0)
pr_info("failed to create debugfs node\n");
 
-   dvb_create_media_graph(>adapter);
+   rc = dvb_create_media_graph(>adapter);
+   if (rc < 0) {
+   pr_err("dvb_create_media_graph failed %d\n", rc);
+   goto client_error;
+   }
 
pr_info("DVB interface registered.\n");
return 0;
diff --git a/drivers/media/dvb-core/dvbdev.c b/drivers/media/dvb-core/dvbdev.c
index 5c51084a331a..df2fe4cc2d47 100644
--- a/drivers/media/dvb-core/dvbdev.c
+++ b/drivers/media/dvb-core/dvbdev.c
@@ -430,17 +430,6 @@ int dvb_register_device(struct dvb_adapter *adap, struct 
dvb_device **pdvbdev,
return -ENOMEM;
}
 
-   ret = dvb_register_media_device(dvbdev, type, minor, demux_sink_pads);
-   if (ret) {
-   printk(KERN_ERR
- "%s: dvb_register_media_device failed to create the 
mediagraph\n",
- __func__);
-
-   dvb_media_device_free(dvbdev);
-   mutex_unlock(_register_lock);
-   return ret;
-   }
-
dvbdevfops = kzalloc(sizeof(struct file_operations), GFP_KERNEL);
 
if (!dvbdevfops){
@@ -493,6 +482,17 @@ int dvb_register_device(struct dvb_adapter *adap, struct 
dvb_device **pdvbdev,
   __func__, adap->num, dnames[type], id, PTR_ERR(clsdev));
return PTR_ERR(clsdev);
}
+
+   ret = dvb_register_media_device(dvbdev, type, minor, demux_sink_pads);
+   if (ret) {
+   printk(KERN_ERR
+ "%s: dvb_register_media_device failed to create the media 
graph\n",
+ __func__);
+
+   dvb_unregister_device(dvbdev);
+   return ret;
+   }
+
dprintk(KERN_DEBUG "DVB: register adapter%d/%s%d @ minor: %i 
(0x%02x)\n",
adap->num, dnames[type], id, minor, minor);
 
diff --git a/drivers/media/dvb-core/dvbdev.h b/drivers/media/dvb-core/dvbdev.h
index 9e24aafeb9ea..bd9fac91c7b9 100644
--- a/drivers/media/dvb-core/dvbdev.h
+++ b/drivers/media/dvb-core/dvbdev.h
@@ -210,7 +210,7 @@ int dvb_register_device(struct dvb_adapter *adap,
 void dvb_unregister_device(struct dvb_device *dvbdev);
 
 #ifdef CONFIG_MEDIA_CONTROLLER_DVB
-int dvb_create_media_graph(struct dvb_adapter *adap);
+__must_check int dvb_create_media_graph(struct dvb_adapter *adap);
 static inline void dvb_register_media_controller(struct dvb_adapter *adap,
 struct media_device *mdev)
 {
diff --git a/drivers/media/usb/au0828/au0828-dvb.c 
b/drivers/media/usb/au0828/au0828-dvb.c
index c01772c4f9f0..cd542b49a6c2 100644
--- a/drivers/media/usb/au0828/au0828-dvb.c
+++ b/drivers/media/usb/au0828/au0828-dvb.c
@@ -486,12 +486,14 @@ static int dvb_register(struct au0828_dev *dev)
dvb->start_count = 0;
dvb->stop_count = 0;
 
-#ifdef CONFIG_MEDIA_CONTROLLER_DVB
-   dvb_create_media_graph(>adapter);
-#endif
+   result = dvb_create_media_graph(>adapter);
+   if (result < 0)
+   goto fail_create_graph;
 
return 0;
 
+fail_create_graph:
+   dvb_net_release(>net);
 fail_fe_conn:
dvb->demux.dmx.remove_frontend(>demux.dmx, >fe_mem);
 fail_fe_mem:
diff --git a/drivers/media/usb/cx231xx/cx231xx-dvb.c 
b/drivers/media/usb/cx231xx/cx231xx-dvb.c
index 66ee161fc7ba..aaf8ef246f13 100644
--- a/drivers/media/usb/cx231xx/cx231xx-dvb.c
+++ b/drivers/media/usb/cx231xx/cx231xx-dvb.c
@@ -551,10 +551,14 @@ static int register_dvb(struct cx231xx_dvb *dvb,
 
/* register network adapter */
dvb_net_init(>adapter, >net, >demux.dmx);
-   dvb_create_media_graph(>adapter);
+   result = dvb_create_media_graph(>adapter);
+   if (result < 0)
+   goto fail_create_graph;
 
return 0;
 
+fail_create_graph:
+   dvb_net_release(>net);
 fail_fe_conn:
dvb->demux.dmx.remove_frontend(>demux.dmx, >fe_mem);
 fail_fe_mem:
diff --git a/drivers/media/usb/dvb-usb-v2/dvb_usb_core.c 
b/drivers/media/usb/dvb-usb-v2/dvb_usb_core.c
index f5df9eaba04f..6d3f61f6dc77 100644
--- a/drivers/media/usb/dvb-usb-v2/dvb_usb_core.c
+++ b/drivers/media/usb/dvb-usb-v2/dvb_usb_core.c
@@ -698,7 +698,9 @@ static int dvb_usbv2_adapter_frontend_init(struct 
dvb_usb_adapter *adap)
}
}
 
-   dvb_create_media_graph(>dvb_adap);
+   ret = dvb_create_media_graph(>dvb_adap);
+   if 

[PATCH 14/18] [media] media-device: export the entity function via new ioctl

2015-09-06 Thread Mauro Carvalho Chehab
Now that entities have a main function, expose it via
MEDIA_IOC_G_TOPOLOGY ioctl.

Signed-off-by: Mauro Carvalho Chehab 

diff --git a/drivers/media/media-device.c b/drivers/media/media-device.c
index ccef9621d147..32090030c342 100644
--- a/drivers/media/media-device.c
+++ b/drivers/media/media-device.c
@@ -263,6 +263,7 @@ static long __media_device_get_topology(struct media_device 
*mdev,
/* Copy fields to userspace struct if not error */
memset(, 0, sizeof(uentity));
uentity.id = entity->graph_obj.id;
+   uentity.function = entity->function;
strncpy(uentity.name, entity->name,
sizeof(uentity.name));
 
diff --git a/include/uapi/linux/media.h b/include/uapi/linux/media.h
index 69433405aec2..d232cc680c67 100644
--- a/include/uapi/linux/media.h
+++ b/include/uapi/linux/media.h
@@ -284,7 +284,8 @@ struct media_links_enum {
 struct media_v2_entity {
__u32 id;
char name[64];  /* FIXME: move to a property? (RFC says so) */
-   __u16 reserved[14];
+   __u32 function; /* Main function of the entity */
+   __u16 reserved[12];
 };
 
 /* Should match the specific fields at media_intf_devnode */
-- 
2.4.3


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


[PATCH 11/18] [media] au0828:: enforce check for graph creation

2015-09-06 Thread Mauro Carvalho Chehab
If the graph creation fails, don't register the device.

Signed-off-by: Mauro Carvalho Chehab 

diff --git a/drivers/media/usb/au0828/au0828-core.c 
b/drivers/media/usb/au0828/au0828-core.c
index 35c607c35155..399c6712faf9 100644
--- a/drivers/media/usb/au0828/au0828-core.c
+++ b/drivers/media/usb/au0828/au0828-core.c
@@ -172,9 +172,9 @@ static void au0828_usb_v4l2_release(struct v4l2_device 
*v4l2_dev)
struct au0828_dev *dev =
container_of(v4l2_dev, struct au0828_dev, v4l2_dev);
 
-   au0828_usb_v4l2_media_release(dev);
v4l2_ctrl_handler_free(>v4l2_ctrl_hdl);
v4l2_device_unregister(>v4l2_dev);
+   au0828_usb_v4l2_media_release(dev);
au0828_usb_release(dev);
 }
 #endif
@@ -251,16 +251,16 @@ static void au0828_media_device_register(struct 
au0828_dev *dev,
 }
 
 
-static void au0828_create_media_graph(struct au0828_dev *dev)
+static int au0828_create_media_graph(struct au0828_dev *dev)
 {
 #ifdef CONFIG_MEDIA_CONTROLLER
struct media_device *mdev = dev->media_dev;
struct media_entity *entity;
struct media_entity *tuner = NULL, *decoder = NULL;
-   int i;
+   int i, ret;
 
if (!mdev)
-   return;
+   return 0;
 
media_device_for_each_entity(entity, mdev) {
switch (entity->type) {
@@ -277,15 +277,23 @@ static void au0828_create_media_graph(struct au0828_dev 
*dev)
 
/* Something bad happened! */
if (!decoder)
-   return;
+   return -EINVAL;
 
-   if (tuner)
-   media_create_pad_link(tuner, TUNER_PAD_IF_OUTPUT, decoder, 0,
- MEDIA_LNK_FL_ENABLED);
-   media_create_pad_link(decoder, 1, >vdev.entity, 0,
- MEDIA_LNK_FL_ENABLED);
-   media_create_pad_link(decoder, 2, >vbi_dev.entity, 0,
- MEDIA_LNK_FL_ENABLED);
+   if (tuner) {
+   ret = media_create_pad_link(tuner, TUNER_PAD_IF_OUTPUT,
+   decoder, 0,
+   MEDIA_LNK_FL_ENABLED);
+   if (ret)
+   return ret;
+   }
+   ret = media_create_pad_link(decoder, 1, >vdev.entity, 0,
+   MEDIA_LNK_FL_ENABLED);
+   if (ret)
+   return ret;
+   ret = media_create_pad_link(decoder, 2, >vbi_dev.entity, 0,
+   MEDIA_LNK_FL_ENABLED);
+   if (ret)
+   return ret;
 
for (i = 0; i < AU0828_MAX_INPUT; i++) {
struct media_entity *ent = >input_ent[i];
@@ -297,20 +305,27 @@ static void au0828_create_media_graph(struct au0828_dev 
*dev)
case AU0828_VMUX_CABLE:
case AU0828_VMUX_TELEVISION:
case AU0828_VMUX_DVB:
-   if (tuner)
-   media_create_pad_link(ent, 0, tuner,
- TUNER_PAD_RF_INPUT,
- MEDIA_LNK_FL_ENABLED);
+   if (!tuner)
+   break;
+
+   ret = media_create_pad_link(ent, 0, tuner,
+   TUNER_PAD_RF_INPUT,
+   MEDIA_LNK_FL_ENABLED);
+   if (ret)
+   return ret;
break;
case AU0828_VMUX_COMPOSITE:
case AU0828_VMUX_SVIDEO:
default: /* AU0828_VMUX_DEBUG */
/* FIXME: fix the decoder PAD */
-   media_create_pad_link(ent, 0, decoder, 0, 0);
+   ret = media_create_pad_link(ent, 0, decoder, 0, 0);
+   if (ret)
+   return ret;
break;
}
}
 #endif
+   return 0;
 }
 
 static int au0828_usb_probe(struct usb_interface *interface,
@@ -425,7 +440,12 @@ static int au0828_usb_probe(struct usb_interface 
*interface,
 
mutex_unlock(>lock);
 
-   au0828_create_media_graph(dev);
+   retval = au0828_create_media_graph(dev);
+   if (retval) {
+   pr_err("%s() au0282_dev_register failed to create graph\n",
+  __func__);
+   au0828_usb_disconnect(interface);
+   }
 
return retval;
 }
-- 
2.4.3


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


3rd posting: em28xx: new board id [1f4d:1abe]

2015-09-06 Thread Ronald Tallent
Hi, 

This is my third attempt to post this information to mailing list in a
little over a week. Am I invisible? Can nobody see my messages? I have
precisely followed the instructions posted on
linuxtv.org/wiki/index.php/Em28xx_devices#How_to_validate_my_vendor.2Fproduct_id_at_upstream_kernel.3F
trying to get my hardware validated. What else do I need to do?  Can
someone answer please and help me. 

Thanks,
--Ronald


I've tested my USB easycap device (Geniatech iGrabber) in Ubuntu
14.04.

Make: Geniatech
Model: iGrabber for MAC
Vendor/Product ID: [1f4d:1abe]
Product website: www.geniatech.com/pa/igrabber.asp

Tests Made:
- Audio Capture [worked]
- Video Capture [device not detected]
- DVB [does not have DVB]

Tested by:
r...@tallent.ws


Detailed information on device and system below for reference:

uname -a:
3.13.0-62-generic #102-Ubuntu SMP Tue Aug 11 14:29:36 UTC 2015 x86_64 
x86_64 x86_64 GNU/Linux

dmesg:
[] usb 3-3.3: new high-speed USB device number 8 using xhci_hcd
[] usb 3-3.3: New USB device found, idVendor=1f4d, idProduct=1abe
[] usb 3-3.3: New USB device strings: Mfr=0, Product=1, SerialNumber=0
[] usb 3-3.3: Product: USB Device
[] usbcore: registered new interface driver snd-usb-audio

lsusb:
Bus 003 Device 008: ID 1f4d:1abe G-Tek Electronics Group 

Hardware: 
Opened the case and found the following text printed on the board:
   HandyCap
   v1.51
   2007-4-24

Three chips on board are:
1: empia
   EM2860
   P8367-010
   201036-01AG

2: Trident
   SAA7113H
   C2P409.00 02
   A5G11152

3: eMPIA
   Technology
   EMP202
   UT11958
   1027


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