blob: 4d1696d1a7f4022d0cca06a90f40f6a912a5b877 [file] [log] [blame]
Jean-Francois Moine6a7eba22008-06-30 15:50:11 -03001/*
Jean-Francois Moine5b34e3e2009-11-02 10:00:48 -03002 * Sonix sn9c102p sn9c105 sn9c120 (jpeg) subdriver
Jean-Francois Moined5aa3852009-11-07 06:10:08 -03003 *
Jean-François Moineb813b0c2011-08-10 05:54:34 -03004 * Copyright (C) 2009-2011 Jean-François Moine <http://moinejf.free.fr>
Jean-Francois Moine5b34e3e2009-11-02 10:00:48 -03005 * Copyright (C) 2005 Michel Xhaard mxhaard@magic.fr
Jean-Francois Moine6a7eba22008-06-30 15:50:11 -03006 *
7 * This program is free software; you can redistribute it and/or modify
8 * it under the terms of the GNU General Public License as published by
9 * the Free Software Foundation; either version 2 of the License, or
10 * any later version.
11 *
12 * This program is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 * GNU General Public License for more details.
16 *
17 * You should have received a copy of the GNU General Public License
18 * along with this program; if not, write to the Free Software
19 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
20 */
21
Joe Perches133a9fe2011-08-21 19:56:57 -030022#define pr_fmt(fmt) KBUILD_MODNAME ": " fmt
23
Jean-Francois Moine6a7eba22008-06-30 15:50:11 -030024#define MODULE_NAME "sonixj"
25
Hans de Goede9712a8b2010-01-31 12:54:29 -030026#include <linux/input.h>
Jean-Francois Moine6a7eba22008-06-30 15:50:11 -030027#include "gspca.h"
28#include "jpeg.h"
29
Jean-François Moine27c6f9e2010-04-02 06:59:13 -030030MODULE_AUTHOR("Jean-François Moine <http://moinejf.free.fr>");
Jean-Francois Moine6a7eba22008-06-30 15:50:11 -030031MODULE_DESCRIPTION("GSPCA/SONIX JPEG USB Camera Driver");
32MODULE_LICENSE("GPL");
33
Jean-François Moine72b667e2010-10-02 04:35:25 -030034/* controls */
35enum e_ctrl {
36 BRIGHTNESS,
37 CONTRAST,
38 COLORS,
39 BLUE,
40 RED,
41 GAMMA,
Jean-François Moinea7705c02012-02-27 06:57:04 -030042 EXPOSURE,
Jean-François Moine72b667e2010-10-02 04:35:25 -030043 AUTOGAIN,
Jean-François Moinea7705c02012-02-27 06:57:04 -030044 GAIN,
Németh Márton76ad3b62010-10-19 03:33:47 -030045 HFLIP,
Jean-François Moine72b667e2010-10-02 04:35:25 -030046 VFLIP,
47 SHARPNESS,
Jean-François Moine3afef852011-01-13 06:39:11 -030048 ILLUM,
Jean-François Moine72b667e2010-10-02 04:35:25 -030049 FREQ,
50 NCTRLS /* number of controls */
51};
52
Jean-Francois Moine6a7eba22008-06-30 15:50:11 -030053/* specific webcam descriptor */
54struct sd {
55 struct gspca_dev gspca_dev; /* !! must be the first item */
56
Jean-François Moine72b667e2010-10-02 04:35:25 -030057 struct gspca_ctrl ctrls[NCTRLS];
58
Jean-Francois Moinecebf3b62008-08-03 07:52:53 -030059 atomic_t avg_lum;
Jean-Francois Moine98819182009-01-19 07:37:33 -030060 u32 exposure;
Jean-Francois Moine6a7eba22008-06-30 15:50:11 -030061
Jean-François Moineb96cfc32011-02-10 07:38:58 -030062 struct work_struct work;
63 struct workqueue_struct *work_thread;
64
65 u32 pktsz; /* (used by pkt_scan) */
66 u16 npkt;
Hans Petter Selasky67e27c742011-05-23 08:09:18 -030067 s8 nchg;
Jean-François Moinea4a30762011-02-10 07:15:24 -030068 s8 short_mark;
69
Jean-Francois Moine71cb2762009-03-03 05:33:41 -030070 u8 quality; /* image quality */
Jean-François Moineb96cfc32011-02-10 07:38:58 -030071#define QUALITY_MIN 25
72#define QUALITY_MAX 90
73#define QUALITY_DEF 70
Jean-Francois Moine71cb2762009-03-03 05:33:41 -030074
Jean-Francois Moine0e4d4132010-12-14 16:17:40 -030075 u8 reg01;
76 u8 reg17;
Jean-Francois Moine71cb2762009-03-03 05:33:41 -030077 u8 reg18;
Jean-Francois Moinec6c14332010-12-14 16:15:37 -030078 u8 flags;
Jean-Francois Moine6a7eba22008-06-30 15:50:11 -030079
Jean-Francois Moine98819182009-01-19 07:37:33 -030080 s8 ag_cnt;
Jean-Francois Moine6a7eba22008-06-30 15:50:11 -030081#define AG_CNT_START 13
82
Jean-Francois Moine98819182009-01-19 07:37:33 -030083 u8 bridge;
Hans de Goede3647fea2008-07-15 05:36:30 -030084#define BRIDGE_SN9C102P 0
85#define BRIDGE_SN9C105 1
86#define BRIDGE_SN9C110 2
87#define BRIDGE_SN9C120 3
Jean-Francois Moine98819182009-01-19 07:37:33 -030088 u8 sensor; /* Type of image sensor chip */
Jean-François Moine11ce8842010-07-26 06:39:40 -030089 u8 i2c_addr;
90
91 u8 jpeg_hdr[JPEG_HDR_SZ];
92};
93enum sensors {
Jean-François Moine9c33afc2010-03-17 15:25:32 -030094 SENSOR_ADCM1700,
Jean-François Moinead98c0f2010-03-18 05:15:30 -030095 SENSOR_GC0307,
Jean-François Moine9c33afc2010-03-17 15:25:32 -030096 SENSOR_HV7131R,
97 SENSOR_MI0360,
Jean-François Moinea067db82010-10-01 07:51:24 -030098 SENSOR_MI0360B,
Jean-François Moine9c33afc2010-03-17 15:25:32 -030099 SENSOR_MO4000,
100 SENSOR_MT9V111,
101 SENSOR_OM6802,
102 SENSOR_OV7630,
103 SENSOR_OV7648,
104 SENSOR_OV7660,
105 SENSOR_PO1030,
Jean-François Moinead98c0f2010-03-18 05:15:30 -0300106 SENSOR_PO2030N,
Jean-François Moine03ed2a12010-04-25 14:45:43 -0300107 SENSOR_SOI768,
Jean-François Moine9c33afc2010-03-17 15:25:32 -0300108 SENSOR_SP80708,
Jean-Francois Moine6a7eba22008-06-30 15:50:11 -0300109};
110
Jean-François Moineb96cfc32011-02-10 07:38:58 -0300111static void qual_upd(struct work_struct *work);
112
Jean-Francois Moineb2272a42010-12-14 16:16:16 -0300113/* device flags */
Jean-François Moine3afef852011-01-13 06:39:11 -0300114#define F_PDN_INV 0x01 /* inverse pin S_PWR_DN / sn_xxx tables */
115#define F_ILLUM 0x02 /* presence of illuminator */
Jean-Francois Moineb2272a42010-12-14 16:16:16 -0300116
Jean-Francois Moine4fd350ee2010-12-14 16:16:58 -0300117/* sn9c1xx definitions */
118/* register 0x01 */
119#define S_PWR_DN 0x01 /* sensor power down */
120#define S_PDN_INV 0x02 /* inverse pin S_PWR_DN */
121#define V_TX_EN 0x04 /* video transfer enable */
122#define LED 0x08 /* output to pin LED */
123#define SCL_SEL_OD 0x20 /* open-drain mode */
124#define SYS_SEL_48M 0x40 /* system clock 0: 24MHz, 1: 48MHz */
125/* register 0x17 */
126#define MCK_SIZE_MASK 0x1f /* sensor master clock */
127#define SEN_CLK_EN 0x20 /* enable sensor clock */
128#define DEF_EN 0x80 /* defect pixel by 0: soft, 1: hard */
129
Jean-Francois Moine6a7eba22008-06-30 15:50:11 -0300130/* V4L2 controls supported by the driver */
Jean-François Moine72b667e2010-10-02 04:35:25 -0300131static void setbrightness(struct gspca_dev *gspca_dev);
132static void setcontrast(struct gspca_dev *gspca_dev);
133static void setcolors(struct gspca_dev *gspca_dev);
134static void setredblue(struct gspca_dev *gspca_dev);
135static void setgamma(struct gspca_dev *gspca_dev);
Jean-François Moinea7705c02012-02-27 06:57:04 -0300136static void setexposure(struct gspca_dev *gspca_dev);
137static int sd_setautogain(struct gspca_dev *gspca_dev, __s32 val);
138static void setgain(struct gspca_dev *gspca_dev);
Németh Márton76ad3b62010-10-19 03:33:47 -0300139static void sethvflip(struct gspca_dev *gspca_dev);
Jean-François Moine72b667e2010-10-02 04:35:25 -0300140static void setsharpness(struct gspca_dev *gspca_dev);
Jean-François Moine3afef852011-01-13 06:39:11 -0300141static void setillum(struct gspca_dev *gspca_dev);
Jean-François Moine72b667e2010-10-02 04:35:25 -0300142static void setfreq(struct gspca_dev *gspca_dev);
Jean-Francois Moine6a7eba22008-06-30 15:50:11 -0300143
Jean-François Moine72b667e2010-10-02 04:35:25 -0300144static const struct ctrl sd_ctrls[NCTRLS] = {
Jean-François Moineb813b0c2011-08-10 05:54:34 -0300145[BRIGHTNESS] = {
Jean-Francois Moine6a7eba22008-06-30 15:50:11 -0300146 {
147 .id = V4L2_CID_BRIGHTNESS,
148 .type = V4L2_CTRL_TYPE_INTEGER,
149 .name = "Brightness",
150 .minimum = 0,
Jean-François Moine72b667e2010-10-02 04:35:25 -0300151 .maximum = 0xff,
Jean-Francois Moine6a7eba22008-06-30 15:50:11 -0300152 .step = 1,
Jean-François Moine72b667e2010-10-02 04:35:25 -0300153 .default_value = 0x80,
Jean-Francois Moine6a7eba22008-06-30 15:50:11 -0300154 },
Jean-François Moine72b667e2010-10-02 04:35:25 -0300155 .set_control = setbrightness
Jean-Francois Moine6a7eba22008-06-30 15:50:11 -0300156 },
Jean-François Moine72b667e2010-10-02 04:35:25 -0300157[CONTRAST] = {
Jean-Francois Moine6a7eba22008-06-30 15:50:11 -0300158 {
159 .id = V4L2_CID_CONTRAST,
160 .type = V4L2_CTRL_TYPE_INTEGER,
161 .name = "Contrast",
162 .minimum = 0,
Jean-Francois Moine05b809c2008-09-03 16:47:59 -0300163#define CONTRAST_MAX 127
164 .maximum = CONTRAST_MAX,
Jean-Francois Moine6a7eba22008-06-30 15:50:11 -0300165 .step = 1,
Jean-François Moineabe8cee2011-08-10 05:13:45 -0300166 .default_value = 20,
Jean-Francois Moine6a7eba22008-06-30 15:50:11 -0300167 },
Jean-François Moine72b667e2010-10-02 04:35:25 -0300168 .set_control = setcontrast
Jean-Francois Moine6a7eba22008-06-30 15:50:11 -0300169 },
Jean-François Moine72b667e2010-10-02 04:35:25 -0300170[COLORS] = {
Jean-Francois Moine6a7eba22008-06-30 15:50:11 -0300171 {
172 .id = V4L2_CID_SATURATION,
173 .type = V4L2_CTRL_TYPE_INTEGER,
Hans de Goede3fb4a572009-06-18 14:31:36 -0300174 .name = "Saturation",
Jean-Francois Moine6a7eba22008-06-30 15:50:11 -0300175 .minimum = 0,
Jean-Francois Moine403123d2008-11-26 04:46:15 -0300176 .maximum = 40,
Jean-Francois Moine6a7eba22008-06-30 15:50:11 -0300177 .step = 1,
Jean-François Moine72b667e2010-10-02 04:35:25 -0300178#define COLORS_DEF 25
179 .default_value = COLORS_DEF,
Jean-Francois Moine6a7eba22008-06-30 15:50:11 -0300180 },
Jean-François Moine72b667e2010-10-02 04:35:25 -0300181 .set_control = setcolors
Jean-Francois Moine6a7eba22008-06-30 15:50:11 -0300182 },
Jean-François Moine72b667e2010-10-02 04:35:25 -0300183[BLUE] = {
Jean-Francois Moine403123d2008-11-26 04:46:15 -0300184 {
185 .id = V4L2_CID_BLUE_BALANCE,
186 .type = V4L2_CTRL_TYPE_INTEGER,
187 .name = "Blue Balance",
188 .minimum = 24,
189 .maximum = 40,
190 .step = 1,
Jean-François Moine72b667e2010-10-02 04:35:25 -0300191 .default_value = 32,
Jean-Francois Moine403123d2008-11-26 04:46:15 -0300192 },
Jean-François Moine72b667e2010-10-02 04:35:25 -0300193 .set_control = setredblue
Jean-Francois Moine403123d2008-11-26 04:46:15 -0300194 },
Jean-François Moine72b667e2010-10-02 04:35:25 -0300195[RED] = {
Jean-Francois Moine403123d2008-11-26 04:46:15 -0300196 {
197 .id = V4L2_CID_RED_BALANCE,
198 .type = V4L2_CTRL_TYPE_INTEGER,
199 .name = "Red Balance",
200 .minimum = 24,
201 .maximum = 40,
202 .step = 1,
Jean-François Moine72b667e2010-10-02 04:35:25 -0300203 .default_value = 32,
Jean-Francois Moine403123d2008-11-26 04:46:15 -0300204 },
Jean-François Moine72b667e2010-10-02 04:35:25 -0300205 .set_control = setredblue
Jean-Francois Moine403123d2008-11-26 04:46:15 -0300206 },
Jean-François Moine72b667e2010-10-02 04:35:25 -0300207[GAMMA] = {
Jean-Francois Moine592f4eb2009-01-15 08:01:32 -0300208 {
209 .id = V4L2_CID_GAMMA,
210 .type = V4L2_CTRL_TYPE_INTEGER,
211 .name = "Gamma",
212 .minimum = 0,
213 .maximum = 40,
214 .step = 1,
215#define GAMMA_DEF 20
216 .default_value = GAMMA_DEF,
217 },
Jean-François Moine72b667e2010-10-02 04:35:25 -0300218 .set_control = setgamma
Jean-Francois Moine592f4eb2009-01-15 08:01:32 -0300219 },
Jean-François Moinea7705c02012-02-27 06:57:04 -0300220[EXPOSURE] = {
221 {
222 .id = V4L2_CID_EXPOSURE,
223 .type = V4L2_CTRL_TYPE_INTEGER,
224 .name = "Exposure",
225 .minimum = 500,
226 .maximum = 1500,
227 .step = 1,
228 .default_value = 1024
229 },
230 .set_control = setexposure
231 },
Jean-François Moine72b667e2010-10-02 04:35:25 -0300232[AUTOGAIN] = {
Jean-Francois Moine6a7eba22008-06-30 15:50:11 -0300233 {
234 .id = V4L2_CID_AUTOGAIN,
235 .type = V4L2_CTRL_TYPE_BOOLEAN,
236 .name = "Auto Gain",
237 .minimum = 0,
238 .maximum = 1,
239 .step = 1,
Jean-François Moine72b667e2010-10-02 04:35:25 -0300240 .default_value = 1
Jean-Francois Moine6a7eba22008-06-30 15:50:11 -0300241 },
Jean-François Moinea7705c02012-02-27 06:57:04 -0300242 .set = sd_setautogain,
243 },
244[GAIN] = {
245 {
246 .id = V4L2_CID_GAIN,
247 .type = V4L2_CTRL_TYPE_INTEGER,
248 .name = "Gain",
249 .minimum = 4,
250 .maximum = 49,
251 .step = 1,
252 .default_value = 15
253 },
254 .set_control = setgain
Jean-Francois Moine6a7eba22008-06-30 15:50:11 -0300255 },
Németh Márton76ad3b62010-10-19 03:33:47 -0300256[HFLIP] = {
257 {
258 .id = V4L2_CID_HFLIP,
259 .type = V4L2_CTRL_TYPE_BOOLEAN,
260 .name = "Mirror",
261 .minimum = 0,
262 .maximum = 1,
263 .step = 1,
264 .default_value = 0,
265 },
266 .set_control = sethvflip
267 },
Jean-François Moine72b667e2010-10-02 04:35:25 -0300268[VFLIP] = {
Jean-Francois Moine6c862742008-09-08 04:57:26 -0300269 {
270 .id = V4L2_CID_VFLIP,
271 .type = V4L2_CTRL_TYPE_BOOLEAN,
272 .name = "Vflip",
273 .minimum = 0,
274 .maximum = 1,
275 .step = 1,
Jean-François Moine72b667e2010-10-02 04:35:25 -0300276 .default_value = 0,
Jean-Francois Moine6c862742008-09-08 04:57:26 -0300277 },
Németh Márton76ad3b62010-10-19 03:33:47 -0300278 .set_control = sethvflip
Jean-Francois Moine6c862742008-09-08 04:57:26 -0300279 },
Jean-François Moine72b667e2010-10-02 04:35:25 -0300280[SHARPNESS] = {
Jean-Francois Moine878b35a2009-12-30 04:53:07 -0300281 {
282 .id = V4L2_CID_SHARPNESS,
283 .type = V4L2_CTRL_TYPE_INTEGER,
284 .name = "Sharpness",
285 .minimum = 0,
286 .maximum = 255,
287 .step = 1,
Jean-François Moine72b667e2010-10-02 04:35:25 -0300288 .default_value = 90,
Jean-Francois Moine878b35a2009-12-30 04:53:07 -0300289 },
Jean-François Moine72b667e2010-10-02 04:35:25 -0300290 .set_control = setsharpness
Jean-Francois Moine878b35a2009-12-30 04:53:07 -0300291 },
Jean-François Moine3afef852011-01-13 06:39:11 -0300292[ILLUM] = {
Jean-Francois Moine0cae8962008-10-17 07:48:24 -0300293 {
Jean-François Moine3afef852011-01-13 06:39:11 -0300294 .id = V4L2_CID_ILLUMINATORS_1,
Jean-Francois Moine0cae8962008-10-17 07:48:24 -0300295 .type = V4L2_CTRL_TYPE_BOOLEAN,
Jean-François Moine3afef852011-01-13 06:39:11 -0300296 .name = "Illuminator / infrared",
Jean-Francois Moine0cae8962008-10-17 07:48:24 -0300297 .minimum = 0,
298 .maximum = 1,
299 .step = 1,
Jean-François Moine72b667e2010-10-02 04:35:25 -0300300 .default_value = 0,
Jean-Francois Moine0cae8962008-10-17 07:48:24 -0300301 },
Jean-François Moine3afef852011-01-13 06:39:11 -0300302 .set_control = setillum
Jean-Francois Moine0cae8962008-10-17 07:48:24 -0300303 },
Hans de Goede37c6dbe2009-06-18 07:35:36 -0300304/* ov7630/ov7648/ov7660 only */
Jean-François Moine72b667e2010-10-02 04:35:25 -0300305[FREQ] = {
Hans de Goede37c6dbe2009-06-18 07:35:36 -0300306 {
307 .id = V4L2_CID_POWER_LINE_FREQUENCY,
308 .type = V4L2_CTRL_TYPE_MENU,
309 .name = "Light frequency filter",
310 .minimum = 0,
311 .maximum = 2, /* 0: 0, 1: 50Hz, 2:60Hz */
312 .step = 1,
Jean-François Moine72b667e2010-10-02 04:35:25 -0300313 .default_value = 1,
Hans de Goede37c6dbe2009-06-18 07:35:36 -0300314 },
Jean-François Moine72b667e2010-10-02 04:35:25 -0300315 .set_control = setfreq
Hans de Goede37c6dbe2009-06-18 07:35:36 -0300316 },
Jean-Francois Moine6a7eba22008-06-30 15:50:11 -0300317};
318
Jean-Francois Moine577cbf42008-12-05 06:18:37 -0300319/* table of the disabled controls */
Jean-François Moine9c33afc2010-03-17 15:25:32 -0300320static const __u32 ctrl_dis[] = {
Jean-François Moinea7705c02012-02-27 06:57:04 -0300321[SENSOR_ADCM1700] = (1 << EXPOSURE) |
322 (1 << AUTOGAIN) |
323 (1 << GAIN) |
Németh Márton76ad3b62010-10-19 03:33:47 -0300324 (1 << HFLIP) |
Jean-François Moine72b667e2010-10-02 04:35:25 -0300325 (1 << VFLIP) |
326 (1 << FREQ),
Jean-François Moine9c33afc2010-03-17 15:25:32 -0300327
Jean-François Moinea7705c02012-02-27 06:57:04 -0300328[SENSOR_GC0307] = (1 << EXPOSURE) |
329 (1 << GAIN) |
330 (1 << HFLIP) |
Jean-François Moine72b667e2010-10-02 04:35:25 -0300331 (1 << VFLIP) |
332 (1 << FREQ),
Jean-François Moinead98c0f2010-03-18 05:15:30 -0300333
Jean-François Moinea7705c02012-02-27 06:57:04 -0300334[SENSOR_HV7131R] = (1 << EXPOSURE) |
335 (1 << GAIN) |
336 (1 << HFLIP) |
Jean-François Moine72b667e2010-10-02 04:35:25 -0300337 (1 << FREQ),
Jean-François Moine9c33afc2010-03-17 15:25:32 -0300338
Jean-François Moinea7705c02012-02-27 06:57:04 -0300339[SENSOR_MI0360] = (1 << EXPOSURE) |
340 (1 << GAIN) |
341 (1 << HFLIP) |
Jean-François Moine72b667e2010-10-02 04:35:25 -0300342 (1 << VFLIP) |
343 (1 << FREQ),
Jean-François Moine9c33afc2010-03-17 15:25:32 -0300344
Jean-François Moinea7705c02012-02-27 06:57:04 -0300345[SENSOR_MI0360B] = (1 << EXPOSURE) |
346 (1 << GAIN) |
347 (1 << HFLIP) |
Jean-François Moine72b667e2010-10-02 04:35:25 -0300348 (1 << VFLIP) |
349 (1 << FREQ),
Jean-François Moinea067db82010-10-01 07:51:24 -0300350
Jean-François Moinea7705c02012-02-27 06:57:04 -0300351[SENSOR_MO4000] = (1 << EXPOSURE) |
352 (1 << GAIN) |
353 (1 << HFLIP) |
Jean-François Moine72b667e2010-10-02 04:35:25 -0300354 (1 << VFLIP) |
355 (1 << FREQ),
Jean-François Moine9c33afc2010-03-17 15:25:32 -0300356
Jean-François Moinea7705c02012-02-27 06:57:04 -0300357[SENSOR_MT9V111] = (1 << EXPOSURE) |
358 (1 << GAIN) |
359 (1 << HFLIP) |
Németh Márton76ad3b62010-10-19 03:33:47 -0300360 (1 << VFLIP) |
Jean-François Moine72b667e2010-10-02 04:35:25 -0300361 (1 << FREQ),
Jean-François Moine9c33afc2010-03-17 15:25:32 -0300362
Jean-François Moinea7705c02012-02-27 06:57:04 -0300363[SENSOR_OM6802] = (1 << EXPOSURE) |
364 (1 << GAIN) |
365 (1 << HFLIP) |
Jean-François Moine72b667e2010-10-02 04:35:25 -0300366 (1 << VFLIP) |
367 (1 << FREQ),
Jean-François Moine9c33afc2010-03-17 15:25:32 -0300368
Jean-François Moinea7705c02012-02-27 06:57:04 -0300369[SENSOR_OV7630] = (1 << EXPOSURE) |
370 (1 << GAIN) |
371 (1 << HFLIP),
Jean-François Moine9c33afc2010-03-17 15:25:32 -0300372
Jean-François Moinea7705c02012-02-27 06:57:04 -0300373[SENSOR_OV7648] = (1 << EXPOSURE) |
374 (1 << GAIN) |
375 (1 << HFLIP),
Jean-François Moine9c33afc2010-03-17 15:25:32 -0300376
Jean-François Moinea7705c02012-02-27 06:57:04 -0300377[SENSOR_OV7660] = (1 << EXPOSURE) |
378 (1 << AUTOGAIN) |
379 (1 << GAIN) |
Németh Márton76ad3b62010-10-19 03:33:47 -0300380 (1 << HFLIP) |
Jean-François Moine72b667e2010-10-02 04:35:25 -0300381 (1 << VFLIP),
Jean-François Moine9c33afc2010-03-17 15:25:32 -0300382
Jean-François Moinea7705c02012-02-27 06:57:04 -0300383[SENSOR_PO1030] = (1 << EXPOSURE) |
384 (1 << AUTOGAIN) |
385 (1 << GAIN) |
Németh Márton76ad3b62010-10-19 03:33:47 -0300386 (1 << HFLIP) |
Jean-François Moine72b667e2010-10-02 04:35:25 -0300387 (1 << VFLIP) |
388 (1 << FREQ),
Jean-François Moine9c33afc2010-03-17 15:25:32 -0300389
Jean-François Moinea7705c02012-02-27 06:57:04 -0300390[SENSOR_PO2030N] = (1 << FREQ),
Jean-François Moine780e3122010-10-19 04:29:10 -0300391
Jean-François Moinea7705c02012-02-27 06:57:04 -0300392[SENSOR_SOI768] = (1 << EXPOSURE) |
393 (1 << AUTOGAIN) |
394 (1 << GAIN) |
Németh Márton76ad3b62010-10-19 03:33:47 -0300395 (1 << HFLIP) |
Jean-François Moine72b667e2010-10-02 04:35:25 -0300396 (1 << VFLIP) |
397 (1 << FREQ),
Jean-François Moinead98c0f2010-03-18 05:15:30 -0300398
Jean-François Moinea7705c02012-02-27 06:57:04 -0300399[SENSOR_SP80708] = (1 << EXPOSURE) |
400 (1 << AUTOGAIN) |
401 (1 << GAIN) |
Németh Márton76ad3b62010-10-19 03:33:47 -0300402 (1 << HFLIP) |
Jean-François Moine72b667e2010-10-02 04:35:25 -0300403 (1 << VFLIP) |
404 (1 << FREQ),
Jean-Francois Moine577cbf42008-12-05 06:18:37 -0300405};
406
Jean-Francois Moine64677572009-12-20 12:31:28 -0300407static const struct v4l2_pix_format cif_mode[] = {
408 {352, 288, V4L2_PIX_FMT_JPEG, V4L2_FIELD_NONE,
409 .bytesperline = 352,
410 .sizeimage = 352 * 288 * 4 / 8 + 590,
411 .colorspace = V4L2_COLORSPACE_JPEG,
412 .priv = 0},
413};
Jean-Francois Moinecc611b82008-12-29 07:49:41 -0300414static const struct v4l2_pix_format vga_mode[] = {
Jean-Francois Moinec2446b32008-07-05 11:49:20 -0300415 {160, 120, V4L2_PIX_FMT_JPEG, V4L2_FIELD_NONE,
416 .bytesperline = 160,
Jean-Francois Moine5d052942008-09-03 16:48:09 -0300417 .sizeimage = 160 * 120 * 4 / 8 + 590,
Jean-Francois Moinec2446b32008-07-05 11:49:20 -0300418 .colorspace = V4L2_COLORSPACE_JPEG,
419 .priv = 2},
420 {320, 240, V4L2_PIX_FMT_JPEG, V4L2_FIELD_NONE,
421 .bytesperline = 320,
422 .sizeimage = 320 * 240 * 3 / 8 + 590,
423 .colorspace = V4L2_COLORSPACE_JPEG,
424 .priv = 1},
425 {640, 480, V4L2_PIX_FMT_JPEG, V4L2_FIELD_NONE,
426 .bytesperline = 640,
Hans de Goedea5d1cc32009-06-18 06:03:20 -0300427 /* Note 3 / 8 is not large enough, not even 5 / 8 is ?! */
428 .sizeimage = 640 * 480 * 3 / 4 + 590,
Jean-Francois Moinec2446b32008-07-05 11:49:20 -0300429 .colorspace = V4L2_COLORSPACE_JPEG,
430 .priv = 0},
Jean-Francois Moine6a7eba22008-06-30 15:50:11 -0300431};
432
Jean-Francois Moine64677572009-12-20 12:31:28 -0300433static const u8 sn_adcm1700[0x1c] = {
434/* reg0 reg1 reg2 reg3 reg4 reg5 reg6 reg7 */
Jean-Francois Moine878b35a2009-12-30 04:53:07 -0300435 0x00, 0x43, 0x60, 0x00, 0x1a, 0x00, 0x00, 0x00,
Jean-Francois Moine64677572009-12-20 12:31:28 -0300436/* reg8 reg9 rega regb regc regd rege regf */
437 0x80, 0x51, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
438/* reg10 reg11 reg12 reg13 reg14 reg15 reg16 reg17 */
439 0x03, 0x00, 0x05, 0x01, 0x05, 0x16, 0x12, 0x42,
440/* reg18 reg19 reg1a reg1b */
441 0x06, 0x00, 0x00, 0x00
442};
443
Jean-François Moinead98c0f2010-03-18 05:15:30 -0300444static const u8 sn_gc0307[0x1c] = {
445/* reg0 reg1 reg2 reg3 reg4 reg5 reg6 reg7 */
446 0x00, 0x61, 0x62, 0x00, 0x1a, 0x00, 0x00, 0x00,
447/* reg8 reg9 rega regb regc regd rege regf */
448 0x80, 0x21, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
449/* reg10 reg11 reg12 reg13 reg14 reg15 reg16 reg17 */
450 0x03, 0x00, 0x03, 0x01, 0x08, 0x28, 0x1e, 0x02,
451/* reg18 reg19 reg1a reg1b */
452 0x06, 0x00, 0x00, 0x00
453};
454
Jean-Francois Moine8c2ba442009-01-13 05:55:40 -0300455static const u8 sn_hv7131[0x1c] = {
Jean-Francois Moine8f47a3c2008-07-29 14:14:04 -0300456/* reg0 reg1 reg2 reg3 reg4 reg5 reg6 reg7 */
Jean-François Moine19697b52010-07-14 06:33:51 -0300457 0x00, 0x03, 0x60, 0x00, 0x1a, 0x20, 0x20, 0x20,
Jean-Francois Moine8f47a3c2008-07-29 14:14:04 -0300458/* reg8 reg9 rega regb regc regd rege regf */
Jean-Francois Moine98941e42009-11-02 09:56:59 -0300459 0x81, 0x11, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
Jean-Francois Moine8f47a3c2008-07-29 14:14:04 -0300460/* reg10 reg11 reg12 reg13 reg14 reg15 reg16 reg17 */
461 0x03, 0x00, 0x00, 0x01, 0x03, 0x28, 0x1e, 0x41,
Jean-Francois Moine8c2ba442009-01-13 05:55:40 -0300462/* reg18 reg19 reg1a reg1b */
463 0x0a, 0x00, 0x00, 0x00
Jean-Francois Moine6a7eba22008-06-30 15:50:11 -0300464};
465
Jean-Francois Moine8c2ba442009-01-13 05:55:40 -0300466static const u8 sn_mi0360[0x1c] = {
Jean-Francois Moine8f47a3c2008-07-29 14:14:04 -0300467/* reg0 reg1 reg2 reg3 reg4 reg5 reg6 reg7 */
Jean-François Moine20c957b2011-02-10 13:18:58 -0300468 0x00, 0x63, 0x40, 0x00, 0x1a, 0x20, 0x20, 0x20,
Jean-Francois Moine8f47a3c2008-07-29 14:14:04 -0300469/* reg8 reg9 rega regb regc regd rege regf */
Jean-Francois Moine98941e42009-11-02 09:56:59 -0300470 0x81, 0x5d, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
Jean-Francois Moine8f47a3c2008-07-29 14:14:04 -0300471/* reg10 reg11 reg12 reg13 reg14 reg15 reg16 reg17 */
472 0x03, 0x00, 0x00, 0x02, 0x0a, 0x28, 0x1e, 0x61,
Jean-Francois Moine8c2ba442009-01-13 05:55:40 -0300473/* reg18 reg19 reg1a reg1b */
474 0x06, 0x00, 0x00, 0x00
Jean-Francois Moine6a7eba22008-06-30 15:50:11 -0300475};
476
Jean-François Moinea067db82010-10-01 07:51:24 -0300477static const u8 sn_mi0360b[0x1c] = {
478/* reg0 reg1 reg2 reg3 reg4 reg5 reg6 reg7 */
479 0x00, 0x61, 0x40, 0x00, 0x1a, 0x00, 0x00, 0x00,
480/* reg8 reg9 rega regb regc regd rege regf */
481 0x81, 0x5d, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
482/* reg10 reg11 reg12 reg13 reg14 reg15 reg16 reg17 */
483 0x03, 0x00, 0x00, 0x02, 0x0a, 0x28, 0x1e, 0x40,
484/* reg18 reg19 reg1a reg1b */
485 0x06, 0x00, 0x00, 0x00
486};
487
Jean-Francois Moine8c2ba442009-01-13 05:55:40 -0300488static const u8 sn_mo4000[0x1c] = {
Jean-Francois Moine8f47a3c2008-07-29 14:14:04 -0300489/* reg0 reg1 reg2 reg3 reg4 reg5 reg6 reg7 */
Jean-Francois Moine8c2ba442009-01-13 05:55:40 -0300490 0x00, 0x23, 0x60, 0x00, 0x1a, 0x00, 0x20, 0x18,
Jean-Francois Moine8f47a3c2008-07-29 14:14:04 -0300491/* reg8 reg9 rega regb regc regd rege regf */
492 0x81, 0x21, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
493/* reg10 reg11 reg12 reg13 reg14 reg15 reg16 reg17 */
494 0x03, 0x00, 0x0b, 0x0f, 0x14, 0x28, 0x1e, 0x40,
Jean-Francois Moine8c2ba442009-01-13 05:55:40 -0300495/* reg18 reg19 reg1a reg1b */
496 0x08, 0x00, 0x00, 0x00
Jean-Francois Moine6a7eba22008-06-30 15:50:11 -0300497};
498
Jean-Francois Moine3ef2c5b2009-01-29 04:59:45 -0300499static const u8 sn_mt9v111[0x1c] = {
500/* reg0 reg1 reg2 reg3 reg4 reg5 reg6 reg7 */
501 0x00, 0x61, 0x40, 0x00, 0x1a, 0x20, 0x20, 0x20,
502/* reg8 reg9 rega regb regc regd rege regf */
Jean-Francois Moine98941e42009-11-02 09:56:59 -0300503 0x81, 0x5c, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
Jean-Francois Moine3ef2c5b2009-01-29 04:59:45 -0300504/* reg10 reg11 reg12 reg13 reg14 reg15 reg16 reg17 */
505 0x03, 0x00, 0x00, 0x02, 0x1c, 0x28, 0x1e, 0x40,
506/* reg18 reg19 reg1a reg1b */
507 0x06, 0x00, 0x00, 0x00
508};
509
Jean-Francois Moine8c2ba442009-01-13 05:55:40 -0300510static const u8 sn_om6802[0x1c] = {
Jean-Francois Moined2d16e92008-09-03 16:47:23 -0300511/* reg0 reg1 reg2 reg3 reg4 reg5 reg6 reg7 */
Amauri Magagna46b4f2a2009-10-17 07:21:29 -0300512 0x00, 0x23, 0x72, 0x00, 0x1a, 0x20, 0x20, 0x19,
Jean-Francois Moined2d16e92008-09-03 16:47:23 -0300513/* reg8 reg9 rega regb regc regd rege regf */
514 0x80, 0x34, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
515/* reg10 reg11 reg12 reg13 reg14 reg15 reg16 reg17 */
516 0x03, 0x00, 0x51, 0x01, 0x00, 0x28, 0x1e, 0x40,
Jean-Francois Moine8c2ba442009-01-13 05:55:40 -0300517/* reg18 reg19 reg1a reg1b */
518 0x05, 0x00, 0x00, 0x00
Jean-Francois Moined2d16e92008-09-03 16:47:23 -0300519};
520
Jean-Francois Moine8c2ba442009-01-13 05:55:40 -0300521static const u8 sn_ov7630[0x1c] = {
Jean-Francois Moine6ab0b172008-09-03 16:47:34 -0300522/* reg0 reg1 reg2 reg3 reg4 reg5 reg6 reg7 */
Jean-François Moine0a85c742010-04-25 14:33:31 -0300523 0x00, 0x21, 0x40, 0x00, 0x1a, 0x00, 0x00, 0x00,
Jean-Francois Moine6ab0b172008-09-03 16:47:34 -0300524/* reg8 reg9 rega regb regc regd rege regf */
Jean-Francois Moine98941e42009-11-02 09:56:59 -0300525 0x81, 0x21, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
Jean-Francois Moine6ab0b172008-09-03 16:47:34 -0300526/* reg10 reg11 reg12 reg13 reg14 reg15 reg16 reg17 */
527 0x03, 0x00, 0x04, 0x01, 0x0a, 0x28, 0x1e, 0xc2,
Jean-Francois Moine8c2ba442009-01-13 05:55:40 -0300528/* reg18 reg19 reg1a reg1b */
529 0x0b, 0x00, 0x00, 0x00
Jean-Francois Moine6ab0b172008-09-03 16:47:34 -0300530};
531
Jean-Francois Moine8c2ba442009-01-13 05:55:40 -0300532static const u8 sn_ov7648[0x1c] = {
Jean-Francois Moine8f47a3c2008-07-29 14:14:04 -0300533/* reg0 reg1 reg2 reg3 reg4 reg5 reg6 reg7 */
Jean-Francois Moine62703302008-11-11 08:42:56 -0300534 0x00, 0x63, 0x40, 0x00, 0x1a, 0x20, 0x20, 0x20,
Jean-Francois Moine8f47a3c2008-07-29 14:14:04 -0300535/* reg8 reg9 rega regb regc regd rege regf */
Jean-Francois Moine98941e42009-11-02 09:56:59 -0300536 0x81, 0x21, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
Jean-Francois Moine8f47a3c2008-07-29 14:14:04 -0300537/* reg10 reg11 reg12 reg13 reg14 reg15 reg16 reg17 */
Jean-Francois Moine62703302008-11-11 08:42:56 -0300538 0x03, 0x00, 0x00, 0x01, 0x00, 0x28, 0x1e, 0x00,
Jean-Francois Moine8c2ba442009-01-13 05:55:40 -0300539/* reg18 reg19 reg1a reg1b */
540 0x0b, 0x00, 0x00, 0x00
Jean-Francois Moine6a7eba22008-06-30 15:50:11 -0300541};
542
Jean-Francois Moine8c2ba442009-01-13 05:55:40 -0300543static const u8 sn_ov7660[0x1c] = {
Jean-Francois Moine8f47a3c2008-07-29 14:14:04 -0300544/* reg0 reg1 reg2 reg3 reg4 reg5 reg6 reg7 */
Jean-Francois Moinec8b9b2ca2009-04-26 14:46:12 -0300545 0x00, 0x61, 0x40, 0x00, 0x1a, 0x00, 0x00, 0x00,
Jean-Francois Moine8f47a3c2008-07-29 14:14:04 -0300546/* reg8 reg9 rega regb regc regd rege regf */
Jean-Francois Moinec8b9b2ca2009-04-26 14:46:12 -0300547 0x81, 0x21, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
Jean-Francois Moine8f47a3c2008-07-29 14:14:04 -0300548/* reg10 reg11 reg12 reg13 reg14 reg15 reg16 reg17 */
549 0x03, 0x00, 0x01, 0x01, 0x08, 0x28, 0x1e, 0x20,
Jean-Francois Moine8c2ba442009-01-13 05:55:40 -0300550/* reg18 reg19 reg1a reg1b */
551 0x07, 0x00, 0x00, 0x00
Jean-Francois Moine6a7eba22008-06-30 15:50:11 -0300552};
553
Jean-Francois Moineb8c8a5b2009-11-23 06:46:35 -0300554static const u8 sn_po1030[0x1c] = {
555/* reg0 reg1 reg2 reg3 reg4 reg5 reg6 reg7 */
556 0x00, 0x21, 0x62, 0x00, 0x1a, 0x20, 0x20, 0x20,
557/* reg8 reg9 rega regb regc regd rege regf */
558 0x81, 0x6e, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
559/* reg10 reg11 reg12 reg13 reg14 reg15 reg16 reg17 */
560 0x03, 0x00, 0x00, 0x06, 0x06, 0x28, 0x1e, 0x00,
561/* reg18 reg19 reg1a reg1b */
562 0x07, 0x00, 0x00, 0x00
563};
564
Jean-François Moinead98c0f2010-03-18 05:15:30 -0300565static const u8 sn_po2030n[0x1c] = {
566/* reg0 reg1 reg2 reg3 reg4 reg5 reg6 reg7 */
567 0x00, 0x63, 0x40, 0x00, 0x1a, 0x00, 0x00, 0x00,
568/* reg8 reg9 rega regb regc regd rege regf */
569 0x81, 0x6e, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
570/* reg10 reg11 reg12 reg13 reg14 reg15 reg16 reg17 */
571 0x03, 0x00, 0x00, 0x01, 0x14, 0x28, 0x1e, 0x00,
572/* reg18 reg19 reg1a reg1b */
573 0x07, 0x00, 0x00, 0x00
574};
575
Jean-François Moine03ed2a12010-04-25 14:45:43 -0300576static const u8 sn_soi768[0x1c] = {
577/* reg0 reg1 reg2 reg3 reg4 reg5 reg6 reg7 */
578 0x00, 0x21, 0x40, 0x00, 0x1a, 0x00, 0x00, 0x00,
579/* reg8 reg9 rega regb regc regd rege regf */
580 0x81, 0x21, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
581/* reg10 reg11 reg12 reg13 reg14 reg15 reg16 reg17 */
582 0x03, 0x00, 0x00, 0x01, 0x08, 0x28, 0x1e, 0x00,
583/* reg18 reg19 reg1a reg1b */
584 0x07, 0x00, 0x00, 0x00
585};
586
Jean-Francois Moine5e31dc82009-02-01 13:59:42 -0300587static const u8 sn_sp80708[0x1c] = {
588/* reg0 reg1 reg2 reg3 reg4 reg5 reg6 reg7 */
589 0x00, 0x63, 0x60, 0x00, 0x1a, 0x20, 0x20, 0x20,
590/* reg8 reg9 rega regb regc regd rege regf */
Jean-Francois Moine98941e42009-11-02 09:56:59 -0300591 0x81, 0x18, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
Jean-Francois Moine5e31dc82009-02-01 13:59:42 -0300592/* reg10 reg11 reg12 reg13 reg14 reg15 reg16 reg17 */
593 0x03, 0x00, 0x00, 0x03, 0x04, 0x28, 0x1e, 0x00,
594/* reg18 reg19 reg1a reg1b */
595 0x07, 0x00, 0x00, 0x00
596};
597
Jean-Francois Moine6a7eba22008-06-30 15:50:11 -0300598/* sequence specific to the sensors - !! index = SENSOR_xxx */
Jean-Francois Moine8c2ba442009-01-13 05:55:40 -0300599static const u8 *sn_tb[] = {
Jean-François Moine9c33afc2010-03-17 15:25:32 -0300600[SENSOR_ADCM1700] = sn_adcm1700,
Jean-François Moinead98c0f2010-03-18 05:15:30 -0300601[SENSOR_GC0307] = sn_gc0307,
Jean-François Moine9c33afc2010-03-17 15:25:32 -0300602[SENSOR_HV7131R] = sn_hv7131,
603[SENSOR_MI0360] = sn_mi0360,
Jean-François Moinea067db82010-10-01 07:51:24 -0300604[SENSOR_MI0360B] = sn_mi0360b,
Jean-François Moine9c33afc2010-03-17 15:25:32 -0300605[SENSOR_MO4000] = sn_mo4000,
606[SENSOR_MT9V111] = sn_mt9v111,
607[SENSOR_OM6802] = sn_om6802,
608[SENSOR_OV7630] = sn_ov7630,
609[SENSOR_OV7648] = sn_ov7648,
610[SENSOR_OV7660] = sn_ov7660,
611[SENSOR_PO1030] = sn_po1030,
Jean-François Moinead98c0f2010-03-18 05:15:30 -0300612[SENSOR_PO2030N] = sn_po2030n,
Jean-François Moine03ed2a12010-04-25 14:45:43 -0300613[SENSOR_SOI768] = sn_soi768,
614[SENSOR_SP80708] = sn_sp80708,
Jean-Francois Moine6a7eba22008-06-30 15:50:11 -0300615};
616
Jean-Francois Moineb083b922009-02-01 14:20:07 -0300617/* default gamma table */
Jean-Francois Moine98819182009-01-19 07:37:33 -0300618static const u8 gamma_def[17] = {
Jean-Francois Moine6a7eba22008-06-30 15:50:11 -0300619 0x00, 0x2d, 0x46, 0x5a, 0x6c, 0x7c, 0x8b, 0x99,
620 0xa6, 0xb2, 0xbf, 0xca, 0xd5, 0xe0, 0xeb, 0xf5, 0xff
621};
Jean-Francois Moine64677572009-12-20 12:31:28 -0300622/* gamma for sensor ADCM1700 */
623static const u8 gamma_spec_0[17] = {
624 0x0f, 0x39, 0x5a, 0x74, 0x86, 0x95, 0xa6, 0xb4,
625 0xbd, 0xc4, 0xcc, 0xd4, 0xd5, 0xde, 0xe4, 0xed, 0xf5
626};
Jean-Francois Moineb083b922009-02-01 14:20:07 -0300627/* gamma for sensors HV7131R and MT9V111 */
628static const u8 gamma_spec_1[17] = {
629 0x08, 0x3a, 0x52, 0x65, 0x75, 0x83, 0x91, 0x9d,
630 0xa9, 0xb4, 0xbe, 0xc8, 0xd2, 0xdb, 0xe4, 0xed, 0xf5
631};
Jean-François Moinead98c0f2010-03-18 05:15:30 -0300632/* gamma for sensor GC0307 */
Jean-Francois Moineb083b922009-02-01 14:20:07 -0300633static const u8 gamma_spec_2[17] = {
Jean-François Moinead98c0f2010-03-18 05:15:30 -0300634 0x14, 0x37, 0x50, 0x6a, 0x7c, 0x8d, 0x9d, 0xab,
635 0xb5, 0xbf, 0xc2, 0xcb, 0xd1, 0xd6, 0xdb, 0xe1, 0xeb
636};
637/* gamma for sensor SP80708 */
638static const u8 gamma_spec_3[17] = {
Jean-Francois Moineb083b922009-02-01 14:20:07 -0300639 0x0a, 0x2d, 0x4e, 0x68, 0x7d, 0x8f, 0x9f, 0xab,
640 0xb7, 0xc2, 0xcc, 0xd3, 0xd8, 0xde, 0xe2, 0xe5, 0xe6
641};
Jean-Francois Moine592f4eb2009-01-15 08:01:32 -0300642
Jean-Francois Moine803f9cc2008-10-04 14:17:02 -0300643/* color matrix and offsets */
Jean-Francois Moine98819182009-01-19 07:37:33 -0300644static const u8 reg84[] = {
Jean-Francois Moine803f9cc2008-10-04 14:17:02 -0300645 0x14, 0x00, 0x27, 0x00, 0x07, 0x00, /* YR YG YB gains */
646 0xe8, 0x0f, 0xda, 0x0f, 0x40, 0x00, /* UR UG UB */
647 0x3e, 0x00, 0xcd, 0x0f, 0xf7, 0x0f, /* VR VG VB */
648 0x00, 0x00, 0x00 /* YUV offsets */
Jean-Francois Moine6a7eba22008-06-30 15:50:11 -0300649};
Németh Mártonccbc5df2010-10-18 07:00:48 -0300650
651#define DELAY 0xdd
652
Jean-Francois Moine64677572009-12-20 12:31:28 -0300653static const u8 adcm1700_sensor_init[][8] = {
654 {0xa0, 0x51, 0xfe, 0x00, 0x00, 0x00, 0x00, 0x10},
Jean-Francois Moine878b35a2009-12-30 04:53:07 -0300655 {0xb0, 0x51, 0x04, 0x08, 0x00, 0x00, 0x00, 0x10}, /* reset */
Németh Mártonccbc5df2010-10-18 07:00:48 -0300656 {DELAY, 0x80, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00},
Jean-Francois Moine64677572009-12-20 12:31:28 -0300657 {0xb0, 0x51, 0x04, 0x00, 0x00, 0x00, 0x00, 0x10},
Németh Mártonccbc5df2010-10-18 07:00:48 -0300658 {DELAY, 0x80, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00},
Jean-Francois Moine64677572009-12-20 12:31:28 -0300659 {0xb0, 0x51, 0x0c, 0xe0, 0x2e, 0x00, 0x00, 0x10},
660 {0xb0, 0x51, 0x10, 0x02, 0x02, 0x00, 0x00, 0x10},
661 {0xb0, 0x51, 0x14, 0x0e, 0x0e, 0x00, 0x00, 0x10},
662 {0xb0, 0x51, 0x1c, 0x00, 0x80, 0x00, 0x00, 0x10},
663 {0xb0, 0x51, 0x20, 0x01, 0x00, 0x00, 0x00, 0x10},
Németh Mártonccbc5df2010-10-18 07:00:48 -0300664 {DELAY, 0xff, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00},
Jean-Francois Moine64677572009-12-20 12:31:28 -0300665 {0xb0, 0x51, 0x04, 0x04, 0x00, 0x00, 0x00, 0x10},
Németh Mártonccbc5df2010-10-18 07:00:48 -0300666 {DELAY, 0xff, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00},
Jean-Francois Moine64677572009-12-20 12:31:28 -0300667 {0xb0, 0x51, 0x04, 0x01, 0x00, 0x00, 0x00, 0x10},
668 {0xa0, 0x51, 0xfe, 0x10, 0x00, 0x00, 0x00, 0x10},
669 {0xb0, 0x51, 0x14, 0x01, 0x00, 0x00, 0x00, 0x10},
670 {0xb0, 0x51, 0x32, 0x00, 0x00, 0x00, 0x00, 0x10},
671 {}
672};
673static const u8 adcm1700_sensor_param1[][8] = {
Jean-Francois Moine878b35a2009-12-30 04:53:07 -0300674 {0xb0, 0x51, 0x26, 0xf9, 0x01, 0x00, 0x00, 0x10}, /* exposure? */
Jean-Francois Moine64677572009-12-20 12:31:28 -0300675 {0xd0, 0x51, 0x1e, 0x8e, 0x8e, 0x8e, 0x8e, 0x10},
676
677 {0xa0, 0x51, 0xfe, 0x01, 0x00, 0x00, 0x00, 0x10},
678 {0xb0, 0x51, 0x00, 0x02, 0x00, 0x00, 0x00, 0x10},
679 {0xa0, 0x51, 0xfe, 0x10, 0x00, 0x00, 0x00, 0x10},
680 {0xb0, 0x51, 0x32, 0x00, 0x72, 0x00, 0x00, 0x10},
Jean-Francois Moine878b35a2009-12-30 04:53:07 -0300681 {0xd0, 0x51, 0x1e, 0xbe, 0xd7, 0xe8, 0xbe, 0x10}, /* exposure? */
Jean-Francois Moine64677572009-12-20 12:31:28 -0300682
Jean-Francois Moine878b35a2009-12-30 04:53:07 -0300683 {0xa0, 0x51, 0xfe, 0x01, 0x00, 0x00, 0x00, 0x10},
684 {0xb0, 0x51, 0x00, 0x02, 0x00, 0x00, 0x00, 0x10},
685 {0xa0, 0x51, 0xfe, 0x10, 0x00, 0x00, 0x00, 0x10},
686 {0xb0, 0x51, 0x32, 0x00, 0xa2, 0x00, 0x00, 0x10},
Jean-Francois Moine64677572009-12-20 12:31:28 -0300687 {}
688};
Jean-François Moinead98c0f2010-03-18 05:15:30 -0300689static const u8 gc0307_sensor_init[][8] = {
690 {0xa0, 0x21, 0x43, 0x00, 0x00, 0x00, 0x00, 0x10},
691 {0xa0, 0x21, 0x44, 0xa2, 0x00, 0x00, 0x00, 0x10},
692 {0xa0, 0x21, 0x01, 0x6a, 0x00, 0x00, 0x00, 0x10},
693 {0xa0, 0x21, 0x02, 0x70, 0x00, 0x00, 0x00, 0x10},
694 {0xa0, 0x21, 0x10, 0x00, 0x00, 0x00, 0x00, 0x10},
695 {0xa0, 0x21, 0x1c, 0x00, 0x00, 0x00, 0x00, 0x10},
696 {0xa0, 0x21, 0x1d, 0x00, 0x00, 0x00, 0x00, 0x10},
697 {0xa0, 0x21, 0x11, 0x05, 0x00, 0x00, 0x00, 0x10},
698 {0xa0, 0x21, 0x05, 0x00, 0x00, 0x00, 0x00, 0x10},
699 {0xa0, 0x21, 0x06, 0x00, 0x00, 0x00, 0x00, 0x10},
700 {0xa0, 0x21, 0x07, 0x00, 0x00, 0x00, 0x00, 0x10},
701 {0xa0, 0x21, 0x08, 0x02, 0x00, 0x00, 0x00, 0x10},
702 {0xa0, 0x21, 0x09, 0x01, 0x00, 0x00, 0x00, 0x10},
703 {0xa0, 0x21, 0x0a, 0xe8, 0x00, 0x00, 0x00, 0x10},
704 {0xa0, 0x21, 0x0b, 0x02, 0x00, 0x00, 0x00, 0x10},
705 {0xa0, 0x21, 0x0c, 0x80, 0x00, 0x00, 0x00, 0x10},
706 {0xa0, 0x21, 0x0d, 0x22, 0x00, 0x00, 0x00, 0x10},
707 {0xa0, 0x21, 0x0e, 0x02, 0x00, 0x00, 0x00, 0x10},
708 {0xa0, 0x21, 0x0f, 0xb2, 0x00, 0x00, 0x00, 0x10},
709 {0xa0, 0x21, 0x12, 0x70, 0x00, 0x00, 0x00, 0x10},
Németh Mártonccbc5df2010-10-18 07:00:48 -0300710 {DELAY, 0x0a, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00}, /*delay 10ms*/
Jean-François Moinead98c0f2010-03-18 05:15:30 -0300711 {0xa0, 0x21, 0x13, 0x00, 0x00, 0x00, 0x00, 0x10},
712 {0xa0, 0x21, 0x15, 0xb8, 0x00, 0x00, 0x00, 0x10},
713 {0xa0, 0x21, 0x16, 0x13, 0x00, 0x00, 0x00, 0x10},
714 {0xa0, 0x21, 0x17, 0x52, 0x00, 0x00, 0x00, 0x10},
715 {0xa0, 0x21, 0x18, 0x50, 0x00, 0x00, 0x00, 0x10},
716 {0xa0, 0x21, 0x1e, 0x0d, 0x00, 0x00, 0x00, 0x10},
717 {0xa0, 0x21, 0x1f, 0x32, 0x00, 0x00, 0x00, 0x10},
718 {0xa0, 0x21, 0x61, 0x90, 0x00, 0x00, 0x00, 0x10},
719 {0xa0, 0x21, 0x63, 0x70, 0x00, 0x00, 0x00, 0x10},
720 {0xa0, 0x21, 0x65, 0x98, 0x00, 0x00, 0x00, 0x10},
721 {0xa0, 0x21, 0x67, 0x90, 0x00, 0x00, 0x00, 0x10},
722 {0xa0, 0x21, 0x03, 0x00, 0x00, 0x00, 0x00, 0x10},
723 {0xa0, 0x21, 0x04, 0x96, 0x00, 0x00, 0x00, 0x10},
724 {0xa0, 0x21, 0x45, 0x27, 0x00, 0x00, 0x00, 0x10},
725 {0xa0, 0x21, 0x47, 0x2c, 0x00, 0x00, 0x00, 0x10},
726 {0xa0, 0x21, 0x43, 0x47, 0x00, 0x00, 0x00, 0x10},
727 {0xa0, 0x21, 0x44, 0xd8, 0x00, 0x00, 0x00, 0x10},
728 {}
729};
730static const u8 gc0307_sensor_param1[][8] = {
731 {0xa0, 0x21, 0x68, 0x13, 0x00, 0x00, 0x00, 0x10},
732 {0xd0, 0x21, 0x61, 0x80, 0x00, 0x80, 0x00, 0x10},
733 {0xc0, 0x21, 0x65, 0x80, 0x00, 0x80, 0x00, 0x10},
734 {0xc0, 0x21, 0x63, 0xa0, 0x00, 0xa6, 0x00, 0x10},
735/*param3*/
736 {0xa0, 0x21, 0x01, 0x6e, 0x00, 0x00, 0x00, 0x10},
737 {0xa0, 0x21, 0x02, 0x88, 0x00, 0x00, 0x00, 0x10},
Jean-François Moinead98c0f2010-03-18 05:15:30 -0300738 {}
739};
740
Jean-Francois Moine98819182009-01-19 07:37:33 -0300741static const u8 hv7131r_sensor_init[][8] = {
Jean-Francois Moine8c2ba442009-01-13 05:55:40 -0300742 {0xc1, 0x11, 0x01, 0x08, 0x01, 0x00, 0x00, 0x10},
743 {0xb1, 0x11, 0x34, 0x17, 0x7f, 0x00, 0x00, 0x10},
744 {0xd1, 0x11, 0x40, 0xff, 0x7f, 0x7f, 0x7f, 0x10},
745/* {0x91, 0x11, 0x44, 0x00, 0x00, 0x00, 0x00, 0x10}, */
746 {0xd1, 0x11, 0x10, 0x00, 0x00, 0x00, 0x00, 0x10},
747 {0xd1, 0x11, 0x14, 0x01, 0xe2, 0x02, 0x82, 0x10},
748/* {0x91, 0x11, 0x18, 0x00, 0x00, 0x00, 0x00, 0x10}, */
Jean-Francois Moine6a7eba22008-06-30 15:50:11 -0300749
Jean-Francois Moine8c2ba442009-01-13 05:55:40 -0300750 {0xa1, 0x11, 0x01, 0x08, 0x00, 0x00, 0x00, 0x10},
751 {0xa1, 0x11, 0x01, 0x08, 0x00, 0x00, 0x00, 0x10},
752 {0xc1, 0x11, 0x25, 0x00, 0x61, 0xa8, 0x00, 0x10},
753 {0xa1, 0x11, 0x30, 0x22, 0x00, 0x00, 0x00, 0x10},
754 {0xc1, 0x11, 0x31, 0x20, 0x2e, 0x20, 0x00, 0x10},
755 {0xc1, 0x11, 0x25, 0x00, 0xc3, 0x50, 0x00, 0x10},
756 {0xa1, 0x11, 0x30, 0x07, 0x00, 0x00, 0x00, 0x10}, /* gain14 */
757 {0xc1, 0x11, 0x31, 0x10, 0x10, 0x10, 0x00, 0x10}, /* r g b 101a10 */
Jean-Francois Moine6a7eba22008-06-30 15:50:11 -0300758
Jean-Francois Moine8c2ba442009-01-13 05:55:40 -0300759 {0xa1, 0x11, 0x01, 0x08, 0x00, 0x00, 0x00, 0x10},
760 {0xa1, 0x11, 0x20, 0x00, 0x00, 0x00, 0x00, 0x10},
Jean-Francois Moine7fb101a2009-10-22 06:27:14 -0300761 {0xa1, 0x11, 0x21, 0xd0, 0x00, 0x00, 0x00, 0x10},
Jean-Francois Moine8c2ba442009-01-13 05:55:40 -0300762 {0xa1, 0x11, 0x22, 0x00, 0x00, 0x00, 0x00, 0x10},
763 {0xa1, 0x11, 0x23, 0x09, 0x00, 0x00, 0x00, 0x10},
Jean-Francois Moine6a7eba22008-06-30 15:50:11 -0300764
Jean-Francois Moine8c2ba442009-01-13 05:55:40 -0300765 {0xa1, 0x11, 0x01, 0x08, 0x00, 0x00, 0x00, 0x10},
766 {0xa1, 0x11, 0x20, 0x00, 0x00, 0x00, 0x00, 0x10},
767 {0xa1, 0x11, 0x21, 0xd0, 0x00, 0x00, 0x00, 0x10},
768 {0xa1, 0x11, 0x22, 0x00, 0x00, 0x00, 0x00, 0x10},
769 {0xa1, 0x11, 0x23, 0x10, 0x00, 0x00, 0x00, 0x10},
Jean-Francois Moine23a98272009-11-02 09:10:25 -0300770 {0xa1, 0x11, 0x01, 0x18, 0x00, 0x00, 0x00, 0x10},
771 /* set sensor clock */
Jean-Francois Moinea5ae2062008-07-04 11:16:16 -0300772 {}
Jean-Francois Moine6a7eba22008-06-30 15:50:11 -0300773};
Jean-Francois Moine98819182009-01-19 07:37:33 -0300774static const u8 mi0360_sensor_init[][8] = {
Jean-Francois Moine8c2ba442009-01-13 05:55:40 -0300775 {0xb1, 0x5d, 0x07, 0x00, 0x02, 0x00, 0x00, 0x10},
Jean-Francois Moine98819182009-01-19 07:37:33 -0300776 {0xb1, 0x5d, 0x0d, 0x00, 0x01, 0x00, 0x00, 0x10},
Jean-Francois Moine3ef2c5b2009-01-29 04:59:45 -0300777 {0xb1, 0x5d, 0x0d, 0x00, 0x00, 0x00, 0x00, 0x10},
Jean-Francois Moine8c2ba442009-01-13 05:55:40 -0300778 {0xd1, 0x5d, 0x01, 0x00, 0x08, 0x00, 0x16, 0x10},
779 {0xd1, 0x5d, 0x03, 0x01, 0xe2, 0x02, 0x82, 0x10},
780 {0xd1, 0x5d, 0x05, 0x00, 0x09, 0x00, 0x53, 0x10},
781 {0xb1, 0x5d, 0x0d, 0x00, 0x02, 0x00, 0x00, 0x10},
782 {0xd1, 0x5d, 0x0a, 0x00, 0x00, 0x00, 0x00, 0x10},
783 {0xd1, 0x5d, 0x0c, 0x00, 0x00, 0x00, 0x00, 0x10},
784 {0xd1, 0x5d, 0x0e, 0x00, 0x00, 0x00, 0x00, 0x10},
785 {0xd1, 0x5d, 0x10, 0x00, 0x00, 0x00, 0x00, 0x10},
786 {0xd1, 0x5d, 0x12, 0x00, 0x00, 0x00, 0x00, 0x10},
787 {0xd1, 0x5d, 0x14, 0x00, 0x00, 0x00, 0x00, 0x10},
788 {0xd1, 0x5d, 0x16, 0x00, 0x00, 0x00, 0x00, 0x10},
789 {0xd1, 0x5d, 0x18, 0x00, 0x00, 0x00, 0x00, 0x10},
790 {0xd1, 0x5d, 0x1a, 0x00, 0x00, 0x00, 0x00, 0x10},
791 {0xd1, 0x5d, 0x1c, 0x00, 0x00, 0x00, 0x00, 0x10},
792 {0xb1, 0x5d, 0x32, 0x00, 0x00, 0x00, 0x00, 0x10},
793 {0xd1, 0x5d, 0x20, 0x91, 0x01, 0x00, 0x00, 0x10},
794 {0xd1, 0x5d, 0x22, 0x00, 0x00, 0x00, 0x00, 0x10},
795 {0xd1, 0x5d, 0x24, 0x00, 0x00, 0x00, 0x00, 0x10},
796 {0xd1, 0x5d, 0x26, 0x00, 0x00, 0x00, 0x24, 0x10},
Jean-François Moineb813b0c2011-08-10 05:54:34 -0300797 {0xd1, 0x5d, 0x2f, 0xf7, 0xb0, 0x00, 0x04, 0x10},
Jean-Francois Moine8c2ba442009-01-13 05:55:40 -0300798 {0xd1, 0x5d, 0x31, 0x00, 0x00, 0x00, 0x00, 0x10},
799 {0xd1, 0x5d, 0x33, 0x00, 0x00, 0x01, 0x00, 0x10},
800 {0xb1, 0x5d, 0x3d, 0x06, 0x8f, 0x00, 0x00, 0x10},
801 {0xd1, 0x5d, 0x40, 0x01, 0xe0, 0x00, 0xd1, 0x10},
802 {0xb1, 0x5d, 0x44, 0x00, 0x82, 0x00, 0x00, 0x10},
803 {0xd1, 0x5d, 0x58, 0x00, 0x78, 0x00, 0x43, 0x10},
804 {0xd1, 0x5d, 0x5a, 0x00, 0x00, 0x00, 0x00, 0x10},
805 {0xd1, 0x5d, 0x5c, 0x00, 0x00, 0x00, 0x00, 0x10},
806 {0xd1, 0x5d, 0x5e, 0x00, 0x00, 0xa3, 0x1d, 0x10},
807 {0xb1, 0x5d, 0x62, 0x04, 0x11, 0x00, 0x00, 0x10},
Jean-Francois Moine6a7eba22008-06-30 15:50:11 -0300808
Jean-Francois Moine8c2ba442009-01-13 05:55:40 -0300809 {0xb1, 0x5d, 0x20, 0x91, 0x01, 0x00, 0x00, 0x10},
810 {0xb1, 0x5d, 0x20, 0x11, 0x01, 0x00, 0x00, 0x10},
811 {0xb1, 0x5d, 0x09, 0x00, 0x64, 0x00, 0x00, 0x10},
812 {0xd1, 0x5d, 0x2b, 0x00, 0xa0, 0x00, 0xb0, 0x10},
813 {0xd1, 0x5d, 0x2d, 0x00, 0xa0, 0x00, 0xa0, 0x10},
Jean-Francois Moine6a7eba22008-06-30 15:50:11 -0300814
Jean-Francois Moine8c2ba442009-01-13 05:55:40 -0300815 {0xb1, 0x5d, 0x0a, 0x00, 0x02, 0x00, 0x00, 0x10}, /* sensor clck ?2 */
816 {0xb1, 0x5d, 0x06, 0x00, 0x30, 0x00, 0x00, 0x10},
817 {0xb1, 0x5d, 0x05, 0x00, 0x0a, 0x00, 0x00, 0x10},
818 {0xb1, 0x5d, 0x09, 0x02, 0x35, 0x00, 0x00, 0x10}, /* exposure 2 */
Jean-Francois Moine6a7eba22008-06-30 15:50:11 -0300819
Jean-Francois Moine8c2ba442009-01-13 05:55:40 -0300820 {0xd1, 0x5d, 0x2b, 0x00, 0xb9, 0x00, 0xe3, 0x10},
821 {0xd1, 0x5d, 0x2d, 0x00, 0x5f, 0x00, 0xb9, 0x10}, /* 42 */
822/* {0xb1, 0x5d, 0x35, 0x00, 0x67, 0x00, 0x00, 0x10}, * gain orig */
823/* {0xb1, 0x5d, 0x35, 0x00, 0x20, 0x00, 0x00, 0x10}, * gain */
824 {0xb1, 0x5d, 0x07, 0x00, 0x03, 0x00, 0x00, 0x10}, /* update */
825 {0xb1, 0x5d, 0x07, 0x00, 0x02, 0x00, 0x00, 0x10}, /* sensor on */
Jean-Francois Moinea5ae2062008-07-04 11:16:16 -0300826 {}
Jean-Francois Moine6a7eba22008-06-30 15:50:11 -0300827};
Jean-François Moinea067db82010-10-01 07:51:24 -0300828static const u8 mi0360b_sensor_init[][8] = {
829 {0xb1, 0x5d, 0x07, 0x00, 0x02, 0x00, 0x00, 0x10},
830 {0xb1, 0x5d, 0x0d, 0x00, 0x01, 0x00, 0x00, 0x10},
Németh Mártonccbc5df2010-10-18 07:00:48 -0300831 {DELAY, 0x14, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00}, /*delay 20ms*/
Jean-François Moinea067db82010-10-01 07:51:24 -0300832 {0xb1, 0x5d, 0x0d, 0x00, 0x00, 0x00, 0x00, 0x10},
Németh Mártonccbc5df2010-10-18 07:00:48 -0300833 {DELAY, 0x14, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00}, /*delay 20ms*/
Jean-François Moinea067db82010-10-01 07:51:24 -0300834 {0xd1, 0x5d, 0x01, 0x00, 0x08, 0x00, 0x16, 0x10},
835 {0xd1, 0x5d, 0x03, 0x01, 0xe2, 0x02, 0x82, 0x10},
836 {0xd1, 0x5d, 0x05, 0x00, 0x00, 0x00, 0x00, 0x10},
837 {0xb1, 0x5d, 0x0d, 0x00, 0x02, 0x00, 0x00, 0x10},
838 {0xd1, 0x5d, 0x0a, 0x00, 0x00, 0x00, 0x00, 0x10},
839 {0xd1, 0x5d, 0x0c, 0x00, 0x00, 0x00, 0x00, 0x10},
840 {0xd1, 0x5d, 0x0e, 0x00, 0x00, 0x00, 0x00, 0x10},
841 {0xd1, 0x5d, 0x10, 0x00, 0x00, 0x00, 0x00, 0x10},
842 {0xd1, 0x5d, 0x12, 0x00, 0x00, 0x00, 0x00, 0x10},
843 {0xd1, 0x5d, 0x14, 0x00, 0x00, 0x00, 0x00, 0x10},
844 {0xd1, 0x5d, 0x16, 0x00, 0x00, 0x00, 0x00, 0x10},
845 {0xd1, 0x5d, 0x18, 0x00, 0x00, 0x00, 0x00, 0x10},
846 {0xd1, 0x5d, 0x1a, 0x00, 0x00, 0x00, 0x00, 0x10},
847 {0xd1, 0x5d, 0x1c, 0x00, 0x00, 0x00, 0x00, 0x10},
848 {0xb1, 0x5d, 0x32, 0x00, 0x00, 0x00, 0x00, 0x10},
849 {0xd1, 0x5d, 0x20, 0x11, 0x01, 0x00, 0x00, 0x10},
850 {0xd1, 0x5d, 0x22, 0x00, 0x00, 0x00, 0x00, 0x10},
851 {0xd1, 0x5d, 0x24, 0x00, 0x00, 0x00, 0x00, 0x10},
852 {0xd1, 0x5d, 0x26, 0x00, 0x00, 0x00, 0x24, 0x10},
853 {0xd1, 0x5d, 0x2f, 0xf7, 0xb0, 0x00, 0x04, 0x10},
854 {0xd1, 0x5d, 0x31, 0x00, 0x00, 0x00, 0x00, 0x10},
855 {0xd1, 0x5d, 0x33, 0x00, 0x00, 0x01, 0x00, 0x10},
856 {0xb1, 0x5d, 0x3d, 0x06, 0x8f, 0x00, 0x00, 0x10},
857 {0xd1, 0x5d, 0x40, 0x01, 0xe0, 0x00, 0xd1, 0x10},
858 {0xb1, 0x5d, 0x44, 0x00, 0x82, 0x00, 0x00, 0x10},
859 {0xd1, 0x5d, 0x58, 0x00, 0x78, 0x00, 0x43, 0x10},
860 {0xd1, 0x5d, 0x5a, 0x00, 0x00, 0x00, 0x00, 0x10},
861 {0xd1, 0x5d, 0x5c, 0x00, 0x00, 0x00, 0x00, 0x10},
862 {0xd1, 0x5d, 0x5e, 0x00, 0x00, 0xa3, 0x1d, 0x10},
863 {0xb1, 0x5d, 0x62, 0x04, 0x11, 0x00, 0x00, 0x10},
864
865 {0xb1, 0x5d, 0x20, 0x11, 0x01, 0x00, 0x00, 0x10},
866 {0xb1, 0x5d, 0x20, 0x11, 0x01, 0x00, 0x00, 0x10},
867 {0xb1, 0x5d, 0x09, 0x00, 0x64, 0x00, 0x00, 0x10},
868 {0xd1, 0x5d, 0x2b, 0x00, 0x33, 0x00, 0xa0, 0x10},
869 {0xd1, 0x5d, 0x2d, 0x00, 0xa0, 0x00, 0x33, 0x10},
870 {}
871};
872static const u8 mi0360b_sensor_param1[][8] = {
873 {0xb1, 0x5d, 0x0a, 0x00, 0x00, 0x00, 0x00, 0x10},
874 {0xb1, 0x5d, 0x06, 0x00, 0x53, 0x00, 0x00, 0x10},
875 {0xb1, 0x5d, 0x05, 0x00, 0x09, 0x00, 0x00, 0x10},
876 {0xb1, 0x5d, 0x09, 0x02, 0x35, 0x00, 0x00, 0x10}, /* exposure 2 */
877
878 {0xd1, 0x5d, 0x2b, 0x00, 0xd1, 0x01, 0xc9, 0x10},
879 {0xd1, 0x5d, 0x2d, 0x00, 0xed, 0x00, 0xd1, 0x10},
880 {0xb1, 0x5d, 0x07, 0x00, 0x03, 0x00, 0x00, 0x10}, /* update */
881 {0xb1, 0x5d, 0x07, 0x00, 0x02, 0x00, 0x00, 0x10}, /* sensor on */
882 {}
883};
Jean-Francois Moine98819182009-01-19 07:37:33 -0300884static const u8 mo4000_sensor_init[][8] = {
Jean-Francois Moine6a7eba22008-06-30 15:50:11 -0300885 {0xa1, 0x21, 0x01, 0x02, 0x00, 0x00, 0x00, 0x10},
886 {0xa1, 0x21, 0x02, 0x00, 0x00, 0x00, 0x00, 0x10},
887 {0xa1, 0x21, 0x03, 0x00, 0x00, 0x00, 0x00, 0x10},
888 {0xa1, 0x21, 0x04, 0x00, 0x00, 0x00, 0x00, 0x10},
889 {0xa1, 0x21, 0x05, 0x00, 0x00, 0x00, 0x00, 0x10},
890 {0xa1, 0x21, 0x05, 0x04, 0x00, 0x00, 0x00, 0x10},
891 {0xa1, 0x21, 0x06, 0x80, 0x00, 0x00, 0x00, 0x10},
892 {0xa1, 0x21, 0x06, 0x81, 0x00, 0x00, 0x00, 0x10},
893 {0xa1, 0x21, 0x0e, 0x00, 0x00, 0x00, 0x00, 0x10},
894 {0xa1, 0x21, 0x11, 0x00, 0x00, 0x00, 0x00, 0x10},
895 {0xa1, 0x21, 0x11, 0x20, 0x00, 0x00, 0x00, 0x10},
896 {0xa1, 0x21, 0x11, 0x30, 0x00, 0x00, 0x00, 0x10},
897 {0xa1, 0x21, 0x11, 0x38, 0x00, 0x00, 0x00, 0x10},
898 {0xa1, 0x21, 0x11, 0x38, 0x00, 0x00, 0x00, 0x10},
899 {0xa1, 0x21, 0x12, 0x00, 0x00, 0x00, 0x00, 0x10},
900 {0xa1, 0x21, 0x10, 0x00, 0x00, 0x00, 0x00, 0x10},
901 {0xa1, 0x21, 0x0f, 0x20, 0x00, 0x00, 0x00, 0x10},
902 {0xa1, 0x21, 0x10, 0x20, 0x00, 0x00, 0x00, 0x10},
903 {0xa1, 0x21, 0x00, 0x00, 0x00, 0x00, 0x00, 0x10},
904 {0xa1, 0x21, 0x11, 0x38, 0x00, 0x00, 0x00, 0x10},
Jean-Francois Moinea5ae2062008-07-04 11:16:16 -0300905 {}
Jean-Francois Moine6a7eba22008-06-30 15:50:11 -0300906};
Jean-Francois Moine3ef2c5b2009-01-29 04:59:45 -0300907static const u8 mt9v111_sensor_init[][8] = {
908 {0xb1, 0x5c, 0x0d, 0x00, 0x01, 0x00, 0x00, 0x10}, /* reset? */
Németh Mártonccbc5df2010-10-18 07:00:48 -0300909 {DELAY, 0x14, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00}, /* delay 20ms */
Jean-Francois Moine3ef2c5b2009-01-29 04:59:45 -0300910 {0xb1, 0x5c, 0x0d, 0x00, 0x00, 0x00, 0x00, 0x10},
911 {0xb1, 0x5c, 0x01, 0x00, 0x01, 0x00, 0x00, 0x10}, /* IFP select */
912 {0xb1, 0x5c, 0x08, 0x04, 0x80, 0x00, 0x00, 0x10}, /* output fmt ctrl */
913 {0xb1, 0x5c, 0x06, 0x00, 0x00, 0x00, 0x00, 0x10}, /* op mode ctrl */
914 {0xb1, 0x5c, 0x01, 0x00, 0x04, 0x00, 0x00, 0x10}, /* sensor select */
915 {0xb1, 0x5c, 0x08, 0x00, 0x08, 0x00, 0x00, 0x10}, /* row start */
916 {0xb1, 0x5c, 0x02, 0x00, 0x16, 0x00, 0x00, 0x10}, /* col start */
917 {0xb1, 0x5c, 0x03, 0x01, 0xe7, 0x00, 0x00, 0x10}, /* window height */
918 {0xb1, 0x5c, 0x04, 0x02, 0x87, 0x00, 0x00, 0x10}, /* window width */
919 {0xb1, 0x5c, 0x07, 0x30, 0x02, 0x00, 0x00, 0x10}, /* output ctrl */
920 {0xb1, 0x5c, 0x0c, 0x00, 0x00, 0x00, 0x00, 0x10}, /* shutter delay */
921 {0xb1, 0x5c, 0x12, 0x00, 0xb0, 0x00, 0x00, 0x10}, /* zoom col start */
922 {0xb1, 0x5c, 0x13, 0x00, 0x7c, 0x00, 0x00, 0x10}, /* zoom row start */
923 {0xb1, 0x5c, 0x1e, 0x00, 0x00, 0x00, 0x00, 0x10}, /* digital zoom */
924 {0xb1, 0x5c, 0x20, 0x00, 0x00, 0x00, 0x00, 0x10}, /* read mode */
925 {0xb1, 0x5c, 0x20, 0x00, 0x00, 0x00, 0x00, 0x10},
Jean-Francois Moine3fccb772009-11-02 09:54:04 -0300926 {}
927};
928static const u8 mt9v111_sensor_param1[][8] = {
Jean-François Moine80463222011-02-10 07:44:59 -0300929 {0xd1, 0x5c, 0x2b, 0x00, 0x33, 0x00, 0xad, 0x10}, /* G1 and B gains */
930 {0xd1, 0x5c, 0x2d, 0x00, 0xad, 0x00, 0x33, 0x10}, /* R and G2 gains */
931 {0xb1, 0x5c, 0x06, 0x00, 0x40, 0x00, 0x00, 0x10}, /* vert blanking */
932 {0xb1, 0x5c, 0x05, 0x00, 0x09, 0x00, 0x00, 0x10}, /* horiz blanking */
Jean-Francois Moine3ef2c5b2009-01-29 04:59:45 -0300933 {0xb1, 0x5c, 0x35, 0x01, 0xc0, 0x00, 0x00, 0x10}, /* global gain */
934 {}
935};
Jean-Francois Moine3fccb772009-11-02 09:54:04 -0300936static const u8 om6802_init0[2][8] = {
937/*fixme: variable*/
938 {0xa0, 0x34, 0x29, 0x0e, 0x00, 0x00, 0x00, 0x10},
939 {0xa0, 0x34, 0x23, 0xb0, 0x00, 0x00, 0x00, 0x10},
940};
Jean-Francois Moine98819182009-01-19 07:37:33 -0300941static const u8 om6802_sensor_init[][8] = {
Jean-Francois Moine3fccb772009-11-02 09:54:04 -0300942 {0xa0, 0x34, 0xdf, 0x6d, 0x00, 0x00, 0x00, 0x10},
943 /* factory mode */
Jean-Francois Moined2d16e92008-09-03 16:47:23 -0300944 {0xa0, 0x34, 0xdd, 0x18, 0x00, 0x00, 0x00, 0x10},
Jean-Francois Moined5aa3852009-11-07 06:10:08 -0300945 /* output raw RGB */
Jean-Francois Moine3fccb772009-11-02 09:54:04 -0300946 {0xa0, 0x34, 0x5a, 0xc0, 0x00, 0x00, 0x00, 0x10},
Jean-Francois Moined2d16e92008-09-03 16:47:23 -0300947/* {0xa0, 0x34, 0xfb, 0x11, 0x00, 0x00, 0x00, 0x10}, */
948 {0xa0, 0x34, 0xf0, 0x04, 0x00, 0x00, 0x00, 0x10},
Jean-Francois Moined5aa3852009-11-07 06:10:08 -0300949 /* auto-exposure speed (0) / white balance mode (auto RGB) */
Jean-Francois Moined2d16e92008-09-03 16:47:23 -0300950/* {0xa0, 0x34, 0xf1, 0x02, 0x00, 0x00, 0x00, 0x10},
951 * set color mode */
952/* {0xa0, 0x34, 0xfe, 0x5b, 0x00, 0x00, 0x00, 0x10},
953 * max AGC value in AE */
954/* {0xa0, 0x34, 0xe5, 0x00, 0x00, 0x00, 0x00, 0x10},
955 * preset AGC */
956/* {0xa0, 0x34, 0xe6, 0x00, 0x00, 0x00, 0x00, 0x10},
957 * preset brightness */
958/* {0xa0, 0x34, 0xe7, 0x00, 0x00, 0x00, 0x00, 0x10},
959 * preset contrast */
960/* {0xa0, 0x34, 0xe8, 0x31, 0x00, 0x00, 0x00, 0x10},
961 * preset gamma */
962 {0xa0, 0x34, 0xe9, 0x0f, 0x00, 0x00, 0x00, 0x10},
Jean-Francois Moined5aa3852009-11-07 06:10:08 -0300963 /* luminance mode (0x4f -> AutoExpo on) */
Jean-Francois Moined2d16e92008-09-03 16:47:23 -0300964 {0xa0, 0x34, 0xe4, 0xff, 0x00, 0x00, 0x00, 0x10},
965 /* preset shutter */
966/* {0xa0, 0x34, 0xef, 0x00, 0x00, 0x00, 0x00, 0x10},
967 * auto frame rate */
968/* {0xa0, 0x34, 0xfb, 0xee, 0x00, 0x00, 0x00, 0x10}, */
Jean-Francois Moine3fccb772009-11-02 09:54:04 -0300969 {0xa0, 0x34, 0x5d, 0x80, 0x00, 0x00, 0x00, 0x10},
970 {}
971};
972static const u8 om6802_sensor_param1[][8] = {
973 {0xa0, 0x34, 0x71, 0x84, 0x00, 0x00, 0x00, 0x10},
974 {0xa0, 0x34, 0x72, 0x05, 0x00, 0x00, 0x00, 0x10},
975 {0xa0, 0x34, 0x68, 0x80, 0x00, 0x00, 0x00, 0x10},
976 {0xa0, 0x34, 0x69, 0x01, 0x00, 0x00, 0x00, 0x10},
Jean-Francois Moined2d16e92008-09-03 16:47:23 -0300977 {}
978};
Jean-Francois Moine98819182009-01-19 07:37:33 -0300979static const u8 ov7630_sensor_init[][8] = {
Jean-Francois Moine6ab0b172008-09-03 16:47:34 -0300980 {0xa1, 0x21, 0x76, 0x01, 0x00, 0x00, 0x00, 0x10},
981 {0xa1, 0x21, 0x12, 0xc8, 0x00, 0x00, 0x00, 0x10},
Németh Mártonccbc5df2010-10-18 07:00:48 -0300982 {DELAY, 0x14, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00}, /* delay 20ms */
Jean-Francois Moine6ab0b172008-09-03 16:47:34 -0300983 {0xa1, 0x21, 0x12, 0x48, 0x00, 0x00, 0x00, 0x10},
984 {0xa1, 0x21, 0x12, 0xc8, 0x00, 0x00, 0x00, 0x10},
Németh Mártonccbc5df2010-10-18 07:00:48 -0300985 {DELAY, 0x14, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00}, /* delay 20ms */
Jean-Francois Moine6ab0b172008-09-03 16:47:34 -0300986 {0xa1, 0x21, 0x12, 0x48, 0x00, 0x00, 0x00, 0x10},
Jean-Francois Moine05b809c2008-09-03 16:47:59 -0300987/* win: i2c_r from 00 to 80 */
Jean-Francois Moine6ab0b172008-09-03 16:47:34 -0300988 {0xd1, 0x21, 0x03, 0x80, 0x10, 0x20, 0x80, 0x10},
989 {0xb1, 0x21, 0x0c, 0x20, 0x20, 0x00, 0x00, 0x10},
Hans de Goedecc7b5b52009-06-18 05:14:42 -0300990/* HDG: 0x11 was 0x00 change to 0x01 for better exposure (15 fps instead of 30)
991 0x13 was 0xc0 change to 0xc3 for auto gain and exposure */
992 {0xd1, 0x21, 0x11, 0x01, 0x48, 0xc3, 0x00, 0x10},
Jean-Francois Moine6ab0b172008-09-03 16:47:34 -0300993 {0xb1, 0x21, 0x15, 0x80, 0x03, 0x00, 0x00, 0x10},
994 {0xd1, 0x21, 0x17, 0x1b, 0xbd, 0x05, 0xf6, 0x10},
995 {0xa1, 0x21, 0x1b, 0x04, 0x00, 0x00, 0x00, 0x10},
996 {0xd1, 0x21, 0x1f, 0x00, 0x80, 0x80, 0x80, 0x10},
997 {0xd1, 0x21, 0x23, 0xde, 0x10, 0x8a, 0xa0, 0x10},
998 {0xc1, 0x21, 0x27, 0xca, 0xa2, 0x74, 0x00, 0x10},
999 {0xd1, 0x21, 0x2a, 0x88, 0x00, 0x88, 0x01, 0x10},
1000 {0xc1, 0x21, 0x2e, 0x80, 0x00, 0x18, 0x00, 0x10},
1001 {0xa1, 0x21, 0x21, 0x08, 0x00, 0x00, 0x00, 0x10},
1002 {0xa1, 0x21, 0x22, 0x00, 0x00, 0x00, 0x00, 0x10},
1003 {0xa1, 0x21, 0x2e, 0x00, 0x00, 0x00, 0x00, 0x10},
1004 {0xb1, 0x21, 0x32, 0xc2, 0x08, 0x00, 0x00, 0x10},
1005 {0xb1, 0x21, 0x4c, 0x00, 0x00, 0x00, 0x00, 0x10},
1006 {0xd1, 0x21, 0x60, 0x05, 0x40, 0x12, 0x57, 0x10},
1007 {0xa1, 0x21, 0x64, 0x73, 0x00, 0x00, 0x00, 0x10},
1008 {0xd1, 0x21, 0x65, 0x00, 0x55, 0x01, 0xac, 0x10},
1009 {0xa1, 0x21, 0x69, 0x38, 0x00, 0x00, 0x00, 0x10},
1010 {0xd1, 0x21, 0x6f, 0x1f, 0x01, 0x00, 0x10, 0x10},
1011 {0xd1, 0x21, 0x73, 0x50, 0x20, 0x02, 0x01, 0x10},
1012 {0xd1, 0x21, 0x77, 0xf3, 0x90, 0x98, 0x98, 0x10},
1013 {0xc1, 0x21, 0x7b, 0x00, 0x4c, 0xf7, 0x00, 0x10},
1014 {0xd1, 0x21, 0x17, 0x1b, 0xbd, 0x05, 0xf6, 0x10},
1015 {0xa1, 0x21, 0x1b, 0x04, 0x00, 0x00, 0x00, 0x10},
Jean-François Moinebdd2b932010-04-25 14:23:39 -03001016 {}
1017};
1018static const u8 ov7630_sensor_param1[][8] = {
Jean-Francois Moine6ab0b172008-09-03 16:47:34 -03001019 {0xa1, 0x21, 0x12, 0x48, 0x00, 0x00, 0x00, 0x10},
1020 {0xa1, 0x21, 0x12, 0x48, 0x00, 0x00, 0x00, 0x10},
1021/*fixme: + 0x12, 0x04*/
Jean-Francois Moine6c862742008-09-08 04:57:26 -03001022/* {0xa1, 0x21, 0x75, 0x82, 0x00, 0x00, 0x00, 0x10}, * COMN
1023 * set by setvflip */
Jean-Francois Moine6ab0b172008-09-03 16:47:34 -03001024 {0xa1, 0x21, 0x10, 0x32, 0x00, 0x00, 0x00, 0x10},
1025 {0xa1, 0x21, 0x00, 0x00, 0x00, 0x00, 0x00, 0x10},
1026 {0xb1, 0x21, 0x01, 0x80, 0x80, 0x00, 0x00, 0x10},
Jean-Francois Moine05b809c2008-09-03 16:47:59 -03001027/* */
Hans de Goede37c6dbe2009-06-18 07:35:36 -03001028/* {0xa1, 0x21, 0x2a, 0x88, 0x00, 0x00, 0x00, 0x10}, * set by setfreq */
1029/* {0xa1, 0x21, 0x2b, 0x34, 0x00, 0x00, 0x00, 0x10}, * set by setfreq */
Jean-Francois Moine05b809c2008-09-03 16:47:59 -03001030/* */
Jean-Francois Moine6ab0b172008-09-03 16:47:34 -03001031 {0xa1, 0x21, 0x10, 0x83, 0x00, 0x00, 0x00, 0x10},
Jean-Francois Moine91de65a2008-09-03 17:12:18 -03001032/* {0xb1, 0x21, 0x01, 0x88, 0x70, 0x00, 0x00, 0x10}, */
Jean-Francois Moine6ab0b172008-09-03 16:47:34 -03001033 {}
1034};
Jean-Francois Moine62703302008-11-11 08:42:56 -03001035
Jean-Francois Moine98819182009-01-19 07:37:33 -03001036static const u8 ov7648_sensor_init[][8] = {
Jean-Francois Moine62703302008-11-11 08:42:56 -03001037 {0xa1, 0x21, 0x76, 0x00, 0x00, 0x00, 0x00, 0x10},
1038 {0xa1, 0x21, 0x12, 0x80, 0x00, 0x00, 0x00, 0x10}, /* reset */
Németh Mártonccbc5df2010-10-18 07:00:48 -03001039 {DELAY, 0x14, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00}, /* delay 20ms */
Jean-Francois Moine62703302008-11-11 08:42:56 -03001040 {0xa1, 0x21, 0x12, 0x00, 0x00, 0x00, 0x00, 0x10},
1041 {0xd1, 0x21, 0x03, 0xa4, 0x30, 0x88, 0x00, 0x10},
1042 {0xb1, 0x21, 0x11, 0x80, 0x08, 0x00, 0x00, 0x10},
1043 {0xc1, 0x21, 0x13, 0xa0, 0x04, 0x84, 0x00, 0x10},
1044 {0xd1, 0x21, 0x17, 0x1a, 0x02, 0xba, 0xf4, 0x10},
1045 {0xa1, 0x21, 0x1b, 0x04, 0x00, 0x00, 0x00, 0x10},
1046 {0xd1, 0x21, 0x1f, 0x41, 0xc0, 0x80, 0x80, 0x10},
1047 {0xd1, 0x21, 0x23, 0xde, 0xa0, 0x80, 0x32, 0x10},
1048 {0xd1, 0x21, 0x27, 0xfe, 0xa0, 0x00, 0x91, 0x10},
1049 {0xd1, 0x21, 0x2b, 0x00, 0x88, 0x85, 0x80, 0x10},
1050 {0xc1, 0x21, 0x2f, 0x9c, 0x00, 0xc4, 0x00, 0x10},
1051 {0xd1, 0x21, 0x60, 0xa6, 0x60, 0x88, 0x12, 0x10},
1052 {0xd1, 0x21, 0x64, 0x88, 0x00, 0x00, 0x94, 0x10},
1053 {0xd1, 0x21, 0x68, 0x7a, 0x0c, 0x00, 0x00, 0x10},
1054 {0xd1, 0x21, 0x6c, 0x11, 0x33, 0x22, 0x00, 0x10},
1055 {0xd1, 0x21, 0x70, 0x11, 0x00, 0x10, 0x50, 0x10},
1056 {0xd1, 0x21, 0x74, 0x20, 0x06, 0x00, 0xb5, 0x10},
1057 {0xd1, 0x21, 0x78, 0x8a, 0x00, 0x00, 0x00, 0x10},
1058 {0xb1, 0x21, 0x7c, 0x00, 0x43, 0x00, 0x00, 0x10},
1059
1060 {0xd1, 0x21, 0x21, 0x86, 0x00, 0xde, 0xa0, 0x10},
1061/* {0xd1, 0x21, 0x25, 0x80, 0x32, 0xfe, 0xa0, 0x10}, jfm done */
1062/* {0xd1, 0x21, 0x29, 0x00, 0x91, 0x00, 0x88, 0x10}, jfm done */
Hans de Goede37c6dbe2009-06-18 07:35:36 -03001063/* {0xb1, 0x21, 0x2d, 0x85, 0x00, 0x00, 0x00, 0x10}, set by setfreq */
Jean-Francois Moine3fccb772009-11-02 09:54:04 -03001064 {}
1065};
1066static const u8 ov7648_sensor_param1[][8] = {
Jean-Francois Moine62703302008-11-11 08:42:56 -03001067/* {0xa1, 0x21, 0x12, 0x08, 0x00, 0x00, 0x00, 0x10}, jfm done */
Jean-Francois Moine2797ba22009-02-05 15:12:24 -03001068/* {0xa1, 0x21, 0x75, 0x06, 0x00, 0x00, 0x00, 0x10}, * COMN
1069 * set by setvflip */
Jean-Francois Moine62703302008-11-11 08:42:56 -03001070 {0xa1, 0x21, 0x19, 0x02, 0x00, 0x00, 0x00, 0x10},
1071 {0xa1, 0x21, 0x10, 0x32, 0x00, 0x00, 0x00, 0x10},
1072/* {0xa1, 0x21, 0x16, 0x00, 0x00, 0x00, 0x00, 0x10}, jfm done */
1073/* {0xa1, 0x21, 0x00, 0x00, 0x00, 0x00, 0x00, 0x10}, * GAIN - def */
1074/* {0xb1, 0x21, 0x01, 0x6c, 0x6c, 0x00, 0x00, 0x10}, * B R - def: 80 */
1075/*...*/
1076 {0xa1, 0x21, 0x11, 0x81, 0x00, 0x00, 0x00, 0x10}, /* CLKRC */
1077/* {0xa1, 0x21, 0x1e, 0x00, 0x00, 0x00, 0x00, 0x10}, jfm done */
1078/* {0xa1, 0x21, 0x16, 0x00, 0x00, 0x00, 0x00, 0x10}, jfm done */
1079/* {0xa1, 0x21, 0x2a, 0x91, 0x00, 0x00, 0x00, 0x10}, jfm done */
1080/* {0xa1, 0x21, 0x2b, 0x00, 0x00, 0x00, 0x00, 0x10}, jfm done */
1081/* {0xb1, 0x21, 0x01, 0x64, 0x84, 0x00, 0x00, 0x10}, * B R - def: 80 */
1082
1083 {}
1084};
1085
Jean-Francois Moine98819182009-01-19 07:37:33 -03001086static const u8 ov7660_sensor_init[][8] = {
Jean-Francois Moine6a7eba22008-06-30 15:50:11 -03001087 {0xa1, 0x21, 0x12, 0x80, 0x00, 0x00, 0x00, 0x10}, /* reset SCCB */
Németh Mártonccbc5df2010-10-18 07:00:48 -03001088 {DELAY, 0x14, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00}, /* delay 20ms */
Jean-Francois Moine6a7eba22008-06-30 15:50:11 -03001089 {0xa1, 0x21, 0x12, 0x05, 0x00, 0x00, 0x00, 0x10},
Jean-Francois Moine738608a2008-07-28 06:41:51 -03001090 /* Outformat = rawRGB */
Jean-Francois Moine6a7eba22008-06-30 15:50:11 -03001091 {0xa1, 0x21, 0x13, 0xb8, 0x00, 0x00, 0x00, 0x10}, /* init COM8 */
Jean-Francois Moined8f400e2009-07-08 06:33:44 -03001092 {0xd1, 0x21, 0x00, 0x01, 0x74, 0x92, 0x00, 0x10},
Jean-Francois Moine6a7eba22008-06-30 15:50:11 -03001093 /* GAIN BLUE RED VREF */
1094 {0xd1, 0x21, 0x04, 0x00, 0x7d, 0x62, 0x00, 0x10},
1095 /* COM 1 BAVE GEAVE AECHH */
1096 {0xb1, 0x21, 0x08, 0x83, 0x01, 0x00, 0x00, 0x10}, /* RAVE COM2 */
1097 {0xd1, 0x21, 0x0c, 0x00, 0x08, 0x04, 0x4f, 0x10}, /* COM 3 4 5 6 */
Jean-Francois Moine47f7f6f2009-08-25 06:14:54 -03001098 {0xd1, 0x21, 0x10, 0x7f, 0x40, 0x05, 0xff, 0x10},
Jean-Francois Moine6a7eba22008-06-30 15:50:11 -03001099 /* AECH CLKRC COM7 COM8 */
1100 {0xc1, 0x21, 0x14, 0x2c, 0x00, 0x02, 0x00, 0x10}, /* COM9 COM10 */
1101 {0xd1, 0x21, 0x17, 0x10, 0x60, 0x02, 0x7b, 0x10},
1102 /* HSTART HSTOP VSTRT VSTOP */
1103 {0xa1, 0x21, 0x1b, 0x02, 0x00, 0x00, 0x00, 0x10}, /* PSHFT */
1104 {0xb1, 0x21, 0x1e, 0x01, 0x0e, 0x00, 0x00, 0x10}, /* MVFP LAEC */
1105 {0xd1, 0x21, 0x20, 0x07, 0x07, 0x07, 0x07, 0x10},
1106 /* BOS GBOS GROS ROS (BGGR offset) */
Jean-Francois Moine738608a2008-07-28 06:41:51 -03001107/* {0xd1, 0x21, 0x24, 0x68, 0x58, 0xd4, 0x80, 0x10}, */
1108 {0xd1, 0x21, 0x24, 0x78, 0x68, 0xd4, 0x80, 0x10},
Jean-Francois Moine6a7eba22008-06-30 15:50:11 -03001109 /* AEW AEB VPT BBIAS */
1110 {0xd1, 0x21, 0x28, 0x80, 0x30, 0x00, 0x00, 0x10},
1111 /* GbBIAS RSVD EXHCH EXHCL */
1112 {0xd1, 0x21, 0x2c, 0x80, 0x00, 0x00, 0x62, 0x10},
1113 /* RBIAS ADVFL ASDVFH YAVE */
1114 {0xc1, 0x21, 0x30, 0x08, 0x30, 0xb4, 0x00, 0x10},
1115 /* HSYST HSYEN HREF */
1116 {0xd1, 0x21, 0x33, 0x00, 0x07, 0x84, 0x00, 0x10}, /* reserved */
1117 {0xd1, 0x21, 0x37, 0x0c, 0x02, 0x43, 0x00, 0x10},
1118 /* ADC ACOM OFON TSLB */
1119 {0xd1, 0x21, 0x3b, 0x02, 0x6c, 0x19, 0x0e, 0x10},
1120 /* COM11 COM12 COM13 COM14 */
1121 {0xd1, 0x21, 0x3f, 0x41, 0xc1, 0x22, 0x08, 0x10},
1122 /* EDGE COM15 COM16 COM17 */
1123 {0xd1, 0x21, 0x43, 0xf0, 0x10, 0x78, 0xa8, 0x10}, /* reserved */
1124 {0xd1, 0x21, 0x47, 0x60, 0x80, 0x00, 0x00, 0x10}, /* reserved */
1125 {0xd1, 0x21, 0x4b, 0x00, 0x00, 0x00, 0x00, 0x10}, /* reserved */
1126 {0xd1, 0x21, 0x4f, 0x46, 0x36, 0x0f, 0x17, 0x10}, /* MTX 1 2 3 4 */
1127 {0xd1, 0x21, 0x53, 0x7f, 0x96, 0x40, 0x40, 0x10}, /* MTX 5 6 7 8 */
1128 {0xb1, 0x21, 0x57, 0x40, 0x0f, 0x00, 0x00, 0x10}, /* MTX9 MTXS */
1129 {0xd1, 0x21, 0x59, 0xba, 0x9a, 0x22, 0xb9, 0x10}, /* reserved */
1130 {0xd1, 0x21, 0x5d, 0x9b, 0x10, 0xf0, 0x05, 0x10}, /* reserved */
1131 {0xa1, 0x21, 0x61, 0x60, 0x00, 0x00, 0x00, 0x10}, /* reserved */
1132 {0xd1, 0x21, 0x62, 0x00, 0x00, 0x50, 0x30, 0x10},
1133 /* LCC1 LCC2 LCC3 LCC4 */
1134 {0xa1, 0x21, 0x66, 0x00, 0x00, 0x00, 0x00, 0x10}, /* LCC5 */
Jean-Francois Moine738608a2008-07-28 06:41:51 -03001135 {0xd1, 0x21, 0x67, 0x80, 0x7a, 0x90, 0x80, 0x10}, /* MANU */
Jean-Francois Moine6a7eba22008-06-30 15:50:11 -03001136 {0xa1, 0x21, 0x6b, 0x0a, 0x00, 0x00, 0x00, 0x10},
Jean-Francois Moine738608a2008-07-28 06:41:51 -03001137 /* band gap reference [0:3] DBLV */
Jean-Francois Moine6a7eba22008-06-30 15:50:11 -03001138 {0xd1, 0x21, 0x6c, 0x30, 0x48, 0x80, 0x74, 0x10}, /* gamma curve */
1139 {0xd1, 0x21, 0x70, 0x64, 0x60, 0x5c, 0x58, 0x10}, /* gamma curve */
1140 {0xd1, 0x21, 0x74, 0x54, 0x4c, 0x40, 0x38, 0x10}, /* gamma curve */
1141 {0xd1, 0x21, 0x78, 0x34, 0x30, 0x2f, 0x2b, 0x10}, /* gamma curve */
1142 {0xd1, 0x21, 0x7c, 0x03, 0x07, 0x17, 0x34, 0x10}, /* gamma curve */
1143 {0xd1, 0x21, 0x80, 0x41, 0x4d, 0x58, 0x63, 0x10}, /* gamma curve */
1144 {0xd1, 0x21, 0x84, 0x6e, 0x77, 0x87, 0x95, 0x10}, /* gamma curve */
1145 {0xc1, 0x21, 0x88, 0xaf, 0xc7, 0xdf, 0x00, 0x10}, /* gamma curve */
1146 {0xc1, 0x21, 0x8b, 0x99, 0x99, 0xcf, 0x00, 0x10}, /* reserved */
Jean-Francois Moine738608a2008-07-28 06:41:51 -03001147 {0xb1, 0x21, 0x92, 0x00, 0x00, 0x00, 0x00, 0x10}, /* DM_LNL/H */
Jean-Francois Moine3fccb772009-11-02 09:54:04 -03001148/* not in all ms-win traces*/
Jean-Francois Moine47f7f6f2009-08-25 06:14:54 -03001149 {0xa1, 0x21, 0xa1, 0x00, 0x00, 0x00, 0x00, 0x10},
Jean-Francois Moine3fccb772009-11-02 09:54:04 -03001150 {}
1151};
1152static const u8 ov7660_sensor_param1[][8] = {
Jean-Francois Moine738608a2008-07-28 06:41:51 -03001153 {0xa1, 0x21, 0x1e, 0x01, 0x00, 0x00, 0x00, 0x10}, /* MVFP */
Jean-Francois Moine6a7eba22008-06-30 15:50:11 -03001154 /* bits[3..0]reserved */
1155 {0xa1, 0x21, 0x1e, 0x01, 0x00, 0x00, 0x00, 0x10},
1156 {0xa1, 0x21, 0x03, 0x00, 0x00, 0x00, 0x00, 0x10},
1157 /* VREF vertical frame ctrl */
1158 {0xa1, 0x21, 0x03, 0x00, 0x00, 0x00, 0x00, 0x10},
Jean-Francois Moine738608a2008-07-28 06:41:51 -03001159 {0xa1, 0x21, 0x10, 0x20, 0x00, 0x00, 0x00, 0x10}, /* AECH 0x20 */
1160 {0xa1, 0x21, 0x2d, 0x00, 0x00, 0x00, 0x00, 0x10}, /* ADVFL */
1161 {0xa1, 0x21, 0x2e, 0x00, 0x00, 0x00, 0x00, 0x10}, /* ADVFH */
1162 {0xa1, 0x21, 0x00, 0x1f, 0x00, 0x00, 0x00, 0x10}, /* GAIN */
1163/* {0xb1, 0x21, 0x01, 0x78, 0x78, 0x00, 0x00, 0x10}, * BLUE */
Jean-Francois Moine6a7eba22008-06-30 15:50:11 -03001164/****** (some exchanges in the win trace) ******/
Jean-Francois Moine3fccb772009-11-02 09:54:04 -03001165/*fixme:param2*/
Jean-Francois Moine6a7eba22008-06-30 15:50:11 -03001166 {0xa1, 0x21, 0x93, 0x00, 0x00, 0x00, 0x00, 0x10},/* dummy line hight */
Jean-Francois Moine738608a2008-07-28 06:41:51 -03001167 {0xa1, 0x21, 0x92, 0x25, 0x00, 0x00, 0x00, 0x10}, /* dummy line low */
1168 {0xa1, 0x21, 0x2a, 0x00, 0x00, 0x00, 0x00, 0x10}, /* EXHCH */
1169 {0xa1, 0x21, 0x2b, 0x00, 0x00, 0x00, 0x00, 0x10}, /* EXHCL */
1170/* {0xa1, 0x21, 0x02, 0x90, 0x00, 0x00, 0x00, 0x10}, * RED */
Jean-Francois Moine6a7eba22008-06-30 15:50:11 -03001171/****** (some exchanges in the win trace) ******/
Jean-Francois Moine738608a2008-07-28 06:41:51 -03001172/******!! startsensor KO if changed !!****/
Jean-Francois Moine3fccb772009-11-02 09:54:04 -03001173/*fixme: param3*/
Jean-Francois Moine6a7eba22008-06-30 15:50:11 -03001174 {0xa1, 0x21, 0x93, 0x01, 0x00, 0x00, 0x00, 0x10},
1175 {0xa1, 0x21, 0x92, 0xff, 0x00, 0x00, 0x00, 0x10},
1176 {0xa1, 0x21, 0x2a, 0x00, 0x00, 0x00, 0x00, 0x10},
1177 {0xa1, 0x21, 0x2b, 0xc3, 0x00, 0x00, 0x00, 0x10},
Jean-Francois Moinea5ae2062008-07-04 11:16:16 -03001178 {}
Jean-Francois Moine6a7eba22008-06-30 15:50:11 -03001179};
Jean-Francois Moine6a7eba22008-06-30 15:50:11 -03001180
Jean-Francois Moineb8c8a5b2009-11-23 06:46:35 -03001181static const u8 po1030_sensor_init[][8] = {
1182/* the sensor registers are described in m5602/m5602_po1030.h */
1183 {0xa1, 0x6e, 0x3f, 0x20, 0x00, 0x00, 0x00, 0x10}, /* sensor reset */
Németh Mártonccbc5df2010-10-18 07:00:48 -03001184 {DELAY, 0x14, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00}, /* delay 20ms */
Jean-Francois Moineb8c8a5b2009-11-23 06:46:35 -03001185 {0xa1, 0x6e, 0x3f, 0x00, 0x00, 0x00, 0x00, 0x10},
1186 {0xa1, 0x6e, 0x3e, 0x00, 0x00, 0x00, 0x00, 0x10},
1187 {0xd1, 0x6e, 0x04, 0x02, 0xb1, 0x02, 0x39, 0x10},
1188 {0xd1, 0x6e, 0x08, 0x00, 0x01, 0x00, 0x00, 0x10},
1189 {0xd1, 0x6e, 0x0c, 0x02, 0x7f, 0x01, 0xe0, 0x10},
1190 {0xd1, 0x6e, 0x12, 0x03, 0x02, 0x00, 0x03, 0x10},
1191 {0xd1, 0x6e, 0x16, 0x85, 0x40, 0x4a, 0x40, 0x10}, /* r/g1/b/g2 gains */
1192 {0xc1, 0x6e, 0x1a, 0x00, 0x80, 0x00, 0x00, 0x10},
1193 {0xd1, 0x6e, 0x1d, 0x08, 0x03, 0x00, 0x00, 0x10},
1194 {0xd1, 0x6e, 0x23, 0x00, 0xb0, 0x00, 0x94, 0x10},
1195 {0xd1, 0x6e, 0x27, 0x58, 0x00, 0x00, 0x00, 0x10},
1196 {0xb1, 0x6e, 0x2b, 0x00, 0x00, 0x00, 0x00, 0x10},
1197 {0xd1, 0x6e, 0x2d, 0x14, 0x35, 0x61, 0x84, 0x10}, /* gamma corr */
1198 {0xd1, 0x6e, 0x31, 0xa2, 0xbd, 0xd8, 0xff, 0x10},
1199 {0xd1, 0x6e, 0x35, 0x06, 0x1e, 0x12, 0x02, 0x10}, /* color matrix */
1200 {0xd1, 0x6e, 0x39, 0xaa, 0x53, 0x37, 0xd5, 0x10},
1201 {0xa1, 0x6e, 0x3d, 0xf2, 0x00, 0x00, 0x00, 0x10},
1202 {0xd1, 0x6e, 0x3e, 0x00, 0x00, 0x80, 0x03, 0x10},
1203 {0xd1, 0x6e, 0x42, 0x03, 0x00, 0x00, 0x00, 0x10},
1204 {0xc1, 0x6e, 0x46, 0x00, 0x80, 0x80, 0x00, 0x10},
1205 {0xd1, 0x6e, 0x4b, 0x02, 0xef, 0x08, 0xcd, 0x10},
1206 {0xd1, 0x6e, 0x4f, 0x00, 0xd0, 0x00, 0xa0, 0x10},
1207 {0xd1, 0x6e, 0x53, 0x01, 0xaa, 0x01, 0x40, 0x10},
1208 {0xd1, 0x6e, 0x5a, 0x50, 0x04, 0x30, 0x03, 0x10}, /* raw rgb bayer */
1209 {0xa1, 0x6e, 0x5e, 0x00, 0x00, 0x00, 0x00, 0x10},
1210 {0xd1, 0x6e, 0x5f, 0x10, 0x40, 0xff, 0x00, 0x10},
1211
1212 {0xd1, 0x6e, 0x63, 0x40, 0x40, 0x00, 0x00, 0x10},
1213 {0xd1, 0x6e, 0x67, 0x00, 0x00, 0x00, 0x00, 0x10},
1214 {0xd1, 0x6e, 0x6b, 0x00, 0x00, 0x00, 0x00, 0x10},
1215 {0xd1, 0x6e, 0x6f, 0x00, 0x00, 0x00, 0x00, 0x10},
1216 {0xc1, 0x6e, 0x73, 0x10, 0x80, 0xeb, 0x00, 0x10},
1217 {}
1218};
1219static const u8 po1030_sensor_param1[][8] = {
1220/* from ms-win traces - these values change with auto gain/expo/wb.. */
1221 {0xa1, 0x6e, 0x1e, 0x03, 0x00, 0x00, 0x00, 0x10},
1222 {0xa1, 0x6e, 0x1e, 0x03, 0x00, 0x00, 0x00, 0x10},
1223/* mean values */
1224 {0xc1, 0x6e, 0x1a, 0x02, 0xd4, 0xa4, 0x00, 0x10}, /* integlines */
1225 {0xa1, 0x6e, 0x15, 0x04, 0x00, 0x00, 0x00, 0x10}, /* global gain */
1226 {0xc1, 0x6e, 0x16, 0x40, 0x40, 0x40, 0x00, 0x10}, /* r/g1/b gains */
1227
1228 {0xa1, 0x6e, 0x1d, 0x08, 0x00, 0x00, 0x00, 0x10}, /* control1 */
1229 {0xa1, 0x6e, 0x06, 0x02, 0x00, 0x00, 0x00, 0x10}, /* frameheight */
1230 {0xa1, 0x6e, 0x07, 0xd5, 0x00, 0x00, 0x00, 0x10},
1231/* {0xc1, 0x6e, 0x16, 0x49, 0x40, 0x45, 0x00, 0x10}, */
1232 {}
1233};
1234
Jean-François Moinead98c0f2010-03-18 05:15:30 -03001235static const u8 po2030n_sensor_init[][8] = {
1236 {0xa1, 0x6e, 0x1e, 0x1a, 0x00, 0x00, 0x00, 0x10},
1237 {0xa1, 0x6e, 0x1f, 0x99, 0x00, 0x00, 0x00, 0x10},
Németh Mártonccbc5df2010-10-18 07:00:48 -03001238 {DELAY, 0x0a, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00}, /* delay 10ms */
Jean-François Moinead98c0f2010-03-18 05:15:30 -03001239 {0xa1, 0x6e, 0x1e, 0x0a, 0x00, 0x00, 0x00, 0x10},
1240 {0xa1, 0x6e, 0x1f, 0x19, 0x00, 0x00, 0x00, 0x10},
Németh Mártonccbc5df2010-10-18 07:00:48 -03001241 {DELAY, 0x0a, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00}, /* delay 10ms */
Jean-François Moinead98c0f2010-03-18 05:15:30 -03001242 {0xa1, 0x6e, 0x20, 0x44, 0x00, 0x00, 0x00, 0x10},
1243 {0xa1, 0x6e, 0x04, 0x03, 0x00, 0x00, 0x00, 0x10},
1244 {0xa1, 0x6e, 0x05, 0x70, 0x00, 0x00, 0x00, 0x10},
1245 {0xa1, 0x6e, 0x06, 0x02, 0x00, 0x00, 0x00, 0x10},
1246 {0xa1, 0x6e, 0x07, 0x25, 0x00, 0x00, 0x00, 0x10},
1247 {0xd1, 0x6e, 0x08, 0x00, 0xd0, 0x00, 0x08, 0x10},
1248 {0xd1, 0x6e, 0x0c, 0x03, 0x50, 0x01, 0xe8, 0x10},
1249 {0xd1, 0x6e, 0x1d, 0x20, 0x0a, 0x19, 0x44, 0x10},
1250 {0xd1, 0x6e, 0x21, 0x00, 0x00, 0x00, 0x00, 0x10},
1251 {0xd1, 0x6e, 0x25, 0x00, 0x00, 0x00, 0x00, 0x10},
1252 {0xd1, 0x6e, 0x29, 0x00, 0x00, 0x00, 0x00, 0x10},
1253 {0xd1, 0x6e, 0x2d, 0x00, 0x00, 0x00, 0x00, 0x10},
1254 {0xd1, 0x6e, 0x31, 0x00, 0x00, 0x00, 0x00, 0x10},
1255 {0xd1, 0x6e, 0x35, 0x00, 0x00, 0x00, 0x00, 0x10},
1256 {0xd1, 0x6e, 0x39, 0x00, 0x00, 0x00, 0x00, 0x10},
1257 {0xd1, 0x6e, 0x3d, 0x00, 0x00, 0x00, 0x00, 0x10},
1258 {0xd1, 0x6e, 0x41, 0x00, 0x00, 0x00, 0x00, 0x10},
1259 {0xd1, 0x6e, 0x45, 0x00, 0x00, 0x00, 0x00, 0x10},
1260 {0xd1, 0x6e, 0x49, 0x00, 0x00, 0x00, 0x00, 0x10},
1261 {0xd1, 0x6e, 0x4d, 0x00, 0x00, 0x00, 0xed, 0x10},
1262 {0xd1, 0x6e, 0x51, 0x17, 0x4a, 0x2f, 0xc0, 0x10},
1263 {0xd1, 0x6e, 0x55, 0x00, 0x00, 0x00, 0x00, 0x10},
1264 {0xd1, 0x6e, 0x59, 0x00, 0x00, 0x00, 0x00, 0x10},
1265 {0xd1, 0x6e, 0x5d, 0x00, 0x00, 0x00, 0x00, 0x10},
1266 {0xd1, 0x6e, 0x61, 0x00, 0x00, 0x00, 0x00, 0x10},
1267 {0xd1, 0x6e, 0x65, 0x00, 0x00, 0x00, 0x00, 0x10},
1268 {0xd1, 0x6e, 0x69, 0x00, 0x00, 0x00, 0x00, 0x10},
1269 {0xd1, 0x6e, 0x6d, 0x00, 0x00, 0x00, 0x00, 0x10},
1270 {0xd1, 0x6e, 0x71, 0x00, 0x00, 0x00, 0x00, 0x10},
1271 {0xd1, 0x6e, 0x75, 0x00, 0x00, 0x00, 0x00, 0x10},
1272 {0xd1, 0x6e, 0x79, 0x00, 0x00, 0x00, 0x00, 0x10},
1273 {0xd1, 0x6e, 0x7d, 0x00, 0x00, 0x00, 0x00, 0x10},
1274 {0xd1, 0x6e, 0x81, 0x00, 0x00, 0x00, 0x00, 0x10},
1275 {0xd1, 0x6e, 0x85, 0x00, 0x00, 0x00, 0x08, 0x10},
1276 {0xd1, 0x6e, 0x89, 0x01, 0xe8, 0x00, 0x01, 0x10},
1277 {0xa1, 0x6e, 0x8d, 0x00, 0x00, 0x00, 0x00, 0x10},
1278 {0xd1, 0x6e, 0x21, 0x00, 0x00, 0x00, 0x00, 0x10},
1279 {0xd1, 0x6e, 0x25, 0x00, 0x00, 0x00, 0x01, 0x10},
1280 {0xd1, 0x6e, 0x29, 0xe6, 0x00, 0xbd, 0x03, 0x10},
1281 {0xd1, 0x6e, 0x2d, 0x41, 0x38, 0x68, 0x40, 0x10},
1282 {0xd1, 0x6e, 0x31, 0x2b, 0x00, 0x36, 0x00, 0x10},
1283 {0xd1, 0x6e, 0x35, 0x30, 0x30, 0x08, 0x00, 0x10},
1284 {0xd1, 0x6e, 0x39, 0x00, 0x00, 0x33, 0x06, 0x10},
1285 {0xb1, 0x6e, 0x3d, 0x06, 0x02, 0x00, 0x00, 0x10},
1286 {}
1287};
1288static const u8 po2030n_sensor_param1[][8] = {
1289 {0xa1, 0x6e, 0x1a, 0x01, 0x00, 0x00, 0x00, 0x10},
Németh Mártonccbc5df2010-10-18 07:00:48 -03001290 {DELAY, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00}, /* delay 8ms */
Jean-François Moinead98c0f2010-03-18 05:15:30 -03001291 {0xa1, 0x6e, 0x1b, 0xf4, 0x00, 0x00, 0x00, 0x10},
1292 {0xa1, 0x6e, 0x15, 0x04, 0x00, 0x00, 0x00, 0x10},
Jean-François Moine41f09322011-11-30 06:20:07 -03001293 {0xd1, 0x6e, 0x16, 0x40, 0x40, 0x40, 0x40, 0x10}, /* RGBG gains */
Jean-François Moinead98c0f2010-03-18 05:15:30 -03001294/*param2*/
1295 {0xa1, 0x6e, 0x1d, 0x00, 0x00, 0x00, 0x00, 0x10},
1296 {0xa1, 0x6e, 0x04, 0x03, 0x00, 0x00, 0x00, 0x10},
1297 {0xa1, 0x6e, 0x05, 0x6f, 0x00, 0x00, 0x00, 0x10},
1298 {0xa1, 0x6e, 0x06, 0x02, 0x00, 0x00, 0x00, 0x10},
1299 {0xa1, 0x6e, 0x07, 0x25, 0x00, 0x00, 0x00, 0x10},
Jean-François Moinead98c0f2010-03-18 05:15:30 -03001300 {}
1301};
1302
Jean-François Moine03ed2a12010-04-25 14:45:43 -03001303static const u8 soi768_sensor_init[][8] = {
1304 {0xa1, 0x21, 0x12, 0x80, 0x00, 0x00, 0x00, 0x10}, /* reset */
Németh Mártonccbc5df2010-10-18 07:00:48 -03001305 {DELAY, 0x60, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00}, /* delay 96ms */
Jean-François Moine03ed2a12010-04-25 14:45:43 -03001306 {0xa1, 0x21, 0x12, 0x00, 0x00, 0x00, 0x00, 0x10},
1307 {0xa1, 0x21, 0x13, 0x80, 0x00, 0x00, 0x00, 0x10},
1308 {0xa1, 0x21, 0x0f, 0x03, 0x00, 0x00, 0x00, 0x10},
1309 {0xa1, 0x21, 0x19, 0x00, 0x00, 0x00, 0x00, 0x10},
1310 {}
1311};
1312static const u8 soi768_sensor_param1[][8] = {
1313 {0xa1, 0x21, 0x10, 0x10, 0x00, 0x00, 0x00, 0x10},
1314 {0xa1, 0x21, 0x2d, 0x00, 0x00, 0x00, 0x00, 0x10},
1315 {0xa1, 0x21, 0x2e, 0x00, 0x00, 0x00, 0x00, 0x10},
1316 {0xa1, 0x21, 0x00, 0x00, 0x00, 0x00, 0x00, 0x10},
1317 {0xb1, 0x21, 0x01, 0x7f, 0x7f, 0x00, 0x00, 0x10},
1318/* */
1319/* {0xa1, 0x21, 0x2e, 0x00, 0x00, 0x00, 0x00, 0x10}, */
1320/* {0xa1, 0x21, 0x2d, 0x25, 0x00, 0x00, 0x00, 0x10}, */
1321 {0xa1, 0x21, 0x2b, 0x00, 0x00, 0x00, 0x00, 0x10},
1322/* {0xb1, 0x21, 0x2d, 0x00, 0x00, 0x00, 0x00, 0x10}, */
1323 {0xa1, 0x21, 0x02, 0x8d, 0x00, 0x00, 0x00, 0x10},
1324/* the next sequence should be used for auto gain */
1325 {0xa1, 0x21, 0x00, 0x07, 0x00, 0x00, 0x00, 0x10},
1326 /* global gain ? : 07 - change with 0x15 at the end */
1327 {0xa1, 0x21, 0x10, 0x3f, 0x00, 0x00, 0x00, 0x10}, /* ???? : 063f */
1328 {0xa1, 0x21, 0x04, 0x06, 0x00, 0x00, 0x00, 0x10},
Jean-François Moine2458df42011-08-10 05:47:34 -03001329 {0xb1, 0x21, 0x2d, 0x63, 0x03, 0x00, 0x00, 0x10},
Jean-François Moine03ed2a12010-04-25 14:45:43 -03001330 /* exposure ? : 0200 - change with 0x1e at the end */
1331 {}
1332};
1333
Jean-Francois Moine5e31dc82009-02-01 13:59:42 -03001334static const u8 sp80708_sensor_init[][8] = {
1335 {0xa1, 0x18, 0x06, 0xf9, 0x00, 0x00, 0x00, 0x10},
1336 {0xa1, 0x18, 0x09, 0x1f, 0x00, 0x00, 0x00, 0x10},
1337 {0xa1, 0x18, 0x0a, 0x00, 0x00, 0x00, 0x00, 0x10},
1338 {0xa1, 0x18, 0x0d, 0xc0, 0x00, 0x00, 0x00, 0x10},
1339 {0xa1, 0x18, 0x0c, 0x04, 0x00, 0x00, 0x00, 0x10},
1340 {0xa1, 0x18, 0x0f, 0x0f, 0x00, 0x00, 0x00, 0x10},
1341 {0xa1, 0x18, 0x10, 0x40, 0x00, 0x00, 0x00, 0x10},
1342 {0xa1, 0x18, 0x11, 0x4e, 0x00, 0x00, 0x00, 0x10},
1343 {0xa1, 0x18, 0x12, 0x53, 0x00, 0x00, 0x00, 0x10},
1344 {0xa1, 0x18, 0x15, 0x80, 0x00, 0x00, 0x00, 0x10},
1345 {0xa1, 0x18, 0x18, 0x18, 0x00, 0x00, 0x00, 0x10},
1346 {0xa1, 0x18, 0x19, 0x18, 0x00, 0x00, 0x00, 0x10},
1347 {0xa1, 0x18, 0x1a, 0x10, 0x00, 0x00, 0x00, 0x10},
1348 {0xa1, 0x18, 0x1b, 0x10, 0x00, 0x00, 0x00, 0x10},
1349 {0xa1, 0x18, 0x1c, 0x28, 0x00, 0x00, 0x00, 0x10},
1350 {0xa1, 0x18, 0x1d, 0x02, 0x00, 0x00, 0x00, 0x10},
1351 {0xa1, 0x18, 0x1e, 0x10, 0x00, 0x00, 0x00, 0x10},
1352 {0xa1, 0x18, 0x26, 0x04, 0x00, 0x00, 0x00, 0x10},
1353 {0xa1, 0x18, 0x27, 0x1e, 0x00, 0x00, 0x00, 0x10},
1354 {0xa1, 0x18, 0x28, 0x5a, 0x00, 0x00, 0x00, 0x10},
1355 {0xa1, 0x18, 0x29, 0x28, 0x00, 0x00, 0x00, 0x10},
1356 {0xa1, 0x18, 0x2a, 0x78, 0x00, 0x00, 0x00, 0x10},
1357 {0xa1, 0x18, 0x2b, 0x01, 0x00, 0x00, 0x00, 0x10},
1358 {0xa1, 0x18, 0x2c, 0xf7, 0x00, 0x00, 0x00, 0x10},
1359 {0xa1, 0x18, 0x2d, 0x2d, 0x00, 0x00, 0x00, 0x10},
1360 {0xa1, 0x18, 0x2e, 0xd5, 0x00, 0x00, 0x00, 0x10},
1361 {0xa1, 0x18, 0x39, 0x42, 0x00, 0x00, 0x00, 0x10},
1362 {0xa1, 0x18, 0x3a, 0x67, 0x00, 0x00, 0x00, 0x10},
1363 {0xa1, 0x18, 0x3b, 0x87, 0x00, 0x00, 0x00, 0x10},
1364 {0xa1, 0x18, 0x3c, 0xa3, 0x00, 0x00, 0x00, 0x10},
1365 {0xa1, 0x18, 0x3d, 0xb0, 0x00, 0x00, 0x00, 0x10},
1366 {0xa1, 0x18, 0x3e, 0xbc, 0x00, 0x00, 0x00, 0x10},
1367 {0xa1, 0x18, 0x3f, 0xc8, 0x00, 0x00, 0x00, 0x10},
1368 {0xa1, 0x18, 0x40, 0xd4, 0x00, 0x00, 0x00, 0x10},
1369 {0xa1, 0x18, 0x41, 0xdf, 0x00, 0x00, 0x00, 0x10},
1370 {0xa1, 0x18, 0x42, 0xea, 0x00, 0x00, 0x00, 0x10},
1371 {0xa1, 0x18, 0x43, 0xf5, 0x00, 0x00, 0x00, 0x10},
1372 {0xa1, 0x18, 0x45, 0x80, 0x00, 0x00, 0x00, 0x10},
1373 {0xa1, 0x18, 0x46, 0x60, 0x00, 0x00, 0x00, 0x10},
1374 {0xa1, 0x18, 0x47, 0x50, 0x00, 0x00, 0x00, 0x10},
1375 {0xa1, 0x18, 0x48, 0x30, 0x00, 0x00, 0x00, 0x10},
1376 {0xa1, 0x18, 0x49, 0x01, 0x00, 0x00, 0x00, 0x10},
1377 {0xa1, 0x18, 0x4d, 0xae, 0x00, 0x00, 0x00, 0x10},
1378 {0xa1, 0x18, 0x4e, 0x03, 0x00, 0x00, 0x00, 0x10},
1379 {0xa1, 0x18, 0x4f, 0x66, 0x00, 0x00, 0x00, 0x10},
1380 {0xa1, 0x18, 0x50, 0x1c, 0x00, 0x00, 0x00, 0x10},
1381 {0xa1, 0x18, 0x44, 0x10, 0x00, 0x00, 0x00, 0x10},
1382 {0xa1, 0x18, 0x4a, 0x30, 0x00, 0x00, 0x00, 0x10},
1383 {0xa1, 0x18, 0x51, 0x80, 0x00, 0x00, 0x00, 0x10},
1384 {0xa1, 0x18, 0x52, 0x80, 0x00, 0x00, 0x00, 0x10},
1385 {0xa1, 0x18, 0x53, 0x80, 0x00, 0x00, 0x00, 0x10},
1386 {0xa1, 0x18, 0x54, 0x80, 0x00, 0x00, 0x00, 0x10},
1387 {0xa1, 0x18, 0x55, 0x80, 0x00, 0x00, 0x00, 0x10},
1388 {0xa1, 0x18, 0x56, 0x80, 0x00, 0x00, 0x00, 0x10},
1389 {0xa1, 0x18, 0x57, 0xe0, 0x00, 0x00, 0x00, 0x10},
1390 {0xa1, 0x18, 0x58, 0xc0, 0x00, 0x00, 0x00, 0x10},
1391 {0xa1, 0x18, 0x59, 0xab, 0x00, 0x00, 0x00, 0x10},
1392 {0xa1, 0x18, 0x5a, 0xa0, 0x00, 0x00, 0x00, 0x10},
1393 {0xa1, 0x18, 0x5b, 0x99, 0x00, 0x00, 0x00, 0x10},
1394 {0xa1, 0x18, 0x5c, 0x90, 0x00, 0x00, 0x00, 0x10},
1395 {0xa1, 0x18, 0x5e, 0x24, 0x00, 0x00, 0x00, 0x10},
1396 {0xa1, 0x18, 0x5f, 0x00, 0x00, 0x00, 0x00, 0x10},
1397 {0xa1, 0x18, 0x60, 0x00, 0x00, 0x00, 0x00, 0x10},
1398 {0xa1, 0x18, 0x61, 0x73, 0x00, 0x00, 0x00, 0x10},
1399 {0xa1, 0x18, 0x63, 0x42, 0x00, 0x00, 0x00, 0x10},
1400 {0xa1, 0x18, 0x64, 0x42, 0x00, 0x00, 0x00, 0x10},
1401 {0xa1, 0x18, 0x65, 0x42, 0x00, 0x00, 0x00, 0x10},
1402 {0xa1, 0x18, 0x66, 0x24, 0x00, 0x00, 0x00, 0x10},
1403 {0xa1, 0x18, 0x67, 0x24, 0x00, 0x00, 0x00, 0x10},
1404 {0xa1, 0x18, 0x68, 0x08, 0x00, 0x00, 0x00, 0x10},
1405 {0xa1, 0x18, 0x2f, 0xc9, 0x00, 0x00, 0x00, 0x10},
Jean-Francois Moine3fccb772009-11-02 09:54:04 -03001406 {}
1407};
1408static const u8 sp80708_sensor_param1[][8] = {
Jean-Francois Moine5e31dc82009-02-01 13:59:42 -03001409 {0xa1, 0x18, 0x0c, 0x04, 0x00, 0x00, 0x00, 0x10},
1410 {0xa1, 0x18, 0x0c, 0x04, 0x00, 0x00, 0x00, 0x10},
1411 {0xa1, 0x18, 0x03, 0x01, 0x00, 0x00, 0x00, 0x10},
1412 {0xa1, 0x18, 0x04, 0xa4, 0x00, 0x00, 0x00, 0x10},
1413 {0xa1, 0x18, 0x14, 0x3f, 0x00, 0x00, 0x00, 0x10},
1414 {0xa1, 0x18, 0x5d, 0x80, 0x00, 0x00, 0x00, 0x10},
1415 {0xb1, 0x18, 0x11, 0x40, 0x40, 0x00, 0x00, 0x10},
1416 {}
1417};
1418
Jean-François Moine9c33afc2010-03-17 15:25:32 -03001419static const u8 (*sensor_init[])[8] = {
1420[SENSOR_ADCM1700] = adcm1700_sensor_init,
Jean-François Moinead98c0f2010-03-18 05:15:30 -03001421[SENSOR_GC0307] = gc0307_sensor_init,
Jean-François Moine9c33afc2010-03-17 15:25:32 -03001422[SENSOR_HV7131R] = hv7131r_sensor_init,
1423[SENSOR_MI0360] = mi0360_sensor_init,
Jean-François Moinea067db82010-10-01 07:51:24 -03001424[SENSOR_MI0360B] = mi0360b_sensor_init,
Jean-François Moine9c33afc2010-03-17 15:25:32 -03001425[SENSOR_MO4000] = mo4000_sensor_init,
1426[SENSOR_MT9V111] = mt9v111_sensor_init,
1427[SENSOR_OM6802] = om6802_sensor_init,
1428[SENSOR_OV7630] = ov7630_sensor_init,
1429[SENSOR_OV7648] = ov7648_sensor_init,
1430[SENSOR_OV7660] = ov7660_sensor_init,
1431[SENSOR_PO1030] = po1030_sensor_init,
Jean-François Moinead98c0f2010-03-18 05:15:30 -03001432[SENSOR_PO2030N] = po2030n_sensor_init,
Jean-François Moine03ed2a12010-04-25 14:45:43 -03001433[SENSOR_SOI768] = soi768_sensor_init,
Jean-François Moine9c33afc2010-03-17 15:25:32 -03001434[SENSOR_SP80708] = sp80708_sensor_init,
Jean-Francois Moine23a98272009-11-02 09:10:25 -03001435};
1436
Jean-Francois Moine8295d992008-09-03 17:12:19 -03001437/* read <len> bytes to gspca_dev->usb_buf */
Jean-Francois Moine739570b2008-07-14 09:38:29 -03001438static void reg_r(struct gspca_dev *gspca_dev,
Jean-Francois Moine98819182009-01-19 07:37:33 -03001439 u16 value, int len)
Jean-Francois Moine6a7eba22008-06-30 15:50:11 -03001440{
Jean-François Moine4bf8b672010-09-25 06:12:44 -03001441 int ret;
1442
1443 if (gspca_dev->usb_err < 0)
1444 return;
Jean-Francois Moine8295d992008-09-03 17:12:19 -03001445#ifdef GSPCA_DEBUG
1446 if (len > USB_BUF_SZ) {
Joe Perches133a9fe2011-08-21 19:56:57 -03001447 pr_err("reg_r: buffer overflow\n");
Jean-Francois Moine8295d992008-09-03 17:12:19 -03001448 return;
1449 }
1450#endif
Jean-François Moine4bf8b672010-09-25 06:12:44 -03001451 ret = usb_control_msg(gspca_dev->dev,
Jean-Francois Moine739570b2008-07-14 09:38:29 -03001452 usb_rcvctrlpipe(gspca_dev->dev, 0),
Jean-Francois Moine6a7eba22008-06-30 15:50:11 -03001453 0,
1454 USB_DIR_IN | USB_TYPE_VENDOR | USB_RECIP_INTERFACE,
1455 value, 0,
Jean-Francois Moine739570b2008-07-14 09:38:29 -03001456 gspca_dev->usb_buf, len,
Jean-Francois Moine6a7eba22008-06-30 15:50:11 -03001457 500);
Jean-Francois Moine60017612008-07-18 08:46:19 -03001458 PDEBUG(D_USBI, "reg_r [%02x] -> %02x", value, gspca_dev->usb_buf[0]);
Jean-François Moine4bf8b672010-09-25 06:12:44 -03001459 if (ret < 0) {
Joe Perches133a9fe2011-08-21 19:56:57 -03001460 pr_err("reg_r err %d\n", ret);
Jean-François Moine4bf8b672010-09-25 06:12:44 -03001461 gspca_dev->usb_err = ret;
1462 }
Jean-Francois Moine6a7eba22008-06-30 15:50:11 -03001463}
1464
Jean-Francois Moine60017612008-07-18 08:46:19 -03001465static void reg_w1(struct gspca_dev *gspca_dev,
Jean-Francois Moine98819182009-01-19 07:37:33 -03001466 u16 value,
1467 u8 data)
Jean-Francois Moine60017612008-07-18 08:46:19 -03001468{
Jean-François Moine4bf8b672010-09-25 06:12:44 -03001469 int ret;
1470
1471 if (gspca_dev->usb_err < 0)
1472 return;
Jean-Francois Moine3ef2c5b2009-01-29 04:59:45 -03001473 PDEBUG(D_USBO, "reg_w1 [%04x] = %02x", value, data);
Jean-Francois Moine60017612008-07-18 08:46:19 -03001474 gspca_dev->usb_buf[0] = data;
Jean-François Moine4bf8b672010-09-25 06:12:44 -03001475 ret = usb_control_msg(gspca_dev->dev,
Jean-Francois Moine60017612008-07-18 08:46:19 -03001476 usb_sndctrlpipe(gspca_dev->dev, 0),
1477 0x08,
1478 USB_DIR_OUT | USB_TYPE_VENDOR | USB_RECIP_INTERFACE,
1479 value,
1480 0,
1481 gspca_dev->usb_buf, 1,
1482 500);
Jean-François Moine4bf8b672010-09-25 06:12:44 -03001483 if (ret < 0) {
Joe Perches133a9fe2011-08-21 19:56:57 -03001484 pr_err("reg_w1 err %d\n", ret);
Jean-François Moine4bf8b672010-09-25 06:12:44 -03001485 gspca_dev->usb_err = ret;
1486 }
Jean-Francois Moine60017612008-07-18 08:46:19 -03001487}
Jean-Francois Moine739570b2008-07-14 09:38:29 -03001488static void reg_w(struct gspca_dev *gspca_dev,
Jean-Francois Moine98819182009-01-19 07:37:33 -03001489 u16 value,
1490 const u8 *buffer,
Jean-Francois Moine6a7eba22008-06-30 15:50:11 -03001491 int len)
1492{
Jean-François Moine4bf8b672010-09-25 06:12:44 -03001493 int ret;
1494
1495 if (gspca_dev->usb_err < 0)
1496 return;
Jean-Francois Moine3ef2c5b2009-01-29 04:59:45 -03001497 PDEBUG(D_USBO, "reg_w [%04x] = %02x %02x ..",
Jean-Francois Moine60017612008-07-18 08:46:19 -03001498 value, buffer[0], buffer[1]);
Jean-Francois Moine8295d992008-09-03 17:12:19 -03001499#ifdef GSPCA_DEBUG
1500 if (len > USB_BUF_SZ) {
Joe Perches133a9fe2011-08-21 19:56:57 -03001501 pr_err("reg_w: buffer overflow\n");
Jean-Francois Moine8295d992008-09-03 17:12:19 -03001502 return;
Jean-Francois Moinebf7f0b92008-07-03 11:09:12 -03001503 }
Jean-Francois Moine8295d992008-09-03 17:12:19 -03001504#endif
1505 memcpy(gspca_dev->usb_buf, buffer, len);
Jean-François Moine4bf8b672010-09-25 06:12:44 -03001506 ret = usb_control_msg(gspca_dev->dev,
Jean-Francois Moine8295d992008-09-03 17:12:19 -03001507 usb_sndctrlpipe(gspca_dev->dev, 0),
1508 0x08,
1509 USB_DIR_OUT | USB_TYPE_VENDOR | USB_RECIP_INTERFACE,
1510 value, 0,
1511 gspca_dev->usb_buf, len,
1512 500);
Jean-François Moine4bf8b672010-09-25 06:12:44 -03001513 if (ret < 0) {
Joe Perches133a9fe2011-08-21 19:56:57 -03001514 pr_err("reg_w err %d\n", ret);
Jean-François Moine4bf8b672010-09-25 06:12:44 -03001515 gspca_dev->usb_err = ret;
1516 }
Jean-Francois Moine6a7eba22008-06-30 15:50:11 -03001517}
1518
Jean-Francois Moine60017612008-07-18 08:46:19 -03001519/* I2C write 1 byte */
Jean-Francois Moine98819182009-01-19 07:37:33 -03001520static void i2c_w1(struct gspca_dev *gspca_dev, u8 reg, u8 val)
Jean-Francois Moine6a7eba22008-06-30 15:50:11 -03001521{
1522 struct sd *sd = (struct sd *) gspca_dev;
Jean-François Moine4bf8b672010-09-25 06:12:44 -03001523 int ret;
Jean-Francois Moine6a7eba22008-06-30 15:50:11 -03001524
Jean-François Moine4bf8b672010-09-25 06:12:44 -03001525 if (gspca_dev->usb_err < 0)
1526 return;
Jean-François Moinecfd23c82010-04-25 14:27:39 -03001527 PDEBUG(D_USBO, "i2c_w1 [%02x] = %02x", reg, val);
Jean-Francois Moinea7826362009-11-02 09:21:06 -03001528 switch (sd->sensor) {
Jean-Francois Moine64677572009-12-20 12:31:28 -03001529 case SENSOR_ADCM1700:
Jean-François Moinead98c0f2010-03-18 05:15:30 -03001530 case SENSOR_OM6802:
1531 case SENSOR_GC0307: /* i2c command = a0 (100 kHz) */
Jean-Francois Moinea7826362009-11-02 09:21:06 -03001532 gspca_dev->usb_buf[0] = 0x80 | (2 << 4);
1533 break;
1534 default: /* i2c command = a1 (400 kHz) */
1535 gspca_dev->usb_buf[0] = 0x81 | (2 << 4);
1536 break;
1537 }
Jean-Francois Moined5aa3852009-11-07 06:10:08 -03001538 gspca_dev->usb_buf[1] = sd->i2c_addr;
Jean-Francois Moine60017612008-07-18 08:46:19 -03001539 gspca_dev->usb_buf[2] = reg;
1540 gspca_dev->usb_buf[3] = val;
1541 gspca_dev->usb_buf[4] = 0;
1542 gspca_dev->usb_buf[5] = 0;
1543 gspca_dev->usb_buf[6] = 0;
1544 gspca_dev->usb_buf[7] = 0x10;
Jean-François Moine4bf8b672010-09-25 06:12:44 -03001545 ret = usb_control_msg(gspca_dev->dev,
Jean-Francois Moine60017612008-07-18 08:46:19 -03001546 usb_sndctrlpipe(gspca_dev->dev, 0),
1547 0x08,
1548 USB_DIR_OUT | USB_TYPE_VENDOR | USB_RECIP_INTERFACE,
1549 0x08, /* value = i2c */
1550 0,
1551 gspca_dev->usb_buf, 8,
1552 500);
Jean-François Moine4bf8b672010-09-25 06:12:44 -03001553 if (ret < 0) {
Joe Perches133a9fe2011-08-21 19:56:57 -03001554 pr_err("i2c_w1 err %d\n", ret);
Jean-François Moine4bf8b672010-09-25 06:12:44 -03001555 gspca_dev->usb_err = ret;
1556 }
Jean-Francois Moine6a7eba22008-06-30 15:50:11 -03001557}
1558
Jean-Francois Moine739570b2008-07-14 09:38:29 -03001559/* I2C write 8 bytes */
1560static void i2c_w8(struct gspca_dev *gspca_dev,
Jean-Francois Moine98819182009-01-19 07:37:33 -03001561 const u8 *buffer)
Jean-Francois Moine6a7eba22008-06-30 15:50:11 -03001562{
Jean-François Moine4bf8b672010-09-25 06:12:44 -03001563 int ret;
1564
1565 if (gspca_dev->usb_err < 0)
1566 return;
Jean-François Moinecfd23c82010-04-25 14:27:39 -03001567 PDEBUG(D_USBO, "i2c_w8 [%02x] = %02x ..",
1568 buffer[2], buffer[3]);
Jean-Francois Moine60017612008-07-18 08:46:19 -03001569 memcpy(gspca_dev->usb_buf, buffer, 8);
Jean-François Moine4bf8b672010-09-25 06:12:44 -03001570 ret = usb_control_msg(gspca_dev->dev,
Jean-Francois Moine60017612008-07-18 08:46:19 -03001571 usb_sndctrlpipe(gspca_dev->dev, 0),
1572 0x08,
1573 USB_DIR_OUT | USB_TYPE_VENDOR | USB_RECIP_INTERFACE,
1574 0x08, 0, /* value, index */
1575 gspca_dev->usb_buf, 8,
1576 500);
Jean-Francois Moine8d768e12008-09-21 03:28:55 -03001577 msleep(2);
Jean-François Moine4bf8b672010-09-25 06:12:44 -03001578 if (ret < 0) {
Joe Perches133a9fe2011-08-21 19:56:57 -03001579 pr_err("i2c_w8 err %d\n", ret);
Jean-François Moine4bf8b672010-09-25 06:12:44 -03001580 gspca_dev->usb_err = ret;
1581 }
Jean-Francois Moine6a7eba22008-06-30 15:50:11 -03001582}
1583
Jean-Francois Moineb8c8a5b2009-11-23 06:46:35 -03001584/* sensor read 'len' (1..5) bytes in gspca_dev->usb_buf */
1585static void i2c_r(struct gspca_dev *gspca_dev, u8 reg, int len)
Jean-Francois Moine6a7eba22008-06-30 15:50:11 -03001586{
1587 struct sd *sd = (struct sd *) gspca_dev;
Jean-Francois Moine98819182009-01-19 07:37:33 -03001588 u8 mode[8];
Jean-Francois Moine6a7eba22008-06-30 15:50:11 -03001589
Jean-Francois Moinea7826362009-11-02 09:21:06 -03001590 switch (sd->sensor) {
Jean-Francois Moine64677572009-12-20 12:31:28 -03001591 case SENSOR_ADCM1700:
Jean-François Moinead98c0f2010-03-18 05:15:30 -03001592 case SENSOR_OM6802:
1593 case SENSOR_GC0307: /* i2c command = a0 (100 kHz) */
Jean-Francois Moinea7826362009-11-02 09:21:06 -03001594 mode[0] = 0x80 | 0x10;
1595 break;
1596 default: /* i2c command = 91 (400 kHz) */
1597 mode[0] = 0x81 | 0x10;
1598 break;
1599 }
Jean-Francois Moined5aa3852009-11-07 06:10:08 -03001600 mode[1] = sd->i2c_addr;
Jean-Francois Moine6a7eba22008-06-30 15:50:11 -03001601 mode[2] = reg;
1602 mode[3] = 0;
1603 mode[4] = 0;
1604 mode[5] = 0;
1605 mode[6] = 0;
1606 mode[7] = 0x10;
Jean-Francois Moine739570b2008-07-14 09:38:29 -03001607 i2c_w8(gspca_dev, mode);
Jean-Francois Moine60017612008-07-18 08:46:19 -03001608 msleep(2);
Jean-Francois Moineb8c8a5b2009-11-23 06:46:35 -03001609 mode[0] = (mode[0] & 0x81) | (len << 4) | 0x02;
Jean-Francois Moine6a7eba22008-06-30 15:50:11 -03001610 mode[2] = 0;
Jean-Francois Moine739570b2008-07-14 09:38:29 -03001611 i2c_w8(gspca_dev, mode);
Jean-Francois Moine60017612008-07-18 08:46:19 -03001612 msleep(2);
Jean-Francois Moine739570b2008-07-14 09:38:29 -03001613 reg_r(gspca_dev, 0x0a, 5);
Jean-Francois Moine6a7eba22008-06-30 15:50:11 -03001614}
1615
Jean-Francois Moine23a98272009-11-02 09:10:25 -03001616static void i2c_w_seq(struct gspca_dev *gspca_dev,
1617 const u8 (*data)[8])
1618{
1619 while ((*data)[0] != 0) {
Németh Mártonccbc5df2010-10-18 07:00:48 -03001620 if ((*data)[0] != DELAY)
Jean-Francois Moine23a98272009-11-02 09:10:25 -03001621 i2c_w8(gspca_dev, *data);
1622 else
1623 msleep((*data)[1]);
1624 data++;
1625 }
1626}
1627
Jean-François Moinea79cc7b2010-10-29 08:10:37 -03001628/* check the ID of the hv7131 sensor */
1629/* this sequence is needed because it activates the sensor */
Jean-Francois Moine7fb101a2009-10-22 06:27:14 -03001630static void hv7131r_probe(struct gspca_dev *gspca_dev)
Jean-Francois Moine6a7eba22008-06-30 15:50:11 -03001631{
Jean-François Moinea79cc7b2010-10-29 08:10:37 -03001632 i2c_w1(gspca_dev, 0x02, 0); /* sensor wakeup */
Jean-Francois Moine6a7eba22008-06-30 15:50:11 -03001633 msleep(10);
Jean-François Moinea79cc7b2010-10-29 08:10:37 -03001634 reg_w1(gspca_dev, 0x02, 0x66); /* Gpio on */
Jean-Francois Moine6a7eba22008-06-30 15:50:11 -03001635 msleep(10);
Jean-François Moinea79cc7b2010-10-29 08:10:37 -03001636 i2c_r(gspca_dev, 0, 5); /* read sensor id */
1637 if (gspca_dev->usb_buf[0] == 0x02 /* chip ID (02 is R) */
Jean-Francois Moine739570b2008-07-14 09:38:29 -03001638 && gspca_dev->usb_buf[1] == 0x09
Jean-François Moinea79cc7b2010-10-29 08:10:37 -03001639 && gspca_dev->usb_buf[2] == 0x01) {
1640 PDEBUG(D_PROBE, "Sensor HV7131R found");
Jean-Francois Moine7fb101a2009-10-22 06:27:14 -03001641 return;
Jean-Francois Moine6a7eba22008-06-30 15:50:11 -03001642 }
Joe Perches133a9fe2011-08-21 19:56:57 -03001643 pr_warn("Erroneous HV7131R ID 0x%02x 0x%02x 0x%02x\n",
Jean-Francois Moine739570b2008-07-14 09:38:29 -03001644 gspca_dev->usb_buf[0], gspca_dev->usb_buf[1],
1645 gspca_dev->usb_buf[2]);
Jean-Francois Moine6a7eba22008-06-30 15:50:11 -03001646}
1647
Jean-Francois Moine65c52592009-02-01 14:26:51 -03001648static void mi0360_probe(struct gspca_dev *gspca_dev)
Jean-Francois Moine3ef2c5b2009-01-29 04:59:45 -03001649{
Jean-Francois Moine65c52592009-02-01 14:26:51 -03001650 struct sd *sd = (struct sd *) gspca_dev;
Jean-Francois Moine3ef2c5b2009-01-29 04:59:45 -03001651 int i, j;
Jean-Francois Moine92e8c912009-02-02 16:25:38 -03001652 u16 val = 0;
Jean-Francois Moine3ef2c5b2009-01-29 04:59:45 -03001653 static const u8 probe_tb[][4][8] = {
Jean-Francois Moine65c52592009-02-01 14:26:51 -03001654 { /* mi0360 */
Jean-Francois Moine3ef2c5b2009-01-29 04:59:45 -03001655 {0xb0, 0x5d, 0x07, 0x00, 0x02, 0x00, 0x00, 0x10},
1656 {0x90, 0x5d, 0x00, 0x00, 0x00, 0x00, 0x00, 0x10},
1657 {0xa2, 0x5d, 0x00, 0x00, 0x00, 0x00, 0x00, 0x10},
1658 {0xb0, 0x5d, 0x07, 0x00, 0x00, 0x00, 0x00, 0x10}
1659 },
Jean-Francois Moine65c52592009-02-01 14:26:51 -03001660 { /* mt9v111 */
Jean-Francois Moine3ef2c5b2009-01-29 04:59:45 -03001661 {0xb0, 0x5c, 0x01, 0x00, 0x04, 0x00, 0x00, 0x10},
1662 {0x90, 0x5c, 0x36, 0x00, 0x00, 0x00, 0x00, 0x10},
1663 {0xa2, 0x5c, 0x00, 0x00, 0x00, 0x00, 0x00, 0x10},
1664 {}
1665 },
1666 };
1667
1668 for (i = 0; i < ARRAY_SIZE(probe_tb); i++) {
1669 reg_w1(gspca_dev, 0x17, 0x62);
1670 reg_w1(gspca_dev, 0x01, 0x08);
1671 for (j = 0; j < 3; j++)
1672 i2c_w8(gspca_dev, probe_tb[i][j]);
1673 msleep(2);
1674 reg_r(gspca_dev, 0x0a, 5);
1675 val = (gspca_dev->usb_buf[3] << 8) | gspca_dev->usb_buf[4];
1676 if (probe_tb[i][3][0] != 0)
1677 i2c_w8(gspca_dev, probe_tb[i][3]);
1678 reg_w1(gspca_dev, 0x01, 0x29);
1679 reg_w1(gspca_dev, 0x17, 0x42);
1680 if (val != 0xffff)
1681 break;
1682 }
Jean-François Moine4bf8b672010-09-25 06:12:44 -03001683 if (gspca_dev->usb_err < 0)
1684 return;
Jean-Francois Moine3ef2c5b2009-01-29 04:59:45 -03001685 switch (val) {
Jean-François Moinea067db82010-10-01 07:51:24 -03001686 case 0x8221:
1687 PDEBUG(D_PROBE, "Sensor mi0360b");
1688 sd->sensor = SENSOR_MI0360B;
1689 break;
Jean-Francois Moine3ef2c5b2009-01-29 04:59:45 -03001690 case 0x823a:
1691 PDEBUG(D_PROBE, "Sensor mt9v111");
Jean-Francois Moine65c52592009-02-01 14:26:51 -03001692 sd->sensor = SENSOR_MT9V111;
Jean-Francois Moine65c52592009-02-01 14:26:51 -03001693 break;
Jean-Francois Moine3ef2c5b2009-01-29 04:59:45 -03001694 case 0x8243:
1695 PDEBUG(D_PROBE, "Sensor mi0360");
Jean-Francois Moine65c52592009-02-01 14:26:51 -03001696 break;
1697 default:
1698 PDEBUG(D_PROBE, "Unknown sensor %04x - forced to mi0360", val);
1699 break;
Jean-Francois Moine3ef2c5b2009-01-29 04:59:45 -03001700 }
Jean-Francois Moine3ef2c5b2009-01-29 04:59:45 -03001701}
1702
Jean-François Moine03ed2a12010-04-25 14:45:43 -03001703static void ov7630_probe(struct gspca_dev *gspca_dev)
1704{
1705 struct sd *sd = (struct sd *) gspca_dev;
1706 u16 val;
1707
1708 /* check ov76xx */
1709 reg_w1(gspca_dev, 0x17, 0x62);
1710 reg_w1(gspca_dev, 0x01, 0x08);
1711 sd->i2c_addr = 0x21;
1712 i2c_r(gspca_dev, 0x0a, 2);
1713 val = (gspca_dev->usb_buf[3] << 8) | gspca_dev->usb_buf[4];
1714 reg_w1(gspca_dev, 0x01, 0x29);
1715 reg_w1(gspca_dev, 0x17, 0x42);
Jean-François Moine4bf8b672010-09-25 06:12:44 -03001716 if (gspca_dev->usb_err < 0)
1717 return;
Jean-François Moine03ed2a12010-04-25 14:45:43 -03001718 if (val == 0x7628) { /* soi768 */
1719 sd->sensor = SENSOR_SOI768;
1720/*fixme: only valid for 0c45:613e?*/
1721 gspca_dev->cam.input_flags =
1722 V4L2_IN_ST_VFLIP | V4L2_IN_ST_HFLIP;
1723 PDEBUG(D_PROBE, "Sensor soi768");
1724 return;
1725 }
1726 PDEBUG(D_PROBE, "Sensor ov%04x", val);
1727}
1728
Jean-Francois Moineb8c8a5b2009-11-23 06:46:35 -03001729static void ov7648_probe(struct gspca_dev *gspca_dev)
1730{
1731 struct sd *sd = (struct sd *) gspca_dev;
Jean-François Moinee3302ca2010-04-25 14:41:51 -03001732 u16 val;
Jean-Francois Moineb8c8a5b2009-11-23 06:46:35 -03001733
1734 /* check ov76xx */
1735 reg_w1(gspca_dev, 0x17, 0x62);
1736 reg_w1(gspca_dev, 0x01, 0x08);
1737 sd->i2c_addr = 0x21;
1738 i2c_r(gspca_dev, 0x0a, 2);
Jean-François Moinee3302ca2010-04-25 14:41:51 -03001739 val = (gspca_dev->usb_buf[3] << 8) | gspca_dev->usb_buf[4];
Jean-Francois Moineb8c8a5b2009-11-23 06:46:35 -03001740 reg_w1(gspca_dev, 0x01, 0x29);
1741 reg_w1(gspca_dev, 0x17, 0x42);
Jean-François Moinee3302ca2010-04-25 14:41:51 -03001742 if ((val & 0xff00) == 0x7600) { /* ov76xx */
1743 PDEBUG(D_PROBE, "Sensor ov%04x", val);
1744 return;
1745 }
Jean-Francois Moineb8c8a5b2009-11-23 06:46:35 -03001746
1747 /* check po1030 */
1748 reg_w1(gspca_dev, 0x17, 0x62);
1749 reg_w1(gspca_dev, 0x01, 0x08);
1750 sd->i2c_addr = 0x6e;
1751 i2c_r(gspca_dev, 0x00, 2);
Jean-François Moinee3302ca2010-04-25 14:41:51 -03001752 val = (gspca_dev->usb_buf[3] << 8) | gspca_dev->usb_buf[4];
1753 reg_w1(gspca_dev, 0x01, 0x29);
1754 reg_w1(gspca_dev, 0x17, 0x42);
Jean-François Moine4bf8b672010-09-25 06:12:44 -03001755 if (gspca_dev->usb_err < 0)
1756 return;
Jean-François Moinee3302ca2010-04-25 14:41:51 -03001757 if (val == 0x1030) { /* po1030 */
Jean-Francois Moineb8c8a5b2009-11-23 06:46:35 -03001758 PDEBUG(D_PROBE, "Sensor po1030");
1759 sd->sensor = SENSOR_PO1030;
1760 return;
1761 }
Joe Perches133a9fe2011-08-21 19:56:57 -03001762 pr_err("Unknown sensor %04x\n", val);
Jean-Francois Moineb8c8a5b2009-11-23 06:46:35 -03001763}
1764
Jean-François Moinead98c0f2010-03-18 05:15:30 -03001765/* 0c45:6142 sensor may be po2030n, gc0305 or gc0307 */
1766static void po2030n_probe(struct gspca_dev *gspca_dev)
1767{
1768 struct sd *sd = (struct sd *) gspca_dev;
Jean-François Moinee3302ca2010-04-25 14:41:51 -03001769 u16 val;
Jean-François Moinead98c0f2010-03-18 05:15:30 -03001770
1771 /* check gc0307 */
1772 reg_w1(gspca_dev, 0x17, 0x62);
1773 reg_w1(gspca_dev, 0x01, 0x08);
1774 reg_w1(gspca_dev, 0x02, 0x22);
1775 sd->i2c_addr = 0x21;
1776 i2c_r(gspca_dev, 0x00, 1);
Jean-François Moinee3302ca2010-04-25 14:41:51 -03001777 val = gspca_dev->usb_buf[4];
Jean-François Moinead98c0f2010-03-18 05:15:30 -03001778 reg_w1(gspca_dev, 0x01, 0x29); /* reset */
1779 reg_w1(gspca_dev, 0x17, 0x42);
Jean-François Moinee3302ca2010-04-25 14:41:51 -03001780 if (val == 0x99) { /* gc0307 (?) */
Jean-François Moinead98c0f2010-03-18 05:15:30 -03001781 PDEBUG(D_PROBE, "Sensor gc0307");
1782 sd->sensor = SENSOR_GC0307;
1783 return;
1784 }
1785
1786 /* check po2030n */
1787 reg_w1(gspca_dev, 0x17, 0x62);
1788 reg_w1(gspca_dev, 0x01, 0x0a);
1789 sd->i2c_addr = 0x6e;
1790 i2c_r(gspca_dev, 0x00, 2);
Jean-François Moinee3302ca2010-04-25 14:41:51 -03001791 val = (gspca_dev->usb_buf[3] << 8) | gspca_dev->usb_buf[4];
Jean-François Moinead98c0f2010-03-18 05:15:30 -03001792 reg_w1(gspca_dev, 0x01, 0x29);
1793 reg_w1(gspca_dev, 0x17, 0x42);
Jean-François Moine4bf8b672010-09-25 06:12:44 -03001794 if (gspca_dev->usb_err < 0)
1795 return;
Jean-François Moinee3302ca2010-04-25 14:41:51 -03001796 if (val == 0x2030) {
Jean-François Moinead98c0f2010-03-18 05:15:30 -03001797 PDEBUG(D_PROBE, "Sensor po2030n");
1798/* sd->sensor = SENSOR_PO2030N; */
Jean-François Moinee3302ca2010-04-25 14:41:51 -03001799 } else {
Joe Perches133a9fe2011-08-21 19:56:57 -03001800 pr_err("Unknown sensor ID %04x\n", val);
Jean-François Moinee3302ca2010-04-25 14:41:51 -03001801 }
Jean-François Moinead98c0f2010-03-18 05:15:30 -03001802}
1803
Jean-Francois Moine6a7eba22008-06-30 15:50:11 -03001804/* this function is called at probe time */
1805static int sd_config(struct gspca_dev *gspca_dev,
1806 const struct usb_device_id *id)
1807{
1808 struct sd *sd = (struct sd *) gspca_dev;
1809 struct cam *cam;
Jean-Francois Moine6a7eba22008-06-30 15:50:11 -03001810
Jean-Francois Moineeac8f5f2010-01-12 07:12:43 -03001811 sd->bridge = id->driver_info >> 16;
Jean-Francois Moinec6c14332010-12-14 16:15:37 -03001812 sd->sensor = id->driver_info >> 8;
1813 sd->flags = id->driver_info;
Jean-Francois Moineeac8f5f2010-01-12 07:12:43 -03001814
Jean-Francois Moine6a7eba22008-06-30 15:50:11 -03001815 cam = &gspca_dev->cam;
Jean-Francois Moine64677572009-12-20 12:31:28 -03001816 if (sd->sensor == SENSOR_ADCM1700) {
1817 cam->cam_mode = cif_mode;
1818 cam->nmodes = ARRAY_SIZE(cif_mode);
1819 } else {
1820 cam->cam_mode = vga_mode;
1821 cam->nmodes = ARRAY_SIZE(vga_mode);
1822 }
Jean-Francois Moine49cb6b02009-04-25 13:29:01 -03001823 cam->npkt = 24; /* 24 packets per ISOC message */
Jean-François Moine72b667e2010-10-02 04:35:25 -03001824 cam->ctrls = sd->ctrls;
Jean-Francois Moinea5ae2062008-07-04 11:16:16 -03001825
Jean-Francois Moinecebf3b62008-08-03 07:52:53 -03001826 sd->ag_cnt = -1;
Jean-Francois Moine77ac0ba2009-03-02 06:40:52 -03001827 sd->quality = QUALITY_DEF;
Jean-Francois Moinecebf3b62008-08-03 07:52:53 -03001828
Jean-François Moineb96cfc32011-02-10 07:38:58 -03001829 INIT_WORK(&sd->work, qual_upd);
1830
Jean-Francois Moine6a7eba22008-06-30 15:50:11 -03001831 return 0;
1832}
1833
Jean-Francois Moine012d6b02008-09-03 17:12:16 -03001834/* this function is called at probe and resume time */
1835static int sd_init(struct gspca_dev *gspca_dev)
Jean-Francois Moine6a7eba22008-06-30 15:50:11 -03001836{
1837 struct sd *sd = (struct sd *) gspca_dev;
Jean-Francois Moined5aa3852009-11-07 06:10:08 -03001838 const u8 *sn9c1xx;
Jean-François Moinee6a92a72011-02-10 07:52:58 -03001839 u8 regGpio[] = { 0x29, 0x70 }; /* no audio */
Jean-Francois Moine98819182009-01-19 07:37:33 -03001840 u8 regF1;
Jean-Francois Moine6a7eba22008-06-30 15:50:11 -03001841
Hans de Goede3647fea2008-07-15 05:36:30 -03001842 /* setup a selector by bridge */
Jean-Francois Moine60017612008-07-18 08:46:19 -03001843 reg_w1(gspca_dev, 0xf1, 0x01);
Jean-Francois Moine739570b2008-07-14 09:38:29 -03001844 reg_r(gspca_dev, 0x00, 1);
Jean-Francois Moine4f67f3a2010-12-14 16:15:00 -03001845 reg_w1(gspca_dev, 0xf1, 0x00);
Jean-Francois Moine8f47a3c2008-07-29 14:14:04 -03001846 reg_r(gspca_dev, 0x00, 1); /* get sonix chip id */
Jean-Francois Moine739570b2008-07-14 09:38:29 -03001847 regF1 = gspca_dev->usb_buf[0];
Jean-François Moine4bf8b672010-09-25 06:12:44 -03001848 if (gspca_dev->usb_err < 0)
1849 return gspca_dev->usb_err;
Jean-Francois Moine8f47a3c2008-07-29 14:14:04 -03001850 PDEBUG(D_PROBE, "Sonix chip id: %02x", regF1);
Jean-François Moinee6a92a72011-02-10 07:52:58 -03001851 if (gspca_dev->audio)
1852 regGpio[1] |= 0x04; /* with audio */
Hans de Goede3647fea2008-07-15 05:36:30 -03001853 switch (sd->bridge) {
1854 case BRIDGE_SN9C102P:
Hans de Goede3647fea2008-07-15 05:36:30 -03001855 case BRIDGE_SN9C105:
Jean-Francois Moine6a7eba22008-06-30 15:50:11 -03001856 if (regF1 != 0x11)
1857 return -ENODEV;
Jean-Francois Moine6a7eba22008-06-30 15:50:11 -03001858 break;
1859 default:
Jean-Francois Moine60017612008-07-18 08:46:19 -03001860/* case BRIDGE_SN9C110: */
Hans de Goedee530a5e2011-01-06 15:23:55 -03001861/* case BRIDGE_SN9C120: */
Jean-Francois Moine6a7eba22008-06-30 15:50:11 -03001862 if (regF1 != 0x12)
1863 return -ENODEV;
Hans de Goedee530a5e2011-01-06 15:23:55 -03001864 }
1865
1866 switch (sd->sensor) {
1867 case SENSOR_MI0360:
1868 mi0360_probe(gspca_dev);
1869 break;
1870 case SENSOR_OV7630:
1871 ov7630_probe(gspca_dev);
1872 break;
1873 case SENSOR_OV7648:
1874 ov7648_probe(gspca_dev);
1875 break;
1876 case SENSOR_PO2030N:
1877 po2030n_probe(gspca_dev);
1878 break;
1879 }
1880
1881 switch (sd->bridge) {
1882 case BRIDGE_SN9C102P:
1883 reg_w1(gspca_dev, 0x02, regGpio[1]);
1884 break;
Jean-François Moine336d23e2011-02-10 08:00:40 -03001885 default:
Hans de Goedee530a5e2011-01-06 15:23:55 -03001886 reg_w(gspca_dev, 0x01, regGpio, 2);
1887 break;
Jean-Francois Moine6a7eba22008-06-30 15:50:11 -03001888 }
1889
Jean-François Moine72b667e2010-10-02 04:35:25 -03001890 if (sd->sensor == SENSOR_OM6802)
1891 sd->ctrls[SHARPNESS].def = 0x10;
1892
Hans de Goede9712a8b2010-01-31 12:54:29 -03001893 /* Note we do not disable the sensor clock here (power saving mode),
1894 as that also disables the button on the cam. */
1895 reg_w1(gspca_dev, 0xf1, 0x00);
Jean-Francois Moine6a7eba22008-06-30 15:50:11 -03001896
Jean-Francois Moined5aa3852009-11-07 06:10:08 -03001897 /* set the i2c address */
1898 sn9c1xx = sn_tb[sd->sensor];
1899 sd->i2c_addr = sn9c1xx[9];
1900
Jean-Francois Moineb8c8a5b2009-11-23 06:46:35 -03001901 gspca_dev->ctrl_dis = ctrl_dis[sd->sensor];
Jean-François Moine3afef852011-01-13 06:39:11 -03001902 if (!(sd->flags & F_ILLUM))
1903 gspca_dev->ctrl_dis |= (1 << ILLUM);
Jean-Francois Moineb8c8a5b2009-11-23 06:46:35 -03001904
Jean-François Moine4bf8b672010-09-25 06:12:44 -03001905 return gspca_dev->usb_err;
Jean-Francois Moine6a7eba22008-06-30 15:50:11 -03001906}
1907
Jean-François Moinea7705c02012-02-27 06:57:04 -03001908static u32 expo_adjust(struct gspca_dev *gspca_dev,
Jean-Francois Moine98819182009-01-19 07:37:33 -03001909 u32 expo)
Jean-Francois Moine6a7eba22008-06-30 15:50:11 -03001910{
1911 struct sd *sd = (struct sd *) gspca_dev;
Jean-Francois Moine6a7eba22008-06-30 15:50:11 -03001912
1913 switch (sd->sensor) {
Jean-François Moinec26b12d2010-04-02 07:08:39 -03001914 case SENSOR_GC0307: {
1915 int a, b;
1916
1917 /* expo = 0..255 -> a = 19..43 */
1918 a = 19 + expo * 25 / 256;
1919 i2c_w1(gspca_dev, 0x68, a);
1920 a -= 12;
1921 b = a * a * 4; /* heuristic */
1922 i2c_w1(gspca_dev, 0x03, b >> 8);
1923 i2c_w1(gspca_dev, 0x04, b);
1924 break;
1925 }
Jean-Francois Moine6a7eba22008-06-30 15:50:11 -03001926 case SENSOR_HV7131R: {
Jean-Francois Moine98819182009-01-19 07:37:33 -03001927 u8 Expodoit[] =
Jean-Francois Moined5aa3852009-11-07 06:10:08 -03001928 { 0xc1, 0x11, 0x25, 0x00, 0x00, 0x00, 0x00, 0x16 };
Jean-Francois Moine6a7eba22008-06-30 15:50:11 -03001929
1930 Expodoit[3] = expo >> 16;
1931 Expodoit[4] = expo >> 8;
1932 Expodoit[5] = expo;
Jean-Francois Moine739570b2008-07-14 09:38:29 -03001933 i2c_w8(gspca_dev, Expodoit);
Jean-Francois Moine6a7eba22008-06-30 15:50:11 -03001934 break;
1935 }
Jean-François Moinea067db82010-10-01 07:51:24 -03001936 case SENSOR_MI0360:
1937 case SENSOR_MI0360B: {
Jean-Francois Moine3ef2c5b2009-01-29 04:59:45 -03001938 u8 expoMi[] = /* exposure 0x0635 -> 4 fp/s 0x10 */
Jean-Francois Moined5aa3852009-11-07 06:10:08 -03001939 { 0xb1, 0x5d, 0x09, 0x00, 0x00, 0x00, 0x00, 0x16 };
Jean-Francois Moine98819182009-01-19 07:37:33 -03001940 static const u8 doit[] = /* update sensor */
1941 { 0xb1, 0x5d, 0x07, 0x00, 0x03, 0x00, 0x00, 0x10 };
1942 static const u8 sensorgo[] = /* sensor on */
1943 { 0xb1, 0x5d, 0x07, 0x00, 0x02, 0x00, 0x00, 0x10 };
Jean-Francois Moine6a7eba22008-06-30 15:50:11 -03001944
1945 if (expo > 0x0635)
1946 expo = 0x0635;
1947 else if (expo < 0x0001)
1948 expo = 0x0001;
1949 expoMi[3] = expo >> 8;
1950 expoMi[4] = expo;
Jean-Francois Moine739570b2008-07-14 09:38:29 -03001951 i2c_w8(gspca_dev, expoMi);
1952 i2c_w8(gspca_dev, doit);
1953 i2c_w8(gspca_dev, sensorgo);
Jean-Francois Moine6a7eba22008-06-30 15:50:11 -03001954 break;
1955 }
1956 case SENSOR_MO4000: {
Jean-Francois Moine98819182009-01-19 07:37:33 -03001957 u8 expoMof[] =
Jean-Francois Moined5aa3852009-11-07 06:10:08 -03001958 { 0xa1, 0x21, 0x0f, 0x00, 0x00, 0x00, 0x00, 0x10 };
Jean-Francois Moine98819182009-01-19 07:37:33 -03001959 u8 expoMo10[] =
Jean-Francois Moined5aa3852009-11-07 06:10:08 -03001960 { 0xa1, 0x21, 0x10, 0x00, 0x00, 0x00, 0x00, 0x10 };
Jean-Francois Moine98819182009-01-19 07:37:33 -03001961 static const u8 gainMo[] =
1962 { 0xa1, 0x21, 0x00, 0x10, 0x00, 0x00, 0x00, 0x1d };
Jean-Francois Moine6a7eba22008-06-30 15:50:11 -03001963
1964 if (expo > 0x1fff)
1965 expo = 0x1fff;
1966 else if (expo < 0x0001)
1967 expo = 0x0001;
1968 expoMof[3] = (expo & 0x03fc) >> 2;
Jean-Francois Moine739570b2008-07-14 09:38:29 -03001969 i2c_w8(gspca_dev, expoMof);
Jean-Francois Moine6a7eba22008-06-30 15:50:11 -03001970 expoMo10[3] = ((expo & 0x1c00) >> 10)
1971 | ((expo & 0x0003) << 4);
Jean-Francois Moine739570b2008-07-14 09:38:29 -03001972 i2c_w8(gspca_dev, expoMo10);
1973 i2c_w8(gspca_dev, gainMo);
Jean-Francois Moine3ef2c5b2009-01-29 04:59:45 -03001974 PDEBUG(D_FRAM, "set exposure %d",
Jean-Francois Moine6a7eba22008-06-30 15:50:11 -03001975 ((expoMo10[3] & 0x07) << 10)
1976 | (expoMof[3] << 2)
1977 | ((expoMo10[3] & 0x30) >> 4));
1978 break;
1979 }
Jean-Francois Moine3ef2c5b2009-01-29 04:59:45 -03001980 case SENSOR_MT9V111: {
1981 u8 expo_c1[] =
1982 { 0xb1, 0x5c, 0x09, 0x00, 0x00, 0x00, 0x00, 0x10 };
1983
Jean-François Moine22203672011-02-10 07:49:32 -03001984 if (expo > 0x0390)
1985 expo = 0x0390;
1986 else if (expo < 0x0060)
1987 expo = 0x0060;
Jean-Francois Moine3ef2c5b2009-01-29 04:59:45 -03001988 expo_c1[3] = expo >> 8;
1989 expo_c1[4] = expo;
1990 i2c_w8(gspca_dev, expo_c1);
1991 break;
1992 }
Jean-Francois Moined2d16e92008-09-03 16:47:23 -03001993 case SENSOR_OM6802: {
Jean-Francois Moine98819182009-01-19 07:37:33 -03001994 u8 gainOm[] =
Jean-Francois Moined2d16e92008-09-03 16:47:23 -03001995 { 0xa0, 0x34, 0xe5, 0x00, 0x00, 0x00, 0x00, 0x10 };
Jean-Francois Moined5aa3852009-11-07 06:10:08 -03001996 /* preset AGC - works when AutoExpo = off */
Jean-Francois Moined2d16e92008-09-03 16:47:23 -03001997
1998 if (expo > 0x03ff)
1999 expo = 0x03ff;
2000 if (expo < 0x0001)
2001 expo = 0x0001;
2002 gainOm[3] = expo >> 2;
2003 i2c_w8(gspca_dev, gainOm);
Jean-Francois Moined5aa3852009-11-07 06:10:08 -03002004 reg_w1(gspca_dev, 0x96, expo >> 5);
Jean-Francois Moine3ef2c5b2009-01-29 04:59:45 -03002005 PDEBUG(D_FRAM, "set exposure %d", gainOm[3]);
Jean-Francois Moined2d16e92008-09-03 16:47:23 -03002006 break;
2007 }
Jean-Francois Moine6a7eba22008-06-30 15:50:11 -03002008 }
2009 return expo;
2010}
2011
2012static void setbrightness(struct gspca_dev *gspca_dev)
2013{
2014 struct sd *sd = (struct sd *) gspca_dev;
2015 unsigned int expo;
Jean-François Moine72b667e2010-10-02 04:35:25 -03002016 int brightness;
Jean-Francois Moine98819182009-01-19 07:37:33 -03002017 u8 k2;
Jean-Francois Moine6a7eba22008-06-30 15:50:11 -03002018
Jean-François Moine72b667e2010-10-02 04:35:25 -03002019 brightness = sd->ctrls[BRIGHTNESS].val;
2020 k2 = (brightness - 0x80) >> 2;
Jean-Francois Moine6a7eba22008-06-30 15:50:11 -03002021 switch (sd->sensor) {
Jean-Francois Moine64677572009-12-20 12:31:28 -03002022 case SENSOR_ADCM1700:
Jean-Francois Moine878b35a2009-12-30 04:53:07 -03002023 if (k2 > 0x1f)
2024 k2 = 0; /* only positive Y offset */
2025 break;
Jean-Francois Moine6a7eba22008-06-30 15:50:11 -03002026 case SENSOR_HV7131R:
Jean-François Moine72b667e2010-10-02 04:35:25 -03002027 expo = brightness << 12;
Jean-Francois Moine6a7eba22008-06-30 15:50:11 -03002028 if (expo > 0x002dc6c0)
2029 expo = 0x002dc6c0;
2030 else if (expo < 0x02a0)
2031 expo = 0x02a0;
Jean-François Moinea7705c02012-02-27 06:57:04 -03002032 sd->exposure = expo_adjust(gspca_dev, expo);
Jean-Francois Moine6a7eba22008-06-30 15:50:11 -03002033 break;
2034 case SENSOR_MI0360:
Jean-Francois Moine6a7eba22008-06-30 15:50:11 -03002035 case SENSOR_MO4000:
Jean-François Moine72b667e2010-10-02 04:35:25 -03002036 expo = brightness << 4;
Jean-François Moinea7705c02012-02-27 06:57:04 -03002037 sd->exposure = expo_adjust(gspca_dev, expo);
Jean-Francois Moine6a7eba22008-06-30 15:50:11 -03002038 break;
Jean-François Moinea067db82010-10-01 07:51:24 -03002039 case SENSOR_MI0360B:
Jean-François Moine72b667e2010-10-02 04:35:25 -03002040 expo = brightness << 2;
Jean-François Moinea7705c02012-02-27 06:57:04 -03002041 sd->exposure = expo_adjust(gspca_dev, expo);
Jean-François Moinea067db82010-10-01 07:51:24 -03002042 break;
Jean-François Moinec26b12d2010-04-02 07:08:39 -03002043 case SENSOR_GC0307:
Jean-François Moine72b667e2010-10-02 04:35:25 -03002044 expo = brightness;
Jean-François Moinea7705c02012-02-27 06:57:04 -03002045 sd->exposure = expo_adjust(gspca_dev, expo);
Jean-Francois Moined5aa3852009-11-07 06:10:08 -03002046 return; /* don't set the Y offset */
Jean-François Moine22203672011-02-10 07:49:32 -03002047 case SENSOR_MT9V111:
2048 expo = brightness << 2;
Jean-François Moinea7705c02012-02-27 06:57:04 -03002049 sd->exposure = expo_adjust(gspca_dev, expo);
Jean-François Moine22203672011-02-10 07:49:32 -03002050 return; /* don't set the Y offset */
Jean-Francois Moined2d16e92008-09-03 16:47:23 -03002051 case SENSOR_OM6802:
Jean-François Moine72b667e2010-10-02 04:35:25 -03002052 expo = brightness << 2;
Jean-François Moinea7705c02012-02-27 06:57:04 -03002053 sd->exposure = expo_adjust(gspca_dev, expo);
Jean-François Moineb813b0c2011-08-10 05:54:34 -03002054 return; /* Y offset already set */
Jean-Francois Moine6a7eba22008-06-30 15:50:11 -03002055 }
2056
Jean-Francois Moined5aa3852009-11-07 06:10:08 -03002057 reg_w1(gspca_dev, 0x96, k2); /* color matrix Y offset */
Jean-Francois Moine6a7eba22008-06-30 15:50:11 -03002058}
2059
2060static void setcontrast(struct gspca_dev *gspca_dev)
2061{
2062 struct sd *sd = (struct sd *) gspca_dev;
Jean-Francois Moine98819182009-01-19 07:37:33 -03002063 u8 k2;
2064 u8 contrast[6];
Jean-Francois Moine6a7eba22008-06-30 15:50:11 -03002065
Jean-François Moineabe8cee2011-08-10 05:13:45 -03002066 k2 = sd->ctrls[CONTRAST].val * 37 / (CONTRAST_MAX + 1)
2067 + 37; /* 37..73 */
Jean-Francois Moine91bd3412008-11-23 14:47:50 -03002068 contrast[0] = (k2 + 1) / 2; /* red */
Jean-Francois Moine577cbf42008-12-05 06:18:37 -03002069 contrast[1] = 0;
Jean-Francois Moine91bd3412008-11-23 14:47:50 -03002070 contrast[2] = k2; /* green */
Jean-Francois Moine577cbf42008-12-05 06:18:37 -03002071 contrast[3] = 0;
Jean-François Moineabe8cee2011-08-10 05:13:45 -03002072 contrast[4] = k2 / 5; /* blue */
Jean-Francois Moine577cbf42008-12-05 06:18:37 -03002073 contrast[5] = 0;
2074 reg_w(gspca_dev, 0x84, contrast, sizeof contrast);
Jean-Francois Moine6a7eba22008-06-30 15:50:11 -03002075}
2076
2077static void setcolors(struct gspca_dev *gspca_dev)
2078{
2079 struct sd *sd = (struct sd *) gspca_dev;
Jean-François Moine72b667e2010-10-02 04:35:25 -03002080 int i, v, colors;
Jean-François Moinea067db82010-10-01 07:51:24 -03002081 const s16 *uv;
Jean-Francois Moine98819182009-01-19 07:37:33 -03002082 u8 reg8a[12]; /* U & V gains */
Jean-François Moinea067db82010-10-01 07:51:24 -03002083 static const s16 uv_com[6] = { /* same as reg84 in signed decimal */
Jean-Francois Moine403123d2008-11-26 04:46:15 -03002084 -24, -38, 64, /* UR UG UB */
2085 62, -51, -9 /* VR VG VB */
2086 };
Jean-François Moinea067db82010-10-01 07:51:24 -03002087 static const s16 uv_mi0360b[6] = {
2088 -20, -38, 64, /* UR UG UB */
2089 60, -51, -9 /* VR VG VB */
2090 };
Jean-Francois Moined5aa3852009-11-07 06:10:08 -03002091
Jean-François Moine72b667e2010-10-02 04:35:25 -03002092 colors = sd->ctrls[COLORS].val;
Jean-François Moinea067db82010-10-01 07:51:24 -03002093 if (sd->sensor == SENSOR_MI0360B)
2094 uv = uv_mi0360b;
2095 else
2096 uv = uv_com;
Jean-Francois Moine403123d2008-11-26 04:46:15 -03002097 for (i = 0; i < 6; i++) {
Jean-François Moine72b667e2010-10-02 04:35:25 -03002098 v = uv[i] * colors / COLORS_DEF;
Jean-Francois Moinebd088832008-12-02 06:58:57 -03002099 reg8a[i * 2] = v;
2100 reg8a[i * 2 + 1] = (v >> 8) & 0x0f;
Jean-Francois Moined55b83d2008-09-03 16:48:01 -03002101 }
Jean-Francois Moinebd088832008-12-02 06:58:57 -03002102 reg_w(gspca_dev, 0x8a, reg8a, sizeof reg8a);
Jean-Francois Moine403123d2008-11-26 04:46:15 -03002103}
2104
2105static void setredblue(struct gspca_dev *gspca_dev)
2106{
2107 struct sd *sd = (struct sd *) gspca_dev;
2108
Jean-François Moine41f09322011-11-30 06:20:07 -03002109 if (sd->sensor == SENSOR_PO2030N) {
2110 u8 rg1b[] = /* red green1 blue (no g2) */
2111 {0xc1, 0x6e, 0x16, 0x00, 0x40, 0x00, 0x00, 0x10};
2112
2113 /* 0x40 = normal value = gain x 1 */
2114 rg1b[3] = sd->ctrls[RED].val * 2;
2115 rg1b[5] = sd->ctrls[BLUE].val * 2;
2116 i2c_w8(gspca_dev, rg1b);
2117 return;
2118 }
Jean-François Moine72b667e2010-10-02 04:35:25 -03002119 reg_w1(gspca_dev, 0x05, sd->ctrls[RED].val);
Jean-Francois Moine9c5f70f2008-09-03 16:48:04 -03002120/* reg_w1(gspca_dev, 0x07, 32); */
Jean-François Moine72b667e2010-10-02 04:35:25 -03002121 reg_w1(gspca_dev, 0x06, sd->ctrls[BLUE].val);
Jean-Francois Moine6a7eba22008-06-30 15:50:11 -03002122}
2123
Jean-Francois Moine592f4eb2009-01-15 08:01:32 -03002124static void setgamma(struct gspca_dev *gspca_dev)
2125{
2126 struct sd *sd = (struct sd *) gspca_dev;
Jean-François Moine72b667e2010-10-02 04:35:25 -03002127 int i, val;
Jean-Francois Moine592f4eb2009-01-15 08:01:32 -03002128 u8 gamma[17];
Jean-Francois Moineb083b922009-02-01 14:20:07 -03002129 const u8 *gamma_base;
Jean-Francois Moine592f4eb2009-01-15 08:01:32 -03002130 static const u8 delta[17] = {
2131 0x00, 0x14, 0x1c, 0x1c, 0x1c, 0x1c, 0x1b, 0x1a,
2132 0x18, 0x13, 0x10, 0x0e, 0x08, 0x07, 0x04, 0x02, 0x00
2133 };
2134
Jean-Francois Moineb083b922009-02-01 14:20:07 -03002135 switch (sd->sensor) {
Jean-Francois Moine64677572009-12-20 12:31:28 -03002136 case SENSOR_ADCM1700:
2137 gamma_base = gamma_spec_0;
2138 break;
Jean-Francois Moineb083b922009-02-01 14:20:07 -03002139 case SENSOR_HV7131R:
Jean-François Moinea067db82010-10-01 07:51:24 -03002140 case SENSOR_MI0360B:
Jean-Francois Moineb083b922009-02-01 14:20:07 -03002141 case SENSOR_MT9V111:
2142 gamma_base = gamma_spec_1;
2143 break;
Jean-François Moinead98c0f2010-03-18 05:15:30 -03002144 case SENSOR_GC0307:
Jean-Francois Moineb083b922009-02-01 14:20:07 -03002145 gamma_base = gamma_spec_2;
2146 break;
Jean-François Moinead98c0f2010-03-18 05:15:30 -03002147 case SENSOR_SP80708:
2148 gamma_base = gamma_spec_3;
2149 break;
Jean-Francois Moineb083b922009-02-01 14:20:07 -03002150 default:
2151 gamma_base = gamma_def;
2152 break;
2153 }
Jean-Francois Moine5e31dc82009-02-01 13:59:42 -03002154
Jean-François Moine72b667e2010-10-02 04:35:25 -03002155 val = sd->ctrls[GAMMA].val;
Jean-Francois Moine592f4eb2009-01-15 08:01:32 -03002156 for (i = 0; i < sizeof gamma; i++)
Jean-Francois Moineb083b922009-02-01 14:20:07 -03002157 gamma[i] = gamma_base[i]
Jean-François Moine72b667e2010-10-02 04:35:25 -03002158 + delta[i] * (val - GAMMA_DEF) / 32;
Jean-Francois Moine592f4eb2009-01-15 08:01:32 -03002159 reg_w(gspca_dev, 0x20, gamma, sizeof gamma);
2160}
2161
Jean-François Moinea7705c02012-02-27 06:57:04 -03002162static void setexposure(struct gspca_dev *gspca_dev)
2163{
2164 struct sd *sd = (struct sd *) gspca_dev;
2165
2166 if (sd->sensor == SENSOR_PO2030N) {
2167 u8 rexpo[] = /* 1a: expo H, 1b: expo M */
2168 {0xa1, 0x6e, 0x1a, 0x00, 0x40, 0x00, 0x00, 0x10};
2169
2170 rexpo[3] = sd->ctrls[EXPOSURE].val >> 8;
2171 i2c_w8(gspca_dev, rexpo);
2172 msleep(6);
2173 rexpo[2] = 0x1b;
2174 rexpo[3] = sd->ctrls[EXPOSURE].val;
2175 i2c_w8(gspca_dev, rexpo);
2176 }
2177}
2178
Jean-Francois Moinecebf3b62008-08-03 07:52:53 -03002179static void setautogain(struct gspca_dev *gspca_dev)
2180{
2181 struct sd *sd = (struct sd *) gspca_dev;
2182
Jean-François Moine72b667e2010-10-02 04:35:25 -03002183 if (gspca_dev->ctrl_dis & (1 << AUTOGAIN))
Jean-Francois Moinef50ba1b2008-09-03 17:12:14 -03002184 return;
Jean-Francois Moine2797ba22009-02-05 15:12:24 -03002185 switch (sd->sensor) {
2186 case SENSOR_OV7630:
2187 case SENSOR_OV7648: {
2188 u8 comb;
2189
2190 if (sd->sensor == SENSOR_OV7630)
2191 comb = 0xc0;
2192 else
2193 comb = 0xa0;
Jean-François Moine72b667e2010-10-02 04:35:25 -03002194 if (sd->ctrls[AUTOGAIN].val)
Hans de Goede1fec7472009-06-18 06:05:07 -03002195 comb |= 0x03;
Jean-Francois Moine2797ba22009-02-05 15:12:24 -03002196 i2c_w1(&sd->gspca_dev, 0x13, comb);
2197 return;
2198 }
2199 }
Jean-François Moine72b667e2010-10-02 04:35:25 -03002200 if (sd->ctrls[AUTOGAIN].val)
Jean-Francois Moinef50ba1b2008-09-03 17:12:14 -03002201 sd->ag_cnt = AG_CNT_START;
2202 else
2203 sd->ag_cnt = -1;
Jean-Francois Moinecebf3b62008-08-03 07:52:53 -03002204}
2205
Jean-François Moinea7705c02012-02-27 06:57:04 -03002206static void setgain(struct gspca_dev *gspca_dev)
2207{
2208 struct sd *sd = (struct sd *) gspca_dev;
2209
2210 if (sd->sensor == SENSOR_PO2030N) {
2211 u8 rgain[] = /* 15: gain */
2212 {0xa1, 0x6e, 0x15, 0x00, 0x40, 0x00, 0x00, 0x15};
2213
2214 rgain[3] = sd->ctrls[GAIN].val;
2215 i2c_w8(gspca_dev, rgain);
2216 }
2217}
2218
Németh Márton76ad3b62010-10-19 03:33:47 -03002219static void sethvflip(struct gspca_dev *gspca_dev)
Jean-Francois Moine6c862742008-09-08 04:57:26 -03002220{
Jean-François Moine72b667e2010-10-02 04:35:25 -03002221 struct sd *sd = (struct sd *) gspca_dev;
Jean-Francois Moine2797ba22009-02-05 15:12:24 -03002222 u8 comn;
2223
Jean-François Moinef6b22e52010-02-18 04:12:06 -03002224 switch (sd->sensor) {
2225 case SENSOR_HV7131R:
2226 comn = 0x18; /* clkdiv = 1, ablcen = 1 */
Jean-François Moine72b667e2010-10-02 04:35:25 -03002227 if (sd->ctrls[VFLIP].val)
Jean-François Moinef6b22e52010-02-18 04:12:06 -03002228 comn |= 0x01;
Jean-François Moine72b667e2010-10-02 04:35:25 -03002229 i2c_w1(gspca_dev, 0x01, comn); /* sctra */
Jean-François Moinef6b22e52010-02-18 04:12:06 -03002230 break;
2231 case SENSOR_OV7630:
Jean-Francois Moine2797ba22009-02-05 15:12:24 -03002232 comn = 0x02;
Jean-François Moine72b667e2010-10-02 04:35:25 -03002233 if (!sd->ctrls[VFLIP].val)
Hans de Goedef8009522009-06-18 14:29:20 -03002234 comn |= 0x80;
Jean-François Moine72b667e2010-10-02 04:35:25 -03002235 i2c_w1(gspca_dev, 0x75, comn);
Jean-François Moinef6b22e52010-02-18 04:12:06 -03002236 break;
Németh Márton76ad3b62010-10-19 03:33:47 -03002237 case SENSOR_OV7648:
Jean-Francois Moine2797ba22009-02-05 15:12:24 -03002238 comn = 0x06;
Jean-François Moine72b667e2010-10-02 04:35:25 -03002239 if (sd->ctrls[VFLIP].val)
Hans de Goedef8009522009-06-18 14:29:20 -03002240 comn |= 0x80;
Jean-François Moine72b667e2010-10-02 04:35:25 -03002241 i2c_w1(gspca_dev, 0x75, comn);
Jean-François Moinef6b22e52010-02-18 04:12:06 -03002242 break;
Németh Márton76ad3b62010-10-19 03:33:47 -03002243 case SENSOR_PO2030N:
2244 /* Reg. 0x1E: Timing Generator Control Register 2 (Tgcontrol2)
2245 * (reset value: 0x0A)
2246 * bit7: HM: Horizontal Mirror: 0: disable, 1: enable
2247 * bit6: VM: Vertical Mirror: 0: disable, 1: enable
2248 * bit5: ST: Shutter Selection: 0: electrical, 1: mechanical
2249 * bit4: FT: Single Frame Transfer: 0: disable, 1: enable
2250 * bit3-0: X
2251 */
2252 comn = 0x0a;
2253 if (sd->ctrls[HFLIP].val)
2254 comn |= 0x80;
2255 if (sd->ctrls[VFLIP].val)
2256 comn |= 0x40;
2257 i2c_w1(&sd->gspca_dev, 0x1e, comn);
2258 break;
Hans de Goedef8009522009-06-18 14:29:20 -03002259 }
Jean-Francois Moine6c862742008-09-08 04:57:26 -03002260}
2261
Jean-François Moine72b667e2010-10-02 04:35:25 -03002262static void setsharpness(struct gspca_dev *gspca_dev)
Jean-Francois Moine878b35a2009-12-30 04:53:07 -03002263{
Jean-François Moine72b667e2010-10-02 04:35:25 -03002264 struct sd *sd = (struct sd *) gspca_dev;
2265
2266 reg_w1(gspca_dev, 0x99, sd->ctrls[SHARPNESS].val);
Jean-Francois Moine878b35a2009-12-30 04:53:07 -03002267}
2268
Jean-François Moine3afef852011-01-13 06:39:11 -03002269static void setillum(struct gspca_dev *gspca_dev)
Jean-Francois Moine0cae8962008-10-17 07:48:24 -03002270{
Jean-François Moine72b667e2010-10-02 04:35:25 -03002271 struct sd *sd = (struct sd *) gspca_dev;
2272
Jean-François Moine3afef852011-01-13 06:39:11 -03002273 if (gspca_dev->ctrl_dis & (1 << ILLUM))
Jean-Francois Moine47f7f6f2009-08-25 06:14:54 -03002274 return;
Jean-François Moinea63d6012011-01-13 07:56:00 -03002275 switch (sd->sensor) {
2276 case SENSOR_ADCM1700:
2277 reg_w1(gspca_dev, 0x02, /* gpio */
2278 sd->ctrls[ILLUM].val ? 0x64 : 0x60);
2279 break;
2280 case SENSOR_MT9V111:
Jean-François Moine5c956062011-02-10 08:03:24 -03002281 reg_w1(gspca_dev, 0x02,
2282 sd->ctrls[ILLUM].val ? 0x77 : 0x74);
2283/* should have been: */
2284/* 0x55 : 0x54); * 370i */
2285/* 0x66 : 0x64); * Clip */
Jean-François Moinea63d6012011-01-13 07:56:00 -03002286 break;
2287 }
Jean-Francois Moine0cae8962008-10-17 07:48:24 -03002288}
2289
Hans de Goede37c6dbe2009-06-18 07:35:36 -03002290static void setfreq(struct gspca_dev *gspca_dev)
2291{
2292 struct sd *sd = (struct sd *) gspca_dev;
2293
Jean-François Moine72b667e2010-10-02 04:35:25 -03002294 if (gspca_dev->ctrl_dis & (1 << FREQ))
Jean-Francois Moine27954932009-07-08 05:21:50 -03002295 return;
Hans de Goede37c6dbe2009-06-18 07:35:36 -03002296 if (sd->sensor == SENSOR_OV7660) {
Jean-Francois Moined8f400e2009-07-08 06:33:44 -03002297 u8 com8;
2298
Jean-Francois Moine47f7f6f2009-08-25 06:14:54 -03002299 com8 = 0xdf; /* auto gain/wb/expo */
Jean-François Moine72b667e2010-10-02 04:35:25 -03002300 switch (sd->ctrls[FREQ].val) {
Hans de Goede37c6dbe2009-06-18 07:35:36 -03002301 case 0: /* Banding filter disabled */
Jean-Francois Moine47f7f6f2009-08-25 06:14:54 -03002302 i2c_w1(gspca_dev, 0x13, com8 | 0x20);
Hans de Goede37c6dbe2009-06-18 07:35:36 -03002303 break;
2304 case 1: /* 50 hz */
Jean-Francois Moined8f400e2009-07-08 06:33:44 -03002305 i2c_w1(gspca_dev, 0x13, com8);
Hans de Goede37c6dbe2009-06-18 07:35:36 -03002306 i2c_w1(gspca_dev, 0x3b, 0x0a);
2307 break;
2308 case 2: /* 60 hz */
Jean-Francois Moined8f400e2009-07-08 06:33:44 -03002309 i2c_w1(gspca_dev, 0x13, com8);
Hans de Goede37c6dbe2009-06-18 07:35:36 -03002310 i2c_w1(gspca_dev, 0x3b, 0x02);
2311 break;
2312 }
2313 } else {
2314 u8 reg2a = 0, reg2b = 0, reg2d = 0;
2315
2316 /* Get reg2a / reg2d base values */
2317 switch (sd->sensor) {
2318 case SENSOR_OV7630:
2319 reg2a = 0x08;
2320 reg2d = 0x01;
2321 break;
2322 case SENSOR_OV7648:
2323 reg2a = 0x11;
2324 reg2d = 0x81;
2325 break;
2326 }
2327
Jean-François Moine72b667e2010-10-02 04:35:25 -03002328 switch (sd->ctrls[FREQ].val) {
Hans de Goede37c6dbe2009-06-18 07:35:36 -03002329 case 0: /* Banding filter disabled */
2330 break;
2331 case 1: /* 50 hz (filter on and framerate adj) */
2332 reg2a |= 0x80;
2333 reg2b = 0xac;
2334 reg2d |= 0x04;
2335 break;
2336 case 2: /* 60 hz (filter on, no framerate adj) */
2337 reg2a |= 0x80;
2338 reg2d |= 0x04;
2339 break;
2340 }
2341 i2c_w1(gspca_dev, 0x2a, reg2a);
2342 i2c_w1(gspca_dev, 0x2b, reg2b);
2343 i2c_w1(gspca_dev, 0x2d, reg2d);
2344 }
2345}
2346
Jean-Francois Moine71cb2762009-03-03 05:33:41 -03002347static void setjpegqual(struct gspca_dev *gspca_dev)
2348{
2349 struct sd *sd = (struct sd *) gspca_dev;
Jean-Francois Moine71cb2762009-03-03 05:33:41 -03002350
Jean-François Moinedccdccc2011-02-10 07:30:03 -03002351 jpeg_set_qual(sd->jpeg_hdr, sd->quality);
Jean-Francois Moine71cb2762009-03-03 05:33:41 -03002352#if USB_BUF_SZ < 64
2353#error "No room enough in usb_buf for quantization table"
2354#endif
Jean-François Moinedccdccc2011-02-10 07:30:03 -03002355 memcpy(gspca_dev->usb_buf, &sd->jpeg_hdr[JPEG_QT0_OFFSET], 64);
Jean-Francois Moine71cb2762009-03-03 05:33:41 -03002356 usb_control_msg(gspca_dev->dev,
2357 usb_sndctrlpipe(gspca_dev->dev, 0),
2358 0x08,
2359 USB_DIR_OUT | USB_TYPE_VENDOR | USB_RECIP_INTERFACE,
2360 0x0100, 0,
2361 gspca_dev->usb_buf, 64,
2362 500);
Jean-François Moinedccdccc2011-02-10 07:30:03 -03002363 memcpy(gspca_dev->usb_buf, &sd->jpeg_hdr[JPEG_QT1_OFFSET], 64);
Jean-Francois Moine71cb2762009-03-03 05:33:41 -03002364 usb_control_msg(gspca_dev->dev,
2365 usb_sndctrlpipe(gspca_dev->dev, 0),
2366 0x08,
2367 USB_DIR_OUT | USB_TYPE_VENDOR | USB_RECIP_INTERFACE,
2368 0x0140, 0,
2369 gspca_dev->usb_buf, 64,
2370 500);
2371
2372 sd->reg18 ^= 0x40;
2373 reg_w1(gspca_dev, 0x18, sd->reg18);
2374}
2375
Jean-François Moineb96cfc32011-02-10 07:38:58 -03002376/* JPEG quality update */
2377/* This function is executed from a work queue. */
2378static void qual_upd(struct work_struct *work)
2379{
2380 struct sd *sd = container_of(work, struct sd, work);
2381 struct gspca_dev *gspca_dev = &sd->gspca_dev;
2382
2383 mutex_lock(&gspca_dev->usb_lock);
2384 PDEBUG(D_STREAM, "qual_upd %d%%", sd->quality);
2385 setjpegqual(gspca_dev);
2386 mutex_unlock(&gspca_dev->usb_lock);
2387}
2388
Jean-Francois Moine6a7eba22008-06-30 15:50:11 -03002389/* -- start the camera -- */
Jean-Francois Moine72ab97c2008-09-20 06:39:08 -03002390static int sd_start(struct gspca_dev *gspca_dev)
Jean-Francois Moine6a7eba22008-06-30 15:50:11 -03002391{
2392 struct sd *sd = (struct sd *) gspca_dev;
Jean-Francois Moine6a7eba22008-06-30 15:50:11 -03002393 int i;
Jean-Francois Moine0e4d4132010-12-14 16:17:40 -03002394 u8 reg01, reg17;
Jean-Francois Moine5e68f402010-12-14 16:14:10 -03002395 u8 reg0102[2];
Jean-Francois Moine98819182009-01-19 07:37:33 -03002396 const u8 *sn9c1xx;
Jean-Francois Moine3fccb772009-11-02 09:54:04 -03002397 const u8 (*init)[8];
Jean-Francois Moine4f67f3a2010-12-14 16:15:00 -03002398 const u8 *reg9a;
Jean-Francois Moine6a7eba22008-06-30 15:50:11 -03002399 int mode;
Jean-Francois Moine5e68f402010-12-14 16:14:10 -03002400 static const u8 reg9a_def[] =
2401 {0x00, 0x40, 0x20, 0x00, 0x00, 0x00};
2402 static const u8 reg9a_spec[] =
2403 {0x00, 0x40, 0x38, 0x30, 0x00, 0x20};
2404 static const u8 regd4[] = {0x60, 0x00, 0x00};
Jean-Francois Moine98819182009-01-19 07:37:33 -03002405 static const u8 C0[] = { 0x2d, 0x2d, 0x3a, 0x05, 0x04, 0x3f };
2406 static const u8 CA[] = { 0x28, 0xd8, 0x14, 0xec };
Jean-Francois Moine64677572009-12-20 12:31:28 -03002407 static const u8 CA_adcm1700[] =
2408 { 0x14, 0xec, 0x0a, 0xf6 };
Jean-François Moinead98c0f2010-03-18 05:15:30 -03002409 static const u8 CA_po2030n[] =
2410 { 0x1e, 0xe2, 0x14, 0xec };
Jean-Francois Moine98819182009-01-19 07:37:33 -03002411 static const u8 CE[] = { 0x32, 0xdd, 0x2d, 0xdd }; /* MI0360 */
Jean-François Moinead98c0f2010-03-18 05:15:30 -03002412 static const u8 CE_gc0307[] =
2413 { 0x32, 0xce, 0x2d, 0xd3 };
Jean-Francois Moine98819182009-01-19 07:37:33 -03002414 static const u8 CE_ov76xx[] =
Jean-Francois Moine674cbc62008-10-02 08:06:59 -03002415 { 0x32, 0xdd, 0x32, 0xdd };
Jean-François Moinead98c0f2010-03-18 05:15:30 -03002416 static const u8 CE_po2030n[] =
2417 { 0x14, 0xe7, 0x1e, 0xdd };
Jean-Francois Moine6a7eba22008-06-30 15:50:11 -03002418
Jean-Francois Moine71cb2762009-03-03 05:33:41 -03002419 /* create the JPEG header */
Jean-Francois Moine71cb2762009-03-03 05:33:41 -03002420 jpeg_define(sd->jpeg_hdr, gspca_dev->height, gspca_dev->width,
2421 0x21); /* JPEG 422 */
Jean-Francois Moine71cb2762009-03-03 05:33:41 -03002422
Jean-Francois Moine3fccb772009-11-02 09:54:04 -03002423 /* initialize the bridge */
2424 sn9c1xx = sn_tb[sd->sensor];
Jean-Francois Moine5e68f402010-12-14 16:14:10 -03002425
2426 /* sensor clock already enabled in sd_init */
2427 /* reg_w1(gspca_dev, 0xf1, 0x00); */
Jean-Francois Moine0e4d4132010-12-14 16:17:40 -03002428 reg01 = sn9c1xx[1];
Jean-François Moine3afef852011-01-13 06:39:11 -03002429 if (sd->flags & F_PDN_INV)
Jean-Francois Moine0e4d4132010-12-14 16:17:40 -03002430 reg01 ^= S_PDN_INV; /* power down inverted */
2431 reg_w1(gspca_dev, 0x01, reg01);
Jean-Francois Moine5e68f402010-12-14 16:14:10 -03002432
2433 /* configure gpio */
Jean-Francois Moine0e4d4132010-12-14 16:17:40 -03002434 reg0102[0] = reg01;
Jean-Francois Moine5e68f402010-12-14 16:14:10 -03002435 reg0102[1] = sn9c1xx[2];
2436 if (gspca_dev->audio)
2437 reg0102[1] |= 0x04; /* keep the audio connection */
2438 reg_w(gspca_dev, 0x01, reg0102, 2);
2439 reg_w(gspca_dev, 0x08, &sn9c1xx[8], 2);
2440 reg_w(gspca_dev, 0x17, &sn9c1xx[0x17], 5);
2441 switch (sd->sensor) {
2442 case SENSOR_GC0307:
2443 case SENSOR_OV7660:
2444 case SENSOR_PO1030:
2445 case SENSOR_PO2030N:
2446 case SENSOR_SOI768:
2447 case SENSOR_SP80708:
2448 reg9a = reg9a_spec;
2449 break;
2450 default:
2451 reg9a = reg9a_def;
2452 break;
2453 }
2454 reg_w(gspca_dev, 0x9a, reg9a, 6);
2455
2456 reg_w(gspca_dev, 0xd4, regd4, sizeof regd4);
2457
2458 reg_w(gspca_dev, 0x03, &sn9c1xx[3], 0x0f);
2459
Jean-Francois Moine0e4d4132010-12-14 16:17:40 -03002460 reg17 = sn9c1xx[0x17];
Jean-Francois Moine5e68f402010-12-14 16:14:10 -03002461 switch (sd->sensor) {
Jean-Francois Moine5e68f402010-12-14 16:14:10 -03002462 case SENSOR_GC0307:
Jean-Francois Moine0e4d4132010-12-14 16:17:40 -03002463 msleep(50); /*fixme: is it useful? */
Jean-Francois Moine5e68f402010-12-14 16:14:10 -03002464 break;
2465 case SENSOR_OM6802:
2466 msleep(10);
2467 reg_w1(gspca_dev, 0x02, 0x73);
Jean-Francois Moine0e4d4132010-12-14 16:17:40 -03002468 reg17 |= SEN_CLK_EN;
2469 reg_w1(gspca_dev, 0x17, reg17);
Jean-Francois Moine5e68f402010-12-14 16:14:10 -03002470 reg_w1(gspca_dev, 0x01, 0x22);
2471 msleep(100);
Jean-Francois Moine0e4d4132010-12-14 16:17:40 -03002472 reg01 = SCL_SEL_OD | S_PDN_INV;
Luiz Ramosd1520c52011-07-14 23:08:39 -03002473 reg17 &= ~MCK_SIZE_MASK;
Jean-Francois Moine0e4d4132010-12-14 16:17:40 -03002474 reg17 |= 0x04; /* clock / 4 */
2475 break;
2476 }
2477 reg01 |= SYS_SEL_48M;
2478 reg_w1(gspca_dev, 0x01, reg01);
2479 reg17 |= SEN_CLK_EN;
2480 reg_w1(gspca_dev, 0x17, reg17);
2481 reg01 &= ~S_PWR_DN; /* sensor power on */
2482 reg_w1(gspca_dev, 0x01, reg01);
Jean-François Moineb4b01072011-11-30 05:58:20 -03002483 reg01 &= ~SCL_SEL_OD; /* remove open-drain mode */
Jean-Francois Moine0e4d4132010-12-14 16:17:40 -03002484 reg_w1(gspca_dev, 0x01, reg01);
2485
2486 switch (sd->sensor) {
2487 case SENSOR_HV7131R:
2488 hv7131r_probe(gspca_dev); /*fixme: is it useful? */
2489 break;
2490 case SENSOR_OM6802:
Jean-Francois Moine5e68f402010-12-14 16:14:10 -03002491 msleep(10);
Jean-Francois Moine0e4d4132010-12-14 16:17:40 -03002492 reg_w1(gspca_dev, 0x01, reg01);
Jean-Francois Moine5e68f402010-12-14 16:14:10 -03002493 i2c_w8(gspca_dev, om6802_init0[0]);
2494 i2c_w8(gspca_dev, om6802_init0[1]);
2495 msleep(15);
2496 reg_w1(gspca_dev, 0x02, 0x71);
2497 msleep(150);
2498 break;
Jean-Francois Moine5e68f402010-12-14 16:14:10 -03002499 case SENSOR_SP80708:
Jean-Francois Moine5e68f402010-12-14 16:14:10 -03002500 msleep(100);
2501 reg_w1(gspca_dev, 0x02, 0x62);
2502 break;
Jean-Francois Moine5e68f402010-12-14 16:14:10 -03002503 }
Jean-Francois Moined5aa3852009-11-07 06:10:08 -03002504
Jean-Francois Moine3fccb772009-11-02 09:54:04 -03002505 /* initialize the sensor */
2506 i2c_w_seq(gspca_dev, sensor_init[sd->sensor]);
2507
Jean-Francois Moine60017612008-07-18 08:46:19 -03002508 reg_w1(gspca_dev, 0x15, sn9c1xx[0x15]);
2509 reg_w1(gspca_dev, 0x16, sn9c1xx[0x16]);
2510 reg_w1(gspca_dev, 0x12, sn9c1xx[0x12]);
2511 reg_w1(gspca_dev, 0x13, sn9c1xx[0x13]);
2512 reg_w1(gspca_dev, 0x18, sn9c1xx[0x18]);
Jean-Francois Moine64677572009-12-20 12:31:28 -03002513 if (sd->sensor == SENSOR_ADCM1700) {
Jean-Francois Moine878b35a2009-12-30 04:53:07 -03002514 reg_w1(gspca_dev, 0xd2, 0x3a); /* AE_H_SIZE = 116 */
2515 reg_w1(gspca_dev, 0xd3, 0x30); /* AE_V_SIZE = 96 */
Jean-Francois Moine64677572009-12-20 12:31:28 -03002516 } else {
Jean-Francois Moine878b35a2009-12-30 04:53:07 -03002517 reg_w1(gspca_dev, 0xd2, 0x6a); /* AE_H_SIZE = 212 */
2518 reg_w1(gspca_dev, 0xd3, 0x50); /* AE_V_SIZE = 160 */
Jean-Francois Moine64677572009-12-20 12:31:28 -03002519 }
Jean-Francois Moine60017612008-07-18 08:46:19 -03002520 reg_w1(gspca_dev, 0xc6, 0x00);
2521 reg_w1(gspca_dev, 0xc7, 0x00);
Jean-Francois Moine64677572009-12-20 12:31:28 -03002522 if (sd->sensor == SENSOR_ADCM1700) {
Jean-Francois Moine878b35a2009-12-30 04:53:07 -03002523 reg_w1(gspca_dev, 0xc8, 0x2c); /* AW_H_STOP = 352 */
2524 reg_w1(gspca_dev, 0xc9, 0x24); /* AW_V_STOP = 288 */
Jean-Francois Moine64677572009-12-20 12:31:28 -03002525 } else {
Jean-Francois Moine878b35a2009-12-30 04:53:07 -03002526 reg_w1(gspca_dev, 0xc8, 0x50); /* AW_H_STOP = 640 */
2527 reg_w1(gspca_dev, 0xc9, 0x3c); /* AW_V_STOP = 480 */
Jean-Francois Moine64677572009-12-20 12:31:28 -03002528 }
Jean-Francois Moine60017612008-07-18 08:46:19 -03002529 reg_w1(gspca_dev, 0x18, sn9c1xx[0x18]);
Jean-Francois Moine6ab0b172008-09-03 16:47:34 -03002530 switch (sd->sensor) {
Jean-Francois Moine0e4d4132010-12-14 16:17:40 -03002531 case SENSOR_OM6802:
2532/* case SENSOR_OV7648: * fixme: sometimes */
Jean-Francois Moineb8c8a5b2009-11-23 06:46:35 -03002533 break;
Jean-Francois Moine568788a2008-07-15 11:46:06 -03002534 default:
Jean-Francois Moine0e4d4132010-12-14 16:17:40 -03002535 reg17 |= DEF_EN;
Jean-Francois Moine568788a2008-07-15 11:46:06 -03002536 break;
2537 }
Jean-Francois Moine8f47a3c2008-07-29 14:14:04 -03002538 reg_w1(gspca_dev, 0x17, reg17);
Jean-Francois Moine878b35a2009-12-30 04:53:07 -03002539
2540 reg_w1(gspca_dev, 0x05, 0x00); /* red */
2541 reg_w1(gspca_dev, 0x07, 0x00); /* green */
2542 reg_w1(gspca_dev, 0x06, 0x00); /* blue */
Jean-Francois Moine60017612008-07-18 08:46:19 -03002543 reg_w1(gspca_dev, 0x14, sn9c1xx[0x14]);
Jean-Francois Moineb083b922009-02-01 14:20:07 -03002544
Jean-Francois Moine5e31dc82009-02-01 13:59:42 -03002545 setgamma(gspca_dev);
2546
Jean-Francois Moine878b35a2009-12-30 04:53:07 -03002547/*fixme: 8 times with all zeroes and 1 or 2 times with normal values */
Jean-Francois Moine05b809c2008-09-03 16:47:59 -03002548 for (i = 0; i < 8; i++)
2549 reg_w(gspca_dev, 0x84, reg84, sizeof reg84);
Jean-Francois Moine674cbc62008-10-02 08:06:59 -03002550 switch (sd->sensor) {
Jean-Francois Moine64677572009-12-20 12:31:28 -03002551 case SENSOR_ADCM1700:
Jean-Francois Moinec8b9b2ca2009-04-26 14:46:12 -03002552 case SENSOR_OV7660:
Jean-Francois Moine5e31dc82009-02-01 13:59:42 -03002553 case SENSOR_SP80708:
2554 reg_w1(gspca_dev, 0x9a, 0x05);
Jean-Francois Moine878b35a2009-12-30 04:53:07 -03002555 break;
Jean-François Moinead98c0f2010-03-18 05:15:30 -03002556 case SENSOR_GC0307:
Jean-Francois Moine878b35a2009-12-30 04:53:07 -03002557 case SENSOR_MT9V111:
Jean-François Moinea067db82010-10-01 07:51:24 -03002558 case SENSOR_MI0360B:
Jean-Francois Moine878b35a2009-12-30 04:53:07 -03002559 reg_w1(gspca_dev, 0x9a, 0x07);
2560 break;
Jean-François Moine0a85c742010-04-25 14:33:31 -03002561 case SENSOR_OV7630:
Jean-Francois Moine878b35a2009-12-30 04:53:07 -03002562 case SENSOR_OV7648:
2563 reg_w1(gspca_dev, 0x9a, 0x0a);
Jean-Francois Moine5e31dc82009-02-01 13:59:42 -03002564 break;
Jean-François Moinead98c0f2010-03-18 05:15:30 -03002565 case SENSOR_PO2030N:
Jean-François Moine03ed2a12010-04-25 14:45:43 -03002566 case SENSOR_SOI768:
Jean-François Moinead98c0f2010-03-18 05:15:30 -03002567 reg_w1(gspca_dev, 0x9a, 0x06);
2568 break;
Jean-Francois Moine674cbc62008-10-02 08:06:59 -03002569 default:
Jean-Francois Moine60017612008-07-18 08:46:19 -03002570 reg_w1(gspca_dev, 0x9a, 0x08);
Jean-Francois Moine674cbc62008-10-02 08:06:59 -03002571 break;
2572 }
Jean-François Moine72b667e2010-10-02 04:35:25 -03002573 setsharpness(gspca_dev);
Jean-Francois Moine6a7eba22008-06-30 15:50:11 -03002574
Jean-Francois Moine3fccb772009-11-02 09:54:04 -03002575 reg_w(gspca_dev, 0x84, reg84, sizeof reg84);
Jean-Francois Moine878b35a2009-12-30 04:53:07 -03002576 reg_w1(gspca_dev, 0x05, 0x20); /* red */
2577 reg_w1(gspca_dev, 0x07, 0x20); /* green */
2578 reg_w1(gspca_dev, 0x06, 0x20); /* blue */
Jean-Francois Moine23a98272009-11-02 09:10:25 -03002579
Jean-Francois Moine3fccb772009-11-02 09:54:04 -03002580 init = NULL;
Jean-Francois Moined5aa3852009-11-07 06:10:08 -03002581 mode = gspca_dev->cam.cam_mode[gspca_dev->curr_mode].priv;
Jean-Francois Moine0e4d4132010-12-14 16:17:40 -03002582 reg01 |= SYS_SEL_48M | V_TX_EN;
2583 reg17 &= ~MCK_SIZE_MASK;
2584 reg17 |= 0x02; /* clock / 2 */
Jean-Francois Moine6a7eba22008-06-30 15:50:11 -03002585 switch (sd->sensor) {
Jean-Francois Moine64677572009-12-20 12:31:28 -03002586 case SENSOR_ADCM1700:
2587 init = adcm1700_sensor_param1;
Jean-Francois Moine64677572009-12-20 12:31:28 -03002588 break;
Jean-François Moinead98c0f2010-03-18 05:15:30 -03002589 case SENSOR_GC0307:
2590 init = gc0307_sensor_param1;
Jean-Francois Moine0e4d4132010-12-14 16:17:40 -03002591 break;
2592 case SENSOR_HV7131R:
2593 case SENSOR_MI0360:
Jean-François Moineb813b0c2011-08-10 05:54:34 -03002594 if (!mode)
Jean-Francois Moine0e4d4132010-12-14 16:17:40 -03002595 reg01 &= ~SYS_SEL_48M; /* 640x480: clk 24Mhz */
2596 reg17 &= ~MCK_SIZE_MASK;
2597 reg17 |= 0x01; /* clock / 1 */
Jean-François Moinead98c0f2010-03-18 05:15:30 -03002598 break;
Jean-François Moinea067db82010-10-01 07:51:24 -03002599 case SENSOR_MI0360B:
2600 init = mi0360b_sensor_param1;
Jean-François Moinea067db82010-10-01 07:51:24 -03002601 break;
Jean-Francois Moine6a7eba22008-06-30 15:50:11 -03002602 case SENSOR_MO4000:
Jean-Francois Moine0e4d4132010-12-14 16:17:40 -03002603 if (mode) { /* if 320x240 */
2604 reg01 &= ~SYS_SEL_48M; /* clk 24Mz */
2605 reg17 &= ~MCK_SIZE_MASK;
2606 reg17 |= 0x01; /* clock / 1 */
Jean-Francois Moine6a7eba22008-06-30 15:50:11 -03002607 }
2608 break;
Jean-Francois Moine3ef2c5b2009-01-29 04:59:45 -03002609 case SENSOR_MT9V111:
Jean-Francois Moine3fccb772009-11-02 09:54:04 -03002610 init = mt9v111_sensor_param1;
Jean-Francois Moine0fbe0572009-01-30 12:14:02 -03002611 break;
Jean-Francois Moined2d16e92008-09-03 16:47:23 -03002612 case SENSOR_OM6802:
Jean-Francois Moine3fccb772009-11-02 09:54:04 -03002613 init = om6802_sensor_param1;
Jean-Francois Moine0e4d4132010-12-14 16:17:40 -03002614 if (!mode) { /* if 640x480 */
2615 reg17 &= ~MCK_SIZE_MASK;
Jean-François Moineaa777a82010-12-28 07:39:13 -03002616 reg17 |= 0x04; /* clock / 4 */
Jean-François Moine822f6e22011-08-09 15:13:50 -03002617 } else {
2618 reg01 &= ~SYS_SEL_48M; /* clk 24Mz */
2619 reg17 &= ~MCK_SIZE_MASK;
2620 reg17 |= 0x02; /* clock / 2 */
Jean-Francois Moine0e4d4132010-12-14 16:17:40 -03002621 }
Jean-Francois Moined2d16e92008-09-03 16:47:23 -03002622 break;
Jean-Francois Moine6ab0b172008-09-03 16:47:34 -03002623 case SENSOR_OV7630:
Jean-François Moinebdd2b932010-04-25 14:23:39 -03002624 init = ov7630_sensor_param1;
Jean-Francois Moine6ab0b172008-09-03 16:47:34 -03002625 break;
Jean-Francois Moine6a7eba22008-06-30 15:50:11 -03002626 case SENSOR_OV7648:
Jean-Francois Moine3fccb772009-11-02 09:54:04 -03002627 init = ov7648_sensor_param1;
Jean-Francois Moine0e4d4132010-12-14 16:17:40 -03002628 reg17 &= ~MCK_SIZE_MASK;
2629 reg17 |= 0x01; /* clock / 1 */
Jean-Francois Moine6a7eba22008-06-30 15:50:11 -03002630 break;
Jean-Francois Moine5e31dc82009-02-01 13:59:42 -03002631 case SENSOR_OV7660:
Jean-Francois Moine3fccb772009-11-02 09:54:04 -03002632 init = ov7660_sensor_param1;
Jean-Francois Moine6a7eba22008-06-30 15:50:11 -03002633 break;
Jean-Francois Moineb8c8a5b2009-11-23 06:46:35 -03002634 case SENSOR_PO1030:
2635 init = po1030_sensor_param1;
Jean-Francois Moineb8c8a5b2009-11-23 06:46:35 -03002636 break;
Jean-François Moinead98c0f2010-03-18 05:15:30 -03002637 case SENSOR_PO2030N:
2638 init = po2030n_sensor_param1;
Jean-François Moinead98c0f2010-03-18 05:15:30 -03002639 break;
Jean-François Moine03ed2a12010-04-25 14:45:43 -03002640 case SENSOR_SOI768:
2641 init = soi768_sensor_param1;
Jean-François Moine03ed2a12010-04-25 14:45:43 -03002642 break;
Jean-François Moine0303a902010-10-21 04:05:15 -03002643 case SENSOR_SP80708:
Jean-Francois Moine3fccb772009-11-02 09:54:04 -03002644 init = sp80708_sensor_param1;
Jean-Francois Moine5e31dc82009-02-01 13:59:42 -03002645 break;
Jean-Francois Moine6a7eba22008-06-30 15:50:11 -03002646 }
Jean-Francois Moine3fccb772009-11-02 09:54:04 -03002647
2648 /* more sensor initialization - param1 */
2649 if (init != NULL) {
2650 i2c_w_seq(gspca_dev, init);
2651/* init = NULL; */
2652 }
2653
Jean-Francois Moine739570b2008-07-14 09:38:29 -03002654 reg_w(gspca_dev, 0xc0, C0, 6);
Jean-François Moinead98c0f2010-03-18 05:15:30 -03002655 switch (sd->sensor) {
2656 case SENSOR_ADCM1700:
2657 case SENSOR_GC0307:
Jean-François Moine03ed2a12010-04-25 14:45:43 -03002658 case SENSOR_SOI768:
Jean-Francois Moine64677572009-12-20 12:31:28 -03002659 reg_w(gspca_dev, 0xca, CA_adcm1700, 4);
Jean-François Moinead98c0f2010-03-18 05:15:30 -03002660 break;
2661 case SENSOR_PO2030N:
2662 reg_w(gspca_dev, 0xca, CA_po2030n, 4);
2663 break;
2664 default:
Jean-Francois Moine64677572009-12-20 12:31:28 -03002665 reg_w(gspca_dev, 0xca, CA, 4);
Jean-François Moinead98c0f2010-03-18 05:15:30 -03002666 break;
2667 }
Jean-Francois Moine6ab0b172008-09-03 16:47:34 -03002668 switch (sd->sensor) {
Jean-Francois Moine64677572009-12-20 12:31:28 -03002669 case SENSOR_ADCM1700:
Jean-Francois Moine6ab0b172008-09-03 16:47:34 -03002670 case SENSOR_OV7630:
2671 case SENSOR_OV7648:
Jean-Francois Moine674cbc62008-10-02 08:06:59 -03002672 case SENSOR_OV7660:
Jean-François Moine03ed2a12010-04-25 14:45:43 -03002673 case SENSOR_SOI768:
Jean-Francois Moine6ab0b172008-09-03 16:47:34 -03002674 reg_w(gspca_dev, 0xce, CE_ov76xx, 4);
Jean-Francois Moine6a7eba22008-06-30 15:50:11 -03002675 break;
Jean-François Moinead98c0f2010-03-18 05:15:30 -03002676 case SENSOR_GC0307:
2677 reg_w(gspca_dev, 0xce, CE_gc0307, 4);
2678 break;
2679 case SENSOR_PO2030N:
2680 reg_w(gspca_dev, 0xce, CE_po2030n, 4);
2681 break;
Jean-Francois Moine6a7eba22008-06-30 15:50:11 -03002682 default:
Jean-Francois Moine739570b2008-07-14 09:38:29 -03002683 reg_w(gspca_dev, 0xce, CE, 4);
Jean-Francois Moine6a7eba22008-06-30 15:50:11 -03002684 /* ?? {0x1e, 0xdd, 0x2d, 0xe7} */
2685 break;
2686 }
2687
2688 /* here change size mode 0 -> VGA; 1 -> CIF */
Jean-Francois Moine71cb2762009-03-03 05:33:41 -03002689 sd->reg18 = sn9c1xx[0x18] | (mode << 4) | 0x40;
2690 reg_w1(gspca_dev, 0x18, sd->reg18);
2691 setjpegqual(gspca_dev);
Jean-Francois Moine6a7eba22008-06-30 15:50:11 -03002692
Jean-Francois Moine60017612008-07-18 08:46:19 -03002693 reg_w1(gspca_dev, 0x17, reg17);
Jean-Francois Moine0e4d4132010-12-14 16:17:40 -03002694 reg_w1(gspca_dev, 0x01, reg01);
2695 sd->reg01 = reg01;
2696 sd->reg17 = reg17;
Jean-Francois Moine3fccb772009-11-02 09:54:04 -03002697
Németh Márton76ad3b62010-10-19 03:33:47 -03002698 sethvflip(gspca_dev);
Jean-Francois Moine91bd3412008-11-23 14:47:50 -03002699 setbrightness(gspca_dev);
2700 setcontrast(gspca_dev);
Jean-François Moinefff2f702010-04-25 14:31:05 -03002701 setcolors(gspca_dev);
Jean-Francois Moinecebf3b62008-08-03 07:52:53 -03002702 setautogain(gspca_dev);
Jean-François Moinea7705c02012-02-27 06:57:04 -03002703 if (!(gspca_dev->ctrl_inac & ((1 << EXPOSURE) | (1 << GAIN)))) {
2704 setexposure(gspca_dev);
2705 setgain(gspca_dev);
2706 }
Hans de Goede37c6dbe2009-06-18 07:35:36 -03002707 setfreq(gspca_dev);
Jean-François Moineb96cfc32011-02-10 07:38:58 -03002708
2709 sd->pktsz = sd->npkt = 0;
2710 sd->nchg = sd->short_mark = 0;
2711 sd->work_thread = create_singlethread_workqueue(MODULE_NAME);
2712
Jean-François Moine4bf8b672010-09-25 06:12:44 -03002713 return gspca_dev->usb_err;
Jean-Francois Moine6a7eba22008-06-30 15:50:11 -03002714}
2715
2716static void sd_stopN(struct gspca_dev *gspca_dev)
2717{
2718 struct sd *sd = (struct sd *) gspca_dev;
Jean-Francois Moine98819182009-01-19 07:37:33 -03002719 static const u8 stophv7131[] =
Jean-Francois Moine6a7eba22008-06-30 15:50:11 -03002720 { 0xa1, 0x11, 0x02, 0x09, 0x00, 0x00, 0x00, 0x10 };
Jean-Francois Moine98819182009-01-19 07:37:33 -03002721 static const u8 stopmi0360[] =
Jean-Francois Moine6a7eba22008-06-30 15:50:11 -03002722 { 0xb1, 0x5d, 0x07, 0x00, 0x00, 0x00, 0x00, 0x10 };
Jean-Francois Moine98819182009-01-19 07:37:33 -03002723 static const u8 stopov7648[] =
Jean-Francois Moine62703302008-11-11 08:42:56 -03002724 { 0xa1, 0x21, 0x76, 0x20, 0x00, 0x00, 0x00, 0x10 };
Jean-François Moine03ed2a12010-04-25 14:45:43 -03002725 static const u8 stopsoi768[] =
2726 { 0xa1, 0x21, 0x12, 0x80, 0x00, 0x00, 0x00, 0x10 };
Jean-Francois Moine0e4d4132010-12-14 16:17:40 -03002727 u8 reg01;
2728 u8 reg17;
Jean-Francois Moine6a7eba22008-06-30 15:50:11 -03002729
Jean-Francois Moine0e4d4132010-12-14 16:17:40 -03002730 reg01 = sd->reg01;
2731 reg17 = sd->reg17 & ~SEN_CLK_EN;
Jean-Francois Moine6a7eba22008-06-30 15:50:11 -03002732 switch (sd->sensor) {
Jean-Francois Moine0e4d4132010-12-14 16:17:40 -03002733 case SENSOR_ADCM1700:
Jean-François Moinead98c0f2010-03-18 05:15:30 -03002734 case SENSOR_GC0307:
Jean-Francois Moine0e4d4132010-12-14 16:17:40 -03002735 case SENSOR_PO2030N:
2736 case SENSOR_SP80708:
2737 reg01 |= LED;
2738 reg_w1(gspca_dev, 0x01, reg01);
2739 reg01 &= ~(LED | V_TX_EN);
2740 reg_w1(gspca_dev, 0x01, reg01);
2741/* reg_w1(gspca_dev, 0x02, 0x??); * LED off ? */
Jean-François Moinead98c0f2010-03-18 05:15:30 -03002742 break;
Jean-Francois Moine6a7eba22008-06-30 15:50:11 -03002743 case SENSOR_HV7131R:
Jean-Francois Moine0e4d4132010-12-14 16:17:40 -03002744 reg01 &= ~V_TX_EN;
2745 reg_w1(gspca_dev, 0x01, reg01);
Jean-Francois Moine739570b2008-07-14 09:38:29 -03002746 i2c_w8(gspca_dev, stophv7131);
Jean-Francois Moine6a7eba22008-06-30 15:50:11 -03002747 break;
2748 case SENSOR_MI0360:
Jean-François Moinea067db82010-10-01 07:51:24 -03002749 case SENSOR_MI0360B:
Jean-Francois Moine0e4d4132010-12-14 16:17:40 -03002750 reg01 &= ~V_TX_EN;
2751 reg_w1(gspca_dev, 0x01, reg01);
2752/* reg_w1(gspca_dev, 0x02, 0x40); * LED off ? */
Jean-Francois Moine739570b2008-07-14 09:38:29 -03002753 i2c_w8(gspca_dev, stopmi0360);
Jean-Francois Moine6a7eba22008-06-30 15:50:11 -03002754 break;
Jean-Francois Moine3ef2c5b2009-01-29 04:59:45 -03002755 case SENSOR_MT9V111:
Jean-Francois Moine0e4d4132010-12-14 16:17:40 -03002756 case SENSOR_OM6802:
Jean-Francois Moineb8c8a5b2009-11-23 06:46:35 -03002757 case SENSOR_PO1030:
Jean-Francois Moine0e4d4132010-12-14 16:17:40 -03002758 reg01 &= ~V_TX_EN;
2759 reg_w1(gspca_dev, 0x01, reg01);
2760 break;
2761 case SENSOR_OV7630:
2762 case SENSOR_OV7648:
2763 reg01 &= ~V_TX_EN;
2764 reg_w1(gspca_dev, 0x01, reg01);
2765 i2c_w8(gspca_dev, stopov7648);
2766 break;
2767 case SENSOR_OV7660:
2768 reg01 &= ~V_TX_EN;
2769 reg_w1(gspca_dev, 0x01, reg01);
Jean-Francois Moine6a7eba22008-06-30 15:50:11 -03002770 break;
Jean-François Moine03ed2a12010-04-25 14:45:43 -03002771 case SENSOR_SOI768:
2772 i2c_w8(gspca_dev, stopsoi768);
Jean-François Moine03ed2a12010-04-25 14:45:43 -03002773 break;
Jean-Francois Moine6a7eba22008-06-30 15:50:11 -03002774 }
Jean-Francois Moine0e4d4132010-12-14 16:17:40 -03002775
2776 reg01 |= SCL_SEL_OD;
2777 reg_w1(gspca_dev, 0x01, reg01);
2778 reg01 |= S_PWR_DN; /* sensor power down */
2779 reg_w1(gspca_dev, 0x01, reg01);
2780 reg_w1(gspca_dev, 0x17, reg17);
2781 reg01 &= ~SYS_SEL_48M; /* clock 24MHz */
2782 reg_w1(gspca_dev, 0x01, reg01);
2783 reg01 |= LED;
2784 reg_w1(gspca_dev, 0x01, reg01);
Hans de Goede9712a8b2010-01-31 12:54:29 -03002785 /* Don't disable sensor clock as that disables the button on the cam */
2786 /* reg_w1(gspca_dev, 0xf1, 0x01); */
Jean-Francois Moine6a7eba22008-06-30 15:50:11 -03002787}
2788
Jean-François Moineb96cfc32011-02-10 07:38:58 -03002789/* called on streamoff with alt==0 and on disconnect */
2790/* the usb_lock is held at entry - restore on exit */
2791static void sd_stop0(struct gspca_dev *gspca_dev)
2792{
2793 struct sd *sd = (struct sd *) gspca_dev;
2794
2795 if (sd->work_thread != NULL) {
2796 mutex_unlock(&gspca_dev->usb_lock);
2797 destroy_workqueue(sd->work_thread);
2798 mutex_lock(&gspca_dev->usb_lock);
2799 sd->work_thread = NULL;
2800 }
2801}
2802
Hans de Goedea648e312012-04-27 11:32:24 -03002803#define WANT_REGULAR_AUTOGAIN
Jean-François Moinea7705c02012-02-27 06:57:04 -03002804#include "autogain_functions.h"
2805
Jean-Francois Moinecebf3b62008-08-03 07:52:53 -03002806static void do_autogain(struct gspca_dev *gspca_dev)
Jean-Francois Moine6a7eba22008-06-30 15:50:11 -03002807{
2808 struct sd *sd = (struct sd *) gspca_dev;
Jean-Francois Moine6a7eba22008-06-30 15:50:11 -03002809 int delta;
Jean-Francois Moinecebf3b62008-08-03 07:52:53 -03002810 int expotimes;
Jean-Francois Moine98819182009-01-19 07:37:33 -03002811 u8 luma_mean = 130;
2812 u8 luma_delta = 20;
Jean-Francois Moine6a7eba22008-06-30 15:50:11 -03002813
Jean-Francois Moinecebf3b62008-08-03 07:52:53 -03002814 /* Thanks S., without your advice, autobright should not work :) */
2815 if (sd->ag_cnt < 0)
2816 return;
2817 if (--sd->ag_cnt >= 0)
2818 return;
2819 sd->ag_cnt = AG_CNT_START;
2820
2821 delta = atomic_read(&sd->avg_lum);
2822 PDEBUG(D_FRAM, "mean lum %d", delta);
Jean-François Moinea7705c02012-02-27 06:57:04 -03002823
2824 if (sd->sensor == SENSOR_PO2030N) {
2825 auto_gain_n_exposure(gspca_dev, delta, luma_mean, luma_delta,
2826 15, 1024);
2827 return;
2828 }
2829
Jean-Francois Moine6a7eba22008-06-30 15:50:11 -03002830 if (delta < luma_mean - luma_delta ||
2831 delta > luma_mean + luma_delta) {
2832 switch (sd->sensor) {
Jean-François Moinec26b12d2010-04-02 07:08:39 -03002833 case SENSOR_GC0307:
2834 expotimes = sd->exposure;
2835 expotimes += (luma_mean - delta) >> 6;
2836 if (expotimes < 0)
2837 expotimes = 0;
Jean-François Moinea7705c02012-02-27 06:57:04 -03002838 sd->exposure = expo_adjust(gspca_dev,
Jean-François Moinec26b12d2010-04-02 07:08:39 -03002839 (unsigned int) expotimes);
2840 break;
Jean-Francois Moine6a7eba22008-06-30 15:50:11 -03002841 case SENSOR_HV7131R:
2842 expotimes = sd->exposure >> 8;
2843 expotimes += (luma_mean - delta) >> 4;
2844 if (expotimes < 0)
2845 expotimes = 0;
Jean-François Moinea7705c02012-02-27 06:57:04 -03002846 sd->exposure = expo_adjust(gspca_dev,
Jean-Francois Moine6a7eba22008-06-30 15:50:11 -03002847 (unsigned int) (expotimes << 8));
2848 break;
Amauri Magagna46b4f2a2009-10-17 07:21:29 -03002849 case SENSOR_OM6802:
Jean-François Moine22203672011-02-10 07:49:32 -03002850 case SENSOR_MT9V111:
Amauri Magagna46b4f2a2009-10-17 07:21:29 -03002851 expotimes = sd->exposure;
2852 expotimes += (luma_mean - delta) >> 2;
2853 if (expotimes < 0)
2854 expotimes = 0;
Jean-François Moinea7705c02012-02-27 06:57:04 -03002855 sd->exposure = expo_adjust(gspca_dev,
Amauri Magagna46b4f2a2009-10-17 07:21:29 -03002856 (unsigned int) expotimes);
2857 setredblue(gspca_dev);
2858 break;
Jean-Francois Moinecebf3b62008-08-03 07:52:53 -03002859 default:
2860/* case SENSOR_MO4000: */
2861/* case SENSOR_MI0360: */
Jean-François Moinea067db82010-10-01 07:51:24 -03002862/* case SENSOR_MI0360B: */
Jean-Francois Moine6a7eba22008-06-30 15:50:11 -03002863 expotimes = sd->exposure;
2864 expotimes += (luma_mean - delta) >> 6;
2865 if (expotimes < 0)
2866 expotimes = 0;
Jean-François Moinea7705c02012-02-27 06:57:04 -03002867 sd->exposure = expo_adjust(gspca_dev,
Jean-Francois Moine6a7eba22008-06-30 15:50:11 -03002868 (unsigned int) expotimes);
Jean-Francois Moine403123d2008-11-26 04:46:15 -03002869 setredblue(gspca_dev);
Jean-Francois Moine6a7eba22008-06-30 15:50:11 -03002870 break;
2871 }
2872 }
2873}
2874
Jean-François Moine0f77f402011-02-10 07:01:30 -03002875/* set the average luminosity from an isoc marker */
2876static void set_lum(struct sd *sd,
2877 u8 *data)
2878{
2879 int avg_lum;
2880
2881 /* w0 w1 w2
2882 * w3 w4 w5
2883 * w6 w7 w8
2884 */
2885 avg_lum = (data[27] << 8) + data[28] /* w3 */
2886
2887 + (data[31] << 8) + data[32] /* w5 */
2888
2889 + (data[23] << 8) + data[24] /* w1 */
2890
2891 + (data[35] << 8) + data[36] /* w7 */
2892
2893 + (data[29] << 10) + (data[30] << 2); /* w4 * 4 */
2894 avg_lum >>= 10;
2895 atomic_set(&sd->avg_lum, avg_lum);
2896}
2897
Jean-Francois Moinecebf3b62008-08-03 07:52:53 -03002898/* scan the URB packets */
2899/* This function is run at interrupt level. */
Jean-Francois Moine6a7eba22008-06-30 15:50:11 -03002900static void sd_pkt_scan(struct gspca_dev *gspca_dev,
Jean-Francois Moine98819182009-01-19 07:37:33 -03002901 u8 *data, /* isoc packet */
Jean-Francois Moine6a7eba22008-06-30 15:50:11 -03002902 int len) /* iso packet length */
2903{
2904 struct sd *sd = (struct sd *) gspca_dev;
Jean-François Moineb96cfc32011-02-10 07:38:58 -03002905 int i, new_qual;
Jean-Francois Moine6a7eba22008-06-30 15:50:11 -03002906
Jean-François Moinea4a30762011-02-10 07:15:24 -03002907 /*
2908 * A frame ends on the marker
2909 * ff ff 00 c4 c4 96 ..
2910 * which is 62 bytes long and is followed by various information
2911 * including statuses and luminosity.
2912 *
2913 * A marker may be splitted on two packets.
2914 *
2915 * The 6th byte of a marker contains the bits:
2916 * 0x08: USB full
2917 * 0xc0: frame sequence
2918 * When the bit 'USB full' is set, the frame must be discarded;
2919 * this is also the case when the 2 bytes before the marker are
2920 * not the JPEG end of frame ('ff d9').
2921 */
2922
Jean-François Moine788ab1b2012-05-02 04:05:18 -03002923 /* count the packets and their size */
2924 sd->npkt++;
2925 sd->pktsz += len;
2926
Jean-François Moinea4a30762011-02-10 07:15:24 -03002927/*fixme: assumption about the following code:
2928 * - there can be only one marker in a packet
2929 */
2930
2931 /* skip the remaining bytes of a short marker */
2932 i = sd->short_mark;
2933 if (i != 0) {
2934 sd->short_mark = 0;
2935 if (i < 0 /* if 'ff' at end of previous packet */
2936 && data[0] == 0xff
2937 && data[1] == 0x00)
2938 goto marker_found;
2939 if (data[0] == 0xff && data[1] == 0xff) {
2940 i = 0;
2941 goto marker_found;
2942 }
2943 len -= i;
2944 if (len <= 0)
2945 return;
2946 data += i;
2947 }
2948
2949 /* search backwards if there is a marker in the packet */
2950 for (i = len - 1; --i >= 0; ) {
2951 if (data[i] != 0xff) {
2952 i--;
2953 continue;
2954 }
2955 if (data[i + 1] == 0xff) {
2956
2957 /* (there may be 'ff ff' inside a marker) */
2958 if (i + 2 >= len || data[i + 2] == 0x00)
2959 goto marker_found;
2960 }
2961 }
2962
2963 /* no marker found */
2964 /* add the JPEG header if first fragment */
2965 if (data[len - 1] == 0xff)
2966 sd->short_mark = -1;
2967 if (gspca_dev->last_packet_type == LAST_PACKET)
Jean-François Moinea95bd642010-10-01 07:54:30 -03002968 gspca_frame_add(gspca_dev, FIRST_PACKET,
2969 sd->jpeg_hdr, JPEG_HDR_SZ);
Jean-François Moinea95bd642010-10-01 07:54:30 -03002970 gspca_frame_add(gspca_dev, INTER_PACKET, data, len);
Jean-François Moinea4a30762011-02-10 07:15:24 -03002971 return;
Jean-Francois Moine6a7eba22008-06-30 15:50:11 -03002972
Jean-François Moinea4a30762011-02-10 07:15:24 -03002973 /* marker found */
Jean-François Moineb96cfc32011-02-10 07:38:58 -03002974 /* if some error, discard the frame and decrease the quality */
Jean-François Moinea4a30762011-02-10 07:15:24 -03002975marker_found:
Jean-François Moineb96cfc32011-02-10 07:38:58 -03002976 new_qual = 0;
Jean-François Moinea4a30762011-02-10 07:15:24 -03002977 if (i > 2) {
2978 if (data[i - 2] != 0xff || data[i - 1] != 0xd9) {
2979 gspca_dev->last_packet_type = DISCARD_PACKET;
Jean-François Moineb96cfc32011-02-10 07:38:58 -03002980 new_qual = -3;
Jean-François Moinea4a30762011-02-10 07:15:24 -03002981 }
2982 } else if (i + 6 < len) {
2983 if (data[i + 6] & 0x08) {
2984 gspca_dev->last_packet_type = DISCARD_PACKET;
Jean-François Moineb96cfc32011-02-10 07:38:58 -03002985 new_qual = -5;
Jean-François Moinea4a30762011-02-10 07:15:24 -03002986 }
2987 }
Jean-François Moinea95bd642010-10-01 07:54:30 -03002988
Jean-François Moinea4a30762011-02-10 07:15:24 -03002989 gspca_frame_add(gspca_dev, LAST_PACKET, data, i);
2990
Jean-François Moineb96cfc32011-02-10 07:38:58 -03002991 /* compute the filling rate and a new JPEG quality */
2992 if (new_qual == 0) {
2993 int r;
2994
2995 r = (sd->pktsz * 100) /
2996 (sd->npkt *
2997 gspca_dev->urb[0]->iso_frame_desc[0].length);
2998 if (r >= 85)
2999 new_qual = -3;
3000 else if (r < 75)
3001 new_qual = 2;
3002 }
3003 if (new_qual != 0) {
3004 sd->nchg += new_qual;
3005 if (sd->nchg < -6 || sd->nchg >= 12) {
3006 sd->nchg = 0;
3007 new_qual += sd->quality;
3008 if (new_qual < QUALITY_MIN)
3009 new_qual = QUALITY_MIN;
3010 else if (new_qual > QUALITY_MAX)
3011 new_qual = QUALITY_MAX;
3012 if (new_qual != sd->quality) {
3013 sd->quality = new_qual;
3014 queue_work(sd->work_thread, &sd->work);
3015 }
3016 }
3017 } else {
3018 sd->nchg = 0;
3019 }
3020 sd->pktsz = sd->npkt = 0;
3021
Jean-François Moinea4a30762011-02-10 07:15:24 -03003022 /* if the marker is smaller than 62 bytes,
3023 * memorize the number of bytes to skip in the next packet */
3024 if (i + 62 > len) { /* no more usable data */
3025 sd->short_mark = i + 62 - len;
3026 return;
3027 }
Jean-François Moine0f77f402011-02-10 07:01:30 -03003028 if (sd->ag_cnt >= 0)
Jean-François Moinea4a30762011-02-10 07:15:24 -03003029 set_lum(sd, data + i);
3030
3031 /* if more data, start a new frame */
3032 i += 62;
3033 if (i < len) {
3034 data += i;
3035 len -= i;
3036 gspca_frame_add(gspca_dev, FIRST_PACKET,
3037 sd->jpeg_hdr, JPEG_HDR_SZ);
3038 gspca_frame_add(gspca_dev, INTER_PACKET, data, len);
3039 }
Jean-Francois Moine6a7eba22008-06-30 15:50:11 -03003040}
3041
Jean-François Moinea7705c02012-02-27 06:57:04 -03003042static int sd_setautogain(struct gspca_dev *gspca_dev, __s32 val)
3043{
3044 struct sd *sd = (struct sd *) gspca_dev;
3045
3046 sd->ctrls[AUTOGAIN].val = val;
3047 if (val)
3048 gspca_dev->ctrl_inac |= (1 << EXPOSURE) | (1 << GAIN);
3049 else
3050 gspca_dev->ctrl_inac &= ~(1 << EXPOSURE) & ~(1 << GAIN);
3051 if (gspca_dev->streaming)
3052 setautogain(gspca_dev);
3053 return gspca_dev->usb_err;
3054}
3055
Hans de Goede37c6dbe2009-06-18 07:35:36 -03003056static int sd_querymenu(struct gspca_dev *gspca_dev,
3057 struct v4l2_querymenu *menu)
3058{
3059 switch (menu->id) {
3060 case V4L2_CID_POWER_LINE_FREQUENCY:
3061 switch (menu->index) {
3062 case 0: /* V4L2_CID_POWER_LINE_FREQUENCY_DISABLED */
3063 strcpy((char *) menu->name, "NoFliker");
3064 return 0;
3065 case 1: /* V4L2_CID_POWER_LINE_FREQUENCY_50HZ */
3066 strcpy((char *) menu->name, "50 Hz");
3067 return 0;
3068 case 2: /* V4L2_CID_POWER_LINE_FREQUENCY_60HZ */
3069 strcpy((char *) menu->name, "60 Hz");
3070 return 0;
3071 }
3072 break;
3073 }
3074 return -EINVAL;
3075}
3076
Jean-François Moine28566432010-10-01 07:33:26 -03003077#if defined(CONFIG_INPUT) || defined(CONFIG_INPUT_MODULE)
Hans de Goede9712a8b2010-01-31 12:54:29 -03003078static int sd_int_pkt_scan(struct gspca_dev *gspca_dev,
3079 u8 *data, /* interrupt packet data */
3080 int len) /* interrupt packet length */
3081{
3082 int ret = -EINVAL;
3083
3084 if (len == 1 && data[0] == 1) {
3085 input_report_key(gspca_dev->input_dev, KEY_CAMERA, 1);
3086 input_sync(gspca_dev->input_dev);
3087 input_report_key(gspca_dev->input_dev, KEY_CAMERA, 0);
3088 input_sync(gspca_dev->input_dev);
3089 ret = 0;
3090 }
3091
3092 return ret;
3093}
3094#endif
3095
Jean-Francois Moine6a7eba22008-06-30 15:50:11 -03003096/* sub-driver description */
Jean-Francois Moinea5ae2062008-07-04 11:16:16 -03003097static const struct sd_desc sd_desc = {
Jean-Francois Moine6a7eba22008-06-30 15:50:11 -03003098 .name = MODULE_NAME,
3099 .ctrls = sd_ctrls,
Jean-François Moine72b667e2010-10-02 04:35:25 -03003100 .nctrls = NCTRLS,
Jean-Francois Moine6a7eba22008-06-30 15:50:11 -03003101 .config = sd_config,
Jean-Francois Moine012d6b02008-09-03 17:12:16 -03003102 .init = sd_init,
Jean-Francois Moine6a7eba22008-06-30 15:50:11 -03003103 .start = sd_start,
3104 .stopN = sd_stopN,
Jean-François Moineb96cfc32011-02-10 07:38:58 -03003105 .stop0 = sd_stop0,
Jean-Francois Moine6a7eba22008-06-30 15:50:11 -03003106 .pkt_scan = sd_pkt_scan,
Jean-Francois Moinecebf3b62008-08-03 07:52:53 -03003107 .dq_callback = do_autogain,
Hans de Goede37c6dbe2009-06-18 07:35:36 -03003108 .querymenu = sd_querymenu,
Jean-François Moine28566432010-10-01 07:33:26 -03003109#if defined(CONFIG_INPUT) || defined(CONFIG_INPUT_MODULE)
Hans de Goede9712a8b2010-01-31 12:54:29 -03003110 .int_pkt_scan = sd_int_pkt_scan,
3111#endif
Jean-Francois Moine6a7eba22008-06-30 15:50:11 -03003112};
3113
3114/* -- module initialisation -- */
Jean-Francois Moined5aa3852009-11-07 06:10:08 -03003115#define BS(bridge, sensor) \
Jean-Francois Moine9d64fdb2008-07-25 08:53:03 -03003116 .driver_info = (BRIDGE_ ## bridge << 16) \
Jean-Francois Moinec6c14332010-12-14 16:15:37 -03003117 | (SENSOR_ ## sensor << 8)
3118#define BSF(bridge, sensor, flags) \
3119 .driver_info = (BRIDGE_ ## bridge << 16) \
3120 | (SENSOR_ ## sensor << 8) \
3121 | (flags)
Jean-François Moine95c967c2011-01-13 05:20:29 -03003122static const struct usb_device_id device_table[] = {
Jean-Francois Moined5aa3852009-11-07 06:10:08 -03003123 {USB_DEVICE(0x0458, 0x7025), BS(SN9C120, MI0360)},
3124 {USB_DEVICE(0x0458, 0x702e), BS(SN9C120, OV7660)},
Jean-François Moine3afef852011-01-13 06:39:11 -03003125 {USB_DEVICE(0x045e, 0x00f5), BSF(SN9C105, OV7660, F_PDN_INV)},
3126 {USB_DEVICE(0x045e, 0x00f7), BSF(SN9C105, OV7660, F_PDN_INV)},
Jean-Francois Moined5aa3852009-11-07 06:10:08 -03003127 {USB_DEVICE(0x0471, 0x0327), BS(SN9C105, MI0360)},
3128 {USB_DEVICE(0x0471, 0x0328), BS(SN9C105, MI0360)},
3129 {USB_DEVICE(0x0471, 0x0330), BS(SN9C105, MI0360)},
3130 {USB_DEVICE(0x06f8, 0x3004), BS(SN9C105, OV7660)},
3131 {USB_DEVICE(0x06f8, 0x3008), BS(SN9C105, OV7660)},
3132/* {USB_DEVICE(0x0c45, 0x603a), BS(SN9C102P, OV7648)}, */
3133 {USB_DEVICE(0x0c45, 0x6040), BS(SN9C102P, HV7131R)},
3134/* {USB_DEVICE(0x0c45, 0x607a), BS(SN9C102P, OV7648)}, */
3135/* {USB_DEVICE(0x0c45, 0x607b), BS(SN9C102P, OV7660)}, */
3136 {USB_DEVICE(0x0c45, 0x607c), BS(SN9C102P, HV7131R)},
3137/* {USB_DEVICE(0x0c45, 0x607e), BS(SN9C102P, OV7630)}, */
Jean-François Moine3afef852011-01-13 06:39:11 -03003138 {USB_DEVICE(0x0c45, 0x60c0), BSF(SN9C105, MI0360, F_ILLUM)},
Jean-François Moinea067db82010-10-01 07:51:24 -03003139 /* or MT9V111 */
Jean-Francois Moined5aa3852009-11-07 06:10:08 -03003140/* {USB_DEVICE(0x0c45, 0x60c2), BS(SN9C105, P1030xC)}, */
3141/* {USB_DEVICE(0x0c45, 0x60c8), BS(SN9C105, OM6802)}, */
3142/* {USB_DEVICE(0x0c45, 0x60cc), BS(SN9C105, HV7131GP)}, */
Warren Bosworth Fockec4f95d82010-05-07 15:40:04 -03003143 {USB_DEVICE(0x0c45, 0x60ce), BS(SN9C105, SP80708)},
Jean-Francois Moined5aa3852009-11-07 06:10:08 -03003144 {USB_DEVICE(0x0c45, 0x60ec), BS(SN9C105, MO4000)},
3145/* {USB_DEVICE(0x0c45, 0x60ef), BS(SN9C105, ICM105C)}, */
3146/* {USB_DEVICE(0x0c45, 0x60fa), BS(SN9C105, OV7648)}, */
Jean-François Moine68046752010-05-07 15:35:08 -03003147/* {USB_DEVICE(0x0c45, 0x60f2), BS(SN9C105, OV7660)}, */
Jean-Francois Moined5aa3852009-11-07 06:10:08 -03003148 {USB_DEVICE(0x0c45, 0x60fb), BS(SN9C105, OV7660)},
Jean-Francois Moined5aa3852009-11-07 06:10:08 -03003149 {USB_DEVICE(0x0c45, 0x60fc), BS(SN9C105, HV7131R)},
3150 {USB_DEVICE(0x0c45, 0x60fe), BS(SN9C105, OV7630)},
Jean-Francois Moined5aa3852009-11-07 06:10:08 -03003151 {USB_DEVICE(0x0c45, 0x6100), BS(SN9C120, MI0360)}, /*sn9c128*/
Jean-François Moine860e7f42010-09-13 06:40:17 -03003152 {USB_DEVICE(0x0c45, 0x6102), BS(SN9C120, PO2030N)}, /* /GC0305*/
Jean-Francois Moined5aa3852009-11-07 06:10:08 -03003153/* {USB_DEVICE(0x0c45, 0x6108), BS(SN9C120, OM6802)}, */
3154 {USB_DEVICE(0x0c45, 0x610a), BS(SN9C120, OV7648)}, /*sn9c128*/
3155 {USB_DEVICE(0x0c45, 0x610b), BS(SN9C120, OV7660)}, /*sn9c128*/
3156 {USB_DEVICE(0x0c45, 0x610c), BS(SN9C120, HV7131R)}, /*sn9c128*/
3157 {USB_DEVICE(0x0c45, 0x610e), BS(SN9C120, OV7630)}, /*sn9c128*/
3158/* {USB_DEVICE(0x0c45, 0x610f), BS(SN9C120, S5K53BEB)}, */
3159/* {USB_DEVICE(0x0c45, 0x6122), BS(SN9C110, ICM105C)}, */
3160/* {USB_DEVICE(0x0c45, 0x6123), BS(SN9C110, SanyoCCD)}, */
3161 {USB_DEVICE(0x0c45, 0x6128), BS(SN9C120, OM6802)}, /*sn9c325?*/
Jean-Francois Moined2d16e92008-09-03 16:47:23 -03003162/*bw600.inf:*/
Jean-Francois Moineb8c8a5b2009-11-23 06:46:35 -03003163 {USB_DEVICE(0x0c45, 0x612a), BS(SN9C120, OV7648)}, /*sn9c325?*/
Alexander Goncharov2a3b5012010-09-13 06:58:16 -03003164 {USB_DEVICE(0x0c45, 0x612b), BS(SN9C110, ADCM1700)},
Jean-Francois Moined5aa3852009-11-07 06:10:08 -03003165 {USB_DEVICE(0x0c45, 0x612c), BS(SN9C110, MO4000)},
3166 {USB_DEVICE(0x0c45, 0x612e), BS(SN9C110, OV7630)},
3167/* {USB_DEVICE(0x0c45, 0x612f), BS(SN9C110, ICM105C)}, */
Jean-Francois Moined5aa3852009-11-07 06:10:08 -03003168 {USB_DEVICE(0x0c45, 0x6130), BS(SN9C120, MI0360)},
Jean-François Moinea067db82010-10-01 07:51:24 -03003169 /* or MT9V111 / MI0360B */
Jean-Francois Moined5aa3852009-11-07 06:10:08 -03003170/* {USB_DEVICE(0x0c45, 0x6132), BS(SN9C120, OV7670)}, */
3171 {USB_DEVICE(0x0c45, 0x6138), BS(SN9C120, MO4000)},
3172 {USB_DEVICE(0x0c45, 0x613a), BS(SN9C120, OV7648)},
Jean-Francois Moined5aa3852009-11-07 06:10:08 -03003173 {USB_DEVICE(0x0c45, 0x613b), BS(SN9C120, OV7660)},
Jean-Francois Moined5aa3852009-11-07 06:10:08 -03003174 {USB_DEVICE(0x0c45, 0x613c), BS(SN9C120, HV7131R)},
3175 {USB_DEVICE(0x0c45, 0x613e), BS(SN9C120, OV7630)},
Jean-François Moinead98c0f2010-03-18 05:15:30 -03003176 {USB_DEVICE(0x0c45, 0x6142), BS(SN9C120, PO2030N)}, /*sn9c120b*/
Jean-François Moine68046752010-05-07 15:35:08 -03003177 /* or GC0305 / GC0307 */
Jean-Francois Moined5aa3852009-11-07 06:10:08 -03003178 {USB_DEVICE(0x0c45, 0x6143), BS(SN9C120, SP80708)}, /*sn9c120b*/
3179 {USB_DEVICE(0x0c45, 0x6148), BS(SN9C120, OM6802)}, /*sn9c120b*/
Jean-François Moinea63d6012011-01-13 07:56:00 -03003180 {USB_DEVICE(0x0c45, 0x614a), BSF(SN9C120, ADCM1700, F_ILLUM)},
Hans de Goedee48d38f2011-01-06 16:21:57 -03003181/* {USB_DEVICE(0x0c45, 0x614c), BS(SN9C120, GC0306)}, */ /*sn9c120b*/
Jean-Francois Moine6a7eba22008-06-30 15:50:11 -03003182 {}
3183};
3184MODULE_DEVICE_TABLE(usb, device_table);
3185
3186/* -- device connect -- */
3187static int sd_probe(struct usb_interface *intf,
3188 const struct usb_device_id *id)
3189{
3190 return gspca_dev_probe(intf, id, &sd_desc, sizeof(struct sd),
3191 THIS_MODULE);
3192}
3193
3194static struct usb_driver sd_driver = {
3195 .name = MODULE_NAME,
3196 .id_table = device_table,
3197 .probe = sd_probe,
3198 .disconnect = gspca_disconnect,
Jean-Francois Moine6a709742008-09-03 16:48:10 -03003199#ifdef CONFIG_PM
3200 .suspend = gspca_suspend,
3201 .resume = gspca_resume,
3202#endif
Jean-Francois Moine6a7eba22008-06-30 15:50:11 -03003203};
3204
Greg Kroah-Hartmanecb3b2b2011-11-18 09:46:12 -08003205module_usb_driver(sd_driver);