1 /***************************************************************************
2 * Plug-in for OV7630 image sensor connected to the SN9C10x PC Camera *
5 * Copyright (C) 2005 by Luca Risolia <luca.risolia@studio.unibo.it> *
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 * (at your option) any later version. *
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. *
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., 675 Mass Ave, Cambridge, MA 02139, USA. *
20 ***************************************************************************/
22 #include "sn9c102_sensor.h"
25 static struct sn9c102_sensor ov7630;
28 static int ov7630_init(struct sn9c102_device* cam)
32 err += sn9c102_write_reg(cam, 0x00, 0x14);
33 err += sn9c102_write_reg(cam, 0x60, 0x17);
34 err += sn9c102_write_reg(cam, 0x0f, 0x18);
35 err += sn9c102_write_reg(cam, 0x50, 0x19);
37 err += sn9c102_i2c_write(cam, 0x12, 0x8d);
38 err += sn9c102_i2c_write(cam, 0x11, 0x00);
39 err += sn9c102_i2c_write(cam, 0x15, 0x34);
40 err += sn9c102_i2c_write(cam, 0x16, 0x03);
41 err += sn9c102_i2c_write(cam, 0x17, 0x1c);
42 err += sn9c102_i2c_write(cam, 0x18, 0xbd);
43 err += sn9c102_i2c_write(cam, 0x19, 0x06);
44 err += sn9c102_i2c_write(cam, 0x1a, 0xf6);
45 err += sn9c102_i2c_write(cam, 0x1b, 0x04);
46 err += sn9c102_i2c_write(cam, 0x20, 0x44);
47 err += sn9c102_i2c_write(cam, 0x23, 0xee);
48 err += sn9c102_i2c_write(cam, 0x26, 0xa0);
49 err += sn9c102_i2c_write(cam, 0x27, 0x9a);
50 err += sn9c102_i2c_write(cam, 0x28, 0x20);
51 err += sn9c102_i2c_write(cam, 0x29, 0x30);
52 err += sn9c102_i2c_write(cam, 0x2f, 0x3d);
53 err += sn9c102_i2c_write(cam, 0x30, 0x24);
54 err += sn9c102_i2c_write(cam, 0x32, 0x86);
55 err += sn9c102_i2c_write(cam, 0x60, 0xa9);
56 err += sn9c102_i2c_write(cam, 0x61, 0x42);
57 err += sn9c102_i2c_write(cam, 0x65, 0x00);
58 err += sn9c102_i2c_write(cam, 0x69, 0x38);
59 err += sn9c102_i2c_write(cam, 0x6f, 0x88);
60 err += sn9c102_i2c_write(cam, 0x70, 0x0b);
61 err += sn9c102_i2c_write(cam, 0x71, 0x00);
62 err += sn9c102_i2c_write(cam, 0x74, 0x21);
63 err += sn9c102_i2c_write(cam, 0x7d, 0xf7);
69 static int ov7630_set_ctrl(struct sn9c102_device* cam,
70 const struct v4l2_control* ctrl)
75 case V4L2_CID_EXPOSURE:
76 err += sn9c102_i2c_write(cam, 0x10, ctrl->value >> 2);
77 err += sn9c102_i2c_write(cam, 0x76, ctrl->value & 0x03);
79 case V4L2_CID_RED_BALANCE:
80 err += sn9c102_i2c_write(cam, 0x02, ctrl->value);
82 case V4L2_CID_BLUE_BALANCE:
83 err += sn9c102_i2c_write(cam, 0x03, ctrl->value);
86 err += sn9c102_i2c_write(cam, 0x00, ctrl->value);
88 case V4L2_CID_CONTRAST:
89 err += ctrl->value ? sn9c102_i2c_write(cam, 0x05,
90 (ctrl->value-1) | 0x20)
91 : sn9c102_i2c_write(cam, 0x05, 0x00);
93 case V4L2_CID_BRIGHTNESS:
94 err += sn9c102_i2c_write(cam, 0x06, ctrl->value);
96 case V4L2_CID_SATURATION:
97 err += sn9c102_i2c_write(cam, 0x03, ctrl->value << 4);
100 err += ctrl->value ? sn9c102_i2c_write(cam, 0x04,
101 (ctrl->value-1) | 0x20)
102 : sn9c102_i2c_write(cam, 0x04, 0x00);
104 case V4L2_CID_DO_WHITE_BALANCE:
105 err += sn9c102_i2c_write(cam, 0x0c, ctrl->value);
107 case V4L2_CID_WHITENESS:
108 err += sn9c102_i2c_write(cam, 0x0d, ctrl->value);
110 case V4L2_CID_AUTO_WHITE_BALANCE:
111 err += sn9c102_i2c_write(cam, 0x12, (ctrl->value << 2) | 0x09);
113 case V4L2_CID_AUTOGAIN:
114 err += sn9c102_i2c_write(cam, 0x13, ctrl->value);
117 err += sn9c102_i2c_write(cam, 0x75, 0x0e | (ctrl->value << 7));
119 case V4L2_CID_BLACK_LEVEL:
120 err += sn9c102_i2c_write(cam, 0x25, ctrl->value);
122 case SN9C102_V4L2_CID_BRIGHT_LEVEL:
123 err += sn9c102_i2c_write(cam, 0x24, ctrl->value);
125 case SN9C102_V4L2_CID_GAMMA:
126 err += sn9c102_i2c_write(cam, 0x14, (ctrl->value << 2) | 0x80);
128 case SN9C102_V4L2_CID_BAND_FILTER:
129 err += sn9c102_i2c_write(cam, 0x2d, ctrl->value << 2);
135 return err ? -EIO : 0;
139 static int ov7630_set_crop(struct sn9c102_device* cam,
140 const struct v4l2_rect* rect)
142 struct sn9c102_sensor* s = &ov7630;
144 u8 v_start = (u8)(rect->top - s->cropcap.bounds.top) + 1;
146 err += sn9c102_write_reg(cam, v_start, 0x13);
152 static int ov7630_set_pix_format(struct sn9c102_device* cam,
153 const struct v4l2_pix_format* pix)
157 if (pix->pixelformat == V4L2_PIX_FMT_SN9C10X)
158 err += sn9c102_write_reg(cam, 0x20, 0x19);
160 err += sn9c102_write_reg(cam, 0x50, 0x19);
166 static struct sn9c102_sensor ov7630 = {
168 .maintainer = "Luca Risolia <luca.risolia@studio.unibo.it>",
169 .sysfs_ops = SN9C102_I2C_WRITE,
170 .frequency = SN9C102_I2C_100KHZ,
171 .interface = SN9C102_I2C_2WIRES,
172 .i2c_slave_id = 0x21,
173 .init = &ov7630_init,
177 .type = V4L2_CTRL_TYPE_INTEGER,
178 .name = "global gain",
182 .default_value = 0x14,
187 .type = V4L2_CTRL_TYPE_INTEGER,
192 .default_value = 0x00,
196 .id = V4L2_CID_SATURATION,
197 .type = V4L2_CTRL_TYPE_INTEGER,
198 .name = "saturation",
202 .default_value = 0x08,
206 .id = V4L2_CID_CONTRAST,
207 .type = V4L2_CTRL_TYPE_INTEGER,
212 .default_value = 0x00,
216 .id = V4L2_CID_EXPOSURE,
217 .type = V4L2_CTRL_TYPE_INTEGER,
222 .default_value = 0x83<<2,
226 .id = V4L2_CID_RED_BALANCE,
227 .type = V4L2_CTRL_TYPE_INTEGER,
228 .name = "red balance",
232 .default_value = 0x3a,
236 .id = V4L2_CID_BLUE_BALANCE,
237 .type = V4L2_CTRL_TYPE_INTEGER,
238 .name = "blue balance",
242 .default_value = 0x77,
246 .id = V4L2_CID_BRIGHTNESS,
247 .type = V4L2_CTRL_TYPE_INTEGER,
248 .name = "brightness",
252 .default_value = 0xa0,
256 .id = V4L2_CID_DO_WHITE_BALANCE,
257 .type = V4L2_CTRL_TYPE_INTEGER,
258 .name = "white balance background: blue",
262 .default_value = 0x20,
266 .id = V4L2_CID_WHITENESS,
267 .type = V4L2_CTRL_TYPE_INTEGER,
268 .name = "white balance background: red",
272 .default_value = 0x20,
276 .id = V4L2_CID_AUTO_WHITE_BALANCE,
277 .type = V4L2_CTRL_TYPE_BOOLEAN,
278 .name = "auto white balance",
282 .default_value = 0x01,
286 .id = V4L2_CID_AUTOGAIN,
287 .type = V4L2_CTRL_TYPE_INTEGER,
288 .name = "gain & exposure mode",
292 .default_value = 0x00,
296 .id = V4L2_CID_VFLIP,
297 .type = V4L2_CTRL_TYPE_BOOLEAN,
298 .name = "vertical flip",
302 .default_value = 0x01,
306 .id = V4L2_CID_BLACK_LEVEL,
307 .type = V4L2_CTRL_TYPE_INTEGER,
308 .name = "black pixel ratio",
312 .default_value = 0x8a,
316 .id = SN9C102_V4L2_CID_BRIGHT_LEVEL,
317 .type = V4L2_CTRL_TYPE_INTEGER,
318 .name = "bright pixel ratio",
322 .default_value = 0x10,
326 .id = SN9C102_V4L2_CID_BAND_FILTER,
327 .type = V4L2_CTRL_TYPE_BOOLEAN,
328 .name = "band filter",
332 .default_value = 0x00,
336 .id = SN9C102_V4L2_CID_GAMMA,
337 .type = V4L2_CTRL_TYPE_BOOLEAN,
342 .default_value = 0x00,
346 .set_ctrl = &ov7630_set_ctrl,
361 .set_crop = &ov7630_set_crop,
365 .pixelformat = V4L2_PIX_FMT_SBGGR8,
368 .set_pix_format = &ov7630_set_pix_format
372 int sn9c102_probe_ov7630(struct sn9c102_device* cam)
376 sn9c102_attach_sensor(cam, &ov7630);
378 if (le16_to_cpu(ov7630.usbdev->descriptor.idProduct) != 0x608f &&
379 le16_to_cpu(ov7630.usbdev->descriptor.idProduct) != 0x602c)
382 err += sn9c102_write_reg(cam, 0x01, 0x01);
383 err += sn9c102_write_reg(cam, 0x00, 0x01);
384 err += sn9c102_write_reg(cam, 0x28, 0x17);
389 err += sn9c102_i2c_write(cam, 0x0b, 0);