1 /* OmniVision OV7610/OV7110 Camera Chip Support Code
3 * Copyright (c) 1999-2004 Mark McClelland <mark@alpha.dyndns.org>
4 * http://alpha.dyndns.org/ov511/
6 * Color fixes by by Orion Sky Lawlor <olawlor@acm.org> (2/26/2000)
8 * This program is free software; you can redistribute it and/or modify it
9 * under the terms of the GNU General Public License as published by the
10 * Free Software Foundation; either version 2 of the License, or (at your
11 * option) any later version. NO WARRANTY OF ANY KIND is expressed or implied.
16 #include <linux/slab.h>
17 #include "ovcamchip_priv.h"
20 #define REG_GAIN 0x00 /* gain [5:0] */
21 #define REG_BLUE 0x01 /* blue channel balance */
22 #define REG_RED 0x02 /* red channel balance */
23 #define REG_SAT 0x03 /* saturation */
24 #define REG_CNT 0x05 /* Y contrast */
25 #define REG_BRT 0x06 /* Y brightness */
26 #define REG_BLUE_BIAS 0x0C /* blue channel bias [5:0] */
27 #define REG_RED_BIAS 0x0D /* red channel bias [5:0] */
28 #define REG_GAMMA_COEFF 0x0E /* gamma settings */
29 #define REG_WB_RANGE 0x0F /* AEC/ALC/S-AWB settings */
30 #define REG_EXP 0x10 /* manual exposure setting */
31 #define REG_CLOCK 0x11 /* polarity/clock prescaler */
32 #define REG_FIELD_DIVIDE 0x16 /* field interval/mode settings */
33 #define REG_HWIN_START 0x17 /* horizontal window start */
34 #define REG_HWIN_END 0x18 /* horizontal window end */
35 #define REG_VWIN_START 0x19 /* vertical window start */
36 #define REG_VWIN_END 0x1A /* vertical window end */
37 #define REG_PIXEL_SHIFT 0x1B /* pixel shift */
38 #define REG_YOFFSET 0x21 /* Y channel offset */
39 #define REG_UOFFSET 0x22 /* U channel offset */
40 #define REG_ECW 0x24 /* exposure white level for AEC */
41 #define REG_ECB 0x25 /* exposure black level for AEC */
42 #define REG_FRAMERATE_H 0x2A /* frame rate MSB + misc */
43 #define REG_FRAMERATE_L 0x2B /* frame rate LSB */
44 #define REG_ALC 0x2C /* Auto Level Control settings */
45 #define REG_VOFFSET 0x2E /* V channel offset adjustment */
46 #define REG_ARRAY_BIAS 0x2F /* array bias -- don't change */
47 #define REG_YGAMMA 0x33 /* misc gamma settings [7:6] */
48 #define REG_BIAS_ADJUST 0x34 /* misc bias settings */
50 /* Window parameters */
63 /* Lawrence Glaister <lg@jfm.bc.ca> reports:
65 * Register 0x0f in the 7610 has the following effects:
67 * 0x85 (AEC method 1): Best overall, good contrast range
68 * 0x45 (AEC method 2): Very overexposed
69 * 0xa5 (spec sheet default): Ok, but the black level is
70 * shifted resulting in loss of contrast
71 * 0x05 (old driver setting): very overexposed, too much
74 static struct ovcamchip_regvals regvals_init_7x10[] = {
81 { 0x28, 0x24 }, /* 0c */
82 { 0x0f, 0x85 }, /* lg's setting */
102 { 0xff, 0xff }, /* END MARKER */
105 /* This initializes the OV7x10 camera chip and relevant variables. */
106 static int ov7x10_init(struct i2c_client *c)
108 struct ovcamchip *ov = i2c_get_clientdata(c);
112 DDEBUG(4, &c->dev, "entered");
114 rc = ov_write_regvals(c, regvals_init_7x10);
118 ov->spriv = s = kmalloc(sizeof *s, GFP_KERNEL);
121 memset(s, 0, sizeof *s);
129 static int ov7x10_free(struct i2c_client *c)
131 struct ovcamchip *ov = i2c_get_clientdata(c);
137 static int ov7x10_set_control(struct i2c_client *c,
138 struct ovcamchip_control *ctl)
140 struct ovcamchip *ov = i2c_get_clientdata(c);
141 struct ov7x10 *s = ov->spriv;
146 case OVCAMCHIP_CID_CONT:
147 rc = ov_write(c, REG_CNT, v >> 8);
149 case OVCAMCHIP_CID_BRIGHT:
150 rc = ov_write(c, REG_BRT, v >> 8);
152 case OVCAMCHIP_CID_SAT:
153 rc = ov_write(c, REG_SAT, v >> 8);
155 case OVCAMCHIP_CID_HUE:
156 rc = ov_write(c, REG_RED, 0xFF - (v >> 8));
160 rc = ov_write(c, REG_BLUE, v >> 8);
162 case OVCAMCHIP_CID_EXP:
163 rc = ov_write(c, REG_EXP, v);
165 case OVCAMCHIP_CID_FREQ:
167 int sixty = (v == 60);
169 rc = ov_write_mask(c, 0x2a, sixty?0x00:0x80, 0x80);
173 rc = ov_write(c, 0x2b, sixty?0x00:0xac);
177 rc = ov_write_mask(c, 0x13, 0x10, 0x10);
181 rc = ov_write_mask(c, 0x13, 0x00, 0x10);
184 case OVCAMCHIP_CID_BANDFILT:
185 rc = ov_write_mask(c, 0x2d, v?0x04:0x00, 0x04);
188 case OVCAMCHIP_CID_AUTOBRIGHT:
189 rc = ov_write_mask(c, 0x2d, v?0x10:0x00, 0x10);
192 case OVCAMCHIP_CID_AUTOEXP:
193 rc = ov_write_mask(c, 0x29, v?0x00:0x80, 0x80);
196 case OVCAMCHIP_CID_MIRROR:
197 rc = ov_write_mask(c, 0x12, v?0x40:0x00, 0x40);
201 DDEBUG(2, &c->dev, "control not supported: %d", ctl->id);
206 DDEBUG(3, &c->dev, "id=%d, arg=%d, rc=%d", ctl->id, v, rc);
210 static int ov7x10_get_control(struct i2c_client *c,
211 struct ovcamchip_control *ctl)
213 struct ovcamchip *ov = i2c_get_clientdata(c);
214 struct ov7x10 *s = ov->spriv;
216 unsigned char val = 0;
219 case OVCAMCHIP_CID_CONT:
220 rc = ov_read(c, REG_CNT, &val);
221 ctl->value = val << 8;
223 case OVCAMCHIP_CID_BRIGHT:
224 rc = ov_read(c, REG_BRT, &val);
225 ctl->value = val << 8;
227 case OVCAMCHIP_CID_SAT:
228 rc = ov_read(c, REG_SAT, &val);
229 ctl->value = val << 8;
231 case OVCAMCHIP_CID_HUE:
232 rc = ov_read(c, REG_BLUE, &val);
233 ctl->value = val << 8;
235 case OVCAMCHIP_CID_EXP:
236 rc = ov_read(c, REG_EXP, &val);
239 case OVCAMCHIP_CID_BANDFILT:
240 ctl->value = s->bandfilt;
242 case OVCAMCHIP_CID_AUTOBRIGHT:
243 ctl->value = s->auto_brt;
245 case OVCAMCHIP_CID_AUTOEXP:
246 ctl->value = s->auto_exp;
248 case OVCAMCHIP_CID_MIRROR:
249 ctl->value = s->mirror;
252 DDEBUG(2, &c->dev, "control not supported: %d", ctl->id);
256 DDEBUG(3, &c->dev, "id=%d, arg=%d, rc=%d", ctl->id, ctl->value, rc);
260 static int ov7x10_mode_init(struct i2c_client *c, struct ovcamchip_window *win)
262 int qvga = win->quarter;
264 /******** QVGA-specific regs ********/
266 ov_write(c, 0x14, qvga?0x24:0x04);
268 /******** Palette-specific regs ********/
270 if (win->format == VIDEO_PALETTE_GREY) {
271 ov_write_mask(c, 0x0e, 0x40, 0x40);
272 ov_write_mask(c, 0x13, 0x20, 0x20);
274 ov_write_mask(c, 0x0e, 0x00, 0x40);
275 ov_write_mask(c, 0x13, 0x00, 0x20);
278 /******** Clock programming ********/
280 ov_write(c, 0x11, win->clockdiv);
282 /******** Resolution-specific ********/
284 if (win->width == 640 && win->height == 480)
285 ov_write(c, 0x35, 0x9e);
287 ov_write(c, 0x35, 0x1e);
292 static int ov7x10_set_window(struct i2c_client *c, struct ovcamchip_window *win)
294 int ret, hwscale, vwscale;
296 ret = ov7x10_mode_init(c, win);
308 ov_write(c, 0x17, HWSBASE + (win->x >> hwscale));
309 ov_write(c, 0x18, HWEBASE + ((win->x + win->width) >> hwscale));
310 ov_write(c, 0x19, VWSBASE + (win->y >> vwscale));
311 ov_write(c, 0x1a, VWEBASE + ((win->y + win->height) >> vwscale));
316 static int ov7x10_command(struct i2c_client *c, unsigned int cmd, void *arg)
319 case OVCAMCHIP_CMD_S_CTRL:
320 return ov7x10_set_control(c, arg);
321 case OVCAMCHIP_CMD_G_CTRL:
322 return ov7x10_get_control(c, arg);
323 case OVCAMCHIP_CMD_S_MODE:
324 return ov7x10_set_window(c, arg);
326 DDEBUG(2, &c->dev, "command not supported: %d", cmd);
331 struct ovcamchip_ops ov7x10_ops = {
334 .command = ov7x10_command,