34 #define pr_fmt(fmt) KBUILD_MODNAME ": " fmt
36 #define W9968CF_I2C_BUS_DELAY 4
38 #define Y_QUANTABLE (&sd->jpeg_hdr[JPEG_QT0_OFFSET])
39 #define UV_QUANTABLE (&sd->jpeg_hdr[JPEG_QT1_OFFSET])
43 .bytesperline = 160 * 2,
44 .sizeimage = 160 * 120 * 2,
47 .bytesperline = 176 * 2,
48 .sizeimage = 176 * 144 * 2,
51 .bytesperline = 320 * 2,
52 .sizeimage = 320 * 240 * 2,
55 .bytesperline = 352 * 2,
56 .sizeimage = 352 * 288 * 2,
59 .bytesperline = 640 * 2,
60 .sizeimage = 640 * 480 * 2,
70 static void w9968cf_write_fsb(
struct sd *
sd,
u16*
data)
84 value, 0x06, sd->
gspca_dev.usb_buf, 6, 500);
86 pr_err(
"Write FSB registers failed (%d)\n", ret);
95 static void w9968cf_write_sb(
struct sd *sd,
u16 value)
108 value, 0x01,
NULL, 0, 500);
113 pr_err(
"Write SB reg [01] %04x failed\n", value);
122 static int w9968cf_read_sb(
struct sd *sd)
140 pr_err(
"Read SB reg [01] failed\n");
154 static void w9968cf_upload_quantizationtables(
struct sd *sd)
159 reg_w(sd, 0x39, 0x0010);
161 for (i = 0, j = 0; i < 32; i++, j += 2) {
164 reg_w(sd, 0x40 + i, a);
165 reg_w(sd, 0x60 + i, b);
167 reg_w(sd, 0x39, 0x0012);
178 static void w9968cf_smbus_start(
struct sd *sd)
180 w9968cf_write_sb(sd, 0x0011);
181 w9968cf_write_sb(sd, 0x0010);
184 static void w9968cf_smbus_stop(
struct sd *sd)
186 w9968cf_write_sb(sd, 0x0010);
187 w9968cf_write_sb(sd, 0x0011);
188 w9968cf_write_sb(sd, 0x0013);
191 static void w9968cf_smbus_write_byte(
struct sd *sd,
u8 v)
196 for (bit = 0 ; bit < 8 ; bit++) {
197 sda = (v & 0x80) ? 2 : 0;
200 w9968cf_write_sb(sd, 0x10 | sda);
202 w9968cf_write_sb(sd, 0x11 | sda);
204 w9968cf_write_sb(sd, 0x10 | sda);
208 static void w9968cf_smbus_read_byte(
struct sd *sd,
u8 *v)
215 for (bit = 0 ; bit < 8 ; bit++) {
218 w9968cf_write_sb(sd, 0x0013);
219 *v |= (w9968cf_read_sb(sd) & 0x0008) ? 1 : 0;
221 w9968cf_write_sb(sd, 0x0012);
225 static void w9968cf_smbus_write_nack(
struct sd *sd)
229 w9968cf_write_sb(sd, 0x0013);
230 w9968cf_write_sb(sd, 0x0012);
233 static void w9968cf_smbus_read_ack(
struct sd *sd)
238 w9968cf_write_sb(sd, 0x0012);
239 w9968cf_write_sb(sd, 0x0013);
240 sda = w9968cf_read_sb(sd);
241 w9968cf_write_sb(sd, 0x0012);
242 if (sda >= 0 && (sda & 0x08)) {
243 PDEBUG(D_USBI,
"Did not receive i2c ACK");
249 static void w9968cf_i2c_w(
struct sd *sd,
u8 reg,
u8 value)
253 data[0] = 0x082f | ((sd->
sensor_addr & 0x80) ? 0x1500 : 0x0);
254 data[0] |= (sd->
sensor_addr & 0x40) ? 0x4000 : 0x0;
255 data[1] = 0x2082 | ((sd->
sensor_addr & 0x40) ? 0x0005 : 0x0);
256 data[1] |= (sd->
sensor_addr & 0x20) ? 0x0150 : 0x0;
257 data[1] |= (sd->
sensor_addr & 0x10) ? 0x5400 : 0x0;
258 data[2] = 0x8208 | ((sd->
sensor_addr & 0x08) ? 0x0015 : 0x0);
259 data[2] |= (sd->
sensor_addr & 0x04) ? 0x0540 : 0x0;
260 data[2] |= (sd->
sensor_addr & 0x02) ? 0x5000 : 0x0;
261 data[3] = 0x1d20 | ((sd->
sensor_addr & 0x02) ? 0x0001 : 0x0);
262 data[3] |= (sd->
sensor_addr & 0x01) ? 0x0054 : 0x0;
264 w9968cf_write_fsb(sd, data);
266 data[0] = 0x8208 | ((reg & 0x80) ? 0x0015 : 0x0);
267 data[0] |= (reg & 0x40) ? 0x0540 : 0x0;
268 data[0] |= (reg & 0x20) ? 0x5000 : 0x0;
269 data[1] = 0x0820 | ((reg & 0x20) ? 0x0001 : 0x0);
270 data[1] |= (reg & 0x10) ? 0x0054 : 0x0;
271 data[1] |= (reg & 0x08) ? 0x1500 : 0x0;
272 data[1] |= (reg & 0x04) ? 0x4000 : 0x0;
273 data[2] = 0x2082 | ((reg & 0x04) ? 0x0005 : 0x0);
274 data[2] |= (reg & 0x02) ? 0x0150 : 0x0;
275 data[2] |= (reg & 0x01) ? 0x5400 : 0x0;
278 w9968cf_write_fsb(sd, data);
280 data[0] = 0x8208 | ((value & 0x80) ? 0x0015 : 0x0);
281 data[0] |= (value & 0x40) ? 0x0540 : 0x0;
282 data[0] |= (value & 0x20) ? 0x5000 : 0x0;
283 data[1] = 0x0820 | ((value & 0x20) ? 0x0001 : 0x0);
284 data[1] |= (value & 0x10) ? 0x0054 : 0x0;
285 data[1] |= (value & 0x08) ? 0x1500 : 0x0;
286 data[1] |= (value & 0x04) ? 0x4000 : 0x0;
287 data[2] = 0x2082 | ((value & 0x04) ? 0x0005 : 0x0);
288 data[2] |= (value & 0x02) ? 0x0150 : 0x0;
289 data[2] |= (value & 0x01) ? 0x5400 : 0x0;
292 w9968cf_write_fsb(sd, data);
294 PDEBUG(D_USBO,
"i2c 0x%02x -> [0x%02x]", value, reg);
298 static int w9968cf_i2c_r(
struct sd *sd,
u8 reg)
304 w9968cf_write_sb(sd, 0x0013);
306 w9968cf_smbus_start(sd);
308 w9968cf_smbus_read_ack(sd);
309 w9968cf_smbus_write_byte(sd, reg);
310 w9968cf_smbus_read_ack(sd);
311 w9968cf_smbus_stop(sd);
312 w9968cf_smbus_start(sd);
314 w9968cf_smbus_read_ack(sd);
315 w9968cf_smbus_read_byte(sd, &value);
319 w9968cf_smbus_write_nack(sd);
320 w9968cf_smbus_stop(sd);
323 w9968cf_write_sb(sd, 0x0030);
327 PDEBUG(D_USBI,
"i2c [0x%02X] -> 0x%02X", reg, value);
338 static void w9968cf_configure(
struct sd *sd)
340 reg_w(sd, 0x00, 0xff00);
341 reg_w(sd, 0x00, 0xbf17);
342 reg_w(sd, 0x00, 0xbf10);
343 reg_w(sd, 0x01, 0x0010);
344 reg_w(sd, 0x01, 0x0000);
345 reg_w(sd, 0x01, 0x0010);
346 reg_w(sd, 0x01, 0x0030);
351 static void w9968cf_init(
struct sd *sd)
353 unsigned long hw_bufsize = sd->
sif ? (352 * 288 * 2) : (640 * 480 * 2),
355 u0 = y0 + hw_bufsize / 2,
356 v0 = u0 + hw_bufsize / 4,
357 y1 =
v0 + hw_bufsize / 4,
358 u1 = y1 + hw_bufsize / 2,
359 v1 = u1 + hw_bufsize / 4;
361 reg_w(sd, 0x00, 0xff00);
362 reg_w(sd, 0x00, 0xbf10);
364 reg_w(sd, 0x03, 0x405d);
365 reg_w(sd, 0x04, 0x0030);
367 reg_w(sd, 0x20, y0 & 0xffff);
368 reg_w(sd, 0x21, y0 >> 16);
369 reg_w(sd, 0x24, u0 & 0xffff);
370 reg_w(sd, 0x25, u0 >> 16);
371 reg_w(sd, 0x28,
v0 & 0xffff);
372 reg_w(sd, 0x29,
v0 >> 16);
374 reg_w(sd, 0x22, y1 & 0xffff);
375 reg_w(sd, 0x23, y1 >> 16);
376 reg_w(sd, 0x26, u1 & 0xffff);
377 reg_w(sd, 0x27, u1 >> 16);
378 reg_w(sd, 0x2a,
v1 & 0xffff);
379 reg_w(sd, 0x2b,
v1 >> 16);
381 reg_w(sd, 0x32, y1 & 0xffff);
382 reg_w(sd, 0x33, y1 >> 16);
384 reg_w(sd, 0x34, y1 & 0xffff);
385 reg_w(sd, 0x35, y1 >> 16);
387 reg_w(sd, 0x36, 0x0000);
388 reg_w(sd, 0x37, 0x0804);
389 reg_w(sd, 0x38, 0x0000);
390 reg_w(sd, 0x3f, 0x0000);
393 static void w9968cf_set_crop_window(
struct sd *sd)
395 int start_cropx, start_cropy,
x,
y,
fw, fh, cw, ch,
414 if (sd->
freq->val == 1) {
427 #define SC(x) ((x) << 10)
433 cw = (fw >= fh) ? max_width :
SC(sd->
gspca_dev.width) / fh;
439 x = (max_width - cw) / 2;
440 y = (max_height - ch) / 2;
442 reg_w(sd, 0x10, start_cropx + x);
443 reg_w(sd, 0x11, start_cropy + y);
444 reg_w(sd, 0x12, start_cropx + x + cw);
445 reg_w(sd, 0x13, start_cropy + y + ch);
448 static void w9968cf_mode_init_regs(
struct sd *sd)
450 int val, vs_polarity, hs_polarity;
452 w9968cf_set_crop_window(sd);
464 reg_w(sd, 0x2c, sd->
gspca_dev.width / 2);
465 reg_w(sd, 0x2d, sd->
gspca_dev.width / 4);
469 reg_w(sd, 0x00, 0xbf17);
470 reg_w(sd, 0x00, 0xbf10);
474 reg_w(sd, 0x3d, val & 0xffff);
475 reg_w(sd, 0x3e, val >> 16);
483 w9968cf_upload_quantizationtables(sd);
497 val = (vs_polarity << 12) | (hs_polarity << 11);
516 reg_w(sd, 0x16, val);
521 static void w9968cf_stop0(
struct sd *sd)
524 reg_w(sd, 0x39, 0x0000);
525 reg_w(sd, 0x16, 0x0000);
540 struct sd *sd = (
struct sd *) gspca_dev;