1 From 40c37d87f774c86135ad5b9b9313cfedf232c864 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 30/54] 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 | 1478 +++++++++++++++++
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 | 52 +
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, 5829 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
50 +++ b/Documentation/video4linux/bcm2835-v4l2.txt
53 +BCM2835 (aka Raspberry Pi) V4L2 driver
54 +======================================
59 +Copyright © 2013 Raspberry Pi (Trading) Ltd.
64 +This program is free software; you can redistribute it and/or modify
65 +it under the terms of the GNU General Public License as published by
66 +the Free Software Foundation; either version 2 of the License, or
67 +(at your option) any later version.
69 +This program is distributed in the hope that it will be useful,
70 +but WITHOUT ANY WARRANTY; without even the implied warranty of
71 +MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
72 +GNU General Public License for more details.
74 +You should have received a copy of the GNU General Public License
75 +along with this program; if not, write to the Free Software
76 +Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
81 +You need a version 1.0 or later of v4l2-ctl, available from:
82 + git://git.linuxtv.org/v4l-utils.git
84 +$ sudo modprobe bcm2835-v4l2
88 +$ v4l2-ctl --overlay=1
90 +Turn off the overlay:
92 +$ v4l2-ctl --overlay=0
94 +Set the capture format for video:
96 +$ v4l2-ctl --set-fmt-video=width=1920,height=1088,pixelformat=4
98 +(Note: 1088 not 1080).
102 +$ v4l2-ctl --stream-mmap=3 --stream-count=100 --stream-to=somefile.h264
106 +$ v4l2-ctl --set-fmt-video=width=2592,height=1944,pixelformat=3
107 +$ v4l2-ctl --stream-mmap=3 --stream-count=1 --stream-to=somefile.jpg
109 +List of available formats:
111 +$ v4l2-ctl --list-formats
112 --- a/drivers/media/platform/Kconfig
113 +++ b/drivers/media/platform/Kconfig
114 @@ -118,6 +118,7 @@ config VIDEO_S3C_CAMIF
115 source "drivers/media/platform/soc_camera/Kconfig"
116 source "drivers/media/platform/exynos4-is/Kconfig"
117 source "drivers/media/platform/s5p-tv/Kconfig"
118 +source "drivers/media/platform/bcm2835/Kconfig"
120 endif # V4L_PLATFORM_DRIVERS
122 --- a/drivers/media/platform/Makefile
123 +++ b/drivers/media/platform/Makefile
124 @@ -51,4 +51,6 @@ obj-y += davinci/
126 obj-$(CONFIG_ARCH_OMAP) += omap/
128 +obj-$(CONFIG_VIDEO_BCM2835) += bcm2835/
130 ccflags-y += -I$(srctree)/drivers/media/i2c
132 +++ b/drivers/media/platform/bcm2835/Kconfig
134 +# Broadcom VideoCore IV v4l2 camera support
136 +config VIDEO_BCM2835
137 + bool "Broadcom BCM2835 camera interface driver"
138 + depends on VIDEO_V4L2 && ARCH_BCM2708
140 + Say Y here to enable camera host interface devices for
141 + Broadcom BCM2835 SoC. This operates over the VCHIQ interface
142 + to a service running on VideoCore.
147 +config VIDEO_BCM2835_MMAL
148 + tristate "Broadcom BM2835 MMAL camera interface driver"
149 + depends on BCM2708_VCHIQ
150 + select VIDEOBUF2_VMALLOC
152 + This is a V4L2 driver for the Broadcom BCM2835 MMAL camera host interface
154 + To compile this driver as a module, choose M here: the
155 + module will be called bcm2835-v4l2.o
158 +endif # VIDEO_BM2835
160 +++ b/drivers/media/platform/bcm2835/Makefile
162 +bcm2835-v4l2-objs := bcm2835-camera.o controls.o mmal-vchiq.o
164 +obj-$(CONFIG_VIDEO_BCM2835_MMAL) += bcm2835-v4l2.o
166 +ccflags-$(CONFIG_VIDEO_BCM2835) += -Idrivers/misc/vc04_services -Idrivers/misc/vc04_services/interface/vcos/linuxkernel -D__VCCOREVER__=0x04000000
168 +++ b/drivers/media/platform/bcm2835/bcm2835-camera.c
171 + * Broadcom BM2835 V4L2 driver
173 + * Copyright © 2013 Raspberry Pi (Trading) Ltd.
175 + * This file is subject to the terms and conditions of the GNU General Public
176 + * License. See the file COPYING in the main directory of this archive
177 + * for more details.
179 + * Authors: Vincent Sanders <vincent.sanders@collabora.co.uk>
180 + * Dave Stevenson <dsteve@broadcom.com>
181 + * Simon Mellor <simellor@broadcom.com>
182 + * Luke Diamand <luked@broadcom.com>
185 +#include <linux/errno.h>
186 +#include <linux/kernel.h>
187 +#include <linux/module.h>
188 +#include <linux/slab.h>
189 +#include <media/videobuf2-vmalloc.h>
190 +#include <media/videobuf2-dma-contig.h>
191 +#include <media/v4l2-device.h>
192 +#include <media/v4l2-ioctl.h>
193 +#include <media/v4l2-ctrls.h>
194 +#include <media/v4l2-fh.h>
195 +#include <media/v4l2-event.h>
196 +#include <media/v4l2-common.h>
197 +#include <linux/delay.h>
199 +#include "mmal-common.h"
200 +#include "mmal-encodings.h"
201 +#include "mmal-vchiq.h"
202 +#include "mmal-msg.h"
203 +#include "mmal-parameters.h"
204 +#include "bcm2835-camera.h"
206 +#define BM2835_MMAL_VERSION "0.0.2"
207 +#define BM2835_MMAL_MODULE_NAME "bcm2835-v4l2"
209 +#define MAX_WIDTH 2592
210 +#define MAX_HEIGHT 1944
211 +#define MIN_BUFFER_SIZE (80*1024)
213 +#define MAX_VIDEO_MODE_WIDTH 1280
214 +#define MAX_VIDEO_MODE_HEIGHT 720
216 +MODULE_DESCRIPTION("Broadcom 2835 MMAL video capture");
217 +MODULE_AUTHOR("Vincent Sanders");
218 +MODULE_LICENSE("GPL");
219 +MODULE_VERSION(BM2835_MMAL_VERSION);
221 +int bcm2835_v4l2_debug;
222 +module_param_named(debug, bcm2835_v4l2_debug, int, 0644);
223 +MODULE_PARM_DESC(bcm2835_v4l2_debug, "Debug level 0-2");
225 +static struct bm2835_mmal_dev *gdev; /* global device data */
228 +static struct mmal_fmt formats[] = {
230 + .name = "4:2:0, packed YUV",
231 + .fourcc = V4L2_PIX_FMT_YUV420,
232 + .mmal = MMAL_ENCODING_I420,
234 + .mmal_component = MMAL_COMPONENT_CAMERA,
237 + .name = "4:2:2, packed, YUYV",
238 + .fourcc = V4L2_PIX_FMT_YUYV,
239 + .mmal = MMAL_ENCODING_YUYV,
241 + .mmal_component = MMAL_COMPONENT_CAMERA,
244 + .name = "RGB24 (BE)",
245 + .fourcc = V4L2_PIX_FMT_BGR24,
246 + .mmal = MMAL_ENCODING_BGR24,
248 + .mmal_component = MMAL_COMPONENT_CAMERA,
252 + .fourcc = V4L2_PIX_FMT_JPEG,
253 + .mmal = MMAL_ENCODING_JPEG,
255 + .mmal_component = MMAL_COMPONENT_IMAGE_ENCODE,
259 + .fourcc = V4L2_PIX_FMT_H264,
260 + .mmal = MMAL_ENCODING_H264,
262 + .mmal_component = MMAL_COMPONENT_VIDEO_ENCODE,
266 +static struct mmal_fmt *get_format(struct v4l2_format *f)
268 + struct mmal_fmt *fmt;
271 + for (k = 0; k < ARRAY_SIZE(formats); k++) {
273 + if (fmt->fourcc == f->fmt.pix.pixelformat)
277 + if (k == ARRAY_SIZE(formats))
280 + return &formats[k];
283 +/* ------------------------------------------------------------------
284 + Videobuf queue operations
285 + ------------------------------------------------------------------*/
287 +static int queue_setup(struct vb2_queue *vq, const struct v4l2_format *fmt,
288 + unsigned int *nbuffers, unsigned int *nplanes,
289 + unsigned int sizes[], void *alloc_ctxs[])
291 + struct bm2835_mmal_dev *dev = vb2_get_drv_priv(vq);
292 + unsigned long size;
294 + /* refuse queue setup if port is not configured */
295 + if (dev->capture.port == NULL) {
296 + v4l2_err(&dev->v4l2_dev,
297 + "%s: capture port not configured\n", __func__);
301 + size = dev->capture.port->current_buffer.size;
303 + v4l2_err(&dev->v4l2_dev,
304 + "%s: capture port buffer size is zero\n", __func__);
308 + if (*nbuffers < (dev->capture.port->current_buffer.num + 2))
309 + *nbuffers = (dev->capture.port->current_buffer.num + 2);
316 + * videobuf2-vmalloc allocator is context-less so no need to set
317 + * alloc_ctxs array.
320 + v4l2_dbg(1, bcm2835_v4l2_debug, &dev->v4l2_dev, "%s: dev:%p\n",
326 +static int buffer_prepare(struct vb2_buffer *vb)
328 + struct bm2835_mmal_dev *dev = vb2_get_drv_priv(vb->vb2_queue);
329 + unsigned long size;
331 + v4l2_dbg(1, bcm2835_v4l2_debug, &dev->v4l2_dev, "%s: dev:%p\n",
334 + BUG_ON(dev->capture.port == NULL);
335 + BUG_ON(dev->capture.fmt == NULL);
337 + size = dev->capture.stride * dev->capture.height;
338 + if (vb2_plane_size(vb, 0) < size) {
339 + v4l2_err(&dev->v4l2_dev,
340 + "%s data will not fit into plane (%lu < %lu)\n",
341 + __func__, vb2_plane_size(vb, 0), size);
348 +static inline bool is_capturing(struct bm2835_mmal_dev *dev)
350 + return dev->capture.camera_port ==
352 + component[MMAL_COMPONENT_CAMERA]->output[MMAL_CAMERA_PORT_CAPTURE];
355 +static void buffer_cb(struct vchiq_mmal_instance *instance,
356 + struct vchiq_mmal_port *port,
358 + struct mmal_buffer *buf,
359 + unsigned long length, u32 mmal_flags, s64 dts, s64 pts)
361 + struct bm2835_mmal_dev *dev = port->cb_ctx;
363 + v4l2_dbg(1, bcm2835_v4l2_debug, &dev->v4l2_dev,
364 + "%s: status:%d, buf:%p, length:%lu, flags %u, pts %lld\n",
365 + __func__, status, buf, length, mmal_flags, pts);
368 + /* error in transfer */
370 + /* there was a buffer with the error so return it */
371 + vb2_buffer_done(&buf->vb, VB2_BUF_STATE_ERROR);
374 + } else if (length == 0) {
377 + /* this should only ever happen if the port is
378 + * disabled and there are buffers still queued
380 + vb2_buffer_done(&buf->vb, VB2_BUF_STATE_ERROR);
381 + pr_debug("Empty buffer");
382 + } else if (dev->capture.frame_count) {
383 + /* grab another frame */
384 + if (is_capturing(dev)) {
385 + pr_debug("Grab another frame");
386 + vchiq_mmal_port_parameter_set(
390 + MMAL_PARAMETER_CAPTURE,
393 + sizeof(dev->capture.frame_count));
396 + /* signal frame completion */
397 + complete(&dev->capture.frame_cmplt);
400 + if (dev->capture.frame_count) {
401 + if (dev->capture.vc_start_timestamp != -1) {
402 + s64 runtime_us = pts -
403 + dev->capture.vc_start_timestamp;
408 + div_u64_rem(runtime_us, USEC_PER_SEC, &rem);
409 + buf->vb.v4l2_buf.timestamp.tv_sec =
410 + dev->capture.kernel_start_ts.tv_sec - 1 +
412 + buf->vb.v4l2_buf.timestamp.tv_usec =
413 + dev->capture.kernel_start_ts.tv_usec + rem;
415 + if (buf->vb.v4l2_buf.timestamp.tv_usec >=
417 + buf->vb.v4l2_buf.timestamp.tv_sec++;
418 + buf->vb.v4l2_buf.timestamp.tv_usec -=
421 + v4l2_dbg(1, bcm2835_v4l2_debug, &dev->v4l2_dev,
422 + "Convert start time %d.%06d and %llu"
423 + "with offset %llu to %d.%06d\n",
424 + (int)dev->capture.kernel_start_ts.
426 + (int)dev->capture.kernel_start_ts.
428 + dev->capture.vc_start_timestamp, pts,
429 + (int)buf->vb.v4l2_buf.timestamp.tv_sec,
430 + (int)buf->vb.v4l2_buf.timestamp.
433 + v4l2_get_timestamp(&buf->vb.v4l2_buf.timestamp);
436 + vb2_set_plane_payload(&buf->vb, 0, length);
437 + vb2_buffer_done(&buf->vb, VB2_BUF_STATE_DONE);
439 + if (mmal_flags & MMAL_BUFFER_HEADER_FLAG_EOS &&
440 + is_capturing(dev)) {
441 + v4l2_dbg(1, bcm2835_v4l2_debug, &dev->v4l2_dev,
442 + "Grab another frame as buffer has EOS");
443 + vchiq_mmal_port_parameter_set(
447 + MMAL_PARAMETER_CAPTURE,
450 + sizeof(dev->capture.frame_count));
453 + /* signal frame completion */
454 + complete(&dev->capture.frame_cmplt);
459 +static int enable_camera(struct bm2835_mmal_dev *dev)
462 + if (!dev->camera_use_count) {
463 + ret = vchiq_mmal_component_enable(
465 + dev->component[MMAL_COMPONENT_CAMERA]);
467 + v4l2_err(&dev->v4l2_dev,
468 + "Failed enabling camera, ret %d\n", ret);
472 + dev->camera_use_count++;
473 + v4l2_dbg(1, bcm2835_v4l2_debug,
474 + &dev->v4l2_dev, "enabled camera (refcount %d)\n",
475 + dev->camera_use_count);
479 +static int disable_camera(struct bm2835_mmal_dev *dev)
482 + if (!dev->camera_use_count) {
483 + v4l2_err(&dev->v4l2_dev,
484 + "Disabled the camera when already disabled\n");
487 + dev->camera_use_count--;
488 + if (!dev->camera_use_count) {
489 + unsigned int i = 0xFFFFFFFF;
490 + v4l2_dbg(1, bcm2835_v4l2_debug, &dev->v4l2_dev,
491 + "Disabling camera\n");
493 + vchiq_mmal_component_disable(
495 + dev->component[MMAL_COMPONENT_CAMERA]);
497 + v4l2_err(&dev->v4l2_dev,
498 + "Failed disabling camera, ret %d\n", ret);
501 + vchiq_mmal_port_parameter_set(
503 + &dev->component[MMAL_COMPONENT_CAMERA]->control,
504 + MMAL_PARAMETER_CAMERA_NUM, &i,
507 + v4l2_dbg(1, bcm2835_v4l2_debug, &dev->v4l2_dev,
508 + "Camera refcount now %d\n", dev->camera_use_count);
512 +static void buffer_queue(struct vb2_buffer *vb)
514 + struct bm2835_mmal_dev *dev = vb2_get_drv_priv(vb->vb2_queue);
515 + struct mmal_buffer *buf = container_of(vb, struct mmal_buffer, vb);
518 + v4l2_dbg(1, bcm2835_v4l2_debug, &dev->v4l2_dev,
519 + "%s: dev:%p buf:%p\n", __func__, dev, buf);
521 + buf->buffer = vb2_plane_vaddr(&buf->vb, 0);
522 + buf->buffer_size = vb2_plane_size(&buf->vb, 0);
524 + ret = vchiq_mmal_submit_buffer(dev->instance, dev->capture.port, buf);
526 + v4l2_err(&dev->v4l2_dev, "%s: error submitting buffer\n",
530 +static int start_streaming(struct vb2_queue *vq, unsigned int count)
532 + struct bm2835_mmal_dev *dev = vb2_get_drv_priv(vq);
534 + int parameter_size;
536 + v4l2_dbg(1, bcm2835_v4l2_debug, &dev->v4l2_dev, "%s: dev:%p\n",
539 + /* ensure a format has actually been set */
540 + if (dev->capture.port == NULL)
543 + if (enable_camera(dev) < 0) {
544 + v4l2_err(&dev->v4l2_dev, "Failed to enable camera\n");
548 + /*init_completion(&dev->capture.frame_cmplt); */
550 + /* enable frame capture */
551 + dev->capture.frame_count = 1;
553 + /* if the preview is not already running, wait for a few frames for AGC
556 + if (!dev->component[MMAL_COMPONENT_PREVIEW]->enabled)
559 + /* enable the connection from camera to encoder (if applicable) */
560 + if (dev->capture.camera_port != dev->capture.port
561 + && dev->capture.camera_port) {
562 + ret = vchiq_mmal_port_enable(dev->instance,
563 + dev->capture.camera_port, NULL);
565 + v4l2_err(&dev->v4l2_dev,
566 + "Failed to enable encode tunnel - error %d\n",
572 + /* Get VC timestamp at this point in time */
573 + parameter_size = sizeof(dev->capture.vc_start_timestamp);
574 + if (vchiq_mmal_port_parameter_get(dev->instance,
575 + dev->capture.camera_port,
576 + MMAL_PARAMETER_SYSTEM_TIME,
577 + &dev->capture.vc_start_timestamp,
578 + ¶meter_size)) {
579 + v4l2_err(&dev->v4l2_dev,
580 + "Failed to get VC start time - update your VC f/w\n");
582 + /* Flag to indicate just to rely on kernel timestamps */
583 + dev->capture.vc_start_timestamp = -1;
585 + v4l2_dbg(1, bcm2835_v4l2_debug, &dev->v4l2_dev,
586 + "Start time %lld size %d\n",
587 + dev->capture.vc_start_timestamp, parameter_size);
589 + v4l2_get_timestamp(&dev->capture.kernel_start_ts);
591 + /* enable the camera port */
592 + dev->capture.port->cb_ctx = dev;
594 + vchiq_mmal_port_enable(dev->instance, dev->capture.port, buffer_cb);
596 + v4l2_err(&dev->v4l2_dev,
597 + "Failed to enable capture port - error %d\n", ret);
601 + /* capture the first frame */
602 + vchiq_mmal_port_parameter_set(dev->instance,
603 + dev->capture.camera_port,
604 + MMAL_PARAMETER_CAPTURE,
605 + &dev->capture.frame_count,
606 + sizeof(dev->capture.frame_count));
610 +/* abort streaming and wait for last buffer */
611 +static int stop_streaming(struct vb2_queue *vq)
614 + struct bm2835_mmal_dev *dev = vb2_get_drv_priv(vq);
616 + v4l2_dbg(1, bcm2835_v4l2_debug, &dev->v4l2_dev, "%s: dev:%p\n",
619 + init_completion(&dev->capture.frame_cmplt);
620 + dev->capture.frame_count = 0;
622 + /* ensure a format has actually been set */
623 + if (dev->capture.port == NULL)
626 + v4l2_dbg(1, bcm2835_v4l2_debug, &dev->v4l2_dev, "stopping capturing\n");
628 + /* stop capturing frames */
629 + vchiq_mmal_port_parameter_set(dev->instance,
630 + dev->capture.camera_port,
631 + MMAL_PARAMETER_CAPTURE,
632 + &dev->capture.frame_count,
633 + sizeof(dev->capture.frame_count));
635 + /* wait for last frame to complete */
636 + ret = wait_for_completion_timeout(&dev->capture.frame_cmplt, HZ);
638 + v4l2_err(&dev->v4l2_dev,
639 + "error %d waiting for frame completion\n", ret);
641 + v4l2_dbg(1, bcm2835_v4l2_debug, &dev->v4l2_dev,
642 + "disabling connection\n");
644 + /* disable the connection from camera to encoder */
645 + ret = vchiq_mmal_port_disable(dev->instance, dev->capture.camera_port);
646 + if (!ret && dev->capture.camera_port != dev->capture.port) {
647 + v4l2_dbg(1, bcm2835_v4l2_debug, &dev->v4l2_dev,
648 + "disabling port\n");
649 + ret = vchiq_mmal_port_disable(dev->instance, dev->capture.port);
650 + } else if (dev->capture.camera_port != dev->capture.port) {
651 + v4l2_err(&dev->v4l2_dev, "port_disable failed, error %d\n",
655 + if (disable_camera(dev) < 0) {
656 + v4l2_err(&dev->v4l2_dev, "Failed to disable camera");
663 +static void bm2835_mmal_lock(struct vb2_queue *vq)
665 + struct bm2835_mmal_dev *dev = vb2_get_drv_priv(vq);
666 + mutex_lock(&dev->mutex);
669 +static void bm2835_mmal_unlock(struct vb2_queue *vq)
671 + struct bm2835_mmal_dev *dev = vb2_get_drv_priv(vq);
672 + mutex_unlock(&dev->mutex);
675 +static struct vb2_ops bm2835_mmal_video_qops = {
676 + .queue_setup = queue_setup,
677 + .buf_prepare = buffer_prepare,
678 + .buf_queue = buffer_queue,
679 + .start_streaming = start_streaming,
680 + .stop_streaming = stop_streaming,
681 + .wait_prepare = bm2835_mmal_unlock,
682 + .wait_finish = bm2835_mmal_lock,
685 +/* ------------------------------------------------------------------
687 + ------------------------------------------------------------------*/
690 +static int vidioc_enum_fmt_vid_overlay(struct file *file, void *priv,
691 + struct v4l2_fmtdesc *f)
693 + struct mmal_fmt *fmt;
695 + if (f->index >= ARRAY_SIZE(formats))
698 + fmt = &formats[f->index];
700 + strlcpy(f->description, fmt->name, sizeof(f->description));
701 + f->pixelformat = fmt->fourcc;
706 +static int vidioc_g_fmt_vid_overlay(struct file *file, void *priv,
707 + struct v4l2_format *f)
709 + struct bm2835_mmal_dev *dev = video_drvdata(file);
711 + f->fmt.win = dev->overlay;
716 +static int vidioc_try_fmt_vid_overlay(struct file *file, void *priv,
717 + struct v4l2_format *f)
719 + /* Only support one format so get the current one. */
720 + vidioc_g_fmt_vid_overlay(file, priv, f);
722 + /* todo: allow the size and/or offset to be changed. */
726 +static int vidioc_s_fmt_vid_overlay(struct file *file, void *priv,
727 + struct v4l2_format *f)
729 + struct bm2835_mmal_dev *dev = video_drvdata(file);
731 + vidioc_try_fmt_vid_overlay(file, priv, f);
733 + dev->overlay = f->fmt.win;
735 + /* todo: program the preview port parameters */
739 +static int vidioc_overlay(struct file *file, void *f, unsigned int on)
742 + struct bm2835_mmal_dev *dev = video_drvdata(file);
743 + struct vchiq_mmal_port *src;
744 + struct vchiq_mmal_port *dst;
745 + struct mmal_parameter_displayregion prev_config = {
746 + .set = MMAL_DISPLAY_SET_LAYER | MMAL_DISPLAY_SET_ALPHA |
747 + MMAL_DISPLAY_SET_DEST_RECT | MMAL_DISPLAY_SET_FULLSCREEN,
748 + .layer = PREVIEW_LAYER,
752 + .x = dev->overlay.w.left,
753 + .y = dev->overlay.w.top,
754 + .width = dev->overlay.w.width,
755 + .height = dev->overlay.w.height,
759 + if ((on && dev->component[MMAL_COMPONENT_PREVIEW]->enabled) ||
760 + (!on && !dev->component[MMAL_COMPONENT_PREVIEW]->enabled))
761 + return 0; /* already in requested state */
764 + &dev->component[MMAL_COMPONENT_CAMERA]->
765 + output[MMAL_CAMERA_PORT_PREVIEW];
768 + /* disconnect preview ports and disable component */
769 + ret = vchiq_mmal_port_disable(dev->instance, src);
772 + vchiq_mmal_port_connect_tunnel(dev->instance, src,
775 + ret = vchiq_mmal_component_disable(
777 + dev->component[MMAL_COMPONENT_PREVIEW]);
779 + disable_camera(dev);
783 + /* set preview port format and connect it to output */
784 + dst = &dev->component[MMAL_COMPONENT_PREVIEW]->input[0];
786 + ret = vchiq_mmal_port_set_format(dev->instance, src);
790 + ret = vchiq_mmal_port_parameter_set(dev->instance, dst,
791 + MMAL_PARAMETER_DISPLAYREGION,
792 + &prev_config, sizeof(prev_config));
796 + if (enable_camera(dev) < 0)
799 + ret = vchiq_mmal_component_enable(
801 + dev->component[MMAL_COMPONENT_PREVIEW]);
805 + v4l2_dbg(1, bcm2835_v4l2_debug, &dev->v4l2_dev, "connecting %p to %p\n",
807 + ret = vchiq_mmal_port_connect_tunnel(dev->instance, src, dst);
809 + ret = vchiq_mmal_port_enable(dev->instance, src, NULL);
814 +static int vidioc_g_fbuf(struct file *file, void *fh,
815 + struct v4l2_framebuffer *a)
817 + /* The video overlay must stay within the framebuffer and can't be
818 + positioned independently. */
819 + a->flags = V4L2_FBUF_FLAG_OVERLAY;
821 + /* todo: v4l2_framebuffer still needs more info filling in
822 + * in order to pass the v4l2-compliance test. */
828 +static int vidioc_enum_input(struct file *file, void *priv,
829 + struct v4l2_input *inp)
831 + /* only a single camera input */
832 + if (inp->index != 0)
835 + inp->type = V4L2_INPUT_TYPE_CAMERA;
836 + sprintf(inp->name, "Camera %u", inp->index);
840 +static int vidioc_g_input(struct file *file, void *priv, unsigned int *i)
846 +static int vidioc_s_input(struct file *file, void *priv, unsigned int i)
854 +/* capture ioctls */
855 +static int vidioc_querycap(struct file *file, void *priv,
856 + struct v4l2_capability *cap)
858 + struct bm2835_mmal_dev *dev = video_drvdata(file);
862 + vchiq_mmal_version(dev->instance, &major, &minor);
864 + strcpy(cap->driver, "bm2835 mmal");
865 + snprintf(cap->card, sizeof(cap->card), "mmal service %d.%d",
868 + snprintf(cap->bus_info, sizeof(cap->bus_info),
869 + "platform:%s", dev->v4l2_dev.name);
870 + cap->device_caps = V4L2_CAP_VIDEO_CAPTURE | V4L2_CAP_VIDEO_OVERLAY |
871 + V4L2_CAP_STREAMING | V4L2_CAP_READWRITE;
872 + cap->capabilities = cap->device_caps | V4L2_CAP_DEVICE_CAPS;
877 +static int vidioc_enum_fmt_vid_cap(struct file *file, void *priv,
878 + struct v4l2_fmtdesc *f)
880 + struct mmal_fmt *fmt;
882 + if (f->index >= ARRAY_SIZE(formats))
885 + fmt = &formats[f->index];
887 + strlcpy(f->description, fmt->name, sizeof(f->description));
888 + f->pixelformat = fmt->fourcc;
892 +static int vidioc_g_fmt_vid_cap(struct file *file, void *priv,
893 + struct v4l2_format *f)
895 + struct bm2835_mmal_dev *dev = video_drvdata(file);
897 + f->fmt.pix.width = dev->capture.width;
898 + f->fmt.pix.height = dev->capture.height;
899 + f->fmt.pix.field = V4L2_FIELD_NONE;
900 + f->fmt.pix.pixelformat = dev->capture.fmt->fourcc;
901 + f->fmt.pix.bytesperline =
902 + (f->fmt.pix.width * dev->capture.fmt->depth) >> 3;
903 + f->fmt.pix.sizeimage = f->fmt.pix.height * f->fmt.pix.bytesperline;
904 + if (dev->capture.fmt->fourcc == V4L2_PIX_FMT_JPEG
905 + && f->fmt.pix.sizeimage < (100 << 10)) {
906 + /* Need a minimum size for JPEG to account for EXIF. */
907 + f->fmt.pix.sizeimage = (100 << 10);
910 + if (dev->capture.fmt->fourcc == V4L2_PIX_FMT_YUYV ||
911 + dev->capture.fmt->fourcc == V4L2_PIX_FMT_UYVY)
912 + f->fmt.pix.colorspace = V4L2_COLORSPACE_SMPTE170M;
914 + f->fmt.pix.colorspace = V4L2_COLORSPACE_SRGB;
915 + f->fmt.pix.priv = 0;
917 + v4l2_dump_pix_format(1, bcm2835_v4l2_debug, &dev->v4l2_dev, &f->fmt.pix,
922 +static int vidioc_try_fmt_vid_cap(struct file *file, void *priv,
923 + struct v4l2_format *f)
925 + struct bm2835_mmal_dev *dev = video_drvdata(file);
926 + struct mmal_fmt *mfmt;
928 + mfmt = get_format(f);
930 + v4l2_dbg(1, bcm2835_v4l2_debug, &dev->v4l2_dev,
931 + "Fourcc format (0x%08x) unknown.\n",
932 + f->fmt.pix.pixelformat);
933 + f->fmt.pix.pixelformat = formats[0].fourcc;
934 + mfmt = get_format(f);
937 + f->fmt.pix.field = V4L2_FIELD_NONE;
938 + /* image must be a multiple of 32 pixels wide and 16 lines high */
939 + v4l_bound_align_image(&f->fmt.pix.width, 48, MAX_WIDTH, 5,
940 + &f->fmt.pix.height, 32, MAX_HEIGHT, 4, 0);
941 + f->fmt.pix.bytesperline = (f->fmt.pix.width * mfmt->depth) >> 3;
942 + f->fmt.pix.sizeimage = f->fmt.pix.height * f->fmt.pix.bytesperline;
943 + if (f->fmt.pix.sizeimage < MIN_BUFFER_SIZE)
944 + f->fmt.pix.sizeimage = MIN_BUFFER_SIZE;
946 + if (mfmt->fourcc == V4L2_PIX_FMT_YUYV ||
947 + mfmt->fourcc == V4L2_PIX_FMT_UYVY)
948 + f->fmt.pix.colorspace = V4L2_COLORSPACE_SMPTE170M;
950 + f->fmt.pix.colorspace = V4L2_COLORSPACE_SRGB;
951 + f->fmt.pix.priv = 0;
953 + v4l2_dump_pix_format(1, bcm2835_v4l2_debug, &dev->v4l2_dev, &f->fmt.pix,
958 +static int mmal_setup_components(struct bm2835_mmal_dev *dev,
959 + struct v4l2_format *f)
962 + struct vchiq_mmal_port *port = NULL, *camera_port = NULL;
963 + struct vchiq_mmal_component *encode_component = NULL;
964 + struct mmal_fmt *mfmt = get_format(f);
968 + if (dev->capture.encode_component) {
969 + v4l2_dbg(1, bcm2835_v4l2_debug, &dev->v4l2_dev,
970 + "vid_cap - disconnect previous tunnel\n");
972 + /* Disconnect any previous connection */
973 + vchiq_mmal_port_connect_tunnel(dev->instance,
974 + dev->capture.camera_port, NULL);
975 + dev->capture.camera_port = NULL;
976 + ret = vchiq_mmal_component_disable(dev->instance,
980 + v4l2_err(&dev->v4l2_dev,
981 + "Failed to disable encode component %d\n",
984 + dev->capture.encode_component = NULL;
986 + /* format dependant port setup */
987 + switch (mfmt->mmal_component) {
988 + case MMAL_COMPONENT_CAMERA:
989 + /* Make a further decision on port based on resolution */
990 + if (f->fmt.pix.width <= MAX_VIDEO_MODE_WIDTH
991 + && f->fmt.pix.height <= MAX_VIDEO_MODE_HEIGHT)
992 + camera_port = port =
993 + &dev->component[MMAL_COMPONENT_CAMERA]->
994 + output[MMAL_CAMERA_PORT_VIDEO];
996 + camera_port = port =
997 + &dev->component[MMAL_COMPONENT_CAMERA]->
998 + output[MMAL_CAMERA_PORT_CAPTURE];
1000 + case MMAL_COMPONENT_IMAGE_ENCODE:
1001 + encode_component = dev->component[MMAL_COMPONENT_IMAGE_ENCODE];
1002 + port = &dev->component[MMAL_COMPONENT_IMAGE_ENCODE]->output[0];
1004 + &dev->component[MMAL_COMPONENT_CAMERA]->
1005 + output[MMAL_CAMERA_PORT_CAPTURE];
1007 + case MMAL_COMPONENT_VIDEO_ENCODE:
1008 + encode_component = dev->component[MMAL_COMPONENT_VIDEO_ENCODE];
1009 + port = &dev->component[MMAL_COMPONENT_VIDEO_ENCODE]->output[0];
1011 + &dev->component[MMAL_COMPONENT_CAMERA]->
1012 + output[MMAL_CAMERA_PORT_VIDEO];
1021 + if (encode_component)
1022 + camera_port->format.encoding = MMAL_ENCODING_OPAQUE;
1024 + camera_port->format.encoding = mfmt->mmal;
1026 + camera_port->format.encoding_variant = 0;
1027 + camera_port->es.video.width = f->fmt.pix.width;
1028 + camera_port->es.video.height = f->fmt.pix.height;
1029 + camera_port->es.video.crop.x = 0;
1030 + camera_port->es.video.crop.y = 0;
1031 + camera_port->es.video.crop.width = f->fmt.pix.width;
1032 + camera_port->es.video.crop.height = f->fmt.pix.height;
1033 + camera_port->es.video.frame_rate.num = 30;
1034 + camera_port->es.video.frame_rate.den = 1;
1036 + ret = vchiq_mmal_port_set_format(dev->instance, camera_port);
1040 + &dev->component[MMAL_COMPONENT_CAMERA]->
1041 + output[MMAL_CAMERA_PORT_VIDEO]) {
1042 + bool overlay_enabled =
1043 + !!dev->component[MMAL_COMPONENT_PREVIEW]->enabled;
1044 + struct vchiq_mmal_port *preview_port =
1045 + &dev->component[MMAL_COMPONENT_CAMERA]->
1046 + output[MMAL_CAMERA_PORT_PREVIEW];
1047 + /* Preview and encode ports need to match on resolution */
1048 + if (overlay_enabled) {
1049 + /* Need to disable the overlay before we can update
1053 + vchiq_mmal_port_disable(dev->instance,
1057 + vchiq_mmal_port_connect_tunnel(
1062 + preview_port->es.video.width = f->fmt.pix.width;
1063 + preview_port->es.video.height = f->fmt.pix.height;
1064 + preview_port->es.video.crop.x = 0;
1065 + preview_port->es.video.crop.y = 0;
1066 + preview_port->es.video.crop.width = f->fmt.pix.width;
1067 + preview_port->es.video.crop.height = f->fmt.pix.height;
1068 + preview_port->es.video.frame_rate.num = 30;
1069 + preview_port->es.video.frame_rate.den = 1;
1070 + ret = vchiq_mmal_port_set_format(dev->instance, preview_port);
1071 + if (overlay_enabled) {
1072 + ret = vchiq_mmal_port_connect_tunnel(
1075 + &dev->component[MMAL_COMPONENT_PREVIEW]->input[0]);
1077 + ret = vchiq_mmal_port_enable(dev->instance,
1084 + v4l2_dbg(1, bcm2835_v4l2_debug, &dev->v4l2_dev,
1085 + "%s failed to set format\n", __func__);
1086 + /* ensure capture is not going to be tried */
1087 + dev->capture.port = NULL;
1089 + if (encode_component) {
1090 + v4l2_dbg(1, bcm2835_v4l2_debug, &dev->v4l2_dev,
1091 + "vid_cap - set up encode comp\n");
1093 + /* configure buffering */
1094 + camera_port->current_buffer.size =
1095 + camera_port->recommended_buffer.size;
1096 + camera_port->current_buffer.num =
1097 + camera_port->recommended_buffer.num;
1099 + port->format.encoding = mfmt->mmal;
1100 + port->format.encoding_variant = 0;
1101 + /* Set any encoding specific parameters */
1102 + switch (mfmt->mmal_component) {
1103 + case MMAL_COMPONENT_VIDEO_ENCODE:
1104 + port->format.bitrate =
1105 + dev->capture.encode_bitrate;
1107 + case MMAL_COMPONENT_IMAGE_ENCODE:
1108 + /* Could set EXIF parameters here */
1113 + ret = vchiq_mmal_port_set_format(dev->instance, port);
1116 + v4l2_dbg(1, bcm2835_v4l2_debug, &dev->v4l2_dev,
1117 + "%s failed to set format\n", __func__);
1119 + ret = vchiq_mmal_component_enable(
1121 + encode_component);
1123 + v4l2_dbg(1, bcm2835_v4l2_debug,
1125 + "%s Failed to enable encode components\n",
1128 + /* configure buffering */
1129 + port->current_buffer.num = 1;
1130 + port->current_buffer.size =
1131 + f->fmt.pix.sizeimage;
1132 + if (port->format.encoding ==
1133 + MMAL_ENCODING_JPEG) {
1134 + v4l2_dbg(1, bcm2835_v4l2_debug,
1136 + "JPEG - fiddle buffer size\n");
1137 + port->current_buffer.size =
1138 + (f->fmt.pix.sizeimage <
1140 + ? (100 << 10) : f->fmt.pix.
1143 + v4l2_dbg(1, bcm2835_v4l2_debug,
1145 + "vid_cap - current_buffer.size being set to %d\n",
1146 + f->fmt.pix.sizeimage);
1147 + port->current_buffer.alignment = 0;
1149 + vchiq_mmal_port_connect_tunnel(
1152 + &encode_component->input[0]);
1154 + v4l2_dbg(1, bcm2835_v4l2_debug,
1156 + "%s failed to create connection\n",
1158 + /* ensure capture is not going to be tried */
1159 + dev->capture.port = NULL;
1164 + /* configure buffering */
1165 + camera_port->current_buffer.num = 1;
1166 + camera_port->current_buffer.size = f->fmt.pix.sizeimage;
1167 + camera_port->current_buffer.alignment = 0;
1171 + dev->capture.fmt = mfmt;
1172 + dev->capture.stride = f->fmt.pix.bytesperline;
1173 + dev->capture.width = port->es.video.crop.width;
1174 + dev->capture.height = port->es.video.crop.height;
1176 + /* select port for capture */
1177 + dev->capture.port = port;
1178 + dev->capture.camera_port = camera_port;
1179 + dev->capture.encode_component = encode_component;
1183 + /* todo: Need to convert the vchiq/mmal error into a v4l2 error. */
1187 +static int vidioc_s_fmt_vid_cap(struct file *file, void *priv,
1188 + struct v4l2_format *f)
1191 + struct bm2835_mmal_dev *dev = video_drvdata(file);
1192 + struct mmal_fmt *mfmt;
1194 + /* try the format to set valid parameters */
1195 + ret = vidioc_try_fmt_vid_cap(file, priv, f);
1197 + v4l2_err(&dev->v4l2_dev,
1198 + "vid_cap - vidioc_try_fmt_vid_cap failed\n");
1202 + /* if a capture is running refuse to set format */
1203 + if (vb2_is_busy(&dev->capture.vb_vidq)) {
1204 + v4l2_info(&dev->v4l2_dev, "%s device busy\n", __func__);
1208 + /* If the format is unsupported v4l2 says we should switch to
1209 + * a supported one and not return an error. */
1210 + mfmt = get_format(f);
1212 + v4l2_dbg(1, bcm2835_v4l2_debug, &dev->v4l2_dev,
1213 + "Fourcc format (0x%08x) unknown.\n",
1214 + f->fmt.pix.pixelformat);
1215 + f->fmt.pix.pixelformat = formats[0].fourcc;
1216 + mfmt = get_format(f);
1219 + ret = mmal_setup_components(dev, f);
1221 + v4l2_err(&dev->v4l2_dev,
1222 + "%s: failed to setup mmal components: %d\n",
1228 +static const struct v4l2_ioctl_ops camera0_ioctl_ops = {
1230 + .vidioc_enum_fmt_vid_overlay = vidioc_enum_fmt_vid_overlay,
1231 + .vidioc_g_fmt_vid_overlay = vidioc_g_fmt_vid_overlay,
1232 + .vidioc_try_fmt_vid_overlay = vidioc_try_fmt_vid_overlay,
1233 + .vidioc_s_fmt_vid_overlay = vidioc_s_fmt_vid_overlay,
1234 + .vidioc_overlay = vidioc_overlay,
1235 + .vidioc_g_fbuf = vidioc_g_fbuf,
1238 + .vidioc_enum_input = vidioc_enum_input,
1239 + .vidioc_g_input = vidioc_g_input,
1240 + .vidioc_s_input = vidioc_s_input,
1243 + .vidioc_querycap = vidioc_querycap,
1244 + .vidioc_enum_fmt_vid_cap = vidioc_enum_fmt_vid_cap,
1245 + .vidioc_g_fmt_vid_cap = vidioc_g_fmt_vid_cap,
1246 + .vidioc_try_fmt_vid_cap = vidioc_try_fmt_vid_cap,
1247 + .vidioc_s_fmt_vid_cap = vidioc_s_fmt_vid_cap,
1249 + /* buffer management */
1250 + .vidioc_reqbufs = vb2_ioctl_reqbufs,
1251 + .vidioc_create_bufs = vb2_ioctl_create_bufs,
1252 + .vidioc_prepare_buf = vb2_ioctl_prepare_buf,
1253 + .vidioc_querybuf = vb2_ioctl_querybuf,
1254 + .vidioc_qbuf = vb2_ioctl_qbuf,
1255 + .vidioc_dqbuf = vb2_ioctl_dqbuf,
1256 + .vidioc_streamon = vb2_ioctl_streamon,
1257 + .vidioc_streamoff = vb2_ioctl_streamoff,
1259 + .vidioc_log_status = v4l2_ctrl_log_status,
1260 + .vidioc_subscribe_event = v4l2_ctrl_subscribe_event,
1261 + .vidioc_unsubscribe_event = v4l2_event_unsubscribe,
1264 +/* ------------------------------------------------------------------
1265 + Driver init/finalise
1266 + ------------------------------------------------------------------*/
1268 +static const struct v4l2_file_operations camera0_fops = {
1269 + .owner = THIS_MODULE,
1270 + .open = v4l2_fh_open,
1271 + .release = vb2_fop_release,
1272 + .read = vb2_fop_read,
1273 + .poll = vb2_fop_poll,
1274 + .unlocked_ioctl = video_ioctl2, /* V4L2 ioctl handler */
1275 + .mmap = vb2_fop_mmap,
1278 +static struct video_device vdev_template = {
1279 + .name = "camera0",
1280 + .fops = &camera0_fops,
1281 + .ioctl_ops = &camera0_ioctl_ops,
1282 + .release = video_device_release_empty,
1285 +static int set_camera_parameters(struct vchiq_mmal_instance *instance,
1286 + struct vchiq_mmal_component *camera)
1289 + struct mmal_parameter_camera_config cam_config = {
1290 + .max_stills_w = MAX_WIDTH,
1291 + .max_stills_h = MAX_HEIGHT,
1292 + .stills_yuv422 = 1,
1293 + .one_shot_stills = 1,
1294 + .max_preview_video_w = 1920,
1295 + .max_preview_video_h = 1088,
1296 + .num_preview_video_frames = 3,
1297 + .stills_capture_circular_buffer_height = 0,
1298 + .fast_preview_resume = 0,
1299 + .use_stc_timestamp = MMAL_PARAM_TIMESTAMP_MODE_RAW_STC
1302 + ret = vchiq_mmal_port_parameter_set(instance, &camera->control,
1303 + MMAL_PARAMETER_CAMERA_CONFIG,
1304 + &cam_config, sizeof(cam_config));
1308 +/* MMAL instance and component init */
1309 +static int __init mmal_init(struct bm2835_mmal_dev *dev)
1312 + struct mmal_es_format *format;
1314 + ret = vchiq_mmal_init(&dev->instance);
1318 + /* get the camera component ready */
1319 + ret = vchiq_mmal_component_init(dev->instance, "ril.camera",
1320 + &dev->component[MMAL_COMPONENT_CAMERA]);
1324 + if (dev->component[MMAL_COMPONENT_CAMERA]->outputs <
1325 + MMAL_CAMERA_PORT_COUNT) {
1327 + goto unreg_camera;
1330 + ret = set_camera_parameters(dev->instance,
1331 + dev->component[MMAL_COMPONENT_CAMERA]);
1333 + goto unreg_camera;
1336 + &dev->component[MMAL_COMPONENT_CAMERA]->
1337 + output[MMAL_CAMERA_PORT_PREVIEW].format;
1339 + format->encoding = MMAL_ENCODING_OPAQUE;
1340 + format->encoding_variant = MMAL_ENCODING_I420;
1342 + format->es->video.width = 1024;
1343 + format->es->video.height = 768;
1344 + format->es->video.crop.x = 0;
1345 + format->es->video.crop.y = 0;
1346 + format->es->video.crop.width = 1024;
1347 + format->es->video.crop.height = 768;
1348 + format->es->video.frame_rate.num = PREVIEW_FRAME_RATE_NUM;
1349 + format->es->video.frame_rate.den = PREVIEW_FRAME_RATE_DEN;
1352 + &dev->component[MMAL_COMPONENT_CAMERA]->
1353 + output[MMAL_CAMERA_PORT_VIDEO].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_CAPTURE].format;
1371 + format->encoding = MMAL_ENCODING_OPAQUE;
1373 + format->es->video.width = 2592;
1374 + format->es->video.height = 1944;
1375 + format->es->video.crop.x = 0;
1376 + format->es->video.crop.y = 0;
1377 + format->es->video.crop.width = 2592;
1378 + format->es->video.crop.height = 1944;
1379 + format->es->video.frame_rate.num = 30;
1380 + format->es->video.frame_rate.den = 1;
1382 + dev->capture.width = format->es->video.width;
1383 + dev->capture.height = format->es->video.height;
1384 + dev->capture.fmt = &formats[0];
1385 + dev->capture.encode_component = NULL;
1387 + /* get the preview component ready */
1388 + ret = vchiq_mmal_component_init(
1389 + dev->instance, "ril.video_render",
1390 + &dev->component[MMAL_COMPONENT_PREVIEW]);
1392 + goto unreg_camera;
1394 + if (dev->component[MMAL_COMPONENT_PREVIEW]->inputs < 1) {
1396 + pr_debug("too few input ports %d needed %d\n",
1397 + dev->component[MMAL_COMPONENT_PREVIEW]->inputs, 1);
1398 + goto unreg_preview;
1401 + /* get the image encoder component ready */
1402 + ret = vchiq_mmal_component_init(
1403 + dev->instance, "ril.image_encode",
1404 + &dev->component[MMAL_COMPONENT_IMAGE_ENCODE]);
1406 + goto unreg_preview;
1408 + if (dev->component[MMAL_COMPONENT_IMAGE_ENCODE]->inputs < 1) {
1410 + v4l2_err(&dev->v4l2_dev, "too few input ports %d needed %d\n",
1411 + dev->component[MMAL_COMPONENT_IMAGE_ENCODE]->inputs,
1413 + goto unreg_image_encoder;
1416 + /* get the video encoder component ready */
1417 + ret = vchiq_mmal_component_init(dev->instance, "ril.video_encode",
1419 + component[MMAL_COMPONENT_VIDEO_ENCODE]);
1421 + goto unreg_image_encoder;
1423 + if (dev->component[MMAL_COMPONENT_VIDEO_ENCODE]->inputs < 1) {
1425 + v4l2_err(&dev->v4l2_dev, "too few input ports %d needed %d\n",
1426 + dev->component[MMAL_COMPONENT_VIDEO_ENCODE]->inputs,
1428 + goto unreg_vid_encoder;
1432 + unsigned int enable = 1;
1433 + vchiq_mmal_port_parameter_set(
1435 + &dev->component[MMAL_COMPONENT_VIDEO_ENCODE]->control,
1436 + MMAL_PARAMETER_VIDEO_IMMUTABLE_INPUT,
1437 + &enable, sizeof(enable));
1439 + vchiq_mmal_port_parameter_set(dev->instance,
1440 + &dev->component[MMAL_COMPONENT_VIDEO_ENCODE]->control,
1441 + MMAL_PARAMETER_MINIMISE_FRAGMENTATION,
1445 + ret = bm2835_mmal_set_all_camera_controls(dev);
1447 + goto unreg_vid_encoder;
1452 + pr_err("Cleanup: Destroy video encoder\n");
1453 + vchiq_mmal_component_finalise(
1455 + dev->component[MMAL_COMPONENT_VIDEO_ENCODE]);
1457 +unreg_image_encoder:
1458 + pr_err("Cleanup: Destroy image encoder\n");
1459 + vchiq_mmal_component_finalise(
1461 + dev->component[MMAL_COMPONENT_IMAGE_ENCODE]);
1464 + pr_err("Cleanup: Destroy video render\n");
1465 + vchiq_mmal_component_finalise(dev->instance,
1466 + dev->component[MMAL_COMPONENT_PREVIEW]);
1469 + pr_err("Cleanup: Destroy camera\n");
1470 + vchiq_mmal_component_finalise(dev->instance,
1471 + dev->component[MMAL_COMPONENT_CAMERA]);
1474 + vchiq_mmal_finalise(dev->instance);
1478 +static int __init bm2835_mmal_init_device(struct bm2835_mmal_dev *dev,
1479 + struct video_device *vfd)
1483 + *vfd = vdev_template;
1485 + vfd->v4l2_dev = &dev->v4l2_dev;
1487 + vfd->lock = &dev->mutex;
1489 + vfd->queue = &dev->capture.vb_vidq;
1491 + set_bit(V4L2_FL_USE_FH_PRIO, &vfd->flags);
1493 + /* video device needs to be able to access instance data */
1494 + video_set_drvdata(vfd, dev);
1496 + ret = video_register_device(vfd, VFL_TYPE_GRABBER, -1);
1500 + v4l2_info(vfd->v4l2_dev, "V4L2 device registered as %s\n",
1501 + video_device_node_name(vfd));
1506 +static struct v4l2_format default_v4l2_format = {
1507 + .fmt.pix.pixelformat = V4L2_PIX_FMT_JPEG,
1508 + .fmt.pix.width = 1024,
1509 + .fmt.pix.bytesperline = 1024 * 3 / 2,
1510 + .fmt.pix.height = 768,
1511 + .fmt.pix.sizeimage = 1<<18,
1514 +static int __init bm2835_mmal_init(void)
1517 + struct bm2835_mmal_dev *dev;
1518 + struct vb2_queue *q;
1520 + dev = kzalloc(sizeof(*gdev), GFP_KERNEL);
1524 + /* setup device defaults */
1525 + dev->overlay.w.left = 150;
1526 + dev->overlay.w.top = 50;
1527 + dev->overlay.w.width = 1024;
1528 + dev->overlay.w.height = 768;
1529 + dev->overlay.clipcount = 0;
1530 + dev->overlay.field = V4L2_FIELD_NONE;
1532 + dev->capture.fmt = &formats[3]; /* JPEG */
1534 + /* v4l device registration */
1535 + snprintf(dev->v4l2_dev.name, sizeof(dev->v4l2_dev.name),
1536 + "%s", BM2835_MMAL_MODULE_NAME);
1537 + ret = v4l2_device_register(NULL, &dev->v4l2_dev);
1541 + /* setup v4l controls */
1542 + ret = bm2835_mmal_init_controls(dev, &dev->ctrl_handler);
1545 + dev->v4l2_dev.ctrl_handler = &dev->ctrl_handler;
1548 + ret = mmal_init(dev);
1552 + /* initialize queue */
1553 + q = &dev->capture.vb_vidq;
1554 + memset(q, 0, sizeof(*q));
1555 + q->type = V4L2_BUF_TYPE_VIDEO_CAPTURE;
1556 + q->io_modes = VB2_MMAP | VB2_USERPTR | VB2_READ;
1557 + q->drv_priv = dev;
1558 + q->buf_struct_size = sizeof(struct mmal_buffer);
1559 + q->ops = &bm2835_mmal_video_qops;
1560 + q->mem_ops = &vb2_vmalloc_memops;
1561 + q->timestamp_type = V4L2_BUF_FLAG_TIMESTAMP_MONOTONIC;
1562 + ret = vb2_queue_init(q);
1566 + /* v4l2 core mutex used to protect all fops and v4l2 ioctls. */
1567 + mutex_init(&dev->mutex);
1569 + /* initialise video devices */
1570 + ret = bm2835_mmal_init_device(dev, &dev->vdev);
1574 + ret = mmal_setup_components(dev, &default_v4l2_format);
1576 + v4l2_err(&dev->v4l2_dev,
1577 + "%s: could not setup components\n", __func__);
1581 + v4l2_info(&dev->v4l2_dev,
1582 + "Broadcom 2835 MMAL video capture ver %s loaded.\n",
1583 + BM2835_MMAL_VERSION);
1589 + v4l2_ctrl_handler_free(&dev->ctrl_handler);
1590 + v4l2_device_unregister(&dev->v4l2_dev);
1595 + v4l2_err(&dev->v4l2_dev,
1596 + "%s: error %d while loading driver\n",
1597 + BM2835_MMAL_MODULE_NAME, ret);
1602 +static void __exit bm2835_mmal_exit(void)
1607 + v4l2_info(&gdev->v4l2_dev, "unregistering %s\n",
1608 + video_device_node_name(&gdev->vdev));
1610 + video_unregister_device(&gdev->vdev);
1612 + if (gdev->capture.encode_component) {
1613 + v4l2_dbg(1, bcm2835_v4l2_debug, &gdev->v4l2_dev,
1614 + "mmal_exit - disconnect tunnel\n");
1615 + vchiq_mmal_port_connect_tunnel(gdev->instance,
1616 + gdev->capture.camera_port, NULL);
1617 + vchiq_mmal_component_disable(gdev->instance,
1618 + gdev->capture.encode_component);
1620 + vchiq_mmal_component_disable(gdev->instance,
1621 + gdev->component[MMAL_COMPONENT_CAMERA]);
1623 + vchiq_mmal_component_finalise(gdev->instance,
1625 + component[MMAL_COMPONENT_VIDEO_ENCODE]);
1627 + vchiq_mmal_component_finalise(gdev->instance,
1629 + component[MMAL_COMPONENT_IMAGE_ENCODE]);
1631 + vchiq_mmal_component_finalise(gdev->instance,
1632 + gdev->component[MMAL_COMPONENT_PREVIEW]);
1634 + vchiq_mmal_component_finalise(gdev->instance,
1635 + gdev->component[MMAL_COMPONENT_CAMERA]);
1637 + vchiq_mmal_finalise(gdev->instance);
1639 + v4l2_ctrl_handler_free(&gdev->ctrl_handler);
1641 + v4l2_device_unregister(&gdev->v4l2_dev);
1646 +module_init(bm2835_mmal_init);
1647 +module_exit(bm2835_mmal_exit);
1649 +++ b/drivers/media/platform/bcm2835/bcm2835-camera.h
1652 + * Broadcom BM2835 V4L2 driver
1654 + * Copyright © 2013 Raspberry Pi (Trading) Ltd.
1656 + * This file is subject to the terms and conditions of the GNU General Public
1657 + * License. See the file COPYING in the main directory of this archive
1658 + * for more details.
1660 + * Authors: Vincent Sanders <vincent.sanders@collabora.co.uk>
1661 + * Dave Stevenson <dsteve@broadcom.com>
1662 + * Simon Mellor <simellor@broadcom.com>
1663 + * Luke Diamand <luked@broadcom.com>
1665 + * core driver device
1668 +#define V4L2_CTRL_COUNT 18 /* number of v4l controls */
1671 + MMAL_COMPONENT_CAMERA = 0,
1672 + MMAL_COMPONENT_PREVIEW,
1673 + MMAL_COMPONENT_IMAGE_ENCODE,
1674 + MMAL_COMPONENT_VIDEO_ENCODE,
1675 + MMAL_COMPONENT_COUNT
1679 + MMAL_CAMERA_PORT_PREVIEW = 0,
1680 + MMAL_CAMERA_PORT_VIDEO,
1681 + MMAL_CAMERA_PORT_CAPTURE,
1682 + MMAL_CAMERA_PORT_COUNT
1685 +#define PREVIEW_FRAME_RATE_NUM 30
1686 +#define PREVIEW_FRAME_RATE_DEN 1
1688 +#define PREVIEW_LAYER 2
1690 +extern int bcm2835_v4l2_debug;
1692 +struct bm2835_mmal_dev {
1693 + /* v4l2 devices */
1694 + struct v4l2_device v4l2_dev;
1695 + struct video_device vdev;
1696 + struct mutex mutex;
1699 + struct v4l2_ctrl_handler ctrl_handler;
1700 + struct v4l2_ctrl *ctrls[V4L2_CTRL_COUNT];
1701 + struct mmal_colourfx colourfx;
1705 + /* allocated mmal instance and components */
1706 + struct vchiq_mmal_instance *instance;
1707 + struct vchiq_mmal_component *component[MMAL_COMPONENT_COUNT];
1708 + int camera_use_count;
1710 + struct v4l2_window overlay;
1713 + unsigned int width; /* width */
1714 + unsigned int height; /* height */
1715 + unsigned int stride; /* stride */
1716 + struct mmal_fmt *fmt;
1718 + /* H264 encode bitrate */
1719 + int encode_bitrate;
1720 + /* H264 bitrate mode. CBR/VBR */
1721 + int encode_bitrate_mode;
1722 + /* JPEG Q-factor */
1725 + struct vb2_queue vb_vidq;
1727 + /* VC start timestamp for streaming */
1728 + s64 vc_start_timestamp;
1729 + /* Kernel start timestamp for streaming */
1730 + struct timeval kernel_start_ts;
1732 + struct vchiq_mmal_port *port; /* port being used for capture */
1733 + /* camera port being used for capture */
1734 + struct vchiq_mmal_port *camera_port;
1735 + /* component being used for encode */
1736 + struct vchiq_mmal_component *encode_component;
1737 + /* number of frames remaining which driver should capture */
1738 + unsigned int frame_count;
1739 + /* last frame completion */
1740 + struct completion frame_cmplt;
1746 +int bm2835_mmal_init_controls(
1747 + struct bm2835_mmal_dev *dev,
1748 + struct v4l2_ctrl_handler *hdl);
1750 +int bm2835_mmal_set_all_camera_controls(struct bm2835_mmal_dev *dev);
1753 +/* Debug helpers */
1755 +#define v4l2_dump_pix_format(level, debug, dev, pix_fmt, desc) \
1757 + v4l2_dbg(level, debug, dev, \
1758 +"%s: w %u h %u field %u pfmt 0x%x bpl %u sz_img %u colorspace 0x%x priv %u\n", \
1759 + desc == NULL ? "" : desc, \
1760 + (pix_fmt)->width, (pix_fmt)->height, (pix_fmt)->field, \
1761 + (pix_fmt)->pixelformat, (pix_fmt)->bytesperline, \
1762 + (pix_fmt)->sizeimage, (pix_fmt)->colorspace, (pix_fmt)->priv); \
1765 +++ b/drivers/media/platform/bcm2835/controls.c
1768 + * Broadcom BM2835 V4L2 driver
1770 + * Copyright © 2013 Raspberry Pi (Trading) Ltd.
1772 + * This file is subject to the terms and conditions of the GNU General Public
1773 + * License. See the file COPYING in the main directory of this archive
1774 + * for more details.
1776 + * Authors: Vincent Sanders <vincent.sanders@collabora.co.uk>
1777 + * Dave Stevenson <dsteve@broadcom.com>
1778 + * Simon Mellor <simellor@broadcom.com>
1779 + * Luke Diamand <luked@broadcom.com>
1782 +#include <linux/errno.h>
1783 +#include <linux/kernel.h>
1784 +#include <linux/module.h>
1785 +#include <linux/slab.h>
1786 +#include <media/videobuf2-vmalloc.h>
1787 +#include <media/v4l2-device.h>
1788 +#include <media/v4l2-ioctl.h>
1789 +#include <media/v4l2-ctrls.h>
1790 +#include <media/v4l2-fh.h>
1791 +#include <media/v4l2-event.h>
1792 +#include <media/v4l2-common.h>
1794 +#include "mmal-common.h"
1795 +#include "mmal-vchiq.h"
1796 +#include "mmal-parameters.h"
1797 +#include "bcm2835-camera.h"
1799 +/* The supported V4L2_CID_AUTO_EXPOSURE_BIAS values are from -24 to +24.
1800 + * These are in 1/6th increments so the effective range is -4.0EV to +4.0EV.
1802 +static const s64 ev_bias_qmenu[] = {
1803 + -24, -21, -18, -15, -12, -9, -6, -3, 0, 3, 6, 9, 12, 15, 18, 21, 24
1806 +/* Supported ISO values
1809 +static const s64 iso_qmenu[] = {
1810 + 0, 100, 200, 400, 800,
1813 +/* Supported video encode modes */
1814 +static const s64 bitrate_mode_qmenu[] = {
1815 + (s64)V4L2_MPEG_VIDEO_BITRATE_MODE_VBR,
1816 + (s64)V4L2_MPEG_VIDEO_BITRATE_MODE_CBR,
1820 +enum bm2835_mmal_ctrl_type {
1821 + MMAL_CONTROL_TYPE_STD,
1822 + MMAL_CONTROL_TYPE_STD_MENU,
1823 + MMAL_CONTROL_TYPE_INT_MENU,
1824 + MMAL_CONTROL_TYPE_CLUSTER, /* special cluster entry */
1827 +struct bm2835_mmal_v4l2_ctrl;
1829 +typedef int(bm2835_mmal_v4l2_ctrl_cb)(
1830 + struct bm2835_mmal_dev *dev,
1831 + struct v4l2_ctrl *ctrl,
1832 + const struct bm2835_mmal_v4l2_ctrl *mmal_ctrl);
1834 +struct bm2835_mmal_v4l2_ctrl {
1835 + u32 id; /* v4l2 control identifier */
1836 + enum bm2835_mmal_ctrl_type type;
1837 + /* control minimum value or
1838 + * mask for MMAL_CONTROL_TYPE_STD_MENU */
1840 + s32 max; /* maximum value of control */
1841 + s32 def; /* default value of control */
1842 + s32 step; /* step size of the control */
1843 + const s64 *imenu; /* integer menu array */
1844 + u32 mmal_id; /* mmal parameter id */
1845 + bm2835_mmal_v4l2_ctrl_cb *setter;
1848 +struct v4l2_to_mmal_effects_setting {
1851 + s32 col_fx_enable;
1852 + s32 col_fx_fixed_cbcr;
1855 + u32 num_effect_params;
1856 + u32 effect_params[MMAL_MAX_IMAGEFX_PARAMETERS];
1859 +static const struct v4l2_to_mmal_effects_setting
1860 + v4l2_to_mmal_effects_values[] = {
1861 + { V4L2_COLORFX_NONE, MMAL_PARAM_IMAGEFX_NONE,
1862 + 0, 0, 0, 0, 0, {0, 0, 0, 0, 0} },
1863 + { V4L2_COLORFX_BW, MMAL_PARAM_IMAGEFX_NONE,
1864 + 1, 0, 128, 128, 0, {0, 0, 0, 0, 0} },
1865 + { V4L2_COLORFX_SEPIA, MMAL_PARAM_IMAGEFX_NONE,
1866 + 1, 0, 87, 151, 0, {0, 0, 0, 0, 0} },
1867 + { V4L2_COLORFX_NEGATIVE, MMAL_PARAM_IMAGEFX_NEGATIVE,
1868 + 0, 0, 0, 0, 0, {0, 0, 0, 0, 0} },
1869 + { V4L2_COLORFX_EMBOSS, MMAL_PARAM_IMAGEFX_EMBOSS,
1870 + 0, 0, 0, 0, 0, {0, 0, 0, 0, 0} },
1871 + { V4L2_COLORFX_SKETCH, MMAL_PARAM_IMAGEFX_SKETCH,
1872 + 0, 0, 0, 0, 0, {0, 0, 0, 0, 0} },
1873 + { V4L2_COLORFX_SKY_BLUE, MMAL_PARAM_IMAGEFX_PASTEL,
1874 + 0, 0, 0, 0, 0, {0, 0, 0, 0, 0} },
1875 + { V4L2_COLORFX_GRASS_GREEN, MMAL_PARAM_IMAGEFX_WATERCOLOUR,
1876 + 0, 0, 0, 0, 0, {0, 0, 0, 0, 0} },
1877 + { V4L2_COLORFX_SKIN_WHITEN, MMAL_PARAM_IMAGEFX_WASHEDOUT,
1878 + 0, 0, 0, 0, 0, {0, 0, 0, 0, 0} },
1879 + { V4L2_COLORFX_VIVID, MMAL_PARAM_IMAGEFX_SATURATION,
1880 + 0, 0, 0, 0, 0, {0, 0, 0, 0, 0} },
1881 + { V4L2_COLORFX_AQUA, MMAL_PARAM_IMAGEFX_NONE,
1882 + 1, 0, 171, 121, 0, {0, 0, 0, 0, 0} },
1883 + { V4L2_COLORFX_ART_FREEZE, MMAL_PARAM_IMAGEFX_HATCH,
1884 + 0, 0, 0, 0, 0, {0, 0, 0, 0, 0} },
1885 + { V4L2_COLORFX_SILHOUETTE, MMAL_PARAM_IMAGEFX_FILM,
1886 + 0, 0, 0, 0, 0, {0, 0, 0, 0, 0} },
1887 + { V4L2_COLORFX_SOLARIZATION, MMAL_PARAM_IMAGEFX_SOLARIZE,
1888 + 0, 0, 0, 0, 5, {1, 128, 160, 160, 48} },
1889 + { V4L2_COLORFX_ANTIQUE, MMAL_PARAM_IMAGEFX_COLOURBALANCE,
1890 + 0, 0, 0, 0, 3, {108, 274, 238, 0, 0} },
1891 + { V4L2_COLORFX_SET_CBCR, MMAL_PARAM_IMAGEFX_NONE,
1892 + 1, 1, 0, 0, 0, {0, 0, 0, 0, 0} }
1896 +/* control handlers*/
1898 +static int ctrl_set_rational(struct bm2835_mmal_dev *dev,
1899 + struct v4l2_ctrl *ctrl,
1900 + const struct bm2835_mmal_v4l2_ctrl *mmal_ctrl)
1903 + s32 num; /**< Numerator */
1904 + s32 den; /**< Denominator */
1906 + struct vchiq_mmal_port *control;
1908 + control = &dev->component[MMAL_COMPONENT_CAMERA]->control;
1910 + rational_value.num = ctrl->val;
1911 + rational_value.den = 100;
1913 + return vchiq_mmal_port_parameter_set(dev->instance, control,
1914 + mmal_ctrl->mmal_id,
1916 + sizeof(rational_value));
1919 +static int ctrl_set_value(struct bm2835_mmal_dev *dev,
1920 + struct v4l2_ctrl *ctrl,
1921 + const struct bm2835_mmal_v4l2_ctrl *mmal_ctrl)
1924 + struct vchiq_mmal_port *control;
1926 + control = &dev->component[MMAL_COMPONENT_CAMERA]->control;
1928 + u32_value = ctrl->val;
1930 + return vchiq_mmal_port_parameter_set(dev->instance, control,
1931 + mmal_ctrl->mmal_id,
1932 + &u32_value, sizeof(u32_value));
1935 +static int ctrl_set_rotate(struct bm2835_mmal_dev *dev,
1936 + struct v4l2_ctrl *ctrl,
1937 + const struct bm2835_mmal_v4l2_ctrl *mmal_ctrl)
1941 + struct vchiq_mmal_component *camera;
1943 + camera = dev->component[MMAL_COMPONENT_CAMERA];
1945 + u32_value = ((ctrl->val % 360) / 90) * 90;
1947 + ret = vchiq_mmal_port_parameter_set(dev->instance, &camera->output[0],
1948 + mmal_ctrl->mmal_id,
1949 + &u32_value, sizeof(u32_value));
1953 + ret = vchiq_mmal_port_parameter_set(dev->instance, &camera->output[1],
1954 + mmal_ctrl->mmal_id,
1955 + &u32_value, sizeof(u32_value));
1959 + ret = vchiq_mmal_port_parameter_set(dev->instance, &camera->output[2],
1960 + mmal_ctrl->mmal_id,
1961 + &u32_value, sizeof(u32_value));
1966 +static int ctrl_set_flip(struct bm2835_mmal_dev *dev,
1967 + struct v4l2_ctrl *ctrl,
1968 + const struct bm2835_mmal_v4l2_ctrl *mmal_ctrl)
1972 + struct vchiq_mmal_component *camera;
1974 + if (ctrl->id == V4L2_CID_HFLIP)
1975 + dev->hflip = ctrl->val;
1977 + dev->vflip = ctrl->val;
1979 + camera = dev->component[MMAL_COMPONENT_CAMERA];
1981 + if (dev->hflip && dev->vflip)
1982 + u32_value = MMAL_PARAM_MIRROR_BOTH;
1983 + else if (dev->hflip)
1984 + u32_value = MMAL_PARAM_MIRROR_HORIZONTAL;
1985 + else if (dev->vflip)
1986 + u32_value = MMAL_PARAM_MIRROR_VERTICAL;
1988 + u32_value = MMAL_PARAM_MIRROR_NONE;
1990 + ret = vchiq_mmal_port_parameter_set(dev->instance, &camera->output[0],
1991 + mmal_ctrl->mmal_id,
1992 + &u32_value, sizeof(u32_value));
1996 + ret = vchiq_mmal_port_parameter_set(dev->instance, &camera->output[1],
1997 + mmal_ctrl->mmal_id,
1998 + &u32_value, sizeof(u32_value));
2002 + ret = vchiq_mmal_port_parameter_set(dev->instance, &camera->output[2],
2003 + mmal_ctrl->mmal_id,
2004 + &u32_value, sizeof(u32_value));
2010 +static int ctrl_set_exposure(struct bm2835_mmal_dev *dev,
2011 + struct v4l2_ctrl *ctrl,
2012 + const struct bm2835_mmal_v4l2_ctrl *mmal_ctrl)
2015 + struct vchiq_mmal_port *control;
2017 + control = &dev->component[MMAL_COMPONENT_CAMERA]->control;
2019 + switch (ctrl->val) {
2020 + case V4L2_EXPOSURE_AUTO:
2021 + u32_value = MMAL_PARAM_EXPOSUREMODE_AUTO;
2024 + case V4L2_EXPOSURE_MANUAL:
2025 + u32_value = MMAL_PARAM_EXPOSUREMODE_OFF;
2028 + case V4L2_EXPOSURE_SHUTTER_PRIORITY:
2029 + u32_value = MMAL_PARAM_EXPOSUREMODE_SPORTS;
2032 + case V4L2_EXPOSURE_APERTURE_PRIORITY:
2033 + u32_value = MMAL_PARAM_EXPOSUREMODE_NIGHT;
2038 + /* todo: what about the other ten modes there are MMAL parameters for */
2039 + return vchiq_mmal_port_parameter_set(dev->instance, control,
2040 + mmal_ctrl->mmal_id,
2041 + &u32_value, sizeof(u32_value));
2044 +static int ctrl_set_metering_mode(struct bm2835_mmal_dev *dev,
2045 + struct v4l2_ctrl *ctrl,
2046 + const struct bm2835_mmal_v4l2_ctrl *mmal_ctrl)
2049 + struct vchiq_mmal_port *control;
2051 + control = &dev->component[MMAL_COMPONENT_CAMERA]->control;
2053 + switch (ctrl->val) {
2054 + case V4L2_EXPOSURE_METERING_AVERAGE:
2055 + u32_value = MMAL_PARAM_EXPOSUREMETERINGMODE_AVERAGE;
2058 + case V4L2_EXPOSURE_METERING_CENTER_WEIGHTED:
2059 + u32_value = MMAL_PARAM_EXPOSUREMETERINGMODE_BACKLIT;
2062 + case V4L2_EXPOSURE_METERING_SPOT:
2063 + u32_value = MMAL_PARAM_EXPOSUREMETERINGMODE_SPOT;
2066 + /* todo matrix weighting not added to Linux API till 3.9
2067 + case V4L2_EXPOSURE_METERING_MATRIX:
2068 + u32_value = MMAL_PARAM_EXPOSUREMETERINGMODE_MATRIX;
2074 + return vchiq_mmal_port_parameter_set(dev->instance, control,
2075 + mmal_ctrl->mmal_id,
2076 + &u32_value, sizeof(u32_value));
2079 +static int ctrl_set_awb_mode(struct bm2835_mmal_dev *dev,
2080 + struct v4l2_ctrl *ctrl,
2081 + const struct bm2835_mmal_v4l2_ctrl *mmal_ctrl)
2084 + struct vchiq_mmal_port *control;
2086 + control = &dev->component[MMAL_COMPONENT_CAMERA]->control;
2088 + switch (ctrl->val) {
2089 + case V4L2_WHITE_BALANCE_MANUAL:
2090 + u32_value = MMAL_PARAM_AWBMODE_OFF;
2093 + case V4L2_WHITE_BALANCE_AUTO:
2094 + u32_value = MMAL_PARAM_AWBMODE_AUTO;
2097 + case V4L2_WHITE_BALANCE_INCANDESCENT:
2098 + u32_value = MMAL_PARAM_AWBMODE_INCANDESCENT;
2101 + case V4L2_WHITE_BALANCE_FLUORESCENT:
2102 + u32_value = MMAL_PARAM_AWBMODE_FLUORESCENT;
2105 + case V4L2_WHITE_BALANCE_FLUORESCENT_H:
2106 + u32_value = MMAL_PARAM_AWBMODE_TUNGSTEN;
2109 + case V4L2_WHITE_BALANCE_HORIZON:
2110 + u32_value = MMAL_PARAM_AWBMODE_HORIZON;
2113 + case V4L2_WHITE_BALANCE_DAYLIGHT:
2114 + u32_value = MMAL_PARAM_AWBMODE_SUNLIGHT;
2117 + case V4L2_WHITE_BALANCE_FLASH:
2118 + u32_value = MMAL_PARAM_AWBMODE_FLASH;
2121 + case V4L2_WHITE_BALANCE_CLOUDY:
2122 + u32_value = MMAL_PARAM_AWBMODE_CLOUDY;
2125 + case V4L2_WHITE_BALANCE_SHADE:
2126 + u32_value = MMAL_PARAM_AWBMODE_SHADE;
2131 + return vchiq_mmal_port_parameter_set(dev->instance, control,
2132 + mmal_ctrl->mmal_id,
2133 + &u32_value, sizeof(u32_value));
2136 +static int ctrl_set_image_effect(struct bm2835_mmal_dev *dev,
2137 + struct v4l2_ctrl *ctrl,
2138 + const struct bm2835_mmal_v4l2_ctrl *mmal_ctrl)
2140 + int ret = -EINVAL;
2142 + struct vchiq_mmal_port *control;
2143 + struct mmal_parameter_imagefx_parameters imagefx;
2145 + for (i = 0; i < ARRAY_SIZE(v4l2_to_mmal_effects_values); i++) {
2146 + if (ctrl->val == v4l2_to_mmal_effects_values[i].v4l2_effect) {
2149 + v4l2_to_mmal_effects_values[i].mmal_effect;
2150 + imagefx.num_effect_params =
2151 + v4l2_to_mmal_effects_values[i].num_effect_params;
2153 + if (imagefx.num_effect_params > MMAL_MAX_IMAGEFX_PARAMETERS)
2154 + imagefx.num_effect_params = MMAL_MAX_IMAGEFX_PARAMETERS;
2156 + for (j = 0; j < imagefx.num_effect_params; j++)
2157 + imagefx.effect_parameter[j] =
2158 + v4l2_to_mmal_effects_values[i].effect_params[j];
2160 + dev->colourfx.enable =
2161 + v4l2_to_mmal_effects_values[i].col_fx_enable;
2162 + if (!v4l2_to_mmal_effects_values[i].col_fx_fixed_cbcr) {
2164 + v4l2_to_mmal_effects_values[i].u;
2166 + v4l2_to_mmal_effects_values[i].v;
2169 + control = &dev->component[MMAL_COMPONENT_CAMERA]->control;
2171 + ret = vchiq_mmal_port_parameter_set(
2172 + dev->instance, control,
2173 + MMAL_PARAMETER_IMAGE_EFFECT_PARAMETERS,
2174 + &imagefx, sizeof(imagefx));
2178 + ret = vchiq_mmal_port_parameter_set(
2179 + dev->instance, control,
2180 + MMAL_PARAMETER_COLOUR_EFFECT,
2181 + &dev->colourfx, sizeof(dev->colourfx));
2186 + v4l2_dbg(1, bcm2835_v4l2_debug, &dev->v4l2_dev,
2187 + "mmal_ctrl:%p ctrl id:0x%x ctrl val:%d imagefx:0x%x color_effect:%s u:%d v:%d ret %d(%d)\n",
2188 + mmal_ctrl, ctrl->id, ctrl->val, imagefx.effect,
2189 + dev->colourfx.enable ? "true" : "false",
2190 + dev->colourfx.u, dev->colourfx.v,
2191 + ret, (ret == 0 ? 0 : -EINVAL));
2192 + return (ret == 0 ? 0 : EINVAL);
2195 +static int ctrl_set_colfx(struct bm2835_mmal_dev *dev,
2196 + struct v4l2_ctrl *ctrl,
2197 + const struct bm2835_mmal_v4l2_ctrl *mmal_ctrl)
2199 + int ret = -EINVAL;
2200 + struct vchiq_mmal_port *control;
2202 + control = &dev->component[MMAL_COMPONENT_CAMERA]->control;
2204 + dev->colourfx.enable = (ctrl->val & 0xff00) >> 8;
2205 + dev->colourfx.enable = ctrl->val & 0xff;
2207 + ret = vchiq_mmal_port_parameter_set(dev->instance, control,
2208 + MMAL_PARAMETER_COLOUR_EFFECT,
2209 + &dev->colourfx, sizeof(dev->colourfx));
2211 + v4l2_dbg(1, bcm2835_v4l2_debug, &dev->v4l2_dev,
2212 + "After: mmal_ctrl:%p ctrl id:0x%x ctrl val:%d ret %d(%d)\n",
2213 + mmal_ctrl, ctrl->id, ctrl->val, ret,
2214 + (ret == 0 ? 0 : -EINVAL));
2215 + return (ret == 0 ? 0 : EINVAL);
2218 +static int ctrl_set_bitrate(struct bm2835_mmal_dev *dev,
2219 + struct v4l2_ctrl *ctrl,
2220 + const struct bm2835_mmal_v4l2_ctrl *mmal_ctrl)
2223 + struct vchiq_mmal_port *encoder_out;
2225 + dev->capture.encode_bitrate = ctrl->val;
2227 + encoder_out = &dev->component[MMAL_COMPONENT_VIDEO_ENCODE]->output[0];
2229 + ret = vchiq_mmal_port_parameter_set(dev->instance, encoder_out,
2230 + mmal_ctrl->mmal_id,
2231 + &ctrl->val, sizeof(ctrl->val));
2236 +static int ctrl_set_bitrate_mode(struct bm2835_mmal_dev *dev,
2237 + struct v4l2_ctrl *ctrl,
2238 + const struct bm2835_mmal_v4l2_ctrl *mmal_ctrl)
2241 + struct vchiq_mmal_port *encoder_out;
2243 + encoder_out = &dev->component[MMAL_COMPONENT_VIDEO_ENCODE]->output[0];
2245 + dev->capture.encode_bitrate_mode = ctrl->val;
2246 + switch (ctrl->val) {
2248 + case V4L2_MPEG_VIDEO_BITRATE_MODE_VBR:
2249 + bitrate_mode = MMAL_VIDEO_RATECONTROL_VARIABLE;
2251 + case V4L2_MPEG_VIDEO_BITRATE_MODE_CBR:
2252 + bitrate_mode = MMAL_VIDEO_RATECONTROL_CONSTANT;
2256 + vchiq_mmal_port_parameter_set(dev->instance, encoder_out,
2257 + mmal_ctrl->mmal_id,
2259 + sizeof(bitrate_mode));
2263 +static int ctrl_set_q_factor(struct bm2835_mmal_dev *dev,
2264 + struct v4l2_ctrl *ctrl,
2265 + const struct bm2835_mmal_v4l2_ctrl *mmal_ctrl)
2268 + struct vchiq_mmal_port *jpeg_out;
2270 + jpeg_out = &dev->component[MMAL_COMPONENT_IMAGE_ENCODE]->output[0];
2272 + u32_value = ctrl->val;
2274 + return vchiq_mmal_port_parameter_set(dev->instance, jpeg_out,
2275 + mmal_ctrl->mmal_id,
2276 + &u32_value, sizeof(u32_value));
2279 +static int bm2835_mmal_s_ctrl(struct v4l2_ctrl *ctrl)
2281 + struct bm2835_mmal_dev *dev =
2282 + container_of(ctrl->handler, struct bm2835_mmal_dev,
2284 + const struct bm2835_mmal_v4l2_ctrl *mmal_ctrl = ctrl->priv;
2286 + if ((mmal_ctrl == NULL) ||
2287 + (mmal_ctrl->id != ctrl->id) ||
2288 + (mmal_ctrl->setter == NULL)) {
2289 + pr_warn("mmal_ctrl:%p ctrl id:%d\n", mmal_ctrl, ctrl->id);
2293 + return mmal_ctrl->setter(dev, ctrl, mmal_ctrl);
2296 +static const struct v4l2_ctrl_ops bm2835_mmal_ctrl_ops = {
2297 + .s_ctrl = bm2835_mmal_s_ctrl,
2302 +static const struct bm2835_mmal_v4l2_ctrl v4l2_ctrls[V4L2_CTRL_COUNT] = {
2304 + V4L2_CID_SATURATION, MMAL_CONTROL_TYPE_STD,
2305 + -100, 100, 0, 1, NULL,
2306 + MMAL_PARAMETER_SATURATION, &ctrl_set_rational
2309 + V4L2_CID_SHARPNESS, MMAL_CONTROL_TYPE_STD,
2310 + -100, 100, 0, 1, NULL,
2311 + MMAL_PARAMETER_SHARPNESS, &ctrl_set_rational
2314 + V4L2_CID_CONTRAST, MMAL_CONTROL_TYPE_STD,
2315 + -100, 100, 0, 1, NULL,
2316 + MMAL_PARAMETER_CONTRAST, &ctrl_set_rational
2319 + V4L2_CID_BRIGHTNESS, MMAL_CONTROL_TYPE_STD,
2320 + 0, 100, 50, 1, NULL,
2321 + MMAL_PARAMETER_BRIGHTNESS, &ctrl_set_rational
2324 + V4L2_CID_ISO_SENSITIVITY, MMAL_CONTROL_TYPE_INT_MENU,
2325 + 0, ARRAY_SIZE(iso_qmenu) - 1, 0, 1, iso_qmenu,
2326 + MMAL_PARAMETER_ISO, &ctrl_set_value
2329 + V4L2_CID_IMAGE_STABILIZATION, MMAL_CONTROL_TYPE_STD,
2331 + MMAL_PARAMETER_VIDEO_STABILISATION, &ctrl_set_value
2334 + 0, MMAL_CONTROL_TYPE_CLUSTER, 3, 1, 0, NULL, 0, NULL
2337 + V4L2_CID_EXPOSURE_AUTO, MMAL_CONTROL_TYPE_STD_MENU,
2338 + ~0x03, 3, V4L2_EXPOSURE_AUTO, 0, NULL,
2339 + MMAL_PARAMETER_EXPOSURE_MODE, &ctrl_set_exposure
2341 +/* todo this needs mixing in with set exposure
2343 + V4L2_CID_SCENE_MODE, MMAL_CONTROL_TYPE_STD_MENU,
2347 + V4L2_CID_AUTO_EXPOSURE_BIAS, MMAL_CONTROL_TYPE_INT_MENU,
2348 + 0, ARRAY_SIZE(ev_bias_qmenu) - 1,
2349 + (ARRAY_SIZE(ev_bias_qmenu)+1)/2 - 1, 0, ev_bias_qmenu,
2350 + MMAL_PARAMETER_EXPOSURE_COMP, &ctrl_set_value
2353 + V4L2_CID_EXPOSURE_METERING,
2354 + MMAL_CONTROL_TYPE_STD_MENU,
2355 + ~0x7, 2, V4L2_EXPOSURE_METERING_AVERAGE, 0, NULL,
2356 + MMAL_PARAMETER_EXP_METERING_MODE, &ctrl_set_metering_mode
2359 + V4L2_CID_AUTO_N_PRESET_WHITE_BALANCE,
2360 + MMAL_CONTROL_TYPE_STD_MENU,
2361 + ~0x3fe, 9, V4L2_WHITE_BALANCE_AUTO, 0, NULL,
2362 + MMAL_PARAMETER_AWB_MODE, &ctrl_set_awb_mode
2365 + V4L2_CID_COLORFX, MMAL_CONTROL_TYPE_STD_MENU,
2366 + 0, 15, V4L2_COLORFX_NONE, 0, NULL,
2367 + MMAL_PARAMETER_IMAGE_EFFECT, &ctrl_set_image_effect
2370 + V4L2_CID_COLORFX_CBCR, MMAL_CONTROL_TYPE_STD,
2371 + 0, 0xffff, 0x8080, 1, NULL,
2372 + MMAL_PARAMETER_COLOUR_EFFECT, &ctrl_set_colfx
2375 + V4L2_CID_ROTATE, MMAL_CONTROL_TYPE_STD,
2376 + 0, 360, 0, 90, NULL,
2377 + MMAL_PARAMETER_ROTATION, &ctrl_set_rotate
2380 + V4L2_CID_HFLIP, MMAL_CONTROL_TYPE_STD,
2382 + MMAL_PARAMETER_MIRROR, &ctrl_set_flip
2385 + V4L2_CID_VFLIP, MMAL_CONTROL_TYPE_STD,
2387 + MMAL_PARAMETER_MIRROR, &ctrl_set_flip
2390 + V4L2_CID_MPEG_VIDEO_BITRATE_MODE, MMAL_CONTROL_TYPE_STD_MENU,
2391 + 0, ARRAY_SIZE(bitrate_mode_qmenu) - 1,
2392 + 0, 0, bitrate_mode_qmenu,
2393 + MMAL_PARAMETER_RATECONTROL, &ctrl_set_bitrate_mode
2396 + V4L2_CID_MPEG_VIDEO_BITRATE, MMAL_CONTROL_TYPE_STD,
2397 + 25*1000, 25*1000*1000, 10*1000*1000, 25*1000, NULL,
2398 + MMAL_PARAMETER_VIDEO_BIT_RATE, &ctrl_set_bitrate
2401 + V4L2_CID_JPEG_COMPRESSION_QUALITY, MMAL_CONTROL_TYPE_STD,
2404 + MMAL_PARAMETER_JPEG_Q_FACTOR, &ctrl_set_q_factor
2408 +int bm2835_mmal_set_all_camera_controls(struct bm2835_mmal_dev *dev)
2413 + for (c = 0; c < V4L2_CTRL_COUNT; c++) {
2414 + if ((dev->ctrls[c]) && (v4l2_ctrls[c].setter)) {
2415 + ret = v4l2_ctrls[c].setter(dev, dev->ctrls[c],
2424 +int bm2835_mmal_init_controls(struct bm2835_mmal_dev *dev,
2425 + struct v4l2_ctrl_handler *hdl)
2428 + const struct bm2835_mmal_v4l2_ctrl *ctrl;
2430 + v4l2_ctrl_handler_init(hdl, V4L2_CTRL_COUNT);
2432 + for (c = 0; c < V4L2_CTRL_COUNT; c++) {
2433 + ctrl = &v4l2_ctrls[c];
2435 + switch (ctrl->type) {
2436 + case MMAL_CONTROL_TYPE_STD:
2437 + dev->ctrls[c] = v4l2_ctrl_new_std(hdl,
2438 + &bm2835_mmal_ctrl_ops, ctrl->id,
2439 + ctrl->min, ctrl->max, ctrl->step, ctrl->def);
2442 + case MMAL_CONTROL_TYPE_STD_MENU:
2443 + dev->ctrls[c] = v4l2_ctrl_new_std_menu(hdl,
2444 + &bm2835_mmal_ctrl_ops, ctrl->id,
2445 + ctrl->max, ctrl->min, ctrl->def);
2448 + case MMAL_CONTROL_TYPE_INT_MENU:
2449 + dev->ctrls[c] = v4l2_ctrl_new_int_menu(hdl,
2450 + &bm2835_mmal_ctrl_ops, ctrl->id,
2451 + ctrl->max, ctrl->def, ctrl->imenu);
2454 + case MMAL_CONTROL_TYPE_CLUSTER:
2455 + /* skip this entry when constructing controls */
2462 + dev->ctrls[c]->priv = (void *)ctrl;
2466 + pr_err("error adding control %d/%d id 0x%x\n", c,
2467 + V4L2_CTRL_COUNT, ctrl->id);
2468 + return hdl->error;
2471 + for (c = 0; c < V4L2_CTRL_COUNT; c++) {
2472 + ctrl = &v4l2_ctrls[c];
2474 + switch (ctrl->type) {
2475 + case MMAL_CONTROL_TYPE_CLUSTER:
2476 + v4l2_ctrl_auto_cluster(ctrl->min,
2482 + case MMAL_CONTROL_TYPE_STD:
2483 + case MMAL_CONTROL_TYPE_STD_MENU:
2484 + case MMAL_CONTROL_TYPE_INT_MENU:
2493 +++ b/drivers/media/platform/bcm2835/mmal-common.h
2496 + * Broadcom BM2835 V4L2 driver
2498 + * Copyright © 2013 Raspberry Pi (Trading) Ltd.
2500 + * This file is subject to the terms and conditions of the GNU General Public
2501 + * License. See the file COPYING in the main directory of this archive
2502 + * for more details.
2504 + * Authors: Vincent Sanders <vincent.sanders@collabora.co.uk>
2505 + * Dave Stevenson <dsteve@broadcom.com>
2506 + * Simon Mellor <simellor@broadcom.com>
2507 + * Luke Diamand <luked@broadcom.com>
2513 +#define MMAL_FOURCC(a, b, c, d) ((a) | (b << 8) | (c << 16) | (d << 24))
2514 +#define MMAL_MAGIC MMAL_FOURCC('m', 'm', 'a', 'l')
2516 +/** Special value signalling that time is not known */
2517 +#define MMAL_TIME_UNKNOWN (1LL<<63)
2519 +/* mapping between v4l and mmal video modes */
2522 + u32 fourcc; /* v4l2 format id */
2525 + u32 mmal_component; /* MMAL component index to be used to encode */
2528 +/* buffer for one video frame */
2529 +struct mmal_buffer {
2530 + /* v4l buffer data -- must be first */
2531 + struct vb2_buffer vb;
2533 + /* list of buffers available */
2534 + struct list_head list;
2536 + void *buffer; /* buffer pointer */
2537 + unsigned long buffer_size; /* size of allocated buffer */
2541 +struct mmal_colourfx {
2548 +++ b/drivers/media/platform/bcm2835/mmal-encodings.h
2551 + * Broadcom BM2835 V4L2 driver
2553 + * Copyright © 2013 Raspberry Pi (Trading) Ltd.
2555 + * This file is subject to the terms and conditions of the GNU General Public
2556 + * License. See the file COPYING in the main directory of this archive
2557 + * for more details.
2559 + * Authors: Vincent Sanders <vincent.sanders@collabora.co.uk>
2560 + * Dave Stevenson <dsteve@broadcom.com>
2561 + * Simon Mellor <simellor@broadcom.com>
2562 + * Luke Diamand <luked@broadcom.com>
2565 +#define MMAL_ENCODING_H264 MMAL_FOURCC('H', '2', '6', '4')
2566 +#define MMAL_ENCODING_H263 MMAL_FOURCC('H', '2', '6', '3')
2567 +#define MMAL_ENCODING_MP4V MMAL_FOURCC('M', 'P', '4', 'V')
2568 +#define MMAL_ENCODING_MP2V MMAL_FOURCC('M', 'P', '2', 'V')
2569 +#define MMAL_ENCODING_MP1V MMAL_FOURCC('M', 'P', '1', 'V')
2570 +#define MMAL_ENCODING_WMV3 MMAL_FOURCC('W', 'M', 'V', '3')
2571 +#define MMAL_ENCODING_WMV2 MMAL_FOURCC('W', 'M', 'V', '2')
2572 +#define MMAL_ENCODING_WMV1 MMAL_FOURCC('W', 'M', 'V', '1')
2573 +#define MMAL_ENCODING_WVC1 MMAL_FOURCC('W', 'V', 'C', '1')
2574 +#define MMAL_ENCODING_VP8 MMAL_FOURCC('V', 'P', '8', ' ')
2575 +#define MMAL_ENCODING_VP7 MMAL_FOURCC('V', 'P', '7', ' ')
2576 +#define MMAL_ENCODING_VP6 MMAL_FOURCC('V', 'P', '6', ' ')
2577 +#define MMAL_ENCODING_THEORA MMAL_FOURCC('T', 'H', 'E', 'O')
2578 +#define MMAL_ENCODING_SPARK MMAL_FOURCC('S', 'P', 'R', 'K')
2580 +#define MMAL_ENCODING_JPEG MMAL_FOURCC('J', 'P', 'E', 'G')
2581 +#define MMAL_ENCODING_GIF MMAL_FOURCC('G', 'I', 'F', ' ')
2582 +#define MMAL_ENCODING_PNG MMAL_FOURCC('P', 'N', 'G', ' ')
2583 +#define MMAL_ENCODING_PPM MMAL_FOURCC('P', 'P', 'M', ' ')
2584 +#define MMAL_ENCODING_TGA MMAL_FOURCC('T', 'G', 'A', ' ')
2585 +#define MMAL_ENCODING_BMP MMAL_FOURCC('B', 'M', 'P', ' ')
2587 +#define MMAL_ENCODING_I420 MMAL_FOURCC('I', '4', '2', '0')
2588 +#define MMAL_ENCODING_I420_SLICE MMAL_FOURCC('S', '4', '2', '0')
2589 +#define MMAL_ENCODING_YV12 MMAL_FOURCC('Y', 'V', '1', '2')
2590 +#define MMAL_ENCODING_I422 MMAL_FOURCC('I', '4', '2', '2')
2591 +#define MMAL_ENCODING_I422_SLICE MMAL_FOURCC('S', '4', '2', '2')
2592 +#define MMAL_ENCODING_YUYV MMAL_FOURCC('Y', 'U', 'Y', 'V')
2593 +#define MMAL_ENCODING_YVYU MMAL_FOURCC('Y', 'V', 'Y', 'U')
2594 +#define MMAL_ENCODING_UYVY MMAL_FOURCC('U', 'Y', 'V', 'Y')
2595 +#define MMAL_ENCODING_VYUY MMAL_FOURCC('V', 'Y', 'U', 'Y')
2596 +#define MMAL_ENCODING_NV12 MMAL_FOURCC('N', 'V', '1', '2')
2597 +#define MMAL_ENCODING_NV21 MMAL_FOURCC('N', 'V', '2', '1')
2598 +#define MMAL_ENCODING_ARGB MMAL_FOURCC('A', 'R', 'G', 'B')
2599 +#define MMAL_ENCODING_RGBA MMAL_FOURCC('R', 'G', 'B', 'A')
2600 +#define MMAL_ENCODING_ABGR MMAL_FOURCC('A', 'B', 'G', 'R')
2601 +#define MMAL_ENCODING_BGRA MMAL_FOURCC('B', 'G', 'R', 'A')
2602 +#define MMAL_ENCODING_RGB16 MMAL_FOURCC('R', 'G', 'B', '2')
2603 +#define MMAL_ENCODING_RGB24 MMAL_FOURCC('R', 'G', 'B', '3')
2604 +#define MMAL_ENCODING_RGB32 MMAL_FOURCC('R', 'G', 'B', '4')
2605 +#define MMAL_ENCODING_BGR16 MMAL_FOURCC('B', 'G', 'R', '2')
2606 +#define MMAL_ENCODING_BGR24 MMAL_FOURCC('B', 'G', 'R', '3')
2607 +#define MMAL_ENCODING_BGR32 MMAL_FOURCC('B', 'G', 'R', '4')
2609 +/** SAND Video (YUVUV128) format, native format understood by VideoCore.
2610 + * This format is *not* opaque - if requested you will receive full frames
2611 + * of YUV_UV video.
2613 +#define MMAL_ENCODING_YUVUV128 MMAL_FOURCC('S', 'A', 'N', 'D')
2615 +/** VideoCore opaque image format, image handles are returned to
2616 + * the host but not the actual image data.
2618 +#define MMAL_ENCODING_OPAQUE MMAL_FOURCC('O', 'P', 'Q', 'V')
2620 +/** An EGL image handle
2622 +#define MMAL_ENCODING_EGL_IMAGE MMAL_FOURCC('E', 'G', 'L', 'I')
2626 +/** \name Pre-defined audio encodings */
2628 +#define MMAL_ENCODING_PCM_UNSIGNED_BE MMAL_FOURCC('P', 'C', 'M', 'U')
2629 +#define MMAL_ENCODING_PCM_UNSIGNED_LE MMAL_FOURCC('p', 'c', 'm', 'u')
2630 +#define MMAL_ENCODING_PCM_SIGNED_BE MMAL_FOURCC('P', 'C', 'M', 'S')
2631 +#define MMAL_ENCODING_PCM_SIGNED_LE MMAL_FOURCC('p', 'c', 'm', 's')
2632 +#define MMAL_ENCODING_PCM_FLOAT_BE MMAL_FOURCC('P', 'C', 'M', 'F')
2633 +#define MMAL_ENCODING_PCM_FLOAT_LE MMAL_FOURCC('p', 'c', 'm', 'f')
2635 +/* Pre-defined H264 encoding variants */
2637 +/** ISO 14496-10 Annex B byte stream format */
2638 +#define MMAL_ENCODING_VARIANT_H264_DEFAULT 0
2639 +/** ISO 14496-15 AVC stream format */
2640 +#define MMAL_ENCODING_VARIANT_H264_AVC1 MMAL_FOURCC('A', 'V', 'C', '1')
2641 +/** Implicitly delineated NAL units without emulation prevention */
2642 +#define MMAL_ENCODING_VARIANT_H264_RAW MMAL_FOURCC('R', 'A', 'W', ' ')
2644 +++ b/drivers/media/platform/bcm2835/mmal-msg-common.h
2647 + * Broadcom BM2835 V4L2 driver
2649 + * Copyright © 2013 Raspberry Pi (Trading) Ltd.
2651 + * This file is subject to the terms and conditions of the GNU General Public
2652 + * License. See the file COPYING in the main directory of this archive
2653 + * for more details.
2655 + * Authors: Vincent Sanders <vincent.sanders@collabora.co.uk>
2656 + * Dave Stevenson <dsteve@broadcom.com>
2657 + * Simon Mellor <simellor@broadcom.com>
2658 + * Luke Diamand <luked@broadcom.com>
2661 +#ifndef MMAL_MSG_COMMON_H
2662 +#define MMAL_MSG_COMMON_H
2664 +enum mmal_msg_status {
2665 + MMAL_MSG_STATUS_SUCCESS = 0, /**< Success */
2666 + MMAL_MSG_STATUS_ENOMEM, /**< Out of memory */
2667 + MMAL_MSG_STATUS_ENOSPC, /**< Out of resources other than memory */
2668 + MMAL_MSG_STATUS_EINVAL, /**< Argument is invalid */
2669 + MMAL_MSG_STATUS_ENOSYS, /**< Function not implemented */
2670 + MMAL_MSG_STATUS_ENOENT, /**< No such file or directory */
2671 + MMAL_MSG_STATUS_ENXIO, /**< No such device or address */
2672 + MMAL_MSG_STATUS_EIO, /**< I/O error */
2673 + MMAL_MSG_STATUS_ESPIPE, /**< Illegal seek */
2674 + MMAL_MSG_STATUS_ECORRUPT, /**< Data is corrupt \attention */
2675 + MMAL_MSG_STATUS_ENOTREADY, /**< Component is not ready */
2676 + MMAL_MSG_STATUS_ECONFIG, /**< Component is not configured */
2677 + MMAL_MSG_STATUS_EISCONN, /**< Port is already connected */
2678 + MMAL_MSG_STATUS_ENOTCONN, /**< Port is disconnected */
2679 + MMAL_MSG_STATUS_EAGAIN, /**< Resource temporarily unavailable. */
2680 + MMAL_MSG_STATUS_EFAULT, /**< Bad address */
2684 + s32 x; /**< x coordinate (from left) */
2685 + s32 y; /**< y coordinate (from top) */
2686 + s32 width; /**< width */
2687 + s32 height; /**< height */
2690 +struct mmal_rational {
2691 + s32 num; /**< Numerator */
2692 + s32 den; /**< Denominator */
2695 +#endif /* MMAL_MSG_COMMON_H */
2697 +++ b/drivers/media/platform/bcm2835/mmal-msg-format.h
2700 + * Broadcom BM2835 V4L2 driver
2702 + * Copyright © 2013 Raspberry Pi (Trading) Ltd.
2704 + * This file is subject to the terms and conditions of the GNU General Public
2705 + * License. See the file COPYING in the main directory of this archive
2706 + * for more details.
2708 + * Authors: Vincent Sanders <vincent.sanders@collabora.co.uk>
2709 + * Dave Stevenson <dsteve@broadcom.com>
2710 + * Simon Mellor <simellor@broadcom.com>
2711 + * Luke Diamand <luked@broadcom.com>
2714 +#ifndef MMAL_MSG_FORMAT_H
2715 +#define MMAL_MSG_FORMAT_H
2717 +#include "mmal-msg-common.h"
2719 +/* MMAL_ES_FORMAT_T */
2722 +struct mmal_audio_format {
2723 + u32 channels; /**< Number of audio channels */
2724 + u32 sample_rate; /**< Sample rate */
2726 + u32 bits_per_sample; /**< Bits per sample */
2727 + u32 block_align; /**< Size of a block of data */
2730 +struct mmal_video_format {
2731 + u32 width; /**< Width of frame in pixels */
2732 + u32 height; /**< Height of frame in rows of pixels */
2733 + struct mmal_rect crop; /**< Visible region of the frame */
2734 + struct mmal_rational frame_rate; /**< Frame rate */
2735 + struct mmal_rational par; /**< Pixel aspect ratio */
2737 + /* FourCC specifying the color space of the video stream. See the
2738 + * \ref MmalColorSpace "pre-defined color spaces" for some examples.
2743 +struct mmal_subpicture_format {
2748 +union mmal_es_specific_format {
2749 + struct mmal_audio_format audio;
2750 + struct mmal_video_format video;
2751 + struct mmal_subpicture_format subpicture;
2754 +/** Definition of an elementary stream format (MMAL_ES_FORMAT_T) */
2755 +struct mmal_es_format {
2756 + u32 type; /* enum mmal_es_type */
2758 + u32 encoding; /* FourCC specifying encoding of the elementary stream.*/
2759 + u32 encoding_variant; /* FourCC specifying the specific
2760 + * encoding variant of the elementary
2764 + union mmal_es_specific_format *es; /* TODO: pointers in
2765 + * message serialisation?!?
2768 + * information for the
2769 + * elementary stream
2772 + u32 bitrate; /**< Bitrate in bits per second */
2773 + u32 flags; /**< Flags describing properties of the elementary stream. */
2775 + u32 extradata_size; /**< Size of the codec specific data */
2776 + u8 *extradata; /**< Codec specific data */
2779 +#endif /* MMAL_MSG_FORMAT_H */
2781 +++ b/drivers/media/platform/bcm2835/mmal-msg-port.h
2784 + * Broadcom BM2835 V4L2 driver
2786 + * Copyright © 2013 Raspberry Pi (Trading) Ltd.
2788 + * This file is subject to the terms and conditions of the GNU General Public
2789 + * License. See the file COPYING in the main directory of this archive
2790 + * for more details.
2792 + * Authors: Vincent Sanders <vincent.sanders@collabora.co.uk>
2793 + * Dave Stevenson <dsteve@broadcom.com>
2794 + * Simon Mellor <simellor@broadcom.com>
2795 + * Luke Diamand <luked@broadcom.com>
2798 +/* MMAL_PORT_TYPE_T */
2799 +enum mmal_port_type {
2800 + MMAL_PORT_TYPE_UNKNOWN = 0, /**< Unknown port type */
2801 + MMAL_PORT_TYPE_CONTROL, /**< Control port */
2802 + MMAL_PORT_TYPE_INPUT, /**< Input port */
2803 + MMAL_PORT_TYPE_OUTPUT, /**< Output port */
2804 + MMAL_PORT_TYPE_CLOCK, /**< Clock port */
2807 +/** The port is pass-through and doesn't need buffer headers allocated */
2808 +#define MMAL_PORT_CAPABILITY_PASSTHROUGH 0x01
2809 +/** The port wants to allocate the buffer payloads.
2810 + * This signals a preference that payload allocation should be done
2811 + * on this port for efficiency reasons. */
2812 +#define MMAL_PORT_CAPABILITY_ALLOCATION 0x02
2813 +/** The port supports format change events.
2814 + * This applies to input ports and is used to let the client know
2815 + * whether the port supports being reconfigured via a format
2816 + * change event (i.e. without having to disable the port). */
2817 +#define MMAL_PORT_CAPABILITY_SUPPORTS_EVENT_FORMAT_CHANGE 0x04
2819 +/* mmal port structure (MMAL_PORT_T)
2821 + * most elements are informational only, the pointer values for
2822 + * interogation messages are generally provided as additional
2823 + * strucures within the message. When used to set values only teh
2824 + * buffer_num, buffer_size and userdata parameters are writable.
2827 + void *priv; /* Private member used by the framework */
2828 + const char *name; /* Port name. Used for debugging purposes (RO) */
2830 + u32 type; /* Type of the port (RO) enum mmal_port_type */
2831 + u16 index; /* Index of the port in its type list (RO) */
2832 + u16 index_all; /* Index of the port in the list of all ports (RO) */
2834 + u32 is_enabled; /* Indicates whether the port is enabled or not (RO) */
2835 + struct mmal_es_format *format; /* Format of the elementary stream */
2837 + u32 buffer_num_min; /* Minimum number of buffers the port
2838 + * requires (RO). This is set by the
2842 + u32 buffer_size_min; /* Minimum size of buffers the port
2843 + * requires (RO). This is set by the
2847 + u32 buffer_alignment_min; /* Minimum alignment requirement for
2848 + * the buffers (RO). A value of
2849 + * zero means no special alignment
2850 + * requirements. This is set by the
2854 + u32 buffer_num_recommended; /* Number of buffers the port
2855 + * recommends for optimal
2856 + * performance (RO). A value of
2857 + * zero means no special
2858 + * recommendation. This is set
2859 + * by the component.
2862 + u32 buffer_size_recommended; /* Size of buffers the port
2863 + * recommends for optimal
2864 + * performance (RO). A value of
2865 + * zero means no special
2866 + * recommendation. This is set
2867 + * by the component.
2870 + u32 buffer_num; /* Actual number of buffers the port will use.
2871 + * This is set by the client.
2874 + u32 buffer_size; /* Actual maximum size of the buffers that
2875 + * will be sent to the port. This is set by
2879 + void *component; /* Component this port belongs to (Read Only) */
2881 + void *userdata; /* Field reserved for use by the client */
2883 + u32 capabilities; /* Flags describing the capabilities of a
2884 + * port (RO). Bitwise combination of \ref
2885 + * portcapabilities "Port capabilities"
2891 +++ b/drivers/media/platform/bcm2835/mmal-msg.h
2894 + * Broadcom BM2835 V4L2 driver
2896 + * Copyright © 2013 Raspberry Pi (Trading) Ltd.
2898 + * This file is subject to the terms and conditions of the GNU General Public
2899 + * License. See the file COPYING in the main directory of this archive
2900 + * for more details.
2902 + * Authors: Vincent Sanders <vincent.sanders@collabora.co.uk>
2903 + * Dave Stevenson <dsteve@broadcom.com>
2904 + * Simon Mellor <simellor@broadcom.com>
2905 + * Luke Diamand <luked@broadcom.com>
2908 +/* all the data structures which serialise the MMAL protocol. note
2909 + * these are directly mapped onto the recived message data.
2911 + * BEWARE: They seem to *assume* pointers are u32 and that there is no
2912 + * structure padding!
2914 + * NOTE: this implementation uses kernel types to ensure sizes. Rather
2915 + * than assigning values to enums to force their size the
2916 + * implementation uses fixed size types and not the enums (though the
2917 + * comments have the actual enum type
2920 +#define VC_MMAL_VER 15
2921 +#define VC_MMAL_MIN_VER 10
2922 +#define VC_MMAL_SERVER_NAME MAKE_FOURCC("mmal")
2924 +/* max total message size is 512 bytes */
2925 +#define MMAL_MSG_MAX_SIZE 512
2926 +/* with six 32bit header elements max payload is therefore 488 bytes */
2927 +#define MMAL_MSG_MAX_PAYLOAD 488
2929 +#include "mmal-msg-common.h"
2930 +#include "mmal-msg-format.h"
2931 +#include "mmal-msg-port.h"
2933 +enum mmal_msg_type {
2934 + MMAL_MSG_TYPE_QUIT = 1,
2935 + MMAL_MSG_TYPE_SERVICE_CLOSED,
2936 + MMAL_MSG_TYPE_GET_VERSION,
2937 + MMAL_MSG_TYPE_COMPONENT_CREATE,
2938 + MMAL_MSG_TYPE_COMPONENT_DESTROY, /* 5 */
2939 + MMAL_MSG_TYPE_COMPONENT_ENABLE,
2940 + MMAL_MSG_TYPE_COMPONENT_DISABLE,
2941 + MMAL_MSG_TYPE_PORT_INFO_GET,
2942 + MMAL_MSG_TYPE_PORT_INFO_SET,
2943 + MMAL_MSG_TYPE_PORT_ACTION, /* 10 */
2944 + MMAL_MSG_TYPE_BUFFER_FROM_HOST,
2945 + MMAL_MSG_TYPE_BUFFER_TO_HOST,
2946 + MMAL_MSG_TYPE_GET_STATS,
2947 + MMAL_MSG_TYPE_PORT_PARAMETER_SET,
2948 + MMAL_MSG_TYPE_PORT_PARAMETER_GET, /* 15 */
2949 + MMAL_MSG_TYPE_EVENT_TO_HOST,
2950 + MMAL_MSG_TYPE_GET_CORE_STATS_FOR_PORT,
2951 + MMAL_MSG_TYPE_OPAQUE_ALLOCATOR,
2952 + MMAL_MSG_TYPE_CONSUME_MEM,
2953 + MMAL_MSG_TYPE_LMK, /* 20 */
2954 + MMAL_MSG_TYPE_OPAQUE_ALLOCATOR_DESC,
2955 + MMAL_MSG_TYPE_DRM_GET_LHS32,
2956 + MMAL_MSG_TYPE_DRM_GET_TIME,
2957 + MMAL_MSG_TYPE_BUFFER_FROM_HOST_ZEROLEN,
2958 + MMAL_MSG_TYPE_PORT_FLUSH, /* 25 */
2959 + MMAL_MSG_TYPE_HOST_LOG,
2960 + MMAL_MSG_TYPE_MSG_LAST
2963 +/* port action request messages differ depending on the action type */
2964 +enum mmal_msg_port_action_type {
2965 + MMAL_MSG_PORT_ACTION_TYPE_UNKNOWN = 0, /* Unkown action */
2966 + MMAL_MSG_PORT_ACTION_TYPE_ENABLE, /* Enable a port */
2967 + MMAL_MSG_PORT_ACTION_TYPE_DISABLE, /* Disable a port */
2968 + MMAL_MSG_PORT_ACTION_TYPE_FLUSH, /* Flush a port */
2969 + MMAL_MSG_PORT_ACTION_TYPE_CONNECT, /* Connect ports */
2970 + MMAL_MSG_PORT_ACTION_TYPE_DISCONNECT, /* Disconnect ports */
2971 + MMAL_MSG_PORT_ACTION_TYPE_SET_REQUIREMENTS, /* Set buffer requirements*/
2974 +struct mmal_msg_header {
2976 + u32 type; /** enum mmal_msg_type */
2978 + /* Opaque handle to the control service */
2979 + struct mmal_control_service *control_service;
2981 + struct mmal_msg_context *context; /** a u32 per message context */
2982 + u32 status; /** The status of the vchiq operation */
2986 +/* Send from VC to host to report version */
2987 +struct mmal_msg_version {
2994 +/* request to VC to create component */
2995 +struct mmal_msg_component_create {
2996 + void *client_component; /* component context */
2998 + u32 pid; /* For debug */
3001 +/* reply from VC to component creation request */
3002 +struct mmal_msg_component_create_reply {
3003 + u32 status; /** enum mmal_msg_status - how does this differ to
3004 + * the one in the header?
3006 + u32 component_handle; /* VideoCore handle for component */
3007 + u32 input_num; /* Number of input ports */
3008 + u32 output_num; /* Number of output ports */
3009 + u32 clock_num; /* Number of clock ports */
3012 +/* request to VC to destroy a component */
3013 +struct mmal_msg_component_destroy {
3014 + u32 component_handle;
3017 +struct mmal_msg_component_destroy_reply {
3018 + u32 status; /** The component destruction status */
3022 +/* request and reply to VC to enable a component */
3023 +struct mmal_msg_component_enable {
3024 + u32 component_handle;
3027 +struct mmal_msg_component_enable_reply {
3028 + u32 status; /** The component enable status */
3032 +/* request and reply to VC to disable a component */
3033 +struct mmal_msg_component_disable {
3034 + u32 component_handle;
3037 +struct mmal_msg_component_disable_reply {
3038 + u32 status; /** The component disable status */
3041 +/* request to VC to get port information */
3042 +struct mmal_msg_port_info_get {
3043 + u32 component_handle; /* component handle port is associated with */
3044 + u32 port_type; /* enum mmal_msg_port_type */
3045 + u32 index; /* port index to query */
3048 +/* reply from VC to get port info request */
3049 +struct mmal_msg_port_info_get_reply {
3050 + u32 status; /** enum mmal_msg_status */
3051 + u32 component_handle; /* component handle port is associated with */
3052 + u32 port_type; /* enum mmal_msg_port_type */
3053 + u32 port_index; /* port indexed in query */
3054 + s32 found; /* unused */
3055 + u32 port_handle; /**< Handle to use for this port */
3056 + struct mmal_port port;
3057 + struct mmal_es_format format; /* elementry stream format */
3058 + union mmal_es_specific_format es; /* es type specific data */
3059 + u8 extradata[MMAL_FORMAT_EXTRADATA_MAX_SIZE]; /* es extra data */
3062 +/* request to VC to set port information */
3063 +struct mmal_msg_port_info_set {
3064 + u32 component_handle;
3065 + u32 port_type; /* enum mmal_msg_port_type */
3066 + u32 port_index; /* port indexed in query */
3067 + struct mmal_port port;
3068 + struct mmal_es_format format;
3069 + union mmal_es_specific_format es;
3070 + u8 extradata[MMAL_FORMAT_EXTRADATA_MAX_SIZE];
3073 +/* reply from VC to port info set request */
3074 +struct mmal_msg_port_info_set_reply {
3076 + u32 component_handle; /* component handle port is associated with */
3077 + u32 port_type; /* enum mmal_msg_port_type */
3078 + u32 index; /* port indexed in query */
3079 + s32 found; /* unused */
3080 + u32 port_handle; /**< Handle to use for this port */
3081 + struct mmal_port port;
3082 + struct mmal_es_format format;
3083 + union mmal_es_specific_format es;
3084 + u8 extradata[MMAL_FORMAT_EXTRADATA_MAX_SIZE];
3088 +/* port action requests that take a mmal_port as a parameter */
3089 +struct mmal_msg_port_action_port {
3090 + u32 component_handle;
3092 + u32 action; /* enum mmal_msg_port_action_type */
3093 + struct mmal_port port;
3096 +/* port action requests that take handles as a parameter */
3097 +struct mmal_msg_port_action_handle {
3098 + u32 component_handle;
3100 + u32 action; /* enum mmal_msg_port_action_type */
3101 + u32 connect_component_handle;
3102 + u32 connect_port_handle;
3105 +struct mmal_msg_port_action_reply {
3106 + u32 status; /** The port action operation status */
3112 +/* MMAL buffer transfer */
3114 +/** Size of space reserved in a buffer message for short messages. */
3115 +#define MMAL_VC_SHORT_DATA 128
3117 +/** Signals that the current payload is the end of the stream of data */
3118 +#define MMAL_BUFFER_HEADER_FLAG_EOS (1<<0)
3119 +/** Signals that the start of the current payload starts a frame */
3120 +#define MMAL_BUFFER_HEADER_FLAG_FRAME_START (1<<1)
3121 +/** Signals that the end of the current payload ends a frame */
3122 +#define MMAL_BUFFER_HEADER_FLAG_FRAME_END (1<<2)
3123 +/** Signals that the current payload contains only complete frames (>1) */
3124 +#define MMAL_BUFFER_HEADER_FLAG_FRAME \
3125 + (MMAL_BUFFER_HEADER_FLAG_FRAME_START|MMAL_BUFFER_HEADER_FLAG_FRAME_END)
3126 +/** Signals that the current payload is a keyframe (i.e. self decodable) */
3127 +#define MMAL_BUFFER_HEADER_FLAG_KEYFRAME (1<<3)
3128 +/** Signals a discontinuity in the stream of data (e.g. after a seek).
3129 + * Can be used for instance by a decoder to reset its state */
3130 +#define MMAL_BUFFER_HEADER_FLAG_DISCONTINUITY (1<<4)
3131 +/** Signals a buffer containing some kind of config data for the component
3132 + * (e.g. codec config data) */
3133 +#define MMAL_BUFFER_HEADER_FLAG_CONFIG (1<<5)
3134 +/** Signals an encrypted payload */
3135 +#define MMAL_BUFFER_HEADER_FLAG_ENCRYPTED (1<<6)
3136 +/** Signals a buffer containing side information */
3137 +#define MMAL_BUFFER_HEADER_FLAG_CODECSIDEINFO (1<<7)
3138 +/** Signals a buffer which is the snapshot/postview image from a stills
3141 +#define MMAL_BUFFER_HEADER_FLAGS_SNAPSHOT (1<<8)
3142 +/** Signals a buffer which contains data known to be corrupted */
3143 +#define MMAL_BUFFER_HEADER_FLAG_CORRUPTED (1<<9)
3144 +/** Signals that a buffer failed to be transmitted */
3145 +#define MMAL_BUFFER_HEADER_FLAG_TRANSMISSION_FAILED (1<<10)
3147 +struct mmal_driver_buffer {
3149 + u32 component_handle;
3151 + void *client_context;
3154 +/* buffer header */
3155 +struct mmal_buffer_header {
3156 + struct mmal_buffer_header *next; /* next header */
3157 + void *priv; /* framework private data */
3170 +struct mmal_buffer_header_type_specific {
3181 +struct mmal_msg_buffer_from_host {
3182 + /* The front 32 bytes of the buffer header are copied
3183 + * back to us in the reply to allow for context. This
3184 + * area is used to store two mmal_driver_buffer structures to
3185 + * allow for multiple concurrent service users.
3187 + /* control data */
3188 + struct mmal_driver_buffer drvbuf;
3190 + /* referenced control data for passthrough buffer management */
3191 + struct mmal_driver_buffer drvbuf_ref;
3192 + struct mmal_buffer_header buffer_header; /* buffer header itself */
3193 + struct mmal_buffer_header_type_specific buffer_header_type_specific;
3195 + s32 has_reference;
3197 + /** allows short data to be xfered in control message */
3198 + u32 payload_in_message;
3199 + u8 short_data[MMAL_VC_SHORT_DATA];
3203 +/* port parameter setting */
3205 +#define MMAL_WORKER_PORT_PARAMETER_SPACE 96
3207 +struct mmal_msg_port_parameter_set {
3208 + u32 component_handle; /* component */
3209 + u32 port_handle; /* port */
3210 + u32 id; /* Parameter ID */
3211 + u32 size; /* Parameter size */
3212 + uint32_t value[MMAL_WORKER_PORT_PARAMETER_SPACE];
3215 +struct mmal_msg_port_parameter_set_reply {
3216 + u32 status; /** enum mmal_msg_status todo: how does this
3217 + * differ to the one in the header?
3221 +/* port parameter getting */
3223 +struct mmal_msg_port_parameter_get {
3224 + u32 component_handle; /* component */
3225 + u32 port_handle; /* port */
3226 + u32 id; /* Parameter ID */
3227 + u32 size; /* Parameter size */
3230 +struct mmal_msg_port_parameter_get_reply {
3231 + u32 status; /* Status of mmal_port_parameter_get call */
3232 + u32 id; /* Parameter ID */
3233 + u32 size; /* Parameter size */
3234 + uint32_t value[MMAL_WORKER_PORT_PARAMETER_SPACE];
3237 +/* event messages */
3238 +#define MMAL_WORKER_EVENT_SPACE 256
3240 +struct mmal_msg_event_to_host {
3241 + void *client_component; /* component context */
3248 + u8 data[MMAL_WORKER_EVENT_SPACE];
3249 + struct mmal_buffer_header *delayed_buffer;
3252 +/* all mmal messages are serialised through this structure */
3255 + struct mmal_msg_header h;
3258 + struct mmal_msg_version version;
3260 + struct mmal_msg_component_create component_create;
3261 + struct mmal_msg_component_create_reply component_create_reply;
3263 + struct mmal_msg_component_destroy component_destroy;
3264 + struct mmal_msg_component_destroy_reply component_destroy_reply;
3266 + struct mmal_msg_component_enable component_enable;
3267 + struct mmal_msg_component_enable_reply component_enable_reply;
3269 + struct mmal_msg_component_disable component_disable;
3270 + struct mmal_msg_component_disable_reply component_disable_reply;
3272 + struct mmal_msg_port_info_get port_info_get;
3273 + struct mmal_msg_port_info_get_reply port_info_get_reply;
3275 + struct mmal_msg_port_info_set port_info_set;
3276 + struct mmal_msg_port_info_set_reply port_info_set_reply;
3278 + struct mmal_msg_port_action_port port_action_port;
3279 + struct mmal_msg_port_action_handle port_action_handle;
3280 + struct mmal_msg_port_action_reply port_action_reply;
3282 + struct mmal_msg_buffer_from_host buffer_from_host;
3284 + struct mmal_msg_port_parameter_set port_parameter_set;
3285 + struct mmal_msg_port_parameter_set_reply
3286 + port_parameter_set_reply;
3287 + struct mmal_msg_port_parameter_get
3288 + port_parameter_get;
3289 + struct mmal_msg_port_parameter_get_reply
3290 + port_parameter_get_reply;
3292 + struct mmal_msg_event_to_host event_to_host;
3294 + u8 payload[MMAL_MSG_MAX_PAYLOAD];
3298 +++ b/drivers/media/platform/bcm2835/mmal-parameters.h
3301 + * Broadcom BM2835 V4L2 driver
3303 + * Copyright © 2013 Raspberry Pi (Trading) Ltd.
3305 + * This file is subject to the terms and conditions of the GNU General Public
3306 + * License. See the file COPYING in the main directory of this archive
3307 + * for more details.
3309 + * Authors: Vincent Sanders <vincent.sanders@collabora.co.uk>
3310 + * Dave Stevenson <dsteve@broadcom.com>
3311 + * Simon Mellor <simellor@broadcom.com>
3312 + * Luke Diamand <luked@broadcom.com>
3315 +/* common parameters */
3317 +/** @name Parameter groups
3318 + * Parameters are divided into groups, and then allocated sequentially within
3319 + * a group using an enum.
3323 +/** Common parameter ID group, used with many types of component. */
3324 +#define MMAL_PARAMETER_GROUP_COMMON (0<<16)
3325 +/** Camera-specific parameter ID group. */
3326 +#define MMAL_PARAMETER_GROUP_CAMERA (1<<16)
3327 +/** Video-specific parameter ID group. */
3328 +#define MMAL_PARAMETER_GROUP_VIDEO (2<<16)
3329 +/** Audio-specific parameter ID group. */
3330 +#define MMAL_PARAMETER_GROUP_AUDIO (3<<16)
3331 +/** Clock-specific parameter ID group. */
3332 +#define MMAL_PARAMETER_GROUP_CLOCK (4<<16)
3333 +/** Miracast-specific parameter ID group. */
3334 +#define MMAL_PARAMETER_GROUP_MIRACAST (5<<16)
3336 +/* Common parameters */
3337 +enum mmal_parameter_common_type {
3338 + MMAL_PARAMETER_UNUSED /**< Never a valid parameter ID */
3339 + = MMAL_PARAMETER_GROUP_COMMON,
3340 + MMAL_PARAMETER_SUPPORTED_ENCODINGS, /**< MMAL_PARAMETER_ENCODING_T */
3341 + MMAL_PARAMETER_URI, /**< MMAL_PARAMETER_URI_T */
3343 + /** MMAL_PARAMETER_CHANGE_EVENT_REQUEST_T */
3344 + MMAL_PARAMETER_CHANGE_EVENT_REQUEST,
3346 + /** MMAL_PARAMETER_BOOLEAN_T */
3347 + MMAL_PARAMETER_ZERO_COPY,
3349 + /**< MMAL_PARAMETER_BUFFER_REQUIREMENTS_T */
3350 + MMAL_PARAMETER_BUFFER_REQUIREMENTS,
3352 + MMAL_PARAMETER_STATISTICS, /**< MMAL_PARAMETER_STATISTICS_T */
3353 + MMAL_PARAMETER_CORE_STATISTICS, /**< MMAL_PARAMETER_CORE_STATISTICS_T */
3354 + MMAL_PARAMETER_MEM_USAGE, /**< MMAL_PARAMETER_MEM_USAGE_T */
3355 + MMAL_PARAMETER_BUFFER_FLAG_FILTER, /**< MMAL_PARAMETER_UINT32_T */
3356 + MMAL_PARAMETER_SEEK, /**< MMAL_PARAMETER_SEEK_T */
3357 + MMAL_PARAMETER_POWERMON_ENABLE, /**< MMAL_PARAMETER_BOOLEAN_T */
3358 + MMAL_PARAMETER_LOGGING, /**< MMAL_PARAMETER_LOGGING_T */
3359 + MMAL_PARAMETER_SYSTEM_TIME /**< MMAL_PARAMETER_UINT64_T */
3362 +/* camera parameters */
3364 +enum mmal_parameter_camera_type {
3366 + /** @ref MMAL_PARAMETER_THUMBNAIL_CONFIG_T */
3367 + MMAL_PARAMETER_THUMBNAIL_CONFIGURATION
3368 + = MMAL_PARAMETER_GROUP_CAMERA,
3369 + MMAL_PARAMETER_CAPTURE_QUALITY, /**< Unused? */
3370 + MMAL_PARAMETER_ROTATION, /**< @ref MMAL_PARAMETER_INT32_T */
3371 + MMAL_PARAMETER_EXIF_DISABLE, /**< @ref MMAL_PARAMETER_BOOLEAN_T */
3372 + MMAL_PARAMETER_EXIF, /**< @ref MMAL_PARAMETER_EXIF_T */
3373 + MMAL_PARAMETER_AWB_MODE, /**< @ref MMAL_PARAM_AWBMODE_T */
3374 + MMAL_PARAMETER_IMAGE_EFFECT, /**< @ref MMAL_PARAMETER_IMAGEFX_T */
3375 + MMAL_PARAMETER_COLOUR_EFFECT, /**< @ref MMAL_PARAMETER_COLOURFX_T */
3376 + MMAL_PARAMETER_FLICKER_AVOID, /**< @ref MMAL_PARAMETER_FLICKERAVOID_T */
3377 + MMAL_PARAMETER_FLASH, /**< @ref MMAL_PARAMETER_FLASH_T */
3378 + MMAL_PARAMETER_REDEYE, /**< @ref MMAL_PARAMETER_REDEYE_T */
3379 + MMAL_PARAMETER_FOCUS, /**< @ref MMAL_PARAMETER_FOCUS_T */
3380 + MMAL_PARAMETER_FOCAL_LENGTHS, /**< Unused? */
3381 + MMAL_PARAMETER_EXPOSURE_COMP, /**< @ref MMAL_PARAMETER_INT32_T */
3382 + MMAL_PARAMETER_ZOOM, /**< @ref MMAL_PARAMETER_SCALEFACTOR_T */
3383 + MMAL_PARAMETER_MIRROR, /**< @ref MMAL_PARAMETER_MIRROR_T */
3386 + MMAL_PARAMETER_CAMERA_NUM, /**< @ref MMAL_PARAMETER_UINT32_T */
3387 + MMAL_PARAMETER_CAPTURE, /**< @ref MMAL_PARAMETER_BOOLEAN_T */
3388 + MMAL_PARAMETER_EXPOSURE_MODE, /**< @ref MMAL_PARAMETER_EXPOSUREMODE_T */
3389 + MMAL_PARAMETER_EXP_METERING_MODE, /**< @ref MMAL_PARAMETER_EXPOSUREMETERINGMODE_T */
3390 + MMAL_PARAMETER_FOCUS_STATUS, /**< @ref MMAL_PARAMETER_FOCUS_STATUS_T */
3391 + MMAL_PARAMETER_CAMERA_CONFIG, /**< @ref MMAL_PARAMETER_CAMERA_CONFIG_T */
3392 + MMAL_PARAMETER_CAPTURE_STATUS, /**< @ref MMAL_PARAMETER_CAPTURE_STATUS_T */
3393 + MMAL_PARAMETER_FACE_TRACK, /**< @ref MMAL_PARAMETER_FACE_TRACK_T */
3394 + MMAL_PARAMETER_DRAW_BOX_FACES_AND_FOCUS, /**< @ref MMAL_PARAMETER_BOOLEAN_T */
3395 + MMAL_PARAMETER_JPEG_Q_FACTOR, /**< @ref MMAL_PARAMETER_UINT32_T */
3396 + MMAL_PARAMETER_FRAME_RATE, /**< @ref MMAL_PARAMETER_FRAME_RATE_T */
3397 + MMAL_PARAMETER_USE_STC, /**< @ref MMAL_PARAMETER_CAMERA_STC_MODE_T */
3398 + MMAL_PARAMETER_CAMERA_INFO, /**< @ref MMAL_PARAMETER_CAMERA_INFO_T */
3399 + MMAL_PARAMETER_VIDEO_STABILISATION, /**< @ref MMAL_PARAMETER_BOOLEAN_T */
3400 + MMAL_PARAMETER_FACE_TRACK_RESULTS, /**< @ref MMAL_PARAMETER_FACE_TRACK_RESULTS_T */
3401 + MMAL_PARAMETER_ENABLE_RAW_CAPTURE, /**< @ref MMAL_PARAMETER_BOOLEAN_T */
3404 + MMAL_PARAMETER_DPF_FILE, /**< @ref MMAL_PARAMETER_URI_T */
3405 + MMAL_PARAMETER_ENABLE_DPF_FILE, /**< @ref MMAL_PARAMETER_BOOLEAN_T */
3406 + MMAL_PARAMETER_DPF_FAIL_IS_FATAL, /**< @ref MMAL_PARAMETER_BOOLEAN_T */
3407 + MMAL_PARAMETER_CAPTURE_MODE, /**< @ref MMAL_PARAMETER_CAPTUREMODE_T */
3408 + MMAL_PARAMETER_FOCUS_REGIONS, /**< @ref MMAL_PARAMETER_FOCUS_REGIONS_T */
3409 + MMAL_PARAMETER_INPUT_CROP, /**< @ref MMAL_PARAMETER_INPUT_CROP_T */
3410 + MMAL_PARAMETER_SENSOR_INFORMATION, /**< @ref MMAL_PARAMETER_SENSOR_INFORMATION_T */
3411 + MMAL_PARAMETER_FLASH_SELECT, /**< @ref MMAL_PARAMETER_FLASH_SELECT_T */
3412 + MMAL_PARAMETER_FIELD_OF_VIEW, /**< @ref MMAL_PARAMETER_FIELD_OF_VIEW_T */
3413 + MMAL_PARAMETER_HIGH_DYNAMIC_RANGE, /**< @ref MMAL_PARAMETER_BOOLEAN_T */
3414 + MMAL_PARAMETER_DYNAMIC_RANGE_COMPRESSION, /**< @ref MMAL_PARAMETER_DRC_T */
3415 + MMAL_PARAMETER_ALGORITHM_CONTROL, /**< @ref MMAL_PARAMETER_ALGORITHM_CONTROL_T */
3416 + MMAL_PARAMETER_SHARPNESS, /**< @ref MMAL_PARAMETER_RATIONAL_T */
3417 + MMAL_PARAMETER_CONTRAST, /**< @ref MMAL_PARAMETER_RATIONAL_T */
3418 + MMAL_PARAMETER_BRIGHTNESS, /**< @ref MMAL_PARAMETER_RATIONAL_T */
3419 + MMAL_PARAMETER_SATURATION, /**< @ref MMAL_PARAMETER_RATIONAL_T */
3422 + MMAL_PARAMETER_ISO, /**< @ref MMAL_PARAMETER_UINT32_T */
3423 + MMAL_PARAMETER_ANTISHAKE, /**< @ref MMAL_PARAMETER_BOOLEAN_T */
3425 + /** @ref MMAL_PARAMETER_IMAGEFX_PARAMETERS_T */
3426 + MMAL_PARAMETER_IMAGE_EFFECT_PARAMETERS,
3428 + /** @ref MMAL_PARAMETER_BOOLEAN_T */
3429 + MMAL_PARAMETER_CAMERA_BURST_CAPTURE,
3431 + /** @ref MMAL_PARAMETER_UINT32_T */
3432 + MMAL_PARAMETER_CAMERA_MIN_ISO,
3434 + /** @ref MMAL_PARAMETER_CAMERA_USE_CASE_T */
3435 + MMAL_PARAMETER_CAMERA_USE_CASE,
3437 + /**< @ref MMAL_PARAMETER_BOOLEAN_T */
3438 + MMAL_PARAMETER_CAPTURE_STATS_PASS,
3440 + /** @ref MMAL_PARAMETER_UINT32_T */
3441 + MMAL_PARAMETER_CAMERA_CUSTOM_SENSOR_CONFIG,
3443 + /** @ref MMAL_PARAMETER_BOOLEAN_T */
3444 + MMAL_PARAMETER_ENABLE_REGISTER_FILE,
3446 + /** @ref MMAL_PARAMETER_BOOLEAN_T */
3447 + MMAL_PARAMETER_REGISTER_FAIL_IS_FATAL,
3449 + /** @ref MMAL_PARAMETER_CONFIGFILE_T */
3450 + MMAL_PARAMETER_CONFIGFILE_REGISTERS,
3452 + /** @ref MMAL_PARAMETER_CONFIGFILE_CHUNK_T */
3453 + MMAL_PARAMETER_CONFIGFILE_CHUNK_REGISTERS,
3454 + MMAL_PARAMETER_JPEG_ATTACH_LOG, /**< @ref MMAL_PARAMETER_BOOLEAN_T */
3455 + MMAL_PARAMETER_ZERO_SHUTTER_LAG, /**< @ref MMAL_PARAMETER_ZEROSHUTTERLAG_T */
3456 + MMAL_PARAMETER_FPS_RANGE, /**< @ref MMAL_PARAMETER_FPS_RANGE_T */
3457 + MMAL_PARAMETER_CAPTURE_EXPOSURE_COMP, /**< @ref MMAL_PARAMETER_INT32_T */
3460 + MMAL_PARAMETER_SW_SHARPEN_DISABLE, /**< @ref MMAL_PARAMETER_BOOLEAN_T */
3461 + MMAL_PARAMETER_FLASH_REQUIRED, /**< @ref MMAL_PARAMETER_BOOLEAN_T */
3462 + MMAL_PARAMETER_SW_SATURATION_DISABLE, /**< @ref MMAL_PARAMETER_BOOLEAN_T */
3465 +enum mmal_parameter_camera_config_timestamp_mode {
3466 + MMAL_PARAM_TIMESTAMP_MODE_ZERO = 0, /* Always timestamp frames as 0 */
3467 + MMAL_PARAM_TIMESTAMP_MODE_RAW_STC, /* Use the raw STC value
3468 + * for the frame timestamp
3470 + MMAL_PARAM_TIMESTAMP_MODE_RESET_STC, /* Use the STC timestamp
3471 + * but subtract the
3472 + * timestamp of the first
3473 + * frame sent to give a
3474 + * zero based timestamp.
3478 +/* camera configuration parameter */
3479 +struct mmal_parameter_camera_config {
3480 + /* Parameters for setting up the image pools */
3481 + u32 max_stills_w; /* Max size of stills capture */
3483 + u32 stills_yuv422; /* Allow YUV422 stills capture */
3484 + u32 one_shot_stills; /* Continuous or one shot stills captures. */
3486 + u32 max_preview_video_w; /* Max size of the preview or video
3489 + u32 max_preview_video_h;
3490 + u32 num_preview_video_frames;
3492 + /** Sets the height of the circular buffer for stills capture. */
3493 + u32 stills_capture_circular_buffer_height;
3495 + /** Allows preview/encode to resume as fast as possible after the stills
3496 + * input frame has been received, and then processes the still frame in
3497 + * the background whilst preview/encode has resumed.
3498 + * Actual mode is controlled by MMAL_PARAMETER_CAPTURE_MODE.
3500 + u32 fast_preview_resume;
3502 + /** Selects algorithm for timestamping frames if
3503 + * there is no clock component connected.
3504 + * enum mmal_parameter_camera_config_timestamp_mode
3506 + s32 use_stc_timestamp;
3510 +enum mmal_parameter_exposuremode {
3511 + MMAL_PARAM_EXPOSUREMODE_OFF,
3512 + MMAL_PARAM_EXPOSUREMODE_AUTO,
3513 + MMAL_PARAM_EXPOSUREMODE_NIGHT,
3514 + MMAL_PARAM_EXPOSUREMODE_NIGHTPREVIEW,
3515 + MMAL_PARAM_EXPOSUREMODE_BACKLIGHT,
3516 + MMAL_PARAM_EXPOSUREMODE_SPOTLIGHT,
3517 + MMAL_PARAM_EXPOSUREMODE_SPORTS,
3518 + MMAL_PARAM_EXPOSUREMODE_SNOW,
3519 + MMAL_PARAM_EXPOSUREMODE_BEACH,
3520 + MMAL_PARAM_EXPOSUREMODE_VERYLONG,
3521 + MMAL_PARAM_EXPOSUREMODE_FIXEDFPS,
3522 + MMAL_PARAM_EXPOSUREMODE_ANTISHAKE,
3523 + MMAL_PARAM_EXPOSUREMODE_FIREWORKS,
3526 +enum mmal_parameter_exposuremeteringmode {
3527 + MMAL_PARAM_EXPOSUREMETERINGMODE_AVERAGE,
3528 + MMAL_PARAM_EXPOSUREMETERINGMODE_SPOT,
3529 + MMAL_PARAM_EXPOSUREMETERINGMODE_BACKLIT,
3530 + MMAL_PARAM_EXPOSUREMETERINGMODE_MATRIX,
3533 +enum mmal_parameter_awbmode {
3534 + MMAL_PARAM_AWBMODE_OFF,
3535 + MMAL_PARAM_AWBMODE_AUTO,
3536 + MMAL_PARAM_AWBMODE_SUNLIGHT,
3537 + MMAL_PARAM_AWBMODE_CLOUDY,
3538 + MMAL_PARAM_AWBMODE_SHADE,
3539 + MMAL_PARAM_AWBMODE_TUNGSTEN,
3540 + MMAL_PARAM_AWBMODE_FLUORESCENT,
3541 + MMAL_PARAM_AWBMODE_INCANDESCENT,
3542 + MMAL_PARAM_AWBMODE_FLASH,
3543 + MMAL_PARAM_AWBMODE_HORIZON,
3546 +enum mmal_parameter_imagefx {
3547 + MMAL_PARAM_IMAGEFX_NONE,
3548 + MMAL_PARAM_IMAGEFX_NEGATIVE,
3549 + MMAL_PARAM_IMAGEFX_SOLARIZE,
3550 + MMAL_PARAM_IMAGEFX_POSTERIZE,
3551 + MMAL_PARAM_IMAGEFX_WHITEBOARD,
3552 + MMAL_PARAM_IMAGEFX_BLACKBOARD,
3553 + MMAL_PARAM_IMAGEFX_SKETCH,
3554 + MMAL_PARAM_IMAGEFX_DENOISE,
3555 + MMAL_PARAM_IMAGEFX_EMBOSS,
3556 + MMAL_PARAM_IMAGEFX_OILPAINT,
3557 + MMAL_PARAM_IMAGEFX_HATCH,
3558 + MMAL_PARAM_IMAGEFX_GPEN,
3559 + MMAL_PARAM_IMAGEFX_PASTEL,
3560 + MMAL_PARAM_IMAGEFX_WATERCOLOUR,
3561 + MMAL_PARAM_IMAGEFX_FILM,
3562 + MMAL_PARAM_IMAGEFX_BLUR,
3563 + MMAL_PARAM_IMAGEFX_SATURATION,
3564 + MMAL_PARAM_IMAGEFX_COLOURSWAP,
3565 + MMAL_PARAM_IMAGEFX_WASHEDOUT,
3566 + MMAL_PARAM_IMAGEFX_POSTERISE,
3567 + MMAL_PARAM_IMAGEFX_COLOURPOINT,
3568 + MMAL_PARAM_IMAGEFX_COLOURBALANCE,
3569 + MMAL_PARAM_IMAGEFX_CARTOON,
3572 +/** Manner of video rate control */
3573 +enum mmal_parameter_rate_control_mode {
3574 + MMAL_VIDEO_RATECONTROL_DEFAULT,
3575 + MMAL_VIDEO_RATECONTROL_VARIABLE,
3576 + MMAL_VIDEO_RATECONTROL_CONSTANT,
3577 + MMAL_VIDEO_RATECONTROL_VARIABLE_SKIP_FRAMES,
3578 + MMAL_VIDEO_RATECONTROL_CONSTANT_SKIP_FRAMES
3581 +/* video parameters */
3583 +enum mmal_parameter_video_type {
3584 + /** @ref MMAL_DISPLAYREGION_T */
3585 + MMAL_PARAMETER_DISPLAYREGION = MMAL_PARAMETER_GROUP_VIDEO,
3587 + /** @ref MMAL_PARAMETER_VIDEO_PROFILE_T */
3588 + MMAL_PARAMETER_SUPPORTED_PROFILES,
3590 + /** @ref MMAL_PARAMETER_VIDEO_PROFILE_T */
3591 + MMAL_PARAMETER_PROFILE,
3593 + /** @ref MMAL_PARAMETER_UINT32_T */
3594 + MMAL_PARAMETER_INTRAPERIOD,
3596 + /** @ref MMAL_PARAMETER_VIDEO_RATECONTROL_T */
3597 + MMAL_PARAMETER_RATECONTROL,
3599 + /** @ref MMAL_PARAMETER_VIDEO_NALUNITFORMAT_T */
3600 + MMAL_PARAMETER_NALUNITFORMAT,
3602 + /** @ref MMAL_PARAMETER_BOOLEAN_T */
3603 + MMAL_PARAMETER_MINIMISE_FRAGMENTATION,
3605 + /** @ref MMAL_PARAMETER_UINT32_T.
3606 + * Setting the value to zero resets to the default (one slice per frame).
3608 + MMAL_PARAMETER_MB_ROWS_PER_SLICE,
3610 + /** @ref MMAL_PARAMETER_VIDEO_LEVEL_EXTENSION_T */
3611 + MMAL_PARAMETER_VIDEO_LEVEL_EXTENSION,
3613 + /** @ref MMAL_PARAMETER_VIDEO_EEDE_ENABLE_T */
3614 + MMAL_PARAMETER_VIDEO_EEDE_ENABLE,
3616 + /** @ref MMAL_PARAMETER_VIDEO_EEDE_LOSSRATE_T */
3617 + MMAL_PARAMETER_VIDEO_EEDE_LOSSRATE,
3619 + /** @ref MMAL_PARAMETER_BOOLEAN_T. Request an I-frame. */
3620 + MMAL_PARAMETER_VIDEO_REQUEST_I_FRAME,
3621 + /** @ref MMAL_PARAMETER_VIDEO_INTRA_REFRESH_T */
3622 + MMAL_PARAMETER_VIDEO_INTRA_REFRESH,
3624 + /** @ref MMAL_PARAMETER_BOOLEAN_T. */
3625 + MMAL_PARAMETER_VIDEO_IMMUTABLE_INPUT,
3627 + /** @ref MMAL_PARAMETER_UINT32_T. Run-time bit rate control */
3628 + MMAL_PARAMETER_VIDEO_BIT_RATE,
3630 + /** @ref MMAL_PARAMETER_FRAME_RATE_T */
3631 + MMAL_PARAMETER_VIDEO_FRAME_RATE,
3633 + /** @ref MMAL_PARAMETER_UINT32_T. */
3634 + MMAL_PARAMETER_VIDEO_ENCODE_MIN_QUANT,
3636 + /** @ref MMAL_PARAMETER_UINT32_T. */
3637 + MMAL_PARAMETER_VIDEO_ENCODE_MAX_QUANT,
3639 + /** @ref MMAL_PARAMETER_VIDEO_ENCODE_RC_MODEL_T. */
3640 + MMAL_PARAMETER_VIDEO_ENCODE_RC_MODEL,
3642 + MMAL_PARAMETER_EXTRA_BUFFERS, /**< @ref MMAL_PARAMETER_UINT32_T. */
3643 + /** @ref MMAL_PARAMETER_UINT32_T.
3644 + * Changing this parameter from the default can reduce frame rate
3645 + * because image buffers need to be re-pitched.
3647 + MMAL_PARAMETER_VIDEO_ALIGN_HORIZ,
3649 + /** @ref MMAL_PARAMETER_UINT32_T.
3650 + * Changing this parameter from the default can reduce frame rate
3651 + * because image buffers need to be re-pitched.
3653 + MMAL_PARAMETER_VIDEO_ALIGN_VERT,
3655 + /** @ref MMAL_PARAMETER_BOOLEAN_T. */
3656 + MMAL_PARAMETER_VIDEO_DROPPABLE_PFRAMES,
3658 + /** @ref MMAL_PARAMETER_UINT32_T. */
3659 + MMAL_PARAMETER_VIDEO_ENCODE_INITIAL_QUANT,
3661 + /**< @ref MMAL_PARAMETER_UINT32_T. */
3662 + MMAL_PARAMETER_VIDEO_ENCODE_QP_P,
3664 + /**< @ref MMAL_PARAMETER_UINT32_T. */
3665 + MMAL_PARAMETER_VIDEO_ENCODE_RC_SLICE_DQUANT,
3667 + /** @ref MMAL_PARAMETER_UINT32_T */
3668 + MMAL_PARAMETER_VIDEO_ENCODE_FRAME_LIMIT_BITS,
3670 + /** @ref MMAL_PARAMETER_UINT32_T. */
3671 + MMAL_PARAMETER_VIDEO_ENCODE_PEAK_RATE,
3673 + /* H264 specific parameters */
3675 + /** @ref MMAL_PARAMETER_BOOLEAN_T. */
3676 + MMAL_PARAMETER_VIDEO_ENCODE_H264_DISABLE_CABAC,
3678 + /** @ref MMAL_PARAMETER_BOOLEAN_T. */
3679 + MMAL_PARAMETER_VIDEO_ENCODE_H264_LOW_LATENCY,
3681 + /** @ref MMAL_PARAMETER_BOOLEAN_T. */
3682 + MMAL_PARAMETER_VIDEO_ENCODE_H264_AU_DELIMITERS,
3684 + /** @ref MMAL_PARAMETER_UINT32_T. */
3685 + MMAL_PARAMETER_VIDEO_ENCODE_H264_DEBLOCK_IDC,
3687 + /** @ref MMAL_PARAMETER_VIDEO_ENCODER_H264_MB_INTRA_MODES_T. */
3688 + MMAL_PARAMETER_VIDEO_ENCODE_H264_MB_INTRA_MODE,
3690 + /** @ref MMAL_PARAMETER_BOOLEAN_T */
3691 + MMAL_PARAMETER_VIDEO_ENCODE_HEADER_ON_OPEN,
3693 + /** @ref MMAL_PARAMETER_BOOLEAN_T */
3694 + MMAL_PARAMETER_VIDEO_ENCODE_PRECODE_FOR_QP,
3696 + /** @ref MMAL_PARAMETER_VIDEO_DRM_INIT_INFO_T. */
3697 + MMAL_PARAMETER_VIDEO_DRM_INIT_INFO,
3699 + /** @ref MMAL_PARAMETER_BOOLEAN_T */
3700 + MMAL_PARAMETER_VIDEO_TIMESTAMP_FIFO,
3702 + /** @ref MMAL_PARAMETER_BOOLEAN_T */
3703 + MMAL_PARAMETER_VIDEO_DECODE_ERROR_CONCEALMENT,
3705 + /** @ref MMAL_PARAMETER_VIDEO_DRM_PROTECT_BUFFER_T. */
3706 + MMAL_PARAMETER_VIDEO_DRM_PROTECT_BUFFER,
3708 + /** @ref MMAL_PARAMETER_BYTES_T */
3709 + MMAL_PARAMETER_VIDEO_DECODE_CONFIG_VD3
3712 +/** Valid mirror modes */
3713 +enum mmal_parameter_mirror {
3714 + MMAL_PARAM_MIRROR_NONE,
3715 + MMAL_PARAM_MIRROR_VERTICAL,
3716 + MMAL_PARAM_MIRROR_HORIZONTAL,
3717 + MMAL_PARAM_MIRROR_BOTH,
3720 +enum mmal_parameter_displaytransform {
3721 + MMAL_DISPLAY_ROT0 = 0,
3722 + MMAL_DISPLAY_MIRROR_ROT0 = 1,
3723 + MMAL_DISPLAY_MIRROR_ROT180 = 2,
3724 + MMAL_DISPLAY_ROT180 = 3,
3725 + MMAL_DISPLAY_MIRROR_ROT90 = 4,
3726 + MMAL_DISPLAY_ROT270 = 5,
3727 + MMAL_DISPLAY_ROT90 = 6,
3728 + MMAL_DISPLAY_MIRROR_ROT270 = 7,
3731 +enum mmal_parameter_displaymode {
3732 + MMAL_DISPLAY_MODE_FILL = 0,
3733 + MMAL_DISPLAY_MODE_LETTERBOX = 1,
3736 +enum mmal_parameter_displayset {
3737 + MMAL_DISPLAY_SET_NONE = 0,
3738 + MMAL_DISPLAY_SET_NUM = 1,
3739 + MMAL_DISPLAY_SET_FULLSCREEN = 2,
3740 + MMAL_DISPLAY_SET_TRANSFORM = 4,
3741 + MMAL_DISPLAY_SET_DEST_RECT = 8,
3742 + MMAL_DISPLAY_SET_SRC_RECT = 0x10,
3743 + MMAL_DISPLAY_SET_MODE = 0x20,
3744 + MMAL_DISPLAY_SET_PIXEL = 0x40,
3745 + MMAL_DISPLAY_SET_NOASPECT = 0x80,
3746 + MMAL_DISPLAY_SET_LAYER = 0x100,
3747 + MMAL_DISPLAY_SET_COPYPROTECT = 0x200,
3748 + MMAL_DISPLAY_SET_ALPHA = 0x400,
3751 +struct mmal_parameter_displayregion {
3752 + /** Bitfield that indicates which fields are set and should be
3753 + * used. All other fields will maintain their current value.
3754 + * \ref MMAL_DISPLAYSET_T defines the bits that can be
3759 + /** Describes the display output device, with 0 typically
3760 + * being a directly connected LCD display. The actual values
3761 + * will depend on the hardware. Code using hard-wired numbers
3762 + * (e.g. 2) is certain to fail.
3766 + /** Indicates that we are using the full device screen area,
3767 + * rather than a window of the display. If zero, then
3768 + * dest_rect is used to specify a region of the display to
3773 + /** Indicates any rotation or flipping used to map frames onto
3774 + * the natural display orientation.
3776 + u32 transform; /* enum mmal_parameter_displaytransform */
3778 + /** Where to display the frame within the screen, if
3779 + * fullscreen is zero.
3781 + struct vchiq_mmal_rect dest_rect;
3783 + /** Indicates which area of the frame to display. If all
3784 + * values are zero, the whole frame will be used.
3786 + struct vchiq_mmal_rect src_rect;
3788 + /** If set to non-zero, indicates that any display scaling
3789 + * should disregard the aspect ratio of the frame region being
3794 + /** Indicates how the image should be scaled to fit the
3795 + * display. \code MMAL_DISPLAY_MODE_FILL \endcode indicates
3796 + * that the image should fill the screen by potentially
3797 + * cropping the frames. Setting \code mode \endcode to \code
3798 + * MMAL_DISPLAY_MODE_LETTERBOX \endcode indicates that all the
3799 + * source region should be displayed and black bars added if
3802 + u32 mode; /* enum mmal_parameter_displaymode */
3804 + /** If non-zero, defines the width of a source pixel relative
3805 + * to \code pixel_y \endcode. If zero, then pixels default to
3810 + /** If non-zero, defines the height of a source pixel relative
3811 + * to \code pixel_x \endcode. If zero, then pixels default to
3816 + /** Sets the relative depth of the images, with greater values
3817 + * being in front of smaller values.
3821 + /** Set to non-zero to ensure copy protection is used on
3824 + s32 copyprotect_required;
3826 + /** Level of opacity of the layer, where zero is fully
3827 + * transparent and 255 is fully opaque.
3832 +#define MMAL_MAX_IMAGEFX_PARAMETERS 5
3834 +struct mmal_parameter_imagefx_parameters {
3835 + enum mmal_parameter_imagefx effect;
3836 + u32 num_effect_params;
3837 + u32 effect_parameter[MMAL_MAX_IMAGEFX_PARAMETERS];
3840 +++ b/drivers/media/platform/bcm2835/mmal-vchiq.c
3843 + * Broadcom BM2835 V4L2 driver
3845 + * Copyright © 2013 Raspberry Pi (Trading) Ltd.
3847 + * This file is subject to the terms and conditions of the GNU General Public
3848 + * License. See the file COPYING in the main directory of this archive
3849 + * for more details.
3851 + * Authors: Vincent Sanders <vincent.sanders@collabora.co.uk>
3852 + * Dave Stevenson <dsteve@broadcom.com>
3853 + * Simon Mellor <simellor@broadcom.com>
3854 + * Luke Diamand <luked@broadcom.com>
3856 + * V4L2 driver MMAL vchiq interface code
3859 +#define pr_fmt(fmt) KBUILD_MODNAME ": " fmt
3861 +#include <linux/errno.h>
3862 +#include <linux/kernel.h>
3863 +#include <linux/mutex.h>
3864 +#include <linux/mm.h>
3865 +#include <linux/slab.h>
3866 +#include <linux/completion.h>
3867 +#include <linux/vmalloc.h>
3868 +#include <asm/cacheflush.h>
3869 +#include <media/videobuf2-vmalloc.h>
3871 +#include "mmal-common.h"
3872 +#include "mmal-vchiq.h"
3873 +#include "mmal-msg.h"
3875 +#define USE_VCHIQ_ARM
3876 +#include "interface/vchi/vchi.h"
3878 +/* maximum number of components supported */
3879 +#define VCHIQ_MMAL_MAX_COMPONENTS 4
3881 +/*#define FULL_MSG_DUMP 1*/
3884 +static const char *const msg_type_names[] = {
3889 + "COMPONENT_CREATE",
3890 + "COMPONENT_DESTROY",
3891 + "COMPONENT_ENABLE",
3892 + "COMPONENT_DISABLE",
3896 + "BUFFER_FROM_HOST",
3899 + "PORT_PARAMETER_SET",
3900 + "PORT_PARAMETER_GET",
3902 + "GET_CORE_STATS_FOR_PORT",
3903 + "OPAQUE_ALLOCATOR",
3906 + "OPAQUE_ALLOCATOR_DESC",
3909 + "BUFFER_FROM_HOST_ZEROLEN",
3915 +static const char *const port_action_type_names[] = {
3922 + "SET_REQUIREMENTS",
3926 +#if defined(FULL_MSG_DUMP)
3927 +#define DBG_DUMP_MSG(MSG, MSG_LEN, TITLE) \
3929 + pr_debug(TITLE" type:%s(%d) length:%d\n", \
3930 + msg_type_names[(MSG)->h.type], \
3931 + (MSG)->h.type, (MSG_LEN)); \
3932 + print_hex_dump(KERN_DEBUG, "<<h: ", DUMP_PREFIX_OFFSET, \
3934 + sizeof(struct mmal_msg_header), 1); \
3935 + print_hex_dump(KERN_DEBUG, "<<p: ", DUMP_PREFIX_OFFSET, \
3937 + ((u8 *)(MSG)) + sizeof(struct mmal_msg_header),\
3938 + (MSG_LEN) - sizeof(struct mmal_msg_header), 1); \
3941 +#define DBG_DUMP_MSG(MSG, MSG_LEN, TITLE) \
3943 + pr_debug(TITLE" type:%s(%d) length:%d\n", \
3944 + msg_type_names[(MSG)->h.type], \
3945 + (MSG)->h.type, (MSG_LEN)); \
3949 +#define DBG_DUMP_MSG(MSG, MSG_LEN, TITLE)
3952 +/* normal message context */
3953 +struct mmal_msg_context {
3956 + /* work struct for defered callback - must come first */
3957 + struct work_struct work;
3958 + /* mmal instance */
3959 + struct vchiq_mmal_instance *instance;
3961 + struct vchiq_mmal_port *port;
3962 + /* actual buffer used to store bulk reply */
3963 + struct mmal_buffer *buffer;
3964 + /* amount of buffer used */
3965 + unsigned long buffer_used;
3966 + /* MMAL buffer flags */
3968 + /* Presentation and Decode timestamps */
3972 + int status; /* context status */
3974 + } bulk; /* bulk data */
3977 + /* message handle to release */
3978 + VCHI_HELD_MSG_T msg_handle;
3979 + /* pointer to received message */
3980 + struct mmal_msg *msg;
3981 + /* received message length */
3983 + /* completion upon reply */
3984 + struct completion cmplt;
3985 + } sync; /* synchronous response */
3990 +struct vchiq_mmal_instance {
3991 + VCHI_SERVICE_HANDLE_T handle;
3993 + /* ensure serialised access to service */
3994 + struct mutex vchiq_mutex;
3996 + /* ensure serialised access to bulk operations */
3997 + struct mutex bulk_mutex;
3999 + /* vmalloc page to receive scratch bulk xfers into */
4000 + void *bulk_scratch;
4002 + /* component to use next */
4003 + int component_idx;
4004 + struct vchiq_mmal_component component[VCHIQ_MMAL_MAX_COMPONENTS];
4007 +static struct mmal_msg_context *get_msg_context(struct vchiq_mmal_instance
4010 + struct mmal_msg_context *msg_context;
4012 + /* todo: should this be allocated from a pool to avoid kmalloc */
4013 + msg_context = kmalloc(sizeof(*msg_context), GFP_KERNEL);
4014 + memset(msg_context, 0, sizeof(*msg_context));
4016 + return msg_context;
4019 +static void release_msg_context(struct mmal_msg_context *msg_context)
4021 + kfree(msg_context);
4024 +/* deals with receipt of event to host message */
4025 +static void event_to_host_cb(struct vchiq_mmal_instance *instance,
4026 + struct mmal_msg *msg, u32 msg_len)
4028 + pr_debug("unhandled event\n");
4029 + pr_debug("component:%p port type:%d num:%d cmd:0x%x length:%d\n",
4030 + msg->u.event_to_host.client_component,
4031 + msg->u.event_to_host.port_type,
4032 + msg->u.event_to_host.port_num,
4033 + msg->u.event_to_host.cmd, msg->u.event_to_host.length);
4036 +/* workqueue scheduled callback
4038 + * we do this because it is important we do not call any other vchiq
4039 + * sync calls from witin the message delivery thread
4041 +static void buffer_work_cb(struct work_struct *work)
4043 + struct mmal_msg_context *msg_context = (struct mmal_msg_context *)work;
4045 + msg_context->u.bulk.port->buffer_cb(msg_context->u.bulk.instance,
4046 + msg_context->u.bulk.port,
4047 + msg_context->u.bulk.status,
4048 + msg_context->u.bulk.buffer,
4049 + msg_context->u.bulk.buffer_used,
4050 + msg_context->u.bulk.mmal_flags,
4051 + msg_context->u.bulk.dts,
4052 + msg_context->u.bulk.pts);
4054 + /* release message context */
4055 + release_msg_context(msg_context);
4058 +/* enqueue a bulk receive for a given message context */
4059 +static int bulk_receive(struct vchiq_mmal_instance *instance,
4060 + struct mmal_msg *msg,
4061 + struct mmal_msg_context *msg_context)
4063 + unsigned long rd_len;
4064 + unsigned long flags = 0;
4067 + /* bulk mutex stops other bulk operations while we have a
4068 + * receive in progress - released in callback
4070 + ret = mutex_lock_interruptible(&instance->bulk_mutex);
4074 + rd_len = msg->u.buffer_from_host.buffer_header.length;
4076 + /* take buffer from queue */
4077 + spin_lock_irqsave(&msg_context->u.bulk.port->slock, flags);
4078 + if (list_empty(&msg_context->u.bulk.port->buffers)) {
4079 + spin_unlock_irqrestore(&msg_context->u.bulk.port->slock, flags);
4080 + pr_err("buffer list empty trying to submit bulk receive\n");
4082 + /* todo: this is a serious error, we should never have
4083 + * commited a buffer_to_host operation to the mmal
4084 + * port without the buffer to back it up (underflow
4085 + * handling) and there is no obvious way to deal with
4086 + * this - how is the mmal servie going to react when
4087 + * we fail to do the xfer and reschedule a buffer when
4088 + * it arrives? perhaps a starved flag to indicate a
4089 + * waiting bulk receive?
4092 + mutex_unlock(&instance->bulk_mutex);
4097 + msg_context->u.bulk.buffer =
4098 + list_entry(msg_context->u.bulk.port->buffers.next,
4099 + struct mmal_buffer, list);
4100 + list_del(&msg_context->u.bulk.buffer->list);
4102 + spin_unlock_irqrestore(&msg_context->u.bulk.port->slock, flags);
4104 + /* ensure we do not overrun the available buffer */
4105 + if (rd_len > msg_context->u.bulk.buffer->buffer_size) {
4106 + rd_len = msg_context->u.bulk.buffer->buffer_size;
4107 + pr_warn("short read as not enough receive buffer space\n");
4108 + /* todo: is this the correct response, what happens to
4109 + * the rest of the message data?
4113 + /* store length */
4114 + msg_context->u.bulk.buffer_used = rd_len;
4115 + msg_context->u.bulk.mmal_flags =
4116 + msg->u.buffer_from_host.buffer_header.flags;
4117 + msg_context->u.bulk.dts = msg->u.buffer_from_host.buffer_header.dts;
4118 + msg_context->u.bulk.pts = msg->u.buffer_from_host.buffer_header.pts;
4120 + // only need to flush L1 cache here, as VCHIQ takes care of the L2
4122 + __cpuc_flush_dcache_area(msg_context->u.bulk.buffer->buffer, rd_len);
4124 + /* queue the bulk submission */
4125 + vchi_service_use(instance->handle);
4126 + ret = vchi_bulk_queue_receive(instance->handle,
4127 + msg_context->u.bulk.buffer->buffer,
4128 + /* Actual receive needs to be a multiple
4131 + (rd_len + 3) & ~3,
4132 + VCHI_FLAGS_CALLBACK_WHEN_OP_COMPLETE |
4133 + VCHI_FLAGS_BLOCK_UNTIL_QUEUED,
4136 + vchi_service_release(instance->handle);
4139 + /* callback will not be clearing the mutex */
4140 + mutex_unlock(&instance->bulk_mutex);
4146 +/* enque a dummy bulk receive for a given message context */
4147 +static int dummy_bulk_receive(struct vchiq_mmal_instance *instance,
4148 + struct mmal_msg_context *msg_context)
4152 + /* bulk mutex stops other bulk operations while we have a
4153 + * receive in progress - released in callback
4155 + ret = mutex_lock_interruptible(&instance->bulk_mutex);
4159 + /* zero length indicates this was a dummy transfer */
4160 + msg_context->u.bulk.buffer_used = 0;
4162 + /* queue the bulk submission */
4163 + vchi_service_use(instance->handle);
4165 + ret = vchi_bulk_queue_receive(instance->handle,
4166 + instance->bulk_scratch,
4168 + VCHI_FLAGS_CALLBACK_WHEN_OP_COMPLETE |
4169 + VCHI_FLAGS_BLOCK_UNTIL_QUEUED,
4172 + vchi_service_release(instance->handle);
4175 + /* callback will not be clearing the mutex */
4176 + mutex_unlock(&instance->bulk_mutex);
4182 +/* data in message, memcpy from packet into output buffer */
4183 +static int inline_receive(struct vchiq_mmal_instance *instance,
4184 + struct mmal_msg *msg,
4185 + struct mmal_msg_context *msg_context)
4187 + unsigned long flags = 0;
4189 + /* take buffer from queue */
4190 + spin_lock_irqsave(&msg_context->u.bulk.port->slock, flags);
4191 + if (list_empty(&msg_context->u.bulk.port->buffers)) {
4192 + spin_unlock_irqrestore(&msg_context->u.bulk.port->slock, flags);
4193 + pr_err("buffer list empty trying to receive inline\n");
4195 + /* todo: this is a serious error, we should never have
4196 + * commited a buffer_to_host operation to the mmal
4197 + * port without the buffer to back it up (with
4198 + * underflow handling) and there is no obvious way to
4199 + * deal with this. Less bad than the bulk case as we
4200 + * can just drop this on the floor but...unhelpful
4205 + msg_context->u.bulk.buffer =
4206 + list_entry(msg_context->u.bulk.port->buffers.next,
4207 + struct mmal_buffer, list);
4208 + list_del(&msg_context->u.bulk.buffer->list);
4210 + spin_unlock_irqrestore(&msg_context->u.bulk.port->slock, flags);
4212 + memcpy(msg_context->u.bulk.buffer->buffer,
4213 + msg->u.buffer_from_host.short_data,
4214 + msg->u.buffer_from_host.payload_in_message);
4216 + msg_context->u.bulk.buffer_used =
4217 + msg->u.buffer_from_host.payload_in_message;
4222 +/* queue the buffer availability with MMAL_MSG_TYPE_BUFFER_FROM_HOST */
4224 +buffer_from_host(struct vchiq_mmal_instance *instance,
4225 + struct vchiq_mmal_port *port, struct mmal_buffer *buf)
4227 + struct mmal_msg_context *msg_context;
4228 + struct mmal_msg m;
4231 + pr_debug("instance:%p buffer:%p\n", instance->handle, buf);
4233 + /* bulk mutex stops other bulk operations while we
4234 + * have a receive in progress
4236 + if (mutex_lock_interruptible(&instance->bulk_mutex))
4240 + msg_context = get_msg_context(instance);
4241 + if (msg_context == NULL)
4244 + /* store bulk message context for when data arrives */
4245 + msg_context->u.bulk.instance = instance;
4246 + msg_context->u.bulk.port = port;
4247 + msg_context->u.bulk.buffer = NULL; /* not valid until bulk xfer */
4248 + msg_context->u.bulk.buffer_used = 0;
4250 + /* initialise work structure ready to schedule callback */
4251 + INIT_WORK(&msg_context->u.bulk.work, buffer_work_cb);
4253 + /* prep the buffer from host message */
4254 + memset(&m, 0xbc, sizeof(m)); /* just to make debug clearer */
4256 + m.h.type = MMAL_MSG_TYPE_BUFFER_FROM_HOST;
4257 + m.h.magic = MMAL_MAGIC;
4258 + m.h.context = msg_context;
4261 + /* drvbuf is our private data passed back */
4262 + m.u.buffer_from_host.drvbuf.magic = MMAL_MAGIC;
4263 + m.u.buffer_from_host.drvbuf.component_handle = port->component->handle;
4264 + m.u.buffer_from_host.drvbuf.port_handle = port->handle;
4265 + m.u.buffer_from_host.drvbuf.client_context = msg_context;
4267 + /* buffer header */
4268 + m.u.buffer_from_host.buffer_header.cmd = 0;
4269 + m.u.buffer_from_host.buffer_header.data = buf->buffer;
4270 + m.u.buffer_from_host.buffer_header.alloc_size = buf->buffer_size;
4271 + m.u.buffer_from_host.buffer_header.length = 0; /* nothing used yet */
4272 + m.u.buffer_from_host.buffer_header.offset = 0; /* no offset */
4273 + m.u.buffer_from_host.buffer_header.flags = 0; /* no flags */
4274 + m.u.buffer_from_host.buffer_header.pts = MMAL_TIME_UNKNOWN;
4275 + m.u.buffer_from_host.buffer_header.dts = MMAL_TIME_UNKNOWN;
4277 + /* clear buffer type sepecific data */
4278 + memset(&m.u.buffer_from_host.buffer_header_type_specific, 0,
4279 + sizeof(m.u.buffer_from_host.buffer_header_type_specific));
4281 + /* no payload in message */
4282 + m.u.buffer_from_host.payload_in_message = 0;
4284 + vchi_service_use(instance->handle);
4286 + ret = vchi_msg_queue(instance->handle, &m,
4287 + sizeof(struct mmal_msg_header) +
4288 + sizeof(m.u.buffer_from_host),
4289 + VCHI_FLAGS_BLOCK_UNTIL_QUEUED, NULL);
4292 + release_msg_context(msg_context);
4293 + /* todo: is this correct error value? */
4296 + vchi_service_release(instance->handle);
4298 + mutex_unlock(&instance->bulk_mutex);
4303 +/* submit a buffer to the mmal sevice
4305 + * the buffer_from_host uses size data from the ports next available
4306 + * mmal_buffer and deals with there being no buffer available by
4307 + * incrementing the underflow for later
4309 +static int port_buffer_from_host(struct vchiq_mmal_instance *instance,
4310 + struct vchiq_mmal_port *port)
4313 + struct mmal_buffer *buf;
4314 + unsigned long flags = 0;
4316 + if (!port->enabled)
4319 + /* peek buffer from queue */
4320 + spin_lock_irqsave(&port->slock, flags);
4321 + if (list_empty(&port->buffers)) {
4322 + port->buffer_underflow++;
4323 + spin_unlock_irqrestore(&port->slock, flags);
4327 + buf = list_entry(port->buffers.next, struct mmal_buffer, list);
4329 + spin_unlock_irqrestore(&port->slock, flags);
4331 + /* issue buffer to mmal service */
4332 + ret = buffer_from_host(instance, port, buf);
4334 + pr_err("adding buffer header failed\n");
4335 + /* todo: how should this be dealt with */
4341 +/* deals with receipt of buffer to host message */
4342 +static void buffer_to_host_cb(struct vchiq_mmal_instance *instance,
4343 + struct mmal_msg *msg, u32 msg_len)
4345 + struct mmal_msg_context *msg_context;
4347 + pr_debug("buffer_to_host_cb: instance:%p msg:%p msg_len:%d\n",
4348 + instance, msg, msg_len);
4350 + if (msg->u.buffer_from_host.drvbuf.magic == MMAL_MAGIC) {
4351 + msg_context = msg->u.buffer_from_host.drvbuf.client_context;
4353 + pr_err("MMAL_MSG_TYPE_BUFFER_TO_HOST with bad magic\n");
4357 + if (msg->h.status != MMAL_MSG_STATUS_SUCCESS) {
4358 + /* message reception had an error */
4359 + pr_warn("error %d in reply\n", msg->h.status);
4361 + msg_context->u.bulk.status = msg->h.status;
4363 + } else if (msg->u.buffer_from_host.buffer_header.length == 0) {
4364 + /* empty buffer */
4365 + if (msg->u.buffer_from_host.buffer_header.flags &
4366 + MMAL_BUFFER_HEADER_FLAG_EOS) {
4367 + msg_context->u.bulk.status =
4368 + dummy_bulk_receive(instance, msg_context);
4369 + if (msg_context->u.bulk.status == 0)
4370 + return; /* successful bulk submission, bulk
4371 + * completion will trigger callback
4374 + /* do callback with empty buffer - not EOS though */
4375 + msg_context->u.bulk.status = 0;
4376 + msg_context->u.bulk.buffer_used = 0;
4378 + } else if (msg->u.buffer_from_host.payload_in_message == 0) {
4379 + /* data is not in message, queue a bulk receive */
4380 + msg_context->u.bulk.status =
4381 + bulk_receive(instance, msg, msg_context);
4382 + if (msg_context->u.bulk.status == 0)
4383 + return; /* successful bulk submission, bulk
4384 + * completion will trigger callback
4387 + /* failed to submit buffer, this will end badly */
4388 + pr_err("error %d on bulk submission\n",
4389 + msg_context->u.bulk.status);
4391 + } else if (msg->u.buffer_from_host.payload_in_message <=
4392 + MMAL_VC_SHORT_DATA) {
4393 + /* data payload within message */
4394 + msg_context->u.bulk.status = inline_receive(instance, msg,
4397 + pr_err("message with invalid short payload\n");
4399 + /* signal error */
4400 + msg_context->u.bulk.status = -EINVAL;
4401 + msg_context->u.bulk.buffer_used =
4402 + msg->u.buffer_from_host.payload_in_message;
4405 + /* replace the buffer header */
4406 + port_buffer_from_host(instance, msg_context->u.bulk.port);
4408 + /* schedule the port callback */
4409 + schedule_work(&msg_context->u.bulk.work);
4412 +static void bulk_receive_cb(struct vchiq_mmal_instance *instance,
4413 + struct mmal_msg_context *msg_context)
4415 + /* bulk receive operation complete */
4416 + mutex_unlock(&msg_context->u.bulk.instance->bulk_mutex);
4418 + /* replace the buffer header */
4419 + port_buffer_from_host(msg_context->u.bulk.instance,
4420 + msg_context->u.bulk.port);
4422 + msg_context->u.bulk.status = 0;
4424 + /* schedule the port callback */
4425 + schedule_work(&msg_context->u.bulk.work);
4428 +static void bulk_abort_cb(struct vchiq_mmal_instance *instance,
4429 + struct mmal_msg_context *msg_context)
4431 + pr_err("%s: bulk ABORTED msg_context:%p\n", __func__, msg_context);
4433 + /* bulk receive operation complete */
4434 + mutex_unlock(&msg_context->u.bulk.instance->bulk_mutex);
4436 + /* replace the buffer header */
4437 + port_buffer_from_host(msg_context->u.bulk.instance,
4438 + msg_context->u.bulk.port);
4440 + msg_context->u.bulk.status = -EINTR;
4442 + schedule_work(&msg_context->u.bulk.work);
4445 +/* incoming event service callback */
4446 +static void service_callback(void *param,
4447 + const VCHI_CALLBACK_REASON_T reason,
4450 + struct vchiq_mmal_instance *instance = param;
4453 + struct mmal_msg *msg;
4454 + VCHI_HELD_MSG_T msg_handle;
4457 + pr_err("Message callback passed NULL instance\n");
4462 + case VCHI_CALLBACK_MSG_AVAILABLE:
4463 + status = vchi_msg_hold(instance->handle, (void **)&msg,
4464 + &msg_len, VCHI_FLAGS_NONE, &msg_handle);
4466 + pr_err("Unable to dequeue a message (%d)\n", status);
4470 + DBG_DUMP_MSG(msg, msg_len, "<<< reply message");
4472 + /* handling is different for buffer messages */
4473 + switch (msg->h.type) {
4475 + case MMAL_MSG_TYPE_BUFFER_FROM_HOST:
4476 + vchi_held_msg_release(&msg_handle);
4479 + case MMAL_MSG_TYPE_EVENT_TO_HOST:
4480 + event_to_host_cb(instance, msg, msg_len);
4481 + vchi_held_msg_release(&msg_handle);
4485 + case MMAL_MSG_TYPE_BUFFER_TO_HOST:
4486 + buffer_to_host_cb(instance, msg, msg_len);
4487 + vchi_held_msg_release(&msg_handle);
4491 + /* messages dependant on header context to complete */
4493 + /* todo: the msg.context really ought to be sanity
4494 + * checked before we just use it, afaict it comes back
4495 + * and is used raw from the videocore. Perhaps it
4496 + * should be verified the address lies in the kernel
4499 + if (msg->h.context == NULL) {
4500 + pr_err("received message context was null!\n");
4501 + vchi_held_msg_release(&msg_handle);
4505 + /* fill in context values */
4506 + msg->h.context->u.sync.msg_handle = msg_handle;
4507 + msg->h.context->u.sync.msg = msg;
4508 + msg->h.context->u.sync.msg_len = msg_len;
4510 + /* todo: should this check (completion_done()
4511 + * == 1) for no one waiting? or do we need a
4512 + * flag to tell us the completion has been
4513 + * interrupted so we can free the message and
4514 + * its context. This probably also solves the
4515 + * message arriving after interruption todo
4519 + /* complete message so caller knows it happened */
4520 + complete(&msg->h.context->u.sync.cmplt);
4526 + case VCHI_CALLBACK_BULK_RECEIVED:
4527 + bulk_receive_cb(instance, bulk_ctx);
4530 + case VCHI_CALLBACK_BULK_RECEIVE_ABORTED:
4531 + bulk_abort_cb(instance, bulk_ctx);
4534 + case VCHI_CALLBACK_SERVICE_CLOSED:
4535 + /* TODO: consider if this requires action if received when
4536 + * driver is not explicitly closing the service
4541 + pr_err("Received unhandled message reason %d\n", reason);
4546 +static int send_synchronous_mmal_msg(struct vchiq_mmal_instance *instance,
4547 + struct mmal_msg *msg,
4548 + unsigned int payload_len,
4549 + struct mmal_msg **msg_out,
4550 + VCHI_HELD_MSG_T *msg_handle_out)
4552 + struct mmal_msg_context msg_context;
4555 + /* payload size must not cause message to exceed max size */
4557 + (MMAL_MSG_MAX_SIZE - sizeof(struct mmal_msg_header))) {
4558 + pr_err("payload length %d exceeds max:%d\n", payload_len,
4559 + (MMAL_MSG_MAX_SIZE - sizeof(struct mmal_msg_header)));
4563 + init_completion(&msg_context.u.sync.cmplt);
4565 + msg->h.magic = MMAL_MAGIC;
4566 + msg->h.context = &msg_context;
4567 + msg->h.status = 0;
4569 + DBG_DUMP_MSG(msg, (sizeof(struct mmal_msg_header) + payload_len),
4570 + ">>> sync message");
4572 + vchi_service_use(instance->handle);
4574 + ret = vchi_msg_queue(instance->handle,
4576 + sizeof(struct mmal_msg_header) + payload_len,
4577 + VCHI_FLAGS_BLOCK_UNTIL_QUEUED, NULL);
4579 + vchi_service_release(instance->handle);
4582 + pr_err("error %d queuing message\n", ret);
4586 + ret = wait_for_completion_timeout(&msg_context.u.sync.cmplt, HZ);
4588 + pr_err("error %d waiting for sync completion\n", ret);
4591 + /* todo: what happens if the message arrives after aborting */
4595 + *msg_out = msg_context.u.sync.msg;
4596 + *msg_handle_out = msg_context.u.sync.msg_handle;
4601 +static void dump_port_info(struct vchiq_mmal_port *port)
4603 + pr_debug("port handle:0x%x enabled:%d\n", port->handle, port->enabled);
4605 + pr_debug("buffer minimum num:%d size:%d align:%d\n",
4606 + port->minimum_buffer.num,
4607 + port->minimum_buffer.size, port->minimum_buffer.alignment);
4609 + pr_debug("buffer recommended num:%d size:%d align:%d\n",
4610 + port->recommended_buffer.num,
4611 + port->recommended_buffer.size,
4612 + port->recommended_buffer.alignment);
4614 + pr_debug("buffer current values num:%d size:%d align:%d\n",
4615 + port->current_buffer.num,
4616 + port->current_buffer.size, port->current_buffer.alignment);
4618 + pr_debug("elementry stream: type:%d encoding:0x%x varient:0x%x\n",
4619 + port->format.type,
4620 + port->format.encoding, port->format.encoding_variant);
4622 + pr_debug(" bitrate:%d flags:0x%x\n",
4623 + port->format.bitrate, port->format.flags);
4625 + if (port->format.type == MMAL_ES_TYPE_VIDEO) {
4627 + ("es video format: width:%d height:%d colourspace:0x%x\n",
4628 + port->es.video.width, port->es.video.height,
4629 + port->es.video.color_space);
4631 + pr_debug(" : crop xywh %d,%d,%d,%d\n",
4632 + port->es.video.crop.x,
4633 + port->es.video.crop.y,
4634 + port->es.video.crop.width, port->es.video.crop.height);
4635 + pr_debug(" : framerate %d/%d aspect %d/%d\n",
4636 + port->es.video.frame_rate.num,
4637 + port->es.video.frame_rate.den,
4638 + port->es.video.par.num, port->es.video.par.den);
4642 +static void port_to_mmal_msg(struct vchiq_mmal_port *port, struct mmal_port *p)
4645 + /* todo do readonly fields need setting at all? */
4646 + p->type = port->type;
4647 + p->index = port->index;
4649 + p->is_enabled = port->enabled;
4650 + p->buffer_num_min = port->minimum_buffer.num;
4651 + p->buffer_size_min = port->minimum_buffer.size;
4652 + p->buffer_alignment_min = port->minimum_buffer.alignment;
4653 + p->buffer_num_recommended = port->recommended_buffer.num;
4654 + p->buffer_size_recommended = port->recommended_buffer.size;
4656 + /* only three writable fields in a port */
4657 + p->buffer_num = port->current_buffer.num;
4658 + p->buffer_size = port->current_buffer.size;
4659 + p->userdata = port;
4662 +static int port_info_set(struct vchiq_mmal_instance *instance,
4663 + struct vchiq_mmal_port *port)
4666 + struct mmal_msg m;
4667 + struct mmal_msg *rmsg;
4668 + VCHI_HELD_MSG_T rmsg_handle;
4670 + pr_debug("setting port info port %p\n", port);
4673 + dump_port_info(port);
4675 + m.h.type = MMAL_MSG_TYPE_PORT_INFO_SET;
4677 + m.u.port_info_set.component_handle = port->component->handle;
4678 + m.u.port_info_set.port_type = port->type;
4679 + m.u.port_info_set.port_index = port->index;
4681 + port_to_mmal_msg(port, &m.u.port_info_set.port);
4683 + /* elementry stream format setup */
4684 + m.u.port_info_set.format.type = port->format.type;
4685 + m.u.port_info_set.format.encoding = port->format.encoding;
4686 + m.u.port_info_set.format.encoding_variant =
4687 + port->format.encoding_variant;
4688 + m.u.port_info_set.format.bitrate = port->format.bitrate;
4689 + m.u.port_info_set.format.flags = port->format.flags;
4691 + memcpy(&m.u.port_info_set.es, &port->es,
4692 + sizeof(union mmal_es_specific_format));
4694 + m.u.port_info_set.format.extradata_size = port->format.extradata_size;
4695 + memcpy(rmsg->u.port_info_set.extradata, port->format.extradata,
4696 + port->format.extradata_size);
4698 + ret = send_synchronous_mmal_msg(instance, &m,
4699 + sizeof(m.u.port_info_set),
4700 + &rmsg, &rmsg_handle);
4704 + if (rmsg->h.type != MMAL_MSG_TYPE_PORT_INFO_SET) {
4705 + /* got an unexpected message type in reply */
4710 + /* return operation status */
4711 + ret = -rmsg->u.port_info_get_reply.status;
4713 + pr_debug("%s:result:%d component:0x%x port:%d\n", __func__, ret,
4714 + port->component->handle, port->handle);
4717 + vchi_held_msg_release(&rmsg_handle);
4723 +/* use port info get message to retrive port information */
4724 +static int port_info_get(struct vchiq_mmal_instance *instance,
4725 + struct vchiq_mmal_port *port)
4728 + struct mmal_msg m;
4729 + struct mmal_msg *rmsg;
4730 + VCHI_HELD_MSG_T rmsg_handle;
4732 + /* port info time */
4733 + m.h.type = MMAL_MSG_TYPE_PORT_INFO_GET;
4734 + m.u.port_info_get.component_handle = port->component->handle;
4735 + m.u.port_info_get.port_type = port->type;
4736 + m.u.port_info_get.index = port->index;
4738 + ret = send_synchronous_mmal_msg(instance, &m,
4739 + sizeof(m.u.port_info_get),
4740 + &rmsg, &rmsg_handle);
4744 + if (rmsg->h.type != MMAL_MSG_TYPE_PORT_INFO_GET) {
4745 + /* got an unexpected message type in reply */
4750 + /* return operation status */
4751 + ret = -rmsg->u.port_info_get_reply.status;
4752 + if (ret != MMAL_MSG_STATUS_SUCCESS)
4755 + if (rmsg->u.port_info_get_reply.port.is_enabled == 0)
4756 + port->enabled = false;
4758 + port->enabled = true;
4760 + /* copy the values out of the message */
4761 + port->handle = rmsg->u.port_info_get_reply.port_handle;
4763 + /* port type and index cached to use on port info set becuase
4764 + * it does not use a port handle
4766 + port->type = rmsg->u.port_info_get_reply.port_type;
4767 + port->index = rmsg->u.port_info_get_reply.port_index;
4769 + port->minimum_buffer.num =
4770 + rmsg->u.port_info_get_reply.port.buffer_num_min;
4771 + port->minimum_buffer.size =
4772 + rmsg->u.port_info_get_reply.port.buffer_size_min;
4773 + port->minimum_buffer.alignment =
4774 + rmsg->u.port_info_get_reply.port.buffer_alignment_min;
4776 + port->recommended_buffer.alignment =
4777 + rmsg->u.port_info_get_reply.port.buffer_alignment_min;
4778 + port->recommended_buffer.num =
4779 + rmsg->u.port_info_get_reply.port.buffer_num_recommended;
4781 + port->current_buffer.num = rmsg->u.port_info_get_reply.port.buffer_num;
4782 + port->current_buffer.size =
4783 + rmsg->u.port_info_get_reply.port.buffer_size;
4785 + /* stream format */
4786 + port->format.type = rmsg->u.port_info_get_reply.format.type;
4787 + port->format.encoding = rmsg->u.port_info_get_reply.format.encoding;
4788 + port->format.encoding_variant =
4789 + rmsg->u.port_info_get_reply.format.encoding_variant;
4790 + port->format.bitrate = rmsg->u.port_info_get_reply.format.bitrate;
4791 + port->format.flags = rmsg->u.port_info_get_reply.format.flags;
4793 + /* elementry stream format */
4795 + &rmsg->u.port_info_get_reply.es,
4796 + sizeof(union mmal_es_specific_format));
4797 + port->format.es = &port->es;
4799 + port->format.extradata_size =
4800 + rmsg->u.port_info_get_reply.format.extradata_size;
4801 + memcpy(port->format.extradata,
4802 + rmsg->u.port_info_get_reply.extradata,
4803 + port->format.extradata_size);
4805 + pr_debug("received port info\n");
4806 + dump_port_info(port);
4810 + pr_debug("%s:result:%d component:0x%x port:%d\n",
4811 + __func__, ret, port->component->handle, port->handle);
4813 + vchi_held_msg_release(&rmsg_handle);
4818 +/* create comonent on vc */
4819 +static int create_component(struct vchiq_mmal_instance *instance,
4820 + struct vchiq_mmal_component *component,
4824 + struct mmal_msg m;
4825 + struct mmal_msg *rmsg;
4826 + VCHI_HELD_MSG_T rmsg_handle;
4828 + /* build component create message */
4829 + m.h.type = MMAL_MSG_TYPE_COMPONENT_CREATE;
4830 + m.u.component_create.client_component = component;
4831 + strncpy(m.u.component_create.name, name,
4832 + sizeof(m.u.component_create.name));
4834 + ret = send_synchronous_mmal_msg(instance, &m,
4835 + sizeof(m.u.component_create),
4836 + &rmsg, &rmsg_handle);
4840 + if (rmsg->h.type != m.h.type) {
4841 + /* got an unexpected message type in reply */
4846 + ret = -rmsg->u.component_create_reply.status;
4847 + if (ret != MMAL_MSG_STATUS_SUCCESS)
4850 + /* a valid component response received */
4851 + component->handle = rmsg->u.component_create_reply.component_handle;
4852 + component->inputs = rmsg->u.component_create_reply.input_num;
4853 + component->outputs = rmsg->u.component_create_reply.output_num;
4854 + component->clocks = rmsg->u.component_create_reply.clock_num;
4856 + pr_debug("Component handle:0x%x in:%d out:%d clock:%d\n",
4857 + component->handle,
4858 + component->inputs, component->outputs, component->clocks);
4861 + vchi_held_msg_release(&rmsg_handle);
4866 +/* destroys a component on vc */
4867 +static int destroy_component(struct vchiq_mmal_instance *instance,
4868 + struct vchiq_mmal_component *component)
4871 + struct mmal_msg m;
4872 + struct mmal_msg *rmsg;
4873 + VCHI_HELD_MSG_T rmsg_handle;
4875 + m.h.type = MMAL_MSG_TYPE_COMPONENT_DESTROY;
4876 + m.u.component_destroy.component_handle = component->handle;
4878 + ret = send_synchronous_mmal_msg(instance, &m,
4879 + sizeof(m.u.component_destroy),
4880 + &rmsg, &rmsg_handle);
4884 + if (rmsg->h.type != m.h.type) {
4885 + /* got an unexpected message type in reply */
4890 + ret = -rmsg->u.component_destroy_reply.status;
4894 + vchi_held_msg_release(&rmsg_handle);
4899 +/* enable a component on vc */
4900 +static int enable_component(struct vchiq_mmal_instance *instance,
4901 + struct vchiq_mmal_component *component)
4904 + struct mmal_msg m;
4905 + struct mmal_msg *rmsg;
4906 + VCHI_HELD_MSG_T rmsg_handle;
4908 + m.h.type = MMAL_MSG_TYPE_COMPONENT_ENABLE;
4909 + m.u.component_enable.component_handle = component->handle;
4911 + ret = send_synchronous_mmal_msg(instance, &m,
4912 + sizeof(m.u.component_enable),
4913 + &rmsg, &rmsg_handle);
4917 + if (rmsg->h.type != m.h.type) {
4918 + /* got an unexpected message type in reply */
4923 + ret = -rmsg->u.component_enable_reply.status;
4926 + vchi_held_msg_release(&rmsg_handle);
4931 +/* disable a component on vc */
4932 +static int disable_component(struct vchiq_mmal_instance *instance,
4933 + struct vchiq_mmal_component *component)
4936 + struct mmal_msg m;
4937 + struct mmal_msg *rmsg;
4938 + VCHI_HELD_MSG_T rmsg_handle;
4940 + m.h.type = MMAL_MSG_TYPE_COMPONENT_DISABLE;
4941 + m.u.component_disable.component_handle = component->handle;
4943 + ret = send_synchronous_mmal_msg(instance, &m,
4944 + sizeof(m.u.component_disable),
4945 + &rmsg, &rmsg_handle);
4949 + if (rmsg->h.type != m.h.type) {
4950 + /* got an unexpected message type in reply */
4955 + ret = -rmsg->u.component_disable_reply.status;
4959 + vchi_held_msg_release(&rmsg_handle);
4964 +/* get version of mmal implementation */
4965 +static int get_version(struct vchiq_mmal_instance *instance,
4966 + u32 *major_out, u32 *minor_out)
4969 + struct mmal_msg m;
4970 + struct mmal_msg *rmsg;
4971 + VCHI_HELD_MSG_T rmsg_handle;
4973 + m.h.type = MMAL_MSG_TYPE_GET_VERSION;
4975 + ret = send_synchronous_mmal_msg(instance, &m,
4976 + sizeof(m.u.version),
4977 + &rmsg, &rmsg_handle);
4981 + if (rmsg->h.type != m.h.type) {
4982 + /* got an unexpected message type in reply */
4987 + *major_out = rmsg->u.version.major;
4988 + *minor_out = rmsg->u.version.minor;
4991 + vchi_held_msg_release(&rmsg_handle);
4996 +/* do a port action with a port as a parameter */
4997 +static int port_action_port(struct vchiq_mmal_instance *instance,
4998 + struct vchiq_mmal_port *port,
4999 + enum mmal_msg_port_action_type action_type)
5002 + struct mmal_msg m;
5003 + struct mmal_msg *rmsg;
5004 + VCHI_HELD_MSG_T rmsg_handle;
5006 + m.h.type = MMAL_MSG_TYPE_PORT_ACTION;
5007 + m.u.port_action_port.component_handle = port->component->handle;
5008 + m.u.port_action_port.port_handle = port->handle;
5009 + m.u.port_action_port.action = action_type;
5011 + port_to_mmal_msg(port, &m.u.port_action_port.port);
5013 + ret = send_synchronous_mmal_msg(instance, &m,
5014 + sizeof(m.u.port_action_port),
5015 + &rmsg, &rmsg_handle);
5019 + if (rmsg->h.type != MMAL_MSG_TYPE_PORT_ACTION) {
5020 + /* got an unexpected message type in reply */
5025 + ret = -rmsg->u.port_action_reply.status;
5027 + pr_debug("%s:result:%d component:0x%x port:%d action:%s(%d)\n",
5029 + ret, port->component->handle, port->handle,
5030 + port_action_type_names[action_type], action_type);
5033 + vchi_held_msg_release(&rmsg_handle);
5038 +/* do a port action with handles as parameters */
5039 +static int port_action_handle(struct vchiq_mmal_instance *instance,
5040 + struct vchiq_mmal_port *port,
5041 + enum mmal_msg_port_action_type action_type,
5042 + u32 connect_component_handle,
5043 + u32 connect_port_handle)
5046 + struct mmal_msg m;
5047 + struct mmal_msg *rmsg;
5048 + VCHI_HELD_MSG_T rmsg_handle;
5050 + m.h.type = MMAL_MSG_TYPE_PORT_ACTION;
5052 + m.u.port_action_handle.component_handle = port->component->handle;
5053 + m.u.port_action_handle.port_handle = port->handle;
5054 + m.u.port_action_handle.action = action_type;
5056 + m.u.port_action_handle.connect_component_handle =
5057 + connect_component_handle;
5058 + m.u.port_action_handle.connect_port_handle = connect_port_handle;
5060 + ret = send_synchronous_mmal_msg(instance, &m,
5061 + sizeof(m.u.port_action_handle),
5062 + &rmsg, &rmsg_handle);
5066 + if (rmsg->h.type != MMAL_MSG_TYPE_PORT_ACTION) {
5067 + /* got an unexpected message type in reply */
5072 + ret = -rmsg->u.port_action_reply.status;
5074 + pr_debug("%s:result:%d component:0x%x port:%d action:%s(%d)" \
5075 + " connect component:0x%x connect port:%d\n",
5077 + ret, port->component->handle, port->handle,
5078 + port_action_type_names[action_type],
5079 + action_type, connect_component_handle, connect_port_handle);
5082 + vchi_held_msg_release(&rmsg_handle);
5087 +static int port_parameter_set(struct vchiq_mmal_instance *instance,
5088 + struct vchiq_mmal_port *port,
5089 + u32 parameter_id, void *value, u32 value_size)
5092 + struct mmal_msg m;
5093 + struct mmal_msg *rmsg;
5094 + VCHI_HELD_MSG_T rmsg_handle;
5096 + m.h.type = MMAL_MSG_TYPE_PORT_PARAMETER_SET;
5098 + m.u.port_parameter_set.component_handle = port->component->handle;
5099 + m.u.port_parameter_set.port_handle = port->handle;
5100 + m.u.port_parameter_set.id = parameter_id;
5101 + m.u.port_parameter_set.size = (2 * sizeof(u32)) + value_size;
5102 + memcpy(&m.u.port_parameter_set.value, value, value_size);
5104 + ret = send_synchronous_mmal_msg(instance, &m,
5105 + (4 * sizeof(u32)) + value_size,
5106 + &rmsg, &rmsg_handle);
5110 + if (rmsg->h.type != MMAL_MSG_TYPE_PORT_PARAMETER_SET) {
5111 + /* got an unexpected message type in reply */
5116 + ret = -rmsg->u.port_parameter_set_reply.status;
5118 + pr_debug("%s:result:%d component:0x%x port:%d parameter:%d\n",
5120 + ret, port->component->handle, port->handle, parameter_id);
5123 + vchi_held_msg_release(&rmsg_handle);
5128 +static int port_parameter_get(struct vchiq_mmal_instance *instance,
5129 + struct vchiq_mmal_port *port,
5130 + u32 parameter_id, void *value, u32 *value_size)
5133 + struct mmal_msg m;
5134 + struct mmal_msg *rmsg;
5135 + VCHI_HELD_MSG_T rmsg_handle;
5137 + m.h.type = MMAL_MSG_TYPE_PORT_PARAMETER_GET;
5139 + m.u.port_parameter_get.component_handle = port->component->handle;
5140 + m.u.port_parameter_get.port_handle = port->handle;
5141 + m.u.port_parameter_get.id = parameter_id;
5142 + m.u.port_parameter_get.size = (2 * sizeof(u32)) + *value_size;
5144 + ret = send_synchronous_mmal_msg(instance, &m,
5146 + mmal_msg_port_parameter_get),
5147 + &rmsg, &rmsg_handle);
5151 + if (rmsg->h.type != MMAL_MSG_TYPE_PORT_PARAMETER_GET) {
5152 + /* got an unexpected message type in reply */
5153 + pr_err("Incorrect reply type %d\n", rmsg->h.type);
5158 + ret = -rmsg->u.port_parameter_get_reply.status;
5160 + /* Copy only as much as we have space for
5161 + * but report true size of parameter
5163 + memcpy(value, &rmsg->u.port_parameter_get_reply.value,
5165 + *value_size = rmsg->u.port_parameter_get_reply.size;
5167 + memcpy(value, &rmsg->u.port_parameter_get_reply.value,
5168 + rmsg->u.port_parameter_get_reply.size);
5170 + pr_info("%s:result:%d component:0x%x port:%d parameter:%d\n", __func__,
5171 + ret, port->component->handle, port->handle, parameter_id);
5174 + vchi_held_msg_release(&rmsg_handle);
5179 +/* disables a port and drains buffers from it */
5180 +static int port_disable(struct vchiq_mmal_instance *instance,
5181 + struct vchiq_mmal_port *port)
5184 + struct list_head *q, *buf_head;
5185 + unsigned long flags = 0;
5187 + if (!port->enabled)
5190 + port->enabled = false;
5192 + ret = port_action_port(instance, port,
5193 + MMAL_MSG_PORT_ACTION_TYPE_DISABLE);
5196 + /* drain all queued buffers on port */
5197 + spin_lock_irqsave(&port->slock, flags);
5199 + list_for_each_safe(buf_head, q, &port->buffers) {
5200 + struct mmal_buffer *mmalbuf;
5201 + mmalbuf = list_entry(buf_head, struct mmal_buffer,
5203 + list_del(buf_head);
5204 + if (port->buffer_cb)
5205 + port->buffer_cb(instance,
5206 + port, 0, mmalbuf, 0, 0,
5207 + MMAL_TIME_UNKNOWN,
5208 + MMAL_TIME_UNKNOWN);
5211 + spin_unlock_irqrestore(&port->slock, flags);
5213 + ret = port_info_get(instance, port);
5219 +/* enable a port */
5220 +static int port_enable(struct vchiq_mmal_instance *instance,
5221 + struct vchiq_mmal_port *port)
5223 + unsigned int hdr_count;
5224 + struct list_head *buf_head;
5227 + if (port->enabled)
5230 + /* ensure there are enough buffers queued to cover the buffer headers */
5231 + if (port->buffer_cb != NULL) {
5233 + list_for_each(buf_head, &port->buffers) {
5236 + if (hdr_count < port->current_buffer.num)
5240 + ret = port_action_port(instance, port,
5241 + MMAL_MSG_PORT_ACTION_TYPE_ENABLE);
5245 + port->enabled = true;
5247 + if (port->buffer_cb) {
5248 + /* send buffer headers to videocore */
5250 + list_for_each(buf_head, &port->buffers) {
5251 + struct mmal_buffer *mmalbuf;
5252 + mmalbuf = list_entry(buf_head, struct mmal_buffer,
5254 + ret = buffer_from_host(instance, port, mmalbuf);
5259 + if (hdr_count > port->current_buffer.num)
5264 + ret = port_info_get(instance, port);
5270 +/* ------------------------------------------------------------------
5272 + *------------------------------------------------------------------*/
5274 +int vchiq_mmal_port_set_format(struct vchiq_mmal_instance *instance,
5275 + struct vchiq_mmal_port *port)
5279 + if (mutex_lock_interruptible(&instance->vchiq_mutex))
5282 + ret = port_info_set(instance, port);
5284 + goto release_unlock;
5286 + /* read what has actually been set */
5287 + ret = port_info_get(instance, port);
5290 + mutex_unlock(&instance->vchiq_mutex);
5296 +int vchiq_mmal_port_parameter_set(struct vchiq_mmal_instance *instance,
5297 + struct vchiq_mmal_port *port,
5298 + u32 parameter, void *value, u32 value_size)
5302 + if (mutex_lock_interruptible(&instance->vchiq_mutex))
5305 + ret = port_parameter_set(instance, port, parameter, value, value_size);
5307 + mutex_unlock(&instance->vchiq_mutex);
5312 +int vchiq_mmal_port_parameter_get(struct vchiq_mmal_instance *instance,
5313 + struct vchiq_mmal_port *port,
5314 + u32 parameter, void *value, u32 *value_size)
5318 + if (mutex_lock_interruptible(&instance->vchiq_mutex))
5321 + ret = port_parameter_get(instance, port, parameter, value, value_size);
5323 + mutex_unlock(&instance->vchiq_mutex);
5330 + * enables a port and queues buffers for satisfying callbacks if we
5331 + * provide a callback handler
5333 +int vchiq_mmal_port_enable(struct vchiq_mmal_instance *instance,
5334 + struct vchiq_mmal_port *port,
5335 + vchiq_mmal_buffer_cb buffer_cb)
5339 + if (mutex_lock_interruptible(&instance->vchiq_mutex))
5342 + /* already enabled - noop */
5343 + if (port->enabled) {
5348 + port->buffer_cb = buffer_cb;
5350 + ret = port_enable(instance, port);
5353 + mutex_unlock(&instance->vchiq_mutex);
5358 +int vchiq_mmal_port_disable(struct vchiq_mmal_instance *instance,
5359 + struct vchiq_mmal_port *port)
5363 + if (mutex_lock_interruptible(&instance->vchiq_mutex))
5366 + if (!port->enabled) {
5367 + mutex_unlock(&instance->vchiq_mutex);
5371 + ret = port_disable(instance, port);
5373 + mutex_unlock(&instance->vchiq_mutex);
5378 +/* ports will be connected in a tunneled manner so data buffers
5379 + * are not handled by client.
5381 +int vchiq_mmal_port_connect_tunnel(struct vchiq_mmal_instance *instance,
5382 + struct vchiq_mmal_port *src,
5383 + struct vchiq_mmal_port *dst)
5387 + if (mutex_lock_interruptible(&instance->vchiq_mutex))
5390 + /* disconnect ports if connected */
5391 + if (src->connected != NULL) {
5392 + ret = port_disable(instance, src);
5394 + pr_err("failed disabling src port(%d)\n", ret);
5395 + goto release_unlock;
5398 + /* do not need to disable the destination port as they
5399 + * are connected and it is done automatically
5402 + ret = port_action_handle(instance, src,
5403 + MMAL_MSG_PORT_ACTION_TYPE_DISCONNECT,
5404 + src->connected->component->handle,
5405 + src->connected->handle);
5407 + pr_err("failed disconnecting src port\n");
5408 + goto release_unlock;
5410 + src->connected->enabled = false;
5411 + src->connected = NULL;
5414 + if (dst == NULL) {
5415 + /* do not make new connection */
5417 + pr_debug("not making new connection\n");
5418 + goto release_unlock;
5421 + /* copy src port format to dst */
5422 + dst->format.encoding = src->format.encoding;
5423 + dst->es.video.width = src->es.video.width;
5424 + dst->es.video.height = src->es.video.height;
5425 + dst->es.video.crop.x = src->es.video.crop.x;
5426 + dst->es.video.crop.y = src->es.video.crop.y;
5427 + dst->es.video.crop.width = src->es.video.crop.width;
5428 + dst->es.video.crop.height = src->es.video.crop.height;
5429 + dst->es.video.frame_rate.num = src->es.video.frame_rate.num;
5430 + dst->es.video.frame_rate.den = src->es.video.frame_rate.den;
5432 + /* set new format */
5433 + ret = port_info_set(instance, dst);
5435 + pr_debug("setting port info failed\n");
5436 + goto release_unlock;
5439 + /* read what has actually been set */
5440 + ret = port_info_get(instance, dst);
5442 + pr_debug("read back port info failed\n");
5443 + goto release_unlock;
5446 + /* connect two ports together */
5447 + ret = port_action_handle(instance, src,
5448 + MMAL_MSG_PORT_ACTION_TYPE_CONNECT,
5449 + dst->component->handle, dst->handle);
5451 + pr_debug("connecting port %d:%d to %d:%d failed\n",
5452 + src->component->handle, src->handle,
5453 + dst->component->handle, dst->handle);
5454 + goto release_unlock;
5456 + src->connected = dst;
5460 + mutex_unlock(&instance->vchiq_mutex);
5465 +int vchiq_mmal_submit_buffer(struct vchiq_mmal_instance *instance,
5466 + struct vchiq_mmal_port *port,
5467 + struct mmal_buffer *buffer)
5469 + unsigned long flags = 0;
5471 + spin_lock_irqsave(&port->slock, flags);
5472 + list_add_tail(&buffer->list, &port->buffers);
5473 + spin_unlock_irqrestore(&port->slock, flags);
5475 + /* the port previously underflowed because it was missing a
5476 + * mmal_buffer which has just been added, submit that buffer
5477 + * to the mmal service.
5479 + if (port->buffer_underflow) {
5480 + port_buffer_from_host(instance, port);
5481 + port->buffer_underflow--;
5487 +/* Initialise a mmal component and its ports
5490 +int vchiq_mmal_component_init(struct vchiq_mmal_instance *instance,
5492 + struct vchiq_mmal_component **component_out)
5495 + int idx; /* port index */
5496 + struct vchiq_mmal_component *component;
5498 + if (mutex_lock_interruptible(&instance->vchiq_mutex))
5501 + if (instance->component_idx == VCHIQ_MMAL_MAX_COMPONENTS) {
5502 + ret = -EINVAL; /* todo is this correct error? */
5506 + component = &instance->component[instance->component_idx];
5508 + ret = create_component(instance, component, name);
5512 + /* ports info needs gathering */
5513 + component->control.type = MMAL_PORT_TYPE_CONTROL;
5514 + component->control.index = 0;
5515 + component->control.component = component;
5516 + spin_lock_init(&component->control.slock);
5517 + INIT_LIST_HEAD(&component->control.buffers);
5518 + ret = port_info_get(instance, &component->control);
5520 + goto release_component;
5522 + for (idx = 0; idx < component->inputs; idx++) {
5523 + component->input[idx].type = MMAL_PORT_TYPE_INPUT;
5524 + component->input[idx].index = idx;
5525 + component->input[idx].component = component;
5526 + spin_lock_init(&component->input[idx].slock);
5527 + INIT_LIST_HEAD(&component->input[idx].buffers);
5528 + ret = port_info_get(instance, &component->input[idx]);
5530 + goto release_component;
5533 + for (idx = 0; idx < component->outputs; idx++) {
5534 + component->output[idx].type = MMAL_PORT_TYPE_OUTPUT;
5535 + component->output[idx].index = idx;
5536 + component->output[idx].component = component;
5537 + spin_lock_init(&component->output[idx].slock);
5538 + INIT_LIST_HEAD(&component->output[idx].buffers);
5539 + ret = port_info_get(instance, &component->output[idx]);
5541 + goto release_component;
5544 + for (idx = 0; idx < component->clocks; idx++) {
5545 + component->clock[idx].type = MMAL_PORT_TYPE_CLOCK;
5546 + component->clock[idx].index = idx;
5547 + component->clock[idx].component = component;
5548 + spin_lock_init(&component->clock[idx].slock);
5549 + INIT_LIST_HEAD(&component->clock[idx].buffers);
5550 + ret = port_info_get(instance, &component->clock[idx]);
5552 + goto release_component;
5555 + instance->component_idx++;
5557 + *component_out = component;
5559 + mutex_unlock(&instance->vchiq_mutex);
5564 + destroy_component(instance, component);
5566 + mutex_unlock(&instance->vchiq_mutex);
5572 + * cause a mmal component to be destroyed
5574 +int vchiq_mmal_component_finalise(struct vchiq_mmal_instance *instance,
5575 + struct vchiq_mmal_component *component)
5579 + if (mutex_lock_interruptible(&instance->vchiq_mutex))
5582 + if (component->enabled)
5583 + ret = disable_component(instance, component);
5585 + ret = destroy_component(instance, component);
5587 + mutex_unlock(&instance->vchiq_mutex);
5593 + * cause a mmal component to be enabled
5595 +int vchiq_mmal_component_enable(struct vchiq_mmal_instance *instance,
5596 + struct vchiq_mmal_component *component)
5600 + if (mutex_lock_interruptible(&instance->vchiq_mutex))
5603 + if (component->enabled) {
5604 + mutex_unlock(&instance->vchiq_mutex);
5608 + ret = enable_component(instance, component);
5610 + component->enabled = true;
5612 + mutex_unlock(&instance->vchiq_mutex);
5618 + * cause a mmal component to be enabled
5620 +int vchiq_mmal_component_disable(struct vchiq_mmal_instance *instance,
5621 + struct vchiq_mmal_component *component)
5625 + if (mutex_lock_interruptible(&instance->vchiq_mutex))
5628 + if (!component->enabled) {
5629 + mutex_unlock(&instance->vchiq_mutex);
5633 + ret = disable_component(instance, component);
5635 + component->enabled = false;
5637 + mutex_unlock(&instance->vchiq_mutex);
5642 +int vchiq_mmal_version(struct vchiq_mmal_instance *instance,
5643 + u32 *major_out, u32 *minor_out)
5647 + if (mutex_lock_interruptible(&instance->vchiq_mutex))
5650 + ret = get_version(instance, major_out, minor_out);
5652 + mutex_unlock(&instance->vchiq_mutex);
5657 +int vchiq_mmal_finalise(struct vchiq_mmal_instance *instance)
5661 + if (instance == NULL)
5664 + if (mutex_lock_interruptible(&instance->vchiq_mutex))
5667 + vchi_service_use(instance->handle);
5669 + status = vchi_service_close(instance->handle);
5671 + pr_err("mmal-vchiq: VCHIQ close failed");
5673 + mutex_unlock(&instance->vchiq_mutex);
5675 + vfree(instance->bulk_scratch);
5682 +int vchiq_mmal_init(struct vchiq_mmal_instance **out_instance)
5685 + struct vchiq_mmal_instance *instance;
5686 + static VCHI_CONNECTION_T *vchi_connection;
5687 + static VCHI_INSTANCE_T vchi_instance;
5688 + SERVICE_CREATION_T params = {
5689 + VCHI_VERSION_EX(VC_MMAL_VER, VC_MMAL_MIN_VER),
5690 + VC_MMAL_SERVER_NAME,
5692 + 0, /* rx fifo size (unused) */
5693 + 0, /* tx fifo size (unused) */
5695 + NULL, /* service callback parameter */
5696 + 1, /* unaligned bulk receives */
5697 + 1, /* unaligned bulk transmits */
5698 + 0 /* want crc check on bulk transfers */
5701 + /* compile time checks to ensure structure size as they are
5702 + * directly (de)serialised from memory.
5705 + /* ensure the header structure has packed to the correct size */
5706 + BUILD_BUG_ON(sizeof(struct mmal_msg_header) != 24);
5708 + /* ensure message structure does not exceed maximum length */
5709 + BUILD_BUG_ON(sizeof(struct mmal_msg) > MMAL_MSG_MAX_SIZE);
5711 + /* mmal port struct is correct size */
5712 + BUILD_BUG_ON(sizeof(struct mmal_port) != 64);
5714 + /* create a vchi instance */
5715 + status = vchi_initialise(&vchi_instance);
5717 + pr_err("Failed to initialise VCHI instance (status=%d)\n",
5722 + status = vchi_connect(NULL, 0, vchi_instance);
5724 + pr_err("Failed to connect VCHI instance (status=%d)\n", status);
5728 + instance = kmalloc(sizeof(*instance), GFP_KERNEL);
5729 + memset(instance, 0, sizeof(*instance));
5731 + mutex_init(&instance->vchiq_mutex);
5732 + mutex_init(&instance->bulk_mutex);
5734 + instance->bulk_scratch = vmalloc(PAGE_SIZE);
5736 + params.callback_param = instance;
5738 + status = vchi_service_open(vchi_instance, ¶ms, &instance->handle);
5740 + pr_err("Failed to open VCHI service connection (status=%d)\n",
5742 + goto err_close_services;
5745 + vchi_service_release(instance->handle);
5747 + *out_instance = instance;
5751 +err_close_services:
5753 + vchi_service_close(instance->handle);
5754 + vfree(instance->bulk_scratch);
5759 +++ b/drivers/media/platform/bcm2835/mmal-vchiq.h
5762 + * Broadcom BM2835 V4L2 driver
5764 + * Copyright © 2013 Raspberry Pi (Trading) Ltd.
5766 + * This file is subject to the terms and conditions of the GNU General Public
5767 + * License. See the file COPYING in the main directory of this archive
5768 + * for more details.
5770 + * Authors: Vincent Sanders <vincent.sanders@collabora.co.uk>
5771 + * Dave Stevenson <dsteve@broadcom.com>
5772 + * Simon Mellor <simellor@broadcom.com>
5773 + * Luke Diamand <luked@broadcom.com>
5775 + * MMAL interface to VCHIQ message passing
5778 +#ifndef MMAL_VCHIQ_H
5779 +#define MMAL_VCHIQ_H
5781 +#include "mmal-msg-format.h"
5783 +#define MAX_PORT_COUNT 4
5785 +/* Maximum size of the format extradata. */
5786 +#define MMAL_FORMAT_EXTRADATA_MAX_SIZE 128
5788 +struct vchiq_mmal_instance;
5790 +enum vchiq_mmal_es_type {
5791 + MMAL_ES_TYPE_UNKNOWN, /**< Unknown elementary stream type */
5792 + MMAL_ES_TYPE_CONTROL, /**< Elementary stream of control commands */
5793 + MMAL_ES_TYPE_AUDIO, /**< Audio elementary stream */
5794 + MMAL_ES_TYPE_VIDEO, /**< Video elementary stream */
5795 + MMAL_ES_TYPE_SUBPICTURE /**< Sub-picture elementary stream */
5798 +/* rectangle, used lots so it gets its own struct */
5799 +struct vchiq_mmal_rect {
5806 +struct vchiq_mmal_port_buffer {
5807 + unsigned int num; /* number of buffers */
5808 + u32 size; /* size of buffers */
5809 + u32 alignment; /* alignment of buffers */
5812 +struct vchiq_mmal_port;
5814 +typedef void (*vchiq_mmal_buffer_cb)(
5815 + struct vchiq_mmal_instance *instance,
5816 + struct vchiq_mmal_port *port,
5817 + int status, struct mmal_buffer *buffer,
5818 + unsigned long length, u32 mmal_flags, s64 dts, s64 pts);
5820 +struct vchiq_mmal_port {
5823 + u32 type; /* port type, cached to use on port info set */
5824 + u32 index; /* port index, cached to use on port info set */
5826 + /* component port belongs to, allows simple deref */
5827 + struct vchiq_mmal_component *component;
5829 + struct vchiq_mmal_port *connected; /* port conencted to */
5832 + struct vchiq_mmal_port_buffer minimum_buffer;
5833 + struct vchiq_mmal_port_buffer recommended_buffer;
5834 + struct vchiq_mmal_port_buffer current_buffer;
5836 + /* stream format */
5837 + struct mmal_es_format format;
5838 + /* elementry stream format */
5839 + union mmal_es_specific_format es;
5841 + /* data buffers to fill */
5842 + struct list_head buffers;
5843 + /* lock to serialise adding and removing buffers from list */
5845 + /* count of how many buffer header refils have failed because
5846 + * there was no buffer to satisfy them
5848 + int buffer_underflow;
5849 + /* callback on buffer completion */
5850 + vchiq_mmal_buffer_cb buffer_cb;
5851 + /* callback context */
5855 +struct vchiq_mmal_component {
5857 + u32 handle; /* VideoCore handle for component */
5858 + u32 inputs; /* Number of input ports */
5859 + u32 outputs; /* Number of output ports */
5860 + u32 clocks; /* Number of clock ports */
5861 + struct vchiq_mmal_port control; /* control port */
5862 + struct vchiq_mmal_port input[MAX_PORT_COUNT]; /* input ports */
5863 + struct vchiq_mmal_port output[MAX_PORT_COUNT]; /* output ports */
5864 + struct vchiq_mmal_port clock[MAX_PORT_COUNT]; /* clock ports */
5868 +int vchiq_mmal_init(struct vchiq_mmal_instance **out_instance);
5869 +int vchiq_mmal_finalise(struct vchiq_mmal_instance *instance);
5871 +/* Initialise a mmal component and its ports
5874 +int vchiq_mmal_component_init(
5875 + struct vchiq_mmal_instance *instance,
5877 + struct vchiq_mmal_component **component_out);
5879 +int vchiq_mmal_component_finalise(
5880 + struct vchiq_mmal_instance *instance,
5881 + struct vchiq_mmal_component *component);
5883 +int vchiq_mmal_component_enable(
5884 + struct vchiq_mmal_instance *instance,
5885 + struct vchiq_mmal_component *component);
5887 +int vchiq_mmal_component_disable(
5888 + struct vchiq_mmal_instance *instance,
5889 + struct vchiq_mmal_component *component);
5893 +/* enable a mmal port
5895 + * enables a port and if a buffer callback provided enque buffer
5896 + * headers as apropriate for the port.
5898 +int vchiq_mmal_port_enable(
5899 + struct vchiq_mmal_instance *instance,
5900 + struct vchiq_mmal_port *port,
5901 + vchiq_mmal_buffer_cb buffer_cb);
5905 + * disable a port will dequeue any pending buffers
5907 +int vchiq_mmal_port_disable(struct vchiq_mmal_instance *instance,
5908 + struct vchiq_mmal_port *port);
5911 +int vchiq_mmal_port_parameter_set(struct vchiq_mmal_instance *instance,
5912 + struct vchiq_mmal_port *port,
5917 +int vchiq_mmal_port_parameter_get(struct vchiq_mmal_instance *instance,
5918 + struct vchiq_mmal_port *port,
5923 +int vchiq_mmal_port_set_format(struct vchiq_mmal_instance *instance,
5924 + struct vchiq_mmal_port *port);
5926 +int vchiq_mmal_port_connect_tunnel(struct vchiq_mmal_instance *instance,
5927 + struct vchiq_mmal_port *src,
5928 + struct vchiq_mmal_port *dst);
5930 +int vchiq_mmal_version(struct vchiq_mmal_instance *instance,
5934 +int vchiq_mmal_submit_buffer(struct vchiq_mmal_instance *instance,
5935 + struct vchiq_mmal_port *port,
5936 + struct mmal_buffer *buf);
5938 +#endif /* MMAL_VCHIQ_H */