Skip to contentSkip to conversation

v4l2: add vb2_get_unmapped_area in vb2 core

PATCH Superseded Scott Jiang 6 participants 39 messages Sep 13, 2011 – Oct 1, 2011

Subsystems (2)

v1 of 2 Superseded Latest is v2 →

lore
Share & tools
lore
#0 lore raw

PATCH 1/4 v4l2: add vb2_get_unmapped_area in vb2 core

no mmu system needs get_unmapped_area file operations to do mmap

---
 drivers/media/video/videobuf2-core.c |   31 +++++++++++++++++++++++++++++++
 include/media/videobuf2-core.h       |    7 +++++++
 2 files changed, 38 insertions(+), 0 deletions(-)
drivers/media/video/videobuf2-core.c +31 -0
index 3015e60..02a0ec6 100644
@@ -1344,6 +1344,37 @@ int vb2_mmap(struct vb2_queue *q, struct vm_area_struct *vma)
 }
 EXPORT_SYMBOL_GPL(vb2_mmap);
 
+#ifndef CONFIG_MMU
+unsigned long vb2_get_unmapped_area(struct vb2_queue *q,
+				    unsigned long addr,
+				    unsigned long len,
+				    unsigned long pgoff,
+				    unsigned long flags)
+{
+	unsigned long off = pgoff << PAGE_SHIFT;
+	struct vb2_buffer *vb;
+	unsigned int buffer, plane;
+	int ret;
+
+	if (q->memory != V4L2_MEMORY_MMAP) {
+		dprintk(1, "Queue is not currently set up for mmap\n");
+		return -EINVAL;
+	}
+
+	/*
+	 * Find the plane corresponding to the offset passed by userspace.
+	 */
+	ret = __find_plane_by_offset(q, off, &buffer, &plane);
+	if (ret)
+		return ret;
+
+	vb = q->bufs[buffer];
+
+	return (unsigned long)vb2_plane_vaddr(vb, plane);
+}
+EXPORT_SYMBOL_GPL(vb2_get_unmapped_area);
+#endif
+
 static int __vb2_init_fileio(struct vb2_queue *q, int read);
 static int __vb2_cleanup_fileio(struct vb2_queue *q);
 
include/media/videobuf2-core.h +7 -0
index f87472a..5c7b5b4 100644
@@ -302,6 +302,13 @@ int vb2_streamon(struct vb2_queue *q, enum v4l2_buf_type type);
 int vb2_streamoff(struct vb2_queue *q, enum v4l2_buf_type type);
 
 int vb2_mmap(struct vb2_queue *q, struct vm_area_struct *vma);
+#ifndef CONFIG_MMU
+unsigned long vb2_get_unmapped_area(struct vb2_queue *q,
+				    unsigned long addr,
+				    unsigned long len,
+				    unsigned long pgoff,
+				    unsigned long flags);
+#endif
 unsigned int vb2_poll(struct vb2_queue *q, struct file *file, poll_table *wait);
 size_t vb2_read(struct vb2_queue *q, char __user *data, size_t count,
 		loff_t *ppos, int nonblock);
Signature · 1 line
1.7.0.4
#1 lore raw

PATCH 2/4 v4l2: add adv7183 decoder driver

this driver is a v4l2 subdevice driver to support
Analog Devices ADV7183 SDTV video decoder

---
 drivers/media/video/Kconfig        |   10 +
 drivers/media/video/Makefile       |    1 +
 drivers/media/video/adv7183.c      |  684 ++++++++++++++++++++++++++++++++++++
 drivers/media/video/adv7183_regs.h |  107 ++++++
 include/media/adv7183.h            |   47 +++
 include/media/v4l2-chip-ident.h    |    3 +
 6 files changed, 852 insertions(+), 0 deletions(-)
 create mode 100644 drivers/media/video/adv7183.c
 create mode 100644 drivers/media/video/adv7183_regs.h
 create mode 100644 include/media/adv7183.h
drivers/media/video/Kconfig +10 -0
index f574dc0..af8ed6b 100644
@@ -273,6 +273,16 @@ config VIDEO_ADV7180
 	  To compile this driver as a module, choose M here: the
 	  module will be called adv7180.
 
+config VIDEO_ADV7183
+	tristate "Analog Devices ADV7183 decoder"
+	depends on VIDEO_V4L2 && I2C
+	---help---
+	  V4l2 subdevice driver for the Analog Devices
+	  ADV7183 video decoder.
+
+	  To compile this driver as a module, choose M here: the
+	  module will be called adv7183.
+
 config VIDEO_BT819
 	tristate "BT819A VideoStream decoder"
 	depends on VIDEO_V4L2 && I2C
drivers/media/video/Makefile +1 -0
index 2723900..b0329ae 100644
@@ -40,6 +40,7 @@ obj-$(CONFIG_VIDEO_SAA7191) += saa7191.o
 obj-$(CONFIG_VIDEO_ADV7170) += adv7170.o
 obj-$(CONFIG_VIDEO_ADV7175) += adv7175.o
 obj-$(CONFIG_VIDEO_ADV7180) += adv7180.o
+obj-$(CONFIG_VIDEO_ADV7183) += adv7183.o
 obj-$(CONFIG_VIDEO_ADV7343) += adv7343.o
 obj-$(CONFIG_VIDEO_VPX3220) += vpx3220.o
 obj-$(CONFIG_VIDEO_BT819) += bt819.o
drivers/media/video/adv7183.c new file +684 -0

684 lines not on this page · raw message

drivers/media/video/adv7183_regs.h new file +107 -0

107 lines not on this page · raw message

include/media/adv7183.h new file +47 -0

47 lines not on this page · raw message

include/media/v4l2-chip-ident.h +3 -0
index 63fd9d3..20fd16d 100644
@@ -162,6 +162,9 @@ enum {
 	/* module adv7180: just ident 7180 */
 	V4L2_IDENT_ADV7180 = 7180,
 
+	/* module adv7183: just ident 7183 */
+	V4L2_IDENT_ADV7183 = 7183,
+
 	/* module saa7185: just ident 7185 */
 	V4L2_IDENT_SAA7185 = 7185,
 
Signature · 1 line
1.7.0.4
#2 lore raw

Re: [uclinux-dist-devel] [PATCH 2/4] v4l2: add adv7183 decoder driver

drivers/media/video/adv7183_regs.h

Quoted 4 lines · Scott Jiang
drivers/media/video/adv7183_regs.h new file +1 -0
 
+#define        ADV7183_IN_CTRL            0x00 /* Input control */

should be a space after the #define, not a tab

include/media/adv7183.h

Quoted 4 lines
include/media/adv7183.h new file +1 -0
 
+#define        ADV7183_16BIT_OUT   1

same here
-mike

#3 lore raw

PATCH 3/4 v4l2: add vs6624 sensor driver

In reply to Scott Jiang

this is a v4l2 sensor-level driver for the ST VS6624 camera

---
 drivers/media/video/Kconfig       |   10 +
 drivers/media/video/Makefile      |    1 +
 drivers/media/video/vs6624.c      |  941 +++++++++++++++++++++++++++++++++++++
 drivers/media/video/vs6624_regs.h |  337 +++++++++++++
 include/media/v4l2-chip-ident.h   |    3 +
 5 files changed, 1292 insertions(+), 0 deletions(-)
 create mode 100644 drivers/media/video/vs6624.c
 create mode 100644 drivers/media/video/vs6624_regs.h
drivers/media/video/Kconfig +10 -0
index af8ed6b..1c03abf 100644
@@ -477,6 +477,16 @@ config VIDEO_OV7670
 	  OV7670 VGA camera.  It currently only works with the M88ALP01
 	  controller.
 
+config VIDEO_VS6624
+	tristate "ST VS6624 sensor support"
+	depends on VIDEO_V4L2 && I2C
+	---help---
+	  This is a Video4Linux2 sensor-level driver for the ST VS6624
+	  camera.
+
+	  To compile this driver as a module, choose M here: the
+	  module will be called vs6624.
+
 config VIDEO_MT9V011
 	tristate "Micron mt9v011 sensor support"
 	depends on I2C && VIDEO_V4L2
drivers/media/video/Makefile +1 -0
index b0329ae..127eba5 100644
@@ -42,6 +42,7 @@ obj-$(CONFIG_VIDEO_ADV7175) += adv7175.o
 obj-$(CONFIG_VIDEO_ADV7180) += adv7180.o
 obj-$(CONFIG_VIDEO_ADV7183) += adv7183.o
 obj-$(CONFIG_VIDEO_ADV7343) += adv7343.o
+obj-$(CONFIG_VIDEO_VS6624)  += vs6624.o
 obj-$(CONFIG_VIDEO_VPX3220) += vpx3220.o
 obj-$(CONFIG_VIDEO_BT819) += bt819.o
 obj-$(CONFIG_VIDEO_BT856) += bt856.o
drivers/media/video/vs6624.c new file +941 -0

941 lines not on this page · raw message

drivers/media/video/vs6624_regs.h new file +337 -0

337 lines not on this page · raw message

include/media/v4l2-chip-ident.h +3 -0
index 20fd16d..0133b3b 100644
@@ -143,6 +143,9 @@ enum {
 	/* module saa6588: just ident 6588 */
 	V4L2_IDENT_SAA6588 = 6588,
 
+	/* module vs6624: just ident 6624 */
+	V4L2_IDENT_VS6624 = 6624,
+
 	/* module saa6752hs: reserved range 6750-6759 */
 	V4L2_IDENT_SAA6752HS = 6752,
 	V4L2_IDENT_SAA6752HS_AC3 = 6753,
Signature · 1 line
1.7.0.4
#4 lore raw

Re: [PATCH 3/4] v4l2: add vs6624 sensor driver

Hi Scott

Thanks for the patch. I am not doing a full review, just a couple of notes:

Quoted 4 lines · Scott Jiang

this is a v4l2 sensor-level driver for the ST VS6624 camera

---

[snip]

Quoted 6 lines
drivers/media/video/vs6624.c new file +0 -0
new file mode 100644
index 0000000..b0030ab
@@ -0,0 +1,941 @@

[snip]

drivers/media/video/vs6624.c line 48

Quoted 12 lines
drivers/media/video/vs6624.c new file +12 -0
+#define VGA_WIDTH       640
+#define VGA_HEIGHT      480
+#define QVGA_WIDTH      320
+#define QVGA_HEIGHT     240
+#define QQVGA_WIDTH     160
+#define QQVGA_HEIGHT    120
+#define CIF_WIDTH       352
+#define CIF_HEIGHT      288
+#define QCIF_WIDTH      176
+#define QCIF_HEIGHT     144
+#define QQCIF_WIDTH     88
+#define QQCIF_HEIGHT    72

...Can anyone put these in a central header, please? really, please?;-)

[snip]

Quoted 324 lines
drivers/media/video/vs6624.c new file +324 -0
+static const u16 vs6624_p1[] = {
+	0x8104, 0x03,
+	0x8105, 0x01,
+	0xc900, 0x03,
+	0xc904, 0x47,
+	0xc905, 0x10,
+	0xc906, 0x80,
+	0xc907, 0x3a,
+	0x903a, 0x02,
+	0x903b, 0x47,
+	0x903c, 0x15,
+	0xc908, 0x31,
+	0xc909, 0xdc,
+	0xc90a, 0x80,
+	0xc90b, 0x44,
+	0x9044, 0x02,
+	0x9045, 0x31,
+	0x9046, 0xe2,
+	0xc90c, 0x07,
+	0xc90d, 0xe0,
+	0xc90e, 0x80,
+	0xc90f, 0x47,
+	0x9047, 0x90,
+	0x9048, 0x83,
+	0x9049, 0x81,
+	0x904a, 0xe0,
+	0x904b, 0x60,
+	0x904c, 0x08,
+	0x904d, 0x90,
+	0x904e, 0xc0,
+	0x904f, 0x43,
+	0x9050, 0x74,
+	0x9051, 0x01,
+	0x9052, 0xf0,
+	0x9053, 0x80,
+	0x9054, 0x05,
+	0x9055, 0xE4,
+	0x9056, 0x90,
+	0x9057, 0xc0,
+	0x9058, 0x43,
+	0x9059, 0xf0,
+	0x905a, 0x02,
+	0x905b, 0x07,
+	0x905c, 0xec,
+	0xc910, 0x5d,
+	0xc911, 0xca,
+	0xc912, 0x80,
+	0xc913, 0x5d,
+	0x905d, 0xa3,
+	0x905e, 0x04,
+	0x905f, 0xf0,
+	0x9060, 0xa3,
+	0x9061, 0x04,
+	0x9062, 0xf0,
+	0x9063, 0x22,
+	0xc914, 0x72,
+	0xc915, 0x92,
+	0xc916, 0x80,
+	0xc917, 0x64,
+	0x9064, 0x74,
+	0x9065, 0x01,
+	0x9066, 0x02,
+	0x9067, 0x72,
+	0x9068, 0x95,
+	0xc918, 0x47,
+	0xc919, 0xf2,
+	0xc91a, 0x81,
+	0xc91b, 0x69,
+	0x9169, 0x74,
+	0x916a, 0x02,
+	0x916b, 0xf0,
+	0x916c, 0xec,
+	0x916d, 0xb4,
+	0x916e, 0x10,
+	0x916f, 0x0a,
+	0x9170, 0x90,
+	0x9171, 0x80,
+	0x9172, 0x16,
+	0x9173, 0xe0,
+	0x9174, 0x70,
+	0x9175, 0x04,
+	0x9176, 0x90,
+	0x9177, 0xd3,
+	0x9178, 0xc4,
+	0x9179, 0xf0,
+	0x917a, 0x22,
+	0xc91c, 0x0a,
+	0xc91d, 0xbe,
+	0xc91e, 0x80,
+	0xc91f, 0x73,
+	0x9073, 0xfc,
+	0x9074, 0xa3,
+	0x9075, 0xe0,
+	0x9076, 0xf5,
+	0x9077, 0x82,
+	0x9078, 0x8c,
+	0x9079, 0x83,
+	0x907a, 0xa3,
+	0x907b, 0xa3,
+	0x907c, 0xe0,
+	0x907d, 0xfc,
+	0x907e, 0xa3,
+	0x907f, 0xe0,
+	0x9080, 0xc3,
+	0x9081, 0x9f,
+	0x9082, 0xff,
+	0x9083, 0xec,
+	0x9084, 0x9e,
+	0x9085, 0xfe,
+	0x9086, 0x02,
+	0x9087, 0x0a,
+	0x9088, 0xea,
+	0xc920, 0x47,
+	0xc921, 0x38,
+	0xc922, 0x80,
+	0xc923, 0x89,
+	0x9089, 0xec,
+	0x908a, 0xd3,
+	0x908b, 0x94,
+	0x908c, 0x20,
+	0x908d, 0x40,
+	0x908e, 0x01,
+	0x908f, 0x1c,
+	0x9090, 0x90,
+	0x9091, 0xd3,
+	0x9092, 0xd4,
+	0x9093, 0xec,
+	0x9094, 0xf0,
+	0x9095, 0x02,
+	0x9096, 0x47,
+	0x9097, 0x3d,
+	0xc924, 0x45,
+	0xc925, 0xca,
+	0xc926, 0x80,
+	0xc927, 0x98,
+	0x9098, 0x12,
+	0x9099, 0x77,
+	0x909a, 0xd6,
+	0x909b, 0x02,
+	0x909c, 0x45,
+	0x909d, 0xcd,
+	0xc928, 0x20,
+	0xc929, 0xd5,
+	0xc92a, 0x80,
+	0xc92b, 0x9e,
+	0x909e, 0x90,
+	0x909f, 0x82,
+	0x90a0, 0x18,
+	0x90a1, 0xe0,
+	0x90a2, 0xb4,
+	0x90a3, 0x03,
+	0x90a4, 0x0e,
+	0x90a5, 0x90,
+	0x90a6, 0x83,
+	0x90a7, 0xbf,
+	0x90a8, 0xe0,
+	0x90a9, 0x60,
+	0x90aa, 0x08,
+	0x90ab, 0x90,
+	0x90ac, 0x81,
+	0x90ad, 0xfc,
+	0x90ae, 0xe0,
+	0x90af, 0xff,
+	0x90b0, 0xc3,
+	0x90b1, 0x13,
+	0x90b2, 0xf0,
+	0x90b3, 0x90,
+	0x90b4, 0x81,
+	0x90b5, 0xfc,
+	0x90b6, 0xe0,
+	0x90b7, 0xff,
+	0x90b8, 0x02,
+	0x90b9, 0x20,
+	0x90ba, 0xda,
+	0xc92c, 0x70,
+	0xc92d, 0xbc,
+	0xc92e, 0x80,
+	0xc92f, 0xbb,
+	0x90bb, 0x90,
+	0x90bc, 0x82,
+	0x90bd, 0x18,
+	0x90be, 0xe0,
+	0x90bf, 0xb4,
+	0x90c0, 0x03,
+	0x90c1, 0x06,
+	0x90c2, 0x90,
+	0x90c3, 0xc1,
+	0x90c4, 0x06,
+	0x90c5, 0x74,
+	0x90c6, 0x05,
+	0x90c7, 0xf0,
+	0x90c8, 0x90,
+	0x90c9, 0xd3,
+	0x90ca, 0xa0,
+	0x90cb, 0x02,
+	0x90cc, 0x70,
+	0x90cd, 0xbf,
+	0xc930, 0x72,
+	0xc931, 0x21,
+	0xc932, 0x81,
+	0xc933, 0x3b,
+	0x913b, 0x7d,
+	0x913c, 0x02,
+	0x913d, 0x7f,
+	0x913e, 0x7b,
+	0x913f, 0x02,
+	0x9140, 0x72,
+	0x9141, 0x25,
+	0xc934, 0x28,
+	0xc935, 0xae,
+	0xc936, 0x80,
+	0xc937, 0xd2,
+	0x90d2, 0xf0,
+	0x90d3, 0x90,
+	0x90d4, 0xd2,
+	0x90d5, 0x0a,
+	0x90d6, 0x02,
+	0x90d7, 0x28,
+	0x90d8, 0xb4,
+	0xc938, 0x28,
+	0xc939, 0xb1,
+	0xc93a, 0x80,
+	0xc93b, 0xd9,
+	0x90d9, 0x90,
+	0x90da, 0x83,
+	0x90db, 0xba,
+	0x90dc, 0xe0,
+	0x90dd, 0xff,
+	0x90de, 0x90,
+	0x90df, 0xd2,
+	0x90e0, 0x08,
+	0x90e1, 0xe0,
+	0x90e2, 0xe4,
+	0x90e3, 0xef,
+	0x90e4, 0xf0,
+	0x90e5, 0xa3,
+	0x90e6, 0xe0,
+	0x90e7, 0x74,
+	0x90e8, 0xff,
+	0x90e9, 0xf0,
+	0x90ea, 0x90,
+	0x90eb, 0xd2,
+	0x90ec, 0x0a,
+	0x90ed, 0x02,
+	0x90ee, 0x28,
+	0x90ef, 0xb4,
+	0xc93c, 0x29,
+	0xc93d, 0x79,
+	0xc93e, 0x80,
+	0xc93f, 0xf0,
+	0x90f0, 0xf0,
+	0x90f1, 0x90,
+	0x90f2, 0xd2,
+	0x90f3, 0x0e,
+	0x90f4, 0x02,
+	0x90f5, 0x29,
+	0x90f6, 0x7f,
+	0xc940, 0x29,
+	0xc941, 0x7c,
+	0xc942, 0x80,
+	0xc943, 0xf7,
+	0x90f7, 0x90,
+	0x90f8, 0x83,
+	0x90f9, 0xba,
+	0x90fa, 0xe0,
+	0x90fb, 0xff,
+	0x90fc, 0x90,
+	0x90fd, 0xd2,
+	0x90fe, 0x0c,
+	0x90ff, 0xe0,
+	0x9100, 0xe4,
+	0x9101, 0xef,
+	0x9102, 0xf0,
+	0x9103, 0xa3,
+	0x9104, 0xe0,
+	0x9105, 0x74,
+	0x9106, 0xff,
+	0x9107, 0xf0,
+	0x9108, 0x90,
+	0x9109, 0xd2,
+	0x910a, 0x0e,
+	0x910b, 0x02,
+	0x910c, 0x29,
+	0x910d, 0x7f,
+	0xc944, 0x2a,
+	0xc945, 0x42,
+	0xc946, 0x81,
+	0xc947, 0x0e,
+	0x910e, 0xf0,
+	0x910f, 0x90,
+	0x9110, 0xd2,
+	0x9111, 0x12,
+	0x9112, 0x02,
+	0x9113, 0x2a,
+	0x9114, 0x48,
+	0xc948, 0x2a,
+	0xc949, 0x45,
+	0xc94a, 0x81,
+	0xc94b, 0x15,
+	0x9115, 0x90,
+	0x9116, 0x83,
+	0x9117, 0xba,
+	0x9118, 0xe0,
+	0x9119, 0xff,
+	0x911a, 0x90,
+	0x911b, 0xd2,
+	0x911c, 0x10,
+	0x911d, 0xe0,
+	0x911e, 0xe4,
+	0x911f, 0xef,
+	0x9120, 0xf0,
+	0x9121, 0xa3,
+	0x9122, 0xe0,
+	0x9123, 0x74,
+	0x9124, 0xff,
+	0x9125, 0xf0,
+	0x9126, 0x90,
+	0x9127, 0xd2,
+	0x9128, 0x12,
+	0x9129, 0x02,
+	0x912a, 0x2a,
+	0x912b, 0x48,
+	0xc900, 0x01,
+	0x0000, 0x00,

drivers/media/video/vs6624.c line 419

Quoted 10 lines
drivers/media/video/vs6624.c new file +10 -0
+};
+
+static const u16 vs6624_p2[] = {
+	0x806f, 0x01,
+	0x058c, 0x01,
+	0x0000, 0x00,
+};
+
+static const u16 vs6624_run_setup[] = {
+	0x1d18, 0x00,		/* Enableconstrainedwhitebalance */

I'm sure many other reviewers will also ask you to replace numerical register addresses with symbolic names, since it looks like a sufficiently detailed documentation is available to you.

drivers/media/video/vs6624.c line 420

Quoted 1 line
drivers/media/video/vs6624.c new file +1 -0
+	0x200d, 0x3c,		/* Damper PeakGain Output MSB */

Actually, some of these registers are already defined in your header:

+#define VS6624_PEAK_MIN_OUT_G_MSB 0x200D /* minimum damper output for gain MSB */

so, please, just use those names here and add defines for missing registers

Quoted 76 lines
drivers/media/video/vs6624.c new file +76 -0
+	0x200e, 0x66,		/* Damper PeakGain Output LSB */
+	0x1f03, 0x65,		/* Damper Low MSB */
+	0x1f04, 0xd1,		/* Damper Low LSB */
+	0x1f07, 0x66,		/* Damper High MSB */
+	0x1f08, 0x62,		/* Damper High LSB */
+	0x1f0b, 0x00,		/* Damper Min output MSB */
+	0x1f0c, 0x00,		/* Damper Min output LSB */
+	0x2600, 0x00,		/* Nora fDisable */
+	0x2602, 0x04,		/* Nora usage */
+	0x260d, 0x63,		/* Damper Low MSB Changed 0x63 to 0x65 */
+	0x260e, 0xd1,		/* Damper Low LSB */
+	0x2611, 0x68,		/* Damper High MSB */
+	0x2612, 0xdd,		/* Damper High LSB */
+	0x2615, 0x3a,		/* Damper Min output MSB */
+	0x2616, 0x00,		/* Damper Min output LSB */
+	0x2480, 0x00,		/* Disable */
+	0x1d8a, 0x30,		/* MAXWeightHigh */
+	0x1d91, 0x62,		/* fpDamperLowThresholdHigh MSB */
+	0x1d92, 0x4a,		/* fpDamperLowThresholdHigh LSB */
+	0x1d95, 0x65,		/* fpDamperHighThresholdHigh MSB */
+	0x1d96, 0x0e,		/* fpDamperHighThresholdHigh LSB */
+	0x1da1, 0x3a,		/* fpMinimumDamperOutputLow MSB */
+	0x1da2, 0xb8,		/* fpMinimumDamperOutputLow LSB */
+	0x1e08, 0x06,		/* MAXWeightLow */
+	0x1e0a, 0x0a,		/* MAXWeightHigh */
+	0x1601, 0x3a,		/* Red A MSB */
+	0x1602, 0x14,		/* Red A LSB */
+	0x1605, 0x3b,		/* Blue A MSB */
+	0x1606, 0x85,		/* BLue A LSB */
+	0x1609, 0x3b,		/* RED B MSB */
+	0x160a, 0x85,		/* RED B LSB */
+	0x160d, 0x3a,		/* Blue B MSB */
+	0x160e, 0x14,		/* Blue B LSB */
+	0x1611, 0x30,		/* Max Distance from Locus MSB */
+	0x1612, 0x8f,		/* Max Distance from Locus MSB */
+	0x1614, 0x01,		/* Enable constrainer */
+	0x0000, 0x00,
+};
+
+static const u16 vs6624_default[] = {
+	VS6624_CONTRAST0, 0x84,
+	VS6624_SATURATION0, 0x75,
+	VS6624_GAMMA0, 0x11,
+	VS6624_CONTRAST1, 0x84,
+	VS6624_SATURATION1, 0x75,
+	VS6624_GAMMA1, 0x11,
+	VS6624_MAN_RG, 0x80,
+	VS6624_MAN_GG, 0x80,
+	VS6624_MAN_BG, 0x80,
+	VS6624_WB_MODE, 0x1,
+	VS6624_EXPO_COMPENSATION, 0xfe,
+	VS6624_EXPO_METER, 0x0,
+	VS6624_LIGHT_FREQ, 0x64,
+	VS6624_PEAK_GAIN, 0xe,
+	VS6624_PEAK_LOW_THR, 0x28,
+	VS6624_HMIRROR0, 0x0,
+	VS6624_VFLIP0, 0x0,
+	VS6624_ZOOM_HSTEP0_MSB, 0x0,
+	VS6624_ZOOM_HSTEP0_LSB, 0x1,
+	VS6624_ZOOM_VSTEP0_MSB, 0x0,
+	VS6624_ZOOM_VSTEP0_LSB, 0x1,
+	VS6624_PAN_HSTEP0_MSB, 0x0,
+	VS6624_PAN_HSTEP0_LSB, 0xf,
+	VS6624_PAN_VSTEP0_MSB, 0x0,
+	VS6624_PAN_VSTEP0_LSB, 0xf,
+	VS6624_SENSOR_MODE, 0x1,
+	VS6624_SYNC_CODE_SETUP, 0x21,
+	VS6624_DISABLE_FR_DAMPER, 0x0,
+	VS6624_FR_DEN, 0x1,
+	VS6624_FR_NUM_LSB, 0xf,
+	VS6624_INIT_PIPE_SETUP, 0x0,
+	VS6624_IMG_FMT0, 0x0,
+	VS6624_YUV_SETUP, 0x1,
+	VS6624_IMAGE_SIZE0, 0x2,
+	0x0000, 0x00,
+};

[snip]

Quoted 16 lines
drivers/media/video/vs6624.c new file +16 -0
+static int __devinit vs6624_probe(struct i2c_client *client,
+			const struct i2c_device_id *id)
+{
+	struct vs6624 *sensor;
+	struct v4l2_subdev *sd;
+	struct v4l2_ctrl_handler *hdl;
+	u16 device_id;
+	const unsigned *ce;
+	int ret;
+
+	/* Check if the adapter supports the needed features */
+	if (!i2c_check_functionality(client->adapter, I2C_FUNC_I2C))
+		return -EIO;
+
+	ce = client->dev.platform_data;
+	if (ce == NULL)

drivers/media/video/vs6624.c line 822

Quoted 10 lines
drivers/media/video/vs6624.c new file +10 -0
+		return -EINVAL;
+
+	ret = gpio_request(*ce, "VS6624 Chip Enable");
+	if (ret) {
+		v4l_err(client, "failed to request GPIO %d\n", *ce);
+		return ret;
+	}
+	gpio_direction_output(*ce, 1);
+	/* wait 100ms before any further i2c writes are performed */
+	mdelay(100);

Logically, it could be a good idea to toggle chip-enable in your v4l2_subdev_core_ops::s_power() method, but if you really have to wait for 100ms before accessing the chip...

Quoted 9 lines
drivers/media/video/vs6624.c new file +9 -0
+
+	sensor = kzalloc(sizeof(*sensor), GFP_KERNEL);
+	if (sensor == NULL) {
+		gpio_free(*ce);
+		return -ENOMEM;
+	}
+
+	sd = &sensor->sd;
+	v4l2_i2c_subdev_init(sd, client, &vs6624_ops);

drivers/media/video/vs6624.c line 841

Quoted 10 lines
drivers/media/video/vs6624.c new file +10 -0
+
+	vs6624_writeregs(sd, vs6624_p1);
+	vs6624_write(sd, VS6624_MICRO_EN, 0x2);
+	vs6624_write(sd, VS6624_DIO_EN, 0x1);
+	mdelay(10);
+	vs6624_writeregs(sd, vs6624_p2);
+
+	/* make sure the sensor is vs6624 */
+	device_id = vs6624_read(sd, VS6624_DEV_ID_MSB) << 8
+			| vs6624_read(sd, VS6624_DEV_ID_LSB);

Wow... this is like saying - sorry, guys, the chip, we just killed by writing random rubbish to it wasn't a vs6624;-) I mean, are ID registers really unreadable before writing defaults to registers?

Thanks
Guennadi
---
Guennadi Liakhovetski, Ph.D.
Freelance Open-Source Software Developer
http://www.open-technology.de/

#5 lore raw

Re: [PATCH 3/4] v4l2: add vs6624 sensor driver

Quoted 6 lines
Quoted 6 lines
drivers/media/video/vs6624.c new file +6 -0
+#define VGA_WIDTH       640
+#define VGA_HEIGHT      480
+#define QVGA_WIDTH      320
+#define QVGA_HEIGHT     240
+#define QQVGA_WIDTH     160
+#define QQVGA_HEIGHT    120
Quoted 9 lines

drivers/media/video/vs6624.c line 48

Quoted 6 lines
drivers/media/video/vs6624.c new file +6 -0
+#define CIF_WIDTH       352
+#define CIF_HEIGHT      288
+#define QCIF_WIDTH      176
+#define QCIF_HEIGHT     144
+#define QQCIF_WIDTH     88
+#define QQCIF_HEIGHT    72

...Can anyone put these in a central header, please? really, please?;-)

if already exists in some common file, please tell me

Quoted 5 lines

I'm sure many other reviewers will also ask you to replace numerical register addresses with symbolic names, since it looks like a sufficiently detailed documentation is available to you.

sorry, I can't find these names in the datasheet I downloaded from st website.

Quoted 9 lines
Quoted 2 lines

+     0x200d, 0x3c,           /* Damper PeakGain Output MSB */

Actually, some of these registers are already defined in your header:

+#define VS6624_PEAK_MIN_OUT_G_MSB     0x200D /* minimum damper output for gain MSB */

so, please, just use those names here and add defines for missing registers

I can't find many register names in datasheet. so I treat it as a binary firmware patch.

Quoted 9 lines
Quoted 8 lines

+     ret = gpio_request(*ce, "VS6624 Chip Enable");
+     if (ret) {
+             v4l_err(client, "failed to request GPIO %d\n", *ce);
+             return ret;
+     }
+     gpio_direction_output(*ce, 1);
+     /* wait 100ms before any further i2c writes are performed */
+     mdelay(100);

Quoted 3 lines

Logically, it could be a good idea to toggle chip-enable in your v4l2_subdev_core_ops::s_power() method, but if you really have to wait for 100ms before accessing the chip...

yes, I found if I don't wait a long time, the i2c operation will fail

Quoted 16 lines

drivers/media/video/vs6624.c line 841

Quoted 11 lines
drivers/media/video/vs6624.c new file +10 -0
+
+     vs6624_writeregs(sd, vs6624_p1);
+     vs6624_write(sd, VS6624_MICRO_EN, 0x2);
+     vs6624_write(sd, VS6624_DIO_EN, 0x1);
+     mdelay(10);
+     vs6624_writeregs(sd, vs6624_p2);
+
+     /* make sure the sensor is vs6624 */
+     device_id = vs6624_read(sd, VS6624_DEV_ID_MSB) << 8
+                     | vs6624_read(sd, VS6624_DEV_ID_LSB);

Wow... this is like saying - sorry, guys, the chip, we just killed by writing random rubbish to it wasn't a vs6624;-) I mean, are ID registers really unreadable before writing defaults to registers?

I remember I put this before writing registers at the first version but it failed...
Perhaps I should remove the id check, it looks strange

Scott

#6 lore raw

Re: [PATCH 3/4] v4l2: add vs6624 sensor driver

Quoted 27 lines · Scott Jiang
Quoted 6 lines
Quoted 6 lines
drivers/media/video/vs6624.c new file +6 -0
+#define VGA_WIDTH       640
+#define VGA_HEIGHT      480
+#define QVGA_WIDTH      320
+#define QVGA_HEIGHT     240
+#define QQVGA_WIDTH     160
+#define QQVGA_HEIGHT    120
Quoted 9 lines

drivers/media/video/vs6624.c line 48

Quoted 6 lines
drivers/media/video/vs6624.c new file +6 -0
+#define CIF_WIDTH       352
+#define CIF_HEIGHT      288
+#define QCIF_WIDTH      176
+#define QCIF_HEIGHT     144
+#define QQCIF_WIDTH     88
+#define QQCIF_HEIGHT    72

...Can anyone put these in a central header, please? really, please?;-)

if already exists in some common file, please tell me

Quoted 5 lines

I'm sure many other reviewers will also ask you to replace numerical register addresses with symbolic names, since it looks like a sufficiently detailed documentation is available to you.

sorry, I can't find these names in the datasheet I downloaded from st website.

Quoted 3 lines
Quoted 2 lines

+     0x200d, 0x3c,           /* Damper PeakGain Output MSB */

Quoted 8 lines
Quoted 6 lines

Actually, some of these registers are already defined in your header:

+#define VS6624_PEAK_MIN_OUT_G_MSB     0x200D /* minimum damper output for gain MSB */

so, please, just use those names here and add defines for missing registers

I can't find many register names in datasheet. so I treat it as a binary firmware patch.

Please, at least use those, that you already define in your header.

Thanks
Guennadi

Quoted 31 lines
Quoted 10 lines
Quoted 9 lines

+     ret = gpio_request(*ce, "VS6624 Chip Enable");
+     if (ret) {
+             v4l_err(client, "failed to request GPIO %d\n", *ce);
+             return ret;
+     }
+     gpio_direction_output(*ce, 1);
+     /* wait 100ms before any further i2c writes are performed */
+     mdelay(100);

Quoted 3 lines

Logically, it could be a good idea to toggle chip-enable in your v4l2_subdev_core_ops::s_power() method, but if you really have to wait for 100ms before accessing the chip...

yes, I found if I don't wait a long time, the i2c operation will fail

Quoted 16 lines

drivers/media/video/vs6624.c line 841

Quoted 11 lines
drivers/media/video/vs6624.c new file +10 -0
+
+     vs6624_writeregs(sd, vs6624_p1);
+     vs6624_write(sd, VS6624_MICRO_EN, 0x2);
+     vs6624_write(sd, VS6624_DIO_EN, 0x1);
+     mdelay(10);
+     vs6624_writeregs(sd, vs6624_p2);
+
+     /* make sure the sensor is vs6624 */
+     device_id = vs6624_read(sd, VS6624_DEV_ID_MSB) << 8
+                     | vs6624_read(sd, VS6624_DEV_ID_LSB);

Wow... this is like saying - sorry, guys, the chip, we just killed by writing random rubbish to it wasn't a vs6624;-) I mean, are ID registers really unreadable before writing defaults to registers?

Quoted 6 lines

I remember I put this before writing registers at the first version but it failed...
Perhaps I should remove the id check, it looks strange

Scott

---
Guennadi Liakhovetski, Ph.D.
Freelance Open-Source Software Developer
http://www.open-technology.de/

#7 lore raw

Re: [uclinux-dist-devel] [PATCH 3/4] v4l2: add vs6624 sensor driver

In reply to Scott Jiang
Quoted 5 lines · Scott Jiang
drivers/media/video/Makefile +1 -0
 
+obj-$(CONFIG_VIDEO_VS6624)  += vs6624.o

 obj-$(CONFIG_VIDEO_VPX3220) += vpx3220.o

should be after vpx, not before ?

drivers/media/video/vs6624.c

Quoted 4 lines
drivers/media/video/vs6624.c new file +1 -0
 
+#include <asm/gpio.h>

run these patches through checkpatch.pl ? this should be linux/gpio.h ...

drivers/media/video/vs6624.c

Quoted 2 lines
drivers/media/video/vs6624.c new file +2 -0
+static const u16 vs6624_p1[] = {
+static const u16 vs6624_p2[] = {

add comments as to what these are for ?

drivers/media/video/vs6624.c line 521

Quoted 3 lines
drivers/media/video/vs6624.c new file +3 -0
+static inline int vs6624_read(struct v4l2_subdev *sd, u16 index)
+static inline int vs6624_write(struct v4l2_subdev *sd, u16 index,
+                               u8 value)

should these be inline ? they're a little "fat" ... better to let the compiler choose

drivers/media/video/vs6624.c line 541

Quoted 9 lines
drivers/media/video/vs6624.c new file +9 -0
+static int vs6624_writeregs(struct v4l2_subdev *sd, const u16 *regs)
+{
+       u16 reg, data;
+
+       while (*regs != 0x00) {
+               reg = *regs++;
+               data = *regs++;
+
+               vs6624_write(sd, reg, (u8)data);

what's the point of declaring data as u16 if the top 8 bits are never used ?

drivers/media/video/vs6624.c line 731

Quoted 8 lines
drivers/media/video/vs6624.c new file +8 -0
+static int vs6624_g_chip_ident(struct v4l2_subdev *sd,
+               struct v4l2_dbg_chip_ident *chip)
+{
+       int rev;
+       struct i2c_client *client = v4l2_get_subdevdata(sd);
+
+       rev = vs6624_read(sd, VS6624_FW_VSN_MAJOR) << 8
+               | vs6624_read(sd, VS6624_FW_VSN_MINOR);

i'm a little surprised the compiler didnt warn about this. usually bit shifts + bitwise operators want paren to keep things clear.

Quoted 1 line

+#ifdef CONFIG_VIDEO_ADV_DEBUG

just use DEBUG ?

Quoted 2 lines

+       v4l_info(client, "chip found @ 0x%02x (%s)\n",
+                       client->addr << 1, client->adapter->name);

is that "<< 1" correct ? i dont think so ...
-mike

#8 lore raw

Re: [uclinux-dist-devel] [PATCH 3/4] v4l2: add vs6624 sensor driver

Quoted 5 lines
Quoted 2 lines

+#ifdef CONFIG_VIDEO_ADV_DEBUG

just use DEBUG ?

no, v4l2 use CONFIG_VIDEO_ADV_DEBUG

Quoted 4 lines
Quoted 2 lines

+       v4l_info(client, "chip found @ 0x%02x (%s)\n",
+                       client->addr << 1, client->adapter->name);

is that "<< 1" correct ?  i dont think so ...

every driver under media I see use this, so what's wrong?

#9 lore raw

Re: [uclinux-dist-devel] [PATCH 3/4] v4l2: add vs6624 sensor driver

Quoted 5 lines · Scott Jiang
Quoted 4 lines
Quoted 1 line

+#ifdef CONFIG_VIDEO_ADV_DEBUG

just use DEBUG ?

no, v4l2 use CONFIG_VIDEO_ADV_DEBUG

ok, i was thinking this was something we added (since we have "ADVxxx" parts)

Quoted 6 lines
Quoted 4 lines
Quoted 2 lines

+       v4l_info(client, "chip found @ 0x%02x (%s)\n",
+                       client->addr << 1, client->adapter->name);

is that "<< 1" correct ?  i dont think so ...

every driver under media I see use this, so what's wrong?

meh, they're all wrong imo then :p. they're shifting the address to accommodate datasheets that incorrectly specify the i2c "address" with the read/write as bit 0. but it's fine for this driver to do that if it's the standard that the rest of the v4l code has adopted. -mike

#10 lore raw

PATCH 4/4 v4l2: add blackfin capture bridge driver

In reply to Scott Jiang

this is a v4l2 bridge driver for Blackfin video capture device, support ppi interface

---
 drivers/media/video/Makefile                |    2 +
 drivers/media/video/blackfin/Kconfig        |   10 +
 drivers/media/video/blackfin/Makefile       |    2 +
 drivers/media/video/blackfin/bfin_capture.c | 1099 +++++++++++++++++++++++++++
 drivers/media/video/blackfin/ppi.c          |  204 +++++
 5 files changed, 1317 insertions(+), 0 deletions(-)
 create mode 100644 drivers/media/video/blackfin/Kconfig
 create mode 100644 drivers/media/video/blackfin/Makefile
 create mode 100644 drivers/media/video/blackfin/bfin_capture.c
 create mode 100644 drivers/media/video/blackfin/ppi.c
drivers/media/video/Makefile +2 -0
index 127eba5..bc53aee 100644
@@ -177,6 +177,8 @@ obj-$(CONFIG_VIDEO_SAMSUNG_S5P_FIMC) 	+= s5p-fimc/
 obj-$(CONFIG_VIDEO_SAMSUNG_S5P_MFC)	+= s5p-mfc/
 obj-$(CONFIG_VIDEO_SAMSUNG_S5P_TV)	+= s5p-tv/
 
+obj-$(CONFIG_BLACKFIN)                  += blackfin/
+
 obj-$(CONFIG_ARCH_DAVINCI)		+= davinci/
 
 obj-$(CONFIG_VIDEO_SH_VOU)		+= sh_vou.o
drivers/media/video/blackfin/Kconfig new file +10 -0
new file mode 100644
index 0000000..2c6e921
@@ -0,0 +1,10 @@
+config VIDEO_BLACKFIN_CAPTURE
+	tristate "Blackfin Video Capture Driver"
+	depends on VIDEO_DEV && BLACKFIN
+	select VIDEOBUF2_DMA_CONTIG
+	help
+	  V4L2 bridge driver for Blackfin video capture device.
+	  Choose PPI or EPPI as its interface.
+
+	  To compile this driver as a module, choose M here: the
+	  module will be called bfin_video_capture.
drivers/media/video/blackfin/Makefile new file +2 -0
new file mode 100644
index 0000000..aa3a0a2
@@ -0,0 +1,2 @@
+bfin_video_capture-objs := bfin_capture.o ppi.o
+obj-$(CONFIG_VIDEO_BLACKFIN_CAPTURE) += bfin_video_capture.o
drivers/media/video/blackfin/bfin_capture.c new file +1099 -0

1,099 lines not on this page · raw message

drivers/media/video/blackfin/ppi.c new file +204 -0

204 lines not on this page · raw message

Signature · 1 line
1.7.0.4
#11 lore raw

Re: [PATCH 4/4] v4l2: add blackfin capture bridge driver

Again, no complete review, just a couple of remarks

Quoted 5 lines · Scott Jiang

this is a v4l2 bridge driver for Blackfin video capture device, support ppi interface

---

[snip]

Quoted 44 lines
drivers/media/video/blackfin/bfin_capture.c new file +38 -0
new file mode 100644
index 0000000..24f89f2
@@ -0,0 +1,1099 @@
+/*
+ * Analog Devices video capture driver
+ *
+ * Copyright (c) 2011 Analog Devices Inc.
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License version 2 as
+ * published by the Free Software Foundation.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
+ */
+
+
+#include <linux/kernel.h>
+#include <linux/init.h>
+#include <linux/module.h>
+#include <linux/io.h>
+#include <linux/delay.h>
+#include <linux/errno.h>
+#include <linux/fs.h>
+#include <linux/interrupt.h>
+#include <linux/completion.h>
+#include <linux/mm.h>
+#include <linux/moduleparam.h>
+#include <linux/time.h>
+#include <linux/version.h>
+#include <linux/device.h>
+#include <linux/platform_device.h>
+#include <linux/clk.h>
+#include <linux/sched.h>
+#include <linux/slab.h>

drivers/media/video/blackfin/bfin_capture.c line 48

Quoted 10 lines
drivers/media/video/blackfin/bfin_capture.c new file +10 -0
+
+#include <media/v4l2-common.h>
+#include <media/v4l2-ioctl.h>
+#include <media/v4l2-device.h>
+#include <media/videobuf2-dma-contig.h>
+#include <media/v4l2-chip-ident.h>
+
+#include <asm/dma.h>
+
+#include <media/blackfin/bfin_capture.h>

Alphabetic order of headers is preferred. Also holds for other your patches.

drivers/media/video/blackfin/bfin_capture.c line 57

Quoted 9 lines
drivers/media/video/blackfin/bfin_capture.c new file +9 -0
+
+#define CAPTURE_DRV_NAME        "bfin_capture"
+#define BCAP_MIN_NUM_BUF        2
+
+struct bcap_format {
+	u8 *desc;
+	u32 pixelformat;
+	enum v4l2_mbus_pixelcode mbus_code;
+	int bpp; /* bytes per pixel */

Don't you think you might have to process 12 bpp formats at some point, like YUV 4:2:0, or NV12? Maybe better calculate in bits from the beginning?

Quoted 34 lines
drivers/media/video/blackfin/bfin_capture.c new file +34 -0
+};
+
+struct bcap_buffer {
+	struct vb2_buffer vb;
+	struct list_head list;
+};
+
+struct bcap_device {
+	/* capture device instance */
+	struct v4l2_device v4l2_dev;
+	/* device node data */
+	struct video_device *video_dev;
+	/* sub device instance */
+	struct v4l2_subdev *sd;
+	/* caputre config */
+	struct bfin_capture_config *cfg;
+	/* ppi interface */
+	struct ppi_if *ppi;
+	/* current input */
+	unsigned int cur_input;
+	/* current selected standard */
+	v4l2_std_id std;
+	/* used to store pixel format */
+	struct v4l2_pix_format fmt;
+	/* bytes per pixel*/
+	int bpp;
+	/* pointing to current video buffer */
+	struct bcap_buffer *cur_frm;
+	/* pointing to next video buffer */
+	struct bcap_buffer *next_frm;
+	/* buffer queue used in videobuf2 */
+	struct vb2_queue buffer_queue;
+	/* allocator-specific contexts for each plane */
+	struct vb2_alloc_ctx *alloc_ctx;

drivers/media/video/blackfin/bfin_capture.c line 101

Quoted 10 lines
drivers/media/video/blackfin/bfin_capture.c new file +10 -0
+	/* queue of filled frames */
+	struct list_head dma_queue;
+	/* used in videobuf2 callback */
+	spinlock_t lock;
+	/* used to access capture device */
+	struct mutex mutex;
+	/* used to wait ppi to complete one transfer */
+	struct completion comp;
+	/* number of users performing IO */
+	u32 io_usrs;

Does it really have to be fixed 32 bits? Seems a plane simple int would do just fine.

drivers/media/video/blackfin/bfin_capture.c line 103

Quoted 2 lines
drivers/media/video/blackfin/bfin_capture.c new file +2 -0
+	/* number of open instances of the device */
+	u32 usrs;

ditto

drivers/media/video/blackfin/bfin_capture.c line 105

Quoted 2 lines
drivers/media/video/blackfin/bfin_capture.c new file +2 -0
+	/* indicate whether streaming has started */
+	u8 started;

bool?

drivers/media/video/blackfin/bfin_capture.c line 112

Quoted 7 lines
drivers/media/video/blackfin/bfin_capture.c new file +7 -0
+};
+
+struct bcap_fh {
+	struct v4l2_fh fh;
+	struct bcap_device *bcap_dev;
+	/* indicates whether this file handle is doing IO */
+	u8 io_allowed;

bool

[snip]

Quoted 17 lines
drivers/media/video/blackfin/bfin_capture.c new file +17 -0
+static irqreturn_t bcap_isr(int irq, void *dev_id)
+{
+	struct ppi_if *ppi = dev_id;
+	struct bcap_device *bcap_dev = ppi->priv;
+	struct timeval timevalue;
+	struct vb2_buffer *vb = &bcap_dev->cur_frm->vb;
+	dma_addr_t *addr;
+
+	spin_lock(&bcap_dev->lock);
+
+	if (bcap_dev->cur_frm != bcap_dev->next_frm) {
+		do_gettimeofday(&timevalue);
+		vb->v4l2_buf.timestamp = timevalue;
+		vb2_buffer_done(vb, VB2_BUF_STATE_DONE);
+		bcap_dev->cur_frm = bcap_dev->next_frm;
+	}
+

drivers/media/video/blackfin/bfin_capture.c line 470

Quoted 10 lines
drivers/media/video/blackfin/bfin_capture.c new file +10 -0
+	ppi->ops->stop(ppi);
+
+	if (!bcap_dev->started)
+		complete(&bcap_dev->comp);
+	else {
+		if (!list_empty(&bcap_dev->dma_queue)) {
+			bcap_dev->next_frm = list_entry(bcap_dev->dma_queue.next,
+						struct bcap_buffer, list);
+			list_del(&bcap_dev->next_frm->list);
+			addr = vb2_plane_cookie(&bcap_dev->next_frm->vb, 0);

I think, the direct use of vb2_plane_cookie() is discouraged. vb2_dma_contig_plane_dma_addr() should work for you.

Quoted 9 lines
drivers/media/video/blackfin/bfin_capture.c new file +9 -0
+			ppi->ops->update_addr(ppi, (unsigned long)(*addr));
+		}
+		ppi->ops->start(ppi);
+	}
+
+	spin_unlock(&bcap_dev->lock);
+
+	return IRQ_HANDLED;
+}

[snip]

Quoted 86 lines
drivers/media/video/blackfin/bfin_capture.c new file +86 -0
+static int bcap_try_format(struct bcap_device *bcap,
+				struct v4l2_pix_format *pixfmt,
+				enum v4l2_mbus_pixelcode *mbus_code,
+				int *bpp)
+{
+	const struct bcap_format *fmt;
+	struct v4l2_mbus_framefmt mbus_fmt;
+	int ret, i;
+
+	for (i = 0; i < BCAP_MAX_FMTS; i++) {
+		if ((pixfmt->pixelformat == bcap_formats[i].pixelformat)) {
+			fmt = &bcap_formats[i];
+			if (mbus_code)
+				*mbus_code = fmt->mbus_code;
+			if (bpp)
+				*bpp = fmt->bpp;
+			v4l2_fill_mbus_format(&mbus_fmt, pixfmt,
+						fmt->mbus_code);
+			ret = v4l2_subdev_call(bcap->sd, video,
+						try_mbus_fmt, &mbus_fmt);
+			if (ret < 0)
+				return ret;
+			v4l2_fill_pix_format(pixfmt, &mbus_fmt);
+			pixfmt->bytesperline = pixfmt->width * fmt->bpp;
+			pixfmt->sizeimage = pixfmt->bytesperline
+						* pixfmt->height;
+			return 0;
+		}
+	}
+	return -EINVAL;
+}
+
+static int bcap_enum_fmt_vid_cap(struct file *file, void  *priv,
+					struct v4l2_fmtdesc *fmt)
+{
+	struct bcap_device *bcap_dev = video_drvdata(file);
+	enum v4l2_mbus_pixelcode mbus_code;
+	u32 index = fmt->index;
+	int ret, i;
+
+	ret = v4l2_subdev_call(bcap_dev->sd, video,
+				enum_mbus_fmt, index, &mbus_code);
+	if (ret < 0)
+		return ret;
+
+	for (i = 0; i < BCAP_MAX_FMTS; i++) {
+		if (mbus_code == bcap_formats[i].mbus_code) {
+			fmt->type = V4L2_BUF_TYPE_VIDEO_CAPTURE;
+			strlcpy(fmt->description,
+					bcap_formats[index].desc,
+					 sizeof(fmt->description));
+			fmt->pixelformat = bcap_formats[index].pixelformat;
+			return 0;
+		}
+	}
+	v4l2_err(&bcap_dev->v4l2_dev,
+			"subdev fmt is not supported by bcap\n");
+	return -EINVAL;
+}
+
+static int bcap_try_fmt_vid_cap(struct file *file, void *priv,
+					struct v4l2_format *fmt)
+{
+	struct bcap_device *bcap_dev = video_drvdata(file);
+	struct v4l2_pix_format *pixfmt = &fmt->fmt.pix;
+
+	if (fmt->type != V4L2_BUF_TYPE_VIDEO_CAPTURE)
+		return -EINVAL;
+
+	return bcap_try_format(bcap_dev, pixfmt, NULL, NULL);
+}
+
+static int bcap_g_fmt_vid_cap(struct file *file, void *priv,
+				struct v4l2_format *fmt)
+{
+	struct bcap_device *bcap_dev = video_drvdata(file);
+	struct v4l2_mbus_framefmt mbus_fmt;
+	const struct bcap_format *bcap_fmt;
+	struct v4l2_pix_format *pixfmt = &fmt->fmt.pix;
+	int ret, i;
+
+	if (fmt->type != V4L2_BUF_TYPE_VIDEO_CAPTURE)
+		return -EINVAL;
+
+	ret = v4l2_subdev_call(bcap_dev->sd, video,
+				g_mbus_fmt, &mbus_fmt);

drivers/media/video/blackfin/bfin_capture.c line 755

Quoted 10 lines
drivers/media/video/blackfin/bfin_capture.c new file +10 -0
+	if (ret < 0)
+		return ret;
+
+	for (i = 0; i < BCAP_MAX_FMTS; i++) {
+		if (mbus_fmt.code == bcap_formats[i].mbus_code) {
+			bcap_fmt = &bcap_formats[i];
+			v4l2_fill_pix_format(pixfmt, &mbus_fmt);
+			pixfmt->bytesperline = pixfmt->width * bcap_fmt->bpp;
+			pixfmt->sizeimage = pixfmt->bytesperline
+						* pixfmt->height;

It seems to me, you're forgetting to fill in ->pixelformat?

Thanks
Guennadi
---
Guennadi Liakhovetski, Ph.D.
Freelance Open-Source Software Developer
http://www.open-technology.de/

#12 lore raw

Re: [PATCH 4/4] v4l2: add blackfin capture bridge driver

Quoted 10 lines

drivers/media/video/blackfin/bfin_capture.c line 57

Quoted 6 lines
drivers/media/video/blackfin/bfin_capture.c new file +6 -0
+
+struct bcap_format {
+     u8 *desc;
+     u32 pixelformat;
+     enum v4l2_mbus_pixelcode mbus_code;
+     int bpp; /* bytes per pixel */

Don't you think you might have to process 12 bpp formats at some point, like YUV 4:2:0, or NV12? Maybe better calculate in bits from the beginning?

sounds good, changed in v2

Quoted 4 lines

Does it really have to be fixed 32 bits? Seems a plane simple int would do just fine.

users can't be negative, so I used u32

Quoted 8 lines
Quoted 5 lines

+struct bcap_fh {
+     struct v4l2_fh fh;
+     struct bcap_device *bcap_dev;
+     /* indicates whether this file handle is doing IO */
+     u8 io_allowed;

bool

does kernel prefer bool now?

Quoted 9 lines
Quoted 8 lines

+     if (!bcap_dev->started)
+             complete(&bcap_dev->comp);
+     else {
+             if (!list_empty(&bcap_dev->dma_queue)) {
+                     bcap_dev->next_frm = list_entry(bcap_dev->dma_queue.next,
+                                             struct bcap_buffer, list);
+                     list_del(&bcap_dev->next_frm->list);
+                     addr = vb2_plane_cookie(&bcap_dev->next_frm->vb, 0);

Quoted 3 lines

I think, the direct use of vb2_plane_cookie() is discouraged. vb2_dma_contig_plane_dma_addr() should work for you.

I guess you mean vb2_dma_contig_plane_paddr

Quoted 11 lines
Quoted 8 lines

+
+     for (i = 0; i < BCAP_MAX_FMTS; i++) {
+             if (mbus_fmt.code == bcap_formats[i].mbus_code) {
+                     bcap_fmt = &bcap_formats[i];
+                     v4l2_fill_pix_format(pixfmt, &mbus_fmt);
+                     pixfmt->bytesperline = pixfmt->width * bcap_fmt->bpp;
+                     pixfmt->sizeimage = pixfmt->bytesperline
+                                             * pixfmt->height;

It seems to me, you're forgetting to fill in ->pixelformat?

yes, add in v2

#13 lore raw

Re: [PATCH 4/4] v4l2: add blackfin capture bridge driver

Quoted 10 lines · Scott Jiang
Quoted 10 lines

drivers/media/video/blackfin/bfin_capture.c line 57

Quoted 6 lines
drivers/media/video/blackfin/bfin_capture.c new file +6 -0
+
+struct bcap_format {
+     u8 *desc;
+     u32 pixelformat;
+     enum v4l2_mbus_pixelcode mbus_code;
+     int bpp; /* bytes per pixel */

Don't you think you might have to process 12 bpp formats at some point, like YUV 4:2:0, or NV12? Maybe better calculate in bits from the beginning?

Quoted 7 lines

sounds good, changed in v2

Quoted 4 lines

Does it really have to be fixed 32 bits? Seems a plane simple int would do just fine.

users can't be negative, so I used u32

no, then use unsigned int.

Quoted 9 lines
Quoted 8 lines
Quoted 5 lines

+struct bcap_fh {
+     struct v4l2_fh fh;
+     struct bcap_device *bcap_dev;
+     /* indicates whether this file handle is doing IO */
+     u8 io_allowed;

bool

does kernel prefer bool now?

yes

Quoted 9 lines
Quoted 9 lines
Quoted 8 lines

+     if (!bcap_dev->started)
+             complete(&bcap_dev->comp);
+     else {
+             if (!list_empty(&bcap_dev->dma_queue)) {
+                     bcap_dev->next_frm = list_entry(bcap_dev->dma_queue.next,
+                                             struct bcap_buffer, list);
+                     list_del(&bcap_dev->next_frm->list);
+                     addr = vb2_plane_cookie(&bcap_dev->next_frm->vb, 0);

Quoted 4 lines
Quoted 3 lines

I think, the direct use of vb2_plane_cookie() is discouraged. vb2_dma_contig_plane_dma_addr() should work for you.

I guess you mean vb2_dma_contig_plane_paddr

no, in the current kernel it's vb2_dma_contig_plane_dma_addr(). See

http://git.linuxtv.org/media_tree.git/shortlog/refs/heads/staging/for_v3.2

Quoted 10 lines
Quoted 10 lines
Quoted 9 lines

+
+     for (i = 0; i < BCAP_MAX_FMTS; i++) {
+             if (mbus_fmt.code == bcap_formats[i].mbus_code) {
+                     bcap_fmt = &bcap_formats[i];
+                     v4l2_fill_pix_format(pixfmt, &mbus_fmt);
+                     pixfmt->bytesperline = pixfmt->width * bcap_fmt->bpp;
+                     pixfmt->sizeimage = pixfmt->bytesperline
+                                             * pixfmt->height;

Quoted 4 lines
Quoted 2 lines

It seems to me, you're forgetting to fill in ->pixelformat?

yes, add in v2

Thanks
Guennadi
---
Guennadi Liakhovetski, Ph.D.
Freelance Open-Source Software Developer
http://www.open-technology.de/

#14 lore raw

Re: [PATCH 4/4] v4l2: add blackfin capture bridge driver

Quoted 9 lines
Quoted 4 lines
Quoted 3 lines

I think, the direct use of vb2_plane_cookie() is discouraged. vb2_dma_contig_plane_dma_addr() should work for you.

I guess you mean vb2_dma_contig_plane_paddr

no, in the current kernel it's vb2_dma_contig_plane_dma_addr(). See

http://git.linuxtv.org/media_tree.git/shortlog/refs/heads/staging/for_v3.2

my git repo is http://git.kernel.org/pub/scm/linux/kernel/git/mchehab/linux-2.6.git
branch is v4l_for_linus
Is this the official git repo or in linuxtv.org?
My patch is against 3.1 not 3.2.

#15 lore raw

Re: [PATCH 4/4] v4l2: add blackfin capture bridge driver

In reply to Guennadi Liakhovetski

2011/9/13 Guennadi Liakhovetski <[email protected]>:

Quoted 12 lines · Scott Jiang
Quoted 11 lines
Quoted 11 lines

drivers/media/video/blackfin/bfin_capture.c line 57

Quoted 7 lines
drivers/media/video/blackfin/bfin_capture.c new file +6 -0
+
+struct bcap_format {
+     u8 *desc;
+     u32 pixelformat;
+     enum v4l2_mbus_pixelcode mbus_code;
+     int bpp; /* bytes per pixel */

Don't you think you might have to process 12 bpp formats at some point, like YUV 4:2:0, or NV12? Maybe better calculate in bits from the beginning?

ppi only stores raw format into memory. I wonder if there is sensor transmit data in planar format?
If planar format only exists in memory, I think I don't need to modify this.

#16 lore raw

Re: [PATCH 4/4] v4l2: add blackfin capture bridge driver

Quoted 13 lines · Scott Jiang

2011/9/13 Guennadi Liakhovetski <[email protected]>:

Quoted 12 lines · Scott Jiang
Quoted 11 lines
Quoted 11 lines

drivers/media/video/blackfin/bfin_capture.c line 57

Quoted 7 lines
drivers/media/video/blackfin/bfin_capture.c new file +6 -0
+
+struct bcap_format {
+     u8 *desc;
+     u32 pixelformat;
+     enum v4l2_mbus_pixelcode mbus_code;
+     int bpp; /* bytes per pixel */

Don't you think you might have to process 12 bpp formats at some point, like YUV 4:2:0, or NV12? Maybe better calculate in bits from the beginning?

Quoted 3 lines

ppi only stores raw format into memory. I wonder if there is sensor transmit data in planar format?
If planar format only exists in memory, I think I don't need to modify this.

There are also packed 12-bit formats, like yuv 4:1:1 (V4L2_PIX_FMT_Y41P).

Thanks
Guennadi
---
Guennadi Liakhovetski, Ph.D.
Freelance Open-Source Software Developer
http://www.open-technology.de/

#17 lore raw

Re: [PATCH 4/4] v4l2: add blackfin capture bridge driver

In reply to Guennadi Liakhovetski
Quoted 14 lines

drivers/media/video/blackfin/bfin_capture.c line 57

Quoted 10 lines
drivers/media/video/blackfin/bfin_capture.c new file +9 -0
+
+#define CAPTURE_DRV_NAME        "bfin_capture"
+#define BCAP_MIN_NUM_BUF        2
+
+struct bcap_format {
+     u8 *desc;
+     u32 pixelformat;
+     enum v4l2_mbus_pixelcode mbus_code;
+     int bpp; /* bytes per pixel */

Don't you think you might have to process 12 bpp formats at some point, like YUV 4:2:0, or NV12? Maybe better calculate in bits from the beginning?

I have a question here. How to calculate bytesperline for planar format? According to v4l2 specification width, height and bytesperline apply to largest plane.
Does it mean bytesperline equal to Y plane distance between two line? And so you can't use bytesperline x height to calculate sizeimage?

#18 lore raw

Re: [PATCH 4/4] v4l2: add blackfin capture bridge driver

Quoted 14 lines · Scott Jiang
Quoted 14 lines

drivers/media/video/blackfin/bfin_capture.c line 57

Quoted 10 lines
drivers/media/video/blackfin/bfin_capture.c new file +9 -0
+
+#define CAPTURE_DRV_NAME        "bfin_capture"
+#define BCAP_MIN_NUM_BUF        2
+
+struct bcap_format {
+     u8 *desc;
+     u32 pixelformat;
+     enum v4l2_mbus_pixelcode mbus_code;
+     int bpp; /* bytes per pixel */

Don't you think you might have to process 12 bpp formats at some point, like YUV 4:2:0, or NV12? Maybe better calculate in bits from the beginning?

Quoted 4 lines

I have a question here. How to calculate bytesperline for planar format? According to v4l2 specification width, height and bytesperline apply to largest plane.
Does it mean bytesperline equal to Y plane distance between two line?

For planar formats - I think so.

Quoted 1 line

And so you can't use bytesperline x height to calculate sizeimage?

No, you can't. Please see this thread:
http://www.mail-archive.com/[email protected]/msg28957.html

Regards,

Signature · 2 lines
Sylwester Nawrocki
Samsung Poland R&D Center
#19 lore raw

Re: [PATCH 4/4] v4l2: add blackfin capture bridge driver

In reply to Scott Jiang

Hi Scott,

Quoted 16 lines · Scott Jiang

this is a v4l2 bridge driver for Blackfin video capture device, support ppi interface

---
  drivers/media/video/Makefile                |    2 +
  drivers/media/video/blackfin/Kconfig        |   10 +
  drivers/media/video/blackfin/Makefile       |    2 +
  drivers/media/video/blackfin/bfin_capture.c | 1099 +++++++++++++++++++++++++++
  drivers/media/video/blackfin/ppi.c          |  204 +++++
  5 files changed, 1317 insertions(+), 0 deletions(-)

create mode 100644 drivers/media/video/blackfin/Kconfig create mode 100644 drivers/media/video/blackfin/Makefile create mode 100644 drivers/media/video/blackfin/bfin_capture.c create mode 100644 drivers/media/video/blackfin/ppi.c

...

Quoted 68 lines
drivers/media/video/blackfin/bfin_capture.c new file +62 -0
new file mode 100644
index 0000000..24f89f2
@@ -0,0 +1,1099 @@
+/*
+ * Analog Devices video capture driver
+ *
+ * Copyright (c) 2011 Analog Devices Inc.
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License version 2 as
+ * published by the Free Software Foundation.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
+ */
+
+
+#include<linux/kernel.h>
+#include<linux/init.h>
+#include<linux/module.h>
+#include<linux/io.h>
+#include<linux/delay.h>
+#include<linux/errno.h>
+#include<linux/fs.h>
+#include<linux/interrupt.h>
+#include<linux/completion.h>
+#include<linux/mm.h>
+#include<linux/moduleparam.h>
+#include<linux/time.h>
+#include<linux/version.h>
+#include<linux/device.h>
+#include<linux/platform_device.h>
+#include<linux/clk.h>
+#include<linux/sched.h>
+#include<linux/slab.h>
+
+#include<media/v4l2-common.h>
+#include<media/v4l2-ioctl.h>
+#include<media/v4l2-device.h>
+#include<media/videobuf2-dma-contig.h>
+#include<media/v4l2-chip-ident.h>
+
+#include<asm/dma.h>
+
+#include<media/blackfin/bfin_capture.h>
+
+#define CAPTURE_DRV_NAME        "bfin_capture"
+#define BCAP_MIN_NUM_BUF        2
+
+struct bcap_format {
+	u8 *desc;
+	u32 pixelformat;
+	enum v4l2_mbus_pixelcode mbus_code;
+	int bpp; /* bytes per pixel */
+};
+
+struct bcap_buffer {
+	struct vb2_buffer vb;
+	struct list_head list;

drivers/media/video/blackfin/bfin_capture.c line 72

Quoted 10 lines
drivers/media/video/blackfin/bfin_capture.c new file +10 -0
+};
+
+struct bcap_device {
+	/* capture device instance */
+	struct v4l2_device v4l2_dev;
+	/* device node data */
+	struct video_device *video_dev;
+	/* sub device instance */
+	struct v4l2_subdev *sd;
+	/* caputre config */

typo: caputre -> capture

Quoted 56 lines
drivers/media/video/blackfin/bfin_capture.c new file +56 -0
+	struct bfin_capture_config *cfg;
+	/* ppi interface */
+	struct ppi_if *ppi;
+	/* current input */
+	unsigned int cur_input;
+	/* current selected standard */
+	v4l2_std_id std;
+	/* used to store pixel format */
+	struct v4l2_pix_format fmt;
+	/* bytes per pixel*/
+	int bpp;
+	/* pointing to current video buffer */
+	struct bcap_buffer *cur_frm;
+	/* pointing to next video buffer */
+	struct bcap_buffer *next_frm;
+	/* buffer queue used in videobuf2 */
+	struct vb2_queue buffer_queue;
+	/* allocator-specific contexts for each plane */
+	struct vb2_alloc_ctx *alloc_ctx;
+	/* queue of filled frames */
+	struct list_head dma_queue;
+	/* used in videobuf2 callback */
+	spinlock_t lock;
+	/* used to access capture device */
+	struct mutex mutex;
+	/* used to wait ppi to complete one transfer */
+	struct completion comp;
+	/* number of users performing IO */
+	u32 io_usrs;
+	/* number of open instances of the device */
+	u32 usrs;
+	/* indicate whether streaming has started */
+	u8 started;
+};
+
+struct bcap_fh {
+	struct v4l2_fh fh;
+	struct bcap_device *bcap_dev;
+	/* indicates whether this file handle is doing IO */
+	u8 io_allowed;
+};
+
+static const struct bcap_format bcap_formats[] = {
+	{
+		.desc        = "YCbCr 4:2:2 Interleaved UYVY",
+		.pixelformat = V4L2_PIX_FMT_UYVY,
+		.mbus_code   = V4L2_MBUS_FMT_UYVY8_2X8,
+		.bpp         = 2,
+	},
+	{
+		.desc        = "YCbCr 4:2:2 Interleaved YUYV",
+		.pixelformat = V4L2_PIX_FMT_YUYV,
+		.mbus_code   = V4L2_MBUS_FMT_YUYV8_2X8,
+		.bpp         = 2,
+	},
+	{

drivers/media/video/blackfin/bfin_capture.c line 138

Quoted 10 lines
drivers/media/video/blackfin/bfin_capture.c new file +10 -0
+		.desc        = "RGB 565",
+		.pixelformat = V4L2_PIX_FMT_RGB565,
+		.mbus_code   = V4L2_MBUS_FMT_RGB565_2X8_LE,
+		.bpp         = 2,
+	},
+	{
+		.desc        = "RGB 444",
+		.pixelformat = V4L2_PIX_FMT_RGB444,
+		.mbus_code   = V4L2_MBUS_FMT_RGB444_2X8_PADHI_LE,
+		.bpp         = 2,

Are these all formats supported by the device ? IIRC it has been already pointed out, wouldn't "bits per pixel" be more useful ? If there are other formats added in future with e.g. 12 bits/pixel it won't be easy to compute the buffers size.

Quoted 210 lines
drivers/media/video/blackfin/bfin_capture.c new file +210 -0
+	},
+
+};
+#define BCAP_MAX_FMTS ARRAY_SIZE(bcap_formats)
+
+static irqreturn_t bcap_isr(int irq, void *dev_id);
+
+static struct bcap_buffer *to_bcap_vb(struct vb2_buffer *vb)
+{
+	return container_of(vb, struct bcap_buffer, vb);
+}
+
+static int bcap_open(struct file *file)
+{
+	struct bcap_device *bcap_dev = video_drvdata(file);
+	struct video_device *vfd = bcap_dev->video_dev;
+	struct bcap_fh *bcap_fh;
+	int ret;
+
+	if (!bcap_dev->sd) {
+		v4l2_err(&bcap_dev->v4l2_dev, "No sub device registered\n");
+		return -ENODEV;
+	}
+
+	bcap_fh = kzalloc(sizeof(*bcap_fh), GFP_KERNEL);
+	if (!bcap_fh) {
+		v4l2_err(&bcap_dev->v4l2_dev,
+			 "unable to allocate memory for file handle object\n");
+		return -ENOMEM;
+	}
+
+	ret = v4l2_fh_init(&bcap_fh->fh, vfd);
+	if (ret) {
+		kfree(bcap_fh);
+		return ret;
+	}
+
+	/* store pointer to v4l2_fh in private_data member of file */
+	file->private_data =&bcap_fh->fh;
+	v4l2_fh_add(&bcap_fh->fh);
+	bcap_fh->bcap_dev = bcap_dev;
+	bcap_dev->usrs++;
+	bcap_fh->io_allowed = 0;
+	return 0;
+}
+
+static int bcap_release(struct file *file)
+{
+	struct bcap_device *bcap_dev = video_drvdata(file);
+	struct v4l2_fh *fh = file->private_data;
+	struct bcap_fh *bcap_fh = container_of(fh, struct bcap_fh, fh);
+
+	/* if this instance is doing IO */
+	if (bcap_fh->io_allowed) {
+		vb2_queue_release(&bcap_dev->buffer_queue);
+		bcap_dev->io_usrs = 0;
+	}
+
+	bcap_dev->usrs--;
+	file->private_data = NULL;
+	v4l2_fh_del(&bcap_fh->fh);
+	v4l2_fh_exit(&bcap_fh->fh);
+	kfree(bcap_fh);
+	return 0;
+}
+
+static int bcap_mmap(struct file *file, struct vm_area_struct *vma)
+{
+	struct bcap_device *bcap_dev = video_drvdata(file);
+
+	return vb2_mmap(&bcap_dev->buffer_queue, vma);
+}
+
+#ifndef CONFIG_MMU
+static unsigned long bcap_get_unmapped_area(struct file *file,
+					    unsigned long addr,
+					    unsigned long len,
+					    unsigned long pgoff,
+					    unsigned long flags)
+{
+	struct bcap_device *bcap_dev = video_drvdata(file);
+
+	return vb2_get_unmapped_area(&bcap_dev->buffer_queue,
+				     addr,
+				     len,
+				     pgoff,
+				     flags);
+}
+#endif
+
+static unsigned int bcap_poll(struct file *file, poll_table *wait)
+{
+	struct bcap_device *bcap_dev = video_drvdata(file);
+
+	if (bcap_dev->started)
+		return vb2_poll(&bcap_dev->buffer_queue, file, wait);
+	return 0;
+}
+
+static int bcap_queue_setup(struct vb2_queue *vq, unsigned int *nbuffers,
+				unsigned int *nplanes, unsigned long sizes[],
+				void *alloc_ctxs[])
+{
+	struct bcap_device *bcap_dev = vb2_get_drv_priv(vq);
+
+	if (*nbuffers<  BCAP_MIN_NUM_BUF)
+		*nbuffers = BCAP_MIN_NUM_BUF;
+
+	*nplanes = 1;
+	sizes[0] = bcap_dev->fmt.sizeimage;
+	alloc_ctxs[0] = bcap_dev->alloc_ctx;
+
+	return 0;
+}
+
+static int bcap_buffer_init(struct vb2_buffer *vb)
+{
+	struct bcap_buffer *buf = to_bcap_vb(vb);
+
+	INIT_LIST_HEAD(&buf->list);
+	return 0;
+}
+
+static int bcap_buffer_prepare(struct vb2_buffer *vb)
+{
+	struct bcap_device *bcap_dev = vb2_get_drv_priv(vb->vb2_queue);
+	struct bcap_buffer *buf = to_bcap_vb(vb);
+	unsigned long size;
+
+	size = bcap_dev->fmt.sizeimage;
+	if (vb2_plane_size(vb, 0)<  size) {
+		v4l2_err(&bcap_dev->v4l2_dev, "buffer too small (%lu<  %lu)\n",
+				vb2_plane_size(vb, 0), size);
+		return -EINVAL;
+	}
+	vb2_set_plane_payload(&buf->vb, 0, size);
+
+	return 0;
+}
+
+static void bcap_buffer_queue(struct vb2_buffer *vb)
+{
+	struct bcap_device *bcap_dev = vb2_get_drv_priv(vb->vb2_queue);
+	struct bcap_buffer *buf = to_bcap_vb(vb);
+	unsigned long flags = 0;
+
+	spin_lock_irqsave(&bcap_dev->lock, flags);
+	list_add_tail(&buf->list,&bcap_dev->dma_queue);
+	spin_unlock_irqrestore(&bcap_dev->lock, flags);
+}
+
+static void bcap_buffer_cleanup(struct vb2_buffer *vb)
+{
+	struct bcap_device *bcap_dev = vb2_get_drv_priv(vb->vb2_queue);
+	struct bcap_buffer *buf = to_bcap_vb(vb);
+	unsigned long flags = 0;
+
+	spin_lock_irqsave(&bcap_dev->lock, flags);
+	list_del_init(&buf->list);
+	spin_unlock_irqrestore(&bcap_dev->lock, flags);
+}
+
+static void bcap_lock(struct vb2_queue *vq)
+{
+	struct bcap_device *bcap_dev = vb2_get_drv_priv(vq);
+	mutex_lock(&bcap_dev->mutex);
+}
+
+static void bcap_unlock(struct vb2_queue *vq)
+{
+	struct bcap_device *bcap_dev = vb2_get_drv_priv(vq);
+	mutex_unlock(&bcap_dev->mutex);
+}
+
+static int bcap_start_streaming(struct vb2_queue *vq)
+{
+	struct bcap_device *bcap_dev = vb2_get_drv_priv(vq);
+	struct ppi_if *ppi = bcap_dev->ppi;
+	struct ppi_params params;
+	int ret;
+
+	/* enable streamon on the sub device */
+	ret = v4l2_subdev_call(bcap_dev->sd, video, s_stream, 1);
+	if (ret&&  (ret != -ENOIOCTLCMD)) {
+		v4l2_err(&bcap_dev->v4l2_dev, "stream on failed in subdev\n");
+		return ret;
+	}
+
+	/* attach ppi DMA irq handler */
+	ret = ppi->ops->attach_irq(ppi, bcap_isr);
+	if (ret<  0) {
+		v4l2_err(&bcap_dev->v4l2_dev,
+				"Error in attaching interrupt handler\n");
+		return -EFAULT;
+	}
+
+	/* set ppi params */
+	params.width = bcap_dev->fmt.width;
+	params.height = bcap_dev->fmt.height;
+	params.bpp = bcap_dev->bpp;
+	params.ppi_control = bcap_dev->cfg->ppi_control;
+	ret = ppi->ops->set_params(ppi,&params);
+	if (ret<  0) {
+		v4l2_err(&bcap_dev->v4l2_dev,
+				"Error in setting ppi params\n");
+		ppi->ops->detach_irq(ppi);
+		return -EINVAL;
+	}
+
+	INIT_COMPLETION(bcap_dev->comp);

drivers/media/video/blackfin/bfin_capture.c line 358

Quoted 10 lines
drivers/media/video/blackfin/bfin_capture.c new file +10 -0
+	return 0;
+}
+
+static int bcap_stop_streaming(struct vb2_queue *vq)
+{
+	struct bcap_device *bcap_dev = vb2_get_drv_priv(vq);
+	struct ppi_if *ppi = bcap_dev->ppi;
+	int ret;
+
+	if (bcap_dev->started) {

How about just doing:

	if (!bcap_dev->started)
		return 0;

and avoid indentation ?

Quoted 57 lines
drivers/media/video/blackfin/bfin_capture.c new file +57 -0
+		bcap_dev->started = 0;
+		wait_for_completion(&bcap_dev->comp);
+		ppi->ops->stop(ppi);
+		ppi->ops->detach_irq(ppi);
+		ret = v4l2_subdev_call(bcap_dev->sd, video, s_stream, 0);
+		if (ret&&  (ret != -ENOIOCTLCMD))
+			v4l2_err(&bcap_dev->v4l2_dev,
+					"stream off failed in subdev\n");
+
+		/* release all active buffers */
+		while (!list_empty(&bcap_dev->dma_queue)) {
+			bcap_dev->next_frm = list_entry(bcap_dev->dma_queue.next,
+						struct bcap_buffer, list);
+			list_del(&bcap_dev->next_frm->list);
+			vb2_buffer_done(&bcap_dev->next_frm->vb, VB2_BUF_STATE_ERROR);
+		}
+	}
+	return 0;
+}
+
+static struct vb2_ops bcap_video_qops = {
+	.queue_setup            = bcap_queue_setup,
+	.buf_init               = bcap_buffer_init,
+	.buf_prepare            = bcap_buffer_prepare,
+	.buf_cleanup            = bcap_buffer_cleanup,
+	.buf_queue              = bcap_buffer_queue,
+	.wait_prepare           = bcap_unlock,
+	.wait_finish            = bcap_lock,
+	.start_streaming        = bcap_start_streaming,
+	.stop_streaming         = bcap_stop_streaming,
+};
+
+static int bcap_reqbufs(struct file *file, void *priv,
+			struct v4l2_requestbuffers *req_buf)
+{
+	struct bcap_device *bcap_dev = video_drvdata(file);
+	struct v4l2_fh *fh = file->private_data;
+	struct bcap_fh *bcap_fh = container_of(fh, struct bcap_fh, fh);
+
+	if (bcap_dev->io_usrs != 0) {
+		v4l2_err(&bcap_dev->v4l2_dev, "Only one IO user allowed\n");
+		return -EBUSY;
+	}
+
+	bcap_fh->io_allowed = 1;
+	bcap_dev->io_usrs = 1;
+
+	return vb2_reqbufs(&bcap_dev->buffer_queue, req_buf);
+}
+
+static int bcap_querybuf(struct file *file, void *priv,
+				struct v4l2_buffer *buf)
+{
+	struct bcap_device *bcap_dev = video_drvdata(file);
+
+	return vb2_querybuf(&bcap_dev->buffer_queue, buf);
+}

drivers/media/video/blackfin/bfin_capture.c line 425

Quoted 10 lines
drivers/media/video/blackfin/bfin_capture.c new file +10 -0
+
+static int bcap_qbuf(struct file *file, void *priv,
+			struct v4l2_buffer *buf)
+{
+	struct bcap_device *bcap_dev = video_drvdata(file);
+	struct v4l2_fh *fh = file->private_data;
+	struct bcap_fh *bcap_fh = container_of(fh, struct bcap_fh, fh);
+
+	if (!bcap_fh->io_allowed)
+		return -EACCES;

I suppose -EBUSY would be more appropriate here.

drivers/media/video/blackfin/bfin_capture.c line 438

Quoted 13 lines
drivers/media/video/blackfin/bfin_capture.c new file +13 -0
+
+	return vb2_qbuf(&bcap_dev->buffer_queue, buf);
+}
+
+static int bcap_dqbuf(struct file *file, void *priv,
+			struct v4l2_buffer *buf)
+{
+	struct bcap_device *bcap_dev = video_drvdata(file);
+	struct v4l2_fh *fh = file->private_data;
+	struct bcap_fh *bcap_fh = container_of(fh, struct bcap_fh, fh);
+
+	if (!bcap_fh->io_allowed)
+		return -EACCES;

Ditto.

Quoted 16 lines
drivers/media/video/blackfin/bfin_capture.c new file +16 -0
+
+	return vb2_dqbuf(&bcap_dev->buffer_queue,
+				buf, file->f_flags&  O_NONBLOCK);
+}
+
+static irqreturn_t bcap_isr(int irq, void *dev_id)
+{
+	struct ppi_if *ppi = dev_id;
+	struct bcap_device *bcap_dev = ppi->priv;
+	struct timeval timevalue;
+	struct vb2_buffer *vb =&bcap_dev->cur_frm->vb;
+	dma_addr_t *addr;
+
+	spin_lock(&bcap_dev->lock);
+
+	if (bcap_dev->cur_frm != bcap_dev->next_frm) {

drivers/media/video/blackfin/bfin_capture.c line 464

Quoted 10 lines
drivers/media/video/blackfin/bfin_capture.c new file +10 -0
+		do_gettimeofday(&timevalue);
+		vb->v4l2_buf.timestamp = timevalue;
+		vb2_buffer_done(vb, VB2_BUF_STATE_DONE);
+		bcap_dev->cur_frm = bcap_dev->next_frm;
+	}
+
+	ppi->ops->stop(ppi);
+
+	if (!bcap_dev->started)
+		complete(&bcap_dev->comp);

Need braces around if/else as well.

Quoted 30 lines
drivers/media/video/blackfin/bfin_capture.c new file +30 -0
+	else {
+		if (!list_empty(&bcap_dev->dma_queue)) {
+			bcap_dev->next_frm = list_entry(bcap_dev->dma_queue.next,
+						struct bcap_buffer, list);
+			list_del(&bcap_dev->next_frm->list);
+			addr = vb2_plane_cookie(&bcap_dev->next_frm->vb, 0);
+			ppi->ops->update_addr(ppi, (unsigned long)(*addr));
+		}
+		ppi->ops->start(ppi);
+	}
+
+	spin_unlock(&bcap_dev->lock);
+
+	return IRQ_HANDLED;
+}
+
+static int bcap_streamon(struct file *file, void *priv,
+				enum v4l2_buf_type buf_type)
+{
+	struct bcap_device *bcap_dev = video_drvdata(file);
+	struct bcap_fh *fh = file->private_data;
+	struct ppi_if *ppi = bcap_dev->ppi;
+	dma_addr_t *addr;
+	int ret;
+
+	if (!fh->io_allowed)
+		return -EACCES;
+
+	if (bcap_dev->started)
+		return -EBUSY;

drivers/media/video/blackfin/bfin_capture.c line 504

Quoted 10 lines
drivers/media/video/blackfin/bfin_capture.c new file +10 -0
+
+	/* call streamon to start streaming in videobuf */
+	ret = vb2_streamon(&bcap_dev->buffer_queue, buf_type);
+	if (ret)
+		return ret;
+
+	/* if dma queue is empty, return error */
+	if (list_empty(&bcap_dev->dma_queue)) {
+		v4l2_err(&bcap_dev->v4l2_dev, "dma queue is empty\n");
+		ret = -EIO;

According to the specification this should be -EINVAL. But I might be wrong, please check: http://linuxtv.org/downloads/v4l-dvb-apis/vidioc-streamon.html

Have you rebased this driver onto latest staging/for_v3.2 branch ? There have been yet another;) change in videobuf2.

Quoted 1 line

From now on there is a number of queued buffers passed by vb2 in start_streaming.

It seems more relevant to move this logic to the start_streaming callback.

And if you ever need read/write methods this will work out of the box this way.

Also calling vb2_streamoff from vidioc_streamon might be not necessarily the right way to go.

drivers/media/video/blackfin/bfin_capture.c line 514

Quoted 10 lines
drivers/media/video/blackfin/bfin_capture.c new file +10 -0
+		goto err;
+	}
+
+	/* get the next frame from the dma queue */
+	bcap_dev->next_frm = list_entry(bcap_dev->dma_queue.next,
+					struct bcap_buffer, list);
+	bcap_dev->cur_frm = bcap_dev->next_frm;
+	/* remove buffer from the dma queue */
+	list_del(&bcap_dev->cur_frm->list);
+	addr = vb2_plane_cookie(&bcap_dev->cur_frm->vb, 0);

As pointed out already, if you need to retrieve DMA adders the proper API is vb2_dma_contig_plane_dma_addr().

Quoted 40 lines
drivers/media/video/blackfin/bfin_capture.c new file +40 -0
+	/* update DMA address */
+	ppi->ops->update_addr(ppi, (unsigned long)(*addr));
+	/* enable ppi */
+	ppi->ops->start(ppi);
+	bcap_dev->started = 1;
+
+	return 0;
+err:
+	vb2_streamoff(&bcap_dev->buffer_queue, buf_type);
+	return ret;
+}
+
+static int bcap_streamoff(struct file *file, void *priv,
+				enum v4l2_buf_type buf_type)
+{
+	struct bcap_device *bcap_dev = video_drvdata(file);
+	struct bcap_fh *fh = file->private_data;
+
+	if (!fh->io_allowed)
+		return -EACCES;
+
+	if (!bcap_dev->started)
+		return -EINVAL;
+
+	return vb2_streamoff(&bcap_dev->buffer_queue, buf_type);
+}
+
+static int bcap_queryctrl(struct file *file, void *priv,
+				struct v4l2_queryctrl *qctrl)
+{
+	struct bcap_device *bcap_dev = video_drvdata(file);
+
+	return v4l2_subdev_call(bcap_dev->sd, core, queryctrl, qctrl);
+}
+
+static int bcap_g_ctrl(struct file *file, void *priv,
+			struct v4l2_control *ctrl)
+{
+	struct bcap_device *bcap_dev = video_drvdata(file);
+

drivers/media/video/blackfin/bfin_capture.c line 564

Quoted 10 lines
drivers/media/video/blackfin/bfin_capture.c new file +10 -0
+	return v4l2_subdev_call(bcap_dev->sd, core, g_ctrl, ctrl);
+}
+
+static int bcap_s_ctrl(struct file *file, void *priv,
+			struct v4l2_control *ctrl)
+{
+	struct bcap_device *bcap_dev = video_drvdata(file);
+
+	return v4l2_subdev_call(bcap_dev->sd, core, s_ctrl, ctrl);
+}

I think you don't need all these control operations in the host driver. If the sensor and host driver uses new control framework the sensor's controls get inherited by the host driver when the sensor is registered. And the subdev's s_ctrl function will be called when required.

For more details please see: Documentation/video4linux/v4l2-controls.txt

Quoted 43 lines
drivers/media/video/blackfin/bfin_capture.c new file +43 -0
+
+static int bcap_querystd(struct file *file, void *priv, v4l2_std_id *std)
+{
+	struct bcap_device *bcap_dev = video_drvdata(file);
+	int ret;
+
+	ret = v4l2_subdev_call(bcap_dev->sd, video, querystd, std);
+	return ret;
+}
+
+static int bcap_g_std(struct file *file, void *priv, v4l2_std_id *std)
+{
+	struct bcap_device *bcap_dev = video_drvdata(file);
+
+	if (bcap_dev->std) {
+		*std = bcap_dev->std;
+		return 0;
+	} else
+		return -EINVAL;
+}
+
+static int bcap_s_std(struct file *file, void *priv, v4l2_std_id *std)
+{
+	struct bcap_device *bcap_dev = video_drvdata(file);
+	int ret;
+
+	/* if streaming is started, return error */
+	if (bcap_dev->started) {
+		v4l2_err(&bcap_dev->v4l2_dev, "Streaming is started\n");
+		return -EBUSY;
+	}
+
+	ret = v4l2_subdev_call(bcap_dev->sd, core, s_std, *std);
+	if (ret<  0)
+		return ret;
+
+	bcap_dev->std = *std;
+	return 0;
+}
+
+static int bcap_enum_input(struct file *file, void *priv,
+				struct v4l2_input *input)
+{

drivers/media/video/blackfin/bfin_capture.c line 617

Quoted 10 lines
drivers/media/video/blackfin/bfin_capture.c new file +10 -0
+	struct bcap_device *bcap_dev = video_drvdata(file);
+	struct bfin_capture_config *config = bcap_dev->cfg;
+	int ret;
+	u32 status;
+
+	if (input->index>= config->num_inputs)
+		return -EINVAL;
+
+	memcpy(input,&config->inputs[input->index],
+		sizeof(*input));

Unecessary wrapping? How about just doing:

	input = &config->inputs[input->index]; ?
Quoted 43 lines
drivers/media/video/blackfin/bfin_capture.c new file +43 -0
+	/* get input status */
+	ret = v4l2_subdev_call(bcap_dev->sd, video, g_input_status,&status);
+	if (!ret)
+		input->status = status;
+	return 0;
+}
+
+static int bcap_g_input(struct file *file, void *priv, unsigned int *index)
+{
+	struct bcap_device *bcap_dev = video_drvdata(file);
+
+	*index = bcap_dev->cur_input;
+	return 0;
+}
+
+static int bcap_s_input(struct file *file, void *priv, unsigned int index)
+{
+	struct bcap_device *bcap_dev = video_drvdata(file);
+	struct bfin_capture_config *config = bcap_dev->cfg;
+	struct bcap_route *route;
+	int ret;
+
+	/* if streaming is started, return error */
+	if (bcap_dev->started) {
+		v4l2_err(&bcap_dev->v4l2_dev, "Streaming is started\n");
+		return -EBUSY;
+	}
+
+	if (index>= config->num_inputs)
+		return -EINVAL;
+
+	route =&config->routes[index];
+	ret = v4l2_subdev_call(bcap_dev->sd, video, s_routing,
+				route->input, route->output, 0);
+	if ((ret<  0)&&  (ret != -ENOIOCTLCMD)) {
+		v4l2_err(&bcap_dev->v4l2_dev, "Failed to set input\n");
+		return ret;
+	}
+	bcap_dev->cur_input = index;
+	return 0;
+}
+
+static int bcap_try_format(struct bcap_device *bcap,

drivers/media/video/blackfin/bfin_capture.c line 670

Quoted 10 lines
drivers/media/video/blackfin/bfin_capture.c new file +10 -0
+				struct v4l2_pix_format *pixfmt,
+				enum v4l2_mbus_pixelcode *mbus_code,
+				int *bpp)
+{
+	const struct bcap_format *fmt;
+	struct v4l2_mbus_framefmt mbus_fmt;
+	int ret, i;
+
+	for (i = 0; i<  BCAP_MAX_FMTS; i++) {
+		if ((pixfmt->pixelformat == bcap_formats[i].pixelformat)) {
		if ((pixfmt->pixelformat != bcap_formats[i].pixelformat))
			continue;

to avoid indentation ?

Quoted 5 lines
drivers/media/video/blackfin/bfin_capture.c new file +5 -0
+			fmt =&bcap_formats[i];
+			if (mbus_code)
+				*mbus_code = fmt->mbus_code;
+			if (bpp)
+				*bpp = fmt->bpp;

drivers/media/video/blackfin/bfin_capture.c line 685

Quoted 10 lines
drivers/media/video/blackfin/bfin_capture.c new file +10 -0
+			v4l2_fill_mbus_format(&mbus_fmt, pixfmt,
+						fmt->mbus_code);
+			ret = v4l2_subdev_call(bcap->sd, video,
+						try_mbus_fmt,&mbus_fmt);
+			if (ret<  0)
+				return ret;
+			v4l2_fill_pix_format(pixfmt,&mbus_fmt);
+			pixfmt->bytesperline = pixfmt->width * fmt->bpp;
+			pixfmt->sizeimage = pixfmt->bytesperline
+						* pixfmt->height;

Still pixfmt->pixelformat isn't filled.

drivers/media/video/blackfin/bfin_capture.c line 272

Quoted 4 lines
drivers/media/video/blackfin/bfin_capture.c new file +4 -0
+			return 0;
+		}
+	}
+	return -EINVAL;

I think you should return some default format, rather than giving up when the fourcc doesn't match. However I'm not 100% sure this is the specification requirement.

Quoted 7 lines
drivers/media/video/blackfin/bfin_capture.c new file +7 -0
+}
+
+static int bcap_enum_fmt_vid_cap(struct file *file, void  *priv,
+					struct v4l2_fmtdesc *fmt)
+{
+	struct bcap_device *bcap_dev = video_drvdata(file);
+	enum v4l2_mbus_pixelcode mbus_code;

drivers/media/video/blackfin/bfin_capture.c line 706

Quoted 10 lines
drivers/media/video/blackfin/bfin_capture.c new file +10 -0
+	u32 index = fmt->index;
+	int ret, i;
+
+	ret = v4l2_subdev_call(bcap_dev->sd, video,
+				enum_mbus_fmt, index,&mbus_code);
+	if (ret<  0)
+		return ret;
+
+	for (i = 0; i<  BCAP_MAX_FMTS; i++) {
+		if (mbus_code == bcap_formats[i].mbus_code) {
	if (mbus_code != bcap_formats[i].mbus_code)
		continue;
	?
Quoted 34 lines
drivers/media/video/blackfin/bfin_capture.c new file +34 -0
+			fmt->type = V4L2_BUF_TYPE_VIDEO_CAPTURE;
+			strlcpy(fmt->description,
+					bcap_formats[index].desc,
+					 sizeof(fmt->description));
+			fmt->pixelformat = bcap_formats[index].pixelformat;
+			return 0;
+		}
+	}
+	v4l2_err(&bcap_dev->v4l2_dev,
+			"subdev fmt is not supported by bcap\n");
+	return -EINVAL;
+}
+
+static int bcap_try_fmt_vid_cap(struct file *file, void *priv,
+					struct v4l2_format *fmt)
+{
+	struct bcap_device *bcap_dev = video_drvdata(file);
+	struct v4l2_pix_format *pixfmt =&fmt->fmt.pix;
+
+	if (fmt->type != V4L2_BUF_TYPE_VIDEO_CAPTURE)
+		return -EINVAL;
+
+	return bcap_try_format(bcap_dev, pixfmt, NULL, NULL);
+}
+
+static int bcap_g_fmt_vid_cap(struct file *file, void *priv,
+				struct v4l2_format *fmt)
+{
+	struct bcap_device *bcap_dev = video_drvdata(file);
+	struct v4l2_mbus_framefmt mbus_fmt;
+	const struct bcap_format *bcap_fmt;
+	struct v4l2_pix_format *pixfmt =&fmt->fmt.pix;
+	int ret, i;
+

drivers/media/video/blackfin/bfin_capture.c line 750

Quoted 10 lines
drivers/media/video/blackfin/bfin_capture.c new file +10 -0
+	if (fmt->type != V4L2_BUF_TYPE_VIDEO_CAPTURE)
+		return -EINVAL;
+
+	ret = v4l2_subdev_call(bcap_dev->sd, video,
+				g_mbus_fmt,&mbus_fmt);
+	if (ret<  0)
+		return ret;
+
+	for (i = 0; i<  BCAP_MAX_FMTS; i++) {
+		if (mbus_fmt.code == bcap_formats[i].mbus_code) {
	if (mbus_fmt.code != bcap_formats[i].mbus_code)
		continue;
	?
Quoted 119 lines
drivers/media/video/blackfin/bfin_capture.c new file +119 -0
+			bcap_fmt =&bcap_formats[i];
+			v4l2_fill_pix_format(pixfmt,&mbus_fmt);
+			pixfmt->bytesperline = pixfmt->width * bcap_fmt->bpp;
+			pixfmt->sizeimage = pixfmt->bytesperline
+						* pixfmt->height;
+			return 0;
+		}
+	}
+	v4l2_err(&bcap_dev->v4l2_dev,
+			"subdev fmt is not supported by bcap\n");
+	return -EINVAL;
+}
+
+static int bcap_s_fmt_vid_cap(struct file *file, void *priv,
+				struct v4l2_format *fmt)
+{
+	struct bcap_device *bcap_dev = video_drvdata(file);
+	struct v4l2_mbus_framefmt mbus_fmt;
+	enum v4l2_mbus_pixelcode mbus_code;
+	struct v4l2_pix_format *pixfmt =&fmt->fmt.pix;
+	int ret, bpp;
+
+	/* if streaming is started, return error */
+	if (bcap_dev->started) {
+		v4l2_err(&bcap_dev->v4l2_dev, "Streaming is started\n");
+		return -EBUSY;
+	}
+
+	if (fmt->type != V4L2_BUF_TYPE_VIDEO_CAPTURE)
+		return -EINVAL;
+	/* see if format works */
+	ret = bcap_try_format(bcap_dev, pixfmt,&mbus_code,&bpp);
+	if (ret<  0)
+		return ret;
+
+	v4l2_fill_mbus_format(&mbus_fmt, pixfmt, mbus_code);
+	ret = v4l2_subdev_call(bcap_dev->sd, video, s_mbus_fmt,&mbus_fmt);
+	if (ret<  0)
+		return ret;
+	bcap_dev->fmt = *pixfmt;
+	bcap_dev->bpp = bpp;
+	return 0;
+}
+
+static int bcap_querycap(struct file *file, void  *priv,
+				struct v4l2_capability *cap)
+{
+	struct bcap_device *bcap_dev = video_drvdata(file);
+
+	cap->capabilities = V4L2_CAP_VIDEO_CAPTURE | V4L2_CAP_STREAMING;
+	strlcpy(cap->driver, CAPTURE_DRV_NAME, sizeof(cap->driver));
+	strlcpy(cap->bus_info, "Blackfin Platform", sizeof(cap->bus_info));
+	strlcpy(cap->card, bcap_dev->cfg->card_name, sizeof(cap->card));
+	return 0;
+}
+
+static int bcap_cropcap(struct file *file, void *priv,
+			struct v4l2_cropcap *crop)
+{
+	struct bcap_device *bcap_dev = video_drvdata(file);
+
+	if (crop->type != V4L2_BUF_TYPE_VIDEO_CAPTURE)
+		return -EINVAL;
+
+	return v4l2_subdev_call(bcap_dev->sd, video, cropcap, crop);
+}
+
+static int bcap_g_parm(struct file *file, void *fh,
+				struct v4l2_streamparm *a)
+{
+	struct bcap_device *bcap_dev = video_drvdata(file);
+
+	if (a->type != V4L2_BUF_TYPE_VIDEO_CAPTURE)
+		return -EINVAL;
+	return v4l2_subdev_call(bcap_dev->sd, video, g_parm, a);
+}
+
+static int bcap_s_parm(struct file *file, void *fh,
+				struct v4l2_streamparm *a)
+{
+	struct bcap_device *bcap_dev = video_drvdata(file);
+
+	if (a->type != V4L2_BUF_TYPE_VIDEO_CAPTURE)
+		return -EINVAL;
+	return v4l2_subdev_call(bcap_dev->sd, video, s_parm, a);
+}
+
+static int bcap_g_chip_ident(struct file *file, void *priv,
+		struct v4l2_dbg_chip_ident *chip)
+{
+	struct bcap_device *bcap_dev = video_drvdata(file);
+
+	chip->ident = V4L2_IDENT_NONE;
+	chip->revision = 0;
+	if (chip->match.type != V4L2_CHIP_MATCH_I2C_DRIVER&&
+			chip->match.type != V4L2_CHIP_MATCH_I2C_ADDR)
+		return -EINVAL;
+
+	return v4l2_subdev_call(bcap_dev->sd, core,
+			g_chip_ident, chip);
+}
+
+#ifdef CONFIG_VIDEO_ADV_DEBUG
+static int bcap_dbg_g_register(struct file *file, void *priv,
+		struct v4l2_dbg_register *reg)
+{
+	struct bcap_device *bcap_dev = video_drvdata(file);
+
+	return v4l2_subdev_call(bcap_dev->sd, core,
+			g_register, reg);
+}
+
+static int bcap_dbg_s_register(struct file *file, void *priv,
+		struct v4l2_dbg_register *reg)
+{
+	struct bcap_device *bcap_dev = video_drvdata(file);
+
+	return v4l2_subdev_call(bcap_dev->sd, core,
+			s_register, reg);

drivers/media/video/blackfin/bfin_capture.c line 879

Quoted 10 lines
drivers/media/video/blackfin/bfin_capture.c new file +10 -0
+}
+#endif
+
+static int bcap_log_status(struct file *file, void *priv)
+{
+	struct bcap_device *bcap_dev = video_drvdata(file);
+	/* status for sub devices */
+	v4l2_device_call_all(&bcap_dev->v4l2_dev, 0, core, log_status);
+	return 0;
+}

This is also not needed, if the subdev implements log_status().

Quoted 120 lines
drivers/media/video/blackfin/bfin_capture.c new file +120 -0
+
+static const struct v4l2_ioctl_ops bcap_ioctl_ops = {
+	.vidioc_querycap         = bcap_querycap,
+	.vidioc_g_fmt_vid_cap    = bcap_g_fmt_vid_cap,
+	.vidioc_enum_fmt_vid_cap = bcap_enum_fmt_vid_cap,
+	.vidioc_s_fmt_vid_cap    = bcap_s_fmt_vid_cap,
+	.vidioc_try_fmt_vid_cap  = bcap_try_fmt_vid_cap,
+	.vidioc_enum_input       = bcap_enum_input,
+	.vidioc_g_input          = bcap_g_input,
+	.vidioc_s_input          = bcap_s_input,
+	.vidioc_querystd         = bcap_querystd,
+	.vidioc_s_std            = bcap_s_std,
+	.vidioc_g_std            = bcap_g_std,
+	.vidioc_queryctrl        = bcap_queryctrl,
+	.vidioc_g_ctrl           = bcap_g_ctrl,
+	.vidioc_s_ctrl           = bcap_s_ctrl,
+	.vidioc_reqbufs          = bcap_reqbufs,
+	.vidioc_querybuf         = bcap_querybuf,
+	.vidioc_qbuf             = bcap_qbuf,
+	.vidioc_dqbuf            = bcap_dqbuf,
+	.vidioc_streamon         = bcap_streamon,
+	.vidioc_streamoff        = bcap_streamoff,
+	.vidioc_cropcap          = bcap_cropcap,
+	.vidioc_g_parm           = bcap_g_parm,
+	.vidioc_s_parm           = bcap_s_parm,
+	.vidioc_g_chip_ident     = bcap_g_chip_ident,
+#ifdef CONFIG_VIDEO_ADV_DEBUG
+	.vidioc_g_register       = bcap_dbg_g_register,
+	.vidioc_s_register       = bcap_dbg_s_register,
+#endif
+	.vidioc_log_status       = bcap_log_status,
+};
+
+static struct v4l2_file_operations bcap_fops = {
+	.owner = THIS_MODULE,
+	.open = bcap_open,
+	.release = bcap_release,
+	.unlocked_ioctl = video_ioctl2,
+	.mmap = bcap_mmap,
+#ifndef CONFIG_MMU
+	.get_unmapped_area = bcap_get_unmapped_area,
+#endif
+	.poll = bcap_poll
+};
+
+static int __devinit bcap_probe(struct platform_device *pdev)
+{
+	struct bcap_device *bcap_dev;
+	struct video_device *vfd;
+	struct i2c_adapter *i2c_adap;
+	struct bfin_capture_config *config;
+	struct vb2_queue *q;
+	int ret;
+
+	config = pdev->dev.platform_data;
+	if (!config) {
+		v4l2_err(pdev->dev.driver, "Unable to get board config\n");
+		return -ENODEV;
+	}
+
+	bcap_dev = kzalloc(sizeof(*bcap_dev), GFP_KERNEL);
+	if (!bcap_dev) {
+		v4l2_err(pdev->dev.driver, "Unable to alloc bcap_dev\n");
+		return -ENOMEM;
+	}
+
+	bcap_dev->cfg = config;
+
+	bcap_dev->ppi = create_ppi_instance(config->ppi_info);
+	if (!bcap_dev->ppi) {
+		v4l2_err(pdev->dev.driver, "Unable to create ppi\n");
+		ret = -ENODEV;
+		goto err_free_dev;
+	}
+	bcap_dev->ppi->priv = bcap_dev;
+
+	bcap_dev->alloc_ctx = vb2_dma_contig_init_ctx(&pdev->dev);
+	if (IS_ERR(bcap_dev->alloc_ctx)) {
+		ret = PTR_ERR(bcap_dev->alloc_ctx);
+		goto err_free_ppi;
+	}
+
+	vfd = video_device_alloc();
+	if (!vfd) {
+		ret = -ENOMEM;
+		v4l2_err(pdev->dev.driver, "Unable to alloc video device\n");
+		goto err_cleanup_ctx;
+	}
+
+	/* initialize field of video device */
+	vfd->release            = video_device_release;
+	vfd->fops               =&bcap_fops;
+	vfd->ioctl_ops          =&bcap_ioctl_ops;
+	vfd->tvnorms            = 0;
+	vfd->v4l2_dev           =&bcap_dev->v4l2_dev;
+	set_bit(V4L2_FL_USE_FH_PRIO,&vfd->flags);
+	strncpy(vfd->name, CAPTURE_DRV_NAME, sizeof(vfd->name));
+	bcap_dev->video_dev     = vfd;
+
+	ret = v4l2_device_register(&pdev->dev,&bcap_dev->v4l2_dev);
+	if (ret) {
+		v4l2_err(pdev->dev.driver,
+				"Unable to register v4l2 device\n");
+		goto err_release_vdev;
+	}
+	v4l2_info(&bcap_dev->v4l2_dev, "v4l2 device registered\n");
+
+	spin_lock_init(&bcap_dev->lock);
+	/* initialize queue */
+	q =&bcap_dev->buffer_queue;
+	memset(q, 0, sizeof(*q));
+	q->type = V4L2_BUF_TYPE_VIDEO_CAPTURE;
+	q->io_modes = VB2_MMAP;
+	q->drv_priv = bcap_dev;
+	q->buf_struct_size = sizeof(struct bcap_buffer);
+	q->ops =&bcap_video_qops;
+	q->mem_ops =&vb2_dma_contig_memops;
+
+	vb2_queue_init(q);
+

drivers/media/video/blackfin/bfin_capture.c line 1009

Quoted 10 lines
drivers/media/video/blackfin/bfin_capture.c new file +10 -0
+	mutex_init(&bcap_dev->mutex);
+	init_completion(&bcap_dev->comp);
+
+	/* init video dma queues */
+	INIT_LIST_HEAD(&bcap_dev->dma_queue);
+
+	vfd->lock =&bcap_dev->mutex;
+
+	/* register video device */
+	ret = video_register_device(bcap_dev->video_dev, VFL_TYPE_GRABBER, -1);

I think the video node registration should be very last thing done in this function, after everything else is initialized. The device is not really ready for use at this point, is it ?

Quoted 133 lines
drivers/media/video/blackfin/bfin_capture.c new file +90 -0
+	if (ret) {
+		v4l2_err(&bcap_dev->v4l2_dev,
+				"Unable to register video device\n");
+		goto err_unreg_v4l2;
+	}
+	video_set_drvdata(bcap_dev->video_dev, bcap_dev);
+	v4l2_info(&bcap_dev->v4l2_dev, "video device registered as: %s\n",
+			video_device_node_name(vfd));
+
+	/* load up the subdevice */
+	i2c_adap = i2c_get_adapter(config->i2c_adapter_id);
+	if (!i2c_adap) {
+		v4l2_err(&bcap_dev->v4l2_dev,
+				"Unable to find i2c adapter\n");
+		goto err_unreg_vdev;
+
+	}
+	bcap_dev->sd = v4l2_i2c_new_subdev_board(&bcap_dev->v4l2_dev,
+						 i2c_adap,
+						&config->board_info,
+						 NULL);
+	if (bcap_dev->sd) {
+		int i;
+		/* update tvnorms from the sub devices */
+		for (i = 0; i<  config->num_inputs; i++)
+			vfd->tvnorms |= config->inputs[i].std;
+		/* set default std */
+		bcap_dev->std = vfd->tvnorms;
+	} else {
+		v4l2_err(&bcap_dev->v4l2_dev,
+				"Unable to register sub device\n");
+		goto err_unreg_vdev;
+	}
+	v4l2_info(&bcap_dev->v4l2_dev, "v4l2 sub device registered\n");
+	return 0;
+err_unreg_vdev:
+	video_unregister_device(bcap_dev->video_dev);
+err_unreg_v4l2:
+	v4l2_device_unregister(&bcap_dev->v4l2_dev);
+err_release_vdev:
+	if (!video_is_registered(bcap_dev->video_dev))
+		video_device_release(bcap_dev->video_dev);
+err_cleanup_ctx:
+	vb2_dma_contig_cleanup_ctx(bcap_dev->alloc_ctx);
+err_free_ppi:
+	delete_ppi_instance(bcap_dev->ppi);
+err_free_dev:
+	kfree(bcap_dev);
+	return ret;
+}
+
+static int __devexit bcap_remove(struct platform_device *pdev)
+{
+	struct v4l2_device *v4l2_dev = platform_get_drvdata(pdev);
+	struct bcap_device *bcap_dev = container_of(v4l2_dev,
+						struct bcap_device, v4l2_dev);
+
+	video_unregister_device(bcap_dev->video_dev);
+	v4l2_device_unregister(v4l2_dev);
+	vb2_dma_contig_cleanup_ctx(bcap_dev->alloc_ctx);
+	delete_ppi_instance(bcap_dev->ppi);
+	kfree(bcap_dev);
+	return 0;
+}
+
+static struct platform_driver bcap_driver = {
+	.driver = {
+		.name   = CAPTURE_DRV_NAME,
+		.owner = THIS_MODULE,
+	},
+	.probe = bcap_probe,
+	.remove = __devexit_p(bcap_remove),
+};
+
+static __init int bcap_init(void)
+{
+	return platform_driver_register(&bcap_driver);
+}
+
+static __exit void bcap_exit(void)
+{
+	platform_driver_unregister(&bcap_driver);
+}
+
+module_init(bcap_init);
+module_exit(bcap_exit);
+
+MODULE_DESCRIPTION("Analog Devices video capture driver");
+MODULE_AUTHOR("Scott Jiang<[email protected]>");
+MODULE_LICENSE("GPL v2");
drivers/media/video/blackfin/ppi.c new file +37 -0
new file mode 100644
index 0000000..8139940
@@ -0,0 +1,204 @@
+/*
+ * ppi.c Analog Devices Parallel Peripheral Interface driver
+ *
+ * Copyright (c) 2011 Analog Devices Inc.
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License version 2 as
+ * published by the Free Software Foundation.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
+ */
+
+#include<linux/kernel.h>
+#include<linux/slab.h>
+#include<linux/ioport.h>
+#include<linux/platform_device.h>
+
+#include<asm/bfin_ppi.h>
+#include<asm/dma.h>
+#include<asm/cacheflush.h>
+#include<asm/blackfin.h>
+#include<asm/portmux.h>
+
+#include<media/blackfin/ppi.h>
+
+static int ppi_attach_irq(struct ppi_if *ppi, irq_handler_t handler);
+static void ppi_detach_irq(struct ppi_if *ppi);
+static int ppi_start(struct ppi_if *ppi);
+static int ppi_stop(struct ppi_if *ppi);
+static int ppi_set_params(struct ppi_if *ppi, struct ppi_params *params);

drivers/media/video/blackfin/ppi.c line 47

Quoted 10 lines
drivers/media/video/blackfin/ppi.c new file +10 -0
+static void ppi_update_addr(struct ppi_if *ppi, unsigned long addr);
+
+static const struct ppi_ops ppi_ops = {
+	.attach_irq = ppi_attach_irq,
+	.detach_irq = ppi_detach_irq,
+	.start = ppi_start,
+	.stop = ppi_stop,
+	.set_params = ppi_set_params,
+	.update_addr = ppi_update_addr,
+};

How about moving this struct to the bottom of the file and getting rid of all the above forward declarations ?

Quoted 41 lines
drivers/media/video/blackfin/ppi.c new file +41 -0
+
+static irqreturn_t ppi_irq_err(int irq, void *dev_id)
+{
+	struct ppi_if *ppi = dev_id;
+	const struct ppi_info *info = ppi->info;
+	unsigned short status;
+
+	if (!strcmp(info->name, "ppi")) {
+		struct bfin_ppi_regs __iomem *reg =
+			(struct bfin_ppi_regs __iomem *)info->base;
+		status = bfin_read16(reg->status);
+		if (printk_ratelimit())
+			pr_info("%s: status = 0x%x\n", __func__, status);
+		bfin_write16(&reg->status, 0xff);
+	}
+
+	return IRQ_HANDLED;
+}
+
+static int ppi_attach_irq(struct ppi_if *ppi, irq_handler_t handler)
+{
+	const struct ppi_info *info = ppi->info;
+
+	if (request_dma(info->dma_ch, "PPI_DMA")<  0) {
+		pr_err("Unable to allocate DMA channel for PPI\n");
+		return -EBUSY;
+	}
+	set_dma_callback(info->dma_ch, handler, ppi);
+
+	if (request_irq(info->irq_err, ppi_irq_err, IRQF_DISABLED,
+				"PPI ERROR", ppi)) {
+		pr_err("Unable to allocate IRQ for PPI\n");
+		free_dma(info->dma_ch);
+		return -EBUSY;
+	}
+	return 0;
+}
+
+static void ppi_detach_irq(struct ppi_if *ppi)
+{
+	const struct ppi_info *info = ppi->info;

drivers/media/video/blackfin/ppi.c line 98

Quoted 10 lines
drivers/media/video/blackfin/ppi.c new file +10 -0
+
+	free_irq(info->irq_err, ppi);
+	free_dma(info->dma_ch);
+}
+
+static int ppi_start(struct ppi_if *ppi)
+{
+	const struct ppi_info *info = ppi->info;
+
+	/* enable DMA */

The comment seems redundant.

Quoted 16 lines
drivers/media/video/blackfin/ppi.c new file +16 -0
+	enable_dma(info->dma_ch);
+
+	/* enable PPI */
+	ppi->ppi_control |= PORT_EN;
+	if (!strcmp(info->name, "ppi")) {
+		struct bfin_ppi_regs __iomem *reg =
+			(struct bfin_ppi_regs __iomem *)info->base;
+		bfin_write16(&reg->control, ppi->ppi_control);
+	}
+
+	SSYNC();
+	return 0;
+}
+
+static int ppi_stop(struct ppi_if *ppi)
+{

drivers/media/video/blackfin/ppi.c line 124

Quoted 10 lines
drivers/media/video/blackfin/ppi.c new file +10 -0
+	const struct ppi_info *info = ppi->info;
+
+	/* disable PPI */
+	ppi->ppi_control&= ~PORT_EN;
+	if (!strcmp(info->name, "ppi")) {
+		struct bfin_ppi_regs __iomem *reg =
+			(struct bfin_ppi_regs __iomem *)info->base;
+		bfin_write16(&reg->control, ppi->ppi_control);
+	}
+

+ /* disable DMA */

Quoted 44 lines
drivers/media/video/blackfin/ppi.c new file +44 -0
+	clear_dma_irqstat(info->dma_ch);
+	disable_dma(info->dma_ch);
+
+	SSYNC();
+	return 0;
+}
+
+static int ppi_set_params(struct ppi_if *ppi, struct ppi_params *params)
+{
+	const struct ppi_info *info = ppi->info;
+
+	ppi->bytes_per_line = params->width * params->bpp;
+	ppi->lines_per_frame = params->height;
+
+	/* config DMA */
+	ppi->dma_config = (DMA_FLOW_STOP | WNR | RESTART | DMA2D | DI_EN);
+	if (params->ppi_control&  DMA32) {
+		ppi->dma_config |= WDSIZE_32;
+		set_dma_x_count(info->dma_ch, ppi->bytes_per_line>>  2);
+		set_dma_x_modify(info->dma_ch, 4);
+		set_dma_y_modify(info->dma_ch, 4);
+	} else {
+		ppi->dma_config |= WDSIZE_16;
+		set_dma_x_count(info->dma_ch, ppi->bytes_per_line>>  1);
+		set_dma_x_modify(info->dma_ch, 2);
+		set_dma_y_modify(info->dma_ch, 2);
+	}
+	set_dma_y_count(info->dma_ch, ppi->lines_per_frame);
+	set_dma_config(info->dma_ch, ppi->dma_config);
+
+	/* config PPI */
+	ppi->ppi_control = params->ppi_control&  ~PORT_EN;
+	if (!strcmp(info->name, "ppi")) {
+		struct bfin_ppi_regs __iomem *reg =
+			(struct bfin_ppi_regs __iomem *)info->base;
+		bfin_write16(&reg->control, ppi->ppi_control);
+		bfin_write16(&reg->count, ppi->bytes_per_line - 1);
+		bfin_write16(&reg->frame, ppi->lines_per_frame);
+	}
+
+	SSYNC();
+	return 0;
+}
+

drivers/media/video/blackfin/ppi.c line 179

Quoted 10 lines
drivers/media/video/blackfin/ppi.c new file +10 -0
+static void ppi_update_addr(struct ppi_if *ppi, unsigned long addr)
+{
+	set_dma_start_addr(ppi->info->dma_ch, addr);
+}
+
+struct ppi_if *create_ppi_instance(const struct ppi_info *info)
+{
+	struct ppi_if *ppi;
+
+	if ((info == NULL) || (info->name == NULL) || (info->pin_req == NULL))

The individual inner braces seem superfluous.

Quoted 15 lines
drivers/media/video/blackfin/ppi.c new file +15 -0
+		return NULL;
+
+	if (peripheral_request_list(info->pin_req, KBUILD_MODNAME)) {
+		pr_err("request peripheral failed\n");
+		return NULL;
+	}
+
+	ppi = kzalloc(sizeof(*ppi), GFP_KERNEL);
+	if (ppi == NULL) {
+		peripheral_free_list(info->pin_req);
+		pr_err("unable to allocate memory for ppi handle\n");
+		return NULL;
+	}
+	ppi->ops =&ppi_ops;
+	ppi->info = info;

drivers/media/video/blackfin/ppi.c line 204

Quoted 10 lines
drivers/media/video/blackfin/ppi.c new file +10 -0
+
+	pr_info("ppi probe success\n");
+	return ppi;
+}
+
+void delete_ppi_instance(struct ppi_if *ppi)
+{
+	peripheral_free_list(ppi->info->pin_req);
+	kfree(ppi);
+}

As a side note, I was not sure if this is just a resend of your original patches or a second version. It would be good to indicate that in the message subject. I think it's not a big deal and makes the reviewers' life easier.

--
Thanks,
Sylwester

#20 lore raw

Re: [PATCH 4/4] v4l2: add blackfin capture bridge driver

Quoted 12 lines

drivers/media/video/blackfin/bfin_capture.c line 425

Quoted 9 lines
drivers/media/video/blackfin/bfin_capture.c new file +9 -0
+static int bcap_qbuf(struct file *file, void *priv,
+                     struct v4l2_buffer *buf)
+{
+     struct bcap_device *bcap_dev = video_drvdata(file);
+     struct v4l2_fh *fh = file->private_data;
+     struct bcap_fh *bcap_fh = container_of(fh, struct bcap_fh, fh);
+
+     if (!bcap_fh->io_allowed)
+             return -EACCES;

I suppose -EBUSY would be more appropriate here.

no, io_allowed is to control which file instance has the right to do I/O.

Quoted 16 lines
Quoted 7 lines

+                     fmt =&bcap_formats[i];
+                     if (mbus_code)
+                             *mbus_code = fmt->mbus_code;
+                     if (bpp)
+                             *bpp = fmt->bpp;
+                     v4l2_fill_mbus_format(&mbus_fmt, pixfmt,
+                                             fmt->mbus_code);

Quoted 8 lines

+                     ret = v4l2_subdev_call(bcap->sd, video,
+                                             try_mbus_fmt,&mbus_fmt);
+                     if (ret<  0)
+                             return ret;
+                     v4l2_fill_pix_format(pixfmt,&mbus_fmt);
+                     pixfmt->bytesperline = pixfmt->width * fmt->bpp;
+                     pixfmt->sizeimage = pixfmt->bytesperline
+                                             * pixfmt->height;

Quoted 2 lines

Still pixfmt->pixelformat isn't filled.

no here pixfmt->pixelformat is passed in

Quoted 9 lines
Quoted 4 lines

+                     return 0;
+             }
+     }
+     return -EINVAL;

I think you should return some default format, rather than giving up when the fourcc doesn't match. However I'm not 100% sure this is the specification requirement.

no, there is no default format for bridge driver because it knows nothing about this.
all the format info bridge needs ask subdevice.

Quoted 12 lines

drivers/media/video/blackfin/ppi.c line 47

Quoted 8 lines
drivers/media/video/blackfin/ppi.c new file +8 -0
+static const struct ppi_ops ppi_ops = {
+     .attach_irq = ppi_attach_irq,
+     .detach_irq = ppi_detach_irq,
+     .start = ppi_start,
+     .stop = ppi_stop,
+     .set_params = ppi_set_params,
+     .update_addr = ppi_update_addr,
+};

How about moving this struct to the bottom of the file and getting rid of all the above forward declarations ?

I'd like to put global varible before function in a file.

Quoted 10 lines

drivers/media/video/blackfin/ppi.c line 204

Quoted 6 lines
drivers/media/video/blackfin/ppi.c new file +6 -0
+
+void delete_ppi_instance(struct ppi_if *ppi)
+{
+     peripheral_free_list(ppi->info->pin_req);
+     kfree(ppi);
+}

As a side note, I was not sure if this is just a resend of your original patches or a second version. It would be good to indicate that in the message subject. I think it's not a big deal and makes the reviewers' life easier.

if I don't add a version number in subject, it means it is the first version.

#21 lore raw

Re: [PATCH 4/4] v4l2: add blackfin capture bridge driver

Quoted 12 lines · Scott Jiang
Quoted 12 lines

drivers/media/video/blackfin/bfin_capture.c line 425

Quoted 9 lines
drivers/media/video/blackfin/bfin_capture.c new file +9 -0
+static int bcap_qbuf(struct file *file, void *priv,
+                     struct v4l2_buffer *buf)
+{
+     struct bcap_device *bcap_dev = video_drvdata(file);
+     struct v4l2_fh *fh = file->private_data;
+     struct bcap_fh *bcap_fh = container_of(fh, struct bcap_fh, fh);
+
+     if (!bcap_fh->io_allowed)
+             return -EACCES;

I suppose -EBUSY would be more appropriate here.

Quoted 1 line

no, io_allowed is to control which file instance has the right to do I/O.

Looks like you are doing here what the v4l2 priority mechanism is meant for. Have you considered the access priority (VIDIOC_G_PRIORITY/VIDIOC_S_PRIORITY and friends)? Does it have any shortcomings?

Quoted 26 lines
Quoted 17 lines
Quoted 6 lines
drivers/media/video/blackfin/bfin_capture.c new file +5 -0
+                     fmt =&bcap_formats[i];
+                     if (mbus_code)
+                             *mbus_code = fmt->mbus_code;
+                     if (bpp)
+                             *bpp = fmt->bpp;

drivers/media/video/blackfin/bfin_capture.c line 685

Quoted 10 lines
drivers/media/video/blackfin/bfin_capture.c new file +10 -0
+                     v4l2_fill_mbus_format(&mbus_fmt, pixfmt,
+                                             fmt->mbus_code);
+                     ret = v4l2_subdev_call(bcap->sd, video,
+                                             try_mbus_fmt,&mbus_fmt);
+                     if (ret<  0)
+                             return ret;
+                     v4l2_fill_pix_format(pixfmt,&mbus_fmt);
+                     pixfmt->bytesperline = pixfmt->width * fmt->bpp;
+                     pixfmt->sizeimage = pixfmt->bytesperline
+                                             * pixfmt->height;
Quoted 2 lines

Still pixfmt->pixelformat isn't filled.

no here pixfmt->pixelformat is passed in

Quoted 5 lines
Quoted 4 lines
drivers/media/video/blackfin/bfin_capture.c new file +4 -0
+                     return 0;
+             }
+     }
+     return -EINVAL;
Quoted 7 lines
Quoted 4 lines

I think you should return some default format, rather than giving up when the fourcc doesn't match. However I'm not 100% sure this is the specification requirement.

no, there is no default format for bridge driver because it knows nothing about this.
all the format info bridge needs ask subdevice.

It's the bridge driver that exports a device node and is responsible for setting the default format. It should be possible to start streaming right after opening the device, without VIDIOC_S_FMT, with some reasonable defaults.

If, as you say, the bridge knows nothing about formats what the bcap_formats[] array is here for ?

Quoted 25 lines
Quoted 13 lines

drivers/media/video/blackfin/ppi.c line 47

Quoted 9 lines
drivers/media/video/blackfin/ppi.c new file +8 -0
+static const struct ppi_ops ppi_ops = {
+     .attach_irq = ppi_attach_irq,
+     .detach_irq = ppi_detach_irq,
+     .start = ppi_start,
+     .stop = ppi_stop,
+     .set_params = ppi_set_params,
+     .update_addr = ppi_update_addr,
+};

How about moving this struct to the bottom of the file and getting rid of all the above forward declarations ?

I'd like to put global varible before function in a file.

Quoted 10 lines

drivers/media/video/blackfin/ppi.c line 204

Quoted 6 lines
drivers/media/video/blackfin/ppi.c new file +6 -0
+
+void delete_ppi_instance(struct ppi_if *ppi)
+{
+     peripheral_free_list(ppi->info->pin_req);
+     kfree(ppi);
+}

As a side note, I was not sure if this is just a resend of your original patches or a second version. It would be good to indicate that in the message subject. I think it's not a big deal and makes the reviewers' life easier.

Quoted 1 line

if I don't add a version number in subject, it means it is the first version.

Sorry, please ignore this. I got confused by the mailer and thought the same patches appeared twice on the list.

Thanks,

Signature · 2 lines
Sylwester Nawrocki
Samsung Poland R&D Center
#22 lore raw

Re: [PATCH 4/4] v4l2: add blackfin capture bridge driver

2011/9/14 Sylwester Nawrocki <[email protected]>:

Quoted 13 lines · Scott Jiang
Quoted 12 lines
Quoted 12 lines

drivers/media/video/blackfin/bfin_capture.c line 425

Quoted 9 lines
drivers/media/video/blackfin/bfin_capture.c new file +9 -0
+static int bcap_qbuf(struct file *file, void *priv,
+                     struct v4l2_buffer *buf)
+{
+     struct bcap_device *bcap_dev = video_drvdata(file);
+     struct v4l2_fh *fh = file->private_data;
+     struct bcap_fh *bcap_fh = container_of(fh, struct bcap_fh, fh);
+
+     if (!bcap_fh->io_allowed)
+             return -EACCES;

I suppose -EBUSY would be more appropriate here.

Quoted 6 lines
Quoted 1 line

no, io_allowed is to control which file instance has the right to do I/O.

Looks like you are doing here what the v4l2 priority mechanism is meant for. Have you considered the access priority (VIDIOC_G_PRIORITY/VIDIOC_S_PRIORITY and friends)? Does it have any shortcomings?

I refer to davinci driver, perhaps it is not good enough, I'd like to modify it later.

Quoted 34 lines
Quoted 26 lines
Quoted 17 lines
Quoted 16 lines

+                     fmt =&bcap_formats[i];
+                     if (mbus_code)
+                             *mbus_code = fmt->mbus_code;
+                     if (bpp)
+                             *bpp = fmt->bpp;
+                     v4l2_fill_mbus_format(&mbus_fmt, pixfmt,
+                                             fmt->mbus_code);
+                     ret = v4l2_subdev_call(bcap->sd, video,
+                                             try_mbus_fmt,&mbus_fmt);
+                     if (ret<  0)
+                             return ret;
+                     v4l2_fill_pix_format(pixfmt,&mbus_fmt);
+                     pixfmt->bytesperline = pixfmt->width * fmt->bpp;
+                     pixfmt->sizeimage = pixfmt->bytesperline
+                                             * pixfmt->height;

Quoted 2 lines

Still pixfmt->pixelformat isn't filled.

no here pixfmt->pixelformat is passed in

Quoted 5 lines
Quoted 4 lines

+                     return 0;
+             }
+     }
+     return -EINVAL;

Quoted 7 lines
Quoted 4 lines

I think you should return some default format, rather than giving up when the fourcc doesn't match. However I'm not 100% sure this is the specification requirement.

no, there is no default format for bridge driver because it knows nothing about this.
all the format info bridge needs ask subdevice.

Quoted 7 lines

It's the bridge driver that exports a device node and is responsible for setting the default format. It should be possible to start streaming right after opening the device, without VIDIOC_S_FMT, with some reasonable defaults.

If, as you say, the bridge knows nothing about formats what the bcap_formats[] array is here for ?

accually this array is to convert mbus to pixformat. ppi supports any formats. Ideally it should contain all formats in v4l2, but it is enough at present for our platform.
If I find someone needs more, I will add it.
So return -EINVAL means this format is out of range, it can't be supported now.

about default format, I think I can only call bcap_g_fmt_vid_cap in probe to get this info.
Dose anybody have a better solution?

#23 lore raw

Re: [PATCH 4/4] v4l2: add blackfin capture bridge driver

Quoted 1 line · Scott Jiang

accually this array is to convert mbus to pixformat. ppi supports any formats.

You mean, it doesn't distinguish formats? It just packs bytes in RAM exactly as it ready them from the bus, and doesn't support any formats natively, i.e., doesn't offer any data processing?

Quoted 4 lines

Ideally it should contain all formats in v4l2, but it is enough at present for our platform.
If I find someone needs more, I will add it.
So return -EINVAL means this format is out of range, it can't be supported now.

You might consider using

drivers/media/video/soc_mediabus.c

If your driver were using soc-camera, it could benefit from the dynamically built pixel translation table, see

drivers/media/video/soc_camera.c::soc_camera_init_user_formats()

and simpler examples like mx1_camera.c or more complex ones like sh_mobile_ceu_camera.c, pxa_camera.c or mx3_camera.c and the use of the soc_camera_xlate_by_fourcc() function in them.

Quoted 3 lines

about default format, I think I can only call bcap_g_fmt_vid_cap in probe to get this info.
Dose anybody have a better solution?

In soc-camera we just use .g_mbus_fmt() to get sensor's default format and see what we can produce from it for the user.

Thanks
Guennadi
---
Guennadi Liakhovetski, Ph.D.
Freelance Open-Source Software Developer
http://www.open-technology.de/

#24 lore raw

Re: [PATCH 4/4] v4l2: add blackfin capture bridge driver

2011/9/15 Guennadi Liakhovetski <[email protected]>:

Quoted 8 lines · Scott Jiang
Quoted 2 lines

accually this array is to convert mbus to pixformat. ppi supports any formats.

You mean, it doesn't distinguish formats? It just packs bytes in RAM exactly as it ready them from the bus, and doesn't support any formats natively, i.e., doesn't offer any data processing?

yes, ppi means Parallel Peripheral Interface.

Quoted 9 lines
Quoted 4 lines

Ideally it should contain all formats in v4l2, but it is enough at present for our platform.
If I find someone needs more, I will add it.
So return -EINVAL means this format is out of range, it can't be supported now.

You might consider using

drivers/media/video/soc_mediabus.c

Quoted 9 lines

If your driver were using soc-camera, it could benefit from the dynamically built pixel translation table, see

drivers/media/video/soc_camera.c::soc_camera_init_user_formats()

and simpler examples like mx1_camera.c or more complex ones like sh_mobile_ceu_camera.c, pxa_camera.c or mx3_camera.c and the use of the soc_camera_xlate_by_fourcc() function in them.

I have considered using soc, but it can't support decoder when I began to write this driver in 2.6.38.

#25 lore raw

Re: [PATCH 4/4] v4l2: add blackfin capture bridge driver

Quoted 23 lines · Scott Jiang

2011/9/15 Guennadi Liakhovetski <[email protected]>:

Quoted 8 lines · Scott Jiang
Quoted 2 lines

accually this array is to convert mbus to pixformat. ppi supports any formats.

You mean, it doesn't distinguish formats? It just packs bytes in RAM exactly as it ready them from the bus, and doesn't support any formats natively, i.e., doesn't offer any data processing?

yes, ppi means Parallel Peripheral Interface.

Quoted 12 lines
Quoted 4 lines

Ideally it should contain all formats in v4l2, but it is enough at present for our platform.
If I find someone needs more, I will add it.
So return -EINVAL means this format is out of range, it can't be supported now.

You might consider using

drivers/media/video/soc_mediabus.c

If your driver were using soc-camera, it could benefit from the dynamically built pixel translation table, see

Quoted 8 lines
Quoted 6 lines

drivers/media/video/soc_camera.c::soc_camera_init_user_formats()

and simpler examples like mx1_camera.c or more complex ones like sh_mobile_ceu_camera.c, pxa_camera.c or mx3_camera.c and the use of the soc_camera_xlate_by_fourcc() function in them.

I have considered using soc, but it can't support decoder when I began to write this driver in 2.6.38.

soc_mediabus.c is a stand-alone module, it has no dependencies on soc-camera.

Out of interest - what kind of decoder you mean? A tv-decoder? We do have a tv-decoder driver tw9910 under soc-camera.

Thanks
Guennadi
---
Guennadi Liakhovetski, Ph.D.
Freelance Open-Source Software Developer
http://www.open-technology.de/

#26 lore raw

Re: [PATCH 4/4] v4l2: add blackfin capture bridge driver

Quoted 9 lines
Quoted 2 lines

I have considered using soc, but it can't support decoder when I began to write this driver in 2.6.38.

soc_mediabus.c is a stand-alone module, it has no dependencies on soc-camera.

Out of interest - what kind of decoder you mean? A tv-decoder? We do have a tv-decoder driver tw9910 under soc-camera.

static int soc_camera_s_input(struct file *file, void *priv, unsigned int i)

{
     if (i > 0)
        return -EINVAL;

    return 0;
}

I don't think most of tv-decoders only support one input.

#27 lore raw

Re: [PATCH 4/4] v4l2: add blackfin capture bridge driver

Quoted 9 lines · Scott Jiang
Quoted 9 lines
Quoted 2 lines

I have considered using soc, but it can't support decoder when I began to write this driver in 2.6.38.

soc_mediabus.c is a stand-alone module, it has no dependencies on soc-camera.

Out of interest - what kind of decoder you mean? A tv-decoder? We do have a tv-decoder driver tw9910 under soc-camera.

Quoted 8 lines

static int soc_camera_s_input(struct file *file, void *priv, unsigned int i)

{
     if (i > 0)
        return -EINVAL;

    return 0;
}

I don't think most of tv-decoders only support one input.

Ah:-) soc-camera is a living project, it's not set in stone. Until now we didn't have any need for more than one input, but as soon as such a need would arise, this would be changed in no time.

Thanks
Guennadi
---
Guennadi Liakhovetski, Ph.D.
Freelance Open-Source Software Developer
http://www.open-technology.de/

#28 lore raw

Re: [PATCH 4/4] v4l2: add blackfin capture bridge driver

In reply to Scott Jiang
Quoted 18 lines · Scott Jiang

2011/9/14 Sylwester Nawrocki<[email protected]>:

Quoted 17 lines · Scott Jiang
Quoted 16 lines
Quoted 16 lines
Quoted 16 lines
drivers/media/video/blackfin/bfin_capture.c new file +15 -0
+                     fmt =&bcap_formats[i];
+                     if (mbus_code)
+                             *mbus_code = fmt->mbus_code;
+                     if (bpp)
+                             *bpp = fmt->bpp;
+                     v4l2_fill_mbus_format(&mbus_fmt, pixfmt,
+                                             fmt->mbus_code);
+                     ret = v4l2_subdev_call(bcap->sd, video,
+                                             try_mbus_fmt,&mbus_fmt);
+                     if (ret<    0)
+                             return ret;
+                     v4l2_fill_pix_format(pixfmt,&mbus_fmt);
+                     pixfmt->bytesperline = pixfmt->width * fmt->bpp;
+                     pixfmt->sizeimage = pixfmt->bytesperline
+                                             * pixfmt->height;

No need to clamp mbus_fmt.width and mbus_fmt.height to some maximum values to prevent allocating huge memory buffers ?

Quoted 22 lines
Quoted 22 lines
Quoted 10 lines
Quoted 3 lines

Still pixfmt->pixelformat isn't filled.

no here pixfmt->pixelformat is passed in

Quoted 5 lines
Quoted 4 lines
drivers/media/video/blackfin/bfin_capture.c new file +4 -0
+                     return 0;
+             }
+     }
+     return -EINVAL;
Quoted 7 lines
Quoted 4 lines

I think you should return some default format, rather than giving up when the fourcc doesn't match. However I'm not 100% sure this is the specification requirement.

no, there is no default format for bridge driver because it knows nothing about this.
all the format info bridge needs ask subdevice.

It's the bridge driver that exports a device node and is responsible for setting the default format. It should be possible to start streaming right after opening the device, without VIDIOC_S_FMT, with some reasonable defaults.

Quoted 8 lines
Quoted 3 lines

If, as you say, the bridge knows nothing about formats what the bcap_formats[] array is here for ?

accually this array is to convert mbus to pixformat. ppi supports any formats. Ideally it should contain all formats in v4l2, but it is enough at present for our platform.
If I find someone needs more, I will add it.
So return -EINVAL means this format is out of range, it can't be supported now.

Ok, fair enough. I guess you rely on subdev driver to return some supported value through mbus_try_fmt and then the bridge driver must be able to handle this. However it might make sense to validate the resolution in some places to prevent allocating insanely huge buffers, when the sensor subdev misbehaves.

Quoted 4 lines

about default format, I think I can only call bcap_g_fmt_vid_cap in probe to get this info.
Dose anybody have a better solution?

How about doing that when device is opened for the first time ? However it could make more sense to try to set format at the subdev and then check how it was adjusted. Not all subdevs might implement g_mbus_fmt op or some might not deliver sane default values.

#29 lore raw

Re: [PATCH 4/4] v4l2: add blackfin capture bridge driver

2011/9/16 Sylwester Nawrocki <[email protected]>:

Quoted 54 lines · Scott Jiang
Quoted 18 lines

2011/9/14 Sylwester Nawrocki<[email protected]>:

Quoted 17 lines · Scott Jiang
Quoted 16 lines
Quoted 16 lines
Quoted 16 lines

+                     fmt =&bcap_formats[i];
+                     if (mbus_code)
+                             *mbus_code = fmt->mbus_code;
+                     if (bpp)
+                             *bpp = fmt->bpp;
+                     v4l2_fill_mbus_format(&mbus_fmt, pixfmt,
+                                             fmt->mbus_code);
+                     ret = v4l2_subdev_call(bcap->sd, video,
+                                             try_mbus_fmt,&mbus_fmt);
+                     if (ret<    0)
+                             return ret;
+                     v4l2_fill_pix_format(pixfmt,&mbus_fmt);
+                     pixfmt->bytesperline = pixfmt->width * fmt->bpp;
+                     pixfmt->sizeimage = pixfmt->bytesperline
+                                             * pixfmt->height;

No need to clamp mbus_fmt.width and mbus_fmt.height to some maximum values to prevent allocating huge memory buffers ?

Quoted 22 lines
Quoted 22 lines
Quoted 10 lines
Quoted 3 lines

Still pixfmt->pixelformat isn't filled.

no here pixfmt->pixelformat is passed in

Quoted 5 lines
Quoted 4 lines

+                     return 0;
+             }
+     }
+     return -EINVAL;

Quoted 7 lines
Quoted 4 lines

I think you should return some default format, rather than giving up when the fourcc doesn't match. However I'm not 100% sure this is the specification requirement.

no, there is no default format for bridge driver because it knows nothing about this.
all the format info bridge needs ask subdevice.

It's the bridge driver that exports a device node and is responsible for setting the default format. It should be possible to start streaming right after opening the device, without VIDIOC_S_FMT, with some reasonable defaults.

Quoted 8 lines
Quoted 3 lines

If, as you say, the bridge knows nothing about formats what the bcap_formats[] array is here for ?

accually this array is to convert mbus to pixformat. ppi supports any formats. Ideally it should contain all formats in v4l2, but it is enough at present for our platform.
If I find someone needs more, I will add it.
So return -EINVAL means this format is out of range, it can't be supported now.

Quoted 5 lines

Ok, fair enough. I guess you rely on subdev driver to return some supported value through mbus_try_fmt and then the bridge driver must be able to handle this. However it might make sense to validate the resolution in some places to prevent allocating insanely huge buffers, when the sensor subdev misbehaves.

all the format info is got from sensor, so it isn't out of control

Quoted 7 lines
Quoted 4 lines

about default format, I think I can only call bcap_g_fmt_vid_cap in probe to get this info.
Dose anybody have a better solution?

How about doing that when device is opened for the first time ?

no, different input and std has different default format, so I think there is no default format is a good choice.
app should negotiate format before use. I'm not sure all the v4l2 app will do this step.
v4l2 spec only says driver must implement xx ioctl, but it doesn't say app must call xx ioctl.
Anyone can tell me how many steps app must call?

Quoted 5 lines

However it
could make more sense to try to set format at the subdev and then check how it was adjusted. Not all subdevs might implement g_mbus_fmt op or some might not deliver sane default values.

in try_format and s_fmt I have implemented this in bridge driver and all my sensor drivers have implemented relative callback.

#30 lore raw

Re: [PATCH 4/4] v4l2: add blackfin capture bridge driver

Quoted 69 lines · Scott Jiang

2011/9/16 Sylwester Nawrocki <[email protected]>:

Quoted 54 lines · Scott Jiang
Quoted 18 lines

2011/9/14 Sylwester Nawrocki<[email protected]>:

Quoted 17 lines · Scott Jiang
Quoted 16 lines
Quoted 16 lines
Quoted 16 lines

+                     fmt =&bcap_formats[i];
+                     if (mbus_code)
+                             *mbus_code = fmt->mbus_code;
+                     if (bpp)
+                             *bpp = fmt->bpp;
+                     v4l2_fill_mbus_format(&mbus_fmt, pixfmt,
+                                             fmt->mbus_code);
+                     ret = v4l2_subdev_call(bcap->sd, video,
+                                             try_mbus_fmt,&mbus_fmt);
+                     if (ret<    0)
+                             return ret;
+                     v4l2_fill_pix_format(pixfmt,&mbus_fmt);
+                     pixfmt->bytesperline = pixfmt->width * fmt->bpp;
+                     pixfmt->sizeimage = pixfmt->bytesperline
+                                             * pixfmt->height;

No need to clamp mbus_fmt.width and mbus_fmt.height to some maximum values to prevent allocating huge memory buffers ?

Quoted 22 lines
Quoted 22 lines
Quoted 10 lines
Quoted 3 lines

Still pixfmt->pixelformat isn't filled.

no here pixfmt->pixelformat is passed in

Quoted 5 lines
Quoted 4 lines

+                     return 0;
+             }
+     }
+     return -EINVAL;

Quoted 7 lines
Quoted 4 lines

I think you should return some default format, rather than giving up when the fourcc doesn't match. However I'm not 100% sure this is the specification requirement.

no, there is no default format for bridge driver because it knows nothing about this.
all the format info bridge needs ask subdevice.

It's the bridge driver that exports a device node and is responsible for setting the default format. It should be possible to start streaming right after opening the device, without VIDIOC_S_FMT, with some reasonable defaults.

Quoted 8 lines
Quoted 3 lines

If, as you say, the bridge knows nothing about formats what the bcap_formats[] array is here for ?

accually this array is to convert mbus to pixformat. ppi supports any formats. Ideally it should contain all formats in v4l2, but it is enough at present for our platform.
If I find someone needs more, I will add it.
So return -EINVAL means this format is out of range, it can't be supported now.

Quoted 5 lines

Ok, fair enough. I guess you rely on subdev driver to return some supported value through mbus_try_fmt and then the bridge driver must be able to handle this. However it might make sense to validate the resolution in some places to prevent allocating insanely huge buffers, when the sensor subdev misbehaves.

all the format info is got from sensor, so it isn't out of control

Quoted 7 lines
Quoted 4 lines

about default format, I think I can only call bcap_g_fmt_vid_cap in probe to get this info.
Dose anybody have a better solution?

How about doing that when device is opened for the first time ?

Quoted 7 lines

no, different input and std has different default format, so I think there is no default format is a good choice.
app should negotiate format before use. I'm not sure all the v4l2 app will do this step.
v4l2 spec only says driver must implement xx ioctl, but it doesn't say app must call xx ioctl.
Anyone can tell me how many steps app must call?

IIRC, the user shall be able to open a v4l2 device, queue buffers and start streaming - without setting any format.

Quoted 7 lines
Quoted 5 lines

However it
could make more sense to try to set format at the subdev and then check how it was adjusted. Not all subdevs might implement g_mbus_fmt op or some might not deliver sane default values.

in try_format and s_fmt I have implemented this in bridge driver and all my sensor drivers have implemented relative callback.

Thanks
Guennadi
---
Guennadi Liakhovetski, Ph.D.
Freelance Open-Source Software Developer
http://www.open-technology.de/

#31 lore raw

Re: [PATCH 4/4] v4l2: add blackfin capture bridge driver

In reply to Sylwester Nawrocki
Quoted 13 lines · On Wednesday, September 14, 2011 16:30:47 Sylwester Nawrocki wrote:
Quoted 12 lines · Scott Jiang
Quoted 12 lines

drivers/media/video/blackfin/bfin_capture.c line 425

Quoted 9 lines
drivers/media/video/blackfin/bfin_capture.c new file +9 -0
+static int bcap_qbuf(struct file *file, void *priv,
+                     struct v4l2_buffer *buf)
+{
+     struct bcap_device *bcap_dev = video_drvdata(file);
+     struct v4l2_fh *fh = file->private_data;
+     struct bcap_fh *bcap_fh = container_of(fh, struct bcap_fh, fh);
+
+     if (!bcap_fh->io_allowed)
+             return -EACCES;

I suppose -EBUSY would be more appropriate here.

Quoted 5 lines
Quoted 1 line

no, io_allowed is to control which file instance has the right to do I/O.

Looks like you are doing here what the v4l2 priority mechanism is meant for. Have you considered the access priority (VIDIOC_G_PRIORITY/VIDIOC_S_PRIORITY and friends)? Does it have any shortcomings?

Sylwester, the priority handling doesn't take care of this particular case.

When it comes to streaming you need to administrate which filehandle started the streaming and block any other filehandle from interfering with that.

This check should really be done in vb2.

Regards,

Hans

#32 lore raw

Re: [PATCH 4/4] v4l2: add blackfin capture bridge driver

Hello Hans,

Quoted 20 lines · Hans Verkuil
Quoted 13 lines · On Wednesday, September 14, 2011 16:30:47 Sylwester Nawrocki wrote:
Quoted 12 lines · Scott Jiang
Quoted 12 lines

drivers/media/video/blackfin/bfin_capture.c line 425

Quoted 9 lines
drivers/media/video/blackfin/bfin_capture.c new file +9 -0
+static int bcap_qbuf(struct file *file, void *priv,
+                     struct v4l2_buffer *buf)
+{
+     struct bcap_device *bcap_dev = video_drvdata(file);
+     struct v4l2_fh *fh = file->private_data;
+     struct bcap_fh *bcap_fh = container_of(fh, struct bcap_fh, fh);
+
+     if (!bcap_fh->io_allowed)
+             return -EACCES;

I suppose -EBUSY would be more appropriate here.

Quoted 5 lines
Quoted 1 line

no, io_allowed is to control which file instance has the right to do I/O.

Looks like you are doing here what the v4l2 priority mechanism is meant for. Have you considered the access priority (VIDIOC_G_PRIORITY/VIDIOC_S_PRIORITY and friends)? Does it have any shortcomings?

Quoted 6 lines

Sylwester, the priority handling doesn't take care of this particular case.

When it comes to streaming you need to administrate which filehandle started the streaming and block any other filehandle from interfering with that.

This check should really be done in vb2.

True, I've noticed QBUF/DQBUF are not touched by the priority handling. Perhaps I didn't follow the discussions in this topic carefully enough.

Then we seem to have another feature request for vb2.

--
Thanks,
Sylwester

#33 lore raw

Re: [uclinux-dist-devel] [PATCH 4/4] v4l2: add blackfin capture bridge driver

In reply to Scott Jiang

drivers/media/video/blackfin/Kconfig line 4

Quoted 7 lines · Scott Jiang
drivers/media/video/blackfin/Kconfig new file +4 -0
@@ -0,0 +1,10 @@
+config VIDEO_BLACKFIN_CAPTURE
+       tristate "Blackfin Video Capture Driver"
+       depends on VIDEO_DEV && BLACKFIN
+       select VIDEOBUF2_DMA_CONTIG

since the code needs i2c, this needs to list I2C under depends

drivers/media/video/blackfin/bfin_capture.c line 36

Quoted 6 lines
drivers/media/video/blackfin/bfin_capture.c new file +3 -0
 
+#include <linux/moduleparam.h>
+#include <linux/version.h>
+#include <linux/clk.h>

i think at least these three are unused and should get punted

drivers/media/video/blackfin/bfin_capture.c line 929

Quoted 5 lines
drivers/media/video/blackfin/bfin_capture.c new file +5 -0
+static int __devinit bcap_probe(struct platform_device *pdev)
+{
+       struct bcap_device *bcap_dev;
+       struct video_device *vfd;
+       struct i2c_adapter *i2c_adap;

you need to include linux/i2c.h for this

drivers/media/video/blackfin/bfin_capture.c line 1082

Quoted 8 lines
drivers/media/video/blackfin/bfin_capture.c new file +8 -0
+static struct platform_driver bcap_driver = {
+       .driver = {
+               .name   = CAPTURE_DRV_NAME,
+               .owner = THIS_MODULE,
+       },
+       .probe = bcap_probe,
+       .remove = __devexit_p(bcap_remove),
+};

no suspend/resume ? :)

Quoted 1 line

+MODULE_DESCRIPTION("Analog Devices video capture driver");

should mention the device part name in the desc

drivers/media/video/blackfin/ppi.c line 200

Quoted 5 lines
drivers/media/video/blackfin/ppi.c new file +2 -0
 
+struct ppi_if *create_ppi_instance(const struct ppi_info *info)
+void delete_ppi_instance(struct ppi_if *ppi)

should be ppi_{create,delete}_instance to match existing ppi_xxx style -mike

#34 lore raw

Re: [uclinux-dist-devel] [PATCH 4/4] v4l2: add blackfin capture bridge driver

Quoted 10 lines

i think at least these three are unused and should get punted

drivers/media/video/blackfin/bfin_capture.c line 929

Quoted 5 lines
drivers/media/video/blackfin/bfin_capture.c new file +5 -0
+static int __devinit bcap_probe(struct platform_device *pdev)
+{
+       struct bcap_device *bcap_dev;
+       struct video_device *vfd;
+       struct i2c_adapter *i2c_adap;

you need to include linux/i2c.h for this

no, bfin_capture.h already contains this.

#35 lore raw

Re: [uclinux-dist-devel] [PATCH 4/4] v4l2: add blackfin capture bridge driver

Quoted 11 lines · Scott Jiang
Quoted 10 lines

i think at least these three are unused and should get punted

drivers/media/video/blackfin/bfin_capture.c line 929

Quoted 5 lines
drivers/media/video/blackfin/bfin_capture.c new file +5 -0
+static int __devinit bcap_probe(struct platform_device *pdev)
+{
+       struct bcap_device *bcap_dev;
+       struct video_device *vfd;
+       struct i2c_adapter *i2c_adap;

you need to include linux/i2c.h for this

no, bfin_capture.h already contains this.

It doesn't matter. You're supposed to _explicitly_ include every header, that is required to build your code.

Thanks
Guennadi
---
Guennadi Liakhovetski, Ph.D.
Freelance Open-Source Software Developer
http://www.open-technology.de/

#36 lore raw

Re: [PATCH 4/4] v4l2: add blackfin capture bridge driver

In reply to Scott Jiang

One more clean-up possibility:

Quoted 5 lines · Scott Jiang

this is a v4l2 bridge driver for Blackfin video capture device, support ppi interface

---

[snip]

Quoted 6 lines
drivers/media/video/blackfin/bfin_capture.c new file +0 -0
new file mode 100644
index 0000000..24f89f2
@@ -0,0 +1,1099 @@

[snip]

Quoted 56 lines
drivers/media/video/blackfin/bfin_capture.c new file +56 -0
+static int __devinit bcap_probe(struct platform_device *pdev)
+{
+	struct bcap_device *bcap_dev;
+	struct video_device *vfd;
+	struct i2c_adapter *i2c_adap;
+	struct bfin_capture_config *config;
+	struct vb2_queue *q;
+	int ret;
+
+	config = pdev->dev.platform_data;
+	if (!config) {
+		v4l2_err(pdev->dev.driver, "Unable to get board config\n");
+		return -ENODEV;
+	}
+
+	bcap_dev = kzalloc(sizeof(*bcap_dev), GFP_KERNEL);
+	if (!bcap_dev) {
+		v4l2_err(pdev->dev.driver, "Unable to alloc bcap_dev\n");
+		return -ENOMEM;
+	}
+
+	bcap_dev->cfg = config;
+
+	bcap_dev->ppi = create_ppi_instance(config->ppi_info);
+	if (!bcap_dev->ppi) {
+		v4l2_err(pdev->dev.driver, "Unable to create ppi\n");
+		ret = -ENODEV;
+		goto err_free_dev;
+	}
+	bcap_dev->ppi->priv = bcap_dev;
+
+	bcap_dev->alloc_ctx = vb2_dma_contig_init_ctx(&pdev->dev);
+	if (IS_ERR(bcap_dev->alloc_ctx)) {
+		ret = PTR_ERR(bcap_dev->alloc_ctx);
+		goto err_free_ppi;
+	}
+
+	vfd = video_device_alloc();
+	if (!vfd) {
+		ret = -ENOMEM;
+		v4l2_err(pdev->dev.driver, "Unable to alloc video device\n");
+		goto err_cleanup_ctx;
+	}
+
+	/* initialize field of video device */
+	vfd->release            = video_device_release;
+	vfd->fops               = &bcap_fops;
+	vfd->ioctl_ops          = &bcap_ioctl_ops;
+	vfd->tvnorms            = 0;
+	vfd->v4l2_dev           = &bcap_dev->v4l2_dev;
+	set_bit(V4L2_FL_USE_FH_PRIO, &vfd->flags);
+	strncpy(vfd->name, CAPTURE_DRV_NAME, sizeof(vfd->name));
+	bcap_dev->video_dev     = vfd;
+
+	ret = v4l2_device_register(&pdev->dev, &bcap_dev->v4l2_dev);
+	if (ret) {

drivers/media/video/blackfin/bfin_capture.c line 990

Quoted 10 lines
drivers/media/video/blackfin/bfin_capture.c new file +10 -0
+		v4l2_err(pdev->dev.driver,
+				"Unable to register v4l2 device\n");
+		goto err_release_vdev;
+	}
+	v4l2_info(&bcap_dev->v4l2_dev, "v4l2 device registered\n");
+
+	spin_lock_init(&bcap_dev->lock);
+	/* initialize queue */
+	q = &bcap_dev->buffer_queue;
+	memset(q, 0, sizeof(*q));

This is superfluous: bcap_dev is allocated with kzalloc().

Thanks
Guennadi
---
Guennadi Liakhovetski, Ph.D.
Freelance Open-Source Software Developer
http://www.open-technology.de/

#37 lore raw
In reply to Scott Jiang
Quoted 35 lines · Scott Jiang

no mmu system needs get_unmapped_area file operations to do mmap

---
 drivers/media/video/videobuf2-core.c |   31 +++++++++++++++++++++++++++++++
 include/media/videobuf2-core.h       |    7 +++++++
 2 files changed, 38 insertions(+), 0 deletions(-)
drivers/media/video/videobuf2-core.c +19 -0
index 3015e60..02a0ec6 100644
@@ -1344,6 +1344,37 @@ int vb2_mmap(struct vb2_queue *q, struct vm_area_struct *vma)
 }
 EXPORT_SYMBOL_GPL(vb2_mmap);
 
+#ifndef CONFIG_MMU
+unsigned long vb2_get_unmapped_area(struct vb2_queue *q,
+				    unsigned long addr,
+				    unsigned long len,
+				    unsigned long pgoff,
+				    unsigned long flags)
+{
+	unsigned long off = pgoff << PAGE_SHIFT;
+	struct vb2_buffer *vb;
+	unsigned int buffer, plane;
+	int ret;
+
+	if (q->memory != V4L2_MEMORY_MMAP) {
+		dprintk(1, "Queue is not currently set up for mmap\n");
+		return -EINVAL;
+	}
+
+	/*
+	 * Find the plane corresponding to the offset passed by userspace.

drivers/media/video/videobuf2-core.c int vb2_mmap(struct vb2_queue *q, struct vm_area_struct *vma) · line 1375

Quoted 10 lines
drivers/media/video/videobuf2-core.c +10 -0
+	 */
+	ret = __find_plane_by_offset(q, off, &buffer, &plane);
+	if (ret)
+		return ret;
+
+	vb = q->bufs[buffer];
+
+	return (unsigned long)vb2_plane_vaddr(vb, plane);
+}
+EXPORT_SYMBOL_GPL(vb2_get_unmapped_area);

Hm, wouldn't it be better to use vb2_mmap() and provide a dummy .mmap() method in videobuf2-dma-contig.c for the NOMMU case?

Thanks
Guennadi

Quoted 27 lines
drivers/media/video/videobuf2-core.c +2 -0
+#endif
+
 static int __vb2_init_fileio(struct vb2_queue *q, int read);
 static int __vb2_cleanup_fileio(struct vb2_queue *q);
 
include/media/videobuf2-core.h +7 -0
index f87472a..5c7b5b4 100644
@@ -302,6 +302,13 @@ int vb2_streamon(struct vb2_queue *q, enum v4l2_buf_type type);
 int vb2_streamoff(struct vb2_queue *q, enum v4l2_buf_type type);
 
 int vb2_mmap(struct vb2_queue *q, struct vm_area_struct *vma);
+#ifndef CONFIG_MMU
+unsigned long vb2_get_unmapped_area(struct vb2_queue *q,
+				    unsigned long addr,
+				    unsigned long len,
+				    unsigned long pgoff,
+				    unsigned long flags);
+#endif
 unsigned int vb2_poll(struct vb2_queue *q, struct file *file, poll_table *wait);
 size_t vb2_read(struct vb2_queue *q, char __user *data, size_t count,
 		loff_t *ppos, int nonblock);
Signature · 1 line
1.7.0.4

---
Guennadi Liakhovetski, Ph.D.
Freelance Open-Source Software Developer
http://www.open-technology.de/

#38 lore raw
Quoted 4 lines

Hm, wouldn't it be better to use vb2_mmap() and provide a dummy .mmap() method in videobuf2-dma-contig.c for the NOMMU case?

these are two different file operations called by mm system.