1 /* OmniVision OV6630/OV6130 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"
18 #define REG_GAIN 0x00 /* gain [5:0] */
19 #define REG_BLUE 0x01 /* blue gain */
20 #define REG_RED 0x02 /* red gain */
21 #define REG_SAT 0x03 /* saturation [7:3] */
22 #define REG_CNT 0x05 /* Y contrast [3:0] */
23 #define REG_BRT 0x06 /* Y brightness */
24 #define REG_SHARP 0x07 /* sharpness */
25 #define REG_WB_BLUE 0x0C /* WB blue ratio [5:0] */
26 #define REG_WB_RED 0x0D /* WB red ratio [5:0] */
27 #define REG_EXP 0x10 /* exposure */
29 /* Window parameters */
43 static struct ovcamchip_regvals regvals_init_6x30
[] = {
44 { 0x12, 0x80 }, /* reset */
45 { 0x00, 0x1f }, /* Gain */
46 { 0x01, 0x99 }, /* Blue gain */
47 { 0x02, 0x7c }, /* Red gain */
48 { 0x03, 0xc0 }, /* Saturation */
49 { 0x05, 0x0a }, /* Contrast */
50 { 0x06, 0x95 }, /* Brightness */
51 { 0x07, 0x2d }, /* Sharpness */
56 { 0x10, 0x9a }, /* "exposure check" */
57 { 0x11, 0x00 }, /* Pixel clock = fastest */
58 { 0x12, 0x24 }, /* Enable AGC and AWB */
73 { 0x23, 0xc0 }, /* Crystal circuit power level */
74 { 0x25, 0x9a }, /* Increase AEC black pixel ratio */
75 { 0x26, 0xb2 }, /* BLC enable */
79 { 0x2a, 0x84 }, /* (keep) */
80 { 0x2b, 0xa8 }, /* (keep) */
82 { 0x2d, 0x95 }, /* Enable auto-brightness */
96 { 0x40, 0x00 }, /* White bal */
97 { 0x41, 0x00 }, /* White bal */
99 { 0x43, 0x3f }, /* White bal */
109 { 0x4d, 0x10 }, /* U = 0.563u, V = 0.714v */
111 { 0x4f, 0x07 }, /* UV average mode, color killer: strongest */
113 { 0x54, 0x23 }, /* Max AGC gain: 18dB */
116 { 0x57, 0x81 }, /* (default) */
118 { 0x59, 0x01 }, /* AGC dark current compensation: +1 */
120 { 0x5b, 0x0f }, /* AWB chrominance levels */
124 /* Toggle AWB off and on */
128 { 0xff, 0xff }, /* END MARKER */
131 /* This initializes the OV6x30 camera chip and relevant variables. */
132 static int ov6x30_init(struct i2c_client
*c
)
134 struct ovcamchip
*ov
= i2c_get_clientdata(c
);
138 DDEBUG(4, &c
->dev
, "entered");
140 rc
= ov_write_regvals(c
, regvals_init_6x30
);
144 ov
->spriv
= s
= kmalloc(sizeof *s
, GFP_KERNEL
);
147 memset(s
, 0, sizeof *s
);
155 static int ov6x30_free(struct i2c_client
*c
)
157 struct ovcamchip
*ov
= i2c_get_clientdata(c
);
163 static int ov6x30_set_control(struct i2c_client
*c
,
164 struct ovcamchip_control
*ctl
)
166 struct ovcamchip
*ov
= i2c_get_clientdata(c
);
167 struct ov6x30
*s
= ov
->spriv
;
172 case OVCAMCHIP_CID_CONT
:
173 rc
= ov_write_mask(c
, REG_CNT
, v
>> 12, 0x0f);
175 case OVCAMCHIP_CID_BRIGHT
:
176 rc
= ov_write(c
, REG_BRT
, v
>> 8);
178 case OVCAMCHIP_CID_SAT
:
179 rc
= ov_write(c
, REG_SAT
, v
>> 8);
181 case OVCAMCHIP_CID_HUE
:
182 rc
= ov_write(c
, REG_RED
, 0xFF - (v
>> 8));
186 rc
= ov_write(c
, REG_BLUE
, v
>> 8);
188 case OVCAMCHIP_CID_EXP
:
189 rc
= ov_write(c
, REG_EXP
, v
);
191 case OVCAMCHIP_CID_FREQ
:
193 int sixty
= (v
== 60);
195 rc
= ov_write(c
, 0x2b, sixty
?0xa8:0x28);
199 rc
= ov_write(c
, 0x2a, sixty
?0x84:0xa4);
202 case OVCAMCHIP_CID_BANDFILT
:
203 rc
= ov_write_mask(c
, 0x2d, v
?0x04:0x00, 0x04);
206 case OVCAMCHIP_CID_AUTOBRIGHT
:
207 rc
= ov_write_mask(c
, 0x2d, v
?0x10:0x00, 0x10);
210 case OVCAMCHIP_CID_AUTOEXP
:
211 rc
= ov_write_mask(c
, 0x28, v
?0x00:0x10, 0x10);
214 case OVCAMCHIP_CID_BACKLIGHT
:
216 rc
= ov_write_mask(c
, 0x4e, v
?0x80:0x60, 0xe0);
220 rc
= ov_write_mask(c
, 0x29, v
?0x08:0x00, 0x08);
224 rc
= ov_write_mask(c
, 0x28, v
?0x02:0x00, 0x02);
228 case OVCAMCHIP_CID_MIRROR
:
229 rc
= ov_write_mask(c
, 0x12, v
?0x40:0x00, 0x40);
233 DDEBUG(2, &c
->dev
, "control not supported: %d", ctl
->id
);
238 DDEBUG(3, &c
->dev
, "id=%d, arg=%d, rc=%d", ctl
->id
, v
, rc
);
242 static int ov6x30_get_control(struct i2c_client
*c
,
243 struct ovcamchip_control
*ctl
)
245 struct ovcamchip
*ov
= i2c_get_clientdata(c
);
246 struct ov6x30
*s
= ov
->spriv
;
248 unsigned char val
= 0;
251 case OVCAMCHIP_CID_CONT
:
252 rc
= ov_read(c
, REG_CNT
, &val
);
253 ctl
->value
= (val
& 0x0f) << 12;
255 case OVCAMCHIP_CID_BRIGHT
:
256 rc
= ov_read(c
, REG_BRT
, &val
);
257 ctl
->value
= val
<< 8;
259 case OVCAMCHIP_CID_SAT
:
260 rc
= ov_read(c
, REG_SAT
, &val
);
261 ctl
->value
= val
<< 8;
263 case OVCAMCHIP_CID_HUE
:
264 rc
= ov_read(c
, REG_BLUE
, &val
);
265 ctl
->value
= val
<< 8;
267 case OVCAMCHIP_CID_EXP
:
268 rc
= ov_read(c
, REG_EXP
, &val
);
271 case OVCAMCHIP_CID_BANDFILT
:
272 ctl
->value
= s
->bandfilt
;
274 case OVCAMCHIP_CID_AUTOBRIGHT
:
275 ctl
->value
= s
->auto_brt
;
277 case OVCAMCHIP_CID_AUTOEXP
:
278 ctl
->value
= s
->auto_exp
;
280 case OVCAMCHIP_CID_BACKLIGHT
:
281 ctl
->value
= s
->backlight
;
283 case OVCAMCHIP_CID_MIRROR
:
284 ctl
->value
= s
->mirror
;
287 DDEBUG(2, &c
->dev
, "control not supported: %d", ctl
->id
);
291 DDEBUG(3, &c
->dev
, "id=%d, arg=%d, rc=%d", ctl
->id
, ctl
->value
, rc
);
295 static int ov6x30_mode_init(struct i2c_client
*c
, struct ovcamchip_window
*win
)
297 /******** QCIF-specific regs ********/
299 ov_write_mask(c
, 0x14, win
->quarter
?0x20:0x00, 0x20);
301 /******** Palette-specific regs ********/
303 if (win
->format
== VIDEO_PALETTE_GREY
) {
304 if (c
->adapter
->id
== (I2C_ALGO_SMBUS
| I2C_HW_SMBUS_OV518
)) {
305 /* Do nothing - we're already in 8-bit mode */
307 ov_write_mask(c
, 0x13, 0x20, 0x20);
310 /* The OV518 needs special treatment. Although both the OV518
311 * and the OV6630 support a 16-bit video bus, only the 8 bit Y
312 * bus is actually used. The UV bus is tied to ground.
313 * Therefore, the OV6630 needs to be in 8-bit multiplexed
316 if (c
->adapter
->id
== (I2C_ALGO_SMBUS
| I2C_HW_SMBUS_OV518
)) {
317 /* Do nothing - we want to stay in 8-bit mode */
318 /* Warning: Messing with reg 0x13 breaks OV518 color */
320 ov_write_mask(c
, 0x13, 0x00, 0x20);
324 /******** Clock programming ********/
326 ov_write(c
, 0x11, win
->clockdiv
);
331 static int ov6x30_set_window(struct i2c_client
*c
, struct ovcamchip_window
*win
)
333 int ret
, hwscale
, vwscale
;
335 ret
= ov6x30_mode_init(c
, win
);
344 vwscale
= 1; /* The datasheet says 0; it's wrong */
347 ov_write(c
, 0x17, HWSBASE
+ (win
->x
>> hwscale
));
348 ov_write(c
, 0x18, HWEBASE
+ ((win
->x
+ win
->width
) >> hwscale
));
349 ov_write(c
, 0x19, VWSBASE
+ (win
->y
>> vwscale
));
350 ov_write(c
, 0x1a, VWEBASE
+ ((win
->y
+ win
->height
) >> vwscale
));
355 static int ov6x30_command(struct i2c_client
*c
, unsigned int cmd
, void *arg
)
358 case OVCAMCHIP_CMD_S_CTRL
:
359 return ov6x30_set_control(c
, arg
);
360 case OVCAMCHIP_CMD_G_CTRL
:
361 return ov6x30_get_control(c
, arg
);
362 case OVCAMCHIP_CMD_S_MODE
:
363 return ov6x30_set_window(c
, arg
);
365 DDEBUG(2, &c
->dev
, "command not supported: %d", cmd
);
370 struct ovcamchip_ops ov6x30_ops
= {
373 .command
= ov6x30_command
,