1212afb97SMichael Zoran /* 2212afb97SMichael Zoran * Broadcom BM2835 V4L2 driver 3212afb97SMichael Zoran * 4212afb97SMichael Zoran * Copyright © 2013 Raspberry Pi (Trading) Ltd. 5212afb97SMichael Zoran * 6212afb97SMichael Zoran * This file is subject to the terms and conditions of the GNU General Public 7212afb97SMichael Zoran * License. See the file COPYING in the main directory of this archive 8212afb97SMichael Zoran * for more details. 9212afb97SMichael Zoran * 10212afb97SMichael Zoran * Authors: Vincent Sanders <vincent.sanders@collabora.co.uk> 11212afb97SMichael Zoran * Dave Stevenson <dsteve@broadcom.com> 12212afb97SMichael Zoran * Simon Mellor <simellor@broadcom.com> 13212afb97SMichael Zoran * Luke Diamand <luked@broadcom.com> 14212afb97SMichael Zoran * 15212afb97SMichael Zoran * core driver device 16212afb97SMichael Zoran */ 17212afb97SMichael Zoran 18212afb97SMichael Zoran #define V4L2_CTRL_COUNT 29 /* number of v4l controls */ 19212afb97SMichael Zoran 20212afb97SMichael Zoran enum { 21212afb97SMichael Zoran MMAL_COMPONENT_CAMERA = 0, 22212afb97SMichael Zoran MMAL_COMPONENT_PREVIEW, 23212afb97SMichael Zoran MMAL_COMPONENT_IMAGE_ENCODE, 24212afb97SMichael Zoran MMAL_COMPONENT_VIDEO_ENCODE, 25212afb97SMichael Zoran MMAL_COMPONENT_COUNT 26212afb97SMichael Zoran }; 27212afb97SMichael Zoran 28212afb97SMichael Zoran enum { 29212afb97SMichael Zoran MMAL_CAMERA_PORT_PREVIEW = 0, 30212afb97SMichael Zoran MMAL_CAMERA_PORT_VIDEO, 31212afb97SMichael Zoran MMAL_CAMERA_PORT_CAPTURE, 32212afb97SMichael Zoran MMAL_CAMERA_PORT_COUNT 33212afb97SMichael Zoran }; 34212afb97SMichael Zoran 35212afb97SMichael Zoran #define PREVIEW_LAYER 2 36212afb97SMichael Zoran 37212afb97SMichael Zoran extern int bcm2835_v4l2_debug; 38212afb97SMichael Zoran 39212afb97SMichael Zoran struct bm2835_mmal_dev { 40212afb97SMichael Zoran /* v4l2 devices */ 41212afb97SMichael Zoran struct v4l2_device v4l2_dev; 42212afb97SMichael Zoran struct video_device vdev; 43212afb97SMichael Zoran struct mutex mutex; 44212afb97SMichael Zoran 45212afb97SMichael Zoran /* controls */ 46212afb97SMichael Zoran struct v4l2_ctrl_handler ctrl_handler; 47212afb97SMichael Zoran struct v4l2_ctrl *ctrls[V4L2_CTRL_COUNT]; 48212afb97SMichael Zoran enum v4l2_scene_mode scene_mode; 49212afb97SMichael Zoran struct mmal_colourfx colourfx; 50212afb97SMichael Zoran int hflip; 51212afb97SMichael Zoran int vflip; 52212afb97SMichael Zoran int red_gain; 53212afb97SMichael Zoran int blue_gain; 54212afb97SMichael Zoran enum mmal_parameter_exposuremode exposure_mode_user; 55212afb97SMichael Zoran enum v4l2_exposure_auto_type exposure_mode_v4l2_user; 56212afb97SMichael Zoran /* active exposure mode may differ if selected via a scene mode */ 57212afb97SMichael Zoran enum mmal_parameter_exposuremode exposure_mode_active; 58212afb97SMichael Zoran enum mmal_parameter_exposuremeteringmode metering_mode; 59212afb97SMichael Zoran unsigned int manual_shutter_speed; 60212afb97SMichael Zoran bool exp_auto_priority; 61212afb97SMichael Zoran bool manual_iso_enabled; 6216255382SNarcisa Ana Maria Vasile u32 iso; 63212afb97SMichael Zoran 64212afb97SMichael Zoran /* allocated mmal instance and components */ 65212afb97SMichael Zoran struct vchiq_mmal_instance *instance; 66212afb97SMichael Zoran struct vchiq_mmal_component *component[MMAL_COMPONENT_COUNT]; 67212afb97SMichael Zoran int camera_use_count; 68212afb97SMichael Zoran 69212afb97SMichael Zoran struct v4l2_window overlay; 70212afb97SMichael Zoran 71212afb97SMichael Zoran struct { 72212afb97SMichael Zoran unsigned int width; /* width */ 73212afb97SMichael Zoran unsigned int height; /* height */ 74212afb97SMichael Zoran unsigned int stride; /* stride */ 75212afb97SMichael Zoran unsigned int buffersize; /* buffer size with padding */ 76212afb97SMichael Zoran struct mmal_fmt *fmt; 77212afb97SMichael Zoran struct v4l2_fract timeperframe; 78212afb97SMichael Zoran 79212afb97SMichael Zoran /* H264 encode bitrate */ 80212afb97SMichael Zoran int encode_bitrate; 81212afb97SMichael Zoran /* H264 bitrate mode. CBR/VBR */ 82212afb97SMichael Zoran int encode_bitrate_mode; 83212afb97SMichael Zoran /* H264 profile */ 84212afb97SMichael Zoran enum v4l2_mpeg_video_h264_profile enc_profile; 85212afb97SMichael Zoran /* H264 level */ 86212afb97SMichael Zoran enum v4l2_mpeg_video_h264_level enc_level; 87212afb97SMichael Zoran /* JPEG Q-factor */ 88212afb97SMichael Zoran int q_factor; 89212afb97SMichael Zoran 90212afb97SMichael Zoran struct vb2_queue vb_vidq; 91212afb97SMichael Zoran 92212afb97SMichael Zoran /* VC start timestamp for streaming */ 93212afb97SMichael Zoran s64 vc_start_timestamp; 94212afb97SMichael Zoran /* Kernel start timestamp for streaming */ 95212afb97SMichael Zoran struct timeval kernel_start_ts; 96212afb97SMichael Zoran 97212afb97SMichael Zoran struct vchiq_mmal_port *port; /* port being used for capture */ 98212afb97SMichael Zoran /* camera port being used for capture */ 99212afb97SMichael Zoran struct vchiq_mmal_port *camera_port; 100212afb97SMichael Zoran /* component being used for encode */ 101212afb97SMichael Zoran struct vchiq_mmal_component *encode_component; 102212afb97SMichael Zoran /* number of frames remaining which driver should capture */ 103212afb97SMichael Zoran unsigned int frame_count; 104212afb97SMichael Zoran /* last frame completion */ 105212afb97SMichael Zoran struct completion frame_cmplt; 106212afb97SMichael Zoran 107212afb97SMichael Zoran } capture; 108212afb97SMichael Zoran 109212afb97SMichael Zoran unsigned int camera_num; 110212afb97SMichael Zoran unsigned int max_width; 111212afb97SMichael Zoran unsigned int max_height; 112212afb97SMichael Zoran unsigned int rgb_bgr_swapped; 113212afb97SMichael Zoran }; 114212afb97SMichael Zoran 115212afb97SMichael Zoran int bm2835_mmal_init_controls( 116212afb97SMichael Zoran struct bm2835_mmal_dev *dev, 117212afb97SMichael Zoran struct v4l2_ctrl_handler *hdl); 118212afb97SMichael Zoran 119212afb97SMichael Zoran int bm2835_mmal_set_all_camera_controls(struct bm2835_mmal_dev *dev); 120212afb97SMichael Zoran int set_framerate_params(struct bm2835_mmal_dev *dev); 121212afb97SMichael Zoran 122212afb97SMichael Zoran /* Debug helpers */ 123212afb97SMichael Zoran 124212afb97SMichael Zoran #define v4l2_dump_pix_format(level, debug, dev, pix_fmt, desc) \ 125212afb97SMichael Zoran { \ 126212afb97SMichael Zoran v4l2_dbg(level, debug, dev, \ 127212afb97SMichael Zoran "%s: w %u h %u field %u pfmt 0x%x bpl %u sz_img %u colorspace 0x%x priv %u\n", \ 1282367eb3fSMichael Zoran desc, \ 129212afb97SMichael Zoran (pix_fmt)->width, (pix_fmt)->height, (pix_fmt)->field, \ 130212afb97SMichael Zoran (pix_fmt)->pixelformat, (pix_fmt)->bytesperline, \ 131212afb97SMichael Zoran (pix_fmt)->sizeimage, (pix_fmt)->colorspace, (pix_fmt)->priv); \ 132212afb97SMichael Zoran } 133212afb97SMichael Zoran #define v4l2_dump_win_format(level, debug, dev, win_fmt, desc) \ 134212afb97SMichael Zoran { \ 135212afb97SMichael Zoran v4l2_dbg(level, debug, dev, \ 136212afb97SMichael Zoran "%s: w %u h %u l %u t %u field %u chromakey %06X clip %p " \ 137212afb97SMichael Zoran "clipcount %u bitmap %p\n", \ 1382367eb3fSMichael Zoran desc, \ 139212afb97SMichael Zoran (win_fmt)->w.width, (win_fmt)->w.height, \ 140212afb97SMichael Zoran (win_fmt)->w.left, (win_fmt)->w.top, \ 141212afb97SMichael Zoran (win_fmt)->field, \ 142212afb97SMichael Zoran (win_fmt)->chromakey, \ 143212afb97SMichael Zoran (win_fmt)->clips, (win_fmt)->clipcount, \ 144212afb97SMichael Zoran (win_fmt)->bitmap); \ 145212afb97SMichael Zoran } 146