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 = kzalloc(sizeof *s, GFP_KERNEL);
154 static int ov6x30_free(struct i2c_client *c)
156 struct ovcamchip *ov = i2c_get_clientdata(c);
162 static int ov6x30_set_control(struct i2c_client *c,
163 struct ovcamchip_control *ctl)
165 struct ovcamchip *ov = i2c_get_clientdata(c);
166 struct ov6x30 *s = ov->spriv;
171 case OVCAMCHIP_CID_CONT:
172 rc = ov_write_mask(c, REG_CNT, v >> 12, 0x0f);
174 case OVCAMCHIP_CID_BRIGHT:
175 rc = ov_write(c, REG_BRT, v >> 8);
177 case OVCAMCHIP_CID_SAT:
178 rc = ov_write(c, REG_SAT, v >> 8);
180 case OVCAMCHIP_CID_HUE:
181 rc = ov_write(c, REG_RED, 0xFF - (v >> 8));
185 rc = ov_write(c, REG_BLUE, v >> 8);
187 case OVCAMCHIP_CID_EXP:
188 rc = ov_write(c, REG_EXP, v);
190 case OVCAMCHIP_CID_FREQ:
192 int sixty = (v == 60);
194 rc = ov_write(c, 0x2b, sixty?0xa8:0x28);
198 rc = ov_write(c, 0x2a, sixty?0x84:0xa4);
201 case OVCAMCHIP_CID_BANDFILT:
202 rc = ov_write_mask(c, 0x2d, v?0x04:0x00, 0x04);
205 case OVCAMCHIP_CID_AUTOBRIGHT:
206 rc = ov_write_mask(c, 0x2d, v?0x10:0x00, 0x10);
209 case OVCAMCHIP_CID_AUTOEXP:
210 rc = ov_write_mask(c, 0x28, v?0x00:0x10, 0x10);
213 case OVCAMCHIP_CID_BACKLIGHT:
215 rc = ov_write_mask(c, 0x4e, v?0x80:0x60, 0xe0);
219 rc = ov_write_mask(c, 0x29, v?0x08:0x00, 0x08);
223 rc = ov_write_mask(c, 0x28, v?0x02:0x00, 0x02);
227 case OVCAMCHIP_CID_MIRROR:
228 rc = ov_write_mask(c, 0x12, v?0x40:0x00, 0x40);
232 DDEBUG(2, &c->dev, "control not supported: %d", ctl->id);
237 DDEBUG(3, &c->dev, "id=%d, arg=%d, rc=%d", ctl->id, v, rc);
241 static int ov6x30_get_control(struct i2c_client *c,
242 struct ovcamchip_control *ctl)
244 struct ovcamchip *ov = i2c_get_clientdata(c);
245 struct ov6x30 *s = ov->spriv;
247 unsigned char val = 0;
250 case OVCAMCHIP_CID_CONT:
251 rc = ov_read(c, REG_CNT, &val);
252 ctl->value = (val & 0x0f) << 12;
254 case OVCAMCHIP_CID_BRIGHT:
255 rc = ov_read(c, REG_BRT, &val);
256 ctl->value = val << 8;
258 case OVCAMCHIP_CID_SAT:
259 rc = ov_read(c, REG_SAT, &val);
260 ctl->value = val << 8;
262 case OVCAMCHIP_CID_HUE:
263 rc = ov_read(c, REG_BLUE, &val);
264 ctl->value = val << 8;
266 case OVCAMCHIP_CID_EXP:
267 rc = ov_read(c, REG_EXP, &val);
270 case OVCAMCHIP_CID_BANDFILT:
271 ctl->value = s->bandfilt;
273 case OVCAMCHIP_CID_AUTOBRIGHT:
274 ctl->value = s->auto_brt;
276 case OVCAMCHIP_CID_AUTOEXP:
277 ctl->value = s->auto_exp;
279 case OVCAMCHIP_CID_BACKLIGHT:
280 ctl->value = s->backlight;
282 case OVCAMCHIP_CID_MIRROR:
283 ctl->value = s->mirror;
286 DDEBUG(2, &c->dev, "control not supported: %d", ctl->id);
290 DDEBUG(3, &c->dev, "id=%d, arg=%d, rc=%d", ctl->id, ctl->value, rc);
294 static int ov6x30_mode_init(struct i2c_client *c, struct ovcamchip_window *win)
296 /******** QCIF-specific regs ********/
298 ov_write_mask(c, 0x14, win->quarter?0x20:0x00, 0x20);
300 /******** Palette-specific regs ********/
302 if (win->format == VIDEO_PALETTE_GREY) {
303 if (c->adapter->id == I2C_HW_SMBUS_OV518) {
304 /* Do nothing - we're already in 8-bit mode */
306 ov_write_mask(c, 0x13, 0x20, 0x20);
309 /* The OV518 needs special treatment. Although both the OV518
310 * and the OV6630 support a 16-bit video bus, only the 8 bit Y
311 * bus is actually used. The UV bus is tied to ground.
312 * Therefore, the OV6630 needs to be in 8-bit multiplexed
315 if (c->adapter->id == I2C_HW_SMBUS_OV518) {
316 /* Do nothing - we want to stay in 8-bit mode */
317 /* Warning: Messing with reg 0x13 breaks OV518 color */
319 ov_write_mask(c, 0x13, 0x00, 0x20);
323 /******** Clock programming ********/
325 ov_write(c, 0x11, win->clockdiv);
330 static int ov6x30_set_window(struct i2c_client *c, struct ovcamchip_window *win)
332 int ret, hwscale, vwscale;
334 ret = ov6x30_mode_init(c, win);
343 vwscale = 1; /* The datasheet says 0; it's wrong */
346 ov_write(c, 0x17, HWSBASE + (win->x >> hwscale));
347 ov_write(c, 0x18, HWEBASE + ((win->x + win->width) >> hwscale));
348 ov_write(c, 0x19, VWSBASE + (win->y >> vwscale));
349 ov_write(c, 0x1a, VWEBASE + ((win->y + win->height) >> vwscale));
354 static int ov6x30_command(struct i2c_client *c, unsigned int cmd, void *arg)
357 case OVCAMCHIP_CMD_S_CTRL:
358 return ov6x30_set_control(c, arg);
359 case OVCAMCHIP_CMD_G_CTRL:
360 return ov6x30_get_control(c, arg);
361 case OVCAMCHIP_CMD_S_MODE:
362 return ov6x30_set_window(c, arg);
364 DDEBUG(2, &c->dev, "command not supported: %d", cmd);
369 struct ovcamchip_ops ov6x30_ops = {
372 .command = ov6x30_command,