Lines Matching refs:sd
23 #define Y_QUANTABLE (&sd->jpeg_hdr[JPEG_QT0_OFFSET])
24 #define UV_QUANTABLE (&sd->jpeg_hdr[JPEG_QT1_OFFSET])
49 static void reg_w(struct sd *sd, u16 index, u16 value);
55 static void w9968cf_write_fsb(struct sd *sd, u16* data)
57 struct usb_device *udev = sd->gspca_dev.dev;
61 if (sd->gspca_dev.usb_err < 0)
65 memcpy(sd->gspca_dev.usb_buf, data, 6);
71 value, 0x06, sd->gspca_dev.usb_buf, 6, 500);
74 sd->gspca_dev.usb_err = ret;
82 static void w9968cf_write_sb(struct sd *sd, u16 value)
86 if (sd->gspca_dev.usb_err < 0)
94 ret = usb_control_msg(sd->gspca_dev.dev,
95 usb_sndctrlpipe(sd->gspca_dev.dev, 0),
104 sd->gspca_dev.usb_err = ret;
112 static int w9968cf_read_sb(struct sd *sd)
116 if (sd->gspca_dev.usb_err < 0)
124 ret = usb_control_msg(sd->gspca_dev.dev,
125 usb_rcvctrlpipe(sd->gspca_dev.dev, 0),
128 0, 0x01, sd->gspca_dev.usb_buf, 2, 500);
130 ret = sd->gspca_dev.usb_buf[0] |
131 (sd->gspca_dev.usb_buf[1] << 8);
134 sd->gspca_dev.usb_err = ret;
139 memset(sd->gspca_dev.usb_buf, 0, 2);
152 static void w9968cf_upload_quantizationtables(struct sd *sd)
157 reg_w(sd, 0x39, 0x0010); /* JPEG clock enable */
162 reg_w(sd, 0x40 + i, a);
163 reg_w(sd, 0x60 + i, b);
165 reg_w(sd, 0x39, 0x0012); /* JPEG encoder enable */
176 static void w9968cf_smbus_start(struct sd *sd)
178 w9968cf_write_sb(sd, 0x0011); /* SDE=1, SDA=0, SCL=1 */
179 w9968cf_write_sb(sd, 0x0010); /* SDE=1, SDA=0, SCL=0 */
182 static void w9968cf_smbus_stop(struct sd *sd)
184 w9968cf_write_sb(sd, 0x0010); /* SDE=1, SDA=0, SCL=0 */
185 w9968cf_write_sb(sd, 0x0011); /* SDE=1, SDA=0, SCL=1 */
186 w9968cf_write_sb(sd, 0x0013); /* SDE=1, SDA=1, SCL=1 */
189 static void w9968cf_smbus_write_byte(struct sd *sd, u8 v)
198 w9968cf_write_sb(sd, 0x10 | sda);
200 w9968cf_write_sb(sd, 0x11 | sda);
202 w9968cf_write_sb(sd, 0x10 | sda);
206 static void w9968cf_smbus_read_byte(struct sd *sd, u8 *v)
216 w9968cf_write_sb(sd, 0x0013);
217 *v |= (w9968cf_read_sb(sd) & 0x0008) ? 1 : 0;
219 w9968cf_write_sb(sd, 0x0012);
223 static void w9968cf_smbus_write_nack(struct sd *sd)
227 w9968cf_write_sb(sd, 0x0013); /* SDE=1, SDA=1, SCL=1 */
228 w9968cf_write_sb(sd, 0x0012); /* SDE=1, SDA=1, SCL=0 */
231 static void w9968cf_smbus_read_ack(struct sd *sd)
233 struct gspca_dev *gspca_dev = (struct gspca_dev *)sd;
237 w9968cf_write_sb(sd, 0x0012); /* SDE=1, SDA=1, SCL=0 */
238 w9968cf_write_sb(sd, 0x0013); /* SDE=1, SDA=1, SCL=1 */
239 sda = w9968cf_read_sb(sd);
240 w9968cf_write_sb(sd, 0x0012); /* SDE=1, SDA=1, SCL=0 */
243 sd->gspca_dev.usb_err = -EIO;
248 static void w9968cf_i2c_w(struct sd *sd, u8 reg, u8 value)
250 struct gspca_dev *gspca_dev = (struct gspca_dev *)sd;
251 u16* data = (u16 *)sd->gspca_dev.usb_buf;
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);
278 w9968cf_write_fsb(sd, data);
292 w9968cf_write_fsb(sd, data);
298 static int w9968cf_i2c_r(struct sd *sd, u8 reg)
300 struct gspca_dev *gspca_dev = (struct gspca_dev *)sd;
305 w9968cf_write_sb(sd, 0x0013); /* don't change ! */
307 w9968cf_smbus_start(sd);
308 w9968cf_smbus_write_byte(sd, sd->sensor_addr);
309 w9968cf_smbus_read_ack(sd);
310 w9968cf_smbus_write_byte(sd, reg);
311 w9968cf_smbus_read_ack(sd);
312 w9968cf_smbus_stop(sd);
313 w9968cf_smbus_start(sd);
314 w9968cf_smbus_write_byte(sd, sd->sensor_addr + 1);
315 w9968cf_smbus_read_ack(sd);
316 w9968cf_smbus_read_byte(sd, &value);
320 w9968cf_smbus_write_nack(sd);
321 w9968cf_smbus_stop(sd);
324 w9968cf_write_sb(sd, 0x0030);
326 if (sd->gspca_dev.usb_err >= 0) {
340 static void w9968cf_configure(struct sd *sd)
342 reg_w(sd, 0x00, 0xff00); /* power-down */
343 reg_w(sd, 0x00, 0xbf17); /* reset everything */
344 reg_w(sd, 0x00, 0xbf10); /* normal operation */
345 reg_w(sd, 0x01, 0x0010); /* serial bus, SDS high */
346 reg_w(sd, 0x01, 0x0000); /* serial bus, SDS low */
347 reg_w(sd, 0x01, 0x0010); /* ..high 'beep-beep' */
348 reg_w(sd, 0x01, 0x0030); /* Set sda scl to FSB mode */
350 sd->stopped = 1;
353 static void w9968cf_init(struct sd *sd)
355 unsigned long hw_bufsize = sd->sif ? (352 * 288 * 2) : (640 * 480 * 2),
363 reg_w(sd, 0x00, 0xff00); /* power off */
364 reg_w(sd, 0x00, 0xbf10); /* power on */
366 reg_w(sd, 0x03, 0x405d); /* DRAM timings */
367 reg_w(sd, 0x04, 0x0030); /* SDRAM timings */
369 reg_w(sd, 0x20, y0 & 0xffff); /* Y buf.0, low */
370 reg_w(sd, 0x21, y0 >> 16); /* Y buf.0, high */
371 reg_w(sd, 0x24, u0 & 0xffff); /* U buf.0, low */
372 reg_w(sd, 0x25, u0 >> 16); /* U buf.0, high */
373 reg_w(sd, 0x28, v0 & 0xffff); /* V buf.0, low */
374 reg_w(sd, 0x29, v0 >> 16); /* V buf.0, high */
376 reg_w(sd, 0x22, y1 & 0xffff); /* Y buf.1, low */
377 reg_w(sd, 0x23, y1 >> 16); /* Y buf.1, high */
378 reg_w(sd, 0x26, u1 & 0xffff); /* U buf.1, low */
379 reg_w(sd, 0x27, u1 >> 16); /* U buf.1, high */
380 reg_w(sd, 0x2a, v1 & 0xffff); /* V buf.1, low */
381 reg_w(sd, 0x2b, v1 >> 16); /* V buf.1, high */
383 reg_w(sd, 0x32, y1 & 0xffff); /* JPEG buf 0 low */
384 reg_w(sd, 0x33, y1 >> 16); /* JPEG buf 0 high */
386 reg_w(sd, 0x34, y1 & 0xffff); /* JPEG buf 1 low */
387 reg_w(sd, 0x35, y1 >> 16); /* JPEG bug 1 high */
389 reg_w(sd, 0x36, 0x0000);/* JPEG restart interval */
390 reg_w(sd, 0x37, 0x0804);/*JPEG VLE FIFO threshold*/
391 reg_w(sd, 0x38, 0x0000);/* disable hw up-scaling */
392 reg_w(sd, 0x3f, 0x0000); /* JPEG/MCTL test data */
395 static void w9968cf_set_crop_window(struct sd *sd)
400 if (sd->sif) {
408 if (sd->sensor == SEN_OV7620) {
416 if (sd->freq->val == 1) {
432 fw = SC(sd->gspca_dev.pixfmt.width) / max_width;
433 fh = SC(sd->gspca_dev.pixfmt.height) / max_height;
435 cw = (fw >= fh) ? max_width : SC(sd->gspca_dev.pixfmt.width) / fh;
436 ch = (fw >= fh) ? SC(sd->gspca_dev.pixfmt.height) / fw : max_height;
438 sd->sensor_width = max_width;
439 sd->sensor_height = max_height;
444 reg_w(sd, 0x10, start_cropx + x);
445 reg_w(sd, 0x11, start_cropy + y);
446 reg_w(sd, 0x12, start_cropx + x + cw);
447 reg_w(sd, 0x13, start_cropy + y + ch);
450 static void w9968cf_mode_init_regs(struct sd *sd)
454 w9968cf_set_crop_window(sd);
456 reg_w(sd, 0x14, sd->gspca_dev.pixfmt.width);
457 reg_w(sd, 0x15, sd->gspca_dev.pixfmt.height);
460 reg_w(sd, 0x30, sd->gspca_dev.pixfmt.width);
461 reg_w(sd, 0x31, sd->gspca_dev.pixfmt.height);
464 if (w9968cf_vga_mode[sd->gspca_dev.curr_mode].pixelformat ==
466 reg_w(sd, 0x2c, sd->gspca_dev.pixfmt.width / 2);
467 reg_w(sd, 0x2d, sd->gspca_dev.pixfmt.width / 4);
469 reg_w(sd, 0x2c, sd->gspca_dev.pixfmt.width);
471 reg_w(sd, 0x00, 0xbf17); /* reset everything */
472 reg_w(sd, 0x00, 0xbf10); /* normal operation */
475 val = sd->gspca_dev.pixfmt.width * sd->gspca_dev.pixfmt.height;
476 reg_w(sd, 0x3d, val & 0xffff); /* low bits */
477 reg_w(sd, 0x3e, val >> 16); /* high bits */
479 if (w9968cf_vga_mode[sd->gspca_dev.curr_mode].pixelformat ==
482 jpeg_define(sd->jpeg_hdr, sd->gspca_dev.pixfmt.height,
483 sd->gspca_dev.pixfmt.width, 0x22); /* JPEG 420 */
484 jpeg_set_qual(sd->jpeg_hdr, v4l2_ctrl_g_ctrl(sd->jpegqual));
485 w9968cf_upload_quantizationtables(sd);
486 v4l2_ctrl_grab(sd->jpegqual, true);
490 if (sd->sensor == SEN_OV7620) {
505 if (w9968cf_vga_mode[sd->gspca_dev.curr_mode].pixelformat ==
518 reg_w(sd, 0x16, val);
520 sd->gspca_dev.empty_packet = 0;
523 static void w9968cf_stop0(struct sd *sd)
525 v4l2_ctrl_grab(sd->jpegqual, false);
526 reg_w(sd, 0x39, 0x0000); /* disable JPEG encoder */
527 reg_w(sd, 0x16, 0x0000); /* stop video capture */
542 struct sd *sd = (struct sd *) gspca_dev;
552 sd->jpeg_hdr, JPEG_HDR_SZ);