xirlink_cit.c 97 KB

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