1 /* OmniVision OV76BE Camera Chip Support Code
3 * Copyright (c) 1999-2004 Mark McClelland <mark@alpha.dyndns.org>
4 * http://alpha.dyndns.org/ov511/
6 * This program is free software; you can redistribute it and/or modify it
7 * under the terms of the GNU General Public License as published by the
8 * Free Software Foundation; either version 2 of the License, or (at your
9 * option) any later version. NO WARRANTY OF ANY KIND is expressed or implied.
14 #include <linux/slab.h>
15 #include "ovcamchip_priv.h"
17 /* OV7610 registers: Since the OV76BE is undocumented, we'll settle for these
19 #define REG_GAIN 0x00 /* gain [5:0] */
20 #define REG_BLUE 0x01 /* blue channel balance */
21 #define REG_RED 0x02 /* red channel balance */
22 #define REG_SAT 0x03 /* saturation */
23 #define REG_CNT 0x05 /* Y contrast */
24 #define REG_BRT 0x06 /* Y brightness */
25 #define REG_BLUE_BIAS 0x0C /* blue channel bias [5:0] */
26 #define REG_RED_BIAS 0x0D /* red channel bias [5:0] */
27 #define REG_GAMMA_COEFF 0x0E /* gamma settings */
28 #define REG_WB_RANGE 0x0F /* AEC/ALC/S-AWB settings */
29 #define REG_EXP 0x10 /* manual exposure setting */
30 #define REG_CLOCK 0x11 /* polarity/clock prescaler */
31 #define REG_FIELD_DIVIDE 0x16 /* field interval/mode settings */
32 #define REG_HWIN_START 0x17 /* horizontal window start */
33 #define REG_HWIN_END 0x18 /* horizontal window end */
34 #define REG_VWIN_START 0x19 /* vertical window start */
35 #define REG_VWIN_END 0x1A /* vertical window end */
36 #define REG_PIXEL_SHIFT 0x1B /* pixel shift */
37 #define REG_YOFFSET 0x21 /* Y channel offset */
38 #define REG_UOFFSET 0x22 /* U channel offset */
39 #define REG_ECW 0x24 /* exposure white level for AEC */
40 #define REG_ECB 0x25 /* exposure black level for AEC */
41 #define REG_FRAMERATE_H 0x2A /* frame rate MSB + misc */
42 #define REG_FRAMERATE_L 0x2B /* frame rate LSB */
43 #define REG_ALC 0x2C /* Auto Level Control settings */
44 #define REG_VOFFSET 0x2E /* V channel offset adjustment */
45 #define REG_ARRAY_BIAS 0x2F /* array bias -- don't change */
46 #define REG_YGAMMA 0x33 /* misc gamma settings [7:6] */
47 #define REG_BIAS_ADJUST 0x34 /* misc bias settings */
49 /* Window parameters */
62 /* NOTE: These are the same as the 7x10 settings, but should eventually be
63 * optimized for the OV76BE */
64 static struct ovcamchip_regvals regvals_init_76be
[] = {
71 { 0x28, 0x24 }, /* 0c */
72 { 0x0f, 0x85 }, /* lg's setting */
92 { 0xff, 0xff }, /* END MARKER */
95 /* This initializes the OV76be camera chip and relevant variables. */
96 static int ov76be_init(struct i2c_client
*c
)
98 struct ovcamchip
*ov
= i2c_get_clientdata(c
);
102 DDEBUG(4, &c
->dev
, "entered");
104 rc
= ov_write_regvals(c
, regvals_init_76be
);
108 ov
->spriv
= s
= kmalloc(sizeof *s
, GFP_KERNEL
);
111 memset(s
, 0, sizeof *s
);
119 static int ov76be_free(struct i2c_client
*c
)
121 struct ovcamchip
*ov
= i2c_get_clientdata(c
);
127 static int ov76be_set_control(struct i2c_client
*c
,
128 struct ovcamchip_control
*ctl
)
130 struct ovcamchip
*ov
= i2c_get_clientdata(c
);
131 struct ov76be
*s
= ov
->spriv
;
136 case OVCAMCHIP_CID_BRIGHT
:
137 rc
= ov_write(c
, REG_BRT
, v
>> 8);
139 case OVCAMCHIP_CID_SAT
:
140 rc
= ov_write(c
, REG_SAT
, v
>> 8);
142 case OVCAMCHIP_CID_EXP
:
143 rc
= ov_write(c
, REG_EXP
, v
);
145 case OVCAMCHIP_CID_FREQ
:
147 int sixty
= (v
== 60);
149 rc
= ov_write_mask(c
, 0x2a, sixty
?0x00:0x80, 0x80);
153 rc
= ov_write(c
, 0x2b, sixty
?0x00:0xac);
157 rc
= ov_write_mask(c
, 0x76, 0x01, 0x01);
160 case OVCAMCHIP_CID_BANDFILT
:
161 rc
= ov_write_mask(c
, 0x2d, v
?0x04:0x00, 0x04);
164 case OVCAMCHIP_CID_AUTOBRIGHT
:
165 rc
= ov_write_mask(c
, 0x2d, v
?0x10:0x00, 0x10);
168 case OVCAMCHIP_CID_AUTOEXP
:
169 rc
= ov_write_mask(c
, 0x13, v
?0x01:0x00, 0x01);
172 case OVCAMCHIP_CID_MIRROR
:
173 rc
= ov_write_mask(c
, 0x12, v
?0x40:0x00, 0x40);
177 DDEBUG(2, &c
->dev
, "control not supported: %d", ctl
->id
);
182 DDEBUG(3, &c
->dev
, "id=%d, arg=%d, rc=%d", ctl
->id
, v
, rc
);
186 static int ov76be_get_control(struct i2c_client
*c
,
187 struct ovcamchip_control
*ctl
)
189 struct ovcamchip
*ov
= i2c_get_clientdata(c
);
190 struct ov76be
*s
= ov
->spriv
;
192 unsigned char val
= 0;
195 case OVCAMCHIP_CID_BRIGHT
:
196 rc
= ov_read(c
, REG_BRT
, &val
);
197 ctl
->value
= val
<< 8;
199 case OVCAMCHIP_CID_SAT
:
200 rc
= ov_read(c
, REG_SAT
, &val
);
201 ctl
->value
= val
<< 8;
203 case OVCAMCHIP_CID_EXP
:
204 rc
= ov_read(c
, REG_EXP
, &val
);
207 case OVCAMCHIP_CID_BANDFILT
:
208 ctl
->value
= s
->bandfilt
;
210 case OVCAMCHIP_CID_AUTOBRIGHT
:
211 ctl
->value
= s
->auto_brt
;
213 case OVCAMCHIP_CID_AUTOEXP
:
214 ctl
->value
= s
->auto_exp
;
216 case OVCAMCHIP_CID_MIRROR
:
217 ctl
->value
= s
->mirror
;
220 DDEBUG(2, &c
->dev
, "control not supported: %d", ctl
->id
);
224 DDEBUG(3, &c
->dev
, "id=%d, arg=%d, rc=%d", ctl
->id
, ctl
->value
, rc
);
228 static int ov76be_mode_init(struct i2c_client
*c
, struct ovcamchip_window
*win
)
230 int qvga
= win
->quarter
;
232 /******** QVGA-specific regs ********/
234 ov_write(c
, 0x14, qvga
?0xa4:0x84);
236 /******** Palette-specific regs ********/
238 if (win
->format
== VIDEO_PALETTE_GREY
) {
239 ov_write_mask(c
, 0x0e, 0x40, 0x40);
240 ov_write_mask(c
, 0x13, 0x20, 0x20);
242 ov_write_mask(c
, 0x0e, 0x00, 0x40);
243 ov_write_mask(c
, 0x13, 0x00, 0x20);
246 /******** Clock programming ********/
248 ov_write(c
, 0x11, win
->clockdiv
);
250 /******** Resolution-specific ********/
252 if (win
->width
== 640 && win
->height
== 480)
253 ov_write(c
, 0x35, 0x9e);
255 ov_write(c
, 0x35, 0x1e);
260 static int ov76be_set_window(struct i2c_client
*c
, struct ovcamchip_window
*win
)
262 int ret
, hwscale
, vwscale
;
264 ret
= ov76be_mode_init(c
, win
);
276 ov_write(c
, 0x17, HWSBASE
+ (win
->x
>> hwscale
));
277 ov_write(c
, 0x18, HWEBASE
+ ((win
->x
+ win
->width
) >> hwscale
));
278 ov_write(c
, 0x19, VWSBASE
+ (win
->y
>> vwscale
));
279 ov_write(c
, 0x1a, VWEBASE
+ ((win
->y
+ win
->height
) >> vwscale
));
284 static int ov76be_command(struct i2c_client
*c
, unsigned int cmd
, void *arg
)
287 case OVCAMCHIP_CMD_S_CTRL
:
288 return ov76be_set_control(c
, arg
);
289 case OVCAMCHIP_CMD_G_CTRL
:
290 return ov76be_get_control(c
, arg
);
291 case OVCAMCHIP_CMD_S_MODE
:
292 return ov76be_set_window(c
, arg
);
294 DDEBUG(2, &c
->dev
, "command not supported: %d", cmd
);
299 struct ovcamchip_ops ov76be_ops
= {
302 .command
= ov76be_command
,