sonixj.c
来自「trident tm5600的linux驱动」· C语言 代码 · 共 1,721 行 · 第 1/4 页
C
1,721 行
case SENSOR_MO4000: mo4000_InitSensor(gspca_dev); if (mode) {/* reg1 = 0x46; * 320 clk 48Mhz 60fp/s */ reg1 = 0x06; /* clk 24Mz */ } else { reg17 = 0x22; /* 640 MCKSIZE *//* reg1 = 0x06; * 640 clk 24Mz (done) */ } break; case SENSOR_OM6802: om6802_InitSensor(gspca_dev); reg17 = 0x64; /* 640 MCKSIZE */ break; case SENSOR_OV7630: ov7630_InitSensor(gspca_dev); setvflip(sd); reg17 = 0xe2; reg1 = 0x44; break; case SENSOR_OV7648: ov7648_InitSensor(gspca_dev); reg17 = 0xa2; reg1 = 0x44;/* if (mode) ; * 320x2... else ; * 640x... */ break; default:/* case SENSOR_OV7660: */ ov7660_InitSensor(gspca_dev); if (mode) {/* reg17 = 0x21; * 320 *//* reg1 = 0x44; *//* reg1 = 0x46; (done) */ } else { reg17 = 0xa2; /* 640 */ reg1 = 0x44; } break; } reg_w(gspca_dev, 0xc0, C0, 6); reg_w(gspca_dev, 0xca, CA, 4); switch (sd->sensor) { case SENSOR_OV7630: case SENSOR_OV7648: case SENSOR_OV7660: reg_w(gspca_dev, 0xce, CE_ov76xx, 4); break; default: reg_w(gspca_dev, 0xce, CE, 4); /* ?? {0x1e, 0xdd, 0x2d, 0xe7} */ break; } /* here change size mode 0 -> VGA; 1 -> CIF */ reg18 = sn9c1xx[0x18] | (mode << 4); reg_w1(gspca_dev, 0x18, reg18 | 0x40); reg_w(gspca_dev, 0x100, qtable4, 0x40); reg_w(gspca_dev, 0x140, qtable4 + 0x40, 0x40); reg_w1(gspca_dev, 0x18, reg18); reg_w1(gspca_dev, 0x17, reg17); switch (sd->sensor) { case SENSOR_HV7131R: case SENSOR_MI0360: case SENSOR_MO4000: case SENSOR_OM6802: setbrightness(gspca_dev); setcontrast(gspca_dev); break; case SENSOR_OV7630: setvflip(sd); /* fall thru */ default: /* OV76xx */ setbrightcont(gspca_dev); break; } setautogain(gspca_dev); reg_w1(gspca_dev, 0x01, reg1); return 0;}static void sd_stopN(struct gspca_dev *gspca_dev){ struct sd *sd = (struct sd *) gspca_dev; static const __u8 stophv7131[] = { 0xa1, 0x11, 0x02, 0x09, 0x00, 0x00, 0x00, 0x10 }; static const __u8 stopmi0360[] = { 0xb1, 0x5d, 0x07, 0x00, 0x00, 0x00, 0x00, 0x10 }; __u8 data; const __u8 *sn9c1xx; data = 0x0b; switch (sd->sensor) { case SENSOR_HV7131R: i2c_w8(gspca_dev, stophv7131); data = 0x2b; break; case SENSOR_MI0360: i2c_w8(gspca_dev, stopmi0360); data = 0x29; break; case SENSOR_OV7630: case SENSOR_OV7648: data = 0x29; break; default:/* case SENSOR_MO4000: *//* case SENSOR_OV7660: */ break; } sn9c1xx = sn_tb[(int) sd->sensor]; reg_w1(gspca_dev, 0x01, sn9c1xx[1]); reg_w1(gspca_dev, 0x17, sn9c1xx[0x17]); reg_w1(gspca_dev, 0x01, sn9c1xx[1]); reg_w1(gspca_dev, 0x01, data); reg_w1(gspca_dev, 0xf1, 0x00);}static void do_autogain(struct gspca_dev *gspca_dev){ struct sd *sd = (struct sd *) gspca_dev; int delta; int expotimes; __u8 luma_mean = 130; __u8 luma_delta = 20; /* Thanks S., without your advice, autobright should not work :) */ if (sd->ag_cnt < 0) return; if (--sd->ag_cnt >= 0) return; sd->ag_cnt = AG_CNT_START; delta = atomic_read(&sd->avg_lum); PDEBUG(D_FRAM, "mean lum %d", delta); if (delta < luma_mean - luma_delta || delta > luma_mean + luma_delta) { switch (sd->sensor) { case SENSOR_HV7131R: expotimes = sd->exposure >> 8; expotimes += (luma_mean - delta) >> 4; if (expotimes < 0) expotimes = 0; sd->exposure = setexposure(gspca_dev, (unsigned int) (expotimes << 8)); break; default:/* case SENSOR_MO4000: *//* case SENSOR_MI0360: *//* case SENSOR_OM6802: */ expotimes = sd->exposure; expotimes += (luma_mean - delta) >> 6; if (expotimes < 0) expotimes = 0; sd->exposure = setexposure(gspca_dev, (unsigned int) expotimes); setcolors(gspca_dev); break; } }}/* scan the URB packets *//* This function is run at interrupt level. */static void sd_pkt_scan(struct gspca_dev *gspca_dev, struct gspca_frame *frame, /* target */ __u8 *data, /* isoc packet */ int len) /* iso packet length */{ struct sd *sd = (struct sd *) gspca_dev; int sof, avg_lum; sof = len - 64; if (sof >= 0 && data[sof] == 0xff && data[sof + 1] == 0xd9) { /* end of frame */ gspca_frame_add(gspca_dev, LAST_PACKET, frame, data, sof + 2); if (sd->ag_cnt < 0) return;/* w1 w2 w3 *//* w4 w5 w6 *//* w7 w8 *//* w4 */ avg_lum = ((data[sof + 29] << 8) | data[sof + 30]) >> 6;/* w6 */ avg_lum += ((data[sof + 33] << 8) | data[sof + 34]) >> 6;/* w2 */ avg_lum += ((data[sof + 25] << 8) | data[sof + 26]) >> 6;/* w8 */ avg_lum += ((data[sof + 37] << 8) | data[sof + 38]) >> 6;/* w5 */ avg_lum += ((data[sof + 31] << 8) | data[sof + 32]) >> 4; avg_lum >>= 4; atomic_set(&sd->avg_lum, avg_lum); return; } if (gspca_dev->last_packet_type == LAST_PACKET) { /* put the JPEG 422 header */ jpeg_put_header(gspca_dev, frame, sd->qindex, 0x21); } gspca_frame_add(gspca_dev, INTER_PACKET, frame, data, len);}static int sd_setbrightness(struct gspca_dev *gspca_dev, __s32 val){ struct sd *sd = (struct sd *) gspca_dev; sd->brightness = val; if (gspca_dev->streaming) { switch (sd->sensor) { case SENSOR_HV7131R: case SENSOR_MI0360: case SENSOR_MO4000: case SENSOR_OM6802: setbrightness(gspca_dev); break; default: /* OV76xx */ setbrightcont(gspca_dev); break; } } return 0;}static int sd_getbrightness(struct gspca_dev *gspca_dev, __s32 *val){ struct sd *sd = (struct sd *) gspca_dev; *val = sd->brightness; return 0;}static int sd_setcontrast(struct gspca_dev *gspca_dev, __s32 val){ struct sd *sd = (struct sd *) gspca_dev; sd->contrast = val; if (gspca_dev->streaming) { switch (sd->sensor) { case SENSOR_HV7131R: case SENSOR_MI0360: case SENSOR_MO4000: case SENSOR_OM6802: setcontrast(gspca_dev); break; default: /* OV76xx */ setbrightcont(gspca_dev); break; } } return 0;}static int sd_getcontrast(struct gspca_dev *gspca_dev, __s32 *val){ struct sd *sd = (struct sd *) gspca_dev; *val = sd->contrast; return 0;}static int sd_setcolors(struct gspca_dev *gspca_dev, __s32 val){ struct sd *sd = (struct sd *) gspca_dev; sd->colors = val; if (gspca_dev->streaming) setcolors(gspca_dev); return 0;}static int sd_getcolors(struct gspca_dev *gspca_dev, __s32 *val){ struct sd *sd = (struct sd *) gspca_dev; *val = sd->colors; return 0;}static int sd_setautogain(struct gspca_dev *gspca_dev, __s32 val){ struct sd *sd = (struct sd *) gspca_dev; sd->autogain = val; if (gspca_dev->streaming) setautogain(gspca_dev); return 0;}static int sd_getautogain(struct gspca_dev *gspca_dev, __s32 *val){ struct sd *sd = (struct sd *) gspca_dev; *val = sd->autogain; return 0;}static int sd_setvflip(struct gspca_dev *gspca_dev, __s32 val){ struct sd *sd = (struct sd *) gspca_dev; sd->vflip = val; if (gspca_dev->streaming) setvflip(sd); return 0;}static int sd_getvflip(struct gspca_dev *gspca_dev, __s32 *val){ struct sd *sd = (struct sd *) gspca_dev; *val = sd->vflip; return 0;}/* sub-driver description */static const struct sd_desc sd_desc = { .name = MODULE_NAME, .ctrls = sd_ctrls, .nctrls = ARRAY_SIZE(sd_ctrls), .config = sd_config, .init = sd_init, .start = sd_start, .stopN = sd_stopN, .pkt_scan = sd_pkt_scan, .dq_callback = do_autogain,};/* -- module initialisation -- */#define BSI(bridge, sensor, i2c_addr) \ .driver_info = (BRIDGE_ ## bridge << 16) \ | (SENSOR_ ## sensor << 8) \ | (i2c_addr)static const __devinitdata struct usb_device_id device_table[] = {#if !defined CONFIG_USB_SN9C102 && !defined CONFIG_USB_SN9C102_MODULE {USB_DEVICE(0x0458, 0x7025), BSI(SN9C120, MI0360, 0x5d)}, {USB_DEVICE(0x0458, 0x702e), BSI(SN9C120, OV7660, 0x21)}, {USB_DEVICE(0x045e, 0x00f5), BSI(SN9C105, OV7660, 0x21)}, {USB_DEVICE(0x045e, 0x00f7), BSI(SN9C105, OV7660, 0x21)}, {USB_DEVICE(0x0471, 0x0327), BSI(SN9C105, MI0360, 0x5d)}, {USB_DEVICE(0x0471, 0x0328), BSI(SN9C105, MI0360, 0x5d)},#endif {USB_DEVICE(0x0471, 0x0330), BSI(SN9C105, MI0360, 0x5d)}, {USB_DEVICE(0x0c45, 0x6040), BSI(SN9C102P, HV7131R, 0x11)},/* bw600.inf: {USB_DEVICE(0x0c45, 0x6040), BSI(SN9C102P, MI0360, 0x5d)}, *//* {USB_DEVICE(0x0c45, 0x603a), BSI(SN9C102P, OV7648, 0x??)}, *//* {USB_DEVICE(0x0c45, 0x607a), BSI(SN9C102P, OV7648, 0x??)}, */ {USB_DEVICE(0x0c45, 0x607c), BSI(SN9C102P, HV7131R, 0x11)},/* {USB_DEVICE(0x0c45, 0x607e), BSI(SN9C102P, OV7630, 0x??)}, */ {USB_DEVICE(0x0c45, 0x60c0), BSI(SN9C105, MI0360, 0x5d)},/* {USB_DEVICE(0x0c45, 0x60c8), BSI(SN9C105, OM6801, 0x??)}, *//* {USB_DEVICE(0x0c45, 0x60cc), BSI(SN9C105, HV7131GP, 0x??)}, */ {USB_DEVICE(0x0c45, 0x60ec), BSI(SN9C105, MO4000, 0x21)},/* {USB_DEVICE(0x0c45, 0x60ef), BSI(SN9C105, ICM105C, 0x??)}, *//* {USB_DEVICE(0x0c45, 0x60fa), BSI(SN9C105, OV7648, 0x??)}, */ {USB_DEVICE(0x0c45, 0x60fb), BSI(SN9C105, OV7660, 0x21)}, {USB_DEVICE(0x0c45, 0x60fc), BSI(SN9C105, HV7131R, 0x11)},#if !defined CONFIG_USB_SN9C102 && !defined CONFIG_USB_SN9C102_MODULE {USB_DEVICE(0x0c45, 0x60fe), BSI(SN9C105, OV7630, 0x21)},#endif/* {USB_DEVICE(0x0c45, 0x6108), BSI(SN9C120, OM6801, 0x??)}, *//* {USB_DEVICE(0x0c45, 0x6122), BSI(SN9C110, ICM105C, 0x??)}, *//* {USB_DEVICE(0x0c45, 0x6123), BSI(SN9C110, SanyoCCD, 0x??)}, */ {USB_DEVICE(0x0c45, 0x6128), BSI(SN9C110, OM6802, 0x21)}, /*sn9c325?*//*bw600.inf:*/ {USB_DEVICE(0x0c45, 0x612a), BSI(SN9C110, OV7648, 0x21)}, /*sn9c325?*/ {USB_DEVICE(0x0c45, 0x612c), BSI(SN9C110, MO4000, 0x21)}, {USB_DEVICE(0x0c45, 0x612e), BSI(SN9C110, OV7630, 0x21)},/* {USB_DEVICE(0x0c45, 0x612f), BSI(SN9C110, ICM105C, 0x??)}, */#if !defined CONFIG_USB_SN9C102 && !defined CONFIG_USB_SN9C102_MODULE {USB_DEVICE(0x0c45, 0x6130), BSI(SN9C120, MI0360, 0x5d)},#endif {USB_DEVICE(0x0c45, 0x6138), BSI(SN9C120, MO4000, 0x21)},#if !defined CONFIG_USB_SN9C102 && !defined CONFIG_USB_SN9C102_MODULE/* {USB_DEVICE(0x0c45, 0x613a), BSI(SN9C120, OV7648, 0x??)}, */ {USB_DEVICE(0x0c45, 0x613b), BSI(SN9C120, OV7660, 0x21)}, {USB_DEVICE(0x0c45, 0x613c), BSI(SN9C120, HV7131R, 0x11)},/* {USB_DEVICE(0x0c45, 0x613e), BSI(SN9C120, OV7630, 0x??)}, */#endif {USB_DEVICE(0x0c45, 0x6143), BSI(SN9C120, MI0360, 0x5d)}, {}};MODULE_DEVICE_TABLE(usb, device_table);/* -- device connect -- */static int sd_probe(struct usb_interface *intf, const struct usb_device_id *id){ return gspca_dev_probe(intf, id, &sd_desc, sizeof(struct sd), THIS_MODULE);}static struct usb_driver sd_driver = { .name = MODULE_NAME, .id_table = device_table, .probe = sd_probe, .disconnect = gspca_disconnect,#ifdef CONFIG_PM .suspend = gspca_suspend, .resume = gspca_resume,#endif};/* -- module insert / remove -- */static int __init sd_mod_init(void){ if (usb_register(&sd_driver) < 0) return -1; info("registered"); return 0;}static void __exit sd_mod_exit(void){ usb_deregister(&sd_driver); info("deregistered");}module_init(sd_mod_init);module_exit(sd_mod_exit);
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?