brcm2708: update against latest rpi-3.10.y branch
[openwrt/svn-archive/archive.git] / target / linux / brcm2708 / patches-3.10 / 0131-V4L2-Fix-EV-values.-Add-manual-shutter-speed-control.patch
1 From 75f2608b89d80e627d50aca40f2124253a8275b0 Mon Sep 17 00:00:00 2001
2 From: Dave Stevenson <dsteve@broadcom.com>
3 Date: Mon, 9 Dec 2013 10:58:01 +0000
4 Subject: [PATCH 131/174] V4L2: Fix EV values. Add manual shutter speed control
5
6 V4L2 EV values should be in units of 1/1000. Corrected.
7 Add support for V4L2_CID_EXPOSURE_ABSOLUTE which should
8 give manual shutter control. Requires manual exposure mode
9 to be selected first.
10
11 Signed-off-by: Dave Stevenson <dsteve@broadcom.com>
12 ---
13 drivers/media/platform/bcm2835/bcm2835-camera.h | 4 +-
14 drivers/media/platform/bcm2835/controls.c | 94 ++++++++++++++++++------
15 drivers/media/platform/bcm2835/mmal-parameters.h | 1 +
16 3 files changed, 76 insertions(+), 23 deletions(-)
17
18 --- a/drivers/media/platform/bcm2835/bcm2835-camera.h
19 +++ b/drivers/media/platform/bcm2835/bcm2835-camera.h
20 @@ -15,7 +15,7 @@
21 * core driver device
22 */
23
24 -#define V4L2_CTRL_COUNT 18 /* number of v4l controls */
25 +#define V4L2_CTRL_COUNT 19 /* number of v4l controls */
26
27 enum {
28 MMAL_COMPONENT_CAMERA = 0,
29 @@ -51,6 +51,8 @@ struct bm2835_mmal_dev {
30 struct mmal_colourfx colourfx;
31 int hflip;
32 int vflip;
33 + enum mmal_parameter_exposuremode exposure_mode;
34 + unsigned int manual_shutter_speed;
35
36 /* allocated mmal instance and components */
37 struct vchiq_mmal_instance *instance;
38 --- a/drivers/media/platform/bcm2835/controls.c
39 +++ b/drivers/media/platform/bcm2835/controls.c
40 @@ -30,11 +30,23 @@
41 #include "mmal-parameters.h"
42 #include "bcm2835-camera.h"
43
44 -/* The supported V4L2_CID_AUTO_EXPOSURE_BIAS values are from -24 to +24.
45 - * These are in 1/6th increments so the effective range is -4.0EV to +4.0EV.
46 +/* The supported V4L2_CID_AUTO_EXPOSURE_BIAS values are from -4.0 to +4.0.
47 + * MMAL values are in 1/6th increments so the MMAL range is -24 to +24.
48 + * V4L2 docs say value "is expressed in terms of EV, drivers should interpret
49 + * the values as 0.001 EV units, where the value 1000 stands for +1 EV."
50 + * V4L2 is limited to a max of 32 values in a menu, so count in 1/3rds from
51 + * -4 to +4
52 */
53 static const s64 ev_bias_qmenu[] = {
54 - -24, -21, -18, -15, -12, -9, -6, -3, 0, 3, 6, 9, 12, 15, 18, 21, 24
55 + -4000, -3667, -3333,
56 + -3000, -2667, -2333,
57 + -2000, -1667, -1333,
58 + -1000, -667, -333,
59 + 0, 333, 667,
60 + 1000, 1333, 1667,
61 + 2000, 2333, 2667,
62 + 3000, 3333, 3667,
63 + 4000
64 };
65
66 /* Supported ISO values
67 @@ -166,6 +178,22 @@ static int ctrl_set_value(struct bm2835_
68 &u32_value, sizeof(u32_value));
69 }
70
71 +static int ctrl_set_value_ev(struct bm2835_mmal_dev *dev,
72 + struct v4l2_ctrl *ctrl,
73 + const struct bm2835_mmal_v4l2_ctrl *mmal_ctrl)
74 +{
75 + s32 s32_value;
76 + struct vchiq_mmal_port *control;
77 +
78 + control = &dev->component[MMAL_COMPONENT_CAMERA]->control;
79 +
80 + s32_value = (ctrl->val-12)*2; /* Convert from index to 1/6ths */
81 +
82 + return vchiq_mmal_port_parameter_set(dev->instance, control,
83 + mmal_ctrl->mmal_id,
84 + &s32_value, sizeof(s32_value));
85 +}
86 +
87 static int ctrl_set_rotate(struct bm2835_mmal_dev *dev,
88 struct v4l2_ctrl *ctrl,
89 const struct bm2835_mmal_v4l2_ctrl *mmal_ctrl)
90 @@ -245,34 +273,50 @@ static int ctrl_set_exposure(struct bm28
91 struct v4l2_ctrl *ctrl,
92 const struct bm2835_mmal_v4l2_ctrl *mmal_ctrl)
93 {
94 - u32 u32_value;
95 + enum mmal_parameter_exposuremode exp_mode = dev->exposure_mode;
96 + u32 shutter_speed = 0;
97 struct vchiq_mmal_port *control;
98 + int ret = 0;
99
100 control = &dev->component[MMAL_COMPONENT_CAMERA]->control;
101
102 - switch (ctrl->val) {
103 - case V4L2_EXPOSURE_AUTO:
104 - u32_value = MMAL_PARAM_EXPOSUREMODE_AUTO;
105 - break;
106 -
107 - case V4L2_EXPOSURE_MANUAL:
108 - u32_value = MMAL_PARAM_EXPOSUREMODE_OFF;
109 - break;
110 -
111 - case V4L2_EXPOSURE_SHUTTER_PRIORITY:
112 - u32_value = MMAL_PARAM_EXPOSUREMODE_SPORTS;
113 - break;
114 -
115 - case V4L2_EXPOSURE_APERTURE_PRIORITY:
116 - u32_value = MMAL_PARAM_EXPOSUREMODE_NIGHT;
117 - break;
118 + if (mmal_ctrl->mmal_id == MMAL_PARAMETER_SHUTTER_SPEED) {
119 + /* V4L2 is in 100usec increments.
120 + * MMAL is 1usec.
121 + */
122 + dev->manual_shutter_speed = ctrl->val * 100;
123 + } else if (mmal_ctrl->mmal_id == MMAL_PARAMETER_EXPOSURE_MODE) {
124 + switch (ctrl->val) {
125 + case V4L2_EXPOSURE_AUTO:
126 + exp_mode = MMAL_PARAM_EXPOSUREMODE_AUTO;
127 + break;
128 +
129 + case V4L2_EXPOSURE_MANUAL:
130 + exp_mode = MMAL_PARAM_EXPOSUREMODE_OFF;
131 + break;
132 +
133 + case V4L2_EXPOSURE_SHUTTER_PRIORITY:
134 + exp_mode = MMAL_PARAM_EXPOSUREMODE_SPORTS;
135 + break;
136 +
137 + case V4L2_EXPOSURE_APERTURE_PRIORITY:
138 + exp_mode = MMAL_PARAM_EXPOSUREMODE_NIGHT;
139 + break;
140
141 + }
142 + dev->exposure_mode = exp_mode;
143 }
144
145 - /* todo: what about the other ten modes there are MMAL parameters for */
146 - return vchiq_mmal_port_parameter_set(dev->instance, control,
147 - mmal_ctrl->mmal_id,
148 - &u32_value, sizeof(u32_value));
149 + if (dev->exposure_mode == MMAL_PARAM_EXPOSUREMODE_OFF)
150 + shutter_speed = dev->manual_shutter_speed;
151 +
152 + ret = vchiq_mmal_port_parameter_set(dev->instance, control,
153 + MMAL_PARAMETER_SHUTTER_SPEED,
154 + &shutter_speed, sizeof(shutter_speed));
155 + ret += vchiq_mmal_port_parameter_set(dev->instance, control,
156 + MMAL_PARAMETER_EXPOSURE_MODE,
157 + &exp_mode, sizeof(u32));
158 + return ret;
159 }
160
161 static int ctrl_set_metering_mode(struct bm2835_mmal_dev *dev,
162 @@ -578,10 +622,16 @@ static const struct bm2835_mmal_v4l2_ctr
163 },
164 */
165 {
166 + V4L2_CID_EXPOSURE_ABSOLUTE, MMAL_CONTROL_TYPE_STD,
167 + /* Units of 100usecs */
168 + 1, 1*1000*10, 100*10, 1, NULL,
169 + MMAL_PARAMETER_SHUTTER_SPEED, &ctrl_set_exposure
170 + },
171 + {
172 V4L2_CID_AUTO_EXPOSURE_BIAS, MMAL_CONTROL_TYPE_INT_MENU,
173 0, ARRAY_SIZE(ev_bias_qmenu) - 1,
174 (ARRAY_SIZE(ev_bias_qmenu)+1)/2 - 1, 0, ev_bias_qmenu,
175 - MMAL_PARAMETER_EXPOSURE_COMP, &ctrl_set_value
176 + MMAL_PARAMETER_EXPOSURE_COMP, &ctrl_set_value_ev
177 },
178 {
179 V4L2_CID_EXPOSURE_METERING,
180 --- a/drivers/media/platform/bcm2835/mmal-parameters.h
181 +++ b/drivers/media/platform/bcm2835/mmal-parameters.h
182 @@ -161,6 +161,7 @@ enum mmal_parameter_camera_type {
183 MMAL_PARAMETER_SW_SHARPEN_DISABLE, /**< @ref MMAL_PARAMETER_BOOLEAN_T */
184 MMAL_PARAMETER_FLASH_REQUIRED, /**< @ref MMAL_PARAMETER_BOOLEAN_T */
185 MMAL_PARAMETER_SW_SATURATION_DISABLE, /**< @ref MMAL_PARAMETER_BOOLEAN_T */
186 + MMAL_PARAMETER_SHUTTER_SPEED /**< Takes a @ref MMAL_PARAMETER_UINT32_T */
187 };
188
189 enum mmal_parameter_camera_config_timestamp_mode {