1 From 19c1ada1c282d61163b6a24a6ee53517caec094c Mon Sep 17 00:00:00 2001
2 From: Vincent Sanders <vincent.sanders@collabora.co.uk>
3 Date: Wed, 30 Jan 2013 12:45:18 +0000
4 Subject: [PATCH 027/114] bcm2835: add v4l2 camera device
6 - Supports raw YUV capture, preview, JPEG and H264.
7 - Uses videobuf2 for data transfer, using dma_buf.
8 - Uses 3.6.10 timestamping
9 - Camera power based on use
10 - Uses immutable input mode on video encoder
12 Signed-off-by: Daniel Stone <daniels@collabora.com>
13 Signed-off-by: Luke Diamand <luked@broadcom.com>
15 Documentation/video4linux/bcm2835-v4l2.txt | 60 +
16 drivers/media/platform/Kconfig | 1 +
17 drivers/media/platform/Makefile | 2 +
18 drivers/media/platform/bcm2835/Kconfig | 25 +
19 drivers/media/platform/bcm2835/Makefile | 5 +
20 drivers/media/platform/bcm2835/bcm2835-camera.c | 1476 +++++++++++++++++
21 drivers/media/platform/bcm2835/bcm2835-camera.h | 113 ++
22 drivers/media/platform/bcm2835/controls.c | 725 ++++++++
23 drivers/media/platform/bcm2835/mmal-common.h | 51 +
24 drivers/media/platform/bcm2835/mmal-encodings.h | 93 ++
25 drivers/media/platform/bcm2835/mmal-msg-common.h | 50 +
26 drivers/media/platform/bcm2835/mmal-msg-format.h | 81 +
27 drivers/media/platform/bcm2835/mmal-msg-port.h | 107 ++
28 drivers/media/platform/bcm2835/mmal-msg.h | 404 +++++
29 drivers/media/platform/bcm2835/mmal-parameters.h | 539 ++++++
30 drivers/media/platform/bcm2835/mmal-vchiq.c | 1916 ++++++++++++++++++++++
31 drivers/media/platform/bcm2835/mmal-vchiq.h | 178 ++
32 17 files changed, 5826 insertions(+)
33 create mode 100644 Documentation/video4linux/bcm2835-v4l2.txt
34 create mode 100644 drivers/media/platform/bcm2835/Kconfig
35 create mode 100644 drivers/media/platform/bcm2835/Makefile
36 create mode 100644 drivers/media/platform/bcm2835/bcm2835-camera.c
37 create mode 100644 drivers/media/platform/bcm2835/bcm2835-camera.h
38 create mode 100644 drivers/media/platform/bcm2835/controls.c
39 create mode 100644 drivers/media/platform/bcm2835/mmal-common.h
40 create mode 100644 drivers/media/platform/bcm2835/mmal-encodings.h
41 create mode 100644 drivers/media/platform/bcm2835/mmal-msg-common.h
42 create mode 100644 drivers/media/platform/bcm2835/mmal-msg-format.h
43 create mode 100644 drivers/media/platform/bcm2835/mmal-msg-port.h
44 create mode 100644 drivers/media/platform/bcm2835/mmal-msg.h
45 create mode 100644 drivers/media/platform/bcm2835/mmal-parameters.h
46 create mode 100644 drivers/media/platform/bcm2835/mmal-vchiq.c
47 create mode 100644 drivers/media/platform/bcm2835/mmal-vchiq.h
49 diff --git a/Documentation/video4linux/bcm2835-v4l2.txt b/Documentation/video4linux/bcm2835-v4l2.txt
51 index 0000000..c585a8f
53 +++ b/Documentation/video4linux/bcm2835-v4l2.txt
56 +BCM2835 (aka Raspberry Pi) V4L2 driver
57 +======================================
62 +Copyright © 2013 Raspberry Pi (Trading) Ltd.
67 +This program is free software; you can redistribute it and/or modify
68 +it under the terms of the GNU General Public License as published by
69 +the Free Software Foundation; either version 2 of the License, or
70 +(at your option) any later version.
72 +This program is distributed in the hope that it will be useful,
73 +but WITHOUT ANY WARRANTY; without even the implied warranty of
74 +MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
75 +GNU General Public License for more details.
77 +You should have received a copy of the GNU General Public License
78 +along with this program; if not, write to the Free Software
79 +Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
84 +You need a version 1.0 or later of v4l2-ctl, available from:
85 + git://git.linuxtv.org/v4l-utils.git
87 +$ sudo modprobe bcm2835-v4l2
91 +$ v4l2-ctl --overlay=1
93 +Turn off the overlay:
95 +$ v4l2-ctl --overlay=0
97 +Set the capture format for video:
99 +$ v4l2-ctl --set-fmt-video=width=1920,height=1088,pixelformat=4
101 +(Note: 1088 not 1080).
105 +$ v4l2-ctl --stream-mmap=3 --stream-count=100 --stream-to=somefile.h264
109 +$ v4l2-ctl --set-fmt-video=width=2592,height=1944,pixelformat=3
110 +$ v4l2-ctl --stream-mmap=3 --stream-count=1 --stream-to=somefile.jpg
112 +List of available formats:
114 +$ v4l2-ctl --list-formats
115 diff --git a/drivers/media/platform/Kconfig b/drivers/media/platform/Kconfig
116 index 3aac88f..9bc18aa 100644
117 --- a/drivers/media/platform/Kconfig
118 +++ b/drivers/media/platform/Kconfig
119 @@ -126,6 +126,7 @@ config VIDEO_S3C_CAMIF
120 source "drivers/media/platform/soc_camera/Kconfig"
121 source "drivers/media/platform/exynos4-is/Kconfig"
122 source "drivers/media/platform/s5p-tv/Kconfig"
123 +source "drivers/media/platform/bcm2835/Kconfig"
125 endif # V4L_PLATFORM_DRIVERS
127 diff --git a/drivers/media/platform/Makefile b/drivers/media/platform/Makefile
128 index 579046b..9c9cb34 100644
129 --- a/drivers/media/platform/Makefile
130 +++ b/drivers/media/platform/Makefile
131 @@ -49,4 +49,6 @@ obj-$(CONFIG_VIDEO_RENESAS_VSP1) += vsp1/
135 +obj-$(CONFIG_VIDEO_BCM2835) += bcm2835/
137 ccflags-y += -I$(srctree)/drivers/media/i2c
138 diff --git a/drivers/media/platform/bcm2835/Kconfig b/drivers/media/platform/bcm2835/Kconfig
140 index 0000000..a8fd172
142 +++ b/drivers/media/platform/bcm2835/Kconfig
144 +# Broadcom VideoCore IV v4l2 camera support
146 +config VIDEO_BCM2835
147 + bool "Broadcom BCM2835 camera interface driver"
148 + depends on VIDEO_V4L2 && ARCH_BCM2708
150 + Say Y here to enable camera host interface devices for
151 + Broadcom BCM2835 SoC. This operates over the VCHIQ interface
152 + to a service running on VideoCore.
157 +config VIDEO_BCM2835_MMAL
158 + tristate "Broadcom BM2835 MMAL camera interface driver"
159 + depends on BCM2708_VCHIQ
160 + select VIDEOBUF2_VMALLOC
162 + This is a V4L2 driver for the Broadcom BCM2835 MMAL camera host interface
164 + To compile this driver as a module, choose M here: the
165 + module will be called bcm2835-v4l2.o
168 +endif # VIDEO_BM2835
169 diff --git a/drivers/media/platform/bcm2835/Makefile b/drivers/media/platform/bcm2835/Makefile
171 index 0000000..f17c79c
173 +++ b/drivers/media/platform/bcm2835/Makefile
175 +bcm2835-v4l2-objs := bcm2835-camera.o controls.o mmal-vchiq.o
177 +obj-$(CONFIG_VIDEO_BCM2835_MMAL) += bcm2835-v4l2.o
179 +ccflags-$(CONFIG_VIDEO_BCM2835) += -Idrivers/misc/vc04_services -Idrivers/misc/vc04_services/interface/vcos/linuxkernel -D__VCCOREVER__=0x04000000
180 diff --git a/drivers/media/platform/bcm2835/bcm2835-camera.c b/drivers/media/platform/bcm2835/bcm2835-camera.c
182 index 0000000..1c9d9d5
184 +++ b/drivers/media/platform/bcm2835/bcm2835-camera.c
187 + * Broadcom BM2835 V4L2 driver
189 + * Copyright © 2013 Raspberry Pi (Trading) Ltd.
191 + * This file is subject to the terms and conditions of the GNU General Public
192 + * License. See the file COPYING in the main directory of this archive
193 + * for more details.
195 + * Authors: Vincent Sanders <vincent.sanders@collabora.co.uk>
196 + * Dave Stevenson <dsteve@broadcom.com>
197 + * Simon Mellor <simellor@broadcom.com>
198 + * Luke Diamand <luked@broadcom.com>
201 +#include <linux/errno.h>
202 +#include <linux/kernel.h>
203 +#include <linux/module.h>
204 +#include <linux/slab.h>
205 +#include <media/videobuf2-vmalloc.h>
206 +#include <media/videobuf2-dma-contig.h>
207 +#include <media/v4l2-device.h>
208 +#include <media/v4l2-ioctl.h>
209 +#include <media/v4l2-ctrls.h>
210 +#include <media/v4l2-fh.h>
211 +#include <media/v4l2-event.h>
212 +#include <media/v4l2-common.h>
213 +#include <linux/delay.h>
215 +#include "mmal-common.h"
216 +#include "mmal-encodings.h"
217 +#include "mmal-vchiq.h"
218 +#include "mmal-msg.h"
219 +#include "mmal-parameters.h"
220 +#include "bcm2835-camera.h"
222 +#define BM2835_MMAL_VERSION "0.0.2"
223 +#define BM2835_MMAL_MODULE_NAME "bcm2835-v4l2"
225 +#define MAX_WIDTH 2592
226 +#define MAX_HEIGHT 1944
227 +#define MIN_BUFFER_SIZE (80*1024)
229 +#define MAX_VIDEO_MODE_WIDTH 1280
230 +#define MAX_VIDEO_MODE_HEIGHT 720
232 +MODULE_DESCRIPTION("Broadcom 2835 MMAL video capture");
233 +MODULE_AUTHOR("Vincent Sanders");
234 +MODULE_LICENSE("GPL");
235 +MODULE_VERSION(BM2835_MMAL_VERSION);
237 +int bcm2835_v4l2_debug;
238 +module_param_named(debug, bcm2835_v4l2_debug, int, 0644);
239 +MODULE_PARM_DESC(bcm2835_v4l2_debug, "Debug level 0-2");
241 +static struct bm2835_mmal_dev *gdev; /* global device data */
244 +static struct mmal_fmt formats[] = {
246 + .name = "4:2:0, packed YUV",
247 + .fourcc = V4L2_PIX_FMT_YUV420,
248 + .mmal = MMAL_ENCODING_I420,
250 + .mmal_component = MMAL_COMPONENT_CAMERA,
253 + .name = "4:2:2, packed, YUYV",
254 + .fourcc = V4L2_PIX_FMT_YUYV,
255 + .mmal = MMAL_ENCODING_YUYV,
257 + .mmal_component = MMAL_COMPONENT_CAMERA,
260 + .name = "RGB24 (BE)",
261 + .fourcc = V4L2_PIX_FMT_BGR24,
262 + .mmal = MMAL_ENCODING_BGR24,
264 + .mmal_component = MMAL_COMPONENT_CAMERA,
268 + .fourcc = V4L2_PIX_FMT_JPEG,
269 + .mmal = MMAL_ENCODING_JPEG,
271 + .mmal_component = MMAL_COMPONENT_IMAGE_ENCODE,
275 + .fourcc = V4L2_PIX_FMT_H264,
276 + .mmal = MMAL_ENCODING_H264,
278 + .mmal_component = MMAL_COMPONENT_VIDEO_ENCODE,
282 +static struct mmal_fmt *get_format(struct v4l2_format *f)
284 + struct mmal_fmt *fmt;
287 + for (k = 0; k < ARRAY_SIZE(formats); k++) {
289 + if (fmt->fourcc == f->fmt.pix.pixelformat)
293 + if (k == ARRAY_SIZE(formats))
296 + return &formats[k];
299 +/* ------------------------------------------------------------------
300 + Videobuf queue operations
301 + ------------------------------------------------------------------*/
303 +static int queue_setup(struct vb2_queue *vq, const struct v4l2_format *fmt,
304 + unsigned int *nbuffers, unsigned int *nplanes,
305 + unsigned int sizes[], void *alloc_ctxs[])
307 + struct bm2835_mmal_dev *dev = vb2_get_drv_priv(vq);
308 + unsigned long size;
310 + /* refuse queue setup if port is not configured */
311 + if (dev->capture.port == NULL) {
312 + v4l2_err(&dev->v4l2_dev,
313 + "%s: capture port not configured\n", __func__);
317 + size = dev->capture.port->current_buffer.size;
319 + v4l2_err(&dev->v4l2_dev,
320 + "%s: capture port buffer size is zero\n", __func__);
324 + if (*nbuffers < (dev->capture.port->current_buffer.num + 2))
325 + *nbuffers = (dev->capture.port->current_buffer.num + 2);
332 + * videobuf2-vmalloc allocator is context-less so no need to set
333 + * alloc_ctxs array.
336 + v4l2_dbg(1, bcm2835_v4l2_debug, &dev->v4l2_dev, "%s: dev:%p\n",
342 +static int buffer_prepare(struct vb2_buffer *vb)
344 + struct bm2835_mmal_dev *dev = vb2_get_drv_priv(vb->vb2_queue);
345 + unsigned long size;
347 + v4l2_dbg(1, bcm2835_v4l2_debug, &dev->v4l2_dev, "%s: dev:%p\n",
350 + BUG_ON(dev->capture.port == NULL);
351 + BUG_ON(dev->capture.fmt == NULL);
353 + size = dev->capture.stride * dev->capture.height;
354 + if (vb2_plane_size(vb, 0) < size) {
355 + v4l2_err(&dev->v4l2_dev,
356 + "%s data will not fit into plane (%lu < %lu)\n",
357 + __func__, vb2_plane_size(vb, 0), size);
364 +static inline bool is_capturing(struct bm2835_mmal_dev *dev)
366 + return dev->capture.camera_port ==
368 + component[MMAL_COMPONENT_CAMERA]->output[MMAL_CAMERA_PORT_CAPTURE];
371 +static void buffer_cb(struct vchiq_mmal_instance *instance,
372 + struct vchiq_mmal_port *port,
374 + struct mmal_buffer *buf,
375 + unsigned long length, u32 mmal_flags, s64 dts, s64 pts)
377 + struct bm2835_mmal_dev *dev = port->cb_ctx;
379 + v4l2_dbg(1, bcm2835_v4l2_debug, &dev->v4l2_dev,
380 + "%s: status:%d, buf:%p, length:%lu, flags %u, pts %lld\n",
381 + __func__, status, buf, length, mmal_flags, pts);
384 + /* error in transfer */
386 + /* there was a buffer with the error so return it */
387 + vb2_buffer_done(&buf->vb, VB2_BUF_STATE_ERROR);
390 + } else if (length == 0) {
393 + /* this should only ever happen if the port is
394 + * disabled and there are buffers still queued
396 + vb2_buffer_done(&buf->vb, VB2_BUF_STATE_ERROR);
397 + pr_debug("Empty buffer");
398 + } else if (dev->capture.frame_count) {
399 + /* grab another frame */
400 + if (is_capturing(dev)) {
401 + pr_debug("Grab another frame");
402 + vchiq_mmal_port_parameter_set(
406 + MMAL_PARAMETER_CAPTURE,
409 + sizeof(dev->capture.frame_count));
412 + /* signal frame completion */
413 + complete(&dev->capture.frame_cmplt);
416 + if (dev->capture.frame_count) {
417 + if (dev->capture.vc_start_timestamp != -1) {
418 + s64 runtime_us = pts -
419 + dev->capture.vc_start_timestamp;
424 + div_u64_rem(runtime_us, USEC_PER_SEC, &rem);
425 + buf->vb.v4l2_buf.timestamp.tv_sec =
426 + dev->capture.kernel_start_ts.tv_sec - 1 +
428 + buf->vb.v4l2_buf.timestamp.tv_usec =
429 + dev->capture.kernel_start_ts.tv_usec + rem;
431 + if (buf->vb.v4l2_buf.timestamp.tv_usec >=
433 + buf->vb.v4l2_buf.timestamp.tv_sec++;
434 + buf->vb.v4l2_buf.timestamp.tv_usec -=
437 + v4l2_dbg(1, bcm2835_v4l2_debug, &dev->v4l2_dev,
438 + "Convert start time %d.%06d and %llu"
439 + "with offset %llu to %d.%06d\n",
440 + (int)dev->capture.kernel_start_ts.
442 + (int)dev->capture.kernel_start_ts.
444 + dev->capture.vc_start_timestamp, pts,
445 + (int)buf->vb.v4l2_buf.timestamp.tv_sec,
446 + (int)buf->vb.v4l2_buf.timestamp.
449 + v4l2_get_timestamp(&buf->vb.v4l2_buf.timestamp);
452 + vb2_set_plane_payload(&buf->vb, 0, length);
453 + vb2_buffer_done(&buf->vb, VB2_BUF_STATE_DONE);
455 + if (mmal_flags & MMAL_BUFFER_HEADER_FLAG_EOS &&
456 + is_capturing(dev)) {
457 + v4l2_dbg(1, bcm2835_v4l2_debug, &dev->v4l2_dev,
458 + "Grab another frame as buffer has EOS");
459 + vchiq_mmal_port_parameter_set(
463 + MMAL_PARAMETER_CAPTURE,
466 + sizeof(dev->capture.frame_count));
469 + /* signal frame completion */
470 + complete(&dev->capture.frame_cmplt);
475 +static int enable_camera(struct bm2835_mmal_dev *dev)
478 + if (!dev->camera_use_count) {
479 + ret = vchiq_mmal_component_enable(
481 + dev->component[MMAL_COMPONENT_CAMERA]);
483 + v4l2_err(&dev->v4l2_dev,
484 + "Failed enabling camera, ret %d\n", ret);
488 + dev->camera_use_count++;
489 + v4l2_dbg(1, bcm2835_v4l2_debug,
490 + &dev->v4l2_dev, "enabled camera (refcount %d)\n",
491 + dev->camera_use_count);
495 +static int disable_camera(struct bm2835_mmal_dev *dev)
498 + if (!dev->camera_use_count) {
499 + v4l2_err(&dev->v4l2_dev,
500 + "Disabled the camera when already disabled\n");
503 + dev->camera_use_count--;
504 + if (!dev->camera_use_count) {
505 + unsigned int i = 0xFFFFFFFF;
506 + v4l2_dbg(1, bcm2835_v4l2_debug, &dev->v4l2_dev,
507 + "Disabling camera\n");
509 + vchiq_mmal_component_disable(
511 + dev->component[MMAL_COMPONENT_CAMERA]);
513 + v4l2_err(&dev->v4l2_dev,
514 + "Failed disabling camera, ret %d\n", ret);
517 + vchiq_mmal_port_parameter_set(
519 + &dev->component[MMAL_COMPONENT_CAMERA]->control,
520 + MMAL_PARAMETER_CAMERA_NUM, &i,
523 + v4l2_dbg(1, bcm2835_v4l2_debug, &dev->v4l2_dev,
524 + "Camera refcount now %d\n", dev->camera_use_count);
528 +static void buffer_queue(struct vb2_buffer *vb)
530 + struct bm2835_mmal_dev *dev = vb2_get_drv_priv(vb->vb2_queue);
531 + struct mmal_buffer *buf = container_of(vb, struct mmal_buffer, vb);
534 + v4l2_dbg(1, bcm2835_v4l2_debug, &dev->v4l2_dev,
535 + "%s: dev:%p buf:%p\n", __func__, dev, buf);
537 + buf->buffer = vb2_plane_vaddr(&buf->vb, 0);
538 + buf->buffer_size = vb2_plane_size(&buf->vb, 0);
540 + ret = vchiq_mmal_submit_buffer(dev->instance, dev->capture.port, buf);
542 + v4l2_err(&dev->v4l2_dev, "%s: error submitting buffer\n",
546 +static int start_streaming(struct vb2_queue *vq, unsigned int count)
548 + struct bm2835_mmal_dev *dev = vb2_get_drv_priv(vq);
550 + int parameter_size;
552 + v4l2_dbg(1, bcm2835_v4l2_debug, &dev->v4l2_dev, "%s: dev:%p\n",
555 + /* ensure a format has actually been set */
556 + if (dev->capture.port == NULL)
559 + if (enable_camera(dev) < 0) {
560 + v4l2_err(&dev->v4l2_dev, "Failed to enable camera\n");
564 + /*init_completion(&dev->capture.frame_cmplt); */
566 + /* enable frame capture */
567 + dev->capture.frame_count = 1;
569 + /* if the preview is not already running, wait for a few frames for AGC
572 + if (!dev->component[MMAL_COMPONENT_PREVIEW]->enabled)
575 + /* enable the connection from camera to encoder (if applicable) */
576 + if (dev->capture.camera_port != dev->capture.port
577 + && dev->capture.camera_port) {
578 + ret = vchiq_mmal_port_enable(dev->instance,
579 + dev->capture.camera_port, NULL);
581 + v4l2_err(&dev->v4l2_dev,
582 + "Failed to enable encode tunnel - error %d\n",
588 + /* Get VC timestamp at this point in time */
589 + parameter_size = sizeof(dev->capture.vc_start_timestamp);
590 + if (vchiq_mmal_port_parameter_get(dev->instance,
591 + dev->capture.camera_port,
592 + MMAL_PARAMETER_SYSTEM_TIME,
593 + &dev->capture.vc_start_timestamp,
594 + ¶meter_size)) {
595 + v4l2_err(&dev->v4l2_dev,
596 + "Failed to get VC start time - update your VC f/w\n");
598 + /* Flag to indicate just to rely on kernel timestamps */
599 + dev->capture.vc_start_timestamp = -1;
601 + v4l2_dbg(1, bcm2835_v4l2_debug, &dev->v4l2_dev,
602 + "Start time %lld size %d\n",
603 + dev->capture.vc_start_timestamp, parameter_size);
605 + v4l2_get_timestamp(&dev->capture.kernel_start_ts);
607 + /* enable the camera port */
608 + dev->capture.port->cb_ctx = dev;
610 + vchiq_mmal_port_enable(dev->instance, dev->capture.port, buffer_cb);
612 + v4l2_err(&dev->v4l2_dev,
613 + "Failed to enable capture port - error %d\n", ret);
617 + /* capture the first frame */
618 + vchiq_mmal_port_parameter_set(dev->instance,
619 + dev->capture.camera_port,
620 + MMAL_PARAMETER_CAPTURE,
621 + &dev->capture.frame_count,
622 + sizeof(dev->capture.frame_count));
626 +/* abort streaming and wait for last buffer */
627 +static int stop_streaming(struct vb2_queue *vq)
630 + struct bm2835_mmal_dev *dev = vb2_get_drv_priv(vq);
632 + v4l2_dbg(1, bcm2835_v4l2_debug, &dev->v4l2_dev, "%s: dev:%p\n",
635 + init_completion(&dev->capture.frame_cmplt);
636 + dev->capture.frame_count = 0;
638 + /* ensure a format has actually been set */
639 + if (dev->capture.port == NULL)
642 + v4l2_dbg(1, bcm2835_v4l2_debug, &dev->v4l2_dev, "stopping capturing\n");
644 + /* stop capturing frames */
645 + vchiq_mmal_port_parameter_set(dev->instance,
646 + dev->capture.camera_port,
647 + MMAL_PARAMETER_CAPTURE,
648 + &dev->capture.frame_count,
649 + sizeof(dev->capture.frame_count));
651 + /* wait for last frame to complete */
652 + ret = wait_for_completion_timeout(&dev->capture.frame_cmplt, HZ);
654 + v4l2_err(&dev->v4l2_dev,
655 + "error %d waiting for frame completion\n", ret);
657 + v4l2_dbg(1, bcm2835_v4l2_debug, &dev->v4l2_dev,
658 + "disabling connection\n");
660 + /* disable the connection from camera to encoder */
661 + ret = vchiq_mmal_port_disable(dev->instance, dev->capture.camera_port);
662 + if (!ret && dev->capture.camera_port != dev->capture.port) {
663 + v4l2_dbg(1, bcm2835_v4l2_debug, &dev->v4l2_dev,
664 + "disabling port\n");
665 + ret = vchiq_mmal_port_disable(dev->instance, dev->capture.port);
666 + } else if (dev->capture.camera_port != dev->capture.port) {
667 + v4l2_err(&dev->v4l2_dev, "port_disable failed, error %d\n",
671 + if (disable_camera(dev) < 0) {
672 + v4l2_err(&dev->v4l2_dev, "Failed to disable camera");
679 +static void bm2835_mmal_lock(struct vb2_queue *vq)
681 + struct bm2835_mmal_dev *dev = vb2_get_drv_priv(vq);
682 + mutex_lock(&dev->mutex);
685 +static void bm2835_mmal_unlock(struct vb2_queue *vq)
687 + struct bm2835_mmal_dev *dev = vb2_get_drv_priv(vq);
688 + mutex_unlock(&dev->mutex);
691 +static struct vb2_ops bm2835_mmal_video_qops = {
692 + .queue_setup = queue_setup,
693 + .buf_prepare = buffer_prepare,
694 + .buf_queue = buffer_queue,
695 + .start_streaming = start_streaming,
696 + .stop_streaming = stop_streaming,
697 + .wait_prepare = bm2835_mmal_unlock,
698 + .wait_finish = bm2835_mmal_lock,
701 +/* ------------------------------------------------------------------
703 + ------------------------------------------------------------------*/
706 +static int vidioc_enum_fmt_vid_overlay(struct file *file, void *priv,
707 + struct v4l2_fmtdesc *f)
709 + struct mmal_fmt *fmt;
711 + if (f->index >= ARRAY_SIZE(formats))
714 + fmt = &formats[f->index];
716 + strlcpy(f->description, fmt->name, sizeof(f->description));
717 + f->pixelformat = fmt->fourcc;
722 +static int vidioc_g_fmt_vid_overlay(struct file *file, void *priv,
723 + struct v4l2_format *f)
725 + struct bm2835_mmal_dev *dev = video_drvdata(file);
727 + f->fmt.win = dev->overlay;
732 +static int vidioc_try_fmt_vid_overlay(struct file *file, void *priv,
733 + struct v4l2_format *f)
735 + /* Only support one format so get the current one. */
736 + vidioc_g_fmt_vid_overlay(file, priv, f);
738 + /* todo: allow the size and/or offset to be changed. */
742 +static int vidioc_s_fmt_vid_overlay(struct file *file, void *priv,
743 + struct v4l2_format *f)
745 + struct bm2835_mmal_dev *dev = video_drvdata(file);
747 + vidioc_try_fmt_vid_overlay(file, priv, f);
749 + dev->overlay = f->fmt.win;
751 + /* todo: program the preview port parameters */
755 +static int vidioc_overlay(struct file *file, void *f, unsigned int on)
758 + struct bm2835_mmal_dev *dev = video_drvdata(file);
759 + struct vchiq_mmal_port *src;
760 + struct vchiq_mmal_port *dst;
761 + struct mmal_parameter_displayregion prev_config = {
762 + .set = MMAL_DISPLAY_SET_LAYER | MMAL_DISPLAY_SET_ALPHA |
763 + MMAL_DISPLAY_SET_DEST_RECT | MMAL_DISPLAY_SET_FULLSCREEN,
764 + .layer = PREVIEW_LAYER,
768 + .x = dev->overlay.w.left,
769 + .y = dev->overlay.w.top,
770 + .width = dev->overlay.w.width,
771 + .height = dev->overlay.w.height,
775 + if ((on && dev->component[MMAL_COMPONENT_PREVIEW]->enabled) ||
776 + (!on && !dev->component[MMAL_COMPONENT_PREVIEW]->enabled))
777 + return 0; /* already in requested state */
780 + &dev->component[MMAL_COMPONENT_CAMERA]->
781 + output[MMAL_CAMERA_PORT_PREVIEW];
784 + /* disconnect preview ports and disable component */
785 + ret = vchiq_mmal_port_disable(dev->instance, src);
788 + vchiq_mmal_port_connect_tunnel(dev->instance, src,
791 + ret = vchiq_mmal_component_disable(
793 + dev->component[MMAL_COMPONENT_PREVIEW]);
795 + disable_camera(dev);
799 + /* set preview port format and connect it to output */
800 + dst = &dev->component[MMAL_COMPONENT_PREVIEW]->input[0];
802 + ret = vchiq_mmal_port_set_format(dev->instance, src);
806 + ret = vchiq_mmal_port_parameter_set(dev->instance, dst,
807 + MMAL_PARAMETER_DISPLAYREGION,
808 + &prev_config, sizeof(prev_config));
812 + if (enable_camera(dev) < 0)
815 + ret = vchiq_mmal_component_enable(
817 + dev->component[MMAL_COMPONENT_PREVIEW]);
821 + v4l2_dbg(1, bcm2835_v4l2_debug, &dev->v4l2_dev, "connecting %p to %p\n",
823 + ret = vchiq_mmal_port_connect_tunnel(dev->instance, src, dst);
825 + ret = vchiq_mmal_port_enable(dev->instance, src, NULL);
830 +static int vidioc_g_fbuf(struct file *file, void *fh,
831 + struct v4l2_framebuffer *a)
833 + /* The video overlay must stay within the framebuffer and can't be
834 + positioned independently. */
835 + a->flags = V4L2_FBUF_FLAG_OVERLAY;
837 + /* todo: v4l2_framebuffer still needs more info filling in
838 + * in order to pass the v4l2-compliance test. */
844 +static int vidioc_enum_input(struct file *file, void *priv,
845 + struct v4l2_input *inp)
847 + /* only a single camera input */
848 + if (inp->index != 0)
851 + inp->type = V4L2_INPUT_TYPE_CAMERA;
852 + sprintf(inp->name, "Camera %u", inp->index);
856 +static int vidioc_g_input(struct file *file, void *priv, unsigned int *i)
862 +static int vidioc_s_input(struct file *file, void *priv, unsigned int i)
870 +/* capture ioctls */
871 +static int vidioc_querycap(struct file *file, void *priv,
872 + struct v4l2_capability *cap)
874 + struct bm2835_mmal_dev *dev = video_drvdata(file);
878 + vchiq_mmal_version(dev->instance, &major, &minor);
880 + strcpy(cap->driver, "bm2835 mmal");
881 + snprintf(cap->card, sizeof(cap->card), "mmal service %d.%d",
884 + snprintf(cap->bus_info, sizeof(cap->bus_info),
885 + "platform:%s", dev->v4l2_dev.name);
886 + cap->device_caps = V4L2_CAP_VIDEO_CAPTURE | V4L2_CAP_VIDEO_OVERLAY |
887 + V4L2_CAP_STREAMING | V4L2_CAP_READWRITE;
888 + cap->capabilities = cap->device_caps | V4L2_CAP_DEVICE_CAPS;
893 +static int vidioc_enum_fmt_vid_cap(struct file *file, void *priv,
894 + struct v4l2_fmtdesc *f)
896 + struct mmal_fmt *fmt;
898 + if (f->index >= ARRAY_SIZE(formats))
901 + fmt = &formats[f->index];
903 + strlcpy(f->description, fmt->name, sizeof(f->description));
904 + f->pixelformat = fmt->fourcc;
908 +static int vidioc_g_fmt_vid_cap(struct file *file, void *priv,
909 + struct v4l2_format *f)
911 + struct bm2835_mmal_dev *dev = video_drvdata(file);
913 + f->fmt.pix.width = dev->capture.width;
914 + f->fmt.pix.height = dev->capture.height;
915 + f->fmt.pix.field = V4L2_FIELD_NONE;
916 + f->fmt.pix.pixelformat = dev->capture.fmt->fourcc;
917 + f->fmt.pix.bytesperline =
918 + (f->fmt.pix.width * dev->capture.fmt->depth) >> 3;
919 + f->fmt.pix.sizeimage = f->fmt.pix.height * f->fmt.pix.bytesperline;
920 + if (dev->capture.fmt->fourcc == V4L2_PIX_FMT_JPEG
921 + && f->fmt.pix.sizeimage < (100 << 10)) {
922 + /* Need a minimum size for JPEG to account for EXIF. */
923 + f->fmt.pix.sizeimage = (100 << 10);
926 + if (dev->capture.fmt->fourcc == V4L2_PIX_FMT_YUYV ||
927 + dev->capture.fmt->fourcc == V4L2_PIX_FMT_UYVY)
928 + f->fmt.pix.colorspace = V4L2_COLORSPACE_SMPTE170M;
930 + f->fmt.pix.colorspace = V4L2_COLORSPACE_SRGB;
931 + f->fmt.pix.priv = 0;
933 + v4l2_dump_pix_format(1, bcm2835_v4l2_debug, &dev->v4l2_dev, &f->fmt.pix,
938 +static int vidioc_try_fmt_vid_cap(struct file *file, void *priv,
939 + struct v4l2_format *f)
941 + struct bm2835_mmal_dev *dev = video_drvdata(file);
942 + struct mmal_fmt *mfmt;
944 + mfmt = get_format(f);
946 + v4l2_dbg(1, bcm2835_v4l2_debug, &dev->v4l2_dev,
947 + "Fourcc format (0x%08x) unknown.\n",
948 + f->fmt.pix.pixelformat);
949 + f->fmt.pix.pixelformat = formats[0].fourcc;
950 + mfmt = get_format(f);
953 + f->fmt.pix.field = V4L2_FIELD_NONE;
954 + /* image must be a multiple of 32 pixels wide and 16 lines high */
955 + v4l_bound_align_image(&f->fmt.pix.width, 48, MAX_WIDTH, 5,
956 + &f->fmt.pix.height, 32, MAX_HEIGHT, 4, 0);
957 + f->fmt.pix.bytesperline = (f->fmt.pix.width * mfmt->depth) >> 3;
958 + f->fmt.pix.sizeimage = f->fmt.pix.height * f->fmt.pix.bytesperline;
959 + if (f->fmt.pix.sizeimage < MIN_BUFFER_SIZE)
960 + f->fmt.pix.sizeimage = MIN_BUFFER_SIZE;
962 + if (mfmt->fourcc == V4L2_PIX_FMT_YUYV ||
963 + mfmt->fourcc == V4L2_PIX_FMT_UYVY)
964 + f->fmt.pix.colorspace = V4L2_COLORSPACE_SMPTE170M;
966 + f->fmt.pix.colorspace = V4L2_COLORSPACE_SRGB;
967 + f->fmt.pix.priv = 0;
969 + v4l2_dump_pix_format(1, bcm2835_v4l2_debug, &dev->v4l2_dev, &f->fmt.pix,
974 +static int mmal_setup_components(struct bm2835_mmal_dev *dev,
975 + struct v4l2_format *f)
978 + struct vchiq_mmal_port *port = NULL, *camera_port = NULL;
979 + struct vchiq_mmal_component *encode_component = NULL;
980 + struct mmal_fmt *mfmt = get_format(f);
984 + if (dev->capture.encode_component) {
985 + v4l2_dbg(1, bcm2835_v4l2_debug, &dev->v4l2_dev,
986 + "vid_cap - disconnect previous tunnel\n");
988 + /* Disconnect any previous connection */
989 + vchiq_mmal_port_connect_tunnel(dev->instance,
990 + dev->capture.camera_port, NULL);
991 + dev->capture.camera_port = NULL;
992 + ret = vchiq_mmal_component_disable(dev->instance,
996 + v4l2_err(&dev->v4l2_dev,
997 + "Failed to disable encode component %d\n",
1000 + dev->capture.encode_component = NULL;
1002 + /* format dependant port setup */
1003 + switch (mfmt->mmal_component) {
1004 + case MMAL_COMPONENT_CAMERA:
1005 + /* Make a further decision on port based on resolution */
1006 + if (f->fmt.pix.width <= MAX_VIDEO_MODE_WIDTH
1007 + && f->fmt.pix.height <= MAX_VIDEO_MODE_HEIGHT)
1008 + camera_port = port =
1009 + &dev->component[MMAL_COMPONENT_CAMERA]->
1010 + output[MMAL_CAMERA_PORT_VIDEO];
1012 + camera_port = port =
1013 + &dev->component[MMAL_COMPONENT_CAMERA]->
1014 + output[MMAL_CAMERA_PORT_CAPTURE];
1016 + case MMAL_COMPONENT_IMAGE_ENCODE:
1017 + encode_component = dev->component[MMAL_COMPONENT_IMAGE_ENCODE];
1018 + port = &dev->component[MMAL_COMPONENT_IMAGE_ENCODE]->output[0];
1020 + &dev->component[MMAL_COMPONENT_CAMERA]->
1021 + output[MMAL_CAMERA_PORT_CAPTURE];
1023 + case MMAL_COMPONENT_VIDEO_ENCODE:
1024 + encode_component = dev->component[MMAL_COMPONENT_VIDEO_ENCODE];
1025 + port = &dev->component[MMAL_COMPONENT_VIDEO_ENCODE]->output[0];
1027 + &dev->component[MMAL_COMPONENT_CAMERA]->
1028 + output[MMAL_CAMERA_PORT_VIDEO];
1037 + if (encode_component)
1038 + camera_port->format.encoding = MMAL_ENCODING_OPAQUE;
1040 + camera_port->format.encoding = mfmt->mmal;
1042 + camera_port->format.encoding_variant = 0;
1043 + camera_port->es.video.width = f->fmt.pix.width;
1044 + camera_port->es.video.height = f->fmt.pix.height;
1045 + camera_port->es.video.crop.x = 0;
1046 + camera_port->es.video.crop.y = 0;
1047 + camera_port->es.video.crop.width = f->fmt.pix.width;
1048 + camera_port->es.video.crop.height = f->fmt.pix.height;
1049 + camera_port->es.video.frame_rate.num = 30;
1050 + camera_port->es.video.frame_rate.den = 1;
1052 + ret = vchiq_mmal_port_set_format(dev->instance, camera_port);
1056 + &dev->component[MMAL_COMPONENT_CAMERA]->
1057 + output[MMAL_CAMERA_PORT_VIDEO]) {
1058 + bool overlay_enabled =
1059 + !!dev->component[MMAL_COMPONENT_PREVIEW]->enabled;
1060 + struct vchiq_mmal_port *preview_port =
1061 + &dev->component[MMAL_COMPONENT_CAMERA]->
1062 + output[MMAL_CAMERA_PORT_PREVIEW];
1063 + /* Preview and encode ports need to match on resolution */
1064 + if (overlay_enabled) {
1065 + /* Need to disable the overlay before we can update
1069 + vchiq_mmal_port_disable(dev->instance,
1073 + vchiq_mmal_port_connect_tunnel(
1078 + preview_port->es.video.width = f->fmt.pix.width;
1079 + preview_port->es.video.height = f->fmt.pix.height;
1080 + preview_port->es.video.crop.x = 0;
1081 + preview_port->es.video.crop.y = 0;
1082 + preview_port->es.video.crop.width = f->fmt.pix.width;
1083 + preview_port->es.video.crop.height = f->fmt.pix.height;
1084 + preview_port->es.video.frame_rate.num = 30;
1085 + preview_port->es.video.frame_rate.den = 1;
1086 + ret = vchiq_mmal_port_set_format(dev->instance, preview_port);
1087 + if (overlay_enabled) {
1088 + ret = vchiq_mmal_port_connect_tunnel(
1091 + &dev->component[MMAL_COMPONENT_PREVIEW]->input[0]);
1093 + ret = vchiq_mmal_port_enable(dev->instance,
1100 + v4l2_dbg(1, bcm2835_v4l2_debug, &dev->v4l2_dev,
1101 + "%s failed to set format\n", __func__);
1102 + /* ensure capture is not going to be tried */
1103 + dev->capture.port = NULL;
1105 + if (encode_component) {
1106 + v4l2_dbg(1, bcm2835_v4l2_debug, &dev->v4l2_dev,
1107 + "vid_cap - set up encode comp\n");
1109 + /* configure buffering */
1110 + camera_port->current_buffer.size =
1111 + camera_port->recommended_buffer.size;
1112 + camera_port->current_buffer.num =
1113 + camera_port->recommended_buffer.num;
1115 + port->format.encoding = mfmt->mmal;
1116 + port->format.encoding_variant = 0;
1117 + /* Set any encoding specific parameters */
1118 + switch (mfmt->mmal_component) {
1119 + case MMAL_COMPONENT_VIDEO_ENCODE:
1120 + port->format.bitrate =
1121 + dev->capture.encode_bitrate;
1123 + case MMAL_COMPONENT_IMAGE_ENCODE:
1124 + /* Could set EXIF parameters here */
1129 + ret = vchiq_mmal_port_set_format(dev->instance, port);
1132 + v4l2_dbg(1, bcm2835_v4l2_debug, &dev->v4l2_dev,
1133 + "%s failed to set format\n", __func__);
1135 + ret = vchiq_mmal_component_enable(
1137 + encode_component);
1139 + v4l2_dbg(1, bcm2835_v4l2_debug,
1141 + "%s Failed to enable encode components\n",
1144 + /* configure buffering */
1145 + port->current_buffer.num = 1;
1146 + port->current_buffer.size =
1147 + f->fmt.pix.sizeimage;
1148 + if (port->format.encoding ==
1149 + MMAL_ENCODING_JPEG) {
1150 + v4l2_dbg(1, bcm2835_v4l2_debug,
1152 + "JPEG - fiddle buffer size\n");
1153 + port->current_buffer.size =
1154 + (f->fmt.pix.sizeimage <
1156 + ? (100 << 10) : f->fmt.pix.
1159 + v4l2_dbg(1, bcm2835_v4l2_debug,
1161 + "vid_cap - current_buffer.size being set to %d\n",
1162 + f->fmt.pix.sizeimage);
1163 + port->current_buffer.alignment = 0;
1165 + vchiq_mmal_port_connect_tunnel(
1168 + &encode_component->input[0]);
1170 + v4l2_dbg(1, bcm2835_v4l2_debug,
1172 + "%s failed to create connection\n",
1174 + /* ensure capture is not going to be tried */
1175 + dev->capture.port = NULL;
1180 + /* configure buffering */
1181 + camera_port->current_buffer.num = 1;
1182 + camera_port->current_buffer.size = f->fmt.pix.sizeimage;
1183 + camera_port->current_buffer.alignment = 0;
1187 + dev->capture.fmt = mfmt;
1188 + dev->capture.stride = f->fmt.pix.bytesperline;
1189 + dev->capture.width = port->es.video.crop.width;
1190 + dev->capture.height = port->es.video.crop.height;
1192 + /* select port for capture */
1193 + dev->capture.port = port;
1194 + dev->capture.camera_port = camera_port;
1195 + dev->capture.encode_component = encode_component;
1199 + /* todo: Need to convert the vchiq/mmal error into a v4l2 error. */
1203 +static int vidioc_s_fmt_vid_cap(struct file *file, void *priv,
1204 + struct v4l2_format *f)
1207 + struct bm2835_mmal_dev *dev = video_drvdata(file);
1208 + struct mmal_fmt *mfmt;
1210 + /* try the format to set valid parameters */
1211 + ret = vidioc_try_fmt_vid_cap(file, priv, f);
1213 + v4l2_err(&dev->v4l2_dev,
1214 + "vid_cap - vidioc_try_fmt_vid_cap failed\n");
1218 + /* if a capture is running refuse to set format */
1219 + if (vb2_is_busy(&dev->capture.vb_vidq)) {
1220 + v4l2_info(&dev->v4l2_dev, "%s device busy\n", __func__);
1224 + /* If the format is unsupported v4l2 says we should switch to
1225 + * a supported one and not return an error. */
1226 + mfmt = get_format(f);
1228 + v4l2_dbg(1, bcm2835_v4l2_debug, &dev->v4l2_dev,
1229 + "Fourcc format (0x%08x) unknown.\n",
1230 + f->fmt.pix.pixelformat);
1231 + f->fmt.pix.pixelformat = formats[0].fourcc;
1232 + mfmt = get_format(f);
1235 + ret = mmal_setup_components(dev, f);
1237 + v4l2_err(&dev->v4l2_dev,
1238 + "%s: failed to setup mmal components: %d\n",
1244 +static const struct v4l2_ioctl_ops camera0_ioctl_ops = {
1246 + .vidioc_enum_fmt_vid_overlay = vidioc_enum_fmt_vid_overlay,
1247 + .vidioc_g_fmt_vid_overlay = vidioc_g_fmt_vid_overlay,
1248 + .vidioc_try_fmt_vid_overlay = vidioc_try_fmt_vid_overlay,
1249 + .vidioc_s_fmt_vid_overlay = vidioc_s_fmt_vid_overlay,
1250 + .vidioc_overlay = vidioc_overlay,
1251 + .vidioc_g_fbuf = vidioc_g_fbuf,
1254 + .vidioc_enum_input = vidioc_enum_input,
1255 + .vidioc_g_input = vidioc_g_input,
1256 + .vidioc_s_input = vidioc_s_input,
1259 + .vidioc_querycap = vidioc_querycap,
1260 + .vidioc_enum_fmt_vid_cap = vidioc_enum_fmt_vid_cap,
1261 + .vidioc_g_fmt_vid_cap = vidioc_g_fmt_vid_cap,
1262 + .vidioc_try_fmt_vid_cap = vidioc_try_fmt_vid_cap,
1263 + .vidioc_s_fmt_vid_cap = vidioc_s_fmt_vid_cap,
1265 + /* buffer management */
1266 + .vidioc_reqbufs = vb2_ioctl_reqbufs,
1267 + .vidioc_create_bufs = vb2_ioctl_create_bufs,
1268 + .vidioc_prepare_buf = vb2_ioctl_prepare_buf,
1269 + .vidioc_querybuf = vb2_ioctl_querybuf,
1270 + .vidioc_qbuf = vb2_ioctl_qbuf,
1271 + .vidioc_dqbuf = vb2_ioctl_dqbuf,
1272 + .vidioc_streamon = vb2_ioctl_streamon,
1273 + .vidioc_streamoff = vb2_ioctl_streamoff,
1275 + .vidioc_log_status = v4l2_ctrl_log_status,
1276 + .vidioc_subscribe_event = v4l2_ctrl_subscribe_event,
1277 + .vidioc_unsubscribe_event = v4l2_event_unsubscribe,
1280 +/* ------------------------------------------------------------------
1281 + Driver init/finalise
1282 + ------------------------------------------------------------------*/
1284 +static const struct v4l2_file_operations camera0_fops = {
1285 + .owner = THIS_MODULE,
1286 + .open = v4l2_fh_open,
1287 + .release = vb2_fop_release,
1288 + .read = vb2_fop_read,
1289 + .poll = vb2_fop_poll,
1290 + .unlocked_ioctl = video_ioctl2, /* V4L2 ioctl handler */
1291 + .mmap = vb2_fop_mmap,
1294 +static struct video_device vdev_template = {
1295 + .name = "camera0",
1296 + .fops = &camera0_fops,
1297 + .ioctl_ops = &camera0_ioctl_ops,
1298 + .release = video_device_release_empty,
1301 +static int set_camera_parameters(struct vchiq_mmal_instance *instance,
1302 + struct vchiq_mmal_component *camera)
1305 + struct mmal_parameter_camera_config cam_config = {
1306 + .max_stills_w = MAX_WIDTH,
1307 + .max_stills_h = MAX_HEIGHT,
1308 + .stills_yuv422 = 1,
1309 + .one_shot_stills = 1,
1310 + .max_preview_video_w = 1920,
1311 + .max_preview_video_h = 1088,
1312 + .num_preview_video_frames = 3,
1313 + .stills_capture_circular_buffer_height = 0,
1314 + .fast_preview_resume = 0,
1315 + .use_stc_timestamp = MMAL_PARAM_TIMESTAMP_MODE_RAW_STC
1318 + ret = vchiq_mmal_port_parameter_set(instance, &camera->control,
1319 + MMAL_PARAMETER_CAMERA_CONFIG,
1320 + &cam_config, sizeof(cam_config));
1324 +/* MMAL instance and component init */
1325 +static int __init mmal_init(struct bm2835_mmal_dev *dev)
1328 + struct mmal_es_format *format;
1330 + ret = vchiq_mmal_init(&dev->instance);
1334 + /* get the camera component ready */
1335 + ret = vchiq_mmal_component_init(dev->instance, "ril.camera",
1336 + &dev->component[MMAL_COMPONENT_CAMERA]);
1340 + if (dev->component[MMAL_COMPONENT_CAMERA]->outputs <
1341 + MMAL_CAMERA_PORT_COUNT) {
1343 + goto unreg_camera;
1346 + ret = set_camera_parameters(dev->instance,
1347 + dev->component[MMAL_COMPONENT_CAMERA]);
1349 + goto unreg_camera;
1352 + &dev->component[MMAL_COMPONENT_CAMERA]->
1353 + output[MMAL_CAMERA_PORT_PREVIEW].format;
1355 + format->encoding = MMAL_ENCODING_OPAQUE;
1356 + format->encoding_variant = MMAL_ENCODING_I420;
1358 + format->es->video.width = 1024;
1359 + format->es->video.height = 768;
1360 + format->es->video.crop.x = 0;
1361 + format->es->video.crop.y = 0;
1362 + format->es->video.crop.width = 1024;
1363 + format->es->video.crop.height = 768;
1364 + format->es->video.frame_rate.num = PREVIEW_FRAME_RATE_NUM;
1365 + format->es->video.frame_rate.den = PREVIEW_FRAME_RATE_DEN;
1368 + &dev->component[MMAL_COMPONENT_CAMERA]->
1369 + output[MMAL_CAMERA_PORT_VIDEO].format;
1371 + format->encoding = MMAL_ENCODING_OPAQUE;
1372 + format->encoding_variant = MMAL_ENCODING_I420;
1374 + format->es->video.width = 1024;
1375 + format->es->video.height = 768;
1376 + format->es->video.crop.x = 0;
1377 + format->es->video.crop.y = 0;
1378 + format->es->video.crop.width = 1024;
1379 + format->es->video.crop.height = 768;
1380 + format->es->video.frame_rate.num = PREVIEW_FRAME_RATE_NUM;
1381 + format->es->video.frame_rate.den = PREVIEW_FRAME_RATE_DEN;
1384 + &dev->component[MMAL_COMPONENT_CAMERA]->
1385 + output[MMAL_CAMERA_PORT_CAPTURE].format;
1387 + format->encoding = MMAL_ENCODING_OPAQUE;
1389 + format->es->video.width = 2592;
1390 + format->es->video.height = 1944;
1391 + format->es->video.crop.x = 0;
1392 + format->es->video.crop.y = 0;
1393 + format->es->video.crop.width = 2592;
1394 + format->es->video.crop.height = 1944;
1395 + format->es->video.frame_rate.num = 30;
1396 + format->es->video.frame_rate.den = 1;
1398 + dev->capture.width = format->es->video.width;
1399 + dev->capture.height = format->es->video.height;
1400 + dev->capture.fmt = &formats[0];
1401 + dev->capture.encode_component = NULL;
1403 + /* get the preview component ready */
1404 + ret = vchiq_mmal_component_init(
1405 + dev->instance, "ril.video_render",
1406 + &dev->component[MMAL_COMPONENT_PREVIEW]);
1408 + goto unreg_camera;
1410 + if (dev->component[MMAL_COMPONENT_PREVIEW]->inputs < 1) {
1412 + pr_debug("too few input ports %d needed %d\n",
1413 + dev->component[MMAL_COMPONENT_PREVIEW]->inputs, 1);
1414 + goto unreg_preview;
1417 + /* get the image encoder component ready */
1418 + ret = vchiq_mmal_component_init(
1419 + dev->instance, "ril.image_encode",
1420 + &dev->component[MMAL_COMPONENT_IMAGE_ENCODE]);
1422 + goto unreg_preview;
1424 + if (dev->component[MMAL_COMPONENT_IMAGE_ENCODE]->inputs < 1) {
1426 + v4l2_err(&dev->v4l2_dev, "too few input ports %d needed %d\n",
1427 + dev->component[MMAL_COMPONENT_IMAGE_ENCODE]->inputs,
1429 + goto unreg_image_encoder;
1432 + /* get the video encoder component ready */
1433 + ret = vchiq_mmal_component_init(dev->instance, "ril.video_encode",
1435 + component[MMAL_COMPONENT_VIDEO_ENCODE]);
1437 + goto unreg_image_encoder;
1439 + if (dev->component[MMAL_COMPONENT_VIDEO_ENCODE]->inputs < 1) {
1441 + v4l2_err(&dev->v4l2_dev, "too few input ports %d needed %d\n",
1442 + dev->component[MMAL_COMPONENT_VIDEO_ENCODE]->inputs,
1444 + goto unreg_vid_encoder;
1448 + unsigned int enable = 1;
1449 + vchiq_mmal_port_parameter_set(
1451 + &dev->component[MMAL_COMPONENT_VIDEO_ENCODE]->control,
1452 + MMAL_PARAMETER_VIDEO_IMMUTABLE_INPUT,
1453 + &enable, sizeof(enable));
1455 + vchiq_mmal_port_parameter_set(dev->instance,
1456 + &dev->component[MMAL_COMPONENT_VIDEO_ENCODE]->control,
1457 + MMAL_PARAMETER_MINIMISE_FRAGMENTATION,
1461 + ret = bm2835_mmal_set_all_camera_controls(dev);
1463 + goto unreg_vid_encoder;
1468 + pr_err("Cleanup: Destroy video encoder\n");
1469 + vchiq_mmal_component_finalise(
1471 + dev->component[MMAL_COMPONENT_VIDEO_ENCODE]);
1473 +unreg_image_encoder:
1474 + pr_err("Cleanup: Destroy image encoder\n");
1475 + vchiq_mmal_component_finalise(
1477 + dev->component[MMAL_COMPONENT_IMAGE_ENCODE]);
1480 + pr_err("Cleanup: Destroy video render\n");
1481 + vchiq_mmal_component_finalise(dev->instance,
1482 + dev->component[MMAL_COMPONENT_PREVIEW]);
1485 + pr_err("Cleanup: Destroy camera\n");
1486 + vchiq_mmal_component_finalise(dev->instance,
1487 + dev->component[MMAL_COMPONENT_CAMERA]);
1490 + vchiq_mmal_finalise(dev->instance);
1494 +static int __init bm2835_mmal_init_device(struct bm2835_mmal_dev *dev,
1495 + struct video_device *vfd)
1499 + *vfd = vdev_template;
1501 + vfd->v4l2_dev = &dev->v4l2_dev;
1503 + vfd->lock = &dev->mutex;
1505 + vfd->queue = &dev->capture.vb_vidq;
1507 + /* video device needs to be able to access instance data */
1508 + video_set_drvdata(vfd, dev);
1510 + ret = video_register_device(vfd, VFL_TYPE_GRABBER, -1);
1514 + v4l2_info(vfd->v4l2_dev, "V4L2 device registered as %s\n",
1515 + video_device_node_name(vfd));
1520 +static struct v4l2_format default_v4l2_format = {
1521 + .fmt.pix.pixelformat = V4L2_PIX_FMT_JPEG,
1522 + .fmt.pix.width = 1024,
1523 + .fmt.pix.bytesperline = 1024 * 3 / 2,
1524 + .fmt.pix.height = 768,
1525 + .fmt.pix.sizeimage = 1<<18,
1528 +static int __init bm2835_mmal_init(void)
1531 + struct bm2835_mmal_dev *dev;
1532 + struct vb2_queue *q;
1534 + dev = kzalloc(sizeof(*gdev), GFP_KERNEL);
1538 + /* setup device defaults */
1539 + dev->overlay.w.left = 150;
1540 + dev->overlay.w.top = 50;
1541 + dev->overlay.w.width = 1024;
1542 + dev->overlay.w.height = 768;
1543 + dev->overlay.clipcount = 0;
1544 + dev->overlay.field = V4L2_FIELD_NONE;
1546 + dev->capture.fmt = &formats[3]; /* JPEG */
1548 + /* v4l device registration */
1549 + snprintf(dev->v4l2_dev.name, sizeof(dev->v4l2_dev.name),
1550 + "%s", BM2835_MMAL_MODULE_NAME);
1551 + ret = v4l2_device_register(NULL, &dev->v4l2_dev);
1555 + /* setup v4l controls */
1556 + ret = bm2835_mmal_init_controls(dev, &dev->ctrl_handler);
1559 + dev->v4l2_dev.ctrl_handler = &dev->ctrl_handler;
1562 + ret = mmal_init(dev);
1566 + /* initialize queue */
1567 + q = &dev->capture.vb_vidq;
1568 + memset(q, 0, sizeof(*q));
1569 + q->type = V4L2_BUF_TYPE_VIDEO_CAPTURE;
1570 + q->io_modes = VB2_MMAP | VB2_USERPTR | VB2_READ;
1571 + q->drv_priv = dev;
1572 + q->buf_struct_size = sizeof(struct mmal_buffer);
1573 + q->ops = &bm2835_mmal_video_qops;
1574 + q->mem_ops = &vb2_vmalloc_memops;
1575 + q->timestamp_flags = V4L2_BUF_FLAG_TIMESTAMP_MONOTONIC;
1576 + ret = vb2_queue_init(q);
1580 + /* v4l2 core mutex used to protect all fops and v4l2 ioctls. */
1581 + mutex_init(&dev->mutex);
1583 + /* initialise video devices */
1584 + ret = bm2835_mmal_init_device(dev, &dev->vdev);
1588 + ret = mmal_setup_components(dev, &default_v4l2_format);
1590 + v4l2_err(&dev->v4l2_dev,
1591 + "%s: could not setup components\n", __func__);
1595 + v4l2_info(&dev->v4l2_dev,
1596 + "Broadcom 2835 MMAL video capture ver %s loaded.\n",
1597 + BM2835_MMAL_VERSION);
1603 + v4l2_ctrl_handler_free(&dev->ctrl_handler);
1604 + v4l2_device_unregister(&dev->v4l2_dev);
1609 + v4l2_err(&dev->v4l2_dev,
1610 + "%s: error %d while loading driver\n",
1611 + BM2835_MMAL_MODULE_NAME, ret);
1616 +static void __exit bm2835_mmal_exit(void)
1621 + v4l2_info(&gdev->v4l2_dev, "unregistering %s\n",
1622 + video_device_node_name(&gdev->vdev));
1624 + video_unregister_device(&gdev->vdev);
1626 + if (gdev->capture.encode_component) {
1627 + v4l2_dbg(1, bcm2835_v4l2_debug, &gdev->v4l2_dev,
1628 + "mmal_exit - disconnect tunnel\n");
1629 + vchiq_mmal_port_connect_tunnel(gdev->instance,
1630 + gdev->capture.camera_port, NULL);
1631 + vchiq_mmal_component_disable(gdev->instance,
1632 + gdev->capture.encode_component);
1634 + vchiq_mmal_component_disable(gdev->instance,
1635 + gdev->component[MMAL_COMPONENT_CAMERA]);
1637 + vchiq_mmal_component_finalise(gdev->instance,
1639 + component[MMAL_COMPONENT_VIDEO_ENCODE]);
1641 + vchiq_mmal_component_finalise(gdev->instance,
1643 + component[MMAL_COMPONENT_IMAGE_ENCODE]);
1645 + vchiq_mmal_component_finalise(gdev->instance,
1646 + gdev->component[MMAL_COMPONENT_PREVIEW]);
1648 + vchiq_mmal_component_finalise(gdev->instance,
1649 + gdev->component[MMAL_COMPONENT_CAMERA]);
1651 + vchiq_mmal_finalise(gdev->instance);
1653 + v4l2_ctrl_handler_free(&gdev->ctrl_handler);
1655 + v4l2_device_unregister(&gdev->v4l2_dev);
1660 +module_init(bm2835_mmal_init);
1661 +module_exit(bm2835_mmal_exit);
1662 diff --git a/drivers/media/platform/bcm2835/bcm2835-camera.h b/drivers/media/platform/bcm2835/bcm2835-camera.h
1663 new file mode 100644
1664 index 0000000..883eab7
1666 +++ b/drivers/media/platform/bcm2835/bcm2835-camera.h
1669 + * Broadcom BM2835 V4L2 driver
1671 + * Copyright © 2013 Raspberry Pi (Trading) Ltd.
1673 + * This file is subject to the terms and conditions of the GNU General Public
1674 + * License. See the file COPYING in the main directory of this archive
1675 + * for more details.
1677 + * Authors: Vincent Sanders <vincent.sanders@collabora.co.uk>
1678 + * Dave Stevenson <dsteve@broadcom.com>
1679 + * Simon Mellor <simellor@broadcom.com>
1680 + * Luke Diamand <luked@broadcom.com>
1682 + * core driver device
1685 +#define V4L2_CTRL_COUNT 18 /* number of v4l controls */
1688 + MMAL_COMPONENT_CAMERA = 0,
1689 + MMAL_COMPONENT_PREVIEW,
1690 + MMAL_COMPONENT_IMAGE_ENCODE,
1691 + MMAL_COMPONENT_VIDEO_ENCODE,
1692 + MMAL_COMPONENT_COUNT
1696 + MMAL_CAMERA_PORT_PREVIEW = 0,
1697 + MMAL_CAMERA_PORT_VIDEO,
1698 + MMAL_CAMERA_PORT_CAPTURE,
1699 + MMAL_CAMERA_PORT_COUNT
1702 +#define PREVIEW_FRAME_RATE_NUM 30
1703 +#define PREVIEW_FRAME_RATE_DEN 1
1705 +#define PREVIEW_LAYER 2
1707 +extern int bcm2835_v4l2_debug;
1709 +struct bm2835_mmal_dev {
1710 + /* v4l2 devices */
1711 + struct v4l2_device v4l2_dev;
1712 + struct video_device vdev;
1713 + struct mutex mutex;
1716 + struct v4l2_ctrl_handler ctrl_handler;
1717 + struct v4l2_ctrl *ctrls[V4L2_CTRL_COUNT];
1718 + struct mmal_colourfx colourfx;
1722 + /* allocated mmal instance and components */
1723 + struct vchiq_mmal_instance *instance;
1724 + struct vchiq_mmal_component *component[MMAL_COMPONENT_COUNT];
1725 + int camera_use_count;
1727 + struct v4l2_window overlay;
1730 + unsigned int width; /* width */
1731 + unsigned int height; /* height */
1732 + unsigned int stride; /* stride */
1733 + struct mmal_fmt *fmt;
1735 + /* H264 encode bitrate */
1736 + int encode_bitrate;
1737 + /* H264 bitrate mode. CBR/VBR */
1738 + int encode_bitrate_mode;
1739 + /* JPEG Q-factor */
1742 + struct vb2_queue vb_vidq;
1744 + /* VC start timestamp for streaming */
1745 + s64 vc_start_timestamp;
1746 + /* Kernel start timestamp for streaming */
1747 + struct timeval kernel_start_ts;
1749 + struct vchiq_mmal_port *port; /* port being used for capture */
1750 + /* camera port being used for capture */
1751 + struct vchiq_mmal_port *camera_port;
1752 + /* component being used for encode */
1753 + struct vchiq_mmal_component *encode_component;
1754 + /* number of frames remaining which driver should capture */
1755 + unsigned int frame_count;
1756 + /* last frame completion */
1757 + struct completion frame_cmplt;
1763 +int bm2835_mmal_init_controls(
1764 + struct bm2835_mmal_dev *dev,
1765 + struct v4l2_ctrl_handler *hdl);
1767 +int bm2835_mmal_set_all_camera_controls(struct bm2835_mmal_dev *dev);
1770 +/* Debug helpers */
1772 +#define v4l2_dump_pix_format(level, debug, dev, pix_fmt, desc) \
1774 + v4l2_dbg(level, debug, dev, \
1775 +"%s: w %u h %u field %u pfmt 0x%x bpl %u sz_img %u colorspace 0x%x priv %u\n", \
1776 + desc == NULL ? "" : desc, \
1777 + (pix_fmt)->width, (pix_fmt)->height, (pix_fmt)->field, \
1778 + (pix_fmt)->pixelformat, (pix_fmt)->bytesperline, \
1779 + (pix_fmt)->sizeimage, (pix_fmt)->colorspace, (pix_fmt)->priv); \
1781 diff --git a/drivers/media/platform/bcm2835/controls.c b/drivers/media/platform/bcm2835/controls.c
1782 new file mode 100644
1783 index 0000000..d1408e5
1785 +++ b/drivers/media/platform/bcm2835/controls.c
1788 + * Broadcom BM2835 V4L2 driver
1790 + * Copyright © 2013 Raspberry Pi (Trading) Ltd.
1792 + * This file is subject to the terms and conditions of the GNU General Public
1793 + * License. See the file COPYING in the main directory of this archive
1794 + * for more details.
1796 + * Authors: Vincent Sanders <vincent.sanders@collabora.co.uk>
1797 + * Dave Stevenson <dsteve@broadcom.com>
1798 + * Simon Mellor <simellor@broadcom.com>
1799 + * Luke Diamand <luked@broadcom.com>
1802 +#include <linux/errno.h>
1803 +#include <linux/kernel.h>
1804 +#include <linux/module.h>
1805 +#include <linux/slab.h>
1806 +#include <media/videobuf2-vmalloc.h>
1807 +#include <media/v4l2-device.h>
1808 +#include <media/v4l2-ioctl.h>
1809 +#include <media/v4l2-ctrls.h>
1810 +#include <media/v4l2-fh.h>
1811 +#include <media/v4l2-event.h>
1812 +#include <media/v4l2-common.h>
1814 +#include "mmal-common.h"
1815 +#include "mmal-vchiq.h"
1816 +#include "mmal-parameters.h"
1817 +#include "bcm2835-camera.h"
1819 +/* The supported V4L2_CID_AUTO_EXPOSURE_BIAS values are from -24 to +24.
1820 + * These are in 1/6th increments so the effective range is -4.0EV to +4.0EV.
1822 +static const s64 ev_bias_qmenu[] = {
1823 + -24, -21, -18, -15, -12, -9, -6, -3, 0, 3, 6, 9, 12, 15, 18, 21, 24
1826 +/* Supported ISO values
1829 +static const s64 iso_qmenu[] = {
1830 + 0, 100, 200, 400, 800,
1833 +/* Supported video encode modes */
1834 +static const s64 bitrate_mode_qmenu[] = {
1835 + (s64)V4L2_MPEG_VIDEO_BITRATE_MODE_VBR,
1836 + (s64)V4L2_MPEG_VIDEO_BITRATE_MODE_CBR,
1840 +enum bm2835_mmal_ctrl_type {
1841 + MMAL_CONTROL_TYPE_STD,
1842 + MMAL_CONTROL_TYPE_STD_MENU,
1843 + MMAL_CONTROL_TYPE_INT_MENU,
1844 + MMAL_CONTROL_TYPE_CLUSTER, /* special cluster entry */
1847 +struct bm2835_mmal_v4l2_ctrl;
1849 +typedef int(bm2835_mmal_v4l2_ctrl_cb)(
1850 + struct bm2835_mmal_dev *dev,
1851 + struct v4l2_ctrl *ctrl,
1852 + const struct bm2835_mmal_v4l2_ctrl *mmal_ctrl);
1854 +struct bm2835_mmal_v4l2_ctrl {
1855 + u32 id; /* v4l2 control identifier */
1856 + enum bm2835_mmal_ctrl_type type;
1857 + /* control minimum value or
1858 + * mask for MMAL_CONTROL_TYPE_STD_MENU */
1860 + s32 max; /* maximum value of control */
1861 + s32 def; /* default value of control */
1862 + s32 step; /* step size of the control */
1863 + const s64 *imenu; /* integer menu array */
1864 + u32 mmal_id; /* mmal parameter id */
1865 + bm2835_mmal_v4l2_ctrl_cb *setter;
1868 +struct v4l2_to_mmal_effects_setting {
1871 + s32 col_fx_enable;
1872 + s32 col_fx_fixed_cbcr;
1875 + u32 num_effect_params;
1876 + u32 effect_params[MMAL_MAX_IMAGEFX_PARAMETERS];
1879 +static const struct v4l2_to_mmal_effects_setting
1880 + v4l2_to_mmal_effects_values[] = {
1881 + { V4L2_COLORFX_NONE, MMAL_PARAM_IMAGEFX_NONE,
1882 + 0, 0, 0, 0, 0, {0, 0, 0, 0, 0} },
1883 + { V4L2_COLORFX_BW, MMAL_PARAM_IMAGEFX_NONE,
1884 + 1, 0, 128, 128, 0, {0, 0, 0, 0, 0} },
1885 + { V4L2_COLORFX_SEPIA, MMAL_PARAM_IMAGEFX_NONE,
1886 + 1, 0, 87, 151, 0, {0, 0, 0, 0, 0} },
1887 + { V4L2_COLORFX_NEGATIVE, MMAL_PARAM_IMAGEFX_NEGATIVE,
1888 + 0, 0, 0, 0, 0, {0, 0, 0, 0, 0} },
1889 + { V4L2_COLORFX_EMBOSS, MMAL_PARAM_IMAGEFX_EMBOSS,
1890 + 0, 0, 0, 0, 0, {0, 0, 0, 0, 0} },
1891 + { V4L2_COLORFX_SKETCH, MMAL_PARAM_IMAGEFX_SKETCH,
1892 + 0, 0, 0, 0, 0, {0, 0, 0, 0, 0} },
1893 + { V4L2_COLORFX_SKY_BLUE, MMAL_PARAM_IMAGEFX_PASTEL,
1894 + 0, 0, 0, 0, 0, {0, 0, 0, 0, 0} },
1895 + { V4L2_COLORFX_GRASS_GREEN, MMAL_PARAM_IMAGEFX_WATERCOLOUR,
1896 + 0, 0, 0, 0, 0, {0, 0, 0, 0, 0} },
1897 + { V4L2_COLORFX_SKIN_WHITEN, MMAL_PARAM_IMAGEFX_WASHEDOUT,
1898 + 0, 0, 0, 0, 0, {0, 0, 0, 0, 0} },
1899 + { V4L2_COLORFX_VIVID, MMAL_PARAM_IMAGEFX_SATURATION,
1900 + 0, 0, 0, 0, 0, {0, 0, 0, 0, 0} },
1901 + { V4L2_COLORFX_AQUA, MMAL_PARAM_IMAGEFX_NONE,
1902 + 1, 0, 171, 121, 0, {0, 0, 0, 0, 0} },
1903 + { V4L2_COLORFX_ART_FREEZE, MMAL_PARAM_IMAGEFX_HATCH,
1904 + 0, 0, 0, 0, 0, {0, 0, 0, 0, 0} },
1905 + { V4L2_COLORFX_SILHOUETTE, MMAL_PARAM_IMAGEFX_FILM,
1906 + 0, 0, 0, 0, 0, {0, 0, 0, 0, 0} },
1907 + { V4L2_COLORFX_SOLARIZATION, MMAL_PARAM_IMAGEFX_SOLARIZE,
1908 + 0, 0, 0, 0, 5, {1, 128, 160, 160, 48} },
1909 + { V4L2_COLORFX_ANTIQUE, MMAL_PARAM_IMAGEFX_COLOURBALANCE,
1910 + 0, 0, 0, 0, 3, {108, 274, 238, 0, 0} },
1911 + { V4L2_COLORFX_SET_CBCR, MMAL_PARAM_IMAGEFX_NONE,
1912 + 1, 1, 0, 0, 0, {0, 0, 0, 0, 0} }
1916 +/* control handlers*/
1918 +static int ctrl_set_rational(struct bm2835_mmal_dev *dev,
1919 + struct v4l2_ctrl *ctrl,
1920 + const struct bm2835_mmal_v4l2_ctrl *mmal_ctrl)
1923 + s32 num; /**< Numerator */
1924 + s32 den; /**< Denominator */
1926 + struct vchiq_mmal_port *control;
1928 + control = &dev->component[MMAL_COMPONENT_CAMERA]->control;
1930 + rational_value.num = ctrl->val;
1931 + rational_value.den = 100;
1933 + return vchiq_mmal_port_parameter_set(dev->instance, control,
1934 + mmal_ctrl->mmal_id,
1936 + sizeof(rational_value));
1939 +static int ctrl_set_value(struct bm2835_mmal_dev *dev,
1940 + struct v4l2_ctrl *ctrl,
1941 + const struct bm2835_mmal_v4l2_ctrl *mmal_ctrl)
1944 + struct vchiq_mmal_port *control;
1946 + control = &dev->component[MMAL_COMPONENT_CAMERA]->control;
1948 + u32_value = ctrl->val;
1950 + return vchiq_mmal_port_parameter_set(dev->instance, control,
1951 + mmal_ctrl->mmal_id,
1952 + &u32_value, sizeof(u32_value));
1955 +static int ctrl_set_rotate(struct bm2835_mmal_dev *dev,
1956 + struct v4l2_ctrl *ctrl,
1957 + const struct bm2835_mmal_v4l2_ctrl *mmal_ctrl)
1961 + struct vchiq_mmal_component *camera;
1963 + camera = dev->component[MMAL_COMPONENT_CAMERA];
1965 + u32_value = ((ctrl->val % 360) / 90) * 90;
1967 + ret = vchiq_mmal_port_parameter_set(dev->instance, &camera->output[0],
1968 + mmal_ctrl->mmal_id,
1969 + &u32_value, sizeof(u32_value));
1973 + ret = vchiq_mmal_port_parameter_set(dev->instance, &camera->output[1],
1974 + mmal_ctrl->mmal_id,
1975 + &u32_value, sizeof(u32_value));
1979 + ret = vchiq_mmal_port_parameter_set(dev->instance, &camera->output[2],
1980 + mmal_ctrl->mmal_id,
1981 + &u32_value, sizeof(u32_value));
1986 +static int ctrl_set_flip(struct bm2835_mmal_dev *dev,
1987 + struct v4l2_ctrl *ctrl,
1988 + const struct bm2835_mmal_v4l2_ctrl *mmal_ctrl)
1992 + struct vchiq_mmal_component *camera;
1994 + if (ctrl->id == V4L2_CID_HFLIP)
1995 + dev->hflip = ctrl->val;
1997 + dev->vflip = ctrl->val;
1999 + camera = dev->component[MMAL_COMPONENT_CAMERA];
2001 + if (dev->hflip && dev->vflip)
2002 + u32_value = MMAL_PARAM_MIRROR_BOTH;
2003 + else if (dev->hflip)
2004 + u32_value = MMAL_PARAM_MIRROR_HORIZONTAL;
2005 + else if (dev->vflip)
2006 + u32_value = MMAL_PARAM_MIRROR_VERTICAL;
2008 + u32_value = MMAL_PARAM_MIRROR_NONE;
2010 + ret = vchiq_mmal_port_parameter_set(dev->instance, &camera->output[0],
2011 + mmal_ctrl->mmal_id,
2012 + &u32_value, sizeof(u32_value));
2016 + ret = vchiq_mmal_port_parameter_set(dev->instance, &camera->output[1],
2017 + mmal_ctrl->mmal_id,
2018 + &u32_value, sizeof(u32_value));
2022 + ret = vchiq_mmal_port_parameter_set(dev->instance, &camera->output[2],
2023 + mmal_ctrl->mmal_id,
2024 + &u32_value, sizeof(u32_value));
2030 +static int ctrl_set_exposure(struct bm2835_mmal_dev *dev,
2031 + struct v4l2_ctrl *ctrl,
2032 + const struct bm2835_mmal_v4l2_ctrl *mmal_ctrl)
2035 + struct vchiq_mmal_port *control;
2037 + control = &dev->component[MMAL_COMPONENT_CAMERA]->control;
2039 + switch (ctrl->val) {
2040 + case V4L2_EXPOSURE_AUTO:
2041 + u32_value = MMAL_PARAM_EXPOSUREMODE_AUTO;
2044 + case V4L2_EXPOSURE_MANUAL:
2045 + u32_value = MMAL_PARAM_EXPOSUREMODE_OFF;
2048 + case V4L2_EXPOSURE_SHUTTER_PRIORITY:
2049 + u32_value = MMAL_PARAM_EXPOSUREMODE_SPORTS;
2052 + case V4L2_EXPOSURE_APERTURE_PRIORITY:
2053 + u32_value = MMAL_PARAM_EXPOSUREMODE_NIGHT;
2058 + /* todo: what about the other ten modes there are MMAL parameters for */
2059 + return vchiq_mmal_port_parameter_set(dev->instance, control,
2060 + mmal_ctrl->mmal_id,
2061 + &u32_value, sizeof(u32_value));
2064 +static int ctrl_set_metering_mode(struct bm2835_mmal_dev *dev,
2065 + struct v4l2_ctrl *ctrl,
2066 + const struct bm2835_mmal_v4l2_ctrl *mmal_ctrl)
2069 + struct vchiq_mmal_port *control;
2071 + control = &dev->component[MMAL_COMPONENT_CAMERA]->control;
2073 + switch (ctrl->val) {
2074 + case V4L2_EXPOSURE_METERING_AVERAGE:
2075 + u32_value = MMAL_PARAM_EXPOSUREMETERINGMODE_AVERAGE;
2078 + case V4L2_EXPOSURE_METERING_CENTER_WEIGHTED:
2079 + u32_value = MMAL_PARAM_EXPOSUREMETERINGMODE_BACKLIT;
2082 + case V4L2_EXPOSURE_METERING_SPOT:
2083 + u32_value = MMAL_PARAM_EXPOSUREMETERINGMODE_SPOT;
2086 + /* todo matrix weighting not added to Linux API till 3.9
2087 + case V4L2_EXPOSURE_METERING_MATRIX:
2088 + u32_value = MMAL_PARAM_EXPOSUREMETERINGMODE_MATRIX;
2094 + return vchiq_mmal_port_parameter_set(dev->instance, control,
2095 + mmal_ctrl->mmal_id,
2096 + &u32_value, sizeof(u32_value));
2099 +static int ctrl_set_awb_mode(struct bm2835_mmal_dev *dev,
2100 + struct v4l2_ctrl *ctrl,
2101 + const struct bm2835_mmal_v4l2_ctrl *mmal_ctrl)
2104 + struct vchiq_mmal_port *control;
2106 + control = &dev->component[MMAL_COMPONENT_CAMERA]->control;
2108 + switch (ctrl->val) {
2109 + case V4L2_WHITE_BALANCE_MANUAL:
2110 + u32_value = MMAL_PARAM_AWBMODE_OFF;
2113 + case V4L2_WHITE_BALANCE_AUTO:
2114 + u32_value = MMAL_PARAM_AWBMODE_AUTO;
2117 + case V4L2_WHITE_BALANCE_INCANDESCENT:
2118 + u32_value = MMAL_PARAM_AWBMODE_INCANDESCENT;
2121 + case V4L2_WHITE_BALANCE_FLUORESCENT:
2122 + u32_value = MMAL_PARAM_AWBMODE_FLUORESCENT;
2125 + case V4L2_WHITE_BALANCE_FLUORESCENT_H:
2126 + u32_value = MMAL_PARAM_AWBMODE_TUNGSTEN;
2129 + case V4L2_WHITE_BALANCE_HORIZON:
2130 + u32_value = MMAL_PARAM_AWBMODE_HORIZON;
2133 + case V4L2_WHITE_BALANCE_DAYLIGHT:
2134 + u32_value = MMAL_PARAM_AWBMODE_SUNLIGHT;
2137 + case V4L2_WHITE_BALANCE_FLASH:
2138 + u32_value = MMAL_PARAM_AWBMODE_FLASH;
2141 + case V4L2_WHITE_BALANCE_CLOUDY:
2142 + u32_value = MMAL_PARAM_AWBMODE_CLOUDY;
2145 + case V4L2_WHITE_BALANCE_SHADE:
2146 + u32_value = MMAL_PARAM_AWBMODE_SHADE;
2151 + return vchiq_mmal_port_parameter_set(dev->instance, control,
2152 + mmal_ctrl->mmal_id,
2153 + &u32_value, sizeof(u32_value));
2156 +static int ctrl_set_image_effect(struct bm2835_mmal_dev *dev,
2157 + struct v4l2_ctrl *ctrl,
2158 + const struct bm2835_mmal_v4l2_ctrl *mmal_ctrl)
2160 + int ret = -EINVAL;
2162 + struct vchiq_mmal_port *control;
2163 + struct mmal_parameter_imagefx_parameters imagefx;
2165 + for (i = 0; i < ARRAY_SIZE(v4l2_to_mmal_effects_values); i++) {
2166 + if (ctrl->val == v4l2_to_mmal_effects_values[i].v4l2_effect) {
2169 + v4l2_to_mmal_effects_values[i].mmal_effect;
2170 + imagefx.num_effect_params =
2171 + v4l2_to_mmal_effects_values[i].num_effect_params;
2173 + if (imagefx.num_effect_params > MMAL_MAX_IMAGEFX_PARAMETERS)
2174 + imagefx.num_effect_params = MMAL_MAX_IMAGEFX_PARAMETERS;
2176 + for (j = 0; j < imagefx.num_effect_params; j++)
2177 + imagefx.effect_parameter[j] =
2178 + v4l2_to_mmal_effects_values[i].effect_params[j];
2180 + dev->colourfx.enable =
2181 + v4l2_to_mmal_effects_values[i].col_fx_enable;
2182 + if (!v4l2_to_mmal_effects_values[i].col_fx_fixed_cbcr) {
2184 + v4l2_to_mmal_effects_values[i].u;
2186 + v4l2_to_mmal_effects_values[i].v;
2189 + control = &dev->component[MMAL_COMPONENT_CAMERA]->control;
2191 + ret = vchiq_mmal_port_parameter_set(
2192 + dev->instance, control,
2193 + MMAL_PARAMETER_IMAGE_EFFECT_PARAMETERS,
2194 + &imagefx, sizeof(imagefx));
2198 + ret = vchiq_mmal_port_parameter_set(
2199 + dev->instance, control,
2200 + MMAL_PARAMETER_COLOUR_EFFECT,
2201 + &dev->colourfx, sizeof(dev->colourfx));
2206 + v4l2_dbg(1, bcm2835_v4l2_debug, &dev->v4l2_dev,
2207 + "mmal_ctrl:%p ctrl id:0x%x ctrl val:%d imagefx:0x%x color_effect:%s u:%d v:%d ret %d(%d)\n",
2208 + mmal_ctrl, ctrl->id, ctrl->val, imagefx.effect,
2209 + dev->colourfx.enable ? "true" : "false",
2210 + dev->colourfx.u, dev->colourfx.v,
2211 + ret, (ret == 0 ? 0 : -EINVAL));
2212 + return (ret == 0 ? 0 : EINVAL);
2215 +static int ctrl_set_colfx(struct bm2835_mmal_dev *dev,
2216 + struct v4l2_ctrl *ctrl,
2217 + const struct bm2835_mmal_v4l2_ctrl *mmal_ctrl)
2219 + int ret = -EINVAL;
2220 + struct vchiq_mmal_port *control;
2222 + control = &dev->component[MMAL_COMPONENT_CAMERA]->control;
2224 + dev->colourfx.enable = (ctrl->val & 0xff00) >> 8;
2225 + dev->colourfx.enable = ctrl->val & 0xff;
2227 + ret = vchiq_mmal_port_parameter_set(dev->instance, control,
2228 + MMAL_PARAMETER_COLOUR_EFFECT,
2229 + &dev->colourfx, sizeof(dev->colourfx));
2231 + v4l2_dbg(1, bcm2835_v4l2_debug, &dev->v4l2_dev,
2232 + "After: mmal_ctrl:%p ctrl id:0x%x ctrl val:%d ret %d(%d)\n",
2233 + mmal_ctrl, ctrl->id, ctrl->val, ret,
2234 + (ret == 0 ? 0 : -EINVAL));
2235 + return (ret == 0 ? 0 : EINVAL);
2238 +static int ctrl_set_bitrate(struct bm2835_mmal_dev *dev,
2239 + struct v4l2_ctrl *ctrl,
2240 + const struct bm2835_mmal_v4l2_ctrl *mmal_ctrl)
2243 + struct vchiq_mmal_port *encoder_out;
2245 + dev->capture.encode_bitrate = ctrl->val;
2247 + encoder_out = &dev->component[MMAL_COMPONENT_VIDEO_ENCODE]->output[0];
2249 + ret = vchiq_mmal_port_parameter_set(dev->instance, encoder_out,
2250 + mmal_ctrl->mmal_id,
2251 + &ctrl->val, sizeof(ctrl->val));
2256 +static int ctrl_set_bitrate_mode(struct bm2835_mmal_dev *dev,
2257 + struct v4l2_ctrl *ctrl,
2258 + const struct bm2835_mmal_v4l2_ctrl *mmal_ctrl)
2261 + struct vchiq_mmal_port *encoder_out;
2263 + encoder_out = &dev->component[MMAL_COMPONENT_VIDEO_ENCODE]->output[0];
2265 + dev->capture.encode_bitrate_mode = ctrl->val;
2266 + switch (ctrl->val) {
2268 + case V4L2_MPEG_VIDEO_BITRATE_MODE_VBR:
2269 + bitrate_mode = MMAL_VIDEO_RATECONTROL_VARIABLE;
2271 + case V4L2_MPEG_VIDEO_BITRATE_MODE_CBR:
2272 + bitrate_mode = MMAL_VIDEO_RATECONTROL_CONSTANT;
2276 + vchiq_mmal_port_parameter_set(dev->instance, encoder_out,
2277 + mmal_ctrl->mmal_id,
2279 + sizeof(bitrate_mode));
2283 +static int ctrl_set_q_factor(struct bm2835_mmal_dev *dev,
2284 + struct v4l2_ctrl *ctrl,
2285 + const struct bm2835_mmal_v4l2_ctrl *mmal_ctrl)
2288 + struct vchiq_mmal_port *jpeg_out;
2290 + jpeg_out = &dev->component[MMAL_COMPONENT_IMAGE_ENCODE]->output[0];
2292 + u32_value = ctrl->val;
2294 + return vchiq_mmal_port_parameter_set(dev->instance, jpeg_out,
2295 + mmal_ctrl->mmal_id,
2296 + &u32_value, sizeof(u32_value));
2299 +static int bm2835_mmal_s_ctrl(struct v4l2_ctrl *ctrl)
2301 + struct bm2835_mmal_dev *dev =
2302 + container_of(ctrl->handler, struct bm2835_mmal_dev,
2304 + const struct bm2835_mmal_v4l2_ctrl *mmal_ctrl = ctrl->priv;
2306 + if ((mmal_ctrl == NULL) ||
2307 + (mmal_ctrl->id != ctrl->id) ||
2308 + (mmal_ctrl->setter == NULL)) {
2309 + pr_warn("mmal_ctrl:%p ctrl id:%d\n", mmal_ctrl, ctrl->id);
2313 + return mmal_ctrl->setter(dev, ctrl, mmal_ctrl);
2316 +static const struct v4l2_ctrl_ops bm2835_mmal_ctrl_ops = {
2317 + .s_ctrl = bm2835_mmal_s_ctrl,
2322 +static const struct bm2835_mmal_v4l2_ctrl v4l2_ctrls[V4L2_CTRL_COUNT] = {
2324 + V4L2_CID_SATURATION, MMAL_CONTROL_TYPE_STD,
2325 + -100, 100, 0, 1, NULL,
2326 + MMAL_PARAMETER_SATURATION, &ctrl_set_rational
2329 + V4L2_CID_SHARPNESS, MMAL_CONTROL_TYPE_STD,
2330 + -100, 100, 0, 1, NULL,
2331 + MMAL_PARAMETER_SHARPNESS, &ctrl_set_rational
2334 + V4L2_CID_CONTRAST, MMAL_CONTROL_TYPE_STD,
2335 + -100, 100, 0, 1, NULL,
2336 + MMAL_PARAMETER_CONTRAST, &ctrl_set_rational
2339 + V4L2_CID_BRIGHTNESS, MMAL_CONTROL_TYPE_STD,
2340 + 0, 100, 50, 1, NULL,
2341 + MMAL_PARAMETER_BRIGHTNESS, &ctrl_set_rational
2344 + V4L2_CID_ISO_SENSITIVITY, MMAL_CONTROL_TYPE_INT_MENU,
2345 + 0, ARRAY_SIZE(iso_qmenu) - 1, 0, 1, iso_qmenu,
2346 + MMAL_PARAMETER_ISO, &ctrl_set_value
2349 + V4L2_CID_IMAGE_STABILIZATION, MMAL_CONTROL_TYPE_STD,
2351 + MMAL_PARAMETER_VIDEO_STABILISATION, &ctrl_set_value
2354 + 0, MMAL_CONTROL_TYPE_CLUSTER, 3, 1, 0, NULL, 0, NULL
2357 + V4L2_CID_EXPOSURE_AUTO, MMAL_CONTROL_TYPE_STD_MENU,
2358 + ~0x03, 3, V4L2_EXPOSURE_AUTO, 0, NULL,
2359 + MMAL_PARAMETER_EXPOSURE_MODE, &ctrl_set_exposure
2361 +/* todo this needs mixing in with set exposure
2363 + V4L2_CID_SCENE_MODE, MMAL_CONTROL_TYPE_STD_MENU,
2367 + V4L2_CID_AUTO_EXPOSURE_BIAS, MMAL_CONTROL_TYPE_INT_MENU,
2368 + 0, ARRAY_SIZE(ev_bias_qmenu) - 1,
2369 + (ARRAY_SIZE(ev_bias_qmenu)+1)/2 - 1, 0, ev_bias_qmenu,
2370 + MMAL_PARAMETER_EXPOSURE_COMP, &ctrl_set_value
2373 + V4L2_CID_EXPOSURE_METERING,
2374 + MMAL_CONTROL_TYPE_STD_MENU,
2375 + ~0x7, 2, V4L2_EXPOSURE_METERING_AVERAGE, 0, NULL,
2376 + MMAL_PARAMETER_EXP_METERING_MODE, &ctrl_set_metering_mode
2379 + V4L2_CID_AUTO_N_PRESET_WHITE_BALANCE,
2380 + MMAL_CONTROL_TYPE_STD_MENU,
2381 + ~0x3fe, 9, V4L2_WHITE_BALANCE_AUTO, 0, NULL,
2382 + MMAL_PARAMETER_AWB_MODE, &ctrl_set_awb_mode
2385 + V4L2_CID_COLORFX, MMAL_CONTROL_TYPE_STD_MENU,
2386 + 0, 15, V4L2_COLORFX_NONE, 0, NULL,
2387 + MMAL_PARAMETER_IMAGE_EFFECT, &ctrl_set_image_effect
2390 + V4L2_CID_COLORFX_CBCR, MMAL_CONTROL_TYPE_STD,
2391 + 0, 0xffff, 0x8080, 1, NULL,
2392 + MMAL_PARAMETER_COLOUR_EFFECT, &ctrl_set_colfx
2395 + V4L2_CID_ROTATE, MMAL_CONTROL_TYPE_STD,
2396 + 0, 360, 0, 90, NULL,
2397 + MMAL_PARAMETER_ROTATION, &ctrl_set_rotate
2400 + V4L2_CID_HFLIP, MMAL_CONTROL_TYPE_STD,
2402 + MMAL_PARAMETER_MIRROR, &ctrl_set_flip
2405 + V4L2_CID_VFLIP, MMAL_CONTROL_TYPE_STD,
2407 + MMAL_PARAMETER_MIRROR, &ctrl_set_flip
2410 + V4L2_CID_MPEG_VIDEO_BITRATE_MODE, MMAL_CONTROL_TYPE_STD_MENU,
2411 + 0, ARRAY_SIZE(bitrate_mode_qmenu) - 1,
2412 + 0, 0, bitrate_mode_qmenu,
2413 + MMAL_PARAMETER_RATECONTROL, &ctrl_set_bitrate_mode
2416 + V4L2_CID_MPEG_VIDEO_BITRATE, MMAL_CONTROL_TYPE_STD,
2417 + 25*1000, 25*1000*1000, 10*1000*1000, 25*1000, NULL,
2418 + MMAL_PARAMETER_VIDEO_BIT_RATE, &ctrl_set_bitrate
2421 + V4L2_CID_JPEG_COMPRESSION_QUALITY, MMAL_CONTROL_TYPE_STD,
2424 + MMAL_PARAMETER_JPEG_Q_FACTOR, &ctrl_set_q_factor
2428 +int bm2835_mmal_set_all_camera_controls(struct bm2835_mmal_dev *dev)
2433 + for (c = 0; c < V4L2_CTRL_COUNT; c++) {
2434 + if ((dev->ctrls[c]) && (v4l2_ctrls[c].setter)) {
2435 + ret = v4l2_ctrls[c].setter(dev, dev->ctrls[c],
2444 +int bm2835_mmal_init_controls(struct bm2835_mmal_dev *dev,
2445 + struct v4l2_ctrl_handler *hdl)
2448 + const struct bm2835_mmal_v4l2_ctrl *ctrl;
2450 + v4l2_ctrl_handler_init(hdl, V4L2_CTRL_COUNT);
2452 + for (c = 0; c < V4L2_CTRL_COUNT; c++) {
2453 + ctrl = &v4l2_ctrls[c];
2455 + switch (ctrl->type) {
2456 + case MMAL_CONTROL_TYPE_STD:
2457 + dev->ctrls[c] = v4l2_ctrl_new_std(hdl,
2458 + &bm2835_mmal_ctrl_ops, ctrl->id,
2459 + ctrl->min, ctrl->max, ctrl->step, ctrl->def);
2462 + case MMAL_CONTROL_TYPE_STD_MENU:
2463 + dev->ctrls[c] = v4l2_ctrl_new_std_menu(hdl,
2464 + &bm2835_mmal_ctrl_ops, ctrl->id,
2465 + ctrl->max, ctrl->min, ctrl->def);
2468 + case MMAL_CONTROL_TYPE_INT_MENU:
2469 + dev->ctrls[c] = v4l2_ctrl_new_int_menu(hdl,
2470 + &bm2835_mmal_ctrl_ops, ctrl->id,
2471 + ctrl->max, ctrl->def, ctrl->imenu);
2474 + case MMAL_CONTROL_TYPE_CLUSTER:
2475 + /* skip this entry when constructing controls */
2482 + dev->ctrls[c]->priv = (void *)ctrl;
2486 + pr_err("error adding control %d/%d id 0x%x\n", c,
2487 + V4L2_CTRL_COUNT, ctrl->id);
2488 + return hdl->error;
2491 + for (c = 0; c < V4L2_CTRL_COUNT; c++) {
2492 + ctrl = &v4l2_ctrls[c];
2494 + switch (ctrl->type) {
2495 + case MMAL_CONTROL_TYPE_CLUSTER:
2496 + v4l2_ctrl_auto_cluster(ctrl->min,
2502 + case MMAL_CONTROL_TYPE_STD:
2503 + case MMAL_CONTROL_TYPE_STD_MENU:
2504 + case MMAL_CONTROL_TYPE_INT_MENU:
2512 diff --git a/drivers/media/platform/bcm2835/mmal-common.h b/drivers/media/platform/bcm2835/mmal-common.h
2513 new file mode 100644
2514 index 0000000..84abbb3
2516 +++ b/drivers/media/platform/bcm2835/mmal-common.h
2519 + * Broadcom BM2835 V4L2 driver
2521 + * Copyright © 2013 Raspberry Pi (Trading) Ltd.
2523 + * This file is subject to the terms and conditions of the GNU General Public
2524 + * License. See the file COPYING in the main directory of this archive
2525 + * for more details.
2527 + * Authors: Vincent Sanders <vincent.sanders@collabora.co.uk>
2528 + * Dave Stevenson <dsteve@broadcom.com>
2529 + * Simon Mellor <simellor@broadcom.com>
2530 + * Luke Diamand <luked@broadcom.com>
2536 +#define MMAL_FOURCC(a, b, c, d) ((a) | (b << 8) | (c << 16) | (d << 24))
2537 +#define MMAL_MAGIC MMAL_FOURCC('m', 'm', 'a', 'l')
2539 +/** Special value signalling that time is not known */
2540 +#define MMAL_TIME_UNKNOWN (1LL<<63)
2542 +/* mapping between v4l and mmal video modes */
2545 + u32 fourcc; /* v4l2 format id */
2548 + u32 mmal_component; /* MMAL component index to be used to encode */
2551 +/* buffer for one video frame */
2552 +struct mmal_buffer {
2553 + /* v4l buffer data -- must be first */
2554 + struct vb2_buffer vb;
2556 + /* list of buffers available */
2557 + struct list_head list;
2559 + void *buffer; /* buffer pointer */
2560 + unsigned long buffer_size; /* size of allocated buffer */
2564 +struct mmal_colourfx {
2569 diff --git a/drivers/media/platform/bcm2835/mmal-encodings.h b/drivers/media/platform/bcm2835/mmal-encodings.h
2570 new file mode 100644
2571 index 0000000..856e80e
2573 +++ b/drivers/media/platform/bcm2835/mmal-encodings.h
2576 + * Broadcom BM2835 V4L2 driver
2578 + * Copyright © 2013 Raspberry Pi (Trading) Ltd.
2580 + * This file is subject to the terms and conditions of the GNU General Public
2581 + * License. See the file COPYING in the main directory of this archive
2582 + * for more details.
2584 + * Authors: Vincent Sanders <vincent.sanders@collabora.co.uk>
2585 + * Dave Stevenson <dsteve@broadcom.com>
2586 + * Simon Mellor <simellor@broadcom.com>
2587 + * Luke Diamand <luked@broadcom.com>
2590 +#define MMAL_ENCODING_H264 MMAL_FOURCC('H', '2', '6', '4')
2591 +#define MMAL_ENCODING_H263 MMAL_FOURCC('H', '2', '6', '3')
2592 +#define MMAL_ENCODING_MP4V MMAL_FOURCC('M', 'P', '4', 'V')
2593 +#define MMAL_ENCODING_MP2V MMAL_FOURCC('M', 'P', '2', 'V')
2594 +#define MMAL_ENCODING_MP1V MMAL_FOURCC('M', 'P', '1', 'V')
2595 +#define MMAL_ENCODING_WMV3 MMAL_FOURCC('W', 'M', 'V', '3')
2596 +#define MMAL_ENCODING_WMV2 MMAL_FOURCC('W', 'M', 'V', '2')
2597 +#define MMAL_ENCODING_WMV1 MMAL_FOURCC('W', 'M', 'V', '1')
2598 +#define MMAL_ENCODING_WVC1 MMAL_FOURCC('W', 'V', 'C', '1')
2599 +#define MMAL_ENCODING_VP8 MMAL_FOURCC('V', 'P', '8', ' ')
2600 +#define MMAL_ENCODING_VP7 MMAL_FOURCC('V', 'P', '7', ' ')
2601 +#define MMAL_ENCODING_VP6 MMAL_FOURCC('V', 'P', '6', ' ')
2602 +#define MMAL_ENCODING_THEORA MMAL_FOURCC('T', 'H', 'E', 'O')
2603 +#define MMAL_ENCODING_SPARK MMAL_FOURCC('S', 'P', 'R', 'K')
2605 +#define MMAL_ENCODING_JPEG MMAL_FOURCC('J', 'P', 'E', 'G')
2606 +#define MMAL_ENCODING_GIF MMAL_FOURCC('G', 'I', 'F', ' ')
2607 +#define MMAL_ENCODING_PNG MMAL_FOURCC('P', 'N', 'G', ' ')
2608 +#define MMAL_ENCODING_PPM MMAL_FOURCC('P', 'P', 'M', ' ')
2609 +#define MMAL_ENCODING_TGA MMAL_FOURCC('T', 'G', 'A', ' ')
2610 +#define MMAL_ENCODING_BMP MMAL_FOURCC('B', 'M', 'P', ' ')
2612 +#define MMAL_ENCODING_I420 MMAL_FOURCC('I', '4', '2', '0')
2613 +#define MMAL_ENCODING_I420_SLICE MMAL_FOURCC('S', '4', '2', '0')
2614 +#define MMAL_ENCODING_YV12 MMAL_FOURCC('Y', 'V', '1', '2')
2615 +#define MMAL_ENCODING_I422 MMAL_FOURCC('I', '4', '2', '2')
2616 +#define MMAL_ENCODING_I422_SLICE MMAL_FOURCC('S', '4', '2', '2')
2617 +#define MMAL_ENCODING_YUYV MMAL_FOURCC('Y', 'U', 'Y', 'V')
2618 +#define MMAL_ENCODING_YVYU MMAL_FOURCC('Y', 'V', 'Y', 'U')
2619 +#define MMAL_ENCODING_UYVY MMAL_FOURCC('U', 'Y', 'V', 'Y')
2620 +#define MMAL_ENCODING_VYUY MMAL_FOURCC('V', 'Y', 'U', 'Y')
2621 +#define MMAL_ENCODING_NV12 MMAL_FOURCC('N', 'V', '1', '2')
2622 +#define MMAL_ENCODING_NV21 MMAL_FOURCC('N', 'V', '2', '1')
2623 +#define MMAL_ENCODING_ARGB MMAL_FOURCC('A', 'R', 'G', 'B')
2624 +#define MMAL_ENCODING_RGBA MMAL_FOURCC('R', 'G', 'B', 'A')
2625 +#define MMAL_ENCODING_ABGR MMAL_FOURCC('A', 'B', 'G', 'R')
2626 +#define MMAL_ENCODING_BGRA MMAL_FOURCC('B', 'G', 'R', 'A')
2627 +#define MMAL_ENCODING_RGB16 MMAL_FOURCC('R', 'G', 'B', '2')
2628 +#define MMAL_ENCODING_RGB24 MMAL_FOURCC('R', 'G', 'B', '3')
2629 +#define MMAL_ENCODING_RGB32 MMAL_FOURCC('R', 'G', 'B', '4')
2630 +#define MMAL_ENCODING_BGR16 MMAL_FOURCC('B', 'G', 'R', '2')
2631 +#define MMAL_ENCODING_BGR24 MMAL_FOURCC('B', 'G', 'R', '3')
2632 +#define MMAL_ENCODING_BGR32 MMAL_FOURCC('B', 'G', 'R', '4')
2634 +/** SAND Video (YUVUV128) format, native format understood by VideoCore.
2635 + * This format is *not* opaque - if requested you will receive full frames
2636 + * of YUV_UV video.
2638 +#define MMAL_ENCODING_YUVUV128 MMAL_FOURCC('S', 'A', 'N', 'D')
2640 +/** VideoCore opaque image format, image handles are returned to
2641 + * the host but not the actual image data.
2643 +#define MMAL_ENCODING_OPAQUE MMAL_FOURCC('O', 'P', 'Q', 'V')
2645 +/** An EGL image handle
2647 +#define MMAL_ENCODING_EGL_IMAGE MMAL_FOURCC('E', 'G', 'L', 'I')
2651 +/** \name Pre-defined audio encodings */
2653 +#define MMAL_ENCODING_PCM_UNSIGNED_BE MMAL_FOURCC('P', 'C', 'M', 'U')
2654 +#define MMAL_ENCODING_PCM_UNSIGNED_LE MMAL_FOURCC('p', 'c', 'm', 'u')
2655 +#define MMAL_ENCODING_PCM_SIGNED_BE MMAL_FOURCC('P', 'C', 'M', 'S')
2656 +#define MMAL_ENCODING_PCM_SIGNED_LE MMAL_FOURCC('p', 'c', 'm', 's')
2657 +#define MMAL_ENCODING_PCM_FLOAT_BE MMAL_FOURCC('P', 'C', 'M', 'F')
2658 +#define MMAL_ENCODING_PCM_FLOAT_LE MMAL_FOURCC('p', 'c', 'm', 'f')
2660 +/* Pre-defined H264 encoding variants */
2662 +/** ISO 14496-10 Annex B byte stream format */
2663 +#define MMAL_ENCODING_VARIANT_H264_DEFAULT 0
2664 +/** ISO 14496-15 AVC stream format */
2665 +#define MMAL_ENCODING_VARIANT_H264_AVC1 MMAL_FOURCC('A', 'V', 'C', '1')
2666 +/** Implicitly delineated NAL units without emulation prevention */
2667 +#define MMAL_ENCODING_VARIANT_H264_RAW MMAL_FOURCC('R', 'A', 'W', ' ')
2668 diff --git a/drivers/media/platform/bcm2835/mmal-msg-common.h b/drivers/media/platform/bcm2835/mmal-msg-common.h
2669 new file mode 100644
2670 index 0000000..66e8a6e
2672 +++ b/drivers/media/platform/bcm2835/mmal-msg-common.h
2675 + * Broadcom BM2835 V4L2 driver
2677 + * Copyright © 2013 Raspberry Pi (Trading) Ltd.
2679 + * This file is subject to the terms and conditions of the GNU General Public
2680 + * License. See the file COPYING in the main directory of this archive
2681 + * for more details.
2683 + * Authors: Vincent Sanders <vincent.sanders@collabora.co.uk>
2684 + * Dave Stevenson <dsteve@broadcom.com>
2685 + * Simon Mellor <simellor@broadcom.com>
2686 + * Luke Diamand <luked@broadcom.com>
2689 +#ifndef MMAL_MSG_COMMON_H
2690 +#define MMAL_MSG_COMMON_H
2692 +enum mmal_msg_status {
2693 + MMAL_MSG_STATUS_SUCCESS = 0, /**< Success */
2694 + MMAL_MSG_STATUS_ENOMEM, /**< Out of memory */
2695 + MMAL_MSG_STATUS_ENOSPC, /**< Out of resources other than memory */
2696 + MMAL_MSG_STATUS_EINVAL, /**< Argument is invalid */
2697 + MMAL_MSG_STATUS_ENOSYS, /**< Function not implemented */
2698 + MMAL_MSG_STATUS_ENOENT, /**< No such file or directory */
2699 + MMAL_MSG_STATUS_ENXIO, /**< No such device or address */
2700 + MMAL_MSG_STATUS_EIO, /**< I/O error */
2701 + MMAL_MSG_STATUS_ESPIPE, /**< Illegal seek */
2702 + MMAL_MSG_STATUS_ECORRUPT, /**< Data is corrupt \attention */
2703 + MMAL_MSG_STATUS_ENOTREADY, /**< Component is not ready */
2704 + MMAL_MSG_STATUS_ECONFIG, /**< Component is not configured */
2705 + MMAL_MSG_STATUS_EISCONN, /**< Port is already connected */
2706 + MMAL_MSG_STATUS_ENOTCONN, /**< Port is disconnected */
2707 + MMAL_MSG_STATUS_EAGAIN, /**< Resource temporarily unavailable. */
2708 + MMAL_MSG_STATUS_EFAULT, /**< Bad address */
2712 + s32 x; /**< x coordinate (from left) */
2713 + s32 y; /**< y coordinate (from top) */
2714 + s32 width; /**< width */
2715 + s32 height; /**< height */
2718 +struct mmal_rational {
2719 + s32 num; /**< Numerator */
2720 + s32 den; /**< Denominator */
2723 +#endif /* MMAL_MSG_COMMON_H */
2724 diff --git a/drivers/media/platform/bcm2835/mmal-msg-format.h b/drivers/media/platform/bcm2835/mmal-msg-format.h
2725 new file mode 100644
2726 index 0000000..123d86e
2728 +++ b/drivers/media/platform/bcm2835/mmal-msg-format.h
2731 + * Broadcom BM2835 V4L2 driver
2733 + * Copyright © 2013 Raspberry Pi (Trading) Ltd.
2735 + * This file is subject to the terms and conditions of the GNU General Public
2736 + * License. See the file COPYING in the main directory of this archive
2737 + * for more details.
2739 + * Authors: Vincent Sanders <vincent.sanders@collabora.co.uk>
2740 + * Dave Stevenson <dsteve@broadcom.com>
2741 + * Simon Mellor <simellor@broadcom.com>
2742 + * Luke Diamand <luked@broadcom.com>
2745 +#ifndef MMAL_MSG_FORMAT_H
2746 +#define MMAL_MSG_FORMAT_H
2748 +#include "mmal-msg-common.h"
2750 +/* MMAL_ES_FORMAT_T */
2753 +struct mmal_audio_format {
2754 + u32 channels; /**< Number of audio channels */
2755 + u32 sample_rate; /**< Sample rate */
2757 + u32 bits_per_sample; /**< Bits per sample */
2758 + u32 block_align; /**< Size of a block of data */
2761 +struct mmal_video_format {
2762 + u32 width; /**< Width of frame in pixels */
2763 + u32 height; /**< Height of frame in rows of pixels */
2764 + struct mmal_rect crop; /**< Visible region of the frame */
2765 + struct mmal_rational frame_rate; /**< Frame rate */
2766 + struct mmal_rational par; /**< Pixel aspect ratio */
2768 + /* FourCC specifying the color space of the video stream. See the
2769 + * \ref MmalColorSpace "pre-defined color spaces" for some examples.
2774 +struct mmal_subpicture_format {
2779 +union mmal_es_specific_format {
2780 + struct mmal_audio_format audio;
2781 + struct mmal_video_format video;
2782 + struct mmal_subpicture_format subpicture;
2785 +/** Definition of an elementary stream format (MMAL_ES_FORMAT_T) */
2786 +struct mmal_es_format {
2787 + u32 type; /* enum mmal_es_type */
2789 + u32 encoding; /* FourCC specifying encoding of the elementary stream.*/
2790 + u32 encoding_variant; /* FourCC specifying the specific
2791 + * encoding variant of the elementary
2795 + union mmal_es_specific_format *es; /* TODO: pointers in
2796 + * message serialisation?!?
2799 + * information for the
2800 + * elementary stream
2803 + u32 bitrate; /**< Bitrate in bits per second */
2804 + u32 flags; /**< Flags describing properties of the elementary stream. */
2806 + u32 extradata_size; /**< Size of the codec specific data */
2807 + u8 *extradata; /**< Codec specific data */
2810 +#endif /* MMAL_MSG_FORMAT_H */
2811 diff --git a/drivers/media/platform/bcm2835/mmal-msg-port.h b/drivers/media/platform/bcm2835/mmal-msg-port.h
2812 new file mode 100644
2813 index 0000000..a55c1ea
2815 +++ b/drivers/media/platform/bcm2835/mmal-msg-port.h
2818 + * Broadcom BM2835 V4L2 driver
2820 + * Copyright © 2013 Raspberry Pi (Trading) Ltd.
2822 + * This file is subject to the terms and conditions of the GNU General Public
2823 + * License. See the file COPYING in the main directory of this archive
2824 + * for more details.
2826 + * Authors: Vincent Sanders <vincent.sanders@collabora.co.uk>
2827 + * Dave Stevenson <dsteve@broadcom.com>
2828 + * Simon Mellor <simellor@broadcom.com>
2829 + * Luke Diamand <luked@broadcom.com>
2832 +/* MMAL_PORT_TYPE_T */
2833 +enum mmal_port_type {
2834 + MMAL_PORT_TYPE_UNKNOWN = 0, /**< Unknown port type */
2835 + MMAL_PORT_TYPE_CONTROL, /**< Control port */
2836 + MMAL_PORT_TYPE_INPUT, /**< Input port */
2837 + MMAL_PORT_TYPE_OUTPUT, /**< Output port */
2838 + MMAL_PORT_TYPE_CLOCK, /**< Clock port */
2841 +/** The port is pass-through and doesn't need buffer headers allocated */
2842 +#define MMAL_PORT_CAPABILITY_PASSTHROUGH 0x01
2843 +/** The port wants to allocate the buffer payloads.
2844 + * This signals a preference that payload allocation should be done
2845 + * on this port for efficiency reasons. */
2846 +#define MMAL_PORT_CAPABILITY_ALLOCATION 0x02
2847 +/** The port supports format change events.
2848 + * This applies to input ports and is used to let the client know
2849 + * whether the port supports being reconfigured via a format
2850 + * change event (i.e. without having to disable the port). */
2851 +#define MMAL_PORT_CAPABILITY_SUPPORTS_EVENT_FORMAT_CHANGE 0x04
2853 +/* mmal port structure (MMAL_PORT_T)
2855 + * most elements are informational only, the pointer values for
2856 + * interogation messages are generally provided as additional
2857 + * strucures within the message. When used to set values only teh
2858 + * buffer_num, buffer_size and userdata parameters are writable.
2861 + void *priv; /* Private member used by the framework */
2862 + const char *name; /* Port name. Used for debugging purposes (RO) */
2864 + u32 type; /* Type of the port (RO) enum mmal_port_type */
2865 + u16 index; /* Index of the port in its type list (RO) */
2866 + u16 index_all; /* Index of the port in the list of all ports (RO) */
2868 + u32 is_enabled; /* Indicates whether the port is enabled or not (RO) */
2869 + struct mmal_es_format *format; /* Format of the elementary stream */
2871 + u32 buffer_num_min; /* Minimum number of buffers the port
2872 + * requires (RO). This is set by the
2876 + u32 buffer_size_min; /* Minimum size of buffers the port
2877 + * requires (RO). This is set by the
2881 + u32 buffer_alignment_min; /* Minimum alignment requirement for
2882 + * the buffers (RO). A value of
2883 + * zero means no special alignment
2884 + * requirements. This is set by the
2888 + u32 buffer_num_recommended; /* Number of buffers the port
2889 + * recommends for optimal
2890 + * performance (RO). A value of
2891 + * zero means no special
2892 + * recommendation. This is set
2893 + * by the component.
2896 + u32 buffer_size_recommended; /* Size of buffers the port
2897 + * recommends for optimal
2898 + * performance (RO). A value of
2899 + * zero means no special
2900 + * recommendation. This is set
2901 + * by the component.
2904 + u32 buffer_num; /* Actual number of buffers the port will use.
2905 + * This is set by the client.
2908 + u32 buffer_size; /* Actual maximum size of the buffers that
2909 + * will be sent to the port. This is set by
2913 + void *component; /* Component this port belongs to (Read Only) */
2915 + void *userdata; /* Field reserved for use by the client */
2917 + u32 capabilities; /* Flags describing the capabilities of a
2918 + * port (RO). Bitwise combination of \ref
2919 + * portcapabilities "Port capabilities"
2924 diff --git a/drivers/media/platform/bcm2835/mmal-msg.h b/drivers/media/platform/bcm2835/mmal-msg.h
2925 new file mode 100644
2926 index 0000000..67b1076
2928 +++ b/drivers/media/platform/bcm2835/mmal-msg.h
2931 + * Broadcom BM2835 V4L2 driver
2933 + * Copyright © 2013 Raspberry Pi (Trading) Ltd.
2935 + * This file is subject to the terms and conditions of the GNU General Public
2936 + * License. See the file COPYING in the main directory of this archive
2937 + * for more details.
2939 + * Authors: Vincent Sanders <vincent.sanders@collabora.co.uk>
2940 + * Dave Stevenson <dsteve@broadcom.com>
2941 + * Simon Mellor <simellor@broadcom.com>
2942 + * Luke Diamand <luked@broadcom.com>
2945 +/* all the data structures which serialise the MMAL protocol. note
2946 + * these are directly mapped onto the recived message data.
2948 + * BEWARE: They seem to *assume* pointers are u32 and that there is no
2949 + * structure padding!
2951 + * NOTE: this implementation uses kernel types to ensure sizes. Rather
2952 + * than assigning values to enums to force their size the
2953 + * implementation uses fixed size types and not the enums (though the
2954 + * comments have the actual enum type
2957 +#define VC_MMAL_VER 15
2958 +#define VC_MMAL_MIN_VER 10
2959 +#define VC_MMAL_SERVER_NAME MAKE_FOURCC("mmal")
2961 +/* max total message size is 512 bytes */
2962 +#define MMAL_MSG_MAX_SIZE 512
2963 +/* with six 32bit header elements max payload is therefore 488 bytes */
2964 +#define MMAL_MSG_MAX_PAYLOAD 488
2966 +#include "mmal-msg-common.h"
2967 +#include "mmal-msg-format.h"
2968 +#include "mmal-msg-port.h"
2970 +enum mmal_msg_type {
2971 + MMAL_MSG_TYPE_QUIT = 1,
2972 + MMAL_MSG_TYPE_SERVICE_CLOSED,
2973 + MMAL_MSG_TYPE_GET_VERSION,
2974 + MMAL_MSG_TYPE_COMPONENT_CREATE,
2975 + MMAL_MSG_TYPE_COMPONENT_DESTROY, /* 5 */
2976 + MMAL_MSG_TYPE_COMPONENT_ENABLE,
2977 + MMAL_MSG_TYPE_COMPONENT_DISABLE,
2978 + MMAL_MSG_TYPE_PORT_INFO_GET,
2979 + MMAL_MSG_TYPE_PORT_INFO_SET,
2980 + MMAL_MSG_TYPE_PORT_ACTION, /* 10 */
2981 + MMAL_MSG_TYPE_BUFFER_FROM_HOST,
2982 + MMAL_MSG_TYPE_BUFFER_TO_HOST,
2983 + MMAL_MSG_TYPE_GET_STATS,
2984 + MMAL_MSG_TYPE_PORT_PARAMETER_SET,
2985 + MMAL_MSG_TYPE_PORT_PARAMETER_GET, /* 15 */
2986 + MMAL_MSG_TYPE_EVENT_TO_HOST,
2987 + MMAL_MSG_TYPE_GET_CORE_STATS_FOR_PORT,
2988 + MMAL_MSG_TYPE_OPAQUE_ALLOCATOR,
2989 + MMAL_MSG_TYPE_CONSUME_MEM,
2990 + MMAL_MSG_TYPE_LMK, /* 20 */
2991 + MMAL_MSG_TYPE_OPAQUE_ALLOCATOR_DESC,
2992 + MMAL_MSG_TYPE_DRM_GET_LHS32,
2993 + MMAL_MSG_TYPE_DRM_GET_TIME,
2994 + MMAL_MSG_TYPE_BUFFER_FROM_HOST_ZEROLEN,
2995 + MMAL_MSG_TYPE_PORT_FLUSH, /* 25 */
2996 + MMAL_MSG_TYPE_HOST_LOG,
2997 + MMAL_MSG_TYPE_MSG_LAST
3000 +/* port action request messages differ depending on the action type */
3001 +enum mmal_msg_port_action_type {
3002 + MMAL_MSG_PORT_ACTION_TYPE_UNKNOWN = 0, /* Unkown action */
3003 + MMAL_MSG_PORT_ACTION_TYPE_ENABLE, /* Enable a port */
3004 + MMAL_MSG_PORT_ACTION_TYPE_DISABLE, /* Disable a port */
3005 + MMAL_MSG_PORT_ACTION_TYPE_FLUSH, /* Flush a port */
3006 + MMAL_MSG_PORT_ACTION_TYPE_CONNECT, /* Connect ports */
3007 + MMAL_MSG_PORT_ACTION_TYPE_DISCONNECT, /* Disconnect ports */
3008 + MMAL_MSG_PORT_ACTION_TYPE_SET_REQUIREMENTS, /* Set buffer requirements*/
3011 +struct mmal_msg_header {
3013 + u32 type; /** enum mmal_msg_type */
3015 + /* Opaque handle to the control service */
3016 + struct mmal_control_service *control_service;
3018 + struct mmal_msg_context *context; /** a u32 per message context */
3019 + u32 status; /** The status of the vchiq operation */
3023 +/* Send from VC to host to report version */
3024 +struct mmal_msg_version {
3031 +/* request to VC to create component */
3032 +struct mmal_msg_component_create {
3033 + void *client_component; /* component context */
3035 + u32 pid; /* For debug */
3038 +/* reply from VC to component creation request */
3039 +struct mmal_msg_component_create_reply {
3040 + u32 status; /** enum mmal_msg_status - how does this differ to
3041 + * the one in the header?
3043 + u32 component_handle; /* VideoCore handle for component */
3044 + u32 input_num; /* Number of input ports */
3045 + u32 output_num; /* Number of output ports */
3046 + u32 clock_num; /* Number of clock ports */
3049 +/* request to VC to destroy a component */
3050 +struct mmal_msg_component_destroy {
3051 + u32 component_handle;
3054 +struct mmal_msg_component_destroy_reply {
3055 + u32 status; /** The component destruction status */
3059 +/* request and reply to VC to enable a component */
3060 +struct mmal_msg_component_enable {
3061 + u32 component_handle;
3064 +struct mmal_msg_component_enable_reply {
3065 + u32 status; /** The component enable status */
3069 +/* request and reply to VC to disable a component */
3070 +struct mmal_msg_component_disable {
3071 + u32 component_handle;
3074 +struct mmal_msg_component_disable_reply {
3075 + u32 status; /** The component disable status */
3078 +/* request to VC to get port information */
3079 +struct mmal_msg_port_info_get {
3080 + u32 component_handle; /* component handle port is associated with */
3081 + u32 port_type; /* enum mmal_msg_port_type */
3082 + u32 index; /* port index to query */
3085 +/* reply from VC to get port info request */
3086 +struct mmal_msg_port_info_get_reply {
3087 + u32 status; /** enum mmal_msg_status */
3088 + u32 component_handle; /* component handle port is associated with */
3089 + u32 port_type; /* enum mmal_msg_port_type */
3090 + u32 port_index; /* port indexed in query */
3091 + s32 found; /* unused */
3092 + u32 port_handle; /**< Handle to use for this port */
3093 + struct mmal_port port;
3094 + struct mmal_es_format format; /* elementry stream format */
3095 + union mmal_es_specific_format es; /* es type specific data */
3096 + u8 extradata[MMAL_FORMAT_EXTRADATA_MAX_SIZE]; /* es extra data */
3099 +/* request to VC to set port information */
3100 +struct mmal_msg_port_info_set {
3101 + u32 component_handle;
3102 + u32 port_type; /* enum mmal_msg_port_type */
3103 + u32 port_index; /* port indexed in query */
3104 + struct mmal_port port;
3105 + struct mmal_es_format format;
3106 + union mmal_es_specific_format es;
3107 + u8 extradata[MMAL_FORMAT_EXTRADATA_MAX_SIZE];
3110 +/* reply from VC to port info set request */
3111 +struct mmal_msg_port_info_set_reply {
3113 + u32 component_handle; /* component handle port is associated with */
3114 + u32 port_type; /* enum mmal_msg_port_type */
3115 + u32 index; /* port indexed in query */
3116 + s32 found; /* unused */
3117 + u32 port_handle; /**< Handle to use for this port */
3118 + struct mmal_port port;
3119 + struct mmal_es_format format;
3120 + union mmal_es_specific_format es;
3121 + u8 extradata[MMAL_FORMAT_EXTRADATA_MAX_SIZE];
3125 +/* port action requests that take a mmal_port as a parameter */
3126 +struct mmal_msg_port_action_port {
3127 + u32 component_handle;
3129 + u32 action; /* enum mmal_msg_port_action_type */
3130 + struct mmal_port port;
3133 +/* port action requests that take handles as a parameter */
3134 +struct mmal_msg_port_action_handle {
3135 + u32 component_handle;
3137 + u32 action; /* enum mmal_msg_port_action_type */
3138 + u32 connect_component_handle;
3139 + u32 connect_port_handle;
3142 +struct mmal_msg_port_action_reply {
3143 + u32 status; /** The port action operation status */
3149 +/* MMAL buffer transfer */
3151 +/** Size of space reserved in a buffer message for short messages. */
3152 +#define MMAL_VC_SHORT_DATA 128
3154 +/** Signals that the current payload is the end of the stream of data */
3155 +#define MMAL_BUFFER_HEADER_FLAG_EOS (1<<0)
3156 +/** Signals that the start of the current payload starts a frame */
3157 +#define MMAL_BUFFER_HEADER_FLAG_FRAME_START (1<<1)
3158 +/** Signals that the end of the current payload ends a frame */
3159 +#define MMAL_BUFFER_HEADER_FLAG_FRAME_END (1<<2)
3160 +/** Signals that the current payload contains only complete frames (>1) */
3161 +#define MMAL_BUFFER_HEADER_FLAG_FRAME \
3162 + (MMAL_BUFFER_HEADER_FLAG_FRAME_START|MMAL_BUFFER_HEADER_FLAG_FRAME_END)
3163 +/** Signals that the current payload is a keyframe (i.e. self decodable) */
3164 +#define MMAL_BUFFER_HEADER_FLAG_KEYFRAME (1<<3)
3165 +/** Signals a discontinuity in the stream of data (e.g. after a seek).
3166 + * Can be used for instance by a decoder to reset its state */
3167 +#define MMAL_BUFFER_HEADER_FLAG_DISCONTINUITY (1<<4)
3168 +/** Signals a buffer containing some kind of config data for the component
3169 + * (e.g. codec config data) */
3170 +#define MMAL_BUFFER_HEADER_FLAG_CONFIG (1<<5)
3171 +/** Signals an encrypted payload */
3172 +#define MMAL_BUFFER_HEADER_FLAG_ENCRYPTED (1<<6)
3173 +/** Signals a buffer containing side information */
3174 +#define MMAL_BUFFER_HEADER_FLAG_CODECSIDEINFO (1<<7)
3175 +/** Signals a buffer which is the snapshot/postview image from a stills
3178 +#define MMAL_BUFFER_HEADER_FLAGS_SNAPSHOT (1<<8)
3179 +/** Signals a buffer which contains data known to be corrupted */
3180 +#define MMAL_BUFFER_HEADER_FLAG_CORRUPTED (1<<9)
3181 +/** Signals that a buffer failed to be transmitted */
3182 +#define MMAL_BUFFER_HEADER_FLAG_TRANSMISSION_FAILED (1<<10)
3184 +struct mmal_driver_buffer {
3186 + u32 component_handle;
3188 + void *client_context;
3191 +/* buffer header */
3192 +struct mmal_buffer_header {
3193 + struct mmal_buffer_header *next; /* next header */
3194 + void *priv; /* framework private data */
3207 +struct mmal_buffer_header_type_specific {
3218 +struct mmal_msg_buffer_from_host {
3219 + /* The front 32 bytes of the buffer header are copied
3220 + * back to us in the reply to allow for context. This
3221 + * area is used to store two mmal_driver_buffer structures to
3222 + * allow for multiple concurrent service users.
3224 + /* control data */
3225 + struct mmal_driver_buffer drvbuf;
3227 + /* referenced control data for passthrough buffer management */
3228 + struct mmal_driver_buffer drvbuf_ref;
3229 + struct mmal_buffer_header buffer_header; /* buffer header itself */
3230 + struct mmal_buffer_header_type_specific buffer_header_type_specific;
3232 + s32 has_reference;
3234 + /** allows short data to be xfered in control message */
3235 + u32 payload_in_message;
3236 + u8 short_data[MMAL_VC_SHORT_DATA];
3240 +/* port parameter setting */
3242 +#define MMAL_WORKER_PORT_PARAMETER_SPACE 96
3244 +struct mmal_msg_port_parameter_set {
3245 + u32 component_handle; /* component */
3246 + u32 port_handle; /* port */
3247 + u32 id; /* Parameter ID */
3248 + u32 size; /* Parameter size */
3249 + uint32_t value[MMAL_WORKER_PORT_PARAMETER_SPACE];
3252 +struct mmal_msg_port_parameter_set_reply {
3253 + u32 status; /** enum mmal_msg_status todo: how does this
3254 + * differ to the one in the header?
3258 +/* port parameter getting */
3260 +struct mmal_msg_port_parameter_get {
3261 + u32 component_handle; /* component */
3262 + u32 port_handle; /* port */
3263 + u32 id; /* Parameter ID */
3264 + u32 size; /* Parameter size */
3267 +struct mmal_msg_port_parameter_get_reply {
3268 + u32 status; /* Status of mmal_port_parameter_get call */
3269 + u32 id; /* Parameter ID */
3270 + u32 size; /* Parameter size */
3271 + uint32_t value[MMAL_WORKER_PORT_PARAMETER_SPACE];
3274 +/* event messages */
3275 +#define MMAL_WORKER_EVENT_SPACE 256
3277 +struct mmal_msg_event_to_host {
3278 + void *client_component; /* component context */
3285 + u8 data[MMAL_WORKER_EVENT_SPACE];
3286 + struct mmal_buffer_header *delayed_buffer;
3289 +/* all mmal messages are serialised through this structure */
3292 + struct mmal_msg_header h;
3295 + struct mmal_msg_version version;
3297 + struct mmal_msg_component_create component_create;
3298 + struct mmal_msg_component_create_reply component_create_reply;
3300 + struct mmal_msg_component_destroy component_destroy;
3301 + struct mmal_msg_component_destroy_reply component_destroy_reply;
3303 + struct mmal_msg_component_enable component_enable;
3304 + struct mmal_msg_component_enable_reply component_enable_reply;
3306 + struct mmal_msg_component_disable component_disable;
3307 + struct mmal_msg_component_disable_reply component_disable_reply;
3309 + struct mmal_msg_port_info_get port_info_get;
3310 + struct mmal_msg_port_info_get_reply port_info_get_reply;
3312 + struct mmal_msg_port_info_set port_info_set;
3313 + struct mmal_msg_port_info_set_reply port_info_set_reply;
3315 + struct mmal_msg_port_action_port port_action_port;
3316 + struct mmal_msg_port_action_handle port_action_handle;
3317 + struct mmal_msg_port_action_reply port_action_reply;
3319 + struct mmal_msg_buffer_from_host buffer_from_host;
3321 + struct mmal_msg_port_parameter_set port_parameter_set;
3322 + struct mmal_msg_port_parameter_set_reply
3323 + port_parameter_set_reply;
3324 + struct mmal_msg_port_parameter_get
3325 + port_parameter_get;
3326 + struct mmal_msg_port_parameter_get_reply
3327 + port_parameter_get_reply;
3329 + struct mmal_msg_event_to_host event_to_host;
3331 + u8 payload[MMAL_MSG_MAX_PAYLOAD];
3334 diff --git a/drivers/media/platform/bcm2835/mmal-parameters.h b/drivers/media/platform/bcm2835/mmal-parameters.h
3335 new file mode 100644
3336 index 0000000..c611b58
3338 +++ b/drivers/media/platform/bcm2835/mmal-parameters.h
3341 + * Broadcom BM2835 V4L2 driver
3343 + * Copyright © 2013 Raspberry Pi (Trading) Ltd.
3345 + * This file is subject to the terms and conditions of the GNU General Public
3346 + * License. See the file COPYING in the main directory of this archive
3347 + * for more details.
3349 + * Authors: Vincent Sanders <vincent.sanders@collabora.co.uk>
3350 + * Dave Stevenson <dsteve@broadcom.com>
3351 + * Simon Mellor <simellor@broadcom.com>
3352 + * Luke Diamand <luked@broadcom.com>
3355 +/* common parameters */
3357 +/** @name Parameter groups
3358 + * Parameters are divided into groups, and then allocated sequentially within
3359 + * a group using an enum.
3363 +/** Common parameter ID group, used with many types of component. */
3364 +#define MMAL_PARAMETER_GROUP_COMMON (0<<16)
3365 +/** Camera-specific parameter ID group. */
3366 +#define MMAL_PARAMETER_GROUP_CAMERA (1<<16)
3367 +/** Video-specific parameter ID group. */
3368 +#define MMAL_PARAMETER_GROUP_VIDEO (2<<16)
3369 +/** Audio-specific parameter ID group. */
3370 +#define MMAL_PARAMETER_GROUP_AUDIO (3<<16)
3371 +/** Clock-specific parameter ID group. */
3372 +#define MMAL_PARAMETER_GROUP_CLOCK (4<<16)
3373 +/** Miracast-specific parameter ID group. */
3374 +#define MMAL_PARAMETER_GROUP_MIRACAST (5<<16)
3376 +/* Common parameters */
3377 +enum mmal_parameter_common_type {
3378 + MMAL_PARAMETER_UNUSED /**< Never a valid parameter ID */
3379 + = MMAL_PARAMETER_GROUP_COMMON,
3380 + MMAL_PARAMETER_SUPPORTED_ENCODINGS, /**< MMAL_PARAMETER_ENCODING_T */
3381 + MMAL_PARAMETER_URI, /**< MMAL_PARAMETER_URI_T */
3383 + /** MMAL_PARAMETER_CHANGE_EVENT_REQUEST_T */
3384 + MMAL_PARAMETER_CHANGE_EVENT_REQUEST,
3386 + /** MMAL_PARAMETER_BOOLEAN_T */
3387 + MMAL_PARAMETER_ZERO_COPY,
3389 + /**< MMAL_PARAMETER_BUFFER_REQUIREMENTS_T */
3390 + MMAL_PARAMETER_BUFFER_REQUIREMENTS,
3392 + MMAL_PARAMETER_STATISTICS, /**< MMAL_PARAMETER_STATISTICS_T */
3393 + MMAL_PARAMETER_CORE_STATISTICS, /**< MMAL_PARAMETER_CORE_STATISTICS_T */
3394 + MMAL_PARAMETER_MEM_USAGE, /**< MMAL_PARAMETER_MEM_USAGE_T */
3395 + MMAL_PARAMETER_BUFFER_FLAG_FILTER, /**< MMAL_PARAMETER_UINT32_T */
3396 + MMAL_PARAMETER_SEEK, /**< MMAL_PARAMETER_SEEK_T */
3397 + MMAL_PARAMETER_POWERMON_ENABLE, /**< MMAL_PARAMETER_BOOLEAN_T */
3398 + MMAL_PARAMETER_LOGGING, /**< MMAL_PARAMETER_LOGGING_T */
3399 + MMAL_PARAMETER_SYSTEM_TIME /**< MMAL_PARAMETER_UINT64_T */
3402 +/* camera parameters */
3404 +enum mmal_parameter_camera_type {
3406 + /** @ref MMAL_PARAMETER_THUMBNAIL_CONFIG_T */
3407 + MMAL_PARAMETER_THUMBNAIL_CONFIGURATION
3408 + = MMAL_PARAMETER_GROUP_CAMERA,
3409 + MMAL_PARAMETER_CAPTURE_QUALITY, /**< Unused? */
3410 + MMAL_PARAMETER_ROTATION, /**< @ref MMAL_PARAMETER_INT32_T */
3411 + MMAL_PARAMETER_EXIF_DISABLE, /**< @ref MMAL_PARAMETER_BOOLEAN_T */
3412 + MMAL_PARAMETER_EXIF, /**< @ref MMAL_PARAMETER_EXIF_T */
3413 + MMAL_PARAMETER_AWB_MODE, /**< @ref MMAL_PARAM_AWBMODE_T */
3414 + MMAL_PARAMETER_IMAGE_EFFECT, /**< @ref MMAL_PARAMETER_IMAGEFX_T */
3415 + MMAL_PARAMETER_COLOUR_EFFECT, /**< @ref MMAL_PARAMETER_COLOURFX_T */
3416 + MMAL_PARAMETER_FLICKER_AVOID, /**< @ref MMAL_PARAMETER_FLICKERAVOID_T */
3417 + MMAL_PARAMETER_FLASH, /**< @ref MMAL_PARAMETER_FLASH_T */
3418 + MMAL_PARAMETER_REDEYE, /**< @ref MMAL_PARAMETER_REDEYE_T */
3419 + MMAL_PARAMETER_FOCUS, /**< @ref MMAL_PARAMETER_FOCUS_T */
3420 + MMAL_PARAMETER_FOCAL_LENGTHS, /**< Unused? */
3421 + MMAL_PARAMETER_EXPOSURE_COMP, /**< @ref MMAL_PARAMETER_INT32_T */
3422 + MMAL_PARAMETER_ZOOM, /**< @ref MMAL_PARAMETER_SCALEFACTOR_T */
3423 + MMAL_PARAMETER_MIRROR, /**< @ref MMAL_PARAMETER_MIRROR_T */
3426 + MMAL_PARAMETER_CAMERA_NUM, /**< @ref MMAL_PARAMETER_UINT32_T */
3427 + MMAL_PARAMETER_CAPTURE, /**< @ref MMAL_PARAMETER_BOOLEAN_T */
3428 + MMAL_PARAMETER_EXPOSURE_MODE, /**< @ref MMAL_PARAMETER_EXPOSUREMODE_T */
3429 + MMAL_PARAMETER_EXP_METERING_MODE, /**< @ref MMAL_PARAMETER_EXPOSUREMETERINGMODE_T */
3430 + MMAL_PARAMETER_FOCUS_STATUS, /**< @ref MMAL_PARAMETER_FOCUS_STATUS_T */
3431 + MMAL_PARAMETER_CAMERA_CONFIG, /**< @ref MMAL_PARAMETER_CAMERA_CONFIG_T */
3432 + MMAL_PARAMETER_CAPTURE_STATUS, /**< @ref MMAL_PARAMETER_CAPTURE_STATUS_T */
3433 + MMAL_PARAMETER_FACE_TRACK, /**< @ref MMAL_PARAMETER_FACE_TRACK_T */
3434 + MMAL_PARAMETER_DRAW_BOX_FACES_AND_FOCUS, /**< @ref MMAL_PARAMETER_BOOLEAN_T */
3435 + MMAL_PARAMETER_JPEG_Q_FACTOR, /**< @ref MMAL_PARAMETER_UINT32_T */
3436 + MMAL_PARAMETER_FRAME_RATE, /**< @ref MMAL_PARAMETER_FRAME_RATE_T */
3437 + MMAL_PARAMETER_USE_STC, /**< @ref MMAL_PARAMETER_CAMERA_STC_MODE_T */
3438 + MMAL_PARAMETER_CAMERA_INFO, /**< @ref MMAL_PARAMETER_CAMERA_INFO_T */
3439 + MMAL_PARAMETER_VIDEO_STABILISATION, /**< @ref MMAL_PARAMETER_BOOLEAN_T */
3440 + MMAL_PARAMETER_FACE_TRACK_RESULTS, /**< @ref MMAL_PARAMETER_FACE_TRACK_RESULTS_T */
3441 + MMAL_PARAMETER_ENABLE_RAW_CAPTURE, /**< @ref MMAL_PARAMETER_BOOLEAN_T */
3444 + MMAL_PARAMETER_DPF_FILE, /**< @ref MMAL_PARAMETER_URI_T */
3445 + MMAL_PARAMETER_ENABLE_DPF_FILE, /**< @ref MMAL_PARAMETER_BOOLEAN_T */
3446 + MMAL_PARAMETER_DPF_FAIL_IS_FATAL, /**< @ref MMAL_PARAMETER_BOOLEAN_T */
3447 + MMAL_PARAMETER_CAPTURE_MODE, /**< @ref MMAL_PARAMETER_CAPTUREMODE_T */
3448 + MMAL_PARAMETER_FOCUS_REGIONS, /**< @ref MMAL_PARAMETER_FOCUS_REGIONS_T */
3449 + MMAL_PARAMETER_INPUT_CROP, /**< @ref MMAL_PARAMETER_INPUT_CROP_T */
3450 + MMAL_PARAMETER_SENSOR_INFORMATION, /**< @ref MMAL_PARAMETER_SENSOR_INFORMATION_T */
3451 + MMAL_PARAMETER_FLASH_SELECT, /**< @ref MMAL_PARAMETER_FLASH_SELECT_T */
3452 + MMAL_PARAMETER_FIELD_OF_VIEW, /**< @ref MMAL_PARAMETER_FIELD_OF_VIEW_T */
3453 + MMAL_PARAMETER_HIGH_DYNAMIC_RANGE, /**< @ref MMAL_PARAMETER_BOOLEAN_T */
3454 + MMAL_PARAMETER_DYNAMIC_RANGE_COMPRESSION, /**< @ref MMAL_PARAMETER_DRC_T */
3455 + MMAL_PARAMETER_ALGORITHM_CONTROL, /**< @ref MMAL_PARAMETER_ALGORITHM_CONTROL_T */
3456 + MMAL_PARAMETER_SHARPNESS, /**< @ref MMAL_PARAMETER_RATIONAL_T */
3457 + MMAL_PARAMETER_CONTRAST, /**< @ref MMAL_PARAMETER_RATIONAL_T */
3458 + MMAL_PARAMETER_BRIGHTNESS, /**< @ref MMAL_PARAMETER_RATIONAL_T */
3459 + MMAL_PARAMETER_SATURATION, /**< @ref MMAL_PARAMETER_RATIONAL_T */
3462 + MMAL_PARAMETER_ISO, /**< @ref MMAL_PARAMETER_UINT32_T */
3463 + MMAL_PARAMETER_ANTISHAKE, /**< @ref MMAL_PARAMETER_BOOLEAN_T */
3465 + /** @ref MMAL_PARAMETER_IMAGEFX_PARAMETERS_T */
3466 + MMAL_PARAMETER_IMAGE_EFFECT_PARAMETERS,
3468 + /** @ref MMAL_PARAMETER_BOOLEAN_T */
3469 + MMAL_PARAMETER_CAMERA_BURST_CAPTURE,
3471 + /** @ref MMAL_PARAMETER_UINT32_T */
3472 + MMAL_PARAMETER_CAMERA_MIN_ISO,
3474 + /** @ref MMAL_PARAMETER_CAMERA_USE_CASE_T */
3475 + MMAL_PARAMETER_CAMERA_USE_CASE,
3477 + /**< @ref MMAL_PARAMETER_BOOLEAN_T */
3478 + MMAL_PARAMETER_CAPTURE_STATS_PASS,
3480 + /** @ref MMAL_PARAMETER_UINT32_T */
3481 + MMAL_PARAMETER_CAMERA_CUSTOM_SENSOR_CONFIG,
3483 + /** @ref MMAL_PARAMETER_BOOLEAN_T */
3484 + MMAL_PARAMETER_ENABLE_REGISTER_FILE,
3486 + /** @ref MMAL_PARAMETER_BOOLEAN_T */
3487 + MMAL_PARAMETER_REGISTER_FAIL_IS_FATAL,
3489 + /** @ref MMAL_PARAMETER_CONFIGFILE_T */
3490 + MMAL_PARAMETER_CONFIGFILE_REGISTERS,
3492 + /** @ref MMAL_PARAMETER_CONFIGFILE_CHUNK_T */
3493 + MMAL_PARAMETER_CONFIGFILE_CHUNK_REGISTERS,
3494 + MMAL_PARAMETER_JPEG_ATTACH_LOG, /**< @ref MMAL_PARAMETER_BOOLEAN_T */
3495 + MMAL_PARAMETER_ZERO_SHUTTER_LAG, /**< @ref MMAL_PARAMETER_ZEROSHUTTERLAG_T */
3496 + MMAL_PARAMETER_FPS_RANGE, /**< @ref MMAL_PARAMETER_FPS_RANGE_T */
3497 + MMAL_PARAMETER_CAPTURE_EXPOSURE_COMP, /**< @ref MMAL_PARAMETER_INT32_T */
3500 + MMAL_PARAMETER_SW_SHARPEN_DISABLE, /**< @ref MMAL_PARAMETER_BOOLEAN_T */
3501 + MMAL_PARAMETER_FLASH_REQUIRED, /**< @ref MMAL_PARAMETER_BOOLEAN_T */
3502 + MMAL_PARAMETER_SW_SATURATION_DISABLE, /**< @ref MMAL_PARAMETER_BOOLEAN_T */
3505 +enum mmal_parameter_camera_config_timestamp_mode {
3506 + MMAL_PARAM_TIMESTAMP_MODE_ZERO = 0, /* Always timestamp frames as 0 */
3507 + MMAL_PARAM_TIMESTAMP_MODE_RAW_STC, /* Use the raw STC value
3508 + * for the frame timestamp
3510 + MMAL_PARAM_TIMESTAMP_MODE_RESET_STC, /* Use the STC timestamp
3511 + * but subtract the
3512 + * timestamp of the first
3513 + * frame sent to give a
3514 + * zero based timestamp.
3518 +/* camera configuration parameter */
3519 +struct mmal_parameter_camera_config {
3520 + /* Parameters for setting up the image pools */
3521 + u32 max_stills_w; /* Max size of stills capture */
3523 + u32 stills_yuv422; /* Allow YUV422 stills capture */
3524 + u32 one_shot_stills; /* Continuous or one shot stills captures. */
3526 + u32 max_preview_video_w; /* Max size of the preview or video
3529 + u32 max_preview_video_h;
3530 + u32 num_preview_video_frames;
3532 + /** Sets the height of the circular buffer for stills capture. */
3533 + u32 stills_capture_circular_buffer_height;
3535 + /** Allows preview/encode to resume as fast as possible after the stills
3536 + * input frame has been received, and then processes the still frame in
3537 + * the background whilst preview/encode has resumed.
3538 + * Actual mode is controlled by MMAL_PARAMETER_CAPTURE_MODE.
3540 + u32 fast_preview_resume;
3542 + /** Selects algorithm for timestamping frames if
3543 + * there is no clock component connected.
3544 + * enum mmal_parameter_camera_config_timestamp_mode
3546 + s32 use_stc_timestamp;
3550 +enum mmal_parameter_exposuremode {
3551 + MMAL_PARAM_EXPOSUREMODE_OFF,
3552 + MMAL_PARAM_EXPOSUREMODE_AUTO,
3553 + MMAL_PARAM_EXPOSUREMODE_NIGHT,
3554 + MMAL_PARAM_EXPOSUREMODE_NIGHTPREVIEW,
3555 + MMAL_PARAM_EXPOSUREMODE_BACKLIGHT,
3556 + MMAL_PARAM_EXPOSUREMODE_SPOTLIGHT,
3557 + MMAL_PARAM_EXPOSUREMODE_SPORTS,
3558 + MMAL_PARAM_EXPOSUREMODE_SNOW,
3559 + MMAL_PARAM_EXPOSUREMODE_BEACH,
3560 + MMAL_PARAM_EXPOSUREMODE_VERYLONG,
3561 + MMAL_PARAM_EXPOSUREMODE_FIXEDFPS,
3562 + MMAL_PARAM_EXPOSUREMODE_ANTISHAKE,
3563 + MMAL_PARAM_EXPOSUREMODE_FIREWORKS,
3566 +enum mmal_parameter_exposuremeteringmode {
3567 + MMAL_PARAM_EXPOSUREMETERINGMODE_AVERAGE,
3568 + MMAL_PARAM_EXPOSUREMETERINGMODE_SPOT,
3569 + MMAL_PARAM_EXPOSUREMETERINGMODE_BACKLIT,
3570 + MMAL_PARAM_EXPOSUREMETERINGMODE_MATRIX,
3573 +enum mmal_parameter_awbmode {
3574 + MMAL_PARAM_AWBMODE_OFF,
3575 + MMAL_PARAM_AWBMODE_AUTO,
3576 + MMAL_PARAM_AWBMODE_SUNLIGHT,
3577 + MMAL_PARAM_AWBMODE_CLOUDY,
3578 + MMAL_PARAM_AWBMODE_SHADE,
3579 + MMAL_PARAM_AWBMODE_TUNGSTEN,
3580 + MMAL_PARAM_AWBMODE_FLUORESCENT,
3581 + MMAL_PARAM_AWBMODE_INCANDESCENT,
3582 + MMAL_PARAM_AWBMODE_FLASH,
3583 + MMAL_PARAM_AWBMODE_HORIZON,
3586 +enum mmal_parameter_imagefx {
3587 + MMAL_PARAM_IMAGEFX_NONE,
3588 + MMAL_PARAM_IMAGEFX_NEGATIVE,
3589 + MMAL_PARAM_IMAGEFX_SOLARIZE,
3590 + MMAL_PARAM_IMAGEFX_POSTERIZE,
3591 + MMAL_PARAM_IMAGEFX_WHITEBOARD,
3592 + MMAL_PARAM_IMAGEFX_BLACKBOARD,
3593 + MMAL_PARAM_IMAGEFX_SKETCH,
3594 + MMAL_PARAM_IMAGEFX_DENOISE,
3595 + MMAL_PARAM_IMAGEFX_EMBOSS,
3596 + MMAL_PARAM_IMAGEFX_OILPAINT,
3597 + MMAL_PARAM_IMAGEFX_HATCH,
3598 + MMAL_PARAM_IMAGEFX_GPEN,
3599 + MMAL_PARAM_IMAGEFX_PASTEL,
3600 + MMAL_PARAM_IMAGEFX_WATERCOLOUR,
3601 + MMAL_PARAM_IMAGEFX_FILM,
3602 + MMAL_PARAM_IMAGEFX_BLUR,
3603 + MMAL_PARAM_IMAGEFX_SATURATION,
3604 + MMAL_PARAM_IMAGEFX_COLOURSWAP,
3605 + MMAL_PARAM_IMAGEFX_WASHEDOUT,
3606 + MMAL_PARAM_IMAGEFX_POSTERISE,
3607 + MMAL_PARAM_IMAGEFX_COLOURPOINT,
3608 + MMAL_PARAM_IMAGEFX_COLOURBALANCE,
3609 + MMAL_PARAM_IMAGEFX_CARTOON,
3612 +/** Manner of video rate control */
3613 +enum mmal_parameter_rate_control_mode {
3614 + MMAL_VIDEO_RATECONTROL_DEFAULT,
3615 + MMAL_VIDEO_RATECONTROL_VARIABLE,
3616 + MMAL_VIDEO_RATECONTROL_CONSTANT,
3617 + MMAL_VIDEO_RATECONTROL_VARIABLE_SKIP_FRAMES,
3618 + MMAL_VIDEO_RATECONTROL_CONSTANT_SKIP_FRAMES
3621 +/* video parameters */
3623 +enum mmal_parameter_video_type {
3624 + /** @ref MMAL_DISPLAYREGION_T */
3625 + MMAL_PARAMETER_DISPLAYREGION = MMAL_PARAMETER_GROUP_VIDEO,
3627 + /** @ref MMAL_PARAMETER_VIDEO_PROFILE_T */
3628 + MMAL_PARAMETER_SUPPORTED_PROFILES,
3630 + /** @ref MMAL_PARAMETER_VIDEO_PROFILE_T */
3631 + MMAL_PARAMETER_PROFILE,
3633 + /** @ref MMAL_PARAMETER_UINT32_T */
3634 + MMAL_PARAMETER_INTRAPERIOD,
3636 + /** @ref MMAL_PARAMETER_VIDEO_RATECONTROL_T */
3637 + MMAL_PARAMETER_RATECONTROL,
3639 + /** @ref MMAL_PARAMETER_VIDEO_NALUNITFORMAT_T */
3640 + MMAL_PARAMETER_NALUNITFORMAT,
3642 + /** @ref MMAL_PARAMETER_BOOLEAN_T */
3643 + MMAL_PARAMETER_MINIMISE_FRAGMENTATION,
3645 + /** @ref MMAL_PARAMETER_UINT32_T.
3646 + * Setting the value to zero resets to the default (one slice per frame).
3648 + MMAL_PARAMETER_MB_ROWS_PER_SLICE,
3650 + /** @ref MMAL_PARAMETER_VIDEO_LEVEL_EXTENSION_T */
3651 + MMAL_PARAMETER_VIDEO_LEVEL_EXTENSION,
3653 + /** @ref MMAL_PARAMETER_VIDEO_EEDE_ENABLE_T */
3654 + MMAL_PARAMETER_VIDEO_EEDE_ENABLE,
3656 + /** @ref MMAL_PARAMETER_VIDEO_EEDE_LOSSRATE_T */
3657 + MMAL_PARAMETER_VIDEO_EEDE_LOSSRATE,
3659 + /** @ref MMAL_PARAMETER_BOOLEAN_T. Request an I-frame. */
3660 + MMAL_PARAMETER_VIDEO_REQUEST_I_FRAME,
3661 + /** @ref MMAL_PARAMETER_VIDEO_INTRA_REFRESH_T */
3662 + MMAL_PARAMETER_VIDEO_INTRA_REFRESH,
3664 + /** @ref MMAL_PARAMETER_BOOLEAN_T. */
3665 + MMAL_PARAMETER_VIDEO_IMMUTABLE_INPUT,
3667 + /** @ref MMAL_PARAMETER_UINT32_T. Run-time bit rate control */
3668 + MMAL_PARAMETER_VIDEO_BIT_RATE,
3670 + /** @ref MMAL_PARAMETER_FRAME_RATE_T */
3671 + MMAL_PARAMETER_VIDEO_FRAME_RATE,
3673 + /** @ref MMAL_PARAMETER_UINT32_T. */
3674 + MMAL_PARAMETER_VIDEO_ENCODE_MIN_QUANT,
3676 + /** @ref MMAL_PARAMETER_UINT32_T. */
3677 + MMAL_PARAMETER_VIDEO_ENCODE_MAX_QUANT,
3679 + /** @ref MMAL_PARAMETER_VIDEO_ENCODE_RC_MODEL_T. */
3680 + MMAL_PARAMETER_VIDEO_ENCODE_RC_MODEL,
3682 + MMAL_PARAMETER_EXTRA_BUFFERS, /**< @ref MMAL_PARAMETER_UINT32_T. */
3683 + /** @ref MMAL_PARAMETER_UINT32_T.
3684 + * Changing this parameter from the default can reduce frame rate
3685 + * because image buffers need to be re-pitched.
3687 + MMAL_PARAMETER_VIDEO_ALIGN_HORIZ,
3689 + /** @ref MMAL_PARAMETER_UINT32_T.
3690 + * Changing this parameter from the default can reduce frame rate
3691 + * because image buffers need to be re-pitched.
3693 + MMAL_PARAMETER_VIDEO_ALIGN_VERT,
3695 + /** @ref MMAL_PARAMETER_BOOLEAN_T. */
3696 + MMAL_PARAMETER_VIDEO_DROPPABLE_PFRAMES,
3698 + /** @ref MMAL_PARAMETER_UINT32_T. */
3699 + MMAL_PARAMETER_VIDEO_ENCODE_INITIAL_QUANT,
3701 + /**< @ref MMAL_PARAMETER_UINT32_T. */
3702 + MMAL_PARAMETER_VIDEO_ENCODE_QP_P,
3704 + /**< @ref MMAL_PARAMETER_UINT32_T. */
3705 + MMAL_PARAMETER_VIDEO_ENCODE_RC_SLICE_DQUANT,
3707 + /** @ref MMAL_PARAMETER_UINT32_T */
3708 + MMAL_PARAMETER_VIDEO_ENCODE_FRAME_LIMIT_BITS,
3710 + /** @ref MMAL_PARAMETER_UINT32_T. */
3711 + MMAL_PARAMETER_VIDEO_ENCODE_PEAK_RATE,
3713 + /* H264 specific parameters */
3715 + /** @ref MMAL_PARAMETER_BOOLEAN_T. */
3716 + MMAL_PARAMETER_VIDEO_ENCODE_H264_DISABLE_CABAC,
3718 + /** @ref MMAL_PARAMETER_BOOLEAN_T. */
3719 + MMAL_PARAMETER_VIDEO_ENCODE_H264_LOW_LATENCY,
3721 + /** @ref MMAL_PARAMETER_BOOLEAN_T. */
3722 + MMAL_PARAMETER_VIDEO_ENCODE_H264_AU_DELIMITERS,
3724 + /** @ref MMAL_PARAMETER_UINT32_T. */
3725 + MMAL_PARAMETER_VIDEO_ENCODE_H264_DEBLOCK_IDC,
3727 + /** @ref MMAL_PARAMETER_VIDEO_ENCODER_H264_MB_INTRA_MODES_T. */
3728 + MMAL_PARAMETER_VIDEO_ENCODE_H264_MB_INTRA_MODE,
3730 + /** @ref MMAL_PARAMETER_BOOLEAN_T */
3731 + MMAL_PARAMETER_VIDEO_ENCODE_HEADER_ON_OPEN,
3733 + /** @ref MMAL_PARAMETER_BOOLEAN_T */
3734 + MMAL_PARAMETER_VIDEO_ENCODE_PRECODE_FOR_QP,
3736 + /** @ref MMAL_PARAMETER_VIDEO_DRM_INIT_INFO_T. */
3737 + MMAL_PARAMETER_VIDEO_DRM_INIT_INFO,
3739 + /** @ref MMAL_PARAMETER_BOOLEAN_T */
3740 + MMAL_PARAMETER_VIDEO_TIMESTAMP_FIFO,
3742 + /** @ref MMAL_PARAMETER_BOOLEAN_T */
3743 + MMAL_PARAMETER_VIDEO_DECODE_ERROR_CONCEALMENT,
3745 + /** @ref MMAL_PARAMETER_VIDEO_DRM_PROTECT_BUFFER_T. */
3746 + MMAL_PARAMETER_VIDEO_DRM_PROTECT_BUFFER,
3748 + /** @ref MMAL_PARAMETER_BYTES_T */
3749 + MMAL_PARAMETER_VIDEO_DECODE_CONFIG_VD3
3752 +/** Valid mirror modes */
3753 +enum mmal_parameter_mirror {
3754 + MMAL_PARAM_MIRROR_NONE,
3755 + MMAL_PARAM_MIRROR_VERTICAL,
3756 + MMAL_PARAM_MIRROR_HORIZONTAL,
3757 + MMAL_PARAM_MIRROR_BOTH,
3760 +enum mmal_parameter_displaytransform {
3761 + MMAL_DISPLAY_ROT0 = 0,
3762 + MMAL_DISPLAY_MIRROR_ROT0 = 1,
3763 + MMAL_DISPLAY_MIRROR_ROT180 = 2,
3764 + MMAL_DISPLAY_ROT180 = 3,
3765 + MMAL_DISPLAY_MIRROR_ROT90 = 4,
3766 + MMAL_DISPLAY_ROT270 = 5,
3767 + MMAL_DISPLAY_ROT90 = 6,
3768 + MMAL_DISPLAY_MIRROR_ROT270 = 7,
3771 +enum mmal_parameter_displaymode {
3772 + MMAL_DISPLAY_MODE_FILL = 0,
3773 + MMAL_DISPLAY_MODE_LETTERBOX = 1,
3776 +enum mmal_parameter_displayset {
3777 + MMAL_DISPLAY_SET_NONE = 0,
3778 + MMAL_DISPLAY_SET_NUM = 1,
3779 + MMAL_DISPLAY_SET_FULLSCREEN = 2,
3780 + MMAL_DISPLAY_SET_TRANSFORM = 4,
3781 + MMAL_DISPLAY_SET_DEST_RECT = 8,
3782 + MMAL_DISPLAY_SET_SRC_RECT = 0x10,
3783 + MMAL_DISPLAY_SET_MODE = 0x20,
3784 + MMAL_DISPLAY_SET_PIXEL = 0x40,
3785 + MMAL_DISPLAY_SET_NOASPECT = 0x80,
3786 + MMAL_DISPLAY_SET_LAYER = 0x100,
3787 + MMAL_DISPLAY_SET_COPYPROTECT = 0x200,
3788 + MMAL_DISPLAY_SET_ALPHA = 0x400,
3791 +struct mmal_parameter_displayregion {
3792 + /** Bitfield that indicates which fields are set and should be
3793 + * used. All other fields will maintain their current value.
3794 + * \ref MMAL_DISPLAYSET_T defines the bits that can be
3799 + /** Describes the display output device, with 0 typically
3800 + * being a directly connected LCD display. The actual values
3801 + * will depend on the hardware. Code using hard-wired numbers
3802 + * (e.g. 2) is certain to fail.
3806 + /** Indicates that we are using the full device screen area,
3807 + * rather than a window of the display. If zero, then
3808 + * dest_rect is used to specify a region of the display to
3813 + /** Indicates any rotation or flipping used to map frames onto
3814 + * the natural display orientation.
3816 + u32 transform; /* enum mmal_parameter_displaytransform */
3818 + /** Where to display the frame within the screen, if
3819 + * fullscreen is zero.
3821 + struct vchiq_mmal_rect dest_rect;
3823 + /** Indicates which area of the frame to display. If all
3824 + * values are zero, the whole frame will be used.
3826 + struct vchiq_mmal_rect src_rect;
3828 + /** If set to non-zero, indicates that any display scaling
3829 + * should disregard the aspect ratio of the frame region being
3834 + /** Indicates how the image should be scaled to fit the
3835 + * display. \code MMAL_DISPLAY_MODE_FILL \endcode indicates
3836 + * that the image should fill the screen by potentially
3837 + * cropping the frames. Setting \code mode \endcode to \code
3838 + * MMAL_DISPLAY_MODE_LETTERBOX \endcode indicates that all the
3839 + * source region should be displayed and black bars added if
3842 + u32 mode; /* enum mmal_parameter_displaymode */
3844 + /** If non-zero, defines the width of a source pixel relative
3845 + * to \code pixel_y \endcode. If zero, then pixels default to
3850 + /** If non-zero, defines the height of a source pixel relative
3851 + * to \code pixel_x \endcode. If zero, then pixels default to
3856 + /** Sets the relative depth of the images, with greater values
3857 + * being in front of smaller values.
3861 + /** Set to non-zero to ensure copy protection is used on
3864 + s32 copyprotect_required;
3866 + /** Level of opacity of the layer, where zero is fully
3867 + * transparent and 255 is fully opaque.
3872 +#define MMAL_MAX_IMAGEFX_PARAMETERS 5
3874 +struct mmal_parameter_imagefx_parameters {
3875 + enum mmal_parameter_imagefx effect;
3876 + u32 num_effect_params;
3877 + u32 effect_parameter[MMAL_MAX_IMAGEFX_PARAMETERS];
3879 diff --git a/drivers/media/platform/bcm2835/mmal-vchiq.c b/drivers/media/platform/bcm2835/mmal-vchiq.c
3880 new file mode 100644
3881 index 0000000..a06fb44
3883 +++ b/drivers/media/platform/bcm2835/mmal-vchiq.c
3886 + * Broadcom BM2835 V4L2 driver
3888 + * Copyright © 2013 Raspberry Pi (Trading) Ltd.
3890 + * This file is subject to the terms and conditions of the GNU General Public
3891 + * License. See the file COPYING in the main directory of this archive
3892 + * for more details.
3894 + * Authors: Vincent Sanders <vincent.sanders@collabora.co.uk>
3895 + * Dave Stevenson <dsteve@broadcom.com>
3896 + * Simon Mellor <simellor@broadcom.com>
3897 + * Luke Diamand <luked@broadcom.com>
3899 + * V4L2 driver MMAL vchiq interface code
3902 +#define pr_fmt(fmt) KBUILD_MODNAME ": " fmt
3904 +#include <linux/errno.h>
3905 +#include <linux/kernel.h>
3906 +#include <linux/mutex.h>
3907 +#include <linux/mm.h>
3908 +#include <linux/slab.h>
3909 +#include <linux/completion.h>
3910 +#include <linux/vmalloc.h>
3911 +#include <asm/cacheflush.h>
3912 +#include <media/videobuf2-vmalloc.h>
3914 +#include "mmal-common.h"
3915 +#include "mmal-vchiq.h"
3916 +#include "mmal-msg.h"
3918 +#define USE_VCHIQ_ARM
3919 +#include "interface/vchi/vchi.h"
3921 +/* maximum number of components supported */
3922 +#define VCHIQ_MMAL_MAX_COMPONENTS 4
3924 +/*#define FULL_MSG_DUMP 1*/
3927 +static const char *const msg_type_names[] = {
3932 + "COMPONENT_CREATE",
3933 + "COMPONENT_DESTROY",
3934 + "COMPONENT_ENABLE",
3935 + "COMPONENT_DISABLE",
3939 + "BUFFER_FROM_HOST",
3942 + "PORT_PARAMETER_SET",
3943 + "PORT_PARAMETER_GET",
3945 + "GET_CORE_STATS_FOR_PORT",
3946 + "OPAQUE_ALLOCATOR",
3949 + "OPAQUE_ALLOCATOR_DESC",
3952 + "BUFFER_FROM_HOST_ZEROLEN",
3958 +static const char *const port_action_type_names[] = {
3965 + "SET_REQUIREMENTS",
3969 +#if defined(FULL_MSG_DUMP)
3970 +#define DBG_DUMP_MSG(MSG, MSG_LEN, TITLE) \
3972 + pr_debug(TITLE" type:%s(%d) length:%d\n", \
3973 + msg_type_names[(MSG)->h.type], \
3974 + (MSG)->h.type, (MSG_LEN)); \
3975 + print_hex_dump(KERN_DEBUG, "<<h: ", DUMP_PREFIX_OFFSET, \
3977 + sizeof(struct mmal_msg_header), 1); \
3978 + print_hex_dump(KERN_DEBUG, "<<p: ", DUMP_PREFIX_OFFSET, \
3980 + ((u8 *)(MSG)) + sizeof(struct mmal_msg_header),\
3981 + (MSG_LEN) - sizeof(struct mmal_msg_header), 1); \
3984 +#define DBG_DUMP_MSG(MSG, MSG_LEN, TITLE) \
3986 + pr_debug(TITLE" type:%s(%d) length:%d\n", \
3987 + msg_type_names[(MSG)->h.type], \
3988 + (MSG)->h.type, (MSG_LEN)); \
3992 +#define DBG_DUMP_MSG(MSG, MSG_LEN, TITLE)
3995 +/* normal message context */
3996 +struct mmal_msg_context {
3999 + /* work struct for defered callback - must come first */
4000 + struct work_struct work;
4001 + /* mmal instance */
4002 + struct vchiq_mmal_instance *instance;
4004 + struct vchiq_mmal_port *port;
4005 + /* actual buffer used to store bulk reply */
4006 + struct mmal_buffer *buffer;
4007 + /* amount of buffer used */
4008 + unsigned long buffer_used;
4009 + /* MMAL buffer flags */
4011 + /* Presentation and Decode timestamps */
4015 + int status; /* context status */
4017 + } bulk; /* bulk data */
4020 + /* message handle to release */
4021 + VCHI_HELD_MSG_T msg_handle;
4022 + /* pointer to received message */
4023 + struct mmal_msg *msg;
4024 + /* received message length */
4026 + /* completion upon reply */
4027 + struct completion cmplt;
4028 + } sync; /* synchronous response */
4033 +struct vchiq_mmal_instance {
4034 + VCHI_SERVICE_HANDLE_T handle;
4036 + /* ensure serialised access to service */
4037 + struct mutex vchiq_mutex;
4039 + /* ensure serialised access to bulk operations */
4040 + struct mutex bulk_mutex;
4042 + /* vmalloc page to receive scratch bulk xfers into */
4043 + void *bulk_scratch;
4045 + /* component to use next */
4046 + int component_idx;
4047 + struct vchiq_mmal_component component[VCHIQ_MMAL_MAX_COMPONENTS];
4050 +static struct mmal_msg_context *get_msg_context(struct vchiq_mmal_instance
4053 + struct mmal_msg_context *msg_context;
4055 + /* todo: should this be allocated from a pool to avoid kmalloc */
4056 + msg_context = kmalloc(sizeof(*msg_context), GFP_KERNEL);
4057 + memset(msg_context, 0, sizeof(*msg_context));
4059 + return msg_context;
4062 +static void release_msg_context(struct mmal_msg_context *msg_context)
4064 + kfree(msg_context);
4067 +/* deals with receipt of event to host message */
4068 +static void event_to_host_cb(struct vchiq_mmal_instance *instance,
4069 + struct mmal_msg *msg, u32 msg_len)
4071 + pr_debug("unhandled event\n");
4072 + pr_debug("component:%p port type:%d num:%d cmd:0x%x length:%d\n",
4073 + msg->u.event_to_host.client_component,
4074 + msg->u.event_to_host.port_type,
4075 + msg->u.event_to_host.port_num,
4076 + msg->u.event_to_host.cmd, msg->u.event_to_host.length);
4079 +/* workqueue scheduled callback
4081 + * we do this because it is important we do not call any other vchiq
4082 + * sync calls from witin the message delivery thread
4084 +static void buffer_work_cb(struct work_struct *work)
4086 + struct mmal_msg_context *msg_context = (struct mmal_msg_context *)work;
4088 + msg_context->u.bulk.port->buffer_cb(msg_context->u.bulk.instance,
4089 + msg_context->u.bulk.port,
4090 + msg_context->u.bulk.status,
4091 + msg_context->u.bulk.buffer,
4092 + msg_context->u.bulk.buffer_used,
4093 + msg_context->u.bulk.mmal_flags,
4094 + msg_context->u.bulk.dts,
4095 + msg_context->u.bulk.pts);
4097 + /* release message context */
4098 + release_msg_context(msg_context);
4101 +/* enqueue a bulk receive for a given message context */
4102 +static int bulk_receive(struct vchiq_mmal_instance *instance,
4103 + struct mmal_msg *msg,
4104 + struct mmal_msg_context *msg_context)
4106 + unsigned long rd_len;
4107 + unsigned long flags = 0;
4110 + /* bulk mutex stops other bulk operations while we have a
4111 + * receive in progress - released in callback
4113 + ret = mutex_lock_interruptible(&instance->bulk_mutex);
4117 + rd_len = msg->u.buffer_from_host.buffer_header.length;
4119 + /* take buffer from queue */
4120 + spin_lock_irqsave(&msg_context->u.bulk.port->slock, flags);
4121 + if (list_empty(&msg_context->u.bulk.port->buffers)) {
4122 + spin_unlock_irqrestore(&msg_context->u.bulk.port->slock, flags);
4123 + pr_err("buffer list empty trying to submit bulk receive\n");
4125 + /* todo: this is a serious error, we should never have
4126 + * commited a buffer_to_host operation to the mmal
4127 + * port without the buffer to back it up (underflow
4128 + * handling) and there is no obvious way to deal with
4129 + * this - how is the mmal servie going to react when
4130 + * we fail to do the xfer and reschedule a buffer when
4131 + * it arrives? perhaps a starved flag to indicate a
4132 + * waiting bulk receive?
4135 + mutex_unlock(&instance->bulk_mutex);
4140 + msg_context->u.bulk.buffer =
4141 + list_entry(msg_context->u.bulk.port->buffers.next,
4142 + struct mmal_buffer, list);
4143 + list_del(&msg_context->u.bulk.buffer->list);
4145 + spin_unlock_irqrestore(&msg_context->u.bulk.port->slock, flags);
4147 + /* ensure we do not overrun the available buffer */
4148 + if (rd_len > msg_context->u.bulk.buffer->buffer_size) {
4149 + rd_len = msg_context->u.bulk.buffer->buffer_size;
4150 + pr_warn("short read as not enough receive buffer space\n");
4151 + /* todo: is this the correct response, what happens to
4152 + * the rest of the message data?
4156 + /* store length */
4157 + msg_context->u.bulk.buffer_used = rd_len;
4158 + msg_context->u.bulk.mmal_flags =
4159 + msg->u.buffer_from_host.buffer_header.flags;
4160 + msg_context->u.bulk.dts = msg->u.buffer_from_host.buffer_header.dts;
4161 + msg_context->u.bulk.pts = msg->u.buffer_from_host.buffer_header.pts;
4163 + // only need to flush L1 cache here, as VCHIQ takes care of the L2
4165 + __cpuc_flush_dcache_area(msg_context->u.bulk.buffer->buffer, rd_len);
4167 + /* queue the bulk submission */
4168 + vchi_service_use(instance->handle);
4169 + ret = vchi_bulk_queue_receive(instance->handle,
4170 + msg_context->u.bulk.buffer->buffer,
4171 + /* Actual receive needs to be a multiple
4174 + (rd_len + 3) & ~3,
4175 + VCHI_FLAGS_CALLBACK_WHEN_OP_COMPLETE |
4176 + VCHI_FLAGS_BLOCK_UNTIL_QUEUED,
4179 + vchi_service_release(instance->handle);
4182 + /* callback will not be clearing the mutex */
4183 + mutex_unlock(&instance->bulk_mutex);
4189 +/* enque a dummy bulk receive for a given message context */
4190 +static int dummy_bulk_receive(struct vchiq_mmal_instance *instance,
4191 + struct mmal_msg_context *msg_context)
4195 + /* bulk mutex stops other bulk operations while we have a
4196 + * receive in progress - released in callback
4198 + ret = mutex_lock_interruptible(&instance->bulk_mutex);
4202 + /* zero length indicates this was a dummy transfer */
4203 + msg_context->u.bulk.buffer_used = 0;
4205 + /* queue the bulk submission */
4206 + vchi_service_use(instance->handle);
4208 + ret = vchi_bulk_queue_receive(instance->handle,
4209 + instance->bulk_scratch,
4211 + VCHI_FLAGS_CALLBACK_WHEN_OP_COMPLETE |
4212 + VCHI_FLAGS_BLOCK_UNTIL_QUEUED,
4215 + vchi_service_release(instance->handle);
4218 + /* callback will not be clearing the mutex */
4219 + mutex_unlock(&instance->bulk_mutex);
4225 +/* data in message, memcpy from packet into output buffer */
4226 +static int inline_receive(struct vchiq_mmal_instance *instance,
4227 + struct mmal_msg *msg,
4228 + struct mmal_msg_context *msg_context)
4230 + unsigned long flags = 0;
4232 + /* take buffer from queue */
4233 + spin_lock_irqsave(&msg_context->u.bulk.port->slock, flags);
4234 + if (list_empty(&msg_context->u.bulk.port->buffers)) {
4235 + spin_unlock_irqrestore(&msg_context->u.bulk.port->slock, flags);
4236 + pr_err("buffer list empty trying to receive inline\n");
4238 + /* todo: this is a serious error, we should never have
4239 + * commited a buffer_to_host operation to the mmal
4240 + * port without the buffer to back it up (with
4241 + * underflow handling) and there is no obvious way to
4242 + * deal with this. Less bad than the bulk case as we
4243 + * can just drop this on the floor but...unhelpful
4248 + msg_context->u.bulk.buffer =
4249 + list_entry(msg_context->u.bulk.port->buffers.next,
4250 + struct mmal_buffer, list);
4251 + list_del(&msg_context->u.bulk.buffer->list);
4253 + spin_unlock_irqrestore(&msg_context->u.bulk.port->slock, flags);
4255 + memcpy(msg_context->u.bulk.buffer->buffer,
4256 + msg->u.buffer_from_host.short_data,
4257 + msg->u.buffer_from_host.payload_in_message);
4259 + msg_context->u.bulk.buffer_used =
4260 + msg->u.buffer_from_host.payload_in_message;
4265 +/* queue the buffer availability with MMAL_MSG_TYPE_BUFFER_FROM_HOST */
4267 +buffer_from_host(struct vchiq_mmal_instance *instance,
4268 + struct vchiq_mmal_port *port, struct mmal_buffer *buf)
4270 + struct mmal_msg_context *msg_context;
4271 + struct mmal_msg m;
4274 + pr_debug("instance:%p buffer:%p\n", instance->handle, buf);
4276 + /* bulk mutex stops other bulk operations while we
4277 + * have a receive in progress
4279 + if (mutex_lock_interruptible(&instance->bulk_mutex))
4283 + msg_context = get_msg_context(instance);
4284 + if (msg_context == NULL)
4287 + /* store bulk message context for when data arrives */
4288 + msg_context->u.bulk.instance = instance;
4289 + msg_context->u.bulk.port = port;
4290 + msg_context->u.bulk.buffer = NULL; /* not valid until bulk xfer */
4291 + msg_context->u.bulk.buffer_used = 0;
4293 + /* initialise work structure ready to schedule callback */
4294 + INIT_WORK(&msg_context->u.bulk.work, buffer_work_cb);
4296 + /* prep the buffer from host message */
4297 + memset(&m, 0xbc, sizeof(m)); /* just to make debug clearer */
4299 + m.h.type = MMAL_MSG_TYPE_BUFFER_FROM_HOST;
4300 + m.h.magic = MMAL_MAGIC;
4301 + m.h.context = msg_context;
4304 + /* drvbuf is our private data passed back */
4305 + m.u.buffer_from_host.drvbuf.magic = MMAL_MAGIC;
4306 + m.u.buffer_from_host.drvbuf.component_handle = port->component->handle;
4307 + m.u.buffer_from_host.drvbuf.port_handle = port->handle;
4308 + m.u.buffer_from_host.drvbuf.client_context = msg_context;
4310 + /* buffer header */
4311 + m.u.buffer_from_host.buffer_header.cmd = 0;
4312 + m.u.buffer_from_host.buffer_header.data = buf->buffer;
4313 + m.u.buffer_from_host.buffer_header.alloc_size = buf->buffer_size;
4314 + m.u.buffer_from_host.buffer_header.length = 0; /* nothing used yet */
4315 + m.u.buffer_from_host.buffer_header.offset = 0; /* no offset */
4316 + m.u.buffer_from_host.buffer_header.flags = 0; /* no flags */
4317 + m.u.buffer_from_host.buffer_header.pts = MMAL_TIME_UNKNOWN;
4318 + m.u.buffer_from_host.buffer_header.dts = MMAL_TIME_UNKNOWN;
4320 + /* clear buffer type sepecific data */
4321 + memset(&m.u.buffer_from_host.buffer_header_type_specific, 0,
4322 + sizeof(m.u.buffer_from_host.buffer_header_type_specific));
4324 + /* no payload in message */
4325 + m.u.buffer_from_host.payload_in_message = 0;
4327 + vchi_service_use(instance->handle);
4329 + ret = vchi_msg_queue(instance->handle, &m,
4330 + sizeof(struct mmal_msg_header) +
4331 + sizeof(m.u.buffer_from_host),
4332 + VCHI_FLAGS_BLOCK_UNTIL_QUEUED, NULL);
4335 + release_msg_context(msg_context);
4336 + /* todo: is this correct error value? */
4339 + vchi_service_release(instance->handle);
4341 + mutex_unlock(&instance->bulk_mutex);
4346 +/* submit a buffer to the mmal sevice
4348 + * the buffer_from_host uses size data from the ports next available
4349 + * mmal_buffer and deals with there being no buffer available by
4350 + * incrementing the underflow for later
4352 +static int port_buffer_from_host(struct vchiq_mmal_instance *instance,
4353 + struct vchiq_mmal_port *port)
4356 + struct mmal_buffer *buf;
4357 + unsigned long flags = 0;
4359 + if (!port->enabled)
4362 + /* peek buffer from queue */
4363 + spin_lock_irqsave(&port->slock, flags);
4364 + if (list_empty(&port->buffers)) {
4365 + port->buffer_underflow++;
4366 + spin_unlock_irqrestore(&port->slock, flags);
4370 + buf = list_entry(port->buffers.next, struct mmal_buffer, list);
4372 + spin_unlock_irqrestore(&port->slock, flags);
4374 + /* issue buffer to mmal service */
4375 + ret = buffer_from_host(instance, port, buf);
4377 + pr_err("adding buffer header failed\n");
4378 + /* todo: how should this be dealt with */
4384 +/* deals with receipt of buffer to host message */
4385 +static void buffer_to_host_cb(struct vchiq_mmal_instance *instance,
4386 + struct mmal_msg *msg, u32 msg_len)
4388 + struct mmal_msg_context *msg_context;
4390 + pr_debug("buffer_to_host_cb: instance:%p msg:%p msg_len:%d\n",
4391 + instance, msg, msg_len);
4393 + if (msg->u.buffer_from_host.drvbuf.magic == MMAL_MAGIC) {
4394 + msg_context = msg->u.buffer_from_host.drvbuf.client_context;
4396 + pr_err("MMAL_MSG_TYPE_BUFFER_TO_HOST with bad magic\n");
4400 + if (msg->h.status != MMAL_MSG_STATUS_SUCCESS) {
4401 + /* message reception had an error */
4402 + pr_warn("error %d in reply\n", msg->h.status);
4404 + msg_context->u.bulk.status = msg->h.status;
4406 + } else if (msg->u.buffer_from_host.buffer_header.length == 0) {
4407 + /* empty buffer */
4408 + if (msg->u.buffer_from_host.buffer_header.flags &
4409 + MMAL_BUFFER_HEADER_FLAG_EOS) {
4410 + msg_context->u.bulk.status =
4411 + dummy_bulk_receive(instance, msg_context);
4412 + if (msg_context->u.bulk.status == 0)
4413 + return; /* successful bulk submission, bulk
4414 + * completion will trigger callback
4417 + /* do callback with empty buffer - not EOS though */
4418 + msg_context->u.bulk.status = 0;
4419 + msg_context->u.bulk.buffer_used = 0;
4421 + } else if (msg->u.buffer_from_host.payload_in_message == 0) {
4422 + /* data is not in message, queue a bulk receive */
4423 + msg_context->u.bulk.status =
4424 + bulk_receive(instance, msg, msg_context);
4425 + if (msg_context->u.bulk.status == 0)
4426 + return; /* successful bulk submission, bulk
4427 + * completion will trigger callback
4430 + /* failed to submit buffer, this will end badly */
4431 + pr_err("error %d on bulk submission\n",
4432 + msg_context->u.bulk.status);
4434 + } else if (msg->u.buffer_from_host.payload_in_message <=
4435 + MMAL_VC_SHORT_DATA) {
4436 + /* data payload within message */
4437 + msg_context->u.bulk.status = inline_receive(instance, msg,
4440 + pr_err("message with invalid short payload\n");
4442 + /* signal error */
4443 + msg_context->u.bulk.status = -EINVAL;
4444 + msg_context->u.bulk.buffer_used =
4445 + msg->u.buffer_from_host.payload_in_message;
4448 + /* replace the buffer header */
4449 + port_buffer_from_host(instance, msg_context->u.bulk.port);
4451 + /* schedule the port callback */
4452 + schedule_work(&msg_context->u.bulk.work);
4455 +static void bulk_receive_cb(struct vchiq_mmal_instance *instance,
4456 + struct mmal_msg_context *msg_context)
4458 + /* bulk receive operation complete */
4459 + mutex_unlock(&msg_context->u.bulk.instance->bulk_mutex);
4461 + /* replace the buffer header */
4462 + port_buffer_from_host(msg_context->u.bulk.instance,
4463 + msg_context->u.bulk.port);
4465 + msg_context->u.bulk.status = 0;
4467 + /* schedule the port callback */
4468 + schedule_work(&msg_context->u.bulk.work);
4471 +static void bulk_abort_cb(struct vchiq_mmal_instance *instance,
4472 + struct mmal_msg_context *msg_context)
4474 + pr_err("%s: bulk ABORTED msg_context:%p\n", __func__, msg_context);
4476 + /* bulk receive operation complete */
4477 + mutex_unlock(&msg_context->u.bulk.instance->bulk_mutex);
4479 + /* replace the buffer header */
4480 + port_buffer_from_host(msg_context->u.bulk.instance,
4481 + msg_context->u.bulk.port);
4483 + msg_context->u.bulk.status = -EINTR;
4485 + schedule_work(&msg_context->u.bulk.work);
4488 +/* incoming event service callback */
4489 +static void service_callback(void *param,
4490 + const VCHI_CALLBACK_REASON_T reason,
4493 + struct vchiq_mmal_instance *instance = param;
4496 + struct mmal_msg *msg;
4497 + VCHI_HELD_MSG_T msg_handle;
4500 + pr_err("Message callback passed NULL instance\n");
4505 + case VCHI_CALLBACK_MSG_AVAILABLE:
4506 + status = vchi_msg_hold(instance->handle, (void **)&msg,
4507 + &msg_len, VCHI_FLAGS_NONE, &msg_handle);
4509 + pr_err("Unable to dequeue a message (%d)\n", status);
4513 + DBG_DUMP_MSG(msg, msg_len, "<<< reply message");
4515 + /* handling is different for buffer messages */
4516 + switch (msg->h.type) {
4518 + case MMAL_MSG_TYPE_BUFFER_FROM_HOST:
4519 + vchi_held_msg_release(&msg_handle);
4522 + case MMAL_MSG_TYPE_EVENT_TO_HOST:
4523 + event_to_host_cb(instance, msg, msg_len);
4524 + vchi_held_msg_release(&msg_handle);
4528 + case MMAL_MSG_TYPE_BUFFER_TO_HOST:
4529 + buffer_to_host_cb(instance, msg, msg_len);
4530 + vchi_held_msg_release(&msg_handle);
4534 + /* messages dependant on header context to complete */
4536 + /* todo: the msg.context really ought to be sanity
4537 + * checked before we just use it, afaict it comes back
4538 + * and is used raw from the videocore. Perhaps it
4539 + * should be verified the address lies in the kernel
4542 + if (msg->h.context == NULL) {
4543 + pr_err("received message context was null!\n");
4544 + vchi_held_msg_release(&msg_handle);
4548 + /* fill in context values */
4549 + msg->h.context->u.sync.msg_handle = msg_handle;
4550 + msg->h.context->u.sync.msg = msg;
4551 + msg->h.context->u.sync.msg_len = msg_len;
4553 + /* todo: should this check (completion_done()
4554 + * == 1) for no one waiting? or do we need a
4555 + * flag to tell us the completion has been
4556 + * interrupted so we can free the message and
4557 + * its context. This probably also solves the
4558 + * message arriving after interruption todo
4562 + /* complete message so caller knows it happened */
4563 + complete(&msg->h.context->u.sync.cmplt);
4569 + case VCHI_CALLBACK_BULK_RECEIVED:
4570 + bulk_receive_cb(instance, bulk_ctx);
4573 + case VCHI_CALLBACK_BULK_RECEIVE_ABORTED:
4574 + bulk_abort_cb(instance, bulk_ctx);
4577 + case VCHI_CALLBACK_SERVICE_CLOSED:
4578 + /* TODO: consider if this requires action if received when
4579 + * driver is not explicitly closing the service
4584 + pr_err("Received unhandled message reason %d\n", reason);
4589 +static int send_synchronous_mmal_msg(struct vchiq_mmal_instance *instance,
4590 + struct mmal_msg *msg,
4591 + unsigned int payload_len,
4592 + struct mmal_msg **msg_out,
4593 + VCHI_HELD_MSG_T *msg_handle_out)
4595 + struct mmal_msg_context msg_context;
4598 + /* payload size must not cause message to exceed max size */
4600 + (MMAL_MSG_MAX_SIZE - sizeof(struct mmal_msg_header))) {
4601 + pr_err("payload length %d exceeds max:%d\n", payload_len,
4602 + (MMAL_MSG_MAX_SIZE - sizeof(struct mmal_msg_header)));
4606 + init_completion(&msg_context.u.sync.cmplt);
4608 + msg->h.magic = MMAL_MAGIC;
4609 + msg->h.context = &msg_context;
4610 + msg->h.status = 0;
4612 + DBG_DUMP_MSG(msg, (sizeof(struct mmal_msg_header) + payload_len),
4613 + ">>> sync message");
4615 + vchi_service_use(instance->handle);
4617 + ret = vchi_msg_queue(instance->handle,
4619 + sizeof(struct mmal_msg_header) + payload_len,
4620 + VCHI_FLAGS_BLOCK_UNTIL_QUEUED, NULL);
4622 + vchi_service_release(instance->handle);
4625 + pr_err("error %d queuing message\n", ret);
4629 + ret = wait_for_completion_timeout(&msg_context.u.sync.cmplt, HZ);
4631 + pr_err("error %d waiting for sync completion\n", ret);
4634 + /* todo: what happens if the message arrives after aborting */
4638 + *msg_out = msg_context.u.sync.msg;
4639 + *msg_handle_out = msg_context.u.sync.msg_handle;
4644 +static void dump_port_info(struct vchiq_mmal_port *port)
4646 + pr_debug("port handle:0x%x enabled:%d\n", port->handle, port->enabled);
4648 + pr_debug("buffer minimum num:%d size:%d align:%d\n",
4649 + port->minimum_buffer.num,
4650 + port->minimum_buffer.size, port->minimum_buffer.alignment);
4652 + pr_debug("buffer recommended num:%d size:%d align:%d\n",
4653 + port->recommended_buffer.num,
4654 + port->recommended_buffer.size,
4655 + port->recommended_buffer.alignment);
4657 + pr_debug("buffer current values num:%d size:%d align:%d\n",
4658 + port->current_buffer.num,
4659 + port->current_buffer.size, port->current_buffer.alignment);
4661 + pr_debug("elementry stream: type:%d encoding:0x%x varient:0x%x\n",
4662 + port->format.type,
4663 + port->format.encoding, port->format.encoding_variant);
4665 + pr_debug(" bitrate:%d flags:0x%x\n",
4666 + port->format.bitrate, port->format.flags);
4668 + if (port->format.type == MMAL_ES_TYPE_VIDEO) {
4670 + ("es video format: width:%d height:%d colourspace:0x%x\n",
4671 + port->es.video.width, port->es.video.height,
4672 + port->es.video.color_space);
4674 + pr_debug(" : crop xywh %d,%d,%d,%d\n",
4675 + port->es.video.crop.x,
4676 + port->es.video.crop.y,
4677 + port->es.video.crop.width, port->es.video.crop.height);
4678 + pr_debug(" : framerate %d/%d aspect %d/%d\n",
4679 + port->es.video.frame_rate.num,
4680 + port->es.video.frame_rate.den,
4681 + port->es.video.par.num, port->es.video.par.den);
4685 +static void port_to_mmal_msg(struct vchiq_mmal_port *port, struct mmal_port *p)
4688 + /* todo do readonly fields need setting at all? */
4689 + p->type = port->type;
4690 + p->index = port->index;
4692 + p->is_enabled = port->enabled;
4693 + p->buffer_num_min = port->minimum_buffer.num;
4694 + p->buffer_size_min = port->minimum_buffer.size;
4695 + p->buffer_alignment_min = port->minimum_buffer.alignment;
4696 + p->buffer_num_recommended = port->recommended_buffer.num;
4697 + p->buffer_size_recommended = port->recommended_buffer.size;
4699 + /* only three writable fields in a port */
4700 + p->buffer_num = port->current_buffer.num;
4701 + p->buffer_size = port->current_buffer.size;
4702 + p->userdata = port;
4705 +static int port_info_set(struct vchiq_mmal_instance *instance,
4706 + struct vchiq_mmal_port *port)
4709 + struct mmal_msg m;
4710 + struct mmal_msg *rmsg;
4711 + VCHI_HELD_MSG_T rmsg_handle;
4713 + pr_debug("setting port info port %p\n", port);
4716 + dump_port_info(port);
4718 + m.h.type = MMAL_MSG_TYPE_PORT_INFO_SET;
4720 + m.u.port_info_set.component_handle = port->component->handle;
4721 + m.u.port_info_set.port_type = port->type;
4722 + m.u.port_info_set.port_index = port->index;
4724 + port_to_mmal_msg(port, &m.u.port_info_set.port);
4726 + /* elementry stream format setup */
4727 + m.u.port_info_set.format.type = port->format.type;
4728 + m.u.port_info_set.format.encoding = port->format.encoding;
4729 + m.u.port_info_set.format.encoding_variant =
4730 + port->format.encoding_variant;
4731 + m.u.port_info_set.format.bitrate = port->format.bitrate;
4732 + m.u.port_info_set.format.flags = port->format.flags;
4734 + memcpy(&m.u.port_info_set.es, &port->es,
4735 + sizeof(union mmal_es_specific_format));
4737 + m.u.port_info_set.format.extradata_size = port->format.extradata_size;
4738 + memcpy(rmsg->u.port_info_set.extradata, port->format.extradata,
4739 + port->format.extradata_size);
4741 + ret = send_synchronous_mmal_msg(instance, &m,
4742 + sizeof(m.u.port_info_set),
4743 + &rmsg, &rmsg_handle);
4747 + if (rmsg->h.type != MMAL_MSG_TYPE_PORT_INFO_SET) {
4748 + /* got an unexpected message type in reply */
4753 + /* return operation status */
4754 + ret = -rmsg->u.port_info_get_reply.status;
4756 + pr_debug("%s:result:%d component:0x%x port:%d\n", __func__, ret,
4757 + port->component->handle, port->handle);
4760 + vchi_held_msg_release(&rmsg_handle);
4766 +/* use port info get message to retrive port information */
4767 +static int port_info_get(struct vchiq_mmal_instance *instance,
4768 + struct vchiq_mmal_port *port)
4771 + struct mmal_msg m;
4772 + struct mmal_msg *rmsg;
4773 + VCHI_HELD_MSG_T rmsg_handle;
4775 + /* port info time */
4776 + m.h.type = MMAL_MSG_TYPE_PORT_INFO_GET;
4777 + m.u.port_info_get.component_handle = port->component->handle;
4778 + m.u.port_info_get.port_type = port->type;
4779 + m.u.port_info_get.index = port->index;
4781 + ret = send_synchronous_mmal_msg(instance, &m,
4782 + sizeof(m.u.port_info_get),
4783 + &rmsg, &rmsg_handle);
4787 + if (rmsg->h.type != MMAL_MSG_TYPE_PORT_INFO_GET) {
4788 + /* got an unexpected message type in reply */
4793 + /* return operation status */
4794 + ret = -rmsg->u.port_info_get_reply.status;
4795 + if (ret != MMAL_MSG_STATUS_SUCCESS)
4798 + if (rmsg->u.port_info_get_reply.port.is_enabled == 0)
4799 + port->enabled = false;
4801 + port->enabled = true;
4803 + /* copy the values out of the message */
4804 + port->handle = rmsg->u.port_info_get_reply.port_handle;
4806 + /* port type and index cached to use on port info set becuase
4807 + * it does not use a port handle
4809 + port->type = rmsg->u.port_info_get_reply.port_type;
4810 + port->index = rmsg->u.port_info_get_reply.port_index;
4812 + port->minimum_buffer.num =
4813 + rmsg->u.port_info_get_reply.port.buffer_num_min;
4814 + port->minimum_buffer.size =
4815 + rmsg->u.port_info_get_reply.port.buffer_size_min;
4816 + port->minimum_buffer.alignment =
4817 + rmsg->u.port_info_get_reply.port.buffer_alignment_min;
4819 + port->recommended_buffer.alignment =
4820 + rmsg->u.port_info_get_reply.port.buffer_alignment_min;
4821 + port->recommended_buffer.num =
4822 + rmsg->u.port_info_get_reply.port.buffer_num_recommended;
4824 + port->current_buffer.num = rmsg->u.port_info_get_reply.port.buffer_num;
4825 + port->current_buffer.size =
4826 + rmsg->u.port_info_get_reply.port.buffer_size;
4828 + /* stream format */
4829 + port->format.type = rmsg->u.port_info_get_reply.format.type;
4830 + port->format.encoding = rmsg->u.port_info_get_reply.format.encoding;
4831 + port->format.encoding_variant =
4832 + rmsg->u.port_info_get_reply.format.encoding_variant;
4833 + port->format.bitrate = rmsg->u.port_info_get_reply.format.bitrate;
4834 + port->format.flags = rmsg->u.port_info_get_reply.format.flags;
4836 + /* elementry stream format */
4838 + &rmsg->u.port_info_get_reply.es,
4839 + sizeof(union mmal_es_specific_format));
4840 + port->format.es = &port->es;
4842 + port->format.extradata_size =
4843 + rmsg->u.port_info_get_reply.format.extradata_size;
4844 + memcpy(port->format.extradata,
4845 + rmsg->u.port_info_get_reply.extradata,
4846 + port->format.extradata_size);
4848 + pr_debug("received port info\n");
4849 + dump_port_info(port);
4853 + pr_debug("%s:result:%d component:0x%x port:%d\n",
4854 + __func__, ret, port->component->handle, port->handle);
4856 + vchi_held_msg_release(&rmsg_handle);
4861 +/* create comonent on vc */
4862 +static int create_component(struct vchiq_mmal_instance *instance,
4863 + struct vchiq_mmal_component *component,
4867 + struct mmal_msg m;
4868 + struct mmal_msg *rmsg;
4869 + VCHI_HELD_MSG_T rmsg_handle;
4871 + /* build component create message */
4872 + m.h.type = MMAL_MSG_TYPE_COMPONENT_CREATE;
4873 + m.u.component_create.client_component = component;
4874 + strncpy(m.u.component_create.name, name,
4875 + sizeof(m.u.component_create.name));
4877 + ret = send_synchronous_mmal_msg(instance, &m,
4878 + sizeof(m.u.component_create),
4879 + &rmsg, &rmsg_handle);
4883 + if (rmsg->h.type != m.h.type) {
4884 + /* got an unexpected message type in reply */
4889 + ret = -rmsg->u.component_create_reply.status;
4890 + if (ret != MMAL_MSG_STATUS_SUCCESS)
4893 + /* a valid component response received */
4894 + component->handle = rmsg->u.component_create_reply.component_handle;
4895 + component->inputs = rmsg->u.component_create_reply.input_num;
4896 + component->outputs = rmsg->u.component_create_reply.output_num;
4897 + component->clocks = rmsg->u.component_create_reply.clock_num;
4899 + pr_debug("Component handle:0x%x in:%d out:%d clock:%d\n",
4900 + component->handle,
4901 + component->inputs, component->outputs, component->clocks);
4904 + vchi_held_msg_release(&rmsg_handle);
4909 +/* destroys a component on vc */
4910 +static int destroy_component(struct vchiq_mmal_instance *instance,
4911 + struct vchiq_mmal_component *component)
4914 + struct mmal_msg m;
4915 + struct mmal_msg *rmsg;
4916 + VCHI_HELD_MSG_T rmsg_handle;
4918 + m.h.type = MMAL_MSG_TYPE_COMPONENT_DESTROY;
4919 + m.u.component_destroy.component_handle = component->handle;
4921 + ret = send_synchronous_mmal_msg(instance, &m,
4922 + sizeof(m.u.component_destroy),
4923 + &rmsg, &rmsg_handle);
4927 + if (rmsg->h.type != m.h.type) {
4928 + /* got an unexpected message type in reply */
4933 + ret = -rmsg->u.component_destroy_reply.status;
4937 + vchi_held_msg_release(&rmsg_handle);
4942 +/* enable a component on vc */
4943 +static int enable_component(struct vchiq_mmal_instance *instance,
4944 + struct vchiq_mmal_component *component)
4947 + struct mmal_msg m;
4948 + struct mmal_msg *rmsg;
4949 + VCHI_HELD_MSG_T rmsg_handle;
4951 + m.h.type = MMAL_MSG_TYPE_COMPONENT_ENABLE;
4952 + m.u.component_enable.component_handle = component->handle;
4954 + ret = send_synchronous_mmal_msg(instance, &m,
4955 + sizeof(m.u.component_enable),
4956 + &rmsg, &rmsg_handle);
4960 + if (rmsg->h.type != m.h.type) {
4961 + /* got an unexpected message type in reply */
4966 + ret = -rmsg->u.component_enable_reply.status;
4969 + vchi_held_msg_release(&rmsg_handle);
4974 +/* disable a component on vc */
4975 +static int disable_component(struct vchiq_mmal_instance *instance,
4976 + struct vchiq_mmal_component *component)
4979 + struct mmal_msg m;
4980 + struct mmal_msg *rmsg;
4981 + VCHI_HELD_MSG_T rmsg_handle;
4983 + m.h.type = MMAL_MSG_TYPE_COMPONENT_DISABLE;
4984 + m.u.component_disable.component_handle = component->handle;
4986 + ret = send_synchronous_mmal_msg(instance, &m,
4987 + sizeof(m.u.component_disable),
4988 + &rmsg, &rmsg_handle);
4992 + if (rmsg->h.type != m.h.type) {
4993 + /* got an unexpected message type in reply */
4998 + ret = -rmsg->u.component_disable_reply.status;
5002 + vchi_held_msg_release(&rmsg_handle);
5007 +/* get version of mmal implementation */
5008 +static int get_version(struct vchiq_mmal_instance *instance,
5009 + u32 *major_out, u32 *minor_out)
5012 + struct mmal_msg m;
5013 + struct mmal_msg *rmsg;
5014 + VCHI_HELD_MSG_T rmsg_handle;
5016 + m.h.type = MMAL_MSG_TYPE_GET_VERSION;
5018 + ret = send_synchronous_mmal_msg(instance, &m,
5019 + sizeof(m.u.version),
5020 + &rmsg, &rmsg_handle);
5024 + if (rmsg->h.type != m.h.type) {
5025 + /* got an unexpected message type in reply */
5030 + *major_out = rmsg->u.version.major;
5031 + *minor_out = rmsg->u.version.minor;
5034 + vchi_held_msg_release(&rmsg_handle);
5039 +/* do a port action with a port as a parameter */
5040 +static int port_action_port(struct vchiq_mmal_instance *instance,
5041 + struct vchiq_mmal_port *port,
5042 + enum mmal_msg_port_action_type action_type)
5045 + struct mmal_msg m;
5046 + struct mmal_msg *rmsg;
5047 + VCHI_HELD_MSG_T rmsg_handle;
5049 + m.h.type = MMAL_MSG_TYPE_PORT_ACTION;
5050 + m.u.port_action_port.component_handle = port->component->handle;
5051 + m.u.port_action_port.port_handle = port->handle;
5052 + m.u.port_action_port.action = action_type;
5054 + port_to_mmal_msg(port, &m.u.port_action_port.port);
5056 + ret = send_synchronous_mmal_msg(instance, &m,
5057 + sizeof(m.u.port_action_port),
5058 + &rmsg, &rmsg_handle);
5062 + if (rmsg->h.type != MMAL_MSG_TYPE_PORT_ACTION) {
5063 + /* got an unexpected message type in reply */
5068 + ret = -rmsg->u.port_action_reply.status;
5070 + pr_debug("%s:result:%d component:0x%x port:%d action:%s(%d)\n",
5072 + ret, port->component->handle, port->handle,
5073 + port_action_type_names[action_type], action_type);
5076 + vchi_held_msg_release(&rmsg_handle);
5081 +/* do a port action with handles as parameters */
5082 +static int port_action_handle(struct vchiq_mmal_instance *instance,
5083 + struct vchiq_mmal_port *port,
5084 + enum mmal_msg_port_action_type action_type,
5085 + u32 connect_component_handle,
5086 + u32 connect_port_handle)
5089 + struct mmal_msg m;
5090 + struct mmal_msg *rmsg;
5091 + VCHI_HELD_MSG_T rmsg_handle;
5093 + m.h.type = MMAL_MSG_TYPE_PORT_ACTION;
5095 + m.u.port_action_handle.component_handle = port->component->handle;
5096 + m.u.port_action_handle.port_handle = port->handle;
5097 + m.u.port_action_handle.action = action_type;
5099 + m.u.port_action_handle.connect_component_handle =
5100 + connect_component_handle;
5101 + m.u.port_action_handle.connect_port_handle = connect_port_handle;
5103 + ret = send_synchronous_mmal_msg(instance, &m,
5104 + sizeof(m.u.port_action_handle),
5105 + &rmsg, &rmsg_handle);
5109 + if (rmsg->h.type != MMAL_MSG_TYPE_PORT_ACTION) {
5110 + /* got an unexpected message type in reply */
5115 + ret = -rmsg->u.port_action_reply.status;
5117 + pr_debug("%s:result:%d component:0x%x port:%d action:%s(%d)" \
5118 + " connect component:0x%x connect port:%d\n",
5120 + ret, port->component->handle, port->handle,
5121 + port_action_type_names[action_type],
5122 + action_type, connect_component_handle, connect_port_handle);
5125 + vchi_held_msg_release(&rmsg_handle);
5130 +static int port_parameter_set(struct vchiq_mmal_instance *instance,
5131 + struct vchiq_mmal_port *port,
5132 + u32 parameter_id, void *value, u32 value_size)
5135 + struct mmal_msg m;
5136 + struct mmal_msg *rmsg;
5137 + VCHI_HELD_MSG_T rmsg_handle;
5139 + m.h.type = MMAL_MSG_TYPE_PORT_PARAMETER_SET;
5141 + m.u.port_parameter_set.component_handle = port->component->handle;
5142 + m.u.port_parameter_set.port_handle = port->handle;
5143 + m.u.port_parameter_set.id = parameter_id;
5144 + m.u.port_parameter_set.size = (2 * sizeof(u32)) + value_size;
5145 + memcpy(&m.u.port_parameter_set.value, value, value_size);
5147 + ret = send_synchronous_mmal_msg(instance, &m,
5148 + (4 * sizeof(u32)) + value_size,
5149 + &rmsg, &rmsg_handle);
5153 + if (rmsg->h.type != MMAL_MSG_TYPE_PORT_PARAMETER_SET) {
5154 + /* got an unexpected message type in reply */
5159 + ret = -rmsg->u.port_parameter_set_reply.status;
5161 + pr_debug("%s:result:%d component:0x%x port:%d parameter:%d\n",
5163 + ret, port->component->handle, port->handle, parameter_id);
5166 + vchi_held_msg_release(&rmsg_handle);
5171 +static int port_parameter_get(struct vchiq_mmal_instance *instance,
5172 + struct vchiq_mmal_port *port,
5173 + u32 parameter_id, void *value, u32 *value_size)
5176 + struct mmal_msg m;
5177 + struct mmal_msg *rmsg;
5178 + VCHI_HELD_MSG_T rmsg_handle;
5180 + m.h.type = MMAL_MSG_TYPE_PORT_PARAMETER_GET;
5182 + m.u.port_parameter_get.component_handle = port->component->handle;
5183 + m.u.port_parameter_get.port_handle = port->handle;
5184 + m.u.port_parameter_get.id = parameter_id;
5185 + m.u.port_parameter_get.size = (2 * sizeof(u32)) + *value_size;
5187 + ret = send_synchronous_mmal_msg(instance, &m,
5189 + mmal_msg_port_parameter_get),
5190 + &rmsg, &rmsg_handle);
5194 + if (rmsg->h.type != MMAL_MSG_TYPE_PORT_PARAMETER_GET) {
5195 + /* got an unexpected message type in reply */
5196 + pr_err("Incorrect reply type %d\n", rmsg->h.type);
5201 + ret = -rmsg->u.port_parameter_get_reply.status;
5203 + /* Copy only as much as we have space for
5204 + * but report true size of parameter
5206 + memcpy(value, &rmsg->u.port_parameter_get_reply.value,
5208 + *value_size = rmsg->u.port_parameter_get_reply.size;
5210 + memcpy(value, &rmsg->u.port_parameter_get_reply.value,
5211 + rmsg->u.port_parameter_get_reply.size);
5213 + pr_info("%s:result:%d component:0x%x port:%d parameter:%d\n", __func__,
5214 + ret, port->component->handle, port->handle, parameter_id);
5217 + vchi_held_msg_release(&rmsg_handle);
5222 +/* disables a port and drains buffers from it */
5223 +static int port_disable(struct vchiq_mmal_instance *instance,
5224 + struct vchiq_mmal_port *port)
5227 + struct list_head *q, *buf_head;
5228 + unsigned long flags = 0;
5230 + if (!port->enabled)
5233 + port->enabled = false;
5235 + ret = port_action_port(instance, port,
5236 + MMAL_MSG_PORT_ACTION_TYPE_DISABLE);
5239 + /* drain all queued buffers on port */
5240 + spin_lock_irqsave(&port->slock, flags);
5242 + list_for_each_safe(buf_head, q, &port->buffers) {
5243 + struct mmal_buffer *mmalbuf;
5244 + mmalbuf = list_entry(buf_head, struct mmal_buffer,
5246 + list_del(buf_head);
5247 + if (port->buffer_cb)
5248 + port->buffer_cb(instance,
5249 + port, 0, mmalbuf, 0, 0,
5250 + MMAL_TIME_UNKNOWN,
5251 + MMAL_TIME_UNKNOWN);
5254 + spin_unlock_irqrestore(&port->slock, flags);
5256 + ret = port_info_get(instance, port);
5262 +/* enable a port */
5263 +static int port_enable(struct vchiq_mmal_instance *instance,
5264 + struct vchiq_mmal_port *port)
5266 + unsigned int hdr_count;
5267 + struct list_head *buf_head;
5270 + if (port->enabled)
5273 + /* ensure there are enough buffers queued to cover the buffer headers */
5274 + if (port->buffer_cb != NULL) {
5276 + list_for_each(buf_head, &port->buffers) {
5279 + if (hdr_count < port->current_buffer.num)
5283 + ret = port_action_port(instance, port,
5284 + MMAL_MSG_PORT_ACTION_TYPE_ENABLE);
5288 + port->enabled = true;
5290 + if (port->buffer_cb) {
5291 + /* send buffer headers to videocore */
5293 + list_for_each(buf_head, &port->buffers) {
5294 + struct mmal_buffer *mmalbuf;
5295 + mmalbuf = list_entry(buf_head, struct mmal_buffer,
5297 + ret = buffer_from_host(instance, port, mmalbuf);
5302 + if (hdr_count > port->current_buffer.num)
5307 + ret = port_info_get(instance, port);
5313 +/* ------------------------------------------------------------------
5315 + *------------------------------------------------------------------*/
5317 +int vchiq_mmal_port_set_format(struct vchiq_mmal_instance *instance,
5318 + struct vchiq_mmal_port *port)
5322 + if (mutex_lock_interruptible(&instance->vchiq_mutex))
5325 + ret = port_info_set(instance, port);
5327 + goto release_unlock;
5329 + /* read what has actually been set */
5330 + ret = port_info_get(instance, port);
5333 + mutex_unlock(&instance->vchiq_mutex);
5339 +int vchiq_mmal_port_parameter_set(struct vchiq_mmal_instance *instance,
5340 + struct vchiq_mmal_port *port,
5341 + u32 parameter, void *value, u32 value_size)
5345 + if (mutex_lock_interruptible(&instance->vchiq_mutex))
5348 + ret = port_parameter_set(instance, port, parameter, value, value_size);
5350 + mutex_unlock(&instance->vchiq_mutex);
5355 +int vchiq_mmal_port_parameter_get(struct vchiq_mmal_instance *instance,
5356 + struct vchiq_mmal_port *port,
5357 + u32 parameter, void *value, u32 *value_size)
5361 + if (mutex_lock_interruptible(&instance->vchiq_mutex))
5364 + ret = port_parameter_get(instance, port, parameter, value, value_size);
5366 + mutex_unlock(&instance->vchiq_mutex);
5373 + * enables a port and queues buffers for satisfying callbacks if we
5374 + * provide a callback handler
5376 +int vchiq_mmal_port_enable(struct vchiq_mmal_instance *instance,
5377 + struct vchiq_mmal_port *port,
5378 + vchiq_mmal_buffer_cb buffer_cb)
5382 + if (mutex_lock_interruptible(&instance->vchiq_mutex))
5385 + /* already enabled - noop */
5386 + if (port->enabled) {
5391 + port->buffer_cb = buffer_cb;
5393 + ret = port_enable(instance, port);
5396 + mutex_unlock(&instance->vchiq_mutex);
5401 +int vchiq_mmal_port_disable(struct vchiq_mmal_instance *instance,
5402 + struct vchiq_mmal_port *port)
5406 + if (mutex_lock_interruptible(&instance->vchiq_mutex))
5409 + if (!port->enabled) {
5410 + mutex_unlock(&instance->vchiq_mutex);
5414 + ret = port_disable(instance, port);
5416 + mutex_unlock(&instance->vchiq_mutex);
5421 +/* ports will be connected in a tunneled manner so data buffers
5422 + * are not handled by client.
5424 +int vchiq_mmal_port_connect_tunnel(struct vchiq_mmal_instance *instance,
5425 + struct vchiq_mmal_port *src,
5426 + struct vchiq_mmal_port *dst)
5430 + if (mutex_lock_interruptible(&instance->vchiq_mutex))
5433 + /* disconnect ports if connected */
5434 + if (src->connected != NULL) {
5435 + ret = port_disable(instance, src);
5437 + pr_err("failed disabling src port(%d)\n", ret);
5438 + goto release_unlock;
5441 + /* do not need to disable the destination port as they
5442 + * are connected and it is done automatically
5445 + ret = port_action_handle(instance, src,
5446 + MMAL_MSG_PORT_ACTION_TYPE_DISCONNECT,
5447 + src->connected->component->handle,
5448 + src->connected->handle);
5450 + pr_err("failed disconnecting src port\n");
5451 + goto release_unlock;
5453 + src->connected->enabled = false;
5454 + src->connected = NULL;
5457 + if (dst == NULL) {
5458 + /* do not make new connection */
5460 + pr_debug("not making new connection\n");
5461 + goto release_unlock;
5464 + /* copy src port format to dst */
5465 + dst->format.encoding = src->format.encoding;
5466 + dst->es.video.width = src->es.video.width;
5467 + dst->es.video.height = src->es.video.height;
5468 + dst->es.video.crop.x = src->es.video.crop.x;
5469 + dst->es.video.crop.y = src->es.video.crop.y;
5470 + dst->es.video.crop.width = src->es.video.crop.width;
5471 + dst->es.video.crop.height = src->es.video.crop.height;
5472 + dst->es.video.frame_rate.num = src->es.video.frame_rate.num;
5473 + dst->es.video.frame_rate.den = src->es.video.frame_rate.den;
5475 + /* set new format */
5476 + ret = port_info_set(instance, dst);
5478 + pr_debug("setting port info failed\n");
5479 + goto release_unlock;
5482 + /* read what has actually been set */
5483 + ret = port_info_get(instance, dst);
5485 + pr_debug("read back port info failed\n");
5486 + goto release_unlock;
5489 + /* connect two ports together */
5490 + ret = port_action_handle(instance, src,
5491 + MMAL_MSG_PORT_ACTION_TYPE_CONNECT,
5492 + dst->component->handle, dst->handle);
5494 + pr_debug("connecting port %d:%d to %d:%d failed\n",
5495 + src->component->handle, src->handle,
5496 + dst->component->handle, dst->handle);
5497 + goto release_unlock;
5499 + src->connected = dst;
5503 + mutex_unlock(&instance->vchiq_mutex);
5508 +int vchiq_mmal_submit_buffer(struct vchiq_mmal_instance *instance,
5509 + struct vchiq_mmal_port *port,
5510 + struct mmal_buffer *buffer)
5512 + unsigned long flags = 0;
5514 + spin_lock_irqsave(&port->slock, flags);
5515 + list_add_tail(&buffer->list, &port->buffers);
5516 + spin_unlock_irqrestore(&port->slock, flags);
5518 + /* the port previously underflowed because it was missing a
5519 + * mmal_buffer which has just been added, submit that buffer
5520 + * to the mmal service.
5522 + if (port->buffer_underflow) {
5523 + port_buffer_from_host(instance, port);
5524 + port->buffer_underflow--;
5530 +/* Initialise a mmal component and its ports
5533 +int vchiq_mmal_component_init(struct vchiq_mmal_instance *instance,
5535 + struct vchiq_mmal_component **component_out)
5538 + int idx; /* port index */
5539 + struct vchiq_mmal_component *component;
5541 + if (mutex_lock_interruptible(&instance->vchiq_mutex))
5544 + if (instance->component_idx == VCHIQ_MMAL_MAX_COMPONENTS) {
5545 + ret = -EINVAL; /* todo is this correct error? */
5549 + component = &instance->component[instance->component_idx];
5551 + ret = create_component(instance, component, name);
5555 + /* ports info needs gathering */
5556 + component->control.type = MMAL_PORT_TYPE_CONTROL;
5557 + component->control.index = 0;
5558 + component->control.component = component;
5559 + spin_lock_init(&component->control.slock);
5560 + INIT_LIST_HEAD(&component->control.buffers);
5561 + ret = port_info_get(instance, &component->control);
5563 + goto release_component;
5565 + for (idx = 0; idx < component->inputs; idx++) {
5566 + component->input[idx].type = MMAL_PORT_TYPE_INPUT;
5567 + component->input[idx].index = idx;
5568 + component->input[idx].component = component;
5569 + spin_lock_init(&component->input[idx].slock);
5570 + INIT_LIST_HEAD(&component->input[idx].buffers);
5571 + ret = port_info_get(instance, &component->input[idx]);
5573 + goto release_component;
5576 + for (idx = 0; idx < component->outputs; idx++) {
5577 + component->output[idx].type = MMAL_PORT_TYPE_OUTPUT;
5578 + component->output[idx].index = idx;
5579 + component->output[idx].component = component;
5580 + spin_lock_init(&component->output[idx].slock);
5581 + INIT_LIST_HEAD(&component->output[idx].buffers);
5582 + ret = port_info_get(instance, &component->output[idx]);
5584 + goto release_component;
5587 + for (idx = 0; idx < component->clocks; idx++) {
5588 + component->clock[idx].type = MMAL_PORT_TYPE_CLOCK;
5589 + component->clock[idx].index = idx;
5590 + component->clock[idx].component = component;
5591 + spin_lock_init(&component->clock[idx].slock);
5592 + INIT_LIST_HEAD(&component->clock[idx].buffers);
5593 + ret = port_info_get(instance, &component->clock[idx]);
5595 + goto release_component;
5598 + instance->component_idx++;
5600 + *component_out = component;
5602 + mutex_unlock(&instance->vchiq_mutex);
5607 + destroy_component(instance, component);
5609 + mutex_unlock(&instance->vchiq_mutex);
5615 + * cause a mmal component to be destroyed
5617 +int vchiq_mmal_component_finalise(struct vchiq_mmal_instance *instance,
5618 + struct vchiq_mmal_component *component)
5622 + if (mutex_lock_interruptible(&instance->vchiq_mutex))
5625 + if (component->enabled)
5626 + ret = disable_component(instance, component);
5628 + ret = destroy_component(instance, component);
5630 + mutex_unlock(&instance->vchiq_mutex);
5636 + * cause a mmal component to be enabled
5638 +int vchiq_mmal_component_enable(struct vchiq_mmal_instance *instance,
5639 + struct vchiq_mmal_component *component)
5643 + if (mutex_lock_interruptible(&instance->vchiq_mutex))
5646 + if (component->enabled) {
5647 + mutex_unlock(&instance->vchiq_mutex);
5651 + ret = enable_component(instance, component);
5653 + component->enabled = true;
5655 + mutex_unlock(&instance->vchiq_mutex);
5661 + * cause a mmal component to be enabled
5663 +int vchiq_mmal_component_disable(struct vchiq_mmal_instance *instance,
5664 + struct vchiq_mmal_component *component)
5668 + if (mutex_lock_interruptible(&instance->vchiq_mutex))
5671 + if (!component->enabled) {
5672 + mutex_unlock(&instance->vchiq_mutex);
5676 + ret = disable_component(instance, component);
5678 + component->enabled = false;
5680 + mutex_unlock(&instance->vchiq_mutex);
5685 +int vchiq_mmal_version(struct vchiq_mmal_instance *instance,
5686 + u32 *major_out, u32 *minor_out)
5690 + if (mutex_lock_interruptible(&instance->vchiq_mutex))
5693 + ret = get_version(instance, major_out, minor_out);
5695 + mutex_unlock(&instance->vchiq_mutex);
5700 +int vchiq_mmal_finalise(struct vchiq_mmal_instance *instance)
5704 + if (instance == NULL)
5707 + if (mutex_lock_interruptible(&instance->vchiq_mutex))
5710 + vchi_service_use(instance->handle);
5712 + status = vchi_service_close(instance->handle);
5714 + pr_err("mmal-vchiq: VCHIQ close failed");
5716 + mutex_unlock(&instance->vchiq_mutex);
5718 + vfree(instance->bulk_scratch);
5725 +int vchiq_mmal_init(struct vchiq_mmal_instance **out_instance)
5728 + struct vchiq_mmal_instance *instance;
5729 + static VCHI_CONNECTION_T *vchi_connection;
5730 + static VCHI_INSTANCE_T vchi_instance;
5731 + SERVICE_CREATION_T params = {
5732 + VCHI_VERSION_EX(VC_MMAL_VER, VC_MMAL_MIN_VER),
5733 + VC_MMAL_SERVER_NAME,
5735 + 0, /* rx fifo size (unused) */
5736 + 0, /* tx fifo size (unused) */
5738 + NULL, /* service callback parameter */
5739 + 1, /* unaligned bulk receives */
5740 + 1, /* unaligned bulk transmits */
5741 + 0 /* want crc check on bulk transfers */
5744 + /* compile time checks to ensure structure size as they are
5745 + * directly (de)serialised from memory.
5748 + /* ensure the header structure has packed to the correct size */
5749 + BUILD_BUG_ON(sizeof(struct mmal_msg_header) != 24);
5751 + /* ensure message structure does not exceed maximum length */
5752 + BUILD_BUG_ON(sizeof(struct mmal_msg) > MMAL_MSG_MAX_SIZE);
5754 + /* mmal port struct is correct size */
5755 + BUILD_BUG_ON(sizeof(struct mmal_port) != 64);
5757 + /* create a vchi instance */
5758 + status = vchi_initialise(&vchi_instance);
5760 + pr_err("Failed to initialise VCHI instance (status=%d)\n",
5765 + status = vchi_connect(NULL, 0, vchi_instance);
5767 + pr_err("Failed to connect VCHI instance (status=%d)\n", status);
5771 + instance = kmalloc(sizeof(*instance), GFP_KERNEL);
5772 + memset(instance, 0, sizeof(*instance));
5774 + mutex_init(&instance->vchiq_mutex);
5775 + mutex_init(&instance->bulk_mutex);
5777 + instance->bulk_scratch = vmalloc(PAGE_SIZE);
5779 + params.callback_param = instance;
5781 + status = vchi_service_open(vchi_instance, ¶ms, &instance->handle);
5783 + pr_err("Failed to open VCHI service connection (status=%d)\n",
5785 + goto err_close_services;
5788 + vchi_service_release(instance->handle);
5790 + *out_instance = instance;
5794 +err_close_services:
5796 + vchi_service_close(instance->handle);
5797 + vfree(instance->bulk_scratch);
5801 diff --git a/drivers/media/platform/bcm2835/mmal-vchiq.h b/drivers/media/platform/bcm2835/mmal-vchiq.h
5802 new file mode 100644
5803 index 0000000..9d1d11e
5805 +++ b/drivers/media/platform/bcm2835/mmal-vchiq.h
5808 + * Broadcom BM2835 V4L2 driver
5810 + * Copyright © 2013 Raspberry Pi (Trading) Ltd.
5812 + * This file is subject to the terms and conditions of the GNU General Public
5813 + * License. See the file COPYING in the main directory of this archive
5814 + * for more details.
5816 + * Authors: Vincent Sanders <vincent.sanders@collabora.co.uk>
5817 + * Dave Stevenson <dsteve@broadcom.com>
5818 + * Simon Mellor <simellor@broadcom.com>
5819 + * Luke Diamand <luked@broadcom.com>
5821 + * MMAL interface to VCHIQ message passing
5824 +#ifndef MMAL_VCHIQ_H
5825 +#define MMAL_VCHIQ_H
5827 +#include "mmal-msg-format.h"
5829 +#define MAX_PORT_COUNT 4
5831 +/* Maximum size of the format extradata. */
5832 +#define MMAL_FORMAT_EXTRADATA_MAX_SIZE 128
5834 +struct vchiq_mmal_instance;
5836 +enum vchiq_mmal_es_type {
5837 + MMAL_ES_TYPE_UNKNOWN, /**< Unknown elementary stream type */
5838 + MMAL_ES_TYPE_CONTROL, /**< Elementary stream of control commands */
5839 + MMAL_ES_TYPE_AUDIO, /**< Audio elementary stream */
5840 + MMAL_ES_TYPE_VIDEO, /**< Video elementary stream */
5841 + MMAL_ES_TYPE_SUBPICTURE /**< Sub-picture elementary stream */
5844 +/* rectangle, used lots so it gets its own struct */
5845 +struct vchiq_mmal_rect {
5852 +struct vchiq_mmal_port_buffer {
5853 + unsigned int num; /* number of buffers */
5854 + u32 size; /* size of buffers */
5855 + u32 alignment; /* alignment of buffers */
5858 +struct vchiq_mmal_port;
5860 +typedef void (*vchiq_mmal_buffer_cb)(
5861 + struct vchiq_mmal_instance *instance,
5862 + struct vchiq_mmal_port *port,
5863 + int status, struct mmal_buffer *buffer,
5864 + unsigned long length, u32 mmal_flags, s64 dts, s64 pts);
5866 +struct vchiq_mmal_port {
5869 + u32 type; /* port type, cached to use on port info set */
5870 + u32 index; /* port index, cached to use on port info set */
5872 + /* component port belongs to, allows simple deref */
5873 + struct vchiq_mmal_component *component;
5875 + struct vchiq_mmal_port *connected; /* port conencted to */
5878 + struct vchiq_mmal_port_buffer minimum_buffer;
5879 + struct vchiq_mmal_port_buffer recommended_buffer;
5880 + struct vchiq_mmal_port_buffer current_buffer;
5882 + /* stream format */
5883 + struct mmal_es_format format;
5884 + /* elementry stream format */
5885 + union mmal_es_specific_format es;
5887 + /* data buffers to fill */
5888 + struct list_head buffers;
5889 + /* lock to serialise adding and removing buffers from list */
5891 + /* count of how many buffer header refils have failed because
5892 + * there was no buffer to satisfy them
5894 + int buffer_underflow;
5895 + /* callback on buffer completion */
5896 + vchiq_mmal_buffer_cb buffer_cb;
5897 + /* callback context */
5901 +struct vchiq_mmal_component {
5903 + u32 handle; /* VideoCore handle for component */
5904 + u32 inputs; /* Number of input ports */
5905 + u32 outputs; /* Number of output ports */
5906 + u32 clocks; /* Number of clock ports */
5907 + struct vchiq_mmal_port control; /* control port */
5908 + struct vchiq_mmal_port input[MAX_PORT_COUNT]; /* input ports */
5909 + struct vchiq_mmal_port output[MAX_PORT_COUNT]; /* output ports */
5910 + struct vchiq_mmal_port clock[MAX_PORT_COUNT]; /* clock ports */
5914 +int vchiq_mmal_init(struct vchiq_mmal_instance **out_instance);
5915 +int vchiq_mmal_finalise(struct vchiq_mmal_instance *instance);
5917 +/* Initialise a mmal component and its ports
5920 +int vchiq_mmal_component_init(
5921 + struct vchiq_mmal_instance *instance,
5923 + struct vchiq_mmal_component **component_out);
5925 +int vchiq_mmal_component_finalise(
5926 + struct vchiq_mmal_instance *instance,
5927 + struct vchiq_mmal_component *component);
5929 +int vchiq_mmal_component_enable(
5930 + struct vchiq_mmal_instance *instance,
5931 + struct vchiq_mmal_component *component);
5933 +int vchiq_mmal_component_disable(
5934 + struct vchiq_mmal_instance *instance,
5935 + struct vchiq_mmal_component *component);
5939 +/* enable a mmal port
5941 + * enables a port and if a buffer callback provided enque buffer
5942 + * headers as apropriate for the port.
5944 +int vchiq_mmal_port_enable(
5945 + struct vchiq_mmal_instance *instance,
5946 + struct vchiq_mmal_port *port,
5947 + vchiq_mmal_buffer_cb buffer_cb);
5951 + * disable a port will dequeue any pending buffers
5953 +int vchiq_mmal_port_disable(struct vchiq_mmal_instance *instance,
5954 + struct vchiq_mmal_port *port);
5957 +int vchiq_mmal_port_parameter_set(struct vchiq_mmal_instance *instance,
5958 + struct vchiq_mmal_port *port,
5963 +int vchiq_mmal_port_parameter_get(struct vchiq_mmal_instance *instance,
5964 + struct vchiq_mmal_port *port,
5969 +int vchiq_mmal_port_set_format(struct vchiq_mmal_instance *instance,
5970 + struct vchiq_mmal_port *port);
5972 +int vchiq_mmal_port_connect_tunnel(struct vchiq_mmal_instance *instance,
5973 + struct vchiq_mmal_port *src,
5974 + struct vchiq_mmal_port *dst);
5976 +int vchiq_mmal_version(struct vchiq_mmal_instance *instance,
5980 +int vchiq_mmal_submit_buffer(struct vchiq_mmal_instance *instance,
5981 + struct vchiq_mmal_port *port,
5982 + struct mmal_buffer *buf);
5984 +#endif /* MMAL_VCHIQ_H */