Re: [PATCH 2/4] media: Support Intersil/Techwell TW686x-based video capture cards

2016-03-22 Thread Ezequiel Garcia
Hi Hans,

On 21 March 2016 at 08:41, Hans Verkuil  wrote:
> From: Ezequiel Garcia 
>
> This commit introduces the support for the Techwell TW686x video
> capture IC. This hardware supports a few DMA modes, including
> scatter-gather and frame (contiguous).
>
> This commit makes little use of the DMA engine and instead has
> a memcpy based implementation. DMA frame and scatter-gather modes
> support may be added in the future.
>
> Currently supported chips:
> - TW6864 (4 video channels),
> - TW6865 (4 video channels, not tested, second generation chip),
> - TW6868 (8 video channels but only 4 first channels using
>built-in video decoder are supported, not tested),
> - TW6869 (8 video channels, second generation chip).
>
> Cc: Krzysztof Halasa 
> Signed-off-by: Ezequiel Garcia 
> Signed-off-by: Hans Verkuil 
> Tested-by: Hans Verkuil 
[..]
> +int tw686x_video_init(struct tw686x_dev *dev)
> +{
> +   unsigned int ch, val, pb;
> +   int err;
> +
> +   err = v4l2_device_register(&dev->pci_dev->dev, &dev->v4l2_dev);
> +   if (err)
> +   return err;
> +
> +   for (ch = 0; ch < max_channels(dev); ch++) {
> +   struct tw686x_video_channel *vc = &dev->video_channels[ch];
> +   struct video_device *vdev;
> +
> +   mutex_init(&vc->vb_mutex);
> +   spin_lock_init(&vc->qlock);
> +   INIT_LIST_HEAD(&vc->vidq_queued);
> +
> +   vc->dev = dev;
> +   vc->ch = ch;
> +
> +   /* default settings */
> +   vc->format = &formats[0];
> +   vc->video_standard = V4L2_STD_NTSC;
> +   vc->width = TW686X_VIDEO_WIDTH;
> +   vc->height = TW686X_VIDEO_HEIGHT(vc->video_standard);
> +   vc->input = 0;
> +
> +   reg_write(vc->dev, SDT[ch], 0);
> +   tw686x_set_framerate(vc, 30);
> +
> +   reg_write(dev, VDELAY_LO[ch], 0x14);
> +   reg_write(dev, HACTIVE_LO[ch], 0xd0);
> +   reg_write(dev, VIDEO_SIZE[ch], 0);
> +
> +   for (pb = 0; pb < 2; pb++) {
> +   err = tw686x_alloc_dma(vc, pb);
> +   if (err)
> +   goto error;
> +   }
> +
> +   vc->vidq.io_modes = VB2_READ | VB2_MMAP | VB2_DMABUF;
> +   vc->vidq.type = V4L2_BUF_TYPE_VIDEO_CAPTURE;
> +   vc->vidq.drv_priv = vc;
> +   vc->vidq.buf_struct_size = sizeof(struct tw686x_v4l2_buf);
> +   vc->vidq.ops = &tw686x_video_qops;
> +   vc->vidq.mem_ops = &vb2_vmalloc_memops;
> +   vc->vidq.timestamp_flags = V4L2_BUF_FLAG_TIMESTAMP_MONOTONIC;
> +   vc->vidq.min_buffers_needed = 2;
> +   vc->vidq.lock = &vc->vb_mutex;
> +

I missed the GFP_DMA32 on vb2_queue.gfp_flags.

Feel free to amend it, unless you want me to submit a patch for you to pick.

Thanks,
-- 
Ezequiel GarcĂ­a, VanguardiaSur
www.vanguardiasur.com.ar
--
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 2/4] media: Support Intersil/Techwell TW686x-based video capture cards

2016-03-21 Thread Hans Verkuil
From: Ezequiel Garcia 

This commit introduces the support for the Techwell TW686x video
capture IC. This hardware supports a few DMA modes, including
scatter-gather and frame (contiguous).

This commit makes little use of the DMA engine and instead has
a memcpy based implementation. DMA frame and scatter-gather modes
support may be added in the future.

Currently supported chips:
- TW6864 (4 video channels),
- TW6865 (4 video channels, not tested, second generation chip),
- TW6868 (8 video channels but only 4 first channels using
   built-in video decoder are supported, not tested),
- TW6869 (8 video channels, second generation chip).

Cc: Krzysztof Halasa 
Signed-off-by: Ezequiel Garcia 
Signed-off-by: Hans Verkuil 
Tested-by: Hans Verkuil 
---
 MAINTAINERS |   8 +
 drivers/media/pci/Kconfig   |   1 +
 drivers/media/pci/Makefile  |   1 +
 drivers/media/pci/tw686x/Kconfig|  18 +
 drivers/media/pci/tw686x/Makefile   |   3 +
 drivers/media/pci/tw686x/tw686x-audio.c | 386 +
 drivers/media/pci/tw686x/tw686x-core.c  | 415 ++
 drivers/media/pci/tw686x/tw686x-regs.h  | 122 +
 drivers/media/pci/tw686x/tw686x-video.c | 927 
 drivers/media/pci/tw686x/tw686x.h   | 158 ++
 10 files changed, 2039 insertions(+)
 create mode 100644 drivers/media/pci/tw686x/Kconfig
 create mode 100644 drivers/media/pci/tw686x/Makefile
 create mode 100644 drivers/media/pci/tw686x/tw686x-audio.c
 create mode 100644 drivers/media/pci/tw686x/tw686x-core.c
 create mode 100644 drivers/media/pci/tw686x/tw686x-regs.h
 create mode 100644 drivers/media/pci/tw686x/tw686x-video.c
 create mode 100644 drivers/media/pci/tw686x/tw686x.h

diff --git a/MAINTAINERS b/MAINTAINERS
index 99bd725..605fd55 100644
--- a/MAINTAINERS
+++ b/MAINTAINERS
@@ -9,6 +9,14 @@ W: https://linuxtv.org
 S: Odd Fixes
 F: drivers/media/pci/tw68/
 
+TW686X VIDEO4LINUX DRIVER
+M: Ezequiel Garcia 
+L: linux-media@vger.kernel.org
+T: git git://linuxtv.org/media_tree.git
+W: http://linuxtv.org
+S: Maintained
+F: drivers/media/pci/tw686x/
+
 TPM DEVICE DRIVER
 M: Peter Huewe 
 M: Marcel Selhorst 
diff --git a/drivers/media/pci/Kconfig b/drivers/media/pci/Kconfig
index 48a611b..4f6467f 100644
--- a/drivers/media/pci/Kconfig
+++ b/drivers/media/pci/Kconfig
@@ -14,6 +14,7 @@ source "drivers/media/pci/meye/Kconfig"
 source "drivers/media/pci/solo6x10/Kconfig"
 source "drivers/media/pci/sta2x11/Kconfig"
 source "drivers/media/pci/tw68/Kconfig"
+source "drivers/media/pci/tw686x/Kconfig"
 source "drivers/media/pci/zoran/Kconfig"
 endif
 
diff --git a/drivers/media/pci/Makefile b/drivers/media/pci/Makefile
index 5f8aacb..2e54c36 100644
--- a/drivers/media/pci/Makefile
+++ b/drivers/media/pci/Makefile
@@ -25,6 +25,7 @@ obj-$(CONFIG_VIDEO_BT848) += bt8xx/
 obj-$(CONFIG_VIDEO_SAA7134) += saa7134/
 obj-$(CONFIG_VIDEO_SAA7164) += saa7164/
 obj-$(CONFIG_VIDEO_TW68) += tw68/
+obj-$(CONFIG_VIDEO_TW686X) += tw686x/
 obj-$(CONFIG_VIDEO_DT3155) += dt3155/
 obj-$(CONFIG_VIDEO_MEYE) += meye/
 obj-$(CONFIG_STA2X11_VIP) += sta2x11/
diff --git a/drivers/media/pci/tw686x/Kconfig b/drivers/media/pci/tw686x/Kconfig
new file mode 100644
index 000..fb85369
--- /dev/null
+++ b/drivers/media/pci/tw686x/Kconfig
@@ -0,0 +1,18 @@
+config VIDEO_TW686X
+   tristate "Intersil/Techwell TW686x video capture cards"
+   depends on PCI && VIDEO_DEV && VIDEO_V4L2 && SND
+   depends on HAS_DMA
+   select VIDEOBUF2_VMALLOC
+   select SND_PCM
+   help
+ Support for Intersil/Techwell TW686x-based frame grabber cards.
+
+ Currently supported chips:
+ - TW6864 (4 video channels),
+ - TW6865 (4 video channels, not tested, second generation chip),
+ - TW6868 (8 video channels but only 4 first channels using
+   built-in video decoder are supported, not tested),
+ - TW6869 (8 video channels, second generation chip).
+
+ To compile this driver as a module, choose M here: the module
+ will be named tw686x.
diff --git a/drivers/media/pci/tw686x/Makefile 
b/drivers/media/pci/tw686x/Makefile
new file mode 100644
index 000..9981954
--- /dev/null
+++ b/drivers/media/pci/tw686x/Makefile
@@ -0,0 +1,3 @@
+tw686x-objs := tw686x-core.o tw686x-video.o tw686x-audio.o
+
+obj-$(CONFIG_VIDEO_TW686X) += tw686x.o
diff --git a/drivers/media/pci/tw686x/tw686x-audio.c 
b/drivers/media/pci/tw686x/tw686x-audio.c
new file mode 100644
index 000..91459ab
--- /dev/null
+++ b/drivers/media/pci/tw686x/tw686x-audio.c
@@ -0,0 +1,386 @@
+/*
+ * Copyright (C) 2015 VanguardiaSur - www.vanguardiasur.com.ar
+ *
+ * Based on the audio support from the tw6869 driver:
+ * Copyright 2015 www.starterkit.ru 
+ *
+ * Based on:
+ * Driver for Intersil|Techwell TW6869 based DVR cards
+ * (c) 2011-12 liran  [Intersil|Techwell China]
+ *
+ * This program is free software; you can redistr