Lines Matching refs:sd
24 #define Y_QUANTABLE (&sd->jpeg_hdr[JPEG_QT0_OFFSET])
25 #define UV_QUANTABLE (&sd->jpeg_hdr[JPEG_QT1_OFFSET])
50 static void reg_w(struct sd *sd, u16 index, u16 value);
56 static void w9968cf_write_fsb(struct sd *sd, u16* data)
58 struct usb_device *udev = sd->gspca_dev.dev;
62 if (sd->gspca_dev.usb_err < 0)
66 memcpy(sd->gspca_dev.usb_buf, data, 6);
72 value, 0x06, sd->gspca_dev.usb_buf, 6, 500);
75 sd->gspca_dev.usb_err = ret;
83 static void w9968cf_write_sb(struct sd *sd, u16 value)
87 if (sd->gspca_dev.usb_err < 0)
95 ret = usb_control_msg(sd->gspca_dev.dev,
96 usb_sndctrlpipe(sd->gspca_dev.dev, 0),
105 sd->gspca_dev.usb_err = ret;
113 static int w9968cf_read_sb(struct sd *sd)
117 if (sd->gspca_dev.usb_err < 0)
125 ret = usb_control_msg(sd->gspca_dev.dev,
126 usb_rcvctrlpipe(sd->gspca_dev.dev, 0),
129 0, 0x01, sd->gspca_dev.usb_buf, 2, 500);
131 ret = sd->gspca_dev.usb_buf[0] |
132 (sd->gspca_dev.usb_buf[1] << 8);
135 sd->gspca_dev.usb_err = ret;
140 memset(sd->gspca_dev.usb_buf, 0, 2);
153 static void w9968cf_upload_quantizationtables(struct sd *sd)
158 reg_w(sd, 0x39, 0x0010); /* JPEG clock enable */
163 reg_w(sd, 0x40 + i, a);
164 reg_w(sd, 0x60 + i, b);
166 reg_w(sd, 0x39, 0x0012); /* JPEG encoder enable */
177 static void w9968cf_smbus_start(struct sd *sd)
179 w9968cf_write_sb(sd, 0x0011); /* SDE=1, SDA=0, SCL=1 */
180 w9968cf_write_sb(sd, 0x0010); /* SDE=1, SDA=0, SCL=0 */
183 static void w9968cf_smbus_stop(struct sd *sd)
185 w9968cf_write_sb(sd, 0x0010); /* SDE=1, SDA=0, SCL=0 */
186 w9968cf_write_sb(sd, 0x0011); /* SDE=1, SDA=0, SCL=1 */
187 w9968cf_write_sb(sd, 0x0013); /* SDE=1, SDA=1, SCL=1 */
190 static void w9968cf_smbus_write_byte(struct sd *sd, u8 v)
199 w9968cf_write_sb(sd, 0x10 | sda);
201 w9968cf_write_sb(sd, 0x11 | sda);
203 w9968cf_write_sb(sd, 0x10 | sda);
207 static void w9968cf_smbus_read_byte(struct sd *sd, u8 *v)
217 w9968cf_write_sb(sd, 0x0013);
218 *v |= (w9968cf_read_sb(sd) & 0x0008) ? 1 : 0;
220 w9968cf_write_sb(sd, 0x0012);
224 static void w9968cf_smbus_write_nack(struct sd *sd)
228 w9968cf_write_sb(sd, 0x0013); /* SDE=1, SDA=1, SCL=1 */
229 w9968cf_write_sb(sd, 0x0012); /* SDE=1, SDA=1, SCL=0 */
232 static void w9968cf_smbus_read_ack(struct sd *sd)
234 struct gspca_dev *gspca_dev = (struct gspca_dev *)sd;
238 w9968cf_write_sb(sd, 0x0012); /* SDE=1, SDA=1, SCL=0 */
239 w9968cf_write_sb(sd, 0x0013); /* SDE=1, SDA=1, SCL=1 */
240 sda = w9968cf_read_sb(sd);
241 w9968cf_write_sb(sd, 0x0012); /* SDE=1, SDA=1, SCL=0 */
244 sd->gspca_dev.usb_err = -EIO;
249 static void w9968cf_i2c_w(struct sd *sd, u8 reg, u8 value)
251 struct gspca_dev *gspca_dev = (struct gspca_dev *)sd;
252 u16* data = (u16 *)sd->gspca_dev.usb_buf;
254 data[0] = 0x082f | ((sd->sensor_addr & 0x80) ? 0x1500 : 0x0);
255 data[0] |= (sd->sensor_addr & 0x40) ? 0x4000 : 0x0;
256 data[1] = 0x2082 | ((sd->sensor_addr & 0x40) ? 0x0005 : 0x0);
257 data[1] |= (sd->sensor_addr & 0x20) ? 0x0150 : 0x0;
258 data[1] |= (sd->sensor_addr & 0x10) ? 0x5400 : 0x0;
259 data[2] = 0x8208 | ((sd->sensor_addr & 0x08) ? 0x0015 : 0x0);
260 data[2] |= (sd->sensor_addr & 0x04) ? 0x0540 : 0x0;
261 data[2] |= (sd->sensor_addr & 0x02) ? 0x5000 : 0x0;
262 data[3] = 0x1d20 | ((sd->sensor_addr & 0x02) ? 0x0001 : 0x0);
263 data[3] |= (sd->sensor_addr & 0x01) ? 0x0054 : 0x0;
265 w9968cf_write_fsb(sd, data);
279 w9968cf_write_fsb(sd, data);
293 w9968cf_write_fsb(sd, data);
299 static int w9968cf_i2c_r(struct sd *sd, u8 reg)
301 struct gspca_dev *gspca_dev = (struct gspca_dev *)sd;
306 w9968cf_write_sb(sd, 0x0013); /* don't change ! */
308 w9968cf_smbus_start(sd);
309 w9968cf_smbus_write_byte(sd, sd->sensor_addr);
310 w9968cf_smbus_read_ack(sd);
311 w9968cf_smbus_write_byte(sd, reg);
312 w9968cf_smbus_read_ack(sd);
313 w9968cf_smbus_stop(sd);
314 w9968cf_smbus_start(sd);
315 w9968cf_smbus_write_byte(sd, sd->sensor_addr + 1);
316 w9968cf_smbus_read_ack(sd);
317 w9968cf_smbus_read_byte(sd, &value);
321 w9968cf_smbus_write_nack(sd);
322 w9968cf_smbus_stop(sd);
325 w9968cf_write_sb(sd, 0x0030);
327 if (sd->gspca_dev.usb_err >= 0) {
341 static void w9968cf_configure(struct sd *sd)
343 reg_w(sd, 0x00, 0xff00); /* power-down */
344 reg_w(sd, 0x00, 0xbf17); /* reset everything */
345 reg_w(sd, 0x00, 0xbf10); /* normal operation */
346 reg_w(sd, 0x01, 0x0010); /* serial bus, SDS high */
347 reg_w(sd, 0x01, 0x0000); /* serial bus, SDS low */
348 reg_w(sd, 0x01, 0x0010); /* ..high 'beep-beep' */
349 reg_w(sd, 0x01, 0x0030); /* Set sda scl to FSB mode */
351 sd->stopped = 1;
354 static void w9968cf_init(struct sd *sd)
356 unsigned long hw_bufsize = sd->sif ? (352 * 288 * 2) : (640 * 480 * 2),
364 reg_w(sd, 0x00, 0xff00); /* power off */
365 reg_w(sd, 0x00, 0xbf10); /* power on */
367 reg_w(sd, 0x03, 0x405d); /* DRAM timings */
368 reg_w(sd, 0x04, 0x0030); /* SDRAM timings */
370 reg_w(sd, 0x20, y0 & 0xffff); /* Y buf.0, low */
371 reg_w(sd, 0x21, y0 >> 16); /* Y buf.0, high */
372 reg_w(sd, 0x24, u0 & 0xffff); /* U buf.0, low */
373 reg_w(sd, 0x25, u0 >> 16); /* U buf.0, high */
374 reg_w(sd, 0x28, v0 & 0xffff); /* V buf.0, low */
375 reg_w(sd, 0x29, v0 >> 16); /* V buf.0, high */
377 reg_w(sd, 0x22, y1 & 0xffff); /* Y buf.1, low */
378 reg_w(sd, 0x23, y1 >> 16); /* Y buf.1, high */
379 reg_w(sd, 0x26, u1 & 0xffff); /* U buf.1, low */
380 reg_w(sd, 0x27, u1 >> 16); /* U buf.1, high */
381 reg_w(sd, 0x2a, v1 & 0xffff); /* V buf.1, low */
382 reg_w(sd, 0x2b, v1 >> 16); /* V buf.1, high */
384 reg_w(sd, 0x32, y1 & 0xffff); /* JPEG buf 0 low */
385 reg_w(sd, 0x33, y1 >> 16); /* JPEG buf 0 high */
387 reg_w(sd, 0x34, y1 & 0xffff); /* JPEG buf 1 low */
388 reg_w(sd, 0x35, y1 >> 16); /* JPEG bug 1 high */
390 reg_w(sd, 0x36, 0x0000);/* JPEG restart interval */
391 reg_w(sd, 0x37, 0x0804);/*JPEG VLE FIFO threshold*/
392 reg_w(sd, 0x38, 0x0000);/* disable hw up-scaling */
393 reg_w(sd, 0x3f, 0x0000); /* JPEG/MCTL test data */
396 static void w9968cf_set_crop_window(struct sd *sd)
401 if (sd->sif) {
409 if (sd->sensor == SEN_OV7620) {
417 if (sd->freq->val == 1) {
433 fw = SC(sd->gspca_dev.pixfmt.width) / max_width;
434 fh = SC(sd->gspca_dev.pixfmt.height) / max_height;
436 cw = (fw >= fh) ? max_width : SC(sd->gspca_dev.pixfmt.width) / fh;
437 ch = (fw >= fh) ? SC(sd->gspca_dev.pixfmt.height) / fw : max_height;
439 sd->sensor_width = max_width;
440 sd->sensor_height = max_height;
445 reg_w(sd, 0x10, start_cropx + x);
446 reg_w(sd, 0x11, start_cropy + y);
447 reg_w(sd, 0x12, start_cropx + x + cw);
448 reg_w(sd, 0x13, start_cropy + y + ch);
451 static void w9968cf_mode_init_regs(struct sd *sd)
455 w9968cf_set_crop_window(sd);
457 reg_w(sd, 0x14, sd->gspca_dev.pixfmt.width);
458 reg_w(sd, 0x15, sd->gspca_dev.pixfmt.height);
461 reg_w(sd, 0x30, sd->gspca_dev.pixfmt.width);
462 reg_w(sd, 0x31, sd->gspca_dev.pixfmt.height);
465 if (w9968cf_vga_mode[sd->gspca_dev.curr_mode].pixelformat ==
467 reg_w(sd, 0x2c, sd->gspca_dev.pixfmt.width / 2);
468 reg_w(sd, 0x2d, sd->gspca_dev.pixfmt.width / 4);
470 reg_w(sd, 0x2c, sd->gspca_dev.pixfmt.width);
472 reg_w(sd, 0x00, 0xbf17); /* reset everything */
473 reg_w(sd, 0x00, 0xbf10); /* normal operation */
476 val = sd->gspca_dev.pixfmt.width * sd->gspca_dev.pixfmt.height;
477 reg_w(sd, 0x3d, val & 0xffff); /* low bits */
478 reg_w(sd, 0x3e, val >> 16); /* high bits */
480 if (w9968cf_vga_mode[sd->gspca_dev.curr_mode].pixelformat ==
483 jpeg_define(sd->jpeg_hdr, sd->gspca_dev.pixfmt.height,
484 sd->gspca_dev.pixfmt.width, 0x22); /* JPEG 420 */
485 jpeg_set_qual(sd->jpeg_hdr, v4l2_ctrl_g_ctrl(sd->jpegqual));
486 w9968cf_upload_quantizationtables(sd);
487 v4l2_ctrl_grab(sd->jpegqual, true);
491 if (sd->sensor == SEN_OV7620) {
506 if (w9968cf_vga_mode[sd->gspca_dev.curr_mode].pixelformat ==
519 reg_w(sd, 0x16, val);
521 sd->gspca_dev.empty_packet = 0;
524 static void w9968cf_stop0(struct sd *sd)
526 v4l2_ctrl_grab(sd->jpegqual, false);
527 reg_w(sd, 0x39, 0x0000); /* disable JPEG encoder */
528 reg_w(sd, 0x16, 0x0000); /* stop video capture */
543 struct sd *sd = (struct sd *) gspca_dev;
553 sd->jpeg_hdr, JPEG_HDR_SZ);