📄 ov511 v1.28.c
字号:
out += sprintf (out, "%s\n", plist[j].name); break; } } if (plist[j].num < 0) out += sprintf (out, "unknown\n"); out += sprintf (out, " segsize : %d\n", ov511->frame[i].segsize); out += sprintf (out, " data_buffer : 0x%p\n", ov511->frame[i].data); } out += sprintf (out, "snap_enabled : %s\n", YES_NO (ov511->snap_enabled)); out += sprintf (out, "bridge : %s\n", ov511->bridge == BRG_OV511 ? "OV511" : ov511->bridge == BRG_OV511PLUS ? "OV511+" : "unknown"); out += sprintf (out, "sensor : %s\n", ov511->sensor == SEN_OV6620 ? "OV6620" : ov511->sensor == SEN_OV7610 ? "OV7610" : ov511->sensor == SEN_OV7620 ? "OV7620" : ov511->sensor == SEN_OV7620AE ? "OV7620AE" : "unknown"); out += sprintf (out, "packet_size : %d\n", ov511->packet_size); out += sprintf (out, "framebuffer : 0x%p\n", ov511->fbuf); len = out - page; len -= off; if (len < count) { *eof = 1; if (len <= 0) return 0; } else len = count; *start = page + off; return len;}static int ov511_write_proc(struct file *file, const char *buffer, unsigned long count, void *data){ return -EINVAL;}static void create_proc_ov511_cam (struct usb_ov511 *ov511){ char name[7]; struct proc_dir_entry *ent; if (!ov511_proc_entry || !ov511) return; sprintf(name, "video%d", ov511->vdev.minor); PDEBUG (4, "creating /proc/video/ov511/%s", name); ent = create_proc_entry(name, S_IFREG|S_IRUGO|S_IWUSR, ov511_proc_entry); if (!ent) return; ent->data = ov511; ent->read_proc = ov511_read_proc; ent->write_proc = ov511_write_proc; ov511->proc_entry = ent;}static void destroy_proc_ov511_cam (struct usb_ov511 *ov511){ char name[7]; if (!ov511 || !ov511->proc_entry) return; sprintf(name, "video%d", ov511->vdev.minor); PDEBUG (4, "destroying %s", name); remove_proc_entry(name, ov511_proc_entry); ov511->proc_entry = NULL;}static void proc_ov511_create(void){ /* No current standard here. Alan prefers /proc/video/ as it keeps * /proc "less cluttered than /proc/randomcardifoundintheshed/" * -claudio */ if (video_proc_entry == NULL) { err("Unable to initialise /proc/video/ov511"); return; } ov511_proc_entry = create_proc_entry("ov511", S_IFDIR, video_proc_entry); if (ov511_proc_entry) ov511_proc_entry->owner = THIS_MODULE; else err("Unable to initialise /proc/ov511");}static void proc_ov511_destroy(void){ PDEBUG (3, "removing /proc/video/ov511"); if (ov511_proc_entry == NULL) return; remove_proc_entry("ov511", video_proc_entry);}#endif /* CONFIG_PROC_FS && CONFIG_VIDEO_PROC_FS *//********************************************************************** * * Camera interface * **********************************************************************/static int ov511_reg_write(struct usb_device *dev, unsigned char reg, unsigned char value){ int rc; rc = usb_control_msg(dev, usb_sndctrlpipe(dev, 0), 2 /* REG_IO */, USB_TYPE_CLASS | USB_RECIP_DEVICE, 0, (__u16)reg, &value, 1, HZ); PDEBUG(5, "reg write: 0x%02X:0x%02X, 0x%x", reg, value, rc); if (rc < 0) err("reg write: error %d", rc); return rc;}/* returns: negative is error, pos or zero is data */static int ov511_reg_read(struct usb_device *dev, unsigned char reg){ int rc; unsigned char buffer[1]; rc = usb_control_msg(dev, usb_rcvctrlpipe(dev, 0), 2 /* REG_IO */, USB_DIR_IN | USB_TYPE_CLASS | USB_RECIP_DEVICE, 0, (__u16)reg, buffer, 1, HZ); PDEBUG(5, "reg read: 0x%02X:0x%02X", reg, buffer[0]); if (rc < 0) { err("reg read: error %d", rc); return rc; } else { return buffer[0]; }}static int ov511_i2c_write(struct usb_device *dev, unsigned char reg, unsigned char value){ int rc, retries; PDEBUG(5, "i2c write: 0x%02X:0x%02X", reg, value); /* Three byte write cycle */ for (retries = OV511_I2C_RETRIES; ; ) { /* Select camera register */ rc = ov511_reg_write(dev, OV511_REG_I2C_SUB_ADDRESS_3_BYTE, reg); if (rc < 0) goto error; /* Write "value" to I2C data port of OV511 */ rc = ov511_reg_write(dev, OV511_REG_I2C_DATA_PORT, value); if (rc < 0) goto error; /* Initiate 3-byte write cycle */ rc = ov511_reg_write(dev, OV511_REG_I2C_CONTROL, 0x01); if (rc < 0) goto error; do rc = ov511_reg_read(dev, OV511_REG_I2C_CONTROL); while (rc > 0 && ((rc&1) == 0)); /* Retry until idle */ if (rc < 0) goto error; if ((rc&2) == 0) /* Ack? */ break;#if 0 /* I2C abort */ ov511_reg_write(dev, OV511_REG_I2C_CONTROL, 0x10);#endif if (--retries < 0) { err("i2c write retries exhausted"); rc = -1; goto error; } } return 0;error: err("i2c write: error %d", rc); return rc;}/* returns: negative is error, pos or zero is data */static int ov511_i2c_read(struct usb_device *dev, unsigned char reg){ int rc, value, retries; /* Two byte write cycle */ for (retries = OV511_I2C_RETRIES; ; ) { /* Select camera register */ rc = ov511_reg_write(dev, OV511_REG_I2C_SUB_ADDRESS_2_BYTE, reg); if (rc < 0) goto error; /* Initiate 2-byte write cycle */ rc = ov511_reg_write(dev, OV511_REG_I2C_CONTROL, 0x03); if (rc < 0) goto error; do rc = ov511_reg_read(dev, OV511_REG_I2C_CONTROL); while (rc > 0 && ((rc&1) == 0)); /* Retry until idle */ if (rc < 0) goto error; if ((rc&2) == 0) /* Ack? */ break; /* I2C abort */ ov511_reg_write(dev, OV511_REG_I2C_CONTROL, 0x10); if (--retries < 0) { err("i2c write retries exhausted"); rc = -1; goto error; } } /* Two byte read cycle */ for (retries = OV511_I2C_RETRIES; ; ) { /* Initiate 2-byte read cycle */ rc = ov511_reg_write(dev, OV511_REG_I2C_CONTROL, 0x05); if (rc < 0) goto error; do rc = ov511_reg_read(dev, OV511_REG_I2C_CONTROL); while (rc > 0 && ((rc&1) == 0)); /* Retry until idle */ if (rc < 0) goto error; if ((rc&2) == 0) /* Ack? */ break; /* I2C abort */ rc = ov511_reg_write(dev, OV511_REG_I2C_CONTROL, 0x10); if (rc < 0) goto error; if (--retries < 0) { err("i2c read retries exhausted"); rc = -1; goto error; } } value = ov511_reg_read(dev, OV511_REG_I2C_DATA_PORT); PDEBUG(5, "i2c read: 0x%02X:0x%02X", reg, value); /* This is needed to make ov511_i2c_write() work */ rc = ov511_reg_write(dev, OV511_REG_I2C_CONTROL, 0x05); if (rc < 0) goto error; return value;error: err("i2c read: error %d", rc); return rc;}static int ov511_write_regvals(struct usb_device *dev, struct ov511_regvals * pRegvals){ int rc; while (pRegvals->bus != OV511_DONE_BUS) { if (pRegvals->bus == OV511_REG_BUS) { if ((rc = ov511_reg_write(dev, pRegvals->reg, pRegvals->val)) < 0) goto error; } else if (pRegvals->bus == OV511_I2C_BUS) { if ((rc = ov511_i2c_write(dev, pRegvals->reg, pRegvals->val)) < 0) goto error; } else { err("Bad regval array"); rc = -1; goto error; } pRegvals++; } return 0;error: err("write regvals: error %d", rc); return rc;}#ifdef OV511_DEBUG static void ov511_dump_i2c_range(struct usb_device *dev, int reg1, int regn){ int i; int rc; for(i = reg1; i <= regn; i++) { rc = ov511_i2c_read(dev, i); PDEBUG(1, "OV7610[0x%X] = 0x%X", i, rc); }}static void ov511_dump_i2c_regs(struct usb_device *dev){ PDEBUG(3, "I2C REGS"); ov511_dump_i2c_range(dev, 0x00, 0x7C);}#if 0static void ov511_dump_reg_range(struct usb_device *dev, int reg1, int regn){ int i; int rc; for(i = reg1; i <= regn; i++) { rc = ov511_reg_read(dev, i); PDEBUG(1, "OV511[0x%X] = 0x%X", i, rc); }}static void ov511_dump_regs(struct usb_device *dev){ PDEBUG(1, "CAMERA INTERFACE REGS"); ov511_dump_reg_range(dev, 0x10, 0x1f); PDEBUG(1, "DRAM INTERFACE REGS"); ov511_dump_reg_range(dev, 0x20, 0x23); PDEBUG(1, "ISO FIFO REGS"); ov511_dump_reg_range(dev, 0x30, 0x31); PDEBUG(1, "PIO REGS"); ov511_dump_reg_range(dev, 0x38, 0x39); ov511_dump_reg_range(dev, 0x3e, 0x3e); PDEBUG(1, "I2C REGS"); ov511_dump_reg_range(dev, 0x40, 0x49); PDEBUG(1, "SYSTEM CONTROL REGS"); ov511_dump_reg_range(dev, 0x50, 0x55); ov511_dump_reg_range(dev, 0x5e, 0x5f); PDEBUG(1, "OmniCE REGS"); ov511_dump_reg_range(dev, 0x70, 0x79); ov511_dump_reg_range(dev, 0x80, 0x9f); ov511_dump_reg_range(dev, 0xa0, 0xbf);}#endif#endifstatic int ov511_reset(struct usb_device *dev, unsigned char reset_type){ int rc; PDEBUG(4, "Reset: type=0x%X", reset_type); rc = ov511_reg_write(dev, OV511_REG_SYSTEM_RESET, reset_type); rc = ov511_reg_write(dev, OV511_REG_SYSTEM_RESET, 0);
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -