123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821
#define pr_fmt(fmt) KBUILD_MODNAME ": " fmt
#define MODULE_NAME "ov534_9"
#include "gspca.h"
#define OV534_REG_ADDRESS 0xf1 /* sensor address */
#define OV534_REG_SUBADDR 0xf2
#define OV534_REG_WRITE 0xf3
#define OV534_REG_READ 0xf4
#define OV534_REG_OPERATION 0xf5
#define OV534_REG_STATUS 0xf6
#define OV534_OP_WRITE_3 0x37
#define OV534_OP_WRITE_2 0x33
#define OV534_OP_READ_2 0xf9
#define CTRL_TIMEOUT 500
MODULE_AUTHOR("Jean-Francois Moine <moinejf@free.fr>");
MODULE_DESCRIPTION("GSPCA/OV534_9 USB Camera Driver");
MODULE_LICENSE("GPL");
struct sd {
struct gspca_dev gspca_dev;
__u32 last_pts;
u8 last_fid;
u8 sensor;
};
enum sensors {
SENSOR_OV965x,
SENSOR_OV971x,
SENSOR_OV562x,
SENSOR_OV361x,
NSENSORS
};
static const struct v4l2_pix_format ov965x_mode[] = {
#define QVGA_MODE 0
{320, 240, V4L2_PIX_FMT_JPEG, V4L2_FIELD_NONE,
.bytesperline = 320,
.sizeimage = 320 * 240 * 3 / 8 + 590,
.colorspace = V4L2_COLORSPACE_JPEG},
#define VGA_MODE 1
{640, 480, V4L2_PIX_FMT_JPEG, V4L2_FIELD_NONE,
.bytesperline = 640,
.sizeimage = 640 * 480 * 3 / 8 + 590,
.colorspace = V4L2_COLORSPACE_JPEG},
#define SVGA_MODE 2
{800, 600, V4L2_PIX_FMT_JPEG, V4L2_FIELD_NONE,
.bytesperline = 800,
.sizeimage = 800 * 600 * 3 / 8 + 590,
.colorspace = V4L2_COLORSPACE_JPEG},
#define XGA_MODE 3
{1024, 768, V4L2_PIX_FMT_JPEG, V4L2_FIELD_NONE,
.bytesperline = 1024,
.sizeimage = 1024 * 768 * 3 / 8 + 590,
.colorspace = V4L2_COLORSPACE_JPEG},
#define SXGA_MODE 4
{1280, 1024, V4L2_PIX_FMT_JPEG, V4L2_FIELD_NONE,
.bytesperline = 1280,
.sizeimage = 1280 * 1024 * 3 / 8 + 590,
.colorspace = V4L2_COLORSPACE_JPEG},
};
static const struct v4l2_pix_format ov971x_mode[] = {
{640, 480, V4L2_PIX_FMT_SBGGR8, V4L2_FIELD_NONE,
.bytesperline = 640,
.sizeimage = 640 * 480,
.colorspace = V4L2_COLORSPACE_SRGB
}
};
static const struct v4l2_pix_format ov562x_mode[] = {
{2592, 1680, V4L2_PIX_FMT_SBGGR8, V4L2_FIELD_NONE,
.bytesperline = 2592,
.sizeimage = 2592 * 1680,
.colorspace = V4L2_COLORSPACE_SRGB
}
};
enum ov361x {
ov361x_2048 = 0,
ov361x_1600,
ov361x_1024,
ov361x_640,
ov361x_320,
ov361x_160,
ov361x_last
};
static const struct v4l2_pix_format ov361x_mode[] = {
{0x800, 0x600, V4L2_PIX_FMT_SBGGR8, V4L2_FIELD_NONE,
.bytesperline = 0x800,
.sizeimage = 0x800 * 0x600,
.colorspace = V4L2_COLORSPACE_SRGB},
{1600, 1200, V4L2_PIX_FMT_SBGGR8, V4L2_FIELD_NONE,
.bytesperline = 1600,
.sizeimage = 1600 * 1200,
.colorspace = V4L2_COLORSPACE_SRGB},
{1024, 768, V4L2_PIX_FMT_SBGGR8, V4L2_FIELD_NONE,
.bytesperline = 768,
.sizeimage = 1024 * 768,
.colorspace = V4L2_COLORSPACE_SRGB},
{640, 480, V4L2_PIX_FMT_SBGGR8, V4L2_FIELD_NONE,
.bytesperline = 640,
.sizeimage = 640 * 480,
.colorspace = V4L2_COLORSPACE_SRGB},
{320, 240, V4L2_PIX_FMT_SBGGR8, V4L2_FIELD_NONE,
.bytesperline = 320,
.sizeimage = 320 * 240,
.colorspace = V4L2_COLORSPACE_SRGB},
{160, 120, V4L2_PIX_FMT_SBGGR8, V4L2_FIELD_NONE,
.bytesperline = 160,
.sizeimage = 160 * 120,
.colorspace = V4L2_COLORSPACE_SRGB}
};
static const u8 ov361x_start_2048[][2] = {
{0x12, 0x80},
{0x13, 0xcf},
{0x14, 0x40},
{0x15, 0x00},
{0x01, 0x80},
{0x02, 0x80},
{0x04, 0x70},
{0x0d, 0x40},
{0x0f, 0x47},
{0x11, 0x81},
{0x32, 0x36},
{0x33, 0x0c},
{0x34, 0x00},
{0x35, 0x90},
{0x12, 0x00},
{0x17, 0x10},
{0x18, 0x90},
{0x19, 0x00},
{0x1a, 0xc0},
};
static const u8 ov361x_bridge_start_2048[][2] = {
{0xf1, 0x60},
{0x88, 0x00},
{0x89, 0x08},
{0x8a, 0x00},
{0x8b, 0x06},
{0x8c, 0x01},
{0x8d, 0x10},
{0x1c, 0x00},
{0x1d, 0x48},
{0x1d, 0x00},
{0x1d, 0xff},
{0x1c, 0x0a},
{0x1d, 0x2e},
{0x1d, 0x1e},
};
static const u8 ov361x_start_1600[][2] = {
{0x12, 0x80},
{0x13, 0xcf},
{0x14, 0x40},
{0x15, 0x00},
{0x01, 0x80},
{0x02, 0x80},
{0x04, 0x70},
{0x0d, 0x40},
{0x0f, 0x47},
{0x11, 0x81},
{0x32, 0x36},
{0x33, 0x0C},
{0x34, 0x00},
{0x35, 0x90},
{0x12, 0x00},
{0x17, 0x10},
{0x18, 0x90},
{0x19, 0x00},
{0x1a, 0xc0},
};
static const u8 ov361x_bridge_start_1600[][2] = {
{0xf1, 0x60},
{0x88, 0x00},
{0x89, 0x08},
{0x8a, 0x00},
{0x8b, 0x06},
{0x8c, 0x01},
{0x8d, 0x10},
{0x1c, 0x00},
{0x1d, 0x48},
{0x1d, 0x00},
{0x1d, 0xff},
{0x1c, 0x0a},
{0x1d, 0x2e},
{0x1d, 0x1e},
};
static const u8 ov361x_start_1024[][2] = {
{0x12, 0x80},
{0x13, 0xcf},
{0x14, 0x40},
{0x15, 0x00},
{0x01, 0x80},
{0x02, 0x80},
{0x04, 0x70},
{0x0d, 0x40},
{0x0f, 0x47},
{0x11, 0x81},
{0x32, 0x36},
{0x33, 0x0C},
{0x34, 0x00},
{0x35, 0x90},
{0x12, 0x40},
{0x17, 0x1f},
{0x18, 0x5f},
{0x19, 0x00},
{0x1a, 0x68},
};
static const u8 ov361x_bridge_start_1024[][2] = {
{0xf1, 0x60},
{0x88, 0x00},
{0x89, 0x04},
{0x8a, 0x00},
{0x8b, 0x03},
{0x8c, 0x01},
{0x8d, 0x10},
{0x1c, 0x00},
{0x1d, 0x48},
{0x1d, 0x00},
{0x1d, 0xff},
{0x1c, 0x0a},
{0x1d, 0x2e},
{0x1d, 0x1e},
};
static const u8 ov361x_start_640[][2] = {
{0x12, 0x80},
{0x13, 0xcf},
{0x14, 0x40},
{0x15, 0x00},
{0x01, 0x80},
{0x02, 0x80},
{0x04, 0x70},
{0x0d, 0x40},
{0x0f, 0x47},
{0x11, 0x81},
{0x32, 0x36},
{0x33, 0x0C},
{0x34, 0x00},
{0x35, 0x90},
{0x12, 0x40},
{0x17, 0x1f},
{0x18, 0x5f},
{0x19, 0x00},
{0x1a, 0x68},
};
static const u8 ov361x_bridge_start_640[][2] = {
{0xf1, 0x60},
{0x88, 0x00},
{0x89, 0x04},
{0x8a, 0x00},
{0x8b, 0x03},
{0x8c, 0x01},
{0x8d, 0x10},
{0x1c, 0x00},
{0x1d, 0x48},
{0x1d, 0x00},
{0x1d, 0xff},
{0x1c, 0x0a},
{0x1d, 0x2e},
{0x1d, 0x1e},
};
static const u8 ov361x_start_320[][2] = {
{0x12, 0x80},
{0x13, 0xcf},
{0x14, 0x40},
{0x15, 0x00},
{0x01, 0x80},
{0x02, 0x80},
{0x04, 0x70},
{0x0d, 0x40},
{0x0f, 0x47},
{0x11, 0x81},
{0x32, 0x36},
{0x33, 0x0C},
{0x34, 0x00},
{0x35, 0x90},
{0x12, 0x40},
{0x17, 0x1f},
{0x18, 0x5f},
{0x19, 0x00},
{0x1a, 0x68},
};
static const u8 ov361x_bridge_start_320[][2] = {
{0xf1, 0x60},
{0x88, 0x00},
{0x89, 0x04},
{0x8a, 0x00},
{0x8b, 0x03},
{0x8c, 0x01},
{0x8d, 0x10},
{0x1c, 0x00},
{0x1d, 0x48},
{0x1d, 0x00},
{0x1d, 0xff},
{0x1c, 0x0a},
{0x1d, 0x2e},
{0x1d, 0x1e},
};
static const u8 ov361x_start_160[][2] = {
{0x12, 0x80},
{0x13, 0xcf},
{0x14, 0x40},
{0x15, 0x00},
{0x01, 0x80},
{0x02, 0x80},
{0x04, 0x70},
{0x0d, 0x40},
{0x0f, 0x47},
{0x11, 0x81},
{0x32, 0x36},
{0x33, 0x0C},
{0x34, 0x00},
{0x35, 0x90},
{0x12, 0x40},
{0x17, 0x1f},
{0x18, 0x5f},
{0x19, 0x00},
{0x1a, 0x68},
};
static const u8 ov361x_bridge_start_160[][2] = {
{0xf1, 0x60},
{0x88, 0x00},
{0x89, 0x04},
{0x8a, 0x00},
{0x8b, 0x03},
{0x8c, 0x01},
{0x8d, 0x10},
{0x1c, 0x00},
{0x1d, 0x48},
{0x1d, 0x00},
{0x1d, 0xff},
{0x1c, 0x0a},
{0x1d, 0x2e},
{0x1d, 0x1e},
};
static const u8 bridge_init[][2] = {
{0x88, 0xf8},
{0x89, 0xff},
{0x76, 0x03},
{0x92, 0x03},
{0x95, 0x10},
{0xe2, 0x00},
{0xe7, 0x3e},
{0x8d, 0x1c},
{0x8e, 0x00},
{0x8f, 0x00},
{0x1f, 0x00},
{0xc3, 0xf9},
{0x89, 0xff},
{0x88, 0xf8},
{0x76, 0x03},
{0x92, 0x01},
{0x93, 0x18},
{0x1c, 0x0a},
{0x1d, 0x48},
{0xc0, 0x50},
{0xc1, 0x3c},
{0x34, 0x05},
{0xc2, 0x0c},
{0xc3, 0xf9},
{0x34, 0x05},
{0xe7, 0x2e},
{0x31, 0xf9},
{0x35, 0x02},
{0xd9, 0x10},
{0x25, 0x42},
{0x94, 0x11},
};
static const u8 ov965x_init[][2] = {
{0x12, 0x80},
{0x00, 0x00},
{0x01, 0x80},
{0x02, 0x80},
{0x03, 0x1b},
{0x04, 0x03},
{0x0b, 0x57},
{0x0e, 0x61},
{0x0f, 0x42},
{0x11, 0x00},
{0x12, 0x02},
{0x13, 0xe7},
{0x14, 0x28},
{0x16, 0x24},
{0x17, 0x1d},
{0x18, 0xbd},
{0x19, 0x01},
{0x1a, 0x81},
{0x1e, 0x04},
{0x24, 0x3c},
{0x25, 0x36},
{0x26, 0x71},
{0x27, 0x08},
{0x28, 0x08},
{0x29, 0x15},
{0x2a, 0x00},
{0x2b, 0x00},
{0x2c, 0x08},
{0x32, 0xff},
{0x33, 0x00},
{0x34, 0x3f},
{0x35, 0x00},
{0x36, 0xf8},
{0x38, 0x72},
{0x39, 0x57},
{0x3a, 0x80},
{0x3b, 0xc4},
{0x3d, 0x99},
{0x3f, 0xc1},
{0x40, 0xc0},
{0x41, 0x40},
{0x42, 0xc0},
{0x43, 0x0a},
{0x44, 0xf0},
{0x45, 0x46},
{0x46, 0x62},
{0x47, 0x2a},
{0x48, 0x3c},
{0x4a, 0xfc},
{0x4b, 0xfc},
{0x4c, 0x7f},
{0x4d, 0x7f},
{0x4e, 0x7f},
{0x4f, 0x98},
{0x50, 0x98},
{0x51, 0x00},
{0x52, 0x28},
{0x53, 0x70},
{0x54, 0x98},
{0x58, 0x1a},
{0x59, 0x85},
{0x5a, 0xa9},
{0x5b, 0x64},
{0x5c, 0x84},
{0x5d, 0x53},
{0x5e, 0x0e},
{0x5f, 0xf0},
{0x60, 0xf0},
{0x61, 0xf0},
{0x62, 0x00},
{0x63, 0x00},
{0x64, 0x02},
{0x65, 0x16},
{0x66, 0x01},
{0x69, 0x02},
{0x6b, 0x5a},
{0x6c, 0x04},
{0x6d, 0x55},
{0x6e, 0x00},
{0x6f, 0x9d},
{0x70, 0x21},
{0x71, 0x78},
{0x72, 0x00},
{0x73, 0x01},
{0x74, 0x3a},
{0x75, 0x35},
{0x76, 0x01},
{0x77, 0x02},
{0x7a, 0x12},
{0x7b, 0x08},
{0x7c, 0x16},
{0x7d, 0x30},
{0x7e, 0x5e},
{0x7f, 0x72},
{0x80, 0x82},
{0x81, 0x8e},
{0x82, 0x9a},
{0x83, 0xa4},
{0x84, 0xac},
{0x85, 0xb8},
{0x86, 0xc3},
{0x87, 0xd6},
{0x88, 0xe6},
{0x89, 0xf2},
{0x8a, 0x03},
{0x8c, 0x89},
{0x14, 0x28},
{0x90, 0x7d},
{0x91, 0x7b},
{0x9d, 0x03},
{0x9e, 0x04},
{0x9f, 0x7a},
{0xa0, 0x79},
{0xa1, 0x40},
{0xa4, 0x50},
{0xa5, 0x68},
{0xa6, 0x4a},
{0xa8, 0xc1},
{0xa9, 0xef},
{0xaa, 0x92},
{0xab, 0x04},
{0xac, 0x80},
{0xad, 0x80},
{0xae, 0x80},
{0xaf, 0x80},
{0xb2, 0xf2},
{0xb3, 0x20},
{0xb4, 0x20},
{0xb5, 0x00},
{0xb6, 0xaf},
{0xbb, 0xae},
{0xbc, 0x7f},
{0xdb, 0x7f},
{0xbe, 0x7f},
{0xbf, 0x7f},
{0xc0, 0xe2},
{0xc1, 0xc0},
{0xc2, 0x01},
{0xc3, 0x4e},
{0xc6, 0x85},
{0xc7, 0x80},
{0xc9, 0xe0},
{0xca, 0xe8},
{0xcb, 0xf0},
{0xcc, 0xd8},
{0xcd, 0xf1},
{0x4f, 0x98},
{0x50, 0x98},
{0x51, 0x00},
{0x52, 0x28},
{0x53, 0x70},
{0x54, 0x98},
{0x58, 0x1a},
{0xff, 0x41},
{0x41, 0x40},
{0xc5, 0x03},
{0x6a, 0x02},
{0x12, 0x62},
{0x36, 0xfa},
{0x69, 0x0a},
{0x8c, 0x89},
{0x14, 0x28},
{0x3e, 0x0c},
{0x41, 0x40},
{0x72, 0x00},
{0x73, 0x00},
{0x74, 0x3a},
{0x75, 0x35},
{0x76, 0x01},
{0xc7, 0x80},
{0x03, 0x12},
{0x17, 0x16},
{0x18, 0x02},
{0x19, 0x01},
{0x1a, 0x3d},
{0x32, 0xff},
{0xc0, 0xaa},
};
static const u8 bridge_init_2[][2] = {
{0x94, 0xaa},
{0xf1, 0x60},
{0xe5, 0x04},
{0xc0, 0x50},
{0xc1, 0x3c},
{0x8c, 0x00},
{0x8d, 0x1c},
{0x34, 0x05},
{0xc2, 0x0c},
{0xc3, 0xf9},
{0xda, 0x01},
{0x50, 0x00},
{0x51, 0xa0},
{0x52, 0x3c},
{0x53, 0x00},
{0x54, 0x00},
{0x55, 0x00},
{0x57, 0x00},
{0x5c, 0x00},
{0x5a, 0xa0},
{0x5b, 0x78},
{0x35, 0x02},
{0xd9, 0x10},
{0x94, 0x11},
};
static const u8 ov965x_init_2[][2] = {
{0x3b, 0xc4},
{0x1e, 0x04},
{0x13, 0xe0},
{0x00, 0x00},
{0x13, 0xe7},
{0x11, 0x03},
{0x6b, 0x5a},
{0x6a, 0x05},
{0xc5, 0x07},
{0xa2, 0x4b},
{0xa3, 0x3e},
{0x2d, 0x00},
{0xff, 0x42},
{0x42, 0xc0},
{0x2d, 0x00},
{0xff, 0x42},
{0x42, 0xc1},
{0x3f, 0x01},
{0xff, 0x42},
{0x42, 0xc1},
{0x4f, 0x98},
{0x50, 0x98},
{0x51, 0x00},
{0x52, 0x28},
{0x53, 0x70},
{0x54, 0x98},
{0x58, 0x1a},
{0xff, 0x41},
{0x41, 0x40},
{0x56, 0x40},
{0x55, 0x8f},
{0x10, 0x25},
{0xff, 0x13},
{0x13, 0xe7},
};
static const u8 ov971x_init[][2] = {
{0x12, 0x80},
{0x09, 0x10},
{0x1e, 0x07},
{0x5f, 0x18},
{0x69, 0x04},
{0x65, 0x2a},
{0x68, 0x0a},
{0x39, 0x28},
{0x4d, 0x90},
{0xc1, 0x80},
{0x0c, 0x30},
{0x6d, 0x02},
{0x96, 0xf1},
{0xbc, 0x68},
{0x12, 0x00},
{0x3b, 0x00},
{0x97, 0x80},
{0x17, 0x25},
{0x18, 0xa2},
{0x19, 0x01},
{0x1a, 0xca},
{0x03, 0x0a},
{0x32, 0x07},
{0x98, 0x40},
{0x99, 0xA0},
{0x9a, 0x01},
{0x57, 0x00},
{0x58, 0x78},
{0x59, 0x50},
{0x4c, 0x13},
{0x4b, 0x36},
{0x3d, 0x3c},
{0x3e, 0x03},
{0xbd, 0x50},
{0xbe, 0x78},
{0x4e, 0x55},
{0x4f, 0x55},
{0x50, 0x55},
{0x51, 0x55},
{0x24, 0x55},
{0x25, 0x40},
{0x26, 0xa1},
{0x5c, 0x59},
{0x5d, 0x00},
{0x11, 0x00},
{0x2a, 0x98},
{0x2b, 0x06},
{0x2d, 0x00},
{0x2e, 0x00},
{0x13, 0xa5},
{0x14, 0x40},
{0x4a, 0x00},
{0x49, 0xce},
{0x22, 0x03},
{0x09, 0x00}
};
static const u8 ov965x_start_1_vga[][2] = {
{0x12, 0x62},
{0x36, 0xfa},
{0x69, 0x0a},
{0x8c, 0x89},
{0x14, 0x28},
{0x3e, 0x0c},
{0x41, 0x40},
{0x72, 0x00},
{0x73, 0x00},
{0x74, 0x3a},
{0x75, 0x35},
{0x76, 0x01},
{0xc7, 0x80},
{0x03, 0x12},
{0x17, 0x16},
{0x18, 0x02},
{0x19, 0x01},
{0x1a, 0x3d},
{0x32, 0xff},
{0xc0, 0xaa},
};
static const u8 ov965x_start_1_svga[][2] = {
{0x12, 0x02},
{0x36, 0xf8},
{0x69, 0x02},
{0x8c, 0x0d},
{0x3e, 0x0c},
{0x41, 0x40},
{0x72, 0x00},
{0x73, 0x01},
{0x74, 0x3a},
{0x75, 0x35},
{0x76, 0x01},
{0xc7, 0x80},
{0x03, 0x1b},
{0x17, 0x1d},
{0x18, 0xbd},
{0x19, 0x01},
{0x1a, 0x81},
{0x32, 0xff},
{0xc0, 0xe2},
};
static const u8 ov965x_start_1_xga[][2] = {
{0x12, 0x02},
{0x36, 0xf8},
{0x69, 0x02},
{0x8c, 0x89},
{0x14, 0x28},
{0x3e, 0x0c},
{0x41, 0x40},
{0x72, 0x00},
{0x73, 0x01},
{0x74, 0x3a},
{0x75, 0x35},
{0x76, 0x01},
{0xc7, 0x80},
{0x03, 0x1b},
{0x17, 0x1d},
{0x18, 0xbd},
{0x19, 0x01},
{0x1a, 0x81},
{0x32, 0xff},
{0xc0, 0xe2},
};
static const u8 ov965x_start_1_sxga[][2] = {
{0x12, 0x02},
{0x36, 0xf8},
{0x69, 0x02},
{0x8c, 0x89},
{0x14, 0x28},
{0x3e, 0x0c},
{0x41, 0x40},
{0x72, 0x00},
{0x73, 0x01},
{0x74, 0x3a},
{0x75, 0x35},
{0x76, 0x01},
{0xc7, 0x80},
{0x03, 0x1b},
{0x17, 0x1d},
{0x18, 0x02},
{0x19, 0x01},
{0x1a, 0x81},
{0x32, 0xff},
{0xc0, 0xe2},
};
static const u8 bridge_start_qvga[][2] = {
{0x94, 0xaa},
{0xf1, 0x60},
{0xe5, 0x04},
{0xc0, 0x50},
{0xc1, 0x3c},
{0x8c, 0x00},
{0x8d, 0x1c},
{0x34, 0x05},
{0xc2, 0x4c},
{0xc3, 0xf9},
{0xda, 0x00},
{0x50, 0x00},
{0x51, 0xa0},
{0x52, 0x78},
{0x53, 0x00},
{0x54, 0x00},
{0x55, 0x00},
{0x57, 0x00},
{0x5c, 0x00},
{0x5a, 0x50},
{0x5b, 0x3c},
{0x35, 0x02},
{0xd9, 0x10},
{0x94, 0x11},
};
static const u8 bridge_start_vga[][2] = {
{0x94, 0xaa},
{0xf1, 0x60},
{0xe5, 0x04},
{0xc0, 0x50},
{0xc1, 0x3c},
{0x8c, 0x00},
{0x8d, 0x1c},
{0x34, 0x05},
{0xc2, 0x0c},
{0xc3, 0xf9},
{0xda, 0x01},
{0x50, 0x00},
{0x51, 0xa0},
{0x52, 0x3c},
{0x53, 0x00},
{0x54, 0x00},
{0x55, 0x00},
{0x57, 0x00},
{0x5c, 0x00},
{0x5a, 0xa0},
{0x5b, 0x78},
{0x35, 0x02},
{0xd9, 0x10},
{0x94, 0x11},
};
static const u8 bridge_start_svga[][2] = {
{0x94, 0xaa},
{0xf1, 0x60},
{0xe5, 0x04},
{0xc0, 0xa0},
{0xc1, 0x80},
{0x8c, 0x00},
{0x8d, 0x1c},
{0x34, 0x05},
{0xc2, 0x4c},
{0xc3, 0xf9},
{0x50, 0x00},
{0x51, 0x40},
{0x52, 0x00},
{0x53, 0x00},
{0x54, 0x00},
{0x55, 0x88},
{0x57, 0x00},
{0x5c, 0x00},
{0x5a, 0xc8},
{0x5b, 0x96},
{0x35, 0x02},
{0xd9, 0x10},
{0xda, 0x00},
{0x94, 0x11},
};
static const u8 bridge_start_xga[][2] = {
{0x94, 0xaa},
{0xf1, 0x60},
{0xe5, 0x04},
{0xc0, 0xa0},
{0xc1, 0x80},
{0x8c, 0x00},
{0x8d, 0x1c},
{0x34, 0x05},
{0xc2, 0x4c},
{0xc3, 0xf9},
{0x50, 0x00},
{0x51, 0x40},
{0x52, 0x00},
{0x53, 0x00},
{0x54, 0x00},
{0x55, 0x88},
{0x57, 0x00},
{0x5c, 0x01},
{0x5a, 0x00},
{0x5b, 0xc0},
{0x35, 0x02},
{0xd9, 0x10},
{0xda, 0x01},
{0x94, 0x11},
};
static const u8 bridge_start_sxga[][2] = {
{0x94, 0xaa},
{0xf1, 0x60},
{0xe5, 0x04},
{0xc0, 0xa0},
{0xc1, 0x80},
{0x8c, 0x00},
{0x8d, 0x1c},
{0x34, 0x05},
{0xc2, 0x0c},
{0xc3, 0xf9},
{0xda, 0x00},
{0x35, 0x02},
{0xd9, 0x10},
{0x94, 0x11},
};
static const u8 ov965x_start_2_qvga[][2] = {
{0x3b, 0xe4},
{0x1e, 0x04},
{0x13, 0xe0},
{0x00, 0x00},
{0x13, 0xe7},
{0x11, 0x01},
{0x6b, 0x5a},
{0x6a, 0x02},
{0xc5, 0x03},
{0xa2, 0x96},
{0xa3, 0x7d},
{0xff, 0x13},
{0x13, 0xe7},
{0x3a, 0x80},
};
static const u8 ov965x_start_2_vga[][2] = {
{0x3b, 0xc4},
{0x1e, 0x04},
{0x13, 0xe0},
{0x00, 0x00},
{0x13, 0xe7},
{0x11, 0x03},
{0x6b, 0x5a},
{0x6a, 0x05},
{0xc5, 0x07},
{0xa2, 0x4b},
{0xa3, 0x3e},
{0x2d, 0x00},
};
static const u8 ov965x_start_2_svga[][2] = {
{0x3b, 0xc4},
{0x1e, 0x04},
{0x13, 0xe0},
{0x00, 0x00},
{0x13, 0xe7},
{0x11, 0x01},
{0x6b, 0x5a},
{0x6a, 0x0c},
{0xc5, 0x0f},
{0xa2, 0x4e},
{0xa3, 0x41},
};
static const u8 ov965x_start_2_sxga[][2] = {
{0x13, 0xe0},
{0x00, 0x00},
{0x13, 0xe7},
{0x3b, 0xc4},
{0x1e, 0x04},
{0x11, 0x01},
{0x6b, 0x5a},
{0x6a, 0x0c},
{0xc5, 0x0f},
{0xa2, 0x4e},
{0xa3, 0x41},
};
static const u8 ov562x_init[][2] = {
{0x88, 0x20},
{0x89, 0x0a},
{0x8a, 0x90},
{0x8b, 0x06},
{0x8c, 0x01},
{0x8d, 0x10},
{0x1c, 0x00},
{0x1d, 0x48},
{0x1d, 0x00},
{0x1d, 0xff},
{0x1c, 0x0a},
{0x1d, 0x2e},
{0x1d, 0x1e},
};
static const u8 ov562x_init_2[][2] = {
{0x12, 0x80},
{0x11, 0x41},
{0x13, 0x00},
{0x10, 0x1e},
{0x3b, 0x07},
{0x5b, 0x40},
{0x39, 0x07},
{0x53, 0x02},
{0x54, 0x60},
{0x04, 0x20},
{0x27, 0x04},
{0x3d, 0x40},
{0x36, 0x00},
{0xc5, 0x04},
{0x4e, 0x00},
{0x4f, 0x93},
{0x50, 0x7b},
{0xca, 0x0c},
{0xcb, 0x0f},
{0x39, 0x07},
{0x4a, 0x10},
{0x3e, 0x0a},
{0x3d, 0x00},
{0x0c, 0x38},
{0x38, 0x90},
{0x46, 0x30},
{0x4f, 0x93},
{0x50, 0x7b},
{0xab, 0x00},
{0xca, 0x0c},
{0xcb, 0x0f},
{0x37, 0x02},
{0x44, 0x48},
{0x8d, 0x44},
{0x2a, 0x00},
{0x2b, 0x00},
{0x32, 0x00},
{0x38, 0x90},
{0x53, 0x02},
{0x54, 0x60},
{0x12, 0x00},
{0x17, 0x12},
{0x18, 0xb4},
{0x19, 0x0c},
{0x1a, 0xf4},
{0x03, 0x4a},
{0x89, 0x20},
{0x83, 0x80},
{0xb7, 0x9d},
{0xb6, 0x11},
{0xb5, 0x55},
{0xb4, 0x00},
{0xa9, 0xf0},
{0xa8, 0x0a},
{0xb8, 0xf0},
{0xb9, 0xf0},
{0xba, 0xf0},
{0x81, 0x07},
{0x63, 0x44},
{0x13, 0xc7},
{0x14, 0x60},
{0x33, 0x75},
{0x2c, 0x00},
{0x09, 0x00},
{0x35, 0x30},
{0x27, 0x04},
{0x3c, 0x07},
{0x3a, 0x0a},
{0x3b, 0x07},
{0x01, 0x40},
{0x02, 0x40},
{0x16, 0x40},
{0x52, 0xb0},
{0x51, 0x83},
{0x21, 0xbb},
{0x22, 0x10},
{0x23, 0x03},
{0x35, 0x38},
{0x20, 0x90},
{0x28, 0x30},
{0x73, 0xe1},
{0x6c, 0x00},
{0x6d, 0x80},
{0x6e, 0x00},
{0x70, 0x04},
{0x71, 0x00},
{0x8d, 0x04},
{0x64, 0x00},
{0x65, 0x00},
{0x66, 0x00},
{0x67, 0x00},
{0x68, 0x00},
{0x69, 0x00},
{0x6a, 0x00},
{0x6b, 0x00},
{0x71, 0x94},
{0x74, 0x20},
{0x80, 0x09},
{0x85, 0xc0},
};
static void reg_w_i(struct gspca_dev *gspca_dev, u16 reg, u8 val)
{
struct usb_device *udev = gspca_dev->dev;
int ret;
if (gspca_dev->usb_err < 0)
return;
gspca_dev->usb_buf[0] = val;
ret = usb_control_msg(udev,
usb_sndctrlpipe(udev, 0),
0x01,
USB_DIR_OUT | USB_TYPE_VENDOR | USB_RECIP_DEVICE,
0x00, reg, gspca_dev->usb_buf, 1, CTRL_TIMEOUT);
if (ret < 0) {
pr_err("reg_w failed %d\n", ret);
gspca_dev->usb_err = ret;
}
}
static void reg_w(struct gspca_dev *gspca_dev, u16 reg, u8 val)
{
gspca_dbg(gspca_dev, D_USBO, "reg_w [%04x] = %02x\n", reg, val);
reg_w_i(gspca_dev, reg, val);
}
static u8 reg_r(struct gspca_dev *gspca_dev, u16 reg)
{
struct usb_device *udev = gspca_dev->dev;
int ret;
if (gspca_dev->usb_err < 0)
return 0;
ret = usb_control_msg(udev,
usb_rcvctrlpipe(udev, 0),
0x01,
USB_DIR_IN | USB_TYPE_VENDOR | USB_RECIP_DEVICE,
0x00, reg, gspca_dev->usb_buf, 1, CTRL_TIMEOUT);
gspca_dbg(gspca_dev, D_USBI, "reg_r [%04x] -> %02x\n",
reg, gspca_dev->usb_buf[0]);
if (ret < 0) {
pr_err("reg_r err %d\n", ret);
gspca_dev->usb_err = ret;
return 0;
}
return gspca_dev->usb_buf[0];
}
static int sccb_check_status(struct gspca_dev *gspca_dev)
{
u8 data;
int i;
for (i = 0; i < 5; i++) {
msleep(20);
data = reg_r(gspca_dev, OV534_REG_STATUS);
switch (data) {
case 0x00:
return 1;
case 0x04:
return 0;
case 0x03:
break;
default:
gspca_dbg(gspca_dev, D_USBI|D_USBO,
"sccb status 0x%02x, attempt %d/5\n",
data, i + 1);
}
}
return 0;
}
static void sccb_write(struct gspca_dev *gspca_dev, u8 reg, u8 val)
{
gspca_dbg(gspca_dev, D_USBO, "sccb_write [%02x] = %02x\n", reg, val);
reg_w_i(gspca_dev, OV534_REG_SUBADDR, reg);
reg_w_i(gspca_dev, OV534_REG_WRITE, val);
reg_w_i(gspca_dev, OV534_REG_OPERATION, OV534_OP_WRITE_3);
if (!sccb_check_status(gspca_dev))
pr_err("sccb_write failed\n");
}
static u8 sccb_read(struct gspca_dev *gspca_dev, u16 reg)
{
reg_w(gspca_dev, OV534_REG_SUBADDR, reg);
reg_w(gspca_dev, OV534_REG_OPERATION, OV534_OP_WRITE_2);
if (!sccb_check_status(gspca_dev))
pr_err("sccb_read failed 1\n");
reg_w(gspca_dev, OV534_REG_OPERATION, OV534_OP_READ_2);
if (!sccb_check_status(gspca_dev))
pr_err("sccb_read failed 2\n");
return reg_r(gspca_dev, OV534_REG_READ);
}
static void reg_w_array(struct gspca_dev *gspca_dev,
const u8 (*data)[2], int len)
{
while (--len >= 0) {
reg_w(gspca_dev, (*data)[0], (*data)[1]);
data++;
}
}
static void sccb_w_array(struct gspca_dev *gspca_dev,
const u8 (*data)[2], int len)
{
while (--len >= 0) {
if ((*data)[0] != 0xff) {
sccb_write(gspca_dev, (*data)[0], (*data)[1]);
} else {
sccb_read(gspca_dev, (*data)[1]);
sccb_write(gspca_dev, 0xff, 0x00);
}
data++;
}
}
static void set_led(struct gspca_dev *gspca_dev, int status)
{
u8 data;
gspca_dbg(gspca_dev, D_CONF, "led status: %d\n", status);
data = reg_r(gspca_dev, 0x21);
data |= 0x80;
reg_w(gspca_dev, 0x21, data);
data = reg_r(gspca_dev, 0x23);
if (status)
data |= 0x80;
else
data &= ~0x80;
reg_w(gspca_dev, 0x23, data);
if (!status) {
data = reg_r(gspca_dev, 0x21);
data &= ~0x80;
reg_w(gspca_dev, 0x21, data);
}
}
static void setbrightness(struct gspca_dev *gspca_dev, s32 brightness)
{
struct sd *sd = (struct sd *) gspca_dev;
u8 val;
s8 sval;
if (sd->sensor == SENSOR_OV562x) {
sval = brightness;
val = 0x76;
val += sval;
sccb_write(gspca_dev, 0x24, val);
val = 0x6a;
val += sval;
sccb_write(gspca_dev, 0x25, val);
if (sval < -40)
val = 0x71;
else if (sval < 20)
val = 0x94;
else
val = 0xe6;
sccb_write(gspca_dev, 0x26, val);
} else {
val = brightness;
if (val < 8)
val = 15 - val;
else
val = val - 8;
sccb_write(gspca_dev, 0x55,
0x0f | (val << 4));
}
}
static void setcontrast(struct gspca_dev *gspca_dev, s32 val)
{
sccb_write(gspca_dev, 0x56,
val << 4);
}
static void setautogain(struct gspca_dev *gspca_dev, s32 autogain)
{
u8 val;
val = sccb_read(gspca_dev, 0x13);
sccb_write(gspca_dev, 0xff, 0x00);
if (autogain)
val |= 0x05;
else
val &= 0xfa;
sccb_write(gspca_dev, 0x13, val);
}
static void setexposure(struct gspca_dev *gspca_dev, s32 exposure)
{
static const u8 expo[4] = {0x00, 0x25, 0x38, 0x5e};
u8 val;
sccb_write(gspca_dev, 0x10, expo[exposure]);
val = sccb_read(gspca_dev, 0x13);
sccb_write(gspca_dev, 0xff, 0x00);
sccb_write(gspca_dev, 0x13, val);
val = sccb_read(gspca_dev, 0xa1);
sccb_write(gspca_dev, 0xff, 0x00);
sccb_write(gspca_dev, 0xa1, val & 0xe0);
}
static void setsharpness(struct gspca_dev *gspca_dev, s32 val)
{
if (val < 0) {
val = sccb_read(gspca_dev, 0x42);
sccb_write(gspca_dev, 0xff, 0x00);
sccb_write(gspca_dev, 0x42, val | 0x40);
return;
}
if (val != 0)
val = 1 << (val - 1);
sccb_write(gspca_dev, 0x3f,
val);
val = sccb_read(gspca_dev, 0x42);
sccb_write(gspca_dev, 0xff, 0x00);
sccb_write(gspca_dev, 0x42, val & 0xbf);
}
static void setsatur(struct gspca_dev *gspca_dev, s32 val)
{
u8 val1, val2, val3;
static const u8 matrix[5][2] = {
{0x14, 0x38},
{0x1e, 0x54},
{0x28, 0x70},
{0x32, 0x8c},
{0x48, 0x90}
};
val1 = matrix[val][0];
val2 = matrix[val][1];
val3 = val1 + val2;
sccb_write(gspca_dev, 0x4f, val3);
sccb_write(gspca_dev, 0x50, val3);
sccb_write(gspca_dev, 0x51, 0x00);
sccb_write(gspca_dev, 0x52, val1);
sccb_write(gspca_dev, 0x53, val2);
sccb_write(gspca_dev, 0x54, val3);
sccb_write(gspca_dev, 0x58, 0x1a);
val1 = sccb_read(gspca_dev, 0x41);
sccb_write(gspca_dev, 0xff, 0x00);
sccb_write(gspca_dev, 0x41, val1);
}
static void setlightfreq(struct gspca_dev *gspca_dev, s32 freq)
{
u8 val;
val = sccb_read(gspca_dev, 0x13);
sccb_write(gspca_dev, 0xff, 0x00);
if (freq == 0) {
sccb_write(gspca_dev, 0x13, val & 0xdf);
return;
}
sccb_write(gspca_dev, 0x13, val | 0x20);
val = sccb_read(gspca_dev, 0x42);
sccb_write(gspca_dev, 0xff, 0x00);
if (freq == 1)
val |= 0x01;
else
val &= 0xfe;
sccb_write(gspca_dev, 0x42, val);
}
static int sd_config(struct gspca_dev *gspca_dev,
const struct usb_device_id *id)
{
return 0;
}
static int sd_init(struct gspca_dev *gspca_dev)
{
struct sd *sd = (struct sd *) gspca_dev;
u16 sensor_id;
reg_w(gspca_dev, 0xe7, 0x3a);
reg_w(gspca_dev, 0xe0, 0x08);
msleep(100);
reg_w(gspca_dev, OV534_REG_ADDRESS, 0x60);
sccb_write(gspca_dev, 0x12, 0x80);
msleep(10);
sccb_read(gspca_dev, 0x0a);
sensor_id = sccb_read(gspca_dev, 0x0a) << 8;
sccb_read(gspca_dev, 0x0b);
sensor_id |= sccb_read(gspca_dev, 0x0b);
gspca_dbg(gspca_dev, D_PROBE, "Sensor ID: %04x\n", sensor_id);
if ((sensor_id & 0xfff0) == 0x9650) {
sd->sensor = SENSOR_OV965x;
gspca_dev->cam.cam_mode = ov965x_mode;
gspca_dev->cam.nmodes = ARRAY_SIZE(ov965x_mode);
reg_w_array(gspca_dev, bridge_init,
ARRAY_SIZE(bridge_init));
sccb_w_array(gspca_dev, ov965x_init,
ARRAY_SIZE(ov965x_init));
reg_w_array(gspca_dev, bridge_init_2,
ARRAY_SIZE(bridge_init_2));
sccb_w_array(gspca_dev, ov965x_init_2,
ARRAY_SIZE(ov965x_init_2));
reg_w(gspca_dev, 0xe0, 0x00);
reg_w(gspca_dev, 0xe0, 0x01);
set_led(gspca_dev, 0);
reg_w(gspca_dev, 0xe0, 0x00);
} else if ((sensor_id & 0xfff0) == 0x9710) {
const char *p;
int l;
sd->sensor = SENSOR_OV971x;
gspca_dev->cam.cam_mode = ov971x_mode;
gspca_dev->cam.nmodes = ARRAY_SIZE(ov971x_mode);
gspca_dev->cam.bulk = 1;
gspca_dev->cam.bulk_size = 16384;
gspca_dev->cam.bulk_nurbs = 2;
sccb_w_array(gspca_dev, ov971x_init,
ARRAY_SIZE(ov971x_init));
reg_w(gspca_dev, 0x1c, 0x00);
reg_w(gspca_dev, 0x1d, 0x00);
p = video_device_node_name(&gspca_dev->vdev);
l = strlen(p) - 1;
if (p[l] == '0')
reg_w(gspca_dev, 0x56, 0x1f);
else
reg_w(gspca_dev, 0x56, 0x17);
} else if ((sensor_id & 0xfff0) == 0x5620) {
sd->sensor = SENSOR_OV562x;
gspca_dev->cam.cam_mode = ov562x_mode;
gspca_dev->cam.nmodes = ARRAY_SIZE(ov562x_mode);
reg_w_array(gspca_dev, ov562x_init,
ARRAY_SIZE(ov562x_init));
sccb_w_array(gspca_dev, ov562x_init_2,
ARRAY_SIZE(ov562x_init_2));
reg_w(gspca_dev, 0xe0, 0x00);
} else if ((sensor_id & 0xfff0) == 0x3610) {
sd->sensor = SENSOR_OV361x;
gspca_dev->cam.cam_mode = ov361x_mode;
gspca_dev->cam.nmodes = ARRAY_SIZE(ov361x_mode);
reg_w(gspca_dev, 0xe7, 0x3a);
reg_w(gspca_dev, 0xf1, 0x60);
sccb_write(gspca_dev, 0x12, 0x80);
} else {
pr_err("Unknown sensor %04x", sensor_id);
return -EINVAL;
}
return gspca_dev->usb_err;
}
static int sd_start_ov361x(struct gspca_dev *gspca_dev)
{
sccb_write(gspca_dev, 0x12, 0x80);
msleep(20);
switch (gspca_dev->curr_mode % (ov361x_last)) {
case ov361x_2048:
reg_w_array(gspca_dev, ov361x_bridge_start_2048,
ARRAY_SIZE(ov361x_bridge_start_2048));
sccb_w_array(gspca_dev, ov361x_start_2048,
ARRAY_SIZE(ov361x_start_2048));
break;
case ov361x_1600:
reg_w_array(gspca_dev, ov361x_bridge_start_1600,
ARRAY_SIZE(ov361x_bridge_start_1600));
sccb_w_array(gspca_dev, ov361x_start_1600,
ARRAY_SIZE(ov361x_start_1600));
break;
case ov361x_1024:
reg_w_array(gspca_dev, ov361x_bridge_start_1024,
ARRAY_SIZE(ov361x_bridge_start_1024));
sccb_w_array(gspca_dev, ov361x_start_1024,
ARRAY_SIZE(ov361x_start_1024));
break;
case ov361x_640:
reg_w_array(gspca_dev, ov361x_bridge_start_640,
ARRAY_SIZE(ov361x_bridge_start_640));
sccb_w_array(gspca_dev, ov361x_start_640,
ARRAY_SIZE(ov361x_start_640));
break;
case ov361x_320:
reg_w_array(gspca_dev, ov361x_bridge_start_320,
ARRAY_SIZE(ov361x_bridge_start_320));
sccb_w_array(gspca_dev, ov361x_start_320,
ARRAY_SIZE(ov361x_start_320));
break;
case ov361x_160:
reg_w_array(gspca_dev, ov361x_bridge_start_160,
ARRAY_SIZE(ov361x_bridge_start_160));
sccb_w_array(gspca_dev, ov361x_start_160,
ARRAY_SIZE(ov361x_start_160));
break;
}
reg_w(gspca_dev, 0xe0, 0x00);
return gspca_dev->usb_err;
}
static int sd_start(struct gspca_dev *gspca_dev)
{
struct sd *sd = (struct sd *) gspca_dev;
if (sd->sensor == SENSOR_OV971x)
return gspca_dev->usb_err;
if (sd->sensor == SENSOR_OV562x)
return gspca_dev->usb_err;
if (sd->sensor == SENSOR_OV361x)
return sd_start_ov361x(gspca_dev);
switch (gspca_dev->curr_mode) {
case QVGA_MODE:
sccb_w_array(gspca_dev, ov965x_start_1_vga,
ARRAY_SIZE(ov965x_start_1_vga));
reg_w_array(gspca_dev, bridge_start_qvga,
ARRAY_SIZE(bridge_start_qvga));
sccb_w_array(gspca_dev, ov965x_start_2_qvga,
ARRAY_SIZE(ov965x_start_2_qvga));
break;
case VGA_MODE:
sccb_w_array(gspca_dev, ov965x_start_1_vga,
ARRAY_SIZE(ov965x_start_1_vga));
reg_w_array(gspca_dev, bridge_start_vga,
ARRAY_SIZE(bridge_start_vga));
sccb_w_array(gspca_dev, ov965x_start_2_vga,
ARRAY_SIZE(ov965x_start_2_vga));
break;
case SVGA_MODE:
sccb_w_array(gspca_dev, ov965x_start_1_svga,
ARRAY_SIZE(ov965x_start_1_svga));
reg_w_array(gspca_dev, bridge_start_svga,
ARRAY_SIZE(bridge_start_svga));
sccb_w_array(gspca_dev, ov965x_start_2_svga,
ARRAY_SIZE(ov965x_start_2_svga));
break;
case XGA_MODE:
sccb_w_array(gspca_dev, ov965x_start_1_xga,
ARRAY_SIZE(ov965x_start_1_xga));
reg_w_array(gspca_dev, bridge_start_xga,
ARRAY_SIZE(bridge_start_xga));
sccb_w_array(gspca_dev, ov965x_start_2_svga,
ARRAY_SIZE(ov965x_start_2_svga));
break;
default:
sccb_w_array(gspca_dev, ov965x_start_1_sxga,
ARRAY_SIZE(ov965x_start_1_sxga));
reg_w_array(gspca_dev, bridge_start_sxga,
ARRAY_SIZE(bridge_start_sxga));
sccb_w_array(gspca_dev, ov965x_start_2_sxga,
ARRAY_SIZE(ov965x_start_2_sxga));
break;
}
reg_w(gspca_dev, 0xe0, 0x00);
reg_w(gspca_dev, 0xe0, 0x00);
set_led(gspca_dev, 1);
return gspca_dev->usb_err;
}
static void sd_stopN(struct gspca_dev *gspca_dev)
{
if (((struct sd *)gspca_dev)->sensor == SENSOR_OV361x) {
reg_w(gspca_dev, 0xe0, 0x01);
return;
}
reg_w(gspca_dev, 0xe0, 0x01);
set_led(gspca_dev, 0);
reg_w(gspca_dev, 0xe0, 0x00);
}
#define UVC_STREAM_EOH (1 << 7)
#define UVC_STREAM_ERR (1 << 6)
#define UVC_STREAM_STI (1 << 5)
#define UVC_STREAM_RES (1 << 4)
#define UVC_STREAM_SCR (1 << 3)
#define UVC_STREAM_PTS (1 << 2)
#define UVC_STREAM_EOF (1 << 1)
#define UVC_STREAM_FID (1 << 0)
static void sd_pkt_scan(struct gspca_dev *gspca_dev,
u8 *data, int len)
{
struct sd *sd = (struct sd *) gspca_dev;
__u32 this_pts;
u8 this_fid;
int remaining_len = len;
int payload_len;
payload_len = gspca_dev->cam.bulk ? 2048 : 2040;
do {
len = min(remaining_len, payload_len);
if (data[0] != 12 || len < 12) {
gspca_dbg(gspca_dev, D_PACK, "bad header\n");
goto discard;
}
if (data[1] & UVC_STREAM_ERR) {
gspca_dbg(gspca_dev, D_PACK, "payload error\n");
goto discard;
}
if (!(data[1] & UVC_STREAM_PTS)) {
gspca_dbg(gspca_dev, D_PACK, "PTS not present\n");
goto discard;
}
this_pts = (data[5] << 24) | (data[4] << 16)
| (data[3] << 8) | data[2];
this_fid = data[1] & UVC_STREAM_FID;
if (this_pts != sd->last_pts || this_fid != sd->last_fid) {
if (gspca_dev->last_packet_type == INTER_PACKET)
gspca_frame_add(gspca_dev, LAST_PACKET,
NULL, 0);
sd->last_pts = this_pts;
sd->last_fid = this_fid;
gspca_frame_add(gspca_dev, FIRST_PACKET,
data + 12, len - 12);
} else if (data[1] & UVC_STREAM_EOF) {
sd->last_pts = 0;
gspca_frame_add(gspca_dev, LAST_PACKET,
data + 12, len - 12);
} else {
gspca_frame_add(gspca_dev, INTER_PACKET,
data + 12, len - 12);
}
goto scan_next;
discard:
gspca_dev->last_packet_type = DISCARD_PACKET;
scan_next:
remaining_len -= len;
data += len;
} while (remaining_len > 0);
}
static int sd_s_ctrl(struct v4l2_ctrl *ctrl)
{
struct gspca_dev *gspca_dev =
container_of(ctrl->handler, struct gspca_dev, ctrl_handler);
gspca_dev->usb_err = 0;
if (!gspca_dev->streaming)
return 0;
switch (ctrl->id) {
case V4L2_CID_BRIGHTNESS:
setbrightness(gspca_dev, ctrl->val);
break;
case V4L2_CID_CONTRAST:
setcontrast(gspca_dev, ctrl->val);
break;
case V4L2_CID_SATURATION:
setsatur(gspca_dev, ctrl->val);
break;
case V4L2_CID_POWER_LINE_FREQUENCY:
setlightfreq(gspca_dev, ctrl->val);
break;
case V4L2_CID_SHARPNESS:
setsharpness(gspca_dev, ctrl->val);
break;
case V4L2_CID_AUTOGAIN:
if (ctrl->is_new)
setautogain(gspca_dev, ctrl->val);
if (!ctrl->val && gspca_dev->exposure->is_new)
setexposure(gspca_dev, gspca_dev->exposure->val);
break;
}
return gspca_dev->usb_err;
}
static const struct v4l2_ctrl_ops sd_ctrl_ops = {
.s_ctrl = sd_s_ctrl,
};
static int sd_init_controls(struct gspca_dev *gspca_dev)
{
struct sd *sd = (struct sd *)gspca_dev;
struct v4l2_ctrl_handler *hdl = &gspca_dev->ctrl_handler;
if (sd->sensor == SENSOR_OV971x)
return 0;
if (sd->sensor == SENSOR_OV361x)
return 0;
gspca_dev->vdev.ctrl_handler = hdl;
v4l2_ctrl_handler_init(hdl, 7);
if (sd->sensor == SENSOR_OV562x) {
v4l2_ctrl_new_std(hdl, &sd_ctrl_ops,
V4L2_CID_BRIGHTNESS, -90, 90, 1, 0);
} else {
v4l2_ctrl_new_std(hdl, &sd_ctrl_ops,
V4L2_CID_BRIGHTNESS, 0, 15, 1, 7);
v4l2_ctrl_new_std(hdl, &sd_ctrl_ops,
V4L2_CID_CONTRAST, 0, 15, 1, 3);
v4l2_ctrl_new_std(hdl, &sd_ctrl_ops,
V4L2_CID_SATURATION, 0, 4, 1, 2);
v4l2_ctrl_new_std(hdl, &sd_ctrl_ops,
V4L2_CID_SHARPNESS, -1, 4, 1, -1);
gspca_dev->autogain = v4l2_ctrl_new_std(hdl, &sd_ctrl_ops,
V4L2_CID_AUTOGAIN, 0, 1, 1, 1);
gspca_dev->exposure = v4l2_ctrl_new_std(hdl, &sd_ctrl_ops,
V4L2_CID_EXPOSURE, 0, 3, 1, 0);
v4l2_ctrl_new_std_menu(hdl, &sd_ctrl_ops,
V4L2_CID_POWER_LINE_FREQUENCY,
V4L2_CID_POWER_LINE_FREQUENCY_60HZ, 0, 0);
v4l2_ctrl_auto_cluster(3, &gspca_dev->autogain, 0, false);
}
if (hdl->error) {
pr_err("Could not initialize controls\n");
return hdl->error;
}
return 0;
}
static const struct sd_desc sd_desc = {
.name = MODULE_NAME,
.config = sd_config,
.init = sd_init,
.init_controls = sd_init_controls,
.start = sd_start,
.stopN = sd_stopN,
.pkt_scan = sd_pkt_scan,
};
static const struct usb_device_id device_table[] = {
{USB_DEVICE(0x05a9, 0x8065)},
{USB_DEVICE(0x06f8, 0x3003)},
{USB_DEVICE(0x05a9, 0x1550)},
{}
};
MODULE_DEVICE_TABLE(usb, device_table);
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,
.reset_resume = gspca_resume,
#endif
};
module_usb_driver(sd_driver);