xirlink_cit.c 101 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061206220632064206520662067206820692070207120722073207420752076207720782079208020812082208320842085208620872088208920902091209220932094209520962097209820992100210121022103210421052106210721082109211021112112211321142115211621172118211921202121212221232124212521262127212821292130213121322133213421352136213721382139214021412142214321442145214621472148214921502151215221532154215521562157215821592160216121622163216421652166216721682169217021712172217321742175217621772178217921802181218221832184218521862187218821892190219121922193219421952196219721982199220022012202220322042205220622072208220922102211221222132214221522162217221822192220222122222223222422252226222722282229223022312232223322342235223622372238223922402241224222432244224522462247224822492250225122522253225422552256225722582259226022612262226322642265226622672268226922702271227222732274227522762277227822792280228122822283228422852286228722882289229022912292229322942295229622972298229923002301230223032304230523062307230823092310231123122313231423152316231723182319232023212322232323242325232623272328232923302331233223332334233523362337233823392340234123422343234423452346234723482349235023512352235323542355235623572358235923602361236223632364236523662367236823692370237123722373237423752376237723782379238023812382238323842385238623872388238923902391239223932394239523962397239823992400240124022403240424052406240724082409241024112412241324142415241624172418241924202421242224232424242524262427242824292430243124322433243424352436243724382439244024412442244324442445244624472448244924502451245224532454245524562457245824592460246124622463246424652466246724682469247024712472247324742475247624772478247924802481248224832484248524862487248824892490249124922493249424952496249724982499250025012502250325042505250625072508250925102511251225132514251525162517251825192520252125222523252425252526252725282529253025312532253325342535253625372538253925402541254225432544254525462547254825492550255125522553255425552556255725582559256025612562256325642565256625672568256925702571257225732574257525762577257825792580258125822583258425852586258725882589259025912592259325942595259625972598259926002601260226032604260526062607260826092610261126122613261426152616261726182619262026212622262326242625262626272628262926302631263226332634263526362637263826392640264126422643264426452646264726482649265026512652265326542655265626572658265926602661266226632664266526662667266826692670267126722673267426752676267726782679268026812682268326842685268626872688268926902691269226932694269526962697269826992700270127022703270427052706270727082709271027112712271327142715271627172718271927202721272227232724272527262727272827292730273127322733273427352736273727382739274027412742274327442745274627472748274927502751275227532754275527562757275827592760276127622763276427652766276727682769277027712772277327742775277627772778277927802781278227832784278527862787278827892790279127922793279427952796279727982799280028012802280328042805280628072808280928102811281228132814281528162817281828192820282128222823282428252826282728282829283028312832283328342835283628372838283928402841284228432844284528462847284828492850285128522853285428552856285728582859286028612862286328642865286628672868286928702871287228732874287528762877287828792880288128822883288428852886288728882889289028912892289328942895289628972898289929002901290229032904290529062907290829092910291129122913291429152916291729182919292029212922292329242925292629272928292929302931293229332934293529362937293829392940294129422943294429452946294729482949295029512952295329542955295629572958295929602961296229632964296529662967296829692970297129722973297429752976297729782979298029812982298329842985298629872988298929902991299229932994299529962997299829993000300130023003300430053006300730083009301030113012301330143015301630173018301930203021302230233024302530263027302830293030303130323033303430353036303730383039304030413042304330443045304630473048304930503051305230533054305530563057305830593060306130623063306430653066306730683069307030713072307330743075307630773078307930803081308230833084308530863087308830893090309130923093309430953096309730983099310031013102310331043105310631073108310931103111311231133114311531163117311831193120312131223123312431253126312731283129313031313132313331343135313631373138313931403141314231433144314531463147314831493150315131523153315431553156315731583159316031613162316331643165316631673168316931703171317231733174317531763177317831793180318131823183318431853186318731883189319031913192319331943195319631973198319932003201320232033204320532063207320832093210321132123213321432153216321732183219322032213222322332243225322632273228322932303231323232333234323532363237323832393240324132423243324432453246324732483249325032513252325332543255325632573258325932603261326232633264326532663267326832693270327132723273327432753276327732783279328032813282328332843285328632873288328932903291329232933294329532963297329832993300330133023303330433053306330733083309331033113312331333143315331633173318331933203321332233233324332533263327
  1. /*
  2. * USB IBM C-It Video Camera driver
  3. *
  4. * Supports Xirlink C-It Video Camera, IBM PC Camera,
  5. * IBM NetCamera and Veo Stingray.
  6. *
  7. * Copyright (C) 2010 Hans de Goede <hdegoede@redhat.com>
  8. *
  9. * This driver is based on earlier work of:
  10. *
  11. * (C) Copyright 1999 Johannes Erdfelt
  12. * (C) Copyright 1999 Randy Dunlap
  13. *
  14. * This program is free software; you can redistribute it and/or modify
  15. * it under the terms of the GNU General Public License as published by
  16. * the Free Software Foundation; either version 2 of the License, or
  17. * (at your option) any later version.
  18. *
  19. * This program is distributed in the hope that it will be useful,
  20. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  21. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  22. * GNU General Public License for more details.
  23. *
  24. * You should have received a copy of the GNU General Public License
  25. * along with this program; if not, write to the Free Software
  26. * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
  27. *
  28. */
  29. #define pr_fmt(fmt) KBUILD_MODNAME ": " fmt
  30. #define MODULE_NAME "xirlink-cit"
  31. #include <linux/input.h>
  32. #include "gspca.h"
  33. MODULE_AUTHOR("Hans de Goede <hdegoede@redhat.com>");
  34. MODULE_DESCRIPTION("Xirlink C-IT");
  35. MODULE_LICENSE("GPL");
  36. /* FIXME we should autodetect this */
  37. static int ibm_netcam_pro;
  38. module_param(ibm_netcam_pro, int, 0);
  39. MODULE_PARM_DESC(ibm_netcam_pro,
  40. "Use IBM Netcamera Pro init sequences for Model 3 cams");
  41. /* FIXME this should be handled through the V4L2 input selection API */
  42. static int rca_input;
  43. module_param(rca_input, int, 0644);
  44. MODULE_PARM_DESC(rca_input,
  45. "Use rca input instead of ccd sensor on Model 3 cams");
  46. /* specific webcam descriptor */
  47. struct sd {
  48. struct gspca_dev gspca_dev; /* !! must be the first item */
  49. u8 model;
  50. #define CIT_MODEL0 0 /* bcd version 0.01 cams ie the xvp-500 */
  51. #define CIT_MODEL1 1 /* The model 1 - 4 nomenclature comes from the old */
  52. #define CIT_MODEL2 2 /* ibmcam driver */
  53. #define CIT_MODEL3 3
  54. #define CIT_MODEL4 4
  55. #define CIT_IBM_NETCAM_PRO 5
  56. u8 input_index;
  57. u8 button_state;
  58. u8 stop_on_control_change;
  59. u8 sof_read;
  60. u8 sof_len;
  61. u8 contrast;
  62. u8 brightness;
  63. u8 hue;
  64. u8 sharpness;
  65. u8 lighting;
  66. u8 hflip;
  67. };
  68. /* V4L2 controls supported by the driver */
  69. static int sd_setbrightness(struct gspca_dev *gspca_dev, __s32 val);
  70. static int sd_getbrightness(struct gspca_dev *gspca_dev, __s32 *val);
  71. static int sd_setcontrast(struct gspca_dev *gspca_dev, __s32 val);
  72. static int sd_getcontrast(struct gspca_dev *gspca_dev, __s32 *val);
  73. static int sd_sethue(struct gspca_dev *gspca_dev, __s32 val);
  74. static int sd_gethue(struct gspca_dev *gspca_dev, __s32 *val);
  75. static int sd_setsharpness(struct gspca_dev *gspca_dev, __s32 val);
  76. static int sd_getsharpness(struct gspca_dev *gspca_dev, __s32 *val);
  77. static int sd_setlighting(struct gspca_dev *gspca_dev, __s32 val);
  78. static int sd_getlighting(struct gspca_dev *gspca_dev, __s32 *val);
  79. static int sd_sethflip(struct gspca_dev *gspca_dev, __s32 val);
  80. static int sd_gethflip(struct gspca_dev *gspca_dev, __s32 *val);
  81. static void sd_stop0(struct gspca_dev *gspca_dev);
  82. static const struct ctrl sd_ctrls[] = {
  83. #define SD_BRIGHTNESS 0
  84. {
  85. {
  86. .id = V4L2_CID_BRIGHTNESS,
  87. .type = V4L2_CTRL_TYPE_INTEGER,
  88. .name = "Brightness",
  89. .minimum = 0,
  90. .maximum = 63,
  91. .step = 1,
  92. #define BRIGHTNESS_DEFAULT 32
  93. .default_value = BRIGHTNESS_DEFAULT,
  94. .flags = 0,
  95. },
  96. .set = sd_setbrightness,
  97. .get = sd_getbrightness,
  98. },
  99. #define SD_CONTRAST 1
  100. {
  101. {
  102. .id = V4L2_CID_CONTRAST,
  103. .type = V4L2_CTRL_TYPE_INTEGER,
  104. .name = "contrast",
  105. .minimum = 0,
  106. .maximum = 20,
  107. .step = 1,
  108. #define CONTRAST_DEFAULT 10
  109. .default_value = CONTRAST_DEFAULT,
  110. .flags = 0,
  111. },
  112. .set = sd_setcontrast,
  113. .get = sd_getcontrast,
  114. },
  115. #define SD_HUE 2
  116. {
  117. {
  118. .id = V4L2_CID_HUE,
  119. .type = V4L2_CTRL_TYPE_INTEGER,
  120. .name = "Hue",
  121. .minimum = 0,
  122. .maximum = 127,
  123. .step = 1,
  124. #define HUE_DEFAULT 63
  125. .default_value = HUE_DEFAULT,
  126. .flags = 0,
  127. },
  128. .set = sd_sethue,
  129. .get = sd_gethue,
  130. },
  131. #define SD_SHARPNESS 3
  132. {
  133. {
  134. .id = V4L2_CID_SHARPNESS,
  135. .type = V4L2_CTRL_TYPE_INTEGER,
  136. .name = "Sharpness",
  137. .minimum = 0,
  138. .maximum = 6,
  139. .step = 1,
  140. #define SHARPNESS_DEFAULT 3
  141. .default_value = SHARPNESS_DEFAULT,
  142. .flags = 0,
  143. },
  144. .set = sd_setsharpness,
  145. .get = sd_getsharpness,
  146. },
  147. #define SD_LIGHTING 4
  148. {
  149. {
  150. .id = V4L2_CID_BACKLIGHT_COMPENSATION,
  151. .type = V4L2_CTRL_TYPE_INTEGER,
  152. .name = "Lighting",
  153. .minimum = 0,
  154. .maximum = 2,
  155. .step = 1,
  156. #define LIGHTING_DEFAULT 1
  157. .default_value = LIGHTING_DEFAULT,
  158. .flags = 0,
  159. },
  160. .set = sd_setlighting,
  161. .get = sd_getlighting,
  162. },
  163. #define SD_HFLIP 5
  164. {
  165. {
  166. .id = V4L2_CID_HFLIP,
  167. .type = V4L2_CTRL_TYPE_BOOLEAN,
  168. .name = "Mirror",
  169. .minimum = 0,
  170. .maximum = 1,
  171. .step = 1,
  172. #define HFLIP_DEFAULT 0
  173. .default_value = HFLIP_DEFAULT,
  174. },
  175. .set = sd_sethflip,
  176. .get = sd_gethflip,
  177. },
  178. };
  179. static const struct v4l2_pix_format cif_yuv_mode[] = {
  180. {176, 144, V4L2_PIX_FMT_CIT_YYVYUY, V4L2_FIELD_NONE,
  181. .bytesperline = 176,
  182. .sizeimage = 176 * 144 * 3 / 2 + 4,
  183. .colorspace = V4L2_COLORSPACE_SRGB},
  184. {352, 288, V4L2_PIX_FMT_CIT_YYVYUY, V4L2_FIELD_NONE,
  185. .bytesperline = 352,
  186. .sizeimage = 352 * 288 * 3 / 2 + 4,
  187. .colorspace = V4L2_COLORSPACE_SRGB},
  188. };
  189. static const struct v4l2_pix_format vga_yuv_mode[] = {
  190. {160, 120, V4L2_PIX_FMT_CIT_YYVYUY, V4L2_FIELD_NONE,
  191. .bytesperline = 160,
  192. .sizeimage = 160 * 120 * 3 / 2 + 4,
  193. .colorspace = V4L2_COLORSPACE_SRGB},
  194. {320, 240, V4L2_PIX_FMT_CIT_YYVYUY, V4L2_FIELD_NONE,
  195. .bytesperline = 320,
  196. .sizeimage = 320 * 240 * 3 / 2 + 4,
  197. .colorspace = V4L2_COLORSPACE_SRGB},
  198. {640, 480, V4L2_PIX_FMT_CIT_YYVYUY, V4L2_FIELD_NONE,
  199. .bytesperline = 640,
  200. .sizeimage = 640 * 480 * 3 / 2 + 4,
  201. .colorspace = V4L2_COLORSPACE_SRGB},
  202. };
  203. static const struct v4l2_pix_format model0_mode[] = {
  204. {160, 120, V4L2_PIX_FMT_CIT_YYVYUY, V4L2_FIELD_NONE,
  205. .bytesperline = 160,
  206. .sizeimage = 160 * 120 * 3 / 2 + 4,
  207. .colorspace = V4L2_COLORSPACE_SRGB},
  208. {176, 144, V4L2_PIX_FMT_CIT_YYVYUY, V4L2_FIELD_NONE,
  209. .bytesperline = 176,
  210. .sizeimage = 176 * 144 * 3 / 2 + 4,
  211. .colorspace = V4L2_COLORSPACE_SRGB},
  212. {320, 240, V4L2_PIX_FMT_CIT_YYVYUY, V4L2_FIELD_NONE,
  213. .bytesperline = 320,
  214. .sizeimage = 320 * 240 * 3 / 2 + 4,
  215. .colorspace = V4L2_COLORSPACE_SRGB},
  216. };
  217. static const struct v4l2_pix_format model2_mode[] = {
  218. {160, 120, V4L2_PIX_FMT_CIT_YYVYUY, V4L2_FIELD_NONE,
  219. .bytesperline = 160,
  220. .sizeimage = 160 * 120 * 3 / 2 + 4,
  221. .colorspace = V4L2_COLORSPACE_SRGB},
  222. {176, 144, V4L2_PIX_FMT_CIT_YYVYUY, V4L2_FIELD_NONE,
  223. .bytesperline = 176,
  224. .sizeimage = 176 * 144 * 3 / 2 + 4,
  225. .colorspace = V4L2_COLORSPACE_SRGB},
  226. {320, 240, V4L2_PIX_FMT_SGRBG8, V4L2_FIELD_NONE,
  227. .bytesperline = 320,
  228. .sizeimage = 320 * 240 + 4,
  229. .colorspace = V4L2_COLORSPACE_SRGB},
  230. {352, 288, V4L2_PIX_FMT_SGRBG8, V4L2_FIELD_NONE,
  231. .bytesperline = 352,
  232. .sizeimage = 352 * 288 + 4,
  233. .colorspace = V4L2_COLORSPACE_SRGB},
  234. };
  235. /*
  236. * 01.01.08 - Added for RCA video in support -LO
  237. * This struct is used to init the Model3 cam to use the RCA video in port
  238. * instead of the CCD sensor.
  239. */
  240. static const u16 rca_initdata[][3] = {
  241. {0, 0x0000, 0x010c},
  242. {0, 0x0006, 0x012c},
  243. {0, 0x0078, 0x012d},
  244. {0, 0x0046, 0x012f},
  245. {0, 0xd141, 0x0124},
  246. {0, 0x0000, 0x0127},
  247. {0, 0xfea8, 0x0124},
  248. {1, 0x0000, 0x0116},
  249. {0, 0x0064, 0x0116},
  250. {1, 0x0000, 0x0115},
  251. {0, 0x0003, 0x0115},
  252. {0, 0x0008, 0x0123},
  253. {0, 0x0000, 0x0117},
  254. {0, 0x0000, 0x0112},
  255. {0, 0x0080, 0x0100},
  256. {0, 0x0000, 0x0100},
  257. {1, 0x0000, 0x0116},
  258. {0, 0x0060, 0x0116},
  259. {0, 0x0002, 0x0112},
  260. {0, 0x0000, 0x0123},
  261. {0, 0x0001, 0x0117},
  262. {0, 0x0040, 0x0108},
  263. {0, 0x0019, 0x012c},
  264. {0, 0x0040, 0x0116},
  265. {0, 0x000a, 0x0115},
  266. {0, 0x000b, 0x0115},
  267. {0, 0x0078, 0x012d},
  268. {0, 0x0046, 0x012f},
  269. {0, 0xd141, 0x0124},
  270. {0, 0x0000, 0x0127},
  271. {0, 0xfea8, 0x0124},
  272. {0, 0x0064, 0x0116},
  273. {0, 0x0000, 0x0115},
  274. {0, 0x0001, 0x0115},
  275. {0, 0xffff, 0x0124},
  276. {0, 0xfff9, 0x0124},
  277. {0, 0x0086, 0x0127},
  278. {0, 0xfff8, 0x0124},
  279. {0, 0xfffd, 0x0124},
  280. {0, 0x00aa, 0x0127},
  281. {0, 0xfff8, 0x0124},
  282. {0, 0xfffd, 0x0124},
  283. {0, 0x0000, 0x0127},
  284. {0, 0xfff8, 0x0124},
  285. {0, 0xfffd, 0x0124},
  286. {0, 0xfffa, 0x0124},
  287. {0, 0xffff, 0x0124},
  288. {0, 0xfff9, 0x0124},
  289. {0, 0x0086, 0x0127},
  290. {0, 0xfff8, 0x0124},
  291. {0, 0xfffd, 0x0124},
  292. {0, 0x00f2, 0x0127},
  293. {0, 0xfff8, 0x0124},
  294. {0, 0xfffd, 0x0124},
  295. {0, 0x000f, 0x0127},
  296. {0, 0xfff8, 0x0124},
  297. {0, 0xfffd, 0x0124},
  298. {0, 0xfffa, 0x0124},
  299. {0, 0xffff, 0x0124},
  300. {0, 0xfff9, 0x0124},
  301. {0, 0x0086, 0x0127},
  302. {0, 0xfff8, 0x0124},
  303. {0, 0xfffd, 0x0124},
  304. {0, 0x00f8, 0x0127},
  305. {0, 0xfff8, 0x0124},
  306. {0, 0xfffd, 0x0124},
  307. {0, 0x00fc, 0x0127},
  308. {0, 0xfff8, 0x0124},
  309. {0, 0xfffd, 0x0124},
  310. {0, 0xfffa, 0x0124},
  311. {0, 0xffff, 0x0124},
  312. {0, 0xfff9, 0x0124},
  313. {0, 0x0086, 0x0127},
  314. {0, 0xfff8, 0x0124},
  315. {0, 0xfffd, 0x0124},
  316. {0, 0x00f9, 0x0127},
  317. {0, 0xfff8, 0x0124},
  318. {0, 0xfffd, 0x0124},
  319. {0, 0x003c, 0x0127},
  320. {0, 0xfff8, 0x0124},
  321. {0, 0xfffd, 0x0124},
  322. {0, 0xfffa, 0x0124},
  323. {0, 0xffff, 0x0124},
  324. {0, 0xfff9, 0x0124},
  325. {0, 0x0086, 0x0127},
  326. {0, 0xfff8, 0x0124},
  327. {0, 0xfffd, 0x0124},
  328. {0, 0x0027, 0x0127},
  329. {0, 0xfff8, 0x0124},
  330. {0, 0xfffd, 0x0124},
  331. {0, 0x0019, 0x0127},
  332. {0, 0xfff8, 0x0124},
  333. {0, 0xfffd, 0x0124},
  334. {0, 0xfffa, 0x0124},
  335. {0, 0xfff9, 0x0124},
  336. {0, 0x0086, 0x0127},
  337. {0, 0xfff8, 0x0124},
  338. {0, 0xfffd, 0x0124},
  339. {0, 0x0037, 0x0127},
  340. {0, 0xfff8, 0x0124},
  341. {0, 0xfffd, 0x0124},
  342. {0, 0x0000, 0x0127},
  343. {0, 0xfff8, 0x0124},
  344. {0, 0xfffd, 0x0124},
  345. {0, 0x0021, 0x0127},
  346. {0, 0xfff8, 0x0124},
  347. {0, 0xfffd, 0x0124},
  348. {0, 0xfffa, 0x0124},
  349. {0, 0xfff9, 0x0124},
  350. {0, 0x0086, 0x0127},
  351. {0, 0xfff8, 0x0124},
  352. {0, 0xfffd, 0x0124},
  353. {0, 0x0038, 0x0127},
  354. {0, 0xfff8, 0x0124},
  355. {0, 0xfffd, 0x0124},
  356. {0, 0x0006, 0x0127},
  357. {0, 0xfff8, 0x0124},
  358. {0, 0xfffd, 0x0124},
  359. {0, 0x0045, 0x0127},
  360. {0, 0xfff8, 0x0124},
  361. {0, 0xfffd, 0x0124},
  362. {0, 0xfffa, 0x0124},
  363. {0, 0xfff9, 0x0124},
  364. {0, 0x0086, 0x0127},
  365. {0, 0xfff8, 0x0124},
  366. {0, 0xfffd, 0x0124},
  367. {0, 0x0037, 0x0127},
  368. {0, 0xfff8, 0x0124},
  369. {0, 0xfffd, 0x0124},
  370. {0, 0x0001, 0x0127},
  371. {0, 0xfff8, 0x0124},
  372. {0, 0xfffd, 0x0124},
  373. {0, 0x002a, 0x0127},
  374. {0, 0xfff8, 0x0124},
  375. {0, 0xfffd, 0x0124},
  376. {0, 0xfffa, 0x0124},
  377. {0, 0xfff9, 0x0124},
  378. {0, 0x0086, 0x0127},
  379. {0, 0xfff8, 0x0124},
  380. {0, 0xfffd, 0x0124},
  381. {0, 0x0038, 0x0127},
  382. {0, 0xfff8, 0x0124},
  383. {0, 0xfffd, 0x0124},
  384. {0, 0x0000, 0x0127},
  385. {0, 0xfff8, 0x0124},
  386. {0, 0xfffd, 0x0124},
  387. {0, 0x000e, 0x0127},
  388. {0, 0xfff8, 0x0124},
  389. {0, 0xfffd, 0x0124},
  390. {0, 0xfffa, 0x0124},
  391. {0, 0xfff9, 0x0124},
  392. {0, 0x0086, 0x0127},
  393. {0, 0xfff8, 0x0124},
  394. {0, 0xfffd, 0x0124},
  395. {0, 0x0037, 0x0127},
  396. {0, 0xfff8, 0x0124},
  397. {0, 0xfffd, 0x0124},
  398. {0, 0x0001, 0x0127},
  399. {0, 0xfff8, 0x0124},
  400. {0, 0xfffd, 0x0124},
  401. {0, 0x002b, 0x0127},
  402. {0, 0xfff8, 0x0124},
  403. {0, 0xfffd, 0x0124},
  404. {0, 0xfffa, 0x0124},
  405. {0, 0xfff9, 0x0124},
  406. {0, 0x0086, 0x0127},
  407. {0, 0xfff8, 0x0124},
  408. {0, 0xfffd, 0x0124},
  409. {0, 0x0038, 0x0127},
  410. {0, 0xfff8, 0x0124},
  411. {0, 0xfffd, 0x0124},
  412. {0, 0x0001, 0x0127},
  413. {0, 0xfff8, 0x0124},
  414. {0, 0xfffd, 0x0124},
  415. {0, 0x00f4, 0x0127},
  416. {0, 0xfff8, 0x0124},
  417. {0, 0xfffd, 0x0124},
  418. {0, 0xfffa, 0x0124},
  419. {0, 0xfff9, 0x0124},
  420. {0, 0x0086, 0x0127},
  421. {0, 0xfff8, 0x0124},
  422. {0, 0xfffd, 0x0124},
  423. {0, 0x0037, 0x0127},
  424. {0, 0xfff8, 0x0124},
  425. {0, 0xfffd, 0x0124},
  426. {0, 0x0001, 0x0127},
  427. {0, 0xfff8, 0x0124},
  428. {0, 0xfffd, 0x0124},
  429. {0, 0x002c, 0x0127},
  430. {0, 0xfff8, 0x0124},
  431. {0, 0xfffd, 0x0124},
  432. {0, 0xfffa, 0x0124},
  433. {0, 0xfff9, 0x0124},
  434. {0, 0x0086, 0x0127},
  435. {0, 0xfff8, 0x0124},
  436. {0, 0xfffd, 0x0124},
  437. {0, 0x0038, 0x0127},
  438. {0, 0xfff8, 0x0124},
  439. {0, 0xfffd, 0x0124},
  440. {0, 0x0001, 0x0127},
  441. {0, 0xfff8, 0x0124},
  442. {0, 0xfffd, 0x0124},
  443. {0, 0x0004, 0x0127},
  444. {0, 0xfff8, 0x0124},
  445. {0, 0xfffd, 0x0124},
  446. {0, 0xfffa, 0x0124},
  447. {0, 0xfff9, 0x0124},
  448. {0, 0x0086, 0x0127},
  449. {0, 0xfff8, 0x0124},
  450. {0, 0xfffd, 0x0124},
  451. {0, 0x0037, 0x0127},
  452. {0, 0xfff8, 0x0124},
  453. {0, 0xfffd, 0x0124},
  454. {0, 0x0001, 0x0127},
  455. {0, 0xfff8, 0x0124},
  456. {0, 0xfffd, 0x0124},
  457. {0, 0x002d, 0x0127},
  458. {0, 0xfff8, 0x0124},
  459. {0, 0xfffd, 0x0124},
  460. {0, 0xfffa, 0x0124},
  461. {0, 0xfff9, 0x0124},
  462. {0, 0x0086, 0x0127},
  463. {0, 0xfff8, 0x0124},
  464. {0, 0xfffd, 0x0124},
  465. {0, 0x0038, 0x0127},
  466. {0, 0xfff8, 0x0124},
  467. {0, 0xfffd, 0x0124},
  468. {0, 0x0000, 0x0127},
  469. {0, 0xfff8, 0x0124},
  470. {0, 0xfffd, 0x0124},
  471. {0, 0x0014, 0x0127},
  472. {0, 0xfff8, 0x0124},
  473. {0, 0xfffd, 0x0124},
  474. {0, 0xfffa, 0x0124},
  475. {0, 0xfff9, 0x0124},
  476. {0, 0x0086, 0x0127},
  477. {0, 0xfff8, 0x0124},
  478. {0, 0xfffd, 0x0124},
  479. {0, 0x0037, 0x0127},
  480. {0, 0xfff8, 0x0124},
  481. {0, 0xfffd, 0x0124},
  482. {0, 0x0001, 0x0127},
  483. {0, 0xfff8, 0x0124},
  484. {0, 0xfffd, 0x0124},
  485. {0, 0x002e, 0x0127},
  486. {0, 0xfff8, 0x0124},
  487. {0, 0xfffd, 0x0124},
  488. {0, 0xfffa, 0x0124},
  489. {0, 0xfff9, 0x0124},
  490. {0, 0x0086, 0x0127},
  491. {0, 0xfff8, 0x0124},
  492. {0, 0xfffd, 0x0124},
  493. {0, 0x0038, 0x0127},
  494. {0, 0xfff8, 0x0124},
  495. {0, 0xfffd, 0x0124},
  496. {0, 0x0003, 0x0127},
  497. {0, 0xfff8, 0x0124},
  498. {0, 0xfffd, 0x0124},
  499. {0, 0x0000, 0x0127},
  500. {0, 0xfff8, 0x0124},
  501. {0, 0xfffd, 0x0124},
  502. {0, 0xfffa, 0x0124},
  503. {0, 0xfff9, 0x0124},
  504. {0, 0x0086, 0x0127},
  505. {0, 0xfff8, 0x0124},
  506. {0, 0xfffd, 0x0124},
  507. {0, 0x0037, 0x0127},
  508. {0, 0xfff8, 0x0124},
  509. {0, 0xfffd, 0x0124},
  510. {0, 0x0001, 0x0127},
  511. {0, 0xfff8, 0x0124},
  512. {0, 0xfffd, 0x0124},
  513. {0, 0x002f, 0x0127},
  514. {0, 0xfff8, 0x0124},
  515. {0, 0xfffd, 0x0124},
  516. {0, 0xfffa, 0x0124},
  517. {0, 0xfff9, 0x0124},
  518. {0, 0x0086, 0x0127},
  519. {0, 0xfff8, 0x0124},
  520. {0, 0xfffd, 0x0124},
  521. {0, 0x0038, 0x0127},
  522. {0, 0xfff8, 0x0124},
  523. {0, 0xfffd, 0x0124},
  524. {0, 0x0003, 0x0127},
  525. {0, 0xfff8, 0x0124},
  526. {0, 0xfffd, 0x0124},
  527. {0, 0x0014, 0x0127},
  528. {0, 0xfff8, 0x0124},
  529. {0, 0xfffd, 0x0124},
  530. {0, 0xfffa, 0x0124},
  531. {0, 0xfff9, 0x0124},
  532. {0, 0x0086, 0x0127},
  533. {0, 0xfff8, 0x0124},
  534. {0, 0xfffd, 0x0124},
  535. {0, 0x0037, 0x0127},
  536. {0, 0xfff8, 0x0124},
  537. {0, 0xfffd, 0x0124},
  538. {0, 0x0001, 0x0127},
  539. {0, 0xfff8, 0x0124},
  540. {0, 0xfffd, 0x0124},
  541. {0, 0x0040, 0x0127},
  542. {0, 0xfff8, 0x0124},
  543. {0, 0xfffd, 0x0124},
  544. {0, 0xfffa, 0x0124},
  545. {0, 0xfff9, 0x0124},
  546. {0, 0x0086, 0x0127},
  547. {0, 0xfff8, 0x0124},
  548. {0, 0xfffd, 0x0124},
  549. {0, 0x0038, 0x0127},
  550. {0, 0xfff8, 0x0124},
  551. {0, 0xfffd, 0x0124},
  552. {0, 0x0000, 0x0127},
  553. {0, 0xfff8, 0x0124},
  554. {0, 0xfffd, 0x0124},
  555. {0, 0x0040, 0x0127},
  556. {0, 0xfff8, 0x0124},
  557. {0, 0xfffd, 0x0124},
  558. {0, 0xfffa, 0x0124},
  559. {0, 0xfff9, 0x0124},
  560. {0, 0x0086, 0x0127},
  561. {0, 0xfff8, 0x0124},
  562. {0, 0xfffd, 0x0124},
  563. {0, 0x0037, 0x0127},
  564. {0, 0xfff8, 0x0124},
  565. {0, 0xfffd, 0x0124},
  566. {0, 0x0001, 0x0127},
  567. {0, 0xfff8, 0x0124},
  568. {0, 0xfffd, 0x0124},
  569. {0, 0x0053, 0x0127},
  570. {0, 0xfff8, 0x0124},
  571. {0, 0xfffd, 0x0124},
  572. {0, 0xfffa, 0x0124},
  573. {0, 0xfff9, 0x0124},
  574. {0, 0x0086, 0x0127},
  575. {0, 0xfff8, 0x0124},
  576. {0, 0xfffd, 0x0124},
  577. {0, 0x0038, 0x0127},
  578. {0, 0xfff8, 0x0124},
  579. {0, 0xfffd, 0x0124},
  580. {0, 0x0000, 0x0127},
  581. {0, 0xfff8, 0x0124},
  582. {0, 0xfffd, 0x0124},
  583. {0, 0x0038, 0x0127},
  584. {0, 0xfff8, 0x0124},
  585. {0, 0xfffd, 0x0124},
  586. {0, 0xfffa, 0x0124},
  587. {0, 0x0000, 0x0101},
  588. {0, 0x00a0, 0x0103},
  589. {0, 0x0078, 0x0105},
  590. {0, 0x0000, 0x010a},
  591. {0, 0x0024, 0x010b},
  592. {0, 0x0028, 0x0119},
  593. {0, 0x0088, 0x011b},
  594. {0, 0x0002, 0x011d},
  595. {0, 0x0003, 0x011e},
  596. {0, 0x0000, 0x0129},
  597. {0, 0x00fc, 0x012b},
  598. {0, 0x0008, 0x0102},
  599. {0, 0x0000, 0x0104},
  600. {0, 0x0008, 0x011a},
  601. {0, 0x0028, 0x011c},
  602. {0, 0x0021, 0x012a},
  603. {0, 0x0000, 0x0118},
  604. {0, 0x0000, 0x0132},
  605. {0, 0x0000, 0x0109},
  606. {0, 0xfff9, 0x0124},
  607. {0, 0x0086, 0x0127},
  608. {0, 0xfff8, 0x0124},
  609. {0, 0xfffd, 0x0124},
  610. {0, 0x0037, 0x0127},
  611. {0, 0xfff8, 0x0124},
  612. {0, 0xfffd, 0x0124},
  613. {0, 0x0001, 0x0127},
  614. {0, 0xfff8, 0x0124},
  615. {0, 0xfffd, 0x0124},
  616. {0, 0x0031, 0x0127},
  617. {0, 0xfff8, 0x0124},
  618. {0, 0xfffd, 0x0124},
  619. {0, 0xfffa, 0x0124},
  620. {0, 0xfff9, 0x0124},
  621. {0, 0x0086, 0x0127},
  622. {0, 0xfff8, 0x0124},
  623. {0, 0xfffd, 0x0124},
  624. {0, 0x0038, 0x0127},
  625. {0, 0xfff8, 0x0124},
  626. {0, 0xfffd, 0x0124},
  627. {0, 0x0000, 0x0127},
  628. {0, 0xfff8, 0x0124},
  629. {0, 0xfffd, 0x0124},
  630. {0, 0x0000, 0x0127},
  631. {0, 0xfff8, 0x0124},
  632. {0, 0xfffd, 0x0124},
  633. {0, 0xfffa, 0x0124},
  634. {0, 0xfff9, 0x0124},
  635. {0, 0x0086, 0x0127},
  636. {0, 0xfff8, 0x0124},
  637. {0, 0xfffd, 0x0124},
  638. {0, 0x0037, 0x0127},
  639. {0, 0xfff8, 0x0124},
  640. {0, 0xfffd, 0x0124},
  641. {0, 0x0001, 0x0127},
  642. {0, 0xfff8, 0x0124},
  643. {0, 0xfffd, 0x0124},
  644. {0, 0x0040, 0x0127},
  645. {0, 0xfff8, 0x0124},
  646. {0, 0xfffd, 0x0124},
  647. {0, 0xfffa, 0x0124},
  648. {0, 0xfff9, 0x0124},
  649. {0, 0x0086, 0x0127},
  650. {0, 0xfff8, 0x0124},
  651. {0, 0xfffd, 0x0124},
  652. {0, 0x0038, 0x0127},
  653. {0, 0xfff8, 0x0124},
  654. {0, 0xfffd, 0x0124},
  655. {0, 0x0000, 0x0127},
  656. {0, 0xfff8, 0x0124},
  657. {0, 0xfffd, 0x0124},
  658. {0, 0x0040, 0x0127},
  659. {0, 0xfff8, 0x0124},
  660. {0, 0xfffd, 0x0124},
  661. {0, 0xfffa, 0x0124},
  662. {0, 0xfff9, 0x0124},
  663. {0, 0x0086, 0x0127},
  664. {0, 0xfff8, 0x0124},
  665. {0, 0xfffd, 0x0124},
  666. {0, 0x0037, 0x0127},
  667. {0, 0xfff8, 0x0124},
  668. {0, 0xfffd, 0x0124},
  669. {0, 0x0000, 0x0127},
  670. {0, 0xfff8, 0x0124},
  671. {0, 0xfffd, 0x0124},
  672. {0, 0x00dc, 0x0127},
  673. {0, 0xfff8, 0x0124},
  674. {0, 0xfffd, 0x0124},
  675. {0, 0xfffa, 0x0124},
  676. {0, 0xfff9, 0x0124},
  677. {0, 0x0086, 0x0127},
  678. {0, 0xfff8, 0x0124},
  679. {0, 0xfffd, 0x0124},
  680. {0, 0x0038, 0x0127},
  681. {0, 0xfff8, 0x0124},
  682. {0, 0xfffd, 0x0124},
  683. {0, 0x0000, 0x0127},
  684. {0, 0xfff8, 0x0124},
  685. {0, 0xfffd, 0x0124},
  686. {0, 0x0000, 0x0127},
  687. {0, 0xfff8, 0x0124},
  688. {0, 0xfffd, 0x0124},
  689. {0, 0xfffa, 0x0124},
  690. {0, 0xfff9, 0x0124},
  691. {0, 0x0086, 0x0127},
  692. {0, 0xfff8, 0x0124},
  693. {0, 0xfffd, 0x0124},
  694. {0, 0x0037, 0x0127},
  695. {0, 0xfff8, 0x0124},
  696. {0, 0xfffd, 0x0124},
  697. {0, 0x0001, 0x0127},
  698. {0, 0xfff8, 0x0124},
  699. {0, 0xfffd, 0x0124},
  700. {0, 0x0032, 0x0127},
  701. {0, 0xfff8, 0x0124},
  702. {0, 0xfffd, 0x0124},
  703. {0, 0xfffa, 0x0124},
  704. {0, 0xfff9, 0x0124},
  705. {0, 0x0086, 0x0127},
  706. {0, 0xfff8, 0x0124},
  707. {0, 0xfffd, 0x0124},
  708. {0, 0x0038, 0x0127},
  709. {0, 0xfff8, 0x0124},
  710. {0, 0xfffd, 0x0124},
  711. {0, 0x0001, 0x0127},
  712. {0, 0xfff8, 0x0124},
  713. {0, 0xfffd, 0x0124},
  714. {0, 0x0020, 0x0127},
  715. {0, 0xfff8, 0x0124},
  716. {0, 0xfffd, 0x0124},
  717. {0, 0xfffa, 0x0124},
  718. {0, 0xfff9, 0x0124},
  719. {0, 0x0086, 0x0127},
  720. {0, 0xfff8, 0x0124},
  721. {0, 0xfffd, 0x0124},
  722. {0, 0x0037, 0x0127},
  723. {0, 0xfff8, 0x0124},
  724. {0, 0xfffd, 0x0124},
  725. {0, 0x0001, 0x0127},
  726. {0, 0xfff8, 0x0124},
  727. {0, 0xfffd, 0x0124},
  728. {0, 0x0040, 0x0127},
  729. {0, 0xfff8, 0x0124},
  730. {0, 0xfffd, 0x0124},
  731. {0, 0xfffa, 0x0124},
  732. {0, 0xfff9, 0x0124},
  733. {0, 0x0086, 0x0127},
  734. {0, 0xfff8, 0x0124},
  735. {0, 0xfffd, 0x0124},
  736. {0, 0x0038, 0x0127},
  737. {0, 0xfff8, 0x0124},
  738. {0, 0xfffd, 0x0124},
  739. {0, 0x0000, 0x0127},
  740. {0, 0xfff8, 0x0124},
  741. {0, 0xfffd, 0x0124},
  742. {0, 0x0040, 0x0127},
  743. {0, 0xfff8, 0x0124},
  744. {0, 0xfffd, 0x0124},
  745. {0, 0xfffa, 0x0124},
  746. {0, 0xfff9, 0x0124},
  747. {0, 0x0086, 0x0127},
  748. {0, 0xfff8, 0x0124},
  749. {0, 0xfffd, 0x0124},
  750. {0, 0x0037, 0x0127},
  751. {0, 0xfff8, 0x0124},
  752. {0, 0xfffd, 0x0124},
  753. {0, 0x0000, 0x0127},
  754. {0, 0xfff8, 0x0124},
  755. {0, 0xfffd, 0x0124},
  756. {0, 0x0030, 0x0127},
  757. {0, 0xfff8, 0x0124},
  758. {0, 0xfffd, 0x0124},
  759. {0, 0xfffa, 0x0124},
  760. {0, 0xfff9, 0x0124},
  761. {0, 0x0086, 0x0127},
  762. {0, 0xfff8, 0x0124},
  763. {0, 0xfffd, 0x0124},
  764. {0, 0x0038, 0x0127},
  765. {0, 0xfff8, 0x0124},
  766. {0, 0xfffd, 0x0124},
  767. {0, 0x0008, 0x0127},
  768. {0, 0xfff8, 0x0124},
  769. {0, 0xfffd, 0x0124},
  770. {0, 0x0000, 0x0127},
  771. {0, 0xfff8, 0x0124},
  772. {0, 0xfffd, 0x0124},
  773. {0, 0xfffa, 0x0124},
  774. {0, 0x0003, 0x0111},
  775. };
  776. /* TESTME the old ibmcam driver repeats certain commands to Model1 cameras, we
  777. do the same for now (testing needed to see if this is really necessary) */
  778. static const int cit_model1_ntries = 5;
  779. static const int cit_model1_ntries2 = 2;
  780. static int cit_write_reg(struct gspca_dev *gspca_dev, u16 value, u16 index)
  781. {
  782. struct usb_device *udev = gspca_dev->dev;
  783. int err;
  784. err = usb_control_msg(udev, usb_sndctrlpipe(udev, 0), 0x00,
  785. USB_DIR_OUT | USB_TYPE_VENDOR | USB_RECIP_ENDPOINT,
  786. value, index, NULL, 0, 1000);
  787. if (err < 0)
  788. pr_err("Failed to write a register (index 0x%04X, value 0x%02X, error %d)\n",
  789. index, value, err);
  790. return 0;
  791. }
  792. static int cit_read_reg(struct gspca_dev *gspca_dev, u16 index, int verbose)
  793. {
  794. struct usb_device *udev = gspca_dev->dev;
  795. __u8 *buf = gspca_dev->usb_buf;
  796. int res;
  797. res = usb_control_msg(udev, usb_rcvctrlpipe(udev, 0), 0x01,
  798. USB_DIR_IN | USB_TYPE_VENDOR | USB_RECIP_ENDPOINT,
  799. 0x00, index, buf, 8, 1000);
  800. if (res < 0) {
  801. pr_err("Failed to read a register (index 0x%04X, error %d)\n",
  802. index, res);
  803. return res;
  804. }
  805. if (verbose)
  806. PDEBUG(D_PROBE, "Register %04x value: %02x", index, buf[0]);
  807. return 0;
  808. }
  809. /*
  810. * cit_send_FF_04_02()
  811. *
  812. * This procedure sends magic 3-command prefix to the camera.
  813. * The purpose of this prefix is not known.
  814. *
  815. * History:
  816. * 1/2/00 Created.
  817. */
  818. static void cit_send_FF_04_02(struct gspca_dev *gspca_dev)
  819. {
  820. cit_write_reg(gspca_dev, 0x00FF, 0x0127);
  821. cit_write_reg(gspca_dev, 0x0004, 0x0124);
  822. cit_write_reg(gspca_dev, 0x0002, 0x0124);
  823. }
  824. static void cit_send_00_04_06(struct gspca_dev *gspca_dev)
  825. {
  826. cit_write_reg(gspca_dev, 0x0000, 0x0127);
  827. cit_write_reg(gspca_dev, 0x0004, 0x0124);
  828. cit_write_reg(gspca_dev, 0x0006, 0x0124);
  829. }
  830. static void cit_send_x_00(struct gspca_dev *gspca_dev, unsigned short x)
  831. {
  832. cit_write_reg(gspca_dev, x, 0x0127);
  833. cit_write_reg(gspca_dev, 0x0000, 0x0124);
  834. }
  835. static void cit_send_x_00_05(struct gspca_dev *gspca_dev, unsigned short x)
  836. {
  837. cit_send_x_00(gspca_dev, x);
  838. cit_write_reg(gspca_dev, 0x0005, 0x0124);
  839. }
  840. static void cit_send_x_00_05_02(struct gspca_dev *gspca_dev, unsigned short x)
  841. {
  842. cit_write_reg(gspca_dev, x, 0x0127);
  843. cit_write_reg(gspca_dev, 0x0000, 0x0124);
  844. cit_write_reg(gspca_dev, 0x0005, 0x0124);
  845. cit_write_reg(gspca_dev, 0x0002, 0x0124);
  846. }
  847. static void cit_send_x_01_00_05(struct gspca_dev *gspca_dev, u16 x)
  848. {
  849. cit_write_reg(gspca_dev, x, 0x0127);
  850. cit_write_reg(gspca_dev, 0x0001, 0x0124);
  851. cit_write_reg(gspca_dev, 0x0000, 0x0124);
  852. cit_write_reg(gspca_dev, 0x0005, 0x0124);
  853. }
  854. static void cit_send_x_00_05_02_01(struct gspca_dev *gspca_dev, u16 x)
  855. {
  856. cit_write_reg(gspca_dev, x, 0x0127);
  857. cit_write_reg(gspca_dev, 0x0000, 0x0124);
  858. cit_write_reg(gspca_dev, 0x0005, 0x0124);
  859. cit_write_reg(gspca_dev, 0x0002, 0x0124);
  860. cit_write_reg(gspca_dev, 0x0001, 0x0124);
  861. }
  862. static void cit_send_x_00_05_02_08_01(struct gspca_dev *gspca_dev, u16 x)
  863. {
  864. cit_write_reg(gspca_dev, x, 0x0127);
  865. cit_write_reg(gspca_dev, 0x0000, 0x0124);
  866. cit_write_reg(gspca_dev, 0x0005, 0x0124);
  867. cit_write_reg(gspca_dev, 0x0002, 0x0124);
  868. cit_write_reg(gspca_dev, 0x0008, 0x0124);
  869. cit_write_reg(gspca_dev, 0x0001, 0x0124);
  870. }
  871. static void cit_Packet_Format1(struct gspca_dev *gspca_dev, u16 fkey, u16 val)
  872. {
  873. cit_send_x_01_00_05(gspca_dev, 0x0088);
  874. cit_send_x_00_05(gspca_dev, fkey);
  875. cit_send_x_00_05_02_08_01(gspca_dev, val);
  876. cit_send_x_00_05(gspca_dev, 0x0088);
  877. cit_send_x_00_05_02_01(gspca_dev, fkey);
  878. cit_send_x_00_05(gspca_dev, 0x0089);
  879. cit_send_x_00(gspca_dev, fkey);
  880. cit_send_00_04_06(gspca_dev);
  881. cit_read_reg(gspca_dev, 0x0126, 0);
  882. cit_send_FF_04_02(gspca_dev);
  883. }
  884. static void cit_PacketFormat2(struct gspca_dev *gspca_dev, u16 fkey, u16 val)
  885. {
  886. cit_send_x_01_00_05(gspca_dev, 0x0088);
  887. cit_send_x_00_05(gspca_dev, fkey);
  888. cit_send_x_00_05_02(gspca_dev, val);
  889. }
  890. static void cit_model2_Packet2(struct gspca_dev *gspca_dev)
  891. {
  892. cit_write_reg(gspca_dev, 0x00ff, 0x012d);
  893. cit_write_reg(gspca_dev, 0xfea3, 0x0124);
  894. }
  895. static void cit_model2_Packet1(struct gspca_dev *gspca_dev, u16 v1, u16 v2)
  896. {
  897. cit_write_reg(gspca_dev, 0x00aa, 0x012d);
  898. cit_write_reg(gspca_dev, 0x00ff, 0x012e);
  899. cit_write_reg(gspca_dev, v1, 0x012f);
  900. cit_write_reg(gspca_dev, 0x00ff, 0x0130);
  901. cit_write_reg(gspca_dev, 0xc719, 0x0124);
  902. cit_write_reg(gspca_dev, v2, 0x0127);
  903. cit_model2_Packet2(gspca_dev);
  904. }
  905. /*
  906. * cit_model3_Packet1()
  907. *
  908. * 00_0078_012d
  909. * 00_0097_012f
  910. * 00_d141_0124
  911. * 00_0096_0127
  912. * 00_fea8_0124
  913. */
  914. static void cit_model3_Packet1(struct gspca_dev *gspca_dev, u16 v1, u16 v2)
  915. {
  916. cit_write_reg(gspca_dev, 0x0078, 0x012d);
  917. cit_write_reg(gspca_dev, v1, 0x012f);
  918. cit_write_reg(gspca_dev, 0xd141, 0x0124);
  919. cit_write_reg(gspca_dev, v2, 0x0127);
  920. cit_write_reg(gspca_dev, 0xfea8, 0x0124);
  921. }
  922. static void cit_model4_Packet1(struct gspca_dev *gspca_dev, u16 v1, u16 v2)
  923. {
  924. cit_write_reg(gspca_dev, 0x00aa, 0x012d);
  925. cit_write_reg(gspca_dev, v1, 0x012f);
  926. cit_write_reg(gspca_dev, 0xd141, 0x0124);
  927. cit_write_reg(gspca_dev, v2, 0x0127);
  928. cit_write_reg(gspca_dev, 0xfea8, 0x0124);
  929. }
  930. static void cit_model4_BrightnessPacket(struct gspca_dev *gspca_dev, u16 val)
  931. {
  932. cit_write_reg(gspca_dev, 0x00aa, 0x012d);
  933. cit_write_reg(gspca_dev, 0x0026, 0x012f);
  934. cit_write_reg(gspca_dev, 0xd141, 0x0124);
  935. cit_write_reg(gspca_dev, val, 0x0127);
  936. cit_write_reg(gspca_dev, 0x00aa, 0x0130);
  937. cit_write_reg(gspca_dev, 0x82a8, 0x0124);
  938. cit_write_reg(gspca_dev, 0x0038, 0x012d);
  939. cit_write_reg(gspca_dev, 0x0004, 0x012f);
  940. cit_write_reg(gspca_dev, 0xd145, 0x0124);
  941. cit_write_reg(gspca_dev, 0xfffa, 0x0124);
  942. }
  943. /* this function is called at probe time */
  944. static int sd_config(struct gspca_dev *gspca_dev,
  945. const struct usb_device_id *id)
  946. {
  947. struct sd *sd = (struct sd *) gspca_dev;
  948. struct cam *cam;
  949. sd->model = id->driver_info;
  950. if (sd->model == CIT_MODEL3 && ibm_netcam_pro)
  951. sd->model = CIT_IBM_NETCAM_PRO;
  952. cam = &gspca_dev->cam;
  953. switch (sd->model) {
  954. case CIT_MODEL0:
  955. cam->cam_mode = model0_mode;
  956. cam->nmodes = ARRAY_SIZE(model0_mode);
  957. gspca_dev->ctrl_dis = ~((1 << SD_CONTRAST) | (1 << SD_HFLIP));
  958. sd->sof_len = 4;
  959. break;
  960. case CIT_MODEL1:
  961. cam->cam_mode = cif_yuv_mode;
  962. cam->nmodes = ARRAY_SIZE(cif_yuv_mode);
  963. gspca_dev->ctrl_dis = (1 << SD_HUE) | (1 << SD_HFLIP);
  964. sd->sof_len = 4;
  965. break;
  966. case CIT_MODEL2:
  967. cam->cam_mode = model2_mode + 1; /* no 160x120 */
  968. cam->nmodes = 3;
  969. gspca_dev->ctrl_dis = (1 << SD_CONTRAST) |
  970. (1 << SD_SHARPNESS) |
  971. (1 << SD_HFLIP);
  972. break;
  973. case CIT_MODEL3:
  974. cam->cam_mode = vga_yuv_mode;
  975. cam->nmodes = ARRAY_SIZE(vga_yuv_mode);
  976. gspca_dev->ctrl_dis = (1 << SD_HUE) |
  977. (1 << SD_LIGHTING) |
  978. (1 << SD_HFLIP);
  979. sd->stop_on_control_change = 1;
  980. sd->sof_len = 4;
  981. break;
  982. case CIT_MODEL4:
  983. cam->cam_mode = model2_mode;
  984. cam->nmodes = ARRAY_SIZE(model2_mode);
  985. gspca_dev->ctrl_dis = (1 << SD_CONTRAST) |
  986. (1 << SD_SHARPNESS) |
  987. (1 << SD_LIGHTING) |
  988. (1 << SD_HFLIP);
  989. break;
  990. case CIT_IBM_NETCAM_PRO:
  991. cam->cam_mode = vga_yuv_mode;
  992. cam->nmodes = 2; /* no 640 x 480 */
  993. cam->input_flags = V4L2_IN_ST_VFLIP;
  994. gspca_dev->ctrl_dis = ~(1 << SD_CONTRAST);
  995. sd->stop_on_control_change = 1;
  996. sd->sof_len = 4;
  997. break;
  998. }
  999. sd->brightness = BRIGHTNESS_DEFAULT;
  1000. sd->contrast = CONTRAST_DEFAULT;
  1001. sd->hue = HUE_DEFAULT;
  1002. sd->sharpness = SHARPNESS_DEFAULT;
  1003. sd->lighting = LIGHTING_DEFAULT;
  1004. sd->hflip = HFLIP_DEFAULT;
  1005. return 0;
  1006. }
  1007. static int cit_init_model0(struct gspca_dev *gspca_dev)
  1008. {
  1009. cit_write_reg(gspca_dev, 0x0000, 0x0100); /* turn on led */
  1010. cit_write_reg(gspca_dev, 0x0001, 0x0112); /* turn on autogain ? */
  1011. cit_write_reg(gspca_dev, 0x0000, 0x0400);
  1012. cit_write_reg(gspca_dev, 0x0001, 0x0400);
  1013. cit_write_reg(gspca_dev, 0x0000, 0x0420);
  1014. cit_write_reg(gspca_dev, 0x0001, 0x0420);
  1015. cit_write_reg(gspca_dev, 0x000d, 0x0409);
  1016. cit_write_reg(gspca_dev, 0x0002, 0x040a);
  1017. cit_write_reg(gspca_dev, 0x0018, 0x0405);
  1018. cit_write_reg(gspca_dev, 0x0008, 0x0435);
  1019. cit_write_reg(gspca_dev, 0x0026, 0x040b);
  1020. cit_write_reg(gspca_dev, 0x0007, 0x0437);
  1021. cit_write_reg(gspca_dev, 0x0015, 0x042f);
  1022. cit_write_reg(gspca_dev, 0x002b, 0x0439);
  1023. cit_write_reg(gspca_dev, 0x0026, 0x043a);
  1024. cit_write_reg(gspca_dev, 0x0008, 0x0438);
  1025. cit_write_reg(gspca_dev, 0x001e, 0x042b);
  1026. cit_write_reg(gspca_dev, 0x0041, 0x042c);
  1027. return 0;
  1028. }
  1029. static int cit_init_ibm_netcam_pro(struct gspca_dev *gspca_dev)
  1030. {
  1031. cit_read_reg(gspca_dev, 0x128, 1);
  1032. cit_write_reg(gspca_dev, 0x0003, 0x0133);
  1033. cit_write_reg(gspca_dev, 0x0000, 0x0117);
  1034. cit_write_reg(gspca_dev, 0x0008, 0x0123);
  1035. cit_write_reg(gspca_dev, 0x0000, 0x0100);
  1036. cit_read_reg(gspca_dev, 0x0116, 0);
  1037. cit_write_reg(gspca_dev, 0x0060, 0x0116);
  1038. cit_write_reg(gspca_dev, 0x0002, 0x0112);
  1039. cit_write_reg(gspca_dev, 0x0000, 0x0133);
  1040. cit_write_reg(gspca_dev, 0x0000, 0x0123);
  1041. cit_write_reg(gspca_dev, 0x0001, 0x0117);
  1042. cit_write_reg(gspca_dev, 0x0040, 0x0108);
  1043. cit_write_reg(gspca_dev, 0x0019, 0x012c);
  1044. cit_write_reg(gspca_dev, 0x0060, 0x0116);
  1045. cit_write_reg(gspca_dev, 0x0002, 0x0115);
  1046. cit_write_reg(gspca_dev, 0x000b, 0x0115);
  1047. cit_write_reg(gspca_dev, 0x0078, 0x012d);
  1048. cit_write_reg(gspca_dev, 0x0001, 0x012f);
  1049. cit_write_reg(gspca_dev, 0xd141, 0x0124);
  1050. cit_write_reg(gspca_dev, 0x0079, 0x012d);
  1051. cit_write_reg(gspca_dev, 0x00ff, 0x0130);
  1052. cit_write_reg(gspca_dev, 0xcd41, 0x0124);
  1053. cit_write_reg(gspca_dev, 0xfffa, 0x0124);
  1054. cit_read_reg(gspca_dev, 0x0126, 1);
  1055. cit_model3_Packet1(gspca_dev, 0x0000, 0x0000);
  1056. cit_model3_Packet1(gspca_dev, 0x0000, 0x0001);
  1057. cit_model3_Packet1(gspca_dev, 0x000b, 0x0000);
  1058. cit_model3_Packet1(gspca_dev, 0x000c, 0x0008);
  1059. cit_model3_Packet1(gspca_dev, 0x000d, 0x003a);
  1060. cit_model3_Packet1(gspca_dev, 0x000e, 0x0060);
  1061. cit_model3_Packet1(gspca_dev, 0x000f, 0x0060);
  1062. cit_model3_Packet1(gspca_dev, 0x0010, 0x0008);
  1063. cit_model3_Packet1(gspca_dev, 0x0011, 0x0004);
  1064. cit_model3_Packet1(gspca_dev, 0x0012, 0x0028);
  1065. cit_model3_Packet1(gspca_dev, 0x0013, 0x0002);
  1066. cit_model3_Packet1(gspca_dev, 0x0014, 0x0000);
  1067. cit_model3_Packet1(gspca_dev, 0x0015, 0x00fb);
  1068. cit_model3_Packet1(gspca_dev, 0x0016, 0x0002);
  1069. cit_model3_Packet1(gspca_dev, 0x0017, 0x0037);
  1070. cit_model3_Packet1(gspca_dev, 0x0018, 0x0036);
  1071. cit_model3_Packet1(gspca_dev, 0x001e, 0x0000);
  1072. cit_model3_Packet1(gspca_dev, 0x001f, 0x0008);
  1073. cit_model3_Packet1(gspca_dev, 0x0020, 0x00c1);
  1074. cit_model3_Packet1(gspca_dev, 0x0021, 0x0034);
  1075. cit_model3_Packet1(gspca_dev, 0x0022, 0x0034);
  1076. cit_model3_Packet1(gspca_dev, 0x0025, 0x0002);
  1077. cit_model3_Packet1(gspca_dev, 0x0028, 0x0022);
  1078. cit_model3_Packet1(gspca_dev, 0x0029, 0x000a);
  1079. cit_model3_Packet1(gspca_dev, 0x002b, 0x0000);
  1080. cit_model3_Packet1(gspca_dev, 0x002c, 0x0000);
  1081. cit_model3_Packet1(gspca_dev, 0x002d, 0x00ff);
  1082. cit_model3_Packet1(gspca_dev, 0x002e, 0x00ff);
  1083. cit_model3_Packet1(gspca_dev, 0x002f, 0x00ff);
  1084. cit_model3_Packet1(gspca_dev, 0x0030, 0x00ff);
  1085. cit_model3_Packet1(gspca_dev, 0x0031, 0x00ff);
  1086. cit_model3_Packet1(gspca_dev, 0x0032, 0x0007);
  1087. cit_model3_Packet1(gspca_dev, 0x0033, 0x0005);
  1088. cit_model3_Packet1(gspca_dev, 0x0037, 0x0040);
  1089. cit_model3_Packet1(gspca_dev, 0x0039, 0x0000);
  1090. cit_model3_Packet1(gspca_dev, 0x003a, 0x0000);
  1091. cit_model3_Packet1(gspca_dev, 0x003b, 0x0001);
  1092. cit_model3_Packet1(gspca_dev, 0x003c, 0x0000);
  1093. cit_model3_Packet1(gspca_dev, 0x0040, 0x000c);
  1094. cit_model3_Packet1(gspca_dev, 0x0041, 0x00fb);
  1095. cit_model3_Packet1(gspca_dev, 0x0042, 0x0002);
  1096. cit_model3_Packet1(gspca_dev, 0x0043, 0x0000);
  1097. cit_model3_Packet1(gspca_dev, 0x0045, 0x0000);
  1098. cit_model3_Packet1(gspca_dev, 0x0046, 0x0000);
  1099. cit_model3_Packet1(gspca_dev, 0x0047, 0x0000);
  1100. cit_model3_Packet1(gspca_dev, 0x0048, 0x0000);
  1101. cit_model3_Packet1(gspca_dev, 0x0049, 0x0000);
  1102. cit_model3_Packet1(gspca_dev, 0x004a, 0x00ff);
  1103. cit_model3_Packet1(gspca_dev, 0x004b, 0x00ff);
  1104. cit_model3_Packet1(gspca_dev, 0x004c, 0x00ff);
  1105. cit_model3_Packet1(gspca_dev, 0x004f, 0x0000);
  1106. cit_model3_Packet1(gspca_dev, 0x0050, 0x0000);
  1107. cit_model3_Packet1(gspca_dev, 0x0051, 0x0002);
  1108. cit_model3_Packet1(gspca_dev, 0x0055, 0x0000);
  1109. cit_model3_Packet1(gspca_dev, 0x0056, 0x0000);
  1110. cit_model3_Packet1(gspca_dev, 0x0057, 0x0000);
  1111. cit_model3_Packet1(gspca_dev, 0x0058, 0x0002);
  1112. cit_model3_Packet1(gspca_dev, 0x0059, 0x0000);
  1113. cit_model3_Packet1(gspca_dev, 0x005c, 0x0016);
  1114. cit_model3_Packet1(gspca_dev, 0x005d, 0x0022);
  1115. cit_model3_Packet1(gspca_dev, 0x005e, 0x003c);
  1116. cit_model3_Packet1(gspca_dev, 0x005f, 0x0050);
  1117. cit_model3_Packet1(gspca_dev, 0x0060, 0x0044);
  1118. cit_model3_Packet1(gspca_dev, 0x0061, 0x0005);
  1119. cit_model3_Packet1(gspca_dev, 0x006a, 0x007e);
  1120. cit_model3_Packet1(gspca_dev, 0x006f, 0x0000);
  1121. cit_model3_Packet1(gspca_dev, 0x0072, 0x001b);
  1122. cit_model3_Packet1(gspca_dev, 0x0073, 0x0005);
  1123. cit_model3_Packet1(gspca_dev, 0x0074, 0x000a);
  1124. cit_model3_Packet1(gspca_dev, 0x0075, 0x001b);
  1125. cit_model3_Packet1(gspca_dev, 0x0076, 0x002a);
  1126. cit_model3_Packet1(gspca_dev, 0x0077, 0x003c);
  1127. cit_model3_Packet1(gspca_dev, 0x0078, 0x0050);
  1128. cit_model3_Packet1(gspca_dev, 0x007b, 0x0000);
  1129. cit_model3_Packet1(gspca_dev, 0x007c, 0x0011);
  1130. cit_model3_Packet1(gspca_dev, 0x007d, 0x0024);
  1131. cit_model3_Packet1(gspca_dev, 0x007e, 0x0043);
  1132. cit_model3_Packet1(gspca_dev, 0x007f, 0x005a);
  1133. cit_model3_Packet1(gspca_dev, 0x0084, 0x0020);
  1134. cit_model3_Packet1(gspca_dev, 0x0085, 0x0033);
  1135. cit_model3_Packet1(gspca_dev, 0x0086, 0x000a);
  1136. cit_model3_Packet1(gspca_dev, 0x0087, 0x0030);
  1137. cit_model3_Packet1(gspca_dev, 0x0088, 0x0070);
  1138. cit_model3_Packet1(gspca_dev, 0x008b, 0x0008);
  1139. cit_model3_Packet1(gspca_dev, 0x008f, 0x0000);
  1140. cit_model3_Packet1(gspca_dev, 0x0090, 0x0006);
  1141. cit_model3_Packet1(gspca_dev, 0x0091, 0x0028);
  1142. cit_model3_Packet1(gspca_dev, 0x0092, 0x005a);
  1143. cit_model3_Packet1(gspca_dev, 0x0093, 0x0082);
  1144. cit_model3_Packet1(gspca_dev, 0x0096, 0x0014);
  1145. cit_model3_Packet1(gspca_dev, 0x0097, 0x0020);
  1146. cit_model3_Packet1(gspca_dev, 0x0098, 0x0000);
  1147. cit_model3_Packet1(gspca_dev, 0x00b0, 0x0046);
  1148. cit_model3_Packet1(gspca_dev, 0x00b1, 0x0000);
  1149. cit_model3_Packet1(gspca_dev, 0x00b2, 0x0000);
  1150. cit_model3_Packet1(gspca_dev, 0x00b3, 0x0004);
  1151. cit_model3_Packet1(gspca_dev, 0x00b4, 0x0007);
  1152. cit_model3_Packet1(gspca_dev, 0x00b6, 0x0002);
  1153. cit_model3_Packet1(gspca_dev, 0x00b7, 0x0004);
  1154. cit_model3_Packet1(gspca_dev, 0x00bb, 0x0000);
  1155. cit_model3_Packet1(gspca_dev, 0x00bc, 0x0001);
  1156. cit_model3_Packet1(gspca_dev, 0x00bd, 0x0000);
  1157. cit_model3_Packet1(gspca_dev, 0x00bf, 0x0000);
  1158. cit_model3_Packet1(gspca_dev, 0x00c0, 0x00c8);
  1159. cit_model3_Packet1(gspca_dev, 0x00c1, 0x0014);
  1160. cit_model3_Packet1(gspca_dev, 0x00c2, 0x0001);
  1161. cit_model3_Packet1(gspca_dev, 0x00c3, 0x0000);
  1162. cit_model3_Packet1(gspca_dev, 0x00c4, 0x0004);
  1163. cit_model3_Packet1(gspca_dev, 0x00cb, 0x00bf);
  1164. cit_model3_Packet1(gspca_dev, 0x00cc, 0x00bf);
  1165. cit_model3_Packet1(gspca_dev, 0x00cd, 0x00bf);
  1166. cit_model3_Packet1(gspca_dev, 0x00ce, 0x0000);
  1167. cit_model3_Packet1(gspca_dev, 0x00cf, 0x0020);
  1168. cit_model3_Packet1(gspca_dev, 0x00d0, 0x0040);
  1169. cit_model3_Packet1(gspca_dev, 0x00d1, 0x00bf);
  1170. cit_model3_Packet1(gspca_dev, 0x00d1, 0x00bf);
  1171. cit_model3_Packet1(gspca_dev, 0x00d2, 0x00bf);
  1172. cit_model3_Packet1(gspca_dev, 0x00d3, 0x00bf);
  1173. cit_model3_Packet1(gspca_dev, 0x00ea, 0x0008);
  1174. cit_model3_Packet1(gspca_dev, 0x00eb, 0x0000);
  1175. cit_model3_Packet1(gspca_dev, 0x00ec, 0x00e8);
  1176. cit_model3_Packet1(gspca_dev, 0x00ed, 0x0001);
  1177. cit_model3_Packet1(gspca_dev, 0x00ef, 0x0022);
  1178. cit_model3_Packet1(gspca_dev, 0x00f0, 0x0000);
  1179. cit_model3_Packet1(gspca_dev, 0x00f2, 0x0028);
  1180. cit_model3_Packet1(gspca_dev, 0x00f4, 0x0002);
  1181. cit_model3_Packet1(gspca_dev, 0x00f5, 0x0000);
  1182. cit_model3_Packet1(gspca_dev, 0x00fa, 0x0000);
  1183. cit_model3_Packet1(gspca_dev, 0x00fb, 0x0001);
  1184. cit_model3_Packet1(gspca_dev, 0x00fc, 0x0000);
  1185. cit_model3_Packet1(gspca_dev, 0x00fd, 0x0000);
  1186. cit_model3_Packet1(gspca_dev, 0x00fe, 0x0000);
  1187. cit_model3_Packet1(gspca_dev, 0x00ff, 0x0000);
  1188. cit_model3_Packet1(gspca_dev, 0x00be, 0x0003);
  1189. cit_model3_Packet1(gspca_dev, 0x00c8, 0x0000);
  1190. cit_model3_Packet1(gspca_dev, 0x00c9, 0x0020);
  1191. cit_model3_Packet1(gspca_dev, 0x00ca, 0x0040);
  1192. cit_model3_Packet1(gspca_dev, 0x0053, 0x0001);
  1193. cit_model3_Packet1(gspca_dev, 0x0082, 0x000e);
  1194. cit_model3_Packet1(gspca_dev, 0x0083, 0x0020);
  1195. cit_model3_Packet1(gspca_dev, 0x0034, 0x003c);
  1196. cit_model3_Packet1(gspca_dev, 0x006e, 0x0055);
  1197. cit_model3_Packet1(gspca_dev, 0x0062, 0x0005);
  1198. cit_model3_Packet1(gspca_dev, 0x0063, 0x0008);
  1199. cit_model3_Packet1(gspca_dev, 0x0066, 0x000a);
  1200. cit_model3_Packet1(gspca_dev, 0x0067, 0x0006);
  1201. cit_model3_Packet1(gspca_dev, 0x006b, 0x0010);
  1202. cit_model3_Packet1(gspca_dev, 0x005a, 0x0001);
  1203. cit_model3_Packet1(gspca_dev, 0x005b, 0x000a);
  1204. cit_model3_Packet1(gspca_dev, 0x0023, 0x0006);
  1205. cit_model3_Packet1(gspca_dev, 0x0026, 0x0004);
  1206. cit_model3_Packet1(gspca_dev, 0x0036, 0x0069);
  1207. cit_model3_Packet1(gspca_dev, 0x0038, 0x0064);
  1208. cit_model3_Packet1(gspca_dev, 0x003d, 0x0003);
  1209. cit_model3_Packet1(gspca_dev, 0x003e, 0x0001);
  1210. cit_model3_Packet1(gspca_dev, 0x00b8, 0x0014);
  1211. cit_model3_Packet1(gspca_dev, 0x00b9, 0x0014);
  1212. cit_model3_Packet1(gspca_dev, 0x00e6, 0x0004);
  1213. cit_model3_Packet1(gspca_dev, 0x00e8, 0x0001);
  1214. return 0;
  1215. }
  1216. /* this function is called at probe and resume time */
  1217. static int sd_init(struct gspca_dev *gspca_dev)
  1218. {
  1219. struct sd *sd = (struct sd *) gspca_dev;
  1220. switch (sd->model) {
  1221. case CIT_MODEL0:
  1222. cit_init_model0(gspca_dev);
  1223. sd_stop0(gspca_dev);
  1224. break;
  1225. case CIT_MODEL1:
  1226. case CIT_MODEL2:
  1227. case CIT_MODEL3:
  1228. case CIT_MODEL4:
  1229. break; /* All is done in sd_start */
  1230. case CIT_IBM_NETCAM_PRO:
  1231. cit_init_ibm_netcam_pro(gspca_dev);
  1232. sd_stop0(gspca_dev);
  1233. break;
  1234. }
  1235. return 0;
  1236. }
  1237. static int cit_set_brightness(struct gspca_dev *gspca_dev)
  1238. {
  1239. struct sd *sd = (struct sd *) gspca_dev;
  1240. int i;
  1241. switch (sd->model) {
  1242. case CIT_MODEL0:
  1243. case CIT_IBM_NETCAM_PRO:
  1244. /* No (known) brightness control for these */
  1245. break;
  1246. case CIT_MODEL1:
  1247. /* Model 1: Brightness range 0 - 63 */
  1248. cit_Packet_Format1(gspca_dev, 0x0031, sd->brightness);
  1249. cit_Packet_Format1(gspca_dev, 0x0032, sd->brightness);
  1250. cit_Packet_Format1(gspca_dev, 0x0033, sd->brightness);
  1251. break;
  1252. case CIT_MODEL2:
  1253. /* Model 2: Brightness range 0x60 - 0xee */
  1254. /* Scale 0 - 63 to 0x60 - 0xee */
  1255. i = 0x60 + sd->brightness * 2254 / 1000;
  1256. cit_model2_Packet1(gspca_dev, 0x001a, i);
  1257. break;
  1258. case CIT_MODEL3:
  1259. /* Model 3: Brightness range 'i' in [0x0C..0x3F] */
  1260. i = sd->brightness;
  1261. if (i < 0x0c)
  1262. i = 0x0c;
  1263. cit_model3_Packet1(gspca_dev, 0x0036, i);
  1264. break;
  1265. case CIT_MODEL4:
  1266. /* Model 4: Brightness range 'i' in [0x04..0xb4] */
  1267. /* Scale 0 - 63 to 0x04 - 0xb4 */
  1268. i = 0x04 + sd->brightness * 2794 / 1000;
  1269. cit_model4_BrightnessPacket(gspca_dev, i);
  1270. break;
  1271. }
  1272. return 0;
  1273. }
  1274. static int cit_set_contrast(struct gspca_dev *gspca_dev)
  1275. {
  1276. struct sd *sd = (struct sd *) gspca_dev;
  1277. switch (sd->model) {
  1278. case CIT_MODEL0: {
  1279. int i;
  1280. /* gain 0-15, 0-20 -> 0-15 */
  1281. i = sd->contrast * 1000 / 1333;
  1282. cit_write_reg(gspca_dev, i, 0x0422);
  1283. /* gain 0-31, may not be lower then 0x0422, 0-20 -> 0-31 */
  1284. i = sd->contrast * 2000 / 1333;
  1285. cit_write_reg(gspca_dev, i, 0x0423);
  1286. /* gain 0-127, may not be lower then 0x0423, 0-20 -> 0-63 */
  1287. i = sd->contrast * 4000 / 1333;
  1288. cit_write_reg(gspca_dev, i, 0x0424);
  1289. /* gain 0-127, may not be lower then 0x0424, , 0-20 -> 0-127 */
  1290. i = sd->contrast * 8000 / 1333;
  1291. cit_write_reg(gspca_dev, i, 0x0425);
  1292. break;
  1293. }
  1294. case CIT_MODEL2:
  1295. case CIT_MODEL4:
  1296. /* These models do not have this control. */
  1297. break;
  1298. case CIT_MODEL1:
  1299. {
  1300. /* Scale 0 - 20 to 15 - 0 */
  1301. int i, new_contrast = (20 - sd->contrast) * 1000 / 1333;
  1302. for (i = 0; i < cit_model1_ntries; i++) {
  1303. cit_Packet_Format1(gspca_dev, 0x0014, new_contrast);
  1304. cit_send_FF_04_02(gspca_dev);
  1305. }
  1306. break;
  1307. }
  1308. case CIT_MODEL3:
  1309. { /* Preset hardware values */
  1310. static const struct {
  1311. unsigned short cv1;
  1312. unsigned short cv2;
  1313. unsigned short cv3;
  1314. } cv[7] = {
  1315. { 0x05, 0x05, 0x0f }, /* Minimum */
  1316. { 0x04, 0x04, 0x16 },
  1317. { 0x02, 0x03, 0x16 },
  1318. { 0x02, 0x08, 0x16 },
  1319. { 0x01, 0x0c, 0x16 },
  1320. { 0x01, 0x0e, 0x16 },
  1321. { 0x01, 0x10, 0x16 } /* Maximum */
  1322. };
  1323. int i = sd->contrast / 3;
  1324. cit_model3_Packet1(gspca_dev, 0x0067, cv[i].cv1);
  1325. cit_model3_Packet1(gspca_dev, 0x005b, cv[i].cv2);
  1326. cit_model3_Packet1(gspca_dev, 0x005c, cv[i].cv3);
  1327. break;
  1328. }
  1329. case CIT_IBM_NETCAM_PRO:
  1330. cit_model3_Packet1(gspca_dev, 0x005b, sd->contrast + 1);
  1331. break;
  1332. }
  1333. return 0;
  1334. }
  1335. static int cit_set_hue(struct gspca_dev *gspca_dev)
  1336. {
  1337. struct sd *sd = (struct sd *) gspca_dev;
  1338. switch (sd->model) {
  1339. case CIT_MODEL0:
  1340. case CIT_MODEL1:
  1341. case CIT_IBM_NETCAM_PRO:
  1342. /* No hue control for these models */
  1343. break;
  1344. case CIT_MODEL2:
  1345. cit_model2_Packet1(gspca_dev, 0x0024, sd->hue);
  1346. /* cit_model2_Packet1(gspca_dev, 0x0020, sat); */
  1347. break;
  1348. case CIT_MODEL3: {
  1349. /* Model 3: Brightness range 'i' in [0x05..0x37] */
  1350. /* TESTME according to the ibmcam driver this does not work */
  1351. if (0) {
  1352. /* Scale 0 - 127 to 0x05 - 0x37 */
  1353. int i = 0x05 + sd->hue * 1000 / 2540;
  1354. cit_model3_Packet1(gspca_dev, 0x007e, i);
  1355. }
  1356. break;
  1357. }
  1358. case CIT_MODEL4:
  1359. /* HDG: taken from ibmcam, setting the color gains does not
  1360. * really belong here.
  1361. *
  1362. * I am not sure r/g/b_gain variables exactly control gain
  1363. * of those channels. Most likely they subtly change some
  1364. * very internal image processing settings in the camera.
  1365. * In any case, here is what they do, and feel free to tweak:
  1366. *
  1367. * r_gain: seriously affects red gain
  1368. * g_gain: seriously affects green gain
  1369. * b_gain: seriously affects blue gain
  1370. * hue: changes average color from violet (0) to red (0xFF)
  1371. */
  1372. cit_write_reg(gspca_dev, 0x00aa, 0x012d);
  1373. cit_write_reg(gspca_dev, 0x001e, 0x012f);
  1374. cit_write_reg(gspca_dev, 0xd141, 0x0124);
  1375. cit_write_reg(gspca_dev, 160, 0x0127); /* Green gain */
  1376. cit_write_reg(gspca_dev, 160, 0x012e); /* Red gain */
  1377. cit_write_reg(gspca_dev, 160, 0x0130); /* Blue gain */
  1378. cit_write_reg(gspca_dev, 0x8a28, 0x0124);
  1379. cit_write_reg(gspca_dev, sd->hue, 0x012d); /* Hue */
  1380. cit_write_reg(gspca_dev, 0xf545, 0x0124);
  1381. break;
  1382. }
  1383. return 0;
  1384. }
  1385. static int cit_set_sharpness(struct gspca_dev *gspca_dev)
  1386. {
  1387. struct sd *sd = (struct sd *) gspca_dev;
  1388. switch (sd->model) {
  1389. case CIT_MODEL0:
  1390. case CIT_MODEL2:
  1391. case CIT_MODEL4:
  1392. case CIT_IBM_NETCAM_PRO:
  1393. /* These models do not have this control */
  1394. break;
  1395. case CIT_MODEL1: {
  1396. int i;
  1397. const unsigned short sa[] = {
  1398. 0x11, 0x13, 0x16, 0x18, 0x1a, 0x8, 0x0a };
  1399. for (i = 0; i < cit_model1_ntries; i++)
  1400. cit_PacketFormat2(gspca_dev, 0x0013, sa[sd->sharpness]);
  1401. break;
  1402. }
  1403. case CIT_MODEL3:
  1404. { /*
  1405. * "Use a table of magic numbers.
  1406. * This setting doesn't really change much.
  1407. * But that's how Windows does it."
  1408. */
  1409. static const struct {
  1410. unsigned short sv1;
  1411. unsigned short sv2;
  1412. unsigned short sv3;
  1413. unsigned short sv4;
  1414. } sv[7] = {
  1415. { 0x00, 0x00, 0x05, 0x14 }, /* Smoothest */
  1416. { 0x01, 0x04, 0x05, 0x14 },
  1417. { 0x02, 0x04, 0x05, 0x14 },
  1418. { 0x03, 0x04, 0x05, 0x14 },
  1419. { 0x03, 0x05, 0x05, 0x14 },
  1420. { 0x03, 0x06, 0x05, 0x14 },
  1421. { 0x03, 0x07, 0x05, 0x14 } /* Sharpest */
  1422. };
  1423. cit_model3_Packet1(gspca_dev, 0x0060, sv[sd->sharpness].sv1);
  1424. cit_model3_Packet1(gspca_dev, 0x0061, sv[sd->sharpness].sv2);
  1425. cit_model3_Packet1(gspca_dev, 0x0062, sv[sd->sharpness].sv3);
  1426. cit_model3_Packet1(gspca_dev, 0x0063, sv[sd->sharpness].sv4);
  1427. break;
  1428. }
  1429. }
  1430. return 0;
  1431. }
  1432. /*
  1433. * cit_set_lighting()
  1434. *
  1435. * Camera model 1:
  1436. * We have 3 levels of lighting conditions: 0=Bright, 1=Medium, 2=Low.
  1437. *
  1438. * Camera model 2:
  1439. * We have 16 levels of lighting, 0 for bright light and up to 15 for
  1440. * low light. But values above 5 or so are useless because camera is
  1441. * not really capable to produce anything worth viewing at such light.
  1442. * This setting may be altered only in certain camera state.
  1443. *
  1444. * Low lighting forces slower FPS.
  1445. *
  1446. * History:
  1447. * 1/5/00 Created.
  1448. * 2/20/00 Added support for Model 2 cameras.
  1449. */
  1450. static void cit_set_lighting(struct gspca_dev *gspca_dev)
  1451. {
  1452. struct sd *sd = (struct sd *) gspca_dev;
  1453. switch (sd->model) {
  1454. case CIT_MODEL0:
  1455. case CIT_MODEL2:
  1456. case CIT_MODEL3:
  1457. case CIT_MODEL4:
  1458. case CIT_IBM_NETCAM_PRO:
  1459. break;
  1460. case CIT_MODEL1: {
  1461. int i;
  1462. for (i = 0; i < cit_model1_ntries; i++)
  1463. cit_Packet_Format1(gspca_dev, 0x0027, sd->lighting);
  1464. break;
  1465. }
  1466. }
  1467. }
  1468. static void cit_set_hflip(struct gspca_dev *gspca_dev)
  1469. {
  1470. struct sd *sd = (struct sd *) gspca_dev;
  1471. switch (sd->model) {
  1472. case CIT_MODEL0:
  1473. if (sd->hflip)
  1474. cit_write_reg(gspca_dev, 0x0020, 0x0115);
  1475. else
  1476. cit_write_reg(gspca_dev, 0x0040, 0x0115);
  1477. break;
  1478. case CIT_MODEL1:
  1479. case CIT_MODEL2:
  1480. case CIT_MODEL3:
  1481. case CIT_MODEL4:
  1482. case CIT_IBM_NETCAM_PRO:
  1483. break;
  1484. }
  1485. }
  1486. static int cit_restart_stream(struct gspca_dev *gspca_dev)
  1487. {
  1488. struct sd *sd = (struct sd *) gspca_dev;
  1489. switch (sd->model) {
  1490. case CIT_MODEL0:
  1491. case CIT_MODEL1:
  1492. cit_write_reg(gspca_dev, 0x0001, 0x0114);
  1493. /* Fall through */
  1494. case CIT_MODEL2:
  1495. case CIT_MODEL4:
  1496. cit_write_reg(gspca_dev, 0x00c0, 0x010c); /* Go! */
  1497. usb_clear_halt(gspca_dev->dev, gspca_dev->urb[0]->pipe);
  1498. break;
  1499. case CIT_MODEL3:
  1500. case CIT_IBM_NETCAM_PRO:
  1501. cit_write_reg(gspca_dev, 0x0001, 0x0114);
  1502. cit_write_reg(gspca_dev, 0x00c0, 0x010c); /* Go! */
  1503. usb_clear_halt(gspca_dev->dev, gspca_dev->urb[0]->pipe);
  1504. /* Clear button events from while we were not streaming */
  1505. cit_write_reg(gspca_dev, 0x0001, 0x0113);
  1506. break;
  1507. }
  1508. sd->sof_read = 0;
  1509. return 0;
  1510. }
  1511. static int cit_get_packet_size(struct gspca_dev *gspca_dev)
  1512. {
  1513. struct usb_host_interface *alt;
  1514. struct usb_interface *intf;
  1515. intf = usb_ifnum_to_if(gspca_dev->dev, gspca_dev->iface);
  1516. alt = usb_altnum_to_altsetting(intf, gspca_dev->alt);
  1517. if (!alt) {
  1518. pr_err("Couldn't get altsetting\n");
  1519. return -EIO;
  1520. }
  1521. return le16_to_cpu(alt->endpoint[0].desc.wMaxPacketSize);
  1522. }
  1523. /* Calculate the clockdiv giving us max fps given the available bandwidth */
  1524. static int cit_get_clock_div(struct gspca_dev *gspca_dev)
  1525. {
  1526. int clock_div = 7; /* 0=30 1=25 2=20 3=15 4=12 5=7.5 6=6 7=3fps ?? */
  1527. int fps[8] = { 30, 25, 20, 15, 12, 8, 6, 3 };
  1528. int packet_size;
  1529. packet_size = cit_get_packet_size(gspca_dev);
  1530. if (packet_size < 0)
  1531. return packet_size;
  1532. while (clock_div > 3 &&
  1533. 1000 * packet_size >
  1534. gspca_dev->width * gspca_dev->height *
  1535. fps[clock_div - 1] * 3 / 2)
  1536. clock_div--;
  1537. PDEBUG(D_PROBE,
  1538. "PacketSize: %d, res: %dx%d -> using clockdiv: %d (%d fps)",
  1539. packet_size, gspca_dev->width, gspca_dev->height, clock_div,
  1540. fps[clock_div]);
  1541. return clock_div;
  1542. }
  1543. static int cit_start_model0(struct gspca_dev *gspca_dev)
  1544. {
  1545. const unsigned short compression = 0; /* 0=none, 7=best frame rate */
  1546. int clock_div;
  1547. clock_div = cit_get_clock_div(gspca_dev);
  1548. if (clock_div < 0)
  1549. return clock_div;
  1550. cit_write_reg(gspca_dev, 0x0000, 0x0100); /* turn on led */
  1551. cit_write_reg(gspca_dev, 0x0003, 0x0438);
  1552. cit_write_reg(gspca_dev, 0x001e, 0x042b);
  1553. cit_write_reg(gspca_dev, 0x0041, 0x042c);
  1554. cit_write_reg(gspca_dev, 0x0008, 0x0436);
  1555. cit_write_reg(gspca_dev, 0x0024, 0x0403);
  1556. cit_write_reg(gspca_dev, 0x002c, 0x0404);
  1557. cit_write_reg(gspca_dev, 0x0002, 0x0426);
  1558. cit_write_reg(gspca_dev, 0x0014, 0x0427);
  1559. switch (gspca_dev->width) {
  1560. case 160: /* 160x120 */
  1561. cit_write_reg(gspca_dev, 0x0004, 0x010b);
  1562. cit_write_reg(gspca_dev, 0x0001, 0x010a);
  1563. cit_write_reg(gspca_dev, 0x0010, 0x0102);
  1564. cit_write_reg(gspca_dev, 0x00a0, 0x0103);
  1565. cit_write_reg(gspca_dev, 0x0000, 0x0104);
  1566. cit_write_reg(gspca_dev, 0x0078, 0x0105);
  1567. break;
  1568. case 176: /* 176x144 */
  1569. cit_write_reg(gspca_dev, 0x0006, 0x010b);
  1570. cit_write_reg(gspca_dev, 0x0000, 0x010a);
  1571. cit_write_reg(gspca_dev, 0x0005, 0x0102);
  1572. cit_write_reg(gspca_dev, 0x00b0, 0x0103);
  1573. cit_write_reg(gspca_dev, 0x0000, 0x0104);
  1574. cit_write_reg(gspca_dev, 0x0090, 0x0105);
  1575. break;
  1576. case 320: /* 320x240 */
  1577. cit_write_reg(gspca_dev, 0x0008, 0x010b);
  1578. cit_write_reg(gspca_dev, 0x0004, 0x010a);
  1579. cit_write_reg(gspca_dev, 0x0005, 0x0102);
  1580. cit_write_reg(gspca_dev, 0x00a0, 0x0103);
  1581. cit_write_reg(gspca_dev, 0x0010, 0x0104);
  1582. cit_write_reg(gspca_dev, 0x0078, 0x0105);
  1583. break;
  1584. }
  1585. cit_write_reg(gspca_dev, compression, 0x0109);
  1586. cit_write_reg(gspca_dev, clock_div, 0x0111);
  1587. return 0;
  1588. }
  1589. static int cit_start_model1(struct gspca_dev *gspca_dev)
  1590. {
  1591. struct sd *sd = (struct sd *) gspca_dev;
  1592. int i, clock_div;
  1593. clock_div = cit_get_clock_div(gspca_dev);
  1594. if (clock_div < 0)
  1595. return clock_div;
  1596. cit_read_reg(gspca_dev, 0x0128, 1);
  1597. cit_read_reg(gspca_dev, 0x0100, 0);
  1598. cit_write_reg(gspca_dev, 0x01, 0x0100); /* LED On */
  1599. cit_read_reg(gspca_dev, 0x0100, 0);
  1600. cit_write_reg(gspca_dev, 0x81, 0x0100); /* LED Off */
  1601. cit_read_reg(gspca_dev, 0x0100, 0);
  1602. cit_write_reg(gspca_dev, 0x01, 0x0100); /* LED On */
  1603. cit_write_reg(gspca_dev, 0x01, 0x0108);
  1604. cit_write_reg(gspca_dev, 0x03, 0x0112);
  1605. cit_read_reg(gspca_dev, 0x0115, 0);
  1606. cit_write_reg(gspca_dev, 0x06, 0x0115);
  1607. cit_read_reg(gspca_dev, 0x0116, 0);
  1608. cit_write_reg(gspca_dev, 0x44, 0x0116);
  1609. cit_read_reg(gspca_dev, 0x0116, 0);
  1610. cit_write_reg(gspca_dev, 0x40, 0x0116);
  1611. cit_read_reg(gspca_dev, 0x0115, 0);
  1612. cit_write_reg(gspca_dev, 0x0e, 0x0115);
  1613. cit_write_reg(gspca_dev, 0x19, 0x012c);
  1614. cit_Packet_Format1(gspca_dev, 0x00, 0x1e);
  1615. cit_Packet_Format1(gspca_dev, 0x39, 0x0d);
  1616. cit_Packet_Format1(gspca_dev, 0x39, 0x09);
  1617. cit_Packet_Format1(gspca_dev, 0x3b, 0x00);
  1618. cit_Packet_Format1(gspca_dev, 0x28, 0x22);
  1619. cit_Packet_Format1(gspca_dev, 0x27, 0x00);
  1620. cit_Packet_Format1(gspca_dev, 0x2b, 0x1f);
  1621. cit_Packet_Format1(gspca_dev, 0x39, 0x08);
  1622. for (i = 0; i < cit_model1_ntries; i++)
  1623. cit_Packet_Format1(gspca_dev, 0x2c, 0x00);
  1624. for (i = 0; i < cit_model1_ntries; i++)
  1625. cit_Packet_Format1(gspca_dev, 0x30, 0x14);
  1626. cit_PacketFormat2(gspca_dev, 0x39, 0x02);
  1627. cit_PacketFormat2(gspca_dev, 0x01, 0xe1);
  1628. cit_PacketFormat2(gspca_dev, 0x02, 0xcd);
  1629. cit_PacketFormat2(gspca_dev, 0x03, 0xcd);
  1630. cit_PacketFormat2(gspca_dev, 0x04, 0xfa);
  1631. cit_PacketFormat2(gspca_dev, 0x3f, 0xff);
  1632. cit_PacketFormat2(gspca_dev, 0x39, 0x00);
  1633. cit_PacketFormat2(gspca_dev, 0x39, 0x02);
  1634. cit_PacketFormat2(gspca_dev, 0x0a, 0x37);
  1635. cit_PacketFormat2(gspca_dev, 0x0b, 0xb8);
  1636. cit_PacketFormat2(gspca_dev, 0x0c, 0xf3);
  1637. cit_PacketFormat2(gspca_dev, 0x0d, 0xe3);
  1638. cit_PacketFormat2(gspca_dev, 0x0e, 0x0d);
  1639. cit_PacketFormat2(gspca_dev, 0x0f, 0xf2);
  1640. cit_PacketFormat2(gspca_dev, 0x10, 0xd5);
  1641. cit_PacketFormat2(gspca_dev, 0x11, 0xba);
  1642. cit_PacketFormat2(gspca_dev, 0x12, 0x53);
  1643. cit_PacketFormat2(gspca_dev, 0x3f, 0xff);
  1644. cit_PacketFormat2(gspca_dev, 0x39, 0x00);
  1645. cit_PacketFormat2(gspca_dev, 0x39, 0x02);
  1646. cit_PacketFormat2(gspca_dev, 0x16, 0x00);
  1647. cit_PacketFormat2(gspca_dev, 0x17, 0x28);
  1648. cit_PacketFormat2(gspca_dev, 0x18, 0x7d);
  1649. cit_PacketFormat2(gspca_dev, 0x19, 0xbe);
  1650. cit_PacketFormat2(gspca_dev, 0x3f, 0xff);
  1651. cit_PacketFormat2(gspca_dev, 0x39, 0x00);
  1652. for (i = 0; i < cit_model1_ntries; i++)
  1653. cit_Packet_Format1(gspca_dev, 0x00, 0x18);
  1654. for (i = 0; i < cit_model1_ntries; i++)
  1655. cit_Packet_Format1(gspca_dev, 0x13, 0x18);
  1656. for (i = 0; i < cit_model1_ntries; i++)
  1657. cit_Packet_Format1(gspca_dev, 0x14, 0x06);
  1658. /* TESTME These are handled through controls
  1659. KEEP until someone can test leaving this out is ok */
  1660. if (0) {
  1661. /* This is default brightness */
  1662. for (i = 0; i < cit_model1_ntries; i++)
  1663. cit_Packet_Format1(gspca_dev, 0x31, 0x37);
  1664. for (i = 0; i < cit_model1_ntries; i++)
  1665. cit_Packet_Format1(gspca_dev, 0x32, 0x46);
  1666. for (i = 0; i < cit_model1_ntries; i++)
  1667. cit_Packet_Format1(gspca_dev, 0x33, 0x55);
  1668. }
  1669. cit_Packet_Format1(gspca_dev, 0x2e, 0x04);
  1670. for (i = 0; i < cit_model1_ntries; i++)
  1671. cit_Packet_Format1(gspca_dev, 0x2d, 0x04);
  1672. for (i = 0; i < cit_model1_ntries; i++)
  1673. cit_Packet_Format1(gspca_dev, 0x29, 0x80);
  1674. cit_Packet_Format1(gspca_dev, 0x2c, 0x01);
  1675. cit_Packet_Format1(gspca_dev, 0x30, 0x17);
  1676. cit_Packet_Format1(gspca_dev, 0x39, 0x08);
  1677. for (i = 0; i < cit_model1_ntries; i++)
  1678. cit_Packet_Format1(gspca_dev, 0x34, 0x00);
  1679. cit_write_reg(gspca_dev, 0x00, 0x0101);
  1680. cit_write_reg(gspca_dev, 0x00, 0x010a);
  1681. switch (gspca_dev->width) {
  1682. case 128: /* 128x96 */
  1683. cit_write_reg(gspca_dev, 0x80, 0x0103);
  1684. cit_write_reg(gspca_dev, 0x60, 0x0105);
  1685. cit_write_reg(gspca_dev, 0x0c, 0x010b);
  1686. cit_write_reg(gspca_dev, 0x04, 0x011b); /* Same everywhere */
  1687. cit_write_reg(gspca_dev, 0x0b, 0x011d);
  1688. cit_write_reg(gspca_dev, 0x00, 0x011e); /* Same everywhere */
  1689. cit_write_reg(gspca_dev, 0x00, 0x0129);
  1690. break;
  1691. case 176: /* 176x144 */
  1692. cit_write_reg(gspca_dev, 0xb0, 0x0103);
  1693. cit_write_reg(gspca_dev, 0x8f, 0x0105);
  1694. cit_write_reg(gspca_dev, 0x06, 0x010b);
  1695. cit_write_reg(gspca_dev, 0x04, 0x011b); /* Same everywhere */
  1696. cit_write_reg(gspca_dev, 0x0d, 0x011d);
  1697. cit_write_reg(gspca_dev, 0x00, 0x011e); /* Same everywhere */
  1698. cit_write_reg(gspca_dev, 0x03, 0x0129);
  1699. break;
  1700. case 352: /* 352x288 */
  1701. cit_write_reg(gspca_dev, 0xb0, 0x0103);
  1702. cit_write_reg(gspca_dev, 0x90, 0x0105);
  1703. cit_write_reg(gspca_dev, 0x02, 0x010b);
  1704. cit_write_reg(gspca_dev, 0x04, 0x011b); /* Same everywhere */
  1705. cit_write_reg(gspca_dev, 0x05, 0x011d);
  1706. cit_write_reg(gspca_dev, 0x00, 0x011e); /* Same everywhere */
  1707. cit_write_reg(gspca_dev, 0x00, 0x0129);
  1708. break;
  1709. }
  1710. cit_write_reg(gspca_dev, 0xff, 0x012b);
  1711. /* TESTME These are handled through controls
  1712. KEEP until someone can test leaving this out is ok */
  1713. if (0) {
  1714. /* This is another brightness - don't know why */
  1715. for (i = 0; i < cit_model1_ntries; i++)
  1716. cit_Packet_Format1(gspca_dev, 0x31, 0xc3);
  1717. for (i = 0; i < cit_model1_ntries; i++)
  1718. cit_Packet_Format1(gspca_dev, 0x32, 0xd2);
  1719. for (i = 0; i < cit_model1_ntries; i++)
  1720. cit_Packet_Format1(gspca_dev, 0x33, 0xe1);
  1721. /* Default contrast */
  1722. for (i = 0; i < cit_model1_ntries; i++)
  1723. cit_Packet_Format1(gspca_dev, 0x14, 0x0a);
  1724. /* Default sharpness */
  1725. for (i = 0; i < cit_model1_ntries2; i++)
  1726. cit_PacketFormat2(gspca_dev, 0x13, 0x1a);
  1727. /* Default lighting conditions */
  1728. cit_Packet_Format1(gspca_dev, 0x0027, sd->lighting);
  1729. }
  1730. /* Assorted init */
  1731. switch (gspca_dev->width) {
  1732. case 128: /* 128x96 */
  1733. cit_Packet_Format1(gspca_dev, 0x2b, 0x1e);
  1734. cit_write_reg(gspca_dev, 0xc9, 0x0119); /* Same everywhere */
  1735. cit_write_reg(gspca_dev, 0x80, 0x0109); /* Same everywhere */
  1736. cit_write_reg(gspca_dev, 0x36, 0x0102);
  1737. cit_write_reg(gspca_dev, 0x1a, 0x0104);
  1738. cit_write_reg(gspca_dev, 0x04, 0x011a); /* Same everywhere */
  1739. cit_write_reg(gspca_dev, 0x2b, 0x011c);
  1740. cit_write_reg(gspca_dev, 0x23, 0x012a); /* Same everywhere */
  1741. break;
  1742. case 176: /* 176x144 */
  1743. cit_Packet_Format1(gspca_dev, 0x2b, 0x1e);
  1744. cit_write_reg(gspca_dev, 0xc9, 0x0119); /* Same everywhere */
  1745. cit_write_reg(gspca_dev, 0x80, 0x0109); /* Same everywhere */
  1746. cit_write_reg(gspca_dev, 0x04, 0x0102);
  1747. cit_write_reg(gspca_dev, 0x02, 0x0104);
  1748. cit_write_reg(gspca_dev, 0x04, 0x011a); /* Same everywhere */
  1749. cit_write_reg(gspca_dev, 0x2b, 0x011c);
  1750. cit_write_reg(gspca_dev, 0x23, 0x012a); /* Same everywhere */
  1751. break;
  1752. case 352: /* 352x288 */
  1753. cit_Packet_Format1(gspca_dev, 0x2b, 0x1f);
  1754. cit_write_reg(gspca_dev, 0xc9, 0x0119); /* Same everywhere */
  1755. cit_write_reg(gspca_dev, 0x80, 0x0109); /* Same everywhere */
  1756. cit_write_reg(gspca_dev, 0x08, 0x0102);
  1757. cit_write_reg(gspca_dev, 0x01, 0x0104);
  1758. cit_write_reg(gspca_dev, 0x04, 0x011a); /* Same everywhere */
  1759. cit_write_reg(gspca_dev, 0x2f, 0x011c);
  1760. cit_write_reg(gspca_dev, 0x23, 0x012a); /* Same everywhere */
  1761. break;
  1762. }
  1763. cit_write_reg(gspca_dev, 0x01, 0x0100); /* LED On */
  1764. cit_write_reg(gspca_dev, clock_div, 0x0111);
  1765. return 0;
  1766. }
  1767. static int cit_start_model2(struct gspca_dev *gspca_dev)
  1768. {
  1769. struct sd *sd = (struct sd *) gspca_dev;
  1770. int clock_div = 0;
  1771. cit_write_reg(gspca_dev, 0x0000, 0x0100); /* LED on */
  1772. cit_read_reg(gspca_dev, 0x0116, 0);
  1773. cit_write_reg(gspca_dev, 0x0060, 0x0116);
  1774. cit_write_reg(gspca_dev, 0x0002, 0x0112);
  1775. cit_write_reg(gspca_dev, 0x00bc, 0x012c);
  1776. cit_write_reg(gspca_dev, 0x0008, 0x012b);
  1777. cit_write_reg(gspca_dev, 0x0000, 0x0108);
  1778. cit_write_reg(gspca_dev, 0x0001, 0x0133);
  1779. cit_write_reg(gspca_dev, 0x0001, 0x0102);
  1780. switch (gspca_dev->width) {
  1781. case 176: /* 176x144 */
  1782. cit_write_reg(gspca_dev, 0x002c, 0x0103); /* All except 320x240 */
  1783. cit_write_reg(gspca_dev, 0x0000, 0x0104); /* Same */
  1784. cit_write_reg(gspca_dev, 0x0024, 0x0105); /* 176x144, 352x288 */
  1785. cit_write_reg(gspca_dev, 0x00b9, 0x010a); /* Unique to this mode */
  1786. cit_write_reg(gspca_dev, 0x0038, 0x0119); /* Unique to this mode */
  1787. /* TESTME HDG: this does not seem right
  1788. (it is 2 for all other resolutions) */
  1789. sd->sof_len = 10;
  1790. break;
  1791. case 320: /* 320x240 */
  1792. cit_write_reg(gspca_dev, 0x0028, 0x0103); /* Unique to this mode */
  1793. cit_write_reg(gspca_dev, 0x0000, 0x0104); /* Same */
  1794. cit_write_reg(gspca_dev, 0x001e, 0x0105); /* 320x240, 352x240 */
  1795. cit_write_reg(gspca_dev, 0x0039, 0x010a); /* All except 176x144 */
  1796. cit_write_reg(gspca_dev, 0x0070, 0x0119); /* All except 176x144 */
  1797. sd->sof_len = 2;
  1798. break;
  1799. /* case VIDEOSIZE_352x240: */
  1800. cit_write_reg(gspca_dev, 0x002c, 0x0103); /* All except 320x240 */
  1801. cit_write_reg(gspca_dev, 0x0000, 0x0104); /* Same */
  1802. cit_write_reg(gspca_dev, 0x001e, 0x0105); /* 320x240, 352x240 */
  1803. cit_write_reg(gspca_dev, 0x0039, 0x010a); /* All except 176x144 */
  1804. cit_write_reg(gspca_dev, 0x0070, 0x0119); /* All except 176x144 */
  1805. sd->sof_len = 2;
  1806. break;
  1807. case 352: /* 352x288 */
  1808. cit_write_reg(gspca_dev, 0x002c, 0x0103); /* All except 320x240 */
  1809. cit_write_reg(gspca_dev, 0x0000, 0x0104); /* Same */
  1810. cit_write_reg(gspca_dev, 0x0024, 0x0105); /* 176x144, 352x288 */
  1811. cit_write_reg(gspca_dev, 0x0039, 0x010a); /* All except 176x144 */
  1812. cit_write_reg(gspca_dev, 0x0070, 0x0119); /* All except 176x144 */
  1813. sd->sof_len = 2;
  1814. break;
  1815. }
  1816. cit_write_reg(gspca_dev, 0x0000, 0x0100); /* LED on */
  1817. switch (gspca_dev->width) {
  1818. case 176: /* 176x144 */
  1819. cit_write_reg(gspca_dev, 0x0050, 0x0111);
  1820. cit_write_reg(gspca_dev, 0x00d0, 0x0111);
  1821. break;
  1822. case 320: /* 320x240 */
  1823. case 352: /* 352x288 */
  1824. cit_write_reg(gspca_dev, 0x0040, 0x0111);
  1825. cit_write_reg(gspca_dev, 0x00c0, 0x0111);
  1826. break;
  1827. }
  1828. cit_write_reg(gspca_dev, 0x009b, 0x010f);
  1829. cit_write_reg(gspca_dev, 0x00bb, 0x010f);
  1830. /*
  1831. * Hardware settings, may affect CMOS sensor; not user controls!
  1832. * -------------------------------------------------------------
  1833. * 0x0004: no effect
  1834. * 0x0006: hardware effect
  1835. * 0x0008: no effect
  1836. * 0x000a: stops video stream, probably important h/w setting
  1837. * 0x000c: changes color in hardware manner (not user setting)
  1838. * 0x0012: changes number of colors (does not affect speed)
  1839. * 0x002a: no effect
  1840. * 0x002c: hardware setting (related to scan lines)
  1841. * 0x002e: stops video stream, probably important h/w setting
  1842. */
  1843. cit_model2_Packet1(gspca_dev, 0x000a, 0x005c);
  1844. cit_model2_Packet1(gspca_dev, 0x0004, 0x0000);
  1845. cit_model2_Packet1(gspca_dev, 0x0006, 0x00fb);
  1846. cit_model2_Packet1(gspca_dev, 0x0008, 0x0000);
  1847. cit_model2_Packet1(gspca_dev, 0x000c, 0x0009);
  1848. cit_model2_Packet1(gspca_dev, 0x0012, 0x000a);
  1849. cit_model2_Packet1(gspca_dev, 0x002a, 0x0000);
  1850. cit_model2_Packet1(gspca_dev, 0x002c, 0x0000);
  1851. cit_model2_Packet1(gspca_dev, 0x002e, 0x0008);
  1852. /*
  1853. * Function 0x0030 pops up all over the place. Apparently
  1854. * it is a hardware control register, with every bit assigned to
  1855. * do something.
  1856. */
  1857. cit_model2_Packet1(gspca_dev, 0x0030, 0x0000);
  1858. /*
  1859. * Magic control of CMOS sensor. Only lower values like
  1860. * 0-3 work, and picture shifts left or right. Don't change.
  1861. */
  1862. switch (gspca_dev->width) {
  1863. case 176: /* 176x144 */
  1864. cit_model2_Packet1(gspca_dev, 0x0014, 0x0002);
  1865. cit_model2_Packet1(gspca_dev, 0x0016, 0x0002); /* Horizontal shift */
  1866. cit_model2_Packet1(gspca_dev, 0x0018, 0x004a); /* Another hardware setting */
  1867. clock_div = 6;
  1868. break;
  1869. case 320: /* 320x240 */
  1870. cit_model2_Packet1(gspca_dev, 0x0014, 0x0009);
  1871. cit_model2_Packet1(gspca_dev, 0x0016, 0x0005); /* Horizontal shift */
  1872. cit_model2_Packet1(gspca_dev, 0x0018, 0x0044); /* Another hardware setting */
  1873. clock_div = 8;
  1874. break;
  1875. /* case VIDEOSIZE_352x240: */
  1876. /* This mode doesn't work as Windows programs it; changed to work */
  1877. cit_model2_Packet1(gspca_dev, 0x0014, 0x0009); /* Windows sets this to 8 */
  1878. cit_model2_Packet1(gspca_dev, 0x0016, 0x0003); /* Horizontal shift */
  1879. cit_model2_Packet1(gspca_dev, 0x0018, 0x0044); /* Windows sets this to 0x0045 */
  1880. clock_div = 10;
  1881. break;
  1882. case 352: /* 352x288 */
  1883. cit_model2_Packet1(gspca_dev, 0x0014, 0x0003);
  1884. cit_model2_Packet1(gspca_dev, 0x0016, 0x0002); /* Horizontal shift */
  1885. cit_model2_Packet1(gspca_dev, 0x0018, 0x004a); /* Another hardware setting */
  1886. clock_div = 16;
  1887. break;
  1888. }
  1889. /* TESTME These are handled through controls
  1890. KEEP until someone can test leaving this out is ok */
  1891. if (0)
  1892. cit_model2_Packet1(gspca_dev, 0x001a, 0x005a);
  1893. /*
  1894. * We have our own frame rate setting varying from 0 (slowest) to 6
  1895. * (fastest). The camera model 2 allows frame rate in range [0..0x1F]
  1896. # where 0 is also the slowest setting. However for all practical
  1897. # reasons high settings make no sense because USB is not fast enough
  1898. # to support high FPS. Be aware that the picture datastream will be
  1899. # severely disrupted if you ask for frame rate faster than allowed
  1900. # for the video size - see below:
  1901. *
  1902. * Allowable ranges (obtained experimentally on OHCI, K6-3, 450 MHz):
  1903. * -----------------------------------------------------------------
  1904. * 176x144: [6..31]
  1905. * 320x240: [8..31]
  1906. * 352x240: [10..31]
  1907. * 352x288: [16..31] I have to raise lower threshold for stability...
  1908. *
  1909. * As usual, slower FPS provides better sensitivity.
  1910. */
  1911. cit_model2_Packet1(gspca_dev, 0x001c, clock_div);
  1912. /*
  1913. * This setting does not visibly affect pictures; left it here
  1914. * because it was present in Windows USB data stream. This function
  1915. * does not allow arbitrary values and apparently is a bit mask, to
  1916. * be activated only at appropriate time. Don't change it randomly!
  1917. */
  1918. switch (gspca_dev->width) {
  1919. case 176: /* 176x144 */
  1920. cit_model2_Packet1(gspca_dev, 0x0026, 0x00c2);
  1921. break;
  1922. case 320: /* 320x240 */
  1923. cit_model2_Packet1(gspca_dev, 0x0026, 0x0044);
  1924. break;
  1925. /* case VIDEOSIZE_352x240: */
  1926. cit_model2_Packet1(gspca_dev, 0x0026, 0x0046);
  1927. break;
  1928. case 352: /* 352x288 */
  1929. cit_model2_Packet1(gspca_dev, 0x0026, 0x0048);
  1930. break;
  1931. }
  1932. /* FIXME this cannot be changed while streaming, so we
  1933. should report a grabbed flag for this control. */
  1934. cit_model2_Packet1(gspca_dev, 0x0028, sd->lighting);
  1935. /* color balance rg2 */
  1936. cit_model2_Packet1(gspca_dev, 0x001e, 0x002f);
  1937. /* saturation */
  1938. cit_model2_Packet1(gspca_dev, 0x0020, 0x0034);
  1939. /* color balance yb */
  1940. cit_model2_Packet1(gspca_dev, 0x0022, 0x00a0);
  1941. /* Hardware control command */
  1942. cit_model2_Packet1(gspca_dev, 0x0030, 0x0004);
  1943. return 0;
  1944. }
  1945. static int cit_start_model3(struct gspca_dev *gspca_dev)
  1946. {
  1947. const unsigned short compression = 0; /* 0=none, 7=best frame rate */
  1948. int i, clock_div = 0;
  1949. /* HDG not in ibmcam driver, added to see if it helps with
  1950. auto-detecting between model3 and ibm netcamera pro */
  1951. cit_read_reg(gspca_dev, 0x128, 1);
  1952. cit_write_reg(gspca_dev, 0x0000, 0x0100);
  1953. cit_read_reg(gspca_dev, 0x0116, 0);
  1954. cit_write_reg(gspca_dev, 0x0060, 0x0116);
  1955. cit_write_reg(gspca_dev, 0x0002, 0x0112);
  1956. cit_write_reg(gspca_dev, 0x0000, 0x0123);
  1957. cit_write_reg(gspca_dev, 0x0001, 0x0117);
  1958. cit_write_reg(gspca_dev, 0x0040, 0x0108);
  1959. cit_write_reg(gspca_dev, 0x0019, 0x012c);
  1960. cit_write_reg(gspca_dev, 0x0060, 0x0116);
  1961. cit_write_reg(gspca_dev, 0x0002, 0x0115);
  1962. cit_write_reg(gspca_dev, 0x0003, 0x0115);
  1963. cit_read_reg(gspca_dev, 0x0115, 0);
  1964. cit_write_reg(gspca_dev, 0x000b, 0x0115);
  1965. /* TESTME HDG not in ibmcam driver, added to see if it helps with
  1966. auto-detecting between model3 and ibm netcamera pro */
  1967. if (0) {
  1968. cit_write_reg(gspca_dev, 0x0078, 0x012d);
  1969. cit_write_reg(gspca_dev, 0x0001, 0x012f);
  1970. cit_write_reg(gspca_dev, 0xd141, 0x0124);
  1971. cit_write_reg(gspca_dev, 0x0079, 0x012d);
  1972. cit_write_reg(gspca_dev, 0x00ff, 0x0130);
  1973. cit_write_reg(gspca_dev, 0xcd41, 0x0124);
  1974. cit_write_reg(gspca_dev, 0xfffa, 0x0124);
  1975. cit_read_reg(gspca_dev, 0x0126, 1);
  1976. }
  1977. cit_model3_Packet1(gspca_dev, 0x000a, 0x0040);
  1978. cit_model3_Packet1(gspca_dev, 0x000b, 0x00f6);
  1979. cit_model3_Packet1(gspca_dev, 0x000c, 0x0002);
  1980. cit_model3_Packet1(gspca_dev, 0x000d, 0x0020);
  1981. cit_model3_Packet1(gspca_dev, 0x000e, 0x0033);
  1982. cit_model3_Packet1(gspca_dev, 0x000f, 0x0007);
  1983. cit_model3_Packet1(gspca_dev, 0x0010, 0x0000);
  1984. cit_model3_Packet1(gspca_dev, 0x0011, 0x0070);
  1985. cit_model3_Packet1(gspca_dev, 0x0012, 0x0030);
  1986. cit_model3_Packet1(gspca_dev, 0x0013, 0x0000);
  1987. cit_model3_Packet1(gspca_dev, 0x0014, 0x0001);
  1988. cit_model3_Packet1(gspca_dev, 0x0015, 0x0001);
  1989. cit_model3_Packet1(gspca_dev, 0x0016, 0x0001);
  1990. cit_model3_Packet1(gspca_dev, 0x0017, 0x0001);
  1991. cit_model3_Packet1(gspca_dev, 0x0018, 0x0000);
  1992. cit_model3_Packet1(gspca_dev, 0x001e, 0x00c3);
  1993. cit_model3_Packet1(gspca_dev, 0x0020, 0x0000);
  1994. cit_model3_Packet1(gspca_dev, 0x0028, 0x0010);
  1995. cit_model3_Packet1(gspca_dev, 0x0029, 0x0054);
  1996. cit_model3_Packet1(gspca_dev, 0x002a, 0x0013);
  1997. cit_model3_Packet1(gspca_dev, 0x002b, 0x0007);
  1998. cit_model3_Packet1(gspca_dev, 0x002d, 0x0028);
  1999. cit_model3_Packet1(gspca_dev, 0x002e, 0x0000);
  2000. cit_model3_Packet1(gspca_dev, 0x0031, 0x0000);
  2001. cit_model3_Packet1(gspca_dev, 0x0032, 0x0000);
  2002. cit_model3_Packet1(gspca_dev, 0x0033, 0x0000);
  2003. cit_model3_Packet1(gspca_dev, 0x0034, 0x0000);
  2004. cit_model3_Packet1(gspca_dev, 0x0035, 0x0038);
  2005. cit_model3_Packet1(gspca_dev, 0x003a, 0x0001);
  2006. cit_model3_Packet1(gspca_dev, 0x003c, 0x001e);
  2007. cit_model3_Packet1(gspca_dev, 0x003f, 0x000a);
  2008. cit_model3_Packet1(gspca_dev, 0x0041, 0x0000);
  2009. cit_model3_Packet1(gspca_dev, 0x0046, 0x003f);
  2010. cit_model3_Packet1(gspca_dev, 0x0047, 0x0000);
  2011. cit_model3_Packet1(gspca_dev, 0x0050, 0x0005);
  2012. cit_model3_Packet1(gspca_dev, 0x0052, 0x001a);
  2013. cit_model3_Packet1(gspca_dev, 0x0053, 0x0003);
  2014. cit_model3_Packet1(gspca_dev, 0x005a, 0x006b);
  2015. cit_model3_Packet1(gspca_dev, 0x005d, 0x001e);
  2016. cit_model3_Packet1(gspca_dev, 0x005e, 0x0030);
  2017. cit_model3_Packet1(gspca_dev, 0x005f, 0x0041);
  2018. cit_model3_Packet1(gspca_dev, 0x0064, 0x0008);
  2019. cit_model3_Packet1(gspca_dev, 0x0065, 0x0015);
  2020. cit_model3_Packet1(gspca_dev, 0x0068, 0x000f);
  2021. cit_model3_Packet1(gspca_dev, 0x0079, 0x0000);
  2022. cit_model3_Packet1(gspca_dev, 0x007a, 0x0000);
  2023. cit_model3_Packet1(gspca_dev, 0x007c, 0x003f);
  2024. cit_model3_Packet1(gspca_dev, 0x0082, 0x000f);
  2025. cit_model3_Packet1(gspca_dev, 0x0085, 0x0000);
  2026. cit_model3_Packet1(gspca_dev, 0x0099, 0x0000);
  2027. cit_model3_Packet1(gspca_dev, 0x009b, 0x0023);
  2028. cit_model3_Packet1(gspca_dev, 0x009c, 0x0022);
  2029. cit_model3_Packet1(gspca_dev, 0x009d, 0x0096);
  2030. cit_model3_Packet1(gspca_dev, 0x009e, 0x0096);
  2031. cit_model3_Packet1(gspca_dev, 0x009f, 0x000a);
  2032. switch (gspca_dev->width) {
  2033. case 160:
  2034. cit_write_reg(gspca_dev, 0x0000, 0x0101); /* Same on 160x120, 320x240 */
  2035. cit_write_reg(gspca_dev, 0x00a0, 0x0103); /* Same on 160x120, 320x240 */
  2036. cit_write_reg(gspca_dev, 0x0078, 0x0105); /* Same on 160x120, 320x240 */
  2037. cit_write_reg(gspca_dev, 0x0000, 0x010a); /* Same */
  2038. cit_write_reg(gspca_dev, 0x0024, 0x010b); /* Differs everywhere */
  2039. cit_write_reg(gspca_dev, 0x00a9, 0x0119);
  2040. cit_write_reg(gspca_dev, 0x0016, 0x011b);
  2041. cit_write_reg(gspca_dev, 0x0002, 0x011d); /* Same on 160x120, 320x240 */
  2042. cit_write_reg(gspca_dev, 0x0003, 0x011e); /* Same on 160x120, 640x480 */
  2043. cit_write_reg(gspca_dev, 0x0000, 0x0129); /* Same */
  2044. cit_write_reg(gspca_dev, 0x00fc, 0x012b); /* Same */
  2045. cit_write_reg(gspca_dev, 0x0018, 0x0102);
  2046. cit_write_reg(gspca_dev, 0x0004, 0x0104);
  2047. cit_write_reg(gspca_dev, 0x0004, 0x011a);
  2048. cit_write_reg(gspca_dev, 0x0028, 0x011c);
  2049. cit_write_reg(gspca_dev, 0x0022, 0x012a); /* Same */
  2050. cit_write_reg(gspca_dev, 0x0000, 0x0118);
  2051. cit_write_reg(gspca_dev, 0x0000, 0x0132);
  2052. cit_model3_Packet1(gspca_dev, 0x0021, 0x0001); /* Same */
  2053. cit_write_reg(gspca_dev, compression, 0x0109);
  2054. clock_div = 3;
  2055. break;
  2056. case 320:
  2057. cit_write_reg(gspca_dev, 0x0000, 0x0101); /* Same on 160x120, 320x240 */
  2058. cit_write_reg(gspca_dev, 0x00a0, 0x0103); /* Same on 160x120, 320x240 */
  2059. cit_write_reg(gspca_dev, 0x0078, 0x0105); /* Same on 160x120, 320x240 */
  2060. cit_write_reg(gspca_dev, 0x0000, 0x010a); /* Same */
  2061. cit_write_reg(gspca_dev, 0x0028, 0x010b); /* Differs everywhere */
  2062. cit_write_reg(gspca_dev, 0x0002, 0x011d); /* Same */
  2063. cit_write_reg(gspca_dev, 0x0000, 0x011e);
  2064. cit_write_reg(gspca_dev, 0x0000, 0x0129); /* Same */
  2065. cit_write_reg(gspca_dev, 0x00fc, 0x012b); /* Same */
  2066. /* 4 commands from 160x120 skipped */
  2067. cit_write_reg(gspca_dev, 0x0022, 0x012a); /* Same */
  2068. cit_model3_Packet1(gspca_dev, 0x0021, 0x0001); /* Same */
  2069. cit_write_reg(gspca_dev, compression, 0x0109);
  2070. cit_write_reg(gspca_dev, 0x00d9, 0x0119);
  2071. cit_write_reg(gspca_dev, 0x0006, 0x011b);
  2072. cit_write_reg(gspca_dev, 0x0021, 0x0102); /* Same on 320x240, 640x480 */
  2073. cit_write_reg(gspca_dev, 0x0010, 0x0104);
  2074. cit_write_reg(gspca_dev, 0x0004, 0x011a);
  2075. cit_write_reg(gspca_dev, 0x003f, 0x011c);
  2076. cit_write_reg(gspca_dev, 0x001c, 0x0118);
  2077. cit_write_reg(gspca_dev, 0x0000, 0x0132);
  2078. clock_div = 5;
  2079. break;
  2080. case 640:
  2081. cit_write_reg(gspca_dev, 0x00f0, 0x0105);
  2082. cit_write_reg(gspca_dev, 0x0000, 0x010a); /* Same */
  2083. cit_write_reg(gspca_dev, 0x0038, 0x010b); /* Differs everywhere */
  2084. cit_write_reg(gspca_dev, 0x00d9, 0x0119); /* Same on 320x240, 640x480 */
  2085. cit_write_reg(gspca_dev, 0x0006, 0x011b); /* Same on 320x240, 640x480 */
  2086. cit_write_reg(gspca_dev, 0x0004, 0x011d); /* NC */
  2087. cit_write_reg(gspca_dev, 0x0003, 0x011e); /* Same on 160x120, 640x480 */
  2088. cit_write_reg(gspca_dev, 0x0000, 0x0129); /* Same */
  2089. cit_write_reg(gspca_dev, 0x00fc, 0x012b); /* Same */
  2090. cit_write_reg(gspca_dev, 0x0021, 0x0102); /* Same on 320x240, 640x480 */
  2091. cit_write_reg(gspca_dev, 0x0016, 0x0104); /* NC */
  2092. cit_write_reg(gspca_dev, 0x0004, 0x011a); /* Same on 320x240, 640x480 */
  2093. cit_write_reg(gspca_dev, 0x003f, 0x011c); /* Same on 320x240, 640x480 */
  2094. cit_write_reg(gspca_dev, 0x0022, 0x012a); /* Same */
  2095. cit_write_reg(gspca_dev, 0x001c, 0x0118); /* Same on 320x240, 640x480 */
  2096. cit_model3_Packet1(gspca_dev, 0x0021, 0x0001); /* Same */
  2097. cit_write_reg(gspca_dev, compression, 0x0109);
  2098. cit_write_reg(gspca_dev, 0x0040, 0x0101);
  2099. cit_write_reg(gspca_dev, 0x0040, 0x0103);
  2100. cit_write_reg(gspca_dev, 0x0000, 0x0132); /* Same on 320x240, 640x480 */
  2101. clock_div = 7;
  2102. break;
  2103. }
  2104. cit_model3_Packet1(gspca_dev, 0x007e, 0x000e); /* Hue */
  2105. cit_model3_Packet1(gspca_dev, 0x0036, 0x0011); /* Brightness */
  2106. cit_model3_Packet1(gspca_dev, 0x0060, 0x0002); /* Sharpness */
  2107. cit_model3_Packet1(gspca_dev, 0x0061, 0x0004); /* Sharpness */
  2108. cit_model3_Packet1(gspca_dev, 0x0062, 0x0005); /* Sharpness */
  2109. cit_model3_Packet1(gspca_dev, 0x0063, 0x0014); /* Sharpness */
  2110. cit_model3_Packet1(gspca_dev, 0x0096, 0x00a0); /* Red sharpness */
  2111. cit_model3_Packet1(gspca_dev, 0x0097, 0x0096); /* Blue sharpness */
  2112. cit_model3_Packet1(gspca_dev, 0x0067, 0x0001); /* Contrast */
  2113. cit_model3_Packet1(gspca_dev, 0x005b, 0x000c); /* Contrast */
  2114. cit_model3_Packet1(gspca_dev, 0x005c, 0x0016); /* Contrast */
  2115. cit_model3_Packet1(gspca_dev, 0x0098, 0x000b);
  2116. cit_model3_Packet1(gspca_dev, 0x002c, 0x0003); /* Was 1, broke 640x480 */
  2117. cit_model3_Packet1(gspca_dev, 0x002f, 0x002a);
  2118. cit_model3_Packet1(gspca_dev, 0x0030, 0x0029);
  2119. cit_model3_Packet1(gspca_dev, 0x0037, 0x0002);
  2120. cit_model3_Packet1(gspca_dev, 0x0038, 0x0059);
  2121. cit_model3_Packet1(gspca_dev, 0x003d, 0x002e);
  2122. cit_model3_Packet1(gspca_dev, 0x003e, 0x0028);
  2123. cit_model3_Packet1(gspca_dev, 0x0078, 0x0005);
  2124. cit_model3_Packet1(gspca_dev, 0x007b, 0x0011);
  2125. cit_model3_Packet1(gspca_dev, 0x007d, 0x004b);
  2126. cit_model3_Packet1(gspca_dev, 0x007f, 0x0022);
  2127. cit_model3_Packet1(gspca_dev, 0x0080, 0x000c);
  2128. cit_model3_Packet1(gspca_dev, 0x0081, 0x000b);
  2129. cit_model3_Packet1(gspca_dev, 0x0083, 0x00fd);
  2130. cit_model3_Packet1(gspca_dev, 0x0086, 0x000b);
  2131. cit_model3_Packet1(gspca_dev, 0x0087, 0x000b);
  2132. cit_model3_Packet1(gspca_dev, 0x007e, 0x000e);
  2133. cit_model3_Packet1(gspca_dev, 0x0096, 0x00a0); /* Red sharpness */
  2134. cit_model3_Packet1(gspca_dev, 0x0097, 0x0096); /* Blue sharpness */
  2135. cit_model3_Packet1(gspca_dev, 0x0098, 0x000b);
  2136. /* FIXME we should probably use cit_get_clock_div() here (in
  2137. combination with isoc negotiation using the programmable isoc size)
  2138. like with the IBM netcam pro). */
  2139. cit_write_reg(gspca_dev, clock_div, 0x0111); /* Clock Divider */
  2140. switch (gspca_dev->width) {
  2141. case 160:
  2142. cit_model3_Packet1(gspca_dev, 0x001f, 0x0000); /* Same */
  2143. cit_model3_Packet1(gspca_dev, 0x0039, 0x001f); /* Same */
  2144. cit_model3_Packet1(gspca_dev, 0x003b, 0x003c); /* Same */
  2145. cit_model3_Packet1(gspca_dev, 0x0040, 0x000a);
  2146. cit_model3_Packet1(gspca_dev, 0x0051, 0x000a);
  2147. break;
  2148. case 320:
  2149. cit_model3_Packet1(gspca_dev, 0x001f, 0x0000); /* Same */
  2150. cit_model3_Packet1(gspca_dev, 0x0039, 0x001f); /* Same */
  2151. cit_model3_Packet1(gspca_dev, 0x003b, 0x003c); /* Same */
  2152. cit_model3_Packet1(gspca_dev, 0x0040, 0x0008);
  2153. cit_model3_Packet1(gspca_dev, 0x0051, 0x000b);
  2154. break;
  2155. case 640:
  2156. cit_model3_Packet1(gspca_dev, 0x001f, 0x0002); /* !Same */
  2157. cit_model3_Packet1(gspca_dev, 0x0039, 0x003e); /* !Same */
  2158. cit_model3_Packet1(gspca_dev, 0x0040, 0x0008);
  2159. cit_model3_Packet1(gspca_dev, 0x0051, 0x000a);
  2160. break;
  2161. }
  2162. /* if (sd->input_index) { */
  2163. if (rca_input) {
  2164. for (i = 0; i < ARRAY_SIZE(rca_initdata); i++) {
  2165. if (rca_initdata[i][0])
  2166. cit_read_reg(gspca_dev, rca_initdata[i][2], 0);
  2167. else
  2168. cit_write_reg(gspca_dev, rca_initdata[i][1],
  2169. rca_initdata[i][2]);
  2170. }
  2171. }
  2172. return 0;
  2173. }
  2174. static int cit_start_model4(struct gspca_dev *gspca_dev)
  2175. {
  2176. struct sd *sd = (struct sd *) gspca_dev;
  2177. cit_write_reg(gspca_dev, 0x0000, 0x0100);
  2178. cit_write_reg(gspca_dev, 0x00c0, 0x0111);
  2179. cit_write_reg(gspca_dev, 0x00bc, 0x012c);
  2180. cit_write_reg(gspca_dev, 0x0080, 0x012b);
  2181. cit_write_reg(gspca_dev, 0x0000, 0x0108);
  2182. cit_write_reg(gspca_dev, 0x0001, 0x0133);
  2183. cit_write_reg(gspca_dev, 0x009b, 0x010f);
  2184. cit_write_reg(gspca_dev, 0x00bb, 0x010f);
  2185. cit_model4_Packet1(gspca_dev, 0x0038, 0x0000);
  2186. cit_model4_Packet1(gspca_dev, 0x000a, 0x005c);
  2187. cit_write_reg(gspca_dev, 0x00aa, 0x012d);
  2188. cit_write_reg(gspca_dev, 0x0004, 0x012f);
  2189. cit_write_reg(gspca_dev, 0xd141, 0x0124);
  2190. cit_write_reg(gspca_dev, 0x0000, 0x0127);
  2191. cit_write_reg(gspca_dev, 0x00fb, 0x012e);
  2192. cit_write_reg(gspca_dev, 0x0000, 0x0130);
  2193. cit_write_reg(gspca_dev, 0x8a28, 0x0124);
  2194. cit_write_reg(gspca_dev, 0x00aa, 0x012f);
  2195. cit_write_reg(gspca_dev, 0xd055, 0x0124);
  2196. cit_write_reg(gspca_dev, 0x000c, 0x0127);
  2197. cit_write_reg(gspca_dev, 0x0009, 0x012e);
  2198. cit_write_reg(gspca_dev, 0xaa28, 0x0124);
  2199. cit_write_reg(gspca_dev, 0x00aa, 0x012d);
  2200. cit_write_reg(gspca_dev, 0x0012, 0x012f);
  2201. cit_write_reg(gspca_dev, 0xd141, 0x0124);
  2202. cit_write_reg(gspca_dev, 0x0008, 0x0127);
  2203. cit_write_reg(gspca_dev, 0x00aa, 0x0130);
  2204. cit_write_reg(gspca_dev, 0x82a8, 0x0124);
  2205. cit_write_reg(gspca_dev, 0x002a, 0x012d);
  2206. cit_write_reg(gspca_dev, 0x0000, 0x012f);
  2207. cit_write_reg(gspca_dev, 0xd145, 0x0124);
  2208. cit_write_reg(gspca_dev, 0xfffa, 0x0124);
  2209. cit_model4_Packet1(gspca_dev, 0x0034, 0x0000);
  2210. switch (gspca_dev->width) {
  2211. case 128: /* 128x96 */
  2212. cit_write_reg(gspca_dev, 0x0070, 0x0119);
  2213. cit_write_reg(gspca_dev, 0x00d0, 0x0111);
  2214. cit_write_reg(gspca_dev, 0x0039, 0x010a);
  2215. cit_write_reg(gspca_dev, 0x0001, 0x0102);
  2216. cit_write_reg(gspca_dev, 0x0028, 0x0103);
  2217. cit_write_reg(gspca_dev, 0x0000, 0x0104);
  2218. cit_write_reg(gspca_dev, 0x001e, 0x0105);
  2219. cit_write_reg(gspca_dev, 0x00aa, 0x012d);
  2220. cit_write_reg(gspca_dev, 0x0016, 0x012f);
  2221. cit_write_reg(gspca_dev, 0xd141, 0x0124);
  2222. cit_write_reg(gspca_dev, 0x000a, 0x0127);
  2223. cit_write_reg(gspca_dev, 0x00aa, 0x0130);
  2224. cit_write_reg(gspca_dev, 0x82a8, 0x0124);
  2225. cit_write_reg(gspca_dev, 0x0014, 0x012d);
  2226. cit_write_reg(gspca_dev, 0x0008, 0x012f);
  2227. cit_write_reg(gspca_dev, 0xd145, 0x0124);
  2228. cit_write_reg(gspca_dev, 0x00aa, 0x012e);
  2229. cit_write_reg(gspca_dev, 0x001a, 0x0130);
  2230. cit_write_reg(gspca_dev, 0x8a0a, 0x0124);
  2231. cit_write_reg(gspca_dev, 0x005a, 0x012d);
  2232. cit_write_reg(gspca_dev, 0x9545, 0x0124);
  2233. cit_write_reg(gspca_dev, 0x00aa, 0x0127);
  2234. cit_write_reg(gspca_dev, 0x0018, 0x012e);
  2235. cit_write_reg(gspca_dev, 0x0043, 0x0130);
  2236. cit_write_reg(gspca_dev, 0x8a28, 0x0124);
  2237. cit_write_reg(gspca_dev, 0x00aa, 0x012f);
  2238. cit_write_reg(gspca_dev, 0xd055, 0x0124);
  2239. cit_write_reg(gspca_dev, 0x001c, 0x0127);
  2240. cit_write_reg(gspca_dev, 0x00eb, 0x012e);
  2241. cit_write_reg(gspca_dev, 0xaa28, 0x0124);
  2242. cit_write_reg(gspca_dev, 0x00aa, 0x012d);
  2243. cit_write_reg(gspca_dev, 0x0032, 0x012f);
  2244. cit_write_reg(gspca_dev, 0xd141, 0x0124);
  2245. cit_write_reg(gspca_dev, 0x0000, 0x0127);
  2246. cit_write_reg(gspca_dev, 0x00aa, 0x0130);
  2247. cit_write_reg(gspca_dev, 0x82a8, 0x0124);
  2248. cit_write_reg(gspca_dev, 0x0036, 0x012d);
  2249. cit_write_reg(gspca_dev, 0x0008, 0x012f);
  2250. cit_write_reg(gspca_dev, 0xd145, 0x0124);
  2251. cit_write_reg(gspca_dev, 0xfffa, 0x0124);
  2252. cit_write_reg(gspca_dev, 0x00aa, 0x012d);
  2253. cit_write_reg(gspca_dev, 0x001e, 0x012f);
  2254. cit_write_reg(gspca_dev, 0xd141, 0x0124);
  2255. cit_write_reg(gspca_dev, 0x0017, 0x0127);
  2256. cit_write_reg(gspca_dev, 0x0013, 0x012e);
  2257. cit_write_reg(gspca_dev, 0x0031, 0x0130);
  2258. cit_write_reg(gspca_dev, 0x8a28, 0x0124);
  2259. cit_write_reg(gspca_dev, 0x0017, 0x012d);
  2260. cit_write_reg(gspca_dev, 0x0078, 0x012f);
  2261. cit_write_reg(gspca_dev, 0xd145, 0x0124);
  2262. cit_write_reg(gspca_dev, 0x0000, 0x0127);
  2263. cit_write_reg(gspca_dev, 0xfea8, 0x0124);
  2264. sd->sof_len = 2;
  2265. break;
  2266. case 160: /* 160x120 */
  2267. cit_write_reg(gspca_dev, 0x0038, 0x0119);
  2268. cit_write_reg(gspca_dev, 0x00d0, 0x0111);
  2269. cit_write_reg(gspca_dev, 0x00b9, 0x010a);
  2270. cit_write_reg(gspca_dev, 0x0001, 0x0102);
  2271. cit_write_reg(gspca_dev, 0x0028, 0x0103);
  2272. cit_write_reg(gspca_dev, 0x0000, 0x0104);
  2273. cit_write_reg(gspca_dev, 0x001e, 0x0105);
  2274. cit_write_reg(gspca_dev, 0x00aa, 0x012d);
  2275. cit_write_reg(gspca_dev, 0x0016, 0x012f);
  2276. cit_write_reg(gspca_dev, 0xd141, 0x0124);
  2277. cit_write_reg(gspca_dev, 0x000b, 0x0127);
  2278. cit_write_reg(gspca_dev, 0x00aa, 0x0130);
  2279. cit_write_reg(gspca_dev, 0x82a8, 0x0124);
  2280. cit_write_reg(gspca_dev, 0x0014, 0x012d);
  2281. cit_write_reg(gspca_dev, 0x0008, 0x012f);
  2282. cit_write_reg(gspca_dev, 0xd145, 0x0124);
  2283. cit_write_reg(gspca_dev, 0x00aa, 0x012e);
  2284. cit_write_reg(gspca_dev, 0x001a, 0x0130);
  2285. cit_write_reg(gspca_dev, 0x8a0a, 0x0124);
  2286. cit_write_reg(gspca_dev, 0x005a, 0x012d);
  2287. cit_write_reg(gspca_dev, 0x9545, 0x0124);
  2288. cit_write_reg(gspca_dev, 0x00aa, 0x0127);
  2289. cit_write_reg(gspca_dev, 0x0018, 0x012e);
  2290. cit_write_reg(gspca_dev, 0x0043, 0x0130);
  2291. cit_write_reg(gspca_dev, 0x8a28, 0x0124);
  2292. cit_write_reg(gspca_dev, 0x00aa, 0x012f);
  2293. cit_write_reg(gspca_dev, 0xd055, 0x0124);
  2294. cit_write_reg(gspca_dev, 0x001c, 0x0127);
  2295. cit_write_reg(gspca_dev, 0x00c7, 0x012e);
  2296. cit_write_reg(gspca_dev, 0xaa28, 0x0124);
  2297. cit_write_reg(gspca_dev, 0x00aa, 0x012d);
  2298. cit_write_reg(gspca_dev, 0x0032, 0x012f);
  2299. cit_write_reg(gspca_dev, 0xd141, 0x0124);
  2300. cit_write_reg(gspca_dev, 0x0025, 0x0127);
  2301. cit_write_reg(gspca_dev, 0x00aa, 0x0130);
  2302. cit_write_reg(gspca_dev, 0x82a8, 0x0124);
  2303. cit_write_reg(gspca_dev, 0x0036, 0x012d);
  2304. cit_write_reg(gspca_dev, 0x0008, 0x012f);
  2305. cit_write_reg(gspca_dev, 0xd145, 0x0124);
  2306. cit_write_reg(gspca_dev, 0xfffa, 0x0124);
  2307. cit_write_reg(gspca_dev, 0x00aa, 0x012d);
  2308. cit_write_reg(gspca_dev, 0x001e, 0x012f);
  2309. cit_write_reg(gspca_dev, 0xd141, 0x0124);
  2310. cit_write_reg(gspca_dev, 0x0048, 0x0127);
  2311. cit_write_reg(gspca_dev, 0x0035, 0x012e);
  2312. cit_write_reg(gspca_dev, 0x00d0, 0x0130);
  2313. cit_write_reg(gspca_dev, 0x8a28, 0x0124);
  2314. cit_write_reg(gspca_dev, 0x0048, 0x012d);
  2315. cit_write_reg(gspca_dev, 0x0090, 0x012f);
  2316. cit_write_reg(gspca_dev, 0xd145, 0x0124);
  2317. cit_write_reg(gspca_dev, 0x0001, 0x0127);
  2318. cit_write_reg(gspca_dev, 0xfea8, 0x0124);
  2319. sd->sof_len = 2;
  2320. break;
  2321. case 176: /* 176x144 */
  2322. cit_write_reg(gspca_dev, 0x0038, 0x0119);
  2323. cit_write_reg(gspca_dev, 0x00d0, 0x0111);
  2324. cit_write_reg(gspca_dev, 0x00b9, 0x010a);
  2325. cit_write_reg(gspca_dev, 0x0001, 0x0102);
  2326. cit_write_reg(gspca_dev, 0x002c, 0x0103);
  2327. cit_write_reg(gspca_dev, 0x0000, 0x0104);
  2328. cit_write_reg(gspca_dev, 0x0024, 0x0105);
  2329. cit_write_reg(gspca_dev, 0x00aa, 0x012d);
  2330. cit_write_reg(gspca_dev, 0x0016, 0x012f);
  2331. cit_write_reg(gspca_dev, 0xd141, 0x0124);
  2332. cit_write_reg(gspca_dev, 0x0007, 0x0127);
  2333. cit_write_reg(gspca_dev, 0x00aa, 0x0130);
  2334. cit_write_reg(gspca_dev, 0x82a8, 0x0124);
  2335. cit_write_reg(gspca_dev, 0x0014, 0x012d);
  2336. cit_write_reg(gspca_dev, 0x0001, 0x012f);
  2337. cit_write_reg(gspca_dev, 0xd145, 0x0124);
  2338. cit_write_reg(gspca_dev, 0x00aa, 0x012e);
  2339. cit_write_reg(gspca_dev, 0x001a, 0x0130);
  2340. cit_write_reg(gspca_dev, 0x8a0a, 0x0124);
  2341. cit_write_reg(gspca_dev, 0x005e, 0x012d);
  2342. cit_write_reg(gspca_dev, 0x9545, 0x0124);
  2343. cit_write_reg(gspca_dev, 0x00aa, 0x0127);
  2344. cit_write_reg(gspca_dev, 0x0018, 0x012e);
  2345. cit_write_reg(gspca_dev, 0x0049, 0x0130);
  2346. cit_write_reg(gspca_dev, 0x8a28, 0x0124);
  2347. cit_write_reg(gspca_dev, 0x00aa, 0x012f);
  2348. cit_write_reg(gspca_dev, 0xd055, 0x0124);
  2349. cit_write_reg(gspca_dev, 0x001c, 0x0127);
  2350. cit_write_reg(gspca_dev, 0x00c7, 0x012e);
  2351. cit_write_reg(gspca_dev, 0xaa28, 0x0124);
  2352. cit_write_reg(gspca_dev, 0x00aa, 0x012d);
  2353. cit_write_reg(gspca_dev, 0x0032, 0x012f);
  2354. cit_write_reg(gspca_dev, 0xd141, 0x0124);
  2355. cit_write_reg(gspca_dev, 0x0028, 0x0127);
  2356. cit_write_reg(gspca_dev, 0x00aa, 0x0130);
  2357. cit_write_reg(gspca_dev, 0x82a8, 0x0124);
  2358. cit_write_reg(gspca_dev, 0x0036, 0x012d);
  2359. cit_write_reg(gspca_dev, 0x0008, 0x012f);
  2360. cit_write_reg(gspca_dev, 0xd145, 0x0124);
  2361. cit_write_reg(gspca_dev, 0xfffa, 0x0124);
  2362. cit_write_reg(gspca_dev, 0x00aa, 0x012d);
  2363. cit_write_reg(gspca_dev, 0x001e, 0x012f);
  2364. cit_write_reg(gspca_dev, 0xd141, 0x0124);
  2365. cit_write_reg(gspca_dev, 0x0010, 0x0127);
  2366. cit_write_reg(gspca_dev, 0x0013, 0x012e);
  2367. cit_write_reg(gspca_dev, 0x002a, 0x0130);
  2368. cit_write_reg(gspca_dev, 0x8a28, 0x0124);
  2369. cit_write_reg(gspca_dev, 0x0010, 0x012d);
  2370. cit_write_reg(gspca_dev, 0x006d, 0x012f);
  2371. cit_write_reg(gspca_dev, 0xd145, 0x0124);
  2372. cit_write_reg(gspca_dev, 0x0001, 0x0127);
  2373. cit_write_reg(gspca_dev, 0xfea8, 0x0124);
  2374. /* TESTME HDG: this does not seem right
  2375. (it is 2 for all other resolutions) */
  2376. sd->sof_len = 10;
  2377. break;
  2378. case 320: /* 320x240 */
  2379. cit_write_reg(gspca_dev, 0x0070, 0x0119);
  2380. cit_write_reg(gspca_dev, 0x00d0, 0x0111);
  2381. cit_write_reg(gspca_dev, 0x0039, 0x010a);
  2382. cit_write_reg(gspca_dev, 0x0001, 0x0102);
  2383. cit_write_reg(gspca_dev, 0x0028, 0x0103);
  2384. cit_write_reg(gspca_dev, 0x0000, 0x0104);
  2385. cit_write_reg(gspca_dev, 0x001e, 0x0105);
  2386. cit_write_reg(gspca_dev, 0x00aa, 0x012d);
  2387. cit_write_reg(gspca_dev, 0x0016, 0x012f);
  2388. cit_write_reg(gspca_dev, 0xd141, 0x0124);
  2389. cit_write_reg(gspca_dev, 0x000a, 0x0127);
  2390. cit_write_reg(gspca_dev, 0x00aa, 0x0130);
  2391. cit_write_reg(gspca_dev, 0x82a8, 0x0124);
  2392. cit_write_reg(gspca_dev, 0x0014, 0x012d);
  2393. cit_write_reg(gspca_dev, 0x0008, 0x012f);
  2394. cit_write_reg(gspca_dev, 0xd145, 0x0124);
  2395. cit_write_reg(gspca_dev, 0x00aa, 0x012e);
  2396. cit_write_reg(gspca_dev, 0x001a, 0x0130);
  2397. cit_write_reg(gspca_dev, 0x8a0a, 0x0124);
  2398. cit_write_reg(gspca_dev, 0x005a, 0x012d);
  2399. cit_write_reg(gspca_dev, 0x9545, 0x0124);
  2400. cit_write_reg(gspca_dev, 0x00aa, 0x0127);
  2401. cit_write_reg(gspca_dev, 0x0018, 0x012e);
  2402. cit_write_reg(gspca_dev, 0x0043, 0x0130);
  2403. cit_write_reg(gspca_dev, 0x8a28, 0x0124);
  2404. cit_write_reg(gspca_dev, 0x00aa, 0x012f);
  2405. cit_write_reg(gspca_dev, 0xd055, 0x0124);
  2406. cit_write_reg(gspca_dev, 0x001c, 0x0127);
  2407. cit_write_reg(gspca_dev, 0x00eb, 0x012e);
  2408. cit_write_reg(gspca_dev, 0xaa28, 0x0124);
  2409. cit_write_reg(gspca_dev, 0x00aa, 0x012d);
  2410. cit_write_reg(gspca_dev, 0x0032, 0x012f);
  2411. cit_write_reg(gspca_dev, 0xd141, 0x0124);
  2412. cit_write_reg(gspca_dev, 0x0000, 0x0127);
  2413. cit_write_reg(gspca_dev, 0x00aa, 0x0130);
  2414. cit_write_reg(gspca_dev, 0x82a8, 0x0124);
  2415. cit_write_reg(gspca_dev, 0x0036, 0x012d);
  2416. cit_write_reg(gspca_dev, 0x0008, 0x012f);
  2417. cit_write_reg(gspca_dev, 0xd145, 0x0124);
  2418. cit_write_reg(gspca_dev, 0xfffa, 0x0124);
  2419. cit_write_reg(gspca_dev, 0x00aa, 0x012d);
  2420. cit_write_reg(gspca_dev, 0x001e, 0x012f);
  2421. cit_write_reg(gspca_dev, 0xd141, 0x0124);
  2422. cit_write_reg(gspca_dev, 0x0017, 0x0127);
  2423. cit_write_reg(gspca_dev, 0x0013, 0x012e);
  2424. cit_write_reg(gspca_dev, 0x0031, 0x0130);
  2425. cit_write_reg(gspca_dev, 0x8a28, 0x0124);
  2426. cit_write_reg(gspca_dev, 0x0017, 0x012d);
  2427. cit_write_reg(gspca_dev, 0x0078, 0x012f);
  2428. cit_write_reg(gspca_dev, 0xd145, 0x0124);
  2429. cit_write_reg(gspca_dev, 0x0000, 0x0127);
  2430. cit_write_reg(gspca_dev, 0xfea8, 0x0124);
  2431. sd->sof_len = 2;
  2432. break;
  2433. case 352: /* 352x288 */
  2434. cit_write_reg(gspca_dev, 0x0070, 0x0119);
  2435. cit_write_reg(gspca_dev, 0x00c0, 0x0111);
  2436. cit_write_reg(gspca_dev, 0x0039, 0x010a);
  2437. cit_write_reg(gspca_dev, 0x0001, 0x0102);
  2438. cit_write_reg(gspca_dev, 0x002c, 0x0103);
  2439. cit_write_reg(gspca_dev, 0x0000, 0x0104);
  2440. cit_write_reg(gspca_dev, 0x0024, 0x0105);
  2441. cit_write_reg(gspca_dev, 0x00aa, 0x012d);
  2442. cit_write_reg(gspca_dev, 0x0016, 0x012f);
  2443. cit_write_reg(gspca_dev, 0xd141, 0x0124);
  2444. cit_write_reg(gspca_dev, 0x0006, 0x0127);
  2445. cit_write_reg(gspca_dev, 0x00aa, 0x0130);
  2446. cit_write_reg(gspca_dev, 0x82a8, 0x0124);
  2447. cit_write_reg(gspca_dev, 0x0014, 0x012d);
  2448. cit_write_reg(gspca_dev, 0x0002, 0x012f);
  2449. cit_write_reg(gspca_dev, 0xd145, 0x0124);
  2450. cit_write_reg(gspca_dev, 0x00aa, 0x012e);
  2451. cit_write_reg(gspca_dev, 0x001a, 0x0130);
  2452. cit_write_reg(gspca_dev, 0x8a0a, 0x0124);
  2453. cit_write_reg(gspca_dev, 0x005e, 0x012d);
  2454. cit_write_reg(gspca_dev, 0x9545, 0x0124);
  2455. cit_write_reg(gspca_dev, 0x00aa, 0x0127);
  2456. cit_write_reg(gspca_dev, 0x0018, 0x012e);
  2457. cit_write_reg(gspca_dev, 0x0049, 0x0130);
  2458. cit_write_reg(gspca_dev, 0x8a28, 0x0124);
  2459. cit_write_reg(gspca_dev, 0x00aa, 0x012f);
  2460. cit_write_reg(gspca_dev, 0xd055, 0x0124);
  2461. cit_write_reg(gspca_dev, 0x001c, 0x0127);
  2462. cit_write_reg(gspca_dev, 0x00cf, 0x012e);
  2463. cit_write_reg(gspca_dev, 0xaa28, 0x0124);
  2464. cit_write_reg(gspca_dev, 0x00aa, 0x012d);
  2465. cit_write_reg(gspca_dev, 0x0032, 0x012f);
  2466. cit_write_reg(gspca_dev, 0xd141, 0x0124);
  2467. cit_write_reg(gspca_dev, 0x0000, 0x0127);
  2468. cit_write_reg(gspca_dev, 0x00aa, 0x0130);
  2469. cit_write_reg(gspca_dev, 0x82a8, 0x0124);
  2470. cit_write_reg(gspca_dev, 0x0036, 0x012d);
  2471. cit_write_reg(gspca_dev, 0x0008, 0x012f);
  2472. cit_write_reg(gspca_dev, 0xd145, 0x0124);
  2473. cit_write_reg(gspca_dev, 0xfffa, 0x0124);
  2474. cit_write_reg(gspca_dev, 0x00aa, 0x012d);
  2475. cit_write_reg(gspca_dev, 0x001e, 0x012f);
  2476. cit_write_reg(gspca_dev, 0xd141, 0x0124);
  2477. cit_write_reg(gspca_dev, 0x0010, 0x0127);
  2478. cit_write_reg(gspca_dev, 0x0013, 0x012e);
  2479. cit_write_reg(gspca_dev, 0x0025, 0x0130);
  2480. cit_write_reg(gspca_dev, 0x8a28, 0x0124);
  2481. cit_write_reg(gspca_dev, 0x0010, 0x012d);
  2482. cit_write_reg(gspca_dev, 0x0048, 0x012f);
  2483. cit_write_reg(gspca_dev, 0xd145, 0x0124);
  2484. cit_write_reg(gspca_dev, 0x0000, 0x0127);
  2485. cit_write_reg(gspca_dev, 0xfea8, 0x0124);
  2486. sd->sof_len = 2;
  2487. break;
  2488. }
  2489. cit_model4_Packet1(gspca_dev, 0x0038, 0x0004);
  2490. return 0;
  2491. }
  2492. static int cit_start_ibm_netcam_pro(struct gspca_dev *gspca_dev)
  2493. {
  2494. const unsigned short compression = 0; /* 0=none, 7=best frame rate */
  2495. int i, clock_div;
  2496. clock_div = cit_get_clock_div(gspca_dev);
  2497. if (clock_div < 0)
  2498. return clock_div;
  2499. cit_write_reg(gspca_dev, 0x0003, 0x0133);
  2500. cit_write_reg(gspca_dev, 0x0000, 0x0117);
  2501. cit_write_reg(gspca_dev, 0x0008, 0x0123);
  2502. cit_write_reg(gspca_dev, 0x0000, 0x0100);
  2503. cit_write_reg(gspca_dev, 0x0060, 0x0116);
  2504. /* cit_write_reg(gspca_dev, 0x0002, 0x0112); see sd_stop0 */
  2505. cit_write_reg(gspca_dev, 0x0000, 0x0133);
  2506. cit_write_reg(gspca_dev, 0x0000, 0x0123);
  2507. cit_write_reg(gspca_dev, 0x0001, 0x0117);
  2508. cit_write_reg(gspca_dev, 0x0040, 0x0108);
  2509. cit_write_reg(gspca_dev, 0x0019, 0x012c);
  2510. cit_write_reg(gspca_dev, 0x0060, 0x0116);
  2511. /* cit_write_reg(gspca_dev, 0x000b, 0x0115); see sd_stop0 */
  2512. cit_model3_Packet1(gspca_dev, 0x0049, 0x0000);
  2513. cit_write_reg(gspca_dev, 0x0000, 0x0101); /* Same on 160x120, 320x240 */
  2514. cit_write_reg(gspca_dev, 0x003a, 0x0102); /* Hstart */
  2515. cit_write_reg(gspca_dev, 0x00a0, 0x0103); /* Same on 160x120, 320x240 */
  2516. cit_write_reg(gspca_dev, 0x0078, 0x0105); /* Same on 160x120, 320x240 */
  2517. cit_write_reg(gspca_dev, 0x0000, 0x010a); /* Same */
  2518. cit_write_reg(gspca_dev, 0x0002, 0x011d); /* Same on 160x120, 320x240 */
  2519. cit_write_reg(gspca_dev, 0x0000, 0x0129); /* Same */
  2520. cit_write_reg(gspca_dev, 0x00fc, 0x012b); /* Same */
  2521. cit_write_reg(gspca_dev, 0x0022, 0x012a); /* Same */
  2522. switch (gspca_dev->width) {
  2523. case 160: /* 160x120 */
  2524. cit_write_reg(gspca_dev, 0x0024, 0x010b);
  2525. cit_write_reg(gspca_dev, 0x0089, 0x0119);
  2526. cit_write_reg(gspca_dev, 0x000a, 0x011b);
  2527. cit_write_reg(gspca_dev, 0x0003, 0x011e);
  2528. cit_write_reg(gspca_dev, 0x0007, 0x0104);
  2529. cit_write_reg(gspca_dev, 0x0009, 0x011a);
  2530. cit_write_reg(gspca_dev, 0x008b, 0x011c);
  2531. cit_write_reg(gspca_dev, 0x0008, 0x0118);
  2532. cit_write_reg(gspca_dev, 0x0000, 0x0132);
  2533. break;
  2534. case 320: /* 320x240 */
  2535. cit_write_reg(gspca_dev, 0x0028, 0x010b);
  2536. cit_write_reg(gspca_dev, 0x00d9, 0x0119);
  2537. cit_write_reg(gspca_dev, 0x0006, 0x011b);
  2538. cit_write_reg(gspca_dev, 0x0000, 0x011e);
  2539. cit_write_reg(gspca_dev, 0x000e, 0x0104);
  2540. cit_write_reg(gspca_dev, 0x0004, 0x011a);
  2541. cit_write_reg(gspca_dev, 0x003f, 0x011c);
  2542. cit_write_reg(gspca_dev, 0x000c, 0x0118);
  2543. cit_write_reg(gspca_dev, 0x0000, 0x0132);
  2544. break;
  2545. }
  2546. cit_model3_Packet1(gspca_dev, 0x0019, 0x0031);
  2547. cit_model3_Packet1(gspca_dev, 0x001a, 0x0003);
  2548. cit_model3_Packet1(gspca_dev, 0x001b, 0x0038);
  2549. cit_model3_Packet1(gspca_dev, 0x001c, 0x0000);
  2550. cit_model3_Packet1(gspca_dev, 0x0024, 0x0001);
  2551. cit_model3_Packet1(gspca_dev, 0x0027, 0x0001);
  2552. cit_model3_Packet1(gspca_dev, 0x002a, 0x0004);
  2553. cit_model3_Packet1(gspca_dev, 0x0035, 0x000b);
  2554. cit_model3_Packet1(gspca_dev, 0x003f, 0x0001);
  2555. cit_model3_Packet1(gspca_dev, 0x0044, 0x0000);
  2556. cit_model3_Packet1(gspca_dev, 0x0054, 0x0000);
  2557. cit_model3_Packet1(gspca_dev, 0x00c4, 0x0000);
  2558. cit_model3_Packet1(gspca_dev, 0x00e7, 0x0001);
  2559. cit_model3_Packet1(gspca_dev, 0x00e9, 0x0001);
  2560. cit_model3_Packet1(gspca_dev, 0x00ee, 0x0000);
  2561. cit_model3_Packet1(gspca_dev, 0x00f3, 0x00c0);
  2562. cit_write_reg(gspca_dev, compression, 0x0109);
  2563. cit_write_reg(gspca_dev, clock_div, 0x0111);
  2564. /* if (sd->input_index) { */
  2565. if (rca_input) {
  2566. for (i = 0; i < ARRAY_SIZE(rca_initdata); i++) {
  2567. if (rca_initdata[i][0])
  2568. cit_read_reg(gspca_dev, rca_initdata[i][2], 0);
  2569. else
  2570. cit_write_reg(gspca_dev, rca_initdata[i][1],
  2571. rca_initdata[i][2]);
  2572. }
  2573. }
  2574. return 0;
  2575. }
  2576. /* -- start the camera -- */
  2577. static int sd_start(struct gspca_dev *gspca_dev)
  2578. {
  2579. struct sd *sd = (struct sd *) gspca_dev;
  2580. int packet_size;
  2581. packet_size = cit_get_packet_size(gspca_dev);
  2582. if (packet_size < 0)
  2583. return packet_size;
  2584. switch (sd->model) {
  2585. case CIT_MODEL0:
  2586. cit_start_model0(gspca_dev);
  2587. break;
  2588. case CIT_MODEL1:
  2589. cit_start_model1(gspca_dev);
  2590. break;
  2591. case CIT_MODEL2:
  2592. cit_start_model2(gspca_dev);
  2593. break;
  2594. case CIT_MODEL3:
  2595. cit_start_model3(gspca_dev);
  2596. break;
  2597. case CIT_MODEL4:
  2598. cit_start_model4(gspca_dev);
  2599. break;
  2600. case CIT_IBM_NETCAM_PRO:
  2601. cit_start_ibm_netcam_pro(gspca_dev);
  2602. break;
  2603. }
  2604. cit_set_brightness(gspca_dev);
  2605. cit_set_contrast(gspca_dev);
  2606. cit_set_hue(gspca_dev);
  2607. cit_set_sharpness(gspca_dev);
  2608. cit_set_lighting(gspca_dev);
  2609. cit_set_hflip(gspca_dev);
  2610. /* Program max isoc packet size */
  2611. cit_write_reg(gspca_dev, packet_size >> 8, 0x0106);
  2612. cit_write_reg(gspca_dev, packet_size & 0xff, 0x0107);
  2613. cit_restart_stream(gspca_dev);
  2614. return 0;
  2615. }
  2616. static int sd_isoc_init(struct gspca_dev *gspca_dev)
  2617. {
  2618. struct usb_host_interface *alt;
  2619. int max_packet_size;
  2620. switch (gspca_dev->width) {
  2621. case 160:
  2622. max_packet_size = 450;
  2623. break;
  2624. case 176:
  2625. max_packet_size = 600;
  2626. break;
  2627. default:
  2628. max_packet_size = 1022;
  2629. break;
  2630. }
  2631. /* Start isoc bandwidth "negotiation" at max isoc bandwidth */
  2632. alt = &gspca_dev->dev->actconfig->intf_cache[0]->altsetting[1];
  2633. alt->endpoint[0].desc.wMaxPacketSize = cpu_to_le16(max_packet_size);
  2634. return 0;
  2635. }
  2636. static int sd_isoc_nego(struct gspca_dev *gspca_dev)
  2637. {
  2638. int ret, packet_size, min_packet_size;
  2639. struct usb_host_interface *alt;
  2640. switch (gspca_dev->width) {
  2641. case 160:
  2642. min_packet_size = 200;
  2643. break;
  2644. case 176:
  2645. min_packet_size = 266;
  2646. break;
  2647. default:
  2648. min_packet_size = 400;
  2649. break;
  2650. }
  2651. alt = &gspca_dev->dev->actconfig->intf_cache[0]->altsetting[1];
  2652. packet_size = le16_to_cpu(alt->endpoint[0].desc.wMaxPacketSize);
  2653. if (packet_size <= min_packet_size)
  2654. return -EIO;
  2655. packet_size -= 100;
  2656. if (packet_size < min_packet_size)
  2657. packet_size = min_packet_size;
  2658. alt->endpoint[0].desc.wMaxPacketSize = cpu_to_le16(packet_size);
  2659. ret = usb_set_interface(gspca_dev->dev, gspca_dev->iface, 1);
  2660. if (ret < 0)
  2661. pr_err("set alt 1 err %d\n", ret);
  2662. return ret;
  2663. }
  2664. static void sd_stopN(struct gspca_dev *gspca_dev)
  2665. {
  2666. cit_write_reg(gspca_dev, 0x0000, 0x010c);
  2667. }
  2668. static void sd_stop0(struct gspca_dev *gspca_dev)
  2669. {
  2670. struct sd *sd = (struct sd *) gspca_dev;
  2671. /* We cannot use gspca_dev->present here as that is not set when
  2672. sd_init gets called and we get called from sd_init */
  2673. if (!gspca_dev->dev)
  2674. return;
  2675. switch (sd->model) {
  2676. case CIT_MODEL0:
  2677. /* HDG windows does this, but it causes the cams autogain to
  2678. restart from a gain of 0, which does not look good when
  2679. changing resolutions. */
  2680. /* cit_write_reg(gspca_dev, 0x0000, 0x0112); */
  2681. cit_write_reg(gspca_dev, 0x00c0, 0x0100); /* LED Off */
  2682. break;
  2683. case CIT_MODEL1:
  2684. cit_send_FF_04_02(gspca_dev);
  2685. cit_read_reg(gspca_dev, 0x0100, 0);
  2686. cit_write_reg(gspca_dev, 0x81, 0x0100); /* LED Off */
  2687. break;
  2688. case CIT_MODEL2:
  2689. case CIT_MODEL4:
  2690. cit_model2_Packet1(gspca_dev, 0x0030, 0x0004);
  2691. cit_write_reg(gspca_dev, 0x0080, 0x0100); /* LED Off */
  2692. cit_write_reg(gspca_dev, 0x0020, 0x0111);
  2693. cit_write_reg(gspca_dev, 0x00a0, 0x0111);
  2694. cit_model2_Packet1(gspca_dev, 0x0030, 0x0002);
  2695. cit_write_reg(gspca_dev, 0x0020, 0x0111);
  2696. cit_write_reg(gspca_dev, 0x0000, 0x0112);
  2697. break;
  2698. case CIT_MODEL3:
  2699. cit_write_reg(gspca_dev, 0x0006, 0x012c);
  2700. cit_model3_Packet1(gspca_dev, 0x0046, 0x0000);
  2701. cit_read_reg(gspca_dev, 0x0116, 0);
  2702. cit_write_reg(gspca_dev, 0x0064, 0x0116);
  2703. cit_read_reg(gspca_dev, 0x0115, 0);
  2704. cit_write_reg(gspca_dev, 0x0003, 0x0115);
  2705. cit_write_reg(gspca_dev, 0x0008, 0x0123);
  2706. cit_write_reg(gspca_dev, 0x0000, 0x0117);
  2707. cit_write_reg(gspca_dev, 0x0000, 0x0112);
  2708. cit_write_reg(gspca_dev, 0x0080, 0x0100);
  2709. break;
  2710. case CIT_IBM_NETCAM_PRO:
  2711. cit_model3_Packet1(gspca_dev, 0x0049, 0x00ff);
  2712. cit_write_reg(gspca_dev, 0x0006, 0x012c);
  2713. cit_write_reg(gspca_dev, 0x0000, 0x0116);
  2714. /* HDG windows does this, but I cannot get the camera
  2715. to restart with this without redoing the entire init
  2716. sequence which makes switching modes really slow */
  2717. /* cit_write_reg(gspca_dev, 0x0006, 0x0115); */
  2718. cit_write_reg(gspca_dev, 0x0008, 0x0123);
  2719. cit_write_reg(gspca_dev, 0x0000, 0x0117);
  2720. cit_write_reg(gspca_dev, 0x0003, 0x0133);
  2721. cit_write_reg(gspca_dev, 0x0000, 0x0111);
  2722. /* HDG windows does this, but I get a green picture when
  2723. restarting the stream after this */
  2724. /* cit_write_reg(gspca_dev, 0x0000, 0x0112); */
  2725. cit_write_reg(gspca_dev, 0x00c0, 0x0100);
  2726. break;
  2727. }
  2728. #if defined(CONFIG_INPUT) || defined(CONFIG_INPUT_MODULE)
  2729. /* If the last button state is pressed, release it now! */
  2730. if (sd->button_state) {
  2731. input_report_key(gspca_dev->input_dev, KEY_CAMERA, 0);
  2732. input_sync(gspca_dev->input_dev);
  2733. sd->button_state = 0;
  2734. }
  2735. #endif
  2736. }
  2737. static u8 *cit_find_sof(struct gspca_dev *gspca_dev, u8 *data, int len)
  2738. {
  2739. struct sd *sd = (struct sd *) gspca_dev;
  2740. u8 byte3 = 0, byte4 = 0;
  2741. int i;
  2742. switch (sd->model) {
  2743. case CIT_MODEL0:
  2744. case CIT_MODEL1:
  2745. case CIT_MODEL3:
  2746. case CIT_IBM_NETCAM_PRO:
  2747. switch (gspca_dev->width) {
  2748. case 160: /* 160x120 */
  2749. byte3 = 0x02;
  2750. byte4 = 0x0a;
  2751. break;
  2752. case 176: /* 176x144 */
  2753. byte3 = 0x02;
  2754. byte4 = 0x0e;
  2755. break;
  2756. case 320: /* 320x240 */
  2757. byte3 = 0x02;
  2758. byte4 = 0x08;
  2759. break;
  2760. case 352: /* 352x288 */
  2761. byte3 = 0x02;
  2762. byte4 = 0x00;
  2763. break;
  2764. case 640:
  2765. byte3 = 0x03;
  2766. byte4 = 0x08;
  2767. break;
  2768. }
  2769. /* These have a different byte3 */
  2770. if (sd->model <= CIT_MODEL1)
  2771. byte3 = 0x00;
  2772. for (i = 0; i < len; i++) {
  2773. /* For this model the SOF always starts at offset 0
  2774. so no need to search the entire frame */
  2775. if (sd->model == CIT_MODEL0 && sd->sof_read != i)
  2776. break;
  2777. switch (sd->sof_read) {
  2778. case 0:
  2779. if (data[i] == 0x00)
  2780. sd->sof_read++;
  2781. break;
  2782. case 1:
  2783. if (data[i] == 0xff)
  2784. sd->sof_read++;
  2785. else if (data[i] == 0x00)
  2786. sd->sof_read = 1;
  2787. else
  2788. sd->sof_read = 0;
  2789. break;
  2790. case 2:
  2791. if (data[i] == byte3)
  2792. sd->sof_read++;
  2793. else if (data[i] == 0x00)
  2794. sd->sof_read = 1;
  2795. else
  2796. sd->sof_read = 0;
  2797. break;
  2798. case 3:
  2799. if (data[i] == byte4) {
  2800. sd->sof_read = 0;
  2801. return data + i + (sd->sof_len - 3);
  2802. }
  2803. if (byte3 == 0x00 && data[i] == 0xff)
  2804. sd->sof_read = 2;
  2805. else if (data[i] == 0x00)
  2806. sd->sof_read = 1;
  2807. else
  2808. sd->sof_read = 0;
  2809. break;
  2810. }
  2811. }
  2812. break;
  2813. case CIT_MODEL2:
  2814. case CIT_MODEL4:
  2815. /* TESTME we need to find a longer sof signature to avoid
  2816. false positives */
  2817. for (i = 0; i < len; i++) {
  2818. switch (sd->sof_read) {
  2819. case 0:
  2820. if (data[i] == 0x00)
  2821. sd->sof_read++;
  2822. break;
  2823. case 1:
  2824. sd->sof_read = 0;
  2825. if (data[i] == 0xff) {
  2826. if (i >= 4)
  2827. PDEBUG(D_FRAM,
  2828. "header found at offset: %d: %02x %02x 00 %02x %02x %02x\n",
  2829. i - 1,
  2830. data[i - 4],
  2831. data[i - 3],
  2832. data[i],
  2833. data[i + 1],
  2834. data[i + 2]);
  2835. else
  2836. PDEBUG(D_FRAM,
  2837. "header found at offset: %d: 00 %02x %02x %02x\n",
  2838. i - 1,
  2839. data[i],
  2840. data[i + 1],
  2841. data[i + 2]);
  2842. return data + i + (sd->sof_len - 1);
  2843. }
  2844. break;
  2845. }
  2846. }
  2847. break;
  2848. }
  2849. return NULL;
  2850. }
  2851. static void sd_pkt_scan(struct gspca_dev *gspca_dev,
  2852. u8 *data, int len)
  2853. {
  2854. struct sd *sd = (struct sd *) gspca_dev;
  2855. unsigned char *sof;
  2856. sof = cit_find_sof(gspca_dev, data, len);
  2857. if (sof) {
  2858. int n;
  2859. /* finish decoding current frame */
  2860. n = sof - data;
  2861. if (n > sd->sof_len)
  2862. n -= sd->sof_len;
  2863. else
  2864. n = 0;
  2865. gspca_frame_add(gspca_dev, LAST_PACKET,
  2866. data, n);
  2867. gspca_frame_add(gspca_dev, FIRST_PACKET, NULL, 0);
  2868. len -= sof - data;
  2869. data = sof;
  2870. }
  2871. gspca_frame_add(gspca_dev, INTER_PACKET, data, len);
  2872. }
  2873. static int sd_setbrightness(struct gspca_dev *gspca_dev, __s32 val)
  2874. {
  2875. struct sd *sd = (struct sd *) gspca_dev;
  2876. sd->brightness = val;
  2877. if (gspca_dev->streaming) {
  2878. if (sd->stop_on_control_change)
  2879. sd_stopN(gspca_dev);
  2880. cit_set_brightness(gspca_dev);
  2881. if (sd->stop_on_control_change)
  2882. cit_restart_stream(gspca_dev);
  2883. }
  2884. return 0;
  2885. }
  2886. static int sd_getbrightness(struct gspca_dev *gspca_dev, __s32 *val)
  2887. {
  2888. struct sd *sd = (struct sd *) gspca_dev;
  2889. *val = sd->brightness;
  2890. return 0;
  2891. }
  2892. static int sd_setcontrast(struct gspca_dev *gspca_dev, __s32 val)
  2893. {
  2894. struct sd *sd = (struct sd *) gspca_dev;
  2895. sd->contrast = val;
  2896. if (gspca_dev->streaming) {
  2897. if (sd->stop_on_control_change)
  2898. sd_stopN(gspca_dev);
  2899. cit_set_contrast(gspca_dev);
  2900. if (sd->stop_on_control_change)
  2901. cit_restart_stream(gspca_dev);
  2902. }
  2903. return 0;
  2904. }
  2905. static int sd_getcontrast(struct gspca_dev *gspca_dev, __s32 *val)
  2906. {
  2907. struct sd *sd = (struct sd *) gspca_dev;
  2908. *val = sd->contrast;
  2909. return 0;
  2910. }
  2911. static int sd_sethue(struct gspca_dev *gspca_dev, __s32 val)
  2912. {
  2913. struct sd *sd = (struct sd *) gspca_dev;
  2914. sd->hue = val;
  2915. if (gspca_dev->streaming) {
  2916. if (sd->stop_on_control_change)
  2917. sd_stopN(gspca_dev);
  2918. cit_set_hue(gspca_dev);
  2919. if (sd->stop_on_control_change)
  2920. cit_restart_stream(gspca_dev);
  2921. }
  2922. return 0;
  2923. }
  2924. static int sd_gethue(struct gspca_dev *gspca_dev, __s32 *val)
  2925. {
  2926. struct sd *sd = (struct sd *) gspca_dev;
  2927. *val = sd->hue;
  2928. return 0;
  2929. }
  2930. static int sd_setsharpness(struct gspca_dev *gspca_dev, __s32 val)
  2931. {
  2932. struct sd *sd = (struct sd *) gspca_dev;
  2933. sd->sharpness = val;
  2934. if (gspca_dev->streaming) {
  2935. if (sd->stop_on_control_change)
  2936. sd_stopN(gspca_dev);
  2937. cit_set_sharpness(gspca_dev);
  2938. if (sd->stop_on_control_change)
  2939. cit_restart_stream(gspca_dev);
  2940. }
  2941. return 0;
  2942. }
  2943. static int sd_getsharpness(struct gspca_dev *gspca_dev, __s32 *val)
  2944. {
  2945. struct sd *sd = (struct sd *) gspca_dev;
  2946. *val = sd->sharpness;
  2947. return 0;
  2948. }
  2949. static int sd_setlighting(struct gspca_dev *gspca_dev, __s32 val)
  2950. {
  2951. struct sd *sd = (struct sd *) gspca_dev;
  2952. sd->lighting = val;
  2953. if (gspca_dev->streaming) {
  2954. if (sd->stop_on_control_change)
  2955. sd_stopN(gspca_dev);
  2956. cit_set_lighting(gspca_dev);
  2957. if (sd->stop_on_control_change)
  2958. cit_restart_stream(gspca_dev);
  2959. }
  2960. return 0;
  2961. }
  2962. static int sd_getlighting(struct gspca_dev *gspca_dev, __s32 *val)
  2963. {
  2964. struct sd *sd = (struct sd *) gspca_dev;
  2965. *val = sd->lighting;
  2966. return 0;
  2967. }
  2968. static int sd_sethflip(struct gspca_dev *gspca_dev, __s32 val)
  2969. {
  2970. struct sd *sd = (struct sd *) gspca_dev;
  2971. sd->hflip = val;
  2972. if (gspca_dev->streaming) {
  2973. if (sd->stop_on_control_change)
  2974. sd_stopN(gspca_dev);
  2975. cit_set_hflip(gspca_dev);
  2976. if (sd->stop_on_control_change)
  2977. cit_restart_stream(gspca_dev);
  2978. }
  2979. return 0;
  2980. }
  2981. static int sd_gethflip(struct gspca_dev *gspca_dev, __s32 *val)
  2982. {
  2983. struct sd *sd = (struct sd *) gspca_dev;
  2984. *val = sd->hflip;
  2985. return 0;
  2986. }
  2987. #if defined(CONFIG_INPUT) || defined(CONFIG_INPUT_MODULE)
  2988. static void cit_check_button(struct gspca_dev *gspca_dev)
  2989. {
  2990. int new_button_state;
  2991. struct sd *sd = (struct sd *)gspca_dev;
  2992. switch (sd->model) {
  2993. case CIT_MODEL3:
  2994. case CIT_IBM_NETCAM_PRO:
  2995. break;
  2996. default: /* TEST ME unknown if this works on other models too */
  2997. return;
  2998. }
  2999. /* Read the button state */
  3000. cit_read_reg(gspca_dev, 0x0113, 0);
  3001. new_button_state = !gspca_dev->usb_buf[0];
  3002. /* Tell the cam we've seen the button press, notice that this
  3003. is a nop (iow the cam keeps reporting pressed) until the
  3004. button is actually released. */
  3005. if (new_button_state)
  3006. cit_write_reg(gspca_dev, 0x01, 0x0113);
  3007. if (sd->button_state != new_button_state) {
  3008. input_report_key(gspca_dev->input_dev, KEY_CAMERA,
  3009. new_button_state);
  3010. input_sync(gspca_dev->input_dev);
  3011. sd->button_state = new_button_state;
  3012. }
  3013. }
  3014. #endif
  3015. /* sub-driver description */
  3016. static const struct sd_desc sd_desc = {
  3017. .name = MODULE_NAME,
  3018. .ctrls = sd_ctrls,
  3019. .nctrls = ARRAY_SIZE(sd_ctrls),
  3020. .config = sd_config,
  3021. .init = sd_init,
  3022. .start = sd_start,
  3023. .stopN = sd_stopN,
  3024. .stop0 = sd_stop0,
  3025. .pkt_scan = sd_pkt_scan,
  3026. #if defined(CONFIG_INPUT) || defined(CONFIG_INPUT_MODULE)
  3027. .dq_callback = cit_check_button,
  3028. .other_input = 1,
  3029. #endif
  3030. };
  3031. static const struct sd_desc sd_desc_isoc_nego = {
  3032. .name = MODULE_NAME,
  3033. .ctrls = sd_ctrls,
  3034. .nctrls = ARRAY_SIZE(sd_ctrls),
  3035. .config = sd_config,
  3036. .init = sd_init,
  3037. .start = sd_start,
  3038. .isoc_init = sd_isoc_init,
  3039. .isoc_nego = sd_isoc_nego,
  3040. .stopN = sd_stopN,
  3041. .stop0 = sd_stop0,
  3042. .pkt_scan = sd_pkt_scan,
  3043. #if defined(CONFIG_INPUT) || defined(CONFIG_INPUT_MODULE)
  3044. .dq_callback = cit_check_button,
  3045. .other_input = 1,
  3046. #endif
  3047. };
  3048. /* -- module initialisation -- */
  3049. static const struct usb_device_id device_table[] = {
  3050. { USB_DEVICE_VER(0x0545, 0x8080, 0x0001, 0x0001), .driver_info = CIT_MODEL0 },
  3051. { USB_DEVICE_VER(0x0545, 0x8080, 0x0002, 0x0002), .driver_info = CIT_MODEL1 },
  3052. { USB_DEVICE_VER(0x0545, 0x8080, 0x030a, 0x030a), .driver_info = CIT_MODEL2 },
  3053. { USB_DEVICE_VER(0x0545, 0x8080, 0x0301, 0x0301), .driver_info = CIT_MODEL3 },
  3054. { USB_DEVICE_VER(0x0545, 0x8002, 0x030a, 0x030a), .driver_info = CIT_MODEL4 },
  3055. { USB_DEVICE_VER(0x0545, 0x800c, 0x030a, 0x030a), .driver_info = CIT_MODEL2 },
  3056. { USB_DEVICE_VER(0x0545, 0x800d, 0x030a, 0x030a), .driver_info = CIT_MODEL4 },
  3057. {}
  3058. };
  3059. MODULE_DEVICE_TABLE(usb, device_table);
  3060. /* -- device connect -- */
  3061. static int sd_probe(struct usb_interface *intf,
  3062. const struct usb_device_id *id)
  3063. {
  3064. const struct sd_desc *desc = &sd_desc;
  3065. switch (id->driver_info) {
  3066. case CIT_MODEL0:
  3067. case CIT_MODEL1:
  3068. if (intf->cur_altsetting->desc.bInterfaceNumber != 2)
  3069. return -ENODEV;
  3070. break;
  3071. case CIT_MODEL2:
  3072. case CIT_MODEL4:
  3073. if (intf->cur_altsetting->desc.bInterfaceNumber != 0)
  3074. return -ENODEV;
  3075. break;
  3076. case CIT_MODEL3:
  3077. if (intf->cur_altsetting->desc.bInterfaceNumber != 0)
  3078. return -ENODEV;
  3079. /* FIXME this likely applies to all model3 cams and probably
  3080. to other models too. */
  3081. if (ibm_netcam_pro)
  3082. desc = &sd_desc_isoc_nego;
  3083. break;
  3084. }
  3085. return gspca_dev_probe2(intf, id, desc, sizeof(struct sd), THIS_MODULE);
  3086. }
  3087. static struct usb_driver sd_driver = {
  3088. .name = MODULE_NAME,
  3089. .id_table = device_table,
  3090. .probe = sd_probe,
  3091. .disconnect = gspca_disconnect,
  3092. #ifdef CONFIG_PM
  3093. .suspend = gspca_suspend,
  3094. .resume = gspca_resume,
  3095. #endif
  3096. };
  3097. module_usb_driver(sd_driver);