📄 zc3xx.c
字号:
/* * Z-Star/Vimicro zc301/zc302p/vc30x library * Copyright (C) 2004 2005 2006 Michel Xhaard * mxhaard@magic.fr * * V4L2 by Jean-Francois Moine <http://moinejf.free.fr> * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation; either version 2 of the License, or * (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program; if not, write to the Free Software * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. */#define MODULE_NAME "zc3xx"#include "gspca.h"MODULE_AUTHOR("Michel Xhaard <mxhaard@users.sourceforge.net>, " "Serge A. Suchkov <Serge.A.S@tochka.ru>");MODULE_DESCRIPTION("GSPCA ZC03xx/VC3xx USB Camera Driver");MODULE_LICENSE("GPL");static int force_sensor = -1;#include "jpeg.h"#include "zc3xx-reg.h"/* specific webcam descriptor */struct sd { struct gspca_dev gspca_dev; /* !! must be the first item */ __u8 brightness; __u8 contrast; __u8 gamma; __u8 autogain; __u8 lightfreq; __u8 sharpness; char qindex; signed char sensor; /* Type of image sensor chip *//* !! values used in different tables */#define SENSOR_CS2102 0#define SENSOR_CS2102K 1#define SENSOR_GC0305 2#define SENSOR_HDCS2020 3#define SENSOR_HDCS2020b 4#define SENSOR_HV7131B 5#define SENSOR_HV7131C 6#define SENSOR_ICM105A 7#define SENSOR_MC501CB 8#define SENSOR_OV7620 9/*#define SENSOR_OV7648 9 - same values */#define SENSOR_OV7630C 10#define SENSOR_PAS106 11#define SENSOR_PB0330 12#define SENSOR_PO2030 13#define SENSOR_TAS5130CK 14#define SENSOR_TAS5130CXX 15#define SENSOR_TAS5130C_VF0250 16#define SENSOR_MAX 17 unsigned short chip_revision;};/* V4L2 controls supported by the driver */static int sd_setbrightness(struct gspca_dev *gspca_dev, __s32 val);static int sd_getbrightness(struct gspca_dev *gspca_dev, __s32 *val);static int sd_setcontrast(struct gspca_dev *gspca_dev, __s32 val);static int sd_getcontrast(struct gspca_dev *gspca_dev, __s32 *val);static int sd_setautogain(struct gspca_dev *gspca_dev, __s32 val);static int sd_getautogain(struct gspca_dev *gspca_dev, __s32 *val);static int sd_setgamma(struct gspca_dev *gspca_dev, __s32 val);static int sd_getgamma(struct gspca_dev *gspca_dev, __s32 *val);static int sd_setfreq(struct gspca_dev *gspca_dev, __s32 val);static int sd_getfreq(struct gspca_dev *gspca_dev, __s32 *val);static int sd_setsharpness(struct gspca_dev *gspca_dev, __s32 val);static int sd_getsharpness(struct gspca_dev *gspca_dev, __s32 *val);static struct ctrl sd_ctrls[] = {#define BRIGHTNESS_IDX 0#define SD_BRIGHTNESS 0 { { .id = V4L2_CID_BRIGHTNESS, .type = V4L2_CTRL_TYPE_INTEGER, .name = "Brightness", .minimum = 0, .maximum = 255, .step = 1, .default_value = 128, }, .set = sd_setbrightness, .get = sd_getbrightness, },#define SD_CONTRAST 1 { { .id = V4L2_CID_CONTRAST, .type = V4L2_CTRL_TYPE_INTEGER, .name = "Contrast", .minimum = 0, .maximum = 256, .step = 1, .default_value = 128, }, .set = sd_setcontrast, .get = sd_getcontrast, },#define SD_GAMMA 2 { { .id = V4L2_CID_GAMMA, .type = V4L2_CTRL_TYPE_INTEGER, .name = "Gamma", .minimum = 1, .maximum = 6, .step = 1, .default_value = 4, }, .set = sd_setgamma, .get = sd_getgamma, },#define SD_AUTOGAIN 3 { { .id = V4L2_CID_AUTOGAIN, .type = V4L2_CTRL_TYPE_BOOLEAN, .name = "Auto Gain", .minimum = 0, .maximum = 1, .step = 1, .default_value = 1, }, .set = sd_setautogain, .get = sd_getautogain, },#define LIGHTFREQ_IDX 4#define SD_FREQ 4 { { .id = V4L2_CID_POWER_LINE_FREQUENCY, .type = V4L2_CTRL_TYPE_MENU, .name = "Light frequency filter", .minimum = 0, .maximum = 2, /* 0: 0, 1: 50Hz, 2:60Hz */ .step = 1, .default_value = 1, }, .set = sd_setfreq, .get = sd_getfreq, },#define SD_SHARPNESS 5 { { .id = V4L2_CID_SHARPNESS, .type = V4L2_CTRL_TYPE_INTEGER, .name = "Sharpness", .minimum = 0, .maximum = 3, .step = 1, .default_value = 2, }, .set = sd_setsharpness, .get = sd_getsharpness, },};static struct v4l2_pix_format vga_mode[] = { {320, 240, V4L2_PIX_FMT_JPEG, V4L2_FIELD_NONE, .bytesperline = 320, .sizeimage = 320 * 240 * 3 / 8 + 590, .colorspace = V4L2_COLORSPACE_JPEG, .priv = 1}, {640, 480, V4L2_PIX_FMT_JPEG, V4L2_FIELD_NONE, .bytesperline = 640, .sizeimage = 640 * 480 * 3 / 8 + 590, .colorspace = V4L2_COLORSPACE_JPEG, .priv = 0},};static struct v4l2_pix_format sif_mode[] = { {176, 144, V4L2_PIX_FMT_JPEG, V4L2_FIELD_NONE, .bytesperline = 176, .sizeimage = 176 * 144 * 3 / 8 + 590, .colorspace = V4L2_COLORSPACE_JPEG, .priv = 1}, {352, 288, V4L2_PIX_FMT_JPEG, V4L2_FIELD_NONE, .bytesperline = 352, .sizeimage = 352 * 288 * 3 / 8 + 590, .colorspace = V4L2_COLORSPACE_JPEG, .priv = 0},};/* usb exchanges */struct usb_action { __u8 req; __u8 val; __u16 idx;};static const struct usb_action cs2102_Initial[] = { {0xa1, 0x01, 0x0008}, {0xa1, 0x01, 0x0008}, {0xa0, 0x01, ZC3XX_R000_SYSTEMCONTROL}, {0xa0, 0x10, ZC3XX_R002_CLOCKSELECT}, {0xa0, 0x00, ZC3XX_R010_CMOSSENSORSELECT}, {0xa0, 0x01, ZC3XX_R001_SYSTEMOPERATING}, {0xa0, 0x20, ZC3XX_R080_HBLANKHIGH}, {0xa0, 0x21, ZC3XX_R081_HBLANKLOW}, {0xa0, 0x30, ZC3XX_R083_RGAINADDR}, {0xa0, 0x31, ZC3XX_R084_GGAINADDR}, {0xa0, 0x32, ZC3XX_R085_BGAINADDR}, {0xa0, 0x23, ZC3XX_R086_EXPTIMEHIGH}, {0xa0, 0x24, ZC3XX_R087_EXPTIMEMID}, {0xa0, 0x25, ZC3XX_R088_EXPTIMELOW}, {0xa0, 0xb3, ZC3XX_R08B_I2CDEVICEADDR}, {0xa0, 0x03, ZC3XX_R008_CLOCKSETTING}, /* 00 */ {0xa0, 0x03, ZC3XX_R012_VIDEOCONTROLFUNC}, {0xa0, 0x01, ZC3XX_R012_VIDEOCONTROLFUNC}, {0xa0, 0x02, ZC3XX_R003_FRAMEWIDTHHIGH}, {0xa0, 0x80, ZC3XX_R004_FRAMEWIDTHLOW}, {0xa0, 0x01, ZC3XX_R005_FRAMEHEIGHTHIGH}, {0xa0, 0xe0, ZC3XX_R006_FRAMEHEIGHTLOW}, {0xa0, 0x00, ZC3XX_R098_WINYSTARTLOW}, {0xa0, 0x00, ZC3XX_R09A_WINXSTARTLOW}, {0xa0, 0x00, ZC3XX_R11A_FIRSTYLOW}, {0xa0, 0x00, ZC3XX_R11C_FIRSTXLOW}, {0xaa, 0x02, 0x0008}, {0xaa, 0x03, 0x0000}, {0xaa, 0x11, 0x0000}, {0xaa, 0x12, 0x0089}, {0xaa, 0x13, 0x0000}, {0xaa, 0x14, 0x00e9}, {0xaa, 0x20, 0x0000}, {0xaa, 0x22, 0x0000}, {0xaa, 0x0b, 0x0004}, {0xaa, 0x30, 0x0030}, {0xaa, 0x31, 0x0030}, {0xaa, 0x32, 0x0030}, {0xa0, 0x37, ZC3XX_R101_SENSORCORRECTION}, {0xa0, 0x00, ZC3XX_R019_AUTOADJUSTFPS}, {0xa0, 0x05, ZC3XX_R012_VIDEOCONTROLFUNC}, {0xa0, 0x0d, ZC3XX_R100_OPERATIONMODE}, {0xa0, 0x06, ZC3XX_R189_AWBSTATUS}, {0xa0, 0x03, ZC3XX_R1C5_SHARPNESSMODE}, {0xa0, 0x13, ZC3XX_R1CB_SHARPNESS05}, {0xa0, 0x10, 0x01ae}, {0xa0, 0x08, ZC3XX_R250_DEADPIXELSMODE}, {0xa0, 0x08, ZC3XX_R301_EEPROMACCESS}, {0xa0, 0x68, ZC3XX_R18D_YTARGET}, {0xa0, 0x00, 0x01ad}, {0xa1, 0x01, 0x0002}, {0xa1, 0x01, 0x0008}, {0xa0, 0x03, ZC3XX_R008_CLOCKSETTING}, /* 00 */ {0xa0, 0x08, ZC3XX_R1C6_SHARPNESS00}, /* sharpness+ */ {0xa1, 0x01, 0x01c8}, {0xa1, 0x01, 0x01c9}, {0xa1, 0x01, 0x01ca}, {0xa0, 0x0f, ZC3XX_R1CB_SHARPNESS05}, /* sharpness- */ {0xa0, 0x24, ZC3XX_R120_GAMMA00}, /* gamma 5 */ {0xa0, 0x44, ZC3XX_R121_GAMMA01}, {0xa0, 0x64, ZC3XX_R122_GAMMA02}, {0xa0, 0x84, ZC3XX_R123_GAMMA03}, {0xa0, 0x9d, ZC3XX_R124_GAMMA04}, {0xa0, 0xb2, ZC3XX_R125_GAMMA05}, {0xa0, 0xc4, ZC3XX_R126_GAMMA06}, {0xa0, 0xd3, ZC3XX_R127_GAMMA07}, {0xa0, 0xe0, ZC3XX_R128_GAMMA08}, {0xa0, 0xeb, ZC3XX_R129_GAMMA09}, {0xa0, 0xf4, ZC3XX_R12A_GAMMA0A}, {0xa0, 0xfb, ZC3XX_R12B_GAMMA0B}, {0xa0, 0xff, ZC3XX_R12C_GAMMA0C}, {0xa0, 0xff, ZC3XX_R12D_GAMMA0D}, {0xa0, 0xff, ZC3XX_R12E_GAMMA0E}, {0xa0, 0xff, ZC3XX_R12F_GAMMA0F}, {0xa0, 0x18, ZC3XX_R130_GAMMA10}, {0xa0, 0x20, ZC3XX_R131_GAMMA11}, {0xa0, 0x20, ZC3XX_R132_GAMMA12}, {0xa0, 0x1c, ZC3XX_R133_GAMMA13}, {0xa0, 0x16, ZC3XX_R134_GAMMA14}, {0xa0, 0x13, ZC3XX_R135_GAMMA15}, {0xa0, 0x10, ZC3XX_R136_GAMMA16}, {0xa0, 0x0e, ZC3XX_R137_GAMMA17}, {0xa0, 0x0b, ZC3XX_R138_GAMMA18}, {0xa0, 0x09, ZC3XX_R139_GAMMA19}, {0xa0, 0x07, ZC3XX_R13A_GAMMA1A}, {0xa0, 0x06, ZC3XX_R13B_GAMMA1B}, {0xa0, 0x00, ZC3XX_R13C_GAMMA1C}, {0xa0, 0x00, ZC3XX_R13D_GAMMA1D}, {0xa0, 0x00, ZC3XX_R13E_GAMMA1E}, {0xa0, 0x01, ZC3XX_R13F_GAMMA1F}, {0xa0, 0x58, ZC3XX_R10A_RGB00}, /* matrix */ {0xa0, 0xf4, ZC3XX_R10B_RGB01}, {0xa0, 0xf4, ZC3XX_R10C_RGB02}, {0xa0, 0xf4, ZC3XX_R10D_RGB10}, {0xa0, 0x58, ZC3XX_R10E_RGB11}, {0xa0, 0xf4, ZC3XX_R10F_RGB12}, {0xa0, 0xf4, ZC3XX_R110_RGB20}, {0xa0, 0xf4, ZC3XX_R111_RGB21}, {0xa0, 0x58, ZC3XX_R112_RGB22}, {0xa1, 0x01, 0x0180}, {0xa0, 0x00, ZC3XX_R180_AUTOCORRECTENABLE}, {0xa0, 0x00, ZC3XX_R019_AUTOADJUSTFPS}, {0xaa, 0x23, 0x0001}, {0xaa, 0x24, 0x0055}, {0xaa, 0x25, 0x00cc}, {0xaa, 0x21, 0x003f}, {0xa0, 0x02, ZC3XX_R190_EXPOSURELIMITHIGH}, {0xa0, 0xab, ZC3XX_R191_EXPOSURELIMITMID}, {0xa0, 0x98, ZC3XX_R192_EXPOSURELIMITLOW}, {0xa0, 0x00, ZC3XX_R195_ANTIFLICKERHIGH}, {0xa0, 0x30, ZC3XX_R196_ANTIFLICKERMID}, {0xa0, 0xd4, ZC3XX_R197_ANTIFLICKERLOW}, {0xa0, 0x10, ZC3XX_R18C_AEFREEZE}, {0xa0, 0x20, ZC3XX_R18F_AEUNFREEZE}, {0xa0, 0x10, ZC3XX_R1A9_DIGITALLIMITDIFF}, {0xa0, 0x24, ZC3XX_R1AA_DIGITALGAINSTEP}, {0xa0, 0x39, ZC3XX_R01D_HSYNC_0}, {0xa0, 0x70, ZC3XX_R01E_HSYNC_1}, {0xa0, 0xb0, ZC3XX_R01F_HSYNC_2}, {0xa0, 0xff, ZC3XX_R020_HSYNC_3}, {0xa0, 0x40, ZC3XX_R180_AUTOCORRECTENABLE}, {0xa1, 0x01, 0x0180}, {0xa0, 0x42, ZC3XX_R180_AUTOCORRECTENABLE}, {0xa0, 0x40, ZC3XX_R116_RGAIN}, {0xa0, 0x40, ZC3XX_R117_GGAIN}, {0xa0, 0x40, ZC3XX_R118_BGAIN}, {}};static const struct usb_action cs2102_InitialScale[] = {
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -